Skip to content

Commit d3c242e

Browse files
Stephen Warrenbroonie
authored andcommitted
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: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent dd775ae commit d3c242e

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎drivers/base/regmap/internal.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct regmap {
4141

4242
#ifdef CONFIG_DEBUG_FS
4343
struct dentry *debugfs;
44+
const char *debugfs_name;
4445
#endif
4546

4647
unsigned int max_register;
@@ -101,7 +102,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,
101102

102103
#ifdef CONFIG_DEBUG_FS
103104
extern void regmap_debugfs_initcall(void);
104-
extern void regmap_debugfs_init(struct regmap *map);
105+
extern void regmap_debugfs_init(struct regmap *map, const char *name);
105106
extern void regmap_debugfs_exit(struct regmap *map);
106107
#else
107108
static inline void regmap_debugfs_initcall(void) { }

‎drivers/base/regmap/regmap-debugfs.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,17 @@ static const struct file_operations regmap_access_fops = {
248248
.llseek = default_llseek,
249249
};
250250

251-
void regmap_debugfs_init(struct regmap *map)
251+
void regmap_debugfs_init(struct regmap *map, const char *name)
252252
{
253-
map->debugfs = debugfs_create_dir(dev_name(map->dev),
254-
regmap_debugfs_root);
253+
if (name) {
254+
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
255+
dev_name(map->dev), name);
256+
name = map->debugfs_name;
257+
} else {
258+
name = dev_name(map->dev);
259+
}
260+
261+
map->debugfs = debugfs_create_dir(name, regmap_debugfs_root);
255262
if (!map->debugfs) {
256263
dev_warn(map->dev, "Failed to create debugfs directory\n");
257264
return;
@@ -280,6 +287,7 @@ void regmap_debugfs_init(struct regmap *map)
280287
void regmap_debugfs_exit(struct regmap *map)
281288
{
282289
debugfs_remove_recursive(map->debugfs);
290+
kfree(map->debugfs_name);
283291
}
284292

285293
void regmap_debugfs_initcall(void)

‎drivers/base/regmap/regmap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ struct regmap *regmap_init(struct device *dev,
289289
goto err_map;
290290
}
291291

292-
regmap_debugfs_init(map);
292+
regmap_debugfs_init(map, config->name);
293293

294294
ret = regcache_init(map, config);
295295
if (ret < 0)
@@ -372,7 +372,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
372372
map->precious_reg = config->precious_reg;
373373
map->cache_type = config->cache_type;
374374

375-
regmap_debugfs_init(map);
375+
regmap_debugfs_init(map, config->name);
376376

377377
map->cache_bypass = false;
378378
map->cache_only = false;

‎include/linux/regmap.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct reg_default {
4646
/**
4747
* Configuration for the register map of a device.
4848
*
49+
* @name: Optional name of the regmap. Useful when a device has multiple
50+
* register regions.
51+
*
4952
* @reg_bits: Number of bits in a register address, mandatory.
5053
* @pad_bits: Number of bits of padding between register and value.
5154
* @val_bits: Number of bits in a register value, mandatory.
@@ -77,6 +80,8 @@ struct reg_default {
7780
* @num_reg_defaults_raw: Number of elements in reg_defaults_raw.
7881
*/
7982
struct regmap_config {
83+
const char *name;
84+
8085
int reg_bits;
8186
int pad_bits;
8287
int val_bits;

0 commit comments

Comments
 (0)