summaryrefslogtreecommitdiffstats
path: root/drivers/misc/eeprom/at24.c
diff options
context:
space:
mode:
authorJon Hunter <jonathanh@nvidia.com>2020-09-24 15:20:39 +0200
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2020-09-25 15:33:04 +0200
commit61f764c307f6b2079b7af0d4fb7951402b824967 (patch)
treeadfa20b5c14e55ea377e64bbb346ee480632d105 /drivers/misc/eeprom/at24.c
parentdt-bindings: eeprom: at24: Add label property for AT24 (diff)
downloadlinux-61f764c307f6b2079b7af0d4fb7951402b824967.tar.xz
linux-61f764c307f6b2079b7af0d4fb7951402b824967.zip
eeprom: at24: Support custom device names for AT24 EEPROMs
By using the label property, a more descriptive name can be populated for AT24 EEPROMs NVMEM device. Update the AT24 driver to check to see if the label property is present and if so, use this as the name for NVMEM device. Please note that when the 'label' property is present for the AT24 EEPROM, we do not want the NVMEM driver to append the 'devid' to the name and so the nvmem_config.id is initialised to NVMEM_DEVID_NONE. Signed-off-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Diffstat (limited to 'drivers/misc/eeprom/at24.c')
-rw-r--r--drivers/misc/eeprom/at24.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2fde53dcfc97..4aa96d8e78ef 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -713,8 +713,28 @@ static int at24_probe(struct i2c_client *client)
return err;
}
+ /*
+ * If the 'label' property is not present for the AT24 EEPROM,
+ * then nvmem_config.id is initialised to NVMEM_DEVID_AUTO,
+ * and this will append the 'devid' to the name of the NVMEM
+ * device. This is purely legacy and the AT24 driver has always
+ * defaulted to this. However, if the 'label' property is
+ * present then this means that the name is specified by the
+ * firmware and this name should be used verbatim and so it is
+ * not necessary to append the 'devid'.
+ */
+ if (device_property_present(dev, "label")) {
+ nvmem_config.id = NVMEM_DEVID_NONE;
+ err = device_property_read_string(dev, "label",
+ &nvmem_config.name);
+ if (err)
+ return err;
+ } else {
+ nvmem_config.id = NVMEM_DEVID_AUTO;
+ nvmem_config.name = dev_name(dev);
+ }
+
nvmem_config.type = NVMEM_TYPE_EEPROM;
- nvmem_config.name = dev_name(dev);
nvmem_config.dev = dev;
nvmem_config.id = NVMEM_DEVID_AUTO;
nvmem_config.read_only = !writable;