Linux-i2c Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v1 0/2] Override device name using DT "dev-name" property
@ 2021-04-07 18:50 Manish Varma
  2021-04-07 18:50 ` [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name Manish Varma
  2021-04-07 18:50 ` [PATCH v1 2/2] i2c: use "dev-name" device tree property to override " Manish Varma
  0 siblings, 2 replies; 5+ messages in thread
From: Manish Varma @ 2021-04-07 18:50 UTC (permalink / raw)
  To: Wolfram Sang, Rob Herring
  Cc: linux-i2c, devicetree, linux-kernel, kernel-team, Manish Varma

Currently I2C device names are assigned dynamically unless they are
instantiated through ACPI, this names are based on adapter_id and
device_address. While device_address will remain constant for a given
device, the adapter_id may vary across different systems and hence,
overall, the device name won't be unique for the same I2C device.

Changes here addresses this problem by introducing an optional device
tree property "dev-name", which will be used to set the device name,
if present, instead of following <adapter_id>-<device_addr> convention.

Manish Varma (2):
  dt-bindings: i2c: add "dev-name" property to assign specific device
    name
  i2c: use "dev-name" device tree property to override device name

 Documentation/devicetree/bindings/i2c/i2c.txt | 5 +++++
 drivers/i2c/i2c-core-of.c                     | 2 ++
 2 files changed, 7 insertions(+)

-- 
2.31.1.295.g9ea45b61b8-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name
  2021-04-07 18:50 [PATCH v1 0/2] Override device name using DT "dev-name" property Manish Varma
@ 2021-04-07 18:50 ` Manish Varma
  2021-04-09 18:34   ` Rob Herring
  2021-04-07 18:50 ` [PATCH v1 2/2] i2c: use "dev-name" device tree property to override " Manish Varma
  1 sibling, 1 reply; 5+ messages in thread
From: Manish Varma @ 2021-04-07 18:50 UTC (permalink / raw)
  To: Wolfram Sang, Rob Herring
  Cc: linux-i2c, devicetree, linux-kernel, kernel-team, Manish Varma

I2C devices currently are named dynamically using
<adapter_id>-<device_address> convention, unless they are instantiated
through ACPI.

This means the device name may vary for the same device across different
systems, infact even on the same system if the I2C bus enumeration order
changes, i.e. because of device tree modifications.

By adding an optional "dev-name" property, it provides a mechanism to
set consistent and easy to recognize names for I2C devices.

Signed-off-by: Manish Varma <varmam@google.com>
---
 Documentation/devicetree/bindings/i2c/i2c.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
index df41f72afc87..6fb03f464b81 100644
--- a/Documentation/devicetree/bindings/i2c/i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c.txt
@@ -130,6 +130,11 @@ wants to support one of the below features, it should adapt these bindings.
 - wakeup-source
 	device can be used as a wakeup source.
 
+- dev-name
+	Name of the device.
+	Overrides the default device name which is in the form of
+	<busnr>-<addr>.
+
 Binding may contain optional "interrupts" property, describing interrupts
 used by the device. I2C core will assign "irq" interrupt (or the very first
 interrupt if not using interrupt names) as primary interrupt for the slave.
-- 
2.31.1.295.g9ea45b61b8-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] i2c: use "dev-name" device tree property to override device name
  2021-04-07 18:50 [PATCH v1 0/2] Override device name using DT "dev-name" property Manish Varma
  2021-04-07 18:50 ` [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name Manish Varma
@ 2021-04-07 18:50 ` Manish Varma
  1 sibling, 0 replies; 5+ messages in thread
From: Manish Varma @ 2021-04-07 18:50 UTC (permalink / raw)
  To: Wolfram Sang, Rob Herring
  Cc: linux-i2c, devicetree, linux-kernel, kernel-team, Manish Varma

Since the dev_name field of i2c_board_info is not set while instantiating
an I2C device, they are named like <adapter_id>-<device_addr>, unless
they are instantiated through ACPI.

These coded names are less desirable in some situations as they will vary
across systems with different hardware configurations, and even also on
the same system as the adapter_id may change with change in the order
of i2c bus enumeration (i.e. due to device tree modifications).

These device names are further used by other modules like "system wakeup
events framework" to assign the name of wakeup_source. So overall this
causes somewhat difficult to interpret device and wakeup source names,
and hence presents difficulties debuging issues at multiple levels.

This change addresses above mentioned problem by setting dev_name field
based on value assigned to an optional "dev-name" property of device
tree (if present). And as a result of this, i2c_dev_set_name() should now
use the actual device name instead of made up one.

Signed-off-by: Manish Varma <varmam@google.com>
---
 drivers/i2c/i2c-core-of.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c
index 3ed74aa4b44b..d7a85a9cc499 100644
--- a/drivers/i2c/i2c-core-of.c
+++ b/drivers/i2c/i2c-core-of.c
@@ -58,6 +58,8 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node,
 	if (of_get_property(node, "wakeup-source", NULL))
 		info->flags |= I2C_CLIENT_WAKE;
 
+	of_property_read_string(node, "dev-name", &(info->dev_name));
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_i2c_get_board_info);
-- 
2.31.1.295.g9ea45b61b8-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name
  2021-04-07 18:50 ` [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name Manish Varma
@ 2021-04-09 18:34   ` Rob Herring
  2021-04-19 23:21     ` Manish Varma
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2021-04-09 18:34 UTC (permalink / raw)
  To: Manish Varma
  Cc: Wolfram Sang, linux-i2c, devicetree, linux-kernel, kernel-team

On Wed, Apr 07, 2021 at 11:50:38AM -0700, Manish Varma wrote:
> I2C devices currently are named dynamically using
> <adapter_id>-<device_address> convention, unless they are instantiated
> through ACPI.
> 
> This means the device name may vary for the same device across different
> systems, infact even on the same system if the I2C bus enumeration order
> changes, i.e. because of device tree modifications.
> 
> By adding an optional "dev-name" property, it provides a mechanism to
> set consistent and easy to recognize names for I2C devices.

So? Why do you need 'easy to recognize names'?

Why is I2C special? If we wanted this in DT, it wouldn't be I2C specific 
and we probably would have added it long ago.

> Signed-off-by: Manish Varma <varmam@google.com>
> ---
>  Documentation/devicetree/bindings/i2c/i2c.txt | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
> index df41f72afc87..6fb03f464b81 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c.txt
> +++ b/Documentation/devicetree/bindings/i2c/i2c.txt
> @@ -130,6 +130,11 @@ wants to support one of the below features, it should adapt these bindings.
>  - wakeup-source
>  	device can be used as a wakeup source.
>  
> +- dev-name
> +	Name of the device.
> +	Overrides the default device name which is in the form of
> +	<busnr>-<addr>.

What's 'busnr'? No such thing in DT.

> +
>  Binding may contain optional "interrupts" property, describing interrupts
>  used by the device. I2C core will assign "irq" interrupt (or the very first
>  interrupt if not using interrupt names) as primary interrupt for the slave.
> -- 
> 2.31.1.295.g9ea45b61b8-goog
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name
  2021-04-09 18:34   ` Rob Herring
@ 2021-04-19 23:21     ` Manish Varma
  0 siblings, 0 replies; 5+ messages in thread
From: Manish Varma @ 2021-04-19 23:21 UTC (permalink / raw)
  To: Rob Herring
  Cc: Wolfram Sang, linux-i2c, devicetree, linux-kernel, kernel-team

Hi Rob,

Thanks for the inputs.

On Fri, Apr 9, 2021 at 11:34 AM Rob Herring <robh@kernel.org> wrote:
>
> On Wed, Apr 07, 2021 at 11:50:38AM -0700, Manish Varma wrote:
> > I2C devices currently are named dynamically using
> > <adapter_id>-<device_address> convention, unless they are instantiated
> > through ACPI.
> >
> > This means the device name may vary for the same device across different
> > systems, infact even on the same system if the I2C bus enumeration order
> > changes, i.e. because of device tree modifications.
> >
> > By adding an optional "dev-name" property, it provides a mechanism to
> > set consistent and easy to recognize names for I2C devices.
>
> So? Why do you need 'easy to recognize names'?
>

From the cover letter:

"Currently I2C device names are assigned dynamically unless they are
instantiated through ACPI, this names are based on adapter_id and
device_address. While device_address will remain constant for a given
device, the adapter_id may vary across different systems and hence,
overall, the device name won't be unique for the same I2C device."

Basically, the motivation here is to provide a mechanism to allow overriding
those names to easy to recognize names (e.g. <vendor_name_dev_name>
or <device part number> which leaves more information compared to just
device name in the form of numbers such as "2-001f").

These (device) names are further used by different module e.g. system
wakeup events framework, and hence this presents difficulties debug/identify
issues at various levels in the software stack.

So, the idea was to address it at the lowest level possible.

> Why is I2C special? If we wanted this in DT, it wouldn't be I2C specific
> and we probably would have added it long ago.
>

"Unlike PCI or USB devices, I2C devices are not enumerated at the hardware
level. Instead, the software must know which devices are connected on each
I2C bus segment, and what address these devices are using. For this
reason, the kernel code must instantiate I2C devices explicitly."

Reference: https://www.kernel.org/doc/Documentation/i2c/instantiating-devices

There are various ways to instantiate I2C devices e.g. through board_info
interface, ACPI and device tree etc.

While board_info and ACPI both allow specifying device name, I find no such
provision to assign device names for the I2C devices instantiated through
device tree interface.

> > Signed-off-by: Manish Varma <varmam@google.com>
> > ---
> >  Documentation/devicetree/bindings/i2c/i2c.txt | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt
> > index df41f72afc87..6fb03f464b81 100644
> > --- a/Documentation/devicetree/bindings/i2c/i2c.txt
> > +++ b/Documentation/devicetree/bindings/i2c/i2c.txt
> > @@ -130,6 +130,11 @@ wants to support one of the below features, it should adapt these bindings.
> >  - wakeup-source
> >       device can be used as a wakeup source.
> >
> > +- dev-name
> > +     Name of the device.
> > +     Overrides the default device name which is in the form of
> > +     <busnr>-<addr>.
>
> What's 'busnr'? No such thing in DT.
>

Right! dev-name introduced to hold the string value for overriding
device names assigned by the kernel. Currently, kernel assigns the device
name in the form of <busnr>-<addr>.

Reference:
https://www.kernel.org/doc/html/latest/driver-api/i2c.html?highlight=i2c_board_info#c.i2c_board_info

> > +
> >  Binding may contain optional "interrupts" property, describing interrupts
> >  used by the device. I2C core will assign "irq" interrupt (or the very first
> >  interrupt if not using interrupt names) as primary interrupt for the slave.
> > --
> > 2.31.1.295.g9ea45b61b8-goog
> >

Hope the explanation provided above answers your questions.

Thanks,
Manish

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 18:50 [PATCH v1 0/2] Override device name using DT "dev-name" property Manish Varma
2021-04-07 18:50 ` [PATCH v1 1/2] dt-bindings: i2c: add "dev-name" property to assign specific device name Manish Varma
2021-04-09 18:34   ` Rob Herring
2021-04-19 23:21     ` Manish Varma
2021-04-07 18:50 ` [PATCH v1 2/2] i2c: use "dev-name" device tree property to override " Manish Varma

Linux-i2c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i2c/0 linux-i2c/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-i2c linux-i2c/ https://lore.kernel.org/linux-i2c \
		linux-i2c@vger.kernel.org
	public-inbox-index linux-i2c

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-i2c


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git