regmap: Add a helper function for regcache sync test

We're going to add another "does this register need syncing?" check, so
rather than repeating it in three places, we'll separate all of the
relevant logic into a helper function.

Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kevin Cernekee 2015-05-05 15:14:13 -07:00 committed by Mark Brown
parent b787f68c36
commit 3969fa0806

View file

@ -249,6 +249,18 @@ int regcache_write(struct regmap *map,
return 0; return 0;
} }
static bool regcache_reg_needs_sync(struct regmap *map, unsigned int reg,
unsigned int val)
{
int ret;
/* Is this the hardware default? If so skip. */
ret = regcache_lookup_reg(map, reg);
if (ret >= 0 && val == map->reg_defaults[ret].def)
return false;
return true;
}
static int regcache_default_sync(struct regmap *map, unsigned int min, static int regcache_default_sync(struct regmap *map, unsigned int min,
unsigned int max) unsigned int max)
{ {
@ -266,9 +278,7 @@ static int regcache_default_sync(struct regmap *map, unsigned int min,
if (ret) if (ret)
return ret; return ret;
/* Is this the hardware default? If so skip. */ if (!regcache_reg_needs_sync(map, reg, val))
ret = regcache_lookup_reg(map, reg);
if (ret >= 0 && val == map->reg_defaults[ret].def)
continue; continue;
map->cache_bypass = 1; map->cache_bypass = 1;
@ -613,10 +623,7 @@ static int regcache_sync_block_single(struct regmap *map, void *block,
continue; continue;
val = regcache_get_val(map, block, i); val = regcache_get_val(map, block, i);
if (!regcache_reg_needs_sync(map, regtmp, val))
/* Is this the hardware default? If so skip. */
ret = regcache_lookup_reg(map, regtmp);
if (ret >= 0 && val == map->reg_defaults[ret].def)
continue; continue;
map->cache_bypass = 1; map->cache_bypass = 1;
@ -688,10 +695,7 @@ static int regcache_sync_block_raw(struct regmap *map, void *block,
} }
val = regcache_get_val(map, block, i); val = regcache_get_val(map, block, i);
if (!regcache_reg_needs_sync(map, regtmp, val)) {
/* Is this the hardware default? If so skip. */
ret = regcache_lookup_reg(map, regtmp);
if (ret >= 0 && val == map->reg_defaults[ret].def) {
ret = regcache_sync_block_raw_flush(map, &data, ret = regcache_sync_block_raw_flush(map, &data,
base, regtmp); base, regtmp);
if (ret != 0) if (ret != 0)