mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Billy Tsai <billy_tsai@aspeedtech.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Frank Li <Frank.Li@nxp.com>,
	Peter Yin <peteryin.openbmc@gmail.com>,
	linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] i3c: master: mark OF bus child nodes OF_POPULATED to avoid legacy I2C rescan
Date: Tue, 1 Dec 2026 15:46:26 -0500	[thread overview]
Message-ID: <aw8yIrduK65Atcj4@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20261127-i3c-master-of-populated-v2-1-c52095d00218@aspeedtech.com>

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>
>

      reply	other threads:[~2026-12-01 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  6:58 Billy Tsai
2026-12-01 20:46 ` Frank Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw8yIrduK65Atcj4@lizhi-Precision-Tower-5810 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=billy_tsai@aspeedtech.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peteryin.openbmc@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®