aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-12 00:55:17 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-12 00:55:17 -0500
commitc6d65bf246fbba6e9042a35aba050d2a92f39505 (patch)
tree896fbb104de505b413c3ef43707514fd886f4f78
parent4fc9ed3344758f22b57db174914b60423c7c1593 (diff)
parentd4d5cef649d1042454c286474343cec50ff1cb60 (diff)
Merge tag 'regulator-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "Lots of driver updates here plus some nice new core features, the main one being the first: - Enable support for providing a dummy regulator when we know that one must exist for the device to be functional. This makes it much easier to add regulator support to drivers since we don't require that the machine integration for all systems using the device be updated to provide regulators. - Substantial reduction in the amount of busy waiting done while waiting for enables to complete. - Allow MFDs to distribute regulator supplies to child devices so we don't have to expose the internal structure of MFDs outside of the driver. - Managed registeration for regulators" * tag 'regulator-v3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (113 commits) regulator: s5m8767: Modify parsing method of the voltage table of buck2/3/4 regulator: s5m8767: Modify parse_dt function to parse data related to ramp regulator: da9052: Revert se apply_[reg|bit] with regmap based voltage_sel operations mfd: arizona: Specify supply mappings for Arizona CODECs mfd: Allow mapping regulator supplies to MFD device from children regulator: core: Add ability to create a lookup alias for supply regulator: tps65910: Fix checkpatch issue regulator: tps65023: Fix checkpatch issue regulator: tps6105x: Fix checkpatch issue regulator: mc13783: Fix checkpatch issue regulator: max8997: Fix checkpatch issue regulator: lp3971: Fix checkpatch issue regulator: fixed: Fix checkpatch issue regulator: anatop: Fix checkpatch issue regulator: Add REGULATOR_LINEAR_RANGE macro regulator: Remove max_uV from struct regulator_linear_range regulator: ti-abb: Fix operator precedence typo regulator: tps65910: get regulators node from parent node only regulator: tps6586x: get regulators node from parent node only regulator: tps65090: get regulators node from parent node only ...
-rw-r--r--Documentation/devicetree/bindings/regulator/as3722-regulator.txt91
-rw-r--r--Documentation/devicetree/bindings/regulator/da9210.txt21
-rw-r--r--Documentation/devicetree/bindings/regulator/palmas-pmic.txt12
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt5
-rw-r--r--Documentation/driver-model/devres.txt1
-rw-r--r--arch/arm/mach-s3c64xx/mach-crag6410.c12
-rw-r--r--drivers/mfd/arizona-core.c32
-rw-r--r--drivers/mfd/mfd-core.c22
-rw-r--r--drivers/regulator/88pm800.c12
-rw-r--r--drivers/regulator/88pm8607.c12
-rw-r--r--drivers/regulator/Kconfig26
-rw-r--r--drivers/regulator/Makefile4
-rw-r--r--drivers/regulator/aat2870-regulator.c11
-rw-r--r--drivers/regulator/ab3100.c3
-rw-r--r--drivers/regulator/ab8500-ext.c26
-rw-r--r--drivers/regulator/ad5398.c19
-rw-r--r--drivers/regulator/anatop-regulator.c7
-rw-r--r--drivers/regulator/arizona-ldo1.c12
-rw-r--r--drivers/regulator/arizona-micsupp.c14
-rw-r--r--drivers/regulator/as3711-regulator.c43
-rw-r--r--drivers/regulator/as3722-regulator.c908
-rw-r--r--drivers/regulator/core.c455
-rw-r--r--drivers/regulator/da903x.c17
-rw-r--r--drivers/regulator/da9052-regulator.c55
-rw-r--r--drivers/regulator/da9055-regulator.c24
-rw-r--r--drivers/regulator/da9063-regulator.c23
-rw-r--r--drivers/regulator/da9210-regulator.c19
-rw-r--r--drivers/regulator/devres.c415
-rw-r--r--drivers/regulator/fan53555.c12
-rw-r--r--drivers/regulator/fixed.c38
-rw-r--r--drivers/regulator/gpio-regulator.c1
-rw-r--r--drivers/regulator/helpers.c6
-rw-r--r--drivers/regulator/internal.h38
-rw-r--r--drivers/regulator/isl6271a-regulator.c24
-rw-r--r--drivers/regulator/lp3971.c4
-rw-r--r--drivers/regulator/lp872x.c33
-rw-r--r--drivers/regulator/lp8788-buck.c12
-rw-r--r--drivers/regulator/lp8788-ldo.c24
-rw-r--r--drivers/regulator/max1586.c26
-rw-r--r--drivers/regulator/max77686.c23
-rw-r--r--drivers/regulator/max77693.c29
-rw-r--r--drivers/regulator/max8649.c14
-rw-r--r--drivers/regulator/max8660.c30
-rw-r--r--drivers/regulator/max8907-regulator.c23
-rw-r--r--drivers/regulator/max8925-regulator.c12
-rw-r--r--drivers/regulator/max8973-regulator.c11
-rw-r--r--drivers/regulator/max8997.c44
-rw-r--r--drivers/regulator/max8998.c35
-rw-r--r--drivers/regulator/mc13783-regulator.c53
-rw-r--r--drivers/regulator/mc13892-regulator.c22
-rw-r--r--drivers/regulator/of_regulator.c6
-rw-r--r--drivers/regulator/palmas-regulator.c208
-rw-r--r--drivers/regulator/pcap-regulator.c13
-rw-r--r--drivers/regulator/pcf50633-regulator.c13
-rw-r--r--drivers/regulator/rc5t583-regulator.c22
-rw-r--r--drivers/regulator/s2mps11.c23
-rw-r--r--drivers/regulator/s5m8767.c86
-rw-r--r--drivers/regulator/stw481x-vmmc.c111
-rw-r--r--drivers/regulator/ti-abb-regulator.c86
-rw-r--r--drivers/regulator/tps51632-regulator.c11
-rw-r--r--drivers/regulator/tps6105x-regulator.c15
-rw-r--r--drivers/regulator/tps62360-regulator.c17
-rw-r--r--drivers/regulator/tps65023-regulator.c25
-rw-r--r--drivers/regulator/tps6507x-regulator.c23
-rw-r--r--drivers/regulator/tps65090-regulator.c37
-rw-r--r--drivers/regulator/tps65217-regulator.c50
-rw-r--r--drivers/regulator/tps6524x-regulator.c32
-rw-r--r--drivers/regulator/tps6586x-regulator.c33
-rw-r--r--drivers/regulator/tps65910-regulator.c33
-rw-r--r--drivers/regulator/tps65912-regulator.c33
-rw-r--r--drivers/regulator/tps80031-regulator.c30
-rw-r--r--drivers/regulator/twl-regulator.c3
-rw-r--r--drivers/regulator/vexpress.c3
-rw-r--r--drivers/regulator/wm831x-dcdc.c118
-rw-r--r--drivers/regulator/wm831x-isink.c25
-rw-r--r--drivers/regulator/wm831x-ldo.c75
-rw-r--r--drivers/regulator/wm8350-regulator.c12
-rw-r--r--drivers/regulator/wm8400-regulator.c19
-rw-r--r--drivers/regulator/wm8994-regulator.c14
-rw-r--r--include/linux/mfd/core.h6
-rw-r--r--include/linux/regulator/consumer.h79
-rw-r--r--include/linux/regulator/driver.h18
-rw-r--r--include/linux/regulator/machine.h7
83 files changed, 2582 insertions, 1519 deletions
diff --git a/Documentation/devicetree/bindings/regulator/as3722-regulator.txt b/Documentation/devicetree/bindings/regulator/as3722-regulator.txt
new file mode 100644
index 000000000000..caad0c8a258d
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/as3722-regulator.txt
@@ -0,0 +1,91 @@
1Regulator of AMS AS3722 PMIC.
2Name of the regulator subnode must be "regulators".
3
4Optional properties:
5--------------------
6The input supply of regulators are the optional properties on the
7regulator node. The AS3722 is having 7 DCDC step-down regulators as
8sd[0-6], 10 LDOs as ldo[0-7], ldo[9-11]. The input supply of these
9regulators are provided through following properties:
10vsup-sd2-supply: Input supply for SD2.
11vsup-sd3-supply: Input supply for SD3.
12vsup-sd4-supply: Input supply for SD4.
13vsup-sd5-supply: Input supply for SD5.
14vin-ldo0-supply: Input supply for LDO0.
15vin-ldo1-6-supply: Input supply for LDO1 and LDO6.
16vin-ldo2-5-7-supply: Input supply for LDO2, LDO5 and LDO7.
17vin-ldo3-4-supply: Input supply for LDO3 and LDO4.
18vin-ldo9-10-supply: Input supply for LDO9 and LDO10.
19vin-ldo11-supply: Input supply for LDO11.
20
21Optional nodes:
22--------------
23- regulators : Must contain a sub-node per regulator from the list below.
24 Each sub-node should contain the constraints and initialization
25 information for that regulator. See regulator.txt for a
26 description of standard properties for these sub-nodes.
27 Additional custom properties are listed below.
28 sd[0-6], ldo[0-7], ldo[9-11].
29
30 Optional sub-node properties:
31 ----------------------------
32 ams,ext-control: External control of the rail. The option of
33 this properties will tell which external input is
34 controlling this rail. Valid values are 0, 1, 2 ad 3.
35 0: There is no external control of this rail.
36 1: Rail is controlled by ENABLE1 input pin.
37 2: Rail is controlled by ENABLE2 input pin.
38 3: Rail is controlled by ENABLE3 input pin.
39 ams,enable-tracking: Enable tracking with SD1, only supported
40 by LDO3.
41
42Example:
43-------
44 ams3722: ams3722 {
45 compatible = "ams,as3722";
46 reg = <0x40>;
47 ...
48
49 regulators {
50 vsup-sd2-supply = <...>;
51 ...
52
53 sd0 {
54 regulator-name = "vdd_cpu";
55 regulator-min-microvolt = <700000>;
56 regulator-max-microvolt = <1400000>;
57 regulator-always-on;
58 ams,ext-control = <2>;
59 };
60
61 sd1 {
62 regulator-name = "vdd_core";
63 regulator-min-microvolt = <700000>;
64 regulator-max-microvolt = <1400000>;
65 regulator-always-on;
66 ams,ext-control = <1>;
67 };
68
69 sd2 {
70 regulator-name = "vddio_ddr";
71 regulator-min-microvolt = <1350000>;
72 regulator-max-microvolt = <1350000>;
73 regulator-always-on;
74 };
75
76 sd4 {
77 regulator-name = "avdd-hdmi-pex";
78 regulator-min-microvolt = <1050000>;
79 regulator-max-microvolt = <1050000>;
80 regulator-always-on;
81 };
82
83 sd5 {
84 regulator-name = "vdd-1v8";
85 regulator-min-microvolt = <1800000>;
86 regulator-max-microvolt = <1800000>;
87 regulator-always-on;
88 };
89 ....
90 };
91 };
diff --git a/Documentation/devicetree/bindings/regulator/da9210.txt b/Documentation/devicetree/bindings/regulator/da9210.txt
new file mode 100644
index 000000000000..f120f229d67d
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/da9210.txt
@@ -0,0 +1,21 @@
1* Dialog Semiconductor DA9210 Voltage Regulator
2
3Required properties:
4
5- compatible: must be "diasemi,da9210"
6- reg: the i2c slave address of the regulator. It should be 0x68.
7
8Any standard regulator properties can be used to configure the single da9210
9DCDC.
10
11Example:
12
13 da9210@68 {
14 compatible = "diasemi,da9210";
15 reg = <0x68>;
16
17 regulator-min-microvolt = <900000>;
18 regulator-max-microvolt = <1000000>;
19 regulator-boot-on;
20 regulator-always-on;
21 };
diff --git a/Documentation/devicetree/bindings/regulator/palmas-pmic.txt b/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
index 875639ae0606..42e6b6bc48ff 100644
--- a/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
+++ b/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
@@ -26,11 +26,17 @@ Optional nodes:
26 26
27 For ti,palmas-pmic - smps12, smps123, smps3 depending on OTP, 27 For ti,palmas-pmic - smps12, smps123, smps3 depending on OTP,
28 smps45, smps457, smps7 depending on variant, smps6, smps[8-9], 28 smps45, smps457, smps7 depending on variant, smps6, smps[8-9],
29 smps10_out2, smps10_out1, do[1-9], ldoln, ldousb. 29 smps10_out2, smps10_out1, ldo[1-9], ldoln, ldousb.
30 30
31 Optional sub-node properties: 31 Optional sub-node properties:
32 ti,warm-reset - maintain voltage during warm reset(boolean) 32 ti,warm-reset - maintain voltage during warm reset(boolean)
33 ti,roof-floor - control voltage selection by pin(boolean) 33 ti,roof-floor - This takes as optional argument on platform supporting
34 the rail from desired external control. If there is no argument then
35 it will be assume that it is controlled by NSLEEP pin.
36 The valid value for external pins are:
37 ENABLE1 then 1,
38 ENABLE2 then 2 or
39 NSLEEP then 3.
34 ti,mode-sleep - mode to adopt in pmic sleep 0 - off, 1 - auto, 40 ti,mode-sleep - mode to adopt in pmic sleep 0 - off, 1 - auto,
35 2 - eco, 3 - forced pwm 41 2 - eco, 3 - forced pwm
36 ti,smps-range - OTP has the wrong range set for the hardware so override 42 ti,smps-range - OTP has the wrong range set for the hardware so override
@@ -61,7 +67,7 @@ pmic {
61 regulator-always-on; 67 regulator-always-on;
62 regulator-boot-on; 68 regulator-boot-on;
63 ti,warm-reset; 69 ti,warm-reset;
64 ti,roof-floor; 70 ti,roof-floor = <1>; /* ENABLE1 control */
65 ti,mode-sleep = <0>; 71 ti,mode-sleep = <0>;
66 ti,smps-range = <1>; 72 ti,smps-range = <1>;
67 }; 73 };
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 2bd8f0978765..e2c7f1e7251a 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -14,6 +14,11 @@ Optional properties:
14- regulator-ramp-delay: ramp delay for regulator(in uV/uS) 14- regulator-ramp-delay: ramp delay for regulator(in uV/uS)
15 For hardwares which support disabling ramp rate, it should be explicitly 15 For hardwares which support disabling ramp rate, it should be explicitly
16 intialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay. 16 intialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay.
17- 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 design requires. This property describes the total system ramp time
20 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.
17 22
18Deprecated properties: 23Deprecated properties:
19- regulator-compatible: If a regulator chip contains multiple 24- regulator-compatible: If a regulator chip contains multiple
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index fcb34a5697ea..3d9c2a766230 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -283,6 +283,7 @@ REGULATOR
283 devm_regulator_get() 283 devm_regulator_get()
284 devm_regulator_put() 284 devm_regulator_put()
285 devm_regulator_bulk_get() 285 devm_regulator_bulk_get()
286 devm_regulator_register()
286 287
287CLOCK 288CLOCK
288 devm_clk_get() 289 devm_clk_get()
diff --git a/arch/arm/mach-s3c64xx/mach-crag6410.c b/arch/arm/mach-s3c64xx/mach-crag6410.c
index 1a911df9e451..aca7d16e195d 100644
--- a/arch/arm/mach-s3c64xx/mach-crag6410.c
+++ b/arch/arm/mach-s3c64xx/mach-crag6410.c
@@ -310,10 +310,6 @@ static struct regulator_consumer_supply wallvdd_consumers[] = {
310 310
311 REGULATOR_SUPPLY("SPKVDDL", "spi0.1"), 311 REGULATOR_SUPPLY("SPKVDDL", "spi0.1"),
312 REGULATOR_SUPPLY("SPKVDDR", "spi0.1"), 312 REGULATOR_SUPPLY("SPKVDDR", "spi0.1"),
313 REGULATOR_SUPPLY("SPKVDDL", "wm5102-codec"),
314 REGULATOR_SUPPLY("SPKVDDR", "wm5102-codec"),
315 REGULATOR_SUPPLY("SPKVDDL", "wm5110-codec"),
316 REGULATOR_SUPPLY("SPKVDDR", "wm5110-codec"),
317 313
318 REGULATOR_SUPPLY("DC1VDD", "0-0034"), 314 REGULATOR_SUPPLY("DC1VDD", "0-0034"),
319 REGULATOR_SUPPLY("DC2VDD", "0-0034"), 315 REGULATOR_SUPPLY("DC2VDD", "0-0034"),
@@ -653,14 +649,6 @@ static struct regulator_consumer_supply pvdd_1v8_consumers[] = {
653 REGULATOR_SUPPLY("DBVDD3", "spi0.1"), 649 REGULATOR_SUPPLY("DBVDD3", "spi0.1"),
654 REGULATOR_SUPPLY("LDOVDD", "spi0.1"), 650 REGULATOR_SUPPLY("LDOVDD", "spi0.1"),
655 REGULATOR_SUPPLY("CPVDD", "spi0.1"), 651 REGULATOR_SUPPLY("CPVDD", "spi0.1"),
656
657 REGULATOR_SUPPLY("DBVDD2", "wm5102-codec"),
658 REGULATOR_SUPPLY("DBVDD3", "wm5102-codec"),
659 REGULATOR_SUPPLY("CPVDD", "wm5102-codec"),
660
661 REGULATOR_SUPPLY("DBVDD2", "wm5110-codec"),
662 REGULATOR_SUPPLY("DBVDD3", "wm5110-codec"),
663 REGULATOR_SUPPLY("CPVDD", "wm5110-codec"),
664}; 652};
665 653
666static struct regulator_init_data pvdd_1v8 = { 654static struct regulator_init_data pvdd_1v8 = {
diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 5ac3aa48473b..022b1863d36c 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -569,13 +569,25 @@ static struct mfd_cell early_devs[] = {
569 { .name = "arizona-ldo1" }, 569 { .name = "arizona-ldo1" },
570}; 570};
571 571
572static const char *wm5102_supplies[] = {
573 "DBVDD2",
574 "DBVDD3",
575 "CPVDD",
576 "SPKVDDL",
577 "SPKVDDR",
578};
579
572static struct mfd_cell wm5102_devs[] = { 580static struct mfd_cell wm5102_devs[] = {
573 { .name = "arizona-micsupp" }, 581 { .name = "arizona-micsupp" },
574 { .name = "arizona-extcon" }, 582 { .name = "arizona-extcon" },
575 { .name = "arizona-gpio" }, 583 { .name = "arizona-gpio" },
576 { .name = "arizona-haptics" }, 584 { .name = "arizona-haptics" },
577 { .name = "arizona-pwm" }, 585 { .name = "arizona-pwm" },
578 { .name = "wm5102-codec" }, 586 {
587 .name = "wm5102-codec",
588 .parent_supplies = wm5102_supplies,
589 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
590 },
579}; 591};
580 592
581static struct mfd_cell wm5110_devs[] = { 593static struct mfd_cell wm5110_devs[] = {
@@ -584,7 +596,17 @@ static struct mfd_cell wm5110_devs[] = {
584 { .name = "arizona-gpio" }, 596 { .name = "arizona-gpio" },
585 { .name = "arizona-haptics" }, 597 { .name = "arizona-haptics" },
586 { .name = "arizona-pwm" }, 598 { .name = "arizona-pwm" },
587 { .name = "wm5110-codec" }, 599 {
600 .name = "wm5110-codec",
601 .parent_supplies = wm5102_supplies,
602 .num_parent_supplies = ARRAY_SIZE(wm5102_supplies),
603 },
604};
605
606static const char *wm8997_supplies[] = {
607 "DBVDD2",
608 "CPVDD",
609 "SPKVDD",
588}; 610};
589 611
590static struct mfd_cell wm8997_devs[] = { 612static struct mfd_cell wm8997_devs[] = {
@@ -593,7 +615,11 @@ static struct mfd_cell wm8997_devs[] = {
593 { .name = "arizona-gpio" }, 615 { .name = "arizona-gpio" },
594 { .name = "arizona-haptics" }, 616 { .name = "arizona-haptics" },
595 { .name = "arizona-pwm" }, 617 { .name = "arizona-pwm" },
596 { .name = "wm8997-codec" }, 618 {
619 .name = "wm8997-codec",
620 .parent_supplies = wm8997_supplies,
621 .num_parent_supplies = ARRAY_SIZE(wm8997_supplies),
622 },
597}; 623};
598 624
599int arizona_dev_init(struct arizona *arizona) 625int arizona_dev_init(struct arizona *arizona)
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index f421586f29fb..adc8ea36e7c4 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -20,6 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/irqdomain.h> 21#include <linux/irqdomain.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/regulator/consumer.h>
23 24
24static struct device_type mfd_dev_type = { 25static struct device_type mfd_dev_type = {
25 .name = "mfd_device", 26 .name = "mfd_device",
@@ -99,6 +100,13 @@ static int mfd_add_device(struct device *parent, int id,
99 pdev->dev.dma_mask = parent->dma_mask; 100 pdev->dev.dma_mask = parent->dma_mask;
100 pdev->dev.dma_parms = parent->dma_parms; 101 pdev->dev.dma_parms = parent->dma_parms;
101 102
103 ret = devm_regulator_bulk_register_supply_alias(
104 &pdev->dev, cell->parent_supplies,
105 parent, cell->parent_supplies,
106 cell->num_parent_supplies);
107 if (ret < 0)
108 goto fail_res;
109
102 if (parent->of_node && cell->of_compatible) { 110 if (parent->of_node && cell->of_compatible) {
103 for_each_child_of_node(parent->of_node, np) { 111 for_each_child_of_node(parent->of_node, np) {
104 if (of_device_is_compatible(np, cell->of_compatible)) { 112 if (of_device_is_compatible(np, cell->of_compatible)) {
@@ -112,12 +120,12 @@ static int mfd_add_device(struct device *parent, int id,
112 ret = platform_device_add_data(pdev, 120 ret = platform_device_add_data(pdev,
113 cell->platform_data, cell->pdata_size); 121 cell->platform_data, cell->pdata_size);
114 if (ret) 122 if (ret)
115 goto fail_res; 123 goto fail_alias;
116 } 124 }
117 125
118 ret = mfd_platform_add_cell(pdev, cell); 126 ret = mfd_platform_add_cell(pdev, cell);
119 if (ret) 127 if (ret)
120 goto fail_res; 128 goto fail_alias;
121 129
122 for (r = 0; r < cell->num_resources; r++) { 130 for (r = 0; r < cell->num_resources; r++) {
123 res[r].name = cell->resources[r].name; 131 res[r].name = cell->resources[r].name;
@@ -152,17 +160,17 @@ static int mfd_add_device(struct device *parent, int id,
152 if (!cell->ignore_resource_conflicts) { 160 if (!cell->ignore_resource_conflicts) {
153 ret = acpi_check_resource_conflict(&res[r]); 161 ret = acpi_check_resource_conflict(&res[r]);
154 if (ret) 162 if (ret)
155 goto fail_res; 163 goto fail_alias;
156 } 164 }
157 } 165 }
158 166
159 ret = platform_device_add_resources(pdev, res, cell->num_resources); 167 ret = platform_device_add_resources(pdev, res, cell->num_resources);
160 if (ret) 168 if (ret)
161 goto fail_res; 169 goto fail_alias;
162 170
163 ret = platform_device_add(pdev); 171 ret = platform_device_add(pdev);
164 if (ret) 172 if (ret)
165 goto fail_res; 173 goto fail_alias;
166 174
167 if (cell->pm_runtime_no_callbacks) 175 if (cell->pm_runtime_no_callbacks)
168 pm_runtime_no_callbacks(&pdev->dev); 176 pm_runtime_no_callbacks(&pdev->dev);
@@ -171,6 +179,10 @@ static int mfd_add_device(struct device *parent, int id,
171 179
172 return 0; 180 return 0;
173 181
182fail_alias:
183 devm_regulator_bulk_unregister_supply_alias(&pdev->dev,
184 cell->parent_supplies,
185 cell->num_parent_supplies);
174fail_res: 186fail_res:
175 kfree(res); 187 kfree(res);
176fail_device: 188fail_device:
diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c
index 3459f60dcfd1..d333f7eac106 100644
--- a/drivers/regulator/88pm800.c
+++ b/drivers/regulator/88pm800.c
@@ -141,18 +141,14 @@ struct pm800_regulators {
141 141
142/* Ranges are sorted in ascending order. */ 142/* Ranges are sorted in ascending order. */
143static const struct regulator_linear_range buck1_volt_range[] = { 143static const struct regulator_linear_range buck1_volt_range[] = {
144 { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f, 144 REGULATOR_LINEAR_RANGE(600000, 0, 0x4f, 12500),
145 .uV_step = 12500 }, 145 REGULATOR_LINEAR_RANGE(1600000, 0x50, 0x54, 50000),
146 { .min_uV = 1600000, .max_uV = 1800000, .min_sel = 0x50,
147 .max_sel = 0x54, .uV_step = 50000 },
148}; 146};
149 147
150/* BUCK 2~5 have same ranges. */ 148/* BUCK 2~5 have same ranges. */
151static const struct regulator_linear_range buck2_5_volt_range[] = { 149static const struct regulator_linear_range buck2_5_volt_range[] = {
152 { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f, 150 REGULATOR_LINEAR_RANGE(600000, 0, 0x4f, 12500),
153 .uV_step = 12500 }, 151 REGULATOR_LINEAR_RANGE(1600000, 0x50, 0x72, 50000),
154 { .min_uV = 1600000, .max_uV = 3300000, .min_sel = 0x50,
155 .max_sel = 0x72, .uV_step = 50000 },
156}; 152};
157 153
158static const unsigned int ldo1_volt_table[] = { 154static const unsigned int ldo1_volt_table[] = {
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 70230974468c..f704d83c93c4 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -391,7 +391,8 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
391 else 391 else
392 config.regmap = chip->regmap_companion; 392 config.regmap = chip->regmap_companion;
393 393
394 info->regulator = regulator_register(&info->desc, &config); 394 info->regulator = devm_regulator_register(&pdev->dev, &info->desc,
395 &config);
395 if (IS_ERR(info->regulator)) { 396 if (IS_ERR(info->regulator)) {
396 dev_err(&pdev->dev, "failed to register regulator %s\n", 397 dev_err(&pdev->dev, "failed to register regulator %s\n",
397 info->desc.name); 398 info->desc.name);
@@ -402,14 +403,6 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
402 return 0; 403 return 0;
403} 404}
404 405
405static int pm8607_regulator_remove(struct platform_device *pdev)
406{
407 struct pm8607_regulator_info *info = platform_get_drvdata(pdev);
408
409 regulator_unregister(info->regulator);
410 return 0;
411}
412
413static struct platform_device_id pm8607_regulator_driver_ids[] = { 406static struct platform_device_id pm8607_regulator_driver_ids[] = {
414 { 407 {
415 .name = "88pm860x-regulator", 408 .name = "88pm860x-regulator",
@@ -428,7 +421,6 @@ static struct platform_driver pm8607_regulator_driver = {
428 .owner = THIS_MODULE, 421 .owner = THIS_MODULE,
429 }, 422 },
430 .probe = pm8607_regulator_probe, 423 .probe = pm8607_regulator_probe,
431 .remove = pm8607_regulator_remove,
432 .id_table = pm8607_regulator_driver_ids, 424 .id_table = pm8607_regulator_driver_ids,
433}; 425};
434 426
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index dfe58096b374..ce785f481281 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -28,16 +28,6 @@ config REGULATOR_DEBUG
28 help 28 help
29 Say yes here to enable debugging support. 29 Say yes here to enable debugging support.
30 30
31config REGULATOR_DUMMY
32 bool "Provide a dummy regulator if regulator lookups fail"
33 help
34 If this option is enabled then when a regulator lookup fails
35 and the board has not specified that it has provided full
36 constraints the regulator core will provide an always
37 enabled dummy regulator, allowing consumer drivers to continue.
38
39 A warning will be generated when this substitution is done.
40
41config REGULATOR_FIXED_VOLTAGE 31config REGULATOR_FIXED_VOLTAGE
42 tristate "Fixed voltage regulator support" 32 tristate "Fixed voltage regulator support"
43 help 33 help
@@ -133,6 +123,14 @@ config REGULATOR_AS3711
133 This driver provides support for the voltage regulators on the 123 This driver provides support for the voltage regulators on the
134 AS3711 PMIC 124 AS3711 PMIC
135 125
126config REGULATOR_AS3722
127 tristate "AMS AS3722 PMIC Regulators"
128 depends on MFD_AS3722
129 help
130 This driver provides support for the voltage regulators on the
131 AS3722 PMIC. This will enable support for all the software
132 controllable DCDC/LDO regulators.
133
136config REGULATOR_DA903X 134config REGULATOR_DA903X
137 tristate "Dialog Semiconductor DA9030/DA9034 regulators" 135 tristate "Dialog Semiconductor DA9030/DA9034 regulators"
138 depends on PMIC_DA903X 136 depends on PMIC_DA903X
@@ -429,6 +427,14 @@ config REGULATOR_TI_ABB
429 on TI SoCs may be unstable without enabling this as it provides 427 on TI SoCs may be unstable without enabling this as it provides
430 device specific optimized bias to allow/optimize functionality. 428 device specific optimized bias to allow/optimize functionality.
431 429
430config REGULATOR_STW481X_VMMC
431 bool "ST Microelectronics STW481X VMMC regulator"
432 depends on MFD_STW481X
433 default y if MFD_STW481X
434 help
435 This driver supports the internal VMMC regulator in the STw481x
436 PMIC chips.
437
432config REGULATOR_TPS51632 438config REGULATOR_TPS51632
433 tristate "TI TPS51632 Power Regulator" 439 tristate "TI TPS51632 Power Regulator"
434 depends on I2C 440 depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 185cce246022..01c597ea1744 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5 5
6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o 6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o
7obj-$(CONFIG_OF) += of_regulator.o 7obj-$(CONFIG_OF) += of_regulator.o
8obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o 8obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
9obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 9obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
18obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o 18obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
19obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o 19obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
20obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o 20obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
21obj-$(CONFIG_REGULATOR_AS3722) += as3722-regulator.o
21obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 22obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
22obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 23obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
23obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o 24obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
@@ -56,6 +57,7 @@ obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
56obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o 57obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
57obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o 58obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
58obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 59obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
60obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
59obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o 61obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
60obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 62obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o
61obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o 63obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 881159dfcb5e..f70a9bfa5ff2 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -176,7 +176,7 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
176 config.driver_data = ri; 176 config.driver_data = ri;
177 config.init_data = dev_get_platdata(&pdev->dev); 177 config.init_data = dev_get_platdata(&pdev->dev);
178 178
179 rdev = regulator_register(&ri->desc, &config); 179 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
180 if (IS_ERR(rdev)) { 180 if (IS_ERR(rdev)) {
181 dev_err(&pdev->dev, "Failed to register regulator %s\n", 181 dev_err(&pdev->dev, "Failed to register regulator %s\n",
182 ri->desc.name); 182 ri->desc.name);
@@ -187,21 +187,12 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
187 return 0; 187 return 0;
188} 188}
189 189
190static int aat2870_regulator_remove(struct platform_device *pdev)
191{
192 struct regulator_dev *rdev = platform_get_drvdata(pdev);
193
194 regulator_unregister(rdev);
195 return 0;
196}
197
198static struct platform_driver aat2870_regulator_driver = { 190static struct platform_driver aat2870_regulator_driver = {
199 .driver = { 191 .driver = {
200 .name = "aat2870-regulator", 192 .name = "aat2870-regulator",
201 .owner = THIS_MODULE, 193 .owner = THIS_MODULE,
202 }, 194 },
203 .probe = aat2870_regulator_probe, 195 .probe = aat2870_regulator_probe,
204 .remove = aat2870_regulator_remove,
205}; 196};
206 197
207static int __init aat2870_regulator_init(void) 198static int __init aat2870_regulator_init(void)
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 7d5eaa874b2d..77b46d0b37a6 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -535,7 +535,7 @@ static int ab3100_regulator_register(struct platform_device *pdev,
535 config.dev = &pdev->dev; 535 config.dev = &pdev->dev;
536 config.driver_data = reg; 536 config.driver_data = reg;
537 537
538 rdev = regulator_register(desc, &config); 538 rdev = devm_regulator_register(&pdev->dev, desc, &config);
539 if (IS_ERR(rdev)) { 539 if (IS_ERR(rdev)) {
540 err = PTR_ERR(rdev); 540 err = PTR_ERR(rdev);
541 dev_err(&pdev->dev, 541 dev_err(&pdev->dev,
@@ -616,7 +616,6 @@ static int ab3100_regulators_remove(struct platform_device *pdev)
616 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 616 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
617 struct ab3100_regulator *reg = &ab3100_regulators[i]; 617 struct ab3100_regulator *reg = &ab3100_regulators[i];
618 618
619 regulator_unregister(reg->rdev);
620 reg->rdev = NULL; 619 reg->rdev = NULL;
621 } 620 }
622 return 0; 621 return 0;
diff --git a/drivers/regulator/ab8500-ext.c b/drivers/regulator/ab8500-ext.c
index 02ff691cdb8b..29c0faaf8eba 100644
--- a/drivers/regulator/ab8500-ext.c
+++ b/drivers/regulator/ab8500-ext.c
@@ -413,16 +413,12 @@ static int ab8500_ext_regulator_probe(struct platform_device *pdev)
413 &pdata->ext_regulator[i]; 413 &pdata->ext_regulator[i];
414 414
415 /* register regulator with framework */ 415 /* register regulator with framework */
416 info->rdev = regulator_register(&info->desc, &config); 416 info->rdev = devm_regulator_register(&pdev->dev, &info->desc,
417 &config);
417 if (IS_ERR(info->rdev)) { 418 if (IS_ERR(info->rdev)) {
418 err = PTR_ERR(info->rdev); 419 err = PTR_ERR(info->rdev);
419 dev_err(&pdev->dev, "failed to register regulator %s\n", 420 dev_err(&pdev->dev, "failed to register regulator %s\n",
420 info->desc.name); 421 info->desc.name);
421 /* when we fail, un-register all earlier regulators */
422 while (--i >= 0) {
423 info = &ab8500_ext_regulator_info[i];
424 regulator_unregister(info->rdev);
425 }
426 return err; 422 return err;
427 } 423 }
428 424
@@ -433,26 +429,8 @@ static int ab8500_ext_regulator_probe(struct platform_device *pdev)
433 return 0; 429 return 0;
434} 430}
435 431
436static int ab8500_ext_regulator_remove(struct platform_device *pdev)
437{
438 int i;
439
440 for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) {
441 struct ab8500_ext_regulator_info *info = NULL;
442 info = &ab8500_ext_regulator_info[i];
443
444 dev_vdbg(rdev_get_dev(info->rdev),
445 "%s-remove\n", info->desc.name);
446
447 regulator_unregister(info->rdev);
448 }
449
450 return 0;
451}
452
453static struct platform_driver ab8500_ext_regulator_driver = { 432static struct platform_driver ab8500_ext_regulator_driver = {
454 .probe = ab8500_ext_regulator_probe, 433 .probe = ab8500_ext_regulator_probe,
455 .remove = ab8500_ext_regulator_remove,
456 .driver = { 434 .driver = {
457 .name = "ab8500-ext-regulator", 435 .name = "ab8500-ext-regulator",
458 .owner = THIS_MODULE, 436 .owner = THIS_MODULE,
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index b2b203cb6b2f..48016a050d5f 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -219,7 +219,6 @@ static int ad5398_probe(struct i2c_client *client,
219 struct ad5398_chip_info *chip; 219 struct ad5398_chip_info *chip;
220 const struct ad5398_current_data_format *df = 220 const struct ad5398_current_data_format *df =
221 (struct ad5398_current_data_format *)id->driver_data; 221 (struct ad5398_current_data_format *)id->driver_data;
222 int ret;
223 222
224 if (!init_data) 223 if (!init_data)
225 return -EINVAL; 224 return -EINVAL;
@@ -240,33 +239,21 @@ static int ad5398_probe(struct i2c_client *client,
240 chip->current_offset = df->current_offset; 239 chip->current_offset = df->current_offset;
241 chip->current_mask = (chip->current_level - 1) << chip->current_offset; 240 chip->current_mask = (chip->current_level - 1) << chip->current_offset;
242 241
243 chip->rdev = regulator_register(&ad5398_reg, &config); 242 chip->rdev = devm_regulator_register(&client->dev, &ad5398_reg,
243 &config);
244 if (IS_ERR(chip->rdev)) { 244 if (IS_ERR(chip->rdev)) {
245 ret = PTR_ERR(chip->rdev);
246 dev_err(&client->dev, "failed to register %s %s\n", 245 dev_err(&client->dev, "failed to register %s %s\n",
247 id->name, ad5398_reg.name); 246 id->name, ad5398_reg.name);
248 goto err; 247 return PTR_ERR(chip->rdev);
249 } 248 }
250 249
251 i2c_set_clientdata(client, chip); 250 i2c_set_clientdata(client, chip);
252 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name); 251 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name);
253 return 0; 252 return 0;
254
255err:
256 return ret;
257}
258
259static int ad5398_remove(struct i2c_client *client)
260{
261 struct ad5398_chip_info *chip = i2c_get_clientdata(client);
262
263 regulator_unregister(chip->rdev);
264 return 0;
265} 253}
266 254
267static struct i2c_driver ad5398_driver = { 255static struct i2c_driver ad5398_driver = {
268 .probe = ad5398_probe, 256 .probe = ad5398_probe,
269 .remove = ad5398_remove,
270 .driver = { 257 .driver = {
271 .name = "ad5398", 258 .name = "ad5398",
272 }, 259 },
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index 0d4a8ccbb536..c734d0980826 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -200,7 +200,7 @@ static int anatop_regulator_probe(struct platform_device *pdev)
200 config.regmap = sreg->anatop; 200 config.regmap = sreg->anatop;
201 201
202 /* register regulator */ 202 /* register regulator */
203 rdev = regulator_register(rdesc, &config); 203 rdev = devm_regulator_register(dev, rdesc, &config);
204 if (IS_ERR(rdev)) { 204 if (IS_ERR(rdev)) {
205 dev_err(dev, "failed to register %s\n", 205 dev_err(dev, "failed to register %s\n",
206 rdesc->name); 206 rdesc->name);
@@ -223,7 +223,6 @@ static int anatop_regulator_remove(struct platform_device *pdev)
223 struct anatop_regulator *sreg = rdev_get_drvdata(rdev); 223 struct anatop_regulator *sreg = rdev_get_drvdata(rdev);
224 const char *name = sreg->name; 224 const char *name = sreg->name;
225 225
226 regulator_unregister(rdev);
227 kfree(name); 226 kfree(name);
228 227
229 return 0; 228 return 0;
@@ -256,7 +255,7 @@ static void __exit anatop_regulator_exit(void)
256} 255}
257module_exit(anatop_regulator_exit); 256module_exit(anatop_regulator_exit);
258 257
259MODULE_AUTHOR("Nancy Chen <Nancy.Chen@freescale.com>, " 258MODULE_AUTHOR("Nancy Chen <Nancy.Chen@freescale.com>");
260 "Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>"); 259MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>");
261MODULE_DESCRIPTION("ANATOP Regulator driver"); 260MODULE_DESCRIPTION("ANATOP Regulator driver");
262MODULE_LICENSE("GPL v2"); 261MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index 81d8681c3195..4f6c2055f6b2 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -226,7 +226,7 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
226 else 226 else
227 config.init_data = &ldo1->init_data; 227 config.init_data = &ldo1->init_data;
228 228
229 ldo1->regulator = regulator_register(desc, &config); 229 ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config);
230 if (IS_ERR(ldo1->regulator)) { 230 if (IS_ERR(ldo1->regulator)) {
231 ret = PTR_ERR(ldo1->regulator); 231 ret = PTR_ERR(ldo1->regulator);
232 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n", 232 dev_err(arizona->dev, "Failed to register LDO1 supply: %d\n",
@@ -239,18 +239,8 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
239 return 0; 239 return 0;
240} 240}
241 241
242static int arizona_ldo1_remove(struct platform_device *pdev)
243{
244 struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
245
246 regulator_unregister(ldo1->regulator);
247
248 return 0;
249}
250
251static struct platform_driver arizona_ldo1_driver = { 242static struct platform_driver arizona_ldo1_driver = {
252 .probe = arizona_ldo1_probe, 243 .probe = arizona_ldo1_probe,
253 .remove = arizona_ldo1_remove,
254 .driver = { 244 .driver = {
255 .name = "arizona-ldo1", 245 .name = "arizona-ldo1",
256 .owner = THIS_MODULE, 246 .owner = THIS_MODULE,
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index e87536bf0bed..724706a97dc4 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -225,7 +225,9 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
225 regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1, 225 regmap_update_bits(arizona->regmap, ARIZONA_MIC_CHARGE_PUMP_1,
226 ARIZONA_CPMIC_BYPASS, 0); 226 ARIZONA_CPMIC_BYPASS, 0);
227 227
228 micsupp->regulator = regulator_register(&arizona_micsupp, &config); 228 micsupp->regulator = devm_regulator_register(&pdev->dev,
229 &arizona_micsupp,
230 &config);
229 if (IS_ERR(micsupp->regulator)) { 231 if (IS_ERR(micsupp->regulator)) {
230 ret = PTR_ERR(micsupp->regulator); 232 ret = PTR_ERR(micsupp->regulator);
231 dev_err(arizona->dev, "Failed to register mic supply: %d\n", 233 dev_err(arizona->dev, "Failed to register mic supply: %d\n",
@@ -238,18 +240,8 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
238 return 0; 240 return 0;
239} 241}
240 242
241static int arizona_micsupp_remove(struct platform_device *pdev)
242{
243 struct arizona_micsupp *micsupp = platform_get_drvdata(pdev);
244
245 regulator_unregister(micsupp->regulator);
246
247 return 0;
248}
249
250static struct platform_driver arizona_micsupp_driver = { 243static struct platform_driver arizona_micsupp_driver = {
251 .probe = arizona_micsupp_probe, 244 .probe = arizona_micsupp_probe,
252 .remove = arizona_micsupp_remove,
253 .driver = { 245 .driver = {
254 .name = "arizona-micsupp", 246 .name = "arizona-micsupp",
255 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
diff --git a/drivers/regulator/as3711-regulator.c b/drivers/regulator/as3711-regulator.c
index 8406cd745da2..c77a58478cca 100644
--- a/drivers/regulator/as3711-regulator.c
+++ b/drivers/regulator/as3711-regulator.c
@@ -117,26 +117,19 @@ static struct regulator_ops as3711_dldo_ops = {
117}; 117};
118 118
119static const struct regulator_linear_range as3711_sd_ranges[] = { 119static const struct regulator_linear_range as3711_sd_ranges[] = {
120 { .min_uV = 612500, .max_uV = 1400000, 120 REGULATOR_LINEAR_RANGE(612500, 0x1, 0x40, 12500),
121 .min_sel = 0x1, .max_sel = 0x40, .uV_step = 12500 }, 121 REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000),
122 { .min_uV = 1425000, .max_uV = 2600000, 122 REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7f, 50000),
123 .min_sel = 0x41, .max_sel = 0x70, .uV_step = 25000 },
124 { .min_uV = 2650000, .max_uV = 3350000,
125 .min_sel = 0x71, .max_sel = 0x7f, .uV_step = 50000 },
126}; 123};
127 124
128static const struct regulator_linear_range as3711_aldo_ranges[] = { 125static const struct regulator_linear_range as3711_aldo_ranges[] = {
129 { .min_uV = 1200000, .max_uV = 1950000, 126 REGULATOR_LINEAR_RANGE(1200000, 0, 0xf, 50000),
130 .min_sel = 0, .max_sel = 0xf, .uV_step = 50000 }, 127 REGULATOR_LINEAR_RANGE(1800000, 0x10, 0x1f, 100000),
131 { .min_uV = 1800000, .max_uV = 3300000,
132 .min_sel = 0x10, .max_sel = 0x1f, .uV_step = 100000 },
133}; 128};
134 129
135static const struct regulator_linear_range as3711_dldo_ranges[] = { 130static const struct regulator_linear_range as3711_dldo_ranges[] = {
136 { .min_uV = 900000, .max_uV = 1700000, 131 REGULATOR_LINEAR_RANGE(900000, 0, 0x10, 50000),
137 .min_sel = 0, .max_sel = 0x10, .uV_step = 50000 }, 132 REGULATOR_LINEAR_RANGE(1750000, 0x20, 0x3f, 50000),
138 { .min_uV = 1750000, .max_uV = 3300000,
139 .min_sel = 0x20, .max_sel = 0x3f, .uV_step = 50000 },
140}; 133};
141 134
142#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \ 135#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \
@@ -273,33 +266,16 @@ static int as3711_regulator_probe(struct platform_device *pdev)
273 config.regmap = as3711->regmap; 266 config.regmap = as3711->regmap;
274 config.of_node = of_node[id]; 267 config.of_node = of_node[id];
275 268
276 rdev = regulator_register(&ri->desc, &config); 269 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
277 if (IS_ERR(rdev)) { 270 if (IS_ERR(rdev)) {
278 dev_err(&pdev->dev, "Failed to register regulator %s\n", 271 dev_err(&pdev->dev, "Failed to register regulator %s\n",
279 ri->desc.name); 272 ri->desc.name);
280 ret = PTR_ERR(rdev); 273 return PTR_ERR(rdev);
281 goto eregreg;
282 } 274 }
283 reg->rdev = rdev; 275 reg->rdev = rdev;
284 } 276 }
285 platform_set_drvdata(pdev, regs); 277 platform_set_drvdata(pdev, regs);
286 return 0; 278 return 0;
287
288eregreg:
289 while (--id >= 0)
290 regulator_unregister(regs[id].rdev);
291
292 return ret;
293}
294
295static int as3711_regulator_remove(struct platform_device *pdev)
296{
297 struct as3711_regulator *regs = platform_get_drvdata(pdev);
298 int id;
299
300 for (id = 0; id < AS3711_REGULATOR_NUM; ++id)
301 regulator_unregister(regs[id].rdev);
302 return 0;
303} 279}
304 280
305static struct platform_driver as3711_regulator_driver = { 281static struct platform_driver as3711_regulator_driver = {
@@ -308,7 +284,6 @@ static struct platform_driver as3711_regulator_driver = {
308 .owner = THIS_MODULE, 284 .owner = THIS_MODULE,
309 }, 285 },
310 .probe = as3711_regulator_probe, 286 .probe = as3711_regulator_probe,
311 .remove = as3711_regulator_remove,
312}; 287};
313 288
314static int __init as3711_regulator_init(void) 289static int __init as3711_regulator_init(void)
diff --git a/drivers/regulator/as3722-regulator.c b/drivers/regulator/as3722-regulator.c
new file mode 100644
index 000000000000..5917fe3dc983
--- /dev/null
+++ b/drivers/regulator/as3722-regulator.c
@@ -0,0 +1,908 @@
1/*
2 * Voltage regulator support for AMS AS3722 PMIC
3 *
4 * Copyright (C) 2013 ams
5 *
6 * Author: Florian Lobmaier <florian.lobmaier@ams.com>
7 * Author: Laxman Dewangan <ldewangan@nvidia.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/err.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/mfd/as3722.h>
29#include <linux/of.h>
30#include <linux/of_platform.h>
31#include <linux/platform_device.h>
32#include <linux/regulator/driver.h>
33#include <linux/regulator/machine.h>
34#include <linux/regulator/of_regulator.h>
35#include <linux/slab.h>
36
37/* Regulator IDs */
38enum as3722_regulators_id {
39 AS3722_REGULATOR_ID_SD0,
40 AS3722_REGULATOR_ID_SD1,
41 AS3722_REGULATOR_ID_SD2,
42 AS3722_REGULATOR_ID_SD3,
43 AS3722_REGULATOR_ID_SD4,
44 AS3722_REGULATOR_ID_SD5,
45 AS3722_REGULATOR_ID_SD6,
46 AS3722_REGULATOR_ID_LDO0,
47 AS3722_REGULATOR_ID_LDO1,
48 AS3722_REGULATOR_ID_LDO2,
49 AS3722_REGULATOR_ID_LDO3,
50 AS3722_REGULATOR_ID_LDO4,
51 AS3722_REGULATOR_ID_LDO5,
52 AS3722_REGULATOR_ID_LDO6,
53 AS3722_REGULATOR_ID_LDO7,
54 AS3722_REGULATOR_ID_LDO9,
55 AS3722_REGULATOR_ID_LDO10,
56 AS3722_REGULATOR_ID_LDO11,
57 AS3722_REGULATOR_ID_MAX,
58};
59
60struct as3722_register_mapping {
61 u8 regulator_id;
62 const char *name;
63 const char *sname;
64 u8 vsel_reg;
65 u8 vsel_mask;
66 int n_voltages;
67 u32 enable_reg;
68 u8 enable_mask;
69 u32 control_reg;
70 u8 mode_mask;
71 u32 sleep_ctrl_reg;
72 u8 sleep_ctrl_mask;
73};
74
75struct as3722_regulator_config_data {
76 struct regulator_init_data *reg_init;
77 bool enable_tracking;
78 int ext_control;
79};
80
81struct as3722_regulators {
82 struct device *dev;
83 struct as3722 *as3722;
84 struct regulator_dev *rdevs[AS3722_REGULATOR_ID_MAX];
85 struct regulator_desc desc[AS3722_REGULATOR_ID_MAX];
86 struct as3722_regulator_config_data
87 reg_config_data[AS3722_REGULATOR_ID_MAX];
88};
89
90static const struct as3722_register_mapping as3722_reg_lookup[] = {
91 {
92 .regulator_id = AS3722_REGULATOR_ID_SD0,
93 .name = "as3722-sd0",
94 .vsel_reg = AS3722_SD0_VOLTAGE_REG,
95 .vsel_mask = AS3722_SD_VSEL_MASK,
96 .enable_reg = AS3722_SD_CONTROL_REG,
97 .enable_mask = AS3722_SDn_CTRL(0),
98 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
99 .sleep_ctrl_mask = AS3722_SD0_EXT_ENABLE_MASK,
100 .control_reg = AS3722_SD0_CONTROL_REG,
101 .mode_mask = AS3722_SD0_MODE_FAST,
102 .n_voltages = AS3722_SD0_VSEL_MAX + 1,
103 },
104 {
105 .regulator_id = AS3722_REGULATOR_ID_SD1,
106 .name = "as3722-sd1",
107 .vsel_reg = AS3722_SD1_VOLTAGE_REG,
108 .vsel_mask = AS3722_SD_VSEL_MASK,
109 .enable_reg = AS3722_SD_CONTROL_REG,
110 .enable_mask = AS3722_SDn_CTRL(1),
111 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
112 .sleep_ctrl_mask = AS3722_SD1_EXT_ENABLE_MASK,
113 .control_reg = AS3722_SD1_CONTROL_REG,
114 .mode_mask = AS3722_SD1_MODE_FAST,
115 .n_voltages = AS3722_SD0_VSEL_MAX + 1,
116 },
117 {
118 .regulator_id = AS3722_REGULATOR_ID_SD2,
119 .name = "as3722-sd2",
120 .sname = "vsup-sd2",
121 .vsel_reg = AS3722_SD2_VOLTAGE_REG,
122 .vsel_mask = AS3722_SD_VSEL_MASK,
123 .enable_reg = AS3722_SD_CONTROL_REG,
124 .enable_mask = AS3722_SDn_CTRL(2),
125 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
126 .sleep_ctrl_mask = AS3722_SD2_EXT_ENABLE_MASK,
127 .control_reg = AS3722_SD23_CONTROL_REG,
128 .mode_mask = AS3722_SD2_MODE_FAST,
129 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
130 },
131 {
132 .regulator_id = AS3722_REGULATOR_ID_SD3,
133 .name = "as3722-sd3",
134 .sname = "vsup-sd3",
135 .vsel_reg = AS3722_SD3_VOLTAGE_REG,
136 .vsel_mask = AS3722_SD_VSEL_MASK,
137 .enable_reg = AS3722_SD_CONTROL_REG,
138 .enable_mask = AS3722_SDn_CTRL(3),
139 .sleep_ctrl_reg = AS3722_ENABLE_CTRL1_REG,
140 .sleep_ctrl_mask = AS3722_SD3_EXT_ENABLE_MASK,
141 .control_reg = AS3722_SD23_CONTROL_REG,
142 .mode_mask = AS3722_SD3_MODE_FAST,
143 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
144 },
145 {
146 .regulator_id = AS3722_REGULATOR_ID_SD4,
147 .name = "as3722-sd4",
148 .sname = "vsup-sd4",
149 .vsel_reg = AS3722_SD4_VOLTAGE_REG,
150 .vsel_mask = AS3722_SD_VSEL_MASK,
151 .enable_reg = AS3722_SD_CONTROL_REG,
152 .enable_mask = AS3722_SDn_CTRL(4),
153 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
154 .sleep_ctrl_mask = AS3722_SD4_EXT_ENABLE_MASK,
155 .control_reg = AS3722_SD4_CONTROL_REG,
156 .mode_mask = AS3722_SD4_MODE_FAST,
157 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
158 },
159 {
160 .regulator_id = AS3722_REGULATOR_ID_SD5,
161 .name = "as3722-sd5",
162 .sname = "vsup-sd5",
163 .vsel_reg = AS3722_SD5_VOLTAGE_REG,
164 .vsel_mask = AS3722_SD_VSEL_MASK,
165 .enable_reg = AS3722_SD_CONTROL_REG,
166 .enable_mask = AS3722_SDn_CTRL(5),
167 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
168 .sleep_ctrl_mask = AS3722_SD5_EXT_ENABLE_MASK,
169 .control_reg = AS3722_SD5_CONTROL_REG,
170 .mode_mask = AS3722_SD5_MODE_FAST,
171 .n_voltages = AS3722_SD2_VSEL_MAX + 1,
172 },
173 {
174 .regulator_id = AS3722_REGULATOR_ID_SD6,
175 .name = "as3722-sd6",
176 .vsel_reg = AS3722_SD6_VOLTAGE_REG,
177 .vsel_mask = AS3722_SD_VSEL_MASK,
178 .enable_reg = AS3722_SD_CONTROL_REG,
179 .enable_mask = AS3722_SDn_CTRL(6),
180 .sleep_ctrl_reg = AS3722_ENABLE_CTRL2_REG,
181 .sleep_ctrl_mask = AS3722_SD6_EXT_ENABLE_MASK,
182 .control_reg = AS3722_SD6_CONTROL_REG,
183 .mode_mask = AS3722_SD6_MODE_FAST,
184 .n_voltages = AS3722_SD0_VSEL_MAX + 1,
185 },
186 {
187 .regulator_id = AS3722_REGULATOR_ID_LDO0,
188 .name = "as3722-ldo0",
189 .sname = "vin-ldo0",
190 .vsel_reg = AS3722_LDO0_VOLTAGE_REG,
191 .vsel_mask = AS3722_LDO0_VSEL_MASK,
192 .enable_reg = AS3722_LDOCONTROL0_REG,
193 .enable_mask = AS3722_LDO0_CTRL,
194 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
195 .sleep_ctrl_mask = AS3722_LDO0_EXT_ENABLE_MASK,
196 .n_voltages = AS3722_LDO0_NUM_VOLT,
197 },
198 {
199 .regulator_id = AS3722_REGULATOR_ID_LDO1,
200 .name = "as3722-ldo1",
201 .sname = "vin-ldo1-6",
202 .vsel_reg = AS3722_LDO1_VOLTAGE_REG,
203 .vsel_mask = AS3722_LDO_VSEL_MASK,
204 .enable_reg = AS3722_LDOCONTROL0_REG,
205 .enable_mask = AS3722_LDO1_CTRL,
206 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
207 .sleep_ctrl_mask = AS3722_LDO1_EXT_ENABLE_MASK,
208 .n_voltages = AS3722_LDO_NUM_VOLT,
209 },
210 {
211 .regulator_id = AS3722_REGULATOR_ID_LDO2,
212 .name = "as3722-ldo2",
213 .sname = "vin-ldo2-5-7",
214 .vsel_reg = AS3722_LDO2_VOLTAGE_REG,
215 .vsel_mask = AS3722_LDO_VSEL_MASK,
216 .enable_reg = AS3722_LDOCONTROL0_REG,
217 .enable_mask = AS3722_LDO2_CTRL,
218 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
219 .sleep_ctrl_mask = AS3722_LDO2_EXT_ENABLE_MASK,
220 .n_voltages = AS3722_LDO_NUM_VOLT,
221 },
222 {
223 .regulator_id = AS3722_REGULATOR_ID_LDO3,
224 .name = "as3722-ldo3",
225 .name = "vin-ldo3-4",
226 .vsel_reg = AS3722_LDO3_VOLTAGE_REG,
227 .vsel_mask = AS3722_LDO3_VSEL_MASK,
228 .enable_reg = AS3722_LDOCONTROL0_REG,
229 .enable_mask = AS3722_LDO3_CTRL,
230 .sleep_ctrl_reg = AS3722_ENABLE_CTRL3_REG,
231 .sleep_ctrl_mask = AS3722_LDO3_EXT_ENABLE_MASK,
232 .n_voltages = AS3722_LDO3_NUM_VOLT,
233 },
234 {
235 .regulator_id = AS3722_REGULATOR_ID_LDO4,
236 .name = "as3722-ldo4",
237 .name = "vin-ldo3-4",
238 .vsel_reg = AS3722_LDO4_VOLTAGE_REG,
239 .vsel_mask = AS3722_LDO_VSEL_MASK,
240 .enable_reg = AS3722_LDOCONTROL0_REG,
241 .enable_mask = AS3722_LDO4_CTRL,
242 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
243 .sleep_ctrl_mask = AS3722_LDO4_EXT_ENABLE_MASK,
244 .n_voltages = AS3722_LDO_NUM_VOLT,
245 },
246 {
247 .regulator_id = AS3722_REGULATOR_ID_LDO5,
248 .name = "as3722-ldo5",
249 .sname = "vin-ldo2-5-7",
250 .vsel_reg = AS3722_LDO5_VOLTAGE_REG,
251 .vsel_mask = AS3722_LDO_VSEL_MASK,
252 .enable_reg = AS3722_LDOCONTROL0_REG,
253 .enable_mask = AS3722_LDO5_CTRL,
254 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
255 .sleep_ctrl_mask = AS3722_LDO5_EXT_ENABLE_MASK,
256 .n_voltages = AS3722_LDO_NUM_VOLT,
257 },
258 {
259 .regulator_id = AS3722_REGULATOR_ID_LDO6,
260 .name = "as3722-ldo6",
261 .sname = "vin-ldo1-6",
262 .vsel_reg = AS3722_LDO6_VOLTAGE_REG,
263 .vsel_mask = AS3722_LDO_VSEL_MASK,
264 .enable_reg = AS3722_LDOCONTROL0_REG,
265 .enable_mask = AS3722_LDO6_CTRL,
266 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
267 .sleep_ctrl_mask = AS3722_LDO6_EXT_ENABLE_MASK,
268 .n_voltages = AS3722_LDO_NUM_VOLT,
269 },
270 {
271 .regulator_id = AS3722_REGULATOR_ID_LDO7,
272 .name = "as3722-ldo7",
273 .sname = "vin-ldo2-5-7",
274 .vsel_reg = AS3722_LDO7_VOLTAGE_REG,
275 .vsel_mask = AS3722_LDO_VSEL_MASK,
276 .enable_reg = AS3722_LDOCONTROL0_REG,
277 .enable_mask = AS3722_LDO7_CTRL,
278 .sleep_ctrl_reg = AS3722_ENABLE_CTRL4_REG,
279 .sleep_ctrl_mask = AS3722_LDO7_EXT_ENABLE_MASK,
280 .n_voltages = AS3722_LDO_NUM_VOLT,
281 },
282 {
283 .regulator_id = AS3722_REGULATOR_ID_LDO9,
284 .name = "as3722-ldo9",
285 .sname = "vin-ldo9-10",
286 .vsel_reg = AS3722_LDO9_VOLTAGE_REG,
287 .vsel_mask = AS3722_LDO_VSEL_MASK,
288 .enable_reg = AS3722_LDOCONTROL1_REG,
289 .enable_mask = AS3722_LDO9_CTRL,
290 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
291 .sleep_ctrl_mask = AS3722_LDO9_EXT_ENABLE_MASK,
292 .n_voltages = AS3722_LDO_NUM_VOLT,
293 },
294 {
295 .regulator_id = AS3722_REGULATOR_ID_LDO10,
296 .name = "as3722-ldo10",
297 .sname = "vin-ldo9-10",
298 .vsel_reg = AS3722_LDO10_VOLTAGE_REG,
299 .vsel_mask = AS3722_LDO_VSEL_MASK,
300 .enable_reg = AS3722_LDOCONTROL1_REG,
301 .enable_mask = AS3722_LDO10_CTRL,
302 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
303 .sleep_ctrl_mask = AS3722_LDO10_EXT_ENABLE_MASK,
304 .n_voltages = AS3722_LDO_NUM_VOLT,
305 },
306 {
307 .regulator_id = AS3722_REGULATOR_ID_LDO11,
308 .name = "as3722-ldo11",
309 .sname = "vin-ldo11",
310 .vsel_reg = AS3722_LDO11_VOLTAGE_REG,
311 .vsel_mask = AS3722_LDO_VSEL_MASK,
312 .enable_reg = AS3722_LDOCONTROL1_REG,
313 .enable_mask = AS3722_LDO11_CTRL,
314 .sleep_ctrl_reg = AS3722_ENABLE_CTRL5_REG,
315 .sleep_ctrl_mask = AS3722_LDO11_EXT_ENABLE_MASK,
316 .n_voltages = AS3722_LDO_NUM_VOLT,
317 },
318};
319
320
321static const int as3722_ldo_current[] = { 150000, 300000 };
322static const int as3722_sd016_current[] = { 2500000, 3000000, 3500000 };
323
324static int as3722_current_to_index(int min_uA, int max_uA,
325 const int *curr_table, int n_currents)
326{
327 int i;
328
329 for (i = n_currents - 1; i >= 0; i--) {
330 if ((min_uA <= curr_table[i]) && (curr_table[i] <= max_uA))
331 return i;
332 }
333 return -EINVAL;
334}
335
336static int as3722_ldo_get_current_limit(struct regulator_dev *rdev)
337{
338 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
339 struct as3722 *as3722 = as3722_regs->as3722;
340 int id = rdev_get_id(rdev);
341 u32 val;
342 int ret;
343
344 ret = as3722_read(as3722, as3722_reg_lookup[id].vsel_reg, &val);
345 if (ret < 0) {
346 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
347 as3722_reg_lookup[id].vsel_reg, ret);
348 return ret;
349 }
350 if (val & AS3722_LDO_ILIMIT_MASK)
351 return 300000;
352 return 150000;
353}
354
355static int as3722_ldo_set_current_limit(struct regulator_dev *rdev,
356 int min_uA, int max_uA)
357{
358 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
359 struct as3722 *as3722 = as3722_regs->as3722;
360 int id = rdev_get_id(rdev);
361 int ret;
362 u32 reg = 0;
363
364 ret = as3722_current_to_index(min_uA, max_uA, as3722_ldo_current,
365 ARRAY_SIZE(as3722_ldo_current));
366 if (ret < 0) {
367 dev_err(as3722_regs->dev,
368 "Current range min:max = %d:%d does not support\n",
369 min_uA, max_uA);
370 return ret;
371 }
372 if (ret)
373 reg = AS3722_LDO_ILIMIT_BIT;
374 return as3722_update_bits(as3722, as3722_reg_lookup[id].vsel_reg,
375 AS3722_LDO_ILIMIT_MASK, reg);
376}
377
378static struct regulator_ops as3722_ldo0_ops = {
379 .is_enabled = regulator_is_enabled_regmap,
380 .enable = regulator_enable_regmap,
381 .disable = regulator_disable_regmap,
382 .list_voltage = regulator_list_voltage_linear,
383 .get_voltage_sel = regulator_get_voltage_sel_regmap,
384 .set_voltage_sel = regulator_set_voltage_sel_regmap,
385 .get_current_limit = as3722_ldo_get_current_limit,
386 .set_current_limit = as3722_ldo_set_current_limit,
387};
388
389static struct regulator_ops as3722_ldo0_extcntrl_ops = {
390 .list_voltage = regulator_list_voltage_linear,
391 .get_voltage_sel = regulator_get_voltage_sel_regmap,
392 .set_voltage_sel = regulator_set_voltage_sel_regmap,
393 .get_current_limit = as3722_ldo_get_current_limit,
394 .set_current_limit = as3722_ldo_set_current_limit,
395};
396
397static int as3722_ldo3_set_tracking_mode(struct as3722_regulators *as3722_reg,
398 int id, u8 mode)
399{
400 struct as3722 *as3722 = as3722_reg->as3722;
401
402 switch (mode) {
403 case AS3722_LDO3_MODE_PMOS:
404 case AS3722_LDO3_MODE_PMOS_TRACKING:
405 case AS3722_LDO3_MODE_NMOS:
406 case AS3722_LDO3_MODE_SWITCH:
407 return as3722_update_bits(as3722,
408 as3722_reg_lookup[id].vsel_reg,
409 AS3722_LDO3_MODE_MASK, mode);
410
411 default:
412 return -EINVAL;
413 }
414}
415
416static int as3722_ldo3_get_current_limit(struct regulator_dev *rdev)
417{
418 return 150000;
419}
420
421static struct regulator_ops as3722_ldo3_ops = {
422 .is_enabled = regulator_is_enabled_regmap,
423 .enable = regulator_enable_regmap,
424 .disable = regulator_disable_regmap,
425 .list_voltage = regulator_list_voltage_linear,
426 .get_voltage_sel = regulator_get_voltage_sel_regmap,
427 .set_voltage_sel = regulator_set_voltage_sel_regmap,
428 .get_current_limit = as3722_ldo3_get_current_limit,
429};
430
431static struct regulator_ops as3722_ldo3_extcntrl_ops = {
432 .list_voltage = regulator_list_voltage_linear,
433 .get_voltage_sel = regulator_get_voltage_sel_regmap,
434 .set_voltage_sel = regulator_set_voltage_sel_regmap,
435 .get_current_limit = as3722_ldo3_get_current_limit,
436};
437
438static const struct regulator_linear_range as3722_ldo_ranges[] = {
439 REGULATOR_LINEAR_RANGE(825000, 0x01, 0x24, 25000),
440 REGULATOR_LINEAR_RANGE(1725000, 0x40, 0x7F, 25000),
441};
442
443static struct regulator_ops as3722_ldo_ops = {
444 .is_enabled = regulator_is_enabled_regmap,
445 .enable = regulator_enable_regmap,
446 .disable = regulator_disable_regmap,
447 .map_voltage = regulator_map_voltage_linear_range,
448 .set_voltage_sel = regulator_set_voltage_sel_regmap,
449 .get_voltage_sel = regulator_get_voltage_sel_regmap,
450 .list_voltage = regulator_list_voltage_linear_range,
451 .get_current_limit = as3722_ldo_get_current_limit,
452 .set_current_limit = as3722_ldo_set_current_limit,
453};
454
455static struct regulator_ops as3722_ldo_extcntrl_ops = {
456 .map_voltage = regulator_map_voltage_linear_range,
457 .set_voltage_sel = regulator_set_voltage_sel_regmap,
458 .get_voltage_sel = regulator_get_voltage_sel_regmap,
459 .list_voltage = regulator_list_voltage_linear_range,
460 .get_current_limit = as3722_ldo_get_current_limit,
461 .set_current_limit = as3722_ldo_set_current_limit,
462};
463
464static unsigned int as3722_sd_get_mode(struct regulator_dev *rdev)
465{
466 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
467 struct as3722 *as3722 = as3722_regs->as3722;
468 int id = rdev_get_id(rdev);
469 u32 val;
470 int ret;
471
472 if (!as3722_reg_lookup[id].control_reg)
473 return -ENOTSUPP;
474
475 ret = as3722_read(as3722, as3722_reg_lookup[id].control_reg, &val);
476 if (ret < 0) {
477 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
478 as3722_reg_lookup[id].control_reg, ret);
479 return ret;
480 }
481
482 if (val & as3722_reg_lookup[id].mode_mask)
483 return REGULATOR_MODE_FAST;
484 else
485 return REGULATOR_MODE_NORMAL;
486}
487
488static int as3722_sd_set_mode(struct regulator_dev *rdev,
489 unsigned int mode)
490{
491 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
492 struct as3722 *as3722 = as3722_regs->as3722;
493 u8 id = rdev_get_id(rdev);
494 u8 val = 0;
495 int ret;
496
497 if (!as3722_reg_lookup[id].control_reg)
498 return -ERANGE;
499
500 switch (mode) {
501 case REGULATOR_MODE_FAST:
502 val = as3722_reg_lookup[id].mode_mask;
503 case REGULATOR_MODE_NORMAL: /* fall down */
504 break;
505 default:
506 return -EINVAL;
507 }
508
509 ret = as3722_update_bits(as3722, as3722_reg_lookup[id].control_reg,
510 as3722_reg_lookup[id].mode_mask, val);
511 if (ret < 0) {
512 dev_err(as3722_regs->dev, "Reg 0x%02x update failed: %d\n",
513 as3722_reg_lookup[id].control_reg, ret);
514 return ret;
515 }
516 return ret;
517}
518
519static int as3722_sd016_get_current_limit(struct regulator_dev *rdev)
520{
521 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
522 struct as3722 *as3722 = as3722_regs->as3722;
523 int id = rdev_get_id(rdev);
524 u32 val, reg;
525 int mask;
526 int ret;
527
528 switch (id) {
529 case AS3722_REGULATOR_ID_SD0:
530 reg = AS3722_OVCURRENT_REG;
531 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
532 break;
533 case AS3722_REGULATOR_ID_SD1:
534 reg = AS3722_OVCURRENT_REG;
535 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
536 break;
537 case AS3722_REGULATOR_ID_SD6:
538 reg = AS3722_OVCURRENT_DEB_REG;
539 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
540 break;
541 default:
542 return -EINVAL;
543 }
544 ret = as3722_read(as3722, reg, &val);
545 if (ret < 0) {
546 dev_err(as3722_regs->dev, "Reg 0x%02x read failed: %d\n",
547 reg, ret);
548 return ret;
549 }
550 val &= mask;
551 val >>= ffs(mask) - 1;
552 if (val == 3)
553 return -EINVAL;
554 return as3722_sd016_current[val];
555}
556
557static int as3722_sd016_set_current_limit(struct regulator_dev *rdev,
558 int min_uA, int max_uA)
559{
560 struct as3722_regulators *as3722_regs = rdev_get_drvdata(rdev);
561 struct as3722 *as3722 = as3722_regs->as3722;
562 int id = rdev_get_id(rdev);
563 int ret;
564 int val;
565 int mask;
566 u32 reg;
567
568 ret = as3722_current_to_index(min_uA, max_uA, as3722_sd016_current,
569 ARRAY_SIZE(as3722_sd016_current));
570 if (ret < 0) {
571 dev_err(as3722_regs->dev,
572 "Current range min:max = %d:%d does not support\n",
573 min_uA, max_uA);
574 return ret;
575 }
576
577 switch (id) {
578 case AS3722_REGULATOR_ID_SD0:
579 reg = AS3722_OVCURRENT_REG;
580 mask = AS3722_OVCURRENT_SD0_TRIP_MASK;
581 break;
582 case AS3722_REGULATOR_ID_SD1:
583 reg = AS3722_OVCURRENT_REG;
584 mask = AS3722_OVCURRENT_SD1_TRIP_MASK;
585 break;
586 case AS3722_REGULATOR_ID_SD6:
587 reg = AS3722_OVCURRENT_DEB_REG;
588 mask = AS3722_OVCURRENT_SD6_TRIP_MASK;
589 break;
590 default:
591 return -EINVAL;
592 }
593 val = ret & mask;
594 val <<= ffs(mask) - 1;
595 return as3722_update_bits(as3722, reg, mask, val);
596}
597
598static const struct regulator_linear_range as3722_sd2345_ranges[] = {
599 REGULATOR_LINEAR_RANGE(612500, 0x01, 0x40, 12500),
600 REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000),
601 REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7F, 50000),
602};
603
604static struct regulator_ops as3722_sd016_ops = {
605 .is_enabled = regulator_is_enabled_regmap,
606 .enable = regulator_enable_regmap,
607 .disable = regulator_disable_regmap,
608 .list_voltage = regulator_list_voltage_linear,
609 .map_voltage = regulator_map_voltage_linear,
610 .get_voltage_sel = regulator_get_voltage_sel_regmap,
611 .set_voltage_sel = regulator_set_voltage_sel_regmap,
612 .get_current_limit = as3722_sd016_get_current_limit,
613 .set_current_limit = as3722_sd016_set_current_limit,
614 .get_mode = as3722_sd_get_mode,
615 .set_mode = as3722_sd_set_mode,
616};
617
618static struct regulator_ops as3722_sd016_extcntrl_ops = {
619 .list_voltage = regulator_list_voltage_linear,
620 .map_voltage = regulator_map_voltage_linear,
621 .get_voltage_sel = regulator_get_voltage_sel_regmap,
622 .set_voltage_sel = regulator_set_voltage_sel_regmap,
623 .get_current_limit = as3722_sd016_get_current_limit,
624 .set_current_limit = as3722_sd016_set_current_limit,
625 .get_mode = as3722_sd_get_mode,
626 .set_mode = as3722_sd_set_mode,
627};
628
629static struct regulator_ops as3722_sd2345_ops = {
630 .is_enabled = regulator_is_enabled_regmap,
631 .enable = regulator_enable_regmap,
632 .disable = regulator_disable_regmap,
633 .list_voltage = regulator_list_voltage_linear_range,
634 .map_voltage = regulator_map_voltage_linear_range,
635 .set_voltage_sel = regulator_set_voltage_sel_regmap,
636 .get_voltage_sel = regulator_get_voltage_sel_regmap,
637 .get_mode = as3722_sd_get_mode,
638 .set_mode = as3722_sd_set_mode,
639};
640
641static struct regulator_ops as3722_sd2345_extcntrl_ops = {
642 .list_voltage = regulator_list_voltage_linear_range,
643 .map_voltage = regulator_map_voltage_linear_range,
644 .set_voltage_sel = regulator_set_voltage_sel_regmap,
645 .get_voltage_sel = regulator_get_voltage_sel_regmap,
646 .get_mode = as3722_sd_get_mode,
647 .set_mode = as3722_sd_set_mode,
648};
649
650static int as3722_extreg_init(struct as3722_regulators *as3722_regs, int id,
651 int ext_pwr_ctrl)
652{
653 int ret;
654 unsigned int val;
655
656 if ((ext_pwr_ctrl < AS3722_EXT_CONTROL_ENABLE1) ||
657 (ext_pwr_ctrl > AS3722_EXT_CONTROL_ENABLE3))
658 return -EINVAL;
659
660 val = ext_pwr_ctrl << (ffs(as3722_reg_lookup[id].sleep_ctrl_mask) - 1);
661 ret = as3722_update_bits(as3722_regs->as3722,
662 as3722_reg_lookup[id].sleep_ctrl_reg,
663 as3722_reg_lookup[id].sleep_ctrl_mask, val);
664 if (ret < 0)
665 dev_err(as3722_regs->dev, "Reg 0x%02x update failed: %d\n",
666 as3722_reg_lookup[id].sleep_ctrl_reg, ret);
667 return ret;
668}
669
670static struct of_regulator_match as3722_regulator_matches[] = {
671 { .name = "sd0", },
672 { .name = "sd1", },
673 { .name = "sd2", },
674 { .name = "sd3", },
675 { .name = "sd4", },
676 { .name = "sd5", },
677 { .name = "sd6", },
678 { .name = "ldo0", },
679 { .name = "ldo1", },
680 { .name = "ldo2", },
681 { .name = "ldo3", },
682 { .name = "ldo4", },
683 { .name = "ldo5", },
684 { .name = "ldo6", },
685 { .name = "ldo7", },
686 { .name = "ldo9", },
687 { .name = "ldo10", },
688 { .name = "ldo11", },
689};
690
691static int as3722_get_regulator_dt_data(struct platform_device *pdev,
692 struct as3722_regulators *as3722_regs)
693{
694 struct device_node *np;
695 struct as3722_regulator_config_data *reg_config;
696 u32 prop;
697 int id;
698 int ret;
699
700 np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
701 if (!np) {
702 dev_err(&pdev->dev, "Device is not having regulators node\n");
703 return -ENODEV;
704 }
705 pdev->dev.of_node = np;
706
707 ret = of_regulator_match(&pdev->dev, np, as3722_regulator_matches,
708 ARRAY_SIZE(as3722_regulator_matches));
709 if (ret < 0) {
710 dev_err(&pdev->dev, "Parsing of regulator node failed: %d\n",
711 ret);
712 return ret;
713 }
714
715 for (id = 0; id < ARRAY_SIZE(as3722_regulator_matches); ++id) {
716 struct device_node *reg_node;
717
718 reg_config = &as3722_regs->reg_config_data[id];
719 reg_config->reg_init = as3722_regulator_matches[id].init_data;
720 reg_node = as3722_regulator_matches[id].of_node;
721
722 if (!reg_config->reg_init || !reg_node)
723 continue;
724
725 ret = of_property_read_u32(reg_node, "ams,ext-control", &prop);
726 if (!ret) {
727 if (prop < 3)
728 reg_config->ext_control = prop;
729 else
730 dev_warn(&pdev->dev,
731 "ext-control have invalid option: %u\n",
732 prop);
733 }
734 reg_config->enable_tracking =
735 of_property_read_bool(reg_node, "ams,enable-tracking");
736 }
737 return 0;
738}
739
740static int as3722_regulator_probe(struct platform_device *pdev)
741{
742 struct as3722 *as3722 = dev_get_drvdata(pdev->dev.parent);
743 struct as3722_regulators *as3722_regs;
744 struct as3722_regulator_config_data *reg_config;
745 struct regulator_dev *rdev;
746 struct regulator_config config = { };
747 struct regulator_ops *ops;
748 int id;
749 int ret;
750
751 as3722_regs = devm_kzalloc(&pdev->dev, sizeof(*as3722_regs),
752 GFP_KERNEL);
753 if (!as3722_regs)
754 return -ENOMEM;
755
756 as3722_regs->dev = &pdev->dev;
757 as3722_regs->as3722 = as3722;
758 platform_set_drvdata(pdev, as3722_regs);
759
760 ret = as3722_get_regulator_dt_data(pdev, as3722_regs);
761 if (ret < 0)
762 return ret;
763
764 config.dev = &pdev->dev;
765 config.driver_data = as3722_regs;
766 config.regmap = as3722->regmap;
767
768 for (id = 0; id < AS3722_REGULATOR_ID_MAX; id++) {
769 reg_config = &as3722_regs->reg_config_data[id];
770
771 as3722_regs->desc[id].name = as3722_reg_lookup[id].name;
772 as3722_regs->desc[id].supply_name = as3722_reg_lookup[id].sname;
773 as3722_regs->desc[id].id = as3722_reg_lookup[id].regulator_id;
774 as3722_regs->desc[id].n_voltages =
775 as3722_reg_lookup[id].n_voltages;
776 as3722_regs->desc[id].type = REGULATOR_VOLTAGE;
777 as3722_regs->desc[id].owner = THIS_MODULE;
778 as3722_regs->desc[id].enable_reg =
779 as3722_reg_lookup[id].enable_reg;
780 as3722_regs->desc[id].enable_mask =
781 as3722_reg_lookup[id].enable_mask;
782 as3722_regs->desc[id].vsel_reg = as3722_reg_lookup[id].vsel_reg;
783 as3722_regs->desc[id].vsel_mask =
784 as3722_reg_lookup[id].vsel_mask;
785 switch (id) {
786 case AS3722_REGULATOR_ID_LDO0:
787 if (reg_config->ext_control)
788 ops = &as3722_ldo0_extcntrl_ops;
789 else
790 ops = &as3722_ldo0_ops;
791 as3722_regs->desc[id].min_uV = 825000;
792 as3722_regs->desc[id].uV_step = 25000;
793 as3722_regs->desc[id].linear_min_sel = 1;
794 as3722_regs->desc[id].enable_time = 500;
795 break;
796 case AS3722_REGULATOR_ID_LDO3:
797 if (reg_config->ext_control)
798 ops = &as3722_ldo3_extcntrl_ops;
799 else
800 ops = &as3722_ldo3_ops;
801 as3722_regs->desc[id].min_uV = 620000;
802 as3722_regs->desc[id].uV_step = 20000;
803 as3722_regs->desc[id].linear_min_sel = 1;
804 as3722_regs->desc[id].enable_time = 500;
805 if (reg_config->enable_tracking) {
806 ret = as3722_ldo3_set_tracking_mode(as3722_regs,
807 id, AS3722_LDO3_MODE_PMOS_TRACKING);
808 if (ret < 0) {
809 dev_err(&pdev->dev,
810 "LDO3 tracking failed: %d\n",
811 ret);
812 return ret;
813 }
814 }
815 break;
816 case AS3722_REGULATOR_ID_SD0:
817 case AS3722_REGULATOR_ID_SD1:
818 case AS3722_REGULATOR_ID_SD6:
819 if (reg_config->ext_control)
820 ops = &as3722_sd016_extcntrl_ops;
821 else
822 ops = &as3722_sd016_ops;
823 as3722_regs->desc[id].min_uV = 610000;
824 as3722_regs->desc[id].uV_step = 10000;
825 as3722_regs->desc[id].linear_min_sel = 1;
826 break;
827 case AS3722_REGULATOR_ID_SD2:
828 case AS3722_REGULATOR_ID_SD3:
829 case AS3722_REGULATOR_ID_SD4:
830 case AS3722_REGULATOR_ID_SD5:
831 if (reg_config->ext_control)
832 ops = &as3722_sd2345_extcntrl_ops;
833 else
834 ops = &as3722_sd2345_ops;
835 as3722_regs->desc[id].linear_ranges =
836 as3722_sd2345_ranges;
837 as3722_regs->desc[id].n_linear_ranges =
838 ARRAY_SIZE(as3722_sd2345_ranges);
839 break;
840 default:
841 if (reg_config->ext_control)
842 ops = &as3722_ldo_extcntrl_ops;
843 else
844 ops = &as3722_ldo_ops;
845 as3722_regs->desc[id].min_uV = 825000;
846 as3722_regs->desc[id].uV_step = 25000;
847 as3722_regs->desc[id].linear_min_sel = 1;
848 as3722_regs->desc[id].enable_time = 500;
849 as3722_regs->desc[id].linear_ranges = as3722_ldo_ranges;
850 as3722_regs->desc[id].n_linear_ranges =
851 ARRAY_SIZE(as3722_ldo_ranges);
852 break;
853 }
854 as3722_regs->desc[id].ops = ops;
855 config.init_data = reg_config->reg_init;
856 config.of_node = as3722_regulator_matches[id].of_node;
857 rdev = devm_regulator_register(&pdev->dev,
858 &as3722_regs->desc[id], &config);
859 if (IS_ERR(rdev)) {
860 ret = PTR_ERR(rdev);
861 dev_err(&pdev->dev, "regulator %d register failed %d\n",
862 id, ret);
863 return ret;
864 }
865
866 as3722_regs->rdevs[id] = rdev;
867 if (reg_config->ext_control) {
868 ret = regulator_enable_regmap(rdev);
869 if (ret < 0) {
870 dev_err(&pdev->dev,
871 "Regulator %d enable failed: %d\n",
872 id, ret);
873 return ret;
874 }
875 ret = as3722_extreg_init(as3722_regs, id,
876 reg_config->ext_control);
877 if (ret < 0) {
878 dev_err(&pdev->dev,
879 "AS3722 ext control failed: %d", ret);
880 return ret;
881 }
882 }
883 }
884 return 0;
885}
886
887static const struct of_device_id of_as3722_regulator_match[] = {
888 { .compatible = "ams,as3722-regulator", },
889 {},
890};
891MODULE_DEVICE_TABLE(of, of_as3722_regulator_match);
892
893static struct platform_driver as3722_regulator_driver = {
894 .driver = {
895 .name = "as3722-regulator",
896 .owner = THIS_MODULE,
897 .of_match_table = of_as3722_regulator_match,
898 },
899 .probe = as3722_regulator_probe,
900};
901
902module_platform_driver(as3722_regulator_driver);
903
904MODULE_ALIAS("platform:as3722-regulator");
905MODULE_DESCRIPTION("AS3722 regulator driver");
906MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
907MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
908MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a01b8b3b70ca..6382f0af353b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -36,6 +36,7 @@
36#include <trace/events/regulator.h> 36#include <trace/events/regulator.h>
37 37
38#include "dummy.h" 38#include "dummy.h"
39#include "internal.h"
39 40
40#define rdev_crit(rdev, fmt, ...) \ 41#define rdev_crit(rdev, fmt, ...) \
41 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__) 42 pr_crit("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
@@ -52,8 +53,8 @@ static DEFINE_MUTEX(regulator_list_mutex);
52static LIST_HEAD(regulator_list); 53static LIST_HEAD(regulator_list);
53static LIST_HEAD(regulator_map_list); 54static LIST_HEAD(regulator_map_list);
54static LIST_HEAD(regulator_ena_gpio_list); 55static LIST_HEAD(regulator_ena_gpio_list);
56static LIST_HEAD(regulator_supply_alias_list);
55static bool has_full_constraints; 57static bool has_full_constraints;
56static bool board_wants_dummy_regulator;
57 58
58static struct dentry *debugfs_root; 59static struct dentry *debugfs_root;
59 60
@@ -83,22 +84,16 @@ struct regulator_enable_gpio {
83}; 84};
84 85
85/* 86/*
86 * struct regulator 87 * struct regulator_supply_alias
87 * 88 *
88 * One for each consumer device. 89 * Used to map lookups for a supply onto an alternative device.
89 */ 90 */
90struct regulator { 91struct regulator_supply_alias {
91 struct device *dev;
92 struct list_head list; 92 struct list_head list;
93 unsigned int always_on:1; 93 struct device *src_dev;
94 unsigned int bypass:1; 94 const char *src_supply;
95 int uA_load; 95 struct device *alias_dev;
96 int min_uV; 96 const char *alias_supply;
97 int max_uV;
98 char *supply_name;
99 struct device_attribute dev_attr;
100 struct regulator_dev *rdev;
101 struct dentry *debugfs;
102}; 97};
103 98
104static int _regulator_is_enabled(struct regulator_dev *rdev); 99static int _regulator_is_enabled(struct regulator_dev *rdev);
@@ -923,6 +918,36 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
923 return 0; 918 return 0;
924} 919}
925 920
921static int machine_constraints_current(struct regulator_dev *rdev,
922 struct regulation_constraints *constraints)
923{
924 struct regulator_ops *ops = rdev->desc->ops;
925 int ret;
926
927 if (!constraints->min_uA && !constraints->max_uA)
928 return 0;
929
930 if (constraints->min_uA > constraints->max_uA) {
931 rdev_err(rdev, "Invalid current constraints\n");
932 return -EINVAL;
933 }
934
935 if (!ops->set_current_limit || !ops->get_current_limit) {
936 rdev_warn(rdev, "Operation of current configuration missing\n");
937 return 0;
938 }
939
940 /* Set regulator current in constraints range */
941 ret = ops->set_current_limit(rdev, constraints->min_uA,
942 constraints->max_uA);
943 if (ret < 0) {
944 rdev_err(rdev, "Failed to set current constraint, %d\n", ret);
945 return ret;
946 }
947
948 return 0;
949}
950
926/** 951/**
927 * set_machine_constraints - sets regulator constraints 952 * set_machine_constraints - sets regulator constraints
928 * @rdev: regulator source 953 * @rdev: regulator source
@@ -953,6 +978,10 @@ static int set_machine_constraints(struct regulator_dev *rdev,
953 if (ret != 0) 978 if (ret != 0)
954 goto out; 979 goto out;
955 980
981 ret = machine_constraints_current(rdev, rdev->constraints);
982 if (ret != 0)
983 goto out;
984
956 /* do we need to setup our suspend state */ 985 /* do we need to setup our suspend state */
957 if (rdev->constraints->initial_state) { 986 if (rdev->constraints->initial_state) {
958 ret = suspend_prepare(rdev, rdev->constraints->initial_state); 987 ret = suspend_prepare(rdev, rdev->constraints->initial_state);
@@ -1186,11 +1215,39 @@ overflow_err:
1186 1215
1187static int _regulator_get_enable_time(struct regulator_dev *rdev) 1216static int _regulator_get_enable_time(struct regulator_dev *rdev)
1188{ 1217{
1218 if (rdev->constraints && rdev->constraints->enable_time)
1219 return rdev->constraints->enable_time;
1189 if (!rdev->desc->ops->enable_time) 1220 if (!rdev->desc->ops->enable_time)
1190 return rdev->desc->enable_time; 1221 return rdev->desc->enable_time;
1191 return rdev->desc->ops->enable_time(rdev); 1222 return rdev->desc->ops->enable_time(rdev);
1192} 1223}
1193 1224
1225static struct regulator_supply_alias *regulator_find_supply_alias(
1226 struct device *dev, const char *supply)
1227{
1228 struct regulator_supply_alias *map;
1229
1230 list_for_each_entry(map, &regulator_supply_alias_list, list)
1231 if (map->src_dev == dev && strcmp(map->src_supply, supply) == 0)
1232 return map;
1233
1234 return NULL;
1235}
1236
1237static void regulator_supply_alias(struct device **dev, const char **supply)
1238{
1239 struct regulator_supply_alias *map;
1240
1241 map = regulator_find_supply_alias(*dev, *supply);
1242 if (map) {
1243 dev_dbg(*dev, "Mapping supply %s to %s,%s\n",
1244 *supply, map->alias_supply,
1245 dev_name(map->alias_dev));
1246 *dev = map->alias_dev;
1247 *supply = map->alias_supply;
1248 }
1249}
1250
1194static struct regulator_dev *regulator_dev_lookup(struct device *dev, 1251static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1195 const char *supply, 1252 const char *supply,
1196 int *ret) 1253 int *ret)
@@ -1200,6 +1257,8 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1200 struct regulator_map *map; 1257 struct regulator_map *map;
1201 const char *devname = NULL; 1258 const char *devname = NULL;
1202 1259
1260 regulator_supply_alias(&dev, &supply);
1261
1203 /* first do a dt based lookup */ 1262 /* first do a dt based lookup */
1204 if (dev && dev->of_node) { 1263 if (dev && dev->of_node) {
1205 node = of_get_regulator(dev, supply); 1264 node = of_get_regulator(dev, supply);
@@ -1243,16 +1302,16 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1243 1302
1244/* Internal regulator request function */ 1303/* Internal regulator request function */
1245static struct regulator *_regulator_get(struct device *dev, const char *id, 1304static struct regulator *_regulator_get(struct device *dev, const char *id,
1246 bool exclusive) 1305 bool exclusive, bool allow_dummy)
1247{ 1306{
1248 struct regulator_dev *rdev; 1307 struct regulator_dev *rdev;
1249 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); 1308 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
1250 const char *devname = NULL; 1309 const char *devname = NULL;
1251 int ret = 0; 1310 int ret = -EPROBE_DEFER;
1252 1311
1253 if (id == NULL) { 1312 if (id == NULL) {
1254 pr_err("get() with no identifier\n"); 1313 pr_err("get() with no identifier\n");
1255 return regulator; 1314 return ERR_PTR(-EINVAL);
1256 } 1315 }
1257 1316
1258 if (dev) 1317 if (dev)
@@ -1264,34 +1323,32 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1264 if (rdev) 1323 if (rdev)
1265 goto found; 1324 goto found;
1266 1325
1326 regulator = ERR_PTR(ret);
1327
1267 /* 1328 /*
1268 * If we have return value from dev_lookup fail, we do not expect to 1329 * If we have return value from dev_lookup fail, we do not expect to
1269 * succeed, so, quit with appropriate error value 1330 * succeed, so, quit with appropriate error value
1270 */ 1331 */
1271 if (ret) { 1332 if (ret && ret != -ENODEV) {
1272 regulator = ERR_PTR(ret);
1273 goto out; 1333 goto out;
1274 } 1334 }
1275 1335
1276 if (board_wants_dummy_regulator) {
1277 rdev = dummy_regulator_rdev;
1278 goto found;
1279 }
1280
1281#ifdef CONFIG_REGULATOR_DUMMY
1282 if (!devname) 1336 if (!devname)
1283 devname = "deviceless"; 1337 devname = "deviceless";
1284 1338
1285 /* If the board didn't flag that it was fully constrained then 1339 /*
1286 * substitute in a dummy regulator so consumers can continue. 1340 * Assume that a regulator is physically present and enabled
1341 * even if it isn't hooked up and just provide a dummy.
1287 */ 1342 */
1288 if (!has_full_constraints) { 1343 if (has_full_constraints && allow_dummy) {
1289 pr_warn("%s supply %s not found, using dummy regulator\n", 1344 pr_warn("%s supply %s not found, using dummy regulator\n",
1290 devname, id); 1345 devname, id);
1346
1291 rdev = dummy_regulator_rdev; 1347 rdev = dummy_regulator_rdev;
1292 goto found; 1348 goto found;
1349 } else {
1350 dev_err(dev, "dummy supplies not allowed\n");
1293 } 1351 }
1294#endif
1295 1352
1296 mutex_unlock(&regulator_list_mutex); 1353 mutex_unlock(&regulator_list_mutex);
1297 return regulator; 1354 return regulator;
@@ -1349,44 +1406,10 @@ out:
1349 */ 1406 */
1350struct regulator *regulator_get(struct device *dev, const char *id) 1407struct regulator *regulator_get(struct device *dev, const char *id)
1351{ 1408{
1352 return _regulator_get(dev, id, false); 1409 return _regulator_get(dev, id, false, true);
1353} 1410}
1354EXPORT_SYMBOL_GPL(regulator_get); 1411EXPORT_SYMBOL_GPL(regulator_get);
1355 1412
1356static void devm_regulator_release(struct device *dev, void *res)
1357{
1358 regulator_put(*(struct regulator **)res);
1359}
1360
1361/**
1362 * devm_regulator_get - Resource managed regulator_get()
1363 * @dev: device for regulator "consumer"
1364 * @id: Supply name or regulator ID.
1365 *
1366 * Managed regulator_get(). Regulators returned from this function are
1367 * automatically regulator_put() on driver detach. See regulator_get() for more
1368 * information.
1369 */
1370struct regulator *devm_regulator_get(struct device *dev, const char *id)
1371{
1372 struct regulator **ptr, *regulator;
1373
1374 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1375 if (!ptr)
1376 return ERR_PTR(-ENOMEM);
1377
1378 regulator = regulator_get(dev, id);
1379 if (!IS_ERR(regulator)) {
1380 *ptr = regulator;
1381 devres_add(dev, ptr);
1382 } else {
1383 devres_free(ptr);
1384 }
1385
1386 return regulator;
1387}
1388EXPORT_SYMBOL_GPL(devm_regulator_get);
1389
1390/** 1413/**
1391 * regulator_get_exclusive - obtain exclusive access to a regulator. 1414 * regulator_get_exclusive - obtain exclusive access to a regulator.
1392 * @dev: device for regulator "consumer" 1415 * @dev: device for regulator "consumer"
@@ -1410,7 +1433,7 @@ EXPORT_SYMBOL_GPL(devm_regulator_get);
1410 */ 1433 */
1411struct regulator *regulator_get_exclusive(struct device *dev, const char *id) 1434struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
1412{ 1435{
1413 return _regulator_get(dev, id, true); 1436 return _regulator_get(dev, id, true, false);
1414} 1437}
1415EXPORT_SYMBOL_GPL(regulator_get_exclusive); 1438EXPORT_SYMBOL_GPL(regulator_get_exclusive);
1416 1439
@@ -1439,40 +1462,10 @@ EXPORT_SYMBOL_GPL(regulator_get_exclusive);
1439 */ 1462 */
1440struct regulator *regulator_get_optional(struct device *dev, const char *id) 1463struct regulator *regulator_get_optional(struct device *dev, const char *id)
1441{ 1464{
1442 return _regulator_get(dev, id, 0); 1465 return _regulator_get(dev, id, false, false);
1443} 1466}
1444EXPORT_SYMBOL_GPL(regulator_get_optional); 1467EXPORT_SYMBOL_GPL(regulator_get_optional);
1445 1468
1446/**
1447 * devm_regulator_get_optional - Resource managed regulator_get_optional()
1448 * @dev: device for regulator "consumer"
1449 * @id: Supply name or regulator ID.
1450 *
1451 * Managed regulator_get_optional(). Regulators returned from this
1452 * function are automatically regulator_put() on driver detach. See
1453 * regulator_get_optional() for more information.
1454 */
1455struct regulator *devm_regulator_get_optional(struct device *dev,
1456 const char *id)
1457{
1458 struct regulator **ptr, *regulator;
1459
1460 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1461 if (!ptr)
1462 return ERR_PTR(-ENOMEM);
1463
1464 regulator = regulator_get_optional(dev, id);
1465 if (!IS_ERR(regulator)) {
1466 *ptr = regulator;
1467 devres_add(dev, ptr);
1468 } else {
1469 devres_free(ptr);
1470 }
1471
1472 return regulator;
1473}
1474EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
1475
1476/* Locks held by regulator_put() */ 1469/* Locks held by regulator_put() */
1477static void _regulator_put(struct regulator *regulator) 1470static void _regulator_put(struct regulator *regulator)
1478{ 1471{
@@ -1499,36 +1492,6 @@ static void _regulator_put(struct regulator *regulator)
1499} 1492}
1500 1493
1501/** 1494/**
1502 * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
1503 * @dev: device for regulator "consumer"
1504 * @id: Supply name or regulator ID.
1505 *
1506 * Managed regulator_get_exclusive(). Regulators returned from this function
1507 * are automatically regulator_put() on driver detach. See regulator_get() for
1508 * more information.
1509 */
1510struct regulator *devm_regulator_get_exclusive(struct device *dev,
1511 const char *id)
1512{
1513 struct regulator **ptr, *regulator;
1514
1515 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
1516 if (!ptr)
1517 return ERR_PTR(-ENOMEM);
1518
1519 regulator = _regulator_get(dev, id, 1);
1520 if (!IS_ERR(regulator)) {
1521 *ptr = regulator;
1522 devres_add(dev, ptr);
1523 } else {
1524 devres_free(ptr);
1525 }
1526
1527 return regulator;
1528}
1529EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
1530
1531/**
1532 * regulator_put - "free" the regulator source 1495 * regulator_put - "free" the regulator source
1533 * @regulator: regulator source 1496 * @regulator: regulator source
1534 * 1497 *
@@ -1544,34 +1507,133 @@ void regulator_put(struct regulator *regulator)
1544} 1507}
1545EXPORT_SYMBOL_GPL(regulator_put); 1508EXPORT_SYMBOL_GPL(regulator_put);
1546 1509
1547static int devm_regulator_match(struct device *dev, void *res, void *data) 1510/**
1511 * regulator_register_supply_alias - Provide device alias for supply lookup
1512 *
1513 * @dev: device that will be given as the regulator "consumer"
1514 * @id: Supply name or regulator ID
1515 * @alias_dev: device that should be used to lookup the supply
1516 * @alias_id: Supply name or regulator ID that should be used to lookup the
1517 * supply
1518 *
1519 * All lookups for id on dev will instead be conducted for alias_id on
1520 * alias_dev.
1521 */
1522int regulator_register_supply_alias(struct device *dev, const char *id,
1523 struct device *alias_dev,
1524 const char *alias_id)
1525{
1526 struct regulator_supply_alias *map;
1527
1528 map = regulator_find_supply_alias(dev, id);
1529 if (map)
1530 return -EEXIST;
1531
1532 map = kzalloc(sizeof(struct regulator_supply_alias), GFP_KERNEL);
1533 if (!map)
1534 return -ENOMEM;
1535
1536 map->src_dev = dev;
1537 map->src_supply = id;
1538 map->alias_dev = alias_dev;
1539 map->alias_supply = alias_id;
1540
1541 list_add(&map->list, &regulator_supply_alias_list);
1542
1543 pr_info("Adding alias for supply %s,%s -> %s,%s\n",
1544 id, dev_name(dev), alias_id, dev_name(alias_dev));
1545
1546 return 0;
1547}
1548EXPORT_SYMBOL_GPL(regulator_register_supply_alias);
1549
1550/**
1551 * regulator_unregister_supply_alias - Remove device alias
1552 *
1553 * @dev: device that will be given as the regulator "consumer"
1554 * @id: Supply name or regulator ID
1555 *
1556 * Remove a lookup alias if one exists for id on dev.
1557 */
1558void regulator_unregister_supply_alias(struct device *dev, const char *id)
1548{ 1559{
1549 struct regulator **r = res; 1560 struct regulator_supply_alias *map;
1550 if (!r || !*r) { 1561
1551 WARN_ON(!r || !*r); 1562 map = regulator_find_supply_alias(dev, id);
1552 return 0; 1563 if (map) {
1564 list_del(&map->list);
1565 kfree(map);
1553 } 1566 }
1554 return *r == data;
1555} 1567}
1568EXPORT_SYMBOL_GPL(regulator_unregister_supply_alias);
1556 1569
1557/** 1570/**
1558 * devm_regulator_put - Resource managed regulator_put() 1571 * regulator_bulk_register_supply_alias - register multiple aliases
1559 * @regulator: regulator to free 1572 *
1573 * @dev: device that will be given as the regulator "consumer"
1574 * @id: List of supply names or regulator IDs
1575 * @alias_dev: device that should be used to lookup the supply
1576 * @alias_id: List of supply names or regulator IDs that should be used to
1577 * lookup the supply
1578 * @num_id: Number of aliases to register
1579 *
1580 * @return 0 on success, an errno on failure.
1560 * 1581 *
1561 * Deallocate a regulator allocated with devm_regulator_get(). Normally 1582 * This helper function allows drivers to register several supply
1562 * this function will not need to be called and the resource management 1583 * aliases in one operation. If any of the aliases cannot be
1563 * code will ensure that the resource is freed. 1584 * registered any aliases that were registered will be removed
1585 * before returning to the caller.
1564 */ 1586 */
1565void devm_regulator_put(struct regulator *regulator) 1587int regulator_bulk_register_supply_alias(struct device *dev, const char **id,
1588 struct device *alias_dev,
1589 const char **alias_id,
1590 int num_id)
1566{ 1591{
1567 int rc; 1592 int i;
1593 int ret;
1594
1595 for (i = 0; i < num_id; ++i) {
1596 ret = regulator_register_supply_alias(dev, id[i], alias_dev,
1597 alias_id[i]);
1598 if (ret < 0)
1599 goto err;
1600 }
1601
1602 return 0;
1603
1604err:
1605 dev_err(dev,
1606 "Failed to create supply alias %s,%s -> %s,%s\n",
1607 id[i], dev_name(dev), alias_id[i], dev_name(alias_dev));
1608
1609 while (--i >= 0)
1610 regulator_unregister_supply_alias(dev, id[i]);
1611
1612 return ret;
1613}
1614EXPORT_SYMBOL_GPL(regulator_bulk_register_supply_alias);
1615
1616/**
1617 * regulator_bulk_unregister_supply_alias - unregister multiple aliases
1618 *
1619 * @dev: device that will be given as the regulator "consumer"
1620 * @id: List of supply names or regulator IDs
1621 * @num_id: Number of aliases to unregister
1622 *
1623 * This helper function allows drivers to unregister several supply
1624 * aliases in one operation.
1625 */
1626void regulator_bulk_unregister_supply_alias(struct device *dev,
1627 const char **id,
1628 int num_id)
1629{
1630 int i;
1568 1631
1569 rc = devres_release(regulator->dev, devm_regulator_release, 1632 for (i = 0; i < num_id; ++i)
1570 devm_regulator_match, regulator); 1633 regulator_unregister_supply_alias(dev, id[i]);
1571 if (rc != 0)
1572 WARN_ON(rc);
1573} 1634}
1574EXPORT_SYMBOL_GPL(devm_regulator_put); 1635EXPORT_SYMBOL_GPL(regulator_bulk_unregister_supply_alias);
1636
1575 1637
1576/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */ 1638/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */
1577static int regulator_ena_gpio_request(struct regulator_dev *rdev, 1639static int regulator_ena_gpio_request(struct regulator_dev *rdev,
@@ -1704,11 +1766,39 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
1704 * together. */ 1766 * together. */
1705 trace_regulator_enable_delay(rdev_get_name(rdev)); 1767 trace_regulator_enable_delay(rdev_get_name(rdev));
1706 1768
1707 if (delay >= 1000) { 1769 /*
1708 mdelay(delay / 1000); 1770 * Delay for the requested amount of time as per the guidelines in:
1709 udelay(delay % 1000); 1771 *
1710 } else if (delay) { 1772 * Documentation/timers/timers-howto.txt
1711 udelay(delay); 1773 *
1774 * The assumption here is that regulators will never be enabled in
1775 * atomic context and therefore sleeping functions can be used.
1776 */
1777 if (delay) {
1778 unsigned int ms = delay / 1000;
1779 unsigned int us = delay % 1000;
1780
1781 if (ms > 0) {
1782 /*
1783 * For small enough values, handle super-millisecond
1784 * delays in the usleep_range() call below.
1785 */
1786 if (ms < 20)
1787 us += ms * 1000;
1788 else
1789 msleep(ms);
1790 }
1791
1792 /*
1793 * Give the scheduler some room to coalesce with any other
1794 * wakeup sources. For delays shorter than 10 us, don't even
1795 * bother setting up high-resolution timers and just busy-
1796 * loop.
1797 */
1798 if (us >= 10)
1799 usleep_range(us, us + 100);
1800 else
1801 udelay(us);
1712 } 1802 }
1713 1803
1714 trace_regulator_enable_complete(rdev_get_name(rdev)); 1804 trace_regulator_enable_complete(rdev_get_name(rdev));
@@ -2489,6 +2579,8 @@ static int _regulator_get_voltage(struct regulator_dev *rdev)
2489 ret = rdev->desc->ops->get_voltage(rdev); 2579 ret = rdev->desc->ops->get_voltage(rdev);
2490 } else if (rdev->desc->ops->list_voltage) { 2580 } else if (rdev->desc->ops->list_voltage) {
2491 ret = rdev->desc->ops->list_voltage(rdev, 0); 2581 ret = rdev->desc->ops->list_voltage(rdev, 0);
2582 } else if (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1)) {
2583 ret = rdev->desc->fixed_uV;
2492 } else { 2584 } else {
2493 return -EINVAL; 2585 return -EINVAL;
2494 } 2586 }
@@ -2912,52 +3004,6 @@ err:
2912} 3004}
2913EXPORT_SYMBOL_GPL(regulator_bulk_get); 3005EXPORT_SYMBOL_GPL(regulator_bulk_get);
2914 3006
2915/**
2916 * devm_regulator_bulk_get - managed get multiple regulator consumers
2917 *
2918 * @dev: Device to supply
2919 * @num_consumers: Number of consumers to register
2920 * @consumers: Configuration of consumers; clients are stored here.
2921 *
2922 * @return 0 on success, an errno on failure.
2923 *
2924 * This helper function allows drivers to get several regulator
2925 * consumers in one operation with management, the regulators will
2926 * automatically be freed when the device is unbound. If any of the
2927 * regulators cannot be acquired then any regulators that were
2928 * allocated will be freed before returning to the caller.
2929 */
2930int devm_regulator_bulk_get(struct device *dev, int num_consumers,
2931 struct regulator_bulk_data *consumers)
2932{
2933 int i;
2934 int ret;
2935
2936 for (i = 0; i < num_consumers; i++)
2937 consumers[i].consumer = NULL;
2938
2939 for (i = 0; i < num_consumers; i++) {
2940 consumers[i].consumer = devm_regulator_get(dev,
2941 consumers[i].supply);
2942 if (IS_ERR(consumers[i].consumer)) {
2943 ret = PTR_ERR(consumers[i].consumer);
2944 dev_err(dev, "Failed to get supply '%s': %d\n",
2945 consumers[i].supply, ret);
2946 consumers[i].consumer = NULL;
2947 goto err;
2948 }
2949 }
2950
2951 return 0;
2952
2953err:
2954 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
2955 devm_regulator_put(consumers[i].consumer);
2956
2957 return ret;
2958}
2959EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
2960
2961static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) 3007static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
2962{ 3008{
2963 struct regulator_bulk_data *bulk = data; 3009 struct regulator_bulk_data *bulk = data;
@@ -3170,7 +3216,8 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
3170 /* some attributes need specific methods to be displayed */ 3216 /* some attributes need specific methods to be displayed */
3171 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || 3217 if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) ||
3172 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) || 3218 (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) ||
3173 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0)) { 3219 (ops->list_voltage && ops->list_voltage(rdev, 0) >= 0) ||
3220 (rdev->desc->fixed_uV && (rdev->desc->n_voltages == 1))) {
3174 status = device_create_file(dev, &dev_attr_microvolts); 3221 status = device_create_file(dev, &dev_attr_microvolts);
3175 if (status < 0) 3222 if (status < 0)
3176 return status; 3223 return status;
@@ -3614,22 +3661,6 @@ void regulator_has_full_constraints(void)
3614EXPORT_SYMBOL_GPL(regulator_has_full_constraints); 3661EXPORT_SYMBOL_GPL(regulator_has_full_constraints);
3615 3662
3616/** 3663/**
3617 * regulator_use_dummy_regulator - Provide a dummy regulator when none is found
3618 *
3619 * Calling this function will cause the regulator API to provide a
3620 * dummy regulator to consumers if no physical regulator is found,
3621 * allowing most consumers to proceed as though a regulator were
3622 * configured. This allows systems such as those with software
3623 * controllable regulators for the CPU core only to be brought up more
3624 * readily.
3625 */
3626void regulator_use_dummy_regulator(void)
3627{
3628 board_wants_dummy_regulator = true;
3629}
3630EXPORT_SYMBOL_GPL(regulator_use_dummy_regulator);
3631
3632/**
3633 * rdev_get_drvdata - get rdev regulator driver data 3664 * rdev_get_drvdata - get rdev regulator driver data
3634 * @rdev: regulator 3665 * @rdev: regulator
3635 * 3666 *
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index f06854cf8cf5..b431ae357fcd 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -253,10 +253,8 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev,
253} 253}
254 254
255static const struct regulator_linear_range da9034_ldo12_ranges[] = { 255static const struct regulator_linear_range da9034_ldo12_ranges[] = {
256 { .min_uV = 1700000, .max_uV = 2050000, .min_sel = 0, .max_sel = 7, 256 REGULATOR_LINEAR_RANGE(1700000, 0, 7, 50000),
257 .uV_step = 50000 }, 257 REGULATOR_LINEAR_RANGE(2700000, 8, 15, 50000),
258 { .min_uV = 2700000, .max_uV = 3050000, .min_sel = 8, .max_sel = 15,
259 .uV_step = 50000 },
260}; 258};
261 259
262static struct regulator_ops da903x_regulator_ldo_ops = { 260static struct regulator_ops da903x_regulator_ldo_ops = {
@@ -463,7 +461,7 @@ static int da903x_regulator_probe(struct platform_device *pdev)
463 config.init_data = dev_get_platdata(&pdev->dev); 461 config.init_data = dev_get_platdata(&pdev->dev);
464 config.driver_data = ri; 462 config.driver_data = ri;
465 463
466 rdev = regulator_register(&ri->desc, &config); 464 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
467 if (IS_ERR(rdev)) { 465 if (IS_ERR(rdev)) {
468 dev_err(&pdev->dev, "failed to register regulator %s\n", 466 dev_err(&pdev->dev, "failed to register regulator %s\n",
469 ri->desc.name); 467 ri->desc.name);
@@ -474,21 +472,12 @@ static int da903x_regulator_probe(struct platform_device *pdev)
474 return 0; 472 return 0;
475} 473}
476 474
477static int da903x_regulator_remove(struct platform_device *pdev)
478{
479 struct regulator_dev *rdev = platform_get_drvdata(pdev);
480
481 regulator_unregister(rdev);
482 return 0;
483}
484
485static struct platform_driver da903x_regulator_driver = { 475static struct platform_driver da903x_regulator_driver = {
486 .driver = { 476 .driver = {
487 .name = "da903x-regulator", 477 .name = "da903x-regulator",
488 .owner = THIS_MODULE, 478 .owner = THIS_MODULE,
489 }, 479 },
490 .probe = da903x_regulator_probe, 480 .probe = da903x_regulator_probe,
491 .remove = da903x_regulator_remove,
492}; 481};
493 482
494static int __init da903x_regulator_init(void) 483static int __init da903x_regulator_init(void)
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 1e4d483f6163..3adeaeffc485 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -70,6 +70,7 @@ struct da9052_regulator_info {
70 int step_uV; 70 int step_uV;
71 int min_uV; 71 int min_uV;
72 int max_uV; 72 int max_uV;
73 unsigned char activate_bit;
73}; 74};
74 75
75struct da9052_regulator { 76struct da9052_regulator {
@@ -209,6 +210,36 @@ static int da9052_map_voltage(struct regulator_dev *rdev,
209 return sel; 210 return sel;
210} 211}
211 212
213static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev,
214 unsigned int selector)
215{
216 struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
217 struct da9052_regulator_info *info = regulator->info;
218 int id = rdev_get_id(rdev);
219 int ret;
220
221 ret = da9052_reg_update(regulator->da9052, rdev->desc->vsel_reg,
222 rdev->desc->vsel_mask, selector);
223 if (ret < 0)
224 return ret;
225
226 /* Some LDOs and DCDCs are DVC controlled which requires enabling of
227 * the activate bit to implment the changes on the output.
228 */
229 switch (id) {
230 case DA9052_ID_BUCK1:
231 case DA9052_ID_BUCK2:
232 case DA9052_ID_BUCK3:
233 case DA9052_ID_LDO2:
234 case DA9052_ID_LDO3:
235 ret = da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG,
236 info->activate_bit, info->activate_bit);
237 break;
238 }
239
240 return ret;
241}
242
212static struct regulator_ops da9052_dcdc_ops = { 243static struct regulator_ops da9052_dcdc_ops = {
213 .get_current_limit = da9052_dcdc_get_current_limit, 244 .get_current_limit = da9052_dcdc_get_current_limit,
214 .set_current_limit = da9052_dcdc_set_current_limit, 245 .set_current_limit = da9052_dcdc_set_current_limit,
@@ -216,7 +247,7 @@ static struct regulator_ops da9052_dcdc_ops = {
216 .list_voltage = da9052_list_voltage, 247 .list_voltage = da9052_list_voltage,
217 .map_voltage = da9052_map_voltage, 248 .map_voltage = da9052_map_voltage,
218 .get_voltage_sel = regulator_get_voltage_sel_regmap, 249 .get_voltage_sel = regulator_get_voltage_sel_regmap,
219 .set_voltage_sel = regulator_set_voltage_sel_regmap, 250 .set_voltage_sel = da9052_regulator_set_voltage_sel,
220 .is_enabled = regulator_is_enabled_regmap, 251 .is_enabled = regulator_is_enabled_regmap,
221 .enable = regulator_enable_regmap, 252 .enable = regulator_enable_regmap,
222 .disable = regulator_disable_regmap, 253 .disable = regulator_disable_regmap,
@@ -226,7 +257,7 @@ static struct regulator_ops da9052_ldo_ops = {
226 .list_voltage = da9052_list_voltage, 257 .list_voltage = da9052_list_voltage,
227 .map_voltage = da9052_map_voltage, 258 .map_voltage = da9052_map_voltage,
228 .get_voltage_sel = regulator_get_voltage_sel_regmap, 259 .get_voltage_sel = regulator_get_voltage_sel_regmap,
229 .set_voltage_sel = regulator_set_voltage_sel_regmap, 260 .set_voltage_sel = da9052_regulator_set_voltage_sel,
230 .is_enabled = regulator_is_enabled_regmap, 261 .is_enabled = regulator_is_enabled_regmap,
231 .enable = regulator_enable_regmap, 262 .enable = regulator_enable_regmap,
232 .disable = regulator_disable_regmap, 263 .disable = regulator_disable_regmap,
@@ -243,14 +274,13 @@ static struct regulator_ops da9052_ldo_ops = {
243 .owner = THIS_MODULE,\ 274 .owner = THIS_MODULE,\
244 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ 275 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
245 .vsel_mask = (1 << (sbits)) - 1,\ 276 .vsel_mask = (1 << (sbits)) - 1,\
246 .apply_reg = DA9052_SUPPLY_REG, \
247 .apply_bit = (abits), \
248 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ 277 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
249 .enable_mask = 1 << (ebits),\ 278 .enable_mask = 1 << (ebits),\
250 },\ 279 },\
251 .min_uV = (min) * 1000,\ 280 .min_uV = (min) * 1000,\
252 .max_uV = (max) * 1000,\ 281 .max_uV = (max) * 1000,\
253 .step_uV = (step) * 1000,\ 282 .step_uV = (step) * 1000,\
283 .activate_bit = (abits),\
254} 284}
255 285
256#define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \ 286#define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \
@@ -264,14 +294,13 @@ static struct regulator_ops da9052_ldo_ops = {
264 .owner = THIS_MODULE,\ 294 .owner = THIS_MODULE,\
265 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ 295 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
266 .vsel_mask = (1 << (sbits)) - 1,\ 296 .vsel_mask = (1 << (sbits)) - 1,\
267 .apply_reg = DA9052_SUPPLY_REG, \
268 .apply_bit = (abits), \
269 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ 297 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
270 .enable_mask = 1 << (ebits),\ 298 .enable_mask = 1 << (ebits),\
271 },\ 299 },\
272 .min_uV = (min) * 1000,\ 300 .min_uV = (min) * 1000,\
273 .max_uV = (max) * 1000,\ 301 .max_uV = (max) * 1000,\
274 .step_uV = (step) * 1000,\ 302 .step_uV = (step) * 1000,\
303 .activate_bit = (abits),\
275} 304}
276 305
277static struct da9052_regulator_info da9052_regulator_info[] = { 306static struct da9052_regulator_info da9052_regulator_info[] = {
@@ -389,8 +418,9 @@ static int da9052_regulator_probe(struct platform_device *pdev)
389#endif 418#endif
390 } 419 }
391 420
392 regulator->rdev = regulator_register(&regulator->info->reg_desc, 421 regulator->rdev = devm_regulator_register(&pdev->dev,
393 &config); 422 &regulator->info->reg_desc,
423 &config);
394 if (IS_ERR(regulator->rdev)) { 424 if (IS_ERR(regulator->rdev)) {
395 dev_err(&pdev->dev, "failed to register regulator %s\n", 425 dev_err(&pdev->dev, "failed to register regulator %s\n",
396 regulator->info->reg_desc.name); 426 regulator->info->reg_desc.name);
@@ -402,17 +432,8 @@ static int da9052_regulator_probe(struct platform_device *pdev)
402 return 0; 432 return 0;
403} 433}
404 434
405static int da9052_regulator_remove(struct platform_device *pdev)
406{
407 struct da9052_regulator *regulator = platform_get_drvdata(pdev);
408
409 regulator_unregister(regulator->rdev);
410 return 0;
411}
412
413static struct platform_driver da9052_regulator_driver = { 435static struct platform_driver da9052_regulator_driver = {
414 .probe = da9052_regulator_probe, 436 .probe = da9052_regulator_probe,
415 .remove = da9052_regulator_remove,
416 .driver = { 437 .driver = {
417 .name = "da9052-regulator", 438 .name = "da9052-regulator",
418 .owner = THIS_MODULE, 439 .owner = THIS_MODULE,
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 77b53e5a231c..7f340206d329 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -564,13 +564,13 @@ static int da9055_regulator_probe(struct platform_device *pdev)
564 if (ret < 0) 564 if (ret < 0)
565 return ret; 565 return ret;
566 566
567 regulator->rdev = regulator_register(&regulator->info->reg_desc, 567 regulator->rdev = devm_regulator_register(&pdev->dev,
568 &config); 568 &regulator->info->reg_desc,
569 &config);
569 if (IS_ERR(regulator->rdev)) { 570 if (IS_ERR(regulator->rdev)) {
570 dev_err(&pdev->dev, "Failed to register regulator %s\n", 571 dev_err(&pdev->dev, "Failed to register regulator %s\n",
571 regulator->info->reg_desc.name); 572 regulator->info->reg_desc.name);
572 ret = PTR_ERR(regulator->rdev); 573 return PTR_ERR(regulator->rdev);
573 return ret;
574 } 574 }
575 575
576 /* Only LDO 5 and 6 has got the over current interrupt */ 576 /* Only LDO 5 and 6 has got the over current interrupt */
@@ -588,7 +588,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
588 dev_err(&pdev->dev, 588 dev_err(&pdev->dev,
589 "Failed to request Regulator IRQ %d: %d\n", 589 "Failed to request Regulator IRQ %d: %d\n",
590 irq, ret); 590 irq, ret);
591 goto err_regulator; 591 return ret;
592 } 592 }
593 } 593 }
594 } 594 }
@@ -596,24 +596,10 @@ static int da9055_regulator_probe(struct platform_device *pdev)
596 platform_set_drvdata(pdev, regulator); 596 platform_set_drvdata(pdev, regulator);
597 597
598 return 0; 598 return 0;
599
600err_regulator:
601 regulator_unregister(regulator->rdev);
602 return ret;
603}
604
605static int da9055_regulator_remove(struct platform_device *pdev)
606{
607 struct da9055_regulator *regulator = platform_get_drvdata(pdev);
608
609 regulator_unregister(regulator->rdev);
610
611 return 0;
612} 599}
613 600
614static struct platform_driver da9055_regulator_driver = { 601static struct platform_driver da9055_regulator_driver = {
615 .probe = da9055_regulator_probe, 602 .probe = da9055_regulator_probe,
616 .remove = da9055_regulator_remove,
617 .driver = { 603 .driver = {
618 .name = "da9055-regulator", 604 .name = "da9055-regulator",
619 .owner = THIS_MODULE, 605 .owner = THIS_MODULE,
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index b9f2653e4ef9..56727eb745df 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -717,7 +717,7 @@ static int da9063_regulator_probe(struct platform_device *pdev)
717{ 717{
718 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); 718 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
719 struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev); 719 struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev);
720 struct of_regulator_match *da9063_reg_matches; 720 struct of_regulator_match *da9063_reg_matches = NULL;
721 struct da9063_regulators_pdata *regl_pdata; 721 struct da9063_regulators_pdata *regl_pdata;
722 const struct da9063_dev_model *model; 722 const struct da9063_dev_model *model;
723 struct da9063_regulators *regulators; 723 struct da9063_regulators *regulators;
@@ -847,13 +847,13 @@ static int da9063_regulator_probe(struct platform_device *pdev)
847 if (da9063_reg_matches) 847 if (da9063_reg_matches)
848 config.of_node = da9063_reg_matches[id].of_node; 848 config.of_node = da9063_reg_matches[id].of_node;
849 config.regmap = da9063->regmap; 849 config.regmap = da9063->regmap;
850 regl->rdev = regulator_register(&regl->desc, &config); 850 regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc,
851 &config);
851 if (IS_ERR(regl->rdev)) { 852 if (IS_ERR(regl->rdev)) {
852 dev_err(&pdev->dev, 853 dev_err(&pdev->dev,
853 "Failed to register %s regulator\n", 854 "Failed to register %s regulator\n",
854 regl->desc.name); 855 regl->desc.name);
855 ret = PTR_ERR(regl->rdev); 856 return PTR_ERR(regl->rdev);
856 goto err;
857 } 857 }
858 id++; 858 id++;
859 n++; 859 n++;
@@ -862,9 +862,8 @@ static int da9063_regulator_probe(struct platform_device *pdev)
862 /* LDOs overcurrent event support */ 862 /* LDOs overcurrent event support */
863 irq = platform_get_irq_byname(pdev, "LDO_LIM"); 863 irq = platform_get_irq_byname(pdev, "LDO_LIM");
864 if (irq < 0) { 864 if (irq < 0) {
865 ret = irq;
866 dev_err(&pdev->dev, "Failed to get IRQ.\n"); 865 dev_err(&pdev->dev, "Failed to get IRQ.\n");
867 goto err; 866 return irq;
868 } 867 }
869 868
870 regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq); 869 regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq);
@@ -881,27 +880,15 @@ static int da9063_regulator_probe(struct platform_device *pdev)
881 } 880 }
882 881
883 return 0; 882 return 0;
884
885err:
886 /* Wind back regulators registeration */
887 while (--n >= 0)
888 regulator_unregister(regulators->regulator[n].rdev);
889
890 return ret;
891} 883}
892 884
893static int da9063_regulator_remove(struct platform_device *pdev) 885static int da9063_regulator_remove(struct platform_device *pdev)
894{ 886{
895 struct da9063_regulators *regulators = platform_get_drvdata(pdev); 887 struct da9063_regulators *regulators = platform_get_drvdata(pdev);
896 struct da9063_regulator *regl;
897 888
898 free_irq(regulators->irq_ldo_lim, regulators); 889 free_irq(regulators->irq_ldo_lim, regulators);
899 free_irq(regulators->irq_uvov, regulators); 890 free_irq(regulators->irq_uvov, regulators);
900 891
901 for (regl = &regulators->regulator[regulators->n_regulators - 1];
902 regl >= &regulators->regulator[0]; regl--)
903 regulator_unregister(regl->rdev);
904
905 return 0; 892 return 0;
906} 893}
907 894
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
index f0fe54b38977..6f5ecbe1132e 100644
--- a/drivers/regulator/da9210-regulator.c
+++ b/drivers/regulator/da9210-regulator.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/regulator/driver.h> 26#include <linux/regulator/driver.h>
27#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
28#include <linux/regulator/of_regulator.h>
28#include <linux/regmap.h> 29#include <linux/regmap.h>
29 30
30#include "da9210-regulator.h" 31#include "da9210-regulator.h"
@@ -126,7 +127,8 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
126 const struct i2c_device_id *id) 127 const struct i2c_device_id *id)
127{ 128{
128 struct da9210 *chip; 129 struct da9210 *chip;
129 struct da9210_pdata *pdata = i2c->dev.platform_data; 130 struct device *dev = &i2c->dev;
131 struct da9210_pdata *pdata = dev_get_platdata(dev);
130 struct regulator_dev *rdev = NULL; 132 struct regulator_dev *rdev = NULL;
131 struct regulator_config config = { }; 133 struct regulator_config config = { };
132 int error; 134 int error;
@@ -147,12 +149,13 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
147 } 149 }
148 150
149 config.dev = &i2c->dev; 151 config.dev = &i2c->dev;
150 if (pdata) 152 config.init_data = pdata ? &pdata->da9210_constraints :
151 config.init_data = &pdata->da9210_constraints; 153 of_get_regulator_init_data(dev, dev->of_node);
152 config.driver_data = chip; 154 config.driver_data = chip;
153 config.regmap = chip->regmap; 155 config.regmap = chip->regmap;
156 config.of_node = dev->of_node;
154 157
155 rdev = regulator_register(&da9210_reg, &config); 158 rdev = devm_regulator_register(&i2c->dev, &da9210_reg, &config);
156 if (IS_ERR(rdev)) { 159 if (IS_ERR(rdev)) {
157 dev_err(&i2c->dev, "Failed to register DA9210 regulator\n"); 160 dev_err(&i2c->dev, "Failed to register DA9210 regulator\n");
158 return PTR_ERR(rdev); 161 return PTR_ERR(rdev);
@@ -165,13 +168,6 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
165 return 0; 168 return 0;
166} 169}
167 170
168static int da9210_i2c_remove(struct i2c_client *i2c)
169{
170 struct da9210 *chip = i2c_get_clientdata(i2c);
171 regulator_unregister(chip->rdev);
172 return 0;
173}
174
175static const struct i2c_device_id da9210_i2c_id[] = { 171static const struct i2c_device_id da9210_i2c_id[] = {
176 {"da9210", 0}, 172 {"da9210", 0},
177 {}, 173 {},
@@ -185,7 +181,6 @@ static struct i2c_driver da9210_regulator_driver = {
185 .owner = THIS_MODULE, 181 .owner = THIS_MODULE,
186 }, 182 },
187 .probe = da9210_i2c_probe, 183 .probe = da9210_i2c_probe,
188 .remove = da9210_i2c_remove,
189 .id_table = da9210_i2c_id, 184 .id_table = da9210_i2c_id,
190}; 185};
191 186
diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
new file mode 100644
index 000000000000..f44818b838dc
--- /dev/null
+++ b/drivers/regulator/devres.c
@@ -0,0 +1,415 @@
1/*
2 * devres.c -- Voltage/Current Regulator framework devres implementation.
3 *
4 * Copyright 2013 Linaro Ltd
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/err.h>
15#include <linux/regmap.h>
16#include <linux/regulator/consumer.h>
17#include <linux/regulator/driver.h>
18#include <linux/module.h>
19
20#include "internal.h"
21
22enum {
23 NORMAL_GET,
24 EXCLUSIVE_GET,
25 OPTIONAL_GET,
26};
27
28static void devm_regulator_release(struct device *dev, void *res)
29{
30 regulator_put(*(struct regulator **)res);
31}
32
33static struct regulator *_devm_regulator_get(struct device *dev, const char *id,
34 int get_type)
35{
36 struct regulator **ptr, *regulator;
37
38 ptr = devres_alloc(devm_regulator_release, sizeof(*ptr), GFP_KERNEL);
39 if (!ptr)
40 return ERR_PTR(-ENOMEM);
41
42 switch (get_type) {
43 case NORMAL_GET:
44 regulator = regulator_get(dev, id);
45 break;
46 case EXCLUSIVE_GET:
47 regulator = regulator_get_exclusive(dev, id);
48 break;
49 case OPTIONAL_GET:
50 regulator = regulator_get_optional(dev, id);
51 break;
52 default:
53 regulator = ERR_PTR(-EINVAL);
54 }
55
56 if (!IS_ERR(regulator)) {
57 *ptr = regulator;
58 devres_add(dev, ptr);
59 } else {
60 devres_free(ptr);
61 }
62
63 return regulator;
64}
65
66/**
67 * devm_regulator_get - Resource managed regulator_get()
68 * @dev: device for regulator "consumer"
69 * @id: Supply name or regulator ID.
70 *
71 * Managed regulator_get(). Regulators returned from this function are
72 * automatically regulator_put() on driver detach. See regulator_get() for more
73 * information.
74 */
75struct regulator *devm_regulator_get(struct device *dev, const char *id)
76{
77 return _devm_regulator_get(dev, id, NORMAL_GET);
78}
79EXPORT_SYMBOL_GPL(devm_regulator_get);
80
81/**
82 * devm_regulator_get_exclusive - Resource managed regulator_get_exclusive()
83 * @dev: device for regulator "consumer"
84 * @id: Supply name or regulator ID.
85 *
86 * Managed regulator_get_exclusive(). Regulators returned from this function
87 * are automatically regulator_put() on driver detach. See regulator_get() for
88 * more information.
89 */
90struct regulator *devm_regulator_get_exclusive(struct device *dev,
91 const char *id)
92{
93 return _devm_regulator_get(dev, id, EXCLUSIVE_GET);
94}
95EXPORT_SYMBOL_GPL(devm_regulator_get_exclusive);
96
97/**
98 * devm_regulator_get_optional - Resource managed regulator_get_optional()
99 * @dev: device for regulator "consumer"
100 * @id: Supply name or regulator ID.
101 *
102 * Managed regulator_get_optional(). Regulators returned from this
103 * function are automatically regulator_put() on driver detach. See
104 * regulator_get_optional() for more information.
105 */
106struct regulator *devm_regulator_get_optional(struct device *dev,
107 const char *id)
108{
109 return _devm_regulator_get(dev, id, OPTIONAL_GET);
110}
111EXPORT_SYMBOL_GPL(devm_regulator_get_optional);
112
113static int devm_regulator_match(struct device *dev, void *res, void *data)
114{
115 struct regulator **r = res;
116 if (!r || !*r) {
117 WARN_ON(!r || !*r);
118 return 0;
119 }
120 return *r == data;
121}
122
123/**
124 * devm_regulator_put - Resource managed regulator_put()
125 * @regulator: regulator to free
126 *
127 * Deallocate a regulator allocated with devm_regulator_get(). Normally
128 * this function will not need to be called and the resource management
129 * code will ensure that the resource is freed.
130 */
131void devm_regulator_put(struct regulator *regulator)
132{
133 int rc;
134
135 rc = devres_release(regulator->dev, devm_regulator_release,
136 devm_regulator_match, regulator);
137 if (rc != 0)
138 WARN_ON(rc);
139}
140EXPORT_SYMBOL_GPL(devm_regulator_put);
141
142/**
143 * devm_regulator_bulk_get - managed get multiple regulator consumers
144 *
145 * @dev: Device to supply
146 * @num_consumers: Number of consumers to register
147 * @consumers: Configuration of consumers; clients are stored here.
148 *
149 * @return 0 on success, an errno on failure.
150 *
151 * This helper function allows drivers to get several regulator
152 * consumers in one operation with management, the regulators will
153 * automatically be freed when the device is unbound. If any of the
154 * regulators cannot be acquired then any regulators that were
155 * allocated will be freed before returning to the caller.
156 */
157int devm_regulator_bulk_get(struct device *dev, int num_consumers,
158 struct regulator_bulk_data *consumers)
159{
160 int i;
161 int ret;
162
163 for (i = 0; i < num_consumers; i++)
164 consumers[i].consumer = NULL;
165
166 for (i = 0; i < num_consumers; i++) {
167 consumers[i].consumer = devm_regulator_get(dev,
168 consumers[i].supply);
169 if (IS_ERR(consumers[i].consumer)) {
170 ret = PTR_ERR(consumers[i].consumer);
171 dev_err(dev, "Failed to get supply '%s': %d\n",
172 consumers[i].supply, ret);
173 consumers[i].consumer = NULL;
174 goto err;
175 }
176 }
177
178 return 0;
179
180err:
181 for (i = 0; i < num_consumers && consumers[i].consumer; i++)
182 devm_regulator_put(consumers[i].consumer);
183
184 return ret;
185}
186EXPORT_SYMBOL_GPL(devm_regulator_bulk_get);
187
188static void devm_rdev_release(struct device *dev, void *res)
189{
190 regulator_unregister(*(struct regulator_dev **)res);
191}
192
193/**
194 * devm_regulator_register - Resource managed regulator_register()
195 * @regulator_desc: regulator to register
196 * @config: runtime configuration for regulator
197 *
198 * Called by regulator drivers to register a regulator. Returns a
199 * valid pointer to struct regulator_dev on success or an ERR_PTR() on
200 * error. The regulator will automatically be released when the device
201 * is unbound.
202 */
203struct regulator_dev *devm_regulator_register(struct device *dev,
204 const struct regulator_desc *regulator_desc,
205 const struct regulator_config *config)
206{
207 struct regulator_dev **ptr, *rdev;
208
209 ptr = devres_alloc(devm_rdev_release, sizeof(*ptr),
210 GFP_KERNEL);
211 if (!ptr)
212 return ERR_PTR(-ENOMEM);
213
214 rdev = regulator_register(regulator_desc, config);
215 if (!IS_ERR(rdev)) {
216 *ptr = rdev;
217 devres_add(dev, ptr);
218 } else {
219 devres_free(ptr);
220 }
221
222 return rdev;
223}
224EXPORT_SYMBOL_GPL(devm_regulator_register);
225
226static int devm_rdev_match(struct device *dev, void *res, void *data)
227{
228 struct regulator_dev **r = res;
229 if (!r || !*r) {
230 WARN_ON(!r || !*r);
231 return 0;
232 }
233 return *r == data;
234}
235
236/**
237 * devm_regulator_unregister - Resource managed regulator_unregister()
238 * @regulator: regulator to free
239 *
240 * Unregister a regulator registered with devm_regulator_register().
241 * Normally this function will not need to be called and the resource
242 * management code will ensure that the resource is freed.
243 */
244void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev)
245{
246 int rc;
247
248 rc = devres_release(dev, devm_rdev_release, devm_rdev_match, rdev);
249 if (rc != 0)
250 WARN_ON(rc);
251}
252EXPORT_SYMBOL_GPL(devm_regulator_unregister);
253
254struct regulator_supply_alias_match {
255 struct device *dev;
256 const char *id;
257};
258
259static int devm_regulator_match_supply_alias(struct device *dev, void *res,
260 void *data)
261{
262 struct regulator_supply_alias_match *match = res;
263 struct regulator_supply_alias_match *target = data;
264
265 return match->dev == target->dev && strcmp(match->id, target->id) == 0;
266}
267
268static void devm_regulator_destroy_supply_alias(struct device *dev, void *res)
269{
270 struct regulator_supply_alias_match *match = res;
271
272 regulator_unregister_supply_alias(match->dev, match->id);
273}
274
275/**
276 * devm_regulator_register_supply_alias - Resource managed
277 * regulator_register_supply_alias()
278 *
279 * @dev: device that will be given as the regulator "consumer"
280 * @id: Supply name or regulator ID
281 * @alias_dev: device that should be used to lookup the supply
282 * @alias_id: Supply name or regulator ID that should be used to lookup the
283 * supply
284 *
285 * The supply alias will automatically be unregistered when the source
286 * device is unbound.
287 */
288int devm_regulator_register_supply_alias(struct device *dev, const char *id,
289 struct device *alias_dev,
290 const char *alias_id)
291{
292 struct regulator_supply_alias_match *match;
293 int ret;
294
295 match = devres_alloc(devm_regulator_destroy_supply_alias,
296 sizeof(struct regulator_supply_alias_match),
297 GFP_KERNEL);
298 if (!match)
299 return -ENOMEM;
300
301 match->dev = dev;
302 match->id = id;
303
304 ret = regulator_register_supply_alias(dev, id, alias_dev, alias_id);
305 if (ret < 0) {
306 devres_free(match);
307 return ret;
308 }
309
310 devres_add(dev, match);
311
312 return 0;
313}
314EXPORT_SYMBOL_GPL(devm_regulator_register_supply_alias);
315
316/**
317 * devm_regulator_unregister_supply_alias - Resource managed
318 * regulator_unregister_supply_alias()
319 *
320 * @dev: device that will be given as the regulator "consumer"
321 * @id: Supply name or regulator ID
322 *
323 * Unregister an alias registered with
324 * devm_regulator_register_supply_alias(). Normally this function
325 * will not need to be called and the resource management code
326 * will ensure that the resource is freed.
327 */
328void devm_regulator_unregister_supply_alias(struct device *dev, const char *id)
329{
330 struct regulator_supply_alias_match match;
331 int rc;
332
333 match.dev = dev;
334 match.id = id;
335
336 rc = devres_release(dev, devm_regulator_destroy_supply_alias,
337 devm_regulator_match_supply_alias, &match);
338 if (rc != 0)
339 WARN_ON(rc);
340}
341EXPORT_SYMBOL_GPL(devm_regulator_unregister_supply_alias);
342
343/**
344 * devm_regulator_bulk_register_supply_alias - Managed register
345 * multiple aliases
346 *
347 * @dev: device that will be given as the regulator "consumer"
348 * @id: List of supply names or regulator IDs
349 * @alias_dev: device that should be used to lookup the supply
350 * @alias_id: List of supply names or regulator IDs that should be used to
351 * lookup the supply
352 * @num_id: Number of aliases to register
353 *
354 * @return 0 on success, an errno on failure.
355 *
356 * This helper function allows drivers to register several supply
357 * aliases in one operation, the aliases will be automatically
358 * unregisters when the source device is unbound. If any of the
359 * aliases cannot be registered any aliases that were registered
360 * will be removed before returning to the caller.
361 */
362int devm_regulator_bulk_register_supply_alias(struct device *dev,
363 const char **id,
364 struct device *alias_dev,
365 const char **alias_id,
366 int num_id)
367{
368 int i;
369 int ret;
370
371 for (i = 0; i < num_id; ++i) {
372 ret = devm_regulator_register_supply_alias(dev, id[i],
373 alias_dev,
374 alias_id[i]);
375 if (ret < 0)
376 goto err;
377 }
378
379 return 0;
380
381err:
382 dev_err(dev,
383 "Failed to create supply alias %s,%s -> %s,%s\n",
384 id[i], dev_name(dev), alias_id[i], dev_name(alias_dev));
385
386 while (--i >= 0)
387 devm_regulator_unregister_supply_alias(dev, id[i]);
388
389 return ret;
390}
391EXPORT_SYMBOL_GPL(devm_regulator_bulk_register_supply_alias);
392
393/**
394 * devm_regulator_bulk_unregister_supply_alias - Managed unregister
395 * multiple aliases
396 *
397 * @dev: device that will be given as the regulator "consumer"
398 * @id: List of supply names or regulator IDs
399 * @num_id: Number of aliases to unregister
400 *
401 * Unregister aliases registered with
402 * devm_regulator_bulk_register_supply_alias(). Normally this function
403 * will not need to be called and the resource management code
404 * will ensure that the resource is freed.
405 */
406void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
407 const char **id,
408 int num_id)
409{
410 int i;
411
412 for (i = 0; i < num_id; ++i)
413 devm_regulator_unregister_supply_alias(dev, id[i]);
414}
415EXPORT_SYMBOL_GPL(devm_regulator_bulk_unregister_supply_alias);
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 70b7220c587f..7ca3d9e3b0fe 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -218,9 +218,8 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
218 rdesc->vsel_mask = VSEL_NSEL_MASK; 218 rdesc->vsel_mask = VSEL_NSEL_MASK;
219 rdesc->owner = THIS_MODULE; 219 rdesc->owner = THIS_MODULE;
220 220
221 di->rdev = regulator_register(&di->desc, config); 221 di->rdev = devm_regulator_register(di->dev, &di->desc, config);
222 return PTR_ERR_OR_ZERO(di->rdev); 222 return PTR_ERR_OR_ZERO(di->rdev);
223
224} 223}
225 224
226static struct regmap_config fan53555_regmap_config = { 225static struct regmap_config fan53555_regmap_config = {
@@ -291,14 +290,6 @@ static int fan53555_regulator_probe(struct i2c_client *client,
291 290
292} 291}
293 292
294static int fan53555_regulator_remove(struct i2c_client *client)
295{
296 struct fan53555_device_info *di = i2c_get_clientdata(client);
297
298 regulator_unregister(di->rdev);
299 return 0;
300}
301
302static const struct i2c_device_id fan53555_id[] = { 293static const struct i2c_device_id fan53555_id[] = {
303 {"fan53555", -1}, 294 {"fan53555", -1},
304 { }, 295 { },
@@ -309,7 +300,6 @@ static struct i2c_driver fan53555_regulator_driver = {
309 .name = "fan53555-regulator", 300 .name = "fan53555-regulator",
310 }, 301 },
311 .probe = fan53555_regulator_probe, 302 .probe = fan53555_regulator_probe,
312 .remove = fan53555_regulator_remove,
313 .id_table = fan53555_id, 303 .id_table = fan53555_id,
314}; 304};
315 305
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 7610920014d7..5ea64b94341c 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -34,7 +34,6 @@
34struct fixed_voltage_data { 34struct fixed_voltage_data {
35 struct regulator_desc desc; 35 struct regulator_desc desc;
36 struct regulator_dev *dev; 36 struct regulator_dev *dev;
37 int microvolts;
38}; 37};
39 38
40 39
@@ -108,30 +107,7 @@ of_get_fixed_voltage_config(struct device *dev)
108 return config; 107 return config;
109} 108}
110 109
111static int fixed_voltage_get_voltage(struct regulator_dev *dev)
112{
113 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
114
115 if (data->microvolts)
116 return data->microvolts;
117 else
118 return -EINVAL;
119}
120
121static int fixed_voltage_list_voltage(struct regulator_dev *dev,
122 unsigned selector)
123{
124 struct fixed_voltage_data *data = rdev_get_drvdata(dev);
125
126 if (selector != 0)
127 return -EINVAL;
128
129 return data->microvolts;
130}
131
132static struct regulator_ops fixed_voltage_ops = { 110static struct regulator_ops fixed_voltage_ops = {
133 .get_voltage = fixed_voltage_get_voltage,
134 .list_voltage = fixed_voltage_list_voltage,
135}; 111};
136 112
137static int reg_fixed_voltage_probe(struct platform_device *pdev) 113static int reg_fixed_voltage_probe(struct platform_device *pdev)
@@ -186,23 +162,21 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
186 if (config->microvolts) 162 if (config->microvolts)
187 drvdata->desc.n_voltages = 1; 163 drvdata->desc.n_voltages = 1;
188 164
189 drvdata->microvolts = config->microvolts; 165 drvdata->desc.fixed_uV = config->microvolts;
190 166
191 if (config->gpio >= 0) 167 if (config->gpio >= 0)
192 cfg.ena_gpio = config->gpio; 168 cfg.ena_gpio = config->gpio;
193 cfg.ena_gpio_invert = !config->enable_high; 169 cfg.ena_gpio_invert = !config->enable_high;
194 if (config->enabled_at_boot) { 170 if (config->enabled_at_boot) {
195 if (config->enable_high) { 171 if (config->enable_high)
196 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; 172 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
197 } else { 173 else
198 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; 174 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
199 }
200 } else { 175 } else {
201 if (config->enable_high) { 176 if (config->enable_high)
202 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; 177 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW;
203 } else { 178 else
204 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; 179 cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
205 }
206 } 180 }
207 if (config->gpio_is_open_drain) 181 if (config->gpio_is_open_drain)
208 cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN; 182 cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN;
@@ -222,7 +196,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
222 platform_set_drvdata(pdev, drvdata); 196 platform_set_drvdata(pdev, drvdata);
223 197
224 dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, 198 dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name,
225 drvdata->microvolts); 199 drvdata->desc.fixed_uV);
226 200
227 return 0; 201 return 0;
228 202
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 98a98ffa7fe0..04406a918c04 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -283,7 +283,6 @@ static int gpio_regulator_probe(struct platform_device *pdev)
283 dev_err(&pdev->dev, "No regulator type set\n"); 283 dev_err(&pdev->dev, "No regulator type set\n");
284 ret = -EINVAL; 284 ret = -EINVAL;
285 goto err_memgpio; 285 goto err_memgpio;
286 break;
287 } 286 }
288 287
289 drvdata->nr_gpios = config->nr_gpios; 288 drvdata->nr_gpios = config->nr_gpios;
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index 6e30df14714b..e221a271ba56 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -284,9 +284,13 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
284 } 284 }
285 285
286 for (i = 0; i < rdev->desc->n_linear_ranges; i++) { 286 for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
287 int linear_max_uV;
288
287 range = &rdev->desc->linear_ranges[i]; 289 range = &rdev->desc->linear_ranges[i];
290 linear_max_uV = range->min_uV +
291 (range->max_sel - range->min_sel) * range->uV_step;
288 292
289 if (!(min_uV <= range->max_uV && max_uV >= range->min_uV)) 293 if (!(min_uV <= linear_max_uV && max_uV >= range->min_uV))
290 continue; 294 continue;
291 295
292 if (min_uV <= range->min_uV) 296 if (min_uV <= range->min_uV)
diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
new file mode 100644
index 000000000000..84bbda10c396
--- /dev/null
+++ b/drivers/regulator/internal.h
@@ -0,0 +1,38 @@
1/*
2 * internal.h -- Voltage/Current Regulator framework internal code
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
6 *
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 */
15
16#ifndef __REGULATOR_INTERNAL_H
17#define __REGULATOR_INTERNAL_H
18
19/*
20 * struct regulator
21 *
22 * One for each consumer device.
23 */
24struct regulator {
25 struct device *dev;
26 struct list_head list;
27 unsigned int always_on:1;
28 unsigned int bypass:1;
29 int uA_load;
30 int min_uV;
31 int max_uV;
32 char *supply_name;
33 struct device_attribute dev_attr;
34 struct regulator_dev *rdev;
35 struct dentry *debugfs;
36};
37
38#endif
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index 88c1a3acf563..6e5da95fa025 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -112,7 +112,7 @@ static int isl6271a_probe(struct i2c_client *i2c,
112 struct regulator_config config = { }; 112 struct regulator_config config = { };
113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev); 113 struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
114 struct isl_pmic *pmic; 114 struct isl_pmic *pmic;
115 int err, i; 115 int i;
116 116
117 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 117 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
118 return -EIO; 118 return -EIO;
@@ -133,32 +133,17 @@ static int isl6271a_probe(struct i2c_client *i2c,
133 config.init_data = NULL; 133 config.init_data = NULL;
134 config.driver_data = pmic; 134 config.driver_data = pmic;
135 135
136 pmic->rdev[i] = regulator_register(&isl_rd[i], &config); 136 pmic->rdev[i] = devm_regulator_register(&i2c->dev, &isl_rd[i],
137 &config);
137 if (IS_ERR(pmic->rdev[i])) { 138 if (IS_ERR(pmic->rdev[i])) {
138 dev_err(&i2c->dev, "failed to register %s\n", id->name); 139 dev_err(&i2c->dev, "failed to register %s\n", id->name);
139 err = PTR_ERR(pmic->rdev[i]); 140 return PTR_ERR(pmic->rdev[i]);
140 goto error;
141 } 141 }
142 } 142 }
143 143
144 i2c_set_clientdata(i2c, pmic); 144 i2c_set_clientdata(i2c, pmic);
145 145
146 return 0; 146 return 0;
147
148error:
149 while (--i >= 0)
150 regulator_unregister(pmic->rdev[i]);
151 return err;
152}
153
154static int isl6271a_remove(struct i2c_client *i2c)
155{
156 struct isl_pmic *pmic = i2c_get_clientdata(i2c);
157 int i;
158
159 for (i = 0; i < 3; i++)
160 regulator_unregister(pmic->rdev[i]);
161 return 0;
162} 147}
163 148
164static const struct i2c_device_id isl6271a_id[] = { 149static const struct i2c_device_id isl6271a_id[] = {
@@ -174,7 +159,6 @@ static struct i2c_driver isl6271a_i2c_driver = {
174 .owner = THIS_MODULE, 159 .owner = THIS_MODULE,
175 }, 160 },
176 .probe = isl6271a_probe, 161 .probe = isl6271a_probe,
177 .remove = isl6271a_remove,
178 .id_table = isl6271a_id, 162 .id_table = isl6271a_id,
179}; 163};
180 164
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 5a4604ee5ea5..947c05ffe0ab 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -474,8 +474,8 @@ static int lp3971_i2c_remove(struct i2c_client *i2c)
474} 474}
475 475
476static const struct i2c_device_id lp3971_i2c_id[] = { 476static const struct i2c_device_id lp3971_i2c_id[] = {
477 { "lp3971", 0 }, 477 { "lp3971", 0 },
478 { } 478 { }
479}; 479};
480MODULE_DEVICE_TABLE(i2c, lp3971_i2c_id); 480MODULE_DEVICE_TABLE(i2c, lp3971_i2c_id);
481 481
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index 2b84b727a3c4..2e4734ff79fc 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -785,7 +785,7 @@ static int lp872x_regulator_register(struct lp872x *lp)
785 struct regulator_desc *desc; 785 struct regulator_desc *desc;
786 struct regulator_config cfg = { }; 786 struct regulator_config cfg = { };
787 struct regulator_dev *rdev; 787 struct regulator_dev *rdev;
788 int i, ret; 788 int i;
789 789
790 for (i = 0; i < lp->num_regulators; i++) { 790 for (i = 0; i < lp->num_regulators; i++) {
791 desc = (lp->chipid == LP8720) ? &lp8720_regulator_desc[i] : 791 desc = (lp->chipid == LP8720) ? &lp8720_regulator_desc[i] :
@@ -796,34 +796,16 @@ static int lp872x_regulator_register(struct lp872x *lp)
796 cfg.driver_data = lp; 796 cfg.driver_data = lp;
797 cfg.regmap = lp->regmap; 797 cfg.regmap = lp->regmap;
798 798
799 rdev = regulator_register(desc, &cfg); 799 rdev = devm_regulator_register(lp->dev, desc, &cfg);
800 if (IS_ERR(rdev)) { 800 if (IS_ERR(rdev)) {
801 dev_err(lp->dev, "regulator register err"); 801 dev_err(lp->dev, "regulator register err");
802 ret = PTR_ERR(rdev); 802 return PTR_ERR(rdev);
803 goto err;
804 } 803 }
805 804
806 *(lp->regulators + i) = rdev; 805 *(lp->regulators + i) = rdev;
807 } 806 }
808 807
809 return 0; 808 return 0;
810err:
811 while (--i >= 0) {
812 rdev = *(lp->regulators + i);
813 regulator_unregister(rdev);
814 }
815 return ret;
816}
817
818static void lp872x_regulator_unregister(struct lp872x *lp)
819{
820 struct regulator_dev *rdev;
821 int i;
822
823 for (i = 0; i < lp->num_regulators; i++) {
824 rdev = *(lp->regulators + i);
825 regulator_unregister(rdev);
826 }
827} 809}
828 810
829static const struct regmap_config lp872x_regmap_config = { 811static const struct regmap_config lp872x_regmap_config = {
@@ -979,14 +961,6 @@ err_dev:
979 return ret; 961 return ret;
980} 962}
981 963
982static int lp872x_remove(struct i2c_client *cl)
983{
984 struct lp872x *lp = i2c_get_clientdata(cl);
985
986 lp872x_regulator_unregister(lp);
987 return 0;
988}
989
990static const struct of_device_id lp872x_dt_ids[] = { 964static const struct of_device_id lp872x_dt_ids[] = {
991 { .compatible = "ti,lp8720", }, 965 { .compatible = "ti,lp8720", },
992 { .compatible = "ti,lp8725", }, 966 { .compatible = "ti,lp8725", },
@@ -1008,7 +982,6 @@ static struct i2c_driver lp872x_driver = {
1008 .of_match_table = of_match_ptr(lp872x_dt_ids), 982 .of_match_table = of_match_ptr(lp872x_dt_ids),
1009 }, 983 },
1010 .probe = lp872x_probe, 984 .probe = lp872x_probe,
1011 .remove = lp872x_remove,
1012 .id_table = lp872x_ids, 985 .id_table = lp872x_ids,
1013}; 986};
1014 987
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
index 0b015f2a7fd9..948afc249e29 100644
--- a/drivers/regulator/lp8788-buck.c
+++ b/drivers/regulator/lp8788-buck.c
@@ -515,7 +515,7 @@ static int lp8788_buck_probe(struct platform_device *pdev)
515 cfg.driver_data = buck; 515 cfg.driver_data = buck;
516 cfg.regmap = lp->regmap; 516 cfg.regmap = lp->regmap;
517 517
518 rdev = regulator_register(&lp8788_buck_desc[id], &cfg); 518 rdev = devm_regulator_register(&pdev->dev, &lp8788_buck_desc[id], &cfg);
519 if (IS_ERR(rdev)) { 519 if (IS_ERR(rdev)) {
520 ret = PTR_ERR(rdev); 520 ret = PTR_ERR(rdev);
521 dev_err(&pdev->dev, "BUCK%d regulator register err = %d\n", 521 dev_err(&pdev->dev, "BUCK%d regulator register err = %d\n",
@@ -529,18 +529,8 @@ static int lp8788_buck_probe(struct platform_device *pdev)
529 return 0; 529 return 0;
530} 530}
531 531
532static int lp8788_buck_remove(struct platform_device *pdev)
533{
534 struct lp8788_buck *buck = platform_get_drvdata(pdev);
535
536 regulator_unregister(buck->regulator);
537
538 return 0;
539}
540
541static struct platform_driver lp8788_buck_driver = { 532static struct platform_driver lp8788_buck_driver = {
542 .probe = lp8788_buck_probe, 533 .probe = lp8788_buck_probe,
543 .remove = lp8788_buck_remove,
544 .driver = { 534 .driver = {
545 .name = LP8788_DEV_BUCK, 535 .name = LP8788_DEV_BUCK,
546 .owner = THIS_MODULE, 536 .owner = THIS_MODULE,
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c
index 0527d87c6dd5..b9a29a29933f 100644
--- a/drivers/regulator/lp8788-ldo.c
+++ b/drivers/regulator/lp8788-ldo.c
@@ -543,7 +543,7 @@ static int lp8788_dldo_probe(struct platform_device *pdev)
543 cfg.driver_data = ldo; 543 cfg.driver_data = ldo;
544 cfg.regmap = lp->regmap; 544 cfg.regmap = lp->regmap;
545 545
546 rdev = regulator_register(&lp8788_dldo_desc[id], &cfg); 546 rdev = devm_regulator_register(&pdev->dev, &lp8788_dldo_desc[id], &cfg);
547 if (IS_ERR(rdev)) { 547 if (IS_ERR(rdev)) {
548 ret = PTR_ERR(rdev); 548 ret = PTR_ERR(rdev);
549 dev_err(&pdev->dev, "DLDO%d regulator register err = %d\n", 549 dev_err(&pdev->dev, "DLDO%d regulator register err = %d\n",
@@ -557,18 +557,8 @@ static int lp8788_dldo_probe(struct platform_device *pdev)
557 return 0; 557 return 0;
558} 558}
559 559
560static int lp8788_dldo_remove(struct platform_device *pdev)
561{
562 struct lp8788_ldo *ldo = platform_get_drvdata(pdev);
563
564 regulator_unregister(ldo->regulator);
565
566 return 0;
567}
568
569static struct platform_driver lp8788_dldo_driver = { 560static struct platform_driver lp8788_dldo_driver = {
570 .probe = lp8788_dldo_probe, 561 .probe = lp8788_dldo_probe,
571 .remove = lp8788_dldo_remove,
572 .driver = { 562 .driver = {
573 .name = LP8788_DEV_DLDO, 563 .name = LP8788_DEV_DLDO,
574 .owner = THIS_MODULE, 564 .owner = THIS_MODULE,
@@ -603,7 +593,7 @@ static int lp8788_aldo_probe(struct platform_device *pdev)
603 cfg.driver_data = ldo; 593 cfg.driver_data = ldo;
604 cfg.regmap = lp->regmap; 594 cfg.regmap = lp->regmap;
605 595
606 rdev = regulator_register(&lp8788_aldo_desc[id], &cfg); 596 rdev = devm_regulator_register(&pdev->dev, &lp8788_aldo_desc[id], &cfg);
607 if (IS_ERR(rdev)) { 597 if (IS_ERR(rdev)) {
608 ret = PTR_ERR(rdev); 598 ret = PTR_ERR(rdev);
609 dev_err(&pdev->dev, "ALDO%d regulator register err = %d\n", 599 dev_err(&pdev->dev, "ALDO%d regulator register err = %d\n",
@@ -617,18 +607,8 @@ static int lp8788_aldo_probe(struct platform_device *pdev)
617 return 0; 607 return 0;
618} 608}
619 609
620static int lp8788_aldo_remove(struct platform_device *pdev)
621{
622 struct lp8788_ldo *ldo = platform_get_drvdata(pdev);
623
624 regulator_unregister(ldo->regulator);
625
626 return 0;
627}
628
629static struct platform_driver lp8788_aldo_driver = { 610static struct platform_driver lp8788_aldo_driver = {
630 .probe = lp8788_aldo_probe, 611 .probe = lp8788_aldo_probe,
631 .remove = lp8788_aldo_remove,
632 .driver = { 612 .driver = {
633 .name = LP8788_DEV_ALDO, 613 .name = LP8788_DEV_ALDO,
634 .owner = THIS_MODULE, 614 .owner = THIS_MODULE,
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 3a599ee0a456..e242dd316d36 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -166,7 +166,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
166 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev); 166 struct max1586_platform_data *pdata = dev_get_platdata(&client->dev);
167 struct regulator_config config = { }; 167 struct regulator_config config = { };
168 struct max1586_data *max1586; 168 struct max1586_data *max1586;
169 int i, id, ret = -ENOMEM; 169 int i, id;
170 170
171 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) + 171 max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) +
172 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1), 172 sizeof(struct regulator_dev *) * (MAX1586_V6 + 1),
@@ -193,7 +193,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
193 continue; 193 continue;
194 if (id < MAX1586_V3 || id > MAX1586_V6) { 194 if (id < MAX1586_V3 || id > MAX1586_V6) {
195 dev_err(&client->dev, "invalid regulator id %d\n", id); 195 dev_err(&client->dev, "invalid regulator id %d\n", id);
196 goto err; 196 return -EINVAL;
197 } 197 }
198 198
199 if (id == MAX1586_V3) { 199 if (id == MAX1586_V3) {
@@ -207,33 +207,18 @@ static int max1586_pmic_probe(struct i2c_client *client,
207 config.init_data = pdata->subdevs[i].platform_data; 207 config.init_data = pdata->subdevs[i].platform_data;
208 config.driver_data = max1586; 208 config.driver_data = max1586;
209 209
210 rdev[i] = regulator_register(&max1586_reg[id], &config); 210 rdev[i] = devm_regulator_register(&client->dev,
211 &max1586_reg[id], &config);
211 if (IS_ERR(rdev[i])) { 212 if (IS_ERR(rdev[i])) {
212 ret = PTR_ERR(rdev[i]);
213 dev_err(&client->dev, "failed to register %s\n", 213 dev_err(&client->dev, "failed to register %s\n",
214 max1586_reg[id].name); 214 max1586_reg[id].name);
215 goto err; 215 return PTR_ERR(rdev[i]);
216 } 216 }
217 } 217 }
218 218
219 i2c_set_clientdata(client, max1586); 219 i2c_set_clientdata(client, max1586);
220 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n"); 220 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n");
221 return 0; 221 return 0;
222
223err:
224 while (--i >= 0)
225 regulator_unregister(rdev[i]);
226 return ret;
227}
228
229static int max1586_pmic_remove(struct i2c_client *client)
230{
231 struct max1586_data *max1586 = i2c_get_clientdata(client);
232 int i;
233
234 for (i = 0; i <= MAX1586_V6; i++)
235 regulator_unregister(max1586->rdev[i]);
236 return 0;
237} 222}
238 223
239static const struct i2c_device_id max1586_id[] = { 224static const struct i2c_device_id max1586_id[] = {
@@ -244,7 +229,6 @@ MODULE_DEVICE_TABLE(i2c, max1586_id);
244 229
245static struct i2c_driver max1586_pmic_driver = { 230static struct i2c_driver max1586_pmic_driver = {
246 .probe = max1586_pmic_probe, 231 .probe = max1586_pmic_probe,
247 .remove = max1586_pmic_remove,
248 .driver = { 232 .driver = {
249 .name = "max1586", 233 .name = "max1586",
250 .owner = THIS_MODULE, 234 .owner = THIS_MODULE,
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index f563057e5690..ae001ccf26f4 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -478,32 +478,16 @@ static int max77686_pmic_probe(struct platform_device *pdev)
478 config.of_node = pdata->regulators[i].of_node; 478 config.of_node = pdata->regulators[i].of_node;
479 479
480 max77686->opmode[i] = regulators[i].enable_mask; 480 max77686->opmode[i] = regulators[i].enable_mask;
481 max77686->rdev[i] = regulator_register(&regulators[i], &config); 481 max77686->rdev[i] = devm_regulator_register(&pdev->dev,
482 &regulators[i], &config);
482 if (IS_ERR(max77686->rdev[i])) { 483 if (IS_ERR(max77686->rdev[i])) {
483 ret = PTR_ERR(max77686->rdev[i]);
484 dev_err(&pdev->dev, 484 dev_err(&pdev->dev,
485 "regulator init failed for %d\n", i); 485 "regulator init failed for %d\n", i);
486 max77686->rdev[i] = NULL; 486 return PTR_ERR(max77686->rdev[i]);
487 goto err;
488 } 487 }
489 } 488 }
490 489
491 return 0; 490 return 0;
492err:
493 while (--i >= 0)
494 regulator_unregister(max77686->rdev[i]);
495 return ret;
496}
497
498static int max77686_pmic_remove(struct platform_device *pdev)
499{
500 struct max77686_data *max77686 = platform_get_drvdata(pdev);
501 int i;
502
503 for (i = 0; i < MAX77686_REGULATORS; i++)
504 regulator_unregister(max77686->rdev[i]);
505
506 return 0;
507} 491}
508 492
509static const struct platform_device_id max77686_pmic_id[] = { 493static const struct platform_device_id max77686_pmic_id[] = {
@@ -518,7 +502,6 @@ static struct platform_driver max77686_pmic_driver = {
518 .owner = THIS_MODULE, 502 .owner = THIS_MODULE,
519 }, 503 },
520 .probe = max77686_pmic_probe, 504 .probe = max77686_pmic_probe,
521 .remove = max77686_pmic_remove,
522 .id_table = max77686_pmic_id, 505 .id_table = max77686_pmic_id,
523}; 506};
524 507
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index ce4b96c15eba..feb20bf4ccab 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -230,7 +230,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
230 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); 230 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
231 struct max77693_pmic_dev *max77693_pmic; 231 struct max77693_pmic_dev *max77693_pmic;
232 struct max77693_regulator_data *rdata = NULL; 232 struct max77693_regulator_data *rdata = NULL;
233 int num_rdata, i, ret; 233 int num_rdata, i;
234 struct regulator_config config; 234 struct regulator_config config;
235 235
236 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata); 236 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata);
@@ -266,36 +266,16 @@ static int max77693_pmic_probe(struct platform_device *pdev)
266 config.init_data = rdata[i].initdata; 266 config.init_data = rdata[i].initdata;
267 config.of_node = rdata[i].of_node; 267 config.of_node = rdata[i].of_node;
268 268
269 max77693_pmic->rdev[i] = regulator_register(&regulators[id], 269 max77693_pmic->rdev[i] = devm_regulator_register(&pdev->dev,
270 &config); 270 &regulators[id], &config);
271 if (IS_ERR(max77693_pmic->rdev[i])) { 271 if (IS_ERR(max77693_pmic->rdev[i])) {
272 ret = PTR_ERR(max77693_pmic->rdev[i]);
273 dev_err(max77693_pmic->dev, 272 dev_err(max77693_pmic->dev,
274 "Failed to initialize regulator-%d\n", id); 273 "Failed to initialize regulator-%d\n", id);
275 max77693_pmic->rdev[i] = NULL; 274 return PTR_ERR(max77693_pmic->rdev[i]);
276 goto err;
277 } 275 }
278 } 276 }
279 277
280 return 0; 278 return 0;
281 err:
282 while (--i >= 0)
283 regulator_unregister(max77693_pmic->rdev[i]);
284
285 return ret;
286}
287
288static int max77693_pmic_remove(struct platform_device *pdev)
289{
290 struct max77693_pmic_dev *max77693_pmic = platform_get_drvdata(pdev);
291 struct regulator_dev **rdev = max77693_pmic->rdev;
292 int i;
293
294 for (i = 0; i < max77693_pmic->num_regulators; i++)
295 if (rdev[i])
296 regulator_unregister(rdev[i]);
297
298 return 0;
299} 279}
300 280
301static const struct platform_device_id max77693_pmic_id[] = { 281static const struct platform_device_id max77693_pmic_id[] = {
@@ -311,7 +291,6 @@ static struct platform_driver max77693_pmic_driver = {
311 .owner = THIS_MODULE, 291 .owner = THIS_MODULE,
312 }, 292 },
313 .probe = max77693_pmic_probe, 293 .probe = max77693_pmic_probe,
314 .remove = max77693_pmic_remove,
315 .id_table = max77693_pmic_id, 294 .id_table = max77693_pmic_id,
316}; 295};
317 296
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 19c6f08eafd5..7f049c92ee52 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -234,7 +234,8 @@ static int max8649_regulator_probe(struct i2c_client *client,
234 config.driver_data = info; 234 config.driver_data = info;
235 config.regmap = info->regmap; 235 config.regmap = info->regmap;
236 236
237 info->regulator = regulator_register(&dcdc_desc, &config); 237 info->regulator = devm_regulator_register(&client->dev, &dcdc_desc,
238 &config);
238 if (IS_ERR(info->regulator)) { 239 if (IS_ERR(info->regulator)) {
239 dev_err(info->dev, "failed to register regulator %s\n", 240 dev_err(info->dev, "failed to register regulator %s\n",
240 dcdc_desc.name); 241 dcdc_desc.name);
@@ -244,16 +245,6 @@ static int max8649_regulator_probe(struct i2c_client *client,
244 return 0; 245 return 0;
245} 246}
246 247
247static int max8649_regulator_remove(struct i2c_client *client)
248{
249 struct max8649_regulator_info *info = i2c_get_clientdata(client);
250
251 if (info)
252 regulator_unregister(info->regulator);
253
254 return 0;
255}
256
257static const struct i2c_device_id max8649_id[] = { 248static const struct i2c_device_id max8649_id[] = {
258 { "max8649", 0 }, 249 { "max8649", 0 },
259 { } 250 { }
@@ -262,7 +253,6 @@ MODULE_DEVICE_TABLE(i2c, max8649_id);
262 253
263static struct i2c_driver max8649_driver = { 254static struct i2c_driver max8649_driver = {
264 .probe = max8649_regulator_probe, 255 .probe = max8649_regulator_probe,
265 .remove = max8649_regulator_remove,
266 .driver = { 256 .driver = {
267 .name = "max8649", 257 .name = "max8649",
268 }, 258 },
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index 144bcacd734d..8d94d3d7f97f 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -439,7 +439,7 @@ static int max8660_probe(struct i2c_client *client,
439 for (i = 0; i < pdata->num_subdevs; i++) { 439 for (i = 0; i < pdata->num_subdevs; i++) {
440 440
441 if (!pdata->subdevs[i].platform_data) 441 if (!pdata->subdevs[i].platform_data)
442 goto err_out; 442 return ret;
443 443
444 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on; 444 boot_on = pdata->subdevs[i].platform_data->constraints.boot_on;
445 445
@@ -465,7 +465,7 @@ static int max8660_probe(struct i2c_client *client,
465 case MAX8660_V7: 465 case MAX8660_V7:
466 if (type == MAX8661) { 466 if (type == MAX8661) {
467 dev_err(dev, "Regulator not on this chip!\n"); 467 dev_err(dev, "Regulator not on this chip!\n");
468 goto err_out; 468 return -EINVAL;
469 } 469 }
470 470
471 if (boot_on) 471 if (boot_on)
@@ -475,7 +475,7 @@ static int max8660_probe(struct i2c_client *client,
475 default: 475 default:
476 dev_err(dev, "invalid regulator %s\n", 476 dev_err(dev, "invalid regulator %s\n",
477 pdata->subdevs[i].name); 477 pdata->subdevs[i].name);
478 goto err_out; 478 return ret;
479 } 479 }
480 } 480 }
481 481
@@ -489,33 +489,18 @@ static int max8660_probe(struct i2c_client *client,
489 config.of_node = of_node[i]; 489 config.of_node = of_node[i];
490 config.driver_data = max8660; 490 config.driver_data = max8660;
491 491
492 rdev[i] = regulator_register(&max8660_reg[id], &config); 492 rdev[i] = devm_regulator_register(&client->dev,
493 &max8660_reg[id], &config);
493 if (IS_ERR(rdev[i])) { 494 if (IS_ERR(rdev[i])) {
494 ret = PTR_ERR(rdev[i]); 495 ret = PTR_ERR(rdev[i]);
495 dev_err(dev, "failed to register %s\n", 496 dev_err(&client->dev, "failed to register %s\n",
496 max8660_reg[id].name); 497 max8660_reg[id].name);
497 goto err_unregister; 498 return PTR_ERR(rdev[i]);
498 } 499 }
499 } 500 }
500 501
501 i2c_set_clientdata(client, max8660); 502 i2c_set_clientdata(client, max8660);
502 return 0; 503 return 0;
503
504err_unregister:
505 while (--i >= 0)
506 regulator_unregister(rdev[i]);
507err_out:
508 return ret;
509}
510
511static int max8660_remove(struct i2c_client *client)
512{
513 struct max8660 *max8660 = i2c_get_clientdata(client);
514 int i;
515
516 for (i = 0; i < MAX8660_V_END; i++)
517 regulator_unregister(max8660->rdev[i]);
518 return 0;
519} 504}
520 505
521static const struct i2c_device_id max8660_id[] = { 506static const struct i2c_device_id max8660_id[] = {
@@ -527,7 +512,6 @@ MODULE_DEVICE_TABLE(i2c, max8660_id);
527 512
528static struct i2c_driver max8660_driver = { 513static struct i2c_driver max8660_driver = {
529 .probe = max8660_probe, 514 .probe = max8660_probe,
530 .remove = max8660_remove,
531 .driver = { 515 .driver = {
532 .name = "max8660", 516 .name = "max8660",
533 .owner = THIS_MODULE, 517 .owner = THIS_MODULE,
diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
index 4568c15fa78d..0c5fe6c6ac26 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -350,33 +350,17 @@ static int max8907_regulator_probe(struct platform_device *pdev)
350 pmic->desc[i].ops = &max8907_out5v_hwctl_ops; 350 pmic->desc[i].ops = &max8907_out5v_hwctl_ops;
351 } 351 }
352 352
353 pmic->rdev[i] = regulator_register(&pmic->desc[i], &config); 353 pmic->rdev[i] = devm_regulator_register(&pdev->dev,
354 &pmic->desc[i], &config);
354 if (IS_ERR(pmic->rdev[i])) { 355 if (IS_ERR(pmic->rdev[i])) {
355 dev_err(&pdev->dev, 356 dev_err(&pdev->dev,
356 "failed to register %s regulator\n", 357 "failed to register %s regulator\n",
357 pmic->desc[i].name); 358 pmic->desc[i].name);
358 ret = PTR_ERR(pmic->rdev[i]); 359 return PTR_ERR(pmic->rdev[i]);
359 goto err_unregister_regulator;
360 } 360 }
361 } 361 }
362 362
363 return 0; 363 return 0;
364
365err_unregister_regulator:
366 while (--i >= 0)
367 regulator_unregister(pmic->rdev[i]);
368 return ret;
369}
370
371static int max8907_regulator_remove(struct platform_device *pdev)
372{
373 struct max8907_regulator *pmic = platform_get_drvdata(pdev);
374 int i;
375
376 for (i = 0; i < MAX8907_NUM_REGULATORS; i++)
377 regulator_unregister(pmic->rdev[i]);
378
379 return 0;
380} 364}
381 365
382static struct platform_driver max8907_regulator_driver = { 366static struct platform_driver max8907_regulator_driver = {
@@ -385,7 +369,6 @@ static struct platform_driver max8907_regulator_driver = {
385 .owner = THIS_MODULE, 369 .owner = THIS_MODULE,
386 }, 370 },
387 .probe = max8907_regulator_probe, 371 .probe = max8907_regulator_probe,
388 .remove = max8907_regulator_remove,
389}; 372};
390 373
391static int __init max8907_regulator_init(void) 374static int __init max8907_regulator_init(void)
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index d80b5fa758ae..759510789e71 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -312,7 +312,7 @@ static int max8925_regulator_probe(struct platform_device *pdev)
312 if (pdata) 312 if (pdata)
313 config.init_data = pdata; 313 config.init_data = pdata;
314 314
315 rdev = regulator_register(&ri->desc, &config); 315 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
316 if (IS_ERR(rdev)) { 316 if (IS_ERR(rdev)) {
317 dev_err(&pdev->dev, "failed to register regulator %s\n", 317 dev_err(&pdev->dev, "failed to register regulator %s\n",
318 ri->desc.name); 318 ri->desc.name);
@@ -323,22 +323,12 @@ static int max8925_regulator_probe(struct platform_device *pdev)
323 return 0; 323 return 0;
324} 324}
325 325
326static int max8925_regulator_remove(struct platform_device *pdev)
327{
328 struct regulator_dev *rdev = platform_get_drvdata(pdev);
329
330 regulator_unregister(rdev);
331
332 return 0;
333}
334
335static struct platform_driver max8925_regulator_driver = { 326static struct platform_driver max8925_regulator_driver = {
336 .driver = { 327 .driver = {
337 .name = "max8925-regulator", 328 .name = "max8925-regulator",
338 .owner = THIS_MODULE, 329 .owner = THIS_MODULE,
339 }, 330 },
340 .probe = max8925_regulator_probe, 331 .probe = max8925_regulator_probe,
341 .remove = max8925_regulator_remove,
342}; 332};
343 333
344static int __init max8925_regulator_init(void) 334static int __init max8925_regulator_init(void)
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index 5b77ab7762e4..892aa1e5b96c 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -467,7 +467,7 @@ static int max8973_probe(struct i2c_client *client,
467 config.regmap = max->regmap; 467 config.regmap = max->regmap;
468 468
469 /* Register the regulators */ 469 /* Register the regulators */
470 rdev = regulator_register(&max->desc, &config); 470 rdev = devm_regulator_register(&client->dev, &max->desc, &config);
471 if (IS_ERR(rdev)) { 471 if (IS_ERR(rdev)) {
472 ret = PTR_ERR(rdev); 472 ret = PTR_ERR(rdev);
473 dev_err(max->dev, "regulator register failed, err %d\n", ret); 473 dev_err(max->dev, "regulator register failed, err %d\n", ret);
@@ -478,14 +478,6 @@ static int max8973_probe(struct i2c_client *client,
478 return 0; 478 return 0;
479} 479}
480 480
481static int max8973_remove(struct i2c_client *client)
482{
483 struct max8973_chip *max = i2c_get_clientdata(client);
484
485 regulator_unregister(max->rdev);
486 return 0;
487}
488
489static const struct i2c_device_id max8973_id[] = { 481static const struct i2c_device_id max8973_id[] = {
490 {.name = "max8973",}, 482 {.name = "max8973",},
491 {}, 483 {},
@@ -499,7 +491,6 @@ static struct i2c_driver max8973_i2c_driver = {
499 .owner = THIS_MODULE, 491 .owner = THIS_MODULE,
500 }, 492 },
501 .probe = max8973_probe, 493 .probe = max8973_probe,
502 .remove = max8973_remove,
503 .id_table = max8973_id, 494 .id_table = max8973_id,
504}; 495};
505 496
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index df20069f0537..2d618fc9c1af 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -690,8 +690,9 @@ static int max8997_set_voltage_buck(struct regulator_dev *rdev,
690 if (max8997->ignore_gpiodvs_side_effect == false) 690 if (max8997->ignore_gpiodvs_side_effect == false)
691 return -EINVAL; 691 return -EINVAL;
692 692
693 dev_warn(&rdev->dev, "MAX8997 GPIO-DVS Side Effect Warning: GPIO SET:" 693 dev_warn(&rdev->dev,
694 " %d -> %d\n", max8997->buck125_gpioindex, tmp_idx); 694 "MAX8997 GPIO-DVS Side Effect Warning: GPIO SET: %d -> %d\n",
695 max8997->buck125_gpioindex, tmp_idx);
695 696
696out: 697out:
697 if (new_idx < 0 || new_val < 0) 698 if (new_idx < 0 || new_val < 0)
@@ -1081,7 +1082,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1081 pdata->buck1_voltage[i] + 1082 pdata->buck1_voltage[i] +
1082 buck1245_voltage_map_desc.step); 1083 buck1245_voltage_map_desc.step);
1083 if (ret < 0) 1084 if (ret < 0)
1084 goto err_out; 1085 return ret;
1085 1086
1086 max8997->buck2_vol[i] = ret = 1087 max8997->buck2_vol[i] = ret =
1087 max8997_get_voltage_proper_val( 1088 max8997_get_voltage_proper_val(
@@ -1090,7 +1091,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1090 pdata->buck2_voltage[i] + 1091 pdata->buck2_voltage[i] +
1091 buck1245_voltage_map_desc.step); 1092 buck1245_voltage_map_desc.step);
1092 if (ret < 0) 1093 if (ret < 0)
1093 goto err_out; 1094 return ret;
1094 1095
1095 max8997->buck5_vol[i] = ret = 1096 max8997->buck5_vol[i] = ret =
1096 max8997_get_voltage_proper_val( 1097 max8997_get_voltage_proper_val(
@@ -1099,7 +1100,7 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1099 pdata->buck5_voltage[i] + 1100 pdata->buck5_voltage[i] +
1100 buck1245_voltage_map_desc.step); 1101 buck1245_voltage_map_desc.step);
1101 if (ret < 0) 1102 if (ret < 0)
1102 goto err_out; 1103 return ret;
1103 1104
1104 if (max_buck1 < max8997->buck1_vol[i]) 1105 if (max_buck1 < max8997->buck1_vol[i])
1105 max_buck1 = max8997->buck1_vol[i]; 1106 max_buck1 = max8997->buck1_vol[i];
@@ -1143,24 +1144,23 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1143 !gpio_is_valid(pdata->buck125_gpios[1]) || 1144 !gpio_is_valid(pdata->buck125_gpios[1]) ||
1144 !gpio_is_valid(pdata->buck125_gpios[2])) { 1145 !gpio_is_valid(pdata->buck125_gpios[2])) {
1145 dev_err(&pdev->dev, "GPIO NOT VALID\n"); 1146 dev_err(&pdev->dev, "GPIO NOT VALID\n");
1146 ret = -EINVAL; 1147 return -EINVAL;
1147 goto err_out;
1148 } 1148 }
1149 1149
1150 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], 1150 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0],
1151 "MAX8997 SET1"); 1151 "MAX8997 SET1");
1152 if (ret) 1152 if (ret)
1153 goto err_out; 1153 return ret;
1154 1154
1155 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], 1155 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1],
1156 "MAX8997 SET2"); 1156 "MAX8997 SET2");
1157 if (ret) 1157 if (ret)
1158 goto err_out; 1158 return ret;
1159 1159
1160 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], 1160 ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2],
1161 "MAX8997 SET3"); 1161 "MAX8997 SET3");
1162 if (ret) 1162 if (ret)
1163 goto err_out; 1163 return ret;
1164 1164
1165 gpio_direction_output(pdata->buck125_gpios[0], 1165 gpio_direction_output(pdata->buck125_gpios[0],
1166 (max8997->buck125_gpioindex >> 2) 1166 (max8997->buck125_gpioindex >> 2)
@@ -1205,33 +1205,16 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1205 config.driver_data = max8997; 1205 config.driver_data = max8997;
1206 config.of_node = pdata->regulators[i].reg_node; 1206 config.of_node = pdata->regulators[i].reg_node;
1207 1207
1208 rdev[i] = regulator_register(&regulators[id], &config); 1208 rdev[i] = devm_regulator_register(&pdev->dev, &regulators[id],
1209 &config);
1209 if (IS_ERR(rdev[i])) { 1210 if (IS_ERR(rdev[i])) {
1210 ret = PTR_ERR(rdev[i]);
1211 dev_err(max8997->dev, "regulator init failed for %d\n", 1211 dev_err(max8997->dev, "regulator init failed for %d\n",
1212 id); 1212 id);
1213 rdev[i] = NULL; 1213 return PTR_ERR(rdev[i]);
1214 goto err;
1215 } 1214 }
1216 } 1215 }
1217 1216
1218 return 0; 1217 return 0;
1219err:
1220 while (--i >= 0)
1221 regulator_unregister(rdev[i]);
1222err_out:
1223 return ret;
1224}
1225
1226static int max8997_pmic_remove(struct platform_device *pdev)
1227{
1228 struct max8997_data *max8997 = platform_get_drvdata(pdev);
1229 struct regulator_dev **rdev = max8997->rdev;
1230 int i;
1231
1232 for (i = 0; i < max8997->num_regulators; i++)
1233 regulator_unregister(rdev[i]);
1234 return 0;
1235} 1218}
1236 1219
1237static const struct platform_device_id max8997_pmic_id[] = { 1220static const struct platform_device_id max8997_pmic_id[] = {
@@ -1246,7 +1229,6 @@ static struct platform_driver max8997_pmic_driver = {
1246 .owner = THIS_MODULE, 1229 .owner = THIS_MODULE,
1247 }, 1230 },
1248 .probe = max8997_pmic_probe, 1231 .probe = max8997_pmic_probe,
1249 .remove = max8997_pmic_remove,
1250 .id_table = max8997_pmic_id, 1232 .id_table = max8997_pmic_id,
1251}; 1233};
1252 1234
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index a4c53b2d1aaf..ae3f0656feb0 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -790,16 +790,14 @@ static int max8998_pmic_probe(struct platform_device *pdev)
790 dev_err(&pdev->dev, 790 dev_err(&pdev->dev,
791 "MAX8998 SET1 GPIO defined as 0 !\n"); 791 "MAX8998 SET1 GPIO defined as 0 !\n");
792 WARN_ON(!pdata->buck1_set1); 792 WARN_ON(!pdata->buck1_set1);
793 ret = -EIO; 793 return -EIO;
794 goto err_out;
795 } 794 }
796 /* Check if SET2 is not equal to 0 */ 795 /* Check if SET2 is not equal to 0 */
797 if (!pdata->buck1_set2) { 796 if (!pdata->buck1_set2) {
798 dev_err(&pdev->dev, 797 dev_err(&pdev->dev,
799 "MAX8998 SET2 GPIO defined as 0 !\n"); 798 "MAX8998 SET2 GPIO defined as 0 !\n");
800 WARN_ON(!pdata->buck1_set2); 799 WARN_ON(!pdata->buck1_set2);
801 ret = -EIO; 800 return -EIO;
802 goto err_out;
803 } 801 }
804 802
805 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); 803 gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1");
@@ -823,7 +821,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
823 ret = max8998_write_reg(i2c, 821 ret = max8998_write_reg(i2c,
824 MAX8998_REG_BUCK1_VOLTAGE1 + v, i); 822 MAX8998_REG_BUCK1_VOLTAGE1 + v, i);
825 if (ret) 823 if (ret)
826 goto err_out; 824 return ret;
827 } 825 }
828 } 826 }
829 827
@@ -833,8 +831,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
833 dev_err(&pdev->dev, 831 dev_err(&pdev->dev,
834 "MAX8998 SET3 GPIO defined as 0 !\n"); 832 "MAX8998 SET3 GPIO defined as 0 !\n");
835 WARN_ON(!pdata->buck2_set3); 833 WARN_ON(!pdata->buck2_set3);
836 ret = -EIO; 834 return -EIO;
837 goto err_out;
838 } 835 }
839 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); 836 gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3");
840 gpio_direction_output(pdata->buck2_set3, 837 gpio_direction_output(pdata->buck2_set3,
@@ -852,7 +849,7 @@ static int max8998_pmic_probe(struct platform_device *pdev)
852 ret = max8998_write_reg(i2c, 849 ret = max8998_write_reg(i2c,
853 MAX8998_REG_BUCK2_VOLTAGE1 + v, i); 850 MAX8998_REG_BUCK2_VOLTAGE1 + v, i);
854 if (ret) 851 if (ret)
855 goto err_out; 852 return ret;
856 } 853 }
857 } 854 }
858 855
@@ -875,34 +872,19 @@ static int max8998_pmic_probe(struct platform_device *pdev)
875 config.init_data = pdata->regulators[i].initdata; 872 config.init_data = pdata->regulators[i].initdata;
876 config.driver_data = max8998; 873 config.driver_data = max8998;
877 874
878 rdev[i] = regulator_register(&regulators[index], &config); 875 rdev[i] = devm_regulator_register(&pdev->dev,
876 &regulators[index], &config);
879 if (IS_ERR(rdev[i])) { 877 if (IS_ERR(rdev[i])) {
880 ret = PTR_ERR(rdev[i]); 878 ret = PTR_ERR(rdev[i]);
881 dev_err(max8998->dev, "regulator %s init failed (%d)\n", 879 dev_err(max8998->dev, "regulator %s init failed (%d)\n",
882 regulators[index].name, ret); 880 regulators[index].name, ret);
883 rdev[i] = NULL; 881 rdev[i] = NULL;
884 goto err; 882 return ret;
885 } 883 }
886 } 884 }
887 885
888 886
889 return 0; 887 return 0;
890err:
891 while (--i >= 0)
892 regulator_unregister(rdev[i]);
893err_out:
894 return ret;
895}
896
897static int max8998_pmic_remove(struct platform_device *pdev)
898{
899 struct max8998_data *max8998 = platform_get_drvdata(pdev);
900 struct regulator_dev **rdev = max8998->rdev;
901 int i;
902
903 for (i = 0; i < max8998->num_regulators; i++)
904 regulator_unregister(rdev[i]);
905 return 0;
906} 888}
907 889
908static const struct platform_device_id max8998_pmic_id[] = { 890static const struct platform_device_id max8998_pmic_id[] = {
@@ -918,7 +900,6 @@ static struct platform_driver max8998_pmic_driver = {
918 .owner = THIS_MODULE, 900 .owner = THIS_MODULE,
919 }, 901 },
920 .probe = max8998_pmic_probe, 902 .probe = max8998_pmic_probe,
921 .remove = max8998_pmic_remove,
922 .id_table = max8998_pmic_id, 903 .id_table = max8998_pmic_id,
923}; 904};
924 905
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 5ff99d2703db..7f4a67edf780 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -258,34 +258,34 @@ static struct mc13xxx_regulator mc13783_regulators[] = {
258 258
259 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), 259 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val),
260 MC13783_FIXED_DEFINE(REG, VIOHI, REGULATORMODE0, mc13783_viohi_val), 260 MC13783_FIXED_DEFINE(REG, VIOHI, REGULATORMODE0, mc13783_viohi_val),
261 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ 261 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0,
262 mc13783_violo_val), 262 mc13783_violo_val),
263 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ 263 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0,
264 mc13783_vdig_val), 264 mc13783_vdig_val),
265 MC13783_DEFINE_REGU(VGEN, REGULATORMODE0, REGULATORSETTING0, \ 265 MC13783_DEFINE_REGU(VGEN, REGULATORMODE0, REGULATORSETTING0,
266 mc13783_vgen_val), 266 mc13783_vgen_val),
267 MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0, REGULATORSETTING0, \ 267 MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0, REGULATORSETTING0,
268 mc13783_vrfdig_val), 268 mc13783_vrfdig_val),
269 MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0, REGULATORSETTING0, \ 269 MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0, REGULATORSETTING0,
270 mc13783_vrfref_val), 270 mc13783_vrfref_val),
271 MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0, REGULATORSETTING0, \ 271 MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0, REGULATORSETTING0,
272 mc13783_vrfcp_val), 272 mc13783_vrfcp_val),
273 MC13783_DEFINE_REGU(VSIM, REGULATORMODE1, REGULATORSETTING0, \ 273 MC13783_DEFINE_REGU(VSIM, REGULATORMODE1, REGULATORSETTING0,
274 mc13783_vsim_val), 274 mc13783_vsim_val),
275 MC13783_DEFINE_REGU(VESIM, REGULATORMODE1, REGULATORSETTING0, \ 275 MC13783_DEFINE_REGU(VESIM, REGULATORMODE1, REGULATORSETTING0,
276 mc13783_vesim_val), 276 mc13783_vesim_val),
277 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ 277 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0,
278 mc13783_vcam_val), 278 mc13783_vcam_val),
279 MC13783_FIXED_DEFINE(REG, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), 279 MC13783_FIXED_DEFINE(REG, VRFBG, REGULATORMODE1, mc13783_vrfbg_val),
280 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ 280 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1,
281 mc13783_vvib_val), 281 mc13783_vvib_val),
282 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ 282 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1,
283 mc13783_vrf_val), 283 mc13783_vrf_val),
284 MC13783_DEFINE_REGU(VRF2, REGULATORMODE1, REGULATORSETTING1, \ 284 MC13783_DEFINE_REGU(VRF2, REGULATORMODE1, REGULATORSETTING1,
285 mc13783_vrf_val), 285 mc13783_vrf_val),
286 MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1, REGULATORSETTING1, \ 286 MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1, REGULATORSETTING1,
287 mc13783_vmmc_val), 287 mc13783_vmmc_val),
288 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ 288 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1,
289 mc13783_vmmc_val), 289 mc13783_vmmc_val),
290 MC13783_GPO_DEFINE(REG, GPO1, POWERMISC, mc13783_gpo_val), 290 MC13783_GPO_DEFINE(REG, GPO1, POWERMISC, mc13783_gpo_val),
291 MC13783_GPO_DEFINE(REG, GPO2, POWERMISC, mc13783_gpo_val), 291 MC13783_GPO_DEFINE(REG, GPO2, POWERMISC, mc13783_gpo_val),
@@ -400,7 +400,7 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
400 dev_get_platdata(&pdev->dev); 400 dev_get_platdata(&pdev->dev);
401 struct mc13xxx_regulator_init_data *mc13xxx_data; 401 struct mc13xxx_regulator_init_data *mc13xxx_data;
402 struct regulator_config config = { }; 402 struct regulator_config config = { };
403 int i, ret, num_regulators; 403 int i, num_regulators;
404 404
405 num_regulators = mc13xxx_get_num_regulators_dt(pdev); 405 num_regulators = mc13xxx_get_num_regulators_dt(pdev);
406 406
@@ -444,32 +444,16 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
444 config.driver_data = priv; 444 config.driver_data = priv;
445 config.of_node = node; 445 config.of_node = node;
446 446
447 priv->regulators[i] = regulator_register(desc, &config); 447 priv->regulators[i] = devm_regulator_register(&pdev->dev, desc,
448 &config);
448 if (IS_ERR(priv->regulators[i])) { 449 if (IS_ERR(priv->regulators[i])) {
449 dev_err(&pdev->dev, "failed to register regulator %s\n", 450 dev_err(&pdev->dev, "failed to register regulator %s\n",
450 mc13783_regulators[i].desc.name); 451 mc13783_regulators[i].desc.name);
451 ret = PTR_ERR(priv->regulators[i]); 452 return PTR_ERR(priv->regulators[i]);
452 goto err;
453 } 453 }
454 } 454 }
455 455
456 return 0; 456 return 0;
457err:
458 while (--i >= 0)
459 regulator_unregister(priv->regulators[i]);
460
461 return ret;
462}
463
464static int mc13783_regulator_remove(struct platform_device *pdev)
465{
466 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
467 int i;
468
469 for (i = 0; i < priv->num_regulators; i++)
470 regulator_unregister(priv->regulators[i]);
471
472 return 0;
473} 457}
474 458
475static struct platform_driver mc13783_regulator_driver = { 459static struct platform_driver mc13783_regulator_driver = {
@@ -477,7 +461,6 @@ static struct platform_driver mc13783_regulator_driver = {
477 .name = "mc13783-regulator", 461 .name = "mc13783-regulator",
478 .owner = THIS_MODULE, 462 .owner = THIS_MODULE,
479 }, 463 },
480 .remove = mc13783_regulator_remove,
481 .probe = mc13783_regulator_probe, 464 .probe = mc13783_regulator_probe,
482}; 465};
483 466
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index 1037e07937cf..96c9f80d9550 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -611,43 +611,27 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
611 config.driver_data = priv; 611 config.driver_data = priv;
612 config.of_node = node; 612 config.of_node = node;
613 613
614 priv->regulators[i] = regulator_register(desc, &config); 614 priv->regulators[i] = devm_regulator_register(&pdev->dev, desc,
615 &config);
615 if (IS_ERR(priv->regulators[i])) { 616 if (IS_ERR(priv->regulators[i])) {
616 dev_err(&pdev->dev, "failed to register regulator %s\n", 617 dev_err(&pdev->dev, "failed to register regulator %s\n",
617 mc13892_regulators[i].desc.name); 618 mc13892_regulators[i].desc.name);
618 ret = PTR_ERR(priv->regulators[i]); 619 return PTR_ERR(priv->regulators[i]);
619 goto err;
620 } 620 }
621 } 621 }
622 622
623 return 0; 623 return 0;
624err:
625 while (--i >= 0)
626 regulator_unregister(priv->regulators[i]);
627 return ret;
628 624
629err_unlock: 625err_unlock:
630 mc13xxx_unlock(mc13892); 626 mc13xxx_unlock(mc13892);
631 return ret; 627 return ret;
632} 628}
633 629
634static int mc13892_regulator_remove(struct platform_device *pdev)
635{
636 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
637 int i;
638
639 for (i = 0; i < priv->num_regulators; i++)
640 regulator_unregister(priv->regulators[i]);
641
642 return 0;
643}
644
645static struct platform_driver mc13892_regulator_driver = { 630static struct platform_driver mc13892_regulator_driver = {
646 .driver = { 631 .driver = {
647 .name = "mc13892-regulator", 632 .name = "mc13892-regulator",
648 .owner = THIS_MODULE, 633 .owner = THIS_MODULE,
649 }, 634 },
650 .remove = mc13892_regulator_remove,
651 .probe = mc13892_regulator_probe, 635 .probe = mc13892_regulator_probe,
652}; 636};
653 637
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 7827384680d6..ea4f36f2cbe2 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -23,6 +23,8 @@ static void of_get_regulation_constraints(struct device_node *np,
23 const __be32 *min_uA, *max_uA, *ramp_delay; 23 const __be32 *min_uA, *max_uA, *ramp_delay;
24 struct property *prop; 24 struct property *prop;
25 struct regulation_constraints *constraints = &(*init_data)->constraints; 25 struct regulation_constraints *constraints = &(*init_data)->constraints;
26 int ret;
27 u32 pval;
26 28
27 constraints->name = of_get_property(np, "regulator-name", NULL); 29 constraints->name = of_get_property(np, "regulator-name", NULL);
28 30
@@ -73,6 +75,10 @@ static void of_get_regulation_constraints(struct device_node *np,
73 else 75 else
74 constraints->ramp_disable = true; 76 constraints->ramp_disable = true;
75 } 77 }
78
79 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval);
80 if (!ret)
81 constraints->enable_time = pval;
76} 82}
77 83
78/** 84/**
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 7e2b165972e6..9c62b1d34685 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -33,6 +33,7 @@ struct regs_info {
33 u8 vsel_addr; 33 u8 vsel_addr;
34 u8 ctrl_addr; 34 u8 ctrl_addr;
35 u8 tstep_addr; 35 u8 tstep_addr;
36 int sleep_id;
36}; 37};
37 38
38static const struct regs_info palmas_regs_info[] = { 39static const struct regs_info palmas_regs_info[] = {
@@ -42,6 +43,7 @@ static const struct regs_info palmas_regs_info[] = {
42 .vsel_addr = PALMAS_SMPS12_VOLTAGE, 43 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
43 .ctrl_addr = PALMAS_SMPS12_CTRL, 44 .ctrl_addr = PALMAS_SMPS12_CTRL,
44 .tstep_addr = PALMAS_SMPS12_TSTEP, 45 .tstep_addr = PALMAS_SMPS12_TSTEP,
46 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
45 }, 47 },
46 { 48 {
47 .name = "SMPS123", 49 .name = "SMPS123",
@@ -49,12 +51,14 @@ static const struct regs_info palmas_regs_info[] = {
49 .vsel_addr = PALMAS_SMPS12_VOLTAGE, 51 .vsel_addr = PALMAS_SMPS12_VOLTAGE,
50 .ctrl_addr = PALMAS_SMPS12_CTRL, 52 .ctrl_addr = PALMAS_SMPS12_CTRL,
51 .tstep_addr = PALMAS_SMPS12_TSTEP, 53 .tstep_addr = PALMAS_SMPS12_TSTEP,
54 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12,
52 }, 55 },
53 { 56 {
54 .name = "SMPS3", 57 .name = "SMPS3",
55 .sname = "smps3-in", 58 .sname = "smps3-in",
56 .vsel_addr = PALMAS_SMPS3_VOLTAGE, 59 .vsel_addr = PALMAS_SMPS3_VOLTAGE,
57 .ctrl_addr = PALMAS_SMPS3_CTRL, 60 .ctrl_addr = PALMAS_SMPS3_CTRL,
61 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS3,
58 }, 62 },
59 { 63 {
60 .name = "SMPS45", 64 .name = "SMPS45",
@@ -62,6 +66,7 @@ static const struct regs_info palmas_regs_info[] = {
62 .vsel_addr = PALMAS_SMPS45_VOLTAGE, 66 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
63 .ctrl_addr = PALMAS_SMPS45_CTRL, 67 .ctrl_addr = PALMAS_SMPS45_CTRL,
64 .tstep_addr = PALMAS_SMPS45_TSTEP, 68 .tstep_addr = PALMAS_SMPS45_TSTEP,
69 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
65 }, 70 },
66 { 71 {
67 .name = "SMPS457", 72 .name = "SMPS457",
@@ -69,6 +74,7 @@ static const struct regs_info palmas_regs_info[] = {
69 .vsel_addr = PALMAS_SMPS45_VOLTAGE, 74 .vsel_addr = PALMAS_SMPS45_VOLTAGE,
70 .ctrl_addr = PALMAS_SMPS45_CTRL, 75 .ctrl_addr = PALMAS_SMPS45_CTRL,
71 .tstep_addr = PALMAS_SMPS45_TSTEP, 76 .tstep_addr = PALMAS_SMPS45_TSTEP,
77 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45,
72 }, 78 },
73 { 79 {
74 .name = "SMPS6", 80 .name = "SMPS6",
@@ -76,12 +82,14 @@ static const struct regs_info palmas_regs_info[] = {
76 .vsel_addr = PALMAS_SMPS6_VOLTAGE, 82 .vsel_addr = PALMAS_SMPS6_VOLTAGE,
77 .ctrl_addr = PALMAS_SMPS6_CTRL, 83 .ctrl_addr = PALMAS_SMPS6_CTRL,
78 .tstep_addr = PALMAS_SMPS6_TSTEP, 84 .tstep_addr = PALMAS_SMPS6_TSTEP,
85 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS6,
79 }, 86 },
80 { 87 {
81 .name = "SMPS7", 88 .name = "SMPS7",
82 .sname = "smps7-in", 89 .sname = "smps7-in",
83 .vsel_addr = PALMAS_SMPS7_VOLTAGE, 90 .vsel_addr = PALMAS_SMPS7_VOLTAGE,
84 .ctrl_addr = PALMAS_SMPS7_CTRL, 91 .ctrl_addr = PALMAS_SMPS7_CTRL,
92 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS7,
85 }, 93 },
86 { 94 {
87 .name = "SMPS8", 95 .name = "SMPS8",
@@ -89,108 +97,128 @@ static const struct regs_info palmas_regs_info[] = {
89 .vsel_addr = PALMAS_SMPS8_VOLTAGE, 97 .vsel_addr = PALMAS_SMPS8_VOLTAGE,
90 .ctrl_addr = PALMAS_SMPS8_CTRL, 98 .ctrl_addr = PALMAS_SMPS8_CTRL,
91 .tstep_addr = PALMAS_SMPS8_TSTEP, 99 .tstep_addr = PALMAS_SMPS8_TSTEP,
100 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS8,
92 }, 101 },
93 { 102 {
94 .name = "SMPS9", 103 .name = "SMPS9",
95 .sname = "smps9-in", 104 .sname = "smps9-in",
96 .vsel_addr = PALMAS_SMPS9_VOLTAGE, 105 .vsel_addr = PALMAS_SMPS9_VOLTAGE,
97 .ctrl_addr = PALMAS_SMPS9_CTRL, 106 .ctrl_addr = PALMAS_SMPS9_CTRL,
107 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS9,
98 }, 108 },
99 { 109 {
100 .name = "SMPS10_OUT2", 110 .name = "SMPS10_OUT2",
101 .sname = "smps10-in", 111 .sname = "smps10-in",
102 .ctrl_addr = PALMAS_SMPS10_CTRL, 112 .ctrl_addr = PALMAS_SMPS10_CTRL,
113 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
103 }, 114 },
104 { 115 {
105 .name = "SMPS10_OUT1", 116 .name = "SMPS10_OUT1",
106 .sname = "smps10-out2", 117 .sname = "smps10-out2",
107 .ctrl_addr = PALMAS_SMPS10_CTRL, 118 .ctrl_addr = PALMAS_SMPS10_CTRL,
119 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10,
108 }, 120 },
109 { 121 {
110 .name = "LDO1", 122 .name = "LDO1",
111 .sname = "ldo1-in", 123 .sname = "ldo1-in",
112 .vsel_addr = PALMAS_LDO1_VOLTAGE, 124 .vsel_addr = PALMAS_LDO1_VOLTAGE,
113 .ctrl_addr = PALMAS_LDO1_CTRL, 125 .ctrl_addr = PALMAS_LDO1_CTRL,
126 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO1,
114 }, 127 },
115 { 128 {
116 .name = "LDO2", 129 .name = "LDO2",
117 .sname = "ldo2-in", 130 .sname = "ldo2-in",
118 .vsel_addr = PALMAS_LDO2_VOLTAGE, 131 .vsel_addr = PALMAS_LDO2_VOLTAGE,
119 .ctrl_addr = PALMAS_LDO2_CTRL, 132 .ctrl_addr = PALMAS_LDO2_CTRL,
133 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO2,
120 }, 134 },
121 { 135 {
122 .name = "LDO3", 136 .name = "LDO3",
123 .sname = "ldo3-in", 137 .sname = "ldo3-in",
124 .vsel_addr = PALMAS_LDO3_VOLTAGE, 138 .vsel_addr = PALMAS_LDO3_VOLTAGE,
125 .ctrl_addr = PALMAS_LDO3_CTRL, 139 .ctrl_addr = PALMAS_LDO3_CTRL,
140 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO3,
126 }, 141 },
127 { 142 {
128 .name = "LDO4", 143 .name = "LDO4",
129 .sname = "ldo4-in", 144 .sname = "ldo4-in",
130 .vsel_addr = PALMAS_LDO4_VOLTAGE, 145 .vsel_addr = PALMAS_LDO4_VOLTAGE,
131 .ctrl_addr = PALMAS_LDO4_CTRL, 146 .ctrl_addr = PALMAS_LDO4_CTRL,
147 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO4,
132 }, 148 },
133 { 149 {
134 .name = "LDO5", 150 .name = "LDO5",
135 .sname = "ldo5-in", 151 .sname = "ldo5-in",
136 .vsel_addr = PALMAS_LDO5_VOLTAGE, 152 .vsel_addr = PALMAS_LDO5_VOLTAGE,
137 .ctrl_addr = PALMAS_LDO5_CTRL, 153 .ctrl_addr = PALMAS_LDO5_CTRL,
154 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO5,
138 }, 155 },
139 { 156 {
140 .name = "LDO6", 157 .name = "LDO6",
141 .sname = "ldo6-in", 158 .sname = "ldo6-in",
142 .vsel_addr = PALMAS_LDO6_VOLTAGE, 159 .vsel_addr = PALMAS_LDO6_VOLTAGE,
143 .ctrl_addr = PALMAS_LDO6_CTRL, 160 .ctrl_addr = PALMAS_LDO6_CTRL,
161 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO6,
144 }, 162 },
145 { 163 {
146 .name = "LDO7", 164 .name = "LDO7",
147 .sname = "ldo7-in", 165 .sname = "ldo7-in",
148 .vsel_addr = PALMAS_LDO7_VOLTAGE, 166 .vsel_addr = PALMAS_LDO7_VOLTAGE,
149 .ctrl_addr = PALMAS_LDO7_CTRL, 167 .ctrl_addr = PALMAS_LDO7_CTRL,
168 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO7,
150 }, 169 },
151 { 170 {
152 .name = "LDO8", 171 .name = "LDO8",
153 .sname = "ldo8-in", 172 .sname = "ldo8-in",
154 .vsel_addr = PALMAS_LDO8_VOLTAGE, 173 .vsel_addr = PALMAS_LDO8_VOLTAGE,
155 .ctrl_addr = PALMAS_LDO8_CTRL, 174 .ctrl_addr = PALMAS_LDO8_CTRL,
175 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO8,
156 }, 176 },
157 { 177 {
158 .name = "LDO9", 178 .name = "LDO9",
159 .sname = "ldo9-in", 179 .sname = "ldo9-in",
160 .vsel_addr = PALMAS_LDO9_VOLTAGE, 180 .vsel_addr = PALMAS_LDO9_VOLTAGE,
161 .ctrl_addr = PALMAS_LDO9_CTRL, 181 .ctrl_addr = PALMAS_LDO9_CTRL,
182 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO9,
162 }, 183 },
163 { 184 {
164 .name = "LDOLN", 185 .name = "LDOLN",
165 .sname = "ldoln-in", 186 .sname = "ldoln-in",
166 .vsel_addr = PALMAS_LDOLN_VOLTAGE, 187 .vsel_addr = PALMAS_LDOLN_VOLTAGE,
167 .ctrl_addr = PALMAS_LDOLN_CTRL, 188 .ctrl_addr = PALMAS_LDOLN_CTRL,
189 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOLN,
168 }, 190 },
169 { 191 {
170 .name = "LDOUSB", 192 .name = "LDOUSB",
171 .sname = "ldousb-in", 193 .sname = "ldousb-in",
172 .vsel_addr = PALMAS_LDOUSB_VOLTAGE, 194 .vsel_addr = PALMAS_LDOUSB_VOLTAGE,
173 .ctrl_addr = PALMAS_LDOUSB_CTRL, 195 .ctrl_addr = PALMAS_LDOUSB_CTRL,
196 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOUSB,
174 }, 197 },
175 { 198 {
176 .name = "REGEN1", 199 .name = "REGEN1",
177 .ctrl_addr = PALMAS_REGEN1_CTRL, 200 .ctrl_addr = PALMAS_REGEN1_CTRL,
201 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN1,
178 }, 202 },
179 { 203 {
180 .name = "REGEN2", 204 .name = "REGEN2",
181 .ctrl_addr = PALMAS_REGEN2_CTRL, 205 .ctrl_addr = PALMAS_REGEN2_CTRL,
206 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN2,
182 }, 207 },
183 { 208 {
184 .name = "REGEN3", 209 .name = "REGEN3",
185 .ctrl_addr = PALMAS_REGEN3_CTRL, 210 .ctrl_addr = PALMAS_REGEN3_CTRL,
211 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN3,
186 }, 212 },
187 { 213 {
188 .name = "SYSEN1", 214 .name = "SYSEN1",
189 .ctrl_addr = PALMAS_SYSEN1_CTRL, 215 .ctrl_addr = PALMAS_SYSEN1_CTRL,
216 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN1,
190 }, 217 },
191 { 218 {
192 .name = "SYSEN2", 219 .name = "SYSEN2",
193 .ctrl_addr = PALMAS_SYSEN2_CTRL, 220 .ctrl_addr = PALMAS_SYSEN2_CTRL,
221 .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN2,
194 }, 222 },
195}; 223};
196 224
@@ -478,6 +506,17 @@ static struct regulator_ops palmas_ops_smps = {
478 .set_ramp_delay = palmas_smps_set_ramp_delay, 506 .set_ramp_delay = palmas_smps_set_ramp_delay,
479}; 507};
480 508
509static struct regulator_ops palmas_ops_ext_control_smps = {
510 .set_mode = palmas_set_mode_smps,
511 .get_mode = palmas_get_mode_smps,
512 .get_voltage_sel = regulator_get_voltage_sel_regmap,
513 .set_voltage_sel = regulator_set_voltage_sel_regmap,
514 .list_voltage = palmas_list_voltage_smps,
515 .map_voltage = palmas_map_voltage_smps,
516 .set_voltage_time_sel = palma_smps_set_voltage_smps_time_sel,
517 .set_ramp_delay = palmas_smps_set_ramp_delay,
518};
519
481static struct regulator_ops palmas_ops_smps10 = { 520static struct regulator_ops palmas_ops_smps10 = {
482 .is_enabled = regulator_is_enabled_regmap, 521 .is_enabled = regulator_is_enabled_regmap,
483 .enable = regulator_enable_regmap, 522 .enable = regulator_enable_regmap,
@@ -513,12 +552,37 @@ static struct regulator_ops palmas_ops_ldo = {
513 .map_voltage = regulator_map_voltage_linear, 552 .map_voltage = regulator_map_voltage_linear,
514}; 553};
515 554
555static struct regulator_ops palmas_ops_ext_control_ldo = {
556 .get_voltage_sel = regulator_get_voltage_sel_regmap,
557 .set_voltage_sel = regulator_set_voltage_sel_regmap,
558 .list_voltage = regulator_list_voltage_linear,
559 .map_voltage = regulator_map_voltage_linear,
560};
561
516static struct regulator_ops palmas_ops_extreg = { 562static struct regulator_ops palmas_ops_extreg = {
517 .is_enabled = regulator_is_enabled_regmap, 563 .is_enabled = regulator_is_enabled_regmap,
518 .enable = regulator_enable_regmap, 564 .enable = regulator_enable_regmap,
519 .disable = regulator_disable_regmap, 565 .disable = regulator_disable_regmap,
520}; 566};
521 567
568static struct regulator_ops palmas_ops_ext_control_extreg = {
569};
570
571static int palmas_regulator_config_external(struct palmas *palmas, int id,
572 struct palmas_reg_init *reg_init)
573{
574 int sleep_id = palmas_regs_info[id].sleep_id;
575 int ret;
576
577 ret = palmas_ext_control_req_config(palmas, sleep_id,
578 reg_init->roof_floor, true);
579 if (ret < 0)
580 dev_err(palmas->dev,
581 "Ext control config for regulator %d failed %d\n",
582 id, ret);
583 return ret;
584}
585
522/* 586/*
523 * setup the hardware based sleep configuration of the SMPS/LDO regulators 587 * setup the hardware based sleep configuration of the SMPS/LDO regulators
524 * from the platform data. This is different to the software based control 588 * from the platform data. This is different to the software based control
@@ -577,7 +641,22 @@ static int palmas_smps_init(struct palmas *palmas, int id,
577 return ret; 641 return ret;
578 } 642 }
579 643
644 if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) &&
645 (id != PALMAS_REG_SMPS10_OUT2)) {
646 /* Enable externally controlled regulator */
647 addr = palmas_regs_info[id].ctrl_addr;
648 ret = palmas_smps_read(palmas, addr, &reg);
649 if (ret < 0)
650 return ret;
580 651
652 if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) {
653 reg |= SMPS_CTRL_MODE_ON;
654 ret = palmas_smps_write(palmas, addr, reg);
655 if (ret < 0)
656 return ret;
657 }
658 return palmas_regulator_config_external(palmas, id, reg_init);
659 }
581 return 0; 660 return 0;
582} 661}
583 662
@@ -608,6 +687,20 @@ static int palmas_ldo_init(struct palmas *palmas, int id,
608 if (ret) 687 if (ret)
609 return ret; 688 return ret;
610 689
690 if (reg_init->roof_floor) {
691 /* Enable externally controlled regulator */
692 addr = palmas_regs_info[id].ctrl_addr;
693 ret = palmas_update_bits(palmas, PALMAS_LDO_BASE,
694 addr, PALMAS_LDO1_CTRL_MODE_ACTIVE,
695 PALMAS_LDO1_CTRL_MODE_ACTIVE);
696 if (ret < 0) {
697 dev_err(palmas->dev,
698 "LDO Register 0x%02x update failed %d\n",
699 addr, ret);
700 return ret;
701 }
702 return palmas_regulator_config_external(palmas, id, reg_init);
703 }
611 return 0; 704 return 0;
612} 705}
613 706
@@ -630,6 +723,21 @@ static int palmas_extreg_init(struct palmas *palmas, int id,
630 addr, ret); 723 addr, ret);
631 return ret; 724 return ret;
632 } 725 }
726
727 if (reg_init->roof_floor) {
728 /* Enable externally controlled regulator */
729 addr = palmas_regs_info[id].ctrl_addr;
730 ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE,
731 addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE,
732 PALMAS_REGEN1_CTRL_MODE_ACTIVE);
733 if (ret < 0) {
734 dev_err(palmas->dev,
735 "Resource Register 0x%02x update failed %d\n",
736 addr, ret);
737 return ret;
738 }
739 return palmas_regulator_config_external(palmas, id, reg_init);
740 }
633 return 0; 741 return 0;
634} 742}
635 743
@@ -712,7 +820,7 @@ static void palmas_dt_to_pdata(struct device *dev,
712 int idx, ret; 820 int idx, ret;
713 821
714 node = of_node_get(node); 822 node = of_node_get(node);
715 regulators = of_find_node_by_name(node, "regulators"); 823 regulators = of_get_child_by_name(node, "regulators");
716 if (!regulators) { 824 if (!regulators) {
717 dev_info(dev, "regulator node not found\n"); 825 dev_info(dev, "regulator node not found\n");
718 return; 826 return;
@@ -740,9 +848,35 @@ static void palmas_dt_to_pdata(struct device *dev,
740 of_property_read_bool(palmas_matches[idx].of_node, 848 of_property_read_bool(palmas_matches[idx].of_node,
741 "ti,warm-reset"); 849 "ti,warm-reset");
742 850
743 pdata->reg_init[idx]->roof_floor = 851 ret = of_property_read_u32(palmas_matches[idx].of_node,
744 of_property_read_bool(palmas_matches[idx].of_node, 852 "ti,roof-floor", &prop);
745 "ti,roof-floor"); 853 /* EINVAL: Property not found */
854 if (ret != -EINVAL) {
855 int econtrol;
856
857 /* use default value, when no value is specified */
858 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
859 if (!ret) {
860 switch (prop) {
861 case 1:
862 econtrol = PALMAS_EXT_CONTROL_ENABLE1;
863 break;
864 case 2:
865 econtrol = PALMAS_EXT_CONTROL_ENABLE2;
866 break;
867 case 3:
868 econtrol = PALMAS_EXT_CONTROL_NSLEEP;
869 break;
870 default:
871 WARN_ON(1);
872 dev_warn(dev,
873 "%s: Invalid roof-floor option: %u\n",
874 palmas_matches[idx].name, prop);
875 break;
876 }
877 }
878 pdata->reg_init[idx]->roof_floor = econtrol;
879 }
746 880
747 ret = of_property_read_u32(palmas_matches[idx].of_node, 881 ret = of_property_read_u32(palmas_matches[idx].of_node,
748 "ti,mode-sleep", &prop); 882 "ti,mode-sleep", &prop);
@@ -856,7 +990,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
856 if (ret < 0) { 990 if (ret < 0) {
857 dev_err(&pdev->dev, 991 dev_err(&pdev->dev,
858 "reading TSTEP reg failed: %d\n", ret); 992 "reading TSTEP reg failed: %d\n", ret);
859 goto err_unregister_regulator; 993 return ret;
860 } 994 }
861 pmic->desc[id].ramp_delay = 995 pmic->desc[id].ramp_delay =
862 palmas_smps_ramp_delay[reg & 0x3]; 996 palmas_smps_ramp_delay[reg & 0x3];
@@ -868,7 +1002,9 @@ static int palmas_regulators_probe(struct platform_device *pdev)
868 reg_init = pdata->reg_init[id]; 1002 reg_init = pdata->reg_init[id];
869 ret = palmas_smps_init(palmas, id, reg_init); 1003 ret = palmas_smps_init(palmas, id, reg_init);
870 if (ret) 1004 if (ret)
871 goto err_unregister_regulator; 1005 return ret;
1006 } else {
1007 reg_init = NULL;
872 } 1008 }
873 1009
874 /* Register the regulators */ 1010 /* Register the regulators */
@@ -909,11 +1045,15 @@ static int palmas_regulators_probe(struct platform_device *pdev)
909 1045
910 ret = palmas_smps_read(pmic->palmas, addr, &reg); 1046 ret = palmas_smps_read(pmic->palmas, addr, &reg);
911 if (ret) 1047 if (ret)
912 goto err_unregister_regulator; 1048 return ret;
913 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) 1049 if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
914 pmic->range[id] = 1; 1050 pmic->range[id] = 1;
915 1051
916 pmic->desc[id].ops = &palmas_ops_smps; 1052 if (reg_init && reg_init->roof_floor)
1053 pmic->desc[id].ops =
1054 &palmas_ops_ext_control_smps;
1055 else
1056 pmic->desc[id].ops = &palmas_ops_smps;
917 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; 1057 pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
918 pmic->desc[id].vsel_reg = 1058 pmic->desc[id].vsel_reg =
919 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, 1059 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
@@ -925,7 +1065,7 @@ static int palmas_regulators_probe(struct platform_device *pdev)
925 addr = palmas_regs_info[id].ctrl_addr; 1065 addr = palmas_regs_info[id].ctrl_addr;
926 ret = palmas_smps_read(pmic->palmas, addr, &reg); 1066 ret = palmas_smps_read(pmic->palmas, addr, &reg);
927 if (ret) 1067 if (ret)
928 goto err_unregister_regulator; 1068 return ret;
929 pmic->current_reg_mode[id] = reg & 1069 pmic->current_reg_mode[id] = reg &
930 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; 1070 PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK;
931 } 1071 }
@@ -941,13 +1081,13 @@ static int palmas_regulators_probe(struct platform_device *pdev)
941 pmic->desc[id].supply_name = palmas_regs_info[id].sname; 1081 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
942 config.of_node = palmas_matches[id].of_node; 1082 config.of_node = palmas_matches[id].of_node;
943 1083
944 rdev = regulator_register(&pmic->desc[id], &config); 1084 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
1085 &config);
945 if (IS_ERR(rdev)) { 1086 if (IS_ERR(rdev)) {
946 dev_err(&pdev->dev, 1087 dev_err(&pdev->dev,
947 "failed to register %s regulator\n", 1088 "failed to register %s regulator\n",
948 pdev->name); 1089 pdev->name);
949 ret = PTR_ERR(rdev); 1090 return PTR_ERR(rdev);
950 goto err_unregister_regulator;
951 } 1091 }
952 1092
953 /* Save regulator for cleanup */ 1093 /* Save regulator for cleanup */
@@ -956,6 +1096,10 @@ static int palmas_regulators_probe(struct platform_device *pdev)
956 1096
957 /* Start this loop from the id left from previous loop */ 1097 /* Start this loop from the id left from previous loop */
958 for (; id < PALMAS_NUM_REGS; id++) { 1098 for (; id < PALMAS_NUM_REGS; id++) {
1099 if (pdata && pdata->reg_init[id])
1100 reg_init = pdata->reg_init[id];
1101 else
1102 reg_init = NULL;
959 1103
960 /* Miss out regulators which are not available due 1104 /* Miss out regulators which are not available due
961 * to alternate functions. 1105 * to alternate functions.
@@ -969,7 +1113,11 @@ static int palmas_regulators_probe(struct platform_device *pdev)
969 1113
970 if (id < PALMAS_REG_REGEN1) { 1114 if (id < PALMAS_REG_REGEN1) {
971 pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES; 1115 pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES;
972 pmic->desc[id].ops = &palmas_ops_ldo; 1116 if (reg_init && reg_init->roof_floor)
1117 pmic->desc[id].ops =
1118 &palmas_ops_ext_control_ldo;
1119 else
1120 pmic->desc[id].ops = &palmas_ops_ldo;
973 pmic->desc[id].min_uV = 900000; 1121 pmic->desc[id].min_uV = 900000;
974 pmic->desc[id].uV_step = 50000; 1122 pmic->desc[id].uV_step = 50000;
975 pmic->desc[id].linear_min_sel = 1; 1123 pmic->desc[id].linear_min_sel = 1;
@@ -999,7 +1147,11 @@ static int palmas_regulators_probe(struct platform_device *pdev)
999 pmic->desc[id].enable_time = 2000; 1147 pmic->desc[id].enable_time = 2000;
1000 } else { 1148 } else {
1001 pmic->desc[id].n_voltages = 1; 1149 pmic->desc[id].n_voltages = 1;
1002 pmic->desc[id].ops = &palmas_ops_extreg; 1150 if (reg_init && reg_init->roof_floor)
1151 pmic->desc[id].ops =
1152 &palmas_ops_ext_control_extreg;
1153 else
1154 pmic->desc[id].ops = &palmas_ops_extreg;
1003 pmic->desc[id].enable_reg = 1155 pmic->desc[id].enable_reg =
1004 PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE, 1156 PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE,
1005 palmas_regs_info[id].ctrl_addr); 1157 palmas_regs_info[id].ctrl_addr);
@@ -1015,13 +1167,13 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1015 pmic->desc[id].supply_name = palmas_regs_info[id].sname; 1167 pmic->desc[id].supply_name = palmas_regs_info[id].sname;
1016 config.of_node = palmas_matches[id].of_node; 1168 config.of_node = palmas_matches[id].of_node;
1017 1169
1018 rdev = regulator_register(&pmic->desc[id], &config); 1170 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id],
1171 &config);
1019 if (IS_ERR(rdev)) { 1172 if (IS_ERR(rdev)) {
1020 dev_err(&pdev->dev, 1173 dev_err(&pdev->dev,
1021 "failed to register %s regulator\n", 1174 "failed to register %s regulator\n",
1022 pdev->name); 1175 pdev->name);
1023 ret = PTR_ERR(rdev); 1176 return PTR_ERR(rdev);
1024 goto err_unregister_regulator;
1025 } 1177 }
1026 1178
1027 /* Save regulator for cleanup */ 1179 /* Save regulator for cleanup */
@@ -1037,31 +1189,14 @@ static int palmas_regulators_probe(struct platform_device *pdev)
1037 else 1189 else
1038 ret = palmas_extreg_init(palmas, 1190 ret = palmas_extreg_init(palmas,
1039 id, reg_init); 1191 id, reg_init);
1040 if (ret) { 1192 if (ret)
1041 regulator_unregister(pmic->rdev[id]); 1193 return ret;
1042 goto err_unregister_regulator;
1043 }
1044 } 1194 }
1045 } 1195 }
1046 } 1196 }
1047 1197
1048 1198
1049 return 0; 1199 return 0;
1050
1051err_unregister_regulator:
1052 while (--id >= 0)
1053 regulator_unregister(pmic->rdev[id]);
1054 return ret;
1055}
1056
1057static int palmas_regulators_remove(struct platform_device *pdev)
1058{
1059 struct palmas_pmic *pmic = platform_get_drvdata(pdev);
1060 int id;
1061
1062 for (id = 0; id < PALMAS_NUM_REGS; id++)
1063 regulator_unregister(pmic->rdev[id]);
1064 return 0;
1065} 1200}
1066 1201
1067static struct of_device_id of_palmas_match_tbl[] = { 1202static struct of_device_id of_palmas_match_tbl[] = {
@@ -1083,7 +1218,6 @@ static struct platform_driver palmas_driver = {
1083 .owner = THIS_MODULE, 1218 .owner = THIS_MODULE,
1084 }, 1219 },
1085 .probe = palmas_regulators_probe, 1220 .probe = palmas_regulators_probe,
1086 .remove = palmas_regulators_remove,
1087}; 1221};
1088 1222
1089static int __init palmas_init(void) 1223static int __init palmas_init(void)
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index b49eaeedea84..3727b7d0e9ac 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -246,7 +246,8 @@ static int pcap_regulator_probe(struct platform_device *pdev)
246 config.init_data = dev_get_platdata(&pdev->dev); 246 config.init_data = dev_get_platdata(&pdev->dev);
247 config.driver_data = pcap; 247 config.driver_data = pcap;
248 248
249 rdev = regulator_register(&pcap_regulators[pdev->id], &config); 249 rdev = devm_regulator_register(&pdev->dev, &pcap_regulators[pdev->id],
250 &config);
250 if (IS_ERR(rdev)) 251 if (IS_ERR(rdev))
251 return PTR_ERR(rdev); 252 return PTR_ERR(rdev);
252 253
@@ -255,22 +256,12 @@ static int pcap_regulator_probe(struct platform_device *pdev)
255 return 0; 256 return 0;
256} 257}
257 258
258static int pcap_regulator_remove(struct platform_device *pdev)
259{
260 struct regulator_dev *rdev = platform_get_drvdata(pdev);
261
262 regulator_unregister(rdev);
263
264 return 0;
265}
266
267static struct platform_driver pcap_regulator_driver = { 259static struct platform_driver pcap_regulator_driver = {
268 .driver = { 260 .driver = {
269 .name = "pcap-regulator", 261 .name = "pcap-regulator",
270 .owner = THIS_MODULE, 262 .owner = THIS_MODULE,
271 }, 263 },
272 .probe = pcap_regulator_probe, 264 .probe = pcap_regulator_probe,
273 .remove = pcap_regulator_remove,
274}; 265};
275 266
276static int __init pcap_regulator_init(void) 267static int __init pcap_regulator_init(void)
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index 0f3576d48abf..d7da1c15a6da 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -90,7 +90,8 @@ static int pcf50633_regulator_probe(struct platform_device *pdev)
90 config.driver_data = pcf; 90 config.driver_data = pcf;
91 config.regmap = pcf->regmap; 91 config.regmap = pcf->regmap;
92 92
93 rdev = regulator_register(&regulators[pdev->id], &config); 93 rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id],
94 &config);
94 if (IS_ERR(rdev)) 95 if (IS_ERR(rdev))
95 return PTR_ERR(rdev); 96 return PTR_ERR(rdev);
96 97
@@ -102,21 +103,11 @@ static int pcf50633_regulator_probe(struct platform_device *pdev)
102 return 0; 103 return 0;
103} 104}
104 105
105static int pcf50633_regulator_remove(struct platform_device *pdev)
106{
107 struct regulator_dev *rdev = platform_get_drvdata(pdev);
108
109 regulator_unregister(rdev);
110
111 return 0;
112}
113
114static struct platform_driver pcf50633_regulator_driver = { 106static struct platform_driver pcf50633_regulator_driver = {
115 .driver = { 107 .driver = {
116 .name = "pcf50633-regltr", 108 .name = "pcf50633-regltr",
117 }, 109 },
118 .probe = pcf50633_regulator_probe, 110 .probe = pcf50633_regulator_probe,
119 .remove = pcf50633_regulator_remove,
120}; 111};
121 112
122static int __init pcf50633_regulator_init(void) 113static int __init pcf50633_regulator_init(void)
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c
index 5885b4504596..b58affb33143 100644
--- a/drivers/regulator/rc5t583-regulator.c
+++ b/drivers/regulator/rc5t583-regulator.c
@@ -173,33 +173,16 @@ skip_ext_pwr_config:
173 config.driver_data = reg; 173 config.driver_data = reg;
174 config.regmap = rc5t583->regmap; 174 config.regmap = rc5t583->regmap;
175 175
176 rdev = regulator_register(&ri->desc, &config); 176 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
177 if (IS_ERR(rdev)) { 177 if (IS_ERR(rdev)) {
178 dev_err(&pdev->dev, "Failed to register regulator %s\n", 178 dev_err(&pdev->dev, "Failed to register regulator %s\n",
179 ri->desc.name); 179 ri->desc.name);
180 ret = PTR_ERR(rdev); 180 return PTR_ERR(rdev);
181 goto clean_exit;
182 } 181 }
183 reg->rdev = rdev; 182 reg->rdev = rdev;
184 } 183 }
185 platform_set_drvdata(pdev, regs); 184 platform_set_drvdata(pdev, regs);
186 return 0; 185 return 0;
187
188clean_exit:
189 while (--id >= 0)
190 regulator_unregister(regs[id].rdev);
191
192 return ret;
193}
194
195static int rc5t583_regulator_remove(struct platform_device *pdev)
196{
197 struct rc5t583_regulator *regs = platform_get_drvdata(pdev);
198 int id;
199
200 for (id = 0; id < RC5T583_REGULATOR_MAX; ++id)
201 regulator_unregister(regs[id].rdev);
202 return 0;
203} 186}
204 187
205static struct platform_driver rc5t583_regulator_driver = { 188static struct platform_driver rc5t583_regulator_driver = {
@@ -208,7 +191,6 @@ static struct platform_driver rc5t583_regulator_driver = {
208 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
209 }, 192 },
210 .probe = rc5t583_regulator_probe, 193 .probe = rc5t583_regulator_probe,
211 .remove = rc5t583_regulator_remove,
212}; 194};
213 195
214static int __init rc5t583_regulator_init(void) 196static int __init rc5t583_regulator_init(void)
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 5eba2ff8c0e8..333677d68d0e 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -448,33 +448,17 @@ common_reg:
448 config.of_node = rdata[i].of_node; 448 config.of_node = rdata[i].of_node;
449 } 449 }
450 450
451 s2mps11->rdev[i] = regulator_register(&regulators[i], &config); 451 s2mps11->rdev[i] = devm_regulator_register(&pdev->dev,
452 &regulators[i], &config);
452 if (IS_ERR(s2mps11->rdev[i])) { 453 if (IS_ERR(s2mps11->rdev[i])) {
453 ret = PTR_ERR(s2mps11->rdev[i]); 454 ret = PTR_ERR(s2mps11->rdev[i]);
454 dev_err(&pdev->dev, "regulator init failed for %d\n", 455 dev_err(&pdev->dev, "regulator init failed for %d\n",
455 i); 456 i);
456 s2mps11->rdev[i] = NULL; 457 return ret;
457 goto err;
458 } 458 }
459 } 459 }
460 460
461 return 0; 461 return 0;
462err:
463 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
464 regulator_unregister(s2mps11->rdev[i]);
465
466 return ret;
467}
468
469static int s2mps11_pmic_remove(struct platform_device *pdev)
470{
471 struct s2mps11_info *s2mps11 = platform_get_drvdata(pdev);
472 int i;
473
474 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++)
475 regulator_unregister(s2mps11->rdev[i]);
476
477 return 0;
478} 462}
479 463
480static const struct platform_device_id s2mps11_pmic_id[] = { 464static const struct platform_device_id s2mps11_pmic_id[] = {
@@ -489,7 +473,6 @@ static struct platform_driver s2mps11_pmic_driver = {
489 .owner = THIS_MODULE, 473 .owner = THIS_MODULE,
490 }, 474 },
491 .probe = s2mps11_pmic_probe, 475 .probe = s2mps11_pmic_probe,
492 .remove = s2mps11_pmic_remove,
493 .id_table = s2mps11_pmic_id, 476 .id_table = s2mps11_pmic_id,
494}; 477};
495 478
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index c24448bc43cf..cbf91e25cf7f 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -522,7 +522,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
522 struct device_node *pmic_np, *regulators_np, *reg_np; 522 struct device_node *pmic_np, *regulators_np, *reg_np;
523 struct sec_regulator_data *rdata; 523 struct sec_regulator_data *rdata;
524 struct sec_opmode_data *rmode; 524 struct sec_opmode_data *rmode;
525 unsigned int i, dvs_voltage_nr = 1, ret; 525 unsigned int i, dvs_voltage_nr = 8, ret;
526 526
527 pmic_np = iodev->dev->of_node; 527 pmic_np = iodev->dev->of_node;
528 if (!pmic_np) { 528 if (!pmic_np) {
@@ -586,15 +586,39 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
586 rmode++; 586 rmode++;
587 } 587 }
588 588
589 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) 589 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-uses-gpio-dvs", NULL)) {
590 pdata->buck2_gpiodvs = true; 590 pdata->buck2_gpiodvs = true;
591 591
592 if (of_get_property(pmic_np, "s5m8767,pmic-buck3-uses-gpio-dvs", NULL)) 592 if (of_property_read_u32_array(pmic_np,
593 "s5m8767,pmic-buck2-dvs-voltage",
594 pdata->buck2_voltage, dvs_voltage_nr)) {
595 dev_err(iodev->dev, "buck2 voltages not specified\n");
596 return -EINVAL;
597 }
598 }
599
600 if (of_get_property(pmic_np, "s5m8767,pmic-buck3-uses-gpio-dvs", NULL)) {
593 pdata->buck3_gpiodvs = true; 601 pdata->buck3_gpiodvs = true;
594 602
595 if (of_get_property(pmic_np, "s5m8767,pmic-buck4-uses-gpio-dvs", NULL)) 603 if (of_property_read_u32_array(pmic_np,
604 "s5m8767,pmic-buck3-dvs-voltage",
605 pdata->buck3_voltage, dvs_voltage_nr)) {
606 dev_err(iodev->dev, "buck3 voltages not specified\n");
607 return -EINVAL;
608 }
609 }
610
611 if (of_get_property(pmic_np, "s5m8767,pmic-buck4-uses-gpio-dvs", NULL)) {
596 pdata->buck4_gpiodvs = true; 612 pdata->buck4_gpiodvs = true;
597 613
614 if (of_property_read_u32_array(pmic_np,
615 "s5m8767,pmic-buck4-dvs-voltage",
616 pdata->buck4_voltage, dvs_voltage_nr)) {
617 dev_err(iodev->dev, "buck4 voltages not specified\n");
618 return -EINVAL;
619 }
620 }
621
598 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || 622 if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs ||
599 pdata->buck4_gpiodvs) { 623 pdata->buck4_gpiodvs) {
600 ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np); 624 ret = s5m8767_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
@@ -612,32 +636,26 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
612 "invalid value for default dvs index, use 0\n"); 636 "invalid value for default dvs index, use 0\n");
613 } 637 }
614 } 638 }
615 dvs_voltage_nr = 8;
616 } 639 }
617 640
618 ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np); 641 ret = s5m8767_pmic_dt_parse_ds_gpio(iodev, pdata, pmic_np);
619 if (ret) 642 if (ret)
620 return -EINVAL; 643 return -EINVAL;
621 644
622 if (of_property_read_u32_array(pmic_np, 645 if (of_get_property(pmic_np, "s5m8767,pmic-buck2-ramp-enable", NULL))
623 "s5m8767,pmic-buck2-dvs-voltage", 646 pdata->buck2_ramp_enable = true;
624 pdata->buck2_voltage, dvs_voltage_nr)) {
625 dev_err(iodev->dev, "buck2 voltages not specified\n");
626 return -EINVAL;
627 }
628 647
629 if (of_property_read_u32_array(pmic_np, 648 if (of_get_property(pmic_np, "s5m8767,pmic-buck3-ramp-enable", NULL))
630 "s5m8767,pmic-buck3-dvs-voltage", 649 pdata->buck3_ramp_enable = true;
631 pdata->buck3_voltage, dvs_voltage_nr)) {
632 dev_err(iodev->dev, "buck3 voltages not specified\n");
633 return -EINVAL;
634 }
635 650
636 if (of_property_read_u32_array(pmic_np, 651 if (of_get_property(pmic_np, "s5m8767,pmic-buck4-ramp-enable", NULL))
637 "s5m8767,pmic-buck4-dvs-voltage", 652 pdata->buck4_ramp_enable = true;
638 pdata->buck4_voltage, dvs_voltage_nr)) { 653
639 dev_err(iodev->dev, "buck4 voltages not specified\n"); 654 if (pdata->buck2_ramp_enable || pdata->buck3_ramp_enable
640 return -EINVAL; 655 || pdata->buck4_ramp_enable) {
656 if (of_property_read_u32(pmic_np, "s5m8767,pmic-buck-ramp-delay",
657 &pdata->buck_ramp_delay))
658 pdata->buck_ramp_delay = 0;
641 } 659 }
642 660
643 return 0; 661 return 0;
@@ -910,34 +928,17 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
910 config.regmap = iodev->regmap; 928 config.regmap = iodev->regmap;
911 config.of_node = pdata->regulators[i].reg_node; 929 config.of_node = pdata->regulators[i].reg_node;
912 930
913 rdev[i] = regulator_register(&regulators[id], &config); 931 rdev[i] = devm_regulator_register(&pdev->dev, &regulators[id],
932 &config);
914 if (IS_ERR(rdev[i])) { 933 if (IS_ERR(rdev[i])) {
915 ret = PTR_ERR(rdev[i]); 934 ret = PTR_ERR(rdev[i]);
916 dev_err(s5m8767->dev, "regulator init failed for %d\n", 935 dev_err(s5m8767->dev, "regulator init failed for %d\n",
917 id); 936 id);
918 rdev[i] = NULL; 937 return ret;
919 goto err;
920 } 938 }
921 } 939 }
922 940
923 return 0; 941 return 0;
924err:
925 for (i = 0; i < s5m8767->num_regulators; i++)
926 regulator_unregister(rdev[i]);
927
928 return ret;
929}
930
931static int s5m8767_pmic_remove(struct platform_device *pdev)
932{
933 struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev);
934 struct regulator_dev **rdev = s5m8767->rdev;
935 int i;
936
937 for (i = 0; i < s5m8767->num_regulators; i++)
938 regulator_unregister(rdev[i]);
939
940 return 0;
941} 942}
942 943
943static const struct platform_device_id s5m8767_pmic_id[] = { 944static const struct platform_device_id s5m8767_pmic_id[] = {
@@ -952,7 +953,6 @@ static struct platform_driver s5m8767_pmic_driver = {
952 .owner = THIS_MODULE, 953 .owner = THIS_MODULE,
953 }, 954 },
954 .probe = s5m8767_pmic_probe, 955 .probe = s5m8767_pmic_probe,
955 .remove = s5m8767_pmic_remove,
956 .id_table = s5m8767_pmic_id, 956 .id_table = s5m8767_pmic_id,
957}; 957};
958 958
diff --git a/drivers/regulator/stw481x-vmmc.c b/drivers/regulator/stw481x-vmmc.c
new file mode 100644
index 000000000000..f78857bd6a15
--- /dev/null
+++ b/drivers/regulator/stw481x-vmmc.c
@@ -0,0 +1,111 @@
1/*
2 * Regulator driver for STw4810/STw4811 VMMC regulator.
3 *
4 * Copyright (C) 2013 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 *
7 * Author: Linus Walleij <linus.walleij@linaro.org>
8 *
9 * License terms: GNU General Public License (GPL) version 2
10 */
11
12#include <linux/err.h>
13#include <linux/init.h>
14#include <linux/mfd/stw481x.h>
15#include <linux/module.h>
16#include <linux/platform_device.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/of_regulator.h>
19
20static const unsigned int stw481x_vmmc_voltages[] = {
21 1800000,
22 1800000,
23 2850000,
24 3000000,
25 1850000,
26 2600000,
27 2700000,
28 3300000,
29};
30
31static struct regulator_ops stw481x_vmmc_ops = {
32 .list_voltage = regulator_list_voltage_table,
33 .enable = regulator_enable_regmap,
34 .disable = regulator_disable_regmap,
35 .is_enabled = regulator_is_enabled_regmap,
36 .get_voltage_sel = regulator_get_voltage_sel_regmap,
37 .set_voltage_sel = regulator_set_voltage_sel_regmap,
38};
39
40static struct regulator_desc vmmc_regulator = {
41 .name = "VMMC",
42 .id = 0,
43 .ops = &stw481x_vmmc_ops,
44 .type = REGULATOR_VOLTAGE,
45 .owner = THIS_MODULE,
46 .n_voltages = ARRAY_SIZE(stw481x_vmmc_voltages),
47 .volt_table = stw481x_vmmc_voltages,
48 .enable_time = 200, /* FIXME: look this up */
49 .enable_reg = STW_CONF1,
50 .enable_mask = STW_CONF1_PDN_VMMC,
51 .vsel_reg = STW_CONF1,
52 .vsel_mask = STW_CONF1_VMMC_MASK,
53};
54
55static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
56{
57 struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
58 struct regulator_config config = { };
59 int ret;
60
61 /* First disable the external VMMC if it's active */
62 ret = regmap_update_bits(stw481x->map, STW_CONF2,
63 STW_CONF2_VMMC_EXT, 0);
64 if (ret) {
65 dev_err(&pdev->dev, "could not disable external VMMC\n");
66 return ret;
67 }
68
69 /* Register VMMC regulator */
70 config.dev = &pdev->dev;
71 config.driver_data = stw481x;
72 config.regmap = stw481x->map;
73 config.of_node = pdev->dev.of_node;
74 config.init_data = of_get_regulator_init_data(&pdev->dev,
75 pdev->dev.of_node);
76
77 stw481x->vmmc_regulator = regulator_register(&vmmc_regulator, &config);
78 if (IS_ERR(stw481x->vmmc_regulator)) {
79 dev_err(&pdev->dev,
80 "error initializing STw481x VMMC regulator\n");
81 return PTR_ERR(stw481x->vmmc_regulator);
82 }
83
84 dev_info(&pdev->dev, "initialized STw481x VMMC regulator\n");
85 return 0;
86}
87
88static int stw481x_vmmc_regulator_remove(struct platform_device *pdev)
89{
90 struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
91
92 regulator_unregister(stw481x->vmmc_regulator);
93 return 0;
94}
95
96static const struct of_device_id stw481x_vmmc_match[] = {
97 { .compatible = "st,stw481x-vmmc", },
98 {},
99};
100
101static struct platform_driver stw481x_vmmc_regulator_driver = {
102 .driver = {
103 .name = "stw481x-vmmc-regulator",
104 .owner = THIS_MODULE,
105 .of_match_table = stw481x_vmmc_match,
106 },
107 .probe = stw481x_vmmc_regulator_probe,
108 .remove = stw481x_vmmc_regulator_remove,
109};
110
111module_platform_driver(stw481x_vmmc_regulator_driver);
diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c
index 20c271d49dcb..b187b6bba7ad 100644
--- a/drivers/regulator/ti-abb-regulator.c
+++ b/drivers/regulator/ti-abb-regulator.c
@@ -615,7 +615,7 @@ static int ti_abb_init_table(struct device *dev, struct ti_abb *abb,
615 pname, *volt_table, vset_mask); 615 pname, *volt_table, vset_mask);
616 continue; 616 continue;
617 } 617 }
618 info->vset = efuse_val & vset_mask >> __ffs(vset_mask); 618 info->vset = (efuse_val & vset_mask) >> __ffs(vset_mask);
619 dev_dbg(dev, "[%d]v=%d vset=%x\n", i, *volt_table, info->vset); 619 dev_dbg(dev, "[%d]v=%d vset=%x\n", i, *volt_table, info->vset);
620check_abb: 620check_abb:
621 switch (info->opp_sel) { 621 switch (info->opp_sel) {
@@ -708,39 +708,31 @@ static int ti_abb_probe(struct platform_device *pdev)
708 match = of_match_device(ti_abb_of_match, dev); 708 match = of_match_device(ti_abb_of_match, dev);
709 if (!match) { 709 if (!match) {
710 /* We do not expect this to happen */ 710 /* We do not expect this to happen */
711 ret = -ENODEV;
712 dev_err(dev, "%s: Unable to match device\n", __func__); 711 dev_err(dev, "%s: Unable to match device\n", __func__);
713 goto err; 712 return -ENODEV;
714 } 713 }
715 if (!match->data) { 714 if (!match->data) {
716 ret = -EINVAL;
717 dev_err(dev, "%s: Bad data in match\n", __func__); 715 dev_err(dev, "%s: Bad data in match\n", __func__);
718 goto err; 716 return -EINVAL;
719 } 717 }
720 718
721 abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL); 719 abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL);
722 if (!abb) { 720 if (!abb)
723 dev_err(dev, "%s: Unable to allocate ABB struct\n", __func__); 721 return -ENOMEM;
724 ret = -ENOMEM;
725 goto err;
726 }
727 abb->regs = match->data; 722 abb->regs = match->data;
728 723
729 /* Map ABB resources */ 724 /* Map ABB resources */
730 pname = "base-address"; 725 pname = "base-address";
731 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 726 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
732 abb->base = devm_ioremap_resource(dev, res); 727 abb->base = devm_ioremap_resource(dev, res);
733 if (IS_ERR(abb->base)) { 728 if (IS_ERR(abb->base))
734 ret = PTR_ERR(abb->base); 729 return PTR_ERR(abb->base);
735 goto err;
736 }
737 730
738 pname = "int-address"; 731 pname = "int-address";
739 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 732 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
740 if (!res) { 733 if (!res) {
741 dev_err(dev, "Missing '%s' IO resource\n", pname); 734 dev_err(dev, "Missing '%s' IO resource\n", pname);
742 ret = -ENODEV; 735 return -ENODEV;
743 goto err;
744 } 736 }
745 /* 737 /*
746 * We may have shared interrupt register offsets which are 738 * We may have shared interrupt register offsets which are
@@ -750,8 +742,7 @@ static int ti_abb_probe(struct platform_device *pdev)
750 resource_size(res)); 742 resource_size(res));
751 if (!abb->int_base) { 743 if (!abb->int_base) {
752 dev_err(dev, "Unable to map '%s'\n", pname); 744 dev_err(dev, "Unable to map '%s'\n", pname);
753 ret = -ENOMEM; 745 return -ENOMEM;
754 goto err;
755 } 746 }
756 747
757 /* Map Optional resources */ 748 /* Map Optional resources */
@@ -771,17 +762,19 @@ static int ti_abb_probe(struct platform_device *pdev)
771 resource_size(res)); 762 resource_size(res));
772 if (!abb->efuse_base) { 763 if (!abb->efuse_base) {
773 dev_err(dev, "Unable to map '%s'\n", pname); 764 dev_err(dev, "Unable to map '%s'\n", pname);
774 ret = -ENOMEM; 765 return -ENOMEM;
775 goto err;
776 } 766 }
777 767
778 pname = "ldo-address"; 768 pname = "ldo-address";
779 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 769 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
780 abb->ldo_base = devm_ioremap_resource(dev, res); 770 if (!res) {
781 if (IS_ERR(abb->ldo_base)) { 771 dev_dbg(dev, "Missing '%s' IO resource\n", pname);
782 ret = PTR_ERR(abb->ldo_base); 772 ret = -ENODEV;
783 goto err; 773 goto skip_opt;
784 } 774 }
775 abb->ldo_base = devm_ioremap_resource(dev, res);
776 if (IS_ERR(abb->ldo_base))
777 return PTR_ERR(abb->ldo_base);
785 778
786 /* IF ldo_base is set, the following are mandatory */ 779 /* IF ldo_base is set, the following are mandatory */
787 pname = "ti,ldovbb-override-mask"; 780 pname = "ti,ldovbb-override-mask";
@@ -790,12 +783,11 @@ static int ti_abb_probe(struct platform_device *pdev)
790 &abb->ldovbb_override_mask); 783 &abb->ldovbb_override_mask);
791 if (ret) { 784 if (ret) {
792 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 785 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
793 goto err; 786 return ret;
794 } 787 }
795 if (!abb->ldovbb_override_mask) { 788 if (!abb->ldovbb_override_mask) {
796 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 789 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
797 ret = -EINVAL; 790 return -EINVAL;
798 goto err;
799 } 791 }
800 792
801 pname = "ti,ldovbb-vset-mask"; 793 pname = "ti,ldovbb-vset-mask";
@@ -804,12 +796,11 @@ static int ti_abb_probe(struct platform_device *pdev)
804 &abb->ldovbb_vset_mask); 796 &abb->ldovbb_vset_mask);
805 if (ret) { 797 if (ret) {
806 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 798 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
807 goto err; 799 return ret;
808 } 800 }
809 if (!abb->ldovbb_vset_mask) { 801 if (!abb->ldovbb_vset_mask) {
810 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 802 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
811 ret = -EINVAL; 803 return -EINVAL;
812 goto err;
813 } 804 }
814 805
815skip_opt: 806skip_opt:
@@ -819,31 +810,29 @@ skip_opt:
819 &abb->txdone_mask); 810 &abb->txdone_mask);
820 if (ret) { 811 if (ret) {
821 dev_err(dev, "Missing '%s' (%d)\n", pname, ret); 812 dev_err(dev, "Missing '%s' (%d)\n", pname, ret);
822 goto err; 813 return ret;
823 } 814 }
824 if (!abb->txdone_mask) { 815 if (!abb->txdone_mask) {
825 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname); 816 dev_err(dev, "Invalid property:'%s' set as 0!\n", pname);
826 ret = -EINVAL; 817 return -EINVAL;
827 goto err;
828 } 818 }
829 819
830 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node); 820 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node);
831 if (!initdata) { 821 if (!initdata) {
832 ret = -ENOMEM;
833 dev_err(dev, "%s: Unable to alloc regulator init data\n", 822 dev_err(dev, "%s: Unable to alloc regulator init data\n",
834 __func__); 823 __func__);
835 goto err; 824 return -ENOMEM;
836 } 825 }
837 826
838 /* init ABB opp_sel table */ 827 /* init ABB opp_sel table */
839 ret = ti_abb_init_table(dev, abb, initdata); 828 ret = ti_abb_init_table(dev, abb, initdata);
840 if (ret) 829 if (ret)
841 goto err; 830 return ret;
842 831
843 /* init ABB timing */ 832 /* init ABB timing */
844 ret = ti_abb_init_timings(dev, abb); 833 ret = ti_abb_init_timings(dev, abb);
845 if (ret) 834 if (ret)
846 goto err; 835 return ret;
847 836
848 desc = &abb->rdesc; 837 desc = &abb->rdesc;
849 desc->name = dev_name(dev); 838 desc->name = dev_name(dev);
@@ -861,12 +850,12 @@ skip_opt:
861 config.driver_data = abb; 850 config.driver_data = abb;
862 config.of_node = pdev->dev.of_node; 851 config.of_node = pdev->dev.of_node;
863 852
864 rdev = regulator_register(desc, &config); 853 rdev = devm_regulator_register(dev, desc, &config);
865 if (IS_ERR(rdev)) { 854 if (IS_ERR(rdev)) {
866 ret = PTR_ERR(rdev); 855 ret = PTR_ERR(rdev);
867 dev_err(dev, "%s: failed to register regulator(%d)\n", 856 dev_err(dev, "%s: failed to register regulator(%d)\n",
868 __func__, ret); 857 __func__, ret);
869 goto err; 858 return ret;
870 } 859 }
871 platform_set_drvdata(pdev, rdev); 860 platform_set_drvdata(pdev, rdev);
872 861
@@ -874,31 +863,12 @@ skip_opt:
874 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->regs->setup_reg, abb->base); 863 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->regs->setup_reg, abb->base);
875 864
876 return 0; 865 return 0;
877
878err:
879 dev_err(dev, "%s: Failed to initialize(%d)\n", __func__, ret);
880 return ret;
881}
882
883/**
884 * ti_abb_remove() - cleanups
885 * @pdev: ABB platform device
886 *
887 * Return: 0
888 */
889static int ti_abb_remove(struct platform_device *pdev)
890{
891 struct regulator_dev *rdev = platform_get_drvdata(pdev);
892
893 regulator_unregister(rdev);
894 return 0;
895} 866}
896 867
897MODULE_ALIAS("platform:ti_abb"); 868MODULE_ALIAS("platform:ti_abb");
898 869
899static struct platform_driver ti_abb_driver = { 870static struct platform_driver ti_abb_driver = {
900 .probe = ti_abb_probe, 871 .probe = ti_abb_probe,
901 .remove = ti_abb_remove,
902 .driver = { 872 .driver = {
903 .name = "ti_abb", 873 .name = "ti_abb",
904 .owner = THIS_MODULE, 874 .owner = THIS_MODULE,
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c
index 9392a7ca3d2d..b0a3f0917a27 100644
--- a/drivers/regulator/tps51632-regulator.c
+++ b/drivers/regulator/tps51632-regulator.c
@@ -343,7 +343,7 @@ static int tps51632_probe(struct i2c_client *client,
343 config.regmap = tps->regmap; 343 config.regmap = tps->regmap;
344 config.of_node = client->dev.of_node; 344 config.of_node = client->dev.of_node;
345 345
346 rdev = regulator_register(&tps->desc, &config); 346 rdev = devm_regulator_register(&client->dev, &tps->desc, &config);
347 if (IS_ERR(rdev)) { 347 if (IS_ERR(rdev)) {
348 dev_err(tps->dev, "regulator register failed\n"); 348 dev_err(tps->dev, "regulator register failed\n");
349 return PTR_ERR(rdev); 349 return PTR_ERR(rdev);
@@ -353,14 +353,6 @@ static int tps51632_probe(struct i2c_client *client,
353 return 0; 353 return 0;
354} 354}
355 355
356static int tps51632_remove(struct i2c_client *client)
357{
358 struct tps51632_chip *tps = i2c_get_clientdata(client);
359
360 regulator_unregister(tps->rdev);
361 return 0;
362}
363
364static const struct i2c_device_id tps51632_id[] = { 356static const struct i2c_device_id tps51632_id[] = {
365 {.name = "tps51632",}, 357 {.name = "tps51632",},
366 {}, 358 {},
@@ -375,7 +367,6 @@ static struct i2c_driver tps51632_i2c_driver = {
375 .of_match_table = of_match_ptr(tps51632_of_match), 367 .of_match_table = of_match_ptr(tps51632_of_match),
376 }, 368 },
377 .probe = tps51632_probe, 369 .probe = tps51632_probe,
378 .remove = tps51632_remove,
379 .id_table = tps51632_id, 370 .id_table = tps51632_id,
380}; 371};
381 372
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c
index ec9453ffb77f..c1e33a3d397b 100644
--- a/drivers/regulator/tps6105x-regulator.c
+++ b/drivers/regulator/tps6105x-regulator.c
@@ -137,7 +137,7 @@ static int tps6105x_regulator_probe(struct platform_device *pdev)
137 /* This instance is not set for regulator mode so bail out */ 137 /* This instance is not set for regulator mode so bail out */
138 if (pdata->mode != TPS6105X_MODE_VOLTAGE) { 138 if (pdata->mode != TPS6105X_MODE_VOLTAGE) {
139 dev_info(&pdev->dev, 139 dev_info(&pdev->dev,
140 "chip not in voltage mode mode, exit probe \n"); 140 "chip not in voltage mode mode, exit probe\n");
141 return 0; 141 return 0;
142 } 142 }
143 143
@@ -146,8 +146,9 @@ static int tps6105x_regulator_probe(struct platform_device *pdev)
146 config.driver_data = tps6105x; 146 config.driver_data = tps6105x;
147 147
148 /* Register regulator with framework */ 148 /* Register regulator with framework */
149 tps6105x->regulator = regulator_register(&tps6105x_regulator_desc, 149 tps6105x->regulator = devm_regulator_register(&pdev->dev,
150 &config); 150 &tps6105x_regulator_desc,
151 &config);
151 if (IS_ERR(tps6105x->regulator)) { 152 if (IS_ERR(tps6105x->regulator)) {
152 ret = PTR_ERR(tps6105x->regulator); 153 ret = PTR_ERR(tps6105x->regulator);
153 dev_err(&tps6105x->client->dev, 154 dev_err(&tps6105x->client->dev,
@@ -159,20 +160,12 @@ static int tps6105x_regulator_probe(struct platform_device *pdev)
159 return 0; 160 return 0;
160} 161}
161 162
162static int tps6105x_regulator_remove(struct platform_device *pdev)
163{
164 struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
165 regulator_unregister(tps6105x->regulator);
166 return 0;
167}
168
169static struct platform_driver tps6105x_regulator_driver = { 163static struct platform_driver tps6105x_regulator_driver = {
170 .driver = { 164 .driver = {
171 .name = "tps6105x-regulator", 165 .name = "tps6105x-regulator",
172 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
173 }, 167 },
174 .probe = tps6105x_regulator_probe, 168 .probe = tps6105x_regulator_probe,
175 .remove = tps6105x_regulator_remove,
176}; 169};
177 170
178static __init int tps6105x_regulator_init(void) 171static __init int tps6105x_regulator_init(void)
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index 0b7ebb1ebf85..c2c0185a2dcd 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -476,7 +476,7 @@ static int tps62360_probe(struct i2c_client *client,
476 config.of_node = client->dev.of_node; 476 config.of_node = client->dev.of_node;
477 477
478 /* Register the regulators */ 478 /* Register the regulators */
479 rdev = regulator_register(&tps->desc, &config); 479 rdev = devm_regulator_register(&client->dev, &tps->desc, &config);
480 if (IS_ERR(rdev)) { 480 if (IS_ERR(rdev)) {
481 dev_err(tps->dev, 481 dev_err(tps->dev,
482 "%s(): regulator register failed with err %s\n", 482 "%s(): regulator register failed with err %s\n",
@@ -488,20 +488,6 @@ static int tps62360_probe(struct i2c_client *client,
488 return 0; 488 return 0;
489} 489}
490 490
491/**
492 * tps62360_remove - tps62360 driver i2c remove handler
493 * @client: i2c driver client device structure
494 *
495 * Unregister TPS driver as an i2c client device driver
496 */
497static int tps62360_remove(struct i2c_client *client)
498{
499 struct tps62360_chip *tps = i2c_get_clientdata(client);
500
501 regulator_unregister(tps->rdev);
502 return 0;
503}
504
505static void tps62360_shutdown(struct i2c_client *client) 491static void tps62360_shutdown(struct i2c_client *client)
506{ 492{
507 struct tps62360_chip *tps = i2c_get_clientdata(client); 493 struct tps62360_chip *tps = i2c_get_clientdata(client);
@@ -535,7 +521,6 @@ static struct i2c_driver tps62360_i2c_driver = {
535 .of_match_table = of_match_ptr(tps62360_of_match), 521 .of_match_table = of_match_ptr(tps62360_of_match),
536 }, 522 },
537 .probe = tps62360_probe, 523 .probe = tps62360_probe,
538 .remove = tps62360_remove,
539 .shutdown = tps62360_shutdown, 524 .shutdown = tps62360_shutdown,
540 .id_table = tps62360_id, 525 .id_table = tps62360_id,
541}; 526};
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index a15263d4bdff..3ef67a86115c 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -277,12 +277,12 @@ static int tps_65023_probe(struct i2c_client *client,
277 config.regmap = tps->regmap; 277 config.regmap = tps->regmap;
278 278
279 /* Register the regulators */ 279 /* Register the regulators */
280 rdev = regulator_register(&tps->desc[i], &config); 280 rdev = devm_regulator_register(&client->dev, &tps->desc[i],
281 &config);
281 if (IS_ERR(rdev)) { 282 if (IS_ERR(rdev)) {
282 dev_err(&client->dev, "failed to register %s\n", 283 dev_err(&client->dev, "failed to register %s\n",
283 id->name); 284 id->name);
284 error = PTR_ERR(rdev); 285 return PTR_ERR(rdev);
285 goto fail;
286 } 286 }
287 287
288 /* Save regulator for cleanup */ 288 /* Save regulator for cleanup */
@@ -293,24 +293,10 @@ static int tps_65023_probe(struct i2c_client *client,
293 293
294 /* Enable setting output voltage by I2C */ 294 /* Enable setting output voltage by I2C */
295 regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, 295 regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
296 TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); 296 TPS65023_REG_CTRL2_CORE_ADJ,
297 TPS65023_REG_CTRL2_CORE_ADJ);
297 298
298 return 0; 299 return 0;
299
300 fail:
301 while (--i >= 0)
302 regulator_unregister(tps->rdev[i]);
303 return error;
304}
305
306static int tps_65023_remove(struct i2c_client *client)
307{
308 struct tps_pmic *tps = i2c_get_clientdata(client);
309 int i;
310
311 for (i = 0; i < TPS65023_NUM_REGULATOR; i++)
312 regulator_unregister(tps->rdev[i]);
313 return 0;
314} 300}
315 301
316static const struct tps_info tps65020_regs[] = { 302static const struct tps_info tps65020_regs[] = {
@@ -430,7 +416,6 @@ static struct i2c_driver tps_65023_i2c_driver = {
430 .owner = THIS_MODULE, 416 .owner = THIS_MODULE,
431 }, 417 },
432 .probe = tps_65023_probe, 418 .probe = tps_65023_probe,
433 .remove = tps_65023_remove,
434 .id_table = tps_65023_id, 419 .id_table = tps_65023_id,
435}; 420};
436 421
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 4117ff52dba1..162a0fae20b3 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -508,13 +508,13 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
508 config.of_node = tps6507x_reg_matches[i].of_node; 508 config.of_node = tps6507x_reg_matches[i].of_node;
509 } 509 }
510 510
511 rdev = regulator_register(&tps->desc[i], &config); 511 rdev = devm_regulator_register(&pdev->dev, &tps->desc[i],
512 &config);
512 if (IS_ERR(rdev)) { 513 if (IS_ERR(rdev)) {
513 dev_err(tps6507x_dev->dev, 514 dev_err(tps6507x_dev->dev,
514 "failed to register %s regulator\n", 515 "failed to register %s regulator\n",
515 pdev->name); 516 pdev->name);
516 error = PTR_ERR(rdev); 517 return PTR_ERR(rdev);
517 goto fail;
518 } 518 }
519 519
520 /* Save regulator for cleanup */ 520 /* Save regulator for cleanup */
@@ -525,22 +525,6 @@ static int tps6507x_pmic_probe(struct platform_device *pdev)
525 platform_set_drvdata(pdev, tps6507x_dev); 525 platform_set_drvdata(pdev, tps6507x_dev);
526 526
527 return 0; 527 return 0;
528
529fail:
530 while (--i >= 0)
531 regulator_unregister(tps->rdev[i]);
532 return error;
533}
534
535static int tps6507x_pmic_remove(struct platform_device *pdev)
536{
537 struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
538 struct tps6507x_pmic *tps = tps6507x_dev->pmic;
539 int i;
540
541 for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
542 regulator_unregister(tps->rdev[i]);
543 return 0;
544} 528}
545 529
546static struct platform_driver tps6507x_pmic_driver = { 530static struct platform_driver tps6507x_pmic_driver = {
@@ -549,7 +533,6 @@ static struct platform_driver tps6507x_pmic_driver = {
549 .owner = THIS_MODULE, 533 .owner = THIS_MODULE,
550 }, 534 },
551 .probe = tps6507x_pmic_probe, 535 .probe = tps6507x_pmic_probe,
552 .remove = tps6507x_pmic_remove,
553}; 536};
554 537
555static int __init tps6507x_pmic_init(void) 538static int __init tps6507x_pmic_init(void)
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c
index c8e70451df38..676f75548f00 100644
--- a/drivers/regulator/tps65090-regulator.c
+++ b/drivers/regulator/tps65090-regulator.c
@@ -180,7 +180,7 @@ static struct tps65090_platform_data *tps65090_parse_dt_reg_data(
180 return ERR_PTR(-ENOMEM); 180 return ERR_PTR(-ENOMEM);
181 } 181 }
182 182
183 regulators = of_find_node_by_name(np, "regulators"); 183 regulators = of_get_child_by_name(np, "regulators");
184 if (!regulators) { 184 if (!regulators) {
185 dev_err(&pdev->dev, "regulator node not found\n"); 185 dev_err(&pdev->dev, "regulator node not found\n");
186 return ERR_PTR(-ENODEV); 186 return ERR_PTR(-ENODEV);
@@ -279,7 +279,7 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
279 if (ret < 0) { 279 if (ret < 0) {
280 dev_err(&pdev->dev, 280 dev_err(&pdev->dev,
281 "failed disable ext control\n"); 281 "failed disable ext control\n");
282 goto scrub; 282 return ret;
283 } 283 }
284 } 284 }
285 } 285 }
@@ -296,12 +296,11 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
296 else 296 else
297 config.of_node = NULL; 297 config.of_node = NULL;
298 298
299 rdev = regulator_register(ri->desc, &config); 299 rdev = devm_regulator_register(&pdev->dev, ri->desc, &config);
300 if (IS_ERR(rdev)) { 300 if (IS_ERR(rdev)) {
301 dev_err(&pdev->dev, "failed to register regulator %s\n", 301 dev_err(&pdev->dev, "failed to register regulator %s\n",
302 ri->desc->name); 302 ri->desc->name);
303 ret = PTR_ERR(rdev); 303 return PTR_ERR(rdev);
304 goto scrub;
305 } 304 }
306 ri->rdev = rdev; 305 ri->rdev = rdev;
307 306
@@ -309,36 +308,13 @@ static int tps65090_regulator_probe(struct platform_device *pdev)
309 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data && 308 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data &&
310 tps_pdata->enable_ext_control) { 309 tps_pdata->enable_ext_control) {
311 ret = tps65090_config_ext_control(ri, true); 310 ret = tps65090_config_ext_control(ri, true);
312 if (ret < 0) { 311 if (ret < 0)
313 /* Increment num to get unregister rdev */ 312 return ret;
314 num++;
315 goto scrub;
316 }
317 } 313 }
318 } 314 }
319 315
320 platform_set_drvdata(pdev, pmic); 316 platform_set_drvdata(pdev, pmic);
321 return 0; 317 return 0;
322
323scrub:
324 while (--num >= 0) {
325 ri = &pmic[num];
326 regulator_unregister(ri->rdev);
327 }
328 return ret;
329}
330
331static int tps65090_regulator_remove(struct platform_device *pdev)
332{
333 struct tps65090_regulator *pmic = platform_get_drvdata(pdev);
334 struct tps65090_regulator *ri;
335 int num;
336
337 for (num = 0; num < TPS65090_REGULATOR_MAX; ++num) {
338 ri = &pmic[num];
339 regulator_unregister(ri->rdev);
340 }
341 return 0;
342} 318}
343 319
344static struct platform_driver tps65090_regulator_driver = { 320static struct platform_driver tps65090_regulator_driver = {
@@ -347,7 +323,6 @@ static struct platform_driver tps65090_regulator_driver = {
347 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
348 }, 324 },
349 .probe = tps65090_regulator_probe, 325 .probe = tps65090_regulator_probe,
350 .remove = tps65090_regulator_remove,
351}; 326};
352 327
353static int __init tps65090_regulator_init(void) 328static int __init tps65090_regulator_init(void)
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 90861d68a0b0..9ea1bf26bd13 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -52,25 +52,17 @@ static const unsigned int LDO1_VSEL_table[] = {
52}; 52};
53 53
54static const struct regulator_linear_range tps65217_uv1_ranges[] = { 54static const struct regulator_linear_range tps65217_uv1_ranges[] = {
55 { .min_uV = 900000, .max_uV = 1500000, .min_sel = 0, .max_sel = 24, 55 REGULATOR_LINEAR_RANGE(900000, 0, 24, 25000),
56 .uV_step = 25000 }, 56 REGULATOR_LINEAR_RANGE(1550000, 25, 30, 50000),
57 { .min_uV = 1550000, .max_uV = 1800000, .min_sel = 25, .max_sel = 30, 57 REGULATOR_LINEAR_RANGE(1850000, 31, 52, 50000),
58 .uV_step = 50000 }, 58 REGULATOR_LINEAR_RANGE(3000000, 53, 55, 100000),
59 { .min_uV = 1850000, .max_uV = 2900000, .min_sel = 31, .max_sel = 52, 59 REGULATOR_LINEAR_RANGE(3300000, 56, 62, 0),
60 .uV_step = 50000 },
61 { .min_uV = 3000000, .max_uV = 3200000, .min_sel = 53, .max_sel = 55,
62 .uV_step = 100000 },
63 { .min_uV = 3300000, .max_uV = 3300000, .min_sel = 56, .max_sel = 62,
64 .uV_step = 0 },
65}; 60};
66 61
67static const struct regulator_linear_range tps65217_uv2_ranges[] = { 62static const struct regulator_linear_range tps65217_uv2_ranges[] = {
68 { .min_uV = 1500000, .max_uV = 1900000, .min_sel = 0, .max_sel = 8, 63 REGULATOR_LINEAR_RANGE(1500000, 0, 8, 50000),
69 .uV_step = 50000 }, 64 REGULATOR_LINEAR_RANGE(2000000, 9, 13, 100000),
70 { .min_uV = 2000000, .max_uV = 2400000, .min_sel = 9, .max_sel = 13, 65 REGULATOR_LINEAR_RANGE(2450000, 14, 31, 50000),
71 .uV_step = 100000 },
72 { .min_uV = 2450000, .max_uV = 3300000, .min_sel = 14, .max_sel = 31,
73 .uV_step = 50000 },
74}; 66};
75 67
76static int tps65217_pmic_enable(struct regulator_dev *dev) 68static int tps65217_pmic_enable(struct regulator_dev *dev)
@@ -233,7 +225,7 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
233 struct regulator_init_data *reg_data; 225 struct regulator_init_data *reg_data;
234 struct regulator_dev *rdev; 226 struct regulator_dev *rdev;
235 struct regulator_config config = { }; 227 struct regulator_config config = { };
236 int i, ret; 228 int i;
237 229
238 if (tps->dev->of_node) 230 if (tps->dev->of_node)
239 pdata = tps65217_parse_dt(pdev); 231 pdata = tps65217_parse_dt(pdev);
@@ -269,35 +261,18 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
269 if (tps->dev->of_node) 261 if (tps->dev->of_node)
270 config.of_node = pdata->of_node[i]; 262 config.of_node = pdata->of_node[i];
271 263
272 rdev = regulator_register(&regulators[i], &config); 264 rdev = devm_regulator_register(&pdev->dev, &regulators[i],
265 &config);
273 if (IS_ERR(rdev)) { 266 if (IS_ERR(rdev)) {
274 dev_err(tps->dev, "failed to register %s regulator\n", 267 dev_err(tps->dev, "failed to register %s regulator\n",
275 pdev->name); 268 pdev->name);
276 ret = PTR_ERR(rdev); 269 return PTR_ERR(rdev);
277 goto err_unregister_regulator;
278 } 270 }
279 271
280 /* Save regulator for cleanup */ 272 /* Save regulator for cleanup */
281 tps->rdev[i] = rdev; 273 tps->rdev[i] = rdev;
282 } 274 }
283 return 0; 275 return 0;
284
285err_unregister_regulator:
286 while (--i >= 0)
287 regulator_unregister(tps->rdev[i]);
288
289 return ret;
290}
291
292static int tps65217_regulator_remove(struct platform_device *pdev)
293{
294 struct tps65217 *tps = platform_get_drvdata(pdev);
295 unsigned int i;
296
297 for (i = 0; i < TPS65217_NUM_REGULATOR; i++)
298 regulator_unregister(tps->rdev[i]);
299
300 return 0;
301} 276}
302 277
303static struct platform_driver tps65217_regulator_driver = { 278static struct platform_driver tps65217_regulator_driver = {
@@ -305,7 +280,6 @@ static struct platform_driver tps65217_regulator_driver = {
305 .name = "tps65217-pmic", 280 .name = "tps65217-pmic",
306 }, 281 },
307 .probe = tps65217_regulator_probe, 282 .probe = tps65217_regulator_probe,
308 .remove = tps65217_regulator_remove,
309}; 283};
310 284
311static int __init tps65217_regulator_init(void) 285static int __init tps65217_regulator_init(void)
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 62e8d28beabd..9f6bfda711b7 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -577,21 +577,6 @@ static struct regulator_ops regulator_ops = {
577 .get_current_limit = get_current_limit, 577 .get_current_limit = get_current_limit,
578}; 578};
579 579
580static int pmic_remove(struct spi_device *spi)
581{
582 struct tps6524x *hw = spi_get_drvdata(spi);
583 int i;
584
585 if (!hw)
586 return 0;
587 for (i = 0; i < N_REGULATORS; i++) {
588 regulator_unregister(hw->rdev[i]);
589 hw->rdev[i] = NULL;
590 }
591 spi_set_drvdata(spi, NULL);
592 return 0;
593}
594
595static int pmic_probe(struct spi_device *spi) 580static int pmic_probe(struct spi_device *spi)
596{ 581{
597 struct tps6524x *hw; 582 struct tps6524x *hw;
@@ -599,7 +584,7 @@ static int pmic_probe(struct spi_device *spi)
599 const struct supply_info *info = supply_info; 584 const struct supply_info *info = supply_info;
600 struct regulator_init_data *init_data; 585 struct regulator_init_data *init_data;
601 struct regulator_config config = { }; 586 struct regulator_config config = { };
602 int ret = 0, i; 587 int i;
603 588
604 init_data = dev_get_platdata(dev); 589 init_data = dev_get_platdata(dev);
605 if (!init_data) { 590 if (!init_data) {
@@ -632,24 +617,17 @@ static int pmic_probe(struct spi_device *spi)
632 config.init_data = init_data; 617 config.init_data = init_data;
633 config.driver_data = hw; 618 config.driver_data = hw;
634 619
635 hw->rdev[i] = regulator_register(&hw->desc[i], &config); 620 hw->rdev[i] = devm_regulator_register(dev, &hw->desc[i],
636 if (IS_ERR(hw->rdev[i])) { 621 &config);
637 ret = PTR_ERR(hw->rdev[i]); 622 if (IS_ERR(hw->rdev[i]))
638 hw->rdev[i] = NULL; 623 return PTR_ERR(hw->rdev[i]);
639 goto fail;
640 }
641 } 624 }
642 625
643 return 0; 626 return 0;
644
645fail:
646 pmic_remove(spi);
647 return ret;
648} 627}
649 628
650static struct spi_driver pmic_driver = { 629static struct spi_driver pmic_driver = {
651 .probe = pmic_probe, 630 .probe = pmic_probe,
652 .remove = pmic_remove,
653 .driver = { 631 .driver = {
654 .name = "tps6524x", 632 .name = "tps6524x",
655 .owner = THIS_MODULE, 633 .owner = THIS_MODULE,
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 2c9155b66f09..e8e3a8afd3e2 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -298,7 +298,7 @@ static struct tps6586x_platform_data *tps6586x_parse_regulator_dt(
298 struct tps6586x_platform_data *pdata; 298 struct tps6586x_platform_data *pdata;
299 int err; 299 int err;
300 300
301 regs = of_find_node_by_name(np, "regulators"); 301 regs = of_get_child_by_name(np, "regulators");
302 if (!regs) { 302 if (!regs) {
303 dev_err(&pdev->dev, "regulator node not found\n"); 303 dev_err(&pdev->dev, "regulator node not found\n");
304 return NULL; 304 return NULL;
@@ -379,15 +379,14 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
379 ri = find_regulator_info(id); 379 ri = find_regulator_info(id);
380 if (!ri) { 380 if (!ri) {
381 dev_err(&pdev->dev, "invalid regulator ID specified\n"); 381 dev_err(&pdev->dev, "invalid regulator ID specified\n");
382 err = -EINVAL; 382 return -EINVAL;
383 goto fail;
384 } 383 }
385 384
386 err = tps6586x_regulator_preinit(pdev->dev.parent, ri); 385 err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
387 if (err) { 386 if (err) {
388 dev_err(&pdev->dev, 387 dev_err(&pdev->dev,
389 "regulator %d preinit failed, e %d\n", id, err); 388 "regulator %d preinit failed, e %d\n", id, err);
390 goto fail; 389 return err;
391 } 390 }
392 391
393 config.dev = pdev->dev.parent; 392 config.dev = pdev->dev.parent;
@@ -397,12 +396,12 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
397 if (tps6586x_reg_matches) 396 if (tps6586x_reg_matches)
398 config.of_node = tps6586x_reg_matches[id].of_node; 397 config.of_node = tps6586x_reg_matches[id].of_node;
399 398
400 rdev[id] = regulator_register(&ri->desc, &config); 399 rdev[id] = devm_regulator_register(&pdev->dev, &ri->desc,
400 &config);
401 if (IS_ERR(rdev[id])) { 401 if (IS_ERR(rdev[id])) {
402 dev_err(&pdev->dev, "failed to register regulator %s\n", 402 dev_err(&pdev->dev, "failed to register regulator %s\n",
403 ri->desc.name); 403 ri->desc.name);
404 err = PTR_ERR(rdev[id]); 404 return PTR_ERR(rdev[id]);
405 goto fail;
406 } 405 }
407 406
408 if (reg_data) { 407 if (reg_data) {
@@ -411,30 +410,13 @@ static int tps6586x_regulator_probe(struct platform_device *pdev)
411 if (err < 0) { 410 if (err < 0) {
412 dev_err(&pdev->dev, 411 dev_err(&pdev->dev,
413 "Slew rate config failed, e %d\n", err); 412 "Slew rate config failed, e %d\n", err);
414 regulator_unregister(rdev[id]); 413 return err;
415 goto fail;
416 } 414 }
417 } 415 }
418 } 416 }
419 417
420 platform_set_drvdata(pdev, rdev); 418 platform_set_drvdata(pdev, rdev);
421 return 0; 419 return 0;
422
423fail:
424 while (--id >= 0)
425 regulator_unregister(rdev[id]);
426 return err;
427}
428
429static int tps6586x_regulator_remove(struct platform_device *pdev)
430{
431 struct regulator_dev **rdev = platform_get_drvdata(pdev);
432 int id = TPS6586X_ID_MAX_REGULATOR;
433
434 while (--id >= 0)
435 regulator_unregister(rdev[id]);
436
437 return 0;
438} 420}
439 421
440static struct platform_driver tps6586x_regulator_driver = { 422static struct platform_driver tps6586x_regulator_driver = {
@@ -443,7 +425,6 @@ static struct platform_driver tps6586x_regulator_driver = {
443 .owner = THIS_MODULE, 425 .owner = THIS_MODULE,
444 }, 426 },
445 .probe = tps6586x_regulator_probe, 427 .probe = tps6586x_regulator_probe,
446 .remove = tps6586x_regulator_remove,
447}; 428};
448 429
449static int __init tps6586x_regulator_init(void) 430static int __init tps6586x_regulator_init(void)
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index 45c16447744b..23f8d1ce877d 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -481,7 +481,7 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
481 481
482 /* multiplier 0 == 1 but 2,3 normal */ 482 /* multiplier 0 == 1 but 2,3 normal */
483 if (!mult) 483 if (!mult)
484 mult=1; 484 mult = 1;
485 485
486 if (sr) { 486 if (sr) {
487 /* normalise to valid range */ 487 /* normalise to valid range */
@@ -685,7 +685,7 @@ static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
685 case TPS65910_REG_VDD2: 685 case TPS65910_REG_VDD2:
686 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; 686 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
687 volt = VDD1_2_MIN_VOLT + 687 volt = VDD1_2_MIN_VOLT +
688 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET; 688 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
689 break; 689 break;
690 case TPS65911_REG_VDDCTRL: 690 case TPS65911_REG_VDDCTRL:
691 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET); 691 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
@@ -703,7 +703,7 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
703 struct tps65910_reg *pmic = rdev_get_drvdata(dev); 703 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
704 int step_mv = 0, id = rdev_get_id(dev); 704 int step_mv = 0, id = rdev_get_id(dev);
705 705
706 switch(id) { 706 switch (id) {
707 case TPS65911_REG_LDO1: 707 case TPS65911_REG_LDO1:
708 case TPS65911_REG_LDO2: 708 case TPS65911_REG_LDO2:
709 case TPS65911_REG_LDO4: 709 case TPS65911_REG_LDO4:
@@ -982,7 +982,7 @@ static struct tps65910_board *tps65910_parse_dt_reg_data(
982 } 982 }
983 983
984 np = of_node_get(pdev->dev.parent->of_node); 984 np = of_node_get(pdev->dev.parent->of_node);
985 regulators = of_find_node_by_name(np, "regulators"); 985 regulators = of_get_child_by_name(np, "regulators");
986 if (!regulators) { 986 if (!regulators) {
987 dev_err(&pdev->dev, "regulator node not found\n"); 987 dev_err(&pdev->dev, "regulator node not found\n");
988 return NULL; 988 return NULL;
@@ -1074,7 +1074,7 @@ static int tps65910_probe(struct platform_device *pdev)
1074 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL, 1074 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1075 DEVCTRL_SR_CTL_I2C_SEL_MASK); 1075 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1076 1076
1077 switch(tps65910_chip_id(tps65910)) { 1077 switch (tps65910_chip_id(tps65910)) {
1078 case TPS65910: 1078 case TPS65910:
1079 pmic->get_ctrl_reg = &tps65910_get_ctrl_register; 1079 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1080 pmic->num_regulators = ARRAY_SIZE(tps65910_regs); 1080 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
@@ -1177,35 +1177,19 @@ static int tps65910_probe(struct platform_device *pdev)
1177 if (tps65910_reg_matches) 1177 if (tps65910_reg_matches)
1178 config.of_node = tps65910_reg_matches[i].of_node; 1178 config.of_node = tps65910_reg_matches[i].of_node;
1179 1179
1180 rdev = regulator_register(&pmic->desc[i], &config); 1180 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1181 &config);
1181 if (IS_ERR(rdev)) { 1182 if (IS_ERR(rdev)) {
1182 dev_err(tps65910->dev, 1183 dev_err(tps65910->dev,
1183 "failed to register %s regulator\n", 1184 "failed to register %s regulator\n",
1184 pdev->name); 1185 pdev->name);
1185 err = PTR_ERR(rdev); 1186 return PTR_ERR(rdev);
1186 goto err_unregister_regulator;
1187 } 1187 }
1188 1188
1189 /* Save regulator for cleanup */ 1189 /* Save regulator for cleanup */
1190 pmic->rdev[i] = rdev; 1190 pmic->rdev[i] = rdev;
1191 } 1191 }
1192 return 0; 1192 return 0;
1193
1194err_unregister_regulator:
1195 while (--i >= 0)
1196 regulator_unregister(pmic->rdev[i]);
1197 return err;
1198}
1199
1200static int tps65910_remove(struct platform_device *pdev)
1201{
1202 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1203 int i;
1204
1205 for (i = 0; i < pmic->num_regulators; i++)
1206 regulator_unregister(pmic->rdev[i]);
1207
1208 return 0;
1209} 1193}
1210 1194
1211static void tps65910_shutdown(struct platform_device *pdev) 1195static void tps65910_shutdown(struct platform_device *pdev)
@@ -1244,7 +1228,6 @@ static struct platform_driver tps65910_driver = {
1244 .owner = THIS_MODULE, 1228 .owner = THIS_MODULE,
1245 }, 1229 },
1246 .probe = tps65910_probe, 1230 .probe = tps65910_probe,
1247 .remove = tps65910_remove,
1248 .shutdown = tps65910_shutdown, 1231 .shutdown = tps65910_shutdown,
1249}; 1232};
1250 1233
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c
index 281e52ac64ba..9cafaa0f9455 100644
--- a/drivers/regulator/tps65912-regulator.c
+++ b/drivers/regulator/tps65912-regulator.c
@@ -119,12 +119,9 @@ struct tps65912_reg {
119}; 119};
120 120
121static const struct regulator_linear_range tps65912_ldo_ranges[] = { 121static const struct regulator_linear_range tps65912_ldo_ranges[] = {
122 { .min_uV = 800000, .max_uV = 1600000, .min_sel = 0, .max_sel = 32, 122 REGULATOR_LINEAR_RANGE(800000, 0, 32, 25000),
123 .uV_step = 25000 }, 123 REGULATOR_LINEAR_RANGE(1650000, 33, 60, 50000),
124 { .min_uV = 1650000, .max_uV = 3000000, .min_sel = 33, .max_sel = 60, 124 REGULATOR_LINEAR_RANGE(3100000, 61, 63, 100000),
125 .uV_step = 50000 },
126 { .min_uV = 3100000, .max_uV = 3300000, .min_sel = 61, .max_sel = 63,
127 .uV_step = 100000 },
128}; 125};
129 126
130static int tps65912_get_range(struct tps65912_reg *pmic, int id) 127static int tps65912_get_range(struct tps65912_reg *pmic, int id)
@@ -461,7 +458,7 @@ static int tps65912_probe(struct platform_device *pdev)
461 struct regulator_dev *rdev; 458 struct regulator_dev *rdev;
462 struct tps65912_reg *pmic; 459 struct tps65912_reg *pmic;
463 struct tps65912_board *pmic_plat_data; 460 struct tps65912_board *pmic_plat_data;
464 int i, err; 461 int i;
465 462
466 pmic_plat_data = dev_get_platdata(tps65912->dev); 463 pmic_plat_data = dev_get_platdata(tps65912->dev);
467 if (!pmic_plat_data) 464 if (!pmic_plat_data)
@@ -504,34 +501,19 @@ static int tps65912_probe(struct platform_device *pdev)
504 config.init_data = reg_data; 501 config.init_data = reg_data;
505 config.driver_data = pmic; 502 config.driver_data = pmic;
506 503
507 rdev = regulator_register(&pmic->desc[i], &config); 504 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
505 &config);
508 if (IS_ERR(rdev)) { 506 if (IS_ERR(rdev)) {
509 dev_err(tps65912->dev, 507 dev_err(tps65912->dev,
510 "failed to register %s regulator\n", 508 "failed to register %s regulator\n",
511 pdev->name); 509 pdev->name);
512 err = PTR_ERR(rdev); 510 return PTR_ERR(rdev);
513 goto err;
514 } 511 }
515 512
516 /* Save regulator for cleanup */ 513 /* Save regulator for cleanup */
517 pmic->rdev[i] = rdev; 514 pmic->rdev[i] = rdev;
518 } 515 }
519 return 0; 516 return 0;
520
521err:
522 while (--i >= 0)
523 regulator_unregister(pmic->rdev[i]);
524 return err;
525}
526
527static int tps65912_remove(struct platform_device *pdev)
528{
529 struct tps65912_reg *tps65912_reg = platform_get_drvdata(pdev);
530 int i;
531
532 for (i = 0; i < TPS65912_NUM_REGULATOR; i++)
533 regulator_unregister(tps65912_reg->rdev[i]);
534 return 0;
535} 517}
536 518
537static struct platform_driver tps65912_driver = { 519static struct platform_driver tps65912_driver = {
@@ -540,7 +522,6 @@ static struct platform_driver tps65912_driver = {
540 .owner = THIS_MODULE, 522 .owner = THIS_MODULE,
541 }, 523 },
542 .probe = tps65912_probe, 524 .probe = tps65912_probe,
543 .remove = tps65912_remove,
544}; 525};
545 526
546static int __init tps65912_init(void) 527static int __init tps65912_init(void)
diff --git a/drivers/regulator/tps80031-regulator.c b/drivers/regulator/tps80031-regulator.c
index 6511d0bfd896..71f457a42623 100644
--- a/drivers/regulator/tps80031-regulator.c
+++ b/drivers/regulator/tps80031-regulator.c
@@ -719,7 +719,7 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
719 if (ret < 0) { 719 if (ret < 0) {
720 dev_err(&pdev->dev, 720 dev_err(&pdev->dev,
721 "regulator config failed, e %d\n", ret); 721 "regulator config failed, e %d\n", ret);
722 goto fail; 722 return ret;
723 } 723 }
724 724
725 ret = tps80031_power_req_config(pdev->dev.parent, 725 ret = tps80031_power_req_config(pdev->dev.parent,
@@ -727,41 +727,22 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
727 if (ret < 0) { 727 if (ret < 0) {
728 dev_err(&pdev->dev, 728 dev_err(&pdev->dev,
729 "pwr_req config failed, err %d\n", ret); 729 "pwr_req config failed, err %d\n", ret);
730 goto fail; 730 return ret;
731 } 731 }
732 } 732 }
733 rdev = regulator_register(&ri->rinfo->desc, &config); 733 rdev = devm_regulator_register(&pdev->dev, &ri->rinfo->desc,
734 &config);
734 if (IS_ERR(rdev)) { 735 if (IS_ERR(rdev)) {
735 dev_err(&pdev->dev, 736 dev_err(&pdev->dev,
736 "register regulator failed %s\n", 737 "register regulator failed %s\n",
737 ri->rinfo->desc.name); 738 ri->rinfo->desc.name);
738 ret = PTR_ERR(rdev); 739 return PTR_ERR(rdev);
739 goto fail;
740 } 740 }
741 ri->rdev = rdev; 741 ri->rdev = rdev;
742 } 742 }
743 743
744 platform_set_drvdata(pdev, pmic); 744 platform_set_drvdata(pdev, pmic);
745 return 0; 745 return 0;
746fail:
747 while (--num >= 0) {
748 ri = &pmic[num];
749 regulator_unregister(ri->rdev);
750 }
751 return ret;
752}
753
754static int tps80031_regulator_remove(struct platform_device *pdev)
755{
756 struct tps80031_regulator *pmic = platform_get_drvdata(pdev);
757 struct tps80031_regulator *ri = NULL;
758 int num;
759
760 for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) {
761 ri = &pmic[num];
762 regulator_unregister(ri->rdev);
763 }
764 return 0;
765} 746}
766 747
767static struct platform_driver tps80031_regulator_driver = { 748static struct platform_driver tps80031_regulator_driver = {
@@ -770,7 +751,6 @@ static struct platform_driver tps80031_regulator_driver = {
770 .owner = THIS_MODULE, 751 .owner = THIS_MODULE,
771 }, 752 },
772 .probe = tps80031_regulator_probe, 753 .probe = tps80031_regulator_probe,
773 .remove = tps80031_regulator_remove,
774}; 754};
775 755
776static int __init tps80031_regulator_init(void) 756static int __init tps80031_regulator_init(void)
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 78aae4cbb004..8ebd785485c7 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -1188,7 +1188,7 @@ static int twlreg_probe(struct platform_device *pdev)
1188 config.driver_data = info; 1188 config.driver_data = info;
1189 config.of_node = pdev->dev.of_node; 1189 config.of_node = pdev->dev.of_node;
1190 1190
1191 rdev = regulator_register(&info->desc, &config); 1191 rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
1192 if (IS_ERR(rdev)) { 1192 if (IS_ERR(rdev)) {
1193 dev_err(&pdev->dev, "can't register %s, %ld\n", 1193 dev_err(&pdev->dev, "can't register %s, %ld\n",
1194 info->desc.name, PTR_ERR(rdev)); 1194 info->desc.name, PTR_ERR(rdev));
@@ -1217,7 +1217,6 @@ static int twlreg_remove(struct platform_device *pdev)
1217 struct regulator_dev *rdev = platform_get_drvdata(pdev); 1217 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1218 struct twlreg_info *info = rdev->reg_data; 1218 struct twlreg_info *info = rdev->reg_data;
1219 1219
1220 regulator_unregister(rdev);
1221 kfree(info); 1220 kfree(info);
1222 return 0; 1221 return 0;
1223} 1222}
diff --git a/drivers/regulator/vexpress.c b/drivers/regulator/vexpress.c
index 4668c7f8133d..f3ae28a7e663 100644
--- a/drivers/regulator/vexpress.c
+++ b/drivers/regulator/vexpress.c
@@ -96,7 +96,7 @@ static int vexpress_regulator_probe(struct platform_device *pdev)
96 config.driver_data = reg; 96 config.driver_data = reg;
97 config.of_node = pdev->dev.of_node; 97 config.of_node = pdev->dev.of_node;
98 98
99 reg->regdev = regulator_register(&reg->desc, &config); 99 reg->regdev = devm_regulator_register(&pdev->dev, &reg->desc, &config);
100 if (IS_ERR(reg->regdev)) { 100 if (IS_ERR(reg->regdev)) {
101 err = PTR_ERR(reg->regdev); 101 err = PTR_ERR(reg->regdev);
102 goto error_regulator_register; 102 goto error_regulator_register;
@@ -119,7 +119,6 @@ static int vexpress_regulator_remove(struct platform_device *pdev)
119 struct vexpress_regulator *reg = platform_get_drvdata(pdev); 119 struct vexpress_regulator *reg = platform_get_drvdata(pdev);
120 120
121 vexpress_config_func_put(reg->func); 121 vexpress_config_func_put(reg->func);
122 regulator_unregister(reg->regdev);
123 122
124 return 0; 123 return 0;
125} 124}
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 11861cb861df..6823e6f2b88a 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -387,8 +387,9 @@ static struct regulator_ops wm831x_buckv_ops = {
387 * Set up DVS control. We just log errors since we can still run 387 * Set up DVS control. We just log errors since we can still run
388 * (with reduced performance) if we fail. 388 * (with reduced performance) if we fail.
389 */ 389 */
390static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, 390static void wm831x_buckv_dvs_init(struct platform_device *pdev,
391 struct wm831x_buckv_pdata *pdata) 391 struct wm831x_dcdc *dcdc,
392 struct wm831x_buckv_pdata *pdata)
392{ 393{
393 struct wm831x *wm831x = dcdc->wm831x; 394 struct wm831x *wm831x = dcdc->wm831x;
394 int ret; 395 int ret;
@@ -402,9 +403,9 @@ static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc,
402 */ 403 */
403 dcdc->dvs_gpio_state = pdata->dvs_init_state; 404 dcdc->dvs_gpio_state = pdata->dvs_init_state;
404 405
405 ret = gpio_request_one(pdata->dvs_gpio, 406 ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio,
406 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, 407 dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0,
407 "DCDC DVS"); 408 "DCDC DVS");
408 if (ret < 0) { 409 if (ret < 0) {
409 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 410 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n",
410 dcdc->name, ret); 411 dcdc->name, ret);
@@ -513,7 +514,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
513 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; 514 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
514 515
515 if (pdata && pdata->dcdc[id]) 516 if (pdata && pdata->dcdc[id])
516 wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); 517 wm831x_buckv_dvs_init(pdev, dcdc,
518 pdata->dcdc[id]->driver_data);
517 519
518 config.dev = pdev->dev.parent; 520 config.dev = pdev->dev.parent;
519 if (pdata) 521 if (pdata)
@@ -521,7 +523,8 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
521 config.driver_data = dcdc; 523 config.driver_data = dcdc;
522 config.regmap = wm831x->regmap; 524 config.regmap = wm831x->regmap;
523 525
524 dcdc->regulator = regulator_register(&dcdc->desc, &config); 526 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
527 &config);
525 if (IS_ERR(dcdc->regulator)) { 528 if (IS_ERR(dcdc->regulator)) {
526 ret = PTR_ERR(dcdc->regulator); 529 ret = PTR_ERR(dcdc->regulator);
527 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 530 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -530,57 +533,35 @@ static int wm831x_buckv_probe(struct platform_device *pdev)
530 } 533 }
531 534
532 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 535 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
533 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 536 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
534 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 537 wm831x_dcdc_uv_irq,
538 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
535 if (ret != 0) { 539 if (ret != 0) {
536 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 540 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
537 irq, ret); 541 irq, ret);
538 goto err_regulator; 542 goto err;
539 } 543 }
540 544
541 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")); 545 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC"));
542 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_oc_irq, 546 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
543 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 547 wm831x_dcdc_oc_irq,
548 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
544 if (ret != 0) { 549 if (ret != 0) {
545 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",
546 irq, ret); 551 irq, ret);
547 goto err_uv; 552 goto err;
548 } 553 }
549 554
550 platform_set_drvdata(pdev, dcdc); 555 platform_set_drvdata(pdev, dcdc);
551 556
552 return 0; 557 return 0;
553 558
554err_uv:
555 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")),
556 dcdc);
557err_regulator:
558 regulator_unregister(dcdc->regulator);
559err: 559err:
560 if (dcdc->dvs_gpio)
561 gpio_free(dcdc->dvs_gpio);
562 return ret; 560 return ret;
563} 561}
564 562
565static int wm831x_buckv_remove(struct platform_device *pdev)
566{
567 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
568 struct wm831x *wm831x = dcdc->wm831x;
569
570 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC")),
571 dcdc);
572 free_irq(wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")),
573 dcdc);
574 regulator_unregister(dcdc->regulator);
575 if (dcdc->dvs_gpio)
576 gpio_free(dcdc->dvs_gpio);
577
578 return 0;
579}
580
581static struct platform_driver wm831x_buckv_driver = { 563static struct platform_driver wm831x_buckv_driver = {
582 .probe = wm831x_buckv_probe, 564 .probe = wm831x_buckv_probe,
583 .remove = wm831x_buckv_remove,
584 .driver = { 565 .driver = {
585 .name = "wm831x-buckv", 566 .name = "wm831x-buckv",
586 .owner = THIS_MODULE, 567 .owner = THIS_MODULE,
@@ -681,7 +662,8 @@ static int wm831x_buckp_probe(struct platform_device *pdev)
681 config.driver_data = dcdc; 662 config.driver_data = dcdc;
682 config.regmap = wm831x->regmap; 663 config.regmap = wm831x->regmap;
683 664
684 dcdc->regulator = regulator_register(&dcdc->desc, &config); 665 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
666 &config);
685 if (IS_ERR(dcdc->regulator)) { 667 if (IS_ERR(dcdc->regulator)) {
686 ret = PTR_ERR(dcdc->regulator); 668 ret = PTR_ERR(dcdc->regulator);
687 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 669 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -690,38 +672,25 @@ static int wm831x_buckp_probe(struct platform_device *pdev)
690 } 672 }
691 673
692 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 674 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
693 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 675 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
694 IRQF_TRIGGER_RISING, dcdc->name, dcdc); 676 wm831x_dcdc_uv_irq,
677 IRQF_TRIGGER_RISING, dcdc->name, dcdc);
695 if (ret != 0) { 678 if (ret != 0) {
696 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 679 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
697 irq, ret); 680 irq, ret);
698 goto err_regulator; 681 goto err;
699 } 682 }
700 683
701 platform_set_drvdata(pdev, dcdc); 684 platform_set_drvdata(pdev, dcdc);
702 685
703 return 0; 686 return 0;
704 687
705err_regulator:
706 regulator_unregister(dcdc->regulator);
707err: 688err:
708 return ret; 689 return ret;
709} 690}
710 691
711static int wm831x_buckp_remove(struct platform_device *pdev)
712{
713 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
714
715 free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")),
716 dcdc);
717 regulator_unregister(dcdc->regulator);
718
719 return 0;
720}
721
722static struct platform_driver wm831x_buckp_driver = { 692static struct platform_driver wm831x_buckp_driver = {
723 .probe = wm831x_buckp_probe, 693 .probe = wm831x_buckp_probe,
724 .remove = wm831x_buckp_remove,
725 .driver = { 694 .driver = {
726 .name = "wm831x-buckp", 695 .name = "wm831x-buckp",
727 .owner = THIS_MODULE, 696 .owner = THIS_MODULE,
@@ -813,7 +782,8 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
813 config.driver_data = dcdc; 782 config.driver_data = dcdc;
814 config.regmap = wm831x->regmap; 783 config.regmap = wm831x->regmap;
815 784
816 dcdc->regulator = regulator_register(&dcdc->desc, &config); 785 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
786 &config);
817 if (IS_ERR(dcdc->regulator)) { 787 if (IS_ERR(dcdc->regulator)) {
818 ret = PTR_ERR(dcdc->regulator); 788 ret = PTR_ERR(dcdc->regulator);
819 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", 789 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
@@ -822,39 +792,26 @@ static int wm831x_boostp_probe(struct platform_device *pdev)
822 } 792 }
823 793
824 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 794 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
825 ret = request_threaded_irq(irq, NULL, wm831x_dcdc_uv_irq, 795 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
826 IRQF_TRIGGER_RISING, dcdc->name, 796 wm831x_dcdc_uv_irq,
827 dcdc); 797 IRQF_TRIGGER_RISING, dcdc->name,
798 dcdc);
828 if (ret != 0) { 799 if (ret != 0) {
829 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 800 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
830 irq, ret); 801 irq, ret);
831 goto err_regulator; 802 goto err;
832 } 803 }
833 804
834 platform_set_drvdata(pdev, dcdc); 805 platform_set_drvdata(pdev, dcdc);
835 806
836 return 0; 807 return 0;
837 808
838err_regulator:
839 regulator_unregister(dcdc->regulator);
840err: 809err:
841 return ret; 810 return ret;
842} 811}
843 812
844static int wm831x_boostp_remove(struct platform_device *pdev)
845{
846 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
847
848 free_irq(wm831x_irq(dcdc->wm831x, platform_get_irq_byname(pdev, "UV")),
849 dcdc);
850 regulator_unregister(dcdc->regulator);
851
852 return 0;
853}
854
855static struct platform_driver wm831x_boostp_driver = { 813static struct platform_driver wm831x_boostp_driver = {
856 .probe = wm831x_boostp_probe, 814 .probe = wm831x_boostp_probe,
857 .remove = wm831x_boostp_remove,
858 .driver = { 815 .driver = {
859 .name = "wm831x-boostp", 816 .name = "wm831x-boostp",
860 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
@@ -914,7 +871,8 @@ static int wm831x_epe_probe(struct platform_device *pdev)
914 config.driver_data = dcdc; 871 config.driver_data = dcdc;
915 config.regmap = wm831x->regmap; 872 config.regmap = wm831x->regmap;
916 873
917 dcdc->regulator = regulator_register(&dcdc->desc, &config); 874 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
875 &config);
918 if (IS_ERR(dcdc->regulator)) { 876 if (IS_ERR(dcdc->regulator)) {
919 ret = PTR_ERR(dcdc->regulator); 877 ret = PTR_ERR(dcdc->regulator);
920 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", 878 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",
@@ -930,18 +888,8 @@ err:
930 return ret; 888 return ret;
931} 889}
932 890
933static int wm831x_epe_remove(struct platform_device *pdev)
934{
935 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
936
937 regulator_unregister(dcdc->regulator);
938
939 return 0;
940}
941
942static struct platform_driver wm831x_epe_driver = { 891static struct platform_driver wm831x_epe_driver = {
943 .probe = wm831x_epe_probe, 892 .probe = wm831x_epe_probe,
944 .remove = wm831x_epe_remove,
945 .driver = { 893 .driver = {
946 .name = "wm831x-epe", 894 .name = "wm831x-epe",
947 .owner = THIS_MODULE, 895 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 4eb373de1fac..0339b886df5d 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -194,7 +194,8 @@ static int wm831x_isink_probe(struct platform_device *pdev)
194 config.init_data = pdata->isink[id]; 194 config.init_data = pdata->isink[id];
195 config.driver_data = isink; 195 config.driver_data = isink;
196 196
197 isink->regulator = regulator_register(&isink->desc, &config); 197 isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
198 &config);
198 if (IS_ERR(isink->regulator)) { 199 if (IS_ERR(isink->regulator)) {
199 ret = PTR_ERR(isink->regulator); 200 ret = PTR_ERR(isink->regulator);
200 dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n", 201 dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n",
@@ -203,38 +204,26 @@ static int wm831x_isink_probe(struct platform_device *pdev)
203 } 204 }
204 205
205 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0)); 206 irq = wm831x_irq(wm831x, platform_get_irq(pdev, 0));
206 ret = request_threaded_irq(irq, NULL, wm831x_isink_irq, 207 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
207 IRQF_TRIGGER_RISING, isink->name, isink); 208 wm831x_isink_irq,
209 IRQF_TRIGGER_RISING, isink->name,
210 isink);
208 if (ret != 0) { 211 if (ret != 0) {
209 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n", 212 dev_err(&pdev->dev, "Failed to request ISINK IRQ %d: %d\n",
210 irq, ret); 213 irq, ret);
211 goto err_regulator; 214 goto err;
212 } 215 }
213 216
214 platform_set_drvdata(pdev, isink); 217 platform_set_drvdata(pdev, isink);
215 218
216 return 0; 219 return 0;
217 220
218err_regulator:
219 regulator_unregister(isink->regulator);
220err: 221err:
221 return ret; 222 return ret;
222} 223}
223 224
224static int wm831x_isink_remove(struct platform_device *pdev)
225{
226 struct wm831x_isink *isink = platform_get_drvdata(pdev);
227
228 free_irq(wm831x_irq(isink->wm831x, platform_get_irq(pdev, 0)), isink);
229
230 regulator_unregister(isink->regulator);
231
232 return 0;
233}
234
235static struct platform_driver wm831x_isink_driver = { 225static struct platform_driver wm831x_isink_driver = {
236 .probe = wm831x_isink_probe, 226 .probe = wm831x_isink_probe,
237 .remove = wm831x_isink_remove,
238 .driver = { 227 .driver = {
239 .name = "wm831x-isink", 228 .name = "wm831x-isink",
240 .owner = THIS_MODULE, 229 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 2205fbc2c37b..46d6700467b5 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -63,10 +63,8 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data)
63 */ 63 */
64 64
65static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = { 65static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = {
66 { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14, 66 REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000),
67 .uV_step = 50000 }, 67 REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000),
68 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
69 .uV_step = 100000 },
70}; 68};
71 69
72static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, 70static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -279,7 +277,8 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
279 config.driver_data = ldo; 277 config.driver_data = ldo;
280 config.regmap = wm831x->regmap; 278 config.regmap = wm831x->regmap;
281 279
282 ldo->regulator = regulator_register(&ldo->desc, &config); 280 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
281 &config);
283 if (IS_ERR(ldo->regulator)) { 282 if (IS_ERR(ldo->regulator)) {
284 ret = PTR_ERR(ldo->regulator); 283 ret = PTR_ERR(ldo->regulator);
285 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 284 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -288,39 +287,26 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
288 } 287 }
289 288
290 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 289 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
291 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 290 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
292 IRQF_TRIGGER_RISING, ldo->name, 291 wm831x_ldo_uv_irq,
293 ldo); 292 IRQF_TRIGGER_RISING, ldo->name,
293 ldo);
294 if (ret != 0) { 294 if (ret != 0) {
295 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 295 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
296 irq, ret); 296 irq, ret);
297 goto err_regulator; 297 goto err;
298 } 298 }
299 299
300 platform_set_drvdata(pdev, ldo); 300 platform_set_drvdata(pdev, ldo);
301 301
302 return 0; 302 return 0;
303 303
304err_regulator:
305 regulator_unregister(ldo->regulator);
306err: 304err:
307 return ret; 305 return ret;
308} 306}
309 307
310static int wm831x_gp_ldo_remove(struct platform_device *pdev)
311{
312 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
313
314 free_irq(wm831x_irq(ldo->wm831x,
315 platform_get_irq_byname(pdev, "UV")), ldo);
316 regulator_unregister(ldo->regulator);
317
318 return 0;
319}
320
321static struct platform_driver wm831x_gp_ldo_driver = { 308static struct platform_driver wm831x_gp_ldo_driver = {
322 .probe = wm831x_gp_ldo_probe, 309 .probe = wm831x_gp_ldo_probe,
323 .remove = wm831x_gp_ldo_remove,
324 .driver = { 310 .driver = {
325 .name = "wm831x-ldo", 311 .name = "wm831x-ldo",
326 .owner = THIS_MODULE, 312 .owner = THIS_MODULE,
@@ -332,10 +318,8 @@ static struct platform_driver wm831x_gp_ldo_driver = {
332 */ 318 */
333 319
334static const struct regulator_linear_range wm831x_aldo_ranges[] = { 320static const struct regulator_linear_range wm831x_aldo_ranges[] = {
335 { .min_uV = 1000000, .max_uV = 1600000, .min_sel = 0, .max_sel = 12, 321 REGULATOR_LINEAR_RANGE(1000000, 0, 12, 50000),
336 .uV_step = 50000 }, 322 REGULATOR_LINEAR_RANGE(1700000, 13, 31, 100000),
337 { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31,
338 .uV_step = 100000 },
339}; 323};
340 324
341static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 325static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -505,7 +489,8 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
505 config.driver_data = ldo; 489 config.driver_data = ldo;
506 config.regmap = wm831x->regmap; 490 config.regmap = wm831x->regmap;
507 491
508 ldo->regulator = regulator_register(&ldo->desc, &config); 492 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
493 &config);
509 if (IS_ERR(ldo->regulator)) { 494 if (IS_ERR(ldo->regulator)) {
510 ret = PTR_ERR(ldo->regulator); 495 ret = PTR_ERR(ldo->regulator);
511 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 496 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -514,38 +499,25 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
514 } 499 }
515 500
516 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 501 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
517 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 502 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
518 IRQF_TRIGGER_RISING, ldo->name, ldo); 503 wm831x_ldo_uv_irq,
504 IRQF_TRIGGER_RISING, ldo->name, ldo);
519 if (ret != 0) { 505 if (ret != 0) {
520 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 506 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
521 irq, ret); 507 irq, ret);
522 goto err_regulator; 508 goto err;
523 } 509 }
524 510
525 platform_set_drvdata(pdev, ldo); 511 platform_set_drvdata(pdev, ldo);
526 512
527 return 0; 513 return 0;
528 514
529err_regulator:
530 regulator_unregister(ldo->regulator);
531err: 515err:
532 return ret; 516 return ret;
533} 517}
534 518
535static int wm831x_aldo_remove(struct platform_device *pdev)
536{
537 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
538
539 free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")),
540 ldo);
541 regulator_unregister(ldo->regulator);
542
543 return 0;
544}
545
546static struct platform_driver wm831x_aldo_driver = { 519static struct platform_driver wm831x_aldo_driver = {
547 .probe = wm831x_aldo_probe, 520 .probe = wm831x_aldo_probe,
548 .remove = wm831x_aldo_remove,
549 .driver = { 521 .driver = {
550 .name = "wm831x-aldo", 522 .name = "wm831x-aldo",
551 .owner = THIS_MODULE, 523 .owner = THIS_MODULE,
@@ -663,7 +635,8 @@ static int wm831x_alive_ldo_probe(struct platform_device *pdev)
663 config.driver_data = ldo; 635 config.driver_data = ldo;
664 config.regmap = wm831x->regmap; 636 config.regmap = wm831x->regmap;
665 637
666 ldo->regulator = regulator_register(&ldo->desc, &config); 638 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
639 &config);
667 if (IS_ERR(ldo->regulator)) { 640 if (IS_ERR(ldo->regulator)) {
668 ret = PTR_ERR(ldo->regulator); 641 ret = PTR_ERR(ldo->regulator);
669 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 642 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
@@ -679,18 +652,8 @@ err:
679 return ret; 652 return ret;
680} 653}
681 654
682static int wm831x_alive_ldo_remove(struct platform_device *pdev)
683{
684 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
685
686 regulator_unregister(ldo->regulator);
687
688 return 0;
689}
690
691static struct platform_driver wm831x_alive_ldo_driver = { 655static struct platform_driver wm831x_alive_ldo_driver = {
692 .probe = wm831x_alive_ldo_probe, 656 .probe = wm831x_alive_ldo_probe,
693 .remove = wm831x_alive_ldo_remove,
694 .driver = { 657 .driver = {
695 .name = "wm831x-alive-ldo", 658 .name = "wm831x-alive-ldo",
696 .owner = THIS_MODULE, 659 .owner = THIS_MODULE,
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 61ca9292a429..de7b9c73e3fa 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -543,10 +543,8 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
543} 543}
544 544
545static const struct regulator_linear_range wm8350_ldo_ranges[] = { 545static const struct regulator_linear_range wm8350_ldo_ranges[] = {
546 { .min_uV = 900000, .max_uV = 1650000, .min_sel = 0, .max_sel = 15, 546 REGULATOR_LINEAR_RANGE(900000, 0, 15, 50000),
547 .uV_step = 50000 }, 547 REGULATOR_LINEAR_RANGE(1800000, 16, 31, 100000),
548 { .min_uV = 1800000, .max_uV = 3300000, .min_sel = 16, .max_sel = 31,
549 .uV_step = 100000 },
550}; 548};
551 549
552static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) 550static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
@@ -1206,7 +1204,8 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1206 config.regmap = wm8350->regmap; 1204 config.regmap = wm8350->regmap;
1207 1205
1208 /* register regulator */ 1206 /* register regulator */
1209 rdev = regulator_register(&wm8350_reg[pdev->id], &config); 1207 rdev = devm_regulator_register(&pdev->dev, &wm8350_reg[pdev->id],
1208 &config);
1210 if (IS_ERR(rdev)) { 1209 if (IS_ERR(rdev)) {
1211 dev_err(&pdev->dev, "failed to register %s\n", 1210 dev_err(&pdev->dev, "failed to register %s\n",
1212 wm8350_reg[pdev->id].name); 1211 wm8350_reg[pdev->id].name);
@@ -1217,7 +1216,6 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1217 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq, 1216 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
1218 pmic_uv_handler, 0, "UV", rdev); 1217 pmic_uv_handler, 0, "UV", rdev);
1219 if (ret < 0) { 1218 if (ret < 0) {
1220 regulator_unregister(rdev);
1221 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n", 1219 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
1222 wm8350_reg[pdev->id].name); 1220 wm8350_reg[pdev->id].name);
1223 return ret; 1221 return ret;
@@ -1233,8 +1231,6 @@ static int wm8350_regulator_remove(struct platform_device *pdev)
1233 1231
1234 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev); 1232 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq, rdev);
1235 1233
1236 regulator_unregister(rdev);
1237
1238 return 0; 1234 return 0;
1239} 1235}
1240 1236
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 58f51bec13f2..82d829000851 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -20,10 +20,8 @@
20#include <linux/mfd/wm8400-private.h> 20#include <linux/mfd/wm8400-private.h>
21 21
22static const struct regulator_linear_range wm8400_ldo_ranges[] = { 22static const struct regulator_linear_range wm8400_ldo_ranges[] = {
23 { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14, 23 REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000),
24 .uV_step = 50000 }, 24 REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000),
25 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
26 .uV_step = 100000 },
27}; 25};
28 26
29static struct regulator_ops wm8400_ldo_ops = { 27static struct regulator_ops wm8400_ldo_ops = {
@@ -219,7 +217,8 @@ static int wm8400_regulator_probe(struct platform_device *pdev)
219 config.driver_data = wm8400; 217 config.driver_data = wm8400;
220 config.regmap = wm8400->regmap; 218 config.regmap = wm8400->regmap;
221 219
222 rdev = regulator_register(&regulators[pdev->id], &config); 220 rdev = devm_regulator_register(&pdev->dev, &regulators[pdev->id],
221 &config);
223 if (IS_ERR(rdev)) 222 if (IS_ERR(rdev))
224 return PTR_ERR(rdev); 223 return PTR_ERR(rdev);
225 224
@@ -228,21 +227,11 @@ static int wm8400_regulator_probe(struct platform_device *pdev)
228 return 0; 227 return 0;
229} 228}
230 229
231static int wm8400_regulator_remove(struct platform_device *pdev)
232{
233 struct regulator_dev *rdev = platform_get_drvdata(pdev);
234
235 regulator_unregister(rdev);
236
237 return 0;
238}
239
240static struct platform_driver wm8400_regulator_driver = { 230static struct platform_driver wm8400_regulator_driver = {
241 .driver = { 231 .driver = {
242 .name = "wm8400-regulator", 232 .name = "wm8400-regulator",
243 }, 233 },
244 .probe = wm8400_regulator_probe, 234 .probe = wm8400_regulator_probe,
245 .remove = wm8400_regulator_remove,
246}; 235};
247 236
248/** 237/**
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 5ee2a208457c..71c5911f2e71 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -165,7 +165,9 @@ static int wm8994_ldo_probe(struct platform_device *pdev)
165 ldo->init_data = *pdata->ldo[id].init_data; 165 ldo->init_data = *pdata->ldo[id].init_data;
166 } 166 }
167 167
168 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); 168 ldo->regulator = devm_regulator_register(&pdev->dev,
169 &wm8994_ldo_desc[id],
170 &config);
169 if (IS_ERR(ldo->regulator)) { 171 if (IS_ERR(ldo->regulator)) {
170 ret = PTR_ERR(ldo->regulator); 172 ret = PTR_ERR(ldo->regulator);
171 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", 173 dev_err(wm8994->dev, "Failed to register LDO%d: %d\n",
@@ -181,18 +183,8 @@ err:
181 return ret; 183 return ret;
182} 184}
183 185
184static int wm8994_ldo_remove(struct platform_device *pdev)
185{
186 struct wm8994_ldo *ldo = platform_get_drvdata(pdev);
187
188 regulator_unregister(ldo->regulator);
189
190 return 0;
191}
192
193static struct platform_driver wm8994_ldo_driver = { 186static struct platform_driver wm8994_ldo_driver = {
194 .probe = wm8994_ldo_probe, 187 .probe = wm8994_ldo_probe,
195 .remove = wm8994_ldo_remove,
196 .driver = { 188 .driver = {
197 .name = "wm8994-ldo", 189 .name = "wm8994-ldo",
198 .owner = THIS_MODULE, 190 .owner = THIS_MODULE,
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index cebe97ee98b8..7314fc4e6d25 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -59,6 +59,12 @@ struct mfd_cell {
59 * pm_runtime_no_callbacks(). 59 * pm_runtime_no_callbacks().
60 */ 60 */
61 bool pm_runtime_no_callbacks; 61 bool pm_runtime_no_callbacks;
62
63 /* A list of regulator supplies that should be mapped to the MFD
64 * device rather than the child device when requested
65 */
66 const char **parent_supplies;
67 int num_parent_supplies;
62}; 68};
63 69
64/* 70/*
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 27be915caa96..e530681bea70 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -146,6 +146,32 @@ struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
146void regulator_put(struct regulator *regulator); 146void regulator_put(struct regulator *regulator);
147void devm_regulator_put(struct regulator *regulator); 147void devm_regulator_put(struct regulator *regulator);
148 148
149int regulator_register_supply_alias(struct device *dev, const char *id,
150 struct device *alias_dev,
151 const char *alias_id);
152void regulator_unregister_supply_alias(struct device *dev, const char *id);
153
154int regulator_bulk_register_supply_alias(struct device *dev, const char **id,
155 struct device *alias_dev,
156 const char **alias_id, int num_id);
157void regulator_bulk_unregister_supply_alias(struct device *dev,
158 const char **id, int num_id);
159
160int devm_regulator_register_supply_alias(struct device *dev, const char *id,
161 struct device *alias_dev,
162 const char *alias_id);
163void devm_regulator_unregister_supply_alias(struct device *dev,
164 const char *id);
165
166int devm_regulator_bulk_register_supply_alias(struct device *dev,
167 const char **id,
168 struct device *alias_dev,
169 const char **alias_id,
170 int num_id);
171void devm_regulator_bulk_unregister_supply_alias(struct device *dev,
172 const char **id,
173 int num_id);
174
149/* regulator output control and status */ 175/* regulator output control and status */
150int __must_check regulator_enable(struct regulator *regulator); 176int __must_check regulator_enable(struct regulator *regulator);
151int regulator_disable(struct regulator *regulator); 177int regulator_disable(struct regulator *regulator);
@@ -250,6 +276,59 @@ static inline void devm_regulator_put(struct regulator *regulator)
250{ 276{
251} 277}
252 278
279static inline int regulator_register_supply_alias(struct device *dev,
280 const char *id,
281 struct device *alias_dev,
282 const char *alias_id)
283{
284 return 0;
285}
286
287static inline void regulator_unregister_supply_alias(struct device *dev,
288 const char *id)
289{
290}
291
292static inline int regulator_bulk_register_supply_alias(struct device *dev,
293 const char **id,
294 struct device *alias_dev,
295 const char **alias_id,
296 int num_id)
297{
298 return 0;
299}
300
301static inline void regulator_bulk_unregister_supply_alias(struct device *dev,
302 const char **id,
303 int num_id)
304{
305}
306
307static inline int devm_regulator_register_supply_alias(struct device *dev,
308 const char *id,
309 struct device *alias_dev,
310 const char *alias_id)
311{
312 return 0;
313}
314
315static inline void devm_regulator_unregister_supply_alias(struct device *dev,
316 const char *id)
317{
318}
319
320static inline int devm_regulator_bulk_register_supply_alias(
321 struct device *dev, const char **id, struct device *alias_dev,
322 const char **alias_id, int num_id)
323{
324 return 0;
325}
326
327static inline void devm_regulator_bulk_unregister_supply_alias(
328 struct device *dev, const char **id, int num_id)
329{
330}
331
253static inline int regulator_enable(struct regulator *regulator) 332static inline int regulator_enable(struct regulator *regulator)
254{ 333{
255 return 0; 334 return 0;
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 9bdad43ad228..9370e65348a4 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -46,19 +46,26 @@ enum regulator_status {
46 * regulator_list_linear_range(). 46 * regulator_list_linear_range().
47 * 47 *
48 * @min_uV: Lowest voltage in range 48 * @min_uV: Lowest voltage in range
49 * @max_uV: Highest voltage in range
50 * @min_sel: Lowest selector for range 49 * @min_sel: Lowest selector for range
51 * @max_sel: Highest selector for range 50 * @max_sel: Highest selector for range
52 * @uV_step: Step size 51 * @uV_step: Step size
53 */ 52 */
54struct regulator_linear_range { 53struct regulator_linear_range {
55 unsigned int min_uV; 54 unsigned int min_uV;
56 unsigned int max_uV;
57 unsigned int min_sel; 55 unsigned int min_sel;
58 unsigned int max_sel; 56 unsigned int max_sel;
59 unsigned int uV_step; 57 unsigned int uV_step;
60}; 58};
61 59
60/* Initialize struct regulator_linear_range */
61#define REGULATOR_LINEAR_RANGE(_min_uV, _min_sel, _max_sel, _step_uV) \
62{ \
63 .min_uV = _min_uV, \
64 .min_sel = _min_sel, \
65 .max_sel = _max_sel, \
66 .uV_step = _step_uV, \
67}
68
62/** 69/**
63 * struct regulator_ops - regulator operations. 70 * struct regulator_ops - regulator operations.
64 * 71 *
@@ -209,6 +216,7 @@ enum regulator_type {
209 * @min_uV: Voltage given by the lowest selector (if linear mapping) 216 * @min_uV: Voltage given by the lowest selector (if linear mapping)
210 * @uV_step: Voltage increase with each selector (if linear mapping) 217 * @uV_step: Voltage increase with each selector (if linear mapping)
211 * @linear_min_sel: Minimal selector for starting linear mapping 218 * @linear_min_sel: Minimal selector for starting linear mapping
219 * @fixed_uV: Fixed voltage of rails.
212 * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 220 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
213 * @volt_table: Voltage mapping table (if table based mapping) 221 * @volt_table: Voltage mapping table (if table based mapping)
214 * 222 *
@@ -241,6 +249,7 @@ struct regulator_desc {
241 unsigned int min_uV; 249 unsigned int min_uV;
242 unsigned int uV_step; 250 unsigned int uV_step;
243 unsigned int linear_min_sel; 251 unsigned int linear_min_sel;
252 int fixed_uV;
244 unsigned int ramp_delay; 253 unsigned int ramp_delay;
245 254
246 const struct regulator_linear_range *linear_ranges; 255 const struct regulator_linear_range *linear_ranges;
@@ -336,7 +345,12 @@ struct regulator_dev {
336struct regulator_dev * 345struct regulator_dev *
337regulator_register(const struct regulator_desc *regulator_desc, 346regulator_register(const struct regulator_desc *regulator_desc,
338 const struct regulator_config *config); 347 const struct regulator_config *config);
348struct regulator_dev *
349devm_regulator_register(struct device *dev,
350 const struct regulator_desc *regulator_desc,
351 const struct regulator_config *config);
339void regulator_unregister(struct regulator_dev *rdev); 352void regulator_unregister(struct regulator_dev *rdev);
353void devm_regulator_unregister(struct device *dev, struct regulator_dev *rdev);
340 354
341int regulator_notifier_call_chain(struct regulator_dev *rdev, 355int regulator_notifier_call_chain(struct regulator_dev *rdev,
342 unsigned long event, void *data); 356 unsigned long event, void *data);
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 999b20ce06cf..730e638c5589 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -95,6 +95,7 @@ struct regulator_state {
95 * @initial_state: Suspend state to set by default. 95 * @initial_state: Suspend state to set by default.
96 * @initial_mode: Mode to set at startup. 96 * @initial_mode: Mode to set at startup.
97 * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 97 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
98 * @enable_time: Turn-on time of the rails (unit: microseconds)
98 */ 99 */
99struct regulation_constraints { 100struct regulation_constraints {
100 101
@@ -129,6 +130,7 @@ struct regulation_constraints {
129 unsigned int initial_mode; 130 unsigned int initial_mode;
130 131
131 unsigned int ramp_delay; 132 unsigned int ramp_delay;
133 unsigned int enable_time;
132 134
133 /* constraint flags */ 135 /* constraint flags */
134 unsigned always_on:1; /* regulator never off when system is on */ 136 unsigned always_on:1; /* regulator never off when system is on */
@@ -193,15 +195,10 @@ int regulator_suspend_finish(void);
193 195
194#ifdef CONFIG_REGULATOR 196#ifdef CONFIG_REGULATOR
195void regulator_has_full_constraints(void); 197void regulator_has_full_constraints(void);
196void regulator_use_dummy_regulator(void);
197#else 198#else
198static inline void regulator_has_full_constraints(void) 199static inline void regulator_has_full_constraints(void)
199{ 200{
200} 201}
201
202static inline void regulator_use_dummy_regulator(void)
203{
204}
205#endif 202#endif
206 203
207#endif 204#endif