aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-03 12:06:20 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-05 08:17:36 -0500
commitbf315173359b2f3b8b8ccca4264815e91f30be12 (patch)
treeeb922a86d595849df02c474e034c855d770abce0
parent50b776fc71c13663eb7434f634f2b796de5c9885 (diff)
regmap: Allow drivers to reinitialise the register cache at runtime
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>
-rw-r--r--drivers/base/regmap/regmap.c33
-rw-r--r--include/linux/regmap.h2
2 files changed, 35 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 3aca18dbf367..579e85b8a684 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -231,6 +231,39 @@ err:
231EXPORT_SYMBOL_GPL(regmap_init); 231EXPORT_SYMBOL_GPL(regmap_init);
232 232
233/** 233/**
234 * regmap_reinit_cache(): Reinitialise the current register cache
235 *
236 * @map: Register map to operate on.
237 * @config: New configuration. Only the cache data will be used.
238 *
239 * Discard any existing register cache for the map and initialize a
240 * new cache. This can be used to restore the cache to defaults or to
241 * update the cache configuration to reflect runtime discovery of the
242 * hardware.
243 */
244int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
245{
246 int ret;
247
248 mutex_lock(&map->lock);
249
250 regcache_exit(map);
251
252 map->max_register = config->max_register;
253 map->writeable_reg = config->writeable_reg;
254 map->readable_reg = config->readable_reg;
255 map->volatile_reg = config->volatile_reg;
256 map->precious_reg = config->precious_reg;
257 map->cache_type = config->cache_type;
258
259 ret = regcache_init(map, config);
260
261 mutex_unlock(&map->lock);
262
263 return ret;
264}
265
266/**
234 * regmap_exit(): Free a previously allocated register map 267 * regmap_exit(): Free a previously allocated register map
235 */ 268 */
236void regmap_exit(struct regmap *map) 269void regmap_exit(struct regmap *map)
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index bebda1481f23..86923a98a766 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -129,6 +129,8 @@ struct regmap *regmap_init_spi(struct spi_device *dev,
129 const struct regmap_config *config); 129 const struct regmap_config *config);
130 130
131void regmap_exit(struct regmap *map); 131void regmap_exit(struct regmap *map);
132int regmap_reinit_cache(struct regmap *map,
133 const struct regmap_config *config);
132int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); 134int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
133int regmap_raw_write(struct regmap *map, unsigned int reg, 135int regmap_raw_write(struct regmap *map, unsigned int reg,
134 const void *val, size_t val_len); 136 const void *val, size_t val_len);