linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
@ 2025-07-03 11:27 Claudiu
  2025-07-03 11:27 ` [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Claudiu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Claudiu @ 2025-07-03 11:27 UTC (permalink / raw)
  To: linux, gregkh, david.m.ertman, ira.weiny, leon, rafael, dakr,
	len.brown, pavel, andersson, mturquette, sboyd, maarten.lankhorst,
	mripard, tzimmermann, airlied, simona, wsa+renesas, ulf.hansson,
	mathieu.poirier, vkoul, yung-chuan.liao, pierre-louis.bossart,
	broonie, robh, jirislaby, saravanak, jic23, dmitry.torokhov
  Cc: claudiu.beznea, linux-kernel, linux-pm, linux-arm-msm, linux-clk,
	linux-i2c, linux-mmc, linux-remoteproc, linux-sound, linux-spi,
	linux-serial, bhelgaas, geert, linux-iio, linux-renesas-soc,
	fabrizio.castro.jz, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

Hi,

Series drops the dev_pm_domain_detach() from platform bus remove and
adds it in device_unbind_cleanup() to avoid runtime resumming the device
after it was detached from its PM domain.

Please provide your feedback.

Thank you,
Claudiu

Changes in v5:
- added PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF;
  due to this a new patch was introduced
  "PM: domains: Add flags to specify power on attach/detach"

Changes in v4:
- added a flag in dev_pm_info that is saved in dev_pm_domain_attach()
  and used in device_unbind_cleanup()

Changes in v3:
- add devm_pm_domain_attach()

Changes in v2:
- dropped the devres group open/close approach and use
  devm_pm_domain_attach()
- adjusted patch description to reflect the new approach


Claudiu Beznea (3):
  PM: domains: Add flags to specify power on attach/detach
  PM: domains: Detach on device_unbind_cleanup()
  driver core: platform: Drop dev_pm_domain_detach() call

 drivers/amba/bus.c                       |  4 ++--
 drivers/base/auxiliary.c                 |  2 +-
 drivers/base/dd.c                        |  2 ++
 drivers/base/platform.c                  |  9 +++------
 drivers/base/power/common.c              |  9 ++++++---
 drivers/clk/qcom/apcs-sdx55.c            |  2 +-
 drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
 drivers/i2c/i2c-core-base.c              |  2 +-
 drivers/mmc/core/sdio_bus.c              |  2 +-
 drivers/rpmsg/rpmsg_core.c               |  2 +-
 drivers/soundwire/bus_type.c             |  2 +-
 drivers/spi/spi.c                        |  2 +-
 drivers/tty/serdev/core.c                |  2 +-
 include/linux/pm.h                       |  1 +
 include/linux/pm_domain.h                | 10 ++++++++--
 15 files changed, 31 insertions(+), 22 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach
  2025-07-03 11:27 [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
@ 2025-07-03 11:27 ` Claudiu
  2025-07-04 15:37   ` Mathieu Poirier
  2025-07-03 11:27 ` [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Claudiu @ 2025-07-03 11:27 UTC (permalink / raw)
  To: linux, gregkh, david.m.ertman, ira.weiny, leon, rafael, dakr,
	len.brown, pavel, andersson, mturquette, sboyd, maarten.lankhorst,
	mripard, tzimmermann, airlied, simona, wsa+renesas, ulf.hansson,
	mathieu.poirier, vkoul, yung-chuan.liao, pierre-louis.bossart,
	broonie, robh, jirislaby, saravanak, jic23, dmitry.torokhov
  Cc: claudiu.beznea, linux-kernel, linux-pm, linux-arm-msm, linux-clk,
	linux-i2c, linux-mmc, linux-remoteproc, linux-sound, linux-spi,
	linux-serial, bhelgaas, geert, linux-iio, linux-renesas-soc,
	fabrizio.castro.jz, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

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 commits 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 is a preparatory commit.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v5:
- none; this patch is new

 drivers/amba/bus.c                       |  4 ++--
 drivers/base/auxiliary.c                 |  2 +-
 drivers/base/platform.c                  |  2 +-
 drivers/base/power/common.c              |  6 +++---
 drivers/clk/qcom/apcs-sdx55.c            |  2 +-
 drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
 drivers/i2c/i2c-core-base.c              |  2 +-
 drivers/mmc/core/sdio_bus.c              |  2 +-
 drivers/rpmsg/rpmsg_core.c               |  2 +-
 drivers/soundwire/bus_type.c             |  2 +-
 drivers/spi/spi.c                        |  2 +-
 drivers/tty/serdev/core.c                |  2 +-
 include/linux/pm_domain.h                | 10 ++++++++--
 13 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 71482d639a6d..74e34a07ef72 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -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;
 
diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
index dba7c8e13a53..44cd3f85b659 100644
--- a/drivers/base/auxiliary.c
+++ b/drivers/base/auxiliary.c
@@ -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;
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 075ec1d1b73a..df1ec34fdf56 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -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;
 
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 781968a128ff..fecb85fa85ac 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -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);
 
diff --git a/drivers/clk/qcom/apcs-sdx55.c b/drivers/clk/qcom/apcs-sdx55.c
index 3ba01622d8f0..90dd1f1855c2 100644
--- a/drivers/clk/qcom/apcs-sdx55.c
+++ b/drivers/clk/qcom/apcs-sdx55.c
@@ -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;
diff --git a/drivers/gpu/drm/display/drm_dp_aux_bus.c b/drivers/gpu/drm/display/drm_dp_aux_bus.c
index 7b9afcf48836..2d279e82922f 100644
--- a/drivers/gpu/drm/display/drm_dp_aux_bus.c
+++ b/drivers/gpu/drm/display/drm_dp_aux_bus.c
@@ -58,7 +58,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");
 
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 2ad2b1838f0f..38eabf1173da 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -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;
 
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index b66b637e2d57..656601754966 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -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;
 
diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 6ee36adcbdba..bece5e635ee9 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -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;
 
diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
index 75d6f16efced..bc1e653080d9 100644
--- a/drivers/soundwire/bus_type.c
+++ b/drivers/soundwire/bus_type.c
@@ -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;
 
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bc0fdbb1bd7..8200b47b2295 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -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;
 
diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index 0213381fa358..d16c207a1a9b 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -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;
 
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 0b18160901a2..62a35a78ce9b 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -36,10 +36,16 @@
  *				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;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-03 11:27 [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
  2025-07-03 11:27 ` [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Claudiu
@ 2025-07-03 11:27 ` Claudiu
  2025-07-03 11:27 ` [PATCH v5 3/3] driver core: platform: Drop dev_pm_domain_detach() call Claudiu
  2025-07-04 11:15 ` [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Ulf Hansson
  3 siblings, 0 replies; 10+ messages in thread
From: Claudiu @ 2025-07-03 11:27 UTC (permalink / raw)
  To: linux, gregkh, david.m.ertman, ira.weiny, leon, rafael, dakr,
	len.brown, pavel, andersson, mturquette, sboyd, maarten.lankhorst,
	mripard, tzimmermann, airlied, simona, wsa+renesas, ulf.hansson,
	mathieu.poirier, vkoul, yung-chuan.liao, pierre-louis.bossart,
	broonie, robh, jirislaby, saravanak, jic23, dmitry.torokhov
  Cc: claudiu.beznea, linux-kernel, linux-pm, linux-arm-msm, linux-clk,
	linux-i2c, linux-mmc, linux-remoteproc, linux-sound, linux-spi,
	linux-serial, bhelgaas, geert, linux-iio, linux-renesas-soc,
	fabrizio.castro.jz, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

The dev_pm_domain_attach() function is typically used in bus code alongside
dev_pm_domain_detach(), often following patterns like:

static int bus_probe(struct device *_dev)
{
    struct bus_driver *drv = to_bus_driver(dev->driver);
    struct bus_device *dev = to_bus_device(_dev);
    int ret;

    // ...

    ret = dev_pm_domain_attach(_dev, true);
    if (ret)
        return ret;

    if (drv->probe)
        ret = drv->probe(dev);

    // ...
}

static void bus_remove(struct device *_dev)
{
    struct bus_driver *drv = to_bus_driver(dev->driver);
    struct bus_device *dev = to_bus_device(_dev);

    if (drv->remove)
        drv->remove(dev);
    dev_pm_domain_detach(_dev);
}

When the driver's probe function uses devres-managed resources that depend
on the power domain state, those resources are released later during
device_unbind_cleanup().

Releasing devres-managed resources that depend on the power domain state
after detaching the device from its PM domain can cause failures.

For example, if the driver uses devm_pm_runtime_enable() in its probe
function, and the device's clocks are managed by the PM domain, then
during removal the runtime PM is disabled in device_unbind_cleanup() after
the clocks have been removed from the PM domain. It may happen that the
devm_pm_runtime_enable() action causes the device to be runtime-resumed.
If the driver specific runtime PM APIs access registers directly, this
will lead to accessing device registers without clocks being enabled.
Similar issues may occur with other devres actions that access device
registers.

Add detach_power_off member to struct dev_pm_info, to be used later in
device_unbind_cleanup() as the power_off argument for
dev_pm_domain_detach(). This is a preparatory step toward removing
dev_pm_domain_detach() calls from bus remove functions. Since the current
PM domain detach functions (genpd_dev_pm_detach() and acpi_dev_pm_detach())
already set dev->pm_domain = NULL, there should be no issues with bus
drivers that still call dev_pm_domain_detach() in their remove functions.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v5:
- added flags argument to dev_pm_domain_attach_attach()
- added description for struct dev_pm_info::detach_power_off;
  @Rafael: I kept the detach_power_off flag outside of CONFIG_PM as it
  is used unconditionally in device_unbind_cleanup()

Changes in v4:
- save dev->power.detach_power_off in dev_pm_domain_attach() and use
  it in device_unbind_cleanup() when detaching
- adjusted patch description

Changes in v3:
- dropped devm_pm_domain_detach_off(), devm_pm_domain_detach_on()
  and use a single function devm_pm_domain_detach()

Changes in v2:
- none; this patch is new

 drivers/base/dd.c           | 2 ++
 drivers/base/power/common.c | 3 +++
 include/linux/pm.h          | 1 +
 3 files changed, 6 insertions(+)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index b526e0e0f52d..13ab98e033ea 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -25,6 +25,7 @@
 #include <linux/kthread.h>
 #include <linux/wait.h>
 #include <linux/async.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/pinctrl/devinfo.h>
 #include <linux/slab.h>
@@ -552,6 +553,7 @@ static void device_unbind_cleanup(struct device *dev)
 	dev->dma_range_map = NULL;
 	device_set_driver(dev, NULL);
 	dev_set_drvdata(dev, NULL);
+	dev_pm_domain_detach(dev, dev->power.detach_power_off);
 	if (dev->pm_domain && dev->pm_domain->dismiss)
 		dev->pm_domain->dismiss(dev);
 	pm_runtime_reinit(dev);
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index fecb85fa85ac..6ecf9ce4a4e6 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -111,6 +111,9 @@ int dev_pm_domain_attach(struct device *dev, u32 flags)
 	if (!ret)
 		ret = genpd_dev_pm_attach(dev);
 
+	if (dev->pm_domain)
+		dev->power.detach_power_off = !!(flags & PD_FLAG_DETACH_POWER_OFF);
+
 	return ret < 0 ? ret : 0;
 }
 EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index f0bd8fbae4f2..be824dfc8577 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -720,6 +720,7 @@ struct dev_pm_info {
 	struct pm_subsys_data	*subsys_data;  /* Owned by the subsystem. */
 	void (*set_latency_tolerance)(struct device *, s32);
 	struct dev_pm_qos	*qos;
+	bool			detach_power_off:1;	/* Owned by the driver core */
 };
 
 extern int dev_pm_get_subsys_data(struct device *dev);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 3/3] driver core: platform: Drop dev_pm_domain_detach() call
  2025-07-03 11:27 [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
  2025-07-03 11:27 ` [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Claudiu
  2025-07-03 11:27 ` [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
@ 2025-07-03 11:27 ` Claudiu
  2025-07-04 11:15 ` [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Ulf Hansson
  3 siblings, 0 replies; 10+ messages in thread
From: Claudiu @ 2025-07-03 11:27 UTC (permalink / raw)
  To: linux, gregkh, david.m.ertman, ira.weiny, leon, rafael, dakr,
	len.brown, pavel, andersson, mturquette, sboyd, maarten.lankhorst,
	mripard, tzimmermann, airlied, simona, wsa+renesas, ulf.hansson,
	mathieu.poirier, vkoul, yung-chuan.liao, pierre-louis.bossart,
	broonie, robh, jirislaby, saravanak, jic23, dmitry.torokhov
  Cc: claudiu.beznea, linux-kernel, linux-pm, linux-arm-msm, linux-clk,
	linux-i2c, linux-mmc, linux-remoteproc, linux-sound, linux-spi,
	linux-serial, bhelgaas, geert, linux-iio, linux-renesas-soc,
	fabrizio.castro.jz, Claudiu Beznea

From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

On the Renesas RZ/G3S (and other Renesas SoCs, e.g., RZ/G2{L, LC, UL}),
clocks are managed through PM domains. These PM domains, registered on
behalf of the clock controller driver, are configured with
GENPD_FLAG_PM_CLK. In most of the Renesas drivers used by RZ SoCs, the
clocks are enabled/disabled using runtime PM APIs. The power domains may
also have power_on/power_off support implemented. After the device PM
domain is powered off any CPU accesses to these domains leads to system
aborts.

During probe, devices are attached to the PM domain controlling their
clocks and power. Similarly, during removal, devices are detached from the
PM domain.

The detachment call stack is as follows:

device_driver_detach() ->
  device_release_driver_internal() ->
    __device_release_driver() ->
      device_remove() ->
        platform_remove() ->
          dev_pm_domain_detach()

During driver unbind, after the device is detached from its PM domain,
the device_unbind_cleanup() function is called, which subsequently invokes
devres_release_all(). This function handles devres resource cleanup.

If runtime PM is enabled in driver probe via devm_pm_runtime_enable(), the
cleanup process triggers the action or reset function for disabling runtime
PM. This function is pm_runtime_disable_action(), which leads to the
following call stack of interest when called:

pm_runtime_disable_action() ->
  pm_runtime_dont_use_autosuspend() ->
    __pm_runtime_use_autosuspend() ->
      update_autosuspend() ->
        rpm_idle()

The rpm_idle() function attempts to resume the device at runtime. However,
at the point it is called, the device is no longer part of a PM domain
(which manages clocks and power states). If the driver implements its own
runtime PM APIs for specific functionalities - such as the rzg2l_adc
driver - while also relying on the power domain subsystem for power
management, rpm_idle() will invoke the driver's runtime PM API. However,
since the device is no longer part of a PM domain at this point, the PM
domain's runtime PM APIs will not be called. This leads to system aborts on
Renesas SoCs.

Another identified case is when a subsystem performs various cleanups
using device_unbind_cleanup(), calling driver-specific APIs in the process.
A known example is the thermal subsystem, which may call driver-specific
APIs to disable the thermal device. The relevant call stack in this case
is:

device_driver_detach() ->
  device_release_driver_internal() ->
    device_unbind_cleanup() ->
      devres_release_all() ->
        devm_thermal_of_zone_release() ->
          thermal_zone_device_disable() ->
            thermal_zone_device_set_mode() ->
              struct thermal_zone_device_ops::change_mode()

At the moment the driver-specific change_mode() API is called, the device
is no longer part of its PM domain. Accessing its registers without proper
power management leads to system aborts.

Drop the call to dev_pm_domain_detach() from the platform bus remove
function and rely on the newly introduced call in device_unbind_cleanup().
This ensures the same effect, but the call now occurs after all
driver-specific devres resources have been freed.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
---

Changes in v5:
- dropped tab in the call traces from patch description
- used PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF

Changes in v4:
- dropped devm_pm_domain_attach() approach
- adjusted patch description to reflect this

Changes in v3:
- adjusted the call to devm_pm_domain_attach() as it now gets
  2 parameters

Changes in v2:
- dropped the devres group open/close approach and use
  devm_pm_domain_attach()
- adjusted patch description to reflect the new approach

 drivers/base/platform.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index df1ec34fdf56..09450349cf32 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1396,15 +1396,13 @@ static int platform_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON);
+	ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON |
+					 PD_FLAG_DETACH_POWER_OFF);
 	if (ret)
 		goto out;
 
-	if (drv->probe) {
+	if (drv->probe)
 		ret = drv->probe(dev);
-		if (ret)
-			dev_pm_domain_detach(_dev, true);
-	}
 
 out:
 	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
@@ -1422,7 +1420,6 @@ static void platform_remove(struct device *_dev)
 
 	if (drv->remove)
 		drv->remove(dev);
-	dev_pm_domain_detach(_dev, true);
 }
 
 static void platform_shutdown(struct device *_dev)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-03 11:27 [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
                   ` (2 preceding siblings ...)
  2025-07-03 11:27 ` [PATCH v5 3/3] driver core: platform: Drop dev_pm_domain_detach() call Claudiu
@ 2025-07-04 11:15 ` Ulf Hansson
  2025-07-04 13:51   ` Claudiu Beznea
  2025-07-04 19:53   ` Rafael J. Wysocki
  3 siblings, 2 replies; 10+ messages in thread
From: Ulf Hansson @ 2025-07-04 11:15 UTC (permalink / raw)
  To: Claudiu, rafael
  Cc: linux, gregkh, david.m.ertman, ira.weiny, leon, dakr, len.brown,
	pavel, andersson, mturquette, sboyd, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, wsa+renesas, mathieu.poirier, vkoul,
	yung-chuan.liao, pierre-louis.bossart, broonie, robh, jirislaby,
	saravanak, jic23, dmitry.torokhov, linux-kernel, linux-pm,
	linux-arm-msm, linux-clk, linux-i2c, linux-mmc, linux-remoteproc,
	linux-sound, linux-spi, linux-serial, bhelgaas, geert, linux-iio,
	linux-renesas-soc, fabrizio.castro.jz, Claudiu Beznea

On Thu, 3 Jul 2025 at 13:27, Claudiu <claudiu.beznea@tuxon.dev> wrote:
>
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>
> Hi,
>
> Series drops the dev_pm_domain_detach() from platform bus remove and
> adds it in device_unbind_cleanup() to avoid runtime resumming the device
> after it was detached from its PM domain.
>
> Please provide your feedback.
>
> Thank you,
> Claudiu
>
> Changes in v5:
> - added PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF;
>   due to this a new patch was introduced
>   "PM: domains: Add flags to specify power on attach/detach"
>
> Changes in v4:
> - added a flag in dev_pm_info that is saved in dev_pm_domain_attach()
>   and used in device_unbind_cleanup()
>
> Changes in v3:
> - add devm_pm_domain_attach()
>
> Changes in v2:
> - dropped the devres group open/close approach and use
>   devm_pm_domain_attach()
> - adjusted patch description to reflect the new approach
>
>
> Claudiu Beznea (3):
>   PM: domains: Add flags to specify power on attach/detach
>   PM: domains: Detach on device_unbind_cleanup()
>   driver core: platform: Drop dev_pm_domain_detach() call
>
>  drivers/amba/bus.c                       |  4 ++--
>  drivers/base/auxiliary.c                 |  2 +-
>  drivers/base/dd.c                        |  2 ++
>  drivers/base/platform.c                  |  9 +++------
>  drivers/base/power/common.c              |  9 ++++++---
>  drivers/clk/qcom/apcs-sdx55.c            |  2 +-
>  drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
>  drivers/i2c/i2c-core-base.c              |  2 +-
>  drivers/mmc/core/sdio_bus.c              |  2 +-
>  drivers/rpmsg/rpmsg_core.c               |  2 +-
>  drivers/soundwire/bus_type.c             |  2 +-
>  drivers/spi/spi.c                        |  2 +-
>  drivers/tty/serdev/core.c                |  2 +-
>  include/linux/pm.h                       |  1 +
>  include/linux/pm_domain.h                | 10 ++++++++--
>  15 files changed, 31 insertions(+), 22 deletions(-)
>
> --
> 2.43.0
>

The series looks good to me, please add:
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Rafael, do you intend to pick this via your tree?

Another note, the similar thing that is being done in patch3 from the
platform bus, is needed for other buses too (at least the amba bus for
sure). Claudiu, are you planning to do that as a step on top - or are
you expecting others to help out?

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-04 11:15 ` [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Ulf Hansson
@ 2025-07-04 13:51   ` Claudiu Beznea
  2025-07-04 19:53   ` Rafael J. Wysocki
  1 sibling, 0 replies; 10+ messages in thread
From: Claudiu Beznea @ 2025-07-04 13:51 UTC (permalink / raw)
  To: Ulf Hansson, rafael
  Cc: linux, gregkh, david.m.ertman, ira.weiny, leon, dakr, len.brown,
	pavel, andersson, mturquette, sboyd, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, wsa+renesas, mathieu.poirier, vkoul,
	yung-chuan.liao, pierre-louis.bossart, broonie, robh, jirislaby,
	saravanak, jic23, dmitry.torokhov, linux-kernel, linux-pm,
	linux-arm-msm, linux-clk, linux-i2c, linux-mmc, linux-remoteproc,
	linux-sound, linux-spi, linux-serial, bhelgaas, geert, linux-iio,
	linux-renesas-soc, fabrizio.castro.jz, Claudiu Beznea

Hi, Ulf,

On 04.07.2025 14:15, Ulf Hansson wrote:
> On Thu, 3 Jul 2025 at 13:27, Claudiu <claudiu.beznea@tuxon.dev> wrote:
>>
>> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>>
>> Hi,
>>
>> Series drops the dev_pm_domain_detach() from platform bus remove and
>> adds it in device_unbind_cleanup() to avoid runtime resumming the device
>> after it was detached from its PM domain.
>>
>> Please provide your feedback.
>>
>> Thank you,
>> Claudiu
>>
>> Changes in v5:
>> - added PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF;
>>   due to this a new patch was introduced
>>   "PM: domains: Add flags to specify power on attach/detach"
>>
>> Changes in v4:
>> - added a flag in dev_pm_info that is saved in dev_pm_domain_attach()
>>   and used in device_unbind_cleanup()
>>
>> Changes in v3:
>> - add devm_pm_domain_attach()
>>
>> Changes in v2:
>> - dropped the devres group open/close approach and use
>>   devm_pm_domain_attach()
>> - adjusted patch description to reflect the new approach
>>
>>
>> Claudiu Beznea (3):
>>   PM: domains: Add flags to specify power on attach/detach
>>   PM: domains: Detach on device_unbind_cleanup()
>>   driver core: platform: Drop dev_pm_domain_detach() call
>>
>>  drivers/amba/bus.c                       |  4 ++--
>>  drivers/base/auxiliary.c                 |  2 +-
>>  drivers/base/dd.c                        |  2 ++
>>  drivers/base/platform.c                  |  9 +++------
>>  drivers/base/power/common.c              |  9 ++++++---
>>  drivers/clk/qcom/apcs-sdx55.c            |  2 +-
>>  drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
>>  drivers/i2c/i2c-core-base.c              |  2 +-
>>  drivers/mmc/core/sdio_bus.c              |  2 +-
>>  drivers/rpmsg/rpmsg_core.c               |  2 +-
>>  drivers/soundwire/bus_type.c             |  2 +-
>>  drivers/spi/spi.c                        |  2 +-
>>  drivers/tty/serdev/core.c                |  2 +-
>>  include/linux/pm.h                       |  1 +
>>  include/linux/pm_domain.h                | 10 ++++++++--
>>  15 files changed, 31 insertions(+), 22 deletions(-)
>>
>> --
>> 2.43.0
>>
> 
> The series looks good to me, please add:
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> 
> Rafael, do you intend to pick this via your tree?
> 
> Another note, the similar thing that is being done in patch3 from the
> platform bus, is needed for other buses too (at least the amba bus for
> sure). Claudiu, are you planning to do that as a step on top - or are
> you expecting others to help out?

My plan was to take care of it once the approach here (or something
similar, if any) will end up in a release.

Thank you,
Claudiu

> 
> Kind regards
> Uffe


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach
  2025-07-03 11:27 ` [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Claudiu
@ 2025-07-04 15:37   ` Mathieu Poirier
  0 siblings, 0 replies; 10+ messages in thread
From: Mathieu Poirier @ 2025-07-04 15:37 UTC (permalink / raw)
  To: Claudiu
  Cc: linux, gregkh, david.m.ertman, ira.weiny, leon, rafael, dakr,
	len.brown, pavel, andersson, mturquette, sboyd, maarten.lankhorst,
	mripard, tzimmermann, airlied, simona, wsa+renesas, ulf.hansson,
	vkoul, yung-chuan.liao, pierre-louis.bossart, broonie, robh,
	jirislaby, saravanak, jic23, dmitry.torokhov, linux-kernel,
	linux-pm, linux-arm-msm, linux-clk, linux-i2c, linux-mmc,
	linux-remoteproc, linux-sound, linux-spi, linux-serial, bhelgaas,
	geert, linux-iio, linux-renesas-soc, fabrizio.castro.jz,
	Claudiu Beznea

On Thu, Jul 03, 2025 at 02:27:06PM +0300, Claudiu wrote:
> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> 
> 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 commits 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 is a preparatory commit.
> 
> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> ---
> 
> Changes in v5:
> - none; this patch is new
> 
>  drivers/amba/bus.c                       |  4 ++--
>  drivers/base/auxiliary.c                 |  2 +-
>  drivers/base/platform.c                  |  2 +-
>  drivers/base/power/common.c              |  6 +++---
>  drivers/clk/qcom/apcs-sdx55.c            |  2 +-
>  drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
>  drivers/i2c/i2c-core-base.c              |  2 +-
>  drivers/mmc/core/sdio_bus.c              |  2 +-
>  drivers/rpmsg/rpmsg_core.c               |  2 +-

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  drivers/soundwire/bus_type.c             |  2 +-
>  drivers/spi/spi.c                        |  2 +-
>  drivers/tty/serdev/core.c                |  2 +-
>  include/linux/pm_domain.h                | 10 ++++++++--
>  13 files changed, 23 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 71482d639a6d..74e34a07ef72 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -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;
>  
> diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c
> index dba7c8e13a53..44cd3f85b659 100644
> --- a/drivers/base/auxiliary.c
> +++ b/drivers/base/auxiliary.c
> @@ -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;
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 075ec1d1b73a..df1ec34fdf56 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -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;
>  
> diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
> index 781968a128ff..fecb85fa85ac 100644
> --- a/drivers/base/power/common.c
> +++ b/drivers/base/power/common.c
> @@ -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);
>  
> diff --git a/drivers/clk/qcom/apcs-sdx55.c b/drivers/clk/qcom/apcs-sdx55.c
> index 3ba01622d8f0..90dd1f1855c2 100644
> --- a/drivers/clk/qcom/apcs-sdx55.c
> +++ b/drivers/clk/qcom/apcs-sdx55.c
> @@ -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;
> diff --git a/drivers/gpu/drm/display/drm_dp_aux_bus.c b/drivers/gpu/drm/display/drm_dp_aux_bus.c
> index 7b9afcf48836..2d279e82922f 100644
> --- a/drivers/gpu/drm/display/drm_dp_aux_bus.c
> +++ b/drivers/gpu/drm/display/drm_dp_aux_bus.c
> @@ -58,7 +58,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");
>  
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 2ad2b1838f0f..38eabf1173da 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -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;
>  
> diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
> index b66b637e2d57..656601754966 100644
> --- a/drivers/mmc/core/sdio_bus.c
> +++ b/drivers/mmc/core/sdio_bus.c
> @@ -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;
>  
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 6ee36adcbdba..bece5e635ee9 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -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;
>  
> diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
> index 75d6f16efced..bc1e653080d9 100644
> --- a/drivers/soundwire/bus_type.c
> +++ b/drivers/soundwire/bus_type.c
> @@ -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;
>  
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 1bc0fdbb1bd7..8200b47b2295 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -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;
>  
> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
> index 0213381fa358..d16c207a1a9b 100644
> --- a/drivers/tty/serdev/core.c
> +++ b/drivers/tty/serdev/core.c
> @@ -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;
>  
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index 0b18160901a2..62a35a78ce9b 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -36,10 +36,16 @@
>   *				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;
>  }
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-04 11:15 ` [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Ulf Hansson
  2025-07-04 13:51   ` Claudiu Beznea
@ 2025-07-04 19:53   ` Rafael J. Wysocki
  2025-07-04 20:00     ` Wolfram Sang
  2025-07-07 18:43     ` Rafael J. Wysocki
  1 sibling, 2 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2025-07-04 19:53 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Claudiu, rafael, linux, gregkh, david.m.ertman, ira.weiny, leon,
	dakr, len.brown, pavel, andersson, mturquette, sboyd,
	maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	wsa+renesas, mathieu.poirier, vkoul, yung-chuan.liao,
	pierre-louis.bossart, broonie, robh, jirislaby, saravanak, jic23,
	dmitry.torokhov, linux-kernel, linux-pm, linux-arm-msm, linux-clk,
	linux-i2c, linux-mmc, linux-remoteproc, linux-sound, linux-spi,
	linux-serial, bhelgaas, geert, linux-iio, linux-renesas-soc,
	fabrizio.castro.jz, Claudiu Beznea

On Fri, Jul 4, 2025 at 1:16 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Thu, 3 Jul 2025 at 13:27, Claudiu <claudiu.beznea@tuxon.dev> wrote:
> >
> > From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> >
> > Hi,
> >
> > Series drops the dev_pm_domain_detach() from platform bus remove and
> > adds it in device_unbind_cleanup() to avoid runtime resumming the device
> > after it was detached from its PM domain.
> >
> > Please provide your feedback.
> >
> > Thank you,
> > Claudiu
> >
> > Changes in v5:
> > - added PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF;
> >   due to this a new patch was introduced
> >   "PM: domains: Add flags to specify power on attach/detach"
> >
> > Changes in v4:
> > - added a flag in dev_pm_info that is saved in dev_pm_domain_attach()
> >   and used in device_unbind_cleanup()
> >
> > Changes in v3:
> > - add devm_pm_domain_attach()
> >
> > Changes in v2:
> > - dropped the devres group open/close approach and use
> >   devm_pm_domain_attach()
> > - adjusted patch description to reflect the new approach
> >
> >
> > Claudiu Beznea (3):
> >   PM: domains: Add flags to specify power on attach/detach
> >   PM: domains: Detach on device_unbind_cleanup()
> >   driver core: platform: Drop dev_pm_domain_detach() call
> >
> >  drivers/amba/bus.c                       |  4 ++--
> >  drivers/base/auxiliary.c                 |  2 +-
> >  drivers/base/dd.c                        |  2 ++
> >  drivers/base/platform.c                  |  9 +++------
> >  drivers/base/power/common.c              |  9 ++++++---
> >  drivers/clk/qcom/apcs-sdx55.c            |  2 +-
> >  drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
> >  drivers/i2c/i2c-core-base.c              |  2 +-
> >  drivers/mmc/core/sdio_bus.c              |  2 +-
> >  drivers/rpmsg/rpmsg_core.c               |  2 +-
> >  drivers/soundwire/bus_type.c             |  2 +-
> >  drivers/spi/spi.c                        |  2 +-
> >  drivers/tty/serdev/core.c                |  2 +-
> >  include/linux/pm.h                       |  1 +
> >  include/linux/pm_domain.h                | 10 ++++++++--
> >  15 files changed, 31 insertions(+), 22 deletions(-)
> >
> > --
> > 2.43.0
> >
>
> The series looks good to me, please add:
> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
>
> Rafael, do you intend to pick this via your tree?

I do in general, but I haven't looked at this version yet.  I'll get
to it early next week.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-04 19:53   ` Rafael J. Wysocki
@ 2025-07-04 20:00     ` Wolfram Sang
  2025-07-07 18:43     ` Rafael J. Wysocki
  1 sibling, 0 replies; 10+ messages in thread
From: Wolfram Sang @ 2025-07-04 20:00 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ulf Hansson, Claudiu, linux, gregkh, david.m.ertman, ira.weiny,
	leon, dakr, len.brown, pavel, andersson, mturquette, sboyd,
	maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	mathieu.poirier, vkoul, yung-chuan.liao, pierre-louis.bossart,
	broonie, robh, jirislaby, saravanak, jic23, dmitry.torokhov,
	linux-kernel, linux-pm, linux-arm-msm, linux-clk, linux-i2c,
	linux-mmc, linux-remoteproc, linux-sound, linux-spi, linux-serial,
	bhelgaas, geert, linux-iio, linux-renesas-soc, fabrizio.castro.jz,
	Claudiu Beznea

[-- Attachment #1: Type: text/plain, Size: 349 bytes --]


> > The series looks good to me, please add:
> > Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> >
> > Rafael, do you intend to pick this via your tree?
> 
> I do in general, but I haven't looked at this version yet.  I'll get
> to it early next week.

For the I2C part:

Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup()
  2025-07-04 19:53   ` Rafael J. Wysocki
  2025-07-04 20:00     ` Wolfram Sang
@ 2025-07-07 18:43     ` Rafael J. Wysocki
  1 sibling, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2025-07-07 18:43 UTC (permalink / raw)
  To: Ulf Hansson, Claudiu
  Cc: linux, gregkh, david.m.ertman, ira.weiny, leon, dakr, len.brown,
	pavel, andersson, mturquette, sboyd, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, wsa+renesas, mathieu.poirier, vkoul,
	yung-chuan.liao, pierre-louis.bossart, broonie, robh, jirislaby,
	saravanak, jic23, dmitry.torokhov, linux-kernel, linux-pm,
	linux-arm-msm, linux-clk, linux-i2c, linux-mmc, linux-remoteproc,
	linux-sound, linux-spi, linux-serial, bhelgaas, geert, linux-iio,
	linux-renesas-soc, fabrizio.castro.jz, Claudiu Beznea

On Fri, Jul 4, 2025 at 9:53 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Fri, Jul 4, 2025 at 1:16 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > On Thu, 3 Jul 2025 at 13:27, Claudiu <claudiu.beznea@tuxon.dev> wrote:
> > >
> > > From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
> > >
> > > Hi,
> > >
> > > Series drops the dev_pm_domain_detach() from platform bus remove and
> > > adds it in device_unbind_cleanup() to avoid runtime resumming the device
> > > after it was detached from its PM domain.
> > >
> > > Please provide your feedback.
> > >
> > > Thank you,
> > > Claudiu
> > >
> > > Changes in v5:
> > > - added PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF;
> > >   due to this a new patch was introduced
> > >   "PM: domains: Add flags to specify power on attach/detach"
> > >
> > > Changes in v4:
> > > - added a flag in dev_pm_info that is saved in dev_pm_domain_attach()
> > >   and used in device_unbind_cleanup()
> > >
> > > Changes in v3:
> > > - add devm_pm_domain_attach()
> > >
> > > Changes in v2:
> > > - dropped the devres group open/close approach and use
> > >   devm_pm_domain_attach()
> > > - adjusted patch description to reflect the new approach
> > >
> > >
> > > Claudiu Beznea (3):
> > >   PM: domains: Add flags to specify power on attach/detach
> > >   PM: domains: Detach on device_unbind_cleanup()
> > >   driver core: platform: Drop dev_pm_domain_detach() call
> > >
> > >  drivers/amba/bus.c                       |  4 ++--
> > >  drivers/base/auxiliary.c                 |  2 +-
> > >  drivers/base/dd.c                        |  2 ++
> > >  drivers/base/platform.c                  |  9 +++------
> > >  drivers/base/power/common.c              |  9 ++++++---
> > >  drivers/clk/qcom/apcs-sdx55.c            |  2 +-
> > >  drivers/gpu/drm/display/drm_dp_aux_bus.c |  2 +-
> > >  drivers/i2c/i2c-core-base.c              |  2 +-
> > >  drivers/mmc/core/sdio_bus.c              |  2 +-
> > >  drivers/rpmsg/rpmsg_core.c               |  2 +-
> > >  drivers/soundwire/bus_type.c             |  2 +-
> > >  drivers/spi/spi.c                        |  2 +-
> > >  drivers/tty/serdev/core.c                |  2 +-
> > >  include/linux/pm.h                       |  1 +
> > >  include/linux/pm_domain.h                | 10 ++++++++--
> > >  15 files changed, 31 insertions(+), 22 deletions(-)
> > >
> > > --
> > > 2.43.0
> > >
> >
> > The series looks good to me, please add:
> > Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
> >
> > Rafael, do you intend to pick this via your tree?
>
> I do in general, but I haven't looked at this version yet.  I'll get
> to it early next week.

Now applied as 6.17 material, thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-07-07 18:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 11:27 [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
2025-07-03 11:27 ` [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Claudiu
2025-07-04 15:37   ` Mathieu Poirier
2025-07-03 11:27 ` [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup() Claudiu
2025-07-03 11:27 ` [PATCH v5 3/3] driver core: platform: Drop dev_pm_domain_detach() call Claudiu
2025-07-04 11:15 ` [PATCH v5 0/3] PM: domains: Detach on device_unbind_cleanup() Ulf Hansson
2025-07-04 13:51   ` Claudiu Beznea
2025-07-04 19:53   ` Rafael J. Wysocki
2025-07-04 20:00     ` Wolfram Sang
2025-07-07 18:43     ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).