[PATCH AUTOSEL 6.19-6.12] i3c: master: dw-i3c: Fix missing of_node for virtual I2C adapter

From: Sasha Levin

Date: Tue Mar 17 2026 - 07:36:12 EST


From: Peter Yin <peteryin.openbmc@xxxxxxxxx>

[ Upstream commit f26ecaa0f0abfe5db173416214098a00d3b7db79 ]

The DesignWare I3C master driver creates a virtual I2C adapter to
provide backward compatibility with I2C devices. However, the current
implementation does not associate this virtual adapter with any
Device Tree node.

Propagate the of_node from the I3C master platform device to the
virtual I2C adapter's device structure. This ensures that standard
I2C aliases are correctly resolved and bus numbering remains consistent.

Signed-off-by: Peter Yin <peteryin.openbmc@xxxxxxxxx>
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
Link: https://patch.msgid.link/20260302075645.1492766-1-peteryin.openbmc@xxxxxxxxx
Signed-off-by: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---

LLM Generated explanations, may be completely bogus:

Now I have the complete picture.

## Analysis

### What the commit fixes

The DesignWare I3C master driver creates a virtual I2C adapter
(`master->base.i2c`) for backward compatibility. When this adapter is
registered via `i3c_master_register()` ->
`i3c_master_i2c_adapter_init()` -> `i2c_add_adapter()`, the I2C core
calls `of_i2c_register_devices(adap)` (at `i2c-core-base.c:1593`).

The critical code in `of_i2c_register_devices()` at `i2c-core-of.c:90`:
```c
if (!adap->dev.of_node)
return;
```

**Without this fix**, `adap->dev.of_node` is NULL, so
`of_i2c_register_devices()` returns immediately without registering any
I2C child devices described in the device tree. This means **I2C devices
under the I3C master node in the DT will never be discovered or
registered**.

### Bug severity

This is a real functional bug. On systems using Device Tree (most
ARM/embedded systems where this driver is used - OpenBMC systems, etc.),
I2C devices behind the DW I3C master won't be enumerated. The author's
email (`peteryin.openbmc@xxxxxxxxx`) confirms this is from an OpenBMC
context where DT-based I2C device discovery is essential.

### Stable criteria assessment

- **Fixes a real bug**: Yes - I2C devices behind I3C master are not
discovered from DT
- **Obviously correct**: Yes - `device_set_of_node_from_dev` is a well-
established helper, and propagating the parent's of_node to a virtual
adapter is standard practice
- **Small and contained**: Yes - single line addition in one file
- **No new features**: Correct - this restores expected functionality
(DT device discovery)
- **Reviewed**: Yes - by Frank Li at NXP (an I3C hardware vendor)

### Risk assessment

Very low risk. The change adds one call to
`device_set_of_node_from_dev()` before `i3c_master_register()`. The
function safely handles refcounting (does `of_node_put` on old,
`of_node_get` on new). If the pdev has no of_node, it's a no-op (NULL ->
NULL).

### Verification

- Read `dw-i3c-master.c:1616-1618`: confirmed the current code has no
of_node propagation before `i3c_master_register()`
- Read `drivers/i3c/master.c:2554-2574`: confirmed
`i3c_master_i2c_adapter_init()` sets `adap->dev.parent` but NOT
`adap->dev.of_node`
- Read `drivers/i2c/i2c-core-of.c:84-91`: confirmed
`of_i2c_register_devices()` returns immediately if `adap->dev.of_node`
is NULL - this is the concrete bug mechanism
- Read `drivers/i2c/i2c-core-base.c:1593`: confirmed
`of_i2c_register_devices()` is called during adapter registration
- git log confirmed the dw-i3c-master.c has existed for a long time and
this code path is established
- The fix pattern (propagating of_node to virtual/child devices) is
standard across the kernel

### Concerns

- The commit doesn't have a `Fixes:` tag pointing to the original commit
that created the driver, but as noted in the guidelines, this is
expected for commits under review
- No dependency on other patches - this is fully self-contained
- The `device_set_of_node_from_dev()` function has been available since
kernel 5.x, so this should apply cleanly to all active stable trees
that have the DW I3C driver

This is a clear bug fix: I2C devices described in Device Tree under an
I3C master node are silently not discovered because the virtual I2C
adapter lacks the of_node needed by the I2C core's DT enumeration. The
fix is a single, safe, well-reviewed line.

**YES**

drivers/i3c/master/dw-i3c-master.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 4033bc16677ff..aa683894e6de9 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -1614,6 +1614,8 @@ int dw_i3c_common_probe(struct dw_i3c_master *master,
pm_runtime_get_noresume(&pdev->dev);

INIT_WORK(&master->hj_work, dw_i3c_hj_work);
+
+ device_set_of_node_from_dev(&master->base.i2c.dev, &pdev->dev);
ret = i3c_master_register(&master->base, &pdev->dev,
&dw_mipi_i3c_ops, false);
if (ret)
--
2.51.0