]> Pileus Git - ~andy/linux/commitdiff
regmap: Allow drivers to reinitialise the register cache at runtime
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sat, 3 Dec 2011 17:06:20 +0000 (17:06 +0000)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 5 Dec 2011 13:17:36 +0000 (13:17 +0000)
Sometimes the register map information may change in ways that drivers can
discover at runtime. For example, new revisions of a device may add new
registers. Support runtime discovery by drivers by allowing the register
cache to be reinitialised with a new function regmap_reinit_cache() which
discards the existing cache and creates a new one.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/base/regmap/regmap.c
include/linux/regmap.h

index 3aca18dbf367389c4e35cac5c38b47d943ee24e4..579e85b8a68458842b6cc918b316742ea0aa1554 100644 (file)
@@ -230,6 +230,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
  */
index bebda1481f23c0ec4411d6f5bad7cef2045766a1..86923a98a7664e5dd3dcd1bfff0016bda56689e1 100644 (file)
@@ -129,6 +129,8 @@ struct regmap *regmap_init_spi(struct spi_device *dev,
                               const struct regmap_config *config);
 
 void regmap_exit(struct regmap *map);
+int regmap_reinit_cache(struct regmap *map,
+                       const struct regmap_config *config);
 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
 int regmap_raw_write(struct regmap *map, unsigned int reg,
                     const void *val, size_t val_len);