summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-03-29 21:12:21 +0100
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-03-30 14:52:31 +0100
commitcfdeb8c37ed32024dcb7d2e3bd70e2a9f9dfc0e6 (patch)
treee10157dd5d641acc1a680f4615e7ecb013f1f311 /drivers/base
parentregmap: cache: Factor out block sync (diff)
downloadlinux-cfdeb8c37ed32024dcb7d2e3bd70e2a9f9dfc0e6.tar.xz
linux-cfdeb8c37ed32024dcb7d2e3bd70e2a9f9dfc0e6.zip
regmap: cache: Split raw and non-raw syncs
For code clarity after implementing block writes split out the raw and non-raw I/O sync implementations. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Reviewed-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/regmap/regcache.c64
1 files changed, 53 insertions, 11 deletions
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index bb317db6818f..da4d9843520f 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -545,9 +545,43 @@ int regcache_lookup_reg(struct regmap *map, unsigned int reg)
return -ENOENT;
}
-int regcache_sync_block(struct regmap *map, void *block,
- unsigned int block_base, unsigned int start,
- unsigned int end)
+static int regcache_sync_block_single(struct regmap *map, void *block,
+ unsigned int block_base,
+ unsigned int start, unsigned int end)
+{
+ unsigned int i, regtmp, val;
+ int ret;
+
+ for (i = start; i < end; i++) {
+ regtmp = block_base + (i * map->reg_stride);
+
+ if (!regcache_reg_present(map, regtmp))
+ continue;
+
+ val = regcache_get_val(map, block, i);
+
+ /* Is this the hardware default? If so skip. */
+ ret = regcache_lookup_reg(map, regtmp);
+ if (ret >= 0 && val == map->reg_defaults[ret].def)
+ continue;
+
+ map->cache_bypass = 1;
+
+ ret = _regmap_write(map, regtmp, val);
+
+ map->cache_bypass = 0;
+ if (ret != 0)
+ return ret;
+ dev_dbg(map->dev, "Synced register %#x, value %#x\n",
+ regtmp, val);
+ }
+
+ return 0;
+}
+
+int regcache_sync_block_raw(struct regmap *map, void *block,
+ unsigned int block_base, unsigned int start,
+ unsigned int end)
{
unsigned int i, regtmp, val;
const void *addr;
@@ -568,14 +602,10 @@ int regcache_sync_block(struct regmap *map, void *block,
map->cache_bypass = 1;
- if (regmap_can_raw_write(map)) {
- addr = regcache_get_val_addr(map, block, i);
- ret = _regmap_raw_write(map, regtmp, addr,
- map->format.val_bytes,
- false);
- } else {
- ret = _regmap_write(map, regtmp, val);
- }
+ addr = regcache_get_val_addr(map, block, i);
+ ret = _regmap_raw_write(map, regtmp, addr,
+ map->format.val_bytes,
+ false);
map->cache_bypass = 0;
if (ret != 0)
@@ -586,3 +616,15 @@ int regcache_sync_block(struct regmap *map, void *block,
return 0;
}
+
+int regcache_sync_block(struct regmap *map, void *block,
+ unsigned int block_base, unsigned int start,
+ unsigned int end)
+{
+ if (regmap_can_raw_write(map))
+ return regcache_sync_block_raw(map, block, block_base,
+ start, end);
+ else
+ return regcache_sync_block_single(map, block, block_base,
+ start, end);
+}