Skip to content

Commit d42c7c6

Browse files
claudiubeznearafaeljw
authored andcommitted
PM: domains: Add flags to specify power on attach/detach
Calling dev_pm_domain_attach()/dev_pm_domain_detach() in bus driver probe/remove functions can affect system behavior when the drivers attached to the bus use devres-managed resources. Since devres actions may need to access device registers, calling dev_pm_domain_detach() too early, i.e., before these actions complete, can cause failures on some systems. One such example is Renesas RZ/G3S SoC-based platforms. If the device clocks are managed via PM domains, invoking dev_pm_domain_detach() in the bus driver's remove function removes the device's clocks from the PM domain, preventing any subsequent pm_runtime_resume*() calls from enabling those clocks. The second argument of dev_pm_domain_attach() specifies whether the PM domain should be powered on during attachment. Likewise, the second argument of dev_pm_domain_detach() indicates whether the domain should be powered off during detachment. Upcoming changes address the issue described above (initially for the platform bus only) by deferring the call to dev_pm_domain_detach() until after devres_release_all() in device_unbind_cleanup(). The detach_power_off field in struct dev_pm_info stores the detach power off info from the second argument of dev_pm_domain_attach(). Because there are cases where the device's PM domain power-on/off behavior must be conditional (e.g., in i2c_device_probe()), the patch introduces PD_FLAG_ATTACH_POWER_ON and PD_FLAG_DETACH_POWER_OFF flags to be passed to dev_pm_domain_attach(). Finally, dev_pm_domain_attach() and its users are updated to use the newly introduced PD_FLAG_ATTACH_POWER_ON and PD_FLAG_DETACH_POWER_OFF macros. This change is preparatory. Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com> # I2C Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://patch.msgid.link/20250703112708.1621607-2-claudiu.beznea.uj@bp.renesas.com [ rjw: Changelog adjustments ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 9047685 commit d42c7c6

13 files changed

Lines changed: 23 additions & 17 deletions

File tree

drivers/amba/bus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int amba_read_periphid(struct amba_device *dev)
138138
void __iomem *tmp;
139139
int i, ret;
140140

141-
ret = dev_pm_domain_attach(&dev->dev, true);
141+
ret = dev_pm_domain_attach(&dev->dev, PD_FLAG_ATTACH_POWER_ON);
142142
if (ret) {
143143
dev_dbg(&dev->dev, "can't get PM domain: %d\n", ret);
144144
goto err_out;
@@ -291,7 +291,7 @@ static int amba_probe(struct device *dev)
291291
if (ret < 0)
292292
break;
293293

294-
ret = dev_pm_domain_attach(dev, true);
294+
ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
295295
if (ret)
296296
break;
297297

drivers/base/auxiliary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static int auxiliary_bus_probe(struct device *dev)
217217
struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
218218
int ret;
219219

220-
ret = dev_pm_domain_attach(dev, true);
220+
ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
221221
if (ret) {
222222
dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
223223
return ret;

drivers/base/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ static int platform_probe(struct device *_dev)
13961396
if (ret < 0)
13971397
return ret;
13981398

1399-
ret = dev_pm_domain_attach(_dev, true);
1399+
ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON);
14001400
if (ret)
14011401
goto out;
14021402

drivers/base/power/common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
8383
/**
8484
* dev_pm_domain_attach - Attach a device to its PM domain.
8585
* @dev: Device to attach.
86-
* @power_on: Used to indicate whether we should power on the device.
86+
* @flags: indicate whether we should power on/off the device on attach/detach
8787
*
8888
* The @dev may only be attached to a single PM domain. By iterating through
8989
* the available alternatives we try to find a valid PM domain for the device.
@@ -100,14 +100,14 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
100100
* Returns 0 on successfully attached PM domain, or when it is found that the
101101
* device doesn't need a PM domain, else a negative error code.
102102
*/
103-
int dev_pm_domain_attach(struct device *dev, bool power_on)
103+
int dev_pm_domain_attach(struct device *dev, u32 flags)
104104
{
105105
int ret;
106106

107107
if (dev->pm_domain)
108108
return 0;
109109

110-
ret = acpi_dev_pm_attach(dev, power_on);
110+
ret = acpi_dev_pm_attach(dev, !!(flags & PD_FLAG_ATTACH_POWER_ON));
111111
if (!ret)
112112
ret = genpd_dev_pm_attach(dev);
113113

drivers/clk/qcom/apcs-sdx55.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int qcom_apcs_sdx55_clk_probe(struct platform_device *pdev)
111111
* driver, there seems to be no better place to do this. So do it here!
112112
*/
113113
cpu_dev = get_cpu_device(0);
114-
ret = dev_pm_domain_attach(cpu_dev, true);
114+
ret = dev_pm_domain_attach(cpu_dev, PD_FLAG_ATTACH_POWER_ON);
115115
if (ret) {
116116
dev_err_probe(dev, ret, "can't get PM domain: %d\n", ret);
117117
goto err;

drivers/gpu/drm/display/drm_dp_aux_bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static int dp_aux_ep_probe(struct device *dev)
5757
container_of(aux_ep, struct dp_aux_ep_device_with_data, aux_ep);
5858
int ret;
5959

60-
ret = dev_pm_domain_attach(dev, true);
60+
ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
6161
if (ret)
6262
return dev_err_probe(dev, ret, "Failed to attach to PM Domain\n");
6363

drivers/i2c/i2c-core-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int i2c_device_probe(struct device *dev)
573573
goto err_clear_wakeup_irq;
574574

575575
do_power_on = !i2c_acpi_waive_d0_probe(dev);
576-
status = dev_pm_domain_attach(&client->dev, do_power_on);
576+
status = dev_pm_domain_attach(&client->dev, do_power_on ? PD_FLAG_ATTACH_POWER_ON : 0);
577577
if (status)
578578
goto err_clear_wakeup_irq;
579579

drivers/mmc/core/sdio_bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static int sdio_bus_probe(struct device *dev)
161161
if (!id)
162162
return -ENODEV;
163163

164-
ret = dev_pm_domain_attach(dev, false);
164+
ret = dev_pm_domain_attach(dev, 0);
165165
if (ret)
166166
return ret;
167167

drivers/rpmsg/rpmsg_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int rpmsg_dev_probe(struct device *dev)
479479
struct rpmsg_endpoint *ept = NULL;
480480
int err;
481481

482-
err = dev_pm_domain_attach(dev, true);
482+
err = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
483483
if (err)
484484
goto out;
485485

drivers/soundwire/bus_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int sdw_drv_probe(struct device *dev)
101101
/*
102102
* attach to power domain but don't turn on (last arg)
103103
*/
104-
ret = dev_pm_domain_attach(dev, false);
104+
ret = dev_pm_domain_attach(dev, 0);
105105
if (ret)
106106
return ret;
107107

0 commit comments

Comments
 (0)