From c3ec23288a92e20e0aff84a4cb6fbc7cc9bcf567 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 23 Feb 2012 20:48:40 +0000 Subject: regmap: Remove default cache sync implementation It's not used as all cache types have sync operations so it's just dead code which never gets tested. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'drivers/base/regmap/regcache.c') diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index ee36bed9479c..4d43ed363481 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -254,12 +254,11 @@ EXPORT_SYMBOL_GPL(regcache_write); int regcache_sync(struct regmap *map) { int ret = 0; - unsigned int val; unsigned int i; const char *name; unsigned int bypass; - BUG_ON(!map->cache_ops); + BUG_ON(!map->cache_ops || !map->cache_ops->sync); mutex_lock(&map->lock); /* Remember the initial bypass state */ @@ -284,24 +283,8 @@ int regcache_sync(struct regmap *map) } map->cache_bypass = 0; - if (map->cache_ops->sync) { - ret = map->cache_ops->sync(map); - } else { - for (i = 0; i < map->num_reg_defaults; i++) { - ret = regcache_read(map, i, &val); - if (ret < 0) - goto out; - map->cache_bypass = 1; - ret = _regmap_write(map, i, val); - map->cache_bypass = 0; - if (ret < 0) - goto out; - dev_dbg(map->dev, "Synced register %#x, value %#x\n", - map->reg_defaults[i].reg, - map->reg_defaults[i].def); - } + ret = map->cache_ops->sync(map); - } out: trace_regcache_sync(map->dev, name, "stop"); /* Restore the bypass state */ -- cgit v1.2.1 From 6ff7373809a9b4eb644d83e2e299da297e1cbffa Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 23 Feb 2012 22:05:59 +0000 Subject: regmap: Mark the cache as clean after a successful sync Previously the cache would never be marked clean, meaning syncs would never be suppressed which isn't the end of the world but could be inefficient. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/base/regmap/regcache.c') diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 4d43ed363481..46c42d3a4655 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -285,6 +285,9 @@ int regcache_sync(struct regmap *map) ret = map->cache_ops->sync(map); + if (ret == 0) + map->cache_dirty = false; + out: trace_regcache_sync(map->dev, name, "stop"); /* Restore the bypass state */ -- cgit v1.2.1 From ac8d91c801905a061ca883dca427a5e19602a1e7 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 23 Feb 2012 19:31:04 +0000 Subject: regmap: Supply ranges to the sync operations In order to allow us to support partial sync operations add minimum and maximum register arguments to the sync operation and update the rbtree and lzo caches to use this new information. The LZO implementation is obviously not good, we could exit the iteration earlier, but there may be room for more wide reaching optimisation there. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base/regmap/regcache.c') diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 46c42d3a4655..aec5a7486a29 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -283,7 +283,7 @@ int regcache_sync(struct regmap *map) } map->cache_bypass = 0; - ret = map->cache_ops->sync(map); + ret = map->cache_ops->sync(map, 0, map->max_register); if (ret == 0) map->cache_dirty = false; -- cgit v1.2.1 From 4d4cfd1656b5f6c88eae51c40741a695b108b006 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 23 Feb 2012 20:53:37 +0000 Subject: regmap: Allow drivers to sync only part of the register cache Provide a regcache_sync_region() operation which allows drivers to write only part of the cache back to the hardware. This is intended for use in cases like power domains or DSP memories where part of the device register map may be reset without fully resetting the device. Fully supporting these devices is likely to require additional work to make specific regions of the register map cache only while they are in reset, but this is enough for most devices. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'drivers/base/regmap/regcache.c') diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index aec5a7486a29..b35f8751471d 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -298,6 +298,51 @@ out: } EXPORT_SYMBOL_GPL(regcache_sync); +/** + * regcache_sync_region: Sync part of the register cache with the hardware. + * + * @map: map to sync. + * @min: first register to sync + * @max: last register to sync + * + * Write all non-default register values in the specified region to + * the hardware. + * + * Return a negative value on failure, 0 on success. + */ +int regcache_sync_region(struct regmap *map, unsigned int min, + unsigned int max) +{ + int ret = 0; + const char *name; + unsigned int bypass; + + BUG_ON(!map->cache_ops || !map->cache_ops->sync); + + mutex_lock(&map->lock); + + /* Remember the initial bypass state */ + bypass = map->cache_bypass; + + name = map->cache_ops->name; + dev_dbg(map->dev, "Syncing %s cache from %d-%d\n", name, min, max); + + trace_regcache_sync(map->dev, name, "start region"); + + if (!map->cache_dirty) + goto out; + + ret = map->cache_ops->sync(map, min, max); + +out: + trace_regcache_sync(map->dev, name, "stop region"); + /* Restore the bypass state */ + map->cache_bypass = bypass; + mutex_unlock(&map->lock); + + return ret; +} + /** * regcache_cache_only: Put a register map into cache only mode * -- cgit v1.2.1