Commit 25ed1156 authored by Dimitris Papastamos's avatar Dimitris Papastamos Committed by Mark Brown

regmap: Remove redundant member `word_size' from regcache_rbtree_node

Signed-off-by: default avatarDimitris Papastamos <dp@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 523d9cfb
...@@ -23,8 +23,6 @@ struct regcache_rbtree_node { ...@@ -23,8 +23,6 @@ struct regcache_rbtree_node {
struct rb_node node; struct rb_node node;
/* base register handled by this block */ /* base register handled by this block */
unsigned int base_reg; unsigned int base_reg;
/* number of bytes needed to represent the register index */
unsigned int word_size;
/* block of adjacent registers */ /* block of adjacent registers */
void *block; void *block;
/* number of registers available in the block */ /* number of registers available in the block */
...@@ -45,11 +43,12 @@ static inline void regcache_rbtree_get_base_top_reg( ...@@ -45,11 +43,12 @@ static inline void regcache_rbtree_get_base_top_reg(
} }
static unsigned int regcache_rbtree_get_register( static unsigned int regcache_rbtree_get_register(
struct regcache_rbtree_node *rbnode, unsigned int idx) struct regcache_rbtree_node *rbnode, unsigned int idx,
unsigned int word_size)
{ {
unsigned int val; unsigned int val;
switch (rbnode->word_size) { switch (word_size) {
case 1: { case 1: {
u8 *p = rbnode->block; u8 *p = rbnode->block;
val = p[idx]; val = p[idx];
...@@ -68,9 +67,10 @@ static unsigned int regcache_rbtree_get_register( ...@@ -68,9 +67,10 @@ static unsigned int regcache_rbtree_get_register(
} }
static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode, static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode,
unsigned int idx, unsigned int val) unsigned int idx, unsigned int val,
unsigned int word_size)
{ {
switch (rbnode->word_size) { switch (word_size) {
case 1: { case 1: {
u8 *p = rbnode->block; u8 *p = rbnode->block;
p[idx] = val; p[idx] = val;
...@@ -217,7 +217,8 @@ static int regcache_rbtree_read(struct regmap *map, ...@@ -217,7 +217,8 @@ static int regcache_rbtree_read(struct regmap *map,
regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg);
if (reg >= base_reg && reg <= top_reg) { if (reg >= base_reg && reg <= top_reg) {
reg_tmp = reg - base_reg; reg_tmp = reg - base_reg;
*value = regcache_rbtree_get_register(rbnode, reg_tmp); *value = regcache_rbtree_get_register(rbnode, reg_tmp,
map->cache_word_size);
return 0; return 0;
} }
} }
...@@ -227,7 +228,8 @@ static int regcache_rbtree_read(struct regmap *map, ...@@ -227,7 +228,8 @@ static int regcache_rbtree_read(struct regmap *map,
rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg); rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg);
if (rbnode) { if (rbnode) {
reg_tmp = reg - rbnode->base_reg; reg_tmp = reg - rbnode->base_reg;
*value = regcache_rbtree_get_register(rbnode, reg_tmp); *value = regcache_rbtree_get_register(rbnode, reg_tmp,
map->cache_word_size);
rbtree_ctx->cached_rbnode = rbnode; rbtree_ctx->cached_rbnode = rbnode;
} else { } else {
/* uninitialized registers default to 0 */ /* uninitialized registers default to 0 */
...@@ -240,19 +242,19 @@ static int regcache_rbtree_read(struct regmap *map, ...@@ -240,19 +242,19 @@ 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 regcache_rbtree_node *rbnode,
unsigned int pos, unsigned int reg, unsigned int pos, unsigned int reg,
unsigned int value) unsigned int value, unsigned int word_size)
{ {
u8 *blk; u8 *blk;
blk = krealloc(rbnode->block, blk = krealloc(rbnode->block,
(rbnode->blklen + 1) * rbnode->word_size, GFP_KERNEL); (rbnode->blklen + 1) * 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) * rbnode->word_size, memmove(blk + (pos + 1) * word_size,
blk + pos * rbnode->word_size, blk + pos * word_size,
(rbnode->blklen - pos) * rbnode->word_size); (rbnode->blklen - pos) * 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;
...@@ -260,7 +262,7 @@ static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode, ...@@ -260,7 +262,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); regcache_rbtree_set_register(rbnode, pos, value, word_size);
return 0; return 0;
} }
...@@ -284,10 +286,12 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -284,10 +286,12 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg); regcache_rbtree_get_base_top_reg(rbnode, &base_reg, &top_reg);
if (reg >= base_reg && reg <= top_reg) { if (reg >= base_reg && reg <= top_reg) {
reg_tmp = reg - base_reg; reg_tmp = reg - base_reg;
val = regcache_rbtree_get_register(rbnode, reg_tmp); val = regcache_rbtree_get_register(rbnode, reg_tmp,
map->cache_word_size);
if (val == value) if (val == value)
return 0; return 0;
regcache_rbtree_set_register(rbnode, reg_tmp, value); regcache_rbtree_set_register(rbnode, reg_tmp, value,
map->cache_word_size);
return 0; return 0;
} }
} }
...@@ -297,10 +301,12 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -297,10 +301,12 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg); rbnode = regcache_rbtree_lookup(&rbtree_ctx->root, reg);
if (rbnode) { if (rbnode) {
reg_tmp = reg - rbnode->base_reg; reg_tmp = reg - rbnode->base_reg;
val = regcache_rbtree_get_register(rbnode, reg_tmp); val = regcache_rbtree_get_register(rbnode, reg_tmp,
map->cache_word_size);
if (val == value) if (val == value)
return 0; return 0;
regcache_rbtree_set_register(rbnode, reg_tmp, value); regcache_rbtree_set_register(rbnode, reg_tmp, value,
map->cache_word_size);
rbtree_ctx->cached_rbnode = rbnode; rbtree_ctx->cached_rbnode = rbnode;
} else { } else {
/* bail out early, no need to create the rbnode yet */ /* bail out early, no need to create the rbnode yet */
...@@ -320,7 +326,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -320,7 +326,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
else else
pos = i; pos = i;
ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos, ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos,
reg, value); reg, value,
map->cache_word_size);
if (ret) if (ret)
return ret; return ret;
rbtree_ctx->cached_rbnode = rbnode_tmp; rbtree_ctx->cached_rbnode = rbnode_tmp;
...@@ -337,14 +344,13 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -337,14 +344,13 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
return -ENOMEM; return -ENOMEM;
rbnode->blklen = 1; rbnode->blklen = 1;
rbnode->base_reg = reg; rbnode->base_reg = reg;
rbnode->word_size = map->cache_word_size; rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size,
rbnode->block = kmalloc(rbnode->blklen * rbnode->word_size,
GFP_KERNEL); GFP_KERNEL);
if (!rbnode->block) { if (!rbnode->block) {
kfree(rbnode); kfree(rbnode);
return -ENOMEM; return -ENOMEM;
} }
regcache_rbtree_set_register(rbnode, 0, value); regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size);
regcache_rbtree_insert(&rbtree_ctx->root, rbnode); regcache_rbtree_insert(&rbtree_ctx->root, rbnode);
rbtree_ctx->cached_rbnode = rbnode; rbtree_ctx->cached_rbnode = rbnode;
} }
...@@ -367,7 +373,8 @@ static int regcache_rbtree_sync(struct regmap *map) ...@@ -367,7 +373,8 @@ static int regcache_rbtree_sync(struct regmap *map)
rbnode = rb_entry(node, struct regcache_rbtree_node, node); rbnode = rb_entry(node, struct regcache_rbtree_node, node);
for (i = 0; i < rbnode->blklen; i++) { for (i = 0; i < rbnode->blklen; i++) {
regtmp = rbnode->base_reg + i; regtmp = rbnode->base_reg + i;
val = regcache_rbtree_get_register(rbnode, i); val = regcache_rbtree_get_register(rbnode, i,
map->cache_word_size);
ret = regcache_lookup_reg(map, i); ret = regcache_lookup_reg(map, i);
if (ret < 0) if (ret < 0)
def = 0; def = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment