Discussion:
[PATCH v3 0/5] Add max77802 regulator operating mode support
Javier Martinez Canillas
2014-10-20 14:47:47 UTC
Permalink
Hello Mark,

This is the third version of the series that adds operating modes
support for the regulators in the max77802 PMIC. This version uses the
standard regulator suspend states bindings as you suggested and also
drops the patches already picked by you from the first [0] and second [1]
version of the series.

The series adds a "regulator-initial-mode" property to configure at
startup the operating mode for the regulators that support changing
its mode during normal operation and a "regulator-mode" property for the
regulators that supports changing its operating mode when the system
enters in a suspend state. These properties were originally part of
Chanwoo Choi's regulator suspend state series [2] but were removed since
there wasn't a way to define the operatin modes in a generic way.

In this series, the generic regulator DT binding doc explains that each
device has to document what their valid operating modes are and the
driver has to parse those and translate to the standard regulator modes.

This series depend on [2] and also v2 of patch:
"ARM: EXYNOS: Call regulator core suspend prepare and finish functions" [3].

Javier Martinez Canillas (5):
regulator: of: Decrement refcount for suspend state nodes
regulator: core: Add regulator mode and initial mode properties
regulator: max77802: Document regulator operating modes
regulator: max77802: Parse regulator operating mode properties
ARM: dts: Configure regulators for suspend on exynos Peach boards

.../devicetree/bindings/regulator/max77802.txt | 33 +++++++++
.../devicetree/bindings/regulator/regulator.txt | 14 ++++
arch/arm/boot/dts/exynos5420-peach-pit.dts | 81 ++++++++++++++++++++++
arch/arm/boot/dts/exynos5800-peach-pi.dts | 81 ++++++++++++++++++++++
drivers/regulator/max77802.c | 44 ++++++++++++
drivers/regulator/of_regulator.c | 1 +
6 files changed, 254 insertions(+)

Patch #1 is a trivial fix to of_get_regulation_constraints() where the
suspend state device node refcount was not decremented after usage.

Patch #2 adds the regulator-initial-mode and regulator-mode properties to the
generic regulator suspend state bindings.

Patch #3 documents the valid operating modes for the max77802 regulators.

Patch #4 adds the parse logic to fill the regulation constraints to change the
regulator operating modes by the core.

Patch #5 configure the regulators operating modes on Exynos Peach Chromebooks.

Best regards,
Javier

[0]: https://lkml.org/lkml/2014/10/8/331
[1]: https://lkml.org/lkml/2014/10/16/504
[2]: https://lkml.org/lkml/2014/10/10/161
[3]: http://www.spinics.net/lists/arm-kernel/msg369923.html
Javier Martinez Canillas
2014-10-20 14:47:49 UTC
Permalink
Some regulators can run on different operating modes (opmodes). This
allows systems to choose the most efficient opmode for each regulator.

This patch adds a "regulator-initial-mode" property to configure at
startup the operating mode for the regulators that support changing
its mode during normal operation and a "regulator-mode" to be used as
a property of the suspend states "regulator-state-[mem/disk]" nodes
for the regulators that supports changing its operating mode when the
system enters in a suspend state.

The set of possible modes that a regulator can operate depends on
the hardware capabilities so a list of generic operating modes can't
be provided. Instead, each hardware should define the list of valid
operating modes for the regulators found on that device.

Signed-off-by: Javier Martinez Canillas <***@collabora.co.uk>
---
Documentation/devicetree/bindings/regulator/regulator.txt | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index aaad615..8b54be1 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -28,6 +28,20 @@ Optional properties:
- regulator-state-[mem/disk] node has following common properties:
- regulator-on-in-suspend: regulator should be on in suspend state.
- regulator-off-in-suspend: regulator should be off in suspend state.
+ - regulator-mode: operating mode in the given suspend state.
+ The set of possible operating modes depends on the capabilities of
+ every hardware so the valid modes are documented on each regulator
+ device tree binding document.
+ The "regulator-mode" property only takes effect if the regulator is
+ enabled for the given suspend state using "regulator-on-in-suspend".
+ If the regulator has not been explicitly disabled for the given state
+ with "regulator-off-in-suspend", then setting the operating mode
+ will also have no effect.
+- regulator-initial-mode: initial operating mode. The set of possible operating
+ modes is the same used for the regulator-mode property and the device binding
+ documentation explains which property each regulator supports.
+If no mode is defined, then the OS will not manage the modes and the hardware
+default values will be used instead.

Deprecated properties:
- regulator-compatible: If a regulator chip contains multiple
--
2.1.0
Javier Martinez Canillas
2014-10-20 14:47:48 UTC
Permalink
of_get_regulation_constraints() calls of_get_child_by_name() to find the
regulator-state-{mem,disk} child nodes for each regulator. This function
increments the device node reference counter but this is not decremented
once the function is done using the node.

Fix that by calling of_node_put() after finishing using the device node.

Signed-off-by: Javier Martinez Canillas <***@collabora.co.uk>
---
drivers/regulator/of_regulator.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index b375ffe..f0d19fc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -107,6 +107,7 @@ static void of_get_regulation_constraints(struct device_node *np,
"regulator-off-in-suspend"))
suspend_state->disabled = true;

+ of_node_put(suspend_np);
suspend_state = NULL;
suspend_np = NULL;
}
--
2.1.0
Javier Martinez Canillas
2014-10-20 14:47:50 UTC
Permalink
Some regulators from the max77802 PMIC support to be configured in one
of two operating mode: Output ON (normal) and Output On Low Power Mode.
Not all regulators support these two modes and for some of them, the
mode can be changed while the system is running in normal operation
while others only support their mode to be changed on system suspend.

Extend the max77802 PMIC binding, documenting the possible operating
modes values so the regulators modes can be correctly configured.

Signed-off-by: Javier Martinez Canillas <***@collabora.co.uk>
---

Changes since v2:
- Use the standard suspend states bindings as suggested by Mark Brown.

.../devicetree/bindings/regulator/max77802.txt | 33 ++++++++++++++++++++++
1 file changed, 33 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/max77802.txt b/Documentation/devicetree/bindings/regulator/max77802.txt
index 5aeaffc..f265319 100644
--- a/Documentation/devicetree/bindings/regulator/max77802.txt
+++ b/Documentation/devicetree/bindings/regulator/max77802.txt
@@ -25,6 +25,27 @@ with their hardware counterparts as follow. The valid names are:
example: LDO1, LDO2, LDO35.
-BUCKn : for BUCKs, where n can lie in range 1 to 10.
example: BUCK1, BUCK5, BUCK10.
+
+The max77802 regulator supports two different operating modes: Normal and Low
+Power Mode. Some regulators support the modes to be changed at startup or by
+the consumers during normal operation while others only support to change the
+mode during system suspend. The standard regulator suspend states binding can
+be used to configure the regulator operating mode.
+
+The regulators that support the standard "regulator-initial-mode" property,
+changing their mode during normal operation are: LDOs 1, 3, 20 and 21.
+
+The possible values for "regulator-initial-mode" and "regulator-mode" are:
+ 1: Normal regulator voltage output mode.
+ 3: Low Power which reduces the quiescent current down to only 1uA
+
+The list of valid modes are defined in the dt-bindings/regulator/regulator.h
+header and can be included by device tree source files.
+
+The standard "regulator-mode" property can only be used for regulators that
+support changing their mode to Low Power Mode during suspend. These regulators
+are: BUCKs 2-4 and LDOs 1-35.
+
Example:

***@09 {
@@ -36,11 +57,23 @@ Example:
#size-cells = <0>;

regulators {
+ ldo1_reg: LDO1 {
+ regulator-name = "vdd_1v0";
+ regulator-min-microvolt = <1000000>;
+ regulator-max-microvolt = <1000000>;
+ regulator-always-on;
+ regulator-initial-mode = <MAX77802_OPMODE_LP>;
+ };
+
ldo11_reg: LDO11 {
regulator-name = "vdd_ldo11";
regulator-min-microvolt = <1900000>;
regulator-max-microvolt = <1900000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

buck1_reg: BUCK1 {
--
2.1.0
Javier Martinez Canillas
2014-10-20 14:47:52 UTC
Permalink
The regulator core now has support to choose if a regulator
has to be enabled or disabled during system suspend and also
the max77802 driver supports changing the regulator operating
mode during runtime and when the system enters into sleep mode.

To lower power during suspend, configure the regulators state
using the same configuration found in the ChromeOS 3.8 kernel.

Signed-off-by: Javier Martinez Canillas <***@collabora.co.uk>
---

Changes since v2:
- Use the standard suspend state binding as suggested by Mark Brown.

arch/arm/boot/dts/exynos5420-peach-pit.dts | 81 ++++++++++++++++++++++++++++++
arch/arm/boot/dts/exynos5800-peach-pi.dts | 81 ++++++++++++++++++++++++++++++
2 files changed, 162 insertions(+)

diff --git a/arch/arm/boot/dts/exynos5420-peach-pit.dts b/arch/arm/boot/dts/exynos5420-peach-pit.dts
index 9a050e1..8b744c7 100644
--- a/arch/arm/boot/dts/exynos5420-peach-pit.dts
+++ b/arch/arm/boot/dts/exynos5420-peach-pit.dts
@@ -13,6 +13,7 @@
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/clock/maxim,max77802.h>
+#include <dt-bindings/regulator/maxim,max77802.h>
#include "exynos5420.dtsi"

/ {
@@ -192,6 +193,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck2_reg: BUCK2 {
@@ -201,6 +205,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck3_reg: BUCK3 {
@@ -210,6 +217,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck4_reg: BUCK4 {
@@ -219,6 +229,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck5_reg: BUCK5 {
@@ -227,6 +240,9 @@
regulator-max-microvolt = <1200000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck6_reg: BUCK6 {
@@ -236,6 +252,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck7_reg: BUCK7 {
@@ -244,6 +263,9 @@
regulator-max-microvolt = <1350000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

buck8_reg: BUCK8 {
@@ -252,6 +274,9 @@
regulator-max-microvolt = <2850000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck9_reg: BUCK9 {
@@ -260,6 +285,9 @@
regulator-max-microvolt = <2000000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

buck10_reg: BUCK10 {
@@ -268,6 +296,9 @@
regulator-max-microvolt = <1800000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

ldo1_reg: LDO1 {
@@ -275,6 +306,10 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo2_reg: LDO2 {
@@ -288,6 +323,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

vqmmc_sdcard: ldo4_reg: LDO4 {
@@ -295,6 +334,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <2800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo5_reg: LDO5 {
@@ -302,6 +344,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo6_reg: LDO6 {
@@ -309,6 +354,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo7_reg: LDO7 {
@@ -322,6 +370,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo9_reg: LDO9 {
@@ -329,6 +380,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo10_reg: LDO10 {
@@ -336,6 +391,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo11_reg: LDO11 {
@@ -343,6 +401,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo12_reg: LDO12 {
@@ -350,6 +412,9 @@
regulator-min-microvolt = <3000000>;
regulator-max-microvolt = <3000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo13_reg: LDO13 {
@@ -357,6 +422,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo14_reg: LDO14 {
@@ -364,6 +433,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo15_reg: LDO15 {
@@ -371,6 +443,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo17_reg: LDO17 {
@@ -378,6 +453,9 @@
regulator-min-microvolt = <900000>;
regulator-max-microvolt = <1400000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo18_reg: LDO18 {
@@ -451,6 +529,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo32_reg: LDO32 {
diff --git a/arch/arm/boot/dts/exynos5800-peach-pi.dts b/arch/arm/boot/dts/exynos5800-peach-pi.dts
index e8fdda8..df7fbde 100644
--- a/arch/arm/boot/dts/exynos5800-peach-pi.dts
+++ b/arch/arm/boot/dts/exynos5800-peach-pi.dts
@@ -13,6 +13,7 @@
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/clock/maxim,max77802.h>
+#include <dt-bindings/regulator/maxim,max77802.h>
#include "exynos5800.dtsi"

/ {
@@ -191,6 +192,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck2_reg: BUCK2 {
@@ -200,6 +204,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck3_reg: BUCK3 {
@@ -209,6 +216,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck4_reg: BUCK4 {
@@ -218,6 +228,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck5_reg: BUCK5 {
@@ -226,6 +239,9 @@
regulator-max-microvolt = <1200000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck6_reg: BUCK6 {
@@ -235,6 +251,9 @@
regulator-always-on;
regulator-boot-on;
regulator-ramp-delay = <12500>;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck7_reg: BUCK7 {
@@ -243,6 +262,9 @@
regulator-max-microvolt = <1350000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

buck8_reg: BUCK8 {
@@ -251,6 +273,9 @@
regulator-max-microvolt = <2850000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

buck9_reg: BUCK9 {
@@ -259,6 +284,9 @@
regulator-max-microvolt = <2000000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

buck10_reg: BUCK10 {
@@ -267,6 +295,9 @@
regulator-max-microvolt = <1800000>;
regulator-always-on;
regulator-boot-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ };
};

ldo1_reg: LDO1 {
@@ -274,6 +305,10 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo2_reg: LDO2 {
@@ -287,6 +322,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

vqmmc_sdcard: ldo4_reg: LDO4 {
@@ -294,6 +333,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <2800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo5_reg: LDO5 {
@@ -301,6 +343,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo6_reg: LDO6 {
@@ -308,6 +353,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo7_reg: LDO7 {
@@ -321,6 +369,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo9_reg: LDO9 {
@@ -328,6 +379,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo10_reg: LDO10 {
@@ -335,6 +390,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo11_reg: LDO11 {
@@ -342,6 +400,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo12_reg: LDO12 {
@@ -349,6 +411,9 @@
regulator-min-microvolt = <3000000>;
regulator-max-microvolt = <3000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo13_reg: LDO13 {
@@ -356,6 +421,10 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-on-in-suspend;
+ regulator-mode = <MAX77802_OPMODE_LP>;
+ };
};

ldo14_reg: LDO14 {
@@ -363,6 +432,9 @@
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo15_reg: LDO15 {
@@ -370,6 +442,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo17_reg: LDO17 {
@@ -377,6 +452,9 @@
regulator-min-microvolt = <900000>;
regulator-max-microvolt = <1400000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo18_reg: LDO18 {
@@ -450,6 +528,9 @@
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1000000>;
regulator-always-on;
+ regulator-state-mem {
+ regulator-off-in-suspend;
+ };
};

ldo32_reg: LDO32 {
--
2.1.0
Javier Martinez Canillas
2014-10-20 14:47:51 UTC
Permalink
The max77802 PMIC regulators output can be configured in one of two
modes: Output ON (normal) and Output ON in Low Power Mode. Some of
the regulators support their operating mode to be changed on startup
or by consumers when the system is running while others only support
their operating mode to be changed while the system has entered in a
suspend state.

The regulator Device Tree binding documents a set of properties to
configure the regulators operating modes from a FDT. This patch parse
those properties and fills the regulator constraints so the regulator
core can call the suspend handlers when the system enters into sleep.

Signed-off-by: Javier Martinez Canillas <***@collabora.co.uk>
---

Changes since v2:
- Use the standard suspend states binding instead of custom properties.
Suggested by Mark Brown.

Changes since v1:
- Use the static inline max77802_map_mode() function instead of a macro.
Suggested by Mark Brown.

drivers/regulator/max77802.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)

diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
index 5839c45..2cbf980 100644
--- a/drivers/regulator/max77802.c
+++ b/drivers/regulator/max77802.c
@@ -518,6 +518,48 @@ static struct regulator_desc regulators[] = {
};

#ifdef CONFIG_OF
+
+static void max77802_parse_opmodes(struct device_node *np,
+ struct regulation_constraints *cons)
+{
+ u32 pval;
+ int i;
+ char *states[PM_SUSPEND_MAX + 1] = {
+ [PM_SUSPEND_MEM] = "regulator-state-mem",
+ [PM_SUSPEND_MAX] = "regulator-state-disk",
+ };
+ struct regulator_state *state;
+ struct device_node *state_np;
+
+ if (!of_property_read_u32(np, "regulator-initial-mode", &pval))
+ cons->initial_mode = max77802_map_mode(pval);
+
+ for (i = 0; i < ARRAY_SIZE(states); i++) {
+ switch (i) {
+ case PM_SUSPEND_MEM:
+ state = &cons->state_mem;
+ break;
+ case PM_SUSPEND_MAX:
+ state = &cons->state_disk;
+ break;
+ default:
+ continue;
+ };
+
+ state_np = of_get_child_by_name(np, states[i]);
+ if (!state_np || !state)
+ continue;
+
+ if (!of_property_read_u32(np, "regulator-mode", &pval))
+ state->mode = max77802_map_mode(pval);
+
+ of_node_put(state_np);
+
+ state = NULL;
+ state_np = NULL;
+ };
+}
+
static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev,
struct max77686_platform_data *pdata)
{
@@ -555,6 +597,8 @@ static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev,
rdata[i].initdata = rmatch.init_data;
rdata[i].of_node = rmatch.of_node;
rdata[i].id = regulators[i].id;
+ max77802_parse_opmodes(rdata[i].of_node,
+ &rdata[i].initdata->constraints);
}

pdata->regulators = rdata;
--
2.1.0
Loading...