lkml.org 
[lkml]   [2018]   [Jan]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/3] regcache: flat: Add valid bit to this cache type
Date
Other regmap cache types (LZO, RBtree) report back un-successful register
lookups when a value has not been previously written into the cache. This
allows regmap core to perform a real un-cached lookup to fetch the value.
The Flat type cache does not and so all read succeed reporting zero for the
registers value, even when the actual value is not known.

We fix this by changing the flat cache element type to a struct
containing both the register's value and a bool signifying if this value
is an actual cached value or not. This also opens up a path to implement
additional regcache_ops such as "sync" and "drop" that rely on such
validity information.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
drivers/base/regmap/regcache-flat.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index 99a7792210b3..89a2226f9a81 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -16,6 +16,11 @@

#include "internal.h"

+struct regcache_flat_reg {
+ unsigned int value; /* Value of this register */
+ bool valid; /* Is value valid? */
+} __packed;
+
static inline unsigned int regcache_flat_get_index(const struct regmap *map,
unsigned int reg)
{
@@ -25,7 +30,7 @@ static inline unsigned int regcache_flat_get_index(const struct regmap *map,
static int regcache_flat_init(struct regmap *map)
{
int i;
- unsigned int *cache;
+ struct regcache_flat_reg *cache;

if (!map || map->reg_stride_order < 0 || !map->max_register)
return -EINVAL;
@@ -41,7 +46,8 @@ static int regcache_flat_init(struct regmap *map)
unsigned int reg = map->reg_defaults[i].reg;
unsigned int index = regcache_flat_get_index(map, reg);

- cache[index] = map->reg_defaults[i].def;
+ cache[index].value = map->reg_defaults[i].def;
+ cache[index].valid = true;
}

return 0;
@@ -58,10 +64,13 @@ static int regcache_flat_exit(struct regmap *map)
static int regcache_flat_read(struct regmap *map,
unsigned int reg, unsigned int *value)
{
- unsigned int *cache = map->cache;
+ struct regcache_flat_reg *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);

- *value = cache[index];
+ if (!cache[index].valid)
+ return -ENOENT;
+
+ *value = cache[index].value;

return 0;
}
@@ -69,10 +78,11 @@ static int regcache_flat_read(struct regmap *map,
static int regcache_flat_write(struct regmap *map, unsigned int reg,
unsigned int value)
{
- unsigned int *cache = map->cache;
+ struct regcache_flat_reg *cache = map->cache;
unsigned int index = regcache_flat_get_index(map, reg);

- cache[index] = value;
+ cache[index].value = value;
+ cache[index].valid = true;

return 0;
}
--
2.15.1
\
 
 \ /
  Last update: 2018-01-14 23:16    [W:0.048 / U:1.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site