Skip to content

Commit

Permalink
i3c: master: Improve initialization of numbered I2C adapters
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Frank Li <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexandre Belloni <[email protected]>
  • Loading branch information
Defa Li authored and alexandrebelloni committed Jan 12, 2025
1 parent b266e0d commit 5eb6d35
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/i3c/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,7 @@ static int i3c_master_i2c_adapter_init(struct i3c_master_controller *master)
struct i2c_adapter *adap = i3c_master_to_i2c_adapter(master);
struct i2c_dev_desc *i2cdev;
struct i2c_dev_boardinfo *i2cboardinfo;
int ret;
int ret, id = -ENODEV;

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

ret = i2c_add_adapter(adap);
if (master->dev.of_node)
id = of_alias_get_id(master->dev.of_node, "i2c");

if (id >= 0) {
adap->nr = id;
ret = i2c_add_numbered_adapter(adap);
} else {
ret = i2c_add_adapter(adap);
}
if (ret)
return ret;

Expand Down

0 comments on commit 5eb6d35

Please sign in to comment.