Commit 194c753a authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Mark Brown

regmap: rbtree: Simplify adjacent node look-up

A register which is adjacent to a node will either be left to the first
register or right to the last register. It will not be within the node's range,
so there is no point in checking for each register cached by the node whether
the new register is next to it. It is sufficient to check whether the register
comes before the first register or after the last register of the node.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 65c180fd
...@@ -352,9 +352,9 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -352,9 +352,9 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
struct regcache_rbtree_ctx *rbtree_ctx; struct regcache_rbtree_ctx *rbtree_ctx;
struct regcache_rbtree_node *rbnode, *rbnode_tmp; struct regcache_rbtree_node *rbnode, *rbnode_tmp;
struct rb_node *node; struct rb_node *node;
unsigned int base_reg, top_reg;
unsigned int reg_tmp; unsigned int reg_tmp;
unsigned int pos; unsigned int pos;
int i;
int ret; int ret;
rbtree_ctx = map->cache; rbtree_ctx = map->cache;
...@@ -376,25 +376,24 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -376,25 +376,24 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
node = rb_next(node)) { node = rb_next(node)) {
rbnode_tmp = rb_entry(node, struct regcache_rbtree_node, rbnode_tmp = rb_entry(node, struct regcache_rbtree_node,
node); node);
for (i = 0; i < rbnode_tmp->blklen; i++) {
reg_tmp = rbnode_tmp->base_reg + regcache_rbtree_get_base_top_reg(map, rbnode_tmp,
(i * map->reg_stride); &base_reg, &top_reg);
if (abs(reg_tmp - reg) != map->reg_stride)
continue; /* decide where in the block to place our register */
/* decide where in the block to place our register */ if (base_reg > 0 && reg == base_reg - map->reg_stride)
if (reg_tmp + map->reg_stride == reg) pos = 0;
pos = i + 1; else if (reg > 0 && reg - map->reg_stride == top_reg)
else pos = rbnode_tmp->blklen;
pos = i; else
ret = regcache_rbtree_insert_to_block(map, continue;
rbnode_tmp,
pos, reg, ret = regcache_rbtree_insert_to_block(map, rbnode_tmp,
value); pos, reg, value);
if (ret) if (ret)
return ret; return ret;
rbtree_ctx->cached_rbnode = rbnode_tmp; rbtree_ctx->cached_rbnode = rbnode_tmp;
return 0; return 0;
}
} }
/* We did not manage to find a place to insert it in /* We did not manage to find a place to insert it in
......
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