Skip to content

Commit 0ac6486

Browse files
jk-ozlabsPaolo Abeni
authored andcommitted
i3c: Add support for bus enumeration & notification
This allows other drivers to be notified when new i3c busses are attached, referring to a whole i3c bus as opposed to individual devices. Signed-off-by: Jeremy Kerr <[email protected]> Signed-off-by: Matt Johnston <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent ee71d6d commit 0ac6486

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/i3c/master.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
static DEFINE_IDR(i3c_bus_idr);
2323
static DEFINE_MUTEX(i3c_core_lock);
2424
static int __i3c_first_dynamic_bus_num;
25+
static BLOCKING_NOTIFIER_HEAD(i3c_bus_notifier);
2526

2627
/**
2728
* i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
@@ -453,6 +454,36 @@ static int i3c_bus_init(struct i3c_bus *i3cbus, struct device_node *np)
453454
return 0;
454455
}
455456

457+
void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
458+
void *data)
459+
{
460+
struct i3c_bus *bus;
461+
int id;
462+
463+
mutex_lock(&i3c_core_lock);
464+
idr_for_each_entry(&i3c_bus_idr, bus, id)
465+
fn(bus, data);
466+
mutex_unlock(&i3c_core_lock);
467+
}
468+
EXPORT_SYMBOL_GPL(i3c_for_each_bus_locked);
469+
470+
int i3c_register_notifier(struct notifier_block *nb)
471+
{
472+
return blocking_notifier_chain_register(&i3c_bus_notifier, nb);
473+
}
474+
EXPORT_SYMBOL_GPL(i3c_register_notifier);
475+
476+
int i3c_unregister_notifier(struct notifier_block *nb)
477+
{
478+
return blocking_notifier_chain_unregister(&i3c_bus_notifier, nb);
479+
}
480+
EXPORT_SYMBOL_GPL(i3c_unregister_notifier);
481+
482+
static void i3c_bus_notify(struct i3c_bus *bus, unsigned int action)
483+
{
484+
blocking_notifier_call_chain(&i3c_bus_notifier, action, bus);
485+
}
486+
456487
static const char * const i3c_bus_mode_strings[] = {
457488
[I3C_BUS_MODE_PURE] = "pure",
458489
[I3C_BUS_MODE_MIXED_FAST] = "mixed-fast",
@@ -2682,6 +2713,8 @@ int i3c_master_register(struct i3c_master_controller *master,
26822713
if (ret)
26832714
goto err_del_dev;
26842715

2716+
i3c_bus_notify(i3cbus, I3C_NOTIFY_BUS_ADD);
2717+
26852718
/*
26862719
* We're done initializing the bus and the controller, we can now
26872720
* register I3C devices discovered during the initial DAA.
@@ -2714,6 +2747,8 @@ EXPORT_SYMBOL_GPL(i3c_master_register);
27142747
*/
27152748
void i3c_master_unregister(struct i3c_master_controller *master)
27162749
{
2750+
i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE);
2751+
27172752
i3c_master_i2c_adapter_cleanup(master);
27182753
i3c_master_unregister_i3c_devs(master);
27192754
i3c_master_bus_cleanup(master);

include/linux/i3c/master.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
struct i2c_client;
2626

27+
/* notifier actions. notifier call data is the struct i3c_bus */
28+
enum {
29+
I3C_NOTIFY_BUS_ADD,
30+
I3C_NOTIFY_BUS_REMOVE,
31+
};
32+
2733
struct i3c_master_controller;
2834
struct i3c_bus;
2935
struct i3c_device;
@@ -652,4 +658,9 @@ void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
652658

653659
struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
654660

661+
void i3c_for_each_bus_locked(int (*fn)(struct i3c_bus *bus, void *data),
662+
void *data);
663+
int i3c_register_notifier(struct notifier_block *nb);
664+
int i3c_unregister_notifier(struct notifier_block *nb);
665+
655666
#endif /* I3C_MASTER_H */

0 commit comments

Comments
 (0)