Re: [PATCH] i2c: i2c-core-base: fix devicetree alias handling

From: Jon Hunter

Date: Fri Mar 06 2026 - 09:07:36 EST



On 06/03/2026 10:18, Jon Hunter wrote:
Hi Andreas,

On 02/03/2026 17:04, Andreas Kemnade wrote:
Parent device is not set up there, so use the new of_node pointer to
handle aliases.

Fixes: 0ab80451c70f ("i2c: allow setting the parent device and OF node through the adapter struct")
Reported-by: Kalle Niemi <kaleposti@xxxxxxxxx>
Closes: https://lore.kernel.org/lkml/ EDF3FB58-4747-442E-8463-6F1C6E568962@xxxxxxxxx/
Signed-off-by: Andreas Kemnade <andreas@xxxxxxxxxxxx>
---
  drivers/i2c/i2c-core-base.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index dd8cec9b04c6..e22d784202b8 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1657,10 +1657,9 @@ static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
   */
  int i2c_add_adapter(struct i2c_adapter *adapter)
  {
-    struct device *dev = &adapter->dev;
      int id;
-    id = of_alias_get_id(dev->of_node, "i2c");
+    id = of_alias_get_id(adapter->of_node, "i2c");
      if (id >= 0) {
          adapter->nr = id;
          return __i2c_add_numbered_adapter(adapter);

This change is breaking a test we run to check that I2C devices are populated as expected on a few of our Tegra boards. For example, on the Tegra234 board, the I2C aliases are defined in arch/arm64/boot/dts/ nvidia/tegra234.dtsi. Here we have ...

        aliases {
                i2c0 = &gen1_i2c;
                i2c1 = &gen2_i2c;
                i2c2 = &cam_i2c;
                i2c3 = &dp_aux_ch1_i2c;
                i2c4 = &bpmp_i2c;
                i2c5 = &dp_aux_ch0_i2c;
                i2c6 = &dp_aux_ch2_i2c;
                i2c7 = &gen8_i2c;
                i2c8 = &dp_aux_ch3_i2c;
        };

I guess I should add the mapping (from tegra234.dtsi) ...

&gen1_i2c --> i2c@3160000
&gen2_i2c --> i2c@c240000
&bpmp_i2c --> Tegra BPMP I2C adapter
dp_aux_ch3_i2c --> i2c@31e0000

Before this change, on the Tegra234 Jetson AGX Orin board (tegra234- p3737-0000+p3701-0000.dts) the I2C devices were mapped as above ...

/sys/class/i2c-dev/i2c-0/name --> 3160000.i2c
/sys/class/i2c-dev/i2c-1/name --> c240000.i2c
/sys/class/i2c-dev/i2c-4/name --> Tegra BPMP I2C adapter
/sys/class/i2c-dev/i2c-8/name --> 31e0000.i2c

Hence this looks correct.

After this change I now see ...

/sys/class/i2c-dev/i2c-9/name --> Tegra BPMP I2C adapter
/sys/class/i2c-dev/i2c-10/name --> 3160000.i2c
/sys/class/i2c-dev/i2c-11/name --> 31e0000.i2c
/sys/class/i2c-dev/i2c-12/name --> c240000.i2c

But this does not.

Jon

--
nvpublic