regmap: Supply ranges to the sync operations
Subsystems (2)
PATCH 1/3 regmap: Supply ranges to the sync operations
In order to allow us to support partial sync operations add minimum and maximum register arguments to the sync operation and update the rbtree and lzo caches to use this new information. The LZO implementation is obviously not good, we could exit the iteration earlier, but there may be room for more wide reaching optimisation there.
--- drivers/base/regmap/internal.h | 2 +- drivers/base/regmap/regcache-lzo.c | 10 ++++++++-- drivers/base/regmap/regcache-rbtree.c | 25 ++++++++++++++++++++++--- drivers/base/regmap/regcache.c | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-)
drivers/base/regmap/internal.h +1 -1
@@ -88,7 +88,7 @@ struct regcache_ops {int (*exit)(struct regmap *map);int (*read)(struct regmap *map,unsigned int reg,unsigned int *value);int (*write)(struct regmap *map,unsigned int reg,unsigned int value); -int (*sync)(struct regmap *map); +int (*sync)(struct regmap *map,unsigned int min,unsigned int max); };bool regmap_writeable (struct regmap *map,unsigned int reg);
drivers/base/regmap/regcache-lzo.c +8 -2
@@ -331,7 +331,8 @@ out:return ret; } -static int regcache_lzo_sync (struct regmap *map) +static int regcache_lzo_sync (struct regmap *map,unsigned int min, +unsigned int max) {struct regcache_lzo_ctx **lzo_blocks;unsigned int val;
@@ -339,7 +340,12 @@ static int regcache_lzo_sync(struct regmap *map)int ret; lzo_blocks = map->cache; -for_each_set_bit (i, lzo_blocks[0 ]->sync_bmp, lzo_blocks[0 ]->sync_bmp_nbits) { + i = min; +for_each_set_bit_from (i, lzo_blocks[0 ]->sync_bmp, + lzo_blocks[0 ]->sync_bmp_nbits) { +if (i > max) +continue ; + ret =regcache_read (map, i, &val);if (ret)return ret;
drivers/base/regmap/regcache-rbtree.c +22 -3
@@ -357,7 +357,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,return 0 ; } -static int regcache_rbtree_sync (struct regmap *map) +static int regcache_rbtree_sync (struct regmap *map,unsigned int min, +unsigned int max) {struct regcache_rbtree_ctx *rbtree_ctx;struct rb_node *node;
@@ -365,12 +366,30 @@ static int regcache_rbtree_sync(struct regmap *map)unsigned int regtmp;unsigned int val;int ret; -int i; +int i, base, end; rbtree_ctx = map->cache;for (node =rb_first (&rbtree_ctx->root); node; node =rb_next (node)) { rbnode = rb_entry(node, struct regcache_rbtree_node, node); -for (i =0 ; i < rbnode->blklen; i++) { + +if (rbnode->base_reg < min) +continue ; +if (rbnode->base_reg > max) +break ; +if (rbnode->base_reg + rbnode->blklen < min) +continue ; + +if (min < rbnode->base_reg + rbnode->blklen) + base = min - rbnode->base_reg; +else + base =0 ; + +if (max < rbnode->base_reg + rbnode->blklen) + end = rbnode->base_reg + rbnode->blklen - max; +else + end = rbnode->blklen; + +for (i = base; i < end; i++) { regtmp = rbnode->base_reg + i; val =regcache_rbtree_get_register (rbnode, i, map->cache_word_size);
drivers/base/regmap/regcache.c +1 -1
@@ -286,7 +286,7 @@ int regcache_sync(struct regmap *map) } map->cache_bypass =0 ; - ret = map->cache_ops->sync (map); + ret = map->cache_ops->sync (map,0 , map->max_register);if (ret ==0 ) map->cache_dirty = false;
Signature · 1 line
1.7.9.1
PATCH 2/3 regmap: Allow drivers to sync only part of the register cache
Provide a regcache_sync_region() operation which allows drivers to write only part of the cache back to the hardware. This is intended for use in cases like power domains or DSP memories where part of the device register map may be reset without fully resetting the device.
Fully supporting these devices is likely to require additional work to make specific regions of the register map cache only while they are in reset, but this is enough for most devices.
--- drivers/base/regmap/regcache.c | 45 ++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 2 + 2 files changed, 47 insertions(+), 0 deletions(-)
drivers/base/regmap/regcache.c +45 -0
@@ -302,6 +302,51 @@ out:EXPORT_SYMBOL_GPL (regcache_sync);/** +* regcache_sync_region: Sync part of the register cache with the hardware. +* +* @map: map to sync. +* @min: first register to sync +* @max: last register to sync +* +* Write all non-default register values in the specified region to +* the hardware. +* +* Return a negative value on failure, 0 on success. +*/ +int regcache_sync_region (struct regmap *map,unsigned int min, +unsigned int max) +{ +int ret =0 ; +const char *name; +unsigned int bypass; + +BUG_ON (!map->cache_ops || !map->cache_ops->sync); + +mutex_lock (&map->lock); + +/* Remember the initial bypass state */ + bypass = map->cache_bypass; + + name = map->cache_ops->name; +dev_dbg (map->dev,"Syncing %s cache from %d-%d\n" , name, min, max); + +trace_regcache_sync (map->dev, name,"start region" ); + +if (!map->cache_dirty) + goto out; + + ret = map->cache_ops->sync (map, min, max); + +out: +trace_regcache_sync (map->dev, name,"stop region" ); +/* Restore the bypass state */ + map->cache_bypass = bypass; +mutex_unlock (&map->lock); + +return ret; +} + +/** * regcache_cache_only: Put a register map into cache only mode * * @map: map to configure
include/linux/regmap.h +2 -0
@@ -160,6 +160,8 @@ int regmap_update_bits_check(struct regmap *map, unsigned int reg,int regmap_get_val_bytes (struct regmap *map);int regcache_sync (struct regmap *map); +int regcache_sync_region (struct regmap *map,unsigned int min, +unsigned int max);void regcache_cache_only (struct regmap *map,bool enable);void regcache_cache_bypass (struct regmap *map,bool enable);void regcache_mark_dirty (struct regmap *map);
Signature · 1 line
1.7.9.1
PATCH 3/3 regmap: Add stub for regcache_sync_region()
In reply to Mark BrownAdded on another branch.
--- include/linux/regmap.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/regmap.h +7 -0
@@ -296,6 +296,13 @@ static inline int regcache_sync(struct regmap *map)return -EINVAL ; } +static inline int regcache_sync_region (struct regmap *map,unsigned int min, +unsigned int max) +{ +WARN_ONCE (1 ,"regmap API is disabled" ); +return -EINVAL ; +} +static inline void regcache_cache_only (struct regmap *map,bool enable) {WARN_ONCE (1 ,"regmap API is disabled" );
Signature · 1 line
1.7.9.1