The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Peter Rosin <peda@lysator.liu.se>
To: Ahmad Byagowi <ahmadexp@gmail.com>, Andy Shevchenko <andy@kernel.org>
Cc: Andi Shyti <andi.shyti@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 3/3] i2c: mux: Propagate software nodes to channel adapters
Date: Tue, 25 Aug 2026 07:50:54 +0200	[thread overview]
Message-ID: <ao0tPhBvK1Er_Vs0@gryt> (raw)
In-Reply-To: <a4abcd31c3a6758e219f5edcdd4acd307e674f18.1787502619.git.ahmadexp@gmail.com>

Hi!

[Adding Andy]

Den Sun, Aug 23, 2026 at 09:34:38AM -0700, skrev Ahmad Byagowi:
> Device Tree channel nodes are associated with the adapters created by
> i2c-mux, but equivalent software-node descriptions are not.
> 
> Use generic firmware-node operations for the existing channel lookup and
> accept either an OF node or a software node. Associate the returned node
> with the adapter so child I2C devices can be instantiated from
> software-node properties.
> 
> Save the adapter firmware node before adapter deletion and release the
> reference afterwards, following the lifetime pattern in i2c-atr.
> 
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
>  drivers/i2c/i2c-mux.c | 45 +++++++++++++++++++++----------------------
>  1 file changed, 22 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index a8b94b97a725..b37d36d3b121 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -25,6 +25,7 @@
>  #include <linux/kernel.h>
>  #include <linux/module.h>
>  #include <linux/of.h>
> +#include <linux/property.h>
>  #include <linux/slab.h>
>  #include <linux/sysfs.h>
>  
> @@ -264,40 +265,40 @@ static const struct i2c_lock_operations i2c_parent_lock_ops = {
>  	.unlock_bus =  i2c_parent_unlock_bus,
>  };
>  
> -static struct device_node *
> +static struct fwnode_handle *
>  i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id)
>  {
> -	struct device_node *dev_node = muxc->dev->of_node;
> -	struct device_node *mux_node, *child = NULL;
> +	struct fwnode_handle *dev_node = dev_fwnode(muxc->dev);
> +	struct fwnode_handle *mux_node, *child = NULL;
>  	u32 reg;
>  	int ret;
>  
> -	if (!dev_node)
> +	if (!is_of_node(dev_node) && !is_software_node(dev_node))
>  		return NULL;

I wonder if this is needed? Andy, I seem to recall that you were
involved with adding ACPI support? Do you have anything to add?

Cheers,
Peter

>  
>  	if (muxc->arbitrator)
> -		mux_node = of_get_child_by_name(dev_node, "i2c-arb");
> +		mux_node = fwnode_get_named_child_node(dev_node, "i2c-arb");
>  	else if (muxc->gate)
> -		mux_node = of_get_child_by_name(dev_node, "i2c-gate");
> +		mux_node = fwnode_get_named_child_node(dev_node, "i2c-gate");
>  	else
> -		mux_node = of_get_child_by_name(dev_node, "i2c-mux");
> +		mux_node = fwnode_get_named_child_node(dev_node, "i2c-mux");
>  
>  	if (mux_node) {
> -		/* A "reg" property indicates an old-style DT entry */
> -		if (!of_property_read_u32(mux_node, "reg", &reg)) {
> -			of_node_put(mux_node);
> +		/* A "reg" property indicates an old-style firmware entry. */
> +		if (!fwnode_property_read_u32(mux_node, "reg", &reg)) {
> +			fwnode_handle_put(mux_node);
>  			mux_node = NULL;
>  		}
>  	}
>  
>  	if (!mux_node)
> -		mux_node = of_node_get(dev_node);
> +		mux_node = fwnode_handle_get(dev_node);
>  	else if (muxc->arbitrator || muxc->gate)
> -		child = of_node_get(mux_node);
> +		child = fwnode_handle_get(mux_node);
>  
>  	if (!child) {
> -		for_each_child_of_node(mux_node, child) {
> -			ret = of_property_read_u32(child, "reg", &reg);
> +		fwnode_for_each_child_node(mux_node, child) {
> +			ret = fwnode_property_read_u32(child, "reg", &reg);
>  			if (ret)
>  				continue;
>  			if (chan_id == reg)
> @@ -305,7 +306,7 @@ i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id)
>  		}
>  	}
>  
> -	of_node_put(mux_node);
> +	fwnode_handle_put(mux_node);
>  	return child;
>  }
>  
> @@ -368,11 +369,9 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
>  	else
>  		priv->adap.lock_ops = &i2c_parent_lock_ops;
>  
> -	/*
> -	 * Try to populate the mux adapter's of_node, expands to
> -	 * nothing if !CONFIG_OF.
> -	 */
> -	priv->adap.dev.of_node = i2c_mux_get_channel_node(muxc, chan_id);
> +	/* Associate the mux adapter with its OF or software-node channel. */
> +	device_set_node(&priv->adap.dev,
> +			i2c_mux_get_channel_node(muxc, chan_id));
>  
>  	/*
>  	 * Associate the mux channel with an ACPI node.
> @@ -416,7 +415,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
>  	return 0;
>  
>  err_free_priv:
> -	of_node_put(priv->adap.dev.of_node);
> +	fwnode_handle_put(dev_fwnode(&priv->adap.dev));
>  	kfree(priv);
>  	return ret;
>  }
> @@ -429,7 +428,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
>  	while (muxc->num_adapters) {
>  		struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters];
>  		struct i2c_mux_priv *priv = adap->algo_data;
> -		struct device_node *np = adap->dev.of_node;
> +		struct fwnode_handle *fwnode = dev_fwnode(&adap->dev);
>  
>  		muxc->adapter[muxc->num_adapters] = NULL;
>  
> @@ -439,7 +438,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
>  
>  		sysfs_remove_link(&priv->adap.dev.kobj, "mux_device");
>  		i2c_del_adapter(adap);
> -		of_node_put(np);
> +		fwnode_handle_put(fwnode);
>  		kfree(priv);
>  	}
>  }
> -- 
> 2.50.1 (Apple Git-155)
> 

      reply	other threads:[~2026-08-25  5:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23 16:34 [PATCH v7 0/3] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
2026-08-23 16:34 ` [PATCH v7 1/3] i2c: mux: Fix channel node leak on adapter add failure Ahmad Byagowi
2026-08-25  5:49   ` Peter Rosin
2026-08-23 16:34 ` [PATCH v7 2/3] i2c: mux: Factor out channel node lookup Ahmad Byagowi
2026-08-25  5:50   ` Peter Rosin
2026-08-23 16:34 ` [PATCH v7 3/3] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
2026-08-25  5:50   ` Peter Rosin [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=ao0tPhBvK1Er_Vs0@gryt \
    --to=peda@lysator.liu.se \
    --cc=ahmadexp@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=andy@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@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