Commit a0a7014cd40b1d1d13e121e5083bd3b2bbffe348

Authored by Linus Walleij
Committed by Mark Brown
1 parent db55168265

regulator: ab8500: provide per-regulator shift

This encodes the voltage shifts (the number of bits to shift
the register to get to the selector) into the regulator info.
We have several new variants of the AB8500 so this varies a
lot.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

Showing 1 changed file with 10 additions and 10 deletions Inline Diff

drivers/regulator/ab8500.c
1 /* 1 /*
2 * Copyright (C) ST-Ericsson SA 2010 2 * Copyright (C) ST-Ericsson SA 2010
3 * 3 *
4 * License Terms: GNU General Public License v2 4 * License Terms: GNU General Public License v2
5 * 5 *
6 * Authors: 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 * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
8 * 8 *
9 * AB8500 peripheral regulators 9 * AB8500 peripheral regulators
10 * 10 *
11 * AB8500 supports the following regulators: 11 * AB8500 supports the following regulators:
12 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA 12 * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
13 */ 13 */
14 #include <linux/init.h> 14 #include <linux/init.h>
15 #include <linux/kernel.h> 15 #include <linux/kernel.h>
16 #include <linux/module.h> 16 #include <linux/module.h>
17 #include <linux/err.h> 17 #include <linux/err.h>
18 #include <linux/platform_device.h> 18 #include <linux/platform_device.h>
19 #include <linux/mfd/abx500.h> 19 #include <linux/mfd/abx500.h>
20 #include <linux/mfd/abx500/ab8500.h> 20 #include <linux/mfd/abx500/ab8500.h>
21 #include <linux/of.h> 21 #include <linux/of.h>
22 #include <linux/regulator/of_regulator.h> 22 #include <linux/regulator/of_regulator.h>
23 #include <linux/regulator/driver.h> 23 #include <linux/regulator/driver.h>
24 #include <linux/regulator/machine.h> 24 #include <linux/regulator/machine.h>
25 #include <linux/regulator/ab8500.h> 25 #include <linux/regulator/ab8500.h>
26 #include <linux/slab.h> 26 #include <linux/slab.h>
27 27
28 /** 28 /**
29 * struct ab8500_regulator_info - ab8500 regulator information 29 * struct ab8500_regulator_info - ab8500 regulator information
30 * @dev: device pointer 30 * @dev: device pointer
31 * @desc: regulator description 31 * @desc: regulator description
32 * @regulator_dev: regulator device 32 * @regulator_dev: regulator device
33 * @update_bank: bank to control on/off 33 * @update_bank: bank to control on/off
34 * @update_reg: register to control on/off 34 * @update_reg: register to control on/off
35 * @update_mask: mask to enable/disable regulator 35 * @update_mask: mask to enable/disable regulator
36 * @update_val_enable: bits to enable the regulator in normal (high power) mode 36 * @update_val_enable: bits to enable the regulator in normal (high power) mode
37 * @voltage_bank: bank to control regulator voltage 37 * @voltage_bank: bank to control regulator voltage
38 * @voltage_reg: register to control regulator voltage 38 * @voltage_reg: register to control regulator voltage
39 * @voltage_mask: mask to control regulator voltage 39 * @voltage_mask: mask to control regulator voltage
40 * @voltage_shift: shift to control regulator voltage
40 * @delay: startup/set voltage delay in us 41 * @delay: startup/set voltage delay in us
41 */ 42 */
42 struct ab8500_regulator_info { 43 struct ab8500_regulator_info {
43 struct device *dev; 44 struct device *dev;
44 struct regulator_desc desc; 45 struct regulator_desc desc;
45 struct regulator_dev *regulator; 46 struct regulator_dev *regulator;
46 u8 update_bank; 47 u8 update_bank;
47 u8 update_reg; 48 u8 update_reg;
48 u8 update_mask; 49 u8 update_mask;
49 u8 update_val_enable; 50 u8 update_val_enable;
50 u8 voltage_bank; 51 u8 voltage_bank;
51 u8 voltage_reg; 52 u8 voltage_reg;
52 u8 voltage_mask; 53 u8 voltage_mask;
54 u8 voltage_shift;
53 unsigned int delay; 55 unsigned int delay;
54 }; 56 };
55 57
56 /* voltage tables for the vauxn/vintcore supplies */ 58 /* voltage tables for the vauxn/vintcore supplies */
57 static const unsigned int ldo_vauxn_voltages[] = { 59 static const unsigned int ldo_vauxn_voltages[] = {
58 1100000, 60 1100000,
59 1200000, 61 1200000,
60 1300000, 62 1300000,
61 1400000, 63 1400000,
62 1500000, 64 1500000,
63 1800000, 65 1800000,
64 1850000, 66 1850000,
65 1900000, 67 1900000,
66 2500000, 68 2500000,
67 2650000, 69 2650000,
68 2700000, 70 2700000,
69 2750000, 71 2750000,
70 2800000, 72 2800000,
71 2900000, 73 2900000,
72 3000000, 74 3000000,
73 3300000, 75 3300000,
74 }; 76 };
75 77
76 static const unsigned int ldo_vaux3_voltages[] = { 78 static const unsigned int ldo_vaux3_voltages[] = {
77 1200000, 79 1200000,
78 1500000, 80 1500000,
79 1800000, 81 1800000,
80 2100000, 82 2100000,
81 2500000, 83 2500000,
82 2750000, 84 2750000,
83 2790000, 85 2790000,
84 2910000, 86 2910000,
85 }; 87 };
86 88
87 static const unsigned int ldo_vintcore_voltages[] = { 89 static const unsigned int ldo_vintcore_voltages[] = {
88 1200000, 90 1200000,
89 1225000, 91 1225000,
90 1250000, 92 1250000,
91 1275000, 93 1275000,
92 1300000, 94 1300000,
93 1325000, 95 1325000,
94 1350000, 96 1350000,
95 }; 97 };
96 98
97 static int ab8500_regulator_enable(struct regulator_dev *rdev) 99 static int ab8500_regulator_enable(struct regulator_dev *rdev)
98 { 100 {
99 int ret; 101 int ret;
100 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 102 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
101 103
102 if (info == NULL) { 104 if (info == NULL) {
103 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); 105 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
104 return -EINVAL; 106 return -EINVAL;
105 } 107 }
106 108
107 ret = abx500_mask_and_set_register_interruptible(info->dev, 109 ret = abx500_mask_and_set_register_interruptible(info->dev,
108 info->update_bank, info->update_reg, 110 info->update_bank, info->update_reg,
109 info->update_mask, info->update_val_enable); 111 info->update_mask, info->update_val_enable);
110 if (ret < 0) 112 if (ret < 0)
111 dev_err(rdev_get_dev(rdev), 113 dev_err(rdev_get_dev(rdev),
112 "couldn't set enable bits for regulator\n"); 114 "couldn't set enable bits for regulator\n");
113 115
114 dev_vdbg(rdev_get_dev(rdev), 116 dev_vdbg(rdev_get_dev(rdev),
115 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", 117 "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
116 info->desc.name, info->update_bank, info->update_reg, 118 info->desc.name, info->update_bank, info->update_reg,
117 info->update_mask, info->update_val_enable); 119 info->update_mask, info->update_val_enable);
118 120
119 return ret; 121 return ret;
120 } 122 }
121 123
122 static int ab8500_regulator_disable(struct regulator_dev *rdev) 124 static int ab8500_regulator_disable(struct regulator_dev *rdev)
123 { 125 {
124 int ret; 126 int ret;
125 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 127 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
126 128
127 if (info == NULL) { 129 if (info == NULL) {
128 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); 130 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
129 return -EINVAL; 131 return -EINVAL;
130 } 132 }
131 133
132 ret = abx500_mask_and_set_register_interruptible(info->dev, 134 ret = abx500_mask_and_set_register_interruptible(info->dev,
133 info->update_bank, info->update_reg, 135 info->update_bank, info->update_reg,
134 info->update_mask, 0x0); 136 info->update_mask, 0x0);
135 if (ret < 0) 137 if (ret < 0)
136 dev_err(rdev_get_dev(rdev), 138 dev_err(rdev_get_dev(rdev),
137 "couldn't set disable bits for regulator\n"); 139 "couldn't set disable bits for regulator\n");
138 140
139 dev_vdbg(rdev_get_dev(rdev), 141 dev_vdbg(rdev_get_dev(rdev),
140 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", 142 "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
141 info->desc.name, info->update_bank, info->update_reg, 143 info->desc.name, info->update_bank, info->update_reg,
142 info->update_mask, 0x0); 144 info->update_mask, 0x0);
143 145
144 return ret; 146 return ret;
145 } 147 }
146 148
147 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) 149 static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
148 { 150 {
149 int ret; 151 int ret;
150 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 152 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
151 u8 regval; 153 u8 regval;
152 154
153 if (info == NULL) { 155 if (info == NULL) {
154 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); 156 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
155 return -EINVAL; 157 return -EINVAL;
156 } 158 }
157 159
158 ret = abx500_get_register_interruptible(info->dev, 160 ret = abx500_get_register_interruptible(info->dev,
159 info->update_bank, info->update_reg, &regval); 161 info->update_bank, info->update_reg, &regval);
160 if (ret < 0) { 162 if (ret < 0) {
161 dev_err(rdev_get_dev(rdev), 163 dev_err(rdev_get_dev(rdev),
162 "couldn't read 0x%x register\n", info->update_reg); 164 "couldn't read 0x%x register\n", info->update_reg);
163 return ret; 165 return ret;
164 } 166 }
165 167
166 dev_vdbg(rdev_get_dev(rdev), 168 dev_vdbg(rdev_get_dev(rdev),
167 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," 169 "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
168 " 0x%x\n", 170 " 0x%x\n",
169 info->desc.name, info->update_bank, info->update_reg, 171 info->desc.name, info->update_bank, info->update_reg,
170 info->update_mask, regval); 172 info->update_mask, regval);
171 173
172 if (regval & info->update_mask) 174 if (regval & info->update_mask)
173 return true; 175 return true;
174 else 176 else
175 return false; 177 return false;
176 } 178 }
177 179
178 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) 180 static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
179 { 181 {
180 int ret, val; 182 int ret, val;
181 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 183 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
182 u8 regval; 184 u8 regval;
183 185
184 if (info == NULL) { 186 if (info == NULL) {
185 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); 187 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
186 return -EINVAL; 188 return -EINVAL;
187 } 189 }
188 190
189 ret = abx500_get_register_interruptible(info->dev, 191 ret = abx500_get_register_interruptible(info->dev,
190 info->voltage_bank, info->voltage_reg, &regval); 192 info->voltage_bank, info->voltage_reg, &regval);
191 if (ret < 0) { 193 if (ret < 0) {
192 dev_err(rdev_get_dev(rdev), 194 dev_err(rdev_get_dev(rdev),
193 "couldn't read voltage reg for regulator\n"); 195 "couldn't read voltage reg for regulator\n");
194 return ret; 196 return ret;
195 } 197 }
196 198
197 dev_vdbg(rdev_get_dev(rdev), 199 dev_vdbg(rdev_get_dev(rdev),
198 "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," 200 "%s-get_voltage (bank, reg, mask, shift, value): "
199 " 0x%x\n", 201 "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
200 info->desc.name, info->voltage_bank, info->voltage_reg, 202 info->desc.name, info->voltage_bank,
201 info->voltage_mask, regval); 203 info->voltage_reg, info->voltage_mask,
204 info->voltage_shift, regval);
202 205
203 /* vintcore has a different layout */
204 val = regval & info->voltage_mask; 206 val = regval & info->voltage_mask;
205 if (info->desc.id == AB8500_LDO_INTCORE) 207 return val >> info->voltage_shift;
206 return val >> 0x3;
207 else
208 return val;
209 } 208 }
210 209
211 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, 210 static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
212 unsigned selector) 211 unsigned selector)
213 { 212 {
214 int ret; 213 int ret;
215 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 214 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
216 u8 regval; 215 u8 regval;
217 216
218 if (info == NULL) { 217 if (info == NULL) {
219 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); 218 dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
220 return -EINVAL; 219 return -EINVAL;
221 } 220 }
222 221
223 /* set the registers for the request */ 222 /* set the registers for the request */
224 regval = (u8)selector; 223 regval = (u8)selector << info->voltage_shift;
225 ret = abx500_mask_and_set_register_interruptible(info->dev, 224 ret = abx500_mask_and_set_register_interruptible(info->dev,
226 info->voltage_bank, info->voltage_reg, 225 info->voltage_bank, info->voltage_reg,
227 info->voltage_mask, regval); 226 info->voltage_mask, regval);
228 if (ret < 0) 227 if (ret < 0)
229 dev_err(rdev_get_dev(rdev), 228 dev_err(rdev_get_dev(rdev),
230 "couldn't set voltage reg for regulator\n"); 229 "couldn't set voltage reg for regulator\n");
231 230
232 dev_vdbg(rdev_get_dev(rdev), 231 dev_vdbg(rdev_get_dev(rdev),
233 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," 232 "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
234 " 0x%x\n", 233 " 0x%x\n",
235 info->desc.name, info->voltage_bank, info->voltage_reg, 234 info->desc.name, info->voltage_bank, info->voltage_reg,
236 info->voltage_mask, regval); 235 info->voltage_mask, regval);
237 236
238 return ret; 237 return ret;
239 } 238 }
240 239
241 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, 240 static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
242 unsigned int old_sel, 241 unsigned int old_sel,
243 unsigned int new_sel) 242 unsigned int new_sel)
244 { 243 {
245 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); 244 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
246 245
247 return info->delay; 246 return info->delay;
248 } 247 }
249 248
250 static struct regulator_ops ab8500_regulator_ops = { 249 static struct regulator_ops ab8500_regulator_ops = {
251 .enable = ab8500_regulator_enable, 250 .enable = ab8500_regulator_enable,
252 .disable = ab8500_regulator_disable, 251 .disable = ab8500_regulator_disable,
253 .is_enabled = ab8500_regulator_is_enabled, 252 .is_enabled = ab8500_regulator_is_enabled,
254 .get_voltage_sel = ab8500_regulator_get_voltage_sel, 253 .get_voltage_sel = ab8500_regulator_get_voltage_sel,
255 .set_voltage_sel = ab8500_regulator_set_voltage_sel, 254 .set_voltage_sel = ab8500_regulator_set_voltage_sel,
256 .list_voltage = regulator_list_voltage_table, 255 .list_voltage = regulator_list_voltage_table,
257 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, 256 .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
258 }; 257 };
259 258
260 static struct regulator_ops ab8500_regulator_fixed_ops = { 259 static struct regulator_ops ab8500_regulator_fixed_ops = {
261 .enable = ab8500_regulator_enable, 260 .enable = ab8500_regulator_enable,
262 .disable = ab8500_regulator_disable, 261 .disable = ab8500_regulator_disable,
263 .is_enabled = ab8500_regulator_is_enabled, 262 .is_enabled = ab8500_regulator_is_enabled,
264 .list_voltage = regulator_list_voltage_linear, 263 .list_voltage = regulator_list_voltage_linear,
265 }; 264 };
266 265
267 static struct ab8500_regulator_info 266 static struct ab8500_regulator_info
268 ab8500_regulator_info[AB8500_NUM_REGULATORS] = { 267 ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
269 /* 268 /*
270 * Variable Voltage Regulators 269 * Variable Voltage Regulators
271 * name, min mV, max mV, 270 * name, min mV, max mV,
272 * update bank, reg, mask, enable val 271 * update bank, reg, mask, enable val
273 * volt bank, reg, mask 272 * volt bank, reg, mask
274 */ 273 */
275 [AB8500_LDO_AUX1] = { 274 [AB8500_LDO_AUX1] = {
276 .desc = { 275 .desc = {
277 .name = "LDO-AUX1", 276 .name = "LDO-AUX1",
278 .ops = &ab8500_regulator_ops, 277 .ops = &ab8500_regulator_ops,
279 .type = REGULATOR_VOLTAGE, 278 .type = REGULATOR_VOLTAGE,
280 .id = AB8500_LDO_AUX1, 279 .id = AB8500_LDO_AUX1,
281 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
282 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), 281 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
283 .volt_table = ldo_vauxn_voltages, 282 .volt_table = ldo_vauxn_voltages,
284 }, 283 },
285 .update_bank = 0x04, 284 .update_bank = 0x04,
286 .update_reg = 0x09, 285 .update_reg = 0x09,
287 .update_mask = 0x03, 286 .update_mask = 0x03,
288 .update_val_enable = 0x01, 287 .update_val_enable = 0x01,
289 .voltage_bank = 0x04, 288 .voltage_bank = 0x04,
290 .voltage_reg = 0x1f, 289 .voltage_reg = 0x1f,
291 .voltage_mask = 0x0f, 290 .voltage_mask = 0x0f,
292 }, 291 },
293 [AB8500_LDO_AUX2] = { 292 [AB8500_LDO_AUX2] = {
294 .desc = { 293 .desc = {
295 .name = "LDO-AUX2", 294 .name = "LDO-AUX2",
296 .ops = &ab8500_regulator_ops, 295 .ops = &ab8500_regulator_ops,
297 .type = REGULATOR_VOLTAGE, 296 .type = REGULATOR_VOLTAGE,
298 .id = AB8500_LDO_AUX2, 297 .id = AB8500_LDO_AUX2,
299 .owner = THIS_MODULE, 298 .owner = THIS_MODULE,
300 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), 299 .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
301 .volt_table = ldo_vauxn_voltages, 300 .volt_table = ldo_vauxn_voltages,
302 }, 301 },
303 .update_bank = 0x04, 302 .update_bank = 0x04,
304 .update_reg = 0x09, 303 .update_reg = 0x09,
305 .update_mask = 0x0c, 304 .update_mask = 0x0c,
306 .update_val_enable = 0x04, 305 .update_val_enable = 0x04,
307 .voltage_bank = 0x04, 306 .voltage_bank = 0x04,
308 .voltage_reg = 0x20, 307 .voltage_reg = 0x20,
309 .voltage_mask = 0x0f, 308 .voltage_mask = 0x0f,
310 }, 309 },
311 [AB8500_LDO_AUX3] = { 310 [AB8500_LDO_AUX3] = {
312 .desc = { 311 .desc = {
313 .name = "LDO-AUX3", 312 .name = "LDO-AUX3",
314 .ops = &ab8500_regulator_ops, 313 .ops = &ab8500_regulator_ops,
315 .type = REGULATOR_VOLTAGE, 314 .type = REGULATOR_VOLTAGE,
316 .id = AB8500_LDO_AUX3, 315 .id = AB8500_LDO_AUX3,
317 .owner = THIS_MODULE, 316 .owner = THIS_MODULE,
318 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), 317 .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
319 .volt_table = ldo_vaux3_voltages, 318 .volt_table = ldo_vaux3_voltages,
320 }, 319 },
321 .update_bank = 0x04, 320 .update_bank = 0x04,
322 .update_reg = 0x0a, 321 .update_reg = 0x0a,
323 .update_mask = 0x03, 322 .update_mask = 0x03,
324 .update_val_enable = 0x01, 323 .update_val_enable = 0x01,
325 .voltage_bank = 0x04, 324 .voltage_bank = 0x04,
326 .voltage_reg = 0x21, 325 .voltage_reg = 0x21,
327 .voltage_mask = 0x07, 326 .voltage_mask = 0x07,
328 }, 327 },
329 [AB8500_LDO_INTCORE] = { 328 [AB8500_LDO_INTCORE] = {
330 .desc = { 329 .desc = {
331 .name = "LDO-INTCORE", 330 .name = "LDO-INTCORE",
332 .ops = &ab8500_regulator_ops, 331 .ops = &ab8500_regulator_ops,
333 .type = REGULATOR_VOLTAGE, 332 .type = REGULATOR_VOLTAGE,
334 .id = AB8500_LDO_INTCORE, 333 .id = AB8500_LDO_INTCORE,
335 .owner = THIS_MODULE, 334 .owner = THIS_MODULE,
336 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), 335 .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
337 .volt_table = ldo_vintcore_voltages, 336 .volt_table = ldo_vintcore_voltages,
338 }, 337 },
339 .update_bank = 0x03, 338 .update_bank = 0x03,
340 .update_reg = 0x80, 339 .update_reg = 0x80,
341 .update_mask = 0x44, 340 .update_mask = 0x44,
342 .update_val_enable = 0x04, 341 .update_val_enable = 0x04,
343 .voltage_bank = 0x03, 342 .voltage_bank = 0x03,
344 .voltage_reg = 0x80, 343 .voltage_reg = 0x80,
345 .voltage_mask = 0x38, 344 .voltage_mask = 0x38,
345 .voltage_shift = 3,
346 }, 346 },
347 347
348 /* 348 /*
349 * Fixed Voltage Regulators 349 * Fixed Voltage Regulators
350 * name, fixed mV, 350 * name, fixed mV,
351 * update bank, reg, mask, enable val 351 * update bank, reg, mask, enable val
352 */ 352 */
353 [AB8500_LDO_TVOUT] = { 353 [AB8500_LDO_TVOUT] = {
354 .desc = { 354 .desc = {
355 .name = "LDO-TVOUT", 355 .name = "LDO-TVOUT",
356 .ops = &ab8500_regulator_fixed_ops, 356 .ops = &ab8500_regulator_fixed_ops,
357 .type = REGULATOR_VOLTAGE, 357 .type = REGULATOR_VOLTAGE,
358 .id = AB8500_LDO_TVOUT, 358 .id = AB8500_LDO_TVOUT,
359 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
360 .n_voltages = 1, 360 .n_voltages = 1,
361 .min_uV = 2000000, 361 .min_uV = 2000000,
362 .enable_time = 10000, 362 .enable_time = 10000,
363 }, 363 },
364 .delay = 10000, 364 .delay = 10000,
365 .update_bank = 0x03, 365 .update_bank = 0x03,
366 .update_reg = 0x80, 366 .update_reg = 0x80,
367 .update_mask = 0x82, 367 .update_mask = 0x82,
368 .update_val_enable = 0x02, 368 .update_val_enable = 0x02,
369 }, 369 },
370 [AB8500_LDO_USB] = { 370 [AB8500_LDO_USB] = {
371 .desc = { 371 .desc = {
372 .name = "LDO-USB", 372 .name = "LDO-USB",
373 .ops = &ab8500_regulator_fixed_ops, 373 .ops = &ab8500_regulator_fixed_ops,
374 .type = REGULATOR_VOLTAGE, 374 .type = REGULATOR_VOLTAGE,
375 .id = AB8500_LDO_USB, 375 .id = AB8500_LDO_USB,
376 .owner = THIS_MODULE, 376 .owner = THIS_MODULE,
377 .n_voltages = 1, 377 .n_voltages = 1,
378 .min_uV = 3300000, 378 .min_uV = 3300000,
379 }, 379 },
380 .update_bank = 0x03, 380 .update_bank = 0x03,
381 .update_reg = 0x82, 381 .update_reg = 0x82,
382 .update_mask = 0x03, 382 .update_mask = 0x03,
383 .update_val_enable = 0x01, 383 .update_val_enable = 0x01,
384 }, 384 },
385 [AB8500_LDO_AUDIO] = { 385 [AB8500_LDO_AUDIO] = {
386 .desc = { 386 .desc = {
387 .name = "LDO-AUDIO", 387 .name = "LDO-AUDIO",
388 .ops = &ab8500_regulator_fixed_ops, 388 .ops = &ab8500_regulator_fixed_ops,
389 .type = REGULATOR_VOLTAGE, 389 .type = REGULATOR_VOLTAGE,
390 .id = AB8500_LDO_AUDIO, 390 .id = AB8500_LDO_AUDIO,
391 .owner = THIS_MODULE, 391 .owner = THIS_MODULE,
392 .n_voltages = 1, 392 .n_voltages = 1,
393 .min_uV = 2000000, 393 .min_uV = 2000000,
394 }, 394 },
395 .update_bank = 0x03, 395 .update_bank = 0x03,
396 .update_reg = 0x83, 396 .update_reg = 0x83,
397 .update_mask = 0x02, 397 .update_mask = 0x02,
398 .update_val_enable = 0x02, 398 .update_val_enable = 0x02,
399 }, 399 },
400 [AB8500_LDO_ANAMIC1] = { 400 [AB8500_LDO_ANAMIC1] = {
401 .desc = { 401 .desc = {
402 .name = "LDO-ANAMIC1", 402 .name = "LDO-ANAMIC1",
403 .ops = &ab8500_regulator_fixed_ops, 403 .ops = &ab8500_regulator_fixed_ops,
404 .type = REGULATOR_VOLTAGE, 404 .type = REGULATOR_VOLTAGE,
405 .id = AB8500_LDO_ANAMIC1, 405 .id = AB8500_LDO_ANAMIC1,
406 .owner = THIS_MODULE, 406 .owner = THIS_MODULE,
407 .n_voltages = 1, 407 .n_voltages = 1,
408 .min_uV = 2050000, 408 .min_uV = 2050000,
409 }, 409 },
410 .update_bank = 0x03, 410 .update_bank = 0x03,
411 .update_reg = 0x83, 411 .update_reg = 0x83,
412 .update_mask = 0x08, 412 .update_mask = 0x08,
413 .update_val_enable = 0x08, 413 .update_val_enable = 0x08,
414 }, 414 },
415 [AB8500_LDO_ANAMIC2] = { 415 [AB8500_LDO_ANAMIC2] = {
416 .desc = { 416 .desc = {
417 .name = "LDO-ANAMIC2", 417 .name = "LDO-ANAMIC2",
418 .ops = &ab8500_regulator_fixed_ops, 418 .ops = &ab8500_regulator_fixed_ops,
419 .type = REGULATOR_VOLTAGE, 419 .type = REGULATOR_VOLTAGE,
420 .id = AB8500_LDO_ANAMIC2, 420 .id = AB8500_LDO_ANAMIC2,
421 .owner = THIS_MODULE, 421 .owner = THIS_MODULE,
422 .n_voltages = 1, 422 .n_voltages = 1,
423 .min_uV = 2050000, 423 .min_uV = 2050000,
424 }, 424 },
425 .update_bank = 0x03, 425 .update_bank = 0x03,
426 .update_reg = 0x83, 426 .update_reg = 0x83,
427 .update_mask = 0x10, 427 .update_mask = 0x10,
428 .update_val_enable = 0x10, 428 .update_val_enable = 0x10,
429 }, 429 },
430 [AB8500_LDO_DMIC] = { 430 [AB8500_LDO_DMIC] = {
431 .desc = { 431 .desc = {
432 .name = "LDO-DMIC", 432 .name = "LDO-DMIC",
433 .ops = &ab8500_regulator_fixed_ops, 433 .ops = &ab8500_regulator_fixed_ops,
434 .type = REGULATOR_VOLTAGE, 434 .type = REGULATOR_VOLTAGE,
435 .id = AB8500_LDO_DMIC, 435 .id = AB8500_LDO_DMIC,
436 .owner = THIS_MODULE, 436 .owner = THIS_MODULE,
437 .n_voltages = 1, 437 .n_voltages = 1,
438 .min_uV = 1800000, 438 .min_uV = 1800000,
439 }, 439 },
440 .update_bank = 0x03, 440 .update_bank = 0x03,
441 .update_reg = 0x83, 441 .update_reg = 0x83,
442 .update_mask = 0x04, 442 .update_mask = 0x04,
443 .update_val_enable = 0x04, 443 .update_val_enable = 0x04,
444 }, 444 },
445 [AB8500_LDO_ANA] = { 445 [AB8500_LDO_ANA] = {
446 .desc = { 446 .desc = {
447 .name = "LDO-ANA", 447 .name = "LDO-ANA",
448 .ops = &ab8500_regulator_fixed_ops, 448 .ops = &ab8500_regulator_fixed_ops,
449 .type = REGULATOR_VOLTAGE, 449 .type = REGULATOR_VOLTAGE,
450 .id = AB8500_LDO_ANA, 450 .id = AB8500_LDO_ANA,
451 .owner = THIS_MODULE, 451 .owner = THIS_MODULE,
452 .n_voltages = 1, 452 .n_voltages = 1,
453 .min_uV = 1200000, 453 .min_uV = 1200000,
454 }, 454 },
455 .update_bank = 0x04, 455 .update_bank = 0x04,
456 .update_reg = 0x06, 456 .update_reg = 0x06,
457 .update_mask = 0x0c, 457 .update_mask = 0x0c,
458 .update_val_enable = 0x04, 458 .update_val_enable = 0x04,
459 }, 459 },
460 460
461 461
462 }; 462 };
463 463
464 struct ab8500_reg_init { 464 struct ab8500_reg_init {
465 u8 bank; 465 u8 bank;
466 u8 addr; 466 u8 addr;
467 u8 mask; 467 u8 mask;
468 }; 468 };
469 469
470 #define REG_INIT(_id, _bank, _addr, _mask) \ 470 #define REG_INIT(_id, _bank, _addr, _mask) \
471 [_id] = { \ 471 [_id] = { \
472 .bank = _bank, \ 472 .bank = _bank, \
473 .addr = _addr, \ 473 .addr = _addr, \
474 .mask = _mask, \ 474 .mask = _mask, \
475 } 475 }
476 476
477 static struct ab8500_reg_init ab8500_reg_init[] = { 477 static struct ab8500_reg_init ab8500_reg_init[] = {
478 /* 478 /*
479 * 0x30, VanaRequestCtrl 479 * 0x30, VanaRequestCtrl
480 * 0x0C, VpllRequestCtrl 480 * 0x0C, VpllRequestCtrl
481 * 0xc0, VextSupply1RequestCtrl 481 * 0xc0, VextSupply1RequestCtrl
482 */ 482 */
483 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc), 483 REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
484 /* 484 /*
485 * 0x03, VextSupply2RequestCtrl 485 * 0x03, VextSupply2RequestCtrl
486 * 0x0c, VextSupply3RequestCtrl 486 * 0x0c, VextSupply3RequestCtrl
487 * 0x30, Vaux1RequestCtrl 487 * 0x30, Vaux1RequestCtrl
488 * 0xc0, Vaux2RequestCtrl 488 * 0xc0, Vaux2RequestCtrl
489 */ 489 */
490 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff), 490 REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
491 /* 491 /*
492 * 0x03, Vaux3RequestCtrl 492 * 0x03, Vaux3RequestCtrl
493 * 0x04, SwHPReq 493 * 0x04, SwHPReq
494 */ 494 */
495 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07), 495 REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
496 /* 496 /*
497 * 0x08, VanaSysClkReq1HPValid 497 * 0x08, VanaSysClkReq1HPValid
498 * 0x20, Vaux1SysClkReq1HPValid 498 * 0x20, Vaux1SysClkReq1HPValid
499 * 0x40, Vaux2SysClkReq1HPValid 499 * 0x40, Vaux2SysClkReq1HPValid
500 * 0x80, Vaux3SysClkReq1HPValid 500 * 0x80, Vaux3SysClkReq1HPValid
501 */ 501 */
502 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8), 502 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
503 /* 503 /*
504 * 0x10, VextSupply1SysClkReq1HPValid 504 * 0x10, VextSupply1SysClkReq1HPValid
505 * 0x20, VextSupply2SysClkReq1HPValid 505 * 0x20, VextSupply2SysClkReq1HPValid
506 * 0x40, VextSupply3SysClkReq1HPValid 506 * 0x40, VextSupply3SysClkReq1HPValid
507 */ 507 */
508 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70), 508 REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
509 /* 509 /*
510 * 0x08, VanaHwHPReq1Valid 510 * 0x08, VanaHwHPReq1Valid
511 * 0x20, Vaux1HwHPReq1Valid 511 * 0x20, Vaux1HwHPReq1Valid
512 * 0x40, Vaux2HwHPReq1Valid 512 * 0x40, Vaux2HwHPReq1Valid
513 * 0x80, Vaux3HwHPReq1Valid 513 * 0x80, Vaux3HwHPReq1Valid
514 */ 514 */
515 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8), 515 REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
516 /* 516 /*
517 * 0x01, VextSupply1HwHPReq1Valid 517 * 0x01, VextSupply1HwHPReq1Valid
518 * 0x02, VextSupply2HwHPReq1Valid 518 * 0x02, VextSupply2HwHPReq1Valid
519 * 0x04, VextSupply3HwHPReq1Valid 519 * 0x04, VextSupply3HwHPReq1Valid
520 */ 520 */
521 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07), 521 REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
522 /* 522 /*
523 * 0x08, VanaHwHPReq2Valid 523 * 0x08, VanaHwHPReq2Valid
524 * 0x20, Vaux1HwHPReq2Valid 524 * 0x20, Vaux1HwHPReq2Valid
525 * 0x40, Vaux2HwHPReq2Valid 525 * 0x40, Vaux2HwHPReq2Valid
526 * 0x80, Vaux3HwHPReq2Valid 526 * 0x80, Vaux3HwHPReq2Valid
527 */ 527 */
528 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8), 528 REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
529 /* 529 /*
530 * 0x01, VextSupply1HwHPReq2Valid 530 * 0x01, VextSupply1HwHPReq2Valid
531 * 0x02, VextSupply2HwHPReq2Valid 531 * 0x02, VextSupply2HwHPReq2Valid
532 * 0x04, VextSupply3HwHPReq2Valid 532 * 0x04, VextSupply3HwHPReq2Valid
533 */ 533 */
534 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07), 534 REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
535 /* 535 /*
536 * 0x20, VanaSwHPReqValid 536 * 0x20, VanaSwHPReqValid
537 * 0x80, Vaux1SwHPReqValid 537 * 0x80, Vaux1SwHPReqValid
538 */ 538 */
539 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0), 539 REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
540 /* 540 /*
541 * 0x01, Vaux2SwHPReqValid 541 * 0x01, Vaux2SwHPReqValid
542 * 0x02, Vaux3SwHPReqValid 542 * 0x02, Vaux3SwHPReqValid
543 * 0x04, VextSupply1SwHPReqValid 543 * 0x04, VextSupply1SwHPReqValid
544 * 0x08, VextSupply2SwHPReqValid 544 * 0x08, VextSupply2SwHPReqValid
545 * 0x10, VextSupply3SwHPReqValid 545 * 0x10, VextSupply3SwHPReqValid
546 */ 546 */
547 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f), 547 REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
548 /* 548 /*
549 * 0x02, SysClkReq2Valid1 549 * 0x02, SysClkReq2Valid1
550 * ... 550 * ...
551 * 0x80, SysClkReq8Valid1 551 * 0x80, SysClkReq8Valid1
552 */ 552 */
553 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe), 553 REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
554 /* 554 /*
555 * 0x02, SysClkReq2Valid2 555 * 0x02, SysClkReq2Valid2
556 * ... 556 * ...
557 * 0x80, SysClkReq8Valid2 557 * 0x80, SysClkReq8Valid2
558 */ 558 */
559 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe), 559 REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
560 /* 560 /*
561 * 0x02, VTVoutEna 561 * 0x02, VTVoutEna
562 * 0x04, Vintcore12Ena 562 * 0x04, Vintcore12Ena
563 * 0x38, Vintcore12Sel 563 * 0x38, Vintcore12Sel
564 * 0x40, Vintcore12LP 564 * 0x40, Vintcore12LP
565 * 0x80, VTVoutLP 565 * 0x80, VTVoutLP
566 */ 566 */
567 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe), 567 REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
568 /* 568 /*
569 * 0x02, VaudioEna 569 * 0x02, VaudioEna
570 * 0x04, VdmicEna 570 * 0x04, VdmicEna
571 * 0x08, Vamic1Ena 571 * 0x08, Vamic1Ena
572 * 0x10, Vamic2Ena 572 * 0x10, Vamic2Ena
573 */ 573 */
574 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e), 574 REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
575 /* 575 /*
576 * 0x01, Vamic1_dzout 576 * 0x01, Vamic1_dzout
577 * 0x02, Vamic2_dzout 577 * 0x02, Vamic2_dzout
578 */ 578 */
579 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03), 579 REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
580 /* 580 /*
581 * 0x0c, VanaRegu 581 * 0x0c, VanaRegu
582 * 0x03, VpllRegu 582 * 0x03, VpllRegu
583 */ 583 */
584 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f), 584 REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
585 /* 585 /*
586 * 0x01, VrefDDREna 586 * 0x01, VrefDDREna
587 * 0x02, VrefDDRSleepMode 587 * 0x02, VrefDDRSleepMode
588 */ 588 */
589 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03), 589 REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
590 /* 590 /*
591 * 0x03, VextSupply1Regu 591 * 0x03, VextSupply1Regu
592 * 0x0c, VextSupply2Regu 592 * 0x0c, VextSupply2Regu
593 * 0x30, VextSupply3Regu 593 * 0x30, VextSupply3Regu
594 * 0x40, ExtSupply2Bypass 594 * 0x40, ExtSupply2Bypass
595 * 0x80, ExtSupply3Bypass 595 * 0x80, ExtSupply3Bypass
596 */ 596 */
597 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff), 597 REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
598 /* 598 /*
599 * 0x03, Vaux1Regu 599 * 0x03, Vaux1Regu
600 * 0x0c, Vaux2Regu 600 * 0x0c, Vaux2Regu
601 */ 601 */
602 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f), 602 REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
603 /* 603 /*
604 * 0x03, Vaux3Regu 604 * 0x03, Vaux3Regu
605 */ 605 */
606 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03), 606 REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
607 /* 607 /*
608 * 0x3f, Vsmps1Sel1 608 * 0x3f, Vsmps1Sel1
609 */ 609 */
610 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f), 610 REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
611 /* 611 /*
612 * 0x0f, Vaux1Sel 612 * 0x0f, Vaux1Sel
613 */ 613 */
614 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f), 614 REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
615 /* 615 /*
616 * 0x0f, Vaux2Sel 616 * 0x0f, Vaux2Sel
617 */ 617 */
618 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f), 618 REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
619 /* 619 /*
620 * 0x07, Vaux3Sel 620 * 0x07, Vaux3Sel
621 */ 621 */
622 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07), 622 REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
623 /* 623 /*
624 * 0x01, VextSupply12LP 624 * 0x01, VextSupply12LP
625 */ 625 */
626 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01), 626 REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
627 /* 627 /*
628 * 0x04, Vaux1Disch 628 * 0x04, Vaux1Disch
629 * 0x08, Vaux2Disch 629 * 0x08, Vaux2Disch
630 * 0x10, Vaux3Disch 630 * 0x10, Vaux3Disch
631 * 0x20, Vintcore12Disch 631 * 0x20, Vintcore12Disch
632 * 0x40, VTVoutDisch 632 * 0x40, VTVoutDisch
633 * 0x80, VaudioDisch 633 * 0x80, VaudioDisch
634 */ 634 */
635 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc), 635 REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
636 /* 636 /*
637 * 0x02, VanaDisch 637 * 0x02, VanaDisch
638 * 0x04, VdmicPullDownEna 638 * 0x04, VdmicPullDownEna
639 * 0x10, VdmicDisch 639 * 0x10, VdmicDisch
640 */ 640 */
641 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), 641 REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
642 }; 642 };
643 643
644 static __devinit int 644 static __devinit int
645 ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value) 645 ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
646 { 646 {
647 int err; 647 int err;
648 648
649 if (value & ~ab8500_reg_init[id].mask) { 649 if (value & ~ab8500_reg_init[id].mask) {
650 dev_err(&pdev->dev, 650 dev_err(&pdev->dev,
651 "Configuration error: value outside mask.\n"); 651 "Configuration error: value outside mask.\n");
652 return -EINVAL; 652 return -EINVAL;
653 } 653 }
654 654
655 err = abx500_mask_and_set_register_interruptible( 655 err = abx500_mask_and_set_register_interruptible(
656 &pdev->dev, 656 &pdev->dev,
657 ab8500_reg_init[id].bank, 657 ab8500_reg_init[id].bank,
658 ab8500_reg_init[id].addr, 658 ab8500_reg_init[id].addr,
659 ab8500_reg_init[id].mask, 659 ab8500_reg_init[id].mask,
660 value); 660 value);
661 if (err < 0) { 661 if (err < 0) {
662 dev_err(&pdev->dev, 662 dev_err(&pdev->dev,
663 "Failed to initialize 0x%02x, 0x%02x.\n", 663 "Failed to initialize 0x%02x, 0x%02x.\n",
664 ab8500_reg_init[id].bank, 664 ab8500_reg_init[id].bank,
665 ab8500_reg_init[id].addr); 665 ab8500_reg_init[id].addr);
666 return err; 666 return err;
667 } 667 }
668 668
669 dev_vdbg(&pdev->dev, 669 dev_vdbg(&pdev->dev,
670 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", 670 "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
671 ab8500_reg_init[id].bank, 671 ab8500_reg_init[id].bank,
672 ab8500_reg_init[id].addr, 672 ab8500_reg_init[id].addr,
673 ab8500_reg_init[id].mask, 673 ab8500_reg_init[id].mask,
674 value); 674 value);
675 675
676 return 0; 676 return 0;
677 } 677 }
678 678
679 static __devinit int ab8500_regulator_register(struct platform_device *pdev, 679 static __devinit int ab8500_regulator_register(struct platform_device *pdev,
680 struct regulator_init_data *init_data, 680 struct regulator_init_data *init_data,
681 int id, 681 int id,
682 struct device_node *np) 682 struct device_node *np)
683 { 683 {
684 struct ab8500_regulator_info *info = NULL; 684 struct ab8500_regulator_info *info = NULL;
685 struct regulator_config config = { }; 685 struct regulator_config config = { };
686 int err; 686 int err;
687 687
688 /* assign per-regulator data */ 688 /* assign per-regulator data */
689 info = &ab8500_regulator_info[id]; 689 info = &ab8500_regulator_info[id];
690 info->dev = &pdev->dev; 690 info->dev = &pdev->dev;
691 691
692 config.dev = &pdev->dev; 692 config.dev = &pdev->dev;
693 config.init_data = init_data; 693 config.init_data = init_data;
694 config.driver_data = info; 694 config.driver_data = info;
695 config.of_node = np; 695 config.of_node = np;
696 696
697 /* fix for hardware before ab8500v2.0 */ 697 /* fix for hardware before ab8500v2.0 */
698 if (abx500_get_chip_id(info->dev) < 0x20) { 698 if (abx500_get_chip_id(info->dev) < 0x20) {
699 if (info->desc.id == AB8500_LDO_AUX3) { 699 if (info->desc.id == AB8500_LDO_AUX3) {
700 info->desc.n_voltages = 700 info->desc.n_voltages =
701 ARRAY_SIZE(ldo_vauxn_voltages); 701 ARRAY_SIZE(ldo_vauxn_voltages);
702 info->desc.volt_table = ldo_vauxn_voltages; 702 info->desc.volt_table = ldo_vauxn_voltages;
703 info->voltage_mask = 0xf; 703 info->voltage_mask = 0xf;
704 } 704 }
705 } 705 }
706 706
707 /* register regulator with framework */ 707 /* register regulator with framework */
708 info->regulator = regulator_register(&info->desc, &config); 708 info->regulator = regulator_register(&info->desc, &config);
709 if (IS_ERR(info->regulator)) { 709 if (IS_ERR(info->regulator)) {
710 err = PTR_ERR(info->regulator); 710 err = PTR_ERR(info->regulator);
711 dev_err(&pdev->dev, "failed to register regulator %s\n", 711 dev_err(&pdev->dev, "failed to register regulator %s\n",
712 info->desc.name); 712 info->desc.name);
713 /* when we fail, un-register all earlier regulators */ 713 /* when we fail, un-register all earlier regulators */
714 while (--id >= 0) { 714 while (--id >= 0) {
715 info = &ab8500_regulator_info[id]; 715 info = &ab8500_regulator_info[id];
716 regulator_unregister(info->regulator); 716 regulator_unregister(info->regulator);
717 } 717 }
718 return err; 718 return err;
719 } 719 }
720 720
721 return 0; 721 return 0;
722 } 722 }
723 723
724 static struct of_regulator_match ab8500_regulator_matches[] = { 724 static struct of_regulator_match ab8500_regulator_matches[] = {
725 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, }, 725 { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
726 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, }, 726 { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
727 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, }, 727 { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
728 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, }, 728 { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
729 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, }, 729 { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
730 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, }, 730 { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
731 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, }, 731 { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
732 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, }, 732 { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
733 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, }, 733 { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
734 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, }, 734 { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
735 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, }, 735 { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
736 }; 736 };
737 737
738 static __devinit int 738 static __devinit int
739 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np) 739 ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
740 { 740 {
741 int err, i; 741 int err, i;
742 742
743 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 743 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
744 err = ab8500_regulator_register( 744 err = ab8500_regulator_register(
745 pdev, ab8500_regulator_matches[i].init_data, 745 pdev, ab8500_regulator_matches[i].init_data,
746 i, ab8500_regulator_matches[i].of_node); 746 i, ab8500_regulator_matches[i].of_node);
747 if (err) 747 if (err)
748 return err; 748 return err;
749 } 749 }
750 750
751 return 0; 751 return 0;
752 } 752 }
753 753
754 static __devinit int ab8500_regulator_probe(struct platform_device *pdev) 754 static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
755 { 755 {
756 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); 756 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
757 struct ab8500_platform_data *pdata; 757 struct ab8500_platform_data *pdata;
758 struct device_node *np = pdev->dev.of_node; 758 struct device_node *np = pdev->dev.of_node;
759 int i, err; 759 int i, err;
760 760
761 if (np) { 761 if (np) {
762 err = of_regulator_match(&pdev->dev, np, 762 err = of_regulator_match(&pdev->dev, np,
763 ab8500_regulator_matches, 763 ab8500_regulator_matches,
764 ARRAY_SIZE(ab8500_regulator_matches)); 764 ARRAY_SIZE(ab8500_regulator_matches));
765 if (err < 0) { 765 if (err < 0) {
766 dev_err(&pdev->dev, 766 dev_err(&pdev->dev,
767 "Error parsing regulator init data: %d\n", err); 767 "Error parsing regulator init data: %d\n", err);
768 return err; 768 return err;
769 } 769 }
770 770
771 err = ab8500_regulator_of_probe(pdev, np); 771 err = ab8500_regulator_of_probe(pdev, np);
772 return err; 772 return err;
773 } 773 }
774 774
775 if (!ab8500) { 775 if (!ab8500) {
776 dev_err(&pdev->dev, "null mfd parent\n"); 776 dev_err(&pdev->dev, "null mfd parent\n");
777 return -EINVAL; 777 return -EINVAL;
778 } 778 }
779 pdata = dev_get_platdata(ab8500->dev); 779 pdata = dev_get_platdata(ab8500->dev);
780 if (!pdata) { 780 if (!pdata) {
781 dev_err(&pdev->dev, "null pdata\n"); 781 dev_err(&pdev->dev, "null pdata\n");
782 return -EINVAL; 782 return -EINVAL;
783 } 783 }
784 784
785 /* make sure the platform data has the correct size */ 785 /* make sure the platform data has the correct size */
786 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { 786 if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
787 dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); 787 dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
788 return -EINVAL; 788 return -EINVAL;
789 } 789 }
790 790
791 /* initialize registers */ 791 /* initialize registers */
792 for (i = 0; i < pdata->num_regulator_reg_init; i++) { 792 for (i = 0; i < pdata->num_regulator_reg_init; i++) {
793 int id, value; 793 int id, value;
794 794
795 id = pdata->regulator_reg_init[i].id; 795 id = pdata->regulator_reg_init[i].id;
796 value = pdata->regulator_reg_init[i].value; 796 value = pdata->regulator_reg_init[i].value;
797 797
798 /* check for configuration errors */ 798 /* check for configuration errors */
799 if (id >= AB8500_NUM_REGULATOR_REGISTERS) { 799 if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
800 dev_err(&pdev->dev, 800 dev_err(&pdev->dev,
801 "Configuration error: id outside range.\n"); 801 "Configuration error: id outside range.\n");
802 return -EINVAL; 802 return -EINVAL;
803 } 803 }
804 804
805 err = ab8500_regulator_init_registers(pdev, id, value); 805 err = ab8500_regulator_init_registers(pdev, id, value);
806 if (err < 0) 806 if (err < 0)
807 return err; 807 return err;
808 } 808 }
809 809
810 /* register all regulators */ 810 /* register all regulators */
811 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 811 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
812 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); 812 err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
813 if (err < 0) 813 if (err < 0)
814 return err; 814 return err;
815 } 815 }
816 816
817 return 0; 817 return 0;
818 } 818 }
819 819
820 static __devexit int ab8500_regulator_remove(struct platform_device *pdev) 820 static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
821 { 821 {
822 int i; 822 int i;
823 823
824 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 824 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
825 struct ab8500_regulator_info *info = NULL; 825 struct ab8500_regulator_info *info = NULL;
826 info = &ab8500_regulator_info[i]; 826 info = &ab8500_regulator_info[i];
827 827
828 dev_vdbg(rdev_get_dev(info->regulator), 828 dev_vdbg(rdev_get_dev(info->regulator),
829 "%s-remove\n", info->desc.name); 829 "%s-remove\n", info->desc.name);
830 830
831 regulator_unregister(info->regulator); 831 regulator_unregister(info->regulator);
832 } 832 }
833 833
834 return 0; 834 return 0;
835 } 835 }
836 836
837 static struct platform_driver ab8500_regulator_driver = { 837 static struct platform_driver ab8500_regulator_driver = {
838 .probe = ab8500_regulator_probe, 838 .probe = ab8500_regulator_probe,
839 .remove = __devexit_p(ab8500_regulator_remove), 839 .remove = __devexit_p(ab8500_regulator_remove),
840 .driver = { 840 .driver = {
841 .name = "ab8500-regulator", 841 .name = "ab8500-regulator",
842 .owner = THIS_MODULE, 842 .owner = THIS_MODULE,
843 }, 843 },
844 }; 844 };
845 845
846 static int __init ab8500_regulator_init(void) 846 static int __init ab8500_regulator_init(void)
847 { 847 {
848 int ret; 848 int ret;
849 849
850 ret = platform_driver_register(&ab8500_regulator_driver); 850 ret = platform_driver_register(&ab8500_regulator_driver);
851 if (ret != 0) 851 if (ret != 0)
852 pr_err("Failed to register ab8500 regulator: %d\n", ret); 852 pr_err("Failed to register ab8500 regulator: %d\n", ret);
853 853
854 return ret; 854 return ret;
855 } 855 }
856 subsys_initcall(ab8500_regulator_init); 856 subsys_initcall(ab8500_regulator_init);
857 857
858 static void __exit ab8500_regulator_exit(void) 858 static void __exit ab8500_regulator_exit(void)
859 { 859 {
860 platform_driver_unregister(&ab8500_regulator_driver); 860 platform_driver_unregister(&ab8500_regulator_driver);
861 } 861 }
862 module_exit(ab8500_regulator_exit); 862 module_exit(ab8500_regulator_exit);
863 863
864 MODULE_LICENSE("GPL v2"); 864 MODULE_LICENSE("GPL v2");