aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2019-03-04 10:32:43 -0500
committerMark Brown <broonie@kernel.org>2019-03-04 10:32:43 -0500
commit88f268a5bcc3b0683e6fbaf9973702e5329fc1e3 (patch)
treea64bf49e575ece017359ba5ac89fbc52efd81f2a
parentc364098fe8745b08a491fb43de785806ca91ba5e (diff)
parente5680c4de3eb3ea5538d11733a91ccef19badd69 (diff)
Merge branch 'regulator-5.1' into regulator-next
-rw-r--r--.mailmap1
-rw-r--r--Documentation/devicetree/bindings/mfd/rohm,bd71837-pmic.txt17
-rw-r--r--Documentation/devicetree/bindings/regulator/fan53555.txt3
-rw-r--r--Documentation/devicetree/bindings/regulator/fixed-regulator.txt35
-rw-r--r--Documentation/devicetree/bindings/regulator/fixed-regulator.yaml67
-rw-r--r--Documentation/devicetree/bindings/regulator/max77650-regulator.txt41
-rw-r--r--Documentation/devicetree/bindings/regulator/pfuze100.txt2
-rw-r--r--Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt68
-rw-r--r--Documentation/devicetree/bindings/regulator/rohm,bd71837-regulator.txt38
-rw-r--r--Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt6
-rw-r--r--Documentation/devicetree/bindings/regulator/tps65218.txt9
-rw-r--r--arch/arm/mach-imx/mach-mx21ads.c1
-rw-r--r--arch/arm/mach-imx/mach-mx27ads.c2
-rw-r--r--arch/arm/mach-mmp/brownstone.c1
-rw-r--r--arch/arm/mach-omap1/board-ams-delta.c2
-rw-r--r--arch/arm/mach-omap2/pdata-quirks.c1
-rw-r--r--arch/arm/mach-pxa/em-x270.c1
-rw-r--r--arch/arm/mach-pxa/ezx.c3
-rw-r--r--arch/arm/mach-pxa/hx4700.c23
-rw-r--r--arch/arm/mach-pxa/magician.c23
-rw-r--r--arch/arm/mach-pxa/raumfeld.c1
-rw-r--r--arch/arm/mach-pxa/zeus.c3
-rw-r--r--arch/arm/mach-sa1100/assabet.c1
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c2
-rw-r--r--arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c1
-rw-r--r--drivers/regulator/88pm8607.c38
-rw-r--r--drivers/regulator/Kconfig27
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/act8865-regulator.c5
-rw-r--r--drivers/regulator/act8945a-regulator.c11
-rw-r--r--drivers/regulator/arizona-ldo1.c56
-rw-r--r--drivers/regulator/as3722-regulator.c2
-rw-r--r--drivers/regulator/axp20x-regulator.c9
-rw-r--r--drivers/regulator/bd70528-regulator.c289
-rw-r--r--drivers/regulator/bd718x7-regulator.c215
-rw-r--r--drivers/regulator/bd9571mwv-regulator.c8
-rw-r--r--drivers/regulator/core.c76
-rw-r--r--drivers/regulator/cpcap-regulator.c106
-rw-r--r--drivers/regulator/da9055-regulator.c46
-rw-r--r--drivers/regulator/da9062-regulator.c37
-rw-r--r--drivers/regulator/da9063-regulator.c37
-rw-r--r--drivers/regulator/da9210-regulator.c53
-rw-r--r--drivers/regulator/fan53555.c109
-rw-r--r--drivers/regulator/fixed.c35
-rw-r--r--drivers/regulator/gpio-regulator.c194
-rw-r--r--drivers/regulator/helpers.c125
-rw-r--r--drivers/regulator/hi655x-regulator.c1
-rw-r--r--drivers/regulator/isl6271a-regulator.c13
-rw-r--r--drivers/regulator/lm363x-regulator.c6
-rw-r--r--drivers/regulator/lochnagar-regulator.c3
-rw-r--r--drivers/regulator/lp3971.c4
-rw-r--r--drivers/regulator/lp3972.c4
-rw-r--r--drivers/regulator/lp872x.c82
-rw-r--r--drivers/regulator/lp873x-regulator.c51
-rw-r--r--drivers/regulator/lp8755.c6
-rw-r--r--drivers/regulator/lp87565-regulator.c4
-rw-r--r--drivers/regulator/lp8788-buck.c40
-rw-r--r--drivers/regulator/lp8788-ldo.c4
-rw-r--r--drivers/regulator/ltc3676.c65
-rw-r--r--drivers/regulator/max14577-regulator.c1
-rw-r--r--drivers/regulator/max77620-regulator.c2
-rw-r--r--drivers/regulator/max77650-regulator.c498
-rw-r--r--drivers/regulator/max77802-regulator.c6
-rw-r--r--drivers/regulator/mc13783-regulator.c4
-rw-r--r--drivers/regulator/mc13892-regulator.c8
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c4
-rw-r--r--drivers/regulator/mc13xxx.h4
-rw-r--r--drivers/regulator/mcp16502.c2
-rw-r--r--drivers/regulator/mt6311-regulator.c10
-rw-r--r--drivers/regulator/of_regulator.c4
-rw-r--r--drivers/regulator/palmas-regulator.c2
-rw-r--r--drivers/regulator/pv88060-regulator.c62
-rw-r--r--drivers/regulator/pv88080-regulator.c55
-rw-r--r--drivers/regulator/pv88090-regulator.c53
-rw-r--r--drivers/regulator/pwm-regulator.c17
-rw-r--r--drivers/regulator/qcom_smd-regulator.c104
-rw-r--r--drivers/regulator/rk808-regulator.c64
-rw-r--r--drivers/regulator/rt5033-regulator.c4
-rw-r--r--drivers/regulator/s5m8767.c8
-rw-r--r--drivers/regulator/stm32-vrefbuf.c121
-rw-r--r--drivers/regulator/stpmic1_regulator.c293
-rw-r--r--drivers/regulator/tps65218-regulator.c18
-rw-r--r--drivers/regulator/twl-regulator.c7
-rw-r--r--drivers/regulator/twl6030-regulator.c88
-rw-r--r--drivers/regulator/wm831x-dcdc.c81
-rw-r--r--include/linux/mfd/tps65218.h3
-rw-r--r--include/linux/regulator/driver.h30
-rw-r--r--include/linux/regulator/fixed.h10
-rw-r--r--include/linux/regulator/gpio-regulator.h18
89 files changed, 2327 insertions, 1369 deletions
diff --git a/.mailmap b/.mailmap
index ea98fcc197e4..37e1847c7988 100644
--- a/.mailmap
+++ b/.mailmap
@@ -123,6 +123,7 @@ Mark Brown <broonie@sirena.org.uk>
123Mark Yao <markyao0591@gmail.com> <mark.yao@rock-chips.com> 123Mark Yao <markyao0591@gmail.com> <mark.yao@rock-chips.com>
124Martin Kepplinger <martink@posteo.de> <martin.kepplinger@theobroma-systems.com> 124Martin Kepplinger <martink@posteo.de> <martin.kepplinger@theobroma-systems.com>
125Martin Kepplinger <martink@posteo.de> <martin.kepplinger@ginzinger.com> 125Martin Kepplinger <martink@posteo.de> <martin.kepplinger@ginzinger.com>
126Mathieu Othacehe <m.othacehe@gmail.com>
126Matthew Wilcox <willy@infradead.org> <matthew.r.wilcox@intel.com> 127Matthew Wilcox <willy@infradead.org> <matthew.r.wilcox@intel.com>
127Matthew Wilcox <willy@infradead.org> <matthew@wil.cx> 128Matthew Wilcox <willy@infradead.org> <matthew@wil.cx>
128Matthew Wilcox <willy@infradead.org> <mawilcox@linuxonhyperv.com> 129Matthew Wilcox <willy@infradead.org> <mawilcox@linuxonhyperv.com>
diff --git a/Documentation/devicetree/bindings/mfd/rohm,bd71837-pmic.txt b/Documentation/devicetree/bindings/mfd/rohm,bd71837-pmic.txt
index a4b056761eaa..d5f68ac78d15 100644
--- a/Documentation/devicetree/bindings/mfd/rohm,bd71837-pmic.txt
+++ b/Documentation/devicetree/bindings/mfd/rohm,bd71837-pmic.txt
@@ -23,6 +23,20 @@ Required properties:
23 23
24Optional properties: 24Optional properties:
25- clock-output-names : Should contain name for output clock. 25- clock-output-names : Should contain name for output clock.
26- rohm,reset-snvs-powered : Transfer BD718x7 to SNVS state at reset.
27
28The BD718x7 supports two different HW states as reset target states. States
29are called as SNVS and READY. At READY state all the PMIC power outputs go
30down and OTP is reload. At the SNVS state all other logic and external
31devices apart from the SNVS power domain are shut off. Please refer to NXP
32i.MX8 documentation for further information regarding SNVS state. When a
33reset is done via SNVS state the PMIC OTP data is not reload. This causes
34power outputs that have been under SW control to stay down when reset has
35switched power state to SNVS. If reset is done via READY state the power
36outputs will be returned to HW control by OTP loading. Thus the reset
37target state is set to READY by default. If SNVS state is used the boot
38crucial regulators must have the regulator-always-on and regulator-boot-on
39properties set in regulator node.
26 40
27Example: 41Example:
28 42
@@ -43,6 +57,7 @@ Example:
43 #clock-cells = <0>; 57 #clock-cells = <0>;
44 clocks = <&osc 0>; 58 clocks = <&osc 0>;
45 clock-output-names = "bd71837-32k-out"; 59 clock-output-names = "bd71837-32k-out";
60 rohm,reset-snvs-powered;
46 61
47 regulators { 62 regulators {
48 buck1: BUCK1 { 63 buck1: BUCK1 {
@@ -50,8 +65,10 @@ Example:
50 regulator-min-microvolt = <700000>; 65 regulator-min-microvolt = <700000>;
51 regulator-max-microvolt = <1300000>; 66 regulator-max-microvolt = <1300000>;
52 regulator-boot-on; 67 regulator-boot-on;
68 regulator-always-on;
53 regulator-ramp-delay = <1250>; 69 regulator-ramp-delay = <1250>;
54 }; 70 };
71 // [...]
55 }; 72 };
56 }; 73 };
57 74
diff --git a/Documentation/devicetree/bindings/regulator/fan53555.txt b/Documentation/devicetree/bindings/regulator/fan53555.txt
index 54a3f2c80e3a..e7fc045281d1 100644
--- a/Documentation/devicetree/bindings/regulator/fan53555.txt
+++ b/Documentation/devicetree/bindings/regulator/fan53555.txt
@@ -1,7 +1,8 @@
1Binding for Fairchild FAN53555 regulators 1Binding for Fairchild FAN53555 regulators
2 2
3Required properties: 3Required properties:
4 - compatible: one of "fcs,fan53555", "silergy,syr827", "silergy,syr828" 4 - compatible: one of "fcs,fan53555", "fcs,fan53526", "silergy,syr827" or
5 "silergy,syr828"
5 - reg: I2C address 6 - reg: I2C address
6 7
7Optional properties: 8Optional properties:
diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt b/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
deleted file mode 100644
index 0c2a6c8a1536..000000000000
--- a/Documentation/devicetree/bindings/regulator/fixed-regulator.txt
+++ /dev/null
@@ -1,35 +0,0 @@
1Fixed Voltage regulators
2
3Required properties:
4- compatible: Must be "regulator-fixed";
5- regulator-name: Defined in regulator.txt as optional, but required here.
6
7Optional properties:
8- gpio: gpio to use for enable control
9- startup-delay-us: startup time in microseconds
10- enable-active-high: Polarity of GPIO is Active high
11If this property is missing, the default assumed is Active low.
12- gpio-open-drain: GPIO is open drain type.
13 If this property is missing then default assumption is false.
14-vin-supply: Input supply name.
15
16Any property defined as part of the core regulator
17binding, defined in regulator.txt, can also be used.
18However a fixed voltage regulator is expected to have the
19regulator-min-microvolt and regulator-max-microvolt
20to be the same.
21
22Example:
23
24 abc: fixedregulator@0 {
25 compatible = "regulator-fixed";
26 regulator-name = "fixed-supply";
27 regulator-min-microvolt = <1800000>;
28 regulator-max-microvolt = <1800000>;
29 gpio = <&gpio1 16 0>;
30 startup-delay-us = <70000>;
31 enable-active-high;
32 regulator-boot-on;
33 gpio-open-drain;
34 vin-supply = <&parent_reg>;
35 };
diff --git a/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml
new file mode 100644
index 000000000000..d289c2f7455a
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/fixed-regulator.yaml
@@ -0,0 +1,67 @@
1# SPDX-License-Identifier: GPL-2.0
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/regulator/fixed-regulator.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Fixed Voltage 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. However a fixed voltage regulator is
16 expected to have the regulator-min-microvolt and regulator-max-microvolt
17 to be the same.
18
19properties:
20 compatible:
21 const: regulator-fixed
22
23 regulator-name: true
24
25 gpio:
26 description: gpio to use for enable control
27 maxItems: 1
28
29 startup-delay-us:
30 description: startup time in microseconds
31 $ref: /schemas/types.yaml#/definitions/uint32
32
33 enable-active-high:
34 description:
35 Polarity of GPIO is Active high. If this property is missing,
36 the default assumed is Active low.
37 type: boolean
38
39 gpio-open-drain:
40 description:
41 GPIO is open drain type. If this property is missing then default
42 assumption is false.
43 type: boolean
44
45 vin-supply:
46 description: Input supply phandle.
47 $ref: /schemas/types.yaml#/definitions/phandle
48
49required:
50 - compatible
51 - regulator-name
52
53examples:
54 - |
55 reg_1v8: regulator-1v8 {
56 compatible = "regulator-fixed";
57 regulator-name = "1v8";
58 regulator-min-microvolt = <1800000>;
59 regulator-max-microvolt = <1800000>;
60 gpio = <&gpio1 16 0>;
61 startup-delay-us = <70000>;
62 enable-active-high;
63 regulator-boot-on;
64 gpio-open-drain;
65 vin-supply = <&parent_reg>;
66 };
67...
diff --git a/Documentation/devicetree/bindings/regulator/max77650-regulator.txt b/Documentation/devicetree/bindings/regulator/max77650-regulator.txt
new file mode 100644
index 000000000000..f1cbe813c30f
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/max77650-regulator.txt
@@ -0,0 +1,41 @@
1Regulator driver for MAX77650 PMIC from Maxim Integrated.
2
3This module is part of the MAX77650 MFD device. For more details
4see Documentation/devicetree/bindings/mfd/max77650.txt.
5
6The regulator controller is represented as a sub-node of the PMIC node
7on the device tree.
8
9The device has a single LDO regulator and a SIMO buck-boost regulator with
10three independent power rails.
11
12Required properties:
13--------------------
14- compatible: Must be "maxim,max77650-regulator"
15
16Each rail must be instantiated under the regulators subnode of the top PMIC
17node. Up to four regulators can be defined. For standard regulator properties
18refer to Documentation/devicetree/bindings/regulator/regulator.txt.
19
20Available regulator compatible strings are: "ldo", "sbb0", "sbb1", "sbb2".
21
22Example:
23--------
24
25 regulators {
26 compatible = "maxim,max77650-regulator";
27
28 max77650_ldo: regulator@0 {
29 regulator-compatible = "ldo";
30 regulator-name = "max77650-ldo";
31 regulator-min-microvolt = <1350000>;
32 regulator-max-microvolt = <2937500>;
33 };
34
35 max77650_sbb0: regulator@1 {
36 regulator-compatible = "sbb0";
37 regulator-name = "max77650-sbb0";
38 regulator-min-microvolt = <800000>;
39 regulator-max-microvolt = <1587500>;
40 };
41 };
diff --git a/Documentation/devicetree/bindings/regulator/pfuze100.txt b/Documentation/devicetree/bindings/regulator/pfuze100.txt
index f9be1acf891c..4d3b12b92cb3 100644
--- a/Documentation/devicetree/bindings/regulator/pfuze100.txt
+++ b/Documentation/devicetree/bindings/regulator/pfuze100.txt
@@ -8,7 +8,7 @@ Optional properties:
8- fsl,pfuze-support-disable-sw: Boolean, if present disable all unused switch 8- fsl,pfuze-support-disable-sw: Boolean, if present disable all unused switch
9 regulators to save power consumption. Attention, ensure that all important 9 regulators to save power consumption. Attention, ensure that all important
10 regulators (e.g. DDR ref, DDR supply) has set the "regulator-always-on" 10 regulators (e.g. DDR ref, DDR supply) has set the "regulator-always-on"
11 property. If not present, the switched regualtors are always on and can't be 11 property. If not present, the switched regulators are always on and can't be
12 disabled. This binding is a workaround to keep backward compatibility with 12 disabled. This binding is a workaround to keep backward compatibility with
13 old dtb's which rely on the fact that the switched regulators are always on 13 old dtb's which rely on the fact that the switched regulators are always on
14 and don't mark them explicit as "regulator-always-on". 14 and don't mark them explicit as "regulator-always-on".
diff --git a/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt b/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt
new file mode 100644
index 000000000000..698cfc3bc3dd
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/rohm,bd70528-regulator.txt
@@ -0,0 +1,68 @@
1ROHM BD70528 Power Management Integrated Circuit regulator bindings
2
3Required properties:
4 - regulator-name: should be "buck1", "buck2", "buck3", "ldo1", "ldo2", "ldo3",
5 "led_ldo1", "led_ldo2"
6
7List of regulators provided by this controller. BD70528 regulators node
8should be sub node of the BD70528 MFD node. See BD70528 MFD bindings at
9Documentation/devicetree/bindings/mfd/rohm,bd70528-pmic.txt
10
11The valid names for BD70528 regulator nodes are:
12BUCK1, BUCK2, BUCK3, LDO1, LDO2, LDO3, LED_LDO1, LED_LDO2
13
14Optional properties:
15- Any optional property defined in bindings/regulator/regulator.txt
16
17Example:
18regulators {
19 buck1: BUCK1 {
20 regulator-name = "buck1";
21 regulator-min-microvolt = <1200000>;
22 regulator-max-microvolt = <3400000>;
23 regulator-boot-on;
24 regulator-ramp-delay = <125>;
25 };
26 buck2: BUCK2 {
27 regulator-name = "buck2";
28 regulator-min-microvolt = <1200000>;
29 regulator-max-microvolt = <3300000>;
30 regulator-boot-on;
31 regulator-ramp-delay = <125>;
32 };
33 buck3: BUCK3 {
34 regulator-name = "buck3";
35 regulator-min-microvolt = <800000>;
36 regulator-max-microvolt = <1800000>;
37 regulator-boot-on;
38 regulator-ramp-delay = <250>;
39 };
40 ldo1: LDO1 {
41 regulator-name = "ldo1";
42 regulator-min-microvolt = <1650000>;
43 regulator-max-microvolt = <3300000>;
44 regulator-boot-on;
45 };
46 ldo2: LDO2 {
47 regulator-name = "ldo2";
48 regulator-min-microvolt = <1650000>;
49 regulator-max-microvolt = <3300000>;
50 regulator-boot-on;
51 };
52
53 ldo3: LDO3 {
54 regulator-name = "ldo3";
55 regulator-min-microvolt = <1650000>;
56 regulator-max-microvolt = <3300000>;
57 };
58 led_ldo1: LED_LDO1 {
59 regulator-name = "led_ldo1";
60 regulator-min-microvolt = <200000>;
61 regulator-max-microvolt = <300000>;
62 };
63 led_ldo2: LED_LDO2 {
64 regulator-name = "led_ldo2";
65 regulator-min-microvolt = <200000>;
66 regulator-max-microvolt = <300000>;
67 };
68};
diff --git a/Documentation/devicetree/bindings/regulator/rohm,bd71837-regulator.txt b/Documentation/devicetree/bindings/regulator/rohm,bd71837-regulator.txt
index 4b98ca26e61a..cbce62c22b60 100644
--- a/Documentation/devicetree/bindings/regulator/rohm,bd71837-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/rohm,bd71837-regulator.txt
@@ -27,8 +27,38 @@ BUCK1, BUCK2, BUCK3, BUCK4, BUCK5, BUCK6
27LDO1, LDO2, LDO3, LDO4, LDO5, LDO6 27LDO1, LDO2, LDO3, LDO4, LDO5, LDO6
28 28
29Optional properties: 29Optional properties:
30- rohm,dvs-run-voltage : PMIC default "RUN" state voltage in uV.
31 See below table for bucks which support this.
32- rohm,dvs-idle-voltage : PMIC default "IDLE" state voltage in uV.
33 See below table for bucks which support this.
34- rohm,dvs-suspend-voltage : PMIC default "SUSPEND" state voltage in uV.
35 See below table for bucks which support this.
30- Any optional property defined in bindings/regulator/regulator.txt 36- Any optional property defined in bindings/regulator/regulator.txt
31 37
38Supported default DVS states:
39
40BD71837:
41buck | dvs-run-voltage | dvs-idle-voltage | dvs-suspend-voltage
42-----------------------------------------------------------------------------
431 | supported | supported | supported
44----------------------------------------------------------------------------
452 | supported | supported | not supported
46----------------------------------------------------------------------------
473 | supported | not supported | not supported
48----------------------------------------------------------------------------
494 | supported | not supported | not supported
50----------------------------------------------------------------------------
51rest | not supported | not supported | not supported
52
53BD71847:
54buck | dvs-run-voltage | dvs-idle-voltage | dvs-suspend-voltage
55-----------------------------------------------------------------------------
561 | supported | supported | supported
57----------------------------------------------------------------------------
582 | supported | supported | not supported
59----------------------------------------------------------------------------
60rest | not supported | not supported | not supported
61
32Example: 62Example:
33regulators { 63regulators {
34 buck1: BUCK1 { 64 buck1: BUCK1 {
@@ -36,7 +66,11 @@ regulators {
36 regulator-min-microvolt = <700000>; 66 regulator-min-microvolt = <700000>;
37 regulator-max-microvolt = <1300000>; 67 regulator-max-microvolt = <1300000>;
38 regulator-boot-on; 68 regulator-boot-on;
69 regulator-always-on;
39 regulator-ramp-delay = <1250>; 70 regulator-ramp-delay = <1250>;
71 rohm,dvs-run-voltage = <900000>;
72 rohm,dvs-idle-voltage = <850000>;
73 rohm,dvs-suspend-voltage = <800000>;
40 }; 74 };
41 buck2: BUCK2 { 75 buck2: BUCK2 {
42 regulator-name = "buck2"; 76 regulator-name = "buck2";
@@ -45,18 +79,22 @@ regulators {
45 regulator-boot-on; 79 regulator-boot-on;
46 regulator-always-on; 80 regulator-always-on;
47 regulator-ramp-delay = <1250>; 81 regulator-ramp-delay = <1250>;
82 rohm,dvs-run-voltage = <1000000>;
83 rohm,dvs-idle-voltage = <900000>;
48 }; 84 };
49 buck3: BUCK3 { 85 buck3: BUCK3 {
50 regulator-name = "buck3"; 86 regulator-name = "buck3";
51 regulator-min-microvolt = <700000>; 87 regulator-min-microvolt = <700000>;
52 regulator-max-microvolt = <1300000>; 88 regulator-max-microvolt = <1300000>;
53 regulator-boot-on; 89 regulator-boot-on;
90 rohm,dvs-run-voltage = <1000000>;
54 }; 91 };
55 buck4: BUCK4 { 92 buck4: BUCK4 {
56 regulator-name = "buck4"; 93 regulator-name = "buck4";
57 regulator-min-microvolt = <700000>; 94 regulator-min-microvolt = <700000>;
58 regulator-max-microvolt = <1300000>; 95 regulator-max-microvolt = <1300000>;
59 regulator-boot-on; 96 regulator-boot-on;
97 rohm,dvs-run-voltage = <1000000>;
60 }; 98 };
61 buck5: BUCK5 { 99 buck5: BUCK5 {
62 regulator-name = "buck5"; 100 regulator-name = "buck5";
diff --git a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
index a3f476240565..6189df71ea98 100644
--- a/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/st,stpmic1-regulator.txt
@@ -23,16 +23,14 @@ Switches are fixed voltage regulators with only enable/disable capability.
23Optional properties: 23Optional properties:
24- st,mask-reset: mask reset for this regulator: the regulator configuration 24- st,mask-reset: mask reset for this regulator: the regulator configuration
25 is maintained during pmic reset. 25 is maintained during pmic reset.
26- regulator-pull-down: enable high pull down
27 if not specified light pull down is used
28- regulator-over-current-protection: 26- regulator-over-current-protection:
29 if set, all regulators are switched off in case of over-current detection 27 if set, all regulators are switched off in case of over-current detection
30 on this regulator, 28 on this regulator,
31 if not set, the driver only sends an over-current event. 29 if not set, the driver only sends an over-current event.
32- interrupt-parent: phandle to the parent interrupt controller
33- interrupts: index of current limit detection interrupt 30- interrupts: index of current limit detection interrupt
34- <regulator>-supply: phandle to the parent supply/regulator node 31- <regulator>-supply: phandle to the parent supply/regulator node
35 each regulator supply can be described except vref_ddr. 32 each regulator supply can be described except vref_ddr.
33- regulator-active-discharge: can be used on pwr_sw1 and pwr_sw2.
36 34
37Example: 35Example:
38regulators { 36regulators {
@@ -43,7 +41,6 @@ regulators {
43 vdd_core: buck1 { 41 vdd_core: buck1 {
44 regulator-name = "vdd_core"; 42 regulator-name = "vdd_core";
45 interrupts = <IT_CURLIM_BUCK1 0>; 43 interrupts = <IT_CURLIM_BUCK1 0>;
46 interrupt-parent = <&pmic>;
47 st,mask-reset; 44 st,mask-reset;
48 regulator-pull-down; 45 regulator-pull-down;
49 regulator-min-microvolt = <700000>; 46 regulator-min-microvolt = <700000>;
@@ -53,7 +50,6 @@ regulators {
53 v3v3: buck4 { 50 v3v3: buck4 {
54 regulator-name = "v3v3"; 51 regulator-name = "v3v3";
55 interrupts = <IT_CURLIM_BUCK4 0>; 52 interrupts = <IT_CURLIM_BUCK4 0>;
56 interrupt-parent = <&mypmic>;
57 53
58 regulator-min-microvolt = <3300000>; 54 regulator-min-microvolt = <3300000>;
59 regulator-max-microvolt = <3300000>; 55 regulator-max-microvolt = <3300000>;
diff --git a/Documentation/devicetree/bindings/regulator/tps65218.txt b/Documentation/devicetree/bindings/regulator/tps65218.txt
index 02f0e9bbfbf8..54aded3b78e2 100644
--- a/Documentation/devicetree/bindings/regulator/tps65218.txt
+++ b/Documentation/devicetree/bindings/regulator/tps65218.txt
@@ -71,8 +71,13 @@ tps65218: tps65218@24 {
71 regulator-always-on; 71 regulator-always-on;
72 }; 72 };
73 73
74 ls2: regulator-ls2 {
75 regulator-min-microamp = <100000>;
76 regulator-max-microamp = <1000000>;
77 };
78
74 ls3: regulator-ls3 { 79 ls3: regulator-ls3 {
75 regulator-min-microvolt = <100000>; 80 regulator-min-microamp = <100000>;
76 regulator-max-microvolt = <1000000>; 81 regulator-max-microamp = <1000000>;
77 }; 82 };
78}; 83};
diff --git a/arch/arm/mach-imx/mach-mx21ads.c b/arch/arm/mach-imx/mach-mx21ads.c
index 2e1e540f2e5a..d278fb672d40 100644
--- a/arch/arm/mach-imx/mach-mx21ads.c
+++ b/arch/arm/mach-imx/mach-mx21ads.c
@@ -205,7 +205,6 @@ static struct regulator_init_data mx21ads_lcd_regulator_init_data = {
205static struct fixed_voltage_config mx21ads_lcd_regulator_pdata = { 205static struct fixed_voltage_config mx21ads_lcd_regulator_pdata = {
206 .supply_name = "LCD", 206 .supply_name = "LCD",
207 .microvolts = 3300000, 207 .microvolts = 3300000,
208 .enable_high = 1,
209 .init_data = &mx21ads_lcd_regulator_init_data, 208 .init_data = &mx21ads_lcd_regulator_init_data,
210}; 209};
211 210
diff --git a/arch/arm/mach-imx/mach-mx27ads.c b/arch/arm/mach-imx/mach-mx27ads.c
index f5e04047ed13..6dd7f57c332f 100644
--- a/arch/arm/mach-imx/mach-mx27ads.c
+++ b/arch/arm/mach-imx/mach-mx27ads.c
@@ -237,7 +237,7 @@ static struct fixed_voltage_config mx27ads_lcd_regulator_pdata = {
237static struct gpiod_lookup_table mx27ads_lcd_regulator_gpiod_table = { 237static struct gpiod_lookup_table mx27ads_lcd_regulator_gpiod_table = {
238 .dev_id = "reg-fixed-voltage.0", /* Let's hope ID 0 is what we get */ 238 .dev_id = "reg-fixed-voltage.0", /* Let's hope ID 0 is what we get */
239 .table = { 239 .table = {
240 GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_HIGH), 240 GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_LOW),
241 { }, 241 { },
242 }, 242 },
243}; 243};
diff --git a/arch/arm/mach-mmp/brownstone.c b/arch/arm/mach-mmp/brownstone.c
index a04e249c654b..d2560fb1e835 100644
--- a/arch/arm/mach-mmp/brownstone.c
+++ b/arch/arm/mach-mmp/brownstone.c
@@ -149,7 +149,6 @@ static struct regulator_init_data brownstone_v_5vp_data = {
149static struct fixed_voltage_config brownstone_v_5vp = { 149static struct fixed_voltage_config brownstone_v_5vp = {
150 .supply_name = "v_5vp", 150 .supply_name = "v_5vp",
151 .microvolts = 5000000, 151 .microvolts = 5000000,
152 .enable_high = 1,
153 .enabled_at_boot = 1, 152 .enabled_at_boot = 1,
154 .init_data = &brownstone_v_5vp_data, 153 .init_data = &brownstone_v_5vp_data,
155}; 154};
diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c
index c4c0a8ea11e4..be30c3c061b4 100644
--- a/arch/arm/mach-omap1/board-ams-delta.c
+++ b/arch/arm/mach-omap1/board-ams-delta.c
@@ -267,7 +267,6 @@ static struct fixed_voltage_config modem_nreset_config = {
267 .supply_name = "modem_nreset", 267 .supply_name = "modem_nreset",
268 .microvolts = 3300000, 268 .microvolts = 3300000,
269 .startup_delay = 25000, 269 .startup_delay = 25000,
270 .enable_high = 1,
271 .enabled_at_boot = 1, 270 .enabled_at_boot = 1,
272 .init_data = &modem_nreset_data, 271 .init_data = &modem_nreset_data,
273}; 272};
@@ -533,7 +532,6 @@ static struct regulator_init_data keybrd_pwr_initdata = {
533static struct fixed_voltage_config keybrd_pwr_config = { 532static struct fixed_voltage_config keybrd_pwr_config = {
534 .supply_name = "keybrd_pwr", 533 .supply_name = "keybrd_pwr",
535 .microvolts = 5000000, 534 .microvolts = 5000000,
536 .enable_high = 1,
537 .init_data = &keybrd_pwr_initdata, 535 .init_data = &keybrd_pwr_initdata,
538}; 536};
539 537
diff --git a/arch/arm/mach-omap2/pdata-quirks.c b/arch/arm/mach-omap2/pdata-quirks.c
index 8a5b6ed4ec36..a2ecc5e69abb 100644
--- a/arch/arm/mach-omap2/pdata-quirks.c
+++ b/arch/arm/mach-omap2/pdata-quirks.c
@@ -330,7 +330,6 @@ static struct fixed_voltage_config pandora_vwlan = {
330 .supply_name = "vwlan", 330 .supply_name = "vwlan",
331 .microvolts = 1800000, /* 1.8V */ 331 .microvolts = 1800000, /* 1.8V */
332 .startup_delay = 50000, /* 50ms */ 332 .startup_delay = 50000, /* 50ms */
333 .enable_high = 1,
334 .init_data = &pandora_vmmc3, 333 .init_data = &pandora_vmmc3,
335}; 334};
336 335
diff --git a/arch/arm/mach-pxa/em-x270.c b/arch/arm/mach-pxa/em-x270.c
index 32c1edeb3f14..5ba7bb7f7d51 100644
--- a/arch/arm/mach-pxa/em-x270.c
+++ b/arch/arm/mach-pxa/em-x270.c
@@ -976,7 +976,6 @@ static struct fixed_voltage_config camera_dummy_config = {
976 .supply_name = "camera_vdd", 976 .supply_name = "camera_vdd",
977 .input_supply = "vcc cam", 977 .input_supply = "vcc cam",
978 .microvolts = 2800000, 978 .microvolts = 2800000,
979 .enable_high = 0,
980 .init_data = &camera_dummy_initdata, 979 .init_data = &camera_dummy_initdata,
981}; 980};
982 981
diff --git a/arch/arm/mach-pxa/ezx.c b/arch/arm/mach-pxa/ezx.c
index 565965e9acc7..5e110e70ce5a 100644
--- a/arch/arm/mach-pxa/ezx.c
+++ b/arch/arm/mach-pxa/ezx.c
@@ -714,7 +714,6 @@ static struct regulator_init_data camera_regulator_initdata = {
714static struct fixed_voltage_config camera_regulator_config = { 714static struct fixed_voltage_config camera_regulator_config = {
715 .supply_name = "camera_vdd", 715 .supply_name = "camera_vdd",
716 .microvolts = 2800000, 716 .microvolts = 2800000,
717 .enable_high = 0,
718 .init_data = &camera_regulator_initdata, 717 .init_data = &camera_regulator_initdata,
719}; 718};
720 719
@@ -730,7 +729,7 @@ static struct gpiod_lookup_table camera_supply_gpiod_table = {
730 .dev_id = "reg-fixed-voltage.1", 729 .dev_id = "reg-fixed-voltage.1",
731 .table = { 730 .table = {
732 GPIO_LOOKUP("gpio-pxa", GPIO50_nCAM_EN, 731 GPIO_LOOKUP("gpio-pxa", GPIO50_nCAM_EN,
733 NULL, GPIO_ACTIVE_HIGH), 732 NULL, GPIO_ACTIVE_LOW),
734 { }, 733 { },
735 }, 734 },
736}; 735};
diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c
index b79b757fdd41..51d38d5e776a 100644
--- a/arch/arm/mach-pxa/hx4700.c
+++ b/arch/arm/mach-pxa/hx4700.c
@@ -19,6 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/fb.h> 21#include <linux/fb.h>
22#include <linux/gpio/machine.h>
22#include <linux/gpio.h> 23#include <linux/gpio.h>
23#include <linux/gpio_keys.h> 24#include <linux/gpio_keys.h>
24#include <linux/input.h> 25#include <linux/input.h>
@@ -702,9 +703,7 @@ static struct regulator_init_data bq24022_init_data = {
702 .consumer_supplies = bq24022_consumers, 703 .consumer_supplies = bq24022_consumers,
703}; 704};
704 705
705static struct gpio bq24022_gpios[] = { 706static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
706 { GPIO96_HX4700_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
707};
708 707
709static struct gpio_regulator_state bq24022_states[] = { 708static struct gpio_regulator_state bq24022_states[] = {
710 { .value = 100000, .gpios = (0 << 0) }, 709 { .value = 100000, .gpios = (0 << 0) },
@@ -714,12 +713,10 @@ static struct gpio_regulator_state bq24022_states[] = {
714static struct gpio_regulator_config bq24022_info = { 713static struct gpio_regulator_config bq24022_info = {
715 .supply_name = "bq24022", 714 .supply_name = "bq24022",
716 715
717 .enable_gpio = GPIO72_HX4700_BQ24022_nCHARGE_EN,
718 .enable_high = 0,
719 .enabled_at_boot = 0, 716 .enabled_at_boot = 0,
720 717
721 .gpios = bq24022_gpios, 718 .gflags = bq24022_gpiod_gflags,
722 .nr_gpios = ARRAY_SIZE(bq24022_gpios), 719 .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
723 720
724 .states = bq24022_states, 721 .states = bq24022_states,
725 .nr_states = ARRAY_SIZE(bq24022_states), 722 .nr_states = ARRAY_SIZE(bq24022_states),
@@ -736,6 +733,17 @@ static struct platform_device bq24022 = {
736 }, 733 },
737}; 734};
738 735
736static struct gpiod_lookup_table bq24022_gpiod_table = {
737 .dev_id = "gpio-regulator",
738 .table = {
739 GPIO_LOOKUP("gpio-pxa", GPIO96_HX4700_BQ24022_ISET2,
740 NULL, GPIO_ACTIVE_HIGH),
741 GPIO_LOOKUP("gpio-pxa", GPIO72_HX4700_BQ24022_nCHARGE_EN,
742 "enable", GPIO_ACTIVE_LOW),
743 { },
744 },
745};
746
739/* 747/*
740 * StrataFlash 748 * StrataFlash
741 */ 749 */
@@ -878,6 +886,7 @@ static void __init hx4700_init(void)
878 pxa_set_btuart_info(NULL); 886 pxa_set_btuart_info(NULL);
879 pxa_set_stuart_info(NULL); 887 pxa_set_stuart_info(NULL);
880 888
889 gpiod_add_lookup_table(&bq24022_gpiod_table);
881 platform_add_devices(devices, ARRAY_SIZE(devices)); 890 platform_add_devices(devices, ARRAY_SIZE(devices));
882 pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup)); 891 pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup));
883 892
diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c
index 08b079653c3f..6538a7c0e504 100644
--- a/arch/arm/mach-pxa/magician.c
+++ b/arch/arm/mach-pxa/magician.c
@@ -645,9 +645,8 @@ static struct regulator_init_data bq24022_init_data = {
645 .consumer_supplies = bq24022_consumers, 645 .consumer_supplies = bq24022_consumers,
646}; 646};
647 647
648static struct gpio bq24022_gpios[] = { 648
649 { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" }, 649static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
650};
651 650
652static struct gpio_regulator_state bq24022_states[] = { 651static struct gpio_regulator_state bq24022_states[] = {
653 { .value = 100000, .gpios = (0 << 0) }, 652 { .value = 100000, .gpios = (0 << 0) },
@@ -657,12 +656,10 @@ static struct gpio_regulator_state bq24022_states[] = {
657static struct gpio_regulator_config bq24022_info = { 656static struct gpio_regulator_config bq24022_info = {
658 .supply_name = "bq24022", 657 .supply_name = "bq24022",
659 658
660 .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
661 .enable_high = 0,
662 .enabled_at_boot = 1, 659 .enabled_at_boot = 1,
663 660
664 .gpios = bq24022_gpios, 661 .gflags = bq24022_gpiod_gflags,
665 .nr_gpios = ARRAY_SIZE(bq24022_gpios), 662 .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
666 663
667 .states = bq24022_states, 664 .states = bq24022_states,
668 .nr_states = ARRAY_SIZE(bq24022_states), 665 .nr_states = ARRAY_SIZE(bq24022_states),
@@ -679,6 +676,17 @@ static struct platform_device bq24022 = {
679 }, 676 },
680}; 677};
681 678
679static struct gpiod_lookup_table bq24022_gpiod_table = {
680 .dev_id = "gpio-regulator",
681 .table = {
682 GPIO_LOOKUP("gpio-pxa", EGPIO_MAGICIAN_BQ24022_ISET2,
683 NULL, GPIO_ACTIVE_HIGH),
684 GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
685 "enable", GPIO_ACTIVE_LOW),
686 { },
687 },
688};
689
682/* 690/*
683 * fixed regulator for ads7846 691 * fixed regulator for ads7846
684 */ 692 */
@@ -1027,6 +1035,7 @@ static void __init magician_init(void)
1027 regulator_register_always_on(0, "power", pwm_backlight_supply, 1035 regulator_register_always_on(0, "power", pwm_backlight_supply,
1028 ARRAY_SIZE(pwm_backlight_supply), 5000000); 1036 ARRAY_SIZE(pwm_backlight_supply), 5000000);
1029 1037
1038 gpiod_add_lookup_table(&bq24022_gpiod_table);
1030 platform_add_devices(ARRAY_AND_SIZE(devices)); 1039 platform_add_devices(ARRAY_AND_SIZE(devices));
1031} 1040}
1032 1041
diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c
index e1db072756f2..e13bfc9b01d2 100644
--- a/arch/arm/mach-pxa/raumfeld.c
+++ b/arch/arm/mach-pxa/raumfeld.c
@@ -883,7 +883,6 @@ static struct regulator_init_data audio_va_initdata = {
883static struct fixed_voltage_config audio_va_config = { 883static struct fixed_voltage_config audio_va_config = {
884 .supply_name = "audio_va", 884 .supply_name = "audio_va",
885 .microvolts = 5000000, 885 .microvolts = 5000000,
886 .enable_high = 1,
887 .enabled_at_boot = 0, 886 .enabled_at_boot = 0,
888 .init_data = &audio_va_initdata, 887 .init_data = &audio_va_initdata,
889}; 888};
diff --git a/arch/arm/mach-pxa/zeus.c b/arch/arm/mach-pxa/zeus.c
index c411f79d4cb5..ebd654302387 100644
--- a/arch/arm/mach-pxa/zeus.c
+++ b/arch/arm/mach-pxa/zeus.c
@@ -426,7 +426,7 @@ static struct gpiod_lookup_table can_regulator_gpiod_table = {
426 .dev_id = "reg-fixed-voltage.0", 426 .dev_id = "reg-fixed-voltage.0",
427 .table = { 427 .table = {
428 GPIO_LOOKUP("gpio-pxa", ZEUS_CAN_SHDN_GPIO, 428 GPIO_LOOKUP("gpio-pxa", ZEUS_CAN_SHDN_GPIO,
429 NULL, GPIO_ACTIVE_HIGH), 429 NULL, GPIO_ACTIVE_LOW),
430 { }, 430 { },
431 }, 431 },
432}; 432};
@@ -547,7 +547,6 @@ static struct regulator_init_data zeus_ohci_regulator_data = {
547static struct fixed_voltage_config zeus_ohci_regulator_config = { 547static struct fixed_voltage_config zeus_ohci_regulator_config = {
548 .supply_name = "vbus2", 548 .supply_name = "vbus2",
549 .microvolts = 5000000, /* 5.0V */ 549 .microvolts = 5000000, /* 5.0V */
550 .enable_high = 1,
551 .startup_delay = 0, 550 .startup_delay = 0,
552 .init_data = &zeus_ohci_regulator_data, 551 .init_data = &zeus_ohci_regulator_data,
553}; 552};
diff --git a/arch/arm/mach-sa1100/assabet.c b/arch/arm/mach-sa1100/assabet.c
index dfa42496ec27..d09c3f236186 100644
--- a/arch/arm/mach-sa1100/assabet.c
+++ b/arch/arm/mach-sa1100/assabet.c
@@ -469,7 +469,6 @@ static struct regulator_consumer_supply assabet_cf_vcc_consumers[] = {
469static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = { 469static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = {
470 .supply_name = "cf-power", 470 .supply_name = "cf-power",
471 .microvolts = 3300000, 471 .microvolts = 3300000,
472 .enable_high = 1,
473}; 472};
474 473
475static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = { 474static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = {
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index 22b4106b8084..5495efa07335 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -630,7 +630,6 @@ static struct regulator_init_data cn12_power_init_data = {
630static struct fixed_voltage_config cn12_power_info = { 630static struct fixed_voltage_config cn12_power_info = {
631 .supply_name = "CN12 SD/MMC Vdd", 631 .supply_name = "CN12 SD/MMC Vdd",
632 .microvolts = 3300000, 632 .microvolts = 3300000,
633 .enable_high = 1,
634 .init_data = &cn12_power_init_data, 633 .init_data = &cn12_power_init_data,
635}; 634};
636 635
@@ -671,7 +670,6 @@ static struct regulator_init_data sdhi0_power_init_data = {
671static struct fixed_voltage_config sdhi0_power_info = { 670static struct fixed_voltage_config sdhi0_power_info = {
672 .supply_name = "CN11 SD/MMC Vdd", 671 .supply_name = "CN11 SD/MMC Vdd",
673 .microvolts = 3300000, 672 .microvolts = 3300000,
674 .enable_high = 1,
675 .init_data = &sdhi0_power_init_data, 673 .init_data = &sdhi0_power_init_data,
676}; 674};
677 675
diff --git a/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c b/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c
index 96f438d4b026..1421d5330b2c 100644
--- a/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c
+++ b/arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c
@@ -44,7 +44,6 @@ static struct fixed_voltage_config bcm43xx_vmmc = {
44 */ 44 */
45 .microvolts = 2000000, /* 1.8V */ 45 .microvolts = 2000000, /* 1.8V */
46 .startup_delay = 250 * 1000, /* 250ms */ 46 .startup_delay = 250 * 1000, /* 250ms */
47 .enable_high = 1, /* active high */
48 .enabled_at_boot = 0, /* disabled at boot */ 47 .enabled_at_boot = 0, /* disabled at boot */
49 .init_data = &bcm43xx_vmmc_data, 48 .init_data = &bcm43xx_vmmc_data,
50}; 49};
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 28f55248eb90..753a6a1b30c3 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -11,7 +11,6 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/of.h> 14#include <linux/of.h>
16#include <linux/regulator/of_regulator.h> 15#include <linux/regulator/of_regulator.h>
17#include <linux/platform_device.h> 16#include <linux/platform_device.h>
@@ -22,12 +21,7 @@
22 21
23struct pm8607_regulator_info { 22struct pm8607_regulator_info {
24 struct regulator_desc desc; 23 struct regulator_desc desc;
25 struct pm860x_chip *chip;
26 struct regulator_dev *regulator;
27 struct i2c_client *i2c;
28 struct i2c_client *i2c_8606;
29 24
30 unsigned int *vol_table;
31 unsigned int *vol_suspend; 25 unsigned int *vol_suspend;
32 26
33 int slope_double; 27 int slope_double;
@@ -210,13 +204,15 @@ static const unsigned int LDO14_suspend_table[] = {
210static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) 204static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
211{ 205{
212 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 206 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
213 int ret = -EINVAL; 207 int ret;
208
209 ret = regulator_list_voltage_table(rdev, index);
210 if (ret < 0)
211 return ret;
212
213 if (info->slope_double)
214 ret <<= 1;
214 215
215 if (info->vol_table && (index < rdev->desc->n_voltages)) {
216 ret = info->vol_table[index];
217 if (info->slope_double)
218 ret <<= 1;
219 }
220 return ret; 216 return ret;
221} 217}
222 218
@@ -257,6 +253,7 @@ static const struct regulator_ops pm8606_preg_ops = {
257 .type = REGULATOR_VOLTAGE, \ 253 .type = REGULATOR_VOLTAGE, \
258 .id = PM8607_ID_##vreg, \ 254 .id = PM8607_ID_##vreg, \
259 .owner = THIS_MODULE, \ 255 .owner = THIS_MODULE, \
256 .volt_table = vreg##_table, \
260 .n_voltages = ARRAY_SIZE(vreg##_table), \ 257 .n_voltages = ARRAY_SIZE(vreg##_table), \
261 .vsel_reg = PM8607_##vreg, \ 258 .vsel_reg = PM8607_##vreg, \
262 .vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \ 259 .vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \
@@ -266,7 +263,6 @@ static const struct regulator_ops pm8606_preg_ops = {
266 .enable_mask = 1 << (ebit), \ 263 .enable_mask = 1 << (ebit), \
267 }, \ 264 }, \
268 .slope_double = (0), \ 265 .slope_double = (0), \
269 .vol_table = (unsigned int *)&vreg##_table, \
270 .vol_suspend = (unsigned int *)&vreg##_suspend_table, \ 266 .vol_suspend = (unsigned int *)&vreg##_suspend_table, \
271} 267}
272 268
@@ -278,6 +274,7 @@ static const struct regulator_ops pm8606_preg_ops = {
278 .type = REGULATOR_VOLTAGE, \ 274 .type = REGULATOR_VOLTAGE, \
279 .id = PM8607_ID_LDO##_id, \ 275 .id = PM8607_ID_LDO##_id, \
280 .owner = THIS_MODULE, \ 276 .owner = THIS_MODULE, \
277 .volt_table = LDO##_id##_table, \
281 .n_voltages = ARRAY_SIZE(LDO##_id##_table), \ 278 .n_voltages = ARRAY_SIZE(LDO##_id##_table), \
282 .vsel_reg = PM8607_##vreg, \ 279 .vsel_reg = PM8607_##vreg, \
283 .vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \ 280 .vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \
@@ -285,7 +282,6 @@ static const struct regulator_ops pm8606_preg_ops = {
285 .enable_mask = 1 << (ebit), \ 282 .enable_mask = 1 << (ebit), \
286 }, \ 283 }, \
287 .slope_double = (0), \ 284 .slope_double = (0), \
288 .vol_table = (unsigned int *)&LDO##_id##_table, \
289 .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \ 285 .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \
290} 286}
291 287
@@ -349,6 +345,7 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
349 struct pm8607_regulator_info *info = NULL; 345 struct pm8607_regulator_info *info = NULL;
350 struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev); 346 struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
351 struct regulator_config config = { }; 347 struct regulator_config config = { };
348 struct regulator_dev *rdev;
352 struct resource *res; 349 struct resource *res;
353 int i; 350 int i;
354 351
@@ -371,13 +368,9 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
371 /* i is used to check regulator ID */ 368 /* i is used to check regulator ID */
372 i = -1; 369 i = -1;
373 } 370 }
374 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
375 info->i2c_8606 = (chip->id == CHIP_PM8607) ? chip->companion :
376 chip->client;
377 info->chip = chip;
378 371
379 /* check DVC ramp slope double */ 372 /* check DVC ramp slope double */
380 if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double) 373 if ((i == PM8607_ID_BUCK3) && chip->buck3_double)
381 info->slope_double = 1; 374 info->slope_double = 1;
382 375
383 config.dev = &pdev->dev; 376 config.dev = &pdev->dev;
@@ -392,12 +385,11 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
392 else 385 else
393 config.regmap = chip->regmap_companion; 386 config.regmap = chip->regmap_companion;
394 387
395 info->regulator = devm_regulator_register(&pdev->dev, &info->desc, 388 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
396 &config); 389 if (IS_ERR(rdev)) {
397 if (IS_ERR(info->regulator)) {
398 dev_err(&pdev->dev, "failed to register regulator %s\n", 390 dev_err(&pdev->dev, "failed to register regulator %s\n",
399 info->desc.name); 391 info->desc.name);
400 return PTR_ERR(info->regulator); 392 return PTR_ERR(rdev);
401 } 393 }
402 394
403 platform_set_drvdata(pdev, info); 395 platform_set_drvdata(pdev, info);
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index ee60a222f5eb..b7f249ee5e68 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -180,6 +180,17 @@ config REGULATOR_BCM590XX
180 BCM590xx PMUs. This will enable support for the software 180 BCM590xx PMUs. This will enable support for the software
181 controllable LDO/Switching regulators. 181 controllable LDO/Switching regulators.
182 182
183config REGULATOR_BD70528
184 tristate "ROHM BD70528 Power Regulator"
185 depends on MFD_ROHM_BD70528
186 help
187 This driver supports voltage regulators on ROHM BD70528 PMIC.
188 This will enable support for the software controllable buck
189 and LDO regulators.
190
191 This driver can also be built as a module. If so, the module
192 will be called bd70528-regulator.
193
183config REGULATOR_BD718XX 194config REGULATOR_BD718XX
184 tristate "ROHM BD71837 Power Regulator" 195 tristate "ROHM BD71837 Power Regulator"
185 depends on MFD_ROHM_BD718XX 196 depends on MFD_ROHM_BD718XX
@@ -457,6 +468,14 @@ config REGULATOR_MAX77620
457 chip to control Step-Down DC-DC and LDOs. Say Y here to 468 chip to control Step-Down DC-DC and LDOs. Say Y here to
458 enable the regulator driver. 469 enable the regulator driver.
459 470
471config REGULATOR_MAX77650
472 tristate "Maxim MAX77650/77651 regulator support"
473 depends on MFD_MAX77650
474 help
475 Regulator driver for MAX77650/77651 PMIC from Maxim
476 Semiconductor. This device has a SIMO with three independent
477 power rails and an LDO.
478
460config REGULATOR_MAX8649 479config REGULATOR_MAX8649
461 tristate "Maxim 8649 voltage regulator" 480 tristate "Maxim 8649 voltage regulator"
462 depends on I2C 481 depends on I2C
@@ -484,7 +503,7 @@ config REGULATOR_MAX8925
484 tristate "Maxim MAX8925 Power Management IC" 503 tristate "Maxim MAX8925 Power Management IC"
485 depends on MFD_MAX8925 504 depends on MFD_MAX8925
486 help 505 help
487 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. 506 Say y here to support the voltage regulator of Maxim MAX8925 PMIC.
488 507
489config REGULATOR_MAX8952 508config REGULATOR_MAX8952
490 tristate "Maxim MAX8952 Power Management IC" 509 tristate "Maxim MAX8952 Power Management IC"
@@ -501,7 +520,7 @@ config REGULATOR_MAX8973
501 select REGMAP_I2C 520 select REGMAP_I2C
502 help 521 help
503 The MAXIM MAX8973 high-efficiency. three phase, DC-DC step-down 522 The MAXIM MAX8973 high-efficiency. three phase, DC-DC step-down
504 switching regulator delievers up to 9A of output current. Each 523 switching regulator delivers up to 9A of output current. Each
505 phase operates at a 2MHz fixed frequency with a 120 deg shift 524 phase operates at a 2MHz fixed frequency with a 120 deg shift
506 from the adjacent phase, allowing the use of small magnetic component. 525 from the adjacent phase, allowing the use of small magnetic component.
507 526
@@ -646,7 +665,7 @@ config REGULATOR_PCF50633
646 tristate "NXP PCF50633 regulator driver" 665 tristate "NXP PCF50633 regulator driver"
647 depends on MFD_PCF50633 666 depends on MFD_PCF50633
648 help 667 help
649 Say Y here to support the voltage regulators and convertors 668 Say Y here to support the voltage regulators and converters
650 on PCF50633 669 on PCF50633
651 670
652config REGULATOR_PFUZE100 671config REGULATOR_PFUZE100
@@ -924,7 +943,7 @@ config REGULATOR_TPS65132
924 select REGMAP_I2C 943 select REGMAP_I2C
925 help 944 help
926 This driver supports TPS65132 single inductor - dual output 945 This driver supports TPS65132 single inductor - dual output
927 power supply specifcally designed for display panels. 946 power supply specifically designed for display panels.
928 947
929config REGULATOR_TPS65217 948config REGULATOR_TPS65217
930 tristate "TI TPS65217 Power regulators" 949 tristate "TI TPS65217 Power regulators"
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index b12e1c9b2118..1169f8a27d91 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
27obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o 27obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o
28obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o 28obj-$(CONFIG_REGULATOR_AXP20X) += axp20x-regulator.o
29obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o 29obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o
30obj-$(CONFIG_REGULATOR_BD70528) += bd70528-regulator.o
30obj-$(CONFIG_REGULATOR_BD718XX) += bd718x7-regulator.o 31obj-$(CONFIG_REGULATOR_BD718XX) += bd718x7-regulator.o
31obj-$(CONFIG_REGULATOR_BD9571MWV) += bd9571mwv-regulator.o 32obj-$(CONFIG_REGULATOR_BD9571MWV) += bd9571mwv-regulator.o
32obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 33obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
@@ -60,6 +61,7 @@ obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
60obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o 61obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
61obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o 62obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
62obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o 63obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o
64obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o
63obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 65obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
64obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 66obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
65obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o 67obj-$(CONFIG_REGULATOR_MAX8907) += max8907-regulator.o
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c
index 21e20483bd91..e0239cf3f56d 100644
--- a/drivers/regulator/act8865-regulator.c
+++ b/drivers/regulator/act8865-regulator.c
@@ -131,7 +131,7 @@
131 * ACT8865 voltage number 131 * ACT8865 voltage number
132 */ 132 */
133#define ACT8865_VOLTAGE_NUM 64 133#define ACT8865_VOLTAGE_NUM 64
134#define ACT8600_SUDCDC_VOLTAGE_NUM 255 134#define ACT8600_SUDCDC_VOLTAGE_NUM 256
135 135
136struct act8865 { 136struct act8865 {
137 struct regmap *regmap; 137 struct regmap *regmap;
@@ -222,7 +222,8 @@ static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = {
222 REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0), 222 REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0),
223 REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000), 223 REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000),
224 REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000), 224 REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000),
225 REGULATOR_LINEAR_RANGE(19000000, 191, 255, 400000), 225 REGULATOR_LINEAR_RANGE(19000000, 192, 247, 400000),
226 REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0),
226}; 227};
227 228
228static struct regulator_ops act8865_ops = { 229static struct regulator_ops act8865_ops = {
diff --git a/drivers/regulator/act8945a-regulator.c b/drivers/regulator/act8945a-regulator.c
index 603db77723b6..caa61d306a69 100644
--- a/drivers/regulator/act8945a-regulator.c
+++ b/drivers/regulator/act8945a-regulator.c
@@ -87,7 +87,8 @@ static const struct regulator_linear_range act8945a_voltage_ranges[] = {
87static int act8945a_set_suspend_state(struct regulator_dev *rdev, bool enable) 87static int act8945a_set_suspend_state(struct regulator_dev *rdev, bool enable)
88{ 88{
89 struct regmap *regmap = rdev->regmap; 89 struct regmap *regmap = rdev->regmap;
90 int id = rdev->desc->id, reg, val; 90 int id = rdev_get_id(rdev);
91 int reg, val;
91 92
92 switch (id) { 93 switch (id) {
93 case ACT8945A_ID_DCDC1: 94 case ACT8945A_ID_DCDC1:
@@ -159,7 +160,7 @@ static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode)
159{ 160{
160 struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev); 161 struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev);
161 struct regmap *regmap = rdev->regmap; 162 struct regmap *regmap = rdev->regmap;
162 int id = rdev->desc->id; 163 int id = rdev_get_id(rdev);
163 int reg, ret, val = 0; 164 int reg, ret, val = 0;
164 165
165 switch (id) { 166 switch (id) {
@@ -190,11 +191,11 @@ static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode)
190 191
191 switch (mode) { 192 switch (mode) {
192 case REGULATOR_MODE_STANDBY: 193 case REGULATOR_MODE_STANDBY:
193 if (rdev->desc->id > ACT8945A_ID_DCDC3) 194 if (id > ACT8945A_ID_DCDC3)
194 val = BIT(5); 195 val = BIT(5);
195 break; 196 break;
196 case REGULATOR_MODE_NORMAL: 197 case REGULATOR_MODE_NORMAL:
197 if (rdev->desc->id <= ACT8945A_ID_DCDC3) 198 if (id <= ACT8945A_ID_DCDC3)
198 val = BIT(5); 199 val = BIT(5);
199 break; 200 break;
200 default: 201 default:
@@ -213,7 +214,7 @@ static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode)
213static unsigned int act8945a_get_mode(struct regulator_dev *rdev) 214static unsigned int act8945a_get_mode(struct regulator_dev *rdev)
214{ 215{
215 struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev); 216 struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev);
216 int id = rdev->desc->id; 217 int id = rdev_get_id(rdev);
217 218
218 if (id < ACT8945A_ID_DCDC1 || id >= ACT8945A_ID_MAX) 219 if (id < ACT8945A_ID_DCDC1 || id >= ACT8945A_ID_MAX)
219 return -EINVAL; 220 return -EINVAL;
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index b9a93049e41e..bf3ab405eed1 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -40,35 +40,10 @@ struct arizona_ldo1 {
40 struct gpio_desc *ena_gpiod; 40 struct gpio_desc *ena_gpiod;
41}; 41};
42 42
43static int arizona_ldo1_hc_list_voltage(struct regulator_dev *rdev,
44 unsigned int selector)
45{
46 if (selector >= rdev->desc->n_voltages)
47 return -EINVAL;
48
49 if (selector == rdev->desc->n_voltages - 1)
50 return 1800000;
51 else
52 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
53}
54
55static int arizona_ldo1_hc_map_voltage(struct regulator_dev *rdev,
56 int min_uV, int max_uV)
57{
58 int sel;
59
60 sel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
61 if (sel >= rdev->desc->n_voltages)
62 sel = rdev->desc->n_voltages - 1;
63
64 return sel;
65}
66
67static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev, 43static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev,
68 unsigned sel) 44 unsigned sel)
69{ 45{
70 struct arizona_ldo1 *ldo = rdev_get_drvdata(rdev); 46 struct regmap *regmap = rdev_get_regmap(rdev);
71 struct regmap *regmap = ldo->regmap;
72 unsigned int val; 47 unsigned int val;
73 int ret; 48 int ret;
74 49
@@ -85,16 +60,12 @@ static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev,
85 if (val) 60 if (val)
86 return 0; 61 return 0;
87 62
88 val = sel << ARIZONA_LDO1_VSEL_SHIFT; 63 return regulator_set_voltage_sel_regmap(rdev, sel);
89
90 return regmap_update_bits(regmap, ARIZONA_LDO1_CONTROL_1,
91 ARIZONA_LDO1_VSEL_MASK, val);
92} 64}
93 65
94static int arizona_ldo1_hc_get_voltage_sel(struct regulator_dev *rdev) 66static int arizona_ldo1_hc_get_voltage_sel(struct regulator_dev *rdev)
95{ 67{
96 struct arizona_ldo1 *ldo = rdev_get_drvdata(rdev); 68 struct regmap *regmap = rdev_get_regmap(rdev);
97 struct regmap *regmap = ldo->regmap;
98 unsigned int val; 69 unsigned int val;
99 int ret; 70 int ret;
100 71
@@ -105,32 +76,35 @@ static int arizona_ldo1_hc_get_voltage_sel(struct regulator_dev *rdev)
105 if (val & ARIZONA_LDO1_HI_PWR) 76 if (val & ARIZONA_LDO1_HI_PWR)
106 return rdev->desc->n_voltages - 1; 77 return rdev->desc->n_voltages - 1;
107 78
108 ret = regmap_read(regmap, ARIZONA_LDO1_CONTROL_1, &val); 79 return regulator_get_voltage_sel_regmap(rdev);
109 if (ret != 0)
110 return ret;
111
112 return (val & ARIZONA_LDO1_VSEL_MASK) >> ARIZONA_LDO1_VSEL_SHIFT;
113} 80}
114 81
115static const struct regulator_ops arizona_ldo1_hc_ops = { 82static const struct regulator_ops arizona_ldo1_hc_ops = {
116 .list_voltage = arizona_ldo1_hc_list_voltage, 83 .list_voltage = regulator_list_voltage_linear_range,
117 .map_voltage = arizona_ldo1_hc_map_voltage, 84 .map_voltage = regulator_map_voltage_linear_range,
118 .get_voltage_sel = arizona_ldo1_hc_get_voltage_sel, 85 .get_voltage_sel = arizona_ldo1_hc_get_voltage_sel,
119 .set_voltage_sel = arizona_ldo1_hc_set_voltage_sel, 86 .set_voltage_sel = arizona_ldo1_hc_set_voltage_sel,
120 .get_bypass = regulator_get_bypass_regmap, 87 .get_bypass = regulator_get_bypass_regmap,
121 .set_bypass = regulator_set_bypass_regmap, 88 .set_bypass = regulator_set_bypass_regmap,
122}; 89};
123 90
91static const struct regulator_linear_range arizona_ldo1_hc_ranges[] = {
92 REGULATOR_LINEAR_RANGE(900000, 0, 0x6, 50000),
93 REGULATOR_LINEAR_RANGE(1800000, 0x7, 0x7, 0),
94};
95
124static const struct regulator_desc arizona_ldo1_hc = { 96static const struct regulator_desc arizona_ldo1_hc = {
125 .name = "LDO1", 97 .name = "LDO1",
126 .supply_name = "LDOVDD", 98 .supply_name = "LDOVDD",
127 .type = REGULATOR_VOLTAGE, 99 .type = REGULATOR_VOLTAGE,
128 .ops = &arizona_ldo1_hc_ops, 100 .ops = &arizona_ldo1_hc_ops,
129 101
102 .vsel_reg = ARIZONA_LDO1_CONTROL_1,
103 .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
130 .bypass_reg = ARIZONA_LDO1_CONTROL_1, 104 .bypass_reg = ARIZONA_LDO1_CONTROL_1,
131 .bypass_mask = ARIZONA_LDO1_BYPASS, 105 .bypass_mask = ARIZONA_LDO1_BYPASS,
132 .min_uV = 900000, 106 .linear_ranges = arizona_ldo1_hc_ranges,
133 .uV_step = 50000, 107 .n_linear_ranges = ARRAY_SIZE(arizona_ldo1_hc_ranges),
134 .n_voltages = 8, 108 .n_voltages = 8,
135 .enable_time = 1500, 109 .enable_time = 1500,
136 .ramp_delay = 24000, 110 .ramp_delay = 24000,
diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c
index 66337e12719b..e5fed289b52d 100644
--- a/drivers/regulator/as3722-regulator.c
+++ b/drivers/regulator/as3722-regulator.c
@@ -886,7 +886,7 @@ static int as3722_regulator_probe(struct platform_device *pdev)
886 as3722_regs->desc[id].min_uV = 410000; 886 as3722_regs->desc[id].min_uV = 410000;
887 } else { 887 } else {
888 as3722_regs->desc[id].n_voltages = 888 as3722_regs->desc[id].n_voltages =
889 AS3722_SD0_VSEL_MAX + 1, 889 AS3722_SD0_VSEL_MAX + 1;
890 as3722_regs->desc[id].min_uV = 610000; 890 as3722_regs->desc[id].min_uV = 610000;
891 } 891 }
892 as3722_regs->desc[id].uV_step = 10000; 892 as3722_regs->desc[id].uV_step = 10000;
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 62243957bd19..fba8f58ab769 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -367,13 +367,12 @@ static const int axp209_dcdc2_ldo3_slew_rates[] = {
367static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) 367static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
368{ 368{
369 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev); 369 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
370 const struct regulator_desc *desc = rdev->desc; 370 const struct regulator_desc *desc;
371 u8 reg, mask, enable, cfg = 0xff; 371 u8 reg, mask, enable, cfg = 0xff;
372 const int *slew_rates; 372 const int *slew_rates;
373 int rate_count = 0; 373 int rate_count = 0;
374 374
375 if (!rdev) 375 desc = rdev->desc;
376 return -EINVAL;
377 376
378 switch (axp20x->variant) { 377 switch (axp20x->variant) {
379 case AXP209_ID: 378 case AXP209_ID:
@@ -436,11 +435,13 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
436static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev) 435static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev)
437{ 436{
438 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev); 437 struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
439 const struct regulator_desc *desc = rdev->desc; 438 const struct regulator_desc *desc;
440 439
441 if (!rdev) 440 if (!rdev)
442 return -EINVAL; 441 return -EINVAL;
443 442
443 desc = rdev->desc;
444
444 switch (axp20x->variant) { 445 switch (axp20x->variant) {
445 case AXP209_ID: 446 case AXP209_ID:
446 if ((desc->id == AXP20X_LDO3) && 447 if ((desc->id == AXP20X_LDO3) &&
diff --git a/drivers/regulator/bd70528-regulator.c b/drivers/regulator/bd70528-regulator.c
new file mode 100644
index 000000000000..30e3ed430a8a
--- /dev/null
+++ b/drivers/regulator/bd70528-regulator.c
@@ -0,0 +1,289 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 ROHM Semiconductors
3// bd70528-regulator.c ROHM BD70528MWV regulator driver
4
5#include <linux/delay.h>
6#include <linux/err.h>
7#include <linux/gpio.h>
8#include <linux/interrupt.h>
9#include <linux/kernel.h>
10#include <linux/mfd/rohm-bd70528.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/platform_device.h>
14#include <linux/regmap.h>
15#include <linux/regulator/driver.h>
16#include <linux/regulator/machine.h>
17#include <linux/regulator/of_regulator.h>
18#include <linux/slab.h>
19
20#define BUCK_RAMPRATE_250MV 0
21#define BUCK_RAMPRATE_125MV 1
22#define BUCK_RAMP_MAX 250
23
24static const struct regulator_linear_range bd70528_buck1_volts[] = {
25 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 600000),
26 REGULATOR_LINEAR_RANGE(2750000, 0x2, 0xf, 50000),
27};
28static const struct regulator_linear_range bd70528_buck2_volts[] = {
29 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x1, 300000),
30 REGULATOR_LINEAR_RANGE(1550000, 0x2, 0xd, 50000),
31 REGULATOR_LINEAR_RANGE(3000000, 0xe, 0xf, 300000),
32};
33static const struct regulator_linear_range bd70528_buck3_volts[] = {
34 REGULATOR_LINEAR_RANGE(800000, 0x00, 0xd, 50000),
35 REGULATOR_LINEAR_RANGE(1800000, 0xe, 0xf, 0),
36};
37
38/* All LDOs have same voltage ranges */
39static const struct regulator_linear_range bd70528_ldo_volts[] = {
40 REGULATOR_LINEAR_RANGE(1650000, 0x0, 0x07, 50000),
41 REGULATOR_LINEAR_RANGE(2100000, 0x8, 0x0f, 100000),
42 REGULATOR_LINEAR_RANGE(2850000, 0x10, 0x19, 50000),
43 REGULATOR_LINEAR_RANGE(3300000, 0x19, 0x1f, 0),
44};
45
46/* Also both LEDs support same voltages */
47static const unsigned int led_volts[] = {
48 20000, 30000
49};
50
51static int bd70528_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
52{
53 if (ramp_delay > 0 && ramp_delay <= BUCK_RAMP_MAX) {
54 unsigned int ramp_value = BUCK_RAMPRATE_250MV;
55
56 if (ramp_delay <= 125)
57 ramp_value = BUCK_RAMPRATE_125MV;
58
59 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
60 BD70528_MASK_BUCK_RAMP,
61 ramp_value << BD70528_SIFT_BUCK_RAMP);
62 }
63 dev_err(&rdev->dev, "%s: ramp_delay: %d not supported\n",
64 rdev->desc->name, ramp_delay);
65 return -EINVAL;
66}
67
68static int bd70528_led_set_voltage_sel(struct regulator_dev *rdev,
69 unsigned int sel)
70{
71 int ret;
72
73 ret = regulator_is_enabled_regmap(rdev);
74 if (ret < 0)
75 return ret;
76
77 if (ret == 0)
78 return regulator_set_voltage_sel_regmap(rdev, sel);
79
80 dev_err(&rdev->dev,
81 "LED voltage change not allowed when led is enabled\n");
82
83 return -EBUSY;
84}
85
86static const struct regulator_ops bd70528_buck_ops = {
87 .enable = regulator_enable_regmap,
88 .disable = regulator_disable_regmap,
89 .is_enabled = regulator_is_enabled_regmap,
90 .list_voltage = regulator_list_voltage_linear_range,
91 .set_voltage_sel = regulator_set_voltage_sel_regmap,
92 .get_voltage_sel = regulator_get_voltage_sel_regmap,
93 .set_voltage_time_sel = regulator_set_voltage_time_sel,
94 .set_ramp_delay = bd70528_set_ramp_delay,
95};
96
97static const struct regulator_ops bd70528_ldo_ops = {
98 .enable = regulator_enable_regmap,
99 .disable = regulator_disable_regmap,
100 .is_enabled = regulator_is_enabled_regmap,
101 .list_voltage = regulator_list_voltage_linear_range,
102 .set_voltage_sel = regulator_set_voltage_sel_regmap,
103 .get_voltage_sel = regulator_get_voltage_sel_regmap,
104 .set_voltage_time_sel = regulator_set_voltage_time_sel,
105 .set_ramp_delay = bd70528_set_ramp_delay,
106};
107
108static const struct regulator_ops bd70528_led_ops = {
109 .enable = regulator_enable_regmap,
110 .disable = regulator_disable_regmap,
111 .is_enabled = regulator_is_enabled_regmap,
112 .list_voltage = regulator_list_voltage_table,
113 .set_voltage_sel = bd70528_led_set_voltage_sel,
114 .get_voltage_sel = regulator_get_voltage_sel_regmap,
115};
116
117static const struct regulator_desc bd70528_desc[] = {
118 {
119 .name = "buck1",
120 .of_match = of_match_ptr("BUCK1"),
121 .regulators_node = of_match_ptr("regulators"),
122 .id = BD70528_BUCK1,
123 .ops = &bd70528_buck_ops,
124 .type = REGULATOR_VOLTAGE,
125 .linear_ranges = bd70528_buck1_volts,
126 .n_linear_ranges = ARRAY_SIZE(bd70528_buck1_volts),
127 .n_voltages = BD70528_BUCK_VOLTS,
128 .enable_reg = BD70528_REG_BUCK1_EN,
129 .enable_mask = BD70528_MASK_RUN_EN,
130 .vsel_reg = BD70528_REG_BUCK1_VOLT,
131 .vsel_mask = BD70528_MASK_BUCK_VOLT,
132 .owner = THIS_MODULE,
133 },
134 {
135 .name = "buck2",
136 .of_match = of_match_ptr("BUCK2"),
137 .regulators_node = of_match_ptr("regulators"),
138 .id = BD70528_BUCK2,
139 .ops = &bd70528_buck_ops,
140 .type = REGULATOR_VOLTAGE,
141 .linear_ranges = bd70528_buck2_volts,
142 .n_linear_ranges = ARRAY_SIZE(bd70528_buck2_volts),
143 .n_voltages = BD70528_BUCK_VOLTS,
144 .enable_reg = BD70528_REG_BUCK2_EN,
145 .enable_mask = BD70528_MASK_RUN_EN,
146 .vsel_reg = BD70528_REG_BUCK2_VOLT,
147 .vsel_mask = BD70528_MASK_BUCK_VOLT,
148 .owner = THIS_MODULE,
149 },
150 {
151 .name = "buck3",
152 .of_match = of_match_ptr("BUCK3"),
153 .regulators_node = of_match_ptr("regulators"),
154 .id = BD70528_BUCK3,
155 .ops = &bd70528_buck_ops,
156 .type = REGULATOR_VOLTAGE,
157 .linear_ranges = bd70528_buck3_volts,
158 .n_linear_ranges = ARRAY_SIZE(bd70528_buck3_volts),
159 .n_voltages = BD70528_BUCK_VOLTS,
160 .enable_reg = BD70528_REG_BUCK3_EN,
161 .enable_mask = BD70528_MASK_RUN_EN,
162 .vsel_reg = BD70528_REG_BUCK3_VOLT,
163 .vsel_mask = BD70528_MASK_BUCK_VOLT,
164 .owner = THIS_MODULE,
165 },
166 {
167 .name = "ldo1",
168 .of_match = of_match_ptr("LDO1"),
169 .regulators_node = of_match_ptr("regulators"),
170 .id = BD70528_LDO1,
171 .ops = &bd70528_ldo_ops,
172 .type = REGULATOR_VOLTAGE,
173 .linear_ranges = bd70528_ldo_volts,
174 .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
175 .n_voltages = BD70528_LDO_VOLTS,
176 .enable_reg = BD70528_REG_LDO1_EN,
177 .enable_mask = BD70528_MASK_RUN_EN,
178 .vsel_reg = BD70528_REG_LDO1_VOLT,
179 .vsel_mask = BD70528_MASK_LDO_VOLT,
180 .owner = THIS_MODULE,
181 },
182 {
183 .name = "ldo2",
184 .of_match = of_match_ptr("LDO2"),
185 .regulators_node = of_match_ptr("regulators"),
186 .id = BD70528_LDO2,
187 .ops = &bd70528_ldo_ops,
188 .type = REGULATOR_VOLTAGE,
189 .linear_ranges = bd70528_ldo_volts,
190 .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
191 .n_voltages = BD70528_LDO_VOLTS,
192 .enable_reg = BD70528_REG_LDO2_EN,
193 .enable_mask = BD70528_MASK_RUN_EN,
194 .vsel_reg = BD70528_REG_LDO2_VOLT,
195 .vsel_mask = BD70528_MASK_LDO_VOLT,
196 .owner = THIS_MODULE,
197 },
198 {
199 .name = "ldo3",
200 .of_match = of_match_ptr("LDO3"),
201 .regulators_node = of_match_ptr("regulators"),
202 .id = BD70528_LDO3,
203 .ops = &bd70528_ldo_ops,
204 .type = REGULATOR_VOLTAGE,
205 .linear_ranges = bd70528_ldo_volts,
206 .n_linear_ranges = ARRAY_SIZE(bd70528_ldo_volts),
207 .n_voltages = BD70528_LDO_VOLTS,
208 .enable_reg = BD70528_REG_LDO3_EN,
209 .enable_mask = BD70528_MASK_RUN_EN,
210 .vsel_reg = BD70528_REG_LDO3_VOLT,
211 .vsel_mask = BD70528_MASK_LDO_VOLT,
212 .owner = THIS_MODULE,
213 },
214 {
215 .name = "ldo_led1",
216 .of_match = of_match_ptr("LDO_LED1"),
217 .regulators_node = of_match_ptr("regulators"),
218 .id = BD70528_LED1,
219 .ops = &bd70528_led_ops,
220 .type = REGULATOR_VOLTAGE,
221 .volt_table = &led_volts[0],
222 .n_voltages = ARRAY_SIZE(led_volts),
223 .enable_reg = BD70528_REG_LED_EN,
224 .enable_mask = BD70528_MASK_LED1_EN,
225 .vsel_reg = BD70528_REG_LED_VOLT,
226 .vsel_mask = BD70528_MASK_LED1_VOLT,
227 .owner = THIS_MODULE,
228 },
229 {
230 .name = "ldo_led2",
231 .of_match = of_match_ptr("LDO_LED2"),
232 .regulators_node = of_match_ptr("regulators"),
233 .id = BD70528_LED2,
234 .ops = &bd70528_led_ops,
235 .type = REGULATOR_VOLTAGE,
236 .volt_table = &led_volts[0],
237 .n_voltages = ARRAY_SIZE(led_volts),
238 .enable_reg = BD70528_REG_LED_EN,
239 .enable_mask = BD70528_MASK_LED2_EN,
240 .vsel_reg = BD70528_REG_LED_VOLT,
241 .vsel_mask = BD70528_MASK_LED2_VOLT,
242 .owner = THIS_MODULE,
243 },
244
245};
246
247static int bd70528_probe(struct platform_device *pdev)
248{
249 struct rohm_regmap_dev *bd70528;
250 int i;
251 struct regulator_config config = {
252 .dev = pdev->dev.parent,
253 };
254
255 bd70528 = dev_get_drvdata(pdev->dev.parent);
256 if (!bd70528) {
257 dev_err(&pdev->dev, "No MFD driver data\n");
258 return -EINVAL;
259 }
260
261 config.regmap = bd70528->regmap;
262
263 for (i = 0; i < ARRAY_SIZE(bd70528_desc); i++) {
264 struct regulator_dev *rdev;
265
266 rdev = devm_regulator_register(&pdev->dev, &bd70528_desc[i],
267 &config);
268 if (IS_ERR(rdev)) {
269 dev_err(&pdev->dev,
270 "failed to register %s regulator\n",
271 bd70528_desc[i].name);
272 return PTR_ERR(rdev);
273 }
274 }
275 return 0;
276}
277
278static struct platform_driver bd70528_regulator = {
279 .driver = {
280 .name = "bd70528-pmic"
281 },
282 .probe = bd70528_probe,
283};
284
285module_platform_driver(bd70528_regulator);
286
287MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
288MODULE_DESCRIPTION("BD70528 voltage regulator driver");
289MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index b8dcdc21dc22..b2191be49670 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -79,7 +79,7 @@ static int bd718xx_set_voltage_sel_pickable_restricted(
79 return regulator_set_voltage_sel_pickable_regmap(rdev, sel); 79 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
80} 80}
81 81
82static struct regulator_ops bd718xx_pickable_range_ldo_ops = { 82static const struct regulator_ops bd718xx_pickable_range_ldo_ops = {
83 .enable = regulator_enable_regmap, 83 .enable = regulator_enable_regmap,
84 .disable = regulator_disable_regmap, 84 .disable = regulator_disable_regmap,
85 .is_enabled = regulator_is_enabled_regmap, 85 .is_enabled = regulator_is_enabled_regmap,
@@ -88,7 +88,7 @@ static struct regulator_ops bd718xx_pickable_range_ldo_ops = {
88 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, 88 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
89}; 89};
90 90
91static struct regulator_ops bd718xx_pickable_range_buck_ops = { 91static const struct regulator_ops bd718xx_pickable_range_buck_ops = {
92 .enable = regulator_enable_regmap, 92 .enable = regulator_enable_regmap,
93 .disable = regulator_disable_regmap, 93 .disable = regulator_disable_regmap,
94 .is_enabled = regulator_is_enabled_regmap, 94 .is_enabled = regulator_is_enabled_regmap,
@@ -98,7 +98,7 @@ static struct regulator_ops bd718xx_pickable_range_buck_ops = {
98 .set_voltage_time_sel = regulator_set_voltage_time_sel, 98 .set_voltage_time_sel = regulator_set_voltage_time_sel,
99}; 99};
100 100
101static struct regulator_ops bd718xx_ldo_regulator_ops = { 101static const struct regulator_ops bd718xx_ldo_regulator_ops = {
102 .enable = regulator_enable_regmap, 102 .enable = regulator_enable_regmap,
103 .disable = regulator_disable_regmap, 103 .disable = regulator_disable_regmap,
104 .is_enabled = regulator_is_enabled_regmap, 104 .is_enabled = regulator_is_enabled_regmap,
@@ -107,7 +107,7 @@ static struct regulator_ops bd718xx_ldo_regulator_ops = {
107 .get_voltage_sel = regulator_get_voltage_sel_regmap, 107 .get_voltage_sel = regulator_get_voltage_sel_regmap,
108}; 108};
109 109
110static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = { 110static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
111 .enable = regulator_enable_regmap, 111 .enable = regulator_enable_regmap,
112 .disable = regulator_disable_regmap, 112 .disable = regulator_disable_regmap,
113 .is_enabled = regulator_is_enabled_regmap, 113 .is_enabled = regulator_is_enabled_regmap,
@@ -116,7 +116,7 @@ static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
116 .get_voltage_sel = regulator_get_voltage_sel_regmap, 116 .get_voltage_sel = regulator_get_voltage_sel_regmap,
117}; 117};
118 118
119static struct regulator_ops bd718xx_buck_regulator_ops = { 119static const struct regulator_ops bd718xx_buck_regulator_ops = {
120 .enable = regulator_enable_regmap, 120 .enable = regulator_enable_regmap,
121 .disable = regulator_disable_regmap, 121 .disable = regulator_disable_regmap,
122 .is_enabled = regulator_is_enabled_regmap, 122 .is_enabled = regulator_is_enabled_regmap,
@@ -126,7 +126,7 @@ static struct regulator_ops bd718xx_buck_regulator_ops = {
126 .set_voltage_time_sel = regulator_set_voltage_time_sel, 126 .set_voltage_time_sel = regulator_set_voltage_time_sel,
127}; 127};
128 128
129static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = { 129static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
130 .enable = regulator_enable_regmap, 130 .enable = regulator_enable_regmap,
131 .disable = regulator_disable_regmap, 131 .disable = regulator_disable_regmap,
132 .is_enabled = regulator_is_enabled_regmap, 132 .is_enabled = regulator_is_enabled_regmap,
@@ -137,7 +137,7 @@ static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
137 .set_voltage_time_sel = regulator_set_voltage_time_sel, 137 .set_voltage_time_sel = regulator_set_voltage_time_sel,
138}; 138};
139 139
140static struct regulator_ops bd718xx_dvs_buck_regulator_ops = { 140static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
141 .enable = regulator_enable_regmap, 141 .enable = regulator_enable_regmap,
142 .disable = regulator_disable_regmap, 142 .disable = regulator_disable_regmap,
143 .is_enabled = regulator_is_enabled_regmap, 143 .is_enabled = regulator_is_enabled_regmap,
@@ -350,6 +350,135 @@ static const struct reg_init bd71837_ldo6_inits[] = {
350 }, 350 },
351}; 351};
352 352
353#define NUM_DVS_BUCKS 4
354
355struct of_dvs_setting {
356 const char *prop;
357 unsigned int reg;
358};
359
360static int set_dvs_levels(const struct of_dvs_setting *dvs,
361 struct device_node *np,
362 const struct regulator_desc *desc,
363 struct regmap *regmap)
364{
365 int ret, i;
366 unsigned int uv;
367
368 ret = of_property_read_u32(np, dvs->prop, &uv);
369 if (ret) {
370 if (ret != -EINVAL)
371 return ret;
372 return 0;
373 }
374
375 for (i = 0; i < desc->n_voltages; i++) {
376 ret = regulator_desc_list_voltage_linear_range(desc, i);
377 if (ret < 0)
378 continue;
379 if (ret == uv) {
380 i <<= ffs(desc->vsel_mask) - 1;
381 ret = regmap_update_bits(regmap, dvs->reg,
382 DVS_BUCK_RUN_MASK, i);
383 break;
384 }
385 }
386 return ret;
387}
388
389static int buck4_set_hw_dvs_levels(struct device_node *np,
390 const struct regulator_desc *desc,
391 struct regulator_config *cfg)
392{
393 int ret, i;
394 const struct of_dvs_setting dvs[] = {
395 {
396 .prop = "rohm,dvs-run-voltage",
397 .reg = BD71837_REG_BUCK4_VOLT_RUN,
398 },
399 };
400
401 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
402 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
403 if (ret)
404 break;
405 }
406 return ret;
407}
408static int buck3_set_hw_dvs_levels(struct device_node *np,
409 const struct regulator_desc *desc,
410 struct regulator_config *cfg)
411{
412 int ret, i;
413 const struct of_dvs_setting dvs[] = {
414 {
415 .prop = "rohm,dvs-run-voltage",
416 .reg = BD71837_REG_BUCK3_VOLT_RUN,
417 },
418 };
419
420 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
421 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
422 if (ret)
423 break;
424 }
425 return ret;
426}
427
428static int buck2_set_hw_dvs_levels(struct device_node *np,
429 const struct regulator_desc *desc,
430 struct regulator_config *cfg)
431{
432 int ret, i;
433 const struct of_dvs_setting dvs[] = {
434 {
435 .prop = "rohm,dvs-run-voltage",
436 .reg = BD718XX_REG_BUCK2_VOLT_RUN,
437 },
438 {
439 .prop = "rohm,dvs-idle-voltage",
440 .reg = BD718XX_REG_BUCK2_VOLT_IDLE,
441 },
442 };
443
444
445
446 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
447 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
448 if (ret)
449 break;
450 }
451 return ret;
452}
453
454static int buck1_set_hw_dvs_levels(struct device_node *np,
455 const struct regulator_desc *desc,
456 struct regulator_config *cfg)
457{
458 int ret, i;
459 const struct of_dvs_setting dvs[] = {
460 {
461 .prop = "rohm,dvs-run-voltage",
462 .reg = BD718XX_REG_BUCK1_VOLT_RUN,
463 },
464 {
465 .prop = "rohm,dvs-idle-voltage",
466 .reg = BD718XX_REG_BUCK1_VOLT_IDLE,
467 },
468 {
469 .prop = "rohm,dvs-suspend-voltage",
470 .reg = BD718XX_REG_BUCK1_VOLT_SUSP,
471 },
472 };
473
474 for (i = 0; i < ARRAY_SIZE(dvs); i++) {
475 ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
476 if (ret)
477 break;
478 }
479 return ret;
480}
481
353static const struct bd718xx_regulator_data bd71847_regulators[] = { 482static const struct bd718xx_regulator_data bd71847_regulators[] = {
354 { 483 {
355 .desc = { 484 .desc = {
@@ -368,6 +497,7 @@ static const struct bd718xx_regulator_data bd71847_regulators[] = {
368 .enable_reg = BD718XX_REG_BUCK1_CTRL, 497 .enable_reg = BD718XX_REG_BUCK1_CTRL,
369 .enable_mask = BD718XX_BUCK_EN, 498 .enable_mask = BD718XX_BUCK_EN,
370 .owner = THIS_MODULE, 499 .owner = THIS_MODULE,
500 .of_parse_cb = buck1_set_hw_dvs_levels,
371 }, 501 },
372 .init = { 502 .init = {
373 .reg = BD718XX_REG_BUCK1_CTRL, 503 .reg = BD718XX_REG_BUCK1_CTRL,
@@ -391,6 +521,7 @@ static const struct bd718xx_regulator_data bd71847_regulators[] = {
391 .enable_reg = BD718XX_REG_BUCK2_CTRL, 521 .enable_reg = BD718XX_REG_BUCK2_CTRL,
392 .enable_mask = BD718XX_BUCK_EN, 522 .enable_mask = BD718XX_BUCK_EN,
393 .owner = THIS_MODULE, 523 .owner = THIS_MODULE,
524 .of_parse_cb = buck2_set_hw_dvs_levels,
394 }, 525 },
395 .init = { 526 .init = {
396 .reg = BD718XX_REG_BUCK2_CTRL, 527 .reg = BD718XX_REG_BUCK2_CTRL,
@@ -662,6 +793,7 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
662 .enable_reg = BD718XX_REG_BUCK1_CTRL, 793 .enable_reg = BD718XX_REG_BUCK1_CTRL,
663 .enable_mask = BD718XX_BUCK_EN, 794 .enable_mask = BD718XX_BUCK_EN,
664 .owner = THIS_MODULE, 795 .owner = THIS_MODULE,
796 .of_parse_cb = buck1_set_hw_dvs_levels,
665 }, 797 },
666 .init = { 798 .init = {
667 .reg = BD718XX_REG_BUCK1_CTRL, 799 .reg = BD718XX_REG_BUCK1_CTRL,
@@ -685,6 +817,7 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
685 .enable_reg = BD718XX_REG_BUCK2_CTRL, 817 .enable_reg = BD718XX_REG_BUCK2_CTRL,
686 .enable_mask = BD718XX_BUCK_EN, 818 .enable_mask = BD718XX_BUCK_EN,
687 .owner = THIS_MODULE, 819 .owner = THIS_MODULE,
820 .of_parse_cb = buck2_set_hw_dvs_levels,
688 }, 821 },
689 .init = { 822 .init = {
690 .reg = BD718XX_REG_BUCK2_CTRL, 823 .reg = BD718XX_REG_BUCK2_CTRL,
@@ -708,6 +841,7 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
708 .enable_reg = BD71837_REG_BUCK3_CTRL, 841 .enable_reg = BD71837_REG_BUCK3_CTRL,
709 .enable_mask = BD718XX_BUCK_EN, 842 .enable_mask = BD718XX_BUCK_EN,
710 .owner = THIS_MODULE, 843 .owner = THIS_MODULE,
844 .of_parse_cb = buck3_set_hw_dvs_levels,
711 }, 845 },
712 .init = { 846 .init = {
713 .reg = BD71837_REG_BUCK3_CTRL, 847 .reg = BD71837_REG_BUCK3_CTRL,
@@ -731,6 +865,7 @@ static const struct bd718xx_regulator_data bd71837_regulators[] = {
731 .enable_reg = BD71837_REG_BUCK4_CTRL, 865 .enable_reg = BD71837_REG_BUCK4_CTRL,
732 .enable_mask = BD718XX_BUCK_EN, 866 .enable_mask = BD718XX_BUCK_EN,
733 .owner = THIS_MODULE, 867 .owner = THIS_MODULE,
868 .of_parse_cb = buck4_set_hw_dvs_levels,
734 }, 869 },
735 .init = { 870 .init = {
736 .reg = BD71837_REG_BUCK4_CTRL, 871 .reg = BD71837_REG_BUCK4_CTRL,
@@ -1029,6 +1164,7 @@ static int bd718xx_probe(struct platform_device *pdev)
1029 }; 1164 };
1030 1165
1031 int i, j, err; 1166 int i, j, err;
1167 bool use_snvs;
1032 1168
1033 mfd = dev_get_drvdata(pdev->dev.parent); 1169 mfd = dev_get_drvdata(pdev->dev.parent);
1034 if (!mfd) { 1170 if (!mfd) {
@@ -1055,27 +1191,28 @@ static int bd718xx_probe(struct platform_device *pdev)
1055 BD718XX_REG_REGLOCK); 1191 BD718XX_REG_REGLOCK);
1056 } 1192 }
1057 1193
1058 /* At poweroff transition PMIC HW disables EN bit for regulators but 1194 use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
1059 * leaves SEL bit untouched. So if state transition from POWEROFF 1195 "rohm,reset-snvs-powered");
1060 * is done to SNVS - then all power rails controlled by SW (having 1196
1061 * SEL bit set) stay disabled as EN is cleared. This may result boot 1197 /*
1062 * failure if any crucial systems are powered by these rails.
1063 *
1064 * Change the next stage from poweroff to be READY instead of SNVS 1198 * Change the next stage from poweroff to be READY instead of SNVS
1065 * for all reset types because OTP loading at READY will clear SEL 1199 * for all reset types because OTP loading at READY will clear SEL
1066 * bit allowing HW defaults for power rails to be used 1200 * bit allowing HW defaults for power rails to be used
1067 */ 1201 */
1068 err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1, 1202 if (!use_snvs) {
1069 BD718XX_ON_REQ_POWEROFF_MASK | 1203 err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1,
1070 BD718XX_SWRESET_POWEROFF_MASK | 1204 BD718XX_ON_REQ_POWEROFF_MASK |
1071 BD718XX_WDOG_POWEROFF_MASK | 1205 BD718XX_SWRESET_POWEROFF_MASK |
1072 BD718XX_KEY_L_POWEROFF_MASK, 1206 BD718XX_WDOG_POWEROFF_MASK |
1073 BD718XX_POWOFF_TO_RDY); 1207 BD718XX_KEY_L_POWEROFF_MASK,
1074 if (err) { 1208 BD718XX_POWOFF_TO_RDY);
1075 dev_err(&pdev->dev, "Failed to change reset target\n"); 1209 if (err) {
1076 goto err; 1210 dev_err(&pdev->dev, "Failed to change reset target\n");
1077 } else { 1211 goto err;
1078 dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n"); 1212 } else {
1213 dev_dbg(&pdev->dev,
1214 "Changed all resets from SVNS to READY\n");
1215 }
1079 } 1216 }
1080 1217
1081 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) { 1218 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
@@ -1098,19 +1235,33 @@ static int bd718xx_probe(struct platform_device *pdev)
1098 err = PTR_ERR(rdev); 1235 err = PTR_ERR(rdev);
1099 goto err; 1236 goto err;
1100 } 1237 }
1101 /* Regulator register gets the regulator constraints and 1238
1239 /*
1240 * Regulator register gets the regulator constraints and
1102 * applies them (set_machine_constraints). This should have 1241 * applies them (set_machine_constraints). This should have
1103 * turned the control register(s) to correct values and we 1242 * turned the control register(s) to correct values and we
1104 * can now switch the control from PMIC state machine to the 1243 * can now switch the control from PMIC state machine to the
1105 * register interface 1244 * register interface
1245 *
1246 * At poweroff transition PMIC HW disables EN bit for
1247 * regulators but leaves SEL bit untouched. So if state
1248 * transition from POWEROFF is done to SNVS - then all power
1249 * rails controlled by SW (having SEL bit set) stay disabled
1250 * as EN is cleared. This will result boot failure if any
1251 * crucial systems are powered by these rails. We don't
1252 * enable SW control for crucial regulators if snvs state is
1253 * used
1106 */ 1254 */
1107 err = regmap_update_bits(mfd->regmap, r->init.reg, 1255 if (!use_snvs || !rdev->constraints->always_on ||
1108 r->init.mask, r->init.val); 1256 !rdev->constraints->boot_on) {
1109 if (err) { 1257 err = regmap_update_bits(mfd->regmap, r->init.reg,
1110 dev_err(&pdev->dev, 1258 r->init.mask, r->init.val);
1111 "Failed to write BUCK/LDO SEL bit for (%s)\n", 1259 if (err) {
1112 desc->name); 1260 dev_err(&pdev->dev,
1113 goto err; 1261 "Failed to take control for (%s)\n",
1262 desc->name);
1263 goto err;
1264 }
1114 } 1265 }
1115 for (j = 0; j < r->additional_init_amnt; j++) { 1266 for (j = 0; j < r->additional_init_amnt; j++) {
1116 err = regmap_update_bits(mfd->regmap, 1267 err = regmap_update_bits(mfd->regmap,
diff --git a/drivers/regulator/bd9571mwv-regulator.c b/drivers/regulator/bd9571mwv-regulator.c
index e12dd1f750f3..e690c2ce5b3c 100644
--- a/drivers/regulator/bd9571mwv-regulator.c
+++ b/drivers/regulator/bd9571mwv-regulator.c
@@ -100,7 +100,7 @@ static int bd9571mwv_reg_set_voltage_sel_regmap(struct regulator_dev *rdev,
100} 100}
101 101
102/* Operations permitted on AVS voltage regulator */ 102/* Operations permitted on AVS voltage regulator */
103static struct regulator_ops avs_ops = { 103static const struct regulator_ops avs_ops = {
104 .set_voltage_sel = bd9571mwv_avs_set_voltage_sel_regmap, 104 .set_voltage_sel = bd9571mwv_avs_set_voltage_sel_regmap,
105 .map_voltage = regulator_map_voltage_linear, 105 .map_voltage = regulator_map_voltage_linear,
106 .get_voltage_sel = bd9571mwv_avs_get_voltage_sel_regmap, 106 .get_voltage_sel = bd9571mwv_avs_get_voltage_sel_regmap,
@@ -108,7 +108,7 @@ static struct regulator_ops avs_ops = {
108}; 108};
109 109
110/* Operations permitted on voltage regulators */ 110/* Operations permitted on voltage regulators */
111static struct regulator_ops reg_ops = { 111static const struct regulator_ops reg_ops = {
112 .set_voltage_sel = bd9571mwv_reg_set_voltage_sel_regmap, 112 .set_voltage_sel = bd9571mwv_reg_set_voltage_sel_regmap,
113 .map_voltage = regulator_map_voltage_linear, 113 .map_voltage = regulator_map_voltage_linear,
114 .get_voltage_sel = regulator_get_voltage_sel_regmap, 114 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -116,13 +116,13 @@ static struct regulator_ops reg_ops = {
116}; 116};
117 117
118/* Operations permitted on voltage monitors */ 118/* Operations permitted on voltage monitors */
119static struct regulator_ops vid_ops = { 119static const struct regulator_ops vid_ops = {
120 .map_voltage = regulator_map_voltage_linear, 120 .map_voltage = regulator_map_voltage_linear,
121 .get_voltage_sel = regulator_get_voltage_sel_regmap, 121 .get_voltage_sel = regulator_get_voltage_sel_regmap,
122 .list_voltage = regulator_list_voltage_linear, 122 .list_voltage = regulator_list_voltage_linear,
123}; 123};
124 124
125static struct regulator_desc regulators[] = { 125static const struct regulator_desc regulators[] = {
126 BD9571MWV_REG("VD09", "vd09", VD09, avs_ops, 0, 0x7f, 126 BD9571MWV_REG("VD09", "vd09", VD09, avs_ops, 0, 0x7f,
127 0x80, 600000, 10000, 0x3c), 127 0x80, 600000, 10000, 0x3c),
128 BD9571MWV_REG("VD18", "vd18", VD18, vid_ops, BD9571MWV_VD18_VID, 0xf, 128 BD9571MWV_REG("VD18", "vd18", VD18, vid_ops, BD9571MWV_VD18_VID, 0xf,
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 19b35d9f3a97..68473d0cc57e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -23,7 +23,6 @@
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/suspend.h> 24#include <linux/suspend.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/gpio.h>
27#include <linux/gpio/consumer.h> 26#include <linux/gpio/consumer.h>
28#include <linux/of.h> 27#include <linux/of.h>
29#include <linux/regmap.h> 28#include <linux/regmap.h>
@@ -82,7 +81,6 @@ struct regulator_enable_gpio {
82 struct gpio_desc *gpiod; 81 struct gpio_desc *gpiod;
83 u32 enable_count; /* a number of enabled shared GPIO */ 82 u32 enable_count; /* a number of enabled shared GPIO */
84 u32 request_count; /* a number of requested shared GPIO */ 83 u32 request_count; /* a number of requested shared GPIO */
85 unsigned int ena_gpio_invert:1;
86}; 84};
87 85
88/* 86/*
@@ -145,14 +143,6 @@ static bool regulator_ops_is_valid(struct regulator_dev *rdev, int ops)
145 return false; 143 return false;
146} 144}
147 145
148static inline struct regulator_dev *rdev_get_supply(struct regulator_dev *rdev)
149{
150 if (rdev && rdev->supply)
151 return rdev->supply->rdev;
152
153 return NULL;
154}
155
156/** 146/**
157 * regulator_lock_nested - lock a single regulator 147 * regulator_lock_nested - lock a single regulator
158 * @rdev: regulator source 148 * @rdev: regulator source
@@ -326,7 +316,7 @@ err_unlock:
326 * @rdev: regulator source 316 * @rdev: regulator source
327 * @ww_ctx: w/w mutex acquire context 317 * @ww_ctx: w/w mutex acquire context
328 * 318 *
329 * Unlock all regulators related with rdev by coupling or suppling. 319 * Unlock all regulators related with rdev by coupling or supplying.
330 */ 320 */
331static void regulator_unlock_dependent(struct regulator_dev *rdev, 321static void regulator_unlock_dependent(struct regulator_dev *rdev,
332 struct ww_acquire_ctx *ww_ctx) 322 struct ww_acquire_ctx *ww_ctx)
@@ -341,7 +331,7 @@ static void regulator_unlock_dependent(struct regulator_dev *rdev,
341 * @ww_ctx: w/w mutex acquire context 331 * @ww_ctx: w/w mutex acquire context
342 * 332 *
343 * This function as a wrapper on regulator_lock_recursive(), which locks 333 * This function as a wrapper on regulator_lock_recursive(), which locks
344 * all regulators related with rdev by coupling or suppling. 334 * all regulators related with rdev by coupling or supplying.
345 */ 335 */
346static void regulator_lock_dependent(struct regulator_dev *rdev, 336static void regulator_lock_dependent(struct regulator_dev *rdev,
347 struct ww_acquire_ctx *ww_ctx) 337 struct ww_acquire_ctx *ww_ctx)
@@ -924,14 +914,14 @@ static int drms_uA_update(struct regulator_dev *rdev)
924 int current_uA = 0, output_uV, input_uV, err; 914 int current_uA = 0, output_uV, input_uV, err;
925 unsigned int mode; 915 unsigned int mode;
926 916
927 lockdep_assert_held_once(&rdev->mutex.base);
928
929 /* 917 /*
930 * first check to see if we can set modes at all, otherwise just 918 * first check to see if we can set modes at all, otherwise just
931 * tell the consumer everything is OK. 919 * tell the consumer everything is OK.
932 */ 920 */
933 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS)) 921 if (!regulator_ops_is_valid(rdev, REGULATOR_CHANGE_DRMS)) {
922 rdev_dbg(rdev, "DRMS operation not allowed\n");
934 return 0; 923 return 0;
924 }
935 925
936 if (!rdev->desc->ops->get_optimum_mode && 926 if (!rdev->desc->ops->get_optimum_mode &&
937 !rdev->desc->ops->set_load) 927 !rdev->desc->ops->set_load)
@@ -1003,7 +993,7 @@ static int suspend_set_state(struct regulator_dev *rdev,
1003 if (rstate == NULL) 993 if (rstate == NULL)
1004 return 0; 994 return 0;
1005 995
1006 /* If we have no suspend mode configration don't set anything; 996 /* If we have no suspend mode configuration don't set anything;
1007 * only warn if the driver implements set_suspend_voltage or 997 * only warn if the driver implements set_suspend_voltage or
1008 * set_suspend_mode callback. 998 * set_suspend_mode callback.
1009 */ 999 */
@@ -1131,7 +1121,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
1131 int current_uV = _regulator_get_voltage(rdev); 1121 int current_uV = _regulator_get_voltage(rdev);
1132 1122
1133 if (current_uV == -ENOTRECOVERABLE) { 1123 if (current_uV == -ENOTRECOVERABLE) {
1134 /* This regulator can't be read and must be initted */ 1124 /* This regulator can't be read and must be initialized */
1135 rdev_info(rdev, "Setting %d-%duV\n", 1125 rdev_info(rdev, "Setting %d-%duV\n",
1136 rdev->constraints->min_uV, 1126 rdev->constraints->min_uV,
1137 rdev->constraints->max_uV); 1127 rdev->constraints->max_uV);
@@ -1782,7 +1772,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
1782 struct device *dev = rdev->dev.parent; 1772 struct device *dev = rdev->dev.parent;
1783 int ret; 1773 int ret;
1784 1774
1785 /* No supply to resovle? */ 1775 /* No supply to resolve? */
1786 if (!rdev->supply_name) 1776 if (!rdev->supply_name)
1787 return 0; 1777 return 0;
1788 1778
@@ -2231,38 +2221,21 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
2231{ 2221{
2232 struct regulator_enable_gpio *pin; 2222 struct regulator_enable_gpio *pin;
2233 struct gpio_desc *gpiod; 2223 struct gpio_desc *gpiod;
2234 int ret;
2235 2224
2236 if (config->ena_gpiod) 2225 gpiod = config->ena_gpiod;
2237 gpiod = config->ena_gpiod;
2238 else
2239 gpiod = gpio_to_desc(config->ena_gpio);
2240 2226
2241 list_for_each_entry(pin, &regulator_ena_gpio_list, list) { 2227 list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
2242 if (pin->gpiod == gpiod) { 2228 if (pin->gpiod == gpiod) {
2243 rdev_dbg(rdev, "GPIO %d is already used\n", 2229 rdev_dbg(rdev, "GPIO is already used\n");
2244 config->ena_gpio);
2245 goto update_ena_gpio_to_rdev; 2230 goto update_ena_gpio_to_rdev;
2246 } 2231 }
2247 } 2232 }
2248 2233
2249 if (!config->ena_gpiod) {
2250 ret = gpio_request_one(config->ena_gpio,
2251 GPIOF_DIR_OUT | config->ena_gpio_flags,
2252 rdev_get_name(rdev));
2253 if (ret)
2254 return ret;
2255 }
2256
2257 pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); 2234 pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
2258 if (pin == NULL) { 2235 if (pin == NULL)
2259 if (!config->ena_gpiod)
2260 gpio_free(config->ena_gpio);
2261 return -ENOMEM; 2236 return -ENOMEM;
2262 }
2263 2237
2264 pin->gpiod = gpiod; 2238 pin->gpiod = gpiod;
2265 pin->ena_gpio_invert = config->ena_gpio_invert;
2266 list_add(&pin->list, &regulator_ena_gpio_list); 2239 list_add(&pin->list, &regulator_ena_gpio_list);
2267 2240
2268update_ena_gpio_to_rdev: 2241update_ena_gpio_to_rdev:
@@ -2283,7 +2256,6 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
2283 if (pin->gpiod == rdev->ena_pin->gpiod) { 2256 if (pin->gpiod == rdev->ena_pin->gpiod) {
2284 if (pin->request_count <= 1) { 2257 if (pin->request_count <= 1) {
2285 pin->request_count = 0; 2258 pin->request_count = 0;
2286 gpiod_put(pin->gpiod);
2287 list_del(&pin->list); 2259 list_del(&pin->list);
2288 kfree(pin); 2260 kfree(pin);
2289 rdev->ena_pin = NULL; 2261 rdev->ena_pin = NULL;
@@ -2313,8 +2285,7 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
2313 if (enable) { 2285 if (enable) {
2314 /* Enable GPIO at initial use */ 2286 /* Enable GPIO at initial use */
2315 if (pin->enable_count == 0) 2287 if (pin->enable_count == 0)
2316 gpiod_set_value_cansleep(pin->gpiod, 2288 gpiod_set_value_cansleep(pin->gpiod, 1);
2317 !pin->ena_gpio_invert);
2318 2289
2319 pin->enable_count++; 2290 pin->enable_count++;
2320 } else { 2291 } else {
@@ -2325,8 +2296,7 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
2325 2296
2326 /* Disable GPIO if not used */ 2297 /* Disable GPIO if not used */
2327 if (pin->enable_count <= 1) { 2298 if (pin->enable_count <= 1) {
2328 gpiod_set_value_cansleep(pin->gpiod, 2299 gpiod_set_value_cansleep(pin->gpiod, 0);
2329 pin->ena_gpio_invert);
2330 pin->enable_count = 0; 2300 pin->enable_count = 0;
2331 } 2301 }
2332 } 2302 }
@@ -2403,7 +2373,7 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
2403 * timer wrapping. 2373 * timer wrapping.
2404 * in case of multiple timer wrapping, either it can be 2374 * in case of multiple timer wrapping, either it can be
2405 * detected by out-of-range remaining, or it cannot be 2375 * detected by out-of-range remaining, or it cannot be
2406 * detected and we gets a panelty of 2376 * detected and we get a penalty of
2407 * _regulator_enable_delay(). 2377 * _regulator_enable_delay().
2408 */ 2378 */
2409 remaining = intended - start_jiffy; 2379 remaining = intended - start_jiffy;
@@ -2803,7 +2773,7 @@ static void regulator_disable_work(struct work_struct *work)
2803/** 2773/**
2804 * regulator_disable_deferred - disable regulator output with delay 2774 * regulator_disable_deferred - disable regulator output with delay
2805 * @regulator: regulator source 2775 * @regulator: regulator source
2806 * @ms: miliseconds until the regulator is disabled 2776 * @ms: milliseconds until the regulator is disabled
2807 * 2777 *
2808 * Execute regulator_disable() on the regulator after a delay. This 2778 * Execute regulator_disable() on the regulator after a delay. This
2809 * is intended for use with devices that require some time to quiesce. 2779 * is intended for use with devices that require some time to quiesce.
@@ -4937,7 +4907,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
4937 * device tree until we have handled it over to the core. If the 4907 * device tree until we have handled it over to the core. If the
4938 * config that was passed in to this function DOES NOT contain 4908 * config that was passed in to this function DOES NOT contain
4939 * a descriptor, and the config after this call DOES contain 4909 * a descriptor, and the config after this call DOES contain
4940 * a descriptor, we definately got one from parsing the device 4910 * a descriptor, we definitely got one from parsing the device
4941 * tree. 4911 * tree.
4942 */ 4912 */
4943 if (!cfg->ena_gpiod && config->ena_gpiod) 4913 if (!cfg->ena_gpiod && config->ena_gpiod)
@@ -4969,15 +4939,13 @@ regulator_register(const struct regulator_desc *regulator_desc,
4969 goto clean; 4939 goto clean;
4970 } 4940 }
4971 4941
4972 if (config->ena_gpiod || 4942 if (config->ena_gpiod) {
4973 ((config->ena_gpio || config->ena_gpio_initialized) &&
4974 gpio_is_valid(config->ena_gpio))) {
4975 mutex_lock(&regulator_list_mutex); 4943 mutex_lock(&regulator_list_mutex);
4976 ret = regulator_ena_gpio_request(rdev, config); 4944 ret = regulator_ena_gpio_request(rdev, config);
4977 mutex_unlock(&regulator_list_mutex); 4945 mutex_unlock(&regulator_list_mutex);
4978 if (ret != 0) { 4946 if (ret != 0) {
4979 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", 4947 rdev_err(rdev, "Failed to request enable GPIO: %d\n",
4980 config->ena_gpio, ret); 4948 ret);
4981 goto clean; 4949 goto clean;
4982 } 4950 }
4983 /* The regulator core took over the GPIO descriptor */ 4951 /* The regulator core took over the GPIO descriptor */
@@ -5245,6 +5213,12 @@ struct device *rdev_get_dev(struct regulator_dev *rdev)
5245} 5213}
5246EXPORT_SYMBOL_GPL(rdev_get_dev); 5214EXPORT_SYMBOL_GPL(rdev_get_dev);
5247 5215
5216struct regmap *rdev_get_regmap(struct regulator_dev *rdev)
5217{
5218 return rdev->regmap;
5219}
5220EXPORT_SYMBOL_GPL(rdev_get_regmap);
5221
5248void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) 5222void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
5249{ 5223{
5250 return reg_init_data->driver_data; 5224 return reg_init_data->driver_data;
diff --git a/drivers/regulator/cpcap-regulator.c b/drivers/regulator/cpcap-regulator.c
index 2131457937b7..e7dab5c4d1d1 100644
--- a/drivers/regulator/cpcap-regulator.c
+++ b/drivers/regulator/cpcap-regulator.c
@@ -100,12 +100,11 @@ struct cpcap_regulator {
100 struct regulator_desc rdesc; 100 struct regulator_desc rdesc;
101 const u16 assign_reg; 101 const u16 assign_reg;
102 const u16 assign_mask; 102 const u16 assign_mask;
103 const u16 vsel_shift;
104}; 103};
105 104
106#define CPCAP_REG(_ID, reg, assignment_reg, assignment_mask, val_tbl, \ 105#define CPCAP_REG(_ID, reg, assignment_reg, assignment_mask, val_tbl, \
107 mode_mask, volt_mask, volt_shft, \ 106 mode_mask, volt_mask, mode_val, off_val, \
108 mode_val, off_val, volt_trans_time) { \ 107 volt_trans_time) { \
109 .rdesc = { \ 108 .rdesc = { \
110 .name = #_ID, \ 109 .name = #_ID, \
111 .of_match = of_match_ptr(#_ID), \ 110 .of_match = of_match_ptr(#_ID), \
@@ -127,7 +126,6 @@ struct cpcap_regulator {
127 }, \ 126 }, \
128 .assign_reg = (assignment_reg), \ 127 .assign_reg = (assignment_reg), \
129 .assign_mask = (assignment_mask), \ 128 .assign_mask = (assignment_mask), \
130 .vsel_shift = (volt_shft), \
131} 129}
132 130
133struct cpcap_ddata { 131struct cpcap_ddata {
@@ -336,155 +334,155 @@ static const unsigned int vaudio_val_tbl[] = { 0, 2775000, };
336 * SW1 to SW4 and SW6 seems to be unused for mapphone. Note that VSIM and 334 * SW1 to SW4 and SW6 seems to be unused for mapphone. Note that VSIM and
337 * VSIMCARD have a shared resource assignment bit. 335 * VSIMCARD have a shared resource assignment bit.
338 */ 336 */
339static struct cpcap_regulator omap4_regulators[] = { 337static const struct cpcap_regulator omap4_regulators[] = {
340 CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2, 338 CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
341 CPCAP_BIT_SW1_SEL, unknown_val_tbl, 339 CPCAP_BIT_SW1_SEL, unknown_val_tbl,
342 0, 0, 0, 0, 0, 0), 340 0, 0, 0, 0, 0),
343 CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2, 341 CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
344 CPCAP_BIT_SW2_SEL, unknown_val_tbl, 342 CPCAP_BIT_SW2_SEL, unknown_val_tbl,
345 0, 0, 0, 0, 0, 0), 343 0, 0, 0, 0, 0),
346 CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2, 344 CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
347 CPCAP_BIT_SW3_SEL, unknown_val_tbl, 345 CPCAP_BIT_SW3_SEL, unknown_val_tbl,
348 0, 0, 0, 0, 0, 0), 346 0, 0, 0, 0, 0),
349 CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2, 347 CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
350 CPCAP_BIT_SW4_SEL, unknown_val_tbl, 348 CPCAP_BIT_SW4_SEL, unknown_val_tbl,
351 0, 0, 0, 0, 0, 0), 349 0, 0, 0, 0, 0),
352 CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2, 350 CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
353 CPCAP_BIT_SW5_SEL, sw5_val_tbl, 351 CPCAP_BIT_SW5_SEL, sw5_val_tbl,
354 0x28, 0, 0, 0x20 | CPCAP_REG_OFF_MODE_SEC, 0, 0), 352 0x28, 0, 0x20 | CPCAP_REG_OFF_MODE_SEC, 0, 0),
355 CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2, 353 CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
356 CPCAP_BIT_SW6_SEL, unknown_val_tbl, 354 CPCAP_BIT_SW6_SEL, unknown_val_tbl,
357 0, 0, 0, 0, 0, 0), 355 0, 0, 0, 0, 0),
358 CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2, 356 CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
359 CPCAP_BIT_VCAM_SEL, vcam_val_tbl, 357 CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
360 0x87, 0x30, 4, 0x3, 0, 420), 358 0x87, 0x30, 0x3, 0, 420),
361 CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3, 359 CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
362 CPCAP_BIT_VCSI_SEL, vcsi_val_tbl, 360 CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
363 0x47, 0x10, 4, 0x43, 0x41, 350), 361 0x47, 0x10, 0x43, 0x41, 350),
364 CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3, 362 CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
365 CPCAP_BIT_VDAC_SEL, vdac_val_tbl, 363 CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
366 0x87, 0x30, 4, 0x3, 0, 420), 364 0x87, 0x30, 0x3, 0, 420),
367 CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2, 365 CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
368 CPCAP_BIT_VDIG_SEL, vdig_val_tbl, 366 CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
369 0x87, 0x30, 4, 0x82, 0, 420), 367 0x87, 0x30, 0x82, 0, 420),
370 CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3, 368 CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
371 CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl, 369 CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
372 0x80, 0xf, 0, 0x80, 0, 420), 370 0x80, 0xf, 0x80, 0, 420),
373 CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3, 371 CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
374 CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl, 372 CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
375 0x17, 0, 0, 0, 0x12, 0), 373 0x17, 0, 0, 0x12, 0),
376 CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2, 374 CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
377 CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl, 375 CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
378 0x87, 0x38, 3, 0x82, 0, 420), 376 0x87, 0x38, 0x82, 0, 420),
379 CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3, 377 CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
380 CPCAP_BIT_VPLL_SEL, vpll_val_tbl, 378 CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
381 0x43, 0x18, 3, 0x2, 0, 420), 379 0x43, 0x18, 0x2, 0, 420),
382 CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3, 380 CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
383 CPCAP_BIT_VRF1_SEL, vrf1_val_tbl, 381 CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
384 0xac, 0x2, 1, 0x4, 0, 10), 382 0xac, 0x2, 0x4, 0, 10),
385 CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3, 383 CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
386 CPCAP_BIT_VRF2_SEL, vrf2_val_tbl, 384 CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
387 0x23, 0x8, 3, 0, 0, 10), 385 0x23, 0x8, 0, 0, 10),
388 CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3, 386 CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
389 CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl, 387 CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
390 0x23, 0x8, 3, 0, 0, 420), 388 0x23, 0x8, 0, 0, 420),
391 CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3, 389 CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
392 CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl, 390 CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
393 0x47, 0x10, 4, 0, 0, 420), 391 0x47, 0x10, 0, 0, 420),
394 CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3, 392 CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
395 CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl, 393 CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
396 0x20c, 0xc0, 6, 0x20c, 0, 420), 394 0x20c, 0xc0, 0x20c, 0, 420),
397 CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 395 CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
398 0xffff, vsim_val_tbl, 396 0xffff, vsim_val_tbl,
399 0x23, 0x8, 3, 0x3, 0, 420), 397 0x23, 0x8, 0x3, 0, 420),
400 CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 398 CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
401 0xffff, vsimcard_val_tbl, 399 0xffff, vsimcard_val_tbl,
402 0x1e80, 0x8, 3, 0x1e00, 0, 420), 400 0x1e80, 0x8, 0x1e00, 0, 420),
403 CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3, 401 CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
404 CPCAP_BIT_VVIB_SEL, vvib_val_tbl, 402 CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
405 0x1, 0xc, 2, 0x1, 0, 500), 403 0x1, 0xc, 0x1, 0, 500),
406 CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3, 404 CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
407 CPCAP_BIT_VUSB_SEL, vusb_val_tbl, 405 CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
408 0x11c, 0x40, 6, 0xc, 0, 0), 406 0x11c, 0x40, 0xc, 0, 0),
409 CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4, 407 CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
410 CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl, 408 CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
411 0x16, 0x1, 0, 0x4, 0, 0), 409 0x16, 0x1, 0x4, 0, 0),
412 { /* sentinel */ }, 410 { /* sentinel */ },
413}; 411};
414 412
415static struct cpcap_regulator xoom_regulators[] = { 413static const struct cpcap_regulator xoom_regulators[] = {
416 CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2, 414 CPCAP_REG(SW1, CPCAP_REG_S1C1, CPCAP_REG_ASSIGN2,
417 CPCAP_BIT_SW1_SEL, unknown_val_tbl, 415 CPCAP_BIT_SW1_SEL, unknown_val_tbl,
418 0, 0, 0, 0, 0, 0), 416 0, 0, 0, 0, 0),
419 CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2, 417 CPCAP_REG(SW2, CPCAP_REG_S2C1, CPCAP_REG_ASSIGN2,
420 CPCAP_BIT_SW2_SEL, sw2_sw4_val_tbl, 418 CPCAP_BIT_SW2_SEL, sw2_sw4_val_tbl,
421 0xf00, 0x7f, 0, 0x800, 0, 120), 419 0xf00, 0x7f, 0x800, 0, 120),
422 CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2, 420 CPCAP_REG(SW3, CPCAP_REG_S3C, CPCAP_REG_ASSIGN2,
423 CPCAP_BIT_SW3_SEL, unknown_val_tbl, 421 CPCAP_BIT_SW3_SEL, unknown_val_tbl,
424 0, 0, 0, 0, 0, 0), 422 0, 0, 0, 0, 0),
425 CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2, 423 CPCAP_REG(SW4, CPCAP_REG_S4C1, CPCAP_REG_ASSIGN2,
426 CPCAP_BIT_SW4_SEL, sw2_sw4_val_tbl, 424 CPCAP_BIT_SW4_SEL, sw2_sw4_val_tbl,
427 0xf00, 0x7f, 0, 0x900, 0, 100), 425 0xf00, 0x7f, 0x900, 0, 100),
428 CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2, 426 CPCAP_REG(SW5, CPCAP_REG_S5C, CPCAP_REG_ASSIGN2,
429 CPCAP_BIT_SW5_SEL, sw5_val_tbl, 427 CPCAP_BIT_SW5_SEL, sw5_val_tbl,
430 0x2a, 0, 0, 0x22, 0, 0), 428 0x2a, 0, 0x22, 0, 0),
431 CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2, 429 CPCAP_REG(SW6, CPCAP_REG_S6C, CPCAP_REG_ASSIGN2,
432 CPCAP_BIT_SW6_SEL, unknown_val_tbl, 430 CPCAP_BIT_SW6_SEL, unknown_val_tbl,
433 0, 0, 0, 0, 0, 0), 431 0, 0, 0, 0, 0),
434 CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2, 432 CPCAP_REG(VCAM, CPCAP_REG_VCAMC, CPCAP_REG_ASSIGN2,
435 CPCAP_BIT_VCAM_SEL, vcam_val_tbl, 433 CPCAP_BIT_VCAM_SEL, vcam_val_tbl,
436 0x87, 0x30, 4, 0x7, 0, 420), 434 0x87, 0x30, 0x7, 0, 420),
437 CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3, 435 CPCAP_REG(VCSI, CPCAP_REG_VCSIC, CPCAP_REG_ASSIGN3,
438 CPCAP_BIT_VCSI_SEL, vcsi_val_tbl, 436 CPCAP_BIT_VCSI_SEL, vcsi_val_tbl,
439 0x47, 0x10, 4, 0x7, 0, 350), 437 0x47, 0x10, 0x7, 0, 350),
440 CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3, 438 CPCAP_REG(VDAC, CPCAP_REG_VDACC, CPCAP_REG_ASSIGN3,
441 CPCAP_BIT_VDAC_SEL, vdac_val_tbl, 439 CPCAP_BIT_VDAC_SEL, vdac_val_tbl,
442 0x87, 0x30, 4, 0x3, 0, 420), 440 0x87, 0x30, 0x3, 0, 420),
443 CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2, 441 CPCAP_REG(VDIG, CPCAP_REG_VDIGC, CPCAP_REG_ASSIGN2,
444 CPCAP_BIT_VDIG_SEL, vdig_val_tbl, 442 CPCAP_BIT_VDIG_SEL, vdig_val_tbl,
445 0x87, 0x30, 4, 0x5, 0, 420), 443 0x87, 0x30, 0x5, 0, 420),
446 CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3, 444 CPCAP_REG(VFUSE, CPCAP_REG_VFUSEC, CPCAP_REG_ASSIGN3,
447 CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl, 445 CPCAP_BIT_VFUSE_SEL, vfuse_val_tbl,
448 0x80, 0xf, 0, 0x80, 0, 420), 446 0x80, 0xf, 0x80, 0, 420),
449 CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3, 447 CPCAP_REG(VHVIO, CPCAP_REG_VHVIOC, CPCAP_REG_ASSIGN3,
450 CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl, 448 CPCAP_BIT_VHVIO_SEL, vhvio_val_tbl,
451 0x17, 0, 0, 0x2, 0, 0), 449 0x17, 0, 0x2, 0, 0),
452 CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2, 450 CPCAP_REG(VSDIO, CPCAP_REG_VSDIOC, CPCAP_REG_ASSIGN2,
453 CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl, 451 CPCAP_BIT_VSDIO_SEL, vsdio_val_tbl,
454 0x87, 0x38, 3, 0x2, 0, 420), 452 0x87, 0x38, 0x2, 0, 420),
455 CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3, 453 CPCAP_REG(VPLL, CPCAP_REG_VPLLC, CPCAP_REG_ASSIGN3,
456 CPCAP_BIT_VPLL_SEL, vpll_val_tbl, 454 CPCAP_BIT_VPLL_SEL, vpll_val_tbl,
457 0x43, 0x18, 3, 0x1, 0, 420), 455 0x43, 0x18, 0x1, 0, 420),
458 CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3, 456 CPCAP_REG(VRF1, CPCAP_REG_VRF1C, CPCAP_REG_ASSIGN3,
459 CPCAP_BIT_VRF1_SEL, vrf1_val_tbl, 457 CPCAP_BIT_VRF1_SEL, vrf1_val_tbl,
460 0xac, 0x2, 1, 0xc, 0, 10), 458 0xac, 0x2, 0xc, 0, 10),
461 CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3, 459 CPCAP_REG(VRF2, CPCAP_REG_VRF2C, CPCAP_REG_ASSIGN3,
462 CPCAP_BIT_VRF2_SEL, vrf2_val_tbl, 460 CPCAP_BIT_VRF2_SEL, vrf2_val_tbl,
463 0x23, 0x8, 3, 0x3, 0, 10), 461 0x23, 0x8, 0x3, 0, 10),
464 CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3, 462 CPCAP_REG(VRFREF, CPCAP_REG_VRFREFC, CPCAP_REG_ASSIGN3,
465 CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl, 463 CPCAP_BIT_VRFREF_SEL, vrfref_val_tbl,
466 0x23, 0x8, 3, 0x3, 0, 420), 464 0x23, 0x8, 0x3, 0, 420),
467 CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3, 465 CPCAP_REG(VWLAN1, CPCAP_REG_VWLAN1C, CPCAP_REG_ASSIGN3,
468 CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl, 466 CPCAP_BIT_VWLAN1_SEL, vwlan1_val_tbl,
469 0x47, 0x10, 4, 0x5, 0, 420), 467 0x47, 0x10, 0x5, 0, 420),
470 CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3, 468 CPCAP_REG(VWLAN2, CPCAP_REG_VWLAN2C, CPCAP_REG_ASSIGN3,
471 CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl, 469 CPCAP_BIT_VWLAN2_SEL, vwlan2_val_tbl,
472 0x20c, 0xc0, 6, 0x8, 0, 420), 470 0x20c, 0xc0, 0x8, 0, 420),
473 CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 471 CPCAP_REG(VSIM, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
474 0xffff, vsim_val_tbl, 472 0xffff, vsim_val_tbl,
475 0x23, 0x8, 3, 0x3, 0, 420), 473 0x23, 0x8, 0x3, 0, 420),
476 CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3, 474 CPCAP_REG(VSIMCARD, CPCAP_REG_VSIMC, CPCAP_REG_ASSIGN3,
477 0xffff, vsimcard_val_tbl, 475 0xffff, vsimcard_val_tbl,
478 0x1e80, 0x8, 3, 0x1e00, 0, 420), 476 0x1e80, 0x8, 0x1e00, 0, 420),
479 CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3, 477 CPCAP_REG(VVIB, CPCAP_REG_VVIBC, CPCAP_REG_ASSIGN3,
480 CPCAP_BIT_VVIB_SEL, vvib_val_tbl, 478 CPCAP_BIT_VVIB_SEL, vvib_val_tbl,
481 0x1, 0xc, 2, 0, 0x1, 500), 479 0x1, 0xc, 0, 0x1, 500),
482 CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3, 480 CPCAP_REG(VUSB, CPCAP_REG_VUSBC, CPCAP_REG_ASSIGN3,
483 CPCAP_BIT_VUSB_SEL, vusb_val_tbl, 481 CPCAP_BIT_VUSB_SEL, vusb_val_tbl,
484 0x11c, 0x40, 6, 0xc, 0, 0), 482 0x11c, 0x40, 0xc, 0, 0),
485 CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4, 483 CPCAP_REG(VAUDIO, CPCAP_REG_VAUDIOC, CPCAP_REG_ASSIGN4,
486 CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl, 484 CPCAP_BIT_VAUDIO_SEL, vaudio_val_tbl,
487 0x16, 0x1, 0, 0x4, 0, 0), 485 0x16, 0x1, 0x4, 0, 0),
488 { /* sentinel */ }, 486 { /* sentinel */ },
489}; 487};
490 488
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 588c3d2445cf..3c6fac793658 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -48,7 +48,9 @@
48#define DA9055_ID_LDO6 7 48#define DA9055_ID_LDO6 7
49 49
50/* DA9055 BUCK current limit */ 50/* DA9055 BUCK current limit */
51static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 }; 51static const unsigned int da9055_current_limits[] = {
52 500000, 600000, 700000, 800000
53};
52 54
53struct da9055_conf_reg { 55struct da9055_conf_reg {
54 int reg; 56 int reg;
@@ -169,39 +171,6 @@ static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
169 val << volt.sl_shift); 171 val << volt.sl_shift);
170} 172}
171 173
172static int da9055_buck_get_current_limit(struct regulator_dev *rdev)
173{
174 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
175 struct da9055_regulator_info *info = regulator->info;
176 int ret;
177
178 ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM);
179 if (ret < 0)
180 return ret;
181
182 ret &= info->mode.mask;
183 return da9055_current_limits[ret >> info->mode.shift];
184}
185
186static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
187 int max_uA)
188{
189 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
190 struct da9055_regulator_info *info = regulator->info;
191 int i;
192
193 for (i = ARRAY_SIZE(da9055_current_limits) - 1; i >= 0; i--) {
194 if ((min_uA <= da9055_current_limits[i]) &&
195 (da9055_current_limits[i] <= max_uA))
196 return da9055_reg_update(regulator->da9055,
197 DA9055_REG_BUCK_LIM,
198 info->mode.mask,
199 i << info->mode.shift);
200 }
201
202 return -EINVAL;
203}
204
205static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev) 174static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
206{ 175{
207 struct da9055_regulator *regulator = rdev_get_drvdata(rdev); 176 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
@@ -329,8 +298,8 @@ static const struct regulator_ops da9055_buck_ops = {
329 .get_mode = da9055_buck_get_mode, 298 .get_mode = da9055_buck_get_mode,
330 .set_mode = da9055_buck_set_mode, 299 .set_mode = da9055_buck_set_mode,
331 300
332 .get_current_limit = da9055_buck_get_current_limit, 301 .get_current_limit = regulator_get_current_limit_regmap,
333 .set_current_limit = da9055_buck_set_current_limit, 302 .set_current_limit = regulator_set_current_limit_regmap,
334 303
335 .get_voltage_sel = da9055_regulator_get_voltage_sel, 304 .get_voltage_sel = da9055_regulator_get_voltage_sel,
336 .set_voltage_sel = da9055_regulator_set_voltage_sel, 305 .set_voltage_sel = da9055_regulator_set_voltage_sel,
@@ -407,6 +376,10 @@ static const struct regulator_ops da9055_ldo_ops = {
407 .uV_step = (step) * 1000,\ 376 .uV_step = (step) * 1000,\
408 .linear_min_sel = (voffset),\ 377 .linear_min_sel = (voffset),\
409 .owner = THIS_MODULE,\ 378 .owner = THIS_MODULE,\
379 .curr_table = da9055_current_limits,\
380 .n_current_limits = ARRAY_SIZE(da9055_current_limits),\
381 .csel_reg = DA9055_REG_BUCK_LIM,\
382 .csel_mask = (mbits),\
410 },\ 383 },\
411 .conf = {\ 384 .conf = {\
412 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \ 385 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
@@ -457,7 +430,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
457 int gpio_mux = pdata->gpio_ren[id]; 430 int gpio_mux = pdata->gpio_ren[id];
458 431
459 config->ena_gpiod = pdata->ena_gpiods[id]; 432 config->ena_gpiod = pdata->ena_gpiods[id];
460 config->ena_gpio_invert = 1;
461 433
462 /* 434 /*
463 * GPI pin is muxed with regulator to control the 435 * GPI pin is muxed with regulator to control the
diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c
index 34a70d9dc450..b064d8a19d4c 100644
--- a/drivers/regulator/da9062-regulator.c
+++ b/drivers/regulator/da9062-regulator.c
@@ -126,7 +126,7 @@ static int da9062_set_current_limit(struct regulator_dev *rdev,
126 const struct da9062_regulator_info *rinfo = regl->info; 126 const struct da9062_regulator_info *rinfo = regl->info;
127 int n, tval; 127 int n, tval;
128 128
129 for (n = 0; n < rinfo->n_current_limits; n++) { 129 for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
130 tval = rinfo->current_limits[n]; 130 tval = rinfo->current_limits[n];
131 if (tval >= min_ua && tval <= max_ua) 131 if (tval >= min_ua && tval <= max_ua)
132 return regmap_field_write(regl->ilimit, n); 132 return regmap_field_write(regl->ilimit, n);
@@ -992,7 +992,6 @@ static int da9062_regulator_probe(struct platform_device *pdev)
992 struct regulator_config config = { }; 992 struct regulator_config config = { };
993 const struct da9062_regulator_info *rinfo; 993 const struct da9062_regulator_info *rinfo;
994 int irq, n, ret; 994 int irq, n, ret;
995 size_t size;
996 int max_regulators; 995 int max_regulators;
997 996
998 switch (chip->chip_type) { 997 switch (chip->chip_type) {
@@ -1010,9 +1009,8 @@ static int da9062_regulator_probe(struct platform_device *pdev)
1010 } 1009 }
1011 1010
1012 /* Allocate memory required by usable regulators */ 1011 /* Allocate memory required by usable regulators */
1013 size = sizeof(struct da9062_regulators) + 1012 regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, regulator,
1014 max_regulators * sizeof(struct da9062_regulator); 1013 max_regulators), GFP_KERNEL);
1015 regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
1016 if (!regulators) 1014 if (!regulators)
1017 return -ENOMEM; 1015 return -ENOMEM;
1018 1016
@@ -1029,31 +1027,50 @@ static int da9062_regulator_probe(struct platform_device *pdev)
1029 regl->desc.type = REGULATOR_VOLTAGE; 1027 regl->desc.type = REGULATOR_VOLTAGE;
1030 regl->desc.owner = THIS_MODULE; 1028 regl->desc.owner = THIS_MODULE;
1031 1029
1032 if (regl->info->mode.reg) 1030 if (regl->info->mode.reg) {
1033 regl->mode = devm_regmap_field_alloc( 1031 regl->mode = devm_regmap_field_alloc(
1034 &pdev->dev, 1032 &pdev->dev,
1035 chip->regmap, 1033 chip->regmap,
1036 regl->info->mode); 1034 regl->info->mode);
1037 if (regl->info->suspend.reg) 1035 if (IS_ERR(regl->mode))
1036 return PTR_ERR(regl->mode);
1037 }
1038
1039 if (regl->info->suspend.reg) {
1038 regl->suspend = devm_regmap_field_alloc( 1040 regl->suspend = devm_regmap_field_alloc(
1039 &pdev->dev, 1041 &pdev->dev,
1040 chip->regmap, 1042 chip->regmap,
1041 regl->info->suspend); 1043 regl->info->suspend);
1042 if (regl->info->sleep.reg) 1044 if (IS_ERR(regl->suspend))
1045 return PTR_ERR(regl->suspend);
1046 }
1047
1048 if (regl->info->sleep.reg) {
1043 regl->sleep = devm_regmap_field_alloc( 1049 regl->sleep = devm_regmap_field_alloc(
1044 &pdev->dev, 1050 &pdev->dev,
1045 chip->regmap, 1051 chip->regmap,
1046 regl->info->sleep); 1052 regl->info->sleep);
1047 if (regl->info->suspend_sleep.reg) 1053 if (IS_ERR(regl->sleep))
1054 return PTR_ERR(regl->sleep);
1055 }
1056
1057 if (regl->info->suspend_sleep.reg) {
1048 regl->suspend_sleep = devm_regmap_field_alloc( 1058 regl->suspend_sleep = devm_regmap_field_alloc(
1049 &pdev->dev, 1059 &pdev->dev,
1050 chip->regmap, 1060 chip->regmap,
1051 regl->info->suspend_sleep); 1061 regl->info->suspend_sleep);
1052 if (regl->info->ilimit.reg) 1062 if (IS_ERR(regl->suspend_sleep))
1063 return PTR_ERR(regl->suspend_sleep);
1064 }
1065
1066 if (regl->info->ilimit.reg) {
1053 regl->ilimit = devm_regmap_field_alloc( 1067 regl->ilimit = devm_regmap_field_alloc(
1054 &pdev->dev, 1068 &pdev->dev,
1055 chip->regmap, 1069 chip->regmap,
1056 regl->info->ilimit); 1070 regl->info->ilimit);
1071 if (IS_ERR(regl->ilimit))
1072 return PTR_ERR(regl->ilimit);
1073 }
1057 1074
1058 /* Register regulator */ 1075 /* Register regulator */
1059 memset(&config, 0, sizeof(config)); 1076 memset(&config, 0, sizeof(config));
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 8cbcd2a3eb20..2b0c7a85306a 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -167,7 +167,7 @@ static int da9063_set_current_limit(struct regulator_dev *rdev,
167 const struct da9063_regulator_info *rinfo = regl->info; 167 const struct da9063_regulator_info *rinfo = regl->info;
168 int n, tval; 168 int n, tval;
169 169
170 for (n = 0; n < rinfo->n_current_limits; n++) { 170 for (n = rinfo->n_current_limits - 1; n >= 0; n--) {
171 tval = rinfo->current_limits[n]; 171 tval = rinfo->current_limits[n];
172 if (tval >= min_uA && tval <= max_uA) 172 if (tval >= min_uA && tval <= max_uA)
173 return regmap_field_write(regl->ilimit, n); 173 return regmap_field_write(regl->ilimit, n);
@@ -739,7 +739,6 @@ static int da9063_regulator_probe(struct platform_device *pdev)
739 struct regulator_config config; 739 struct regulator_config config;
740 bool bcores_merged, bmem_bio_merged; 740 bool bcores_merged, bmem_bio_merged;
741 int id, irq, n, n_regulators, ret, val; 741 int id, irq, n, n_regulators, ret, val;
742 size_t size;
743 742
744 regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL; 743 regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL;
745 744
@@ -784,9 +783,8 @@ static int da9063_regulator_probe(struct platform_device *pdev)
784 n_regulators--; /* remove BMEM_BIO_MERGED */ 783 n_regulators--; /* remove BMEM_BIO_MERGED */
785 784
786 /* Allocate memory required by usable regulators */ 785 /* Allocate memory required by usable regulators */
787 size = sizeof(struct da9063_regulators) + 786 regulators = devm_kzalloc(&pdev->dev, struct_size(regulators,
788 n_regulators * sizeof(struct da9063_regulator); 787 regulator, n_regulators), GFP_KERNEL);
789 regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
790 if (!regulators) 788 if (!regulators)
791 return -ENOMEM; 789 return -ENOMEM;
792 790
@@ -835,21 +833,40 @@ static int da9063_regulator_probe(struct platform_device *pdev)
835 regl->desc.type = REGULATOR_VOLTAGE; 833 regl->desc.type = REGULATOR_VOLTAGE;
836 regl->desc.owner = THIS_MODULE; 834 regl->desc.owner = THIS_MODULE;
837 835
838 if (regl->info->mode.reg) 836 if (regl->info->mode.reg) {
839 regl->mode = devm_regmap_field_alloc(&pdev->dev, 837 regl->mode = devm_regmap_field_alloc(&pdev->dev,
840 da9063->regmap, regl->info->mode); 838 da9063->regmap, regl->info->mode);
841 if (regl->info->suspend.reg) 839 if (IS_ERR(regl->mode))
840 return PTR_ERR(regl->mode);
841 }
842
843 if (regl->info->suspend.reg) {
842 regl->suspend = devm_regmap_field_alloc(&pdev->dev, 844 regl->suspend = devm_regmap_field_alloc(&pdev->dev,
843 da9063->regmap, regl->info->suspend); 845 da9063->regmap, regl->info->suspend);
844 if (regl->info->sleep.reg) 846 if (IS_ERR(regl->suspend))
847 return PTR_ERR(regl->suspend);
848 }
849
850 if (regl->info->sleep.reg) {
845 regl->sleep = devm_regmap_field_alloc(&pdev->dev, 851 regl->sleep = devm_regmap_field_alloc(&pdev->dev,
846 da9063->regmap, regl->info->sleep); 852 da9063->regmap, regl->info->sleep);
847 if (regl->info->suspend_sleep.reg) 853 if (IS_ERR(regl->sleep))
854 return PTR_ERR(regl->sleep);
855 }
856
857 if (regl->info->suspend_sleep.reg) {
848 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev, 858 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev,
849 da9063->regmap, regl->info->suspend_sleep); 859 da9063->regmap, regl->info->suspend_sleep);
850 if (regl->info->ilimit.reg) 860 if (IS_ERR(regl->suspend_sleep))
861 return PTR_ERR(regl->suspend_sleep);
862 }
863
864 if (regl->info->ilimit.reg) {
851 regl->ilimit = devm_regmap_field_alloc(&pdev->dev, 865 regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
852 da9063->regmap, regl->info->ilimit); 866 da9063->regmap, regl->info->ilimit);
867 if (IS_ERR(regl->ilimit))
868 return PTR_ERR(regl->ilimit);
869 }
853 870
854 /* Register regulator */ 871 /* Register regulator */
855 memset(&config, 0, sizeof(config)); 872 memset(&config, 0, sizeof(config));
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
index 84dba64ed11e..528303771723 100644
--- a/drivers/regulator/da9210-regulator.c
+++ b/drivers/regulator/da9210-regulator.c
@@ -41,10 +41,6 @@ static const struct regmap_config da9210_regmap_config = {
41 .val_bits = 8, 41 .val_bits = 8,
42}; 42};
43 43
44static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
45 int max_uA);
46static int da9210_get_current_limit(struct regulator_dev *rdev);
47
48static const struct regulator_ops da9210_buck_ops = { 44static const struct regulator_ops da9210_buck_ops = {
49 .enable = regulator_enable_regmap, 45 .enable = regulator_enable_regmap,
50 .disable = regulator_disable_regmap, 46 .disable = regulator_disable_regmap,
@@ -52,8 +48,8 @@ static const struct regulator_ops da9210_buck_ops = {
52 .set_voltage_sel = regulator_set_voltage_sel_regmap, 48 .set_voltage_sel = regulator_set_voltage_sel_regmap,
53 .get_voltage_sel = regulator_get_voltage_sel_regmap, 49 .get_voltage_sel = regulator_get_voltage_sel_regmap,
54 .list_voltage = regulator_list_voltage_linear, 50 .list_voltage = regulator_list_voltage_linear,
55 .set_current_limit = da9210_set_current_limit, 51 .set_current_limit = regulator_set_current_limit_regmap,
56 .get_current_limit = da9210_get_current_limit, 52 .get_current_limit = regulator_get_current_limit_regmap,
57}; 53};
58 54
59/* Default limits measured in millivolts and milliamps */ 55/* Default limits measured in millivolts and milliamps */
@@ -62,7 +58,7 @@ static const struct regulator_ops da9210_buck_ops = {
62#define DA9210_STEP_MV 10 58#define DA9210_STEP_MV 10
63 59
64/* Current limits for buck (uA) indices corresponds with register values */ 60/* Current limits for buck (uA) indices corresponds with register values */
65static const int da9210_buck_limits[] = { 61static const unsigned int da9210_buck_limits[] = {
66 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000, 62 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000,
67 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000 63 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000
68}; 64};
@@ -80,47 +76,12 @@ static const struct regulator_desc da9210_reg = {
80 .enable_reg = DA9210_REG_BUCK_CONT, 76 .enable_reg = DA9210_REG_BUCK_CONT,
81 .enable_mask = DA9210_BUCK_EN, 77 .enable_mask = DA9210_BUCK_EN,
82 .owner = THIS_MODULE, 78 .owner = THIS_MODULE,
79 .curr_table = da9210_buck_limits,
80 .n_current_limits = ARRAY_SIZE(da9210_buck_limits),
81 .csel_reg = DA9210_REG_BUCK_ILIM,
82 .csel_mask = DA9210_BUCK_ILIM_MASK,
83}; 83};
84 84
85static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
86 int max_uA)
87{
88 struct da9210 *chip = rdev_get_drvdata(rdev);
89 unsigned int sel;
90 int i;
91
92 /* search for closest to maximum */
93 for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) {
94 if (min_uA <= da9210_buck_limits[i] &&
95 max_uA >= da9210_buck_limits[i]) {
96 sel = i;
97 sel = sel << DA9210_BUCK_ILIM_SHIFT;
98 return regmap_update_bits(chip->regmap,
99 DA9210_REG_BUCK_ILIM,
100 DA9210_BUCK_ILIM_MASK, sel);
101 }
102 }
103
104 return -EINVAL;
105}
106
107static int da9210_get_current_limit(struct regulator_dev *rdev)
108{
109 struct da9210 *chip = rdev_get_drvdata(rdev);
110 unsigned int data;
111 unsigned int sel;
112 int ret;
113
114 ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data);
115 if (ret < 0)
116 return ret;
117
118 /* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */
119 sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT;
120
121 return da9210_buck_limits[sel];
122}
123
124static irqreturn_t da9210_irq_handler(int irq, void *data) 85static irqreturn_t da9210_irq_handler(int irq, void *data)
125{ 86{
126 struct da9210 *chip = data; 87 struct da9210 *chip = data;
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index a3bc8037153e..771a06d1900d 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -40,7 +40,6 @@
40/* VSEL bit definitions */ 40/* VSEL bit definitions */
41#define VSEL_BUCK_EN (1 << 7) 41#define VSEL_BUCK_EN (1 << 7)
42#define VSEL_MODE (1 << 6) 42#define VSEL_MODE (1 << 6)
43#define VSEL_NSEL_MASK 0x3F
44/* Chip ID and Verison */ 43/* Chip ID and Verison */
45#define DIE_ID 0x0F /* ID1 */ 44#define DIE_ID 0x0F /* ID1 */
46#define DIE_REV 0x0F /* ID2 */ 45#define DIE_REV 0x0F /* ID2 */
@@ -49,14 +48,26 @@
49#define CTL_SLEW_MASK (0x7 << 4) 48#define CTL_SLEW_MASK (0x7 << 4)
50#define CTL_SLEW_SHIFT 4 49#define CTL_SLEW_SHIFT 4
51#define CTL_RESET (1 << 2) 50#define CTL_RESET (1 << 2)
51#define CTL_MODE_VSEL0_MODE BIT(0)
52#define CTL_MODE_VSEL1_MODE BIT(1)
52 53
53#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */ 54#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
55#define FAN53526_NVOLTAGES 128
54 56
55enum fan53555_vendor { 57enum fan53555_vendor {
56 FAN53555_VENDOR_FAIRCHILD = 0, 58 FAN53526_VENDOR_FAIRCHILD = 0,
59 FAN53555_VENDOR_FAIRCHILD,
57 FAN53555_VENDOR_SILERGY, 60 FAN53555_VENDOR_SILERGY,
58}; 61};
59 62
63enum {
64 FAN53526_CHIP_ID_01 = 1,
65};
66
67enum {
68 FAN53526_CHIP_REV_08 = 8,
69};
70
60/* IC Type */ 71/* IC Type */
61enum { 72enum {
62 FAN53555_CHIP_ID_00 = 0, 73 FAN53555_CHIP_ID_00 = 0,
@@ -94,8 +105,12 @@ struct fan53555_device_info {
94 /* Voltage range and step(linear) */ 105 /* Voltage range and step(linear) */
95 unsigned int vsel_min; 106 unsigned int vsel_min;
96 unsigned int vsel_step; 107 unsigned int vsel_step;
108 unsigned int vsel_count;
97 /* Voltage slew rate limiting */ 109 /* Voltage slew rate limiting */
98 unsigned int slew_rate; 110 unsigned int slew_rate;
111 /* Mode */
112 unsigned int mode_reg;
113 unsigned int mode_mask;
99 /* Sleep voltage cache */ 114 /* Sleep voltage cache */
100 unsigned int sleep_vol_cache; 115 unsigned int sleep_vol_cache;
101}; 116};
@@ -111,7 +126,7 @@ static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV)
111 if (ret < 0) 126 if (ret < 0)
112 return ret; 127 return ret;
113 ret = regmap_update_bits(di->regmap, di->sleep_reg, 128 ret = regmap_update_bits(di->regmap, di->sleep_reg,
114 VSEL_NSEL_MASK, ret); 129 di->desc.vsel_mask, ret);
115 if (ret < 0) 130 if (ret < 0)
116 return ret; 131 return ret;
117 /* Cache the sleep voltage setting. 132 /* Cache the sleep voltage setting.
@@ -143,11 +158,11 @@ static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode)
143 158
144 switch (mode) { 159 switch (mode) {
145 case REGULATOR_MODE_FAST: 160 case REGULATOR_MODE_FAST:
146 regmap_update_bits(di->regmap, di->vol_reg, 161 regmap_update_bits(di->regmap, di->mode_reg,
147 VSEL_MODE, VSEL_MODE); 162 di->mode_mask, di->mode_mask);
148 break; 163 break;
149 case REGULATOR_MODE_NORMAL: 164 case REGULATOR_MODE_NORMAL:
150 regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0); 165 regmap_update_bits(di->regmap, di->vol_reg, di->mode_mask, 0);
151 break; 166 break;
152 default: 167 default:
153 return -EINVAL; 168 return -EINVAL;
@@ -161,10 +176,10 @@ static unsigned int fan53555_get_mode(struct regulator_dev *rdev)
161 unsigned int val; 176 unsigned int val;
162 int ret = 0; 177 int ret = 0;
163 178
164 ret = regmap_read(di->regmap, di->vol_reg, &val); 179 ret = regmap_read(di->regmap, di->mode_reg, &val);
165 if (ret < 0) 180 if (ret < 0)
166 return ret; 181 return ret;
167 if (val & VSEL_MODE) 182 if (val & di->mode_mask)
168 return REGULATOR_MODE_FAST; 183 return REGULATOR_MODE_FAST;
169 else 184 else
170 return REGULATOR_MODE_NORMAL; 185 return REGULATOR_MODE_NORMAL;
@@ -219,6 +234,34 @@ static const struct regulator_ops fan53555_regulator_ops = {
219 .set_suspend_disable = fan53555_set_suspend_disable, 234 .set_suspend_disable = fan53555_set_suspend_disable,
220}; 235};
221 236
237static int fan53526_voltages_setup_fairchild(struct fan53555_device_info *di)
238{
239 /* Init voltage range and step */
240 switch (di->chip_id) {
241 case FAN53526_CHIP_ID_01:
242 switch (di->chip_rev) {
243 case FAN53526_CHIP_REV_08:
244 di->vsel_min = 600000;
245 di->vsel_step = 6250;
246 break;
247 default:
248 dev_err(di->dev,
249 "Chip ID %d with rev %d not supported!\n",
250 di->chip_id, di->chip_rev);
251 return -EINVAL;
252 }
253 break;
254 default:
255 dev_err(di->dev,
256 "Chip ID %d not supported!\n", di->chip_id);
257 return -EINVAL;
258 }
259
260 di->vsel_count = FAN53526_NVOLTAGES;
261
262 return 0;
263}
264
222static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di) 265static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
223{ 266{
224 /* Init voltage range and step */ 267 /* Init voltage range and step */
@@ -257,6 +300,8 @@ static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
257 return -EINVAL; 300 return -EINVAL;
258 } 301 }
259 302
303 di->vsel_count = FAN53555_NVOLTAGES;
304
260 return 0; 305 return 0;
261} 306}
262 307
@@ -274,6 +319,8 @@ static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
274 return -EINVAL; 319 return -EINVAL;
275 } 320 }
276 321
322 di->vsel_count = FAN53555_NVOLTAGES;
323
277 return 0; 324 return 0;
278} 325}
279 326
@@ -302,7 +349,35 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
302 return -EINVAL; 349 return -EINVAL;
303 } 350 }
304 351
352 /* Setup mode control register */
353 switch (di->vendor) {
354 case FAN53526_VENDOR_FAIRCHILD:
355 di->mode_reg = FAN53555_CONTROL;
356
357 switch (pdata->sleep_vsel_id) {
358 case FAN53555_VSEL_ID_0:
359 di->mode_mask = CTL_MODE_VSEL1_MODE;
360 break;
361 case FAN53555_VSEL_ID_1:
362 di->mode_mask = CTL_MODE_VSEL0_MODE;
363 break;
364 }
365 break;
366 case FAN53555_VENDOR_FAIRCHILD:
367 case FAN53555_VENDOR_SILERGY:
368 di->mode_reg = di->vol_reg;
369 di->mode_mask = VSEL_MODE;
370 break;
371 default:
372 dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
373 return -EINVAL;
374 }
375
376 /* Setup voltage range */
305 switch (di->vendor) { 377 switch (di->vendor) {
378 case FAN53526_VENDOR_FAIRCHILD:
379 ret = fan53526_voltages_setup_fairchild(di);
380 break;
306 case FAN53555_VENDOR_FAIRCHILD: 381 case FAN53555_VENDOR_FAIRCHILD:
307 ret = fan53555_voltages_setup_fairchild(di); 382 ret = fan53555_voltages_setup_fairchild(di);
308 break; 383 break;
@@ -326,13 +401,13 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
326 rdesc->supply_name = "vin"; 401 rdesc->supply_name = "vin";
327 rdesc->ops = &fan53555_regulator_ops; 402 rdesc->ops = &fan53555_regulator_ops;
328 rdesc->type = REGULATOR_VOLTAGE; 403 rdesc->type = REGULATOR_VOLTAGE;
329 rdesc->n_voltages = FAN53555_NVOLTAGES; 404 rdesc->n_voltages = di->vsel_count;
330 rdesc->enable_reg = di->vol_reg; 405 rdesc->enable_reg = di->vol_reg;
331 rdesc->enable_mask = VSEL_BUCK_EN; 406 rdesc->enable_mask = VSEL_BUCK_EN;
332 rdesc->min_uV = di->vsel_min; 407 rdesc->min_uV = di->vsel_min;
333 rdesc->uV_step = di->vsel_step; 408 rdesc->uV_step = di->vsel_step;
334 rdesc->vsel_reg = di->vol_reg; 409 rdesc->vsel_reg = di->vol_reg;
335 rdesc->vsel_mask = VSEL_NSEL_MASK; 410 rdesc->vsel_mask = di->vsel_count - 1;
336 rdesc->owner = THIS_MODULE; 411 rdesc->owner = THIS_MODULE;
337 412
338 di->rdev = devm_regulator_register(di->dev, &di->desc, config); 413 di->rdev = devm_regulator_register(di->dev, &di->desc, config);
@@ -368,6 +443,9 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
368 443
369static const struct of_device_id fan53555_dt_ids[] = { 444static const struct of_device_id fan53555_dt_ids[] = {
370 { 445 {
446 .compatible = "fcs,fan53526",
447 .data = (void *)FAN53526_VENDOR_FAIRCHILD,
448 }, {
371 .compatible = "fcs,fan53555", 449 .compatible = "fcs,fan53555",
372 .data = (void *)FAN53555_VENDOR_FAIRCHILD 450 .data = (void *)FAN53555_VENDOR_FAIRCHILD
373 }, { 451 }, {
@@ -412,11 +490,13 @@ static int fan53555_regulator_probe(struct i2c_client *client,
412 } else { 490 } else {
413 /* if no ramp constraint set, get the pdata ramp_delay */ 491 /* if no ramp constraint set, get the pdata ramp_delay */
414 if (!di->regulator->constraints.ramp_delay) { 492 if (!di->regulator->constraints.ramp_delay) {
415 int slew_idx = (pdata->slew_rate & 0x7) 493 if (pdata->slew_rate >= ARRAY_SIZE(slew_rates)) {
416 ? pdata->slew_rate : 0; 494 dev_err(&client->dev, "Invalid slew_rate\n");
495 return -EINVAL;
496 }
417 497
418 di->regulator->constraints.ramp_delay 498 di->regulator->constraints.ramp_delay
419 = slew_rates[slew_idx]; 499 = slew_rates[pdata->slew_rate];
420 } 500 }
421 501
422 di->vendor = id->driver_data; 502 di->vendor = id->driver_data;
@@ -467,6 +547,9 @@ static int fan53555_regulator_probe(struct i2c_client *client,
467 547
468static const struct i2c_device_id fan53555_id[] = { 548static const struct i2c_device_id fan53555_id[] = {
469 { 549 {
550 .name = "fan53526",
551 .driver_data = FAN53526_VENDOR_FAIRCHILD
552 }, {
470 .name = "fan53555", 553 .name = "fan53555",
471 .driver_data = FAN53555_VENDOR_FAIRCHILD 554 .driver_data = FAN53555_VENDOR_FAIRCHILD
472 }, { 555 }, {
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 9abdb9130766..b5afc9db2c61 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -79,15 +79,6 @@ of_get_fixed_voltage_config(struct device *dev,
79 79
80 of_property_read_u32(np, "startup-delay-us", &config->startup_delay); 80 of_property_read_u32(np, "startup-delay-us", &config->startup_delay);
81 81
82 /*
83 * FIXME: we pulled active low/high and open drain handling into
84 * gpiolib so it will be handled there. Delete this in the second
85 * step when we also remove the custom inversion handling for all
86 * legacy boardfiles.
87 */
88 config->enable_high = 1;
89 config->gpio_is_open_drain = 0;
90
91 if (of_find_property(np, "vin-supply", NULL)) 82 if (of_find_property(np, "vin-supply", NULL))
92 config->input_supply = "vin"; 83 config->input_supply = "vin";
93 84
@@ -151,24 +142,14 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
151 142
152 drvdata->desc.fixed_uV = config->microvolts; 143 drvdata->desc.fixed_uV = config->microvolts;
153 144
154 cfg.ena_gpio_invert = !config->enable_high; 145 /*
155 if (config->enabled_at_boot) { 146 * The signal will be inverted by the GPIO core if flagged so in the
156 if (config->enable_high) 147 * decriptor.
157 gflags = GPIOD_OUT_HIGH; 148 */
158 else 149 if (config->enabled_at_boot)
159 gflags = GPIOD_OUT_LOW; 150 gflags = GPIOD_OUT_HIGH;
160 } else { 151 else
161 if (config->enable_high) 152 gflags = GPIOD_OUT_LOW;
162 gflags = GPIOD_OUT_LOW;
163 else
164 gflags = GPIOD_OUT_HIGH;
165 }
166 if (config->gpio_is_open_drain) {
167 if (gflags == GPIOD_OUT_HIGH)
168 gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
169 else
170 gflags = GPIOD_OUT_LOW_OPEN_DRAIN;
171 }
172 153
173 /* 154 /*
174 * Some fixed regulators share the enable line between two 155 * Some fixed regulators share the enable line between two
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index b2f5ec4f658a..6157001df0a4 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -30,16 +30,15 @@
30#include <linux/regulator/machine.h> 30#include <linux/regulator/machine.h>
31#include <linux/regulator/of_regulator.h> 31#include <linux/regulator/of_regulator.h>
32#include <linux/regulator/gpio-regulator.h> 32#include <linux/regulator/gpio-regulator.h>
33#include <linux/gpio.h> 33#include <linux/gpio/consumer.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/of.h> 35#include <linux/of.h>
36#include <linux/of_gpio.h>
37 36
38struct gpio_regulator_data { 37struct gpio_regulator_data {
39 struct regulator_desc desc; 38 struct regulator_desc desc;
40 struct regulator_dev *dev; 39 struct regulator_dev *dev;
41 40
42 struct gpio *gpios; 41 struct gpio_desc **gpiods;
43 int nr_gpios; 42 int nr_gpios;
44 43
45 struct gpio_regulator_state *states; 44 struct gpio_regulator_state *states;
@@ -82,7 +81,7 @@ static int gpio_regulator_set_voltage(struct regulator_dev *dev,
82 81
83 for (ptr = 0; ptr < data->nr_gpios; ptr++) { 82 for (ptr = 0; ptr < data->nr_gpios; ptr++) {
84 state = (target & (1 << ptr)) >> ptr; 83 state = (target & (1 << ptr)) >> ptr;
85 gpio_set_value_cansleep(data->gpios[ptr].gpio, state); 84 gpiod_set_value_cansleep(data->gpiods[ptr], state);
86 } 85 }
87 data->state = target; 86 data->state = target;
88 87
@@ -119,7 +118,7 @@ static int gpio_regulator_set_current_limit(struct regulator_dev *dev,
119 118
120 for (ptr = 0; ptr < data->nr_gpios; ptr++) { 119 for (ptr = 0; ptr < data->nr_gpios; ptr++) {
121 state = (target & (1 << ptr)) >> ptr; 120 state = (target & (1 << ptr)) >> ptr;
122 gpio_set_value_cansleep(data->gpios[ptr].gpio, state); 121 gpiod_set_value_cansleep(data->gpiods[ptr], state);
123 } 122 }
124 data->state = target; 123 data->state = target;
125 124
@@ -138,7 +137,8 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
138{ 137{
139 struct gpio_regulator_config *config; 138 struct gpio_regulator_config *config;
140 const char *regtype; 139 const char *regtype;
141 int proplen, gpio, i; 140 int proplen, i;
141 int ngpios;
142 int ret; 142 int ret;
143 143
144 config = devm_kzalloc(dev, 144 config = devm_kzalloc(dev,
@@ -153,59 +153,36 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
153 153
154 config->supply_name = config->init_data->constraints.name; 154 config->supply_name = config->init_data->constraints.name;
155 155
156 if (of_property_read_bool(np, "enable-active-high"))
157 config->enable_high = true;
158
159 if (of_property_read_bool(np, "enable-at-boot")) 156 if (of_property_read_bool(np, "enable-at-boot"))
160 config->enabled_at_boot = true; 157 config->enabled_at_boot = true;
161 158
162 of_property_read_u32(np, "startup-delay-us", &config->startup_delay); 159 of_property_read_u32(np, "startup-delay-us", &config->startup_delay);
163 160
164 config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); 161 /* Fetch GPIO init levels */
165 if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) 162 ngpios = gpiod_count(dev, NULL);
166 return ERR_PTR(config->enable_gpio); 163 if (ngpios > 0) {
167 164 config->gflags = devm_kzalloc(dev,
168 /* Fetch GPIOs. - optional property*/ 165 sizeof(enum gpiod_flags)
169 ret = of_gpio_count(np); 166 * ngpios,
170 if ((ret < 0) && (ret != -ENOENT)) 167 GFP_KERNEL);
171 return ERR_PTR(ret); 168 if (!config->gflags)
172
173 if (ret > 0) {
174 config->nr_gpios = ret;
175 config->gpios = devm_kcalloc(dev,
176 config->nr_gpios, sizeof(struct gpio),
177 GFP_KERNEL);
178 if (!config->gpios)
179 return ERR_PTR(-ENOMEM); 169 return ERR_PTR(-ENOMEM);
180 170
181 proplen = of_property_count_u32_elems(np, "gpios-states"); 171 for (i = 0; i < ngpios; i++) {
182 /* optional property */ 172 u32 val;
183 if (proplen < 0)
184 proplen = 0;
185 173
186 if (proplen > 0 && proplen != config->nr_gpios) { 174 ret = of_property_read_u32_index(np, "gpios-states", i,
187 dev_warn(dev, "gpios <-> gpios-states mismatch\n"); 175 &val);
188 proplen = 0;
189 }
190 176
191 for (i = 0; i < config->nr_gpios; i++) { 177 /* Default to high per specification */
192 gpio = of_get_named_gpio(np, "gpios", i); 178 if (ret)
193 if (gpio < 0) { 179 config->gflags[i] = GPIOD_OUT_HIGH;
194 if (gpio != -ENOENT) 180 else
195 return ERR_PTR(gpio); 181 config->gflags[i] =
196 break; 182 val ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
197 }
198 config->gpios[i].gpio = gpio;
199 config->gpios[i].label = config->supply_name;
200 if (proplen > 0) {
201 of_property_read_u32_index(np, "gpios-states",
202 i, &ret);
203 if (ret)
204 config->gpios[i].flags =
205 GPIOF_OUT_INIT_HIGH;
206 }
207 } 183 }
208 } 184 }
185 config->ngpios = ngpios;
209 186
210 /* Fetch states. */ 187 /* Fetch states. */
211 proplen = of_property_count_u32_elems(np, "states"); 188 proplen = of_property_count_u32_elems(np, "states");
@@ -251,59 +228,56 @@ static struct regulator_ops gpio_regulator_current_ops = {
251 228
252static int gpio_regulator_probe(struct platform_device *pdev) 229static int gpio_regulator_probe(struct platform_device *pdev)
253{ 230{
254 struct gpio_regulator_config *config = dev_get_platdata(&pdev->dev); 231 struct device *dev = &pdev->dev;
255 struct device_node *np = pdev->dev.of_node; 232 struct gpio_regulator_config *config = dev_get_platdata(dev);
233 struct device_node *np = dev->of_node;
256 struct gpio_regulator_data *drvdata; 234 struct gpio_regulator_data *drvdata;
257 struct regulator_config cfg = { }; 235 struct regulator_config cfg = { };
258 int ptr, ret, state; 236 enum gpiod_flags gflags;
237 int ptr, ret, state, i;
259 238
260 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), 239 drvdata = devm_kzalloc(dev, sizeof(struct gpio_regulator_data),
261 GFP_KERNEL); 240 GFP_KERNEL);
262 if (drvdata == NULL) 241 if (drvdata == NULL)
263 return -ENOMEM; 242 return -ENOMEM;
264 243
265 if (np) { 244 if (np) {
266 config = of_get_gpio_regulator_config(&pdev->dev, np, 245 config = of_get_gpio_regulator_config(dev, np,
267 &drvdata->desc); 246 &drvdata->desc);
268 if (IS_ERR(config)) 247 if (IS_ERR(config))
269 return PTR_ERR(config); 248 return PTR_ERR(config);
270 } 249 }
271 250
272 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 251 drvdata->desc.name = devm_kstrdup(dev, config->supply_name, GFP_KERNEL);
273 if (drvdata->desc.name == NULL) { 252 if (drvdata->desc.name == NULL) {
274 dev_err(&pdev->dev, "Failed to allocate supply name\n"); 253 dev_err(dev, "Failed to allocate supply name\n");
275 return -ENOMEM; 254 return -ENOMEM;
276 } 255 }
277 256
278 if (config->nr_gpios != 0) { 257 drvdata->gpiods = devm_kzalloc(dev, sizeof(struct gpio_desc *),
279 drvdata->gpios = kmemdup(config->gpios, 258 GFP_KERNEL);
280 config->nr_gpios * sizeof(struct gpio), 259 if (!drvdata->gpiods)
281 GFP_KERNEL); 260 return -ENOMEM;
282 if (drvdata->gpios == NULL) { 261 for (i = 0; i < config->ngpios; i++) {
283 dev_err(&pdev->dev, "Failed to allocate gpio data\n"); 262 drvdata->gpiods[i] = devm_gpiod_get_index(dev,
284 ret = -ENOMEM; 263 NULL,
285 goto err_name; 264 i,
286 } 265 config->gflags[i]);
287 266 if (IS_ERR(drvdata->gpiods[i]))
288 drvdata->nr_gpios = config->nr_gpios; 267 return PTR_ERR(drvdata->gpiods[i]);
289 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); 268 /* This is good to know */
290 if (ret) { 269 gpiod_set_consumer_name(drvdata->gpiods[i], drvdata->desc.name);
291 if (ret != -EPROBE_DEFER)
292 dev_err(&pdev->dev,
293 "Could not obtain regulator setting GPIOs: %d\n",
294 ret);
295 goto err_memgpio;
296 }
297 } 270 }
271 drvdata->nr_gpios = config->ngpios;
298 272
299 drvdata->states = kmemdup(config->states, 273 drvdata->states = devm_kmemdup(dev,
300 config->nr_states * 274 config->states,
301 sizeof(struct gpio_regulator_state), 275 config->nr_states *
302 GFP_KERNEL); 276 sizeof(struct gpio_regulator_state),
277 GFP_KERNEL);
303 if (drvdata->states == NULL) { 278 if (drvdata->states == NULL) {
304 dev_err(&pdev->dev, "Failed to allocate state data\n"); 279 dev_err(dev, "Failed to allocate state data\n");
305 ret = -ENOMEM; 280 return -ENOMEM;
306 goto err_stategpio;
307 } 281 }
308 drvdata->nr_states = config->nr_states; 282 drvdata->nr_states = config->nr_states;
309 283
@@ -322,61 +296,46 @@ static int gpio_regulator_probe(struct platform_device *pdev)
322 drvdata->desc.ops = &gpio_regulator_current_ops; 296 drvdata->desc.ops = &gpio_regulator_current_ops;
323 break; 297 break;
324 default: 298 default:
325 dev_err(&pdev->dev, "No regulator type set\n"); 299 dev_err(dev, "No regulator type set\n");
326 ret = -EINVAL; 300 return -EINVAL;
327 goto err_memstate;
328 } 301 }
329 302
330 /* build initial state from gpio init data. */ 303 /* build initial state from gpio init data. */
331 state = 0; 304 state = 0;
332 for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) { 305 for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) {
333 if (config->gpios[ptr].flags & GPIOF_OUT_INIT_HIGH) 306 if (config->gflags[ptr] == GPIOD_OUT_HIGH)
334 state |= (1 << ptr); 307 state |= (1 << ptr);
335 } 308 }
336 drvdata->state = state; 309 drvdata->state = state;
337 310
338 cfg.dev = &pdev->dev; 311 cfg.dev = dev;
339 cfg.init_data = config->init_data; 312 cfg.init_data = config->init_data;
340 cfg.driver_data = drvdata; 313 cfg.driver_data = drvdata;
341 cfg.of_node = np; 314 cfg.of_node = np;
342 315
343 if (gpio_is_valid(config->enable_gpio)) { 316 /*
344 cfg.ena_gpio = config->enable_gpio; 317 * The signal will be inverted by the GPIO core if flagged so in the
345 cfg.ena_gpio_initialized = true; 318 * decriptor.
346 } 319 */
347 cfg.ena_gpio_invert = !config->enable_high; 320 if (config->enabled_at_boot)
348 if (config->enabled_at_boot) { 321 gflags = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE;
349 if (config->enable_high) 322 else
350 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; 323 gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE;
351 else 324
352 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; 325 cfg.ena_gpiod = gpiod_get_optional(dev, "enable", gflags);
353 } else { 326 if (IS_ERR(cfg.ena_gpiod))
354 if (config->enable_high) 327 return PTR_ERR(cfg.ena_gpiod);
355 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
356 else
357 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
358 }
359 328
360 drvdata->dev = regulator_register(&drvdata->desc, &cfg); 329 drvdata->dev = regulator_register(&drvdata->desc, &cfg);
361 if (IS_ERR(drvdata->dev)) { 330 if (IS_ERR(drvdata->dev)) {
362 ret = PTR_ERR(drvdata->dev); 331 ret = PTR_ERR(drvdata->dev);
363 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); 332 dev_err(dev, "Failed to register regulator: %d\n", ret);
364 goto err_memstate; 333 return ret;
365 } 334 }
366 335
367 platform_set_drvdata(pdev, drvdata); 336 platform_set_drvdata(pdev, drvdata);
368 337
369 return 0; 338 return 0;
370
371err_memstate:
372 kfree(drvdata->states);
373err_stategpio:
374 gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
375err_memgpio:
376 kfree(drvdata->gpios);
377err_name:
378 kfree(drvdata->desc.name);
379 return ret;
380} 339}
381 340
382static int gpio_regulator_remove(struct platform_device *pdev) 341static int gpio_regulator_remove(struct platform_device *pdev)
@@ -385,13 +344,6 @@ static int gpio_regulator_remove(struct platform_device *pdev)
385 344
386 regulator_unregister(drvdata->dev); 345 regulator_unregister(drvdata->dev);
387 346
388 gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
389
390 kfree(drvdata->states);
391 kfree(drvdata->gpios);
392
393 kfree(drvdata->desc.name);
394
395 return 0; 347 return 0;
396} 348}
397 349
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index 5686a1335bd3..32d3f0499e2d 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -594,28 +594,30 @@ int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev,
594EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range); 594EXPORT_SYMBOL_GPL(regulator_list_voltage_pickable_linear_range);
595 595
596/** 596/**
597 * regulator_list_voltage_linear_range - List voltages for linear ranges 597 * regulator_desc_list_voltage_linear_range - List voltages for linear ranges
598 * 598 *
599 * @rdev: Regulator device 599 * @desc: Regulator desc for regulator which volatges are to be listed
600 * @selector: Selector to convert into a voltage 600 * @selector: Selector to convert into a voltage
601 * 601 *
602 * Regulators with a series of simple linear mappings between voltages 602 * Regulators with a series of simple linear mappings between voltages
603 * and selectors can set linear_ranges in the regulator descriptor and 603 * and selectors who have set linear_ranges in the regulator descriptor
604 * then use this function as their list_voltage() operation, 604 * can use this function prior regulator registration to list voltages.
605 * This is useful when voltages need to be listed during device-tree
606 * parsing.
605 */ 607 */
606int regulator_list_voltage_linear_range(struct regulator_dev *rdev, 608int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
607 unsigned int selector) 609 unsigned int selector)
608{ 610{
609 const struct regulator_linear_range *range; 611 const struct regulator_linear_range *range;
610 int i; 612 int i;
611 613
612 if (!rdev->desc->n_linear_ranges) { 614 if (!desc->n_linear_ranges) {
613 BUG_ON(!rdev->desc->n_linear_ranges); 615 BUG_ON(!desc->n_linear_ranges);
614 return -EINVAL; 616 return -EINVAL;
615 } 617 }
616 618
617 for (i = 0; i < rdev->desc->n_linear_ranges; i++) { 619 for (i = 0; i < desc->n_linear_ranges; i++) {
618 range = &rdev->desc->linear_ranges[i]; 620 range = &desc->linear_ranges[i];
619 621
620 if (!(selector >= range->min_sel && 622 if (!(selector >= range->min_sel &&
621 selector <= range->max_sel)) 623 selector <= range->max_sel))
@@ -628,6 +630,23 @@ int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
628 630
629 return -EINVAL; 631 return -EINVAL;
630} 632}
633EXPORT_SYMBOL_GPL(regulator_desc_list_voltage_linear_range);
634
635/**
636 * regulator_list_voltage_linear_range - List voltages for linear ranges
637 *
638 * @rdev: Regulator device
639 * @selector: Selector to convert into a voltage
640 *
641 * Regulators with a series of simple linear mappings between voltages
642 * and selectors can set linear_ranges in the regulator descriptor and
643 * then use this function as their list_voltage() operation,
644 */
645int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
646 unsigned int selector)
647{
648 return regulator_desc_list_voltage_linear_range(rdev->desc, selector);
649}
631EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range); 650EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range);
632 651
633/** 652/**
@@ -761,3 +780,89 @@ int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
761 rdev->desc->active_discharge_mask, val); 780 rdev->desc->active_discharge_mask, val);
762} 781}
763EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap); 782EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap);
783
784/**
785 * regulator_set_current_limit_regmap - set_current_limit for regmap users
786 *
787 * @rdev: regulator to operate on
788 * @min_uA: Lower bound for current limit
789 * @max_uA: Upper bound for current limit
790 *
791 * Regulators that use regmap for their register I/O can set curr_table,
792 * csel_reg and csel_mask fields in their descriptor and then use this
793 * as their set_current_limit operation, saving some code.
794 */
795int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
796 int min_uA, int max_uA)
797{
798 unsigned int n_currents = rdev->desc->n_current_limits;
799 int i, sel = -1;
800
801 if (n_currents == 0)
802 return -EINVAL;
803
804 if (rdev->desc->curr_table) {
805 const unsigned int *curr_table = rdev->desc->curr_table;
806 bool ascend = curr_table[n_currents - 1] > curr_table[0];
807
808 /* search for closest to maximum */
809 if (ascend) {
810 for (i = n_currents - 1; i >= 0; i--) {
811 if (min_uA <= curr_table[i] &&
812 curr_table[i] <= max_uA) {
813 sel = i;
814 break;
815 }
816 }
817 } else {
818 for (i = 0; i < n_currents; i++) {
819 if (min_uA <= curr_table[i] &&
820 curr_table[i] <= max_uA) {
821 sel = i;
822 break;
823 }
824 }
825 }
826 }
827
828 if (sel < 0)
829 return -EINVAL;
830
831 sel <<= ffs(rdev->desc->csel_mask) - 1;
832
833 return regmap_update_bits(rdev->regmap, rdev->desc->csel_reg,
834 rdev->desc->csel_mask, sel);
835}
836EXPORT_SYMBOL_GPL(regulator_set_current_limit_regmap);
837
838/**
839 * regulator_get_current_limit_regmap - get_current_limit for regmap users
840 *
841 * @rdev: regulator to operate on
842 *
843 * Regulators that use regmap for their register I/O can set the
844 * csel_reg and csel_mask fields in their descriptor and then use this
845 * as their get_current_limit operation, saving some code.
846 */
847int regulator_get_current_limit_regmap(struct regulator_dev *rdev)
848{
849 unsigned int val;
850 int ret;
851
852 ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &val);
853 if (ret != 0)
854 return ret;
855
856 val &= rdev->desc->csel_mask;
857 val >>= ffs(rdev->desc->csel_mask) - 1;
858
859 if (rdev->desc->curr_table) {
860 if (val >= rdev->desc->n_current_limits)
861 return -EINVAL;
862
863 return rdev->desc->curr_table[val];
864 }
865
866 return -EINVAL;
867}
868EXPORT_SYMBOL_GPL(regulator_get_current_limit_regmap);
diff --git a/drivers/regulator/hi655x-regulator.c b/drivers/regulator/hi655x-regulator.c
index 36ae54b53814..bba24a6fdb1e 100644
--- a/drivers/regulator/hi655x-regulator.c
+++ b/drivers/regulator/hi655x-regulator.c
@@ -28,7 +28,6 @@
28struct hi655x_regulator { 28struct hi655x_regulator {
29 unsigned int disable_reg; 29 unsigned int disable_reg;
30 unsigned int status_reg; 30 unsigned int status_reg;
31 unsigned int ctrl_regs;
32 unsigned int ctrl_mask; 31 unsigned int ctrl_mask;
33 struct regulator_desc rdesc; 32 struct regulator_desc rdesc;
34}; 33};
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index 4abd8e9c81e5..6f28bba81d13 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -31,7 +31,6 @@
31/* PMIC details */ 31/* PMIC details */
32struct isl_pmic { 32struct isl_pmic {
33 struct i2c_client *client; 33 struct i2c_client *client;
34 struct regulator_dev *rdev[3];
35 struct mutex mtx; 34 struct mutex mtx;
36}; 35};
37 36
@@ -66,14 +65,14 @@ static int isl6271a_set_voltage_sel(struct regulator_dev *dev,
66 return err; 65 return err;
67} 66}
68 67
69static struct regulator_ops isl_core_ops = { 68static const struct regulator_ops isl_core_ops = {
70 .get_voltage_sel = isl6271a_get_voltage_sel, 69 .get_voltage_sel = isl6271a_get_voltage_sel,
71 .set_voltage_sel = isl6271a_set_voltage_sel, 70 .set_voltage_sel = isl6271a_set_voltage_sel,
72 .list_voltage = regulator_list_voltage_linear, 71 .list_voltage = regulator_list_voltage_linear,
73 .map_voltage = regulator_map_voltage_linear, 72 .map_voltage = regulator_map_voltage_linear,
74}; 73};
75 74
76static struct regulator_ops isl_fixed_ops = { 75static const struct regulator_ops isl_fixed_ops = {
77 .list_voltage = regulator_list_voltage_linear, 76 .list_voltage = regulator_list_voltage_linear,
78}; 77};
79 78
@@ -109,6 +108,7 @@ static const struct regulator_desc isl_rd[] = {
109static int isl6271a_probe(struct i2c_client *i2c, 108static int isl6271a_probe(struct i2c_client *i2c,
110 const struct i2c_device_id *id) 109 const struct i2c_device_id *id)
111{ 110{
111 struct regulator_dev *rdev;
112 struct regulator_config config = { }; 112 struct regulator_config config = { };
113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev); 113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
114 struct isl_pmic *pmic; 114 struct isl_pmic *pmic;
@@ -133,11 +133,10 @@ static int isl6271a_probe(struct i2c_client *i2c,
133 config.init_data = NULL; 133 config.init_data = NULL;
134 config.driver_data = pmic; 134 config.driver_data = pmic;
135 135
136 pmic->rdev[i] = devm_regulator_register(&i2c->dev, &isl_rd[i], 136 rdev = devm_regulator_register(&i2c->dev, &isl_rd[i], &config);
137 &config); 137 if (IS_ERR(rdev)) {
138 if (IS_ERR(pmic->rdev[i])) {
139 dev_err(&i2c->dev, "failed to register %s\n", id->name); 138 dev_err(&i2c->dev, "failed to register %s\n", id->name);
140 return PTR_ERR(pmic->rdev[i]); 139 return PTR_ERR(rdev);
141 } 140 }
142 } 141 }
143 142
diff --git a/drivers/regulator/lm363x-regulator.c b/drivers/regulator/lm363x-regulator.c
index 8c0e8419c43f..c876e161052a 100644
--- a/drivers/regulator/lm363x-regulator.c
+++ b/drivers/regulator/lm363x-regulator.c
@@ -258,6 +258,9 @@ static int lm363x_regulator_probe(struct platform_device *pdev)
258 * Register update is required if the pin is used. 258 * Register update is required if the pin is used.
259 */ 259 */
260 gpiod = lm363x_regulator_of_get_enable_gpio(dev, id); 260 gpiod = lm363x_regulator_of_get_enable_gpio(dev, id);
261 if (IS_ERR(gpiod))
262 return PTR_ERR(gpiod);
263
261 if (gpiod) { 264 if (gpiod) {
262 cfg.ena_gpiod = gpiod; 265 cfg.ena_gpiod = gpiod;
263 266
@@ -265,8 +268,7 @@ static int lm363x_regulator_probe(struct platform_device *pdev)
265 LM3632_EXT_EN_MASK, 268 LM3632_EXT_EN_MASK,
266 LM3632_EXT_EN_MASK); 269 LM3632_EXT_EN_MASK);
267 if (ret) { 270 if (ret) {
268 if (gpiod) 271 gpiod_put(gpiod);
269 gpiod_put(gpiod);
270 dev_err(dev, "External pin err: %d\n", ret); 272 dev_err(dev, "External pin err: %d\n", ret);
271 return ret; 273 return ret;
272 } 274 }
diff --git a/drivers/regulator/lochnagar-regulator.c b/drivers/regulator/lochnagar-regulator.c
index 47f5663e99c8..ff97cc50f2eb 100644
--- a/drivers/regulator/lochnagar-regulator.c
+++ b/drivers/regulator/lochnagar-regulator.c
@@ -232,8 +232,9 @@ static const struct of_device_id lochnagar_of_match[] = {
232 .compatible = "cirrus,lochnagar2-vddcore", 232 .compatible = "cirrus,lochnagar2-vddcore",
233 .data = &lochnagar_regulators[LOCHNAGAR_VDDCORE], 233 .data = &lochnagar_regulators[LOCHNAGAR_VDDCORE],
234 }, 234 },
235 {}, 235 {}
236}; 236};
237MODULE_DEVICE_TABLE(of, lochnagar_of_match);
237 238
238static int lochnagar_regulator_probe(struct platform_device *pdev) 239static int lochnagar_regulator_probe(struct platform_device *pdev)
239{ 240{
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 204b5c5270e0..9e45112658ba 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -159,7 +159,7 @@ static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
159 selector << LDO_VOL_CONTR_SHIFT(ldo)); 159 selector << LDO_VOL_CONTR_SHIFT(ldo));
160} 160}
161 161
162static struct regulator_ops lp3971_ldo_ops = { 162static const struct regulator_ops lp3971_ldo_ops = {
163 .list_voltage = regulator_list_voltage_table, 163 .list_voltage = regulator_list_voltage_table,
164 .map_voltage = regulator_map_voltage_ascend, 164 .map_voltage = regulator_map_voltage_ascend,
165 .is_enabled = lp3971_ldo_is_enabled, 165 .is_enabled = lp3971_ldo_is_enabled,
@@ -233,7 +233,7 @@ static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev,
233 0 << BUCK_VOL_CHANGE_SHIFT(buck)); 233 0 << BUCK_VOL_CHANGE_SHIFT(buck));
234} 234}
235 235
236static struct regulator_ops lp3971_dcdc_ops = { 236static const struct regulator_ops lp3971_dcdc_ops = {
237 .list_voltage = regulator_list_voltage_table, 237 .list_voltage = regulator_list_voltage_table,
238 .map_voltage = regulator_map_voltage_ascend, 238 .map_voltage = regulator_map_voltage_ascend,
239 .is_enabled = lp3971_dcdc_is_enabled, 239 .is_enabled = lp3971_dcdc_is_enabled,
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index ff0c275f902e..fb098198b688 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -305,7 +305,7 @@ static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
305 return ret; 305 return ret;
306} 306}
307 307
308static struct regulator_ops lp3972_ldo_ops = { 308static const struct regulator_ops lp3972_ldo_ops = {
309 .list_voltage = regulator_list_voltage_table, 309 .list_voltage = regulator_list_voltage_table,
310 .map_voltage = regulator_map_voltage_ascend, 310 .map_voltage = regulator_map_voltage_ascend,
311 .is_enabled = lp3972_ldo_is_enabled, 311 .is_enabled = lp3972_ldo_is_enabled,
@@ -386,7 +386,7 @@ static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev,
386 LP3972_VOL_CHANGE_FLAG_MASK, 0); 386 LP3972_VOL_CHANGE_FLAG_MASK, 0);
387} 387}
388 388
389static struct regulator_ops lp3972_dcdc_ops = { 389static const struct regulator_ops lp3972_dcdc_ops = {
390 .list_voltage = regulator_list_voltage_table, 390 .list_voltage = regulator_list_voltage_table,
391 .map_voltage = regulator_map_voltage_ascend, 391 .map_voltage = regulator_map_voltage_ascend,
392 .is_enabled = lp3972_dcdc_is_enabled, 392 .is_enabled = lp3972_dcdc_is_enabled,
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index 38992112fd6e..ca95257ce252 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -353,64 +353,6 @@ static int lp872x_buck_get_voltage_sel(struct regulator_dev *rdev)
353 return val & LP872X_VOUT_M; 353 return val & LP872X_VOUT_M;
354} 354}
355 355
356static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
357 int min_uA, int max_uA)
358{
359 struct lp872x *lp = rdev_get_drvdata(rdev);
360 enum lp872x_regulator_id buck = rdev_get_id(rdev);
361 int i;
362 u8 addr;
363
364 switch (buck) {
365 case LP8725_ID_BUCK1:
366 addr = LP8725_BUCK1_VOUT2;
367 break;
368 case LP8725_ID_BUCK2:
369 addr = LP8725_BUCK2_VOUT2;
370 break;
371 default:
372 return -EINVAL;
373 }
374
375 for (i = ARRAY_SIZE(lp8725_buck_uA) - 1; i >= 0; i--) {
376 if (lp8725_buck_uA[i] >= min_uA &&
377 lp8725_buck_uA[i] <= max_uA)
378 return lp872x_update_bits(lp, addr,
379 LP8725_BUCK_CL_M,
380 i << LP8725_BUCK_CL_S);
381 }
382
383 return -EINVAL;
384}
385
386static int lp8725_buck_get_current_limit(struct regulator_dev *rdev)
387{
388 struct lp872x *lp = rdev_get_drvdata(rdev);
389 enum lp872x_regulator_id buck = rdev_get_id(rdev);
390 u8 addr, val;
391 int ret;
392
393 switch (buck) {
394 case LP8725_ID_BUCK1:
395 addr = LP8725_BUCK1_VOUT2;
396 break;
397 case LP8725_ID_BUCK2:
398 addr = LP8725_BUCK2_VOUT2;
399 break;
400 default:
401 return -EINVAL;
402 }
403
404 ret = lp872x_read_byte(lp, addr, &val);
405 if (ret)
406 return ret;
407
408 val = (val & LP8725_BUCK_CL_M) >> LP8725_BUCK_CL_S;
409
410 return (val < ARRAY_SIZE(lp8725_buck_uA)) ?
411 lp8725_buck_uA[val] : -EINVAL;
412}
413
414static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) 356static int lp872x_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
415{ 357{
416 struct lp872x *lp = rdev_get_drvdata(rdev); 358 struct lp872x *lp = rdev_get_drvdata(rdev);
@@ -478,7 +420,7 @@ static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev)
478 return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 420 return val & mask ? REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
479} 421}
480 422
481static struct regulator_ops lp872x_ldo_ops = { 423static const struct regulator_ops lp872x_ldo_ops = {
482 .list_voltage = regulator_list_voltage_table, 424 .list_voltage = regulator_list_voltage_table,
483 .map_voltage = regulator_map_voltage_ascend, 425 .map_voltage = regulator_map_voltage_ascend,
484 .set_voltage_sel = regulator_set_voltage_sel_regmap, 426 .set_voltage_sel = regulator_set_voltage_sel_regmap,
@@ -489,7 +431,7 @@ static struct regulator_ops lp872x_ldo_ops = {
489 .enable_time = lp872x_regulator_enable_time, 431 .enable_time = lp872x_regulator_enable_time,
490}; 432};
491 433
492static struct regulator_ops lp8720_buck_ops = { 434static const struct regulator_ops lp8720_buck_ops = {
493 .list_voltage = regulator_list_voltage_table, 435 .list_voltage = regulator_list_voltage_table,
494 .map_voltage = regulator_map_voltage_ascend, 436 .map_voltage = regulator_map_voltage_ascend,
495 .set_voltage_sel = lp872x_buck_set_voltage_sel, 437 .set_voltage_sel = lp872x_buck_set_voltage_sel,
@@ -502,7 +444,7 @@ static struct regulator_ops lp8720_buck_ops = {
502 .get_mode = lp872x_buck_get_mode, 444 .get_mode = lp872x_buck_get_mode,
503}; 445};
504 446
505static struct regulator_ops lp8725_buck_ops = { 447static const struct regulator_ops lp8725_buck_ops = {
506 .list_voltage = regulator_list_voltage_table, 448 .list_voltage = regulator_list_voltage_table,
507 .map_voltage = regulator_map_voltage_ascend, 449 .map_voltage = regulator_map_voltage_ascend,
508 .set_voltage_sel = lp872x_buck_set_voltage_sel, 450 .set_voltage_sel = lp872x_buck_set_voltage_sel,
@@ -513,11 +455,11 @@ static struct regulator_ops lp8725_buck_ops = {
513 .enable_time = lp872x_regulator_enable_time, 455 .enable_time = lp872x_regulator_enable_time,
514 .set_mode = lp872x_buck_set_mode, 456 .set_mode = lp872x_buck_set_mode,
515 .get_mode = lp872x_buck_get_mode, 457 .get_mode = lp872x_buck_get_mode,
516 .set_current_limit = lp8725_buck_set_current_limit, 458 .set_current_limit = regulator_set_current_limit_regmap,
517 .get_current_limit = lp8725_buck_get_current_limit, 459 .get_current_limit = regulator_get_current_limit_regmap,
518}; 460};
519 461
520static struct regulator_desc lp8720_regulator_desc[] = { 462static const struct regulator_desc lp8720_regulator_desc[] = {
521 { 463 {
522 .name = "ldo1", 464 .name = "ldo1",
523 .of_match = of_match_ptr("ldo1"), 465 .of_match = of_match_ptr("ldo1"),
@@ -602,7 +544,7 @@ static struct regulator_desc lp8720_regulator_desc[] = {
602 }, 544 },
603}; 545};
604 546
605static struct regulator_desc lp8725_regulator_desc[] = { 547static const struct regulator_desc lp8725_regulator_desc[] = {
606 { 548 {
607 .name = "ldo1", 549 .name = "ldo1",
608 .of_match = of_match_ptr("ldo1"), 550 .of_match = of_match_ptr("ldo1"),
@@ -712,6 +654,10 @@ static struct regulator_desc lp8725_regulator_desc[] = {
712 .owner = THIS_MODULE, 654 .owner = THIS_MODULE,
713 .enable_reg = LP872X_GENERAL_CFG, 655 .enable_reg = LP872X_GENERAL_CFG,
714 .enable_mask = LP8725_BUCK1_EN_M, 656 .enable_mask = LP8725_BUCK1_EN_M,
657 .curr_table = lp8725_buck_uA,
658 .n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
659 .csel_reg = LP8725_BUCK1_VOUT2,
660 .csel_mask = LP8725_BUCK_CL_M,
715 }, 661 },
716 { 662 {
717 .name = "buck2", 663 .name = "buck2",
@@ -724,6 +670,10 @@ static struct regulator_desc lp8725_regulator_desc[] = {
724 .owner = THIS_MODULE, 670 .owner = THIS_MODULE,
725 .enable_reg = LP872X_GENERAL_CFG, 671 .enable_reg = LP872X_GENERAL_CFG,
726 .enable_mask = LP8725_BUCK2_EN_M, 672 .enable_mask = LP8725_BUCK2_EN_M,
673 .curr_table = lp8725_buck_uA,
674 .n_current_limits = ARRAY_SIZE(lp8725_buck_uA),
675 .csel_reg = LP8725_BUCK2_VOUT2,
676 .csel_mask = LP8725_BUCK_CL_M,
727 }, 677 },
728}; 678};
729 679
@@ -820,7 +770,7 @@ static struct regulator_init_data
820 770
821static int lp872x_regulator_register(struct lp872x *lp) 771static int lp872x_regulator_register(struct lp872x *lp)
822{ 772{
823 struct regulator_desc *desc; 773 const struct regulator_desc *desc;
824 struct regulator_config cfg = { }; 774 struct regulator_config cfg = { };
825 struct regulator_dev *rdev; 775 struct regulator_dev *rdev;
826 int i; 776 int i;
diff --git a/drivers/regulator/lp873x-regulator.c b/drivers/regulator/lp873x-regulator.c
index 70e3df653381..b55de293ca7a 100644
--- a/drivers/regulator/lp873x-regulator.c
+++ b/drivers/regulator/lp873x-regulator.c
@@ -39,6 +39,10 @@
39 .ramp_delay = _delay, \ 39 .ramp_delay = _delay, \
40 .linear_ranges = _lr, \ 40 .linear_ranges = _lr, \
41 .n_linear_ranges = ARRAY_SIZE(_lr), \ 41 .n_linear_ranges = ARRAY_SIZE(_lr), \
42 .curr_table = lp873x_buck_uA, \
43 .n_current_limits = ARRAY_SIZE(lp873x_buck_uA), \
44 .csel_reg = (_cr), \
45 .csel_mask = LP873X_BUCK0_CTRL_2_BUCK0_ILIM,\
42 }, \ 46 }, \
43 .ctrl2_reg = _cr, \ 47 .ctrl2_reg = _cr, \
44 } 48 }
@@ -61,7 +65,7 @@ static const struct regulator_linear_range ldo0_ldo1_ranges[] = {
61 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x19, 100000), 65 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x19, 100000),
62}; 66};
63 67
64static unsigned int lp873x_buck_ramp_delay[] = { 68static const unsigned int lp873x_buck_ramp_delay[] = {
65 30000, 15000, 10000, 7500, 3800, 1900, 940, 470 69 30000, 15000, 10000, 7500, 3800, 1900, 940, 470
66}; 70};
67 71
@@ -108,45 +112,8 @@ static int lp873x_buck_set_ramp_delay(struct regulator_dev *rdev,
108 return 0; 112 return 0;
109} 113}
110 114
111static int lp873x_buck_set_current_limit(struct regulator_dev *rdev,
112 int min_uA, int max_uA)
113{
114 int id = rdev_get_id(rdev);
115 struct lp873x *lp873 = rdev_get_drvdata(rdev);
116 int i;
117
118 for (i = ARRAY_SIZE(lp873x_buck_uA) - 1; i >= 0; i--) {
119 if (lp873x_buck_uA[i] >= min_uA &&
120 lp873x_buck_uA[i] <= max_uA)
121 return regmap_update_bits(lp873->regmap,
122 regulators[id].ctrl2_reg,
123 LP873X_BUCK0_CTRL_2_BUCK0_ILIM,
124 i << __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM));
125 }
126
127 return -EINVAL;
128}
129
130static int lp873x_buck_get_current_limit(struct regulator_dev *rdev)
131{
132 int id = rdev_get_id(rdev);
133 struct lp873x *lp873 = rdev_get_drvdata(rdev);
134 int ret;
135 unsigned int val;
136
137 ret = regmap_read(lp873->regmap, regulators[id].ctrl2_reg, &val);
138 if (ret)
139 return ret;
140
141 val = (val & LP873X_BUCK0_CTRL_2_BUCK0_ILIM) >>
142 __ffs(LP873X_BUCK0_CTRL_2_BUCK0_ILIM);
143
144 return (val < ARRAY_SIZE(lp873x_buck_uA)) ?
145 lp873x_buck_uA[val] : -EINVAL;
146}
147
148/* Operations permitted on BUCK0, BUCK1 */ 115/* Operations permitted on BUCK0, BUCK1 */
149static struct regulator_ops lp873x_buck01_ops = { 116static const struct regulator_ops lp873x_buck01_ops = {
150 .is_enabled = regulator_is_enabled_regmap, 117 .is_enabled = regulator_is_enabled_regmap,
151 .enable = regulator_enable_regmap, 118 .enable = regulator_enable_regmap,
152 .disable = regulator_disable_regmap, 119 .disable = regulator_disable_regmap,
@@ -156,12 +123,12 @@ static struct regulator_ops lp873x_buck01_ops = {
156 .map_voltage = regulator_map_voltage_linear_range, 123 .map_voltage = regulator_map_voltage_linear_range,
157 .set_voltage_time_sel = regulator_set_voltage_time_sel, 124 .set_voltage_time_sel = regulator_set_voltage_time_sel,
158 .set_ramp_delay = lp873x_buck_set_ramp_delay, 125 .set_ramp_delay = lp873x_buck_set_ramp_delay,
159 .set_current_limit = lp873x_buck_set_current_limit, 126 .set_current_limit = regulator_set_current_limit_regmap,
160 .get_current_limit = lp873x_buck_get_current_limit, 127 .get_current_limit = regulator_get_current_limit_regmap,
161}; 128};
162 129
163/* Operations permitted on LDO0 and LDO1 */ 130/* Operations permitted on LDO0 and LDO1 */
164static struct regulator_ops lp873x_ldo01_ops = { 131static const struct regulator_ops lp873x_ldo01_ops = {
165 .is_enabled = regulator_is_enabled_regmap, 132 .is_enabled = regulator_is_enabled_regmap,
166 .enable = regulator_enable_regmap, 133 .enable = regulator_enable_regmap,
167 .disable = regulator_disable_regmap, 134 .disable = regulator_disable_regmap,
diff --git a/drivers/regulator/lp8755.c b/drivers/regulator/lp8755.c
index 244822bb63cd..14fd38807134 100644
--- a/drivers/regulator/lp8755.c
+++ b/drivers/regulator/lp8755.c
@@ -315,7 +315,7 @@ out_i2c_error:
315 .vsel_mask = LP8755_BUCK_VOUT_M,\ 315 .vsel_mask = LP8755_BUCK_VOUT_M,\
316} 316}
317 317
318static struct regulator_desc lp8755_regulators[] = { 318static const struct regulator_desc lp8755_regulators[] = {
319 lp8755_buck_desc(0), 319 lp8755_buck_desc(0),
320 lp8755_buck_desc(1), 320 lp8755_buck_desc(1),
321 lp8755_buck_desc(2), 321 lp8755_buck_desc(2),
@@ -386,7 +386,7 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data)
386 if (ret < 0) 386 if (ret < 0)
387 goto err_i2c; 387 goto err_i2c;
388 388
389 /* send OCP event to all regualtor devices */ 389 /* send OCP event to all regulator devices */
390 if ((flag1 & 0x01) && (pchip->irqmask & 0x01)) 390 if ((flag1 & 0x01) && (pchip->irqmask & 0x01))
391 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) 391 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
392 if (pchip->rdev[icnt] != NULL) 392 if (pchip->rdev[icnt] != NULL)
@@ -394,7 +394,7 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data)
394 LP8755_EVENT_OCP, 394 LP8755_EVENT_OCP,
395 NULL); 395 NULL);
396 396
397 /* send OVP event to all regualtor devices */ 397 /* send OVP event to all regulator devices */
398 if ((flag1 & 0x02) && (pchip->irqmask & 0x02)) 398 if ((flag1 & 0x02) && (pchip->irqmask & 0x02))
399 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) 399 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
400 if (pchip->rdev[icnt] != NULL) 400 if (pchip->rdev[icnt] != NULL)
diff --git a/drivers/regulator/lp87565-regulator.c b/drivers/regulator/lp87565-regulator.c
index c192357d1dea..4ed41731a5b1 100644
--- a/drivers/regulator/lp87565-regulator.c
+++ b/drivers/regulator/lp87565-regulator.c
@@ -51,7 +51,7 @@ static const struct regulator_linear_range buck0_1_2_3_ranges[] = {
51 REGULATOR_LINEAR_RANGE(1420000, 0x9e, 0xff, 20000), 51 REGULATOR_LINEAR_RANGE(1420000, 0x9e, 0xff, 20000),
52}; 52};
53 53
54static unsigned int lp87565_buck_ramp_delay[] = { 54static const unsigned int lp87565_buck_ramp_delay[] = {
55 30000, 15000, 10000, 7500, 3800, 1900, 940, 470 55 30000, 15000, 10000, 7500, 3800, 1900, 940, 470
56}; 56};
57 57
@@ -140,7 +140,7 @@ static int lp87565_buck_get_current_limit(struct regulator_dev *rdev)
140} 140}
141 141
142/* Operations permitted on BUCK0, BUCK1 */ 142/* Operations permitted on BUCK0, BUCK1 */
143static struct regulator_ops lp87565_buck_ops = { 143static const struct regulator_ops lp87565_buck_ops = {
144 .is_enabled = regulator_is_enabled_regmap, 144 .is_enabled = regulator_is_enabled_regmap,
145 .enable = regulator_enable_regmap, 145 .enable = regulator_enable_regmap,
146 .disable = regulator_disable_regmap, 146 .disable = regulator_disable_regmap,
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
index ec46290b647e..a7d30550bb5f 100644
--- a/drivers/regulator/lp8788-buck.c
+++ b/drivers/regulator/lp8788-buck.c
@@ -95,12 +95,10 @@ struct lp8788_buck {
95 void *dvs; 95 void *dvs;
96}; 96};
97 97
98/* BUCK 1 ~ 4 voltage table */ 98/* BUCK 1 ~ 4 voltage ranges */
99static const int lp8788_buck_vtbl[] = { 99static const struct regulator_linear_range buck_volt_ranges[] = {
100 500000, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, 100 REGULATOR_LINEAR_RANGE(500000, 0, 0, 0),
101 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 101 REGULATOR_LINEAR_RANGE(800000, 1, 25, 50000),
102 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000,
103 1950000, 2000000,
104}; 102};
105 103
106static void lp8788_buck1_set_dvs(struct lp8788_buck *buck) 104static void lp8788_buck1_set_dvs(struct lp8788_buck *buck)
@@ -345,8 +343,8 @@ static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev)
345} 343}
346 344
347static const struct regulator_ops lp8788_buck12_ops = { 345static const struct regulator_ops lp8788_buck12_ops = {
348 .list_voltage = regulator_list_voltage_table, 346 .list_voltage = regulator_list_voltage_linear_range,
349 .map_voltage = regulator_map_voltage_ascend, 347 .map_voltage = regulator_map_voltage_linear_range,
350 .set_voltage_sel = lp8788_buck12_set_voltage_sel, 348 .set_voltage_sel = lp8788_buck12_set_voltage_sel,
351 .get_voltage_sel = lp8788_buck12_get_voltage_sel, 349 .get_voltage_sel = lp8788_buck12_get_voltage_sel,
352 .enable = regulator_enable_regmap, 350 .enable = regulator_enable_regmap,
@@ -358,8 +356,8 @@ static const struct regulator_ops lp8788_buck12_ops = {
358}; 356};
359 357
360static const struct regulator_ops lp8788_buck34_ops = { 358static const struct regulator_ops lp8788_buck34_ops = {
361 .list_voltage = regulator_list_voltage_table, 359 .list_voltage = regulator_list_voltage_linear_range,
362 .map_voltage = regulator_map_voltage_ascend, 360 .map_voltage = regulator_map_voltage_linear_range,
363 .set_voltage_sel = regulator_set_voltage_sel_regmap, 361 .set_voltage_sel = regulator_set_voltage_sel_regmap,
364 .get_voltage_sel = regulator_get_voltage_sel_regmap, 362 .get_voltage_sel = regulator_get_voltage_sel_regmap,
365 .enable = regulator_enable_regmap, 363 .enable = regulator_enable_regmap,
@@ -370,13 +368,14 @@ static const struct regulator_ops lp8788_buck34_ops = {
370 .get_mode = lp8788_buck_get_mode, 368 .get_mode = lp8788_buck_get_mode,
371}; 369};
372 370
373static struct regulator_desc lp8788_buck_desc[] = { 371static const struct regulator_desc lp8788_buck_desc[] = {
374 { 372 {
375 .name = "buck1", 373 .name = "buck1",
376 .id = BUCK1, 374 .id = BUCK1,
377 .ops = &lp8788_buck12_ops, 375 .ops = &lp8788_buck12_ops,
378 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), 376 .n_voltages = 26,
379 .volt_table = lp8788_buck_vtbl, 377 .linear_ranges = buck_volt_ranges,
378 .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges),
380 .type = REGULATOR_VOLTAGE, 379 .type = REGULATOR_VOLTAGE,
381 .owner = THIS_MODULE, 380 .owner = THIS_MODULE,
382 .enable_reg = LP8788_EN_BUCK, 381 .enable_reg = LP8788_EN_BUCK,
@@ -386,8 +385,9 @@ static struct regulator_desc lp8788_buck_desc[] = {
386 .name = "buck2", 385 .name = "buck2",
387 .id = BUCK2, 386 .id = BUCK2,
388 .ops = &lp8788_buck12_ops, 387 .ops = &lp8788_buck12_ops,
389 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), 388 .n_voltages = 26,
390 .volt_table = lp8788_buck_vtbl, 389 .linear_ranges = buck_volt_ranges,
390 .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges),
391 .type = REGULATOR_VOLTAGE, 391 .type = REGULATOR_VOLTAGE,
392 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
393 .enable_reg = LP8788_EN_BUCK, 393 .enable_reg = LP8788_EN_BUCK,
@@ -397,8 +397,9 @@ static struct regulator_desc lp8788_buck_desc[] = {
397 .name = "buck3", 397 .name = "buck3",
398 .id = BUCK3, 398 .id = BUCK3,
399 .ops = &lp8788_buck34_ops, 399 .ops = &lp8788_buck34_ops,
400 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), 400 .n_voltages = 26,
401 .volt_table = lp8788_buck_vtbl, 401 .linear_ranges = buck_volt_ranges,
402 .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges),
402 .type = REGULATOR_VOLTAGE, 403 .type = REGULATOR_VOLTAGE,
403 .owner = THIS_MODULE, 404 .owner = THIS_MODULE,
404 .vsel_reg = LP8788_BUCK3_VOUT, 405 .vsel_reg = LP8788_BUCK3_VOUT,
@@ -410,8 +411,9 @@ static struct regulator_desc lp8788_buck_desc[] = {
410 .name = "buck4", 411 .name = "buck4",
411 .id = BUCK4, 412 .id = BUCK4,
412 .ops = &lp8788_buck34_ops, 413 .ops = &lp8788_buck34_ops,
413 .n_voltages = ARRAY_SIZE(lp8788_buck_vtbl), 414 .n_voltages = 26,
414 .volt_table = lp8788_buck_vtbl, 415 .linear_ranges = buck_volt_ranges,
416 .n_linear_ranges = ARRAY_SIZE(buck_volt_ranges),
415 .type = REGULATOR_VOLTAGE, 417 .type = REGULATOR_VOLTAGE,
416 .owner = THIS_MODULE, 418 .owner = THIS_MODULE,
417 .vsel_reg = LP8788_BUCK4_VOUT, 419 .vsel_reg = LP8788_BUCK4_VOUT,
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c
index 2ee22e7ea675..a2ef146e6b3a 100644
--- a/drivers/regulator/lp8788-ldo.c
+++ b/drivers/regulator/lp8788-ldo.c
@@ -186,7 +186,7 @@ static const struct regulator_ops lp8788_ldo_voltage_fixed_ops = {
186 .enable_time = lp8788_ldo_enable_time, 186 .enable_time = lp8788_ldo_enable_time,
187}; 187};
188 188
189static struct regulator_desc lp8788_dldo_desc[] = { 189static const struct regulator_desc lp8788_dldo_desc[] = {
190 { 190 {
191 .name = "dldo1", 191 .name = "dldo1",
192 .id = DLDO1, 192 .id = DLDO1,
@@ -343,7 +343,7 @@ static struct regulator_desc lp8788_dldo_desc[] = {
343 }, 343 },
344}; 344};
345 345
346static struct regulator_desc lp8788_aldo_desc[] = { 346static const struct regulator_desc lp8788_aldo_desc[] = {
347 { 347 {
348 .name = "aldo1", 348 .name = "aldo1",
349 .id = ALDO1, 349 .id = ALDO1,
diff --git a/drivers/regulator/ltc3676.c b/drivers/regulator/ltc3676.c
index 71fd0f2a4b76..e6d66e492b85 100644
--- a/drivers/regulator/ltc3676.c
+++ b/drivers/regulator/ltc3676.c
@@ -241,61 +241,10 @@ static struct regulator_desc ltc3676_regulators[LTC3676_NUM_REGULATORS] = {
241 LTC3676_FIXED_REG(LDO4, ldo4, LDOB, 2), 241 LTC3676_FIXED_REG(LDO4, ldo4, LDOB, 2),
242}; 242};
243 243
244static bool ltc3676_writeable_reg(struct device *dev, unsigned int reg) 244static bool ltc3676_readable_writeable_reg(struct device *dev, unsigned int reg)
245{ 245{
246 switch (reg) { 246 switch (reg) {
247 case LTC3676_IRQSTAT: 247 case LTC3676_BUCK1 ... LTC3676_IRQSTAT:
248 case LTC3676_BUCK1:
249 case LTC3676_BUCK2:
250 case LTC3676_BUCK3:
251 case LTC3676_BUCK4:
252 case LTC3676_LDOA:
253 case LTC3676_LDOB:
254 case LTC3676_SQD1:
255 case LTC3676_SQD2:
256 case LTC3676_CNTRL:
257 case LTC3676_DVB1A:
258 case LTC3676_DVB1B:
259 case LTC3676_DVB2A:
260 case LTC3676_DVB2B:
261 case LTC3676_DVB3A:
262 case LTC3676_DVB3B:
263 case LTC3676_DVB4A:
264 case LTC3676_DVB4B:
265 case LTC3676_MSKIRQ:
266 case LTC3676_MSKPG:
267 case LTC3676_USER:
268 case LTC3676_HRST:
269 case LTC3676_CLIRQ:
270 return true;
271 }
272 return false;
273}
274
275static bool ltc3676_readable_reg(struct device *dev, unsigned int reg)
276{
277 switch (reg) {
278 case LTC3676_IRQSTAT:
279 case LTC3676_BUCK1:
280 case LTC3676_BUCK2:
281 case LTC3676_BUCK3:
282 case LTC3676_BUCK4:
283 case LTC3676_LDOA:
284 case LTC3676_LDOB:
285 case LTC3676_SQD1:
286 case LTC3676_SQD2:
287 case LTC3676_CNTRL:
288 case LTC3676_DVB1A:
289 case LTC3676_DVB1B:
290 case LTC3676_DVB2A:
291 case LTC3676_DVB2B:
292 case LTC3676_DVB3A:
293 case LTC3676_DVB3B:
294 case LTC3676_DVB4A:
295 case LTC3676_DVB4B:
296 case LTC3676_MSKIRQ:
297 case LTC3676_MSKPG:
298 case LTC3676_USER:
299 case LTC3676_HRST: 248 case LTC3676_HRST:
300 case LTC3676_CLIRQ: 249 case LTC3676_CLIRQ:
301 return true; 250 return true;
@@ -306,9 +255,7 @@ static bool ltc3676_readable_reg(struct device *dev, unsigned int reg)
306static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg) 255static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg)
307{ 256{
308 switch (reg) { 257 switch (reg) {
309 case LTC3676_IRQSTAT: 258 case LTC3676_IRQSTAT ... LTC3676_PGSTATRT:
310 case LTC3676_PGSTATL:
311 case LTC3676_PGSTATRT:
312 return true; 259 return true;
313 } 260 }
314 return false; 261 return false;
@@ -317,8 +264,8 @@ static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg)
317static const struct regmap_config ltc3676_regmap_config = { 264static const struct regmap_config ltc3676_regmap_config = {
318 .reg_bits = 8, 265 .reg_bits = 8,
319 .val_bits = 8, 266 .val_bits = 8,
320 .writeable_reg = ltc3676_writeable_reg, 267 .writeable_reg = ltc3676_readable_writeable_reg,
321 .readable_reg = ltc3676_readable_reg, 268 .readable_reg = ltc3676_readable_writeable_reg,
322 .volatile_reg = ltc3676_volatile_reg, 269 .volatile_reg = ltc3676_volatile_reg,
323 .max_register = LTC3676_CLIRQ, 270 .max_register = LTC3676_CLIRQ,
324 .use_single_read = true, 271 .use_single_read = true,
@@ -442,5 +389,5 @@ static struct i2c_driver ltc3676_driver = {
442module_i2c_driver(ltc3676_driver); 389module_i2c_driver(ltc3676_driver);
443 390
444MODULE_AUTHOR("Tim Harvey <tharvey@gateworks.com>"); 391MODULE_AUTHOR("Tim Harvey <tharvey@gateworks.com>");
445MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC1376"); 392MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC3676");
446MODULE_LICENSE("GPL v2"); 393MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/max14577-regulator.c b/drivers/regulator/max14577-regulator.c
index bc7f4751bf9c..85a88a9e4d42 100644
--- a/drivers/regulator/max14577-regulator.c
+++ b/drivers/regulator/max14577-regulator.c
@@ -324,4 +324,3 @@ module_exit(max14577_regulator_exit);
324MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>"); 324MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
325MODULE_DESCRIPTION("Maxim 14577/77836 regulator driver"); 325MODULE_DESCRIPTION("Maxim 14577/77836 regulator driver");
326MODULE_LICENSE("GPL"); 326MODULE_LICENSE("GPL");
327MODULE_ALIAS("platform:max14577-regulator");
diff --git a/drivers/regulator/max77620-regulator.c b/drivers/regulator/max77620-regulator.c
index cd93cf53e23c..1607ac673e44 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -690,6 +690,7 @@ static const struct regulator_ops max77620_regulator_ops = {
690 .active_discharge_mask = MAX77620_SD_CFG1_ADE_MASK, \ 690 .active_discharge_mask = MAX77620_SD_CFG1_ADE_MASK, \
691 .active_discharge_reg = MAX77620_REG_##_id##_CFG, \ 691 .active_discharge_reg = MAX77620_REG_##_id##_CFG, \
692 .type = REGULATOR_VOLTAGE, \ 692 .type = REGULATOR_VOLTAGE, \
693 .owner = THIS_MODULE, \
693 }, \ 694 }, \
694 } 695 }
695 696
@@ -721,6 +722,7 @@ static const struct regulator_ops max77620_regulator_ops = {
721 .active_discharge_mask = MAX77620_LDO_CFG2_ADE_MASK, \ 722 .active_discharge_mask = MAX77620_LDO_CFG2_ADE_MASK, \
722 .active_discharge_reg = MAX77620_REG_##_id##_CFG2, \ 723 .active_discharge_reg = MAX77620_REG_##_id##_CFG2, \
723 .type = REGULATOR_VOLTAGE, \ 724 .type = REGULATOR_VOLTAGE, \
725 .owner = THIS_MODULE, \
724 }, \ 726 }, \
725 } 727 }
726 728
diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
new file mode 100644
index 000000000000..31ebf34b01ec
--- /dev/null
+++ b/drivers/regulator/max77650-regulator.c
@@ -0,0 +1,498 @@
1// SPDX-License-Identifier: GPL-2.0
2//
3// Copyright (C) 2018 BayLibre SAS
4// Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
5//
6// Regulator driver for MAXIM 77650/77651 charger/power-supply.
7
8#include <linux/of.h>
9#include <linux/mfd/max77650.h>
10#include <linux/module.h>
11#include <linux/platform_device.h>
12#include <linux/regmap.h>
13#include <linux/regulator/driver.h>
14
15#define MAX77650_REGULATOR_EN_CTRL_MASK GENMASK(3, 0)
16#define MAX77650_REGULATOR_EN_CTRL_BITS(_reg) \
17 ((_reg) & MAX77650_REGULATOR_EN_CTRL_MASK)
18#define MAX77650_REGULATOR_ENABLED GENMASK(2, 1)
19#define MAX77650_REGULATOR_DISABLED BIT(2)
20
21#define MAX77650_REGULATOR_V_LDO_MASK GENMASK(6, 0)
22#define MAX77650_REGULATOR_V_SBB_MASK GENMASK(5, 0)
23
24#define MAX77650_REGULATOR_AD_MASK BIT(3)
25#define MAX77650_REGULATOR_AD_DISABLED 0x00
26#define MAX77650_REGULATOR_AD_ENABLED BIT(3)
27
28#define MAX77650_REGULATOR_CURR_LIM_MASK GENMASK(7, 6)
29
30enum {
31 MAX77650_REGULATOR_ID_LDO = 0,
32 MAX77650_REGULATOR_ID_SBB0,
33 MAX77650_REGULATOR_ID_SBB1,
34 MAX77650_REGULATOR_ID_SBB2,
35 MAX77650_REGULATOR_NUM_REGULATORS,
36};
37
38struct max77650_regulator_desc {
39 struct regulator_desc desc;
40 unsigned int regA;
41 unsigned int regB;
42};
43
44static const u32 max77651_sbb1_regulator_volt_table[] = {
45 2400000, 3200000, 4000000, 4800000,
46 2450000, 3250000, 4050000, 4850000,
47 2500000, 3300000, 4100000, 4900000,
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};
62
63#define MAX77651_REGULATOR_SBB1_SEL_DEC(_val) \
64 (((_val & 0x3c) >> 2) | ((_val & 0x03) << 4))
65#define MAX77651_REGULATOR_SBB1_SEL_ENC(_val) \
66 (((_val & 0x30) >> 4) | ((_val & 0x0f) << 2))
67
68#define MAX77650_REGULATOR_SBB1_SEL_DECR(_val) \
69 do { \
70 _val = MAX77651_REGULATOR_SBB1_SEL_DEC(_val); \
71 _val--; \
72 _val = MAX77651_REGULATOR_SBB1_SEL_ENC(_val); \
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
82static const unsigned int max77650_current_limit_table[] = {
83 1000000, 866000, 707000, 500000,
84};
85
86static int max77650_regulator_is_enabled(struct regulator_dev *rdev)
87{
88 struct max77650_regulator_desc *rdesc;
89 struct regmap *map;
90 int val, rv, en;
91
92 rdesc = rdev_get_drvdata(rdev);
93 map = rdev_get_regmap(rdev);
94
95 rv = regmap_read(map, rdesc->regB, &val);
96 if (rv)
97 return rv;
98
99 en = MAX77650_REGULATOR_EN_CTRL_BITS(val);
100
101 return en != MAX77650_REGULATOR_DISABLED;
102}
103
104static int max77650_regulator_enable(struct regulator_dev *rdev)
105{
106 struct max77650_regulator_desc *rdesc;
107 struct regmap *map;
108
109 rdesc = rdev_get_drvdata(rdev);
110 map = rdev_get_regmap(rdev);
111
112 return regmap_update_bits(map, rdesc->regB,
113 MAX77650_REGULATOR_EN_CTRL_MASK,
114 MAX77650_REGULATOR_ENABLED);
115}
116
117static int max77650_regulator_disable(struct regulator_dev *rdev)
118{
119 struct max77650_regulator_desc *rdesc;
120 struct regmap *map;
121
122 rdesc = rdev_get_drvdata(rdev);
123 map = rdev_get_regmap(rdev);
124
125 return regmap_update_bits(map, rdesc->regB,
126 MAX77650_REGULATOR_EN_CTRL_MASK,
127 MAX77650_REGULATOR_DISABLED);
128}
129
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 = {
221 .is_enabled = max77650_regulator_is_enabled,
222 .enable = max77650_regulator_enable,
223 .disable = max77650_regulator_disable,
224 .list_voltage = regulator_list_voltage_linear,
225 .map_voltage = regulator_map_voltage_linear,
226 .get_voltage_sel = regulator_get_voltage_sel_regmap,
227 .set_voltage_sel = max77650_regulator_set_voltage_sel,
228 .set_active_discharge = regulator_set_active_discharge_regmap,
229};
230
231static const struct regulator_ops max77650_regulator_SBB_ops = {
232 .is_enabled = max77650_regulator_is_enabled,
233 .enable = max77650_regulator_enable,
234 .disable = max77650_regulator_disable,
235 .list_voltage = regulator_list_voltage_linear,
236 .map_voltage = regulator_map_voltage_linear,
237 .get_voltage_sel = regulator_get_voltage_sel_regmap,
238 .set_voltage_sel = max77650_regulator_set_voltage_sel,
239 .get_current_limit = regulator_get_current_limit_regmap,
240 .set_current_limit = regulator_set_current_limit_regmap,
241 .set_active_discharge = regulator_set_active_discharge_regmap,
242};
243
244/* Special case for max77651 SBB1 - non-linear voltage mapping. */
245static const struct regulator_ops max77651_SBB1_regulator_ops = {
246 .is_enabled = max77650_regulator_is_enabled,
247 .enable = max77650_regulator_enable,
248 .disable = max77650_regulator_disable,
249 .list_voltage = regulator_list_voltage_table,
250 .get_voltage_sel = regulator_get_voltage_sel_regmap,
251 .set_voltage_sel = max77651_regulator_sbb1_set_voltage_sel,
252 .get_current_limit = regulator_get_current_limit_regmap,
253 .set_current_limit = regulator_set_current_limit_regmap,
254 .set_active_discharge = regulator_set_active_discharge_regmap,
255};
256
257static struct max77650_regulator_desc max77650_LDO_desc = {
258 .desc = {
259 .name = "ldo",
260 .of_match = of_match_ptr("ldo"),
261 .regulators_node = of_match_ptr("regulators"),
262 .supply_name = "in-ldo",
263 .id = MAX77650_REGULATOR_ID_LDO,
264 .ops = &max77650_regulator_LDO_ops,
265 .min_uV = 1350000,
266 .uV_step = 12500,
267 .n_voltages = 128,
268 .vsel_mask = MAX77650_REGULATOR_V_LDO_MASK,
269 .vsel_reg = MAX77650_REG_CNFG_LDO_A,
270 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
271 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
272 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
273 .active_discharge_reg = MAX77650_REG_CNFG_LDO_B,
274 .enable_time = 100,
275 .type = REGULATOR_VOLTAGE,
276 .owner = THIS_MODULE,
277 },
278 .regA = MAX77650_REG_CNFG_LDO_A,
279 .regB = MAX77650_REG_CNFG_LDO_B,
280};
281
282static struct max77650_regulator_desc max77650_SBB0_desc = {
283 .desc = {
284 .name = "sbb0",
285 .of_match = of_match_ptr("sbb0"),
286 .regulators_node = of_match_ptr("regulators"),
287 .supply_name = "in-sbb0",
288 .id = MAX77650_REGULATOR_ID_SBB0,
289 .ops = &max77650_regulator_SBB_ops,
290 .min_uV = 800000,
291 .uV_step = 25000,
292 .n_voltages = 64,
293 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
294 .vsel_reg = MAX77650_REG_CNFG_SBB0_A,
295 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
296 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
297 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
298 .active_discharge_reg = MAX77650_REG_CNFG_SBB0_B,
299 .enable_time = 100,
300 .type = REGULATOR_VOLTAGE,
301 .owner = THIS_MODULE,
302 .csel_reg = MAX77650_REG_CNFG_SBB0_A,
303 .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK,
304 .curr_table = max77650_current_limit_table,
305 .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
306 },
307 .regA = MAX77650_REG_CNFG_SBB0_A,
308 .regB = MAX77650_REG_CNFG_SBB0_B,
309};
310
311static struct max77650_regulator_desc max77650_SBB1_desc = {
312 .desc = {
313 .name = "sbb1",
314 .of_match = of_match_ptr("sbb1"),
315 .regulators_node = of_match_ptr("regulators"),
316 .supply_name = "in-sbb1",
317 .id = MAX77650_REGULATOR_ID_SBB1,
318 .ops = &max77650_regulator_SBB_ops,
319 .min_uV = 800000,
320 .uV_step = 12500,
321 .n_voltages = 64,
322 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
323 .vsel_reg = MAX77650_REG_CNFG_SBB1_A,
324 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
325 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
326 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
327 .active_discharge_reg = MAX77650_REG_CNFG_SBB1_B,
328 .enable_time = 100,
329 .type = REGULATOR_VOLTAGE,
330 .owner = THIS_MODULE,
331 .csel_reg = MAX77650_REG_CNFG_SBB1_A,
332 .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK,
333 .curr_table = max77650_current_limit_table,
334 .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
335 },
336 .regA = MAX77650_REG_CNFG_SBB1_A,
337 .regB = MAX77650_REG_CNFG_SBB1_B,
338};
339
340static struct max77650_regulator_desc max77651_SBB1_desc = {
341 .desc = {
342 .name = "sbb1",
343 .of_match = of_match_ptr("sbb1"),
344 .regulators_node = of_match_ptr("regulators"),
345 .supply_name = "in-sbb1",
346 .id = MAX77650_REGULATOR_ID_SBB1,
347 .ops = &max77651_SBB1_regulator_ops,
348 .volt_table = max77651_sbb1_regulator_volt_table,
349 .n_voltages = ARRAY_SIZE(max77651_sbb1_regulator_volt_table),
350 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
351 .vsel_reg = MAX77650_REG_CNFG_SBB1_A,
352 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
353 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
354 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
355 .active_discharge_reg = MAX77650_REG_CNFG_SBB1_B,
356 .enable_time = 100,
357 .type = REGULATOR_VOLTAGE,
358 .owner = THIS_MODULE,
359 .csel_reg = MAX77650_REG_CNFG_SBB1_A,
360 .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK,
361 .curr_table = max77650_current_limit_table,
362 .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
363 },
364 .regA = MAX77650_REG_CNFG_SBB1_A,
365 .regB = MAX77650_REG_CNFG_SBB1_B,
366};
367
368static struct max77650_regulator_desc max77650_SBB2_desc = {
369 .desc = {
370 .name = "sbb2",
371 .of_match = of_match_ptr("sbb2"),
372 .regulators_node = of_match_ptr("regulators"),
373 .supply_name = "in-sbb0",
374 .id = MAX77650_REGULATOR_ID_SBB2,
375 .ops = &max77650_regulator_SBB_ops,
376 .min_uV = 800000,
377 .uV_step = 50000,
378 .n_voltages = 64,
379 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
380 .vsel_reg = MAX77650_REG_CNFG_SBB2_A,
381 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
382 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
383 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
384 .active_discharge_reg = MAX77650_REG_CNFG_SBB2_B,
385 .enable_time = 100,
386 .type = REGULATOR_VOLTAGE,
387 .owner = THIS_MODULE,
388 .csel_reg = MAX77650_REG_CNFG_SBB2_A,
389 .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK,
390 .curr_table = max77650_current_limit_table,
391 .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
392 },
393 .regA = MAX77650_REG_CNFG_SBB2_A,
394 .regB = MAX77650_REG_CNFG_SBB2_B,
395};
396
397static struct max77650_regulator_desc max77651_SBB2_desc = {
398 .desc = {
399 .name = "sbb2",
400 .of_match = of_match_ptr("sbb2"),
401 .regulators_node = of_match_ptr("regulators"),
402 .supply_name = "in-sbb0",
403 .id = MAX77650_REGULATOR_ID_SBB2,
404 .ops = &max77650_regulator_SBB_ops,
405 .min_uV = 2400000,
406 .uV_step = 50000,
407 .n_voltages = 64,
408 .vsel_mask = MAX77650_REGULATOR_V_SBB_MASK,
409 .vsel_reg = MAX77650_REG_CNFG_SBB2_A,
410 .active_discharge_off = MAX77650_REGULATOR_AD_DISABLED,
411 .active_discharge_on = MAX77650_REGULATOR_AD_ENABLED,
412 .active_discharge_mask = MAX77650_REGULATOR_AD_MASK,
413 .active_discharge_reg = MAX77650_REG_CNFG_SBB2_B,
414 .enable_time = 100,
415 .type = REGULATOR_VOLTAGE,
416 .owner = THIS_MODULE,
417 .csel_reg = MAX77650_REG_CNFG_SBB2_A,
418 .csel_mask = MAX77650_REGULATOR_CURR_LIM_MASK,
419 .curr_table = max77650_current_limit_table,
420 .n_current_limits = ARRAY_SIZE(max77650_current_limit_table),
421 },
422 .regA = MAX77650_REG_CNFG_SBB2_A,
423 .regB = MAX77650_REG_CNFG_SBB2_B,
424};
425
426static int max77650_regulator_probe(struct platform_device *pdev)
427{
428 struct max77650_regulator_desc **rdescs;
429 struct max77650_regulator_desc *rdesc;
430 struct regulator_config config = { };
431 struct device *dev, *parent;
432 struct regulator_dev *rdev;
433 struct regmap *map;
434 unsigned int val;
435 int i, rv;
436
437 dev = &pdev->dev;
438 parent = dev->parent;
439
440 if (!dev->of_node)
441 dev->of_node = parent->of_node;
442
443 rdescs = devm_kcalloc(dev, MAX77650_REGULATOR_NUM_REGULATORS,
444 sizeof(*rdescs), GFP_KERNEL);
445 if (!rdescs)
446 return -ENOMEM;
447
448 map = dev_get_regmap(parent, NULL);
449 if (!map)
450 return -ENODEV;
451
452 rv = regmap_read(map, MAX77650_REG_CID, &val);
453 if (rv)
454 return rv;
455
456 rdescs[MAX77650_REGULATOR_ID_LDO] = &max77650_LDO_desc;
457 rdescs[MAX77650_REGULATOR_ID_SBB0] = &max77650_SBB0_desc;
458
459 switch (MAX77650_CID_BITS(val)) {
460 case MAX77650_CID_77650A:
461 case MAX77650_CID_77650C:
462 rdescs[MAX77650_REGULATOR_ID_SBB1] = &max77650_SBB1_desc;
463 rdescs[MAX77650_REGULATOR_ID_SBB2] = &max77650_SBB2_desc;
464 break;
465 case MAX77650_CID_77651A:
466 case MAX77650_CID_77651B:
467 rdescs[MAX77650_REGULATOR_ID_SBB1] = &max77651_SBB1_desc;
468 rdescs[MAX77650_REGULATOR_ID_SBB2] = &max77651_SBB2_desc;
469 break;
470 default:
471 return -ENODEV;
472 }
473
474 config.dev = parent;
475
476 for (i = 0; i < MAX77650_REGULATOR_NUM_REGULATORS; i++) {
477 rdesc = rdescs[i];
478 config.driver_data = rdesc;
479
480 rdev = devm_regulator_register(dev, &rdesc->desc, &config);
481 if (IS_ERR(rdev))
482 return PTR_ERR(rdev);
483 }
484
485 return 0;
486}
487
488static struct platform_driver max77650_regulator_driver = {
489 .driver = {
490 .name = "max77650-regulator",
491 },
492 .probe = max77650_regulator_probe,
493};
494module_platform_driver(max77650_regulator_driver);
495
496MODULE_DESCRIPTION("MAXIM 77650/77651 regulator driver");
497MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
498MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c
index c30cf5c9f2de..ea7b50397300 100644
--- a/drivers/regulator/max77802-regulator.c
+++ b/drivers/regulator/max77802-regulator.c
@@ -248,9 +248,9 @@ static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev,
248 unsigned int ramp_value; 248 unsigned int ramp_value;
249 249
250 if (id > MAX77802_BUCK4) { 250 if (id > MAX77802_BUCK4) {
251 dev_warn(&rdev->dev, 251 dev_warn(&rdev->dev,
252 "%s: regulator: ramp delay not supported\n", 252 "%s: regulator: ramp delay not supported\n",
253 rdev->desc->name); 253 rdev->desc->name);
254 return -EINVAL; 254 return -EINVAL;
255 } 255 }
256 ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit, 256 ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit,
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 887a1d1726ad..ab558b26cd7c 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -226,7 +226,7 @@ static const unsigned int mc13783_pwgtdrv_val[] = {
226 5500000, 226 5500000,
227}; 227};
228 228
229static struct regulator_ops mc13783_gpo_regulator_ops; 229static const struct regulator_ops mc13783_gpo_regulator_ops;
230 230
231#define MC13783_DEFINE(prefix, name, node, reg, vsel_reg, voltages) \ 231#define MC13783_DEFINE(prefix, name, node, reg, vsel_reg, voltages) \
232 MC13xxx_DEFINE(MC13783_REG_, name, node, reg, vsel_reg, voltages, \ 232 MC13xxx_DEFINE(MC13783_REG_, name, node, reg, vsel_reg, voltages, \
@@ -380,7 +380,7 @@ static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
380 return (val & mc13xxx_regulators[id].enable_bit) != 0; 380 return (val & mc13xxx_regulators[id].enable_bit) != 0;
381} 381}
382 382
383static struct regulator_ops mc13783_gpo_regulator_ops = { 383static const struct regulator_ops mc13783_gpo_regulator_ops = {
384 .enable = mc13783_gpo_regulator_enable, 384 .enable = mc13783_gpo_regulator_enable,
385 .disable = mc13783_gpo_regulator_disable, 385 .disable = mc13783_gpo_regulator_disable,
386 .is_enabled = mc13783_gpo_regulator_is_enabled, 386 .is_enabled = mc13783_gpo_regulator_is_enabled,
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index b55894980066..a731e826a037 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -242,8 +242,8 @@ static const unsigned int mc13892_pwgtdrv[] = {
242 5000000, 242 5000000,
243}; 243};
244 244
245static struct regulator_ops mc13892_gpo_regulator_ops; 245static const struct regulator_ops mc13892_gpo_regulator_ops;
246static struct regulator_ops mc13892_sw_regulator_ops; 246static const struct regulator_ops mc13892_sw_regulator_ops;
247 247
248 248
249#define MC13892_FIXED_DEFINE(name, node, reg, voltages) \ 249#define MC13892_FIXED_DEFINE(name, node, reg, voltages) \
@@ -387,7 +387,7 @@ static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev)
387} 387}
388 388
389 389
390static struct regulator_ops mc13892_gpo_regulator_ops = { 390static const struct regulator_ops mc13892_gpo_regulator_ops = {
391 .enable = mc13892_gpo_regulator_enable, 391 .enable = mc13892_gpo_regulator_enable,
392 .disable = mc13892_gpo_regulator_disable, 392 .disable = mc13892_gpo_regulator_disable,
393 .is_enabled = mc13892_gpo_regulator_is_enabled, 393 .is_enabled = mc13892_gpo_regulator_is_enabled,
@@ -479,7 +479,7 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
479 return ret; 479 return ret;
480} 480}
481 481
482static struct regulator_ops mc13892_sw_regulator_ops = { 482static const struct regulator_ops mc13892_sw_regulator_ops = {
483 .list_voltage = regulator_list_voltage_table, 483 .list_voltage = regulator_list_voltage_table,
484 .map_voltage = regulator_map_voltage_ascend, 484 .map_voltage = regulator_map_voltage_ascend,
485 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, 485 .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index 2243138d8a58..8ff19150ca92 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -99,7 +99,7 @@ static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
99 return rdev->desc->volt_table[val]; 99 return rdev->desc->volt_table[val];
100} 100}
101 101
102struct regulator_ops mc13xxx_regulator_ops = { 102const struct regulator_ops mc13xxx_regulator_ops = {
103 .enable = mc13xxx_regulator_enable, 103 .enable = mc13xxx_regulator_enable,
104 .disable = mc13xxx_regulator_disable, 104 .disable = mc13xxx_regulator_disable,
105 .is_enabled = mc13xxx_regulator_is_enabled, 105 .is_enabled = mc13xxx_regulator_is_enabled,
@@ -127,7 +127,7 @@ int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
127} 127}
128EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage); 128EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);
129 129
130struct regulator_ops mc13xxx_fixed_regulator_ops = { 130const struct regulator_ops mc13xxx_fixed_regulator_ops = {
131 .enable = mc13xxx_regulator_enable, 131 .enable = mc13xxx_regulator_enable,
132 .disable = mc13xxx_regulator_disable, 132 .disable = mc13xxx_regulator_disable,
133 .is_enabled = mc13xxx_regulator_is_enabled, 133 .is_enabled = mc13xxx_regulator_is_enabled,
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h
index a602b08d4c9e..ba7eff1070bd 100644
--- a/drivers/regulator/mc13xxx.h
+++ b/drivers/regulator/mc13xxx.h
@@ -53,8 +53,8 @@ static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
53} 53}
54#endif 54#endif
55 55
56extern struct regulator_ops mc13xxx_regulator_ops; 56extern const struct regulator_ops mc13xxx_regulator_ops;
57extern struct regulator_ops mc13xxx_fixed_regulator_ops; 57extern const struct regulator_ops mc13xxx_fixed_regulator_ops;
58 58
59#define MC13xxx_DEFINE(prefix, _name, _node, _reg, _vsel_reg, _voltages, _ops) \ 59#define MC13xxx_DEFINE(prefix, _name, _node, _reg, _vsel_reg, _voltages, _ops) \
60 [prefix ## _name] = { \ 60 [prefix ## _name] = { \
diff --git a/drivers/regulator/mcp16502.c b/drivers/regulator/mcp16502.c
index 3479ae009b0b..3a8004abe044 100644
--- a/drivers/regulator/mcp16502.c
+++ b/drivers/regulator/mcp16502.c
@@ -17,6 +17,7 @@
17#include <linux/regmap.h> 17#include <linux/regmap.h>
18#include <linux/regulator/driver.h> 18#include <linux/regulator/driver.h>
19#include <linux/suspend.h> 19#include <linux/suspend.h>
20#include <linux/gpio/consumer.h>
20 21
21#define VDD_LOW_SEL 0x0D 22#define VDD_LOW_SEL 0x0D
22#define VDD_HIGH_SEL 0x3F 23#define VDD_HIGH_SEL 0x3F
@@ -546,7 +547,6 @@ static struct i2c_driver mcp16502_drv = {
546 547
547module_i2c_driver(mcp16502_drv); 548module_i2c_driver(mcp16502_drv);
548 549
549MODULE_VERSION("1.0");
550MODULE_LICENSE("GPL v2"); 550MODULE_LICENSE("GPL v2");
551MODULE_DESCRIPTION("MCP16502 PMIC driver"); 551MODULE_DESCRIPTION("MCP16502 PMIC driver");
552MODULE_AUTHOR("Andrei Stefanescu andrei.stefanescu@microchip.com"); 552MODULE_AUTHOR("Andrei Stefanescu andrei.stefanescu@microchip.com");
diff --git a/drivers/regulator/mt6311-regulator.c b/drivers/regulator/mt6311-regulator.c
index 0495716fd35f..01d69f43d2b0 100644
--- a/drivers/regulator/mt6311-regulator.c
+++ b/drivers/regulator/mt6311-regulator.c
@@ -38,13 +38,9 @@ static const struct regmap_config mt6311_regmap_config = {
38#define MT6311_MAX_UV 1393750 38#define MT6311_MAX_UV 1393750
39#define MT6311_STEP_UV 6250 39#define MT6311_STEP_UV 6250
40 40
41static const struct regulator_linear_range buck_volt_range[] = {
42 REGULATOR_LINEAR_RANGE(MT6311_MIN_UV, 0, 0x7f, MT6311_STEP_UV),
43};
44
45static const struct regulator_ops mt6311_buck_ops = { 41static const struct regulator_ops mt6311_buck_ops = {
46 .list_voltage = regulator_list_voltage_linear_range, 42 .list_voltage = regulator_list_voltage_linear,
47 .map_voltage = regulator_map_voltage_linear_range, 43 .map_voltage = regulator_map_voltage_linear,
48 .set_voltage_sel = regulator_set_voltage_sel_regmap, 44 .set_voltage_sel = regulator_set_voltage_sel_regmap,
49 .get_voltage_sel = regulator_get_voltage_sel_regmap, 45 .get_voltage_sel = regulator_get_voltage_sel_regmap,
50 .set_voltage_time_sel = regulator_set_voltage_time_sel, 46 .set_voltage_time_sel = regulator_set_voltage_time_sel,
@@ -71,8 +67,6 @@ static const struct regulator_ops mt6311_ldo_ops = {
71 .min_uV = MT6311_MIN_UV,\ 67 .min_uV = MT6311_MIN_UV,\
72 .uV_step = MT6311_STEP_UV,\ 68 .uV_step = MT6311_STEP_UV,\
73 .owner = THIS_MODULE,\ 69 .owner = THIS_MODULE,\
74 .linear_ranges = buck_volt_range, \
75 .n_linear_ranges = ARRAY_SIZE(buck_volt_range), \
76 .enable_reg = MT6311_VDVFS11_CON9,\ 70 .enable_reg = MT6311_VDVFS11_CON9,\
77 .enable_mask = MT6311_PMIC_VDVFS11_EN_MASK,\ 71 .enable_mask = MT6311_PMIC_VDVFS11_EN_MASK,\
78 .vsel_reg = MT6311_VDVFS11_CON12,\ 72 .vsel_reg = MT6311_VDVFS11_CON12,\
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index ffa5fc3724e4..7b6bf3536271 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -255,7 +255,7 @@ static void of_get_regulation_constraints(struct device_node *np,
255 * @desc: regulator description 255 * @desc: regulator description
256 * 256 *
257 * Populates regulator_init_data structure by extracting data from device 257 * Populates regulator_init_data structure by extracting data from device
258 * tree node, returns a pointer to the populated struture or NULL if memory 258 * tree node, returns a pointer to the populated structure or NULL if memory
259 * alloc fails. 259 * alloc fails.
260 */ 260 */
261struct regulator_init_data *of_get_regulator_init_data(struct device *dev, 261struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
@@ -547,7 +547,7 @@ bool of_check_coupling_data(struct regulator_dev *rdev)
547 NULL); 547 NULL);
548 548
549 if (c_n_phandles != n_phandles) { 549 if (c_n_phandles != n_phandles) {
550 dev_err(&rdev->dev, "number of couped reg phandles mismatch\n"); 550 dev_err(&rdev->dev, "number of coupled reg phandles mismatch\n");
551 ret = false; 551 ret = false;
552 goto clean; 552 goto clean;
553 } 553 }
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index c2cc392a27d4..7fb9e8dd834e 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -382,7 +382,7 @@ static struct palmas_sleep_requestor_info tps65917_sleep_req_info[] = {
382 EXTERNAL_REQUESTOR_TPS65917(LDO5, 2, 4), 382 EXTERNAL_REQUESTOR_TPS65917(LDO5, 2, 4),
383}; 383};
384 384
385static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500}; 385static const unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500};
386 386
387#define SMPS_CTRL_MODE_OFF 0x00 387#define SMPS_CTRL_MODE_OFF 0x00
388#define SMPS_CTRL_MODE_ON 0x01 388#define SMPS_CTRL_MODE_ON 0x01
diff --git a/drivers/regulator/pv88060-regulator.c b/drivers/regulator/pv88060-regulator.c
index 1f2d8180506b..1600f9821891 100644
--- a/drivers/regulator/pv88060-regulator.c
+++ b/drivers/regulator/pv88060-regulator.c
@@ -53,10 +53,6 @@ enum {
53 53
54struct pv88060_regulator { 54struct pv88060_regulator {
55 struct regulator_desc desc; 55 struct regulator_desc desc;
56 /* Current limiting */
57 unsigned n_current_limits;
58 const int *current_limits;
59 unsigned int limit_mask;
60 unsigned int conf; /* buck configuration register */ 56 unsigned int conf; /* buck configuration register */
61}; 57};
62 58
@@ -75,7 +71,7 @@ static const struct regmap_config pv88060_regmap_config = {
75 * Entry indexes corresponds to register values. 71 * Entry indexes corresponds to register values.
76 */ 72 */
77 73
78static const int pv88060_buck1_limits[] = { 74static const unsigned int pv88060_buck1_limits[] = {
79 1496000, 2393000, 3291000, 4189000 75 1496000, 2393000, 3291000, 4189000
80}; 76};
81 77
@@ -128,40 +124,6 @@ static int pv88060_buck_set_mode(struct regulator_dev *rdev,
128 PV88060_BUCK_MODE_MASK, val); 124 PV88060_BUCK_MODE_MASK, val);
129} 125}
130 126
131static int pv88060_set_current_limit(struct regulator_dev *rdev, int min,
132 int max)
133{
134 struct pv88060_regulator *info = rdev_get_drvdata(rdev);
135 int i;
136
137 /* search for closest to maximum */
138 for (i = info->n_current_limits - 1; i >= 0; i--) {
139 if (min <= info->current_limits[i]
140 && max >= info->current_limits[i]) {
141 return regmap_update_bits(rdev->regmap,
142 info->conf,
143 info->limit_mask,
144 i << PV88060_BUCK_ILIM_SHIFT);
145 }
146 }
147
148 return -EINVAL;
149}
150
151static int pv88060_get_current_limit(struct regulator_dev *rdev)
152{
153 struct pv88060_regulator *info = rdev_get_drvdata(rdev);
154 unsigned int data;
155 int ret;
156
157 ret = regmap_read(rdev->regmap, info->conf, &data);
158 if (ret < 0)
159 return ret;
160
161 data = (data & info->limit_mask) >> PV88060_BUCK_ILIM_SHIFT;
162 return info->current_limits[data];
163}
164
165static const struct regulator_ops pv88060_buck_ops = { 127static const struct regulator_ops pv88060_buck_ops = {
166 .get_mode = pv88060_buck_get_mode, 128 .get_mode = pv88060_buck_get_mode,
167 .set_mode = pv88060_buck_set_mode, 129 .set_mode = pv88060_buck_set_mode,
@@ -171,8 +133,8 @@ static const struct regulator_ops pv88060_buck_ops = {
171 .set_voltage_sel = regulator_set_voltage_sel_regmap, 133 .set_voltage_sel = regulator_set_voltage_sel_regmap,
172 .get_voltage_sel = regulator_get_voltage_sel_regmap, 134 .get_voltage_sel = regulator_get_voltage_sel_regmap,
173 .list_voltage = regulator_list_voltage_linear, 135 .list_voltage = regulator_list_voltage_linear,
174 .set_current_limit = pv88060_set_current_limit, 136 .set_current_limit = regulator_set_current_limit_regmap,
175 .get_current_limit = pv88060_get_current_limit, 137 .get_current_limit = regulator_get_current_limit_regmap,
176}; 138};
177 139
178static const struct regulator_ops pv88060_ldo_ops = { 140static const struct regulator_ops pv88060_ldo_ops = {
@@ -184,6 +146,12 @@ static const struct regulator_ops pv88060_ldo_ops = {
184 .list_voltage = regulator_list_voltage_linear, 146 .list_voltage = regulator_list_voltage_linear,
185}; 147};
186 148
149static const struct regulator_ops pv88060_sw_ops = {
150 .enable = regulator_enable_regmap,
151 .disable = regulator_disable_regmap,
152 .is_enabled = regulator_is_enabled_regmap,
153};
154
187#define PV88060_BUCK(chip, regl_name, min, step, max, limits_array) \ 155#define PV88060_BUCK(chip, regl_name, min, step, max, limits_array) \
188{\ 156{\
189 .desc = {\ 157 .desc = {\
@@ -201,10 +169,11 @@ static const struct regulator_ops pv88060_ldo_ops = {
201 .enable_mask = PV88060_BUCK_EN, \ 169 .enable_mask = PV88060_BUCK_EN, \
202 .vsel_reg = PV88060_REG_##regl_name##_CONF0,\ 170 .vsel_reg = PV88060_REG_##regl_name##_CONF0,\
203 .vsel_mask = PV88060_VBUCK_MASK,\ 171 .vsel_mask = PV88060_VBUCK_MASK,\
172 .curr_table = limits_array,\
173 .n_current_limits = ARRAY_SIZE(limits_array),\
174 .csel_reg = PV88060_REG_##regl_name##_CONF1,\
175 .csel_mask = PV88060_BUCK_ILIM_MASK,\
204 },\ 176 },\
205 .current_limits = limits_array,\
206 .n_current_limits = ARRAY_SIZE(limits_array),\
207 .limit_mask = PV88060_BUCK_ILIM_MASK, \
208 .conf = PV88060_REG_##regl_name##_CONF1,\ 177 .conf = PV88060_REG_##regl_name##_CONF1,\
209} 178}
210 179
@@ -237,9 +206,8 @@ static const struct regulator_ops pv88060_ldo_ops = {
237 .regulators_node = of_match_ptr("regulators"),\ 206 .regulators_node = of_match_ptr("regulators"),\
238 .type = REGULATOR_VOLTAGE,\ 207 .type = REGULATOR_VOLTAGE,\
239 .owner = THIS_MODULE,\ 208 .owner = THIS_MODULE,\
240 .ops = &pv88060_ldo_ops,\ 209 .ops = &pv88060_sw_ops,\
241 .min_uV = max,\ 210 .fixed_uV = max,\
242 .uV_step = 0,\
243 .n_voltages = 1,\ 211 .n_voltages = 1,\
244 .enable_reg = PV88060_REG_##regl_name##_CONF,\ 212 .enable_reg = PV88060_REG_##regl_name##_CONF,\
245 .enable_mask = PV88060_SW_EN,\ 213 .enable_mask = PV88060_SW_EN,\
diff --git a/drivers/regulator/pv88080-regulator.c b/drivers/regulator/pv88080-regulator.c
index 6770e4de2097..bdddacdbeb99 100644
--- a/drivers/regulator/pv88080-regulator.c
+++ b/drivers/regulator/pv88080-regulator.c
@@ -45,12 +45,7 @@ enum pv88080_types {
45 45
46struct pv88080_regulator { 46struct pv88080_regulator {
47 struct regulator_desc desc; 47 struct regulator_desc desc;
48 /* Current limiting */
49 unsigned int n_current_limits;
50 const int *current_limits;
51 unsigned int limit_mask;
52 unsigned int mode_reg; 48 unsigned int mode_reg;
53 unsigned int limit_reg;
54 unsigned int conf2; 49 unsigned int conf2;
55 unsigned int conf5; 50 unsigned int conf5;
56}; 51};
@@ -102,11 +97,11 @@ static const struct regmap_config pv88080_regmap_config = {
102 * Entry indexes corresponds to register values. 97 * Entry indexes corresponds to register values.
103 */ 98 */
104 99
105static const int pv88080_buck1_limits[] = { 100static const unsigned int pv88080_buck1_limits[] = {
106 3230000, 5130000, 6960000, 8790000 101 3230000, 5130000, 6960000, 8790000
107}; 102};
108 103
109static const int pv88080_buck23_limits[] = { 104static const unsigned int pv88080_buck23_limits[] = {
110 1496000, 2393000, 3291000, 4189000 105 1496000, 2393000, 3291000, 4189000
111}; 106};
112 107
@@ -272,40 +267,6 @@ static int pv88080_buck_set_mode(struct regulator_dev *rdev,
272 PV88080_BUCK1_MODE_MASK, val); 267 PV88080_BUCK1_MODE_MASK, val);
273} 268}
274 269
275static int pv88080_set_current_limit(struct regulator_dev *rdev, int min,
276 int max)
277{
278 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
279 int i;
280
281 /* search for closest to maximum */
282 for (i = info->n_current_limits - 1; i >= 0; i--) {
283 if (min <= info->current_limits[i]
284 && max >= info->current_limits[i]) {
285 return regmap_update_bits(rdev->regmap,
286 info->limit_reg,
287 info->limit_mask,
288 i << PV88080_BUCK1_ILIM_SHIFT);
289 }
290 }
291
292 return -EINVAL;
293}
294
295static int pv88080_get_current_limit(struct regulator_dev *rdev)
296{
297 struct pv88080_regulator *info = rdev_get_drvdata(rdev);
298 unsigned int data;
299 int ret;
300
301 ret = regmap_read(rdev->regmap, info->limit_reg, &data);
302 if (ret < 0)
303 return ret;
304
305 data = (data & info->limit_mask) >> PV88080_BUCK1_ILIM_SHIFT;
306 return info->current_limits[data];
307}
308
309static const struct regulator_ops pv88080_buck_ops = { 270static const struct regulator_ops pv88080_buck_ops = {
310 .get_mode = pv88080_buck_get_mode, 271 .get_mode = pv88080_buck_get_mode,
311 .set_mode = pv88080_buck_set_mode, 272 .set_mode = pv88080_buck_set_mode,
@@ -315,8 +276,8 @@ static const struct regulator_ops pv88080_buck_ops = {
315 .set_voltage_sel = regulator_set_voltage_sel_regmap, 276 .set_voltage_sel = regulator_set_voltage_sel_regmap,
316 .get_voltage_sel = regulator_get_voltage_sel_regmap, 277 .get_voltage_sel = regulator_get_voltage_sel_regmap,
317 .list_voltage = regulator_list_voltage_linear, 278 .list_voltage = regulator_list_voltage_linear,
318 .set_current_limit = pv88080_set_current_limit, 279 .set_current_limit = regulator_set_current_limit_regmap,
319 .get_current_limit = pv88080_get_current_limit, 280 .get_current_limit = regulator_get_current_limit_regmap,
320}; 281};
321 282
322static const struct regulator_ops pv88080_hvbuck_ops = { 283static const struct regulator_ops pv88080_hvbuck_ops = {
@@ -341,9 +302,9 @@ static const struct regulator_ops pv88080_hvbuck_ops = {
341 .min_uV = min, \ 302 .min_uV = min, \
342 .uV_step = step, \ 303 .uV_step = step, \
343 .n_voltages = ((max) - (min))/(step) + 1, \ 304 .n_voltages = ((max) - (min))/(step) + 1, \
305 .curr_table = limits_array, \
306 .n_current_limits = ARRAY_SIZE(limits_array), \
344 },\ 307 },\
345 .current_limits = limits_array, \
346 .n_current_limits = ARRAY_SIZE(limits_array), \
347} 308}
348 309
349#define PV88080_HVBUCK(chip, regl_name, min, step, max) \ 310#define PV88080_HVBUCK(chip, regl_name, min, step, max) \
@@ -521,9 +482,9 @@ static int pv88080_i2c_probe(struct i2c_client *i2c,
521 if (init_data) 482 if (init_data)
522 config.init_data = &init_data[i]; 483 config.init_data = &init_data[i];
523 484
524 pv88080_regulator_info[i].limit_reg 485 pv88080_regulator_info[i].desc.csel_reg
525 = regmap_config->buck_regmap[i].buck_limit_reg; 486 = regmap_config->buck_regmap[i].buck_limit_reg;
526 pv88080_regulator_info[i].limit_mask 487 pv88080_regulator_info[i].desc.csel_mask
527 = regmap_config->buck_regmap[i].buck_limit_mask; 488 = regmap_config->buck_regmap[i].buck_limit_mask;
528 pv88080_regulator_info[i].mode_reg 489 pv88080_regulator_info[i].mode_reg
529 = regmap_config->buck_regmap[i].buck_mode_reg; 490 = regmap_config->buck_regmap[i].buck_mode_reg;
diff --git a/drivers/regulator/pv88090-regulator.c b/drivers/regulator/pv88090-regulator.c
index 2302b0df7630..6e97cc6df2ee 100644
--- a/drivers/regulator/pv88090-regulator.c
+++ b/drivers/regulator/pv88090-regulator.c
@@ -42,10 +42,6 @@ enum {
42 42
43struct pv88090_regulator { 43struct pv88090_regulator {
44 struct regulator_desc desc; 44 struct regulator_desc desc;
45 /* Current limiting */
46 unsigned int n_current_limits;
47 const int *current_limits;
48 unsigned int limit_mask;
49 unsigned int conf; 45 unsigned int conf;
50 unsigned int conf2; 46 unsigned int conf2;
51}; 47};
@@ -71,14 +67,14 @@ static const struct regmap_config pv88090_regmap_config = {
71 * Entry indexes corresponds to register values. 67 * Entry indexes corresponds to register values.
72 */ 68 */
73 69
74static const int pv88090_buck1_limits[] = { 70static const unsigned int pv88090_buck1_limits[] = {
75 220000, 440000, 660000, 880000, 1100000, 1320000, 1540000, 1760000, 71 220000, 440000, 660000, 880000, 1100000, 1320000, 1540000, 1760000,
76 1980000, 2200000, 2420000, 2640000, 2860000, 3080000, 3300000, 3520000, 72 1980000, 2200000, 2420000, 2640000, 2860000, 3080000, 3300000, 3520000,
77 3740000, 3960000, 4180000, 4400000, 4620000, 4840000, 5060000, 5280000, 73 3740000, 3960000, 4180000, 4400000, 4620000, 4840000, 5060000, 5280000,
78 5500000, 5720000, 5940000, 6160000, 6380000, 6600000, 6820000, 7040000 74 5500000, 5720000, 5940000, 6160000, 6380000, 6600000, 6820000, 7040000
79}; 75};
80 76
81static const int pv88090_buck23_limits[] = { 77static const unsigned int pv88090_buck23_limits[] = {
82 1496000, 2393000, 3291000, 4189000 78 1496000, 2393000, 3291000, 4189000
83}; 79};
84 80
@@ -150,40 +146,6 @@ static int pv88090_buck_set_mode(struct regulator_dev *rdev,
150 PV88090_BUCK1_MODE_MASK, val); 146 PV88090_BUCK1_MODE_MASK, val);
151} 147}
152 148
153static int pv88090_set_current_limit(struct regulator_dev *rdev, int min,
154 int max)
155{
156 struct pv88090_regulator *info = rdev_get_drvdata(rdev);
157 int i;
158
159 /* search for closest to maximum */
160 for (i = info->n_current_limits - 1; i >= 0; i--) {
161 if (min <= info->current_limits[i]
162 && max >= info->current_limits[i]) {
163 return regmap_update_bits(rdev->regmap,
164 info->conf,
165 info->limit_mask,
166 i << PV88090_BUCK1_ILIM_SHIFT);
167 }
168 }
169
170 return -EINVAL;
171}
172
173static int pv88090_get_current_limit(struct regulator_dev *rdev)
174{
175 struct pv88090_regulator *info = rdev_get_drvdata(rdev);
176 unsigned int data;
177 int ret;
178
179 ret = regmap_read(rdev->regmap, info->conf, &data);
180 if (ret < 0)
181 return ret;
182
183 data = (data & info->limit_mask) >> PV88090_BUCK1_ILIM_SHIFT;
184 return info->current_limits[data];
185}
186
187static const struct regulator_ops pv88090_buck_ops = { 149static const struct regulator_ops pv88090_buck_ops = {
188 .get_mode = pv88090_buck_get_mode, 150 .get_mode = pv88090_buck_get_mode,
189 .set_mode = pv88090_buck_set_mode, 151 .set_mode = pv88090_buck_set_mode,
@@ -193,8 +155,8 @@ static const struct regulator_ops pv88090_buck_ops = {
193 .set_voltage_sel = regulator_set_voltage_sel_regmap, 155 .set_voltage_sel = regulator_set_voltage_sel_regmap,
194 .get_voltage_sel = regulator_get_voltage_sel_regmap, 156 .get_voltage_sel = regulator_get_voltage_sel_regmap,
195 .list_voltage = regulator_list_voltage_linear, 157 .list_voltage = regulator_list_voltage_linear,
196 .set_current_limit = pv88090_set_current_limit, 158 .set_current_limit = regulator_set_current_limit_regmap,
197 .get_current_limit = pv88090_get_current_limit, 159 .get_current_limit = regulator_get_current_limit_regmap,
198}; 160};
199 161
200static const struct regulator_ops pv88090_ldo_ops = { 162static const struct regulator_ops pv88090_ldo_ops = {
@@ -223,10 +185,11 @@ static const struct regulator_ops pv88090_ldo_ops = {
223 .enable_mask = PV88090_##regl_name##_EN, \ 185 .enable_mask = PV88090_##regl_name##_EN, \
224 .vsel_reg = PV88090_REG_##regl_name##_CONF0, \ 186 .vsel_reg = PV88090_REG_##regl_name##_CONF0, \
225 .vsel_mask = PV88090_V##regl_name##_MASK, \ 187 .vsel_mask = PV88090_V##regl_name##_MASK, \
188 .curr_table = limits_array, \
189 .n_current_limits = ARRAY_SIZE(limits_array), \
190 .csel_reg = PV88090_REG_##regl_name##_CONF1, \
191 .csel_mask = PV88090_##regl_name##_ILIM_MASK, \
226 },\ 192 },\
227 .current_limits = limits_array, \
228 .n_current_limits = ARRAY_SIZE(limits_array), \
229 .limit_mask = PV88090_##regl_name##_ILIM_MASK, \
230 .conf = PV88090_REG_##regl_name##_CONF1, \ 193 .conf = PV88090_REG_##regl_name##_CONF1, \
231 .conf2 = PV88090_REG_##regl_name##_CONF2, \ 194 .conf2 = PV88090_REG_##regl_name##_CONF2, \
232} 195}
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index a2fd140eff81..3f53f9134b32 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -40,9 +40,6 @@ struct pwm_regulator_data {
40 /* regulator descriptor */ 40 /* regulator descriptor */
41 struct regulator_desc desc; 41 struct regulator_desc desc;
42 42
43 /* Regulator ops */
44 struct regulator_ops ops;
45
46 int state; 43 int state;
47 44
48 /* Enable GPIO */ 45 /* Enable GPIO */
@@ -231,7 +228,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev,
231 return 0; 228 return 0;
232} 229}
233 230
234static struct regulator_ops pwm_regulator_voltage_table_ops = { 231static const struct regulator_ops pwm_regulator_voltage_table_ops = {
235 .set_voltage_sel = pwm_regulator_set_voltage_sel, 232 .set_voltage_sel = pwm_regulator_set_voltage_sel,
236 .get_voltage_sel = pwm_regulator_get_voltage_sel, 233 .get_voltage_sel = pwm_regulator_get_voltage_sel,
237 .list_voltage = pwm_regulator_list_voltage, 234 .list_voltage = pwm_regulator_list_voltage,
@@ -241,7 +238,7 @@ static struct regulator_ops pwm_regulator_voltage_table_ops = {
241 .is_enabled = pwm_regulator_is_enabled, 238 .is_enabled = pwm_regulator_is_enabled,
242}; 239};
243 240
244static struct regulator_ops pwm_regulator_voltage_continuous_ops = { 241static const struct regulator_ops pwm_regulator_voltage_continuous_ops = {
245 .get_voltage = pwm_regulator_get_voltage, 242 .get_voltage = pwm_regulator_get_voltage,
246 .set_voltage = pwm_regulator_set_voltage, 243 .set_voltage = pwm_regulator_set_voltage,
247 .enable = pwm_regulator_enable, 244 .enable = pwm_regulator_enable,
@@ -249,7 +246,7 @@ static struct regulator_ops pwm_regulator_voltage_continuous_ops = {
249 .is_enabled = pwm_regulator_is_enabled, 246 .is_enabled = pwm_regulator_is_enabled,
250}; 247};
251 248
252static struct regulator_desc pwm_regulator_desc = { 249static const struct regulator_desc pwm_regulator_desc = {
253 .name = "pwm-regulator", 250 .name = "pwm-regulator",
254 .type = REGULATOR_VOLTAGE, 251 .type = REGULATOR_VOLTAGE,
255 .owner = THIS_MODULE, 252 .owner = THIS_MODULE,
@@ -287,9 +284,7 @@ static int pwm_regulator_init_table(struct platform_device *pdev,
287 284
288 drvdata->state = -EINVAL; 285 drvdata->state = -EINVAL;
289 drvdata->duty_cycle_table = duty_cycle_table; 286 drvdata->duty_cycle_table = duty_cycle_table;
290 memcpy(&drvdata->ops, &pwm_regulator_voltage_table_ops, 287 drvdata->desc.ops = &pwm_regulator_voltage_table_ops;
291 sizeof(drvdata->ops));
292 drvdata->desc.ops = &drvdata->ops;
293 drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table); 288 drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table);
294 289
295 return 0; 290 return 0;
@@ -301,9 +296,7 @@ static int pwm_regulator_init_continuous(struct platform_device *pdev,
301 u32 dutycycle_range[2] = { 0, 100 }; 296 u32 dutycycle_range[2] = { 0, 100 };
302 u32 dutycycle_unit = 100; 297 u32 dutycycle_unit = 100;
303 298
304 memcpy(&drvdata->ops, &pwm_regulator_voltage_continuous_ops, 299 drvdata->desc.ops = &pwm_regulator_voltage_continuous_ops;
305 sizeof(drvdata->ops));
306 drvdata->desc.ops = &drvdata->ops;
307 drvdata->desc.continuous_voltage_range = true; 300 drvdata->desc.continuous_voltage_range = true;
308 301
309 of_property_read_u32_array(pdev->dev.of_node, 302 of_property_read_u32_array(pdev->dev.of_node,
diff --git a/drivers/regulator/qcom_smd-regulator.c b/drivers/regulator/qcom_smd-regulator.c
index f5bca77d67c1..68bc23df4213 100644
--- a/drivers/regulator/qcom_smd-regulator.c
+++ b/drivers/regulator/qcom_smd-regulator.c
@@ -31,6 +31,11 @@ struct qcom_rpm_reg {
31 31
32 int is_enabled; 32 int is_enabled;
33 int uV; 33 int uV;
34 u32 load;
35
36 unsigned int enabled_updated:1;
37 unsigned int uv_updated:1;
38 unsigned int load_updated:1;
34}; 39};
35 40
36struct rpm_regulator_req { 41struct rpm_regulator_req {
@@ -43,30 +48,59 @@ struct rpm_regulator_req {
43#define RPM_KEY_UV 0x00007675 /* "uv" */ 48#define RPM_KEY_UV 0x00007675 /* "uv" */
44#define RPM_KEY_MA 0x0000616d /* "ma" */ 49#define RPM_KEY_MA 0x0000616d /* "ma" */
45 50
46static int rpm_reg_write_active(struct qcom_rpm_reg *vreg, 51static int rpm_reg_write_active(struct qcom_rpm_reg *vreg)
47 struct rpm_regulator_req *req,
48 size_t size)
49{ 52{
50 return qcom_rpm_smd_write(vreg->rpm, 53 struct rpm_regulator_req req[3];
51 QCOM_SMD_RPM_ACTIVE_STATE, 54 int reqlen = 0;
52 vreg->type, 55 int ret;
53 vreg->id, 56
54 req, size); 57 if (vreg->enabled_updated) {
58 req[reqlen].key = cpu_to_le32(RPM_KEY_SWEN);
59 req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
60 req[reqlen].value = cpu_to_le32(vreg->is_enabled);
61 reqlen++;
62 }
63
64 if (vreg->uv_updated && vreg->is_enabled) {
65 req[reqlen].key = cpu_to_le32(RPM_KEY_UV);
66 req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
67 req[reqlen].value = cpu_to_le32(vreg->uV);
68 reqlen++;
69 }
70
71 if (vreg->load_updated && vreg->is_enabled) {
72 req[reqlen].key = cpu_to_le32(RPM_KEY_MA);
73 req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
74 req[reqlen].value = cpu_to_le32(vreg->load / 1000);
75 reqlen++;
76 }
77
78 if (!reqlen)
79 return 0;
80
81 ret = qcom_rpm_smd_write(vreg->rpm, QCOM_SMD_RPM_ACTIVE_STATE,
82 vreg->type, vreg->id,
83 req, sizeof(req[0]) * reqlen);
84 if (!ret) {
85 vreg->enabled_updated = 0;
86 vreg->uv_updated = 0;
87 vreg->load_updated = 0;
88 }
89
90 return ret;
55} 91}
56 92
57static int rpm_reg_enable(struct regulator_dev *rdev) 93static int rpm_reg_enable(struct regulator_dev *rdev)
58{ 94{
59 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 95 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
60 struct rpm_regulator_req req;
61 int ret; 96 int ret;
62 97
63 req.key = cpu_to_le32(RPM_KEY_SWEN); 98 vreg->is_enabled = 1;
64 req.nbytes = cpu_to_le32(sizeof(u32)); 99 vreg->enabled_updated = 1;
65 req.value = cpu_to_le32(1);
66 100
67 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 101 ret = rpm_reg_write_active(vreg);
68 if (!ret) 102 if (ret)
69 vreg->is_enabled = 1; 103 vreg->is_enabled = 0;
70 104
71 return ret; 105 return ret;
72} 106}
@@ -81,16 +115,14 @@ static int rpm_reg_is_enabled(struct regulator_dev *rdev)
81static int rpm_reg_disable(struct regulator_dev *rdev) 115static int rpm_reg_disable(struct regulator_dev *rdev)
82{ 116{
83 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 117 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
84 struct rpm_regulator_req req;
85 int ret; 118 int ret;
86 119
87 req.key = cpu_to_le32(RPM_KEY_SWEN); 120 vreg->is_enabled = 0;
88 req.nbytes = cpu_to_le32(sizeof(u32)); 121 vreg->enabled_updated = 1;
89 req.value = 0;
90 122
91 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 123 ret = rpm_reg_write_active(vreg);
92 if (!ret) 124 if (ret)
93 vreg->is_enabled = 0; 125 vreg->is_enabled = 1;
94 126
95 return ret; 127 return ret;
96} 128}
@@ -108,16 +140,15 @@ static int rpm_reg_set_voltage(struct regulator_dev *rdev,
108 unsigned *selector) 140 unsigned *selector)
109{ 141{
110 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 142 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
111 struct rpm_regulator_req req; 143 int ret;
112 int ret = 0; 144 int old_uV = vreg->uV;
113 145
114 req.key = cpu_to_le32(RPM_KEY_UV); 146 vreg->uV = min_uV;
115 req.nbytes = cpu_to_le32(sizeof(u32)); 147 vreg->uv_updated = 1;
116 req.value = cpu_to_le32(min_uV);
117 148
118 ret = rpm_reg_write_active(vreg, &req, sizeof(req)); 149 ret = rpm_reg_write_active(vreg);
119 if (!ret) 150 if (ret)
120 vreg->uV = min_uV; 151 vreg->uV = old_uV;
121 152
122 return ret; 153 return ret;
123} 154}
@@ -125,13 +156,16 @@ static int rpm_reg_set_voltage(struct regulator_dev *rdev,
125static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA) 156static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA)
126{ 157{
127 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); 158 struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
128 struct rpm_regulator_req req; 159 u32 old_load = vreg->load;
160 int ret;
129 161
130 req.key = cpu_to_le32(RPM_KEY_MA); 162 vreg->load = load_uA;
131 req.nbytes = cpu_to_le32(sizeof(u32)); 163 vreg->load_updated = 1;
132 req.value = cpu_to_le32(load_uA / 1000); 164 ret = rpm_reg_write_active(vreg);
165 if (ret)
166 vreg->load = old_load;
133 167
134 return rpm_reg_write_active(vreg, &req, sizeof(req)); 168 return ret;
135} 169}
136 170
137static const struct regulator_ops rpm_smps_ldo_ops = { 171static const struct regulator_ops rpm_smps_ldo_ops = {
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index 213b68743cc8..23713e16c286 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Regulator driver for Rockchip RK808/RK818 2 * Regulator driver for Rockchip RK805/RK808/RK818
3 * 3 *
4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd 4 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
5 * 5 *
@@ -363,28 +363,28 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
363 rdev->desc->enable_mask); 363 rdev->desc->enable_mask);
364} 364}
365 365
366static struct regulator_ops rk805_reg_ops = { 366static const struct regulator_ops rk805_reg_ops = {
367 .list_voltage = regulator_list_voltage_linear, 367 .list_voltage = regulator_list_voltage_linear,
368 .map_voltage = regulator_map_voltage_linear, 368 .map_voltage = regulator_map_voltage_linear,
369 .get_voltage_sel = regulator_get_voltage_sel_regmap, 369 .get_voltage_sel = regulator_get_voltage_sel_regmap,
370 .set_voltage_sel = regulator_set_voltage_sel_regmap, 370 .set_voltage_sel = regulator_set_voltage_sel_regmap,
371 .enable = regulator_enable_regmap, 371 .enable = regulator_enable_regmap,
372 .disable = regulator_disable_regmap, 372 .disable = regulator_disable_regmap,
373 .is_enabled = regulator_is_enabled_regmap, 373 .is_enabled = regulator_is_enabled_regmap,
374 .set_suspend_voltage = rk808_set_suspend_voltage, 374 .set_suspend_voltage = rk808_set_suspend_voltage,
375 .set_suspend_enable = rk805_set_suspend_enable, 375 .set_suspend_enable = rk805_set_suspend_enable,
376 .set_suspend_disable = rk805_set_suspend_disable, 376 .set_suspend_disable = rk805_set_suspend_disable,
377}; 377};
378 378
379static struct regulator_ops rk805_switch_ops = { 379static const struct regulator_ops rk805_switch_ops = {
380 .enable = regulator_enable_regmap, 380 .enable = regulator_enable_regmap,
381 .disable = regulator_disable_regmap, 381 .disable = regulator_disable_regmap,
382 .is_enabled = regulator_is_enabled_regmap, 382 .is_enabled = regulator_is_enabled_regmap,
383 .set_suspend_enable = rk805_set_suspend_enable, 383 .set_suspend_enable = rk805_set_suspend_enable,
384 .set_suspend_disable = rk805_set_suspend_disable, 384 .set_suspend_disable = rk805_set_suspend_disable,
385}; 385};
386 386
387static struct regulator_ops rk808_buck1_2_ops = { 387static const struct regulator_ops rk808_buck1_2_ops = {
388 .list_voltage = regulator_list_voltage_linear, 388 .list_voltage = regulator_list_voltage_linear,
389 .map_voltage = regulator_map_voltage_linear, 389 .map_voltage = regulator_map_voltage_linear,
390 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap, 390 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap,
@@ -399,7 +399,7 @@ static struct regulator_ops rk808_buck1_2_ops = {
399 .set_suspend_disable = rk808_set_suspend_disable, 399 .set_suspend_disable = rk808_set_suspend_disable,
400}; 400};
401 401
402static struct regulator_ops rk808_reg_ops = { 402static const struct regulator_ops rk808_reg_ops = {
403 .list_voltage = regulator_list_voltage_linear, 403 .list_voltage = regulator_list_voltage_linear,
404 .map_voltage = regulator_map_voltage_linear, 404 .map_voltage = regulator_map_voltage_linear,
405 .get_voltage_sel = regulator_get_voltage_sel_regmap, 405 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -412,7 +412,7 @@ static struct regulator_ops rk808_reg_ops = {
412 .set_suspend_disable = rk808_set_suspend_disable, 412 .set_suspend_disable = rk808_set_suspend_disable,
413}; 413};
414 414
415static struct regulator_ops rk808_reg_ops_ranges = { 415static const struct regulator_ops rk808_reg_ops_ranges = {
416 .list_voltage = regulator_list_voltage_linear_range, 416 .list_voltage = regulator_list_voltage_linear_range,
417 .map_voltage = regulator_map_voltage_linear_range, 417 .map_voltage = regulator_map_voltage_linear_range,
418 .get_voltage_sel = regulator_get_voltage_sel_regmap, 418 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -425,7 +425,7 @@ static struct regulator_ops rk808_reg_ops_ranges = {
425 .set_suspend_disable = rk808_set_suspend_disable, 425 .set_suspend_disable = rk808_set_suspend_disable,
426}; 426};
427 427
428static struct regulator_ops rk808_switch_ops = { 428static const struct regulator_ops rk808_switch_ops = {
429 .enable = regulator_enable_regmap, 429 .enable = regulator_enable_regmap,
430 .disable = regulator_disable_regmap, 430 .disable = regulator_disable_regmap,
431 .is_enabled = regulator_is_enabled_regmap, 431 .is_enabled = regulator_is_enabled_regmap,
@@ -433,6 +433,12 @@ static struct regulator_ops rk808_switch_ops = {
433 .set_suspend_disable = rk808_set_suspend_disable, 433 .set_suspend_disable = rk808_set_suspend_disable,
434}; 434};
435 435
436static const struct regulator_linear_range rk805_buck_1_2_voltage_ranges[] = {
437 REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500),
438 REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),
439 REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0),
440};
441
436static const struct regulator_desc rk805_reg[] = { 442static const struct regulator_desc rk805_reg[] = {
437 { 443 {
438 .name = "DCDC_REG1", 444 .name = "DCDC_REG1",
@@ -440,11 +446,11 @@ static const struct regulator_desc rk805_reg[] = {
440 .of_match = of_match_ptr("DCDC_REG1"), 446 .of_match = of_match_ptr("DCDC_REG1"),
441 .regulators_node = of_match_ptr("regulators"), 447 .regulators_node = of_match_ptr("regulators"),
442 .id = RK805_ID_DCDC1, 448 .id = RK805_ID_DCDC1,
443 .ops = &rk805_reg_ops, 449 .ops = &rk808_reg_ops_ranges,
444 .type = REGULATOR_VOLTAGE, 450 .type = REGULATOR_VOLTAGE,
445 .min_uV = 712500,
446 .uV_step = 12500,
447 .n_voltages = 64, 451 .n_voltages = 64,
452 .linear_ranges = rk805_buck_1_2_voltage_ranges,
453 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
448 .vsel_reg = RK805_BUCK1_ON_VSEL_REG, 454 .vsel_reg = RK805_BUCK1_ON_VSEL_REG,
449 .vsel_mask = RK818_BUCK_VSEL_MASK, 455 .vsel_mask = RK818_BUCK_VSEL_MASK,
450 .enable_reg = RK805_DCDC_EN_REG, 456 .enable_reg = RK805_DCDC_EN_REG,
@@ -456,11 +462,11 @@ static const struct regulator_desc rk805_reg[] = {
456 .of_match = of_match_ptr("DCDC_REG2"), 462 .of_match = of_match_ptr("DCDC_REG2"),
457 .regulators_node = of_match_ptr("regulators"), 463 .regulators_node = of_match_ptr("regulators"),
458 .id = RK805_ID_DCDC2, 464 .id = RK805_ID_DCDC2,
459 .ops = &rk805_reg_ops, 465 .ops = &rk808_reg_ops_ranges,
460 .type = REGULATOR_VOLTAGE, 466 .type = REGULATOR_VOLTAGE,
461 .min_uV = 712500,
462 .uV_step = 12500,
463 .n_voltages = 64, 467 .n_voltages = 64,
468 .linear_ranges = rk805_buck_1_2_voltage_ranges,
469 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
464 .vsel_reg = RK805_BUCK2_ON_VSEL_REG, 470 .vsel_reg = RK805_BUCK2_ON_VSEL_REG,
465 .vsel_mask = RK818_BUCK_VSEL_MASK, 471 .vsel_mask = RK818_BUCK_VSEL_MASK,
466 .enable_reg = RK805_DCDC_EN_REG, 472 .enable_reg = RK805_DCDC_EN_REG,
@@ -796,7 +802,7 @@ static struct platform_driver rk808_regulator_driver = {
796 802
797module_platform_driver(rk808_regulator_driver); 803module_platform_driver(rk808_regulator_driver);
798 804
799MODULE_DESCRIPTION("regulator driver for the RK808/RK818 series PMICs"); 805MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK818 series PMICs");
800MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); 806MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
801MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>"); 807MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
802MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>"); 808MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
diff --git a/drivers/regulator/rt5033-regulator.c b/drivers/regulator/rt5033-regulator.c
index 96d2c18e051a..639cbadc044a 100644
--- a/drivers/regulator/rt5033-regulator.c
+++ b/drivers/regulator/rt5033-regulator.c
@@ -16,14 +16,14 @@
16#include <linux/mfd/rt5033-private.h> 16#include <linux/mfd/rt5033-private.h>
17#include <linux/regulator/of_regulator.h> 17#include <linux/regulator/of_regulator.h>
18 18
19static struct regulator_ops rt5033_safe_ldo_ops = { 19static const struct regulator_ops rt5033_safe_ldo_ops = {
20 .is_enabled = regulator_is_enabled_regmap, 20 .is_enabled = regulator_is_enabled_regmap,
21 .enable = regulator_enable_regmap, 21 .enable = regulator_enable_regmap,
22 .disable = regulator_disable_regmap, 22 .disable = regulator_disable_regmap,
23 .list_voltage = regulator_list_voltage_linear, 23 .list_voltage = regulator_list_voltage_linear,
24}; 24};
25 25
26static struct regulator_ops rt5033_buck_ops = { 26static const struct regulator_ops rt5033_buck_ops = {
27 .is_enabled = regulator_is_enabled_regmap, 27 .is_enabled = regulator_is_enabled_regmap,
28 .enable = regulator_enable_regmap, 28 .enable = regulator_enable_regmap,
29 .disable = regulator_disable_regmap, 29 .disable = regulator_disable_regmap,
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index b581f01f3395..bb9d1a083299 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -115,7 +115,7 @@ static const struct sec_voltage_desc *reg_voltage_map[] = {
115 [S5M8767_BUCK9] = &buck_voltage_val3, 115 [S5M8767_BUCK9] = &buck_voltage_val3,
116}; 116};
117 117
118static unsigned int s5m8767_opmode_reg[][4] = { 118static const unsigned int s5m8767_opmode_reg[][4] = {
119 /* {OFF, ON, LOWPOWER, SUSPEND} */ 119 /* {OFF, ON, LOWPOWER, SUSPEND} */
120 /* LDO1 ... LDO28 */ 120 /* LDO1 ... LDO28 */
121 {0x0, 0x3, 0x2, 0x1}, /* LDO1 */ 121 {0x0, 0x3, 0x2, 0x1}, /* LDO1 */
@@ -339,13 +339,9 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev,
339 unsigned int new_sel) 339 unsigned int new_sel)
340{ 340{
341 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); 341 struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev);
342 const struct sec_voltage_desc *desc;
343 int reg_id = rdev_get_id(rdev);
344
345 desc = reg_voltage_map[reg_id];
346 342
347 if ((old_sel < new_sel) && s5m8767->ramp_delay) 343 if ((old_sel < new_sel) && s5m8767->ramp_delay)
348 return DIV_ROUND_UP(desc->step * (new_sel - old_sel), 344 return DIV_ROUND_UP(rdev->desc->uV_step * (new_sel - old_sel),
349 s5m8767->ramp_delay * 1000); 345 s5m8767->ramp_delay * 1000);
350 return 0; 346 return 0;
351} 347}
diff --git a/drivers/regulator/stm32-vrefbuf.c b/drivers/regulator/stm32-vrefbuf.c
index e0a9c445ed67..ba2f24949dc9 100644
--- a/drivers/regulator/stm32-vrefbuf.c
+++ b/drivers/regulator/stm32-vrefbuf.c
@@ -15,6 +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/of_regulator.h> 17#include <linux/regulator/of_regulator.h>
18#include <linux/pm_runtime.h>
18 19
19/* STM32 VREFBUF registers */ 20/* STM32 VREFBUF registers */
20#define STM32_VREFBUF_CSR 0x00 21#define STM32_VREFBUF_CSR 0x00
@@ -25,9 +26,12 @@
25#define STM32_HIZ BIT(1) 26#define STM32_HIZ BIT(1)
26#define STM32_ENVR BIT(0) 27#define STM32_ENVR BIT(0)
27 28
29#define STM32_VREFBUF_AUTO_SUSPEND_DELAY_MS 10
30
28struct stm32_vrefbuf { 31struct stm32_vrefbuf {
29 void __iomem *base; 32 void __iomem *base;
30 struct clk *clk; 33 struct clk *clk;
34 struct device *dev;
31}; 35};
32 36
33static const unsigned int stm32_vrefbuf_voltages[] = { 37static const unsigned int stm32_vrefbuf_voltages[] = {
@@ -38,9 +42,16 @@ static const unsigned int stm32_vrefbuf_voltages[] = {
38static int stm32_vrefbuf_enable(struct regulator_dev *rdev) 42static int stm32_vrefbuf_enable(struct regulator_dev *rdev)
39{ 43{
40 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 44 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
41 u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); 45 u32 val;
42 int ret; 46 int ret;
43 47
48 ret = pm_runtime_get_sync(priv->dev);
49 if (ret < 0) {
50 pm_runtime_put_noidle(priv->dev);
51 return ret;
52 }
53
54 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
44 val = (val & ~STM32_HIZ) | STM32_ENVR; 55 val = (val & ~STM32_HIZ) | STM32_ENVR;
45 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); 56 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
46 57
@@ -59,45 +70,95 @@ static int stm32_vrefbuf_enable(struct regulator_dev *rdev)
59 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); 70 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
60 } 71 }
61 72
73 pm_runtime_mark_last_busy(priv->dev);
74 pm_runtime_put_autosuspend(priv->dev);
75
62 return ret; 76 return ret;
63} 77}
64 78
65static int stm32_vrefbuf_disable(struct regulator_dev *rdev) 79static int stm32_vrefbuf_disable(struct regulator_dev *rdev)
66{ 80{
67 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 81 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
68 u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); 82 u32 val;
83 int ret;
69 84
85 ret = pm_runtime_get_sync(priv->dev);
86 if (ret < 0) {
87 pm_runtime_put_noidle(priv->dev);
88 return ret;
89 }
90
91 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
70 val = (val & ~STM32_ENVR) | STM32_HIZ; 92 val = (val & ~STM32_ENVR) | STM32_HIZ;
71 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); 93 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
72 94
95 pm_runtime_mark_last_busy(priv->dev);
96 pm_runtime_put_autosuspend(priv->dev);
97
73 return 0; 98 return 0;
74} 99}
75 100
76static int stm32_vrefbuf_is_enabled(struct regulator_dev *rdev) 101static int stm32_vrefbuf_is_enabled(struct regulator_dev *rdev)
77{ 102{
78 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 103 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
104 int ret;
105
106 ret = pm_runtime_get_sync(priv->dev);
107 if (ret < 0) {
108 pm_runtime_put_noidle(priv->dev);
109 return ret;
110 }
111
112 ret = readl_relaxed(priv->base + STM32_VREFBUF_CSR) & STM32_ENVR;
79 113
80 return readl_relaxed(priv->base + STM32_VREFBUF_CSR) & STM32_ENVR; 114 pm_runtime_mark_last_busy(priv->dev);
115 pm_runtime_put_autosuspend(priv->dev);
116
117 return ret;
81} 118}
82 119
83static int stm32_vrefbuf_set_voltage_sel(struct regulator_dev *rdev, 120static int stm32_vrefbuf_set_voltage_sel(struct regulator_dev *rdev,
84 unsigned sel) 121 unsigned sel)
85{ 122{
86 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 123 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
87 u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); 124 u32 val;
125 int ret;
88 126
127 ret = pm_runtime_get_sync(priv->dev);
128 if (ret < 0) {
129 pm_runtime_put_noidle(priv->dev);
130 return ret;
131 }
132
133 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
89 val = (val & ~STM32_VRS) | FIELD_PREP(STM32_VRS, sel); 134 val = (val & ~STM32_VRS) | FIELD_PREP(STM32_VRS, sel);
90 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); 135 writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
91 136
137 pm_runtime_mark_last_busy(priv->dev);
138 pm_runtime_put_autosuspend(priv->dev);
139
92 return 0; 140 return 0;
93} 141}
94 142
95static int stm32_vrefbuf_get_voltage_sel(struct regulator_dev *rdev) 143static int stm32_vrefbuf_get_voltage_sel(struct regulator_dev *rdev)
96{ 144{
97 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 145 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
98 u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); 146 u32 val;
147 int ret;
99 148
100 return FIELD_GET(STM32_VRS, val); 149 ret = pm_runtime_get_sync(priv->dev);
150 if (ret < 0) {
151 pm_runtime_put_noidle(priv->dev);
152 return ret;
153 }
154
155 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
156 ret = FIELD_GET(STM32_VRS, val);
157
158 pm_runtime_mark_last_busy(priv->dev);
159 pm_runtime_put_autosuspend(priv->dev);
160
161 return ret;
101} 162}
102 163
103static const struct regulator_ops stm32_vrefbuf_volt_ops = { 164static const struct regulator_ops stm32_vrefbuf_volt_ops = {
@@ -130,6 +191,7 @@ static int stm32_vrefbuf_probe(struct platform_device *pdev)
130 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 191 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
131 if (!priv) 192 if (!priv)
132 return -ENOMEM; 193 return -ENOMEM;
194 priv->dev = &pdev->dev;
133 195
134 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
135 priv->base = devm_ioremap_resource(&pdev->dev, res); 197 priv->base = devm_ioremap_resource(&pdev->dev, res);
@@ -140,10 +202,17 @@ static int stm32_vrefbuf_probe(struct platform_device *pdev)
140 if (IS_ERR(priv->clk)) 202 if (IS_ERR(priv->clk))
141 return PTR_ERR(priv->clk); 203 return PTR_ERR(priv->clk);
142 204
205 pm_runtime_get_noresume(&pdev->dev);
206 pm_runtime_set_active(&pdev->dev);
207 pm_runtime_set_autosuspend_delay(&pdev->dev,
208 STM32_VREFBUF_AUTO_SUSPEND_DELAY_MS);
209 pm_runtime_use_autosuspend(&pdev->dev);
210 pm_runtime_enable(&pdev->dev);
211
143 ret = clk_prepare_enable(priv->clk); 212 ret = clk_prepare_enable(priv->clk);
144 if (ret) { 213 if (ret) {
145 dev_err(&pdev->dev, "clk prepare failed with error %d\n", ret); 214 dev_err(&pdev->dev, "clk prepare failed with error %d\n", ret);
146 return ret; 215 goto err_pm_stop;
147 } 216 }
148 217
149 config.dev = &pdev->dev; 218 config.dev = &pdev->dev;
@@ -161,10 +230,17 @@ static int stm32_vrefbuf_probe(struct platform_device *pdev)
161 } 230 }
162 platform_set_drvdata(pdev, rdev); 231 platform_set_drvdata(pdev, rdev);
163 232
233 pm_runtime_mark_last_busy(&pdev->dev);
234 pm_runtime_put_autosuspend(&pdev->dev);
235
164 return 0; 236 return 0;
165 237
166err_clk_dis: 238err_clk_dis:
167 clk_disable_unprepare(priv->clk); 239 clk_disable_unprepare(priv->clk);
240err_pm_stop:
241 pm_runtime_disable(&pdev->dev);
242 pm_runtime_set_suspended(&pdev->dev);
243 pm_runtime_put_noidle(&pdev->dev);
168 244
169 return ret; 245 return ret;
170} 246}
@@ -174,12 +250,42 @@ static int stm32_vrefbuf_remove(struct platform_device *pdev)
174 struct regulator_dev *rdev = platform_get_drvdata(pdev); 250 struct regulator_dev *rdev = platform_get_drvdata(pdev);
175 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); 251 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
176 252
253 pm_runtime_get_sync(&pdev->dev);
177 regulator_unregister(rdev); 254 regulator_unregister(rdev);
178 clk_disable_unprepare(priv->clk); 255 clk_disable_unprepare(priv->clk);
256 pm_runtime_disable(&pdev->dev);
257 pm_runtime_set_suspended(&pdev->dev);
258 pm_runtime_put_noidle(&pdev->dev);
179 259
180 return 0; 260 return 0;
181}; 261};
182 262
263static int __maybe_unused stm32_vrefbuf_runtime_suspend(struct device *dev)
264{
265 struct regulator_dev *rdev = dev_get_drvdata(dev);
266 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
267
268 clk_disable_unprepare(priv->clk);
269
270 return 0;
271}
272
273static int __maybe_unused stm32_vrefbuf_runtime_resume(struct device *dev)
274{
275 struct regulator_dev *rdev = dev_get_drvdata(dev);
276 struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
277
278 return clk_prepare_enable(priv->clk);
279}
280
281static const struct dev_pm_ops stm32_vrefbuf_pm_ops = {
282 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
283 pm_runtime_force_resume)
284 SET_RUNTIME_PM_OPS(stm32_vrefbuf_runtime_suspend,
285 stm32_vrefbuf_runtime_resume,
286 NULL)
287};
288
183static const struct of_device_id stm32_vrefbuf_of_match[] = { 289static const struct of_device_id stm32_vrefbuf_of_match[] = {
184 { .compatible = "st,stm32-vrefbuf", }, 290 { .compatible = "st,stm32-vrefbuf", },
185 {}, 291 {},
@@ -192,6 +298,7 @@ static struct platform_driver stm32_vrefbuf_driver = {
192 .driver = { 298 .driver = {
193 .name = "stm32-vrefbuf", 299 .name = "stm32-vrefbuf",
194 .of_match_table = of_match_ptr(stm32_vrefbuf_of_match), 300 .of_match_table = of_match_ptr(stm32_vrefbuf_of_match),
301 .pm = &stm32_vrefbuf_pm_ops,
195 }, 302 },
196}; 303};
197module_platform_driver(stm32_vrefbuf_driver); 304module_platform_driver(stm32_vrefbuf_driver);
diff --git a/drivers/regulator/stpmic1_regulator.c b/drivers/regulator/stpmic1_regulator.c
index a1f88e996cae..f09061473613 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -12,8 +12,10 @@
12#include <linux/regulator/machine.h> 12#include <linux/regulator/machine.h>
13#include <linux/regulator/of_regulator.h> 13#include <linux/regulator/of_regulator.h>
14 14
15#include <dt-bindings/mfd/st,stpmic1.h>
16
15/** 17/**
16 * stpmic1 regulator description 18 * stpmic1 regulator description: this structure is used as driver data
17 * @desc: regulator framework description 19 * @desc: regulator framework description
18 * @mask_reset_reg: mask reset register address 20 * @mask_reset_reg: mask reset register address
19 * @mask_reset_mask: mask rank and mask reset register mask 21 * @mask_reset_mask: mask rank and mask reset register mask
@@ -28,28 +30,9 @@ struct stpmic1_regulator_cfg {
28 u8 icc_mask; 30 u8 icc_mask;
29}; 31};
30 32
31/**
32 * stpmic1 regulator data: this structure is used as driver data
33 * @regul_id: regulator id
34 * @reg_node: DT node of regulator (unused on non-DT platforms)
35 * @cfg: stpmic specific regulator description
36 * @mask_reset: mask_reset bit value
37 * @irq_curlim: current limit interrupt number
38 * @regmap: point to parent regmap structure
39 */
40struct stpmic1_regulator {
41 unsigned int regul_id;
42 struct device_node *reg_node;
43 struct stpmic1_regulator_cfg *cfg;
44 u8 mask_reset;
45 int irq_curlim;
46 struct regmap *regmap;
47};
48
49static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode); 33static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode);
50static unsigned int stpmic1_get_mode(struct regulator_dev *rdev); 34static unsigned int stpmic1_get_mode(struct regulator_dev *rdev);
51static int stpmic1_set_icc(struct regulator_dev *rdev); 35static int stpmic1_set_icc(struct regulator_dev *rdev);
52static int stpmic1_regulator_parse_dt(void *driver_data);
53static unsigned int stpmic1_map_mode(unsigned int mode); 36static unsigned int stpmic1_map_mode(unsigned int mode);
54 37
55enum { 38enum {
@@ -72,16 +55,13 @@ enum {
72/* Enable time worst case is 5000mV/(2250uV/uS) */ 55/* Enable time worst case is 5000mV/(2250uV/uS) */
73#define PMIC_ENABLE_TIME_US 2200 56#define PMIC_ENABLE_TIME_US 2200
74 57
75#define STPMIC1_BUCK_MODE_NORMAL 0
76#define STPMIC1_BUCK_MODE_LP BUCK_HPLP_ENABLE_MASK
77
78static const struct regulator_linear_range buck1_ranges[] = { 58static const struct regulator_linear_range buck1_ranges[] = {
79 REGULATOR_LINEAR_RANGE(725000, 0, 4, 0), 59 REGULATOR_LINEAR_RANGE(725000, 0, 4, 0),
80 REGULATOR_LINEAR_RANGE(725000, 5, 36, 25000), 60 REGULATOR_LINEAR_RANGE(725000, 5, 36, 25000),
81 REGULATOR_LINEAR_RANGE(1500000, 37, 63, 0), 61 REGULATOR_LINEAR_RANGE(1500000, 37, 63, 0),
82}; 62};
83 63
84struct regulator_linear_range buck2_ranges[] = { 64static const struct regulator_linear_range buck2_ranges[] = {
85 REGULATOR_LINEAR_RANGE(1000000, 0, 17, 0), 65 REGULATOR_LINEAR_RANGE(1000000, 0, 17, 0),
86 REGULATOR_LINEAR_RANGE(1050000, 18, 19, 0), 66 REGULATOR_LINEAR_RANGE(1050000, 18, 19, 0),
87 REGULATOR_LINEAR_RANGE(1100000, 20, 21, 0), 67 REGULATOR_LINEAR_RANGE(1100000, 20, 21, 0),
@@ -95,7 +75,7 @@ struct regulator_linear_range buck2_ranges[] = {
95 REGULATOR_LINEAR_RANGE(1500000, 36, 63, 0), 75 REGULATOR_LINEAR_RANGE(1500000, 36, 63, 0),
96}; 76};
97 77
98struct regulator_linear_range buck3_ranges[] = { 78static const struct regulator_linear_range buck3_ranges[] = {
99 REGULATOR_LINEAR_RANGE(1000000, 0, 19, 0), 79 REGULATOR_LINEAR_RANGE(1000000, 0, 19, 0),
100 REGULATOR_LINEAR_RANGE(1100000, 20, 23, 0), 80 REGULATOR_LINEAR_RANGE(1100000, 20, 23, 0),
101 REGULATOR_LINEAR_RANGE(1200000, 24, 27, 0), 81 REGULATOR_LINEAR_RANGE(1200000, 24, 27, 0),
@@ -103,10 +83,9 @@ struct regulator_linear_range buck3_ranges[] = {
103 REGULATOR_LINEAR_RANGE(1400000, 32, 35, 0), 83 REGULATOR_LINEAR_RANGE(1400000, 32, 35, 0),
104 REGULATOR_LINEAR_RANGE(1500000, 36, 55, 100000), 84 REGULATOR_LINEAR_RANGE(1500000, 36, 55, 100000),
105 REGULATOR_LINEAR_RANGE(3400000, 56, 63, 0), 85 REGULATOR_LINEAR_RANGE(3400000, 56, 63, 0),
106
107}; 86};
108 87
109struct regulator_linear_range buck4_ranges[] = { 88static const struct regulator_linear_range buck4_ranges[] = {
110 REGULATOR_LINEAR_RANGE(600000, 0, 27, 25000), 89 REGULATOR_LINEAR_RANGE(600000, 0, 27, 25000),
111 REGULATOR_LINEAR_RANGE(1300000, 28, 29, 0), 90 REGULATOR_LINEAR_RANGE(1300000, 28, 29, 0),
112 REGULATOR_LINEAR_RANGE(1350000, 30, 31, 0), 91 REGULATOR_LINEAR_RANGE(1350000, 30, 31, 0),
@@ -114,24 +93,21 @@ struct regulator_linear_range buck4_ranges[] = {
114 REGULATOR_LINEAR_RANGE(1450000, 34, 35, 0), 93 REGULATOR_LINEAR_RANGE(1450000, 34, 35, 0),
115 REGULATOR_LINEAR_RANGE(1500000, 36, 60, 100000), 94 REGULATOR_LINEAR_RANGE(1500000, 36, 60, 100000),
116 REGULATOR_LINEAR_RANGE(3900000, 61, 63, 0), 95 REGULATOR_LINEAR_RANGE(3900000, 61, 63, 0),
117
118}; 96};
119 97
120struct regulator_linear_range ldo1_ranges[] = { 98static const struct regulator_linear_range ldo1_ranges[] = {
121 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0), 99 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0),
122 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000), 100 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000),
123 REGULATOR_LINEAR_RANGE(3300000, 25, 31, 0), 101 REGULATOR_LINEAR_RANGE(3300000, 25, 31, 0),
124
125}; 102};
126 103
127struct regulator_linear_range ldo2_ranges[] = { 104static const struct regulator_linear_range ldo2_ranges[] = {
128 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0), 105 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0),
129 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000), 106 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000),
130 REGULATOR_LINEAR_RANGE(3300000, 25, 30, 0), 107 REGULATOR_LINEAR_RANGE(3300000, 25, 30, 0),
131
132}; 108};
133 109
134struct regulator_linear_range ldo3_ranges[] = { 110static const struct regulator_linear_range ldo3_ranges[] = {
135 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0), 111 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0),
136 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000), 112 REGULATOR_LINEAR_RANGE(1700000, 8, 24, 100000),
137 REGULATOR_LINEAR_RANGE(3300000, 25, 30, 0), 113 REGULATOR_LINEAR_RANGE(3300000, 25, 30, 0),
@@ -139,18 +115,18 @@ struct regulator_linear_range ldo3_ranges[] = {
139 REGULATOR_LINEAR_RANGE(500000, 31, 31, 0), 115 REGULATOR_LINEAR_RANGE(500000, 31, 31, 0),
140}; 116};
141 117
142struct regulator_linear_range ldo5_ranges[] = { 118static const struct regulator_linear_range ldo5_ranges[] = {
143 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0), 119 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 0),
144 REGULATOR_LINEAR_RANGE(1700000, 8, 30, 100000), 120 REGULATOR_LINEAR_RANGE(1700000, 8, 30, 100000),
145 REGULATOR_LINEAR_RANGE(3900000, 31, 31, 0), 121 REGULATOR_LINEAR_RANGE(3900000, 31, 31, 0),
146}; 122};
147 123
148struct regulator_linear_range ldo6_ranges[] = { 124static const struct regulator_linear_range ldo6_ranges[] = {
149 REGULATOR_LINEAR_RANGE(900000, 0, 24, 100000), 125 REGULATOR_LINEAR_RANGE(900000, 0, 24, 100000),
150 REGULATOR_LINEAR_RANGE(3300000, 25, 31, 0), 126 REGULATOR_LINEAR_RANGE(3300000, 25, 31, 0),
151}; 127};
152 128
153static struct regulator_ops stpmic1_ldo_ops = { 129static const struct regulator_ops stpmic1_ldo_ops = {
154 .list_voltage = regulator_list_voltage_linear_range, 130 .list_voltage = regulator_list_voltage_linear_range,
155 .map_voltage = regulator_map_voltage_linear_range, 131 .map_voltage = regulator_map_voltage_linear_range,
156 .is_enabled = regulator_is_enabled_regmap, 132 .is_enabled = regulator_is_enabled_regmap,
@@ -158,11 +134,10 @@ static struct regulator_ops stpmic1_ldo_ops = {
158 .disable = regulator_disable_regmap, 134 .disable = regulator_disable_regmap,
159 .get_voltage_sel = regulator_get_voltage_sel_regmap, 135 .get_voltage_sel = regulator_get_voltage_sel_regmap,
160 .set_voltage_sel = regulator_set_voltage_sel_regmap, 136 .set_voltage_sel = regulator_set_voltage_sel_regmap,
161 .set_pull_down = regulator_set_pull_down_regmap,
162 .set_over_current_protection = stpmic1_set_icc, 137 .set_over_current_protection = stpmic1_set_icc,
163}; 138};
164 139
165static struct regulator_ops stpmic1_ldo3_ops = { 140static const struct regulator_ops stpmic1_ldo3_ops = {
166 .list_voltage = regulator_list_voltage_linear_range, 141 .list_voltage = regulator_list_voltage_linear_range,
167 .map_voltage = regulator_map_voltage_iterate, 142 .map_voltage = regulator_map_voltage_iterate,
168 .is_enabled = regulator_is_enabled_regmap, 143 .is_enabled = regulator_is_enabled_regmap,
@@ -170,21 +145,19 @@ static struct regulator_ops stpmic1_ldo3_ops = {
170 .disable = regulator_disable_regmap, 145 .disable = regulator_disable_regmap,
171 .get_voltage_sel = regulator_get_voltage_sel_regmap, 146 .get_voltage_sel = regulator_get_voltage_sel_regmap,
172 .set_voltage_sel = regulator_set_voltage_sel_regmap, 147 .set_voltage_sel = regulator_set_voltage_sel_regmap,
173 .set_pull_down = regulator_set_pull_down_regmap,
174 .get_bypass = regulator_get_bypass_regmap, 148 .get_bypass = regulator_get_bypass_regmap,
175 .set_bypass = regulator_set_bypass_regmap, 149 .set_bypass = regulator_set_bypass_regmap,
176 .set_over_current_protection = stpmic1_set_icc, 150 .set_over_current_protection = stpmic1_set_icc,
177}; 151};
178 152
179static struct regulator_ops stpmic1_ldo4_fixed_regul_ops = { 153static const struct regulator_ops stpmic1_ldo4_fixed_regul_ops = {
180 .is_enabled = regulator_is_enabled_regmap, 154 .is_enabled = regulator_is_enabled_regmap,
181 .enable = regulator_enable_regmap, 155 .enable = regulator_enable_regmap,
182 .disable = regulator_disable_regmap, 156 .disable = regulator_disable_regmap,
183 .set_pull_down = regulator_set_pull_down_regmap,
184 .set_over_current_protection = stpmic1_set_icc, 157 .set_over_current_protection = stpmic1_set_icc,
185}; 158};
186 159
187static struct regulator_ops stpmic1_buck_ops = { 160static const struct regulator_ops stpmic1_buck_ops = {
188 .list_voltage = regulator_list_voltage_linear_range, 161 .list_voltage = regulator_list_voltage_linear_range,
189 .map_voltage = regulator_map_voltage_linear_range, 162 .map_voltage = regulator_map_voltage_linear_range,
190 .is_enabled = regulator_is_enabled_regmap, 163 .is_enabled = regulator_is_enabled_regmap,
@@ -198,20 +171,27 @@ static struct regulator_ops stpmic1_buck_ops = {
198 .set_over_current_protection = stpmic1_set_icc, 171 .set_over_current_protection = stpmic1_set_icc,
199}; 172};
200 173
201static struct regulator_ops stpmic1_vref_ddr_ops = { 174static const struct regulator_ops stpmic1_vref_ddr_ops = {
202 .is_enabled = regulator_is_enabled_regmap, 175 .is_enabled = regulator_is_enabled_regmap,
203 .enable = regulator_enable_regmap, 176 .enable = regulator_enable_regmap,
204 .disable = regulator_disable_regmap, 177 .disable = regulator_disable_regmap,
205 .set_pull_down = regulator_set_pull_down_regmap,
206}; 178};
207 179
208static struct regulator_ops stpmic1_switch_regul_ops = { 180static const struct regulator_ops stpmic1_boost_regul_ops = {
209 .is_enabled = regulator_is_enabled_regmap, 181 .is_enabled = regulator_is_enabled_regmap,
210 .enable = regulator_enable_regmap, 182 .enable = regulator_enable_regmap,
211 .disable = regulator_disable_regmap, 183 .disable = regulator_disable_regmap,
212 .set_over_current_protection = stpmic1_set_icc, 184 .set_over_current_protection = stpmic1_set_icc,
213}; 185};
214 186
187static const struct regulator_ops stpmic1_switch_regul_ops = {
188 .is_enabled = regulator_is_enabled_regmap,
189 .enable = regulator_enable_regmap,
190 .disable = regulator_disable_regmap,
191 .set_over_current_protection = stpmic1_set_icc,
192 .set_active_discharge = regulator_set_active_discharge_regmap,
193};
194
215#define REG_LDO(ids, base) { \ 195#define REG_LDO(ids, base) { \
216 .name = #ids, \ 196 .name = #ids, \
217 .id = STPMIC1_##ids, \ 197 .id = STPMIC1_##ids, \
@@ -228,8 +208,6 @@ static struct regulator_ops stpmic1_switch_regul_ops = {
228 .enable_val = 1, \ 208 .enable_val = 1, \
229 .disable_val = 0, \ 209 .disable_val = 0, \
230 .enable_time = PMIC_ENABLE_TIME_US, \ 210 .enable_time = PMIC_ENABLE_TIME_US, \
231 .pull_down_reg = ids##_PULL_DOWN_REG, \
232 .pull_down_mask = ids##_PULL_DOWN_MASK, \
233 .supply_name = #base, \ 211 .supply_name = #base, \
234} 212}
235 213
@@ -253,8 +231,6 @@ static struct regulator_ops stpmic1_switch_regul_ops = {
253 .bypass_mask = LDO_BYPASS_MASK, \ 231 .bypass_mask = LDO_BYPASS_MASK, \
254 .bypass_val_on = LDO_BYPASS_MASK, \ 232 .bypass_val_on = LDO_BYPASS_MASK, \
255 .bypass_val_off = 0, \ 233 .bypass_val_off = 0, \
256 .pull_down_reg = ids##_PULL_DOWN_REG, \
257 .pull_down_mask = ids##_PULL_DOWN_MASK, \
258 .supply_name = #base, \ 234 .supply_name = #base, \
259} 235}
260 236
@@ -272,8 +248,6 @@ static struct regulator_ops stpmic1_switch_regul_ops = {
272 .enable_val = 1, \ 248 .enable_val = 1, \
273 .disable_val = 0, \ 249 .disable_val = 0, \
274 .enable_time = PMIC_ENABLE_TIME_US, \ 250 .enable_time = PMIC_ENABLE_TIME_US, \
275 .pull_down_reg = ids##_PULL_DOWN_REG, \
276 .pull_down_mask = ids##_PULL_DOWN_MASK, \
277 .supply_name = #base, \ 251 .supply_name = #base, \
278} 252}
279 253
@@ -313,12 +287,47 @@ static struct regulator_ops stpmic1_switch_regul_ops = {
313 .enable_val = 1, \ 287 .enable_val = 1, \
314 .disable_val = 0, \ 288 .disable_val = 0, \
315 .enable_time = PMIC_ENABLE_TIME_US, \ 289 .enable_time = PMIC_ENABLE_TIME_US, \
316 .pull_down_reg = ids##_PULL_DOWN_REG, \
317 .pull_down_mask = ids##_PULL_DOWN_MASK, \
318 .supply_name = #base, \ 290 .supply_name = #base, \
319} 291}
320 292
321#define REG_SWITCH(ids, base, reg, mask, val) { \ 293#define REG_BOOST(ids, base) { \
294 .name = #ids, \
295 .id = STPMIC1_##ids, \
296 .n_voltages = 1, \
297 .ops = &stpmic1_boost_regul_ops, \
298 .type = REGULATOR_VOLTAGE, \
299 .owner = THIS_MODULE, \
300 .min_uV = 0, \
301 .fixed_uV = 5000000, \
302 .enable_reg = BST_SW_CR, \
303 .enable_mask = BOOST_ENABLED, \
304 .enable_val = BOOST_ENABLED, \
305 .disable_val = 0, \
306 .enable_time = PMIC_ENABLE_TIME_US, \
307 .supply_name = #base, \
308}
309
310#define REG_VBUS_OTG(ids, base) { \
311 .name = #ids, \
312 .id = STPMIC1_##ids, \
313 .n_voltages = 1, \
314 .ops = &stpmic1_switch_regul_ops, \
315 .type = REGULATOR_VOLTAGE, \
316 .owner = THIS_MODULE, \
317 .min_uV = 0, \
318 .fixed_uV = 5000000, \
319 .enable_reg = BST_SW_CR, \
320 .enable_mask = USBSW_OTG_SWITCH_ENABLED, \
321 .enable_val = USBSW_OTG_SWITCH_ENABLED, \
322 .disable_val = 0, \
323 .enable_time = PMIC_ENABLE_TIME_US, \
324 .supply_name = #base, \
325 .active_discharge_reg = BST_SW_CR, \
326 .active_discharge_mask = VBUS_OTG_DISCHARGE, \
327 .active_discharge_on = VBUS_OTG_DISCHARGE, \
328}
329
330#define REG_SW_OUT(ids, base) { \
322 .name = #ids, \ 331 .name = #ids, \
323 .id = STPMIC1_##ids, \ 332 .id = STPMIC1_##ids, \
324 .n_voltages = 1, \ 333 .n_voltages = 1, \
@@ -327,15 +336,18 @@ static struct regulator_ops stpmic1_switch_regul_ops = {
327 .owner = THIS_MODULE, \ 336 .owner = THIS_MODULE, \
328 .min_uV = 0, \ 337 .min_uV = 0, \
329 .fixed_uV = 5000000, \ 338 .fixed_uV = 5000000, \
330 .enable_reg = (reg), \ 339 .enable_reg = BST_SW_CR, \
331 .enable_mask = (mask), \ 340 .enable_mask = SWIN_SWOUT_ENABLED, \
332 .enable_val = (val), \ 341 .enable_val = SWIN_SWOUT_ENABLED, \
333 .disable_val = 0, \ 342 .disable_val = 0, \
334 .enable_time = PMIC_ENABLE_TIME_US, \ 343 .enable_time = PMIC_ENABLE_TIME_US, \
335 .supply_name = #base, \ 344 .supply_name = #base, \
345 .active_discharge_reg = BST_SW_CR, \
346 .active_discharge_mask = SW_OUT_DISCHARGE, \
347 .active_discharge_on = SW_OUT_DISCHARGE, \
336} 348}
337 349
338struct stpmic1_regulator_cfg stpmic1_regulator_cfgs[] = { 350static const struct stpmic1_regulator_cfg stpmic1_regulator_cfgs[] = {
339 [STPMIC1_BUCK1] = { 351 [STPMIC1_BUCK1] = {
340 .desc = REG_BUCK(BUCK1, buck1), 352 .desc = REG_BUCK(BUCK1, buck1),
341 .icc_reg = BUCKS_ICCTO_CR, 353 .icc_reg = BUCKS_ICCTO_CR,
@@ -412,23 +424,17 @@ struct stpmic1_regulator_cfg stpmic1_regulator_cfgs[] = {
412 .mask_reset_mask = BIT(6), 424 .mask_reset_mask = BIT(6),
413 }, 425 },
414 [STPMIC1_BOOST] = { 426 [STPMIC1_BOOST] = {
415 .desc = REG_SWITCH(BOOST, boost, BST_SW_CR, 427 .desc = REG_BOOST(BOOST, boost),
416 BOOST_ENABLED,
417 BOOST_ENABLED),
418 .icc_reg = BUCKS_ICCTO_CR, 428 .icc_reg = BUCKS_ICCTO_CR,
419 .icc_mask = BIT(6), 429 .icc_mask = BIT(6),
420 }, 430 },
421 [STPMIC1_VBUS_OTG] = { 431 [STPMIC1_VBUS_OTG] = {
422 .desc = REG_SWITCH(VBUS_OTG, pwr_sw1, BST_SW_CR, 432 .desc = REG_VBUS_OTG(VBUS_OTG, pwr_sw1),
423 USBSW_OTG_SWITCH_ENABLED,
424 USBSW_OTG_SWITCH_ENABLED),
425 .icc_reg = BUCKS_ICCTO_CR, 433 .icc_reg = BUCKS_ICCTO_CR,
426 .icc_mask = BIT(4), 434 .icc_mask = BIT(4),
427 }, 435 },
428 [STPMIC1_SW_OUT] = { 436 [STPMIC1_SW_OUT] = {
429 .desc = REG_SWITCH(SW_OUT, pwr_sw2, BST_SW_CR, 437 .desc = REG_SW_OUT(SW_OUT, pwr_sw2),
430 SWIN_SWOUT_ENABLED,
431 SWIN_SWOUT_ENABLED),
432 .icc_reg = BUCKS_ICCTO_CR, 438 .icc_reg = BUCKS_ICCTO_CR,
433 .icc_mask = BIT(5), 439 .icc_mask = BIT(5),
434 }, 440 },
@@ -449,8 +455,9 @@ static unsigned int stpmic1_map_mode(unsigned int mode)
449static unsigned int stpmic1_get_mode(struct regulator_dev *rdev) 455static unsigned int stpmic1_get_mode(struct regulator_dev *rdev)
450{ 456{
451 int value; 457 int value;
458 struct regmap *regmap = rdev_get_regmap(rdev);
452 459
453 regmap_read(rdev->regmap, rdev->desc->enable_reg, &value); 460 regmap_read(regmap, rdev->desc->enable_reg, &value);
454 461
455 if (value & STPMIC1_BUCK_MODE_LP) 462 if (value & STPMIC1_BUCK_MODE_LP)
456 return REGULATOR_MODE_STANDBY; 463 return REGULATOR_MODE_STANDBY;
@@ -461,6 +468,7 @@ static unsigned int stpmic1_get_mode(struct regulator_dev *rdev)
461static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode) 468static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode)
462{ 469{
463 int value; 470 int value;
471 struct regmap *regmap = rdev_get_regmap(rdev);
464 472
465 switch (mode) { 473 switch (mode) {
466 case REGULATOR_MODE_NORMAL: 474 case REGULATOR_MODE_NORMAL:
@@ -473,17 +481,18 @@ static int stpmic1_set_mode(struct regulator_dev *rdev, unsigned int mode)
473 return -EINVAL; 481 return -EINVAL;
474 } 482 }
475 483
476 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 484 return regmap_update_bits(regmap, rdev->desc->enable_reg,
477 STPMIC1_BUCK_MODE_LP, value); 485 STPMIC1_BUCK_MODE_LP, value);
478} 486}
479 487
480static int stpmic1_set_icc(struct regulator_dev *rdev) 488static int stpmic1_set_icc(struct regulator_dev *rdev)
481{ 489{
482 struct stpmic1_regulator *regul = rdev_get_drvdata(rdev); 490 struct stpmic1_regulator_cfg *cfg = rdev_get_drvdata(rdev);
491 struct regmap *regmap = rdev_get_regmap(rdev);
483 492
484 /* enable switch off in case of over current */ 493 /* enable switch off in case of over current */
485 return regmap_update_bits(regul->regmap, regul->cfg->icc_reg, 494 return regmap_update_bits(regmap, cfg->icc_reg, cfg->icc_mask,
486 regul->cfg->icc_mask, regul->cfg->icc_mask); 495 cfg->icc_mask);
487} 496}
488 497
489static irqreturn_t stpmic1_curlim_irq_handler(int irq, void *data) 498static irqreturn_t stpmic1_curlim_irq_handler(int irq, void *data)
@@ -502,46 +511,13 @@ static irqreturn_t stpmic1_curlim_irq_handler(int irq, void *data)
502 return IRQ_HANDLED; 511 return IRQ_HANDLED;
503} 512}
504 513
505static int stpmic1_regulator_init(struct platform_device *pdev,
506 struct regulator_dev *rdev)
507{
508 struct stpmic1_regulator *regul = rdev_get_drvdata(rdev);
509 int ret = 0;
510
511 /* set mask reset */
512 if (regul->mask_reset && regul->cfg->mask_reset_reg != 0) {
513 ret = regmap_update_bits(regul->regmap,
514 regul->cfg->mask_reset_reg,
515 regul->cfg->mask_reset_mask,
516 regul->cfg->mask_reset_mask);
517 if (ret) {
518 dev_err(&pdev->dev, "set mask reset failed\n");
519 return ret;
520 }
521 }
522
523 /* setup an irq handler for over-current detection */
524 if (regul->irq_curlim > 0) {
525 ret = devm_request_threaded_irq(&pdev->dev,
526 regul->irq_curlim, NULL,
527 stpmic1_curlim_irq_handler,
528 IRQF_ONESHOT | IRQF_SHARED,
529 pdev->name, rdev);
530 if (ret) {
531 dev_err(&pdev->dev, "Request IRQ failed\n");
532 return ret;
533 }
534 }
535 return 0;
536}
537
538#define MATCH(_name, _id) \ 514#define MATCH(_name, _id) \
539 [STPMIC1_##_id] = { \ 515 [STPMIC1_##_id] = { \
540 .name = #_name, \ 516 .name = #_name, \
541 .desc = &stpmic1_regulator_cfgs[STPMIC1_##_id].desc, \ 517 .desc = &stpmic1_regulator_cfgs[STPMIC1_##_id].desc, \
542 } 518 }
543 519
544static struct of_regulator_match stpmic1_regulators_matches[] = { 520static struct of_regulator_match stpmic1_matches[] = {
545 MATCH(buck1, BUCK1), 521 MATCH(buck1, BUCK1),
546 MATCH(buck2, BUCK2), 522 MATCH(buck2, BUCK2),
547 MATCH(buck3, BUCK3), 523 MATCH(buck3, BUCK3),
@@ -558,94 +534,75 @@ static struct of_regulator_match stpmic1_regulators_matches[] = {
558 MATCH(pwr_sw2, SW_OUT), 534 MATCH(pwr_sw2, SW_OUT),
559}; 535};
560 536
561static int stpmic1_regulator_parse_dt(void *driver_data) 537static int stpmic1_regulator_register(struct platform_device *pdev, int id,
562{ 538 struct of_regulator_match *match,
563 struct stpmic1_regulator *regul = 539 const struct stpmic1_regulator_cfg *cfg)
564 (struct stpmic1_regulator *)driver_data;
565
566 if (!regul)
567 return -EINVAL;
568
569 if (of_get_property(regul->reg_node, "st,mask-reset", NULL))
570 regul->mask_reset = 1;
571
572 regul->irq_curlim = of_irq_get(regul->reg_node, 0);
573
574 return 0;
575}
576
577static struct
578regulator_dev *stpmic1_regulator_register(struct platform_device *pdev, int id,
579 struct regulator_init_data *init_data,
580 struct stpmic1_regulator *regul)
581{ 540{
582 struct stpmic1 *pmic_dev = dev_get_drvdata(pdev->dev.parent); 541 struct stpmic1 *pmic_dev = dev_get_drvdata(pdev->dev.parent);
583 struct regulator_dev *rdev; 542 struct regulator_dev *rdev;
584 struct regulator_config config = {}; 543 struct regulator_config config = {};
544 int ret = 0;
545 int irq;
585 546
586 config.dev = &pdev->dev; 547 config.dev = &pdev->dev;
587 config.init_data = init_data; 548 config.init_data = match->init_data;
588 config.of_node = stpmic1_regulators_matches[id].of_node; 549 config.of_node = match->of_node;
589 config.regmap = pmic_dev->regmap; 550 config.regmap = pmic_dev->regmap;
590 config.driver_data = regul; 551 config.driver_data = (void *)cfg;
591
592 regul->regul_id = id;
593 regul->reg_node = config.of_node;
594 regul->cfg = &stpmic1_regulator_cfgs[id];
595 regul->regmap = pmic_dev->regmap;
596 552
597 rdev = devm_regulator_register(&pdev->dev, &regul->cfg->desc, &config); 553 rdev = devm_regulator_register(&pdev->dev, &cfg->desc, &config);
598 if (IS_ERR(rdev)) { 554 if (IS_ERR(rdev)) {
599 dev_err(&pdev->dev, "failed to register %s regulator\n", 555 dev_err(&pdev->dev, "failed to register %s regulator\n",
600 regul->cfg->desc.name); 556 cfg->desc.name);
557 return PTR_ERR(rdev);
558 }
559
560 /* set mask reset */
561 if (of_get_property(config.of_node, "st,mask-reset", NULL) &&
562 cfg->mask_reset_reg != 0) {
563 ret = regmap_update_bits(pmic_dev->regmap,
564 cfg->mask_reset_reg,
565 cfg->mask_reset_mask,
566 cfg->mask_reset_mask);
567 if (ret) {
568 dev_err(&pdev->dev, "set mask reset failed\n");
569 return ret;
570 }
601 } 571 }
602 572
603 return rdev; 573 /* setup an irq handler for over-current detection */
574 irq = of_irq_get(config.of_node, 0);
575 if (irq > 0) {
576 ret = devm_request_threaded_irq(&pdev->dev,
577 irq, NULL,
578 stpmic1_curlim_irq_handler,
579 IRQF_ONESHOT | IRQF_SHARED,
580 pdev->name, rdev);
581 if (ret) {
582 dev_err(&pdev->dev, "Request IRQ failed\n");
583 return ret;
584 }
585 }
586 return 0;
604} 587}
605 588
606static int stpmic1_regulator_probe(struct platform_device *pdev) 589static int stpmic1_regulator_probe(struct platform_device *pdev)
607{ 590{
608 struct regulator_dev *rdev;
609 struct stpmic1_regulator *regul;
610 struct regulator_init_data *init_data;
611 struct device_node *np;
612 int i, ret; 591 int i, ret;
613 592
614 np = pdev->dev.of_node; 593 ret = of_regulator_match(&pdev->dev, pdev->dev.of_node, stpmic1_matches,
615 594 ARRAY_SIZE(stpmic1_matches));
616 ret = of_regulator_match(&pdev->dev, np,
617 stpmic1_regulators_matches,
618 ARRAY_SIZE(stpmic1_regulators_matches));
619 if (ret < 0) { 595 if (ret < 0) {
620 dev_err(&pdev->dev, 596 dev_err(&pdev->dev,
621 "Error in PMIC regulator device tree node"); 597 "Error in PMIC regulator device tree node");
622 return ret; 598 return ret;
623 } 599 }
624 600
625 regul = devm_kzalloc(&pdev->dev, ARRAY_SIZE(stpmic1_regulator_cfgs) *
626 sizeof(struct stpmic1_regulator),
627 GFP_KERNEL);
628 if (!regul)
629 return -ENOMEM;
630
631 for (i = 0; i < ARRAY_SIZE(stpmic1_regulator_cfgs); i++) { 601 for (i = 0; i < ARRAY_SIZE(stpmic1_regulator_cfgs); i++) {
632 /* Parse DT & find regulators to register */ 602 ret = stpmic1_regulator_register(pdev, i, &stpmic1_matches[i],
633 init_data = stpmic1_regulators_matches[i].init_data; 603 &stpmic1_regulator_cfgs[i]);
634 if (init_data) 604 if (ret < 0)
635 init_data->regulator_init = &stpmic1_regulator_parse_dt;
636
637 rdev = stpmic1_regulator_register(pdev, i, init_data, regul);
638 if (IS_ERR(rdev))
639 return PTR_ERR(rdev);
640
641 ret = stpmic1_regulator_init(pdev, rdev);
642 if (ret) {
643 dev_err(&pdev->dev,
644 "failed to initialize regulator %d\n", ret);
645 return ret; 605 return ret;
646 }
647
648 regul++;
649 } 606 }
650 607
651 dev_dbg(&pdev->dev, "stpmic1_regulator driver probed\n"); 608 dev_dbg(&pdev->dev, "stpmic1_regulator driver probed\n");
diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index 5dd559eabc81..95708d34876b 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -205,7 +205,8 @@ static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
205 return -EINVAL; 205 return -EINVAL;
206 206
207 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, 207 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
208 index << 2, TPS65218_PROTECT_L1); 208 index << __builtin_ctz(dev->desc->csel_mask),
209 TPS65218_PROTECT_L1);
209} 210}
210 211
211static int tps65218_pmic_set_current_limit(struct regulator_dev *dev, 212static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
@@ -224,7 +225,8 @@ static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
224 return -EINVAL; 225 return -EINVAL;
225 226
226 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, 227 return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
227 index << 2, TPS65218_PROTECT_L1); 228 index << __builtin_ctz(dev->desc->csel_mask),
229 TPS65218_PROTECT_L1);
228} 230}
229 231
230static int tps65218_pmic_get_current_limit(struct regulator_dev *dev) 232static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
@@ -237,12 +239,13 @@ static int tps65218_pmic_get_current_limit(struct regulator_dev *dev)
237 if (retval < 0) 239 if (retval < 0)
238 return retval; 240 return retval;
239 241
240 index = (index & dev->desc->csel_mask) >> 2; 242 index = (index & dev->desc->csel_mask) >>
243 __builtin_ctz(dev->desc->csel_mask);
241 244
242 return ls3_currents[index]; 245 return ls3_currents[index];
243} 246}
244 247
245static struct regulator_ops tps65218_ls3_ops = { 248static struct regulator_ops tps65218_ls23_ops = {
246 .is_enabled = regulator_is_enabled_regmap, 249 .is_enabled = regulator_is_enabled_regmap,
247 .enable = tps65218_pmic_enable, 250 .enable = tps65218_pmic_enable,
248 .disable = tps65218_pmic_disable, 251 .disable = tps65218_pmic_disable,
@@ -304,8 +307,13 @@ static const struct regulator_desc regulators[] = {
304 TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges, 307 TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
305 2, 0, 0, TPS65218_REG_SEQ6, 308 2, 0, 0, TPS65218_REG_SEQ6,
306 TPS65218_SEQ6_LDO1_SEQ_MASK), 309 TPS65218_SEQ6_LDO1_SEQ_MASK),
310 TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
311 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
312 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
313 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
314 NULL, 0, 0, 0, 0, 0),
307 TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3, 315 TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
308 REGULATOR_CURRENT, tps65218_ls3_ops, 0, 0, 0, 316 REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
309 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN, 317 TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
310 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK, 318 TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
311 NULL, 0, 0, 0, 0, 0), 319 NULL, 0, 0, 0, 0, 0),
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 884c7505ed91..402ea43c77d1 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -576,14 +576,9 @@ static int twlreg_probe(struct platform_device *pdev)
576 struct regulator_init_data *initdata; 576 struct regulator_init_data *initdata;
577 struct regulation_constraints *c; 577 struct regulation_constraints *c;
578 struct regulator_dev *rdev; 578 struct regulator_dev *rdev;
579 const struct of_device_id *match;
580 struct regulator_config config = { }; 579 struct regulator_config config = { };
581 580
582 match = of_match_device(twl_of_match, &pdev->dev); 581 template = of_device_get_match_data(&pdev->dev);
583 if (!match)
584 return -ENODEV;
585
586 template = match->data;
587 if (!template) 582 if (!template)
588 return -ENODEV; 583 return -ENODEV;
589 584
diff --git a/drivers/regulator/twl6030-regulator.c b/drivers/regulator/twl6030-regulator.c
index 219cbd910dbf..15f19df6bc5d 100644
--- a/drivers/regulator/twl6030-regulator.c
+++ b/drivers/regulator/twl6030-regulator.c
@@ -31,9 +31,6 @@ struct twlreg_info {
31 /* twl resource ID, for resource control state machine */ 31 /* twl resource ID, for resource control state machine */
32 u8 id; 32 u8 id;
33 33
34 /* chip constraints on regulator behavior */
35 u16 min_mV;
36
37 u8 flags; 34 u8 flags;
38 35
39 /* used by regulator core */ 36 /* used by regulator core */
@@ -247,32 +244,11 @@ static int twl6030coresmps_get_voltage(struct regulator_dev *rdev)
247 return -ENODEV; 244 return -ENODEV;
248} 245}
249 246
250static struct regulator_ops twl6030coresmps_ops = { 247static const struct regulator_ops twl6030coresmps_ops = {
251 .set_voltage = twl6030coresmps_set_voltage, 248 .set_voltage = twl6030coresmps_set_voltage,
252 .get_voltage = twl6030coresmps_get_voltage, 249 .get_voltage = twl6030coresmps_get_voltage,
253}; 250};
254 251
255static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel)
256{
257 struct twlreg_info *info = rdev_get_drvdata(rdev);
258
259 switch (sel) {
260 case 0:
261 return 0;
262 case 1 ... 24:
263 /* Linear mapping from 00000001 to 00011000:
264 * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001)
265 */
266 return (info->min_mV + 100 * (sel - 1)) * 1000;
267 case 25 ... 30:
268 return -EINVAL;
269 case 31:
270 return 2750000;
271 default:
272 return -EINVAL;
273 }
274}
275
276static int 252static int
277twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 253twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
278{ 254{
@@ -290,8 +266,8 @@ static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev)
290 return vsel; 266 return vsel;
291} 267}
292 268
293static struct regulator_ops twl6030ldo_ops = { 269static const struct regulator_ops twl6030ldo_ops = {
294 .list_voltage = twl6030ldo_list_voltage, 270 .list_voltage = regulator_list_voltage_linear_range,
295 271
296 .set_voltage_sel = twl6030ldo_set_voltage_sel, 272 .set_voltage_sel = twl6030ldo_set_voltage_sel,
297 .get_voltage_sel = twl6030ldo_get_voltage_sel, 273 .get_voltage_sel = twl6030ldo_get_voltage_sel,
@@ -305,7 +281,7 @@ static struct regulator_ops twl6030ldo_ops = {
305 .get_status = twl6030reg_get_status, 281 .get_status = twl6030reg_get_status,
306}; 282};
307 283
308static struct regulator_ops twl6030fixed_ops = { 284static const struct regulator_ops twl6030fixed_ops = {
309 .list_voltage = regulator_list_voltage_linear, 285 .list_voltage = regulator_list_voltage_linear,
310 286
311 .enable = twl6030reg_enable, 287 .enable = twl6030reg_enable,
@@ -496,7 +472,7 @@ static int twl6030smps_get_voltage_sel(struct regulator_dev *rdev)
496 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS); 472 return twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS);
497} 473}
498 474
499static struct regulator_ops twlsmps_ops = { 475static const struct regulator_ops twlsmps_ops = {
500 .list_voltage = twl6030smps_list_voltage, 476 .list_voltage = twl6030smps_list_voltage,
501 .map_voltage = twl6030smps_map_voltage, 477 .map_voltage = twl6030smps_map_voltage,
502 478
@@ -513,6 +489,11 @@ static struct regulator_ops twlsmps_ops = {
513}; 489};
514 490
515/*----------------------------------------------------------------------*/ 491/*----------------------------------------------------------------------*/
492static const struct regulator_linear_range twl6030ldo_linear_range[] = {
493 REGULATOR_LINEAR_RANGE(0, 0, 0, 0),
494 REGULATOR_LINEAR_RANGE(1000000, 1, 24, 100000),
495 REGULATOR_LINEAR_RANGE(2750000, 31, 31, 0),
496};
516 497
517#define TWL6030_ADJUSTABLE_SMPS(label) \ 498#define TWL6030_ADJUSTABLE_SMPS(label) \
518static const struct twlreg_info TWL6030_INFO_##label = { \ 499static const struct twlreg_info TWL6030_INFO_##label = { \
@@ -525,28 +506,30 @@ static const struct twlreg_info TWL6030_INFO_##label = { \
525 }, \ 506 }, \
526 } 507 }
527 508
528#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts) \ 509#define TWL6030_ADJUSTABLE_LDO(label, offset) \
529static const struct twlreg_info TWL6030_INFO_##label = { \ 510static const struct twlreg_info TWL6030_INFO_##label = { \
530 .base = offset, \ 511 .base = offset, \
531 .min_mV = min_mVolts, \
532 .desc = { \ 512 .desc = { \
533 .name = #label, \ 513 .name = #label, \
534 .id = TWL6030_REG_##label, \ 514 .id = TWL6030_REG_##label, \
535 .n_voltages = 32, \ 515 .n_voltages = 32, \
516 .linear_ranges = twl6030ldo_linear_range, \
517 .n_linear_ranges = ARRAY_SIZE(twl6030ldo_linear_range), \
536 .ops = &twl6030ldo_ops, \ 518 .ops = &twl6030ldo_ops, \
537 .type = REGULATOR_VOLTAGE, \ 519 .type = REGULATOR_VOLTAGE, \
538 .owner = THIS_MODULE, \ 520 .owner = THIS_MODULE, \
539 }, \ 521 }, \
540 } 522 }
541 523
542#define TWL6032_ADJUSTABLE_LDO(label, offset, min_mVolts) \ 524#define TWL6032_ADJUSTABLE_LDO(label, offset) \
543static const struct twlreg_info TWL6032_INFO_##label = { \ 525static const struct twlreg_info TWL6032_INFO_##label = { \
544 .base = offset, \ 526 .base = offset, \
545 .min_mV = min_mVolts, \
546 .desc = { \ 527 .desc = { \
547 .name = #label, \ 528 .name = #label, \
548 .id = TWL6032_REG_##label, \ 529 .id = TWL6032_REG_##label, \
549 .n_voltages = 32, \ 530 .n_voltages = 32, \
531 .linear_ranges = twl6030ldo_linear_range, \
532 .n_linear_ranges = ARRAY_SIZE(twl6030ldo_linear_range), \
550 .ops = &twl6030ldo_ops, \ 533 .ops = &twl6030ldo_ops, \
551 .type = REGULATOR_VOLTAGE, \ 534 .type = REGULATOR_VOLTAGE, \
552 .owner = THIS_MODULE, \ 535 .owner = THIS_MODULE, \
@@ -557,7 +540,6 @@ static const struct twlreg_info TWL6032_INFO_##label = { \
557static const struct twlreg_info TWLFIXED_INFO_##label = { \ 540static const struct twlreg_info TWLFIXED_INFO_##label = { \
558 .base = offset, \ 541 .base = offset, \
559 .id = 0, \ 542 .id = 0, \
560 .min_mV = mVolts, \
561 .desc = { \ 543 .desc = { \
562 .name = #label, \ 544 .name = #label, \
563 .id = TWL6030##_REG_##label, \ 545 .id = TWL6030##_REG_##label, \
@@ -574,7 +556,6 @@ static const struct twlreg_info TWLFIXED_INFO_##label = { \
574#define TWL6032_ADJUSTABLE_SMPS(label, offset) \ 556#define TWL6032_ADJUSTABLE_SMPS(label, offset) \
575static const struct twlreg_info TWLSMPS_INFO_##label = { \ 557static const struct twlreg_info TWLSMPS_INFO_##label = { \
576 .base = offset, \ 558 .base = offset, \
577 .min_mV = 600, \
578 .desc = { \ 559 .desc = { \
579 .name = #label, \ 560 .name = #label, \
580 .id = TWL6032_REG_##label, \ 561 .id = TWL6032_REG_##label, \
@@ -592,22 +573,22 @@ static const struct twlreg_info TWLSMPS_INFO_##label = { \
592TWL6030_ADJUSTABLE_SMPS(VDD1); 573TWL6030_ADJUSTABLE_SMPS(VDD1);
593TWL6030_ADJUSTABLE_SMPS(VDD2); 574TWL6030_ADJUSTABLE_SMPS(VDD2);
594TWL6030_ADJUSTABLE_SMPS(VDD3); 575TWL6030_ADJUSTABLE_SMPS(VDD3);
595TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1000); 576TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54);
596TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 1000); 577TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58);
597TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 1000); 578TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c);
598TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 1000); 579TWL6030_ADJUSTABLE_LDO(VMMC, 0x68);
599TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 1000); 580TWL6030_ADJUSTABLE_LDO(VPP, 0x6c);
600TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 1000); 581TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74);
601/* 6025 are renamed compared to 6030 versions */ 582/* 6025 are renamed compared to 6030 versions */
602TWL6032_ADJUSTABLE_LDO(LDO2, 0x54, 1000); 583TWL6032_ADJUSTABLE_LDO(LDO2, 0x54);
603TWL6032_ADJUSTABLE_LDO(LDO4, 0x58, 1000); 584TWL6032_ADJUSTABLE_LDO(LDO4, 0x58);
604TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c, 1000); 585TWL6032_ADJUSTABLE_LDO(LDO3, 0x5c);
605TWL6032_ADJUSTABLE_LDO(LDO5, 0x68, 1000); 586TWL6032_ADJUSTABLE_LDO(LDO5, 0x68);
606TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c, 1000); 587TWL6032_ADJUSTABLE_LDO(LDO1, 0x6c);
607TWL6032_ADJUSTABLE_LDO(LDO7, 0x74, 1000); 588TWL6032_ADJUSTABLE_LDO(LDO7, 0x74);
608TWL6032_ADJUSTABLE_LDO(LDO6, 0x60, 1000); 589TWL6032_ADJUSTABLE_LDO(LDO6, 0x60);
609TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64, 1000); 590TWL6032_ADJUSTABLE_LDO(LDOLN, 0x64);
610TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70, 1000); 591TWL6032_ADJUSTABLE_LDO(LDOUSB, 0x70);
611TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0); 592TWL6030_FIXED_LDO(VANA, 0x50, 2100, 0);
612TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0); 593TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 0);
613TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0); 594TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 0);
@@ -687,14 +668,9 @@ static int twlreg_probe(struct platform_device *pdev)
687 struct regulator_init_data *initdata; 668 struct regulator_init_data *initdata;
688 struct regulation_constraints *c; 669 struct regulation_constraints *c;
689 struct regulator_dev *rdev; 670 struct regulator_dev *rdev;
690 const struct of_device_id *match;
691 struct regulator_config config = { }; 671 struct regulator_config config = { };
692 672
693 match = of_match_device(twl_of_match, &pdev->dev); 673 template = of_device_get_match_data(&pdev->dev);
694 if (!match)
695 return -ENODEV;
696
697 template = match->data;
698 if (!template) 674 if (!template)
699 return -ENODEV; 675 return -ENODEV;
700 676
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index df591435d12a..12b422373580 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -205,33 +205,10 @@ static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data)
205 * BUCKV specifics 205 * BUCKV specifics
206 */ 206 */
207 207
208static int wm831x_buckv_list_voltage(struct regulator_dev *rdev, 208static const struct regulator_linear_range wm831x_buckv_ranges[] = {
209 unsigned selector) 209 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
210{ 210 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
211 if (selector <= 0x8) 211};
212 return 600000;
213 if (selector <= WM831X_BUCKV_MAX_SELECTOR)
214 return 600000 + ((selector - 0x8) * 12500);
215 return -EINVAL;
216}
217
218static int wm831x_buckv_map_voltage(struct regulator_dev *rdev,
219 int min_uV, int max_uV)
220{
221 u16 vsel;
222
223 if (min_uV < 600000)
224 vsel = 0;
225 else if (min_uV <= 1800000)
226 vsel = DIV_ROUND_UP(min_uV - 600000, 12500) + 8;
227 else
228 return -EINVAL;
229
230 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
231 return -EINVAL;
232
233 return vsel;
234}
235 212
236static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state) 213static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
237{ 214{
@@ -309,7 +286,7 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
309 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 286 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
310 int vsel; 287 int vsel;
311 288
312 vsel = wm831x_buckv_map_voltage(rdev, uV, uV); 289 vsel = regulator_map_voltage_linear_range(rdev, uV, uV);
313 if (vsel < 0) 290 if (vsel < 0)
314 return vsel; 291 return vsel;
315 292
@@ -331,48 +308,14 @@ static const unsigned int wm831x_dcdc_ilim[] = {
331 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000 308 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
332}; 309};
333 310
334static int wm831x_buckv_set_current_limit(struct regulator_dev *rdev,
335 int min_uA, int max_uA)
336{
337 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
338 struct wm831x *wm831x = dcdc->wm831x;
339 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
340 int i;
341
342 for (i = ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) {
343 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
344 (wm831x_dcdc_ilim[i] <= max_uA))
345 return wm831x_set_bits(wm831x, reg,
346 WM831X_DC1_HC_THR_MASK,
347 i << WM831X_DC1_HC_THR_SHIFT);
348 }
349
350 return -EINVAL;
351}
352
353static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
354{
355 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
356 struct wm831x *wm831x = dcdc->wm831x;
357 u16 reg = dcdc->base + WM831X_DCDC_CONTROL_2;
358 int val;
359
360 val = wm831x_reg_read(wm831x, reg);
361 if (val < 0)
362 return val;
363
364 val = (val & WM831X_DC1_HC_THR_MASK) >> WM831X_DC1_HC_THR_SHIFT;
365 return wm831x_dcdc_ilim[val];
366}
367
368static const struct regulator_ops wm831x_buckv_ops = { 311static const struct regulator_ops wm831x_buckv_ops = {
369 .set_voltage_sel = wm831x_buckv_set_voltage_sel, 312 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
370 .get_voltage_sel = wm831x_buckv_get_voltage_sel, 313 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
371 .list_voltage = wm831x_buckv_list_voltage, 314 .list_voltage = regulator_list_voltage_linear_range,
372 .map_voltage = wm831x_buckv_map_voltage, 315 .map_voltage = regulator_map_voltage_linear_range,
373 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 316 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
374 .set_current_limit = wm831x_buckv_set_current_limit, 317 .set_current_limit = regulator_set_current_limit_regmap,
375 .get_current_limit = wm831x_buckv_get_current_limit, 318 .get_current_limit = regulator_get_current_limit_regmap,
376 319
377 .is_enabled = regulator_is_enabled_regmap, 320 .is_enabled = regulator_is_enabled_regmap,
378 .enable = regulator_enable_regmap, 321 .enable = regulator_enable_regmap,
@@ -492,10 +435,16 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
492 dcdc->desc.id = id; 435 dcdc->desc.id = id;
493 dcdc->desc.type = REGULATOR_VOLTAGE; 436 dcdc->desc.type = REGULATOR_VOLTAGE;
494 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; 437 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
438 dcdc->desc.linear_ranges = wm831x_buckv_ranges;
439 dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges);
495 dcdc->desc.ops = &wm831x_buckv_ops; 440 dcdc->desc.ops = &wm831x_buckv_ops;
496 dcdc->desc.owner = THIS_MODULE; 441 dcdc->desc.owner = THIS_MODULE;
497 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; 442 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
498 dcdc->desc.enable_mask = 1 << id; 443 dcdc->desc.enable_mask = 1 << id;
444 dcdc->desc.csel_reg = dcdc->base + WM831X_DCDC_CONTROL_2;
445 dcdc->desc.csel_mask = WM831X_DC1_HC_THR_MASK;
446 dcdc->desc.n_current_limits = ARRAY_SIZE(wm831x_dcdc_ilim);
447 dcdc->desc.curr_table = wm831x_dcdc_ilim;
499 448
500 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); 449 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
501 if (ret < 0) { 450 if (ret < 0) {
diff --git a/include/linux/mfd/tps65218.h b/include/linux/mfd/tps65218.h
index c204d9a79436..45cdcd0fee53 100644
--- a/include/linux/mfd/tps65218.h
+++ b/include/linux/mfd/tps65218.h
@@ -208,6 +208,7 @@ enum tps65218_regulator_id {
208 /* LDOs */ 208 /* LDOs */
209 TPS65218_LDO_1, 209 TPS65218_LDO_1,
210 /* LS's */ 210 /* LS's */
211 TPS65218_LS_2,
211 TPS65218_LS_3, 212 TPS65218_LS_3,
212}; 213};
213 214
@@ -218,7 +219,7 @@ enum tps65218_regulator_id {
218/* Number of LDO voltage regulators available */ 219/* Number of LDO voltage regulators available */
219#define TPS65218_NUM_LDO 1 220#define TPS65218_NUM_LDO 1
220/* Number of total LS current regulators available */ 221/* Number of total LS current regulators available */
221#define TPS65218_NUM_LS 1 222#define TPS65218_NUM_LS 2
222/* Number of total regulators available */ 223/* Number of total regulators available */
223#define TPS65218_NUM_REGULATOR (TPS65218_NUM_DCDC + TPS65218_NUM_LDO \ 224#define TPS65218_NUM_REGULATOR (TPS65218_NUM_DCDC + TPS65218_NUM_LDO \
224 + TPS65218_NUM_LS) 225 + TPS65218_NUM_LS)
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 389bcaf7900f..377da2357118 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -264,6 +264,7 @@ enum regulator_type {
264 * @continuous_voltage_range: Indicates if the regulator can set any 264 * @continuous_voltage_range: Indicates if the regulator can set any
265 * voltage within constrains range. 265 * voltage within constrains range.
266 * @n_voltages: Number of selectors available for ops.list_voltage(). 266 * @n_voltages: Number of selectors available for ops.list_voltage().
267 * @n_current_limits: Number of selectors available for current limits
267 * 268 *
268 * @min_uV: Voltage given by the lowest selector (if linear mapping) 269 * @min_uV: Voltage given by the lowest selector (if linear mapping)
269 * @uV_step: Voltage increase with each selector (if linear mapping) 270 * @uV_step: Voltage increase with each selector (if linear mapping)
@@ -278,14 +279,15 @@ enum regulator_type {
278 * @n_linear_ranges: Number of entries in the @linear_ranges (and in 279 * @n_linear_ranges: Number of entries in the @linear_ranges (and in
279 * linear_range_selectors if used) table(s). 280 * linear_range_selectors if used) table(s).
280 * @volt_table: Voltage mapping table (if table based mapping) 281 * @volt_table: Voltage mapping table (if table based mapping)
282 * @curr_table: Current limit mapping table (if table based mapping)
281 * 283 *
282 * @vsel_range_reg: Register for range selector when using pickable ranges 284 * @vsel_range_reg: Register for range selector when using pickable ranges
283 * and regulator_regmap_X_voltage_X_pickable functions. 285 * and regulator_regmap_X_voltage_X_pickable functions.
284 * @vsel_range_mask: Mask for register bitfield used for range selector 286 * @vsel_range_mask: Mask for register bitfield used for range selector
285 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_ 287 * @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
286 * @vsel_mask: Mask for register bitfield used for selector 288 * @vsel_mask: Mask for register bitfield used for selector
287 * @csel_reg: Register for TPS65218 LS3 current regulator 289 * @csel_reg: Register for current limit selector using regmap set_current_limit
288 * @csel_mask: Mask for TPS65218 LS3 current regulator 290 * @csel_mask: Mask for register bitfield used for current limit selector
289 * @apply_reg: Register for initiate voltage change on the output when 291 * @apply_reg: Register for initiate voltage change on the output when
290 * using regulator_set_voltage_sel_regmap 292 * using regulator_set_voltage_sel_regmap
291 * @apply_bit: Register bitfield used for initiate voltage change on the 293 * @apply_bit: Register bitfield used for initiate voltage change on the
@@ -333,6 +335,7 @@ struct regulator_desc {
333 int id; 335 int id;
334 unsigned int continuous_voltage_range:1; 336 unsigned int continuous_voltage_range:1;
335 unsigned n_voltages; 337 unsigned n_voltages;
338 unsigned int n_current_limits;
336 const struct regulator_ops *ops; 339 const struct regulator_ops *ops;
337 int irq; 340 int irq;
338 enum regulator_type type; 341 enum regulator_type type;
@@ -351,6 +354,7 @@ struct regulator_desc {
351 int n_linear_ranges; 354 int n_linear_ranges;
352 355
353 const unsigned int *volt_table; 356 const unsigned int *volt_table;
357 const unsigned int *curr_table;
354 358
355 unsigned int vsel_range_reg; 359 unsigned int vsel_range_reg;
356 unsigned int vsel_range_mask; 360 unsigned int vsel_range_mask;
@@ -401,13 +405,7 @@ struct regulator_desc {
401 * NULL). 405 * NULL).
402 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is 406 * @regmap: regmap to use for core regmap helpers if dev_get_regmap() is
403 * insufficient. 407 * insufficient.
404 * @ena_gpio_initialized: GPIO controlling regulator enable was properly 408 * @ena_gpiod: GPIO controlling regulator enable.
405 * initialized, meaning that >= 0 is a valid gpio
406 * identifier and < 0 is a non existent gpio.
407 * @ena_gpio: GPIO controlling regulator enable.
408 * @ena_gpiod: GPIO descriptor controlling regulator enable.
409 * @ena_gpio_invert: Sense for GPIO enable control.
410 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
411 */ 409 */
412struct regulator_config { 410struct regulator_config {
413 struct device *dev; 411 struct device *dev;
@@ -416,11 +414,7 @@ struct regulator_config {
416 struct device_node *of_node; 414 struct device_node *of_node;
417 struct regmap *regmap; 415 struct regmap *regmap;
418 416
419 bool ena_gpio_initialized;
420 int ena_gpio;
421 struct gpio_desc *ena_gpiod; 417 struct gpio_desc *ena_gpiod;
422 unsigned int ena_gpio_invert:1;
423 unsigned int ena_gpio_flags;
424}; 418};
425 419
426/* 420/*
@@ -503,6 +497,7 @@ int regulator_notifier_call_chain(struct regulator_dev *rdev,
503 497
504void *rdev_get_drvdata(struct regulator_dev *rdev); 498void *rdev_get_drvdata(struct regulator_dev *rdev);
505struct device *rdev_get_dev(struct regulator_dev *rdev); 499struct device *rdev_get_dev(struct regulator_dev *rdev);
500struct regmap *rdev_get_regmap(struct regulator_dev *rdev);
506int rdev_get_id(struct regulator_dev *rdev); 501int rdev_get_id(struct regulator_dev *rdev);
507 502
508int regulator_mode_to_status(unsigned int); 503int regulator_mode_to_status(unsigned int);
@@ -543,9 +538,18 @@ int regulator_set_pull_down_regmap(struct regulator_dev *rdev);
543 538
544int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, 539int regulator_set_active_discharge_regmap(struct regulator_dev *rdev,
545 bool enable); 540 bool enable);
541int regulator_set_current_limit_regmap(struct regulator_dev *rdev,
542 int min_uA, int max_uA);
543int regulator_get_current_limit_regmap(struct regulator_dev *rdev);
546void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 544void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
547 545
548void regulator_lock(struct regulator_dev *rdev); 546void regulator_lock(struct regulator_dev *rdev);
549void regulator_unlock(struct regulator_dev *rdev); 547void regulator_unlock(struct regulator_dev *rdev);
550 548
549/*
550 * Helper functions intended to be used by regulator drivers prior registering
551 * their regulators.
552 */
553int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
554 unsigned int selector);
551#endif 555#endif
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h
index 1a4340ed8e2b..f10140da7145 100644
--- a/include/linux/regulator/fixed.h
+++ b/include/linux/regulator/fixed.h
@@ -25,14 +25,6 @@ struct regulator_init_data;
25 * @input_supply: Name of the input regulator supply 25 * @input_supply: Name of the input regulator supply
26 * @microvolts: Output voltage of regulator 26 * @microvolts: Output voltage of regulator
27 * @startup_delay: Start-up time in microseconds 27 * @startup_delay: Start-up time in microseconds
28 * @gpio_is_open_drain: Gpio pin is open drain or normal type.
29 * If it is open drain type then HIGH will be set
30 * through PULL-UP with setting gpio as input
31 * and low will be set as gpio-output with driven
32 * to low. For non-open-drain case, the gpio will
33 * will be in output and drive to low/high accordingly.
34 * @enable_high: Polarity of enable GPIO
35 * 1 = Active high, 0 = Active low
36 * @enabled_at_boot: Whether regulator has been enabled at 28 * @enabled_at_boot: Whether regulator has been enabled at
37 * boot or not. 1 = Yes, 0 = No 29 * boot or not. 1 = Yes, 0 = No
38 * This is used to keep the regulator at 30 * This is used to keep the regulator at
@@ -48,8 +40,6 @@ struct fixed_voltage_config {
48 const char *input_supply; 40 const char *input_supply;
49 int microvolts; 41 int microvolts;
50 unsigned startup_delay; 42 unsigned startup_delay;
51 unsigned gpio_is_open_drain:1;
52 unsigned enable_high:1;
53 unsigned enabled_at_boot:1; 43 unsigned enabled_at_boot:1;
54 struct regulator_init_data *init_data; 44 struct regulator_init_data *init_data;
55}; 45};
diff --git a/include/linux/regulator/gpio-regulator.h b/include/linux/regulator/gpio-regulator.h
index 19fbd267406d..11cd6375215d 100644
--- a/include/linux/regulator/gpio-regulator.h
+++ b/include/linux/regulator/gpio-regulator.h
@@ -21,6 +21,8 @@
21#ifndef __REGULATOR_GPIO_H 21#ifndef __REGULATOR_GPIO_H
22#define __REGULATOR_GPIO_H 22#define __REGULATOR_GPIO_H
23 23
24#include <linux/gpio/consumer.h>
25
24struct regulator_init_data; 26struct regulator_init_data;
25 27
26enum regulator_type; 28enum regulator_type;
@@ -44,18 +46,14 @@ struct gpio_regulator_state {
44/** 46/**
45 * struct gpio_regulator_config - config structure 47 * struct gpio_regulator_config - config structure
46 * @supply_name: Name of the regulator supply 48 * @supply_name: Name of the regulator supply
47 * @enable_gpio: GPIO to use for enable control
48 * set to -EINVAL if not used
49 * @enable_high: Polarity of enable GPIO
50 * 1 = Active high, 0 = Active low
51 * @enabled_at_boot: Whether regulator has been enabled at 49 * @enabled_at_boot: Whether regulator has been enabled at
52 * boot or not. 1 = Yes, 0 = No 50 * boot or not. 1 = Yes, 0 = No
53 * This is used to keep the regulator at 51 * This is used to keep the regulator at
54 * the default state 52 * the default state
55 * @startup_delay: Start-up time in microseconds 53 * @startup_delay: Start-up time in microseconds
56 * @gpios: Array containing the gpios needed to control 54 * @gflags: Array of GPIO configuration flags for initial
57 * the setting of the regulator 55 * states
58 * @nr_gpios: Number of gpios 56 * @ngpios: Number of GPIOs and configurations available
59 * @states: Array of gpio_regulator_state entries describing 57 * @states: Array of gpio_regulator_state entries describing
60 * the gpio state for specific voltages 58 * the gpio state for specific voltages
61 * @nr_states: Number of states available 59 * @nr_states: Number of states available
@@ -69,13 +67,11 @@ struct gpio_regulator_state {
69struct gpio_regulator_config { 67struct gpio_regulator_config {
70 const char *supply_name; 68 const char *supply_name;
71 69
72 int enable_gpio;
73 unsigned enable_high:1;
74 unsigned enabled_at_boot:1; 70 unsigned enabled_at_boot:1;
75 unsigned startup_delay; 71 unsigned startup_delay;
76 72
77 struct gpio *gpios; 73 enum gpiod_flags *gflags;
78 int nr_gpios; 74 int ngpios;
79 75
80 struct gpio_regulator_state *states; 76 struct gpio_regulator_state *states;
81 int nr_states; 77 int nr_states;