提交 4b5c0186 编写于 作者: S Stephen Warren 提交者: Mark Brown

regmap: allow regmap instances to be named

Some devices have multiple separate register regions. Logically, one
regmap would be created per region. One issue that prevents this is that
each instance will attempt to create the same debugfs files. Avoid this
by allowing regmaps to be named, and use the name to construct the
debugfs directory name.
Signed-off-by: NStephen Warren <swarren@nvidia.com>
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
上级 2690dfdb
...@@ -48,6 +48,7 @@ struct regmap { ...@@ -48,6 +48,7 @@ struct regmap {
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debugfs; struct dentry *debugfs;
const char *debugfs_name;
#endif #endif
unsigned int max_register; unsigned int max_register;
...@@ -111,7 +112,7 @@ int _regmap_write(struct regmap *map, unsigned int reg, ...@@ -111,7 +112,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
extern void regmap_debugfs_initcall(void); extern void regmap_debugfs_initcall(void);
extern void regmap_debugfs_init(struct regmap *map); extern void regmap_debugfs_init(struct regmap *map, const char *name);
extern void regmap_debugfs_exit(struct regmap *map); extern void regmap_debugfs_exit(struct regmap *map);
#else #else
static inline void regmap_debugfs_initcall(void) { } static inline void regmap_debugfs_initcall(void) { }
......
...@@ -242,10 +242,17 @@ static const struct file_operations regmap_access_fops = { ...@@ -242,10 +242,17 @@ static const struct file_operations regmap_access_fops = {
.llseek = default_llseek, .llseek = default_llseek,
}; };
void regmap_debugfs_init(struct regmap *map) void regmap_debugfs_init(struct regmap *map, const char *name)
{ {
map->debugfs = debugfs_create_dir(dev_name(map->dev), if (name) {
regmap_debugfs_root); map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
dev_name(map->dev), name);
name = map->debugfs_name;
} else {
name = dev_name(map->dev);
}
map->debugfs = debugfs_create_dir(name, regmap_debugfs_root);
if (!map->debugfs) { if (!map->debugfs) {
dev_warn(map->dev, "Failed to create debugfs directory\n"); dev_warn(map->dev, "Failed to create debugfs directory\n");
return; return;
...@@ -274,6 +281,7 @@ void regmap_debugfs_init(struct regmap *map) ...@@ -274,6 +281,7 @@ void regmap_debugfs_init(struct regmap *map)
void regmap_debugfs_exit(struct regmap *map) void regmap_debugfs_exit(struct regmap *map)
{ {
debugfs_remove_recursive(map->debugfs); debugfs_remove_recursive(map->debugfs);
kfree(map->debugfs_name);
} }
void regmap_debugfs_initcall(void) void regmap_debugfs_initcall(void)
......
...@@ -346,7 +346,7 @@ struct regmap *regmap_init(struct device *dev, ...@@ -346,7 +346,7 @@ struct regmap *regmap_init(struct device *dev,
goto err_map; goto err_map;
} }
regmap_debugfs_init(map); regmap_debugfs_init(map, config->name);
ret = regcache_init(map, config); ret = regcache_init(map, config);
if (ret < 0) if (ret < 0)
...@@ -431,7 +431,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) ...@@ -431,7 +431,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
map->precious_reg = config->precious_reg; map->precious_reg = config->precious_reg;
map->cache_type = config->cache_type; map->cache_type = config->cache_type;
regmap_debugfs_init(map); regmap_debugfs_init(map, config->name);
map->cache_bypass = false; map->cache_bypass = false;
map->cache_only = false; map->cache_only = false;
......
...@@ -46,6 +46,9 @@ struct reg_default { ...@@ -46,6 +46,9 @@ struct reg_default {
/** /**
* Configuration for the register map of a device. * Configuration for the register map of a device.
* *
* @name: Optional name of the regmap. Useful when a device has multiple
* register regions.
*
* @reg_bits: Number of bits in a register address, mandatory. * @reg_bits: Number of bits in a register address, mandatory.
* @pad_bits: Number of bits of padding between register and value. * @pad_bits: Number of bits of padding between register and value.
* @val_bits: Number of bits in a register value, mandatory. * @val_bits: Number of bits in a register value, mandatory.
...@@ -77,6 +80,8 @@ struct reg_default { ...@@ -77,6 +80,8 @@ struct reg_default {
* @num_reg_defaults_raw: Number of elements in reg_defaults_raw. * @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
*/ */
struct regmap_config { struct regmap_config {
const char *name;
int reg_bits; int reg_bits;
int pad_bits; int pad_bits;
int val_bits; int val_bits;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册