Skip to content

Commit

Permalink
Merge remote-tracking branch 'regmap/topic/async' into regmap-next
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Brown committed Feb 14, 2013
2 parents 3bef905 + 95601d6 commit 3689cf7
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 47 deletions.
18 changes: 18 additions & 0 deletions drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/regmap.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/wait.h>

struct regmap;
struct regcache_ops;
Expand All @@ -39,6 +40,13 @@ struct regmap_format {
unsigned int (*parse_val)(void *buf);
};

struct regmap_async {
struct list_head list;
struct work_struct cleanup;
struct regmap *map;
void *work_buf;
};

struct regmap {
struct mutex mutex;
spinlock_t spinlock;
Expand All @@ -53,6 +61,11 @@ struct regmap {
void *bus_context;
const char *name;

spinlock_t async_lock;
wait_queue_head_t async_waitq;
struct list_head async_list;
int async_ret;

#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs;
const char *debugfs_name;
Expand All @@ -74,6 +87,9 @@ struct regmap {
const struct regmap_access_table *volatile_table;
const struct regmap_access_table *precious_table;

int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
int (*reg_write)(void *context, unsigned int reg, unsigned int val);

u8 read_flag_mask;
u8 write_flag_mask;

Expand Down Expand Up @@ -175,6 +191,8 @@ bool regcache_set_val(void *base, unsigned int idx,
unsigned int val, unsigned int word_size);
int regcache_lookup_reg(struct regmap *map, unsigned int reg);

void regmap_async_complete_cb(struct regmap_async *async, int ret);

extern struct regcache_ops regcache_rbtree_ops;
extern struct regcache_ops regcache_lzo_ops;

Expand Down
54 changes: 54 additions & 0 deletions drivers/base/regmap/regmap-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
#include <linux/init.h>
#include <linux/module.h>

#include "internal.h"

struct regmap_async_spi {
struct regmap_async core;
struct spi_message m;
struct spi_transfer t[2];
};

static void regmap_spi_complete(void *data)
{
struct regmap_async_spi *async = data;

regmap_async_complete_cb(&async->core, async->m.status);
}

static int regmap_spi_write(void *context, const void *data, size_t count)
{
struct device *dev = context;
Expand All @@ -40,6 +55,43 @@ static int regmap_spi_gather_write(void *context,
return spi_sync(spi, &m);
}

static int regmap_spi_async_write(void *context,
const void *reg, size_t reg_len,
const void *val, size_t val_len,
struct regmap_async *a)
{
struct regmap_async_spi *async = container_of(a,
struct regmap_async_spi,
core);
struct device *dev = context;
struct spi_device *spi = to_spi_device(dev);

async->t[0].tx_buf = reg;
async->t[0].len = reg_len;
async->t[1].tx_buf = val;
async->t[1].len = val_len;

spi_message_init(&async->m);
spi_message_add_tail(&async->t[0], &async->m);
spi_message_add_tail(&async->t[1], &async->m);

async->m.complete = regmap_spi_complete;
async->m.context = async;

return spi_async(spi, &async->m);
}

static struct regmap_async *regmap_spi_async_alloc(void)
{
struct regmap_async_spi *async_spi;

async_spi = kzalloc(sizeof(*async_spi), GFP_KERNEL);
if (!async_spi)
return NULL;

return &async_spi->core;
}

static int regmap_spi_read(void *context,
const void *reg, size_t reg_size,
void *val, size_t val_size)
Expand All @@ -53,6 +105,8 @@ static int regmap_spi_read(void *context,
static struct regmap_bus regmap_spi = {
.write = regmap_spi_write,
.gather_write = regmap_spi_gather_write,
.async_write = regmap_spi_async_write,
.async_alloc = regmap_spi_async_alloc,
.read = regmap_spi_read,
.read_flag_mask = 0x80,
};
Expand Down
Loading

0 comments on commit 3689cf7

Please sign in to comment.