Skip to content

Commit f8bd822

Browse files
committed
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 <[email protected]> Reviewed-by: Dimitris Papastamos <[email protected]>
1 parent 78493f2 commit f8bd822

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

drivers/base/regmap/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ int regcache_read(struct regmap *map,
191191
int regcache_write(struct regmap *map,
192192
unsigned int reg, unsigned int value);
193193
int regcache_sync(struct regmap *map);
194+
int regcache_sync_block(struct regmap *map, void *block,
195+
unsigned int block_base, unsigned int start,
196+
unsigned int end);
194197

195198
static inline const void *regcache_get_val_addr(struct regmap *map,
196199
const void *base,

drivers/base/regmap/regcache-rbtree.c

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ static unsigned int regcache_rbtree_get_register(struct regmap *map,
5353
return regcache_get_val(map, rbnode->block, idx);
5454
}
5555

56-
static const void *regcache_rbtree_get_reg_addr(struct regmap *map,
57-
struct regcache_rbtree_node *rbnode, unsigned int idx)
58-
{
59-
return regcache_get_val_addr(map, rbnode->block, idx);
60-
}
61-
6256
static void regcache_rbtree_set_register(struct regmap *map,
6357
struct regcache_rbtree_node *rbnode,
6458
unsigned int idx, unsigned int val)
@@ -390,11 +384,8 @@ static int regcache_rbtree_sync(struct regmap *map, unsigned int min,
390384
struct regcache_rbtree_ctx *rbtree_ctx;
391385
struct rb_node *node;
392386
struct regcache_rbtree_node *rbnode;
393-
unsigned int regtmp;
394-
unsigned int val;
395-
const void *addr;
396387
int ret;
397-
int i, base, end;
388+
int base, end;
398389

399390
rbtree_ctx = map->cache;
400391
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,
417408
else
418409
end = rbnode->blklen;
419410

420-
for (i = base; i < end; i++) {
421-
regtmp = rbnode->base_reg + (i * map->reg_stride);
422-
423-
if (!regcache_reg_present(map, regtmp))
424-
continue;
425-
426-
val = regcache_rbtree_get_register(map, rbnode, i);
427-
428-
/* Is this the hardware default? If so skip. */
429-
ret = regcache_lookup_reg(map, regtmp);
430-
if (ret >= 0 && val == map->reg_defaults[ret].def)
431-
continue;
432-
433-
map->cache_bypass = 1;
434-
435-
if (regmap_can_raw_write(map)) {
436-
addr = regcache_rbtree_get_reg_addr(map,
437-
rbnode, i);
438-
ret = _regmap_raw_write(map, regtmp, addr,
439-
map->format.val_bytes,
440-
false);
441-
} else {
442-
ret = _regmap_write(map, regtmp, val);
443-
}
444-
445-
map->cache_bypass = 0;
446-
if (ret)
447-
return ret;
448-
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
449-
regtmp, val);
450-
}
411+
ret = regcache_sync_block(map, rbnode->block, rbnode->base_reg,
412+
base, end);
413+
if (ret != 0)
414+
return ret;
451415
}
452416

453-
return 0;
417+
return regmap_async_complete(map);
454418
}
455419

456420
struct regcache_ops regcache_rbtree_ops = {

drivers/base/regmap/regcache.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,45 @@ int regcache_lookup_reg(struct regmap *map, unsigned int reg)
544544
else
545545
return -ENOENT;
546546
}
547+
548+
int regcache_sync_block(struct regmap *map, void *block,
549+
unsigned int block_base, unsigned int start,
550+
unsigned int end)
551+
{
552+
unsigned int i, regtmp, val;
553+
const void *addr;
554+
int ret;
555+
556+
for (i = start; i < end; i++) {
557+
regtmp = block_base + (i * map->reg_stride);
558+
559+
if (!regcache_reg_present(map, regtmp))
560+
continue;
561+
562+
val = regcache_get_val(map, block, i);
563+
564+
/* Is this the hardware default? If so skip. */
565+
ret = regcache_lookup_reg(map, regtmp);
566+
if (ret >= 0 && val == map->reg_defaults[ret].def)
567+
continue;
568+
569+
map->cache_bypass = 1;
570+
571+
if (regmap_can_raw_write(map)) {
572+
addr = regcache_get_val_addr(map, block, i);
573+
ret = _regmap_raw_write(map, regtmp, addr,
574+
map->format.val_bytes,
575+
false);
576+
} else {
577+
ret = _regmap_write(map, regtmp, val);
578+
}
579+
580+
map->cache_bypass = 0;
581+
if (ret != 0)
582+
return ret;
583+
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
584+
regtmp, val);
585+
}
586+
587+
return 0;
588+
}

0 commit comments

Comments
 (0)