aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-09-03 13:09:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-03 13:09:29 -0400
commitec1882a9391c55332ebf3d1654f40b76e4a6c010 (patch)
treea72da16d78b1a62e6f4ee01444dd93f0d7a296c1
parent5d3fed701d75ac6888f892ea2eb7c5dcc7831750 (diff)
parenta584862221426f461f56674d30fe0d712ee63d00 (diff)
Merge tag 'regulator-v3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown: "Not much exciting going on with the regulator API this time around, lots of driver fixes and enhancements - the main thing is the addition of a new API to help make the stubbing code do the right thing for missing regulator mappings. Highlights: - A new regulator_get_optional() API call for regulators that can be absent in normal operation. This currently does nothing but will be used to improve the stubbing code for unspecified regulators, helping avoid some of the issues we've seen with adding new regulator support. - Helpers for devices with multiple linear ranges of voltages in the same regulator. - Moved the helpers into a separate file since core.c is getting rather large. - New drivers for Dialog DA9210 and DA9063, Freescale pfuze100 and Marvell 88pm800" * tag 'regulator-v3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (70 commits) regulator: da9063: Statize da9063_ldo_lim_event regulator: lp872x: Make REGULATOR_LP872X depend on I2C rather than I2C=y regulator: tps65217: Convert to use linear ranges regulator: da9063: Use IS_ERR to check return value of regulator_register() regulator: da9063: Optimize da9063_set_current_limit implementation regulator: build: Allow most regulators to be built as modules regulator: Add devm_regulator_get_exclusive() regulator: da9063: Add Dialog DA9063 voltage regulators support. regulator: ti-abb: simplify platform_get_resource_byname/devm_ioremap_resource hwmon: (sht15) Use devm_regulator_get_optional() regulator: core: Use bool for exclusivitity flag regulator: 88pm800: forever loop in pm800_regulator_probe() cpufreq: cpufreq-cpu0: Use devm_regulator_get_optional() regulator: da9210: Remove redundant MODULE_ALIAS regulator: 88pm800: Fix checking whether num_regulator is valid regulator: s2mps11: Fix setting ramp_delay regulator: s2mps11: Fix wrong arguments for regmap_update_bits() call regulator: palmas: Update the DT binding doc for smps10 out1 and out2 regulator: palmas: model SMPS10 as two regulators regulator: core: Move list_voltage_{linear,linear_range,table} to helpers.c ...
-rw-r--r--Documentation/devicetree/bindings/regulator/88pm800.txt38
-rw-r--r--Documentation/devicetree/bindings/regulator/max8660.txt47
-rw-r--r--Documentation/devicetree/bindings/regulator/palmas-pmic.txt4
-rw-r--r--Documentation/devicetree/bindings/regulator/pfuze100.txt115
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt2
-rw-r--r--drivers/cpufreq/cpufreq-cpu0.c2
-rw-r--r--drivers/hwmon/sht15.c2
-rw-r--r--drivers/mmc/core/core.c2
-rw-r--r--drivers/mmc/host/dw_mmc.c2
-rw-r--r--drivers/mmc/host/pxamci.c2
-rw-r--r--drivers/mmc/host/sdhci.c4
-rw-r--r--drivers/regulator/88pm800.c383
-rw-r--r--drivers/regulator/88pm8607.c2
-rw-r--r--drivers/regulator/Kconfig284
-rw-r--r--drivers/regulator/Makefile8
-rw-r--r--drivers/regulator/aat2870-regulator.c2
-rw-r--r--drivers/regulator/ab3100.c2
-rw-r--r--drivers/regulator/ad5398.c2
-rw-r--r--drivers/regulator/as3711-regulator.c163
-rw-r--r--drivers/regulator/core.c472
-rw-r--r--drivers/regulator/da903x.c47
-rw-r--r--drivers/regulator/da9052-regulator.c2
-rw-r--r--drivers/regulator/da9055-regulator.c2
-rw-r--r--drivers/regulator/da9063-regulator.c934
-rw-r--r--drivers/regulator/da9210-regulator.c196
-rw-r--r--drivers/regulator/da9210-regulator.h288
-rw-r--r--drivers/regulator/fan53555.c2
-rw-r--r--drivers/regulator/fixed.c2
-rw-r--r--drivers/regulator/gpio-regulator.c2
-rw-r--r--drivers/regulator/helpers.c447
-rw-r--r--drivers/regulator/isl6271a-regulator.c2
-rw-r--r--drivers/regulator/lp3971.c2
-rw-r--r--drivers/regulator/lp3972.c2
-rw-r--r--drivers/regulator/lp872x.c11
-rw-r--r--drivers/regulator/lp8755.c3
-rw-r--r--drivers/regulator/max1586.c2
-rw-r--r--drivers/regulator/max8649.c2
-rw-r--r--drivers/regulator/max8660.c108
-rw-r--r--drivers/regulator/max8925-regulator.c2
-rw-r--r--drivers/regulator/max8952.c2
-rw-r--r--drivers/regulator/max8973-regulator.c2
-rw-r--r--drivers/regulator/of_regulator.c12
-rw-r--r--drivers/regulator/palmas-regulator.c32
-rw-r--r--drivers/regulator/pcap-regulator.c2
-rw-r--r--drivers/regulator/pcf50633-regulator.c2
-rw-r--r--drivers/regulator/pfuze100-regulator.c445
-rw-r--r--drivers/regulator/s2mps11.c245
-rw-r--r--drivers/regulator/ti-abb-regulator.c10
-rw-r--r--drivers/regulator/tps51632-regulator.c2
-rw-r--r--drivers/regulator/tps62360-regulator.c2
-rw-r--r--drivers/regulator/tps65023-regulator.c2
-rw-r--r--drivers/regulator/tps65217-regulator.c182
-rw-r--r--drivers/regulator/tps6524x-regulator.c2
-rw-r--r--drivers/regulator/tps65912-regulator.c39
-rw-r--r--drivers/regulator/twl-regulator.c2
-rw-r--r--drivers/regulator/userspace-consumer.c2
-rw-r--r--drivers/regulator/virtual.c2
-rw-r--r--drivers/regulator/wm831x-dcdc.c8
-rw-r--r--drivers/regulator/wm831x-isink.c2
-rw-r--r--drivers/regulator/wm831x-ldo.c110
-rw-r--r--drivers/regulator/wm8350-regulator.c57
-rw-r--r--drivers/regulator/wm8400-regulator.c52
-rw-r--r--drivers/regulator/wm8994-regulator.c2
-rw-r--r--include/linux/mfd/palmas.h9
-rw-r--r--include/linux/mfd/samsung/s2mps11.h11
-rw-r--r--include/linux/mfd/tps65217.h19
-rw-r--r--include/linux/regulator/consumer.h32
-rw-r--r--include/linux/regulator/driver.h25
-rw-r--r--include/linux/regulator/fan53555.h1
-rw-r--r--include/linux/regulator/machine.h1
-rw-r--r--include/linux/regulator/max8660.h2
-rw-r--r--include/linux/regulator/pfuze100.h44
72 files changed, 3840 insertions, 1116 deletions
diff --git a/Documentation/devicetree/bindings/regulator/88pm800.txt b/Documentation/devicetree/bindings/regulator/88pm800.txt
new file mode 100644
index 000000000000..e8a54c2a5821
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/88pm800.txt
@@ -0,0 +1,38 @@
1Marvell 88PM800 regulator
2
3Required properties:
4- compatible: "marvell,88pm800"
5- reg: I2C slave address
6- regulators: A node that houses a sub-node for each regulator within the
7 device. Each sub-node is identified using the node's name (or the deprecated
8 regulator-compatible property if present), with valid values listed below.
9 The content of each sub-node is defined by the standard binding for
10 regulators; see regulator.txt.
11
12The valid names for regulators are:
13
14 buck1, buck2, buck3, buck4, buck5, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7,
15 ldo8, ldo9, ldo10, ldo11, ldo12, ldo13, ldo14, ldo15, ldo16, ldo17, ldo18, ldo19
16
17Example:
18
19 pmic: 88pm800@31 {
20 compatible = "marvell,88pm800";
21 reg = <0x31>;
22
23 regulators {
24 buck1 {
25 regulator-min-microvolt = <600000>;
26 regulator-max-microvolt = <3950000>;
27 regulator-boot-on;
28 regulator-always-on;
29 };
30 ldo1 {
31 regulator-min-microvolt = <600000>;
32 regulator-max-microvolt = <15000000>;
33 regulator-boot-on;
34 regulator-always-on;
35 };
36...
37 };
38 };
diff --git a/Documentation/devicetree/bindings/regulator/max8660.txt b/Documentation/devicetree/bindings/regulator/max8660.txt
new file mode 100644
index 000000000000..8ba994d8a142
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/max8660.txt
@@ -0,0 +1,47 @@
1Maxim MAX8660 voltage regulator
2
3Required properties:
4- compatible: must be one of "maxim,max8660", "maxim,max8661"
5- reg: I2C slave address, usually 0x34
6- any required generic properties defined in regulator.txt
7
8Example:
9
10 i2c_master {
11 max8660@34 {
12 compatible = "maxim,max8660";
13 reg = <0x34>;
14
15 regulators {
16 regulator@0 {
17 regulator-compatible= "V3(DCDC)";
18 regulator-min-microvolt = <725000>;
19 regulator-max-microvolt = <1800000>;
20 };
21
22 regulator@1 {
23 regulator-compatible= "V4(DCDC)";
24 regulator-min-microvolt = <725000>;
25 regulator-max-microvolt = <1800000>;
26 };
27
28 regulator@2 {
29 regulator-compatible= "V5(LDO)";
30 regulator-min-microvolt = <1700000>;
31 regulator-max-microvolt = <2000000>;
32 };
33
34 regulator@3 {
35 regulator-compatible= "V6(LDO)";
36 regulator-min-microvolt = <1800000>;
37 regulator-max-microvolt = <3300000>;
38 };
39
40 regulator@4 {
41 regulator-compatible= "V7(LDO)";
42 regulator-min-microvolt = <1800000>;
43 regulator-max-microvolt = <3300000>;
44 };
45 };
46 };
47 };
diff --git a/Documentation/devicetree/bindings/regulator/palmas-pmic.txt b/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
index 30b0581bb1ce..a22e4c70db5c 100644
--- a/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
+++ b/Documentation/devicetree/bindings/regulator/palmas-pmic.txt
@@ -25,8 +25,8 @@ Optional nodes:
25 Additional custom properties are listed below. 25 Additional custom properties are listed below.
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-10], 28 smps45, smps457, smps7 depending on variant, smps6, smps[8-9],
29 ldo[1-9], ldoln, ldousb. 29 smps10_out2, smps10_out1, do[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)
diff --git a/Documentation/devicetree/bindings/regulator/pfuze100.txt b/Documentation/devicetree/bindings/regulator/pfuze100.txt
new file mode 100644
index 000000000000..fc989b2e8057
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/pfuze100.txt
@@ -0,0 +1,115 @@
1PFUZE100 family of regulators
2
3Required properties:
4- compatible: "fsl,pfuze100"
5- reg: I2C slave address
6
7Required child node:
8- regulators: This is the list of child nodes that specify the regulator
9 initialization data for defined regulators. Please refer to below doc
10 Documentation/devicetree/bindings/regulator/regulator.txt.
11
12 The valid names for regulators are:
13 sw1ab,sw1c,sw2,sw3a,sw3b,sw4,swbst,vsnvs,vrefddr,vgen1~vgen6
14
15Each regulator is defined using the standard binding for regulators.
16
17Example:
18
19 pmic: pfuze100@08 {
20 compatible = "fsl,pfuze100";
21 reg = <0x08>;
22
23 regulators {
24 sw1a_reg: sw1ab {
25 regulator-min-microvolt = <300000>;
26 regulator-max-microvolt = <1875000>;
27 regulator-boot-on;
28 regulator-always-on;
29 regulator-ramp-delay = <6250>;
30 };
31
32 sw1c_reg: sw1c {
33 regulator-min-microvolt = <300000>;
34 regulator-max-microvolt = <1875000>;
35 regulator-boot-on;
36 regulator-always-on;
37 };
38
39 sw2_reg: sw2 {
40 regulator-min-microvolt = <800000>;
41 regulator-max-microvolt = <3300000>;
42 regulator-boot-on;
43 regulator-always-on;
44 };
45
46 sw3a_reg: sw3a {
47 regulator-min-microvolt = <400000>;
48 regulator-max-microvolt = <1975000>;
49 regulator-boot-on;
50 regulator-always-on;
51 };
52
53 sw3b_reg: sw3b {
54 regulator-min-microvolt = <400000>;
55 regulator-max-microvolt = <1975000>;
56 regulator-boot-on;
57 regulator-always-on;
58 };
59
60 sw4_reg: sw4 {
61 regulator-min-microvolt = <800000>;
62 regulator-max-microvolt = <3300000>;
63 };
64
65 swbst_reg: swbst {
66 regulator-min-microvolt = <5000000>;
67 regulator-max-microvolt = <5150000>;
68 };
69
70 snvs_reg: vsnvs {
71 regulator-min-microvolt = <1000000>;
72 regulator-max-microvolt = <3000000>;
73 regulator-boot-on;
74 regulator-always-on;
75 };
76
77 vref_reg: vrefddr {
78 regulator-boot-on;
79 regulator-always-on;
80 };
81
82 vgen1_reg: vgen1 {
83 regulator-min-microvolt = <800000>;
84 regulator-max-microvolt = <1550000>;
85 };
86
87 vgen2_reg: vgen2 {
88 regulator-min-microvolt = <800000>;
89 regulator-max-microvolt = <1550000>;
90 };
91
92 vgen3_reg: vgen3 {
93 regulator-min-microvolt = <1800000>;
94 regulator-max-microvolt = <3300000>;
95 };
96
97 vgen4_reg: vgen4 {
98 regulator-min-microvolt = <1800000>;
99 regulator-max-microvolt = <3300000>;
100 regulator-always-on;
101 };
102
103 vgen5_reg: vgen5 {
104 regulator-min-microvolt = <1800000>;
105 regulator-max-microvolt = <3300000>;
106 regulator-always-on;
107 };
108
109 vgen6_reg: vgen6 {
110 regulator-min-microvolt = <1800000>;
111 regulator-max-microvolt = <3300000>;
112 regulator-always-on;
113 };
114 };
115 };
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 48a3b8e5d6bd..2bd8f0978765 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -12,6 +12,8 @@ Optional properties:
12- regulator-allow-bypass: allow the regulator to go into bypass mode 12- regulator-allow-bypass: allow the regulator to go into bypass mode
13- <name>-supply: phandle to the parent supply/regulator node 13- <name>-supply: phandle to the parent supply/regulator node
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
16 intialised to zero (regulator-ramp-delay = <0>) for disabling ramp delay.
15 17
16Deprecated properties: 18Deprecated properties:
17- regulator-compatible: If a regulator chip contains multiple 19- regulator-compatible: If a regulator chip contains multiple
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c
index ad1fde277661..e9dedb27deca 100644
--- a/drivers/cpufreq/cpufreq-cpu0.c
+++ b/drivers/cpufreq/cpufreq-cpu0.c
@@ -197,7 +197,7 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)
197 cpu_dev = &pdev->dev; 197 cpu_dev = &pdev->dev;
198 cpu_dev->of_node = np; 198 cpu_dev->of_node = np;
199 199
200 cpu_reg = devm_regulator_get(cpu_dev, "cpu0"); 200 cpu_reg = devm_regulator_get_optional(cpu_dev, "cpu0");
201 if (IS_ERR(cpu_reg)) { 201 if (IS_ERR(cpu_reg)) {
202 /* 202 /*
203 * If cpu0 regulator supply node is present, but regulator is 203 * If cpu0 regulator supply node is present, but regulator is
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
index 2507f902fb7a..ab5dc3af4cfb 100644
--- a/drivers/hwmon/sht15.c
+++ b/drivers/hwmon/sht15.c
@@ -957,7 +957,7 @@ static int sht15_probe(struct platform_device *pdev)
957 * If a regulator is available, 957 * If a regulator is available,
958 * query what the supply voltage actually is! 958 * query what the supply voltage actually is!
959 */ 959 */
960 data->reg = devm_regulator_get(data->dev, "vcc"); 960 data->reg = devm_regulator_get_optional(data->dev, "vcc");
961 if (!IS_ERR(data->reg)) { 961 if (!IS_ERR(data->reg)) {
962 int voltage; 962 int voltage;
963 963
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 49a5bca418bd..5d088551196b 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1313,7 +1313,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc)
1313 1313
1314 supply = devm_regulator_get(dev, "vmmc"); 1314 supply = devm_regulator_get(dev, "vmmc");
1315 mmc->supply.vmmc = supply; 1315 mmc->supply.vmmc = supply;
1316 mmc->supply.vqmmc = devm_regulator_get(dev, "vqmmc"); 1316 mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc");
1317 1317
1318 if (IS_ERR(supply)) 1318 if (IS_ERR(supply))
1319 return PTR_ERR(supply); 1319 return PTR_ERR(supply);
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index ee5f1676f14e..542407363dd2 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -2231,7 +2231,7 @@ int dw_mci_probe(struct dw_mci *host)
2231 } 2231 }
2232 } 2232 }
2233 2233
2234 host->vmmc = devm_regulator_get(host->dev, "vmmc"); 2234 host->vmmc = devm_regulator_get_optional(host->dev, "vmmc");
2235 if (IS_ERR(host->vmmc)) { 2235 if (IS_ERR(host->vmmc)) {
2236 ret = PTR_ERR(host->vmmc); 2236 ret = PTR_ERR(host->vmmc);
2237 if (ret == -EPROBE_DEFER) 2237 if (ret == -EPROBE_DEFER)
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 2c5a91bb8ec3..1956a3df7cf3 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -83,7 +83,7 @@ struct pxamci_host {
83static inline void pxamci_init_ocr(struct pxamci_host *host) 83static inline void pxamci_init_ocr(struct pxamci_host *host)
84{ 84{
85#ifdef CONFIG_REGULATOR 85#ifdef CONFIG_REGULATOR
86 host->vcc = regulator_get(mmc_dev(host->mmc), "vmmc"); 86 host->vcc = regulator_get_optional(mmc_dev(host->mmc), "vmmc");
87 87
88 if (IS_ERR(host->vcc)) 88 if (IS_ERR(host->vcc))
89 host->vcc = NULL; 89 host->vcc = NULL;
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index a78bd4f3aecc..dd2c083c434d 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -2966,7 +2966,7 @@ int sdhci_add_host(struct sdhci_host *host)
2966 mmc->caps |= MMC_CAP_NEEDS_POLL; 2966 mmc->caps |= MMC_CAP_NEEDS_POLL;
2967 2967
2968 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ 2968 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
2969 host->vqmmc = regulator_get(mmc_dev(mmc), "vqmmc"); 2969 host->vqmmc = regulator_get_optional(mmc_dev(mmc), "vqmmc");
2970 if (IS_ERR_OR_NULL(host->vqmmc)) { 2970 if (IS_ERR_OR_NULL(host->vqmmc)) {
2971 if (PTR_ERR(host->vqmmc) < 0) { 2971 if (PTR_ERR(host->vqmmc) < 0) {
2972 pr_info("%s: no vqmmc regulator found\n", 2972 pr_info("%s: no vqmmc regulator found\n",
@@ -3042,7 +3042,7 @@ int sdhci_add_host(struct sdhci_host *host)
3042 3042
3043 ocr_avail = 0; 3043 ocr_avail = 0;
3044 3044
3045 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); 3045 host->vmmc = regulator_get_optional(mmc_dev(mmc), "vmmc");
3046 if (IS_ERR_OR_NULL(host->vmmc)) { 3046 if (IS_ERR_OR_NULL(host->vmmc)) {
3047 if (PTR_ERR(host->vmmc) < 0) { 3047 if (PTR_ERR(host->vmmc) < 0) {
3048 pr_info("%s: no vmmc regulator found\n", 3048 pr_info("%s: no vmmc regulator found\n",
diff --git a/drivers/regulator/88pm800.c b/drivers/regulator/88pm800.c
new file mode 100644
index 000000000000..3459f60dcfd1
--- /dev/null
+++ b/drivers/regulator/88pm800.c
@@ -0,0 +1,383 @@
1/*
2 * Regulators driver for Marvell 88PM800
3 *
4 * Copyright (C) 2012 Marvell International Ltd.
5 * Joseph(Yossi) Hanin <yhanin@marvell.com>
6 * Yi Zhang <yizhang@marvell.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/init.h>
15#include <linux/err.h>
16#include <linux/regmap.h>
17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h>
19#include <linux/mfd/88pm80x.h>
20#include <linux/delay.h>
21#include <linux/io.h>
22#include <linux/of.h>
23#include <linux/regulator/of_regulator.h>
24
25/* LDO1 with DVC[0..3] */
26#define PM800_LDO1_VOUT (0x08) /* VOUT1 */
27#define PM800_LDO1_VOUT_2 (0x09)
28#define PM800_LDO1_VOUT_3 (0x0A)
29#define PM800_LDO2_VOUT (0x0B)
30#define PM800_LDO3_VOUT (0x0C)
31#define PM800_LDO4_VOUT (0x0D)
32#define PM800_LDO5_VOUT (0x0E)
33#define PM800_LDO6_VOUT (0x0F)
34#define PM800_LDO7_VOUT (0x10)
35#define PM800_LDO8_VOUT (0x11)
36#define PM800_LDO9_VOUT (0x12)
37#define PM800_LDO10_VOUT (0x13)
38#define PM800_LDO11_VOUT (0x14)
39#define PM800_LDO12_VOUT (0x15)
40#define PM800_LDO13_VOUT (0x16)
41#define PM800_LDO14_VOUT (0x17)
42#define PM800_LDO15_VOUT (0x18)
43#define PM800_LDO16_VOUT (0x19)
44#define PM800_LDO17_VOUT (0x1A)
45#define PM800_LDO18_VOUT (0x1B)
46#define PM800_LDO19_VOUT (0x1C)
47
48/* BUCK1 with DVC[0..3] */
49#define PM800_BUCK1 (0x3C)
50#define PM800_BUCK1_1 (0x3D)
51#define PM800_BUCK1_2 (0x3E)
52#define PM800_BUCK1_3 (0x3F)
53#define PM800_BUCK2 (0x40)
54#define PM800_BUCK3 (0x41)
55#define PM800_BUCK3 (0x41)
56#define PM800_BUCK4 (0x42)
57#define PM800_BUCK4_1 (0x43)
58#define PM800_BUCK4_2 (0x44)
59#define PM800_BUCK4_3 (0x45)
60#define PM800_BUCK5 (0x46)
61
62#define PM800_BUCK_ENA (0x50)
63#define PM800_LDO_ENA1_1 (0x51)
64#define PM800_LDO_ENA1_2 (0x52)
65#define PM800_LDO_ENA1_3 (0x53)
66
67#define PM800_LDO_ENA2_1 (0x56)
68#define PM800_LDO_ENA2_2 (0x57)
69#define PM800_LDO_ENA2_3 (0x58)
70
71#define PM800_BUCK1_MISC1 (0x78)
72#define PM800_BUCK3_MISC1 (0x7E)
73#define PM800_BUCK4_MISC1 (0x81)
74#define PM800_BUCK5_MISC1 (0x84)
75
76struct pm800_regulator_info {
77 struct regulator_desc desc;
78 int max_ua;
79};
80
81struct pm800_regulators {
82 struct regulator_dev *regulators[PM800_ID_RG_MAX];
83 struct pm80x_chip *chip;
84 struct regmap *map;
85};
86
87/*
88 * vreg - the buck regs string.
89 * ereg - the string for the enable register.
90 * ebit - the bit number in the enable register.
91 * amax - the current
92 * Buck has 2 kinds of voltage steps. It is easy to find voltage by ranges,
93 * not the constant voltage table.
94 * n_volt - Number of available selectors
95 */
96#define PM800_BUCK(vreg, ereg, ebit, amax, volt_ranges, n_volt) \
97{ \
98 .desc = { \
99 .name = #vreg, \
100 .ops = &pm800_volt_range_ops, \
101 .type = REGULATOR_VOLTAGE, \
102 .id = PM800_ID_##vreg, \
103 .owner = THIS_MODULE, \
104 .n_voltages = n_volt, \
105 .linear_ranges = volt_ranges, \
106 .n_linear_ranges = ARRAY_SIZE(volt_ranges), \
107 .vsel_reg = PM800_##vreg, \
108 .vsel_mask = 0x7f, \
109 .enable_reg = PM800_##ereg, \
110 .enable_mask = 1 << (ebit), \
111 }, \
112 .max_ua = (amax), \
113}
114
115/*
116 * vreg - the LDO regs string
117 * ereg - the string for the enable register.
118 * ebit - the bit number in the enable register.
119 * amax - the current
120 * volt_table - the LDO voltage table
121 * For all the LDOes, there are too many ranges. Using volt_table will be
122 * simpler and faster.
123 */
124#define PM800_LDO(vreg, ereg, ebit, amax, ldo_volt_table) \
125{ \
126 .desc = { \
127 .name = #vreg, \
128 .ops = &pm800_volt_table_ops, \
129 .type = REGULATOR_VOLTAGE, \
130 .id = PM800_ID_##vreg, \
131 .owner = THIS_MODULE, \
132 .n_voltages = ARRAY_SIZE(ldo_volt_table), \
133 .vsel_reg = PM800_##vreg##_VOUT, \
134 .vsel_mask = 0x1f, \
135 .enable_reg = PM800_##ereg, \
136 .enable_mask = 1 << (ebit), \
137 .volt_table = ldo_volt_table, \
138 }, \
139 .max_ua = (amax), \
140}
141
142/* Ranges are sorted in ascending order. */
143static const struct regulator_linear_range buck1_volt_range[] = {
144 { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f,
145 .uV_step = 12500 },
146 { .min_uV = 1600000, .max_uV = 1800000, .min_sel = 0x50,
147 .max_sel = 0x54, .uV_step = 50000 },
148};
149
150/* BUCK 2~5 have same ranges. */
151static const struct regulator_linear_range buck2_5_volt_range[] = {
152 { .min_uV = 600000, .max_uV = 1587500, .min_sel = 0, .max_sel = 0x4f,
153 .uV_step = 12500 },
154 { .min_uV = 1600000, .max_uV = 3300000, .min_sel = 0x50,
155 .max_sel = 0x72, .uV_step = 50000 },
156};
157
158static const unsigned int ldo1_volt_table[] = {
159 600000, 650000, 700000, 750000, 800000, 850000, 900000, 950000,
160 1000000, 1050000, 1100000, 1150000, 1200000, 1300000, 1400000, 1500000,
161};
162
163static const unsigned int ldo2_volt_table[] = {
164 1700000, 1800000, 1900000, 2000000, 2100000, 2500000, 2700000, 2800000,
165};
166
167/* LDO 3~17 have same voltage table. */
168static const unsigned int ldo3_17_volt_table[] = {
169 1200000, 1250000, 1700000, 1800000, 1850000, 1900000, 2500000, 2600000,
170 2700000, 2750000, 2800000, 2850000, 2900000, 3000000, 3100000, 3300000,
171};
172
173/* LDO 18~19 have same voltage table. */
174static const unsigned int ldo18_19_volt_table[] = {
175 1700000, 1800000, 1900000, 2500000, 2800000, 2900000, 3100000, 3300000,
176};
177
178static int pm800_get_current_limit(struct regulator_dev *rdev)
179{
180 struct pm800_regulator_info *info = rdev_get_drvdata(rdev);
181
182 return info->max_ua;
183}
184
185static struct regulator_ops pm800_volt_range_ops = {
186 .list_voltage = regulator_list_voltage_linear_range,
187 .map_voltage = regulator_map_voltage_linear_range,
188 .set_voltage_sel = regulator_set_voltage_sel_regmap,
189 .get_voltage_sel = regulator_get_voltage_sel_regmap,
190 .enable = regulator_enable_regmap,
191 .disable = regulator_disable_regmap,
192 .is_enabled = regulator_is_enabled_regmap,
193 .get_current_limit = pm800_get_current_limit,
194};
195
196static struct regulator_ops pm800_volt_table_ops = {
197 .list_voltage = regulator_list_voltage_table,
198 .map_voltage = regulator_map_voltage_iterate,
199 .set_voltage_sel = regulator_set_voltage_sel_regmap,
200 .get_voltage_sel = regulator_get_voltage_sel_regmap,
201 .enable = regulator_enable_regmap,
202 .disable = regulator_disable_regmap,
203 .is_enabled = regulator_is_enabled_regmap,
204 .get_current_limit = pm800_get_current_limit,
205};
206
207/* The array is indexed by id(PM800_ID_XXX) */
208static struct pm800_regulator_info pm800_regulator_info[] = {
209 PM800_BUCK(BUCK1, BUCK_ENA, 0, 3000000, buck1_volt_range, 0x55),
210 PM800_BUCK(BUCK2, BUCK_ENA, 1, 1200000, buck2_5_volt_range, 0x73),
211 PM800_BUCK(BUCK3, BUCK_ENA, 2, 1200000, buck2_5_volt_range, 0x73),
212 PM800_BUCK(BUCK4, BUCK_ENA, 3, 1200000, buck2_5_volt_range, 0x73),
213 PM800_BUCK(BUCK5, BUCK_ENA, 4, 1200000, buck2_5_volt_range, 0x73),
214
215 PM800_LDO(LDO1, LDO_ENA1_1, 0, 200000, ldo1_volt_table),
216 PM800_LDO(LDO2, LDO_ENA1_1, 1, 10000, ldo2_volt_table),
217 PM800_LDO(LDO3, LDO_ENA1_1, 2, 300000, ldo3_17_volt_table),
218 PM800_LDO(LDO4, LDO_ENA1_1, 3, 300000, ldo3_17_volt_table),
219 PM800_LDO(LDO5, LDO_ENA1_1, 4, 300000, ldo3_17_volt_table),
220 PM800_LDO(LDO6, LDO_ENA1_1, 5, 300000, ldo3_17_volt_table),
221 PM800_LDO(LDO7, LDO_ENA1_1, 6, 300000, ldo3_17_volt_table),
222 PM800_LDO(LDO8, LDO_ENA1_1, 7, 300000, ldo3_17_volt_table),
223 PM800_LDO(LDO9, LDO_ENA1_2, 0, 300000, ldo3_17_volt_table),
224 PM800_LDO(LDO10, LDO_ENA1_2, 1, 300000, ldo3_17_volt_table),
225 PM800_LDO(LDO11, LDO_ENA1_2, 2, 300000, ldo3_17_volt_table),
226 PM800_LDO(LDO12, LDO_ENA1_2, 3, 300000, ldo3_17_volt_table),
227 PM800_LDO(LDO13, LDO_ENA1_2, 4, 300000, ldo3_17_volt_table),
228 PM800_LDO(LDO14, LDO_ENA1_2, 5, 300000, ldo3_17_volt_table),
229 PM800_LDO(LDO15, LDO_ENA1_2, 6, 300000, ldo3_17_volt_table),
230 PM800_LDO(LDO16, LDO_ENA1_2, 7, 300000, ldo3_17_volt_table),
231 PM800_LDO(LDO17, LDO_ENA1_3, 0, 300000, ldo3_17_volt_table),
232 PM800_LDO(LDO18, LDO_ENA1_3, 1, 200000, ldo18_19_volt_table),
233 PM800_LDO(LDO19, LDO_ENA1_3, 2, 200000, ldo18_19_volt_table),
234};
235
236#define PM800_REGULATOR_OF_MATCH(_name, _id) \
237 [PM800_ID_##_id] = { \
238 .name = #_name, \
239 .driver_data = &pm800_regulator_info[PM800_ID_##_id], \
240 }
241
242static struct of_regulator_match pm800_regulator_matches[] = {
243 PM800_REGULATOR_OF_MATCH(buck1, BUCK1),
244 PM800_REGULATOR_OF_MATCH(buck2, BUCK2),
245 PM800_REGULATOR_OF_MATCH(buck3, BUCK3),
246 PM800_REGULATOR_OF_MATCH(buck4, BUCK4),
247 PM800_REGULATOR_OF_MATCH(buck5, BUCK5),
248 PM800_REGULATOR_OF_MATCH(ldo1, LDO1),
249 PM800_REGULATOR_OF_MATCH(ldo2, LDO2),
250 PM800_REGULATOR_OF_MATCH(ldo3, LDO3),
251 PM800_REGULATOR_OF_MATCH(ldo4, LDO4),
252 PM800_REGULATOR_OF_MATCH(ldo5, LDO5),
253 PM800_REGULATOR_OF_MATCH(ldo6, LDO6),
254 PM800_REGULATOR_OF_MATCH(ldo7, LDO7),
255 PM800_REGULATOR_OF_MATCH(ldo8, LDO8),
256 PM800_REGULATOR_OF_MATCH(ldo9, LDO9),
257 PM800_REGULATOR_OF_MATCH(ldo10, LDO10),
258 PM800_REGULATOR_OF_MATCH(ldo11, LDO11),
259 PM800_REGULATOR_OF_MATCH(ldo12, LDO12),
260 PM800_REGULATOR_OF_MATCH(ldo13, LDO13),
261 PM800_REGULATOR_OF_MATCH(ldo14, LDO14),
262 PM800_REGULATOR_OF_MATCH(ldo15, LDO15),
263 PM800_REGULATOR_OF_MATCH(ldo16, LDO16),
264 PM800_REGULATOR_OF_MATCH(ldo17, LDO17),
265 PM800_REGULATOR_OF_MATCH(ldo18, LDO18),
266 PM800_REGULATOR_OF_MATCH(ldo19, LDO19),
267};
268
269static int pm800_regulator_dt_init(struct platform_device *pdev)
270{
271 struct device_node *np = pdev->dev.of_node;
272 int ret;
273
274 ret = of_regulator_match(&pdev->dev, np,
275 pm800_regulator_matches,
276 ARRAY_SIZE(pm800_regulator_matches));
277 if (ret < 0)
278 return ret;
279
280 return 0;
281}
282
283static int pm800_regulator_probe(struct platform_device *pdev)
284{
285 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
286 struct pm80x_platform_data *pdata = dev_get_platdata(pdev->dev.parent);
287 struct pm800_regulators *pm800_data;
288 struct pm800_regulator_info *info;
289 struct regulator_config config = { };
290 struct regulator_init_data *init_data;
291 int i, ret;
292
293 if (!pdata || pdata->num_regulators == 0) {
294 if (IS_ENABLED(CONFIG_OF)) {
295 ret = pm800_regulator_dt_init(pdev);
296 if (ret)
297 return ret;
298 } else {
299 return -ENODEV;
300 }
301 } else if (pdata->num_regulators) {
302 unsigned int count = 0;
303
304 /* Check whether num_regulator is valid. */
305 for (i = 0; i < ARRAY_SIZE(pdata->regulators); i++) {
306 if (pdata->regulators[i])
307 count++;
308 }
309 if (count != pdata->num_regulators)
310 return -EINVAL;
311 } else {
312 return -EINVAL;
313 }
314
315 pm800_data = devm_kzalloc(&pdev->dev, sizeof(*pm800_data),
316 GFP_KERNEL);
317 if (!pm800_data) {
318 dev_err(&pdev->dev, "Failed to allocate pm800_regualtors");
319 return -ENOMEM;
320 }
321
322 pm800_data->map = chip->subchip->regmap_power;
323 pm800_data->chip = chip;
324
325 platform_set_drvdata(pdev, pm800_data);
326
327 for (i = 0; i < PM800_ID_RG_MAX; i++) {
328 if (!pdata || pdata->num_regulators == 0)
329 init_data = pm800_regulator_matches[i].init_data;
330 else
331 init_data = pdata->regulators[i];
332 if (!init_data)
333 continue;
334 info = pm800_regulator_matches[i].driver_data;
335 config.dev = &pdev->dev;
336 config.init_data = init_data;
337 config.driver_data = info;
338 config.regmap = pm800_data->map;
339 config.of_node = pm800_regulator_matches[i].of_node;
340
341 pm800_data->regulators[i] =
342 regulator_register(&info->desc, &config);
343 if (IS_ERR(pm800_data->regulators[i])) {
344 ret = PTR_ERR(pm800_data->regulators[i]);
345 dev_err(&pdev->dev, "Failed to register %s\n",
346 info->desc.name);
347
348 while (--i >= 0)
349 regulator_unregister(pm800_data->regulators[i]);
350
351 return ret;
352 }
353 }
354
355 return 0;
356}
357
358static int pm800_regulator_remove(struct platform_device *pdev)
359{
360 struct pm800_regulators *pm800_data = platform_get_drvdata(pdev);
361 int i;
362
363 for (i = 0; i < PM800_ID_RG_MAX; i++)
364 regulator_unregister(pm800_data->regulators[i]);
365
366 return 0;
367}
368
369static struct platform_driver pm800_regulator_driver = {
370 .driver = {
371 .name = "88pm80x-regulator",
372 .owner = THIS_MODULE,
373 },
374 .probe = pm800_regulator_probe,
375 .remove = pm800_regulator_remove,
376};
377
378module_platform_driver(pm800_regulator_driver);
379
380MODULE_LICENSE("GPL");
381MODULE_AUTHOR("Joseph(Yossi) Hanin <yhanin@marvell.com>");
382MODULE_DESCRIPTION("Regulator Driver for Marvell 88PM800 PMIC");
383MODULE_ALIAS("platform:88pm800-regulator");
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 8a7cb1f43046..70230974468c 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -346,7 +346,7 @@ static int pm8607_regulator_probe(struct platform_device *pdev)
346{ 346{
347 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); 347 struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
348 struct pm8607_regulator_info *info = NULL; 348 struct pm8607_regulator_info *info = NULL;
349 struct regulator_init_data *pdata = pdev->dev.platform_data; 349 struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
350 struct regulator_config config = { }; 350 struct regulator_config config = { };
351 struct resource *res; 351 struct resource *res;
352 int i; 352 int i;
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index f1e6ad98eeba..dfe58096b374 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -64,15 +64,21 @@ config REGULATOR_USERSPACE_CONSUMER
64 64
65 If unsure, say no. 65 If unsure, say no.
66 66
67config REGULATOR_GPIO 67config REGULATOR_88PM800
68 tristate "GPIO regulator support" 68 tristate "Marvell 88PM800 Power regulators"
69 depends on GPIOLIB 69 depends on MFD_88PM800
70 help 70 help
71 This driver provides support for regulators that can be 71 This driver supports Marvell 88PM800 voltage regulator chips.
72 controlled via gpios. 72 It delivers digitally programmable output,
73 It is capable of supporting current and voltage regulators 73 the voltage is programmed via I2C interface.
74 and the platform has to provide a mapping of GPIO-states 74 It's suitable to support PXA988 chips to control VCC_MAIN and
75 to target volts/amps. 75 various voltages.
76
77config REGULATOR_88PM8607
78 tristate "Marvell 88PM8607 Power regulators"
79 depends on MFD_88PM860X=y
80 help
81 This driver supports 88PM8607 voltage regulator chips.
76 82
77config REGULATOR_AD5398 83config REGULATOR_AD5398
78 tristate "Analog Devices AD5398/AD5821 regulators" 84 tristate "Analog Devices AD5398/AD5821 regulators"
@@ -81,6 +87,14 @@ config REGULATOR_AD5398
81 This driver supports AD5398 and AD5821 current regulator chips. 87 This driver supports AD5398 and AD5821 current regulator chips.
82 If building into module, its name is ad5398.ko. 88 If building into module, its name is ad5398.ko.
83 89
90config REGULATOR_ANATOP
91 tristate "Freescale i.MX on-chip ANATOP LDO regulators"
92 depends on MFD_SYSCON
93 help
94 Say y here to support Freescale i.MX on-chip ANATOP LDOs
95 regulators. It is recommended that this option be
96 enabled on i.MX6 platform.
97
84config REGULATOR_AAT2870 98config REGULATOR_AAT2870
85 tristate "AnalogicTech AAT2870 Regulators" 99 tristate "AnalogicTech AAT2870 Regulators"
86 depends on MFD_AAT2870_CORE 100 depends on MFD_AAT2870_CORE
@@ -88,6 +102,22 @@ config REGULATOR_AAT2870
88 If you have a AnalogicTech AAT2870 say Y to enable the 102 If you have a AnalogicTech AAT2870 say Y to enable the
89 regulator driver. 103 regulator driver.
90 104
105config REGULATOR_AB3100
106 tristate "ST-Ericsson AB3100 Regulator functions"
107 depends on AB3100_CORE
108 default y if AB3100_CORE
109 help
110 These regulators correspond to functionality in the
111 AB3100 analog baseband dealing with power regulators
112 for the system.
113
114config REGULATOR_AB8500
115 bool "ST-Ericsson AB8500 Power Regulators"
116 depends on AB8500_CORE
117 help
118 This driver supports the regulators found on the ST-Ericsson mixed
119 signal AB8500 PMIC
120
91config REGULATOR_ARIZONA 121config REGULATOR_ARIZONA
92 tristate "Wolfson Arizona class devices" 122 tristate "Wolfson Arizona class devices"
93 depends on MFD_ARIZONA 123 depends on MFD_ARIZONA
@@ -96,6 +126,13 @@ config REGULATOR_ARIZONA
96 Support for the regulators found on Wolfson Arizona class 126 Support for the regulators found on Wolfson Arizona class
97 devices. 127 devices.
98 128
129config REGULATOR_AS3711
130 tristate "AS3711 PMIC"
131 depends on MFD_AS3711
132 help
133 This driver provides support for the voltage regulators on the
134 AS3711 PMIC
135
99config REGULATOR_DA903X 136config REGULATOR_DA903X
100 tristate "Dialog Semiconductor DA9030/DA9034 regulators" 137 tristate "Dialog Semiconductor DA9030/DA9034 regulators"
101 depends on PMIC_DA903X 138 depends on PMIC_DA903X
@@ -120,6 +157,37 @@ config REGULATOR_DA9055
120 This driver can also be built as a module. If so, the module 157 This driver can also be built as a module. If so, the module
121 will be called da9055-regulator. 158 will be called da9055-regulator.
122 159
160config REGULATOR_DA9063
161 tristate "Dialog Semiconductor DA9063 regulators"
162 depends on MFD_DA9063
163 help
164 Say y here to support the BUCKs and LDOs regulators found on
165 DA9063 PMICs.
166
167 This driver can also be built as a module. If so, the module
168 will be called da9063-regulator.
169
170config REGULATOR_DA9210
171 tristate "Dialog Semiconductor DA9210 regulator"
172 depends on I2C
173 select REGMAP_I2C
174 help
175 Say y here to support for the Dialog Semiconductor DA9210.
176 The DA9210 is a multi-phase synchronous step down
177 converter 12A DC-DC Buck controlled through an I2C
178 interface.
179
180config REGULATOR_DBX500_PRCMU
181 bool
182
183config REGULATOR_DB8500_PRCMU
184 bool "ST-Ericsson DB8500 Voltage Domain Regulators"
185 depends on MFD_DB8500_PRCMU
186 select REGULATOR_DBX500_PRCMU
187 help
188 This driver supports the voltage domain regulators controlled by the
189 DB8500 PRCMU
190
123config REGULATOR_FAN53555 191config REGULATOR_FAN53555
124 tristate "Fairchild FAN53555 Regulator" 192 tristate "Fairchild FAN53555 Regulator"
125 depends on I2C 193 depends on I2C
@@ -131,44 +199,57 @@ config REGULATOR_FAN53555
131 input voltage supply of 2.5V to 5.5V. The output voltage is 199 input voltage supply of 2.5V to 5.5V. The output voltage is
132 programmed through an I2C interface. 200 programmed through an I2C interface.
133 201
134config REGULATOR_ANATOP 202config REGULATOR_GPIO
135 tristate "Freescale i.MX on-chip ANATOP LDO regulators" 203 tristate "GPIO regulator support"
136 depends on MFD_SYSCON 204 depends on GPIOLIB
137 help 205 help
138 Say y here to support Freescale i.MX on-chip ANATOP LDOs 206 This driver provides support for regulators that can be
139 regulators. It is recommended that this option be 207 controlled via gpios.
140 enabled on i.MX6 platform. 208 It is capable of supporting current and voltage regulators
209 and the platform has to provide a mapping of GPIO-states
210 to target volts/amps.
141 211
142config REGULATOR_MC13XXX_CORE 212config REGULATOR_ISL6271A
143 tristate 213 tristate "Intersil ISL6271A Power regulator"
214 depends on I2C
215 help
216 This driver supports ISL6271A voltage regulator chip.
144 217
145config REGULATOR_MC13783 218config REGULATOR_LP3971
146 tristate "Freescale MC13783 regulator driver" 219 tristate "National Semiconductors LP3971 PMIC regulator driver"
147 depends on MFD_MC13783 220 depends on I2C
148 select REGULATOR_MC13XXX_CORE
149 help 221 help
150 Say y here to support the regulators found on the Freescale MC13783 222 Say Y here to support the voltage regulators and convertors
151 PMIC. 223 on National Semiconductors LP3971 PMIC
152 224
153config REGULATOR_MC13892 225config REGULATOR_LP3972
154 tristate "Freescale MC13892 regulator driver" 226 tristate "National Semiconductors LP3972 PMIC regulator driver"
155 depends on MFD_MC13XXX 227 depends on I2C
156 select REGULATOR_MC13XXX_CORE
157 help 228 help
158 Say y here to support the regulators found on the Freescale MC13892 229 Say Y here to support the voltage regulators and convertors
159 PMIC. 230 on National Semiconductors LP3972 PMIC
160 231
161config REGULATOR_ISL6271A 232config REGULATOR_LP872X
162 tristate "Intersil ISL6271A Power regulator" 233 tristate "TI/National Semiconductor LP8720/LP8725 voltage regulators"
163 depends on I2C 234 depends on I2C
235 select REGMAP_I2C
164 help 236 help
165 This driver supports ISL6271A voltage regulator chip. 237 This driver supports LP8720/LP8725 PMIC
166 238
167config REGULATOR_88PM8607 239config REGULATOR_LP8755
168 bool "Marvell 88PM8607 Power regulators" 240 tristate "TI LP8755 High Performance PMU driver"
169 depends on MFD_88PM860X=y 241 depends on I2C
242 select REGMAP_I2C
170 help 243 help
171 This driver supports 88PM8607 voltage regulator chips. 244 This driver supports LP8755 High Performance PMU driver. This
245 chip contains six step-down DC/DC converters which can support
246 9 mode multiphase configuration.
247
248config REGULATOR_LP8788
249 tristate "TI LP8788 Power Regulators"
250 depends on MFD_LP8788
251 help
252 This driver supports LP8788 voltage regulator chip.
172 253
173config REGULATOR_MAX1586 254config REGULATOR_MAX1586
174 tristate "Maxim 1586/1587 voltage regulator" 255 tristate "Maxim 1586/1587 voltage regulator"
@@ -259,48 +340,43 @@ config REGULATOR_MAX77693
259 and one current regulator 'CHARGER'. This is suitable for 340 and one current regulator 'CHARGER'. This is suitable for
260 Exynos-4x12 chips. 341 Exynos-4x12 chips.
261 342
262config REGULATOR_PCAP 343config REGULATOR_MC13XXX_CORE
263 tristate "Motorola PCAP2 regulator driver" 344 tristate
264 depends on EZX_PCAP
265 help
266 This driver provides support for the voltage regulators of the
267 PCAP2 PMIC.
268 345
269config REGULATOR_LP3971 346config REGULATOR_MC13783
270 tristate "National Semiconductors LP3971 PMIC regulator driver" 347 tristate "Freescale MC13783 regulator driver"
271 depends on I2C 348 depends on MFD_MC13783
349 select REGULATOR_MC13XXX_CORE
272 help 350 help
273 Say Y here to support the voltage regulators and convertors 351 Say y here to support the regulators found on the Freescale MC13783
274 on National Semiconductors LP3971 PMIC 352 PMIC.
275 353
276config REGULATOR_LP3972 354config REGULATOR_MC13892
277 tristate "National Semiconductors LP3972 PMIC regulator driver" 355 tristate "Freescale MC13892 regulator driver"
278 depends on I2C 356 depends on MFD_MC13XXX
357 select REGULATOR_MC13XXX_CORE
279 help 358 help
280 Say Y here to support the voltage regulators and convertors 359 Say y here to support the regulators found on the Freescale MC13892
281 on National Semiconductors LP3972 PMIC 360 PMIC.
282 361
283config REGULATOR_LP872X 362config REGULATOR_PALMAS
284 bool "TI/National Semiconductor LP8720/LP8725 voltage regulators" 363 tristate "TI Palmas PMIC Regulators"
285 depends on I2C=y 364 depends on MFD_PALMAS
286 select REGMAP_I2C
287 help 365 help
288 This driver supports LP8720/LP8725 PMIC 366 If you wish to control the regulators on the Palmas series of
367 chips say Y here. This will enable support for all the software
368 controllable SMPS/LDO regulators.
289 369
290config REGULATOR_LP8755 370 The regulators available on Palmas series chips vary depending
291 tristate "TI LP8755 High Performance PMU driver" 371 on the muxing. This is handled automatically in the driver by
292 depends on I2C 372 reading the mux info from OTP.
293 select REGMAP_I2C
294 help
295 This driver supports LP8755 High Performance PMU driver. This
296 chip contains six step-down DC/DC converters which can support
297 9 mode multiphase configuration.
298 373
299config REGULATOR_LP8788 374config REGULATOR_PCAP
300 bool "TI LP8788 Power Regulators" 375 tristate "Motorola PCAP2 regulator driver"
301 depends on MFD_LP8788 376 depends on EZX_PCAP
302 help 377 help
303 This driver supports LP8788 voltage regulator chip. 378 This driver provides support for the voltage regulators of the
379 PCAP2 PMIC.
304 380
305config REGULATOR_PCF50633 381config REGULATOR_PCF50633
306 tristate "NXP PCF50633 regulator driver" 382 tristate "NXP PCF50633 regulator driver"
@@ -309,6 +385,14 @@ config REGULATOR_PCF50633
309 Say Y here to support the voltage regulators and convertors 385 Say Y here to support the voltage regulators and convertors
310 on PCF50633 386 on PCF50633
311 387
388config REGULATOR_PFUZE100
389 tristate "Support regulators on Freescale PFUZE100 PMIC"
390 depends on I2C
391 select REGMAP_I2C
392 help
393 Say y here to support the regulators found on the Freescale PFUZE100
394 PMIC.
395
312config REGULATOR_RC5T583 396config REGULATOR_RC5T583
313 tristate "RICOH RC5T583 Power regulators" 397 tristate "RICOH RC5T583 Power regulators"
314 depends on MFD_RC5T583 398 depends on MFD_RC5T583
@@ -335,44 +419,15 @@ config REGULATOR_S5M8767
335 via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and 419 via I2C bus. S5M8767A have 9 Bucks and 28 LDOs output and
336 supports DVS mode with 8bits of output voltage control. 420 supports DVS mode with 8bits of output voltage control.
337 421
338config REGULATOR_AB3100 422config REGULATOR_TI_ABB
339 tristate "ST-Ericsson AB3100 Regulator functions" 423 tristate "TI Adaptive Body Bias on-chip LDO"
340 depends on AB3100_CORE 424 depends on ARCH_OMAP
341 default y if AB3100_CORE
342 help
343 These regulators correspond to functionality in the
344 AB3100 analog baseband dealing with power regulators
345 for the system.
346
347config REGULATOR_AB8500
348 bool "ST-Ericsson AB8500 Power Regulators"
349 depends on AB8500_CORE
350 help
351 This driver supports the regulators found on the ST-Ericsson mixed
352 signal AB8500 PMIC
353
354config REGULATOR_DBX500_PRCMU
355 bool
356
357config REGULATOR_DB8500_PRCMU
358 bool "ST-Ericsson DB8500 Voltage Domain Regulators"
359 depends on MFD_DB8500_PRCMU
360 select REGULATOR_DBX500_PRCMU
361 help
362 This driver supports the voltage domain regulators controlled by the
363 DB8500 PRCMU
364
365config REGULATOR_PALMAS
366 tristate "TI Palmas PMIC Regulators"
367 depends on MFD_PALMAS
368 help 425 help
369 If you wish to control the regulators on the Palmas series of 426 Select this option to support Texas Instruments' on-chip Adaptive Body
370 chips say Y here. This will enable support for all the software 427 Bias (ABB) LDO regulators. It is recommended that this option be
371 controllable SMPS/LDO regulators. 428 enabled on required TI SoC. Certain Operating Performance Points
372 429 on TI SoCs may be unstable without enabling this as it provides
373 The regulators available on Palmas series chips vary depending 430 device specific optimized bias to allow/optimize functionality.
374 on the muxing. This is handled automatically in the driver by
375 reading the mux info from OTP.
376 431
377config REGULATOR_TPS51632 432config REGULATOR_TPS51632
378 tristate "TI TPS51632 Power Regulator" 433 tristate "TI TPS51632 Power Regulator"
@@ -475,22 +530,12 @@ config REGULATOR_TPS80031
475 output to control regulators. 530 output to control regulators.
476 531
477config REGULATOR_TWL4030 532config REGULATOR_TWL4030
478 bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" 533 tristate "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC"
479 depends on TWL4030_CORE 534 depends on TWL4030_CORE
480 help 535 help
481 This driver supports the voltage regulators provided by 536 This driver supports the voltage regulators provided by
482 this family of companion chips. 537 this family of companion chips.
483 538
484config REGULATOR_TI_ABB
485 bool "TI Adaptive Body Bias on-chip LDO"
486 depends on ARCH_OMAP
487 help
488 Select this option to support Texas Instruments' on-chip Adaptive Body
489 Bias (ABB) LDO regulators. It is recommended that this option be
490 enabled on required TI SoC. Certain Operating Performance Points
491 on TI SoCs may be unstable without enabling this as it provides
492 device specific optimized bias to allow/optimize functionality.
493
494config REGULATOR_VEXPRESS 539config REGULATOR_VEXPRESS
495 tristate "Versatile Express regulators" 540 tristate "Versatile Express regulators"
496 depends on VEXPRESS_CONFIG 541 depends on VEXPRESS_CONFIG
@@ -526,12 +571,5 @@ config REGULATOR_WM8994
526 This driver provides support for the voltage regulators on the 571 This driver provides support for the voltage regulators on the
527 WM8994 CODEC. 572 WM8994 CODEC.
528 573
529config REGULATOR_AS3711
530 tristate "AS3711 PMIC"
531 depends on MFD_AS3711
532 help
533 This driver provides support for the voltage regulators on the
534 AS3711 PMIC
535
536endif 574endif
537 575
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ba4a3cf3afec..185cce246022 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -3,12 +3,13 @@
3# 3#
4 4
5 5
6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o 6obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.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
10obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 10obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
11 11
12obj-$(CONFIG_REGULATOR_88PM800) += 88pm800.o
12obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 13obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
13obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o 14obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o
14obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 15obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
@@ -20,6 +21,8 @@ obj-$(CONFIG_REGULATOR_AS3711) += as3711-regulator.o
20obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 21obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
21obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 22obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
22obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o 23obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
24obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
25obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
23obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 26obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
24obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 27obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
25obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 28obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
@@ -46,12 +49,14 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
46obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o 49obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
47obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o 50obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
48obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o 51obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o
52obj-$(CONFIG_REGULATOR_PFUZE100) += pfuze100-regulator.o
49obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o 53obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o
50obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 54obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
51obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 55obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
52obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o 56obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
53obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o 57obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
54obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 58obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
59obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
55obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o 60obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o
56obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o 61obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o
57obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 62obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
@@ -64,7 +69,6 @@ obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
64obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o 69obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
65obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o 70obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
66obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o 71obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
67obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
68obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress.o 72obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress.o
69obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 73obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
70obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 74obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 8b5876356db9..881159dfcb5e 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -174,7 +174,7 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
174 174
175 config.dev = &pdev->dev; 175 config.dev = &pdev->dev;
176 config.driver_data = ri; 176 config.driver_data = ri;
177 config.init_data = pdev->dev.platform_data; 177 config.init_data = dev_get_platdata(&pdev->dev);
178 178
179 rdev = regulator_register(&ri->desc, &config); 179 rdev = regulator_register(&ri->desc, &config);
180 if (IS_ERR(rdev)) { 180 if (IS_ERR(rdev)) {
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 3be9e46594a1..7d5eaa874b2d 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -660,7 +660,7 @@ ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
660 660
661static int ab3100_regulators_probe(struct platform_device *pdev) 661static int ab3100_regulators_probe(struct platform_device *pdev)
662{ 662{
663 struct ab3100_platform_data *plfdata = pdev->dev.platform_data; 663 struct ab3100_platform_data *plfdata = dev_get_platdata(&pdev->dev);
664 struct device_node *np = pdev->dev.of_node; 664 struct device_node *np = pdev->dev.of_node;
665 int err = 0; 665 int err = 0;
666 u8 data; 666 u8 data;
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index 6b981b5faa70..b2b203cb6b2f 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -214,7 +214,7 @@ MODULE_DEVICE_TABLE(i2c, ad5398_id);
214static int ad5398_probe(struct i2c_client *client, 214static int ad5398_probe(struct i2c_client *client,
215 const struct i2c_device_id *id) 215 const struct i2c_device_id *id)
216{ 216{
217 struct regulator_init_data *init_data = client->dev.platform_data; 217 struct regulator_init_data *init_data = dev_get_platdata(&client->dev);
218 struct regulator_config config = { }; 218 struct regulator_config config = { };
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 =
diff --git a/drivers/regulator/as3711-regulator.c b/drivers/regulator/as3711-regulator.c
index 3da6bd6950cf..8406cd745da2 100644
--- a/drivers/regulator/as3711-regulator.c
+++ b/drivers/regulator/as3711-regulator.c
@@ -30,102 +30,6 @@ struct as3711_regulator {
30 struct regulator_dev *rdev; 30 struct regulator_dev *rdev;
31}; 31};
32 32
33static int as3711_list_voltage_sd(struct regulator_dev *rdev,
34 unsigned int selector)
35{
36 if (selector >= rdev->desc->n_voltages)
37 return -EINVAL;
38
39 if (!selector)
40 return 0;
41 if (selector < 0x41)
42 return 600000 + selector * 12500;
43 if (selector < 0x71)
44 return 1400000 + (selector - 0x40) * 25000;
45 return 2600000 + (selector - 0x70) * 50000;
46}
47
48static int as3711_list_voltage_aldo(struct regulator_dev *rdev,
49 unsigned int selector)
50{
51 if (selector >= rdev->desc->n_voltages)
52 return -EINVAL;
53
54 if (selector < 0x10)
55 return 1200000 + selector * 50000;
56 return 1800000 + (selector - 0x10) * 100000;
57}
58
59static int as3711_list_voltage_dldo(struct regulator_dev *rdev,
60 unsigned int selector)
61{
62 if (selector >= rdev->desc->n_voltages ||
63 (selector > 0x10 && selector < 0x20))
64 return -EINVAL;
65
66 if (selector < 0x11)
67 return 900000 + selector * 50000;
68 return 1750000 + (selector - 0x20) * 50000;
69}
70
71static int as3711_bound_check(struct regulator_dev *rdev,
72 int *min_uV, int *max_uV)
73{
74 struct as3711_regulator *reg = rdev_get_drvdata(rdev);
75 struct as3711_regulator_info *info = reg->reg_info;
76
77 dev_dbg(&rdev->dev, "%s(), %d, %d, %d\n", __func__,
78 *min_uV, rdev->desc->min_uV, info->max_uV);
79
80 if (*max_uV < *min_uV ||
81 *min_uV > info->max_uV || rdev->desc->min_uV > *max_uV)
82 return -EINVAL;
83
84 if (rdev->desc->n_voltages == 1)
85 return 0;
86
87 if (*max_uV > info->max_uV)
88 *max_uV = info->max_uV;
89
90 if (*min_uV < rdev->desc->min_uV)
91 *min_uV = rdev->desc->min_uV;
92
93 return *min_uV;
94}
95
96static int as3711_sel_check(int min, int max, int bottom, int step)
97{
98 int sel, voltage;
99
100 /* Round up min, when dividing: keeps us within the range */
101 sel = DIV_ROUND_UP(min - bottom, step);
102 voltage = sel * step + bottom;
103 pr_debug("%s(): select %d..%d in %d+N*%d: %d\n", __func__,
104 min, max, bottom, step, sel);
105 if (voltage > max)
106 return -EINVAL;
107
108 return sel;
109}
110
111static int as3711_map_voltage_sd(struct regulator_dev *rdev,
112 int min_uV, int max_uV)
113{
114 int ret;
115
116 ret = as3711_bound_check(rdev, &min_uV, &max_uV);
117 if (ret <= 0)
118 return ret;
119
120 if (min_uV <= 1400000)
121 return as3711_sel_check(min_uV, max_uV, 600000, 12500);
122
123 if (min_uV <= 2600000)
124 return as3711_sel_check(min_uV, max_uV, 1400000, 25000) + 0x40;
125
126 return as3711_sel_check(min_uV, max_uV, 2600000, 50000) + 0x70;
127}
128
129/* 33/*
130 * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and 34 * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and
131 * STANDBY. We map them in the following way to AS3711 SD1-4 DCDC modes: 35 * STANDBY. We map them in the following way to AS3711 SD1-4 DCDC modes:
@@ -180,44 +84,14 @@ static unsigned int as3711_get_mode_sd(struct regulator_dev *rdev)
180 return -EINVAL; 84 return -EINVAL;
181} 85}
182 86
183static int as3711_map_voltage_aldo(struct regulator_dev *rdev,
184 int min_uV, int max_uV)
185{
186 int ret;
187
188 ret = as3711_bound_check(rdev, &min_uV, &max_uV);
189 if (ret <= 0)
190 return ret;
191
192 if (min_uV <= 1800000)
193 return as3711_sel_check(min_uV, max_uV, 1200000, 50000);
194
195 return as3711_sel_check(min_uV, max_uV, 1800000, 100000) + 0x10;
196}
197
198static int as3711_map_voltage_dldo(struct regulator_dev *rdev,
199 int min_uV, int max_uV)
200{
201 int ret;
202
203 ret = as3711_bound_check(rdev, &min_uV, &max_uV);
204 if (ret <= 0)
205 return ret;
206
207 if (min_uV <= 1700000)
208 return as3711_sel_check(min_uV, max_uV, 900000, 50000);
209
210 return as3711_sel_check(min_uV, max_uV, 1750000, 50000) + 0x20;
211}
212
213static struct regulator_ops as3711_sd_ops = { 87static struct regulator_ops as3711_sd_ops = {
214 .is_enabled = regulator_is_enabled_regmap, 88 .is_enabled = regulator_is_enabled_regmap,
215 .enable = regulator_enable_regmap, 89 .enable = regulator_enable_regmap,
216 .disable = regulator_disable_regmap, 90 .disable = regulator_disable_regmap,
217 .get_voltage_sel = regulator_get_voltage_sel_regmap, 91 .get_voltage_sel = regulator_get_voltage_sel_regmap,
218 .set_voltage_sel = regulator_set_voltage_sel_regmap, 92 .set_voltage_sel = regulator_set_voltage_sel_regmap,
219 .list_voltage = as3711_list_voltage_sd, 93 .list_voltage = regulator_list_voltage_linear_range,
220 .map_voltage = as3711_map_voltage_sd, 94 .map_voltage = regulator_map_voltage_linear_range,
221 .get_mode = as3711_get_mode_sd, 95 .get_mode = as3711_get_mode_sd,
222 .set_mode = as3711_set_mode_sd, 96 .set_mode = as3711_set_mode_sd,
223}; 97};
@@ -228,8 +102,8 @@ static struct regulator_ops as3711_aldo_ops = {
228 .disable = regulator_disable_regmap, 102 .disable = regulator_disable_regmap,
229 .get_voltage_sel = regulator_get_voltage_sel_regmap, 103 .get_voltage_sel = regulator_get_voltage_sel_regmap,
230 .set_voltage_sel = regulator_set_voltage_sel_regmap, 104 .set_voltage_sel = regulator_set_voltage_sel_regmap,
231 .list_voltage = as3711_list_voltage_aldo, 105 .list_voltage = regulator_list_voltage_linear_range,
232 .map_voltage = as3711_map_voltage_aldo, 106 .map_voltage = regulator_map_voltage_linear_range,
233}; 107};
234 108
235static struct regulator_ops as3711_dldo_ops = { 109static struct regulator_ops as3711_dldo_ops = {
@@ -238,8 +112,31 @@ static struct regulator_ops as3711_dldo_ops = {
238 .disable = regulator_disable_regmap, 112 .disable = regulator_disable_regmap,
239 .get_voltage_sel = regulator_get_voltage_sel_regmap, 113 .get_voltage_sel = regulator_get_voltage_sel_regmap,
240 .set_voltage_sel = regulator_set_voltage_sel_regmap, 114 .set_voltage_sel = regulator_set_voltage_sel_regmap,
241 .list_voltage = as3711_list_voltage_dldo, 115 .list_voltage = regulator_list_voltage_linear_range,
242 .map_voltage = as3711_map_voltage_dldo, 116 .map_voltage = regulator_map_voltage_linear_range,
117};
118
119static const struct regulator_linear_range as3711_sd_ranges[] = {
120 { .min_uV = 612500, .max_uV = 1400000,
121 .min_sel = 0x1, .max_sel = 0x40, .uV_step = 12500 },
122 { .min_uV = 1425000, .max_uV = 2600000,
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};
127
128static const struct regulator_linear_range as3711_aldo_ranges[] = {
129 { .min_uV = 1200000, .max_uV = 1950000,
130 .min_sel = 0, .max_sel = 0xf, .uV_step = 50000 },
131 { .min_uV = 1800000, .max_uV = 3300000,
132 .min_sel = 0x10, .max_sel = 0x1f, .uV_step = 100000 },
133};
134
135static const struct regulator_linear_range as3711_dldo_ranges[] = {
136 { .min_uV = 900000, .max_uV = 1700000,
137 .min_sel = 0, .max_sel = 0x10, .uV_step = 50000 },
138 { .min_uV = 1750000, .max_uV = 3300000,
139 .min_sel = 0x20, .max_sel = 0x3f, .uV_step = 50000 },
243}; 140};
244 141
245#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \ 142#define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _vshift, _min_uV, _max_uV, _sfx) \
@@ -256,6 +153,8 @@ static struct regulator_ops as3711_dldo_ops = {
256 .enable_reg = AS3711_ ## _en_reg, \ 153 .enable_reg = AS3711_ ## _en_reg, \
257 .enable_mask = BIT(_en_bit), \ 154 .enable_mask = BIT(_en_bit), \
258 .min_uV = _min_uV, \ 155 .min_uV = _min_uV, \
156 .linear_ranges = as3711_ ## _sfx ## _ranges, \
157 .n_linear_ranges = ARRAY_SIZE(as3711_ ## _sfx ## _ranges), \
259 }, \ 158 }, \
260 .max_uV = _max_uV, \ 159 .max_uV = _max_uV, \
261} 160}
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 288c75abc190..a01b8b3b70ca 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -323,13 +323,14 @@ static ssize_t regulator_uA_show(struct device *dev,
323} 323}
324static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL); 324static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
325 325
326static ssize_t regulator_name_show(struct device *dev, 326static ssize_t name_show(struct device *dev, struct device_attribute *attr,
327 struct device_attribute *attr, char *buf) 327 char *buf)
328{ 328{
329 struct regulator_dev *rdev = dev_get_drvdata(dev); 329 struct regulator_dev *rdev = dev_get_drvdata(dev);
330 330
331 return sprintf(buf, "%s\n", rdev_get_name(rdev)); 331 return sprintf(buf, "%s\n", rdev_get_name(rdev));
332} 332}
333static DEVICE_ATTR_RO(name);
333 334
334static ssize_t regulator_print_opmode(char *buf, int mode) 335static ssize_t regulator_print_opmode(char *buf, int mode)
335{ 336{
@@ -489,15 +490,16 @@ static ssize_t regulator_total_uA_show(struct device *dev,
489} 490}
490static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL); 491static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
491 492
492static ssize_t regulator_num_users_show(struct device *dev, 493static ssize_t num_users_show(struct device *dev, struct device_attribute *attr,
493 struct device_attribute *attr, char *buf) 494 char *buf)
494{ 495{
495 struct regulator_dev *rdev = dev_get_drvdata(dev); 496 struct regulator_dev *rdev = dev_get_drvdata(dev);
496 return sprintf(buf, "%d\n", rdev->use_count); 497 return sprintf(buf, "%d\n", rdev->use_count);
497} 498}
499static DEVICE_ATTR_RO(num_users);
498 500
499static ssize_t regulator_type_show(struct device *dev, 501static ssize_t type_show(struct device *dev, struct device_attribute *attr,
500 struct device_attribute *attr, char *buf) 502 char *buf)
501{ 503{
502 struct regulator_dev *rdev = dev_get_drvdata(dev); 504 struct regulator_dev *rdev = dev_get_drvdata(dev);
503 505
@@ -509,6 +511,7 @@ static ssize_t regulator_type_show(struct device *dev,
509 } 511 }
510 return sprintf(buf, "unknown\n"); 512 return sprintf(buf, "unknown\n");
511} 513}
514static DEVICE_ATTR_RO(type);
512 515
513static ssize_t regulator_suspend_mem_uV_show(struct device *dev, 516static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
514 struct device_attribute *attr, char *buf) 517 struct device_attribute *attr, char *buf)
@@ -632,12 +635,13 @@ static DEVICE_ATTR(bypass, 0444,
632 * These are the only attributes are present for all regulators. 635 * These are the only attributes are present for all regulators.
633 * Other attributes are a function of regulator functionality. 636 * Other attributes are a function of regulator functionality.
634 */ 637 */
635static struct device_attribute regulator_dev_attrs[] = { 638static struct attribute *regulator_dev_attrs[] = {
636 __ATTR(name, 0444, regulator_name_show, NULL), 639 &dev_attr_name.attr,
637 __ATTR(num_users, 0444, regulator_num_users_show, NULL), 640 &dev_attr_num_users.attr,
638 __ATTR(type, 0444, regulator_type_show, NULL), 641 &dev_attr_type.attr,
639 __ATTR_NULL, 642 NULL,
640}; 643};
644ATTRIBUTE_GROUPS(regulator_dev);
641 645
642static void regulator_dev_release(struct device *dev) 646static void regulator_dev_release(struct device *dev)
643{ 647{
@@ -648,7 +652,7 @@ static void regulator_dev_release(struct device *dev)
648static struct class regulator_class = { 652static struct class regulator_class = {
649 .name = "regulator", 653 .name = "regulator",
650 .dev_release = regulator_dev_release, 654 .dev_release = regulator_dev_release,
651 .dev_attrs = regulator_dev_attrs, 655 .dev_groups = regulator_dev_groups,
652}; 656};
653 657
654/* Calculate the new optimum regulator operating mode based on the new total 658/* Calculate the new optimum regulator operating mode based on the new total
@@ -984,7 +988,8 @@ static int set_machine_constraints(struct regulator_dev *rdev,
984 } 988 }
985 } 989 }
986 990
987 if (rdev->constraints->ramp_delay && ops->set_ramp_delay) { 991 if ((rdev->constraints->ramp_delay || rdev->constraints->ramp_disable)
992 && ops->set_ramp_delay) {
988 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay); 993 ret = ops->set_ramp_delay(rdev, rdev->constraints->ramp_delay);
989 if (ret < 0) { 994 if (ret < 0) {
990 rdev_err(rdev, "failed to set ramp_delay\n"); 995 rdev_err(rdev, "failed to set ramp_delay\n");
@@ -1238,7 +1243,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
1238 1243
1239/* Internal regulator request function */ 1244/* Internal regulator request function */
1240static struct regulator *_regulator_get(struct device *dev, const char *id, 1245static struct regulator *_regulator_get(struct device *dev, const char *id,
1241 int exclusive) 1246 bool exclusive)
1242{ 1247{
1243 struct regulator_dev *rdev; 1248 struct regulator_dev *rdev;
1244 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); 1249 struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
@@ -1344,7 +1349,7 @@ out:
1344 */ 1349 */
1345struct regulator *regulator_get(struct device *dev, const char *id) 1350struct regulator *regulator_get(struct device *dev, const char *id)
1346{ 1351{
1347 return _regulator_get(dev, id, 0); 1352 return _regulator_get(dev, id, false);
1348} 1353}
1349EXPORT_SYMBOL_GPL(regulator_get); 1354EXPORT_SYMBOL_GPL(regulator_get);
1350 1355
@@ -1405,10 +1410,69 @@ EXPORT_SYMBOL_GPL(devm_regulator_get);
1405 */ 1410 */
1406struct regulator *regulator_get_exclusive(struct device *dev, const char *id) 1411struct regulator *regulator_get_exclusive(struct device *dev, const char *id)
1407{ 1412{
1408 return _regulator_get(dev, id, 1); 1413 return _regulator_get(dev, id, true);
1409} 1414}
1410EXPORT_SYMBOL_GPL(regulator_get_exclusive); 1415EXPORT_SYMBOL_GPL(regulator_get_exclusive);
1411 1416
1417/**
1418 * regulator_get_optional - obtain optional access to a regulator.
1419 * @dev: device for regulator "consumer"
1420 * @id: Supply name or regulator ID.
1421 *
1422 * Returns a struct regulator corresponding to the regulator producer,
1423 * or IS_ERR() condition containing errno. Other consumers will be
1424 * unable to obtain this reference is held and the use count for the
1425 * regulator will be initialised to reflect the current state of the
1426 * regulator.
1427 *
1428 * This is intended for use by consumers for devices which can have
1429 * some supplies unconnected in normal use, such as some MMC devices.
1430 * It can allow the regulator core to provide stub supplies for other
1431 * supplies requested using normal regulator_get() calls without
1432 * disrupting the operation of drivers that can handle absent
1433 * supplies.
1434 *
1435 * Use of supply names configured via regulator_set_device_supply() is
1436 * strongly encouraged. It is recommended that the supply name used
1437 * should match the name used for the supply and/or the relevant
1438 * device pins in the datasheet.
1439 */
1440struct regulator *regulator_get_optional(struct device *dev, const char *id)
1441{
1442 return _regulator_get(dev, id, 0);
1443}
1444EXPORT_SYMBOL_GPL(regulator_get_optional);
1445
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
1412/* Locks held by regulator_put() */ 1476/* Locks held by regulator_put() */
1413static void _regulator_put(struct regulator *regulator) 1477static void _regulator_put(struct regulator *regulator)
1414{ 1478{
@@ -1435,6 +1499,36 @@ static void _regulator_put(struct regulator *regulator)
1435} 1499}
1436 1500
1437/** 1501/**
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/**
1438 * regulator_put - "free" the regulator source 1532 * regulator_put - "free" the regulator source
1439 * @regulator: regulator source 1533 * @regulator: regulator source
1440 * 1534 *
@@ -1890,8 +1984,9 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
1890 rdev->deferred_disables++; 1984 rdev->deferred_disables++;
1891 mutex_unlock(&rdev->mutex); 1985 mutex_unlock(&rdev->mutex);
1892 1986
1893 ret = schedule_delayed_work(&rdev->disable_work, 1987 ret = queue_delayed_work(system_power_efficient_wq,
1894 msecs_to_jiffies(ms)); 1988 &rdev->disable_work,
1989 msecs_to_jiffies(ms));
1895 if (ret < 0) 1990 if (ret < 0)
1896 return ret; 1991 return ret;
1897 else 1992 else
@@ -1899,77 +1994,6 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
1899} 1994}
1900EXPORT_SYMBOL_GPL(regulator_disable_deferred); 1995EXPORT_SYMBOL_GPL(regulator_disable_deferred);
1901 1996
1902/**
1903 * regulator_is_enabled_regmap - standard is_enabled() for regmap users
1904 *
1905 * @rdev: regulator to operate on
1906 *
1907 * Regulators that use regmap for their register I/O can set the
1908 * enable_reg and enable_mask fields in their descriptor and then use
1909 * this as their is_enabled operation, saving some code.
1910 */
1911int regulator_is_enabled_regmap(struct regulator_dev *rdev)
1912{
1913 unsigned int val;
1914 int ret;
1915
1916 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
1917 if (ret != 0)
1918 return ret;
1919
1920 if (rdev->desc->enable_is_inverted)
1921 return (val & rdev->desc->enable_mask) == 0;
1922 else
1923 return (val & rdev->desc->enable_mask) != 0;
1924}
1925EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
1926
1927/**
1928 * regulator_enable_regmap - standard enable() for regmap users
1929 *
1930 * @rdev: regulator to operate on
1931 *
1932 * Regulators that use regmap for their register I/O can set the
1933 * enable_reg and enable_mask fields in their descriptor and then use
1934 * this as their enable() operation, saving some code.
1935 */
1936int regulator_enable_regmap(struct regulator_dev *rdev)
1937{
1938 unsigned int val;
1939
1940 if (rdev->desc->enable_is_inverted)
1941 val = 0;
1942 else
1943 val = rdev->desc->enable_mask;
1944
1945 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1946 rdev->desc->enable_mask, val);
1947}
1948EXPORT_SYMBOL_GPL(regulator_enable_regmap);
1949
1950/**
1951 * regulator_disable_regmap - standard disable() for regmap users
1952 *
1953 * @rdev: regulator to operate on
1954 *
1955 * Regulators that use regmap for their register I/O can set the
1956 * enable_reg and enable_mask fields in their descriptor and then use
1957 * this as their disable() operation, saving some code.
1958 */
1959int regulator_disable_regmap(struct regulator_dev *rdev)
1960{
1961 unsigned int val;
1962
1963 if (rdev->desc->enable_is_inverted)
1964 val = rdev->desc->enable_mask;
1965 else
1966 val = 0;
1967
1968 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1969 rdev->desc->enable_mask, val);
1970}
1971EXPORT_SYMBOL_GPL(regulator_disable_regmap);
1972
1973static int _regulator_is_enabled(struct regulator_dev *rdev) 1997static int _regulator_is_enabled(struct regulator_dev *rdev)
1974{ 1998{
1975 /* A GPIO control always takes precedence */ 1999 /* A GPIO control always takes precedence */
@@ -2055,55 +2079,6 @@ int regulator_count_voltages(struct regulator *regulator)
2055EXPORT_SYMBOL_GPL(regulator_count_voltages); 2079EXPORT_SYMBOL_GPL(regulator_count_voltages);
2056 2080
2057/** 2081/**
2058 * regulator_list_voltage_linear - List voltages with simple calculation
2059 *
2060 * @rdev: Regulator device
2061 * @selector: Selector to convert into a voltage
2062 *
2063 * Regulators with a simple linear mapping between voltages and
2064 * selectors can set min_uV and uV_step in the regulator descriptor
2065 * and then use this function as their list_voltage() operation,
2066 */
2067int regulator_list_voltage_linear(struct regulator_dev *rdev,
2068 unsigned int selector)
2069{
2070 if (selector >= rdev->desc->n_voltages)
2071 return -EINVAL;
2072 if (selector < rdev->desc->linear_min_sel)
2073 return 0;
2074
2075 selector -= rdev->desc->linear_min_sel;
2076
2077 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
2078}
2079EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);
2080
2081/**
2082 * regulator_list_voltage_table - List voltages with table based mapping
2083 *
2084 * @rdev: Regulator device
2085 * @selector: Selector to convert into a voltage
2086 *
2087 * Regulators with table based mapping between voltages and
2088 * selectors can set volt_table in the regulator descriptor
2089 * and then use this function as their list_voltage() operation.
2090 */
2091int regulator_list_voltage_table(struct regulator_dev *rdev,
2092 unsigned int selector)
2093{
2094 if (!rdev->desc->volt_table) {
2095 BUG_ON(!rdev->desc->volt_table);
2096 return -EINVAL;
2097 }
2098
2099 if (selector >= rdev->desc->n_voltages)
2100 return -EINVAL;
2101
2102 return rdev->desc->volt_table[selector];
2103}
2104EXPORT_SYMBOL_GPL(regulator_list_voltage_table);
2105
2106/**
2107 * regulator_list_voltage - enumerate supported voltages 2082 * regulator_list_voltage - enumerate supported voltages
2108 * @regulator: regulator source 2083 * @regulator: regulator source
2109 * @selector: identify voltage to list 2084 * @selector: identify voltage to list
@@ -2197,177 +2172,6 @@ int regulator_is_supported_voltage(struct regulator *regulator,
2197} 2172}
2198EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 2173EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
2199 2174
2200/**
2201 * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users
2202 *
2203 * @rdev: regulator to operate on
2204 *
2205 * Regulators that use regmap for their register I/O can set the
2206 * vsel_reg and vsel_mask fields in their descriptor and then use this
2207 * as their get_voltage_vsel operation, saving some code.
2208 */
2209int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev)
2210{
2211 unsigned int val;
2212 int ret;
2213
2214 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
2215 if (ret != 0)
2216 return ret;
2217
2218 val &= rdev->desc->vsel_mask;
2219 val >>= ffs(rdev->desc->vsel_mask) - 1;
2220
2221 return val;
2222}
2223EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap);
2224
2225/**
2226 * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users
2227 *
2228 * @rdev: regulator to operate on
2229 * @sel: Selector to set
2230 *
2231 * Regulators that use regmap for their register I/O can set the
2232 * vsel_reg and vsel_mask fields in their descriptor and then use this
2233 * as their set_voltage_vsel operation, saving some code.
2234 */
2235int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel)
2236{
2237 int ret;
2238
2239 sel <<= ffs(rdev->desc->vsel_mask) - 1;
2240
2241 ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
2242 rdev->desc->vsel_mask, sel);
2243 if (ret)
2244 return ret;
2245
2246 if (rdev->desc->apply_bit)
2247 ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg,
2248 rdev->desc->apply_bit,
2249 rdev->desc->apply_bit);
2250 return ret;
2251}
2252EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap);
2253
2254/**
2255 * regulator_map_voltage_iterate - map_voltage() based on list_voltage()
2256 *
2257 * @rdev: Regulator to operate on
2258 * @min_uV: Lower bound for voltage
2259 * @max_uV: Upper bound for voltage
2260 *
2261 * Drivers implementing set_voltage_sel() and list_voltage() can use
2262 * this as their map_voltage() operation. It will find a suitable
2263 * voltage by calling list_voltage() until it gets something in bounds
2264 * for the requested voltages.
2265 */
2266int regulator_map_voltage_iterate(struct regulator_dev *rdev,
2267 int min_uV, int max_uV)
2268{
2269 int best_val = INT_MAX;
2270 int selector = 0;
2271 int i, ret;
2272
2273 /* Find the smallest voltage that falls within the specified
2274 * range.
2275 */
2276 for (i = 0; i < rdev->desc->n_voltages; i++) {
2277 ret = rdev->desc->ops->list_voltage(rdev, i);
2278 if (ret < 0)
2279 continue;
2280
2281 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
2282 best_val = ret;
2283 selector = i;
2284 }
2285 }
2286
2287 if (best_val != INT_MAX)
2288 return selector;
2289 else
2290 return -EINVAL;
2291}
2292EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
2293
2294/**
2295 * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
2296 *
2297 * @rdev: Regulator to operate on
2298 * @min_uV: Lower bound for voltage
2299 * @max_uV: Upper bound for voltage
2300 *
2301 * Drivers that have ascendant voltage list can use this as their
2302 * map_voltage() operation.
2303 */
2304int regulator_map_voltage_ascend(struct regulator_dev *rdev,
2305 int min_uV, int max_uV)
2306{
2307 int i, ret;
2308
2309 for (i = 0; i < rdev->desc->n_voltages; i++) {
2310 ret = rdev->desc->ops->list_voltage(rdev, i);
2311 if (ret < 0)
2312 continue;
2313
2314 if (ret > max_uV)
2315 break;
2316
2317 if (ret >= min_uV && ret <= max_uV)
2318 return i;
2319 }
2320
2321 return -EINVAL;
2322}
2323EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
2324
2325/**
2326 * regulator_map_voltage_linear - map_voltage() for simple linear mappings
2327 *
2328 * @rdev: Regulator to operate on
2329 * @min_uV: Lower bound for voltage
2330 * @max_uV: Upper bound for voltage
2331 *
2332 * Drivers providing min_uV and uV_step in their regulator_desc can
2333 * use this as their map_voltage() operation.
2334 */
2335int regulator_map_voltage_linear(struct regulator_dev *rdev,
2336 int min_uV, int max_uV)
2337{
2338 int ret, voltage;
2339
2340 /* Allow uV_step to be 0 for fixed voltage */
2341 if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) {
2342 if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV)
2343 return 0;
2344 else
2345 return -EINVAL;
2346 }
2347
2348 if (!rdev->desc->uV_step) {
2349 BUG_ON(!rdev->desc->uV_step);
2350 return -EINVAL;
2351 }
2352
2353 if (min_uV < rdev->desc->min_uV)
2354 min_uV = rdev->desc->min_uV;
2355
2356 ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
2357 if (ret < 0)
2358 return ret;
2359
2360 ret += rdev->desc->linear_min_sel;
2361
2362 /* Map back into a voltage to verify we're still in bounds */
2363 voltage = rdev->desc->ops->list_voltage(rdev, ret);
2364 if (voltage < min_uV || voltage > max_uV)
2365 return -EINVAL;
2366
2367 return ret;
2368}
2369EXPORT_SYMBOL_GPL(regulator_map_voltage_linear);
2370
2371static int _regulator_do_set_voltage(struct regulator_dev *rdev, 2175static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2372 int min_uV, int max_uV) 2176 int min_uV, int max_uV)
2373{ 2177{
@@ -2438,8 +2242,8 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2438 } 2242 }
2439 2243
2440 /* Call set_voltage_time_sel if successfully obtained old_selector */ 2244 /* Call set_voltage_time_sel if successfully obtained old_selector */
2441 if (ret == 0 && _regulator_is_enabled(rdev) && old_selector >= 0 && 2245 if (ret == 0 && !rdev->constraints->ramp_disable && old_selector >= 0
2442 old_selector != selector && rdev->desc->ops->set_voltage_time_sel) { 2246 && old_selector != selector) {
2443 2247
2444 delay = rdev->desc->ops->set_voltage_time_sel(rdev, 2248 delay = rdev->desc->ops->set_voltage_time_sel(rdev,
2445 old_selector, selector); 2249 old_selector, selector);
@@ -2971,47 +2775,6 @@ out:
2971EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 2775EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
2972 2776
2973/** 2777/**
2974 * regulator_set_bypass_regmap - Default set_bypass() using regmap
2975 *
2976 * @rdev: device to operate on.
2977 * @enable: state to set.
2978 */
2979int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
2980{
2981 unsigned int val;
2982
2983 if (enable)
2984 val = rdev->desc->bypass_mask;
2985 else
2986 val = 0;
2987
2988 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
2989 rdev->desc->bypass_mask, val);
2990}
2991EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);
2992
2993/**
2994 * regulator_get_bypass_regmap - Default get_bypass() using regmap
2995 *
2996 * @rdev: device to operate on.
2997 * @enable: current state.
2998 */
2999int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
3000{
3001 unsigned int val;
3002 int ret;
3003
3004 ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val);
3005 if (ret != 0)
3006 return ret;
3007
3008 *enable = val & rdev->desc->bypass_mask;
3009
3010 return 0;
3011}
3012EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap);
3013
3014/**
3015 * regulator_allow_bypass - allow the regulator to go into bypass mode 2778 * regulator_allow_bypass - allow the regulator to go into bypass mode
3016 * 2779 *
3017 * @regulator: Regulator to configure 2780 * @regulator: Regulator to configure
@@ -3740,8 +3503,11 @@ void regulator_unregister(struct regulator_dev *rdev)
3740 if (rdev == NULL) 3503 if (rdev == NULL)
3741 return; 3504 return;
3742 3505
3743 if (rdev->supply) 3506 if (rdev->supply) {
3507 while (rdev->use_count--)
3508 regulator_disable(rdev->supply);
3744 regulator_put(rdev->supply); 3509 regulator_put(rdev->supply);
3510 }
3745 mutex_lock(&regulator_list_mutex); 3511 mutex_lock(&regulator_list_mutex);
3746 debugfs_remove_recursive(rdev->debugfs); 3512 debugfs_remove_recursive(rdev->debugfs);
3747 flush_work(&rdev->disable_work.work); 3513 flush_work(&rdev->disable_work.work);
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 2afa5730f324..f06854cf8cf5 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -252,39 +252,12 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev,
252 return ret; 252 return ret;
253} 253}
254 254
255static int da9034_map_ldo12_voltage(struct regulator_dev *rdev, 255static const struct regulator_linear_range da9034_ldo12_ranges[] = {
256 int min_uV, int max_uV) 256 { .min_uV = 1700000, .max_uV = 2050000, .min_sel = 0, .max_sel = 7,
257{ 257 .uV_step = 50000 },
258 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 258 { .min_uV = 2700000, .max_uV = 3050000, .min_sel = 8, .max_sel = 15,
259 int sel; 259 .uV_step = 50000 },
260 260};
261 if (check_range(info, min_uV, max_uV)) {
262 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
263 return -EINVAL;
264 }
265
266 sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
267 sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel);
268
269 return sel;
270}
271
272static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
273 unsigned selector)
274{
275 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
276 int volt;
277
278 if (selector >= 8)
279 volt = 2700000 + rdev->desc->uV_step * (selector - 8);
280 else
281 volt = rdev->desc->min_uV + rdev->desc->uV_step * selector;
282
283 if (volt > info->max_uV)
284 return -EINVAL;
285
286 return volt;
287}
288 261
289static struct regulator_ops da903x_regulator_ldo_ops = { 262static struct regulator_ops da903x_regulator_ldo_ops = {
290 .set_voltage_sel = da903x_set_voltage_sel, 263 .set_voltage_sel = da903x_set_voltage_sel,
@@ -332,8 +305,8 @@ static struct regulator_ops da9034_regulator_dvc_ops = {
332static struct regulator_ops da9034_regulator_ldo12_ops = { 305static struct regulator_ops da9034_regulator_ldo12_ops = {
333 .set_voltage_sel = da903x_set_voltage_sel, 306 .set_voltage_sel = da903x_set_voltage_sel,
334 .get_voltage_sel = da903x_get_voltage_sel, 307 .get_voltage_sel = da903x_get_voltage_sel,
335 .list_voltage = da9034_list_ldo12_voltage, 308 .list_voltage = regulator_list_voltage_linear_range,
336 .map_voltage = da9034_map_ldo12_voltage, 309 .map_voltage = regulator_map_voltage_linear_range,
337 .enable = da903x_enable, 310 .enable = da903x_enable,
338 .disable = da903x_disable, 311 .disable = da903x_disable,
339 .is_enabled = da903x_is_enabled, 312 .is_enabled = da903x_is_enabled,
@@ -476,6 +449,8 @@ static int da903x_regulator_probe(struct platform_device *pdev)
476 if (ri->desc.id == DA9034_ID_LDO12) { 449 if (ri->desc.id == DA9034_ID_LDO12) {
477 ri->desc.ops = &da9034_regulator_ldo12_ops; 450 ri->desc.ops = &da9034_regulator_ldo12_ops;
478 ri->desc.n_voltages = 16; 451 ri->desc.n_voltages = 16;
452 ri->desc.linear_ranges = da9034_ldo12_ranges;
453 ri->desc.n_linear_ranges = ARRAY_SIZE(da9034_ldo12_ranges);
479 } 454 }
480 455
481 if (ri->desc.id == DA9030_ID_LDO14) 456 if (ri->desc.id == DA9030_ID_LDO14)
@@ -485,7 +460,7 @@ static int da903x_regulator_probe(struct platform_device *pdev)
485 ri->desc.ops = &da9030_regulator_ldo1_15_ops; 460 ri->desc.ops = &da9030_regulator_ldo1_15_ops;
486 461
487 config.dev = &pdev->dev; 462 config.dev = &pdev->dev;
488 config.init_data = pdev->dev.platform_data; 463 config.init_data = dev_get_platdata(&pdev->dev);
489 config.driver_data = ri; 464 config.driver_data = ri;
490 465
491 rdev = regulator_register(&ri->desc, &config); 466 rdev = regulator_register(&ri->desc, &config);
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 96b569abb46c..1e4d483f6163 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -349,7 +349,7 @@ static int da9052_regulator_probe(struct platform_device *pdev)
349 return -ENOMEM; 349 return -ENOMEM;
350 350
351 da9052 = dev_get_drvdata(pdev->dev.parent); 351 da9052 = dev_get_drvdata(pdev->dev.parent);
352 pdata = da9052->dev->platform_data; 352 pdata = dev_get_platdata(da9052->dev);
353 regulator->da9052 = da9052; 353 regulator->da9052 = da9052;
354 354
355 regulator->info = find_regulator_info(regulator->da9052->chip_id, 355 regulator->info = find_regulator_info(regulator->da9052->chip_id,
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 30221099d09c..77b53e5a231c 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -535,7 +535,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
535 struct regulator_config config = { }; 535 struct regulator_config config = { };
536 struct da9055_regulator *regulator; 536 struct da9055_regulator *regulator;
537 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent); 537 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
538 struct da9055_pdata *pdata = da9055->dev->platform_data; 538 struct da9055_pdata *pdata = dev_get_platdata(da9055->dev);
539 int ret, irq; 539 int ret, irq;
540 540
541 if (pdata == NULL || pdata->regulators[pdev->id] == NULL) 541 if (pdata == NULL || pdata->regulators[pdev->id] == NULL)
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
new file mode 100644
index 000000000000..1a7816390773
--- /dev/null
+++ b/drivers/regulator/da9063-regulator.c
@@ -0,0 +1,934 @@
1/*
2 * Regulator driver for DA9063 PMIC series
3 *
4 * Copyright 2012 Dialog Semiconductors Ltd.
5 * Copyright 2013 Philipp Zabel, Pengutronix
6 *
7 * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
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#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22#include <linux/regmap.h>
23#include <linux/regulator/driver.h>
24#include <linux/regulator/machine.h>
25#include <linux/regulator/of_regulator.h>
26#include <linux/mfd/da9063/core.h>
27#include <linux/mfd/da9063/pdata.h>
28#include <linux/mfd/da9063/registers.h>
29
30
31/* Definition for registering regmap bit fields using a mask */
32#define BFIELD(_reg, _mask) \
33 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \
34 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1)
35
36/* Regulator capabilities and registers description */
37struct da9063_regulator_info {
38 struct regulator_desc desc;
39
40 /* Current limiting */
41 unsigned n_current_limits;
42 const int *current_limits;
43
44 /* DA9063 main register fields */
45 struct reg_field mode; /* buck mode of operation */
46 struct reg_field suspend;
47 struct reg_field sleep;
48 struct reg_field suspend_sleep;
49 unsigned int suspend_vsel_reg;
50 struct reg_field ilimit;
51
52 /* DA9063 event detection bit */
53 struct reg_field oc_event;
54};
55
56/* Macros for LDO */
57#define DA9063_LDO(chip, regl_name, min_mV, step_mV, max_mV) \
58 .desc.id = chip##_ID_##regl_name, \
59 .desc.name = __stringify(chip##_##regl_name), \
60 .desc.ops = &da9063_ldo_ops, \
61 .desc.min_uV = (min_mV) * 1000, \
62 .desc.uV_step = (step_mV) * 1000, \
63 .desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1), \
64 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
65 .desc.enable_mask = DA9063_LDO_EN, \
66 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \
67 .desc.vsel_mask = DA9063_V##regl_name##_MASK, \
68 .desc.linear_min_sel = DA9063_V##regl_name##_BIAS, \
69 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_LDO_SL), \
70 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_LDO_SL), \
71 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B
72
73/* Macros for voltage DC/DC converters (BUCKs) */
74#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
75 .desc.id = chip##_ID_##regl_name, \
76 .desc.name = __stringify(chip##_##regl_name), \
77 .desc.ops = &da9063_buck_ops, \
78 .desc.min_uV = (min_mV) * 1000, \
79 .desc.uV_step = (step_mV) * 1000, \
80 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
81 .current_limits = limits_array, \
82 .n_current_limits = ARRAY_SIZE(limits_array)
83
84#define DA9063_BUCK_COMMON_FIELDS(regl_name) \
85 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
86 .desc.enable_mask = DA9063_BUCK_EN, \
87 .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \
88 .desc.vsel_mask = DA9063_VBUCK_MASK, \
89 .desc.linear_min_sel = DA9063_VBUCK_BIAS, \
90 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_BUCK_SL), \
91 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_BUCK_SL), \
92 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B, \
93 .mode = BFIELD(DA9063_REG_##regl_name##_CFG, DA9063_BUCK_MODE_MASK)
94
95/* Defines asignment of regulators info table to chip model */
96struct da9063_dev_model {
97 const struct da9063_regulator_info *regulator_info;
98 unsigned n_regulators;
99 unsigned dev_model;
100};
101
102/* Single regulator settings */
103struct da9063_regulator {
104 struct regulator_desc desc;
105 struct regulator_dev *rdev;
106 struct da9063 *hw;
107 const struct da9063_regulator_info *info;
108
109 struct regmap_field *mode;
110 struct regmap_field *suspend;
111 struct regmap_field *sleep;
112 struct regmap_field *suspend_sleep;
113 struct regmap_field *ilimit;
114};
115
116/* Encapsulates all information for the regulators driver */
117struct da9063_regulators {
118 int irq_ldo_lim;
119 int irq_uvov;
120
121 unsigned n_regulators;
122 /* Array size to be defined during init. Keep at end. */
123 struct da9063_regulator regulator[0];
124};
125
126/* BUCK modes for DA9063 */
127enum {
128 BUCK_MODE_MANUAL, /* 0 */
129 BUCK_MODE_SLEEP, /* 1 */
130 BUCK_MODE_SYNC, /* 2 */
131 BUCK_MODE_AUTO /* 3 */
132};
133
134/* Regulator operations */
135
136/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
137 Entry indexes corresponds to register values. */
138static const int da9063_buck_a_limits[] = {
139 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
140 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
141};
142
143/* Current limits array (in uA) for BMEM, BIO, BPERI.
144 Entry indexes corresponds to register values. */
145static const int da9063_buck_b_limits[] = {
146 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
147 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
148};
149
150/* Current limits array (in uA) for merged BCORE1 and BCORE2.
151 Entry indexes corresponds to register values. */
152static const int da9063_bcores_merged_limits[] = {
153 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
154 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
155};
156
157/* Current limits array (in uA) for merged BMEM and BIO.
158 Entry indexes corresponds to register values. */
159static const int da9063_bmem_bio_merged_limits[] = {
160 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
161 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
162};
163
164static int da9063_set_current_limit(struct regulator_dev *rdev,
165 int min_uA, int max_uA)
166{
167 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
168 const struct da9063_regulator_info *rinfo = regl->info;
169 int n, tval;
170
171 for (n = 0; n < rinfo->n_current_limits; n++) {
172 tval = rinfo->current_limits[n];
173 if (tval >= min_uA && tval <= max_uA)
174 return regmap_field_write(regl->ilimit, n);
175 }
176
177 return -EINVAL;
178}
179
180static int da9063_get_current_limit(struct regulator_dev *rdev)
181{
182 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
183 const struct da9063_regulator_info *rinfo = regl->info;
184 unsigned int sel;
185 int ret;
186
187 ret = regmap_field_read(regl->ilimit, &sel);
188 if (ret < 0)
189 return ret;
190
191 if (sel >= rinfo->n_current_limits)
192 sel = rinfo->n_current_limits - 1;
193
194 return rinfo->current_limits[sel];
195}
196
197static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
198{
199 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
200 unsigned val;
201
202 switch (mode) {
203 case REGULATOR_MODE_FAST:
204 val = BUCK_MODE_SYNC;
205 break;
206 case REGULATOR_MODE_NORMAL:
207 val = BUCK_MODE_AUTO;
208 break;
209 case REGULATOR_MODE_STANDBY:
210 val = BUCK_MODE_SLEEP;
211 break;
212 default:
213 return -EINVAL;
214 }
215
216 return regmap_field_write(regl->mode, val);
217}
218
219/*
220 * Bucks use single mode register field for normal operation
221 * and suspend state.
222 * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
223 */
224
225static unsigned da9063_buck_get_mode(struct regulator_dev *rdev)
226{
227 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
228 struct regmap_field *field;
229 unsigned int val, mode = 0;
230 int ret;
231
232 ret = regmap_field_read(regl->mode, &val);
233 if (ret < 0)
234 return ret;
235
236 switch (val) {
237 default:
238 case BUCK_MODE_MANUAL:
239 mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
240 /* Sleep flag bit decides the mode */
241 break;
242 case BUCK_MODE_SLEEP:
243 return REGULATOR_MODE_STANDBY;
244 case BUCK_MODE_SYNC:
245 return REGULATOR_MODE_FAST;
246 case BUCK_MODE_AUTO:
247 return REGULATOR_MODE_NORMAL;
248 }
249
250 /* Detect current regulator state */
251 ret = regmap_field_read(regl->suspend, &val);
252 if (ret < 0)
253 return 0;
254
255 /* Read regulator mode from proper register, depending on state */
256 if (val)
257 field = regl->suspend_sleep;
258 else
259 field = regl->sleep;
260
261 ret = regmap_field_read(field, &val);
262 if (ret < 0)
263 return 0;
264
265 if (val)
266 mode &= REGULATOR_MODE_STANDBY;
267 else
268 mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
269
270 return mode;
271}
272
273/*
274 * LDOs use sleep flags - one for normal and one for suspend state.
275 * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
276 */
277
278static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
279{
280 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
281 unsigned val;
282
283 switch (mode) {
284 case REGULATOR_MODE_NORMAL:
285 val = 0;
286 break;
287 case REGULATOR_MODE_STANDBY:
288 val = 1;
289 break;
290 default:
291 return -EINVAL;
292 }
293
294 return regmap_field_write(regl->sleep, val);
295}
296
297static unsigned da9063_ldo_get_mode(struct regulator_dev *rdev)
298{
299 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
300 struct regmap_field *field;
301 int ret, val;
302
303 /* Detect current regulator state */
304 ret = regmap_field_read(regl->suspend, &val);
305 if (ret < 0)
306 return 0;
307
308 /* Read regulator mode from proper register, depending on state */
309 if (val)
310 field = regl->suspend_sleep;
311 else
312 field = regl->sleep;
313
314 ret = regmap_field_read(field, &val);
315 if (ret < 0)
316 return 0;
317
318 if (val)
319 return REGULATOR_MODE_STANDBY;
320 else
321 return REGULATOR_MODE_NORMAL;
322}
323
324static int da9063_buck_get_status(struct regulator_dev *rdev)
325{
326 int ret = regulator_is_enabled_regmap(rdev);
327
328 if (ret == 0) {
329 ret = REGULATOR_STATUS_OFF;
330 } else if (ret > 0) {
331 ret = da9063_buck_get_mode(rdev);
332 if (ret > 0)
333 ret = regulator_mode_to_status(ret);
334 else if (ret == 0)
335 ret = -EIO;
336 }
337
338 return ret;
339}
340
341static int da9063_ldo_get_status(struct regulator_dev *rdev)
342{
343 int ret = regulator_is_enabled_regmap(rdev);
344
345 if (ret == 0) {
346 ret = REGULATOR_STATUS_OFF;
347 } else if (ret > 0) {
348 ret = da9063_ldo_get_mode(rdev);
349 if (ret > 0)
350 ret = regulator_mode_to_status(ret);
351 else if (ret == 0)
352 ret = -EIO;
353 }
354
355 return ret;
356}
357
358static int da9063_set_suspend_voltage(struct regulator_dev *rdev, int uV)
359{
360 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
361 const struct da9063_regulator_info *rinfo = regl->info;
362 int ret, sel;
363
364 sel = regulator_map_voltage_linear(rdev, uV, uV);
365 if (sel < 0)
366 return -EINVAL;
367
368 sel <<= ffs(rdev->desc->vsel_mask) - 1;
369
370 ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg,
371 rdev->desc->vsel_mask, sel);
372
373 return ret;
374}
375
376static int da9063_suspend_enable(struct regulator_dev *rdev)
377{
378 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
379
380 return regmap_field_write(regl->suspend, 1);
381}
382
383static int da9063_suspend_disable(struct regulator_dev *rdev)
384{
385 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
386
387 return regmap_field_write(regl->suspend, 0);
388}
389
390static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
391{
392 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
393 int val;
394
395 switch (mode) {
396 case REGULATOR_MODE_FAST:
397 val = BUCK_MODE_SYNC;
398 break;
399 case REGULATOR_MODE_NORMAL:
400 val = BUCK_MODE_AUTO;
401 break;
402 case REGULATOR_MODE_STANDBY:
403 val = BUCK_MODE_SLEEP;
404 break;
405 default:
406 return -EINVAL;
407 }
408
409 return regmap_field_write(regl->mode, val);
410}
411
412static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
413{
414 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
415 unsigned val;
416
417 switch (mode) {
418 case REGULATOR_MODE_NORMAL:
419 val = 0;
420 break;
421 case REGULATOR_MODE_STANDBY:
422 val = 1;
423 break;
424 default:
425 return -EINVAL;
426 }
427
428 return regmap_field_write(regl->suspend_sleep, val);
429}
430
431static struct regulator_ops da9063_buck_ops = {
432 .enable = regulator_enable_regmap,
433 .disable = regulator_disable_regmap,
434 .is_enabled = regulator_is_enabled_regmap,
435 .get_voltage_sel = regulator_get_voltage_sel_regmap,
436 .set_voltage_sel = regulator_set_voltage_sel_regmap,
437 .list_voltage = regulator_list_voltage_linear,
438 .set_current_limit = da9063_set_current_limit,
439 .get_current_limit = da9063_get_current_limit,
440 .set_mode = da9063_buck_set_mode,
441 .get_mode = da9063_buck_get_mode,
442 .get_status = da9063_buck_get_status,
443 .set_suspend_voltage = da9063_set_suspend_voltage,
444 .set_suspend_enable = da9063_suspend_enable,
445 .set_suspend_disable = da9063_suspend_disable,
446 .set_suspend_mode = da9063_buck_set_suspend_mode,
447};
448
449static struct regulator_ops da9063_ldo_ops = {
450 .enable = regulator_enable_regmap,
451 .disable = regulator_disable_regmap,
452 .is_enabled = regulator_is_enabled_regmap,
453 .get_voltage_sel = regulator_get_voltage_sel_regmap,
454 .set_voltage_sel = regulator_set_voltage_sel_regmap,
455 .list_voltage = regulator_list_voltage_linear,
456 .set_mode = da9063_ldo_set_mode,
457 .get_mode = da9063_ldo_get_mode,
458 .get_status = da9063_ldo_get_status,
459 .set_suspend_voltage = da9063_set_suspend_voltage,
460 .set_suspend_enable = da9063_suspend_enable,
461 .set_suspend_disable = da9063_suspend_disable,
462 .set_suspend_mode = da9063_ldo_set_suspend_mode,
463};
464
465/* Info of regulators for DA9063 */
466static const struct da9063_regulator_info da9063_regulator_info[] = {
467 {
468 DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,
469 da9063_buck_a_limits),
470 DA9063_BUCK_COMMON_FIELDS(BCORE1),
471 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
472 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
473 DA9063_BCORE1_ILIM_MASK),
474 },
475 {
476 DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,
477 da9063_buck_a_limits),
478 DA9063_BUCK_COMMON_FIELDS(BCORE2),
479 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),
480 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
481 DA9063_BCORE2_ILIM_MASK),
482 },
483 {
484 DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,
485 da9063_buck_a_limits),
486 DA9063_BUCK_COMMON_FIELDS(BPRO),
487 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),
488 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
489 DA9063_BPRO_ILIM_MASK),
490 },
491 {
492 DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,
493 da9063_buck_b_limits),
494 DA9063_BUCK_COMMON_FIELDS(BMEM),
495 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
496 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
497 DA9063_BMEM_ILIM_MASK),
498 },
499 {
500 DA9063_BUCK(DA9063, BIO, 800, 20, 3340,
501 da9063_buck_b_limits),
502 DA9063_BUCK_COMMON_FIELDS(BIO),
503 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),
504 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
505 DA9063_BIO_ILIM_MASK),
506 },
507 {
508 DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,
509 da9063_buck_b_limits),
510 DA9063_BUCK_COMMON_FIELDS(BPERI),
511 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),
512 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
513 DA9063_BPERI_ILIM_MASK),
514 },
515 {
516 DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
517 da9063_bcores_merged_limits),
518 /* BCORES_MERGED uses the same register fields as BCORE1 */
519 DA9063_BUCK_COMMON_FIELDS(BCORE1),
520 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
521 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
522 DA9063_BCORE1_ILIM_MASK),
523 },
524 {
525 DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
526 da9063_bmem_bio_merged_limits),
527 /* BMEM_BIO_MERGED uses the same register fields as BMEM */
528 DA9063_BUCK_COMMON_FIELDS(BMEM),
529 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
530 .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
531 DA9063_BMEM_ILIM_MASK),
532 },
533 {
534 DA9063_LDO(DA9063, LDO1, 600, 20, 1860),
535 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO1_SEL),
536 },
537 {
538 DA9063_LDO(DA9063, LDO2, 600, 20, 1860),
539 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO2_SEL),
540 },
541 {
542 DA9063_LDO(DA9063, LDO3, 900, 20, 3440),
543 .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO3_SEL),
544 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO3_LIM),
545 },
546 {
547 DA9063_LDO(DA9063, LDO4, 900, 20, 3440),
548 .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VLDO4_SEL),
549 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO4_LIM),
550 },
551 {
552 DA9063_LDO(DA9063, LDO5, 900, 50, 3600),
553 .suspend = BFIELD(DA9063_REG_LDO5_CONT, DA9063_VLDO5_SEL),
554 },
555 {
556 DA9063_LDO(DA9063, LDO6, 900, 50, 3600),
557 .suspend = BFIELD(DA9063_REG_LDO6_CONT, DA9063_VLDO6_SEL),
558 },
559 {
560 DA9063_LDO(DA9063, LDO7, 900, 50, 3600),
561 .suspend = BFIELD(DA9063_REG_LDO7_CONT, DA9063_VLDO7_SEL),
562 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO7_LIM),
563 },
564 {
565 DA9063_LDO(DA9063, LDO8, 900, 50, 3600),
566 .suspend = BFIELD(DA9063_REG_LDO8_CONT, DA9063_VLDO8_SEL),
567 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO8_LIM),
568 },
569 {
570 DA9063_LDO(DA9063, LDO9, 950, 50, 3600),
571 .suspend = BFIELD(DA9063_REG_LDO9_CONT, DA9063_VLDO9_SEL),
572 },
573 {
574 DA9063_LDO(DA9063, LDO10, 900, 50, 3600),
575 .suspend = BFIELD(DA9063_REG_LDO10_CONT, DA9063_VLDO10_SEL),
576 },
577 {
578 DA9063_LDO(DA9063, LDO11, 900, 50, 3600),
579 .suspend = BFIELD(DA9063_REG_LDO11_CONT, DA9063_VLDO11_SEL),
580 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO11_LIM),
581 },
582};
583
584/* Link chip model with regulators info table */
585static struct da9063_dev_model regulators_models[] = {
586 {
587 .regulator_info = da9063_regulator_info,
588 .n_regulators = ARRAY_SIZE(da9063_regulator_info),
589 .dev_model = PMIC_DA9063,
590 },
591 { }
592};
593
594/* Regulator interrupt handlers */
595static irqreturn_t da9063_ldo_lim_event(int irq, void *data)
596{
597 struct da9063_regulators *regulators = data;
598 struct da9063 *hw = regulators->regulator[0].hw;
599 struct da9063_regulator *regl;
600 int bits, i , ret;
601
602 ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits);
603 if (ret < 0)
604 return IRQ_NONE;
605
606 for (i = regulators->n_regulators - 1; i >= 0; i--) {
607 regl = &regulators->regulator[i];
608 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D)
609 continue;
610
611 if (BIT(regl->info->oc_event.lsb) & bits)
612 regulator_notifier_call_chain(regl->rdev,
613 REGULATOR_EVENT_OVER_CURRENT, NULL);
614 }
615
616 return IRQ_HANDLED;
617}
618
619/*
620 * Probing and Initialisation functions
621 */
622static const struct regulator_init_data *da9063_get_regulator_initdata(
623 const struct da9063_regulators_pdata *regl_pdata, int id)
624{
625 int i;
626
627 for (i = 0; i < regl_pdata->n_regulators; i++) {
628 if (id == regl_pdata->regulator_data[i].id)
629 return regl_pdata->regulator_data[i].initdata;
630 }
631
632 return NULL;
633}
634
635#ifdef CONFIG_OF
636static struct of_regulator_match da9063_matches[] = {
637 [DA9063_ID_BCORE1] = { .name = "bcore1" },
638 [DA9063_ID_BCORE2] = { .name = "bcore2" },
639 [DA9063_ID_BPRO] = { .name = "bpro", },
640 [DA9063_ID_BMEM] = { .name = "bmem", },
641 [DA9063_ID_BIO] = { .name = "bio", },
642 [DA9063_ID_BPERI] = { .name = "bperi", },
643 [DA9063_ID_BCORES_MERGED] = { .name = "bcores-merged" },
644 [DA9063_ID_BMEM_BIO_MERGED] = { .name = "bmem-bio-merged", },
645 [DA9063_ID_LDO1] = { .name = "ldo1", },
646 [DA9063_ID_LDO2] = { .name = "ldo2", },
647 [DA9063_ID_LDO3] = { .name = "ldo3", },
648 [DA9063_ID_LDO4] = { .name = "ldo4", },
649 [DA9063_ID_LDO5] = { .name = "ldo5", },
650 [DA9063_ID_LDO6] = { .name = "ldo6", },
651 [DA9063_ID_LDO7] = { .name = "ldo7", },
652 [DA9063_ID_LDO8] = { .name = "ldo8", },
653 [DA9063_ID_LDO9] = { .name = "ldo9", },
654 [DA9063_ID_LDO10] = { .name = "ldo10", },
655 [DA9063_ID_LDO11] = { .name = "ldo11", },
656};
657
658static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
659 struct platform_device *pdev,
660 struct of_regulator_match **da9063_reg_matches)
661{
662 struct da9063_regulators_pdata *pdata;
663 struct da9063_regulator_data *rdata;
664 struct device_node *node;
665 int i, n, num;
666
667 node = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
668 if (!node) {
669 dev_err(&pdev->dev, "Regulators device node not found\n");
670 return ERR_PTR(-ENODEV);
671 }
672
673 num = of_regulator_match(&pdev->dev, node, da9063_matches,
674 ARRAY_SIZE(da9063_matches));
675 if (num < 0) {
676 dev_err(&pdev->dev, "Failed to match regulators\n");
677 return ERR_PTR(-EINVAL);
678 }
679
680 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
681 if (!pdata)
682 return ERR_PTR(-ENOMEM);
683
684 pdata->regulator_data = devm_kzalloc(&pdev->dev,
685 num * sizeof(*pdata->regulator_data),
686 GFP_KERNEL);
687 if (!pdata->regulator_data)
688 return ERR_PTR(-ENOMEM);
689 pdata->n_regulators = num;
690
691 n = 0;
692 for (i = 0; i < ARRAY_SIZE(da9063_matches); i++) {
693 if (!da9063_matches[i].init_data)
694 continue;
695
696 rdata = &pdata->regulator_data[n];
697 rdata->id = i;
698 rdata->initdata = da9063_matches[i].init_data;
699
700 n++;
701 };
702
703 *da9063_reg_matches = da9063_matches;
704 return pdata;
705}
706#else
707static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
708 struct platform_device *pdev,
709 struct of_regulator_match **da9063_reg_matches)
710{
711 da9063_reg_matches = NULL;
712 return PTR_ERR(-ENODEV);
713}
714#endif
715
716static int da9063_regulator_probe(struct platform_device *pdev)
717{
718 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
719 struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev);
720 struct of_regulator_match *da9063_reg_matches;
721 struct da9063_regulators_pdata *regl_pdata;
722 const struct da9063_dev_model *model;
723 struct da9063_regulators *regulators;
724 struct da9063_regulator *regl;
725 struct regulator_config config;
726 bool bcores_merged, bmem_bio_merged;
727 int id, irq, n, n_regulators, ret, val;
728 size_t size;
729
730 regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL;
731
732 if (!regl_pdata)
733 regl_pdata = da9063_parse_regulators_dt(pdev,
734 &da9063_reg_matches);
735
736 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) {
737 dev_err(&pdev->dev,
738 "No regulators defined for the platform\n");
739 return PTR_ERR(regl_pdata);
740 }
741
742 /* Find regulators set for particular device model */
743 for (model = regulators_models; model->regulator_info; model++) {
744 if (model->dev_model == da9063->model)
745 break;
746 }
747 if (!model->regulator_info) {
748 dev_err(&pdev->dev, "Chip model not recognised (%u)\n",
749 da9063->model);
750 return -ENODEV;
751 }
752
753 ret = regmap_read(da9063->regmap, DA9063_REG_CONFIG_H, &val);
754 if (ret < 0) {
755 dev_err(&pdev->dev,
756 "Error while reading BUCKs configuration\n");
757 return -EIO;
758 }
759 bcores_merged = val & DA9063_BCORE_MERGE;
760 bmem_bio_merged = val & DA9063_BUCK_MERGE;
761
762 n_regulators = model->n_regulators;
763 if (bcores_merged)
764 n_regulators -= 2; /* remove BCORE1, BCORE2 */
765 else
766 n_regulators--; /* remove BCORES_MERGED */
767 if (bmem_bio_merged)
768 n_regulators -= 2; /* remove BMEM, BIO */
769 else
770 n_regulators--; /* remove BMEM_BIO_MERGED */
771
772 /* Allocate memory required by usable regulators */
773 size = sizeof(struct da9063_regulators) +
774 n_regulators * sizeof(struct da9063_regulator);
775 regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
776 if (!regulators) {
777 dev_err(&pdev->dev, "No memory for regulators\n");
778 return -ENOMEM;
779 }
780
781 regulators->n_regulators = n_regulators;
782 platform_set_drvdata(pdev, regulators);
783
784 /* Register all regulators declared in platform information */
785 n = 0;
786 id = 0;
787 while (n < regulators->n_regulators) {
788 /* Skip regulator IDs depending on merge mode configuration */
789 switch (id) {
790 case DA9063_ID_BCORE1:
791 case DA9063_ID_BCORE2:
792 if (bcores_merged) {
793 id++;
794 continue;
795 }
796 break;
797 case DA9063_ID_BMEM:
798 case DA9063_ID_BIO:
799 if (bmem_bio_merged) {
800 id++;
801 continue;
802 }
803 break;
804 case DA9063_ID_BCORES_MERGED:
805 if (!bcores_merged) {
806 id++;
807 continue;
808 }
809 break;
810 case DA9063_ID_BMEM_BIO_MERGED:
811 if (!bmem_bio_merged) {
812 id++;
813 continue;
814 }
815 break;
816 }
817
818 /* Initialise regulator structure */
819 regl = &regulators->regulator[n];
820 regl->hw = da9063;
821 regl->info = &model->regulator_info[id];
822 regl->desc = regl->info->desc;
823 regl->desc.type = REGULATOR_VOLTAGE;
824 regl->desc.owner = THIS_MODULE;
825
826 if (regl->info->mode.reg)
827 regl->mode = devm_regmap_field_alloc(&pdev->dev,
828 da9063->regmap, regl->info->mode);
829 if (regl->info->suspend.reg)
830 regl->suspend = devm_regmap_field_alloc(&pdev->dev,
831 da9063->regmap, regl->info->suspend);
832 if (regl->info->sleep.reg)
833 regl->sleep = devm_regmap_field_alloc(&pdev->dev,
834 da9063->regmap, regl->info->sleep);
835 if (regl->info->suspend_sleep.reg)
836 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev,
837 da9063->regmap, regl->info->suspend_sleep);
838 if (regl->info->ilimit.reg)
839 regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
840 da9063->regmap, regl->info->ilimit);
841
842 /* Register regulator */
843 memset(&config, 0, sizeof(config));
844 config.dev = &pdev->dev;
845 config.init_data = da9063_get_regulator_initdata(regl_pdata, id);
846 config.driver_data = regl;
847 if (da9063_reg_matches)
848 config.of_node = da9063_reg_matches[id].of_node;
849 config.regmap = da9063->regmap;
850 regl->rdev = regulator_register(&regl->desc, &config);
851 if (IS_ERR(regl->rdev)) {
852 dev_err(&pdev->dev,
853 "Failed to register %s regulator\n",
854 regl->desc.name);
855 ret = PTR_ERR(regl->rdev);
856 goto err;
857 }
858 id++;
859 n++;
860 }
861
862 /* LDOs overcurrent event support */
863 irq = platform_get_irq_byname(pdev, "LDO_LIM");
864 if (irq < 0) {
865 ret = irq;
866 dev_err(&pdev->dev, "Failed to get IRQ.\n");
867 goto err;
868 }
869
870 regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq);
871 if (regulators->irq_ldo_lim >= 0) {
872 ret = request_threaded_irq(regulators->irq_ldo_lim,
873 NULL, da9063_ldo_lim_event,
874 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
875 "LDO_LIM", regulators);
876 if (ret) {
877 dev_err(&pdev->dev,
878 "Failed to request LDO_LIM IRQ.\n");
879 regulators->irq_ldo_lim = -ENXIO;
880 }
881 }
882
883 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}
892
893static int da9063_regulator_remove(struct platform_device *pdev)
894{
895 struct da9063_regulators *regulators = platform_get_drvdata(pdev);
896 struct da9063_regulator *regl;
897
898 free_irq(regulators->irq_ldo_lim, regulators);
899 free_irq(regulators->irq_uvov, regulators);
900
901 for (regl = &regulators->regulator[regulators->n_regulators - 1];
902 regl >= &regulators->regulator[0]; regl--)
903 regulator_unregister(regl->rdev);
904
905 return 0;
906}
907
908static struct platform_driver da9063_regulator_driver = {
909 .driver = {
910 .name = DA9063_DRVNAME_REGULATORS,
911 .owner = THIS_MODULE,
912 },
913 .probe = da9063_regulator_probe,
914 .remove = da9063_regulator_remove,
915};
916
917static int __init da9063_regulator_init(void)
918{
919 return platform_driver_register(&da9063_regulator_driver);
920}
921subsys_initcall(da9063_regulator_init);
922
923static void __exit da9063_regulator_cleanup(void)
924{
925 platform_driver_unregister(&da9063_regulator_driver);
926}
927module_exit(da9063_regulator_cleanup);
928
929
930/* Module information */
931MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>");
932MODULE_DESCRIPTION("DA9063 regulators driver");
933MODULE_LICENSE("GPL");
934MODULE_ALIAS("paltform:" DA9063_DRVNAME_REGULATORS);
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
new file mode 100644
index 000000000000..f0fe54b38977
--- /dev/null
+++ b/drivers/regulator/da9210-regulator.c
@@ -0,0 +1,196 @@
1/*
2 * da9210-regulator.c - Regulator device driver for DA9210
3 * Copyright (C) 2013 Dialog Semiconductor Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include <linux/err.h>
22#include <linux/i2c.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/regulator/driver.h>
27#include <linux/regulator/machine.h>
28#include <linux/regmap.h>
29
30#include "da9210-regulator.h"
31
32struct da9210 {
33 struct regulator_dev *rdev;
34 struct regmap *regmap;
35};
36
37static const struct regmap_config da9210_regmap_config = {
38 .reg_bits = 8,
39 .val_bits = 8,
40};
41
42static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
43 int max_uA);
44static int da9210_get_current_limit(struct regulator_dev *rdev);
45
46static struct regulator_ops da9210_buck_ops = {
47 .enable = regulator_enable_regmap,
48 .disable = regulator_disable_regmap,
49 .is_enabled = regulator_is_enabled_regmap,
50 .set_voltage_sel = regulator_set_voltage_sel_regmap,
51 .get_voltage_sel = regulator_get_voltage_sel_regmap,
52 .list_voltage = regulator_list_voltage_linear,
53 .set_current_limit = da9210_set_current_limit,
54 .get_current_limit = da9210_get_current_limit,
55};
56
57/* Default limits measured in millivolts and milliamps */
58#define DA9210_MIN_MV 300
59#define DA9210_MAX_MV 1570
60#define DA9210_STEP_MV 10
61
62/* Current limits for buck (uA) indices corresponds with register values */
63static const int da9210_buck_limits[] = {
64 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000,
65 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000
66};
67
68static const struct regulator_desc da9210_reg = {
69 .name = "DA9210",
70 .id = 0,
71 .ops = &da9210_buck_ops,
72 .type = REGULATOR_VOLTAGE,
73 .n_voltages = ((DA9210_MAX_MV - DA9210_MIN_MV) / DA9210_STEP_MV) + 1,
74 .min_uV = (DA9210_MIN_MV * 1000),
75 .uV_step = (DA9210_STEP_MV * 1000),
76 .vsel_reg = DA9210_REG_VBUCK_A,
77 .vsel_mask = DA9210_VBUCK_MASK,
78 .enable_reg = DA9210_REG_BUCK_CONT,
79 .enable_mask = DA9210_BUCK_EN,
80 .owner = THIS_MODULE,
81};
82
83static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
84 int max_uA)
85{
86 struct da9210 *chip = rdev_get_drvdata(rdev);
87 unsigned int sel;
88 int i;
89
90 /* search for closest to maximum */
91 for (i = ARRAY_SIZE(da9210_buck_limits)-1; i >= 0; i--) {
92 if (min_uA <= da9210_buck_limits[i] &&
93 max_uA >= da9210_buck_limits[i]) {
94 sel = i;
95 sel = sel << DA9210_BUCK_ILIM_SHIFT;
96 return regmap_update_bits(chip->regmap,
97 DA9210_REG_BUCK_ILIM,
98 DA9210_BUCK_ILIM_MASK, sel);
99 }
100 }
101
102 return -EINVAL;
103}
104
105static int da9210_get_current_limit(struct regulator_dev *rdev)
106{
107 struct da9210 *chip = rdev_get_drvdata(rdev);
108 unsigned int data;
109 unsigned int sel;
110 int ret;
111
112 ret = regmap_read(chip->regmap, DA9210_REG_BUCK_ILIM, &data);
113 if (ret < 0)
114 return ret;
115
116 /* select one of 16 values: 0000 (1600mA) to 1111 (4600mA) */
117 sel = (data & DA9210_BUCK_ILIM_MASK) >> DA9210_BUCK_ILIM_SHIFT;
118
119 return da9210_buck_limits[sel];
120}
121
122/*
123 * I2C driver interface functions
124 */
125static int da9210_i2c_probe(struct i2c_client *i2c,
126 const struct i2c_device_id *id)
127{
128 struct da9210 *chip;
129 struct da9210_pdata *pdata = i2c->dev.platform_data;
130 struct regulator_dev *rdev = NULL;
131 struct regulator_config config = { };
132 int error;
133
134 chip = devm_kzalloc(&i2c->dev, sizeof(struct da9210), GFP_KERNEL);
135 if (NULL == chip) {
136 dev_err(&i2c->dev,
137 "Cannot kzalloc memory for regulator structure\n");
138 return -ENOMEM;
139 }
140
141 chip->regmap = devm_regmap_init_i2c(i2c, &da9210_regmap_config);
142 if (IS_ERR(chip->regmap)) {
143 error = PTR_ERR(chip->regmap);
144 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
145 error);
146 return error;
147 }
148
149 config.dev = &i2c->dev;
150 if (pdata)
151 config.init_data = &pdata->da9210_constraints;
152 config.driver_data = chip;
153 config.regmap = chip->regmap;
154
155 rdev = regulator_register(&da9210_reg, &config);
156 if (IS_ERR(rdev)) {
157 dev_err(&i2c->dev, "Failed to register DA9210 regulator\n");
158 return PTR_ERR(rdev);
159 }
160
161 chip->rdev = rdev;
162
163 i2c_set_clientdata(i2c, chip);
164
165 return 0;
166}
167
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[] = {
176 {"da9210", 0},
177 {},
178};
179
180MODULE_DEVICE_TABLE(i2c, da9210_i2c_id);
181
182static struct i2c_driver da9210_regulator_driver = {
183 .driver = {
184 .name = "da9210",
185 .owner = THIS_MODULE,
186 },
187 .probe = da9210_i2c_probe,
188 .remove = da9210_i2c_remove,
189 .id_table = da9210_i2c_id,
190};
191
192module_i2c_driver(da9210_regulator_driver);
193
194MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
195MODULE_DESCRIPTION("Regulator device driver for Dialog DA9210");
196MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/da9210-regulator.h b/drivers/regulator/da9210-regulator.h
new file mode 100644
index 000000000000..749c550808b6
--- /dev/null
+++ b/drivers/regulator/da9210-regulator.h
@@ -0,0 +1,288 @@
1
2/*
3 * da9210-regulator.h - Regulator definitions for DA9210
4 * Copyright (C) 2013 Dialog Semiconductor Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#ifndef __DA9210_REGISTERS_H__
23#define __DA9210_REGISTERS_H__
24
25struct da9210_pdata {
26 struct regulator_init_data da9210_constraints;
27};
28
29/* Page selection */
30#define DA9210_REG_PAGE_CON 0x00
31
32/* System Control and Event Registers */
33#define DA9210_REG_STATUS_A 0x50
34#define DA9210_REG_STATUS_B 0x51
35#define DA9210_REG_EVENT_A 0x52
36#define DA9210_REG_EVENT_B 0x53
37#define DA9210_REG_MASK_A 0x54
38#define DA9210_REG_MASK_B 0x55
39#define DA9210_REG_CONTROL_A 0x56
40
41/* GPIO Control Registers */
42#define DA9210_REG_GPIO_0_1 0x58
43#define DA9210_REG_GPIO_2_3 0x59
44#define DA9210_REG_GPIO_4_5 0x5A
45#define DA9210_REG_GPIO_6 0x5B
46
47/* Regulator Registers */
48#define DA9210_REG_BUCK_CONT 0x5D
49#define DA9210_REG_BUCK_ILIM 0xD0
50#define DA9210_REG_BUCK_CONF1 0xD1
51#define DA9210_REG_BUCK_CONF2 0xD2
52#define DA9210_REG_VBACK_AUTO 0xD4
53#define DA9210_REG_VBACK_BASE 0xD5
54#define DA9210_REG_VBACK_MAX_DVC_IF 0xD6
55#define DA9210_REG_VBACK_DVC 0xD7
56#define DA9210_REG_VBUCK_A 0xD8
57#define DA9210_REG_VBUCK_B 0xD9
58
59/* I2C Interface Settings */
60#define DA9210_REG_INTERFACE 0x105
61
62/* OTP */
63#define DA9210_REG_OPT_COUNT 0x140
64#define DA9210_REG_OPT_ADDR 0x141
65#define DA9210_REG_OPT_DATA 0x142
66
67/* Customer Trim and Configuration */
68#define DA9210_REG_CONFIG_A 0x143
69#define DA9210_REG_CONFIG_B 0x144
70#define DA9210_REG_CONFIG_C 0x145
71#define DA9210_REG_CONFIG_D 0x146
72#define DA9210_REG_CONFIG_E 0x147
73
74
75/*
76 * Registers bits
77 */
78/* DA9210_REG_PAGE_CON (addr=0x00) */
79#define DA9210_PEG_PAGE_SHIFT 0
80#define DA9210_REG_PAGE_MASK 0x0F
81/* On I2C registers 0x00 - 0xFF */
82#define DA9210_REG_PAGE0 0
83/* On I2C registers 0x100 - 0x1FF */
84#define DA9210_REG_PAGE2 2
85#define DA9210_PAGE_WRITE_MODE 0x00
86#define DA9210_REPEAT_WRITE_MODE 0x40
87#define DA9210_PAGE_REVERT 0x80
88
89/* DA9210_REG_STATUS_A (addr=0x50) */
90#define DA9210_GPI0 0x01
91#define DA9210_GPI1 0x02
92#define DA9210_GPI2 0x04
93#define DA9210_GPI3 0x08
94#define DA9210_GPI4 0x10
95#define DA9210_GPI5 0x20
96#define DA9210_GPI6 0x40
97
98/* DA9210_REG_EVENT_A (addr=0x52) */
99#define DA9210_E_GPI0 0x01
100#define DA9210_E_GPI1 0x02
101#define DA9210_E_GPI2 0x04
102#define DA9210_E_GPI3 0x08
103#define DA9210_E_GPI4 0x10
104#define DA9210_E_GPI5 0x20
105#define DA9210_E_GPI6 0x40
106
107/* DA9210_REG_EVENT_B (addr=0x53) */
108#define DA9210_E_OVCURR 0x01
109#define DA9210_E_NPWRGOOD 0x02
110#define DA9210_E_TEMP_WARN 0x04
111#define DA9210_E_TEMP_CRIT 0x08
112#define DA9210_E_VMAX 0x10
113
114/* DA9210_REG_MASK_A (addr=0x54) */
115#define DA9210_M_GPI0 0x01
116#define DA9210_M_GPI1 0x02
117#define DA9210_M_GPI2 0x04
118#define DA9210_M_GPI3 0x08
119#define DA9210_M_GPI4 0x10
120#define DA9210_M_GPI5 0x20
121#define DA9210_M_GPI6 0x40
122
123/* DA9210_REG_MASK_B (addr=0x55) */
124#define DA9210_M_OVCURR 0x01
125#define DA9210_M_NPWRGOOD 0x02
126#define DA9210_M_TEMP_WARN 0x04
127#define DA9210_M_TEMP_CRIT 0x08
128#define DA9210_M_VMAX 0x10
129
130/* DA9210_REG_CONTROL_A (addr=0x56) */
131#define DA9210_DEBOUNCING_SHIFT 0
132#define DA9210_DEBOUNCING_MASK 0x07
133#define DA9210_SLEW_RATE_SHIFT 3
134#define DA9210_SLEW_RATE_MASK 0x18
135#define DA9210_V_LOCK 0x20
136
137/* DA9210_REG_GPIO_0_1 (addr=0x58) */
138#define DA9210_GPIO0_PIN_SHIFT 0
139#define DA9210_GPIO0_PIN_MASK 0x03
140#define DA9210_GPIO0_PIN_GPI 0x00
141#define DA9210_GPIO0_PIN_GPO_OD 0x02
142#define DA9210_GPIO0_PIN_GPO 0x03
143#define DA9210_GPIO0_TYPE 0x04
144#define DA9210_GPIO0_TYPE_GPI 0x00
145#define DA9210_GPIO0_TYPE_GPO 0x04
146#define DA9210_GPIO0_MODE 0x08
147#define DA9210_GPIO1_PIN_SHIFT 4
148#define DA9210_GPIO1_PIN_MASK 0x30
149#define DA9210_GPIO1_PIN_GPI 0x00
150#define DA9210_GPIO1_PIN_VERROR 0x10
151#define DA9210_GPIO1_PIN_GPO_OD 0x20
152#define DA9210_GPIO1_PIN_GPO 0x30
153#define DA9210_GPIO1_TYPE_SHIFT 0x40
154#define DA9210_GPIO1_TYPE_GPI 0x00
155#define DA9210_GPIO1_TYPE_GPO 0x40
156#define DA9210_GPIO1_MODE 0x80
157
158/* DA9210_REG_GPIO_2_3 (addr=0x59) */
159#define DA9210_GPIO2_PIN_SHIFT 0
160#define DA9210_GPIO2_PIN_MASK 0x03
161#define DA9210_GPIO2_PIN_GPI 0x00
162#define DA9210_GPIO5_PIN_BUCK_CLK 0x10
163#define DA9210_GPIO2_PIN_GPO_OD 0x02
164#define DA9210_GPIO2_PIN_GPO 0x03
165#define DA9210_GPIO2_TYPE 0x04
166#define DA9210_GPIO2_TYPE_GPI 0x00
167#define DA9210_GPIO2_TYPE_GPO 0x04
168#define DA9210_GPIO2_MODE 0x08
169#define DA9210_GPIO3_PIN_SHIFT 4
170#define DA9210_GPIO3_PIN_MASK 0x30
171#define DA9210_GPIO3_PIN_GPI 0x00
172#define DA9210_GPIO3_PIN_IERROR 0x10
173#define DA9210_GPIO3_PIN_GPO_OD 0x20
174#define DA9210_GPIO3_PIN_GPO 0x30
175#define DA9210_GPIO3_TYPE_SHIFT 0x40
176#define DA9210_GPIO3_TYPE_GPI 0x00
177#define DA9210_GPIO3_TYPE_GPO 0x40
178#define DA9210_GPIO3_MODE 0x80
179
180/* DA9210_REG_GPIO_4_5 (addr=0x5A) */
181#define DA9210_GPIO4_PIN_SHIFT 0
182#define DA9210_GPIO4_PIN_MASK 0x03
183#define DA9210_GPIO4_PIN_GPI 0x00
184#define DA9210_GPIO4_PIN_GPO_OD 0x02
185#define DA9210_GPIO4_PIN_GPO 0x03
186#define DA9210_GPIO4_TYPE 0x04
187#define DA9210_GPIO4_TYPE_GPI 0x00
188#define DA9210_GPIO4_TYPE_GPO 0x04
189#define DA9210_GPIO4_MODE 0x08
190#define DA9210_GPIO5_PIN_SHIFT 4
191#define DA9210_GPIO5_PIN_MASK 0x30
192#define DA9210_GPIO5_PIN_GPI 0x00
193#define DA9210_GPIO5_PIN_INTERFACE 0x01
194#define DA9210_GPIO5_PIN_GPO_OD 0x20
195#define DA9210_GPIO5_PIN_GPO 0x30
196#define DA9210_GPIO5_TYPE_SHIFT 0x40
197#define DA9210_GPIO5_TYPE_GPI 0x00
198#define DA9210_GPIO5_TYPE_GPO 0x40
199#define DA9210_GPIO5_MODE 0x80
200
201/* DA9210_REG_GPIO_6 (addr=0x5B) */
202#define DA9210_GPIO6_PIN_SHIFT 0
203#define DA9210_GPIO6_PIN_MASK 0x03
204#define DA9210_GPIO6_PIN_GPI 0x00
205#define DA9210_GPIO6_PIN_INTERFACE 0x01
206#define DA9210_GPIO6_PIN_GPO_OD 0x02
207#define DA9210_GPIO6_PIN_GPO 0x03
208#define DA9210_GPIO6_TYPE 0x04
209#define DA9210_GPIO6_TYPE_GPI 0x00
210#define DA9210_GPIO6_TYPE_GPO 0x04
211#define DA9210_GPIO6_MODE 0x08
212
213/* DA9210_REG_BUCK_CONT (addr=0x5D) */
214#define DA9210_BUCK_EN 0x01
215#define DA9210_BUCK_GPI_SHIFT 1
216#define DA9210_BUCK_GPI_MASK 0x06
217#define DA9210_BUCK_GPI_OFF 0x00
218#define DA9210_BUCK_GPI_GPIO0 0x02
219#define DA9210_BUCK_GPI_GPIO3 0x04
220#define DA9210_BUCK_GPI_GPIO4 0x06
221#define DA9210_BUCK_PD_DIS 0x08
222#define DA9210_VBUCK_SEL 0x10
223#define DA9210_VBUCK_SEL_A 0x00
224#define DA9210_VBUCK_SEL_B 0x10
225#define DA9210_VBUCK_GPI_SHIFT 5
226#define DA9210_VBUCK_GPI_MASK 0x60
227#define DA9210_VBUCK_GPI_OFF 0x00
228#define DA9210_VBUCK_GPI_GPIO0 0x20
229#define DA9210_VBUCK_GPI_GPIO3 0x40
230#define DA9210_VBUCK_GPI_GPIO4 0x60
231#define DA9210_DVC_CTRL_EN 0x80
232
233/* DA9210_REG_BUCK_ILIM (addr=0xD0) */
234#define DA9210_BUCK_ILIM_SHIFT 0
235#define DA9210_BUCK_ILIM_MASK 0x0F
236#define DA9210_BUCK_IALARM 0x10
237
238/* DA9210_REG_BUCK_CONF1 (addr=0xD1) */
239#define DA9210_BUCK_MODE_SHIFT 0
240#define DA9210_BUCK_MODE_MASK 0x03
241#define DA9210_BUCK_MODE_MANUAL 0x00
242#define DA9210_BUCK_MODE_SLEEP 0x01
243#define DA9210_BUCK_MODE_SYNC 0x02
244#define DA9210_BUCK_MODE_AUTO 0x03
245#define DA9210_STARTUP_CTRL_SHIFT 2
246#define DA9210_STARTUP_CTRL_MASK 0x1C
247#define DA9210_PWR_DOWN_CTRL_SHIFT 5
248#define DA9210_PWR_DOWN_CTRL_MASK 0xE0
249
250/* DA9210_REG_BUCK_CONF2 (addr=0xD2) */
251#define DA9210_PHASE_SEL_SHIFT 0
252#define DA9210_PHASE_SEL_MASK 0x03
253#define DA9210_FREQ_SEL 0x40
254
255/* DA9210_REG_BUCK_AUTO (addr=0xD4) */
256#define DA9210_VBUCK_AUTO_SHIFT 0
257#define DA9210_VBUCK_AUTO_MASK 0x7F
258
259/* DA9210_REG_BUCK_BASE (addr=0xD5) */
260#define DA9210_VBUCK_BASE_SHIFT 0
261#define DA9210_VBUCK_BASE_MASK 0x7F
262
263/* DA9210_REG_VBUCK_MAX_DVC_IF (addr=0xD6) */
264#define DA9210_VBUCK_MAX_SHIFT 0
265#define DA9210_VBUCK_MAX_MASK 0x7F
266#define DA9210_DVC_STEP_SIZE 0x80
267#define DA9210_DVC_STEP_SIZE_10MV 0x00
268#define DA9210_DVC_STEP_SIZE_20MV 0x80
269
270/* DA9210_REG_VBUCK_DVC (addr=0xD7) */
271#define DA9210_VBUCK_DVC_SHIFT 0
272#define DA9210_VBUCK_DVC_MASK 0x7F
273
274/* DA9210_REG_VBUCK_A/B (addr=0xD8/0xD9) */
275#define DA9210_VBUCK_SHIFT 0
276#define DA9210_VBUCK_MASK 0x7F
277#define DA9210_VBUCK_BIAS 0
278#define DA9210_BUCK_SL 0x80
279
280/* DA9210_REG_INTERFACE (addr=0x105) */
281#define DA9210_IF_BASE_ADDR_SHIFT 4
282#define DA9210_IF_BASE_ADDR_MASK 0xF0
283
284/* DA9210_REG_CONFIG_E (addr=0x147) */
285#define DA9210_STAND_ALONE 0x01
286
287#endif /* __DA9210_REGISTERS_H__ */
288
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index f0e1ae52bb05..a32b44272a05 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -237,7 +237,7 @@ static int fan53555_regulator_probe(struct i2c_client *client,
237 unsigned int val; 237 unsigned int val;
238 int ret; 238 int ret;
239 239
240 pdata = client->dev.platform_data; 240 pdata = dev_get_platdata(&client->dev);
241 if (!pdata || !pdata->regulator) { 241 if (!pdata || !pdata->regulator) {
242 dev_err(&client->dev, "Platform data not found!\n"); 242 dev_err(&client->dev, "Platform data not found!\n");
243 return -ENODEV; 243 return -ENODEV;
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index e5c03b534fae..7610920014d7 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -146,7 +146,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
146 if (IS_ERR(config)) 146 if (IS_ERR(config))
147 return PTR_ERR(config); 147 return PTR_ERR(config);
148 } else { 148 } else {
149 config = pdev->dev.platform_data; 149 config = dev_get_platdata(&pdev->dev);
150 } 150 }
151 151
152 if (!config) 152 if (!config)
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 9d39eb4aafa3..98a98ffa7fe0 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -219,7 +219,7 @@ static struct regulator_ops gpio_regulator_current_ops = {
219 219
220static int gpio_regulator_probe(struct platform_device *pdev) 220static int gpio_regulator_probe(struct platform_device *pdev)
221{ 221{
222 struct gpio_regulator_config *config = pdev->dev.platform_data; 222 struct gpio_regulator_config *config = dev_get_platdata(&pdev->dev);
223 struct device_node *np = pdev->dev.of_node; 223 struct device_node *np = pdev->dev.of_node;
224 struct gpio_regulator_data *drvdata; 224 struct gpio_regulator_data *drvdata;
225 struct regulator_config cfg = { }; 225 struct regulator_config cfg = { };
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
new file mode 100644
index 000000000000..6e30df14714b
--- /dev/null
+++ b/drivers/regulator/helpers.c
@@ -0,0 +1,447 @@
1/*
2 * helpers.c -- Voltage/Current Regulator framework helper functions.
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/err.h>
16#include <linux/delay.h>
17#include <linux/regmap.h>
18#include <linux/regulator/consumer.h>
19#include <linux/regulator/driver.h>
20#include <linux/module.h>
21
22/**
23 * regulator_is_enabled_regmap - standard is_enabled() for regmap users
24 *
25 * @rdev: regulator to operate on
26 *
27 * Regulators that use regmap for their register I/O can set the
28 * enable_reg and enable_mask fields in their descriptor and then use
29 * this as their is_enabled operation, saving some code.
30 */
31int regulator_is_enabled_regmap(struct regulator_dev *rdev)
32{
33 unsigned int val;
34 int ret;
35
36 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
37 if (ret != 0)
38 return ret;
39
40 if (rdev->desc->enable_is_inverted)
41 return (val & rdev->desc->enable_mask) == 0;
42 else
43 return (val & rdev->desc->enable_mask) != 0;
44}
45EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
46
47/**
48 * regulator_enable_regmap - standard enable() for regmap users
49 *
50 * @rdev: regulator to operate on
51 *
52 * Regulators that use regmap for their register I/O can set the
53 * enable_reg and enable_mask fields in their descriptor and then use
54 * this as their enable() operation, saving some code.
55 */
56int regulator_enable_regmap(struct regulator_dev *rdev)
57{
58 unsigned int val;
59
60 if (rdev->desc->enable_is_inverted)
61 val = 0;
62 else
63 val = rdev->desc->enable_mask;
64
65 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
66 rdev->desc->enable_mask, val);
67}
68EXPORT_SYMBOL_GPL(regulator_enable_regmap);
69
70/**
71 * regulator_disable_regmap - standard disable() for regmap users
72 *
73 * @rdev: regulator to operate on
74 *
75 * Regulators that use regmap for their register I/O can set the
76 * enable_reg and enable_mask fields in their descriptor and then use
77 * this as their disable() operation, saving some code.
78 */
79int regulator_disable_regmap(struct regulator_dev *rdev)
80{
81 unsigned int val;
82
83 if (rdev->desc->enable_is_inverted)
84 val = rdev->desc->enable_mask;
85 else
86 val = 0;
87
88 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
89 rdev->desc->enable_mask, val);
90}
91EXPORT_SYMBOL_GPL(regulator_disable_regmap);
92
93/**
94 * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users
95 *
96 * @rdev: regulator to operate on
97 *
98 * Regulators that use regmap for their register I/O can set the
99 * vsel_reg and vsel_mask fields in their descriptor and then use this
100 * as their get_voltage_vsel operation, saving some code.
101 */
102int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev)
103{
104 unsigned int val;
105 int ret;
106
107 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
108 if (ret != 0)
109 return ret;
110
111 val &= rdev->desc->vsel_mask;
112 val >>= ffs(rdev->desc->vsel_mask) - 1;
113
114 return val;
115}
116EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap);
117
118/**
119 * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users
120 *
121 * @rdev: regulator to operate on
122 * @sel: Selector to set
123 *
124 * Regulators that use regmap for their register I/O can set the
125 * vsel_reg and vsel_mask fields in their descriptor and then use this
126 * as their set_voltage_vsel operation, saving some code.
127 */
128int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel)
129{
130 int ret;
131
132 sel <<= ffs(rdev->desc->vsel_mask) - 1;
133
134 ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
135 rdev->desc->vsel_mask, sel);
136 if (ret)
137 return ret;
138
139 if (rdev->desc->apply_bit)
140 ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg,
141 rdev->desc->apply_bit,
142 rdev->desc->apply_bit);
143 return ret;
144}
145EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap);
146
147/**
148 * regulator_map_voltage_iterate - map_voltage() based on list_voltage()
149 *
150 * @rdev: Regulator to operate on
151 * @min_uV: Lower bound for voltage
152 * @max_uV: Upper bound for voltage
153 *
154 * Drivers implementing set_voltage_sel() and list_voltage() can use
155 * this as their map_voltage() operation. It will find a suitable
156 * voltage by calling list_voltage() until it gets something in bounds
157 * for the requested voltages.
158 */
159int regulator_map_voltage_iterate(struct regulator_dev *rdev,
160 int min_uV, int max_uV)
161{
162 int best_val = INT_MAX;
163 int selector = 0;
164 int i, ret;
165
166 /* Find the smallest voltage that falls within the specified
167 * range.
168 */
169 for (i = 0; i < rdev->desc->n_voltages; i++) {
170 ret = rdev->desc->ops->list_voltage(rdev, i);
171 if (ret < 0)
172 continue;
173
174 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
175 best_val = ret;
176 selector = i;
177 }
178 }
179
180 if (best_val != INT_MAX)
181 return selector;
182 else
183 return -EINVAL;
184}
185EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
186
187/**
188 * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
189 *
190 * @rdev: Regulator to operate on
191 * @min_uV: Lower bound for voltage
192 * @max_uV: Upper bound for voltage
193 *
194 * Drivers that have ascendant voltage list can use this as their
195 * map_voltage() operation.
196 */
197int regulator_map_voltage_ascend(struct regulator_dev *rdev,
198 int min_uV, int max_uV)
199{
200 int i, ret;
201
202 for (i = 0; i < rdev->desc->n_voltages; i++) {
203 ret = rdev->desc->ops->list_voltage(rdev, i);
204 if (ret < 0)
205 continue;
206
207 if (ret > max_uV)
208 break;
209
210 if (ret >= min_uV && ret <= max_uV)
211 return i;
212 }
213
214 return -EINVAL;
215}
216EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
217
218/**
219 * regulator_map_voltage_linear - map_voltage() for simple linear mappings
220 *
221 * @rdev: Regulator to operate on
222 * @min_uV: Lower bound for voltage
223 * @max_uV: Upper bound for voltage
224 *
225 * Drivers providing min_uV and uV_step in their regulator_desc can
226 * use this as their map_voltage() operation.
227 */
228int regulator_map_voltage_linear(struct regulator_dev *rdev,
229 int min_uV, int max_uV)
230{
231 int ret, voltage;
232
233 /* Allow uV_step to be 0 for fixed voltage */
234 if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) {
235 if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV)
236 return 0;
237 else
238 return -EINVAL;
239 }
240
241 if (!rdev->desc->uV_step) {
242 BUG_ON(!rdev->desc->uV_step);
243 return -EINVAL;
244 }
245
246 if (min_uV < rdev->desc->min_uV)
247 min_uV = rdev->desc->min_uV;
248
249 ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
250 if (ret < 0)
251 return ret;
252
253 ret += rdev->desc->linear_min_sel;
254
255 /* Map back into a voltage to verify we're still in bounds */
256 voltage = rdev->desc->ops->list_voltage(rdev, ret);
257 if (voltage < min_uV || voltage > max_uV)
258 return -EINVAL;
259
260 return ret;
261}
262EXPORT_SYMBOL_GPL(regulator_map_voltage_linear);
263
264/**
265 * regulator_map_voltage_linear - map_voltage() for multiple linear ranges
266 *
267 * @rdev: Regulator to operate on
268 * @min_uV: Lower bound for voltage
269 * @max_uV: Upper bound for voltage
270 *
271 * Drivers providing linear_ranges in their descriptor can use this as
272 * their map_voltage() callback.
273 */
274int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
275 int min_uV, int max_uV)
276{
277 const struct regulator_linear_range *range;
278 int ret = -EINVAL;
279 int voltage, i;
280
281 if (!rdev->desc->n_linear_ranges) {
282 BUG_ON(!rdev->desc->n_linear_ranges);
283 return -EINVAL;
284 }
285
286 for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
287 range = &rdev->desc->linear_ranges[i];
288
289 if (!(min_uV <= range->max_uV && max_uV >= range->min_uV))
290 continue;
291
292 if (min_uV <= range->min_uV)
293 min_uV = range->min_uV;
294
295 /* range->uV_step == 0 means fixed voltage range */
296 if (range->uV_step == 0) {
297 ret = 0;
298 } else {
299 ret = DIV_ROUND_UP(min_uV - range->min_uV,
300 range->uV_step);
301 if (ret < 0)
302 return ret;
303 }
304
305 ret += range->min_sel;
306
307 break;
308 }
309
310 if (i == rdev->desc->n_linear_ranges)
311 return -EINVAL;
312
313 /* Map back into a voltage to verify we're still in bounds */
314 voltage = rdev->desc->ops->list_voltage(rdev, ret);
315 if (voltage < min_uV || voltage > max_uV)
316 return -EINVAL;
317
318 return ret;
319}
320EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range);
321
322/**
323 * regulator_list_voltage_linear - List voltages with simple calculation
324 *
325 * @rdev: Regulator device
326 * @selector: Selector to convert into a voltage
327 *
328 * Regulators with a simple linear mapping between voltages and
329 * selectors can set min_uV and uV_step in the regulator descriptor
330 * and then use this function as their list_voltage() operation,
331 */
332int regulator_list_voltage_linear(struct regulator_dev *rdev,
333 unsigned int selector)
334{
335 if (selector >= rdev->desc->n_voltages)
336 return -EINVAL;
337 if (selector < rdev->desc->linear_min_sel)
338 return 0;
339
340 selector -= rdev->desc->linear_min_sel;
341
342 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
343}
344EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);
345
346/**
347 * regulator_list_voltage_linear_range - List voltages for linear ranges
348 *
349 * @rdev: Regulator device
350 * @selector: Selector to convert into a voltage
351 *
352 * Regulators with a series of simple linear mappings between voltages
353 * and selectors can set linear_ranges in the regulator descriptor and
354 * then use this function as their list_voltage() operation,
355 */
356int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
357 unsigned int selector)
358{
359 const struct regulator_linear_range *range;
360 int i;
361
362 if (!rdev->desc->n_linear_ranges) {
363 BUG_ON(!rdev->desc->n_linear_ranges);
364 return -EINVAL;
365 }
366
367 for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
368 range = &rdev->desc->linear_ranges[i];
369
370 if (!(selector >= range->min_sel &&
371 selector <= range->max_sel))
372 continue;
373
374 selector -= range->min_sel;
375
376 return range->min_uV + (range->uV_step * selector);
377 }
378
379 return -EINVAL;
380}
381EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range);
382
383/**
384 * regulator_list_voltage_table - List voltages with table based mapping
385 *
386 * @rdev: Regulator device
387 * @selector: Selector to convert into a voltage
388 *
389 * Regulators with table based mapping between voltages and
390 * selectors can set volt_table in the regulator descriptor
391 * and then use this function as their list_voltage() operation.
392 */
393int regulator_list_voltage_table(struct regulator_dev *rdev,
394 unsigned int selector)
395{
396 if (!rdev->desc->volt_table) {
397 BUG_ON(!rdev->desc->volt_table);
398 return -EINVAL;
399 }
400
401 if (selector >= rdev->desc->n_voltages)
402 return -EINVAL;
403
404 return rdev->desc->volt_table[selector];
405}
406EXPORT_SYMBOL_GPL(regulator_list_voltage_table);
407
408/**
409 * regulator_set_bypass_regmap - Default set_bypass() using regmap
410 *
411 * @rdev: device to operate on.
412 * @enable: state to set.
413 */
414int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
415{
416 unsigned int val;
417
418 if (enable)
419 val = rdev->desc->bypass_mask;
420 else
421 val = 0;
422
423 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
424 rdev->desc->bypass_mask, val);
425}
426EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);
427
428/**
429 * regulator_get_bypass_regmap - Default get_bypass() using regmap
430 *
431 * @rdev: device to operate on.
432 * @enable: current state.
433 */
434int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
435{
436 unsigned int val;
437 int ret;
438
439 ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val);
440 if (ret != 0)
441 return ret;
442
443 *enable = val & rdev->desc->bypass_mask;
444
445 return 0;
446}
447EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap);
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index b99c49b9aff0..88c1a3acf563 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -110,7 +110,7 @@ static int isl6271a_probe(struct i2c_client *i2c,
110 const struct i2c_device_id *id) 110 const struct i2c_device_id *id)
111{ 111{
112 struct regulator_config config = { }; 112 struct regulator_config config = { };
113 struct regulator_init_data *init_data = i2c->dev.platform_data; 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 err, i;
116 116
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 3809b4381606..5a4604ee5ea5 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -425,7 +425,7 @@ static int lp3971_i2c_probe(struct i2c_client *i2c,
425 const struct i2c_device_id *id) 425 const struct i2c_device_id *id)
426{ 426{
427 struct lp3971 *lp3971; 427 struct lp3971 *lp3971;
428 struct lp3971_platform_data *pdata = i2c->dev.platform_data; 428 struct lp3971_platform_data *pdata = dev_get_platdata(&i2c->dev);
429 int ret; 429 int ret;
430 u16 val; 430 u16 val;
431 431
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index 573024039ca0..093e6f44ff8a 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -519,7 +519,7 @@ static int lp3972_i2c_probe(struct i2c_client *i2c,
519 const struct i2c_device_id *id) 519 const struct i2c_device_id *id)
520{ 520{
521 struct lp3972 *lp3972; 521 struct lp3972 *lp3972;
522 struct lp3972_platform_data *pdata = i2c->dev.platform_data; 522 struct lp3972_platform_data *pdata = dev_get_platdata(&i2c->dev);
523 int ret; 523 int ret;
524 u16 val; 524 u16 val;
525 525
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c
index b16336bcd4d4..2b84b727a3c4 100644
--- a/drivers/regulator/lp872x.c
+++ b/drivers/regulator/lp872x.c
@@ -373,7 +373,7 @@ static int lp8725_buck_set_current_limit(struct regulator_dev *rdev,
373 return -EINVAL; 373 return -EINVAL;
374 } 374 }
375 375
376 for (i = ARRAY_SIZE(lp8725_buck_uA) - 1 ; i >= 0; i--) { 376 for (i = ARRAY_SIZE(lp8725_buck_uA) - 1; i >= 0; i--) {
377 if (lp8725_buck_uA[i] >= min_uA && 377 if (lp8725_buck_uA[i] >= min_uA &&
378 lp8725_buck_uA[i] <= max_uA) 378 lp8725_buck_uA[i] <= max_uA)
379 return lp872x_update_bits(lp, addr, 379 return lp872x_update_bits(lp, addr,
@@ -787,7 +787,7 @@ static int lp872x_regulator_register(struct lp872x *lp)
787 struct regulator_dev *rdev; 787 struct regulator_dev *rdev;
788 int i, ret; 788 int i, ret;
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] :
792 &lp8725_regulator_desc[i]; 792 &lp8725_regulator_desc[i];
793 793
@@ -820,7 +820,7 @@ static void lp872x_regulator_unregister(struct lp872x *lp)
820 struct regulator_dev *rdev; 820 struct regulator_dev *rdev;
821 int i; 821 int i;
822 822
823 for (i = 0 ; i < lp->num_regulators ; i++) { 823 for (i = 0; i < lp->num_regulators; i++) {
824 rdev = *(lp->regulators + i); 824 rdev = *(lp->regulators + i);
825 regulator_unregister(rdev); 825 regulator_unregister(rdev);
826 } 826 }
@@ -907,7 +907,8 @@ static struct lp872x_platform_data
907 goto out; 907 goto out;
908 908
909 for (i = 0; i < num_matches; i++) { 909 for (i = 0; i < num_matches; i++) {
910 pdata->regulator_data[i].id = (int)match[i].driver_data; 910 pdata->regulator_data[i].id =
911 (enum lp872x_regulator_id)match[i].driver_data;
911 pdata->regulator_data[i].init_data = match[i].init_data; 912 pdata->regulator_data[i].init_data = match[i].init_data;
912 913
913 /* Operation mode configuration for buck/buck1/buck2 */ 914 /* Operation mode configuration for buck/buck1/buck2 */
@@ -961,7 +962,7 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
961 } 962 }
962 963
963 lp->dev = &cl->dev; 964 lp->dev = &cl->dev;
964 lp->pdata = cl->dev.platform_data; 965 lp->pdata = dev_get_platdata(&cl->dev);
965 lp->chipid = id->driver_data; 966 lp->chipid = id->driver_data;
966 lp->num_regulators = num_regulators; 967 lp->num_regulators = num_regulators;
967 i2c_set_clientdata(cl, lp); 968 i2c_set_clientdata(cl, lp);
diff --git a/drivers/regulator/lp8755.c b/drivers/regulator/lp8755.c
index d9e38b4c2adc..785a25e9a437 100644
--- a/drivers/regulator/lp8755.c
+++ b/drivers/regulator/lp8755.c
@@ -228,6 +228,7 @@ err_i2c:
228} 228}
229 229
230static struct regulator_ops lp8755_buck_ops = { 230static struct regulator_ops lp8755_buck_ops = {
231 .map_voltage = regulator_map_voltage_linear,
231 .list_voltage = regulator_list_voltage_linear, 232 .list_voltage = regulator_list_voltage_linear,
232 .set_voltage_sel = regulator_set_voltage_sel_regmap, 233 .set_voltage_sel = regulator_set_voltage_sel_regmap,
233 .get_voltage_sel = regulator_get_voltage_sel_regmap, 234 .get_voltage_sel = regulator_get_voltage_sel_regmap,
@@ -449,7 +450,7 @@ static int lp8755_probe(struct i2c_client *client,
449{ 450{
450 int ret, icnt; 451 int ret, icnt;
451 struct lp8755_chip *pchip; 452 struct lp8755_chip *pchip;
452 struct lp8755_platform_data *pdata = client->dev.platform_data; 453 struct lp8755_platform_data *pdata = dev_get_platdata(&client->dev);
453 454
454 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 455 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
455 dev_err(&client->dev, "i2c functionality check fail.\n"); 456 dev_err(&client->dev, "i2c functionality check fail.\n");
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 54af61015814..3a599ee0a456 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -163,7 +163,7 @@ static int max1586_pmic_probe(struct i2c_client *client,
163 const struct i2c_device_id *i2c_id) 163 const struct i2c_device_id *i2c_id)
164{ 164{
165 struct regulator_dev **rdev; 165 struct regulator_dev **rdev;
166 struct max1586_platform_data *pdata = client->dev.platform_data; 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, ret = -ENOMEM;
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index db6c9be10f3f..19c6f08eafd5 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -152,7 +152,7 @@ static struct regmap_config max8649_regmap_config = {
152static int max8649_regulator_probe(struct i2c_client *client, 152static int max8649_regulator_probe(struct i2c_client *client,
153 const struct i2c_device_id *id) 153 const struct i2c_device_id *id)
154{ 154{
155 struct max8649_platform_data *pdata = client->dev.platform_data; 155 struct max8649_platform_data *pdata = dev_get_platdata(&client->dev);
156 struct max8649_regulator_info *info = NULL; 156 struct max8649_regulator_info *info = NULL;
157 struct regulator_config config = { }; 157 struct regulator_config config = { };
158 unsigned int val; 158 unsigned int val;
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index d428ef9a626f..144bcacd734d 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -44,6 +44,9 @@
44#include <linux/regulator/driver.h> 44#include <linux/regulator/driver.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/regulator/max8660.h> 46#include <linux/regulator/max8660.h>
47#include <linux/of.h>
48#include <linux/of_device.h>
49#include <linux/regulator/of_regulator.h>
47 50
48#define MAX8660_DCDC_MIN_UV 725000 51#define MAX8660_DCDC_MIN_UV 725000
49#define MAX8660_DCDC_MAX_UV 1800000 52#define MAX8660_DCDC_MAX_UV 1800000
@@ -305,21 +308,105 @@ static const struct regulator_desc max8660_reg[] = {
305 }, 308 },
306}; 309};
307 310
311enum {
312 MAX8660 = 0,
313 MAX8661 = 1,
314};
315
316#ifdef CONFIG_OF
317static const struct of_device_id max8660_dt_ids[] = {
318 { .compatible = "maxim,max8660", .data = (void *) MAX8660 },
319 { .compatible = "maxim,max8661", .data = (void *) MAX8661 },
320 { }
321};
322MODULE_DEVICE_TABLE(of, max8660_dt_ids);
323
324static int max8660_pdata_from_dt(struct device *dev,
325 struct device_node **of_node,
326 struct max8660_platform_data *pdata)
327{
328 int matched, i;
329 struct device_node *np;
330 struct max8660_subdev_data *sub;
331 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)];
332
333 np = of_find_node_by_name(dev->of_node, "regulators");
334 if (!np) {
335 dev_err(dev, "missing 'regulators' subnode in DT\n");
336 return -EINVAL;
337 }
338
339 for (i = 0; i < ARRAY_SIZE(rmatch); i++)
340 rmatch[i].name = max8660_reg[i].name;
341
342 matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch));
343 if (matched <= 0)
344 return matched;
345
346 pdata->subdevs = devm_kzalloc(dev, sizeof(struct max8660_subdev_data) *
347 matched, GFP_KERNEL);
348 if (!pdata->subdevs)
349 return -ENOMEM;
350
351 pdata->num_subdevs = matched;
352 sub = pdata->subdevs;
353
354 for (i = 0; i < matched; i++) {
355 sub->id = i;
356 sub->name = rmatch[i].name;
357 sub->platform_data = rmatch[i].init_data;
358 of_node[i] = rmatch[i].of_node;
359 sub++;
360 }
361
362 return 0;
363}
364#else
365static inline int max8660_pdata_from_dt(struct device *dev,
366 struct device_node **of_node,
367 struct max8660_platform_data *pdata)
368{
369 return 0;
370}
371#endif
372
308static int max8660_probe(struct i2c_client *client, 373static int max8660_probe(struct i2c_client *client,
309 const struct i2c_device_id *i2c_id) 374 const struct i2c_device_id *i2c_id)
310{ 375{
311 struct regulator_dev **rdev; 376 struct regulator_dev **rdev;
312 struct max8660_platform_data *pdata = client->dev.platform_data; 377 struct device *dev = &client->dev;
378 struct max8660_platform_data *pdata = dev_get_platdata(dev);
313 struct regulator_config config = { }; 379 struct regulator_config config = { };
314 struct max8660 *max8660; 380 struct max8660 *max8660;
315 int boot_on, i, id, ret = -EINVAL; 381 int boot_on, i, id, ret = -EINVAL;
382 struct device_node *of_node[MAX8660_V_END];
383 unsigned long type;
384
385 if (dev->of_node && !pdata) {
386 const struct of_device_id *id;
387 struct max8660_platform_data pdata_of;
388
389 id = of_match_device(of_match_ptr(max8660_dt_ids), dev);
390 if (!id)
391 return -ENODEV;
392
393 ret = max8660_pdata_from_dt(dev, of_node, &pdata_of);
394 if (ret < 0)
395 return ret;
396
397 pdata = &pdata_of;
398 type = (unsigned long) id->data;
399 } else {
400 type = i2c_id->driver_data;
401 memset(of_node, 0, sizeof(of_node));
402 }
316 403
317 if (pdata->num_subdevs > MAX8660_V_END) { 404 if (pdata->num_subdevs > MAX8660_V_END) {
318 dev_err(&client->dev, "Too many regulators found!\n"); 405 dev_err(dev, "Too many regulators found!\n");
319 return -EINVAL; 406 return -EINVAL;
320 } 407 }
321 408
322 max8660 = devm_kzalloc(&client->dev, sizeof(struct max8660) + 409 max8660 = devm_kzalloc(dev, sizeof(struct max8660) +
323 sizeof(struct regulator_dev *) * MAX8660_V_END, 410 sizeof(struct regulator_dev *) * MAX8660_V_END,
324 GFP_KERNEL); 411 GFP_KERNEL);
325 if (!max8660) 412 if (!max8660)
@@ -376,8 +463,8 @@ static int max8660_probe(struct i2c_client *client,
376 break; 463 break;
377 464
378 case MAX8660_V7: 465 case MAX8660_V7:
379 if (!strcmp(i2c_id->name, "max8661")) { 466 if (type == MAX8661) {
380 dev_err(&client->dev, "Regulator not on this chip!\n"); 467 dev_err(dev, "Regulator not on this chip!\n");
381 goto err_out; 468 goto err_out;
382 } 469 }
383 470
@@ -386,7 +473,7 @@ static int max8660_probe(struct i2c_client *client,
386 break; 473 break;
387 474
388 default: 475 default:
389 dev_err(&client->dev, "invalid regulator %s\n", 476 dev_err(dev, "invalid regulator %s\n",
390 pdata->subdevs[i].name); 477 pdata->subdevs[i].name);
391 goto err_out; 478 goto err_out;
392 } 479 }
@@ -397,14 +484,15 @@ static int max8660_probe(struct i2c_client *client,
397 484
398 id = pdata->subdevs[i].id; 485 id = pdata->subdevs[i].id;
399 486
400 config.dev = &client->dev; 487 config.dev = dev;
401 config.init_data = pdata->subdevs[i].platform_data; 488 config.init_data = pdata->subdevs[i].platform_data;
489 config.of_node = of_node[i];
402 config.driver_data = max8660; 490 config.driver_data = max8660;
403 491
404 rdev[i] = regulator_register(&max8660_reg[id], &config); 492 rdev[i] = regulator_register(&max8660_reg[id], &config);
405 if (IS_ERR(rdev[i])) { 493 if (IS_ERR(rdev[i])) {
406 ret = PTR_ERR(rdev[i]); 494 ret = PTR_ERR(rdev[i]);
407 dev_err(&client->dev, "failed to register %s\n", 495 dev_err(dev, "failed to register %s\n",
408 max8660_reg[id].name); 496 max8660_reg[id].name);
409 goto err_unregister; 497 goto err_unregister;
410 } 498 }
@@ -431,8 +519,8 @@ static int max8660_remove(struct i2c_client *client)
431} 519}
432 520
433static const struct i2c_device_id max8660_id[] = { 521static const struct i2c_device_id max8660_id[] = {
434 { "max8660", 0 }, 522 { .name = "max8660", .driver_data = MAX8660 },
435 { "max8661", 0 }, 523 { .name = "max8661", .driver_data = MAX8661 },
436 { } 524 { }
437}; 525};
438MODULE_DEVICE_TABLE(i2c, max8660_id); 526MODULE_DEVICE_TABLE(i2c, max8660_id);
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index e6d54a546d36..d80b5fa758ae 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -277,7 +277,7 @@ static int max8925_regulator_dt_init(struct platform_device *pdev,
277static int max8925_regulator_probe(struct platform_device *pdev) 277static int max8925_regulator_probe(struct platform_device *pdev)
278{ 278{
279 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); 279 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
280 struct regulator_init_data *pdata = pdev->dev.platform_data; 280 struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
281 struct regulator_config config = { }; 281 struct regulator_config config = { };
282 struct max8925_regulator_info *ri; 282 struct max8925_regulator_info *ri;
283 struct resource *res; 283 struct resource *res;
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 5259c2fea90a..788e5ae2af1b 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -196,7 +196,7 @@ static int max8952_pmic_probe(struct i2c_client *client,
196 const struct i2c_device_id *i2c_id) 196 const struct i2c_device_id *i2c_id)
197{ 197{
198 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 198 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
199 struct max8952_platform_data *pdata = client->dev.platform_data; 199 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev);
200 struct regulator_config config = { }; 200 struct regulator_config config = { };
201 struct max8952_data *max8952; 201 struct max8952_data *max8952;
202 202
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index 0c5195a842e2..5b77ab7762e4 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -371,7 +371,7 @@ static int max8973_probe(struct i2c_client *client,
371 struct max8973_chip *max; 371 struct max8973_chip *max;
372 int ret; 372 int ret;
373 373
374 pdata = client->dev.platform_data; 374 pdata = dev_get_platdata(&client->dev);
375 375
376 if (!pdata && !client->dev.of_node) { 376 if (!pdata && !client->dev.of_node) {
377 dev_err(&client->dev, "No Platform data"); 377 dev_err(&client->dev, "No Platform data");
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index f3c8f8f9dc39..7827384680d6 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -21,6 +21,7 @@ static void of_get_regulation_constraints(struct device_node *np,
21{ 21{
22 const __be32 *min_uV, *max_uV, *uV_offset; 22 const __be32 *min_uV, *max_uV, *uV_offset;
23 const __be32 *min_uA, *max_uA, *ramp_delay; 23 const __be32 *min_uA, *max_uA, *ramp_delay;
24 struct property *prop;
24 struct regulation_constraints *constraints = &(*init_data)->constraints; 25 struct regulation_constraints *constraints = &(*init_data)->constraints;
25 26
26 constraints->name = of_get_property(np, "regulator-name", NULL); 27 constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -64,9 +65,14 @@ static void of_get_regulation_constraints(struct device_node *np,
64 if (of_property_read_bool(np, "regulator-allow-bypass")) 65 if (of_property_read_bool(np, "regulator-allow-bypass"))
65 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS; 66 constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS;
66 67
67 ramp_delay = of_get_property(np, "regulator-ramp-delay", NULL); 68 prop = of_find_property(np, "regulator-ramp-delay", NULL);
68 if (ramp_delay) 69 if (prop && prop->value) {
69 constraints->ramp_delay = be32_to_cpu(*ramp_delay); 70 ramp_delay = prop->value;
71 if (*ramp_delay)
72 constraints->ramp_delay = be32_to_cpu(*ramp_delay);
73 else
74 constraints->ramp_disable = true;
75 }
70} 76}
71 77
72/** 78/**
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index d0c87856dd25..488dfe7ce9a6 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -97,11 +97,16 @@ static const struct regs_info palmas_regs_info[] = {
97 .ctrl_addr = PALMAS_SMPS9_CTRL, 97 .ctrl_addr = PALMAS_SMPS9_CTRL,
98 }, 98 },
99 { 99 {
100 .name = "SMPS10", 100 .name = "SMPS10_OUT2",
101 .sname = "smps10-in", 101 .sname = "smps10-in",
102 .ctrl_addr = PALMAS_SMPS10_CTRL, 102 .ctrl_addr = PALMAS_SMPS10_CTRL,
103 }, 103 },
104 { 104 {
105 .name = "SMPS10_OUT1",
106 .sname = "smps10-out2",
107 .ctrl_addr = PALMAS_SMPS10_CTRL,
108 },
109 {
105 .name = "LDO1", 110 .name = "LDO1",
106 .sname = "ldo1-in", 111 .sname = "ldo1-in",
107 .vsel_addr = PALMAS_LDO1_VOLTAGE, 112 .vsel_addr = PALMAS_LDO1_VOLTAGE,
@@ -487,6 +492,8 @@ static struct regulator_ops palmas_ops_smps10 = {
487 .set_voltage_sel = regulator_set_voltage_sel_regmap, 492 .set_voltage_sel = regulator_set_voltage_sel_regmap,
488 .list_voltage = regulator_list_voltage_linear, 493 .list_voltage = regulator_list_voltage_linear,
489 .map_voltage = regulator_map_voltage_linear, 494 .map_voltage = regulator_map_voltage_linear,
495 .set_bypass = regulator_set_bypass_regmap,
496 .get_bypass = regulator_get_bypass_regmap,
490}; 497};
491 498
492static int palmas_is_enabled_ldo(struct regulator_dev *dev) 499static int palmas_is_enabled_ldo(struct regulator_dev *dev)
@@ -538,7 +545,8 @@ static int palmas_smps_init(struct palmas *palmas, int id,
538 return ret; 545 return ret;
539 546
540 switch (id) { 547 switch (id) {
541 case PALMAS_REG_SMPS10: 548 case PALMAS_REG_SMPS10_OUT1:
549 case PALMAS_REG_SMPS10_OUT2:
542 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; 550 reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK;
543 if (reg_init->mode_sleep) 551 if (reg_init->mode_sleep)
544 reg |= reg_init->mode_sleep << 552 reg |= reg_init->mode_sleep <<
@@ -681,7 +689,8 @@ static struct of_regulator_match palmas_matches[] = {
681 { .name = "smps7", }, 689 { .name = "smps7", },
682 { .name = "smps8", }, 690 { .name = "smps8", },
683 { .name = "smps9", }, 691 { .name = "smps9", },
684 { .name = "smps10", }, 692 { .name = "smps10_out2", },
693 { .name = "smps10_out1", },
685 { .name = "ldo1", }, 694 { .name = "ldo1", },
686 { .name = "ldo2", }, 695 { .name = "ldo2", },
687 { .name = "ldo3", }, 696 { .name = "ldo3", },
@@ -765,7 +774,7 @@ static void palmas_dt_to_pdata(struct device *dev,
765static int palmas_regulators_probe(struct platform_device *pdev) 774static int palmas_regulators_probe(struct platform_device *pdev)
766{ 775{
767 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); 776 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
768 struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data; 777 struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev);
769 struct device_node *node = pdev->dev.of_node; 778 struct device_node *node = pdev->dev.of_node;
770 struct regulator_dev *rdev; 779 struct regulator_dev *rdev;
771 struct regulator_config config = { }; 780 struct regulator_config config = { };
@@ -838,7 +847,8 @@ static int palmas_regulators_probe(struct platform_device *pdev)
838 continue; 847 continue;
839 ramp_delay_support = true; 848 ramp_delay_support = true;
840 break; 849 break;
841 case PALMAS_REG_SMPS10: 850 case PALMAS_REG_SMPS10_OUT1:
851 case PALMAS_REG_SMPS10_OUT2:
842 if (!PALMAS_PMIC_HAS(palmas, SMPS10_BOOST)) 852 if (!PALMAS_PMIC_HAS(palmas, SMPS10_BOOST))
843 continue; 853 continue;
844 } 854 }
@@ -872,7 +882,8 @@ static int palmas_regulators_probe(struct platform_device *pdev)
872 pmic->desc[id].id = id; 882 pmic->desc[id].id = id;
873 883
874 switch (id) { 884 switch (id) {
875 case PALMAS_REG_SMPS10: 885 case PALMAS_REG_SMPS10_OUT1:
886 case PALMAS_REG_SMPS10_OUT2:
876 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; 887 pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
877 pmic->desc[id].ops = &palmas_ops_smps10; 888 pmic->desc[id].ops = &palmas_ops_smps10;
878 pmic->desc[id].vsel_reg = 889 pmic->desc[id].vsel_reg =
@@ -882,7 +893,14 @@ static int palmas_regulators_probe(struct platform_device *pdev)
882 pmic->desc[id].enable_reg = 893 pmic->desc[id].enable_reg =
883 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, 894 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
884 PALMAS_SMPS10_CTRL); 895 PALMAS_SMPS10_CTRL);
885 pmic->desc[id].enable_mask = SMPS10_BOOST_EN; 896 if (id == PALMAS_REG_SMPS10_OUT1)
897 pmic->desc[id].enable_mask = SMPS10_SWITCH_EN;
898 else
899 pmic->desc[id].enable_mask = SMPS10_BOOST_EN;
900 pmic->desc[id].bypass_reg =
901 PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
902 PALMAS_SMPS10_CTRL);
903 pmic->desc[id].bypass_mask = SMPS10_BYPASS_EN;
886 pmic->desc[id].min_uV = 3750000; 904 pmic->desc[id].min_uV = 3750000;
887 pmic->desc[id].uV_step = 1250000; 905 pmic->desc[id].uV_step = 1250000;
888 break; 906 break;
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index 1a73a297fe73..b49eaeedea84 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -243,7 +243,7 @@ static int pcap_regulator_probe(struct platform_device *pdev)
243 struct regulator_config config = { }; 243 struct regulator_config config = { };
244 244
245 config.dev = &pdev->dev; 245 config.dev = &pdev->dev;
246 config.init_data = pdev->dev.platform_data; 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 = regulator_register(&pcap_regulators[pdev->id], &config);
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index 54df9f7cb504..0f3576d48abf 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -86,7 +86,7 @@ static int pcf50633_regulator_probe(struct platform_device *pdev)
86 pcf = dev_to_pcf50633(pdev->dev.parent); 86 pcf = dev_to_pcf50633(pdev->dev.parent);
87 87
88 config.dev = &pdev->dev; 88 config.dev = &pdev->dev;
89 config.init_data = pdev->dev.platform_data; 89 config.init_data = dev_get_platdata(&pdev->dev);
90 config.driver_data = pcf; 90 config.driver_data = pcf;
91 config.regmap = pcf->regmap; 91 config.regmap = pcf->regmap;
92 92
diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
new file mode 100644
index 000000000000..ba67b2c4e2e7
--- /dev/null
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -0,0 +1,445 @@
1/*
2 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/err.h>
22#include <linux/of.h>
23#include <linux/of_device.h>
24#include <linux/regulator/of_regulator.h>
25#include <linux/platform_device.h>
26#include <linux/regulator/driver.h>
27#include <linux/regulator/machine.h>
28#include <linux/regulator/pfuze100.h>
29#include <linux/i2c.h>
30#include <linux/slab.h>
31#include <linux/regmap.h>
32
33#define PFUZE_NUMREGS 128
34#define PFUZE100_VOL_OFFSET 0
35#define PFUZE100_STANDBY_OFFSET 1
36#define PFUZE100_MODE_OFFSET 3
37#define PFUZE100_CONF_OFFSET 4
38
39#define PFUZE100_DEVICEID 0x0
40#define PFUZE100_REVID 0x3
41#define PFUZE100_FABID 0x3
42
43#define PFUZE100_SW1ABVOL 0x20
44#define PFUZE100_SW1CVOL 0x2e
45#define PFUZE100_SW2VOL 0x35
46#define PFUZE100_SW3AVOL 0x3c
47#define PFUZE100_SW3BVOL 0x43
48#define PFUZE100_SW4VOL 0x4a
49#define PFUZE100_SWBSTCON1 0x66
50#define PFUZE100_VREFDDRCON 0x6a
51#define PFUZE100_VSNVSVOL 0x6b
52#define PFUZE100_VGEN1VOL 0x6c
53#define PFUZE100_VGEN2VOL 0x6d
54#define PFUZE100_VGEN3VOL 0x6e
55#define PFUZE100_VGEN4VOL 0x6f
56#define PFUZE100_VGEN5VOL 0x70
57#define PFUZE100_VGEN6VOL 0x71
58
59struct pfuze_regulator {
60 struct regulator_desc desc;
61 unsigned char stby_reg;
62 unsigned char stby_mask;
63};
64
65struct pfuze_chip {
66 struct regmap *regmap;
67 struct device *dev;
68 struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR];
69 struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR];
70};
71
72static const int pfuze100_swbst[] = {
73 5000000, 5050000, 5100000, 5150000,
74};
75
76static const int pfuze100_vsnvs[] = {
77 1000000, 1100000, 1200000, 1300000, 1500000, 1800000, 3000000,
78};
79
80static const struct i2c_device_id pfuze_device_id[] = {
81 {.name = "pfuze100"},
82 {},
83};
84MODULE_DEVICE_TABLE(i2c, pfuze_device_id);
85
86static const struct of_device_id pfuze_dt_ids[] = {
87 { .compatible = "fsl,pfuze100" },
88 {},
89};
90MODULE_DEVICE_TABLE(of, pfuze_dt_ids);
91
92static int pfuze100_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
93{
94 struct pfuze_chip *pfuze100 = rdev_get_drvdata(rdev);
95 int id = rdev->desc->id;
96 unsigned int ramp_bits;
97 int ret;
98
99 if (id < PFUZE100_SWBST) {
100 ramp_delay = 12500 / ramp_delay;
101 ramp_bits = (ramp_delay >> 1) - (ramp_delay >> 3);
102 ret = regmap_update_bits(pfuze100->regmap,
103 rdev->desc->vsel_reg + 4,
104 0xc0, ramp_bits << 6);
105 if (ret < 0)
106 dev_err(pfuze100->dev, "ramp failed, err %d\n", ret);
107 } else
108 ret = -EACCES;
109
110 return ret;
111}
112
113static struct regulator_ops pfuze100_ldo_regulator_ops = {
114 .enable = regulator_enable_regmap,
115 .disable = regulator_disable_regmap,
116 .is_enabled = regulator_is_enabled_regmap,
117 .list_voltage = regulator_list_voltage_linear,
118 .set_voltage_sel = regulator_set_voltage_sel_regmap,
119 .get_voltage_sel = regulator_get_voltage_sel_regmap,
120};
121
122static struct regulator_ops pfuze100_fixed_regulator_ops = {
123 .list_voltage = regulator_list_voltage_linear,
124};
125
126static struct regulator_ops pfuze100_sw_regulator_ops = {
127 .list_voltage = regulator_list_voltage_linear,
128 .set_voltage_sel = regulator_set_voltage_sel_regmap,
129 .get_voltage_sel = regulator_get_voltage_sel_regmap,
130 .set_voltage_time_sel = regulator_set_voltage_time_sel,
131 .set_ramp_delay = pfuze100_set_ramp_delay,
132};
133
134static struct regulator_ops pfuze100_swb_regulator_ops = {
135 .list_voltage = regulator_list_voltage_table,
136 .map_voltage = regulator_map_voltage_ascend,
137 .set_voltage_sel = regulator_set_voltage_sel_regmap,
138 .get_voltage_sel = regulator_get_voltage_sel_regmap,
139
140};
141
142#define PFUZE100_FIXED_REG(_name, base, voltage) \
143 [PFUZE100_ ## _name] = { \
144 .desc = { \
145 .name = #_name, \
146 .n_voltages = 1, \
147 .ops = &pfuze100_fixed_regulator_ops, \
148 .type = REGULATOR_VOLTAGE, \
149 .id = PFUZE100_ ## _name, \
150 .owner = THIS_MODULE, \
151 .min_uV = (voltage), \
152 .enable_reg = (base), \
153 .enable_mask = 0x10, \
154 }, \
155 }
156
157#define PFUZE100_SW_REG(_name, base, min, max, step) \
158 [PFUZE100_ ## _name] = { \
159 .desc = { \
160 .name = #_name,\
161 .n_voltages = ((max) - (min)) / (step) + 1, \
162 .ops = &pfuze100_sw_regulator_ops, \
163 .type = REGULATOR_VOLTAGE, \
164 .id = PFUZE100_ ## _name, \
165 .owner = THIS_MODULE, \
166 .min_uV = (min), \
167 .uV_step = (step), \
168 .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \
169 .vsel_mask = 0x3f, \
170 }, \
171 .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \
172 .stby_mask = 0x3f, \
173 }
174
175#define PFUZE100_SWB_REG(_name, base, mask, voltages) \
176 [PFUZE100_ ## _name] = { \
177 .desc = { \
178 .name = #_name, \
179 .n_voltages = ARRAY_SIZE(voltages), \
180 .ops = &pfuze100_swb_regulator_ops, \
181 .type = REGULATOR_VOLTAGE, \
182 .id = PFUZE100_ ## _name, \
183 .owner = THIS_MODULE, \
184 .volt_table = voltages, \
185 .vsel_reg = (base), \
186 .vsel_mask = (mask), \
187 }, \
188 }
189
190#define PFUZE100_VGEN_REG(_name, base, min, max, step) \
191 [PFUZE100_ ## _name] = { \
192 .desc = { \
193 .name = #_name, \
194 .n_voltages = ((max) - (min)) / (step) + 1, \
195 .ops = &pfuze100_ldo_regulator_ops, \
196 .type = REGULATOR_VOLTAGE, \
197 .id = PFUZE100_ ## _name, \
198 .owner = THIS_MODULE, \
199 .min_uV = (min), \
200 .uV_step = (step), \
201 .vsel_reg = (base), \
202 .vsel_mask = 0xf, \
203 .enable_reg = (base), \
204 .enable_mask = 0x10, \
205 }, \
206 .stby_reg = (base), \
207 .stby_mask = 0x20, \
208 }
209
210static struct pfuze_regulator pfuze100_regulators[] = {
211 PFUZE100_SW_REG(SW1AB, PFUZE100_SW1ABVOL, 300000, 1875000, 25000),
212 PFUZE100_SW_REG(SW1C, PFUZE100_SW1CVOL, 300000, 1875000, 25000),
213 PFUZE100_SW_REG(SW2, PFUZE100_SW2VOL, 400000, 1975000, 25000),
214 PFUZE100_SW_REG(SW3A, PFUZE100_SW3AVOL, 400000, 1975000, 25000),
215 PFUZE100_SW_REG(SW3B, PFUZE100_SW3BVOL, 400000, 1975000, 25000),
216 PFUZE100_SW_REG(SW4, PFUZE100_SW4VOL, 400000, 1975000, 25000),
217 PFUZE100_SWB_REG(SWBST, PFUZE100_SWBSTCON1, 0x3 , pfuze100_swbst),
218 PFUZE100_SWB_REG(VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs),
219 PFUZE100_FIXED_REG(VREFDDR, PFUZE100_VREFDDRCON, 750000),
220 PFUZE100_VGEN_REG(VGEN1, PFUZE100_VGEN1VOL, 800000, 1550000, 50000),
221 PFUZE100_VGEN_REG(VGEN2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000),
222 PFUZE100_VGEN_REG(VGEN3, PFUZE100_VGEN3VOL, 1800000, 3300000, 100000),
223 PFUZE100_VGEN_REG(VGEN4, PFUZE100_VGEN4VOL, 1800000, 3300000, 100000),
224 PFUZE100_VGEN_REG(VGEN5, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000),
225 PFUZE100_VGEN_REG(VGEN6, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000),
226};
227
228#ifdef CONFIG_OF
229static struct of_regulator_match pfuze100_matches[] = {
230 { .name = "sw1ab", },
231 { .name = "sw1c", },
232 { .name = "sw2", },
233 { .name = "sw3a", },
234 { .name = "sw3b", },
235 { .name = "sw4", },
236 { .name = "swbst", },
237 { .name = "vsnvs", },
238 { .name = "vrefddr", },
239 { .name = "vgen1", },
240 { .name = "vgen2", },
241 { .name = "vgen3", },
242 { .name = "vgen4", },
243 { .name = "vgen5", },
244 { .name = "vgen6", },
245};
246
247static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
248{
249 struct device *dev = chip->dev;
250 struct device_node *np, *parent;
251 int ret;
252
253 np = of_node_get(dev->parent->of_node);
254 if (!np)
255 return 0;
256
257 parent = of_find_node_by_name(np, "regulators");
258 if (!parent) {
259 dev_err(dev, "regulators node not found\n");
260 return -EINVAL;
261 }
262
263 ret = of_regulator_match(dev, parent, pfuze100_matches,
264 ARRAY_SIZE(pfuze100_matches));
265
266 of_node_put(parent);
267 if (ret < 0) {
268 dev_err(dev, "Error parsing regulator init data: %d\n",
269 ret);
270 return ret;
271 }
272
273 return 0;
274}
275
276static inline struct regulator_init_data *match_init_data(int index)
277{
278 return pfuze100_matches[index].init_data;
279}
280
281static inline struct device_node *match_of_node(int index)
282{
283 return pfuze100_matches[index].of_node;
284}
285#else
286static int pfuze_parse_regulators_dt(struct pfuze_chip *chip)
287{
288 return 0;
289}
290
291static inline struct regulator_init_data *match_init_data(int index)
292{
293 return NULL;
294}
295
296static inline struct device_node *match_of_node(int index)
297{
298 return NULL;
299}
300#endif
301
302static int pfuze_identify(struct pfuze_chip *pfuze_chip)
303{
304 unsigned int value;
305 int ret;
306
307 ret = regmap_read(pfuze_chip->regmap, PFUZE100_DEVICEID, &value);
308 if (ret)
309 return ret;
310
311 if (value & 0x0f) {
312 dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value);
313 return -ENODEV;
314 }
315
316 ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value);
317 if (ret)
318 return ret;
319 dev_info(pfuze_chip->dev,
320 "Full lay: %x, Metal lay: %x\n",
321 (value & 0xf0) >> 4, value & 0x0f);
322
323 ret = regmap_read(pfuze_chip->regmap, PFUZE100_FABID, &value);
324 if (ret)
325 return ret;
326 dev_info(pfuze_chip->dev, "FAB: %x, FIN: %x\n",
327 (value & 0xc) >> 2, value & 0x3);
328
329 return 0;
330}
331
332static const struct regmap_config pfuze_regmap_config = {
333 .reg_bits = 8,
334 .val_bits = 8,
335 .max_register = PFUZE_NUMREGS - 1,
336 .cache_type = REGCACHE_RBTREE,
337};
338
339static int pfuze100_regulator_probe(struct i2c_client *client,
340 const struct i2c_device_id *id)
341{
342 struct pfuze_chip *pfuze_chip;
343 struct pfuze_regulator_platform_data *pdata =
344 dev_get_platdata(&client->dev);
345 struct regulator_config config = { };
346 int i, ret;
347
348 pfuze_chip = devm_kzalloc(&client->dev, sizeof(*pfuze_chip),
349 GFP_KERNEL);
350 if (!pfuze_chip)
351 return -ENOMEM;
352
353 i2c_set_clientdata(client, pfuze_chip);
354
355 memcpy(pfuze_chip->regulator_descs, pfuze100_regulators,
356 sizeof(pfuze_chip->regulator_descs));
357
358 pfuze_chip->dev = &client->dev;
359
360 pfuze_chip->regmap = devm_regmap_init_i2c(client, &pfuze_regmap_config);
361 if (IS_ERR(pfuze_chip->regmap)) {
362 ret = PTR_ERR(pfuze_chip->regmap);
363 dev_err(&client->dev,
364 "regmap allocation failed with err %d\n", ret);
365 return ret;
366 }
367
368 ret = pfuze_identify(pfuze_chip);
369 if (ret) {
370 dev_err(&client->dev, "unrecognized pfuze chip ID!\n");
371 return ret;
372 }
373
374 ret = pfuze_parse_regulators_dt(pfuze_chip);
375 if (ret)
376 return ret;
377
378 for (i = 0; i < PFUZE100_MAX_REGULATOR; i++) {
379 struct regulator_init_data *init_data;
380 struct regulator_desc *desc;
381 int val;
382
383 desc = &pfuze_chip->regulator_descs[i].desc;
384
385 if (pdata)
386 init_data = pdata->init_data[i];
387 else
388 init_data = match_init_data(i);
389
390 /* SW2~SW4 high bit check and modify the voltage value table */
391 if (i > PFUZE100_SW1C && i < PFUZE100_SWBST) {
392 regmap_read(pfuze_chip->regmap, desc->vsel_reg, &val);
393 if (val & 0x40) {
394 desc->min_uV = 800000;
395 desc->uV_step = 50000;
396 desc->n_voltages = 51;
397 }
398 }
399
400 config.dev = &client->dev;
401 config.init_data = init_data;
402 config.driver_data = pfuze_chip;
403 config.of_node = match_of_node(i);
404
405 pfuze_chip->regulators[i] = regulator_register(desc, &config);
406 if (IS_ERR(pfuze_chip->regulators[i])) {
407 dev_err(&client->dev, "register regulator%s failed\n",
408 pfuze100_regulators[i].desc.name);
409 ret = PTR_ERR(pfuze_chip->regulators[i]);
410 while (--i >= 0)
411 regulator_unregister(pfuze_chip->regulators[i]);
412 return ret;
413 }
414 }
415
416 return 0;
417}
418
419static int pfuze100_regulator_remove(struct i2c_client *client)
420{
421 int i;
422 struct pfuze_chip *pfuze_chip = i2c_get_clientdata(client);
423
424 for (i = 0; i < PFUZE100_MAX_REGULATOR; i++)
425 regulator_unregister(pfuze_chip->regulators[i]);
426
427 return 0;
428}
429
430static struct i2c_driver pfuze_driver = {
431 .id_table = pfuze_device_id,
432 .driver = {
433 .name = "pfuze100-regulator",
434 .owner = THIS_MODULE,
435 .of_match_table = pfuze_dt_ids,
436 },
437 .probe = pfuze100_regulator_probe,
438 .remove = pfuze100_regulator_remove,
439};
440module_i2c_driver(pfuze_driver);
441
442MODULE_AUTHOR("Robin Gong <b38343@freescale.com>");
443MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100 PMIC");
444MODULE_LICENSE("GPL v2");
445MODULE_ALIAS("i2c:pfuze100-regulator");
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index 2f62564ca936..5eba2ff8c0e8 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -16,12 +16,17 @@
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/regmap.h>
19#include <linux/platform_device.h> 21#include <linux/platform_device.h>
20#include <linux/regulator/driver.h> 22#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h> 23#include <linux/regulator/machine.h>
24#include <linux/regulator/of_regulator.h>
22#include <linux/mfd/samsung/core.h> 25#include <linux/mfd/samsung/core.h>
23#include <linux/mfd/samsung/s2mps11.h> 26#include <linux/mfd/samsung/s2mps11.h>
24 27
28#define S2MPS11_REGULATOR_CNT ARRAY_SIZE(regulators)
29
25struct s2mps11_info { 30struct s2mps11_info {
26 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX]; 31 struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX];
27 32
@@ -31,11 +36,6 @@ struct s2mps11_info {
31 int ramp_delay16; 36 int ramp_delay16;
32 int ramp_delay7810; 37 int ramp_delay7810;
33 int ramp_delay9; 38 int ramp_delay9;
34
35 bool buck6_ramp;
36 bool buck2_ramp;
37 bool buck3_ramp;
38 bool buck4_ramp;
39}; 39};
40 40
41static int get_ramp_delay(int ramp_delay) 41static int get_ramp_delay(int ramp_delay)
@@ -50,9 +50,171 @@ static int get_ramp_delay(int ramp_delay)
50 break; 50 break;
51 cnt++; 51 cnt++;
52 } 52 }
53
54 if (cnt > 3)
55 cnt = 3;
56
53 return cnt; 57 return cnt;
54} 58}
55 59
60static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
61 unsigned int old_selector,
62 unsigned int new_selector)
63{
64 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
65 unsigned int ramp_delay = 0;
66 int old_volt, new_volt;
67
68 switch (rdev->desc->id) {
69 case S2MPS11_BUCK2:
70 ramp_delay = s2mps11->ramp_delay2;
71 break;
72 case S2MPS11_BUCK3:
73 ramp_delay = s2mps11->ramp_delay34;
74 break;
75 case S2MPS11_BUCK4:
76 ramp_delay = s2mps11->ramp_delay34;
77 break;
78 case S2MPS11_BUCK5:
79 ramp_delay = s2mps11->ramp_delay5;
80 break;
81 case S2MPS11_BUCK6:
82 case S2MPS11_BUCK1:
83 ramp_delay = s2mps11->ramp_delay16;
84 break;
85 case S2MPS11_BUCK7:
86 case S2MPS11_BUCK8:
87 case S2MPS11_BUCK10:
88 ramp_delay = s2mps11->ramp_delay7810;
89 break;
90 case S2MPS11_BUCK9:
91 ramp_delay = s2mps11->ramp_delay9;
92 }
93
94 if (ramp_delay == 0)
95 ramp_delay = rdev->desc->ramp_delay;
96
97 old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
98 new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
99
100 return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
101}
102
103static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
104{
105 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
106 unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
107 unsigned int ramp_enable = 1, enable_shift = 0;
108 int ret;
109
110 switch (rdev->desc->id) {
111 case S2MPS11_BUCK1:
112 if (ramp_delay > s2mps11->ramp_delay16)
113 s2mps11->ramp_delay16 = ramp_delay;
114 else
115 ramp_delay = s2mps11->ramp_delay16;
116
117 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
118 break;
119 case S2MPS11_BUCK2:
120 enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
121 if (!ramp_delay) {
122 ramp_enable = 0;
123 break;
124 }
125
126 s2mps11->ramp_delay2 = ramp_delay;
127 ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
128 ramp_reg = S2MPS11_REG_RAMP;
129 break;
130 case S2MPS11_BUCK3:
131 enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
132 if (!ramp_delay) {
133 ramp_enable = 0;
134 break;
135 }
136
137 if (ramp_delay > s2mps11->ramp_delay34)
138 s2mps11->ramp_delay34 = ramp_delay;
139 else
140 ramp_delay = s2mps11->ramp_delay34;
141
142 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
143 ramp_reg = S2MPS11_REG_RAMP;
144 break;
145 case S2MPS11_BUCK4:
146 enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
147 if (!ramp_delay) {
148 ramp_enable = 0;
149 break;
150 }
151
152 if (ramp_delay > s2mps11->ramp_delay34)
153 s2mps11->ramp_delay34 = ramp_delay;
154 else
155 ramp_delay = s2mps11->ramp_delay34;
156
157 ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
158 ramp_reg = S2MPS11_REG_RAMP;
159 break;
160 case S2MPS11_BUCK5:
161 s2mps11->ramp_delay5 = ramp_delay;
162 ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
163 break;
164 case S2MPS11_BUCK6:
165 enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
166 if (!ramp_delay) {
167 ramp_enable = 0;
168 break;
169 }
170
171 if (ramp_delay > s2mps11->ramp_delay16)
172 s2mps11->ramp_delay16 = ramp_delay;
173 else
174 ramp_delay = s2mps11->ramp_delay16;
175
176 ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
177 break;
178 case S2MPS11_BUCK7:
179 case S2MPS11_BUCK8:
180 case S2MPS11_BUCK10:
181 if (ramp_delay > s2mps11->ramp_delay7810)
182 s2mps11->ramp_delay7810 = ramp_delay;
183 else
184 ramp_delay = s2mps11->ramp_delay7810;
185
186 ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
187 break;
188 case S2MPS11_BUCK9:
189 s2mps11->ramp_delay9 = ramp_delay;
190 ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
191 break;
192 default:
193 return 0;
194 }
195
196 if (!ramp_enable)
197 goto ramp_disable;
198
199 if (enable_shift) {
200 ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
201 1 << enable_shift, 1 << enable_shift);
202 if (ret) {
203 dev_err(&rdev->dev, "failed to enable ramp rate\n");
204 return ret;
205 }
206 }
207
208 ramp_val = get_ramp_delay(ramp_delay);
209
210 return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
211 ramp_val << ramp_shift);
212
213ramp_disable:
214 return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
215 1 << enable_shift, 0);
216}
217
56static struct regulator_ops s2mps11_ldo_ops = { 218static struct regulator_ops s2mps11_ldo_ops = {
57 .list_voltage = regulator_list_voltage_linear, 219 .list_voltage = regulator_list_voltage_linear,
58 .map_voltage = regulator_map_voltage_linear, 220 .map_voltage = regulator_map_voltage_linear,
@@ -72,7 +234,8 @@ static struct regulator_ops s2mps11_buck_ops = {
72 .disable = regulator_disable_regmap, 234 .disable = regulator_disable_regmap,
73 .get_voltage_sel = regulator_get_voltage_sel_regmap, 235 .get_voltage_sel = regulator_get_voltage_sel_regmap,
74 .set_voltage_sel = regulator_set_voltage_sel_regmap, 236 .set_voltage_sel = regulator_set_voltage_sel_regmap,
75 .set_voltage_time_sel = regulator_set_voltage_time_sel, 237 .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
238 .set_ramp_delay = s2mps11_set_ramp_delay,
76}; 239};
77 240
78#define regulator_desc_ldo1(num) { \ 241#define regulator_desc_ldo1(num) { \
@@ -239,59 +402,51 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
239{ 402{
240 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 403 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
241 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); 404 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
405 struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX];
406 struct device_node *reg_np = NULL;
242 struct regulator_config config = { }; 407 struct regulator_config config = { };
243 struct s2mps11_info *s2mps11; 408 struct s2mps11_info *s2mps11;
244 int i, ret; 409 int i, ret;
245 unsigned char ramp_enable, ramp_reg = 0;
246
247 if (!pdata) {
248 dev_err(pdev->dev.parent, "Platform data not supplied\n");
249 return -ENODEV;
250 }
251 410
252 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info), 411 s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
253 GFP_KERNEL); 412 GFP_KERNEL);
254 if (!s2mps11) 413 if (!s2mps11)
255 return -ENOMEM; 414 return -ENOMEM;
256 415
257 platform_set_drvdata(pdev, s2mps11); 416 if (!iodev->dev->of_node) {
417 if (pdata) {
418 goto common_reg;
419 } else {
420 dev_err(pdev->dev.parent,
421 "Platform data or DT node not supplied\n");
422 return -ENODEV;
423 }
424 }
258 425
259 s2mps11->ramp_delay2 = pdata->buck2_ramp_delay; 426 for (i = 0; i < S2MPS11_REGULATOR_CNT; i++)
260 s2mps11->ramp_delay34 = pdata->buck34_ramp_delay; 427 rdata[i].name = regulators[i].name;
261 s2mps11->ramp_delay5 = pdata->buck5_ramp_delay; 428
262 s2mps11->ramp_delay16 = pdata->buck16_ramp_delay; 429 reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators");
263 s2mps11->ramp_delay7810 = pdata->buck7810_ramp_delay; 430 if (!reg_np) {
264 s2mps11->ramp_delay9 = pdata->buck9_ramp_delay; 431 dev_err(&pdev->dev, "could not find regulators sub-node\n");
265 432 return -EINVAL;
266 s2mps11->buck6_ramp = pdata->buck6_ramp_enable;
267 s2mps11->buck2_ramp = pdata->buck2_ramp_enable;
268 s2mps11->buck3_ramp = pdata->buck3_ramp_enable;
269 s2mps11->buck4_ramp = pdata->buck4_ramp_enable;
270
271 ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) |
272 (s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ;
273
274 if (ramp_enable) {
275 if (s2mps11->buck2_ramp)
276 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay2) << 6;
277 if (s2mps11->buck3_ramp || s2mps11->buck4_ramp)
278 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay34) << 4;
279 sec_reg_write(iodev, S2MPS11_REG_RAMP, ramp_reg | ramp_enable);
280 } 433 }
281 434
282 ramp_reg &= 0x00; 435 of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX);
283 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay5) << 6;
284 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay16) << 4;
285 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay7810) << 2;
286 ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9);
287 sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg);
288 436
289 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) { 437common_reg:
438 platform_set_drvdata(pdev, s2mps11);
290 439
291 config.dev = &pdev->dev; 440 config.dev = &pdev->dev;
292 config.regmap = iodev->regmap; 441 config.regmap = iodev->regmap;
293 config.init_data = pdata->regulators[i].initdata; 442 config.driver_data = s2mps11;
294 config.driver_data = s2mps11; 443 for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
444 if (!reg_np) {
445 config.init_data = pdata->regulators[i].initdata;
446 } else {
447 config.init_data = rdata[i].init_data;
448 config.of_node = rdata[i].of_node;
449 }
295 450
296 s2mps11->rdev[i] = regulator_register(&regulators[i], &config); 451 s2mps11->rdev[i] = regulator_register(&regulators[i], &config);
297 if (IS_ERR(s2mps11->rdev[i])) { 452 if (IS_ERR(s2mps11->rdev[i])) {
diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c
index 3753ed05e719..d8e3e1262bc2 100644
--- a/drivers/regulator/ti-abb-regulator.c
+++ b/drivers/regulator/ti-abb-regulator.c
@@ -717,11 +717,6 @@ static int ti_abb_probe(struct platform_device *pdev)
717 /* Map ABB resources */ 717 /* Map ABB resources */
718 pname = "base-address"; 718 pname = "base-address";
719 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 719 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
720 if (!res) {
721 dev_err(dev, "Missing '%s' IO resource\n", pname);
722 ret = -ENODEV;
723 goto err;
724 }
725 abb->base = devm_ioremap_resource(dev, res); 720 abb->base = devm_ioremap_resource(dev, res);
726 if (IS_ERR(abb->base)) { 721 if (IS_ERR(abb->base)) {
727 ret = PTR_ERR(abb->base); 722 ret = PTR_ERR(abb->base);
@@ -770,11 +765,6 @@ static int ti_abb_probe(struct platform_device *pdev)
770 765
771 pname = "ldo-address"; 766 pname = "ldo-address";
772 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); 767 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
773 if (!res) {
774 dev_dbg(dev, "Missing '%s' IO resource\n", pname);
775 ret = -ENODEV;
776 goto skip_opt;
777 }
778 abb->ldo_base = devm_ioremap_resource(dev, res); 768 abb->ldo_base = devm_ioremap_resource(dev, res);
779 if (IS_ERR(abb->ldo_base)) { 769 if (IS_ERR(abb->ldo_base)) {
780 ret = PTR_ERR(abb->ldo_base); 770 ret = PTR_ERR(abb->ldo_base);
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c
index 6e67be75ea1b..9392a7ca3d2d 100644
--- a/drivers/regulator/tps51632-regulator.c
+++ b/drivers/regulator/tps51632-regulator.c
@@ -275,7 +275,7 @@ static int tps51632_probe(struct i2c_client *client,
275 } 275 }
276 } 276 }
277 277
278 pdata = client->dev.platform_data; 278 pdata = dev_get_platdata(&client->dev);
279 if (!pdata && client->dev.of_node) 279 if (!pdata && client->dev.of_node)
280 pdata = of_get_tps51632_platform_data(&client->dev); 280 pdata = of_get_tps51632_platform_data(&client->dev);
281 if (!pdata) { 281 if (!pdata) {
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index a490d5b749b2..0b7ebb1ebf85 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -350,7 +350,7 @@ static int tps62360_probe(struct i2c_client *client,
350 int i; 350 int i;
351 int chip_id; 351 int chip_id;
352 352
353 pdata = client->dev.platform_data; 353 pdata = dev_get_platdata(&client->dev);
354 354
355 if (client->dev.of_node) { 355 if (client->dev.of_node) {
356 const struct of_device_id *match; 356 const struct of_device_id *match;
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index 9d053e23e9eb..a15263d4bdff 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -218,7 +218,7 @@ static int tps_65023_probe(struct i2c_client *client,
218 * init_data points to array of regulator_init structures 218 * init_data points to array of regulator_init structures
219 * coming from the board-evm file. 219 * coming from the board-evm file.
220 */ 220 */
221 init_data = client->dev.platform_data; 221 init_data = dev_get_platdata(&client->dev);
222 if (!init_data) 222 if (!init_data)
223 return -EIO; 223 return -EIO;
224 224
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 2df4616621f5..90861d68a0b0 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -27,7 +27,7 @@
27#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
28#include <linux/mfd/tps65217.h> 28#include <linux/mfd/tps65217.h>
29 29
30#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t) \ 30#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t, _lr, _nlr) \
31 { \ 31 { \
32 .name = _name, \ 32 .name = _name, \
33 .id = _id, \ 33 .id = _id, \
@@ -40,17 +40,10 @@
40 .enable_reg = TPS65217_REG_ENABLE, \ 40 .enable_reg = TPS65217_REG_ENABLE, \
41 .enable_mask = _em, \ 41 .enable_mask = _em, \
42 .volt_table = _t, \ 42 .volt_table = _t, \
43 .linear_ranges = _lr, \
44 .n_linear_ranges = _nlr, \
43 } \ 45 } \
44 46
45#define TPS65217_INFO(_nm, _min, _max, _f1, _f2) \
46 { \
47 .name = _nm, \
48 .min_uV = _min, \
49 .max_uV = _max, \
50 .vsel_to_uv = _f1, \
51 .uv_to_vsel = _f2, \
52 }
53
54static const unsigned int LDO1_VSEL_table[] = { 47static const unsigned int LDO1_VSEL_table[] = {
55 1000000, 1100000, 1200000, 1250000, 48 1000000, 1100000, 1200000, 1250000,
56 1300000, 1350000, 1400000, 1500000, 49 1300000, 1350000, 1400000, 1500000,
@@ -58,88 +51,26 @@ static const unsigned int LDO1_VSEL_table[] = {
58 2800000, 3000000, 3100000, 3300000, 51 2800000, 3000000, 3100000, 3300000,
59}; 52};
60 53
61static int tps65217_vsel_to_uv1(unsigned int vsel) 54static const struct regulator_linear_range tps65217_uv1_ranges[] = {
62{ 55 { .min_uV = 900000, .max_uV = 1500000, .min_sel = 0, .max_sel = 24,
63 int uV = 0; 56 .uV_step = 25000 },
64 57 { .min_uV = 1550000, .max_uV = 1800000, .min_sel = 25, .max_sel = 30,
65 if (vsel > 63) 58 .uV_step = 50000 },
66 return -EINVAL; 59 { .min_uV = 1850000, .max_uV = 2900000, .min_sel = 31, .max_sel = 52,
67 60 .uV_step = 50000 },
68 if (vsel <= 24) 61 { .min_uV = 3000000, .max_uV = 3200000, .min_sel = 53, .max_sel = 55,
69 uV = vsel * 25000 + 900000; 62 .uV_step = 100000 },
70 else if (vsel <= 52) 63 { .min_uV = 3300000, .max_uV = 3300000, .min_sel = 56, .max_sel = 62,
71 uV = (vsel - 24) * 50000 + 1500000; 64 .uV_step = 0 },
72 else if (vsel < 56) 65};
73 uV = (vsel - 52) * 100000 + 2900000;
74 else
75 uV = 3300000;
76
77 return uV;
78}
79
80static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel)
81{
82 if (uV < 0 || uV > 3300000)
83 return -EINVAL;
84
85 if (uV <= 1500000)
86 *vsel = DIV_ROUND_UP(uV - 900000, 25000);
87 else if (uV <= 2900000)
88 *vsel = 24 + DIV_ROUND_UP(uV - 1500000, 50000);
89 else if (uV < 3300000)
90 *vsel = 52 + DIV_ROUND_UP(uV - 2900000, 100000);
91 else
92 *vsel = 56;
93
94 return 0;
95}
96
97static int tps65217_vsel_to_uv2(unsigned int vsel)
98{
99 int uV = 0;
100
101 if (vsel > 31)
102 return -EINVAL;
103
104 if (vsel <= 8)
105 uV = vsel * 50000 + 1500000;
106 else if (vsel <= 13)
107 uV = (vsel - 8) * 100000 + 1900000;
108 else
109 uV = (vsel - 13) * 50000 + 2400000;
110
111 return uV;
112}
113
114static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
115{
116 if (uV < 0 || uV > 3300000)
117 return -EINVAL;
118
119 if (uV <= 1900000)
120 *vsel = DIV_ROUND_UP(uV - 1500000, 50000);
121 else if (uV <= 2400000)
122 *vsel = 8 + DIV_ROUND_UP(uV - 1900000, 100000);
123 else
124 *vsel = 13 + DIV_ROUND_UP(uV - 2400000, 50000);
125
126 return 0;
127}
128 66
129static struct tps_info tps65217_pmic_regs[] = { 67static const struct regulator_linear_range tps65217_uv2_ranges[] = {
130 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, 68 { .min_uV = 1500000, .max_uV = 1900000, .min_sel = 0, .max_sel = 8,
131 tps65217_uv_to_vsel1), 69 .uV_step = 50000 },
132 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, 70 { .min_uV = 2000000, .max_uV = 2400000, .min_sel = 9, .max_sel = 13,
133 tps65217_uv_to_vsel1), 71 .uV_step = 100000 },
134 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, 72 { .min_uV = 2450000, .max_uV = 3300000, .min_sel = 14, .max_sel = 31,
135 tps65217_uv_to_vsel1), 73 .uV_step = 50000 },
136 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL),
137 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1,
138 tps65217_uv_to_vsel1),
139 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2,
140 tps65217_uv_to_vsel2),
141 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2,
142 tps65217_uv_to_vsel2),
143}; 74};
144 75
145static int tps65217_pmic_enable(struct regulator_dev *dev) 76static int tps65217_pmic_enable(struct regulator_dev *dev)
@@ -192,49 +123,6 @@ static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
192 return ret; 123 return ret;
193} 124}
194 125
195static int tps65217_pmic_map_voltage(struct regulator_dev *dev,
196 int min_uV, int max_uV)
197{
198
199 struct tps65217 *tps = rdev_get_drvdata(dev);
200 unsigned int sel, rid = rdev_get_id(dev);
201 int ret;
202
203 /* LDO1 uses regulator_map_voltage_iterate() */
204 if (rid == TPS65217_LDO_1)
205 return -EINVAL;
206
207 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
208 return -EINVAL;
209
210 if (min_uV < tps->info[rid]->min_uV)
211 min_uV = tps->info[rid]->min_uV;
212
213 if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
214 return -EINVAL;
215
216 ret = tps->info[rid]->uv_to_vsel(min_uV, &sel);
217 if (ret)
218 return ret;
219
220 return sel;
221}
222
223static int tps65217_pmic_list_voltage(struct regulator_dev *dev,
224 unsigned selector)
225{
226 struct tps65217 *tps = rdev_get_drvdata(dev);
227 unsigned int rid = rdev_get_id(dev);
228
229 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
230 return -EINVAL;
231
232 if (selector >= dev->desc->n_voltages)
233 return -EINVAL;
234
235 return tps->info[rid]->vsel_to_uv(selector);
236}
237
238/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ 126/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
239static struct regulator_ops tps65217_pmic_ops = { 127static struct regulator_ops tps65217_pmic_ops = {
240 .is_enabled = regulator_is_enabled_regmap, 128 .is_enabled = regulator_is_enabled_regmap,
@@ -242,8 +130,8 @@ static struct regulator_ops tps65217_pmic_ops = {
242 .disable = tps65217_pmic_disable, 130 .disable = tps65217_pmic_disable,
243 .get_voltage_sel = regulator_get_voltage_sel_regmap, 131 .get_voltage_sel = regulator_get_voltage_sel_regmap,
244 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 132 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
245 .list_voltage = tps65217_pmic_list_voltage, 133 .list_voltage = regulator_list_voltage_linear_range,
246 .map_voltage = tps65217_pmic_map_voltage, 134 .map_voltage = regulator_map_voltage_linear_range,
247}; 135};
248 136
249/* Operations permitted on LDO1 */ 137/* Operations permitted on LDO1 */
@@ -259,27 +147,33 @@ static struct regulator_ops tps65217_pmic_ldo1_ops = {
259static const struct regulator_desc regulators[] = { 147static const struct regulator_desc regulators[] = {
260 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64, 148 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64,
261 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK, 149 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK,
262 TPS65217_ENABLE_DC1_EN, NULL), 150 TPS65217_ENABLE_DC1_EN, NULL, tps65217_uv1_ranges,
151 2), /* DCDC1 voltage range: 900000 ~ 1800000 */
263 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64, 152 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64,
264 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK, 153 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK,
265 TPS65217_ENABLE_DC2_EN, NULL), 154 TPS65217_ENABLE_DC2_EN, NULL, tps65217_uv1_ranges,
155 ARRAY_SIZE(tps65217_uv1_ranges)),
266 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64, 156 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64,
267 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK, 157 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK,
268 TPS65217_ENABLE_DC3_EN, NULL), 158 TPS65217_ENABLE_DC3_EN, NULL, tps65217_uv1_ranges,
159 1), /* DCDC3 voltage range: 900000 ~ 1500000 */
269 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16, 160 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16,
270 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK, 161 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK,
271 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table), 162 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table, NULL, 0),
272 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64, 163 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64,
273 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK, 164 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK,
274 TPS65217_ENABLE_LDO2_EN, NULL), 165 TPS65217_ENABLE_LDO2_EN, NULL, tps65217_uv1_ranges,
166 ARRAY_SIZE(tps65217_uv1_ranges)),
275 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32, 167 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32,
276 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, 168 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK,
277 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, 169 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
278 NULL), 170 NULL, tps65217_uv2_ranges,
171 ARRAY_SIZE(tps65217_uv2_ranges)),
279 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32, 172 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32,
280 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, 173 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK,
281 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, 174 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
282 NULL), 175 NULL, tps65217_uv2_ranges,
176 ARRAY_SIZE(tps65217_uv2_ranges)),
283}; 177};
284 178
285#ifdef CONFIG_OF 179#ifdef CONFIG_OF
@@ -368,8 +262,6 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
368 continue; 262 continue;
369 263
370 /* Register the regulators */ 264 /* Register the regulators */
371 tps->info[i] = &tps65217_pmic_regs[i];
372
373 config.dev = tps->dev; 265 config.dev = tps->dev;
374 config.init_data = reg_data; 266 config.init_data = reg_data;
375 config.driver_data = tps; 267 config.driver_data = tps;
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 1094393155ed..62e8d28beabd 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -601,7 +601,7 @@ static int pmic_probe(struct spi_device *spi)
601 struct regulator_config config = { }; 601 struct regulator_config config = { };
602 int ret = 0, i; 602 int ret = 0, i;
603 603
604 init_data = dev->platform_data; 604 init_data = dev_get_platdata(dev);
605 if (!init_data) { 605 if (!init_data) {
606 dev_err(dev, "could not find regulator platform data\n"); 606 dev_err(dev, "could not find regulator platform data\n");
607 return -EINVAL; 607 return -EINVAL;
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c
index 17e994e47dc1..281e52ac64ba 100644
--- a/drivers/regulator/tps65912-regulator.c
+++ b/drivers/regulator/tps65912-regulator.c
@@ -118,6 +118,15 @@ struct tps65912_reg {
118 int eco_reg; 118 int eco_reg;
119}; 119};
120 120
121static const struct regulator_linear_range tps65912_ldo_ranges[] = {
122 { .min_uV = 800000, .max_uV = 1600000, .min_sel = 0, .max_sel = 32,
123 .uV_step = 25000 },
124 { .min_uV = 1650000, .max_uV = 3000000, .min_sel = 33, .max_sel = 60,
125 .uV_step = 50000 },
126 { .min_uV = 3100000, .max_uV = 3300000, .min_sel = 61, .max_sel = 63,
127 .uV_step = 100000 },
128};
129
121static int tps65912_get_range(struct tps65912_reg *pmic, int id) 130static int tps65912_get_range(struct tps65912_reg *pmic, int id)
122{ 131{
123 struct tps65912 *mfd = pmic->mfd; 132 struct tps65912 *mfd = pmic->mfd;
@@ -184,20 +193,6 @@ static unsigned long tps65912_vsel_to_uv_range3(u8 vsel)
184 return uv; 193 return uv;
185} 194}
186 195
187static unsigned long tps65912_vsel_to_uv_ldo(u8 vsel)
188{
189 unsigned long uv = 0;
190
191 if (vsel <= 32)
192 uv = ((vsel * 25000) + 800000);
193 else if (vsel > 32 && vsel <= 60)
194 uv = (((vsel - 32) * 50000) + 1600000);
195 else if (vsel > 60)
196 uv = (((vsel - 60) * 100000) + 3000000);
197
198 return uv;
199}
200
201static int tps65912_get_ctrl_register(int id) 196static int tps65912_get_ctrl_register(int id)
202{ 197{
203 if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4) 198 if (id >= TPS65912_REG_DCDC1 && id <= TPS65912_REG_LDO4)
@@ -376,9 +371,6 @@ static int tps65912_list_voltage(struct regulator_dev *dev, unsigned selector)
376 struct tps65912_reg *pmic = rdev_get_drvdata(dev); 371 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
377 int range, voltage = 0, id = rdev_get_id(dev); 372 int range, voltage = 0, id = rdev_get_id(dev);
378 373
379 if (id >= TPS65912_REG_LDO1 && id <= TPS65912_REG_LDO10)
380 return tps65912_vsel_to_uv_ldo(selector);
381
382 if (id > TPS65912_REG_DCDC4) 374 if (id > TPS65912_REG_DCDC4)
383 return -EINVAL; 375 return -EINVAL;
384 376
@@ -456,7 +448,8 @@ static struct regulator_ops tps65912_ops_ldo = {
456 .disable = tps65912_reg_disable, 448 .disable = tps65912_reg_disable,
457 .get_voltage_sel = tps65912_get_voltage_sel, 449 .get_voltage_sel = tps65912_get_voltage_sel,
458 .set_voltage_sel = tps65912_set_voltage_sel, 450 .set_voltage_sel = tps65912_set_voltage_sel,
459 .list_voltage = tps65912_list_voltage, 451 .list_voltage = regulator_list_voltage_linear_range,
452 .map_voltage = regulator_map_voltage_linear_range,
460}; 453};
461 454
462static int tps65912_probe(struct platform_device *pdev) 455static int tps65912_probe(struct platform_device *pdev)
@@ -495,8 +488,14 @@ static int tps65912_probe(struct platform_device *pdev)
495 pmic->desc[i].name = info->name; 488 pmic->desc[i].name = info->name;
496 pmic->desc[i].id = i; 489 pmic->desc[i].id = i;
497 pmic->desc[i].n_voltages = 64; 490 pmic->desc[i].n_voltages = 64;
498 pmic->desc[i].ops = (i > TPS65912_REG_DCDC4 ? 491 if (i > TPS65912_REG_DCDC4) {
499 &tps65912_ops_ldo : &tps65912_ops_dcdc); 492 pmic->desc[i].ops = &tps65912_ops_ldo;
493 pmic->desc[i].linear_ranges = tps65912_ldo_ranges;
494 pmic->desc[i].n_linear_ranges =
495 ARRAY_SIZE(tps65912_ldo_ranges);
496 } else {
497 pmic->desc[i].ops = &tps65912_ops_dcdc;
498 }
500 pmic->desc[i].type = REGULATOR_VOLTAGE; 499 pmic->desc[i].type = REGULATOR_VOLTAGE;
501 pmic->desc[i].owner = THIS_MODULE; 500 pmic->desc[i].owner = THIS_MODULE;
502 range = tps65912_get_range(pmic, i); 501 range = tps65912_get_range(pmic, i);
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 93bc4f456da4..78aae4cbb004 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -1108,7 +1108,7 @@ static int twlreg_probe(struct platform_device *pdev)
1108 drvdata = NULL; 1108 drvdata = NULL;
1109 } else { 1109 } else {
1110 id = pdev->id; 1110 id = pdev->id;
1111 initdata = pdev->dev.platform_data; 1111 initdata = dev_get_platdata(&pdev->dev);
1112 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) { 1112 for (i = 0, template = NULL; i < ARRAY_SIZE(twl_of_match); i++) {
1113 template = twl_of_match[i].data; 1113 template = twl_of_match[i].data;
1114 if (template && template->desc.id == id) 1114 if (template && template->desc.id == id)
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index a7c8deb5f28f..765acc11c9c8 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -111,7 +111,7 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
111 struct userspace_consumer_data *drvdata; 111 struct userspace_consumer_data *drvdata;
112 int ret; 112 int ret;
113 113
114 pdata = pdev->dev.platform_data; 114 pdata = dev_get_platdata(&pdev->dev);
115 if (!pdata) 115 if (!pdata)
116 return -EINVAL; 116 return -EINVAL;
117 117
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c
index a9d4284ea007..f53e78b9a84e 100644
--- a/drivers/regulator/virtual.c
+++ b/drivers/regulator/virtual.c
@@ -287,7 +287,7 @@ static const struct attribute_group regulator_virtual_attr_group = {
287 287
288static int regulator_virtual_probe(struct platform_device *pdev) 288static int regulator_virtual_probe(struct platform_device *pdev)
289{ 289{
290 char *reg_id = pdev->dev.platform_data; 290 char *reg_id = dev_get_platdata(&pdev->dev);
291 struct virtual_consumer_data *drvdata; 291 struct virtual_consumer_data *drvdata;
292 int ret; 292 int ret;
293 293
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index 46938cf162ad..11861cb861df 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -451,7 +451,7 @@ static void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc,
451static int wm831x_buckv_probe(struct platform_device *pdev) 451static int wm831x_buckv_probe(struct platform_device *pdev)
452{ 452{
453 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 453 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
454 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 454 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
455 struct regulator_config config = { }; 455 struct regulator_config config = { };
456 int id; 456 int id;
457 struct wm831x_dcdc *dcdc; 457 struct wm831x_dcdc *dcdc;
@@ -624,7 +624,7 @@ static struct regulator_ops wm831x_buckp_ops = {
624static int wm831x_buckp_probe(struct platform_device *pdev) 624static int wm831x_buckp_probe(struct platform_device *pdev)
625{ 625{
626 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 626 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
627 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 627 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
628 struct regulator_config config = { }; 628 struct regulator_config config = { };
629 int id; 629 int id;
630 struct wm831x_dcdc *dcdc; 630 struct wm831x_dcdc *dcdc;
@@ -770,7 +770,7 @@ static struct regulator_ops wm831x_boostp_ops = {
770static int wm831x_boostp_probe(struct platform_device *pdev) 770static int wm831x_boostp_probe(struct platform_device *pdev)
771{ 771{
772 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 772 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
773 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 773 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
774 struct regulator_config config = { }; 774 struct regulator_config config = { };
775 int id = pdev->id % ARRAY_SIZE(pdata->dcdc); 775 int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
776 struct wm831x_dcdc *dcdc; 776 struct wm831x_dcdc *dcdc;
@@ -880,7 +880,7 @@ static struct regulator_ops wm831x_epe_ops = {
880static int wm831x_epe_probe(struct platform_device *pdev) 880static int wm831x_epe_probe(struct platform_device *pdev)
881{ 881{
882 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 882 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
883 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 883 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
884 struct regulator_config config = { }; 884 struct regulator_config config = { };
885 int id = pdev->id % ARRAY_SIZE(pdata->epe); 885 int id = pdev->id % ARRAY_SIZE(pdata->epe);
886 struct wm831x_dcdc *dcdc; 886 struct wm831x_dcdc *dcdc;
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c
index 16ebdf94d0a0..4eb373de1fac 100644
--- a/drivers/regulator/wm831x-isink.c
+++ b/drivers/regulator/wm831x-isink.c
@@ -151,7 +151,7 @@ static irqreturn_t wm831x_isink_irq(int irq, void *data)
151static int wm831x_isink_probe(struct platform_device *pdev) 151static int wm831x_isink_probe(struct platform_device *pdev)
152{ 152{
153 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 153 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
154 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 154 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
155 struct wm831x_isink *isink; 155 struct wm831x_isink *isink;
156 int id = pdev->id % ARRAY_SIZE(pdata->isink); 156 int id = pdev->id % ARRAY_SIZE(pdata->isink);
157 struct regulator_config config = { }; 157 struct regulator_config config = { };
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 9ff883f80878..1432b26ef2e9 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -62,41 +62,12 @@ static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data)
62 * General purpose LDOs 62 * General purpose LDOs
63 */ 63 */
64 64
65#define WM831X_GP_LDO_SELECTOR_LOW 0xe 65static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = {
66#define WM831X_GP_LDO_MAX_SELECTOR 0x1f 66 { .min_uV = 900000, .max_uV = 1650000, .min_sel = 0, .max_sel = 14,
67 67 .uV_step = 50000 },
68static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, 68 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
69 unsigned int selector) 69 .uV_step = 100000 },
70{ 70};
71 /* 0.9-1.6V in 50mV steps */
72 if (selector <= WM831X_GP_LDO_SELECTOR_LOW)
73 return 900000 + (selector * 50000);
74 /* 1.7-3.3V in 100mV steps */
75 if (selector <= WM831X_GP_LDO_MAX_SELECTOR)
76 return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW)
77 * 100000);
78 return -EINVAL;
79}
80
81static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev,
82 int min_uV, int max_uV)
83{
84 int volt, vsel;
85
86 if (min_uV < 900000)
87 vsel = 0;
88 else if (min_uV < 1700000)
89 vsel = ((min_uV - 900000) / 50000);
90 else
91 vsel = ((min_uV - 1700000) / 100000)
92 + WM831X_GP_LDO_SELECTOR_LOW + 1;
93
94 volt = wm831x_gp_ldo_list_voltage(rdev, vsel);
95 if (volt < min_uV || volt > max_uV)
96 return -EINVAL;
97
98 return vsel;
99}
100 71
101static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, 72static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
102 int uV) 73 int uV)
@@ -105,7 +76,7 @@ static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
105 struct wm831x *wm831x = ldo->wm831x; 76 struct wm831x *wm831x = ldo->wm831x;
106 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 77 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
107 78
108 sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV); 79 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
109 if (sel < 0) 80 if (sel < 0)
110 return sel; 81 return sel;
111 82
@@ -230,8 +201,8 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
230 201
231 202
232static struct regulator_ops wm831x_gp_ldo_ops = { 203static struct regulator_ops wm831x_gp_ldo_ops = {
233 .list_voltage = wm831x_gp_ldo_list_voltage, 204 .list_voltage = regulator_list_voltage_linear_range,
234 .map_voltage = wm831x_gp_ldo_map_voltage, 205 .map_voltage = regulator_map_voltage_linear_range,
235 .get_voltage_sel = regulator_get_voltage_sel_regmap, 206 .get_voltage_sel = regulator_get_voltage_sel_regmap,
236 .set_voltage_sel = regulator_set_voltage_sel_regmap, 207 .set_voltage_sel = regulator_set_voltage_sel_regmap,
237 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, 208 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
@@ -250,7 +221,7 @@ static struct regulator_ops wm831x_gp_ldo_ops = {
250static int wm831x_gp_ldo_probe(struct platform_device *pdev) 221static int wm831x_gp_ldo_probe(struct platform_device *pdev)
251{ 222{
252 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 223 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
253 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 224 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
254 struct regulator_config config = { }; 225 struct regulator_config config = { };
255 int id; 226 int id;
256 struct wm831x_ldo *ldo; 227 struct wm831x_ldo *ldo;
@@ -290,7 +261,7 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
290 261
291 ldo->desc.id = id; 262 ldo->desc.id = id;
292 ldo->desc.type = REGULATOR_VOLTAGE; 263 ldo->desc.type = REGULATOR_VOLTAGE;
293 ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; 264 ldo->desc.n_voltages = 32;
294 ldo->desc.ops = &wm831x_gp_ldo_ops; 265 ldo->desc.ops = &wm831x_gp_ldo_ops;
295 ldo->desc.owner = THIS_MODULE; 266 ldo->desc.owner = THIS_MODULE;
296 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; 267 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
@@ -299,6 +270,8 @@ static int wm831x_gp_ldo_probe(struct platform_device *pdev)
299 ldo->desc.enable_mask = 1 << id; 270 ldo->desc.enable_mask = 1 << id;
300 ldo->desc.bypass_reg = ldo->base; 271 ldo->desc.bypass_reg = ldo->base;
301 ldo->desc.bypass_mask = WM831X_LDO1_SWI; 272 ldo->desc.bypass_mask = WM831X_LDO1_SWI;
273 ldo->desc.linear_ranges = wm831x_gp_ldo_ranges;
274 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges);
302 275
303 config.dev = pdev->dev.parent; 276 config.dev = pdev->dev.parent;
304 if (pdata) 277 if (pdata)
@@ -358,43 +331,12 @@ static struct platform_driver wm831x_gp_ldo_driver = {
358 * Analogue LDOs 331 * Analogue LDOs
359 */ 332 */
360 333
361 334static const struct regulator_linear_range wm831x_aldo_ranges[] = {
362#define WM831X_ALDO_SELECTOR_LOW 0xc 335 { .min_uV = 1000000, .max_uV = 1650000, .min_sel = 0, .max_sel = 12,
363#define WM831X_ALDO_MAX_SELECTOR 0x1f 336 .uV_step = 50000 },
364 337 { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31,
365static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, 338 .uV_step = 100000 },
366 unsigned int selector) 339};
367{
368 /* 1-1.6V in 50mV steps */
369 if (selector <= WM831X_ALDO_SELECTOR_LOW)
370 return 1000000 + (selector * 50000);
371 /* 1.7-3.5V in 100mV steps */
372 if (selector <= WM831X_ALDO_MAX_SELECTOR)
373 return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW)
374 * 100000);
375 return -EINVAL;
376}
377
378static int wm831x_aldo_map_voltage(struct regulator_dev *rdev,
379 int min_uV, int max_uV)
380{
381 int volt, vsel;
382
383 if (min_uV < 1000000)
384 vsel = 0;
385 else if (min_uV < 1700000)
386 vsel = ((min_uV - 1000000) / 50000);
387 else
388 vsel = ((min_uV - 1700000) / 100000)
389 + WM831X_ALDO_SELECTOR_LOW + 1;
390
391 volt = wm831x_aldo_list_voltage(rdev, vsel);
392 if (volt < min_uV || volt > max_uV)
393 return -EINVAL;
394
395 return vsel;
396
397}
398 340
399static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 341static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
400 int uV) 342 int uV)
@@ -403,7 +345,7 @@ static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
403 struct wm831x *wm831x = ldo->wm831x; 345 struct wm831x *wm831x = ldo->wm831x;
404 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 346 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
405 347
406 sel = wm831x_aldo_map_voltage(rdev, uV, uV); 348 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
407 if (sel < 0) 349 if (sel < 0)
408 return sel; 350 return sel;
409 351
@@ -486,8 +428,8 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev)
486} 428}
487 429
488static struct regulator_ops wm831x_aldo_ops = { 430static struct regulator_ops wm831x_aldo_ops = {
489 .list_voltage = wm831x_aldo_list_voltage, 431 .list_voltage = regulator_list_voltage_linear_range,
490 .map_voltage = wm831x_aldo_map_voltage, 432 .map_voltage = regulator_map_voltage_linear_range,
491 .get_voltage_sel = regulator_get_voltage_sel_regmap, 433 .get_voltage_sel = regulator_get_voltage_sel_regmap,
492 .set_voltage_sel = regulator_set_voltage_sel_regmap, 434 .set_voltage_sel = regulator_set_voltage_sel_regmap,
493 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, 435 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
@@ -505,7 +447,7 @@ static struct regulator_ops wm831x_aldo_ops = {
505static int wm831x_aldo_probe(struct platform_device *pdev) 447static int wm831x_aldo_probe(struct platform_device *pdev)
506{ 448{
507 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 449 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
508 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 450 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
509 struct regulator_config config = { }; 451 struct regulator_config config = { };
510 int id; 452 int id;
511 struct wm831x_ldo *ldo; 453 struct wm831x_ldo *ldo;
@@ -545,7 +487,9 @@ static int wm831x_aldo_probe(struct platform_device *pdev)
545 487
546 ldo->desc.id = id; 488 ldo->desc.id = id;
547 ldo->desc.type = REGULATOR_VOLTAGE; 489 ldo->desc.type = REGULATOR_VOLTAGE;
548 ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; 490 ldo->desc.n_voltages = 32;
491 ldo->desc.linear_ranges = wm831x_aldo_ranges;
492 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges);
549 ldo->desc.ops = &wm831x_aldo_ops; 493 ldo->desc.ops = &wm831x_aldo_ops;
550 ldo->desc.owner = THIS_MODULE; 494 ldo->desc.owner = THIS_MODULE;
551 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; 495 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
@@ -661,7 +605,7 @@ static struct regulator_ops wm831x_alive_ldo_ops = {
661static int wm831x_alive_ldo_probe(struct platform_device *pdev) 605static int wm831x_alive_ldo_probe(struct platform_device *pdev)
662{ 606{
663 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 607 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
664 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 608 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
665 struct regulator_config config = { }; 609 struct regulator_config config = { };
666 int id; 610 int id;
667 struct wm831x_ldo *ldo; 611 struct wm831x_ldo *ldo;
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 7f0fa22ef2aa..835b5f0f344e 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -542,41 +542,12 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
542 return 0; 542 return 0;
543} 543}
544 544
545static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, 545static const struct regulator_linear_range wm8350_ldo_ranges[] = {
546 unsigned selector) 546 { .min_uV = 900000, .max_uV = 1750000, .min_sel = 0, .max_sel = 15,
547{ 547 .uV_step = 50000 },
548 if (selector > WM8350_LDO1_VSEL_MASK) 548 { .min_uV = 1800000, .max_uV = 3300000, .min_sel = 16, .max_sel = 31,
549 return -EINVAL; 549 .uV_step = 100000 },
550 550};
551 if (selector < 16)
552 return (selector * 50000) + 900000;
553 else
554 return ((selector - 16) * 100000) + 1800000;
555}
556
557static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
558 int max_uV)
559{
560 int volt, sel;
561 int min_mV = min_uV / 1000;
562 int max_mV = max_uV / 1000;
563
564 if (min_mV < 900 || min_mV > 3300)
565 return -EINVAL;
566 if (max_mV < 900 || max_mV > 3300)
567 return -EINVAL;
568
569 if (min_mV < 1800) /* step size is 50mV < 1800mV */
570 sel = DIV_ROUND_UP(min_uV - 900, 50);
571 else /* step size is 100mV > 1800mV */
572 sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;
573
574 volt = wm8350_ldo_list_voltage(rdev, sel);
575 if (volt < min_uV || volt > max_uV)
576 return -EINVAL;
577
578 return sel;
579}
580 551
581static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) 552static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
582{ 553{
@@ -603,7 +574,7 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
603 return -EINVAL; 574 return -EINVAL;
604 } 575 }
605 576
606 sel = wm8350_ldo_map_voltage(rdev, uV, uV); 577 sel = regulator_map_voltage_linear_range(rdev, uV, uV);
607 if (sel < 0) 578 if (sel < 0)
608 return -EINVAL; 579 return -EINVAL;
609 580
@@ -998,10 +969,10 @@ static struct regulator_ops wm8350_dcdc2_5_ops = {
998}; 969};
999 970
1000static struct regulator_ops wm8350_ldo_ops = { 971static struct regulator_ops wm8350_ldo_ops = {
1001 .map_voltage = wm8350_ldo_map_voltage, 972 .map_voltage = regulator_map_voltage_linear_range,
1002 .set_voltage_sel = regulator_set_voltage_sel_regmap, 973 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1003 .get_voltage_sel = regulator_get_voltage_sel_regmap, 974 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1004 .list_voltage = wm8350_ldo_list_voltage, 975 .list_voltage = regulator_list_voltage_linear_range,
1005 .enable = regulator_enable_regmap, 976 .enable = regulator_enable_regmap,
1006 .disable = regulator_disable_regmap, 977 .disable = regulator_disable_regmap,
1007 .is_enabled = regulator_is_enabled_regmap, 978 .is_enabled = regulator_is_enabled_regmap,
@@ -1108,6 +1079,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1108 .irq = WM8350_IRQ_UV_LDO1, 1079 .irq = WM8350_IRQ_UV_LDO1,
1109 .type = REGULATOR_VOLTAGE, 1080 .type = REGULATOR_VOLTAGE,
1110 .n_voltages = WM8350_LDO1_VSEL_MASK + 1, 1081 .n_voltages = WM8350_LDO1_VSEL_MASK + 1,
1082 .linear_ranges = wm8350_ldo_ranges,
1083 .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
1111 .vsel_reg = WM8350_LDO1_CONTROL, 1084 .vsel_reg = WM8350_LDO1_CONTROL,
1112 .vsel_mask = WM8350_LDO1_VSEL_MASK, 1085 .vsel_mask = WM8350_LDO1_VSEL_MASK,
1113 .enable_reg = WM8350_DCDC_LDO_REQUESTED, 1086 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
@@ -1121,6 +1094,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1121 .irq = WM8350_IRQ_UV_LDO2, 1094 .irq = WM8350_IRQ_UV_LDO2,
1122 .type = REGULATOR_VOLTAGE, 1095 .type = REGULATOR_VOLTAGE,
1123 .n_voltages = WM8350_LDO2_VSEL_MASK + 1, 1096 .n_voltages = WM8350_LDO2_VSEL_MASK + 1,
1097 .linear_ranges = wm8350_ldo_ranges,
1098 .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
1124 .vsel_reg = WM8350_LDO2_CONTROL, 1099 .vsel_reg = WM8350_LDO2_CONTROL,
1125 .vsel_mask = WM8350_LDO2_VSEL_MASK, 1100 .vsel_mask = WM8350_LDO2_VSEL_MASK,
1126 .enable_reg = WM8350_DCDC_LDO_REQUESTED, 1101 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
@@ -1134,6 +1109,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1134 .irq = WM8350_IRQ_UV_LDO3, 1109 .irq = WM8350_IRQ_UV_LDO3,
1135 .type = REGULATOR_VOLTAGE, 1110 .type = REGULATOR_VOLTAGE,
1136 .n_voltages = WM8350_LDO3_VSEL_MASK + 1, 1111 .n_voltages = WM8350_LDO3_VSEL_MASK + 1,
1112 .linear_ranges = wm8350_ldo_ranges,
1113 .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
1137 .vsel_reg = WM8350_LDO3_CONTROL, 1114 .vsel_reg = WM8350_LDO3_CONTROL,
1138 .vsel_mask = WM8350_LDO3_VSEL_MASK, 1115 .vsel_mask = WM8350_LDO3_VSEL_MASK,
1139 .enable_reg = WM8350_DCDC_LDO_REQUESTED, 1116 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
@@ -1147,6 +1124,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1147 .irq = WM8350_IRQ_UV_LDO4, 1124 .irq = WM8350_IRQ_UV_LDO4,
1148 .type = REGULATOR_VOLTAGE, 1125 .type = REGULATOR_VOLTAGE,
1149 .n_voltages = WM8350_LDO4_VSEL_MASK + 1, 1126 .n_voltages = WM8350_LDO4_VSEL_MASK + 1,
1127 .linear_ranges = wm8350_ldo_ranges,
1128 .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges),
1150 .vsel_reg = WM8350_LDO4_CONTROL, 1129 .vsel_reg = WM8350_LDO4_CONTROL,
1151 .vsel_mask = WM8350_LDO4_VSEL_MASK, 1130 .vsel_mask = WM8350_LDO4_VSEL_MASK,
1152 .enable_reg = WM8350_DCDC_LDO_REQUESTED, 1131 .enable_reg = WM8350_DCDC_LDO_REQUESTED,
@@ -1222,7 +1201,7 @@ static int wm8350_regulator_probe(struct platform_device *pdev)
1222 } 1201 }
1223 1202
1224 config.dev = &pdev->dev; 1203 config.dev = &pdev->dev;
1225 config.init_data = pdev->dev.platform_data; 1204 config.init_data = dev_get_platdata(&pdev->dev);
1226 config.driver_data = dev_get_drvdata(&pdev->dev); 1205 config.driver_data = dev_get_drvdata(&pdev->dev);
1227 config.regmap = wm8350->regmap; 1206 config.regmap = wm8350->regmap;
1228 1207
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index a09f03ee5506..58f51bec13f2 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -19,47 +19,21 @@
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20#include <linux/mfd/wm8400-private.h> 20#include <linux/mfd/wm8400-private.h>
21 21
22static int wm8400_ldo_list_voltage(struct regulator_dev *dev, 22static const struct regulator_linear_range wm8400_ldo_ranges[] = {
23 unsigned selector) 23 { .min_uV = 900000, .max_uV = 1600000, .min_sel = 0, .max_sel = 14,
24{ 24 .uV_step = 50000 },
25 if (selector > WM8400_LDO1_VSEL_MASK) 25 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31,
26 return -EINVAL; 26 .uV_step = 100000 },
27 27};
28 if (selector < 15)
29 return 900000 + (selector * 50000);
30 else
31 return 1700000 + ((selector - 15) * 100000);
32}
33
34static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
35 int min_uV, int max_uV)
36{
37 u16 val;
38 int volt;
39
40 if (min_uV < 900000 || min_uV > 3300000)
41 return -EINVAL;
42
43 if (min_uV < 1700000) /* Steps of 50mV from 900mV; */
44 val = DIV_ROUND_UP(min_uV - 900000, 50000);
45 else /* Steps of 100mV from 1700mV */
46 val = DIV_ROUND_UP(min_uV - 1700000, 100000) + 15;
47
48 volt = wm8400_ldo_list_voltage(dev, val);
49 if (volt < min_uV || volt > max_uV)
50 return -EINVAL;
51
52 return val;
53}
54 28
55static struct regulator_ops wm8400_ldo_ops = { 29static struct regulator_ops wm8400_ldo_ops = {
56 .is_enabled = regulator_is_enabled_regmap, 30 .is_enabled = regulator_is_enabled_regmap,
57 .enable = regulator_enable_regmap, 31 .enable = regulator_enable_regmap,
58 .disable = regulator_disable_regmap, 32 .disable = regulator_disable_regmap,
59 .list_voltage = wm8400_ldo_list_voltage, 33 .list_voltage = regulator_list_voltage_linear_range,
60 .get_voltage_sel = regulator_get_voltage_sel_regmap, 34 .get_voltage_sel = regulator_get_voltage_sel_regmap,
61 .set_voltage_sel = regulator_set_voltage_sel_regmap, 35 .set_voltage_sel = regulator_set_voltage_sel_regmap,
62 .map_voltage = wm8400_ldo_map_voltage, 36 .map_voltage = regulator_map_voltage_linear_range,
63}; 37};
64 38
65static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) 39static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
@@ -155,6 +129,8 @@ static struct regulator_desc regulators[] = {
155 .enable_reg = WM8400_LDO1_CONTROL, 129 .enable_reg = WM8400_LDO1_CONTROL,
156 .enable_mask = WM8400_LDO1_ENA, 130 .enable_mask = WM8400_LDO1_ENA,
157 .n_voltages = WM8400_LDO1_VSEL_MASK + 1, 131 .n_voltages = WM8400_LDO1_VSEL_MASK + 1,
132 .linear_ranges = wm8400_ldo_ranges,
133 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
158 .vsel_reg = WM8400_LDO1_CONTROL, 134 .vsel_reg = WM8400_LDO1_CONTROL,
159 .vsel_mask = WM8400_LDO1_VSEL_MASK, 135 .vsel_mask = WM8400_LDO1_VSEL_MASK,
160 .type = REGULATOR_VOLTAGE, 136 .type = REGULATOR_VOLTAGE,
@@ -167,6 +143,8 @@ static struct regulator_desc regulators[] = {
167 .enable_reg = WM8400_LDO2_CONTROL, 143 .enable_reg = WM8400_LDO2_CONTROL,
168 .enable_mask = WM8400_LDO2_ENA, 144 .enable_mask = WM8400_LDO2_ENA,
169 .n_voltages = WM8400_LDO2_VSEL_MASK + 1, 145 .n_voltages = WM8400_LDO2_VSEL_MASK + 1,
146 .linear_ranges = wm8400_ldo_ranges,
147 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
170 .type = REGULATOR_VOLTAGE, 148 .type = REGULATOR_VOLTAGE,
171 .vsel_reg = WM8400_LDO2_CONTROL, 149 .vsel_reg = WM8400_LDO2_CONTROL,
172 .vsel_mask = WM8400_LDO2_VSEL_MASK, 150 .vsel_mask = WM8400_LDO2_VSEL_MASK,
@@ -179,6 +157,8 @@ static struct regulator_desc regulators[] = {
179 .enable_reg = WM8400_LDO3_CONTROL, 157 .enable_reg = WM8400_LDO3_CONTROL,
180 .enable_mask = WM8400_LDO3_ENA, 158 .enable_mask = WM8400_LDO3_ENA,
181 .n_voltages = WM8400_LDO3_VSEL_MASK + 1, 159 .n_voltages = WM8400_LDO3_VSEL_MASK + 1,
160 .linear_ranges = wm8400_ldo_ranges,
161 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
182 .vsel_reg = WM8400_LDO3_CONTROL, 162 .vsel_reg = WM8400_LDO3_CONTROL,
183 .vsel_mask = WM8400_LDO3_VSEL_MASK, 163 .vsel_mask = WM8400_LDO3_VSEL_MASK,
184 .type = REGULATOR_VOLTAGE, 164 .type = REGULATOR_VOLTAGE,
@@ -191,6 +171,8 @@ static struct regulator_desc regulators[] = {
191 .enable_reg = WM8400_LDO4_CONTROL, 171 .enable_reg = WM8400_LDO4_CONTROL,
192 .enable_mask = WM8400_LDO4_ENA, 172 .enable_mask = WM8400_LDO4_ENA,
193 .n_voltages = WM8400_LDO4_VSEL_MASK + 1, 173 .n_voltages = WM8400_LDO4_VSEL_MASK + 1,
174 .linear_ranges = wm8400_ldo_ranges,
175 .n_linear_ranges = ARRAY_SIZE(wm8400_ldo_ranges),
194 .vsel_reg = WM8400_LDO4_CONTROL, 176 .vsel_reg = WM8400_LDO4_CONTROL,
195 .vsel_mask = WM8400_LDO4_VSEL_MASK, 177 .vsel_mask = WM8400_LDO4_VSEL_MASK,
196 .type = REGULATOR_VOLTAGE, 178 .type = REGULATOR_VOLTAGE,
@@ -233,7 +215,7 @@ static int wm8400_regulator_probe(struct platform_device *pdev)
233 struct regulator_dev *rdev; 215 struct regulator_dev *rdev;
234 216
235 config.dev = &pdev->dev; 217 config.dev = &pdev->dev;
236 config.init_data = pdev->dev.platform_data; 218 config.init_data = dev_get_platdata(&pdev->dev);
237 config.driver_data = wm8400; 219 config.driver_data = wm8400;
238 config.regmap = wm8400->regmap; 220 config.regmap = wm8400->regmap;
239 221
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 8f2a8a7a3f99..5ee2a208457c 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -125,7 +125,7 @@ static const struct regulator_init_data wm8994_ldo_default[] = {
125static int wm8994_ldo_probe(struct platform_device *pdev) 125static int wm8994_ldo_probe(struct platform_device *pdev)
126{ 126{
127 struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); 127 struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
128 struct wm8994_pdata *pdata = wm8994->dev->platform_data; 128 struct wm8994_pdata *pdata = dev_get_platdata(wm8994->dev);
129 int id = pdev->id % ARRAY_SIZE(pdata->ldo); 129 int id = pdev->id % ARRAY_SIZE(pdata->ldo);
130 struct regulator_config config = { }; 130 struct regulator_config config = { };
131 struct wm8994_ldo *ldo; 131 struct wm8994_ldo *ldo;
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 1a8dd7afe084..c06d78af3342 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -160,7 +160,8 @@ enum palmas_regulators {
160 PALMAS_REG_SMPS7, 160 PALMAS_REG_SMPS7,
161 PALMAS_REG_SMPS8, 161 PALMAS_REG_SMPS8,
162 PALMAS_REG_SMPS9, 162 PALMAS_REG_SMPS9,
163 PALMAS_REG_SMPS10, 163 PALMAS_REG_SMPS10_OUT2,
164 PALMAS_REG_SMPS10_OUT1,
164 /* LDO regulators */ 165 /* LDO regulators */
165 PALMAS_REG_LDO1, 166 PALMAS_REG_LDO1,
166 PALMAS_REG_LDO2, 167 PALMAS_REG_LDO2,
@@ -355,9 +356,9 @@ struct palmas_pmic {
355 int smps123; 356 int smps123;
356 int smps457; 357 int smps457;
357 358
358 int range[PALMAS_REG_SMPS10]; 359 int range[PALMAS_REG_SMPS10_OUT1];
359 unsigned int ramp_delay[PALMAS_REG_SMPS10]; 360 unsigned int ramp_delay[PALMAS_REG_SMPS10_OUT1];
360 unsigned int current_reg_mode[PALMAS_REG_SMPS10]; 361 unsigned int current_reg_mode[PALMAS_REG_SMPS10_OUT1];
361}; 362};
362 363
363struct palmas_resource { 364struct palmas_resource {
diff --git a/include/linux/mfd/samsung/s2mps11.h b/include/linux/mfd/samsung/s2mps11.h
index 4e94dc65f987..d0d52ea60074 100644
--- a/include/linux/mfd/samsung/s2mps11.h
+++ b/include/linux/mfd/samsung/s2mps11.h
@@ -191,6 +191,17 @@ enum s2mps11_regulators {
191#define S2MPS11_BUCK_N_VOLTAGES (S2MPS11_BUCK_VSEL_MASK + 1) 191#define S2MPS11_BUCK_N_VOLTAGES (S2MPS11_BUCK_VSEL_MASK + 1)
192#define S2MPS11_RAMP_DELAY 25000 /* uV/us */ 192#define S2MPS11_RAMP_DELAY 25000 /* uV/us */
193 193
194
195#define S2MPS11_BUCK2_RAMP_SHIFT 6
196#define S2MPS11_BUCK34_RAMP_SHIFT 4
197#define S2MPS11_BUCK5_RAMP_SHIFT 6
198#define S2MPS11_BUCK16_RAMP_SHIFT 4
199#define S2MPS11_BUCK7810_RAMP_SHIFT 2
200#define S2MPS11_BUCK9_RAMP_SHIFT 0
201#define S2MPS11_BUCK2_RAMP_EN_SHIFT 3
202#define S2MPS11_BUCK3_RAMP_EN_SHIFT 2
203#define S2MPS11_BUCK4_RAMP_EN_SHIFT 1
204#define S2MPS11_BUCK6_RAMP_EN_SHIFT 0
194#define S2MPS11_PMIC_EN_SHIFT 6 205#define S2MPS11_PMIC_EN_SHIFT 6
195#define S2MPS11_REGULATOR_MAX (S2MPS11_REG_MAX - 3) 206#define S2MPS11_REGULATOR_MAX (S2MPS11_REG_MAX - 3)
196 207
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index 29eab2bd3dfa..a5a7f0130e96 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -244,24 +244,6 @@ struct tps65217_board {
244}; 244};
245 245
246/** 246/**
247 * struct tps_info - packages regulator constraints
248 * @name: Voltage regulator name
249 * @min_uV: minimum micro volts
250 * @max_uV: minimum micro volts
251 * @vsel_to_uv: Function pointer to get voltage from selector
252 * @uv_to_vsel: Function pointer to get selector from voltage
253 *
254 * This data is used to check the regualtor voltage limits while setting.
255 */
256struct tps_info {
257 const char *name;
258 int min_uV;
259 int max_uV;
260 int (*vsel_to_uv)(unsigned int vsel);
261 int (*uv_to_vsel)(int uV, unsigned int *vsel);
262};
263
264/**
265 * struct tps65217 - tps65217 sub-driver chip access routines 247 * struct tps65217 - tps65217 sub-driver chip access routines
266 * 248 *
267 * Device data may be used to access the TPS65217 chip 249 * Device data may be used to access the TPS65217 chip
@@ -273,7 +255,6 @@ struct tps65217 {
273 unsigned int id; 255 unsigned int id;
274 struct regulator_desc desc[TPS65217_NUM_REGULATOR]; 256 struct regulator_desc desc[TPS65217_NUM_REGULATOR];
275 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR]; 257 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR];
276 struct tps_info *info[TPS65217_NUM_REGULATOR];
277 struct regmap *regmap; 258 struct regmap *regmap;
278}; 259};
279 260
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index 3a76389c6aaa..27be915caa96 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -137,6 +137,12 @@ struct regulator *__must_check devm_regulator_get(struct device *dev,
137 const char *id); 137 const char *id);
138struct regulator *__must_check regulator_get_exclusive(struct device *dev, 138struct regulator *__must_check regulator_get_exclusive(struct device *dev,
139 const char *id); 139 const char *id);
140struct regulator *__must_check devm_regulator_get_exclusive(struct device *dev,
141 const char *id);
142struct regulator *__must_check regulator_get_optional(struct device *dev,
143 const char *id);
144struct regulator *__must_check devm_regulator_get_optional(struct device *dev,
145 const char *id);
140void regulator_put(struct regulator *regulator); 146void regulator_put(struct regulator *regulator);
141void devm_regulator_put(struct regulator *regulator); 147void devm_regulator_put(struct regulator *regulator);
142 148
@@ -217,6 +223,25 @@ devm_regulator_get(struct device *dev, const char *id)
217 return NULL; 223 return NULL;
218} 224}
219 225
226static inline struct regulator *__must_check
227regulator_get_exclusive(struct device *dev, const char *id)
228{
229 return NULL;
230}
231
232static inline struct regulator *__must_check
233regulator_get_optional(struct device *dev, const char *id)
234{
235 return NULL;
236}
237
238
239static inline struct regulator *__must_check
240devm_regulator_get_optional(struct device *dev, const char *id)
241{
242 return NULL;
243}
244
220static inline void regulator_put(struct regulator *regulator) 245static inline void regulator_put(struct regulator *regulator)
221{ 246{
222} 247}
@@ -369,8 +394,11 @@ static inline int regulator_count_voltages(struct regulator *regulator)
369static inline int regulator_set_voltage_tol(struct regulator *regulator, 394static inline int regulator_set_voltage_tol(struct regulator *regulator,
370 int new_uV, int tol_uV) 395 int new_uV, int tol_uV)
371{ 396{
372 return regulator_set_voltage(regulator, 397 if (regulator_set_voltage(regulator, new_uV, new_uV + tol_uV) == 0)
373 new_uV - tol_uV, new_uV + tol_uV); 398 return 0;
399 else
400 return regulator_set_voltage(regulator,
401 new_uV - tol_uV, new_uV + tol_uV);
374} 402}
375 403
376static inline int regulator_is_supported_voltage_tol(struct regulator *regulator, 404static inline int regulator_is_supported_voltage_tol(struct regulator *regulator,
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 6700cc94bdd1..67e13aa5a478 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -40,6 +40,24 @@ enum regulator_status {
40}; 40};
41 41
42/** 42/**
43 * Specify a range of voltages for regulator_map_linar_range() and
44 * regulator_list_linear_range().
45 *
46 * @min_uV: Lowest voltage in range
47 * @max_uV: Highest voltage in range
48 * @min_sel: Lowest selector for range
49 * @max_sel: Highest selector for range
50 * @uV_step: Step size
51 */
52struct regulator_linear_range {
53 unsigned int min_uV;
54 unsigned int max_uV;
55 unsigned int min_sel;
56 unsigned int max_sel;
57 unsigned int uV_step;
58};
59
60/**
43 * struct regulator_ops - regulator operations. 61 * struct regulator_ops - regulator operations.
44 * 62 *
45 * @enable: Configure the regulator as enabled. 63 * @enable: Configure the regulator as enabled.
@@ -223,6 +241,9 @@ struct regulator_desc {
223 unsigned int linear_min_sel; 241 unsigned int linear_min_sel;
224 unsigned int ramp_delay; 242 unsigned int ramp_delay;
225 243
244 const struct regulator_linear_range *linear_ranges;
245 int n_linear_ranges;
246
226 const unsigned int *volt_table; 247 const unsigned int *volt_table;
227 248
228 unsigned int vsel_reg; 249 unsigned int vsel_reg;
@@ -326,10 +347,14 @@ int regulator_mode_to_status(unsigned int);
326 347
327int regulator_list_voltage_linear(struct regulator_dev *rdev, 348int regulator_list_voltage_linear(struct regulator_dev *rdev,
328 unsigned int selector); 349 unsigned int selector);
350int regulator_list_voltage_linear_range(struct regulator_dev *rdev,
351 unsigned int selector);
329int regulator_list_voltage_table(struct regulator_dev *rdev, 352int regulator_list_voltage_table(struct regulator_dev *rdev,
330 unsigned int selector); 353 unsigned int selector);
331int regulator_map_voltage_linear(struct regulator_dev *rdev, 354int regulator_map_voltage_linear(struct regulator_dev *rdev,
332 int min_uV, int max_uV); 355 int min_uV, int max_uV);
356int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
357 int min_uV, int max_uV);
333int regulator_map_voltage_iterate(struct regulator_dev *rdev, 358int regulator_map_voltage_iterate(struct regulator_dev *rdev,
334 int min_uV, int max_uV); 359 int min_uV, int max_uV);
335int regulator_map_voltage_ascend(struct regulator_dev *rdev, 360int regulator_map_voltage_ascend(struct regulator_dev *rdev,
diff --git a/include/linux/regulator/fan53555.h b/include/linux/regulator/fan53555.h
index 5c45c85d52ca..f13880e84d85 100644
--- a/include/linux/regulator/fan53555.h
+++ b/include/linux/regulator/fan53555.h
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#ifndef __FAN53555_H__ 13#ifndef __FAN53555_H__
14#define __FAN53555_H__
14 15
15/* VSEL ID */ 16/* VSEL ID */
16enum { 17enum {
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 36adbc82de6a..999b20ce06cf 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -134,6 +134,7 @@ struct regulation_constraints {
134 unsigned always_on:1; /* regulator never off when system is on */ 134 unsigned always_on:1; /* regulator never off when system is on */
135 unsigned boot_on:1; /* bootloader/firmware enabled regulator */ 135 unsigned boot_on:1; /* bootloader/firmware enabled regulator */
136 unsigned apply_uV:1; /* apply uV constraint if min == max */ 136 unsigned apply_uV:1; /* apply uV constraint if min == max */
137 unsigned ramp_disable:1; /* disable ramp delay */
137}; 138};
138 139
139/** 140/**
diff --git a/include/linux/regulator/max8660.h b/include/linux/regulator/max8660.h
index 9936763621c7..f8a6a4844864 100644
--- a/include/linux/regulator/max8660.h
+++ b/include/linux/regulator/max8660.h
@@ -39,7 +39,7 @@ enum {
39 */ 39 */
40struct max8660_subdev_data { 40struct max8660_subdev_data {
41 int id; 41 int id;
42 char *name; 42 const char *name;
43 struct regulator_init_data *platform_data; 43 struct regulator_init_data *platform_data;
44}; 44};
45 45
diff --git a/include/linux/regulator/pfuze100.h b/include/linux/regulator/pfuze100.h
new file mode 100644
index 000000000000..65d550bf3954
--- /dev/null
+++ b/include/linux/regulator/pfuze100.h
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18#ifndef __LINUX_REG_PFUZE100_H
19#define __LINUX_REG_PFUZE100_H
20
21#define PFUZE100_SW1AB 0
22#define PFUZE100_SW1C 1
23#define PFUZE100_SW2 2
24#define PFUZE100_SW3A 3
25#define PFUZE100_SW3B 4
26#define PFUZE100_SW4 5
27#define PFUZE100_SWBST 6
28#define PFUZE100_VSNVS 7
29#define PFUZE100_VREFDDR 8
30#define PFUZE100_VGEN1 9
31#define PFUZE100_VGEN2 10
32#define PFUZE100_VGEN3 11
33#define PFUZE100_VGEN4 12
34#define PFUZE100_VGEN5 13
35#define PFUZE100_VGEN6 14
36#define PFUZE100_MAX_REGULATOR 15
37
38struct regulator_init_data;
39
40struct pfuze_regulator_platform_data {
41 struct regulator_init_data *init_data[PFUZE100_MAX_REGULATOR];
42};
43
44#endif /* __LINUX_REG_PFUZE100_H */