aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-02-21 13:03:13 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-03-03 21:30:27 -0500
commit879082c9fe6e8fbddf787170eee605e4be138d0f (patch)
tree90d721437b67177dae4a2e84348002d74835710d /drivers/base
parent66baf407571662f7e2a22dd0764cbe279559446c (diff)
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>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/internal.h8
-rw-r--r--drivers/base/regmap/regcache-lzo.c6
-rw-r--r--drivers/base/regmap/regcache-rbtree.c51
-rw-r--r--drivers/base/regmap/regcache.c18
4 files changed, 39 insertions, 44 deletions
diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 5a22bd33ce3d..582d7fdf414b 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -188,10 +188,10 @@ int regcache_write(struct regmap *map,
188 unsigned int reg, unsigned int value); 188 unsigned int reg, unsigned int value);
189int regcache_sync(struct regmap *map); 189int regcache_sync(struct regmap *map);
190 190
191unsigned int regcache_get_val(const void *base, unsigned int idx, 191unsigned int regcache_get_val(struct regmap *map, const void *base,
192 unsigned int word_size); 192 unsigned int idx);
193bool regcache_set_val(void *base, unsigned int idx, 193bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
194 unsigned int val, unsigned int word_size); 194 unsigned int val);
195int regcache_lookup_reg(struct regmap *map, unsigned int reg); 195int regcache_lookup_reg(struct regmap *map, unsigned int reg);
196 196
197void regmap_async_complete_cb(struct regmap_async *async, int ret); 197void regmap_async_complete_cb(struct regmap_async *async, int ret);
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c
index afd6aa91a0df..e210a6d1406a 100644
--- a/drivers/base/regmap/regcache-lzo.c
+++ b/drivers/base/regmap/regcache-lzo.c
@@ -260,8 +260,7 @@ static int regcache_lzo_read(struct regmap *map,
260 ret = regcache_lzo_decompress_cache_block(map, lzo_block); 260 ret = regcache_lzo_decompress_cache_block(map, lzo_block);
261 if (ret >= 0) 261 if (ret >= 0)
262 /* fetch the value from the cache */ 262 /* fetch the value from the cache */
263 *value = regcache_get_val(lzo_block->dst, blkpos, 263 *value = regcache_get_val(map, lzo_block->dst, blkpos);
264 map->cache_word_size);
265 264
266 kfree(lzo_block->dst); 265 kfree(lzo_block->dst);
267 /* restore the pointer and length of the compressed block */ 266 /* restore the pointer and length of the compressed block */
@@ -304,8 +303,7 @@ static int regcache_lzo_write(struct regmap *map,
304 } 303 }
305 304
306 /* write the new value to the cache */ 305 /* write the new value to the cache */
307 if (regcache_set_val(lzo_block->dst, blkpos, value, 306 if (regcache_set_val(map, lzo_block->dst, blkpos, value)) {
308 map->cache_word_size)) {
309 kfree(lzo_block->dst); 307 kfree(lzo_block->dst);
310 goto out; 308 goto out;
311 } 309 }
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 3f21c6ab296f..461cff888bb1 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -47,22 +47,21 @@ static inline void regcache_rbtree_get_base_top_reg(
47 *top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride); 47 *top = rbnode->base_reg + ((rbnode->blklen - 1) * map->reg_stride);
48} 48}
49 49
50static unsigned int regcache_rbtree_get_register( 50static unsigned int regcache_rbtree_get_register(struct regmap *map,
51 struct regcache_rbtree_node *rbnode, unsigned int idx, 51 struct regcache_rbtree_node *rbnode, unsigned int idx)
52 unsigned int word_size)
53{ 52{
54 return regcache_get_val(rbnode->block, idx, word_size); 53 return regcache_get_val(map, rbnode->block, idx);
55} 54}
56 55
57static void regcache_rbtree_set_register(struct regcache_rbtree_node *rbnode, 56static void regcache_rbtree_set_register(struct regmap *map,
58 unsigned int idx, unsigned int val, 57 struct regcache_rbtree_node *rbnode,
59 unsigned int word_size) 58 unsigned int idx, unsigned int val)
60{ 59{
61 regcache_set_val(rbnode->block, idx, val, word_size); 60 regcache_set_val(map, rbnode->block, idx, val);
62} 61}
63 62
64static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map, 63static struct regcache_rbtree_node *regcache_rbtree_lookup(struct regmap *map,
65 unsigned int reg) 64 unsigned int reg)
66{ 65{
67 struct regcache_rbtree_ctx *rbtree_ctx = map->cache; 66 struct regcache_rbtree_ctx *rbtree_ctx = map->cache;
68 struct rb_node *node; 67 struct rb_node *node;
@@ -260,8 +259,7 @@ static int regcache_rbtree_read(struct regmap *map,
260 rbnode = regcache_rbtree_lookup(map, reg); 259 rbnode = regcache_rbtree_lookup(map, reg);
261 if (rbnode) { 260 if (rbnode) {
262 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride; 261 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
263 *value = regcache_rbtree_get_register(rbnode, reg_tmp, 262 *value = regcache_rbtree_get_register(map, rbnode, reg_tmp);
264 map->cache_word_size);
265 } else { 263 } else {
266 return -ENOENT; 264 return -ENOENT;
267 } 265 }
@@ -270,21 +268,23 @@ static int regcache_rbtree_read(struct regmap *map,
270} 268}
271 269
272 270
273static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode, 271static int regcache_rbtree_insert_to_block(struct regmap *map,
272 struct regcache_rbtree_node *rbnode,
274 unsigned int pos, unsigned int reg, 273 unsigned int pos, unsigned int reg,
275 unsigned int value, unsigned int word_size) 274 unsigned int value)
276{ 275{
277 u8 *blk; 276 u8 *blk;
278 277
279 blk = krealloc(rbnode->block, 278 blk = krealloc(rbnode->block,
280 (rbnode->blklen + 1) * word_size, GFP_KERNEL); 279 (rbnode->blklen + 1) * map->cache_word_size,
280 GFP_KERNEL);
281 if (!blk) 281 if (!blk)
282 return -ENOMEM; 282 return -ENOMEM;
283 283
284 /* insert the register value in the correct place in the rbnode block */ 284 /* insert the register value in the correct place in the rbnode block */
285 memmove(blk + (pos + 1) * word_size, 285 memmove(blk + (pos + 1) * map->cache_word_size,
286 blk + pos * word_size, 286 blk + pos * map->cache_word_size,
287 (rbnode->blklen - pos) * word_size); 287 (rbnode->blklen - pos) * map->cache_word_size);
288 288
289 /* update the rbnode block, its size and the base register */ 289 /* update the rbnode block, its size and the base register */
290 rbnode->block = blk; 290 rbnode->block = blk;
@@ -292,7 +292,7 @@ static int regcache_rbtree_insert_to_block(struct regcache_rbtree_node *rbnode,
292 if (!pos) 292 if (!pos)
293 rbnode->base_reg = reg; 293 rbnode->base_reg = reg;
294 294
295 regcache_rbtree_set_register(rbnode, pos, value, word_size); 295 regcache_rbtree_set_register(map, rbnode, pos, value);
296 return 0; 296 return 0;
297} 297}
298 298
@@ -314,8 +314,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
314 rbnode = regcache_rbtree_lookup(map, reg); 314 rbnode = regcache_rbtree_lookup(map, reg);
315 if (rbnode) { 315 if (rbnode) {
316 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride; 316 reg_tmp = (reg - rbnode->base_reg) / map->reg_stride;
317 regcache_rbtree_set_register(rbnode, reg_tmp, value, 317 regcache_rbtree_set_register(map, rbnode, reg_tmp, value);
318 map->cache_word_size);
319 } else { 318 } else {
320 /* look for an adjacent register to the one we are about to add */ 319 /* look for an adjacent register to the one we are about to add */
321 for (node = rb_first(&rbtree_ctx->root); node; 320 for (node = rb_first(&rbtree_ctx->root); node;
@@ -332,9 +331,10 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
332 pos = i + 1; 331 pos = i + 1;
333 else 332 else
334 pos = i; 333 pos = i;
335 ret = regcache_rbtree_insert_to_block(rbnode_tmp, pos, 334 ret = regcache_rbtree_insert_to_block(map,
336 reg, value, 335 rbnode_tmp,
337 map->cache_word_size); 336 pos, reg,
337 value);
338 if (ret) 338 if (ret)
339 return ret; 339 return ret;
340 rbtree_ctx->cached_rbnode = rbnode_tmp; 340 rbtree_ctx->cached_rbnode = rbnode_tmp;
@@ -357,7 +357,7 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
357 kfree(rbnode); 357 kfree(rbnode);
358 return -ENOMEM; 358 return -ENOMEM;
359 } 359 }
360 regcache_rbtree_set_register(rbnode, 0, value, map->cache_word_size); 360 regcache_rbtree_set_register(map, rbnode, 0, value);
361 regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode); 361 regcache_rbtree_insert(map, &rbtree_ctx->root, rbnode);
362 rbtree_ctx->cached_rbnode = rbnode; 362 rbtree_ctx->cached_rbnode = rbnode;
363 } 363 }
@@ -399,8 +399,7 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
399 399
400 for (i = base; i < end; i++) { 400 for (i = base; i < end; i++) {
401 regtmp = rbnode->base_reg + (i * map->reg_stride); 401 regtmp = rbnode->base_reg + (i * map->reg_stride);
402 val = regcache_rbtree_get_register(rbnode, i, 402 val = regcache_rbtree_get_register(map, rbnode, i);
403 map->cache_word_size);
404 403
405 /* Is this the hardware default? If so skip. */ 404 /* Is this the hardware default? If so skip. */
406 ret = regcache_lookup_reg(map, regtmp); 405 ret = regcache_lookup_reg(map, regtmp);
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index e69ff3e4742c..f0a3db6ff9c2 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -58,8 +58,7 @@ static int regcache_hw_init(struct regmap *map)
58 58
59 /* calculate the size of reg_defaults */ 59 /* calculate the size of reg_defaults */
60 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) { 60 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
61 val = regcache_get_val(map->reg_defaults_raw, 61 val = regcache_get_val(map, map->reg_defaults_raw, i);
62 i, map->cache_word_size);
63 if (regmap_volatile(map, i * map->reg_stride)) 62 if (regmap_volatile(map, i * map->reg_stride))
64 continue; 63 continue;
65 count++; 64 count++;
@@ -75,8 +74,7 @@ static int regcache_hw_init(struct regmap *map)
75 /* fill the reg_defaults */ 74 /* fill the reg_defaults */
76 map->num_reg_defaults = count; 75 map->num_reg_defaults = count;
77 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { 76 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
78 val = regcache_get_val(map->reg_defaults_raw, 77 val = regcache_get_val(map, map->reg_defaults_raw, i);
79 i, map->cache_word_size);
80 if (regmap_volatile(map, i * map->reg_stride)) 78 if (regmap_volatile(map, i * map->reg_stride))
81 continue; 79 continue;
82 map->reg_defaults[j].reg = i * map->reg_stride; 80 map->reg_defaults[j].reg = i * map->reg_stride;
@@ -417,10 +415,10 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
417} 415}
418EXPORT_SYMBOL_GPL(regcache_cache_bypass); 416EXPORT_SYMBOL_GPL(regcache_cache_bypass);
419 417
420bool regcache_set_val(void *base, unsigned int idx, 418bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
421 unsigned int val, unsigned int word_size) 419 unsigned int val)
422{ 420{
423 switch (word_size) { 421 switch (map->cache_word_size) {
424 case 1: { 422 case 1: {
425 u8 *cache = base; 423 u8 *cache = base;
426 if (cache[idx] == val) 424 if (cache[idx] == val)
@@ -448,13 +446,13 @@ bool regcache_set_val(void *base, unsigned int idx,
448 return false; 446 return false;
449} 447}
450 448
451unsigned int regcache_get_val(const void *base, unsigned int idx, 449unsigned int regcache_get_val(struct regmap *map, const void *base,
452 unsigned int word_size) 450 unsigned int idx)
453{ 451{
454 if (!base) 452 if (!base)
455 return -EINVAL; 453 return -EINVAL;
456 454
457 switch (word_size) { 455 switch (map->cache_word_size) {
458 case 1: { 456 case 1: {
459 const u8 *cache = base; 457 const u8 *cache = base;
460 return cache[idx]; 458 return cache[idx];