* [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
@ 2026-11-27 6:58 Billy Tsai
2026-12-01 20:46 ` Frank Li
0 siblings, 1 reply; 2+ messages in thread
From: Billy Tsai @ 2026-11-27 6:58 UTC (permalink / raw)
To: Alexandre Belloni, Frank Li, Peter Yin
Cc: linux-i3c, linux-kernel, stable, Billy Tsai
Commit f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for
virtual I2C adapter") made the DesignWare I3C master's virtual legacy
I2C adapter reuse the I3C bus platform device's of_node, so consumers
can resolve the adapter by phandle. i2c_register_adapter() reacts to
any adapter with a non-NULL of_node by unconditionally calling
of_i2c_register_devices(), which walks every child of that node and
requires a "compatible" property to build a modalias.
The I3C core already owns and fully parses every child of the bus node
via fwnode_populate_i3c_bus()/i3c_master_add_of_dev(), for both native
I3C devices (no "compatible" needed per the i3c.yaml binding) and
legacy-I2C-under-I3C devices (registered explicitly through
master->boardinfo.i2c in i3c_master_i2c_adapter_init()). Since neither
path marks the node OF_POPULATED, the generic of_i2c_register_devices()
walk that now runs afterwards treats every child as unclaimed:
- native I3C-only nodes have no "compatible", so of_i2c_get_board_info()
fails the modalias lookup and logs "of_i2c: modalias failure" /
"Failed to create I2C device" noise for a device that is already
correctly registered on the I3C bus.
- legacy-I2C nodes do have "compatible", so of_i2c_register_devices()
silently creates a duplicate i2c_client for the same address that
i3c_master_i2c_adapter_init() also registers from boardinfo.i2c.
Mark each OF bus child OF_POPULATED once i3c_master_add_of_dev() has
accounted for it. ACPI-described children are left untouched, since
OF_POPULATED and of_i2c_register_devices() only apply to the
devicetree case. fwnode_populate_i3c_bus() always runs before the I2C
adapter is registered, so of_i2c_register_devices() sees the flag
already set and skips these nodes entirely, without disturbing the
of_node propagation from f26ecaa0f0ab.
OF_POPULATED is a property of the device_node itself, which outlives
this master's registration. fwnode_depopulate_i3c_bus() is the
counterpart that clears the flag again, called from
i3c_master_bus_cleanup() (shared by the registration error path and
i3c_master_unregister()) and from fwnode_populate_i3c_bus()'s own
error path. Without it, the nodes stay claimed after this master is
unbound or fails to register, and a later re-probe or rebind finds
them already marked and silently skips creating their devices.
Fixes: f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for virtual I2C adapter")
Cc: stable@vger.kernel.org
Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
Changes in v2:
- Also clear OF_POPULATED again on teardown and on a mid-loop probe
failure (fwnode_depopulate_i3c_bus(), called from
i3c_master_bus_cleanup() and from fwnode_populate_i3c_bus()'s own
error path), so unregister/rebind and a failed probe do not leave OF
bus children permanently marked.
- Link to v1: https://lore.kernel.org/r/20261127-i3c-master-of-populated-v1-1-29d2a6a5509c@aspeedtech.com
---
drivers/i3c/master.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 01e05bad8661..e85307678fdc 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2667,6 +2667,8 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
return ret;
}
+static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master);
+
static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
{
if (master->ops->bus_cleanup) {
@@ -2681,6 +2683,7 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
}
}
+ fwnode_depopulate_i3c_bus(master);
i3c_master_detach_free_devs(master);
}
@@ -3353,15 +3356,29 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
return 0;
fwnode_for_each_available_child_node_scoped(fwnode, child) {
- if (is_of_node(child))
+ if (is_of_node(child)) {
ret = i3c_master_add_of_dev(master, child);
- else if (is_acpi_device_node(child))
- ret = i3c_master_add_acpi_dev(master, child);
- else
- continue;
+ if (ret) {
+ fwnode_depopulate_i3c_bus(master);
+ return ret;
+ }
- if (ret)
- return ret;
+ /*
+ * Claim the node so that i2c_register_adapter(),
+ * called later for the legacy I2C adapter sharing
+ * this same of_node, does not also run
+ * of_i2c_register_devices() on it: every child here
+ * is already fully accounted for, whether it ends up
+ * I3C or legacy-I2C boardinfo.
+ */
+ of_node_set_flag(to_of_node(child), OF_POPULATED);
+ } else if (is_acpi_device_node(child)) {
+ ret = i3c_master_add_acpi_dev(master, child);
+ if (ret) {
+ fwnode_depopulate_i3c_bus(master);
+ return ret;
+ }
+ }
}
/*
@@ -3378,6 +3395,26 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
return 0;
}
+/*
+ * Counterpart to fwnode_populate_i3c_bus(): drop the OF_POPULATED claim on
+ * every OF bus child so a later re-probe of this master, or the legacy I2C
+ * adapter's of_i2c_register_devices() walk on a different master sharing
+ * the same of_node, does not find these nodes permanently locked out.
+ * ACPI-described children were never marked, so they are skipped here too.
+ */
+static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master)
+{
+ struct fwnode_handle *fwnode = dev_fwnode(&master->dev);
+
+ if (!fwnode)
+ return;
+
+ fwnode_for_each_available_child_node_scoped(fwnode, child) {
+ if (is_of_node(child))
+ of_node_clear_flag(to_of_node(child), OF_POPULATED);
+ }
+}
+
static int i3c_master_i2c_adapter_xfer(struct i2c_adapter *adap,
struct i2c_msg *xfers, int nxfers)
{
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261127-i3c-master-of-populated-2ef07c2bb743
Best regards,
--
Billy Tsai <billy_tsai@aspeedtech.com>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
2026-11-27 6:58 [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
@ 2026-12-01 20:46 ` Frank Li
0 siblings, 0 replies; 2+ messages in thread
From: Frank Li @ 2026-12-01 20:46 UTC (permalink / raw)
To: Billy Tsai
Cc: Alexandre Belloni, Frank Li, Peter Yin, linux-i3c, linux-kernel, stable
On Fri, Nov 27, 2026 at 02:58:15PM +0800, Billy Tsai wrote:
> Commit f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for
> virtual I2C adapter") made the DesignWare I3C master's virtual legacy
> I2C adapter reuse the I3C bus platform device's of_node, so consumers
> can resolve the adapter by phandle. i2c_register_adapter() reacts to
> any adapter with a non-NULL of_node by unconditionally calling
> of_i2c_register_devices(), which walks every child of that node and
> requires a "compatible" property to build a modalias.
>
> The I3C core already owns and fully parses every child of the bus node
> via fwnode_populate_i3c_bus()/i3c_master_add_of_dev(), for both native
> I3C devices (no "compatible" needed per the i3c.yaml binding) and
> legacy-I2C-under-I3C devices (registered explicitly through
> master->boardinfo.i2c in i3c_master_i2c_adapter_init()). Since neither
> path marks the node OF_POPULATED, the generic of_i2c_register_devices()
> walk that now runs afterwards treats every child as unclaimed:
>
> - native I3C-only nodes have no "compatible", so of_i2c_get_board_info()
> fails the modalias lookup and logs "of_i2c: modalias failure" /
> "Failed to create I2C device" noise for a device that is already
> correctly registered on the I3C bus.
>
> - legacy-I2C nodes do have "compatible", so of_i2c_register_devices()
> silently creates a duplicate i2c_client for the same address that
> i3c_master_i2c_adapter_init() also registers from boardinfo.i2c.
>
> Mark each OF bus child OF_POPULATED once i3c_master_add_of_dev() has
> accounted for it. ACPI-described children are left untouched, since
> OF_POPULATED and of_i2c_register_devices() only apply to the
> devicetree case. fwnode_populate_i3c_bus() always runs before the I2C
> adapter is registered, so of_i2c_register_devices() sees the flag
> already set and skips these nodes entirely, without disturbing the
> of_node propagation from f26ecaa0f0ab.
>
> OF_POPULATED is a property of the device_node itself, which outlives
> this master's registration. fwnode_depopulate_i3c_bus() is the
> counterpart that clears the flag again, called from
> i3c_master_bus_cleanup() (shared by the registration error path and
> i3c_master_unregister()) and from fwnode_populate_i3c_bus()'s own
> error path. Without it, the nodes stay claimed after this master is
> unbound or fails to register, and a later re-probe or rebind finds
> them already marked and silently skips creating their devices.
>
> Fixes: f26ecaa0f0ab ("i3c: master: dw-i3c: Fix missing of_node for virtual I2C adapter")
> Cc: stable@vger.kernel.org
> Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
> ---
> Changes in v2:
> - Also clear OF_POPULATED again on teardown and on a mid-loop probe
> failure (fwnode_depopulate_i3c_bus(), called from
> i3c_master_bus_cleanup() and from fwnode_populate_i3c_bus()'s own
> error path), so unregister/rebind and a failed probe do not leave OF
> bus children permanently marked.
> - Link to v1: https://lore.kernel.org/r/20261127-i3c-master-of-populated-v1-1-29d2a6a5509c@aspeedtech.com
> ---
> drivers/i3c/master.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 44 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 01e05bad8661..e85307678fdc 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -2667,6 +2667,8 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
> return ret;
> }
>
> +static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master);
> +
Can you move function implement to here to avoid forward declear?
Frank
> static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
> {
> if (master->ops->bus_cleanup) {
> @@ -2681,6 +2683,7 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
> }
> }
>
> + fwnode_depopulate_i3c_bus(master);
> i3c_master_detach_free_devs(master);
> }
>
> @@ -3353,15 +3356,29 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
> return 0;
>
> fwnode_for_each_available_child_node_scoped(fwnode, child) {
> - if (is_of_node(child))
> + if (is_of_node(child)) {
> ret = i3c_master_add_of_dev(master, child);
> - else if (is_acpi_device_node(child))
> - ret = i3c_master_add_acpi_dev(master, child);
> - else
> - continue;
> + if (ret) {
> + fwnode_depopulate_i3c_bus(master);
> + return ret;
> + }
>
> - if (ret)
> - return ret;
> + /*
> + * Claim the node so that i2c_register_adapter(),
> + * called later for the legacy I2C adapter sharing
> + * this same of_node, does not also run
> + * of_i2c_register_devices() on it: every child here
> + * is already fully accounted for, whether it ends up
> + * I3C or legacy-I2C boardinfo.
> + */
> + of_node_set_flag(to_of_node(child), OF_POPULATED);
> + } else if (is_acpi_device_node(child)) {
> + ret = i3c_master_add_acpi_dev(master, child);
> + if (ret) {
> + fwnode_depopulate_i3c_bus(master);
> + return ret;
> + }
> + }
> }
>
> /*
> @@ -3378,6 +3395,26 @@ static int fwnode_populate_i3c_bus(struct i3c_master_controller *master)
> return 0;
> }
>
> +/*
> + * Counterpart to fwnode_populate_i3c_bus(): drop the OF_POPULATED claim on
> + * every OF bus child so a later re-probe of this master, or the legacy I2C
> + * adapter's of_i2c_register_devices() walk on a different master sharing
> + * the same of_node, does not find these nodes permanently locked out.
> + * ACPI-described children were never marked, so they are skipped here too.
> + */
> +static void fwnode_depopulate_i3c_bus(struct i3c_master_controller *master)
> +{
> + struct fwnode_handle *fwnode = dev_fwnode(&master->dev);
> +
> + if (!fwnode)
> + return;
> +
> + fwnode_for_each_available_child_node_scoped(fwnode, child) {
> + if (is_of_node(child))
> + of_node_clear_flag(to_of_node(child), OF_POPULATED);
> + }
> +}
> +
> static int i3c_master_i2c_adapter_xfer(struct i2c_adapter *adap,
> struct i2c_msg *xfers, int nxfers)
> {
>
> ---
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> change-id: 20261127-i3c-master-of-populated-2ef07c2bb743
>
> Best regards,
> --
> Billy Tsai <billy_tsai@aspeedtech.com>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 20:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 6:58 [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan Billy Tsai
2026-12-01 20:46 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®