regmap: regcache: allow read-only regs to be cached
authorIonut Nicu <ioan.nicu.ext@nsn.com>
Fri, 9 Aug 2013 10:09:20 +0000 (12:09 +0200)
committerMark Brown <broonie@linaro.org>
Fri, 9 Aug 2013 11:47:29 +0000 (12:47 +0100)
The regmap_writeable() check should not be done in
regcache_write() because this prevents read-only
registers to be cached. After a read on a read-only
register its value will not be stored in the cache
and the next time someone will try to read it the
value will be read from the bus instead of the
cache.

Instead the regmap_writeable() check should be done
in _regmap_write() to prevent callers from writing
to read-only registers.

Signed-off-by: Ionut Nicu <ioan.nicu.ext@nsn.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
drivers/base/regmap/regcache.c
drivers/base/regmap/regmap.c

index e69102696533e7224b74a1237f64c478eeb2ab18..f1aa1bcd36a0ab919824bbc78fe9a5db86914c88 100644 (file)
@@ -241,9 +241,6 @@ int regcache_write(struct regmap *map,
 
        BUG_ON(!map->cache_ops);
 
-       if (!regmap_writeable(map, reg))
-               return -EIO;
-
        if (!regmap_volatile(map, reg))
                return map->cache_ops->write(map, reg, value);
 
index e0d0c7d8a5c527867fb4ba05f4f21e74c43fcff2..0e85367e504d0781c7b8fcf94b775266e6c033d5 100644 (file)
@@ -1261,6 +1261,9 @@ int _regmap_write(struct regmap *map, unsigned int reg,
        int ret;
        void *context = _regmap_map_get_context(map);
 
+       if (!regmap_writeable(map, reg))
+               return -EIO;
+
        if (!map->cache_bypass && !map->defer_caching) {
                ret = regcache_write(map, reg, val);
                if (ret != 0)