lkml.org 
[lkml]   [2011]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 8/8] regmap: Support NULL cache_defaults_raw
Date
Some IC's like PMIC's tend not to have cache defaults.  Support this
by reading back from the hardware using the bulk read operation the values
of all registers and constructing the cache defaults manually.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
---
drivers/base/regmap/internal.h | 2 ++
drivers/base/regmap/regcache.c | 27 ++++++++++++++++++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 9f228c7..f8b6219 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -65,6 +65,8 @@ struct regmap {
unsigned int cache_only:1;
/* if set, only the HW is modified not the cache */
unsigned int cache_bypass:1;
+ /* if set, remember to free cache_defaults_raw */
+ unsigned int cache_free:1;

struct reg_default *cache_defaults;
const void *cache_defaults_raw;
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 6346d77..fb35fc4 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -31,7 +31,9 @@ int regcache_init(struct regmap *map)
{
int i, j;
int count;
+ int ret;
unsigned int val;
+ void *tmp_buf;

if (map->cache_type == REGCACHE_NONE)
return 0;
@@ -51,9 +53,25 @@ int regcache_init(struct regmap *map)
if (!map->cache_ops->name)
return -EINVAL;

- if (!map->cache_defaults_raw || !map->num_cache_defaults_raw) {
- dev_err(map->dev, "Client has not provided a defaults cache\n");
- return -EINVAL;
+ /* Some devices such as PMIC's don't have cache defaults,
+ * we cope with this by reading back the HW registers and
+ * crafting the cache defaults by hand.
+ */
+ if (!map->cache_defaults_raw) {
+ if (!map->num_cache_defaults_raw)
+ return -EINVAL;
+ dev_warn(map->dev, "No cache defaults, reading back from HW\n");
+ tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL);
+ if (!tmp_buf)
+ return -EINVAL;
+ ret = regmap_bulk_read(map, 0, tmp_buf,
+ map->num_cache_defaults_raw);
+ if (ret < 0) {
+ kfree(tmp_buf);
+ return ret;
+ }
+ map->cache_defaults_raw = tmp_buf;
+ map->cache_free = 1;
}

/* calculate the size of cache_defaults */
@@ -98,6 +116,9 @@ void regcache_exit(struct regmap *map)
BUG_ON(!map->cache_ops);

kfree(map->cache_defaults);
+ if (map->cache_free)
+ kfree(map->cache_defaults_raw);
+
if (map->cache_ops->exit) {
dev_dbg(map->dev, "Destroying %s cache\n",
map->cache_ops->name);
--
1.7.6.1


\
 
 \ /
  Last update: 2011-09-02 17:49    [W:0.190 / U:0.584 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site