Skip to content

Commit 60f6859

Browse files
jwrdegoedeAndi Shyti
authored andcommitted
i2c: core: Setup i2c_adapter runtime-pm before calling device_add()
Platform glue code, which is not build into the kernel and thus cannot use i2c_register_board_info() may want to use bus_register_notifier() to listen for i2c-adapters to show up on which the platform code needs to manually instantiate platform specific i2c_clients. This results in calling i2c_new_client_device() from the bus notifier which happens near the device_add() call. If the i2c-core has not yet setup runtime-pm (specifically the no-callbacks and ignore-children flags) for the device embedded inside struct i2c_adapter and the driver for the i2c_client calls pm_runtime_set_active() this will trigger the following error inside __pm_runtime_set_status(): "runtime PM trying to activate child device %s but parent (%s) is not active\n" and the i2c_client's runtime-status will not be updated. Split the device_register() call for the adapter into device_initialize() and device_add() and move the pm-runtime init calls inbetween these 2 calls so that the runtime-status can be correctly set when a driver binds from the bus-notifier. Note the moved pm-runtime init calls just override the initial value of some flags in struct device set by device_initialize() and calling these before device_add() is safe. Reviewed-by: Pali Rohár <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Acked-by: Wolfram Sang <[email protected]> Signed-off-by: Andi Shyti <[email protected]>
1 parent 15b882c commit 60f6859

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,18 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15241524
dev_set_name(&adap->dev, "i2c-%d", adap->nr);
15251525
adap->dev.bus = &i2c_bus_type;
15261526
adap->dev.type = &i2c_adapter_type;
1527-
res = device_register(&adap->dev);
1527+
device_initialize(&adap->dev);
1528+
1529+
/*
1530+
* This adapter can be used as a parent immediately after device_add(),
1531+
* setup runtime-pm (especially ignore-children) before hand.
1532+
*/
1533+
device_enable_async_suspend(&adap->dev);
1534+
pm_runtime_no_callbacks(&adap->dev);
1535+
pm_suspend_ignore_children(&adap->dev, true);
1536+
pm_runtime_enable(&adap->dev);
1537+
1538+
res = device_add(&adap->dev);
15281539
if (res) {
15291540
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
15301541
goto out_list;
@@ -1536,11 +1547,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15361547
if (res)
15371548
goto out_reg;
15381549

1539-
device_enable_async_suspend(&adap->dev);
1540-
pm_runtime_no_callbacks(&adap->dev);
1541-
pm_suspend_ignore_children(&adap->dev, true);
1542-
pm_runtime_enable(&adap->dev);
1543-
15441550
res = i2c_init_recovery(adap);
15451551
if (res == -EPROBE_DEFER)
15461552
goto out_reg;

0 commit comments

Comments
 (0)