Skip to content

Commit 05933e2

Browse files
committed
regmap: Factor out single value register syncing
In order to support sparse caches that don't store data in raw format factor out the parts of the raw block sync implementation that deal with writing a single register via _regmap_write(). Signed-off-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20230325-regcache-maple-v3-1-23e271f93dc7@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 2238959 commit 05933e2

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

drivers/base/regmap/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ unsigned int regcache_get_val(struct regmap *map, const void *base,
270270
bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
271271
unsigned int val);
272272
int regcache_lookup_reg(struct regmap *map, unsigned int reg);
273+
int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val);
273274

274275
int _regmap_raw_write(struct regmap *map, unsigned int reg,
275276
const void *val, size_t val_len, bool noinc);

drivers/base/regmap/regcache.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,30 @@ static bool regcache_reg_present(unsigned long *cache_present, unsigned int idx)
677677
return test_bit(idx, cache_present);
678678
}
679679

680+
int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val)
681+
{
682+
int ret;
683+
684+
if (!regcache_reg_needs_sync(map, reg, val))
685+
return 0;
686+
687+
map->cache_bypass = true;
688+
689+
ret = _regmap_write(map, reg, val);
690+
691+
map->cache_bypass = false;
692+
693+
if (ret != 0) {
694+
dev_err(map->dev, "Unable to sync register %#x. %d\n",
695+
reg, ret);
696+
return ret;
697+
}
698+
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
699+
reg, val);
700+
701+
return 0;
702+
}
703+
680704
static int regcache_sync_block_single(struct regmap *map, void *block,
681705
unsigned long *cache_present,
682706
unsigned int block_base,
@@ -693,21 +717,9 @@ static int regcache_sync_block_single(struct regmap *map, void *block,
693717
continue;
694718

695719
val = regcache_get_val(map, block, i);
696-
if (!regcache_reg_needs_sync(map, regtmp, val))
697-
continue;
698-
699-
map->cache_bypass = true;
700-
701-
ret = _regmap_write(map, regtmp, val);
702-
703-
map->cache_bypass = false;
704-
if (ret != 0) {
705-
dev_err(map->dev, "Unable to sync register %#x. %d\n",
706-
regtmp, ret);
720+
ret = regcache_sync_val(map, regtmp, val);
721+
if (ret != 0)
707722
return ret;
708-
}
709-
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
710-
regtmp, val);
711723
}
712724

713725
return 0;

0 commit comments

Comments
 (0)