From 00f402cd61f5877c31ac3e52a3352c70b5093af0 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 13 Mar 2013 19:29:36 +0000 Subject: [PATCH] regmap: cache: Provide a get address of value operation Provide a helper to do the size based index into a block of registers and use it when reading a value. Signed-off-by: Mark Brown --- drivers/base/regmap/internal.h | 7 +++++++ drivers/base/regmap/regcache.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 6d409350f50aa..95d46a5ea7e70 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -189,6 +189,13 @@ int regcache_write(struct regmap *map, unsigned int reg, unsigned int value); int regcache_sync(struct regmap *map); +static inline const void *regcache_get_val_addr(struct regmap *map, + const void *base, + unsigned int idx) +{ + return base + (map->cache_word_size * idx); +} + unsigned int regcache_get_val(struct regmap *map, const void *base, unsigned int idx); bool regcache_set_val(struct regmap *map, void *base, unsigned int idx, diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 0f4fb8bc37e5d..229c804e409ea 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -458,8 +458,8 @@ unsigned int regcache_get_val(struct regmap *map, const void *base, /* Use device native format if possible */ if (map->format.parse_val) - return map->format.parse_val(base + - (map->cache_word_size * idx)); + return map->format.parse_val(regcache_get_val_addr(map, base, + idx)); switch (map->cache_word_size) { case 1: { -- 2.39.5