All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-04 13:52   ` Ulf Hansson
@ 2014-08-23 22:45     ` Pavel Machek
  -1 siblings, 0 replies; 96+ messages in thread
From: Pavel Machek @ 2014-08-23 22:45 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King

On Thu 2014-09-04 15:52:28, Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

Acked-by: Pavel Machek <Pavel@ucw.cz>

> ---
>  drivers/acpi/device_pm.c | 8 +++++++-
>  include/linux/acpi.h     | 7 +++++--
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
> index 67075f8..0d52ce1 100644
> --- a/drivers/acpi/device_pm.c
> +++ b/drivers/acpi/device_pm.c
> @@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
>   */
>  int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
> @@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
>   */
> -void acpi_dev_pm_detach(struct device *dev, bool power_off)
> +int acpi_dev_pm_detach(struct device *dev, bool power_off)
>  {
>  	struct acpi_device *adev = ACPI_COMPANION(dev);
>  
> @@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
>  			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
>  			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
>  		}
> +		return 0;
>  	}
> +	return -EINVAL;
>  }
>  EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
>  #endif /* CONFIG_PM */
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 807cbc4..c83cca5 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
>  #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
>  struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
>  int acpi_dev_pm_attach(struct device *dev, bool power_on);
> -void acpi_dev_pm_detach(struct device *dev, bool power_off);
> +int acpi_dev_pm_detach(struct device *dev, bool power_off);
>  #else
>  static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
>  {
> @@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
>  	return -ENODEV;
>  }
> -static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
> +static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
>  #endif
>  
>  #ifdef CONFIG_ACPI
> -- 
> 1.9.1

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-08-23 22:45     ` Pavel Machek
  0 siblings, 0 replies; 96+ messages in thread
From: Pavel Machek @ 2014-08-23 22:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu 2014-09-04 15:52:28, Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

Acked-by: Pavel Machek <Pavel@ucw.cz>

> ---
>  drivers/acpi/device_pm.c | 8 +++++++-
>  include/linux/acpi.h     | 7 +++++--
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
> index 67075f8..0d52ce1 100644
> --- a/drivers/acpi/device_pm.c
> +++ b/drivers/acpi/device_pm.c
> @@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
>   */
>  int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
> @@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
>   */
> -void acpi_dev_pm_detach(struct device *dev, bool power_off)
> +int acpi_dev_pm_detach(struct device *dev, bool power_off)
>  {
>  	struct acpi_device *adev = ACPI_COMPANION(dev);
>  
> @@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
>  			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
>  			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
>  		}
> +		return 0;
>  	}
> +	return -EINVAL;
>  }
>  EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
>  #endif /* CONFIG_PM */
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 807cbc4..c83cca5 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
>  #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
>  struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
>  int acpi_dev_pm_attach(struct device *dev, bool power_on);
> -void acpi_dev_pm_detach(struct device *dev, bool power_off);
> +int acpi_dev_pm_detach(struct device *dev, bool power_off);
>  #else
>  static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
>  {
> @@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
>  	return -ENODEV;
>  }
> -static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
> +static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
>  #endif
>  
>  #ifdef CONFIG_ACPI
> -- 
> 1.9.1

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* [PATCH v3 0/9] PM / Domains: Generic OF-based support
@ 2014-09-04 13:52 ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

Changes in v3:
	- Aligned on terminology, now using "PM domain" in comments and commit
	- messages/headers.
	- Improved English and grammar in comments and commit messages/headers.
	- Adopted proposal from Geert, to have compile-time-check wrapper
	  functions for the API that adds xlate_simple and xlate_onecell
	  providers.
 	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
	- Handle non-contiguous arrays for onecell PM domain providers.
	- Rebased the Exynos patch to follow the new genpd API changes.


Changes in v2:
	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
	- Updated some comments in code and in commit messages.
	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
	- Rebased the ARM Exynos patch.
	- Added some Tested-by tags.


This patchset has a bit of a history and some parts of it has been posted
earlier.

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html

In the first revision I intentially didn't increase version number of the
patches, since I think it would have cause more confusion than clarity.

A summary of changes in V1 and since the last patchset, from the link above:
	- Instead of letting driver core handling the device to power domain
	binding/unbinding, follow the behavior of how the ACPI power domain
	is handled.


This is a summary of what these patches are intended to do:

1)
Add generic power domain OF-based support which also includes APIs to handle
attach/detach of generic power domains to devices.

2)
Adding a common API to attach/detach power domains and include support for the
ACPI and the generic power domain in there.

3)
>From subsystem level code, at probe/remove, convert from invoking the ACPI
specific power domain attach/detach functions to the new common attach/detach
APIs.

4)
Add support for the AMBA bus to attach/detach power domains, using the new
common APIs.

5)
Convert Exynos to use the new generic power domain OF support.

Obviously, there are dependencies througout this patchset, which means if they
get accepted the all need to go together. It might also be convenient to share
them through an immutable branch.


Tomasz Figa (2):
  PM / Domains: Add generic OF-based PM domain look-up
  ARM: exynos: Move to generic PM domain DT bindings

Ulf Hansson (7):
  ACPI / PM: Let acpi_dev_pm_detach() return an error code
  PM / Domains: Add APIs to attach/detach a PM domain for a device
  drivercore / platform: Convert to dev_pm_domain_attach|detach()
  i2c: core: Convert to dev_pm_domain_attach|detach()
  mmc: sdio: Convert to dev_pm_domain_attach|detach()
  spi: core: Convert to dev_pm_domain_attach|detach()
  amba: Add support for attach/detach of PM domains

 .../bindings/arm/exynos/power_domain.txt           |  13 +-
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 arch/arm/mach-exynos/pm_domains.c                  |  78 +-----
 drivers/acpi/device_pm.c                           |   8 +-
 drivers/amba/bus.c                                 |  10 +-
 drivers/base/platform.c                            |  15 +-
 drivers/base/power/common.c                        |  56 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 drivers/i2c/i2c-core.c                             |  13 +-
 drivers/mmc/core/sdio_bus.c                        |   4 +-
 drivers/spi/spi.c                                  |  12 +-
 include/linux/acpi.h                               |   7 +-
 include/linux/pm.h                                 |  14 +
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 15 files changed, 524 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

-- 
1.9.1


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

* [PATCH v3 0/9] PM / Domains: Generic OF-based support
@ 2014-09-04 13:52 ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Changes in v3:
	- Aligned on terminology, now using "PM domain" in comments and commit
	- messages/headers.
	- Improved English and grammar in comments and commit messages/headers.
	- Adopted proposal from Geert, to have compile-time-check wrapper
	  functions for the API that adds xlate_simple and xlate_onecell
	  providers.
 	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
	- Handle non-contiguous arrays for onecell PM domain providers.
	- Rebased the Exynos patch to follow the new genpd API changes.


Changes in v2:
	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
	- Updated some comments in code and in commit messages.
	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
	- Rebased the ARM Exynos patch.
	- Added some Tested-by tags.


This patchset has a bit of a history and some parts of it has been posted
earlier.

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html

In the first revision I intentially didn't increase version number of the
patches, since I think it would have cause more confusion than clarity.

A summary of changes in V1 and since the last patchset, from the link above:
	- Instead of letting driver core handling the device to power domain
	binding/unbinding, follow the behavior of how the ACPI power domain
	is handled.


This is a summary of what these patches are intended to do:

1)
Add generic power domain OF-based support which also includes APIs to handle
attach/detach of generic power domains to devices.

2)
Adding a common API to attach/detach power domains and include support for the
ACPI and the generic power domain in there.

3)
>From subsystem level code, at probe/remove, convert from invoking the ACPI
specific power domain attach/detach functions to the new common attach/detach
APIs.

4)
Add support for the AMBA bus to attach/detach power domains, using the new
common APIs.

5)
Convert Exynos to use the new generic power domain OF support.

Obviously, there are dependencies througout this patchset, which means if they
get accepted the all need to go together. It might also be convenient to share
them through an immutable branch.


Tomasz Figa (2):
  PM / Domains: Add generic OF-based PM domain look-up
  ARM: exynos: Move to generic PM domain DT bindings

Ulf Hansson (7):
  ACPI / PM: Let acpi_dev_pm_detach() return an error code
  PM / Domains: Add APIs to attach/detach a PM domain for a device
  drivercore / platform: Convert to dev_pm_domain_attach|detach()
  i2c: core: Convert to dev_pm_domain_attach|detach()
  mmc: sdio: Convert to dev_pm_domain_attach|detach()
  spi: core: Convert to dev_pm_domain_attach|detach()
  amba: Add support for attach/detach of PM domains

 .../bindings/arm/exynos/power_domain.txt           |  13 +-
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 arch/arm/mach-exynos/pm_domains.c                  |  78 +-----
 drivers/acpi/device_pm.c                           |   8 +-
 drivers/amba/bus.c                                 |  10 +-
 drivers/base/platform.c                            |  15 +-
 drivers/base/power/common.c                        |  56 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 drivers/i2c/i2c-core.c                             |  13 +-
 drivers/mmc/core/sdio_bus.c                        |   4 +-
 drivers/spi/spi.c                                  |  12 +-
 include/linux/acpi.h                               |   7 +-
 include/linux/pm.h                                 |  14 +
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 15 files changed, 524 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

-- 
1.9.1

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

* [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

To give callers the option of acting on a errors while removing the
pm_domain ops for the device in the ACPI PM domain, let
acpi_dev_pm_detach() return an int to provide the error code.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/acpi/device_pm.c | 8 +++++++-
 include/linux/acpi.h     | 7 +++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 67075f8..0d52ce1 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
  */
 int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
@@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
  */
-void acpi_dev_pm_detach(struct device *dev, bool power_off)
+int acpi_dev_pm_detach(struct device *dev, bool power_off)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
 
@@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
 			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
 			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
 		}
+		return 0;
 	}
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
 #endif /* CONFIG_PM */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 807cbc4..c83cca5 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
 #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
 struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
 int acpi_dev_pm_attach(struct device *dev, bool power_on);
-void acpi_dev_pm_detach(struct device *dev, bool power_off);
+int acpi_dev_pm_detach(struct device *dev, bool power_off);
 #else
 static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
 {
@@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
 	return -ENODEV;
 }
-static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
+static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
 #endif
 
 #ifdef CONFIG_ACPI
-- 
1.9.1


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

* [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

To give callers the option of acting on a errors while removing the
pm_domain ops for the device in the ACPI PM domain, let
acpi_dev_pm_detach() return an int to provide the error code.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/acpi/device_pm.c | 8 +++++++-
 include/linux/acpi.h     | 7 +++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 67075f8..0d52ce1 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
  */
 int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
@@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
  */
-void acpi_dev_pm_detach(struct device *dev, bool power_off)
+int acpi_dev_pm_detach(struct device *dev, bool power_off)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
 
@@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
 			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
 			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
 		}
+		return 0;
 	}
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
 #endif /* CONFIG_PM */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 807cbc4..c83cca5 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
 #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
 struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
 int acpi_dev_pm_attach(struct device *dev, bool power_on);
-void acpi_dev_pm_detach(struct device *dev, bool power_off);
+int acpi_dev_pm_detach(struct device *dev, bool power_off);
 #else
 static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
 {
@@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
 	return -ENODEV;
 }
-static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
+static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
 #endif
 
 #ifdef CONFIG_ACPI
-- 
1.9.1

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Tomasz Figa, Ulf Hansson

From: Tomasz Figa <t.figa@samsung.com>

This patch introduces generic code to perform PM domain look-up using
device tree and automatically bind devices to their PM domains.

Generic device tree bindings are introduced to specify PM domains of
devices in their device tree nodes.

Backwards compatibility with legacy Samsung-specific PM domain bindings
is provided, but for now the new code is not compiled when
CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
This will change as soon as the Exynos PM domain code gets converted to
use the generic framework in further patch.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
[Ulf:Added attach|detach functions, fixed review comments]
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 4 files changed, 401 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
new file mode 100644
index 0000000..98c1667
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -0,0 +1,49 @@
+* Generic PM domains
+
+System on chip designs are often divided into multiple PM domains that can be
+used for power gating of selected IP blocks for power saving by reduced leakage
+current.
+
+This device tree binding can be used to bind PM domain consumer devices with
+their PM domains provided by PM domain providers. A PM domain provider can be
+represented by any node in the device tree and can provide one or more PM
+domains. A consumer node can refer to the provider by a phandle and a set of
+phandle arguments (so called PM domain specifiers) of length specified by the
+#power-domain-cells property in the PM domain provider node.
+
+==PM domain providers==
+
+Required properties:
+ - #power-domain-cells : Number of cells in a PM domain specifier;
+   Typically 0 for nodes representing a single PM domain and 1 for nodes
+   providing multiple PM domains (e.g. power controllers), but can be any value
+   as specified by device tree binding documentation of particular provider.
+
+Example:
+
+	power: power-controller@12340000 {
+		compatible = "foo,power-controller";
+		reg = <0x12340000 0x1000>;
+		#power-domain-cells = <1>;
+	};
+
+The node above defines a power controller that is a PM domain provider and
+expects one cell as its phandle argument.
+
+==PM domain consumers==
+
+Required properties:
+ - power-domains : A phandle and PM domain specifier as defined by bindings of
+                   the power controller specified by phandle.
+
+Example:
+
+	leaky-device@12350000 {
+		compatible = "foo,i-leak-current";
+		reg = <0x12350000 0x1000>;
+		power-domains = <&power 0>;
+	};
+
+The node above defines a typical PM domain consumer device, which is located
+inside a PM domain with index 0 of a power controller represented by a node
+with the label "power".
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index eee55c1..ed42651 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -8,6 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_qos.h>
@@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 	list_add(&genpd->gpd_list_node, &gpd_list);
 	mutex_unlock(&gpd_list_lock);
 }
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+/*
+ * Device Tree based PM domain providers.
+ *
+ * The code below implements generic device tree based PM domain providers that
+ * bind device tree nodes with generic PM domains registered in the system.
+ *
+ * Any driver that registers generic PM domains and needs to support binding of
+ * devices to these domains is supposed to register a PM domain provider, which
+ * maps a PM domain specifier retrieved from the device tree to a PM domain.
+ *
+ * Two simple mapping functions have been provided for convenience:
+ *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
+ *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
+ *    index.
+ */
+
+/**
+ * struct of_genpd_provider - PM domain provider registration structure
+ * @link: Entry in global list of PM domain providers
+ * @node: Pointer to device tree node of PM domain provider
+ * @xlate: Provider-specific xlate callback mapping a set of specifier cells
+ *         into a PM domain.
+ * @data: context pointer to be passed into @xlate callback
+ */
+struct of_genpd_provider {
+	struct list_head link;
+	struct device_node *node;
+	genpd_xlate_t xlate;
+	void *data;
+};
+
+/* List of registered PM domain providers. */
+static LIST_HEAD(of_genpd_providers);
+/* Mutex to protect the list above. */
+static DEFINE_MUTEX(of_genpd_mutex);
+
+/**
+ * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct generic_pm_domain
+ *
+ * This is a generic xlate function that can be used to model PM domains that
+ * have their own device tree nodes. The private data of xlate function needs
+ * to be a valid pointer to struct generic_pm_domain.
+ */
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	if (genpdspec->args_count != 0)
+		return ERR_PTR(-EINVAL);
+	return data;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
+
+/**
+ * __of_genpd_xlate_onecell() - Xlate function using a single index.
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct genpd_onecell_data
+ *
+ * This is a generic xlate function that can be used to model simple PM domain
+ * controllers that have one device tree node and provide multiple PM domains.
+ * A single cell is used as an index into an array of PM domains specified in
+ * the genpd_onecell_data struct when registering the provider.
+ */
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	struct genpd_onecell_data *genpd_data = data;
+	unsigned int idx = genpdspec->args[0];
+
+	if (genpdspec->args_count != 1)
+		return ERR_PTR(-EINVAL);
+
+	if (idx >= genpd_data->num_domains) {
+		pr_err("%s: invalid domain index %u\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	if (!genpd_data->domains[idx])
+		return ERR_PTR(-ENOENT);
+
+	return genpd_data->domains[idx];
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
+
+/**
+ * __of_genpd_add_provider() - Register a PM domain provider for a node
+ * @np: Device node pointer associated with the PM domain provider.
+ * @xlate: Callback for decoding PM domain from phandle arguments.
+ * @data: Context pointer for @xlate callback.
+ */
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data)
+{
+	struct of_genpd_provider *cp;
+
+	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->xlate = xlate;
+
+	mutex_lock(&of_genpd_mutex);
+	list_add(&cp->link, &of_genpd_providers);
+	mutex_unlock(&of_genpd_mutex);
+	pr_debug("Added domain provider from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
+
+/**
+ * of_genpd_del_provider() - Remove a previously registered PM domain provider
+ * @np: Device node pointer associated with the PM domain provider
+ */
+void of_genpd_del_provider(struct device_node *np)
+{
+	struct of_genpd_provider *cp;
+
+	mutex_lock(&of_genpd_mutex);
+	list_for_each_entry(cp, &of_genpd_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_genpd_mutex);
+}
+EXPORT_SYMBOL_GPL(of_genpd_del_provider);
+
+/**
+ * of_genpd_get_from_provider() - Look-up PM domain
+ * @genpdspec: OF phandle args to use for look-up
+ *
+ * Looks for a PM domain provider under the node specified by @genpdspec and if
+ * found, uses xlate function of the provider to map phandle args to a PM
+ * domain.
+ *
+ * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
+ * on failure.
+ */
+static struct generic_pm_domain *of_genpd_get_from_provider(
+					struct of_phandle_args *genpdspec)
+{
+	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
+	struct of_genpd_provider *provider;
+
+	mutex_lock(&of_genpd_mutex);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_genpd_providers, link) {
+		if (provider->node == genpdspec->np)
+			genpd = provider->xlate(genpdspec, provider->data);
+		if (!IS_ERR(genpd))
+			break;
+	}
+
+	mutex_unlock(&of_genpd_mutex);
+
+	return genpd;
+}
+
+/**
+ * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
+ * @dev: Device to attach.
+ *
+ * Parse device's OF node to find a PM domain specifier. If such is found,
+ * attaches the device to retrieved pm_domain ops.
+ *
+ * Both generic and legacy Samsung-specific DT bindings are supported to keep
+ * backwards compatibility with existing DTBs.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int genpd_dev_pm_attach(struct device *dev)
+{
+	struct of_phandle_args pd_args;
+	struct generic_pm_domain *pd;
+	int ret;
+
+	if (!dev->of_node)
+		return -ENODEV;
+
+	if (dev->pm_domain)
+		return -EEXIST;
+
+	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
+					"#power-domain-cells", 0, &pd_args);
+	if (ret < 0) {
+		if (ret != -ENOENT)
+			return ret;
+
+		/*
+		 * Try legacy Samsung-specific bindings
+		 * (for backwards compatibility of DT ABI)
+		 */
+		pd_args.args_count = 0;
+		pd_args.np = of_parse_phandle(dev->of_node,
+						"samsung,power-domain", 0);
+		if (!pd_args.np)
+			return -ENOENT;
+	}
+
+	pd = of_genpd_get_from_provider(&pd_args);
+	if (IS_ERR(pd)) {
+		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
+			__func__, PTR_ERR(pd));
+		of_node_put(dev->of_node);
+		return PTR_ERR(pd);
+	}
+
+	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_add_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to add to PM domain %s: %d",
+			pd->name, ret);
+		of_node_put(dev->of_node);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
+
+/**
+ * genpd_dev_pm_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ *
+ * Try to locate a corresponding generic PM domain, which the device was
+ * attached to previously. If such is found, the device is detached from it.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int genpd_dev_pm_detach(struct device *dev)
+{
+	struct generic_pm_domain *pd = NULL, *gpd;
+	int ret = 0;
+
+	if (!dev->pm_domain)
+		return -ENODEV;
+
+	mutex_lock(&gpd_list_lock);
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
+		if (&gpd->domain == dev->pm_domain) {
+			pd = gpd;
+			break;
+		}
+	}
+	mutex_unlock(&gpd_list_lock);
+
+	if (!pd)
+		return -ENOENT;
+
+	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_remove_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to remove from PM domain %s: %d",
+			pd->name, ret);
+		return ret;
+	}
+
+	/* Check if PM domain can be powered off after removing this device. */
+	genpd_queue_power_off_work(pd);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
+#endif
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ebc4c76..b09eaa7 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
 	pm_genpd_syscore_switch(dev, false);
 }
 
+/* OF PM domain providers */
+struct of_device_id;
+
+struct genpd_onecell_data {
+	struct generic_pm_domain **domains;
+	unsigned int num_domains;
+};
+
+typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
+						void *data);
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data);
+void of_genpd_del_provider(struct device_node *np);
+
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data);
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data);
+
+int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_detach(struct device *dev);
+#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
+static inline int __of_genpd_add_provider(struct device_node *np,
+					genpd_xlate_t xlate, void *data)
+{
+	return 0;
+}
+static inline void of_genpd_del_provider(struct device_node *np) {}
+
+#define __of_genpd_xlate_simple		NULL
+#define __of_genpd_xlate_onecell	NULL
+
+static inline int genpd_dev_pm_attach(struct device *dev)
+{
+	return -ENODEV;
+}
+static inline int genpd_dev_pm_detach(struct device *dev)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
+
+static inline int of_genpd_add_provider_simple(struct device_node *np,
+					struct generic_pm_domain *genpd)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
+}
+static inline int of_genpd_add_provider_onecell(struct device_node *np,
+					struct genpd_onecell_data *data)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
+}
+
 #endif /* _LINUX_PM_DOMAIN_H */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index e4e4121..897619b 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
 	def_bool y
 	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
 
+config PM_GENERIC_DOMAINS_OF
+	def_bool y
+	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+
 config CPU_PM
 	bool
 	depends on SUSPEND || CPU_IDLE
-- 
1.9.1


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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Tomasz Figa <t.figa@samsung.com>

This patch introduces generic code to perform PM domain look-up using
device tree and automatically bind devices to their PM domains.

Generic device tree bindings are introduced to specify PM domains of
devices in their device tree nodes.

Backwards compatibility with legacy Samsung-specific PM domain bindings
is provided, but for now the new code is not compiled when
CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
This will change as soon as the Exynos PM domain code gets converted to
use the generic framework in further patch.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
[Ulf:Added attach|detach functions, fixed review comments]
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 4 files changed, 401 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
new file mode 100644
index 0000000..98c1667
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -0,0 +1,49 @@
+* Generic PM domains
+
+System on chip designs are often divided into multiple PM domains that can be
+used for power gating of selected IP blocks for power saving by reduced leakage
+current.
+
+This device tree binding can be used to bind PM domain consumer devices with
+their PM domains provided by PM domain providers. A PM domain provider can be
+represented by any node in the device tree and can provide one or more PM
+domains. A consumer node can refer to the provider by a phandle and a set of
+phandle arguments (so called PM domain specifiers) of length specified by the
+#power-domain-cells property in the PM domain provider node.
+
+==PM domain providers==
+
+Required properties:
+ - #power-domain-cells : Number of cells in a PM domain specifier;
+   Typically 0 for nodes representing a single PM domain and 1 for nodes
+   providing multiple PM domains (e.g. power controllers), but can be any value
+   as specified by device tree binding documentation of particular provider.
+
+Example:
+
+	power: power-controller at 12340000 {
+		compatible = "foo,power-controller";
+		reg = <0x12340000 0x1000>;
+		#power-domain-cells = <1>;
+	};
+
+The node above defines a power controller that is a PM domain provider and
+expects one cell as its phandle argument.
+
+==PM domain consumers==
+
+Required properties:
+ - power-domains : A phandle and PM domain specifier as defined by bindings of
+                   the power controller specified by phandle.
+
+Example:
+
+	leaky-device at 12350000 {
+		compatible = "foo,i-leak-current";
+		reg = <0x12350000 0x1000>;
+		power-domains = <&power 0>;
+	};
+
+The node above defines a typical PM domain consumer device, which is located
+inside a PM domain with index 0 of a power controller represented by a node
+with the label "power".
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index eee55c1..ed42651 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -8,6 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_qos.h>
@@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 	list_add(&genpd->gpd_list_node, &gpd_list);
 	mutex_unlock(&gpd_list_lock);
 }
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+/*
+ * Device Tree based PM domain providers.
+ *
+ * The code below implements generic device tree based PM domain providers that
+ * bind device tree nodes with generic PM domains registered in the system.
+ *
+ * Any driver that registers generic PM domains and needs to support binding of
+ * devices to these domains is supposed to register a PM domain provider, which
+ * maps a PM domain specifier retrieved from the device tree to a PM domain.
+ *
+ * Two simple mapping functions have been provided for convenience:
+ *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
+ *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
+ *    index.
+ */
+
+/**
+ * struct of_genpd_provider - PM domain provider registration structure
+ * @link: Entry in global list of PM domain providers
+ * @node: Pointer to device tree node of PM domain provider
+ * @xlate: Provider-specific xlate callback mapping a set of specifier cells
+ *         into a PM domain.
+ * @data: context pointer to be passed into @xlate callback
+ */
+struct of_genpd_provider {
+	struct list_head link;
+	struct device_node *node;
+	genpd_xlate_t xlate;
+	void *data;
+};
+
+/* List of registered PM domain providers. */
+static LIST_HEAD(of_genpd_providers);
+/* Mutex to protect the list above. */
+static DEFINE_MUTEX(of_genpd_mutex);
+
+/**
+ * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct generic_pm_domain
+ *
+ * This is a generic xlate function that can be used to model PM domains that
+ * have their own device tree nodes. The private data of xlate function needs
+ * to be a valid pointer to struct generic_pm_domain.
+ */
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	if (genpdspec->args_count != 0)
+		return ERR_PTR(-EINVAL);
+	return data;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
+
+/**
+ * __of_genpd_xlate_onecell() - Xlate function using a single index.
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct genpd_onecell_data
+ *
+ * This is a generic xlate function that can be used to model simple PM domain
+ * controllers that have one device tree node and provide multiple PM domains.
+ * A single cell is used as an index into an array of PM domains specified in
+ * the genpd_onecell_data struct when registering the provider.
+ */
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	struct genpd_onecell_data *genpd_data = data;
+	unsigned int idx = genpdspec->args[0];
+
+	if (genpdspec->args_count != 1)
+		return ERR_PTR(-EINVAL);
+
+	if (idx >= genpd_data->num_domains) {
+		pr_err("%s: invalid domain index %u\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	if (!genpd_data->domains[idx])
+		return ERR_PTR(-ENOENT);
+
+	return genpd_data->domains[idx];
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
+
+/**
+ * __of_genpd_add_provider() - Register a PM domain provider for a node
+ * @np: Device node pointer associated with the PM domain provider.
+ * @xlate: Callback for decoding PM domain from phandle arguments.
+ * @data: Context pointer for @xlate callback.
+ */
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data)
+{
+	struct of_genpd_provider *cp;
+
+	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->xlate = xlate;
+
+	mutex_lock(&of_genpd_mutex);
+	list_add(&cp->link, &of_genpd_providers);
+	mutex_unlock(&of_genpd_mutex);
+	pr_debug("Added domain provider from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
+
+/**
+ * of_genpd_del_provider() - Remove a previously registered PM domain provider
+ * @np: Device node pointer associated with the PM domain provider
+ */
+void of_genpd_del_provider(struct device_node *np)
+{
+	struct of_genpd_provider *cp;
+
+	mutex_lock(&of_genpd_mutex);
+	list_for_each_entry(cp, &of_genpd_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_genpd_mutex);
+}
+EXPORT_SYMBOL_GPL(of_genpd_del_provider);
+
+/**
+ * of_genpd_get_from_provider() - Look-up PM domain
+ * @genpdspec: OF phandle args to use for look-up
+ *
+ * Looks for a PM domain provider under the node specified by @genpdspec and if
+ * found, uses xlate function of the provider to map phandle args to a PM
+ * domain.
+ *
+ * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
+ * on failure.
+ */
+static struct generic_pm_domain *of_genpd_get_from_provider(
+					struct of_phandle_args *genpdspec)
+{
+	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
+	struct of_genpd_provider *provider;
+
+	mutex_lock(&of_genpd_mutex);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_genpd_providers, link) {
+		if (provider->node == genpdspec->np)
+			genpd = provider->xlate(genpdspec, provider->data);
+		if (!IS_ERR(genpd))
+			break;
+	}
+
+	mutex_unlock(&of_genpd_mutex);
+
+	return genpd;
+}
+
+/**
+ * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
+ * @dev: Device to attach.
+ *
+ * Parse device's OF node to find a PM domain specifier. If such is found,
+ * attaches the device to retrieved pm_domain ops.
+ *
+ * Both generic and legacy Samsung-specific DT bindings are supported to keep
+ * backwards compatibility with existing DTBs.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int genpd_dev_pm_attach(struct device *dev)
+{
+	struct of_phandle_args pd_args;
+	struct generic_pm_domain *pd;
+	int ret;
+
+	if (!dev->of_node)
+		return -ENODEV;
+
+	if (dev->pm_domain)
+		return -EEXIST;
+
+	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
+					"#power-domain-cells", 0, &pd_args);
+	if (ret < 0) {
+		if (ret != -ENOENT)
+			return ret;
+
+		/*
+		 * Try legacy Samsung-specific bindings
+		 * (for backwards compatibility of DT ABI)
+		 */
+		pd_args.args_count = 0;
+		pd_args.np = of_parse_phandle(dev->of_node,
+						"samsung,power-domain", 0);
+		if (!pd_args.np)
+			return -ENOENT;
+	}
+
+	pd = of_genpd_get_from_provider(&pd_args);
+	if (IS_ERR(pd)) {
+		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
+			__func__, PTR_ERR(pd));
+		of_node_put(dev->of_node);
+		return PTR_ERR(pd);
+	}
+
+	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_add_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to add to PM domain %s: %d",
+			pd->name, ret);
+		of_node_put(dev->of_node);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
+
+/**
+ * genpd_dev_pm_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ *
+ * Try to locate a corresponding generic PM domain, which the device was
+ * attached to previously. If such is found, the device is detached from it.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int genpd_dev_pm_detach(struct device *dev)
+{
+	struct generic_pm_domain *pd = NULL, *gpd;
+	int ret = 0;
+
+	if (!dev->pm_domain)
+		return -ENODEV;
+
+	mutex_lock(&gpd_list_lock);
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
+		if (&gpd->domain == dev->pm_domain) {
+			pd = gpd;
+			break;
+		}
+	}
+	mutex_unlock(&gpd_list_lock);
+
+	if (!pd)
+		return -ENOENT;
+
+	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_remove_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to remove from PM domain %s: %d",
+			pd->name, ret);
+		return ret;
+	}
+
+	/* Check if PM domain can be powered off after removing this device. */
+	genpd_queue_power_off_work(pd);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
+#endif
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ebc4c76..b09eaa7 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
 	pm_genpd_syscore_switch(dev, false);
 }
 
+/* OF PM domain providers */
+struct of_device_id;
+
+struct genpd_onecell_data {
+	struct generic_pm_domain **domains;
+	unsigned int num_domains;
+};
+
+typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
+						void *data);
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data);
+void of_genpd_del_provider(struct device_node *np);
+
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data);
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data);
+
+int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_detach(struct device *dev);
+#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
+static inline int __of_genpd_add_provider(struct device_node *np,
+					genpd_xlate_t xlate, void *data)
+{
+	return 0;
+}
+static inline void of_genpd_del_provider(struct device_node *np) {}
+
+#define __of_genpd_xlate_simple		NULL
+#define __of_genpd_xlate_onecell	NULL
+
+static inline int genpd_dev_pm_attach(struct device *dev)
+{
+	return -ENODEV;
+}
+static inline int genpd_dev_pm_detach(struct device *dev)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
+
+static inline int of_genpd_add_provider_simple(struct device_node *np,
+					struct generic_pm_domain *genpd)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
+}
+static inline int of_genpd_add_provider_onecell(struct device_node *np,
+					struct genpd_onecell_data *data)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
+}
+
 #endif /* _LINUX_PM_DOMAIN_H */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index e4e4121..897619b 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
 	def_bool y
 	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
 
+config PM_GENERIC_DOMAINS_OF
+	def_bool y
+	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+
 config CPU_PM
 	bool
 	depends on SUSPEND || CPU_IDLE
-- 
1.9.1

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

* [PATCH v3 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

To maintain scalability let's add common methods to attach and detach
a PM domain for a device, dev_pm_domain_attach|detach().

Typically dev_pm_domain_attach() shall be invoked from subsystem level
code at the probe phase to try to attach a device to its PM domain.
The reversed actions may be done a the remove phase and then by invoking
dev_pm_domain_detach().

The supported PM domains at this point are the ACPI and the generic
PM domains.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/base/power/common.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm.h          | 14 ++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index df2e5ee..9a86b16 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -11,6 +11,8 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/pm_clock.h>
+#include <linux/acpi.h>
+#include <linux/pm_domain.h>
 
 /**
  * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
@@ -82,3 +84,57 @@ int dev_pm_put_subsys_data(struct device *dev)
 	return ret;
 }
 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.
+ *
+ * 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.
+ *
+ * This function should typically be invoked from subsystem level code during
+ * the probe phase. Especially for those that holds devices which requires
+ * power management through PM domains.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	int ret;
+
+	ret = acpi_dev_pm_attach(dev, power_on);
+	if (!ret || ret == -EPROBE_DEFER)
+		return ret;
+
+	return genpd_dev_pm_attach(dev);
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
+
+/**
+ * dev_pm_domain_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ * @power_off: Used to indicate whether we should power off the device.
+ *
+ * The @dev may be attached to a PM domain. By iterating through the available
+ * alternatives we detach it from its PM domain.
+ *
+ * This functions will reverse the actions from dev_pm_domain_attach() and thus
+ * detach the @dev from its PM domain. Typically it should be invoked from
+ * subsystem level code during the remove phase.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	if (acpi_dev_pm_detach(dev, power_off))
+		return genpd_dev_pm_detach(dev);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 72c0fe0..8176b07 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -621,6 +621,20 @@ struct dev_pm_domain {
 	struct dev_pm_ops	ops;
 };
 
+#ifdef CONFIG_PM
+extern int dev_pm_domain_attach(struct device *dev, bool power_on);
+extern int dev_pm_domain_detach(struct device *dev, bool power_off);
+#else
+static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	return -ENODEV;
+}
+static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
+#endif
+
 /*
  * The PM_EVENT_ messages are also used by drivers implementing the legacy
  * suspend framework, based on the ->suspend() and ->resume() callbacks common
-- 
1.9.1


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

* [PATCH v3 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

To maintain scalability let's add common methods to attach and detach
a PM domain for a device, dev_pm_domain_attach|detach().

Typically dev_pm_domain_attach() shall be invoked from subsystem level
code at the probe phase to try to attach a device to its PM domain.
The reversed actions may be done a the remove phase and then by invoking
dev_pm_domain_detach().

The supported PM domains at this point are the ACPI and the generic
PM domains.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/base/power/common.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm.h          | 14 ++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index df2e5ee..9a86b16 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -11,6 +11,8 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/pm_clock.h>
+#include <linux/acpi.h>
+#include <linux/pm_domain.h>
 
 /**
  * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
@@ -82,3 +84,57 @@ int dev_pm_put_subsys_data(struct device *dev)
 	return ret;
 }
 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.
+ *
+ * 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.
+ *
+ * This function should typically be invoked from subsystem level code during
+ * the probe phase. Especially for those that holds devices which requires
+ * power management through PM domains.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	int ret;
+
+	ret = acpi_dev_pm_attach(dev, power_on);
+	if (!ret || ret == -EPROBE_DEFER)
+		return ret;
+
+	return genpd_dev_pm_attach(dev);
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
+
+/**
+ * dev_pm_domain_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ * @power_off: Used to indicate whether we should power off the device.
+ *
+ * The @dev may be attached to a PM domain. By iterating through the available
+ * alternatives we detach it from its PM domain.
+ *
+ * This functions will reverse the actions from dev_pm_domain_attach() and thus
+ * detach the @dev from its PM domain. Typically it should be invoked from
+ * subsystem level code during the remove phase.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	if (acpi_dev_pm_detach(dev, power_off))
+		return genpd_dev_pm_detach(dev);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 72c0fe0..8176b07 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -621,6 +621,20 @@ struct dev_pm_domain {
 	struct dev_pm_ops	ops;
 };
 
+#ifdef CONFIG_PM
+extern int dev_pm_domain_attach(struct device *dev, bool power_on);
+extern int dev_pm_domain_detach(struct device *dev, bool power_off);
+#else
+static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	return -ENODEV;
+}
+static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
+#endif
+
 /*
  * The PM_EVENT_ messages are also used by drivers implementing the legacy
  * suspend framework, based on the ->suspend() and ->resume() callbacks common
-- 
1.9.1

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

* [PATCH v3 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

Previously only the ACPI PM domain was supported by the platform bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/base/platform.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ab4f4ce..904be3d 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	acpi_dev_pm_attach(_dev, true);
-
-	ret = drv->probe(dev);
-	if (ret)
-		acpi_dev_pm_detach(_dev, true);
+	ret = dev_pm_domain_attach(_dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = drv->probe(dev);
+		if (ret)
+			dev_pm_domain_detach(_dev, true);
+	}
 
 	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
 		dev_warn(_dev, "probe deferral not supported\n");
@@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
 	int ret;
 
 	ret = drv->remove(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 
 	return ret;
 }
@@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 
 	drv->shutdown(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 }
 
 /**
-- 
1.9.1


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

* [PATCH v3 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the platform bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/base/platform.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ab4f4ce..904be3d 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	acpi_dev_pm_attach(_dev, true);
-
-	ret = drv->probe(dev);
-	if (ret)
-		acpi_dev_pm_detach(_dev, true);
+	ret = dev_pm_domain_attach(_dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = drv->probe(dev);
+		if (ret)
+			dev_pm_domain_detach(_dev, true);
+	}
 
 	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
 		dev_warn(_dev, "probe deferral not supported\n");
@@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
 	int ret;
 
 	ret = drv->remove(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 
 	return ret;
 }
@@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 
 	drv->shutdown(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 }
 
 /**
-- 
1.9.1

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

* [PATCH v3 5/9] i2c: core: Convert to dev_pm_domain_attach|detach()
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-i2c

Previously only the ACPI PM domain was supported by the i2c bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-i2c@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/i2c/i2c-core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 632057a..3cd8f11 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -279,10 +279,13 @@ static int i2c_device_probe(struct device *dev)
 	if (status < 0)
 		return status;
 
-	acpi_dev_pm_attach(&client->dev, true);
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
-	if (status)
-		acpi_dev_pm_detach(&client->dev, true);
+	status = dev_pm_domain_attach(&client->dev, true);
+	if (status != -EPROBE_DEFER) {
+		status = driver->probe(client, i2c_match_id(driver->id_table,
+					client));
+		if (status)
+			dev_pm_domain_detach(&client->dev, true);
+	}
 
 	return status;
 }
@@ -302,7 +305,7 @@ static int i2c_device_remove(struct device *dev)
 		status = driver->remove(client);
 	}
 
-	acpi_dev_pm_detach(&client->dev, true);
+	dev_pm_domain_detach(&client->dev, true);
 	return status;
 }
 
-- 
1.9.1


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

* [PATCH v3 5/9] i2c: core: Convert to dev_pm_domain_attach|detach()
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the i2c bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-i2c at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/i2c/i2c-core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 632057a..3cd8f11 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -279,10 +279,13 @@ static int i2c_device_probe(struct device *dev)
 	if (status < 0)
 		return status;
 
-	acpi_dev_pm_attach(&client->dev, true);
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
-	if (status)
-		acpi_dev_pm_detach(&client->dev, true);
+	status = dev_pm_domain_attach(&client->dev, true);
+	if (status != -EPROBE_DEFER) {
+		status = driver->probe(client, i2c_match_id(driver->id_table,
+					client));
+		if (status)
+			dev_pm_domain_detach(&client->dev, true);
+	}
 
 	return status;
 }
@@ -302,7 +305,7 @@ static int i2c_device_remove(struct device *dev)
 		status = driver->remove(client);
 	}
 
-	acpi_dev_pm_detach(&client->dev, true);
+	dev_pm_domain_detach(&client->dev, true);
 	return status;
 }
 
-- 
1.9.1

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

* [PATCH v3 6/9] mmc: sdio: Convert to dev_pm_domain_attach|detach()
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-mmc

Previously only the ACPI PM domain was supported by the sdio bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-mmc@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/core/sdio_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 4fa8fef9..1df0fc6 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -315,7 +315,7 @@ int sdio_add_func(struct sdio_func *func)
 	ret = device_add(&func->dev);
 	if (ret == 0) {
 		sdio_func_set_present(func);
-		acpi_dev_pm_attach(&func->dev, false);
+		dev_pm_domain_attach(&func->dev, false);
 	}
 
 	return ret;
@@ -332,7 +332,7 @@ void sdio_remove_func(struct sdio_func *func)
 	if (!sdio_func_present(func))
 		return;
 
-	acpi_dev_pm_detach(&func->dev, false);
+	dev_pm_domain_detach(&func->dev, false);
 	device_del(&func->dev);
 	put_device(&func->dev);
 }
-- 
1.9.1


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

* [PATCH v3 6/9] mmc: sdio: Convert to dev_pm_domain_attach|detach()
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the sdio bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-mmc at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/core/sdio_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 4fa8fef9..1df0fc6 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -315,7 +315,7 @@ int sdio_add_func(struct sdio_func *func)
 	ret = device_add(&func->dev);
 	if (ret == 0) {
 		sdio_func_set_present(func);
-		acpi_dev_pm_attach(&func->dev, false);
+		dev_pm_domain_attach(&func->dev, false);
 	}
 
 	return ret;
@@ -332,7 +332,7 @@ void sdio_remove_func(struct sdio_func *func)
 	if (!sdio_func_present(func))
 		return;
 
-	acpi_dev_pm_detach(&func->dev, false);
+	dev_pm_domain_detach(&func->dev, false);
 	device_del(&func->dev);
 	put_device(&func->dev);
 }
-- 
1.9.1

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

* [PATCH v3 7/9] spi: core: Convert to dev_pm_domain_attach|detach()
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-spi

Previously only the ACPI PM domain was supported by the spi bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-spi@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/spi/spi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ca935df..72a0beb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -264,10 +264,12 @@ static int spi_drv_probe(struct device *dev)
 	if (ret)
 		return ret;
 
-	acpi_dev_pm_attach(dev, true);
-	ret = sdrv->probe(to_spi_device(dev));
-	if (ret)
-		acpi_dev_pm_detach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = sdrv->probe(to_spi_device(dev));
+		if (ret)
+			dev_pm_domain_detach(dev, true);
+	}
 
 	return ret;
 }
@@ -278,7 +280,7 @@ static int spi_drv_remove(struct device *dev)
 	int ret;
 
 	ret = sdrv->remove(to_spi_device(dev));
-	acpi_dev_pm_detach(dev, true);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v3 7/9] spi: core: Convert to dev_pm_domain_attach|detach()
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the spi bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-spi at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/spi/spi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ca935df..72a0beb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -264,10 +264,12 @@ static int spi_drv_probe(struct device *dev)
 	if (ret)
 		return ret;
 
-	acpi_dev_pm_attach(dev, true);
-	ret = sdrv->probe(to_spi_device(dev));
-	if (ret)
-		acpi_dev_pm_detach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = sdrv->probe(to_spi_device(dev));
+		if (ret)
+			dev_pm_domain_detach(dev, true);
+	}
 
 	return ret;
 }
@@ -278,7 +280,7 @@ static int spi_drv_remove(struct device *dev)
 	int ret;
 
 	ret = sdrv->remove(to_spi_device(dev));
-	acpi_dev_pm_detach(dev, true);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1

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

* [PATCH v3 8/9] amba: Add support for attach/detach of PM domains
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

AMBA devices may on some SoCs resides in PM domains. To be able to
manage these devices from there, let's try to attach devices to their
corresponding PM domain during the probe phase.

To reverse these actions at the remove phase, we try to detach the
device from its PM domain.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/amba/bus.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3cf61a1..8f52393 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -182,9 +182,15 @@ static int amba_probe(struct device *dev)
 	int ret;
 
 	do {
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret == -EPROBE_DEFER)
+			break;
+
 		ret = amba_get_enable_pclk(pcdev);
-		if (ret)
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
 			break;
+		}
 
 		pm_runtime_get_noresume(dev);
 		pm_runtime_set_active(dev);
@@ -199,6 +205,7 @@ static int amba_probe(struct device *dev)
 		pm_runtime_put_noidle(dev);
 
 		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
 	} while (0);
 
 	return ret;
@@ -220,6 +227,7 @@ static int amba_remove(struct device *dev)
 	pm_runtime_put_noidle(dev);
 
 	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v3 8/9] amba: Add support for attach/detach of PM domains
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

AMBA devices may on some SoCs resides in PM domains. To be able to
manage these devices from there, let's try to attach devices to their
corresponding PM domain during the probe phase.

To reverse these actions at the remove phase, we try to detach the
device from its PM domain.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/amba/bus.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3cf61a1..8f52393 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -182,9 +182,15 @@ static int amba_probe(struct device *dev)
 	int ret;
 
 	do {
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret == -EPROBE_DEFER)
+			break;
+
 		ret = amba_get_enable_pclk(pcdev);
-		if (ret)
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
 			break;
+		}
 
 		pm_runtime_get_noresume(dev);
 		pm_runtime_set_active(dev);
@@ -199,6 +205,7 @@ static int amba_probe(struct device *dev)
 		pm_runtime_put_noidle(dev);
 
 		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
 	} while (0);
 
 	return ret;
@@ -220,6 +227,7 @@ static int amba_remove(struct device *dev)
 	pm_runtime_put_noidle(dev);
 
 	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1

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

* [PATCH v3 9/9] ARM: exynos: Move to generic PM domain DT bindings
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-04 13:52   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Tomasz Figa, linux-samsung-soc,
	Ulf Hansson

From: Tomasz Figa <t.figa@samsung.com>

This patch moves Exynos PM domain code to use the new generic PM domain
look-up framework introduced in previous patches, thus also allowing
the new code to be compiled with CONFIG_ARCH_EXYNOS.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Cc: linux-samsung-soc@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
[Ulf:Rebased and resolved conflicts]
---
 .../bindings/arm/exynos/power_domain.txt           | 13 ++--
 arch/arm/mach-exynos/pm_domains.c                  | 78 +---------------------
 kernel/power/Kconfig                               |  2 +-
 3 files changed, 8 insertions(+), 85 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
index 8b4f7b7f..abde1ea 100644
--- a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
+++ b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
@@ -8,6 +8,8 @@ Required Properties:
     * samsung,exynos4210-pd - for exynos4210 type power domain.
 - reg: physical base address of the controller and length of memory mapped
     region.
+- #power-domain-cells: number of cells in power domain specifier;
+    must be 0.
 
 Optional Properties:
 - clocks: List of clock handles. The parent clocks of the input clocks to the
@@ -29,6 +31,7 @@ Example:
 	lcd0: power-domain-lcd0 {
 		compatible = "samsung,exynos4210-pd";
 		reg = <0x10023C00 0x10>;
+		#power-domain-cells = <0>;
 	};
 
 	mfc_pd: power-domain@10044060 {
@@ -37,12 +40,8 @@ Example:
 		clocks = <&clock CLK_FIN_PLL>, <&clock CLK_MOUT_SW_ACLK333>,
 			<&clock CLK_MOUT_USER_ACLK333>;
 		clock-names = "oscclk", "pclk0", "clk0";
+		#power-domain-cells = <0>;
 	};
 
-Example of the node using power domain:
-
-	node {
-		/* ... */
-		samsung,power-domain = <&lcd0>;
-		/* ... */
-	};
+See Documentation/devicetree/bindings/power/power_domain.txt for description
+of consumer-side bindings.
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index fd76e1b..20f2671 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -105,78 +105,6 @@ static int exynos_pd_power_off(struct generic_pm_domain *domain)
 	return exynos_pd_power(domain, false);
 }
 
-static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
-					 struct device *dev)
-{
-	int ret;
-
-	dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
-
-	while (1) {
-		ret = pm_genpd_add_device(&pd->pd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-
-	pm_genpd_dev_need_restore(dev, true);
-}
-
-static void exynos_remove_device_from_domain(struct device *dev)
-{
-	struct generic_pm_domain *genpd = dev_to_genpd(dev);
-	int ret;
-
-	dev_dbg(dev, "removing from power domain %s\n", genpd->name);
-
-	while (1) {
-		ret = pm_genpd_remove_device(genpd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-}
-
-static void exynos_read_domain_from_dt(struct device *dev)
-{
-	struct platform_device *pd_pdev;
-	struct exynos_pm_domain *pd;
-	struct device_node *node;
-
-	node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
-	if (!node)
-		return;
-	pd_pdev = of_find_device_by_node(node);
-	if (!pd_pdev)
-		return;
-	pd = platform_get_drvdata(pd_pdev);
-	exynos_add_device_to_domain(pd, dev);
-}
-
-static int exynos_pm_notifier_call(struct notifier_block *nb,
-				    unsigned long event, void *data)
-{
-	struct device *dev = data;
-
-	switch (event) {
-	case BUS_NOTIFY_BIND_DRIVER:
-		if (dev->of_node)
-			exynos_read_domain_from_dt(dev);
-
-		break;
-
-	case BUS_NOTIFY_UNBOUND_DRIVER:
-		exynos_remove_device_from_domain(dev);
-
-		break;
-	}
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block platform_nb = {
-	.notifier_call = exynos_pm_notifier_call,
-};
-
 static __init int exynos4_pm_init_power_domain(void)
 {
 	struct platform_device *pdev;
@@ -202,7 +130,6 @@ static __init int exynos4_pm_init_power_domain(void)
 		pd->base = of_iomap(np, 0);
 		pd->pd.power_off = exynos_pd_power_off;
 		pd->pd.power_on = exynos_pd_power_on;
-		pd->pd.of_node = np;
 
 		pd->oscclk = clk_get(dev, "oscclk");
 		if (IS_ERR(pd->oscclk))
@@ -228,15 +155,12 @@ static __init int exynos4_pm_init_power_domain(void)
 			clk_put(pd->oscclk);
 
 no_clk:
-		platform_set_drvdata(pdev, pd);
-
 		on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
 
 		pm_genpd_init(&pd->pd, NULL, !on);
+		of_genpd_add_provider_simple(np, &pd->pd);
 	}
 
-	bus_register_notifier(&platform_bus_type, &platform_nb);
-
 	return 0;
 }
 arch_initcall(exynos4_pm_init_power_domain);
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 897619b..bbef57f 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -304,7 +304,7 @@ config PM_GENERIC_DOMAINS_RUNTIME
 
 config PM_GENERIC_DOMAINS_OF
 	def_bool y
-	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+	depends on PM_GENERIC_DOMAINS && OF
 
 config CPU_PM
 	bool
-- 
1.9.1


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

* [PATCH v3 9/9] ARM: exynos: Move to generic PM domain DT bindings
@ 2014-09-04 13:52   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-04 13:52 UTC (permalink / raw)
  To: linux-arm-kernel

From: Tomasz Figa <t.figa@samsung.com>

This patch moves Exynos PM domain code to use the new generic PM domain
look-up framework introduced in previous patches, thus also allowing
the new code to be compiled with CONFIG_ARCH_EXYNOS.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Cc: linux-samsung-soc at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
[Ulf:Rebased and resolved conflicts]
---
 .../bindings/arm/exynos/power_domain.txt           | 13 ++--
 arch/arm/mach-exynos/pm_domains.c                  | 78 +---------------------
 kernel/power/Kconfig                               |  2 +-
 3 files changed, 8 insertions(+), 85 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
index 8b4f7b7f..abde1ea 100644
--- a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
+++ b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
@@ -8,6 +8,8 @@ Required Properties:
     * samsung,exynos4210-pd - for exynos4210 type power domain.
 - reg: physical base address of the controller and length of memory mapped
     region.
+- #power-domain-cells: number of cells in power domain specifier;
+    must be 0.
 
 Optional Properties:
 - clocks: List of clock handles. The parent clocks of the input clocks to the
@@ -29,6 +31,7 @@ Example:
 	lcd0: power-domain-lcd0 {
 		compatible = "samsung,exynos4210-pd";
 		reg = <0x10023C00 0x10>;
+		#power-domain-cells = <0>;
 	};
 
 	mfc_pd: power-domain at 10044060 {
@@ -37,12 +40,8 @@ Example:
 		clocks = <&clock CLK_FIN_PLL>, <&clock CLK_MOUT_SW_ACLK333>,
 			<&clock CLK_MOUT_USER_ACLK333>;
 		clock-names = "oscclk", "pclk0", "clk0";
+		#power-domain-cells = <0>;
 	};
 
-Example of the node using power domain:
-
-	node {
-		/* ... */
-		samsung,power-domain = <&lcd0>;
-		/* ... */
-	};
+See Documentation/devicetree/bindings/power/power_domain.txt for description
+of consumer-side bindings.
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index fd76e1b..20f2671 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -105,78 +105,6 @@ static int exynos_pd_power_off(struct generic_pm_domain *domain)
 	return exynos_pd_power(domain, false);
 }
 
-static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
-					 struct device *dev)
-{
-	int ret;
-
-	dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
-
-	while (1) {
-		ret = pm_genpd_add_device(&pd->pd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-
-	pm_genpd_dev_need_restore(dev, true);
-}
-
-static void exynos_remove_device_from_domain(struct device *dev)
-{
-	struct generic_pm_domain *genpd = dev_to_genpd(dev);
-	int ret;
-
-	dev_dbg(dev, "removing from power domain %s\n", genpd->name);
-
-	while (1) {
-		ret = pm_genpd_remove_device(genpd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-}
-
-static void exynos_read_domain_from_dt(struct device *dev)
-{
-	struct platform_device *pd_pdev;
-	struct exynos_pm_domain *pd;
-	struct device_node *node;
-
-	node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
-	if (!node)
-		return;
-	pd_pdev = of_find_device_by_node(node);
-	if (!pd_pdev)
-		return;
-	pd = platform_get_drvdata(pd_pdev);
-	exynos_add_device_to_domain(pd, dev);
-}
-
-static int exynos_pm_notifier_call(struct notifier_block *nb,
-				    unsigned long event, void *data)
-{
-	struct device *dev = data;
-
-	switch (event) {
-	case BUS_NOTIFY_BIND_DRIVER:
-		if (dev->of_node)
-			exynos_read_domain_from_dt(dev);
-
-		break;
-
-	case BUS_NOTIFY_UNBOUND_DRIVER:
-		exynos_remove_device_from_domain(dev);
-
-		break;
-	}
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block platform_nb = {
-	.notifier_call = exynos_pm_notifier_call,
-};
-
 static __init int exynos4_pm_init_power_domain(void)
 {
 	struct platform_device *pdev;
@@ -202,7 +130,6 @@ static __init int exynos4_pm_init_power_domain(void)
 		pd->base = of_iomap(np, 0);
 		pd->pd.power_off = exynos_pd_power_off;
 		pd->pd.power_on = exynos_pd_power_on;
-		pd->pd.of_node = np;
 
 		pd->oscclk = clk_get(dev, "oscclk");
 		if (IS_ERR(pd->oscclk))
@@ -228,15 +155,12 @@ static __init int exynos4_pm_init_power_domain(void)
 			clk_put(pd->oscclk);
 
 no_clk:
-		platform_set_drvdata(pdev, pd);
-
 		on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
 
 		pm_genpd_init(&pd->pd, NULL, !on);
+		of_genpd_add_provider_simple(np, &pd->pd);
 	}
 
-	bus_register_notifier(&platform_bus_type, &platform_nb);
-
 	return 0;
 }
 arch_initcall(exynos4_pm_init_power_domain);
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 897619b..bbef57f 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -304,7 +304,7 @@ config PM_GENERIC_DOMAINS_RUNTIME
 
 config PM_GENERIC_DOMAINS_OF
 	def_bool y
-	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+	depends on PM_GENERIC_DOMAINS && OF
 
 config CPU_PM
 	bool
-- 
1.9.1

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

* Re: [PATCH v3 0/9] PM / Domains: Generic OF-based support
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-05 15:39   ` Kevin Hilman
  -1 siblings, 0 replies; 96+ messages in thread
From: Kevin Hilman @ 2014-09-05 15:39 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, linux-acpi, Geert Uytterhoeven,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King

Ulf Hansson <ulf.hansson@linaro.org> writes:

> Changes in v3:
> 	- Aligned on terminology, now using "PM domain" in comments and commit
> 	- messages/headers.
> 	- Improved English and grammar in comments and commit messages/headers.
> 	- Adopted proposal from Geert, to have compile-time-check wrapper
> 	  functions for the API that adds xlate_simple and xlate_onecell
> 	  providers.
>  	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
> 	- Handle non-contiguous arrays for onecell PM domain providers.
> 	- Rebased the Exynos patch to follow the new genpd API changes.
>
>
> Changes in v2:
> 	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
> 	- Updated some comments in code and in commit messages.
> 	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
> 	- Rebased the ARM Exynos patch.
> 	- Added some Tested-by tags.
>
>
> This patchset has a bit of a history and some parts of it has been posted
> earlier.
>
> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html
>
> In the first revision I intentially didn't increase version number of the
> patches, since I think it would have cause more confusion than clarity.
>
> A summary of changes in V1 and since the last patchset, from the link above:
> 	- Instead of letting driver core handling the device to power domain
> 	binding/unbinding, follow the behavior of how the ACPI power domain
> 	is handled.
>
>
> This is a summary of what these patches are intended to do:
>
> 1)
> Add generic power domain OF-based support which also includes APIs to handle
> attach/detach of generic power domains to devices.
>
> 2)
> Adding a common API to attach/detach power domains and include support for the
> ACPI and the generic power domain in there.
>
> 3)
> From subsystem level code, at probe/remove, convert from invoking the ACPI
> specific power domain attach/detach functions to the new common attach/detach
> APIs.
>
> 4)
> Add support for the AMBA bus to attach/detach power domains, using the new
> common APIs.
>
> 5)
> Convert Exynos to use the new generic power domain OF support.
>
> Obviously, there are dependencies througout this patchset, which means if they
> get accepted the all need to go together. It might also be convenient to share
> them through an immutable branch.

Reviewed-by: Kevin Hilman <khilman@linaro.org>

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

* [PATCH v3 0/9] PM / Domains: Generic OF-based support
@ 2014-09-05 15:39   ` Kevin Hilman
  0 siblings, 0 replies; 96+ messages in thread
From: Kevin Hilman @ 2014-09-05 15:39 UTC (permalink / raw)
  To: linux-arm-kernel

Ulf Hansson <ulf.hansson@linaro.org> writes:

> Changes in v3:
> 	- Aligned on terminology, now using "PM domain" in comments and commit
> 	- messages/headers.
> 	- Improved English and grammar in comments and commit messages/headers.
> 	- Adopted proposal from Geert, to have compile-time-check wrapper
> 	  functions for the API that adds xlate_simple and xlate_onecell
> 	  providers.
>  	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
> 	- Handle non-contiguous arrays for onecell PM domain providers.
> 	- Rebased the Exynos patch to follow the new genpd API changes.
>
>
> Changes in v2:
> 	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
> 	- Updated some comments in code and in commit messages.
> 	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
> 	- Rebased the ARM Exynos patch.
> 	- Added some Tested-by tags.
>
>
> This patchset has a bit of a history and some parts of it has been posted
> earlier.
>
> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html
>
> In the first revision I intentially didn't increase version number of the
> patches, since I think it would have cause more confusion than clarity.
>
> A summary of changes in V1 and since the last patchset, from the link above:
> 	- Instead of letting driver core handling the device to power domain
> 	binding/unbinding, follow the behavior of how the ACPI power domain
> 	is handled.
>
>
> This is a summary of what these patches are intended to do:
>
> 1)
> Add generic power domain OF-based support which also includes APIs to handle
> attach/detach of generic power domains to devices.
>
> 2)
> Adding a common API to attach/detach power domains and include support for the
> ACPI and the generic power domain in there.
>
> 3)
> From subsystem level code, at probe/remove, convert from invoking the ACPI
> specific power domain attach/detach functions to the new common attach/detach
> APIs.
>
> 4)
> Add support for the AMBA bus to attach/detach power domains, using the new
> common APIs.
>
> 5)
> Convert Exynos to use the new generic power domain OF support.
>
> Obviously, there are dependencies througout this patchset, which means if they
> get accepted the all need to go together. It might also be convenient to share
> them through an immutable branch.

Reviewed-by: Kevin Hilman <khilman@linaro.org>

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

* Re: [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-04 13:52   ` Ulf Hansson
@ 2014-09-07 22:12     ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-07 22:12 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King

On Thursday, September 04, 2014 03:52:28 PM Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

I can take this patch alone for 3.8 if that helps.

> ---
>  drivers/acpi/device_pm.c | 8 +++++++-
>  include/linux/acpi.h     | 7 +++++--
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
> index 67075f8..0d52ce1 100644
> --- a/drivers/acpi/device_pm.c
> +++ b/drivers/acpi/device_pm.c
> @@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
>   */
>  int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
> @@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
>   */
> -void acpi_dev_pm_detach(struct device *dev, bool power_off)
> +int acpi_dev_pm_detach(struct device *dev, bool power_off)
>  {
>  	struct acpi_device *adev = ACPI_COMPANION(dev);
>  
> @@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
>  			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
>  			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
>  		}
> +		return 0;
>  	}
> +	return -EINVAL;
>  }
>  EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
>  #endif /* CONFIG_PM */
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 807cbc4..c83cca5 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
>  #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
>  struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
>  int acpi_dev_pm_attach(struct device *dev, bool power_on);
> -void acpi_dev_pm_detach(struct device *dev, bool power_off);
> +int acpi_dev_pm_detach(struct device *dev, bool power_off);
>  #else
>  static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
>  {
> @@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
>  	return -ENODEV;
>  }
> -static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
> +static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
>  #endif
>  
>  #ifdef CONFIG_ACPI
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-07 22:12     ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-07 22:12 UTC (permalink / raw)
  To: linux-arm-kernel

On Thursday, September 04, 2014 03:52:28 PM Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

I can take this patch alone for 3.8 if that helps.

> ---
>  drivers/acpi/device_pm.c | 8 +++++++-
>  include/linux/acpi.h     | 7 +++++--
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
> index 67075f8..0d52ce1 100644
> --- a/drivers/acpi/device_pm.c
> +++ b/drivers/acpi/device_pm.c
> @@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
>   */
>  int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
> @@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
>   *
>   * Callers must ensure proper synchronization of this function with power
>   * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
>   */
> -void acpi_dev_pm_detach(struct device *dev, bool power_off)
> +int acpi_dev_pm_detach(struct device *dev, bool power_off)
>  {
>  	struct acpi_device *adev = ACPI_COMPANION(dev);
>  
> @@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
>  			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
>  			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
>  		}
> +		return 0;
>  	}
> +	return -EINVAL;
>  }
>  EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
>  #endif /* CONFIG_PM */
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 807cbc4..c83cca5 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
>  #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
>  struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
>  int acpi_dev_pm_attach(struct device *dev, bool power_on);
> -void acpi_dev_pm_detach(struct device *dev, bool power_off);
> +int acpi_dev_pm_detach(struct device *dev, bool power_off);
>  #else
>  static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
>  {
> @@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
>  {
>  	return -ENODEV;
>  }
> -static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
> +static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
>  #endif
>  
>  #ifdef CONFIG_ACPI
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-04 13:52   ` Ulf Hansson
@ 2014-09-07 22:13     ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-07 22:13 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Tomasz Figa

On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> From: Tomasz Figa <t.figa@samsung.com>
> 
> This patch introduces generic code to perform PM domain look-up using
> device tree and automatically bind devices to their PM domains.
> 
> Generic device tree bindings are introduced to specify PM domains of
> devices in their device tree nodes.
> 
> Backwards compatibility with legacy Samsung-specific PM domain bindings
> is provided, but for now the new code is not compiled when
> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> This will change as soon as the Exynos PM domain code gets converted to
> use the generic framework in further patch.
> 
> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> [Ulf:Added attach|detach functions, fixed review comments]
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

However, for this one (and consequently the rest) I need an ACK from the
people who maintain the bindings.

> ---
>  .../devicetree/bindings/power/power_domain.txt     |  49 ++++
>  drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
>  include/linux/pm_domain.h                          |  57 ++++
>  kernel/power/Kconfig                               |   4 +
>  4 files changed, 401 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt
> 
> diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
> new file mode 100644
> index 0000000..98c1667
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/power_domain.txt
> @@ -0,0 +1,49 @@
> +* Generic PM domains
> +
> +System on chip designs are often divided into multiple PM domains that can be
> +used for power gating of selected IP blocks for power saving by reduced leakage
> +current.
> +
> +This device tree binding can be used to bind PM domain consumer devices with
> +their PM domains provided by PM domain providers. A PM domain provider can be
> +represented by any node in the device tree and can provide one or more PM
> +domains. A consumer node can refer to the provider by a phandle and a set of
> +phandle arguments (so called PM domain specifiers) of length specified by the
> +#power-domain-cells property in the PM domain provider node.
> +
> +==PM domain providers==
> +
> +Required properties:
> + - #power-domain-cells : Number of cells in a PM domain specifier;
> +   Typically 0 for nodes representing a single PM domain and 1 for nodes
> +   providing multiple PM domains (e.g. power controllers), but can be any value
> +   as specified by device tree binding documentation of particular provider.
> +
> +Example:
> +
> +	power: power-controller@12340000 {
> +		compatible = "foo,power-controller";
> +		reg = <0x12340000 0x1000>;
> +		#power-domain-cells = <1>;
> +	};
> +
> +The node above defines a power controller that is a PM domain provider and
> +expects one cell as its phandle argument.
> +
> +==PM domain consumers==
> +
> +Required properties:
> + - power-domains : A phandle and PM domain specifier as defined by bindings of
> +                   the power controller specified by phandle.
> +
> +Example:
> +
> +	leaky-device@12350000 {
> +		compatible = "foo,i-leak-current";
> +		reg = <0x12350000 0x1000>;
> +		power-domains = <&power 0>;
> +	};
> +
> +The node above defines a typical PM domain consumer device, which is located
> +inside a PM domain with index 0 of a power controller represented by a node
> +with the label "power".
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index eee55c1..ed42651 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -8,6 +8,7 @@
>  
>  #include <linux/kernel.h>
>  #include <linux/io.h>
> +#include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/pm_domain.h>
>  #include <linux/pm_qos.h>
> @@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>  	list_add(&genpd->gpd_list_node, &gpd_list);
>  	mutex_unlock(&gpd_list_lock);
>  }
> +
> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
> +/*
> + * Device Tree based PM domain providers.
> + *
> + * The code below implements generic device tree based PM domain providers that
> + * bind device tree nodes with generic PM domains registered in the system.
> + *
> + * Any driver that registers generic PM domains and needs to support binding of
> + * devices to these domains is supposed to register a PM domain provider, which
> + * maps a PM domain specifier retrieved from the device tree to a PM domain.
> + *
> + * Two simple mapping functions have been provided for convenience:
> + *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
> + *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
> + *    index.
> + */
> +
> +/**
> + * struct of_genpd_provider - PM domain provider registration structure
> + * @link: Entry in global list of PM domain providers
> + * @node: Pointer to device tree node of PM domain provider
> + * @xlate: Provider-specific xlate callback mapping a set of specifier cells
> + *         into a PM domain.
> + * @data: context pointer to be passed into @xlate callback
> + */
> +struct of_genpd_provider {
> +	struct list_head link;
> +	struct device_node *node;
> +	genpd_xlate_t xlate;
> +	void *data;
> +};
> +
> +/* List of registered PM domain providers. */
> +static LIST_HEAD(of_genpd_providers);
> +/* Mutex to protect the list above. */
> +static DEFINE_MUTEX(of_genpd_mutex);
> +
> +/**
> + * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
> + * @genpdspec: OF phandle args to map into a PM domain
> + * @data: xlate function private data - pointer to struct generic_pm_domain
> + *
> + * This is a generic xlate function that can be used to model PM domains that
> + * have their own device tree nodes. The private data of xlate function needs
> + * to be a valid pointer to struct generic_pm_domain.
> + */
> +struct generic_pm_domain *__of_genpd_xlate_simple(
> +					struct of_phandle_args *genpdspec,
> +					void *data)
> +{
> +	if (genpdspec->args_count != 0)
> +		return ERR_PTR(-EINVAL);
> +	return data;
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
> +
> +/**
> + * __of_genpd_xlate_onecell() - Xlate function using a single index.
> + * @genpdspec: OF phandle args to map into a PM domain
> + * @data: xlate function private data - pointer to struct genpd_onecell_data
> + *
> + * This is a generic xlate function that can be used to model simple PM domain
> + * controllers that have one device tree node and provide multiple PM domains.
> + * A single cell is used as an index into an array of PM domains specified in
> + * the genpd_onecell_data struct when registering the provider.
> + */
> +struct generic_pm_domain *__of_genpd_xlate_onecell(
> +					struct of_phandle_args *genpdspec,
> +					void *data)
> +{
> +	struct genpd_onecell_data *genpd_data = data;
> +	unsigned int idx = genpdspec->args[0];
> +
> +	if (genpdspec->args_count != 1)
> +		return ERR_PTR(-EINVAL);
> +
> +	if (idx >= genpd_data->num_domains) {
> +		pr_err("%s: invalid domain index %u\n", __func__, idx);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	if (!genpd_data->domains[idx])
> +		return ERR_PTR(-ENOENT);
> +
> +	return genpd_data->domains[idx];
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
> +
> +/**
> + * __of_genpd_add_provider() - Register a PM domain provider for a node
> + * @np: Device node pointer associated with the PM domain provider.
> + * @xlate: Callback for decoding PM domain from phandle arguments.
> + * @data: Context pointer for @xlate callback.
> + */
> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
> +			void *data)
> +{
> +	struct of_genpd_provider *cp;
> +
> +	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
> +	if (!cp)
> +		return -ENOMEM;
> +
> +	cp->node = of_node_get(np);
> +	cp->data = data;
> +	cp->xlate = xlate;
> +
> +	mutex_lock(&of_genpd_mutex);
> +	list_add(&cp->link, &of_genpd_providers);
> +	mutex_unlock(&of_genpd_mutex);
> +	pr_debug("Added domain provider from %s\n", np->full_name);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
> +
> +/**
> + * of_genpd_del_provider() - Remove a previously registered PM domain provider
> + * @np: Device node pointer associated with the PM domain provider
> + */
> +void of_genpd_del_provider(struct device_node *np)
> +{
> +	struct of_genpd_provider *cp;
> +
> +	mutex_lock(&of_genpd_mutex);
> +	list_for_each_entry(cp, &of_genpd_providers, link) {
> +		if (cp->node == np) {
> +			list_del(&cp->link);
> +			of_node_put(cp->node);
> +			kfree(cp);
> +			break;
> +		}
> +	}
> +	mutex_unlock(&of_genpd_mutex);
> +}
> +EXPORT_SYMBOL_GPL(of_genpd_del_provider);
> +
> +/**
> + * of_genpd_get_from_provider() - Look-up PM domain
> + * @genpdspec: OF phandle args to use for look-up
> + *
> + * Looks for a PM domain provider under the node specified by @genpdspec and if
> + * found, uses xlate function of the provider to map phandle args to a PM
> + * domain.
> + *
> + * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
> + * on failure.
> + */
> +static struct generic_pm_domain *of_genpd_get_from_provider(
> +					struct of_phandle_args *genpdspec)
> +{
> +	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
> +	struct of_genpd_provider *provider;
> +
> +	mutex_lock(&of_genpd_mutex);
> +
> +	/* Check if we have such a provider in our array */
> +	list_for_each_entry(provider, &of_genpd_providers, link) {
> +		if (provider->node == genpdspec->np)
> +			genpd = provider->xlate(genpdspec, provider->data);
> +		if (!IS_ERR(genpd))
> +			break;
> +	}
> +
> +	mutex_unlock(&of_genpd_mutex);
> +
> +	return genpd;
> +}
> +
> +/**
> + * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
> + * @dev: Device to attach.
> + *
> + * Parse device's OF node to find a PM domain specifier. If such is found,
> + * attaches the device to retrieved pm_domain ops.
> + *
> + * Both generic and legacy Samsung-specific DT bindings are supported to keep
> + * backwards compatibility with existing DTBs.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
> + */
> +int genpd_dev_pm_attach(struct device *dev)
> +{
> +	struct of_phandle_args pd_args;
> +	struct generic_pm_domain *pd;
> +	int ret;
> +
> +	if (!dev->of_node)
> +		return -ENODEV;
> +
> +	if (dev->pm_domain)
> +		return -EEXIST;
> +
> +	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
> +					"#power-domain-cells", 0, &pd_args);
> +	if (ret < 0) {
> +		if (ret != -ENOENT)
> +			return ret;
> +
> +		/*
> +		 * Try legacy Samsung-specific bindings
> +		 * (for backwards compatibility of DT ABI)
> +		 */
> +		pd_args.args_count = 0;
> +		pd_args.np = of_parse_phandle(dev->of_node,
> +						"samsung,power-domain", 0);
> +		if (!pd_args.np)
> +			return -ENOENT;
> +	}
> +
> +	pd = of_genpd_get_from_provider(&pd_args);
> +	if (IS_ERR(pd)) {
> +		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
> +			__func__, PTR_ERR(pd));
> +		of_node_put(dev->of_node);
> +		return PTR_ERR(pd);
> +	}
> +
> +	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
> +
> +	while (1) {
> +		ret = pm_genpd_add_device(pd, dev);
> +		if (ret != -EAGAIN)
> +			break;
> +		cond_resched();
> +	}
> +
> +	if (ret < 0) {
> +		dev_err(dev, "failed to add to PM domain %s: %d",
> +			pd->name, ret);
> +		of_node_put(dev->of_node);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
> +
> +/**
> + * genpd_dev_pm_detach - Detach a device from its PM domain.
> + * @dev: Device to attach.
> + *
> + * Try to locate a corresponding generic PM domain, which the device was
> + * attached to previously. If such is found, the device is detached from it.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
> + */
> +int genpd_dev_pm_detach(struct device *dev)
> +{
> +	struct generic_pm_domain *pd = NULL, *gpd;
> +	int ret = 0;
> +
> +	if (!dev->pm_domain)
> +		return -ENODEV;
> +
> +	mutex_lock(&gpd_list_lock);
> +	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
> +		if (&gpd->domain == dev->pm_domain) {
> +			pd = gpd;
> +			break;
> +		}
> +	}
> +	mutex_unlock(&gpd_list_lock);
> +
> +	if (!pd)
> +		return -ENOENT;
> +
> +	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
> +
> +	while (1) {
> +		ret = pm_genpd_remove_device(pd, dev);
> +		if (ret != -EAGAIN)
> +			break;
> +		cond_resched();
> +	}
> +
> +	if (ret < 0) {
> +		dev_err(dev, "failed to remove from PM domain %s: %d",
> +			pd->name, ret);
> +		return ret;
> +	}
> +
> +	/* Check if PM domain can be powered off after removing this device. */
> +	genpd_queue_power_off_work(pd);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
> +#endif
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index ebc4c76..b09eaa7 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
>  	pm_genpd_syscore_switch(dev, false);
>  }
>  
> +/* OF PM domain providers */
> +struct of_device_id;
> +
> +struct genpd_onecell_data {
> +	struct generic_pm_domain **domains;
> +	unsigned int num_domains;
> +};
> +
> +typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
> +						void *data);
> +
> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
> +			void *data);
> +void of_genpd_del_provider(struct device_node *np);
> +
> +struct generic_pm_domain *__of_genpd_xlate_simple(
> +					struct of_phandle_args *genpdspec,
> +					void *data);
> +struct generic_pm_domain *__of_genpd_xlate_onecell(
> +					struct of_phandle_args *genpdspec,
> +					void *data);
> +
> +int genpd_dev_pm_attach(struct device *dev);
> +int genpd_dev_pm_detach(struct device *dev);
> +#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
> +static inline int __of_genpd_add_provider(struct device_node *np,
> +					genpd_xlate_t xlate, void *data)
> +{
> +	return 0;
> +}
> +static inline void of_genpd_del_provider(struct device_node *np) {}
> +
> +#define __of_genpd_xlate_simple		NULL
> +#define __of_genpd_xlate_onecell	NULL
> +
> +static inline int genpd_dev_pm_attach(struct device *dev)
> +{
> +	return -ENODEV;
> +}
> +static inline int genpd_dev_pm_detach(struct device *dev)
> +{
> +	return -ENODEV;
> +}
> +#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
> +
> +static inline int of_genpd_add_provider_simple(struct device_node *np,
> +					struct generic_pm_domain *genpd)
> +{
> +	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
> +}
> +static inline int of_genpd_add_provider_onecell(struct device_node *np,
> +					struct genpd_onecell_data *data)
> +{
> +	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
> +}
> +
>  #endif /* _LINUX_PM_DOMAIN_H */
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index e4e4121..897619b 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
>  	def_bool y
>  	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
>  
> +config PM_GENERIC_DOMAINS_OF
> +	def_bool y
> +	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
> +
>  config CPU_PM
>  	bool
>  	depends on SUSPEND || CPU_IDLE
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-07 22:13     ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-07 22:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> From: Tomasz Figa <t.figa@samsung.com>
> 
> This patch introduces generic code to perform PM domain look-up using
> device tree and automatically bind devices to their PM domains.
> 
> Generic device tree bindings are introduced to specify PM domains of
> devices in their device tree nodes.
> 
> Backwards compatibility with legacy Samsung-specific PM domain bindings
> is provided, but for now the new code is not compiled when
> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> This will change as soon as the Exynos PM domain code gets converted to
> use the generic framework in further patch.
> 
> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> [Ulf:Added attach|detach functions, fixed review comments]
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>

However, for this one (and consequently the rest) I need an ACK from the
people who maintain the bindings.

> ---
>  .../devicetree/bindings/power/power_domain.txt     |  49 ++++
>  drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
>  include/linux/pm_domain.h                          |  57 ++++
>  kernel/power/Kconfig                               |   4 +
>  4 files changed, 401 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt
> 
> diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
> new file mode 100644
> index 0000000..98c1667
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/power/power_domain.txt
> @@ -0,0 +1,49 @@
> +* Generic PM domains
> +
> +System on chip designs are often divided into multiple PM domains that can be
> +used for power gating of selected IP blocks for power saving by reduced leakage
> +current.
> +
> +This device tree binding can be used to bind PM domain consumer devices with
> +their PM domains provided by PM domain providers. A PM domain provider can be
> +represented by any node in the device tree and can provide one or more PM
> +domains. A consumer node can refer to the provider by a phandle and a set of
> +phandle arguments (so called PM domain specifiers) of length specified by the
> +#power-domain-cells property in the PM domain provider node.
> +
> +==PM domain providers==
> +
> +Required properties:
> + - #power-domain-cells : Number of cells in a PM domain specifier;
> +   Typically 0 for nodes representing a single PM domain and 1 for nodes
> +   providing multiple PM domains (e.g. power controllers), but can be any value
> +   as specified by device tree binding documentation of particular provider.
> +
> +Example:
> +
> +	power: power-controller at 12340000 {
> +		compatible = "foo,power-controller";
> +		reg = <0x12340000 0x1000>;
> +		#power-domain-cells = <1>;
> +	};
> +
> +The node above defines a power controller that is a PM domain provider and
> +expects one cell as its phandle argument.
> +
> +==PM domain consumers==
> +
> +Required properties:
> + - power-domains : A phandle and PM domain specifier as defined by bindings of
> +                   the power controller specified by phandle.
> +
> +Example:
> +
> +	leaky-device at 12350000 {
> +		compatible = "foo,i-leak-current";
> +		reg = <0x12350000 0x1000>;
> +		power-domains = <&power 0>;
> +	};
> +
> +The node above defines a typical PM domain consumer device, which is located
> +inside a PM domain with index 0 of a power controller represented by a node
> +with the label "power".
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index eee55c1..ed42651 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -8,6 +8,7 @@
>  
>  #include <linux/kernel.h>
>  #include <linux/io.h>
> +#include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/pm_domain.h>
>  #include <linux/pm_qos.h>
> @@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>  	list_add(&genpd->gpd_list_node, &gpd_list);
>  	mutex_unlock(&gpd_list_lock);
>  }
> +
> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
> +/*
> + * Device Tree based PM domain providers.
> + *
> + * The code below implements generic device tree based PM domain providers that
> + * bind device tree nodes with generic PM domains registered in the system.
> + *
> + * Any driver that registers generic PM domains and needs to support binding of
> + * devices to these domains is supposed to register a PM domain provider, which
> + * maps a PM domain specifier retrieved from the device tree to a PM domain.
> + *
> + * Two simple mapping functions have been provided for convenience:
> + *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
> + *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
> + *    index.
> + */
> +
> +/**
> + * struct of_genpd_provider - PM domain provider registration structure
> + * @link: Entry in global list of PM domain providers
> + * @node: Pointer to device tree node of PM domain provider
> + * @xlate: Provider-specific xlate callback mapping a set of specifier cells
> + *         into a PM domain.
> + * @data: context pointer to be passed into @xlate callback
> + */
> +struct of_genpd_provider {
> +	struct list_head link;
> +	struct device_node *node;
> +	genpd_xlate_t xlate;
> +	void *data;
> +};
> +
> +/* List of registered PM domain providers. */
> +static LIST_HEAD(of_genpd_providers);
> +/* Mutex to protect the list above. */
> +static DEFINE_MUTEX(of_genpd_mutex);
> +
> +/**
> + * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
> + * @genpdspec: OF phandle args to map into a PM domain
> + * @data: xlate function private data - pointer to struct generic_pm_domain
> + *
> + * This is a generic xlate function that can be used to model PM domains that
> + * have their own device tree nodes. The private data of xlate function needs
> + * to be a valid pointer to struct generic_pm_domain.
> + */
> +struct generic_pm_domain *__of_genpd_xlate_simple(
> +					struct of_phandle_args *genpdspec,
> +					void *data)
> +{
> +	if (genpdspec->args_count != 0)
> +		return ERR_PTR(-EINVAL);
> +	return data;
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
> +
> +/**
> + * __of_genpd_xlate_onecell() - Xlate function using a single index.
> + * @genpdspec: OF phandle args to map into a PM domain
> + * @data: xlate function private data - pointer to struct genpd_onecell_data
> + *
> + * This is a generic xlate function that can be used to model simple PM domain
> + * controllers that have one device tree node and provide multiple PM domains.
> + * A single cell is used as an index into an array of PM domains specified in
> + * the genpd_onecell_data struct when registering the provider.
> + */
> +struct generic_pm_domain *__of_genpd_xlate_onecell(
> +					struct of_phandle_args *genpdspec,
> +					void *data)
> +{
> +	struct genpd_onecell_data *genpd_data = data;
> +	unsigned int idx = genpdspec->args[0];
> +
> +	if (genpdspec->args_count != 1)
> +		return ERR_PTR(-EINVAL);
> +
> +	if (idx >= genpd_data->num_domains) {
> +		pr_err("%s: invalid domain index %u\n", __func__, idx);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	if (!genpd_data->domains[idx])
> +		return ERR_PTR(-ENOENT);
> +
> +	return genpd_data->domains[idx];
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
> +
> +/**
> + * __of_genpd_add_provider() - Register a PM domain provider for a node
> + * @np: Device node pointer associated with the PM domain provider.
> + * @xlate: Callback for decoding PM domain from phandle arguments.
> + * @data: Context pointer for @xlate callback.
> + */
> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
> +			void *data)
> +{
> +	struct of_genpd_provider *cp;
> +
> +	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
> +	if (!cp)
> +		return -ENOMEM;
> +
> +	cp->node = of_node_get(np);
> +	cp->data = data;
> +	cp->xlate = xlate;
> +
> +	mutex_lock(&of_genpd_mutex);
> +	list_add(&cp->link, &of_genpd_providers);
> +	mutex_unlock(&of_genpd_mutex);
> +	pr_debug("Added domain provider from %s\n", np->full_name);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
> +
> +/**
> + * of_genpd_del_provider() - Remove a previously registered PM domain provider
> + * @np: Device node pointer associated with the PM domain provider
> + */
> +void of_genpd_del_provider(struct device_node *np)
> +{
> +	struct of_genpd_provider *cp;
> +
> +	mutex_lock(&of_genpd_mutex);
> +	list_for_each_entry(cp, &of_genpd_providers, link) {
> +		if (cp->node == np) {
> +			list_del(&cp->link);
> +			of_node_put(cp->node);
> +			kfree(cp);
> +			break;
> +		}
> +	}
> +	mutex_unlock(&of_genpd_mutex);
> +}
> +EXPORT_SYMBOL_GPL(of_genpd_del_provider);
> +
> +/**
> + * of_genpd_get_from_provider() - Look-up PM domain
> + * @genpdspec: OF phandle args to use for look-up
> + *
> + * Looks for a PM domain provider under the node specified by @genpdspec and if
> + * found, uses xlate function of the provider to map phandle args to a PM
> + * domain.
> + *
> + * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
> + * on failure.
> + */
> +static struct generic_pm_domain *of_genpd_get_from_provider(
> +					struct of_phandle_args *genpdspec)
> +{
> +	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
> +	struct of_genpd_provider *provider;
> +
> +	mutex_lock(&of_genpd_mutex);
> +
> +	/* Check if we have such a provider in our array */
> +	list_for_each_entry(provider, &of_genpd_providers, link) {
> +		if (provider->node == genpdspec->np)
> +			genpd = provider->xlate(genpdspec, provider->data);
> +		if (!IS_ERR(genpd))
> +			break;
> +	}
> +
> +	mutex_unlock(&of_genpd_mutex);
> +
> +	return genpd;
> +}
> +
> +/**
> + * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
> + * @dev: Device to attach.
> + *
> + * Parse device's OF node to find a PM domain specifier. If such is found,
> + * attaches the device to retrieved pm_domain ops.
> + *
> + * Both generic and legacy Samsung-specific DT bindings are supported to keep
> + * backwards compatibility with existing DTBs.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
> + */
> +int genpd_dev_pm_attach(struct device *dev)
> +{
> +	struct of_phandle_args pd_args;
> +	struct generic_pm_domain *pd;
> +	int ret;
> +
> +	if (!dev->of_node)
> +		return -ENODEV;
> +
> +	if (dev->pm_domain)
> +		return -EEXIST;
> +
> +	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
> +					"#power-domain-cells", 0, &pd_args);
> +	if (ret < 0) {
> +		if (ret != -ENOENT)
> +			return ret;
> +
> +		/*
> +		 * Try legacy Samsung-specific bindings
> +		 * (for backwards compatibility of DT ABI)
> +		 */
> +		pd_args.args_count = 0;
> +		pd_args.np = of_parse_phandle(dev->of_node,
> +						"samsung,power-domain", 0);
> +		if (!pd_args.np)
> +			return -ENOENT;
> +	}
> +
> +	pd = of_genpd_get_from_provider(&pd_args);
> +	if (IS_ERR(pd)) {
> +		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
> +			__func__, PTR_ERR(pd));
> +		of_node_put(dev->of_node);
> +		return PTR_ERR(pd);
> +	}
> +
> +	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
> +
> +	while (1) {
> +		ret = pm_genpd_add_device(pd, dev);
> +		if (ret != -EAGAIN)
> +			break;
> +		cond_resched();
> +	}
> +
> +	if (ret < 0) {
> +		dev_err(dev, "failed to add to PM domain %s: %d",
> +			pd->name, ret);
> +		of_node_put(dev->of_node);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
> +
> +/**
> + * genpd_dev_pm_detach - Detach a device from its PM domain.
> + * @dev: Device to attach.
> + *
> + * Try to locate a corresponding generic PM domain, which the device was
> + * attached to previously. If such is found, the device is detached from it.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
> + */
> +int genpd_dev_pm_detach(struct device *dev)
> +{
> +	struct generic_pm_domain *pd = NULL, *gpd;
> +	int ret = 0;
> +
> +	if (!dev->pm_domain)
> +		return -ENODEV;
> +
> +	mutex_lock(&gpd_list_lock);
> +	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
> +		if (&gpd->domain == dev->pm_domain) {
> +			pd = gpd;
> +			break;
> +		}
> +	}
> +	mutex_unlock(&gpd_list_lock);
> +
> +	if (!pd)
> +		return -ENOENT;
> +
> +	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
> +
> +	while (1) {
> +		ret = pm_genpd_remove_device(pd, dev);
> +		if (ret != -EAGAIN)
> +			break;
> +		cond_resched();
> +	}
> +
> +	if (ret < 0) {
> +		dev_err(dev, "failed to remove from PM domain %s: %d",
> +			pd->name, ret);
> +		return ret;
> +	}
> +
> +	/* Check if PM domain can be powered off after removing this device. */
> +	genpd_queue_power_off_work(pd);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
> +#endif
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index ebc4c76..b09eaa7 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
>  	pm_genpd_syscore_switch(dev, false);
>  }
>  
> +/* OF PM domain providers */
> +struct of_device_id;
> +
> +struct genpd_onecell_data {
> +	struct generic_pm_domain **domains;
> +	unsigned int num_domains;
> +};
> +
> +typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
> +						void *data);
> +
> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
> +			void *data);
> +void of_genpd_del_provider(struct device_node *np);
> +
> +struct generic_pm_domain *__of_genpd_xlate_simple(
> +					struct of_phandle_args *genpdspec,
> +					void *data);
> +struct generic_pm_domain *__of_genpd_xlate_onecell(
> +					struct of_phandle_args *genpdspec,
> +					void *data);
> +
> +int genpd_dev_pm_attach(struct device *dev);
> +int genpd_dev_pm_detach(struct device *dev);
> +#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
> +static inline int __of_genpd_add_provider(struct device_node *np,
> +					genpd_xlate_t xlate, void *data)
> +{
> +	return 0;
> +}
> +static inline void of_genpd_del_provider(struct device_node *np) {}
> +
> +#define __of_genpd_xlate_simple		NULL
> +#define __of_genpd_xlate_onecell	NULL
> +
> +static inline int genpd_dev_pm_attach(struct device *dev)
> +{
> +	return -ENODEV;
> +}
> +static inline int genpd_dev_pm_detach(struct device *dev)
> +{
> +	return -ENODEV;
> +}
> +#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
> +
> +static inline int of_genpd_add_provider_simple(struct device_node *np,
> +					struct generic_pm_domain *genpd)
> +{
> +	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
> +}
> +static inline int of_genpd_add_provider_onecell(struct device_node *np,
> +					struct genpd_onecell_data *data)
> +{
> +	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
> +}
> +
>  #endif /* _LINUX_PM_DOMAIN_H */
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index e4e4121..897619b 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
>  	def_bool y
>  	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
>  
> +config PM_GENERIC_DOMAINS_OF
> +	def_bool y
> +	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
> +
>  config CPU_PM
>  	bool
>  	depends on SUSPEND || CPU_IDLE
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-07 22:13     ` Rafael J. Wysocki
@ 2014-09-08  7:26       ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-08  7:26 UTC (permalink / raw)
  To: Rafael J. Wysocki, Rob Herring
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, ACPI Devel Maling List, Geert Uytterhoeven,
	Kevin Hilman, Alan Stern, Daniel Lezcano, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball

On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>> From: Tomasz Figa <t.figa@samsung.com>
>>
>> This patch introduces generic code to perform PM domain look-up using
>> device tree and automatically bind devices to their PM domains.
>>
>> Generic device tree bindings are introduced to specify PM domains of
>> devices in their device tree nodes.
>>
>> Backwards compatibility with legacy Samsung-specific PM domain bindings
>> is provided, but for now the new code is not compiled when
>> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>> This will change as soon as the Exynos PM domain code gets converted to
>> use the generic framework in further patch.
>>
>> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> [Ulf:Added attach|detach functions, fixed review comments]
>> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>
> However, for this one (and consequently the rest) I need an ACK from the
> people who maintain the bindings.

These DT bindings have been discussed between Tomasz and devicetree
maintainers previously. So I think there are fine.

Also, when browsing the mail-archives, I found an ack from Rob Herrring:
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html

I realize that I didn't put the DT maintainers on the to-line when
posting this patch, but just the devicetree list. I have now included
them on this reply, but maybe I should repost instead. What do you
think? Are you happy with the above ack from Rob?

Kind regards
Uffe

>
>> ---
>>  .../devicetree/bindings/power/power_domain.txt     |  49 ++++
>>  drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
>>  include/linux/pm_domain.h                          |  57 ++++
>>  kernel/power/Kconfig                               |   4 +
>>  4 files changed, 401 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt
>>
>> diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
>> new file mode 100644
>> index 0000000..98c1667
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/power_domain.txt
>> @@ -0,0 +1,49 @@
>> +* Generic PM domains
>> +
>> +System on chip designs are often divided into multiple PM domains that can be
>> +used for power gating of selected IP blocks for power saving by reduced leakage
>> +current.
>> +
>> +This device tree binding can be used to bind PM domain consumer devices with
>> +their PM domains provided by PM domain providers. A PM domain provider can be
>> +represented by any node in the device tree and can provide one or more PM
>> +domains. A consumer node can refer to the provider by a phandle and a set of
>> +phandle arguments (so called PM domain specifiers) of length specified by the
>> +#power-domain-cells property in the PM domain provider node.
>> +
>> +==PM domain providers==
>> +
>> +Required properties:
>> + - #power-domain-cells : Number of cells in a PM domain specifier;
>> +   Typically 0 for nodes representing a single PM domain and 1 for nodes
>> +   providing multiple PM domains (e.g. power controllers), but can be any value
>> +   as specified by device tree binding documentation of particular provider.
>> +
>> +Example:
>> +
>> +     power: power-controller@12340000 {
>> +             compatible = "foo,power-controller";
>> +             reg = <0x12340000 0x1000>;
>> +             #power-domain-cells = <1>;
>> +     };
>> +
>> +The node above defines a power controller that is a PM domain provider and
>> +expects one cell as its phandle argument.
>> +
>> +==PM domain consumers==
>> +
>> +Required properties:
>> + - power-domains : A phandle and PM domain specifier as defined by bindings of
>> +                   the power controller specified by phandle.
>> +
>> +Example:
>> +
>> +     leaky-device@12350000 {
>> +             compatible = "foo,i-leak-current";
>> +             reg = <0x12350000 0x1000>;
>> +             power-domains = <&power 0>;
>> +     };
>> +
>> +The node above defines a typical PM domain consumer device, which is located
>> +inside a PM domain with index 0 of a power controller represented by a node
>> +with the label "power".
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index eee55c1..ed42651 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -8,6 +8,7 @@
>>
>>  #include <linux/kernel.h>
>>  #include <linux/io.h>
>> +#include <linux/platform_device.h>
>>  #include <linux/pm_runtime.h>
>>  #include <linux/pm_domain.h>
>>  #include <linux/pm_qos.h>
>> @@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>>       list_add(&genpd->gpd_list_node, &gpd_list);
>>       mutex_unlock(&gpd_list_lock);
>>  }
>> +
>> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
>> +/*
>> + * Device Tree based PM domain providers.
>> + *
>> + * The code below implements generic device tree based PM domain providers that
>> + * bind device tree nodes with generic PM domains registered in the system.
>> + *
>> + * Any driver that registers generic PM domains and needs to support binding of
>> + * devices to these domains is supposed to register a PM domain provider, which
>> + * maps a PM domain specifier retrieved from the device tree to a PM domain.
>> + *
>> + * Two simple mapping functions have been provided for convenience:
>> + *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
>> + *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
>> + *    index.
>> + */
>> +
>> +/**
>> + * struct of_genpd_provider - PM domain provider registration structure
>> + * @link: Entry in global list of PM domain providers
>> + * @node: Pointer to device tree node of PM domain provider
>> + * @xlate: Provider-specific xlate callback mapping a set of specifier cells
>> + *         into a PM domain.
>> + * @data: context pointer to be passed into @xlate callback
>> + */
>> +struct of_genpd_provider {
>> +     struct list_head link;
>> +     struct device_node *node;
>> +     genpd_xlate_t xlate;
>> +     void *data;
>> +};
>> +
>> +/* List of registered PM domain providers. */
>> +static LIST_HEAD(of_genpd_providers);
>> +/* Mutex to protect the list above. */
>> +static DEFINE_MUTEX(of_genpd_mutex);
>> +
>> +/**
>> + * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
>> + * @genpdspec: OF phandle args to map into a PM domain
>> + * @data: xlate function private data - pointer to struct generic_pm_domain
>> + *
>> + * This is a generic xlate function that can be used to model PM domains that
>> + * have their own device tree nodes. The private data of xlate function needs
>> + * to be a valid pointer to struct generic_pm_domain.
>> + */
>> +struct generic_pm_domain *__of_genpd_xlate_simple(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data)
>> +{
>> +     if (genpdspec->args_count != 0)
>> +             return ERR_PTR(-EINVAL);
>> +     return data;
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
>> +
>> +/**
>> + * __of_genpd_xlate_onecell() - Xlate function using a single index.
>> + * @genpdspec: OF phandle args to map into a PM domain
>> + * @data: xlate function private data - pointer to struct genpd_onecell_data
>> + *
>> + * This is a generic xlate function that can be used to model simple PM domain
>> + * controllers that have one device tree node and provide multiple PM domains.
>> + * A single cell is used as an index into an array of PM domains specified in
>> + * the genpd_onecell_data struct when registering the provider.
>> + */
>> +struct generic_pm_domain *__of_genpd_xlate_onecell(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data)
>> +{
>> +     struct genpd_onecell_data *genpd_data = data;
>> +     unsigned int idx = genpdspec->args[0];
>> +
>> +     if (genpdspec->args_count != 1)
>> +             return ERR_PTR(-EINVAL);
>> +
>> +     if (idx >= genpd_data->num_domains) {
>> +             pr_err("%s: invalid domain index %u\n", __func__, idx);
>> +             return ERR_PTR(-EINVAL);
>> +     }
>> +
>> +     if (!genpd_data->domains[idx])
>> +             return ERR_PTR(-ENOENT);
>> +
>> +     return genpd_data->domains[idx];
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
>> +
>> +/**
>> + * __of_genpd_add_provider() - Register a PM domain provider for a node
>> + * @np: Device node pointer associated with the PM domain provider.
>> + * @xlate: Callback for decoding PM domain from phandle arguments.
>> + * @data: Context pointer for @xlate callback.
>> + */
>> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
>> +                     void *data)
>> +{
>> +     struct of_genpd_provider *cp;
>> +
>> +     cp = kzalloc(sizeof(*cp), GFP_KERNEL);
>> +     if (!cp)
>> +             return -ENOMEM;
>> +
>> +     cp->node = of_node_get(np);
>> +     cp->data = data;
>> +     cp->xlate = xlate;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +     list_add(&cp->link, &of_genpd_providers);
>> +     mutex_unlock(&of_genpd_mutex);
>> +     pr_debug("Added domain provider from %s\n", np->full_name);
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
>> +
>> +/**
>> + * of_genpd_del_provider() - Remove a previously registered PM domain provider
>> + * @np: Device node pointer associated with the PM domain provider
>> + */
>> +void of_genpd_del_provider(struct device_node *np)
>> +{
>> +     struct of_genpd_provider *cp;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +     list_for_each_entry(cp, &of_genpd_providers, link) {
>> +             if (cp->node == np) {
>> +                     list_del(&cp->link);
>> +                     of_node_put(cp->node);
>> +                     kfree(cp);
>> +                     break;
>> +             }
>> +     }
>> +     mutex_unlock(&of_genpd_mutex);
>> +}
>> +EXPORT_SYMBOL_GPL(of_genpd_del_provider);
>> +
>> +/**
>> + * of_genpd_get_from_provider() - Look-up PM domain
>> + * @genpdspec: OF phandle args to use for look-up
>> + *
>> + * Looks for a PM domain provider under the node specified by @genpdspec and if
>> + * found, uses xlate function of the provider to map phandle args to a PM
>> + * domain.
>> + *
>> + * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
>> + * on failure.
>> + */
>> +static struct generic_pm_domain *of_genpd_get_from_provider(
>> +                                     struct of_phandle_args *genpdspec)
>> +{
>> +     struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
>> +     struct of_genpd_provider *provider;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +
>> +     /* Check if we have such a provider in our array */
>> +     list_for_each_entry(provider, &of_genpd_providers, link) {
>> +             if (provider->node == genpdspec->np)
>> +                     genpd = provider->xlate(genpdspec, provider->data);
>> +             if (!IS_ERR(genpd))
>> +                     break;
>> +     }
>> +
>> +     mutex_unlock(&of_genpd_mutex);
>> +
>> +     return genpd;
>> +}
>> +
>> +/**
>> + * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
>> + * @dev: Device to attach.
>> + *
>> + * Parse device's OF node to find a PM domain specifier. If such is found,
>> + * attaches the device to retrieved pm_domain ops.
>> + *
>> + * Both generic and legacy Samsung-specific DT bindings are supported to keep
>> + * backwards compatibility with existing DTBs.
>> + *
>> + * Returns 0 on successfully attached PM domain or negative error code.
>> + */
>> +int genpd_dev_pm_attach(struct device *dev)
>> +{
>> +     struct of_phandle_args pd_args;
>> +     struct generic_pm_domain *pd;
>> +     int ret;
>> +
>> +     if (!dev->of_node)
>> +             return -ENODEV;
>> +
>> +     if (dev->pm_domain)
>> +             return -EEXIST;
>> +
>> +     ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
>> +                                     "#power-domain-cells", 0, &pd_args);
>> +     if (ret < 0) {
>> +             if (ret != -ENOENT)
>> +                     return ret;
>> +
>> +             /*
>> +              * Try legacy Samsung-specific bindings
>> +              * (for backwards compatibility of DT ABI)
>> +              */
>> +             pd_args.args_count = 0;
>> +             pd_args.np = of_parse_phandle(dev->of_node,
>> +                                             "samsung,power-domain", 0);
>> +             if (!pd_args.np)
>> +                     return -ENOENT;
>> +     }
>> +
>> +     pd = of_genpd_get_from_provider(&pd_args);
>> +     if (IS_ERR(pd)) {
>> +             dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
>> +                     __func__, PTR_ERR(pd));
>> +             of_node_put(dev->of_node);
>> +             return PTR_ERR(pd);
>> +     }
>> +
>> +     dev_dbg(dev, "adding to PM domain %s\n", pd->name);
>> +
>> +     while (1) {
>> +             ret = pm_genpd_add_device(pd, dev);
>> +             if (ret != -EAGAIN)
>> +                     break;
>> +             cond_resched();
>> +     }
>> +
>> +     if (ret < 0) {
>> +             dev_err(dev, "failed to add to PM domain %s: %d",
>> +                     pd->name, ret);
>> +             of_node_put(dev->of_node);
>> +             return ret;
>> +     }
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
>> +
>> +/**
>> + * genpd_dev_pm_detach - Detach a device from its PM domain.
>> + * @dev: Device to attach.
>> + *
>> + * Try to locate a corresponding generic PM domain, which the device was
>> + * attached to previously. If such is found, the device is detached from it.
>> + *
>> + * Returns 0 on successfully detached PM domain or negative error code.
>> + */
>> +int genpd_dev_pm_detach(struct device *dev)
>> +{
>> +     struct generic_pm_domain *pd = NULL, *gpd;
>> +     int ret = 0;
>> +
>> +     if (!dev->pm_domain)
>> +             return -ENODEV;
>> +
>> +     mutex_lock(&gpd_list_lock);
>> +     list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
>> +             if (&gpd->domain == dev->pm_domain) {
>> +                     pd = gpd;
>> +                     break;
>> +             }
>> +     }
>> +     mutex_unlock(&gpd_list_lock);
>> +
>> +     if (!pd)
>> +             return -ENOENT;
>> +
>> +     dev_dbg(dev, "removing from PM domain %s\n", pd->name);
>> +
>> +     while (1) {
>> +             ret = pm_genpd_remove_device(pd, dev);
>> +             if (ret != -EAGAIN)
>> +                     break;
>> +             cond_resched();
>> +     }
>> +
>> +     if (ret < 0) {
>> +             dev_err(dev, "failed to remove from PM domain %s: %d",
>> +                     pd->name, ret);
>> +             return ret;
>> +     }
>> +
>> +     /* Check if PM domain can be powered off after removing this device. */
>> +     genpd_queue_power_off_work(pd);
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
>> +#endif
>> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
>> index ebc4c76..b09eaa7 100644
>> --- a/include/linux/pm_domain.h
>> +++ b/include/linux/pm_domain.h
>> @@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
>>       pm_genpd_syscore_switch(dev, false);
>>  }
>>
>> +/* OF PM domain providers */
>> +struct of_device_id;
>> +
>> +struct genpd_onecell_data {
>> +     struct generic_pm_domain **domains;
>> +     unsigned int num_domains;
>> +};
>> +
>> +typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
>> +                                             void *data);
>> +
>> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
>> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
>> +                     void *data);
>> +void of_genpd_del_provider(struct device_node *np);
>> +
>> +struct generic_pm_domain *__of_genpd_xlate_simple(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data);
>> +struct generic_pm_domain *__of_genpd_xlate_onecell(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data);
>> +
>> +int genpd_dev_pm_attach(struct device *dev);
>> +int genpd_dev_pm_detach(struct device *dev);
>> +#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
>> +static inline int __of_genpd_add_provider(struct device_node *np,
>> +                                     genpd_xlate_t xlate, void *data)
>> +{
>> +     return 0;
>> +}
>> +static inline void of_genpd_del_provider(struct device_node *np) {}
>> +
>> +#define __of_genpd_xlate_simple              NULL
>> +#define __of_genpd_xlate_onecell     NULL
>> +
>> +static inline int genpd_dev_pm_attach(struct device *dev)
>> +{
>> +     return -ENODEV;
>> +}
>> +static inline int genpd_dev_pm_detach(struct device *dev)
>> +{
>> +     return -ENODEV;
>> +}
>> +#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
>> +
>> +static inline int of_genpd_add_provider_simple(struct device_node *np,
>> +                                     struct generic_pm_domain *genpd)
>> +{
>> +     return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
>> +}
>> +static inline int of_genpd_add_provider_onecell(struct device_node *np,
>> +                                     struct genpd_onecell_data *data)
>> +{
>> +     return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
>> +}
>> +
>>  #endif /* _LINUX_PM_DOMAIN_H */
>> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
>> index e4e4121..897619b 100644
>> --- a/kernel/power/Kconfig
>> +++ b/kernel/power/Kconfig
>> @@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
>>       def_bool y
>>       depends on PM_RUNTIME && PM_GENERIC_DOMAINS
>>
>> +config PM_GENERIC_DOMAINS_OF
>> +     def_bool y
>> +     depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
>> +
>>  config CPU_PM
>>       bool
>>       depends on SUSPEND || CPU_IDLE
>>
>
> --
> I speak only for myself.
> Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08  7:26       ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-08  7:26 UTC (permalink / raw)
  To: linux-arm-kernel

On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>> From: Tomasz Figa <t.figa@samsung.com>
>>
>> This patch introduces generic code to perform PM domain look-up using
>> device tree and automatically bind devices to their PM domains.
>>
>> Generic device tree bindings are introduced to specify PM domains of
>> devices in their device tree nodes.
>>
>> Backwards compatibility with legacy Samsung-specific PM domain bindings
>> is provided, but for now the new code is not compiled when
>> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>> This will change as soon as the Exynos PM domain code gets converted to
>> use the generic framework in further patch.
>>
>> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> [Ulf:Added attach|detach functions, fixed review comments]
>> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>
> However, for this one (and consequently the rest) I need an ACK from the
> people who maintain the bindings.

These DT bindings have been discussed between Tomasz and devicetree
maintainers previously. So I think there are fine.

Also, when browsing the mail-archives, I found an ack from Rob Herrring:
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html

I realize that I didn't put the DT maintainers on the to-line when
posting this patch, but just the devicetree list. I have now included
them on this reply, but maybe I should repost instead. What do you
think? Are you happy with the above ack from Rob?

Kind regards
Uffe

>
>> ---
>>  .../devicetree/bindings/power/power_domain.txt     |  49 ++++
>>  drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
>>  include/linux/pm_domain.h                          |  57 ++++
>>  kernel/power/Kconfig                               |   4 +
>>  4 files changed, 401 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt
>>
>> diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
>> new file mode 100644
>> index 0000000..98c1667
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/power/power_domain.txt
>> @@ -0,0 +1,49 @@
>> +* Generic PM domains
>> +
>> +System on chip designs are often divided into multiple PM domains that can be
>> +used for power gating of selected IP blocks for power saving by reduced leakage
>> +current.
>> +
>> +This device tree binding can be used to bind PM domain consumer devices with
>> +their PM domains provided by PM domain providers. A PM domain provider can be
>> +represented by any node in the device tree and can provide one or more PM
>> +domains. A consumer node can refer to the provider by a phandle and a set of
>> +phandle arguments (so called PM domain specifiers) of length specified by the
>> +#power-domain-cells property in the PM domain provider node.
>> +
>> +==PM domain providers==
>> +
>> +Required properties:
>> + - #power-domain-cells : Number of cells in a PM domain specifier;
>> +   Typically 0 for nodes representing a single PM domain and 1 for nodes
>> +   providing multiple PM domains (e.g. power controllers), but can be any value
>> +   as specified by device tree binding documentation of particular provider.
>> +
>> +Example:
>> +
>> +     power: power-controller at 12340000 {
>> +             compatible = "foo,power-controller";
>> +             reg = <0x12340000 0x1000>;
>> +             #power-domain-cells = <1>;
>> +     };
>> +
>> +The node above defines a power controller that is a PM domain provider and
>> +expects one cell as its phandle argument.
>> +
>> +==PM domain consumers==
>> +
>> +Required properties:
>> + - power-domains : A phandle and PM domain specifier as defined by bindings of
>> +                   the power controller specified by phandle.
>> +
>> +Example:
>> +
>> +     leaky-device at 12350000 {
>> +             compatible = "foo,i-leak-current";
>> +             reg = <0x12350000 0x1000>;
>> +             power-domains = <&power 0>;
>> +     };
>> +
>> +The node above defines a typical PM domain consumer device, which is located
>> +inside a PM domain with index 0 of a power controller represented by a node
>> +with the label "power".
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index eee55c1..ed42651 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -8,6 +8,7 @@
>>
>>  #include <linux/kernel.h>
>>  #include <linux/io.h>
>> +#include <linux/platform_device.h>
>>  #include <linux/pm_runtime.h>
>>  #include <linux/pm_domain.h>
>>  #include <linux/pm_qos.h>
>> @@ -2189,3 +2190,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>>       list_add(&genpd->gpd_list_node, &gpd_list);
>>       mutex_unlock(&gpd_list_lock);
>>  }
>> +
>> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
>> +/*
>> + * Device Tree based PM domain providers.
>> + *
>> + * The code below implements generic device tree based PM domain providers that
>> + * bind device tree nodes with generic PM domains registered in the system.
>> + *
>> + * Any driver that registers generic PM domains and needs to support binding of
>> + * devices to these domains is supposed to register a PM domain provider, which
>> + * maps a PM domain specifier retrieved from the device tree to a PM domain.
>> + *
>> + * Two simple mapping functions have been provided for convenience:
>> + *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
>> + *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
>> + *    index.
>> + */
>> +
>> +/**
>> + * struct of_genpd_provider - PM domain provider registration structure
>> + * @link: Entry in global list of PM domain providers
>> + * @node: Pointer to device tree node of PM domain provider
>> + * @xlate: Provider-specific xlate callback mapping a set of specifier cells
>> + *         into a PM domain.
>> + * @data: context pointer to be passed into @xlate callback
>> + */
>> +struct of_genpd_provider {
>> +     struct list_head link;
>> +     struct device_node *node;
>> +     genpd_xlate_t xlate;
>> +     void *data;
>> +};
>> +
>> +/* List of registered PM domain providers. */
>> +static LIST_HEAD(of_genpd_providers);
>> +/* Mutex to protect the list above. */
>> +static DEFINE_MUTEX(of_genpd_mutex);
>> +
>> +/**
>> + * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
>> + * @genpdspec: OF phandle args to map into a PM domain
>> + * @data: xlate function private data - pointer to struct generic_pm_domain
>> + *
>> + * This is a generic xlate function that can be used to model PM domains that
>> + * have their own device tree nodes. The private data of xlate function needs
>> + * to be a valid pointer to struct generic_pm_domain.
>> + */
>> +struct generic_pm_domain *__of_genpd_xlate_simple(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data)
>> +{
>> +     if (genpdspec->args_count != 0)
>> +             return ERR_PTR(-EINVAL);
>> +     return data;
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
>> +
>> +/**
>> + * __of_genpd_xlate_onecell() - Xlate function using a single index.
>> + * @genpdspec: OF phandle args to map into a PM domain
>> + * @data: xlate function private data - pointer to struct genpd_onecell_data
>> + *
>> + * This is a generic xlate function that can be used to model simple PM domain
>> + * controllers that have one device tree node and provide multiple PM domains.
>> + * A single cell is used as an index into an array of PM domains specified in
>> + * the genpd_onecell_data struct when registering the provider.
>> + */
>> +struct generic_pm_domain *__of_genpd_xlate_onecell(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data)
>> +{
>> +     struct genpd_onecell_data *genpd_data = data;
>> +     unsigned int idx = genpdspec->args[0];
>> +
>> +     if (genpdspec->args_count != 1)
>> +             return ERR_PTR(-EINVAL);
>> +
>> +     if (idx >= genpd_data->num_domains) {
>> +             pr_err("%s: invalid domain index %u\n", __func__, idx);
>> +             return ERR_PTR(-EINVAL);
>> +     }
>> +
>> +     if (!genpd_data->domains[idx])
>> +             return ERR_PTR(-ENOENT);
>> +
>> +     return genpd_data->domains[idx];
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
>> +
>> +/**
>> + * __of_genpd_add_provider() - Register a PM domain provider for a node
>> + * @np: Device node pointer associated with the PM domain provider.
>> + * @xlate: Callback for decoding PM domain from phandle arguments.
>> + * @data: Context pointer for @xlate callback.
>> + */
>> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
>> +                     void *data)
>> +{
>> +     struct of_genpd_provider *cp;
>> +
>> +     cp = kzalloc(sizeof(*cp), GFP_KERNEL);
>> +     if (!cp)
>> +             return -ENOMEM;
>> +
>> +     cp->node = of_node_get(np);
>> +     cp->data = data;
>> +     cp->xlate = xlate;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +     list_add(&cp->link, &of_genpd_providers);
>> +     mutex_unlock(&of_genpd_mutex);
>> +     pr_debug("Added domain provider from %s\n", np->full_name);
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
>> +
>> +/**
>> + * of_genpd_del_provider() - Remove a previously registered PM domain provider
>> + * @np: Device node pointer associated with the PM domain provider
>> + */
>> +void of_genpd_del_provider(struct device_node *np)
>> +{
>> +     struct of_genpd_provider *cp;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +     list_for_each_entry(cp, &of_genpd_providers, link) {
>> +             if (cp->node == np) {
>> +                     list_del(&cp->link);
>> +                     of_node_put(cp->node);
>> +                     kfree(cp);
>> +                     break;
>> +             }
>> +     }
>> +     mutex_unlock(&of_genpd_mutex);
>> +}
>> +EXPORT_SYMBOL_GPL(of_genpd_del_provider);
>> +
>> +/**
>> + * of_genpd_get_from_provider() - Look-up PM domain
>> + * @genpdspec: OF phandle args to use for look-up
>> + *
>> + * Looks for a PM domain provider under the node specified by @genpdspec and if
>> + * found, uses xlate function of the provider to map phandle args to a PM
>> + * domain.
>> + *
>> + * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
>> + * on failure.
>> + */
>> +static struct generic_pm_domain *of_genpd_get_from_provider(
>> +                                     struct of_phandle_args *genpdspec)
>> +{
>> +     struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
>> +     struct of_genpd_provider *provider;
>> +
>> +     mutex_lock(&of_genpd_mutex);
>> +
>> +     /* Check if we have such a provider in our array */
>> +     list_for_each_entry(provider, &of_genpd_providers, link) {
>> +             if (provider->node == genpdspec->np)
>> +                     genpd = provider->xlate(genpdspec, provider->data);
>> +             if (!IS_ERR(genpd))
>> +                     break;
>> +     }
>> +
>> +     mutex_unlock(&of_genpd_mutex);
>> +
>> +     return genpd;
>> +}
>> +
>> +/**
>> + * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
>> + * @dev: Device to attach.
>> + *
>> + * Parse device's OF node to find a PM domain specifier. If such is found,
>> + * attaches the device to retrieved pm_domain ops.
>> + *
>> + * Both generic and legacy Samsung-specific DT bindings are supported to keep
>> + * backwards compatibility with existing DTBs.
>> + *
>> + * Returns 0 on successfully attached PM domain or negative error code.
>> + */
>> +int genpd_dev_pm_attach(struct device *dev)
>> +{
>> +     struct of_phandle_args pd_args;
>> +     struct generic_pm_domain *pd;
>> +     int ret;
>> +
>> +     if (!dev->of_node)
>> +             return -ENODEV;
>> +
>> +     if (dev->pm_domain)
>> +             return -EEXIST;
>> +
>> +     ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
>> +                                     "#power-domain-cells", 0, &pd_args);
>> +     if (ret < 0) {
>> +             if (ret != -ENOENT)
>> +                     return ret;
>> +
>> +             /*
>> +              * Try legacy Samsung-specific bindings
>> +              * (for backwards compatibility of DT ABI)
>> +              */
>> +             pd_args.args_count = 0;
>> +             pd_args.np = of_parse_phandle(dev->of_node,
>> +                                             "samsung,power-domain", 0);
>> +             if (!pd_args.np)
>> +                     return -ENOENT;
>> +     }
>> +
>> +     pd = of_genpd_get_from_provider(&pd_args);
>> +     if (IS_ERR(pd)) {
>> +             dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
>> +                     __func__, PTR_ERR(pd));
>> +             of_node_put(dev->of_node);
>> +             return PTR_ERR(pd);
>> +     }
>> +
>> +     dev_dbg(dev, "adding to PM domain %s\n", pd->name);
>> +
>> +     while (1) {
>> +             ret = pm_genpd_add_device(pd, dev);
>> +             if (ret != -EAGAIN)
>> +                     break;
>> +             cond_resched();
>> +     }
>> +
>> +     if (ret < 0) {
>> +             dev_err(dev, "failed to add to PM domain %s: %d",
>> +                     pd->name, ret);
>> +             of_node_put(dev->of_node);
>> +             return ret;
>> +     }
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
>> +
>> +/**
>> + * genpd_dev_pm_detach - Detach a device from its PM domain.
>> + * @dev: Device to attach.
>> + *
>> + * Try to locate a corresponding generic PM domain, which the device was
>> + * attached to previously. If such is found, the device is detached from it.
>> + *
>> + * Returns 0 on successfully detached PM domain or negative error code.
>> + */
>> +int genpd_dev_pm_detach(struct device *dev)
>> +{
>> +     struct generic_pm_domain *pd = NULL, *gpd;
>> +     int ret = 0;
>> +
>> +     if (!dev->pm_domain)
>> +             return -ENODEV;
>> +
>> +     mutex_lock(&gpd_list_lock);
>> +     list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
>> +             if (&gpd->domain == dev->pm_domain) {
>> +                     pd = gpd;
>> +                     break;
>> +             }
>> +     }
>> +     mutex_unlock(&gpd_list_lock);
>> +
>> +     if (!pd)
>> +             return -ENOENT;
>> +
>> +     dev_dbg(dev, "removing from PM domain %s\n", pd->name);
>> +
>> +     while (1) {
>> +             ret = pm_genpd_remove_device(pd, dev);
>> +             if (ret != -EAGAIN)
>> +                     break;
>> +             cond_resched();
>> +     }
>> +
>> +     if (ret < 0) {
>> +             dev_err(dev, "failed to remove from PM domain %s: %d",
>> +                     pd->name, ret);
>> +             return ret;
>> +     }
>> +
>> +     /* Check if PM domain can be powered off after removing this device. */
>> +     genpd_queue_power_off_work(pd);
>> +
>> +     return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
>> +#endif
>> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
>> index ebc4c76..b09eaa7 100644
>> --- a/include/linux/pm_domain.h
>> +++ b/include/linux/pm_domain.h
>> @@ -310,4 +310,61 @@ static inline void pm_genpd_syscore_poweron(struct device *dev)
>>       pm_genpd_syscore_switch(dev, false);
>>  }
>>
>> +/* OF PM domain providers */
>> +struct of_device_id;
>> +
>> +struct genpd_onecell_data {
>> +     struct generic_pm_domain **domains;
>> +     unsigned int num_domains;
>> +};
>> +
>> +typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
>> +                                             void *data);
>> +
>> +#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
>> +int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
>> +                     void *data);
>> +void of_genpd_del_provider(struct device_node *np);
>> +
>> +struct generic_pm_domain *__of_genpd_xlate_simple(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data);
>> +struct generic_pm_domain *__of_genpd_xlate_onecell(
>> +                                     struct of_phandle_args *genpdspec,
>> +                                     void *data);
>> +
>> +int genpd_dev_pm_attach(struct device *dev);
>> +int genpd_dev_pm_detach(struct device *dev);
>> +#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
>> +static inline int __of_genpd_add_provider(struct device_node *np,
>> +                                     genpd_xlate_t xlate, void *data)
>> +{
>> +     return 0;
>> +}
>> +static inline void of_genpd_del_provider(struct device_node *np) {}
>> +
>> +#define __of_genpd_xlate_simple              NULL
>> +#define __of_genpd_xlate_onecell     NULL
>> +
>> +static inline int genpd_dev_pm_attach(struct device *dev)
>> +{
>> +     return -ENODEV;
>> +}
>> +static inline int genpd_dev_pm_detach(struct device *dev)
>> +{
>> +     return -ENODEV;
>> +}
>> +#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
>> +
>> +static inline int of_genpd_add_provider_simple(struct device_node *np,
>> +                                     struct generic_pm_domain *genpd)
>> +{
>> +     return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
>> +}
>> +static inline int of_genpd_add_provider_onecell(struct device_node *np,
>> +                                     struct genpd_onecell_data *data)
>> +{
>> +     return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
>> +}
>> +
>>  #endif /* _LINUX_PM_DOMAIN_H */
>> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
>> index e4e4121..897619b 100644
>> --- a/kernel/power/Kconfig
>> +++ b/kernel/power/Kconfig
>> @@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
>>       def_bool y
>>       depends on PM_RUNTIME && PM_GENERIC_DOMAINS
>>
>> +config PM_GENERIC_DOMAINS_OF
>> +     def_bool y
>> +     depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
>> +
>>  config CPU_PM
>>       bool
>>       depends on SUSPEND || CPU_IDLE
>>
>
> --
> I speak only for myself.
> Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 21:08           ` Rafael J. Wysocki
@ 2014-09-08 20:53             ` Tomasz Figa
  -1 siblings, 0 replies; 96+ messages in thread
From: Tomasz Figa @ 2014-09-08 20:53 UTC (permalink / raw)
  To: Rafael J. Wysocki, Ulf Hansson, Pawel Moll
  Cc: Mark Rutland, Pavel Machek, Geert Uytterhoeven, Wolfram Sang,
	Linus Walleij, Chris Ball, devicetree, Philipp Zabel, Kukjin Kim,
	Russell King, Daniel Lezcano, Magnus Damm,
	ACPI Devel Maling List, Alan Stern, Len Brown, Kevin Hilman,
	linux-pm, Simon Horman, Ben Dooks, linux-arm-kernel,
	Ian Campbell

On 08.09.2014 23:08, Rafael J. Wysocki wrote:
> On Monday, September 08, 2014 11:04:23 PM Rafael J. Wysocki wrote:
>> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
>>> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>>>> On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>>>>> From: Tomasz Figa <t.figa@samsung.com>
>>>>>
>>>>> This patch introduces generic code to perform PM domain look-up using
>>>>> device tree and automatically bind devices to their PM domains.
>>>>>
>>>>> Generic device tree bindings are introduced to specify PM domains of
>>>>> devices in their device tree nodes.
>>>>>
>>>>> Backwards compatibility with legacy Samsung-specific PM domain bindings
>>>>> is provided, but for now the new code is not compiled when
>>>>> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>>>>> This will change as soon as the Exynos PM domain code gets converted to
>>>>> use the generic framework in further patch.
>>>>>
>>>>> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>>>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>>>> [Ulf:Added attach|detach functions, fixed review comments]
>>>>> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>>>>
>>>> However, for this one (and consequently the rest) I need an ACK from the
>>>> people who maintain the bindings.
>>>
>>> These DT bindings have been discussed between Tomasz and devicetree
>>> maintainers previously. So I think there are fine.
>>>
>>> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
>>> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
>>>
>>> I realize that I didn't put the DT maintainers on the to-line when
>>> posting this patch, but just the devicetree list. I have now included
>>> them on this reply, but maybe I should repost instead. What do you
>>> think? Are you happy with the above ack from Rob?
>>
>> That should be sufficient, but I wonder why you didn't add it to the patch
>> to start with?
> 
> BTW, I get bounces from t.figa@samsung.com, so I won't apply the patch with
> that as the "From" field.  And the s-o-b from a bouncing address is worthless
> too.

Yes, that e-mail address is no longer valid, as I'm not at Samsung
anymore. I'm not sure what's the right thing to do with From and SOB in
this series, though.

If it's of any help, my private address (and the one I use for things I
maintain and any open source activity on my own) is this one.

Best regards,
Tomasz

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 21:08           ` Rafael J. Wysocki
@ 2014-09-08 20:53             ` Geert Uytterhoeven
  -1 siblings, 0 replies; 96+ messages in thread
From: Geert Uytterhoeven @ 2014-09-08 20:53 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mark Rutland, Ulf Hansson, Philipp Zabel, Geert Uytterhoeven,
	devicetree, Wolfram Sang, Linus Walleij, Chris Ball,
	Pavel Machek, Kukjin Kim, Russell King, Daniel Lezcano,
	Magnus Damm, ACPI Devel Maling List, Alan Stern, Len Brown,
	Kevin Hilman, Pawel Moll, linux-pm, Tomasz Figa, Simon Horman,
	Ben Dooks, linux-arm-ker

Hi Rafael,

On Mon, Sep 8, 2014 at 11:08 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> BTW, I get bounces from t.figa@samsung.com, so I won't apply the patch with
> that as the "From" field.  And the s-o-b from a bouncing address is worthless
> too.

In the mean time, Tomasz has moved:
http://www.spinics.net/lists/arm-kernel/msg357102.html

Still, the From/SoB indicate attribution to Samsung, so I think it should be
kept.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08 20:53             ` Tomasz Figa
  0 siblings, 0 replies; 96+ messages in thread
From: Tomasz Figa @ 2014-09-08 20:53 UTC (permalink / raw)
  To: linux-arm-kernel

On 08.09.2014 23:08, Rafael J. Wysocki wrote:
> On Monday, September 08, 2014 11:04:23 PM Rafael J. Wysocki wrote:
>> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
>>> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>>>> On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>>>>> From: Tomasz Figa <t.figa@samsung.com>
>>>>>
>>>>> This patch introduces generic code to perform PM domain look-up using
>>>>> device tree and automatically bind devices to their PM domains.
>>>>>
>>>>> Generic device tree bindings are introduced to specify PM domains of
>>>>> devices in their device tree nodes.
>>>>>
>>>>> Backwards compatibility with legacy Samsung-specific PM domain bindings
>>>>> is provided, but for now the new code is not compiled when
>>>>> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>>>>> This will change as soon as the Exynos PM domain code gets converted to
>>>>> use the generic framework in further patch.
>>>>>
>>>>> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>>>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>>>> [Ulf:Added attach|detach functions, fixed review comments]
>>>>> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>>>>
>>>> However, for this one (and consequently the rest) I need an ACK from the
>>>> people who maintain the bindings.
>>>
>>> These DT bindings have been discussed between Tomasz and devicetree
>>> maintainers previously. So I think there are fine.
>>>
>>> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
>>> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
>>>
>>> I realize that I didn't put the DT maintainers on the to-line when
>>> posting this patch, but just the devicetree list. I have now included
>>> them on this reply, but maybe I should repost instead. What do you
>>> think? Are you happy with the above ack from Rob?
>>
>> That should be sufficient, but I wonder why you didn't add it to the patch
>> to start with?
> 
> BTW, I get bounces from t.figa at samsung.com, so I won't apply the patch with
> that as the "From" field.  And the s-o-b from a bouncing address is worthless
> too.

Yes, that e-mail address is no longer valid, as I'm not at Samsung
anymore. I'm not sure what's the right thing to do with From and SOB in
this series, though.

If it's of any help, my private address (and the one I use for things I
maintain and any open source activity on my own) is this one.

Best regards,
Tomasz

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08 20:53             ` Geert Uytterhoeven
  0 siblings, 0 replies; 96+ messages in thread
From: Geert Uytterhoeven @ 2014-09-08 20:53 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Rafael,

On Mon, Sep 8, 2014 at 11:08 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> BTW, I get bounces from t.figa at samsung.com, so I won't apply the patch with
> that as the "From" field.  And the s-o-b from a bouncing address is worthless
> too.

In the mean time, Tomasz has moved:
http://www.spinics.net/lists/arm-kernel/msg357102.html

Still, the From/SoB indicate attribution to Samsung, so I think it should be
kept.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08  7:26       ` Ulf Hansson
@ 2014-09-08 21:04         ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:04 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rob Herring, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, ACPI Devel Maling List,
	Geert Uytterhoeven, Kevin Hilman, Alan Stern, Daniel Lezcano,
	devicetree, Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks,
	Kukjin Kim, Stephen Boyd, Philipp Zabel, Mark Brown,
	Wolfram Sang

On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> >> From: Tomasz Figa <t.figa@samsung.com>
> >>
> >> This patch introduces generic code to perform PM domain look-up using
> >> device tree and automatically bind devices to their PM domains.
> >>
> >> Generic device tree bindings are introduced to specify PM domains of
> >> devices in their device tree nodes.
> >>
> >> Backwards compatibility with legacy Samsung-specific PM domain bindings
> >> is provided, but for now the new code is not compiled when
> >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> >> This will change as soon as the Exynos PM domain code gets converted to
> >> use the generic framework in further patch.
> >>
> >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> >> [Ulf:Added attach|detach functions, fixed review comments]
> >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> >
> > However, for this one (and consequently the rest) I need an ACK from the
> > people who maintain the bindings.
> 
> These DT bindings have been discussed between Tomasz and devicetree
> maintainers previously. So I think there are fine.
> 
> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
> 
> I realize that I didn't put the DT maintainers on the to-line when
> posting this patch, but just the devicetree list. I have now included
> them on this reply, but maybe I should repost instead. What do you
> think? Are you happy with the above ack from Rob?

That should be sufficient, but I wonder why you didn't add it to the patch
to start with?

Rafael


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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08 21:04         ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:04 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> >> From: Tomasz Figa <t.figa@samsung.com>
> >>
> >> This patch introduces generic code to perform PM domain look-up using
> >> device tree and automatically bind devices to their PM domains.
> >>
> >> Generic device tree bindings are introduced to specify PM domains of
> >> devices in their device tree nodes.
> >>
> >> Backwards compatibility with legacy Samsung-specific PM domain bindings
> >> is provided, but for now the new code is not compiled when
> >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> >> This will change as soon as the Exynos PM domain code gets converted to
> >> use the generic framework in further patch.
> >>
> >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> >> [Ulf:Added attach|detach functions, fixed review comments]
> >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> >
> > However, for this one (and consequently the rest) I need an ACK from the
> > people who maintain the bindings.
> 
> These DT bindings have been discussed between Tomasz and devicetree
> maintainers previously. So I think there are fine.
> 
> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
> 
> I realize that I didn't put the DT maintainers on the to-line when
> posting this patch, but just the devicetree list. I have now included
> them on this reply, but maybe I should repost instead. What do you
> think? Are you happy with the above ack from Rob?

That should be sufficient, but I wonder why you didn't add it to the patch
to start with?

Rafael

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 21:04         ` Rafael J. Wysocki
@ 2014-09-08 21:08           ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:08 UTC (permalink / raw)
  To: Ulf Hansson, Pawel Moll
  Cc: Rob Herring, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, ACPI Devel Maling List,
	Geert Uytterhoeven, Kevin Hilman, Alan Stern, Daniel Lezcano,
	devicetree, Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks,
	Kukjin Kim, Stephen Boyd, Philipp Zabel, Mark Brown,
	Wolfram Sang

On Monday, September 08, 2014 11:04:23 PM Rafael J. Wysocki wrote:
> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
> > On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> > >> From: Tomasz Figa <t.figa@samsung.com>
> > >>
> > >> This patch introduces generic code to perform PM domain look-up using
> > >> device tree and automatically bind devices to their PM domains.
> > >>
> > >> Generic device tree bindings are introduced to specify PM domains of
> > >> devices in their device tree nodes.
> > >>
> > >> Backwards compatibility with legacy Samsung-specific PM domain bindings
> > >> is provided, but for now the new code is not compiled when
> > >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> > >> This will change as soon as the Exynos PM domain code gets converted to
> > >> use the generic framework in further patch.
> > >>
> > >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> > >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > >> [Ulf:Added attach|detach functions, fixed review comments]
> > >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> > >
> > > However, for this one (and consequently the rest) I need an ACK from the
> > > people who maintain the bindings.
> > 
> > These DT bindings have been discussed between Tomasz and devicetree
> > maintainers previously. So I think there are fine.
> > 
> > Also, when browsing the mail-archives, I found an ack from Rob Herrring:
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
> > 
> > I realize that I didn't put the DT maintainers on the to-line when
> > posting this patch, but just the devicetree list. I have now included
> > them on this reply, but maybe I should repost instead. What do you
> > think? Are you happy with the above ack from Rob?
> 
> That should be sufficient, but I wonder why you didn't add it to the patch
> to start with?

BTW, I get bounces from t.figa@samsung.com, so I won't apply the patch with
that as the "From" field.  And the s-o-b from a bouncing address is worthless
too.

Rafael


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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08 21:08           ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:08 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, September 08, 2014 11:04:23 PM Rafael J. Wysocki wrote:
> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
> > On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
> > >> From: Tomasz Figa <t.figa@samsung.com>
> > >>
> > >> This patch introduces generic code to perform PM domain look-up using
> > >> device tree and automatically bind devices to their PM domains.
> > >>
> > >> Generic device tree bindings are introduced to specify PM domains of
> > >> devices in their device tree nodes.
> > >>
> > >> Backwards compatibility with legacy Samsung-specific PM domain bindings
> > >> is provided, but for now the new code is not compiled when
> > >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
> > >> This will change as soon as the Exynos PM domain code gets converted to
> > >> use the generic framework in further patch.
> > >>
> > >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
> > >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > >> [Ulf:Added attach|detach functions, fixed review comments]
> > >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> > >
> > > However, for this one (and consequently the rest) I need an ACK from the
> > > people who maintain the bindings.
> > 
> > These DT bindings have been discussed between Tomasz and devicetree
> > maintainers previously. So I think there are fine.
> > 
> > Also, when browsing the mail-archives, I found an ack from Rob Herrring:
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
> > 
> > I realize that I didn't put the DT maintainers on the to-line when
> > posting this patch, but just the devicetree list. I have now included
> > them on this reply, but maybe I should repost instead. What do you
> > think? Are you happy with the above ack from Rob?
> 
> That should be sufficient, but I wonder why you didn't add it to the patch
> to start with?

BTW, I get bounces from t.figa at samsung.com, so I won't apply the patch with
that as the "From" field.  And the s-o-b from a bouncing address is worthless
too.

Rafael

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 20:53             ` Geert Uytterhoeven
@ 2014-09-08 21:26                 ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:26 UTC (permalink / raw)
  To: Geert Uytterhoeven, Ulf Hansson
  Cc: Pawel Moll, Rob Herring, Len Brown, Pavel Machek,
	Greg Kroah-Hartman, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	ACPI Devel Maling List, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, devicetree-u79uwXL29TY76Z2rM5mHXA,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown

On Monday, September 08, 2014 10:53:09 PM Geert Uytterhoeven wrote:
> Hi Rafael,
> 
> On Mon, Sep 8, 2014 at 11:08 PM, Rafael J. Wysocki <rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org> wrote:
> > BTW, I get bounces from t.figa-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, so I won't apply the patch with
> > that as the "From" field.  And the s-o-b from a bouncing address is worthless
> > too.
> 
> In the mean time, Tomasz has moved:
> http://www.spinics.net/lists/arm-kernel/msg357102.html
> 
> Still, the From/SoB indicate attribution to Samsung, so I think it should be
> kept.

The "From:" field should point to a submitter's address that is actually active,
so that (s)he can handle problem reports *sent* *to* *that* address.  I'm not
going to apply anything with a bouncing "From:".

The s-o-b is more of a gray area, but again it is supposed to be possible
to verify which it won't be if it bounces.

Also note that this is not Tomasz who is submitting this patch today, but Ulf
who doesn't even work for Samsung as far as I know.

So I'd suggest using "Tomasz Figa <tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>" as a "From:", remove
his s-o-b entirely (and using the Ulf's one only) and add something like that
to the changelog:

"This patch was originally submitted by Tomasz Figa when he was employed
 by Samsung.

 Link: <URL-of-the-original-submission>"

This way Samsung will get the recognition and there won't be bouncing addresses
in tags etc.

Rafael

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-08 21:26                 ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 21:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, September 08, 2014 10:53:09 PM Geert Uytterhoeven wrote:
> Hi Rafael,
> 
> On Mon, Sep 8, 2014 at 11:08 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > BTW, I get bounces from t.figa at samsung.com, so I won't apply the patch with
> > that as the "From" field.  And the s-o-b from a bouncing address is worthless
> > too.
> 
> In the mean time, Tomasz has moved:
> http://www.spinics.net/lists/arm-kernel/msg357102.html
> 
> Still, the From/SoB indicate attribution to Samsung, so I think it should be
> kept.

The "From:" field should point to a submitter's address that is actually active,
so that (s)he can handle problem reports *sent* *to* *that* address.  I'm not
going to apply anything with a bouncing "From:".

The s-o-b is more of a gray area, but again it is supposed to be possible
to verify which it won't be if it bounces.

Also note that this is not Tomasz who is submitting this patch today, but Ulf
who doesn't even work for Samsung as far as I know.

So I'd suggest using "Tomasz Figa <tomasz.figa@gmail.com>" as a "From:", remove
his s-o-b entirely (and using the Ulf's one only) and add something like that
to the changelog:

"This patch was originally submitted by Tomasz Figa when he was employed
 by Samsung.

 Link: <URL-of-the-original-submission>"

This way Samsung will get the recognition and there won't be bouncing addresses
in tags etc.

Rafael

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

* Re: [PATCH v3 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
  2014-09-04 13:52   ` Ulf Hansson
@ 2014-09-08 22:11     ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 22:11 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King

On Thursday, September 04, 2014 03:52:30 PM Ulf Hansson wrote:
> To maintain scalability let's add common methods to attach and detach
> a PM domain for a device, dev_pm_domain_attach|detach().
> 
> Typically dev_pm_domain_attach() shall be invoked from subsystem level
> code at the probe phase to try to attach a device to its PM domain.
> The reversed actions may be done a the remove phase and then by invoking
> dev_pm_domain_detach().
> 
> The supported PM domains at this point are the ACPI and the generic
> PM domains.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/base/power/common.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/pm.h          | 14 ++++++++++++
>  2 files changed, 70 insertions(+)
> 
> diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
> index df2e5ee..9a86b16 100644
> --- a/drivers/base/power/common.c
> +++ b/drivers/base/power/common.c
> @@ -11,6 +11,8 @@
>  #include <linux/export.h>
>  #include <linux/slab.h>
>  #include <linux/pm_clock.h>
> +#include <linux/acpi.h>
> +#include <linux/pm_domain.h>
>  
>  /**
>   * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
> @@ -82,3 +84,57 @@ int dev_pm_put_subsys_data(struct device *dev)
>  	return ret;
>  }
>  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.
> + *
> + * 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.
> + *
> + * This function should typically be invoked from subsystem level code during
> + * the probe phase. Especially for those that holds devices which requires
> + * power management through PM domains.
> + *
> + * Callers must ensure proper synchronization of this function with power
> + * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
> + */
> +int dev_pm_domain_attach(struct device *dev, bool power_on)
> +{
> +	int ret;
> +
> +	ret = acpi_dev_pm_attach(dev, power_on);
> +	if (!ret || ret == -EPROBE_DEFER)

acpi_dev_pm_attach() doesn't return EPROBE_DEFER and there are no plans for it
to do that.  IIRC, I pointed that out to you in the previous round (or even
earlier).  Please remove this check, it is pointless.

> +		return ret;
> +
> +	return genpd_dev_pm_attach(dev);

And why don't you write this as

	ret = acpi_dev_pm_attach(dev, power_on);
	if (ret)
		ret = genpd_dev_pm_attach(dev);

	return ret;

> +}
> +EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
> +
> +/**
> + * dev_pm_domain_detach - Detach a device from its PM domain.
> + * @dev: Device to attach.
> + * @power_off: Used to indicate whether we should power off the device.
> + *
> + * The @dev may be attached to a PM domain. By iterating through the available
> + * alternatives we detach it from its PM domain.
> + *
> + * This functions will reverse the actions from dev_pm_domain_attach() and thus
> + * detach the @dev from its PM domain. Typically it should be invoked from
> + * subsystem level code during the remove phase.
> + *
> + * Callers must ensure proper synchronization of this function with power
> + * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
> + */
> +int dev_pm_domain_detach(struct device *dev, bool power_off)
> +{
> +	if (acpi_dev_pm_detach(dev, power_off))
> +		return genpd_dev_pm_detach(dev);

And analogously here?  Or the other way around?  Just please make them both
look analogously.

> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 72c0fe0..8176b07 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -621,6 +621,20 @@ struct dev_pm_domain {
>  	struct dev_pm_ops	ops;
>  };
>  
> +#ifdef CONFIG_PM
> +extern int dev_pm_domain_attach(struct device *dev, bool power_on);
> +extern int dev_pm_domain_detach(struct device *dev, bool power_off);
> +#else
> +static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
> +{
> +	return -ENODEV;
> +}
> +static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
> +#endif
> +
>  /*
>   * The PM_EVENT_ messages are also used by drivers implementing the legacy
>   * suspend framework, based on the ->suspend() and ->resume() callbacks common
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v3 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
@ 2014-09-08 22:11     ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-08 22:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Thursday, September 04, 2014 03:52:30 PM Ulf Hansson wrote:
> To maintain scalability let's add common methods to attach and detach
> a PM domain for a device, dev_pm_domain_attach|detach().
> 
> Typically dev_pm_domain_attach() shall be invoked from subsystem level
> code at the probe phase to try to attach a device to its PM domain.
> The reversed actions may be done a the remove phase and then by invoking
> dev_pm_domain_detach().
> 
> The supported PM domains at this point are the ACPI and the generic
> PM domains.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/base/power/common.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/pm.h          | 14 ++++++++++++
>  2 files changed, 70 insertions(+)
> 
> diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
> index df2e5ee..9a86b16 100644
> --- a/drivers/base/power/common.c
> +++ b/drivers/base/power/common.c
> @@ -11,6 +11,8 @@
>  #include <linux/export.h>
>  #include <linux/slab.h>
>  #include <linux/pm_clock.h>
> +#include <linux/acpi.h>
> +#include <linux/pm_domain.h>
>  
>  /**
>   * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
> @@ -82,3 +84,57 @@ int dev_pm_put_subsys_data(struct device *dev)
>  	return ret;
>  }
>  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.
> + *
> + * 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.
> + *
> + * This function should typically be invoked from subsystem level code during
> + * the probe phase. Especially for those that holds devices which requires
> + * power management through PM domains.
> + *
> + * Callers must ensure proper synchronization of this function with power
> + * management callbacks.
> + *
> + * Returns 0 on successfully attached PM domain or negative error code.
> + */
> +int dev_pm_domain_attach(struct device *dev, bool power_on)
> +{
> +	int ret;
> +
> +	ret = acpi_dev_pm_attach(dev, power_on);
> +	if (!ret || ret == -EPROBE_DEFER)

acpi_dev_pm_attach() doesn't return EPROBE_DEFER and there are no plans for it
to do that.  IIRC, I pointed that out to you in the previous round (or even
earlier).  Please remove this check, it is pointless.

> +		return ret;
> +
> +	return genpd_dev_pm_attach(dev);

And why don't you write this as

	ret = acpi_dev_pm_attach(dev, power_on);
	if (ret)
		ret = genpd_dev_pm_attach(dev);

	return ret;

> +}
> +EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
> +
> +/**
> + * dev_pm_domain_detach - Detach a device from its PM domain.
> + * @dev: Device to attach.
> + * @power_off: Used to indicate whether we should power off the device.
> + *
> + * The @dev may be attached to a PM domain. By iterating through the available
> + * alternatives we detach it from its PM domain.
> + *
> + * This functions will reverse the actions from dev_pm_domain_attach() and thus
> + * detach the @dev from its PM domain. Typically it should be invoked from
> + * subsystem level code during the remove phase.
> + *
> + * Callers must ensure proper synchronization of this function with power
> + * management callbacks.
> + *
> + * Returns 0 on successfully detached PM domain or negative error code.
> + */
> +int dev_pm_domain_detach(struct device *dev, bool power_off)
> +{
> +	if (acpi_dev_pm_detach(dev, power_off))
> +		return genpd_dev_pm_detach(dev);

And analogously here?  Or the other way around?  Just please make them both
look analogously.

> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 72c0fe0..8176b07 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -621,6 +621,20 @@ struct dev_pm_domain {
>  	struct dev_pm_ops	ops;
>  };
>  
> +#ifdef CONFIG_PM
> +extern int dev_pm_domain_attach(struct device *dev, bool power_on);
> +extern int dev_pm_domain_detach(struct device *dev, bool power_off);
> +#else
> +static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
> +{
> +	return -ENODEV;
> +}
> +static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
> +{
> +	return -ENODEV;
> +}
> +#endif
> +
>  /*
>   * The PM_EVENT_ messages are also used by drivers implementing the legacy
>   * suspend framework, based on the ->suspend() and ->resume() callbacks common
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 21:04         ` Rafael J. Wysocki
@ 2014-09-09  7:04           ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09  7:04 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rob Herring, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, ACPI Devel Maling List,
	Geert Uytterhoeven, Kevin Hilman, Alan Stern, Daniel Lezcano,
	devicetree, Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks,
	Kukjin Kim, Stephen Boyd, Philipp Zabel, Mark Brown,
	Wolfram Sang

On 8 September 2014 23:04, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
>> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>> >> From: Tomasz Figa <t.figa@samsung.com>
>> >>
>> >> This patch introduces generic code to perform PM domain look-up using
>> >> device tree and automatically bind devices to their PM domains.
>> >>
>> >> Generic device tree bindings are introduced to specify PM domains of
>> >> devices in their device tree nodes.
>> >>
>> >> Backwards compatibility with legacy Samsung-specific PM domain bindings
>> >> is provided, but for now the new code is not compiled when
>> >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>> >> This will change as soon as the Exynos PM domain code gets converted to
>> >> use the generic framework in further patch.
>> >>
>> >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>> >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> >> [Ulf:Added attach|detach functions, fixed review comments]
>> >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>> >
>> > However, for this one (and consequently the rest) I need an ACK from the
>> > people who maintain the bindings.
>>
>> These DT bindings have been discussed between Tomasz and devicetree
>> maintainers previously. So I think there are fine.
>>
>> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
>> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
>>
>> I realize that I didn't put the DT maintainers on the to-line when
>> posting this patch, but just the devicetree list. I have now included
>> them on this reply, but maybe I should repost instead. What do you
>> think? Are you happy with the above ack from Rob?
>
> That should be sufficient, but I wonder why you didn't add it to the patch
> to start with?

I didn't remember it being formally acked, until I decided to browsed
the mail archives in detail. Sorry about that.

Kind regards
Uffe

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-09  7:04           ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09  7:04 UTC (permalink / raw)
  To: linux-arm-kernel

On 8 September 2014 23:04, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Monday, September 08, 2014 09:26:20 AM Ulf Hansson wrote:
>> On 8 September 2014 00:13, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> > On Thursday, September 04, 2014 03:52:29 PM Ulf Hansson wrote:
>> >> From: Tomasz Figa <t.figa@samsung.com>
>> >>
>> >> This patch introduces generic code to perform PM domain look-up using
>> >> device tree and automatically bind devices to their PM domains.
>> >>
>> >> Generic device tree bindings are introduced to specify PM domains of
>> >> devices in their device tree nodes.
>> >>
>> >> Backwards compatibility with legacy Samsung-specific PM domain bindings
>> >> is provided, but for now the new code is not compiled when
>> >> CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
>> >> This will change as soon as the Exynos PM domain code gets converted to
>> >> use the generic framework in further patch.
>> >>
>> >> Signed-off-by: Tomasz Figa <t.figa@samsung.com>
>> >> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> >> [Ulf:Added attach|detach functions, fixed review comments]
>> >> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
>> >
>> > However, for this one (and consequently the rest) I need an ACK from the
>> > people who maintain the bindings.
>>
>> These DT bindings have been discussed between Tomasz and devicetree
>> maintainers previously. So I think there are fine.
>>
>> Also, when browsing the mail-archives, I found an ack from Rob Herrring:
>> http://lists.infradead.org/pipermail/linux-arm-kernel/2014-March/237989.html
>>
>> I realize that I didn't put the DT maintainers on the to-line when
>> posting this patch, but just the devicetree list. I have now included
>> them on this reply, but maybe I should repost instead. What do you
>> think? Are you happy with the above ack from Rob?
>
> That should be sufficient, but I wonder why you didn't add it to the patch
> to start with?

I didn't remember it being formally acked, until I decided to browsed
the mail archives in detail. Sorry about that.

Kind regards
Uffe

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

* [PATCH v4 0/9] PM / Domains: Generic OF-based support
  2014-09-04 13:52 ` Ulf Hansson
@ 2014-09-09 11:36   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

Changes in v4:
	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
	  and updated the author and the commit message.
	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
	  a PM domain for a device".
	- Updated author and commit message for "ARM: exynos: Move to generic
	  PM domain DT bindings".
	- Added some acks and reviewed by tags.
	- Started to use the "--in-reply-to" option to git-send-email. It should
	  provide the option to show a better diffstat per patch.

Changes in v3:
	- Aligned on terminology, now using "PM domain" in comments and commit
	- messages/headers.
	- Improved English and grammar in comments and commit messages/headers.
	- Adopted proposal from Geert, to have compile-time-check wrapper
	  functions for the API that adds xlate_simple and xlate_onecell
	  providers.
 	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
	- Handle non-contiguous arrays for onecell PM domain providers.
	- Rebased the Exynos patch to follow the new genpd API changes.


Changes in v2:
	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
	- Updated some comments in code and in commit messages.
	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
	- Rebased the ARM Exynos patch.
	- Added some Tested-by tags.


This patchset has a bit of a history and some parts of it has been posted
earlier.

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html

In the first revision I intentially didn't increase version number of the
patches, since I think it would have cause more confusion than clarity.

A summary of changes in V1 and since the last patchset, from the link above:
	- Instead of letting driver core handling the device to power domain
	binding/unbinding, follow the behavior of how the ACPI power domain
	is handled.


This is a summary of what these patches are intended to do:

1)
Add generic power domain OF-based support which also includes APIs to handle
attach/detach of generic power domains to devices.

2)
Adding a common API to attach/detach power domains and include support for the
ACPI and the generic power domain in there.

3)
>From subsystem level code, at probe/remove, convert from invoking the ACPI
specific power domain attach/detach functions to the new common attach/detach
APIs.

4)
Add support for the AMBA bus to attach/detach power domains, using the new
common APIs.

5)
Convert Exynos to use the new generic power domain OF support.

Obviously, there are dependencies througout this patchset, which means if they
get accepted the all need to go together. It might also be convenient to share
them through an immutable branch.


Tomasz Figa (2):
  PM / Domains: Add generic OF-based PM domain look-up
  ARM: exynos: Move to generic PM domain DT bindings

Ulf Hansson (7):
  ACPI / PM: Let acpi_dev_pm_detach() return an error code
  PM / Domains: Add APIs to attach/detach a PM domain for a device
  drivercore / platform: Convert to dev_pm_domain_attach|detach()
  i2c: core: Convert to dev_pm_domain_attach|detach()
  mmc: sdio: Convert to dev_pm_domain_attach|detach()
  spi: core: Convert to dev_pm_domain_attach|detach()
  amba: Add support for attach/detach of PM domains

 .../bindings/arm/exynos/power_domain.txt           |  13 +-
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 arch/arm/mach-exynos/pm_domains.c                  |  78 +-----
 drivers/acpi/device_pm.c                           |   8 +-
 drivers/amba/bus.c                                 |  10 +-
 drivers/base/platform.c                            |  15 +-
 drivers/base/power/common.c                        |  60 +++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 drivers/i2c/i2c-core.c                             |  13 +-
 drivers/mmc/core/sdio_bus.c                        |   4 +-
 drivers/spi/spi.c                                  |  12 +-
 include/linux/acpi.h                               |   7 +-
 include/linux/pm.h                                 |  14 +
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 15 files changed, 528 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

-- 
1.9.1


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

* [PATCH v4 0/9] PM / Domains: Generic OF-based support
@ 2014-09-09 11:36   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

Changes in v4:
	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
	  and updated the author and the commit message.
	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
	  a PM domain for a device".
	- Updated author and commit message for "ARM: exynos: Move to generic
	  PM domain DT bindings".
	- Added some acks and reviewed by tags.
	- Started to use the "--in-reply-to" option to git-send-email. It should
	  provide the option to show a better diffstat per patch.

Changes in v3:
	- Aligned on terminology, now using "PM domain" in comments and commit
	- messages/headers.
	- Improved English and grammar in comments and commit messages/headers.
	- Adopted proposal from Geert, to have compile-time-check wrapper
	  functions for the API that adds xlate_simple and xlate_onecell
	  providers.
 	- Renamed "domain_num" to "num_domains", in genpd_onecell_data struct.
	- Handle non-contiguous arrays for onecell PM domain providers.
	- Rebased the Exynos patch to follow the new genpd API changes.


Changes in v2:
	- Fix the ACPI patch, it didn't even compile for CONFIG_ACPI.
	- Updated some comments in code and in commit messages.
	- Fixed the dev_pm_domain_attach API to handle EPROBE_DEFER properly.
	- Rebased the ARM Exynos patch.
	- Added some Tested-by tags.


This patchset has a bit of a history and some parts of it has been posted
earlier.

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-June/262725.html

In the first revision I intentially didn't increase version number of the
patches, since I think it would have cause more confusion than clarity.

A summary of changes in V1 and since the last patchset, from the link above:
	- Instead of letting driver core handling the device to power domain
	binding/unbinding, follow the behavior of how the ACPI power domain
	is handled.


This is a summary of what these patches are intended to do:

1)
Add generic power domain OF-based support which also includes APIs to handle
attach/detach of generic power domains to devices.

2)
Adding a common API to attach/detach power domains and include support for the
ACPI and the generic power domain in there.

3)
>From subsystem level code, at probe/remove, convert from invoking the ACPI
specific power domain attach/detach functions to the new common attach/detach
APIs.

4)
Add support for the AMBA bus to attach/detach power domains, using the new
common APIs.

5)
Convert Exynos to use the new generic power domain OF support.

Obviously, there are dependencies througout this patchset, which means if they
get accepted the all need to go together. It might also be convenient to share
them through an immutable branch.


Tomasz Figa (2):
  PM / Domains: Add generic OF-based PM domain look-up
  ARM: exynos: Move to generic PM domain DT bindings

Ulf Hansson (7):
  ACPI / PM: Let acpi_dev_pm_detach() return an error code
  PM / Domains: Add APIs to attach/detach a PM domain for a device
  drivercore / platform: Convert to dev_pm_domain_attach|detach()
  i2c: core: Convert to dev_pm_domain_attach|detach()
  mmc: sdio: Convert to dev_pm_domain_attach|detach()
  spi: core: Convert to dev_pm_domain_attach|detach()
  amba: Add support for attach/detach of PM domains

 .../bindings/arm/exynos/power_domain.txt           |  13 +-
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 arch/arm/mach-exynos/pm_domains.c                  |  78 +-----
 drivers/acpi/device_pm.c                           |   8 +-
 drivers/amba/bus.c                                 |  10 +-
 drivers/base/platform.c                            |  15 +-
 drivers/base/power/common.c                        |  60 +++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 drivers/i2c/i2c-core.c                             |  13 +-
 drivers/mmc/core/sdio_bus.c                        |   4 +-
 drivers/spi/spi.c                                  |  12 +-
 include/linux/acpi.h                               |   7 +-
 include/linux/pm.h                                 |  14 +
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 15 files changed, 528 insertions(+), 107 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

-- 
1.9.1

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

* [PATCH v4 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

To give callers the option of acting on a errors while removing the
pm_domain ops for the device in the ACPI PM domain, let
acpi_dev_pm_detach() return an int to provide the error code.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Pavel Machek <Pavel@ucw.cz>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/acpi/device_pm.c | 8 +++++++-
 include/linux/acpi.h     | 7 +++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 67075f8..0d52ce1 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
  */
 int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
@@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
  */
-void acpi_dev_pm_detach(struct device *dev, bool power_off)
+int acpi_dev_pm_detach(struct device *dev, bool power_off)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
 
@@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
 			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
 			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
 		}
+		return 0;
 	}
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
 #endif /* CONFIG_PM */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 807cbc4..c83cca5 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
 #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
 struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
 int acpi_dev_pm_attach(struct device *dev, bool power_on);
-void acpi_dev_pm_detach(struct device *dev, bool power_off);
+int acpi_dev_pm_detach(struct device *dev, bool power_off);
 #else
 static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
 {
@@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
 	return -ENODEV;
 }
-static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
+static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
 #endif
 
 #ifdef CONFIG_ACPI
-- 
1.9.1


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

* [PATCH v4 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

To give callers the option of acting on a errors while removing the
pm_domain ops for the device in the ACPI PM domain, let
acpi_dev_pm_detach() return an int to provide the error code.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Pavel Machek <Pavel@ucw.cz>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/acpi/device_pm.c | 8 +++++++-
 include/linux/acpi.h     | 7 +++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 67075f8..0d52ce1 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1055,6 +1055,8 @@ static struct dev_pm_domain acpi_general_pm_domain = {
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
  */
 int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
@@ -1087,8 +1089,10 @@ EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
  *
  * Callers must ensure proper synchronization of this function with power
  * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
  */
-void acpi_dev_pm_detach(struct device *dev, bool power_off)
+int acpi_dev_pm_detach(struct device *dev, bool power_off)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
 
@@ -1107,7 +1111,9 @@ void acpi_dev_pm_detach(struct device *dev, bool power_off)
 			acpi_device_wakeup(adev, ACPI_STATE_S0, false);
 			acpi_dev_pm_low_power(dev, adev, ACPI_STATE_S0);
 		}
+		return 0;
 	}
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(acpi_dev_pm_detach);
 #endif /* CONFIG_PM */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 807cbc4..c83cca5 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -587,7 +587,7 @@ static inline int acpi_subsys_freeze(struct device *dev) { return 0; }
 #if defined(CONFIG_ACPI) && defined(CONFIG_PM)
 struct acpi_device *acpi_dev_pm_get_node(struct device *dev);
 int acpi_dev_pm_attach(struct device *dev, bool power_on);
-void acpi_dev_pm_detach(struct device *dev, bool power_off);
+int acpi_dev_pm_detach(struct device *dev, bool power_off);
 #else
 static inline struct acpi_device *acpi_dev_pm_get_node(struct device *dev)
 {
@@ -597,7 +597,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
 {
 	return -ENODEV;
 }
-static inline void acpi_dev_pm_detach(struct device *dev, bool power_off) {}
+static inline int acpi_dev_pm_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
 #endif
 
 #ifdef CONFIG_ACPI
-- 
1.9.1

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

* [PATCH v4 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

From: Tomasz Figa <tomasz.figa@gmail.com>

This patch introduces generic code to perform PM domain look-up using
device tree and automatically bind devices to their PM domains.

Generic device tree bindings are introduced to specify PM domains of
devices in their device tree nodes.

Backwards compatibility with legacy Samsung-specific PM domain bindings
is provided, but for now the new code is not compiled when
CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
This will change as soon as the Exynos PM domain code gets converted to
use the generic framework in further patch.

This patch was originally submitted by Tomasz Figa when he was employed
by Samsung.
http://marc.info/?l=linux-pm&m=139955349702152&w=2

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 4 files changed, 401 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
new file mode 100644
index 0000000..98c1667
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -0,0 +1,49 @@
+* Generic PM domains
+
+System on chip designs are often divided into multiple PM domains that can be
+used for power gating of selected IP blocks for power saving by reduced leakage
+current.
+
+This device tree binding can be used to bind PM domain consumer devices with
+their PM domains provided by PM domain providers. A PM domain provider can be
+represented by any node in the device tree and can provide one or more PM
+domains. A consumer node can refer to the provider by a phandle and a set of
+phandle arguments (so called PM domain specifiers) of length specified by the
+#power-domain-cells property in the PM domain provider node.
+
+==PM domain providers==
+
+Required properties:
+ - #power-domain-cells : Number of cells in a PM domain specifier;
+   Typically 0 for nodes representing a single PM domain and 1 for nodes
+   providing multiple PM domains (e.g. power controllers), but can be any value
+   as specified by device tree binding documentation of particular provider.
+
+Example:
+
+	power: power-controller@12340000 {
+		compatible = "foo,power-controller";
+		reg = <0x12340000 0x1000>;
+		#power-domain-cells = <1>;
+	};
+
+The node above defines a power controller that is a PM domain provider and
+expects one cell as its phandle argument.
+
+==PM domain consumers==
+
+Required properties:
+ - power-domains : A phandle and PM domain specifier as defined by bindings of
+                   the power controller specified by phandle.
+
+Example:
+
+	leaky-device@12350000 {
+		compatible = "foo,i-leak-current";
+		reg = <0x12350000 0x1000>;
+		power-domains = <&power 0>;
+	};
+
+The node above defines a typical PM domain consumer device, which is located
+inside a PM domain with index 0 of a power controller represented by a node
+with the label "power".
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index cf4651a..f09b615 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -8,6 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_qos.h>
@@ -1933,3 +1934,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 	list_add(&genpd->gpd_list_node, &gpd_list);
 	mutex_unlock(&gpd_list_lock);
 }
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+/*
+ * Device Tree based PM domain providers.
+ *
+ * The code below implements generic device tree based PM domain providers that
+ * bind device tree nodes with generic PM domains registered in the system.
+ *
+ * Any driver that registers generic PM domains and needs to support binding of
+ * devices to these domains is supposed to register a PM domain provider, which
+ * maps a PM domain specifier retrieved from the device tree to a PM domain.
+ *
+ * Two simple mapping functions have been provided for convenience:
+ *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
+ *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
+ *    index.
+ */
+
+/**
+ * struct of_genpd_provider - PM domain provider registration structure
+ * @link: Entry in global list of PM domain providers
+ * @node: Pointer to device tree node of PM domain provider
+ * @xlate: Provider-specific xlate callback mapping a set of specifier cells
+ *         into a PM domain.
+ * @data: context pointer to be passed into @xlate callback
+ */
+struct of_genpd_provider {
+	struct list_head link;
+	struct device_node *node;
+	genpd_xlate_t xlate;
+	void *data;
+};
+
+/* List of registered PM domain providers. */
+static LIST_HEAD(of_genpd_providers);
+/* Mutex to protect the list above. */
+static DEFINE_MUTEX(of_genpd_mutex);
+
+/**
+ * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct generic_pm_domain
+ *
+ * This is a generic xlate function that can be used to model PM domains that
+ * have their own device tree nodes. The private data of xlate function needs
+ * to be a valid pointer to struct generic_pm_domain.
+ */
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	if (genpdspec->args_count != 0)
+		return ERR_PTR(-EINVAL);
+	return data;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
+
+/**
+ * __of_genpd_xlate_onecell() - Xlate function using a single index.
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct genpd_onecell_data
+ *
+ * This is a generic xlate function that can be used to model simple PM domain
+ * controllers that have one device tree node and provide multiple PM domains.
+ * A single cell is used as an index into an array of PM domains specified in
+ * the genpd_onecell_data struct when registering the provider.
+ */
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	struct genpd_onecell_data *genpd_data = data;
+	unsigned int idx = genpdspec->args[0];
+
+	if (genpdspec->args_count != 1)
+		return ERR_PTR(-EINVAL);
+
+	if (idx >= genpd_data->num_domains) {
+		pr_err("%s: invalid domain index %u\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	if (!genpd_data->domains[idx])
+		return ERR_PTR(-ENOENT);
+
+	return genpd_data->domains[idx];
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
+
+/**
+ * __of_genpd_add_provider() - Register a PM domain provider for a node
+ * @np: Device node pointer associated with the PM domain provider.
+ * @xlate: Callback for decoding PM domain from phandle arguments.
+ * @data: Context pointer for @xlate callback.
+ */
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data)
+{
+	struct of_genpd_provider *cp;
+
+	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->xlate = xlate;
+
+	mutex_lock(&of_genpd_mutex);
+	list_add(&cp->link, &of_genpd_providers);
+	mutex_unlock(&of_genpd_mutex);
+	pr_debug("Added domain provider from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
+
+/**
+ * of_genpd_del_provider() - Remove a previously registered PM domain provider
+ * @np: Device node pointer associated with the PM domain provider
+ */
+void of_genpd_del_provider(struct device_node *np)
+{
+	struct of_genpd_provider *cp;
+
+	mutex_lock(&of_genpd_mutex);
+	list_for_each_entry(cp, &of_genpd_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_genpd_mutex);
+}
+EXPORT_SYMBOL_GPL(of_genpd_del_provider);
+
+/**
+ * of_genpd_get_from_provider() - Look-up PM domain
+ * @genpdspec: OF phandle args to use for look-up
+ *
+ * Looks for a PM domain provider under the node specified by @genpdspec and if
+ * found, uses xlate function of the provider to map phandle args to a PM
+ * domain.
+ *
+ * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
+ * on failure.
+ */
+static struct generic_pm_domain *of_genpd_get_from_provider(
+					struct of_phandle_args *genpdspec)
+{
+	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
+	struct of_genpd_provider *provider;
+
+	mutex_lock(&of_genpd_mutex);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_genpd_providers, link) {
+		if (provider->node == genpdspec->np)
+			genpd = provider->xlate(genpdspec, provider->data);
+		if (!IS_ERR(genpd))
+			break;
+	}
+
+	mutex_unlock(&of_genpd_mutex);
+
+	return genpd;
+}
+
+/**
+ * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
+ * @dev: Device to attach.
+ *
+ * Parse device's OF node to find a PM domain specifier. If such is found,
+ * attaches the device to retrieved pm_domain ops.
+ *
+ * Both generic and legacy Samsung-specific DT bindings are supported to keep
+ * backwards compatibility with existing DTBs.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int genpd_dev_pm_attach(struct device *dev)
+{
+	struct of_phandle_args pd_args;
+	struct generic_pm_domain *pd;
+	int ret;
+
+	if (!dev->of_node)
+		return -ENODEV;
+
+	if (dev->pm_domain)
+		return -EEXIST;
+
+	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
+					"#power-domain-cells", 0, &pd_args);
+	if (ret < 0) {
+		if (ret != -ENOENT)
+			return ret;
+
+		/*
+		 * Try legacy Samsung-specific bindings
+		 * (for backwards compatibility of DT ABI)
+		 */
+		pd_args.args_count = 0;
+		pd_args.np = of_parse_phandle(dev->of_node,
+						"samsung,power-domain", 0);
+		if (!pd_args.np)
+			return -ENOENT;
+	}
+
+	pd = of_genpd_get_from_provider(&pd_args);
+	if (IS_ERR(pd)) {
+		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
+			__func__, PTR_ERR(pd));
+		of_node_put(dev->of_node);
+		return PTR_ERR(pd);
+	}
+
+	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_add_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to add to PM domain %s: %d",
+			pd->name, ret);
+		of_node_put(dev->of_node);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
+
+/**
+ * genpd_dev_pm_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ *
+ * Try to locate a corresponding generic PM domain, which the device was
+ * attached to previously. If such is found, the device is detached from it.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int genpd_dev_pm_detach(struct device *dev)
+{
+	struct generic_pm_domain *pd = NULL, *gpd;
+	int ret = 0;
+
+	if (!dev->pm_domain)
+		return -ENODEV;
+
+	mutex_lock(&gpd_list_lock);
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
+		if (&gpd->domain == dev->pm_domain) {
+			pd = gpd;
+			break;
+		}
+	}
+	mutex_unlock(&gpd_list_lock);
+
+	if (!pd)
+		return -ENOENT;
+
+	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_remove_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to remove from PM domain %s: %d",
+			pd->name, ret);
+		return ret;
+	}
+
+	/* Check if PM domain can be powered off after removing this device. */
+	genpd_queue_power_off_work(pd);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
+#endif
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index aa03586..ff128c1 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -264,4 +264,61 @@ static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
 #endif
 
+/* OF PM domain providers */
+struct of_device_id;
+
+struct genpd_onecell_data {
+	struct generic_pm_domain **domains;
+	unsigned int num_domains;
+};
+
+typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
+						void *data);
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data);
+void of_genpd_del_provider(struct device_node *np);
+
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data);
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data);
+
+int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_detach(struct device *dev);
+#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
+static inline int __of_genpd_add_provider(struct device_node *np,
+					genpd_xlate_t xlate, void *data)
+{
+	return 0;
+}
+static inline void of_genpd_del_provider(struct device_node *np) {}
+
+#define __of_genpd_xlate_simple		NULL
+#define __of_genpd_xlate_onecell	NULL
+
+static inline int genpd_dev_pm_attach(struct device *dev)
+{
+	return -ENODEV;
+}
+static inline int genpd_dev_pm_detach(struct device *dev)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
+
+static inline int of_genpd_add_provider_simple(struct device_node *np,
+					struct generic_pm_domain *genpd)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
+}
+static inline int of_genpd_add_provider_onecell(struct device_node *np,
+					struct genpd_onecell_data *data)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
+}
+
 #endif /* _LINUX_PM_DOMAIN_H */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index e4e4121..897619b 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
 	def_bool y
 	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
 
+config PM_GENERIC_DOMAINS_OF
+	def_bool y
+	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+
 config CPU_PM
 	bool
 	depends on SUSPEND || CPU_IDLE
-- 
1.9.1


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

* [PATCH v4 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

From: Tomasz Figa <tomasz.figa@gmail.com>

This patch introduces generic code to perform PM domain look-up using
device tree and automatically bind devices to their PM domains.

Generic device tree bindings are introduced to specify PM domains of
devices in their device tree nodes.

Backwards compatibility with legacy Samsung-specific PM domain bindings
is provided, but for now the new code is not compiled when
CONFIG_ARCH_EXYNOS is selected to avoid collision with legacy code.
This will change as soon as the Exynos PM domain code gets converted to
use the generic framework in further patch.

This patch was originally submitted by Tomasz Figa when he was employed
by Samsung.
http://marc.info/?l=linux-pm&m=139955349702152&w=2

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 .../devicetree/bindings/power/power_domain.txt     |  49 ++++
 drivers/base/power/domain.c                        | 291 +++++++++++++++++++++
 include/linux/pm_domain.h                          |  57 ++++
 kernel/power/Kconfig                               |   4 +
 4 files changed, 401 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/power_domain.txt

diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
new file mode 100644
index 0000000..98c1667
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -0,0 +1,49 @@
+* Generic PM domains
+
+System on chip designs are often divided into multiple PM domains that can be
+used for power gating of selected IP blocks for power saving by reduced leakage
+current.
+
+This device tree binding can be used to bind PM domain consumer devices with
+their PM domains provided by PM domain providers. A PM domain provider can be
+represented by any node in the device tree and can provide one or more PM
+domains. A consumer node can refer to the provider by a phandle and a set of
+phandle arguments (so called PM domain specifiers) of length specified by the
+#power-domain-cells property in the PM domain provider node.
+
+==PM domain providers==
+
+Required properties:
+ - #power-domain-cells : Number of cells in a PM domain specifier;
+   Typically 0 for nodes representing a single PM domain and 1 for nodes
+   providing multiple PM domains (e.g. power controllers), but can be any value
+   as specified by device tree binding documentation of particular provider.
+
+Example:
+
+	power: power-controller at 12340000 {
+		compatible = "foo,power-controller";
+		reg = <0x12340000 0x1000>;
+		#power-domain-cells = <1>;
+	};
+
+The node above defines a power controller that is a PM domain provider and
+expects one cell as its phandle argument.
+
+==PM domain consumers==
+
+Required properties:
+ - power-domains : A phandle and PM domain specifier as defined by bindings of
+                   the power controller specified by phandle.
+
+Example:
+
+	leaky-device at 12350000 {
+		compatible = "foo,i-leak-current";
+		reg = <0x12350000 0x1000>;
+		power-domains = <&power 0>;
+	};
+
+The node above defines a typical PM domain consumer device, which is located
+inside a PM domain with index 0 of a power controller represented by a node
+with the label "power".
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index cf4651a..f09b615 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -8,6 +8,7 @@
 
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_qos.h>
@@ -1933,3 +1934,293 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 	list_add(&genpd->gpd_list_node, &gpd_list);
 	mutex_unlock(&gpd_list_lock);
 }
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+/*
+ * Device Tree based PM domain providers.
+ *
+ * The code below implements generic device tree based PM domain providers that
+ * bind device tree nodes with generic PM domains registered in the system.
+ *
+ * Any driver that registers generic PM domains and needs to support binding of
+ * devices to these domains is supposed to register a PM domain provider, which
+ * maps a PM domain specifier retrieved from the device tree to a PM domain.
+ *
+ * Two simple mapping functions have been provided for convenience:
+ *  - __of_genpd_xlate_simple() for 1:1 device tree node to PM domain mapping.
+ *  - __of_genpd_xlate_onecell() for mapping of multiple PM domains per node by
+ *    index.
+ */
+
+/**
+ * struct of_genpd_provider - PM domain provider registration structure
+ * @link: Entry in global list of PM domain providers
+ * @node: Pointer to device tree node of PM domain provider
+ * @xlate: Provider-specific xlate callback mapping a set of specifier cells
+ *         into a PM domain.
+ * @data: context pointer to be passed into @xlate callback
+ */
+struct of_genpd_provider {
+	struct list_head link;
+	struct device_node *node;
+	genpd_xlate_t xlate;
+	void *data;
+};
+
+/* List of registered PM domain providers. */
+static LIST_HEAD(of_genpd_providers);
+/* Mutex to protect the list above. */
+static DEFINE_MUTEX(of_genpd_mutex);
+
+/**
+ * __of_genpd_xlate_simple() - Xlate function for direct node-domain mapping
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct generic_pm_domain
+ *
+ * This is a generic xlate function that can be used to model PM domains that
+ * have their own device tree nodes. The private data of xlate function needs
+ * to be a valid pointer to struct generic_pm_domain.
+ */
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	if (genpdspec->args_count != 0)
+		return ERR_PTR(-EINVAL);
+	return data;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_simple);
+
+/**
+ * __of_genpd_xlate_onecell() - Xlate function using a single index.
+ * @genpdspec: OF phandle args to map into a PM domain
+ * @data: xlate function private data - pointer to struct genpd_onecell_data
+ *
+ * This is a generic xlate function that can be used to model simple PM domain
+ * controllers that have one device tree node and provide multiple PM domains.
+ * A single cell is used as an index into an array of PM domains specified in
+ * the genpd_onecell_data struct when registering the provider.
+ */
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data)
+{
+	struct genpd_onecell_data *genpd_data = data;
+	unsigned int idx = genpdspec->args[0];
+
+	if (genpdspec->args_count != 1)
+		return ERR_PTR(-EINVAL);
+
+	if (idx >= genpd_data->num_domains) {
+		pr_err("%s: invalid domain index %u\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	if (!genpd_data->domains[idx])
+		return ERR_PTR(-ENOENT);
+
+	return genpd_data->domains[idx];
+}
+EXPORT_SYMBOL_GPL(__of_genpd_xlate_onecell);
+
+/**
+ * __of_genpd_add_provider() - Register a PM domain provider for a node
+ * @np: Device node pointer associated with the PM domain provider.
+ * @xlate: Callback for decoding PM domain from phandle arguments.
+ * @data: Context pointer for @xlate callback.
+ */
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data)
+{
+	struct of_genpd_provider *cp;
+
+	cp = kzalloc(sizeof(*cp), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->xlate = xlate;
+
+	mutex_lock(&of_genpd_mutex);
+	list_add(&cp->link, &of_genpd_providers);
+	mutex_unlock(&of_genpd_mutex);
+	pr_debug("Added domain provider from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__of_genpd_add_provider);
+
+/**
+ * of_genpd_del_provider() - Remove a previously registered PM domain provider
+ * @np: Device node pointer associated with the PM domain provider
+ */
+void of_genpd_del_provider(struct device_node *np)
+{
+	struct of_genpd_provider *cp;
+
+	mutex_lock(&of_genpd_mutex);
+	list_for_each_entry(cp, &of_genpd_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_genpd_mutex);
+}
+EXPORT_SYMBOL_GPL(of_genpd_del_provider);
+
+/**
+ * of_genpd_get_from_provider() - Look-up PM domain
+ * @genpdspec: OF phandle args to use for look-up
+ *
+ * Looks for a PM domain provider under the node specified by @genpdspec and if
+ * found, uses xlate function of the provider to map phandle args to a PM
+ * domain.
+ *
+ * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR()
+ * on failure.
+ */
+static struct generic_pm_domain *of_genpd_get_from_provider(
+					struct of_phandle_args *genpdspec)
+{
+	struct generic_pm_domain *genpd = ERR_PTR(-ENOENT);
+	struct of_genpd_provider *provider;
+
+	mutex_lock(&of_genpd_mutex);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_genpd_providers, link) {
+		if (provider->node == genpdspec->np)
+			genpd = provider->xlate(genpdspec, provider->data);
+		if (!IS_ERR(genpd))
+			break;
+	}
+
+	mutex_unlock(&of_genpd_mutex);
+
+	return genpd;
+}
+
+/**
+ * genpd_dev_pm_attach - Attach a device to its PM domain using DT.
+ * @dev: Device to attach.
+ *
+ * Parse device's OF node to find a PM domain specifier. If such is found,
+ * attaches the device to retrieved pm_domain ops.
+ *
+ * Both generic and legacy Samsung-specific DT bindings are supported to keep
+ * backwards compatibility with existing DTBs.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int genpd_dev_pm_attach(struct device *dev)
+{
+	struct of_phandle_args pd_args;
+	struct generic_pm_domain *pd;
+	int ret;
+
+	if (!dev->of_node)
+		return -ENODEV;
+
+	if (dev->pm_domain)
+		return -EEXIST;
+
+	ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
+					"#power-domain-cells", 0, &pd_args);
+	if (ret < 0) {
+		if (ret != -ENOENT)
+			return ret;
+
+		/*
+		 * Try legacy Samsung-specific bindings
+		 * (for backwards compatibility of DT ABI)
+		 */
+		pd_args.args_count = 0;
+		pd_args.np = of_parse_phandle(dev->of_node,
+						"samsung,power-domain", 0);
+		if (!pd_args.np)
+			return -ENOENT;
+	}
+
+	pd = of_genpd_get_from_provider(&pd_args);
+	if (IS_ERR(pd)) {
+		dev_dbg(dev, "%s() failed to find PM domain: %ld\n",
+			__func__, PTR_ERR(pd));
+		of_node_put(dev->of_node);
+		return PTR_ERR(pd);
+	}
+
+	dev_dbg(dev, "adding to PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_add_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to add to PM domain %s: %d",
+			pd->name, ret);
+		of_node_put(dev->of_node);
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
+
+/**
+ * genpd_dev_pm_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ *
+ * Try to locate a corresponding generic PM domain, which the device was
+ * attached to previously. If such is found, the device is detached from it.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int genpd_dev_pm_detach(struct device *dev)
+{
+	struct generic_pm_domain *pd = NULL, *gpd;
+	int ret = 0;
+
+	if (!dev->pm_domain)
+		return -ENODEV;
+
+	mutex_lock(&gpd_list_lock);
+	list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
+		if (&gpd->domain == dev->pm_domain) {
+			pd = gpd;
+			break;
+		}
+	}
+	mutex_unlock(&gpd_list_lock);
+
+	if (!pd)
+		return -ENOENT;
+
+	dev_dbg(dev, "removing from PM domain %s\n", pd->name);
+
+	while (1) {
+		ret = pm_genpd_remove_device(pd, dev);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
+
+	if (ret < 0) {
+		dev_err(dev, "failed to remove from PM domain %s: %d",
+			pd->name, ret);
+		return ret;
+	}
+
+	/* Check if PM domain can be powered off after removing this device. */
+	genpd_queue_power_off_work(pd);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_detach);
+#endif
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index aa03586..ff128c1 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -264,4 +264,61 @@ static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
 #endif
 
+/* OF PM domain providers */
+struct of_device_id;
+
+struct genpd_onecell_data {
+	struct generic_pm_domain **domains;
+	unsigned int num_domains;
+};
+
+typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
+						void *data);
+
+#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
+int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
+			void *data);
+void of_genpd_del_provider(struct device_node *np);
+
+struct generic_pm_domain *__of_genpd_xlate_simple(
+					struct of_phandle_args *genpdspec,
+					void *data);
+struct generic_pm_domain *__of_genpd_xlate_onecell(
+					struct of_phandle_args *genpdspec,
+					void *data);
+
+int genpd_dev_pm_attach(struct device *dev);
+int genpd_dev_pm_detach(struct device *dev);
+#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
+static inline int __of_genpd_add_provider(struct device_node *np,
+					genpd_xlate_t xlate, void *data)
+{
+	return 0;
+}
+static inline void of_genpd_del_provider(struct device_node *np) {}
+
+#define __of_genpd_xlate_simple		NULL
+#define __of_genpd_xlate_onecell	NULL
+
+static inline int genpd_dev_pm_attach(struct device *dev)
+{
+	return -ENODEV;
+}
+static inline int genpd_dev_pm_detach(struct device *dev)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
+
+static inline int of_genpd_add_provider_simple(struct device_node *np,
+					struct generic_pm_domain *genpd)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
+}
+static inline int of_genpd_add_provider_onecell(struct device_node *np,
+					struct genpd_onecell_data *data)
+{
+	return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
+}
+
 #endif /* _LINUX_PM_DOMAIN_H */
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index e4e4121..897619b 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -302,6 +302,10 @@ config PM_GENERIC_DOMAINS_RUNTIME
 	def_bool y
 	depends on PM_RUNTIME && PM_GENERIC_DOMAINS
 
+config PM_GENERIC_DOMAINS_OF
+	def_bool y
+	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+
 config CPU_PM
 	bool
 	depends on SUSPEND || CPU_IDLE
-- 
1.9.1

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

* [PATCH v4 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

To maintain scalability let's add common methods to attach and detach
a PM domain for a device, dev_pm_domain_attach|detach().

Typically dev_pm_domain_attach() shall be invoked from subsystem level
code at the probe phase to try to attach a device to its PM domain.
The reversed actions may be done a the remove phase and then by invoking
dev_pm_domain_detach().

The supported PM domains at this point are the ACPI and the generic
PM domains.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/base/power/common.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm.h          | 14 +++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index df2e5ee..6a2e05c 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -11,6 +11,8 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/pm_clock.h>
+#include <linux/acpi.h>
+#include <linux/pm_domain.h>
 
 /**
  * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
@@ -82,3 +84,61 @@ int dev_pm_put_subsys_data(struct device *dev)
 	return ret;
 }
 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.
+ *
+ * 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.
+ *
+ * This function should typically be invoked from subsystem level code during
+ * the probe phase. Especially for those that holds devices which requires
+ * power management through PM domains.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	int ret;
+
+	ret = acpi_dev_pm_attach(dev, power_on);
+	if (ret)
+		ret = genpd_dev_pm_attach(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
+
+/**
+ * dev_pm_domain_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ * @power_off: Used to indicate whether we should power off the device.
+ *
+ * The @dev may be attached to a PM domain. By iterating through the available
+ * alternatives we detach it from its PM domain.
+ *
+ * This functions will reverse the actions from dev_pm_domain_attach() and thus
+ * detach the @dev from its PM domain. Typically it should be invoked from
+ * subsystem level code during the remove phase.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	int ret;
+
+	ret = acpi_dev_pm_detach(dev, power_off);
+	if (ret)
+		ret = genpd_dev_pm_detach(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 72c0fe0..8176b07 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -621,6 +621,20 @@ struct dev_pm_domain {
 	struct dev_pm_ops	ops;
 };
 
+#ifdef CONFIG_PM
+extern int dev_pm_domain_attach(struct device *dev, bool power_on);
+extern int dev_pm_domain_detach(struct device *dev, bool power_off);
+#else
+static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	return -ENODEV;
+}
+static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
+#endif
+
 /*
  * The PM_EVENT_ messages are also used by drivers implementing the legacy
  * suspend framework, based on the ->suspend() and ->resume() callbacks common
-- 
1.9.1


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

* [PATCH v4 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

To maintain scalability let's add common methods to attach and detach
a PM domain for a device, dev_pm_domain_attach|detach().

Typically dev_pm_domain_attach() shall be invoked from subsystem level
code at the probe phase to try to attach a device to its PM domain.
The reversed actions may be done a the remove phase and then by invoking
dev_pm_domain_detach().

The supported PM domains at this point are the ACPI and the generic
PM domains.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/base/power/common.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm.h          | 14 +++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index df2e5ee..6a2e05c 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -11,6 +11,8 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/pm_clock.h>
+#include <linux/acpi.h>
+#include <linux/pm_domain.h>
 
 /**
  * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device.
@@ -82,3 +84,61 @@ int dev_pm_put_subsys_data(struct device *dev)
 	return ret;
 }
 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.
+ *
+ * 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.
+ *
+ * This function should typically be invoked from subsystem level code during
+ * the probe phase. Especially for those that holds devices which requires
+ * power management through PM domains.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully attached PM domain or negative error code.
+ */
+int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	int ret;
+
+	ret = acpi_dev_pm_attach(dev, power_on);
+	if (ret)
+		ret = genpd_dev_pm_attach(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
+
+/**
+ * dev_pm_domain_detach - Detach a device from its PM domain.
+ * @dev: Device to attach.
+ * @power_off: Used to indicate whether we should power off the device.
+ *
+ * The @dev may be attached to a PM domain. By iterating through the available
+ * alternatives we detach it from its PM domain.
+ *
+ * This functions will reverse the actions from dev_pm_domain_attach() and thus
+ * detach the @dev from its PM domain. Typically it should be invoked from
+ * subsystem level code during the remove phase.
+ *
+ * Callers must ensure proper synchronization of this function with power
+ * management callbacks.
+ *
+ * Returns 0 on successfully detached PM domain or negative error code.
+ */
+int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	int ret;
+
+	ret = acpi_dev_pm_detach(dev, power_off);
+	if (ret)
+		ret = genpd_dev_pm_detach(dev);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(dev_pm_domain_detach);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 72c0fe0..8176b07 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -621,6 +621,20 @@ struct dev_pm_domain {
 	struct dev_pm_ops	ops;
 };
 
+#ifdef CONFIG_PM
+extern int dev_pm_domain_attach(struct device *dev, bool power_on);
+extern int dev_pm_domain_detach(struct device *dev, bool power_off);
+#else
+static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
+{
+	return -ENODEV;
+}
+static inline int dev_pm_domain_detach(struct device *dev, bool power_off)
+{
+	return -ENODEV;
+}
+#endif
+
 /*
  * The PM_EVENT_ messages are also used by drivers implementing the legacy
  * suspend framework, based on the ->suspend() and ->resume() callbacks common
-- 
1.9.1

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

* [PATCH v4 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

Previously only the ACPI PM domain was supported by the platform bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/base/platform.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ab4f4ce..904be3d 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	acpi_dev_pm_attach(_dev, true);
-
-	ret = drv->probe(dev);
-	if (ret)
-		acpi_dev_pm_detach(_dev, true);
+	ret = dev_pm_domain_attach(_dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = drv->probe(dev);
+		if (ret)
+			dev_pm_domain_detach(_dev, true);
+	}
 
 	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
 		dev_warn(_dev, "probe deferral not supported\n");
@@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
 	int ret;
 
 	ret = drv->remove(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 
 	return ret;
 }
@@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 
 	drv->shutdown(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 }
 
 /**
-- 
1.9.1


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

* [PATCH v4 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the platform bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/base/platform.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index ab4f4ce..904be3d 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
 	if (ret < 0)
 		return ret;
 
-	acpi_dev_pm_attach(_dev, true);
-
-	ret = drv->probe(dev);
-	if (ret)
-		acpi_dev_pm_detach(_dev, true);
+	ret = dev_pm_domain_attach(_dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = drv->probe(dev);
+		if (ret)
+			dev_pm_domain_detach(_dev, true);
+	}
 
 	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
 		dev_warn(_dev, "probe deferral not supported\n");
@@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
 	int ret;
 
 	ret = drv->remove(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 
 	return ret;
 }
@@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
 	struct platform_device *dev = to_platform_device(_dev);
 
 	drv->shutdown(dev);
-	acpi_dev_pm_detach(_dev, true);
+	dev_pm_domain_detach(_dev, true);
 }
 
 /**
-- 
1.9.1

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

* [PATCH v4 5/9] i2c: core: Convert to dev_pm_domain_attach|detach()
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-i2c

Previously only the ACPI PM domain was supported by the i2c bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-i2c@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/i2c/i2c-core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 632057a..3cd8f11 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -279,10 +279,13 @@ static int i2c_device_probe(struct device *dev)
 	if (status < 0)
 		return status;
 
-	acpi_dev_pm_attach(&client->dev, true);
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
-	if (status)
-		acpi_dev_pm_detach(&client->dev, true);
+	status = dev_pm_domain_attach(&client->dev, true);
+	if (status != -EPROBE_DEFER) {
+		status = driver->probe(client, i2c_match_id(driver->id_table,
+					client));
+		if (status)
+			dev_pm_domain_detach(&client->dev, true);
+	}
 
 	return status;
 }
@@ -302,7 +305,7 @@ static int i2c_device_remove(struct device *dev)
 		status = driver->remove(client);
 	}
 
-	acpi_dev_pm_detach(&client->dev, true);
+	dev_pm_domain_detach(&client->dev, true);
 	return status;
 }
 
-- 
1.9.1


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

* [PATCH v4 5/9] i2c: core: Convert to dev_pm_domain_attach|detach()
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the i2c bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-i2c at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/i2c/i2c-core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 632057a..3cd8f11 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -279,10 +279,13 @@ static int i2c_device_probe(struct device *dev)
 	if (status < 0)
 		return status;
 
-	acpi_dev_pm_attach(&client->dev, true);
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
-	if (status)
-		acpi_dev_pm_detach(&client->dev, true);
+	status = dev_pm_domain_attach(&client->dev, true);
+	if (status != -EPROBE_DEFER) {
+		status = driver->probe(client, i2c_match_id(driver->id_table,
+					client));
+		if (status)
+			dev_pm_domain_detach(&client->dev, true);
+	}
 
 	return status;
 }
@@ -302,7 +305,7 @@ static int i2c_device_remove(struct device *dev)
 		status = driver->remove(client);
 	}
 
-	acpi_dev_pm_detach(&client->dev, true);
+	dev_pm_domain_detach(&client->dev, true);
 	return status;
 }
 
-- 
1.9.1

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

* [PATCH v4 6/9] mmc: sdio: Convert to dev_pm_domain_attach|detach()
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-mmc

Previously only the ACPI PM domain was supported by the sdio bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-mmc@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/mmc/core/sdio_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 4fa8fef9..1df0fc6 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -315,7 +315,7 @@ int sdio_add_func(struct sdio_func *func)
 	ret = device_add(&func->dev);
 	if (ret == 0) {
 		sdio_func_set_present(func);
-		acpi_dev_pm_attach(&func->dev, false);
+		dev_pm_domain_attach(&func->dev, false);
 	}
 
 	return ret;
@@ -332,7 +332,7 @@ void sdio_remove_func(struct sdio_func *func)
 	if (!sdio_func_present(func))
 		return;
 
-	acpi_dev_pm_detach(&func->dev, false);
+	dev_pm_domain_detach(&func->dev, false);
 	device_del(&func->dev);
 	put_device(&func->dev);
 }
-- 
1.9.1


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

* [PATCH v4 6/9] mmc: sdio: Convert to dev_pm_domain_attach|detach()
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the sdio bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-mmc at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/mmc/core/sdio_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 4fa8fef9..1df0fc6 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -315,7 +315,7 @@ int sdio_add_func(struct sdio_func *func)
 	ret = device_add(&func->dev);
 	if (ret == 0) {
 		sdio_func_set_present(func);
-		acpi_dev_pm_attach(&func->dev, false);
+		dev_pm_domain_attach(&func->dev, false);
 	}
 
 	return ret;
@@ -332,7 +332,7 @@ void sdio_remove_func(struct sdio_func *func)
 	if (!sdio_func_present(func))
 		return;
 
-	acpi_dev_pm_detach(&func->dev, false);
+	dev_pm_domain_detach(&func->dev, false);
 	device_del(&func->dev);
 	put_device(&func->dev);
 }
-- 
1.9.1

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

* [PATCH v4 7/9] spi: core: Convert to dev_pm_domain_attach|detach()
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson, linux-spi

Previously only the ACPI PM domain was supported by the spi bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-spi@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/spi/spi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ca935df..72a0beb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -264,10 +264,12 @@ static int spi_drv_probe(struct device *dev)
 	if (ret)
 		return ret;
 
-	acpi_dev_pm_attach(dev, true);
-	ret = sdrv->probe(to_spi_device(dev));
-	if (ret)
-		acpi_dev_pm_detach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = sdrv->probe(to_spi_device(dev));
+		if (ret)
+			dev_pm_domain_detach(dev, true);
+	}
 
 	return ret;
 }
@@ -278,7 +280,7 @@ static int spi_drv_remove(struct device *dev)
 	int ret;
 
 	ret = sdrv->remove(to_spi_device(dev));
-	acpi_dev_pm_detach(dev, true);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v4 7/9] spi: core: Convert to dev_pm_domain_attach|detach()
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

Previously only the ACPI PM domain was supported by the spi bus.

Let's convert to the common attach/detach functions for PM domains,
which currently means we are extending the support to include the
generic PM domain as well.

Cc: linux-spi at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/spi/spi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ca935df..72a0beb 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -264,10 +264,12 @@ static int spi_drv_probe(struct device *dev)
 	if (ret)
 		return ret;
 
-	acpi_dev_pm_attach(dev, true);
-	ret = sdrv->probe(to_spi_device(dev));
-	if (ret)
-		acpi_dev_pm_detach(dev, true);
+	ret = dev_pm_domain_attach(dev, true);
+	if (ret != -EPROBE_DEFER) {
+		ret = sdrv->probe(to_spi_device(dev));
+		if (ret)
+			dev_pm_domain_detach(dev, true);
+	}
 
 	return ret;
 }
@@ -278,7 +280,7 @@ static int spi_drv_remove(struct device *dev)
 	int ret;
 
 	ret = sdrv->remove(to_spi_device(dev));
-	acpi_dev_pm_detach(dev, true);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1

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

* [PATCH v4 8/9] amba: Add support for attach/detach of PM domains
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, Ulf Hansson

AMBA devices may on some SoCs resides in PM domains. To be able to
manage these devices from there, let's try to attach devices to their
corresponding PM domain during the probe phase.

To reverse these actions at the remove phase, we try to detach the
device from its PM domain.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/amba/bus.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3cf61a1..8f52393 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -182,9 +182,15 @@ static int amba_probe(struct device *dev)
 	int ret;
 
 	do {
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret == -EPROBE_DEFER)
+			break;
+
 		ret = amba_get_enable_pclk(pcdev);
-		if (ret)
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
 			break;
+		}
 
 		pm_runtime_get_noresume(dev);
 		pm_runtime_set_active(dev);
@@ -199,6 +205,7 @@ static int amba_probe(struct device *dev)
 		pm_runtime_put_noidle(dev);
 
 		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
 	} while (0);
 
 	return ret;
@@ -220,6 +227,7 @@ static int amba_remove(struct device *dev)
 	pm_runtime_put_noidle(dev);
 
 	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1


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

* [PATCH v4 8/9] amba: Add support for attach/detach of PM domains
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

AMBA devices may on some SoCs resides in PM domains. To be able to
manage these devices from there, let's try to attach devices to their
corresponding PM domain during the probe phase.

To reverse these actions at the remove phase, we try to detach the
device from its PM domain.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 drivers/amba/bus.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3cf61a1..8f52393 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -182,9 +182,15 @@ static int amba_probe(struct device *dev)
 	int ret;
 
 	do {
+		ret = dev_pm_domain_attach(dev, true);
+		if (ret == -EPROBE_DEFER)
+			break;
+
 		ret = amba_get_enable_pclk(pcdev);
-		if (ret)
+		if (ret) {
+			dev_pm_domain_detach(dev, true);
 			break;
+		}
 
 		pm_runtime_get_noresume(dev);
 		pm_runtime_set_active(dev);
@@ -199,6 +205,7 @@ static int amba_probe(struct device *dev)
 		pm_runtime_put_noidle(dev);
 
 		amba_put_disable_pclk(pcdev);
+		dev_pm_domain_detach(dev, true);
 	} while (0);
 
 	return ret;
@@ -220,6 +227,7 @@ static int amba_remove(struct device *dev)
 	pm_runtime_put_noidle(dev);
 
 	amba_put_disable_pclk(pcdev);
+	dev_pm_domain_detach(dev, true);
 
 	return ret;
 }
-- 
1.9.1

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

* [PATCH v4 9/9] ARM: exynos: Move to generic PM domain DT bindings
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:36     ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, Tomasz Figa, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd, Philipp Zabel, Mark Brown, Wolfram Sang,
	Chris Ball, Russell King, linux-samsung-soc, Ulf Hansson

From: Tomasz Figa <tomasz.figa@gmail.com>

This patch moves Exynos PM domain code to use the new generic PM domain
look-up framework introduced in previous patches, thus also allowing
the new code to be compiled with CONFIG_ARCH_EXYNOS.

This patch was originally submitted by Tomasz Figa when he was employed
by Samsung.
http://marc.info/?l=linux-pm&m=139955336002083&w=2

Cc: linux-samsung-soc@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 .../bindings/arm/exynos/power_domain.txt           | 13 ++--
 arch/arm/mach-exynos/pm_domains.c                  | 78 +---------------------
 kernel/power/Kconfig                               |  2 +-
 3 files changed, 8 insertions(+), 85 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
index 8b4f7b7f..abde1ea 100644
--- a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
+++ b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
@@ -8,6 +8,8 @@ Required Properties:
     * samsung,exynos4210-pd - for exynos4210 type power domain.
 - reg: physical base address of the controller and length of memory mapped
     region.
+- #power-domain-cells: number of cells in power domain specifier;
+    must be 0.
 
 Optional Properties:
 - clocks: List of clock handles. The parent clocks of the input clocks to the
@@ -29,6 +31,7 @@ Example:
 	lcd0: power-domain-lcd0 {
 		compatible = "samsung,exynos4210-pd";
 		reg = <0x10023C00 0x10>;
+		#power-domain-cells = <0>;
 	};
 
 	mfc_pd: power-domain@10044060 {
@@ -37,12 +40,8 @@ Example:
 		clocks = <&clock CLK_FIN_PLL>, <&clock CLK_MOUT_SW_ACLK333>,
 			<&clock CLK_MOUT_USER_ACLK333>;
 		clock-names = "oscclk", "pclk0", "clk0";
+		#power-domain-cells = <0>;
 	};
 
-Example of the node using power domain:
-
-	node {
-		/* ... */
-		samsung,power-domain = <&lcd0>;
-		/* ... */
-	};
+See Documentation/devicetree/bindings/power/power_domain.txt for description
+of consumer-side bindings.
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index fd76e1b..20f2671 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -105,78 +105,6 @@ static int exynos_pd_power_off(struct generic_pm_domain *domain)
 	return exynos_pd_power(domain, false);
 }
 
-static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
-					 struct device *dev)
-{
-	int ret;
-
-	dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
-
-	while (1) {
-		ret = pm_genpd_add_device(&pd->pd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-
-	pm_genpd_dev_need_restore(dev, true);
-}
-
-static void exynos_remove_device_from_domain(struct device *dev)
-{
-	struct generic_pm_domain *genpd = dev_to_genpd(dev);
-	int ret;
-
-	dev_dbg(dev, "removing from power domain %s\n", genpd->name);
-
-	while (1) {
-		ret = pm_genpd_remove_device(genpd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-}
-
-static void exynos_read_domain_from_dt(struct device *dev)
-{
-	struct platform_device *pd_pdev;
-	struct exynos_pm_domain *pd;
-	struct device_node *node;
-
-	node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
-	if (!node)
-		return;
-	pd_pdev = of_find_device_by_node(node);
-	if (!pd_pdev)
-		return;
-	pd = platform_get_drvdata(pd_pdev);
-	exynos_add_device_to_domain(pd, dev);
-}
-
-static int exynos_pm_notifier_call(struct notifier_block *nb,
-				    unsigned long event, void *data)
-{
-	struct device *dev = data;
-
-	switch (event) {
-	case BUS_NOTIFY_BIND_DRIVER:
-		if (dev->of_node)
-			exynos_read_domain_from_dt(dev);
-
-		break;
-
-	case BUS_NOTIFY_UNBOUND_DRIVER:
-		exynos_remove_device_from_domain(dev);
-
-		break;
-	}
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block platform_nb = {
-	.notifier_call = exynos_pm_notifier_call,
-};
-
 static __init int exynos4_pm_init_power_domain(void)
 {
 	struct platform_device *pdev;
@@ -202,7 +130,6 @@ static __init int exynos4_pm_init_power_domain(void)
 		pd->base = of_iomap(np, 0);
 		pd->pd.power_off = exynos_pd_power_off;
 		pd->pd.power_on = exynos_pd_power_on;
-		pd->pd.of_node = np;
 
 		pd->oscclk = clk_get(dev, "oscclk");
 		if (IS_ERR(pd->oscclk))
@@ -228,15 +155,12 @@ static __init int exynos4_pm_init_power_domain(void)
 			clk_put(pd->oscclk);
 
 no_clk:
-		platform_set_drvdata(pdev, pd);
-
 		on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
 
 		pm_genpd_init(&pd->pd, NULL, !on);
+		of_genpd_add_provider_simple(np, &pd->pd);
 	}
 
-	bus_register_notifier(&platform_bus_type, &platform_nb);
-
 	return 0;
 }
 arch_initcall(exynos4_pm_init_power_domain);
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 897619b..bbef57f 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -304,7 +304,7 @@ config PM_GENERIC_DOMAINS_RUNTIME
 
 config PM_GENERIC_DOMAINS_OF
 	def_bool y
-	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+	depends on PM_GENERIC_DOMAINS && OF
 
 config CPU_PM
 	bool
-- 
1.9.1

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

* [PATCH v4 9/9] ARM: exynos: Move to generic PM domain DT bindings
@ 2014-09-09 11:36     ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 11:36 UTC (permalink / raw)
  To: linux-arm-kernel

From: Tomasz Figa <tomasz.figa@gmail.com>

This patch moves Exynos PM domain code to use the new generic PM domain
look-up framework introduced in previous patches, thus also allowing
the new code to be compiled with CONFIG_ARCH_EXYNOS.

This patch was originally submitted by Tomasz Figa when he was employed
by Samsung.
http://marc.info/?l=linux-pm&m=139955336002083&w=2

Cc: linux-samsung-soc at vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Kevin Hilman <khilman@linaro.org>
---
 .../bindings/arm/exynos/power_domain.txt           | 13 ++--
 arch/arm/mach-exynos/pm_domains.c                  | 78 +---------------------
 kernel/power/Kconfig                               |  2 +-
 3 files changed, 8 insertions(+), 85 deletions(-)

diff --git a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
index 8b4f7b7f..abde1ea 100644
--- a/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
+++ b/Documentation/devicetree/bindings/arm/exynos/power_domain.txt
@@ -8,6 +8,8 @@ Required Properties:
     * samsung,exynos4210-pd - for exynos4210 type power domain.
 - reg: physical base address of the controller and length of memory mapped
     region.
+- #power-domain-cells: number of cells in power domain specifier;
+    must be 0.
 
 Optional Properties:
 - clocks: List of clock handles. The parent clocks of the input clocks to the
@@ -29,6 +31,7 @@ Example:
 	lcd0: power-domain-lcd0 {
 		compatible = "samsung,exynos4210-pd";
 		reg = <0x10023C00 0x10>;
+		#power-domain-cells = <0>;
 	};
 
 	mfc_pd: power-domain at 10044060 {
@@ -37,12 +40,8 @@ Example:
 		clocks = <&clock CLK_FIN_PLL>, <&clock CLK_MOUT_SW_ACLK333>,
 			<&clock CLK_MOUT_USER_ACLK333>;
 		clock-names = "oscclk", "pclk0", "clk0";
+		#power-domain-cells = <0>;
 	};
 
-Example of the node using power domain:
-
-	node {
-		/* ... */
-		samsung,power-domain = <&lcd0>;
-		/* ... */
-	};
+See Documentation/devicetree/bindings/power/power_domain.txt for description
+of consumer-side bindings.
diff --git a/arch/arm/mach-exynos/pm_domains.c b/arch/arm/mach-exynos/pm_domains.c
index fd76e1b..20f2671 100644
--- a/arch/arm/mach-exynos/pm_domains.c
+++ b/arch/arm/mach-exynos/pm_domains.c
@@ -105,78 +105,6 @@ static int exynos_pd_power_off(struct generic_pm_domain *domain)
 	return exynos_pd_power(domain, false);
 }
 
-static void exynos_add_device_to_domain(struct exynos_pm_domain *pd,
-					 struct device *dev)
-{
-	int ret;
-
-	dev_dbg(dev, "adding to power domain %s\n", pd->pd.name);
-
-	while (1) {
-		ret = pm_genpd_add_device(&pd->pd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-
-	pm_genpd_dev_need_restore(dev, true);
-}
-
-static void exynos_remove_device_from_domain(struct device *dev)
-{
-	struct generic_pm_domain *genpd = dev_to_genpd(dev);
-	int ret;
-
-	dev_dbg(dev, "removing from power domain %s\n", genpd->name);
-
-	while (1) {
-		ret = pm_genpd_remove_device(genpd, dev);
-		if (ret != -EAGAIN)
-			break;
-		cond_resched();
-	}
-}
-
-static void exynos_read_domain_from_dt(struct device *dev)
-{
-	struct platform_device *pd_pdev;
-	struct exynos_pm_domain *pd;
-	struct device_node *node;
-
-	node = of_parse_phandle(dev->of_node, "samsung,power-domain", 0);
-	if (!node)
-		return;
-	pd_pdev = of_find_device_by_node(node);
-	if (!pd_pdev)
-		return;
-	pd = platform_get_drvdata(pd_pdev);
-	exynos_add_device_to_domain(pd, dev);
-}
-
-static int exynos_pm_notifier_call(struct notifier_block *nb,
-				    unsigned long event, void *data)
-{
-	struct device *dev = data;
-
-	switch (event) {
-	case BUS_NOTIFY_BIND_DRIVER:
-		if (dev->of_node)
-			exynos_read_domain_from_dt(dev);
-
-		break;
-
-	case BUS_NOTIFY_UNBOUND_DRIVER:
-		exynos_remove_device_from_domain(dev);
-
-		break;
-	}
-	return NOTIFY_DONE;
-}
-
-static struct notifier_block platform_nb = {
-	.notifier_call = exynos_pm_notifier_call,
-};
-
 static __init int exynos4_pm_init_power_domain(void)
 {
 	struct platform_device *pdev;
@@ -202,7 +130,6 @@ static __init int exynos4_pm_init_power_domain(void)
 		pd->base = of_iomap(np, 0);
 		pd->pd.power_off = exynos_pd_power_off;
 		pd->pd.power_on = exynos_pd_power_on;
-		pd->pd.of_node = np;
 
 		pd->oscclk = clk_get(dev, "oscclk");
 		if (IS_ERR(pd->oscclk))
@@ -228,15 +155,12 @@ static __init int exynos4_pm_init_power_domain(void)
 			clk_put(pd->oscclk);
 
 no_clk:
-		platform_set_drvdata(pdev, pd);
-
 		on = __raw_readl(pd->base + 0x4) & INT_LOCAL_PWR_EN;
 
 		pm_genpd_init(&pd->pd, NULL, !on);
+		of_genpd_add_provider_simple(np, &pd->pd);
 	}
 
-	bus_register_notifier(&platform_bus_type, &platform_nb);
-
 	return 0;
 }
 arch_initcall(exynos4_pm_init_power_domain);
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 897619b..bbef57f 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -304,7 +304,7 @@ config PM_GENERIC_DOMAINS_RUNTIME
 
 config PM_GENERIC_DOMAINS_OF
 	def_bool y
-	depends on PM_GENERIC_DOMAINS && OF && !ARCH_EXYNOS
+	depends on PM_GENERIC_DOMAINS && OF
 
 config CPU_PM
 	bool
-- 
1.9.1

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-08 21:26                 ` Rafael J. Wysocki
@ 2014-09-09 11:40                   ` Mark Brown
  -1 siblings, 0 replies; 96+ messages in thread
From: Mark Brown @ 2014-09-09 11:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Geert Uytterhoeven, Ulf Hansson, Pawel Moll, Rob Herring,
	Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, ACPI Devel Maling List, Geert Uytterhoeven,
	Kevin Hilman, Alan Stern, Daniel Lezcano, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd

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

On Mon, Sep 08, 2014 at 11:26:49PM +0200, Rafael J. Wysocki wrote:

> The s-o-b is more of a gray area, but again it is supposed to be possible
> to verify which it won't be if it bounces.

That's always going to be an issue with signoffs - people's addresses
can and do go bad at any point.

> Also note that this is not Tomasz who is submitting this patch today, but Ulf
> who doesn't even work for Samsung as far as I know.

> So I'd suggest using "Tomasz Figa <tomasz.figa@gmail.com>" as a "From:", remove
> his s-o-b entirely (and using the Ulf's one only) and add something like that
> to the changelog:

> "This patch was originally submitted by Tomasz Figa when he was employed
>  by Samsung.

>  Link: <URL-of-the-original-submission>"

> This way Samsung will get the recognition and there won't be bouncing addresses
> in tags etc.

Stripping people's signoffs seems more worrying than a bouncing address
TBH - it's more alarming to see a commit log that's missing an author
signoff than finding an address that doesn't work, I'd probably just
drop any submissions that did that.  If you're really worried updating
the signoff address or adding a comment with the new one is probably
better.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-09 11:40                   ` Mark Brown
  0 siblings, 0 replies; 96+ messages in thread
From: Mark Brown @ 2014-09-09 11:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Sep 08, 2014 at 11:26:49PM +0200, Rafael J. Wysocki wrote:

> The s-o-b is more of a gray area, but again it is supposed to be possible
> to verify which it won't be if it bounces.

That's always going to be an issue with signoffs - people's addresses
can and do go bad at any point.

> Also note that this is not Tomasz who is submitting this patch today, but Ulf
> who doesn't even work for Samsung as far as I know.

> So I'd suggest using "Tomasz Figa <tomasz.figa@gmail.com>" as a "From:", remove
> his s-o-b entirely (and using the Ulf's one only) and add something like that
> to the changelog:

> "This patch was originally submitted by Tomasz Figa when he was employed
>  by Samsung.

>  Link: <URL-of-the-original-submission>"

> This way Samsung will get the recognition and there won't be bouncing addresses
> in tags etc.

Stripping people's signoffs seems more worrying than a bouncing address
TBH - it's more alarming to see a commit log that's missing an author
signoff than finding an address that doesn't work, I'd probably just
drop any submissions that did that.  If you're really worried updating
the signoff address or adding a comment with the new one is probably
better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140909/55ad43ef/attachment-0001.sig>

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

* Re: [PATCH v4 0/9] PM / Domains: Generic OF-based support
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:43     ` Tomasz Figa
  -1 siblings, 0 replies; 96+ messages in thread
From: Tomasz Figa @ 2014-09-09 11:43 UTC (permalink / raw)
  To: Ulf Hansson, Rafael J. Wysocki, Len Brown, Pavel Machek,
	Greg Kroah-Hartman, linux-pm
  Cc: linux-arm-kernel, linux-acpi, Geert Uytterhoeven, Kevin Hilman,
	Alan Stern, Daniel Lezcano, devicetree, Linus Walleij,
	Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim, Stephen Boyd,
	Philipp Zabel, Mark Brown, Wolfram Sang, Chris Ball,
	Russell King

Hi Ulf,

On 09.09.2014 13:36, Ulf Hansson wrote:
> Changes in v4:
> 	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
> 	  and updated the author and the commit message.
> 	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
> 	  a PM domain for a device".
> 	- Updated author and commit message for "ARM: exynos: Move to generic
> 	  PM domain DT bindings".
> 	- Added some acks and reviewed by tags.
> 	- Started to use the "--in-reply-to" option to git-send-email. It should
> 	  provide the option to show a better diffstat per patch.
> 

I guess this series doesn't need more tags, but, anyway, it looks good
to me. Thanks a lot for taking care of it.

Best regards,
Tomasz

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

* [PATCH v4 0/9] PM / Domains: Generic OF-based support
@ 2014-09-09 11:43     ` Tomasz Figa
  0 siblings, 0 replies; 96+ messages in thread
From: Tomasz Figa @ 2014-09-09 11:43 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Ulf,

On 09.09.2014 13:36, Ulf Hansson wrote:
> Changes in v4:
> 	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
> 	  and updated the author and the commit message.
> 	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
> 	  a PM domain for a device".
> 	- Updated author and commit message for "ARM: exynos: Move to generic
> 	  PM domain DT bindings".
> 	- Added some acks and reviewed by tags.
> 	- Started to use the "--in-reply-to" option to git-send-email. It should
> 	  provide the option to show a better diffstat per patch.
> 

I guess this series doesn't need more tags, but, anyway, it looks good
to me. Thanks a lot for taking care of it.

Best regards,
Tomasz

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

* Re: [PATCH v4 0/9] PM / Domains: Generic OF-based support
  2014-09-09 11:36   ` Ulf Hansson
@ 2014-09-09 11:54     ` Mark Brown
  -1 siblings, 0 replies; 96+ messages in thread
From: Mark Brown @ 2014-09-09 11:54 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, linux-acpi, Geert Uytterhoeven,
	Kevin Hilman, Alan Stern, Daniel Lezcano, Tomasz Figa,
	devicetree, Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks,
	Kukjin Kim, Stephen Boyd, Philipp Zabel, Wolfram Sang,
	Chris Ball, Russell King

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

On Tue, Sep 09, 2014 at 01:36:01PM +0200, Ulf Hansson wrote:
> Changes in v4:
> 	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
> 	  and updated the author and the commit message.
> 	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
> 	  a PM domain for a device".
> 	- Updated author and commit message for "ARM: exynos: Move to generic
> 	  PM domain DT bindings".
> 	- Added some acks and reviewed by tags.
> 	- Started to use the "--in-reply-to" option to git-send-email. It should
> 	  provide the option to show a better diffstat per patch.

Please don't send serieses in reply to earlier versions, it buries
things in the middle of old discussions which can mean they don't get
noticed, especially when you're sending multiple large patch serieses at
the same time.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* [PATCH v4 0/9] PM / Domains: Generic OF-based support
@ 2014-09-09 11:54     ` Mark Brown
  0 siblings, 0 replies; 96+ messages in thread
From: Mark Brown @ 2014-09-09 11:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Sep 09, 2014 at 01:36:01PM +0200, Ulf Hansson wrote:
> Changes in v4:
> 	- Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
> 	  and updated the author and the commit message.
> 	- Adopted review comments for "PM / Domains: Add APIs to attach/detach
> 	  a PM domain for a device".
> 	- Updated author and commit message for "ARM: exynos: Move to generic
> 	  PM domain DT bindings".
> 	- Added some acks and reviewed by tags.
> 	- Started to use the "--in-reply-to" option to git-send-email. It should
> 	  provide the option to show a better diffstat per patch.

Please don't send serieses in reply to earlier versions, it buries
things in the middle of old discussions which can mean they don't get
noticed, especially when you're sending multiple large patch serieses at
the same time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140909/9406e4fc/attachment.sig>

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

* Re: [PATCH v4 0/9] PM / Domains: Generic OF-based support
  2014-09-09 11:54     ` Mark Brown
@ 2014-09-09 12:45       ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 12:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, linux-arm-kernel, ACPI Devel Maling List,
	Geert Uytterhoeven, Kevin Hilman, Alan Stern, Daniel Lezcano,
	Tomasz Figa, devicetree, Linus Walleij, Simon Horman,
	Magnus Damm, Ben Dooks, Kukjin Kim, Stephen Boyd, Philipp Zabel

On 9 September 2014 13:54, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Sep 09, 2014 at 01:36:01PM +0200, Ulf Hansson wrote:
>> Changes in v4:
>>       - Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
>>         and updated the author and the commit message.
>>       - Adopted review comments for "PM / Domains: Add APIs to attach/detach
>>         a PM domain for a device".
>>       - Updated author and commit message for "ARM: exynos: Move to generic
>>         PM domain DT bindings".
>>       - Added some acks and reviewed by tags.
>>       - Started to use the "--in-reply-to" option to git-send-email. It should
>>         provide the option to show a better diffstat per patch.
>
> Please don't send serieses in reply to earlier versions, it buries
> things in the middle of old discussions which can mean they don't get
> noticed, especially when you're sending multiple large patch serieses at
> the same time.

Sorry, I just thought that it simplified life in this particular case. :-)

If additional versions needs to be posted I will follow your advise. Thanks!

Kind regards
Uffe

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

* [PATCH v4 0/9] PM / Domains: Generic OF-based support
@ 2014-09-09 12:45       ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-09 12:45 UTC (permalink / raw)
  To: linux-arm-kernel

On 9 September 2014 13:54, Mark Brown <broonie@kernel.org> wrote:
> On Tue, Sep 09, 2014 at 01:36:01PM +0200, Ulf Hansson wrote:
>> Changes in v4:
>>       - Rebased patch "PM / Domains: Add generic OF-based PM domain look-up" -
>>         and updated the author and the commit message.
>>       - Adopted review comments for "PM / Domains: Add APIs to attach/detach
>>         a PM domain for a device".
>>       - Updated author and commit message for "ARM: exynos: Move to generic
>>         PM domain DT bindings".
>>       - Added some acks and reviewed by tags.
>>       - Started to use the "--in-reply-to" option to git-send-email. It should
>>         provide the option to show a better diffstat per patch.
>
> Please don't send serieses in reply to earlier versions, it buries
> things in the middle of old discussions which can mean they don't get
> noticed, especially when you're sending multiple large patch serieses at
> the same time.

Sorry, I just thought that it simplified life in this particular case. :-)

If additional versions needs to be posted I will follow your advise. Thanks!

Kind regards
Uffe

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

* Re: [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
  2014-09-09 11:40                   ` Mark Brown
@ 2014-09-09 13:45                     ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-09 13:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: Geert Uytterhoeven, Ulf Hansson, Pawel Moll, Rob Herring,
	Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	linux-arm-kernel, ACPI Devel Maling List, Geert Uytterhoeven,
	Kevin Hilman, Alan Stern, Daniel Lezcano, devicetree,
	Linus Walleij, Simon Horman, Magnus Damm, Ben Dooks, Kukjin Kim,
	Stephen Boyd

On Tuesday, September 09, 2014 12:40:51 PM Mark Brown wrote:
> 
> --FJ0JV+AOCbvjFtNn
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> On Mon, Sep 08, 2014 at 11:26:49PM +0200, Rafael J. Wysocki wrote:
> 
> > The s-o-b is more of a gray area, but again it is supposed to be possible
> > to verify which it won't be if it bounces.
> 
> That's always going to be an issue with signoffs - people's addresses
> can and do go bad at any point.

I know and that's a gray area as I said.

Whether or not it is appropriate to submit a patch with an s-o-b that is known
to bounce is a good question to me.

It is true, though, that this particular patch was originally submitted when
the s-o-b address didn't bounce, so I may restore the tag when applying the
patch.  Need to think about that.

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up
@ 2014-09-09 13:45                     ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-09 13:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday, September 09, 2014 12:40:51 PM Mark Brown wrote:
> 
> --FJ0JV+AOCbvjFtNn
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> On Mon, Sep 08, 2014 at 11:26:49PM +0200, Rafael J. Wysocki wrote:
> 
> > The s-o-b is more of a gray area, but again it is supposed to be possible
> > to verify which it won't be if it bounces.
> 
> That's always going to be an issue with signoffs - people's addresses
> can and do go bad at any point.

I know and that's a gray area as I said.

Whether or not it is appropriate to submit a patch with an s-o-b that is known
to bounce is a good question to me.

It is true, though, that this particular patch was originally submitted when
the s-o-b address didn't bounce, so I may restore the tag when applying the
patch.  Need to think about that.

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH v4 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
  2014-09-09 11:36     ` Ulf Hansson
@ 2014-09-09 13:46       ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-09 13:46 UTC (permalink / raw)
  To: Ulf Hansson, Greg Kroah-Hartman
  Cc: Len Brown, Pavel Machek, linux-pm, linux-arm-kernel, linux-acpi,
	Geert Uytterhoeven, Kevin Hilman, Alan Stern, Daniel Lezcano,
	Tomasz Figa, devicetree, Linus Walleij, Simon Horman,
	Magnus Damm, Ben Dooks, Kukjin Kim, Stephen Boyd, Philipp Zabel,
	Mark Brown, Wolfram Sang, Chris Ball, Russell King

On Tuesday, September 09, 2014 01:36:05 PM Ulf Hansson wrote:
> Previously only the ACPI PM domain was supported by the platform bus.
> 
> Let's convert to the common attach/detach functions for PM domains,
> which currently means we are extending the support to include the
> generic PM domain as well.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> Reviewed-by: Kevin Hilman <khilman@linaro.org>

Greg, any objections here?

> ---
>  drivers/base/platform.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index ab4f4ce..904be3d 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
>  	if (ret < 0)
>  		return ret;
>  
> -	acpi_dev_pm_attach(_dev, true);
> -
> -	ret = drv->probe(dev);
> -	if (ret)
> -		acpi_dev_pm_detach(_dev, true);
> +	ret = dev_pm_domain_attach(_dev, true);
> +	if (ret != -EPROBE_DEFER) {
> +		ret = drv->probe(dev);
> +		if (ret)
> +			dev_pm_domain_detach(_dev, true);
> +	}
>  
>  	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
>  		dev_warn(_dev, "probe deferral not supported\n");
> @@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
>  	int ret;
>  
>  	ret = drv->remove(dev);
> -	acpi_dev_pm_detach(_dev, true);
> +	dev_pm_domain_detach(_dev, true);
>  
>  	return ret;
>  }
> @@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
>  	struct platform_device *dev = to_platform_device(_dev);
>  
>  	drv->shutdown(dev);
> -	acpi_dev_pm_detach(_dev, true);
> +	dev_pm_domain_detach(_dev, true);
>  }
>  
>  /**
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH v4 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach()
@ 2014-09-09 13:46       ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-09 13:46 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday, September 09, 2014 01:36:05 PM Ulf Hansson wrote:
> Previously only the ACPI PM domain was supported by the platform bus.
> 
> Let's convert to the common attach/detach functions for PM domains,
> which currently means we are extending the support to include the
> generic PM domain as well.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> Tested-by: Philipp Zabel <p.zabel@pengutronix.de>
> Reviewed-by: Kevin Hilman <khilman@linaro.org>

Greg, any objections here?

> ---
>  drivers/base/platform.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index ab4f4ce..904be3d 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -506,11 +506,12 @@ static int platform_drv_probe(struct device *_dev)
>  	if (ret < 0)
>  		return ret;
>  
> -	acpi_dev_pm_attach(_dev, true);
> -
> -	ret = drv->probe(dev);
> -	if (ret)
> -		acpi_dev_pm_detach(_dev, true);
> +	ret = dev_pm_domain_attach(_dev, true);
> +	if (ret != -EPROBE_DEFER) {
> +		ret = drv->probe(dev);
> +		if (ret)
> +			dev_pm_domain_detach(_dev, true);
> +	}
>  
>  	if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
>  		dev_warn(_dev, "probe deferral not supported\n");
> @@ -532,7 +533,7 @@ static int platform_drv_remove(struct device *_dev)
>  	int ret;
>  
>  	ret = drv->remove(dev);
> -	acpi_dev_pm_detach(_dev, true);
> +	dev_pm_domain_detach(_dev, true);
>  
>  	return ret;
>  }
> @@ -543,7 +544,7 @@ static void platform_drv_shutdown(struct device *_dev)
>  	struct platform_device *dev = to_platform_device(_dev);
>  
>  	drv->shutdown(dev);
> -	acpi_dev_pm_detach(_dev, true);
> +	dev_pm_domain_detach(_dev, true);
>  }
>  
>  /**
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-09 11:36     ` Ulf Hansson
@ 2014-09-12 21:05       ` Dmitry Torokhov
  -1 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-12 21:05 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball, linux-acpi,
	Simon Horman, Alan Stern, Mark Brown, Ben Dooks, Kukjin Kim,
	linux-arm-kernel

Hi Ulf,

On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.

So how would callers handle the errors? As far as I can see
acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
there is no meaningful strategy to handle errors as you are past the point of
no return and you keep on tearing down the device.

Thanks. 

-- 
Dmitry

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-12 21:05       ` Dmitry Torokhov
  0 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-12 21:05 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Ulf,

On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> To give callers the option of acting on a errors while removing the
> pm_domain ops for the device in the ACPI PM domain, let
> acpi_dev_pm_detach() return an int to provide the error code.

So how would callers handle the errors? As far as I can see
acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
there is no meaningful strategy to handle errors as you are past the point of
no return and you keep on tearing down the device.

Thanks. 

-- 
Dmitry

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-12 21:05       ` [v4, 1/9] " Dmitry Torokhov
@ 2014-09-14 16:38         ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-14 16:38 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Ulf Hansson, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball, linux-acpi,
	Simon Horman, Alan Stern, Mark Brown, Ben Dooks, Kukjin Kim,
	linux-arm-kernel

On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> Hi Ulf,
> 
> On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > To give callers the option of acting on a errors while removing the
> > pm_domain ops for the device in the ACPI PM domain, let
> > acpi_dev_pm_detach() return an int to provide the error code.
> 
> So how would callers handle the errors? As far as I can see
> acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> there is no meaningful strategy to handle errors as you are past the point of
> no return and you keep on tearing down the device.

This is specifically for what patch [3/9] is doing AFAICS.  

The existing callers don't need to worry about this.

Rafael


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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-14 16:38         ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-14 16:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> Hi Ulf,
> 
> On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > To give callers the option of acting on a errors while removing the
> > pm_domain ops for the device in the ACPI PM domain, let
> > acpi_dev_pm_detach() return an int to provide the error code.
> 
> So how would callers handle the errors? As far as I can see
> acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> there is no meaningful strategy to handle errors as you are past the point of
> no return and you keep on tearing down the device.

This is specifically for what patch [3/9] is doing AFAICS.  

The existing callers don't need to worry about this.

Rafael

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-14 16:38         ` [v4, 1/9] " Rafael J. Wysocki
@ 2014-09-15 16:53           ` Dmitry Torokhov
  -1 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-15 16:53 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ulf Hansson, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball, linux-acpi,
	Simon Horman, Alan Stern, Mark Brown, Ben Dooks, Kukjin Kim,
	linux-arm-kernel

On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> > Hi Ulf,
> > 
> > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > > To give callers the option of acting on a errors while removing the
> > > pm_domain ops for the device in the ACPI PM domain, let
> > > acpi_dev_pm_detach() return an int to provide the error code.
> > 
> > So how would callers handle the errors? As far as I can see
> > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> > there is no meaningful strategy to handle errors as you are past the point of
> > no return and you keep on tearing down the device.
> 
> This is specifically for what patch [3/9] is doing AFAICS.  
> 
> The existing callers don't need to worry about this.

OK, so I have the very same comment about patch 3 then: we have
dev_pm_domain_detach() returning error. How would the callers handle errors?

WRT this patch: I'd rater we did not just return generic "error code" just
because we do not know who manages PD for the device. Can we add API to check
if we are using ACPI to manage power domains? Then patch #3 could check if it
needs to use ACPI or generic power domain API.

Thanks.

-- 
Dmitry

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-15 16:53           ` Dmitry Torokhov
  0 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-15 16:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> > Hi Ulf,
> > 
> > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > > To give callers the option of acting on a errors while removing the
> > > pm_domain ops for the device in the ACPI PM domain, let
> > > acpi_dev_pm_detach() return an int to provide the error code.
> > 
> > So how would callers handle the errors? As far as I can see
> > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> > there is no meaningful strategy to handle errors as you are past the point of
> > no return and you keep on tearing down the device.
> 
> This is specifically for what patch [3/9] is doing AFAICS.  
> 
> The existing callers don't need to worry about this.

OK, so I have the very same comment about patch 3 then: we have
dev_pm_domain_detach() returning error. How would the callers handle errors?

WRT this patch: I'd rater we did not just return generic "error code" just
because we do not know who manages PD for the device. Can we add API to check
if we are using ACPI to manage power domains? Then patch #3 could check if it
needs to use ACPI or generic power domain API.

Thanks.

-- 
Dmitry

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-15 16:53           ` [v4, 1/9] " Dmitry Torokhov
@ 2014-09-15 23:36             ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-15 23:36 UTC (permalink / raw)
  To: Dmitry Torokhov, Ulf Hansson
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball, linux-acpi,
	Simon Horman, Alan Stern, Mark Brown, Ben Dooks, Kukjin Kim,
	linux-arm-kernel

On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> > > Hi Ulf,
> > > 
> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > > > To give callers the option of acting on a errors while removing the
> > > > pm_domain ops for the device in the ACPI PM domain, let
> > > > acpi_dev_pm_detach() return an int to provide the error code.
> > > 
> > > So how would callers handle the errors? As far as I can see
> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> > > there is no meaningful strategy to handle errors as you are past the point of
> > > no return and you keep on tearing down the device.
> > 
> > This is specifically for what patch [3/9] is doing AFAICS.  
> > 
> > The existing callers don't need to worry about this.
> 
> OK, so I have the very same comment about patch 3 then: we have
> dev_pm_domain_detach() returning error. How would the callers handle errors?

Ulf?

> WRT this patch: I'd rater we did not just return generic "error code" just
> because we do not know who manages PD for the device. Can we add API to check
> if we are using ACPI to manage power domains? Then patch #3 could check if it
> needs to use ACPI or generic power domain API.

The rule is that if there is an ACPI companion object for the given device, then
ACPI is used.  So the API is ACPI_COMPANION(dev) and we have that check around
until someone realized that acpi_dev_pm_attach/detach() made it too.  We can
restore it, I suppose, but I'm not sure how much better it is going to be.

Either way, I have no strong preferences here.

Rafael


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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-15 23:36             ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-15 23:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> > > Hi Ulf,
> > > 
> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> > > > To give callers the option of acting on a errors while removing the
> > > > pm_domain ops for the device in the ACPI PM domain, let
> > > > acpi_dev_pm_detach() return an int to provide the error code.
> > > 
> > > So how would callers handle the errors? As far as I can see
> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> > > there is no meaningful strategy to handle errors as you are past the point of
> > > no return and you keep on tearing down the device.
> > 
> > This is specifically for what patch [3/9] is doing AFAICS.  
> > 
> > The existing callers don't need to worry about this.
> 
> OK, so I have the very same comment about patch 3 then: we have
> dev_pm_domain_detach() returning error. How would the callers handle errors?

Ulf?

> WRT this patch: I'd rater we did not just return generic "error code" just
> because we do not know who manages PD for the device. Can we add API to check
> if we are using ACPI to manage power domains? Then patch #3 could check if it
> needs to use ACPI or generic power domain API.

The rule is that if there is an ACPI companion object for the given device, then
ACPI is used.  So the API is ACPI_COMPANION(dev) and we have that check around
until someone realized that acpi_dev_pm_attach/detach() made it too.  We can
restore it, I suppose, but I'm not sure how much better it is going to be.

Either way, I have no strong preferences here.

Rafael

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-15 23:36             ` [v4, 1/9] " Rafael J. Wysocki
@ 2014-09-17 18:25               ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-17 18:25 UTC (permalink / raw)
  To: Rafael J. Wysocki, Dmitry Torokhov
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, linux-pm,
	devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball,
	ACPI Devel Maling List, Simon Horman, Alan Stern, Mark Brown,
	Ben Dooks, Kukjin Kim

On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> > > Hi Ulf,
>> > >
>> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> > > > To give callers the option of acting on a errors while removing the
>> > > > pm_domain ops for the device in the ACPI PM domain, let
>> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> > >
>> > > So how would callers handle the errors? As far as I can see
>> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> > > there is no meaningful strategy to handle errors as you are past the point of
>> > > no return and you keep on tearing down the device.

The benefit is only relevant when ACPI and genpd PM domains would
co-exist. In that case we might be able to skip genpd_dev_pm_detach()
if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
but still it doesn't hurt.

>> >
>> > This is specifically for what patch [3/9] is doing AFAICS.
>> >
>> > The existing callers don't need to worry about this.
>>
>> OK, so I have the very same comment about patch 3 then: we have
>> dev_pm_domain_detach() returning error. How would the callers handle errors?
>
> Ulf?

I see your point. How about making dev_pm_domain_detach() to be a void
function instead?

>
>> WRT this patch: I'd rater we did not just return generic "error code" just
>> because we do not know who manages PD for the device. Can we add API to check
>> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> needs to use ACPI or generic power domain API.

The problem is scalability. If we have other PM domains implementation
in future, each of them need to be checked prior invoking the attach
functions.
Also, how would we distinguish between genpd and a new PM domain XYZ?

Kind regards
Uffe

>
> The rule is that if there is an ACPI companion object for the given device, then
> ACPI is used.  So the API is ACPI_COMPANION(dev) and we have that check around
> until someone realized that acpi_dev_pm_attach/detach() made it too.  We can
> restore it, I suppose, but I'm not sure how much better it is going to be.
>
> Either way, I have no strong preferences here.
>
> Rafael
>

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-17 18:25               ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-17 18:25 UTC (permalink / raw)
  To: linux-arm-kernel

On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> > > Hi Ulf,
>> > >
>> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> > > > To give callers the option of acting on a errors while removing the
>> > > > pm_domain ops for the device in the ACPI PM domain, let
>> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> > >
>> > > So how would callers handle the errors? As far as I can see
>> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> > > there is no meaningful strategy to handle errors as you are past the point of
>> > > no return and you keep on tearing down the device.

The benefit is only relevant when ACPI and genpd PM domains would
co-exist. In that case we might be able to skip genpd_dev_pm_detach()
if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
but still it doesn't hurt.

>> >
>> > This is specifically for what patch [3/9] is doing AFAICS.
>> >
>> > The existing callers don't need to worry about this.
>>
>> OK, so I have the very same comment about patch 3 then: we have
>> dev_pm_domain_detach() returning error. How would the callers handle errors?
>
> Ulf?

I see your point. How about making dev_pm_domain_detach() to be a void
function instead?

>
>> WRT this patch: I'd rater we did not just return generic "error code" just
>> because we do not know who manages PD for the device. Can we add API to check
>> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> needs to use ACPI or generic power domain API.

The problem is scalability. If we have other PM domains implementation
in future, each of them need to be checked prior invoking the attach
functions.
Also, how would we distinguish between genpd and a new PM domain XYZ?

Kind regards
Uffe

>
> The rule is that if there is an ACPI companion object for the given device, then
> ACPI is used.  So the API is ACPI_COMPANION(dev) and we have that check around
> until someone realized that acpi_dev_pm_attach/detach() made it too.  We can
> restore it, I suppose, but I'm not sure how much better it is going to be.
>
> Either way, I have no strong preferences here.
>
> Rafael
>

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-17 18:25               ` [v4, 1/9] " Ulf Hansson
@ 2014-09-17 20:10                 ` Dmitry Torokhov
  -1 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-17 20:10 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball,
	ACPI Devel Maling List, Simon Horman, Alan Stern, Mark Brown,
	Ben Dooks

On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> > > Hi Ulf,
> >> > >
> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> > > > To give callers the option of acting on a errors while removing the
> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> > >
> >> > > So how would callers handle the errors? As far as I can see
> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> > > no return and you keep on tearing down the device.
> 
> The benefit is only relevant when ACPI and genpd PM domains would
> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> but still it doesn't hurt.

It doe snot have any negative material effect, the drawback is purely
from API perspective.

> 
> >> >
> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >
> >> > The existing callers don't need to worry about this.
> >>
> >> OK, so I have the very same comment about patch 3 then: we have
> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >
> > Ulf?
> 
> I see your point. How about making dev_pm_domain_detach() to be a void
> function instead?

Yes, please.

> 
> >
> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> because we do not know who manages PD for the device. Can we add API to check
> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> needs to use ACPI or generic power domain API.
> 
> The problem is scalability. If we have other PM domains implementation
> in future, each of them need to be checked prior invoking the attach
> functions.
> Also, how would we distinguish between genpd and a new PM domain XYZ?

I do not think that trying all available methods to detach a pm domain,
i.e.

	err = acpi_dev_pm_detach();
	if (err)
		err = blah_dev_pm_detach();
	if (err)
		err = flab_dev_pm_detach();
	if (err)
		err = gen_dev_pm_detach();

is any better from scalability point of view. If you need to do that you
will probably have to store something like "struct pd_ops *pd_ops" in
your device and call appropriate implementation via it.

Thanks.

-- 
Dmitry

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-17 20:10                 ` Dmitry Torokhov
  0 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-17 20:10 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> > > Hi Ulf,
> >> > >
> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> > > > To give callers the option of acting on a errors while removing the
> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> > >
> >> > > So how would callers handle the errors? As far as I can see
> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> > > no return and you keep on tearing down the device.
> 
> The benefit is only relevant when ACPI and genpd PM domains would
> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> but still it doesn't hurt.

It doe snot have any negative material effect, the drawback is purely
from API perspective.

> 
> >> >
> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >
> >> > The existing callers don't need to worry about this.
> >>
> >> OK, so I have the very same comment about patch 3 then: we have
> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >
> > Ulf?
> 
> I see your point. How about making dev_pm_domain_detach() to be a void
> function instead?

Yes, please.

> 
> >
> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> because we do not know who manages PD for the device. Can we add API to check
> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> needs to use ACPI or generic power domain API.
> 
> The problem is scalability. If we have other PM domains implementation
> in future, each of them need to be checked prior invoking the attach
> functions.
> Also, how would we distinguish between genpd and a new PM domain XYZ?

I do not think that trying all available methods to detach a pm domain,
i.e.

	err = acpi_dev_pm_detach();
	if (err)
		err = blah_dev_pm_detach();
	if (err)
		err = flab_dev_pm_detach();
	if (err)
		err = gen_dev_pm_detach();

is any better from scalability point of view. If you need to do that you
will probably have to store something like "struct pd_ops *pd_ops" in
your device and call appropriate implementation via it.

Thanks.

-- 
Dmitry

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-17 20:10                 ` [v4, 1/9] " Dmitry Torokhov
@ 2014-09-17 23:20                   ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-17 23:20 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball,
	ACPI Devel Maling List, Simon Horman, Alan Stern, Mark Brown,
	Ben Dooks

On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
>> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> >> > > Hi Ulf,
>> >> > >
>> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> >> > > > To give callers the option of acting on a errors while removing the
>> >> > > > pm_domain ops for the device in the ACPI PM domain, let
>> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> >> > >
>> >> > > So how would callers handle the errors? As far as I can see
>> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> >> > > there is no meaningful strategy to handle errors as you are past the point of
>> >> > > no return and you keep on tearing down the device.
>>
>> The benefit is only relevant when ACPI and genpd PM domains would
>> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
>> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
>> but still it doesn't hurt.
>
> It doe snot have any negative material effect, the drawback is purely
> from API perspective.
>
>>
>> >> >
>> >> > This is specifically for what patch [3/9] is doing AFAICS.
>> >> >
>> >> > The existing callers don't need to worry about this.
>> >>
>> >> OK, so I have the very same comment about patch 3 then: we have
>> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
>> >
>> > Ulf?
>>
>> I see your point. How about making dev_pm_domain_detach() to be a void
>> function instead?
>
> Yes, please.

OK!

>
>>
>> >
>> >> WRT this patch: I'd rater we did not just return generic "error code" just
>> >> because we do not know who manages PD for the device. Can we add API to check
>> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> >> needs to use ACPI or generic power domain API.
>>
>> The problem is scalability. If we have other PM domains implementation
>> in future, each of them need to be checked prior invoking the attach
>> functions.
>> Also, how would we distinguish between genpd and a new PM domain XYZ?
>
> I do not think that trying all available methods to detach a pm domain,
> i.e.
>
>         err = acpi_dev_pm_detach();
>         if (err)
>                 err = blah_dev_pm_detach();
>         if (err)
>                 err = flab_dev_pm_detach();
>         if (err)
>                 err = gen_dev_pm_detach();
>
> is any better from scalability point of view. If you need to do that you
> will probably have to store something like "struct pd_ops *pd_ops" in
> your device and call appropriate implementation via it.

No, that's not needed. Go ahead and have look at both ACPI and genpd,
the interesting part is the validation of struct dev_pm_domain pointer
in the struct device. That's all there is to it, no additional data
are required.

Kind regards
Uffe

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-17 23:20                   ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-17 23:20 UTC (permalink / raw)
  To: linux-arm-kernel

On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
>> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> >> > > Hi Ulf,
>> >> > >
>> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> >> > > > To give callers the option of acting on a errors while removing the
>> >> > > > pm_domain ops for the device in the ACPI PM domain, let
>> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> >> > >
>> >> > > So how would callers handle the errors? As far as I can see
>> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> >> > > there is no meaningful strategy to handle errors as you are past the point of
>> >> > > no return and you keep on tearing down the device.
>>
>> The benefit is only relevant when ACPI and genpd PM domains would
>> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
>> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
>> but still it doesn't hurt.
>
> It doe snot have any negative material effect, the drawback is purely
> from API perspective.
>
>>
>> >> >
>> >> > This is specifically for what patch [3/9] is doing AFAICS.
>> >> >
>> >> > The existing callers don't need to worry about this.
>> >>
>> >> OK, so I have the very same comment about patch 3 then: we have
>> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
>> >
>> > Ulf?
>>
>> I see your point. How about making dev_pm_domain_detach() to be a void
>> function instead?
>
> Yes, please.

OK!

>
>>
>> >
>> >> WRT this patch: I'd rater we did not just return generic "error code" just
>> >> because we do not know who manages PD for the device. Can we add API to check
>> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> >> needs to use ACPI or generic power domain API.
>>
>> The problem is scalability. If we have other PM domains implementation
>> in future, each of them need to be checked prior invoking the attach
>> functions.
>> Also, how would we distinguish between genpd and a new PM domain XYZ?
>
> I do not think that trying all available methods to detach a pm domain,
> i.e.
>
>         err = acpi_dev_pm_detach();
>         if (err)
>                 err = blah_dev_pm_detach();
>         if (err)
>                 err = flab_dev_pm_detach();
>         if (err)
>                 err = gen_dev_pm_detach();
>
> is any better from scalability point of view. If you need to do that you
> will probably have to store something like "struct pd_ops *pd_ops" in
> your device and call appropriate implementation via it.

No, that's not needed. Go ahead and have look at both ACPI and genpd,
the interesting part is the validation of struct dev_pm_domain pointer
in the struct device. That's all there is to it, no additional data
are required.

Kind regards
Uffe

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-17 23:20                   ` [v4, 1/9] " Ulf Hansson
@ 2014-09-17 23:43                     ` Dmitry Torokhov
  -1 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-17 23:43 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball,
	ACPI Devel Maling List, Simon Horman, Alan Stern, Mark Brown,
	Ben Dooks

On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> >> > > Hi Ulf,
> >> >> > >
> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> >> > > > To give callers the option of acting on a errors while removing the
> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> >> > >
> >> >> > > So how would callers handle the errors? As far as I can see
> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> >> > > no return and you keep on tearing down the device.
> >>
> >> The benefit is only relevant when ACPI and genpd PM domains would
> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> >> but still it doesn't hurt.
> >
> > It doe snot have any negative material effect, the drawback is purely
> > from API perspective.
> >
> >>
> >> >> >
> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >> >
> >> >> > The existing callers don't need to worry about this.
> >> >>
> >> >> OK, so I have the very same comment about patch 3 then: we have
> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >> >
> >> > Ulf?
> >>
> >> I see your point. How about making dev_pm_domain_detach() to be a void
> >> function instead?
> >
> > Yes, please.
> 
> OK!
> 
> >
> >>
> >> >
> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> >> because we do not know who manages PD for the device. Can we add API to check
> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> >> needs to use ACPI or generic power domain API.
> >>
> >> The problem is scalability. If we have other PM domains implementation
> >> in future, each of them need to be checked prior invoking the attach
> >> functions.
> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
> >
> > I do not think that trying all available methods to detach a pm domain,
> > i.e.
> >
> >         err = acpi_dev_pm_detach();
> >         if (err)
> >                 err = blah_dev_pm_detach();
> >         if (err)
> >                 err = flab_dev_pm_detach();
> >         if (err)
> >                 err = gen_dev_pm_detach();
> >
> > is any better from scalability point of view. If you need to do that you
> > will probably have to store something like "struct pd_ops *pd_ops" in
> > your device and call appropriate implementation via it.
> 
> No, that's not needed. Go ahead and have look at both ACPI and genpd,
> the interesting part is the validation of struct dev_pm_domain pointer
> in the struct device. That's all there is to it, no additional data
> are required.

OK, so can you simply put the needed method into struct dev_pm_domain and then
dev_pm_domain_detach() would become:

void dev_pm_domain_detach(struct device *dev, bool power_off)
{
	if (dev->pm_domain)
		dev->pm_domain->detach(dev, power_off);
}

Thanks.

-- 
Dmitry

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-17 23:43                     ` Dmitry Torokhov
  0 siblings, 0 replies; 96+ messages in thread
From: Dmitry Torokhov @ 2014-09-17 23:43 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> >> > > Hi Ulf,
> >> >> > >
> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> >> > > > To give callers the option of acting on a errors while removing the
> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> >> > >
> >> >> > > So how would callers handle the errors? As far as I can see
> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> >> > > no return and you keep on tearing down the device.
> >>
> >> The benefit is only relevant when ACPI and genpd PM domains would
> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> >> but still it doesn't hurt.
> >
> > It doe snot have any negative material effect, the drawback is purely
> > from API perspective.
> >
> >>
> >> >> >
> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >> >
> >> >> > The existing callers don't need to worry about this.
> >> >>
> >> >> OK, so I have the very same comment about patch 3 then: we have
> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >> >
> >> > Ulf?
> >>
> >> I see your point. How about making dev_pm_domain_detach() to be a void
> >> function instead?
> >
> > Yes, please.
> 
> OK!
> 
> >
> >>
> >> >
> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> >> because we do not know who manages PD for the device. Can we add API to check
> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> >> needs to use ACPI or generic power domain API.
> >>
> >> The problem is scalability. If we have other PM domains implementation
> >> in future, each of them need to be checked prior invoking the attach
> >> functions.
> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
> >
> > I do not think that trying all available methods to detach a pm domain,
> > i.e.
> >
> >         err = acpi_dev_pm_detach();
> >         if (err)
> >                 err = blah_dev_pm_detach();
> >         if (err)
> >                 err = flab_dev_pm_detach();
> >         if (err)
> >                 err = gen_dev_pm_detach();
> >
> > is any better from scalability point of view. If you need to do that you
> > will probably have to store something like "struct pd_ops *pd_ops" in
> > your device and call appropriate implementation via it.
> 
> No, that's not needed. Go ahead and have look at both ACPI and genpd,
> the interesting part is the validation of struct dev_pm_domain pointer
> in the struct device. That's all there is to it, no additional data
> are required.

OK, so can you simply put the needed method into struct dev_pm_domain and then
dev_pm_domain_detach() would become:

void dev_pm_domain_detach(struct device *dev, bool power_off)
{
	if (dev->pm_domain)
		dev->pm_domain->detach(dev, power_off);
}

Thanks.

-- 
Dmitry

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-17 23:43                     ` [v4, 1/9] " Dmitry Torokhov
@ 2014-09-18  0:35                         ` Ulf Hansson
  -1 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-18  0:35 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Kevin Hilman, Russell King,
	Philipp Zabel, Geert Uytterhoeven, Wolfram Sang, Stephen Boyd,
	Linus Walleij, Daniel Lezcano, Magnus Damm, Tomasz Figa,
	Chris Ball, ACPI Devel Maling List, Simon Horman, Alan Stern,
	Mark Brown, Ben Dooks

On 18 September 2014 01:43, Dmitry Torokhov <dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
>> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
>> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw-LthD3rsA81gm4RdzfppkhA@public.gmane.org> wrote:
>> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> >> >> > > Hi Ulf,
>> >> >> > >
>> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> >> >> > > > To give callers the option of acting on a errors while removing the
>> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
>> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> >> >> > >
>> >> >> > > So how would callers handle the errors? As far as I can see
>> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
>> >> >> > > no return and you keep on tearing down the device.
>> >>
>> >> The benefit is only relevant when ACPI and genpd PM domains would
>> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
>> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
>> >> but still it doesn't hurt.
>> >
>> > It doe snot have any negative material effect, the drawback is purely
>> > from API perspective.
>> >
>> >>
>> >> >> >
>> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
>> >> >> >
>> >> >> > The existing callers don't need to worry about this.
>> >> >>
>> >> >> OK, so I have the very same comment about patch 3 then: we have
>> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
>> >> >
>> >> > Ulf?
>> >>
>> >> I see your point. How about making dev_pm_domain_detach() to be a void
>> >> function instead?
>> >
>> > Yes, please.
>>
>> OK!
>>
>> >
>> >>
>> >> >
>> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
>> >> >> because we do not know who manages PD for the device. Can we add API to check
>> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> >> >> needs to use ACPI or generic power domain API.
>> >>
>> >> The problem is scalability. If we have other PM domains implementation
>> >> in future, each of them need to be checked prior invoking the attach
>> >> functions.
>> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
>> >
>> > I do not think that trying all available methods to detach a pm domain,
>> > i.e.
>> >
>> >         err = acpi_dev_pm_detach();
>> >         if (err)
>> >                 err = blah_dev_pm_detach();
>> >         if (err)
>> >                 err = flab_dev_pm_detach();
>> >         if (err)
>> >                 err = gen_dev_pm_detach();
>> >
>> > is any better from scalability point of view. If you need to do that you
>> > will probably have to store something like "struct pd_ops *pd_ops" in
>> > your device and call appropriate implementation via it.
>>
>> No, that's not needed. Go ahead and have look at both ACPI and genpd,
>> the interesting part is the validation of struct dev_pm_domain pointer
>> in the struct device. That's all there is to it, no additional data
>> are required.
>
> OK, so can you simply put the needed method into struct dev_pm_domain and then
> dev_pm_domain_detach() would become:
>
> void dev_pm_domain_detach(struct device *dev, bool power_off)
> {
>         if (dev->pm_domain)
>                 dev->pm_domain->detach(dev, power_off);
> }
>
> Thanks.

Ohh, didn't quite follow that this is what you meant. That would be a
great improvement, I will adopt in the next version.

Kind regards
Uffe

>
> --
> Dmitry
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-18  0:35                         ` Ulf Hansson
  0 siblings, 0 replies; 96+ messages in thread
From: Ulf Hansson @ 2014-09-18  0:35 UTC (permalink / raw)
  To: linux-arm-kernel

On 18 September 2014 01:43, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
>> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
>> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
>> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
>> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
>> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
>> >> >> > > Hi Ulf,
>> >> >> > >
>> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
>> >> >> > > > To give callers the option of acting on a errors while removing the
>> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
>> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
>> >> >> > >
>> >> >> > > So how would callers handle the errors? As far as I can see
>> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
>> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
>> >> >> > > no return and you keep on tearing down the device.
>> >>
>> >> The benefit is only relevant when ACPI and genpd PM domains would
>> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
>> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
>> >> but still it doesn't hurt.
>> >
>> > It doe snot have any negative material effect, the drawback is purely
>> > from API perspective.
>> >
>> >>
>> >> >> >
>> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
>> >> >> >
>> >> >> > The existing callers don't need to worry about this.
>> >> >>
>> >> >> OK, so I have the very same comment about patch 3 then: we have
>> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
>> >> >
>> >> > Ulf?
>> >>
>> >> I see your point. How about making dev_pm_domain_detach() to be a void
>> >> function instead?
>> >
>> > Yes, please.
>>
>> OK!
>>
>> >
>> >>
>> >> >
>> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
>> >> >> because we do not know who manages PD for the device. Can we add API to check
>> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
>> >> >> needs to use ACPI or generic power domain API.
>> >>
>> >> The problem is scalability. If we have other PM domains implementation
>> >> in future, each of them need to be checked prior invoking the attach
>> >> functions.
>> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
>> >
>> > I do not think that trying all available methods to detach a pm domain,
>> > i.e.
>> >
>> >         err = acpi_dev_pm_detach();
>> >         if (err)
>> >                 err = blah_dev_pm_detach();
>> >         if (err)
>> >                 err = flab_dev_pm_detach();
>> >         if (err)
>> >                 err = gen_dev_pm_detach();
>> >
>> > is any better from scalability point of view. If you need to do that you
>> > will probably have to store something like "struct pd_ops *pd_ops" in
>> > your device and call appropriate implementation via it.
>>
>> No, that's not needed. Go ahead and have look at both ACPI and genpd,
>> the interesting part is the validation of struct dev_pm_domain pointer
>> in the struct device. That's all there is to it, no additional data
>> are required.
>
> OK, so can you simply put the needed method into struct dev_pm_domain and then
> dev_pm_domain_detach() would become:
>
> void dev_pm_domain_detach(struct device *dev, bool power_off)
> {
>         if (dev->pm_domain)
>                 dev->pm_domain->detach(dev, power_off);
> }
>
> Thanks.

Ohh, didn't quite follow that this is what you meant. That would be a
great improvement, I will adopt in the next version.

Kind regards
Uffe

>
> --
> Dmitry

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

* Re: [v4,1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
  2014-09-18  0:35                         ` [v4, 1/9] " Ulf Hansson
@ 2014-09-18 23:13                           ` Rafael J. Wysocki
  -1 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-18 23:13 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Dmitry Torokhov, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	linux-pm, devicetree, Kevin Hilman, Russell King, Philipp Zabel,
	Geert Uytterhoeven, Wolfram Sang, Stephen Boyd, Linus Walleij,
	Daniel Lezcano, Magnus Damm, Tomasz Figa, Chris Ball,
	ACPI Devel Maling List, Simon Horman, Alan Stern, Mark Brown,
	Ben Dooks

On Thursday, September 18, 2014 02:35:44 AM Ulf Hansson wrote:
> On 18 September 2014 01:43, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
> >> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> >> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> >> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> >> >> > > Hi Ulf,
> >> >> >> > >
> >> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> >> >> > > > To give callers the option of acting on a errors while removing the
> >> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> >> >> > >
> >> >> >> > > So how would callers handle the errors? As far as I can see
> >> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> >> >> > > no return and you keep on tearing down the device.
> >> >>
> >> >> The benefit is only relevant when ACPI and genpd PM domains would
> >> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> >> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> >> >> but still it doesn't hurt.
> >> >
> >> > It doe snot have any negative material effect, the drawback is purely
> >> > from API perspective.
> >> >
> >> >>
> >> >> >> >
> >> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >> >> >
> >> >> >> > The existing callers don't need to worry about this.
> >> >> >>
> >> >> >> OK, so I have the very same comment about patch 3 then: we have
> >> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >> >> >
> >> >> > Ulf?
> >> >>
> >> >> I see your point. How about making dev_pm_domain_detach() to be a void
> >> >> function instead?
> >> >
> >> > Yes, please.
> >>
> >> OK!
> >>
> >> >
> >> >>
> >> >> >
> >> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> >> >> because we do not know who manages PD for the device. Can we add API to check
> >> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> >> >> needs to use ACPI or generic power domain API.
> >> >>
> >> >> The problem is scalability. If we have other PM domains implementation
> >> >> in future, each of them need to be checked prior invoking the attach
> >> >> functions.
> >> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
> >> >
> >> > I do not think that trying all available methods to detach a pm domain,
> >> > i.e.
> >> >
> >> >         err = acpi_dev_pm_detach();
> >> >         if (err)
> >> >                 err = blah_dev_pm_detach();
> >> >         if (err)
> >> >                 err = flab_dev_pm_detach();
> >> >         if (err)
> >> >                 err = gen_dev_pm_detach();
> >> >
> >> > is any better from scalability point of view. If you need to do that you
> >> > will probably have to store something like "struct pd_ops *pd_ops" in
> >> > your device and call appropriate implementation via it.
> >>
> >> No, that's not needed. Go ahead and have look at both ACPI and genpd,
> >> the interesting part is the validation of struct dev_pm_domain pointer
> >> in the struct device. That's all there is to it, no additional data
> >> are required.
> >
> > OK, so can you simply put the needed method into struct dev_pm_domain and then
> > dev_pm_domain_detach() would become:
> >
> > void dev_pm_domain_detach(struct device *dev, bool power_off)
> > {
> >         if (dev->pm_domain)
> >                 dev->pm_domain->detach(dev, power_off);
> > }
> >
> > Thanks.
> 
> Ohh, didn't quite follow that this is what you meant. That would be a
> great improvement, I will adopt in the next version.


         if (dev->pm_domain && dev->pm_domain->detach)
                 dev->pm_domain->detach(dev, power_off);


Pretty please.

Rafael


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

* [v4, 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code
@ 2014-09-18 23:13                           ` Rafael J. Wysocki
  0 siblings, 0 replies; 96+ messages in thread
From: Rafael J. Wysocki @ 2014-09-18 23:13 UTC (permalink / raw)
  To: linux-arm-kernel

On Thursday, September 18, 2014 02:35:44 AM Ulf Hansson wrote:
> On 18 September 2014 01:43, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > On Thu, Sep 18, 2014 at 01:20:49AM +0200, Ulf Hansson wrote:
> >> On 17 September 2014 22:10, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> >> > On Wed, Sep 17, 2014 at 08:25:44PM +0200, Ulf Hansson wrote:
> >> >> On 16 September 2014 01:36, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >> >> > On Monday, September 15, 2014 09:53:59 AM Dmitry Torokhov wrote:
> >> >> >> On Sun, Sep 14, 2014 at 06:38:58PM +0200, Rafael J. Wysocki wrote:
> >> >> >> > On Friday, September 12, 2014 02:05:53 PM Dmitry Torokhov wrote:
> >> >> >> > > Hi Ulf,
> >> >> >> > >
> >> >> >> > > On Tue, Sep 09, 2014 at 01:36:02PM +0200, Ulf Hansson wrote:
> >> >> >> > > > To give callers the option of acting on a errors while removing the
> >> >> >> > > > pm_domain ops for the device in the ACPI PM domain, let
> >> >> >> > > > acpi_dev_pm_detach() return an int to provide the error code.
> >> >> >> > >
> >> >> >> > > So how would callers handle the errors? As far as I can see
> >> >> >> > > acpi_dev_pm_detach() is called from ->remove() and ->shutdown() methods, where
> >> >> >> > > there is no meaningful strategy to handle errors as you are past the point of
> >> >> >> > > no return and you keep on tearing down the device.
> >> >>
> >> >> The benefit is only relevant when ACPI and genpd PM domains would
> >> >> co-exist. In that case we might be able to skip genpd_dev_pm_detach()
> >> >> if acpi_dev_pm_detach() succeeds. So, currently there are  no benefit,
> >> >> but still it doesn't hurt.
> >> >
> >> > It doe snot have any negative material effect, the drawback is purely
> >> > from API perspective.
> >> >
> >> >>
> >> >> >> >
> >> >> >> > This is specifically for what patch [3/9] is doing AFAICS.
> >> >> >> >
> >> >> >> > The existing callers don't need to worry about this.
> >> >> >>
> >> >> >> OK, so I have the very same comment about patch 3 then: we have
> >> >> >> dev_pm_domain_detach() returning error. How would the callers handle errors?
> >> >> >
> >> >> > Ulf?
> >> >>
> >> >> I see your point. How about making dev_pm_domain_detach() to be a void
> >> >> function instead?
> >> >
> >> > Yes, please.
> >>
> >> OK!
> >>
> >> >
> >> >>
> >> >> >
> >> >> >> WRT this patch: I'd rater we did not just return generic "error code" just
> >> >> >> because we do not know who manages PD for the device. Can we add API to check
> >> >> >> if we are using ACPI to manage power domains? Then patch #3 could check if it
> >> >> >> needs to use ACPI or generic power domain API.
> >> >>
> >> >> The problem is scalability. If we have other PM domains implementation
> >> >> in future, each of them need to be checked prior invoking the attach
> >> >> functions.
> >> >> Also, how would we distinguish between genpd and a new PM domain XYZ?
> >> >
> >> > I do not think that trying all available methods to detach a pm domain,
> >> > i.e.
> >> >
> >> >         err = acpi_dev_pm_detach();
> >> >         if (err)
> >> >                 err = blah_dev_pm_detach();
> >> >         if (err)
> >> >                 err = flab_dev_pm_detach();
> >> >         if (err)
> >> >                 err = gen_dev_pm_detach();
> >> >
> >> > is any better from scalability point of view. If you need to do that you
> >> > will probably have to store something like "struct pd_ops *pd_ops" in
> >> > your device and call appropriate implementation via it.
> >>
> >> No, that's not needed. Go ahead and have look at both ACPI and genpd,
> >> the interesting part is the validation of struct dev_pm_domain pointer
> >> in the struct device. That's all there is to it, no additional data
> >> are required.
> >
> > OK, so can you simply put the needed method into struct dev_pm_domain and then
> > dev_pm_domain_detach() would become:
> >
> > void dev_pm_domain_detach(struct device *dev, bool power_off)
> > {
> >         if (dev->pm_domain)
> >                 dev->pm_domain->detach(dev, power_off);
> > }
> >
> > Thanks.
> 
> Ohh, didn't quite follow that this is what you meant. That would be a
> great improvement, I will adopt in the next version.


         if (dev->pm_domain && dev->pm_domain->detach)
                 dev->pm_domain->detach(dev, power_off);


Pretty please.

Rafael

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

end of thread, other threads:[~2014-09-18 23:13 UTC | newest]

Thread overview: 96+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 13:52 [PATCH v3 0/9] PM / Domains: Generic OF-based support Ulf Hansson
2014-09-04 13:52 ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-08-23 22:45   ` Pavel Machek
2014-08-23 22:45     ` Pavel Machek
2014-09-07 22:12   ` Rafael J. Wysocki
2014-09-07 22:12     ` Rafael J. Wysocki
2014-09-04 13:52 ` [PATCH v3 2/9] PM / Domains: Add generic OF-based PM domain look-up Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-07 22:13   ` Rafael J. Wysocki
2014-09-07 22:13     ` Rafael J. Wysocki
2014-09-08  7:26     ` Ulf Hansson
2014-09-08  7:26       ` Ulf Hansson
2014-09-08 21:04       ` Rafael J. Wysocki
2014-09-08 21:04         ` Rafael J. Wysocki
2014-09-08 21:08         ` Rafael J. Wysocki
2014-09-08 21:08           ` Rafael J. Wysocki
2014-09-08 20:53           ` Geert Uytterhoeven
2014-09-08 20:53             ` Geert Uytterhoeven
     [not found]             ` <CAMuHMdURbp8a0Ps2sZUZn7UHcWXZvRgS-4ubk1r=wGgXZ1PHmA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-09-08 21:26               ` Rafael J. Wysocki
2014-09-08 21:26                 ` Rafael J. Wysocki
2014-09-09 11:40                 ` Mark Brown
2014-09-09 11:40                   ` Mark Brown
2014-09-09 13:45                   ` Rafael J. Wysocki
2014-09-09 13:45                     ` Rafael J. Wysocki
2014-09-08 20:53           ` Tomasz Figa
2014-09-08 20:53             ` Tomasz Figa
2014-09-09  7:04         ` Ulf Hansson
2014-09-09  7:04           ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-08 22:11   ` Rafael J. Wysocki
2014-09-08 22:11     ` Rafael J. Wysocki
2014-09-04 13:52 ` [PATCH v3 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach() Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 5/9] i2c: core: " Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 6/9] mmc: sdio: " Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 7/9] spi: core: " Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 8/9] amba: Add support for attach/detach of PM domains Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-04 13:52 ` [PATCH v3 9/9] ARM: exynos: Move to generic PM domain DT bindings Ulf Hansson
2014-09-04 13:52   ` Ulf Hansson
2014-09-05 15:39 ` [PATCH v3 0/9] PM / Domains: Generic OF-based support Kevin Hilman
2014-09-05 15:39   ` Kevin Hilman
2014-09-09 11:36 ` [PATCH v4 " Ulf Hansson
2014-09-09 11:36   ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 1/9] ACPI / PM: Let acpi_dev_pm_detach() return an error code Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-12 21:05     ` [v4,1/9] " Dmitry Torokhov
2014-09-12 21:05       ` [v4, 1/9] " Dmitry Torokhov
2014-09-14 16:38       ` [v4,1/9] " Rafael J. Wysocki
2014-09-14 16:38         ` [v4, 1/9] " Rafael J. Wysocki
2014-09-15 16:53         ` [v4,1/9] " Dmitry Torokhov
2014-09-15 16:53           ` [v4, 1/9] " Dmitry Torokhov
2014-09-15 23:36           ` [v4,1/9] " Rafael J. Wysocki
2014-09-15 23:36             ` [v4, 1/9] " Rafael J. Wysocki
2014-09-17 18:25             ` [v4,1/9] " Ulf Hansson
2014-09-17 18:25               ` [v4, 1/9] " Ulf Hansson
2014-09-17 20:10               ` [v4,1/9] " Dmitry Torokhov
2014-09-17 20:10                 ` [v4, 1/9] " Dmitry Torokhov
2014-09-17 23:20                 ` [v4,1/9] " Ulf Hansson
2014-09-17 23:20                   ` [v4, 1/9] " Ulf Hansson
2014-09-17 23:43                   ` [v4,1/9] " Dmitry Torokhov
2014-09-17 23:43                     ` [v4, 1/9] " Dmitry Torokhov
     [not found]                     ` <20140917234331.GA28771-WlK9ik9hQGAhIp7JRqBPierSzoNAToWh@public.gmane.org>
2014-09-18  0:35                       ` [v4,1/9] " Ulf Hansson
2014-09-18  0:35                         ` [v4, 1/9] " Ulf Hansson
2014-09-18 23:13                         ` [v4,1/9] " Rafael J. Wysocki
2014-09-18 23:13                           ` [v4, 1/9] " Rafael J. Wysocki
2014-09-09 11:36   ` [PATCH v4 2/9] PM / Domains: Add generic OF-based PM domain look-up Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 3/9] PM / Domains: Add APIs to attach/detach a PM domain for a device Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 4/9] drivercore / platform: Convert to dev_pm_domain_attach|detach() Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 13:46     ` Rafael J. Wysocki
2014-09-09 13:46       ` Rafael J. Wysocki
2014-09-09 11:36   ` [PATCH v4 5/9] i2c: core: " Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 6/9] mmc: sdio: " Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 7/9] spi: core: " Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 8/9] amba: Add support for attach/detach of PM domains Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:36   ` [PATCH v4 9/9] ARM: exynos: Move to generic PM domain DT bindings Ulf Hansson
2014-09-09 11:36     ` Ulf Hansson
2014-09-09 11:43   ` [PATCH v4 0/9] PM / Domains: Generic OF-based support Tomasz Figa
2014-09-09 11:43     ` Tomasz Figa
2014-09-09 11:54   ` Mark Brown
2014-09-09 11:54     ` Mark Brown
2014-09-09 12:45     ` Ulf Hansson
2014-09-09 12:45       ` Ulf Hansson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.