Re: [PATCH v9 1/2] i2c: mux: Factor out channel node lookup
From: Andy Shevchenko
Date: Thu Sep 03 2026 - 16:07:53 EST
On Thu, Sep 03, 2026 at 12:40:55PM -0700, Ahmad Byagowi wrote:
> Move the existing Device Tree channel-node lookup into a helper in
> preparation for using generic firmware-node operations.
>
> This is a pure refactoring with no functional change.
...
> +static struct device_node *
> +i2c_mux_get_channel_node(struct i2c_mux_core *muxc, u32 chan_id)
> +{
> + struct device_node *dev_node;
> + struct device_node *mux_node, *child;
Now all three can be defined in a single line.
> + u32 reg;
> + int ret;
> +
> + dev_node = dev_of_node(muxc->dev);
> + if (!dev_node)
> + return NULL;
> +
> + if (muxc->arbitrator)
> + mux_node = of_get_child_by_name(dev_node, "i2c-arb");
> + else if (muxc->gate)
> + mux_node = of_get_child_by_name(dev_node, "i2c-gate");
> + else
> + mux_node = of_get_child_by_name(dev_node, "i2c-mux");
> +
> + if (mux_node) {
> + /* A "reg" property indicates an old-style DT entry */
> + if (!of_property_read_u32(mux_node, "reg", ®)) {
> + of_node_put(mux_node);
> + mux_node = NULL;
> + }
> + }
> +
> + if (!mux_node)
> + mux_node = of_node_get(dev_node);
> + else if (muxc->arbitrator || muxc->gate)
> + return mux_node;
> +
> + for_each_child_of_node(mux_node, child) {
> + ret = of_property_read_u32(child, "reg", ®);
> + if (ret)
> + continue;
> + if (chan_id == reg)
> + break;
> + }
> +
> + of_node_put(mux_node);
> + return child;
> +}
--
With Best Regards,
Andy Shevchenko