Skip to content

Commit 7dc2e0a

Browse files
jk-ozlabsalexandrebelloni
authored andcommitted
i3c: Allow OF-alias-based persistent bus numbering
Parse the /aliases node to assign any fixed bus numbers, as is done with the i2c subsystem. Numbering for non-aliased busses will start after the highest fixed bus number. This allows an alias node such as: aliases { i3c0 = &bus_a, i3c4 = &bus_b, }; to set the numbering for a set of i3c controllers: /* fixed-numbered bus, assigned "i3c-0" */ bus_a: i3c-master { }; /* another fixed-numbered bus, assigned "i3c-4" */ bus_b: i3c-master { }; /* dynamic-numbered bus, likely assigned "i3c-5" */ bus_c: i3c-master { }; If no i3c device aliases are present, the numbering will stay as-is, starting from 0. Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au> Link: https://lore.kernel.org/r/20230405094149.1513209-1-jk@codeconstruct.com.au Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 5844564 commit 7dc2e0a

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

drivers/i3c/master.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
static DEFINE_IDR(i3c_bus_idr);
2323
static DEFINE_MUTEX(i3c_core_lock);
24+
static int __i3c_first_dynamic_bus_num;
2425

2526
/**
2627
* i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
@@ -419,18 +420,29 @@ static void i3c_bus_cleanup(struct i3c_bus *i3cbus)
419420
mutex_unlock(&i3c_core_lock);
420421
}
421422

422-
static int i3c_bus_init(struct i3c_bus *i3cbus)
423+
static int i3c_bus_init(struct i3c_bus *i3cbus, struct device_node *np)
423424
{
424-
int ret;
425+
int ret, start, end, id = -1;
425426

426427
init_rwsem(&i3cbus->lock);
427428
INIT_LIST_HEAD(&i3cbus->devs.i2c);
428429
INIT_LIST_HEAD(&i3cbus->devs.i3c);
429430
i3c_bus_init_addrslots(i3cbus);
430431
i3cbus->mode = I3C_BUS_MODE_PURE;
431432

433+
if (np)
434+
id = of_alias_get_id(np, "i3c");
435+
432436
mutex_lock(&i3c_core_lock);
433-
ret = idr_alloc(&i3c_bus_idr, i3cbus, 0, 0, GFP_KERNEL);
437+
if (id >= 0) {
438+
start = id;
439+
end = start + 1;
440+
} else {
441+
start = __i3c_first_dynamic_bus_num;
442+
end = 0;
443+
}
444+
445+
ret = idr_alloc(&i3c_bus_idr, i3cbus, start, end, GFP_KERNEL);
434446
mutex_unlock(&i3c_core_lock);
435447

436448
if (ret < 0)
@@ -2606,7 +2618,7 @@ int i3c_master_register(struct i3c_master_controller *master,
26062618
INIT_LIST_HEAD(&master->boardinfo.i2c);
26072619
INIT_LIST_HEAD(&master->boardinfo.i3c);
26082620

2609-
ret = i3c_bus_init(i3cbus);
2621+
ret = i3c_bus_init(i3cbus, master->dev.of_node);
26102622
if (ret)
26112623
return ret;
26122624

@@ -2830,8 +2842,16 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
28302842

28312843
static int __init i3c_init(void)
28322844
{
2833-
int res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
2845+
int res;
2846+
2847+
res = of_alias_get_highest_id("i3c");
2848+
if (res >= 0) {
2849+
mutex_lock(&i3c_core_lock);
2850+
__i3c_first_dynamic_bus_num = res + 1;
2851+
mutex_unlock(&i3c_core_lock);
2852+
}
28342853

2854+
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
28352855
if (res)
28362856
return res;
28372857

0 commit comments

Comments
 (0)