Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 305613
b: refs/heads/master
c: a42678c
h: refs/heads/master
i:
  305611: 1b2c748
v: v3
  • Loading branch information
Stephen Warren authored and Mark Brown committed Apr 13, 2012
1 parent 5202863 commit 1ef4351
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 31 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 26b5e74d318241d95430d440e43ebbdfab3c70d4
refs/heads/master: a42678c4c8b5f6d489829ffc3071fa1f08ee99d1
8 changes: 7 additions & 1 deletion trunk/drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ struct regmap_format {
unsigned int (*parse_val)(void *buf);
};

typedef void (*regmap_lock)(struct regmap *map);
typedef void (*regmap_unlock)(struct regmap *map);

struct regmap {
struct mutex lock;
struct mutex mutex;
spinlock_t spinlock;
regmap_lock lock;
regmap_unlock unlock;

struct device *dev; /* Device we do I/O on */
void *work_buf; /* Scratch buffer used to format I/O */
Expand Down
4 changes: 2 additions & 2 deletions trunk/drivers/base/regmap/regcache-rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
int registers = 0;
int average;

mutex_lock(&map->lock);
map->lock(map);

for (node = rb_first(&rbtree_ctx->root); node != NULL;
node = rb_next(node)) {
Expand All @@ -161,7 +161,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
seq_printf(s, "%d nodes, %d registers, average %d registers\n",
nodes, registers, average);

mutex_unlock(&map->lock);
map->unlock(map);

return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions trunk/drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ int regcache_sync(struct regmap *map)

BUG_ON(!map->cache_ops || !map->cache_ops->sync);

mutex_lock(&map->lock);
map->lock(map);
/* Remember the initial bypass state */
bypass = map->cache_bypass;
dev_dbg(map->dev, "Syncing %s cache\n",
Expand Down Expand Up @@ -296,7 +296,7 @@ int regcache_sync(struct regmap *map)
trace_regcache_sync(map->dev, name, "stop");
/* Restore the bypass state */
map->cache_bypass = bypass;
mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand All @@ -323,7 +323,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,

BUG_ON(!map->cache_ops || !map->cache_ops->sync);

mutex_lock(&map->lock);
map->lock(map);

/* Remember the initial bypass state */
bypass = map->cache_bypass;
Expand All @@ -342,7 +342,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
trace_regcache_sync(map->dev, name, "stop region");
/* Restore the bypass state */
map->cache_bypass = bypass;
mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand All @@ -362,11 +362,11 @@ EXPORT_SYMBOL_GPL(regcache_sync_region);
*/
void regcache_cache_only(struct regmap *map, bool enable)
{
mutex_lock(&map->lock);
map->lock(map);
WARN_ON(map->cache_bypass && enable);
map->cache_only = enable;
trace_regmap_cache_only(map->dev, enable);
mutex_unlock(&map->lock);
map->unlock(map);
}
EXPORT_SYMBOL_GPL(regcache_cache_only);

Expand All @@ -381,9 +381,9 @@ EXPORT_SYMBOL_GPL(regcache_cache_only);
*/
void regcache_mark_dirty(struct regmap *map)
{
mutex_lock(&map->lock);
map->lock(map);
map->cache_dirty = true;
mutex_unlock(&map->lock);
map->unlock(map);
}
EXPORT_SYMBOL_GPL(regcache_mark_dirty);

Expand All @@ -400,11 +400,11 @@ EXPORT_SYMBOL_GPL(regcache_mark_dirty);
*/
void regcache_cache_bypass(struct regmap *map, bool enable)
{
mutex_lock(&map->lock);
map->lock(map);
WARN_ON(map->cache_only && enable);
map->cache_bypass = enable;
trace_regmap_cache_bypass(map->dev, enable);
mutex_unlock(&map->lock);
map->unlock(map);
}
EXPORT_SYMBOL_GPL(regcache_cache_bypass);

Expand Down
62 changes: 45 additions & 17 deletions trunk/drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ static unsigned int regmap_parse_32(void *buf)
return b[0];
}

static void regmap_lock_mutex(struct regmap *map)
{
mutex_lock(&map->mutex);
}

static void regmap_unlock_mutex(struct regmap *map)
{
mutex_unlock(&map->mutex);
}

static void regmap_lock_spinlock(struct regmap *map)
{
spin_lock(&map->spinlock);
}

static void regmap_unlock_spinlock(struct regmap *map)
{
spin_unlock(&map->spinlock);
}

/**
* regmap_init(): Initialise register map
*
Expand Down Expand Up @@ -208,7 +228,15 @@ struct regmap *regmap_init(struct device *dev,
goto err;
}

mutex_init(&map->lock);
if (bus->fast_io) {
spin_lock_init(&map->spinlock);
map->lock = regmap_lock_spinlock;
map->unlock = regmap_unlock_spinlock;
} else {
mutex_init(&map->mutex);
map->lock = regmap_lock_mutex;
map->unlock = regmap_unlock_mutex;
}
map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
map->format.pad_bytes = config->pad_bits / 8;
Expand Down Expand Up @@ -391,7 +419,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
{
int ret;

mutex_lock(&map->lock);
map->lock(map);

regcache_exit(map);
regmap_debugfs_exit(map);
Expand All @@ -410,7 +438,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)

ret = regcache_init(map, config);

mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand Down Expand Up @@ -562,11 +590,11 @@ int regmap_write(struct regmap *map, unsigned int reg, unsigned int val)
{
int ret;

mutex_lock(&map->lock);
map->lock(map);

ret = _regmap_write(map, reg, val);

mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand All @@ -593,11 +621,11 @@ int regmap_raw_write(struct regmap *map, unsigned int reg,
{
int ret;

mutex_lock(&map->lock);
map->lock(map);

ret = _regmap_raw_write(map, reg, val, val_len);

mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand Down Expand Up @@ -627,7 +655,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
if (!map->format.parse_val)
return -EINVAL;

mutex_lock(&map->lock);
map->lock(map);

/* No formatting is require if val_byte is 1 */
if (val_bytes == 1) {
Expand All @@ -648,7 +676,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
kfree(wval);

out:
mutex_unlock(&map->lock);
map->unlock(map);
return ret;
}
EXPORT_SYMBOL_GPL(regmap_bulk_write);
Expand Down Expand Up @@ -722,11 +750,11 @@ int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val)
{
int ret;

mutex_lock(&map->lock);
map->lock(map);

ret = _regmap_read(map, reg, val);

mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand All @@ -751,7 +779,7 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
unsigned int v;
int ret, i;

mutex_lock(&map->lock);
map->lock(map);

if (regmap_volatile_range(map, reg, val_count) || map->cache_bypass ||
map->cache_type == REGCACHE_NONE) {
Expand All @@ -772,7 +800,7 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
}

out:
mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand Down Expand Up @@ -825,7 +853,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
int ret;
unsigned int tmp, orig;

mutex_lock(&map->lock);
map->lock(map);

ret = _regmap_read(map, reg, &orig);
if (ret != 0)
Expand All @@ -842,7 +870,7 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg,
}

out:
mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand Down Expand Up @@ -909,7 +937,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
if (map->patch)
return -EBUSY;

mutex_lock(&map->lock);
map->lock(map);

bypass = map->cache_bypass;

Expand Down Expand Up @@ -937,7 +965,7 @@ int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
out:
map->cache_bypass = bypass;

mutex_unlock(&map->lock);
map->unlock(map);

return ret;
}
Expand Down
3 changes: 3 additions & 0 deletions trunk/include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ typedef void (*regmap_hw_free_context)(void *context);
/**
* Description of a hardware bus for the register map infrastructure.
*
* @fast_io: Register IO is fast. Use a spinlock instead of a mutex
* to perform locking.
* @write: Write operation.
* @gather_write: Write operation with split register/value, return -ENOTSUPP
* if not implemented on a given device.
Expand All @@ -119,6 +121,7 @@ typedef void (*regmap_hw_free_context)(void *context);
* a read.
*/
struct regmap_bus {
bool fast_io;
regmap_hw_write write;
regmap_hw_gather_write gather_write;
regmap_hw_read read;
Expand Down

0 comments on commit 1ef4351

Please sign in to comment.