All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] Raspberry Pi power domains v2
@ 2015-12-04 17:45 ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Eric Anholt

This is a series to replace Alexander Aring's power domains
submission.  It uses a new firmware interface to add support for the
other power domains in the system, which I needed for the 3D support,
while still supporting the USB domain on older firmwares.  It also
drops the static declarations, so that the driver instance is entirely
contained inside of the device.

Alexander Aring (4):
  power: domain: add pm_genpd_exit
  ARM: bcm2835: add rpi power domain driver
  dt-bindings: add rpi power domain driver bindings
  ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT.

Eric Anholt (1):
  ARM: bcm2835: Define two new packets from the latest firmware.

 .../bindings/arm/bcm/raspberrypi,bcm2835-power.txt |  47 ++++
 arch/arm/boot/dts/bcm2835-rpi.dtsi                 |  11 +
 arch/arm/boot/dts/bcm2835.dtsi                     |   2 +-
 arch/arm/mach-bcm/Kconfig                          |  10 +
 arch/arm/mach-bcm/Makefile                         |   1 +
 arch/arm/mach-bcm/raspberrypi-power.c              | 269 +++++++++++++++++++++
 drivers/base/power/domain.c                        |  22 ++
 include/dt-bindings/arm/raspberrypi-power.h        |  41 ++++
 include/linux/pm_domain.h                          |   4 +
 include/soc/bcm2835/raspberrypi-firmware.h         |   2 +
 10 files changed, 408 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
 create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
 create mode 100644 include/dt-bindings/arm/raspberrypi-power.h

-- 
2.6.2


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

* [PATCH v2 0/5] Raspberry Pi power domains v2
@ 2015-12-04 17:45 ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mark Rutland, devicetree, Ulf Hansson, Florian Fainelli,
	Alexander Aring, Pawel Moll, Stephen Warren, Eric Anholt,
	Greg Kroah-Hartman, linux-pm, Lee Jones, linux-kernel,
	Kevin Hilman, Rob Herring, linux-rpi-kernel, Ian Campbell,
	linux-arm-kernel

This is a series to replace Alexander Aring's power domains
submission.  It uses a new firmware interface to add support for the
other power domains in the system, which I needed for the 3D support,
while still supporting the USB domain on older firmwares.  It also
drops the static declarations, so that the driver instance is entirely
contained inside of the device.

Alexander Aring (4):
  power: domain: add pm_genpd_exit
  ARM: bcm2835: add rpi power domain driver
  dt-bindings: add rpi power domain driver bindings
  ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT.

Eric Anholt (1):
  ARM: bcm2835: Define two new packets from the latest firmware.

 .../bindings/arm/bcm/raspberrypi,bcm2835-power.txt |  47 ++++
 arch/arm/boot/dts/bcm2835-rpi.dtsi                 |  11 +
 arch/arm/boot/dts/bcm2835.dtsi                     |   2 +-
 arch/arm/mach-bcm/Kconfig                          |  10 +
 arch/arm/mach-bcm/Makefile                         |   1 +
 arch/arm/mach-bcm/raspberrypi-power.c              | 269 +++++++++++++++++++++
 drivers/base/power/domain.c                        |  22 ++
 include/dt-bindings/arm/raspberrypi-power.h        |  41 ++++
 include/linux/pm_domain.h                          |   4 +
 include/soc/bcm2835/raspberrypi-firmware.h         |   2 +
 10 files changed, 408 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
 create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
 create mode 100644 include/dt-bindings/arm/raspberrypi-power.h

-- 
2.6.2

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

* [PATCH v2 0/5] Raspberry Pi power domains v2
@ 2015-12-04 17:45 ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

This is a series to replace Alexander Aring's power domains
submission.  It uses a new firmware interface to add support for the
other power domains in the system, which I needed for the 3D support,
while still supporting the USB domain on older firmwares.  It also
drops the static declarations, so that the driver instance is entirely
contained inside of the device.

Alexander Aring (4):
  power: domain: add pm_genpd_exit
  ARM: bcm2835: add rpi power domain driver
  dt-bindings: add rpi power domain driver bindings
  ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT.

Eric Anholt (1):
  ARM: bcm2835: Define two new packets from the latest firmware.

 .../bindings/arm/bcm/raspberrypi,bcm2835-power.txt |  47 ++++
 arch/arm/boot/dts/bcm2835-rpi.dtsi                 |  11 +
 arch/arm/boot/dts/bcm2835.dtsi                     |   2 +-
 arch/arm/mach-bcm/Kconfig                          |  10 +
 arch/arm/mach-bcm/Makefile                         |   1 +
 arch/arm/mach-bcm/raspberrypi-power.c              | 269 +++++++++++++++++++++
 drivers/base/power/domain.c                        |  22 ++
 include/dt-bindings/arm/raspberrypi-power.h        |  41 ++++
 include/linux/pm_domain.h                          |   4 +
 include/soc/bcm2835/raspberrypi-firmware.h         |   2 +
 10 files changed, 408 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
 create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
 create mode 100644 include/dt-bindings/arm/raspberrypi-power.h

-- 
2.6.2

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-04 17:45 ` Eric Anholt
  (?)
@ 2015-12-04 17:45   ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Pavel Machek,
	Len Brown, Eric Anholt

From: Alexander Aring <alex.aring@gmail.com>

This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
is useful for multiple power domains while probing. If the probing fails
after one pm_genpd_init was called we need to undo all previous
registrations of generic pm domains inside the gpd_list list.

There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
registered power domains and not registered domains, the driver can use
this mechanism to have an array with registered and non-registered power
domains, where non-registered power domains are NULL.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/domain.c | 22 ++++++++++++++++++++++
 include/linux/pm_domain.h   |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 167418e..e7aca27 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 }
 EXPORT_SYMBOL_GPL(pm_genpd_init);
 
+/**
+ * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
+ * @genpd: PM domain object to uninitialize.
+ */
+void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+	if (IS_ERR_OR_NULL(genpd))
+		return;
+
+	/* check if domain is still in registered inside the pm subsystem */
+	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
+		     !list_empty(&genpd->slave_links) ||
+		     !list_empty(&genpd->dev_list));
+
+	mutex_lock(&gpd_list_lock);
+	list_del(&genpd->gpd_list_node);
+	mutex_unlock(&gpd_list_lock);
+
+	mutex_destroy(&genpd->lock);
+}
+EXPORT_SYMBOL_GPL(pm_genpd_exit);
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
 /*
  * Device Tree based PM domain providers.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ba4ced3..5020b36 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -123,6 +123,7 @@ extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 				     struct generic_pm_domain *target);
 extern void pm_genpd_init(struct generic_pm_domain *genpd,
 			  struct dev_power_governor *gov, bool is_off);
+extern void pm_genpd_exit(struct generic_pm_domain *genpd);
 
 extern struct dev_power_governor simple_qos_governor;
 extern struct dev_power_governor pm_domain_always_on_gov;
@@ -161,6 +162,9 @@ static inline void pm_genpd_init(struct generic_pm_domain *genpd,
 				 struct dev_power_governor *gov, bool is_off)
 {
 }
+static inline void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+}
 #endif
 
 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
-- 
2.6.2


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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mark Rutland, devicetree, Ulf Hansson, Florian Fainelli,
	Alexander Aring, Pawel Moll, Stephen Warren, Eric Anholt,
	Greg Kroah-Hartman, linux-pm, Lee Jones, linux-kernel,
	Kevin Hilman, Rob Herring, linux-rpi-kernel, Pavel Machek,
	Len Brown, Ian Campbell, linux-arm-kernel

From: Alexander Aring <alex.aring@gmail.com>

This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
is useful for multiple power domains while probing. If the probing fails
after one pm_genpd_init was called we need to undo all previous
registrations of generic pm domains inside the gpd_list list.

There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
registered power domains and not registered domains, the driver can use
this mechanism to have an array with registered and non-registered power
domains, where non-registered power domains are NULL.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/domain.c | 22 ++++++++++++++++++++++
 include/linux/pm_domain.h   |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 167418e..e7aca27 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 }
 EXPORT_SYMBOL_GPL(pm_genpd_init);
 
+/**
+ * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
+ * @genpd: PM domain object to uninitialize.
+ */
+void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+	if (IS_ERR_OR_NULL(genpd))
+		return;
+
+	/* check if domain is still in registered inside the pm subsystem */
+	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
+		     !list_empty(&genpd->slave_links) ||
+		     !list_empty(&genpd->dev_list));
+
+	mutex_lock(&gpd_list_lock);
+	list_del(&genpd->gpd_list_node);
+	mutex_unlock(&gpd_list_lock);
+
+	mutex_destroy(&genpd->lock);
+}
+EXPORT_SYMBOL_GPL(pm_genpd_exit);
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
 /*
  * Device Tree based PM domain providers.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ba4ced3..5020b36 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -123,6 +123,7 @@ extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 				     struct generic_pm_domain *target);
 extern void pm_genpd_init(struct generic_pm_domain *genpd,
 			  struct dev_power_governor *gov, bool is_off);
+extern void pm_genpd_exit(struct generic_pm_domain *genpd);
 
 extern struct dev_power_governor simple_qos_governor;
 extern struct dev_power_governor pm_domain_always_on_gov;
@@ -161,6 +162,9 @@ static inline void pm_genpd_init(struct generic_pm_domain *genpd,
 				 struct dev_power_governor *gov, bool is_off)
 {
 }
+static inline void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+}
 #endif
 
 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
-- 
2.6.2

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

From: Alexander Aring <alex.aring@gmail.com>

This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
is useful for multiple power domains while probing. If the probing fails
after one pm_genpd_init was called we need to undo all previous
registrations of generic pm domains inside the gpd_list list.

There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
registered power domains and not registered domains, the driver can use
this mechanism to have an array with registered and non-registered power
domains, where non-registered power domains are NULL.

Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Kevin Hilman <khilman@kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Len Brown <len.brown@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/domain.c | 22 ++++++++++++++++++++++
 include/linux/pm_domain.h   |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 167418e..e7aca27 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
 }
 EXPORT_SYMBOL_GPL(pm_genpd_init);
 
+/**
+ * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
+ * @genpd: PM domain object to uninitialize.
+ */
+void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+	if (IS_ERR_OR_NULL(genpd))
+		return;
+
+	/* check if domain is still in registered inside the pm subsystem */
+	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
+		     !list_empty(&genpd->slave_links) ||
+		     !list_empty(&genpd->dev_list));
+
+	mutex_lock(&gpd_list_lock);
+	list_del(&genpd->gpd_list_node);
+	mutex_unlock(&gpd_list_lock);
+
+	mutex_destroy(&genpd->lock);
+}
+EXPORT_SYMBOL_GPL(pm_genpd_exit);
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
 /*
  * Device Tree based PM domain providers.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index ba4ced3..5020b36 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -123,6 +123,7 @@ extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
 				     struct generic_pm_domain *target);
 extern void pm_genpd_init(struct generic_pm_domain *genpd,
 			  struct dev_power_governor *gov, bool is_off);
+extern void pm_genpd_exit(struct generic_pm_domain *genpd);
 
 extern struct dev_power_governor simple_qos_governor;
 extern struct dev_power_governor pm_domain_always_on_gov;
@@ -161,6 +162,9 @@ static inline void pm_genpd_init(struct generic_pm_domain *genpd,
 				 struct dev_power_governor *gov, bool is_off)
 {
 }
+static inline void pm_genpd_exit(struct generic_pm_domain *genpd)
+{
+}
 #endif
 
 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
-- 
2.6.2

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

* [PATCH v2 2/5] ARM: bcm2835: Define two new packets from the latest firmware.
  2015-12-04 17:45 ` Eric Anholt
  (?)
@ 2015-12-04 17:45   ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Eric Anholt

These packets give us direct access to the firmware's power management
code, as opposed to GET/SET_POWER_STATE packets that only had a couple
of domains implemented.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 include/soc/bcm2835/raspberrypi-firmware.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index c07d74a..3fb3571 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -72,10 +72,12 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_SET_ENABLE_QPU =                         0x00030012,
 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
+	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
 	RPI_FIRMWARE_SET_CLOCK_STATE =                        0x00038001,
 	RPI_FIRMWARE_SET_CLOCK_RATE =                         0x00038002,
 	RPI_FIRMWARE_SET_VOLTAGE =                            0x00038003,
 	RPI_FIRMWARE_SET_TURBO =                              0x00038009,
+	RPI_FIRMWARE_SET_DOMAIN_STATE =                       0x00038030,
 
 	/* Dispmanx TAGS */
 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
-- 
2.6.2


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

* [PATCH v2 2/5] ARM: bcm2835: Define two new packets from the latest firmware.
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Mark Rutland, devicetree, Ulf Hansson, Florian Fainelli,
	Alexander Aring, Pawel Moll, Stephen Warren, Eric Anholt,
	Greg Kroah-Hartman, linux-pm, Lee Jones, linux-kernel,
	Kevin Hilman, Rob Herring, linux-rpi-kernel, Ian Campbell,
	linux-arm-kernel

These packets give us direct access to the firmware's power management
code, as opposed to GET/SET_POWER_STATE packets that only had a couple
of domains implemented.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 include/soc/bcm2835/raspberrypi-firmware.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index c07d74a..3fb3571 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -72,10 +72,12 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_SET_ENABLE_QPU =                         0x00030012,
 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
+	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
 	RPI_FIRMWARE_SET_CLOCK_STATE =                        0x00038001,
 	RPI_FIRMWARE_SET_CLOCK_RATE =                         0x00038002,
 	RPI_FIRMWARE_SET_VOLTAGE =                            0x00038003,
 	RPI_FIRMWARE_SET_TURBO =                              0x00038009,
+	RPI_FIRMWARE_SET_DOMAIN_STATE =                       0x00038030,
 
 	/* Dispmanx TAGS */
 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
-- 
2.6.2

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

* [PATCH v2 2/5] ARM: bcm2835: Define two new packets from the latest firmware.
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

These packets give us direct access to the firmware's power management
code, as opposed to GET/SET_POWER_STATE packets that only had a couple
of domains implemented.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 include/soc/bcm2835/raspberrypi-firmware.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/soc/bcm2835/raspberrypi-firmware.h b/include/soc/bcm2835/raspberrypi-firmware.h
index c07d74a..3fb3571 100644
--- a/include/soc/bcm2835/raspberrypi-firmware.h
+++ b/include/soc/bcm2835/raspberrypi-firmware.h
@@ -72,10 +72,12 @@ enum rpi_firmware_property_tag {
 	RPI_FIRMWARE_SET_ENABLE_QPU =                         0x00030012,
 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
+	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
 	RPI_FIRMWARE_SET_CLOCK_STATE =                        0x00038001,
 	RPI_FIRMWARE_SET_CLOCK_RATE =                         0x00038002,
 	RPI_FIRMWARE_SET_VOLTAGE =                            0x00038003,
 	RPI_FIRMWARE_SET_TURBO =                              0x00038009,
+	RPI_FIRMWARE_SET_DOMAIN_STATE =                       0x00038030,
 
 	/* Dispmanx TAGS */
 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
-- 
2.6.2

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

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
  2015-12-04 17:45 ` Eric Anholt
@ 2015-12-04 17:45   ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Eric Anholt

From: Alexander Aring <alex.aring@gmail.com>

This patch adds support for several power domains on Raspberry Pi,
including USB (so it can be enabled even if the bootloader didn't do
it), and graphics.

This patch is the combined work of Eric Anholt (who wrote USB support
inside of the Raspberry Pi firmware driver, and wrote the non-USB
domain support) and Alexander Aring (who separated the original USB
work out from the firmware driver).

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
---

v2: Add support for power domains other than USB, using the new
    firmware interface, reword commit message (changes by Eric)

 arch/arm/mach-bcm/Kconfig                   |  10 ++
 arch/arm/mach-bcm/Makefile                  |   1 +
 arch/arm/mach-bcm/raspberrypi-power.c       | 269 ++++++++++++++++++++++++++++
 include/dt-bindings/arm/raspberrypi-power.h |  41 +++++
 4 files changed, 321 insertions(+)
 create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
 create mode 100644 include/dt-bindings/arm/raspberrypi-power.h

diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
index 8c53c55..0f23bad 100644
--- a/arch/arm/mach-bcm/Kconfig
+++ b/arch/arm/mach-bcm/Kconfig
@@ -134,6 +134,16 @@ config ARCH_BCM2835
 	  This enables support for the Broadcom BCM2835 SoC. This SoC is
 	  used in the Raspberry Pi and Roku 2 devices.
 
+config RASPBERRYPI_POWER
+	bool "Raspberry Pi power domain driver"
+	depends on ARCH_BCM2835 || COMPILE_TEST
+	depends on RASPBERRYPI_FIRMWARE
+	select PM_GENERIC_DOMAINS if PM
+	select PM_GENERIC_DOMAINS_OF if PM
+	help
+	  This enables support for the RPi power domains which can be enabled
+	  or disabled via the RPi firmware.
+
 config ARCH_BCM_63XX
 	bool "Broadcom BCM63xx DSL SoC" if ARCH_MULTI_V7
 	depends on MMU
diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
index 892261f..fec2d6b 100644
--- a/arch/arm/mach-bcm/Makefile
+++ b/arch/arm/mach-bcm/Makefile
@@ -36,6 +36,7 @@ endif
 
 # BCM2835
 obj-$(CONFIG_ARCH_BCM2835)	+= board_bcm2835.o
+obj-$(CONFIG_RASPBERRYPI_POWER)	+= raspberrypi-power.o
 
 # BCM5301X
 obj-$(CONFIG_ARCH_BCM_5301X)	+= bcm_5301x.o
diff --git a/arch/arm/mach-bcm/raspberrypi-power.c b/arch/arm/mach-bcm/raspberrypi-power.c
new file mode 100644
index 0000000..3444301
--- /dev/null
+++ b/arch/arm/mach-bcm/raspberrypi-power.c
@@ -0,0 +1,269 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Authors:
+ * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
+ * Eric Anholt <eric@anholt.net>
+ */
+
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <dt-bindings/arm/raspberrypi-power.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+/*
+ * Firmware indices for the old power domains interface.  Only a few
+ * of them were actually implemented.
+ */
+#define RPI_OLD_POWER_DOMAIN_USB		3
+#define RPI_OLD_POWER_DOMAIN_V3D		10
+
+struct rpi_power_domain {
+	u32 domain;
+	bool enabled;
+	bool old_interface;
+	struct generic_pm_domain base;
+	struct rpi_firmware *fw;
+};
+
+struct rpi_power_domains {
+	bool has_new_interface;
+	struct genpd_onecell_data xlate;
+	struct rpi_firmware *fw;
+	struct rpi_power_domain domains[RPI_POWER_DOMAIN_COUNT];
+};
+
+/*
+ * Packet definition used by RPI_FIRMWARE_SET_POWER_STATE and
+ * RPI_FIRMWARE_SET_DOMAIN_STATE
+ */
+struct rpi_power_domain_packet {
+	u32 domain;
+	u32 on;
+} __packet;
+
+/*
+ * Asks the firmware to enable or disable power on a specific power
+ * domain.
+ */
+static int rpi_firmware_set_power(struct rpi_power_domain *rpi_domain, bool on)
+{
+	struct rpi_power_domain_packet packet;
+
+	packet.domain = rpi_domain->domain;
+	packet.on = on;
+	return rpi_firmware_property(rpi_domain->fw,
+				     rpi_domain->old_interface ?
+				     RPI_FIRMWARE_SET_POWER_STATE :
+				     RPI_FIRMWARE_SET_DOMAIN_STATE,
+				     &packet, sizeof(packet));
+}
+
+static int rpi_domain_off(struct generic_pm_domain *domain)
+{
+	struct rpi_power_domain *rpi_domain =
+		container_of(domain, struct rpi_power_domain, base);
+
+	return rpi_firmware_set_power(rpi_domain, false);
+}
+
+static int rpi_domain_on(struct generic_pm_domain *domain)
+{
+	struct rpi_power_domain *rpi_domain =
+		container_of(domain, struct rpi_power_domain, base);
+
+	return rpi_firmware_set_power(rpi_domain, true);
+}
+
+static void rpi_common_init_power_domain(struct rpi_power_domains *rpi_domains,
+					 int xlate_index, const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	dom->fw = rpi_domains->fw;
+
+	dom->base.name = name;
+	dom->base.power_on = rpi_domain_on;
+	dom->base.power_off = rpi_domain_off;
+
+	/*
+	 * Treat all power domains as off at boot.
+	 *
+	 * The firmware itself may be keeping some domains on, but
+	 * from Linux's perspective all we control is the refcounts
+	 * that we give to the firmware, and we can't ask the firmware
+	 * to turn off something that we haven't ourselves turned on.
+	 */
+	pm_genpd_init(&dom->base, NULL, true);
+
+	rpi_domains->xlate.domains[xlate_index] = &dom->base;
+}
+
+static void rpi_init_power_domain(struct rpi_power_domains *rpi_domains,
+				  int xlate_index, const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	if (!rpi_domains->has_new_interface)
+		return;
+
+	/* The DT binding index is the firmware's domain index minus one. */
+	dom->domain = xlate_index + 1;
+
+	rpi_common_init_power_domain(rpi_domains, xlate_index, name);
+}
+
+static void rpi_init_old_power_domain(struct rpi_power_domains *rpi_domains,
+				      int xlate_index, int domain,
+				      const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	dom->old_interface = true;
+	dom->domain = domain;
+
+	rpi_common_init_power_domain(rpi_domains, xlate_index, name);
+}
+
+/*
+ * Detects whether the firmware supports the new power domains interface.
+ *
+ * The firmware doesn't actually return an error on an unknown tag,
+ * and just skips over it, so we do the detection by putting an
+ * unexpected value in the return field and checking if it was
+ * unchanged.
+ */
+static bool
+rpi_has_new_domain_support(struct rpi_power_domains *rpi_domains)
+{
+	struct rpi_power_domain_packet packet;
+	int ret;
+
+	packet.domain = RPI_POWER_DOMAIN_ARM;
+	packet.on = ~0;
+
+	ret = rpi_firmware_property(rpi_domains->fw,
+				    RPI_FIRMWARE_GET_DOMAIN_STATE,
+				    &packet, sizeof(packet));
+
+	return ret == 0 && packet.on != ~0;
+}
+
+static int rpi_power_probe(struct platform_device *pdev)
+{
+	struct device_node *fw_np;
+	struct device *dev = &pdev->dev;
+	struct rpi_power_domains *rpi_domains;
+	int ret, i;
+
+	rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL);
+	if (!rpi_domains)
+		return -ENOMEM;
+
+	rpi_domains->xlate.domains =
+		devm_kzalloc(dev, sizeof(*rpi_domains->xlate.domains) *
+			     RPI_POWER_DOMAIN_COUNT, GFP_KERNEL);
+	if (!rpi_domains->xlate.domains)
+		return -ENOMEM;
+
+	rpi_domains->xlate.num_domains = RPI_POWER_DOMAIN_COUNT;
+
+	fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
+	if (!fw_np) {
+		dev_err(&pdev->dev, "no firmware node\n");
+		return -ENODEV;
+	}
+
+	rpi_domains->fw = rpi_firmware_get(fw_np);
+	of_node_put(fw_np);
+	if (!rpi_domains->fw)
+		return -EPROBE_DEFER;
+
+	rpi_domains->has_new_interface =
+		rpi_has_new_domain_support(rpi_domains);
+
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C0, "I2C0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C1, "I2C1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C2, "I2C2");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VIDEO_SCALER,
+			      "VIDEO_SCALER");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VPU1, "VPU1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_HDMI, "HDMI");
+
+	/*
+	 * Use the old firmware interface for USB power, so that we
+	 * can turn it on even if the firmware hasn't been updated.
+	 */
+	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
+				  RPI_OLD_POWER_DOMAIN_USB, "USB");
+
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VEC, "VEC");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_JPEG, "JPEG");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_H264, "H264");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_V3D, "V3D");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM0, "UNICAM0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM1, "UNICAM1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2RX, "CCP2RX");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CSI2, "CSI2");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CPI, "CPI");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI0, "DSI0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI1, "DSI1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_TRANSPOSER,
+			      "TRANPOSER");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2TX, "CCP2TX");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
+
+	ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
+	if (ret < 0)
+		goto exit_pm;
+
+	platform_set_drvdata(pdev, rpi_domains);
+
+	return 0;
+
+exit_pm:
+	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
+		pm_genpd_exit(rpi_domains->xlate.domains[i]);
+
+	return ret;
+}
+
+static int rpi_power_remove(struct platform_device *pdev)
+{
+	struct rpi_power_domains *rpi_domains = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+	int i;
+
+	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
+		pm_genpd_exit(rpi_domains->xlate.domains[i]);
+
+	of_genpd_del_provider(dev->of_node);
+
+	return 0;
+}
+
+static const struct of_device_id rpi_power_of_match[] = {
+	{ .compatible = "raspberrypi,bcm2835-power", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, rpi_power_of_match);
+
+static struct platform_driver rpi_power_driver = {
+	.driver = {
+		.name = "raspberrypi-power",
+		.of_match_table = rpi_power_of_match,
+	},
+	.probe		= rpi_power_probe,
+	.remove		= rpi_power_remove,
+};
+module_platform_driver(rpi_power_driver);
+
+MODULE_AUTHOR("Alexander Aring <aar@pengutronix.de>");
+MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
+MODULE_DESCRIPTION("Raspberry Pi power domain driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/dt-bindings/arm/raspberrypi-power.h b/include/dt-bindings/arm/raspberrypi-power.h
new file mode 100644
index 0000000..b3ff8e0
--- /dev/null
+++ b/include/dt-bindings/arm/raspberrypi-power.h
@@ -0,0 +1,41 @@
+/*
+ *  Copyright © 2015 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H
+#define _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H
+
+/* These power domain indices are the firmware interface's indices
+ * minus one.
+ */
+#define RPI_POWER_DOMAIN_I2C0		0
+#define RPI_POWER_DOMAIN_I2C1		1
+#define RPI_POWER_DOMAIN_I2C2		2
+#define RPI_POWER_DOMAIN_VIDEO_SCALER	3
+#define RPI_POWER_DOMAIN_VPU1		4
+#define RPI_POWER_DOMAIN_HDMI		5
+#define RPI_POWER_DOMAIN_USB		6
+#define RPI_POWER_DOMAIN_VEC		7
+#define RPI_POWER_DOMAIN_JPEG		8
+#define RPI_POWER_DOMAIN_H264		9
+#define RPI_POWER_DOMAIN_V3D		10
+#define RPI_POWER_DOMAIN_ISP		11
+#define RPI_POWER_DOMAIN_UNICAM0	12
+#define RPI_POWER_DOMAIN_UNICAM1	13
+#define RPI_POWER_DOMAIN_CCP2RX		14
+#define RPI_POWER_DOMAIN_CSI2		15
+#define RPI_POWER_DOMAIN_CPI		16
+#define RPI_POWER_DOMAIN_DSI0		17
+#define RPI_POWER_DOMAIN_DSI1		18
+#define RPI_POWER_DOMAIN_TRANSPOSER	19
+#define RPI_POWER_DOMAIN_CCP2TX		20
+#define RPI_POWER_DOMAIN_CDP		21
+#define RPI_POWER_DOMAIN_ARM		22
+
+#define RPI_POWER_DOMAIN_COUNT		23
+
+#endif /* _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H */
-- 
2.6.2


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

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

From: Alexander Aring <alex.aring@gmail.com>

This patch adds support for several power domains on Raspberry Pi,
including USB (so it can be enabled even if the bootloader didn't do
it), and graphics.

This patch is the combined work of Eric Anholt (who wrote USB support
inside of the Raspberry Pi firmware driver, and wrote the non-USB
domain support) and Alexander Aring (who separated the original USB
work out from the firmware driver).

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
---

v2: Add support for power domains other than USB, using the new
    firmware interface, reword commit message (changes by Eric)

 arch/arm/mach-bcm/Kconfig                   |  10 ++
 arch/arm/mach-bcm/Makefile                  |   1 +
 arch/arm/mach-bcm/raspberrypi-power.c       | 269 ++++++++++++++++++++++++++++
 include/dt-bindings/arm/raspberrypi-power.h |  41 +++++
 4 files changed, 321 insertions(+)
 create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
 create mode 100644 include/dt-bindings/arm/raspberrypi-power.h

diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
index 8c53c55..0f23bad 100644
--- a/arch/arm/mach-bcm/Kconfig
+++ b/arch/arm/mach-bcm/Kconfig
@@ -134,6 +134,16 @@ config ARCH_BCM2835
 	  This enables support for the Broadcom BCM2835 SoC. This SoC is
 	  used in the Raspberry Pi and Roku 2 devices.
 
+config RASPBERRYPI_POWER
+	bool "Raspberry Pi power domain driver"
+	depends on ARCH_BCM2835 || COMPILE_TEST
+	depends on RASPBERRYPI_FIRMWARE
+	select PM_GENERIC_DOMAINS if PM
+	select PM_GENERIC_DOMAINS_OF if PM
+	help
+	  This enables support for the RPi power domains which can be enabled
+	  or disabled via the RPi firmware.
+
 config ARCH_BCM_63XX
 	bool "Broadcom BCM63xx DSL SoC" if ARCH_MULTI_V7
 	depends on MMU
diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
index 892261f..fec2d6b 100644
--- a/arch/arm/mach-bcm/Makefile
+++ b/arch/arm/mach-bcm/Makefile
@@ -36,6 +36,7 @@ endif
 
 # BCM2835
 obj-$(CONFIG_ARCH_BCM2835)	+= board_bcm2835.o
+obj-$(CONFIG_RASPBERRYPI_POWER)	+= raspberrypi-power.o
 
 # BCM5301X
 obj-$(CONFIG_ARCH_BCM_5301X)	+= bcm_5301x.o
diff --git a/arch/arm/mach-bcm/raspberrypi-power.c b/arch/arm/mach-bcm/raspberrypi-power.c
new file mode 100644
index 0000000..3444301
--- /dev/null
+++ b/arch/arm/mach-bcm/raspberrypi-power.c
@@ -0,0 +1,269 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Authors:
+ * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
+ * Eric Anholt <eric@anholt.net>
+ */
+
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
+#include <dt-bindings/arm/raspberrypi-power.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
+
+/*
+ * Firmware indices for the old power domains interface.  Only a few
+ * of them were actually implemented.
+ */
+#define RPI_OLD_POWER_DOMAIN_USB		3
+#define RPI_OLD_POWER_DOMAIN_V3D		10
+
+struct rpi_power_domain {
+	u32 domain;
+	bool enabled;
+	bool old_interface;
+	struct generic_pm_domain base;
+	struct rpi_firmware *fw;
+};
+
+struct rpi_power_domains {
+	bool has_new_interface;
+	struct genpd_onecell_data xlate;
+	struct rpi_firmware *fw;
+	struct rpi_power_domain domains[RPI_POWER_DOMAIN_COUNT];
+};
+
+/*
+ * Packet definition used by RPI_FIRMWARE_SET_POWER_STATE and
+ * RPI_FIRMWARE_SET_DOMAIN_STATE
+ */
+struct rpi_power_domain_packet {
+	u32 domain;
+	u32 on;
+} __packet;
+
+/*
+ * Asks the firmware to enable or disable power on a specific power
+ * domain.
+ */
+static int rpi_firmware_set_power(struct rpi_power_domain *rpi_domain, bool on)
+{
+	struct rpi_power_domain_packet packet;
+
+	packet.domain = rpi_domain->domain;
+	packet.on = on;
+	return rpi_firmware_property(rpi_domain->fw,
+				     rpi_domain->old_interface ?
+				     RPI_FIRMWARE_SET_POWER_STATE :
+				     RPI_FIRMWARE_SET_DOMAIN_STATE,
+				     &packet, sizeof(packet));
+}
+
+static int rpi_domain_off(struct generic_pm_domain *domain)
+{
+	struct rpi_power_domain *rpi_domain =
+		container_of(domain, struct rpi_power_domain, base);
+
+	return rpi_firmware_set_power(rpi_domain, false);
+}
+
+static int rpi_domain_on(struct generic_pm_domain *domain)
+{
+	struct rpi_power_domain *rpi_domain =
+		container_of(domain, struct rpi_power_domain, base);
+
+	return rpi_firmware_set_power(rpi_domain, true);
+}
+
+static void rpi_common_init_power_domain(struct rpi_power_domains *rpi_domains,
+					 int xlate_index, const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	dom->fw = rpi_domains->fw;
+
+	dom->base.name = name;
+	dom->base.power_on = rpi_domain_on;
+	dom->base.power_off = rpi_domain_off;
+
+	/*
+	 * Treat all power domains as off at boot.
+	 *
+	 * The firmware itself may be keeping some domains on, but
+	 * from Linux's perspective all we control is the refcounts
+	 * that we give to the firmware, and we can't ask the firmware
+	 * to turn off something that we haven't ourselves turned on.
+	 */
+	pm_genpd_init(&dom->base, NULL, true);
+
+	rpi_domains->xlate.domains[xlate_index] = &dom->base;
+}
+
+static void rpi_init_power_domain(struct rpi_power_domains *rpi_domains,
+				  int xlate_index, const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	if (!rpi_domains->has_new_interface)
+		return;
+
+	/* The DT binding index is the firmware's domain index minus one. */
+	dom->domain = xlate_index + 1;
+
+	rpi_common_init_power_domain(rpi_domains, xlate_index, name);
+}
+
+static void rpi_init_old_power_domain(struct rpi_power_domains *rpi_domains,
+				      int xlate_index, int domain,
+				      const char *name)
+{
+	struct rpi_power_domain *dom = &rpi_domains->domains[xlate_index];
+
+	dom->old_interface = true;
+	dom->domain = domain;
+
+	rpi_common_init_power_domain(rpi_domains, xlate_index, name);
+}
+
+/*
+ * Detects whether the firmware supports the new power domains interface.
+ *
+ * The firmware doesn't actually return an error on an unknown tag,
+ * and just skips over it, so we do the detection by putting an
+ * unexpected value in the return field and checking if it was
+ * unchanged.
+ */
+static bool
+rpi_has_new_domain_support(struct rpi_power_domains *rpi_domains)
+{
+	struct rpi_power_domain_packet packet;
+	int ret;
+
+	packet.domain = RPI_POWER_DOMAIN_ARM;
+	packet.on = ~0;
+
+	ret = rpi_firmware_property(rpi_domains->fw,
+				    RPI_FIRMWARE_GET_DOMAIN_STATE,
+				    &packet, sizeof(packet));
+
+	return ret == 0 && packet.on != ~0;
+}
+
+static int rpi_power_probe(struct platform_device *pdev)
+{
+	struct device_node *fw_np;
+	struct device *dev = &pdev->dev;
+	struct rpi_power_domains *rpi_domains;
+	int ret, i;
+
+	rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL);
+	if (!rpi_domains)
+		return -ENOMEM;
+
+	rpi_domains->xlate.domains =
+		devm_kzalloc(dev, sizeof(*rpi_domains->xlate.domains) *
+			     RPI_POWER_DOMAIN_COUNT, GFP_KERNEL);
+	if (!rpi_domains->xlate.domains)
+		return -ENOMEM;
+
+	rpi_domains->xlate.num_domains = RPI_POWER_DOMAIN_COUNT;
+
+	fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
+	if (!fw_np) {
+		dev_err(&pdev->dev, "no firmware node\n");
+		return -ENODEV;
+	}
+
+	rpi_domains->fw = rpi_firmware_get(fw_np);
+	of_node_put(fw_np);
+	if (!rpi_domains->fw)
+		return -EPROBE_DEFER;
+
+	rpi_domains->has_new_interface =
+		rpi_has_new_domain_support(rpi_domains);
+
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C0, "I2C0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C1, "I2C1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C2, "I2C2");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VIDEO_SCALER,
+			      "VIDEO_SCALER");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VPU1, "VPU1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_HDMI, "HDMI");
+
+	/*
+	 * Use the old firmware interface for USB power, so that we
+	 * can turn it on even if the firmware hasn't been updated.
+	 */
+	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
+				  RPI_OLD_POWER_DOMAIN_USB, "USB");
+
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VEC, "VEC");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_JPEG, "JPEG");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_H264, "H264");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_V3D, "V3D");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM0, "UNICAM0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM1, "UNICAM1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2RX, "CCP2RX");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CSI2, "CSI2");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CPI, "CPI");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI0, "DSI0");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI1, "DSI1");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_TRANSPOSER,
+			      "TRANPOSER");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2TX, "CCP2TX");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
+	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
+
+	ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
+	if (ret < 0)
+		goto exit_pm;
+
+	platform_set_drvdata(pdev, rpi_domains);
+
+	return 0;
+
+exit_pm:
+	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
+		pm_genpd_exit(rpi_domains->xlate.domains[i]);
+
+	return ret;
+}
+
+static int rpi_power_remove(struct platform_device *pdev)
+{
+	struct rpi_power_domains *rpi_domains = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+	int i;
+
+	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
+		pm_genpd_exit(rpi_domains->xlate.domains[i]);
+
+	of_genpd_del_provider(dev->of_node);
+
+	return 0;
+}
+
+static const struct of_device_id rpi_power_of_match[] = {
+	{ .compatible = "raspberrypi,bcm2835-power", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, rpi_power_of_match);
+
+static struct platform_driver rpi_power_driver = {
+	.driver = {
+		.name = "raspberrypi-power",
+		.of_match_table = rpi_power_of_match,
+	},
+	.probe		= rpi_power_probe,
+	.remove		= rpi_power_remove,
+};
+module_platform_driver(rpi_power_driver);
+
+MODULE_AUTHOR("Alexander Aring <aar@pengutronix.de>");
+MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
+MODULE_DESCRIPTION("Raspberry Pi power domain driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/dt-bindings/arm/raspberrypi-power.h b/include/dt-bindings/arm/raspberrypi-power.h
new file mode 100644
index 0000000..b3ff8e0
--- /dev/null
+++ b/include/dt-bindings/arm/raspberrypi-power.h
@@ -0,0 +1,41 @@
+/*
+ *  Copyright ? 2015 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H
+#define _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H
+
+/* These power domain indices are the firmware interface's indices
+ * minus one.
+ */
+#define RPI_POWER_DOMAIN_I2C0		0
+#define RPI_POWER_DOMAIN_I2C1		1
+#define RPI_POWER_DOMAIN_I2C2		2
+#define RPI_POWER_DOMAIN_VIDEO_SCALER	3
+#define RPI_POWER_DOMAIN_VPU1		4
+#define RPI_POWER_DOMAIN_HDMI		5
+#define RPI_POWER_DOMAIN_USB		6
+#define RPI_POWER_DOMAIN_VEC		7
+#define RPI_POWER_DOMAIN_JPEG		8
+#define RPI_POWER_DOMAIN_H264		9
+#define RPI_POWER_DOMAIN_V3D		10
+#define RPI_POWER_DOMAIN_ISP		11
+#define RPI_POWER_DOMAIN_UNICAM0	12
+#define RPI_POWER_DOMAIN_UNICAM1	13
+#define RPI_POWER_DOMAIN_CCP2RX		14
+#define RPI_POWER_DOMAIN_CSI2		15
+#define RPI_POWER_DOMAIN_CPI		16
+#define RPI_POWER_DOMAIN_DSI0		17
+#define RPI_POWER_DOMAIN_DSI1		18
+#define RPI_POWER_DOMAIN_TRANSPOSER	19
+#define RPI_POWER_DOMAIN_CCP2TX		20
+#define RPI_POWER_DOMAIN_CDP		21
+#define RPI_POWER_DOMAIN_ARM		22
+
+#define RPI_POWER_DOMAIN_COUNT		23
+
+#endif /* _DT_BINDINGS_ARM_BCM2835_RPI_POWER_H */
-- 
2.6.2

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

* [PATCH v2 4/5] dt-bindings: add rpi power domain driver bindings
  2015-12-04 17:45 ` Eric Anholt
@ 2015-12-04 17:45   ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Eric Anholt

From: Alexander Aring <alex.aring@gmail.com>

This patch adds devicetree tree bindings for the Raspberry Pi power
domain driver.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Eric Anholt <eric@anholt.net>
---

v2: Add the new domains present in v2 to the list.

 .../bindings/arm/bcm/raspberrypi,bcm2835-power.txt | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt

diff --git a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
new file mode 100644
index 0000000..30942cf
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
@@ -0,0 +1,47 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,bcm2835-power".
+- firmware:		Reference to the RPi firmware device node.
+- #power-domain-cells:	Should be <1>, we providing multiple power domains.
+
+The valid defines for power domain are:
+
+ RPI_POWER_DOMAIN_I2C0
+ RPI_POWER_DOMAIN_I2C1
+ RPI_POWER_DOMAIN_I2C2
+ RPI_POWER_DOMAIN_VIDEO_SCALER
+ RPI_POWER_DOMAIN_VPU1
+ RPI_POWER_DOMAIN_HDMI
+ RPI_POWER_DOMAIN_USB
+ RPI_POWER_DOMAIN_VEC
+ RPI_POWER_DOMAIN_JPEG
+ RPI_POWER_DOMAIN_H264
+ RPI_POWER_DOMAIN_V3D
+ RPI_POWER_DOMAIN_ISP
+ RPI_POWER_DOMAIN_UNICAM0
+ RPI_POWER_DOMAIN_UNICAM1
+ RPI_POWER_DOMAIN_CCP2RX
+ RPI_POWER_DOMAIN_CSI2
+ RPI_POWER_DOMAIN_CPI
+ RPI_POWER_DOMAIN_DSI0
+ RPI_POWER_DOMAIN_DSI1
+ RPI_POWER_DOMAIN_TRANSPOSER
+ RPI_POWER_DOMAIN_CCP2TX
+ RPI_POWER_DOMAIN_CDP
+ RPI_POWER_DOMAIN_ARM
+
+Example:
+
+power: power {
+	compatible = "raspberrypi,bcm2835-power";
+	firmware = <&firmware>;
+	#power-domain-cells = <1>;
+};
+
+Example for using power domain:
+
+&usb {
+       power-domains = <&power RPI_POWER_DOMAIN_USB>;
+};
-- 
2.6.2


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

* [PATCH v2 4/5] dt-bindings: add rpi power domain driver bindings
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

From: Alexander Aring <alex.aring@gmail.com>

This patch adds devicetree tree bindings for the Raspberry Pi power
domain driver.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Eric Anholt <eric@anholt.net>
---

v2: Add the new domains present in v2 to the list.

 .../bindings/arm/bcm/raspberrypi,bcm2835-power.txt | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt

diff --git a/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
new file mode 100644
index 0000000..30942cf
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/bcm/raspberrypi,bcm2835-power.txt
@@ -0,0 +1,47 @@
+Raspberry Pi power domain driver
+
+Required properties:
+
+- compatible:		Should be "raspberrypi,bcm2835-power".
+- firmware:		Reference to the RPi firmware device node.
+- #power-domain-cells:	Should be <1>, we providing multiple power domains.
+
+The valid defines for power domain are:
+
+ RPI_POWER_DOMAIN_I2C0
+ RPI_POWER_DOMAIN_I2C1
+ RPI_POWER_DOMAIN_I2C2
+ RPI_POWER_DOMAIN_VIDEO_SCALER
+ RPI_POWER_DOMAIN_VPU1
+ RPI_POWER_DOMAIN_HDMI
+ RPI_POWER_DOMAIN_USB
+ RPI_POWER_DOMAIN_VEC
+ RPI_POWER_DOMAIN_JPEG
+ RPI_POWER_DOMAIN_H264
+ RPI_POWER_DOMAIN_V3D
+ RPI_POWER_DOMAIN_ISP
+ RPI_POWER_DOMAIN_UNICAM0
+ RPI_POWER_DOMAIN_UNICAM1
+ RPI_POWER_DOMAIN_CCP2RX
+ RPI_POWER_DOMAIN_CSI2
+ RPI_POWER_DOMAIN_CPI
+ RPI_POWER_DOMAIN_DSI0
+ RPI_POWER_DOMAIN_DSI1
+ RPI_POWER_DOMAIN_TRANSPOSER
+ RPI_POWER_DOMAIN_CCP2TX
+ RPI_POWER_DOMAIN_CDP
+ RPI_POWER_DOMAIN_ARM
+
+Example:
+
+power: power {
+	compatible = "raspberrypi,bcm2835-power";
+	firmware = <&firmware>;
+	#power-domain-cells = <1>;
+};
+
+Example for using power domain:
+
+&usb {
+       power-domains = <&power RPI_POWER_DOMAIN_USB>;
+};
-- 
2.6.2

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

* [PATCH v2 5/5] ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT.
  2015-12-04 17:45 ` Eric Anholt
@ 2015-12-04 17:45   ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-arm-kernel, linux-rpi-kernel, linux-kernel, Stephen Warren,
	Lee Jones, Florian Fainelli, Kevin Hilman, Ulf Hansson,
	Greg Kroah-Hartman, Alexander Aring, devicetree, linux-pm,
	Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Eric Anholt

From: Alexander Aring <alex.aring@gmail.com>

This connects the USB driver to the USB power domain, so that USB can
actually be turned on at boot if the bootloader didn't do it for us.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 11 +++++++++++
 arch/arm/boot/dts/bcm2835.dtsi     |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
index 3572f03..f828202 100644
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
@@ -1,3 +1,4 @@
+#include <dt-bindings/arm/raspberrypi-power.h>
 #include "bcm2835.dtsi"
 
 / {
@@ -20,6 +21,12 @@
 			compatible = "raspberrypi,bcm2835-firmware";
 			mboxes = <&mailbox>;
 		};
+
+		power: power {
+			compatible = "raspberrypi,bcm2835-power";
+			firmware = <&firmware>;
+			#power-domain-cells = <1>;
+		};
 	};
 };
 
@@ -60,3 +67,7 @@
 	status = "okay";
 	bus-width = <4>;
 };
+
+&usb {
+	power-domains = <&power RPI_POWER_DOMAIN_USB>;
+};
diff --git a/arch/arm/boot/dts/bcm2835.dtsi b/arch/arm/boot/dts/bcm2835.dtsi
index aef64de..6d62af0 100644
--- a/arch/arm/boot/dts/bcm2835.dtsi
+++ b/arch/arm/boot/dts/bcm2835.dtsi
@@ -177,7 +177,7 @@
 			status = "disabled";
 		};
 
-		usb@7e980000 {
+		usb: usb@7e980000 {
 			compatible = "brcm,bcm2835-usb";
 			reg = <0x7e980000 0x10000>;
 			interrupts = <1 9>;
-- 
2.6.2


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

* [PATCH v2 5/5] ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT.
@ 2015-12-04 17:45   ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-04 17:45 UTC (permalink / raw)
  To: linux-arm-kernel

From: Alexander Aring <alex.aring@gmail.com>

This connects the USB driver to the USB power domain, so that USB can
actually be turned on at boot if the bootloader didn't do it for us.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
---
 arch/arm/boot/dts/bcm2835-rpi.dtsi | 11 +++++++++++
 arch/arm/boot/dts/bcm2835.dtsi     |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/bcm2835-rpi.dtsi b/arch/arm/boot/dts/bcm2835-rpi.dtsi
index 3572f03..f828202 100644
--- a/arch/arm/boot/dts/bcm2835-rpi.dtsi
+++ b/arch/arm/boot/dts/bcm2835-rpi.dtsi
@@ -1,3 +1,4 @@
+#include <dt-bindings/arm/raspberrypi-power.h>
 #include "bcm2835.dtsi"
 
 / {
@@ -20,6 +21,12 @@
 			compatible = "raspberrypi,bcm2835-firmware";
 			mboxes = <&mailbox>;
 		};
+
+		power: power {
+			compatible = "raspberrypi,bcm2835-power";
+			firmware = <&firmware>;
+			#power-domain-cells = <1>;
+		};
 	};
 };
 
@@ -60,3 +67,7 @@
 	status = "okay";
 	bus-width = <4>;
 };
+
+&usb {
+	power-domains = <&power RPI_POWER_DOMAIN_USB>;
+};
diff --git a/arch/arm/boot/dts/bcm2835.dtsi b/arch/arm/boot/dts/bcm2835.dtsi
index aef64de..6d62af0 100644
--- a/arch/arm/boot/dts/bcm2835.dtsi
+++ b/arch/arm/boot/dts/bcm2835.dtsi
@@ -177,7 +177,7 @@
 			status = "disabled";
 		};
 
-		usb at 7e980000 {
+		usb: usb at 7e980000 {
 			compatible = "brcm,bcm2835-usb";
 			reg = <0x7e980000 0x10000>;
 			interrupts = <1 9>;
-- 
2.6.2

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-04 17:45   ` Eric Anholt
  (?)
@ 2015-12-07 10:04     ` Jon Hunter
  -1 siblings, 0 replies; 37+ messages in thread
From: Jon Hunter @ 2015-12-07 10:04 UTC (permalink / raw)
  To: Eric Anholt, Rafael J. Wysocki
  Cc: Mark Rutland, devicetree, Ulf Hansson, Florian Fainelli,
	Alexander Aring, Pawel Moll, Stephen Warren, Greg Kroah-Hartman,
	linux-pm, Lee Jones, linux-kernel, Kevin Hilman, Rob Herring,
	linux-rpi-kernel, Pavel Machek, Len Brown, Ian Campbell,
	linux-arm-kernel


On 04/12/15 17:45, Eric Anholt wrote:
> From: Alexander Aring <alex.aring@gmail.com>
> 
> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
> is useful for multiple power domains while probing. If the probing fails
> after one pm_genpd_init was called we need to undo all previous
> registrations of generic pm domains inside the gpd_list list.
> 
> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
> registered power domains and not registered domains, the driver can use
> this mechanism to have an array with registered and non-registered power
> domains, where non-registered power domains are NULL.
> 
> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>  include/linux/pm_domain.h   |  4 ++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 167418e..e7aca27 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>  }
>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>  
> +/**
> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
> + * @genpd: PM domain object to uninitialize.
> + */
> +void pm_genpd_exit(struct generic_pm_domain *genpd)
> +{
> +	if (IS_ERR_OR_NULL(genpd))
> +		return;
> +
> +	/* check if domain is still in registered inside the pm subsystem */
> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
> +		     !list_empty(&genpd->slave_links) ||
> +		     !list_empty(&genpd->dev_list));
> +

Why not return an error here? Seems bad to remove it, if it could still
be referenced by other domains.

Also not sure if you need to lock around the above test and removing the
domain.

> +	mutex_lock(&gpd_list_lock);
> +	list_del(&genpd->gpd_list_node);
> +	mutex_unlock(&gpd_list_lock);
> +
> +	mutex_destroy(&genpd->lock);
> +}
> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
> +

BTW, I had just submitted a similar patch here [0]. So I would also like
to see such an API added.

Cheers
Jon

[0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-07 10:04     ` Jon Hunter
  0 siblings, 0 replies; 37+ messages in thread
From: Jon Hunter @ 2015-12-07 10:04 UTC (permalink / raw)
  To: Eric Anholt, Rafael J. Wysocki
  Cc: Mark Rutland, devicetree, Ulf Hansson, Florian Fainelli,
	Alexander Aring, Pawel Moll, Stephen Warren, Greg Kroah-Hartman,
	linux-pm, Lee Jones, linux-kernel, Kevin Hilman, Rob Herring,
	linux-rpi-kernel, Pavel Machek, Len Brown, Ian Campbell,
	linux-arm-kernel


On 04/12/15 17:45, Eric Anholt wrote:
> From: Alexander Aring <alex.aring@gmail.com>
> 
> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
> is useful for multiple power domains while probing. If the probing fails
> after one pm_genpd_init was called we need to undo all previous
> registrations of generic pm domains inside the gpd_list list.
> 
> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
> registered power domains and not registered domains, the driver can use
> this mechanism to have an array with registered and non-registered power
> domains, where non-registered power domains are NULL.
> 
> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>  include/linux/pm_domain.h   |  4 ++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 167418e..e7aca27 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>  }
>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>  
> +/**
> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
> + * @genpd: PM domain object to uninitialize.
> + */
> +void pm_genpd_exit(struct generic_pm_domain *genpd)
> +{
> +	if (IS_ERR_OR_NULL(genpd))
> +		return;
> +
> +	/* check if domain is still in registered inside the pm subsystem */
> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
> +		     !list_empty(&genpd->slave_links) ||
> +		     !list_empty(&genpd->dev_list));
> +

Why not return an error here? Seems bad to remove it, if it could still
be referenced by other domains.

Also not sure if you need to lock around the above test and removing the
domain.

> +	mutex_lock(&gpd_list_lock);
> +	list_del(&genpd->gpd_list_node);
> +	mutex_unlock(&gpd_list_lock);
> +
> +	mutex_destroy(&genpd->lock);
> +}
> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
> +

BTW, I had just submitted a similar patch here [0]. So I would also like
to see such an API added.

Cheers
Jon

[0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-07 10:04     ` Jon Hunter
  0 siblings, 0 replies; 37+ messages in thread
From: Jon Hunter @ 2015-12-07 10:04 UTC (permalink / raw)
  To: linux-arm-kernel


On 04/12/15 17:45, Eric Anholt wrote:
> From: Alexander Aring <alex.aring@gmail.com>
> 
> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
> is useful for multiple power domains while probing. If the probing fails
> after one pm_genpd_init was called we need to undo all previous
> registrations of generic pm domains inside the gpd_list list.
> 
> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
> registered power domains and not registered domains, the driver can use
> this mechanism to have an array with registered and non-registered power
> domains, where non-registered power domains are NULL.
> 
> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
> Cc: Kevin Hilman <khilman@kernel.org>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Len Brown <len.brown@intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>  include/linux/pm_domain.h   |  4 ++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 167418e..e7aca27 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>  }
>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>  
> +/**
> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
> + * @genpd: PM domain object to uninitialize.
> + */
> +void pm_genpd_exit(struct generic_pm_domain *genpd)
> +{
> +	if (IS_ERR_OR_NULL(genpd))
> +		return;
> +
> +	/* check if domain is still in registered inside the pm subsystem */
> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
> +		     !list_empty(&genpd->slave_links) ||
> +		     !list_empty(&genpd->dev_list));
> +

Why not return an error here? Seems bad to remove it, if it could still
be referenced by other domains.

Also not sure if you need to lock around the above test and removing the
domain.

> +	mutex_lock(&gpd_list_lock);
> +	list_del(&genpd->gpd_list_node);
> +	mutex_unlock(&gpd_list_lock);
> +
> +	mutex_destroy(&genpd->lock);
> +}
> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
> +

BTW, I had just submitted a similar patch here [0]. So I would also like
to see such an API added.

Cheers
Jon

[0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* Re: [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
  2015-12-04 17:45   ` Eric Anholt
@ 2015-12-07 23:35     ` Kevin Hilman
  -1 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-07 23:35 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Rafael J. Wysocki, linux-arm-kernel, linux-rpi-kernel,
	linux-kernel, Stephen Warren, Lee Jones, Florian Fainelli,
	Ulf Hansson, Greg Kroah-Hartman, Alexander Aring, devicetree,
	linux-pm, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell

Eric Anholt <eric@anholt.net> writes:

> From: Alexander Aring <alex.aring@gmail.com>
>
> This patch adds support for several power domains on Raspberry Pi,
> including USB (so it can be enabled even if the bootloader didn't do
> it), and graphics.
>
> This patch is the combined work of Eric Anholt (who wrote USB support
> inside of the Raspberry Pi firmware driver, and wrote the non-USB
> domain support) and Alexander Aring (who separated the original USB
> work out from the firmware driver).
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>
> v2: Add support for power domains other than USB, using the new
>     firmware interface, reword commit message (changes by Eric)

[...]

> +/*
> + * Firmware indices for the old power domains interface.  Only a few
> + * of them were actually implemented.
> + */
> +#define RPI_OLD_POWER_DOMAIN_USB		3
> +#define RPI_OLD_POWER_DOMAIN_V3D		10
> +

Is "old" the right word here?  Are there firmware versions that could be
used instead?  What happens when the firwmware is updated next time?

[...]

> +	/*
> +	 * Use the old firmware interface for USB power, so that we
> +	 * can turn it on even if the firmware hasn't been updated.
> +	 */
> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");

This seems a bit restrictive.

To me, it seems that determining "old" or "new" (or revision of fw
interface to use) should be described in DT, not hard-coded in the power
domain driver.

What about an additional DT property to describe that? or possibly
another cell in the domain which could be used to optionally set
old/legacy.

Kevin

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

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-07 23:35     ` Kevin Hilman
  0 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-07 23:35 UTC (permalink / raw)
  To: linux-arm-kernel

Eric Anholt <eric@anholt.net> writes:

> From: Alexander Aring <alex.aring@gmail.com>
>
> This patch adds support for several power domains on Raspberry Pi,
> including USB (so it can be enabled even if the bootloader didn't do
> it), and graphics.
>
> This patch is the combined work of Eric Anholt (who wrote USB support
> inside of the Raspberry Pi firmware driver, and wrote the non-USB
> domain support) and Alexander Aring (who separated the original USB
> work out from the firmware driver).
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>
> v2: Add support for power domains other than USB, using the new
>     firmware interface, reword commit message (changes by Eric)

[...]

> +/*
> + * Firmware indices for the old power domains interface.  Only a few
> + * of them were actually implemented.
> + */
> +#define RPI_OLD_POWER_DOMAIN_USB		3
> +#define RPI_OLD_POWER_DOMAIN_V3D		10
> +

Is "old" the right word here?  Are there firmware versions that could be
used instead?  What happens when the firwmware is updated next time?

[...]

> +	/*
> +	 * Use the old firmware interface for USB power, so that we
> +	 * can turn it on even if the firmware hasn't been updated.
> +	 */
> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");

This seems a bit restrictive.

To me, it seems that determining "old" or "new" (or revision of fw
interface to use) should be described in DT, not hard-coded in the power
domain driver.

What about an additional DT property to describe that? or possibly
another cell in the domain which could be used to optionally set
old/legacy.

Kevin

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

* Re: [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
  2015-12-07 23:35     ` Kevin Hilman
@ 2015-12-08  1:04       ` Eric Anholt
  -1 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-08  1:04 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Rafael J. Wysocki, linux-arm-kernel, linux-rpi-kernel,
	linux-kernel, Stephen Warren, Lee Jones, Florian Fainelli,
	Ulf Hansson, Greg Kroah-Hartman, Alexander Aring, devicetree,
	linux-pm, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell

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

Kevin Hilman <khilman@kernel.org> writes:

> Eric Anholt <eric@anholt.net> writes:
>
>> From: Alexander Aring <alex.aring@gmail.com>
>>
>> This patch adds support for several power domains on Raspberry Pi,
>> including USB (so it can be enabled even if the bootloader didn't do
>> it), and graphics.
>>
>> This patch is the combined work of Eric Anholt (who wrote USB support
>> inside of the Raspberry Pi firmware driver, and wrote the non-USB
>> domain support) and Alexander Aring (who separated the original USB
>> work out from the firmware driver).
>>
>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> ---
>>
>> v2: Add support for power domains other than USB, using the new
>>     firmware interface, reword commit message (changes by Eric)
>
> [...]
>
>> +/*
>> + * Firmware indices for the old power domains interface.  Only a few
>> + * of them were actually implemented.
>> + */
>> +#define RPI_OLD_POWER_DOMAIN_USB		3
>> +#define RPI_OLD_POWER_DOMAIN_V3D		10
>> +
>
> Is "old" the right word here?  Are there firmware versions that could be
> used instead?  What happens when the firwmware is updated next time?

Old is a good word.  It's the old interface.

As for what happens when the firmware is updated: Nothing.  The firmware
is updated all the time, and it maintains backwards compatibility.
Unless you mean "what happens when a newer, fancier power domain
interface is created and we need a name for the newer one" and the
answer is "this is a define entirely within the driver, and we can just
rename it when we want to."

> [...]
>
>> +	/*
>> +	 * Use the old firmware interface for USB power, so that we
>> +	 * can turn it on even if the firmware hasn't been updated.
>> +	 */
>> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
>> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
>
> This seems a bit restrictive.
>
> To me, it seems that determining "old" or "new" (or revision of fw
> interface to use) should be described in DT, not hard-coded in the power
> domain driver.
>
> What about an additional DT property to describe that? or possibly
> another cell in the domain which could be used to optionally set
> old/legacy.

As the author and maintainer of the code, I don't feel it's restrictive.
The firmware protocol is defined and is guaranteed to continue to exist,
it's only useful for this platform, and defining a new set of custom
devicetree properties for it would only obfuscate the implementation.
DT is a useful tool for separating out the between-board differences for
the same piece of hardware across multiple implementations at different
addresses, while this is neither hardware nor in multiple
implementations at different addresses.

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

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

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-08  1:04       ` Eric Anholt
  0 siblings, 0 replies; 37+ messages in thread
From: Eric Anholt @ 2015-12-08  1:04 UTC (permalink / raw)
  To: linux-arm-kernel

Kevin Hilman <khilman@kernel.org> writes:

> Eric Anholt <eric@anholt.net> writes:
>
>> From: Alexander Aring <alex.aring@gmail.com>
>>
>> This patch adds support for several power domains on Raspberry Pi,
>> including USB (so it can be enabled even if the bootloader didn't do
>> it), and graphics.
>>
>> This patch is the combined work of Eric Anholt (who wrote USB support
>> inside of the Raspberry Pi firmware driver, and wrote the non-USB
>> domain support) and Alexander Aring (who separated the original USB
>> work out from the firmware driver).
>>
>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> ---
>>
>> v2: Add support for power domains other than USB, using the new
>>     firmware interface, reword commit message (changes by Eric)
>
> [...]
>
>> +/*
>> + * Firmware indices for the old power domains interface.  Only a few
>> + * of them were actually implemented.
>> + */
>> +#define RPI_OLD_POWER_DOMAIN_USB		3
>> +#define RPI_OLD_POWER_DOMAIN_V3D		10
>> +
>
> Is "old" the right word here?  Are there firmware versions that could be
> used instead?  What happens when the firwmware is updated next time?

Old is a good word.  It's the old interface.

As for what happens when the firmware is updated: Nothing.  The firmware
is updated all the time, and it maintains backwards compatibility.
Unless you mean "what happens when a newer, fancier power domain
interface is created and we need a name for the newer one" and the
answer is "this is a define entirely within the driver, and we can just
rename it when we want to."

> [...]
>
>> +	/*
>> +	 * Use the old firmware interface for USB power, so that we
>> +	 * can turn it on even if the firmware hasn't been updated.
>> +	 */
>> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
>> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
>
> This seems a bit restrictive.
>
> To me, it seems that determining "old" or "new" (or revision of fw
> interface to use) should be described in DT, not hard-coded in the power
> domain driver.
>
> What about an additional DT property to describe that? or possibly
> another cell in the domain which could be used to optionally set
> old/legacy.

As the author and maintainer of the code, I don't feel it's restrictive.
The firmware protocol is defined and is guaranteed to continue to exist,
it's only useful for this platform, and defining a new set of custom
devicetree properties for it would only obfuscate the implementation.
DT is a useful tool for separating out the between-board differences for
the same piece of hardware across multiple implementations at different
addresses, while this is neither hardware nor in multiple
implementations at different addresses.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151207/f1555bb1/attachment.sig>

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

* Re: [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
  2015-12-08  1:04       ` Eric Anholt
@ 2015-12-08 18:19         ` Kevin Hilman
  -1 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-08 18:19 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Rafael J. Wysocki, linux-arm-kernel, linux-rpi-kernel,
	linux-kernel, Stephen Warren, Lee Jones, Florian Fainelli,
	Ulf Hansson, Greg Kroah-Hartman, Alexander Aring, devicetree,
	linux-pm, Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell

Hi Eric,

Eric Anholt <eric@anholt.net> writes:

> Kevin Hilman <khilman@kernel.org> writes:
>
>> Eric Anholt <eric@anholt.net> writes:
>>
>>> From: Alexander Aring <alex.aring@gmail.com>
>>>
>>> This patch adds support for several power domains on Raspberry Pi,
>>> including USB (so it can be enabled even if the bootloader didn't do
>>> it), and graphics.
>>>
>>> This patch is the combined work of Eric Anholt (who wrote USB support
>>> inside of the Raspberry Pi firmware driver, and wrote the non-USB
>>> domain support) and Alexander Aring (who separated the original USB
>>> work out from the firmware driver).
>>>
>>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>>> Signed-off-by: Eric Anholt <eric@anholt.net>
>>> ---
>>>
>>> v2: Add support for power domains other than USB, using the new
>>>     firmware interface, reword commit message (changes by Eric)
>>
>> [...]
>>
>>> +/*
>>> + * Firmware indices for the old power domains interface.  Only a few
>>> + * of them were actually implemented.
>>> + */
>>> +#define RPI_OLD_POWER_DOMAIN_USB		3
>>> +#define RPI_OLD_POWER_DOMAIN_V3D		10
>>> +
>>
>> Is "old" the right word here?  Are there firmware versions that could be
>> used instead?  What happens when the firwmware is updated next time?
>
> Old is a good word.  It's the old interface.

Sure, but "old" is relative and based on experience, folks come to
regret those kinds of names.

> As for what happens when the firmware is updated: Nothing.  The firmware
> is updated all the time, and it maintains backwards compatibility.
> Unless you mean "what happens when a newer, fancier power domain
> interface is created and we need a name for the newer one" and the
> answer is "this is a define entirely within the driver, and we can just
> rename it when we want to."

Sure, it's very contained in this driver, so it's ultimately up to you.
It's not something worth blocking this about, I just wanted to be sure
since I'm not very familiar with how the rpi firmware evolves.

>> [...]
>>
>>> +	/*
>>> +	 * Use the old firmware interface for USB power, so that we
>>> +	 * can turn it on even if the firmware hasn't been updated.
>>> +	 */
>>> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
>>> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
>>
>> This seems a bit restrictive.
>>
>> To me, it seems that determining "old" or "new" (or revision of fw
>> interface to use) should be described in DT, not hard-coded in the power
>> domain driver.
>>
>> What about an additional DT property to describe that? or possibly
>> another cell in the domain which could be used to optionally set
>> old/legacy.
>
> As the author and maintainer of the code, I don't feel it's restrictive.
> The firmware protocol is defined and is guaranteed to continue to exist,
> it's only useful for this platform, and defining a new set of custom
> devicetree properties for it would only obfuscate the implementation.
> DT is a useful tool for separating out the between-board differences for
> the same piece of hardware across multiple implementations at different
> addresses, while this is neither hardware nor in multiple
> implementations at different addresses.

That being said, firmware revisions are also very often something that
qualifies as a difference between boards.

Anyways, as I said above, I think this is a potential future problem,
but it's not a big deal to me since it's very self contained.

Kevin

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

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-08 18:19         ` Kevin Hilman
  0 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-08 18:19 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Eric,

Eric Anholt <eric@anholt.net> writes:

> Kevin Hilman <khilman@kernel.org> writes:
>
>> Eric Anholt <eric@anholt.net> writes:
>>
>>> From: Alexander Aring <alex.aring@gmail.com>
>>>
>>> This patch adds support for several power domains on Raspberry Pi,
>>> including USB (so it can be enabled even if the bootloader didn't do
>>> it), and graphics.
>>>
>>> This patch is the combined work of Eric Anholt (who wrote USB support
>>> inside of the Raspberry Pi firmware driver, and wrote the non-USB
>>> domain support) and Alexander Aring (who separated the original USB
>>> work out from the firmware driver).
>>>
>>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>>> Signed-off-by: Eric Anholt <eric@anholt.net>
>>> ---
>>>
>>> v2: Add support for power domains other than USB, using the new
>>>     firmware interface, reword commit message (changes by Eric)
>>
>> [...]
>>
>>> +/*
>>> + * Firmware indices for the old power domains interface.  Only a few
>>> + * of them were actually implemented.
>>> + */
>>> +#define RPI_OLD_POWER_DOMAIN_USB		3
>>> +#define RPI_OLD_POWER_DOMAIN_V3D		10
>>> +
>>
>> Is "old" the right word here?  Are there firmware versions that could be
>> used instead?  What happens when the firwmware is updated next time?
>
> Old is a good word.  It's the old interface.

Sure, but "old" is relative and based on experience, folks come to
regret those kinds of names.

> As for what happens when the firmware is updated: Nothing.  The firmware
> is updated all the time, and it maintains backwards compatibility.
> Unless you mean "what happens when a newer, fancier power domain
> interface is created and we need a name for the newer one" and the
> answer is "this is a define entirely within the driver, and we can just
> rename it when we want to."

Sure, it's very contained in this driver, so it's ultimately up to you.
It's not something worth blocking this about, I just wanted to be sure
since I'm not very familiar with how the rpi firmware evolves.

>> [...]
>>
>>> +	/*
>>> +	 * Use the old firmware interface for USB power, so that we
>>> +	 * can turn it on even if the firmware hasn't been updated.
>>> +	 */
>>> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
>>> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
>>
>> This seems a bit restrictive.
>>
>> To me, it seems that determining "old" or "new" (or revision of fw
>> interface to use) should be described in DT, not hard-coded in the power
>> domain driver.
>>
>> What about an additional DT property to describe that? or possibly
>> another cell in the domain which could be used to optionally set
>> old/legacy.
>
> As the author and maintainer of the code, I don't feel it's restrictive.
> The firmware protocol is defined and is guaranteed to continue to exist,
> it's only useful for this platform, and defining a new set of custom
> devicetree properties for it would only obfuscate the implementation.
> DT is a useful tool for separating out the between-board differences for
> the same piece of hardware across multiple implementations at different
> addresses, while this is neither hardware nor in multiple
> implementations at different addresses.

That being said, firmware revisions are also very often something that
qualifies as a difference between boards.

Anyways, as I said above, I think this is a potential future problem,
but it's not a big deal to me since it's very self contained.

Kevin

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-07 10:04     ` Jon Hunter
  (?)
@ 2015-12-08 18:59       ` Kevin Hilman
  -1 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-08 18:59 UTC (permalink / raw)
  To: Jon Hunter
  Cc: Eric Anholt, Rafael J. Wysocki, Mark Rutland, devicetree,
	Ulf Hansson, Florian Fainelli, Alexander Aring, Pawel Moll,
	Stephen Warren, Greg Kroah-Hartman, linux-pm, Lee Jones,
	linux-kernel, Rob Herring, linux-rpi-kernel, Pavel Machek,
	Len Brown, Ian Campbell, linux-arm-kernel

Jon Hunter <jonathanh@nvidia.com> writes:

> On 04/12/15 17:45, Eric Anholt wrote:
>> From: Alexander Aring <alex.aring@gmail.com>
>> 
>> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
>> is useful for multiple power domains while probing. If the probing fails
>> after one pm_genpd_init was called we need to undo all previous
>> registrations of generic pm domains inside the gpd_list list.
>> 
>> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
>> registered power domains and not registered domains, the driver can use
>> this mechanism to have an array with registered and non-registered power
>> domains, where non-registered power domains are NULL.
>> 
>> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
>> Cc: Kevin Hilman <khilman@kernel.org>
>> Cc: Ulf Hansson <ulf.hansson@linaro.org>
>> Cc: Pavel Machek <pavel@ucw.cz>
>> Cc: Len Brown <len.brown@intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
>> ---
>>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>>  include/linux/pm_domain.h   |  4 ++++
>>  2 files changed, 26 insertions(+)
>> 
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index 167418e..e7aca27 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>>  }
>>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>>  
>> +/**
>> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
>> + * @genpd: PM domain object to uninitialize.
>> + */
>> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> +{
>> +	if (IS_ERR_OR_NULL(genpd))
>> +		return;
>> +
>> +	/* check if domain is still in registered inside the pm subsystem */
>> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> +		     !list_empty(&genpd->slave_links) ||
>> +		     !list_empty(&genpd->dev_list));
>> +
>
> Why not return an error here? Seems bad to remove it, if it could still
> be referenced by other domains.

I had pointed this out as well in an earlier review.

> Also not sure if you need to lock around the above test and removing the
> domain.
>
>> +	mutex_lock(&gpd_list_lock);
>> +	list_del(&genpd->gpd_list_node);
>> +	mutex_unlock(&gpd_list_lock);
>> +
>> +	mutex_destroy(&genpd->lock);
>> +}
>> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
>> +
>
> BTW, I had just submitted a similar patch here [0]. So I would also like
> to see such an API added.

Between the two of you, maybe come up with an agreed upon patch and
re-submit.

Kevin

> Cheers
> Jon
>
> [0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-08 18:59       ` Kevin Hilman
  0 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-08 18:59 UTC (permalink / raw)
  To: Jon Hunter
  Cc: Eric Anholt, Rafael J. Wysocki, Mark Rutland, devicetree,
	Ulf Hansson, Florian Fainelli, Alexander Aring, Pawel Moll,
	Stephen Warren, Greg Kroah-Hartman, linux-pm, Lee Jones,
	linux-kernel, Rob Herring, linux-rpi-kernel, Pavel Machek,
	Len Brown, Ian Campbell, linux-arm-kernel

Jon Hunter <jonathanh@nvidia.com> writes:

> On 04/12/15 17:45, Eric Anholt wrote:
>> From: Alexander Aring <alex.aring@gmail.com>
>> 
>> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
>> is useful for multiple power domains while probing. If the probing fails
>> after one pm_genpd_init was called we need to undo all previous
>> registrations of generic pm domains inside the gpd_list list.
>> 
>> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
>> registered power domains and not registered domains, the driver can use
>> this mechanism to have an array with registered and non-registered power
>> domains, where non-registered power domains are NULL.
>> 
>> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
>> Cc: Kevin Hilman <khilman@kernel.org>
>> Cc: Ulf Hansson <ulf.hansson@linaro.org>
>> Cc: Pavel Machek <pavel@ucw.cz>
>> Cc: Len Brown <len.brown@intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
>> ---
>>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>>  include/linux/pm_domain.h   |  4 ++++
>>  2 files changed, 26 insertions(+)
>> 
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index 167418e..e7aca27 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>>  }
>>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>>  
>> +/**
>> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
>> + * @genpd: PM domain object to uninitialize.
>> + */
>> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> +{
>> +	if (IS_ERR_OR_NULL(genpd))
>> +		return;
>> +
>> +	/* check if domain is still in registered inside the pm subsystem */
>> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> +		     !list_empty(&genpd->slave_links) ||
>> +		     !list_empty(&genpd->dev_list));
>> +
>
> Why not return an error here? Seems bad to remove it, if it could still
> be referenced by other domains.

I had pointed this out as well in an earlier review.

> Also not sure if you need to lock around the above test and removing the
> domain.
>
>> +	mutex_lock(&gpd_list_lock);
>> +	list_del(&genpd->gpd_list_node);
>> +	mutex_unlock(&gpd_list_lock);
>> +
>> +	mutex_destroy(&genpd->lock);
>> +}
>> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
>> +
>
> BTW, I had just submitted a similar patch here [0]. So I would also like
> to see such an API added.

Between the two of you, maybe come up with an agreed upon patch and
re-submit.

Kevin

> Cheers
> Jon
>
> [0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-08 18:59       ` Kevin Hilman
  0 siblings, 0 replies; 37+ messages in thread
From: Kevin Hilman @ 2015-12-08 18:59 UTC (permalink / raw)
  To: linux-arm-kernel

Jon Hunter <jonathanh@nvidia.com> writes:

> On 04/12/15 17:45, Eric Anholt wrote:
>> From: Alexander Aring <alex.aring@gmail.com>
>> 
>> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
>> is useful for multiple power domains while probing. If the probing fails
>> after one pm_genpd_init was called we need to undo all previous
>> registrations of generic pm domains inside the gpd_list list.
>> 
>> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
>> registered power domains and not registered domains, the driver can use
>> this mechanism to have an array with registered and non-registered power
>> domains, where non-registered power domains are NULL.
>> 
>> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
>> Cc: Kevin Hilman <khilman@kernel.org>
>> Cc: Ulf Hansson <ulf.hansson@linaro.org>
>> Cc: Pavel Machek <pavel@ucw.cz>
>> Cc: Len Brown <len.brown@intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
>> ---
>>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
>>  include/linux/pm_domain.h   |  4 ++++
>>  2 files changed, 26 insertions(+)
>> 
>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
>> index 167418e..e7aca27 100644
>> --- a/drivers/base/power/domain.c
>> +++ b/drivers/base/power/domain.c
>> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
>>  }
>>  EXPORT_SYMBOL_GPL(pm_genpd_init);
>>  
>> +/**
>> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
>> + * @genpd: PM domain object to uninitialize.
>> + */
>> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> +{
>> +	if (IS_ERR_OR_NULL(genpd))
>> +		return;
>> +
>> +	/* check if domain is still in registered inside the pm subsystem */
>> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> +		     !list_empty(&genpd->slave_links) ||
>> +		     !list_empty(&genpd->dev_list));
>> +
>
> Why not return an error here? Seems bad to remove it, if it could still
> be referenced by other domains.

I had pointed this out as well in an earlier review.

> Also not sure if you need to lock around the above test and removing the
> domain.
>
>> +	mutex_lock(&gpd_list_lock);
>> +	list_del(&genpd->gpd_list_node);
>> +	mutex_unlock(&gpd_list_lock);
>> +
>> +	mutex_destroy(&genpd->lock);
>> +}
>> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
>> +
>
> BTW, I had just submitted a similar patch here [0]. So I would also like
> to see such an API added.

Between the two of you, maybe come up with an agreed upon patch and
re-submit.

Kevin

> Cheers
> Jon
>
> [0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-08 18:59       ` Kevin Hilman
@ 2015-12-09 10:47         ` Alexander Aring
  -1 siblings, 0 replies; 37+ messages in thread
From: Alexander Aring @ 2015-12-09 10:47 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Jon Hunter, Eric Anholt, Rafael J. Wysocki, Mark Rutland,
	devicetree, Ulf Hansson, Florian Fainelli, Pawel Moll,
	Stephen Warren, Greg Kroah-Hartman, linux-pm, Lee Jones,
	linux-kernel, Rob Herring, linux-rpi-kernel, Pavel Machek,
	Len Brown, Ian Campbell, linux-arm-kernel

Hi,

On Tue, Dec 08, 2015 at 10:59:00AM -0800, Kevin Hilman wrote:
> Jon Hunter <jonathanh@nvidia.com> writes:
> 
> > On 04/12/15 17:45, Eric Anholt wrote:
> >> From: Alexander Aring <alex.aring@gmail.com>
> >> 
> >> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
> >> is useful for multiple power domains while probing. If the probing fails
> >> after one pm_genpd_init was called we need to undo all previous
> >> registrations of generic pm domains inside the gpd_list list.
> >> 
> >> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
> >> registered power domains and not registered domains, the driver can use
> >> this mechanism to have an array with registered and non-registered power
> >> domains, where non-registered power domains are NULL.
> >> 
> >> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
> >> Cc: Kevin Hilman <khilman@kernel.org>
> >> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> >> Cc: Pavel Machek <pavel@ucw.cz>
> >> Cc: Len Brown <len.brown@intel.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> >> Signed-off-by: Eric Anholt <eric@anholt.net>
> >> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> >> ---
> >>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
> >>  include/linux/pm_domain.h   |  4 ++++
> >>  2 files changed, 26 insertions(+)
> >> 
> >> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> >> index 167418e..e7aca27 100644
> >> --- a/drivers/base/power/domain.c
> >> +++ b/drivers/base/power/domain.c
> >> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
> >>  }
> >>  EXPORT_SYMBOL_GPL(pm_genpd_init);
> >>  
> >> +/**
> >> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
> >> + * @genpd: PM domain object to uninitialize.
> >> + */
> >> +void pm_genpd_exit(struct generic_pm_domain *genpd)
> >> +{
> >> +	if (IS_ERR_OR_NULL(genpd))
> >> +		return;
> >> +
> >> +	/* check if domain is still in registered inside the pm subsystem */
> >> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
> >> +		     !list_empty(&genpd->slave_links) ||
> >> +		     !list_empty(&genpd->dev_list));
> >> +
> >
> > Why not return an error here? Seems bad to remove it, if it could still
> > be referenced by other domains.
> 
> I had pointed this out as well in an earlier review.
> 

I talked with Ulf Hansson about such handling and there exists currently
no handling to remove the pm_genpd on error handling (what our use case
is for RPi domains).

The real solution would be a "pm_genpd_exit_recursive" functionality to
remove subdomains, etc -> simple everything. Anway I am not a expert into
power domain functionality and this simple approach was enough to him to
add "something" which we have actually a lack of support.


Now "returning an errno" here:

I don't know how it should be handled in an "error handling" case. The
WARN_ON_ONCE should say "somebody use this API wrong" which is a very
unlikely case.
These lists should be empty when calling pm_genpd_exit before in any case.


Example: the error case is while probing, how we react on a -EBUSY there
"in an error case" -> simple ignore it? But then nobody see that the use
of this function is wrong.

Should it be something like that?

err_probe:
	WARN_ON_ONCE(pm_genpd_exit(foo) < 0);

This function should be "void" here, I never saw some unregistration
functionality which returns some "int" for error handling. Which brings
us back to the "real" solution, a "pm_genpd_exit_recursive" functionality
which unregister everything which belongs to a "generic_pm_domain".

To have a "pm_genpd_exit" is only the first step. That we can improve error
handling for pm_genpd_init. (Which RPi power domains use and doesn't
register any subdomains, etc. for probing).

> > Also not sure if you need to lock around the above test and removing the
> > domain.
> >
> >> +	mutex_lock(&gpd_list_lock);
> >> +	list_del(&genpd->gpd_list_node);
> >> +	mutex_unlock(&gpd_list_lock);
> >> +
> >> +	mutex_destroy(&genpd->lock);
> >> +}
> >> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
> >> +
> >
> > BTW, I had just submitted a similar patch here [0]. So I would also like
> > to see such an API added.
> 

:-)

> Between the two of you, maybe come up with an agreed upon patch and
> re-submit.
> 
> Kevin
> 
> > Cheers
> > Jon
> >
> > [0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-09 10:47         ` Alexander Aring
  0 siblings, 0 replies; 37+ messages in thread
From: Alexander Aring @ 2015-12-09 10:47 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Tue, Dec 08, 2015 at 10:59:00AM -0800, Kevin Hilman wrote:
> Jon Hunter <jonathanh@nvidia.com> writes:
> 
> > On 04/12/15 17:45, Eric Anholt wrote:
> >> From: Alexander Aring <alex.aring@gmail.com>
> >> 
> >> This patch adds function pm_genpd_exit for undo a pm_genpd_init. This
> >> is useful for multiple power domains while probing. If the probing fails
> >> after one pm_genpd_init was called we need to undo all previous
> >> registrations of generic pm domains inside the gpd_list list.
> >> 
> >> There is a check on IS_ERR_OR_NULL(genpd) which is useful to check again
> >> registered power domains and not registered domains, the driver can use
> >> this mechanism to have an array with registered and non-registered power
> >> domains, where non-registered power domains are NULL.
> >> 
> >> Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
> >> Cc: Kevin Hilman <khilman@kernel.org>
> >> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> >> Cc: Pavel Machek <pavel@ucw.cz>
> >> Cc: Len Brown <len.brown@intel.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> >> Signed-off-by: Eric Anholt <eric@anholt.net>
> >> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
> >> ---
> >>  drivers/base/power/domain.c | 22 ++++++++++++++++++++++
> >>  include/linux/pm_domain.h   |  4 ++++
> >>  2 files changed, 26 insertions(+)
> >> 
> >> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> >> index 167418e..e7aca27 100644
> >> --- a/drivers/base/power/domain.c
> >> +++ b/drivers/base/power/domain.c
> >> @@ -1509,6 +1509,28 @@ void pm_genpd_init(struct generic_pm_domain *genpd,
> >>  }
> >>  EXPORT_SYMBOL_GPL(pm_genpd_init);
> >>  
> >> +/**
> >> + * pm_genpd_exit - Uninitialize a generic I/O PM domain object.
> >> + * @genpd: PM domain object to uninitialize.
> >> + */
> >> +void pm_genpd_exit(struct generic_pm_domain *genpd)
> >> +{
> >> +	if (IS_ERR_OR_NULL(genpd))
> >> +		return;
> >> +
> >> +	/* check if domain is still in registered inside the pm subsystem */
> >> +	WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
> >> +		     !list_empty(&genpd->slave_links) ||
> >> +		     !list_empty(&genpd->dev_list));
> >> +
> >
> > Why not return an error here? Seems bad to remove it, if it could still
> > be referenced by other domains.
> 
> I had pointed this out as well in an earlier review.
> 

I talked with Ulf Hansson about such handling and there exists currently
no handling to remove the pm_genpd on error handling (what our use case
is for RPi domains).

The real solution would be a "pm_genpd_exit_recursive" functionality to
remove subdomains, etc -> simple everything. Anway I am not a expert into
power domain functionality and this simple approach was enough to him to
add "something" which we have actually a lack of support.


Now "returning an errno" here:

I don't know how it should be handled in an "error handling" case. The
WARN_ON_ONCE should say "somebody use this API wrong" which is a very
unlikely case.
These lists should be empty when calling pm_genpd_exit before in any case.


Example: the error case is while probing, how we react on a -EBUSY there
"in an error case" -> simple ignore it? But then nobody see that the use
of this function is wrong.

Should it be something like that?

err_probe:
	WARN_ON_ONCE(pm_genpd_exit(foo) < 0);

This function should be "void" here, I never saw some unregistration
functionality which returns some "int" for error handling. Which brings
us back to the "real" solution, a "pm_genpd_exit_recursive" functionality
which unregister everything which belongs to a "generic_pm_domain".

To have a "pm_genpd_exit" is only the first step. That we can improve error
handling for pm_genpd_init. (Which RPi power domains use and doesn't
register any subdomains, etc. for probing).

> > Also not sure if you need to lock around the above test and removing the
> > domain.
> >
> >> +	mutex_lock(&gpd_list_lock);
> >> +	list_del(&genpd->gpd_list_node);
> >> +	mutex_unlock(&gpd_list_lock);
> >> +
> >> +	mutex_destroy(&genpd->lock);
> >> +}
> >> +EXPORT_SYMBOL_GPL(pm_genpd_exit);
> >> +
> >
> > BTW, I had just submitted a similar patch here [0]. So I would also like
> > to see such an API added.
> 

:-)

> Between the two of you, maybe come up with an agreed upon patch and
> re-submit.
> 
> Kevin
> 
> > Cheers
> > Jon
> >
> > [0] http://marc.info/?l=devicetree&m=144924138932726&w=2

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-09 10:47         ` Alexander Aring
@ 2015-12-09 10:54           ` Russell King - ARM Linux
  -1 siblings, 0 replies; 37+ messages in thread
From: Russell King - ARM Linux @ 2015-12-09 10:54 UTC (permalink / raw)
  To: Alexander Aring
  Cc: Kevin Hilman, Mark Rutland, devicetree, Ulf Hansson,
	Florian Fainelli, Pawel Moll, Stephen Warren, Greg Kroah-Hartman,
	linux-pm, Rafael J. Wysocki, linux-kernel, Jon Hunter,
	Eric Anholt, Rob Herring, Lee Jones, Pavel Machek, Len Brown,
	Ian Campbell, linux-arm-kernel, linux-rpi-kernel

On Wed, Dec 09, 2015 at 11:47:58AM +0100, Alexander Aring wrote:
> Example: the error case is while probing, how we react on a -EBUSY there
> "in an error case" -> simple ignore it? But then nobody see that the use
> of this function is wrong.

The proper way to deal with functionality that can only be registered
but never removed is to report the error, but never fail during probing,
and never allow removal (empty removal function.)

If you return a failure code during probe, you end up in an inconsistent
situation where you have facilities registered, but resources that those
facilities require will be undone when probe() returns a failure, and
that can potentially lead to kernel oops or scribbling over someone
elses device or memory.

-- 
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-09 10:54           ` Russell King - ARM Linux
  0 siblings, 0 replies; 37+ messages in thread
From: Russell King - ARM Linux @ 2015-12-09 10:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Dec 09, 2015 at 11:47:58AM +0100, Alexander Aring wrote:
> Example: the error case is while probing, how we react on a -EBUSY there
> "in an error case" -> simple ignore it? But then nobody see that the use
> of this function is wrong.

The proper way to deal with functionality that can only be registered
but never removed is to report the error, but never fail during probing,
and never allow removal (empty removal function.)

If you return a failure code during probe, you end up in an inconsistent
situation where you have facilities registered, but resources that those
facilities require will be undone when probe() returns a failure, and
that can potentially lead to kernel oops or scribbling over someone
elses device or memory.

-- 
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* Re: [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-11 18:13     ` Stefan Wahren
  0 siblings, 0 replies; 37+ messages in thread
From: Stefan Wahren @ 2015-12-11 18:13 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Rafael J. Wysocki, Mark Rutland, devicetree, Ulf Hansson,
	Florian Fainelli, Pawel Moll, Greg Kroah-Hartman, linux-pm,
	linux-kernel, Rob Herring, linux-rpi-kernel, Ian Campbell,
	linux-arm-kernel

Hi Eric,

Am 04.12.2015 um 18:45 schrieb Eric Anholt:
> From: Alexander Aring <alex.aring@gmail.com>
>
> This patch adds support for several power domains on Raspberry Pi,
> including USB (so it can be enabled even if the bootloader didn't do
> it), and graphics.
>
> This patch is the combined work of Eric Anholt (who wrote USB support
> inside of the Raspberry Pi firmware driver, and wrote the non-USB
> domain support) and Alexander Aring (who separated the original USB
> work out from the firmware driver).
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>
> v2: Add support for power domains other than USB, using the new
>      firmware interface, reword commit message (changes by Eric)
>
>   arch/arm/mach-bcm/Kconfig                   |  10 ++
>   arch/arm/mach-bcm/Makefile                  |   1 +
>   arch/arm/mach-bcm/raspberrypi-power.c       | 269 ++++++++++++++++++++++++++++
>   include/dt-bindings/arm/raspberrypi-power.h |  41 +++++
>   4 files changed, 321 insertions(+)
>   create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
>   create mode 100644 include/dt-bindings/arm/raspberrypi-power.h
>
> diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
> index 8c53c55..0f23bad 100644
> --- a/arch/arm/mach-bcm/Kconfig
> +++ b/arch/arm/mach-bcm/Kconfig
> @@ -134,6 +134,16 @@ config ARCH_BCM2835
>   	  This enables support for the Broadcom BCM2835 SoC. This SoC is
>   	  used in the Raspberry Pi and Roku 2 devices.
>
> +config RASPBERRYPI_POWER
> +	bool "Raspberry Pi power domain driver"
> +	depends on ARCH_BCM2835 || COMPILE_TEST
> +	depends on RASPBERRYPI_FIRMWARE
> +	select PM_GENERIC_DOMAINS if PM
> +	select PM_GENERIC_DOMAINS_OF if PM
> +	help
> +	  This enables support for the RPi power domains which can be enabled
> +	  or disabled via the RPi firmware.
> +
>   config ARCH_BCM_63XX
>   	bool "Broadcom BCM63xx DSL SoC" if ARCH_MULTI_V7
>   	depends on MMU
> diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
> index 892261f..fec2d6b 100644
> --- a/arch/arm/mach-bcm/Makefile
> +++ b/arch/arm/mach-bcm/Makefile
> @@ -36,6 +36,7 @@ endif
>
>   # BCM2835
>   obj-$(CONFIG_ARCH_BCM2835)	+= board_bcm2835.o
> +obj-$(CONFIG_RASPBERRYPI_POWER)	+= raspberrypi-power.o
>
>   # BCM5301X
>   obj-$(CONFIG_ARCH_BCM_5301X)	+= bcm_5301x.o
> diff --git a/arch/arm/mach-bcm/raspberrypi-power.c b/arch/arm/mach-bcm/raspberrypi-power.c
> new file mode 100644
> index 0000000..3444301
> --- /dev/null
> +++ b/arch/arm/mach-bcm/raspberrypi-power.c
> @@ -0,0 +1,269 @@
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Authors:
> + * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
> + * Eric Anholt <eric@anholt.net>

shouldn't be the copyright before license?

> + */
> + [...]
> +
> +static int rpi_power_probe(struct platform_device *pdev)
> +{
> +	struct device_node *fw_np;
> +	struct device *dev = &pdev->dev;
> +	struct rpi_power_domains *rpi_domains;
> +	int ret, i;
> +
> +	rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL);
> +	if (!rpi_domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.domains =
> +		devm_kzalloc(dev, sizeof(*rpi_domains->xlate.domains) *
> +			     RPI_POWER_DOMAIN_COUNT, GFP_KERNEL);
> +	if (!rpi_domains->xlate.domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.num_domains = RPI_POWER_DOMAIN_COUNT;
> +
> +	fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
> +	if (!fw_np) {
> +		dev_err(&pdev->dev, "no firmware node\n");
> +		return -ENODEV;
> +	}
> +
> +	rpi_domains->fw = rpi_firmware_get(fw_np);
> +	of_node_put(fw_np);
> +	if (!rpi_domains->fw)
> +		return -EPROBE_DEFER;
> +
> +	rpi_domains->has_new_interface =
> +		rpi_has_new_domain_support(rpi_domains);
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C0, "I2C0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C1, "I2C1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C2, "I2C2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VIDEO_SCALER,
> +			      "VIDEO_SCALER");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VPU1, "VPU1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_HDMI, "HDMI");
> +
> +	/*
> +	 * Use the old firmware interface for USB power, so that we
> +	 * can turn it on even if the firmware hasn't been updated.
> +	 */
> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VEC, "VEC");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_JPEG, "JPEG");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_H264, "H264");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_V3D, "V3D");

After this line i would expect the following:

rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ISP, "ISP");

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM0, "UNICAM0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM1, "UNICAM1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2RX, "CCP2RX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CSI2, "CSI2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CPI, "CPI");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI0, "DSI0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI1, "DSI1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_TRANSPOSER,
> +			      "TRANPOSER");

s/TRANPOSER/TRANSPOSER ?

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2TX, "CCP2TX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
> +
> +	ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
> +	if (ret < 0)
> +		goto exit_pm;
> +
> +	platform_set_drvdata(pdev, rpi_domains);
> +
> +	return 0;
> +
> +exit_pm:
> +	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
> +		pm_genpd_exit(rpi_domains->xlate.domains[i]);
> +
> +	return ret;
> +}
> +

Best regards
Stefan


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

* Re: [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-11 18:13     ` Stefan Wahren
  0 siblings, 0 replies; 37+ messages in thread
From: Stefan Wahren @ 2015-12-11 18:13 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Rafael J. Wysocki, Mark Rutland,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Ulf Hansson, Florian Fainelli,
	Pawel Moll, Greg Kroah-Hartman, linux-pm-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Rob Herring,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Ian Campbell,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi Eric,

Am 04.12.2015 um 18:45 schrieb Eric Anholt:
> From: Alexander Aring <alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>
> This patch adds support for several power domains on Raspberry Pi,
> including USB (so it can be enabled even if the bootloader didn't do
> it), and graphics.
>
> This patch is the combined work of Eric Anholt (who wrote USB support
> inside of the Raspberry Pi firmware driver, and wrote the non-USB
> domain support) and Alexander Aring (who separated the original USB
> work out from the firmware driver).
>
> Signed-off-by: Alexander Aring <alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
> ---
>
> v2: Add support for power domains other than USB, using the new
>      firmware interface, reword commit message (changes by Eric)
>
>   arch/arm/mach-bcm/Kconfig                   |  10 ++
>   arch/arm/mach-bcm/Makefile                  |   1 +
>   arch/arm/mach-bcm/raspberrypi-power.c       | 269 ++++++++++++++++++++++++++++
>   include/dt-bindings/arm/raspberrypi-power.h |  41 +++++
>   4 files changed, 321 insertions(+)
>   create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
>   create mode 100644 include/dt-bindings/arm/raspberrypi-power.h
>
> diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
> index 8c53c55..0f23bad 100644
> --- a/arch/arm/mach-bcm/Kconfig
> +++ b/arch/arm/mach-bcm/Kconfig
> @@ -134,6 +134,16 @@ config ARCH_BCM2835
>   	  This enables support for the Broadcom BCM2835 SoC. This SoC is
>   	  used in the Raspberry Pi and Roku 2 devices.
>
> +config RASPBERRYPI_POWER
> +	bool "Raspberry Pi power domain driver"
> +	depends on ARCH_BCM2835 || COMPILE_TEST
> +	depends on RASPBERRYPI_FIRMWARE
> +	select PM_GENERIC_DOMAINS if PM
> +	select PM_GENERIC_DOMAINS_OF if PM
> +	help
> +	  This enables support for the RPi power domains which can be enabled
> +	  or disabled via the RPi firmware.
> +
>   config ARCH_BCM_63XX
>   	bool "Broadcom BCM63xx DSL SoC" if ARCH_MULTI_V7
>   	depends on MMU
> diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
> index 892261f..fec2d6b 100644
> --- a/arch/arm/mach-bcm/Makefile
> +++ b/arch/arm/mach-bcm/Makefile
> @@ -36,6 +36,7 @@ endif
>
>   # BCM2835
>   obj-$(CONFIG_ARCH_BCM2835)	+= board_bcm2835.o
> +obj-$(CONFIG_RASPBERRYPI_POWER)	+= raspberrypi-power.o
>
>   # BCM5301X
>   obj-$(CONFIG_ARCH_BCM_5301X)	+= bcm_5301x.o
> diff --git a/arch/arm/mach-bcm/raspberrypi-power.c b/arch/arm/mach-bcm/raspberrypi-power.c
> new file mode 100644
> index 0000000..3444301
> --- /dev/null
> +++ b/arch/arm/mach-bcm/raspberrypi-power.c
> @@ -0,0 +1,269 @@
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Authors:
> + * (C) 2015 Pengutronix, Alexander Aring <aar-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> + * Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>

shouldn't be the copyright before license?

> + */
> + [...]
> +
> +static int rpi_power_probe(struct platform_device *pdev)
> +{
> +	struct device_node *fw_np;
> +	struct device *dev = &pdev->dev;
> +	struct rpi_power_domains *rpi_domains;
> +	int ret, i;
> +
> +	rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL);
> +	if (!rpi_domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.domains =
> +		devm_kzalloc(dev, sizeof(*rpi_domains->xlate.domains) *
> +			     RPI_POWER_DOMAIN_COUNT, GFP_KERNEL);
> +	if (!rpi_domains->xlate.domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.num_domains = RPI_POWER_DOMAIN_COUNT;
> +
> +	fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
> +	if (!fw_np) {
> +		dev_err(&pdev->dev, "no firmware node\n");
> +		return -ENODEV;
> +	}
> +
> +	rpi_domains->fw = rpi_firmware_get(fw_np);
> +	of_node_put(fw_np);
> +	if (!rpi_domains->fw)
> +		return -EPROBE_DEFER;
> +
> +	rpi_domains->has_new_interface =
> +		rpi_has_new_domain_support(rpi_domains);
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C0, "I2C0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C1, "I2C1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C2, "I2C2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VIDEO_SCALER,
> +			      "VIDEO_SCALER");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VPU1, "VPU1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_HDMI, "HDMI");
> +
> +	/*
> +	 * Use the old firmware interface for USB power, so that we
> +	 * can turn it on even if the firmware hasn't been updated.
> +	 */
> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VEC, "VEC");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_JPEG, "JPEG");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_H264, "H264");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_V3D, "V3D");

After this line i would expect the following:

rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ISP, "ISP");

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM0, "UNICAM0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM1, "UNICAM1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2RX, "CCP2RX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CSI2, "CSI2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CPI, "CPI");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI0, "DSI0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI1, "DSI1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_TRANSPOSER,
> +			      "TRANPOSER");

s/TRANPOSER/TRANSPOSER ?

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2TX, "CCP2TX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
> +
> +	ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
> +	if (ret < 0)
> +		goto exit_pm;
> +
> +	platform_set_drvdata(pdev, rpi_domains);
> +
> +	return 0;
> +
> +exit_pm:
> +	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
> +		pm_genpd_exit(rpi_domains->xlate.domains[i]);
> +
> +	return ret;
> +}
> +

Best regards
Stefan

--
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] 37+ messages in thread

* [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver
@ 2015-12-11 18:13     ` Stefan Wahren
  0 siblings, 0 replies; 37+ messages in thread
From: Stefan Wahren @ 2015-12-11 18:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Eric,

Am 04.12.2015 um 18:45 schrieb Eric Anholt:
> From: Alexander Aring <alex.aring@gmail.com>
>
> This patch adds support for several power domains on Raspberry Pi,
> including USB (so it can be enabled even if the bootloader didn't do
> it), and graphics.
>
> This patch is the combined work of Eric Anholt (who wrote USB support
> inside of the Raspberry Pi firmware driver, and wrote the non-USB
> domain support) and Alexander Aring (who separated the original USB
> work out from the firmware driver).
>
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>
> v2: Add support for power domains other than USB, using the new
>      firmware interface, reword commit message (changes by Eric)
>
>   arch/arm/mach-bcm/Kconfig                   |  10 ++
>   arch/arm/mach-bcm/Makefile                  |   1 +
>   arch/arm/mach-bcm/raspberrypi-power.c       | 269 ++++++++++++++++++++++++++++
>   include/dt-bindings/arm/raspberrypi-power.h |  41 +++++
>   4 files changed, 321 insertions(+)
>   create mode 100644 arch/arm/mach-bcm/raspberrypi-power.c
>   create mode 100644 include/dt-bindings/arm/raspberrypi-power.h
>
> diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
> index 8c53c55..0f23bad 100644
> --- a/arch/arm/mach-bcm/Kconfig
> +++ b/arch/arm/mach-bcm/Kconfig
> @@ -134,6 +134,16 @@ config ARCH_BCM2835
>   	  This enables support for the Broadcom BCM2835 SoC. This SoC is
>   	  used in the Raspberry Pi and Roku 2 devices.
>
> +config RASPBERRYPI_POWER
> +	bool "Raspberry Pi power domain driver"
> +	depends on ARCH_BCM2835 || COMPILE_TEST
> +	depends on RASPBERRYPI_FIRMWARE
> +	select PM_GENERIC_DOMAINS if PM
> +	select PM_GENERIC_DOMAINS_OF if PM
> +	help
> +	  This enables support for the RPi power domains which can be enabled
> +	  or disabled via the RPi firmware.
> +
>   config ARCH_BCM_63XX
>   	bool "Broadcom BCM63xx DSL SoC" if ARCH_MULTI_V7
>   	depends on MMU
> diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
> index 892261f..fec2d6b 100644
> --- a/arch/arm/mach-bcm/Makefile
> +++ b/arch/arm/mach-bcm/Makefile
> @@ -36,6 +36,7 @@ endif
>
>   # BCM2835
>   obj-$(CONFIG_ARCH_BCM2835)	+= board_bcm2835.o
> +obj-$(CONFIG_RASPBERRYPI_POWER)	+= raspberrypi-power.o
>
>   # BCM5301X
>   obj-$(CONFIG_ARCH_BCM_5301X)	+= bcm_5301x.o
> diff --git a/arch/arm/mach-bcm/raspberrypi-power.c b/arch/arm/mach-bcm/raspberrypi-power.c
> new file mode 100644
> index 0000000..3444301
> --- /dev/null
> +++ b/arch/arm/mach-bcm/raspberrypi-power.c
> @@ -0,0 +1,269 @@
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Authors:
> + * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
> + * Eric Anholt <eric@anholt.net>

shouldn't be the copyright before license?

> + */
> + [...]
> +
> +static int rpi_power_probe(struct platform_device *pdev)
> +{
> +	struct device_node *fw_np;
> +	struct device *dev = &pdev->dev;
> +	struct rpi_power_domains *rpi_domains;
> +	int ret, i;
> +
> +	rpi_domains = devm_kzalloc(dev, sizeof(*rpi_domains), GFP_KERNEL);
> +	if (!rpi_domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.domains =
> +		devm_kzalloc(dev, sizeof(*rpi_domains->xlate.domains) *
> +			     RPI_POWER_DOMAIN_COUNT, GFP_KERNEL);
> +	if (!rpi_domains->xlate.domains)
> +		return -ENOMEM;
> +
> +	rpi_domains->xlate.num_domains = RPI_POWER_DOMAIN_COUNT;
> +
> +	fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
> +	if (!fw_np) {
> +		dev_err(&pdev->dev, "no firmware node\n");
> +		return -ENODEV;
> +	}
> +
> +	rpi_domains->fw = rpi_firmware_get(fw_np);
> +	of_node_put(fw_np);
> +	if (!rpi_domains->fw)
> +		return -EPROBE_DEFER;
> +
> +	rpi_domains->has_new_interface =
> +		rpi_has_new_domain_support(rpi_domains);
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C0, "I2C0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C1, "I2C1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_I2C2, "I2C2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VIDEO_SCALER,
> +			      "VIDEO_SCALER");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VPU1, "VPU1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_HDMI, "HDMI");
> +
> +	/*
> +	 * Use the old firmware interface for USB power, so that we
> +	 * can turn it on even if the firmware hasn't been updated.
> +	 */
> +	rpi_init_old_power_domain(rpi_domains, RPI_POWER_DOMAIN_USB,
> +				  RPI_OLD_POWER_DOMAIN_USB, "USB");
> +
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_VEC, "VEC");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_JPEG, "JPEG");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_H264, "H264");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_V3D, "V3D");

After this line i would expect the following:

rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ISP, "ISP");

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM0, "UNICAM0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_UNICAM1, "UNICAM1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2RX, "CCP2RX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CSI2, "CSI2");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CPI, "CPI");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI0, "DSI0");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_DSI1, "DSI1");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_TRANSPOSER,
> +			      "TRANPOSER");

s/TRANPOSER/TRANSPOSER ?

> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CCP2TX, "CCP2TX");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
> +	rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
> +
> +	ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
> +	if (ret < 0)
> +		goto exit_pm;
> +
> +	platform_set_drvdata(pdev, rpi_domains);
> +
> +	return 0;
> +
> +exit_pm:
> +	for (i = 0; i < rpi_domains->xlate.num_domains; i++)
> +		pm_genpd_exit(rpi_domains->xlate.domains[i]);
> +
> +	return ret;
> +}
> +

Best regards
Stefan

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
  2015-12-09 10:47         ` Alexander Aring
  (?)
@ 2015-12-14  9:49           ` Ulf Hansson
  -1 siblings, 0 replies; 37+ messages in thread
From: Ulf Hansson @ 2015-12-14  9:49 UTC (permalink / raw)
  To: Alexander Aring, Eric Anholt, Jon Hunter
  Cc: Kevin Hilman, Rafael J. Wysocki, Mark Rutland,
	devicetree@vger.kernel.org, Florian Fainelli, Pawel Moll,
	Stephen Warren, Greg Kroah-Hartman, linux-pm@vger.kernel.org,
	Lee Jones, linux-kernel@vger.kernel.org, Rob Herring,
	linux-rpi-kernel, Pavel Machek, Len Brown, Ian Campbell,
	linux-arm-kernel@lists.infradead.org, Russell King - ARM Linux

+Russell

[...]

>> >> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> >> +{
>> >> +  if (IS_ERR_OR_NULL(genpd))
>> >> +          return;
>> >> +
>> >> +  /* check if domain is still in registered inside the pm subsystem */
>> >> +  WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> >> +               !list_empty(&genpd->slave_links) ||
>> >> +               !list_empty(&genpd->dev_list));
>> >> +
>> >
>> > Why not return an error here? Seems bad to remove it, if it could still
>> > be referenced by other domains.
>>
>> I had pointed this out as well in an earlier review.
>>
>
> I talked with Ulf Hansson about such handling and there exists currently
> no handling to remove the pm_genpd on error handling (what our use case
> is for RPi domains).
>
> The real solution would be a "pm_genpd_exit_recursive" functionality to
> remove subdomains, etc -> simple everything. Anway I am not a expert into
> power domain functionality and this simple approach was enough to him to
> add "something" which we have actually a lack of support.
>
>

[...]

Just to be clear on my view. I think Russell made a good summary of
how we should implement this API [1].
We should return an error, instead of WARN_ON_ONCE and continue.

Perhaps you can do both a WARN *and* return an error.

Regarding the similar patch from Jon Hunter, I would suggest we focus
on Alexander's $subject patch and try to it queued for 4.5. Please
send a new version.

Also, as other SoC genpd driver isn't using a "pm_genpd_exit()" API,
it shouldn't prevent neither Alexander/Eric or Jon from proceeding
with the RPI/Tegra genpd drivers. Once the new API is in place you can
update these drivers to properly deal with error handling and undo
things from pm_genpd_init().

Kind regards
Uffe

[1]
https://lkml.org/lkml/2015/12/9/308

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

* Re: [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-14  9:49           ` Ulf Hansson
  0 siblings, 0 replies; 37+ messages in thread
From: Ulf Hansson @ 2015-12-14  9:49 UTC (permalink / raw)
  To: Alexander Aring, Eric Anholt, Jon Hunter
  Cc: Kevin Hilman, Rafael J. Wysocki, Mark Rutland,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Florian Fainelli, Pawel Moll, Stephen Warren, Greg Kroah-Hartman,
	linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Lee Jones,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Rob Herring,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Pavel Machek,
	Len Brown, Ian Campbell,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Russell King - ARM Linux

+Russell

[...]

>> >> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> >> +{
>> >> +  if (IS_ERR_OR_NULL(genpd))
>> >> +          return;
>> >> +
>> >> +  /* check if domain is still in registered inside the pm subsystem */
>> >> +  WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> >> +               !list_empty(&genpd->slave_links) ||
>> >> +               !list_empty(&genpd->dev_list));
>> >> +
>> >
>> > Why not return an error here? Seems bad to remove it, if it could still
>> > be referenced by other domains.
>>
>> I had pointed this out as well in an earlier review.
>>
>
> I talked with Ulf Hansson about such handling and there exists currently
> no handling to remove the pm_genpd on error handling (what our use case
> is for RPi domains).
>
> The real solution would be a "pm_genpd_exit_recursive" functionality to
> remove subdomains, etc -> simple everything. Anway I am not a expert into
> power domain functionality and this simple approach was enough to him to
> add "something" which we have actually a lack of support.
>
>

[...]

Just to be clear on my view. I think Russell made a good summary of
how we should implement this API [1].
We should return an error, instead of WARN_ON_ONCE and continue.

Perhaps you can do both a WARN *and* return an error.

Regarding the similar patch from Jon Hunter, I would suggest we focus
on Alexander's $subject patch and try to it queued for 4.5. Please
send a new version.

Also, as other SoC genpd driver isn't using a "pm_genpd_exit()" API,
it shouldn't prevent neither Alexander/Eric or Jon from proceeding
with the RPI/Tegra genpd drivers. Once the new API is in place you can
update these drivers to properly deal with error handling and undo
things from pm_genpd_init().

Kind regards
Uffe

[1]
https://lkml.org/lkml/2015/12/9/308
--
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] 37+ messages in thread

* [PATCH v2 1/5] power: domain: add pm_genpd_exit
@ 2015-12-14  9:49           ` Ulf Hansson
  0 siblings, 0 replies; 37+ messages in thread
From: Ulf Hansson @ 2015-12-14  9:49 UTC (permalink / raw)
  To: linux-arm-kernel

+Russell

[...]

>> >> +void pm_genpd_exit(struct generic_pm_domain *genpd)
>> >> +{
>> >> +  if (IS_ERR_OR_NULL(genpd))
>> >> +          return;
>> >> +
>> >> +  /* check if domain is still in registered inside the pm subsystem */
>> >> +  WARN_ON_ONCE(!list_empty(&genpd->master_links) ||
>> >> +               !list_empty(&genpd->slave_links) ||
>> >> +               !list_empty(&genpd->dev_list));
>> >> +
>> >
>> > Why not return an error here? Seems bad to remove it, if it could still
>> > be referenced by other domains.
>>
>> I had pointed this out as well in an earlier review.
>>
>
> I talked with Ulf Hansson about such handling and there exists currently
> no handling to remove the pm_genpd on error handling (what our use case
> is for RPi domains).
>
> The real solution would be a "pm_genpd_exit_recursive" functionality to
> remove subdomains, etc -> simple everything. Anway I am not a expert into
> power domain functionality and this simple approach was enough to him to
> add "something" which we have actually a lack of support.
>
>

[...]

Just to be clear on my view. I think Russell made a good summary of
how we should implement this API [1].
We should return an error, instead of WARN_ON_ONCE and continue.

Perhaps you can do both a WARN *and* return an error.

Regarding the similar patch from Jon Hunter, I would suggest we focus
on Alexander's $subject patch and try to it queued for 4.5. Please
send a new version.

Also, as other SoC genpd driver isn't using a "pm_genpd_exit()" API,
it shouldn't prevent neither Alexander/Eric or Jon from proceeding
with the RPI/Tegra genpd drivers. Once the new API is in place you can
update these drivers to properly deal with error handling and undo
things from pm_genpd_init().

Kind regards
Uffe

[1]
https://lkml.org/lkml/2015/12/9/308

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

end of thread, other threads:[~2015-12-14  9:49 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 17:45 [PATCH v2 0/5] Raspberry Pi power domains v2 Eric Anholt
2015-12-04 17:45 ` Eric Anholt
2015-12-04 17:45 ` Eric Anholt
2015-12-04 17:45 ` [PATCH v2 1/5] power: domain: add pm_genpd_exit Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-07 10:04   ` Jon Hunter
2015-12-07 10:04     ` Jon Hunter
2015-12-07 10:04     ` Jon Hunter
2015-12-08 18:59     ` Kevin Hilman
2015-12-08 18:59       ` Kevin Hilman
2015-12-08 18:59       ` Kevin Hilman
2015-12-09 10:47       ` Alexander Aring
2015-12-09 10:47         ` Alexander Aring
2015-12-09 10:54         ` Russell King - ARM Linux
2015-12-09 10:54           ` Russell King - ARM Linux
2015-12-14  9:49         ` Ulf Hansson
2015-12-14  9:49           ` Ulf Hansson
2015-12-14  9:49           ` Ulf Hansson
2015-12-04 17:45 ` [PATCH v2 2/5] ARM: bcm2835: Define two new packets from the latest firmware Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-04 17:45 ` [PATCH v2 3/5] ARM: bcm2835: add rpi power domain driver Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-07 23:35   ` Kevin Hilman
2015-12-07 23:35     ` Kevin Hilman
2015-12-08  1:04     ` Eric Anholt
2015-12-08  1:04       ` Eric Anholt
2015-12-08 18:19       ` Kevin Hilman
2015-12-08 18:19         ` Kevin Hilman
2015-12-11 18:13   ` Stefan Wahren
2015-12-11 18:13     ` Stefan Wahren
2015-12-11 18:13     ` Stefan Wahren
2015-12-04 17:45 ` [PATCH v2 4/5] dt-bindings: add rpi power domain driver bindings Eric Anholt
2015-12-04 17:45   ` Eric Anholt
2015-12-04 17:45 ` [PATCH v2 5/5] ARM: bcm2835: Add the Raspberry Pi power domain driver to the DT Eric Anholt
2015-12-04 17:45   ` Eric Anholt

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.