aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/regulator/arizona-regulator.txt3
-rw-r--r--Documentation/devicetree/bindings/regulator/fixed-regulator.yaml5
-rw-r--r--Documentation/devicetree/bindings/regulator/gpio-regulator.txt57
-rw-r--r--Documentation/devicetree/bindings/regulator/gpio-regulator.yaml118
-rw-r--r--Documentation/devicetree/bindings/regulator/max8660.txt47
-rw-r--r--Documentation/devicetree/bindings/regulator/max8660.yaml77
-rw-r--r--Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt22
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt140
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.yaml200
-rw-r--r--Documentation/devicetree/bindings/regulator/slg51000.txt88
-rw-r--r--Documentation/devicetree/bindings/regulator/st,stm32-booster.txt18
-rw-r--r--MAINTAINERS2
-rw-r--r--arch/arm/mach-s3c64xx/mach-crag6410.c21
-rw-r--r--arch/arm64/boot/dts/qcom/msm8998-mtp.dtsi17
-rw-r--r--drivers/gpio/gpiolib.c6
-rw-r--r--drivers/regulator/88pm800-regulator.c (renamed from drivers/regulator/88pm800.c)0
-rw-r--r--drivers/regulator/Kconfig37
-rw-r--r--drivers/regulator/Makefile4
-rw-r--r--drivers/regulator/arizona-ldo1.c83
-rw-r--r--drivers/regulator/arizona-micsupp.c72
-rw-r--r--drivers/regulator/bd70528-regulator.c1
-rw-r--r--drivers/regulator/bd718x7-regulator.c1
-rw-r--r--drivers/regulator/core.c278
-rw-r--r--drivers/regulator/cpcap-regulator.c2
-rw-r--r--drivers/regulator/da9062-regulator.c40
-rw-r--r--drivers/regulator/da9063-regulator.c61
-rw-r--r--drivers/regulator/da9211-regulator.c2
-rw-r--r--drivers/regulator/helpers.c11
-rw-r--r--drivers/regulator/max77620-regulator.c28
-rw-r--r--drivers/regulator/max77650-regulator.c170
-rw-r--r--drivers/regulator/max77802-regulator.c2
-rw-r--r--drivers/regulator/max8952.c64
-rw-r--r--drivers/regulator/of_regulator.c63
-rw-r--r--drivers/regulator/qcom_spmi-regulator.c252
-rw-r--r--drivers/regulator/s2mps11.c255
-rw-r--r--drivers/regulator/s5m8767.c4
-rw-r--r--drivers/regulator/slg51000-regulator.c523
-rw-r--r--drivers/regulator/slg51000-regulator.h505
-rw-r--r--drivers/regulator/stm32-booster.c132
-rw-r--r--drivers/regulator/tps65090-regulator.c7
-rw-r--r--drivers/regulator/wm831x-dcdc.c29
-rw-r--r--include/linux/mfd/da9062/registers.h3
-rw-r--r--include/linux/mfd/da9063/pdata.h49
-rw-r--r--include/linux/mfd/samsung/core.h1
-rw-r--r--include/linux/mfd/samsung/s2mps11.h9
-rw-r--r--include/linux/mfd/wm831x/pdata.h1
-rw-r--r--include/linux/regulator/coupler.h97
-rw-r--r--include/linux/regulator/driver.h12
-rw-r--r--include/linux/regulator/machine.h2
-rw-r--r--include/linux/regulator/max8952.h3
50 files changed, 2862 insertions, 762 deletions
diff --git a/Documentation/devicetree/bindings/regulator/arizona-regulator.txt b/Documentation/devicetree/bindings/regulator/arizona-regulator.txt
index 443564d7784f..69bf41949b01 100644
--- a/Documentation/devicetree/bindings/regulator/arizona-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/arizona-regulator.txt
@@ -5,7 +5,8 @@ of analogue I/O.
5 5
6This document lists regulator specific bindings, see the primary binding 6This document lists regulator specific bindings, see the primary binding
7document: 7document:
8 ../mfd/arizona.txt 8 For Wolfson Microelectronic Arizona codecs: ../mfd/arizona.txt
9 For Cirrus Logic Madera codecs: ../mfd/madera.txt
9 10
10Optional properties: 11Optional properties:
11 - wlf,ldoena : GPIO specifier for the GPIO controlling LDOENA 12 - wlf,ldoena : GPIO specifier for the GPIO controlling LDOENA
diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml
index d289c2f7455a..a650b457085d 100644
--- a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml
+++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml
@@ -12,10 +12,13 @@ maintainers:
12 12
13description: 13description:
14 Any property defined as part of the core regulator binding, defined in 14 Any property defined as part of the core regulator binding, defined in
15 regulator.txt, can also be used. However a fixed voltage regulator is 15 regulator.yaml, can also be used. However a fixed voltage regulator is
16 expected to have the regulator-min-microvolt and regulator-max-microvolt 16 expected to have the regulator-min-microvolt and regulator-max-microvolt
17 to be the same. 17 to be the same.
18 18
19allOf:
20 - $ref: "regulator.yaml#"
21
19properties: 22properties:
20 compatible: 23 compatible:
21 const: regulator-fixed 24 const: regulator-fixed
diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt b/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
deleted file mode 100644
index dd25e73b5d79..000000000000
--- a/Documentation/devicetree/bindings/regulator/gpio-regulator.txt
+++ /dev/null
@@ -1,57 +0,0 @@
1GPIO controlled regulators
2
3Required properties:
4- compatible : Must be "regulator-gpio".
5- regulator-name : Defined in regulator.txt as optional, but required
6 here.
7- gpios : Array of one or more GPIO pins used to select the
8 regulator voltage/current listed in "states".
9- states : Selection of available voltages/currents provided by
10 this regulator and matching GPIO configurations to
11 achieve them. If there are no states in the "states"
12 array, use a fixed regulator instead.
13
14Optional properties:
15- enable-gpios : GPIO used to enable/disable the regulator.
16 Warning, the GPIO phandle flags are ignored and the
17 GPIO polarity is controlled solely by the presence
18 of "enable-active-high" DT property. This is due to
19 compatibility with old DTs.
20- enable-active-high : Polarity of "enable-gpio" GPIO is active HIGH.
21 Default is active LOW.
22- gpios-states : On operating systems, that don't support reading back
23 gpio values in output mode (most notably linux), this
24 array provides the state of GPIO pins set when
25 requesting them from the gpio controller. Systems,
26 that are capable of preserving state when requesting
27 the lines, are free to ignore this property.
28 0: LOW, 1: HIGH. Default is LOW if nothing else
29 is specified.
30- startup-delay-us : Startup time in microseconds.
31- regulator-type : Specifies what is being regulated, must be either
32 "voltage" or "current", defaults to voltage.
33
34Any property defined as part of the core regulator binding defined in
35regulator.txt can also be used.
36
37Example:
38
39 mmciv: gpio-regulator {
40 compatible = "regulator-gpio";
41
42 regulator-name = "mmci-gpio-supply";
43 regulator-min-microvolt = <1800000>;
44 regulator-max-microvolt = <2600000>;
45 regulator-boot-on;
46
47 enable-gpios = <&gpio0 23 0x4>;
48 gpios = <&gpio0 24 0x4
49 &gpio0 25 0x4>;
50 states = <1800000 0x3
51 2200000 0x2
52 2600000 0x1
53 2900000 0x0>;
54
55 startup-delay-us = <100000>;
56 enable-active-high;
57 };
diff --git a/Documentation/devicetree/bindings/regulator/gpio-regulator.yaml b/Documentation/devicetree/bindings/regulator/gpio-regulator.yaml
new file mode 100644
index 000000000000..9d3b28417fb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/gpio-regulator.yaml
@@ -0,0 +1,118 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/regulator/gpio-regulator.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: GPIO controlled regulators
8
9maintainers:
10 - Liam Girdwood <lgirdwood@gmail.com>
11 - Mark Brown <broonie@kernel.org>
12
13description:
14 Any property defined as part of the core regulator binding, defined in
15 regulator.txt, can also be used.
16
17allOf:
18 - $ref: "regulator.yaml#"
19
20properties:
21 compatible:
22 const: regulator-gpio
23
24 regulator-name: true
25
26 enable-gpios:
27 description: GPIO to use to enable/disable the regulator.
28 Warning, the GPIO phandle flags are ignored and the GPIO polarity is
29 controlled solely by the presence of "enable-active-high" DT property.
30 This is due to compatibility with old DTs.
31 maxItems: 1
32
33 gpios:
34 description: Array of one or more GPIO pins used to select the regulator
35 voltage/current listed in "states".
36 minItems: 1
37 maxItems: 8 # Should be enough...
38
39 gpios-states:
40 description: |
41 On operating systems, that don't support reading back gpio values in
42 output mode (most notably linux), this array provides the state of GPIO
43 pins set when requesting them from the gpio controller. Systems, that are
44 capable of preserving state when requesting the lines, are free to ignore
45 this property.
46 0: LOW
47 1: HIGH
48 Default is LOW if nothing else is specified.
49 allOf:
50 - $ref: /schemas/types.yaml#/definitions/uint32-array
51 - maxItems: 8
52 items:
53 enum: [ 0, 1 ]
54 default: 0
55
56 states:
57 description: Selection of available voltages/currents provided by this
58 regulator and matching GPIO configurations to achieve them. If there are
59 no states in the "states" array, use a fixed regulator instead.
60 allOf:
61 - $ref: /schemas/types.yaml#/definitions/uint32-matrix
62 - maxItems: 8
63 items:
64 items:
65 - description: Voltage in microvolts
66 - description: GPIO group state value
67
68 startup-delay-us:
69 description: startup time in microseconds
70
71 enable-active-high:
72 description: Polarity of "enable-gpio" GPIO is active HIGH. Default is
73 active LOW.
74 type: boolean
75
76 gpio-open-drain:
77 description:
78 GPIO is open drain type. If this property is missing then default
79 assumption is false.
80 type: boolean
81
82 regulator-type:
83 description: Specifies what is being regulated.
84 allOf:
85 - $ref: /schemas/types.yaml#/definitions/string
86 - enum:
87 - voltage
88 - current
89 default: voltage
90
91required:
92 - compatible
93 - regulator-name
94 - gpios
95 - states
96
97examples:
98 - |
99 gpio-regulator {
100 compatible = "regulator-gpio";
101
102 regulator-name = "mmci-gpio-supply";
103 regulator-min-microvolt = <1800000>;
104 regulator-max-microvolt = <2600000>;
105 regulator-boot-on;
106
107 enable-gpios = <&gpio0 23 0x4>;
108 gpios = <&gpio0 24 0x4
109 &gpio0 25 0x4>;
110 states = <1800000 0x3>,
111 <2200000 0x2>,
112 <2600000 0x1>,
113 <2900000 0x0>;
114
115 startup-delay-us = <100000>;
116 enable-active-high;
117 };
118...
diff --git a/Documentation/devicetree/bindings/regulator/max8660.txt b/Documentation/devicetree/bindings/regulator/max8660.txt
deleted file mode 100644
index 8ba994d8a142..000000000000
--- a/Documentation/devicetree/bindings/regulator/max8660.txt
+++ /dev/null
@@ -1,47 +0,0 @@
1Maxim MAX8660 voltage regulator
2
3Required properties:
4- compatible: must be one of "maxim,max8660", "maxim,max8661"
5- reg: I2C slave address, usually 0x34
6- any required generic properties defined in regulator.txt
7
8Example:
9
10 i2c_master {
11 max8660@34 {
12 compatible = "maxim,max8660";
13 reg = <0x34>;
14
15 regulators {
16 regulator@0 {
17 regulator-compatible= "V3(DCDC)";
18 regulator-min-microvolt = <725000>;
19 regulator-max-microvolt = <1800000>;
20 };
21
22 regulator@1 {
23 regulator-compatible= "V4(DCDC)";
24 regulator-min-microvolt = <725000>;
25 regulator-max-microvolt = <1800000>;
26 };
27
28 regulator@2 {
29 regulator-compatible= "V5(LDO)";
30 regulator-min-microvolt = <1700000>;
31 regulator-max-microvolt = <2000000>;
32 };
33
34 regulator@3 {
35 regulator-compatible= "V6(LDO)";
36 regulator-min-microvolt = <1800000>;
37 regulator-max-microvolt = <3300000>;
38 };
39
40 regulator@4 {
41 regulator-compatible= "V7(LDO)";
42 regulator-min-microvolt = <1800000>;
43 regulator-max-microvolt = <3300000>;
44 };
45 };
46 };
47 };
diff --git a/Documentation/devicetree/bindings/regulator/max8660.yaml b/Documentation/devicetree/bindings/regulator/max8660.yaml
new file mode 100644
index 000000000000..9c038698f880
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/max8660.yaml
@@ -0,0 +1,77 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/regulator/max8660.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Maxim MAX8660 voltage regulator
8
9maintainers:
10 - Daniel Mack <zonque@gmail.com>
11
12properties:
13 $nodename:
14 pattern: "pmic@[0-9a-f]{1,2}"
15 compatible:
16 enum:
17 - maxim,max8660
18 - maxim,max8661
19
20 reg:
21 maxItems: 1
22
23 regulators:
24 type: object
25
26 patternProperties:
27 "regulator-.+":
28 $ref: "regulator.yaml#"
29
30 additionalProperties: false
31
32additionalProperties: false
33
34examples:
35 - |
36 i2c {
37 #address-cells = <1>;
38 #size-cells = <0>;
39
40 pmic@34 {
41 compatible = "maxim,max8660";
42 reg = <0x34>;
43
44 regulators {
45 regulator-V3 {
46 regulator-compatible= "V3(DCDC)";
47 regulator-min-microvolt = <725000>;
48 regulator-max-microvolt = <1800000>;
49 };
50
51 regulator-V4 {
52 regulator-compatible= "V4(DCDC)";
53 regulator-min-microvolt = <725000>;
54 regulator-max-microvolt = <1800000>;
55 };
56
57 regulator-V5 {
58 regulator-compatible= "V5(LDO)";
59 regulator-min-microvolt = <1700000>;
60 regulator-max-microvolt = <2000000>;
61 };
62
63 regulator-V6 {
64 regulator-compatible= "V6(LDO)";
65 regulator-min-microvolt = <1800000>;
66 regulator-max-microvolt = <3300000>;
67 };
68
69 regulator-V7 {
70 regulator-compatible= "V7(LDO)";
71 regulator-min-microvolt = <1800000>;
72 regulator-max-microvolt = <3300000>;
73 };
74 };
75 };
76 };
77...
diff --git a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
index 406f2e570c50..430b8622bda1 100644
--- a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
@@ -4,11 +4,13 @@ Qualcomm SPMI Regulators
4 Usage: required 4 Usage: required
5 Value type: <string> 5 Value type: <string>
6 Definition: must be one of: 6 Definition: must be one of:
7 "qcom,pm8005-regulators"
7 "qcom,pm8841-regulators" 8 "qcom,pm8841-regulators"
8 "qcom,pm8916-regulators" 9 "qcom,pm8916-regulators"
9 "qcom,pm8941-regulators" 10 "qcom,pm8941-regulators"
10 "qcom,pm8994-regulators" 11 "qcom,pm8994-regulators"
11 "qcom,pmi8994-regulators" 12 "qcom,pmi8994-regulators"
13 "qcom,pms405-regulators"
12 14
13- interrupts: 15- interrupts:
14 Usage: optional 16 Usage: optional
@@ -110,6 +112,23 @@ Qualcomm SPMI Regulators
110 Definition: Reference to regulator supplying the input pin, as 112 Definition: Reference to regulator supplying the input pin, as
111 described in the data sheet. 113 described in the data sheet.
112 114
115- vdd_l1_l2-supply:
116- vdd_l3_l8-supply:
117- vdd_l4-supply:
118- vdd_l5_l6-supply:
119- vdd_l10_l11_l12_l13-supply:
120- vdd_l7-supply:
121- vdd_l9-supply:
122- vdd_s1-supply:
123- vdd_s2-supply:
124- vdd_s3-supply:
125- vdd_s4-supply:
126- vdd_s5-supply
127 Usage: optional (pms405 only)
128 Value type: <phandle>
129 Definition: Reference to regulator supplying the input pin, as
130 described in the data sheet.
131
113- qcom,saw-reg: 132- qcom,saw-reg:
114 Usage: optional 133 Usage: optional
115 Value type: <phandle> 134 Value type: <phandle>
@@ -120,6 +139,9 @@ The regulator node houses sub-nodes for each regulator within the device. Each
120sub-node is identified using the node's name, with valid values listed for each 139sub-node is identified using the node's name, with valid values listed for each
121of the PMICs below. 140of the PMICs below.
122 141
142pm8005:
143 s1, s2, s3, s4
144
123pm8841: 145pm8841:
124 s1, s2, s3, s4, s5, s6, s7, s8 146 s1, s2, s3, s4, s5, s6, s7, s8
125 147
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 0a3f087d5844..487ccd8370b3 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -1,139 +1 @@
1Voltage/Current Regulators This file has moved to regulator.yaml.
2
3Optional properties:
4- regulator-name: A string used as a descriptive name for regulator outputs
5- regulator-min-microvolt: smallest voltage consumers may set
6- regulator-max-microvolt: largest voltage consumers may set
7- regulator-microvolt-offset: Offset applied to voltages to compensate for voltage drops
8- regulator-min-microamp: smallest current consumers may set
9- regulator-max-microamp: largest current consumers may set
10- regulator-input-current-limit-microamp: maximum input current regulator allows
11- regulator-always-on: boolean, regulator should never be disabled
12- regulator-boot-on: bootloader/firmware enabled regulator
13- regulator-allow-bypass: allow the regulator to go into bypass mode
14- regulator-allow-set-load: allow the regulator performance level to be configured
15- <name>-supply: phandle to the parent supply/regulator node
16- regulator-ramp-delay: ramp delay for regulator(in uV/us)
17 For hardware which supports disabling ramp rate, it should be explicitly
18 initialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay.
19- regulator-enable-ramp-delay: The time taken, in microseconds, for the supply
20 rail to reach the target voltage, plus/minus whatever tolerance the board
21 design requires. This property describes the total system ramp time
22 required due to the combination of internal ramping of the regulator itself,
23 and board design issues such as trace capacitance and load on the supply.
24- regulator-settling-time-us: Settling time, in microseconds, for voltage
25 change if regulator have the constant time for any level voltage change.
26 This is useful when regulator have exponential voltage change.
27- regulator-settling-time-up-us: Settling time, in microseconds, for voltage
28 increase if the regulator needs a constant time to settle after voltage
29 increases of any level. This is useful for regulators with exponential
30 voltage changes.
31- regulator-settling-time-down-us: Settling time, in microseconds, for voltage
32 decrease if the regulator needs a constant time to settle after voltage
33 decreases of any level. This is useful for regulators with exponential
34 voltage changes.
35- regulator-soft-start: Enable soft start so that voltage ramps slowly
36- regulator-state-standby sub-root node for Standby mode
37 : equivalent with standby Linux sleep state, which provides energy savings
38 with a relatively quick transition back time.
39- regulator-state-mem sub-root node for Suspend-to-RAM mode
40 : suspend to memory, the device goes to sleep, but all data stored in memory,
41 only some external interrupt can wake the device.
42- regulator-state-disk sub-root node for Suspend-to-DISK mode
43 : suspend to disk, this state operates similarly to Suspend-to-RAM,
44 but includes a final step of writing memory contents to disk.
45- regulator-state-[mem/disk/standby] node has following common properties:
46 - regulator-on-in-suspend: regulator should be on in suspend state.
47 - regulator-off-in-suspend: regulator should be off in suspend state.
48 - regulator-suspend-min-microvolt: minimum voltage may be set in
49 suspend state.
50 - regulator-suspend-max-microvolt: maximum voltage may be set in
51 suspend state.
52 - regulator-suspend-microvolt: the default voltage which regulator
53 would be set in suspend. This property is now deprecated, instead
54 setting voltage for suspend mode via the API which regulator
55 driver provides is recommended.
56 - regulator-changeable-in-suspend: whether the default voltage and
57 the regulator on/off in suspend can be changed in runtime.
58 - regulator-mode: operating mode in the given suspend state.
59 The set of possible operating modes depends on the capabilities of
60 every hardware so the valid modes are documented on each regulator
61 device tree binding document.
62- regulator-initial-mode: initial operating mode. The set of possible operating
63 modes depends on the capabilities of every hardware so each device binding
64 documentation explains which values the regulator supports.
65- regulator-allowed-modes: list of operating modes that software is allowed to
66 configure for the regulator at run-time. Elements may be specified in any
67 order. The set of possible operating modes depends on the capabilities of
68 every hardware so each device binding document explains which values the
69 regulator supports.
70- regulator-system-load: Load in uA present on regulator that is not captured by
71 any consumer request.
72- regulator-pull-down: Enable pull down resistor when the regulator is disabled.
73- regulator-over-current-protection: Enable over current protection.
74- regulator-active-discharge: tristate, enable/disable active discharge of
75 regulators. The values are:
76 0: Disable active discharge.
77 1: Enable active discharge.
78 Absence of this property will leave configuration to default.
79- regulator-coupled-with: Regulators with which the regulator
80 is coupled. The linkage is 2-way - all coupled regulators should be linked
81 with each other. A regulator should not be coupled with its supplier.
82- regulator-coupled-max-spread: Array of maximum spread between voltages of
83 coupled regulators in microvolts, each value in the array relates to the
84 corresponding couple specified by the regulator-coupled-with property.
85- regulator-max-step-microvolt: Maximum difference between current and target
86 voltages that can be changed safely in a single step.
87
88Deprecated properties:
89- regulator-compatible: If a regulator chip contains multiple
90 regulators, and if the chip's binding contains a child node that
91 describes each regulator, then this property indicates which regulator
92 this child node is intended to configure. If this property is missing,
93 the node's name will be used instead.
94
95Example:
96
97 xyzreg: regulator@0 {
98 regulator-min-microvolt = <1000000>;
99 regulator-max-microvolt = <2500000>;
100 regulator-always-on;
101 vin-supply = <&vin>;
102
103 regulator-state-mem {
104 regulator-on-in-suspend;
105 };
106 };
107
108Regulator Consumers:
109Consumer nodes can reference one or more of its supplies/
110regulators using the below bindings.
111
112- <name>-supply: phandle to the regulator node
113
114These are the same bindings that a regulator in the above
115example used to reference its own supply, in which case
116its just seen as a special case of a regulator being a
117consumer itself.
118
119Example of a consumer device node (mmc) referencing two
120regulators (twl_reg1 and twl_reg2),
121
122 twl_reg1: regulator@0 {
123 ...
124 ...
125 ...
126 };
127
128 twl_reg2: regulator@1 {
129 ...
130 ...
131 ...
132 };
133
134 mmc: mmc@0 {
135 ...
136 ...
137 vmmc-supply = <&twl_reg1>;
138 vmmcaux-supply = <&twl_reg2>;
139 };
diff --git a/Documentation/devicetree/bindings/regulator/regulator.yaml b/Documentation/devicetree/bindings/regulator/regulator.yaml
new file mode 100644
index 000000000000..02c3043ce419
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/regulator.yaml
@@ -0,0 +1,200 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/regulator/regulator.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Voltage/Current Regulators
8
9maintainers:
10 - Liam Girdwood <lgirdwood@gmail.com>
11 - Mark Brown <broonie@kernel.org>
12
13properties:
14 regulator-name:
15 description: A string used as a descriptive name for regulator outputs
16 $ref: "/schemas/types.yaml#/definitions/string"
17
18 regulator-min-microvolt:
19 description: smallest voltage consumers may set
20
21 regulator-max-microvolt:
22 description: largest voltage consumers may set
23
24 regulator-microvolt-offset:
25 description: Offset applied to voltages to compensate for voltage drops
26
27 regulator-min-microamp:
28 description: smallest current consumers may set
29
30 regulator-max-microamp:
31 description: largest current consumers may set
32
33 regulator-input-current-limit-microamp:
34 description: maximum input current regulator allows
35
36 regulator-always-on:
37 description: boolean, regulator should never be disabled
38 type: boolean
39
40 regulator-boot-on:
41 description: bootloader/firmware enabled regulator
42 type: boolean
43
44 regulator-allow-bypass:
45 description: allow the regulator to go into bypass mode
46 type: boolean
47
48 regulator-allow-set-load:
49 description: allow the regulator performance level to be configured
50 type: boolean
51
52 regulator-ramp-delay:
53 description: ramp delay for regulator(in uV/us) For hardware which supports
54 disabling ramp rate, it should be explicitly initialised to zero (regulator-ramp-delay
55 = <0>) for disabling ramp delay.
56 $ref: "/schemas/types.yaml#/definitions/uint32"
57
58 regulator-enable-ramp-delay:
59 description: The time taken, in microseconds, for the supply rail to
60 reach the target voltage, plus/minus whatever tolerance the board
61 design requires. This property describes the total system ramp time
62 required due to the combination of internal ramping of the regulator
63 itself, and board design issues such as trace capacitance and load
64 on the supply.
65 $ref: "/schemas/types.yaml#/definitions/uint32"
66
67 regulator-settling-time-us:
68 description: Settling time, in microseconds, for voltage change if regulator
69 have the constant time for any level voltage change. This is useful
70 when regulator have exponential voltage change.
71
72 regulator-settling-time-up-us:
73 description: Settling time, in microseconds, for voltage increase if
74 the regulator needs a constant time to settle after voltage increases
75 of any level. This is useful for regulators with exponential voltage
76 changes.
77
78 regulator-settling-time-down-us:
79 description: Settling time, in microseconds, for voltage decrease if
80 the regulator needs a constant time to settle after voltage decreases
81 of any level. This is useful for regulators with exponential voltage
82 changes.
83
84 regulator-soft-start:
85 description: Enable soft start so that voltage ramps slowly
86 type: boolean
87
88 regulator-initial-mode:
89 description: initial operating mode. The set of possible operating modes
90 depends on the capabilities of every hardware so each device binding
91 documentation explains which values the regulator supports.
92 $ref: "/schemas/types.yaml#/definitions/uint32"
93
94 regulator-allowed-modes:
95 description: list of operating modes that software is allowed to configure
96 for the regulator at run-time. Elements may be specified in any order.
97 The set of possible operating modes depends on the capabilities of
98 every hardware so each device binding document explains which values
99 the regulator supports.
100 $ref: "/schemas/types.yaml#/definitions/uint32-array"
101
102 regulator-system-load:
103 description: Load in uA present on regulator that is not captured by
104 any consumer request.
105 $ref: "/schemas/types.yaml#/definitions/uint32"
106
107 regulator-pull-down:
108 description: Enable pull down resistor when the regulator is disabled.
109 type: boolean
110
111 regulator-over-current-protection:
112 description: Enable over current protection.
113 type: boolean
114
115 regulator-active-discharge:
116 description: |
117 tristate, enable/disable active discharge of regulators. The values are:
118 0: Disable active discharge.
119 1: Enable active discharge.
120 Absence of this property will leave configuration to default.
121 allOf:
122 - $ref: "/schemas/types.yaml#/definitions/uint32"
123 - enum: [ 0, 1 ]
124
125 regulator-coupled-with:
126 description: Regulators with which the regulator is coupled. The linkage
127 is 2-way - all coupled regulators should be linked with each other.
128 A regulator should not be coupled with its supplier.
129 $ref: "/schemas/types.yaml#/definitions/phandle-array"
130
131 regulator-coupled-max-spread:
132 description: Array of maximum spread between voltages of coupled regulators
133 in microvolts, each value in the array relates to the corresponding
134 couple specified by the regulator-coupled-with property.
135 $ref: "/schemas/types.yaml#/definitions/uint32"
136
137 regulator-max-step-microvolt:
138 description: Maximum difference between current and target voltages
139 that can be changed safely in a single step.
140
141patternProperties:
142 ".*-supply$":
143 description: Input supply phandle(s) for this node
144
145 regulator-state-(standby|mem|disk):
146 type: object
147 description:
148 sub-nodes for regulator state in Standby, Suspend-to-RAM, and
149 Suspend-to-DISK modes. Equivalent with standby, mem, and disk Linux
150 sleep states.
151
152 properties:
153 regulator-on-in-suspend:
154 description: regulator should be on in suspend state.
155 type: boolean
156
157 regulator-off-in-suspend:
158 description: regulator should be off in suspend state.
159 type: boolean
160
161 regulator-suspend-min-microvolt:
162 description: minimum voltage may be set in suspend state.
163
164 regulator-suspend-max-microvolt:
165 description: maximum voltage may be set in suspend state.
166
167 regulator-suspend-microvolt:
168 description: the default voltage which regulator would be set in
169 suspend. This property is now deprecated, instead setting voltage
170 for suspend mode via the API which regulator driver provides is
171 recommended.
172
173 regulator-changeable-in-suspend:
174 description: whether the default voltage and the regulator on/off
175 in suspend can be changed in runtime.
176 type: boolean
177
178 regulator-mode:
179 description: operating mode in the given suspend state. The set
180 of possible operating modes depends on the capabilities of every
181 hardware so the valid modes are documented on each regulator device
182 tree binding document.
183 $ref: "/schemas/types.yaml#/definitions/uint32"
184
185 additionalProperties: false
186
187examples:
188 - |
189 xyzreg: regulator@0 {
190 regulator-min-microvolt = <1000000>;
191 regulator-max-microvolt = <2500000>;
192 regulator-always-on;
193 vin-supply = <&vin>;
194
195 regulator-state-mem {
196 regulator-on-in-suspend;
197 };
198 };
199
200...
diff --git a/Documentation/devicetree/bindings/regulator/slg51000.txt b/Documentation/devicetree/bindings/regulator/slg51000.txt
new file mode 100644
index 000000000000..aa0733e49b90
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/slg51000.txt
@@ -0,0 +1,88 @@
1* Dialog Semiconductor SLG51000 Voltage Regulator
2
3Required properties:
4- compatible : Should be "dlg,slg51000" for SLG51000
5- reg : Specifies the I2C slave address.
6- xxx-supply: Input voltage supply regulator for ldo3 to ldo7.
7 These entries are required if regulators are enabled for a device.
8 An absence of these properties can cause the regulator registration to fail.
9 If some of input supply is powered through battery or always-on supply then
10 also it is required to have these parameters with proper node handle of always
11 on power supply.
12 vin3-supply: Input supply for ldo3
13 vin4-supply: Input supply for ldo4
14 vin5-supply: Input supply for ldo5
15 vin6-supply: Input supply for ldo6
16 vin7-supply: Input supply for ldo7
17
18Optional properties:
19- interrupt-parent : Specifies the reference to the interrupt controller.
20- interrupts : IRQ line information.
21- dlg,cs-gpios : Specify a valid GPIO for chip select
22
23Sub-nodes:
24- regulators : This node defines the settings for the regulators.
25 The content of the sub-node is defined by the standard binding
26 for regulators; see regulator.txt.
27
28 The SLG51000 regulators are bound using their names listed below:
29 ldo1
30 ldo2
31 ldo3
32 ldo4
33 ldo5
34 ldo6
35 ldo7
36
37Optional properties for regulators:
38- enable-gpios : Specify a valid GPIO for platform control of the regulator.
39
40Example:
41 pmic: slg51000@75 {
42 compatible = "dlg,slg51000";
43 reg = <0x75>;
44
45 regulators {
46 ldo1 {
47 regulator-name = "ldo1";
48 regulator-min-microvolt = <2400000>;
49 regulator-max-microvolt = <3300000>;
50 };
51
52 ldo2 {
53 regulator-name = "ldo2";
54 regulator-min-microvolt = <2400000>;
55 regulator-max-microvolt = <3300000>;
56 };
57
58 ldo3 {
59 regulator-name = "ldo3";
60 regulator-min-microvolt = <1200000>;
61 regulator-max-microvolt = <3750000>;
62 };
63
64 ldo4 {
65 regulator-name = "ldo4";
66 regulator-min-microvolt = <1200000>;
67 regulator-max-microvolt = <3750000>;
68 };
69
70 ldo5 {
71 regulator-name = "ldo5";
72 regulator-min-microvolt = <500000>;
73 regulator-max-microvolt = <1200000>;
74 };
75
76 ldo6 {
77 regulator-name = "ldo6";
78 regulator-min-microvolt = <500000>;
79 regulator-max-microvolt = <1200000>;
80 };
81
82 ldo7 {
83 regulator-name = "ldo7";
84 regulator-min-microvolt = <1200000>;
85 regulator-max-microvolt = <3750000>;
86 };
87 };
88 };
diff --git a/Documentation/devicetree/bindings/regulator/st,stm32-booster.txt b/Documentation/devicetree/bindings/regulator/st,stm32-booster.txt
new file mode 100644
index 000000000000..479ad4c8758e
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/st,stm32-booster.txt
@@ -0,0 +1,18 @@
1STM32 BOOSTER - Booster for ADC analog input switches
2
3Some STM32 devices embed a 3.3V booster supplied by Vdda, that can be used
4to supply ADC analog input switches.
5
6Required properties:
7- compatible: Should be one of:
8 "st,stm32h7-booster"
9 "st,stm32mp1-booster"
10- st,syscfg: Phandle to system configuration controller.
11- vdda-supply: Phandle to the vdda input analog voltage.
12
13Example:
14 booster: regulator-booster {
15 compatible = "st,stm32mp1-booster";
16 st,syscfg = <&syscfg>;
17 vdda-supply = <&vdda>;
18 };
diff --git a/MAINTAINERS b/MAINTAINERS
index e61476a388b1..aa738a14bf6e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4714,6 +4714,7 @@ F: Documentation/devicetree/bindings/mfd/da90*.txt
4714F: Documentation/devicetree/bindings/input/da90??-onkey.txt 4714F: Documentation/devicetree/bindings/input/da90??-onkey.txt
4715F: Documentation/devicetree/bindings/thermal/da90??-thermal.txt 4715F: Documentation/devicetree/bindings/thermal/da90??-thermal.txt
4716F: Documentation/devicetree/bindings/regulator/da92*.txt 4716F: Documentation/devicetree/bindings/regulator/da92*.txt
4717F: Documentation/devicetree/bindings/regulator/slg51000.txt
4717F: Documentation/devicetree/bindings/watchdog/da90??-wdt.txt 4718F: Documentation/devicetree/bindings/watchdog/da90??-wdt.txt
4718F: Documentation/devicetree/bindings/sound/da[79]*.txt 4719F: Documentation/devicetree/bindings/sound/da[79]*.txt
4719F: drivers/gpio/gpio-da90??.c 4720F: drivers/gpio/gpio-da90??.c
@@ -4729,6 +4730,7 @@ F: drivers/power/supply/da9052-battery.c
4729F: drivers/power/supply/da91??-*.c 4730F: drivers/power/supply/da91??-*.c
4730F: drivers/regulator/da903x.c 4731F: drivers/regulator/da903x.c
4731F: drivers/regulator/da9???-regulator.[ch] 4732F: drivers/regulator/da9???-regulator.[ch]
4733F: drivers/regulator/slg51000-regulator.[ch]
4732F: drivers/thermal/da90??-thermal.c 4734F: drivers/thermal/da90??-thermal.c
4733F: drivers/rtc/rtc-da90??.c 4735F: drivers/rtc/rtc-da90??.c
4734F: drivers/video/backlight/da90??_bl.c 4736F: drivers/video/backlight/da90??_bl.c
diff --git a/arch/arm/mach-s3c64xx/mach-crag6410.c b/arch/arm/mach-s3c64xx/mach-crag6410.c
index 379424d72ae7..8ec6a4f5eb05 100644
--- a/arch/arm/mach-s3c64xx/mach-crag6410.c
+++ b/arch/arm/mach-s3c64xx/mach-crag6410.c
@@ -15,6 +15,7 @@
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/gpio/machine.h>
18#include <linux/leds.h> 19#include <linux/leds.h>
19#include <linux/delay.h> 20#include <linux/delay.h>
20#include <linux/mmc/host.h> 21#include <linux/mmc/host.h>
@@ -398,7 +399,6 @@ static struct pca953x_platform_data crag6410_pca_data = {
398/* VDDARM is controlled by DVS1 connected to GPK(0) */ 399/* VDDARM is controlled by DVS1 connected to GPK(0) */
399static struct wm831x_buckv_pdata vddarm_pdata = { 400static struct wm831x_buckv_pdata vddarm_pdata = {
400 .dvs_control_src = 1, 401 .dvs_control_src = 1,
401 .dvs_gpio = S3C64XX_GPK(0),
402}; 402};
403 403
404static struct regulator_consumer_supply vddarm_consumers[] = { 404static struct regulator_consumer_supply vddarm_consumers[] = {
@@ -596,6 +596,24 @@ static struct wm831x_pdata crag_pmic_pdata = {
596 .touch = &touch_pdata, 596 .touch = &touch_pdata,
597}; 597};
598 598
599/*
600 * VDDARM is eventually ending up as a regulator hanging on the MFD cell device
601 * "wm831x-buckv.1" spawn from drivers/mfd/wm831x-core.c.
602 *
603 * From the note on the platform data we can see that this is clearly DVS1
604 * and assigned as dcdc1 resource to the MFD core which sets .id of the cell
605 * spawning the DVS1 platform device to 1, then the cell platform device
606 * name is calculated from 10*instance + id resulting in the device name
607 * "wm831x-buckv.11"
608 */
609static struct gpiod_lookup_table crag_pmic_gpiod_table = {
610 .dev_id = "wm831x-buckv.11",
611 .table = {
612 GPIO_LOOKUP("GPIOK", 0, "dvs", GPIO_ACTIVE_HIGH),
613 { },
614 },
615};
616
599static struct i2c_board_info i2c_devs0[] = { 617static struct i2c_board_info i2c_devs0[] = {
600 { I2C_BOARD_INFO("24c08", 0x50), }, 618 { I2C_BOARD_INFO("24c08", 0x50), },
601 { I2C_BOARD_INFO("tca6408", 0x20), 619 { I2C_BOARD_INFO("tca6408", 0x20),
@@ -836,6 +854,7 @@ static void __init crag6410_machine_init(void)
836 s3c_fb_set_platdata(&crag6410_lcd_pdata); 854 s3c_fb_set_platdata(&crag6410_lcd_pdata);
837 dwc2_hsotg_set_platdata(&crag6410_hsotg_pdata); 855 dwc2_hsotg_set_platdata(&crag6410_hsotg_pdata);
838 856
857 gpiod_add_lookup_table(&crag_pmic_gpiod_table);
839 i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0)); 858 i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));
840 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1)); 859 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
841 860
diff --git a/arch/arm64/boot/dts/qcom/msm8998-mtp.dtsi b/arch/arm64/boot/dts/qcom/msm8998-mtp.dtsi
index f09f3e03f708..108667ce4f31 100644
--- a/arch/arm64/boot/dts/qcom/msm8998-mtp.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8998-mtp.dtsi
@@ -27,6 +27,23 @@
27 status = "okay"; 27 status = "okay";
28}; 28};
29 29
30&pm8005_lsid1 {
31 pm8005-regulators {
32 compatible = "qcom,pm8005-regulators";
33
34 vdd_s1-supply = <&vph_pwr>;
35
36 pm8005_s1: s1 { /* VDD_GFX supply */
37 regulator-min-microvolt = <524000>;
38 regulator-max-microvolt = <1100000>;
39 regulator-enable-ramp-delay = <500>;
40
41 /* hack until we rig up the gpu consumer */
42 regulator-always-on;
43 };
44 };
45};
46
30&qusb2phy { 47&qusb2phy {
31 status = "okay"; 48 status = "okay";
32 49
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 47a67c4deed4..3ee99d070608 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4257,8 +4257,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_index);
4257 * 4257 *
4258 * Returns: 4258 * Returns:
4259 * On successful request the GPIO pin is configured in accordance with 4259 * On successful request the GPIO pin is configured in accordance with
4260 * provided @dflags. If the node does not have the requested GPIO 4260 * provided @dflags.
4261 * property, NULL is returned.
4262 * 4261 *
4263 * In case of error an ERR_PTR() is returned. 4262 * In case of error an ERR_PTR() is returned.
4264 */ 4263 */
@@ -4280,9 +4279,6 @@ struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
4280 index, &flags); 4279 index, &flags);
4281 4280
4282 if (!desc || IS_ERR(desc)) { 4281 if (!desc || IS_ERR(desc)) {
4283 /* If it is not there, just return NULL */
4284 if (PTR_ERR(desc) == -ENOENT)
4285 return NULL;
4286 return desc; 4282 return desc;
4287 } 4283 }
4288 4284
diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800-regulator.c
index 69ae25886181..69ae25886181 100644
--- a/drivers/regulator/88pm800.c
+++ b/drivers/regulator/88pm800-regulator.c
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index b5d0e07a62d7..7928960563e6 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -136,19 +136,20 @@ config REGULATOR_AB8500
136 signal AB8500 PMIC 136 signal AB8500 PMIC
137 137
138config REGULATOR_ARIZONA_LDO1 138config REGULATOR_ARIZONA_LDO1
139 tristate "Wolfson Arizona class devices LDO1" 139 tristate "Cirrus Madera and Wolfson Arizona class devices LDO1"
140 depends on MFD_ARIZONA 140 depends on MFD_ARIZONA || MFD_MADERA
141 depends on SND_SOC 141 depends on SND_SOC
142 help 142 help
143 Support for the LDO1 regulators found on Wolfson Arizona class 143 Support for the LDO1 regulators found on Cirrus Logic Madera codecs
144 devices. 144 and Wolfson Microelectronic Arizona codecs.
145 145
146config REGULATOR_ARIZONA_MICSUPP 146config REGULATOR_ARIZONA_MICSUPP
147 tristate "Wolfson Arizona class devices MICSUPP" 147 tristate "Cirrus Madera and Wolfson Arizona class devices MICSUPP"
148 depends on MFD_ARIZONA 148 depends on MFD_ARIZONA || MFD_MADERA
149 depends on SND_SOC 149 depends on SND_SOC
150 help 150 help
151 Support for the MICSUPP regulators found on Wolfson Arizona class 151 Support for the MICSUPP regulators found on Cirrus Logic Madera codecs
152 and Wolfson Microelectronic Arizona codecs
152 devices. 153 devices.
153 154
154config REGULATOR_AS3711 155config REGULATOR_AS3711
@@ -258,7 +259,7 @@ config REGULATOR_DA9062
258 259
259config REGULATOR_DA9063 260config REGULATOR_DA9063
260 tristate "Dialog Semiconductor DA9063 regulators" 261 tristate "Dialog Semiconductor DA9063 regulators"
261 depends on MFD_DA9063 262 depends on MFD_DA9063 && OF
262 help 263 help
263 Say y here to support the BUCKs and LDOs regulators found on 264 Say y here to support the BUCKs and LDOs regulators found on
264 DA9063 PMICs. 265 DA9063 PMICs.
@@ -829,6 +830,26 @@ config REGULATOR_SKY81452
829 This driver can also be built as a module. If so, the module 830 This driver can also be built as a module. If so, the module
830 will be called sky81452-regulator. 831 will be called sky81452-regulator.
831 832
833config REGULATOR_SLG51000
834 tristate "Dialog Semiconductor SLG51000 regulators"
835 depends on I2C
836 select REGMAP_I2C
837 help
838 Say y here to support for the Dialog Semiconductor SLG51000.
839 The SLG51000 is seven compact and customizable low dropout
840 regulators.
841
842config REGULATOR_STM32_BOOSTER
843 tristate "STMicroelectronics STM32 BOOSTER"
844 depends on ARCH_STM32 || COMPILE_TEST
845 help
846 This driver supports internal booster (3V3) embedded in some
847 STMicroelectronics STM32 chips. It can be used to supply ADC analog
848 input switches when vdda supply is below 2.7V.
849
850 This driver can also be built as a module. If so, the module
851 will be called stm32-booster.
852
832config REGULATOR_STM32_VREFBUF 853config REGULATOR_STM32_VREFBUF
833 tristate "STMicroelectronics STM32 VREFBUF" 854 tristate "STMicroelectronics STM32 VREFBUF"
834 depends on ARCH_STM32 || COMPILE_TEST 855 depends on ARCH_STM32 || COMPILE_TEST
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 93f53840e8f1..eef73b5a35a4 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
11obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 11obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
12 12
13obj-$(CONFIG_REGULATOR_88PG86X) += 88pg86x.o 13obj-$(CONFIG_REGULATOR_88PG86X) += 88pg86x.o
14obj-$(CONFIG_REGULATOR_88PM800) += 88pm800.o 14obj-$(CONFIG_REGULATOR_88PM800) += 88pm800-regulator.o
15obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 15obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
16obj-$(CONFIG_REGULATOR_CPCAP) += cpcap-regulator.o 16obj-$(CONFIG_REGULATOR_CPCAP) += cpcap-regulator.o
17obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o 17obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o
@@ -104,6 +104,8 @@ obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
104obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 104obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
105obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o 105obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
106obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o 106obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
107obj-$(CONFIG_REGULATOR_SLG51000) += slg51000-regulator.o
108obj-$(CONFIG_REGULATOR_STM32_BOOSTER) += stm32-booster.o
107obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o 109obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
108obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o 110obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
109obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o 111obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index e4bc7b1e5ccd..1a3d7b720f5e 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -25,6 +25,10 @@
25#include <linux/mfd/arizona/pdata.h> 25#include <linux/mfd/arizona/pdata.h>
26#include <linux/mfd/arizona/registers.h> 26#include <linux/mfd/arizona/registers.h>
27 27
28#include <linux/mfd/madera/core.h>
29#include <linux/mfd/madera/pdata.h>
30#include <linux/mfd/madera/registers.h>
31
28struct arizona_ldo1 { 32struct arizona_ldo1 {
29 struct regulator_dev *regulator; 33 struct regulator_dev *regulator;
30 struct regmap *regmap; 34 struct regmap *regmap;
@@ -158,6 +162,31 @@ static const struct regulator_init_data arizona_ldo1_wm5110 = {
158 .num_consumer_supplies = 1, 162 .num_consumer_supplies = 1,
159}; 163};
160 164
165static const struct regulator_desc madera_ldo1 = {
166 .name = "LDO1",
167 .supply_name = "LDOVDD",
168 .type = REGULATOR_VOLTAGE,
169 .ops = &arizona_ldo1_ops,
170
171 .vsel_reg = MADERA_LDO1_CONTROL_1,
172 .vsel_mask = MADERA_LDO1_VSEL_MASK,
173 .min_uV = 900000,
174 .uV_step = 25000,
175 .n_voltages = 13,
176 .enable_time = 3000,
177
178 .owner = THIS_MODULE,
179};
180
181static const struct regulator_init_data madera_ldo1_default = {
182 .constraints = {
183 .min_uV = 1200000,
184 .max_uV = 1200000,
185 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
186 },
187 .num_consumer_supplies = 1,
188};
189
161static int arizona_ldo1_of_get_pdata(struct arizona_ldo1_pdata *pdata, 190static int arizona_ldo1_of_get_pdata(struct arizona_ldo1_pdata *pdata,
162 struct regulator_config *config, 191 struct regulator_config *config,
163 const struct regulator_desc *desc, 192 const struct regulator_desc *desc,
@@ -320,6 +349,32 @@ static int arizona_ldo1_remove(struct platform_device *pdev)
320 return 0; 349 return 0;
321} 350}
322 351
352static int madera_ldo1_probe(struct platform_device *pdev)
353{
354 struct madera *madera = dev_get_drvdata(pdev->dev.parent);
355 struct arizona_ldo1 *ldo1;
356 bool external_dcvdd;
357 int ret;
358
359 ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
360 if (!ldo1)
361 return -ENOMEM;
362
363 ldo1->regmap = madera->regmap;
364
365 ldo1->init_data = madera_ldo1_default;
366
367 ret = arizona_ldo1_common_init(pdev, ldo1, &madera_ldo1,
368 &madera->pdata.ldo1,
369 &external_dcvdd);
370 if (ret)
371 return ret;
372
373 madera->internal_dcvdd = !external_dcvdd;
374
375 return 0;
376}
377
323static struct platform_driver arizona_ldo1_driver = { 378static struct platform_driver arizona_ldo1_driver = {
324 .probe = arizona_ldo1_probe, 379 .probe = arizona_ldo1_probe,
325 .remove = arizona_ldo1_remove, 380 .remove = arizona_ldo1_remove,
@@ -328,10 +383,36 @@ static struct platform_driver arizona_ldo1_driver = {
328 }, 383 },
329}; 384};
330 385
331module_platform_driver(arizona_ldo1_driver); 386static struct platform_driver madera_ldo1_driver = {
387 .probe = madera_ldo1_probe,
388 .remove = arizona_ldo1_remove,
389 .driver = {
390 .name = "madera-ldo1",
391 },
392};
393
394static struct platform_driver * const madera_ldo1_drivers[] = {
395 &arizona_ldo1_driver,
396 &madera_ldo1_driver,
397};
398
399static int __init arizona_ldo1_init(void)
400{
401 return platform_register_drivers(madera_ldo1_drivers,
402 ARRAY_SIZE(madera_ldo1_drivers));
403}
404module_init(arizona_ldo1_init);
405
406static void __exit madera_ldo1_exit(void)
407{
408 platform_unregister_drivers(madera_ldo1_drivers,
409 ARRAY_SIZE(madera_ldo1_drivers));
410}
411module_exit(madera_ldo1_exit);
332 412
333/* Module information */ 413/* Module information */
334MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 414MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
335MODULE_DESCRIPTION("Arizona LDO1 driver"); 415MODULE_DESCRIPTION("Arizona LDO1 driver");
336MODULE_LICENSE("GPL"); 416MODULE_LICENSE("GPL");
337MODULE_ALIAS("platform:arizona-ldo1"); 417MODULE_ALIAS("platform:arizona-ldo1");
418MODULE_ALIAS("platform:madera-ldo1");
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index be0d46da51a1..ae1a5de3e57d 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -16,7 +16,6 @@
16#include <linux/regulator/driver.h> 16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h> 17#include <linux/regulator/machine.h>
18#include <linux/regulator/of_regulator.h> 18#include <linux/regulator/of_regulator.h>
19#include <linux/gpio.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/workqueue.h> 20#include <linux/workqueue.h>
22#include <sound/soc.h> 21#include <sound/soc.h>
@@ -25,6 +24,10 @@
25#include <linux/mfd/arizona/pdata.h> 24#include <linux/mfd/arizona/pdata.h>
26#include <linux/mfd/arizona/registers.h> 25#include <linux/mfd/arizona/registers.h>
27 26
27#include <linux/mfd/madera/core.h>
28#include <linux/mfd/madera/pdata.h>
29#include <linux/mfd/madera/registers.h>
30
28#include <linux/regulator/arizona-micsupp.h> 31#include <linux/regulator/arizona-micsupp.h>
29 32
30struct arizona_micsupp { 33struct arizona_micsupp {
@@ -200,6 +203,28 @@ static const struct regulator_init_data arizona_micsupp_ext_default = {
200 .num_consumer_supplies = 1, 203 .num_consumer_supplies = 1,
201}; 204};
202 205
206static const struct regulator_desc madera_micsupp = {
207 .name = "MICVDD",
208 .supply_name = "CPVDD1",
209 .type = REGULATOR_VOLTAGE,
210 .n_voltages = 40,
211 .ops = &arizona_micsupp_ops,
212
213 .vsel_reg = MADERA_LDO2_CONTROL_1,
214 .vsel_mask = MADERA_LDO2_VSEL_MASK,
215 .enable_reg = MADERA_MIC_CHARGE_PUMP_1,
216 .enable_mask = MADERA_CPMIC_ENA,
217 .bypass_reg = MADERA_MIC_CHARGE_PUMP_1,
218 .bypass_mask = MADERA_CPMIC_BYPASS,
219
220 .linear_ranges = arizona_micsupp_ext_ranges,
221 .n_linear_ranges = ARRAY_SIZE(arizona_micsupp_ext_ranges),
222
223 .enable_time = 3000,
224
225 .owner = THIS_MODULE,
226};
227
203static int arizona_micsupp_of_get_pdata(struct arizona_micsupp_pdata *pdata, 228static int arizona_micsupp_of_get_pdata(struct arizona_micsupp_pdata *pdata,
204 struct regulator_config *config, 229 struct regulator_config *config,
205 const struct regulator_desc *desc) 230 const struct regulator_desc *desc)
@@ -316,6 +341,24 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
316 &arizona->pdata.micvdd); 341 &arizona->pdata.micvdd);
317} 342}
318 343
344static int madera_micsupp_probe(struct platform_device *pdev)
345{
346 struct madera *madera = dev_get_drvdata(pdev->dev.parent);
347 struct arizona_micsupp *micsupp;
348
349 micsupp = devm_kzalloc(&pdev->dev, sizeof(*micsupp), GFP_KERNEL);
350 if (!micsupp)
351 return -ENOMEM;
352
353 micsupp->regmap = madera->regmap;
354 micsupp->dapm = &madera->dapm;
355 micsupp->dev = madera->dev;
356 micsupp->init_data = arizona_micsupp_ext_default;
357
358 return arizona_micsupp_common_init(pdev, micsupp, &madera_micsupp,
359 &madera->pdata.micvdd);
360}
361
319static struct platform_driver arizona_micsupp_driver = { 362static struct platform_driver arizona_micsupp_driver = {
320 .probe = arizona_micsupp_probe, 363 .probe = arizona_micsupp_probe,
321 .driver = { 364 .driver = {
@@ -323,10 +366,35 @@ static struct platform_driver arizona_micsupp_driver = {
323 }, 366 },
324}; 367};
325 368
326module_platform_driver(arizona_micsupp_driver); 369static struct platform_driver madera_micsupp_driver = {
370 .probe = madera_micsupp_probe,
371 .driver = {
372 .name = "madera-micsupp",
373 },
374};
375
376static struct platform_driver * const arizona_micsupp_drivers[] = {
377 &arizona_micsupp_driver,
378 &madera_micsupp_driver,
379};
380
381static int __init arizona_micsupp_init(void)
382{
383 return platform_register_drivers(arizona_micsupp_drivers,
384 ARRAY_SIZE(arizona_micsupp_drivers));
385}
386module_init(arizona_micsupp_init);
387
388static void __exit arizona_micsupp_exit(void)
389{
390 platform_unregister_drivers(arizona_micsupp_drivers,
391 ARRAY_SIZE(arizona_micsupp_drivers));
392}
393module_exit(arizona_micsupp_exit);
327 394
328/* Module information */ 395/* Module information */
329MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 396MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
330MODULE_DESCRIPTION("Arizona microphone supply driver"); 397MODULE_DESCRIPTION("Arizona microphone supply driver");
331MODULE_LICENSE("GPL"); 398MODULE_LICENSE("GPL");
332MODULE_ALIAS("platform:arizona-micsupp"); 399MODULE_ALIAS("platform:arizona-micsupp");
400MODULE_ALIAS("platform:madera-micsupp");
diff --git a/drivers/regulator/bd70528-regulator.c b/drivers/regulator/bd70528-regulator.c
index 30e3ed430a8a..0248a61f1006 100644
--- a/drivers/regulator/bd70528-regulator.c
+++ b/drivers/regulator/bd70528-regulator.c
@@ -4,7 +4,6 @@
4 4
5#include <linux/delay.h> 5#include <linux/delay.h>
6#include <linux/err.h> 6#include <linux/err.h>
7#include <linux/gpio.h>
8#include <linux/interrupt.h> 7#include <linux/interrupt.h>
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10#include <linux/mfd/rohm-bd70528.h> 9#include <linux/mfd/rohm-bd70528.h>
diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index fde4264da6ff..8c22cfb76173 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -4,7 +4,6 @@
4 4
5#include <linux/delay.h> 5#include <linux/delay.h>
6#include <linux/err.h> 6#include <linux/err.h>
7#include <linux/gpio.h>
8#include <linux/interrupt.h> 7#include <linux/interrupt.h>
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10#include <linux/mfd/rohm-bd718x7.h> 9#include <linux/mfd/rohm-bd718x7.h>
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c894cf0d8a28..86ae1825cec1 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1,12 +1,11 @@
1// SPDX-License-Identifier: GPL-2.0-or-later 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2//
3 * core.c -- Voltage/Current Regulator framework. 3// core.c -- Voltage/Current Regulator framework.
4 * 4//
5 * Copyright 2007, 2008 Wolfson Microelectronics PLC. 5// Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Copyright 2008 SlimLogic Ltd. 6// Copyright 2008 SlimLogic Ltd.
7 * 7//
8 * Author: Liam Girdwood <lrg@slimlogic.co.uk> 8// Author: Liam Girdwood <lrg@slimlogic.co.uk>
9 */
10 9
11#include <linux/kernel.h> 10#include <linux/kernel.h>
12#include <linux/init.h> 11#include <linux/init.h>
@@ -23,6 +22,7 @@
23#include <linux/regmap.h> 22#include <linux/regmap.h>
24#include <linux/regulator/of_regulator.h> 23#include <linux/regulator/of_regulator.h>
25#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
25#include <linux/regulator/coupler.h>
26#include <linux/regulator/driver.h> 26#include <linux/regulator/driver.h>
27#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
28#include <linux/module.h> 28#include <linux/module.h>
@@ -50,6 +50,7 @@ static DEFINE_MUTEX(regulator_list_mutex);
50static LIST_HEAD(regulator_map_list); 50static LIST_HEAD(regulator_map_list);
51static LIST_HEAD(regulator_ena_gpio_list); 51static LIST_HEAD(regulator_ena_gpio_list);
52static LIST_HEAD(regulator_supply_alias_list); 52static LIST_HEAD(regulator_supply_alias_list);
53static LIST_HEAD(regulator_coupler_list);
53static bool has_full_constraints; 54static bool has_full_constraints;
54 55
55static struct dentry *debugfs_root; 56static struct dentry *debugfs_root;
@@ -93,7 +94,6 @@ struct regulator_supply_alias {
93 94
94static int _regulator_is_enabled(struct regulator_dev *rdev); 95static int _regulator_is_enabled(struct regulator_dev *rdev);
95static int _regulator_disable(struct regulator *regulator); 96static int _regulator_disable(struct regulator *regulator);
96static int _regulator_get_voltage(struct regulator_dev *rdev);
97static int _regulator_get_current_limit(struct regulator_dev *rdev); 97static int _regulator_get_current_limit(struct regulator_dev *rdev);
98static unsigned int _regulator_get_mode(struct regulator_dev *rdev); 98static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
99static int _notifier_call_chain(struct regulator_dev *rdev, 99static int _notifier_call_chain(struct regulator_dev *rdev,
@@ -102,15 +102,12 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
102 int min_uV, int max_uV); 102 int min_uV, int max_uV);
103static int regulator_balance_voltage(struct regulator_dev *rdev, 103static int regulator_balance_voltage(struct regulator_dev *rdev,
104 suspend_state_t state); 104 suspend_state_t state);
105static int regulator_set_voltage_rdev(struct regulator_dev *rdev,
106 int min_uV, int max_uV,
107 suspend_state_t state);
108static struct regulator *create_regulator(struct regulator_dev *rdev, 105static struct regulator *create_regulator(struct regulator_dev *rdev,
109 struct device *dev, 106 struct device *dev,
110 const char *supply_name); 107 const char *supply_name);
111static void _regulator_put(struct regulator *regulator); 108static void _regulator_put(struct regulator *regulator);
112 109
113static const char *rdev_get_name(struct regulator_dev *rdev) 110const char *rdev_get_name(struct regulator_dev *rdev)
114{ 111{
115 if (rdev->constraints && rdev->constraints->name) 112 if (rdev->constraints && rdev->constraints->name)
116 return rdev->constraints->name; 113 return rdev->constraints->name;
@@ -424,8 +421,8 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp
424} 421}
425 422
426/* Platform voltage constraint check */ 423/* Platform voltage constraint check */
427static int regulator_check_voltage(struct regulator_dev *rdev, 424int regulator_check_voltage(struct regulator_dev *rdev,
428 int *min_uV, int *max_uV) 425 int *min_uV, int *max_uV)
429{ 426{
430 BUG_ON(*min_uV > *max_uV); 427 BUG_ON(*min_uV > *max_uV);
431 428
@@ -457,9 +454,9 @@ static int regulator_check_states(suspend_state_t state)
457/* Make sure we select a voltage that suits the needs of all 454/* Make sure we select a voltage that suits the needs of all
458 * regulator consumers 455 * regulator consumers
459 */ 456 */
460static int regulator_check_consumers(struct regulator_dev *rdev, 457int regulator_check_consumers(struct regulator_dev *rdev,
461 int *min_uV, int *max_uV, 458 int *min_uV, int *max_uV,
462 suspend_state_t state) 459 suspend_state_t state)
463{ 460{
464 struct regulator *regulator; 461 struct regulator *regulator;
465 struct regulator_voltage *voltage; 462 struct regulator_voltage *voltage;
@@ -570,7 +567,7 @@ static ssize_t regulator_uV_show(struct device *dev,
570 ssize_t ret; 567 ssize_t ret;
571 568
572 regulator_lock(rdev); 569 regulator_lock(rdev);
573 ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); 570 ret = sprintf(buf, "%d\n", regulator_get_voltage_rdev(rdev));
574 regulator_unlock(rdev); 571 regulator_unlock(rdev);
575 572
576 return ret; 573 return ret;
@@ -941,7 +938,7 @@ static int drms_uA_update(struct regulator_dev *rdev)
941 rdev_err(rdev, "failed to set load %d\n", current_uA); 938 rdev_err(rdev, "failed to set load %d\n", current_uA);
942 } else { 939 } else {
943 /* get output voltage */ 940 /* get output voltage */
944 output_uV = _regulator_get_voltage(rdev); 941 output_uV = regulator_get_voltage_rdev(rdev);
945 if (output_uV <= 0) { 942 if (output_uV <= 0) {
946 rdev_err(rdev, "invalid output voltage found\n"); 943 rdev_err(rdev, "invalid output voltage found\n");
947 return -EINVAL; 944 return -EINVAL;
@@ -1054,7 +1051,7 @@ static void print_constraints(struct regulator_dev *rdev)
1054 1051
1055 if (!constraints->min_uV || 1052 if (!constraints->min_uV ||
1056 constraints->min_uV != constraints->max_uV) { 1053 constraints->min_uV != constraints->max_uV) {
1057 ret = _regulator_get_voltage(rdev); 1054 ret = regulator_get_voltage_rdev(rdev);
1058 if (ret > 0) 1055 if (ret > 0)
1059 count += scnprintf(buf + count, len - count, 1056 count += scnprintf(buf + count, len - count,
1060 "at %d mV ", ret / 1000); 1057 "at %d mV ", ret / 1000);
@@ -1113,7 +1110,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
1113 if (rdev->constraints->apply_uV && 1110 if (rdev->constraints->apply_uV &&
1114 rdev->constraints->min_uV && rdev->constraints->max_uV) { 1111 rdev->constraints->min_uV && rdev->constraints->max_uV) {
1115 int target_min, target_max; 1112 int target_min, target_max;
1116 int current_uV = _regulator_get_voltage(rdev); 1113 int current_uV = regulator_get_voltage_rdev(rdev);
1117 1114
1118 if (current_uV == -ENOTRECOVERABLE) { 1115 if (current_uV == -ENOTRECOVERABLE) {
1119 /* This regulator can't be read and must be initialized */ 1116 /* This regulator can't be read and must be initialized */
@@ -1123,7 +1120,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
1123 _regulator_do_set_voltage(rdev, 1120 _regulator_do_set_voltage(rdev,
1124 rdev->constraints->min_uV, 1121 rdev->constraints->min_uV,
1125 rdev->constraints->max_uV); 1122 rdev->constraints->max_uV);
1126 current_uV = _regulator_get_voltage(rdev); 1123 current_uV = regulator_get_voltage_rdev(rdev);
1127 } 1124 }
1128 1125
1129 if (current_uV < 0) { 1126 if (current_uV < 0) {
@@ -1645,9 +1642,9 @@ static int _regulator_get_enable_time(struct regulator_dev *rdev)
1645{ 1642{
1646 if (rdev->constraints && rdev->constraints->enable_time) 1643 if (rdev->constraints && rdev->constraints->enable_time)
1647 return rdev->constraints->enable_time; 1644 return rdev->constraints->enable_time;
1648 if (!rdev->desc->ops->enable_time) 1645 if (rdev->desc->ops->enable_time)
1649 return rdev->desc->enable_time; 1646 return rdev->desc->ops->enable_time(rdev);
1650 return rdev->desc->ops->enable_time(rdev); 1647 return rdev->desc->enable_time;
1651} 1648}
1652 1649
1653static struct regulator_supply_alias *regulator_find_supply_alias( 1650static struct regulator_supply_alias *regulator_find_supply_alias(
@@ -3065,7 +3062,7 @@ static int _regulator_call_set_voltage(struct regulator_dev *rdev,
3065 struct pre_voltage_change_data data; 3062 struct pre_voltage_change_data data;
3066 int ret; 3063 int ret;
3067 3064
3068 data.old_uV = _regulator_get_voltage(rdev); 3065 data.old_uV = regulator_get_voltage_rdev(rdev);
3069 data.min_uV = min_uV; 3066 data.min_uV = min_uV;
3070 data.max_uV = max_uV; 3067 data.max_uV = max_uV;
3071 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, 3068 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
@@ -3089,7 +3086,7 @@ static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,
3089 struct pre_voltage_change_data data; 3086 struct pre_voltage_change_data data;
3090 int ret; 3087 int ret;
3091 3088
3092 data.old_uV = _regulator_get_voltage(rdev); 3089 data.old_uV = regulator_get_voltage_rdev(rdev);
3093 data.min_uV = uV; 3090 data.min_uV = uV;
3094 data.max_uV = uV; 3091 data.max_uV = uV;
3095 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE, 3092 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_PRE_VOLTAGE_CHANGE,
@@ -3107,6 +3104,66 @@ static int _regulator_call_set_voltage_sel(struct regulator_dev *rdev,
3107 return ret; 3104 return ret;
3108} 3105}
3109 3106
3107static int _regulator_set_voltage_sel_step(struct regulator_dev *rdev,
3108 int uV, int new_selector)
3109{
3110 const struct regulator_ops *ops = rdev->desc->ops;
3111 int diff, old_sel, curr_sel, ret;
3112
3113 /* Stepping is only needed if the regulator is enabled. */
3114 if (!_regulator_is_enabled(rdev))
3115 goto final_set;
3116
3117 if (!ops->get_voltage_sel)
3118 return -EINVAL;
3119
3120 old_sel = ops->get_voltage_sel(rdev);
3121 if (old_sel < 0)
3122 return old_sel;
3123
3124 diff = new_selector - old_sel;
3125 if (diff == 0)
3126 return 0; /* No change needed. */
3127
3128 if (diff > 0) {
3129 /* Stepping up. */
3130 for (curr_sel = old_sel + rdev->desc->vsel_step;
3131 curr_sel < new_selector;
3132 curr_sel += rdev->desc->vsel_step) {
3133 /*
3134 * Call the callback directly instead of using
3135 * _regulator_call_set_voltage_sel() as we don't
3136 * want to notify anyone yet. Same in the branch
3137 * below.
3138 */
3139 ret = ops->set_voltage_sel(rdev, curr_sel);
3140 if (ret)
3141 goto try_revert;
3142 }
3143 } else {
3144 /* Stepping down. */
3145 for (curr_sel = old_sel - rdev->desc->vsel_step;
3146 curr_sel > new_selector;
3147 curr_sel -= rdev->desc->vsel_step) {
3148 ret = ops->set_voltage_sel(rdev, curr_sel);
3149 if (ret)
3150 goto try_revert;
3151 }
3152 }
3153
3154final_set:
3155 /* The final selector will trigger the notifiers. */
3156 return _regulator_call_set_voltage_sel(rdev, uV, new_selector);
3157
3158try_revert:
3159 /*
3160 * At least try to return to the previous voltage if setting a new
3161 * one failed.
3162 */
3163 (void)ops->set_voltage_sel(rdev, old_sel);
3164 return ret;
3165}
3166
3110static int _regulator_set_voltage_time(struct regulator_dev *rdev, 3167static int _regulator_set_voltage_time(struct regulator_dev *rdev,
3111 int old_uV, int new_uV) 3168 int old_uV, int new_uV)
3112{ 3169{
@@ -3142,7 +3199,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
3142 unsigned int selector; 3199 unsigned int selector;
3143 int old_selector = -1; 3200 int old_selector = -1;
3144 const struct regulator_ops *ops = rdev->desc->ops; 3201 const struct regulator_ops *ops = rdev->desc->ops;
3145 int old_uV = _regulator_get_voltage(rdev); 3202 int old_uV = regulator_get_voltage_rdev(rdev);
3146 3203
3147 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); 3204 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
3148 3205
@@ -3169,7 +3226,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
3169 best_val = ops->list_voltage(rdev, 3226 best_val = ops->list_voltage(rdev,
3170 selector); 3227 selector);
3171 else 3228 else
3172 best_val = _regulator_get_voltage(rdev); 3229 best_val = regulator_get_voltage_rdev(rdev);
3173 } 3230 }
3174 3231
3175 } else if (ops->set_voltage_sel) { 3232 } else if (ops->set_voltage_sel) {
@@ -3180,6 +3237,9 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
3180 selector = ret; 3237 selector = ret;
3181 if (old_selector == selector) 3238 if (old_selector == selector)
3182 ret = 0; 3239 ret = 0;
3240 else if (rdev->desc->vsel_step)
3241 ret = _regulator_set_voltage_sel_step(
3242 rdev, best_val, selector);
3183 else 3243 else
3184 ret = _regulator_call_set_voltage_sel( 3244 ret = _regulator_call_set_voltage_sel(
3185 rdev, best_val, selector); 3245 rdev, best_val, selector);
@@ -3288,7 +3348,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator,
3288 * changing the voltage. 3348 * changing the voltage.
3289 */ 3349 */
3290 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) { 3350 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
3291 current_uV = _regulator_get_voltage(rdev); 3351 current_uV = regulator_get_voltage_rdev(rdev);
3292 if (min_uV <= current_uV && current_uV <= max_uV) { 3352 if (min_uV <= current_uV && current_uV <= max_uV) {
3293 voltage->min_uV = min_uV; 3353 voltage->min_uV = min_uV;
3294 voltage->max_uV = max_uV; 3354 voltage->max_uV = max_uV;
@@ -3325,8 +3385,8 @@ out:
3325 return ret; 3385 return ret;
3326} 3386}
3327 3387
3328static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, 3388int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV,
3329 int max_uV, suspend_state_t state) 3389 int max_uV, suspend_state_t state)
3330{ 3390{
3331 int best_supply_uV = 0; 3391 int best_supply_uV = 0;
3332 int supply_change_uV = 0; 3392 int supply_change_uV = 0;
@@ -3354,7 +3414,7 @@ static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV,
3354 3414
3355 best_supply_uV += rdev->desc->min_dropout_uV; 3415 best_supply_uV += rdev->desc->min_dropout_uV;
3356 3416
3357 current_supply_uV = _regulator_get_voltage(rdev->supply->rdev); 3417 current_supply_uV = regulator_get_voltage_rdev(rdev->supply->rdev);
3358 if (current_supply_uV < 0) { 3418 if (current_supply_uV < 0) {
3359 ret = current_supply_uV; 3419 ret = current_supply_uV;
3360 goto out; 3420 goto out;
@@ -3405,7 +3465,7 @@ static int regulator_limit_voltage_step(struct regulator_dev *rdev,
3405 return 1; 3465 return 1;
3406 3466
3407 if (*current_uV < 0) { 3467 if (*current_uV < 0) {
3408 *current_uV = _regulator_get_voltage(rdev); 3468 *current_uV = regulator_get_voltage_rdev(rdev);
3409 3469
3410 if (*current_uV < 0) 3470 if (*current_uV < 0)
3411 return *current_uV; 3471 return *current_uV;
@@ -3434,11 +3494,10 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev,
3434 struct coupling_desc *c_desc = &rdev->coupling_desc; 3494 struct coupling_desc *c_desc = &rdev->coupling_desc;
3435 struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; 3495 struct regulator_dev **c_rdevs = c_desc->coupled_rdevs;
3436 struct regulation_constraints *constraints = rdev->constraints; 3496 struct regulation_constraints *constraints = rdev->constraints;
3437 int max_spread = constraints->max_spread;
3438 int desired_min_uV = 0, desired_max_uV = INT_MAX; 3497 int desired_min_uV = 0, desired_max_uV = INT_MAX;
3439 int max_current_uV = 0, min_current_uV = INT_MAX; 3498 int max_current_uV = 0, min_current_uV = INT_MAX;
3440 int highest_min_uV = 0, target_uV, possible_uV; 3499 int highest_min_uV = 0, target_uV, possible_uV;
3441 int i, ret; 3500 int i, ret, max_spread;
3442 bool done; 3501 bool done;
3443 3502
3444 *current_uV = -1; 3503 *current_uV = -1;
@@ -3492,6 +3551,8 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev,
3492 } 3551 }
3493 } 3552 }
3494 3553
3554 max_spread = constraints->max_spread[0];
3555
3495 /* 3556 /*
3496 * Let target_uV be equal to the desired one if possible. 3557 * Let target_uV be equal to the desired one if possible.
3497 * If not, set it to minimum voltage, allowed by other coupled 3558 * If not, set it to minimum voltage, allowed by other coupled
@@ -3509,7 +3570,7 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev,
3509 if (!_regulator_is_enabled(c_rdevs[i])) 3570 if (!_regulator_is_enabled(c_rdevs[i]))
3510 continue; 3571 continue;
3511 3572
3512 tmp_act = _regulator_get_voltage(c_rdevs[i]); 3573 tmp_act = regulator_get_voltage_rdev(c_rdevs[i]);
3513 if (tmp_act < 0) 3574 if (tmp_act < 0)
3514 return tmp_act; 3575 return tmp_act;
3515 3576
@@ -3551,7 +3612,7 @@ finish:
3551 if (n_coupled > 1 && *current_uV == -1) { 3612 if (n_coupled > 1 && *current_uV == -1) {
3552 3613
3553 if (_regulator_is_enabled(rdev)) { 3614 if (_regulator_is_enabled(rdev)) {
3554 ret = _regulator_get_voltage(rdev); 3615 ret = regulator_get_voltage_rdev(rdev);
3555 if (ret < 0) 3616 if (ret < 0)
3556 return ret; 3617 return ret;
3557 3618
@@ -3573,9 +3634,11 @@ static int regulator_balance_voltage(struct regulator_dev *rdev,
3573 struct regulator_dev **c_rdevs; 3634 struct regulator_dev **c_rdevs;
3574 struct regulator_dev *best_rdev; 3635 struct regulator_dev *best_rdev;
3575 struct coupling_desc *c_desc = &rdev->coupling_desc; 3636 struct coupling_desc *c_desc = &rdev->coupling_desc;
3637 struct regulator_coupler *coupler = c_desc->coupler;
3576 int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev; 3638 int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev;
3577 bool best_c_rdev_done, c_rdev_done[MAX_COUPLED];
3578 unsigned int delta, best_delta; 3639 unsigned int delta, best_delta;
3640 unsigned long c_rdev_done = 0;
3641 bool best_c_rdev_done;
3579 3642
3580 c_rdevs = c_desc->coupled_rdevs; 3643 c_rdevs = c_desc->coupled_rdevs;
3581 n_coupled = c_desc->n_coupled; 3644 n_coupled = c_desc->n_coupled;
@@ -3592,8 +3655,9 @@ static int regulator_balance_voltage(struct regulator_dev *rdev,
3592 return -EPERM; 3655 return -EPERM;
3593 } 3656 }
3594 3657
3595 for (i = 0; i < n_coupled; i++) 3658 /* Invoke custom balancer for customized couplers */
3596 c_rdev_done[i] = false; 3659 if (coupler && coupler->balance_voltage)
3660 return coupler->balance_voltage(coupler, rdev, state);
3597 3661
3598 /* 3662 /*
3599 * Find the best possible voltage change on each loop. Leave the loop 3663 * Find the best possible voltage change on each loop. Leave the loop
@@ -3620,7 +3684,7 @@ static int regulator_balance_voltage(struct regulator_dev *rdev,
3620 */ 3684 */
3621 int optimal_uV = 0, optimal_max_uV = 0, current_uV = 0; 3685 int optimal_uV = 0, optimal_max_uV = 0, current_uV = 0;
3622 3686
3623 if (c_rdev_done[i]) 3687 if (test_bit(i, &c_rdev_done))
3624 continue; 3688 continue;
3625 3689
3626 ret = regulator_get_optimal_voltage(c_rdevs[i], 3690 ret = regulator_get_optimal_voltage(c_rdevs[i],
@@ -3655,7 +3719,8 @@ static int regulator_balance_voltage(struct regulator_dev *rdev,
3655 if (ret < 0) 3719 if (ret < 0)
3656 goto out; 3720 goto out;
3657 3721
3658 c_rdev_done[best_c_rdev] = best_c_rdev_done; 3722 if (best_c_rdev_done)
3723 set_bit(best_c_rdev, &c_rdev_done);
3659 3724
3660 } while (n_coupled > 1); 3725 } while (n_coupled > 1);
3661 3726
@@ -3911,7 +3976,7 @@ out:
3911} 3976}
3912EXPORT_SYMBOL_GPL(regulator_sync_voltage); 3977EXPORT_SYMBOL_GPL(regulator_sync_voltage);
3913 3978
3914static int _regulator_get_voltage(struct regulator_dev *rdev) 3979int regulator_get_voltage_rdev(struct regulator_dev *rdev)
3915{ 3980{
3916 int sel, ret; 3981 int sel, ret;
3917 bool bypassed; 3982 bool bypassed;
@@ -3928,7 +3993,7 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
3928 return -EPROBE_DEFER; 3993 return -EPROBE_DEFER;
3929 } 3994 }
3930 3995
3931 return _regulator_get_voltage(rdev->supply->rdev); 3996 return regulator_get_voltage_rdev(rdev->supply->rdev);
3932 } 3997 }
3933 } 3998 }
3934 3999
@@ -3944,7 +4009,7 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
3944 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) { 4009 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) {
3945 ret = rdev->desc->fixed_uV; 4010 ret = rdev->desc->fixed_uV;
3946 } else if (rdev->supply) { 4011 } else if (rdev->supply) {
3947 ret = _regulator_get_voltage(rdev->supply->rdev); 4012 ret = regulator_get_voltage_rdev(rdev->supply->rdev);
3948 } else { 4013 } else {
3949 return -EINVAL; 4014 return -EINVAL;
3950 } 4015 }
@@ -3969,7 +4034,7 @@ int regulator_get_voltage(struct regulator *regulator)
3969 int ret; 4034 int ret;
3970 4035
3971 regulator_lock_dependent(regulator->rdev, &ww_ctx); 4036 regulator_lock_dependent(regulator->rdev, &ww_ctx);
3972 ret = _regulator_get_voltage(regulator->rdev); 4037 ret = regulator_get_voltage_rdev(regulator->rdev);
3973 regulator_unlock_dependent(regulator->rdev, &ww_ctx); 4038 regulator_unlock_dependent(regulator->rdev, &ww_ctx);
3974 4039
3975 return ret; 4040 return ret;
@@ -4707,8 +4772,60 @@ static int regulator_register_resolve_supply(struct device *dev, void *data)
4707 return 0; 4772 return 0;
4708} 4773}
4709 4774
4775int regulator_coupler_register(struct regulator_coupler *coupler)
4776{
4777 mutex_lock(&regulator_list_mutex);
4778 list_add_tail(&coupler->list, &regulator_coupler_list);
4779 mutex_unlock(&regulator_list_mutex);
4780
4781 return 0;
4782}
4783
4784static struct regulator_coupler *
4785regulator_find_coupler(struct regulator_dev *rdev)
4786{
4787 struct regulator_coupler *coupler;
4788 int err;
4789
4790 /*
4791 * Note that regulators are appended to the list and the generic
4792 * coupler is registered first, hence it will be attached at last
4793 * if nobody cared.
4794 */
4795 list_for_each_entry_reverse(coupler, &regulator_coupler_list, list) {
4796 err = coupler->attach_regulator(coupler, rdev);
4797 if (!err) {
4798 if (!coupler->balance_voltage &&
4799 rdev->coupling_desc.n_coupled > 2)
4800 goto err_unsupported;
4801
4802 return coupler;
4803 }
4804
4805 if (err < 0)
4806 return ERR_PTR(err);
4807
4808 if (err == 1)
4809 continue;
4810
4811 break;
4812 }
4813
4814 return ERR_PTR(-EINVAL);
4815
4816err_unsupported:
4817 if (coupler->detach_regulator)
4818 coupler->detach_regulator(coupler, rdev);
4819
4820 rdev_err(rdev,
4821 "Voltage balancing for multiple regulator couples is unimplemented\n");
4822
4823 return ERR_PTR(-EPERM);
4824}
4825
4710static void regulator_resolve_coupling(struct regulator_dev *rdev) 4826static void regulator_resolve_coupling(struct regulator_dev *rdev)
4711{ 4827{
4828 struct regulator_coupler *coupler = rdev->coupling_desc.coupler;
4712 struct coupling_desc *c_desc = &rdev->coupling_desc; 4829 struct coupling_desc *c_desc = &rdev->coupling_desc;
4713 int n_coupled = c_desc->n_coupled; 4830 int n_coupled = c_desc->n_coupled;
4714 struct regulator_dev *c_rdev; 4831 struct regulator_dev *c_rdev;
@@ -4724,6 +4841,12 @@ static void regulator_resolve_coupling(struct regulator_dev *rdev)
4724 if (!c_rdev) 4841 if (!c_rdev)
4725 continue; 4842 continue;
4726 4843
4844 if (c_rdev->coupling_desc.coupler != coupler) {
4845 rdev_err(rdev, "coupler mismatch with %s\n",
4846 rdev_get_name(c_rdev));
4847 return;
4848 }
4849
4727 regulator_lock(c_rdev); 4850 regulator_lock(c_rdev);
4728 4851
4729 c_desc->coupled_rdevs[i] = c_rdev; 4852 c_desc->coupled_rdevs[i] = c_rdev;
@@ -4737,10 +4860,12 @@ static void regulator_resolve_coupling(struct regulator_dev *rdev)
4737 4860
4738static void regulator_remove_coupling(struct regulator_dev *rdev) 4861static void regulator_remove_coupling(struct regulator_dev *rdev)
4739{ 4862{
4863 struct regulator_coupler *coupler = rdev->coupling_desc.coupler;
4740 struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc; 4864 struct coupling_desc *__c_desc, *c_desc = &rdev->coupling_desc;
4741 struct regulator_dev *__c_rdev, *c_rdev; 4865 struct regulator_dev *__c_rdev, *c_rdev;
4742 unsigned int __n_coupled, n_coupled; 4866 unsigned int __n_coupled, n_coupled;
4743 int i, k; 4867 int i, k;
4868 int err;
4744 4869
4745 n_coupled = c_desc->n_coupled; 4870 n_coupled = c_desc->n_coupled;
4746 4871
@@ -4770,21 +4895,33 @@ static void regulator_remove_coupling(struct regulator_dev *rdev)
4770 c_desc->coupled_rdevs[i] = NULL; 4895 c_desc->coupled_rdevs[i] = NULL;
4771 c_desc->n_resolved--; 4896 c_desc->n_resolved--;
4772 } 4897 }
4898
4899 if (coupler && coupler->detach_regulator) {
4900 err = coupler->detach_regulator(coupler, rdev);
4901 if (err)
4902 rdev_err(rdev, "failed to detach from coupler: %d\n",
4903 err);
4904 }
4905
4906 kfree(rdev->coupling_desc.coupled_rdevs);
4907 rdev->coupling_desc.coupled_rdevs = NULL;
4773} 4908}
4774 4909
4775static int regulator_init_coupling(struct regulator_dev *rdev) 4910static int regulator_init_coupling(struct regulator_dev *rdev)
4776{ 4911{
4777 int n_phandles; 4912 int err, n_phandles;
4913 size_t alloc_size;
4778 4914
4779 if (!IS_ENABLED(CONFIG_OF)) 4915 if (!IS_ENABLED(CONFIG_OF))
4780 n_phandles = 0; 4916 n_phandles = 0;
4781 else 4917 else
4782 n_phandles = of_get_n_coupled(rdev); 4918 n_phandles = of_get_n_coupled(rdev);
4783 4919
4784 if (n_phandles + 1 > MAX_COUPLED) { 4920 alloc_size = sizeof(*rdev) * (n_phandles + 1);
4785 rdev_err(rdev, "too many regulators coupled\n"); 4921
4786 return -EPERM; 4922 rdev->coupling_desc.coupled_rdevs = kzalloc(alloc_size, GFP_KERNEL);
4787 } 4923 if (!rdev->coupling_desc.coupled_rdevs)
4924 return -ENOMEM;
4788 4925
4789 /* 4926 /*
4790 * Every regulator should always have coupling descriptor filled with 4927 * Every regulator should always have coupling descriptor filled with
@@ -4798,23 +4935,35 @@ static int regulator_init_coupling(struct regulator_dev *rdev)
4798 if (n_phandles == 0) 4935 if (n_phandles == 0)
4799 return 0; 4936 return 0;
4800 4937
4801 /* regulator, which can't change its voltage, can't be coupled */ 4938 if (!of_check_coupling_data(rdev))
4802 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_VOLTAGE)) {
4803 rdev_err(rdev, "voltage operation not allowed\n");
4804 return -EPERM; 4939 return -EPERM;
4805 }
4806 4940
4807 if (rdev->constraints->max_spread <= 0) { 4941 rdev->coupling_desc.coupler = regulator_find_coupler(rdev);
4808 rdev_err(rdev, "wrong max_spread value\n"); 4942 if (IS_ERR(rdev->coupling_desc.coupler)) {
4809 return -EPERM; 4943 err = PTR_ERR(rdev->coupling_desc.coupler);
4944 rdev_err(rdev, "failed to get coupler: %d\n", err);
4945 return err;
4810 } 4946 }
4811 4947
4812 if (!of_check_coupling_data(rdev)) 4948 return 0;
4949}
4950
4951static int generic_coupler_attach(struct regulator_coupler *coupler,
4952 struct regulator_dev *rdev)
4953{
4954 if (rdev->coupling_desc.n_coupled > 2) {
4955 rdev_err(rdev,
4956 "Voltage balancing for multiple regulator couples is unimplemented\n");
4813 return -EPERM; 4957 return -EPERM;
4958 }
4814 4959
4815 return 0; 4960 return 0;
4816} 4961}
4817 4962
4963static struct regulator_coupler generic_regulator_coupler = {
4964 .attach_regulator = generic_coupler_attach,
4965};
4966
4818/** 4967/**
4819 * regulator_register - register regulator 4968 * regulator_register - register regulator
4820 * @regulator_desc: regulator to register 4969 * @regulator_desc: regulator to register
@@ -4976,7 +5125,9 @@ regulator_register(const struct regulator_desc *regulator_desc,
4976 if (ret < 0) 5125 if (ret < 0)
4977 goto wash; 5126 goto wash;
4978 5127
5128 mutex_lock(&regulator_list_mutex);
4979 ret = regulator_init_coupling(rdev); 5129 ret = regulator_init_coupling(rdev);
5130 mutex_unlock(&regulator_list_mutex);
4980 if (ret < 0) 5131 if (ret < 0)
4981 goto wash; 5132 goto wash;
4982 5133
@@ -5025,6 +5176,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
5025unset_supplies: 5176unset_supplies:
5026 mutex_lock(&regulator_list_mutex); 5177 mutex_lock(&regulator_list_mutex);
5027 unset_regulator_supplies(rdev); 5178 unset_regulator_supplies(rdev);
5179 regulator_remove_coupling(rdev);
5028 mutex_unlock(&regulator_list_mutex); 5180 mutex_unlock(&regulator_list_mutex);
5029wash: 5181wash:
5030 kfree(rdev->constraints); 5182 kfree(rdev->constraints);
@@ -5278,7 +5430,7 @@ static void regulator_summary_show_subtree(struct seq_file *s,
5278 rdev->use_count, rdev->open_count, rdev->bypass_count, 5430 rdev->use_count, rdev->open_count, rdev->bypass_count,
5279 regulator_opmode_to_str(opmode)); 5431 regulator_opmode_to_str(opmode));
5280 5432
5281 seq_printf(s, "%5dmV ", _regulator_get_voltage(rdev) / 1000); 5433 seq_printf(s, "%5dmV ", regulator_get_voltage_rdev(rdev) / 1000);
5282 seq_printf(s, "%5dmA ", 5434 seq_printf(s, "%5dmA ",
5283 _regulator_get_current_limit_unlocked(rdev) / 1000); 5435 _regulator_get_current_limit_unlocked(rdev) / 1000);
5284 5436
@@ -5480,6 +5632,8 @@ static int __init regulator_init(void)
5480#endif 5632#endif
5481 regulator_dummy_init(); 5633 regulator_dummy_init();
5482 5634
5635 regulator_coupler_register(&generic_regulator_coupler);
5636
5483 return ret; 5637 return ret;
5484} 5638}
5485 5639
diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c
index d3284361e594..f80781d58a28 100644
--- a/drivers/regulator/cpcap-regulator.c
+++ b/drivers/regulator/cpcap-regulator.c
@@ -90,7 +90,7 @@
90#define CPCAP_REG_OFF_MODE_SEC BIT(15) 90#define CPCAP_REG_OFF_MODE_SEC BIT(15)
91 91
92/** 92/**
93 * SoC specific configuraion for CPCAP regulator. There are at least three 93 * SoC specific configuration for CPCAP regulator. There are at least three
94 * different SoCs each with their own parameters: omap3, omap4 and tegra2. 94 * different SoCs each with their own parameters: omap3, omap4 and tegra2.
95 * 95 *
96 * The assign_reg and assign_mask seem to allow toggling between primary 96 * The assign_reg and assign_mask seem to allow toggling between primary
diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c
index a02e0488410f..2ffc64622451 100644
--- a/drivers/regulator/da9062-regulator.c
+++ b/drivers/regulator/da9062-regulator.c
@@ -493,12 +493,13 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
493 .desc.ops = &da9062_ldo_ops, 493 .desc.ops = &da9062_ldo_ops,
494 .desc.min_uV = (900) * 1000, 494 .desc.min_uV = (900) * 1000,
495 .desc.uV_step = (50) * 1000, 495 .desc.uV_step = (50) * 1000,
496 .desc.n_voltages = ((3600) - (900))/(50) + 1, 496 .desc.n_voltages = ((3600) - (900))/(50) + 1
497 + DA9062AA_VLDO_A_MIN_SEL,
497 .desc.enable_reg = DA9062AA_LDO1_CONT, 498 .desc.enable_reg = DA9062AA_LDO1_CONT,
498 .desc.enable_mask = DA9062AA_LDO1_EN_MASK, 499 .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
499 .desc.vsel_reg = DA9062AA_VLDO1_A, 500 .desc.vsel_reg = DA9062AA_VLDO1_A,
500 .desc.vsel_mask = DA9062AA_VLDO1_A_MASK, 501 .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
501 .desc.linear_min_sel = 0, 502 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
502 .sleep = REG_FIELD(DA9062AA_VLDO1_A, 503 .sleep = REG_FIELD(DA9062AA_VLDO1_A,
503 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1, 504 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
504 sizeof(unsigned int) * 8 - 505 sizeof(unsigned int) * 8 -
@@ -525,12 +526,13 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
525 .desc.ops = &da9062_ldo_ops, 526 .desc.ops = &da9062_ldo_ops,
526 .desc.min_uV = (900) * 1000, 527 .desc.min_uV = (900) * 1000,
527 .desc.uV_step = (50) * 1000, 528 .desc.uV_step = (50) * 1000,
528 .desc.n_voltages = ((3600) - (600))/(50) + 1, 529 .desc.n_voltages = ((3600) - (900))/(50) + 1
530 + DA9062AA_VLDO_A_MIN_SEL,
529 .desc.enable_reg = DA9062AA_LDO2_CONT, 531 .desc.enable_reg = DA9062AA_LDO2_CONT,
530 .desc.enable_mask = DA9062AA_LDO2_EN_MASK, 532 .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
531 .desc.vsel_reg = DA9062AA_VLDO2_A, 533 .desc.vsel_reg = DA9062AA_VLDO2_A,
532 .desc.vsel_mask = DA9062AA_VLDO2_A_MASK, 534 .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
533 .desc.linear_min_sel = 0, 535 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
534 .sleep = REG_FIELD(DA9062AA_VLDO2_A, 536 .sleep = REG_FIELD(DA9062AA_VLDO2_A,
535 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1, 537 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
536 sizeof(unsigned int) * 8 - 538 sizeof(unsigned int) * 8 -
@@ -557,12 +559,13 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
557 .desc.ops = &da9062_ldo_ops, 559 .desc.ops = &da9062_ldo_ops,
558 .desc.min_uV = (900) * 1000, 560 .desc.min_uV = (900) * 1000,
559 .desc.uV_step = (50) * 1000, 561 .desc.uV_step = (50) * 1000,
560 .desc.n_voltages = ((3600) - (900))/(50) + 1, 562 .desc.n_voltages = ((3600) - (900))/(50) + 1
563 + DA9062AA_VLDO_A_MIN_SEL,
561 .desc.enable_reg = DA9062AA_LDO3_CONT, 564 .desc.enable_reg = DA9062AA_LDO3_CONT,
562 .desc.enable_mask = DA9062AA_LDO3_EN_MASK, 565 .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
563 .desc.vsel_reg = DA9062AA_VLDO3_A, 566 .desc.vsel_reg = DA9062AA_VLDO3_A,
564 .desc.vsel_mask = DA9062AA_VLDO3_A_MASK, 567 .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
565 .desc.linear_min_sel = 0, 568 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
566 .sleep = REG_FIELD(DA9062AA_VLDO3_A, 569 .sleep = REG_FIELD(DA9062AA_VLDO3_A,
567 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1, 570 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
568 sizeof(unsigned int) * 8 - 571 sizeof(unsigned int) * 8 -
@@ -589,12 +592,13 @@ static const struct da9062_regulator_info local_da9061_regulator_info[] = {
589 .desc.ops = &da9062_ldo_ops, 592 .desc.ops = &da9062_ldo_ops,
590 .desc.min_uV = (900) * 1000, 593 .desc.min_uV = (900) * 1000,
591 .desc.uV_step = (50) * 1000, 594 .desc.uV_step = (50) * 1000,
592 .desc.n_voltages = ((3600) - (900))/(50) + 1, 595 .desc.n_voltages = ((3600) - (900))/(50) + 1
596 + DA9062AA_VLDO_A_MIN_SEL,
593 .desc.enable_reg = DA9062AA_LDO4_CONT, 597 .desc.enable_reg = DA9062AA_LDO4_CONT,
594 .desc.enable_mask = DA9062AA_LDO4_EN_MASK, 598 .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
595 .desc.vsel_reg = DA9062AA_VLDO4_A, 599 .desc.vsel_reg = DA9062AA_VLDO4_A,
596 .desc.vsel_mask = DA9062AA_VLDO4_A_MASK, 600 .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
597 .desc.linear_min_sel = 0, 601 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
598 .sleep = REG_FIELD(DA9062AA_VLDO4_A, 602 .sleep = REG_FIELD(DA9062AA_VLDO4_A,
599 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1, 603 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
600 sizeof(unsigned int) * 8 - 604 sizeof(unsigned int) * 8 -
@@ -769,12 +773,13 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
769 .desc.ops = &da9062_ldo_ops, 773 .desc.ops = &da9062_ldo_ops,
770 .desc.min_uV = (900) * 1000, 774 .desc.min_uV = (900) * 1000,
771 .desc.uV_step = (50) * 1000, 775 .desc.uV_step = (50) * 1000,
772 .desc.n_voltages = ((3600) - (900))/(50) + 1, 776 .desc.n_voltages = ((3600) - (900))/(50) + 1
777 + DA9062AA_VLDO_A_MIN_SEL,
773 .desc.enable_reg = DA9062AA_LDO1_CONT, 778 .desc.enable_reg = DA9062AA_LDO1_CONT,
774 .desc.enable_mask = DA9062AA_LDO1_EN_MASK, 779 .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
775 .desc.vsel_reg = DA9062AA_VLDO1_A, 780 .desc.vsel_reg = DA9062AA_VLDO1_A,
776 .desc.vsel_mask = DA9062AA_VLDO1_A_MASK, 781 .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
777 .desc.linear_min_sel = 0, 782 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
778 .sleep = REG_FIELD(DA9062AA_VLDO1_A, 783 .sleep = REG_FIELD(DA9062AA_VLDO1_A,
779 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1, 784 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
780 sizeof(unsigned int) * 8 - 785 sizeof(unsigned int) * 8 -
@@ -801,12 +806,13 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
801 .desc.ops = &da9062_ldo_ops, 806 .desc.ops = &da9062_ldo_ops,
802 .desc.min_uV = (900) * 1000, 807 .desc.min_uV = (900) * 1000,
803 .desc.uV_step = (50) * 1000, 808 .desc.uV_step = (50) * 1000,
804 .desc.n_voltages = ((3600) - (600))/(50) + 1, 809 .desc.n_voltages = ((3600) - (900))/(50) + 1
810 + DA9062AA_VLDO_A_MIN_SEL,
805 .desc.enable_reg = DA9062AA_LDO2_CONT, 811 .desc.enable_reg = DA9062AA_LDO2_CONT,
806 .desc.enable_mask = DA9062AA_LDO2_EN_MASK, 812 .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
807 .desc.vsel_reg = DA9062AA_VLDO2_A, 813 .desc.vsel_reg = DA9062AA_VLDO2_A,
808 .desc.vsel_mask = DA9062AA_VLDO2_A_MASK, 814 .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
809 .desc.linear_min_sel = 0, 815 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
810 .sleep = REG_FIELD(DA9062AA_VLDO2_A, 816 .sleep = REG_FIELD(DA9062AA_VLDO2_A,
811 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1, 817 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
812 sizeof(unsigned int) * 8 - 818 sizeof(unsigned int) * 8 -
@@ -833,12 +839,13 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
833 .desc.ops = &da9062_ldo_ops, 839 .desc.ops = &da9062_ldo_ops,
834 .desc.min_uV = (900) * 1000, 840 .desc.min_uV = (900) * 1000,
835 .desc.uV_step = (50) * 1000, 841 .desc.uV_step = (50) * 1000,
836 .desc.n_voltages = ((3600) - (900))/(50) + 1, 842 .desc.n_voltages = ((3600) - (900))/(50) + 1
843 + DA9062AA_VLDO_A_MIN_SEL,
837 .desc.enable_reg = DA9062AA_LDO3_CONT, 844 .desc.enable_reg = DA9062AA_LDO3_CONT,
838 .desc.enable_mask = DA9062AA_LDO3_EN_MASK, 845 .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
839 .desc.vsel_reg = DA9062AA_VLDO3_A, 846 .desc.vsel_reg = DA9062AA_VLDO3_A,
840 .desc.vsel_mask = DA9062AA_VLDO3_A_MASK, 847 .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
841 .desc.linear_min_sel = 0, 848 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
842 .sleep = REG_FIELD(DA9062AA_VLDO3_A, 849 .sleep = REG_FIELD(DA9062AA_VLDO3_A,
843 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1, 850 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
844 sizeof(unsigned int) * 8 - 851 sizeof(unsigned int) * 8 -
@@ -865,12 +872,13 @@ static const struct da9062_regulator_info local_da9062_regulator_info[] = {
865 .desc.ops = &da9062_ldo_ops, 872 .desc.ops = &da9062_ldo_ops,
866 .desc.min_uV = (900) * 1000, 873 .desc.min_uV = (900) * 1000,
867 .desc.uV_step = (50) * 1000, 874 .desc.uV_step = (50) * 1000,
868 .desc.n_voltages = ((3600) - (900))/(50) + 1, 875 .desc.n_voltages = ((3600) - (900))/(50) + 1
876 + DA9062AA_VLDO_A_MIN_SEL,
869 .desc.enable_reg = DA9062AA_LDO4_CONT, 877 .desc.enable_reg = DA9062AA_LDO4_CONT,
870 .desc.enable_mask = DA9062AA_LDO4_EN_MASK, 878 .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
871 .desc.vsel_reg = DA9062AA_VLDO4_A, 879 .desc.vsel_reg = DA9062AA_VLDO4_A,
872 .desc.vsel_mask = DA9062AA_VLDO4_A_MASK, 880 .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
873 .desc.linear_min_sel = 0, 881 .desc.linear_min_sel = DA9062AA_VLDO_A_MIN_SEL,
874 .sleep = REG_FIELD(DA9062AA_VLDO4_A, 882 .sleep = REG_FIELD(DA9062AA_VLDO4_A,
875 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1, 883 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
876 sizeof(unsigned int) * 8 - 884 sizeof(unsigned int) * 8 -
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 6f9ce1a6e44d..02f816318fba 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -19,7 +19,6 @@
19#include <linux/regulator/machine.h> 19#include <linux/regulator/machine.h>
20#include <linux/regulator/of_regulator.h> 20#include <linux/regulator/of_regulator.h>
21#include <linux/mfd/da9063/core.h> 21#include <linux/mfd/da9063/core.h>
22#include <linux/mfd/da9063/pdata.h>
23#include <linux/mfd/da9063/registers.h> 22#include <linux/mfd/da9063/registers.h>
24 23
25 24
@@ -28,6 +27,49 @@
28 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \ 27 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \
29 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1) 28 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1)
30 29
30/* DA9063 and DA9063L regulator IDs */
31enum {
32 /* BUCKs */
33 DA9063_ID_BCORE1,
34 DA9063_ID_BCORE2,
35 DA9063_ID_BPRO,
36 DA9063_ID_BMEM,
37 DA9063_ID_BIO,
38 DA9063_ID_BPERI,
39
40 /* BCORE1 and BCORE2 in merged mode */
41 DA9063_ID_BCORES_MERGED,
42 /* BMEM and BIO in merged mode */
43 DA9063_ID_BMEM_BIO_MERGED,
44 /* When two BUCKs are merged, they cannot be reused separately */
45
46 /* LDOs on both DA9063 and DA9063L */
47 DA9063_ID_LDO3,
48 DA9063_ID_LDO7,
49 DA9063_ID_LDO8,
50 DA9063_ID_LDO9,
51 DA9063_ID_LDO11,
52
53 /* DA9063-only LDOs */
54 DA9063_ID_LDO1,
55 DA9063_ID_LDO2,
56 DA9063_ID_LDO4,
57 DA9063_ID_LDO5,
58 DA9063_ID_LDO6,
59 DA9063_ID_LDO10,
60};
61
62/* Old regulator platform data */
63struct da9063_regulator_data {
64 int id;
65 struct regulator_init_data *initdata;
66};
67
68struct da9063_regulators_pdata {
69 unsigned n_regulators;
70 struct da9063_regulator_data *regulator_data;
71};
72
31/* Regulator capabilities and registers description */ 73/* Regulator capabilities and registers description */
32struct da9063_regulator_info { 74struct da9063_regulator_info {
33 struct regulator_desc desc; 75 struct regulator_desc desc;
@@ -592,7 +634,6 @@ static const struct regulator_init_data *da9063_get_regulator_initdata(
592 return NULL; 634 return NULL;
593} 635}
594 636
595#ifdef CONFIG_OF
596static struct of_regulator_match da9063_matches[] = { 637static struct of_regulator_match da9063_matches[] = {
597 [DA9063_ID_BCORE1] = { .name = "bcore1" }, 638 [DA9063_ID_BCORE1] = { .name = "bcore1" },
598 [DA9063_ID_BCORE2] = { .name = "bcore2" }, 639 [DA9063_ID_BCORE2] = { .name = "bcore2" },
@@ -670,20 +711,10 @@ static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
670 *da9063_reg_matches = da9063_matches; 711 *da9063_reg_matches = da9063_matches;
671 return pdata; 712 return pdata;
672} 713}
673#else
674static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
675 struct platform_device *pdev,
676 struct of_regulator_match **da9063_reg_matches)
677{
678 *da9063_reg_matches = NULL;
679 return ERR_PTR(-ENODEV);
680}
681#endif
682 714
683static int da9063_regulator_probe(struct platform_device *pdev) 715static int da9063_regulator_probe(struct platform_device *pdev)
684{ 716{
685 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); 717 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
686 struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev);
687 struct of_regulator_match *da9063_reg_matches = NULL; 718 struct of_regulator_match *da9063_reg_matches = NULL;
688 struct da9063_regulators_pdata *regl_pdata; 719 struct da9063_regulators_pdata *regl_pdata;
689 const struct da9063_dev_model *model; 720 const struct da9063_dev_model *model;
@@ -693,11 +724,7 @@ static int da9063_regulator_probe(struct platform_device *pdev)
693 bool bcores_merged, bmem_bio_merged; 724 bool bcores_merged, bmem_bio_merged;
694 int id, irq, n, n_regulators, ret, val; 725 int id, irq, n, n_regulators, ret, val;
695 726
696 regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL; 727 regl_pdata = da9063_parse_regulators_dt(pdev, &da9063_reg_matches);
697
698 if (!regl_pdata)
699 regl_pdata = da9063_parse_regulators_dt(pdev,
700 &da9063_reg_matches);
701 728
702 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) { 729 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) {
703 dev_err(&pdev->dev, 730 dev_err(&pdev->dev,
diff --git a/drivers/regulator/da9211-regulator.c b/drivers/regulator/da9211-regulator.c
index da37b4ccd834..0309823d2c72 100644
--- a/drivers/regulator/da9211-regulator.c
+++ b/drivers/regulator/da9211-regulator.c
@@ -289,6 +289,8 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
289 0, 289 0,
290 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, 290 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
291 "da9211-enable"); 291 "da9211-enable");
292 if (IS_ERR(pdata->gpiod_ren[n]))
293 pdata->gpiod_ren[n] = NULL;
292 n++; 294 n++;
293 } 295 }
294 296
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index b9ae45d2d199..4986cc5064a1 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -1,10 +1,9 @@
1// SPDX-License-Identifier: GPL-2.0-or-later 1// SPDX-License-Identifier: GPL-2.0-or-later
2/* 2//
3 * helpers.c -- Voltage/Current Regulator framework helper functions. 3// helpers.c -- Voltage/Current Regulator framework helper functions.
4 * 4//
5 * Copyright 2007, 2008 Wolfson Microelectronics PLC. 5// Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Copyright 2008 SlimLogic Ltd. 6// Copyright 2008 SlimLogic Ltd.
7 */
8 7
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10#include <linux/err.h> 9#include <linux/err.h>
diff --git a/drivers/regulator/max77620-regulator.c b/drivers/regulator/max77620-regulator.c
index 0db367b54ae7..8d9731e4052b 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -467,7 +467,7 @@ static int max77620_regulator_is_enabled(struct regulator_dev *rdev)
467{ 467{
468 struct max77620_regulator *pmic = rdev_get_drvdata(rdev); 468 struct max77620_regulator *pmic = rdev_get_drvdata(rdev);
469 int id = rdev_get_id(rdev); 469 int id = rdev_get_id(rdev);
470 int ret = 1; 470 int ret;
471 471
472 if (pmic->active_fps_src[id] != MAX77620_FPS_SRC_NONE) 472 if (pmic->active_fps_src[id] != MAX77620_FPS_SRC_NONE)
473 return 1; 473 return 1;
@@ -758,6 +758,24 @@ static struct max77620_regulator_info max20024_regs_info[MAX77620_NUM_REGS] = {
758 RAIL_LDO(LDO8, ldo8, "in-ldo7-8", N, 800000, 3950000, 50000), 758 RAIL_LDO(LDO8, ldo8, "in-ldo7-8", N, 800000, 3950000, 50000),
759}; 759};
760 760
761static struct max77620_regulator_info max77663_regs_info[MAX77620_NUM_REGS] = {
762 RAIL_SD(SD0, sd0, "in-sd0", SD0, 600000, 3387500, 12500, 0xFF, NONE),
763 RAIL_SD(SD1, sd1, "in-sd1", SD1, 800000, 1587500, 12500, 0xFF, NONE),
764 RAIL_SD(SD2, sd2, "in-sd2", SDX, 600000, 3787500, 12500, 0xFF, NONE),
765 RAIL_SD(SD3, sd3, "in-sd3", SDX, 600000, 3787500, 12500, 0xFF, NONE),
766 RAIL_SD(SD4, sd4, "in-sd4", SDX, 600000, 3787500, 12500, 0xFF, NONE),
767
768 RAIL_LDO(LDO0, ldo0, "in-ldo0-1", N, 800000, 2375000, 25000),
769 RAIL_LDO(LDO1, ldo1, "in-ldo0-1", N, 800000, 2375000, 25000),
770 RAIL_LDO(LDO2, ldo2, "in-ldo2", P, 800000, 3950000, 50000),
771 RAIL_LDO(LDO3, ldo3, "in-ldo3-5", P, 800000, 3950000, 50000),
772 RAIL_LDO(LDO4, ldo4, "in-ldo4-6", P, 800000, 1587500, 12500),
773 RAIL_LDO(LDO5, ldo5, "in-ldo3-5", P, 800000, 3950000, 50000),
774 RAIL_LDO(LDO6, ldo6, "in-ldo4-6", P, 800000, 3950000, 50000),
775 RAIL_LDO(LDO7, ldo7, "in-ldo7-8", N, 800000, 3950000, 50000),
776 RAIL_LDO(LDO8, ldo8, "in-ldo7-8", N, 800000, 3950000, 50000),
777};
778
761static int max77620_regulator_probe(struct platform_device *pdev) 779static int max77620_regulator_probe(struct platform_device *pdev)
762{ 780{
763 struct max77620_chip *max77620_chip = dev_get_drvdata(pdev->dev.parent); 781 struct max77620_chip *max77620_chip = dev_get_drvdata(pdev->dev.parent);
@@ -782,9 +800,14 @@ static int max77620_regulator_probe(struct platform_device *pdev)
782 case MAX77620: 800 case MAX77620:
783 rinfo = max77620_regs_info; 801 rinfo = max77620_regs_info;
784 break; 802 break;
785 default: 803 case MAX20024:
786 rinfo = max20024_regs_info; 804 rinfo = max20024_regs_info;
787 break; 805 break;
806 case MAX77663:
807 rinfo = max77663_regs_info;
808 break;
809 default:
810 return -EINVAL;
788 } 811 }
789 812
790 config.regmap = pmic->rmap; 813 config.regmap = pmic->rmap;
@@ -878,6 +901,7 @@ static const struct dev_pm_ops max77620_regulator_pm_ops = {
878static const struct platform_device_id max77620_regulator_devtype[] = { 901static const struct platform_device_id max77620_regulator_devtype[] = {
879 { .name = "max77620-pmic", }, 902 { .name = "max77620-pmic", },
880 { .name = "max20024-pmic", }, 903 { .name = "max20024-pmic", },
904 { .name = "max77663-pmic", },
881 {}, 905 {},
882}; 906};
883MODULE_DEVICE_TABLE(platform, max77620_regulator_devtype); 907MODULE_DEVICE_TABLE(platform, max77620_regulator_devtype);
diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
index 5c4f86c98510..e57fc9197d62 100644
--- a/drivers/regulator/max77650-regulator.c
+++ b/drivers/regulator/max77650-regulator.c
@@ -20,6 +20,8 @@
20 20
21#define MAX77650_REGULATOR_V_LDO_MASK GENMASK(6, 0) 21#define MAX77650_REGULATOR_V_LDO_MASK GENMASK(6, 0)
22#define MAX77650_REGULATOR_V_SBB_MASK GENMASK(5, 0) 22#define MAX77650_REGULATOR_V_SBB_MASK GENMASK(5, 0)
23#define MAX77651_REGULATOR_V_SBB1_MASK GENMASK(5, 2)
24#define MAX77651_REGULATOR_V_SBB1_RANGE_MASK GENMASK(1, 0)
23 25
24#define MAX77650_REGULATOR_AD_MASK BIT(3) 26#define MAX77650_REGULATOR_AD_MASK BIT(3)
25#define MAX77650_REGULATOR_AD_DISABLED 0x00 27#define MAX77650_REGULATOR_AD_DISABLED 0x00
@@ -41,43 +43,22 @@ struct max77650_regulator_desc {
41 unsigned int regB; 43 unsigned int regB;
42}; 44};
43 45
44static const unsigned int max77651_sbb1_regulator_volt_table[] = { 46static struct max77650_regulator_desc max77651_SBB1_desc;
45 2400000, 3200000, 4000000, 4800000, 47
46 2450000, 3250000, 4050000, 4850000, 48static const unsigned int max77651_sbb1_volt_range_sel[] = {
47 2500000, 3300000, 4100000, 4900000, 49 0x0, 0x1, 0x2, 0x3
48 2550000, 3350000, 4150000, 4950000,
49 2600000, 3400000, 4200000, 5000000,
50 2650000, 3450000, 4250000, 5050000,
51 2700000, 3500000, 4300000, 5100000,
52 2750000, 3550000, 4350000, 5150000,
53 2800000, 3600000, 4400000, 5200000,
54 2850000, 3650000, 4450000, 5250000,
55 2900000, 3700000, 4500000, 0,
56 2950000, 3750000, 4550000, 0,
57 3000000, 3800000, 4600000, 0,
58 3050000, 3850000, 4650000, 0,
59 3100000, 3900000, 4700000, 0,
60 3150000, 3950000, 4750000, 0,
61}; 50};
62 51
63#define MAX77651_REGULATOR_SBB1_SEL_DEC(_val) \ 52static const struct regulator_linear_range max77651_sbb1_volt_ranges[] = {
64 (((_val & 0x3c) >> 2) | ((_val & 0x03) << 4)) 53 /* range index 0 */
65#define MAX77651_REGULATOR_SBB1_SEL_ENC(_val) \ 54 REGULATOR_LINEAR_RANGE(2400000, 0x00, 0x0f, 50000),
66 (((_val & 0x30) >> 4) | ((_val & 0x0f) << 2)) 55 /* range index 1 */
67 56 REGULATOR_LINEAR_RANGE(3200000, 0x00, 0x0f, 50000),
68#define MAX77650_REGULATOR_SBB1_SEL_DECR(_val) \ 57 /* range index 2 */
69 do { \ 58 REGULATOR_LINEAR_RANGE(4000000, 0x00, 0x0f, 50000),
70 _val = MAX77651_REGULATOR_SBB1_SEL_DEC(_val); \ 59 /* range index 3 */
71 _val--; \ 60 REGULATOR_LINEAR_RANGE(4800000, 0x00, 0x09, 50000),
72 _val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val); \ 61};
73 } while (0)
74
75#define MAX77650_REGULATOR_SBB1_SEL_INCR(_val) \
76 do { \
77 _val = MAX77651_REGULATOR_SBB1_SEL_DEC(_val); \
78 _val++; \
79 _val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val); \
80 } while (0)
81 62
82static const unsigned int max77650_current_limit_table[] = { 63static const unsigned int max77650_current_limit_table[] = {
83 1000000, 866000, 707000, 500000, 64 1000000, 866000, 707000, 500000,
@@ -127,96 +108,6 @@ static int max77650_regulator_disable(struct regulator_dev *rdev)
127 MAX77650_REGULATOR_DISABLED); 108 MAX77650_REGULATOR_DISABLED);
128} 109}
129 110
130static int max77650_regulator_set_voltage_sel(struct regulator_dev *rdev,
131 unsigned int sel)
132{
133 int rv = 0, curr, diff;
134 bool ascending;
135
136 /*
137 * If the regulator is disabled, we can program the desired
138 * voltage right away.
139 */
140 if (!max77650_regulator_is_enabled(rdev))
141 return regulator_set_voltage_sel_regmap(rdev, sel);
142
143 /*
144 * Otherwise we need to manually ramp the output voltage up/down
145 * one step at a time.
146 */
147
148 curr = regulator_get_voltage_sel_regmap(rdev);
149 if (curr < 0)
150 return curr;
151
152 diff = curr - sel;
153 if (diff == 0)
154 return 0; /* Already there. */
155 else if (diff > 0)
156 ascending = false;
157 else
158 ascending = true;
159
160 /*
161 * Make sure we'll get to the right voltage and break the loop even if
162 * the selector equals 0.
163 */
164 for (ascending ? curr++ : curr--;; ascending ? curr++ : curr--) {
165 rv = regulator_set_voltage_sel_regmap(rdev, curr);
166 if (rv)
167 return rv;
168
169 if (curr == sel)
170 break;
171 }
172
173 return 0;
174}
175
176/*
177 * Special case: non-linear voltage table for max77651 SBB1 - software
178 * must ensure the voltage is ramped in 50mV increments.
179 */
180static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev *rdev,
181 unsigned int sel)
182{
183 int rv = 0, curr, vcurr, vdest, vdiff;
184
185 /*
186 * If the regulator is disabled, we can program the desired
187 * voltage right away.
188 */
189 if (!max77650_regulator_is_enabled(rdev))
190 return regulator_set_voltage_sel_regmap(rdev, sel);
191
192 curr = regulator_get_voltage_sel_regmap(rdev);
193 if (curr < 0)
194 return curr;
195
196 if (curr == sel)
197 return 0; /* Already there. */
198
199 vcurr = max77651_sbb1_regulator_volt_table[curr];
200 vdest = max77651_sbb1_regulator_volt_table[sel];
201 vdiff = vcurr - vdest;
202
203 for (;;) {
204 if (vdiff > 0)
205 MAX77650_REGULATOR_SBB1_SEL_DECR(curr);
206 else
207 MAX77650_REGULATOR_SBB1_SEL_INCR(curr);
208
209 rv = regulator_set_voltage_sel_regmap(rdev, curr);
210 if (rv)
211 return rv;
212
213 if (curr == sel)
214 break;
215 };
216
217 return 0;
218}
219
220static const struct regulator_ops max77650_regulator_LDO_ops = { 111static const struct regulator_ops max77650_regulator_LDO_ops = {
221 .is_enabled = max77650_regulator_is_enabled, 112 .is_enabled = max77650_regulator_is_enabled,
222 .enable = max77650_regulator_enable, 113 .enable = max77650_regulator_enable,
@@ -224,7 +115,7 @@ static const struct regulator_ops max77650_regulator_LDO_ops = {
224 .list_voltage = regulator_list_voltage_linear, 115 .list_voltage = regulator_list_voltage_linear,
225 .map_voltage = regulator_map_voltage_linear, 116 .map_voltage = regulator_map_voltage_linear,
226 .get_voltage_sel = regulator_get_voltage_sel_regmap, 117 .get_voltage_sel = regulator_get_voltage_sel_regmap,
227 .set_voltage_sel = max77650_regulator_set_voltage_sel, 118 .set_voltage_sel = regulator_set_voltage_sel_regmap,
228 .set_active_discharge = regulator_set_active_discharge_regmap, 119 .set_active_discharge = regulator_set_active_discharge_regmap,
229}; 120};
230 121
@@ -235,20 +126,20 @@ static const struct regulator_ops max77650_regulator_SBB_ops = {
235 .list_voltage = regulator_list_voltage_linear, 126 .list_voltage = regulator_list_voltage_linear,
236 .map_voltage = regulator_map_voltage_linear, 127 .map_voltage = regulator_map_voltage_linear,
237 .get_voltage_sel = regulator_get_voltage_sel_regmap, 128 .get_voltage_sel = regulator_get_voltage_sel_regmap,
238 .set_voltage_sel = max77650_regulator_set_voltage_sel, 129 .set_voltage_sel = regulator_set_voltage_sel_regmap,
239 .get_current_limit = regulator_get_current_limit_regmap, 130 .get_current_limit = regulator_get_current_limit_regmap,
240 .set_current_limit = regulator_set_current_limit_regmap, 131 .set_current_limit = regulator_set_current_limit_regmap,
241 .set_active_discharge = regulator_set_active_discharge_regmap, 132 .set_active_discharge = regulator_set_active_discharge_regmap,
242}; 133};
243 134
244/* Special case for max77651 SBB1 - non-linear voltage mapping. */ 135/* Special case for max77651 SBB1 - pickable linear-range voltage mapping. */
245static const struct regulator_ops max77651_SBB1_regulator_ops = { 136static const struct regulator_ops max77651_SBB1_regulator_ops = {
246 .is_enabled = max77650_regulator_is_enabled, 137 .is_enabled = max77650_regulator_is_enabled,
247 .enable = max77650_regulator_enable, 138 .enable = max77650_regulator_enable,
248 .disable = max77650_regulator_disable, 139 .disable = max77650_regulator_disable,
249 .list_voltage = regulator_list_voltage_table, 140 .list_voltage = regulator_list_voltage_pickable_linear_range,
250 .get_voltage_sel = regulator_get_voltage_sel_regmap, 141 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
251 .set_voltage_sel = max77651_regulator_sbb1_set_voltage_sel, 142 .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap,
252 .get_current_limit = regulator_get_current_limit_regmap, 143 .get_current_limit = regulator_get_current_limit_regmap,
253 .set_current_limit = regulator_set_current_limit_regmap, 144 .set_current_limit = regulator_set_current_limit_regmap,
254 .set_active_discharge = regulator_set_active_discharge_regmap, 145 .set_active_discharge = regulator_set_active_discharge_regmap,
@@ -265,6 +156,7 @@ static struct max77650_regulator_desc max77650_LDO_desc = {
265 .min_uV = 1350000, 156 .min_uV = 1350000,
266 .uV_step = 12500, 157 .uV_step = 12500,
267 .n_voltages = 128, 158 .n_voltages = 128,
159 .vsel_step = 1,
268 .vsel_mask = MAX77650_REGULATOR_V_LDO_MASK, 160 .vsel_mask = MAX77650_REGULATOR_V_LDO_MASK,
269 .vsel_reg = MAX77650_REG_CNFG_LDO_A, 161 .vsel_reg = MAX77650_REG_CNFG_LDO_A,
270 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 162 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -290,6 +182,7 @@ static struct max77650_regulator_desc max77650_SBB0_desc = {
290 .min_uV = 800000, 182 .min_uV = 800000,
291 .uV_step = 25000, 183 .uV_step = 25000,
292 .n_voltages = 64, 184 .n_voltages = 64,
185 .vsel_step = 1,
293 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, 186 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
294 .vsel_reg = MAX77650_REG_CNFG_SBB0_A, 187 .vsel_reg = MAX77650_REG_CNFG_SBB0_A,
295 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 188 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -319,6 +212,7 @@ static struct max77650_regulator_desc max77650_SBB1_desc = {
319 .min_uV = 800000, 212 .min_uV = 800000,
320 .uV_step = 12500, 213 .uV_step = 12500,
321 .n_voltages = 64, 214 .n_voltages = 64,
215 .vsel_step = 1,
322 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, 216 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
323 .vsel_reg = MAX77650_REG_CNFG_SBB1_A, 217 .vsel_reg = MAX77650_REG_CNFG_SBB1_A,
324 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 218 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -345,9 +239,14 @@ static struct max77650_regulator_desc max77651_SBB1_desc = {
345 .supply_name = "in-sbb1", 239 .supply_name = "in-sbb1",
346 .id = MAX77650_REGULATOR_ID_SBB1, 240 .id = MAX77650_REGULATOR_ID_SBB1,
347 .ops = &max77651_SBB1_regulator_ops, 241 .ops = &max77651_SBB1_regulator_ops,
348 .volt_table = max77651_sbb1_regulator_volt_table, 242 .linear_range_selectors = max77651_sbb1_volt_range_sel,
349 .n_voltages = ARRAY_SIZE(max77651_sbb1_regulator_volt_table), 243 .linear_ranges = max77651_sbb1_volt_ranges,
350 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, 244 .n_linear_ranges = ARRAY_SIZE(max77651_sbb1_volt_ranges),
245 .n_voltages = 58,
246 .vsel_step = 1,
247 .vsel_range_mask = MAX77651_REGULATOR_V_SBB1_RANGE_MASK,
248 .vsel_range_reg = MAX77650_REG_CNFG_SBB1_A,
249 .vsel_mask = MAX77651_REGULATOR_V_SBB1_MASK,
351 .vsel_reg = MAX77650_REG_CNFG_SBB1_A, 250 .vsel_reg = MAX77650_REG_CNFG_SBB1_A,
352 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 251 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
353 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED, 252 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
@@ -376,6 +275,7 @@ static struct max77650_regulator_desc max77650_SBB2_desc = {
376 .min_uV = 800000, 275 .min_uV = 800000,
377 .uV_step = 50000, 276 .uV_step = 50000,
378 .n_voltages = 64, 277 .n_voltages = 64,
278 .vsel_step = 1,
379 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, 279 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
380 .vsel_reg = MAX77650_REG_CNFG_SBB2_A, 280 .vsel_reg = MAX77650_REG_CNFG_SBB2_A,
381 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 281 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -405,6 +305,7 @@ static struct max77650_regulator_desc max77651_SBB2_desc = {
405 .min_uV = 2400000, 305 .min_uV = 2400000,
406 .uV_step = 50000, 306 .uV_step = 50000,
407 .n_voltages = 64, 307 .n_voltages = 64,
308 .vsel_step = 1,
408 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK, 309 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
409 .vsel_reg = MAX77650_REG_CNFG_SBB2_A, 310 .vsel_reg = MAX77650_REG_CNFG_SBB2_A,
410 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED, 311 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
@@ -496,3 +397,4 @@ module_platform_driver(max77650_regulator_driver);
496MODULE_DESCRIPTION("MAXIM 77650/77651 regulator driver"); 397MODULE_DESCRIPTION("MAXIM 77650/77651 regulator driver");
497MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>"); 398MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
498MODULE_LICENSE("GPL v2"); 399MODULE_LICENSE("GPL v2");
400MODULE_ALIAS("platform:max77650-regulator");
diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c
index ea7b50397300..7b8ec8c0bd15 100644
--- a/drivers/regulator/max77802-regulator.c
+++ b/drivers/regulator/max77802-regulator.c
@@ -14,9 +14,7 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/bug.h> 15#include <linux/bug.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/gpio.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
19#include <linux/gpio/consumer.h>
20#include <linux/module.h> 18#include <linux/module.h>
21#include <linux/platform_device.h> 19#include <linux/platform_device.h>
22#include <linux/regulator/driver.h> 20#include <linux/regulator/driver.h>
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 2a123b87d9f2..ccd5da63cdf2 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -13,11 +13,9 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/regulator/driver.h> 14#include <linux/regulator/driver.h>
15#include <linux/regulator/max8952.h> 15#include <linux/regulator/max8952.h>
16#include <linux/gpio.h>
17#include <linux/gpio/consumer.h> 16#include <linux/gpio/consumer.h>
18#include <linux/io.h> 17#include <linux/io.h>
19#include <linux/of.h> 18#include <linux/of.h>
20#include <linux/of_gpio.h>
21#include <linux/regulator/of_regulator.h> 19#include <linux/regulator/of_regulator.h>
22#include <linux/slab.h> 20#include <linux/slab.h>
23 21
@@ -37,7 +35,8 @@ enum {
37struct max8952_data { 35struct max8952_data {
38 struct i2c_client *client; 36 struct i2c_client *client;
39 struct max8952_platform_data *pdata; 37 struct max8952_platform_data *pdata;
40 38 struct gpio_desc *vid0_gpiod;
39 struct gpio_desc *vid1_gpiod;
41 bool vid0; 40 bool vid0;
42 bool vid1; 41 bool vid1;
43}; 42};
@@ -87,16 +86,15 @@ static int max8952_set_voltage_sel(struct regulator_dev *rdev,
87{ 86{
88 struct max8952_data *max8952 = rdev_get_drvdata(rdev); 87 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
89 88
90 if (!gpio_is_valid(max8952->pdata->gpio_vid0) || 89 if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) {
91 !gpio_is_valid(max8952->pdata->gpio_vid1)) {
92 /* DVS not supported */ 90 /* DVS not supported */
93 return -EPERM; 91 return -EPERM;
94 } 92 }
95 93
96 max8952->vid0 = selector & 0x1; 94 max8952->vid0 = selector & 0x1;
97 max8952->vid1 = (selector >> 1) & 0x1; 95 max8952->vid1 = (selector >> 1) & 0x1;
98 gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); 96 gpiod_set_value(max8952->vid0_gpiod, max8952->vid0);
99 gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); 97 gpiod_set_value(max8952->vid1_gpiod, max8952->vid1);
100 98
101 return 0; 99 return 0;
102} 100}
@@ -134,9 +132,6 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
134 if (!pd) 132 if (!pd)
135 return NULL; 133 return NULL;
136 134
137 pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0);
138 pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1);
139
140 if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode)) 135 if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode))
141 dev_warn(dev, "Default mode not specified, assuming 0\n"); 136 dev_warn(dev, "Default mode not specified, assuming 0\n");
142 137
@@ -179,7 +174,7 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
179static int max8952_pmic_probe(struct i2c_client *client, 174static int max8952_pmic_probe(struct i2c_client *client,
180 const struct i2c_device_id *i2c_id) 175 const struct i2c_device_id *i2c_id)
181{ 176{
182 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 177 struct i2c_adapter *adapter = client->adapter;
183 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev); 178 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev);
184 struct regulator_config config = { }; 179 struct regulator_config config = { };
185 struct max8952_data *max8952; 180 struct max8952_data *max8952;
@@ -187,7 +182,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
187 struct gpio_desc *gpiod; 182 struct gpio_desc *gpiod;
188 enum gpiod_flags gflags; 183 enum gpiod_flags gflags;
189 184
190 int ret = 0, err = 0; 185 int ret = 0;
191 186
192 if (client->dev.of_node) 187 if (client->dev.of_node)
193 pdata = max8952_parse_dt(&client->dev); 188 pdata = max8952_parse_dt(&client->dev);
@@ -240,32 +235,31 @@ static int max8952_pmic_probe(struct i2c_client *client,
240 max8952->vid0 = pdata->default_mode & 0x1; 235 max8952->vid0 = pdata->default_mode & 0x1;
241 max8952->vid1 = (pdata->default_mode >> 1) & 0x1; 236 max8952->vid1 = (pdata->default_mode >> 1) & 0x1;
242 237
243 if (gpio_is_valid(pdata->gpio_vid0) && 238 /* Fetch vid0 and vid1 GPIOs if available */
244 gpio_is_valid(pdata->gpio_vid1)) { 239 gflags = max8952->vid0 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
245 unsigned long gpio_flags; 240 max8952->vid0_gpiod = devm_gpiod_get_index_optional(&client->dev,
246 241 "max8952,vid",
247 gpio_flags = max8952->vid0 ? 242 0, gflags);
248 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 243 if (IS_ERR(max8952->vid0_gpiod))
249 if (devm_gpio_request_one(&client->dev, pdata->gpio_vid0, 244 return PTR_ERR(max8952->vid0_gpiod);
250 gpio_flags, "MAX8952 VID0")) 245 gflags = max8952->vid1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
251 err = 1; 246 max8952->vid1_gpiod = devm_gpiod_get_index_optional(&client->dev,
252 247 "max8952,vid",
253 gpio_flags = max8952->vid1 ? 248 1, gflags);
254 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; 249 if (IS_ERR(max8952->vid1_gpiod))
255 if (devm_gpio_request_one(&client->dev, pdata->gpio_vid1, 250 return PTR_ERR(max8952->vid1_gpiod);
256 gpio_flags, "MAX8952 VID1")) 251
257 err = 2; 252 /* If either VID GPIO is missing just disable this */
258 } else 253 if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) {
259 err = 3;
260
261 if (err) {
262 dev_warn(&client->dev, "VID0/1 gpio invalid: " 254 dev_warn(&client->dev, "VID0/1 gpio invalid: "
263 "DVS not available.\n"); 255 "DVS not available.\n");
264 max8952->vid0 = 0; 256 max8952->vid0 = 0;
265 max8952->vid1 = 0; 257 max8952->vid1 = 0;
266 /* Mark invalid */ 258 /* Make sure if we have any descriptors they get set to low */
267 pdata->gpio_vid0 = -1; 259 if (max8952->vid0_gpiod)
268 pdata->gpio_vid1 = -1; 260 gpiod_set_value(max8952->vid0_gpiod, 0);
261 if (max8952->vid1_gpiod)
262 gpiod_set_value(max8952->vid1_gpiod, 0);
269 263
270 /* Disable Pulldown of EN only */ 264 /* Disable Pulldown of EN only */
271 max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60); 265 max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60);
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 0ead1164e4d6..397918ebba55 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -21,7 +21,8 @@ static const char *const regulator_states[PM_SUSPEND_MAX + 1] = {
21 [PM_SUSPEND_MAX] = "regulator-state-disk", 21 [PM_SUSPEND_MAX] = "regulator-state-disk",
22}; 22};
23 23
24static void of_get_regulation_constraints(struct device_node *np, 24static int of_get_regulation_constraints(struct device *dev,
25 struct device_node *np,
25 struct regulator_init_data **init_data, 26 struct regulator_init_data **init_data,
26 const struct regulator_desc *desc) 27 const struct regulator_desc *desc)
27{ 28{
@@ -30,8 +31,13 @@ static void of_get_regulation_constraints(struct device_node *np,
30 struct device_node *suspend_np; 31 struct device_node *suspend_np;
31 unsigned int mode; 32 unsigned int mode;
32 int ret, i, len; 33 int ret, i, len;
34 int n_phandles;
33 u32 pval; 35 u32 pval;
34 36
37 n_phandles = of_count_phandle_with_args(np, "regulator-coupled-with",
38 NULL);
39 n_phandles = max(n_phandles, 0);
40
35 constraints->name = of_get_property(np, "regulator-name", NULL); 41 constraints->name = of_get_property(np, "regulator-name", NULL);
36 42
37 if (!of_property_read_u32(np, "regulator-min-microvolt", &pval)) 43 if (!of_property_read_u32(np, "regulator-min-microvolt", &pval))
@@ -163,9 +169,17 @@ static void of_get_regulation_constraints(struct device_node *np,
163 if (!of_property_read_u32(np, "regulator-system-load", &pval)) 169 if (!of_property_read_u32(np, "regulator-system-load", &pval))
164 constraints->system_load = pval; 170 constraints->system_load = pval;
165 171
166 if (!of_property_read_u32(np, "regulator-coupled-max-spread", 172 if (n_phandles) {
167 &pval)) 173 constraints->max_spread = devm_kzalloc(dev,
168 constraints->max_spread = pval; 174 sizeof(*constraints->max_spread) * n_phandles,
175 GFP_KERNEL);
176
177 if (!constraints->max_spread)
178 return -ENOMEM;
179
180 of_property_read_u32_array(np, "regulator-coupled-max-spread",
181 constraints->max_spread, n_phandles);
182 }
169 183
170 if (!of_property_read_u32(np, "regulator-max-step-microvolt", 184 if (!of_property_read_u32(np, "regulator-max-step-microvolt",
171 &pval)) 185 &pval))
@@ -242,6 +256,8 @@ static void of_get_regulation_constraints(struct device_node *np,
242 suspend_state = NULL; 256 suspend_state = NULL;
243 suspend_np = NULL; 257 suspend_np = NULL;
244 } 258 }
259
260 return 0;
245} 261}
246 262
247/** 263/**
@@ -267,7 +283,9 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
267 if (!init_data) 283 if (!init_data)
268 return NULL; /* Out of memory? */ 284 return NULL; /* Out of memory? */
269 285
270 of_get_regulation_constraints(node, &init_data, desc); 286 if (of_get_regulation_constraints(dev, node, &init_data, desc))
287 return NULL;
288
271 return init_data; 289 return init_data;
272} 290}
273EXPORT_SYMBOL_GPL(of_get_regulator_init_data); 291EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
@@ -473,7 +491,8 @@ int of_get_n_coupled(struct regulator_dev *rdev)
473 491
474/* Looks for "to_find" device_node in src's "regulator-coupled-with" property */ 492/* Looks for "to_find" device_node in src's "regulator-coupled-with" property */
475static bool of_coupling_find_node(struct device_node *src, 493static bool of_coupling_find_node(struct device_node *src,
476 struct device_node *to_find) 494 struct device_node *to_find,
495 int *index)
477{ 496{
478 int n_phandles, i; 497 int n_phandles, i;
479 bool found = false; 498 bool found = false;
@@ -495,8 +514,10 @@ static bool of_coupling_find_node(struct device_node *src,
495 514
496 of_node_put(tmp); 515 of_node_put(tmp);
497 516
498 if (found) 517 if (found) {
518 *index = i;
499 break; 519 break;
520 }
500 } 521 }
501 522
502 return found; 523 return found;
@@ -517,22 +538,23 @@ static bool of_coupling_find_node(struct device_node *src,
517 */ 538 */
518bool of_check_coupling_data(struct regulator_dev *rdev) 539bool of_check_coupling_data(struct regulator_dev *rdev)
519{ 540{
520 int max_spread = rdev->constraints->max_spread;
521 struct device_node *node = rdev->dev.of_node; 541 struct device_node *node = rdev->dev.of_node;
522 int n_phandles = of_get_n_coupled(rdev); 542 int n_phandles = of_get_n_coupled(rdev);
523 struct device_node *c_node; 543 struct device_node *c_node;
544 int index;
524 int i; 545 int i;
525 bool ret = true; 546 bool ret = true;
526 547
527 if (max_spread <= 0) {
528 dev_err(&rdev->dev, "max_spread value invalid\n");
529 return false;
530 }
531
532 /* iterate over rdev's phandles */ 548 /* iterate over rdev's phandles */
533 for (i = 0; i < n_phandles; i++) { 549 for (i = 0; i < n_phandles; i++) {
550 int max_spread = rdev->constraints->max_spread[i];
534 int c_max_spread, c_n_phandles; 551 int c_max_spread, c_n_phandles;
535 552
553 if (max_spread <= 0) {
554 dev_err(&rdev->dev, "max_spread value invalid\n");
555 return false;
556 }
557
536 c_node = of_parse_phandle(node, 558 c_node = of_parse_phandle(node,
537 "regulator-coupled-with", i); 559 "regulator-coupled-with", i);
538 560
@@ -549,22 +571,23 @@ bool of_check_coupling_data(struct regulator_dev *rdev)
549 goto clean; 571 goto clean;
550 } 572 }
551 573
552 if (of_property_read_u32(c_node, "regulator-coupled-max-spread", 574 if (!of_coupling_find_node(c_node, node, &index)) {
553 &c_max_spread)) { 575 dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n");
554 ret = false; 576 ret = false;
555 goto clean; 577 goto clean;
556 } 578 }
557 579
558 if (c_max_spread != max_spread) { 580 if (of_property_read_u32_index(c_node, "regulator-coupled-max-spread",
559 dev_err(&rdev->dev, 581 index, &c_max_spread)) {
560 "coupled regulators max_spread mismatch\n");
561 ret = false; 582 ret = false;
562 goto clean; 583 goto clean;
563 } 584 }
564 585
565 if (!of_coupling_find_node(c_node, node)) { 586 if (c_max_spread != max_spread) {
566 dev_err(&rdev->dev, "missing 2-way linking for coupled regulators\n"); 587 dev_err(&rdev->dev,
588 "coupled regulators max_spread mismatch\n");
567 ret = false; 589 ret = false;
590 goto clean;
568 } 591 }
569 592
570clean: 593clean:
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index 6dfc9e176360..7f51c5fc8194 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -96,6 +96,8 @@ enum spmi_regulator_logical_type {
96 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS, 96 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS,
97 SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS, 97 SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS,
98 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO, 98 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO,
99 SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426,
100 SPMI_REGULATOR_LOGICAL_TYPE_HFS430,
99}; 101};
100 102
101enum spmi_regulator_type { 103enum spmi_regulator_type {
@@ -142,11 +144,13 @@ enum spmi_regulator_subtype {
142 SPMI_REGULATOR_SUBTYPE_5V_BOOST = 0x01, 144 SPMI_REGULATOR_SUBTYPE_5V_BOOST = 0x01,
143 SPMI_REGULATOR_SUBTYPE_FTS_CTL = 0x08, 145 SPMI_REGULATOR_SUBTYPE_FTS_CTL = 0x08,
144 SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL = 0x09, 146 SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL = 0x09,
147 SPMI_REGULATOR_SUBTYPE_FTS426_CTL = 0x0a,
145 SPMI_REGULATOR_SUBTYPE_BB_2A = 0x01, 148 SPMI_REGULATOR_SUBTYPE_BB_2A = 0x01,
146 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1 = 0x0d, 149 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1 = 0x0d,
147 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2 = 0x0e, 150 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2 = 0x0e,
148 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3 = 0x0f, 151 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3 = 0x0f,
149 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4 = 0x10, 152 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4 = 0x10,
153 SPMI_REGULATOR_SUBTYPE_HFS430 = 0x0a,
150}; 154};
151 155
152enum spmi_common_regulator_registers { 156enum spmi_common_regulator_registers {
@@ -162,6 +166,18 @@ enum spmi_common_regulator_registers {
162 SPMI_COMMON_REG_STEP_CTRL = 0x61, 166 SPMI_COMMON_REG_STEP_CTRL = 0x61,
163}; 167};
164 168
169/*
170 * Second common register layout used by newer devices starting with ftsmps426
171 * Note that some of the registers from the first common layout remain
172 * unchanged and their definition is not duplicated.
173 */
174enum spmi_ftsmps426_regulator_registers {
175 SPMI_FTSMPS426_REG_VOLTAGE_LSB = 0x40,
176 SPMI_FTSMPS426_REG_VOLTAGE_MSB = 0x41,
177 SPMI_FTSMPS426_REG_VOLTAGE_ULS_LSB = 0x68,
178 SPMI_FTSMPS426_REG_VOLTAGE_ULS_MSB = 0x69,
179};
180
165enum spmi_vs_registers { 181enum spmi_vs_registers {
166 SPMI_VS_REG_OCP = 0x4a, 182 SPMI_VS_REG_OCP = 0x4a,
167 SPMI_VS_REG_SOFT_START = 0x4c, 183 SPMI_VS_REG_SOFT_START = 0x4c,
@@ -221,6 +237,14 @@ enum spmi_common_control_register_index {
221#define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01 237#define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01
222#define SPMI_COMMON_MODE_FOLLOW_ALL_MASK 0x1f 238#define SPMI_COMMON_MODE_FOLLOW_ALL_MASK 0x1f
223 239
240#define SPMI_FTSMPS426_MODE_BYPASS_MASK 3
241#define SPMI_FTSMPS426_MODE_RETENTION_MASK 4
242#define SPMI_FTSMPS426_MODE_LPM_MASK 5
243#define SPMI_FTSMPS426_MODE_AUTO_MASK 6
244#define SPMI_FTSMPS426_MODE_HPM_MASK 7
245
246#define SPMI_FTSMPS426_MODE_MASK 0x07
247
224/* Common regulator pull down control register layout */ 248/* Common regulator pull down control register layout */
225#define SPMI_COMMON_PULL_DOWN_ENABLE_MASK 0x80 249#define SPMI_COMMON_PULL_DOWN_ENABLE_MASK 0x80
226 250
@@ -266,6 +290,25 @@ enum spmi_common_control_register_index {
266#define SPMI_FTSMPS_STEP_MARGIN_NUM 4 290#define SPMI_FTSMPS_STEP_MARGIN_NUM 4
267#define SPMI_FTSMPS_STEP_MARGIN_DEN 5 291#define SPMI_FTSMPS_STEP_MARGIN_DEN 5
268 292
293#define SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK 0x03
294#define SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT 0
295
296/* Clock rate in kHz of the FTSMPS426 regulator reference clock. */
297#define SPMI_FTSMPS426_CLOCK_RATE 4800
298
299#define SPMI_HFS430_CLOCK_RATE 1600
300
301/* Minimum voltage stepper delay for each step. */
302#define SPMI_FTSMPS426_STEP_DELAY 2
303
304/*
305 * The ratio SPMI_FTSMPS426_STEP_MARGIN_NUM/SPMI_FTSMPS426_STEP_MARGIN_DEN is
306 * used to adjust the step rate in order to account for oscillator variance.
307 */
308#define SPMI_FTSMPS426_STEP_MARGIN_NUM 10
309#define SPMI_FTSMPS426_STEP_MARGIN_DEN 11
310
311
269/* VSET value to decide the range of ULT SMPS */ 312/* VSET value to decide the range of ULT SMPS */
270#define ULT_SMPS_RANGE_SPLIT 0x60 313#define ULT_SMPS_RANGE_SPLIT 0x60
271 314
@@ -439,6 +482,10 @@ static struct spmi_voltage_range ftsmps2p5_ranges[] = {
439 SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000), 482 SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000),
440}; 483};
441 484
485static struct spmi_voltage_range ftsmps426_ranges[] = {
486 SPMI_VOLTAGE_RANGE(0, 0, 320000, 1352000, 1352000, 4000),
487};
488
442static struct spmi_voltage_range boost_ranges[] = { 489static struct spmi_voltage_range boost_ranges[] = {
443 SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000), 490 SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000),
444}; 491};
@@ -464,6 +511,10 @@ static struct spmi_voltage_range ult_pldo_ranges[] = {
464 SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500), 511 SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500),
465}; 512};
466 513
514static struct spmi_voltage_range hfs430_ranges[] = {
515 SPMI_VOLTAGE_RANGE(0, 320000, 320000, 2040000, 2040000, 8000),
516};
517
467static DEFINE_SPMI_SET_POINTS(pldo); 518static DEFINE_SPMI_SET_POINTS(pldo);
468static DEFINE_SPMI_SET_POINTS(nldo1); 519static DEFINE_SPMI_SET_POINTS(nldo1);
469static DEFINE_SPMI_SET_POINTS(nldo2); 520static DEFINE_SPMI_SET_POINTS(nldo2);
@@ -472,12 +523,14 @@ static DEFINE_SPMI_SET_POINTS(ln_ldo);
472static DEFINE_SPMI_SET_POINTS(smps); 523static DEFINE_SPMI_SET_POINTS(smps);
473static DEFINE_SPMI_SET_POINTS(ftsmps); 524static DEFINE_SPMI_SET_POINTS(ftsmps);
474static DEFINE_SPMI_SET_POINTS(ftsmps2p5); 525static DEFINE_SPMI_SET_POINTS(ftsmps2p5);
526static DEFINE_SPMI_SET_POINTS(ftsmps426);
475static DEFINE_SPMI_SET_POINTS(boost); 527static DEFINE_SPMI_SET_POINTS(boost);
476static DEFINE_SPMI_SET_POINTS(boost_byp); 528static DEFINE_SPMI_SET_POINTS(boost_byp);
477static DEFINE_SPMI_SET_POINTS(ult_lo_smps); 529static DEFINE_SPMI_SET_POINTS(ult_lo_smps);
478static DEFINE_SPMI_SET_POINTS(ult_ho_smps); 530static DEFINE_SPMI_SET_POINTS(ult_ho_smps);
479static DEFINE_SPMI_SET_POINTS(ult_nldo); 531static DEFINE_SPMI_SET_POINTS(ult_nldo);
480static DEFINE_SPMI_SET_POINTS(ult_pldo); 532static DEFINE_SPMI_SET_POINTS(ult_pldo);
533static DEFINE_SPMI_SET_POINTS(hfs430);
481 534
482static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf, 535static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf,
483 int len) 536 int len)
@@ -739,18 +792,31 @@ spmi_regulator_common_set_voltage(struct regulator_dev *rdev, unsigned selector)
739 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2); 792 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2);
740} 793}
741 794
795static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev,
796 unsigned selector);
797
798static int spmi_regulator_ftsmps426_set_voltage(struct regulator_dev *rdev,
799 unsigned selector)
800{
801 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
802 u8 buf[2];
803 int mV;
804
805 mV = spmi_regulator_common_list_voltage(rdev, selector) / 1000;
806
807 buf[0] = mV & 0xff;
808 buf[1] = mV >> 8;
809 return spmi_vreg_write(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2);
810}
811
742static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev, 812static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
743 unsigned int old_selector, unsigned int new_selector) 813 unsigned int old_selector, unsigned int new_selector)
744{ 814{
745 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 815 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
746 const struct spmi_voltage_range *range;
747 int diff_uV; 816 int diff_uV;
748 817
749 range = spmi_regulator_find_range(vreg); 818 diff_uV = abs(spmi_regulator_common_list_voltage(rdev, new_selector) -
750 if (!range) 819 spmi_regulator_common_list_voltage(rdev, old_selector));
751 return -EINVAL;
752
753 diff_uV = abs(new_selector - old_selector) * range->step_uV;
754 820
755 return DIV_ROUND_UP(diff_uV, vreg->slew_rate); 821 return DIV_ROUND_UP(diff_uV, vreg->slew_rate);
756} 822}
@@ -770,6 +836,21 @@ static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev)
770 return spmi_hw_selector_to_sw(vreg, voltage_sel, range); 836 return spmi_hw_selector_to_sw(vreg, voltage_sel, range);
771} 837}
772 838
839static int spmi_regulator_ftsmps426_get_voltage(struct regulator_dev *rdev)
840{
841 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
842 const struct spmi_voltage_range *range;
843 u8 buf[2];
844 int uV;
845
846 spmi_vreg_read(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2);
847
848 uV = (((unsigned int)buf[1] << 8) | (unsigned int)buf[0]) * 1000;
849 range = vreg->set_points->range;
850
851 return (uV - range->set_point_min_uV) / range->step_uV;
852}
853
773static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev, 854static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev,
774 int min_uV, int max_uV) 855 int min_uV, int max_uV)
775{ 856{
@@ -903,13 +984,33 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev)
903 984
904 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1); 985 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
905 986
906 if (reg & SPMI_COMMON_MODE_HPM_MASK) 987 reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK;
907 return REGULATOR_MODE_NORMAL;
908 988
909 if (reg & SPMI_COMMON_MODE_AUTO_MASK) 989 switch (reg) {
990 case SPMI_COMMON_MODE_HPM_MASK:
991 return REGULATOR_MODE_NORMAL;
992 case SPMI_COMMON_MODE_AUTO_MASK:
910 return REGULATOR_MODE_FAST; 993 return REGULATOR_MODE_FAST;
994 default:
995 return REGULATOR_MODE_IDLE;
996 }
997}
911 998
912 return REGULATOR_MODE_IDLE; 999static unsigned int spmi_regulator_ftsmps426_get_mode(struct regulator_dev *rdev)
1000{
1001 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1002 u8 reg;
1003
1004 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
1005
1006 switch (reg) {
1007 case SPMI_FTSMPS426_MODE_HPM_MASK:
1008 return REGULATOR_MODE_NORMAL;
1009 case SPMI_FTSMPS426_MODE_AUTO_MASK:
1010 return REGULATOR_MODE_FAST;
1011 default:
1012 return REGULATOR_MODE_IDLE;
1013 }
913} 1014}
914 1015
915static int 1016static int
@@ -917,12 +1018,43 @@ spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode)
917{ 1018{
918 struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1019 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
919 u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; 1020 u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK;
920 u8 val = 0; 1021 u8 val;
921 1022
922 if (mode == REGULATOR_MODE_NORMAL) 1023 switch (mode) {
1024 case REGULATOR_MODE_NORMAL:
923 val = SPMI_COMMON_MODE_HPM_MASK; 1025 val = SPMI_COMMON_MODE_HPM_MASK;
924 else if (mode == REGULATOR_MODE_FAST) 1026 break;
1027 case REGULATOR_MODE_FAST:
925 val = SPMI_COMMON_MODE_AUTO_MASK; 1028 val = SPMI_COMMON_MODE_AUTO_MASK;
1029 break;
1030 default:
1031 val = 0;
1032 break;
1033 }
1034
1035 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
1036}
1037
1038static int
1039spmi_regulator_ftsmps426_set_mode(struct regulator_dev *rdev, unsigned int mode)
1040{
1041 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1042 u8 mask = SPMI_FTSMPS426_MODE_MASK;
1043 u8 val;
1044
1045 switch (mode) {
1046 case REGULATOR_MODE_NORMAL:
1047 val = SPMI_FTSMPS426_MODE_HPM_MASK;
1048 break;
1049 case REGULATOR_MODE_FAST:
1050 val = SPMI_FTSMPS426_MODE_AUTO_MASK;
1051 break;
1052 case REGULATOR_MODE_IDLE:
1053 val = SPMI_FTSMPS426_MODE_LPM_MASK;
1054 break;
1055 default:
1056 return -EINVAL;
1057 }
926 1058
927 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1059 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
928} 1060}
@@ -1256,12 +1388,41 @@ static struct regulator_ops spmi_ult_ldo_ops = {
1256 .set_soft_start = spmi_regulator_common_set_soft_start, 1388 .set_soft_start = spmi_regulator_common_set_soft_start,
1257}; 1389};
1258 1390
1391static struct regulator_ops spmi_ftsmps426_ops = {
1392 .enable = regulator_enable_regmap,
1393 .disable = regulator_disable_regmap,
1394 .is_enabled = regulator_is_enabled_regmap,
1395 .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage,
1396 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1397 .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage,
1398 .map_voltage = spmi_regulator_single_map_voltage,
1399 .list_voltage = spmi_regulator_common_list_voltage,
1400 .set_mode = spmi_regulator_ftsmps426_set_mode,
1401 .get_mode = spmi_regulator_ftsmps426_get_mode,
1402 .set_load = spmi_regulator_common_set_load,
1403 .set_pull_down = spmi_regulator_common_set_pull_down,
1404};
1405
1406static struct regulator_ops spmi_hfs430_ops = {
1407 .enable = regulator_enable_regmap,
1408 .disable = regulator_disable_regmap,
1409 .is_enabled = regulator_is_enabled_regmap,
1410 .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage,
1411 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
1412 .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage,
1413 .map_voltage = spmi_regulator_single_map_voltage,
1414 .list_voltage = spmi_regulator_common_list_voltage,
1415 .set_mode = spmi_regulator_ftsmps426_set_mode,
1416 .get_mode = spmi_regulator_ftsmps426_get_mode,
1417};
1418
1259/* Maximum possible digital major revision value */ 1419/* Maximum possible digital major revision value */
1260#define INF 0xFF 1420#define INF 0xFF
1261 1421
1262static const struct spmi_regulator_mapping supported_regulators[] = { 1422static const struct spmi_regulator_mapping supported_regulators[] = {
1263 /* type subtype dig_min dig_max ltype ops setpoints hpm_min */ 1423 /* type subtype dig_min dig_max ltype ops setpoints hpm_min */
1264 SPMI_VREG(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000), 1424 SPMI_VREG(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000),
1425 SPMI_VREG(BUCK, HFS430, 0, INF, HFS430, hfs430, hfs430, 10000),
1265 SPMI_VREG(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000), 1426 SPMI_VREG(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000),
1266 SPMI_VREG(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000), 1427 SPMI_VREG(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000),
1267 SPMI_VREG(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000), 1428 SPMI_VREG(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000),
@@ -1291,6 +1452,7 @@ static const struct spmi_regulator_mapping supported_regulators[] = {
1291 SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0), 1452 SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0),
1292 SPMI_VREG(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000), 1453 SPMI_VREG(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000),
1293 SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000), 1454 SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000),
1455 SPMI_VREG(FTS, FTS426_CTL, 0, INF, FTSMPS426, ftsmps426, ftsmps426, 100000),
1294 SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0), 1456 SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0),
1295 SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1457 SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1296 ult_lo_smps, 100000), 1458 ult_lo_smps, 100000),
@@ -1428,6 +1590,35 @@ static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg)
1428 return ret; 1590 return ret;
1429} 1591}
1430 1592
1593static int spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator *vreg,
1594 int clock_rate)
1595{
1596 int ret;
1597 u8 reg = 0;
1598 int delay, slew_rate;
1599 const struct spmi_voltage_range *range = &vreg->set_points->range[0];
1600
1601 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
1602 if (ret) {
1603 dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret);
1604 return ret;
1605 }
1606
1607 delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK;
1608 delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT;
1609
1610 /* slew_rate has units of uV/us */
1611 slew_rate = clock_rate * range->step_uV;
1612 slew_rate /= 1000 * (SPMI_FTSMPS426_STEP_DELAY << delay);
1613 slew_rate *= SPMI_FTSMPS426_STEP_MARGIN_NUM;
1614 slew_rate /= SPMI_FTSMPS426_STEP_MARGIN_DEN;
1615
1616 /* Ensure that the slew rate is greater than 0 */
1617 vreg->slew_rate = max(slew_rate, 1);
1618
1619 return ret;
1620}
1621
1431static int spmi_regulator_init_registers(struct spmi_regulator *vreg, 1622static int spmi_regulator_init_registers(struct spmi_regulator *vreg,
1432 const struct spmi_regulator_init_data *data) 1623 const struct spmi_regulator_init_data *data)
1433{ 1624{
@@ -1567,6 +1758,19 @@ static int spmi_regulator_of_parse(struct device_node *node,
1567 ret = spmi_regulator_init_slew_rate(vreg); 1758 ret = spmi_regulator_init_slew_rate(vreg);
1568 if (ret) 1759 if (ret)
1569 return ret; 1760 return ret;
1761 break;
1762 case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426:
1763 ret = spmi_regulator_init_slew_rate_ftsmps426(vreg,
1764 SPMI_FTSMPS426_CLOCK_RATE);
1765 if (ret)
1766 return ret;
1767 break;
1768 case SPMI_REGULATOR_LOGICAL_TYPE_HFS430:
1769 ret = spmi_regulator_init_slew_rate_ftsmps426(vreg,
1770 SPMI_HFS430_CLOCK_RATE);
1771 if (ret)
1772 return ret;
1773 break;
1570 default: 1774 default:
1571 break; 1775 break;
1572 } 1776 }
@@ -1723,12 +1927,27 @@ static const struct spmi_regulator_data pmi8994_regulators[] = {
1723 { } 1927 { }
1724}; 1928};
1725 1929
1930static const struct spmi_regulator_data pm8005_regulators[] = {
1931 { "s1", 0x1400, "vdd_s1", },
1932 { "s2", 0x1700, "vdd_s2", },
1933 { "s3", 0x1a00, "vdd_s3", },
1934 { "s4", 0x1d00, "vdd_s4", },
1935 { }
1936};
1937
1938static const struct spmi_regulator_data pms405_regulators[] = {
1939 { "s3", 0x1a00, "vdd_s3"},
1940 { }
1941};
1942
1726static const struct of_device_id qcom_spmi_regulator_match[] = { 1943static const struct of_device_id qcom_spmi_regulator_match[] = {
1944 { .compatible = "qcom,pm8005-regulators", .data = &pm8005_regulators },
1727 { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators }, 1945 { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators },
1728 { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators }, 1946 { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators },
1729 { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators }, 1947 { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators },
1730 { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators }, 1948 { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators },
1731 { .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators }, 1949 { .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators },
1950 { .compatible = "qcom,pms405-regulators", .data = &pms405_regulators },
1732 { } 1951 { }
1733}; 1952};
1734MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match); 1953MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);
@@ -1736,6 +1955,7 @@ MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);
1736static int qcom_spmi_regulator_probe(struct platform_device *pdev) 1955static int qcom_spmi_regulator_probe(struct platform_device *pdev)
1737{ 1956{
1738 const struct spmi_regulator_data *reg; 1957 const struct spmi_regulator_data *reg;
1958 const struct spmi_voltage_range *range;
1739 const struct of_device_id *match; 1959 const struct of_device_id *match;
1740 struct regulator_config config = { }; 1960 struct regulator_config config = { };
1741 struct regulator_dev *rdev; 1961 struct regulator_dev *rdev;
@@ -1825,6 +2045,12 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
1825 } 2045 }
1826 } 2046 }
1827 2047
2048 if (vreg->set_points && vreg->set_points->count == 1) {
2049 /* since there is only one range */
2050 range = vreg->set_points->range;
2051 vreg->desc.uV_step = range->step_uV;
2052 }
2053
1828 config.dev = dev; 2054 config.dev = dev;
1829 config.driver_data = vreg; 2055 config.driver_data = vreg;
1830 config.regmap = regmap; 2056 config.regmap = regmap;
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 134c62db36c5..054baaadfdfd 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -34,7 +34,7 @@ struct s2mps11_info {
34 enum sec_device_type dev_type; 34 enum sec_device_type dev_type;
35 35
36 /* 36 /*
37 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether 37 * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
38 * the suspend mode was enabled. 38 * the suspend mode was enabled.
39 */ 39 */
40 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX); 40 DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
@@ -70,10 +70,11 @@ static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
70 unsigned int new_selector) 70 unsigned int new_selector)
71{ 71{
72 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); 72 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
73 int rdev_id = rdev_get_id(rdev);
73 unsigned int ramp_delay = 0; 74 unsigned int ramp_delay = 0;
74 int old_volt, new_volt; 75 int old_volt, new_volt;
75 76
76 switch (rdev_get_id(rdev)) { 77 switch (rdev_id) {
77 case S2MPS11_BUCK2: 78 case S2MPS11_BUCK2:
78 ramp_delay = s2mps11->ramp_delay2; 79 ramp_delay = s2mps11->ramp_delay2;
79 break; 80 break;
@@ -111,9 +112,10 @@ static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
111 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); 112 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
112 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK; 113 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
113 unsigned int ramp_enable = 1, enable_shift = 0; 114 unsigned int ramp_enable = 1, enable_shift = 0;
115 int rdev_id = rdev_get_id(rdev);
114 int ret; 116 int ret;
115 117
116 switch (rdev_get_id(rdev)) { 118 switch (rdev_id) {
117 case S2MPS11_BUCK1: 119 case S2MPS11_BUCK1:
118 if (ramp_delay > s2mps11->ramp_delay16) 120 if (ramp_delay > s2mps11->ramp_delay16)
119 s2mps11->ramp_delay16 = ramp_delay; 121 s2mps11->ramp_delay16 = ramp_delay;
@@ -203,9 +205,8 @@ static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
203 goto ramp_disable; 205 goto ramp_disable;
204 206
205 /* Ramp delay can be enabled/disabled only for buck[2346] */ 207 /* Ramp delay can be enabled/disabled only for buck[2346] */
206 if ((rdev_get_id(rdev) >= S2MPS11_BUCK2 && 208 if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
207 rdev_get_id(rdev) <= S2MPS11_BUCK4) || 209 rdev_id == S2MPS11_BUCK6) {
208 rdev_get_id(rdev) == S2MPS11_BUCK6) {
209 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP, 210 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
210 1 << enable_shift, 1 << enable_shift); 211 1 << enable_shift, 1 << enable_shift);
211 if (ret) { 212 if (ret) {
@@ -224,27 +225,133 @@ ramp_disable:
224 1 << enable_shift, 0); 225 1 << enable_shift, 0);
225} 226}
226 227
228static int s2mps11_regulator_enable(struct regulator_dev *rdev)
229{
230 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
231 int rdev_id = rdev_get_id(rdev);
232 unsigned int val;
233
234 switch (s2mps11->dev_type) {
235 case S2MPS11X:
236 if (test_bit(rdev_id, s2mps11->suspend_state))
237 val = S2MPS14_ENABLE_SUSPEND;
238 else
239 val = rdev->desc->enable_mask;
240 break;
241 case S2MPS13X:
242 case S2MPS14X:
243 if (test_bit(rdev_id, s2mps11->suspend_state))
244 val = S2MPS14_ENABLE_SUSPEND;
245 else if (s2mps11->ext_control_gpiod[rdev_id])
246 val = S2MPS14_ENABLE_EXT_CONTROL;
247 else
248 val = rdev->desc->enable_mask;
249 break;
250 case S2MPU02:
251 if (test_bit(rdev_id, s2mps11->suspend_state))
252 val = S2MPU02_ENABLE_SUSPEND;
253 else
254 val = rdev->desc->enable_mask;
255 break;
256 default:
257 return -EINVAL;
258 }
259
260 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
261 rdev->desc->enable_mask, val);
262}
263
264static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
265{
266 int ret;
267 unsigned int val, state;
268 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
269 int rdev_id = rdev_get_id(rdev);
270
271 /* Below LDO should be always on or does not support suspend mode. */
272 switch (s2mps11->dev_type) {
273 case S2MPS11X:
274 switch (rdev_id) {
275 case S2MPS11_LDO2:
276 case S2MPS11_LDO36:
277 case S2MPS11_LDO37:
278 case S2MPS11_LDO38:
279 return 0;
280 default:
281 state = S2MPS14_ENABLE_SUSPEND;
282 break;
283 }
284 break;
285 case S2MPS13X:
286 case S2MPS14X:
287 switch (rdev_id) {
288 case S2MPS14_LDO3:
289 return 0;
290 default:
291 state = S2MPS14_ENABLE_SUSPEND;
292 break;
293 }
294 break;
295 case S2MPU02:
296 switch (rdev_id) {
297 case S2MPU02_LDO13:
298 case S2MPU02_LDO14:
299 case S2MPU02_LDO15:
300 case S2MPU02_LDO17:
301 case S2MPU02_BUCK7:
302 state = S2MPU02_DISABLE_SUSPEND;
303 break;
304 default:
305 state = S2MPU02_ENABLE_SUSPEND;
306 break;
307 }
308 break;
309 default:
310 return -EINVAL;
311 }
312
313 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
314 if (ret < 0)
315 return ret;
316
317 set_bit(rdev_id, s2mps11->suspend_state);
318 /*
319 * Don't enable suspend mode if regulator is already disabled because
320 * this would effectively for a short time turn on the regulator after
321 * resuming.
322 * However we still want to toggle the suspend_state bit for regulator
323 * in case if it got enabled before suspending the system.
324 */
325 if (!(val & rdev->desc->enable_mask))
326 return 0;
327
328 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
329 rdev->desc->enable_mask, state);
330}
331
227static const struct regulator_ops s2mps11_ldo_ops = { 332static const struct regulator_ops s2mps11_ldo_ops = {
228 .list_voltage = regulator_list_voltage_linear, 333 .list_voltage = regulator_list_voltage_linear,
229 .map_voltage = regulator_map_voltage_linear, 334 .map_voltage = regulator_map_voltage_linear,
230 .is_enabled = regulator_is_enabled_regmap, 335 .is_enabled = regulator_is_enabled_regmap,
231 .enable = regulator_enable_regmap, 336 .enable = s2mps11_regulator_enable,
232 .disable = regulator_disable_regmap, 337 .disable = regulator_disable_regmap,
233 .get_voltage_sel = regulator_get_voltage_sel_regmap, 338 .get_voltage_sel = regulator_get_voltage_sel_regmap,
234 .set_voltage_sel = regulator_set_voltage_sel_regmap, 339 .set_voltage_sel = regulator_set_voltage_sel_regmap,
235 .set_voltage_time_sel = regulator_set_voltage_time_sel, 340 .set_voltage_time_sel = regulator_set_voltage_time_sel,
341 .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
236}; 342};
237 343
238static const struct regulator_ops s2mps11_buck_ops = { 344static const struct regulator_ops s2mps11_buck_ops = {
239 .list_voltage = regulator_list_voltage_linear, 345 .list_voltage = regulator_list_voltage_linear,
240 .map_voltage = regulator_map_voltage_linear, 346 .map_voltage = regulator_map_voltage_linear,
241 .is_enabled = regulator_is_enabled_regmap, 347 .is_enabled = regulator_is_enabled_regmap,
242 .enable = regulator_enable_regmap, 348 .enable = s2mps11_regulator_enable,
243 .disable = regulator_disable_regmap, 349 .disable = regulator_disable_regmap,
244 .get_voltage_sel = regulator_get_voltage_sel_regmap, 350 .get_voltage_sel = regulator_get_voltage_sel_regmap,
245 .set_voltage_sel = regulator_set_voltage_sel_regmap, 351 .set_voltage_sel = regulator_set_voltage_sel_regmap,
246 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel, 352 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
247 .set_ramp_delay = s2mps11_set_ramp_delay, 353 .set_ramp_delay = s2mps11_set_ramp_delay,
354 .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
248}; 355};
249 356
250#define regulator_desc_s2mps11_ldo(num, step) { \ 357#define regulator_desc_s2mps11_ldo(num, step) { \
@@ -269,9 +376,10 @@ static const struct regulator_ops s2mps11_buck_ops = {
269 .ops = &s2mps11_buck_ops, \ 376 .ops = &s2mps11_buck_ops, \
270 .type = REGULATOR_VOLTAGE, \ 377 .type = REGULATOR_VOLTAGE, \
271 .owner = THIS_MODULE, \ 378 .owner = THIS_MODULE, \
272 .min_uV = MIN_600_MV, \ 379 .min_uV = MIN_650_MV, \
273 .uV_step = STEP_6_25_MV, \ 380 .uV_step = STEP_6_25_MV, \
274 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ 381 .linear_min_sel = 8, \
382 .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \
275 .ramp_delay = S2MPS11_RAMP_DELAY, \ 383 .ramp_delay = S2MPS11_RAMP_DELAY, \
276 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \ 384 .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
277 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ 385 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
@@ -285,9 +393,10 @@ static const struct regulator_ops s2mps11_buck_ops = {
285 .ops = &s2mps11_buck_ops, \ 393 .ops = &s2mps11_buck_ops, \
286 .type = REGULATOR_VOLTAGE, \ 394 .type = REGULATOR_VOLTAGE, \
287 .owner = THIS_MODULE, \ 395 .owner = THIS_MODULE, \
288 .min_uV = MIN_600_MV, \ 396 .min_uV = MIN_650_MV, \
289 .uV_step = STEP_6_25_MV, \ 397 .uV_step = STEP_6_25_MV, \
290 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ 398 .linear_min_sel = 8, \
399 .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \
291 .ramp_delay = S2MPS11_RAMP_DELAY, \ 400 .ramp_delay = S2MPS11_RAMP_DELAY, \
292 .vsel_reg = S2MPS11_REG_B5CTRL2, \ 401 .vsel_reg = S2MPS11_REG_B5CTRL2, \
293 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ 402 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
@@ -295,7 +404,7 @@ static const struct regulator_ops s2mps11_buck_ops = {
295 .enable_mask = S2MPS11_ENABLE_MASK \ 404 .enable_mask = S2MPS11_ENABLE_MASK \
296} 405}
297 406
298#define regulator_desc_s2mps11_buck67810(num, min, step) { \ 407#define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \
299 .name = "BUCK"#num, \ 408 .name = "BUCK"#num, \
300 .id = S2MPS11_BUCK##num, \ 409 .id = S2MPS11_BUCK##num, \
301 .ops = &s2mps11_buck_ops, \ 410 .ops = &s2mps11_buck_ops, \
@@ -303,7 +412,8 @@ static const struct regulator_ops s2mps11_buck_ops = {
303 .owner = THIS_MODULE, \ 412 .owner = THIS_MODULE, \
304 .min_uV = min, \ 413 .min_uV = min, \
305 .uV_step = step, \ 414 .uV_step = step, \
306 .n_voltages = S2MPS11_BUCK_N_VOLTAGES, \ 415 .linear_min_sel = min_sel, \
416 .n_voltages = voltages, \
307 .ramp_delay = S2MPS11_RAMP_DELAY, \ 417 .ramp_delay = S2MPS11_RAMP_DELAY, \
308 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \ 418 .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
309 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \ 419 .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
@@ -371,11 +481,15 @@ static const struct regulator_desc s2mps11_regulators[] = {
371 regulator_desc_s2mps11_buck1_4(3), 481 regulator_desc_s2mps11_buck1_4(3),
372 regulator_desc_s2mps11_buck1_4(4), 482 regulator_desc_s2mps11_buck1_4(4),
373 regulator_desc_s2mps11_buck5, 483 regulator_desc_s2mps11_buck5,
374 regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV), 484 regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
375 regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_12_5_MV), 485 S2MPS11_BUCK12346_N_VOLTAGES),
376 regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_12_5_MV), 486 regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
487 S2MPS11_BUCK7810_N_VOLTAGES),
488 regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
489 S2MPS11_BUCK7810_N_VOLTAGES),
377 regulator_desc_s2mps11_buck9, 490 regulator_desc_s2mps11_buck9,
378 regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV), 491 regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
492 S2MPS11_BUCK7810_N_VOLTAGES),
379}; 493};
380 494
381static const struct regulator_ops s2mps14_reg_ops; 495static const struct regulator_ops s2mps14_reg_ops;
@@ -500,101 +614,16 @@ static const struct regulator_desc s2mps13_regulators[] = {
500 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10), 614 regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
501}; 615};
502 616
503static int s2mps14_regulator_enable(struct regulator_dev *rdev)
504{
505 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
506 unsigned int val;
507
508 switch (s2mps11->dev_type) {
509 case S2MPS13X:
510 case S2MPS14X:
511 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
512 val = S2MPS14_ENABLE_SUSPEND;
513 else if (s2mps11->ext_control_gpiod[rdev_get_id(rdev)])
514 val = S2MPS14_ENABLE_EXT_CONTROL;
515 else
516 val = rdev->desc->enable_mask;
517 break;
518 case S2MPU02:
519 if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
520 val = S2MPU02_ENABLE_SUSPEND;
521 else
522 val = rdev->desc->enable_mask;
523 break;
524 default:
525 return -EINVAL;
526 }
527
528 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
529 rdev->desc->enable_mask, val);
530}
531
532static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
533{
534 int ret;
535 unsigned int val, state;
536 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
537 int rdev_id = rdev_get_id(rdev);
538
539 /* Below LDO should be always on or does not support suspend mode. */
540 switch (s2mps11->dev_type) {
541 case S2MPS13X:
542 case S2MPS14X:
543 switch (rdev_id) {
544 case S2MPS14_LDO3:
545 return 0;
546 default:
547 state = S2MPS14_ENABLE_SUSPEND;
548 break;
549 }
550 break;
551 case S2MPU02:
552 switch (rdev_id) {
553 case S2MPU02_LDO13:
554 case S2MPU02_LDO14:
555 case S2MPU02_LDO15:
556 case S2MPU02_LDO17:
557 case S2MPU02_BUCK7:
558 state = S2MPU02_DISABLE_SUSPEND;
559 break;
560 default:
561 state = S2MPU02_ENABLE_SUSPEND;
562 break;
563 }
564 break;
565 default:
566 return -EINVAL;
567 }
568
569 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
570 if (ret < 0)
571 return ret;
572
573 set_bit(rdev_get_id(rdev), s2mps11->suspend_state);
574 /*
575 * Don't enable suspend mode if regulator is already disabled because
576 * this would effectively for a short time turn on the regulator after
577 * resuming.
578 * However we still want to toggle the suspend_state bit for regulator
579 * in case if it got enabled before suspending the system.
580 */
581 if (!(val & rdev->desc->enable_mask))
582 return 0;
583
584 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
585 rdev->desc->enable_mask, state);
586}
587
588static const struct regulator_ops s2mps14_reg_ops = { 617static const struct regulator_ops s2mps14_reg_ops = {
589 .list_voltage = regulator_list_voltage_linear, 618 .list_voltage = regulator_list_voltage_linear,
590 .map_voltage = regulator_map_voltage_linear, 619 .map_voltage = regulator_map_voltage_linear,
591 .is_enabled = regulator_is_enabled_regmap, 620 .is_enabled = regulator_is_enabled_regmap,
592 .enable = s2mps14_regulator_enable, 621 .enable = s2mps11_regulator_enable,
593 .disable = regulator_disable_regmap, 622 .disable = regulator_disable_regmap,
594 .get_voltage_sel = regulator_get_voltage_sel_regmap, 623 .get_voltage_sel = regulator_get_voltage_sel_regmap,
595 .set_voltage_sel = regulator_set_voltage_sel_regmap, 624 .set_voltage_sel = regulator_set_voltage_sel_regmap,
596 .set_voltage_time_sel = regulator_set_voltage_time_sel, 625 .set_voltage_time_sel = regulator_set_voltage_time_sel,
597 .set_suspend_disable = s2mps14_regulator_set_suspend_disable, 626 .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
598}; 627};
599 628
600#define regulator_desc_s2mps14_ldo(num, min, step) { \ 629#define regulator_desc_s2mps14_ldo(num, min, step) { \
@@ -821,9 +850,12 @@ static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
821 0, 850 0,
822 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, 851 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
823 "s2mps11-regulator"); 852 "s2mps11-regulator");
824 if (IS_ERR(gpio[reg])) { 853 if (PTR_ERR(gpio[reg]) == -ENOENT)
854 gpio[reg] = NULL;
855 else if (IS_ERR(gpio[reg])) {
825 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n", 856 dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
826 reg, rdata[reg].name); 857 reg, rdata[reg].name);
858 gpio[reg] = NULL;
827 continue; 859 continue;
828 } 860 }
829 if (gpio[reg]) 861 if (gpio[reg])
@@ -856,8 +888,9 @@ static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
856static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) 888static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
857{ 889{
858 unsigned int ramp_val, ramp_shift, ramp_reg; 890 unsigned int ramp_val, ramp_shift, ramp_reg;
891 int rdev_id = rdev_get_id(rdev);
859 892
860 switch (rdev_get_id(rdev)) { 893 switch (rdev_id) {
861 case S2MPU02_BUCK1: 894 case S2MPU02_BUCK1:
862 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT; 895 ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
863 break; 896 break;
@@ -885,24 +918,24 @@ static const struct regulator_ops s2mpu02_ldo_ops = {
885 .list_voltage = regulator_list_voltage_linear, 918 .list_voltage = regulator_list_voltage_linear,
886 .map_voltage = regulator_map_voltage_linear, 919 .map_voltage = regulator_map_voltage_linear,
887 .is_enabled = regulator_is_enabled_regmap, 920 .is_enabled = regulator_is_enabled_regmap,
888 .enable = s2mps14_regulator_enable, 921 .enable = s2mps11_regulator_enable,
889 .disable = regulator_disable_regmap, 922 .disable = regulator_disable_regmap,
890 .get_voltage_sel = regulator_get_voltage_sel_regmap, 923 .get_voltage_sel = regulator_get_voltage_sel_regmap,
891 .set_voltage_sel = regulator_set_voltage_sel_regmap, 924 .set_voltage_sel = regulator_set_voltage_sel_regmap,
892 .set_voltage_time_sel = regulator_set_voltage_time_sel, 925 .set_voltage_time_sel = regulator_set_voltage_time_sel,
893 .set_suspend_disable = s2mps14_regulator_set_suspend_disable, 926 .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
894}; 927};
895 928
896static const struct regulator_ops s2mpu02_buck_ops = { 929static const struct regulator_ops s2mpu02_buck_ops = {
897 .list_voltage = regulator_list_voltage_linear, 930 .list_voltage = regulator_list_voltage_linear,
898 .map_voltage = regulator_map_voltage_linear, 931 .map_voltage = regulator_map_voltage_linear,
899 .is_enabled = regulator_is_enabled_regmap, 932 .is_enabled = regulator_is_enabled_regmap,
900 .enable = s2mps14_regulator_enable, 933 .enable = s2mps11_regulator_enable,
901 .disable = regulator_disable_regmap, 934 .disable = regulator_disable_regmap,
902 .get_voltage_sel = regulator_get_voltage_sel_regmap, 935 .get_voltage_sel = regulator_get_voltage_sel_regmap,
903 .set_voltage_sel = regulator_set_voltage_sel_regmap, 936 .set_voltage_sel = regulator_set_voltage_sel_regmap,
904 .set_voltage_time_sel = regulator_set_voltage_time_sel, 937 .set_voltage_time_sel = regulator_set_voltage_time_sel,
905 .set_suspend_disable = s2mps14_regulator_set_suspend_disable, 938 .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
906 .set_ramp_delay = s2mpu02_set_ramp_delay, 939 .set_ramp_delay = s2mpu02_set_ramp_delay,
907}; 940};
908 941
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index bb9d1a083299..6ca27e9d5ef7 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -574,7 +574,9 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
574 0, 574 0,
575 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, 575 GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
576 "s5m8767"); 576 "s5m8767");
577 if (IS_ERR(rdata->ext_control_gpiod)) 577 if (PTR_ERR(rdata->ext_control_gpiod) == -ENOENT)
578 rdata->ext_control_gpiod = NULL;
579 else if (IS_ERR(rdata->ext_control_gpiod))
578 return PTR_ERR(rdata->ext_control_gpiod); 580 return PTR_ERR(rdata->ext_control_gpiod);
579 581
580 rdata->id = i; 582 rdata->id = i;
diff --git a/drivers/regulator/slg51000-regulator.c b/drivers/regulator/slg51000-regulator.c
new file mode 100644
index 000000000000..04b732991d69
--- /dev/null
+++ b/drivers/regulator/slg51000-regulator.c
@@ -0,0 +1,523 @@
1// SPDX-License-Identifier: GPL-2.0+
2//
3// SLG51000 High PSRR, Multi-Output Regulators
4// Copyright (C) 2019 Dialog Semiconductor
5//
6// Author: Eric Jeong <eric.jeong.opensource@diasemi.com>
7
8#include <linux/err.h>
9#include <linux/gpio/consumer.h>
10#include <linux/i2c.h>
11#include <linux/init.h>
12#include <linux/interrupt.h>
13#include <linux/irq.h>
14#include <linux/module.h>
15#include <linux/of.h>
16#include <linux/regmap.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
19#include <linux/regulator/of_regulator.h>
20#include "slg51000-regulator.h"
21
22#define SLG51000_SCTL_EVT 7
23#define SLG51000_MAX_EVT_REGISTER 8
24#define SLG51000_LDOHP_LV_MIN 1200000
25#define SLG51000_LDOHP_HV_MIN 2400000
26
27enum slg51000_regulators {
28 SLG51000_REGULATOR_LDO1 = 0,
29 SLG51000_REGULATOR_LDO2,
30 SLG51000_REGULATOR_LDO3,
31 SLG51000_REGULATOR_LDO4,
32 SLG51000_REGULATOR_LDO5,
33 SLG51000_REGULATOR_LDO6,
34 SLG51000_REGULATOR_LDO7,
35 SLG51000_MAX_REGULATORS,
36};
37
38struct slg51000 {
39 struct device *dev;
40 struct regmap *regmap;
41 struct regulator_desc *rdesc[SLG51000_MAX_REGULATORS];
42 struct regulator_dev *rdev[SLG51000_MAX_REGULATORS];
43 struct gpio_desc *cs_gpiod;
44 int chip_irq;
45};
46
47struct slg51000_evt_sta {
48 unsigned int ereg;
49 unsigned int sreg;
50};
51
52static const struct slg51000_evt_sta es_reg[SLG51000_MAX_EVT_REGISTER] = {
53 {SLG51000_LDO1_EVENT, SLG51000_LDO1_STATUS},
54 {SLG51000_LDO2_EVENT, SLG51000_LDO2_STATUS},
55 {SLG51000_LDO3_EVENT, SLG51000_LDO3_STATUS},
56 {SLG51000_LDO4_EVENT, SLG51000_LDO4_STATUS},
57 {SLG51000_LDO5_EVENT, SLG51000_LDO5_STATUS},
58 {SLG51000_LDO6_EVENT, SLG51000_LDO6_STATUS},
59 {SLG51000_LDO7_EVENT, SLG51000_LDO7_STATUS},
60 {SLG51000_SYSCTL_EVENT, SLG51000_SYSCTL_STATUS},
61};
62
63static const struct regmap_range slg51000_writeable_ranges[] = {
64 regmap_reg_range(SLG51000_SYSCTL_MATRIX_CONF_A,
65 SLG51000_SYSCTL_MATRIX_CONF_A),
66 regmap_reg_range(SLG51000_LDO1_VSEL, SLG51000_LDO1_VSEL),
67 regmap_reg_range(SLG51000_LDO1_MINV, SLG51000_LDO1_MAXV),
68 regmap_reg_range(SLG51000_LDO1_IRQ_MASK, SLG51000_LDO1_IRQ_MASK),
69 regmap_reg_range(SLG51000_LDO2_VSEL, SLG51000_LDO2_VSEL),
70 regmap_reg_range(SLG51000_LDO2_MINV, SLG51000_LDO2_MAXV),
71 regmap_reg_range(SLG51000_LDO2_IRQ_MASK, SLG51000_LDO2_IRQ_MASK),
72 regmap_reg_range(SLG51000_LDO3_VSEL, SLG51000_LDO3_VSEL),
73 regmap_reg_range(SLG51000_LDO3_MINV, SLG51000_LDO3_MAXV),
74 regmap_reg_range(SLG51000_LDO3_IRQ_MASK, SLG51000_LDO3_IRQ_MASK),
75 regmap_reg_range(SLG51000_LDO4_VSEL, SLG51000_LDO4_VSEL),
76 regmap_reg_range(SLG51000_LDO4_MINV, SLG51000_LDO4_MAXV),
77 regmap_reg_range(SLG51000_LDO4_IRQ_MASK, SLG51000_LDO4_IRQ_MASK),
78 regmap_reg_range(SLG51000_LDO5_VSEL, SLG51000_LDO5_VSEL),
79 regmap_reg_range(SLG51000_LDO5_MINV, SLG51000_LDO5_MAXV),
80 regmap_reg_range(SLG51000_LDO5_IRQ_MASK, SLG51000_LDO5_IRQ_MASK),
81 regmap_reg_range(SLG51000_LDO6_VSEL, SLG51000_LDO6_VSEL),
82 regmap_reg_range(SLG51000_LDO6_MINV, SLG51000_LDO6_MAXV),
83 regmap_reg_range(SLG51000_LDO6_IRQ_MASK, SLG51000_LDO6_IRQ_MASK),
84 regmap_reg_range(SLG51000_LDO7_VSEL, SLG51000_LDO7_VSEL),
85 regmap_reg_range(SLG51000_LDO7_MINV, SLG51000_LDO7_MAXV),
86 regmap_reg_range(SLG51000_LDO7_IRQ_MASK, SLG51000_LDO7_IRQ_MASK),
87 regmap_reg_range(SLG51000_OTP_IRQ_MASK, SLG51000_OTP_IRQ_MASK),
88};
89
90static const struct regmap_range slg51000_readable_ranges[] = {
91 regmap_reg_range(SLG51000_SYSCTL_PATN_ID_B0,
92 SLG51000_SYSCTL_PATN_ID_B2),
93 regmap_reg_range(SLG51000_SYSCTL_SYS_CONF_A,
94 SLG51000_SYSCTL_SYS_CONF_A),
95 regmap_reg_range(SLG51000_SYSCTL_SYS_CONF_D,
96 SLG51000_SYSCTL_MATRIX_CONF_B),
97 regmap_reg_range(SLG51000_SYSCTL_REFGEN_CONF_C,
98 SLG51000_SYSCTL_UVLO_CONF_A),
99 regmap_reg_range(SLG51000_SYSCTL_FAULT_LOG1, SLG51000_SYSCTL_IRQ_MASK),
100 regmap_reg_range(SLG51000_IO_GPIO1_CONF, SLG51000_IO_GPIO_STATUS),
101 regmap_reg_range(SLG51000_LUTARRAY_LUT_VAL_0,
102 SLG51000_LUTARRAY_LUT_VAL_11),
103 regmap_reg_range(SLG51000_MUXARRAY_INPUT_SEL_0,
104 SLG51000_MUXARRAY_INPUT_SEL_63),
105 regmap_reg_range(SLG51000_PWRSEQ_RESOURCE_EN_0,
106 SLG51000_PWRSEQ_INPUT_SENSE_CONF_B),
107 regmap_reg_range(SLG51000_LDO1_VSEL, SLG51000_LDO1_VSEL),
108 regmap_reg_range(SLG51000_LDO1_MINV, SLG51000_LDO1_MAXV),
109 regmap_reg_range(SLG51000_LDO1_MISC1, SLG51000_LDO1_VSEL_ACTUAL),
110 regmap_reg_range(SLG51000_LDO1_EVENT, SLG51000_LDO1_IRQ_MASK),
111 regmap_reg_range(SLG51000_LDO2_VSEL, SLG51000_LDO2_VSEL),
112 regmap_reg_range(SLG51000_LDO2_MINV, SLG51000_LDO2_MAXV),
113 regmap_reg_range(SLG51000_LDO2_MISC1, SLG51000_LDO2_VSEL_ACTUAL),
114 regmap_reg_range(SLG51000_LDO2_EVENT, SLG51000_LDO2_IRQ_MASK),
115 regmap_reg_range(SLG51000_LDO3_VSEL, SLG51000_LDO3_VSEL),
116 regmap_reg_range(SLG51000_LDO3_MINV, SLG51000_LDO3_MAXV),
117 regmap_reg_range(SLG51000_LDO3_CONF1, SLG51000_LDO3_VSEL_ACTUAL),
118 regmap_reg_range(SLG51000_LDO3_EVENT, SLG51000_LDO3_IRQ_MASK),
119 regmap_reg_range(SLG51000_LDO4_VSEL, SLG51000_LDO4_VSEL),
120 regmap_reg_range(SLG51000_LDO4_MINV, SLG51000_LDO4_MAXV),
121 regmap_reg_range(SLG51000_LDO4_CONF1, SLG51000_LDO4_VSEL_ACTUAL),
122 regmap_reg_range(SLG51000_LDO4_EVENT, SLG51000_LDO4_IRQ_MASK),
123 regmap_reg_range(SLG51000_LDO5_VSEL, SLG51000_LDO5_VSEL),
124 regmap_reg_range(SLG51000_LDO5_MINV, SLG51000_LDO5_MAXV),
125 regmap_reg_range(SLG51000_LDO5_TRIM2, SLG51000_LDO5_TRIM2),
126 regmap_reg_range(SLG51000_LDO5_CONF1, SLG51000_LDO5_VSEL_ACTUAL),
127 regmap_reg_range(SLG51000_LDO5_EVENT, SLG51000_LDO5_IRQ_MASK),
128 regmap_reg_range(SLG51000_LDO6_VSEL, SLG51000_LDO6_VSEL),
129 regmap_reg_range(SLG51000_LDO6_MINV, SLG51000_LDO6_MAXV),
130 regmap_reg_range(SLG51000_LDO6_TRIM2, SLG51000_LDO6_TRIM2),
131 regmap_reg_range(SLG51000_LDO6_CONF1, SLG51000_LDO6_VSEL_ACTUAL),
132 regmap_reg_range(SLG51000_LDO6_EVENT, SLG51000_LDO6_IRQ_MASK),
133 regmap_reg_range(SLG51000_LDO7_VSEL, SLG51000_LDO7_VSEL),
134 regmap_reg_range(SLG51000_LDO7_MINV, SLG51000_LDO7_MAXV),
135 regmap_reg_range(SLG51000_LDO7_CONF1, SLG51000_LDO7_VSEL_ACTUAL),
136 regmap_reg_range(SLG51000_LDO7_EVENT, SLG51000_LDO7_IRQ_MASK),
137 regmap_reg_range(SLG51000_OTP_EVENT, SLG51000_OTP_EVENT),
138 regmap_reg_range(SLG51000_OTP_IRQ_MASK, SLG51000_OTP_IRQ_MASK),
139 regmap_reg_range(SLG51000_OTP_LOCK_OTP_PROG, SLG51000_OTP_LOCK_CTRL),
140 regmap_reg_range(SLG51000_LOCK_GLOBAL_LOCK_CTRL1,
141 SLG51000_LOCK_GLOBAL_LOCK_CTRL1),
142};
143
144static const struct regmap_range slg51000_volatile_ranges[] = {
145 regmap_reg_range(SLG51000_SYSCTL_FAULT_LOG1, SLG51000_SYSCTL_STATUS),
146 regmap_reg_range(SLG51000_IO_GPIO_STATUS, SLG51000_IO_GPIO_STATUS),
147 regmap_reg_range(SLG51000_LDO1_EVENT, SLG51000_LDO1_STATUS),
148 regmap_reg_range(SLG51000_LDO2_EVENT, SLG51000_LDO2_STATUS),
149 regmap_reg_range(SLG51000_LDO3_EVENT, SLG51000_LDO3_STATUS),
150 regmap_reg_range(SLG51000_LDO4_EVENT, SLG51000_LDO4_STATUS),
151 regmap_reg_range(SLG51000_LDO5_EVENT, SLG51000_LDO5_STATUS),
152 regmap_reg_range(SLG51000_LDO6_EVENT, SLG51000_LDO6_STATUS),
153 regmap_reg_range(SLG51000_LDO7_EVENT, SLG51000_LDO7_STATUS),
154 regmap_reg_range(SLG51000_OTP_EVENT, SLG51000_OTP_EVENT),
155};
156
157static const struct regmap_access_table slg51000_writeable_table = {
158 .yes_ranges = slg51000_writeable_ranges,
159 .n_yes_ranges = ARRAY_SIZE(slg51000_writeable_ranges),
160};
161
162static const struct regmap_access_table slg51000_readable_table = {
163 .yes_ranges = slg51000_readable_ranges,
164 .n_yes_ranges = ARRAY_SIZE(slg51000_readable_ranges),
165};
166
167static const struct regmap_access_table slg51000_volatile_table = {
168 .yes_ranges = slg51000_volatile_ranges,
169 .n_yes_ranges = ARRAY_SIZE(slg51000_volatile_ranges),
170};
171
172static const struct regmap_config slg51000_regmap_config = {
173 .reg_bits = 16,
174 .val_bits = 8,
175 .max_register = 0x8000,
176 .wr_table = &slg51000_writeable_table,
177 .rd_table = &slg51000_readable_table,
178 .volatile_table = &slg51000_volatile_table,
179};
180
181static const struct regulator_ops slg51000_regl_ops = {
182 .enable = regulator_enable_regmap,
183 .disable = regulator_disable_regmap,
184 .is_enabled = regulator_is_enabled_regmap,
185 .list_voltage = regulator_list_voltage_linear,
186 .map_voltage = regulator_map_voltage_linear,
187 .get_voltage_sel = regulator_get_voltage_sel_regmap,
188 .set_voltage_sel = regulator_set_voltage_sel_regmap,
189};
190
191static const struct regulator_ops slg51000_switch_ops = {
192 .enable = regulator_enable_regmap,
193 .disable = regulator_disable_regmap,
194 .is_enabled = regulator_is_enabled_regmap,
195};
196
197static int slg51000_of_parse_cb(struct device_node *np,
198 const struct regulator_desc *desc,
199 struct regulator_config *config)
200{
201 struct slg51000 *chip = config->driver_data;
202 struct gpio_desc *ena_gpiod;
203 enum gpiod_flags gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE;
204
205 ena_gpiod = devm_gpiod_get_from_of_node(chip->dev, np,
206 "enable-gpios", 0,
207 gflags, "gpio-en-ldo");
208 if (ena_gpiod) {
209 config->ena_gpiod = ena_gpiod;
210 devm_gpiod_unhinge(chip->dev, config->ena_gpiod);
211 }
212
213 return 0;
214}
215
216#define SLG51000_REGL_DESC(_id, _name, _s_name, _min, _step) \
217 [SLG51000_REGULATOR_##_id] = { \
218 .name = #_name, \
219 .supply_name = _s_name, \
220 .id = SLG51000_REGULATOR_##_id, \
221 .of_match = of_match_ptr(#_name), \
222 .of_parse_cb = slg51000_of_parse_cb, \
223 .ops = &slg51000_regl_ops, \
224 .regulators_node = of_match_ptr("regulators"), \
225 .n_voltages = 256, \
226 .min_uV = _min, \
227 .uV_step = _step, \
228 .linear_min_sel = 0, \
229 .vsel_mask = SLG51000_VSEL_MASK, \
230 .vsel_reg = SLG51000_##_id##_VSEL, \
231 .enable_reg = SLG51000_SYSCTL_MATRIX_CONF_A, \
232 .enable_mask = BIT(SLG51000_REGULATOR_##_id), \
233 .type = REGULATOR_VOLTAGE, \
234 .owner = THIS_MODULE, \
235 }
236
237static struct regulator_desc regls_desc[SLG51000_MAX_REGULATORS] = {
238 SLG51000_REGL_DESC(LDO1, ldo1, NULL, 2400000, 5000),
239 SLG51000_REGL_DESC(LDO2, ldo2, NULL, 2400000, 5000),
240 SLG51000_REGL_DESC(LDO3, ldo3, "vin3", 1200000, 10000),
241 SLG51000_REGL_DESC(LDO4, ldo4, "vin4", 1200000, 10000),
242 SLG51000_REGL_DESC(LDO5, ldo5, "vin5", 400000, 5000),
243 SLG51000_REGL_DESC(LDO6, ldo6, "vin6", 400000, 5000),
244 SLG51000_REGL_DESC(LDO7, ldo7, "vin7", 1200000, 10000),
245};
246
247static int slg51000_regulator_init(struct slg51000 *chip)
248{
249 struct regulator_config config = { };
250 struct regulator_desc *rdesc;
251 unsigned int reg, val;
252 u8 vsel_range[2];
253 int id, ret = 0;
254 const unsigned int min_regs[SLG51000_MAX_REGULATORS] = {
255 SLG51000_LDO1_MINV, SLG51000_LDO2_MINV, SLG51000_LDO3_MINV,
256 SLG51000_LDO4_MINV, SLG51000_LDO5_MINV, SLG51000_LDO6_MINV,
257 SLG51000_LDO7_MINV,
258 };
259
260 for (id = 0; id < SLG51000_MAX_REGULATORS; id++) {
261 chip->rdesc[id] = &regls_desc[id];
262 rdesc = chip->rdesc[id];
263 config.regmap = chip->regmap;
264 config.dev = chip->dev;
265 config.driver_data = chip;
266
267 ret = regmap_bulk_read(chip->regmap, min_regs[id],
268 vsel_range, 2);
269 if (ret < 0) {
270 dev_err(chip->dev,
271 "Failed to read the MIN register\n");
272 return ret;
273 }
274
275 switch (id) {
276 case SLG51000_REGULATOR_LDO1:
277 case SLG51000_REGULATOR_LDO2:
278 if (id == SLG51000_REGULATOR_LDO1)
279 reg = SLG51000_LDO1_MISC1;
280 else
281 reg = SLG51000_LDO2_MISC1;
282
283 ret = regmap_read(chip->regmap, reg, &val);
284 if (ret < 0) {
285 dev_err(chip->dev,
286 "Failed to read voltage range of ldo%d\n",
287 id + 1);
288 return ret;
289 }
290
291 rdesc->linear_min_sel = vsel_range[0];
292 rdesc->n_voltages = vsel_range[1] + 1;
293 if (val & SLG51000_SEL_VRANGE_MASK)
294 rdesc->min_uV = SLG51000_LDOHP_HV_MIN
295 + (vsel_range[0]
296 * rdesc->uV_step);
297 else
298 rdesc->min_uV = SLG51000_LDOHP_LV_MIN
299 + (vsel_range[0]
300 * rdesc->uV_step);
301 break;
302
303 case SLG51000_REGULATOR_LDO5:
304 case SLG51000_REGULATOR_LDO6:
305 if (id == SLG51000_REGULATOR_LDO5)
306 reg = SLG51000_LDO5_TRIM2;
307 else
308 reg = SLG51000_LDO6_TRIM2;
309
310 ret = regmap_read(chip->regmap, reg, &val);
311 if (ret < 0) {
312 dev_err(chip->dev,
313 "Failed to read LDO mode register\n");
314 return ret;
315 }
316
317 if (val & SLG51000_SEL_BYP_MODE_MASK) {
318 rdesc->ops = &slg51000_switch_ops;
319 rdesc->n_voltages = 0;
320 rdesc->min_uV = 0;
321 rdesc->uV_step = 0;
322 rdesc->linear_min_sel = 0;
323 break;
324 }
325 /* Fall through - to the check below.*/
326
327 default:
328 rdesc->linear_min_sel = vsel_range[0];
329 rdesc->n_voltages = vsel_range[1] + 1;
330 rdesc->min_uV = rdesc->min_uV
331 + (vsel_range[0] * rdesc->uV_step);
332 break;
333 }
334
335 chip->rdev[id] = devm_regulator_register(chip->dev, rdesc,
336 &config);
337 if (IS_ERR(chip->rdev[id])) {
338 ret = PTR_ERR(chip->rdev[id]);
339 dev_err(chip->dev,
340 "Failed to register regulator(%s):%d\n",
341 chip->rdesc[id]->name, ret);
342 return ret;
343 }
344 }
345
346 return 0;
347}
348
349static irqreturn_t slg51000_irq_handler(int irq, void *data)
350{
351 struct slg51000 *chip = data;
352 struct regmap *regmap = chip->regmap;
353 enum { R0 = 0, R1, R2, REG_MAX };
354 u8 evt[SLG51000_MAX_EVT_REGISTER][REG_MAX];
355 int ret, i, handled = IRQ_NONE;
356 unsigned int evt_otp, mask_otp;
357
358 /* Read event[R0], status[R1] and mask[R2] register */
359 for (i = 0; i < SLG51000_MAX_EVT_REGISTER; i++) {
360 ret = regmap_bulk_read(regmap, es_reg[i].ereg, evt[i], REG_MAX);
361 if (ret < 0) {
362 dev_err(chip->dev,
363 "Failed to read event registers(%d)\n", ret);
364 return IRQ_NONE;
365 }
366 }
367
368 ret = regmap_read(regmap, SLG51000_OTP_EVENT, &evt_otp);
369 if (ret < 0) {
370 dev_err(chip->dev,
371 "Failed to read otp event registers(%d)\n", ret);
372 return IRQ_NONE;
373 }
374
375 ret = regmap_read(regmap, SLG51000_OTP_IRQ_MASK, &mask_otp);
376 if (ret < 0) {
377 dev_err(chip->dev,
378 "Failed to read otp mask register(%d)\n", ret);
379 return IRQ_NONE;
380 }
381
382 if ((evt_otp & SLG51000_EVT_CRC_MASK) &&
383 !(mask_otp & SLG51000_IRQ_CRC_MASK)) {
384 dev_info(chip->dev,
385 "OTP has been read or OTP crc is not zero\n");
386 handled = IRQ_HANDLED;
387 }
388
389 for (i = 0; i < SLG51000_MAX_REGULATORS; i++) {
390 if (!(evt[i][R2] & SLG51000_IRQ_ILIM_FLAG_MASK) &&
391 (evt[i][R0] & SLG51000_EVT_ILIM_FLAG_MASK)) {
392 regulator_lock(chip->rdev[i]);
393 regulator_notifier_call_chain(chip->rdev[i],
394 REGULATOR_EVENT_OVER_CURRENT, NULL);
395 regulator_unlock(chip->rdev[i]);
396
397 if (evt[i][R1] & SLG51000_STA_ILIM_FLAG_MASK)
398 dev_warn(chip->dev,
399 "Over-current limit(ldo%d)\n", i + 1);
400 handled = IRQ_HANDLED;
401 }
402 }
403
404 if (!(evt[SLG51000_SCTL_EVT][R2] & SLG51000_IRQ_HIGH_TEMP_WARN_MASK) &&
405 (evt[SLG51000_SCTL_EVT][R0] & SLG51000_EVT_HIGH_TEMP_WARN_MASK)) {
406 for (i = 0; i < SLG51000_MAX_REGULATORS; i++) {
407 if (!(evt[i][R1] & SLG51000_STA_ILIM_FLAG_MASK) &&
408 (evt[i][R1] & SLG51000_STA_VOUT_OK_FLAG_MASK)) {
409 regulator_lock(chip->rdev[i]);
410 regulator_notifier_call_chain(chip->rdev[i],
411 REGULATOR_EVENT_OVER_TEMP, NULL);
412 regulator_unlock(chip->rdev[i]);
413 }
414 }
415 handled = IRQ_HANDLED;
416 if (evt[SLG51000_SCTL_EVT][R1] &
417 SLG51000_STA_HIGH_TEMP_WARN_MASK)
418 dev_warn(chip->dev, "High temperature warning!\n");
419 }
420
421 return handled;
422}
423
424static void slg51000_clear_fault_log(struct slg51000 *chip)
425{
426 unsigned int val = 0;
427 int ret = 0;
428
429 ret = regmap_read(chip->regmap, SLG51000_SYSCTL_FAULT_LOG1, &val);
430 if (ret < 0) {
431 dev_err(chip->dev, "Failed to read Fault log register\n");
432 return;
433 }
434
435 if (val & SLG51000_FLT_OVER_TEMP_MASK)
436 dev_dbg(chip->dev, "Fault log: FLT_OVER_TEMP\n");
437 if (val & SLG51000_FLT_POWER_SEQ_CRASH_REQ_MASK)
438 dev_dbg(chip->dev, "Fault log: FLT_POWER_SEQ_CRASH_REQ\n");
439 if (val & SLG51000_FLT_RST_MASK)
440 dev_dbg(chip->dev, "Fault log: FLT_RST\n");
441 if (val & SLG51000_FLT_POR_MASK)
442 dev_dbg(chip->dev, "Fault log: FLT_POR\n");
443}
444
445static int slg51000_i2c_probe(struct i2c_client *client,
446 const struct i2c_device_id *id)
447{
448 struct device *dev = &client->dev;
449 struct slg51000 *chip;
450 struct gpio_desc *cs_gpiod = NULL;
451 int error, ret;
452
453 chip = devm_kzalloc(dev, sizeof(struct slg51000), GFP_KERNEL);
454 if (!chip)
455 return -ENOMEM;
456
457 cs_gpiod = devm_gpiod_get_from_of_node(dev, dev->of_node,
458 "dlg,cs-gpios", 0,
459 GPIOD_OUT_HIGH
460 | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
461 "slg51000-cs");
462 if (cs_gpiod) {
463 dev_info(dev, "Found chip selector property\n");
464 chip->cs_gpiod = cs_gpiod;
465 }
466
467 i2c_set_clientdata(client, chip);
468 chip->chip_irq = client->irq;
469 chip->dev = dev;
470 chip->regmap = devm_regmap_init_i2c(client, &slg51000_regmap_config);
471 if (IS_ERR(chip->regmap)) {
472 error = PTR_ERR(chip->regmap);
473 dev_err(dev, "Failed to allocate register map: %d\n",
474 error);
475 return error;
476 }
477
478 ret = slg51000_regulator_init(chip);
479 if (ret < 0) {
480 dev_err(chip->dev, "Failed to init regulator(%d)\n", ret);
481 return ret;
482 }
483
484 slg51000_clear_fault_log(chip);
485
486 if (chip->chip_irq) {
487 ret = devm_request_threaded_irq(dev, chip->chip_irq, NULL,
488 slg51000_irq_handler,
489 (IRQF_TRIGGER_HIGH |
490 IRQF_ONESHOT),
491 "slg51000-irq", chip);
492 if (ret != 0) {
493 dev_err(dev, "Failed to request IRQ: %d\n",
494 chip->chip_irq);
495 return ret;
496 }
497 } else {
498 dev_info(dev, "No IRQ configured\n");
499 }
500
501 return ret;
502}
503
504static const struct i2c_device_id slg51000_i2c_id[] = {
505 {"slg51000", 0},
506 {},
507};
508MODULE_DEVICE_TABLE(i2c, slg51000_i2c_id);
509
510static struct i2c_driver slg51000_regulator_driver = {
511 .driver = {
512 .name = "slg51000-regulator",
513 },
514 .probe = slg51000_i2c_probe,
515 .id_table = slg51000_i2c_id,
516};
517
518module_i2c_driver(slg51000_regulator_driver);
519
520MODULE_AUTHOR("Eric Jeong <eric.jeong.opensource@diasemi.com>");
521MODULE_DESCRIPTION("SLG51000 regulator driver");
522MODULE_LICENSE("GPL");
523
diff --git a/drivers/regulator/slg51000-regulator.h b/drivers/regulator/slg51000-regulator.h
new file mode 100644
index 000000000000..20feb7f91942
--- /dev/null
+++ b/drivers/regulator/slg51000-regulator.h
@@ -0,0 +1,505 @@
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * SLG51000 High PSRR, Multi-Output Regulators
4 * Copyright (C) 2019 Dialog Semiconductor
5 *
6 * Author: Eric Jeong <eric.jeong.opensource@diasemi.com>
7 */
8
9#ifndef __SLG51000_REGISTERS_H__
10#define __SLG51000_REGISTERS_H__
11
12/* Registers */
13
14#define SLG51000_SYSCTL_PATN_ID_B0 0x1105
15#define SLG51000_SYSCTL_PATN_ID_B1 0x1106
16#define SLG51000_SYSCTL_PATN_ID_B2 0x1107
17#define SLG51000_SYSCTL_SYS_CONF_A 0x1109
18#define SLG51000_SYSCTL_SYS_CONF_D 0x110c
19#define SLG51000_SYSCTL_MATRIX_CONF_A 0x110d
20#define SLG51000_SYSCTL_MATRIX_CONF_B 0x110e
21#define SLG51000_SYSCTL_REFGEN_CONF_C 0x1111
22#define SLG51000_SYSCTL_UVLO_CONF_A 0x1112
23#define SLG51000_SYSCTL_FAULT_LOG1 0x1115
24#define SLG51000_SYSCTL_EVENT 0x1116
25#define SLG51000_SYSCTL_STATUS 0x1117
26#define SLG51000_SYSCTL_IRQ_MASK 0x1118
27#define SLG51000_IO_GPIO1_CONF 0x1500
28#define SLG51000_IO_GPIO2_CONF 0x1501
29#define SLG51000_IO_GPIO3_CONF 0x1502
30#define SLG51000_IO_GPIO4_CONF 0x1503
31#define SLG51000_IO_GPIO5_CONF 0x1504
32#define SLG51000_IO_GPIO6_CONF 0x1505
33#define SLG51000_IO_GPIO_STATUS 0x1506
34#define SLG51000_LUTARRAY_LUT_VAL_0 0x1600
35#define SLG51000_LUTARRAY_LUT_VAL_1 0x1601
36#define SLG51000_LUTARRAY_LUT_VAL_2 0x1602
37#define SLG51000_LUTARRAY_LUT_VAL_3 0x1603
38#define SLG51000_LUTARRAY_LUT_VAL_4 0x1604
39#define SLG51000_LUTARRAY_LUT_VAL_5 0x1605
40#define SLG51000_LUTARRAY_LUT_VAL_6 0x1606
41#define SLG51000_LUTARRAY_LUT_VAL_7 0x1607
42#define SLG51000_LUTARRAY_LUT_VAL_8 0x1608
43#define SLG51000_LUTARRAY_LUT_VAL_9 0x1609
44#define SLG51000_LUTARRAY_LUT_VAL_10 0x160a
45#define SLG51000_LUTARRAY_LUT_VAL_11 0x160b
46#define SLG51000_MUXARRAY_INPUT_SEL_0 0x1700
47#define SLG51000_MUXARRAY_INPUT_SEL_1 0x1701
48#define SLG51000_MUXARRAY_INPUT_SEL_2 0x1702
49#define SLG51000_MUXARRAY_INPUT_SEL_3 0x1703
50#define SLG51000_MUXARRAY_INPUT_SEL_4 0x1704
51#define SLG51000_MUXARRAY_INPUT_SEL_5 0x1705
52#define SLG51000_MUXARRAY_INPUT_SEL_6 0x1706
53#define SLG51000_MUXARRAY_INPUT_SEL_7 0x1707
54#define SLG51000_MUXARRAY_INPUT_SEL_8 0x1708
55#define SLG51000_MUXARRAY_INPUT_SEL_9 0x1709
56#define SLG51000_MUXARRAY_INPUT_SEL_10 0x170a
57#define SLG51000_MUXARRAY_INPUT_SEL_11 0x170b
58#define SLG51000_MUXARRAY_INPUT_SEL_12 0x170c
59#define SLG51000_MUXARRAY_INPUT_SEL_13 0x170d
60#define SLG51000_MUXARRAY_INPUT_SEL_14 0x170e
61#define SLG51000_MUXARRAY_INPUT_SEL_15 0x170f
62#define SLG51000_MUXARRAY_INPUT_SEL_16 0x1710
63#define SLG51000_MUXARRAY_INPUT_SEL_17 0x1711
64#define SLG51000_MUXARRAY_INPUT_SEL_18 0x1712
65#define SLG51000_MUXARRAY_INPUT_SEL_19 0x1713
66#define SLG51000_MUXARRAY_INPUT_SEL_20 0x1714
67#define SLG51000_MUXARRAY_INPUT_SEL_21 0x1715
68#define SLG51000_MUXARRAY_INPUT_SEL_22 0x1716
69#define SLG51000_MUXARRAY_INPUT_SEL_23 0x1717
70#define SLG51000_MUXARRAY_INPUT_SEL_24 0x1718
71#define SLG51000_MUXARRAY_INPUT_SEL_25 0x1719
72#define SLG51000_MUXARRAY_INPUT_SEL_26 0x171a
73#define SLG51000_MUXARRAY_INPUT_SEL_27 0x171b
74#define SLG51000_MUXARRAY_INPUT_SEL_28 0x171c
75#define SLG51000_MUXARRAY_INPUT_SEL_29 0x171d
76#define SLG51000_MUXARRAY_INPUT_SEL_30 0x171e
77#define SLG51000_MUXARRAY_INPUT_SEL_31 0x171f
78#define SLG51000_MUXARRAY_INPUT_SEL_32 0x1720
79#define SLG51000_MUXARRAY_INPUT_SEL_33 0x1721
80#define SLG51000_MUXARRAY_INPUT_SEL_34 0x1722
81#define SLG51000_MUXARRAY_INPUT_SEL_35 0x1723
82#define SLG51000_MUXARRAY_INPUT_SEL_36 0x1724
83#define SLG51000_MUXARRAY_INPUT_SEL_37 0x1725
84#define SLG51000_MUXARRAY_INPUT_SEL_38 0x1726
85#define SLG51000_MUXARRAY_INPUT_SEL_39 0x1727
86#define SLG51000_MUXARRAY_INPUT_SEL_40 0x1728
87#define SLG51000_MUXARRAY_INPUT_SEL_41 0x1729
88#define SLG51000_MUXARRAY_INPUT_SEL_42 0x172a
89#define SLG51000_MUXARRAY_INPUT_SEL_43 0x172b
90#define SLG51000_MUXARRAY_INPUT_SEL_44 0x172c
91#define SLG51000_MUXARRAY_INPUT_SEL_45 0x172d
92#define SLG51000_MUXARRAY_INPUT_SEL_46 0x172e
93#define SLG51000_MUXARRAY_INPUT_SEL_47 0x172f
94#define SLG51000_MUXARRAY_INPUT_SEL_48 0x1730
95#define SLG51000_MUXARRAY_INPUT_SEL_49 0x1731
96#define SLG51000_MUXARRAY_INPUT_SEL_50 0x1732
97#define SLG51000_MUXARRAY_INPUT_SEL_51 0x1733
98#define SLG51000_MUXARRAY_INPUT_SEL_52 0x1734
99#define SLG51000_MUXARRAY_INPUT_SEL_53 0x1735
100#define SLG51000_MUXARRAY_INPUT_SEL_54 0x1736
101#define SLG51000_MUXARRAY_INPUT_SEL_55 0x1737
102#define SLG51000_MUXARRAY_INPUT_SEL_56 0x1738
103#define SLG51000_MUXARRAY_INPUT_SEL_57 0x1739
104#define SLG51000_MUXARRAY_INPUT_SEL_58 0x173a
105#define SLG51000_MUXARRAY_INPUT_SEL_59 0x173b
106#define SLG51000_MUXARRAY_INPUT_SEL_60 0x173c
107#define SLG51000_MUXARRAY_INPUT_SEL_61 0x173d
108#define SLG51000_MUXARRAY_INPUT_SEL_62 0x173e
109#define SLG51000_MUXARRAY_INPUT_SEL_63 0x173f
110#define SLG51000_PWRSEQ_RESOURCE_EN_0 0x1900
111#define SLG51000_PWRSEQ_RESOURCE_EN_1 0x1901
112#define SLG51000_PWRSEQ_RESOURCE_EN_2 0x1902
113#define SLG51000_PWRSEQ_RESOURCE_EN_3 0x1903
114#define SLG51000_PWRSEQ_RESOURCE_EN_4 0x1904
115#define SLG51000_PWRSEQ_RESOURCE_EN_5 0x1905
116#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP0 0x1906
117#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN0 0x1907
118#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP1 0x1908
119#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN1 0x1909
120#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP2 0x190a
121#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN2 0x190b
122#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP3 0x190c
123#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN3 0x190d
124#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP4 0x190e
125#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN4 0x190f
126#define SLG51000_PWRSEQ_SLOT_TIME_MIN_UP5 0x1910
127#define SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN5 0x1911
128#define SLG51000_PWRSEQ_SLOT_TIME_MAX_CONF_A 0x1912
129#define SLG51000_PWRSEQ_SLOT_TIME_MAX_CONF_B 0x1913
130#define SLG51000_PWRSEQ_SLOT_TIME_MAX_CONF_C 0x1914
131#define SLG51000_PWRSEQ_INPUT_SENSE_CONF_A 0x1915
132#define SLG51000_PWRSEQ_INPUT_SENSE_CONF_B 0x1916
133#define SLG51000_LDO1_VSEL 0x2000
134#define SLG51000_LDO1_MINV 0x2060
135#define SLG51000_LDO1_MAXV 0x2061
136#define SLG51000_LDO1_MISC1 0x2064
137#define SLG51000_LDO1_VSEL_ACTUAL 0x2065
138#define SLG51000_LDO1_EVENT 0x20c0
139#define SLG51000_LDO1_STATUS 0x20c1
140#define SLG51000_LDO1_IRQ_MASK 0x20c2
141#define SLG51000_LDO2_VSEL 0x2200
142#define SLG51000_LDO2_MINV 0x2260
143#define SLG51000_LDO2_MAXV 0x2261
144#define SLG51000_LDO2_MISC1 0x2264
145#define SLG51000_LDO2_VSEL_ACTUAL 0x2265
146#define SLG51000_LDO2_EVENT 0x22c0
147#define SLG51000_LDO2_STATUS 0x22c1
148#define SLG51000_LDO2_IRQ_MASK 0x22c2
149#define SLG51000_LDO3_VSEL 0x2300
150#define SLG51000_LDO3_MINV 0x2360
151#define SLG51000_LDO3_MAXV 0x2361
152#define SLG51000_LDO3_CONF1 0x2364
153#define SLG51000_LDO3_CONF2 0x2365
154#define SLG51000_LDO3_VSEL_ACTUAL 0x2366
155#define SLG51000_LDO3_EVENT 0x23c0
156#define SLG51000_LDO3_STATUS 0x23c1
157#define SLG51000_LDO3_IRQ_MASK 0x23c2
158#define SLG51000_LDO4_VSEL 0x2500
159#define SLG51000_LDO4_MINV 0x2560
160#define SLG51000_LDO4_MAXV 0x2561
161#define SLG51000_LDO4_CONF1 0x2564
162#define SLG51000_LDO4_CONF2 0x2565
163#define SLG51000_LDO4_VSEL_ACTUAL 0x2566
164#define SLG51000_LDO4_EVENT 0x25c0
165#define SLG51000_LDO4_STATUS 0x25c1
166#define SLG51000_LDO4_IRQ_MASK 0x25c2
167#define SLG51000_LDO5_VSEL 0x2700
168#define SLG51000_LDO5_MINV 0x2760
169#define SLG51000_LDO5_MAXV 0x2761
170#define SLG51000_LDO5_TRIM2 0x2763
171#define SLG51000_LDO5_CONF1 0x2765
172#define SLG51000_LDO5_CONF2 0x2766
173#define SLG51000_LDO5_VSEL_ACTUAL 0x2767
174#define SLG51000_LDO5_EVENT 0x27c0
175#define SLG51000_LDO5_STATUS 0x27c1
176#define SLG51000_LDO5_IRQ_MASK 0x27c2
177#define SLG51000_LDO6_VSEL 0x2900
178#define SLG51000_LDO6_MINV 0x2960
179#define SLG51000_LDO6_MAXV 0x2961
180#define SLG51000_LDO6_TRIM2 0x2963
181#define SLG51000_LDO6_CONF1 0x2965
182#define SLG51000_LDO6_CONF2 0x2966
183#define SLG51000_LDO6_VSEL_ACTUAL 0x2967
184#define SLG51000_LDO6_EVENT 0x29c0
185#define SLG51000_LDO6_STATUS 0x29c1
186#define SLG51000_LDO6_IRQ_MASK 0x29c2
187#define SLG51000_LDO7_VSEL 0x3100
188#define SLG51000_LDO7_MINV 0x3160
189#define SLG51000_LDO7_MAXV 0x3161
190#define SLG51000_LDO7_CONF1 0x3164
191#define SLG51000_LDO7_CONF2 0x3165
192#define SLG51000_LDO7_VSEL_ACTUAL 0x3166
193#define SLG51000_LDO7_EVENT 0x31c0
194#define SLG51000_LDO7_STATUS 0x31c1
195#define SLG51000_LDO7_IRQ_MASK 0x31c2
196#define SLG51000_OTP_EVENT 0x782b
197#define SLG51000_OTP_IRQ_MASK 0x782d
198#define SLG51000_OTP_LOCK_OTP_PROG 0x78fe
199#define SLG51000_OTP_LOCK_CTRL 0x78ff
200#define SLG51000_LOCK_GLOBAL_LOCK_CTRL1 0x8000
201
202/* Register Bit Fields */
203
204/* SLG51000_SYSCTL_PATTERN_ID_BYTE0 = 0x1105 */
205#define SLG51000_PATTERN_ID_BYTE0_SHIFT 0
206#define SLG51000_PATTERN_ID_BYTE0_MASK (0xff << 0)
207
208/* SLG51000_SYSCTL_PATTERN_ID_BYTE1 = 0x1106 */
209#define SLG51000_PATTERN_ID_BYTE1_SHIFT 0
210#define SLG51000_PATTERN_ID_BYTE1_MASK (0xff << 0)
211
212/* SLG51000_SYSCTL_PATTERN_ID_BYTE2 = 0x1107 */
213#define SLG51000_PATTERN_ID_BYTE2_SHIFT 0
214#define SLG51000_PATTERN_ID_BYTE2_MASK (0xff << 0)
215
216/* SLG51000_SYSCTL_SYS_CONF_A = 0x1109 */
217#define SLG51000_I2C_ADDRESS_SHIFT 0
218#define SLG51000_I2C_ADDRESS_MASK (0x7f << 0)
219#define SLG51000_I2C_DISABLE_SHIFT 7
220#define SLG51000_I2C_DISABLE_MASK (0x01 << 7)
221
222/* SLG51000_SYSCTL_SYS_CONF_D = 0x110c */
223#define SLG51000_CS_T_DEB_SHIFT 6
224#define SLG51000_CS_T_DEB_MASK (0x03 << 6)
225#define SLG51000_I2C_CLR_MODE_SHIFT 5
226#define SLG51000_I2C_CLR_MODE_MASK (0x01 << 5)
227
228/* SLG51000_SYSCTL_MATRIX_CTRL_CONF_A = 0x110d */
229#define SLG51000_RESOURCE_CTRL_SHIFT 0
230#define SLG51000_RESOURCE_CTRL_MASK (0xff << 0)
231
232/* SLG51000_SYSCTL_MATRIX_CTRL_CONF_B = 0x110e */
233#define SLG51000_MATRIX_EVENT_SENSE_SHIFT 0
234#define SLG51000_MATRIX_EVENT_SENSE_MASK (0x07 << 0)
235
236/* SLG51000_SYSCTL_REFGEN_CONF_C = 0x1111 */
237#define SLG51000_REFGEN_SEL_TEMP_WARN_DEBOUNCE_SHIFT 2
238#define SLG51000_REFGEN_SEL_TEMP_WARN_DEBOUNCE_MASK (0x03 << 2)
239#define SLG51000_REFGEN_SEL_TEMP_WARN_THR_SHIFT 0
240#define SLG51000_REFGEN_SEL_TEMP_WARN_THR_MASK (0x03 << 0)
241
242/* SLG51000_SYSCTL_UVLO_CONF_A = 0x1112 */
243#define SLG51000_VMON_UVLO_SEL_THR_SHIFT 0
244#define SLG51000_VMON_UVLO_SEL_THR_MASK (0x1f << 0)
245
246/* SLG51000_SYSCTL_FAULT_LOG1 = 0x1115 */
247#define SLG51000_FLT_POR_SHIFT 5
248#define SLG51000_FLT_POR_MASK (0x01 << 5)
249#define SLG51000_FLT_RST_SHIFT 4
250#define SLG51000_FLT_RST_MASK (0x01 << 4)
251#define SLG51000_FLT_POWER_SEQ_CRASH_REQ_SHIFT 2
252#define SLG51000_FLT_POWER_SEQ_CRASH_REQ_MASK (0x01 << 2)
253#define SLG51000_FLT_OVER_TEMP_SHIFT 1
254#define SLG51000_FLT_OVER_TEMP_MASK (0x01 << 1)
255
256/* SLG51000_SYSCTL_EVENT = 0x1116 */
257#define SLG51000_EVT_MATRIX_SHIFT 1
258#define SLG51000_EVT_MATRIX_MASK (0x01 << 1)
259#define SLG51000_EVT_HIGH_TEMP_WARN_SHIFT 0
260#define SLG51000_EVT_HIGH_TEMP_WARN_MASK (0x01 << 0)
261
262/* SLG51000_SYSCTL_STATUS = 0x1117 */
263#define SLG51000_STA_MATRIX_SHIFT 1
264#define SLG51000_STA_MATRIX_MASK (0x01 << 1)
265#define SLG51000_STA_HIGH_TEMP_WARN_SHIFT 0
266#define SLG51000_STA_HIGH_TEMP_WARN_MASK (0x01 << 0)
267
268/* SLG51000_SYSCTL_IRQ_MASK = 0x1118 */
269#define SLG51000_IRQ_MATRIX_SHIFT 1
270#define SLG51000_IRQ_MATRIX_MASK (0x01 << 1)
271#define SLG51000_IRQ_HIGH_TEMP_WARN_SHIFT 0
272#define SLG51000_IRQ_HIGH_TEMP_WARN_MASK (0x01 << 0)
273
274/* SLG51000_IO_GPIO1_CONF ~ SLG51000_IO_GPIO5_CONF =
275 * 0x1500, 0x1501, 0x1502, 0x1503, 0x1504
276 */
277#define SLG51000_GPIO_DIR_SHIFT 7
278#define SLG51000_GPIO_DIR_MASK (0x01 << 7)
279#define SLG51000_GPIO_SENS_SHIFT 5
280#define SLG51000_GPIO_SENS_MASK (0x03 << 5)
281#define SLG51000_GPIO_INVERT_SHIFT 4
282#define SLG51000_GPIO_INVERT_MASK (0x01 << 4)
283#define SLG51000_GPIO_BYP_SHIFT 3
284#define SLG51000_GPIO_BYP_MASK (0x01 << 3)
285#define SLG51000_GPIO_T_DEB_SHIFT 1
286#define SLG51000_GPIO_T_DEB_MASK (0x03 << 1)
287#define SLG51000_GPIO_LEVEL_SHIFT 0
288#define SLG51000_GPIO_LEVEL_MASK (0x01 << 0)
289
290/* SLG51000_IO_GPIO6_CONF = 0x1505 */
291#define SLG51000_GPIO6_SENS_SHIFT 5
292#define SLG51000_GPIO6_SENS_MASK (0x03 << 5)
293#define SLG51000_GPIO6_INVERT_SHIFT 4
294#define SLG51000_GPIO6_INVERT_MASK (0x01 << 4)
295#define SLG51000_GPIO6_T_DEB_SHIFT 1
296#define SLG51000_GPIO6_T_DEB_MASK (0x03 << 1)
297#define SLG51000_GPIO6_LEVEL_SHIFT 0
298#define SLG51000_GPIO6_LEVEL_MASK (0x01 << 0)
299
300/* SLG51000_IO_GPIO_STATUS = 0x1506 */
301#define SLG51000_GPIO6_STATUS_SHIFT 5
302#define SLG51000_GPIO6_STATUS_MASK (0x01 << 5)
303#define SLG51000_GPIO5_STATUS_SHIFT 4
304#define SLG51000_GPIO5_STATUS_MASK (0x01 << 4)
305#define SLG51000_GPIO4_STATUS_SHIFT 3
306#define SLG51000_GPIO4_STATUS_MASK (0x01 << 3)
307#define SLG51000_GPIO3_STATUS_SHIFT 2
308#define SLG51000_GPIO3_STATUS_MASK (0x01 << 2)
309#define SLG51000_GPIO2_STATUS_SHIFT 1
310#define SLG51000_GPIO2_STATUS_MASK (0x01 << 1)
311#define SLG51000_GPIO1_STATUS_SHIFT 0
312#define SLG51000_GPIO1_STATUS_MASK (0x01 << 0)
313
314/* SLG51000_LUTARRAY_LUT_VAL_0 ~ SLG51000_LUTARRAY_LUT_VAL_11
315 * 0x1600, 0x1601, 0x1602, 0x1603, 0x1604, 0x1605,
316 * 0x1606, 0x1607, 0x1608, 0x1609, 0x160a, 0x160b
317 */
318#define SLG51000_LUT_VAL_SHIFT 0
319#define SLG51000_LUT_VAL_MASK (0xff << 0)
320
321/* SLG51000_MUXARRAY_INPUT_SEL_0 ~ SLG51000_MUXARRAY_INPUT_SEL_63
322 * 0x1700, 0x1701, 0x1702, 0x1703, 0x1704, 0x1705,
323 * 0x1706, 0x1707, 0x1708, 0x1709, 0x170a, 0x170b,
324 * 0x170c, 0x170d, 0x170e, 0x170f, 0x1710, 0x1711,
325 * 0x1712, 0x1713, 0x1714, 0x1715, 0x1716, 0x1717,
326 * 0x1718, 0x1719, 0x171a, 0x171b, 0x171c, 0x171d,
327 * 0x171e, 0x171f, 0x1720, 0x1721, 0x1722, 0x1723,
328 * 0x1724, 0x1725, 0x1726, 0x1727, 0x1728, 0x1729,
329 * 0x173a, 0x173b, 0x173c, 0x173d, 0x173e, 0x173f,
330 */
331#define SLG51000_INPUT_SEL_SHIFT 0
332#define SLG51000_INPUT_SEL_MASK (0x3f << 0)
333
334/* SLG51000_PWRSEQ_RESOURCE_EN_0 ~ SLG51000_PWRSEQ_RESOURCE_EN_5
335 * 0x1900, 0x1901, 0x1902, 0x1903, 0x1904, 0x1905
336 */
337#define SLG51000_RESOURCE_EN_DOWN0_SHIFT 4
338#define SLG51000_RESOURCE_EN_DOWN0_MASK (0x07 << 4)
339#define SLG51000_RESOURCE_EN_UP0_SHIFT 0
340#define SLG51000_RESOURCE_EN_UP0_MASK (0x07 << 0)
341
342/* SLG51000_PWRSEQ_SLOT_TIME_MIN_UP0 ~ SLG51000_PWRSEQ_SLOT_TIME_MIN_UP5
343 * 0x1906, 0x1908, 0x190a, 0x190c, 0x190e, 0x1910
344 */
345#define SLG51000_SLOT_TIME_MIN_UP_SHIFT 0
346#define SLG51000_SLOT_TIME_MIN_UP_MASK (0xff << 0)
347
348/* SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN0 ~ SLG51000_PWRSEQ_SLOT_TIME_MIN_DOWN5
349 * 0x1907, 0x1909, 0x190b, 0x190d, 0x190f, 0x1911
350 */
351#define SLG51000_SLOT_TIME_MIN_DOWN_SHIFT 0
352#define SLG51000_SLOT_TIME_MIN_DOWN_MASK (0xff << 0)
353
354/* SLG51000_PWRSEQ_SLOT_TIME_MAX_CONF_A ~ SLG51000_PWRSEQ_SLOT_TIME_MAX_CONF_C
355 * 0x1912, 0x1913, 0x1914
356 */
357#define SLG51000_SLOT_TIME_MAX_DOWN1_SHIFT 6
358#define SLG51000_SLOT_TIME_MAX_DOWN1_MASK (0x03 << 6)
359#define SLG51000_SLOT_TIME_MAX_UP1_SHIFT 4
360#define SLG51000_SLOT_TIME_MAX_UP1_MASK (0x03 << 4)
361#define SLG51000_SLOT_TIME_MAX_DOWN0_SHIFT 2
362#define SLG51000_SLOT_TIME_MAX_DOWN0_MASK (0x03 << 2)
363#define SLG51000_SLOT_TIME_MAX_UP0_SHIFT 0
364#define SLG51000_SLOT_TIME_MAX_UP0_MASK (0x03 << 0)
365
366/* SLG51000_PWRSEQ_INPUT_SENSE_CONF_A = 0x1915 */
367#define SLG51000_TRIG_UP_SENSE_SHIFT 6
368#define SLG51000_TRIG_UP_SENSE_MASK (0x01 << 6)
369#define SLG51000_UP_EN_SENSE5_SHIFT 5
370#define SLG51000_UP_EN_SENSE5_MASK (0x01 << 5)
371#define SLG51000_UP_EN_SENSE4_SHIFT 4
372#define SLG51000_UP_EN_SENSE4_MASK (0x01 << 4)
373#define SLG51000_UP_EN_SENSE3_SHIFT 3
374#define SLG51000_UP_EN_SENSE3_MASK (0x01 << 3)
375#define SLG51000_UP_EN_SENSE2_SHIFT 2
376#define SLG51000_UP_EN_SENSE2_MASK (0x01 << 2)
377#define SLG51000_UP_EN_SENSE1_SHIFT 1
378#define SLG51000_UP_EN_SENSE1_MASK (0x01 << 1)
379#define SLG51000_UP_EN_SENSE0_SHIFT 0
380#define SLG51000_UP_EN_SENSE0_MASK (0x01 << 0)
381
382/* SLG51000_PWRSEQ_INPUT_SENSE_CONF_B = 0x1916 */
383#define SLG51000_CRASH_DETECT_SENSE_SHIFT 7
384#define SLG51000_CRASH_DETECT_SENSE_MASK (0x01 << 7)
385#define SLG51000_TRIG_DOWN_SENSE_SHIFT 6
386#define SLG51000_TRIG_DOWN_SENSE_MASK (0x01 << 6)
387#define SLG51000_DOWN_EN_SENSE5_SHIFT 5
388#define SLG51000_DOWN_EN_SENSE5_MASK (0x01 << 5)
389#define SLG51000_DOWN_EN_SENSE4_SHIFT 4
390#define SLG51000_DOWN_EN_SENSE4_MASK (0x01 << 4)
391#define SLG51000_DOWN_EN_SENSE3_SHIFT 3
392#define SLG51000_DOWN_EN_SENSE3_MASK (0x01 << 3)
393#define SLG51000_DOWN_EN_SENSE2_SHIFT 2
394#define SLG51000_DOWN_EN_SENSE2_MASK (0x01 << 2)
395#define SLG51000_DOWN_EN_SENSE1_SHIFT 1
396#define SLG51000_DOWN_EN_SENSE1_MASK (0x01 << 1)
397#define SLG51000_DOWN_EN_SENSE0_SHIFT 0
398#define SLG51000_DOWN_EN_SENSE0_MASK (0x01 << 0)
399
400/* SLG51000_LDO1_VSEL ~ SLG51000_LDO7_VSEL =
401 * 0x2000, 0x2200, 0x2300, 0x2500, 0x2700, 0x2900, 0x3100
402 */
403#define SLG51000_VSEL_SHIFT 0
404#define SLG51000_VSEL_MASK (0xff << 0)
405
406/* SLG51000_LDO1_MINV ~ SLG51000_LDO7_MINV =
407 * 0x2060, 0x2260, 0x2360, 0x2560, 0x2760, 0x2960, 0x3160
408 */
409#define SLG51000_MINV_SHIFT 0
410#define SLG51000_MINV_MASK (0xff << 0)
411
412/* SLG51000_LDO1_MAXV ~ SLG51000_LDO7_MAXV =
413 * 0x2061, 0x2261, 0x2361, 0x2561, 0x2761, 0x2961, 0x3161
414 */
415#define SLG51000_MAXV_SHIFT 0
416#define SLG51000_MAXV_MASK (0xff << 0)
417
418/* SLG51000_LDO1_MISC1 = 0x2064, SLG51000_LDO2_MISC1 = 0x2264 */
419#define SLG51000_SEL_VRANGE_SHIFT 0
420#define SLG51000_SEL_VRANGE_MASK (0x01 << 0)
421
422/* SLG51000_LDO1_VSEL_ACTUAL ~ SLG51000_LDO7_VSEL_ACTUAL =
423 * 0x2065, 0x2265, 0x2366, 0x2566, 0x2767, 0x2967, 0x3166
424 */
425#define SLG51000_VSEL_ACTUAL_SHIFT 0
426#define SLG51000_VSEL_ACTUAL_MASK (0xff << 0)
427
428/* SLG51000_LDO1_EVENT ~ SLG51000_LDO7_EVENT =
429 * 0x20c0, 0x22c0, 0x23c0, 0x25c0, 0x27c0, 0x29c0, 0x31c0
430 */
431#define SLG51000_EVT_ILIM_FLAG_SHIFT 0
432#define SLG51000_EVT_ILIM_FLAG_MASK (0x01 << 0)
433#define SLG51000_EVT_VOUT_OK_FLAG_SHIFT 1
434#define SLG51000_EVT_VOUT_OK_FLAG_MASK (0x01 << 1)
435
436/* SLG51000_LDO1_STATUS ~ SLG51000_LDO7_STATUS =
437 * 0x20c1, 0x22c1, 0x23c1, 0x25c1, 0x27c1, 0x29c1, 0x31c1
438 */
439#define SLG51000_STA_ILIM_FLAG_SHIFT 0
440#define SLG51000_STA_ILIM_FLAG_MASK (0x01 << 0)
441#define SLG51000_STA_VOUT_OK_FLAG_SHIFT 1
442#define SLG51000_STA_VOUT_OK_FLAG_MASK (0x01 << 1)
443
444/* SLG51000_LDO1_IRQ_MASK ~ SLG51000_LDO7_IRQ_MASK =
445 * 0x20c2, 0x22c2, 0x23c2, 0x25c2, 0x27c2, 0x29c2, 0x31c2
446 */
447#define SLG51000_IRQ_ILIM_FLAG_SHIFT 0
448#define SLG51000_IRQ_ILIM_FLAG_MASK (0x01 << 0)
449
450/* SLG51000_LDO3_CONF1 ~ SLG51000_LDO7_CONF1 =
451 * 0x2364, 0x2564, 0x2765, 0x2965, 0x3164
452 */
453#define SLG51000_SEL_START_ILIM_SHIFT 0
454#define SLG51000_SEL_START_ILIM_MASK (0x7f << 0)
455
456/* SLG51000_LDO3_CONF2 ~ SLG51000_LDO7_CONF2 =
457 * 0x2365, 0x2565, 0x2766, 0x2966, 0x3165
458 */
459#define SLG51000_SEL_FUNC_ILIM_SHIFT 0
460#define SLG51000_SEL_FUNC_ILIM_MASK (0x7f << 0)
461
462/* SLG51000_LDO5_TRIM2 = 0x2763, SLG51000_LDO6_TRIM2 = 0x2963 */
463#define SLG51000_SEL_BYP_SLEW_RATE_SHIFT 2
464#define SLG51000_SEL_BYP_SLEW_RATE_MASK (0x03 << 2)
465#define SLG51000_SEL_BYP_VGATE_SHIFT 1
466#define SLG51000_SEL_BYP_VGATE_MASK (0x01 << 1)
467#define SLG51000_SEL_BYP_MODE_SHIFT 0
468#define SLG51000_SEL_BYP_MODE_MASK (0x01 << 0)
469
470/* SLG51000_OTP_EVENT = 0x782b */
471#define SLG51000_EVT_CRC_SHIFT 0
472#define SLG51000_EVT_CRC_MASK (0x01 << 0)
473
474/* SLG51000_OTP_IRQ_MASK = 0x782d */
475#define SLG51000_IRQ_CRC_SHIFT 0
476#define SLG51000_IRQ_CRC_MASK (0x01 << 0)
477
478/* SLG51000_OTP_LOCK_OTP_PROG = 0x78fe */
479#define SLG51000_LOCK_OTP_PROG_SHIFT 0
480#define SLG51000_LOCK_OTP_PROG_MASK (0x01 << 0)
481
482/* SLG51000_OTP_LOCK_CTRL = 0x78ff */
483#define SLG51000_LOCK_DFT_SHIFT 1
484#define SLG51000_LOCK_DFT_MASK (0x01 << 1)
485#define SLG51000_LOCK_RWT_SHIFT 0
486#define SLG51000_LOCK_RWT_MASK (0x01 << 0)
487
488/* SLG51000_LOCK_GLOBAL_LOCK_CTRL1 = 0x8000 */
489#define SLG51000_LDO7_LOCK_SHIFT 7
490#define SLG51000_LDO7_LOCK_MASK (0x01 << 7)
491#define SLG51000_LDO6_LOCK_SHIFT 6
492#define SLG51000_LDO6_LOCK_MASK (0x01 << 6)
493#define SLG51000_LDO5_LOCK_SHIFT 5
494#define SLG51000_LDO5_LOCK_MASK (0x01 << 5)
495#define SLG51000_LDO4_LOCK_SHIFT 4
496#define SLG51000_LDO4_LOCK_MASK (0x01 << 4)
497#define SLG51000_LDO3_LOCK_SHIFT 3
498#define SLG51000_LDO3_LOCK_MASK (0x01 << 3)
499#define SLG51000_LDO2_LOCK_SHIFT 2
500#define SLG51000_LDO2_LOCK_MASK (0x01 << 2)
501#define SLG51000_LDO1_LOCK_SHIFT 1
502#define SLG51000_LDO1_LOCK_MASK (0x01 << 1)
503
504#endif /* __SLG51000_REGISTERS_H__ */
505
diff --git a/drivers/regulator/stm32-booster.c b/drivers/regulator/stm32-booster.c
new file mode 100644
index 000000000000..2a897666c650
--- /dev/null
+++ b/drivers/regulator/stm32-booster.c
@@ -0,0 +1,132 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) STMicroelectronics 2019
3// Author(s): Fabrice Gasnier <fabrice.gasnier@st.com>.
4
5#include <linux/mfd/syscon.h>
6#include <linux/module.h>
7#include <linux/of_device.h>
8#include <linux/platform_device.h>
9#include <linux/regmap.h>
10#include <linux/regulator/driver.h>
11#include <linux/regulator/of_regulator.h>
12
13/* STM32H7 SYSCFG register */
14#define STM32H7_SYSCFG_PMCR 0x04
15#define STM32H7_SYSCFG_BOOSTE_MASK BIT(8)
16
17/* STM32MP1 SYSCFG has set and clear registers */
18#define STM32MP1_SYSCFG_PMCSETR 0x04
19#define STM32MP1_SYSCFG_PMCCLRR 0x44
20#define STM32MP1_SYSCFG_EN_BOOSTER_MASK BIT(8)
21
22static const struct regulator_ops stm32h7_booster_ops = {
23 .list_voltage = regulator_list_voltage_linear,
24 .enable = regulator_enable_regmap,
25 .disable = regulator_disable_regmap,
26 .is_enabled = regulator_is_enabled_regmap,
27};
28
29static const struct regulator_desc stm32h7_booster_desc = {
30 .name = "booster",
31 .supply_name = "vdda",
32 .n_voltages = 1,
33 .type = REGULATOR_VOLTAGE,
34 .min_uV = 3300000,
35 .fixed_uV = 3300000,
36 .ramp_delay = 66000, /* up to 50us to stabilize */
37 .ops = &stm32h7_booster_ops,
38 .enable_reg = STM32H7_SYSCFG_PMCR,
39 .enable_mask = STM32H7_SYSCFG_BOOSTE_MASK,
40 .owner = THIS_MODULE,
41};
42
43static int stm32mp1_booster_enable(struct regulator_dev *rdev)
44{
45 return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCSETR,
46 STM32MP1_SYSCFG_EN_BOOSTER_MASK);
47}
48
49static int stm32mp1_booster_disable(struct regulator_dev *rdev)
50{
51 return regmap_write(rdev->regmap, STM32MP1_SYSCFG_PMCCLRR,
52 STM32MP1_SYSCFG_EN_BOOSTER_MASK);
53}
54
55static const struct regulator_ops stm32mp1_booster_ops = {
56 .list_voltage = regulator_list_voltage_linear,
57 .enable = stm32mp1_booster_enable,
58 .disable = stm32mp1_booster_disable,
59 .is_enabled = regulator_is_enabled_regmap,
60};
61
62static const struct regulator_desc stm32mp1_booster_desc = {
63 .name = "booster",
64 .supply_name = "vdda",
65 .n_voltages = 1,
66 .type = REGULATOR_VOLTAGE,
67 .min_uV = 3300000,
68 .fixed_uV = 3300000,
69 .ramp_delay = 66000,
70 .ops = &stm32mp1_booster_ops,
71 .enable_reg = STM32MP1_SYSCFG_PMCSETR,
72 .enable_mask = STM32MP1_SYSCFG_EN_BOOSTER_MASK,
73 .owner = THIS_MODULE,
74};
75
76static int stm32_booster_probe(struct platform_device *pdev)
77{
78 struct device *dev = &pdev->dev;
79 struct device_node *np = pdev->dev.of_node;
80 struct regulator_config config = { };
81 const struct regulator_desc *desc;
82 struct regulator_dev *rdev;
83 struct regmap *regmap;
84 int ret;
85
86 regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
87 if (IS_ERR(regmap))
88 return PTR_ERR(regmap);
89
90 desc = (const struct regulator_desc *)
91 of_match_device(dev->driver->of_match_table, dev)->data;
92
93 config.regmap = regmap;
94 config.dev = dev;
95 config.of_node = np;
96 config.init_data = of_get_regulator_init_data(dev, np, desc);
97
98 rdev = devm_regulator_register(dev, desc, &config);
99 if (IS_ERR(rdev)) {
100 ret = PTR_ERR(rdev);
101 dev_err(dev, "register failed with error %d\n", ret);
102 return ret;
103 }
104
105 return 0;
106}
107
108static const struct of_device_id stm32_booster_of_match[] = {
109 {
110 .compatible = "st,stm32h7-booster",
111 .data = (void *)&stm32h7_booster_desc
112 }, {
113 .compatible = "st,stm32mp1-booster",
114 .data = (void *)&stm32mp1_booster_desc
115 }, {
116 },
117};
118MODULE_DEVICE_TABLE(of, stm32_booster_of_match);
119
120static struct platform_driver stm32_booster_driver = {
121 .probe = stm32_booster_probe,
122 .driver = {
123 .name = "stm32-booster",
124 .of_match_table = of_match_ptr(stm32_booster_of_match),
125 },
126};
127module_platform_driver(stm32_booster_driver);
128
129MODULE_LICENSE("GPL v2");
130MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>");
131MODULE_DESCRIPTION("STMicroelectronics STM32 booster regulator driver");
132MODULE_ALIAS("platform:stm32-booster");
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c
index ca39b3d55123..10ea4b5a0f55 100644
--- a/drivers/regulator/tps65090-regulator.c
+++ b/drivers/regulator/tps65090-regulator.c
@@ -371,11 +371,12 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
371 "dcdc-ext-control-gpios", 0, 371 "dcdc-ext-control-gpios", 0,
372 gflags, 372 gflags,
373 "tps65090"); 373 "tps65090");
374 if (IS_ERR(rpdata->gpiod)) 374 if (PTR_ERR(rpdata->gpiod) == -ENOENT) {
375 return ERR_CAST(rpdata->gpiod);
376 if (!rpdata->gpiod)
377 dev_err(&pdev->dev, 375 dev_err(&pdev->dev,
378 "could not find DCDC external control GPIO\n"); 376 "could not find DCDC external control GPIO\n");
377 rpdata->gpiod = NULL;
378 } else if (IS_ERR(rpdata->gpiod))
379 return ERR_CAST(rpdata->gpiod);
379 } 380 }
380 381
381 if (of_property_read_u32(tps65090_matches[idx].of_node, 382 if (of_property_read_u32(tps65090_matches[idx].of_node,
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index b422eef97b77..018dbbd96771 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -15,7 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h> 16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h> 17#include <linux/regulator/machine.h>
18#include <linux/gpio.h> 18#include <linux/gpio/consumer.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20 20
21#include <linux/mfd/wm831x/core.h> 21#include <linux/mfd/wm831x/core.h>
@@ -50,7 +50,7 @@ struct wm831x_dcdc {
50 int base; 50 int base;
51 struct wm831x *wm831x; 51 struct wm831x *wm831x;
52 struct regulator_dev *regulator; 52 struct regulator_dev *regulator;
53 int dvs_gpio; 53 struct gpio_desc *dvs_gpiod;
54 int dvs_gpio_state; 54 int dvs_gpio_state;
55 int on_vsel; 55 int on_vsel;
56 int dvs_vsel; 56 int dvs_vsel;
@@ -217,7 +217,7 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
217 return 0; 217 return 0;
218 218
219 dcdc->dvs_gpio_state = state; 219 dcdc->dvs_gpio_state = state;
220 gpio_set_value(dcdc->dvs_gpio, state); 220 gpiod_set_value(dcdc->dvs_gpiod, state);
221 221
222 /* Should wait for DVS state change to be asserted if we have 222 /* Should wait for DVS state change to be asserted if we have
223 * a GPIO for it, for now assume the device is configured 223 * a GPIO for it, for now assume the device is configured
@@ -237,10 +237,10 @@ static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
237 int ret; 237 int ret;
238 238
239 /* If this value is already set then do a GPIO update if we can */ 239 /* If this value is already set then do a GPIO update if we can */
240 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 240 if (dcdc->dvs_gpiod && dcdc->on_vsel == vsel)
241 return wm831x_buckv_set_dvs(rdev, 0); 241 return wm831x_buckv_set_dvs(rdev, 0);
242 242
243 if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) 243 if (dcdc->dvs_gpiod && dcdc->dvs_vsel == vsel)
244 return wm831x_buckv_set_dvs(rdev, 1); 244 return wm831x_buckv_set_dvs(rdev, 1);
245 245
246 /* Always set the ON status to the minimum voltage */ 246 /* Always set the ON status to the minimum voltage */
@@ -249,7 +249,7 @@ static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
249 return ret; 249 return ret;
250 dcdc->on_vsel = vsel; 250 dcdc->on_vsel = vsel;
251 251
252 if (!dcdc->dvs_gpio) 252 if (!dcdc->dvs_gpiod)
253 return ret; 253 return ret;
254 254
255 /* Kick the voltage transition now */ 255 /* Kick the voltage transition now */
@@ -296,7 +296,7 @@ static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
296{ 296{
297 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 297 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
298 298
299 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 299 if (dcdc->dvs_gpiod && dcdc->dvs_gpio_state)
300 return dcdc->dvs_vsel; 300 return dcdc->dvs_vsel;
301 else 301 else
302 return dcdc->on_vsel; 302 return dcdc->on_vsel;
@@ -337,7 +337,7 @@ static void wm831x_buckv_dvs_init(struct platform_device *pdev,
337 int ret; 337 int ret;
338 u16 ctrl; 338 u16 ctrl;
339 339
340 if (!pdata || !pdata->dvs_gpio) 340 if (!pdata)
341 return; 341 return;
342 342
343 /* gpiolib won't let us read the GPIO status so pick the higher 343 /* gpiolib won't let us read the GPIO status so pick the higher
@@ -345,17 +345,14 @@ static void wm831x_buckv_dvs_init(struct platform_device *pdev,
345 */ 345 */
346 dcdc->dvs_gpio_state = pdata->dvs_init_state; 346 dcdc->dvs_gpio_state = pdata->dvs_init_state;
347 347
348 ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio, 348 dcdc->dvs_gpiod = devm_gpiod_get(&pdev->dev, "dvs",
349 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, 349 dcdc->dvs_gpio_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
350 "DCDC DVS"); 350 if (IS_ERR(dcdc->dvs_gpiod)) {
351 if (ret < 0) { 351 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %ld\n",
352 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 352 dcdc->name, PTR_ERR(dcdc->dvs_gpiod));
353 dcdc->name, ret);
354 return; 353 return;
355 } 354 }
356 355
357 dcdc->dvs_gpio = pdata->dvs_gpio;
358
359 switch (pdata->dvs_control_src) { 356 switch (pdata->dvs_control_src) {
360 case 1: 357 case 1:
361 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT; 358 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;
diff --git a/include/linux/mfd/da9062/registers.h b/include/linux/mfd/da9062/registers.h
index fe04b708742b..2906bf6160fb 100644
--- a/include/linux/mfd/da9062/registers.h
+++ b/include/linux/mfd/da9062/registers.h
@@ -797,6 +797,9 @@
797#define DA9062AA_BUCK3_SL_A_SHIFT 7 797#define DA9062AA_BUCK3_SL_A_SHIFT 7
798#define DA9062AA_BUCK3_SL_A_MASK BIT(7) 798#define DA9062AA_BUCK3_SL_A_MASK BIT(7)
799 799
800/* DA9062AA_VLDO[1-4]_A common */
801#define DA9062AA_VLDO_A_MIN_SEL 2
802
800/* DA9062AA_VLDO1_A = 0x0A9 */ 803/* DA9062AA_VLDO1_A = 0x0A9 */
801#define DA9062AA_VLDO1_A_SHIFT 0 804#define DA9062AA_VLDO1_A_SHIFT 0
802#define DA9062AA_VLDO1_A_MASK 0x3f 805#define DA9062AA_VLDO1_A_MASK 0x3f
diff --git a/include/linux/mfd/da9063/pdata.h b/include/linux/mfd/da9063/pdata.h
index 77c566ab96ab..085edbf7601b 100644
--- a/include/linux/mfd/da9063/pdata.h
+++ b/include/linux/mfd/da9063/pdata.h
@@ -11,55 +11,6 @@
11#ifndef __MFD_DA9063_PDATA_H__ 11#ifndef __MFD_DA9063_PDATA_H__
12#define __MFD_DA9063_PDATA_H__ 12#define __MFD_DA9063_PDATA_H__
13 13
14#include <linux/regulator/machine.h>
15
16/*
17 * Regulator configuration
18 */
19/* DA9063 and DA9063L regulator IDs */
20enum {
21 /* BUCKs */
22 DA9063_ID_BCORE1,
23 DA9063_ID_BCORE2,
24 DA9063_ID_BPRO,
25 DA9063_ID_BMEM,
26 DA9063_ID_BIO,
27 DA9063_ID_BPERI,
28
29 /* BCORE1 and BCORE2 in merged mode */
30 DA9063_ID_BCORES_MERGED,
31 /* BMEM and BIO in merged mode */
32 DA9063_ID_BMEM_BIO_MERGED,
33 /* When two BUCKs are merged, they cannot be reused separately */
34
35 /* LDOs on both DA9063 and DA9063L */
36 DA9063_ID_LDO3,
37 DA9063_ID_LDO7,
38 DA9063_ID_LDO8,
39 DA9063_ID_LDO9,
40 DA9063_ID_LDO11,
41
42 /* DA9063-only LDOs */
43 DA9063_ID_LDO1,
44 DA9063_ID_LDO2,
45 DA9063_ID_LDO4,
46 DA9063_ID_LDO5,
47 DA9063_ID_LDO6,
48 DA9063_ID_LDO10,
49};
50
51/* Regulators platform data */
52struct da9063_regulator_data {
53 int id;
54 struct regulator_init_data *initdata;
55};
56
57struct da9063_regulators_pdata {
58 unsigned n_regulators;
59 struct da9063_regulator_data *regulator_data;
60};
61
62
63/* 14/*
64 * RGB LED configuration 15 * RGB LED configuration
65 */ 16 */
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 3ca17eb89aa2..f1631a39acfc 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -20,6 +20,7 @@
20#define MIN_850_MV 850000 20#define MIN_850_MV 850000
21#define MIN_800_MV 800000 21#define MIN_800_MV 800000
22#define MIN_750_MV 750000 22#define MIN_750_MV 750000
23#define MIN_650_MV 650000
23#define MIN_600_MV 600000 24#define MIN_600_MV 600000
24#define MIN_500_MV 500000 25#define MIN_500_MV 500000
25 26
diff --git a/include/linux/mfd/samsung/s2mps11.h b/include/linux/mfd/samsung/s2mps11.h
index 6e7668a389a1..4805c90609c4 100644
--- a/include/linux/mfd/samsung/s2mps11.h
+++ b/include/linux/mfd/samsung/s2mps11.h
@@ -170,7 +170,9 @@ enum s2mps11_regulators {
170#define S2MPS11_ENABLE_MASK (0x03 << S2MPS11_ENABLE_SHIFT) 170#define S2MPS11_ENABLE_MASK (0x03 << S2MPS11_ENABLE_SHIFT)
171#define S2MPS11_ENABLE_SHIFT 0x06 171#define S2MPS11_ENABLE_SHIFT 0x06
172#define S2MPS11_LDO_N_VOLTAGES (S2MPS11_LDO_VSEL_MASK + 1) 172#define S2MPS11_LDO_N_VOLTAGES (S2MPS11_LDO_VSEL_MASK + 1)
173#define S2MPS11_BUCK_N_VOLTAGES (S2MPS11_BUCK_VSEL_MASK + 1) 173#define S2MPS11_BUCK12346_N_VOLTAGES 153
174#define S2MPS11_BUCK5_N_VOLTAGES 216
175#define S2MPS11_BUCK7810_N_VOLTAGES 225
174#define S2MPS11_BUCK9_N_VOLTAGES (S2MPS11_BUCK9_VSEL_MASK + 1) 176#define S2MPS11_BUCK9_N_VOLTAGES (S2MPS11_BUCK9_VSEL_MASK + 1)
175#define S2MPS11_RAMP_DELAY 25000 /* uV/us */ 177#define S2MPS11_RAMP_DELAY 25000 /* uV/us */
176 178
@@ -188,4 +190,9 @@ enum s2mps11_regulators {
188#define S2MPS11_BUCK6_RAMP_EN_SHIFT 0 190#define S2MPS11_BUCK6_RAMP_EN_SHIFT 0
189#define S2MPS11_PMIC_EN_SHIFT 6 191#define S2MPS11_PMIC_EN_SHIFT 6
190 192
193/*
194 * Bits for "enable suspend" (On/Off controlled by PWREN)
195 * are the same as in S2MPS14: S2MPS14_ENABLE_SUSPEND
196 */
197
191#endif /* __LINUX_MFD_S2MPS11_H */ 198#endif /* __LINUX_MFD_S2MPS11_H */
diff --git a/include/linux/mfd/wm831x/pdata.h b/include/linux/mfd/wm831x/pdata.h
index 071cdf3e16cf..986986fe4e4e 100644
--- a/include/linux/mfd/wm831x/pdata.h
+++ b/include/linux/mfd/wm831x/pdata.h
@@ -47,7 +47,6 @@ struct wm831x_battery_pdata {
47 * I2C or SPI buses. 47 * I2C or SPI buses.
48 */ 48 */
49struct wm831x_buckv_pdata { 49struct wm831x_buckv_pdata {
50 int dvs_gpio; /** CPU GPIO to use for DVS switching */
51 int dvs_control_src; /** Hardware DVS source to use (1 or 2) */ 50 int dvs_control_src; /** Hardware DVS source to use (1 or 2) */
52 int dvs_init_state; /** DVS state to expect on startup */ 51 int dvs_init_state; /** DVS state to expect on startup */
53 int dvs_state_gpio; /** CPU GPIO to use for monitoring status */ 52 int dvs_state_gpio; /** CPU GPIO to use for monitoring status */
diff --git a/include/linux/regulator/coupler.h b/include/linux/regulator/coupler.h
new file mode 100644
index 000000000000..0212d6255e4e
--- /dev/null
+++ b/include/linux/regulator/coupler.h
@@ -0,0 +1,97 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * coupler.h -- SoC Regulator support, coupler API.
4 *
5 * Regulator Coupler Interface.
6 */
7
8#ifndef __LINUX_REGULATOR_COUPLER_H_
9#define __LINUX_REGULATOR_COUPLER_H_
10
11#include <linux/kernel.h>
12#include <linux/suspend.h>
13
14struct regulator_coupler;
15struct regulator_dev;
16
17/**
18 * struct regulator_coupler - customized regulator's coupler
19 *
20 * Regulator's coupler allows to customize coupling algorithm.
21 *
22 * @list: couplers list entry
23 * @attach_regulator: Callback invoked on creation of a coupled regulator,
24 * couples are unresolved at this point. The callee should
25 * check that it could handle the regulator and return 0 on
26 * success, -errno on failure and 1 if given regulator is
27 * not suitable for this coupler (case of having multiple
28 * regulators in a system). Callback shall be implemented.
29 * @detach_regulator: Callback invoked on destruction of a coupled regulator.
30 * This callback is optional and could be NULL.
31 * @balance_voltage: Callback invoked when voltage of a coupled regulator is
32 * changing. Called with all of the coupled rdev's being held
33 * under "consumer lock". The callee should perform voltage
34 * balancing, changing voltage of the coupled regulators as
35 * needed. It's up to the coupler to verify the voltage
36 * before changing it in hardware, i.e. coupler should
37 * check consumer's min/max and etc. This callback is
38 * optional and could be NULL, in which case a generic
39 * voltage balancer will be used.
40 */
41struct regulator_coupler {
42 struct list_head list;
43
44 int (*attach_regulator)(struct regulator_coupler *coupler,
45 struct regulator_dev *rdev);
46 int (*detach_regulator)(struct regulator_coupler *coupler,
47 struct regulator_dev *rdev);
48 int (*balance_voltage)(struct regulator_coupler *coupler,
49 struct regulator_dev *rdev,
50 suspend_state_t state);
51};
52
53#ifdef CONFIG_REGULATOR
54int regulator_coupler_register(struct regulator_coupler *coupler);
55const char *rdev_get_name(struct regulator_dev *rdev);
56int regulator_check_consumers(struct regulator_dev *rdev,
57 int *min_uV, int *max_uV,
58 suspend_state_t state);
59int regulator_check_voltage(struct regulator_dev *rdev,
60 int *min_uV, int *max_uV);
61int regulator_get_voltage_rdev(struct regulator_dev *rdev);
62int regulator_set_voltage_rdev(struct regulator_dev *rdev,
63 int min_uV, int max_uV,
64 suspend_state_t state);
65#else
66static inline int regulator_coupler_register(struct regulator_coupler *coupler)
67{
68 return 0;
69}
70static inline const char *rdev_get_name(struct regulator_dev *rdev)
71{
72 return NULL;
73}
74static inline int regulator_check_consumers(struct regulator_dev *rdev,
75 int *min_uV, int *max_uV,
76 suspend_state_t state)
77{
78 return -EINVAL;
79}
80static inline int regulator_check_voltage(struct regulator_dev *rdev,
81 int *min_uV, int *max_uV)
82{
83 return -EINVAL;
84}
85static inline int regulator_get_voltage_rdev(struct regulator_dev *rdev)
86{
87 return -EINVAL;
88}
89static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
90 int min_uV, int max_uV,
91 suspend_state_t state)
92{
93 return -EINVAL;
94}
95#endif
96
97#endif
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index d45ab52c91c9..9a911bb5fb61 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -12,8 +12,6 @@
12#ifndef __LINUX_REGULATOR_DRIVER_H_ 12#ifndef __LINUX_REGULATOR_DRIVER_H_
13#define __LINUX_REGULATOR_DRIVER_H_ 13#define __LINUX_REGULATOR_DRIVER_H_
14 14
15#define MAX_COUPLED 2
16
17#include <linux/device.h> 15#include <linux/device.h>
18#include <linux/notifier.h> 16#include <linux/notifier.h>
19#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
@@ -283,6 +281,11 @@ enum regulator_type {
283 * @vsel_range_mask: Mask for register bitfield used for range selector 281 * @vsel_range_mask: Mask for register bitfield used for range selector
284 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ 282 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
285 * @vsel_mask: Mask for register bitfield used for selector 283 * @vsel_mask: Mask for register bitfield used for selector
284 * @vsel_step: Specify the resolution of selector stepping when setting
285 * voltage. If 0, then no stepping is done (requested selector is
286 * set directly), if >0 then the regulator API will ramp the
287 * voltage up/down gradually each time increasing/decreasing the
288 * selector by the specified step value.
286 * @csel_reg: Register for current limit selector using regmap set_current_limit 289 * @csel_reg: Register for current limit selector using regmap set_current_limit
287 * @csel_mask: Mask for register bitfield used for current limit selector 290 * @csel_mask: Mask for register bitfield used for current limit selector
288 * @apply_reg: Register for initiate voltage change on the output when 291 * @apply_reg: Register for initiate voltage change on the output when
@@ -357,6 +360,7 @@ struct regulator_desc {
357 unsigned int vsel_range_mask; 360 unsigned int vsel_range_mask;
358 unsigned int vsel_reg; 361 unsigned int vsel_reg;
359 unsigned int vsel_mask; 362 unsigned int vsel_mask;
363 unsigned int vsel_step;
360 unsigned int csel_reg; 364 unsigned int csel_reg;
361 unsigned int csel_mask; 365 unsigned int csel_mask;
362 unsigned int apply_reg; 366 unsigned int apply_reg;
@@ -423,7 +427,8 @@ struct regulator_config {
423 * incremented. 427 * incremented.
424 */ 428 */
425struct coupling_desc { 429struct coupling_desc {
426 struct regulator_dev *coupled_rdevs[MAX_COUPLED]; 430 struct regulator_dev **coupled_rdevs;
431 struct regulator_coupler *coupler;
427 int n_resolved; 432 int n_resolved;
428 int n_coupled; 433 int n_coupled;
429}; 434};
@@ -549,4 +554,5 @@ void regulator_unlock(struct regulator_dev *rdev);
549 */ 554 */
550int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, 555int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
551 unsigned int selector); 556 unsigned int selector);
557
552#endif 558#endif
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 5539efa76d26..a84cc8879c3e 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -153,7 +153,7 @@ struct regulation_constraints {
153 int system_load; 153 int system_load;
154 154
155 /* used for coupled regulators */ 155 /* used for coupled regulators */
156 int max_spread; 156 u32 *max_spread;
157 157
158 /* used for changing voltage in steps */ 158 /* used for changing voltage in steps */
159 int max_uV_step; 159 int max_uV_step;
diff --git a/include/linux/regulator/max8952.h b/include/linux/regulator/max8952.h
index ebd99d2e62ad..8712c091abf0 100644
--- a/include/linux/regulator/max8952.h
+++ b/include/linux/regulator/max8952.h
@@ -105,9 +105,6 @@ enum {
105#define MAX8952_NUM_DVS_MODE 4 105#define MAX8952_NUM_DVS_MODE 4
106 106
107struct max8952_platform_data { 107struct max8952_platform_data {
108 int gpio_vid0;
109 int gpio_vid1;
110
111 u32 default_mode; 108 u32 default_mode;
112 u32 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */ 109 u32 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */
113 110