From 1767da9e8e9a1dc1416d6bb1029b8cf5659dac2a Mon Sep 17 00:00:00 2001 From: Ionut Nicu Date: Fri, 9 Aug 2013 12:09:15 +0200 Subject: regmap: fix regcache_reg_present() for empty cache In the initial case when no reg_defaults values are provided and no register value was added to the cache yet, the cache_present bitmap is NULL. If this function is invoked for any register it should return false (i.e. the register is not cached) instead of true. Signed-off-by: Ionut Nicu Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/base/regmap') diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 29c83160ca2..5308e3e870b 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -223,7 +223,7 @@ int regcache_set_reg_present(struct regmap *map, unsigned int reg); static inline bool regcache_reg_present(struct regmap *map, unsigned int reg) { if (!map->cache_present) - return true; + return false; if (reg > map->cache_present_nbits) return false; return map->cache_present[BIT_WORD(reg)] & BIT_MASK(reg); -- cgit v1.2.3 From 515f2261703d09c6b647a5687b7d657dd5911065 Mon Sep 17 00:00:00 2001 From: Ionut Nicu Date: Fri, 9 Aug 2013 12:09:20 +0200 Subject: regmap: regcache: allow read-only regs to be cached 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 Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 3 --- drivers/base/regmap/regmap.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/base/regmap') diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index e6910269653..f1aa1bcd36a 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -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); diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index e0d0c7d8a5c..0e85367e504 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -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) -- cgit v1.2.3