aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 22:04:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 22:04:53 -0400
commitd9dce51c9b77b803348c787165a884b6e11011f0 (patch)
treee17db09d1cc37d1a87598dbc134abb9e38ac4c60
parente2ca54250d14347c35c55e9304296c2f04f3fbad (diff)
parent4f38c566a0967ce9291537ba04891391681a7661 (diff)
Merge tag 'regulator-v4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "A few core enhancements to deal with some of the slightly more complicated edge cases that have started cropping up in systems, both new ones and old ones that people started worrying about upstream, but otherwise a quiet release for the regulator API: - When applying constraints at system image if we have a voltage range specified and the regulator is currently configured outside the bounds of that range bring the regulator to the nearest end of the range. - When regulators are in non-regulating bypass modes make sure that we always use the voltage from the parent regulator. - Support for LP873x, PV88080, PM8894 and FAN53555 chips" * tag 'regulator-v4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (71 commits) regulator: rk808: Migrate to regulator core's simplified DT parsing code regulator: lp873x: Add support for lp873x PMIC regulators regulator: tps65917/palmas: Simplify multiple dereference of match->of_node regulator: tps65917/palmas: Handle possible memory allocation failure regulator: tps65917/palmas: Simplify multiple dereference of pdata->reg_init[idx] regulator: tps65917/palmas: Simplify multiple dereference of ddata->palmas_matches[idx] regulator: pwm: Use pwm_get_args() where appropriate pwm: Introduce the pwm_args concept regulator: max77686: Configure enable time to properly handle regulator enable regulator: rk808: Add rk808_reg_ops_ranges for LDO3 regulator: core: Add early supply resolution for regulators regulator: axp20x: Fix axp22x ldo_io voltage ranges regulator: tps65917/palmas: Add bypass "On" value regulator: rk808: remove unused rk808_reg_ops_ranges regulator: refactor valid_ops_mask checking code regulator: rk808: remove linear range definitions with a single range regulator: max77620: Add support for device specific ramp rate setting regulator: max77620: Add details of device specific ramp rate setting regulator: helpers: Ensure bypass register field matches ON value regulator: core: Move registration of regulator device ...
-rw-r--r--Documentation/devicetree/bindings/regulator/max8973-regulator.txt7
-rw-r--r--Documentation/devicetree/bindings/regulator/pv88080.txt49
-rw-r--r--Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt37
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator-max77620.txt22
-rw-r--r--Documentation/devicetree/bindings/regulator/ti-abb-regulator.txt10
-rw-r--r--Documentation/devicetree/bindings/regulator/twl-regulator.txt6
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/pwm/core.c21
-rw-r--r--drivers/pwm/pwm-clps711x.c2
-rw-r--r--drivers/pwm/pwm-pxa.c2
-rw-r--r--drivers/regulator/Kconfig17
-rw-r--r--drivers/regulator/Makefile8
-rw-r--r--drivers/regulator/act8865-regulator.c113
-rw-r--r--drivers/regulator/as3722-regulator.c65
-rw-r--r--drivers/regulator/core.c279
-rw-r--r--drivers/regulator/fan53555.c24
-rw-r--r--drivers/regulator/helpers.c2
-rw-r--r--drivers/regulator/lp3971.c2
-rw-r--r--drivers/regulator/lp3972.c2
-rw-r--r--drivers/regulator/lp873x-regulator.c241
-rw-r--r--drivers/regulator/max14577-regulator.c (renamed from drivers/regulator/max14577.c)0
-rw-r--r--drivers/regulator/max77620-regulator.c83
-rw-r--r--drivers/regulator/max77686-regulator.c17
-rw-r--r--drivers/regulator/max77693-regulator.c (renamed from drivers/regulator/max77693.c)0
-rw-r--r--drivers/regulator/max77802-regulator.c2
-rw-r--r--drivers/regulator/max8973-regulator.c97
-rw-r--r--drivers/regulator/max8997-regulator.c (renamed from drivers/regulator/max8997.c)2
-rw-r--r--drivers/regulator/of_regulator.c6
-rw-r--r--drivers/regulator/palmas-regulator.c67
-rw-r--r--drivers/regulator/pv88080-regulator.c419
-rw-r--r--drivers/regulator/pv88080-regulator.h92
-rw-r--r--drivers/regulator/pwm-regulator.c78
-rw-r--r--drivers/regulator/qcom_spmi-regulator.c275
-rw-r--r--drivers/regulator/rk808-regulator.c310
-rw-r--r--drivers/regulator/s2mps11.c13
-rw-r--r--drivers/regulator/tps6524x-regulator.c2
-rw-r--r--drivers/regulator/twl-regulator.c106
-rw-r--r--include/linux/mfd/as3722.h1
-rw-r--r--include/linux/mfd/samsung/core.h3
-rw-r--r--include/linux/pwm.h33
-rw-r--r--include/linux/regulator/act8865.h2
-rw-r--r--include/linux/regulator/consumer.h4
-rw-r--r--include/linux/regulator/driver.h7
-rw-r--r--include/linux/regulator/machine.h1
-rw-r--r--include/linux/regulator/max8973-regulator.h5
45 files changed, 1960 insertions, 580 deletions
diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
index f80ea2fe27e6..c2c68fcc1b41 100644
--- a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
@@ -32,6 +32,13 @@ Optional properties:
32 32
33Enhanced transient response (ETR) will affect the configuration of CKADV. 33Enhanced transient response (ETR) will affect the configuration of CKADV.
34 34
35-junction-warn-millicelsius: u32, junction warning temperature threshold
36 in millicelsius. If die temperature crosses this level then
37 device generates the warning interrupts.
38
39Please note that thermal functionality is only supported on MAX77621. The
40supported threshold warning temperature for MAX77621 are 120 degC and 140 degC.
41
35Example: 42Example:
36 43
37 max8973@1b { 44 max8973@1b {
diff --git a/Documentation/devicetree/bindings/regulator/pv88080.txt b/Documentation/devicetree/bindings/regulator/pv88080.txt
new file mode 100644
index 000000000000..38a614210dcb
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/pv88080.txt
@@ -0,0 +1,49 @@
1* Powerventure Semiconductor PV88080 Voltage Regulator
2
3Required properties:
4- compatible: "pvs,pv88080".
5- reg: I2C slave address, usually 0x49.
6- interrupts: the interrupt outputs of the controller
7- regulators: A node that houses a sub-node for each regulator within the
8 device. Each sub-node is identified using the node's name, with valid
9 values listed below. The content of each sub-node is defined by the
10 standard binding for regulators; see regulator.txt.
11 BUCK1, BUCK2, and BUCK3.
12
13Optional properties:
14- Any optional property defined in regulator.txt
15
16Example
17
18 pmic: pv88080@49 {
19 compatible = "pvs,pv88080";
20 reg = <0x49>;
21 interrupt-parent = <&gpio>;
22 interrupts = <24 24>;
23
24 regulators {
25 BUCK1 {
26 regulator-name = "buck1";
27 regulator-min-microvolt = < 600000>;
28 regulator-max-microvolt = <1393750>;
29 regulator-min-microamp = < 220000>;
30 regulator-max-microamp = <7040000>;
31 };
32
33 BUCK2 {
34 regulator-name = "buck2";
35 regulator-min-microvolt = < 600000>;
36 regulator-max-microvolt = <1393750>;
37 regulator-min-microamp = <1496000>;
38 regulator-max-microamp = <4189000>;
39 };
40
41 BUCK3 {
42 regulator-name = "buck3";
43 regulator-min-microvolt = <1400000>;
44 regulator-max-microvolt = <2193750>;
45 regulator-min-microamp = <1496000>;
46 regulator-max-microamp = <4189000>;
47 };
48 };
49 };
diff --git a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
index d00bfd8624a5..46c6f3ed1a1c 100644
--- a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
@@ -7,6 +7,7 @@ Qualcomm SPMI Regulators
7 "qcom,pm8841-regulators" 7 "qcom,pm8841-regulators"
8 "qcom,pm8916-regulators" 8 "qcom,pm8916-regulators"
9 "qcom,pm8941-regulators" 9 "qcom,pm8941-regulators"
10 "qcom,pm8994-regulators"
10 11
11- interrupts: 12- interrupts:
12 Usage: optional 13 Usage: optional
@@ -68,6 +69,37 @@ Qualcomm SPMI Regulators
68 Definition: Reference to regulator supplying the input pin, as 69 Definition: Reference to regulator supplying the input pin, as
69 described in the data sheet. 70 described in the data sheet.
70 71
72- vdd_s1-supply:
73- vdd_s2-supply:
74- vdd_s3-supply:
75- vdd_s4-supply:
76- vdd_s5-supply:
77- vdd_s6-supply:
78- vdd_s7-supply:
79- vdd_s8-supply:
80- vdd_s9-supply:
81- vdd_s10-supply:
82- vdd_s11-supply:
83- vdd_s12-supply:
84- vdd_l1-supply:
85- vdd_l2_l26_l28-supply:
86- vdd_l3_l11-supply:
87- vdd_l4_l27_l31-supply:
88- vdd_l5_l7-supply:
89- vdd_l6_l12_l32-supply:
90- vdd_l8_l16_l30-supply:
91- vdd_l9_l10_l18_l22-supply:
92- vdd_l13_l19_l23_l24-supply:
93- vdd_l14_l15-supply:
94- vdd_l17_l29-supply:
95- vdd_l20_l21-supply:
96- vdd_l25-supply:
97- vdd_lvs_1_2-supply:
98 Usage: optional (pm8994 only)
99 Value type: <phandle>
100 Definition: Reference to regulator supplying the input pin, as
101 described in the data sheet.
102
71 103
72The regulator node houses sub-nodes for each regulator within the device. Each 104The regulator node houses sub-nodes for each regulator within the device. Each
73sub-node is identified using the node's name, with valid values listed for each 105sub-node is identified using the node's name, with valid values listed for each
@@ -85,6 +117,11 @@ pm8941:
85 l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, lvs1, lvs2, lvs3, 117 l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, lvs1, lvs2, lvs3,
86 mvs1, mvs2 118 mvs1, mvs2
87 119
120pm8994:
121 s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, l1, l2, l3, l4, l5,
122 l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, l17, l18, l19, l20,
123 l21, l22, l23, l24, l25, l26, l27, l28, l29, l30, l31, l32, lvs1, lvs2
124
88The content of each sub-node is defined by the standard binding for regulators - 125The content of each sub-node is defined by the standard binding for regulators -
89see regulator.txt - with additional custom properties described below: 126see regulator.txt - with additional custom properties described below:
90 127
diff --git a/Documentation/devicetree/bindings/regulator/regulator-max77620.txt b/Documentation/devicetree/bindings/regulator/regulator-max77620.txt
index b3c8ca672024..1c4bfe786736 100644
--- a/Documentation/devicetree/bindings/regulator/regulator-max77620.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator-max77620.txt
@@ -94,6 +94,28 @@ Following are additional properties:
94 This is applicable if suspend state 94 This is applicable if suspend state
95 FPS source is selected as FPS0, FPS1 or 95 FPS source is selected as FPS0, FPS1 or
96 FPS2. 96 FPS2.
97- maxim,ramp-rate-setting: integer, ramp rate(uV/us) setting to be
98 configured to the device.
99 The platform may have different ramp
100 rate than advertised ramp rate if it has
101 design variation from Maxim's
102 recommended. On this case, platform
103 specific ramp rate is used for ramp time
104 calculation and this property is used
105 for device register configurations.
106 The measured ramp rate of platform is
107 provided by the regulator-ramp-delay
108 as described in <devicetree/bindings/
109 regulator/regulator.txt>.
110 Maxim Max77620 supports following ramp
111 delay:
112 SD: 13.75mV/us, 27.5mV/us, 55mV/us
113 LDOs: 5mV/us, 100mV/us
114
115Note: If the measured ramp delay is same as advertised ramp delay then it is not
116required to provide the ramp delay with property "maxim,ramp-rate-setting". The
117ramp rate can be provided by the regulator-ramp-delay which will be used for
118ramp time calculation for voltage change as well as for device configuration.
97 119
98Example: 120Example:
99-------- 121--------
diff --git a/Documentation/devicetree/bindings/regulator/ti-abb-regulator.txt b/Documentation/devicetree/bindings/regulator/ti-abb-regulator.txt
index c58db75f959e..c3f6546ebac7 100644
--- a/Documentation/devicetree/bindings/regulator/ti-abb-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/ti-abb-regulator.txt
@@ -14,8 +14,8 @@ Required Properties:
14 - "setup-address" - contains setup register address of ABB module (ti,abb-v3) 14 - "setup-address" - contains setup register address of ABB module (ti,abb-v3)
15 - "int-address" - contains address of interrupt register for ABB module 15 - "int-address" - contains address of interrupt register for ABB module
16 (also see Optional properties) 16 (also see Optional properties)
17- #address-cell: should be 0 17- #address-cells: should be 0
18- #size-cell: should be 0 18- #size-cells: should be 0
19- clocks: should point to the clock node used by ABB module 19- clocks: should point to the clock node used by ABB module
20- ti,settling-time: Settling time in uSecs from SoC documentation for ABB module 20- ti,settling-time: Settling time in uSecs from SoC documentation for ABB module
21 to settle down(target time for SR2_WTCNT_VALUE). 21 to settle down(target time for SR2_WTCNT_VALUE).
@@ -69,7 +69,7 @@ Example #1: Simplest configuration (no efuse data, hard coded ABB table):
69abb_x: regulator-abb-x { 69abb_x: regulator-abb-x {
70 compatible = "ti,abb-v1"; 70 compatible = "ti,abb-v1";
71 regulator-name = "abb_x"; 71 regulator-name = "abb_x";
72 #address-cell = <0>; 72 #address-cells = <0>;
73 #size-cells = <0>; 73 #size-cells = <0>;
74 reg = <0x483072f0 0x8>, <0x48306818 0x4>; 74 reg = <0x483072f0 0x8>, <0x48306818 0x4>;
75 reg-names = "base-address", "int-address"; 75 reg-names = "base-address", "int-address";
@@ -89,7 +89,7 @@ Example #2: Efuse bits contain ABB mode setting (no LDO override capability)
89abb_y: regulator-abb-y { 89abb_y: regulator-abb-y {
90 compatible = "ti,abb-v2"; 90 compatible = "ti,abb-v2";
91 regulator-name = "abb_y"; 91 regulator-name = "abb_y";
92 #address-cell = <0>; 92 #address-cells = <0>;
93 #size-cells = <0>; 93 #size-cells = <0>;
94 reg = <0x4a307bd0 0x8>, <0x4a306014 0x4>, <0x4A002268 0x8>; 94 reg = <0x4a307bd0 0x8>, <0x4a306014 0x4>, <0x4A002268 0x8>;
95 reg-names = "base-address", "int-address", "efuse-address"; 95 reg-names = "base-address", "int-address", "efuse-address";
@@ -110,7 +110,7 @@ Example #3: Efuse bits contain ABB mode setting and LDO override capability
110abb_z: regulator-abb-z { 110abb_z: regulator-abb-z {
111 compatible = "ti,abb-v2"; 111 compatible = "ti,abb-v2";
112 regulator-name = "abb_z"; 112 regulator-name = "abb_z";
113 #address-cell = <0>; 113 #address-cells = <0>;
114 #size-cells = <0>; 114 #size-cells = <0>;
115 reg = <0x4ae07ce4 0x8>, <0x4ae06010 0x4>, 115 reg = <0x4ae07ce4 0x8>, <0x4ae06010 0x4>,
116 <0x4a002194 0x8>, <0x4ae0C314 0x4>; 116 <0x4a002194 0x8>, <0x4ae0C314 0x4>;
diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
index 75b0c1669504..74a91c4f8530 100644
--- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -57,6 +57,12 @@ For twl4030 regulators/LDOs
57 57
58Optional properties: 58Optional properties:
59- Any optional property defined in bindings/regulator/regulator.txt 59- Any optional property defined in bindings/regulator/regulator.txt
60For twl4030 regulators/LDOs:
61 - regulator-initial-mode:
62 - 0x08 - Sleep mode, the nominal output voltage is maintained with low power
63 consumption with low load current capability.
64 - 0x0e - Active mode, the regulator can deliver its nominal output voltage
65 with full-load current capability.
60 66
61Example: 67Example:
62 68
diff --git a/MAINTAINERS b/MAINTAINERS
index 9c567a431d8d..ca373daf8b68 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7020,9 +7020,9 @@ M: Chanwoo Choi <cw00.choi@samsung.com>
7020M: Krzysztof Kozlowski <k.kozlowski@samsung.com> 7020M: Krzysztof Kozlowski <k.kozlowski@samsung.com>
7021L: linux-kernel@vger.kernel.org 7021L: linux-kernel@vger.kernel.org
7022S: Supported 7022S: Supported
7023F: drivers/*/max14577.c 7023F: drivers/*/max14577*.c
7024F: drivers/*/max77686*.c 7024F: drivers/*/max77686*.c
7025F: drivers/*/max77693.c 7025F: drivers/*/max77693*.c
7026F: drivers/extcon/extcon-max14577.c 7026F: drivers/extcon/extcon-max14577.c
7027F: drivers/extcon/extcon-max77693.c 7027F: drivers/extcon/extcon-max77693.c
7028F: drivers/rtc/rtc-max77686.c 7028F: drivers/rtc/rtc-max77686.c
@@ -12011,7 +12011,9 @@ L: linux-kernel@vger.kernel.org
12011W: http://www.slimlogic.co.uk/?p=48 12011W: http://www.slimlogic.co.uk/?p=48
12012T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 12012T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git
12013S: Supported 12013S: Supported
12014F: Documentation/devicetree/bindings/regulator/
12014F: drivers/regulator/ 12015F: drivers/regulator/
12016F: include/dt-bindings/regulator/
12015F: include/linux/regulator/ 12017F: include/linux/regulator/
12016 12018
12017VRF 12019VRF
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 7831bc6b51dd..680fbc795a0a 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -128,6 +128,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
128 set_bit(PWMF_REQUESTED, &pwm->flags); 128 set_bit(PWMF_REQUESTED, &pwm->flags);
129 pwm->label = label; 129 pwm->label = label;
130 130
131 /*
132 * FIXME: This should be removed once all PWM users properly make use
133 * of struct pwm_args to initialize the PWM device. As long as this is
134 * here, the PWM state and hardware state can get out of sync.
135 */
136 pwm_apply_args(pwm);
137
131 return 0; 138 return 0;
132} 139}
133 140
@@ -146,12 +153,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args)
146 if (IS_ERR(pwm)) 153 if (IS_ERR(pwm))
147 return pwm; 154 return pwm;
148 155
149 pwm_set_period(pwm, args->args[1]); 156 pwm->args.period = args->args[1];
150 157
151 if (args->args[2] & PWM_POLARITY_INVERTED) 158 if (args->args[2] & PWM_POLARITY_INVERTED)
152 pwm_set_polarity(pwm, PWM_POLARITY_INVERSED); 159 pwm->args.polarity = PWM_POLARITY_INVERSED;
153 else 160 else
154 pwm_set_polarity(pwm, PWM_POLARITY_NORMAL); 161 pwm->args.polarity = PWM_POLARITY_NORMAL;
155 162
156 return pwm; 163 return pwm;
157} 164}
@@ -172,7 +179,7 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
172 if (IS_ERR(pwm)) 179 if (IS_ERR(pwm))
173 return pwm; 180 return pwm;
174 181
175 pwm_set_period(pwm, args->args[1]); 182 pwm->args.period = args->args[1];
176 183
177 return pwm; 184 return pwm;
178} 185}
@@ -747,13 +754,13 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id)
747 if (!chip) 754 if (!chip)
748 goto out; 755 goto out;
749 756
757 pwm->args.period = chosen->period;
758 pwm->args.polarity = chosen->polarity;
759
750 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); 760 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
751 if (IS_ERR(pwm)) 761 if (IS_ERR(pwm))
752 goto out; 762 goto out;
753 763
754 pwm_set_period(pwm, chosen->period);
755 pwm_set_polarity(pwm, chosen->polarity);
756
757out: 764out:
758 mutex_unlock(&pwm_lookup_lock); 765 mutex_unlock(&pwm_lookup_lock);
759 return pwm; 766 return pwm;
diff --git a/drivers/pwm/pwm-clps711x.c b/drivers/pwm/pwm-clps711x.c
index a80c10803636..7d335422cfda 100644
--- a/drivers/pwm/pwm-clps711x.c
+++ b/drivers/pwm/pwm-clps711x.c
@@ -60,7 +60,7 @@ static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
60 return -EINVAL; 60 return -EINVAL;
61 61
62 /* Store constant period value */ 62 /* Store constant period value */
63 pwm_set_period(pwm, DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq)); 63 pwm->args.period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq);
64 64
65 return 0; 65 return 0;
66} 66}
diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index cb2f7024cf68..58b709f29130 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -160,7 +160,7 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args)
160 if (IS_ERR(pwm)) 160 if (IS_ERR(pwm))
161 return pwm; 161 return pwm;
162 162
163 pwm_set_period(pwm, args->args[0]); 163 pwm->args.period = args->args[0];
164 164
165 return pwm; 165 return pwm;
166} 166}
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index c77dc08b1202..144cbf5b3e5a 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -321,6 +321,15 @@ config REGULATOR_LP872X
321 help 321 help
322 This driver supports LP8720/LP8725 PMIC 322 This driver supports LP8720/LP8725 PMIC
323 323
324config REGULATOR_LP873X
325 tristate "TI LP873X Power regulators"
326 depends on MFD_LP873X && OF
327 help
328 This driver supports LP873X voltage regulator chips. LP873X
329 provides two step-down converters and two general-purpose LDO
330 voltage regulators. It supports software based voltage control
331 for different voltage domains
332
324config REGULATOR_LP8755 333config REGULATOR_LP8755
325 tristate "TI LP8755 High Performance PMU driver" 334 tristate "TI LP8755 High Performance PMU driver"
326 depends on I2C 335 depends on I2C
@@ -409,6 +418,7 @@ config REGULATOR_MAX8952
409config REGULATOR_MAX8973 418config REGULATOR_MAX8973
410 tristate "Maxim MAX8973 voltage regulator " 419 tristate "Maxim MAX8973 voltage regulator "
411 depends on I2C 420 depends on I2C
421 depends on THERMAL && THERMAL_OF
412 select REGMAP_I2C 422 select REGMAP_I2C
413 help 423 help
414 The MAXIM MAX8973 high-efficiency. three phase, DC-DC step-down 424 The MAXIM MAX8973 high-efficiency. three phase, DC-DC step-down
@@ -548,6 +558,13 @@ config REGULATOR_PV88060
548 Say y here to support the voltage regulators and convertors 558 Say y here to support the voltage regulators and convertors
549 PV88060 559 PV88060
550 560
561config REGULATOR_PV88080
562 tristate "Powerventure Semiconductor PV88080 regulator"
563 depends on I2C
564 select REGMAP_I2C
565 help
566 Say y here to support the buck convertors on PV88080
567
551config REGULATOR_PV88090 568config REGULATOR_PV88090
552 tristate "Powerventure Semiconductor PV88090 regulator" 569 tristate "Powerventure Semiconductor PV88090 regulator"
553 depends on I2C 570 depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 61bfbb9d4a0c..85a1d44a3939 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -42,11 +42,12 @@ obj-$(CONFIG_REGULATOR_LM363X) += lm363x-regulator.o
42obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 42obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
43obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o 43obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
44obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o 44obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o
45obj-$(CONFIG_REGULATOR_LP873X) += lp873x-regulator.o
45obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o 46obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o
46obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o 47obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o
47obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o 48obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o
48obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o 49obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o
49obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o 50obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
50obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 51obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
51obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o 52obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o
52obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 53obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
@@ -55,10 +56,10 @@ obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o
55obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 56obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
56obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o 57obj-$(CONFIG_REGULATOR_MAX8952) += max8952.o
57obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o 58obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o
58obj-$(CONFIG_REGULATOR_MAX8997) += max8997.o 59obj-$(CONFIG_REGULATOR_MAX8997) += max8997-regulator.o
59obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o 60obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
60obj-$(CONFIG_REGULATOR_MAX77686) += max77686-regulator.o 61obj-$(CONFIG_REGULATOR_MAX77686) += max77686-regulator.o
61obj-$(CONFIG_REGULATOR_MAX77693) += max77693.o 62obj-$(CONFIG_REGULATOR_MAX77693) += max77693-regulator.o
62obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o 63obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o
63obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 64obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
64obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 65obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
@@ -71,6 +72,7 @@ obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o
71obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o 72obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
72obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o 73obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
73obj-$(CONFIG_REGULATOR_PV88060) += pv88060-regulator.o 74obj-$(CONFIG_REGULATOR_PV88060) += pv88060-regulator.o
75obj-$(CONFIG_REGULATOR_PV88080) += pv88080-regulator.o
74obj-$(CONFIG_REGULATOR_PV88090) += pv88090-regulator.o 76obj-$(CONFIG_REGULATOR_PV88090) += pv88090-regulator.o
75obj-$(CONFIG_REGULATOR_PWM) += pwm-regulator.o 77obj-$(CONFIG_REGULATOR_PWM) += pwm-regulator.o
76obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o 78obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c
index 000d566e32a4..a1cd0d4f8257 100644
--- a/drivers/regulator/act8865-regulator.c
+++ b/drivers/regulator/act8865-regulator.c
@@ -139,6 +139,74 @@ struct act8865 {
139 int off_mask; 139 int off_mask;
140}; 140};
141 141
142static const struct regmap_range act8600_reg_ranges[] = {
143 regmap_reg_range(0x00, 0x01),
144 regmap_reg_range(0x10, 0x10),
145 regmap_reg_range(0x12, 0x12),
146 regmap_reg_range(0x20, 0x20),
147 regmap_reg_range(0x22, 0x22),
148 regmap_reg_range(0x30, 0x30),
149 regmap_reg_range(0x32, 0x32),
150 regmap_reg_range(0x40, 0x41),
151 regmap_reg_range(0x50, 0x51),
152 regmap_reg_range(0x60, 0x61),
153 regmap_reg_range(0x70, 0x71),
154 regmap_reg_range(0x80, 0x81),
155 regmap_reg_range(0x91, 0x91),
156 regmap_reg_range(0xA1, 0xA1),
157 regmap_reg_range(0xA8, 0xAA),
158 regmap_reg_range(0xB0, 0xB0),
159 regmap_reg_range(0xB2, 0xB2),
160 regmap_reg_range(0xC1, 0xC1),
161};
162
163static const struct regmap_range act8600_reg_ro_ranges[] = {
164 regmap_reg_range(0xAA, 0xAA),
165 regmap_reg_range(0xC1, 0xC1),
166};
167
168static const struct regmap_range act8600_reg_volatile_ranges[] = {
169 regmap_reg_range(0x00, 0x01),
170 regmap_reg_range(0x12, 0x12),
171 regmap_reg_range(0x22, 0x22),
172 regmap_reg_range(0x32, 0x32),
173 regmap_reg_range(0x41, 0x41),
174 regmap_reg_range(0x51, 0x51),
175 regmap_reg_range(0x61, 0x61),
176 regmap_reg_range(0x71, 0x71),
177 regmap_reg_range(0x81, 0x81),
178 regmap_reg_range(0xA8, 0xA8),
179 regmap_reg_range(0xAA, 0xAA),
180 regmap_reg_range(0xB0, 0xB0),
181 regmap_reg_range(0xC1, 0xC1),
182};
183
184static const struct regmap_access_table act8600_write_ranges_table = {
185 .yes_ranges = act8600_reg_ranges,
186 .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
187 .no_ranges = act8600_reg_ro_ranges,
188 .n_no_ranges = ARRAY_SIZE(act8600_reg_ro_ranges),
189};
190
191static const struct regmap_access_table act8600_read_ranges_table = {
192 .yes_ranges = act8600_reg_ranges,
193 .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges),
194};
195
196static const struct regmap_access_table act8600_volatile_ranges_table = {
197 .yes_ranges = act8600_reg_volatile_ranges,
198 .n_yes_ranges = ARRAY_SIZE(act8600_reg_volatile_ranges),
199};
200
201static const struct regmap_config act8600_regmap_config = {
202 .reg_bits = 8,
203 .val_bits = 8,
204 .max_register = 0xFF,
205 .wr_table = &act8600_write_ranges_table,
206 .rd_table = &act8600_read_ranges_table,
207 .volatile_table = &act8600_volatile_ranges_table,
208};
209
142static const struct regmap_config act8865_regmap_config = { 210static const struct regmap_config act8865_regmap_config = {
143 .reg_bits = 8, 211 .reg_bits = 8,
144 .val_bits = 8, 212 .val_bits = 8,
@@ -319,7 +387,6 @@ static struct of_regulator_match act8600_matches[] = {
319}; 387};
320 388
321static int act8865_pdata_from_dt(struct device *dev, 389static int act8865_pdata_from_dt(struct device *dev,
322 struct device_node **of_node,
323 struct act8865_platform_data *pdata, 390 struct act8865_platform_data *pdata,
324 unsigned long type) 391 unsigned long type)
325{ 392{
@@ -370,7 +437,7 @@ static int act8865_pdata_from_dt(struct device *dev,
370 regulator->id = i; 437 regulator->id = i;
371 regulator->name = matches[i].name; 438 regulator->name = matches[i].name;
372 regulator->init_data = matches[i].init_data; 439 regulator->init_data = matches[i].init_data;
373 of_node[i] = matches[i].of_node; 440 regulator->of_node = matches[i].of_node;
374 regulator++; 441 regulator++;
375 } 442 }
376 443
@@ -378,7 +445,6 @@ static int act8865_pdata_from_dt(struct device *dev,
378} 445}
379#else 446#else
380static inline int act8865_pdata_from_dt(struct device *dev, 447static inline int act8865_pdata_from_dt(struct device *dev,
381 struct device_node **of_node,
382 struct act8865_platform_data *pdata, 448 struct act8865_platform_data *pdata,
383 unsigned long type) 449 unsigned long type)
384{ 450{
@@ -386,8 +452,8 @@ static inline int act8865_pdata_from_dt(struct device *dev,
386} 452}
387#endif 453#endif
388 454
389static struct regulator_init_data 455static struct act8865_regulator_data *act8865_get_regulator_data(
390*act8865_get_init_data(int id, struct act8865_platform_data *pdata) 456 int id, struct act8865_platform_data *pdata)
391{ 457{
392 int i; 458 int i;
393 459
@@ -396,7 +462,7 @@ static struct regulator_init_data
396 462
397 for (i = 0; i < pdata->num_regulators; i++) { 463 for (i = 0; i < pdata->num_regulators; i++) {
398 if (pdata->regulators[i].id == id) 464 if (pdata->regulators[i].id == id)
399 return pdata->regulators[i].init_data; 465 return &pdata->regulators[i];
400 } 466 }
401 467
402 return NULL; 468 return NULL;
@@ -418,9 +484,9 @@ static int act8865_pmic_probe(struct i2c_client *client,
418 const struct regulator_desc *regulators; 484 const struct regulator_desc *regulators;
419 struct act8865_platform_data pdata_of, *pdata; 485 struct act8865_platform_data pdata_of, *pdata;
420 struct device *dev = &client->dev; 486 struct device *dev = &client->dev;
421 struct device_node **of_node;
422 int i, ret, num_regulators; 487 int i, ret, num_regulators;
423 struct act8865 *act8865; 488 struct act8865 *act8865;
489 const struct regmap_config *regmap_config;
424 unsigned long type; 490 unsigned long type;
425 int off_reg, off_mask; 491 int off_reg, off_mask;
426 int voltage_select = 0; 492 int voltage_select = 0;
@@ -447,12 +513,14 @@ static int act8865_pmic_probe(struct i2c_client *client,
447 case ACT8600: 513 case ACT8600:
448 regulators = act8600_regulators; 514 regulators = act8600_regulators;
449 num_regulators = ARRAY_SIZE(act8600_regulators); 515 num_regulators = ARRAY_SIZE(act8600_regulators);
516 regmap_config = &act8600_regmap_config;
450 off_reg = -1; 517 off_reg = -1;
451 off_mask = -1; 518 off_mask = -1;
452 break; 519 break;
453 case ACT8846: 520 case ACT8846:
454 regulators = act8846_regulators; 521 regulators = act8846_regulators;
455 num_regulators = ARRAY_SIZE(act8846_regulators); 522 num_regulators = ARRAY_SIZE(act8846_regulators);
523 regmap_config = &act8865_regmap_config;
456 off_reg = ACT8846_GLB_OFF_CTRL; 524 off_reg = ACT8846_GLB_OFF_CTRL;
457 off_mask = ACT8846_OFF_SYSMASK; 525 off_mask = ACT8846_OFF_SYSMASK;
458 break; 526 break;
@@ -464,6 +532,7 @@ static int act8865_pmic_probe(struct i2c_client *client,
464 regulators = act8865_regulators; 532 regulators = act8865_regulators;
465 num_regulators = ARRAY_SIZE(act8865_regulators); 533 num_regulators = ARRAY_SIZE(act8865_regulators);
466 } 534 }
535 regmap_config = &act8865_regmap_config;
467 off_reg = ACT8865_SYS_CTRL; 536 off_reg = ACT8865_SYS_CTRL;
468 off_mask = ACT8865_MSTROFF; 537 off_mask = ACT8865_MSTROFF;
469 break; 538 break;
@@ -472,34 +541,22 @@ static int act8865_pmic_probe(struct i2c_client *client,
472 return -EINVAL; 541 return -EINVAL;
473 } 542 }
474 543
475 of_node = devm_kzalloc(dev, sizeof(struct device_node *) *
476 num_regulators, GFP_KERNEL);
477 if (!of_node)
478 return -ENOMEM;
479
480 if (dev->of_node && !pdata) { 544 if (dev->of_node && !pdata) {
481 ret = act8865_pdata_from_dt(dev, of_node, &pdata_of, type); 545 ret = act8865_pdata_from_dt(dev, &pdata_of, type);
482 if (ret < 0) 546 if (ret < 0)
483 return ret; 547 return ret;
484 548
485 pdata = &pdata_of; 549 pdata = &pdata_of;
486 } 550 }
487 551
488 if (pdata->num_regulators > num_regulators) {
489 dev_err(dev, "too many regulators: %d\n",
490 pdata->num_regulators);
491 return -EINVAL;
492 }
493
494 act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); 552 act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL);
495 if (!act8865) 553 if (!act8865)
496 return -ENOMEM; 554 return -ENOMEM;
497 555
498 act8865->regmap = devm_regmap_init_i2c(client, &act8865_regmap_config); 556 act8865->regmap = devm_regmap_init_i2c(client, regmap_config);
499 if (IS_ERR(act8865->regmap)) { 557 if (IS_ERR(act8865->regmap)) {
500 ret = PTR_ERR(act8865->regmap); 558 ret = PTR_ERR(act8865->regmap);
501 dev_err(&client->dev, "Failed to allocate register map: %d\n", 559 dev_err(dev, "Failed to allocate register map: %d\n", ret);
502 ret);
503 return ret; 560 return ret;
504 } 561 }
505 562
@@ -518,15 +575,20 @@ static int act8865_pmic_probe(struct i2c_client *client,
518 for (i = 0; i < num_regulators; i++) { 575 for (i = 0; i < num_regulators; i++) {
519 const struct regulator_desc *desc = &regulators[i]; 576 const struct regulator_desc *desc = &regulators[i];
520 struct regulator_config config = { }; 577 struct regulator_config config = { };
578 struct act8865_regulator_data *rdata;
521 struct regulator_dev *rdev; 579 struct regulator_dev *rdev;
522 580
523 config.dev = dev; 581 config.dev = dev;
524 config.init_data = act8865_get_init_data(desc->id, pdata);
525 config.of_node = of_node[i];
526 config.driver_data = act8865; 582 config.driver_data = act8865;
527 config.regmap = act8865->regmap; 583 config.regmap = act8865->regmap;
528 584
529 rdev = devm_regulator_register(&client->dev, desc, &config); 585 rdata = act8865_get_regulator_data(desc->id, pdata);
586 if (rdata) {
587 config.init_data = rdata->init_data;
588 config.of_node = rdata->of_node;
589 }
590
591 rdev = devm_regulator_register(dev, desc, &config);
530 if (IS_ERR(rdev)) { 592 if (IS_ERR(rdev)) {
531 dev_err(dev, "failed to register %s\n", desc->name); 593 dev_err(dev, "failed to register %s\n", desc->name);
532 return PTR_ERR(rdev); 594 return PTR_ERR(rdev);
@@ -534,7 +596,6 @@ static int act8865_pmic_probe(struct i2c_client *client,
534 } 596 }
535 597
536 i2c_set_clientdata(client, act8865); 598 i2c_set_clientdata(client, act8865);
537 devm_kfree(dev, of_node);
538 599
539 return 0; 600 return 0;
540} 601}
diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c
index 8b046eec6ae0..66337e12719b 100644
--- a/drivers/regulator/as3722-regulator.c
+++ b/drivers/regulator/as3722-regulator.c
@@ -372,7 +372,7 @@ static int as3722_ldo_set_current_limit(struct regulator_dev *rdev,
372 AS3722_LDO_ILIMIT_MASK, reg); 372 AS3722_LDO_ILIMIT_MASK, reg);
373} 373}
374 374
375static struct regulator_ops as3722_ldo0_ops = { 375static const struct regulator_ops as3722_ldo0_ops = {
376 .is_enabled = regulator_is_enabled_regmap, 376 .is_enabled = regulator_is_enabled_regmap,
377 .enable = regulator_enable_regmap, 377 .enable = regulator_enable_regmap,
378 .disable = regulator_disable_regmap, 378 .disable = regulator_disable_regmap,
@@ -383,7 +383,7 @@ static struct regulator_ops as3722_ldo0_ops = {
383 .set_current_limit = as3722_ldo_set_current_limit, 383 .set_current_limit = as3722_ldo_set_current_limit,
384}; 384};
385 385
386static struct regulator_ops as3722_ldo0_extcntrl_ops = { 386static const struct regulator_ops as3722_ldo0_extcntrl_ops = {
387 .list_voltage = regulator_list_voltage_linear, 387 .list_voltage = regulator_list_voltage_linear,
388 .get_voltage_sel = regulator_get_voltage_sel_regmap, 388 .get_voltage_sel = regulator_get_voltage_sel_regmap,
389 .set_voltage_sel = regulator_set_voltage_sel_regmap, 389 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -415,7 +415,7 @@ static int as3722_ldo3_get_current_limit(struct regulator_dev *rdev)
415 return 150000; 415 return 150000;
416} 416}
417 417
418static struct regulator_ops as3722_ldo3_ops = { 418static const struct regulator_ops as3722_ldo3_ops = {
419 .is_enabled = regulator_is_enabled_regmap, 419 .is_enabled = regulator_is_enabled_regmap,
420 .enable = regulator_enable_regmap, 420 .enable = regulator_enable_regmap,
421 .disable = regulator_disable_regmap, 421 .disable = regulator_disable_regmap,
@@ -425,20 +425,45 @@ static struct regulator_ops as3722_ldo3_ops = {
425 .get_current_limit = as3722_ldo3_get_current_limit, 425 .get_current_limit = as3722_ldo3_get_current_limit,
426}; 426};
427 427
428static struct regulator_ops as3722_ldo3_extcntrl_ops = { 428static const struct regulator_ops as3722_ldo3_extcntrl_ops = {
429 .list_voltage = regulator_list_voltage_linear, 429 .list_voltage = regulator_list_voltage_linear,
430 .get_voltage_sel = regulator_get_voltage_sel_regmap, 430 .get_voltage_sel = regulator_get_voltage_sel_regmap,
431 .set_voltage_sel = regulator_set_voltage_sel_regmap, 431 .set_voltage_sel = regulator_set_voltage_sel_regmap,
432 .get_current_limit = as3722_ldo3_get_current_limit, 432 .get_current_limit = as3722_ldo3_get_current_limit,
433}; 433};
434 434
435static const struct regulator_ops as3722_ldo6_ops = {
436 .is_enabled = regulator_is_enabled_regmap,
437 .enable = regulator_enable_regmap,
438 .disable = regulator_disable_regmap,
439 .map_voltage = regulator_map_voltage_linear_range,
440 .set_voltage_sel = regulator_set_voltage_sel_regmap,
441 .get_voltage_sel = regulator_get_voltage_sel_regmap,
442 .list_voltage = regulator_list_voltage_linear_range,
443 .get_current_limit = as3722_ldo_get_current_limit,
444 .set_current_limit = as3722_ldo_set_current_limit,
445 .get_bypass = regulator_get_bypass_regmap,
446 .set_bypass = regulator_set_bypass_regmap,
447};
448
449static const struct regulator_ops as3722_ldo6_extcntrl_ops = {
450 .map_voltage = regulator_map_voltage_linear_range,
451 .set_voltage_sel = regulator_set_voltage_sel_regmap,
452 .get_voltage_sel = regulator_get_voltage_sel_regmap,
453 .list_voltage = regulator_list_voltage_linear_range,
454 .get_current_limit = as3722_ldo_get_current_limit,
455 .set_current_limit = as3722_ldo_set_current_limit,
456 .get_bypass = regulator_get_bypass_regmap,
457 .set_bypass = regulator_set_bypass_regmap,
458};
459
435static const struct regulator_linear_range as3722_ldo_ranges[] = { 460static const struct regulator_linear_range as3722_ldo_ranges[] = {
436 REGULATOR_LINEAR_RANGE(0, 0x00, 0x00, 0), 461 REGULATOR_LINEAR_RANGE(0, 0x00, 0x00, 0),
437 REGULATOR_LINEAR_RANGE(825000, 0x01, 0x24, 25000), 462 REGULATOR_LINEAR_RANGE(825000, 0x01, 0x24, 25000),
438 REGULATOR_LINEAR_RANGE(1725000, 0x40, 0x7F, 25000), 463 REGULATOR_LINEAR_RANGE(1725000, 0x40, 0x7F, 25000),
439}; 464};
440 465
441static struct regulator_ops as3722_ldo_ops = { 466static const struct regulator_ops as3722_ldo_ops = {
442 .is_enabled = regulator_is_enabled_regmap, 467 .is_enabled = regulator_is_enabled_regmap,
443 .enable = regulator_enable_regmap, 468 .enable = regulator_enable_regmap,
444 .disable = regulator_disable_regmap, 469 .disable = regulator_disable_regmap,
@@ -450,7 +475,7 @@ static struct regulator_ops as3722_ldo_ops = {
450 .set_current_limit = as3722_ldo_set_current_limit, 475 .set_current_limit = as3722_ldo_set_current_limit,
451}; 476};
452 477
453static struct regulator_ops as3722_ldo_extcntrl_ops = { 478static const struct regulator_ops as3722_ldo_extcntrl_ops = {
454 .map_voltage = regulator_map_voltage_linear_range, 479 .map_voltage = regulator_map_voltage_linear_range,
455 .set_voltage_sel = regulator_set_voltage_sel_regmap, 480 .set_voltage_sel = regulator_set_voltage_sel_regmap,
456 .get_voltage_sel = regulator_get_voltage_sel_regmap, 481 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -616,7 +641,7 @@ static const struct regulator_linear_range as3722_sd2345_ranges[] = {
616 REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7F, 50000), 641 REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7F, 50000),
617}; 642};
618 643
619static struct regulator_ops as3722_sd016_ops = { 644static const struct regulator_ops as3722_sd016_ops = {
620 .is_enabled = regulator_is_enabled_regmap, 645 .is_enabled = regulator_is_enabled_regmap,
621 .enable = regulator_enable_regmap, 646 .enable = regulator_enable_regmap,
622 .disable = regulator_disable_regmap, 647 .disable = regulator_disable_regmap,
@@ -630,7 +655,7 @@ static struct regulator_ops as3722_sd016_ops = {
630 .set_mode = as3722_sd_set_mode, 655 .set_mode = as3722_sd_set_mode,
631}; 656};
632 657
633static struct regulator_ops as3722_sd016_extcntrl_ops = { 658static const struct regulator_ops as3722_sd016_extcntrl_ops = {
634 .list_voltage = regulator_list_voltage_linear, 659 .list_voltage = regulator_list_voltage_linear,
635 .map_voltage = regulator_map_voltage_linear, 660 .map_voltage = regulator_map_voltage_linear,
636 .get_voltage_sel = regulator_get_voltage_sel_regmap, 661 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -641,7 +666,7 @@ static struct regulator_ops as3722_sd016_extcntrl_ops = {
641 .set_mode = as3722_sd_set_mode, 666 .set_mode = as3722_sd_set_mode,
642}; 667};
643 668
644static struct regulator_ops as3722_sd2345_ops = { 669static const struct regulator_ops as3722_sd2345_ops = {
645 .is_enabled = regulator_is_enabled_regmap, 670 .is_enabled = regulator_is_enabled_regmap,
646 .enable = regulator_enable_regmap, 671 .enable = regulator_enable_regmap,
647 .disable = regulator_disable_regmap, 672 .disable = regulator_disable_regmap,
@@ -653,7 +678,7 @@ static struct regulator_ops as3722_sd2345_ops = {
653 .set_mode = as3722_sd_set_mode, 678 .set_mode = as3722_sd_set_mode,
654}; 679};
655 680
656static struct regulator_ops as3722_sd2345_extcntrl_ops = { 681static const struct regulator_ops as3722_sd2345_extcntrl_ops = {
657 .list_voltage = regulator_list_voltage_linear_range, 682 .list_voltage = regulator_list_voltage_linear_range,
658 .map_voltage = regulator_map_voltage_linear_range, 683 .map_voltage = regulator_map_voltage_linear_range,
659 .set_voltage_sel = regulator_set_voltage_sel_regmap, 684 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -760,7 +785,7 @@ static int as3722_regulator_probe(struct platform_device *pdev)
760 struct as3722_regulator_config_data *reg_config; 785 struct as3722_regulator_config_data *reg_config;
761 struct regulator_dev *rdev; 786 struct regulator_dev *rdev;
762 struct regulator_config config = { }; 787 struct regulator_config config = { };
763 struct regulator_ops *ops; 788 const struct regulator_ops *ops;
764 int id; 789 int id;
765 int ret; 790 int ret;
766 791
@@ -829,6 +854,24 @@ static int as3722_regulator_probe(struct platform_device *pdev)
829 } 854 }
830 } 855 }
831 break; 856 break;
857 case AS3722_REGULATOR_ID_LDO6:
858 if (reg_config->ext_control)
859 ops = &as3722_ldo6_extcntrl_ops;
860 else
861 ops = &as3722_ldo6_ops;
862 as3722_regs->desc[id].enable_time = 500;
863 as3722_regs->desc[id].bypass_reg =
864 AS3722_LDO6_VOLTAGE_REG;
865 as3722_regs->desc[id].bypass_mask =
866 AS3722_LDO_VSEL_MASK;
867 as3722_regs->desc[id].bypass_val_on =
868 AS3722_LDO6_VSEL_BYPASS;
869 as3722_regs->desc[id].bypass_val_off =
870 AS3722_LDO6_VSEL_BYPASS;
871 as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges;
872 as3722_regs->desc[id].n_linear_ranges =
873 ARRAY_SIZE(as3722_ldo_ranges);
874 break;
832 case AS3722_REGULATOR_ID_SD0: 875 case AS3722_REGULATOR_ID_SD0:
833 case AS3722_REGULATOR_ID_SD1: 876 case AS3722_REGULATOR_ID_SD1:
834 case AS3722_REGULATOR_ID_SD6: 877 case AS3722_REGULATOR_ID_SD6:
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e0b764284773..ec8184d53f13 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -132,6 +132,19 @@ static bool have_full_constraints(void)
132 return has_full_constraints || of_have_populated_dt(); 132 return has_full_constraints || of_have_populated_dt();
133} 133}
134 134
135static bool regulator_ops_is_valid(struct regulator_dev *rdev, int ops)
136{
137 if (!rdev->constraints) {
138 rdev_err(rdev, "no constraints\n");
139 return false;
140 }
141
142 if (rdev->constraints->valid_ops_mask & ops)
143 return true;
144
145 return false;
146}
147
135static inline struct regulator_dev *rdev_get_supply(struct regulator_dev *rdev) 148static inline struct regulator_dev *rdev_get_supply(struct regulator_dev *rdev)
136{ 149{
137 if (rdev && rdev->supply) 150 if (rdev && rdev->supply)
@@ -198,28 +211,13 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp
198 return regnode; 211 return regnode;
199} 212}
200 213
201static int _regulator_can_change_status(struct regulator_dev *rdev)
202{
203 if (!rdev->constraints)
204 return 0;
205
206 if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
207 return 1;
208 else
209 return 0;
210}
211
212/* Platform voltage constraint check */ 214/* Platform voltage constraint check */
213static int regulator_check_voltage(struct regulator_dev *rdev, 215static int regulator_check_voltage(struct regulator_dev *rdev,
214 int *min_uV, int *max_uV) 216 int *min_uV, int *max_uV)
215{ 217{
216 BUG_ON(*min_uV > *max_uV); 218 BUG_ON(*min_uV > *max_uV);
217 219
218 if (!rdev->constraints) { 220 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
219 rdev_err(rdev, "no constraints\n");
220 return -ENODEV;
221 }
222 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
223 rdev_err(rdev, "voltage operation not allowed\n"); 221 rdev_err(rdev, "voltage operation not allowed\n");
224 return -EPERM; 222 return -EPERM;
225 } 223 }
@@ -275,11 +273,7 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
275{ 273{
276 BUG_ON(*min_uA > *max_uA); 274 BUG_ON(*min_uA > *max_uA);
277 275
278 if (!rdev->constraints) { 276 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_CURRENT)) {
279 rdev_err(rdev, "no constraints\n");
280 return -ENODEV;
281 }
282 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
283 rdev_err(rdev, "current operation not allowed\n"); 277 rdev_err(rdev, "current operation not allowed\n");
284 return -EPERM; 278 return -EPERM;
285 } 279 }
@@ -312,11 +306,7 @@ static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode)
312 return -EINVAL; 306 return -EINVAL;
313 } 307 }
314 308
315 if (!rdev->constraints) { 309 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_MODE)) {
316 rdev_err(rdev, "no constraints\n");
317 return -ENODEV;
318 }
319 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
320 rdev_err(rdev, "mode operation not allowed\n"); 310 rdev_err(rdev, "mode operation not allowed\n");
321 return -EPERM; 311 return -EPERM;
322 } 312 }
@@ -333,20 +323,6 @@ static int regulator_mode_constrain(struct regulator_dev *rdev, int *mode)
333 return -EINVAL; 323 return -EINVAL;
334} 324}
335 325
336/* dynamic regulator mode switching constraint check */
337static int regulator_check_drms(struct regulator_dev *rdev)
338{
339 if (!rdev->constraints) {
340 rdev_err(rdev, "no constraints\n");
341 return -ENODEV;
342 }
343 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
344 rdev_dbg(rdev, "drms operation not allowed\n");
345 return -EPERM;
346 }
347 return 0;
348}
349
350static ssize_t regulator_uV_show(struct device *dev, 326static ssize_t regulator_uV_show(struct device *dev,
351 struct device_attribute *attr, char *buf) 327 struct device_attribute *attr, char *buf)
352{ 328{
@@ -692,8 +668,7 @@ static int drms_uA_update(struct regulator_dev *rdev)
692 * first check to see if we can set modes at all, otherwise just 668 * first check to see if we can set modes at all, otherwise just
693 * tell the consumer everything is OK. 669 * tell the consumer everything is OK.
694 */ 670 */
695 err = regulator_check_drms(rdev); 671 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
696 if (err < 0)
697 return 0; 672 return 0;
698 673
699 if (!rdev->desc->ops->get_optimum_mode && 674 if (!rdev->desc->ops->get_optimum_mode &&
@@ -808,8 +783,6 @@ static int suspend_set_state(struct regulator_dev *rdev,
808/* locks held by caller */ 783/* locks held by caller */
809static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) 784static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
810{ 785{
811 lockdep_assert_held_once(&rdev->mutex);
812
813 if (!rdev->constraints) 786 if (!rdev->constraints)
814 return -EINVAL; 787 return -EINVAL;
815 788
@@ -893,7 +866,7 @@ static void print_constraints(struct regulator_dev *rdev)
893 rdev_dbg(rdev, "%s\n", buf); 866 rdev_dbg(rdev, "%s\n", buf);
894 867
895 if ((constraints->min_uV != constraints->max_uV) && 868 if ((constraints->min_uV != constraints->max_uV) &&
896 !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) 869 !regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE))
897 rdev_warn(rdev, 870 rdev_warn(rdev,
898 "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n"); 871 "Voltage range but no REGULATOR_CHANGE_VOLTAGE\n");
899} 872}
@@ -906,7 +879,8 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
906 879
907 /* do we need to apply the constraint voltage */ 880 /* do we need to apply the constraint voltage */
908 if (rdev->constraints->apply_uV && 881 if (rdev->constraints->apply_uV &&
909 rdev->constraints->min_uV == rdev->constraints->max_uV) { 882 rdev->constraints->min_uV && rdev->constraints->max_uV) {
883 int target_min, target_max;
910 int current_uV = _regulator_get_voltage(rdev); 884 int current_uV = _regulator_get_voltage(rdev);
911 if (current_uV < 0) { 885 if (current_uV < 0) {
912 rdev_err(rdev, 886 rdev_err(rdev,
@@ -914,15 +888,34 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
914 current_uV); 888 current_uV);
915 return current_uV; 889 return current_uV;
916 } 890 }
917 if (current_uV < rdev->constraints->min_uV || 891
918 current_uV > rdev->constraints->max_uV) { 892 /*
893 * If we're below the minimum voltage move up to the
894 * minimum voltage, if we're above the maximum voltage
895 * then move down to the maximum.
896 */
897 target_min = current_uV;
898 target_max = current_uV;
899
900 if (current_uV < rdev->constraints->min_uV) {
901 target_min = rdev->constraints->min_uV;
902 target_max = rdev->constraints->min_uV;
903 }
904
905 if (current_uV > rdev->constraints->max_uV) {
906 target_min = rdev->constraints->max_uV;
907 target_max = rdev->constraints->max_uV;
908 }
909
910 if (target_min != current_uV || target_max != current_uV) {
911 rdev_info(rdev, "Bringing %duV into %d-%duV\n",
912 current_uV, target_min, target_max);
919 ret = _regulator_do_set_voltage( 913 ret = _regulator_do_set_voltage(
920 rdev, rdev->constraints->min_uV, 914 rdev, target_min, target_max);
921 rdev->constraints->max_uV);
922 if (ret < 0) { 915 if (ret < 0) {
923 rdev_err(rdev, 916 rdev_err(rdev,
924 "failed to apply %duV constraint(%d)\n", 917 "failed to apply %d-%duV constraint(%d)\n",
925 rdev->constraints->min_uV, ret); 918 target_min, target_max, ret);
926 return ret; 919 return ret;
927 } 920 }
928 } 921 }
@@ -1150,17 +1143,6 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1150 } 1143 }
1151 } 1144 }
1152 1145
1153 if (rdev->constraints->active_discharge && ops->set_active_discharge) {
1154 bool ad_state = (rdev->constraints->active_discharge ==
1155 REGULATOR_ACTIVE_DISCHARGE_ENABLE) ? true : false;
1156
1157 ret = ops->set_active_discharge(rdev, ad_state);
1158 if (ret < 0) {
1159 rdev_err(rdev, "failed to set active discharge\n");
1160 return ret;
1161 }
1162 }
1163
1164 print_constraints(rdev); 1146 print_constraints(rdev);
1165 return 0; 1147 return 0;
1166} 1148}
@@ -1272,6 +1254,55 @@ static void unset_regulator_supplies(struct regulator_dev *rdev)
1272 } 1254 }
1273} 1255}
1274 1256
1257#ifdef CONFIG_DEBUG_FS
1258static ssize_t constraint_flags_read_file(struct file *file,
1259 char __user *user_buf,
1260 size_t count, loff_t *ppos)
1261{
1262 const struct regulator *regulator = file->private_data;
1263 const struct regulation_constraints *c = regulator->rdev->constraints;
1264 char *buf;
1265 ssize_t ret;
1266
1267 if (!c)
1268 return 0;
1269
1270 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1271 if (!buf)
1272 return -ENOMEM;
1273
1274 ret = snprintf(buf, PAGE_SIZE,
1275 "always_on: %u\n"
1276 "boot_on: %u\n"
1277 "apply_uV: %u\n"
1278 "ramp_disable: %u\n"
1279 "soft_start: %u\n"
1280 "pull_down: %u\n"
1281 "over_current_protection: %u\n",
1282 c->always_on,
1283 c->boot_on,
1284 c->apply_uV,
1285 c->ramp_disable,
1286 c->soft_start,
1287 c->pull_down,
1288 c->over_current_protection);
1289
1290 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1291 kfree(buf);
1292
1293 return ret;
1294}
1295
1296#endif
1297
1298static const struct file_operations constraint_flags_fops = {
1299#ifdef CONFIG_DEBUG_FS
1300 .open = simple_open,
1301 .read = constraint_flags_read_file,
1302 .llseek = default_llseek,
1303#endif
1304};
1305
1275#define REG_STR_SIZE 64 1306#define REG_STR_SIZE 64
1276 1307
1277static struct regulator *create_regulator(struct regulator_dev *rdev, 1308static struct regulator *create_regulator(struct regulator_dev *rdev,
@@ -1327,6 +1358,9 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1327 &regulator->min_uV); 1358 &regulator->min_uV);
1328 debugfs_create_u32("max_uV", 0444, regulator->debugfs, 1359 debugfs_create_u32("max_uV", 0444, regulator->debugfs,
1329 &regulator->max_uV); 1360 &regulator->max_uV);
1361 debugfs_create_file("constraint_flags", 0444,
1362 regulator->debugfs, regulator,
1363 &constraint_flags_fops);
1330 } 1364 }
1331 1365
1332 /* 1366 /*
@@ -1334,7 +1368,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1334 * it is then we don't need to do nearly so much work for 1368 * it is then we don't need to do nearly so much work for
1335 * enable/disable calls. 1369 * enable/disable calls.
1336 */ 1370 */
1337 if (!_regulator_can_change_status(rdev) && 1371 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS) &&
1338 _regulator_is_enabled(rdev)) 1372 _regulator_is_enabled(rdev))
1339 regulator->always_on = true; 1373 regulator->always_on = true;
1340 1374
@@ -1532,10 +1566,11 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
1532 } 1566 }
1533 1567
1534 /* Cascade always-on state to supply */ 1568 /* Cascade always-on state to supply */
1535 if (_regulator_is_enabled(rdev) && rdev->supply) { 1569 if (_regulator_is_enabled(rdev)) {
1536 ret = regulator_enable(rdev->supply); 1570 ret = regulator_enable(rdev->supply);
1537 if (ret < 0) { 1571 if (ret < 0) {
1538 _regulator_put(rdev->supply); 1572 _regulator_put(rdev->supply);
1573 rdev->supply = NULL;
1539 return ret; 1574 return ret;
1540 } 1575 }
1541 } 1576 }
@@ -2111,15 +2146,15 @@ static int _regulator_enable(struct regulator_dev *rdev)
2111 lockdep_assert_held_once(&rdev->mutex); 2146 lockdep_assert_held_once(&rdev->mutex);
2112 2147
2113 /* check voltage and requested load before enabling */ 2148 /* check voltage and requested load before enabling */
2114 if (rdev->constraints && 2149 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
2115 (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
2116 drms_uA_update(rdev); 2150 drms_uA_update(rdev);
2117 2151
2118 if (rdev->use_count == 0) { 2152 if (rdev->use_count == 0) {
2119 /* The regulator may on if it's not switchable or left on */ 2153 /* The regulator may on if it's not switchable or left on */
2120 ret = _regulator_is_enabled(rdev); 2154 ret = _regulator_is_enabled(rdev);
2121 if (ret == -EINVAL || ret == 0) { 2155 if (ret == -EINVAL || ret == 0) {
2122 if (!_regulator_can_change_status(rdev)) 2156 if (!regulator_ops_is_valid(rdev,
2157 REGULATOR_CHANGE_STATUS))
2123 return -EPERM; 2158 return -EPERM;
2124 2159
2125 ret = _regulator_do_enable(rdev); 2160 ret = _regulator_do_enable(rdev);
@@ -2221,7 +2256,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
2221 (rdev->constraints && !rdev->constraints->always_on)) { 2256 (rdev->constraints && !rdev->constraints->always_on)) {
2222 2257
2223 /* we are last user */ 2258 /* we are last user */
2224 if (_regulator_can_change_status(rdev)) { 2259 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS)) {
2225 ret = _notifier_call_chain(rdev, 2260 ret = _notifier_call_chain(rdev,
2226 REGULATOR_EVENT_PRE_DISABLE, 2261 REGULATOR_EVENT_PRE_DISABLE,
2227 NULL); 2262 NULL);
@@ -2242,10 +2277,7 @@ static int _regulator_disable(struct regulator_dev *rdev)
2242 2277
2243 rdev->use_count = 0; 2278 rdev->use_count = 0;
2244 } else if (rdev->use_count > 1) { 2279 } else if (rdev->use_count > 1) {
2245 2280 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS))
2246 if (rdev->constraints &&
2247 (rdev->constraints->valid_ops_mask &
2248 REGULATOR_CHANGE_DRMS))
2249 drms_uA_update(rdev); 2281 drms_uA_update(rdev);
2250 2282
2251 rdev->use_count--; 2283 rdev->use_count--;
@@ -2489,8 +2521,7 @@ int regulator_can_change_voltage(struct regulator *regulator)
2489{ 2521{
2490 struct regulator_dev *rdev = regulator->rdev; 2522 struct regulator_dev *rdev = regulator->rdev;
2491 2523
2492 if (rdev->constraints && 2524 if (regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
2493 (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
2494 if (rdev->desc->n_voltages - rdev->desc->linear_min_sel > 1) 2525 if (rdev->desc->n_voltages - rdev->desc->linear_min_sel > 1)
2495 return 1; 2526 return 1;
2496 2527
@@ -2644,7 +2675,7 @@ int regulator_is_supported_voltage(struct regulator *regulator,
2644 int i, voltages, ret; 2675 int i, voltages, ret;
2645 2676
2646 /* If we can't change voltage check the current voltage */ 2677 /* If we can't change voltage check the current voltage */
2647 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 2678 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
2648 ret = regulator_get_voltage(regulator); 2679 ret = regulator_get_voltage(regulator);
2649 if (ret >= 0) 2680 if (ret >= 0)
2650 return min_uV <= ret && ret <= max_uV; 2681 return min_uV <= ret && ret <= max_uV;
@@ -2850,7 +2881,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
2850 * return successfully even though the regulator does not support 2881 * return successfully even though the regulator does not support
2851 * changing the voltage. 2882 * changing the voltage.
2852 */ 2883 */
2853 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 2884 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
2854 current_uV = _regulator_get_voltage(rdev); 2885 current_uV = _regulator_get_voltage(rdev);
2855 if (min_uV <= current_uV && current_uV <= max_uV) { 2886 if (min_uV <= current_uV && current_uV <= max_uV) {
2856 regulator->min_uV = min_uV; 2887 regulator->min_uV = min_uV;
@@ -3109,6 +3140,23 @@ EXPORT_SYMBOL_GPL(regulator_sync_voltage);
3109static int _regulator_get_voltage(struct regulator_dev *rdev) 3140static int _regulator_get_voltage(struct regulator_dev *rdev)
3110{ 3141{
3111 int sel, ret; 3142 int sel, ret;
3143 bool bypassed;
3144
3145 if (rdev->desc->ops->get_bypass) {
3146 ret = rdev->desc->ops->get_bypass(rdev, &bypassed);
3147 if (ret < 0)
3148 return ret;
3149 if (bypassed) {
3150 /* if bypassed the regulator must have a supply */
3151 if (!rdev->supply) {
3152 rdev_err(rdev,
3153 "bypassed regulator has no supply!\n");
3154 return -EPROBE_DEFER;
3155 }
3156
3157 return _regulator_get_voltage(rdev->supply->rdev);
3158 }
3159 }
3112 3160
3113 if (rdev->desc->ops->get_voltage_sel) { 3161 if (rdev->desc->ops->get_voltage_sel) {
3114 sel = rdev->desc->ops->get_voltage_sel(rdev); 3162 sel = rdev->desc->ops->get_voltage_sel(rdev);
@@ -3365,8 +3413,7 @@ int regulator_allow_bypass(struct regulator *regulator, bool enable)
3365 if (!rdev->desc->ops->set_bypass) 3413 if (!rdev->desc->ops->set_bypass)
3366 return 0; 3414 return 0;
3367 3415
3368 if (rdev->constraints && 3416 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_BYPASS))
3369 !(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_BYPASS))
3370 return 0; 3417 return 0;
3371 3418
3372 mutex_lock(&rdev->mutex); 3419 mutex_lock(&rdev->mutex);
@@ -3840,6 +3887,16 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
3840 &rdev->bypass_count); 3887 &rdev->bypass_count);
3841} 3888}
3842 3889
3890static int regulator_register_resolve_supply(struct device *dev, void *data)
3891{
3892 struct regulator_dev *rdev = dev_to_rdev(dev);
3893
3894 if (regulator_resolve_supply(rdev))
3895 rdev_dbg(rdev, "unable to resolve supply\n");
3896
3897 return 0;
3898}
3899
3843/** 3900/**
3844 * regulator_register - register regulator 3901 * regulator_register - register regulator
3845 * @regulator_desc: regulator to register 3902 * @regulator_desc: regulator to register
@@ -3911,8 +3968,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
3911 rdev->dev.of_node = of_node_get(config->of_node); 3968 rdev->dev.of_node = of_node_get(config->of_node);
3912 } 3969 }
3913 3970
3914 mutex_lock(&regulator_list_mutex);
3915
3916 mutex_init(&rdev->mutex); 3971 mutex_init(&rdev->mutex);
3917 rdev->reg_data = config->driver_data; 3972 rdev->reg_data = config->driver_data;
3918 rdev->owner = regulator_desc->owner; 3973 rdev->owner = regulator_desc->owner;
@@ -3937,7 +3992,9 @@ regulator_register(const struct regulator_desc *regulator_desc,
3937 3992
3938 if ((config->ena_gpio || config->ena_gpio_initialized) && 3993 if ((config->ena_gpio || config->ena_gpio_initialized) &&
3939 gpio_is_valid(config->ena_gpio)) { 3994 gpio_is_valid(config->ena_gpio)) {
3995 mutex_lock(&regulator_list_mutex);
3940 ret = regulator_ena_gpio_request(rdev, config); 3996 ret = regulator_ena_gpio_request(rdev, config);
3997 mutex_unlock(&regulator_list_mutex);
3941 if (ret != 0) { 3998 if (ret != 0) {
3942 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", 3999 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
3943 config->ena_gpio, ret); 4000 config->ena_gpio, ret);
@@ -3950,63 +4007,73 @@ regulator_register(const struct regulator_desc *regulator_desc,
3950 rdev->dev.parent = dev; 4007 rdev->dev.parent = dev;
3951 dev_set_name(&rdev->dev, "regulator.%lu", 4008 dev_set_name(&rdev->dev, "regulator.%lu",
3952 (unsigned long) atomic_inc_return(&regulator_no)); 4009 (unsigned long) atomic_inc_return(&regulator_no));
3953 ret = device_register(&rdev->dev);
3954 if (ret != 0) {
3955 put_device(&rdev->dev);
3956 goto wash;
3957 }
3958
3959 dev_set_drvdata(&rdev->dev, rdev);
3960 4010
3961 /* set regulator constraints */ 4011 /* set regulator constraints */
3962 if (init_data) 4012 if (init_data)
3963 constraints = &init_data->constraints; 4013 constraints = &init_data->constraints;
3964 4014
3965 ret = set_machine_constraints(rdev, constraints);
3966 if (ret < 0)
3967 goto scrub;
3968
3969 if (init_data && init_data->supply_regulator) 4015 if (init_data && init_data->supply_regulator)
3970 rdev->supply_name = init_data->supply_regulator; 4016 rdev->supply_name = init_data->supply_regulator;
3971 else if (regulator_desc->supply_name) 4017 else if (regulator_desc->supply_name)
3972 rdev->supply_name = regulator_desc->supply_name; 4018 rdev->supply_name = regulator_desc->supply_name;
3973 4019
4020 /*
4021 * Attempt to resolve the regulator supply, if specified,
4022 * but don't return an error if we fail because we will try
4023 * to resolve it again later as more regulators are added.
4024 */
4025 if (regulator_resolve_supply(rdev))
4026 rdev_dbg(rdev, "unable to resolve supply\n");
4027
4028 ret = set_machine_constraints(rdev, constraints);
4029 if (ret < 0)
4030 goto wash;
4031
3974 /* add consumers devices */ 4032 /* add consumers devices */
3975 if (init_data) { 4033 if (init_data) {
4034 mutex_lock(&regulator_list_mutex);
3976 for (i = 0; i < init_data->num_consumer_supplies; i++) { 4035 for (i = 0; i < init_data->num_consumer_supplies; i++) {
3977 ret = set_consumer_device_supply(rdev, 4036 ret = set_consumer_device_supply(rdev,
3978 init_data->consumer_supplies[i].dev_name, 4037 init_data->consumer_supplies[i].dev_name,
3979 init_data->consumer_supplies[i].supply); 4038 init_data->consumer_supplies[i].supply);
3980 if (ret < 0) { 4039 if (ret < 0) {
4040 mutex_unlock(&regulator_list_mutex);
3981 dev_err(dev, "Failed to set supply %s\n", 4041 dev_err(dev, "Failed to set supply %s\n",
3982 init_data->consumer_supplies[i].supply); 4042 init_data->consumer_supplies[i].supply);
3983 goto unset_supplies; 4043 goto unset_supplies;
3984 } 4044 }
3985 } 4045 }
4046 mutex_unlock(&regulator_list_mutex);
4047 }
4048
4049 ret = device_register(&rdev->dev);
4050 if (ret != 0) {
4051 put_device(&rdev->dev);
4052 goto unset_supplies;
3986 } 4053 }
3987 4054
4055 dev_set_drvdata(&rdev->dev, rdev);
3988 rdev_init_debugfs(rdev); 4056 rdev_init_debugfs(rdev);
3989out: 4057
3990 mutex_unlock(&regulator_list_mutex); 4058 /* try to resolve regulators supply since a new one was registered */
4059 class_for_each_device(&regulator_class, NULL, NULL,
4060 regulator_register_resolve_supply);
3991 kfree(config); 4061 kfree(config);
3992 return rdev; 4062 return rdev;
3993 4063
3994unset_supplies: 4064unset_supplies:
4065 mutex_lock(&regulator_list_mutex);
3995 unset_regulator_supplies(rdev); 4066 unset_regulator_supplies(rdev);
3996 4067 mutex_unlock(&regulator_list_mutex);
3997scrub:
3998 regulator_ena_gpio_free(rdev);
3999 device_unregister(&rdev->dev);
4000 /* device core frees rdev */
4001 rdev = ERR_PTR(ret);
4002 goto out;
4003
4004wash: 4068wash:
4069 kfree(rdev->constraints);
4070 mutex_lock(&regulator_list_mutex);
4005 regulator_ena_gpio_free(rdev); 4071 regulator_ena_gpio_free(rdev);
4072 mutex_unlock(&regulator_list_mutex);
4006clean: 4073clean:
4007 kfree(rdev); 4074 kfree(rdev);
4008 rdev = ERR_PTR(ret); 4075 kfree(config);
4009 goto out; 4076 return ERR_PTR(ret);
4010} 4077}
4011EXPORT_SYMBOL_GPL(regulator_register); 4078EXPORT_SYMBOL_GPL(regulator_register);
4012 4079
@@ -4032,8 +4099,8 @@ void regulator_unregister(struct regulator_dev *rdev)
4032 WARN_ON(rdev->open_count); 4099 WARN_ON(rdev->open_count);
4033 unset_regulator_supplies(rdev); 4100 unset_regulator_supplies(rdev);
4034 list_del(&rdev->list); 4101 list_del(&rdev->list);
4035 mutex_unlock(&regulator_list_mutex);
4036 regulator_ena_gpio_free(rdev); 4102 regulator_ena_gpio_free(rdev);
4103 mutex_unlock(&regulator_list_mutex);
4037 device_unregister(&rdev->dev); 4104 device_unregister(&rdev->dev);
4038} 4105}
4039EXPORT_SYMBOL_GPL(regulator_unregister); 4106EXPORT_SYMBOL_GPL(regulator_unregister);
@@ -4386,7 +4453,7 @@ static int __init regulator_late_cleanup(struct device *dev, void *data)
4386 if (c && c->always_on) 4453 if (c && c->always_on)
4387 return 0; 4454 return 0;
4388 4455
4389 if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS)) 4456 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_STATUS))
4390 return 0; 4457 return 0;
4391 4458
4392 mutex_lock(&rdev->mutex); 4459 mutex_lock(&rdev->mutex);
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 2cb5cc311610..d7da81a875cf 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -65,6 +65,13 @@ enum {
65 FAN53555_CHIP_ID_03, 65 FAN53555_CHIP_ID_03,
66 FAN53555_CHIP_ID_04, 66 FAN53555_CHIP_ID_04,
67 FAN53555_CHIP_ID_05, 67 FAN53555_CHIP_ID_05,
68 FAN53555_CHIP_ID_08 = 8,
69};
70
71/* IC mask revision */
72enum {
73 FAN53555_CHIP_REV_00 = 0x3,
74 FAN53555_CHIP_REV_13 = 0xf,
68}; 75};
69 76
70enum { 77enum {
@@ -217,9 +224,26 @@ static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
217 /* Init voltage range and step */ 224 /* Init voltage range and step */
218 switch (di->chip_id) { 225 switch (di->chip_id) {
219 case FAN53555_CHIP_ID_00: 226 case FAN53555_CHIP_ID_00:
227 switch (di->chip_rev) {
228 case FAN53555_CHIP_REV_00:
229 di->vsel_min = 600000;
230 di->vsel_step = 10000;
231 break;
232 case FAN53555_CHIP_REV_13:
233 di->vsel_min = 800000;
234 di->vsel_step = 10000;
235 break;
236 default:
237 dev_err(di->dev,
238 "Chip ID %d with rev %d not supported!\n",
239 di->chip_id, di->chip_rev);
240 return -EINVAL;
241 }
242 break;
220 case FAN53555_CHIP_ID_01: 243 case FAN53555_CHIP_ID_01:
221 case FAN53555_CHIP_ID_03: 244 case FAN53555_CHIP_ID_03:
222 case FAN53555_CHIP_ID_05: 245 case FAN53555_CHIP_ID_05:
246 case FAN53555_CHIP_ID_08:
223 di->vsel_min = 600000; 247 di->vsel_min = 600000;
224 di->vsel_step = 10000; 248 di->vsel_step = 10000;
225 break; 249 break;
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index b1e32e7482e9..bcf38fd5106a 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -460,7 +460,7 @@ int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
460 if (ret != 0) 460 if (ret != 0)
461 return ret; 461 return ret;
462 462
463 *enable = val & rdev->desc->bypass_mask; 463 *enable = (val & rdev->desc->bypass_mask) == rdev->desc->bypass_val_on;
464 464
465 return 0; 465 return 0;
466} 466}
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 15c25c622edf..204b5c5270e0 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -365,8 +365,8 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val)
365 mutex_lock(&lp3971->io_lock); 365 mutex_lock(&lp3971->io_lock);
366 366
367 ret = lp3971_i2c_read(lp3971->i2c, reg, 1, &tmp); 367 ret = lp3971_i2c_read(lp3971->i2c, reg, 1, &tmp);
368 tmp = (tmp & ~mask) | val;
369 if (ret == 0) { 368 if (ret == 0) {
369 tmp = (tmp & ~mask) | val;
370 ret = lp3971_i2c_write(lp3971->i2c, reg, 1, &tmp); 370 ret = lp3971_i2c_write(lp3971->i2c, reg, 1, &tmp);
371 dev_dbg(lp3971->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg, 371 dev_dbg(lp3971->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg,
372 (unsigned)val&0xff); 372 (unsigned)val&0xff);
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index 3a7e96e2c7b3..ff0c275f902e 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -211,8 +211,8 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val)
211 mutex_lock(&lp3972->io_lock); 211 mutex_lock(&lp3972->io_lock);
212 212
213 ret = lp3972_i2c_read(lp3972->i2c, reg, 1, &tmp); 213 ret = lp3972_i2c_read(lp3972->i2c, reg, 1, &tmp);
214 tmp = (tmp & ~mask) | val;
215 if (ret == 0) { 214 if (ret == 0) {
215 tmp = (tmp & ~mask) | val;
216 ret = lp3972_i2c_write(lp3972->i2c, reg, 1, &tmp); 216 ret = lp3972_i2c_write(lp3972->i2c, reg, 1, &tmp);
217 dev_dbg(lp3972->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg, 217 dev_dbg(lp3972->dev, "reg write 0x%02x -> 0x%02x\n", (int)reg,
218 (unsigned)val & 0xff); 218 (unsigned)val & 0xff);
diff --git a/drivers/regulator/lp873x-regulator.c b/drivers/regulator/lp873x-regulator.c
new file mode 100644
index 000000000000..b4ffd113ba21
--- /dev/null
+++ b/drivers/regulator/lp873x-regulator.c
@@ -0,0 +1,241 @@
1/*
2 * Regulator driver for LP873X PMIC
3 *
4 * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether expressed or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details.
14 */
15
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/regmap.h>
19
20#include <linux/mfd/lp873x.h>
21
22#define LP873X_REGULATOR(_name, _id, _of, _ops, _n, _vr, _vm, _er, _em, \
23 _delay, _lr, _nlr, _cr) \
24 [_id] = { \
25 .desc = { \
26 .name = _name, \
27 .id = _id, \
28 .of_match = of_match_ptr(_of), \
29 .regulators_node = of_match_ptr("regulators"),\
30 .ops = &_ops, \
31 .n_voltages = _n, \
32 .type = REGULATOR_VOLTAGE, \
33 .owner = THIS_MODULE, \
34 .vsel_reg = _vr, \
35 .vsel_mask = _vm, \
36 .enable_reg = _er, \
37 .enable_mask = _em, \
38 .ramp_delay = _delay, \
39 .linear_ranges = _lr, \
40 .n_linear_ranges = _nlr, \
41 }, \
42 .ctrl2_reg = _cr, \
43 }
44
45struct lp873x_regulator {
46 struct regulator_desc desc;
47 unsigned int ctrl2_reg;
48};
49
50static const struct lp873x_regulator regulators[];
51
52static const struct regulator_linear_range buck0_buck1_ranges[] = {
53 REGULATOR_LINEAR_RANGE(0, 0x0, 0x13, 0),
54 REGULATOR_LINEAR_RANGE(700000, 0x14, 0x17, 10000),
55 REGULATOR_LINEAR_RANGE(735000, 0x18, 0x9d, 5000),
56 REGULATOR_LINEAR_RANGE(1420000, 0x9e, 0xff, 20000),
57};
58
59static const struct regulator_linear_range ldo0_ldo1_ranges[] = {
60 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x19, 100000),
61};
62
63static unsigned int lp873x_buck_ramp_delay[] = {
64 30000, 15000, 10000, 7500, 3800, 1900, 940, 470
65};
66
67/* LP873X BUCK current limit */
68static const unsigned int lp873x_buck_uA[] = {
69 1500000, 2000000, 2500000, 3000000, 3500000, 4000000,
70};
71
72static int lp873x_buck_set_ramp_delay(struct regulator_dev *rdev,
73 int ramp_delay)
74{
75 int id = rdev_get_id(rdev);
76 struct lp873x *lp873 = rdev_get_drvdata(rdev);
77 unsigned int reg;
78 int ret;
79
80 if (ramp_delay <= 470)
81 reg = 7;
82 else if (ramp_delay <= 940)
83 reg = 6;
84 else if (ramp_delay <= 1900)
85 reg = 5;
86 else if (ramp_delay <= 3800)
87 reg = 4;
88 else if (ramp_delay <= 7500)
89 reg = 3;
90 else if (ramp_delay <= 10000)
91 reg = 2;
92 else if (ramp_delay <= 15000)
93 reg = 1;
94 else
95 reg = 0;
96
97 ret = regmap_update_bits(lp873->regmap, regulators[id].ctrl2_reg,
98 LP873X_BUCK0_CTRL_2_BUCK0_SLEW_RATE,
99 reg << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_SLEW_RATE));
100 if (ret) {
101 dev_err(lp873->dev, "SLEW RATE write failed: %d\n", ret);
102 return ret;
103 }
104
105 rdev->constraints->ramp_delay = lp873x_buck_ramp_delay[reg];
106
107 return 0;
108}
109
110static int lp873x_buck_set_current_limit(struct regulator_dev *rdev,
111 int min_uA, int max_uA)
112{
113 int id = rdev_get_id(rdev);
114 struct lp873x *lp873 = rdev_get_drvdata(rdev);
115 int i;
116
117 for (i = ARRAY_SIZE(lp873x_buck_uA) - 1; i >= 0; i--) {
118 if (lp873x_buck_uA[i] >= min_uA &&
119 lp873x_buck_uA[i] <= max_uA)
120 return regmap_update_bits(lp873->regmap,
121 regulators[id].ctrl2_reg,
122 LP873X_BUCK0_CTRL_2_BUCK0_ILIM,
123 i << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM));
124 }
125
126 return -EINVAL;
127}
128
129static int lp873x_buck_get_current_limit(struct regulator_dev *rdev)
130{
131 int id = rdev_get_id(rdev);
132 struct lp873x *lp873 = rdev_get_drvdata(rdev);
133 int ret;
134 unsigned int val;
135
136 ret = regmap_read(lp873->regmap, regulators[id].ctrl2_reg, &val);
137 if (ret)
138 return ret;
139
140 val = (val & LP873X_BUCK0_CTRL_2_BUCK0_ILIM) >>
141 __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM);
142
143 return (val < ARRAY_SIZE(lp873x_buck_uA)) ?
144 lp873x_buck_uA[val] : -EINVAL;
145}
146
147/* Operations permitted on BUCK0, BUCK1 */
148static struct regulator_ops lp873x_buck01_ops = {
149 .is_enabled = regulator_is_enabled_regmap,
150 .enable = regulator_enable_regmap,
151 .disable = regulator_disable_regmap,
152 .get_voltage_sel = regulator_get_voltage_sel_regmap,
153 .set_voltage_sel = regulator_set_voltage_sel_regmap,
154 .list_voltage = regulator_list_voltage_linear_range,
155 .map_voltage = regulator_map_voltage_linear_range,
156 .set_voltage_time_sel = regulator_set_voltage_time_sel,
157 .set_ramp_delay = lp873x_buck_set_ramp_delay,
158 .set_current_limit = lp873x_buck_set_current_limit,
159 .get_current_limit = lp873x_buck_get_current_limit,
160};
161
162/* Operations permitted on LDO0 and LDO1 */
163static struct regulator_ops lp873x_ldo01_ops = {
164 .is_enabled = regulator_is_enabled_regmap,
165 .enable = regulator_enable_regmap,
166 .disable = regulator_disable_regmap,
167 .get_voltage_sel = regulator_get_voltage_sel_regmap,
168 .set_voltage_sel = regulator_set_voltage_sel_regmap,
169 .list_voltage = regulator_list_voltage_linear_range,
170 .map_voltage = regulator_map_voltage_linear_range,
171};
172
173static const struct lp873x_regulator regulators[] = {
174 LP873X_REGULATOR("BUCK0", LP873X_BUCK_0, "buck0", lp873x_buck01_ops,
175 256, LP873X_REG_BUCK0_VOUT,
176 LP873X_BUCK0_VOUT_BUCK0_VSET, LP873X_REG_BUCK0_CTRL_1,
177 LP873X_BUCK0_CTRL_1_BUCK0_EN, 10000,
178 buck0_buck1_ranges, 4, LP873X_REG_BUCK0_CTRL_2),
179 LP873X_REGULATOR("BUCK1", LP873X_BUCK_1, "buck1", lp873x_buck01_ops,
180 256, LP873X_REG_BUCK1_VOUT,
181 LP873X_BUCK1_VOUT_BUCK1_VSET, LP873X_REG_BUCK1_CTRL_1,
182 LP873X_BUCK1_CTRL_1_BUCK1_EN, 10000,
183 buck0_buck1_ranges, 4, LP873X_REG_BUCK1_CTRL_2),
184 LP873X_REGULATOR("LDO0", LP873X_LDO_0, "ldo0", lp873x_ldo01_ops, 26,
185 LP873X_REG_LDO0_VOUT, LP873X_LDO0_VOUT_LDO0_VSET,
186 LP873X_REG_LDO0_CTRL,
187 LP873X_LDO0_CTRL_LDO0_EN, 0, ldo0_ldo1_ranges, 1,
188 0xFF),
189 LP873X_REGULATOR("LDO1", LP873X_LDO_1, "ldo1", lp873x_ldo01_ops, 26,
190 LP873X_REG_LDO1_VOUT, LP873X_LDO1_VOUT_LDO1_VSET,
191 LP873X_REG_LDO1_CTRL,
192 LP873X_LDO1_CTRL_LDO1_EN, 0, ldo0_ldo1_ranges, 1,
193 0xFF),
194};
195
196static int lp873x_regulator_probe(struct platform_device *pdev)
197{
198 struct lp873x *lp873 = dev_get_drvdata(pdev->dev.parent);
199 struct regulator_config config = { };
200 struct regulator_dev *rdev;
201 int i;
202
203 platform_set_drvdata(pdev, lp873);
204
205 config.dev = &pdev->dev;
206 config.dev->of_node = lp873->dev->of_node;
207 config.driver_data = lp873;
208 config.regmap = lp873->regmap;
209
210 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
211 rdev = devm_regulator_register(&pdev->dev, &regulators[i].desc,
212 &config);
213 if (IS_ERR(rdev)) {
214 dev_err(lp873->dev, "failed to register %s regulator\n",
215 pdev->name);
216 return PTR_ERR(rdev);
217 }
218 }
219
220 return 0;
221}
222
223static const struct platform_device_id lp873x_regulator_id_table[] = {
224 { "lp873x-regulator", },
225 { /* sentinel */ }
226};
227MODULE_DEVICE_TABLE(platform, lp873x_regulator_id_table);
228
229static struct platform_driver lp873x_regulator_driver = {
230 .driver = {
231 .name = "lp873x-pmic",
232 },
233 .probe = lp873x_regulator_probe,
234 .id_table = lp873x_regulator_id_table,
235};
236module_platform_driver(lp873x_regulator_driver);
237
238MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
239MODULE_DESCRIPTION("LP873X voltage regulator driver");
240MODULE_ALIAS("platform:lp873x-pmic");
241MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577-regulator.c
index b2daa6641417..b2daa6641417 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577-regulator.c
diff --git a/drivers/regulator/max77620-regulator.c b/drivers/regulator/max77620-regulator.c
index 73a3356a5c19..321e804aeab0 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -81,6 +81,7 @@ struct max77620_regulator_pdata {
81 int suspend_fps_pd_slot; 81 int suspend_fps_pd_slot;
82 int suspend_fps_pu_slot; 82 int suspend_fps_pu_slot;
83 int current_mode; 83 int current_mode;
84 int ramp_rate_setting;
84}; 85};
85 86
86struct max77620_regulator { 87struct max77620_regulator {
@@ -307,6 +308,43 @@ static int max77620_read_slew_rate(struct max77620_regulator *pmic, int id)
307 return 0; 308 return 0;
308} 309}
309 310
311static int max77620_set_slew_rate(struct max77620_regulator *pmic, int id,
312 int slew_rate)
313{
314 struct max77620_regulator_info *rinfo = pmic->rinfo[id];
315 unsigned int val;
316 int ret;
317 u8 mask;
318
319 if (rinfo->type == MAX77620_REGULATOR_TYPE_SD) {
320 if (slew_rate <= 13750)
321 val = 0;
322 else if (slew_rate <= 27500)
323 val = 1;
324 else if (slew_rate <= 55000)
325 val = 2;
326 else
327 val = 3;
328 val <<= MAX77620_SD_SR_SHIFT;
329 mask = MAX77620_SD_SR_MASK;
330 } else {
331 if (slew_rate <= 5000)
332 val = 1;
333 else
334 val = 0;
335 mask = MAX77620_LDO_SLEW_RATE_MASK;
336 }
337
338 ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr, mask, val);
339 if (ret < 0) {
340 dev_err(pmic->dev, "Regulator %d slew rate set failed: %d\n",
341 id, ret);
342 return ret;
343 }
344
345 return 0;
346}
347
310static int max77620_init_pmic(struct max77620_regulator *pmic, int id) 348static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
311{ 349{
312 struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id]; 350 struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id];
@@ -351,6 +389,13 @@ static int max77620_init_pmic(struct max77620_regulator *pmic, int id)
351 if (ret < 0) 389 if (ret < 0)
352 return ret; 390 return ret;
353 391
392 if (rpdata->ramp_rate_setting) {
393 ret = max77620_set_slew_rate(pmic, id,
394 rpdata->ramp_rate_setting);
395 if (ret < 0)
396 return ret;
397 }
398
354 return 0; 399 return 0;
355} 400}
356 401
@@ -502,35 +547,16 @@ static int max77620_regulator_set_ramp_delay(struct regulator_dev *rdev,
502{ 547{
503 struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 548 struct max77620_regulator *pmic = rdev_get_drvdata(rdev);
504 int id = rdev_get_id(rdev); 549 int id = rdev_get_id(rdev);
505 struct max77620_regulator_info *rinfo = pmic->rinfo[id]; 550 struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[id];
506 int ret, val;
507 u8 mask;
508
509 if (rinfo->type == MAX77620_REGULATOR_TYPE_SD) {
510 if (ramp_delay <= 13750)
511 val = 0;
512 else if (ramp_delay <= 27500)
513 val = 1;
514 else if (ramp_delay <= 55000)
515 val = 2;
516 else
517 val = 3;
518 val <<= MAX77620_SD_SR_SHIFT;
519 mask = MAX77620_SD_SR_MASK;
520 } else {
521 if (ramp_delay <= 5000)
522 val = 1;
523 else
524 val = 0;
525 mask = MAX77620_LDO_SLEW_RATE_MASK;
526 }
527 551
528 ret = regmap_update_bits(pmic->rmap, rinfo->cfg_addr, mask, val); 552 /* Device specific ramp rate setting tells that platform has
529 if (ret < 0) 553 * different ramp rate from advertised value. In this case,
530 dev_err(pmic->dev, "Reg 0x%02x update failed: %d\n", 554 * do not configure anything and just return success.
531 rinfo->cfg_addr, ret); 555 */
556 if (rpdata->ramp_rate_setting)
557 return 0;
532 558
533 return ret; 559 return max77620_set_slew_rate(pmic, id, ramp_delay);
534} 560}
535 561
536static int max77620_of_parse_cb(struct device_node *np, 562static int max77620_of_parse_cb(struct device_node *np,
@@ -563,6 +589,9 @@ static int max77620_of_parse_cb(struct device_node *np,
563 np, "maxim,suspend-fps-power-down-slot", &pval); 589 np, "maxim,suspend-fps-power-down-slot", &pval);
564 rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1; 590 rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
565 591
592 ret = of_property_read_u32(np, "maxim,ramp-rate-setting", &pval);
593 rpdata->ramp_rate_setting = (!ret) ? pval : 0;
594
566 return max77620_init_pmic(pmic, desc->id); 595 return max77620_init_pmic(pmic, desc->id);
567} 596}
568 597
diff --git a/drivers/regulator/max77686-regulator.c b/drivers/regulator/max77686-regulator.c
index 17ccf365a9c0..ac4fa581e0a5 100644
--- a/drivers/regulator/max77686-regulator.c
+++ b/drivers/regulator/max77686-regulator.c
@@ -41,6 +41,8 @@
41#define MAX77686_LDO_LOW_UVSTEP 25000 41#define MAX77686_LDO_LOW_UVSTEP 25000
42#define MAX77686_BUCK_MINUV 750000 42#define MAX77686_BUCK_MINUV 750000
43#define MAX77686_BUCK_UVSTEP 50000 43#define MAX77686_BUCK_UVSTEP 50000
44#define MAX77686_BUCK_ENABLE_TIME 40 /* us */
45#define MAX77686_DVS_ENABLE_TIME 22 /* us */
44#define MAX77686_RAMP_DELAY 100000 /* uV/us */ 46#define MAX77686_RAMP_DELAY 100000 /* uV/us */
45#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ 47#define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
46#define MAX77686_DVS_MINUV 600000 48#define MAX77686_DVS_MINUV 600000
@@ -422,6 +424,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
422 .min_uV = MAX77686_BUCK_MINUV, \ 424 .min_uV = MAX77686_BUCK_MINUV, \
423 .uV_step = MAX77686_BUCK_UVSTEP, \ 425 .uV_step = MAX77686_BUCK_UVSTEP, \
424 .ramp_delay = MAX77686_RAMP_DELAY, \ 426 .ramp_delay = MAX77686_RAMP_DELAY, \
427 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
425 .n_voltages = MAX77686_VSEL_MASK + 1, \ 428 .n_voltages = MAX77686_VSEL_MASK + 1, \
426 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ 429 .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
427 .vsel_mask = MAX77686_VSEL_MASK, \ 430 .vsel_mask = MAX77686_VSEL_MASK, \
@@ -439,6 +442,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
439 .min_uV = MAX77686_BUCK_MINUV, \ 442 .min_uV = MAX77686_BUCK_MINUV, \
440 .uV_step = MAX77686_BUCK_UVSTEP, \ 443 .uV_step = MAX77686_BUCK_UVSTEP, \
441 .ramp_delay = MAX77686_RAMP_DELAY, \ 444 .ramp_delay = MAX77686_RAMP_DELAY, \
445 .enable_time = MAX77686_BUCK_ENABLE_TIME, \
442 .n_voltages = MAX77686_VSEL_MASK + 1, \ 446 .n_voltages = MAX77686_VSEL_MASK + 1, \
443 .vsel_reg = MAX77686_REG_BUCK1OUT, \ 447 .vsel_reg = MAX77686_REG_BUCK1OUT, \
444 .vsel_mask = MAX77686_VSEL_MASK, \ 448 .vsel_mask = MAX77686_VSEL_MASK, \
@@ -456,6 +460,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
456 .min_uV = MAX77686_DVS_MINUV, \ 460 .min_uV = MAX77686_DVS_MINUV, \
457 .uV_step = MAX77686_DVS_UVSTEP, \ 461 .uV_step = MAX77686_DVS_UVSTEP, \
458 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ 462 .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
463 .enable_time = MAX77686_DVS_ENABLE_TIME, \
459 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ 464 .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
460 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ 465 .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
461 .vsel_mask = MAX77686_DVS_VSEL_MASK, \ 466 .vsel_mask = MAX77686_DVS_VSEL_MASK, \
@@ -553,17 +558,7 @@ static struct platform_driver max77686_pmic_driver = {
553 .id_table = max77686_pmic_id, 558 .id_table = max77686_pmic_id,
554}; 559};
555 560
556static int __init max77686_pmic_init(void) 561module_platform_driver(max77686_pmic_driver);
557{
558 return platform_driver_register(&max77686_pmic_driver);
559}
560subsys_initcall(max77686_pmic_init);
561
562static void __exit max77686_pmic_cleanup(void)
563{
564 platform_driver_unregister(&max77686_pmic_driver);
565}
566module_exit(max77686_pmic_cleanup);
567 562
568MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); 563MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
569MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); 564MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693-regulator.c
index de730fd3f8a5..de730fd3f8a5 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693-regulator.c
diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c
index c07ee13bd470..1d3539324d9a 100644
--- a/drivers/regulator/max77802-regulator.c
+++ b/drivers/regulator/max77802-regulator.c
@@ -5,7 +5,7 @@
5 * Simon Glass <sjg@chromium.org> 5 * Simon Glass <sjg@chromium.org>
6 * 6 *
7 * Copyright (C) 2012 Samsung Electronics 7 * Copyright (C) 2012 Samsung Electronics
8 * Chiwoong Byun <woong.byun@smasung.com> 8 * Chiwoong Byun <woong.byun@samsung.com>
9 * Jonghwa Lee <jonghwa3.lee@samsung.com> 9 * Jonghwa Lee <jonghwa3.lee@samsung.com>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index 5b75b7c2e3ea..08d2f13eca00 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -38,6 +38,9 @@
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/regmap.h> 40#include <linux/regmap.h>
41#include <linux/thermal.h>
42#include <linux/irq.h>
43#include <linux/interrupt.h>
41 44
42/* Register definitions */ 45/* Register definitions */
43#define MAX8973_VOUT 0x0 46#define MAX8973_VOUT 0x0
@@ -74,6 +77,7 @@
74#define MAX8973_WDTMR_ENABLE BIT(6) 77#define MAX8973_WDTMR_ENABLE BIT(6)
75#define MAX8973_DISCH_ENBABLE BIT(5) 78#define MAX8973_DISCH_ENBABLE BIT(5)
76#define MAX8973_FT_ENABLE BIT(4) 79#define MAX8973_FT_ENABLE BIT(4)
80#define MAX77621_T_JUNCTION_120 BIT(7)
77 81
78#define MAX8973_CKKADV_TRIP_MASK 0xC 82#define MAX8973_CKKADV_TRIP_MASK 0xC
79#define MAX8973_CKKADV_TRIP_DISABLE 0xC 83#define MAX8973_CKKADV_TRIP_DISABLE 0xC
@@ -93,6 +97,12 @@
93#define MAX8973_VOLATGE_STEP 6250 97#define MAX8973_VOLATGE_STEP 6250
94#define MAX8973_BUCK_N_VOLTAGE 0x80 98#define MAX8973_BUCK_N_VOLTAGE 0x80
95 99
100#define MAX77621_CHIPID_TJINT_S BIT(0)
101
102#define MAX77621_NORMAL_OPERATING_TEMP 100000
103#define MAX77621_TJINT_WARNING_TEMP_120 120000
104#define MAX77621_TJINT_WARNING_TEMP_140 140000
105
96enum device_id { 106enum device_id {
97 MAX8973, 107 MAX8973,
98 MAX77621 108 MAX77621
@@ -112,6 +122,9 @@ struct max8973_chip {
112 int curr_gpio_val; 122 int curr_gpio_val;
113 struct regulator_ops ops; 123 struct regulator_ops ops;
114 enum device_id id; 124 enum device_id id;
125 int junction_temp_warning;
126 int irq;
127 struct thermal_zone_device *tz_device;
115}; 128};
116 129
117/* 130/*
@@ -391,6 +404,10 @@ static int max8973_init_dcdc(struct max8973_chip *max,
391 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) 404 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE)
392 control1 |= MAX8973_FREQSHIFT_9PER; 405 control1 |= MAX8973_FREQSHIFT_9PER;
393 406
407 if ((pdata->junction_temp_warning == MAX77621_TJINT_WARNING_TEMP_120) &&
408 (max->id == MAX77621))
409 control2 |= MAX77621_T_JUNCTION_120;
410
394 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) 411 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE))
395 control2 |= MAX8973_DISCH_ENBABLE; 412 control2 |= MAX8973_DISCH_ENBABLE;
396 413
@@ -457,6 +474,79 @@ static int max8973_init_dcdc(struct max8973_chip *max,
457 return ret; 474 return ret;
458} 475}
459 476
477static int max8973_thermal_read_temp(void *data, int *temp)
478{
479 struct max8973_chip *mchip = data;
480 unsigned int val;
481 int ret;
482
483 ret = regmap_read(mchip->regmap, MAX8973_CHIPID1, &val);
484 if (ret < 0) {
485 dev_err(mchip->dev, "Failed to read register CHIPID1, %d", ret);
486 return ret;
487 }
488
489 /* +1 degC to trigger cool devive */
490 if (val & MAX77621_CHIPID_TJINT_S)
491 *temp = mchip->junction_temp_warning + 1000;
492 else
493 *temp = MAX77621_NORMAL_OPERATING_TEMP;
494
495 return 0;
496}
497
498static irqreturn_t max8973_thermal_irq(int irq, void *data)
499{
500 struct max8973_chip *mchip = data;
501
502 thermal_zone_device_update(mchip->tz_device);
503
504 return IRQ_HANDLED;
505}
506
507static const struct thermal_zone_of_device_ops max77621_tz_ops = {
508 .get_temp = max8973_thermal_read_temp,
509};
510
511static int max8973_thermal_init(struct max8973_chip *mchip)
512{
513 struct thermal_zone_device *tzd;
514 struct irq_data *irq_data;
515 unsigned long irq_flags = 0;
516 int ret;
517
518 if (mchip->id != MAX77621)
519 return 0;
520
521 tzd = devm_thermal_zone_of_sensor_register(mchip->dev, 0, mchip,
522 &max77621_tz_ops);
523 if (IS_ERR(tzd)) {
524 ret = PTR_ERR(tzd);
525 dev_err(mchip->dev, "Failed to register thermal sensor: %d\n",
526 ret);
527 return ret;
528 }
529
530 if (mchip->irq <= 0)
531 return 0;
532
533 irq_data = irq_get_irq_data(mchip->irq);
534 if (irq_data)
535 irq_flags = irqd_get_trigger_type(irq_data);
536
537 ret = devm_request_threaded_irq(mchip->dev, mchip->irq, NULL,
538 max8973_thermal_irq,
539 IRQF_ONESHOT | IRQF_SHARED | irq_flags,
540 dev_name(mchip->dev), mchip);
541 if (ret < 0) {
542 dev_err(mchip->dev, "Failed to request irq %d, %d\n",
543 mchip->irq, ret);
544 return ret;
545 }
546
547 return 0;
548}
549
460static const struct regmap_config max8973_regmap_config = { 550static const struct regmap_config max8973_regmap_config = {
461 .reg_bits = 8, 551 .reg_bits = 8,
462 .val_bits = 8, 552 .val_bits = 8,
@@ -521,6 +611,11 @@ static struct max8973_regulator_platform_data *max8973_parse_dt(
521 pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED; 611 pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED;
522 } 612 }
523 613
614 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_140;
615 ret = of_property_read_u32(np, "junction-warn-millicelsius", &pval);
616 if (!ret && (pval <= MAX77621_TJINT_WARNING_TEMP_120))
617 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_120;
618
524 return pdata; 619 return pdata;
525} 620}
526 621
@@ -608,6 +703,7 @@ static int max8973_probe(struct i2c_client *client,
608 max->enable_external_control = pdata->enable_ext_control; 703 max->enable_external_control = pdata->enable_ext_control;
609 max->curr_gpio_val = pdata->dvs_def_state; 704 max->curr_gpio_val = pdata->dvs_def_state;
610 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; 705 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
706 max->junction_temp_warning = pdata->junction_temp_warning;
611 707
612 if (gpio_is_valid(max->enable_gpio)) 708 if (gpio_is_valid(max->enable_gpio))
613 max->enable_external_control = true; 709 max->enable_external_control = true;
@@ -718,6 +814,7 @@ static int max8973_probe(struct i2c_client *client,
718 return ret; 814 return ret;
719 } 815 }
720 816
817 max8973_thermal_init(max);
721 return 0; 818 return 0;
722} 819}
723 820
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997-regulator.c
index ea0196d4496b..efabc0ea0e96 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997-regulator.c
@@ -2,7 +2,7 @@
2 * max8997.c - Regulator driver for the Maxim 8997/8966 2 * max8997.c - Regulator driver for the Maxim 8997/8966
3 * 3 *
4 * Copyright (C) 2011 Samsung Electronics 4 * Copyright (C) 2011 Samsung Electronics
5 * MyungJoo Ham <myungjoo.ham@smasung.com> 5 * MyungJoo Ham <myungjoo.ham@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 6b0aa80b22fd..cd828dbf9d52 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -45,9 +45,9 @@ static void of_get_regulation_constraints(struct device_node *np,
45 /* Voltage change possible? */ 45 /* Voltage change possible? */
46 if (constraints->min_uV != constraints->max_uV) 46 if (constraints->min_uV != constraints->max_uV)
47 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; 47 constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
48 /* Only one voltage? Then make sure it's set. */ 48
49 if (constraints->min_uV && constraints->max_uV && 49 /* Do we have a voltage range, if so try to apply it? */
50 constraints->min_uV == constraints->max_uV) 50 if (constraints->min_uV && constraints->max_uV)
51 constraints->apply_uV = true; 51 constraints->apply_uV = true;
52 52
53 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval)) 53 if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval))
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 6efc7ee8aea3..f11d41dad9c1 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -944,6 +944,8 @@ static int palmas_ldo_registration(struct palmas_pmic *pmic,
944 if (id == PALMAS_REG_LDO9) { 944 if (id == PALMAS_REG_LDO9) {
945 desc->ops = &palmas_ops_ldo9; 945 desc->ops = &palmas_ops_ldo9;
946 desc->bypass_reg = desc->enable_reg; 946 desc->bypass_reg = desc->enable_reg;
947 desc->bypass_val_on =
948 PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
947 desc->bypass_mask = 949 desc->bypass_mask =
948 PALMAS_LDO9_CTRL_LDO_BYPASS_EN; 950 PALMAS_LDO9_CTRL_LDO_BYPASS_EN;
949 } 951 }
@@ -1055,6 +1057,8 @@ static int tps65917_ldo_registration(struct palmas_pmic *pmic,
1055 id == TPS65917_REG_LDO2) { 1057 id == TPS65917_REG_LDO2) {
1056 desc->ops = &tps65917_ops_ldo_1_2; 1058 desc->ops = &tps65917_ops_ldo_1_2;
1057 desc->bypass_reg = desc->enable_reg; 1059 desc->bypass_reg = desc->enable_reg;
1060 desc->bypass_val_on =
1061 TPS65917_LDO1_CTRL_BYPASS_EN;
1058 desc->bypass_mask = 1062 desc->bypass_mask =
1059 TPS65917_LDO1_CTRL_BYPASS_EN; 1063 TPS65917_LDO1_CTRL_BYPASS_EN;
1060 } 1064 }
@@ -1206,6 +1210,7 @@ static int palmas_smps_registration(struct palmas_pmic *pmic,
1206 desc->enable_mask = SMPS10_BOOST_EN; 1210 desc->enable_mask = SMPS10_BOOST_EN;
1207 desc->bypass_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, 1211 desc->bypass_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
1208 PALMAS_SMPS10_CTRL); 1212 PALMAS_SMPS10_CTRL);
1213 desc->bypass_val_on = SMPS10_BYPASS_EN;
1209 desc->bypass_mask = SMPS10_BYPASS_EN; 1214 desc->bypass_mask = SMPS10_BYPASS_EN;
1210 desc->min_uV = 3750000; 1215 desc->min_uV = 3750000;
1211 desc->uV_step = 1250000; 1216 desc->uV_step = 1250000;
@@ -1462,10 +1467,10 @@ static struct palmas_pmic_driver_data tps65917_ddata = {
1462 .ldo_register = tps65917_ldo_registration, 1467 .ldo_register = tps65917_ldo_registration,
1463}; 1468};
1464 1469
1465static void palmas_dt_to_pdata(struct device *dev, 1470static int palmas_dt_to_pdata(struct device *dev,
1466 struct device_node *node, 1471 struct device_node *node,
1467 struct palmas_pmic_platform_data *pdata, 1472 struct palmas_pmic_platform_data *pdata,
1468 struct palmas_pmic_driver_data *ddata) 1473 struct palmas_pmic_driver_data *ddata)
1469{ 1474{
1470 struct device_node *regulators; 1475 struct device_node *regulators;
1471 u32 prop; 1476 u32 prop;
@@ -1474,7 +1479,7 @@ static void palmas_dt_to_pdata(struct device *dev,
1474 regulators = of_get_child_by_name(node, "regulators"); 1479 regulators = of_get_child_by_name(node, "regulators");
1475 if (!regulators) { 1480 if (!regulators) {
1476 dev_info(dev, "regulator node not found\n"); 1481 dev_info(dev, "regulator node not found\n");
1477 return; 1482 return 0;
1478 } 1483 }
1479 1484
1480 ret = of_regulator_match(dev, regulators, ddata->palmas_matches, 1485 ret = of_regulator_match(dev, regulators, ddata->palmas_matches,
@@ -1482,25 +1487,29 @@ static void palmas_dt_to_pdata(struct device *dev,
1482 of_node_put(regulators); 1487 of_node_put(regulators);
1483 if (ret < 0) { 1488 if (ret < 0) {
1484 dev_err(dev, "Error parsing regulator init data: %d\n", ret); 1489 dev_err(dev, "Error parsing regulator init data: %d\n", ret);
1485 return; 1490 return 0;
1486 } 1491 }
1487 1492
1488 for (idx = 0; idx < ddata->max_reg; idx++) { 1493 for (idx = 0; idx < ddata->max_reg; idx++) {
1489 if (!ddata->palmas_matches[idx].init_data || 1494 static struct of_regulator_match *match;
1490 !ddata->palmas_matches[idx].of_node) 1495 struct palmas_reg_init *rinit;
1491 continue; 1496 struct device_node *np;
1492 1497
1493 pdata->reg_data[idx] = ddata->palmas_matches[idx].init_data; 1498 match = &ddata->palmas_matches[idx];
1499 np = match->of_node;
1494 1500
1495 pdata->reg_init[idx] = devm_kzalloc(dev, 1501 if (!match->init_data || !np)
1496 sizeof(struct palmas_reg_init), GFP_KERNEL); 1502 continue;
1503
1504 rinit = devm_kzalloc(dev, sizeof(*rinit), GFP_KERNEL);
1505 if (!rinit)
1506 return -ENOMEM;
1497 1507
1498 pdata->reg_init[idx]->warm_reset = 1508 pdata->reg_data[idx] = match->init_data;
1499 of_property_read_bool(ddata->palmas_matches[idx].of_node, 1509 pdata->reg_init[idx] = rinit;
1500 "ti,warm-reset");
1501 1510
1502 ret = of_property_read_u32(ddata->palmas_matches[idx].of_node, 1511 rinit->warm_reset = of_property_read_bool(np, "ti,warm-reset");
1503 "ti,roof-floor", &prop); 1512 ret = of_property_read_u32(np, "ti,roof-floor", &prop);
1504 /* EINVAL: Property not found */ 1513 /* EINVAL: Property not found */
1505 if (ret != -EINVAL) { 1514 if (ret != -EINVAL) {
1506 int econtrol; 1515 int econtrol;
@@ -1522,31 +1531,29 @@ static void palmas_dt_to_pdata(struct device *dev,
1522 WARN_ON(1); 1531 WARN_ON(1);
1523 dev_warn(dev, 1532 dev_warn(dev,
1524 "%s: Invalid roof-floor option: %u\n", 1533 "%s: Invalid roof-floor option: %u\n",
1525 palmas_matches[idx].name, prop); 1534 match->name, prop);
1526 break; 1535 break;
1527 } 1536 }
1528 } 1537 }
1529 pdata->reg_init[idx]->roof_floor = econtrol; 1538 rinit->roof_floor = econtrol;
1530 } 1539 }
1531 1540
1532 ret = of_property_read_u32(ddata->palmas_matches[idx].of_node, 1541 ret = of_property_read_u32(np, "ti,mode-sleep", &prop);
1533 "ti,mode-sleep", &prop);
1534 if (!ret) 1542 if (!ret)
1535 pdata->reg_init[idx]->mode_sleep = prop; 1543 rinit->mode_sleep = prop;
1536 1544
1537 ret = of_property_read_bool(ddata->palmas_matches[idx].of_node, 1545 ret = of_property_read_bool(np, "ti,smps-range");
1538 "ti,smps-range");
1539 if (ret) 1546 if (ret)
1540 pdata->reg_init[idx]->vsel = 1547 rinit->vsel = PALMAS_SMPS12_VOLTAGE_RANGE;
1541 PALMAS_SMPS12_VOLTAGE_RANGE;
1542 1548
1543 if (idx == PALMAS_REG_LDO8) 1549 if (idx == PALMAS_REG_LDO8)
1544 pdata->enable_ldo8_tracking = of_property_read_bool( 1550 pdata->enable_ldo8_tracking = of_property_read_bool(
1545 ddata->palmas_matches[idx].of_node, 1551 np, "ti,enable-ldo8-tracking");
1546 "ti,enable-ldo8-tracking");
1547 } 1552 }
1548 1553
1549 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); 1554 pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
1555
1556 return 0;
1550} 1557}
1551 1558
1552static const struct of_device_id of_palmas_match_tbl[] = { 1559static const struct of_device_id of_palmas_match_tbl[] = {
@@ -1628,7 +1635,9 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1628 platform_set_drvdata(pdev, pmic); 1635 platform_set_drvdata(pdev, pmic);
1629 pmic->palmas->pmic_ddata = driver_data; 1636 pmic->palmas->pmic_ddata = driver_data;
1630 1637
1631 palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data); 1638 ret = palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data);
1639 if (ret)
1640 return ret;
1632 1641
1633 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg); 1642 ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
1634 if (ret) 1643 if (ret)
diff --git a/drivers/regulator/pv88080-regulator.c b/drivers/regulator/pv88080-regulator.c
new file mode 100644
index 000000000000..d7107566c429
--- /dev/null
+++ b/drivers/regulator/pv88080-regulator.c
@@ -0,0 +1,419 @@
1/*
2 * pv88080-regulator.c - Regulator device driver for PV88080
3 * Copyright (C) 2016 Powerventure Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/i2c.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/slab.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24#include <linux/regmap.h>
25#include <linux/irq.h>
26#include <linux/interrupt.h>
27#include <linux/regulator/of_regulator.h>
28#include <linux/proc_fs.h>
29#include <linux/uaccess.h>
30#include "pv88080-regulator.h"
31
32#define PV88080_MAX_REGULATORS 3
33
34/* PV88080 REGULATOR IDs */
35enum {
36 /* BUCKs */
37 PV88080_ID_BUCK1,
38 PV88080_ID_BUCK2,
39 PV88080_ID_BUCK3,
40};
41
42struct pv88080_regulator {
43 struct regulator_desc desc;
44 /* Current limiting */
45 unsigned int n_current_limits;
46 const int *current_limits;
47 unsigned int limit_mask;
48 unsigned int conf;
49 unsigned int conf2;
50 unsigned int conf5;
51};
52
53struct pv88080 {
54 struct device *dev;
55 struct regmap *regmap;
56 struct regulator_dev *rdev[PV88080_MAX_REGULATORS];
57};
58
59struct pv88080_buck_voltage {
60 int min_uV;
61 int max_uV;
62 int uV_step;
63};
64
65static const struct regmap_config pv88080_regmap_config = {
66 .reg_bits = 8,
67 .val_bits = 8,
68};
69
70/* Current limits array (in uA) for BUCK1, BUCK2, BUCK3.
71 * Entry indexes corresponds to register values.
72 */
73
74static const int pv88080_buck1_limits[] = {
75 3230000, 5130000, 6960000, 8790000
76};
77
78static const int pv88080_buck23_limits[] = {
79 1496000, 2393000, 3291000, 4189000
80};
81
82static const struct pv88080_buck_voltage pv88080_buck_vol[2] = {
83 {
84 .min_uV = 600000,
85 .max_uV = 1393750,
86 .uV_step = 6250,
87 },
88 {
89 .min_uV = 1400000,
90 .max_uV = 2193750,
91 .uV_step = 6250,
92 },
93};
94
95static unsigned int pv88080_buck_get_mode(struct regulator_dev *rdev)
96{
97 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
98 unsigned int data;
99 int ret, mode = 0;
100
101 ret = regmap_read(rdev->regmap, info->conf, &data);
102 if (ret < 0)
103 return ret;
104
105 switch (data & PV88080_BUCK1_MODE_MASK) {
106 case PV88080_BUCK_MODE_SYNC:
107 mode = REGULATOR_MODE_FAST;
108 break;
109 case PV88080_BUCK_MODE_AUTO:
110 mode = REGULATOR_MODE_NORMAL;
111 break;
112 case PV88080_BUCK_MODE_SLEEP:
113 mode = REGULATOR_MODE_STANDBY;
114 break;
115 default:
116 return -EINVAL;
117 }
118
119 return mode;
120}
121
122static int pv88080_buck_set_mode(struct regulator_dev *rdev,
123 unsigned int mode)
124{
125 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
126 int val = 0;
127
128 switch (mode) {
129 case REGULATOR_MODE_FAST:
130 val = PV88080_BUCK_MODE_SYNC;
131 break;
132 case REGULATOR_MODE_NORMAL:
133 val = PV88080_BUCK_MODE_AUTO;
134 break;
135 case REGULATOR_MODE_STANDBY:
136 val = PV88080_BUCK_MODE_SLEEP;
137 break;
138 default:
139 return -EINVAL;
140 }
141
142 return regmap_update_bits(rdev->regmap, info->conf,
143 PV88080_BUCK1_MODE_MASK, val);
144}
145
146static int pv88080_set_current_limit(struct regulator_dev *rdev, int min,
147 int max)
148{
149 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
150 int i;
151
152 /* search for closest to maximum */
153 for (i = info->n_current_limits; i >= 0; i--) {
154 if (min <= info->current_limits[i]
155 && max >= info->current_limits[i]) {
156 return regmap_update_bits(rdev->regmap,
157 info->conf,
158 info->limit_mask,
159 i << PV88080_BUCK1_ILIM_SHIFT);
160 }
161 }
162
163 return -EINVAL;
164}
165
166static int pv88080_get_current_limit(struct regulator_dev *rdev)
167{
168 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
169 unsigned int data;
170 int ret;
171
172 ret = regmap_read(rdev->regmap, info->conf, &data);
173 if (ret < 0)
174 return ret;
175
176 data = (data & info->limit_mask) >> PV88080_BUCK1_ILIM_SHIFT;
177 return info->current_limits[data];
178}
179
180static struct regulator_ops pv88080_buck_ops = {
181 .get_mode = pv88080_buck_get_mode,
182 .set_mode = pv88080_buck_set_mode,
183 .enable = regulator_enable_regmap,
184 .disable = regulator_disable_regmap,
185 .is_enabled = regulator_is_enabled_regmap,
186 .set_voltage_sel = regulator_set_voltage_sel_regmap,
187 .get_voltage_sel = regulator_get_voltage_sel_regmap,
188 .list_voltage = regulator_list_voltage_linear,
189 .set_current_limit = pv88080_set_current_limit,
190 .get_current_limit = pv88080_get_current_limit,
191};
192
193#define PV88080_BUCK(chip, regl_name, min, step, max, limits_array) \
194{\
195 .desc = {\
196 .id = chip##_ID_##regl_name,\
197 .name = __stringify(chip##_##regl_name),\
198 .of_match = of_match_ptr(#regl_name),\
199 .regulators_node = of_match_ptr("regulators"),\
200 .type = REGULATOR_VOLTAGE,\
201 .owner = THIS_MODULE,\
202 .ops = &pv88080_buck_ops,\
203 .min_uV = min, \
204 .uV_step = step, \
205 .n_voltages = ((max) - (min))/(step) + 1, \
206 .enable_reg = PV88080_REG_##regl_name##_CONF0, \
207 .enable_mask = PV88080_##regl_name##_EN, \
208 .vsel_reg = PV88080_REG_##regl_name##_CONF0, \
209 .vsel_mask = PV88080_V##regl_name##_MASK, \
210 },\
211 .current_limits = limits_array, \
212 .n_current_limits = ARRAY_SIZE(limits_array), \
213 .limit_mask = PV88080_##regl_name##_ILIM_MASK, \
214 .conf = PV88080_REG_##regl_name##_CONF1, \
215 .conf2 = PV88080_REG_##regl_name##_CONF2, \
216 .conf5 = PV88080_REG_##regl_name##_CONF5, \
217}
218
219static struct pv88080_regulator pv88080_regulator_info[] = {
220 PV88080_BUCK(PV88080, BUCK1, 600000, 6250, 1393750,
221 pv88080_buck1_limits),
222 PV88080_BUCK(PV88080, BUCK2, 600000, 6250, 1393750,
223 pv88080_buck23_limits),
224 PV88080_BUCK(PV88080, BUCK3, 600000, 6250, 1393750,
225 pv88080_buck23_limits),
226};
227
228static irqreturn_t pv88080_irq_handler(int irq, void *data)
229{
230 struct pv88080 *chip = data;
231 int i, reg_val, err, ret = IRQ_NONE;
232
233 err = regmap_read(chip->regmap, PV88080_REG_EVENT_A, &reg_val);
234 if (err < 0)
235 goto error_i2c;
236
237 if (reg_val & PV88080_E_VDD_FLT) {
238 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
239 if (chip->rdev[i] != NULL) {
240 regulator_notifier_call_chain(chip->rdev[i],
241 REGULATOR_EVENT_UNDER_VOLTAGE,
242 NULL);
243 }
244 }
245
246 err = regmap_write(chip->regmap, PV88080_REG_EVENT_A,
247 PV88080_E_VDD_FLT);
248 if (err < 0)
249 goto error_i2c;
250
251 ret = IRQ_HANDLED;
252 }
253
254 if (reg_val & PV88080_E_OVER_TEMP) {
255 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
256 if (chip->rdev[i] != NULL) {
257 regulator_notifier_call_chain(chip->rdev[i],
258 REGULATOR_EVENT_OVER_TEMP,
259 NULL);
260 }
261 }
262
263 err = regmap_write(chip->regmap, PV88080_REG_EVENT_A,
264 PV88080_E_OVER_TEMP);
265 if (err < 0)
266 goto error_i2c;
267
268 ret = IRQ_HANDLED;
269 }
270
271 return ret;
272
273error_i2c:
274 dev_err(chip->dev, "I2C error : %d\n", err);
275 return IRQ_NONE;
276}
277
278/*
279 * I2C driver interface functions
280 */
281static int pv88080_i2c_probe(struct i2c_client *i2c,
282 const struct i2c_device_id *id)
283{
284 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
285 struct pv88080 *chip;
286 struct regulator_config config = { };
287 int i, error, ret;
288 unsigned int conf2, conf5;
289
290 chip = devm_kzalloc(&i2c->dev, sizeof(struct pv88080), GFP_KERNEL);
291 if (!chip)
292 return -ENOMEM;
293
294 chip->dev = &i2c->dev;
295 chip->regmap = devm_regmap_init_i2c(i2c, &pv88080_regmap_config);
296 if (IS_ERR(chip->regmap)) {
297 error = PTR_ERR(chip->regmap);
298 dev_err(chip->dev, "Failed to allocate register map: %d\n",
299 error);
300 return error;
301 }
302
303 i2c_set_clientdata(i2c, chip);
304
305 if (i2c->irq != 0) {
306 ret = regmap_write(chip->regmap, PV88080_REG_MASK_A, 0xFF);
307 if (ret < 0) {
308 dev_err(chip->dev,
309 "Failed to mask A reg: %d\n", ret);
310 return ret;
311 }
312 ret = regmap_write(chip->regmap, PV88080_REG_MASK_B, 0xFF);
313 if (ret < 0) {
314 dev_err(chip->dev,
315 "Failed to mask B reg: %d\n", ret);
316 return ret;
317 }
318 ret = regmap_write(chip->regmap, PV88080_REG_MASK_C, 0xFF);
319 if (ret < 0) {
320 dev_err(chip->dev,
321 "Failed to mask C reg: %d\n", ret);
322 return ret;
323 }
324
325 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
326 pv88080_irq_handler,
327 IRQF_TRIGGER_LOW|IRQF_ONESHOT,
328 "pv88080", chip);
329 if (ret != 0) {
330 dev_err(chip->dev, "Failed to request IRQ: %d\n",
331 i2c->irq);
332 return ret;
333 }
334
335 ret = regmap_update_bits(chip->regmap, PV88080_REG_MASK_A,
336 PV88080_M_VDD_FLT | PV88080_M_OVER_TEMP, 0);
337 if (ret < 0) {
338 dev_err(chip->dev,
339 "Failed to update mask reg: %d\n", ret);
340 return ret;
341 }
342
343 } else {
344 dev_warn(chip->dev, "No IRQ configured\n");
345 }
346
347 config.dev = chip->dev;
348 config.regmap = chip->regmap;
349
350 for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
351 if (init_data)
352 config.init_data = &init_data[i];
353
354 ret = regmap_read(chip->regmap,
355 pv88080_regulator_info[i].conf2, &conf2);
356 if (ret < 0)
357 return ret;
358
359 conf2 = ((conf2 >> PV88080_BUCK_VDAC_RANGE_SHIFT) &
360 PV88080_BUCK_VDAC_RANGE_MASK);
361
362 ret = regmap_read(chip->regmap,
363 pv88080_regulator_info[i].conf5, &conf5);
364 if (ret < 0)
365 return ret;
366
367 conf5 = ((conf5 >> PV88080_BUCK_VRANGE_GAIN_SHIFT) &
368 PV88080_BUCK_VRANGE_GAIN_MASK);
369
370 pv88080_regulator_info[i].desc.min_uV =
371 pv88080_buck_vol[conf2].min_uV * (conf5+1);
372 pv88080_regulator_info[i].desc.uV_step =
373 pv88080_buck_vol[conf2].uV_step * (conf5+1);
374 pv88080_regulator_info[i].desc.n_voltages =
375 ((pv88080_buck_vol[conf2].max_uV * (conf5+1))
376 - (pv88080_regulator_info[i].desc.min_uV))
377 /(pv88080_regulator_info[i].desc.uV_step) + 1;
378
379 config.driver_data = (void *)&pv88080_regulator_info[i];
380 chip->rdev[i] = devm_regulator_register(chip->dev,
381 &pv88080_regulator_info[i].desc, &config);
382 if (IS_ERR(chip->rdev[i])) {
383 dev_err(chip->dev,
384 "Failed to register PV88080 regulator\n");
385 return PTR_ERR(chip->rdev[i]);
386 }
387 }
388
389 return 0;
390}
391
392static const struct i2c_device_id pv88080_i2c_id[] = {
393 {"pv88080", 0},
394 {},
395};
396MODULE_DEVICE_TABLE(i2c, pv88080_i2c_id);
397
398#ifdef CONFIG_OF
399static const struct of_device_id pv88080_dt_ids[] = {
400 { .compatible = "pvs,pv88080", .data = &pv88080_i2c_id[0] },
401 {},
402};
403MODULE_DEVICE_TABLE(of, pv88080_dt_ids);
404#endif
405
406static struct i2c_driver pv88080_regulator_driver = {
407 .driver = {
408 .name = "pv88080",
409 .of_match_table = of_match_ptr(pv88080_dt_ids),
410 },
411 .probe = pv88080_i2c_probe,
412 .id_table = pv88080_i2c_id,
413};
414
415module_i2c_driver(pv88080_regulator_driver);
416
417MODULE_AUTHOR("James Ban <James.Ban.opensource@diasemi.com>");
418MODULE_DESCRIPTION("Regulator device driver for Powerventure PV88080");
419MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/pv88080-regulator.h b/drivers/regulator/pv88080-regulator.h
new file mode 100644
index 000000000000..5e9afde606f4
--- /dev/null
+++ b/drivers/regulator/pv88080-regulator.h
@@ -0,0 +1,92 @@
1/*
2 * pv88080-regulator.h - Regulator definitions for PV88080
3 * Copyright (C) 2016 Powerventure Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef __PV88080_REGISTERS_H__
17#define __PV88080_REGISTERS_H__
18
19/* System Control and Event Registers */
20#define PV88080_REG_EVENT_A 0x04
21#define PV88080_REG_MASK_A 0x09
22#define PV88080_REG_MASK_B 0x0a
23#define PV88080_REG_MASK_C 0x0b
24
25/* Regulator Registers */
26#define PV88080_REG_BUCK1_CONF0 0x27
27#define PV88080_REG_BUCK1_CONF1 0x28
28#define PV88080_REG_BUCK1_CONF2 0x59
29#define PV88080_REG_BUCK1_CONF5 0x5c
30#define PV88080_REG_BUCK2_CONF0 0x29
31#define PV88080_REG_BUCK2_CONF1 0x2a
32#define PV88080_REG_BUCK2_CONF2 0x61
33#define PV88080_REG_BUCK2_CONF5 0x64
34#define PV88080_REG_BUCK3_CONF0 0x2b
35#define PV88080_REG_BUCK3_CONF1 0x2c
36#define PV88080_REG_BUCK3_CONF2 0x69
37#define PV88080_REG_BUCK3_CONF5 0x6c
38
39/* PV88080_REG_EVENT_A (addr=0x04) */
40#define PV88080_E_VDD_FLT 0x01
41#define PV88080_E_OVER_TEMP 0x02
42
43/* PV88080_REG_MASK_A (addr=0x09) */
44#define PV88080_M_VDD_FLT 0x01
45#define PV88080_M_OVER_TEMP 0x02
46
47/* PV88080_REG_BUCK1_CONF0 (addr=0x27) */
48#define PV88080_BUCK1_EN 0x80
49#define PV88080_VBUCK1_MASK 0x7F
50/* PV88080_REG_BUCK2_CONF0 (addr=0x29) */
51#define PV88080_BUCK2_EN 0x80
52#define PV88080_VBUCK2_MASK 0x7F
53/* PV88080_REG_BUCK3_CONF0 (addr=0x2b) */
54#define PV88080_BUCK3_EN 0x80
55#define PV88080_VBUCK3_MASK 0x7F
56
57/* PV88080_REG_BUCK1_CONF1 (addr=0x28) */
58#define PV88080_BUCK1_ILIM_SHIFT 2
59#define PV88080_BUCK1_ILIM_MASK 0x0C
60#define PV88080_BUCK1_MODE_MASK 0x03
61
62/* PV88080_REG_BUCK2_CONF1 (addr=0x2a) */
63#define PV88080_BUCK2_ILIM_SHIFT 2
64#define PV88080_BUCK2_ILIM_MASK 0x0C
65#define PV88080_BUCK2_MODE_MASK 0x03
66
67/* PV88080_REG_BUCK3_CONF1 (addr=0x2c) */
68#define PV88080_BUCK3_ILIM_SHIFT 2
69#define PV88080_BUCK3_ILIM_MASK 0x0C
70#define PV88080_BUCK3_MODE_MASK 0x03
71
72#define PV88080_BUCK_MODE_SLEEP 0x00
73#define PV88080_BUCK_MODE_AUTO 0x01
74#define PV88080_BUCK_MODE_SYNC 0x02
75
76/* PV88080_REG_BUCK2_CONF2 (addr=0x61) */
77/* PV88080_REG_BUCK3_CONF2 (addr=0x69) */
78#define PV88080_BUCK_VDAC_RANGE_SHIFT 7
79#define PV88080_BUCK_VDAC_RANGE_MASK 0x01
80
81#define PV88080_BUCK_VDAC_RANGE_1 0x00
82#define PV88080_BUCK_VDAC_RANGE_2 0x01
83
84/* PV88080_REG_BUCK2_CONF5 (addr=0x64) */
85/* PV88080_REG_BUCK3_CONF5 (addr=0x6c) */
86#define PV88080_BUCK_VRANGE_GAIN_SHIFT 0
87#define PV88080_BUCK_VRANGE_GAIN_MASK 0x01
88
89#define PV88080_BUCK_VRANGE_GAIN_1 0x00
90#define PV88080_BUCK_VRANGE_GAIN_2 0x01
91
92#endif /* __PV88080_REGISTERS_H__ */
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index 4689d62f4841..fafa3488e960 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -59,18 +59,18 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
59 unsigned selector) 59 unsigned selector)
60{ 60{
61 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); 61 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
62 unsigned int pwm_reg_period; 62 struct pwm_args pargs;
63 int dutycycle; 63 int dutycycle;
64 int ret; 64 int ret;
65 65
66 pwm_reg_period = pwm_get_period(drvdata->pwm); 66 pwm_get_args(drvdata->pwm, &pargs);
67 67
68 dutycycle = (pwm_reg_period * 68 dutycycle = (pargs.period *
69 drvdata->duty_cycle_table[selector].dutycycle) / 100; 69 drvdata->duty_cycle_table[selector].dutycycle) / 100;
70 70
71 ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period); 71 ret = pwm_config(drvdata->pwm, dutycycle, pargs.period);
72 if (ret) { 72 if (ret) {
73 dev_err(&rdev->dev, "Failed to configure PWM\n"); 73 dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
74 return ret; 74 return ret;
75 } 75 }
76 76
@@ -113,18 +113,6 @@ static int pwm_regulator_is_enabled(struct regulator_dev *dev)
113 return pwm_is_enabled(drvdata->pwm); 113 return pwm_is_enabled(drvdata->pwm);
114} 114}
115 115
116/**
117 * Continuous voltage call-backs
118 */
119static int pwm_voltage_to_duty_cycle_percentage(struct regulator_dev *rdev, int req_uV)
120{
121 int min_uV = rdev->constraints->min_uV;
122 int max_uV = rdev->constraints->max_uV;
123 int diff = max_uV - min_uV;
124
125 return ((req_uV * 100) - (min_uV * 100)) / diff;
126}
127
128static int pwm_regulator_get_voltage(struct regulator_dev *rdev) 116static int pwm_regulator_get_voltage(struct regulator_dev *rdev)
129{ 117{
130 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); 118 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
@@ -138,21 +126,42 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
138{ 126{
139 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); 127 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
140 unsigned int ramp_delay = rdev->constraints->ramp_delay; 128 unsigned int ramp_delay = rdev->constraints->ramp_delay;
141 unsigned int period = pwm_get_period(drvdata->pwm); 129 struct pwm_args pargs;
142 int duty_cycle; 130 unsigned int req_diff = min_uV - rdev->constraints->min_uV;
131 unsigned int diff;
132 unsigned int duty_pulse;
133 u64 req_period;
134 u32 rem;
143 int ret; 135 int ret;
144 136
145 duty_cycle = pwm_voltage_to_duty_cycle_percentage(rdev, min_uV); 137 pwm_get_args(drvdata->pwm, &pargs);
138 diff = rdev->constraints->max_uV - rdev->constraints->min_uV;
139
140 /* First try to find out if we get the iduty cycle time which is
141 * factor of PWM period time. If (request_diff_to_min * pwm_period)
142 * is perfect divided by voltage_range_diff then it is possible to
143 * get duty cycle time which is factor of PWM period. This will help
144 * to get output voltage nearer to requested value as there is no
145 * calculation loss.
146 */
147 req_period = req_diff * pargs.period;
148 div_u64_rem(req_period, diff, &rem);
149 if (!rem) {
150 do_div(req_period, diff);
151 duty_pulse = (unsigned int)req_period;
152 } else {
153 duty_pulse = (pargs.period / 100) * ((req_diff * 100) / diff);
154 }
146 155
147 ret = pwm_config(drvdata->pwm, (period / 100) * duty_cycle, period); 156 ret = pwm_config(drvdata->pwm, duty_pulse, pargs.period);
148 if (ret) { 157 if (ret) {
149 dev_err(&rdev->dev, "Failed to configure PWM\n"); 158 dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
150 return ret; 159 return ret;
151 } 160 }
152 161
153 ret = pwm_enable(drvdata->pwm); 162 ret = pwm_enable(drvdata->pwm);
154 if (ret) { 163 if (ret) {
155 dev_err(&rdev->dev, "Failed to enable PWM\n"); 164 dev_err(&rdev->dev, "Failed to enable PWM: %d\n", ret);
156 return ret; 165 return ret;
157 } 166 }
158 drvdata->volt_uV = min_uV; 167 drvdata->volt_uV = min_uV;
@@ -200,8 +209,7 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
200 209
201 if ((length < sizeof(*duty_cycle_table)) || 210 if ((length < sizeof(*duty_cycle_table)) ||
202 (length % sizeof(*duty_cycle_table))) { 211 (length % sizeof(*duty_cycle_table))) {
203 dev_err(&pdev->dev, 212 dev_err(&pdev->dev, "voltage-table length(%d) is invalid\n",
204 "voltage-table length(%d) is invalid\n",
205 length); 213 length);
206 return -EINVAL; 214 return -EINVAL;
207 } 215 }
@@ -214,7 +222,7 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
214 (u32 *)duty_cycle_table, 222 (u32 *)duty_cycle_table,
215 length / sizeof(u32)); 223 length / sizeof(u32));
216 if (ret) { 224 if (ret) {
217 dev_err(&pdev->dev, "Failed to read voltage-table\n"); 225 dev_err(&pdev->dev, "Failed to read voltage-table: %d\n", ret);
218 return ret; 226 return ret;
219 } 227 }
220 228
@@ -277,16 +285,24 @@ static int pwm_regulator_probe(struct platform_device *pdev)
277 285
278 drvdata->pwm = devm_pwm_get(&pdev->dev, NULL); 286 drvdata->pwm = devm_pwm_get(&pdev->dev, NULL);
279 if (IS_ERR(drvdata->pwm)) { 287 if (IS_ERR(drvdata->pwm)) {
280 dev_err(&pdev->dev, "Failed to get PWM\n"); 288 ret = PTR_ERR(drvdata->pwm);
281 return PTR_ERR(drvdata->pwm); 289 dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);
290 return ret;
282 } 291 }
283 292
293 /*
294 * FIXME: pwm_apply_args() should be removed when switching to the
295 * atomic PWM API.
296 */
297 pwm_apply_args(drvdata->pwm);
298
284 regulator = devm_regulator_register(&pdev->dev, 299 regulator = devm_regulator_register(&pdev->dev,
285 &drvdata->desc, &config); 300 &drvdata->desc, &config);
286 if (IS_ERR(regulator)) { 301 if (IS_ERR(regulator)) {
287 dev_err(&pdev->dev, "Failed to register regulator %s\n", 302 ret = PTR_ERR(regulator);
288 drvdata->desc.name); 303 dev_err(&pdev->dev, "Failed to register regulator %s: %d\n",
289 return PTR_ERR(regulator); 304 drvdata->desc.name, ret);
305 return ret;
290 } 306 }
291 307
292 return 0; 308 return 0;
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index 88a5dc88badc..84cce21e98cd 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -246,6 +246,7 @@ enum spmi_common_control_register_index {
246 246
247/* Minimum voltage stepper delay for each step. */ 247/* Minimum voltage stepper delay for each step. */
248#define SPMI_FTSMPS_STEP_DELAY 8 248#define SPMI_FTSMPS_STEP_DELAY 8
249#define SPMI_DEFAULT_STEP_DELAY 20
249 250
250/* 251/*
251 * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to 252 * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to
@@ -254,13 +255,6 @@ enum spmi_common_control_register_index {
254#define SPMI_FTSMPS_STEP_MARGIN_NUM 4 255#define SPMI_FTSMPS_STEP_MARGIN_NUM 4
255#define SPMI_FTSMPS_STEP_MARGIN_DEN 5 256#define SPMI_FTSMPS_STEP_MARGIN_DEN 5
256 257
257/*
258 * This voltage in uV is returned by get_voltage functions when there is no way
259 * to determine the current voltage level. It is needed because the regulator
260 * framework treats a 0 uV voltage as an error.
261 */
262#define VOLTAGE_UNKNOWN 1
263
264/* VSET value to decide the range of ULT SMPS */ 258/* VSET value to decide the range of ULT SMPS */
265#define ULT_SMPS_RANGE_SPLIT 0x60 259#define ULT_SMPS_RANGE_SPLIT 0x60
266 260
@@ -539,12 +533,12 @@ static int spmi_regulator_common_disable(struct regulator_dev *rdev)
539} 533}
540 534
541static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, 535static int spmi_regulator_select_voltage(struct spmi_regulator *vreg,
542 int min_uV, int max_uV, u8 *range_sel, u8 *voltage_sel, 536 int min_uV, int max_uV)
543 unsigned *selector)
544{ 537{
545 const struct spmi_voltage_range *range; 538 const struct spmi_voltage_range *range;
546 int uV = min_uV; 539 int uV = min_uV;
547 int lim_min_uV, lim_max_uV, i, range_id, range_max_uV; 540 int lim_min_uV, lim_max_uV, i, range_id, range_max_uV;
541 int selector, voltage_sel;
548 542
549 /* Check if request voltage is outside of physically settable range. */ 543 /* Check if request voltage is outside of physically settable range. */
550 lim_min_uV = vreg->set_points->range[0].set_point_min_uV; 544 lim_min_uV = vreg->set_points->range[0].set_point_min_uV;
@@ -570,14 +564,13 @@ static int spmi_regulator_select_voltage(struct spmi_regulator *vreg,
570 564
571 range_id = i; 565 range_id = i;
572 range = &vreg->set_points->range[range_id]; 566 range = &vreg->set_points->range[range_id];
573 *range_sel = range->range_sel;
574 567
575 /* 568 /*
576 * Force uV to be an allowed set point by applying a ceiling function to 569 * Force uV to be an allowed set point by applying a ceiling function to
577 * the uV value. 570 * the uV value.
578 */ 571 */
579 *voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 572 voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV);
580 uV = *voltage_sel * range->step_uV + range->min_uV; 573 uV = voltage_sel * range->step_uV + range->min_uV;
581 574
582 if (uV > max_uV) { 575 if (uV > max_uV) {
583 dev_err(vreg->dev, 576 dev_err(vreg->dev,
@@ -587,12 +580,48 @@ static int spmi_regulator_select_voltage(struct spmi_regulator *vreg,
587 return -EINVAL; 580 return -EINVAL;
588 } 581 }
589 582
590 *selector = 0; 583 selector = 0;
591 for (i = 0; i < range_id; i++) 584 for (i = 0; i < range_id; i++)
592 *selector += vreg->set_points->range[i].n_voltages; 585 selector += vreg->set_points->range[i].n_voltages;
593 *selector += (uV - range->set_point_min_uV) / range->step_uV; 586 selector += (uV - range->set_point_min_uV) / range->step_uV;
594 587
595 return 0; 588 return selector;
589}
590
591static int spmi_sw_selector_to_hw(struct spmi_regulator *vreg,
592 unsigned selector, u8 *range_sel,
593 u8 *voltage_sel)
594{
595 const struct spmi_voltage_range *range, *end;
596
597 range = vreg->set_points->range;
598 end = range + vreg->set_points->count;
599
600 for (; range < end; range++) {
601 if (selector < range->n_voltages) {
602 *voltage_sel = selector;
603 *range_sel = range->range_sel;
604 return 0;
605 }
606
607 selector -= range->n_voltages;
608 }
609
610 return -EINVAL;
611}
612
613static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel,
614 const struct spmi_voltage_range *range)
615{
616 int sw_sel = hw_sel;
617 const struct spmi_voltage_range *r = vreg->set_points->range;
618
619 while (r != range) {
620 sw_sel += r->n_voltages;
621 r++;
622 }
623
624 return sw_sel;
596} 625}
597 626
598static const struct spmi_voltage_range * 627static const struct spmi_voltage_range *
@@ -614,12 +643,11 @@ spmi_regulator_find_range(struct spmi_regulator *vreg)
614} 643}
615 644
616static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg, 645static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg,
617 int min_uV, int max_uV, u8 *range_sel, u8 *voltage_sel, 646 int min_uV, int max_uV)
618 unsigned *selector)
619{ 647{
620 const struct spmi_voltage_range *range; 648 const struct spmi_voltage_range *range;
621 int uV = min_uV; 649 int uV = min_uV;
622 int i; 650 int i, selector;
623 651
624 range = spmi_regulator_find_range(vreg); 652 range = spmi_regulator_find_range(vreg);
625 if (!range) 653 if (!range)
@@ -637,8 +665,8 @@ static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg,
637 * Force uV to be an allowed set point by applying a ceiling function to 665 * Force uV to be an allowed set point by applying a ceiling function to
638 * the uV value. 666 * the uV value.
639 */ 667 */
640 *voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 668 uV = DIV_ROUND_UP(uV - range->min_uV, range->step_uV);
641 uV = *voltage_sel * range->step_uV + range->min_uV; 669 uV = uV * range->step_uV + range->min_uV;
642 670
643 if (uV > max_uV) { 671 if (uV > max_uV) {
644 /* 672 /*
@@ -648,43 +676,49 @@ static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg,
648 goto different_range; 676 goto different_range;
649 } 677 }
650 678
651 *selector = 0; 679 selector = 0;
652 for (i = 0; i < vreg->set_points->count; i++) { 680 for (i = 0; i < vreg->set_points->count; i++) {
653 if (uV >= vreg->set_points->range[i].set_point_min_uV 681 if (uV >= vreg->set_points->range[i].set_point_min_uV
654 && uV <= vreg->set_points->range[i].set_point_max_uV) { 682 && uV <= vreg->set_points->range[i].set_point_max_uV) {
655 *selector += 683 selector +=
656 (uV - vreg->set_points->range[i].set_point_min_uV) 684 (uV - vreg->set_points->range[i].set_point_min_uV)
657 / vreg->set_points->range[i].step_uV; 685 / vreg->set_points->range[i].step_uV;
658 break; 686 break;
659 } 687 }
660 688
661 *selector += vreg->set_points->range[i].n_voltages; 689 selector += vreg->set_points->range[i].n_voltages;
662 } 690 }
663 691
664 if (*selector >= vreg->set_points->n_voltages) 692 if (selector >= vreg->set_points->n_voltages)
665 goto different_range; 693 goto different_range;
666 694
667 return 0; 695 return selector;
668 696
669different_range: 697different_range:
670 return spmi_regulator_select_voltage(vreg, min_uV, max_uV, 698 return spmi_regulator_select_voltage(vreg, min_uV, max_uV);
671 range_sel, voltage_sel, selector);
672} 699}
673 700
674static int spmi_regulator_common_set_voltage(struct regulator_dev *rdev, 701static int spmi_regulator_common_map_voltage(struct regulator_dev *rdev,
675 int min_uV, int max_uV, unsigned *selector) 702 int min_uV, int max_uV)
676{ 703{
677 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 704 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
678 int ret;
679 u8 buf[2];
680 u8 range_sel, voltage_sel;
681 705
682 /* 706 /*
683 * Favor staying in the current voltage range if possible. This avoids 707 * Favor staying in the current voltage range if possible. This avoids
684 * voltage spikes that occur when changing the voltage range. 708 * voltage spikes that occur when changing the voltage range.
685 */ 709 */
686 ret = spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV, 710 return spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV);
687 &range_sel, &voltage_sel, selector); 711}
712
713static int
714spmi_regulator_common_set_voltage(struct regulator_dev *rdev, unsigned selector)
715{
716 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
717 int ret;
718 u8 buf[2];
719 u8 range_sel, voltage_sel;
720
721 ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel);
688 if (ret) 722 if (ret)
689 return ret; 723 return ret;
690 724
@@ -719,24 +753,24 @@ static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev)
719 753
720 range = spmi_regulator_find_range(vreg); 754 range = spmi_regulator_find_range(vreg);
721 if (!range) 755 if (!range)
722 return VOLTAGE_UNKNOWN; 756 return -EINVAL;
723 757
724 return range->step_uV * voltage_sel + range->min_uV; 758 return spmi_hw_selector_to_sw(vreg, voltage_sel, range);
725} 759}
726 760
727static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev, 761static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev,
728 int min_uV, int max_uV, unsigned *selector) 762 int min_uV, int max_uV)
729{ 763{
730 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 764 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
731 int ret;
732 u8 range_sel, sel;
733 765
734 ret = spmi_regulator_select_voltage(vreg, min_uV, max_uV, &range_sel, 766 return spmi_regulator_select_voltage(vreg, min_uV, max_uV);
735 &sel, selector); 767}
736 if (ret) { 768
737 dev_err(vreg->dev, "could not set voltage, ret=%d\n", ret); 769static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev,
738 return ret; 770 unsigned selector)
739 } 771{
772 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
773 u8 sel = selector;
740 774
741 /* 775 /*
742 * Certain types of regulators do not have a range select register so 776 * Certain types of regulators do not have a range select register so
@@ -748,27 +782,24 @@ static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev,
748static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev) 782static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev)
749{ 783{
750 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 784 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
751 const struct spmi_voltage_range *range = vreg->set_points->range; 785 u8 selector;
752 u8 voltage_sel; 786 int ret;
753 787
754 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); 788 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &selector, 1);
789 if (ret)
790 return ret;
755 791
756 return range->step_uV * voltage_sel + range->min_uV; 792 return selector;
757} 793}
758 794
759static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev, 795static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev,
760 int min_uV, int max_uV, unsigned *selector) 796 unsigned selector)
761{ 797{
762 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 798 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
763 int ret; 799 int ret;
764 u8 range_sel, voltage_sel; 800 u8 range_sel, voltage_sel;
765 801
766 /* 802 ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel);
767 * Favor staying in the current voltage range if possible. This avoids
768 * voltage spikes that occur when changing the voltage range.
769 */
770 ret = spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV,
771 &range_sel, &voltage_sel, selector);
772 if (ret) 803 if (ret)
773 return ret; 804 return ret;
774 805
@@ -783,7 +814,7 @@ static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev,
783 voltage_sel |= ULT_SMPS_RANGE_SPLIT; 814 voltage_sel |= ULT_SMPS_RANGE_SPLIT;
784 815
785 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET, 816 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET,
786 voltage_sel, 0xff); 817 voltage_sel, 0xff);
787} 818}
788 819
789static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev) 820static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev)
@@ -796,12 +827,12 @@ static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev)
796 827
797 range = spmi_regulator_find_range(vreg); 828 range = spmi_regulator_find_range(vreg);
798 if (!range) 829 if (!range)
799 return VOLTAGE_UNKNOWN; 830 return -EINVAL;
800 831
801 if (range->range_sel == 1) 832 if (range->range_sel == 1)
802 voltage_sel &= ~ULT_SMPS_RANGE_SPLIT; 833 voltage_sel &= ~ULT_SMPS_RANGE_SPLIT;
803 834
804 return range->step_uV * voltage_sel + range->min_uV; 835 return spmi_hw_selector_to_sw(vreg, voltage_sel, range);
805} 836}
806 837
807static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev, 838static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev,
@@ -1007,8 +1038,10 @@ static struct regulator_ops spmi_smps_ops = {
1007 .enable = spmi_regulator_common_enable, 1038 .enable = spmi_regulator_common_enable,
1008 .disable = spmi_regulator_common_disable, 1039 .disable = spmi_regulator_common_disable,
1009 .is_enabled = spmi_regulator_common_is_enabled, 1040 .is_enabled = spmi_regulator_common_is_enabled,
1010 .set_voltage = spmi_regulator_common_set_voltage, 1041 .set_voltage_sel = spmi_regulator_common_set_voltage,
1011 .get_voltage = spmi_regulator_common_get_voltage, 1042 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1043 .get_voltage_sel = spmi_regulator_common_get_voltage,
1044 .map_voltage = spmi_regulator_common_map_voltage,
1012 .list_voltage = spmi_regulator_common_list_voltage, 1045 .list_voltage = spmi_regulator_common_list_voltage,
1013 .set_mode = spmi_regulator_common_set_mode, 1046 .set_mode = spmi_regulator_common_set_mode,
1014 .get_mode = spmi_regulator_common_get_mode, 1047 .get_mode = spmi_regulator_common_get_mode,
@@ -1020,8 +1053,9 @@ static struct regulator_ops spmi_ldo_ops = {
1020 .enable = spmi_regulator_common_enable, 1053 .enable = spmi_regulator_common_enable,
1021 .disable = spmi_regulator_common_disable, 1054 .disable = spmi_regulator_common_disable,
1022 .is_enabled = spmi_regulator_common_is_enabled, 1055 .is_enabled = spmi_regulator_common_is_enabled,
1023 .set_voltage = spmi_regulator_common_set_voltage, 1056 .set_voltage_sel = spmi_regulator_common_set_voltage,
1024 .get_voltage = spmi_regulator_common_get_voltage, 1057 .get_voltage_sel = spmi_regulator_common_get_voltage,
1058 .map_voltage = spmi_regulator_common_map_voltage,
1025 .list_voltage = spmi_regulator_common_list_voltage, 1059 .list_voltage = spmi_regulator_common_list_voltage,
1026 .set_mode = spmi_regulator_common_set_mode, 1060 .set_mode = spmi_regulator_common_set_mode,
1027 .get_mode = spmi_regulator_common_get_mode, 1061 .get_mode = spmi_regulator_common_get_mode,
@@ -1036,8 +1070,9 @@ static struct regulator_ops spmi_ln_ldo_ops = {
1036 .enable = spmi_regulator_common_enable, 1070 .enable = spmi_regulator_common_enable,
1037 .disable = spmi_regulator_common_disable, 1071 .disable = spmi_regulator_common_disable,
1038 .is_enabled = spmi_regulator_common_is_enabled, 1072 .is_enabled = spmi_regulator_common_is_enabled,
1039 .set_voltage = spmi_regulator_common_set_voltage, 1073 .set_voltage_sel = spmi_regulator_common_set_voltage,
1040 .get_voltage = spmi_regulator_common_get_voltage, 1074 .get_voltage_sel = spmi_regulator_common_get_voltage,
1075 .map_voltage = spmi_regulator_common_map_voltage,
1041 .list_voltage = spmi_regulator_common_list_voltage, 1076 .list_voltage = spmi_regulator_common_list_voltage,
1042 .set_bypass = spmi_regulator_common_set_bypass, 1077 .set_bypass = spmi_regulator_common_set_bypass,
1043 .get_bypass = spmi_regulator_common_get_bypass, 1078 .get_bypass = spmi_regulator_common_get_bypass,
@@ -1056,8 +1091,9 @@ static struct regulator_ops spmi_boost_ops = {
1056 .enable = spmi_regulator_common_enable, 1091 .enable = spmi_regulator_common_enable,
1057 .disable = spmi_regulator_common_disable, 1092 .disable = spmi_regulator_common_disable,
1058 .is_enabled = spmi_regulator_common_is_enabled, 1093 .is_enabled = spmi_regulator_common_is_enabled,
1059 .set_voltage = spmi_regulator_single_range_set_voltage, 1094 .set_voltage_sel = spmi_regulator_single_range_set_voltage,
1060 .get_voltage = spmi_regulator_single_range_get_voltage, 1095 .get_voltage_sel = spmi_regulator_single_range_get_voltage,
1096 .map_voltage = spmi_regulator_single_map_voltage,
1061 .list_voltage = spmi_regulator_common_list_voltage, 1097 .list_voltage = spmi_regulator_common_list_voltage,
1062 .set_input_current_limit = spmi_regulator_set_ilim, 1098 .set_input_current_limit = spmi_regulator_set_ilim,
1063}; 1099};
@@ -1066,9 +1102,10 @@ static struct regulator_ops spmi_ftsmps_ops = {
1066 .enable = spmi_regulator_common_enable, 1102 .enable = spmi_regulator_common_enable,
1067 .disable = spmi_regulator_common_disable, 1103 .disable = spmi_regulator_common_disable,
1068 .is_enabled = spmi_regulator_common_is_enabled, 1104 .is_enabled = spmi_regulator_common_is_enabled,
1069 .set_voltage = spmi_regulator_common_set_voltage, 1105 .set_voltage_sel = spmi_regulator_common_set_voltage,
1070 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 1106 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1071 .get_voltage = spmi_regulator_common_get_voltage, 1107 .get_voltage_sel = spmi_regulator_common_get_voltage,
1108 .map_voltage = spmi_regulator_common_map_voltage,
1072 .list_voltage = spmi_regulator_common_list_voltage, 1109 .list_voltage = spmi_regulator_common_list_voltage,
1073 .set_mode = spmi_regulator_common_set_mode, 1110 .set_mode = spmi_regulator_common_set_mode,
1074 .get_mode = spmi_regulator_common_get_mode, 1111 .get_mode = spmi_regulator_common_get_mode,
@@ -1080,8 +1117,9 @@ static struct regulator_ops spmi_ult_lo_smps_ops = {
1080 .enable = spmi_regulator_common_enable, 1117 .enable = spmi_regulator_common_enable,
1081 .disable = spmi_regulator_common_disable, 1118 .disable = spmi_regulator_common_disable,
1082 .is_enabled = spmi_regulator_common_is_enabled, 1119 .is_enabled = spmi_regulator_common_is_enabled,
1083 .set_voltage = spmi_regulator_ult_lo_smps_set_voltage, 1120 .set_voltage_sel = spmi_regulator_ult_lo_smps_set_voltage,
1084 .get_voltage = spmi_regulator_ult_lo_smps_get_voltage, 1121 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1122 .get_voltage_sel = spmi_regulator_ult_lo_smps_get_voltage,
1085 .list_voltage = spmi_regulator_common_list_voltage, 1123 .list_voltage = spmi_regulator_common_list_voltage,
1086 .set_mode = spmi_regulator_common_set_mode, 1124 .set_mode = spmi_regulator_common_set_mode,
1087 .get_mode = spmi_regulator_common_get_mode, 1125 .get_mode = spmi_regulator_common_get_mode,
@@ -1093,8 +1131,10 @@ static struct regulator_ops spmi_ult_ho_smps_ops = {
1093 .enable = spmi_regulator_common_enable, 1131 .enable = spmi_regulator_common_enable,
1094 .disable = spmi_regulator_common_disable, 1132 .disable = spmi_regulator_common_disable,
1095 .is_enabled = spmi_regulator_common_is_enabled, 1133 .is_enabled = spmi_regulator_common_is_enabled,
1096 .set_voltage = spmi_regulator_single_range_set_voltage, 1134 .set_voltage_sel = spmi_regulator_single_range_set_voltage,
1097 .get_voltage = spmi_regulator_single_range_get_voltage, 1135 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1136 .get_voltage_sel = spmi_regulator_single_range_get_voltage,
1137 .map_voltage = spmi_regulator_single_map_voltage,
1098 .list_voltage = spmi_regulator_common_list_voltage, 1138 .list_voltage = spmi_regulator_common_list_voltage,
1099 .set_mode = spmi_regulator_common_set_mode, 1139 .set_mode = spmi_regulator_common_set_mode,
1100 .get_mode = spmi_regulator_common_get_mode, 1140 .get_mode = spmi_regulator_common_get_mode,
@@ -1106,8 +1146,9 @@ static struct regulator_ops spmi_ult_ldo_ops = {
1106 .enable = spmi_regulator_common_enable, 1146 .enable = spmi_regulator_common_enable,
1107 .disable = spmi_regulator_common_disable, 1147 .disable = spmi_regulator_common_disable,
1108 .is_enabled = spmi_regulator_common_is_enabled, 1148 .is_enabled = spmi_regulator_common_is_enabled,
1109 .set_voltage = spmi_regulator_single_range_set_voltage, 1149 .set_voltage_sel = spmi_regulator_single_range_set_voltage,
1110 .get_voltage = spmi_regulator_single_range_get_voltage, 1150 .get_voltage_sel = spmi_regulator_single_range_get_voltage,
1151 .map_voltage = spmi_regulator_single_map_voltage,
1111 .list_voltage = spmi_regulator_common_list_voltage, 1152 .list_voltage = spmi_regulator_common_list_voltage,
1112 .set_mode = spmi_regulator_common_set_mode, 1153 .set_mode = spmi_regulator_common_set_mode,
1113 .get_mode = spmi_regulator_common_get_mode, 1154 .get_mode = spmi_regulator_common_get_mode,
@@ -1201,7 +1242,7 @@ static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type)
1201 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version, 1242 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version,
1202 ARRAY_SIZE(version)); 1243 ARRAY_SIZE(version));
1203 if (ret) { 1244 if (ret) {
1204 dev_err(vreg->dev, "could not read version registers\n"); 1245 dev_dbg(vreg->dev, "could not read version registers\n");
1205 return ret; 1246 return ret;
1206 } 1247 }
1207 dig_major_rev = version[SPMI_COMMON_REG_DIG_MAJOR_REV 1248 dig_major_rev = version[SPMI_COMMON_REG_DIG_MAJOR_REV
@@ -1245,11 +1286,11 @@ found:
1245 return 0; 1286 return 0;
1246} 1287}
1247 1288
1248static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg) 1289static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg)
1249{ 1290{
1250 int ret; 1291 int ret;
1251 u8 reg = 0; 1292 u8 reg = 0;
1252 int step, delay, slew_rate; 1293 int step, delay, slew_rate, step_delay;
1253 const struct spmi_voltage_range *range; 1294 const struct spmi_voltage_range *range;
1254 1295
1255 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1); 1296 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
@@ -1262,6 +1303,15 @@ static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
1262 if (!range) 1303 if (!range)
1263 return -EINVAL; 1304 return -EINVAL;
1264 1305
1306 switch (vreg->logical_type) {
1307 case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS:
1308 step_delay = SPMI_FTSMPS_STEP_DELAY;
1309 break;
1310 default:
1311 step_delay = SPMI_DEFAULT_STEP_DELAY;
1312 break;
1313 }
1314
1265 step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK; 1315 step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK;
1266 step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT; 1316 step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT;
1267 1317
@@ -1270,7 +1320,7 @@ static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
1270 1320
1271 /* slew_rate has units of uV/us */ 1321 /* slew_rate has units of uV/us */
1272 slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step); 1322 slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step);
1273 slew_rate /= 1000 * (SPMI_FTSMPS_STEP_DELAY << delay); 1323 slew_rate /= 1000 * (step_delay << delay);
1274 slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM; 1324 slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM;
1275 slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN; 1325 slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN;
1276 1326
@@ -1411,10 +1461,16 @@ static int spmi_regulator_of_parse(struct device_node *node,
1411 return ret; 1461 return ret;
1412 } 1462 }
1413 1463
1414 if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) { 1464 switch (vreg->logical_type) {
1415 ret = spmi_regulator_ftsmps_init_slew_rate(vreg); 1465 case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS:
1466 case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS:
1467 case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS:
1468 case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
1469 ret = spmi_regulator_init_slew_rate(vreg);
1416 if (ret) 1470 if (ret)
1417 return ret; 1471 return ret;
1472 default:
1473 break;
1418 } 1474 }
1419 1475
1420 if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS) 1476 if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS)
@@ -1510,10 +1566,61 @@ static const struct spmi_regulator_data pm8916_regulators[] = {
1510 { } 1566 { }
1511}; 1567};
1512 1568
1569static const struct spmi_regulator_data pm8994_regulators[] = {
1570 { "s1", 0x1400, "vdd_s1", },
1571 { "s2", 0x1700, "vdd_s2", },
1572 { "s3", 0x1a00, "vdd_s3", },
1573 { "s4", 0x1d00, "vdd_s4", },
1574 { "s5", 0x2000, "vdd_s5", },
1575 { "s6", 0x2300, "vdd_s6", },
1576 { "s7", 0x2600, "vdd_s7", },
1577 { "s8", 0x2900, "vdd_s8", },
1578 { "s9", 0x2c00, "vdd_s9", },
1579 { "s10", 0x2f00, "vdd_s10", },
1580 { "s11", 0x3200, "vdd_s11", },
1581 { "s12", 0x3500, "vdd_s12", },
1582 { "l1", 0x4000, "vdd_l1", },
1583 { "l2", 0x4100, "vdd_l2_l26_l28", },
1584 { "l3", 0x4200, "vdd_l3_l11", },
1585 { "l4", 0x4300, "vdd_l4_l27_l31", },
1586 { "l5", 0x4400, "vdd_l5_l7", },
1587 { "l6", 0x4500, "vdd_l6_l12_l32", },
1588 { "l7", 0x4600, "vdd_l5_l7", },
1589 { "l8", 0x4700, "vdd_l8_l16_l30", },
1590 { "l9", 0x4800, "vdd_l9_l10_l18_l22", },
1591 { "l10", 0x4900, "vdd_l9_l10_l18_l22", },
1592 { "l11", 0x4a00, "vdd_l3_l11", },
1593 { "l12", 0x4b00, "vdd_l6_l12_l32", },
1594 { "l13", 0x4c00, "vdd_l13_l19_l23_l24", },
1595 { "l14", 0x4d00, "vdd_l14_l15", },
1596 { "l15", 0x4e00, "vdd_l14_l15", },
1597 { "l16", 0x4f00, "vdd_l8_l16_l30", },
1598 { "l17", 0x5000, "vdd_l17_l29", },
1599 { "l18", 0x5100, "vdd_l9_l10_l18_l22", },
1600 { "l19", 0x5200, "vdd_l13_l19_l23_l24", },
1601 { "l20", 0x5300, "vdd_l20_l21", },
1602 { "l21", 0x5400, "vdd_l20_l21", },
1603 { "l22", 0x5500, "vdd_l9_l10_l18_l22", },
1604 { "l23", 0x5600, "vdd_l13_l19_l23_l24", },
1605 { "l24", 0x5700, "vdd_l13_l19_l23_l24", },
1606 { "l25", 0x5800, "vdd_l25", },
1607 { "l26", 0x5900, "vdd_l2_l26_l28", },
1608 { "l27", 0x5a00, "vdd_l4_l27_l31", },
1609 { "l28", 0x5b00, "vdd_l2_l26_l28", },
1610 { "l29", 0x5c00, "vdd_l17_l29", },
1611 { "l30", 0x5d00, "vdd_l8_l16_l30", },
1612 { "l31", 0x5e00, "vdd_l4_l27_l31", },
1613 { "l32", 0x5f00, "vdd_l6_l12_l32", },
1614 { "lvs1", 0x8000, "vdd_lvs_1_2", },
1615 { "lvs2", 0x8100, "vdd_lvs_1_2", },
1616 { }
1617};
1618
1513static const struct of_device_id qcom_spmi_regulator_match[] = { 1619static const struct of_device_id qcom_spmi_regulator_match[] = {
1514 { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators }, 1620 { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators },
1515 { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators }, 1621 { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators },
1516 { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators }, 1622 { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators },
1623 { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators },
1517 { } 1624 { }
1518}; 1625};
1519MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match); 1626MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);
@@ -1573,7 +1680,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
1573 1680
1574 ret = spmi_regulator_match(vreg, reg->force_type); 1681 ret = spmi_regulator_match(vreg, reg->force_type);
1575 if (ret) 1682 if (ret)
1576 goto err; 1683 continue;
1577 1684
1578 config.dev = dev; 1685 config.dev = dev;
1579 config.driver_data = vreg; 1686 config.driver_data = vreg;
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index d86a3dcd61e2..40d07ba036e7 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -55,6 +55,42 @@
55/* max steps for increase voltage of Buck1/2, equal 100mv*/ 55/* max steps for increase voltage of Buck1/2, equal 100mv*/
56#define MAX_STEPS_ONE_TIME 8 56#define MAX_STEPS_ONE_TIME 8
57 57
58#define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
59 _vmask, _ereg, _emask, _etime) \
60 [_id] = { \
61 .name = (_match), \
62 .supply_name = (_supply), \
63 .of_match = of_match_ptr(_match), \
64 .regulators_node = of_match_ptr("regulators"), \
65 .type = REGULATOR_VOLTAGE, \
66 .id = (_id), \
67 .n_voltages = (((_max) - (_min)) / (_step) + 1), \
68 .owner = THIS_MODULE, \
69 .min_uV = (_min) * 1000, \
70 .uV_step = (_step) * 1000, \
71 .vsel_reg = (_vreg), \
72 .vsel_mask = (_vmask), \
73 .enable_reg = (_ereg), \
74 .enable_mask = (_emask), \
75 .enable_time = (_etime), \
76 .ops = &rk808_reg_ops, \
77 }
78
79#define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask) \
80 [_id] = { \
81 .name = (_match), \
82 .supply_name = (_supply), \
83 .of_match = of_match_ptr(_match), \
84 .regulators_node = of_match_ptr("regulators"), \
85 .type = REGULATOR_VOLTAGE, \
86 .id = (_id), \
87 .enable_reg = (_ereg), \
88 .enable_mask = (_emask), \
89 .owner = THIS_MODULE, \
90 .ops = &rk808_switch_ops \
91 }
92
93
58struct rk808_regulator_data { 94struct rk808_regulator_data {
59 struct gpio_desc *dvs_gpio[2]; 95 struct gpio_desc *dvs_gpio[2];
60}; 96};
@@ -66,27 +102,11 @@ static const int rk808_buck_config_regs[] = {
66 RK808_BUCK4_CONFIG_REG, 102 RK808_BUCK4_CONFIG_REG,
67}; 103};
68 104
69static const struct regulator_linear_range rk808_buck_voltage_ranges[] = {
70 REGULATOR_LINEAR_RANGE(712500, 0, 63, 12500),
71};
72
73static const struct regulator_linear_range rk808_buck4_voltage_ranges[] = {
74 REGULATOR_LINEAR_RANGE(1800000, 0, 15, 100000),
75};
76
77static const struct regulator_linear_range rk808_ldo_voltage_ranges[] = {
78 REGULATOR_LINEAR_RANGE(1800000, 0, 16, 100000),
79};
80
81static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = { 105static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = {
82 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), 106 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
83 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), 107 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
84}; 108};
85 109
86static const struct regulator_linear_range rk808_ldo6_voltage_ranges[] = {
87 REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000),
88};
89
90static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev) 110static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
91{ 111{
92 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 112 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
@@ -242,6 +262,21 @@ static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
242static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv) 262static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
243{ 263{
244 unsigned int reg; 264 unsigned int reg;
265 int sel = regulator_map_voltage_linear(rdev, uv, uv);
266
267 if (sel < 0)
268 return -EINVAL;
269
270 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
271
272 return regmap_update_bits(rdev->regmap, reg,
273 rdev->desc->vsel_mask,
274 sel);
275}
276
277static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
278{
279 unsigned int reg;
245 int sel = regulator_map_voltage_linear_range(rdev, uv, uv); 280 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
246 281
247 if (sel < 0) 282 if (sel < 0)
@@ -277,8 +312,8 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
277} 312}
278 313
279static struct regulator_ops rk808_buck1_2_ops = { 314static struct regulator_ops rk808_buck1_2_ops = {
280 .list_voltage = regulator_list_voltage_linear_range, 315 .list_voltage = regulator_list_voltage_linear,
281 .map_voltage = regulator_map_voltage_linear_range, 316 .map_voltage = regulator_map_voltage_linear,
282 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap, 317 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap,
283 .set_voltage_sel = rk808_buck1_2_set_voltage_sel, 318 .set_voltage_sel = rk808_buck1_2_set_voltage_sel,
284 .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel, 319 .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel,
@@ -292,6 +327,19 @@ static struct regulator_ops rk808_buck1_2_ops = {
292}; 327};
293 328
294static struct regulator_ops rk808_reg_ops = { 329static struct regulator_ops rk808_reg_ops = {
330 .list_voltage = regulator_list_voltage_linear,
331 .map_voltage = regulator_map_voltage_linear,
332 .get_voltage_sel = regulator_get_voltage_sel_regmap,
333 .set_voltage_sel = regulator_set_voltage_sel_regmap,
334 .enable = regulator_enable_regmap,
335 .disable = regulator_disable_regmap,
336 .is_enabled = regulator_is_enabled_regmap,
337 .set_suspend_voltage = rk808_set_suspend_voltage,
338 .set_suspend_enable = rk808_set_suspend_enable,
339 .set_suspend_disable = rk808_set_suspend_disable,
340};
341
342static struct regulator_ops rk808_reg_ops_ranges = {
295 .list_voltage = regulator_list_voltage_linear_range, 343 .list_voltage = regulator_list_voltage_linear_range,
296 .map_voltage = regulator_map_voltage_linear_range, 344 .map_voltage = regulator_map_voltage_linear_range,
297 .get_voltage_sel = regulator_get_voltage_sel_regmap, 345 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -299,7 +347,7 @@ static struct regulator_ops rk808_reg_ops = {
299 .enable = regulator_enable_regmap, 347 .enable = regulator_enable_regmap,
300 .disable = regulator_disable_regmap, 348 .disable = regulator_disable_regmap,
301 .is_enabled = regulator_is_enabled_regmap, 349 .is_enabled = regulator_is_enabled_regmap,
302 .set_suspend_voltage = rk808_set_suspend_voltage, 350 .set_suspend_voltage = rk808_set_suspend_voltage_range,
303 .set_suspend_enable = rk808_set_suspend_enable, 351 .set_suspend_enable = rk808_set_suspend_enable,
304 .set_suspend_disable = rk808_set_suspend_disable, 352 .set_suspend_disable = rk808_set_suspend_disable,
305}; 353};
@@ -316,12 +364,14 @@ static const struct regulator_desc rk808_reg[] = {
316 { 364 {
317 .name = "DCDC_REG1", 365 .name = "DCDC_REG1",
318 .supply_name = "vcc1", 366 .supply_name = "vcc1",
367 .of_match = of_match_ptr("DCDC_REG1"),
368 .regulators_node = of_match_ptr("regulators"),
319 .id = RK808_ID_DCDC1, 369 .id = RK808_ID_DCDC1,
320 .ops = &rk808_buck1_2_ops, 370 .ops = &rk808_buck1_2_ops,
321 .type = REGULATOR_VOLTAGE, 371 .type = REGULATOR_VOLTAGE,
372 .min_uV = 712500,
373 .uV_step = 12500,
322 .n_voltages = 64, 374 .n_voltages = 64,
323 .linear_ranges = rk808_buck_voltage_ranges,
324 .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges),
325 .vsel_reg = RK808_BUCK1_ON_VSEL_REG, 375 .vsel_reg = RK808_BUCK1_ON_VSEL_REG,
326 .vsel_mask = RK808_BUCK_VSEL_MASK, 376 .vsel_mask = RK808_BUCK_VSEL_MASK,
327 .enable_reg = RK808_DCDC_EN_REG, 377 .enable_reg = RK808_DCDC_EN_REG,
@@ -330,12 +380,14 @@ static const struct regulator_desc rk808_reg[] = {
330 }, { 380 }, {
331 .name = "DCDC_REG2", 381 .name = "DCDC_REG2",
332 .supply_name = "vcc2", 382 .supply_name = "vcc2",
383 .of_match = of_match_ptr("DCDC_REG2"),
384 .regulators_node = of_match_ptr("regulators"),
333 .id = RK808_ID_DCDC2, 385 .id = RK808_ID_DCDC2,
334 .ops = &rk808_buck1_2_ops, 386 .ops = &rk808_buck1_2_ops,
335 .type = REGULATOR_VOLTAGE, 387 .type = REGULATOR_VOLTAGE,
388 .min_uV = 712500,
389 .uV_step = 12500,
336 .n_voltages = 64, 390 .n_voltages = 64,
337 .linear_ranges = rk808_buck_voltage_ranges,
338 .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges),
339 .vsel_reg = RK808_BUCK2_ON_VSEL_REG, 391 .vsel_reg = RK808_BUCK2_ON_VSEL_REG,
340 .vsel_mask = RK808_BUCK_VSEL_MASK, 392 .vsel_mask = RK808_BUCK_VSEL_MASK,
341 .enable_reg = RK808_DCDC_EN_REG, 393 .enable_reg = RK808_DCDC_EN_REG,
@@ -344,6 +396,8 @@ static const struct regulator_desc rk808_reg[] = {
344 }, { 396 }, {
345 .name = "DCDC_REG3", 397 .name = "DCDC_REG3",
346 .supply_name = "vcc3", 398 .supply_name = "vcc3",
399 .of_match = of_match_ptr("DCDC_REG3"),
400 .regulators_node = of_match_ptr("regulators"),
347 .id = RK808_ID_DCDC3, 401 .id = RK808_ID_DCDC3,
348 .ops = &rk808_switch_ops, 402 .ops = &rk808_switch_ops,
349 .type = REGULATOR_VOLTAGE, 403 .type = REGULATOR_VOLTAGE,
@@ -351,55 +405,23 @@ static const struct regulator_desc rk808_reg[] = {
351 .enable_reg = RK808_DCDC_EN_REG, 405 .enable_reg = RK808_DCDC_EN_REG,
352 .enable_mask = BIT(2), 406 .enable_mask = BIT(2),
353 .owner = THIS_MODULE, 407 .owner = THIS_MODULE,
354 }, { 408 },
355 .name = "DCDC_REG4", 409 RK8XX_DESC(RK808_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3300, 100,
356 .supply_name = "vcc4", 410 RK808_BUCK4_ON_VSEL_REG, RK808_BUCK4_VSEL_MASK,
357 .id = RK808_ID_DCDC4, 411 RK808_DCDC_EN_REG, BIT(3), 0),
358 .ops = &rk808_reg_ops, 412 RK8XX_DESC(RK808_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100,
359 .type = REGULATOR_VOLTAGE, 413 RK808_LDO1_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
360 .n_voltages = 16, 414 BIT(0), 400),
361 .linear_ranges = rk808_buck4_voltage_ranges, 415 RK8XX_DESC(RK808_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100,
362 .n_linear_ranges = ARRAY_SIZE(rk808_buck4_voltage_ranges), 416 RK808_LDO2_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
363 .vsel_reg = RK808_BUCK4_ON_VSEL_REG, 417 BIT(1), 400),
364 .vsel_mask = RK808_BUCK4_VSEL_MASK, 418 {
365 .enable_reg = RK808_DCDC_EN_REG,
366 .enable_mask = BIT(3),
367 .owner = THIS_MODULE,
368 }, {
369 .name = "LDO_REG1",
370 .supply_name = "vcc6",
371 .id = RK808_ID_LDO1,
372 .ops = &rk808_reg_ops,
373 .type = REGULATOR_VOLTAGE,
374 .n_voltages = 17,
375 .linear_ranges = rk808_ldo_voltage_ranges,
376 .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges),
377 .vsel_reg = RK808_LDO1_ON_VSEL_REG,
378 .vsel_mask = RK808_LDO_VSEL_MASK,
379 .enable_reg = RK808_LDO_EN_REG,
380 .enable_mask = BIT(0),
381 .enable_time = 400,
382 .owner = THIS_MODULE,
383 }, {
384 .name = "LDO_REG2",
385 .supply_name = "vcc6",
386 .id = RK808_ID_LDO2,
387 .ops = &rk808_reg_ops,
388 .type = REGULATOR_VOLTAGE,
389 .n_voltages = 17,
390 .linear_ranges = rk808_ldo_voltage_ranges,
391 .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges),
392 .vsel_reg = RK808_LDO2_ON_VSEL_REG,
393 .vsel_mask = RK808_LDO_VSEL_MASK,
394 .enable_reg = RK808_LDO_EN_REG,
395 .enable_mask = BIT(1),
396 .enable_time = 400,
397 .owner = THIS_MODULE,
398 }, {
399 .name = "LDO_REG3", 419 .name = "LDO_REG3",
400 .supply_name = "vcc7", 420 .supply_name = "vcc7",
421 .of_match = of_match_ptr("LDO_REG3"),
422 .regulators_node = of_match_ptr("regulators"),
401 .id = RK808_ID_LDO3, 423 .id = RK808_ID_LDO3,
402 .ops = &rk808_reg_ops, 424 .ops = &rk808_reg_ops_ranges,
403 .type = REGULATOR_VOLTAGE, 425 .type = REGULATOR_VOLTAGE,
404 .n_voltages = 16, 426 .n_voltages = 16,
405 .linear_ranges = rk808_ldo3_voltage_ranges, 427 .linear_ranges = rk808_ldo3_voltage_ranges,
@@ -410,117 +432,26 @@ static const struct regulator_desc rk808_reg[] = {
410 .enable_mask = BIT(2), 432 .enable_mask = BIT(2),
411 .enable_time = 400, 433 .enable_time = 400,
412 .owner = THIS_MODULE, 434 .owner = THIS_MODULE,
413 }, {
414 .name = "LDO_REG4",
415 .supply_name = "vcc9",
416 .id = RK808_ID_LDO4,
417 .ops = &rk808_reg_ops,
418 .type = REGULATOR_VOLTAGE,
419 .n_voltages = 17,
420 .linear_ranges = rk808_ldo_voltage_ranges,
421 .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges),
422 .vsel_reg = RK808_LDO4_ON_VSEL_REG,
423 .vsel_mask = RK808_LDO_VSEL_MASK,
424 .enable_reg = RK808_LDO_EN_REG,
425 .enable_mask = BIT(3),
426 .enable_time = 400,
427 .owner = THIS_MODULE,
428 }, {
429 .name = "LDO_REG5",
430 .supply_name = "vcc9",
431 .id = RK808_ID_LDO5,
432 .ops = &rk808_reg_ops,
433 .type = REGULATOR_VOLTAGE,
434 .n_voltages = 17,
435 .linear_ranges = rk808_ldo_voltage_ranges,
436 .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges),
437 .vsel_reg = RK808_LDO5_ON_VSEL_REG,
438 .vsel_mask = RK808_LDO_VSEL_MASK,
439 .enable_reg = RK808_LDO_EN_REG,
440 .enable_mask = BIT(4),
441 .enable_time = 400,
442 .owner = THIS_MODULE,
443 }, {
444 .name = "LDO_REG6",
445 .supply_name = "vcc10",
446 .id = RK808_ID_LDO6,
447 .ops = &rk808_reg_ops,
448 .type = REGULATOR_VOLTAGE,
449 .n_voltages = 18,
450 .linear_ranges = rk808_ldo6_voltage_ranges,
451 .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges),
452 .vsel_reg = RK808_LDO6_ON_VSEL_REG,
453 .vsel_mask = RK808_LDO_VSEL_MASK,
454 .enable_reg = RK808_LDO_EN_REG,
455 .enable_mask = BIT(5),
456 .enable_time = 400,
457 .owner = THIS_MODULE,
458 }, {
459 .name = "LDO_REG7",
460 .supply_name = "vcc7",
461 .id = RK808_ID_LDO7,
462 .ops = &rk808_reg_ops,
463 .type = REGULATOR_VOLTAGE,
464 .n_voltages = 18,
465 .linear_ranges = rk808_ldo6_voltage_ranges,
466 .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges),
467 .vsel_reg = RK808_LDO7_ON_VSEL_REG,
468 .vsel_mask = RK808_LDO_VSEL_MASK,
469 .enable_reg = RK808_LDO_EN_REG,
470 .enable_mask = BIT(6),
471 .enable_time = 400,
472 .owner = THIS_MODULE,
473 }, {
474 .name = "LDO_REG8",
475 .supply_name = "vcc11",
476 .id = RK808_ID_LDO8,
477 .ops = &rk808_reg_ops,
478 .type = REGULATOR_VOLTAGE,
479 .n_voltages = 17,
480 .linear_ranges = rk808_ldo_voltage_ranges,
481 .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges),
482 .vsel_reg = RK808_LDO8_ON_VSEL_REG,
483 .vsel_mask = RK808_LDO_VSEL_MASK,
484 .enable_reg = RK808_LDO_EN_REG,
485 .enable_mask = BIT(7),
486 .enable_time = 400,
487 .owner = THIS_MODULE,
488 }, {
489 .name = "SWITCH_REG1",
490 .supply_name = "vcc8",
491 .id = RK808_ID_SWITCH1,
492 .ops = &rk808_switch_ops,
493 .type = REGULATOR_VOLTAGE,
494 .enable_reg = RK808_DCDC_EN_REG,
495 .enable_mask = BIT(5),
496 .owner = THIS_MODULE,
497 }, {
498 .name = "SWITCH_REG2",
499 .supply_name = "vcc12",
500 .id = RK808_ID_SWITCH2,
501 .ops = &rk808_switch_ops,
502 .type = REGULATOR_VOLTAGE,
503 .enable_reg = RK808_DCDC_EN_REG,
504 .enable_mask = BIT(6),
505 .owner = THIS_MODULE,
506 }, 435 },
507}; 436 RK8XX_DESC(RK808_ID_LDO4, "LDO_REG4", "vcc9", 1800, 3400, 100,
508 437 RK808_LDO4_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
509static struct of_regulator_match rk808_reg_matches[] = { 438 BIT(3), 400),
510 [RK808_ID_DCDC1] = { .name = "DCDC_REG1" }, 439 RK8XX_DESC(RK808_ID_LDO5, "LDO_REG5", "vcc9", 1800, 3400, 100,
511 [RK808_ID_DCDC2] = { .name = "DCDC_REG2" }, 440 RK808_LDO5_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
512 [RK808_ID_DCDC3] = { .name = "DCDC_REG3" }, 441 BIT(4), 400),
513 [RK808_ID_DCDC4] = { .name = "DCDC_REG4" }, 442 RK8XX_DESC(RK808_ID_LDO6, "LDO_REG6", "vcc10", 800, 2500, 100,
514 [RK808_ID_LDO1] = { .name = "LDO_REG1" }, 443 RK808_LDO6_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
515 [RK808_ID_LDO2] = { .name = "LDO_REG2" }, 444 BIT(5), 400),
516 [RK808_ID_LDO3] = { .name = "LDO_REG3" }, 445 RK8XX_DESC(RK808_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100,
517 [RK808_ID_LDO4] = { .name = "LDO_REG4" }, 446 RK808_LDO7_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
518 [RK808_ID_LDO5] = { .name = "LDO_REG5" }, 447 BIT(6), 400),
519 [RK808_ID_LDO6] = { .name = "LDO_REG6" }, 448 RK8XX_DESC(RK808_ID_LDO8, "LDO_REG8", "vcc11", 1800, 3400, 100,
520 [RK808_ID_LDO7] = { .name = "LDO_REG7" }, 449 RK808_LDO8_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
521 [RK808_ID_LDO8] = { .name = "LDO_REG8" }, 450 BIT(7), 400),
522 [RK808_ID_SWITCH1] = { .name = "SWITCH_REG1" }, 451 RK8XX_DESC_SWITCH(RK808_ID_SWITCH1, "SWITCH_REG1", "vcc8",
523 [RK808_ID_SWITCH2] = { .name = "SWITCH_REG2" }, 452 RK808_DCDC_EN_REG, BIT(5)),
453 RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12",
454 RK808_DCDC_EN_REG, BIT(6)),
524}; 455};
525 456
526static int rk808_regulator_dt_parse_pdata(struct device *dev, 457static int rk808_regulator_dt_parse_pdata(struct device *dev,
@@ -529,17 +460,12 @@ static int rk808_regulator_dt_parse_pdata(struct device *dev,
529 struct rk808_regulator_data *pdata) 460 struct rk808_regulator_data *pdata)
530{ 461{
531 struct device_node *np; 462 struct device_node *np;
532 int tmp, ret, i; 463 int tmp, ret = 0, i;
533 464
534 np = of_get_child_by_name(client_dev->of_node, "regulators"); 465 np = of_get_child_by_name(client_dev->of_node, "regulators");
535 if (!np) 466 if (!np)
536 return -ENXIO; 467 return -ENXIO;
537 468
538 ret = of_regulator_match(dev, np, rk808_reg_matches,
539 RK808_NUM_REGULATORS);
540 if (ret < 0)
541 goto dt_parse_end;
542
543 for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { 469 for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
544 pdata->dvs_gpio[i] = 470 pdata->dvs_gpio[i] =
545 devm_gpiod_get_index_optional(client_dev, "dvs", i, 471 devm_gpiod_get_index_optional(client_dev, "dvs", i,
@@ -586,18 +512,12 @@ static int rk808_regulator_probe(struct platform_device *pdev)
586 512
587 platform_set_drvdata(pdev, pdata); 513 platform_set_drvdata(pdev, pdata);
588 514
515 config.dev = &client->dev;
516 config.driver_data = pdata;
517 config.regmap = rk808->regmap;
518
589 /* Instantiate the regulators */ 519 /* Instantiate the regulators */
590 for (i = 0; i < RK808_NUM_REGULATORS; i++) { 520 for (i = 0; i < RK808_NUM_REGULATORS; i++) {
591 if (!rk808_reg_matches[i].init_data ||
592 !rk808_reg_matches[i].of_node)
593 continue;
594
595 config.dev = &client->dev;
596 config.driver_data = pdata;
597 config.regmap = rk808->regmap;
598 config.of_node = rk808_reg_matches[i].of_node;
599 config.init_data = rk808_reg_matches[i].init_data;
600
601 rk808_rdev = devm_regulator_register(&pdev->dev, 521 rk808_rdev = devm_regulator_register(&pdev->dev,
602 &rk808_reg[i], &config); 522 &rk808_reg[i], &config);
603 if (IS_ERR(rk808_rdev)) { 523 if (IS_ERR(rk808_rdev)) {
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 6dfa3502e1f1..02fb6b4ea820 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -267,6 +267,7 @@ static struct regulator_ops s2mps11_buck_ops = {
267 .ops = &s2mps11_ldo_ops, \ 267 .ops = &s2mps11_ldo_ops, \
268 .type = REGULATOR_VOLTAGE, \ 268 .type = REGULATOR_VOLTAGE, \
269 .owner = THIS_MODULE, \ 269 .owner = THIS_MODULE, \
270 .ramp_delay = RAMP_DELAY_12_MVUS, \
270 .min_uV = MIN_800_MV, \ 271 .min_uV = MIN_800_MV, \
271 .uV_step = step, \ 272 .uV_step = step, \
272 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \ 273 .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
@@ -1237,17 +1238,7 @@ static struct platform_driver s2mps11_pmic_driver = {
1237 .id_table = s2mps11_pmic_id, 1238 .id_table = s2mps11_pmic_id,
1238}; 1239};
1239 1240
1240static int __init s2mps11_pmic_init(void) 1241module_platform_driver(s2mps11_pmic_driver);
1241{
1242 return platform_driver_register(&s2mps11_pmic_driver);
1243}
1244subsys_initcall(s2mps11_pmic_init);
1245
1246static void __exit s2mps11_pmic_exit(void)
1247{
1248 platform_driver_unregister(&s2mps11_pmic_driver);
1249}
1250module_exit(s2mps11_pmic_exit);
1251 1242
1252/* Module information */ 1243/* Module information */
1253MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); 1244MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 9d6ea3a4dccd..67cac2682f50 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -600,7 +600,7 @@ static int pmic_probe(struct spi_device *spi)
600 600
601 memset(hw, 0, sizeof(struct tps6524x)); 601 memset(hw, 0, sizeof(struct tps6524x));
602 hw->dev = dev; 602 hw->dev = dev;
603 hw->spi = spi_dev_get(spi); 603 hw->spi = spi;
604 mutex_init(&hw->lock); 604 mutex_init(&hw->lock);
605 605
606 for (i = 0; i < N_REGULATORS; i++, info++, init_data++) { 606 for (i = 0; i < N_REGULATORS; i++, info++, init_data++) {
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 955a6fb1355c..faeb5ee92c9e 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -21,7 +21,7 @@
21#include <linux/regulator/machine.h> 21#include <linux/regulator/machine.h>
22#include <linux/regulator/of_regulator.h> 22#include <linux/regulator/of_regulator.h>
23#include <linux/i2c/twl.h> 23#include <linux/i2c/twl.h>
24 24#include <linux/delay.h>
25 25
26/* 26/*
27 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a 27 * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a
@@ -188,6 +188,74 @@ static int twl6030reg_is_enabled(struct regulator_dev *rdev)
188 return grp && (val == TWL6030_CFG_STATE_ON); 188 return grp && (val == TWL6030_CFG_STATE_ON);
189} 189}
190 190
191#define PB_I2C_BUSY BIT(0)
192#define PB_I2C_BWEN BIT(1)
193
194/* Wait until buffer empty/ready to send a word on power bus. */
195static int twl4030_wait_pb_ready(void)
196{
197
198 int ret;
199 int timeout = 10;
200 u8 val;
201
202 do {
203 ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
204 TWL4030_PM_MASTER_PB_CFG);
205 if (ret < 0)
206 return ret;
207
208 if (!(val & PB_I2C_BUSY))
209 return 0;
210
211 mdelay(1);
212 timeout--;
213 } while (timeout);
214
215 return -ETIMEDOUT;
216}
217
218/* Send a word over the powerbus */
219static int twl4030_send_pb_msg(unsigned msg)
220{
221 u8 val;
222 int ret;
223
224 /* save powerbus configuration */
225 ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
226 TWL4030_PM_MASTER_PB_CFG);
227 if (ret < 0)
228 return ret;
229
230 /* Enable i2c access to powerbus */
231 ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val | PB_I2C_BWEN,
232 TWL4030_PM_MASTER_PB_CFG);
233 if (ret < 0)
234 return ret;
235
236 ret = twl4030_wait_pb_ready();
237 if (ret < 0)
238 return ret;
239
240 ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg >> 8,
241 TWL4030_PM_MASTER_PB_WORD_MSB);
242 if (ret < 0)
243 return ret;
244
245 ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg & 0xff,
246 TWL4030_PM_MASTER_PB_WORD_LSB);
247 if (ret < 0)
248 return ret;
249
250 ret = twl4030_wait_pb_ready();
251 if (ret < 0)
252 return ret;
253
254 /* Restore powerbus configuration */
255 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val,
256 TWL4030_PM_MASTER_PB_CFG);
257}
258
191static int twl4030reg_enable(struct regulator_dev *rdev) 259static int twl4030reg_enable(struct regulator_dev *rdev)
192{ 260{
193 struct twlreg_info *info = rdev_get_drvdata(rdev); 261 struct twlreg_info *info = rdev_get_drvdata(rdev);
@@ -303,7 +371,6 @@ static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
303{ 371{
304 struct twlreg_info *info = rdev_get_drvdata(rdev); 372 struct twlreg_info *info = rdev_get_drvdata(rdev);
305 unsigned message; 373 unsigned message;
306 int status;
307 374
308 /* We can only set the mode through state machine commands... */ 375 /* We can only set the mode through state machine commands... */
309 switch (mode) { 376 switch (mode) {
@@ -317,20 +384,19 @@ static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
317 return -EINVAL; 384 return -EINVAL;
318 } 385 }
319 386
320 /* Ensure the resource is associated with some group */ 387 return twl4030_send_pb_msg(message);
321 status = twlreg_grp(rdev); 388}
322 if (status < 0)
323 return status;
324 if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030)))
325 return -EACCES;
326
327 status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
328 message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB);
329 if (status < 0)
330 return status;
331 389
332 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 390static inline unsigned int twl4030reg_map_mode(unsigned int mode)
333 message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); 391{
392 switch (mode) {
393 case RES_STATE_ACTIVE:
394 return REGULATOR_MODE_NORMAL;
395 case RES_STATE_SLEEP:
396 return REGULATOR_MODE_STANDBY;
397 default:
398 return -EINVAL;
399 }
334} 400}
335 401
336static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 402static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)
@@ -835,10 +901,11 @@ static struct regulator_ops twlsmps_ops = {
835#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 901#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
836 remap_conf) \ 902 remap_conf) \
837 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 903 TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \
838 remap_conf, TWL4030, twl4030fixed_ops) 904 remap_conf, TWL4030, twl4030fixed_ops, \
905 twl4030reg_map_mode)
839#define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \ 906#define TWL6030_FIXED_LDO(label, offset, mVolts, turnon_delay) \
840 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \ 907 TWL_FIXED_LDO(label, offset, mVolts, 0x0, turnon_delay, \
841 0x0, TWL6030, twl6030fixed_ops) 908 0x0, TWL6030, twl6030fixed_ops, 0x0)
842 909
843#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 910#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \
844static const struct twlreg_info TWL4030_INFO_##label = { \ 911static const struct twlreg_info TWL4030_INFO_##label = { \
@@ -855,6 +922,7 @@ static const struct twlreg_info TWL4030_INFO_##label = { \
855 .type = REGULATOR_VOLTAGE, \ 922 .type = REGULATOR_VOLTAGE, \
856 .owner = THIS_MODULE, \ 923 .owner = THIS_MODULE, \
857 .enable_time = turnon_delay, \ 924 .enable_time = turnon_delay, \
925 .of_map_mode = twl4030reg_map_mode, \
858 }, \ 926 }, \
859 } 927 }
860 928
@@ -870,6 +938,7 @@ static const struct twlreg_info TWL4030_INFO_##label = { \
870 .type = REGULATOR_VOLTAGE, \ 938 .type = REGULATOR_VOLTAGE, \
871 .owner = THIS_MODULE, \ 939 .owner = THIS_MODULE, \
872 .enable_time = turnon_delay, \ 940 .enable_time = turnon_delay, \
941 .of_map_mode = twl4030reg_map_mode, \
873 }, \ 942 }, \
874 } 943 }
875 944
@@ -915,7 +984,7 @@ static const struct twlreg_info TWL6032_INFO_##label = { \
915 } 984 }
916 985
917#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \ 986#define TWL_FIXED_LDO(label, offset, mVolts, num, turnon_delay, remap_conf, \
918 family, operations) \ 987 family, operations, map_mode) \
919static const struct twlreg_info TWLFIXED_INFO_##label = { \ 988static const struct twlreg_info TWLFIXED_INFO_##label = { \
920 .base = offset, \ 989 .base = offset, \
921 .id = num, \ 990 .id = num, \
@@ -930,6 +999,7 @@ static const struct twlreg_info TWLFIXED_INFO_##label = { \
930 .owner = THIS_MODULE, \ 999 .owner = THIS_MODULE, \
931 .min_uV = mVolts * 1000, \ 1000 .min_uV = mVolts * 1000, \
932 .enable_time = turnon_delay, \ 1001 .enable_time = turnon_delay, \
1002 .of_map_mode = map_mode, \
933 }, \ 1003 }, \
934 } 1004 }
935 1005
diff --git a/include/linux/mfd/as3722.h b/include/linux/mfd/as3722.h
index 8d43e9f2a842..51e6f9414575 100644
--- a/include/linux/mfd/as3722.h
+++ b/include/linux/mfd/as3722.h
@@ -196,6 +196,7 @@
196#define AS3722_LDO3_VSEL_MIN 0x01 196#define AS3722_LDO3_VSEL_MIN 0x01
197#define AS3722_LDO3_VSEL_MAX 0x2D 197#define AS3722_LDO3_VSEL_MAX 0x2D
198#define AS3722_LDO3_NUM_VOLT 0x2D 198#define AS3722_LDO3_NUM_VOLT 0x2D
199#define AS3722_LDO6_VSEL_BYPASS 0x3F
199#define AS3722_LDO_VSEL_MASK 0x7F 200#define AS3722_LDO_VSEL_MASK 0x7F
200#define AS3722_LDO_VSEL_MIN 0x01 201#define AS3722_LDO_VSEL_MIN 0x01
201#define AS3722_LDO_VSEL_MAX 0x7F 202#define AS3722_LDO_VSEL_MAX 0x7F
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 6bc4bcd488ac..5a23dd4df432 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -30,6 +30,9 @@
30#define MIN_600_MV 600000 30#define MIN_600_MV 600000
31#define MIN_500_MV 500000 31#define MIN_500_MV 500000
32 32
33/* Ramp delay in uV/us */
34#define RAMP_DELAY_12_MVUS 12000
35
33/* Macros to represent steps for LDO/BUCK */ 36/* Macros to represent steps for LDO/BUCK */
34#define STEP_50_MV 50000 37#define STEP_50_MV 50000
35#define STEP_25_MV 25000 38#define STEP_25_MV 25000
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index cfc3ed46cad2..b78d27c42629 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -74,6 +74,24 @@ enum pwm_polarity {
74 PWM_POLARITY_INVERSED, 74 PWM_POLARITY_INVERSED,
75}; 75};
76 76
77/**
78 * struct pwm_args - board-dependent PWM arguments
79 * @period: reference period
80 * @polarity: reference polarity
81 *
82 * This structure describes board-dependent arguments attached to a PWM
83 * device. These arguments are usually retrieved from the PWM lookup table or
84 * device tree.
85 *
86 * Do not confuse this with the PWM state: PWM arguments represent the initial
87 * configuration that users want to use on this PWM device rather than the
88 * current PWM hardware state.
89 */
90struct pwm_args {
91 unsigned int period;
92 enum pwm_polarity polarity;
93};
94
77enum { 95enum {
78 PWMF_REQUESTED = 1 << 0, 96 PWMF_REQUESTED = 1 << 0,
79 PWMF_ENABLED = 1 << 1, 97 PWMF_ENABLED = 1 << 1,
@@ -92,6 +110,7 @@ enum {
92 * @period: period of the PWM signal (in nanoseconds) 110 * @period: period of the PWM signal (in nanoseconds)
93 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds) 111 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
94 * @polarity: polarity of the PWM signal 112 * @polarity: polarity of the PWM signal
113 * @args: PWM arguments
95 */ 114 */
96struct pwm_device { 115struct pwm_device {
97 const char *label; 116 const char *label;
@@ -105,6 +124,8 @@ struct pwm_device {
105 unsigned int period; 124 unsigned int period;
106 unsigned int duty_cycle; 125 unsigned int duty_cycle;
107 enum pwm_polarity polarity; 126 enum pwm_polarity polarity;
127
128 struct pwm_args args;
108}; 129};
109 130
110static inline bool pwm_is_enabled(const struct pwm_device *pwm) 131static inline bool pwm_is_enabled(const struct pwm_device *pwm)
@@ -144,6 +165,18 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
144 return pwm ? pwm->polarity : PWM_POLARITY_NORMAL; 165 return pwm ? pwm->polarity : PWM_POLARITY_NORMAL;
145} 166}
146 167
168static inline void pwm_get_args(const struct pwm_device *pwm,
169 struct pwm_args *args)
170{
171 *args = pwm->args;
172}
173
174static inline void pwm_apply_args(struct pwm_device *pwm)
175{
176 pwm_set_period(pwm, pwm->args.period);
177 pwm_set_polarity(pwm, pwm->args.polarity);
178}
179
147/** 180/**
148 * struct pwm_ops - PWM controller operations 181 * struct pwm_ops - PWM controller operations
149 * @request: optional hook for requesting a PWM 182 * @request: optional hook for requesting a PWM
diff --git a/include/linux/regulator/act8865.h b/include/linux/regulator/act8865.h
index 2eb386017fa5..113d861a1e4c 100644
--- a/include/linux/regulator/act8865.h
+++ b/include/linux/regulator/act8865.h
@@ -69,11 +69,13 @@ enum {
69 * @id: regulator id 69 * @id: regulator id
70 * @name: regulator name 70 * @name: regulator name
71 * @init_data: regulator init data 71 * @init_data: regulator init data
72 * @of_node: device tree node (optional)
72 */ 73 */
73struct act8865_regulator_data { 74struct act8865_regulator_data {
74 int id; 75 int id;
75 const char *name; 76 const char *name;
76 struct regulator_init_data *init_data; 77 struct regulator_init_data *init_data;
78 struct device_node *of_node;
77}; 79};
78 80
79/** 81/**
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 48603506f8de..80dc4e51d14a 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -224,7 +224,7 @@ int regulator_bulk_force_disable(int num_consumers,
224void regulator_bulk_free(int num_consumers, 224void regulator_bulk_free(int num_consumers,
225 struct regulator_bulk_data *consumers); 225 struct regulator_bulk_data *consumers);
226 226
227int regulator_can_change_voltage(struct regulator *regulator); 227int __deprecated regulator_can_change_voltage(struct regulator *regulator);
228int regulator_count_voltages(struct regulator *regulator); 228int regulator_count_voltages(struct regulator *regulator);
229int regulator_list_voltage(struct regulator *regulator, unsigned selector); 229int regulator_list_voltage(struct regulator *regulator, unsigned selector);
230int regulator_is_supported_voltage(struct regulator *regulator, 230int regulator_is_supported_voltage(struct regulator *regulator,
@@ -436,7 +436,7 @@ static inline void regulator_bulk_free(int num_consumers,
436{ 436{
437} 437}
438 438
439static inline int regulator_can_change_voltage(struct regulator *regulator) 439static inline int __deprecated regulator_can_change_voltage(struct regulator *regulator)
440{ 440{
441 return 0; 441 return 0;
442} 442}
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index cd271e89a7e6..fcfa40a6692c 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -93,6 +93,9 @@ struct regulator_linear_range {
93 * @get_current_limit: Get the configured limit for a current-limited regulator. 93 * @get_current_limit: Get the configured limit for a current-limited regulator.
94 * @set_input_current_limit: Configure an input limit. 94 * @set_input_current_limit: Configure an input limit.
95 * 95 *
96 * @set_over_current_protection: Support capability of automatically shutting
97 * down when detecting an over current event.
98 *
96 * @set_active_discharge: Set active discharge enable/disable of regulators. 99 * @set_active_discharge: Set active discharge enable/disable of regulators.
97 * 100 *
98 * @set_mode: Set the configured operating mode for the regulator. 101 * @set_mode: Set the configured operating mode for the regulator.
@@ -255,6 +258,8 @@ enum regulator_type {
255 * 258 *
256 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ 259 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
257 * @vsel_mask: Mask for register bitfield used for selector 260 * @vsel_mask: Mask for register bitfield used for selector
261 * @csel_reg: Register for TPS65218 LS3 current regulator
262 * @csel_mask: Mask for TPS65218 LS3 current regulator
258 * @apply_reg: Register for initiate voltage change on the output when 263 * @apply_reg: Register for initiate voltage change on the output when
259 * using regulator_set_voltage_sel_regmap 264 * using regulator_set_voltage_sel_regmap
260 * @apply_bit: Register bitfield used for initiate voltage change on the 265 * @apply_bit: Register bitfield used for initiate voltage change on the
@@ -292,7 +297,7 @@ struct regulator_desc {
292 const struct regulator_desc *, 297 const struct regulator_desc *,
293 struct regulator_config *); 298 struct regulator_config *);
294 int id; 299 int id;
295 bool continuous_voltage_range; 300 unsigned int continuous_voltage_range:1;
296 unsigned n_voltages; 301 unsigned n_voltages;
297 const struct regulator_ops *ops; 302 const struct regulator_ops *ops;
298 int irq; 303 int irq;
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 5d627c83a630..ad3e5158e586 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -97,6 +97,7 @@ struct regulator_state {
97 * @ramp_disable: Disable ramp delay when initialising or when setting voltage. 97 * @ramp_disable: Disable ramp delay when initialising or when setting voltage.
98 * @soft_start: Enable soft start so that voltage ramps slowly. 98 * @soft_start: Enable soft start so that voltage ramps slowly.
99 * @pull_down: Enable pull down when regulator is disabled. 99 * @pull_down: Enable pull down when regulator is disabled.
100 * @over_current_protection: Auto disable on over current event.
100 * 101 *
101 * @input_uV: Input voltage for regulator when supplied by another regulator. 102 * @input_uV: Input voltage for regulator when supplied by another regulator.
102 * 103 *
diff --git a/include/linux/regulator/max8973-regulator.h b/include/linux/regulator/max8973-regulator.h
index f6a8a16a0d4d..2fcb9980262a 100644
--- a/include/linux/regulator/max8973-regulator.h
+++ b/include/linux/regulator/max8973-regulator.h
@@ -54,6 +54,10 @@
54 * @reg_init_data: The regulator init data. 54 * @reg_init_data: The regulator init data.
55 * @control_flags: Control flags which are ORed value of above flags to 55 * @control_flags: Control flags which are ORed value of above flags to
56 * configure device. 56 * configure device.
57 * @junction_temp_warning: Junction temp in millicelcius on which warning need
58 * to be set. Thermal functionality is only supported on
59 * MAX77621. The threshold warning supported by MAX77621
60 * are 120C and 140C.
57 * @enable_ext_control: Enable the voltage enable/disable through external 61 * @enable_ext_control: Enable the voltage enable/disable through external
58 * control signal from EN input pin. If it is false then 62 * control signal from EN input pin. If it is false then
59 * voltage output will be enabled/disabled through EN bit of 63 * voltage output will be enabled/disabled through EN bit of
@@ -67,6 +71,7 @@
67struct max8973_regulator_platform_data { 71struct max8973_regulator_platform_data {
68 struct regulator_init_data *reg_init_data; 72 struct regulator_init_data *reg_init_data;
69 unsigned long control_flags; 73 unsigned long control_flags;
74 unsigned long junction_temp_warning;
70 bool enable_ext_control; 75 bool enable_ext_control;
71 int enable_gpio; 76 int enable_gpio;
72 int dvs_gpio; 77 int dvs_gpio;