Skip to content

Commit 61f764c

Browse files
jonhunterbrgl
authored andcommitted
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 <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 412b7a5 commit 61f764c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/misc/eeprom/at24.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,28 @@ static int at24_probe(struct i2c_client *client)
713713
return err;
714714
}
715715

716+
/*
717+
* If the 'label' property is not present for the AT24 EEPROM,
718+
* then nvmem_config.id is initialised to NVMEM_DEVID_AUTO,
719+
* and this will append the 'devid' to the name of the NVMEM
720+
* device. This is purely legacy and the AT24 driver has always
721+
* defaulted to this. However, if the 'label' property is
722+
* present then this means that the name is specified by the
723+
* firmware and this name should be used verbatim and so it is
724+
* not necessary to append the 'devid'.
725+
*/
726+
if (device_property_present(dev, "label")) {
727+
nvmem_config.id = NVMEM_DEVID_NONE;
728+
err = device_property_read_string(dev, "label",
729+
&nvmem_config.name);
730+
if (err)
731+
return err;
732+
} else {
733+
nvmem_config.id = NVMEM_DEVID_AUTO;
734+
nvmem_config.name = dev_name(dev);
735+
}
736+
716737
nvmem_config.type = NVMEM_TYPE_EEPROM;
717-
nvmem_config.name = dev_name(dev);
718738
nvmem_config.dev = dev;
719739
nvmem_config.id = NVMEM_DEVID_AUTO;
720740
nvmem_config.read_only = !writable;

0 commit comments

Comments
 (0)