Skip to content

Commit 5eb6d35

Browse files
Defa Lialexandrebelloni
authored andcommitted
i3c: master: Improve initialization of numbered I2C adapters
Add logic to initialize I2C adapters with a specific ID if available, improving device identification and configuration. For mixed buses, in addition to the i3c alias, an i2c alias can be added to assign a fixed bus number to the i2c adapter. This allows an alias node such as: aliases { i2c2 = &mixed_bus_a, i3c2 = &mixed_bus_a, i3c4 = &mixed_bus_b, }; /* assigned "i3c-2" and "i2c-2" */ mixed_bus_a: i3c-master { }; If there is no i2c alias for a mixed bus, the i2c adapter numbers will remain as is and will be assigned starting after the highest fixed bus number. /* assigned "i3c-4" and likely assigned "i2c-3" */ mixed_bus_b: i3c-master { }; Signed-off-by: Defa Li <defa.li@mediatek.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20241212091818.8591-1-defa.li@mediatek.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent b266e0d commit 5eb6d35

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/i3c/master.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
24862486
struct i2c_adapter *adap = i3c_master_to_i2c_adapter(master);
24872487
struct i2c_dev_desc *i2cdev;
24882488
struct i2c_dev_boardinfo *i2cboardinfo;
2489-
int ret;
2489+
int ret, id = -ENODEV;
24902490

24912491
adap->dev.parent = master->dev.parent;
24922492
adap->owner = master->dev.parent->driver->owner;
@@ -2497,7 +2497,15 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
24972497
adap->timeout = 1000;
24982498
adap->retries = 3;
24992499

2500-
ret = i2c_add_adapter(adap);
2500+
if (master->dev.of_node)
2501+
id = of_alias_get_id(master->dev.of_node, "i2c");
2502+
2503+
if (id >= 0) {
2504+
adap->nr = id;
2505+
ret = i2c_add_numbered_adapter(adap);
2506+
} else {
2507+
ret = i2c_add_adapter(adap);
2508+
}
25012509
if (ret)
25022510
return ret;
25032511

0 commit comments

Comments
 (0)