[PATCH 2/2] i2c: mux: reg: allow fixing the base bus number via fwnode
From: Abdurrahman Hussain
Date: Sun Jun 07 2026 - 04:22:55 EST
i2c_mux_reg supports per-channel force_nr through mux->data.base_nr
(when set, the channel-N adapter is registered as
i2c_add_numbered_adapter(base_nr + N)), but the only way to populate
base_nr was the legacy i2c_mux_reg_platform_data path. DT/ACPI/swnode
instances have always defaulted to dynamic allocation, which makes
sensors.conf bus stanzas and other static references break across
boots whenever the i2c-core pool shifts.
Read base_nr from the new "base-bus-num" device property in
i2c_mux_reg_probe_fw(). When the property is absent, base_nr stays
zero and the existing dynamic-allocation behaviour is preserved.
Anchor the per-channel bus number to the channel index (values[i]
== the child node's reg) rather than the iteration counter:
nr = base_nr ? base_nr + values[i] : 0
values[i] is the channel id encoded in the child node's reg property
(0..n-1), which is also what i2c_mux_add_adapter() receives as
chan_id. Using values[i] makes the mapping deterministic across
fwnode-iteration orderings (some OF kernels walk children in reverse
source order) and across DTS gaps (e.g. a mux that wires channels
0, 1, 3 still gets sane, consecutive bus numbers).
Signed-off-by: Abdurrahman Hussain <abdurrahman@xxxxxxxxxx>
---
drivers/i2c/muxes/i2c-mux-reg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index 13da757100fe..5ea59ecb4ae5 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -141,6 +141,8 @@ static int i2c_mux_reg_probe_fw(struct regmux *mux, struct device *dev)
if (!device_property_read_u32(dev, "idle-state", &mux->data.idle))
mux->data.idle_in_use = true;
+ device_property_read_u32(dev, "base-bus-num", &mux->data.base_nr);
+
return 0;
}
@@ -197,7 +199,7 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
muxc->deselect = i2c_mux_reg_deselect;
for (i = 0; i < mux->data.n_values; i++) {
- nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0;
+ nr = mux->data.base_nr ? (mux->data.base_nr + mux->data.values[i]) : 0;
ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i]);
if (ret)
--
2.54.0