Skip to contentSkip to conversation

Allow platform drivers to skip PM domain power-on at probe

PATCH In review Beleswar Padhi 2 participants 4 messages Nov 23 – Nov 25

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Allow platform drivers to skip PM domain power-on at probe

Some devices must be configured before their PM domain is powered on, but on DT based platforms platform_probe() always powers it on first. This series lets a platform driver opt out.

The user will be the TI K3 DSP/M4 remoteproc drivers which need to put those remote cores in reset before powering on the pmdomain. A patch has been posted to add "power-domains" DT property to these devices[0] which is the motivation of this series as well.

[0]: https://lore.kernel.org/all/[email protected]

No changelog since RFC. Re-submitted after removing RFC tag.

Link to RFC:
https://lore.kernel.org/all/[email protected]/

Thanks,
Beleswar

Beleswar Padhi (2):
PM: domains: Honour PD_FLAG_ATTACH_POWER_ON for genpd driver core: platform: Allow drivers to skip PM domain power-on at
probe

 drivers/base/platform.c         | 7 +++++--
 drivers/base/power/common.c     | 5 +++--
 drivers/pmdomain/core.c         | 5 +++--
 include/linux/platform_device.h | 8 ++++++++
 include/linux/pm_domain.h       | 4 ++--
 5 files changed, 21 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 PM: domains: Honour PD_FLAG_ATTACH_POWER_ON for genpd

dev_pm_domain_attach() takes PD_FLAG_ATTACH_POWER_ON to let the caller decide whether the PM domain is powered on during attach. But, only the ACPI path honours it today. genpd_dev_pm_attach() takes no flags and always powers on the domain, so a DT based device cannot be attached to its PM domain without powering it on.

Add a power_on argument to genpd_dev_pm_attach() and pass it on to __genpd_dev_pm_attach(), which already supports it for the multiple PM domains case.

---
No changes since RFC.

Link to RFC:
https://lore.kernel.org/all/[email protected]/

 drivers/base/power/common.c | 5 +++--
 drivers/pmdomain/core.c     | 5 +++--
 include/linux/pm_domain.h   | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)
drivers/base/power/common.c +3 -2
index 9bef9248a7052..3263659c58dc8 100644
@@ -102,14 +102,15 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
  */
 int dev_pm_domain_attach(struct device *dev, u32 flags)
 {
+	bool power_on = !!(flags & PD_FLAG_ATTACH_POWER_ON);
 	int ret;
 
 	if (dev->pm_domain)
 		return 0;
 
-	ret = acpi_dev_pm_attach(dev, !!(flags & PD_FLAG_ATTACH_POWER_ON));
+	ret = acpi_dev_pm_attach(dev, power_on);
 	if (!ret)
-		ret = genpd_dev_pm_attach(dev);
+		ret = genpd_dev_pm_attach(dev, power_on);
 
 	if (dev->pm_domain)
 		dev->power.detach_power_off = !!(flags & PD_FLAG_DETACH_POWER_OFF);
drivers/pmdomain/core.c +3 -2
index e0bf30c59ccea..c73927ac07e2c 100644
@@ -3556,6 +3556,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
 /**
  * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
  * @dev: Device to attach.
+ * @power_on: Whether to power on the PM domain during attach.
  *
  * Parse device's OF node to find a PM domain specifier. If such is found,
  * attaches the device to retrieved pm_domain ops.
@@ -3566,7 +3567,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
  * found or turned on, then return -EPROBE_DEFER to ensure that the device is
  * not probed and to re-try again later.
  */
-int genpd_dev_pm_attach(struct device *dev)
+int genpd_dev_pm_attach(struct device *dev, bool power_on)
 {
 	if (!dev->of_node)
 		return 0;
@@ -3579,7 +3580,7 @@ int genpd_dev_pm_attach(struct device *dev)
 				       "#power-domain-cells") != 1)
 		return 0;
 
-	return __genpd_dev_pm_attach(dev, dev, 0, 1, true);
+	return __genpd_dev_pm_attach(dev, dev, 0, 1, power_on);
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 
include/linux/pm_domain.h +2 -2
index 14e0e346c610a..010fbfffee39d 100644
@@ -481,7 +481,7 @@ int of_genpd_add_child_ids(struct device_node *np,
 int of_genpd_remove_child_ids(struct device_node *np,
 			      struct genpd_onecell_data *data);
 
-int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_attach(struct device *dev, bool power_on);
 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
 					 unsigned int index);
 struct device *genpd_dev_pm_attach_by_name(struct device *dev,
@@ -527,7 +527,7 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
 
 static inline void of_genpd_sync_state(struct device_node *np) {}
 
-static inline int genpd_dev_pm_attach(struct device *dev)
+static inline int genpd_dev_pm_attach(struct device *dev, bool power_on)
 {
 	return 0;
 }
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] PM: domains: Honour PD_FLAG_ATTACH_POWER_ON for genpd

Quoted 7 lines · Beleswar Padhi

dev_pm_domain_attach() takes PD_FLAG_ATTACH_POWER_ON to let the caller decide whether the PM domain is powered on during attach. But, only the ACPI path honours it today. genpd_dev_pm_attach() takes no flags and always powers on the domain, so a DT based device cannot be attached to its PM domain without powering it on.

Quoted 5 lines

Add a power_on argument to genpd_dev_pm_attach() and pass it on to __genpd_dev_pm_attach(), which already supports it for the multiple PM domains case.

Fine with me.

Quoted 88 lines

---
No changes since RFC.

Link to RFC:
https://lore.kernel.org/all/[email protected]/

 drivers/base/power/common.c | 5 +++--
 drivers/pmdomain/core.c     | 5 +++--
 include/linux/pm_domain.h   | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)
drivers/base/power/common.c +3 -2
index 9bef9248a7052..3263659c58dc8 100644
@@ -102,14 +102,15 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
  */
 int dev_pm_domain_attach(struct device *dev, u32 flags)
 {
+       bool power_on = !!(flags & PD_FLAG_ATTACH_POWER_ON);
        int ret;
 
        if (dev->pm_domain)
                return 0;
 
-       ret = acpi_dev_pm_attach(dev, !!(flags & PD_FLAG_ATTACH_POWER_ON));
+       ret = acpi_dev_pm_attach(dev, power_on);
        if (!ret)
-               ret = genpd_dev_pm_attach(dev);
+               ret = genpd_dev_pm_attach(dev, power_on);
 
        if (dev->pm_domain)
                dev->power.detach_power_off = !!(flags & PD_FLAG_DETACH_POWER_OFF);
drivers/pmdomain/core.c +3 -2
index e0bf30c59ccea..c73927ac07e2c 100644
@@ -3556,6 +3556,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
 /**
  * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
  * @dev: Device to attach.
+ * @power_on: Whether to power on the PM domain during attach.
  *
  * Parse device's OF node to find a PM domain specifier. If such is found,
  * attaches the device to retrieved pm_domain ops.
@@ -3566,7 +3567,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
  * found or turned on, then return -EPROBE_DEFER to ensure that the device is
  * not probed and to re-try again later.
  */
-int genpd_dev_pm_attach(struct device *dev)
+int genpd_dev_pm_attach(struct device *dev, bool power_on)
 {
        if (!dev->of_node)
                return 0;
@@ -3579,7 +3580,7 @@ int genpd_dev_pm_attach(struct device *dev)
                                       "#power-domain-cells") != 1)
                return 0;
 
-       return __genpd_dev_pm_attach(dev, dev, 0, 1, true);
+       return __genpd_dev_pm_attach(dev, dev, 0, 1, power_on);
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 
include/linux/pm_domain.h +2 -3
index 14e0e346c610a..010fbfffee39d 100644
@@ -481,7 +481,7 @@ int of_genpd_add_child_ids(struct device_node *np,
 int of_genpd_remove_child_ids(struct device_node *np,
                              struct genpd_onecell_data *data);
 
-int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_attach(struct device *dev, bool power_on);
 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
                                         unsigned int index);
 struct device *genpd_dev_pm_attach_by_name(struct device *dev,
@@ -527,7 +527,7 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
 
 static inline void of_genpd_sync_state(struct device_node *np) {}
 
-static inline int genpd_dev_pm_attach(struct device *dev)
+static inline int genpd_dev_pm_attach(struct device *dev, bool power_on)
 {
        return 0;
 }
--

2.34.1

#3 lore raw

PATCH 2/2 driver core: platform: Allow drivers to skip PM domain power-on at probe

In reply to Beleswar Padhi

Currently, platform_probe() attaches the PM domain to the device and powers the domain on before calling the driver's probe. This works for most cases, but would be erroneous for devices that must be configured before they can be powered on.

One example is the C66x/C7x remote processors on TI K3 SoCs like AM62A. Such a remote core's local reset must be asserted before the device is powered on, otherwise the core can start running bogus instructions whatever happens to be in its memories at that point.

dev_pm_domain_attach() lets its caller skip the power-on by not passing PD_FLAG_ATTACH_POWER_ON. So, add a pm_domain_no_power_on flag to struct platform_driver by which platform drivers can opt out of the power-on at attach. Drivers that set it must power on the PM domain themselves.

---
No changes since RFC.

Link to RFC:
https://lore.kernel.org/all/[email protected]/

 drivers/base/platform.c         | 7 +++++--
 include/linux/platform_device.h | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/base/platform.c +5 -2
index 979593e5cca15..6e7b803a50ab2 100644
@@ -1482,6 +1482,7 @@ static int platform_probe(struct device *_dev)
 {
 	struct platform_driver *drv = to_platform_driver(_dev->driver);
 	struct platform_device *dev = to_platform_device(_dev);
+	u32 pd_flags = PD_FLAG_DETACH_POWER_OFF;
 	int ret;
 
 	/*
@@ -1498,8 +1499,10 @@ static int platform_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON |
-					 PD_FLAG_DETACH_POWER_OFF);
+	if (!drv->pm_domain_no_power_on)
+		pd_flags |= PD_FLAG_ATTACH_POWER_ON;
+
+	ret = dev_pm_domain_attach(_dev, pd_flags);
 	if (ret)
 		goto out;
 
include/linux/platform_device.h +8 -0
index 3bd0f1f0d8704..4d1679c4ea78e 100644
@@ -292,6 +292,14 @@ struct platform_driver {
 	 * to setup and manage their own I/O address space.
 	 */
 	bool driver_managed_dma;
+	/*
+	 * By default the PM domain of a platform device is powered on before
+	 * the driver's probe is invoked. Drivers that need to configure the
+	 * device (e.g. hold it in reset) before its PM domain can be powered
+	 * on must set this flag, and are then responsible for powering on the
+	 * PM domain themselves.
+	 */
+	bool pm_domain_no_power_on;
 };
 
 #define to_platform_driver(drv)	(container_of((drv), struct platform_driver, \
Signature · 1 line
2.34.1