]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: domains: Add flags to specify power on attach/detach
authorClaudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Thu, 3 Jul 2025 11:27:06 +0000 (14:27 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 7 Jul 2025 18:41:20 +0000 (20:41 +0200)
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>
13 files changed:
drivers/amba/bus.c
drivers/base/auxiliary.c
drivers/base/platform.c
drivers/base/power/common.c
drivers/clk/qcom/apcs-sdx55.c
drivers/gpu/drm/display/drm_dp_aux_bus.c
drivers/i2c/i2c-core-base.c
drivers/mmc/core/sdio_bus.c
drivers/rpmsg/rpmsg_core.c
drivers/soundwire/bus_type.c
drivers/spi/spi.c
drivers/tty/serdev/core.c
include/linux/pm_domain.h

index 71482d639a6dae1d62b31c8a210b83d88c24e305..74e34a07ef72fb4c9f327f72d8ef251f0c44cad6 100644 (file)
@@ -138,7 +138,7 @@ static int amba_read_periphid(struct amba_device *dev)
        void __iomem *tmp;
        int i, ret;
 
-       ret = dev_pm_domain_attach(&dev->dev, true);
+       ret = dev_pm_domain_attach(&dev->dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret) {
                dev_dbg(&dev->dev, "can't get PM domain: %d\n", ret);
                goto err_out;
@@ -291,7 +291,7 @@ static int amba_probe(struct device *dev)
                if (ret < 0)
                        break;
 
-               ret = dev_pm_domain_attach(dev, true);
+               ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
                if (ret)
                        break;
 
index dba7c8e13a531fdf4070e476fbc9671a8bb886eb..44cd3f85b659db47a2d591bfacde423312e7f0fd 100644 (file)
@@ -217,7 +217,7 @@ static int auxiliary_bus_probe(struct device *dev)
        struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
        int ret;
 
-       ret = dev_pm_domain_attach(dev, true);
+       ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret) {
                dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret);
                return ret;
index 075ec1d1b73a1c18a2d489f83108886a66e41639..df1ec34fdf567ccb66a162415a565b889be1c375 100644 (file)
@@ -1396,7 +1396,7 @@ static int platform_probe(struct device *_dev)
        if (ret < 0)
                return ret;
 
-       ret = dev_pm_domain_attach(_dev, true);
+       ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret)
                goto out;
 
index 781968a128ff75c1051da83fbc631406ad481289..fecb85fa85ac814c588a816ab4c4ea0a1e7456df 100644 (file)
@@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
 /**
  * dev_pm_domain_attach - Attach a device to its PM domain.
  * @dev: Device to attach.
- * @power_on: Used to indicate whether we should power on the device.
+ * @flags: indicate whether we should power on/off the device on attach/detach
  *
  * The @dev may only be attached to a single PM domain. By iterating through
  * 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);
  * Returns 0 on successfully attached PM domain, or when it is found that the
  * device doesn't need a PM domain, else a negative error code.
  */
-int dev_pm_domain_attach(struct device *dev, bool power_on)
+int dev_pm_domain_attach(struct device *dev, u32 flags)
 {
        int ret;
 
        if (dev->pm_domain)
                return 0;
 
-       ret = acpi_dev_pm_attach(dev, power_on);
+       ret = acpi_dev_pm_attach(dev, !!(flags & PD_FLAG_ATTACH_POWER_ON));
        if (!ret)
                ret = genpd_dev_pm_attach(dev);
 
index 3ba01622d8f0ef99dc5f63c0e83085cd53f38621..90dd1f1855c21f2164381b68ba491ecacfe1c9d6 100644 (file)
@@ -111,7 +111,7 @@ static int qcom_apcs_sdx55_clk_probe(struct platform_device *pdev)
         * driver, there seems to be no better place to do this. So do it here!
         */
        cpu_dev = get_cpu_device(0);
-       ret = dev_pm_domain_attach(cpu_dev, true);
+       ret = dev_pm_domain_attach(cpu_dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret) {
                dev_err_probe(dev, ret, "can't get PM domain: %d\n", ret);
                goto err;
index ec7eac6b595f7eeee0151c524a3998321c7e3ab9..718c9122bc3a6b299c2460b5f65ba9b156fda365 100644 (file)
@@ -57,7 +57,7 @@ static int dp_aux_ep_probe(struct device *dev)
                container_of(aux_ep, struct dp_aux_ep_device_with_data, aux_ep);
        int ret;
 
-       ret = dev_pm_domain_attach(dev, true);
+       ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret)
                return dev_err_probe(dev, ret, "Failed to attach to PM Domain\n");
 
index 2ad2b1838f0f41c83362743c72a3c491f630f294..38eabf1173da8edf76bf2a2a047415375bbc86f5 100644 (file)
@@ -573,7 +573,7 @@ static int i2c_device_probe(struct device *dev)
                goto err_clear_wakeup_irq;
 
        do_power_on = !i2c_acpi_waive_d0_probe(dev);
-       status = dev_pm_domain_attach(&client->dev, do_power_on);
+       status = dev_pm_domain_attach(&client->dev, do_power_on ? PD_FLAG_ATTACH_POWER_ON : 0);
        if (status)
                goto err_clear_wakeup_irq;
 
index b66b637e2d574a6c85fce2f1083e3a9d035be6d7..656601754966b2a612bd22b9d66973edfb8f969f 100644 (file)
@@ -161,7 +161,7 @@ static int sdio_bus_probe(struct device *dev)
        if (!id)
                return -ENODEV;
 
-       ret = dev_pm_domain_attach(dev, false);
+       ret = dev_pm_domain_attach(dev, 0);
        if (ret)
                return ret;
 
index 6ee36adcbdba4d9b25534ffe0b97a09af46f1ede..bece5e635ee9f6ce3815adf689b353690be004a9 100644 (file)
@@ -479,7 +479,7 @@ static int rpmsg_dev_probe(struct device *dev)
        struct rpmsg_endpoint *ept = NULL;
        int err;
 
-       err = dev_pm_domain_attach(dev, true);
+       err = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
        if (err)
                goto out;
 
index 75d6f16efcedb45d36b6c95c05d0fd3a7715264c..bc1e653080d9091cdd12199d1fc5c8e4f76d1c75 100644 (file)
@@ -101,7 +101,7 @@ static int sdw_drv_probe(struct device *dev)
        /*
         * attach to power domain but don't turn on (last arg)
         */
-       ret = dev_pm_domain_attach(dev, false);
+       ret = dev_pm_domain_attach(dev, 0);
        if (ret)
                return ret;
 
index 1bc0fdbb1bd749a988d8c2b15c57daaa44aec8d9..8200b47b2295c1497328da45e4572e6d43698540 100644 (file)
@@ -427,7 +427,7 @@ static int spi_probe(struct device *dev)
        if (spi->irq < 0)
                spi->irq = 0;
 
-       ret = dev_pm_domain_attach(dev, true);
+       ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret)
                return ret;
 
index 0213381fa35876f43f2f10f6c444160cde73a686..d16c207a1a9b2b4af5fde7a26f4f7b78dd84e22b 100644 (file)
@@ -399,7 +399,7 @@ static int serdev_drv_probe(struct device *dev)
        const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
        int ret;
 
-       ret = dev_pm_domain_attach(dev, true);
+       ret = dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON);
        if (ret)
                return ret;
 
index 0b18160901a2c9ea4281118f00d17ae803327316..62a35a78ce9bd06158ad637d6858512384c2a2c3 100644 (file)
  *                             isn't specified, the index just follows the
  *                             index for the attached PM domain.
  *
+ * PD_FLAG_ATTACH_POWER_ON:    Power on the domain during attach.
+ *
+ * PD_FLAG_DETACH_POWER_OFF:   Power off the domain during detach.
+ *
  */
 #define PD_FLAG_NO_DEV_LINK            BIT(0)
 #define PD_FLAG_DEV_LINK_ON            BIT(1)
 #define PD_FLAG_REQUIRED_OPP           BIT(2)
+#define PD_FLAG_ATTACH_POWER_ON                BIT(3)
+#define PD_FLAG_DETACH_POWER_OFF       BIT(4)
 
 struct dev_pm_domain_attach_data {
        const char * const *pd_names;
@@ -501,7 +507,7 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
 
 #ifdef CONFIG_PM
-int dev_pm_domain_attach(struct device *dev, bool power_on);
+int dev_pm_domain_attach(struct device *dev, u32 flags);
 struct device *dev_pm_domain_attach_by_id(struct device *dev,
                                          unsigned int index);
 struct device *dev_pm_domain_attach_by_name(struct device *dev,
@@ -518,7 +524,7 @@ int dev_pm_domain_start(struct device *dev);
 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
 int dev_pm_domain_set_performance_state(struct device *dev, unsigned int state);
 #else
-static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
+static inline int dev_pm_domain_attach(struct device *dev, u32 flags)
 {
        return 0;
 }