aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-06-23 20:30:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-23 20:30:20 -0400
commit7fe0bf908d4f8f7d134cab280cac64fe65997ac1 (patch)
treee14095fcaadd69df93b7a0a792001675582a1a1b
parent5a602e157a9d91d5ce98d07c404097edba8ec9f3 (diff)
parent733ada000f2c9618ccbac7b9ba146113f0a6675b (diff)
Merge tag 'regulator-v4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "Another fairly quiet release, some new drivers with generic handling for minor features but nothing that makes a substantial difference outside of the subsystem or for most boards: - support for a bunch of new parameters which are present on enough regulators to be worth having generic handling for in the framework. - fixes for some issues with printing constraints during boot which should probably have gone in for v4.1 but didn't. - new drivers for Dialog DA9062, Maxim MAX77621 and Qualcomm SPMI regulators" * tag 'regulator-v4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (45 commits) regulator: qcom_spmi: Fix calculating number of voltages regulator: qcom_spmi: Add missing braces for aligned code regulator: fix simple_return.cocci warnings regulator: Add QCOM SPMI regulator driver regulator: Add docbook for soft start regulator: Add input current limit support regulator: Add soft start support regulator: Add pull down support regulator: Add system_load constraint regulator: max8973: Fix up ramp_delay for MAX8973_RAMP_25mV_PER_US case regulator: core: replace sprintf with scnprintf regulator: core: fix constraints output buffer regulator: core: Don't corrupt display when printing uV offsets regulator: max8973: add support for MAX77621 regulator: max8973: configure ramp delay through callback regulator: pwm-regulator: Diffientiate between dev (device) and rdev (regulator_dev) regulator: pwm-regulator: Remove superfluous is_enabled check regulator: pwm-regulator: Remove unnecessary descriptor attribute from ddata regulator: core: Don't spew backtraces on duplicate sysfs regulator: da9063: Fix up irq leak ...
-rw-r--r--Documentation/devicetree/bindings/regulator/max8973-regulator.txt20
-rw-r--r--Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt121
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt7
-rw-r--r--drivers/regulator/88pm8607.c2
-rw-r--r--drivers/regulator/Kconfig23
-rw-r--r--drivers/regulator/Makefile2
-rw-r--r--drivers/regulator/arizona-ldo1.c15
-rw-r--r--drivers/regulator/core.c76
-rw-r--r--drivers/regulator/da9062-regulator.c842
-rw-r--r--drivers/regulator/da9063-regulator.c21
-rw-r--r--drivers/regulator/fan53555.c1
-rw-r--r--drivers/regulator/helpers.c2
-rw-r--r--drivers/regulator/lp8755.c23
-rw-r--r--drivers/regulator/max14577.c128
-rw-r--r--drivers/regulator/max77686.c8
-rw-r--r--drivers/regulator/max77693.c17
-rw-r--r--drivers/regulator/max77843.c68
-rw-r--r--drivers/regulator/max8973-regulator.c269
-rw-r--r--drivers/regulator/of_regulator.c16
-rw-r--r--drivers/regulator/pwm-regulator.c41
-rw-r--r--drivers/regulator/qcom_spmi-regulator.c1435
-rw-r--r--drivers/regulator/s2mps11.c10
-rw-r--r--drivers/regulator/wm831x-dcdc.c12
-rw-r--r--drivers/regulator/wm831x-isink.c3
-rw-r--r--drivers/regulator/wm831x-ldo.c6
-rw-r--r--include/linux/regulator/driver.h11
-rw-r--r--include/linux/regulator/machine.h9
-rw-r--r--include/linux/regulator/max8973-regulator.h4
28 files changed, 2897 insertions, 295 deletions
diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
index 4f15d8a1bfd0..55efb24e5683 100644
--- a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
@@ -2,12 +2,30 @@
2 2
3Required properties: 3Required properties:
4 4
5- compatible: must be "maxim,max8973" 5- compatible: must be one of following:
6 "maxim,max8973"
7 "maxim,max77621".
6- reg: the i2c slave address of the regulator. It should be 0x1b. 8- reg: the i2c slave address of the regulator. It should be 0x1b.
7 9
8Any standard regulator properties can be used to configure the single max8973 10Any standard regulator properties can be used to configure the single max8973
9DCDC. 11DCDC.
10 12
13Optional properties:
14
15-maxim,externally-enable: boolean, externally control the regulator output
16 enable/disable.
17-maxim,enable-gpio: GPIO for enable control. If the valid GPIO is provided
18 then externally enable control will be considered.
19-maxim,dvs-gpio: GPIO which is connected to DVS pin of device.
20-maxim,dvs-default-state: Default state of GPIO during initialisation.
21 1 for HIGH and 0 for LOW.
22-maxim,enable-remote-sense: boolean, enable reote sense.
23-maxim,enable-falling-slew-rate: boolean, enable falling slew rate.
24-maxim,enable-active-discharge: boolean: enable active discharge.
25-maxim,enable-frequency-shift: boolean, enable 9% frequency shift.
26-maxim,enable-bias-control: boolean, enable bias control. By enabling this
27 startup delay can be reduce to 20us from 220us.
28
11Example: 29Example:
12 30
13 max8973@1b { 31 max8973@1b {
diff --git a/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
new file mode 100644
index 000000000000..75b4604bad07
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/qcom,spmi-regulator.txt
@@ -0,0 +1,121 @@
1Qualcomm SPMI Regulators
2
3- compatible:
4 Usage: required
5 Value type: <string>
6 Definition: must be one of:
7 "qcom,pm8841-regulators"
8 "qcom,pm8916-regulators"
9 "qcom,pm8941-regulators"
10
11- interrupts:
12 Usage: optional
13 Value type: <prop-encoded-array>
14 Definition: List of OCP interrupts.
15
16- interrupt-names:
17 Usage: required if 'interrupts' property present
18 Value type: <string-array>
19 Definition: List of strings defining the names of the
20 interrupts in the 'interrupts' property 1-to-1.
21 Supported values are "ocp-<regulator_name>", where
22 <regulator_name> corresponds to a voltage switch
23 type regulator.
24
25- vdd_s1-supply:
26- vdd_s2-supply:
27- vdd_s3-supply:
28- vdd_s4-supply:
29- vdd_s5-supply:
30- vdd_s6-supply:
31- vdd_s7-supply:
32- vdd_s8-supply:
33 Usage: optional (pm8841 only)
34 Value type: <phandle>
35 Definition: Reference to regulator supplying the input pin, as
36 described in the data sheet.
37
38- vdd_s1-supply:
39- vdd_s2-supply:
40- vdd_s3-supply:
41- vdd_s4-supply:
42- vdd_l1_l3-supply:
43- vdd_l2-supply:
44- vdd_l4_l5_l6-supply:
45- vdd_l7-supply:
46- vdd_l8_l11_l14_l15_l16-supply:
47- vdd_l9_l10_l12_l13_l17_l18-supply:
48 Usage: optional (pm8916 only)
49 Value type: <phandle>
50 Definition: Reference to regulator supplying the input pin, as
51 described in the data sheet.
52
53- vdd_s1-supply:
54- vdd_s2-supply:
55- vdd_s3-supply:
56- vdd_l1_l3-supply:
57- vdd_l2_lvs_1_2_3-supply:
58- vdd_l4_l11-supply:
59- vdd_l5_l7-supply:
60- vdd_l6_l12_l14_l15-supply:
61- vdd_l8_l16_l18_19-supply:
62- vdd_l9_l10_l17_l22-supply:
63- vdd_l13_l20_l23_l24-supply:
64- vdd_l21-supply:
65- vin_5vs-supply:
66 Usage: optional (pm8941 only)
67 Value type: <phandle>
68 Definition: Reference to regulator supplying the input pin, as
69 described in the data sheet.
70
71
72The regulator node houses sub-nodes for each regulator within the device. Each
73sub-node is identified using the node's name, with valid values listed for each
74of the PMICs below.
75
76pm8841:
77 s1, s2, s3, s4, s5, s6, s7, s8
78
79pm8916:
80 s1, s2, s3, s4, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13,
81 l14, l15, l16, l17, l18
82
83pm8941:
84 s1, s2, s3, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14,
85 l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, lvs1, lvs2, lvs3,
86 mvs1, mvs2
87
88The content of each sub-node is defined by the standard binding for regulators -
89see regulator.txt - with additional custom properties described below:
90
91- regulator-initial-mode:
92 Usage: optional
93 Value type: <u32>
94 Descrption: 1 = Set initial mode to high power mode (HPM), also referred
95 to as NPM. HPM consumes more ground current than LPM, but
96 it can source significantly higher load current. HPM is not
97 available on boost type regulators. For voltage switch type
98 regulators, HPM implies that over current protection and
99 soft start are active all the time. 0 = Set initial mode to
100 low power mode (LPM).
101
102Example:
103
104 regulators {
105 compatible = "qcom,pm8941-regulators";
106 vdd_l1_l3-supply = <&s1>;
107
108 s1: s1 {
109 regulator-min-microvolt = <1300000>;
110 regulator-max-microvolt = <1400000>;
111 };
112
113 ...
114
115 l1: l1 {
116 regulator-min-microvolt = <1225000>;
117 regulator-max-microvolt = <1300000>;
118 };
119
120 ....
121 };
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index abb26b58c83e..db88feb28c03 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -7,18 +7,20 @@ Optional properties:
7- regulator-microvolt-offset: Offset applied to voltages to compensate for voltage drops 7- regulator-microvolt-offset: Offset applied to voltages to compensate for voltage drops
8- regulator-min-microamp: smallest current consumers may set 8- regulator-min-microamp: smallest current consumers may set
9- regulator-max-microamp: largest current consumers may set 9- regulator-max-microamp: largest current consumers may set
10- regulator-input-current-limit-microamp: maximum input current regulator allows
10- regulator-always-on: boolean, regulator should never be disabled 11- regulator-always-on: boolean, regulator should never be disabled
11- regulator-boot-on: bootloader/firmware enabled regulator 12- regulator-boot-on: bootloader/firmware enabled regulator
12- regulator-allow-bypass: allow the regulator to go into bypass mode 13- regulator-allow-bypass: allow the regulator to go into bypass mode
13- <name>-supply: phandle to the parent supply/regulator node 14- <name>-supply: phandle to the parent supply/regulator node
14- regulator-ramp-delay: ramp delay for regulator(in uV/uS) 15- regulator-ramp-delay: ramp delay for regulator(in uV/uS)
15 For hardware which supports disabling ramp rate, it should be explicitly 16 For hardware which supports disabling ramp rate, it should be explicitly
16 intialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay. 17 initialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay.
17- regulator-enable-ramp-delay: The time taken, in microseconds, for the supply 18- regulator-enable-ramp-delay: The time taken, in microseconds, for the supply
18 rail to reach the target voltage, plus/minus whatever tolerance the board 19 rail to reach the target voltage, plus/minus whatever tolerance the board
19 design requires. This property describes the total system ramp time 20 design requires. This property describes the total system ramp time
20 required due to the combination of internal ramping of the regulator itself, 21 required due to the combination of internal ramping of the regulator itself,
21 and board design issues such as trace capacitance and load on the supply. 22 and board design issues such as trace capacitance and load on the supply.
23- regulator-soft-start: Enable soft start so that voltage ramps slowly
22- regulator-state-mem sub-root node for Suspend-to-RAM mode 24- regulator-state-mem sub-root node for Suspend-to-RAM mode
23 : suspend to memory, the device goes to sleep, but all data stored in memory, 25 : suspend to memory, the device goes to sleep, but all data stored in memory,
24 only some external interrupt can wake the device. 26 only some external interrupt can wake the device.
@@ -37,6 +39,9 @@ Optional properties:
37- regulator-initial-mode: initial operating mode. The set of possible operating 39- regulator-initial-mode: initial operating mode. The set of possible operating
38 modes depends on the capabilities of every hardware so each device binding 40 modes depends on the capabilities of every hardware so each device binding
39 documentation explains which values the regulator supports. 41 documentation explains which values the regulator supports.
42- regulator-system-load: Load in uA present on regulator that is not captured by
43 any consumer request.
44- regulator-pull-down: Enable pull down resistor when the regulator is disabled.
40 45
41Deprecated properties: 46Deprecated properties:
42- regulator-compatible: If a regulator chip contains multiple 47- regulator-compatible: If a regulator chip contains multiple
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index c3d15427adc7..b100a63ff3b3 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -404,7 +404,7 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
404 return 0; 404 return 0;
405} 405}
406 406
407static struct platform_device_id pm8607_regulator_driver_ids[] = { 407static const struct platform_device_id pm8607_regulator_driver_ids[] = {
408 { 408 {
409 .name = "88pm860x-regulator", 409 .name = "88pm860x-regulator",
410 .driver_data = 0, 410 .driver_data = 0,
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index a6f116aa5235..bef3bde6971b 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -178,6 +178,16 @@ config REGULATOR_DA9055
178 This driver can also be built as a module. If so, the module 178 This driver can also be built as a module. If so, the module
179 will be called da9055-regulator. 179 will be called da9055-regulator.
180 180
181config REGULATOR_DA9062
182 tristate "Dialog Semiconductor DA9062 regulators"
183 depends on MFD_DA9062
184 help
185 Say y here to support the BUCKs and LDOs regulators found on
186 DA9062 PMICs.
187
188 This driver can also be built as a module. If so, the module
189 will be called da9062-regulator.
190
181config REGULATOR_DA9063 191config REGULATOR_DA9063
182 tristate "Dialog Semiconductor DA9063 regulators" 192 tristate "Dialog Semiconductor DA9063 regulators"
183 depends on MFD_DA9063 193 depends on MFD_DA9063
@@ -233,7 +243,7 @@ config REGULATOR_FAN53555
233 243
234config REGULATOR_GPIO 244config REGULATOR_GPIO
235 tristate "GPIO regulator support" 245 tristate "GPIO regulator support"
236 depends on GPIOLIB 246 depends on GPIOLIB || COMPILE_TEST
237 help 247 help
238 This driver provides support for regulators that can be 248 This driver provides support for regulators that can be
239 controlled via gpios. 249 controlled via gpios.
@@ -512,6 +522,17 @@ config REGULATOR_QCOM_RPM
512 Qualcomm RPM as a module. The module will be named 522 Qualcomm RPM as a module. The module will be named
513 "qcom_rpm-regulator". 523 "qcom_rpm-regulator".
514 524
525config REGULATOR_QCOM_SPMI
526 tristate "Qualcomm SPMI regulator driver"
527 depends on SPMI || COMPILE_TEST
528 help
529 If you say yes to this option, support will be included for the
530 regulators found in Qualcomm SPMI PMICs.
531
532 Say M here if you want to include support for the regulators on the
533 Qualcomm SPMI PMICs as a module. The module will be named
534 "qcom_spmi-regulator".
535
515config REGULATOR_RC5T583 536config REGULATOR_RC5T583
516 tristate "RICOH RC5T583 Power regulators" 537 tristate "RICOH RC5T583 Power regulators"
517 depends on MFD_RC5T583 538 depends on MFD_RC5T583
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 2c4da15e1545..91bf76267404 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_REGULATOR_BCM590XX) += bcm590xx-regulator.o
25obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 25obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
26obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 26obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
27obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o 27obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
28obj-$(CONFIG_REGULATOR_DA9062) += da9062-regulator.o
28obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o 29obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
29obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o 30obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
30obj-$(CONFIG_REGULATOR_DA9211) += da9211-regulator.o 31obj-$(CONFIG_REGULATOR_DA9211) += da9211-regulator.o
@@ -61,6 +62,7 @@ obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
61obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 62obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
62obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o 63obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o
63obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o 64obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o
65obj-$(CONFIG_REGULATOR_QCOM_SPMI) += qcom_spmi-regulator.o
64obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o 66obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
65obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o 67obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
66obj-$(CONFIG_REGULATOR_PWM) += pwm-regulator.o 68obj-$(CONFIG_REGULATOR_PWM) += pwm-regulator.o
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index a1d07d347c20..90941632efa9 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -178,6 +178,16 @@ static const struct regulator_init_data arizona_ldo1_default = {
178 .num_consumer_supplies = 1, 178 .num_consumer_supplies = 1,
179}; 179};
180 180
181static const struct regulator_init_data arizona_ldo1_wm5110 = {
182 .constraints = {
183 .min_uV = 1175000,
184 .max_uV = 1200000,
185 .valid_ops_mask = REGULATOR_CHANGE_STATUS |
186 REGULATOR_CHANGE_VOLTAGE,
187 },
188 .num_consumer_supplies = 1,
189};
190
181static int arizona_ldo1_of_get_pdata(struct arizona *arizona, 191static int arizona_ldo1_of_get_pdata(struct arizona *arizona,
182 struct regulator_config *config, 192 struct regulator_config *config,
183 const struct regulator_desc *desc) 193 const struct regulator_desc *desc)
@@ -243,6 +253,11 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
243 desc = &arizona_ldo1_hc; 253 desc = &arizona_ldo1_hc;
244 ldo1->init_data = arizona_ldo1_dvfs; 254 ldo1->init_data = arizona_ldo1_dvfs;
245 break; 255 break;
256 case WM5110:
257 case WM8280:
258 desc = &arizona_ldo1;
259 ldo1->init_data = arizona_ldo1_wm5110;
260 break;
246 default: 261 default:
247 desc = &arizona_ldo1; 262 desc = &arizona_ldo1;
248 ldo1->init_data = arizona_ldo1_default; 263 ldo1->init_data = arizona_ldo1_default;
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 443eaab933fc..c9f72019bd68 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -678,6 +678,8 @@ static int drms_uA_update(struct regulator_dev *rdev)
678 list_for_each_entry(sibling, &rdev->consumer_list, list) 678 list_for_each_entry(sibling, &rdev->consumer_list, list)
679 current_uA += sibling->uA_load; 679 current_uA += sibling->uA_load;
680 680
681 current_uA += rdev->constraints->system_load;
682
681 if (rdev->desc->ops->set_load) { 683 if (rdev->desc->ops->set_load) {
682 /* set the optimum mode for our new total regulator load */ 684 /* set the optimum mode for our new total regulator load */
683 err = rdev->desc->ops->set_load(rdev, current_uA); 685 err = rdev->desc->ops->set_load(rdev, current_uA);
@@ -779,59 +781,64 @@ static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
779static void print_constraints(struct regulator_dev *rdev) 781static void print_constraints(struct regulator_dev *rdev)
780{ 782{
781 struct regulation_constraints *constraints = rdev->constraints; 783 struct regulation_constraints *constraints = rdev->constraints;
782 char buf[80] = ""; 784 char buf[160] = "";
785 size_t len = sizeof(buf) - 1;
783 int count = 0; 786 int count = 0;
784 int ret; 787 int ret;
785 788
786 if (constraints->min_uV && constraints->max_uV) { 789 if (constraints->min_uV && constraints->max_uV) {
787 if (constraints->min_uV == constraints->max_uV) 790 if (constraints->min_uV == constraints->max_uV)
788 count += sprintf(buf + count, "%d mV ", 791 count += scnprintf(buf + count, len - count, "%d mV ",
789 constraints->min_uV / 1000); 792 constraints->min_uV / 1000);
790 else 793 else
791 count += sprintf(buf + count, "%d <--> %d mV ", 794 count += scnprintf(buf + count, len - count,
792 constraints->min_uV / 1000, 795 "%d <--> %d mV ",
793 constraints->max_uV / 1000); 796 constraints->min_uV / 1000,
797 constraints->max_uV / 1000);
794 } 798 }
795 799
796 if (!constraints->min_uV || 800 if (!constraints->min_uV ||
797 constraints->min_uV != constraints->max_uV) { 801 constraints->min_uV != constraints->max_uV) {
798 ret = _regulator_get_voltage(rdev); 802 ret = _regulator_get_voltage(rdev);
799 if (ret > 0) 803 if (ret > 0)
800 count += sprintf(buf + count, "at %d mV ", ret / 1000); 804 count += scnprintf(buf + count, len - count,
805 "at %d mV ", ret / 1000);
801 } 806 }
802 807
803 if (constraints->uV_offset) 808 if (constraints->uV_offset)
804 count += sprintf(buf, "%dmV offset ", 809 count += scnprintf(buf + count, len - count, "%dmV offset ",
805 constraints->uV_offset / 1000); 810 constraints->uV_offset / 1000);
806 811
807 if (constraints->min_uA && constraints->max_uA) { 812 if (constraints->min_uA && constraints->max_uA) {
808 if (constraints->min_uA == constraints->max_uA) 813 if (constraints->min_uA == constraints->max_uA)
809 count += sprintf(buf + count, "%d mA ", 814 count += scnprintf(buf + count, len - count, "%d mA ",
810 constraints->min_uA / 1000); 815 constraints->min_uA / 1000);
811 else 816 else
812 count += sprintf(buf + count, "%d <--> %d mA ", 817 count += scnprintf(buf + count, len - count,
813 constraints->min_uA / 1000, 818 "%d <--> %d mA ",
814 constraints->max_uA / 1000); 819 constraints->min_uA / 1000,
820 constraints->max_uA / 1000);
815 } 821 }
816 822
817 if (!constraints->min_uA || 823 if (!constraints->min_uA ||
818 constraints->min_uA != constraints->max_uA) { 824 constraints->min_uA != constraints->max_uA) {
819 ret = _regulator_get_current_limit(rdev); 825 ret = _regulator_get_current_limit(rdev);
820 if (ret > 0) 826 if (ret > 0)
821 count += sprintf(buf + count, "at %d mA ", ret / 1000); 827 count += scnprintf(buf + count, len - count,
828 "at %d mA ", ret / 1000);
822 } 829 }
823 830
824 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) 831 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
825 count += sprintf(buf + count, "fast "); 832 count += scnprintf(buf + count, len - count, "fast ");
826 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) 833 if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
827 count += sprintf(buf + count, "normal "); 834 count += scnprintf(buf + count, len - count, "normal ");
828 if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) 835 if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE)
829 count += sprintf(buf + count, "idle "); 836 count += scnprintf(buf + count, len - count, "idle ");
830 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 837 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
831 count += sprintf(buf + count, "standby"); 838 count += scnprintf(buf + count, len - count, "standby");
832 839
833 if (!count) 840 if (!count)
834 sprintf(buf, "no parameters"); 841 scnprintf(buf, len, "no parameters");
835 842
836 rdev_dbg(rdev, "%s\n", buf); 843 rdev_dbg(rdev, "%s\n", buf);
837 844
@@ -1006,6 +1013,15 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1006 if (ret != 0) 1013 if (ret != 0)
1007 goto out; 1014 goto out;
1008 1015
1016 if (rdev->constraints->ilim_uA && ops->set_input_current_limit) {
1017 ret = ops->set_input_current_limit(rdev,
1018 rdev->constraints->ilim_uA);
1019 if (ret < 0) {
1020 rdev_err(rdev, "failed to set input limit\n");
1021 goto out;
1022 }
1023 }
1024
1009 /* do we need to setup our suspend state */ 1025 /* do we need to setup our suspend state */
1010 if (rdev->constraints->initial_state) { 1026 if (rdev->constraints->initial_state) {
1011 ret = suspend_prepare(rdev, rdev->constraints->initial_state); 1027 ret = suspend_prepare(rdev, rdev->constraints->initial_state);
@@ -1049,6 +1065,22 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1049 } 1065 }
1050 } 1066 }
1051 1067
1068 if (rdev->constraints->pull_down && ops->set_pull_down) {
1069 ret = ops->set_pull_down(rdev);
1070 if (ret < 0) {
1071 rdev_err(rdev, "failed to set pull down\n");
1072 goto out;
1073 }
1074 }
1075
1076 if (rdev->constraints->soft_start && ops->set_soft_start) {
1077 ret = ops->set_soft_start(rdev);
1078 if (ret < 0) {
1079 rdev_err(rdev, "failed to set soft start\n");
1080 goto out;
1081 }
1082 }
1083
1052 print_constraints(rdev); 1084 print_constraints(rdev);
1053 return 0; 1085 return 0;
1054out: 1086out:
@@ -1192,10 +1224,10 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1192 if (regulator->supply_name == NULL) 1224 if (regulator->supply_name == NULL)
1193 goto overflow_err; 1225 goto overflow_err;
1194 1226
1195 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, 1227 err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
1196 buf); 1228 buf);
1197 if (err) { 1229 if (err) {
1198 rdev_warn(rdev, "could not add device link %s err %d\n", 1230 rdev_dbg(rdev, "could not add device link %s err %d\n",
1199 dev->kobj.name, err); 1231 dev->kobj.name, err);
1200 /* non-fatal */ 1232 /* non-fatal */
1201 } 1233 }
diff --git a/drivers/regulator/da9062-regulator.c b/drivers/regulator/da9062-regulator.c
new file mode 100644
index 000000000000..dd76da09b3c7
--- /dev/null
+++ b/drivers/regulator/da9062-regulator.c
@@ -0,0 +1,842 @@
1/*
2 * da9062-regulator.c - REGULATOR device driver for DA9062
3 * Copyright (C) 2015 Dialog Semiconductor Ltd.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22#include <linux/regmap.h>
23#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h>
25#include <linux/regulator/of_regulator.h>
26#include <linux/mfd/da9062/core.h>
27#include <linux/mfd/da9062/registers.h>
28
29/* Regulator IDs */
30enum {
31 DA9062_ID_BUCK1,
32 DA9062_ID_BUCK2,
33 DA9062_ID_BUCK3,
34 DA9062_ID_BUCK4,
35 DA9062_ID_LDO1,
36 DA9062_ID_LDO2,
37 DA9062_ID_LDO3,
38 DA9062_ID_LDO4,
39 DA9062_MAX_REGULATORS,
40};
41
42/* Regulator capabilities and registers description */
43struct da9062_regulator_info {
44 struct regulator_desc desc;
45 /* Current limiting */
46 unsigned int n_current_limits;
47 const int *current_limits;
48 /* Main register fields */
49 struct reg_field mode;
50 struct reg_field suspend;
51 struct reg_field sleep;
52 struct reg_field suspend_sleep;
53 unsigned int suspend_vsel_reg;
54 struct reg_field ilimit;
55 /* Event detection bit */
56 struct reg_field oc_event;
57};
58
59/* Single regulator settings */
60struct da9062_regulator {
61 struct regulator_desc desc;
62 struct regulator_dev *rdev;
63 struct da9062 *hw;
64 const struct da9062_regulator_info *info;
65
66 struct regmap_field *mode;
67 struct regmap_field *suspend;
68 struct regmap_field *sleep;
69 struct regmap_field *suspend_sleep;
70 struct regmap_field *ilimit;
71};
72
73/* Encapsulates all information for the regulators driver */
74struct da9062_regulators {
75 int irq_ldo_lim;
76 unsigned n_regulators;
77 /* Array size to be defined during init. Keep at end. */
78 struct da9062_regulator regulator[0];
79};
80
81/* BUCK modes */
82enum {
83 BUCK_MODE_MANUAL, /* 0 */
84 BUCK_MODE_SLEEP, /* 1 */
85 BUCK_MODE_SYNC, /* 2 */
86 BUCK_MODE_AUTO /* 3 */
87};
88
89/* Regulator operations */
90
91/* Current limits array (in uA) BUCK1 and BUCK3.
92 Entry indexes corresponds to register values. */
93static const int da9062_buck_a_limits[] = {
94 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
95 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
96};
97
98/* Current limits array (in uA) for BUCK2.
99 Entry indexes corresponds to register values. */
100static const int da9062_buck_b_limits[] = {
101 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
102 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
103};
104
105static int da9062_set_current_limit(struct regulator_dev *rdev,
106 int min_ua, int max_ua)
107{
108 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
109 const struct da9062_regulator_info *rinfo = regl->info;
110 int n, tval;
111
112 for (n = 0; n < rinfo->n_current_limits; n++) {
113 tval = rinfo->current_limits[n];
114 if (tval >= min_ua && tval <= max_ua)
115 return regmap_field_write(regl->ilimit, n);
116 }
117
118 return -EINVAL;
119}
120
121static int da9062_get_current_limit(struct regulator_dev *rdev)
122{
123 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
124 const struct da9062_regulator_info *rinfo = regl->info;
125 unsigned int sel;
126 int ret;
127
128 ret = regmap_field_read(regl->ilimit, &sel);
129 if (ret < 0)
130 return ret;
131
132 if (sel >= rinfo->n_current_limits)
133 sel = rinfo->n_current_limits - 1;
134
135 return rinfo->current_limits[sel];
136}
137
138static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
139{
140 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
141 unsigned val;
142
143 switch (mode) {
144 case REGULATOR_MODE_FAST:
145 val = BUCK_MODE_SYNC;
146 break;
147 case REGULATOR_MODE_NORMAL:
148 val = BUCK_MODE_AUTO;
149 break;
150 case REGULATOR_MODE_STANDBY:
151 val = BUCK_MODE_SLEEP;
152 break;
153 default:
154 return -EINVAL;
155 }
156
157 return regmap_field_write(regl->mode, val);
158}
159
160/*
161 * Bucks use single mode register field for normal operation
162 * and suspend state.
163 * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
164 */
165
166static unsigned da9062_buck_get_mode(struct regulator_dev *rdev)
167{
168 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
169 struct regmap_field *field;
170 unsigned int val, mode = 0;
171 int ret;
172
173 ret = regmap_field_read(regl->mode, &val);
174 if (ret < 0)
175 return ret;
176
177 switch (val) {
178 default:
179 case BUCK_MODE_MANUAL:
180 mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
181 /* Sleep flag bit decides the mode */
182 break;
183 case BUCK_MODE_SLEEP:
184 return REGULATOR_MODE_STANDBY;
185 case BUCK_MODE_SYNC:
186 return REGULATOR_MODE_FAST;
187 case BUCK_MODE_AUTO:
188 return REGULATOR_MODE_NORMAL;
189 }
190
191 /* Detect current regulator state */
192 ret = regmap_field_read(regl->suspend, &val);
193 if (ret < 0)
194 return 0;
195
196 /* Read regulator mode from proper register, depending on state */
197 if (val)
198 field = regl->suspend_sleep;
199 else
200 field = regl->sleep;
201
202 ret = regmap_field_read(field, &val);
203 if (ret < 0)
204 return 0;
205
206 if (val)
207 mode &= REGULATOR_MODE_STANDBY;
208 else
209 mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
210
211 return mode;
212}
213
214/*
215 * LDOs use sleep flags - one for normal and one for suspend state.
216 * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
217 */
218
219static int da9062_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
220{
221 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
222 unsigned val;
223
224 switch (mode) {
225 case REGULATOR_MODE_NORMAL:
226 val = 0;
227 break;
228 case REGULATOR_MODE_STANDBY:
229 val = 1;
230 break;
231 default:
232 return -EINVAL;
233 }
234
235 return regmap_field_write(regl->sleep, val);
236}
237
238static unsigned da9062_ldo_get_mode(struct regulator_dev *rdev)
239{
240 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
241 struct regmap_field *field;
242 int ret, val;
243
244 /* Detect current regulator state */
245 ret = regmap_field_read(regl->suspend, &val);
246 if (ret < 0)
247 return 0;
248
249 /* Read regulator mode from proper register, depending on state */
250 if (val)
251 field = regl->suspend_sleep;
252 else
253 field = regl->sleep;
254
255 ret = regmap_field_read(field, &val);
256 if (ret < 0)
257 return 0;
258
259 if (val)
260 return REGULATOR_MODE_STANDBY;
261 else
262 return REGULATOR_MODE_NORMAL;
263}
264
265static int da9062_buck_get_status(struct regulator_dev *rdev)
266{
267 int ret = regulator_is_enabled_regmap(rdev);
268
269 if (ret == 0) {
270 ret = REGULATOR_STATUS_OFF;
271 } else if (ret > 0) {
272 ret = da9062_buck_get_mode(rdev);
273 if (ret > 0)
274 ret = regulator_mode_to_status(ret);
275 else if (ret == 0)
276 ret = -EIO;
277 }
278
279 return ret;
280}
281
282static int da9062_ldo_get_status(struct regulator_dev *rdev)
283{
284 int ret = regulator_is_enabled_regmap(rdev);
285
286 if (ret == 0) {
287 ret = REGULATOR_STATUS_OFF;
288 } else if (ret > 0) {
289 ret = da9062_ldo_get_mode(rdev);
290 if (ret > 0)
291 ret = regulator_mode_to_status(ret);
292 else if (ret == 0)
293 ret = -EIO;
294 }
295
296 return ret;
297}
298
299static int da9062_set_suspend_voltage(struct regulator_dev *rdev, int uv)
300{
301 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
302 const struct da9062_regulator_info *rinfo = regl->info;
303 int ret, sel;
304
305 sel = regulator_map_voltage_linear(rdev, uv, uv);
306 if (sel < 0)
307 return sel;
308
309 sel <<= ffs(rdev->desc->vsel_mask) - 1;
310
311 ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg,
312 rdev->desc->vsel_mask, sel);
313
314 return ret;
315}
316
317static int da9062_suspend_enable(struct regulator_dev *rdev)
318{
319 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
320
321 return regmap_field_write(regl->suspend, 1);
322}
323
324static int da9062_suspend_disable(struct regulator_dev *rdev)
325{
326 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
327
328 return regmap_field_write(regl->suspend, 0);
329}
330
331static int da9062_buck_set_suspend_mode(struct regulator_dev *rdev,
332 unsigned mode)
333{
334 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
335 int val;
336
337 switch (mode) {
338 case REGULATOR_MODE_FAST:
339 val = BUCK_MODE_SYNC;
340 break;
341 case REGULATOR_MODE_NORMAL:
342 val = BUCK_MODE_AUTO;
343 break;
344 case REGULATOR_MODE_STANDBY:
345 val = BUCK_MODE_SLEEP;
346 break;
347 default:
348 return -EINVAL;
349 }
350
351 return regmap_field_write(regl->mode, val);
352}
353
354static int da9062_ldo_set_suspend_mode(struct regulator_dev *rdev,
355 unsigned mode)
356{
357 struct da9062_regulator *regl = rdev_get_drvdata(rdev);
358 unsigned val;
359
360 switch (mode) {
361 case REGULATOR_MODE_NORMAL:
362 val = 0;
363 break;
364 case REGULATOR_MODE_STANDBY:
365 val = 1;
366 break;
367 default:
368 return -EINVAL;
369 }
370
371 return regmap_field_write(regl->suspend_sleep, val);
372}
373
374static struct regulator_ops da9062_buck_ops = {
375 .enable = regulator_enable_regmap,
376 .disable = regulator_disable_regmap,
377 .is_enabled = regulator_is_enabled_regmap,
378 .get_voltage_sel = regulator_get_voltage_sel_regmap,
379 .set_voltage_sel = regulator_set_voltage_sel_regmap,
380 .list_voltage = regulator_list_voltage_linear,
381 .set_current_limit = da9062_set_current_limit,
382 .get_current_limit = da9062_get_current_limit,
383 .set_mode = da9062_buck_set_mode,
384 .get_mode = da9062_buck_get_mode,
385 .get_status = da9062_buck_get_status,
386 .set_suspend_voltage = da9062_set_suspend_voltage,
387 .set_suspend_enable = da9062_suspend_enable,
388 .set_suspend_disable = da9062_suspend_disable,
389 .set_suspend_mode = da9062_buck_set_suspend_mode,
390};
391
392static struct regulator_ops da9062_ldo_ops = {
393 .enable = regulator_enable_regmap,
394 .disable = regulator_disable_regmap,
395 .is_enabled = regulator_is_enabled_regmap,
396 .get_voltage_sel = regulator_get_voltage_sel_regmap,
397 .set_voltage_sel = regulator_set_voltage_sel_regmap,
398 .list_voltage = regulator_list_voltage_linear,
399 .set_mode = da9062_ldo_set_mode,
400 .get_mode = da9062_ldo_get_mode,
401 .get_status = da9062_ldo_get_status,
402 .set_suspend_voltage = da9062_set_suspend_voltage,
403 .set_suspend_enable = da9062_suspend_enable,
404 .set_suspend_disable = da9062_suspend_disable,
405 .set_suspend_mode = da9062_ldo_set_suspend_mode,
406};
407
408/* Regulator information */
409static const struct da9062_regulator_info local_regulator_info[] = {
410 {
411 .desc.id = DA9062_ID_BUCK1,
412 .desc.name = "DA9062 BUCK1",
413 .desc.of_match = of_match_ptr("buck1"),
414 .desc.regulators_node = of_match_ptr("regulators"),
415 .desc.ops = &da9062_buck_ops,
416 .desc.min_uV = (300) * 1000,
417 .desc.uV_step = (10) * 1000,
418 .desc.n_voltages = ((1570) - (300))/(10) + 1,
419 .current_limits = da9062_buck_a_limits,
420 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
421 .desc.enable_reg = DA9062AA_BUCK1_CONT,
422 .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
423 .desc.vsel_reg = DA9062AA_VBUCK1_A,
424 .desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
425 .desc.linear_min_sel = 0,
426 .sleep = REG_FIELD(DA9062AA_VBUCK1_A,
427 __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
428 sizeof(unsigned int) * 8 -
429 __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
430 .suspend_sleep = REG_FIELD(DA9062AA_VBUCK1_B,
431 __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
432 sizeof(unsigned int) * 8 -
433 __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
434 .suspend_vsel_reg = DA9062AA_VBUCK1_B,
435 .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
436 __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
437 sizeof(unsigned int) * 8 -
438 __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
439 .suspend = REG_FIELD(DA9062AA_DVC_1,
440 __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
441 sizeof(unsigned int) * 8 -
442 __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
443 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
444 __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
445 sizeof(unsigned int) * 8 -
446 __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
447 },
448 {
449 .desc.id = DA9062_ID_BUCK2,
450 .desc.name = "DA9062 BUCK2",
451 .desc.of_match = of_match_ptr("buck2"),
452 .desc.regulators_node = of_match_ptr("regulators"),
453 .desc.ops = &da9062_buck_ops,
454 .desc.min_uV = (300) * 1000,
455 .desc.uV_step = (10) * 1000,
456 .desc.n_voltages = ((1570) - (300))/(10) + 1,
457 .current_limits = da9062_buck_a_limits,
458 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
459 .desc.enable_reg = DA9062AA_BUCK2_CONT,
460 .desc.enable_mask = DA9062AA_BUCK2_EN_MASK,
461 .desc.vsel_reg = DA9062AA_VBUCK2_A,
462 .desc.vsel_mask = DA9062AA_VBUCK2_A_MASK,
463 .desc.linear_min_sel = 0,
464 .sleep = REG_FIELD(DA9062AA_VBUCK2_A,
465 __builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
466 sizeof(unsigned int) * 8 -
467 __builtin_clz((DA9062AA_BUCK2_SL_A_MASK)) - 1),
468 .suspend_sleep = REG_FIELD(DA9062AA_VBUCK2_B,
469 __builtin_ffs((int)DA9062AA_BUCK2_SL_B_MASK) - 1,
470 sizeof(unsigned int) * 8 -
471 __builtin_clz((DA9062AA_BUCK2_SL_B_MASK)) - 1),
472 .suspend_vsel_reg = DA9062AA_VBUCK2_B,
473 .mode = REG_FIELD(DA9062AA_BUCK2_CFG,
474 __builtin_ffs((int)DA9062AA_BUCK2_MODE_MASK) - 1,
475 sizeof(unsigned int) * 8 -
476 __builtin_clz((DA9062AA_BUCK2_MODE_MASK)) - 1),
477 .suspend = REG_FIELD(DA9062AA_DVC_1,
478 __builtin_ffs((int)DA9062AA_VBUCK2_SEL_MASK) - 1,
479 sizeof(unsigned int) * 8 -
480 __builtin_clz((DA9062AA_VBUCK2_SEL_MASK)) - 1),
481 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
482 __builtin_ffs((int)DA9062AA_BUCK2_ILIM_MASK) - 1,
483 sizeof(unsigned int) * 8 -
484 __builtin_clz((DA9062AA_BUCK2_ILIM_MASK)) - 1),
485 },
486 {
487 .desc.id = DA9062_ID_BUCK3,
488 .desc.name = "DA9062 BUCK3",
489 .desc.of_match = of_match_ptr("buck3"),
490 .desc.regulators_node = of_match_ptr("regulators"),
491 .desc.ops = &da9062_buck_ops,
492 .desc.min_uV = (800) * 1000,
493 .desc.uV_step = (20) * 1000,
494 .desc.n_voltages = ((3340) - (800))/(20) + 1,
495 .current_limits = da9062_buck_b_limits,
496 .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
497 .desc.enable_reg = DA9062AA_BUCK3_CONT,
498 .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
499 .desc.vsel_reg = DA9062AA_VBUCK3_A,
500 .desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
501 .desc.linear_min_sel = 0,
502 .sleep = REG_FIELD(DA9062AA_VBUCK3_A,
503 __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
504 sizeof(unsigned int) * 8 -
505 __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
506 .suspend_sleep = REG_FIELD(DA9062AA_VBUCK3_B,
507 __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
508 sizeof(unsigned int) * 8 -
509 __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
510 .suspend_vsel_reg = DA9062AA_VBUCK3_B,
511 .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
512 __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
513 sizeof(unsigned int) * 8 -
514 __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
515 .suspend = REG_FIELD(DA9062AA_DVC_1,
516 __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
517 sizeof(unsigned int) * 8 -
518 __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
519 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
520 __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
521 sizeof(unsigned int) * 8 -
522 __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
523 },
524 {
525 .desc.id = DA9062_ID_BUCK4,
526 .desc.name = "DA9062 BUCK4",
527 .desc.of_match = of_match_ptr("buck4"),
528 .desc.regulators_node = of_match_ptr("regulators"),
529 .desc.ops = &da9062_buck_ops,
530 .desc.min_uV = (530) * 1000,
531 .desc.uV_step = (10) * 1000,
532 .desc.n_voltages = ((1800) - (530))/(10) + 1,
533 .current_limits = da9062_buck_a_limits,
534 .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
535 .desc.enable_reg = DA9062AA_BUCK4_CONT,
536 .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
537 .desc.vsel_reg = DA9062AA_VBUCK4_A,
538 .desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
539 .desc.linear_min_sel = 0,
540 .sleep = REG_FIELD(DA9062AA_VBUCK4_A,
541 __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
542 sizeof(unsigned int) * 8 -
543 __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
544 .suspend_sleep = REG_FIELD(DA9062AA_VBUCK4_B,
545 __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
546 sizeof(unsigned int) * 8 -
547 __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
548 .suspend_vsel_reg = DA9062AA_VBUCK4_B,
549 .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
550 __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
551 sizeof(unsigned int) * 8 -
552 __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
553 .suspend = REG_FIELD(DA9062AA_DVC_1,
554 __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
555 sizeof(unsigned int) * 8 -
556 __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
557 .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
558 __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
559 sizeof(unsigned int) * 8 -
560 __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
561 },
562 {
563 .desc.id = DA9062_ID_LDO1,
564 .desc.name = "DA9062 LDO1",
565 .desc.of_match = of_match_ptr("ldo1"),
566 .desc.regulators_node = of_match_ptr("regulators"),
567 .desc.ops = &da9062_ldo_ops,
568 .desc.min_uV = (900) * 1000,
569 .desc.uV_step = (50) * 1000,
570 .desc.n_voltages = ((3600) - (900))/(50) + 1,
571 .desc.enable_reg = DA9062AA_LDO1_CONT,
572 .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
573 .desc.vsel_reg = DA9062AA_VLDO1_A,
574 .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
575 .desc.linear_min_sel = 0,
576 .sleep = REG_FIELD(DA9062AA_VLDO1_A,
577 __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
578 sizeof(unsigned int) * 8 -
579 __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
580 .suspend_sleep = REG_FIELD(DA9062AA_VLDO1_B,
581 __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
582 sizeof(unsigned int) * 8 -
583 __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
584 .suspend_vsel_reg = DA9062AA_VLDO1_B,
585 .suspend = REG_FIELD(DA9062AA_DVC_1,
586 __builtin_ffs((int)DA9062AA_VLDO1_SEL_MASK) - 1,
587 sizeof(unsigned int) * 8 -
588 __builtin_clz((DA9062AA_VLDO1_SEL_MASK)) - 1),
589 .oc_event = REG_FIELD(DA9062AA_STATUS_D,
590 __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
591 sizeof(unsigned int) * 8 -
592 __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
593 },
594 {
595 .desc.id = DA9062_ID_LDO2,
596 .desc.name = "DA9062 LDO2",
597 .desc.of_match = of_match_ptr("ldo2"),
598 .desc.regulators_node = of_match_ptr("regulators"),
599 .desc.ops = &da9062_ldo_ops,
600 .desc.min_uV = (900) * 1000,
601 .desc.uV_step = (50) * 1000,
602 .desc.n_voltages = ((3600) - (600))/(50) + 1,
603 .desc.enable_reg = DA9062AA_LDO2_CONT,
604 .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
605 .desc.vsel_reg = DA9062AA_VLDO2_A,
606 .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
607 .desc.linear_min_sel = 0,
608 .sleep = REG_FIELD(DA9062AA_VLDO2_A,
609 __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
610 sizeof(unsigned int) * 8 -
611 __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
612 .suspend_sleep = REG_FIELD(DA9062AA_VLDO2_B,
613 __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
614 sizeof(unsigned int) * 8 -
615 __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
616 .suspend_vsel_reg = DA9062AA_VLDO2_B,
617 .suspend = REG_FIELD(DA9062AA_DVC_1,
618 __builtin_ffs((int)DA9062AA_VLDO2_SEL_MASK) - 1,
619 sizeof(unsigned int) * 8 -
620 __builtin_clz((DA9062AA_VLDO2_SEL_MASK)) - 1),
621 .oc_event = REG_FIELD(DA9062AA_STATUS_D,
622 __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
623 sizeof(unsigned int) * 8 -
624 __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
625 },
626 {
627 .desc.id = DA9062_ID_LDO3,
628 .desc.name = "DA9062 LDO3",
629 .desc.of_match = of_match_ptr("ldo3"),
630 .desc.regulators_node = of_match_ptr("regulators"),
631 .desc.ops = &da9062_ldo_ops,
632 .desc.min_uV = (900) * 1000,
633 .desc.uV_step = (50) * 1000,
634 .desc.n_voltages = ((3600) - (900))/(50) + 1,
635 .desc.enable_reg = DA9062AA_LDO3_CONT,
636 .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
637 .desc.vsel_reg = DA9062AA_VLDO3_A,
638 .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
639 .desc.linear_min_sel = 0,
640 .sleep = REG_FIELD(DA9062AA_VLDO3_A,
641 __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
642 sizeof(unsigned int) * 8 -
643 __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
644 .suspend_sleep = REG_FIELD(DA9062AA_VLDO3_B,
645 __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
646 sizeof(unsigned int) * 8 -
647 __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
648 .suspend_vsel_reg = DA9062AA_VLDO3_B,
649 .suspend = REG_FIELD(DA9062AA_DVC_1,
650 __builtin_ffs((int)DA9062AA_VLDO3_SEL_MASK) - 1,
651 sizeof(unsigned int) * 8 -
652 __builtin_clz((DA9062AA_VLDO3_SEL_MASK)) - 1),
653 .oc_event = REG_FIELD(DA9062AA_STATUS_D,
654 __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
655 sizeof(unsigned int) * 8 -
656 __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
657 },
658 {
659 .desc.id = DA9062_ID_LDO4,
660 .desc.name = "DA9062 LDO4",
661 .desc.of_match = of_match_ptr("ldo4"),
662 .desc.regulators_node = of_match_ptr("regulators"),
663 .desc.ops = &da9062_ldo_ops,
664 .desc.min_uV = (900) * 1000,
665 .desc.uV_step = (50) * 1000,
666 .desc.n_voltages = ((3600) - (900))/(50) + 1,
667 .desc.enable_reg = DA9062AA_LDO4_CONT,
668 .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
669 .desc.vsel_reg = DA9062AA_VLDO4_A,
670 .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
671 .desc.linear_min_sel = 0,
672 .sleep = REG_FIELD(DA9062AA_VLDO4_A,
673 __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
674 sizeof(unsigned int) * 8 -
675 __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
676 .suspend_sleep = REG_FIELD(DA9062AA_VLDO4_B,
677 __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
678 sizeof(unsigned int) * 8 -
679 __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
680 .suspend_vsel_reg = DA9062AA_VLDO4_B,
681 .suspend = REG_FIELD(DA9062AA_DVC_1,
682 __builtin_ffs((int)DA9062AA_VLDO4_SEL_MASK) - 1,
683 sizeof(unsigned int) * 8 -
684 __builtin_clz((DA9062AA_VLDO4_SEL_MASK)) - 1),
685 .oc_event = REG_FIELD(DA9062AA_STATUS_D,
686 __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
687 sizeof(unsigned int) * 8 -
688 __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
689 },
690};
691
692/* Regulator interrupt handlers */
693static irqreturn_t da9062_ldo_lim_event(int irq, void *data)
694{
695 struct da9062_regulators *regulators = data;
696 struct da9062 *hw = regulators->regulator[0].hw;
697 struct da9062_regulator *regl;
698 int handled = IRQ_NONE;
699 int bits, i, ret;
700
701 ret = regmap_read(hw->regmap, DA9062AA_STATUS_D, &bits);
702 if (ret < 0) {
703 dev_err(hw->dev,
704 "Failed to read LDO overcurrent indicator\n");
705 goto ldo_lim_error;
706 }
707
708 for (i = regulators->n_regulators - 1; i >= 0; i--) {
709 regl = &regulators->regulator[i];
710 if (regl->info->oc_event.reg != DA9062AA_STATUS_D)
711 continue;
712
713 if (BIT(regl->info->oc_event.lsb) & bits) {
714 regulator_notifier_call_chain(regl->rdev,
715 REGULATOR_EVENT_OVER_CURRENT, NULL);
716 handled = IRQ_HANDLED;
717 }
718 }
719
720ldo_lim_error:
721 return handled;
722}
723
724static int da9062_regulator_probe(struct platform_device *pdev)
725{
726 struct da9062 *chip = dev_get_drvdata(pdev->dev.parent);
727 struct da9062_regulators *regulators;
728 struct da9062_regulator *regl;
729 struct regulator_config config = { };
730 int irq, n, ret;
731 size_t size;
732
733 /* Allocate memory required by usable regulators */
734 size = sizeof(struct da9062_regulators) +
735 DA9062_MAX_REGULATORS * sizeof(struct da9062_regulator);
736 regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
737 if (!regulators)
738 return -ENOMEM;
739
740 regulators->n_regulators = DA9062_MAX_REGULATORS;
741 platform_set_drvdata(pdev, regulators);
742
743 n = 0;
744 while (n < regulators->n_regulators) {
745 /* Initialise regulator structure */
746 regl = &regulators->regulator[n];
747 regl->hw = chip;
748 regl->info = &local_regulator_info[n];
749 regl->desc = regl->info->desc;
750 regl->desc.type = REGULATOR_VOLTAGE;
751 regl->desc.owner = THIS_MODULE;
752
753 if (regl->info->mode.reg)
754 regl->mode = devm_regmap_field_alloc(
755 &pdev->dev,
756 chip->regmap,
757 regl->info->mode);
758 if (regl->info->suspend.reg)
759 regl->suspend = devm_regmap_field_alloc(
760 &pdev->dev,
761 chip->regmap,
762 regl->info->suspend);
763 if (regl->info->sleep.reg)
764 regl->sleep = devm_regmap_field_alloc(
765 &pdev->dev,
766 chip->regmap,
767 regl->info->sleep);
768 if (regl->info->suspend_sleep.reg)
769 regl->suspend_sleep = devm_regmap_field_alloc(
770 &pdev->dev,
771 chip->regmap,
772 regl->info->suspend_sleep);
773 if (regl->info->ilimit.reg)
774 regl->ilimit = devm_regmap_field_alloc(
775 &pdev->dev,
776 chip->regmap,
777 regl->info->ilimit);
778
779 /* Register regulator */
780 memset(&config, 0, sizeof(config));
781 config.dev = chip->dev;
782 config.driver_data = regl;
783 config.regmap = chip->regmap;
784
785 regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc,
786 &config);
787 if (IS_ERR(regl->rdev)) {
788 dev_err(&pdev->dev,
789 "Failed to register %s regulator\n",
790 regl->desc.name);
791 return PTR_ERR(regl->rdev);
792 }
793
794 n++;
795 }
796
797 /* LDOs overcurrent event support */
798 irq = platform_get_irq_byname(pdev, "LDO_LIM");
799 if (irq < 0) {
800 dev_err(&pdev->dev, "Failed to get IRQ.\n");
801 return irq;
802 }
803 regulators->irq_ldo_lim = irq;
804
805 ret = devm_request_threaded_irq(&pdev->dev, irq,
806 NULL, da9062_ldo_lim_event,
807 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
808 "LDO_LIM", regulators);
809 if (ret) {
810 dev_warn(&pdev->dev,
811 "Failed to request LDO_LIM IRQ.\n");
812 regulators->irq_ldo_lim = -ENXIO;
813 }
814
815 return 0;
816}
817
818static struct platform_driver da9062_regulator_driver = {
819 .driver = {
820 .name = "da9062-regulators",
821 .owner = THIS_MODULE,
822 },
823 .probe = da9062_regulator_probe,
824};
825
826static int __init da9062_regulator_init(void)
827{
828 return platform_driver_register(&da9062_regulator_driver);
829}
830subsys_initcall(da9062_regulator_init);
831
832static void __exit da9062_regulator_cleanup(void)
833{
834 platform_driver_unregister(&da9062_regulator_driver);
835}
836module_exit(da9062_regulator_cleanup);
837
838/* Module information */
839MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
840MODULE_DESCRIPTION("REGULATOR device driver for Dialog DA9062");
841MODULE_LICENSE("GPL");
842MODULE_ALIAS("platform:da9062-regulators");
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 31c2c593ae0b..aed1ad3dc964 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -117,9 +117,6 @@ struct da9063_regulator {
117 117
118/* Encapsulates all information for the regulators driver */ 118/* Encapsulates all information for the regulators driver */
119struct da9063_regulators { 119struct da9063_regulators {
120 int irq_ldo_lim;
121 int irq_uvov;
122
123 unsigned n_regulators; 120 unsigned n_regulators;
124 /* Array size to be defined during init. Keep at end. */ 121 /* Array size to be defined during init. Keep at end. */
125 struct da9063_regulator regulator[0]; 122 struct da9063_regulator regulator[0];
@@ -867,35 +864,23 @@ static int da9063_regulator_probe(struct platform_device *pdev)
867 return irq; 864 return irq;
868 } 865 }
869 866
870 ret = request_threaded_irq(irq, 867 ret = devm_request_threaded_irq(&pdev->dev, irq,
871 NULL, da9063_ldo_lim_event, 868 NULL, da9063_ldo_lim_event,
872 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 869 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
873 "LDO_LIM", regulators); 870 "LDO_LIM", regulators);
874 if (ret) { 871 if (ret) {
875 dev_err(&pdev->dev, 872 dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ.\n");
876 "Failed to request LDO_LIM IRQ.\n"); 873 return ret;
877 regulators->irq_ldo_lim = -ENXIO;
878 } 874 }
879 875
880 return 0; 876 return 0;
881} 877}
882 878
883static int da9063_regulator_remove(struct platform_device *pdev)
884{
885 struct da9063_regulators *regulators = platform_get_drvdata(pdev);
886
887 free_irq(regulators->irq_ldo_lim, regulators);
888 free_irq(regulators->irq_uvov, regulators);
889
890 return 0;
891}
892
893static struct platform_driver da9063_regulator_driver = { 879static struct platform_driver da9063_regulator_driver = {
894 .driver = { 880 .driver = {
895 .name = DA9063_DRVNAME_REGULATORS, 881 .name = DA9063_DRVNAME_REGULATORS,
896 }, 882 },
897 .probe = da9063_regulator_probe, 883 .probe = da9063_regulator_probe,
898 .remove = da9063_regulator_remove,
899}; 884};
900 885
901static int __init da9063_regulator_init(void) 886static int __init da9063_regulator_init(void)
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 3c25db89a021..42865681c00b 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -182,6 +182,7 @@ static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp)
182static struct regulator_ops fan53555_regulator_ops = { 182static struct regulator_ops fan53555_regulator_ops = {
183 .set_voltage_sel = regulator_set_voltage_sel_regmap, 183 .set_voltage_sel = regulator_set_voltage_sel_regmap,
184 .get_voltage_sel = regulator_get_voltage_sel_regmap, 184 .get_voltage_sel = regulator_get_voltage_sel_regmap,
185 .set_voltage_time_sel = regulator_set_voltage_time_sel,
185 .map_voltage = regulator_map_voltage_linear, 186 .map_voltage = regulator_map_voltage_linear,
186 .list_voltage = regulator_list_voltage_linear, 187 .list_voltage = regulator_list_voltage_linear,
187 .set_suspend_voltage = fan53555_set_suspend_voltage, 188 .set_suspend_voltage = fan53555_set_suspend_voltage,
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index cbc39096c78d..3bbb32680a94 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -275,7 +275,7 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
275EXPORT_SYMBOL_GPL(regulator_map_voltage_linear); 275EXPORT_SYMBOL_GPL(regulator_map_voltage_linear);
276 276
277/** 277/**
278 * regulator_map_voltage_linear - map_voltage() for multiple linear ranges 278 * regulator_map_voltage_linear_range - map_voltage() for multiple linear ranges
279 * 279 *
280 * @rdev: Regulator to operate on 280 * @rdev: Regulator to operate on
281 * @min_uV: Lower bound for voltage 281 * @min_uV: Lower bound for voltage
diff --git a/drivers/regulator/lp8755.c b/drivers/regulator/lp8755.c
index 4a415d4ee463..d6773da925ba 100644
--- a/drivers/regulator/lp8755.c
+++ b/drivers/regulator/lp8755.c
@@ -419,20 +419,16 @@ static int lp8755_int_config(struct lp8755_chip *pchip)
419 } 419 }
420 420
421 ret = lp8755_read(pchip, 0x0F, &regval); 421 ret = lp8755_read(pchip, 0x0F, &regval);
422 if (ret < 0) 422 if (ret < 0) {
423 goto err_i2c; 423 dev_err(pchip->dev, "i2c acceess error %s\n", __func__);
424 pchip->irqmask = regval;
425 ret = request_threaded_irq(pchip->irq, NULL, lp8755_irq_handler,
426 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
427 "lp8755-irq", pchip);
428 if (ret)
429 return ret; 424 return ret;
425 }
430 426
431 return ret; 427 pchip->irqmask = regval;
432 428 return devm_request_threaded_irq(pchip->dev, pchip->irq, NULL,
433err_i2c: 429 lp8755_irq_handler,
434 dev_err(pchip->dev, "i2c acceess error %s\n", __func__); 430 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
435 return ret; 431 "lp8755-irq", pchip);
436} 432}
437 433
438static const struct regmap_config lp8755_regmap = { 434static const struct regmap_config lp8755_regmap = {
@@ -514,9 +510,6 @@ static int lp8755_remove(struct i2c_client *client)
514 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) 510 for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
515 lp8755_write(pchip, icnt, 0x00); 511 lp8755_write(pchip, icnt, 0x00);
516 512
517 if (pchip->irq != 0)
518 free_irq(pchip->irq, pchip);
519
520 return 0; 513 return 0;
521} 514}
522 515
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c
index b3678d289619..b2daa6641417 100644
--- a/drivers/regulator/max14577.c
+++ b/drivers/regulator/max14577.c
@@ -100,31 +100,34 @@ static struct regulator_ops max14577_charger_ops = {
100 .set_current_limit = max14577_reg_set_current_limit, 100 .set_current_limit = max14577_reg_set_current_limit,
101}; 101};
102 102
103#define MAX14577_SAFEOUT_REG { \
104 .name = "SAFEOUT", \
105 .of_match = of_match_ptr("SAFEOUT"), \
106 .regulators_node = of_match_ptr("regulators"), \
107 .id = MAX14577_SAFEOUT, \
108 .ops = &max14577_safeout_ops, \
109 .type = REGULATOR_VOLTAGE, \
110 .owner = THIS_MODULE, \
111 .n_voltages = 1, \
112 .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE, \
113 .enable_reg = MAX14577_REG_CONTROL2, \
114 .enable_mask = CTRL2_SFOUTORD_MASK, \
115}
116#define MAX14577_CHARGER_REG { \
117 .name = "CHARGER", \
118 .of_match = of_match_ptr("CHARGER"), \
119 .regulators_node = of_match_ptr("regulators"), \
120 .id = MAX14577_CHARGER, \
121 .ops = &max14577_charger_ops, \
122 .type = REGULATOR_CURRENT, \
123 .owner = THIS_MODULE, \
124 .enable_reg = MAX14577_CHG_REG_CHG_CTRL2, \
125 .enable_mask = CHGCTRL2_MBCHOSTEN_MASK, \
126}
127
103static const struct regulator_desc max14577_supported_regulators[] = { 128static const struct regulator_desc max14577_supported_regulators[] = {
104 [MAX14577_SAFEOUT] = { 129 [MAX14577_SAFEOUT] = MAX14577_SAFEOUT_REG,
105 .name = "SAFEOUT", 130 [MAX14577_CHARGER] = MAX14577_CHARGER_REG,
106 .of_match = of_match_ptr("SAFEOUT"),
107 .regulators_node = of_match_ptr("regulators"),
108 .id = MAX14577_SAFEOUT,
109 .ops = &max14577_safeout_ops,
110 .type = REGULATOR_VOLTAGE,
111 .owner = THIS_MODULE,
112 .n_voltages = 1,
113 .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE,
114 .enable_reg = MAX14577_REG_CONTROL2,
115 .enable_mask = CTRL2_SFOUTORD_MASK,
116 },
117 [MAX14577_CHARGER] = {
118 .name = "CHARGER",
119 .of_match = of_match_ptr("CHARGER"),
120 .regulators_node = of_match_ptr("regulators"),
121 .id = MAX14577_CHARGER,
122 .ops = &max14577_charger_ops,
123 .type = REGULATOR_CURRENT,
124 .owner = THIS_MODULE,
125 .enable_reg = MAX14577_CHG_REG_CHG_CTRL2,
126 .enable_mask = CHGCTRL2_MBCHOSTEN_MASK,
127 },
128}; 131};
129 132
130static struct regulator_ops max77836_ldo_ops = { 133static struct regulator_ops max77836_ldo_ops = {
@@ -138,63 +141,28 @@ static struct regulator_ops max77836_ldo_ops = {
138 /* TODO: add .set_suspend_mode */ 141 /* TODO: add .set_suspend_mode */
139}; 142};
140 143
144#define MAX77836_LDO_REG(num) { \
145 .name = "LDO" # num, \
146 .of_match = of_match_ptr("LDO" # num), \
147 .regulators_node = of_match_ptr("regulators"), \
148 .id = MAX77836_LDO ## num, \
149 .ops = &max77836_ldo_ops, \
150 .type = REGULATOR_VOLTAGE, \
151 .owner = THIS_MODULE, \
152 .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM, \
153 .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN, \
154 .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP, \
155 .enable_reg = MAX77836_LDO_REG_CNFG1_LDO ## num, \
156 .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK, \
157 .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO ## num, \
158 .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK, \
159}
160
141static const struct regulator_desc max77836_supported_regulators[] = { 161static const struct regulator_desc max77836_supported_regulators[] = {
142 [MAX14577_SAFEOUT] = { 162 [MAX14577_SAFEOUT] = MAX14577_SAFEOUT_REG,
143 .name = "SAFEOUT", 163 [MAX14577_CHARGER] = MAX14577_CHARGER_REG,
144 .of_match = of_match_ptr("SAFEOUT"), 164 [MAX77836_LDO1] = MAX77836_LDO_REG(1),
145 .regulators_node = of_match_ptr("regulators"), 165 [MAX77836_LDO2] = MAX77836_LDO_REG(2),
146 .id = MAX14577_SAFEOUT,
147 .ops = &max14577_safeout_ops,
148 .type = REGULATOR_VOLTAGE,
149 .owner = THIS_MODULE,
150 .n_voltages = 1,
151 .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE,
152 .enable_reg = MAX14577_REG_CONTROL2,
153 .enable_mask = CTRL2_SFOUTORD_MASK,
154 },
155 [MAX14577_CHARGER] = {
156 .name = "CHARGER",
157 .of_match = of_match_ptr("CHARGER"),
158 .regulators_node = of_match_ptr("regulators"),
159 .id = MAX14577_CHARGER,
160 .ops = &max14577_charger_ops,
161 .type = REGULATOR_CURRENT,
162 .owner = THIS_MODULE,
163 .enable_reg = MAX14577_CHG_REG_CHG_CTRL2,
164 .enable_mask = CHGCTRL2_MBCHOSTEN_MASK,
165 },
166 [MAX77836_LDO1] = {
167 .name = "LDO1",
168 .of_match = of_match_ptr("LDO1"),
169 .regulators_node = of_match_ptr("regulators"),
170 .id = MAX77836_LDO1,
171 .ops = &max77836_ldo_ops,
172 .type = REGULATOR_VOLTAGE,
173 .owner = THIS_MODULE,
174 .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM,
175 .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN,
176 .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP,
177 .enable_reg = MAX77836_LDO_REG_CNFG1_LDO1,
178 .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK,
179 .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO1,
180 .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK,
181 },
182 [MAX77836_LDO2] = {
183 .name = "LDO2",
184 .of_match = of_match_ptr("LDO2"),
185 .regulators_node = of_match_ptr("regulators"),
186 .id = MAX77836_LDO2,
187 .ops = &max77836_ldo_ops,
188 .type = REGULATOR_VOLTAGE,
189 .owner = THIS_MODULE,
190 .n_voltages = MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM,
191 .min_uV = MAX77836_REGULATOR_LDO_VOLTAGE_MIN,
192 .uV_step = MAX77836_REGULATOR_LDO_VOLTAGE_STEP,
193 .enable_reg = MAX77836_LDO_REG_CNFG1_LDO2,
194 .enable_mask = MAX77836_CNFG1_LDO_PWRMD_MASK,
195 .vsel_reg = MAX77836_LDO_REG_CNFG1_LDO2,
196 .vsel_mask = MAX77836_CNFG1_LDO_TV_MASK,
197 },
198}; 166};
199 167
200#ifdef CONFIG_OF 168#ifdef CONFIG_OF
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index 15fb1416bfbd..17ccf365a9c0 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -2,7 +2,7 @@
2 * max77686.c - Regulator driver for the Maxim 77686 2 * max77686.c - Regulator driver for the Maxim 77686
3 * 3 *
4 * Copyright (C) 2012 Samsung Electronics 4 * Copyright (C) 2012 Samsung Electronics
5 * Chiwoong Byun <woong.byun@smasung.com> 5 * Chiwoong Byun <woong.byun@samsung.com>
6 * Jonghwa Lee <jonghwa3.lee@samsung.com> 6 * Jonghwa Lee <jonghwa3.lee@samsung.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
@@ -88,7 +88,7 @@ enum max77686_ramp_rate {
88}; 88};
89 89
90struct max77686_data { 90struct max77686_data {
91 u64 gpio_enabled:MAX77686_REGULATORS; 91 DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
92 92
93 /* Array indexed by regulator id */ 93 /* Array indexed by regulator id */
94 unsigned int opmode[MAX77686_REGULATORS]; 94 unsigned int opmode[MAX77686_REGULATORS];
@@ -121,7 +121,7 @@ static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
121 case MAX77686_BUCK8: 121 case MAX77686_BUCK8:
122 case MAX77686_BUCK9: 122 case MAX77686_BUCK9:
123 case MAX77686_LDO20 ... MAX77686_LDO22: 123 case MAX77686_LDO20 ... MAX77686_LDO22:
124 if (max77686->gpio_enabled & (1 << id)) 124 if (test_bit(id, max77686->gpio_enabled))
125 return MAX77686_GPIO_CONTROL; 125 return MAX77686_GPIO_CONTROL;
126 } 126 }
127 127
@@ -277,7 +277,7 @@ static int max77686_of_parse_cb(struct device_node *np,
277 } 277 }
278 278
279 if (gpio_is_valid(config->ena_gpio)) { 279 if (gpio_is_valid(config->ena_gpio)) {
280 max77686->gpio_enabled |= (1 << desc->id); 280 set_bit(desc->id, max77686->gpio_enabled);
281 281
282 return regmap_update_bits(config->regmap, desc->enable_reg, 282 return regmap_update_bits(config->regmap, desc->enable_reg,
283 desc->enable_mask, 283 desc->enable_mask,
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index 9665a488e2f1..38722c8311a5 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -35,20 +35,6 @@
35 35
36#define CHGIN_ILIM_STEP_20mA 20000 36#define CHGIN_ILIM_STEP_20mA 20000
37 37
38/* CHARGER regulator ops */
39/* CHARGER regulator uses two bits for enabling */
40static int max77693_chg_is_enabled(struct regulator_dev *rdev)
41{
42 int ret;
43 unsigned int val;
44
45 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
46 if (ret)
47 return ret;
48
49 return (val & rdev->desc->enable_mask) == rdev->desc->enable_mask;
50}
51
52/* 38/*
53 * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA 39 * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
54 * 0x00, 0x01, 0x2, 0x03 = 60 mA 40 * 0x00, 0x01, 0x2, 0x03 = 60 mA
@@ -118,7 +104,7 @@ static struct regulator_ops max77693_safeout_ops = {
118}; 104};
119 105
120static struct regulator_ops max77693_charger_ops = { 106static struct regulator_ops max77693_charger_ops = {
121 .is_enabled = max77693_chg_is_enabled, 107 .is_enabled = regulator_is_enabled_regmap,
122 .enable = regulator_enable_regmap, 108 .enable = regulator_enable_regmap,
123 .disable = regulator_disable_regmap, 109 .disable = regulator_disable_regmap,
124 .get_current_limit = max77693_chg_get_current_limit, 110 .get_current_limit = max77693_chg_get_current_limit,
@@ -155,6 +141,7 @@ static const struct regulator_desc regulators[] = {
155 .enable_reg = MAX77693_CHG_REG_CHG_CNFG_00, 141 .enable_reg = MAX77693_CHG_REG_CHG_CNFG_00,
156 .enable_mask = CHG_CNFG_00_CHG_MASK | 142 .enable_mask = CHG_CNFG_00_CHG_MASK |
157 CHG_CNFG_00_BUCK_MASK, 143 CHG_CNFG_00_BUCK_MASK,
144 .enable_val = CHG_CNFG_00_CHG_MASK | CHG_CNFG_00_BUCK_MASK,
158 }, 145 },
159}; 146};
160 147
diff --git a/drivers/regulator/max77843.c b/drivers/regulator/max77843.c
index c132ef527cdd..f4fd0d3cfa6e 100644
--- a/drivers/regulator/max77843.c
+++ b/drivers/regulator/max77843.c
@@ -33,21 +33,6 @@ static const unsigned int max77843_safeout_voltage_table[] = {
33 3300000, 33 3300000,
34}; 34};
35 35
36static int max77843_reg_is_enabled(struct regulator_dev *rdev)
37{
38 struct regmap *regmap = rdev->regmap;
39 int ret;
40 unsigned int reg;
41
42 ret = regmap_read(regmap, rdev->desc->enable_reg, &reg);
43 if (ret) {
44 dev_err(&rdev->dev, "Fialed to read charger register\n");
45 return ret;
46 }
47
48 return (reg & rdev->desc->enable_mask) == rdev->desc->enable_mask;
49}
50
51static int max77843_reg_get_current_limit(struct regulator_dev *rdev) 36static int max77843_reg_get_current_limit(struct regulator_dev *rdev)
52{ 37{
53 struct regmap *regmap = rdev->regmap; 38 struct regmap *regmap = rdev->regmap;
@@ -96,7 +81,7 @@ static int max77843_reg_set_current_limit(struct regulator_dev *rdev,
96} 81}
97 82
98static struct regulator_ops max77843_charger_ops = { 83static struct regulator_ops max77843_charger_ops = {
99 .is_enabled = max77843_reg_is_enabled, 84 .is_enabled = regulator_is_enabled_regmap,
100 .enable = regulator_enable_regmap, 85 .enable = regulator_enable_regmap,
101 .disable = regulator_disable_regmap, 86 .disable = regulator_disable_regmap,
102 .get_current_limit = max77843_reg_get_current_limit, 87 .get_current_limit = max77843_reg_get_current_limit,
@@ -112,37 +97,25 @@ static struct regulator_ops max77843_regulator_ops = {
112 .set_voltage_sel = regulator_set_voltage_sel_regmap, 97 .set_voltage_sel = regulator_set_voltage_sel_regmap,
113}; 98};
114 99
100#define MAX77843_SAFEOUT(num) { \
101 .name = "SAFEOUT" # num, \
102 .id = MAX77843_SAFEOUT ## num, \
103 .ops = &max77843_regulator_ops, \
104 .of_match = of_match_ptr("SAFEOUT" # num), \
105 .regulators_node = of_match_ptr("regulators"), \
106 .type = REGULATOR_VOLTAGE, \
107 .owner = THIS_MODULE, \
108 .n_voltages = ARRAY_SIZE(max77843_safeout_voltage_table), \
109 .volt_table = max77843_safeout_voltage_table, \
110 .enable_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \
111 .enable_mask = MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT ## num, \
112 .vsel_reg = MAX77843_SYS_REG_SAFEOUTCTRL, \
113 .vsel_mask = MAX77843_REG_SAFEOUTCTRL_SAFEOUT ## num ## _MASK, \
114}
115
115static const struct regulator_desc max77843_supported_regulators[] = { 116static const struct regulator_desc max77843_supported_regulators[] = {
116 [MAX77843_SAFEOUT1] = { 117 [MAX77843_SAFEOUT1] = MAX77843_SAFEOUT(1),
117 .name = "SAFEOUT1", 118 [MAX77843_SAFEOUT2] = MAX77843_SAFEOUT(2),
118 .id = MAX77843_SAFEOUT1,
119 .ops = &max77843_regulator_ops,
120 .of_match = of_match_ptr("SAFEOUT1"),
121 .regulators_node = of_match_ptr("regulators"),
122 .type = REGULATOR_VOLTAGE,
123 .owner = THIS_MODULE,
124 .n_voltages = ARRAY_SIZE(max77843_safeout_voltage_table),
125 .volt_table = max77843_safeout_voltage_table,
126 .enable_reg = MAX77843_SYS_REG_SAFEOUTCTRL,
127 .enable_mask = MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT1,
128 .vsel_reg = MAX77843_SYS_REG_SAFEOUTCTRL,
129 .vsel_mask = MAX77843_REG_SAFEOUTCTRL_SAFEOUT1_MASK,
130 },
131 [MAX77843_SAFEOUT2] = {
132 .name = "SAFEOUT2",
133 .id = MAX77843_SAFEOUT2,
134 .ops = &max77843_regulator_ops,
135 .of_match = of_match_ptr("SAFEOUT2"),
136 .regulators_node = of_match_ptr("regulators"),
137 .type = REGULATOR_VOLTAGE,
138 .owner = THIS_MODULE,
139 .n_voltages = ARRAY_SIZE(max77843_safeout_voltage_table),
140 .volt_table = max77843_safeout_voltage_table,
141 .enable_reg = MAX77843_SYS_REG_SAFEOUTCTRL,
142 .enable_mask = MAX77843_REG_SAFEOUTCTRL_ENSAFEOUT2,
143 .vsel_reg = MAX77843_SYS_REG_SAFEOUTCTRL,
144 .vsel_mask = MAX77843_REG_SAFEOUTCTRL_SAFEOUT2_MASK,
145 },
146 [MAX77843_CHARGER] = { 119 [MAX77843_CHARGER] = {
147 .name = "CHARGER", 120 .name = "CHARGER",
148 .id = MAX77843_CHARGER, 121 .id = MAX77843_CHARGER,
@@ -152,7 +125,8 @@ static const struct regulator_desc max77843_supported_regulators[] = {
152 .type = REGULATOR_CURRENT, 125 .type = REGULATOR_CURRENT,
153 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
154 .enable_reg = MAX77843_CHG_REG_CHG_CNFG_00, 127 .enable_reg = MAX77843_CHG_REG_CHG_CNFG_00,
155 .enable_mask = MAX77843_CHG_MASK, 128 .enable_mask = MAX77843_CHG_MASK | MAX77843_CHG_BUCK_MASK,
129 .enable_val = MAX77843_CHG_MASK | MAX77843_CHG_BUCK_MASK,
156 }, 130 },
157}; 131};
158 132
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index c3d55c2db593..6f2bdad8b4d8 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -27,12 +27,14 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/of_device.h>
30#include <linux/platform_device.h> 31#include <linux/platform_device.h>
31#include <linux/regulator/driver.h> 32#include <linux/regulator/driver.h>
32#include <linux/regulator/machine.h> 33#include <linux/regulator/machine.h>
33#include <linux/regulator/max8973-regulator.h> 34#include <linux/regulator/max8973-regulator.h>
34#include <linux/regulator/of_regulator.h> 35#include <linux/regulator/of_regulator.h>
35#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/of_gpio.h>
36#include <linux/i2c.h> 38#include <linux/i2c.h>
37#include <linux/slab.h> 39#include <linux/slab.h>
38#include <linux/regmap.h> 40#include <linux/regmap.h>
@@ -66,6 +68,7 @@
66#define MAX8973_RAMP_25mV_PER_US 0x1 68#define MAX8973_RAMP_25mV_PER_US 0x1
67#define MAX8973_RAMP_50mV_PER_US 0x2 69#define MAX8973_RAMP_50mV_PER_US 0x2
68#define MAX8973_RAMP_200mV_PER_US 0x3 70#define MAX8973_RAMP_200mV_PER_US 0x3
71#define MAX8973_RAMP_MASK 0x3
69 72
70/* MAX8973_CONTROL2 */ 73/* MAX8973_CONTROL2 */
71#define MAX8973_WDTMR_ENABLE BIT(6) 74#define MAX8973_WDTMR_ENABLE BIT(6)
@@ -89,19 +92,25 @@
89#define MAX8973_VOLATGE_STEP 6250 92#define MAX8973_VOLATGE_STEP 6250
90#define MAX8973_BUCK_N_VOLTAGE 0x80 93#define MAX8973_BUCK_N_VOLTAGE 0x80
91 94
95enum device_id {
96 MAX8973,
97 MAX77621
98};
99
92/* Maxim 8973 chip information */ 100/* Maxim 8973 chip information */
93struct max8973_chip { 101struct max8973_chip {
94 struct device *dev; 102 struct device *dev;
95 struct regulator_desc desc; 103 struct regulator_desc desc;
96 struct regmap *regmap; 104 struct regmap *regmap;
97 bool enable_external_control; 105 bool enable_external_control;
106 int enable_gpio;
98 int dvs_gpio; 107 int dvs_gpio;
99 int lru_index[MAX8973_MAX_VOUT_REG]; 108 int lru_index[MAX8973_MAX_VOUT_REG];
100 int curr_vout_val[MAX8973_MAX_VOUT_REG]; 109 int curr_vout_val[MAX8973_MAX_VOUT_REG];
101 int curr_vout_reg; 110 int curr_vout_reg;
102 int curr_gpio_val; 111 int curr_gpio_val;
103 bool valid_dvs_gpio;
104 struct regulator_ops ops; 112 struct regulator_ops ops;
113 enum device_id id;
105}; 114};
106 115
107/* 116/*
@@ -174,7 +183,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
174 * If gpios are available to select the VOUT register then least 183 * If gpios are available to select the VOUT register then least
175 * recently used register for new configuration. 184 * recently used register for new configuration.
176 */ 185 */
177 if (max->valid_dvs_gpio) 186 if (gpio_is_valid(max->dvs_gpio))
178 found = find_voltage_set_register(max, vsel, 187 found = find_voltage_set_register(max, vsel,
179 &vout_reg, &gpio_val); 188 &vout_reg, &gpio_val);
180 189
@@ -191,7 +200,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
191 } 200 }
192 201
193 /* Select proper VOUT register vio gpios */ 202 /* Select proper VOUT register vio gpios */
194 if (max->valid_dvs_gpio) { 203 if (gpio_is_valid(max->dvs_gpio)) {
195 gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1); 204 gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
196 max->curr_gpio_val = gpio_val; 205 max->curr_gpio_val = gpio_val;
197 } 206 }
@@ -242,12 +251,45 @@ static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev)
242 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 251 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
243} 252}
244 253
254static int max8973_set_ramp_delay(struct regulator_dev *rdev,
255 int ramp_delay)
256{
257 struct max8973_chip *max = rdev_get_drvdata(rdev);
258 unsigned int control;
259 int ret;
260 int ret_val;
261
262 /* Set ramp delay */
263 if (ramp_delay < 25000) {
264 control = MAX8973_RAMP_12mV_PER_US;
265 ret_val = 12000;
266 } else if (ramp_delay < 50000) {
267 control = MAX8973_RAMP_25mV_PER_US;
268 ret_val = 25000;
269 } else if (ramp_delay < 200000) {
270 control = MAX8973_RAMP_50mV_PER_US;
271 ret_val = 50000;
272 } else {
273 control = MAX8973_RAMP_200mV_PER_US;
274 ret_val = 200000;
275 }
276
277 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1,
278 MAX8973_RAMP_MASK, control);
279 if (ret < 0)
280 dev_err(max->dev, "register %d update failed, %d",
281 MAX8973_CONTROL1, ret);
282 return ret;
283}
284
245static const struct regulator_ops max8973_dcdc_ops = { 285static const struct regulator_ops max8973_dcdc_ops = {
246 .get_voltage_sel = max8973_dcdc_get_voltage_sel, 286 .get_voltage_sel = max8973_dcdc_get_voltage_sel,
247 .set_voltage_sel = max8973_dcdc_set_voltage_sel, 287 .set_voltage_sel = max8973_dcdc_set_voltage_sel,
248 .list_voltage = regulator_list_voltage_linear, 288 .list_voltage = regulator_list_voltage_linear,
249 .set_mode = max8973_dcdc_set_mode, 289 .set_mode = max8973_dcdc_set_mode,
250 .get_mode = max8973_dcdc_get_mode, 290 .get_mode = max8973_dcdc_get_mode,
291 .set_voltage_time_sel = regulator_set_voltage_time_sel,
292 .set_ramp_delay = max8973_set_ramp_delay,
251}; 293};
252 294
253static int max8973_init_dcdc(struct max8973_chip *max, 295static int max8973_init_dcdc(struct max8973_chip *max,
@@ -256,6 +298,29 @@ static int max8973_init_dcdc(struct max8973_chip *max,
256 int ret; 298 int ret;
257 uint8_t control1 = 0; 299 uint8_t control1 = 0;
258 uint8_t control2 = 0; 300 uint8_t control2 = 0;
301 unsigned int data;
302
303 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data);
304 if (ret < 0) {
305 dev_err(max->dev, "register %d read failed, err = %d",
306 MAX8973_CONTROL1, ret);
307 return ret;
308 }
309 control1 = data & MAX8973_RAMP_MASK;
310 switch (control1) {
311 case MAX8973_RAMP_12mV_PER_US:
312 max->desc.ramp_delay = 12000;
313 break;
314 case MAX8973_RAMP_25mV_PER_US:
315 max->desc.ramp_delay = 25000;
316 break;
317 case MAX8973_RAMP_50mV_PER_US:
318 max->desc.ramp_delay = 50000;
319 break;
320 case MAX8973_RAMP_200mV_PER_US:
321 max->desc.ramp_delay = 200000;
322 break;
323 }
259 324
260 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE) 325 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE)
261 control1 |= MAX8973_SNS_ENABLE; 326 control1 |= MAX8973_SNS_ENABLE;
@@ -266,28 +331,16 @@ static int max8973_init_dcdc(struct max8973_chip *max,
266 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE) 331 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE)
267 control1 |= MAX8973_AD_ENABLE; 332 control1 |= MAX8973_AD_ENABLE;
268 333
269 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) 334 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) {
270 control1 |= MAX8973_BIAS_ENABLE; 335 control1 |= MAX8973_BIAS_ENABLE;
336 max->desc.enable_time = 20;
337 } else {
338 max->desc.enable_time = 240;
339 }
271 340
272 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE) 341 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE)
273 control1 |= MAX8973_FREQSHIFT_9PER; 342 control1 |= MAX8973_FREQSHIFT_9PER;
274 343
275 /* Set ramp delay */
276 if (pdata->reg_init_data &&
277 pdata->reg_init_data->constraints.ramp_delay) {
278 if (pdata->reg_init_data->constraints.ramp_delay < 25000)
279 control1 |= MAX8973_RAMP_12mV_PER_US;
280 else if (pdata->reg_init_data->constraints.ramp_delay < 50000)
281 control1 |= MAX8973_RAMP_25mV_PER_US;
282 else if (pdata->reg_init_data->constraints.ramp_delay < 200000)
283 control1 |= MAX8973_RAMP_50mV_PER_US;
284 else
285 control1 |= MAX8973_RAMP_200mV_PER_US;
286 } else {
287 control1 |= MAX8973_RAMP_12mV_PER_US;
288 max->desc.ramp_delay = 12500;
289 }
290
291 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE)) 344 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE))
292 control2 |= MAX8973_DISCH_ENBABLE; 345 control2 |= MAX8973_DISCH_ENBABLE;
293 346
@@ -344,7 +397,7 @@ static int max8973_init_dcdc(struct max8973_chip *max,
344 } 397 }
345 398
346 /* If external control is enabled then disable EN bit */ 399 /* If external control is enabled then disable EN bit */
347 if (max->enable_external_control) { 400 if (max->enable_external_control && (max->id == MAX8973)) {
348 ret = regmap_update_bits(max->regmap, MAX8973_VOUT, 401 ret = regmap_update_bits(max->regmap, MAX8973_VOUT,
349 MAX8973_VOUT_ENABLE, 0); 402 MAX8973_VOUT_ENABLE, 0);
350 if (ret < 0) 403 if (ret < 0)
@@ -361,22 +414,82 @@ static const struct regmap_config max8973_regmap_config = {
361 .cache_type = REGCACHE_RBTREE, 414 .cache_type = REGCACHE_RBTREE,
362}; 415};
363 416
417static struct max8973_regulator_platform_data *max8973_parse_dt(
418 struct device *dev)
419{
420 struct max8973_regulator_platform_data *pdata;
421 struct device_node *np = dev->of_node;
422 int ret;
423 u32 pval;
424
425 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
426 if (!pdata)
427 return NULL;
428
429 pdata->enable_ext_control = of_property_read_bool(np,
430 "maxim,externally-enable");
431 pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0);
432 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
433
434 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
435 if (!ret)
436 pdata->dvs_def_state = pval;
437
438 if (of_property_read_bool(np, "maxim,enable-remote-sense"))
439 pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE;
440
441 if (of_property_read_bool(np, "maxim,enable-falling-slew-rate"))
442 pdata->control_flags |=
443 MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE;
444
445 if (of_property_read_bool(np, "maxim,enable-active-discharge"))
446 pdata->control_flags |=
447 MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE;
448
449 if (of_property_read_bool(np, "maxim,enable-frequency-shift"))
450 pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE;
451
452 if (of_property_read_bool(np, "maxim,enable-bias-control"))
453 pdata->control_flags |= MAX8973_BIAS_ENABLE;
454
455 return pdata;
456}
457
458static const struct of_device_id of_max8973_match_tbl[] = {
459 { .compatible = "maxim,max8973", .data = (void *)MAX8973, },
460 { .compatible = "maxim,max77621", .data = (void *)MAX77621, },
461 { },
462};
463MODULE_DEVICE_TABLE(of, of_max8973_match_tbl);
464
364static int max8973_probe(struct i2c_client *client, 465static int max8973_probe(struct i2c_client *client,
365 const struct i2c_device_id *id) 466 const struct i2c_device_id *id)
366{ 467{
367 struct max8973_regulator_platform_data *pdata; 468 struct max8973_regulator_platform_data *pdata;
469 struct regulator_init_data *ridata;
368 struct regulator_config config = { }; 470 struct regulator_config config = { };
369 struct regulator_dev *rdev; 471 struct regulator_dev *rdev;
370 struct max8973_chip *max; 472 struct max8973_chip *max;
473 bool pdata_from_dt = false;
474 unsigned int chip_id;
371 int ret; 475 int ret;
372 476
373 pdata = dev_get_platdata(&client->dev); 477 pdata = dev_get_platdata(&client->dev);
374 478
375 if (!pdata && !client->dev.of_node) { 479 if (!pdata && client->dev.of_node) {
480 pdata = max8973_parse_dt(&client->dev);
481 pdata_from_dt = true;
482 }
483
484 if (!pdata) {
376 dev_err(&client->dev, "No Platform data"); 485 dev_err(&client->dev, "No Platform data");
377 return -EIO; 486 return -EIO;
378 } 487 }
379 488
489 if ((pdata->dvs_gpio == -EPROBE_DEFER) ||
490 (pdata->enable_gpio == -EPROBE_DEFER))
491 return -EPROBE_DEFER;
492
380 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); 493 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
381 if (!max) 494 if (!max)
382 return -ENOMEM; 495 return -ENOMEM;
@@ -388,6 +501,27 @@ static int max8973_probe(struct i2c_client *client,
388 return ret; 501 return ret;
389 } 502 }
390 503
504 if (client->dev.of_node) {
505 const struct of_device_id *match;
506
507 match = of_match_device(of_match_ptr(of_max8973_match_tbl),
508 &client->dev);
509 if (!match)
510 return -ENODATA;
511 max->id = (u32)((uintptr_t)match->data);
512 } else {
513 max->id = id->driver_data;
514 }
515
516 ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id);
517 if (ret < 0) {
518 dev_err(&client->dev, "register CHIPID1 read failed, %d", ret);
519 return ret;
520 }
521
522 dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n",
523 (chip_id >> 4) & 0xF, (chip_id >> 1) & 0x7);
524
391 i2c_set_clientdata(client, max); 525 i2c_set_clientdata(client, max);
392 max->ops = max8973_dcdc_ops; 526 max->ops = max8973_dcdc_ops;
393 max->dev = &client->dev; 527 max->dev = &client->dev;
@@ -400,23 +534,14 @@ static int max8973_probe(struct i2c_client *client,
400 max->desc.uV_step = MAX8973_VOLATGE_STEP; 534 max->desc.uV_step = MAX8973_VOLATGE_STEP;
401 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; 535 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
402 536
403 if (!pdata || !pdata->enable_ext_control) { 537 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
404 max->desc.enable_reg = MAX8973_VOUT; 538 max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL;
405 max->desc.enable_mask = MAX8973_VOUT_ENABLE; 539 max->enable_external_control = pdata->enable_ext_control;
406 max->ops.enable = regulator_enable_regmap; 540 max->curr_gpio_val = pdata->dvs_def_state;
407 max->ops.disable = regulator_disable_regmap; 541 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
408 max->ops.is_enabled = regulator_is_enabled_regmap;
409 }
410 542
411 if (pdata) { 543 if (gpio_is_valid(max->enable_gpio))
412 max->dvs_gpio = pdata->dvs_gpio; 544 max->enable_external_control = true;
413 max->enable_external_control = pdata->enable_ext_control;
414 max->curr_gpio_val = pdata->dvs_def_state;
415 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
416 } else {
417 max->dvs_gpio = -EINVAL;
418 max->curr_vout_reg = MAX8973_VOUT;
419 }
420 545
421 max->lru_index[0] = max->curr_vout_reg; 546 max->lru_index[0] = max->curr_vout_reg;
422 547
@@ -434,7 +559,6 @@ static int max8973_probe(struct i2c_client *client,
434 max->dvs_gpio, ret); 559 max->dvs_gpio, ret);
435 return ret; 560 return ret;
436 } 561 }
437 max->valid_dvs_gpio = true;
438 562
439 /* 563 /*
440 * Initialize the lru index with vout_reg id 564 * Initialize the lru index with vout_reg id
@@ -444,22 +568,64 @@ static int max8973_probe(struct i2c_client *client,
444 max->lru_index[i] = i; 568 max->lru_index[i] = i;
445 max->lru_index[0] = max->curr_vout_reg; 569 max->lru_index[0] = max->curr_vout_reg;
446 max->lru_index[max->curr_vout_reg] = 0; 570 max->lru_index[max->curr_vout_reg] = 0;
447 } else {
448 max->valid_dvs_gpio = false;
449 } 571 }
450 572
451 if (pdata) { 573 if (pdata_from_dt)
452 ret = max8973_init_dcdc(max, pdata); 574 pdata->reg_init_data = of_get_regulator_init_data(&client->dev,
453 if (ret < 0) { 575 client->dev.of_node, &max->desc);
454 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); 576
455 return ret; 577 ridata = pdata->reg_init_data;
578 switch (max->id) {
579 case MAX8973:
580 if (!pdata->enable_ext_control) {
581 max->desc.enable_reg = MAX8973_VOUT;
582 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
583 max->ops.enable = regulator_enable_regmap;
584 max->ops.disable = regulator_disable_regmap;
585 max->ops.is_enabled = regulator_is_enabled_regmap;
586 break;
587 }
588
589 if (gpio_is_valid(max->enable_gpio)) {
590 config.ena_gpio_flags = GPIOF_OUT_INIT_LOW;
591 if (ridata && (ridata->constraints.always_on ||
592 ridata->constraints.boot_on))
593 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
594 config.ena_gpio = max->enable_gpio;
456 } 595 }
596 break;
597
598 case MAX77621:
599 if (gpio_is_valid(max->enable_gpio)) {
600 ret = devm_gpio_request_one(&client->dev,
601 max->enable_gpio, GPIOF_OUT_INIT_HIGH,
602 "max8973-en-gpio");
603 if (ret) {
604 dev_err(&client->dev,
605 "gpio_request for gpio %d failed: %d\n",
606 max->enable_gpio, ret);
607 return ret;
608 }
609 }
610
611 max->desc.enable_reg = MAX8973_VOUT;
612 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
613 max->ops.enable = regulator_enable_regmap;
614 max->ops.disable = regulator_disable_regmap;
615 max->ops.is_enabled = regulator_is_enabled_regmap;
616 break;
617 default:
618 break;
619 }
620
621 ret = max8973_init_dcdc(max, pdata);
622 if (ret < 0) {
623 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret);
624 return ret;
457 } 625 }
458 626
459 config.dev = &client->dev; 627 config.dev = &client->dev;
460 config.init_data = pdata ? pdata->reg_init_data : 628 config.init_data = pdata->reg_init_data;
461 of_get_regulator_init_data(&client->dev, client->dev.of_node,
462 &max->desc);
463 config.driver_data = max; 629 config.driver_data = max;
464 config.of_node = client->dev.of_node; 630 config.of_node = client->dev.of_node;
465 config.regmap = max->regmap; 631 config.regmap = max->regmap;
@@ -476,15 +642,16 @@ static int max8973_probe(struct i2c_client *client,
476} 642}
477 643
478static const struct i2c_device_id max8973_id[] = { 644static const struct i2c_device_id max8973_id[] = {
479 {.name = "max8973",}, 645 {.name = "max8973", .driver_data = MAX8973},
646 {.name = "max77621", .driver_data = MAX77621},
480 {}, 647 {},
481}; 648};
482
483MODULE_DEVICE_TABLE(i2c, max8973_id); 649MODULE_DEVICE_TABLE(i2c, max8973_id);
484 650
485static struct i2c_driver max8973_i2c_driver = { 651static struct i2c_driver max8973_i2c_driver = {
486 .driver = { 652 .driver = {
487 .name = "max8973", 653 .name = "max8973",
654 .of_match_table = of_max8973_match_tbl,
488 .owner = THIS_MODULE, 655 .owner = THIS_MODULE,
489 }, 656 },
490 .probe = max8973_probe, 657 .probe = max8973_probe,
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 24e812c48d93..b1c485b24ab2 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -58,6 +58,10 @@ static void of_get_regulation_constraints(struct device_node *np,
58 if (!of_property_read_u32(np, "regulator-max-microamp", &pval)) 58 if (!of_property_read_u32(np, "regulator-max-microamp", &pval))
59 constraints->max_uA = pval; 59 constraints->max_uA = pval;
60 60
61 if (!of_property_read_u32(np, "regulator-input-current-limit-microamp",
62 &pval))
63 constraints->ilim_uA = pval;
64
61 /* Current change possible? */ 65 /* Current change possible? */
62 if (constraints->min_uA != constraints->max_uA) 66 if (constraints->min_uA != constraints->max_uA)
63 constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT; 67 constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
@@ -67,6 +71,8 @@ static void of_get_regulation_constraints(struct device_node *np,
67 if (!constraints->always_on) /* status change should be possible. */ 71 if (!constraints->always_on) /* status change should be possible. */
68 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS; 72 constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
69 73
74 constraints->pull_down = of_property_read_bool(np, "regulator-pull-down");
75
70 if (of_property_read_bool(np, "regulator-allow-bypass")) 76 if (of_property_read_bool(np, "regulator-allow-bypass"))
71 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; 77 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS;
72 78
@@ -82,6 +88,9 @@ static void of_get_regulation_constraints(struct device_node *np,
82 if (!ret) 88 if (!ret)
83 constraints->enable_time = pval; 89 constraints->enable_time = pval;
84 90
91 constraints->soft_start = of_property_read_bool(np,
92 "regulator-soft-start");
93
85 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) { 94 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
86 if (desc && desc->of_map_mode) { 95 if (desc && desc->of_map_mode) {
87 ret = desc->of_map_mode(pval); 96 ret = desc->of_map_mode(pval);
@@ -95,6 +104,9 @@ static void of_get_regulation_constraints(struct device_node *np,
95 } 104 }
96 } 105 }
97 106
107 if (!of_property_read_u32(np, "regulator-system-load", &pval))
108 constraints->system_load = pval;
109
98 for (i = 0; i < ARRAY_SIZE(regulator_states); i++) { 110 for (i = 0; i < ARRAY_SIZE(regulator_states); i++) {
99 switch (i) { 111 switch (i) {
100 case PM_SUSPEND_MEM: 112 case PM_SUSPEND_MEM:
@@ -108,7 +120,7 @@ static void of_get_regulation_constraints(struct device_node *np,
108 case PM_SUSPEND_STANDBY: 120 case PM_SUSPEND_STANDBY:
109 default: 121 default:
110 continue; 122 continue;
111 }; 123 }
112 124
113 suspend_np = of_get_child_by_name(np, regulator_states[i]); 125 suspend_np = of_get_child_by_name(np, regulator_states[i]);
114 if (!suspend_np || !suspend_state) 126 if (!suspend_np || !suspend_state)
@@ -292,7 +304,7 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
292 return NULL; 304 return NULL;
293 } 305 }
294 306
295 for_each_child_of_node(search, child) { 307 for_each_available_child_of_node(search, child) {
296 name = of_get_property(child, "regulator-compatible", NULL); 308 name = of_get_property(child, "regulator-compatible", NULL);
297 if (!name) 309 if (!name)
298 name = child->name; 310 name = child->name;
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index 253833ae35f3..ffa96124a5e7 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -21,10 +21,8 @@
21#include <linux/pwm.h> 21#include <linux/pwm.h>
22 22
23struct pwm_regulator_data { 23struct pwm_regulator_data {
24 struct regulator_desc desc;
25 struct pwm_voltages *duty_cycle_table; 24 struct pwm_voltages *duty_cycle_table;
26 struct pwm_device *pwm; 25 struct pwm_device *pwm;
27 bool enabled;
28 int state; 26 int state;
29}; 27};
30 28
@@ -33,17 +31,17 @@ struct pwm_voltages {
33 unsigned int dutycycle; 31 unsigned int dutycycle;
34}; 32};
35 33
36static int pwm_regulator_get_voltage_sel(struct regulator_dev *dev) 34static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev)
37{ 35{
38 struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 36 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
39 37
40 return drvdata->state; 38 return drvdata->state;
41} 39}
42 40
43static int pwm_regulator_set_voltage_sel(struct regulator_dev *dev, 41static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
44 unsigned selector) 42 unsigned selector)
45{ 43{
46 struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 44 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
47 unsigned int pwm_reg_period; 45 unsigned int pwm_reg_period;
48 int dutycycle; 46 int dutycycle;
49 int ret; 47 int ret;
@@ -55,30 +53,27 @@ static int pwm_regulator_set_voltage_sel(struct regulator_dev *dev,
55 53
56 ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period); 54 ret = pwm_config(drvdata->pwm, dutycycle, pwm_reg_period);
57 if (ret) { 55 if (ret) {
58 dev_err(&dev->dev, "Failed to configure PWM\n"); 56 dev_err(&rdev->dev, "Failed to configure PWM\n");
59 return ret; 57 return ret;
60 } 58 }
61 59
62 drvdata->state = selector; 60 drvdata->state = selector;
63 61
64 if (!drvdata->enabled) { 62 ret = pwm_enable(drvdata->pwm);
65 ret = pwm_enable(drvdata->pwm); 63 if (ret) {
66 if (ret) { 64 dev_err(&rdev->dev, "Failed to enable PWM\n");
67 dev_err(&dev->dev, "Failed to enable PWM\n"); 65 return ret;
68 return ret;
69 }
70 drvdata->enabled = true;
71 } 66 }
72 67
73 return 0; 68 return 0;
74} 69}
75 70
76static int pwm_regulator_list_voltage(struct regulator_dev *dev, 71static int pwm_regulator_list_voltage(struct regulator_dev *rdev,
77 unsigned selector) 72 unsigned selector)
78{ 73{
79 struct pwm_regulator_data *drvdata = rdev_get_drvdata(dev); 74 struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
80 75
81 if (selector >= drvdata->desc.n_voltages) 76 if (selector >= rdev->desc->n_voltages)
82 return -EINVAL; 77 return -EINVAL;
83 78
84 return drvdata->duty_cycle_table[selector].uV; 79 return drvdata->duty_cycle_table[selector].uV;
@@ -91,7 +86,7 @@ static struct regulator_ops pwm_regulator_voltage_ops = {
91 .map_voltage = regulator_map_voltage_iterate, 86 .map_voltage = regulator_map_voltage_iterate,
92}; 87};
93 88
94static const struct regulator_desc pwm_regulator_desc = { 89static struct regulator_desc pwm_regulator_desc = {
95 .name = "pwm-regulator", 90 .name = "pwm-regulator",
96 .ops = &pwm_regulator_voltage_ops, 91 .ops = &pwm_regulator_voltage_ops,
97 .type = REGULATOR_VOLTAGE, 92 .type = REGULATOR_VOLTAGE,
@@ -117,8 +112,6 @@ static int pwm_regulator_probe(struct platform_device *pdev)
117 if (!drvdata) 112 if (!drvdata)
118 return -ENOMEM; 113 return -ENOMEM;
119 114
120 memcpy(&drvdata->desc, &pwm_regulator_desc, sizeof(pwm_regulator_desc));
121
122 /* determine the number of voltage-table */ 115 /* determine the number of voltage-table */
123 prop = of_find_property(np, "voltage-table", &length); 116 prop = of_find_property(np, "voltage-table", &length);
124 if (!prop) { 117 if (!prop) {
@@ -133,7 +126,7 @@ static int pwm_regulator_probe(struct platform_device *pdev)
133 return -EINVAL; 126 return -EINVAL;
134 } 127 }
135 128
136 drvdata->desc.n_voltages = length / sizeof(*drvdata->duty_cycle_table); 129 pwm_regulator_desc.n_voltages = length / sizeof(*drvdata->duty_cycle_table);
137 130
138 drvdata->duty_cycle_table = devm_kzalloc(&pdev->dev, 131 drvdata->duty_cycle_table = devm_kzalloc(&pdev->dev,
139 length, GFP_KERNEL); 132 length, GFP_KERNEL);
@@ -150,7 +143,7 @@ static int pwm_regulator_probe(struct platform_device *pdev)
150 } 143 }
151 144
152 config.init_data = of_get_regulator_init_data(&pdev->dev, np, 145 config.init_data = of_get_regulator_init_data(&pdev->dev, np,
153 &drvdata->desc); 146 &pwm_regulator_desc);
154 if (!config.init_data) 147 if (!config.init_data)
155 return -ENOMEM; 148 return -ENOMEM;
156 149
@@ -165,10 +158,10 @@ static int pwm_regulator_probe(struct platform_device *pdev)
165 } 158 }
166 159
167 regulator = devm_regulator_register(&pdev->dev, 160 regulator = devm_regulator_register(&pdev->dev,
168 &drvdata->desc, &config); 161 &pwm_regulator_desc, &config);
169 if (IS_ERR(regulator)) { 162 if (IS_ERR(regulator)) {
170 dev_err(&pdev->dev, "Failed to register regulator %s\n", 163 dev_err(&pdev->dev, "Failed to register regulator %s\n",
171 drvdata->desc.name); 164 pwm_regulator_desc.name);
172 return PTR_ERR(regulator); 165 return PTR_ERR(regulator);
173 } 166 }
174 167
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
new file mode 100644
index 000000000000..850a30a95b5b
--- /dev/null
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -0,0 +1,1435 @@
1/*
2 * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/module.h>
15#include <linux/delay.h>
16#include <linux/err.h>
17#include <linux/kernel.h>
18#include <linux/interrupt.h>
19#include <linux/bitops.h>
20#include <linux/slab.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
23#include <linux/platform_device.h>
24#include <linux/ktime.h>
25#include <linux/regulator/driver.h>
26#include <linux/regmap.h>
27#include <linux/list.h>
28
29/* These types correspond to unique register layouts. */
30enum spmi_regulator_logical_type {
31 SPMI_REGULATOR_LOGICAL_TYPE_SMPS,
32 SPMI_REGULATOR_LOGICAL_TYPE_LDO,
33 SPMI_REGULATOR_LOGICAL_TYPE_VS,
34 SPMI_REGULATOR_LOGICAL_TYPE_BOOST,
35 SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS,
36 SPMI_REGULATOR_LOGICAL_TYPE_BOOST_BYP,
37 SPMI_REGULATOR_LOGICAL_TYPE_LN_LDO,
38 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS,
39 SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS,
40 SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO,
41};
42
43enum spmi_regulator_type {
44 SPMI_REGULATOR_TYPE_BUCK = 0x03,
45 SPMI_REGULATOR_TYPE_LDO = 0x04,
46 SPMI_REGULATOR_TYPE_VS = 0x05,
47 SPMI_REGULATOR_TYPE_BOOST = 0x1b,
48 SPMI_REGULATOR_TYPE_FTS = 0x1c,
49 SPMI_REGULATOR_TYPE_BOOST_BYP = 0x1f,
50 SPMI_REGULATOR_TYPE_ULT_LDO = 0x21,
51 SPMI_REGULATOR_TYPE_ULT_BUCK = 0x22,
52};
53
54enum spmi_regulator_subtype {
55 SPMI_REGULATOR_SUBTYPE_GP_CTL = 0x08,
56 SPMI_REGULATOR_SUBTYPE_RF_CTL = 0x09,
57 SPMI_REGULATOR_SUBTYPE_N50 = 0x01,
58 SPMI_REGULATOR_SUBTYPE_N150 = 0x02,
59 SPMI_REGULATOR_SUBTYPE_N300 = 0x03,
60 SPMI_REGULATOR_SUBTYPE_N600 = 0x04,
61 SPMI_REGULATOR_SUBTYPE_N1200 = 0x05,
62 SPMI_REGULATOR_SUBTYPE_N600_ST = 0x06,
63 SPMI_REGULATOR_SUBTYPE_N1200_ST = 0x07,
64 SPMI_REGULATOR_SUBTYPE_N900_ST = 0x14,
65 SPMI_REGULATOR_SUBTYPE_N300_ST = 0x15,
66 SPMI_REGULATOR_SUBTYPE_P50 = 0x08,
67 SPMI_REGULATOR_SUBTYPE_P150 = 0x09,
68 SPMI_REGULATOR_SUBTYPE_P300 = 0x0a,
69 SPMI_REGULATOR_SUBTYPE_P600 = 0x0b,
70 SPMI_REGULATOR_SUBTYPE_P1200 = 0x0c,
71 SPMI_REGULATOR_SUBTYPE_LN = 0x10,
72 SPMI_REGULATOR_SUBTYPE_LV_P50 = 0x28,
73 SPMI_REGULATOR_SUBTYPE_LV_P150 = 0x29,
74 SPMI_REGULATOR_SUBTYPE_LV_P300 = 0x2a,
75 SPMI_REGULATOR_SUBTYPE_LV_P600 = 0x2b,
76 SPMI_REGULATOR_SUBTYPE_LV_P1200 = 0x2c,
77 SPMI_REGULATOR_SUBTYPE_LV_P450 = 0x2d,
78 SPMI_REGULATOR_SUBTYPE_LV100 = 0x01,
79 SPMI_REGULATOR_SUBTYPE_LV300 = 0x02,
80 SPMI_REGULATOR_SUBTYPE_MV300 = 0x08,
81 SPMI_REGULATOR_SUBTYPE_MV500 = 0x09,
82 SPMI_REGULATOR_SUBTYPE_HDMI = 0x10,
83 SPMI_REGULATOR_SUBTYPE_OTG = 0x11,
84 SPMI_REGULATOR_SUBTYPE_5V_BOOST = 0x01,
85 SPMI_REGULATOR_SUBTYPE_FTS_CTL = 0x08,
86 SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL = 0x09,
87 SPMI_REGULATOR_SUBTYPE_BB_2A = 0x01,
88 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1 = 0x0d,
89 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2 = 0x0e,
90 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3 = 0x0f,
91 SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4 = 0x10,
92};
93
94enum spmi_common_regulator_registers {
95 SPMI_COMMON_REG_DIG_MAJOR_REV = 0x01,
96 SPMI_COMMON_REG_TYPE = 0x04,
97 SPMI_COMMON_REG_SUBTYPE = 0x05,
98 SPMI_COMMON_REG_VOLTAGE_RANGE = 0x40,
99 SPMI_COMMON_REG_VOLTAGE_SET = 0x41,
100 SPMI_COMMON_REG_MODE = 0x45,
101 SPMI_COMMON_REG_ENABLE = 0x46,
102 SPMI_COMMON_REG_PULL_DOWN = 0x48,
103 SPMI_COMMON_REG_SOFT_START = 0x4c,
104 SPMI_COMMON_REG_STEP_CTRL = 0x61,
105};
106
107enum spmi_vs_registers {
108 SPMI_VS_REG_OCP = 0x4a,
109 SPMI_VS_REG_SOFT_START = 0x4c,
110};
111
112enum spmi_boost_registers {
113 SPMI_BOOST_REG_CURRENT_LIMIT = 0x4a,
114};
115
116enum spmi_boost_byp_registers {
117 SPMI_BOOST_BYP_REG_CURRENT_LIMIT = 0x4b,
118};
119
120/* Used for indexing into ctrl_reg. These are offets from 0x40 */
121enum spmi_common_control_register_index {
122 SPMI_COMMON_IDX_VOLTAGE_RANGE = 0,
123 SPMI_COMMON_IDX_VOLTAGE_SET = 1,
124 SPMI_COMMON_IDX_MODE = 5,
125 SPMI_COMMON_IDX_ENABLE = 6,
126};
127
128/* Common regulator control register layout */
129#define SPMI_COMMON_ENABLE_MASK 0x80
130#define SPMI_COMMON_ENABLE 0x80
131#define SPMI_COMMON_DISABLE 0x00
132#define SPMI_COMMON_ENABLE_FOLLOW_HW_EN3_MASK 0x08
133#define SPMI_COMMON_ENABLE_FOLLOW_HW_EN2_MASK 0x04
134#define SPMI_COMMON_ENABLE_FOLLOW_HW_EN1_MASK 0x02
135#define SPMI_COMMON_ENABLE_FOLLOW_HW_EN0_MASK 0x01
136#define SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK 0x0f
137
138/* Common regulator mode register layout */
139#define SPMI_COMMON_MODE_HPM_MASK 0x80
140#define SPMI_COMMON_MODE_AUTO_MASK 0x40
141#define SPMI_COMMON_MODE_BYPASS_MASK 0x20
142#define SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK 0x10
143#define SPMI_COMMON_MODE_FOLLOW_HW_EN3_MASK 0x08
144#define SPMI_COMMON_MODE_FOLLOW_HW_EN2_MASK 0x04
145#define SPMI_COMMON_MODE_FOLLOW_HW_EN1_MASK 0x02
146#define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01
147#define SPMI_COMMON_MODE_FOLLOW_ALL_MASK 0x1f
148
149/* Common regulator pull down control register layout */
150#define SPMI_COMMON_PULL_DOWN_ENABLE_MASK 0x80
151
152/* LDO regulator current limit control register layout */
153#define SPMI_LDO_CURRENT_LIMIT_ENABLE_MASK 0x80
154
155/* LDO regulator soft start control register layout */
156#define SPMI_LDO_SOFT_START_ENABLE_MASK 0x80
157
158/* VS regulator over current protection control register layout */
159#define SPMI_VS_OCP_OVERRIDE 0x01
160#define SPMI_VS_OCP_NO_OVERRIDE 0x00
161
162/* VS regulator soft start control register layout */
163#define SPMI_VS_SOFT_START_ENABLE_MASK 0x80
164#define SPMI_VS_SOFT_START_SEL_MASK 0x03
165
166/* Boost regulator current limit control register layout */
167#define SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK 0x80
168#define SPMI_BOOST_CURRENT_LIMIT_MASK 0x07
169
170#define SPMI_VS_OCP_DEFAULT_MAX_RETRIES 10
171#define SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS 30
172#define SPMI_VS_OCP_FALL_DELAY_US 90
173#define SPMI_VS_OCP_FAULT_DELAY_US 20000
174
175#define SPMI_FTSMPS_STEP_CTRL_STEP_MASK 0x18
176#define SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT 3
177#define SPMI_FTSMPS_STEP_CTRL_DELAY_MASK 0x07
178#define SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT 0
179
180/* Clock rate in kHz of the FTSMPS regulator reference clock. */
181#define SPMI_FTSMPS_CLOCK_RATE 19200
182
183/* Minimum voltage stepper delay for each step. */
184#define SPMI_FTSMPS_STEP_DELAY 8
185
186/*
187 * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to
188 * adjust the step rate in order to account for oscillator variance.
189 */
190#define SPMI_FTSMPS_STEP_MARGIN_NUM 4
191#define SPMI_FTSMPS_STEP_MARGIN_DEN 5
192
193/*
194 * This voltage in uV is returned by get_voltage functions when there is no way
195 * to determine the current voltage level. It is needed because the regulator
196 * framework treats a 0 uV voltage as an error.
197 */
198#define VOLTAGE_UNKNOWN 1
199
200/* VSET value to decide the range of ULT SMPS */
201#define ULT_SMPS_RANGE_SPLIT 0x60
202
203/**
204 * struct spmi_voltage_range - regulator set point voltage mapping description
205 * @min_uV: Minimum programmable output voltage resulting from
206 * set point register value 0x00
207 * @max_uV: Maximum programmable output voltage
208 * @step_uV: Output voltage increase resulting from the set point
209 * register value increasing by 1
210 * @set_point_min_uV: Minimum allowed voltage
211 * @set_point_max_uV: Maximum allowed voltage. This may be tweaked in order
212 * to pick which range should be used in the case of
213 * overlapping set points.
214 * @n_voltages: Number of preferred voltage set points present in this
215 * range
216 * @range_sel: Voltage range register value corresponding to this range
217 *
218 * The following relationships must be true for the values used in this struct:
219 * (max_uV - min_uV) % step_uV == 0
220 * (set_point_min_uV - min_uV) % step_uV == 0*
221 * (set_point_max_uV - min_uV) % step_uV == 0*
222 * n_voltages = (set_point_max_uV - set_point_min_uV) / step_uV + 1
223 *
224 * *Note, set_point_min_uV == set_point_max_uV == 0 is allowed in order to
225 * specify that the voltage range has meaning, but is not preferred.
226 */
227struct spmi_voltage_range {
228 int min_uV;
229 int max_uV;
230 int step_uV;
231 int set_point_min_uV;
232 int set_point_max_uV;
233 unsigned n_voltages;
234 u8 range_sel;
235};
236
237/*
238 * The ranges specified in the spmi_voltage_set_points struct must be listed
239 * so that range[i].set_point_max_uV < range[i+1].set_point_min_uV.
240 */
241struct spmi_voltage_set_points {
242 struct spmi_voltage_range *range;
243 int count;
244 unsigned n_voltages;
245};
246
247struct spmi_regulator {
248 struct regulator_desc desc;
249 struct device *dev;
250 struct delayed_work ocp_work;
251 struct regmap *regmap;
252 struct spmi_voltage_set_points *set_points;
253 enum spmi_regulator_logical_type logical_type;
254 int ocp_irq;
255 int ocp_count;
256 int ocp_max_retries;
257 int ocp_retry_delay_ms;
258 int hpm_min_load;
259 int slew_rate;
260 ktime_t vs_enable_time;
261 u16 base;
262 struct list_head node;
263};
264
265struct spmi_regulator_mapping {
266 enum spmi_regulator_type type;
267 enum spmi_regulator_subtype subtype;
268 enum spmi_regulator_logical_type logical_type;
269 u32 revision_min;
270 u32 revision_max;
271 struct regulator_ops *ops;
272 struct spmi_voltage_set_points *set_points;
273 int hpm_min_load;
274};
275
276struct spmi_regulator_data {
277 const char *name;
278 u16 base;
279 const char *supply;
280 const char *ocp;
281 u16 force_type;
282};
283
284#define SPMI_VREG(_type, _subtype, _dig_major_min, _dig_major_max, \
285 _logical_type, _ops_val, _set_points_val, _hpm_min_load) \
286 { \
287 .type = SPMI_REGULATOR_TYPE_##_type, \
288 .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \
289 .revision_min = _dig_major_min, \
290 .revision_max = _dig_major_max, \
291 .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_##_logical_type, \
292 .ops = &spmi_##_ops_val##_ops, \
293 .set_points = &_set_points_val##_set_points, \
294 .hpm_min_load = _hpm_min_load, \
295 }
296
297#define SPMI_VREG_VS(_subtype, _dig_major_min, _dig_major_max) \
298 { \
299 .type = SPMI_REGULATOR_TYPE_VS, \
300 .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \
301 .revision_min = _dig_major_min, \
302 .revision_max = _dig_major_max, \
303 .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_VS, \
304 .ops = &spmi_vs_ops, \
305 }
306
307#define SPMI_VOLTAGE_RANGE(_range_sel, _min_uV, _set_point_min_uV, \
308 _set_point_max_uV, _max_uV, _step_uV) \
309 { \
310 .min_uV = _min_uV, \
311 .max_uV = _max_uV, \
312 .set_point_min_uV = _set_point_min_uV, \
313 .set_point_max_uV = _set_point_max_uV, \
314 .step_uV = _step_uV, \
315 .range_sel = _range_sel, \
316 }
317
318#define DEFINE_SPMI_SET_POINTS(name) \
319struct spmi_voltage_set_points name##_set_points = { \
320 .range = name##_ranges, \
321 .count = ARRAY_SIZE(name##_ranges), \
322}
323
324/*
325 * These tables contain the physically available PMIC regulator voltage setpoint
326 * ranges. Where two ranges overlap in hardware, one of the ranges is trimmed
327 * to ensure that the setpoints available to software are monotonically
328 * increasing and unique. The set_voltage callback functions expect these
329 * properties to hold.
330 */
331static struct spmi_voltage_range pldo_ranges[] = {
332 SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500),
333 SPMI_VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 3075000, 25000),
334 SPMI_VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 4900000, 50000),
335};
336
337static struct spmi_voltage_range nldo1_ranges[] = {
338 SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500),
339};
340
341static struct spmi_voltage_range nldo2_ranges[] = {
342 SPMI_VOLTAGE_RANGE(0, 375000, 0, 0, 1537500, 12500),
343 SPMI_VOLTAGE_RANGE(1, 375000, 375000, 768750, 768750, 6250),
344 SPMI_VOLTAGE_RANGE(2, 750000, 775000, 1537500, 1537500, 12500),
345};
346
347static struct spmi_voltage_range nldo3_ranges[] = {
348 SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500),
349 SPMI_VOLTAGE_RANGE(1, 375000, 0, 0, 1537500, 12500),
350 SPMI_VOLTAGE_RANGE(2, 750000, 0, 0, 1537500, 12500),
351};
352
353static struct spmi_voltage_range ln_ldo_ranges[] = {
354 SPMI_VOLTAGE_RANGE(1, 690000, 690000, 1110000, 1110000, 60000),
355 SPMI_VOLTAGE_RANGE(0, 1380000, 1380000, 2220000, 2220000, 120000),
356};
357
358static struct spmi_voltage_range smps_ranges[] = {
359 SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500),
360 SPMI_VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 3125000, 25000),
361};
362
363static struct spmi_voltage_range ftsmps_ranges[] = {
364 SPMI_VOLTAGE_RANGE(0, 0, 350000, 1275000, 1275000, 5000),
365 SPMI_VOLTAGE_RANGE(1, 0, 1280000, 2040000, 2040000, 10000),
366};
367
368static struct spmi_voltage_range ftsmps2p5_ranges[] = {
369 SPMI_VOLTAGE_RANGE(0, 80000, 350000, 1355000, 1355000, 5000),
370 SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000),
371};
372
373static struct spmi_voltage_range boost_ranges[] = {
374 SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000),
375};
376
377static struct spmi_voltage_range boost_byp_ranges[] = {
378 SPMI_VOLTAGE_RANGE(0, 2500000, 2500000, 5200000, 5650000, 50000),
379};
380
381static struct spmi_voltage_range ult_lo_smps_ranges[] = {
382 SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500),
383 SPMI_VOLTAGE_RANGE(1, 750000, 0, 0, 1525000, 25000),
384};
385
386static struct spmi_voltage_range ult_ho_smps_ranges[] = {
387 SPMI_VOLTAGE_RANGE(0, 1550000, 1550000, 2325000, 2325000, 25000),
388};
389
390static struct spmi_voltage_range ult_nldo_ranges[] = {
391 SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500),
392};
393
394static struct spmi_voltage_range ult_pldo_ranges[] = {
395 SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500),
396};
397
398static DEFINE_SPMI_SET_POINTS(pldo);
399static DEFINE_SPMI_SET_POINTS(nldo1);
400static DEFINE_SPMI_SET_POINTS(nldo2);
401static DEFINE_SPMI_SET_POINTS(nldo3);
402static DEFINE_SPMI_SET_POINTS(ln_ldo);
403static DEFINE_SPMI_SET_POINTS(smps);
404static DEFINE_SPMI_SET_POINTS(ftsmps);
405static DEFINE_SPMI_SET_POINTS(ftsmps2p5);
406static DEFINE_SPMI_SET_POINTS(boost);
407static DEFINE_SPMI_SET_POINTS(boost_byp);
408static DEFINE_SPMI_SET_POINTS(ult_lo_smps);
409static DEFINE_SPMI_SET_POINTS(ult_ho_smps);
410static DEFINE_SPMI_SET_POINTS(ult_nldo);
411static DEFINE_SPMI_SET_POINTS(ult_pldo);
412
413static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf,
414 int len)
415{
416 return regmap_bulk_read(vreg->regmap, vreg->base + addr, buf, len);
417}
418
419static inline int spmi_vreg_write(struct spmi_regulator *vreg, u16 addr,
420 u8 *buf, int len)
421{
422 return regmap_bulk_write(vreg->regmap, vreg->base + addr, buf, len);
423}
424
425static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val,
426 u8 mask)
427{
428 return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val);
429}
430
431static int spmi_regulator_common_is_enabled(struct regulator_dev *rdev)
432{
433 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
434 u8 reg;
435
436 spmi_vreg_read(vreg, SPMI_COMMON_REG_ENABLE, &reg, 1);
437
438 return (reg & SPMI_COMMON_ENABLE_MASK) == SPMI_COMMON_ENABLE;
439}
440
441static int spmi_regulator_common_enable(struct regulator_dev *rdev)
442{
443 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
444
445 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
446 SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK);
447}
448
449static int spmi_regulator_vs_enable(struct regulator_dev *rdev)
450{
451 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
452
453 if (vreg->ocp_irq) {
454 vreg->ocp_count = 0;
455 vreg->vs_enable_time = ktime_get();
456 }
457
458 return spmi_regulator_common_enable(rdev);
459}
460
461static int spmi_regulator_common_disable(struct regulator_dev *rdev)
462{
463 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
464
465 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
466 SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK);
467}
468
469static int spmi_regulator_select_voltage(struct spmi_regulator *vreg,
470 int min_uV, int max_uV, u8 *range_sel, u8 *voltage_sel,
471 unsigned *selector)
472{
473 const struct spmi_voltage_range *range;
474 int uV = min_uV;
475 int lim_min_uV, lim_max_uV, i, range_id, range_max_uV;
476
477 /* Check if request voltage is outside of physically settable range. */
478 lim_min_uV = vreg->set_points->range[0].set_point_min_uV;
479 lim_max_uV =
480 vreg->set_points->range[vreg->set_points->count - 1].set_point_max_uV;
481
482 if (uV < lim_min_uV && max_uV >= lim_min_uV)
483 uV = lim_min_uV;
484
485 if (uV < lim_min_uV || uV > lim_max_uV) {
486 dev_err(vreg->dev,
487 "request v=[%d, %d] is outside possible v=[%d, %d]\n",
488 min_uV, max_uV, lim_min_uV, lim_max_uV);
489 return -EINVAL;
490 }
491
492 /* Find the range which uV is inside of. */
493 for (i = vreg->set_points->count - 1; i > 0; i--) {
494 range_max_uV = vreg->set_points->range[i - 1].set_point_max_uV;
495 if (uV > range_max_uV && range_max_uV > 0)
496 break;
497 }
498
499 range_id = i;
500 range = &vreg->set_points->range[range_id];
501 *range_sel = range->range_sel;
502
503 /*
504 * Force uV to be an allowed set point by applying a ceiling function to
505 * the uV value.
506 */
507 *voltage_sel = (uV - range->min_uV + range->step_uV - 1)
508 / range->step_uV;
509 uV = *voltage_sel * range->step_uV + range->min_uV;
510
511 if (uV > max_uV) {
512 dev_err(vreg->dev,
513 "request v=[%d, %d] cannot be met by any set point; "
514 "next set point: %d\n",
515 min_uV, max_uV, uV);
516 return -EINVAL;
517 }
518
519 *selector = 0;
520 for (i = 0; i < range_id; i++)
521 *selector += vreg->set_points->range[i].n_voltages;
522 *selector += (uV - range->set_point_min_uV) / range->step_uV;
523
524 return 0;
525}
526
527static const struct spmi_voltage_range *
528spmi_regulator_find_range(struct spmi_regulator *vreg)
529{
530 u8 range_sel;
531 const struct spmi_voltage_range *range, *end;
532
533 range = vreg->set_points->range;
534 end = range + vreg->set_points->count;
535
536 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, &range_sel, 1);
537
538 for (; range < end; range++)
539 if (range->range_sel == range_sel)
540 return range;
541
542 return NULL;
543}
544
545static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg,
546 int min_uV, int max_uV, u8 *range_sel, u8 *voltage_sel,
547 unsigned *selector)
548{
549 const struct spmi_voltage_range *range;
550 int uV = min_uV;
551 int i;
552
553 range = spmi_regulator_find_range(vreg);
554 if (!range)
555 goto different_range;
556
557 if (uV < range->min_uV && max_uV >= range->min_uV)
558 uV = range->min_uV;
559
560 if (uV < range->min_uV || uV > range->max_uV) {
561 /* Current range doesn't support the requested voltage. */
562 goto different_range;
563 }
564
565 /*
566 * Force uV to be an allowed set point by applying a ceiling function to
567 * the uV value.
568 */
569 *voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV);
570 uV = *voltage_sel * range->step_uV + range->min_uV;
571
572 if (uV > max_uV) {
573 /*
574 * No set point in the current voltage range is within the
575 * requested min_uV to max_uV range.
576 */
577 goto different_range;
578 }
579
580 *selector = 0;
581 for (i = 0; i < vreg->set_points->count; i++) {
582 if (uV >= vreg->set_points->range[i].set_point_min_uV
583 && uV <= vreg->set_points->range[i].set_point_max_uV) {
584 *selector +=
585 (uV - vreg->set_points->range[i].set_point_min_uV)
586 / vreg->set_points->range[i].step_uV;
587 break;
588 }
589
590 *selector += vreg->set_points->range[i].n_voltages;
591 }
592
593 if (*selector >= vreg->set_points->n_voltages)
594 goto different_range;
595
596 return 0;
597
598different_range:
599 return spmi_regulator_select_voltage(vreg, min_uV, max_uV,
600 range_sel, voltage_sel, selector);
601}
602
603static int spmi_regulator_common_set_voltage(struct regulator_dev *rdev,
604 int min_uV, int max_uV, unsigned *selector)
605{
606 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
607 int ret;
608 u8 buf[2];
609 u8 range_sel, voltage_sel;
610
611 /*
612 * Favor staying in the current voltage range if possible. This avoids
613 * voltage spikes that occur when changing the voltage range.
614 */
615 ret = spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV,
616 &range_sel, &voltage_sel, selector);
617 if (ret)
618 return ret;
619
620 buf[0] = range_sel;
621 buf[1] = voltage_sel;
622 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2);
623}
624
625static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
626 unsigned int old_selector, unsigned int new_selector)
627{
628 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
629 const struct spmi_voltage_range *range;
630 int diff_uV;
631
632 range = spmi_regulator_find_range(vreg);
633 if (!range)
634 return -EINVAL;
635
636 diff_uV = abs(new_selector - old_selector) * range->step_uV;
637
638 return DIV_ROUND_UP(diff_uV, vreg->slew_rate);
639}
640
641static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev)
642{
643 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
644 const struct spmi_voltage_range *range;
645 u8 voltage_sel;
646
647 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1);
648
649 range = spmi_regulator_find_range(vreg);
650 if (!range)
651 return VOLTAGE_UNKNOWN;
652
653 return range->step_uV * voltage_sel + range->min_uV;
654}
655
656static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev,
657 int min_uV, int max_uV, unsigned *selector)
658{
659 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
660 int ret;
661 u8 range_sel, sel;
662
663 ret = spmi_regulator_select_voltage(vreg, min_uV, max_uV, &range_sel,
664 &sel, selector);
665 if (ret) {
666 dev_err(vreg->dev, "could not set voltage, ret=%d\n", ret);
667 return ret;
668 }
669
670 /*
671 * Certain types of regulators do not have a range select register so
672 * only voltage set register needs to be written.
673 */
674 return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &sel, 1);
675}
676
677static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev)
678{
679 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
680 const struct spmi_voltage_range *range = vreg->set_points->range;
681 u8 voltage_sel;
682
683 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1);
684
685 return range->step_uV * voltage_sel + range->min_uV;
686}
687
688static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev,
689 int min_uV, int max_uV, unsigned *selector)
690{
691 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
692 int ret;
693 u8 range_sel, voltage_sel;
694
695 /*
696 * Favor staying in the current voltage range if possible. This avoids
697 * voltage spikes that occur when changing the voltage range.
698 */
699 ret = spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV,
700 &range_sel, &voltage_sel, selector);
701 if (ret)
702 return ret;
703
704 /*
705 * Calculate VSET based on range
706 * In case of range 0: voltage_sel is a 7 bit value, can be written
707 * witout any modification.
708 * In case of range 1: voltage_sel is a 5 bit value, bits[7-5] set to
709 * [011].
710 */
711 if (range_sel == 1)
712 voltage_sel |= ULT_SMPS_RANGE_SPLIT;
713
714 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET,
715 voltage_sel, 0xff);
716}
717
718static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev)
719{
720 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
721 const struct spmi_voltage_range *range;
722 u8 voltage_sel;
723
724 spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1);
725
726 range = spmi_regulator_find_range(vreg);
727 if (!range)
728 return VOLTAGE_UNKNOWN;
729
730 if (range->range_sel == 1)
731 voltage_sel &= ~ULT_SMPS_RANGE_SPLIT;
732
733 return range->step_uV * voltage_sel + range->min_uV;
734}
735
736static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev,
737 unsigned selector)
738{
739 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
740 int uV = 0;
741 int i;
742
743 if (selector >= vreg->set_points->n_voltages)
744 return 0;
745
746 for (i = 0; i < vreg->set_points->count; i++) {
747 if (selector < vreg->set_points->range[i].n_voltages) {
748 uV = selector * vreg->set_points->range[i].step_uV
749 + vreg->set_points->range[i].set_point_min_uV;
750 break;
751 }
752
753 selector -= vreg->set_points->range[i].n_voltages;
754 }
755
756 return uV;
757}
758
759static int
760spmi_regulator_common_set_bypass(struct regulator_dev *rdev, bool enable)
761{
762 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
763 u8 mask = SPMI_COMMON_MODE_BYPASS_MASK;
764 u8 val = 0;
765
766 if (enable)
767 val = mask;
768
769 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
770}
771
772static int
773spmi_regulator_common_get_bypass(struct regulator_dev *rdev, bool *enable)
774{
775 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
776 u8 val;
777 int ret;
778
779 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &val, 1);
780 *enable = val & SPMI_COMMON_MODE_BYPASS_MASK;
781
782 return ret;
783}
784
785static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev)
786{
787 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
788 u8 reg;
789
790 spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
791
792 if (reg & SPMI_COMMON_MODE_HPM_MASK)
793 return REGULATOR_MODE_NORMAL;
794
795 return REGULATOR_MODE_IDLE;
796}
797
798static int
799spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode)
800{
801 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
802 u8 mask = SPMI_COMMON_MODE_HPM_MASK;
803 u8 val = 0;
804
805 if (mode == REGULATOR_MODE_NORMAL)
806 val = mask;
807
808 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
809}
810
811static int
812spmi_regulator_common_set_load(struct regulator_dev *rdev, int load_uA)
813{
814 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
815 unsigned int mode;
816
817 if (load_uA >= vreg->hpm_min_load)
818 mode = REGULATOR_MODE_NORMAL;
819 else
820 mode = REGULATOR_MODE_IDLE;
821
822 return spmi_regulator_common_set_mode(rdev, mode);
823}
824
825static int spmi_regulator_common_set_pull_down(struct regulator_dev *rdev)
826{
827 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
828 unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK;
829
830 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_PULL_DOWN,
831 mask, mask);
832}
833
834static int spmi_regulator_common_set_soft_start(struct regulator_dev *rdev)
835{
836 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
837 unsigned int mask = SPMI_LDO_SOFT_START_ENABLE_MASK;
838
839 return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_SOFT_START,
840 mask, mask);
841}
842
843static int spmi_regulator_set_ilim(struct regulator_dev *rdev, int ilim_uA)
844{
845 struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
846 enum spmi_regulator_logical_type type = vreg->logical_type;
847 unsigned int current_reg;
848 u8 reg;
849 u8 mask = SPMI_BOOST_CURRENT_LIMIT_MASK |
850 SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK;
851 int max = (SPMI_BOOST_CURRENT_LIMIT_MASK + 1) * 500;
852
853 if (type == SPMI_REGULATOR_LOGICAL_TYPE_BOOST)
854 current_reg = SPMI_BOOST_REG_CURRENT_LIMIT;
855 else
856 current_reg = SPMI_BOOST_BYP_REG_CURRENT_LIMIT;
857
858 if (ilim_uA > max || ilim_uA <= 0)
859 return -EINVAL;
860
861 reg = (ilim_uA - 1) / 500;
862 reg |= SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK;
863
864 return spmi_vreg_update_bits(vreg, current_reg, reg, mask);
865}
866
867static int spmi_regulator_vs_clear_ocp(struct spmi_regulator *vreg)
868{
869 int ret;
870
871 ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
872 SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK);
873
874 vreg->vs_enable_time = ktime_get();
875
876 ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
877 SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK);
878
879 return ret;
880}
881
882static void spmi_regulator_vs_ocp_work(struct work_struct *work)
883{
884 struct delayed_work *dwork = to_delayed_work(work);
885 struct spmi_regulator *vreg
886 = container_of(dwork, struct spmi_regulator, ocp_work);
887
888 spmi_regulator_vs_clear_ocp(vreg);
889}
890
891static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data)
892{
893 struct spmi_regulator *vreg = data;
894 ktime_t ocp_irq_time;
895 s64 ocp_trigger_delay_us;
896
897 ocp_irq_time = ktime_get();
898 ocp_trigger_delay_us = ktime_us_delta(ocp_irq_time,
899 vreg->vs_enable_time);
900
901 /*
902 * Reset the OCP count if there is a large delay between switch enable
903 * and when OCP triggers. This is indicative of a hotplug event as
904 * opposed to a fault.
905 */
906 if (ocp_trigger_delay_us > SPMI_VS_OCP_FAULT_DELAY_US)
907 vreg->ocp_count = 0;
908
909 /* Wait for switch output to settle back to 0 V after OCP triggered. */
910 udelay(SPMI_VS_OCP_FALL_DELAY_US);
911
912 vreg->ocp_count++;
913
914 if (vreg->ocp_count == 1) {
915 /* Immediately clear the over current condition. */
916 spmi_regulator_vs_clear_ocp(vreg);
917 } else if (vreg->ocp_count <= vreg->ocp_max_retries) {
918 /* Schedule the over current clear task to run later. */
919 schedule_delayed_work(&vreg->ocp_work,
920 msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1);
921 } else {
922 dev_err(vreg->dev,
923 "OCP triggered %d times; no further retries\n",
924 vreg->ocp_count);
925 }
926
927 return IRQ_HANDLED;
928}
929
930static struct regulator_ops spmi_smps_ops = {
931 .enable = spmi_regulator_common_enable,
932 .disable = spmi_regulator_common_disable,
933 .is_enabled = spmi_regulator_common_is_enabled,
934 .set_voltage = spmi_regulator_common_set_voltage,
935 .get_voltage = spmi_regulator_common_get_voltage,
936 .list_voltage = spmi_regulator_common_list_voltage,
937 .set_mode = spmi_regulator_common_set_mode,
938 .get_mode = spmi_regulator_common_get_mode,
939 .set_load = spmi_regulator_common_set_load,
940 .set_pull_down = spmi_regulator_common_set_pull_down,
941};
942
943static struct regulator_ops spmi_ldo_ops = {
944 .enable = spmi_regulator_common_enable,
945 .disable = spmi_regulator_common_disable,
946 .is_enabled = spmi_regulator_common_is_enabled,
947 .set_voltage = spmi_regulator_common_set_voltage,
948 .get_voltage = spmi_regulator_common_get_voltage,
949 .list_voltage = spmi_regulator_common_list_voltage,
950 .set_mode = spmi_regulator_common_set_mode,
951 .get_mode = spmi_regulator_common_get_mode,
952 .set_load = spmi_regulator_common_set_load,
953 .set_bypass = spmi_regulator_common_set_bypass,
954 .get_bypass = spmi_regulator_common_get_bypass,
955 .set_pull_down = spmi_regulator_common_set_pull_down,
956 .set_soft_start = spmi_regulator_common_set_soft_start,
957};
958
959static struct regulator_ops spmi_ln_ldo_ops = {
960 .enable = spmi_regulator_common_enable,
961 .disable = spmi_regulator_common_disable,
962 .is_enabled = spmi_regulator_common_is_enabled,
963 .set_voltage = spmi_regulator_common_set_voltage,
964 .get_voltage = spmi_regulator_common_get_voltage,
965 .list_voltage = spmi_regulator_common_list_voltage,
966 .set_bypass = spmi_regulator_common_set_bypass,
967 .get_bypass = spmi_regulator_common_get_bypass,
968};
969
970static struct regulator_ops spmi_vs_ops = {
971 .enable = spmi_regulator_vs_enable,
972 .disable = spmi_regulator_common_disable,
973 .is_enabled = spmi_regulator_common_is_enabled,
974 .set_pull_down = spmi_regulator_common_set_pull_down,
975 .set_soft_start = spmi_regulator_common_set_soft_start,
976};
977
978static struct regulator_ops spmi_boost_ops = {
979 .enable = spmi_regulator_common_enable,
980 .disable = spmi_regulator_common_disable,
981 .is_enabled = spmi_regulator_common_is_enabled,
982 .set_voltage = spmi_regulator_single_range_set_voltage,
983 .get_voltage = spmi_regulator_single_range_get_voltage,
984 .list_voltage = spmi_regulator_common_list_voltage,
985 .set_input_current_limit = spmi_regulator_set_ilim,
986};
987
988static struct regulator_ops spmi_ftsmps_ops = {
989 .enable = spmi_regulator_common_enable,
990 .disable = spmi_regulator_common_disable,
991 .is_enabled = spmi_regulator_common_is_enabled,
992 .set_voltage = spmi_regulator_common_set_voltage,
993 .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel,
994 .get_voltage = spmi_regulator_common_get_voltage,
995 .list_voltage = spmi_regulator_common_list_voltage,
996 .set_mode = spmi_regulator_common_set_mode,
997 .get_mode = spmi_regulator_common_get_mode,
998 .set_load = spmi_regulator_common_set_load,
999 .set_pull_down = spmi_regulator_common_set_pull_down,
1000};
1001
1002static struct regulator_ops spmi_ult_lo_smps_ops = {
1003 .enable = spmi_regulator_common_enable,
1004 .disable = spmi_regulator_common_disable,
1005 .is_enabled = spmi_regulator_common_is_enabled,
1006 .set_voltage = spmi_regulator_ult_lo_smps_set_voltage,
1007 .get_voltage = spmi_regulator_ult_lo_smps_get_voltage,
1008 .list_voltage = spmi_regulator_common_list_voltage,
1009 .set_mode = spmi_regulator_common_set_mode,
1010 .get_mode = spmi_regulator_common_get_mode,
1011 .set_load = spmi_regulator_common_set_load,
1012 .set_pull_down = spmi_regulator_common_set_pull_down,
1013};
1014
1015static struct regulator_ops spmi_ult_ho_smps_ops = {
1016 .enable = spmi_regulator_common_enable,
1017 .disable = spmi_regulator_common_disable,
1018 .is_enabled = spmi_regulator_common_is_enabled,
1019 .set_voltage = spmi_regulator_single_range_set_voltage,
1020 .get_voltage = spmi_regulator_single_range_get_voltage,
1021 .list_voltage = spmi_regulator_common_list_voltage,
1022 .set_mode = spmi_regulator_common_set_mode,
1023 .get_mode = spmi_regulator_common_get_mode,
1024 .set_load = spmi_regulator_common_set_load,
1025 .set_pull_down = spmi_regulator_common_set_pull_down,
1026};
1027
1028static struct regulator_ops spmi_ult_ldo_ops = {
1029 .enable = spmi_regulator_common_enable,
1030 .disable = spmi_regulator_common_disable,
1031 .is_enabled = spmi_regulator_common_is_enabled,
1032 .set_voltage = spmi_regulator_single_range_set_voltage,
1033 .get_voltage = spmi_regulator_single_range_get_voltage,
1034 .list_voltage = spmi_regulator_common_list_voltage,
1035 .set_mode = spmi_regulator_common_set_mode,
1036 .get_mode = spmi_regulator_common_get_mode,
1037 .set_load = spmi_regulator_common_set_load,
1038 .set_bypass = spmi_regulator_common_set_bypass,
1039 .get_bypass = spmi_regulator_common_get_bypass,
1040 .set_pull_down = spmi_regulator_common_set_pull_down,
1041 .set_soft_start = spmi_regulator_common_set_soft_start,
1042};
1043
1044/* Maximum possible digital major revision value */
1045#define INF 0xFF
1046
1047static const struct spmi_regulator_mapping supported_regulators[] = {
1048 /* type subtype dig_min dig_max ltype ops setpoints hpm_min */
1049 SPMI_VREG(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000),
1050 SPMI_VREG(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000),
1051 SPMI_VREG(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000),
1052 SPMI_VREG(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000),
1053 SPMI_VREG(LDO, N600, 1, INF, LDO, ldo, nldo3, 10000),
1054 SPMI_VREG(LDO, N1200, 1, INF, LDO, ldo, nldo3, 10000),
1055 SPMI_VREG(LDO, N600_ST, 0, 0, LDO, ldo, nldo2, 10000),
1056 SPMI_VREG(LDO, N1200_ST, 0, 0, LDO, ldo, nldo2, 10000),
1057 SPMI_VREG(LDO, N600_ST, 1, INF, LDO, ldo, nldo3, 10000),
1058 SPMI_VREG(LDO, N1200_ST, 1, INF, LDO, ldo, nldo3, 10000),
1059 SPMI_VREG(LDO, P50, 0, INF, LDO, ldo, pldo, 5000),
1060 SPMI_VREG(LDO, P150, 0, INF, LDO, ldo, pldo, 10000),
1061 SPMI_VREG(LDO, P300, 0, INF, LDO, ldo, pldo, 10000),
1062 SPMI_VREG(LDO, P600, 0, INF, LDO, ldo, pldo, 10000),
1063 SPMI_VREG(LDO, P1200, 0, INF, LDO, ldo, pldo, 10000),
1064 SPMI_VREG(LDO, LN, 0, INF, LN_LDO, ln_ldo, ln_ldo, 0),
1065 SPMI_VREG(LDO, LV_P50, 0, INF, LDO, ldo, pldo, 5000),
1066 SPMI_VREG(LDO, LV_P150, 0, INF, LDO, ldo, pldo, 10000),
1067 SPMI_VREG(LDO, LV_P300, 0, INF, LDO, ldo, pldo, 10000),
1068 SPMI_VREG(LDO, LV_P600, 0, INF, LDO, ldo, pldo, 10000),
1069 SPMI_VREG(LDO, LV_P1200, 0, INF, LDO, ldo, pldo, 10000),
1070 SPMI_VREG_VS(LV100, 0, INF),
1071 SPMI_VREG_VS(LV300, 0, INF),
1072 SPMI_VREG_VS(MV300, 0, INF),
1073 SPMI_VREG_VS(MV500, 0, INF),
1074 SPMI_VREG_VS(HDMI, 0, INF),
1075 SPMI_VREG_VS(OTG, 0, INF),
1076 SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0),
1077 SPMI_VREG(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000),
1078 SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000),
1079 SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0),
1080 SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1081 ult_lo_smps, 100000),
1082 SPMI_VREG(ULT_BUCK, ULT_HF_CTL2, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1083 ult_lo_smps, 100000),
1084 SPMI_VREG(ULT_BUCK, ULT_HF_CTL3, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1085 ult_lo_smps, 100000),
1086 SPMI_VREG(ULT_BUCK, ULT_HF_CTL4, 0, INF, ULT_HO_SMPS, ult_ho_smps,
1087 ult_ho_smps, 100000),
1088 SPMI_VREG(ULT_LDO, N300_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1089 SPMI_VREG(ULT_LDO, N600_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1090 SPMI_VREG(ULT_LDO, N900_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1091 SPMI_VREG(ULT_LDO, N1200_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1092 SPMI_VREG(ULT_LDO, LV_P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1093 SPMI_VREG(ULT_LDO, LV_P300, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1094 SPMI_VREG(ULT_LDO, LV_P450, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1095 SPMI_VREG(ULT_LDO, P600, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1096 SPMI_VREG(ULT_LDO, P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1097 SPMI_VREG(ULT_LDO, P50, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 5000),
1098};
1099
1100static void spmi_calculate_num_voltages(struct spmi_voltage_set_points *points)
1101{
1102 unsigned int n;
1103 struct spmi_voltage_range *range = points->range;
1104
1105 for (; range < points->range + points->count; range++) {
1106 n = 0;
1107 if (range->set_point_max_uV) {
1108 n = range->set_point_max_uV - range->set_point_min_uV;
1109 n = (n / range->step_uV) + 1;
1110 }
1111 range->n_voltages = n;
1112 points->n_voltages += n;
1113 }
1114}
1115
1116static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type)
1117{
1118 const struct spmi_regulator_mapping *mapping;
1119 int ret, i;
1120 u32 dig_major_rev;
1121 u8 version[SPMI_COMMON_REG_SUBTYPE - SPMI_COMMON_REG_DIG_MAJOR_REV + 1];
1122 u8 type, subtype;
1123
1124 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version,
1125 ARRAY_SIZE(version));
1126 if (ret) {
1127 dev_err(vreg->dev, "could not read version registers\n");
1128 return ret;
1129 }
1130 dig_major_rev = version[SPMI_COMMON_REG_DIG_MAJOR_REV
1131 - SPMI_COMMON_REG_DIG_MAJOR_REV];
1132 if (!force_type) {
1133 type = version[SPMI_COMMON_REG_TYPE -
1134 SPMI_COMMON_REG_DIG_MAJOR_REV];
1135 subtype = version[SPMI_COMMON_REG_SUBTYPE -
1136 SPMI_COMMON_REG_DIG_MAJOR_REV];
1137 } else {
1138 type = force_type >> 8;
1139 subtype = force_type;
1140 }
1141
1142 for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
1143 mapping = &supported_regulators[i];
1144 if (mapping->type == type && mapping->subtype == subtype
1145 && mapping->revision_min <= dig_major_rev
1146 && mapping->revision_max >= dig_major_rev)
1147 goto found;
1148 }
1149
1150 dev_err(vreg->dev,
1151 "unsupported regulator: name=%s type=0x%02X, subtype=0x%02X, dig major rev=0x%02X\n",
1152 vreg->desc.name, type, subtype, dig_major_rev);
1153
1154 return -ENODEV;
1155
1156found:
1157 vreg->logical_type = mapping->logical_type;
1158 vreg->set_points = mapping->set_points;
1159 vreg->hpm_min_load = mapping->hpm_min_load;
1160 vreg->desc.ops = mapping->ops;
1161
1162 if (mapping->set_points) {
1163 if (!mapping->set_points->n_voltages)
1164 spmi_calculate_num_voltages(mapping->set_points);
1165 vreg->desc.n_voltages = mapping->set_points->n_voltages;
1166 }
1167
1168 return 0;
1169}
1170
1171static int spmi_regulator_ftsmps_init_slew_rate(struct spmi_regulator *vreg)
1172{
1173 int ret;
1174 u8 reg = 0;
1175 int step, delay, slew_rate;
1176 const struct spmi_voltage_range *range;
1177
1178 ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
1179 if (ret) {
1180 dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret);
1181 return ret;
1182 }
1183
1184 range = spmi_regulator_find_range(vreg);
1185 if (!range)
1186 return -EINVAL;
1187
1188 step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK;
1189 step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT;
1190
1191 delay = reg & SPMI_FTSMPS_STEP_CTRL_DELAY_MASK;
1192 delay >>= SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT;
1193
1194 /* slew_rate has units of uV/us */
1195 slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step);
1196 slew_rate /= 1000 * (SPMI_FTSMPS_STEP_DELAY << delay);
1197 slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM;
1198 slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN;
1199
1200 /* Ensure that the slew rate is greater than 0 */
1201 vreg->slew_rate = max(slew_rate, 1);
1202
1203 return ret;
1204}
1205
1206static unsigned int spmi_regulator_of_map_mode(unsigned int mode)
1207{
1208 if (mode)
1209 return REGULATOR_MODE_NORMAL;
1210
1211 return REGULATOR_MODE_IDLE;
1212}
1213
1214static int spmi_regulator_of_parse(struct device_node *node,
1215 const struct regulator_desc *desc,
1216 struct regulator_config *config)
1217{
1218 struct spmi_regulator *vreg = config->driver_data;
1219 struct device *dev = config->dev;
1220 int ret;
1221
1222 vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES;
1223 vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS;
1224
1225 if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS) {
1226 ret = spmi_regulator_ftsmps_init_slew_rate(vreg);
1227 if (ret)
1228 return ret;
1229 }
1230
1231 if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS)
1232 vreg->ocp_irq = 0;
1233
1234 if (vreg->ocp_irq) {
1235 ret = devm_request_irq(dev, vreg->ocp_irq,
1236 spmi_regulator_vs_ocp_isr, IRQF_TRIGGER_RISING, "ocp",
1237 vreg);
1238 if (ret < 0) {
1239 dev_err(dev, "failed to request irq %d, ret=%d\n",
1240 vreg->ocp_irq, ret);
1241 return ret;
1242 }
1243
1244 INIT_DELAYED_WORK(&vreg->ocp_work, spmi_regulator_vs_ocp_work);
1245 }
1246
1247 return 0;
1248}
1249
1250static const struct spmi_regulator_data pm8941_regulators[] = {
1251 { "s1", 0x1400, "vdd_s1", },
1252 { "s2", 0x1700, "vdd_s2", },
1253 { "s3", 0x1a00, "vdd_s3", },
1254 { "l1", 0x4000, "vdd_l1_l3", },
1255 { "l2", 0x4100, "vdd_l2_lvs_1_2_3", },
1256 { "l3", 0x4200, "vdd_l1_l3", },
1257 { "l4", 0x4300, "vdd_l4_l11", },
1258 { "l5", 0x4400, "vdd_l5_l7", NULL, 0x0410 },
1259 { "l6", 0x4500, "vdd_l6_l12_l14_l15", },
1260 { "l7", 0x4600, "vdd_l5_l7", NULL, 0x0410 },
1261 { "l8", 0x4700, "vdd_l8_l16_l18_19", },
1262 { "l9", 0x4800, "vdd_l9_l10_l17_l22", },
1263 { "l10", 0x4900, "vdd_l9_l10_l17_l22", },
1264 { "l11", 0x4a00, "vdd_l4_l11", },
1265 { "l12", 0x4b00, "vdd_l6_l12_l14_l15", },
1266 { "l13", 0x4c00, "vdd_l13_l20_l23_l24", },
1267 { "l14", 0x4d00, "vdd_l6_l12_l14_l15", },
1268 { "l15", 0x4e00, "vdd_l6_l12_l14_l15", },
1269 { "l16", 0x4f00, "vdd_l8_l16_l18_19", },
1270 { "l17", 0x5000, "vdd_l9_l10_l17_l22", },
1271 { "l18", 0x5100, "vdd_l8_l16_l18_19", },
1272 { "l19", 0x5200, "vdd_l8_l16_l18_19", },
1273 { "l20", 0x5300, "vdd_l13_l20_l23_l24", },
1274 { "l21", 0x5400, "vdd_l21", },
1275 { "l22", 0x5500, "vdd_l9_l10_l17_l22", },
1276 { "l23", 0x5600, "vdd_l13_l20_l23_l24", },
1277 { "l24", 0x5700, "vdd_l13_l20_l23_l24", },
1278 { "lvs1", 0x8000, "vdd_l2_lvs_1_2_3", },
1279 { "lvs2", 0x8100, "vdd_l2_lvs_1_2_3", },
1280 { "lvs3", 0x8200, "vdd_l2_lvs_1_2_3", },
1281 { "mvs1", 0x8300, "vin_5vs", },
1282 { "mvs2", 0x8400, "vin_5vs", },
1283 { }
1284};
1285
1286static const struct spmi_regulator_data pm8841_regulators[] = {
1287 { "s1", 0x1400, "vdd_s1", },
1288 { "s2", 0x1700, "vdd_s2", NULL, 0x1c08 },
1289 { "s3", 0x1a00, "vdd_s3", },
1290 { "s4", 0x1d00, "vdd_s4", NULL, 0x1c08 },
1291 { "s5", 0x2000, "vdd_s5", NULL, 0x1c08 },
1292 { "s6", 0x2300, "vdd_s6", NULL, 0x1c08 },
1293 { "s7", 0x2600, "vdd_s7", NULL, 0x1c08 },
1294 { "s8", 0x2900, "vdd_s8", NULL, 0x1c08 },
1295 { }
1296};
1297
1298static const struct spmi_regulator_data pm8916_regulators[] = {
1299 { "s1", 0x1400, "vdd_s1", },
1300 { "s2", 0x1700, "vdd_s2", },
1301 { "s3", 0x1a00, "vdd_s3", },
1302 { "s4", 0x1d00, "vdd_s4", },
1303 { "l1", 0x4000, "vdd_l1_l3", },
1304 { "l2", 0x4100, "vdd_l2", },
1305 { "l3", 0x4200, "vdd_l1_l3", },
1306 { "l4", 0x4300, "vdd_l4_l5_l6", },
1307 { "l5", 0x4400, "vdd_l4_l5_l6", },
1308 { "l6", 0x4500, "vdd_l4_l5_l6", },
1309 { "l7", 0x4600, "vdd_l7", },
1310 { "l8", 0x4700, "vdd_l8_l11_l14_l15_l16", },
1311 { "l9", 0x4800, "vdd_l9_l10_l12_l13_l17_l18", },
1312 { "l10", 0x4900, "vdd_l9_l10_l12_l13_l17_l18", },
1313 { "l11", 0x4a00, "vdd_l8_l11_l14_l15_l16", },
1314 { "l12", 0x4b00, "vdd_l9_l10_l12_l13_l17_l18", },
1315 { "l13", 0x4c00, "vdd_l9_l10_l12_l13_l17_l18", },
1316 { "l14", 0x4d00, "vdd_l8_l11_l14_l15_l16", },
1317 { "l15", 0x4e00, "vdd_l8_l11_l14_l15_l16", },
1318 { "l16", 0x4f00, "vdd_l8_l11_l14_l15_l16", },
1319 { "l17", 0x5000, "vdd_l9_l10_l12_l13_l17_l18", },
1320 { "l18", 0x5100, "vdd_l9_l10_l12_l13_l17_l18", },
1321 { }
1322};
1323
1324static const struct of_device_id qcom_spmi_regulator_match[] = {
1325 { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators },
1326 { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators },
1327 { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators },
1328 { }
1329};
1330MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);
1331
1332static int qcom_spmi_regulator_probe(struct platform_device *pdev)
1333{
1334 const struct spmi_regulator_data *reg;
1335 const struct of_device_id *match;
1336 struct regulator_config config = { };
1337 struct regulator_dev *rdev;
1338 struct spmi_regulator *vreg;
1339 struct regmap *regmap;
1340 const char *name;
1341 struct device *dev = &pdev->dev;
1342 int ret;
1343 struct list_head *vreg_list;
1344
1345 vreg_list = devm_kzalloc(dev, sizeof(*vreg_list), GFP_KERNEL);
1346 if (!vreg_list)
1347 return -ENOMEM;
1348 INIT_LIST_HEAD(vreg_list);
1349 platform_set_drvdata(pdev, vreg_list);
1350
1351 regmap = dev_get_regmap(dev->parent, NULL);
1352 if (!regmap)
1353 return -ENODEV;
1354
1355 match = of_match_device(qcom_spmi_regulator_match, &pdev->dev);
1356 if (!match)
1357 return -ENODEV;
1358
1359 for (reg = match->data; reg->name; reg++) {
1360 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
1361 if (!vreg)
1362 return -ENOMEM;
1363
1364 vreg->dev = dev;
1365 vreg->base = reg->base;
1366 vreg->regmap = regmap;
1367
1368 if (reg->ocp) {
1369 vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp);
1370 if (vreg->ocp_irq < 0) {
1371 ret = vreg->ocp_irq;
1372 goto err;
1373 }
1374 }
1375
1376 vreg->desc.id = -1;
1377 vreg->desc.owner = THIS_MODULE;
1378 vreg->desc.type = REGULATOR_VOLTAGE;
1379 vreg->desc.name = name = reg->name;
1380 vreg->desc.supply_name = reg->supply;
1381 vreg->desc.of_match = reg->name;
1382 vreg->desc.of_parse_cb = spmi_regulator_of_parse;
1383 vreg->desc.of_map_mode = spmi_regulator_of_map_mode;
1384
1385 ret = spmi_regulator_match(vreg, reg->force_type);
1386 if (ret)
1387 goto err;
1388
1389 config.dev = dev;
1390 config.driver_data = vreg;
1391 rdev = devm_regulator_register(dev, &vreg->desc, &config);
1392 if (IS_ERR(rdev)) {
1393 dev_err(dev, "failed to register %s\n", name);
1394 ret = PTR_ERR(rdev);
1395 goto err;
1396 }
1397
1398 INIT_LIST_HEAD(&vreg->node);
1399 list_add(&vreg->node, vreg_list);
1400 }
1401
1402 return 0;
1403
1404err:
1405 list_for_each_entry(vreg, vreg_list, node)
1406 if (vreg->ocp_irq)
1407 cancel_delayed_work_sync(&vreg->ocp_work);
1408 return ret;
1409}
1410
1411static int qcom_spmi_regulator_remove(struct platform_device *pdev)
1412{
1413 struct spmi_regulator *vreg;
1414 struct list_head *vreg_list = platform_get_drvdata(pdev);
1415
1416 list_for_each_entry(vreg, vreg_list, node)
1417 if (vreg->ocp_irq)
1418 cancel_delayed_work_sync(&vreg->ocp_work);
1419
1420 return 0;
1421}
1422
1423static struct platform_driver qcom_spmi_regulator_driver = {
1424 .driver = {
1425 .name = "qcom-spmi-regulator",
1426 .of_match_table = qcom_spmi_regulator_match,
1427 },
1428 .probe = qcom_spmi_regulator_probe,
1429 .remove = qcom_spmi_regulator_remove,
1430};
1431module_platform_driver(qcom_spmi_regulator_driver);
1432
1433MODULE_DESCRIPTION("Qualcomm SPMI PMIC regulator driver");
1434MODULE_LICENSE("GPL v2");
1435MODULE_ALIAS("platform:qcom-spmi-regulator");
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index ff828117798f..326ffb553371 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -515,7 +515,7 @@ static int s2mps14_regulator_enable(struct regulator_dev *rdev)
515 break; 515 break;
516 default: 516 default:
517 return -EINVAL; 517 return -EINVAL;
518 }; 518 }
519 519
520 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 520 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
521 rdev->desc->enable_mask, val); 521 rdev->desc->enable_mask, val);
@@ -538,7 +538,7 @@ static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
538 default: 538 default:
539 state = S2MPS14_ENABLE_SUSPEND; 539 state = S2MPS14_ENABLE_SUSPEND;
540 break; 540 break;
541 }; 541 }
542 break; 542 break;
543 case S2MPU02: 543 case S2MPU02:
544 switch (rdev_id) { 544 switch (rdev_id) {
@@ -552,11 +552,11 @@ static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
552 default: 552 default:
553 state = S2MPU02_ENABLE_SUSPEND; 553 state = S2MPU02_ENABLE_SUSPEND;
554 break; 554 break;
555 }; 555 }
556 break; 556 break;
557 default: 557 default:
558 return -EINVAL; 558 return -EINVAL;
559 }; 559 }
560 560
561 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); 561 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
562 if (ret < 0) 562 if (ret < 0)
@@ -977,7 +977,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
977 dev_err(&pdev->dev, "Invalid device type: %u\n", 977 dev_err(&pdev->dev, "Invalid device type: %u\n",
978 s2mps11->dev_type); 978 s2mps11->dev_type);
979 return -EINVAL; 979 return -EINVAL;
980 }; 980 }
981 981
982 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev, 982 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
983 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num, 983 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 0d7e164a5e76..8cbb82ceec40 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -533,7 +533,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
533 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 533 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
534 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 534 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
535 wm831x_dcdc_uv_irq, 535 wm831x_dcdc_uv_irq,
536 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 536 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
537 dcdc->name, dcdc);
537 if (ret != 0) { 538 if (ret != 0) {
538 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 539 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
539 irq, ret); 540 irq, ret);
@@ -543,7 +544,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
543 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")); 544 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC"));
544 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 545 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
545 wm831x_dcdc_oc_irq, 546 wm831x_dcdc_oc_irq,
546 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 547 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
548 dcdc->name, dcdc);
547 if (ret != 0) { 549 if (ret != 0) {
548 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n", 550 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n",
549 irq, ret); 551 irq, ret);
@@ -669,7 +671,8 @@ static int wm831x_buckp_probe(struct platform_device *pdev)
669 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 671 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
670 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 672 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
671 wm831x_dcdc_uv_irq, 673 wm831x_dcdc_uv_irq,
672 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 674 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
675 dcdc->name, dcdc);
673 if (ret != 0) { 676 if (ret != 0) {
674 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 677 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
675 irq, ret); 678 irq, ret);
@@ -785,7 +788,8 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
785 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 788 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
786 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 789 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
787 wm831x_dcdc_uv_irq, 790 wm831x_dcdc_uv_irq,
788 IRQF_TRIGGER_RISING, dcdc->name, 791 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
792 dcdc->name,
789 dcdc); 793 dcdc);
790 if (ret != 0) { 794 if (ret != 0) {
791 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 795 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 1e88391a1628..1442828fcd9a 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -204,7 +204,8 @@ static int wm831x_isink_probe(struct platform_device *pdev)
204 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0)); 204 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0));
205 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 205 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
206 wm831x_isink_irq, 206 wm831x_isink_irq,
207 IRQF_TRIGGER_RISING, isink->name, 207 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
208 isink->name,
208 isink); 209 isink);
209 if (ret != 0) { 210 if (ret != 0) {
210 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n", 211 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n",
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 7ae2dc82f636..5a7b65e8a529 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -287,7 +287,8 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
287 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 287 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
288 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 288 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
289 wm831x_ldo_uv_irq, 289 wm831x_ldo_uv_irq,
290 IRQF_TRIGGER_RISING, ldo->name, 290 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
291 ldo->name,
291 ldo); 292 ldo);
292 if (ret != 0) { 293 if (ret != 0) {
293 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 294 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
@@ -496,7 +497,8 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
496 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 497 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
497 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 498 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
498 wm831x_ldo_uv_irq, 499 wm831x_ldo_uv_irq,
499 IRQF_TRIGGER_RISING, ldo->name, ldo); 500 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
501 ldo->name, ldo);
500 if (ret != 0) { 502 if (ret != 0) {
501 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 503 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
502 irq, ret); 504 irq, ret);
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index fffa688ac3a7..4db9fbe4889d 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -91,6 +91,7 @@ struct regulator_linear_range {
91 * @set_current_limit: Configure a limit for a current-limited regulator. 91 * @set_current_limit: Configure a limit for a current-limited regulator.
92 * The driver should select the current closest to max_uA. 92 * The driver should select the current closest to max_uA.
93 * @get_current_limit: Get the configured limit for a current-limited regulator. 93 * @get_current_limit: Get the configured limit for a current-limited regulator.
94 * @set_input_current_limit: Configure an input limit.
94 * 95 *
95 * @set_mode: Set the configured operating mode for the regulator. 96 * @set_mode: Set the configured operating mode for the regulator.
96 * @get_mode: Get the configured operating mode for the regulator. 97 * @get_mode: Get the configured operating mode for the regulator.
@@ -111,6 +112,7 @@ struct regulator_linear_range {
111 * to stabilise after being set to a new value, in microseconds. 112 * to stabilise after being set to a new value, in microseconds.
112 * The function provides the from and to voltage selector, the 113 * The function provides the from and to voltage selector, the
113 * function should return the worst case. 114 * function should return the worst case.
115 * @set_soft_start: Enable soft start for the regulator.
114 * 116 *
115 * @set_suspend_voltage: Set the voltage for the regulator when the system 117 * @set_suspend_voltage: Set the voltage for the regulator when the system
116 * is suspended. 118 * is suspended.
@@ -121,6 +123,9 @@ struct regulator_linear_range {
121 * @set_suspend_mode: Set the operating mode for the regulator when the 123 * @set_suspend_mode: Set the operating mode for the regulator when the
122 * system is suspended. 124 * system is suspended.
123 * 125 *
126 * @set_pull_down: Configure the regulator to pull down when the regulator
127 * is disabled.
128 *
124 * This struct describes regulator operations which can be implemented by 129 * This struct describes regulator operations which can be implemented by
125 * regulator chip drivers. 130 * regulator chip drivers.
126 */ 131 */
@@ -142,6 +147,8 @@ struct regulator_ops {
142 int min_uA, int max_uA); 147 int min_uA, int max_uA);
143 int (*get_current_limit) (struct regulator_dev *); 148 int (*get_current_limit) (struct regulator_dev *);
144 149
150 int (*set_input_current_limit) (struct regulator_dev *, int lim_uA);
151
145 /* enable/disable regulator */ 152 /* enable/disable regulator */
146 int (*enable) (struct regulator_dev *); 153 int (*enable) (struct regulator_dev *);
147 int (*disable) (struct regulator_dev *); 154 int (*disable) (struct regulator_dev *);
@@ -158,6 +165,8 @@ struct regulator_ops {
158 unsigned int old_selector, 165 unsigned int old_selector,
159 unsigned int new_selector); 166 unsigned int new_selector);
160 167
168 int (*set_soft_start) (struct regulator_dev *);
169
161 /* report regulator status ... most other accessors report 170 /* report regulator status ... most other accessors report
162 * control inputs, this reports results of combining inputs 171 * control inputs, this reports results of combining inputs
163 * from Linux (and other sources) with the actual load. 172 * from Linux (and other sources) with the actual load.
@@ -187,6 +196,8 @@ struct regulator_ops {
187 196
188 /* set regulator suspend operating mode (defined in consumer.h) */ 197 /* set regulator suspend operating mode (defined in consumer.h) */
189 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); 198 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode);
199
200 int (*set_pull_down) (struct regulator_dev *);
190}; 201};
191 202
192/* 203/*
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index b07562e082c4..b11be1260129 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -75,6 +75,8 @@ struct regulator_state {
75 * 75 *
76 * @min_uA: Smallest current consumers may set. 76 * @min_uA: Smallest current consumers may set.
77 * @max_uA: Largest current consumers may set. 77 * @max_uA: Largest current consumers may set.
78 * @ilim_uA: Maximum input current.
79 * @system_load: Load that isn't captured by any consumer requests.
78 * 80 *
79 * @valid_modes_mask: Mask of modes which may be configured by consumers. 81 * @valid_modes_mask: Mask of modes which may be configured by consumers.
80 * @valid_ops_mask: Operations which may be performed by consumers. 82 * @valid_ops_mask: Operations which may be performed by consumers.
@@ -86,6 +88,8 @@ struct regulator_state {
86 * applied. 88 * applied.
87 * @apply_uV: Apply the voltage constraint when initialising. 89 * @apply_uV: Apply the voltage constraint when initialising.
88 * @ramp_disable: Disable ramp delay when initialising or when setting voltage. 90 * @ramp_disable: Disable ramp delay when initialising or when setting voltage.
91 * @soft_start: Enable soft start so that voltage ramps slowly.
92 * @pull_down: Enable pull down when regulator is disabled.
89 * 93 *
90 * @input_uV: Input voltage for regulator when supplied by another regulator. 94 * @input_uV: Input voltage for regulator when supplied by another regulator.
91 * 95 *
@@ -111,6 +115,9 @@ struct regulation_constraints {
111 /* current output range (inclusive) - for current control */ 115 /* current output range (inclusive) - for current control */
112 int min_uA; 116 int min_uA;
113 int max_uA; 117 int max_uA;
118 int ilim_uA;
119
120 int system_load;
114 121
115 /* valid regulator operating modes for this machine */ 122 /* valid regulator operating modes for this machine */
116 unsigned int valid_modes_mask; 123 unsigned int valid_modes_mask;
@@ -138,6 +145,8 @@ struct regulation_constraints {
138 unsigned boot_on:1; /* bootloader/firmware enabled regulator */ 145 unsigned boot_on:1; /* bootloader/firmware enabled regulator */
139 unsigned apply_uV:1; /* apply uV constraint if min == max */ 146 unsigned apply_uV:1; /* apply uV constraint if min == max */
140 unsigned ramp_disable:1; /* disable ramp delay */ 147 unsigned ramp_disable:1; /* disable ramp delay */
148 unsigned soft_start:1; /* ramp voltage slowly */
149 unsigned pull_down:1; /* pull down resistor when regulator off */
141}; 150};
142 151
143/** 152/**
diff --git a/include/linux/regulator/max8973-regulator.h b/include/linux/regulator/max8973-regulator.h
index f8acc052e353..f6a8a16a0d4d 100644
--- a/include/linux/regulator/max8973-regulator.h
+++ b/include/linux/regulator/max8973-regulator.h
@@ -58,6 +58,9 @@
58 * control signal from EN input pin. If it is false then 58 * control signal from EN input pin. If it is false then
59 * voltage output will be enabled/disabled through EN bit of 59 * voltage output will be enabled/disabled through EN bit of
60 * device register. 60 * device register.
61 * @enable_gpio: Enable GPIO. If EN pin is controlled through GPIO from host
62 * then GPIO number can be provided. If no GPIO controlled then
63 * it should be -1.
61 * @dvs_gpio: GPIO for dvs. It should be -1 if this is tied with fixed logic. 64 * @dvs_gpio: GPIO for dvs. It should be -1 if this is tied with fixed logic.
62 * @dvs_def_state: Default state of dvs. 1 if it is high else 0. 65 * @dvs_def_state: Default state of dvs. 1 if it is high else 0.
63 */ 66 */
@@ -65,6 +68,7 @@ struct max8973_regulator_platform_data {
65 struct regulator_init_data *reg_init_data; 68 struct regulator_init_data *reg_init_data;
66 unsigned long control_flags; 69 unsigned long control_flags;
67 bool enable_ext_control; 70 bool enable_ext_control;
71 int enable_gpio;
68 int dvs_gpio; 72 int dvs_gpio;
69 unsigned dvs_def_state:1; 73 unsigned dvs_def_state:1;
70}; 74};