mbox series

[0/5] Add support for custom names for AT24 EEPROMs

Message ID 20200910134239.192030-1-jonathanh@nvidia.com
Headers show
Series Add support for custom names for AT24 EEPROMs | expand

Message

Jon Hunter Sept. 10, 2020, 1:42 p.m. UTC
For platforms that have multiple boards and hence have multiple EEPROMs
for identifying the different boards, it is useful to label the EEPROMs
in device-tree so that they can be easily identified. For example, MAC
address information is stored in the EEPROM on the processor module for
some Jetson platforms which is not only required by the kernel but the
bootloader as well. So having a simple way to identify the EEPROM is
needed.

Jon Hunter (5):
  misc: eeprom: at24: Initialise AT24 NVMEM ID field
  dt-bindings: eeprom: at24: Add label property for AT24
  misc: eeprom: at24: Support custom device names for AT24 EEPROMs
  arm64: tegra: Add label properties for EEPROMs
  arm64: tegra: Populate EEPROMs for Jetson Xavier NX

 .../devicetree/bindings/eeprom/at24.yaml         |  4 ++++
 .../boot/dts/nvidia/tegra186-p2771-0000.dts      |  1 +
 arch/arm64/boot/dts/nvidia/tegra186-p3310.dtsi   |  1 +
 arch/arm64/boot/dts/nvidia/tegra194-p2888.dtsi   |  1 +
 .../boot/dts/nvidia/tegra194-p2972-0000.dts      |  1 +
 .../nvidia/tegra194-p3509-0000+p3668-0000.dts    | 14 ++++++++++++++
 .../boot/dts/nvidia/tegra194-p3668-0000.dtsi     | 16 ++++++++++++++++
 arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi   |  1 +
 .../boot/dts/nvidia/tegra210-p2371-2180.dts      |  1 +
 .../boot/dts/nvidia/tegra210-p3450-0000.dts      |  2 ++
 drivers/misc/eeprom/at24.c                       | 11 ++++++++++-
 11 files changed, 52 insertions(+), 1 deletion(-)

Comments

Bartosz Golaszewski Sept. 10, 2020, 3:35 p.m. UTC | #1
On Thu, Sep 10, 2020 at 3:43 PM Jon Hunter <jonathanh@nvidia.com> wrote:
>
> The AT24 EEPROM driver does not initialise the 'id' field of the
> nvmem_config structure and because the entire structure is not
> initialised, it ends up with a random value. This causes the NVMEM
> driver to append the device 'devid' value to name of the NVMEM
> device. Although this is not a problem per-se, for I2C devices such as
> the AT24, that already have a device unique name, there does not seem
> much value in appending an additional 0 to the I2C name. For example,
> appending a 0 to an I2C device name such as 1-0050 does not seem
> necessary and maybe even a bit confusing. Therefore, fix this by
> setting the NVMEM config.id to NVMEM_DEVID_NONE for AT24 EEPROMs.
>
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
>  drivers/misc/eeprom/at24.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index e9df1ca251df..3f7a3bb6a36c 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -715,6 +715,7 @@ static int at24_probe(struct i2c_client *client)
>
>         nvmem_config.name = dev_name(dev);
>         nvmem_config.dev = dev;
> +       nvmem_config.id = NVMEM_DEVID_NONE;
>         nvmem_config.read_only = !writable;
>         nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO);
>         nvmem_config.owner = THIS_MODULE;
> --
> 2.25.1
>

This patch is correct and thanks for catching it. I vaguely recall
wondering at some point why the appended 0 in the nvmem name for at24.
Unfortunately this change would affect how the device is visible in
user-space in /sys/bus/nvmem/devices/ and this could break existing
users. Also: there are many in-kernel users that would need to be
updated. I'm afraid we'll need some sort of backward compatibility.

Bartosz
Jon Hunter Sept. 10, 2020, 6:15 p.m. UTC | #2
On 10/09/2020 16:35, Bartosz Golaszewski wrote:
> On Thu, Sep 10, 2020 at 3:43 PM Jon Hunter <jonathanh@nvidia.com> wrote:
>>
>> The AT24 EEPROM driver does not initialise the 'id' field of the
>> nvmem_config structure and because the entire structure is not
>> initialised, it ends up with a random value. This causes the NVMEM
>> driver to append the device 'devid' value to name of the NVMEM
>> device. Although this is not a problem per-se, for I2C devices such as
>> the AT24, that already have a device unique name, there does not seem
>> much value in appending an additional 0 to the I2C name. For example,
>> appending a 0 to an I2C device name such as 1-0050 does not seem
>> necessary and maybe even a bit confusing. Therefore, fix this by
>> setting the NVMEM config.id to NVMEM_DEVID_NONE for AT24 EEPROMs.
>>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>>  drivers/misc/eeprom/at24.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>> index e9df1ca251df..3f7a3bb6a36c 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -715,6 +715,7 @@ static int at24_probe(struct i2c_client *client)
>>
>>         nvmem_config.name = dev_name(dev);
>>         nvmem_config.dev = dev;
>> +       nvmem_config.id = NVMEM_DEVID_NONE;
>>         nvmem_config.read_only = !writable;
>>         nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO);
>>         nvmem_config.owner = THIS_MODULE;
>> --
>> 2.25.1
>>
> 
> This patch is correct and thanks for catching it. I vaguely recall
> wondering at some point why the appended 0 in the nvmem name for at24.
> Unfortunately this change would affect how the device is visible in
> user-space in /sys/bus/nvmem/devices/ and this could break existing
> users. Also: there are many in-kernel users that would need to be
> updated. I'm afraid we'll need some sort of backward compatibility.


Thanks, yes that is a problem. I guess for now we could explicitly init
to NVMEM_DEVID_AUTO or maybe just 0 so that it defaults to the same path
in the NVMEM driver. However, I am not sure how we can make allow some
devices to use NVMEM_DEVID_NONE and others use something else. This is
not really something that we can describe in DT because it has nothing
to do with h/w.

Cheers
Jon
Jon Hunter Sept. 10, 2020, 6:19 p.m. UTC | #3
On 10/09/2020 19:15, Jon Hunter wrote:
> 
> On 10/09/2020 16:35, Bartosz Golaszewski wrote:
>> On Thu, Sep 10, 2020 at 3:43 PM Jon Hunter <jonathanh@nvidia.com> wrote:
>>>
>>> The AT24 EEPROM driver does not initialise the 'id' field of the
>>> nvmem_config structure and because the entire structure is not
>>> initialised, it ends up with a random value. This causes the NVMEM
>>> driver to append the device 'devid' value to name of the NVMEM
>>> device. Although this is not a problem per-se, for I2C devices such as
>>> the AT24, that already have a device unique name, there does not seem
>>> much value in appending an additional 0 to the I2C name. For example,
>>> appending a 0 to an I2C device name such as 1-0050 does not seem
>>> necessary and maybe even a bit confusing. Therefore, fix this by
>>> setting the NVMEM config.id to NVMEM_DEVID_NONE for AT24 EEPROMs.
>>>
>>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>>> ---
>>>  drivers/misc/eeprom/at24.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>>> index e9df1ca251df..3f7a3bb6a36c 100644
>>> --- a/drivers/misc/eeprom/at24.c
>>> +++ b/drivers/misc/eeprom/at24.c
>>> @@ -715,6 +715,7 @@ static int at24_probe(struct i2c_client *client)
>>>
>>>         nvmem_config.name = dev_name(dev);
>>>         nvmem_config.dev = dev;
>>> +       nvmem_config.id = NVMEM_DEVID_NONE;
>>>         nvmem_config.read_only = !writable;
>>>         nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO);
>>>         nvmem_config.owner = THIS_MODULE;
>>> --
>>> 2.25.1
>>>
>>
>> This patch is correct and thanks for catching it. I vaguely recall
>> wondering at some point why the appended 0 in the nvmem name for at24.
>> Unfortunately this change would affect how the device is visible in
>> user-space in /sys/bus/nvmem/devices/ and this could break existing
>> users. Also: there are many in-kernel users that would need to be
>> updated. I'm afraid we'll need some sort of backward compatibility.
> 
> 
> Thanks, yes that is a problem. I guess for now we could explicitly init
> to NVMEM_DEVID_AUTO or maybe just 0 so that it defaults to the same path
> in the NVMEM driver. However, I am not sure how we can make allow some
> devices to use NVMEM_DEVID_NONE and others use something else. This is
> not really something that we can describe in DT because it has nothing
> to do with h/w.


Unless we make the configuration of the 'id' dependent on the 'label'
property so something like ...

	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);
	}

Cheers
Jon
Bartosz Golaszewski Sept. 11, 2020, 7:45 a.m. UTC | #4
On Thu, Sep 10, 2020 at 8:19 PM Jon Hunter <jonathanh@nvidia.com> wrote:
>
>
> On 10/09/2020 19:15, Jon Hunter wrote:
> >
> > On 10/09/2020 16:35, Bartosz Golaszewski wrote:
> >> On Thu, Sep 10, 2020 at 3:43 PM Jon Hunter <jonathanh@nvidia.com> wrote:
> >>>
> >>> The AT24 EEPROM driver does not initialise the 'id' field of the
> >>> nvmem_config structure and because the entire structure is not
> >>> initialised, it ends up with a random value. This causes the NVMEM
> >>> driver to append the device 'devid' value to name of the NVMEM
> >>> device. Although this is not a problem per-se, for I2C devices such as
> >>> the AT24, that already have a device unique name, there does not seem
> >>> much value in appending an additional 0 to the I2C name. For example,
> >>> appending a 0 to an I2C device name such as 1-0050 does not seem
> >>> necessary and maybe even a bit confusing. Therefore, fix this by
> >>> setting the NVMEM config.id to NVMEM_DEVID_NONE for AT24 EEPROMs.
> >>>
> >>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> >>> ---
> >>>  drivers/misc/eeprom/at24.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> >>> index e9df1ca251df..3f7a3bb6a36c 100644
> >>> --- a/drivers/misc/eeprom/at24.c
> >>> +++ b/drivers/misc/eeprom/at24.c
> >>> @@ -715,6 +715,7 @@ static int at24_probe(struct i2c_client *client)
> >>>
> >>>         nvmem_config.name = dev_name(dev);
> >>>         nvmem_config.dev = dev;
> >>> +       nvmem_config.id = NVMEM_DEVID_NONE;
> >>>         nvmem_config.read_only = !writable;
> >>>         nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO);
> >>>         nvmem_config.owner = THIS_MODULE;
> >>> --
> >>> 2.25.1
> >>>
> >>
> >> This patch is correct and thanks for catching it. I vaguely recall
> >> wondering at some point why the appended 0 in the nvmem name for at24.
> >> Unfortunately this change would affect how the device is visible in
> >> user-space in /sys/bus/nvmem/devices/ and this could break existing
> >> users. Also: there are many in-kernel users that would need to be
> >> updated. I'm afraid we'll need some sort of backward compatibility.
> >
> >
> > Thanks, yes that is a problem. I guess for now we could explicitly init
> > to NVMEM_DEVID_AUTO or maybe just 0 so that it defaults to the same path
> > in the NVMEM driver. However, I am not sure how we can make allow some
> > devices to use NVMEM_DEVID_NONE and others use something else. This is
> > not really something that we can describe in DT because it has nothing
> > to do with h/w.
>
>
> Unless we make the configuration of the 'id' dependent on the 'label'
> property so something like ...
>
>         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);
>         }
>
> Cheers
> Jon
>
> --
> nvpublic

Yes, this looks like the best compromise we can get for now. Please
make sure to document why we do this in the code.

Bartosz