[PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes
Ahmad Fatoum
a.fatoum at pengutronix.de
Sun Dec 15 01:54:11 PST 2024
When probed from device tree, "real" I2C controllers are virtual
devices that have the OF device as parent.
For those the current logic of using the alias of the parent
device's of_node works.
I2C muxes are different, because their parent device is the virtual
device of their controller. Using that controller's alias is often
destined to result in an -EBUSY:
pca9450-i2c pca9450b0: PMIC Chip ID: 0x3
ERROR: i2c1: failed to add mux-adapter (error=-16)
ERROR: pca954x pca95450: failed to register multiplexed adapter0
As a single I2C mux can have multiple channels, there may also be just
one OF device for multiple virtual adapters. As all I2C adapters being
registered in barebox also have the of_node of the virtual device
populated, let's just consult that.
Fixes: b4746725454c ("i2c: get adapter.nr from device tree")
Reported-by: Alexander Shiyan <eagle.alexander923 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
drivers/i2c/i2c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index d19506af2627..017842f026dd 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -705,8 +705,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
struct device *hw_dev;
int ret;
- if (adapter->nr < 0 && adapter->dev.parent && adapter->dev.parent->of_node)
- adapter->nr = of_alias_get_id(adapter->dev.parent->of_node, "i2c");
+ if (adapter->nr < 0 && dev_of_node(&adapter->dev))
+ adapter->nr = of_alias_get_id(adapter->dev.of_node, "i2c");
if (adapter->nr < 0) {
int nr;
--
2.39.5
More information about the barebox
mailing list