Skip to content

Commit 731aa3f

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
nvmem: core: add support to auto devid
For nvmem providers which have multiple instances, it is required to suffix the provider name with proper id, so that they do not confict for the same name. Currently the core does not handle this case properly eventhough core already has logic to generate the id. This patch add new devid type NVMEM_DEVID_AUTO for providers to be able to allow core to assign id and append it to provier name. Reported-by: Shawn Guo <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Tested-by: Shawn Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5037d36 commit 731aa3f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

drivers/nvmem/core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,18 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
635635
if (!config->no_of_node)
636636
nvmem->dev.of_node = config->dev->of_node;
637637

638-
if (config->id == -1 && config->name) {
638+
switch (config->id) {
639+
case NVMEM_DEVID_NONE:
639640
dev_set_name(&nvmem->dev, "%s", config->name);
640-
} else {
641+
break;
642+
case NVMEM_DEVID_AUTO:
643+
dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id);
644+
break;
645+
default:
641646
dev_set_name(&nvmem->dev, "%s%d",
642647
config->name ? : "nvmem",
643648
config->name ? config->id : nvmem->id);
649+
break;
644650
}
645651

646652
nvmem->read_only = device_property_present(config->dev, "read-only") ||

include/linux/nvmem-provider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ enum nvmem_type {
2727
NVMEM_TYPE_BATTERY_BACKED,
2828
};
2929

30+
#define NVMEM_DEVID_NONE (-1)
31+
#define NVMEM_DEVID_AUTO (-2)
32+
3033
/**
3134
* struct nvmem_config - NVMEM device configuration
3235
*

0 commit comments

Comments
 (0)