regmap: Support for caching in reg_raw_write()
Laxman Dewangan [Fri, 10 Feb 2012 16:00:27 +0000 (21:00 +0530)]
Adding support for caching of data into the
non-volatile register from the call of reg_raw_write().

This will allow the larger block of data write into multiple
register without worrying whether register is cached or not
through reg_raw_write().

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
(cherry picked from commit c9157198417076c0c2664ba997e7b0217f61fcce)

Change-Id: I6e6a96bc9e08ca9b7fe0f52a0a5692a4a61ef0ae
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/87590

Rebase-Id: Rb69cfc6dc98b2c4e4d7bcf5554ce2de605e7fb78

drivers/base/regmap/regmap.c

index eb8c696..c145884 100644 (file)
@@ -385,6 +385,26 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
                        if (!map->writeable_reg(map->dev, reg + i))
                                return -EINVAL;
 
+       if (!map->cache_bypass && map->format.parse_val) {
+               unsigned int ival;
+               int val_bytes = map->format.val_bytes;
+               for (i = 0; i < val_len / val_bytes; i++) {
+                       memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
+                       ival = map->format.parse_val(map->work_buf);
+                       ret = regcache_write(map, reg + i, ival);
+                       if (ret) {
+                               dev_err(map->dev,
+                                  "Error in caching of register: %u ret: %d\n",
+                                       reg + i, ret);
+                               return ret;
+                       }
+               }
+               if (map->cache_only) {
+                       map->cache_dirty = true;
+                       return 0;
+               }
+       }
+
        map->format.format_reg(map->work_buf, reg);
 
        u8[0] |= map->write_flag_mask;
@@ -435,7 +455,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
        int ret;
        BUG_ON(!map->format.format_write && !map->format.format_val);
 
-       if (!map->cache_bypass) {
+       if (!map->cache_bypass && map->format.format_write) {
                ret = regcache_write(map, reg, val);
                if (ret != 0)
                        return ret;
@@ -512,12 +532,8 @@ EXPORT_SYMBOL_GPL(regmap_write);
 int regmap_raw_write(struct regmap *map, unsigned int reg,
                     const void *val, size_t val_len)
 {
-       size_t val_count = val_len / map->format.val_bytes;
        int ret;
 
-       WARN_ON(!regmap_volatile_range(map, reg, val_count) &&
-               map->cache_type != REGCACHE_NONE);
-
        mutex_lock(&map->lock);
 
        ret = _regmap_raw_write(map, reg, val, val_len);