aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/88pm8607.c3
-rw-r--r--drivers/regulator/Kconfig22
-rw-r--r--drivers/regulator/Makefile3
-rw-r--r--drivers/regulator/ab3100.c5
-rw-r--r--drivers/regulator/ab8500.c453
-rw-r--r--drivers/regulator/core.c462
-rw-r--r--drivers/regulator/da903x.c17
-rw-r--r--drivers/regulator/isl6271a-regulator.c8
-rw-r--r--drivers/regulator/lp3971.c10
-rw-r--r--drivers/regulator/lp3972.c10
-rw-r--r--drivers/regulator/max1586.c30
-rw-r--r--drivers/regulator/max8649.c3
-rw-r--r--drivers/regulator/max8660.c14
-rw-r--r--drivers/regulator/max8925-regulator.c3
-rw-r--r--drivers/regulator/max8952.c3
-rw-r--r--drivers/regulator/max8998.c102
-rw-r--r--drivers/regulator/mc13783-regulator.c385
-rw-r--r--drivers/regulator/mc13892-regulator.c635
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c241
-rw-r--r--drivers/regulator/mc13xxx.h101
-rw-r--r--drivers/regulator/pcap-regulator.c7
-rw-r--r--drivers/regulator/pcf50633-regulator.c5
-rw-r--r--drivers/regulator/tps65023-regulator.c9
-rw-r--r--drivers/regulator/tps6507x-regulator.c10
-rw-r--r--drivers/regulator/tps6524x-regulator.c693
-rw-r--r--drivers/regulator/tps6586x-regulator.c15
-rw-r--r--drivers/regulator/twl-regulator.c11
-rw-r--r--drivers/regulator/wm831x-dcdc.c31
-rw-r--r--drivers/regulator/wm831x-ldo.c59
-rw-r--r--drivers/regulator/wm8350-regulator.c24
-rw-r--r--drivers/regulator/wm8400-regulator.c8
-rw-r--r--drivers/regulator/wm8994-regulator.c45
32 files changed, 2708 insertions, 719 deletions
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 2ce2eb71d0f5..dd6308499bd4 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -249,7 +249,7 @@ static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
249} 249}
250 250
251static int pm8607_set_voltage(struct regulator_dev *rdev, 251static int pm8607_set_voltage(struct regulator_dev *rdev,
252 int min_uV, int max_uV) 252 int min_uV, int max_uV, unsigned *selector)
253{ 253{
254 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 254 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
255 uint8_t val, mask; 255 uint8_t val, mask;
@@ -263,6 +263,7 @@ static int pm8607_set_voltage(struct regulator_dev *rdev,
263 ret = choose_voltage(rdev, min_uV, max_uV); 263 ret = choose_voltage(rdev, min_uV, max_uV);
264 if (ret < 0) 264 if (ret < 0)
265 return -EINVAL; 265 return -EINVAL;
266 *selector = ret;
266 val = (uint8_t)(ret << info->vol_shift); 267 val = (uint8_t)(ret << info->vol_shift);
267 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 268 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
268 269
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index dd30e883d4a7..e1d943619ab8 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -186,13 +186,25 @@ config REGULATOR_PCAP
186 This driver provides support for the voltage regulators of the 186 This driver provides support for the voltage regulators of the
187 PCAP2 PMIC. 187 PCAP2 PMIC.
188 188
189config REGULATOR_MC13XXX_CORE
190 tristate
191
189config REGULATOR_MC13783 192config REGULATOR_MC13783
190 tristate "Support regulators on Freescale MC13783 PMIC" 193 tristate "Support regulators on Freescale MC13783 PMIC"
191 depends on MFD_MC13783 194 depends on MFD_MC13783
195 select REGULATOR_MC13XXX_CORE
192 help 196 help
193 Say y here to support the regulators found on the Freescale MC13783 197 Say y here to support the regulators found on the Freescale MC13783
194 PMIC. 198 PMIC.
195 199
200config REGULATOR_MC13892
201 tristate "Support regulators on Freescale MC13892 PMIC"
202 depends on MFD_MC13XXX
203 select REGULATOR_MC13XXX_CORE
204 help
205 Say y here to support the regulators found on the Freescale MC13892
206 PMIC.
207
196config REGULATOR_AB3100 208config REGULATOR_AB3100
197 tristate "ST-Ericsson AB3100 Regulator functions" 209 tristate "ST-Ericsson AB3100 Regulator functions"
198 depends on AB3100_CORE 210 depends on AB3100_CORE
@@ -250,5 +262,15 @@ config REGULATOR_TPS6586X
250 help 262 help
251 This driver supports TPS6586X voltage regulator chips. 263 This driver supports TPS6586X voltage regulator chips.
252 264
265config REGULATOR_TPS6524X
266 tristate "TI TPS6524X Power regulators"
267 depends on SPI
268 help
269 This driver supports TPS6524X voltage regulator chips. TPS6524X
270 provides three step-down converters and two general-purpose LDO
271 voltage regulators. This device is interfaced using a customized
272 serial interface currently supported on the sequencer serial
273 port controller.
274
253endif 275endif
254 276
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index bff815736780..0b5e88c2b8d7 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -30,10 +30,13 @@ obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
30obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 30obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
31obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 31obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
32obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o 32obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
33obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
34obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
33obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 35obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
34 36
35obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 37obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
36obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 38obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
39obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
37obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 40obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
38obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o 41obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
39obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o 42obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index b349266a43de..ed6feaf9398d 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -362,7 +362,8 @@ static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
362} 362}
363 363
364static int ab3100_set_voltage_regulator(struct regulator_dev *reg, 364static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
365 int min_uV, int max_uV) 365 int min_uV, int max_uV,
366 unsigned *selector)
366{ 367{
367 struct ab3100_regulator *abreg = reg->reg_data; 368 struct ab3100_regulator *abreg = reg->reg_data;
368 u8 regval; 369 u8 regval;
@@ -373,6 +374,8 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
373 if (bestindex < 0) 374 if (bestindex < 0)
374 return bestindex; 375 return bestindex;
375 376
377 *selector = bestindex;
378
376 err = abx500_get_register_interruptible(abreg->dev, 0, 379 err = abx500_get_register_interruptible(abreg->dev, 0,
377 abreg->regreg, &regval); 380 abreg->regreg, &regval);
378 if (err) { 381 if (err) {
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index db6b70f20511..d9a052c53aec 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -3,18 +3,13 @@
3 * 3 *
4 * License Terms: GNU General Public License v2 4 * License Terms: GNU General Public License v2
5 * 5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson 6 * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
7 * 8 *
8 * AB8500 peripheral regulators 9 * AB8500 peripheral regulators
9 * 10 *
10 * AB8500 supports the following regulators, 11 * AB8500 supports the following regulators:
11 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VINTCORE12, VTVOUT, 12 * VAUX1/2/3, VINTCORE, VTVOUT, VAUDIO, VAMIC1/2, VDMIC, VANA
12 * VAUX1/2/3, VANA
13 *
14 * for DB8500 cut 1.0 and previous versions of the silicon, all accesses
15 * to registers are through the DB8500 SPI. In cut 1.1 onwards, these
16 * accesses are through the DB8500 PRCMU I2C
17 *
18 */ 13 */
19#include <linux/init.h> 14#include <linux/init.h>
20#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -28,38 +23,37 @@
28 23
29/** 24/**
30 * struct ab8500_regulator_info - ab8500 regulator information 25 * struct ab8500_regulator_info - ab8500 regulator information
26 * @dev: device pointer
31 * @desc: regulator description 27 * @desc: regulator description
32 * @ab8500: ab8500 parent
33 * @regulator_dev: regulator device 28 * @regulator_dev: regulator device
34 * @max_uV: maximum voltage (for variable voltage supplies) 29 * @max_uV: maximum voltage (for variable voltage supplies)
35 * @min_uV: minimum voltage (for variable voltage supplies) 30 * @min_uV: minimum voltage (for variable voltage supplies)
36 * @fixed_uV: typical voltage (for fixed voltage supplies) 31 * @fixed_uV: typical voltage (for fixed voltage supplies)
37 * @update_bank: bank to control on/off 32 * @update_bank: bank to control on/off
38 * @update_reg: register to control on/off 33 * @update_reg: register to control on/off
39 * @mask: mask to enable/disable regulator 34 * @update_mask: mask to enable/disable regulator
40 * @enable: bits to enable the regulator in normal(high power) mode 35 * @update_val_enable: bits to enable the regulator in normal (high power) mode
41 * @voltage_bank: bank to control regulator voltage 36 * @voltage_bank: bank to control regulator voltage
42 * @voltage_reg: register to control regulator voltage 37 * @voltage_reg: register to control regulator voltage
43 * @voltage_mask: mask to control regulator voltage 38 * @voltage_mask: mask to control regulator voltage
44 * @supported_voltages: supported voltage table 39 * @voltages: supported voltage table
45 * @voltages_len: number of supported voltages for the regulator 40 * @voltages_len: number of supported voltages for the regulator
46 */ 41 */
47struct ab8500_regulator_info { 42struct ab8500_regulator_info {
48 struct device *dev; 43 struct device *dev;
49 struct regulator_desc desc; 44 struct regulator_desc desc;
50 struct ab8500 *ab8500;
51 struct regulator_dev *regulator; 45 struct regulator_dev *regulator;
52 int max_uV; 46 int max_uV;
53 int min_uV; 47 int min_uV;
54 int fixed_uV; 48 int fixed_uV;
55 u8 update_bank; 49 u8 update_bank;
56 u8 update_reg; 50 u8 update_reg;
57 u8 mask; 51 u8 update_mask;
58 u8 enable; 52 u8 update_val_enable;
59 u8 voltage_bank; 53 u8 voltage_bank;
60 u8 voltage_reg; 54 u8 voltage_reg;
61 u8 voltage_mask; 55 u8 voltage_mask;
62 int const *supported_voltages; 56 int const *voltages;
63 int voltages_len; 57 int voltages_len;
64}; 58};
65 59
@@ -83,6 +77,17 @@ static const int ldo_vauxn_voltages[] = {
83 3300000, 77 3300000,
84}; 78};
85 79
80static const int ldo_vaux3_voltages[] = {
81 1200000,
82 1500000,
83 1800000,
84 2100000,
85 2500000,
86 2750000,
87 2790000,
88 2910000,
89};
90
86static const int ldo_vintcore_voltages[] = { 91static const int ldo_vintcore_voltages[] = {
87 1200000, 92 1200000,
88 1225000, 93 1225000,
@@ -95,57 +100,80 @@ static const int ldo_vintcore_voltages[] = {
95 100
96static int ab8500_regulator_enable(struct regulator_dev *rdev) 101static int ab8500_regulator_enable(struct regulator_dev *rdev)
97{ 102{
98 int regulator_id, ret; 103 int ret;
99 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 104 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
100 105
101 regulator_id = rdev_get_id(rdev); 106 if (info == NULL) {
102 if (regulator_id >= AB8500_NUM_REGULATORS) 107 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
103 return -EINVAL; 108 return -EINVAL;
109 }
104 110
105 ret = abx500_mask_and_set_register_interruptible(info->dev, 111 ret = abx500_mask_and_set_register_interruptible(info->dev,
106 info->update_bank, info->update_reg, info->mask, info->enable); 112 info->update_bank, info->update_reg,
113 info->update_mask, info->update_val_enable);
107 if (ret < 0) 114 if (ret < 0)
108 dev_err(rdev_get_dev(rdev), 115 dev_err(rdev_get_dev(rdev),
109 "couldn't set enable bits for regulator\n"); 116 "couldn't set enable bits for regulator\n");
117
118 dev_vdbg(rdev_get_dev(rdev),
119 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
120 info->desc.name, info->update_bank, info->update_reg,
121 info->update_mask, info->update_val_enable);
122
110 return ret; 123 return ret;
111} 124}
112 125
113static int ab8500_regulator_disable(struct regulator_dev *rdev) 126static int ab8500_regulator_disable(struct regulator_dev *rdev)
114{ 127{
115 int regulator_id, ret; 128 int ret;
116 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 129 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
117 130
118 regulator_id = rdev_get_id(rdev); 131 if (info == NULL) {
119 if (regulator_id >= AB8500_NUM_REGULATORS) 132 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
120 return -EINVAL; 133 return -EINVAL;
134 }
121 135
122 ret = abx500_mask_and_set_register_interruptible(info->dev, 136 ret = abx500_mask_and_set_register_interruptible(info->dev,
123 info->update_bank, info->update_reg, info->mask, 0x0); 137 info->update_bank, info->update_reg,
138 info->update_mask, 0x0);
124 if (ret < 0) 139 if (ret < 0)
125 dev_err(rdev_get_dev(rdev), 140 dev_err(rdev_get_dev(rdev),
126 "couldn't set disable bits for regulator\n"); 141 "couldn't set disable bits for regulator\n");
142
143 dev_vdbg(rdev_get_dev(rdev),
144 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
145 info->desc.name, info->update_bank, info->update_reg,
146 info->update_mask, 0x0);
147
127 return ret; 148 return ret;
128} 149}
129 150
130static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) 151static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
131{ 152{
132 int regulator_id, ret; 153 int ret;
133 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 154 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
134 u8 value; 155 u8 regval;
135 156
136 regulator_id = rdev_get_id(rdev); 157 if (info == NULL) {
137 if (regulator_id >= AB8500_NUM_REGULATORS) 158 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
138 return -EINVAL; 159 return -EINVAL;
160 }
139 161
140 ret = abx500_get_register_interruptible(info->dev, 162 ret = abx500_get_register_interruptible(info->dev,
141 info->update_bank, info->update_reg, &value); 163 info->update_bank, info->update_reg, &regval);
142 if (ret < 0) { 164 if (ret < 0) {
143 dev_err(rdev_get_dev(rdev), 165 dev_err(rdev_get_dev(rdev),
144 "couldn't read 0x%x register\n", info->update_reg); 166 "couldn't read 0x%x register\n", info->update_reg);
145 return ret; 167 return ret;
146 } 168 }
147 169
148 if (value & info->mask) 170 dev_vdbg(rdev_get_dev(rdev),
171 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
172 " 0x%x\n",
173 info->desc.name, info->update_bank, info->update_reg,
174 info->update_mask, regval);
175
176 if (regval & info->update_mask)
149 return true; 177 return true;
150 else 178 else
151 return false; 179 return false;
@@ -153,12 +181,12 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
153 181
154static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) 182static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
155{ 183{
156 int regulator_id;
157 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 184 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
158 185
159 regulator_id = rdev_get_id(rdev); 186 if (info == NULL) {
160 if (regulator_id >= AB8500_NUM_REGULATORS) 187 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
161 return -EINVAL; 188 return -EINVAL;
189 }
162 190
163 /* return the uV for the fixed regulators */ 191 /* return the uV for the fixed regulators */
164 if (info->fixed_uV) 192 if (info->fixed_uV)
@@ -167,33 +195,40 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
167 if (selector >= info->voltages_len) 195 if (selector >= info->voltages_len)
168 return -EINVAL; 196 return -EINVAL;
169 197
170 return info->supported_voltages[selector]; 198 return info->voltages[selector];
171} 199}
172 200
173static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) 201static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
174{ 202{
175 int regulator_id, ret; 203 int ret, val;
176 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 204 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
177 u8 value; 205 u8 regval;
178 206
179 regulator_id = rdev_get_id(rdev); 207 if (info == NULL) {
180 if (regulator_id >= AB8500_NUM_REGULATORS) 208 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
181 return -EINVAL; 209 return -EINVAL;
210 }
182 211
183 ret = abx500_get_register_interruptible(info->dev, info->voltage_bank, 212 ret = abx500_get_register_interruptible(info->dev,
184 info->voltage_reg, &value); 213 info->voltage_bank, info->voltage_reg, &regval);
185 if (ret < 0) { 214 if (ret < 0) {
186 dev_err(rdev_get_dev(rdev), 215 dev_err(rdev_get_dev(rdev),
187 "couldn't read voltage reg for regulator\n"); 216 "couldn't read voltage reg for regulator\n");
188 return ret; 217 return ret;
189 } 218 }
190 219
220 dev_vdbg(rdev_get_dev(rdev),
221 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
222 " 0x%x\n",
223 info->desc.name, info->voltage_bank, info->voltage_reg,
224 info->voltage_mask, regval);
225
191 /* vintcore has a different layout */ 226 /* vintcore has a different layout */
192 value &= info->voltage_mask; 227 val = regval & info->voltage_mask;
193 if (regulator_id == AB8500_LDO_INTCORE) 228 if (info->desc.id == AB8500_LDO_INTCORE)
194 ret = info->supported_voltages[value >> 0x3]; 229 ret = info->voltages[val >> 0x3];
195 else 230 else
196 ret = info->supported_voltages[value]; 231 ret = info->voltages[val];
197 232
198 return ret; 233 return ret;
199} 234}
@@ -206,8 +241,8 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
206 241
207 /* check the supported voltage */ 242 /* check the supported voltage */
208 for (i = 0; i < info->voltages_len; i++) { 243 for (i = 0; i < info->voltages_len; i++) {
209 if ((info->supported_voltages[i] >= min_uV) && 244 if ((info->voltages[i] >= min_uV) &&
210 (info->supported_voltages[i] <= max_uV)) 245 (info->voltages[i] <= max_uV))
211 return i; 246 return i;
212 } 247 }
213 248
@@ -215,14 +250,17 @@ static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
215} 250}
216 251
217static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, 252static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
218 int min_uV, int max_uV) 253 int min_uV, int max_uV,
254 unsigned *selector)
219{ 255{
220 int regulator_id, ret; 256 int ret;
221 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 257 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
258 u8 regval;
222 259
223 regulator_id = rdev_get_id(rdev); 260 if (info == NULL) {
224 if (regulator_id >= AB8500_NUM_REGULATORS) 261 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
225 return -EINVAL; 262 return -EINVAL;
263 }
226 264
227 /* get the appropriate voltages within the range */ 265 /* get the appropriate voltages within the range */
228 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); 266 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
@@ -232,14 +270,23 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
232 return ret; 270 return ret;
233 } 271 }
234 272
273 *selector = ret;
274
235 /* set the registers for the request */ 275 /* set the registers for the request */
276 regval = (u8)ret;
236 ret = abx500_mask_and_set_register_interruptible(info->dev, 277 ret = abx500_mask_and_set_register_interruptible(info->dev,
237 info->voltage_bank, info->voltage_reg, 278 info->voltage_bank, info->voltage_reg,
238 info->voltage_mask, (u8)ret); 279 info->voltage_mask, regval);
239 if (ret < 0) 280 if (ret < 0)
240 dev_err(rdev_get_dev(rdev), 281 dev_err(rdev_get_dev(rdev),
241 "couldn't set voltage reg for regulator\n"); 282 "couldn't set voltage reg for regulator\n");
242 283
284 dev_vdbg(rdev_get_dev(rdev),
285 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
286 " 0x%x\n",
287 info->desc.name, info->voltage_bank, info->voltage_reg,
288 info->voltage_mask, regval);
289
243 return ret; 290 return ret;
244} 291}
245 292
@@ -254,17 +301,17 @@ static struct regulator_ops ab8500_regulator_ops = {
254 301
255static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) 302static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
256{ 303{
257 int regulator_id;
258 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 304 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
259 305
260 regulator_id = rdev_get_id(rdev); 306 if (info == NULL) {
261 if (regulator_id >= AB8500_NUM_REGULATORS) 307 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
262 return -EINVAL; 308 return -EINVAL;
309 }
263 310
264 return info->fixed_uV; 311 return info->fixed_uV;
265} 312}
266 313
267static struct regulator_ops ab8500_ldo_fixed_ops = { 314static struct regulator_ops ab8500_regulator_fixed_ops = {
268 .enable = ab8500_regulator_enable, 315 .enable = ab8500_regulator_enable,
269 .disable = ab8500_regulator_disable, 316 .disable = ab8500_regulator_disable,
270 .is_enabled = ab8500_regulator_is_enabled, 317 .is_enabled = ab8500_regulator_is_enabled,
@@ -272,88 +319,197 @@ static struct regulator_ops ab8500_ldo_fixed_ops = {
272 .list_voltage = ab8500_list_voltage, 319 .list_voltage = ab8500_list_voltage,
273}; 320};
274 321
275#define AB8500_LDO(_id, min, max, bank, reg, reg_mask, \ 322static struct ab8500_regulator_info
276 reg_enable, volt_bank, volt_reg, volt_mask, \ 323 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
277 voltages, len_volts) \
278{ \
279 .desc = { \
280 .name = "LDO-" #_id, \
281 .ops = &ab8500_regulator_ops, \
282 .type = REGULATOR_VOLTAGE, \
283 .id = AB8500_LDO_##_id, \
284 .owner = THIS_MODULE, \
285 }, \
286 .min_uV = (min) * 1000, \
287 .max_uV = (max) * 1000, \
288 .update_bank = bank, \
289 .update_reg = reg, \
290 .mask = reg_mask, \
291 .enable = reg_enable, \
292 .voltage_bank = volt_bank, \
293 .voltage_reg = volt_reg, \
294 .voltage_mask = volt_mask, \
295 .supported_voltages = voltages, \
296 .voltages_len = len_volts, \
297 .fixed_uV = 0, \
298}
299
300#define AB8500_FIXED_LDO(_id, fixed, bank, reg, \
301 reg_mask, reg_enable) \
302{ \
303 .desc = { \
304 .name = "LDO-" #_id, \
305 .ops = &ab8500_ldo_fixed_ops, \
306 .type = REGULATOR_VOLTAGE, \
307 .id = AB8500_LDO_##_id, \
308 .owner = THIS_MODULE, \
309 }, \
310 .fixed_uV = fixed * 1000, \
311 .update_bank = bank, \
312 .update_reg = reg, \
313 .mask = reg_mask, \
314 .enable = reg_enable, \
315}
316
317static struct ab8500_regulator_info ab8500_regulator_info[] = {
318 /* 324 /*
319 * Variable Voltage LDOs 325 * Variable Voltage Regulators
320 * name, min uV, max uV, ctrl bank, ctrl reg, reg mask, enable mask, 326 * name, min mV, max mV,
321 * volt ctrl bank, volt ctrl reg, volt ctrl mask, volt table, 327 * update bank, reg, mask, enable val
322 * num supported volts 328 * volt bank, reg, mask, table, table length
323 */ 329 */
324 AB8500_LDO(AUX1, 1100, 3300, 0x04, 0x09, 0x3, 0x1, 0x04, 0x1f, 0xf, 330 [AB8500_LDO_AUX1] = {
325 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 331 .desc = {
326 AB8500_LDO(AUX2, 1100, 3300, 0x04, 0x09, 0xc, 0x4, 0x04, 0x20, 0xf, 332 .name = "LDO-AUX1",
327 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 333 .ops = &ab8500_regulator_ops,
328 AB8500_LDO(AUX3, 1100, 3300, 0x04, 0x0a, 0x3, 0x1, 0x04, 0x21, 0xf, 334 .type = REGULATOR_VOLTAGE,
329 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)), 335 .id = AB8500_LDO_AUX1,
330 AB8500_LDO(INTCORE, 1100, 3300, 0x03, 0x80, 0x4, 0x4, 0x03, 0x80, 0x38, 336 .owner = THIS_MODULE,
331 ldo_vintcore_voltages, ARRAY_SIZE(ldo_vintcore_voltages)), 337 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
338 },
339 .min_uV = 1100000,
340 .max_uV = 3300000,
341 .update_bank = 0x04,
342 .update_reg = 0x09,
343 .update_mask = 0x03,
344 .update_val_enable = 0x01,
345 .voltage_bank = 0x04,
346 .voltage_reg = 0x1f,
347 .voltage_mask = 0x0f,
348 .voltages = ldo_vauxn_voltages,
349 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
350 },
351 [AB8500_LDO_AUX2] = {
352 .desc = {
353 .name = "LDO-AUX2",
354 .ops = &ab8500_regulator_ops,
355 .type = REGULATOR_VOLTAGE,
356 .id = AB8500_LDO_AUX2,
357 .owner = THIS_MODULE,
358 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
359 },
360 .min_uV = 1100000,
361 .max_uV = 3300000,
362 .update_bank = 0x04,
363 .update_reg = 0x09,
364 .update_mask = 0x0c,
365 .update_val_enable = 0x04,
366 .voltage_bank = 0x04,
367 .voltage_reg = 0x20,
368 .voltage_mask = 0x0f,
369 .voltages = ldo_vauxn_voltages,
370 .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages),
371 },
372 [AB8500_LDO_AUX3] = {
373 .desc = {
374 .name = "LDO-AUX3",
375 .ops = &ab8500_regulator_ops,
376 .type = REGULATOR_VOLTAGE,
377 .id = AB8500_LDO_AUX3,
378 .owner = THIS_MODULE,
379 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
380 },
381 .min_uV = 1100000,
382 .max_uV = 3300000,
383 .update_bank = 0x04,
384 .update_reg = 0x0a,
385 .update_mask = 0x03,
386 .update_val_enable = 0x01,
387 .voltage_bank = 0x04,
388 .voltage_reg = 0x21,
389 .voltage_mask = 0x07,
390 .voltages = ldo_vaux3_voltages,
391 .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages),
392 },
393 [AB8500_LDO_INTCORE] = {
394 .desc = {
395 .name = "LDO-INTCORE",
396 .ops = &ab8500_regulator_ops,
397 .type = REGULATOR_VOLTAGE,
398 .id = AB8500_LDO_INTCORE,
399 .owner = THIS_MODULE,
400 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
401 },
402 .min_uV = 1100000,
403 .max_uV = 3300000,
404 .update_bank = 0x03,
405 .update_reg = 0x80,
406 .update_mask = 0x44,
407 .update_val_enable = 0x04,
408 .voltage_bank = 0x03,
409 .voltage_reg = 0x80,
410 .voltage_mask = 0x38,
411 .voltages = ldo_vintcore_voltages,
412 .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages),
413 },
332 414
333 /* 415 /*
334 * Fixed Voltage LDOs 416 * Fixed Voltage Regulators
335 * name, o/p uV, ctrl bank, ctrl reg, enable, disable 417 * name, fixed mV,
418 * update bank, reg, mask, enable val
336 */ 419 */
337 AB8500_FIXED_LDO(TVOUT, 2000, 0x03, 0x80, 0x2, 0x2), 420 [AB8500_LDO_TVOUT] = {
338 AB8500_FIXED_LDO(AUDIO, 2000, 0x03, 0x83, 0x2, 0x2), 421 .desc = {
339 AB8500_FIXED_LDO(ANAMIC1, 2050, 0x03, 0x83, 0x4, 0x4), 422 .name = "LDO-TVOUT",
340 AB8500_FIXED_LDO(ANAMIC2, 2050, 0x03, 0x83, 0x8, 0x8), 423 .ops = &ab8500_regulator_fixed_ops,
341 AB8500_FIXED_LDO(DMIC, 1800, 0x03, 0x83, 0x10, 0x10), 424 .type = REGULATOR_VOLTAGE,
342 AB8500_FIXED_LDO(ANA, 1200, 0x03, 0x83, 0xc, 0x4), 425 .id = AB8500_LDO_TVOUT,
343}; 426 .owner = THIS_MODULE,
427 .n_voltages = 1,
428 },
429 .fixed_uV = 2000000,
430 .update_bank = 0x03,
431 .update_reg = 0x80,
432 .update_mask = 0x82,
433 .update_val_enable = 0x02,
434 },
435 [AB8500_LDO_AUDIO] = {
436 .desc = {
437 .name = "LDO-AUDIO",
438 .ops = &ab8500_regulator_fixed_ops,
439 .type = REGULATOR_VOLTAGE,
440 .id = AB8500_LDO_AUDIO,
441 .owner = THIS_MODULE,
442 .n_voltages = 1,
443 },
444 .fixed_uV = 2000000,
445 .update_bank = 0x03,
446 .update_reg = 0x83,
447 .update_mask = 0x02,
448 .update_val_enable = 0x02,
449 },
450 [AB8500_LDO_ANAMIC1] = {
451 .desc = {
452 .name = "LDO-ANAMIC1",
453 .ops = &ab8500_regulator_fixed_ops,
454 .type = REGULATOR_VOLTAGE,
455 .id = AB8500_LDO_ANAMIC1,
456 .owner = THIS_MODULE,
457 .n_voltages = 1,
458 },
459 .fixed_uV = 2050000,
460 .update_bank = 0x03,
461 .update_reg = 0x83,
462 .update_mask = 0x08,
463 .update_val_enable = 0x08,
464 },
465 [AB8500_LDO_ANAMIC2] = {
466 .desc = {
467 .name = "LDO-ANAMIC2",
468 .ops = &ab8500_regulator_fixed_ops,
469 .type = REGULATOR_VOLTAGE,
470 .id = AB8500_LDO_ANAMIC2,
471 .owner = THIS_MODULE,
472 .n_voltages = 1,
473 },
474 .fixed_uV = 2050000,
475 .update_bank = 0x03,
476 .update_reg = 0x83,
477 .update_mask = 0x10,
478 .update_val_enable = 0x10,
479 },
480 [AB8500_LDO_DMIC] = {
481 .desc = {
482 .name = "LDO-DMIC",
483 .ops = &ab8500_regulator_fixed_ops,
484 .type = REGULATOR_VOLTAGE,
485 .id = AB8500_LDO_DMIC,
486 .owner = THIS_MODULE,
487 .n_voltages = 1,
488 },
489 .fixed_uV = 1800000,
490 .update_bank = 0x03,
491 .update_reg = 0x83,
492 .update_mask = 0x04,
493 .update_val_enable = 0x04,
494 },
495 [AB8500_LDO_ANA] = {
496 .desc = {
497 .name = "LDO-ANA",
498 .ops = &ab8500_regulator_fixed_ops,
499 .type = REGULATOR_VOLTAGE,
500 .id = AB8500_LDO_ANA,
501 .owner = THIS_MODULE,
502 .n_voltages = 1,
503 },
504 .fixed_uV = 1200000,
505 .update_bank = 0x04,
506 .update_reg = 0x06,
507 .update_mask = 0x0c,
508 .update_val_enable = 0x04,
509 },
344 510
345static inline struct ab8500_regulator_info *find_regulator_info(int id)
346{
347 struct ab8500_regulator_info *info;
348 int i;
349 511
350 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 512};
351 info = &ab8500_regulator_info[i];
352 if (info->desc.id == id)
353 return info;
354 }
355 return NULL;
356}
357 513
358static __devinit int ab8500_regulator_probe(struct platform_device *pdev) 514static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
359{ 515{
@@ -366,6 +522,16 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
366 return -EINVAL; 522 return -EINVAL;
367 } 523 }
368 pdata = dev_get_platdata(ab8500->dev); 524 pdata = dev_get_platdata(ab8500->dev);
525 if (!pdata) {
526 dev_err(&pdev->dev, "null pdata\n");
527 return -EINVAL;
528 }
529
530 /* make sure the platform data has the correct size */
531 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
532 dev_err(&pdev->dev, "platform configuration error\n");
533 return -EINVAL;
534 }
369 535
370 /* register all regulators */ 536 /* register all regulators */
371 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 537 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
@@ -374,10 +540,22 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
374 /* assign per-regulator data */ 540 /* assign per-regulator data */
375 info = &ab8500_regulator_info[i]; 541 info = &ab8500_regulator_info[i];
376 info->dev = &pdev->dev; 542 info->dev = &pdev->dev;
377 info->ab8500 = ab8500;
378 543
544 /* fix for hardware before ab8500v2.0 */
545 if (abx500_get_chip_id(info->dev) < 0x20) {
546 if (info->desc.id == AB8500_LDO_AUX3) {
547 info->desc.n_voltages =
548 ARRAY_SIZE(ldo_vauxn_voltages);
549 info->voltages = ldo_vauxn_voltages;
550 info->voltages_len =
551 ARRAY_SIZE(ldo_vauxn_voltages);
552 info->voltage_mask = 0xf;
553 }
554 }
555
556 /* register regulator with framework */
379 info->regulator = regulator_register(&info->desc, &pdev->dev, 557 info->regulator = regulator_register(&info->desc, &pdev->dev,
380 pdata->regulator[i], info); 558 &pdata->regulator[i], info);
381 if (IS_ERR(info->regulator)) { 559 if (IS_ERR(info->regulator)) {
382 err = PTR_ERR(info->regulator); 560 err = PTR_ERR(info->regulator);
383 dev_err(&pdev->dev, "failed to register regulator %s\n", 561 dev_err(&pdev->dev, "failed to register regulator %s\n",
@@ -389,6 +567,9 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
389 } 567 }
390 return err; 568 return err;
391 } 569 }
570
571 dev_vdbg(rdev_get_dev(info->regulator),
572 "%s-probed\n", info->desc.name);
392 } 573 }
393 574
394 return 0; 575 return 0;
@@ -401,6 +582,10 @@ static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
401 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 582 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
402 struct ab8500_regulator_info *info = NULL; 583 struct ab8500_regulator_info *info = NULL;
403 info = &ab8500_regulator_info[i]; 584 info = &ab8500_regulator_info[i];
585
586 dev_vdbg(rdev_get_dev(info->regulator),
587 "%s-remove\n", info->desc.name);
588
404 regulator_unregister(info->regulator); 589 regulator_unregister(info->regulator);
405 } 590 }
406 591
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ba521f0f0fac..9fa20957847d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -13,8 +13,11 @@
13 * 13 *
14 */ 14 */
15 15
16#define pr_fmt(fmt) "%s: " fmt, __func__
17
16#include <linux/kernel.h> 18#include <linux/kernel.h>
17#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/debugfs.h>
18#include <linux/device.h> 21#include <linux/device.h>
19#include <linux/slab.h> 22#include <linux/slab.h>
20#include <linux/err.h> 23#include <linux/err.h>
@@ -25,16 +28,30 @@
25#include <linux/regulator/driver.h> 28#include <linux/regulator/driver.h>
26#include <linux/regulator/machine.h> 29#include <linux/regulator/machine.h>
27 30
31#define CREATE_TRACE_POINTS
32#include <trace/events/regulator.h>
33
28#include "dummy.h" 34#include "dummy.h"
29 35
30#define REGULATOR_VERSION "0.5" 36#define rdev_err(rdev, fmt, ...) \
37 pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
38#define rdev_warn(rdev, fmt, ...) \
39 pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
40#define rdev_info(rdev, fmt, ...) \
41 pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
42#define rdev_dbg(rdev, fmt, ...) \
43 pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
31 44
32static DEFINE_MUTEX(regulator_list_mutex); 45static DEFINE_MUTEX(regulator_list_mutex);
33static LIST_HEAD(regulator_list); 46static LIST_HEAD(regulator_list);
34static LIST_HEAD(regulator_map_list); 47static LIST_HEAD(regulator_map_list);
35static int has_full_constraints; 48static bool has_full_constraints;
36static bool board_wants_dummy_regulator; 49static bool board_wants_dummy_regulator;
37 50
51#ifdef CONFIG_DEBUG_FS
52static struct dentry *debugfs_root;
53#endif
54
38/* 55/*
39 * struct regulator_map 56 * struct regulator_map
40 * 57 *
@@ -71,6 +88,8 @@ static int _regulator_get_current_limit(struct regulator_dev *rdev);
71static unsigned int _regulator_get_mode(struct regulator_dev *rdev); 88static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
72static void _notifier_call_chain(struct regulator_dev *rdev, 89static void _notifier_call_chain(struct regulator_dev *rdev,
73 unsigned long event, void *data); 90 unsigned long event, void *data);
91static int _regulator_do_set_voltage(struct regulator_dev *rdev,
92 int min_uV, int max_uV);
74 93
75static const char *rdev_get_name(struct regulator_dev *rdev) 94static const char *rdev_get_name(struct regulator_dev *rdev)
76{ 95{
@@ -111,13 +130,11 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
111 BUG_ON(*min_uV > *max_uV); 130 BUG_ON(*min_uV > *max_uV);
112 131
113 if (!rdev->constraints) { 132 if (!rdev->constraints) {
114 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 133 rdev_err(rdev, "no constraints\n");
115 rdev_get_name(rdev));
116 return -ENODEV; 134 return -ENODEV;
117 } 135 }
118 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 136 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
119 printk(KERN_ERR "%s: operation not allowed for %s\n", 137 rdev_err(rdev, "operation not allowed\n");
120 __func__, rdev_get_name(rdev));
121 return -EPERM; 138 return -EPERM;
122 } 139 }
123 140
@@ -132,6 +149,27 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
132 return 0; 149 return 0;
133} 150}
134 151
152/* Make sure we select a voltage that suits the needs of all
153 * regulator consumers
154 */
155static int regulator_check_consumers(struct regulator_dev *rdev,
156 int *min_uV, int *max_uV)
157{
158 struct regulator *regulator;
159
160 list_for_each_entry(regulator, &rdev->consumer_list, list) {
161 if (*max_uV > regulator->max_uV)
162 *max_uV = regulator->max_uV;
163 if (*min_uV < regulator->min_uV)
164 *min_uV = regulator->min_uV;
165 }
166
167 if (*min_uV > *max_uV)
168 return -EINVAL;
169
170 return 0;
171}
172
135/* current constraint check */ 173/* current constraint check */
136static int regulator_check_current_limit(struct regulator_dev *rdev, 174static int regulator_check_current_limit(struct regulator_dev *rdev,
137 int *min_uA, int *max_uA) 175 int *min_uA, int *max_uA)
@@ -139,13 +177,11 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
139 BUG_ON(*min_uA > *max_uA); 177 BUG_ON(*min_uA > *max_uA);
140 178
141 if (!rdev->constraints) { 179 if (!rdev->constraints) {
142 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 180 rdev_err(rdev, "no constraints\n");
143 rdev_get_name(rdev));
144 return -ENODEV; 181 return -ENODEV;
145 } 182 }
146 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 183 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
147 printk(KERN_ERR "%s: operation not allowed for %s\n", 184 rdev_err(rdev, "operation not allowed\n");
148 __func__, rdev_get_name(rdev));
149 return -EPERM; 185 return -EPERM;
150 } 186 }
151 187
@@ -174,18 +210,15 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
174 } 210 }
175 211
176 if (!rdev->constraints) { 212 if (!rdev->constraints) {
177 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 213 rdev_err(rdev, "no constraints\n");
178 rdev_get_name(rdev));
179 return -ENODEV; 214 return -ENODEV;
180 } 215 }
181 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 216 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
182 printk(KERN_ERR "%s: operation not allowed for %s\n", 217 rdev_err(rdev, "operation not allowed\n");
183 __func__, rdev_get_name(rdev));
184 return -EPERM; 218 return -EPERM;
185 } 219 }
186 if (!(rdev->constraints->valid_modes_mask & mode)) { 220 if (!(rdev->constraints->valid_modes_mask & mode)) {
187 printk(KERN_ERR "%s: invalid mode %x for %s\n", 221 rdev_err(rdev, "invalid mode %x\n", mode);
188 __func__, mode, rdev_get_name(rdev));
189 return -EINVAL; 222 return -EINVAL;
190 } 223 }
191 return 0; 224 return 0;
@@ -195,13 +228,11 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
195static int regulator_check_drms(struct regulator_dev *rdev) 228static int regulator_check_drms(struct regulator_dev *rdev)
196{ 229{
197 if (!rdev->constraints) { 230 if (!rdev->constraints) {
198 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 231 rdev_err(rdev, "no constraints\n");
199 rdev_get_name(rdev));
200 return -ENODEV; 232 return -ENODEV;
201 } 233 }
202 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 234 if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
203 printk(KERN_ERR "%s: operation not allowed for %s\n", 235 rdev_err(rdev, "operation not allowed\n");
204 __func__, rdev_get_name(rdev));
205 return -EPERM; 236 return -EPERM;
206 } 237 }
207 return 0; 238 return 0;
@@ -553,18 +584,21 @@ static void drms_uA_update(struct regulator_dev *rdev)
553 584
554 err = regulator_check_drms(rdev); 585 err = regulator_check_drms(rdev);
555 if (err < 0 || !rdev->desc->ops->get_optimum_mode || 586 if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
556 !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode) 587 (!rdev->desc->ops->get_voltage &&
588 !rdev->desc->ops->get_voltage_sel) ||
589 !rdev->desc->ops->set_mode)
557 return; 590 return;
558 591
559 /* get output voltage */ 592 /* get output voltage */
560 output_uV = rdev->desc->ops->get_voltage(rdev); 593 output_uV = _regulator_get_voltage(rdev);
561 if (output_uV <= 0) 594 if (output_uV <= 0)
562 return; 595 return;
563 596
564 /* get input voltage */ 597 /* get input voltage */
565 if (rdev->supply && rdev->supply->desc->ops->get_voltage) 598 input_uV = 0;
566 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 599 if (rdev->supply)
567 else 600 input_uV = _regulator_get_voltage(rdev);
601 if (input_uV <= 0)
568 input_uV = rdev->constraints->input_uV; 602 input_uV = rdev->constraints->input_uV;
569 if (input_uV <= 0) 603 if (input_uV <= 0)
570 return; 604 return;
@@ -598,20 +632,17 @@ static int suspend_set_state(struct regulator_dev *rdev,
598 */ 632 */
599 if (!rstate->enabled && !rstate->disabled) { 633 if (!rstate->enabled && !rstate->disabled) {
600 if (can_set_state) 634 if (can_set_state)
601 printk(KERN_WARNING "%s: No configuration for %s\n", 635 rdev_warn(rdev, "No configuration\n");
602 __func__, rdev_get_name(rdev));
603 return 0; 636 return 0;
604 } 637 }
605 638
606 if (rstate->enabled && rstate->disabled) { 639 if (rstate->enabled && rstate->disabled) {
607 printk(KERN_ERR "%s: invalid configuration for %s\n", 640 rdev_err(rdev, "invalid configuration\n");
608 __func__, rdev_get_name(rdev));
609 return -EINVAL; 641 return -EINVAL;
610 } 642 }
611 643
612 if (!can_set_state) { 644 if (!can_set_state) {
613 printk(KERN_ERR "%s: no way to set suspend state\n", 645 rdev_err(rdev, "no way to set suspend state\n");
614 __func__);
615 return -EINVAL; 646 return -EINVAL;
616 } 647 }
617 648
@@ -620,15 +651,14 @@ static int suspend_set_state(struct regulator_dev *rdev,
620 else 651 else
621 ret = rdev->desc->ops->set_suspend_disable(rdev); 652 ret = rdev->desc->ops->set_suspend_disable(rdev);
622 if (ret < 0) { 653 if (ret < 0) {
623 printk(KERN_ERR "%s: failed to enabled/disable\n", __func__); 654 rdev_err(rdev, "failed to enabled/disable\n");
624 return ret; 655 return ret;
625 } 656 }
626 657
627 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { 658 if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
628 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); 659 ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
629 if (ret < 0) { 660 if (ret < 0) {
630 printk(KERN_ERR "%s: failed to set voltage\n", 661 rdev_err(rdev, "failed to set voltage\n");
631 __func__);
632 return ret; 662 return ret;
633 } 663 }
634 } 664 }
@@ -636,7 +666,7 @@ static int suspend_set_state(struct regulator_dev *rdev,
636 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { 666 if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
637 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); 667 ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
638 if (ret < 0) { 668 if (ret < 0) {
639 printk(KERN_ERR "%s: failed to set mode\n", __func__); 669 rdev_err(rdev, "failed to set mode\n");
640 return ret; 670 return ret;
641 } 671 }
642 } 672 }
@@ -714,29 +744,27 @@ static void print_constraints(struct regulator_dev *rdev)
714 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 744 if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
715 count += sprintf(buf + count, "standby"); 745 count += sprintf(buf + count, "standby");
716 746
717 printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); 747 rdev_info(rdev, "%s\n", buf);
718} 748}
719 749
720static int machine_constraints_voltage(struct regulator_dev *rdev, 750static int machine_constraints_voltage(struct regulator_dev *rdev,
721 struct regulation_constraints *constraints) 751 struct regulation_constraints *constraints)
722{ 752{
723 struct regulator_ops *ops = rdev->desc->ops; 753 struct regulator_ops *ops = rdev->desc->ops;
724 const char *name = rdev_get_name(rdev);
725 int ret; 754 int ret;
726 755
727 /* do we need to apply the constraint voltage */ 756 /* do we need to apply the constraint voltage */
728 if (rdev->constraints->apply_uV && 757 if (rdev->constraints->apply_uV &&
729 rdev->constraints->min_uV == rdev->constraints->max_uV && 758 rdev->constraints->min_uV == rdev->constraints->max_uV) {
730 ops->set_voltage) { 759 ret = _regulator_do_set_voltage(rdev,
731 ret = ops->set_voltage(rdev, 760 rdev->constraints->min_uV,
732 rdev->constraints->min_uV, rdev->constraints->max_uV); 761 rdev->constraints->max_uV);
733 if (ret < 0) { 762 if (ret < 0) {
734 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 763 rdev_err(rdev, "failed to apply %duV constraint\n",
735 __func__, 764 rdev->constraints->min_uV);
736 rdev->constraints->min_uV, name); 765 rdev->constraints = NULL;
737 rdev->constraints = NULL; 766 return ret;
738 return ret; 767 }
739 }
740 } 768 }
741 769
742 /* constrain machine-level voltage specs to fit 770 /* constrain machine-level voltage specs to fit
@@ -765,8 +793,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
765 793
766 /* else require explicit machine-level constraints */ 794 /* else require explicit machine-level constraints */
767 if (cmin <= 0 || cmax <= 0 || cmax < cmin) { 795 if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
768 pr_err("%s: %s '%s' voltage constraints\n", 796 rdev_err(rdev, "invalid voltage constraints\n");
769 __func__, "invalid", name);
770 return -EINVAL; 797 return -EINVAL;
771 } 798 }
772 799
@@ -787,22 +814,19 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
787 814
788 /* final: [min_uV..max_uV] valid iff constraints valid */ 815 /* final: [min_uV..max_uV] valid iff constraints valid */
789 if (max_uV < min_uV) { 816 if (max_uV < min_uV) {
790 pr_err("%s: %s '%s' voltage constraints\n", 817 rdev_err(rdev, "unsupportable voltage constraints\n");
791 __func__, "unsupportable", name);
792 return -EINVAL; 818 return -EINVAL;
793 } 819 }
794 820
795 /* use regulator's subset of machine constraints */ 821 /* use regulator's subset of machine constraints */
796 if (constraints->min_uV < min_uV) { 822 if (constraints->min_uV < min_uV) {
797 pr_debug("%s: override '%s' %s, %d -> %d\n", 823 rdev_dbg(rdev, "override min_uV, %d -> %d\n",
798 __func__, name, "min_uV", 824 constraints->min_uV, min_uV);
799 constraints->min_uV, min_uV);
800 constraints->min_uV = min_uV; 825 constraints->min_uV = min_uV;
801 } 826 }
802 if (constraints->max_uV > max_uV) { 827 if (constraints->max_uV > max_uV) {
803 pr_debug("%s: override '%s' %s, %d -> %d\n", 828 rdev_dbg(rdev, "override max_uV, %d -> %d\n",
804 __func__, name, "max_uV", 829 constraints->max_uV, max_uV);
805 constraints->max_uV, max_uV);
806 constraints->max_uV = max_uV; 830 constraints->max_uV = max_uV;
807 } 831 }
808 } 832 }
@@ -822,26 +846,25 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
822 * set_mode. 846 * set_mode.
823 */ 847 */
824static int set_machine_constraints(struct regulator_dev *rdev, 848static int set_machine_constraints(struct regulator_dev *rdev,
825 struct regulation_constraints *constraints) 849 const struct regulation_constraints *constraints)
826{ 850{
827 int ret = 0; 851 int ret = 0;
828 const char *name;
829 struct regulator_ops *ops = rdev->desc->ops; 852 struct regulator_ops *ops = rdev->desc->ops;
830 853
831 rdev->constraints = constraints; 854 rdev->constraints = kmemdup(constraints, sizeof(*constraints),
832 855 GFP_KERNEL);
833 name = rdev_get_name(rdev); 856 if (!rdev->constraints)
857 return -ENOMEM;
834 858
835 ret = machine_constraints_voltage(rdev, constraints); 859 ret = machine_constraints_voltage(rdev, rdev->constraints);
836 if (ret != 0) 860 if (ret != 0)
837 goto out; 861 goto out;
838 862
839 /* do we need to setup our suspend state */ 863 /* do we need to setup our suspend state */
840 if (constraints->initial_state) { 864 if (constraints->initial_state) {
841 ret = suspend_prepare(rdev, constraints->initial_state); 865 ret = suspend_prepare(rdev, rdev->constraints->initial_state);
842 if (ret < 0) { 866 if (ret < 0) {
843 printk(KERN_ERR "%s: failed to set suspend state for %s\n", 867 rdev_err(rdev, "failed to set suspend state\n");
844 __func__, name);
845 rdev->constraints = NULL; 868 rdev->constraints = NULL;
846 goto out; 869 goto out;
847 } 870 }
@@ -849,17 +872,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
849 872
850 if (constraints->initial_mode) { 873 if (constraints->initial_mode) {
851 if (!ops->set_mode) { 874 if (!ops->set_mode) {
852 printk(KERN_ERR "%s: no set_mode operation for %s\n", 875 rdev_err(rdev, "no set_mode operation\n");
853 __func__, name);
854 ret = -EINVAL; 876 ret = -EINVAL;
855 goto out; 877 goto out;
856 } 878 }
857 879
858 ret = ops->set_mode(rdev, constraints->initial_mode); 880 ret = ops->set_mode(rdev, rdev->constraints->initial_mode);
859 if (ret < 0) { 881 if (ret < 0) {
860 printk(KERN_ERR 882 rdev_err(rdev, "failed to set initial mode: %d\n", ret);
861 "%s: failed to set initial mode for %s: %d\n",
862 __func__, name, ret);
863 goto out; 883 goto out;
864 } 884 }
865 } 885 }
@@ -867,11 +887,11 @@ static int set_machine_constraints(struct regulator_dev *rdev,
867 /* If the constraints say the regulator should be on at this point 887 /* If the constraints say the regulator should be on at this point
868 * and we have control then make sure it is enabled. 888 * and we have control then make sure it is enabled.
869 */ 889 */
870 if ((constraints->always_on || constraints->boot_on) && ops->enable) { 890 if ((rdev->constraints->always_on || rdev->constraints->boot_on) &&
891 ops->enable) {
871 ret = ops->enable(rdev); 892 ret = ops->enable(rdev);
872 if (ret < 0) { 893 if (ret < 0) {
873 printk(KERN_ERR "%s: failed to enable %s\n", 894 rdev_err(rdev, "failed to enable\n");
874 __func__, name);
875 rdev->constraints = NULL; 895 rdev->constraints = NULL;
876 goto out; 896 goto out;
877 } 897 }
@@ -899,9 +919,8 @@ static int set_supply(struct regulator_dev *rdev,
899 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, 919 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
900 "supply"); 920 "supply");
901 if (err) { 921 if (err) {
902 printk(KERN_ERR 922 rdev_err(rdev, "could not add device link %s err %d\n",
903 "%s: could not add device link %s err %d\n", 923 supply_rdev->dev.kobj.name, err);
904 __func__, supply_rdev->dev.kobj.name, err);
905 goto out; 924 goto out;
906 } 925 }
907 rdev->supply = supply_rdev; 926 rdev->supply = supply_rdev;
@@ -957,10 +976,10 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
957 continue; 976 continue;
958 977
959 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", 978 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
960 dev_name(&node->regulator->dev), 979 dev_name(&node->regulator->dev),
961 node->regulator->desc->name, 980 node->regulator->desc->name,
962 supply, 981 supply,
963 dev_name(&rdev->dev), rdev_get_name(rdev)); 982 dev_name(&rdev->dev), rdev_get_name(rdev));
964 return -EBUSY; 983 return -EBUSY;
965 } 984 }
966 985
@@ -1031,8 +1050,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1031 regulator->dev_attr.show = device_requested_uA_show; 1050 regulator->dev_attr.show = device_requested_uA_show;
1032 err = device_create_file(dev, &regulator->dev_attr); 1051 err = device_create_file(dev, &regulator->dev_attr);
1033 if (err < 0) { 1052 if (err < 0) {
1034 printk(KERN_WARNING "%s: could not add regulator_dev" 1053 rdev_warn(rdev, "could not add regulator_dev requested microamps sysfs entry\n");
1035 " load sysfs\n", __func__);
1036 goto attr_name_err; 1054 goto attr_name_err;
1037 } 1055 }
1038 1056
@@ -1049,9 +1067,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
1049 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, 1067 err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
1050 buf); 1068 buf);
1051 if (err) { 1069 if (err) {
1052 printk(KERN_WARNING 1070 rdev_warn(rdev, "could not add device link %s err %d\n",
1053 "%s: could not add device link %s err %d\n", 1071 dev->kobj.name, err);
1054 __func__, dev->kobj.name, err);
1055 goto link_name_err; 1072 goto link_name_err;
1056 } 1073 }
1057 } 1074 }
@@ -1088,7 +1105,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1088 int ret; 1105 int ret;
1089 1106
1090 if (id == NULL) { 1107 if (id == NULL) {
1091 printk(KERN_ERR "regulator: get() with no identifier\n"); 1108 pr_err("get() with no identifier\n");
1092 return regulator; 1109 return regulator;
1093 } 1110 }
1094 1111
@@ -1122,8 +1139,8 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
1122 * substitute in a dummy regulator so consumers can continue. 1139 * substitute in a dummy regulator so consumers can continue.
1123 */ 1140 */
1124 if (!has_full_constraints) { 1141 if (!has_full_constraints) {
1125 pr_warning("%s supply %s not found, using dummy regulator\n", 1142 pr_warn("%s supply %s not found, using dummy regulator\n",
1126 devname, id); 1143 devname, id);
1127 rdev = dummy_regulator_rdev; 1144 rdev = dummy_regulator_rdev;
1128 goto found; 1145 goto found;
1129 } 1146 }
@@ -1274,8 +1291,7 @@ static int _regulator_enable(struct regulator_dev *rdev)
1274 ret = _regulator_enable(rdev->supply); 1291 ret = _regulator_enable(rdev->supply);
1275 mutex_unlock(&rdev->supply->mutex); 1292 mutex_unlock(&rdev->supply->mutex);
1276 if (ret < 0) { 1293 if (ret < 0) {
1277 printk(KERN_ERR "%s: failed to enable %s: %d\n", 1294 rdev_err(rdev, "failed to enable: %d\n", ret);
1278 __func__, rdev_get_name(rdev), ret);
1279 return ret; 1295 return ret;
1280 } 1296 }
1281 } 1297 }
@@ -1302,13 +1318,13 @@ static int _regulator_enable(struct regulator_dev *rdev)
1302 if (ret >= 0) { 1318 if (ret >= 0) {
1303 delay = ret; 1319 delay = ret;
1304 } else { 1320 } else {
1305 printk(KERN_WARNING 1321 rdev_warn(rdev, "enable_time() failed: %d\n",
1306 "%s: enable_time() failed for %s: %d\n", 1322 ret);
1307 __func__, rdev_get_name(rdev),
1308 ret);
1309 delay = 0; 1323 delay = 0;
1310 } 1324 }
1311 1325
1326 trace_regulator_enable(rdev_get_name(rdev));
1327
1312 /* Allow the regulator to ramp; it would be useful 1328 /* Allow the regulator to ramp; it would be useful
1313 * to extend this for bulk operations so that the 1329 * to extend this for bulk operations so that the
1314 * regulators can ramp together. */ 1330 * regulators can ramp together. */
@@ -1316,6 +1332,8 @@ static int _regulator_enable(struct regulator_dev *rdev)
1316 if (ret < 0) 1332 if (ret < 0)
1317 return ret; 1333 return ret;
1318 1334
1335 trace_regulator_enable_delay(rdev_get_name(rdev));
1336
1319 if (delay >= 1000) { 1337 if (delay >= 1000) {
1320 mdelay(delay / 1000); 1338 mdelay(delay / 1000);
1321 udelay(delay % 1000); 1339 udelay(delay % 1000);
@@ -1323,9 +1341,10 @@ static int _regulator_enable(struct regulator_dev *rdev)
1323 udelay(delay); 1341 udelay(delay);
1324 } 1342 }
1325 1343
1344 trace_regulator_enable_complete(rdev_get_name(rdev));
1345
1326 } else if (ret < 0) { 1346 } else if (ret < 0) {
1327 printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1347 rdev_err(rdev, "is_enabled() failed: %d\n", ret);
1328 __func__, rdev_get_name(rdev), ret);
1329 return ret; 1348 return ret;
1330 } 1349 }
1331 /* Fallthrough on positive return values - already enabled */ 1350 /* Fallthrough on positive return values - already enabled */
@@ -1367,8 +1386,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
1367 *supply_rdev_ptr = NULL; 1386 *supply_rdev_ptr = NULL;
1368 1387
1369 if (WARN(rdev->use_count <= 0, 1388 if (WARN(rdev->use_count <= 0,
1370 "unbalanced disables for %s\n", 1389 "unbalanced disables for %s\n", rdev_get_name(rdev)))
1371 rdev_get_name(rdev)))
1372 return -EIO; 1390 return -EIO;
1373 1391
1374 /* are we the last user and permitted to disable ? */ 1392 /* are we the last user and permitted to disable ? */
@@ -1378,13 +1396,16 @@ static int _regulator_disable(struct regulator_dev *rdev,
1378 /* we are last user */ 1396 /* we are last user */
1379 if (_regulator_can_change_status(rdev) && 1397 if (_regulator_can_change_status(rdev) &&
1380 rdev->desc->ops->disable) { 1398 rdev->desc->ops->disable) {
1399 trace_regulator_disable(rdev_get_name(rdev));
1400
1381 ret = rdev->desc->ops->disable(rdev); 1401 ret = rdev->desc->ops->disable(rdev);
1382 if (ret < 0) { 1402 if (ret < 0) {
1383 printk(KERN_ERR "%s: failed to disable %s\n", 1403 rdev_err(rdev, "failed to disable\n");
1384 __func__, rdev_get_name(rdev));
1385 return ret; 1404 return ret;
1386 } 1405 }
1387 1406
1407 trace_regulator_disable_complete(rdev_get_name(rdev));
1408
1388 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, 1409 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1389 NULL); 1410 NULL);
1390 } 1411 }
@@ -1451,8 +1472,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev,
1451 /* ah well, who wants to live forever... */ 1472 /* ah well, who wants to live forever... */
1452 ret = rdev->desc->ops->disable(rdev); 1473 ret = rdev->desc->ops->disable(rdev);
1453 if (ret < 0) { 1474 if (ret < 0) {
1454 printk(KERN_ERR "%s: failed to force disable %s\n", 1475 rdev_err(rdev, "failed to force disable\n");
1455 __func__, rdev_get_name(rdev));
1456 return ret; 1476 return ret;
1457 } 1477 }
1458 /* notify other consumers that power has been forced off */ 1478 /* notify other consumers that power has been forced off */
@@ -1605,6 +1625,62 @@ int regulator_is_supported_voltage(struct regulator *regulator,
1605 return 0; 1625 return 0;
1606} 1626}
1607 1627
1628static int _regulator_do_set_voltage(struct regulator_dev *rdev,
1629 int min_uV, int max_uV)
1630{
1631 int ret;
1632 unsigned int selector;
1633
1634 trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
1635
1636 if (rdev->desc->ops->set_voltage) {
1637 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
1638 &selector);
1639
1640 if (rdev->desc->ops->list_voltage)
1641 selector = rdev->desc->ops->list_voltage(rdev,
1642 selector);
1643 else
1644 selector = -1;
1645 } else if (rdev->desc->ops->set_voltage_sel) {
1646 int best_val = INT_MAX;
1647 int i;
1648
1649 selector = 0;
1650
1651 /* Find the smallest voltage that falls within the specified
1652 * range.
1653 */
1654 for (i = 0; i < rdev->desc->n_voltages; i++) {
1655 ret = rdev->desc->ops->list_voltage(rdev, i);
1656 if (ret < 0)
1657 continue;
1658
1659 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
1660 best_val = ret;
1661 selector = i;
1662 }
1663 }
1664
1665 if (best_val != INT_MAX) {
1666 ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
1667 selector = best_val;
1668 } else {
1669 ret = -EINVAL;
1670 }
1671 } else {
1672 ret = -EINVAL;
1673 }
1674
1675 if (ret == 0)
1676 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
1677 NULL);
1678
1679 trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector);
1680
1681 return ret;
1682}
1683
1608/** 1684/**
1609 * regulator_set_voltage - set regulator output voltage 1685 * regulator_set_voltage - set regulator output voltage
1610 * @regulator: regulator source 1686 * @regulator: regulator source
@@ -1626,12 +1702,20 @@ int regulator_is_supported_voltage(struct regulator *regulator,
1626int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 1702int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
1627{ 1703{
1628 struct regulator_dev *rdev = regulator->rdev; 1704 struct regulator_dev *rdev = regulator->rdev;
1629 int ret; 1705 int ret = 0;
1630 1706
1631 mutex_lock(&rdev->mutex); 1707 mutex_lock(&rdev->mutex);
1632 1708
1709 /* If we're setting the same range as last time the change
1710 * should be a noop (some cpufreq implementations use the same
1711 * voltage for multiple frequencies, for example).
1712 */
1713 if (regulator->min_uV == min_uV && regulator->max_uV == max_uV)
1714 goto out;
1715
1633 /* sanity check */ 1716 /* sanity check */
1634 if (!rdev->desc->ops->set_voltage) { 1717 if (!rdev->desc->ops->set_voltage &&
1718 !rdev->desc->ops->set_voltage_sel) {
1635 ret = -EINVAL; 1719 ret = -EINVAL;
1636 goto out; 1720 goto out;
1637 } 1721 }
@@ -1642,18 +1726,76 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
1642 goto out; 1726 goto out;
1643 regulator->min_uV = min_uV; 1727 regulator->min_uV = min_uV;
1644 regulator->max_uV = max_uV; 1728 regulator->max_uV = max_uV;
1645 ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); 1729
1730 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
1731 if (ret < 0)
1732 goto out;
1733
1734 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
1646 1735
1647out: 1736out:
1648 _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, NULL);
1649 mutex_unlock(&rdev->mutex); 1737 mutex_unlock(&rdev->mutex);
1650 return ret; 1738 return ret;
1651} 1739}
1652EXPORT_SYMBOL_GPL(regulator_set_voltage); 1740EXPORT_SYMBOL_GPL(regulator_set_voltage);
1653 1741
1742/**
1743 * regulator_sync_voltage - re-apply last regulator output voltage
1744 * @regulator: regulator source
1745 *
1746 * Re-apply the last configured voltage. This is intended to be used
1747 * where some external control source the consumer is cooperating with
1748 * has caused the configured voltage to change.
1749 */
1750int regulator_sync_voltage(struct regulator *regulator)
1751{
1752 struct regulator_dev *rdev = regulator->rdev;
1753 int ret, min_uV, max_uV;
1754
1755 mutex_lock(&rdev->mutex);
1756
1757 if (!rdev->desc->ops->set_voltage &&
1758 !rdev->desc->ops->set_voltage_sel) {
1759 ret = -EINVAL;
1760 goto out;
1761 }
1762
1763 /* This is only going to work if we've had a voltage configured. */
1764 if (!regulator->min_uV && !regulator->max_uV) {
1765 ret = -EINVAL;
1766 goto out;
1767 }
1768
1769 min_uV = regulator->min_uV;
1770 max_uV = regulator->max_uV;
1771
1772 /* This should be a paranoia check... */
1773 ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
1774 if (ret < 0)
1775 goto out;
1776
1777 ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
1778 if (ret < 0)
1779 goto out;
1780
1781 ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
1782
1783out:
1784 mutex_unlock(&rdev->mutex);
1785 return ret;
1786}
1787EXPORT_SYMBOL_GPL(regulator_sync_voltage);
1788
1654static int _regulator_get_voltage(struct regulator_dev *rdev) 1789static int _regulator_get_voltage(struct regulator_dev *rdev)
1655{ 1790{
1656 /* sanity check */ 1791 int sel;
1792
1793 if (rdev->desc->ops->get_voltage_sel) {
1794 sel = rdev->desc->ops->get_voltage_sel(rdev);
1795 if (sel < 0)
1796 return sel;
1797 return rdev->desc->ops->list_voltage(rdev, sel);
1798 }
1657 if (rdev->desc->ops->get_voltage) 1799 if (rdev->desc->ops->get_voltage)
1658 return rdev->desc->ops->get_voltage(rdev); 1800 return rdev->desc->ops->get_voltage(rdev);
1659 else 1801 else
@@ -1880,21 +2022,20 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1880 goto out; 2022 goto out;
1881 2023
1882 /* get output voltage */ 2024 /* get output voltage */
1883 output_uV = rdev->desc->ops->get_voltage(rdev); 2025 output_uV = _regulator_get_voltage(rdev);
1884 if (output_uV <= 0) { 2026 if (output_uV <= 0) {
1885 printk(KERN_ERR "%s: invalid output voltage found for %s\n", 2027 rdev_err(rdev, "invalid output voltage found\n");
1886 __func__, rdev_get_name(rdev));
1887 goto out; 2028 goto out;
1888 } 2029 }
1889 2030
1890 /* get input voltage */ 2031 /* get input voltage */
1891 if (rdev->supply && rdev->supply->desc->ops->get_voltage) 2032 input_uV = 0;
1892 input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 2033 if (rdev->supply)
1893 else 2034 input_uV = _regulator_get_voltage(rdev->supply);
2035 if (input_uV <= 0)
1894 input_uV = rdev->constraints->input_uV; 2036 input_uV = rdev->constraints->input_uV;
1895 if (input_uV <= 0) { 2037 if (input_uV <= 0) {
1896 printk(KERN_ERR "%s: invalid input voltage found for %s\n", 2038 rdev_err(rdev, "invalid input voltage found\n");
1897 __func__, rdev_get_name(rdev));
1898 goto out; 2039 goto out;
1899 } 2040 }
1900 2041
@@ -1907,16 +2048,14 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1907 total_uA_load); 2048 total_uA_load);
1908 ret = regulator_check_mode(rdev, mode); 2049 ret = regulator_check_mode(rdev, mode);
1909 if (ret < 0) { 2050 if (ret < 0) {
1910 printk(KERN_ERR "%s: failed to get optimum mode for %s @" 2051 rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n",
1911 " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev), 2052 total_uA_load, input_uV, output_uV);
1912 total_uA_load, input_uV, output_uV);
1913 goto out; 2053 goto out;
1914 } 2054 }
1915 2055
1916 ret = rdev->desc->ops->set_mode(rdev, mode); 2056 ret = rdev->desc->ops->set_mode(rdev, mode);
1917 if (ret < 0) { 2057 if (ret < 0) {
1918 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 2058 rdev_err(rdev, "failed to set optimum mode %x\n", mode);
1919 __func__, mode, rdev_get_name(rdev));
1920 goto out; 2059 goto out;
1921 } 2060 }
1922 ret = mode; 2061 ret = mode;
@@ -2047,7 +2186,7 @@ int regulator_bulk_enable(int num_consumers,
2047 return 0; 2186 return 0;
2048 2187
2049err: 2188err:
2050 printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret); 2189 pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret);
2051 for (--i; i >= 0; --i) 2190 for (--i; i >= 0; --i)
2052 regulator_disable(consumers[i].consumer); 2191 regulator_disable(consumers[i].consumer);
2053 2192
@@ -2082,8 +2221,7 @@ int regulator_bulk_disable(int num_consumers,
2082 return 0; 2221 return 0;
2083 2222
2084err: 2223err:
2085 printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply, 2224 pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret);
2086 ret);
2087 for (--i; i >= 0; --i) 2225 for (--i; i >= 0; --i)
2088 regulator_enable(consumers[i].consumer); 2226 regulator_enable(consumers[i].consumer);
2089 2227
@@ -2166,7 +2304,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2166 int status = 0; 2304 int status = 0;
2167 2305
2168 /* some attributes need specific methods to be displayed */ 2306 /* some attributes need specific methods to be displayed */
2169 if (ops->get_voltage) { 2307 if (ops->get_voltage || ops->get_voltage_sel) {
2170 status = device_create_file(dev, &dev_attr_microvolts); 2308 status = device_create_file(dev, &dev_attr_microvolts);
2171 if (status < 0) 2309 if (status < 0)
2172 return status; 2310 return status;
@@ -2207,7 +2345,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2207 return status; 2345 return status;
2208 2346
2209 /* constraints need specific supporting methods */ 2347 /* constraints need specific supporting methods */
2210 if (ops->set_voltage) { 2348 if (ops->set_voltage || ops->set_voltage_sel) {
2211 status = device_create_file(dev, &dev_attr_min_microvolts); 2349 status = device_create_file(dev, &dev_attr_min_microvolts);
2212 if (status < 0) 2350 if (status < 0)
2213 return status; 2351 return status;
@@ -2271,6 +2409,23 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2271 return status; 2409 return status;
2272} 2410}
2273 2411
2412static void rdev_init_debugfs(struct regulator_dev *rdev)
2413{
2414#ifdef CONFIG_DEBUG_FS
2415 rdev->debugfs = debugfs_create_dir(rdev_get_name(rdev), debugfs_root);
2416 if (IS_ERR(rdev->debugfs) || !rdev->debugfs) {
2417 rdev_warn(rdev, "Failed to create debugfs directory\n");
2418 rdev->debugfs = NULL;
2419 return;
2420 }
2421
2422 debugfs_create_u32("use_count", 0444, rdev->debugfs,
2423 &rdev->use_count);
2424 debugfs_create_u32("open_count", 0444, rdev->debugfs,
2425 &rdev->open_count);
2426#endif
2427}
2428
2274/** 2429/**
2275 * regulator_register - register regulator 2430 * regulator_register - register regulator
2276 * @regulator_desc: regulator to register 2431 * @regulator_desc: regulator to register
@@ -2282,7 +2437,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2282 * Returns 0 on success. 2437 * Returns 0 on success.
2283 */ 2438 */
2284struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 2439struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2285 struct device *dev, struct regulator_init_data *init_data, 2440 struct device *dev, const struct regulator_init_data *init_data,
2286 void *driver_data) 2441 void *driver_data)
2287{ 2442{
2288 static atomic_t regulator_no = ATOMIC_INIT(0); 2443 static atomic_t regulator_no = ATOMIC_INIT(0);
@@ -2302,6 +2457,22 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2302 if (!init_data) 2457 if (!init_data)
2303 return ERR_PTR(-EINVAL); 2458 return ERR_PTR(-EINVAL);
2304 2459
2460 /* Only one of each should be implemented */
2461 WARN_ON(regulator_desc->ops->get_voltage &&
2462 regulator_desc->ops->get_voltage_sel);
2463 WARN_ON(regulator_desc->ops->set_voltage &&
2464 regulator_desc->ops->set_voltage_sel);
2465
2466 /* If we're using selectors we must implement list_voltage. */
2467 if (regulator_desc->ops->get_voltage_sel &&
2468 !regulator_desc->ops->list_voltage) {
2469 return ERR_PTR(-EINVAL);
2470 }
2471 if (regulator_desc->ops->set_voltage_sel &&
2472 !regulator_desc->ops->list_voltage) {
2473 return ERR_PTR(-EINVAL);
2474 }
2475
2305 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 2476 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
2306 if (rdev == NULL) 2477 if (rdev == NULL)
2307 return ERR_PTR(-ENOMEM); 2478 return ERR_PTR(-ENOMEM);
@@ -2399,6 +2570,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2399 } 2570 }
2400 2571
2401 list_add(&rdev->list, &regulator_list); 2572 list_add(&rdev->list, &regulator_list);
2573
2574 rdev_init_debugfs(rdev);
2402out: 2575out:
2403 mutex_unlock(&regulator_list_mutex); 2576 mutex_unlock(&regulator_list_mutex);
2404 return rdev; 2577 return rdev;
@@ -2431,12 +2604,16 @@ void regulator_unregister(struct regulator_dev *rdev)
2431 return; 2604 return;
2432 2605
2433 mutex_lock(&regulator_list_mutex); 2606 mutex_lock(&regulator_list_mutex);
2607#ifdef CONFIG_DEBUG_FS
2608 debugfs_remove_recursive(rdev->debugfs);
2609#endif
2434 WARN_ON(rdev->open_count); 2610 WARN_ON(rdev->open_count);
2435 unset_regulator_supplies(rdev); 2611 unset_regulator_supplies(rdev);
2436 list_del(&rdev->list); 2612 list_del(&rdev->list);
2437 if (rdev->supply) 2613 if (rdev->supply)
2438 sysfs_remove_link(&rdev->dev.kobj, "supply"); 2614 sysfs_remove_link(&rdev->dev.kobj, "supply");
2439 device_unregister(&rdev->dev); 2615 device_unregister(&rdev->dev);
2616 kfree(rdev->constraints);
2440 mutex_unlock(&regulator_list_mutex); 2617 mutex_unlock(&regulator_list_mutex);
2441} 2618}
2442EXPORT_SYMBOL_GPL(regulator_unregister); 2619EXPORT_SYMBOL_GPL(regulator_unregister);
@@ -2465,8 +2642,7 @@ int regulator_suspend_prepare(suspend_state_t state)
2465 mutex_unlock(&rdev->mutex); 2642 mutex_unlock(&rdev->mutex);
2466 2643
2467 if (ret < 0) { 2644 if (ret < 0) {
2468 printk(KERN_ERR "%s: failed to prepare %s\n", 2645 rdev_err(rdev, "failed to prepare\n");
2469 __func__, rdev_get_name(rdev));
2470 goto out; 2646 goto out;
2471 } 2647 }
2472 } 2648 }
@@ -2572,10 +2748,16 @@ static int __init regulator_init(void)
2572{ 2748{
2573 int ret; 2749 int ret;
2574 2750
2575 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
2576
2577 ret = class_register(&regulator_class); 2751 ret = class_register(&regulator_class);
2578 2752
2753#ifdef CONFIG_DEBUG_FS
2754 debugfs_root = debugfs_create_dir("regulator", NULL);
2755 if (IS_ERR(debugfs_root) || !debugfs_root) {
2756 pr_warn("regulator: Failed to create debugfs directory\n");
2757 debugfs_root = NULL;
2758 }
2759#endif
2760
2579 regulator_dummy_init(); 2761 regulator_dummy_init();
2580 2762
2581 return ret; 2763 return ret;
@@ -2590,7 +2772,6 @@ static int __init regulator_init_complete(void)
2590 struct regulator_ops *ops; 2772 struct regulator_ops *ops;
2591 struct regulation_constraints *c; 2773 struct regulation_constraints *c;
2592 int enabled, ret; 2774 int enabled, ret;
2593 const char *name;
2594 2775
2595 mutex_lock(&regulator_list_mutex); 2776 mutex_lock(&regulator_list_mutex);
2596 2777
@@ -2602,8 +2783,6 @@ static int __init regulator_init_complete(void)
2602 ops = rdev->desc->ops; 2783 ops = rdev->desc->ops;
2603 c = rdev->constraints; 2784 c = rdev->constraints;
2604 2785
2605 name = rdev_get_name(rdev);
2606
2607 if (!ops->disable || (c && c->always_on)) 2786 if (!ops->disable || (c && c->always_on))
2608 continue; 2787 continue;
2609 2788
@@ -2624,13 +2803,10 @@ static int __init regulator_init_complete(void)
2624 if (has_full_constraints) { 2803 if (has_full_constraints) {
2625 /* We log since this may kill the system if it 2804 /* We log since this may kill the system if it
2626 * goes wrong. */ 2805 * goes wrong. */
2627 printk(KERN_INFO "%s: disabling %s\n", 2806 rdev_info(rdev, "disabling\n");
2628 __func__, name);
2629 ret = ops->disable(rdev); 2807 ret = ops->disable(rdev);
2630 if (ret != 0) { 2808 if (ret != 0) {
2631 printk(KERN_ERR 2809 rdev_err(rdev, "couldn't disable: %d\n", ret);
2632 "%s: couldn't disable %s: %d\n",
2633 __func__, name, ret);
2634 } 2810 }
2635 } else { 2811 } else {
2636 /* The intention is that in future we will 2812 /* The intention is that in future we will
@@ -2638,9 +2814,7 @@ static int __init regulator_init_complete(void)
2638 * so warn even if we aren't going to do 2814 * so warn even if we aren't going to do
2639 * anything here. 2815 * anything here.
2640 */ 2816 */
2641 printk(KERN_WARNING 2817 rdev_warn(rdev, "incomplete constraints, leaving on\n");
2642 "%s: incomplete constraints, leaving %s on\n",
2643 __func__, name);
2644 } 2818 }
2645 2819
2646unlock: 2820unlock:
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index f8c4661a7a81..362e08221085 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -107,7 +107,7 @@ static inline int check_range(struct da903x_regulator_info *info,
107 107
108/* DA9030/DA9034 common operations */ 108/* DA9030/DA9034 common operations */
109static int da903x_set_ldo_voltage(struct regulator_dev *rdev, 109static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
110 int min_uV, int max_uV) 110 int min_uV, int max_uV, unsigned *selector)
111{ 111{
112 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 112 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
113 struct device *da9034_dev = to_da903x_dev(rdev); 113 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -119,6 +119,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
119 } 119 }
120 120
121 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 121 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
122 *selector = val;
122 val <<= info->vol_shift; 123 val <<= info->vol_shift;
123 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 124 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
124 125
@@ -187,7 +188,8 @@ static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
187 188
188/* DA9030 specific operations */ 189/* DA9030 specific operations */
189static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, 190static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
190 int min_uV, int max_uV) 191 int min_uV, int max_uV,
192 unsigned *selector)
191{ 193{
192 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 194 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
193 struct device *da903x_dev = to_da903x_dev(rdev); 195 struct device *da903x_dev = to_da903x_dev(rdev);
@@ -200,6 +202,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
200 } 202 }
201 203
202 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 204 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
205 *selector = val;
203 val <<= info->vol_shift; 206 val <<= info->vol_shift;
204 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 207 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
205 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ 208 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
@@ -214,7 +217,8 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
214} 217}
215 218
216static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, 219static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
217 int min_uV, int max_uV) 220 int min_uV, int max_uV,
221 unsigned *selector)
218{ 222{
219 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 223 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
220 struct device *da903x_dev = to_da903x_dev(rdev); 224 struct device *da903x_dev = to_da903x_dev(rdev);
@@ -234,6 +238,7 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
234 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV; 238 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
235 } 239 }
236 240
241 *selector = val;
237 val <<= info->vol_shift; 242 val <<= info->vol_shift;
238 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 243 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
239 244
@@ -263,7 +268,7 @@ static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
263 268
264/* DA9034 specific operations */ 269/* DA9034 specific operations */
265static int da9034_set_dvc_voltage(struct regulator_dev *rdev, 270static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
266 int min_uV, int max_uV) 271 int min_uV, int max_uV, unsigned *selector)
267{ 272{
268 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 273 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
269 struct device *da9034_dev = to_da903x_dev(rdev); 274 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -276,6 +281,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
276 } 281 }
277 282
278 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 283 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
284 *selector = val;
279 val <<= info->vol_shift; 285 val <<= info->vol_shift;
280 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 286 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
281 287
@@ -289,7 +295,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
289} 295}
290 296
291static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, 297static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
292 int min_uV, int max_uV) 298 int min_uV, int max_uV, unsigned *selector)
293{ 299{
294 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 300 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
295 struct device *da9034_dev = to_da903x_dev(rdev); 301 struct device *da9034_dev = to_da903x_dev(rdev);
@@ -302,6 +308,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
302 308
303 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 309 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
304 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 310 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
311 *selector = val;
305 val <<= info->vol_shift; 312 val <<= info->vol_shift;
306 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 313 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
307 314
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index b8cc6389a541..e4b3592e8176 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -58,7 +58,9 @@ out:
58 return data; 58 return data;
59} 59}
60 60
61static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV) 61static int isl6271a_set_voltage(struct regulator_dev *dev,
62 int minuV, int maxuV,
63 unsigned *selector)
62{ 64{
63 struct isl_pmic *pmic = rdev_get_drvdata(dev); 65 struct isl_pmic *pmic = rdev_get_drvdata(dev);
64 int vsel, err, data; 66 int vsel, err, data;
@@ -78,6 +80,8 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV)
78 /* Convert the microvolts to data for the chip */ 80 /* Convert the microvolts to data for the chip */
79 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP; 81 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
80 82
83 *selector = data;
84
81 mutex_lock(&pmic->mtx); 85 mutex_lock(&pmic->mtx);
82 86
83 err = i2c_smbus_write_byte(pmic->client, data); 87 err = i2c_smbus_write_byte(pmic->client, data);
@@ -169,7 +173,7 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
169 init_data, pmic); 173 init_data, pmic);
170 if (IS_ERR(pmic->rdev[i])) { 174 if (IS_ERR(pmic->rdev[i])) {
171 dev_err(&i2c->dev, "failed to register %s\n", id->name); 175 dev_err(&i2c->dev, "failed to register %s\n", id->name);
172 err = PTR_ERR(pmic->rdev); 176 err = PTR_ERR(pmic->rdev[i]);
173 goto error; 177 goto error;
174 } 178 }
175 } 179 }
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 3bb82b624e19..0f22ef12601c 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -168,7 +168,8 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev)
168} 168}
169 169
170static int lp3971_ldo_set_voltage(struct regulator_dev *dev, 170static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
171 int min_uV, int max_uV) 171 int min_uV, int max_uV,
172 unsigned int *selector)
172{ 173{
173 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 174 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
174 int ldo = rdev_get_id(dev) - LP3971_LDO1; 175 int ldo = rdev_get_id(dev) - LP3971_LDO1;
@@ -187,6 +188,8 @@ static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
187 if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol) 188 if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol)
188 return -EINVAL; 189 return -EINVAL;
189 190
191 *selector = val;
192
190 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), 193 return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
191 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), 194 LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
192 val << LDO_VOL_CONTR_SHIFT(ldo)); 195 val << LDO_VOL_CONTR_SHIFT(ldo));
@@ -256,7 +259,8 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev)
256} 259}
257 260
258static int lp3971_dcdc_set_voltage(struct regulator_dev *dev, 261static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
259 int min_uV, int max_uV) 262 int min_uV, int max_uV,
263 unsigned int *selector)
260{ 264{
261 struct lp3971 *lp3971 = rdev_get_drvdata(dev); 265 struct lp3971 *lp3971 = rdev_get_drvdata(dev);
262 int buck = rdev_get_id(dev) - LP3971_DCDC1; 266 int buck = rdev_get_id(dev) - LP3971_DCDC1;
@@ -277,6 +281,8 @@ static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
277 if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol) 281 if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol)
278 return -EINVAL; 282 return -EINVAL;
279 283
284 *selector = val;
285
280 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), 286 ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
281 BUCK_TARGET_VOL_MASK, val); 287 BUCK_TARGET_VOL_MASK, val);
282 if (ret) 288 if (ret)
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index e07062fd0b42..6aa1b506fb5d 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -292,7 +292,8 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
292} 292}
293 293
294static int lp3972_ldo_set_voltage(struct regulator_dev *dev, 294static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
295 int min_uV, int max_uV) 295 int min_uV, int max_uV,
296 unsigned int *selector)
296{ 297{
297 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 298 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
298 int ldo = rdev_get_id(dev) - LP3972_LDO1; 299 int ldo = rdev_get_id(dev) - LP3972_LDO1;
@@ -313,6 +314,8 @@ static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
313 if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol) 314 if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol)
314 return -EINVAL; 315 return -EINVAL;
315 316
317 *selector = val;
318
316 shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); 319 shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo);
317 ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), 320 ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo),
318 LP3972_LDO_VOL_MASK(ldo) << shift, val << shift); 321 LP3972_LDO_VOL_MASK(ldo) << shift, val << shift);
@@ -416,7 +419,8 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
416} 419}
417 420
418static int lp3972_dcdc_set_voltage(struct regulator_dev *dev, 421static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
419 int min_uV, int max_uV) 422 int min_uV, int max_uV,
423 unsigned int *selector)
420{ 424{
421 struct lp3972 *lp3972 = rdev_get_drvdata(dev); 425 struct lp3972 *lp3972 = rdev_get_drvdata(dev);
422 int buck = rdev_get_id(dev) - LP3972_DCDC1; 426 int buck = rdev_get_id(dev) - LP3972_DCDC1;
@@ -438,6 +442,8 @@ static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
438 vol_map[val] > max_vol) 442 vol_map[val] > max_vol)
439 return -EINVAL; 443 return -EINVAL;
440 444
445 *selector = val;
446
441 ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), 447 ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck),
442 LP3972_BUCK_VOL_MASK, val); 448 LP3972_BUCK_VOL_MASK, val);
443 if (ret) 449 if (ret)
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 559cfa271a44..3f49512c5134 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -63,12 +63,12 @@ static int max1586_v3_calc_voltage(struct max1586_data *max1586,
63 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL); 63 return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL);
64} 64}
65 65
66static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV) 66static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV,
67 unsigned *selector)
67{ 68{
68 struct max1586_data *max1586 = rdev_get_drvdata(rdev); 69 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
69 struct i2c_client *client = max1586->client; 70 struct i2c_client *client = max1586->client;
70 unsigned range_uV = max1586->max_uV - max1586->min_uV; 71 unsigned range_uV = max1586->max_uV - max1586->min_uV;
71 unsigned selector;
72 u8 v3_prog; 72 u8 v3_prog;
73 73
74 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV) 74 if (min_uV > max1586->max_uV || max_uV < max1586->min_uV)
@@ -76,15 +76,15 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV)
76 if (min_uV < max1586->min_uV) 76 if (min_uV < max1586->min_uV)
77 min_uV = max1586->min_uV; 77 min_uV = max1586->min_uV;
78 78
79 selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + 79 *selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL +
80 range_uV - 1) / range_uV; 80 range_uV - 1) / range_uV;
81 if (max1586_v3_calc_voltage(max1586, selector) > max_uV) 81 if (max1586_v3_calc_voltage(max1586, *selector) > max_uV)
82 return -EINVAL; 82 return -EINVAL;
83 83
84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", 84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
85 max1586_v3_calc_voltage(max1586, selector) / 1000); 85 max1586_v3_calc_voltage(max1586, *selector) / 1000);
86 86
87 v3_prog = I2C_V3_SELECT | (u8) selector; 87 v3_prog = I2C_V3_SELECT | (u8) *selector;
88 return i2c_smbus_write_byte(client, v3_prog); 88 return i2c_smbus_write_byte(client, v3_prog);
89} 89}
90 90
@@ -110,10 +110,10 @@ static int max1586_v6_calc_voltage(unsigned selector)
110 return voltages_uv[selector]; 110 return voltages_uv[selector];
111} 111}
112 112
113static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV) 113static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV,
114 unsigned int *selector)
114{ 115{
115 struct i2c_client *client = rdev_get_drvdata(rdev); 116 struct i2c_client *client = rdev_get_drvdata(rdev);
116 unsigned selector;
117 u8 v6_prog; 117 u8 v6_prog;
118 118
119 if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV) 119 if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV)
@@ -122,21 +122,21 @@ static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV)
122 return -EINVAL; 122 return -EINVAL;
123 123
124 if (min_uV < 1800000) 124 if (min_uV < 1800000)
125 selector = 0; 125 *selector = 0;
126 else if (min_uV < 2500000) 126 else if (min_uV < 2500000)
127 selector = 1; 127 *selector = 1;
128 else if (min_uV < 3000000) 128 else if (min_uV < 3000000)
129 selector = 2; 129 *selector = 2;
130 else if (min_uV >= 3000000) 130 else if (min_uV >= 3000000)
131 selector = 3; 131 *selector = 3;
132 132
133 if (max1586_v6_calc_voltage(selector) > max_uV) 133 if (max1586_v6_calc_voltage(*selector) > max_uV)
134 return -EINVAL; 134 return -EINVAL;
135 135
136 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", 136 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
137 max1586_v6_calc_voltage(selector) / 1000); 137 max1586_v6_calc_voltage(*selector) / 1000);
138 138
139 v6_prog = I2C_V6_SELECT | (u8) selector; 139 v6_prog = I2C_V6_SELECT | (u8) *selector;
140 return i2c_smbus_write_byte(client, v6_prog); 140 return i2c_smbus_write_byte(client, v6_prog);
141} 141}
142 142
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 6b60a9c0366b..30eb9e54f7ec 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -155,7 +155,7 @@ static int max8649_get_voltage(struct regulator_dev *rdev)
155} 155}
156 156
157static int max8649_set_voltage(struct regulator_dev *rdev, 157static int max8649_set_voltage(struct regulator_dev *rdev,
158 int min_uV, int max_uV) 158 int min_uV, int max_uV, unsigned *selector)
159{ 159{
160 struct max8649_regulator_info *info = rdev_get_drvdata(rdev); 160 struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
161 unsigned char data, mask; 161 unsigned char data, mask;
@@ -168,6 +168,7 @@ static int max8649_set_voltage(struct regulator_dev *rdev,
168 data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1) 168 data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1)
169 / MAX8649_DCDC_STEP; 169 / MAX8649_DCDC_STEP;
170 mask = MAX8649_VOL_MASK; 170 mask = MAX8649_VOL_MASK;
171 *selector = data & mask;
171 172
172 return max8649_set_bits(info->i2c, info->vol_reg, mask, data); 173 return max8649_set_bits(info->i2c, info->vol_reg, mask, data);
173} 174}
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index c570e6eb0db2..33f5d9a492ef 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -141,7 +141,8 @@ static int max8660_dcdc_get(struct regulator_dev *rdev)
141 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; 141 return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP;
142} 142}
143 143
144static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV) 144static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV,
145 unsigned int *s)
145{ 146{
146 struct max8660 *max8660 = rdev_get_drvdata(rdev); 147 struct max8660 *max8660 = rdev_get_drvdata(rdev);
147 u8 reg, selector, bits; 148 u8 reg, selector, bits;
@@ -154,6 +155,7 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV)
154 155
155 selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1)) 156 selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1))
156 / MAX8660_DCDC_STEP; 157 / MAX8660_DCDC_STEP;
158 *s = selector;
157 159
158 ret = max8660_dcdc_list(rdev, selector); 160 ret = max8660_dcdc_list(rdev, selector);
159 if (ret < 0 || ret > max_uV) 161 if (ret < 0 || ret > max_uV)
@@ -196,7 +198,8 @@ static int max8660_ldo5_get(struct regulator_dev *rdev)
196 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; 198 return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP;
197} 199}
198 200
199static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV) 201static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV,
202 unsigned int *s)
200{ 203{
201 struct max8660 *max8660 = rdev_get_drvdata(rdev); 204 struct max8660 *max8660 = rdev_get_drvdata(rdev);
202 u8 selector; 205 u8 selector;
@@ -213,6 +216,8 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV)
213 if (ret < 0 || ret > max_uV) 216 if (ret < 0 || ret > max_uV)
214 return -EINVAL; 217 return -EINVAL;
215 218
219 *s = selector;
220
216 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); 221 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector);
217 if (ret) 222 if (ret)
218 return ret; 223 return ret;
@@ -270,7 +275,8 @@ static int max8660_ldo67_get(struct regulator_dev *rdev)
270 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; 275 return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP;
271} 276}
272 277
273static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV) 278static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV,
279 int max_uV, unsigned int *s)
274{ 280{
275 struct max8660 *max8660 = rdev_get_drvdata(rdev); 281 struct max8660 *max8660 = rdev_get_drvdata(rdev);
276 u8 selector; 282 u8 selector;
@@ -288,6 +294,8 @@ static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, int max_uV)
288 if (ret < 0 || ret > max_uV) 294 if (ret < 0 || ret > max_uV)
289 return -EINVAL; 295 return -EINVAL;
290 296
297 *s = selector;
298
291 if (rdev_get_id(rdev) == MAX8660_V6) 299 if (rdev_get_id(rdev) == MAX8660_V6)
292 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); 300 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector);
293 else 301 else
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index 552cad85ae5a..8ae147549c6a 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -55,7 +55,7 @@ static int max8925_list_voltage(struct regulator_dev *rdev, unsigned index)
55} 55}
56 56
57static int max8925_set_voltage(struct regulator_dev *rdev, 57static int max8925_set_voltage(struct regulator_dev *rdev,
58 int min_uV, int max_uV) 58 int min_uV, int max_uV, unsigned int *selector)
59{ 59{
60 struct max8925_regulator_info *info = rdev_get_drvdata(rdev); 60 struct max8925_regulator_info *info = rdev_get_drvdata(rdev);
61 unsigned char data, mask; 61 unsigned char data, mask;
@@ -66,6 +66,7 @@ static int max8925_set_voltage(struct regulator_dev *rdev,
66 return -EINVAL; 66 return -EINVAL;
67 } 67 }
68 data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 68 data = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
69 *selector = data;
69 data <<= info->vol_shift; 70 data <<= info->vol_shift;
70 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 71 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
71 72
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index 0d5dda4fd911..a8f4ecfb0843 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -133,7 +133,7 @@ static int max8952_get_voltage(struct regulator_dev *rdev)
133} 133}
134 134
135static int max8952_set_voltage(struct regulator_dev *rdev, 135static int max8952_set_voltage(struct regulator_dev *rdev,
136 int min_uV, int max_uV) 136 int min_uV, int max_uV, unsigned *selector)
137{ 137{
138 struct max8952_data *max8952 = rdev_get_drvdata(rdev); 138 struct max8952_data *max8952 = rdev_get_drvdata(rdev);
139 s8 vid = -1, i; 139 s8 vid = -1, i;
@@ -156,6 +156,7 @@ static int max8952_set_voltage(struct regulator_dev *rdev,
156 if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) { 156 if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) {
157 max8952->vid0 = (vid % 2 == 1); 157 max8952->vid0 = (vid % 2 == 1);
158 max8952->vid1 = (((vid >> 1) % 2) == 1); 158 max8952->vid1 = (((vid >> 1) % 2) == 1);
159 *selector = vid;
159 gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); 160 gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0);
160 gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); 161 gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1);
161 } else 162 } else
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 5c20756db607..0ec49ca527a8 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -304,7 +304,7 @@ static int max8998_get_voltage(struct regulator_dev *rdev)
304} 304}
305 305
306static int max8998_set_voltage_ldo(struct regulator_dev *rdev, 306static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
307 int min_uV, int max_uV) 307 int min_uV, int max_uV, unsigned *selector)
308{ 308{
309 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 309 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
310 struct i2c_client *i2c = max8998->iodev->i2c; 310 struct i2c_client *i2c = max8998->iodev->i2c;
@@ -331,6 +331,8 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
331 if (desc->min + desc->step*i > max_vol) 331 if (desc->min + desc->step*i > max_vol)
332 return -EINVAL; 332 return -EINVAL;
333 333
334 *selector = i;
335
334 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 336 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
335 if (ret) 337 if (ret)
336 return ret; 338 return ret;
@@ -352,7 +354,7 @@ static inline void buck2_gpio_set(int gpio, int v)
352} 354}
353 355
354static int max8998_set_voltage_buck(struct regulator_dev *rdev, 356static int max8998_set_voltage_buck(struct regulator_dev *rdev,
355 int min_uV, int max_uV) 357 int min_uV, int max_uV, unsigned *selector)
356{ 358{
357 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 359 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
358 struct max8998_platform_data *pdata = 360 struct max8998_platform_data *pdata =
@@ -384,6 +386,8 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
384 if (desc->min + desc->step*i > max_vol) 386 if (desc->min + desc->step*i > max_vol)
385 return -EINVAL; 387 return -EINVAL;
386 388
389 *selector = i;
390
387 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 391 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
388 if (ret) 392 if (ret)
389 return ret; 393 return ret;
@@ -420,6 +424,9 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
420 } 424 }
421 } 425 }
422 426
427 if (pdata->buck_voltage_lock)
428 return -EINVAL;
429
423 /* no predefine regulator found */ 430 /* no predefine regulator found */
424 max8998->buck1_idx = (buck1_last_val % 2) + 2; 431 max8998->buck1_idx = (buck1_last_val % 2) + 2;
425 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", 432 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n",
@@ -447,18 +454,26 @@ buck1_exit:
447 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" 454 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n"
448 , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); 455 , i, max8998->buck2_vol[0], max8998->buck2_vol[1]);
449 if (gpio_is_valid(pdata->buck2_set3)) { 456 if (gpio_is_valid(pdata->buck2_set3)) {
450 if (max8998->buck2_vol[0] == i) { 457
451 max8998->buck1_idx = 0; 458 /* check if requested voltage */
452 buck2_gpio_set(pdata->buck2_set3, 0); 459 /* value is already defined */
453 } else { 460 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) {
454 max8998->buck1_idx = 1; 461 if (max8998->buck2_vol[j] == i) {
455 ret = max8998_get_voltage_register(rdev, &reg, 462 max8998->buck2_idx = j;
456 &shift, 463 buck2_gpio_set(pdata->buck2_set3, j);
457 &mask); 464 goto buck2_exit;
458 ret = max8998_write_reg(i2c, reg, i); 465 }
459 max8998->buck2_vol[1] = i;
460 buck2_gpio_set(pdata->buck2_set3, 1);
461 } 466 }
467
468 if (pdata->buck_voltage_lock)
469 return -EINVAL;
470
471 max8998_get_voltage_register(rdev,
472 &reg, &shift, &mask);
473 ret = max8998_write_reg(i2c, reg, i);
474 max8998->buck2_vol[max8998->buck2_idx] = i;
475 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx);
476buck2_exit:
462 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, 477 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name,
463 gpio_get_value(pdata->buck2_set3)); 478 gpio_get_value(pdata->buck2_set3));
464 } else { 479 } else {
@@ -703,6 +718,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
703 platform_set_drvdata(pdev, max8998); 718 platform_set_drvdata(pdev, max8998);
704 i2c = max8998->iodev->i2c; 719 i2c = max8998->iodev->i2c;
705 720
721 max8998->buck1_idx = pdata->buck1_default_idx;
722 max8998->buck2_idx = pdata->buck2_default_idx;
723
706 /* NOTE: */ 724 /* NOTE: */
707 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */ 725 /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */
708 /* will be displayed */ 726 /* will be displayed */
@@ -735,23 +753,46 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
735 i = 0; 753 i = 0;
736 while (buck12_voltage_map_desc.min + 754 while (buck12_voltage_map_desc.min +
737 buck12_voltage_map_desc.step*i 755 buck12_voltage_map_desc.step*i
738 != (pdata->buck1_max_voltage1 / 1000)) 756 < (pdata->buck1_voltage1 / 1000))
739 i++; 757 i++;
740 printk(KERN_ERR "i:%d, buck1_idx:%d\n", i, max8998->buck1_idx);
741 max8998->buck1_vol[0] = i; 758 max8998->buck1_vol[0] = i;
742 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); 759 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i);
760 if (ret)
761 return ret;
743 762
744 /* Set predefined value for BUCK1 register 2 */ 763 /* Set predefined value for BUCK1 register 2 */
745 i = 0; 764 i = 0;
746 while (buck12_voltage_map_desc.min + 765 while (buck12_voltage_map_desc.min +
747 buck12_voltage_map_desc.step*i 766 buck12_voltage_map_desc.step*i
748 != (pdata->buck1_max_voltage2 / 1000)) 767 < (pdata->buck1_voltage2 / 1000))
749 i++; 768 i++;
750 769
751 max8998->buck1_vol[1] = i; 770 max8998->buck1_vol[1] = i;
752 printk(KERN_ERR "i:%d, buck1_idx:%d\n", i, max8998->buck1_idx); 771 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i);
753 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i) 772 if (ret)
754 + ret; 773 return ret;
774
775 /* Set predefined value for BUCK1 register 3 */
776 i = 0;
777 while (buck12_voltage_map_desc.min +
778 buck12_voltage_map_desc.step*i
779 < (pdata->buck1_voltage3 / 1000))
780 i++;
781
782 max8998->buck1_vol[2] = i;
783 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i);
784 if (ret)
785 return ret;
786
787 /* Set predefined value for BUCK1 register 4 */
788 i = 0;
789 while (buck12_voltage_map_desc.min +
790 buck12_voltage_map_desc.step*i
791 < (pdata->buck1_voltage4 / 1000))
792 i++;
793
794 max8998->buck1_vol[3] = i;
795 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i);
755 if (ret) 796 if (ret)
756 return ret; 797 return ret;
757 798
@@ -768,18 +809,28 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
768 gpio_direction_output(pdata->buck2_set3, 809 gpio_direction_output(pdata->buck2_set3,
769 max8998->buck2_idx & 0x1); 810 max8998->buck2_idx & 0x1);
770 811
771 /* BUCK2 - set preset default voltage value to buck2_vol[0] */ 812 /* BUCK2 register 1 */
772 i = 0; 813 i = 0;
773 while (buck12_voltage_map_desc.min + 814 while (buck12_voltage_map_desc.min +
774 buck12_voltage_map_desc.step*i 815 buck12_voltage_map_desc.step*i
775 != (pdata->buck2_max_voltage / 1000)) 816 < (pdata->buck2_voltage1 / 1000))
776 i++; 817 i++;
777 printk(KERN_ERR "i:%d, buck2_idx:%d\n", i, max8998->buck2_idx);
778 max8998->buck2_vol[0] = i; 818 max8998->buck2_vol[0] = i;
779 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); 819 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i);
780 if (ret) 820 if (ret)
781 return ret; 821 return ret;
782 822
823 /* BUCK2 register 2 */
824 i = 0;
825 while (buck12_voltage_map_desc.min +
826 buck12_voltage_map_desc.step*i
827 < (pdata->buck2_voltage2 / 1000))
828 i++;
829 printk(KERN_ERR "i2:%d, buck2_idx:%d\n", i, max8998->buck2_idx);
830 max8998->buck2_vol[1] = i;
831 ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i);
832 if (ret)
833 return ret;
783 } 834 }
784 835
785 for (i = 0; i < pdata->num_regulators; i++) { 836 for (i = 0; i < pdata->num_regulators; i++) {
@@ -831,6 +882,12 @@ static int __devexit max8998_pmic_remove(struct platform_device *pdev)
831 return 0; 882 return 0;
832} 883}
833 884
885static const struct platform_device_id max8998_pmic_id[] = {
886 { "max8998-pmic", TYPE_MAX8998 },
887 { "lp3974-pmic", TYPE_LP3974 },
888 { }
889};
890
834static struct platform_driver max8998_pmic_driver = { 891static struct platform_driver max8998_pmic_driver = {
835 .driver = { 892 .driver = {
836 .name = "max8998-pmic", 893 .name = "max8998-pmic",
@@ -838,6 +895,7 @@ static struct platform_driver max8998_pmic_driver = {
838 }, 895 },
839 .probe = max8998_pmic_probe, 896 .probe = max8998_pmic_probe,
840 .remove = __devexit_p(max8998_pmic_remove), 897 .remove = __devexit_p(max8998_pmic_remove),
898 .id_table = max8998_pmic_id,
841}; 899};
842 900
843static int __init max8998_pmic_init(void) 901static int __init max8998_pmic_init(void)
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index ecd99f59dba8..3e5d0c3b4e53 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Regulator Driver for Freescale MC13783 PMIC 2 * Regulator Driver for Freescale MC13783 PMIC
3 * 3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
4 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 5 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
5 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> 6 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
6 * 7 *
@@ -17,6 +18,7 @@
17#include <linux/slab.h> 18#include <linux/slab.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/err.h> 20#include <linux/err.h>
21#include "mc13xxx.h"
20 22
21#define MC13783_REG_SWITCHERS5 29 23#define MC13783_REG_SWITCHERS5 29
22#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) 24#define MC13783_REG_SWITCHERS5_SW3EN (1 << 20)
@@ -89,154 +91,106 @@
89#define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15) 91#define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15)
90 92
91 93
92struct mc13783_regulator {
93 struct regulator_desc desc;
94 int reg;
95 int enable_bit;
96 int vsel_reg;
97 int vsel_shift;
98 int vsel_mask;
99 int const *voltages;
100};
101
102/* Voltage Values */ 94/* Voltage Values */
103static const int const mc13783_sw3_val[] = { 95static const int mc13783_sw3_val[] = {
104 5000000, 5000000, 5000000, 5500000, 96 5000000, 5000000, 5000000, 5500000,
105}; 97};
106 98
107static const int const mc13783_vaudio_val[] = { 99static const int mc13783_vaudio_val[] = {
108 2775000, 100 2775000,
109}; 101};
110 102
111static const int const mc13783_viohi_val[] = { 103static const int mc13783_viohi_val[] = {
112 2775000, 104 2775000,
113}; 105};
114 106
115static const int const mc13783_violo_val[] = { 107static const int mc13783_violo_val[] = {
116 1200000, 1300000, 1500000, 1800000, 108 1200000, 1300000, 1500000, 1800000,
117}; 109};
118 110
119static const int const mc13783_vdig_val[] = { 111static const int mc13783_vdig_val[] = {
120 1200000, 1300000, 1500000, 1800000, 112 1200000, 1300000, 1500000, 1800000,
121}; 113};
122 114
123static const int const mc13783_vgen_val[] = { 115static const int mc13783_vgen_val[] = {
124 1200000, 1300000, 1500000, 1800000, 116 1200000, 1300000, 1500000, 1800000,
125 1100000, 2000000, 2775000, 2400000, 117 1100000, 2000000, 2775000, 2400000,
126}; 118};
127 119
128static const int const mc13783_vrfdig_val[] = { 120static const int mc13783_vrfdig_val[] = {
129 1200000, 1500000, 1800000, 1875000, 121 1200000, 1500000, 1800000, 1875000,
130}; 122};
131 123
132static const int const mc13783_vrfref_val[] = { 124static const int mc13783_vrfref_val[] = {
133 2475000, 2600000, 2700000, 2775000, 125 2475000, 2600000, 2700000, 2775000,
134}; 126};
135 127
136static const int const mc13783_vrfcp_val[] = { 128static const int mc13783_vrfcp_val[] = {
137 2700000, 2775000, 129 2700000, 2775000,
138}; 130};
139 131
140static const int const mc13783_vsim_val[] = { 132static const int mc13783_vsim_val[] = {
141 1800000, 2900000, 3000000, 133 1800000, 2900000, 3000000,
142}; 134};
143 135
144static const int const mc13783_vesim_val[] = { 136static const int mc13783_vesim_val[] = {
145 1800000, 2900000, 137 1800000, 2900000,
146}; 138};
147 139
148static const int const mc13783_vcam_val[] = { 140static const int mc13783_vcam_val[] = {
149 1500000, 1800000, 2500000, 2550000, 141 1500000, 1800000, 2500000, 2550000,
150 2600000, 2750000, 2800000, 3000000, 142 2600000, 2750000, 2800000, 3000000,
151}; 143};
152 144
153static const int const mc13783_vrfbg_val[] = { 145static const int mc13783_vrfbg_val[] = {
154 1250000, 146 1250000,
155}; 147};
156 148
157static const int const mc13783_vvib_val[] = { 149static const int mc13783_vvib_val[] = {
158 1300000, 1800000, 2000000, 3000000, 150 1300000, 1800000, 2000000, 3000000,
159}; 151};
160 152
161static const int const mc13783_vmmc_val[] = { 153static const int mc13783_vmmc_val[] = {
162 1600000, 1800000, 2000000, 2600000, 154 1600000, 1800000, 2000000, 2600000,
163 2700000, 2800000, 2900000, 3000000, 155 2700000, 2800000, 2900000, 3000000,
164}; 156};
165 157
166static const int const mc13783_vrf_val[] = { 158static const int mc13783_vrf_val[] = {
167 1500000, 1875000, 2700000, 2775000, 159 1500000, 1875000, 2700000, 2775000,
168}; 160};
169 161
170static const int const mc13783_gpo_val[] = { 162static const int mc13783_gpo_val[] = {
171 3100000, 163 3100000,
172}; 164};
173 165
174static const int const mc13783_pwgtdrv_val[] = { 166static const int mc13783_pwgtdrv_val[] = {
175 5500000, 167 5500000,
176}; 168};
177 169
178static struct regulator_ops mc13783_regulator_ops;
179static struct regulator_ops mc13783_fixed_regulator_ops;
180static struct regulator_ops mc13783_gpo_regulator_ops; 170static struct regulator_ops mc13783_gpo_regulator_ops;
181 171
182#define MC13783_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages) \ 172#define MC13783_DEFINE(prefix, name, reg, vsel_reg, voltages) \
183 [MC13783_ ## prefix ## _ ## _name] = { \ 173 MC13xxx_DEFINE(MC13783_REG_, name, reg, vsel_reg, voltages, \
184 .desc = { \ 174 mc13xxx_regulator_ops)
185 .name = #prefix "_" #_name, \
186 .n_voltages = ARRAY_SIZE(_voltages), \
187 .ops = &mc13783_regulator_ops, \
188 .type = REGULATOR_VOLTAGE, \
189 .id = MC13783_ ## prefix ## _ ## _name, \
190 .owner = THIS_MODULE, \
191 }, \
192 .reg = MC13783_REG_ ## _reg, \
193 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
194 .vsel_reg = MC13783_REG_ ## _vsel_reg, \
195 .vsel_shift = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL,\
196 .vsel_mask = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL_M,\
197 .voltages = _voltages, \
198 }
199 175
200#define MC13783_FIXED_DEFINE(prefix, _name, _reg, _voltages) \ 176#define MC13783_FIXED_DEFINE(prefix, name, reg, voltages) \
201 [MC13783_ ## prefix ## _ ## _name] = { \ 177 MC13xxx_FIXED_DEFINE(MC13783_REG_, name, reg, voltages, \
202 .desc = { \ 178 mc13xxx_fixed_regulator_ops)
203 .name = #prefix "_" #_name, \
204 .n_voltages = ARRAY_SIZE(_voltages), \
205 .ops = &mc13783_fixed_regulator_ops, \
206 .type = REGULATOR_VOLTAGE, \
207 .id = MC13783_ ## prefix ## _ ## _name, \
208 .owner = THIS_MODULE, \
209 }, \
210 .reg = MC13783_REG_ ## _reg, \
211 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
212 .voltages = _voltages, \
213 }
214 179
215#define MC13783_GPO_DEFINE(prefix, _name, _reg, _voltages) \ 180#define MC13783_GPO_DEFINE(prefix, name, reg, voltages) \
216 [MC13783_ ## prefix ## _ ## _name] = { \ 181 MC13xxx_GPO_DEFINE(MC13783_REG_, name, reg, voltages, \
217 .desc = { \ 182 mc13783_gpo_regulator_ops)
218 .name = #prefix "_" #_name, \
219 .n_voltages = ARRAY_SIZE(_voltages), \
220 .ops = &mc13783_gpo_regulator_ops, \
221 .type = REGULATOR_VOLTAGE, \
222 .id = MC13783_ ## prefix ## _ ## _name, \
223 .owner = THIS_MODULE, \
224 }, \
225 .reg = MC13783_REG_ ## _reg, \
226 .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \
227 .voltages = _voltages, \
228 }
229 183
230#define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \ 184#define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \
231 MC13783_DEFINE(SW, _name, _reg, _vsel_reg, _voltages) 185 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages)
232#define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \ 186#define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \
233 MC13783_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages) 187 MC13783_DEFINE(REG, _name, _reg, _vsel_reg, _voltages)
234 188
235static struct mc13783_regulator mc13783_regulators[] = { 189static struct mc13xxx_regulator mc13783_regulators[] = {
236 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), 190 MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val),
237 191
238 MC13783_FIXED_DEFINE(REGU, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), 192 MC13783_FIXED_DEFINE(REG, VAUDIO, REGULATORMODE0, mc13783_vaudio_val),
239 MC13783_FIXED_DEFINE(REGU, VIOHI, REGULATORMODE0, mc13783_viohi_val), 193 MC13783_FIXED_DEFINE(REG, VIOHI, REGULATORMODE0, mc13783_viohi_val),
240 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ 194 MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \
241 mc13783_violo_val), 195 mc13783_violo_val),
242 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ 196 MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \
@@ -255,7 +209,7 @@ static struct mc13783_regulator mc13783_regulators[] = {
255 mc13783_vesim_val), 209 mc13783_vesim_val),
256 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ 210 MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \
257 mc13783_vcam_val), 211 mc13783_vcam_val),
258 MC13783_FIXED_DEFINE(REGU, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), 212 MC13783_FIXED_DEFINE(REG, VRFBG, REGULATORMODE1, mc13783_vrfbg_val),
259 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ 213 MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \
260 mc13783_vvib_val), 214 mc13783_vvib_val),
261 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ 215 MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \
@@ -266,215 +220,24 @@ static struct mc13783_regulator mc13783_regulators[] = {
266 mc13783_vmmc_val), 220 mc13783_vmmc_val),
267 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ 221 MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \
268 mc13783_vmmc_val), 222 mc13783_vmmc_val),
269 MC13783_GPO_DEFINE(REGU, GPO1, POWERMISC, mc13783_gpo_val), 223 MC13783_GPO_DEFINE(REG, GPO1, POWERMISC, mc13783_gpo_val),
270 MC13783_GPO_DEFINE(REGU, GPO2, POWERMISC, mc13783_gpo_val), 224 MC13783_GPO_DEFINE(REG, GPO2, POWERMISC, mc13783_gpo_val),
271 MC13783_GPO_DEFINE(REGU, GPO3, POWERMISC, mc13783_gpo_val), 225 MC13783_GPO_DEFINE(REG, GPO3, POWERMISC, mc13783_gpo_val),
272 MC13783_GPO_DEFINE(REGU, GPO4, POWERMISC, mc13783_gpo_val), 226 MC13783_GPO_DEFINE(REG, GPO4, POWERMISC, mc13783_gpo_val),
273 MC13783_GPO_DEFINE(REGU, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val), 227 MC13783_GPO_DEFINE(REG, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val),
274 MC13783_GPO_DEFINE(REGU, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val), 228 MC13783_GPO_DEFINE(REG, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val),
275};
276
277struct mc13783_regulator_priv {
278 struct mc13783 *mc13783;
279 u32 powermisc_pwgt_state;
280 struct regulator_dev *regulators[];
281};
282
283static int mc13783_regulator_enable(struct regulator_dev *rdev)
284{
285 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
286 int id = rdev_get_id(rdev);
287 int ret;
288
289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
290
291 mc13783_lock(priv->mc13783);
292 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
293 mc13783_regulators[id].enable_bit,
294 mc13783_regulators[id].enable_bit);
295 mc13783_unlock(priv->mc13783);
296
297 return ret;
298}
299
300static int mc13783_regulator_disable(struct regulator_dev *rdev)
301{
302 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
303 int id = rdev_get_id(rdev);
304 int ret;
305
306 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
307
308 mc13783_lock(priv->mc13783);
309 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].reg,
310 mc13783_regulators[id].enable_bit, 0);
311 mc13783_unlock(priv->mc13783);
312
313 return ret;
314}
315
316static int mc13783_regulator_is_enabled(struct regulator_dev *rdev)
317{
318 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
319 int ret, id = rdev_get_id(rdev);
320 unsigned int val;
321
322 mc13783_lock(priv->mc13783);
323 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val);
324 mc13783_unlock(priv->mc13783);
325
326 if (ret)
327 return ret;
328
329 return (val & mc13783_regulators[id].enable_bit) != 0;
330}
331
332static int mc13783_regulator_list_voltage(struct regulator_dev *rdev,
333 unsigned selector)
334{
335 int id = rdev_get_id(rdev);
336
337 if (selector >= mc13783_regulators[id].desc.n_voltages)
338 return -EINVAL;
339
340 return mc13783_regulators[id].voltages[selector];
341}
342
343static int mc13783_get_best_voltage_index(struct regulator_dev *rdev,
344 int min_uV, int max_uV)
345{
346 int reg_id = rdev_get_id(rdev);
347 int i;
348 int bestmatch;
349 int bestindex;
350
351 /*
352 * Locate the minimum voltage fitting the criteria on
353 * this regulator. The switchable voltages are not
354 * in strict falling order so we need to check them
355 * all for the best match.
356 */
357 bestmatch = INT_MAX;
358 bestindex = -1;
359 for (i = 0; i < mc13783_regulators[reg_id].desc.n_voltages; i++) {
360 if (mc13783_regulators[reg_id].voltages[i] >= min_uV &&
361 mc13783_regulators[reg_id].voltages[i] < bestmatch) {
362 bestmatch = mc13783_regulators[reg_id].voltages[i];
363 bestindex = i;
364 }
365 }
366
367 if (bestindex < 0 || bestmatch > max_uV) {
368 dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
369 min_uV, max_uV);
370 return -EINVAL;
371 }
372 return bestindex;
373}
374
375static int mc13783_regulator_set_voltage(struct regulator_dev *rdev,
376 int min_uV, int max_uV)
377{
378 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
379 int value, id = rdev_get_id(rdev);
380 int ret;
381
382 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
383 __func__, id, min_uV, max_uV);
384
385 /* Find the best index */
386 value = mc13783_get_best_voltage_index(rdev, min_uV, max_uV);
387 dev_dbg(rdev_get_dev(rdev), "%s best value: %d \n", __func__, value);
388 if (value < 0)
389 return value;
390
391 mc13783_lock(priv->mc13783);
392 ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].vsel_reg,
393 mc13783_regulators[id].vsel_mask,
394 value << mc13783_regulators[id].vsel_shift);
395 mc13783_unlock(priv->mc13783);
396
397 return ret;
398}
399
400static int mc13783_regulator_get_voltage(struct regulator_dev *rdev)
401{
402 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev);
403 int ret, id = rdev_get_id(rdev);
404 unsigned int val;
405
406 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
407
408 mc13783_lock(priv->mc13783);
409 ret = mc13783_reg_read(priv->mc13783,
410 mc13783_regulators[id].vsel_reg, &val);
411 mc13783_unlock(priv->mc13783);
412
413 if (ret)
414 return ret;
415
416 val = (val & mc13783_regulators[id].vsel_mask)
417 >> mc13783_regulators[id].vsel_shift;
418
419 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
420
421 BUG_ON(val < 0 || val > mc13783_regulators[id].desc.n_voltages);
422
423 return mc13783_regulators[id].voltages[val];
424}
425
426static struct regulator_ops mc13783_regulator_ops = {
427 .enable = mc13783_regulator_enable,
428 .disable = mc13783_regulator_disable,
429 .is_enabled = mc13783_regulator_is_enabled,
430 .list_voltage = mc13783_regulator_list_voltage,
431 .set_voltage = mc13783_regulator_set_voltage,
432 .get_voltage = mc13783_regulator_get_voltage,
433};
434
435static int mc13783_fixed_regulator_set_voltage(struct regulator_dev *rdev,
436 int min_uV, int max_uV)
437{
438 int id = rdev_get_id(rdev);
439
440 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
441 __func__, id, min_uV, max_uV);
442
443 if (min_uV >= mc13783_regulators[id].voltages[0] &&
444 max_uV <= mc13783_regulators[id].voltages[0])
445 return 0;
446 else
447 return -EINVAL;
448}
449
450static int mc13783_fixed_regulator_get_voltage(struct regulator_dev *rdev)
451{
452 int id = rdev_get_id(rdev);
453
454 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
455
456 return mc13783_regulators[id].voltages[0];
457}
458
459static struct regulator_ops mc13783_fixed_regulator_ops = {
460 .enable = mc13783_regulator_enable,
461 .disable = mc13783_regulator_disable,
462 .is_enabled = mc13783_regulator_is_enabled,
463 .list_voltage = mc13783_regulator_list_voltage,
464 .set_voltage = mc13783_fixed_regulator_set_voltage,
465 .get_voltage = mc13783_fixed_regulator_get_voltage,
466}; 229};
467 230
468static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, 231static int mc13783_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
469 u32 val) 232 u32 val)
470{ 233{
471 struct mc13783 *mc13783 = priv->mc13783; 234 struct mc13xxx *mc13783 = priv->mc13xxx;
472 int ret; 235 int ret;
473 u32 valread; 236 u32 valread;
474 237
475 BUG_ON(val & ~mask); 238 BUG_ON(val & ~mask);
476 239
477 ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); 240 ret = mc13xxx_reg_read(mc13783, MC13783_REG_POWERMISC, &valread);
478 if (ret) 241 if (ret)
479 return ret; 242 return ret;
480 243
@@ -489,34 +252,36 @@ static int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask,
489 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 252 valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
490 priv->powermisc_pwgt_state; 253 priv->powermisc_pwgt_state;
491 254
492 return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread); 255 return mc13xxx_reg_write(mc13783, MC13783_REG_POWERMISC, valread);
493} 256}
494 257
495static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) 258static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev)
496{ 259{
497 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 260 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
261 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
498 int id = rdev_get_id(rdev); 262 int id = rdev_get_id(rdev);
499 int ret; 263 int ret;
500 u32 en_val = mc13783_regulators[id].enable_bit; 264 u32 en_val = mc13xxx_regulators[id].enable_bit;
501 265
502 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 266 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
503 267
504 /* Power Gate enable value is 0 */ 268 /* Power Gate enable value is 0 */
505 if (id == MC13783_REGU_PWGT1SPI || 269 if (id == MC13783_REG_PWGT1SPI ||
506 id == MC13783_REGU_PWGT2SPI) 270 id == MC13783_REG_PWGT2SPI)
507 en_val = 0; 271 en_val = 0;
508 272
509 mc13783_lock(priv->mc13783); 273 mc13xxx_lock(priv->mc13xxx);
510 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, 274 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
511 en_val); 275 en_val);
512 mc13783_unlock(priv->mc13783); 276 mc13xxx_unlock(priv->mc13xxx);
513 277
514 return ret; 278 return ret;
515} 279}
516 280
517static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) 281static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
518{ 282{
519 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 283 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
284 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
520 int id = rdev_get_id(rdev); 285 int id = rdev_get_id(rdev);
521 int ret; 286 int ret;
522 u32 dis_val = 0; 287 u32 dis_val = 0;
@@ -524,27 +289,28 @@ static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev)
524 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); 289 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
525 290
526 /* Power Gate disable value is 1 */ 291 /* Power Gate disable value is 1 */
527 if (id == MC13783_REGU_PWGT1SPI || 292 if (id == MC13783_REG_PWGT1SPI ||
528 id == MC13783_REGU_PWGT2SPI) 293 id == MC13783_REG_PWGT2SPI)
529 dis_val = mc13783_regulators[id].enable_bit; 294 dis_val = mc13xxx_regulators[id].enable_bit;
530 295
531 mc13783_lock(priv->mc13783); 296 mc13xxx_lock(priv->mc13xxx);
532 ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, 297 ret = mc13783_powermisc_rmw(priv, mc13xxx_regulators[id].enable_bit,
533 dis_val); 298 dis_val);
534 mc13783_unlock(priv->mc13783); 299 mc13xxx_unlock(priv->mc13xxx);
535 300
536 return ret; 301 return ret;
537} 302}
538 303
539static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) 304static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
540{ 305{
541 struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); 306 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
307 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
542 int ret, id = rdev_get_id(rdev); 308 int ret, id = rdev_get_id(rdev);
543 unsigned int val; 309 unsigned int val;
544 310
545 mc13783_lock(priv->mc13783); 311 mc13xxx_lock(priv->mc13xxx);
546 ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); 312 ret = mc13xxx_reg_read(priv->mc13xxx, mc13xxx_regulators[id].reg, &val);
547 mc13783_unlock(priv->mc13783); 313 mc13xxx_unlock(priv->mc13xxx);
548 314
549 if (ret) 315 if (ret)
550 return ret; 316 return ret;
@@ -554,22 +320,22 @@ static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev)
554 val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) | 320 val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) |
555 (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M); 321 (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M);
556 322
557 return (val & mc13783_regulators[id].enable_bit) != 0; 323 return (val & mc13xxx_regulators[id].enable_bit) != 0;
558} 324}
559 325
560static struct regulator_ops mc13783_gpo_regulator_ops = { 326static struct regulator_ops mc13783_gpo_regulator_ops = {
561 .enable = mc13783_gpo_regulator_enable, 327 .enable = mc13783_gpo_regulator_enable,
562 .disable = mc13783_gpo_regulator_disable, 328 .disable = mc13783_gpo_regulator_disable,
563 .is_enabled = mc13783_gpo_regulator_is_enabled, 329 .is_enabled = mc13783_gpo_regulator_is_enabled,
564 .list_voltage = mc13783_regulator_list_voltage, 330 .list_voltage = mc13xxx_regulator_list_voltage,
565 .set_voltage = mc13783_fixed_regulator_set_voltage, 331 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
566 .get_voltage = mc13783_fixed_regulator_get_voltage, 332 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
567}; 333};
568 334
569static int __devinit mc13783_regulator_probe(struct platform_device *pdev) 335static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
570{ 336{
571 struct mc13783_regulator_priv *priv; 337 struct mc13xxx_regulator_priv *priv;
572 struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent); 338 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
573 struct mc13783_regulator_platform_data *pdata = 339 struct mc13783_regulator_platform_data *pdata =
574 dev_get_platdata(&pdev->dev); 340 dev_get_platdata(&pdev->dev);
575 struct mc13783_regulator_init_data *init_data; 341 struct mc13783_regulator_init_data *init_data;
@@ -583,7 +349,8 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
583 if (!priv) 349 if (!priv)
584 return -ENOMEM; 350 return -ENOMEM;
585 351
586 priv->mc13783 = mc13783; 352 priv->mc13xxx_regulators = mc13783_regulators;
353 priv->mc13xxx = mc13783;
587 354
588 for (i = 0; i < pdata->num_regulators; i++) { 355 for (i = 0; i < pdata->num_regulators; i++) {
589 init_data = &pdata->regulators[i]; 356 init_data = &pdata->regulators[i];
@@ -613,7 +380,7 @@ err:
613 380
614static int __devexit mc13783_regulator_remove(struct platform_device *pdev) 381static int __devexit mc13783_regulator_remove(struct platform_device *pdev)
615{ 382{
616 struct mc13783_regulator_priv *priv = platform_get_drvdata(pdev); 383 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
617 struct mc13783_regulator_platform_data *pdata = 384 struct mc13783_regulator_platform_data *pdata =
618 dev_get_platdata(&pdev->dev); 385 dev_get_platdata(&pdev->dev);
619 int i; 386 int i;
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
new file mode 100644
index 000000000000..1b8f7398a4a8
--- /dev/null
+++ b/drivers/regulator/mc13892-regulator.c
@@ -0,0 +1,635 @@
1/*
2 * Regulator Driver for Freescale MC13892 PMIC
3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * Based on draft driver from Arnaud Patard <arnaud.patard@rtp-net.org>
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
13#include <linux/mfd/mc13892.h>
14#include <linux/regulator/machine.h>
15#include <linux/regulator/driver.h>
16#include <linux/platform_device.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/err.h>
21#include "mc13xxx.h"
22
23#define MC13892_REVISION 7
24
25#define MC13892_POWERCTL0 13
26#define MC13892_POWERCTL0_USEROFFSPI 3
27#define MC13892_POWERCTL0_VCOINCELLVSEL 20
28#define MC13892_POWERCTL0_VCOINCELLVSEL_M (7<<20)
29#define MC13892_POWERCTL0_VCOINCELLEN (1<<23)
30
31#define MC13892_SWITCHERS0_SWxHI (1<<23)
32
33#define MC13892_SWITCHERS0 24
34#define MC13892_SWITCHERS0_SW1VSEL 0
35#define MC13892_SWITCHERS0_SW1VSEL_M (0x1f<<0)
36#define MC13892_SWITCHERS0_SW1HI (1<<23)
37#define MC13892_SWITCHERS0_SW1EN 0
38
39#define MC13892_SWITCHERS1 25
40#define MC13892_SWITCHERS1_SW2VSEL 0
41#define MC13892_SWITCHERS1_SW2VSEL_M (0x1f<<0)
42#define MC13892_SWITCHERS1_SW2HI (1<<23)
43#define MC13892_SWITCHERS1_SW2EN 0
44
45#define MC13892_SWITCHERS2 26
46#define MC13892_SWITCHERS2_SW3VSEL 0
47#define MC13892_SWITCHERS2_SW3VSEL_M (0x1f<<0)
48#define MC13892_SWITCHERS2_SW3HI (1<<23)
49#define MC13892_SWITCHERS2_SW3EN 0
50
51#define MC13892_SWITCHERS3 27
52#define MC13892_SWITCHERS3_SW4VSEL 0
53#define MC13892_SWITCHERS3_SW4VSEL_M (0x1f<<0)
54#define MC13892_SWITCHERS3_SW4HI (1<<23)
55#define MC13892_SWITCHERS3_SW4EN 0
56
57#define MC13892_SWITCHERS4 28
58#define MC13892_SWITCHERS4_SW1MODE 0
59#define MC13892_SWITCHERS4_SW1MODE_AUTO (8<<0)
60#define MC13892_SWITCHERS4_SW1MODE_M (0xf<<0)
61#define MC13892_SWITCHERS4_SW2MODE 10
62#define MC13892_SWITCHERS4_SW2MODE_AUTO (8<<10)
63#define MC13892_SWITCHERS4_SW2MODE_M (0xf<<10)
64
65#define MC13892_SWITCHERS5 29
66#define MC13892_SWITCHERS5_SW3MODE 0
67#define MC13892_SWITCHERS5_SW3MODE_AUTO (8<<0)
68#define MC13892_SWITCHERS5_SW3MODE_M (0xf<<0)
69#define MC13892_SWITCHERS5_SW4MODE 8
70#define MC13892_SWITCHERS5_SW4MODE_AUTO (8<<8)
71#define MC13892_SWITCHERS5_SW4MODE_M (0xf<<8)
72#define MC13892_SWITCHERS5_SWBSTEN (1<<20)
73
74#define MC13892_REGULATORSETTING0 30
75#define MC13892_REGULATORSETTING0_VGEN1VSEL 0
76#define MC13892_REGULATORSETTING0_VDIGVSEL 4
77#define MC13892_REGULATORSETTING0_VGEN2VSEL 6
78#define MC13892_REGULATORSETTING0_VPLLVSEL 9
79#define MC13892_REGULATORSETTING0_VUSB2VSEL 11
80#define MC13892_REGULATORSETTING0_VGEN3VSEL 14
81#define MC13892_REGULATORSETTING0_VCAMVSEL 16
82
83#define MC13892_REGULATORSETTING0_VGEN1VSEL_M (3<<0)
84#define MC13892_REGULATORSETTING0_VDIGVSEL_M (3<<4)
85#define MC13892_REGULATORSETTING0_VGEN2VSEL_M (7<<6)
86#define MC13892_REGULATORSETTING0_VPLLVSEL_M (3<<9)
87#define MC13892_REGULATORSETTING0_VUSB2VSEL_M (3<<11)
88#define MC13892_REGULATORSETTING0_VGEN3VSEL_M (1<<14)
89#define MC13892_REGULATORSETTING0_VCAMVSEL_M (3<<16)
90
91#define MC13892_REGULATORSETTING1 31
92#define MC13892_REGULATORSETTING1_VVIDEOVSEL 2
93#define MC13892_REGULATORSETTING1_VAUDIOVSEL 4
94#define MC13892_REGULATORSETTING1_VSDVSEL 6
95
96#define MC13892_REGULATORSETTING1_VVIDEOVSEL_M (3<<2)
97#define MC13892_REGULATORSETTING1_VAUDIOVSEL_M (3<<4)
98#define MC13892_REGULATORSETTING1_VSDVSEL_M (7<<6)
99
100#define MC13892_REGULATORMODE0 32
101#define MC13892_REGULATORMODE0_VGEN1EN (1<<0)
102#define MC13892_REGULATORMODE0_VGEN1STDBY (1<<1)
103#define MC13892_REGULATORMODE0_VGEN1MODE (1<<2)
104#define MC13892_REGULATORMODE0_VIOHIEN (1<<3)
105#define MC13892_REGULATORMODE0_VIOHISTDBY (1<<4)
106#define MC13892_REGULATORMODE0_VIOHIMODE (1<<5)
107#define MC13892_REGULATORMODE0_VDIGEN (1<<9)
108#define MC13892_REGULATORMODE0_VDIGSTDBY (1<<10)
109#define MC13892_REGULATORMODE0_VDIGMODE (1<<11)
110#define MC13892_REGULATORMODE0_VGEN2EN (1<<12)
111#define MC13892_REGULATORMODE0_VGEN2STDBY (1<<13)
112#define MC13892_REGULATORMODE0_VGEN2MODE (1<<14)
113#define MC13892_REGULATORMODE0_VPLLEN (1<<15)
114#define MC13892_REGULATORMODE0_VPLLSTDBY (1<<16)
115#define MC13892_REGULATORMODE0_VPLLMODE (1<<17)
116#define MC13892_REGULATORMODE0_VUSB2EN (1<<18)
117#define MC13892_REGULATORMODE0_VUSB2STDBY (1<<19)
118#define MC13892_REGULATORMODE0_VUSB2MODE (1<<20)
119
120#define MC13892_REGULATORMODE1 33
121#define MC13892_REGULATORMODE1_VGEN3EN (1<<0)
122#define MC13892_REGULATORMODE1_VGEN3STDBY (1<<1)
123#define MC13892_REGULATORMODE1_VGEN3MODE (1<<2)
124#define MC13892_REGULATORMODE1_VCAMEN (1<<6)
125#define MC13892_REGULATORMODE1_VCAMSTDBY (1<<7)
126#define MC13892_REGULATORMODE1_VCAMMODE (1<<8)
127#define MC13892_REGULATORMODE1_VCAMCONFIGEN (1<<9)
128#define MC13892_REGULATORMODE1_VVIDEOEN (1<<12)
129#define MC13892_REGULATORMODE1_VVIDEOSTDBY (1<<13)
130#define MC13892_REGULATORMODE1_VVIDEOMODE (1<<14)
131#define MC13892_REGULATORMODE1_VAUDIOEN (1<<15)
132#define MC13892_REGULATORMODE1_VAUDIOSTDBY (1<<16)
133#define MC13892_REGULATORMODE1_VAUDIOMODE (1<<17)
134#define MC13892_REGULATORMODE1_VSDEN (1<<18)
135#define MC13892_REGULATORMODE1_VSDSTDBY (1<<19)
136#define MC13892_REGULATORMODE1_VSDMODE (1<<20)
137
138#define MC13892_POWERMISC 34
139#define MC13892_POWERMISC_GPO1EN (1<<6)
140#define MC13892_POWERMISC_GPO2EN (1<<8)
141#define MC13892_POWERMISC_GPO3EN (1<<10)
142#define MC13892_POWERMISC_GPO4EN (1<<12)
143#define MC13892_POWERMISC_PWGT1SPIEN (1<<15)
144#define MC13892_POWERMISC_PWGT2SPIEN (1<<16)
145#define MC13892_POWERMISC_GPO4ADINEN (1<<21)
146
147#define MC13892_POWERMISC_PWGTSPI_M (3 << 15)
148
149#define MC13892_USB1 50
150#define MC13892_USB1_VUSBEN (1<<3)
151
152static const int mc13892_vcoincell[] = {
153 2500000, 2700000, 2800000, 2900000, 3000000, 3100000,
154 3200000, 3300000,
155};
156
157static const int mc13892_sw1[] = {
158 600000, 625000, 650000, 675000, 700000, 725000,
159 750000, 775000, 800000, 825000, 850000, 875000,
160 900000, 925000, 950000, 975000, 1000000, 1025000,
161 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
162 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
163 1350000, 1375000
164};
165
166static const int mc13892_sw[] = {
167 600000, 625000, 650000, 675000, 700000, 725000,
168 750000, 775000, 800000, 825000, 850000, 875000,
169 900000, 925000, 950000, 975000, 1000000, 1025000,
170 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
171 1200000, 1225000, 1250000, 1275000, 1300000, 1325000,
172 1350000, 1375000, 1400000, 1425000, 1450000, 1475000,
173 1500000, 1525000, 1550000, 1575000, 1600000, 1625000,
174 1650000, 1675000, 1700000, 1725000, 1750000, 1775000,
175 1800000, 1825000, 1850000, 1875000
176};
177
178static const int mc13892_swbst[] = {
179 5000000,
180};
181
182static const int mc13892_viohi[] = {
183 2775000,
184};
185
186static const int mc13892_vpll[] = {
187 1050000, 1250000, 1650000, 1800000,
188};
189
190static const int mc13892_vdig[] = {
191 1050000, 1250000, 1650000, 1800000,
192};
193
194static const int mc13892_vsd[] = {
195 1800000, 2000000, 2600000, 2700000,
196 2800000, 2900000, 3000000, 3150000,
197};
198
199static const int mc13892_vusb2[] = {
200 2400000, 2600000, 2700000, 2775000,
201};
202
203static const int mc13892_vvideo[] = {
204 2700000, 2775000, 2500000, 2600000,
205};
206
207static const int mc13892_vaudio[] = {
208 2300000, 2500000, 2775000, 3000000,
209};
210
211static const int mc13892_vcam[] = {
212 2500000, 2600000, 2750000, 3000000,
213};
214
215static const int mc13892_vgen1[] = {
216 1200000, 1500000, 2775000, 3150000,
217};
218
219static const int mc13892_vgen2[] = {
220 1200000, 1500000, 1600000, 1800000,
221 2700000, 2800000, 3000000, 3150000,
222};
223
224static const int mc13892_vgen3[] = {
225 1800000, 2900000,
226};
227
228static const int mc13892_vusb[] = {
229 3300000,
230};
231
232static const int mc13892_gpo[] = {
233 2750000,
234};
235
236static const int mc13892_pwgtdrv[] = {
237 5000000,
238};
239
240static struct regulator_ops mc13892_gpo_regulator_ops;
241/* sw regulators need special care due to the "hi bit" */
242static struct regulator_ops mc13892_sw_regulator_ops;
243
244
245#define MC13892_FIXED_DEFINE(name, reg, voltages) \
246 MC13xxx_FIXED_DEFINE(MC13892_, name, reg, voltages, \
247 mc13xxx_fixed_regulator_ops)
248
249#define MC13892_GPO_DEFINE(name, reg, voltages) \
250 MC13xxx_GPO_DEFINE(MC13892_, name, reg, voltages, \
251 mc13892_gpo_regulator_ops)
252
253#define MC13892_SW_DEFINE(name, reg, vsel_reg, voltages) \
254 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
255 mc13892_sw_regulator_ops)
256
257#define MC13892_DEFINE_REGU(name, reg, vsel_reg, voltages) \
258 MC13xxx_DEFINE(MC13892_, name, reg, vsel_reg, voltages, \
259 mc13xxx_regulator_ops)
260
261static struct mc13xxx_regulator mc13892_regulators[] = {
262 MC13892_DEFINE_REGU(VCOINCELL, POWERCTL0, POWERCTL0, mc13892_vcoincell),
263 MC13892_SW_DEFINE(SW1, SWITCHERS0, SWITCHERS0, mc13892_sw1),
264 MC13892_SW_DEFINE(SW2, SWITCHERS1, SWITCHERS1, mc13892_sw),
265 MC13892_SW_DEFINE(SW3, SWITCHERS2, SWITCHERS2, mc13892_sw),
266 MC13892_SW_DEFINE(SW4, SWITCHERS3, SWITCHERS3, mc13892_sw),
267 MC13892_FIXED_DEFINE(SWBST, SWITCHERS5, mc13892_swbst),
268 MC13892_FIXED_DEFINE(VIOHI, REGULATORMODE0, mc13892_viohi),
269 MC13892_DEFINE_REGU(VPLL, REGULATORMODE0, REGULATORSETTING0, \
270 mc13892_vpll),
271 MC13892_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \
272 mc13892_vdig),
273 MC13892_DEFINE_REGU(VSD, REGULATORMODE1, REGULATORSETTING1, \
274 mc13892_vsd),
275 MC13892_DEFINE_REGU(VUSB2, REGULATORMODE0, REGULATORSETTING0, \
276 mc13892_vusb2),
277 MC13892_DEFINE_REGU(VVIDEO, REGULATORMODE1, REGULATORSETTING1, \
278 mc13892_vvideo),
279 MC13892_DEFINE_REGU(VAUDIO, REGULATORMODE1, REGULATORSETTING1, \
280 mc13892_vaudio),
281 MC13892_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \
282 mc13892_vcam),
283 MC13892_DEFINE_REGU(VGEN1, REGULATORMODE0, REGULATORSETTING0, \
284 mc13892_vgen1),
285 MC13892_DEFINE_REGU(VGEN2, REGULATORMODE0, REGULATORSETTING0, \
286 mc13892_vgen2),
287 MC13892_DEFINE_REGU(VGEN3, REGULATORMODE1, REGULATORSETTING0, \
288 mc13892_vgen3),
289 MC13892_FIXED_DEFINE(VUSB, USB1, mc13892_vusb),
290 MC13892_GPO_DEFINE(GPO1, POWERMISC, mc13892_gpo),
291 MC13892_GPO_DEFINE(GPO2, POWERMISC, mc13892_gpo),
292 MC13892_GPO_DEFINE(GPO3, POWERMISC, mc13892_gpo),
293 MC13892_GPO_DEFINE(GPO4, POWERMISC, mc13892_gpo),
294 MC13892_GPO_DEFINE(PWGT1SPI, POWERMISC, mc13892_pwgtdrv),
295 MC13892_GPO_DEFINE(PWGT2SPI, POWERMISC, mc13892_pwgtdrv),
296};
297
298static int mc13892_powermisc_rmw(struct mc13xxx_regulator_priv *priv, u32 mask,
299 u32 val)
300{
301 struct mc13xxx *mc13892 = priv->mc13xxx;
302 int ret;
303 u32 valread;
304
305 BUG_ON(val & ~mask);
306
307 ret = mc13xxx_reg_read(mc13892, MC13892_POWERMISC, &valread);
308 if (ret)
309 return ret;
310
311 /* Update the stored state for Power Gates. */
312 priv->powermisc_pwgt_state =
313 (priv->powermisc_pwgt_state & ~mask) | val;
314 priv->powermisc_pwgt_state &= MC13892_POWERMISC_PWGTSPI_M;
315
316 /* Construct the new register value */
317 valread = (valread & ~mask) | val;
318 /* Overwrite the PWGTxEN with the stored version */
319 valread = (valread & ~MC13892_POWERMISC_PWGTSPI_M) |
320 priv->powermisc_pwgt_state;
321
322 return mc13xxx_reg_write(mc13892, MC13892_POWERMISC, valread);
323}
324
325static int mc13892_gpo_regulator_enable(struct regulator_dev *rdev)
326{
327 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
328 int id = rdev_get_id(rdev);
329 int ret;
330 u32 en_val = mc13892_regulators[id].enable_bit;
331 u32 mask = mc13892_regulators[id].enable_bit;
332
333 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
334
335 /* Power Gate enable value is 0 */
336 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI)
337 en_val = 0;
338
339 if (id == MC13892_GPO4)
340 mask |= MC13892_POWERMISC_GPO4ADINEN;
341
342 mc13xxx_lock(priv->mc13xxx);
343 ret = mc13892_powermisc_rmw(priv, mask, en_val);
344 mc13xxx_unlock(priv->mc13xxx);
345
346 return ret;
347}
348
349static int mc13892_gpo_regulator_disable(struct regulator_dev *rdev)
350{
351 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
352 int id = rdev_get_id(rdev);
353 int ret;
354 u32 dis_val = 0;
355
356 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
357
358 /* Power Gate disable value is 1 */
359 if (id == MC13892_PWGT1SPI || id == MC13892_PWGT2SPI)
360 dis_val = mc13892_regulators[id].enable_bit;
361
362 mc13xxx_lock(priv->mc13xxx);
363 ret = mc13892_powermisc_rmw(priv, mc13892_regulators[id].enable_bit,
364 dis_val);
365 mc13xxx_unlock(priv->mc13xxx);
366
367 return ret;
368}
369
370static int mc13892_gpo_regulator_is_enabled(struct regulator_dev *rdev)
371{
372 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
373 int ret, id = rdev_get_id(rdev);
374 unsigned int val;
375
376 mc13xxx_lock(priv->mc13xxx);
377 ret = mc13xxx_reg_read(priv->mc13xxx, mc13892_regulators[id].reg, &val);
378 mc13xxx_unlock(priv->mc13xxx);
379
380 if (ret)
381 return ret;
382
383 /* Power Gates state is stored in powermisc_pwgt_state
384 * where the meaning of bits is negated */
385 val = (val & ~MC13892_POWERMISC_PWGTSPI_M) |
386 (priv->powermisc_pwgt_state ^ MC13892_POWERMISC_PWGTSPI_M);
387
388 return (val & mc13892_regulators[id].enable_bit) != 0;
389}
390
391
392static struct regulator_ops mc13892_gpo_regulator_ops = {
393 .enable = mc13892_gpo_regulator_enable,
394 .disable = mc13892_gpo_regulator_disable,
395 .is_enabled = mc13892_gpo_regulator_is_enabled,
396 .list_voltage = mc13xxx_regulator_list_voltage,
397 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
398 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
399};
400
401static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
402{
403 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
404 int ret, id = rdev_get_id(rdev);
405 unsigned int val, hi;
406
407 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
408
409 mc13xxx_lock(priv->mc13xxx);
410 ret = mc13xxx_reg_read(priv->mc13xxx,
411 mc13892_regulators[id].vsel_reg, &val);
412 mc13xxx_unlock(priv->mc13xxx);
413 if (ret)
414 return ret;
415
416 hi = val & MC13892_SWITCHERS0_SWxHI;
417 val = (val & mc13892_regulators[id].vsel_mask)
418 >> mc13892_regulators[id].vsel_shift;
419
420 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
421
422 if (hi)
423 val = (25000 * val) + 1100000;
424 else
425 val = (25000 * val) + 600000;
426
427 return val;
428}
429
430static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev,
431 int min_uV, int max_uV, unsigned *selector)
432{
433 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
434 int hi, value, val, mask, id = rdev_get_id(rdev);
435 int ret;
436
437 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
438 __func__, id, min_uV, max_uV);
439
440 /* Find the best index */
441 value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
442 dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
443 if (value < 0)
444 return value;
445
446 value = mc13892_regulators[id].voltages[value];
447
448 mc13xxx_lock(priv->mc13xxx);
449 ret = mc13xxx_reg_read(priv->mc13xxx,
450 mc13892_regulators[id].vsel_reg, &val);
451 if (ret)
452 goto err;
453
454 hi = val & MC13892_SWITCHERS0_SWxHI;
455 if (value > 1375)
456 hi = 1;
457 if (value < 1100)
458 hi = 0;
459
460 if (hi) {
461 value = (value - 1100000) / 25000;
462 value |= MC13892_SWITCHERS0_SWxHI;
463 } else
464 value = (value - 600000) / 25000;
465
466 mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI;
467 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg,
468 mask, value << mc13892_regulators[id].vsel_shift);
469err:
470 mc13xxx_unlock(priv->mc13xxx);
471
472 return ret;
473}
474
475static struct regulator_ops mc13892_sw_regulator_ops = {
476 .is_enabled = mc13xxx_sw_regulator_is_enabled,
477 .list_voltage = mc13xxx_regulator_list_voltage,
478 .set_voltage = mc13892_sw_regulator_set_voltage,
479 .get_voltage = mc13892_sw_regulator_get_voltage,
480};
481
482static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode)
483{
484 unsigned int en_val = 0;
485 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
486 int ret, id = rdev_get_id(rdev);
487
488 if (mode == REGULATOR_MODE_FAST)
489 en_val = MC13892_REGULATORMODE1_VCAMCONFIGEN;
490
491 mc13xxx_lock(priv->mc13xxx);
492 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg,
493 MC13892_REGULATORMODE1_VCAMCONFIGEN, en_val);
494 mc13xxx_unlock(priv->mc13xxx);
495
496 return ret;
497}
498
499static unsigned int mc13892_vcam_get_mode(struct regulator_dev *rdev)
500{
501 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
502 int ret, id = rdev_get_id(rdev);
503 unsigned int val;
504
505 mc13xxx_lock(priv->mc13xxx);
506 ret = mc13xxx_reg_read(priv->mc13xxx, mc13892_regulators[id].reg, &val);
507 mc13xxx_unlock(priv->mc13xxx);
508
509 if (ret)
510 return ret;
511
512 if (val & MC13892_REGULATORMODE1_VCAMCONFIGEN)
513 return REGULATOR_MODE_FAST;
514
515 return REGULATOR_MODE_NORMAL;
516}
517
518
519static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
520{
521 struct mc13xxx_regulator_priv *priv;
522 struct mc13xxx *mc13892 = dev_get_drvdata(pdev->dev.parent);
523 struct mc13xxx_regulator_platform_data *pdata =
524 dev_get_platdata(&pdev->dev);
525 struct mc13xxx_regulator_init_data *init_data;
526 int i, ret;
527 u32 val;
528
529 priv = kzalloc(sizeof(*priv) +
530 pdata->num_regulators * sizeof(priv->regulators[0]),
531 GFP_KERNEL);
532 if (!priv)
533 return -ENOMEM;
534
535 priv->mc13xxx_regulators = mc13892_regulators;
536 priv->mc13xxx = mc13892;
537
538 mc13xxx_lock(mc13892);
539 ret = mc13xxx_reg_read(mc13892, MC13892_REVISION, &val);
540 if (ret)
541 goto err_free;
542
543 /* enable switch auto mode */
544 if ((val & 0x0000FFFF) == 0x45d0) {
545 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4,
546 MC13892_SWITCHERS4_SW1MODE_M |
547 MC13892_SWITCHERS4_SW2MODE_M,
548 MC13892_SWITCHERS4_SW1MODE_AUTO |
549 MC13892_SWITCHERS4_SW2MODE_AUTO);
550 if (ret)
551 goto err_free;
552
553 ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS5,
554 MC13892_SWITCHERS5_SW3MODE_M |
555 MC13892_SWITCHERS5_SW4MODE_M,
556 MC13892_SWITCHERS5_SW3MODE_AUTO |
557 MC13892_SWITCHERS5_SW4MODE_AUTO);
558 if (ret)
559 goto err_free;
560 }
561 mc13xxx_unlock(mc13892);
562
563 mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
564 = mc13892_vcam_set_mode;
565 mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
566 = mc13892_vcam_get_mode;
567 for (i = 0; i < pdata->num_regulators; i++) {
568 init_data = &pdata->regulators[i];
569 priv->regulators[i] = regulator_register(
570 &mc13892_regulators[init_data->id].desc,
571 &pdev->dev, init_data->init_data, priv);
572
573 if (IS_ERR(priv->regulators[i])) {
574 dev_err(&pdev->dev, "failed to register regulator %s\n",
575 mc13892_regulators[i].desc.name);
576 ret = PTR_ERR(priv->regulators[i]);
577 goto err;
578 }
579 }
580
581 platform_set_drvdata(pdev, priv);
582
583 return 0;
584err:
585 while (--i >= 0)
586 regulator_unregister(priv->regulators[i]);
587
588err_free:
589 mc13xxx_unlock(mc13892);
590 kfree(priv);
591
592 return ret;
593}
594
595static int __devexit mc13892_regulator_remove(struct platform_device *pdev)
596{
597 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
598 struct mc13xxx_regulator_platform_data *pdata =
599 dev_get_platdata(&pdev->dev);
600 int i;
601
602 platform_set_drvdata(pdev, NULL);
603
604 for (i = 0; i < pdata->num_regulators; i++)
605 regulator_unregister(priv->regulators[i]);
606
607 kfree(priv);
608 return 0;
609}
610
611static struct platform_driver mc13892_regulator_driver = {
612 .driver = {
613 .name = "mc13892-regulator",
614 .owner = THIS_MODULE,
615 },
616 .remove = __devexit_p(mc13892_regulator_remove),
617 .probe = mc13892_regulator_probe,
618};
619
620static int __init mc13892_regulator_init(void)
621{
622 return platform_driver_register(&mc13892_regulator_driver);
623}
624subsys_initcall(mc13892_regulator_init);
625
626static void __exit mc13892_regulator_exit(void)
627{
628 platform_driver_unregister(&mc13892_regulator_driver);
629}
630module_exit(mc13892_regulator_exit);
631
632MODULE_LICENSE("GPL v2");
633MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>");
634MODULE_DESCRIPTION("Regulator Driver for Freescale MC13892 PMIC");
635MODULE_ALIAS("platform:mc13892-regulator");
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
new file mode 100644
index 000000000000..f53d31b950d4
--- /dev/null
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -0,0 +1,241 @@
1/*
2 * Regulator Driver for Freescale MC13xxx PMIC
3 *
4 * Copyright 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * Based on mc13783 regulator driver :
7 * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
8 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Regs infos taken from mc13xxx drivers from freescale and mc13xxx.pdf file
15 * from freescale
16 */
17
18#include <linux/mfd/mc13xxx.h>
19#include <linux/regulator/machine.h>
20#include <linux/regulator/driver.h>
21#include <linux/platform_device.h>
22#include <linux/kernel.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <linux/err.h>
26#include "mc13xxx.h"
27
28static int mc13xxx_regulator_enable(struct regulator_dev *rdev)
29{
30 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
31 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
32 int id = rdev_get_id(rdev);
33 int ret;
34
35 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
36
37 mc13xxx_lock(priv->mc13xxx);
38 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].reg,
39 mc13xxx_regulators[id].enable_bit,
40 mc13xxx_regulators[id].enable_bit);
41 mc13xxx_unlock(priv->mc13xxx);
42
43 return ret;
44}
45
46static int mc13xxx_regulator_disable(struct regulator_dev *rdev)
47{
48 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
49 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
50 int id = rdev_get_id(rdev);
51 int ret;
52
53 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
54
55 mc13xxx_lock(priv->mc13xxx);
56 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].reg,
57 mc13xxx_regulators[id].enable_bit, 0);
58 mc13xxx_unlock(priv->mc13xxx);
59
60 return ret;
61}
62
63static int mc13xxx_regulator_is_enabled(struct regulator_dev *rdev)
64{
65 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
66 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
67 int ret, id = rdev_get_id(rdev);
68 unsigned int val;
69
70 mc13xxx_lock(priv->mc13xxx);
71 ret = mc13xxx_reg_read(priv->mc13xxx, mc13xxx_regulators[id].reg, &val);
72 mc13xxx_unlock(priv->mc13xxx);
73
74 if (ret)
75 return ret;
76
77 return (val & mc13xxx_regulators[id].enable_bit) != 0;
78}
79
80int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
81 unsigned selector)
82{
83 int id = rdev_get_id(rdev);
84 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
85 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
86
87 if (selector >= mc13xxx_regulators[id].desc.n_voltages)
88 return -EINVAL;
89
90 return mc13xxx_regulators[id].voltages[selector];
91}
92EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage);
93
94int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
95 int min_uV, int max_uV)
96{
97 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
98 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
99 int reg_id = rdev_get_id(rdev);
100 int i;
101 int bestmatch;
102 int bestindex;
103
104 /*
105 * Locate the minimum voltage fitting the criteria on
106 * this regulator. The switchable voltages are not
107 * in strict falling order so we need to check them
108 * all for the best match.
109 */
110 bestmatch = INT_MAX;
111 bestindex = -1;
112 for (i = 0; i < mc13xxx_regulators[reg_id].desc.n_voltages; i++) {
113 if (mc13xxx_regulators[reg_id].voltages[i] >= min_uV &&
114 mc13xxx_regulators[reg_id].voltages[i] < bestmatch) {
115 bestmatch = mc13xxx_regulators[reg_id].voltages[i];
116 bestindex = i;
117 }
118 }
119
120 if (bestindex < 0 || bestmatch > max_uV) {
121 dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
122 min_uV, max_uV);
123 return -EINVAL;
124 }
125 return bestindex;
126}
127EXPORT_SYMBOL_GPL(mc13xxx_get_best_voltage_index);
128
129static int mc13xxx_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
130 int max_uV, unsigned *selector)
131{
132 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
133 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
134 int value, id = rdev_get_id(rdev);
135 int ret;
136
137 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
138 __func__, id, min_uV, max_uV);
139
140 /* Find the best index */
141 value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
142 dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
143 if (value < 0)
144 return value;
145
146 mc13xxx_lock(priv->mc13xxx);
147 ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg,
148 mc13xxx_regulators[id].vsel_mask,
149 value << mc13xxx_regulators[id].vsel_shift);
150 mc13xxx_unlock(priv->mc13xxx);
151
152 return ret;
153}
154
155static int mc13xxx_regulator_get_voltage(struct regulator_dev *rdev)
156{
157 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
158 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
159 int ret, id = rdev_get_id(rdev);
160 unsigned int val;
161
162 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
163
164 mc13xxx_lock(priv->mc13xxx);
165 ret = mc13xxx_reg_read(priv->mc13xxx,
166 mc13xxx_regulators[id].vsel_reg, &val);
167 mc13xxx_unlock(priv->mc13xxx);
168
169 if (ret)
170 return ret;
171
172 val = (val & mc13xxx_regulators[id].vsel_mask)
173 >> mc13xxx_regulators[id].vsel_shift;
174
175 dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
176
177 BUG_ON(val < 0 || val > mc13xxx_regulators[id].desc.n_voltages);
178
179 return mc13xxx_regulators[id].voltages[val];
180}
181
182struct regulator_ops mc13xxx_regulator_ops = {
183 .enable = mc13xxx_regulator_enable,
184 .disable = mc13xxx_regulator_disable,
185 .is_enabled = mc13xxx_regulator_is_enabled,
186 .list_voltage = mc13xxx_regulator_list_voltage,
187 .set_voltage = mc13xxx_regulator_set_voltage,
188 .get_voltage = mc13xxx_regulator_get_voltage,
189};
190EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);
191
192int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
193 int max_uV, unsigned *selector)
194{
195 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
196 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
197 int id = rdev_get_id(rdev);
198
199 dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
200 __func__, id, min_uV, max_uV);
201
202 if (min_uV >= mc13xxx_regulators[id].voltages[0] &&
203 max_uV <= mc13xxx_regulators[id].voltages[0])
204 return 0;
205 else
206 return -EINVAL;
207}
208EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_set_voltage);
209
210int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev)
211{
212 struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
213 struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
214 int id = rdev_get_id(rdev);
215
216 dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
217
218 return mc13xxx_regulators[id].voltages[0];
219}
220EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_get_voltage);
221
222struct regulator_ops mc13xxx_fixed_regulator_ops = {
223 .enable = mc13xxx_regulator_enable,
224 .disable = mc13xxx_regulator_disable,
225 .is_enabled = mc13xxx_regulator_is_enabled,
226 .list_voltage = mc13xxx_regulator_list_voltage,
227 .set_voltage = mc13xxx_fixed_regulator_set_voltage,
228 .get_voltage = mc13xxx_fixed_regulator_get_voltage,
229};
230EXPORT_SYMBOL_GPL(mc13xxx_fixed_regulator_ops);
231
232int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev)
233{
234 return 1;
235}
236EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled);
237
238MODULE_LICENSE("GPL v2");
239MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>");
240MODULE_DESCRIPTION("Regulator Driver for Freescale MC13xxx PMIC");
241MODULE_ALIAS("mc13xxx-regulator-core");
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h
new file mode 100644
index 000000000000..27758267e122
--- /dev/null
+++ b/drivers/regulator/mc13xxx.h
@@ -0,0 +1,101 @@
1/*
2 * mc13xxx.h - regulators for the Freescale mc13xxx PMIC
3 *
4 * Copyright (C) 2010 Yong Shen <yong.shen@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __LINUX_REGULATOR_MC13XXX_H
13#define __LINUX_REGULATOR_MC13XXX_H
14
15#include <linux/regulator/driver.h>
16
17struct mc13xxx_regulator {
18 struct regulator_desc desc;
19 int reg;
20 int enable_bit;
21 int vsel_reg;
22 int vsel_shift;
23 int vsel_mask;
24 int hi_bit;
25 int const *voltages;
26};
27
28struct mc13xxx_regulator_priv {
29 struct mc13xxx *mc13xxx;
30 u32 powermisc_pwgt_state;
31 struct mc13xxx_regulator *mc13xxx_regulators;
32 struct regulator_dev *regulators[];
33};
34
35extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
36extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
37extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
38 int min_uV, int max_uV);
39extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
40 unsigned selector);
41extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
42 int min_uV, int max_uV, unsigned *selector);
43extern int mc13xxx_fixed_regulator_get_voltage(struct regulator_dev *rdev);
44
45extern struct regulator_ops mc13xxx_regulator_ops;
46extern struct regulator_ops mc13xxx_fixed_regulator_ops;
47
48#define MC13xxx_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages, _ops) \
49 [prefix ## _name] = { \
50 .desc = { \
51 .name = #prefix "_" #_name, \
52 .n_voltages = ARRAY_SIZE(_voltages), \
53 .ops = &_ops, \
54 .type = REGULATOR_VOLTAGE, \
55 .id = prefix ## _name, \
56 .owner = THIS_MODULE, \
57 }, \
58 .reg = prefix ## _reg, \
59 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
60 .vsel_reg = prefix ## _vsel_reg, \
61 .vsel_shift = prefix ## _vsel_reg ## _ ## _name ## VSEL,\
62 .vsel_mask = prefix ## _vsel_reg ## _ ## _name ## VSEL_M,\
63 .voltages = _voltages, \
64 }
65
66#define MC13xxx_FIXED_DEFINE(prefix, _name, _reg, _voltages, _ops) \
67 [prefix ## _name] = { \
68 .desc = { \
69 .name = #prefix "_" #_name, \
70 .n_voltages = ARRAY_SIZE(_voltages), \
71 .ops = &_ops, \
72 .type = REGULATOR_VOLTAGE, \
73 .id = prefix ## _name, \
74 .owner = THIS_MODULE, \
75 }, \
76 .reg = prefix ## _reg, \
77 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
78 .voltages = _voltages, \
79 }
80
81#define MC13xxx_GPO_DEFINE(prefix, _name, _reg, _voltages, _ops) \
82 [prefix ## _name] = { \
83 .desc = { \
84 .name = #prefix "_" #_name, \
85 .n_voltages = ARRAY_SIZE(_voltages), \
86 .ops = &_ops, \
87 .type = REGULATOR_VOLTAGE, \
88 .id = prefix ## _name, \
89 .owner = THIS_MODULE, \
90 }, \
91 .reg = prefix ## _reg, \
92 .enable_bit = prefix ## _reg ## _ ## _name ## EN, \
93 .voltages = _voltages, \
94 }
95
96#define MC13xxx_DEFINE_SW(_name, _reg, _vsel_reg, _voltages, ops) \
97 MC13xxx_DEFINE(SW, _name, _reg, _vsel_reg, _voltages, ops)
98#define MC13xxx_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages, ops) \
99 MC13xxx_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages, ops)
100
101#endif
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c
index 29d0566379ae..31f6e11a7f16 100644
--- a/drivers/regulator/pcap-regulator.c
+++ b/drivers/regulator/pcap-regulator.c
@@ -151,7 +151,8 @@ static struct pcap_regulator vreg_table[] = {
151}; 151};
152 152
153static int pcap_regulator_set_voltage(struct regulator_dev *rdev, 153static int pcap_regulator_set_voltage(struct regulator_dev *rdev,
154 int min_uV, int max_uV) 154 int min_uV, int max_uV,
155 unsigned *selector)
155{ 156{
156 struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; 157 struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)];
157 void *pcap = rdev_get_drvdata(rdev); 158 void *pcap = rdev_get_drvdata(rdev);
@@ -170,10 +171,12 @@ static int pcap_regulator_set_voltage(struct regulator_dev *rdev,
170 i = 0; 171 i = 0;
171 172
172 uV = vreg->voltage_table[i] * 1000; 173 uV = vreg->voltage_table[i] * 1000;
173 if (min_uV <= uV && uV <= max_uV) 174 if (min_uV <= uV && uV <= max_uV) {
175 *selector = i;
174 return ezx_pcap_set_bits(pcap, vreg->reg, 176 return ezx_pcap_set_bits(pcap, vreg->reg,
175 (vreg->n_voltages - 1) << vreg->index, 177 (vreg->n_voltages - 1) << vreg->index,
176 i << vreg->index); 178 i << vreg->index);
179 }
177 180
178 if (i == 0 && rdev_get_id(rdev) == V1) 181 if (i == 0 && rdev_get_id(rdev) == V1)
179 i = vreg->n_voltages - 1; 182 i = vreg->n_voltages - 1;
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
index c8f41dc05b76..69a11d9dd87f 100644
--- a/drivers/regulator/pcf50633-regulator.c
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -108,7 +108,8 @@ static unsigned int ldo_voltage_value(u8 bits)
108} 108}
109 109
110static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, 110static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
111 int min_uV, int max_uV) 111 int min_uV, int max_uV,
112 unsigned *selector)
112{ 113{
113 struct pcf50633 *pcf; 114 struct pcf50633 *pcf;
114 int regulator_id, millivolts; 115 int regulator_id, millivolts;
@@ -147,6 +148,8 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
147 return -EINVAL; 148 return -EINVAL;
148 } 149 }
149 150
151 *selector = volt_bits;
152
150 return pcf50633_reg_write(pcf, regnr, volt_bits); 153 return pcf50633_reg_write(pcf, regnr, volt_bits);
151} 154}
152 155
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index cd6d4fc9d74f..60a7ca5409e9 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -321,7 +321,8 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
321} 321}
322 322
323static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, 323static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
324 int min_uV, int max_uV) 324 int min_uV, int max_uV,
325 unsigned *selector)
325{ 326{
326 struct tps_pmic *tps = rdev_get_drvdata(dev); 327 struct tps_pmic *tps = rdev_get_drvdata(dev);
327 int dcdc = rdev_get_id(dev); 328 int dcdc = rdev_get_id(dev);
@@ -346,6 +347,8 @@ static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
346 break; 347 break;
347 } 348 }
348 349
350 *selector = vsel;
351
349 /* write to the register in case we found a match */ 352 /* write to the register in case we found a match */
350 if (vsel == tps->info[dcdc]->table_len) 353 if (vsel == tps->info[dcdc]->table_len)
351 return -EINVAL; 354 return -EINVAL;
@@ -371,7 +374,7 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
371} 374}
372 375
373static int tps65023_ldo_set_voltage(struct regulator_dev *dev, 376static int tps65023_ldo_set_voltage(struct regulator_dev *dev,
374 int min_uV, int max_uV) 377 int min_uV, int max_uV, unsigned *selector)
375{ 378{
376 struct tps_pmic *tps = rdev_get_drvdata(dev); 379 struct tps_pmic *tps = rdev_get_drvdata(dev);
377 int data, vsel, ldo = rdev_get_id(dev); 380 int data, vsel, ldo = rdev_get_id(dev);
@@ -396,6 +399,8 @@ static int tps65023_ldo_set_voltage(struct regulator_dev *dev,
396 if (vsel == tps->info[ldo]->table_len) 399 if (vsel == tps->info[ldo]->table_len)
397 return -EINVAL; 400 return -EINVAL;
398 401
402 *selector = vsel;
403
399 data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); 404 data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL);
400 if (data < 0) 405 if (data < 0)
401 return data; 406 return data;
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 020f5878d7ff..064755290599 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -369,7 +369,8 @@ static int tps6507x_pmic_dcdc_get_voltage(struct regulator_dev *dev)
369} 369}
370 370
371static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev, 371static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
372 int min_uV, int max_uV) 372 int min_uV, int max_uV,
373 unsigned *selector)
373{ 374{
374 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 375 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
375 int data, vsel, dcdc = rdev_get_id(dev); 376 int data, vsel, dcdc = rdev_get_id(dev);
@@ -415,6 +416,8 @@ static int tps6507x_pmic_dcdc_set_voltage(struct regulator_dev *dev,
415 if (vsel == tps->info[dcdc]->table_len) 416 if (vsel == tps->info[dcdc]->table_len)
416 return -EINVAL; 417 return -EINVAL;
417 418
419 *selector = vsel;
420
418 data = tps6507x_pmic_reg_read(tps, reg); 421 data = tps6507x_pmic_reg_read(tps, reg);
419 if (data < 0) 422 if (data < 0)
420 return data; 423 return data;
@@ -450,7 +453,8 @@ static int tps6507x_pmic_ldo_get_voltage(struct regulator_dev *dev)
450} 453}
451 454
452static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev, 455static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
453 int min_uV, int max_uV) 456 int min_uV, int max_uV,
457 unsigned *selector)
454{ 458{
455 struct tps6507x_pmic *tps = rdev_get_drvdata(dev); 459 struct tps6507x_pmic *tps = rdev_get_drvdata(dev);
456 int data, vsel, ldo = rdev_get_id(dev); 460 int data, vsel, ldo = rdev_get_id(dev);
@@ -483,6 +487,8 @@ static int tps6507x_pmic_ldo_set_voltage(struct regulator_dev *dev,
483 if (vsel == tps->info[ldo]->table_len) 487 if (vsel == tps->info[ldo]->table_len)
484 return -EINVAL; 488 return -EINVAL;
485 489
490 *selector = vsel;
491
486 data = tps6507x_pmic_reg_read(tps, reg); 492 data = tps6507x_pmic_reg_read(tps, reg);
487 if (data < 0) 493 if (data < 0)
488 return data; 494 return data;
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
new file mode 100644
index 000000000000..176a6be5a8ce
--- /dev/null
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -0,0 +1,693 @@
1/*
2 * Regulator driver for TPS6524x PMIC
3 *
4 * Copyright (C) 2010 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
11 * whether express or implied; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/err.h>
19#include <linux/errno.h>
20#include <linux/slab.h>
21#include <linux/spi/spi.h>
22#include <linux/regulator/driver.h>
23#include <linux/regulator/machine.h>
24
25#define REG_LDO_SET 0x0
26#define LDO_ILIM_MASK 1 /* 0 = 400-800, 1 = 900-1500 */
27#define LDO_VSEL_MASK 0x0f
28#define LDO2_ILIM_SHIFT 12
29#define LDO2_VSEL_SHIFT 4
30#define LDO1_ILIM_SHIFT 8
31#define LDO1_VSEL_SHIFT 0
32
33#define REG_BLOCK_EN 0x1
34#define BLOCK_MASK 1
35#define BLOCK_LDO1_SHIFT 0
36#define BLOCK_LDO2_SHIFT 1
37#define BLOCK_LCD_SHIFT 2
38#define BLOCK_USB_SHIFT 3
39
40#define REG_DCDC_SET 0x2
41#define DCDC_VDCDC_MASK 0x1f
42#define DCDC_VDCDC1_SHIFT 0
43#define DCDC_VDCDC2_SHIFT 5
44#define DCDC_VDCDC3_SHIFT 10
45
46#define REG_DCDC_EN 0x3
47#define DCDCDCDC_EN_MASK 0x1
48#define DCDCDCDC1_EN_SHIFT 0
49#define DCDCDCDC1_PG_MSK BIT(1)
50#define DCDCDCDC2_EN_SHIFT 2
51#define DCDCDCDC2_PG_MSK BIT(3)
52#define DCDCDCDC3_EN_SHIFT 4
53#define DCDCDCDC3_PG_MSK BIT(5)
54
55#define REG_USB 0x4
56#define USB_ILIM_SHIFT 0
57#define USB_ILIM_MASK 0x3
58#define USB_TSD_SHIFT 2
59#define USB_TSD_MASK 0x3
60#define USB_TWARN_SHIFT 4
61#define USB_TWARN_MASK 0x3
62#define USB_IWARN_SD BIT(6)
63#define USB_FAST_LOOP BIT(7)
64
65#define REG_ALARM 0x5
66#define ALARM_LDO1 BIT(0)
67#define ALARM_DCDC1 BIT(1)
68#define ALARM_DCDC2 BIT(2)
69#define ALARM_DCDC3 BIT(3)
70#define ALARM_LDO2 BIT(4)
71#define ALARM_USB_WARN BIT(5)
72#define ALARM_USB_ALARM BIT(6)
73#define ALARM_LCD BIT(9)
74#define ALARM_TEMP_WARM BIT(10)
75#define ALARM_TEMP_HOT BIT(11)
76#define ALARM_NRST BIT(14)
77#define ALARM_POWERUP BIT(15)
78
79#define REG_INT_ENABLE 0x6
80#define INT_LDO1 BIT(0)
81#define INT_DCDC1 BIT(1)
82#define INT_DCDC2 BIT(2)
83#define INT_DCDC3 BIT(3)
84#define INT_LDO2 BIT(4)
85#define INT_USB_WARN BIT(5)
86#define INT_USB_ALARM BIT(6)
87#define INT_LCD BIT(9)
88#define INT_TEMP_WARM BIT(10)
89#define INT_TEMP_HOT BIT(11)
90#define INT_GLOBAL_EN BIT(15)
91
92#define REG_INT_STATUS 0x7
93#define STATUS_LDO1 BIT(0)
94#define STATUS_DCDC1 BIT(1)
95#define STATUS_DCDC2 BIT(2)
96#define STATUS_DCDC3 BIT(3)
97#define STATUS_LDO2 BIT(4)
98#define STATUS_USB_WARN BIT(5)
99#define STATUS_USB_ALARM BIT(6)
100#define STATUS_LCD BIT(9)
101#define STATUS_TEMP_WARM BIT(10)
102#define STATUS_TEMP_HOT BIT(11)
103
104#define REG_SOFTWARE_RESET 0xb
105#define REG_WRITE_ENABLE 0xd
106#define REG_REV_ID 0xf
107
108#define N_DCDC 3
109#define N_LDO 2
110#define N_SWITCH 2
111#define N_REGULATORS (3 /* DCDC */ + \
112 2 /* LDO */ + \
113 2 /* switch */)
114
115#define FIXED_ILIMSEL BIT(0)
116#define FIXED_VOLTAGE BIT(1)
117
118#define CMD_READ(reg) ((reg) << 6)
119#define CMD_WRITE(reg) (BIT(5) | (reg) << 6)
120#define STAT_CLK BIT(3)
121#define STAT_WRITE BIT(2)
122#define STAT_INVALID BIT(1)
123#define STAT_WP BIT(0)
124
125struct field {
126 int reg;
127 int shift;
128 int mask;
129};
130
131struct supply_info {
132 const char *name;
133 int n_voltages;
134 const int *voltages;
135 int fixed_voltage;
136 int n_ilimsels;
137 const int *ilimsels;
138 int fixed_ilimsel;
139 int flags;
140 struct field enable, voltage, ilimsel;
141};
142
143struct tps6524x {
144 struct device *dev;
145 struct spi_device *spi;
146 struct mutex lock;
147 struct regulator_desc desc[N_REGULATORS];
148 struct regulator_dev *rdev[N_REGULATORS];
149};
150
151static int __read_reg(struct tps6524x *hw, int reg)
152{
153 int error = 0;
154 u16 cmd = CMD_READ(reg), in;
155 u8 status;
156 struct spi_message m;
157 struct spi_transfer t[3];
158
159 spi_message_init(&m);
160 memset(t, 0, sizeof(t));
161
162 t[0].tx_buf = &cmd;
163 t[0].len = 2;
164 t[0].bits_per_word = 12;
165 spi_message_add_tail(&t[0], &m);
166
167 t[1].rx_buf = &in;
168 t[1].len = 2;
169 t[1].bits_per_word = 16;
170 spi_message_add_tail(&t[1], &m);
171
172 t[2].rx_buf = &status;
173 t[2].len = 1;
174 t[2].bits_per_word = 4;
175 spi_message_add_tail(&t[2], &m);
176
177 error = spi_sync(hw->spi, &m);
178 if (error < 0)
179 return error;
180
181 dev_dbg(hw->dev, "read reg %d, data %x, status %x\n",
182 reg, in, status);
183
184 if (!(status & STAT_CLK) || (status & STAT_WRITE))
185 return -EIO;
186
187 if (status & STAT_INVALID)
188 return -EINVAL;
189
190 return in;
191}
192
193static int read_reg(struct tps6524x *hw, int reg)
194{
195 int ret;
196
197 mutex_lock(&hw->lock);
198 ret = __read_reg(hw, reg);
199 mutex_unlock(&hw->lock);
200
201 return ret;
202}
203
204static int __write_reg(struct tps6524x *hw, int reg, int val)
205{
206 int error = 0;
207 u16 cmd = CMD_WRITE(reg), out = val;
208 u8 status;
209 struct spi_message m;
210 struct spi_transfer t[3];
211
212 spi_message_init(&m);
213 memset(t, 0, sizeof(t));
214
215 t[0].tx_buf = &cmd;
216 t[0].len = 2;
217 t[0].bits_per_word = 12;
218 spi_message_add_tail(&t[0], &m);
219
220 t[1].tx_buf = &out;
221 t[1].len = 2;
222 t[1].bits_per_word = 16;
223 spi_message_add_tail(&t[1], &m);
224
225 t[2].rx_buf = &status;
226 t[2].len = 1;
227 t[2].bits_per_word = 4;
228 spi_message_add_tail(&t[2], &m);
229
230 error = spi_sync(hw->spi, &m);
231 if (error < 0)
232 return error;
233
234 dev_dbg(hw->dev, "wrote reg %d, data %x, status %x\n",
235 reg, out, status);
236
237 if (!(status & STAT_CLK) || !(status & STAT_WRITE))
238 return -EIO;
239
240 if (status & (STAT_INVALID | STAT_WP))
241 return -EINVAL;
242
243 return error;
244}
245
246static int __rmw_reg(struct tps6524x *hw, int reg, int mask, int val)
247{
248 int ret;
249
250 ret = __read_reg(hw, reg);
251 if (ret < 0)
252 return ret;
253
254 ret &= ~mask;
255 ret |= val;
256
257 ret = __write_reg(hw, reg, ret);
258
259 return (ret < 0) ? ret : 0;
260}
261
262static int rmw_protect(struct tps6524x *hw, int reg, int mask, int val)
263{
264 int ret;
265
266 mutex_lock(&hw->lock);
267
268 ret = __write_reg(hw, REG_WRITE_ENABLE, 1);
269 if (ret) {
270 dev_err(hw->dev, "failed to set write enable\n");
271 goto error;
272 }
273
274 ret = __rmw_reg(hw, reg, mask, val);
275 if (ret)
276 dev_err(hw->dev, "failed to rmw register %d\n", reg);
277
278 ret = __write_reg(hw, REG_WRITE_ENABLE, 0);
279 if (ret) {
280 dev_err(hw->dev, "failed to clear write enable\n");
281 goto error;
282 }
283
284error:
285 mutex_unlock(&hw->lock);
286
287 return ret;
288}
289
290static int read_field(struct tps6524x *hw, const struct field *field)
291{
292 int tmp;
293
294 tmp = read_reg(hw, field->reg);
295 if (tmp < 0)
296 return tmp;
297
298 return (tmp >> field->shift) & field->mask;
299}
300
301static int write_field(struct tps6524x *hw, const struct field *field,
302 int val)
303{
304 if (val & ~field->mask)
305 return -EOVERFLOW;
306
307 return rmw_protect(hw, field->reg,
308 field->mask << field->shift,
309 val << field->shift);
310}
311
312static const int dcdc1_voltages[] = {
313 800000, 825000, 850000, 875000,
314 900000, 925000, 950000, 975000,
315 1000000, 1025000, 1050000, 1075000,
316 1100000, 1125000, 1150000, 1175000,
317 1200000, 1225000, 1250000, 1275000,
318 1300000, 1325000, 1350000, 1375000,
319 1400000, 1425000, 1450000, 1475000,
320 1500000, 1525000, 1550000, 1575000,
321};
322
323static const int dcdc2_voltages[] = {
324 1400000, 1450000, 1500000, 1550000,
325 1600000, 1650000, 1700000, 1750000,
326 1800000, 1850000, 1900000, 1950000,
327 2000000, 2050000, 2100000, 2150000,
328 2200000, 2250000, 2300000, 2350000,
329 2400000, 2450000, 2500000, 2550000,
330 2600000, 2650000, 2700000, 2750000,
331 2800000, 2850000, 2900000, 2950000,
332};
333
334static const int dcdc3_voltages[] = {
335 2400000, 2450000, 2500000, 2550000, 2600000,
336 2650000, 2700000, 2750000, 2800000, 2850000,
337 2900000, 2950000, 3000000, 3050000, 3100000,
338 3150000, 3200000, 3250000, 3300000, 3350000,
339 3400000, 3450000, 3500000, 3550000, 3600000,
340};
341
342static const int ldo1_voltages[] = {
343 4300000, 4350000, 4400000, 4450000,
344 4500000, 4550000, 4600000, 4650000,
345 4700000, 4750000, 4800000, 4850000,
346 4900000, 4950000, 5000000, 5050000,
347};
348
349static const int ldo2_voltages[] = {
350 1100000, 1150000, 1200000, 1250000,
351 1300000, 1700000, 1750000, 1800000,
352 1850000, 1900000, 3150000, 3200000,
353 3250000, 3300000, 3350000, 3400000,
354};
355
356static const int ldo_ilimsel[] = {
357 400000, 1500000
358};
359
360static const int usb_ilimsel[] = {
361 200000, 400000, 800000, 1000000
362};
363
364#define __MK_FIELD(_reg, _mask, _shift) \
365 { .reg = (_reg), .mask = (_mask), .shift = (_shift), }
366
367static const struct supply_info supply_info[N_REGULATORS] = {
368 {
369 .name = "DCDC1",
370 .flags = FIXED_ILIMSEL,
371 .n_voltages = ARRAY_SIZE(dcdc1_voltages),
372 .voltages = dcdc1_voltages,
373 .fixed_ilimsel = 2400000,
374 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
375 DCDCDCDC1_EN_SHIFT),
376 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
377 DCDC_VDCDC1_SHIFT),
378 },
379 {
380 .name = "DCDC2",
381 .flags = FIXED_ILIMSEL,
382 .n_voltages = ARRAY_SIZE(dcdc2_voltages),
383 .voltages = dcdc2_voltages,
384 .fixed_ilimsel = 1200000,
385 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
386 DCDCDCDC2_EN_SHIFT),
387 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
388 DCDC_VDCDC2_SHIFT),
389 },
390 {
391 .name = "DCDC3",
392 .flags = FIXED_ILIMSEL,
393 .n_voltages = ARRAY_SIZE(dcdc3_voltages),
394 .voltages = dcdc3_voltages,
395 .fixed_ilimsel = 1200000,
396 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
397 DCDCDCDC3_EN_SHIFT),
398 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
399 DCDC_VDCDC3_SHIFT),
400 },
401 {
402 .name = "LDO1",
403 .n_voltages = ARRAY_SIZE(ldo1_voltages),
404 .voltages = ldo1_voltages,
405 .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
406 .ilimsels = ldo_ilimsel,
407 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
408 BLOCK_LDO1_SHIFT),
409 .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
410 LDO1_VSEL_SHIFT),
411 .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
412 LDO1_ILIM_SHIFT),
413 },
414 {
415 .name = "LDO2",
416 .n_voltages = ARRAY_SIZE(ldo2_voltages),
417 .voltages = ldo2_voltages,
418 .n_ilimsels = ARRAY_SIZE(ldo_ilimsel),
419 .ilimsels = ldo_ilimsel,
420 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
421 BLOCK_LDO2_SHIFT),
422 .voltage = __MK_FIELD(REG_LDO_SET, LDO_VSEL_MASK,
423 LDO2_VSEL_SHIFT),
424 .ilimsel = __MK_FIELD(REG_LDO_SET, LDO_ILIM_MASK,
425 LDO2_ILIM_SHIFT),
426 },
427 {
428 .name = "USB",
429 .flags = FIXED_VOLTAGE,
430 .fixed_voltage = 5000000,
431 .n_ilimsels = ARRAY_SIZE(usb_ilimsel),
432 .ilimsels = usb_ilimsel,
433 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
434 BLOCK_USB_SHIFT),
435 .ilimsel = __MK_FIELD(REG_USB, USB_ILIM_MASK,
436 USB_ILIM_SHIFT),
437 },
438 {
439 .name = "LCD",
440 .flags = FIXED_VOLTAGE | FIXED_ILIMSEL,
441 .fixed_voltage = 5000000,
442 .fixed_ilimsel = 400000,
443 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
444 BLOCK_LCD_SHIFT),
445 },
446};
447
448static int list_voltage(struct regulator_dev *rdev, unsigned selector)
449{
450 const struct supply_info *info;
451 struct tps6524x *hw;
452
453 hw = rdev_get_drvdata(rdev);
454 info = &supply_info[rdev_get_id(rdev)];
455
456 if (info->flags & FIXED_VOLTAGE)
457 return selector ? -EINVAL : info->fixed_voltage;
458
459 return ((selector < info->n_voltages) ?
460 info->voltages[selector] : -EINVAL);
461}
462
463static int set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
464 unsigned *selector)
465{
466 const struct supply_info *info;
467 struct tps6524x *hw;
468 unsigned i;
469
470 hw = rdev_get_drvdata(rdev);
471 info = &supply_info[rdev_get_id(rdev)];
472
473 if (info->flags & FIXED_VOLTAGE)
474 return -EINVAL;
475
476 for (i = 0; i < info->n_voltages; i++)
477 if (min_uV <= info->voltages[i] &&
478 max_uV >= info->voltages[i])
479 break;
480
481 if (i >= info->n_voltages)
482 i = info->n_voltages - 1;
483
484 *selector = info->voltages[i];
485
486 return write_field(hw, &info->voltage, i);
487}
488
489static int get_voltage(struct regulator_dev *rdev)
490{
491 const struct supply_info *info;
492 struct tps6524x *hw;
493 int ret;
494
495 hw = rdev_get_drvdata(rdev);
496 info = &supply_info[rdev_get_id(rdev)];
497
498 if (info->flags & FIXED_VOLTAGE)
499 return info->fixed_voltage;
500
501 ret = read_field(hw, &info->voltage);
502 if (ret < 0)
503 return ret;
504 if (WARN_ON(ret >= info->n_voltages))
505 return -EIO;
506
507 return info->voltages[ret];
508}
509
510static int set_current_limit(struct regulator_dev *rdev, int min_uA,
511 int max_uA)
512{
513 const struct supply_info *info;
514 struct tps6524x *hw;
515 int i;
516
517 hw = rdev_get_drvdata(rdev);
518 info = &supply_info[rdev_get_id(rdev)];
519
520 if (info->flags & FIXED_ILIMSEL)
521 return -EINVAL;
522
523 for (i = 0; i < info->n_ilimsels; i++)
524 if (min_uA <= info->ilimsels[i] &&
525 max_uA >= info->ilimsels[i])
526 break;
527
528 if (i >= info->n_ilimsels)
529 return -EINVAL;
530
531 return write_field(hw, &info->ilimsel, i);
532}
533
534static int get_current_limit(struct regulator_dev *rdev)
535{
536 const struct supply_info *info;
537 struct tps6524x *hw;
538 int ret;
539
540 hw = rdev_get_drvdata(rdev);
541 info = &supply_info[rdev_get_id(rdev)];
542
543 if (info->flags & FIXED_ILIMSEL)
544 return info->fixed_ilimsel;
545
546 ret = read_field(hw, &info->ilimsel);
547 if (ret < 0)
548 return ret;
549 if (WARN_ON(ret >= info->n_ilimsels))
550 return -EIO;
551
552 return info->ilimsels[ret];
553}
554
555static int enable_supply(struct regulator_dev *rdev)
556{
557 const struct supply_info *info;
558 struct tps6524x *hw;
559
560 hw = rdev_get_drvdata(rdev);
561 info = &supply_info[rdev_get_id(rdev)];
562
563 return write_field(hw, &info->enable, 1);
564}
565
566static int disable_supply(struct regulator_dev *rdev)
567{
568 const struct supply_info *info;
569 struct tps6524x *hw;
570
571 hw = rdev_get_drvdata(rdev);
572 info = &supply_info[rdev_get_id(rdev)];
573
574 return write_field(hw, &info->enable, 0);
575}
576
577static int is_supply_enabled(struct regulator_dev *rdev)
578{
579 const struct supply_info *info;
580 struct tps6524x *hw;
581
582 hw = rdev_get_drvdata(rdev);
583 info = &supply_info[rdev_get_id(rdev)];
584
585 return read_field(hw, &info->enable);
586}
587
588static struct regulator_ops regulator_ops = {
589 .is_enabled = is_supply_enabled,
590 .enable = enable_supply,
591 .disable = disable_supply,
592 .get_voltage = get_voltage,
593 .set_voltage = set_voltage,
594 .list_voltage = list_voltage,
595 .set_current_limit = set_current_limit,
596 .get_current_limit = get_current_limit,
597};
598
599static int __devexit pmic_remove(struct spi_device *spi)
600{
601 struct tps6524x *hw = spi_get_drvdata(spi);
602 int i;
603
604 if (!hw)
605 return 0;
606 for (i = 0; i < N_REGULATORS; i++) {
607 if (hw->rdev[i])
608 regulator_unregister(hw->rdev[i]);
609 hw->rdev[i] = NULL;
610 }
611 spi_set_drvdata(spi, NULL);
612 kfree(hw);
613 return 0;
614}
615
616static int __devinit pmic_probe(struct spi_device *spi)
617{
618 struct tps6524x *hw;
619 struct device *dev = &spi->dev;
620 const struct supply_info *info = supply_info;
621 struct regulator_init_data *init_data;
622 int ret = 0, i;
623
624 init_data = dev->platform_data;
625 if (!init_data) {
626 dev_err(dev, "could not find regulator platform data\n");
627 return -EINVAL;
628 }
629
630 hw = kzalloc(sizeof(struct tps6524x), GFP_KERNEL);
631 if (!hw) {
632 dev_err(dev, "cannot allocate regulator private data\n");
633 return -ENOMEM;
634 }
635 spi_set_drvdata(spi, hw);
636
637 memset(hw, 0, sizeof(struct tps6524x));
638 hw->dev = dev;
639 hw->spi = spi_dev_get(spi);
640 mutex_init(&hw->lock);
641
642 for (i = 0; i < N_REGULATORS; i++, info++, init_data++) {
643 hw->desc[i].name = info->name;
644 hw->desc[i].id = i;
645 hw->desc[i].n_voltages = info->n_voltages;
646 hw->desc[i].ops = &regulator_ops;
647 hw->desc[i].type = REGULATOR_VOLTAGE;
648 hw->desc[i].owner = THIS_MODULE;
649
650 if (info->flags & FIXED_VOLTAGE)
651 hw->desc[i].n_voltages = 1;
652
653 hw->rdev[i] = regulator_register(&hw->desc[i], dev,
654 init_data, hw);
655 if (IS_ERR(hw->rdev[i])) {
656 ret = PTR_ERR(hw->rdev[i]);
657 hw->rdev[i] = NULL;
658 goto fail;
659 }
660 }
661
662 return 0;
663
664fail:
665 pmic_remove(spi);
666 return ret;
667}
668
669static struct spi_driver pmic_driver = {
670 .probe = pmic_probe,
671 .remove = __devexit_p(pmic_remove),
672 .driver = {
673 .name = "tps6524x",
674 .owner = THIS_MODULE,
675 },
676};
677
678static int __init pmic_driver_init(void)
679{
680 return spi_register_driver(&pmic_driver);
681}
682module_init(pmic_driver_init);
683
684static void __exit pmic_driver_exit(void)
685{
686 spi_unregister_driver(&pmic_driver);
687}
688module_exit(pmic_driver_exit);
689
690MODULE_DESCRIPTION("TPS6524X PMIC Driver");
691MODULE_AUTHOR("Cyril Chemparathy");
692MODULE_LICENSE("GPL");
693MODULE_ALIAS("spi:tps6524x");
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 6d20b0454a1d..bb04a75a4c98 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -85,7 +85,8 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
85 85
86static int __tps6586x_ldo_set_voltage(struct device *parent, 86static int __tps6586x_ldo_set_voltage(struct device *parent,
87 struct tps6586x_regulator *ri, 87 struct tps6586x_regulator *ri,
88 int min_uV, int max_uV) 88 int min_uV, int max_uV,
89 unsigned *selector)
89{ 90{
90 int val, uV; 91 int val, uV;
91 uint8_t mask; 92 uint8_t mask;
@@ -100,6 +101,8 @@ static int __tps6586x_ldo_set_voltage(struct device *parent,
100 /* use the first in-range value */ 101 /* use the first in-range value */
101 if (min_uV <= uV && uV <= max_uV) { 102 if (min_uV <= uV && uV <= max_uV) {
102 103
104 *selector = val;
105
103 val <<= ri->volt_shift; 106 val <<= ri->volt_shift;
104 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 107 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
105 108
@@ -111,12 +114,13 @@ static int __tps6586x_ldo_set_voltage(struct device *parent,
111} 114}
112 115
113static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev, 116static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev,
114 int min_uV, int max_uV) 117 int min_uV, int max_uV, unsigned *selector)
115{ 118{
116 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 119 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
117 struct device *parent = to_tps6586x_dev(rdev); 120 struct device *parent = to_tps6586x_dev(rdev);
118 121
119 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV); 122 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV,
123 selector);
120} 124}
121 125
122static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) 126static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
@@ -140,13 +144,14 @@ static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
140} 144}
141 145
142static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev, 146static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
143 int min_uV, int max_uV) 147 int min_uV, int max_uV, unsigned *selector)
144{ 148{
145 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); 149 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
146 struct device *parent = to_tps6586x_dev(rdev); 150 struct device *parent = to_tps6586x_dev(rdev);
147 int ret; 151 int ret;
148 152
149 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV); 153 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV,
154 selector);
150 if (ret) 155 if (ret)
151 return ret; 156 return ret;
152 157
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index a57262a4fa6c..bd332cf1cc3f 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -329,7 +329,8 @@ static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
329} 329}
330 330
331static int 331static int
332twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 332twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
333 unsigned *selector)
333{ 334{
334 struct twlreg_info *info = rdev_get_drvdata(rdev); 335 struct twlreg_info *info = rdev_get_drvdata(rdev);
335 int vsel; 336 int vsel;
@@ -345,9 +346,11 @@ twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
345 /* REVISIT for VAUX2, first match may not be best/lowest */ 346 /* REVISIT for VAUX2, first match may not be best/lowest */
346 347
347 /* use the first in-range value */ 348 /* use the first in-range value */
348 if (min_uV <= uV && uV <= max_uV) 349 if (min_uV <= uV && uV <= max_uV) {
350 *selector = vsel;
349 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, 351 return twlreg_write(info, TWL_MODULE_PM_RECEIVER,
350 VREG_VOLTAGE, vsel); 352 VREG_VOLTAGE, vsel);
353 }
351 } 354 }
352 355
353 return -EDOM; 356 return -EDOM;
@@ -389,7 +392,8 @@ static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
389} 392}
390 393
391static int 394static int
392twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) 395twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
396 unsigned *selector)
393{ 397{
394 struct twlreg_info *info = rdev_get_drvdata(rdev); 398 struct twlreg_info *info = rdev_get_drvdata(rdev);
395 int vsel; 399 int vsel;
@@ -402,6 +406,7 @@ twl6030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
402 * mV = 1000mv + 100mv * (vsel - 1) 406 * mV = 1000mv + 100mv * (vsel - 1)
403 */ 407 */
404 vsel = (min_uV/1000 - 1000)/100 + 1; 408 vsel = (min_uV/1000 - 1000)/100 + 1;
409 *selector = vsel;
405 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel); 410 return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, vsel);
406 411
407} 412}
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c
index dbfaf5945e48..8b0d2c4bde91 100644
--- a/drivers/regulator/wm831x-dcdc.c
+++ b/drivers/regulator/wm831x-dcdc.c
@@ -302,7 +302,7 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
302} 302}
303 303
304static int wm831x_buckv_set_voltage(struct regulator_dev *rdev, 304static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
305 int min_uV, int max_uV) 305 int min_uV, int max_uV, unsigned *selector)
306{ 306{
307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 307 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
308 struct wm831x *wm831x = dcdc->wm831x; 308 struct wm831x *wm831x = dcdc->wm831x;
@@ -314,6 +314,8 @@ static int wm831x_buckv_set_voltage(struct regulator_dev *rdev,
314 if (vsel < 0) 314 if (vsel < 0)
315 return vsel; 315 return vsel;
316 316
317 *selector = vsel;
318
317 /* If this value is already set then do a GPIO update if we can */ 319 /* If this value is already set then do a GPIO update if we can */
318 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 320 if (dcdc->dvs_gpio && dcdc->on_vsel == vsel)
319 return wm831x_buckv_set_dvs(rdev, 0); 321 return wm831x_buckv_set_dvs(rdev, 0);
@@ -375,14 +377,14 @@ static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
375 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel); 377 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
376} 378}
377 379
378static int wm831x_buckv_get_voltage(struct regulator_dev *rdev) 380static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
379{ 381{
380 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 382 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
381 383
382 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 384 if (dcdc->dvs_gpio && dcdc->dvs_gpio_state)
383 return wm831x_buckv_list_voltage(rdev, dcdc->dvs_vsel); 385 return dcdc->dvs_vsel;
384 else 386 else
385 return wm831x_buckv_list_voltage(rdev, dcdc->on_vsel); 387 return dcdc->on_vsel;
386} 388}
387 389
388/* Current limit options */ 390/* Current limit options */
@@ -424,7 +426,7 @@ static int wm831x_buckv_get_current_limit(struct regulator_dev *rdev)
424 426
425static struct regulator_ops wm831x_buckv_ops = { 427static struct regulator_ops wm831x_buckv_ops = {
426 .set_voltage = wm831x_buckv_set_voltage, 428 .set_voltage = wm831x_buckv_set_voltage,
427 .get_voltage = wm831x_buckv_get_voltage, 429 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
428 .list_voltage = wm831x_buckv_list_voltage, 430 .list_voltage = wm831x_buckv_list_voltage,
429 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage, 431 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
430 .set_current_limit = wm831x_buckv_set_current_limit, 432 .set_current_limit = wm831x_buckv_set_current_limit,
@@ -636,7 +638,7 @@ static int wm831x_buckp_list_voltage(struct regulator_dev *rdev,
636} 638}
637 639
638static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg, 640static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
639 int min_uV, int max_uV) 641 int min_uV, int max_uV, int *selector)
640{ 642{
641 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 643 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
642 struct wm831x *wm831x = dcdc->wm831x; 644 struct wm831x *wm831x = dcdc->wm831x;
@@ -650,16 +652,20 @@ static int wm831x_buckp_set_voltage_int(struct regulator_dev *rdev, int reg,
650 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV) 652 if (wm831x_buckp_list_voltage(rdev, vsel) > max_uV)
651 return -EINVAL; 653 return -EINVAL;
652 654
655 *selector = vsel;
656
653 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel); 657 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, vsel);
654} 658}
655 659
656static int wm831x_buckp_set_voltage(struct regulator_dev *rdev, 660static int wm831x_buckp_set_voltage(struct regulator_dev *rdev,
657 int min_uV, int max_uV) 661 int min_uV, int max_uV,
662 unsigned *selector)
658{ 663{
659 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 664 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
660 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; 665 u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
661 666
662 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV); 667 return wm831x_buckp_set_voltage_int(rdev, reg, min_uV, max_uV,
668 selector);
663} 669}
664 670
665static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, 671static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
@@ -667,11 +673,12 @@ static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev,
667{ 673{
668 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 674 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
669 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL; 675 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
676 unsigned selector;
670 677
671 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV); 678 return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector);
672} 679}
673 680
674static int wm831x_buckp_get_voltage(struct regulator_dev *rdev) 681static int wm831x_buckp_get_voltage_sel(struct regulator_dev *rdev)
675{ 682{
676 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 683 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
677 struct wm831x *wm831x = dcdc->wm831x; 684 struct wm831x *wm831x = dcdc->wm831x;
@@ -682,12 +689,12 @@ static int wm831x_buckp_get_voltage(struct regulator_dev *rdev)
682 if (val < 0) 689 if (val < 0)
683 return val; 690 return val;
684 691
685 return wm831x_buckp_list_voltage(rdev, val & WM831X_DC3_ON_VSEL_MASK); 692 return val & WM831X_DC3_ON_VSEL_MASK;
686} 693}
687 694
688static struct regulator_ops wm831x_buckp_ops = { 695static struct regulator_ops wm831x_buckp_ops = {
689 .set_voltage = wm831x_buckp_set_voltage, 696 .set_voltage = wm831x_buckp_set_voltage,
690 .get_voltage = wm831x_buckp_get_voltage, 697 .get_voltage_sel = wm831x_buckp_get_voltage_sel,
691 .list_voltage = wm831x_buckp_list_voltage, 698 .list_voltage = wm831x_buckp_list_voltage,
692 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, 699 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
693 700
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index 9edf8f692341..c94fc5b7cd5b 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -113,7 +113,8 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev,
113} 113}
114 114
115static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, 115static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg,
116 int min_uV, int max_uV) 116 int min_uV, int max_uV,
117 unsigned *selector)
117{ 118{
118 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 119 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
119 struct wm831x *wm831x = ldo->wm831x; 120 struct wm831x *wm831x = ldo->wm831x;
@@ -133,16 +134,20 @@ static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg,
133 if (ret < min_uV || ret > max_uV) 134 if (ret < min_uV || ret > max_uV)
134 return -EINVAL; 135 return -EINVAL;
135 136
137 *selector = vsel;
138
136 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); 139 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel);
137} 140}
138 141
139static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, 142static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev,
140 int min_uV, int max_uV) 143 int min_uV, int max_uV,
144 unsigned *selector)
141{ 145{
142 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 146 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
143 int reg = ldo->base + WM831X_LDO_ON_CONTROL; 147 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
144 148
145 return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV); 149 return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
150 selector);
146} 151}
147 152
148static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, 153static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -150,11 +155,12 @@ static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
150{ 155{
151 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 156 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
152 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 157 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
158 unsigned int selector;
153 159
154 return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV); 160 return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector);
155} 161}
156 162
157static int wm831x_gp_ldo_get_voltage(struct regulator_dev *rdev) 163static int wm831x_gp_ldo_get_voltage_sel(struct regulator_dev *rdev)
158{ 164{
159 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 165 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
160 struct wm831x *wm831x = ldo->wm831x; 166 struct wm831x *wm831x = ldo->wm831x;
@@ -167,7 +173,7 @@ static int wm831x_gp_ldo_get_voltage(struct regulator_dev *rdev)
167 173
168 ret &= WM831X_LDO1_ON_VSEL_MASK; 174 ret &= WM831X_LDO1_ON_VSEL_MASK;
169 175
170 return wm831x_gp_ldo_list_voltage(rdev, ret); 176 return ret;
171} 177}
172 178
173static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) 179static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
@@ -287,7 +293,7 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
287 293
288static struct regulator_ops wm831x_gp_ldo_ops = { 294static struct regulator_ops wm831x_gp_ldo_ops = {
289 .list_voltage = wm831x_gp_ldo_list_voltage, 295 .list_voltage = wm831x_gp_ldo_list_voltage,
290 .get_voltage = wm831x_gp_ldo_get_voltage, 296 .get_voltage_sel = wm831x_gp_ldo_get_voltage_sel,
291 .set_voltage = wm831x_gp_ldo_set_voltage, 297 .set_voltage = wm831x_gp_ldo_set_voltage,
292 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, 298 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
293 .get_mode = wm831x_gp_ldo_get_mode, 299 .get_mode = wm831x_gp_ldo_get_mode,
@@ -413,7 +419,8 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev,
413} 419}
414 420
415static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, 421static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg,
416 int min_uV, int max_uV) 422 int min_uV, int max_uV,
423 unsigned *selector)
417{ 424{
418 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 425 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
419 struct wm831x *wm831x = ldo->wm831x; 426 struct wm831x *wm831x = ldo->wm831x;
@@ -433,16 +440,19 @@ static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg,
433 if (ret < min_uV || ret > max_uV) 440 if (ret < min_uV || ret > max_uV)
434 return -EINVAL; 441 return -EINVAL;
435 442
443 *selector = vsel;
444
436 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); 445 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel);
437} 446}
438 447
439static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, 448static int wm831x_aldo_set_voltage(struct regulator_dev *rdev,
440 int min_uV, int max_uV) 449 int min_uV, int max_uV, unsigned *selector)
441{ 450{
442 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 451 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
443 int reg = ldo->base + WM831X_LDO_ON_CONTROL; 452 int reg = ldo->base + WM831X_LDO_ON_CONTROL;
444 453
445 return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV); 454 return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV,
455 selector);
446} 456}
447 457
448static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 458static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -450,11 +460,12 @@ static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
450{ 460{
451 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 461 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
452 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 462 int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
463 unsigned int selector;
453 464
454 return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV); 465 return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector);
455} 466}
456 467
457static int wm831x_aldo_get_voltage(struct regulator_dev *rdev) 468static int wm831x_aldo_get_voltage_sel(struct regulator_dev *rdev)
458{ 469{
459 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 470 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
460 struct wm831x *wm831x = ldo->wm831x; 471 struct wm831x *wm831x = ldo->wm831x;
@@ -467,7 +478,7 @@ static int wm831x_aldo_get_voltage(struct regulator_dev *rdev)
467 478
468 ret &= WM831X_LDO7_ON_VSEL_MASK; 479 ret &= WM831X_LDO7_ON_VSEL_MASK;
469 480
470 return wm831x_aldo_list_voltage(rdev, ret); 481 return ret;
471} 482}
472 483
473static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) 484static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
@@ -548,7 +559,7 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev)
548 559
549static struct regulator_ops wm831x_aldo_ops = { 560static struct regulator_ops wm831x_aldo_ops = {
550 .list_voltage = wm831x_aldo_list_voltage, 561 .list_voltage = wm831x_aldo_list_voltage,
551 .get_voltage = wm831x_aldo_get_voltage, 562 .get_voltage_sel = wm831x_aldo_get_voltage_sel,
552 .set_voltage = wm831x_aldo_set_voltage, 563 .set_voltage = wm831x_aldo_set_voltage,
553 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, 564 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
554 .get_mode = wm831x_aldo_get_mode, 565 .get_mode = wm831x_aldo_get_mode,
@@ -666,7 +677,8 @@ static int wm831x_alive_ldo_list_voltage(struct regulator_dev *rdev,
666 677
667static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, 678static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev,
668 int reg, 679 int reg,
669 int min_uV, int max_uV) 680 int min_uV, int max_uV,
681 unsigned *selector)
670{ 682{
671 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 683 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
672 struct wm831x *wm831x = ldo->wm831x; 684 struct wm831x *wm831x = ldo->wm831x;
@@ -680,16 +692,20 @@ static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev,
680 if (ret < min_uV || ret > max_uV) 692 if (ret < min_uV || ret > max_uV)
681 return -EINVAL; 693 return -EINVAL;
682 694
695 *selector = vsel;
696
683 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); 697 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel);
684} 698}
685 699
686static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, 700static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev,
687 int min_uV, int max_uV) 701 int min_uV, int max_uV,
702 unsigned *selector)
688{ 703{
689 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 704 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
690 int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; 705 int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
691 706
692 return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV); 707 return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV,
708 selector);
693} 709}
694 710
695static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, 711static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
@@ -697,11 +713,12 @@ static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
697{ 713{
698 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 714 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
699 int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; 715 int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
716 unsigned selector;
700 717
701 return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV); 718 return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector);
702} 719}
703 720
704static int wm831x_alive_ldo_get_voltage(struct regulator_dev *rdev) 721static int wm831x_alive_ldo_get_voltage_sel(struct regulator_dev *rdev)
705{ 722{
706 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 723 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
707 struct wm831x *wm831x = ldo->wm831x; 724 struct wm831x *wm831x = ldo->wm831x;
@@ -714,7 +731,7 @@ static int wm831x_alive_ldo_get_voltage(struct regulator_dev *rdev)
714 731
715 ret &= WM831X_LDO11_ON_VSEL_MASK; 732 ret &= WM831X_LDO11_ON_VSEL_MASK;
716 733
717 return wm831x_alive_ldo_list_voltage(rdev, ret); 734 return ret;
718} 735}
719 736
720static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) 737static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
@@ -736,7 +753,7 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
736 753
737static struct regulator_ops wm831x_alive_ldo_ops = { 754static struct regulator_ops wm831x_alive_ldo_ops = {
738 .list_voltage = wm831x_alive_ldo_list_voltage, 755 .list_voltage = wm831x_alive_ldo_list_voltage,
739 .get_voltage = wm831x_alive_ldo_get_voltage, 756 .get_voltage_sel = wm831x_alive_ldo_get_voltage_sel,
740 .set_voltage = wm831x_alive_ldo_set_voltage, 757 .set_voltage = wm831x_alive_ldo_set_voltage,
741 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, 758 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
742 .get_status = wm831x_alive_ldo_get_status, 759 .get_status = wm831x_alive_ldo_get_status,
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index fe4b8a8a9dfd..1bcb22c44095 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -360,7 +360,7 @@ int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
360EXPORT_SYMBOL_GPL(wm8350_isink_set_flash); 360EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
361 361
362static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV, 362static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
363 int max_uV) 363 int max_uV, unsigned *selector)
364{ 364{
365 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 365 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
366 int volt_reg, dcdc = rdev_get_id(rdev), mV, 366 int volt_reg, dcdc = rdev_get_id(rdev), mV,
@@ -397,17 +397,18 @@ static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
397 return -EINVAL; 397 return -EINVAL;
398 } 398 }
399 399
400 *selector = mV;
401
400 /* all DCDCs have same mV bits */ 402 /* all DCDCs have same mV bits */
401 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; 403 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
402 wm8350_reg_write(wm8350, volt_reg, val | mV); 404 wm8350_reg_write(wm8350, volt_reg, val | mV);
403 return 0; 405 return 0;
404} 406}
405 407
406static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev) 408static int wm8350_dcdc_get_voltage_sel(struct regulator_dev *rdev)
407{ 409{
408 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 410 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
409 int volt_reg, dcdc = rdev_get_id(rdev); 411 int volt_reg, dcdc = rdev_get_id(rdev);
410 u16 val;
411 412
412 switch (dcdc) { 413 switch (dcdc) {
413 case WM8350_DCDC_1: 414 case WM8350_DCDC_1:
@@ -429,8 +430,7 @@ static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev)
429 } 430 }
430 431
431 /* all DCDCs have same mV bits */ 432 /* all DCDCs have same mV bits */
432 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK; 433 return wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
433 return wm8350_dcdc_val_to_mvolts(val) * 1000;
434} 434}
435 435
436static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev, 436static int wm8350_dcdc_list_voltage(struct regulator_dev *rdev,
@@ -754,7 +754,7 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
754} 754}
755 755
756static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV, 756static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
757 int max_uV) 757 int max_uV, unsigned *selector)
758{ 758{
759 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 759 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
760 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000, 760 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
@@ -797,17 +797,18 @@ static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
797 return -EINVAL; 797 return -EINVAL;
798 } 798 }
799 799
800 *selector = mV;
801
800 /* all LDOs have same mV bits */ 802 /* all LDOs have same mV bits */
801 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; 803 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
802 wm8350_reg_write(wm8350, volt_reg, val | mV); 804 wm8350_reg_write(wm8350, volt_reg, val | mV);
803 return 0; 805 return 0;
804} 806}
805 807
806static int wm8350_ldo_get_voltage(struct regulator_dev *rdev) 808static int wm8350_ldo_get_voltage_sel(struct regulator_dev *rdev)
807{ 809{
808 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 810 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
809 int volt_reg, ldo = rdev_get_id(rdev); 811 int volt_reg, ldo = rdev_get_id(rdev);
810 u16 val;
811 812
812 switch (ldo) { 813 switch (ldo) {
813 case WM8350_LDO_1: 814 case WM8350_LDO_1:
@@ -827,8 +828,7 @@ static int wm8350_ldo_get_voltage(struct regulator_dev *rdev)
827 } 828 }
828 829
829 /* all LDOs have same mV bits */ 830 /* all LDOs have same mV bits */
830 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK; 831 return wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
831 return wm8350_ldo_val_to_mvolts(val) * 1000;
832} 832}
833 833
834static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, 834static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
@@ -1225,7 +1225,7 @@ static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
1225 1225
1226static struct regulator_ops wm8350_dcdc_ops = { 1226static struct regulator_ops wm8350_dcdc_ops = {
1227 .set_voltage = wm8350_dcdc_set_voltage, 1227 .set_voltage = wm8350_dcdc_set_voltage,
1228 .get_voltage = wm8350_dcdc_get_voltage, 1228 .get_voltage_sel = wm8350_dcdc_get_voltage_sel,
1229 .list_voltage = wm8350_dcdc_list_voltage, 1229 .list_voltage = wm8350_dcdc_list_voltage,
1230 .enable = wm8350_dcdc_enable, 1230 .enable = wm8350_dcdc_enable,
1231 .disable = wm8350_dcdc_disable, 1231 .disable = wm8350_dcdc_disable,
@@ -1249,7 +1249,7 @@ static struct regulator_ops wm8350_dcdc2_5_ops = {
1249 1249
1250static struct regulator_ops wm8350_ldo_ops = { 1250static struct regulator_ops wm8350_ldo_ops = {
1251 .set_voltage = wm8350_ldo_set_voltage, 1251 .set_voltage = wm8350_ldo_set_voltage,
1252 .get_voltage = wm8350_ldo_get_voltage, 1252 .get_voltage_sel = wm8350_ldo_get_voltage_sel,
1253 .list_voltage = wm8350_ldo_list_voltage, 1253 .list_voltage = wm8350_ldo_list_voltage,
1254 .enable = wm8350_ldo_enable, 1254 .enable = wm8350_ldo_enable,
1255 .disable = wm8350_ldo_disable, 1255 .disable = wm8350_ldo_disable,
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 924c7eb29ee9..b42d01cef35a 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -67,7 +67,7 @@ static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
67} 67}
68 68
69static int wm8400_ldo_set_voltage(struct regulator_dev *dev, 69static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
70 int min_uV, int max_uV) 70 int min_uV, int max_uV, unsigned *selector)
71{ 71{
72 struct wm8400 *wm8400 = rdev_get_drvdata(dev); 72 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
73 u16 val; 73 u16 val;
@@ -93,6 +93,8 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
93 val += 0xf; 93 val += 0xf;
94 } 94 }
95 95
96 *selector = val;
97
96 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), 98 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
97 WM8400_LDO1_VSEL_MASK, val); 99 WM8400_LDO1_VSEL_MASK, val);
98} 100}
@@ -156,7 +158,7 @@ static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
156} 158}
157 159
158static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, 160static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
159 int min_uV, int max_uV) 161 int min_uV, int max_uV, unsigned *selector)
160{ 162{
161 struct wm8400 *wm8400 = rdev_get_drvdata(dev); 163 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
162 u16 val; 164 u16 val;
@@ -171,6 +173,8 @@ static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
171 return -EINVAL; 173 return -EINVAL;
172 BUG_ON(850000 + (25000 * val) < min_uV); 174 BUG_ON(850000 + (25000 * val) < min_uV);
173 175
176 *selector = val;
177
174 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 178 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
175 WM8400_DC1_VSEL_MASK, val); 179 WM8400_DC1_VSEL_MASK, val);
176} 180}
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 03713bc66e4a..35b2958d5106 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -86,7 +86,7 @@ static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev,
86 return (selector * 100000) + 2400000; 86 return (selector * 100000) + 2400000;
87} 87}
88 88
89static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev) 89static int wm8994_ldo1_get_voltage_sel(struct regulator_dev *rdev)
90{ 90{
91 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 91 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
92 int val; 92 int val;
@@ -95,13 +95,11 @@ static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev)
95 if (val < 0) 95 if (val < 0)
96 return val; 96 return val;
97 97
98 val = (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT; 98 return (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT;
99
100 return wm8994_ldo1_list_voltage(rdev, val);
101} 99}
102 100
103static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev, 101static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
104 int min_uV, int max_uV) 102 int min_uV, int max_uV, unsigned *s)
105{ 103{
106 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 104 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
107 int selector, v; 105 int selector, v;
@@ -111,6 +109,7 @@ static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev,
111 if (v < 0 || v > max_uV) 109 if (v < 0 || v > max_uV)
112 return -EINVAL; 110 return -EINVAL;
113 111
112 *s = selector;
114 selector <<= WM8994_LDO1_VSEL_SHIFT; 113 selector <<= WM8994_LDO1_VSEL_SHIFT;
115 114
116 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1, 115 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1,
@@ -124,20 +123,29 @@ static struct regulator_ops wm8994_ldo1_ops = {
124 .enable_time = wm8994_ldo_enable_time, 123 .enable_time = wm8994_ldo_enable_time,
125 124
126 .list_voltage = wm8994_ldo1_list_voltage, 125 .list_voltage = wm8994_ldo1_list_voltage,
127 .get_voltage = wm8994_ldo1_get_voltage, 126 .get_voltage_sel = wm8994_ldo1_get_voltage_sel,
128 .set_voltage = wm8994_ldo1_set_voltage, 127 .set_voltage = wm8994_ldo1_set_voltage,
129}; 128};
130 129
131static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, 130static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev,
132 unsigned int selector) 131 unsigned int selector)
133{ 132{
133 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
134
134 if (selector > WM8994_LDO2_MAX_SELECTOR) 135 if (selector > WM8994_LDO2_MAX_SELECTOR)
135 return -EINVAL; 136 return -EINVAL;
136 137
137 return (selector * 100000) + 900000; 138 switch (ldo->wm8994->type) {
139 case WM8994:
140 return (selector * 100000) + 900000;
141 case WM8958:
142 return (selector * 100000) + 1000000;
143 default:
144 return -EINVAL;
145 }
138} 146}
139 147
140static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev) 148static int wm8994_ldo2_get_voltage_sel(struct regulator_dev *rdev)
141{ 149{
142 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 150 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
143 int val; 151 int val;
@@ -146,22 +154,31 @@ static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev)
146 if (val < 0) 154 if (val < 0)
147 return val; 155 return val;
148 156
149 val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT; 157 return (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT;
150
151 return wm8994_ldo2_list_voltage(rdev, val);
152} 158}
153 159
154static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev, 160static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev,
155 int min_uV, int max_uV) 161 int min_uV, int max_uV, unsigned *s)
156{ 162{
157 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); 163 struct wm8994_ldo *ldo = rdev_get_drvdata(rdev);
158 int selector, v; 164 int selector, v;
159 165
160 selector = (min_uV - 900000) / 100000; 166 switch (ldo->wm8994->type) {
167 case WM8994:
168 selector = (min_uV - 900000) / 100000;
169 break;
170 case WM8958:
171 selector = (min_uV - 1000000) / 100000;
172 break;
173 default:
174 return -EINVAL;
175 }
176
161 v = wm8994_ldo2_list_voltage(rdev, selector); 177 v = wm8994_ldo2_list_voltage(rdev, selector);
162 if (v < 0 || v > max_uV) 178 if (v < 0 || v > max_uV)
163 return -EINVAL; 179 return -EINVAL;
164 180
181 *s = selector;
165 selector <<= WM8994_LDO2_VSEL_SHIFT; 182 selector <<= WM8994_LDO2_VSEL_SHIFT;
166 183
167 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2, 184 return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2,
@@ -175,7 +192,7 @@ static struct regulator_ops wm8994_ldo2_ops = {
175 .enable_time = wm8994_ldo_enable_time, 192 .enable_time = wm8994_ldo_enable_time,
176 193
177 .list_voltage = wm8994_ldo2_list_voltage, 194 .list_voltage = wm8994_ldo2_list_voltage,
178 .get_voltage = wm8994_ldo2_get_voltage, 195 .get_voltage_sel = wm8994_ldo2_get_voltage_sel,
179 .set_voltage = wm8994_ldo2_set_voltage, 196 .set_voltage = wm8994_ldo2_set_voltage,
180}; 197};
181 198