|
22 | 22 | static DEFINE_IDR(i3c_bus_idr);
|
23 | 23 | static DEFINE_MUTEX(i3c_core_lock);
|
24 | 24 | static int __i3c_first_dynamic_bus_num;
|
| 25 | +static BLOCKING_NOTIFIER_HEAD(i3c_bus_notifier); |
25 | 26 |
|
26 | 27 | /**
|
27 | 28 | * 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)
|
453 | 454 | return 0;
|
454 | 455 | }
|
455 | 456 |
|
| 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 | + |
456 | 487 | static const char * const i3c_bus_mode_strings[] = {
|
457 | 488 | [I3C_BUS_MODE_PURE] = "pure",
|
458 | 489 | [I3C_BUS_MODE_MIXED_FAST] = "mixed-fast",
|
@@ -2682,6 +2713,8 @@ int i3c_master_register(struct i3c_master_controller *master,
|
2682 | 2713 | if (ret)
|
2683 | 2714 | goto err_del_dev;
|
2684 | 2715 |
|
| 2716 | + i3c_bus_notify(i3cbus, I3C_NOTIFY_BUS_ADD); |
| 2717 | + |
2685 | 2718 | /*
|
2686 | 2719 | * We're done initializing the bus and the controller, we can now
|
2687 | 2720 | * register I3C devices discovered during the initial DAA.
|
@@ -2714,6 +2747,8 @@ EXPORT_SYMBOL_GPL(i3c_master_register);
|
2714 | 2747 | */
|
2715 | 2748 | void i3c_master_unregister(struct i3c_master_controller *master)
|
2716 | 2749 | {
|
| 2750 | + i3c_bus_notify(&master->bus, I3C_NOTIFY_BUS_REMOVE); |
| 2751 | + |
2717 | 2752 | i3c_master_i2c_adapter_cleanup(master);
|
2718 | 2753 | i3c_master_unregister_i3c_devs(master);
|
2719 | 2754 | i3c_master_bus_cleanup(master);
|
|
0 commit comments