From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754829AbeAGXWj (ORCPT + 1 other); Sun, 7 Jan 2018 18:22:39 -0500 Received: from fllnx209.ext.ti.com ([198.47.19.16]:42722 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754738AbeAGXWg (ORCPT ); Sun, 7 Jan 2018 18:22:36 -0500 From: "Andrew F. Davis" To: Mark Brown CC: , "Andrew F . Davis" Subject: [PATCH 3/3] regcache: flat: Add valid bit to this cache type Date: Sun, 7 Jan 2018 17:22:34 -0600 Message-ID: <20180107232234.11064-3-afd@ti.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180107232234.11064-1-afd@ti.com> References: <20180107232234.11064-1-afd@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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 --- 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