]> Pileus Git - ~andy/linux/blobdiff - drivers/base/regmap/regcache.c
Merge remote-tracking branch 'regmap/topic/drivers' into regmap-next
[~andy/linux] / drivers / base / regmap / regcache.c
index 1ead66186b7c0a90586f223b0b9bc23d3770a3ed..8db713ffef66eed4eb4739f90af93eed4b616d7d 100644 (file)
@@ -53,7 +53,7 @@ static int regcache_hw_init(struct regmap *map)
        for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
                val = regcache_get_val(map->reg_defaults_raw,
                                       i, map->cache_word_size);
-               if (!val)
+               if (regmap_volatile(map, i))
                        continue;
                count++;
        }
@@ -70,7 +70,7 @@ static int regcache_hw_init(struct regmap *map)
        for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
                val = regcache_get_val(map->reg_defaults_raw,
                                       i, map->cache_word_size);
-               if (!val)
+               if (regmap_volatile(map, i))
                        continue;
                map->reg_defaults[j].reg = i;
                map->reg_defaults[j].def = val;
@@ -211,7 +211,6 @@ int regcache_read(struct regmap *map,
 
        return -EINVAL;
 }
-EXPORT_SYMBOL_GPL(regcache_read);
 
 /**
  * regcache_write: Set the value of a given register in the cache.
@@ -238,7 +237,6 @@ int regcache_write(struct regmap *map,
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(regcache_write);
 
 /**
  * regcache_sync: Sync the register cache with the hardware.
@@ -268,8 +266,22 @@ int regcache_sync(struct regmap *map)
                map->cache_ops->name);
        name = map->cache_ops->name;
        trace_regcache_sync(map->dev, name, "start");
+
        if (!map->cache_dirty)
                goto out;
+
+       /* Apply any patch first */
+       map->cache_bypass = 1;
+       for (i = 0; i < map->patch_regs; i++) {
+               ret = _regmap_write(map, map->patch[i].reg, map->patch[i].def);
+               if (ret != 0) {
+                       dev_err(map->dev, "Failed to write %x = %x: %d\n",
+                               map->patch[i].reg, map->patch[i].def, ret);
+                       goto out;
+               }
+       }
+       map->cache_bypass = 0;
+
        if (map->cache_ops->sync) {
                ret = map->cache_ops->sync(map);
        } else {
@@ -315,6 +327,7 @@ void regcache_cache_only(struct regmap *map, bool enable)
        mutex_lock(&map->lock);
        WARN_ON(map->cache_bypass && enable);
        map->cache_only = enable;
+       trace_regmap_cache_only(map->dev, enable);
        mutex_unlock(&map->lock);
 }
 EXPORT_SYMBOL_GPL(regcache_cache_only);
@@ -352,6 +365,7 @@ void regcache_cache_bypass(struct regmap *map, bool enable)
        mutex_lock(&map->lock);
        WARN_ON(map->cache_only && enable);
        map->cache_bypass = enable;
+       trace_regmap_cache_bypass(map->dev, enable);
        mutex_unlock(&map->lock);
 }
 EXPORT_SYMBOL_GPL(regcache_cache_bypass);
@@ -374,10 +388,16 @@ bool regcache_set_val(void *base, unsigned int idx,
                cache[idx] = val;
                break;
        }
+       case 4: {
+               u32 *cache = base;
+               if (cache[idx] == val)
+                       return true;
+               cache[idx] = val;
+               break;
+       }
        default:
                BUG();
        }
-       /* unreachable */
        return false;
 }
 
@@ -396,6 +416,10 @@ unsigned int regcache_get_val(const void *base, unsigned int idx,
                const u16 *cache = base;
                return cache[idx];
        }
+       case 4: {
+               const u32 *cache = base;
+               return cache[idx];
+       }
        default:
                BUG();
        }