Skip to content

Commit

Permalink
regmap: Factor out single value register syncing
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
broonie committed Apr 3, 2023
1 parent 2238959 commit 05933e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions drivers/base/regmap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ unsigned int regcache_get_val(struct regmap *map, const void *base,
bool regcache_set_val(struct regmap *map, void *base, unsigned int idx,
unsigned int val);
int regcache_lookup_reg(struct regmap *map, unsigned int reg);
int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val);

int _regmap_raw_write(struct regmap *map, unsigned int reg,
const void *val, size_t val_len, bool noinc);
Expand Down
40 changes: 26 additions & 14 deletions drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,30 @@ static bool regcache_reg_present(unsigned long *cache_present, unsigned int idx)
return test_bit(idx, cache_present);
}

int regcache_sync_val(struct regmap *map, unsigned int reg, unsigned int val)
{
int ret;

if (!regcache_reg_needs_sync(map, reg, val))
return 0;

map->cache_bypass = true;

ret = _regmap_write(map, reg, val);

map->cache_bypass = false;

if (ret != 0) {
dev_err(map->dev, "Unable to sync register %#x. %d\n",
reg, ret);
return ret;
}
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
reg, val);

return 0;
}

static int regcache_sync_block_single(struct regmap *map, void *block,
unsigned long *cache_present,
unsigned int block_base,
Expand All @@ -693,21 +717,9 @@ static int regcache_sync_block_single(struct regmap *map, void *block,
continue;

val = regcache_get_val(map, block, i);
if (!regcache_reg_needs_sync(map, regtmp, val))
continue;

map->cache_bypass = true;

ret = _regmap_write(map, regtmp, val);

map->cache_bypass = false;
if (ret != 0) {
dev_err(map->dev, "Unable to sync register %#x. %d\n",
regtmp, ret);
ret = regcache_sync_val(map, regtmp, val);
if (ret != 0)
return ret;
}
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
regtmp, val);
}

return 0;
Expand Down

0 comments on commit 05933e2

Please sign in to comment.