2022-11-14 13:53:49

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v6 1/1] 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: b18c1ad685d9 ("i2c: Allow an ACPI driver to manage the device's power state during probe")
Signed-off-by: Ricardo Ribalda <[email protected]>

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index b4edf10e8fd0..7539b0740351 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -467,6 +467,7 @@ static int i2c_device_probe(struct device *dev)
{
struct i2c_client *client = i2c_verify_client(dev);
struct i2c_driver *driver;
+ bool do_power_on;
int status;

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

- status = dev_pm_domain_attach(&client->dev,
- !i2c_acpi_waive_d0_probe(dev));
+ do_power_on = !i2c_acpi_waive_d0_probe(dev);
+ status = dev_pm_domain_attach(&client->dev, do_power_on);
if (status)
goto err_clear_wakeup_irq;

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

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

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

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

--
b4 0.11.0-dev-d93f8


2022-11-14 14:26:32

by Mika Westerberg

[permalink] [raw]
Subject: Re: [PATCH v6 1/1] i2c: Restore initial power state if probe fails

On Mon, Nov 14, 2022 at 01:20:34PM +0100, Ricardo Ribalda wrote:
> 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]>

Reviewed-by: Mika Westerberg <[email protected]>

2022-11-14 20:33:25

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v6 1/1] i2c: Restore initial power state if probe fails

wOn Mon, Nov 14, 2022 at 01:20:34PM +0100, Ricardo Ribalda wrote:
> 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: b18c1ad685d9 ("i2c: Allow an ACPI driver to manage the device's power state during probe")
> Signed-off-by: Ricardo Ribalda <[email protected]>

Applied to for-current, thanks!


Attachments:
(No filename) (0.99 kB)
signature.asc (849.00 B)
Download all attachments