For the correct assignment of the I2C bus number, let's use an alias from the devicetree. Signed-off-by: Alexander Shiyan <eagle.alexander923@xxxxxxxxx> --- drivers/i2c/i2c.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 300365bd1f..df3b968a4b 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -701,17 +701,21 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter) int ret; if (adapter->nr < 0) { - int nr; + if (!adapter->dev.of_node) { + int nr = adapter->dev.id; - for (nr = 0;; nr++) - if (!i2c_get_adapter(nr)) - break; - adapter->nr = nr; - } else { - if (i2c_get_adapter(adapter->nr)) - return -EBUSY; + for (nr = 0;; nr++) + if (!i2c_get_adapter(nr)) + break; + adapter->nr = nr; + } else + adapter->nr = + of_alias_get_id(adapter->dev.of_node, "i2c"); } + if (i2c_get_adapter(adapter->nr)) + return -EBUSY; + adapter->dev.id = adapter->nr; dev_set_name(&adapter->dev, "i2c"); -- 2.38.2