[PATCH 2/3] i2c: get adapter.nr from device tree

Sascha Hauer s.hauer at pengutronix.de
Fri Oct 25 00:30:25 PDT 2024


In case we are instantiating a I2C bus driver from device tree let's
try to get the bus number from the device tree instead of dynamically
assigning a free bus number.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/i2c/i2c.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 5471519045..4eed7fb5c6 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -705,6 +705,9 @@ 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) {
 		int nr;
 

-- 
2.39.5




More information about the barebox mailing list