Skip to content

Commit 79ece9b

Browse files
ribaldawsakernel
authored andcommitted
i2c: Restore initial power state if probe fails
A driver that supports I2C_DRV_ACPI_WAIVE_D0_PROBE is not expected to power off a device that it has not powered on previously. For devices operating in "full_power" mode, the first call to `i2c_acpi_waive_d0_probe` will return 0, which means that the device will be turned on with `dev_pm_domain_attach`. If probe fails the second call to `i2c_acpi_waive_d0_probe` will return 1, which means that the device will not be turned off. This is, it will be left in a different power state. Lets fix it. Reviewed-by: Hidenori Kobayashi <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Sakari Ailus <[email protected]> Cc: [email protected] Fixes: b18c1ad ("i2c: Allow an ACPI driver to manage the device's power state during probe") Signed-off-by: Ricardo Ribalda <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 145900c commit 79ece9b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ static int i2c_device_probe(struct device *dev)
467467
{
468468
struct i2c_client *client = i2c_verify_client(dev);
469469
struct i2c_driver *driver;
470+
bool do_power_on;
470471
int status;
471472

472473
if (!client)
@@ -545,8 +546,8 @@ static int i2c_device_probe(struct device *dev)
545546
if (status < 0)
546547
goto err_clear_wakeup_irq;
547548

548-
status = dev_pm_domain_attach(&client->dev,
549-
!i2c_acpi_waive_d0_probe(dev));
549+
do_power_on = !i2c_acpi_waive_d0_probe(dev);
550+
status = dev_pm_domain_attach(&client->dev, do_power_on);
550551
if (status)
551552
goto err_clear_wakeup_irq;
552553

@@ -585,7 +586,7 @@ static int i2c_device_probe(struct device *dev)
585586
err_release_driver_resources:
586587
devres_release_group(&client->dev, client->devres_group_id);
587588
err_detach_pm_domain:
588-
dev_pm_domain_detach(&client->dev, !i2c_acpi_waive_d0_probe(dev));
589+
dev_pm_domain_detach(&client->dev, do_power_on);
589590
err_clear_wakeup_irq:
590591
dev_pm_clear_wake_irq(&client->dev);
591592
device_init_wakeup(&client->dev, false);
@@ -610,7 +611,7 @@ static void i2c_device_remove(struct device *dev)
610611

611612
devres_release_group(&client->dev, client->devres_group_id);
612613

613-
dev_pm_domain_detach(&client->dev, !i2c_acpi_waive_d0_probe(dev));
614+
dev_pm_domain_detach(&client->dev, true);
614615

615616
dev_pm_clear_wake_irq(&client->dev);
616617
device_init_wakeup(&client->dev, false);

0 commit comments

Comments
 (0)