Skip to contentSkip to conversation

regmap: cache: Provide a get address of value operation

PATCH New Mark Brown 1 participant 1 message Mar 13, 2013

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/base/regmap/internal.h |    6 ++++++
 drivers/base/regmap/regcache.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/base/regmap/internal.h +6 -0
index 9fc351f0..54b2fd9 100644
@@ -190,6 +190,12 @@ int regcache_write(struct regmap *map,
 			unsigned int reg, unsigned int value);
 int regcache_sync(struct regmap *map);
 
+static inline 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,
drivers/base/regmap/regcache.c +2 -2
index 0f4fb8b..229c804 100644
@@ -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: {
Signature · 1 line
1.7.10.4