2013-05-31 14:38:28

by Maarten ter Huurne

[permalink] [raw]
Subject: [PATCH] regmap: regcache-flat: Implemented sync operation


Signed-off-by: Maarten ter Huurne <[email protected]>
---
drivers/base/regmap/regcache-flat.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index d9762e4..1f18bec 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -62,6 +62,37 @@ static int regcache_flat_write(struct regmap *map, unsigned int reg,
return 0;
}

+static int regcache_flat_sync(struct regmap *map, unsigned int min,
+ unsigned int max)
+{
+ unsigned int *cache = map->cache;
+ unsigned int reg;
+
+ for (reg = min; reg <= max; reg++) {
+ unsigned int val;
+ int ret;
+
+ if (regmap_volatile(map, reg))
+ continue;
+
+ val = cache[reg];
+
+ /* Is this the hardware default? If so skip. */
+ ret = regcache_lookup_reg(map, reg);
+ if (ret >= 0 && val == map->reg_defaults[ret].def)
+ continue;
+
+ map->cache_bypass = 1;
+ ret = _regmap_write(map, reg, val);
+ map->cache_bypass = 0;
+ if (ret)
+ return ret;
+ dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val);
+ }
+
+ return 0;
+}
+
struct regcache_ops regcache_flat_ops = {
.type = REGCACHE_FLAT,
.name = "flat",
@@ -69,4 +100,5 @@ struct regcache_ops regcache_flat_ops = {
.exit = regcache_flat_exit,
.read = regcache_flat_read,
.write = regcache_flat_write,
+ .sync = regcache_flat_sync,
};
--
1.7.10.4


2013-06-01 19:09:21

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regmap: regcache-flat: Implemented sync operation

On Fri, May 31, 2013 at 04:36:15PM +0200, Maarten ter Huurne wrote:
>
> Signed-off-by: Maarten ter Huurne <[email protected]>

This should probably just go into regcache.c as a default sync operation
based on doing reads rather than being open coded - it's not meanigfully
using any features of the cache data structure really.


Attachments:
(No filename) (334.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-06-02 22:16:35

by Maarten ter Huurne

[permalink] [raw]
Subject: [PATCH] regmap: Implemented default cache sync operation

This can be used for cache types for which syncing values one by one is
equally efficient as syncing a range, such as the flat cache.

Signed-off-by: Maarten ter Huurne <[email protected]>
---
drivers/base/regmap/regcache.c | 46 ++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index e69ff3e..e1c23464 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -249,6 +249,38 @@ int regcache_write(struct regmap *map,
return 0;
}

+static int regcache_default_sync(struct regmap *map, unsigned int min,
+ unsigned int max)
+{
+ unsigned int reg;
+
+ for (reg = min; reg <= max; reg++) {
+ unsigned int val;
+ int ret;
+
+ if (regmap_volatile(map, reg))
+ continue;
+
+ ret = regcache_read(map, reg, &val);
+ if (ret)
+ return ret;
+
+ /* Is this the hardware default? If so skip. */
+ ret = regcache_lookup_reg(map, reg);
+ if (ret >= 0 && val == map->reg_defaults[ret].def)
+ continue;
+
+ map->cache_bypass = 1;
+ ret = _regmap_write(map, reg, val);
+ map->cache_bypass = 0;
+ if (ret)
+ return ret;
+ dev_dbg(map->dev, "Synced register %#x, value %#x\n", reg, val);
+ }
+
+ return 0;
+}
+
/**
* regcache_sync: Sync the register cache with the hardware.
*
@@ -267,7 +299,7 @@ int regcache_sync(struct regmap *map)
const char *name;
unsigned int bypass;

- BUG_ON(!map->cache_ops || !map->cache_ops->sync);
+ BUG_ON(!map->cache_ops);

map->lock(map);
/* Remember the initial bypass state */
@@ -296,7 +328,10 @@ int regcache_sync(struct regmap *map)
}
map->cache_bypass = 0;

- ret = map->cache_ops->sync(map, 0, map->max_register);
+ if (map->cache_ops->sync)
+ ret = map->cache_ops->sync(map, 0, map->max_register);
+ else
+ ret = regcache_default_sync(map, 0, map->max_register);

if (ret == 0)
map->cache_dirty = false;
@@ -330,7 +365,7 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
const char *name;
unsigned int bypass;

- BUG_ON(!map->cache_ops || !map->cache_ops->sync);
+ BUG_ON(!map->cache_ops);

map->lock(map);

@@ -345,7 +380,10 @@ int regcache_sync_region(struct regmap *map, unsigned int min,
if (!map->cache_dirty)
goto out;

- ret = map->cache_ops->sync(map, min, max);
+ if (map->cache_ops->sync)
+ ret = map->cache_ops->sync(map, min, max);
+ else
+ ret = regcache_default_sync(map, min, max);

out:
trace_regcache_sync(map->dev, name, "stop region");
--
1.7.10.4

2013-06-03 10:51:35

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] regmap: Implemented default cache sync operation

On Mon, Jun 03, 2013 at 12:15:26AM +0200, Maarten ter Huurne wrote:
> This can be used for cache types for which syncing values one by one is
> equally efficient as syncing a range, such as the flat cache.

Applied, thanks.


Attachments:
(No filename) (224.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments