regmap: cache: Factor out block sync
The idea of holding blocks of registers in device format is shared between at least rbtree and lzo cache formats so split out the loop that does the sync from the rbtree code so optimisations on it can be reused. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
This commit is contained in:
Родитель
78493f2d7b
Коммит
f8bd822cbf
|
@ -191,6 +191,9 @@ int regcache_read(struct regmap *map,
|
||||||
int regcache_write(struct regmap *map,
|
int regcache_write(struct regmap *map,
|
||||||
unsigned int reg, unsigned int value);
|
unsigned int reg, unsigned int value);
|
||||||
int regcache_sync(struct regmap *map);
|
int regcache_sync(struct regmap *map);
|
||||||
|
int regcache_sync_block(struct regmap *map, void *block,
|
||||||
|
unsigned int block_base, unsigned int start,
|
||||||
|
unsigned int end);
|
||||||
|
|
||||||
static inline const void *regcache_get_val_addr(struct regmap *map,
|
static inline const void *regcache_get_val_addr(struct regmap *map,
|
||||||
const void *base,
|
const void *base,
|
||||||
|
|
|
@ -53,12 +53,6 @@ static unsigned int regcache_rbtree_get_register(struct regmap *map,
|
||||||
return regcache_get_val(map, rbnode->block, idx);
|
return regcache_get_val(map, rbnode->block, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const void *regcache_rbtree_get_reg_addr(struct regmap *map,
|
|
||||||
struct regcache_rbtree_node *rbnode, unsigned int idx)
|
|
||||||
{
|
|
||||||
return regcache_get_val_addr(map, rbnode->block, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void regcache_rbtree_set_register(struct regmap *map,
|
static void regcache_rbtree_set_register(struct regmap *map,
|
||||||
struct regcache_rbtree_node *rbnode,
|
struct regcache_rbtree_node *rbnode,
|
||||||
unsigned int idx, unsigned int val)
|
unsigned int idx, unsigned int val)
|
||||||
|
@ -390,11 +384,8 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
|
||||||
struct regcache_rbtree_ctx *rbtree_ctx;
|
struct regcache_rbtree_ctx *rbtree_ctx;
|
||||||
struct rb_node *node;
|
struct rb_node *node;
|
||||||
struct regcache_rbtree_node *rbnode;
|
struct regcache_rbtree_node *rbnode;
|
||||||
unsigned int regtmp;
|
|
||||||
unsigned int val;
|
|
||||||
const void *addr;
|
|
||||||
int ret;
|
int ret;
|
||||||
int i, base, end;
|
int base, end;
|
||||||
|
|
||||||
rbtree_ctx = map->cache;
|
rbtree_ctx = map->cache;
|
||||||
for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
|
for (node = rb_first(&rbtree_ctx->root); node; node = rb_next(node)) {
|
||||||
|
@ -417,40 +408,13 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
|
||||||
else
|
else
|
||||||
end = rbnode->blklen;
|
end = rbnode->blklen;
|
||||||
|
|
||||||
for (i = base; i < end; i++) {
|
ret = regcache_sync_block(map, rbnode->block, rbnode->base_reg,
|
||||||
regtmp = rbnode->base_reg + (i * map->reg_stride);
|
base, end);
|
||||||
|
if (ret != 0)
|
||||||
if (!regcache_reg_present(map, regtmp))
|
return ret;
|
||||||
continue;
|
|
||||||
|
|
||||||
val = regcache_rbtree_get_register(map, rbnode, i);
|
|
||||||
|
|
||||||
/* Is this the hardware default? If so skip. */
|
|
||||||
ret = regcache_lookup_reg(map, regtmp);
|
|
||||||
if (ret >= 0 && val == map->reg_defaults[ret].def)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
map->cache_bypass = 1;
|
|
||||||
|
|
||||||
if (regmap_can_raw_write(map)) {
|
|
||||||
addr = regcache_rbtree_get_reg_addr(map,
|
|
||||||
rbnode, i);
|
|
||||||
ret = _regmap_raw_write(map, regtmp, addr,
|
|
||||||
map->format.val_bytes,
|
|
||||||
false);
|
|
||||||
} else {
|
|
||||||
ret = _regmap_write(map, regtmp, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
map->cache_bypass = 0;
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
|
|
||||||
regtmp, val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return regmap_async_complete(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct regcache_ops regcache_rbtree_ops = {
|
struct regcache_ops regcache_rbtree_ops = {
|
||||||
|
|
|
@ -544,3 +544,45 @@ int regcache_lookup_reg(struct regmap *map, unsigned int reg)
|
||||||
else
|
else
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int regcache_sync_block(struct regmap *map, void *block,
|
||||||
|
unsigned int block_base, unsigned int start,
|
||||||
|
unsigned int end)
|
||||||
|
{
|
||||||
|
unsigned int i, regtmp, val;
|
||||||
|
const void *addr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
for (i = start; i < end; i++) {
|
||||||
|
regtmp = block_base + (i * map->reg_stride);
|
||||||
|
|
||||||
|
if (!regcache_reg_present(map, regtmp))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
val = regcache_get_val(map, block, i);
|
||||||
|
|
||||||
|
/* Is this the hardware default? If so skip. */
|
||||||
|
ret = regcache_lookup_reg(map, regtmp);
|
||||||
|
if (ret >= 0 && val == map->reg_defaults[ret].def)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
map->cache_bypass = 1;
|
||||||
|
|
||||||
|
if (regmap_can_raw_write(map)) {
|
||||||
|
addr = regcache_get_val_addr(map, block, i);
|
||||||
|
ret = _regmap_raw_write(map, regtmp, addr,
|
||||||
|
map->format.val_bytes,
|
||||||
|
false);
|
||||||
|
} else {
|
||||||
|
ret = _regmap_write(map, regtmp, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
map->cache_bypass = 0;
|
||||||
|
if (ret != 0)
|
||||||
|
return ret;
|
||||||
|
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
|
||||||
|
regtmp, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче