regmap: cache: Pass the map rather than the word size when updating values
It's more idiomatic to pass the map structure around and this means we can use other bits of information from the map. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Родитель
66baf40757
Коммит
879082c9fe
|
@ -188,10 +188,10 @@ 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);
|
||||||
|
|
||||||
unsigned int regcache_get_val(const void *base, unsigned int idx,
|
unsigned int regcache_get_val(struct regmap *map, const void *base,
|
||||||
unsigned int word_size);
|
unsigned int idx);
|
||||||
bool regcache_set_val(void *base, unsigned int idx,
|
bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
|
||||||
unsigned int val, unsigned int word_size);
|
unsigned int val);
|
||||||
int regcache_lookup_reg(struct regmap *map, unsigned int reg);
|
int regcache_lookup_reg(struct regmap *map, unsigned int reg);
|
||||||
|
|
||||||
void regmap_async_complete_cb(struct regmap_async *async, int ret);
|
void regmap_async_complete_cb(struct regmap_async *async, int ret);
|
||||||
|
|
|
@ -260,8 +260,7 @@ static int regcache_lzo_read(struct regmap *map,
|
||||||
ret = regcache_lzo_decompress_cache_block(map, lzo_block);
|
ret = regcache_lzo_decompress_cache_block(map, lzo_block);
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
/* fetch the value from the cache */
|
/* fetch the value from the cache */
|
||||||
*value = regcache_get_val(lzo_block->dst, blkpos,
|
*value = regcache_get_val(map, lzo_block->dst, blkpos);
|
||||||
map->cache_word_size);
|
|
||||||
|
|
||||||
kfree(lzo_block->dst);
|
kfree(lzo_block->dst);
|
||||||
/* restore the pointer and length of the compressed block */
|
/* restore the pointer and length of the compressed block */
|
||||||
|
@ -304,8 +303,7 @@ static int regcache_lzo_write(struct regmap *map,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the new value to the cache */
|
/* write the new value to the cache */
|
||||||
if (regcache_set_val(lzo_block->dst, blkpos, value,
|
if (regcache_set_val(map, lzo_block->dst, blkpos, value)) {
|
||||||
map->cache_word_size)) {
|
|
||||||
kfree(lzo_block->dst);
|
kfree(lzo_block->dst);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,22 +47,21 @@ static inline void regcache_rbtree_get_base_top_reg(
|
||||||
*top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride);
|
*top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int regcache_rbtree_get_register(
|
static unsigned int regcache_rbtree_get_register(struct regmap *map,
|
||||||
struct regcache_rbtree_node *rbnode, unsigned int idx,
|
struct regcache_rbtree_node *rbnode, unsigned int idx)
|
||||||
unsigned int word_size)
|
|
||||||
{
|
{
|
||||||
return regcache_get_val(rbnode->block, idx, word_size);
|
return regcache_get_val(map, rbnode->block, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode,
|
static void regcache_rbtree_set_register(struct regmap *map,
|
||||||
unsigned int idx, unsigned int val,
|
struct regcache_rbtree_node *rbnode,
|
||||||
unsigned int word_size)
|
unsigned int idx, unsigned int val)
|
||||||
{
|
{
|
||||||
regcache_set_val(rbnode->block, idx, val, word_size);
|
regcache_set_val(map, rbnode->block, idx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
|
static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
|
||||||
unsigned int reg)
|
unsigned int reg)
|
||||||
{
|
{
|
||||||
struct regcache_rbtree_ctx *rbtree_ctx = map->cache;
|
struct regcache_rbtree_ctx *rbtree_ctx = map->cache;
|
||||||
struct rb_node *node;
|
struct rb_node *node;
|
||||||
|
@ -260,8 +259,7 @@ static int regcache_rbtree_read(struct regmap *map,
|
||||||
rbnode = regcache_rbtree_lookup(map, reg);
|
rbnode = regcache_rbtree_lookup(map, reg);
|
||||||
if (rbnode) {
|
if (rbnode) {
|
||||||
reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
|
reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
|
||||||
*value = regcache_rbtree_get_register(rbnode, reg_tmp,
|
*value = regcache_rbtree_get_register(map, rbnode, reg_tmp);
|
||||||
map->cache_word_size);
|
|
||||||
} else {
|
} else {
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
@ -270,21 +268,23 @@ static int regcache_rbtree_read(struct regmap *map,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode,
|
static int regcache_rbtree_insert_to_block(struct regmap *map,
|
||||||
|
struct regcache_rbtree_node *rbnode,
|
||||||
unsigned int pos, unsigned int reg,
|
unsigned int pos, unsigned int reg,
|
||||||
unsigned int value, unsigned int word_size)
|
unsigned int value)
|
||||||
{
|
{
|
||||||
u8 *blk;
|
u8 *blk;
|
||||||
|
|
||||||
blk = krealloc(rbnode->block,
|
blk = krealloc(rbnode->block,
|
||||||
(rbnode->blklen + 1) * word_size, GFP_KERNEL);
|
(rbnode->blklen + 1) * map->cache_word_size,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!blk)
|
if (!blk)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* insert the register value in the correct place in the rbnode block */
|
/* insert the register value in the correct place in the rbnode block */
|
||||||
memmove(blk + (pos + 1) * word_size,
|
memmove(blk + (pos + 1) * map->cache_word_size,
|
||||||
blk + pos * word_size,
|
blk + pos * map->cache_word_size,
|
||||||
(rbnode->blklen - pos) * word_size);
|
(rbnode->blklen - pos) * map->cache_word_size);
|
||||||
|
|
||||||
/* update the rbnode block, its size and the base register */
|
/* update the rbnode block, its size and the base register */
|
||||||
rbnode->block = blk;
|
rbnode->block = blk;
|
||||||
|
@ -292,7 +292,7 @@ static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode,
|
||||||
if (!pos)
|
if (!pos)
|
||||||
rbnode->base_reg = reg;
|
rbnode->base_reg = reg;
|
||||||
|
|
||||||
regcache_rbtree_set_register(rbnode, pos, value, word_size);
|
regcache_rbtree_set_register(map, rbnode, pos, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,8 +314,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
||||||
rbnode = regcache_rbtree_lookup(map, reg);
|
rbnode = regcache_rbtree_lookup(map, reg);
|
||||||
if (rbnode) {
|
if (rbnode) {
|
||||||
reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
|
reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
|
||||||
regcache_rbtree_set_register(rbnode, reg_tmp, value,
|
regcache_rbtree_set_register(map, rbnode, reg_tmp, value);
|
||||||
map->cache_word_size);
|
|
||||||
} else {
|
} else {
|
||||||
/* look for an adjacent register to the one we are about to add */
|
/* look for an adjacent register to the one we are about to add */
|
||||||
for (node = rb_first(&rbtree_ctx->root); node;
|
for (node = rb_first(&rbtree_ctx->root); node;
|
||||||
|
@ -332,9 +331,10 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
||||||
pos = i + 1;
|
pos = i + 1;
|
||||||
else
|
else
|
||||||
pos = i;
|
pos = i;
|
||||||
ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos,
|
ret = regcache_rbtree_insert_to_block(map,
|
||||||
reg, value,
|
rbnode_tmp,
|
||||||
map->cache_word_size);
|
pos, reg,
|
||||||
|
value);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
rbtree_ctx->cached_rbnode = rbnode_tmp;
|
rbtree_ctx->cached_rbnode = rbnode_tmp;
|
||||||
|
@ -357,7 +357,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
|
||||||
kfree(rbnode);
|
kfree(rbnode);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size);
|
regcache_rbtree_set_register(map, rbnode, 0, value);
|
||||||
regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
|
regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
|
||||||
rbtree_ctx->cached_rbnode = rbnode;
|
rbtree_ctx->cached_rbnode = rbnode;
|
||||||
}
|
}
|
||||||
|
@ -399,8 +399,7 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
|
||||||
|
|
||||||
for (i = base; i < end; i++) {
|
for (i = base; i < end; i++) {
|
||||||
regtmp = rbnode->base_reg + (i * map->reg_stride);
|
regtmp = rbnode->base_reg + (i * map->reg_stride);
|
||||||
val = regcache_rbtree_get_register(rbnode, i,
|
val = regcache_rbtree_get_register(map, rbnode, i);
|
||||||
map->cache_word_size);
|
|
||||||
|
|
||||||
/* Is this the hardware default? If so skip. */
|
/* Is this the hardware default? If so skip. */
|
||||||
ret = regcache_lookup_reg(map, regtmp);
|
ret = regcache_lookup_reg(map, regtmp);
|
||||||
|
|
|
@ -58,8 +58,7 @@ static int regcache_hw_init(struct regmap *map)
|
||||||
|
|
||||||
/* calculate the size of reg_defaults */
|
/* calculate the size of reg_defaults */
|
||||||
for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
|
for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
|
||||||
val = regcache_get_val(map->reg_defaults_raw,
|
val = regcache_get_val(map, map->reg_defaults_raw, i);
|
||||||
i, map->cache_word_size);
|
|
||||||
if (regmap_volatile(map, i * map->reg_stride))
|
if (regmap_volatile(map, i * map->reg_stride))
|
||||||
continue;
|
continue;
|
||||||
count++;
|
count++;
|
||||||
|
@ -75,8 +74,7 @@ static int regcache_hw_init(struct regmap *map)
|
||||||
/* fill the reg_defaults */
|
/* fill the reg_defaults */
|
||||||
map->num_reg_defaults = count;
|
map->num_reg_defaults = count;
|
||||||
for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
|
for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
|
||||||
val = regcache_get_val(map->reg_defaults_raw,
|
val = regcache_get_val(map, map->reg_defaults_raw, i);
|
||||||
i, map->cache_word_size);
|
|
||||||
if (regmap_volatile(map, i * map->reg_stride))
|
if (regmap_volatile(map, i * map->reg_stride))
|
||||||
continue;
|
continue;
|
||||||
map->reg_defaults[j].reg = i * map->reg_stride;
|
map->reg_defaults[j].reg = i * map->reg_stride;
|
||||||
|
@ -417,10 +415,10 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(regcache_cache_bypass);
|
EXPORT_SYMBOL_GPL(regcache_cache_bypass);
|
||||||
|
|
||||||
bool regcache_set_val(void *base, unsigned int idx,
|
bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
|
||||||
unsigned int val, unsigned int word_size)
|
unsigned int val)
|
||||||
{
|
{
|
||||||
switch (word_size) {
|
switch (map->cache_word_size) {
|
||||||
case 1: {
|
case 1: {
|
||||||
u8 *cache = base;
|
u8 *cache = base;
|
||||||
if (cache[idx] == val)
|
if (cache[idx] == val)
|
||||||
|
@ -448,13 +446,13 @@ bool regcache_set_val(void *base, unsigned int idx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int regcache_get_val(const void *base, unsigned int idx,
|
unsigned int regcache_get_val(struct regmap *map, const void *base,
|
||||||
unsigned int word_size)
|
unsigned int idx)
|
||||||
{
|
{
|
||||||
if (!base)
|
if (!base)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
switch (word_size) {
|
switch (map->cache_word_size) {
|
||||||
case 1: {
|
case 1: {
|
||||||
const u8 *cache = base;
|
const u8 *cache = base;
|
||||||
return cache[idx];
|
return cache[idx];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче