]> Pileus Git - ~andy/linux/blobdiff - drivers/base/regmap/regmap.c
Merge branch 'topic/cache' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[~andy/linux] / drivers / base / regmap / regmap.c
index e533368e5598bec983e1c85117519a20fa78f6ae..be10a4ff660915625454375ce9fb30a97d5b7ef9 100644 (file)
@@ -241,12 +241,12 @@ struct regmap *regmap_init(struct device *dev,
                goto err_map;
        }
 
+       regmap_debugfs_init(map);
+
        ret = regcache_init(map, config);
        if (ret < 0)
                goto err_free_workbuf;
 
-       regmap_debugfs_init(map);
-
        return map;
 
 err_free_workbuf:
@@ -258,6 +258,39 @@ err:
 }
 EXPORT_SYMBOL_GPL(regmap_init);
 
+/**
+ * regmap_reinit_cache(): Reinitialise the current register cache
+ *
+ * @map: Register map to operate on.
+ * @config: New configuration.  Only the cache data will be used.
+ *
+ * Discard any existing register cache for the map and initialize a
+ * new cache.  This can be used to restore the cache to defaults or to
+ * update the cache configuration to reflect runtime discovery of the
+ * hardware.
+ */
+int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
+{
+       int ret;
+
+       mutex_lock(&map->lock);
+
+       regcache_exit(map);
+
+       map->max_register = config->max_register;
+       map->writeable_reg = config->writeable_reg;
+       map->readable_reg = config->readable_reg;
+       map->volatile_reg = config->volatile_reg;
+       map->precious_reg = config->precious_reg;
+       map->cache_type = config->cache_type;
+
+       ret = regcache_init(map, config);
+
+       mutex_unlock(&map->lock);
+
+       return ret;
+}
+
 /**
  * regmap_exit(): Free a previously allocated register map
  */
@@ -569,40 +602,73 @@ int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
 }
 EXPORT_SYMBOL_GPL(regmap_bulk_read);
 
-/**
- * regmap_update_bits: Perform a read/modify/write cycle on the register map
- *
- * @map: Register map to update
- * @reg: Register to update
- * @mask: Bitmask to change
- * @val: New value for bitmask
- *
- * Returns zero for success, a negative number on error.
- */
-int regmap_update_bits(struct regmap *map, unsigned int reg,
-                      unsigned int mask, unsigned int val)
+static int _regmap_update_bits(struct regmap *map, unsigned int reg,
+                              unsigned int mask, unsigned int val,
+                              bool *change)
 {
        int ret;
-       unsigned int tmp;
+       unsigned int tmp, orig;
 
        mutex_lock(&map->lock);
 
-       ret = _regmap_read(map, reg, &tmp);
+       ret = _regmap_read(map, reg, &orig);
        if (ret != 0)
                goto out;
 
-       tmp &= ~mask;
+       tmp = orig & ~mask;
        tmp |= val & mask;
 
-       ret = _regmap_write(map, reg, tmp);
+       if (tmp != orig) {
+               ret = _regmap_write(map, reg, tmp);
+               *change = true;
+       } else {
+               *change = false;
+       }
 
 out:
        mutex_unlock(&map->lock);
 
        return ret;
 }
+
+/**
+ * regmap_update_bits: Perform a read/modify/write cycle on the register map
+ *
+ * @map: Register map to update
+ * @reg: Register to update
+ * @mask: Bitmask to change
+ * @val: New value for bitmask
+ *
+ * Returns zero for success, a negative number on error.
+ */
+int regmap_update_bits(struct regmap *map, unsigned int reg,
+                      unsigned int mask, unsigned int val)
+{
+       bool change;
+       return _regmap_update_bits(map, reg, mask, val, &change);
+}
 EXPORT_SYMBOL_GPL(regmap_update_bits);
 
+/**
+ * regmap_update_bits_check: Perform a read/modify/write cycle on the
+ *                           register map and report if updated
+ *
+ * @map: Register map to update
+ * @reg: Register to update
+ * @mask: Bitmask to change
+ * @val: New value for bitmask
+ * @change: Boolean indicating if a write was done
+ *
+ * Returns zero for success, a negative number on error.
+ */
+int regmap_update_bits_check(struct regmap *map, unsigned int reg,
+                            unsigned int mask, unsigned int val,
+                            bool *change)
+{
+       return _regmap_update_bits(map, reg, mask, val, change);
+}
+EXPORT_SYMBOL_GPL(regmap_update_bits_check);
+
 static int __init regmap_initcall(void)
 {
        regmap_debugfs_initcall();