regmap: Properly round cache_word_size
Subsystems (2)
PATCH v2 1/2 regmap: Properly round cache_word_size
regcache currently only properly works with val bit sizes of 8 or 16, since it will, when calculating the cache word size, round down. This causes the cache storage to be too small to hold the full register value. Fix this by rounding up instead.
---
Changes since v1:
* Use DIV_ROUND_UP
--- drivers/base/regmap/regcache.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regcache.c +2 -2
@@ -111,8 +111,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) map->num_reg_defaults = config->num_reg_defaults; map->num_reg_defaults_raw = config->num_reg_defaults_raw; map->reg_defaults_raw = config->reg_defaults_raw; - map->cache_size_raw = (config->val_bits /8 ) * config->num_reg_defaults_raw; - map->cache_word_size = config->val_bits /8 ; + map->cache_word_size =DIV_ROUND_UP (config->val_bits,8 ); + map->cache_size_raw = map->cache_word_size * config->num_reg_defaults_raw; map->cache =NULL ; map->cache_ops = cache_types[i];
Signature · 1 line
1.7.7.1
PATCH v2 2/2 regmap: Drop check whether a register is readable in regcache_read
One of the reasons for using a cache is to have a software shadow of a register which is writable but not readable. This allows us to do a read-modify-write operation on such a register.
Currently regcache checks whether a register is readable when performing a cached read and returns an error if it is not. Drop this check, since it will prevent us from using the cache for registers where read-back is not possible.
---
Changes since v1:
* Drop the check instead of replaceing it with a check whether the register is writable since this would break once we start adding read-back values to the cache.
--- drivers/base/regmap/regcache.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
drivers/base/regmap/regcache.c +0 -3
@@ -199,9 +199,6 @@ int regcache_read(struct regmap *map,BUG_ON (!map->cache_ops); -if (!regmap_readable (map, reg)) -return -EIO ; -if (!regmap_volatile (map, reg))return map->cache_ops->read (map, reg, value);
Signature · 1 line
1.7.7.1
Mark Brown
AppliedRe: [PATCH v2 2/2] regmap: Drop check whether a register is readable in regcache_read
Quoted 3 lines · Lars-Peter Clausen
One of the reasons for using a cache is to have a software shadow of a register which is writable but not readable. This allows us to do a read-modify-write operation on such a register.
Applied, thanks.
Mark Brown
AppliedQuoted 4 lines · Lars-Peter Clausen
regcache currently only properly works with val bit sizes of 8 or 16, since it will, when calculating the cache word size, round down. This causes the cache storage to be too small to hold the full register value. Fix this by rounding up instead.
Applied, thanks.