Commit bf315173359b2f3b8b8ccca4264815e91f30be12

Authored by Mark Brown
1 parent 50b776fc71

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>

Showing 2 changed files with 35 additions and 0 deletions Side-by-side Diff

drivers/base/regmap/regmap.c
... ... @@ -231,6 +231,39 @@
231 231 EXPORT_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 + */
  244 +int 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 267 * regmap_exit(): Free a previously allocated register map
235 268 */
236 269 void regmap_exit(struct regmap *map)
include/linux/regmap.h
... ... @@ -129,6 +129,8 @@
129 129 const struct regmap_config *config);
130 130  
131 131 void regmap_exit(struct regmap *map);
  132 +int regmap_reinit_cache(struct regmap *map,
  133 + const struct regmap_config *config);
132 134 int regmap_write(struct regmap *map, unsigned int reg, unsigned int val);
133 135 int regmap_raw_write(struct regmap *map, unsigned int reg,
134 136 const void *val, size_t val_len);