]>
Commit | Line | Data |
---|---|---|
129eef96 EM |
1 | /* |
2 | * Regulators driver for Dialog Semiconductor DA903x | |
3 | * | |
4 | * Copyright (C) 2006-2008 Marvell International Ltd. | |
5 | * Copyright (C) 2008 Compulab Ltd. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | ||
12 | #include <linux/kernel.h> | |
13 | #include <linux/init.h> | |
14 | #include <linux/err.h> | |
65602c32 | 15 | #include <linux/module.h> |
129eef96 EM |
16 | #include <linux/platform_device.h> |
17 | #include <linux/regulator/driver.h> | |
18 | #include <linux/regulator/machine.h> | |
19 | #include <linux/mfd/da903x.h> | |
20 | ||
21 | /* DA9030 Registers */ | |
22 | #define DA9030_INVAL (-1) | |
23 | #define DA9030_LDO1011 (0x10) | |
24 | #define DA9030_LDO15 (0x11) | |
25 | #define DA9030_LDO1416 (0x12) | |
26 | #define DA9030_LDO1819 (0x13) | |
27 | #define DA9030_LDO17 (0x14) | |
28 | #define DA9030_BUCK2DVM1 (0x15) | |
29 | #define DA9030_BUCK2DVM2 (0x16) | |
30 | #define DA9030_RCTL11 (0x17) | |
31 | #define DA9030_RCTL21 (0x18) | |
32 | #define DA9030_LDO1 (0x90) | |
33 | #define DA9030_LDO23 (0x91) | |
34 | #define DA9030_LDO45 (0x92) | |
35 | #define DA9030_LDO6 (0x93) | |
36 | #define DA9030_LDO78 (0x94) | |
37 | #define DA9030_LDO912 (0x95) | |
38 | #define DA9030_BUCK (0x96) | |
39 | #define DA9030_RCTL12 (0x97) | |
40 | #define DA9030_RCTL22 (0x98) | |
41 | #define DA9030_LDO_UNLOCK (0xa0) | |
42 | #define DA9030_LDO_UNLOCK_MASK (0xe0) | |
43 | #define DA9034_OVER1 (0x10) | |
44 | ||
45 | /* DA9034 Registers */ | |
46 | #define DA9034_INVAL (-1) | |
47 | #define DA9034_OVER2 (0x11) | |
48 | #define DA9034_OVER3 (0x12) | |
49 | #define DA9034_LDO643 (0x13) | |
50 | #define DA9034_LDO987 (0x14) | |
51 | #define DA9034_LDO1110 (0x15) | |
52 | #define DA9034_LDO1312 (0x16) | |
53 | #define DA9034_LDO1514 (0x17) | |
54 | #define DA9034_VCC1 (0x20) | |
55 | #define DA9034_ADTV1 (0x23) | |
56 | #define DA9034_ADTV2 (0x24) | |
57 | #define DA9034_AVRC (0x25) | |
58 | #define DA9034_CDTV1 (0x26) | |
59 | #define DA9034_CDTV2 (0x27) | |
60 | #define DA9034_CVRC (0x28) | |
61 | #define DA9034_SDTV1 (0x29) | |
62 | #define DA9034_SDTV2 (0x2a) | |
63 | #define DA9034_SVRC (0x2b) | |
64 | #define DA9034_MDTV1 (0x32) | |
65 | #define DA9034_MDTV2 (0x33) | |
66 | #define DA9034_MVRC (0x34) | |
67 | ||
0198d116 HZ |
68 | /* DA9035 Registers. DA9034 Registers are comptabile to DA9035. */ |
69 | #define DA9035_OVER3 (0x12) | |
70 | #define DA9035_VCC2 (0x1f) | |
71 | #define DA9035_3DTV1 (0x2c) | |
72 | #define DA9035_3DTV2 (0x2d) | |
73 | #define DA9035_3VRC (0x2e) | |
74 | #define DA9035_AUTOSKIP (0x2f) | |
75 | ||
129eef96 EM |
76 | struct da903x_regulator_info { |
77 | struct regulator_desc desc; | |
78 | ||
129eef96 | 79 | int max_uV; |
129eef96 EM |
80 | int vol_reg; |
81 | int vol_shift; | |
82 | int vol_nbits; | |
83 | int update_reg; | |
84 | int update_bit; | |
85 | int enable_reg; | |
86 | int enable_bit; | |
87 | }; | |
88 | ||
1841c0f2 JC |
89 | static inline struct device *to_da903x_dev(struct regulator_dev *rdev) |
90 | { | |
91 | return rdev_get_dev(rdev)->parent->parent; | |
92 | } | |
93 | ||
129eef96 EM |
94 | static inline int check_range(struct da903x_regulator_info *info, |
95 | int min_uV, int max_uV) | |
96 | { | |
70b4e786 | 97 | if (min_uV < info->desc.min_uV || min_uV > info->max_uV) |
129eef96 EM |
98 | return -EINVAL; |
99 | ||
100 | return 0; | |
101 | } | |
102 | ||
103 | /* DA9030/DA9034 common operations */ | |
c972a029 AL |
104 | static int da903x_set_ldo_voltage_sel(struct regulator_dev *rdev, |
105 | unsigned selector) | |
129eef96 EM |
106 | { |
107 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 108 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
109 | uint8_t val, mask; |
110 | ||
c972a029 | 111 | val = selector << info->vol_shift; |
129eef96 EM |
112 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
113 | ||
114 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | |
115 | } | |
116 | ||
9447f35a | 117 | static int da903x_get_voltage_sel(struct regulator_dev *rdev) |
129eef96 EM |
118 | { |
119 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 120 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
121 | uint8_t val, mask; |
122 | int ret; | |
123 | ||
124 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | |
125 | if (ret) | |
126 | return ret; | |
127 | ||
128 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | |
129 | val = (val & mask) >> info->vol_shift; | |
130 | ||
9447f35a | 131 | return val; |
129eef96 EM |
132 | } |
133 | ||
134 | static int da903x_enable(struct regulator_dev *rdev) | |
135 | { | |
136 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 137 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
138 | |
139 | return da903x_set_bits(da9034_dev, info->enable_reg, | |
140 | 1 << info->enable_bit); | |
141 | } | |
142 | ||
143 | static int da903x_disable(struct regulator_dev *rdev) | |
144 | { | |
145 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 146 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
147 | |
148 | return da903x_clr_bits(da9034_dev, info->enable_reg, | |
149 | 1 << info->enable_bit); | |
150 | } | |
151 | ||
152 | static int da903x_is_enabled(struct regulator_dev *rdev) | |
153 | { | |
154 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 155 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
156 | uint8_t reg_val; |
157 | int ret; | |
158 | ||
159 | ret = da903x_read(da9034_dev, info->enable_reg, ®_val); | |
160 | if (ret) | |
161 | return ret; | |
162 | ||
96186904 | 163 | return !!(reg_val & (1 << info->enable_bit)); |
129eef96 EM |
164 | } |
165 | ||
166 | /* DA9030 specific operations */ | |
c972a029 AL |
167 | static int da9030_set_ldo1_15_voltage_sel(struct regulator_dev *rdev, |
168 | unsigned selector) | |
129eef96 EM |
169 | { |
170 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 171 | struct device *da903x_dev = to_da903x_dev(rdev); |
129eef96 EM |
172 | uint8_t val, mask; |
173 | int ret; | |
174 | ||
c972a029 | 175 | val = selector << info->vol_shift; |
129eef96 EM |
176 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
177 | val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ | |
178 | mask |= DA9030_LDO_UNLOCK_MASK; | |
179 | ||
180 | /* write twice */ | |
181 | ret = da903x_update(da903x_dev, info->vol_reg, val, mask); | |
182 | if (ret) | |
183 | return ret; | |
184 | ||
185 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | |
186 | } | |
187 | ||
c972a029 AL |
188 | static int da9030_set_ldo14_voltage_sel(struct regulator_dev *rdev, |
189 | unsigned selector) | |
129eef96 EM |
190 | { |
191 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 192 | struct device *da903x_dev = to_da903x_dev(rdev); |
129eef96 | 193 | uint8_t val, mask; |
c972a029 AL |
194 | |
195 | val = selector << info->vol_shift; | |
196 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | |
197 | ||
198 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | |
199 | } | |
200 | ||
201 | static int da9030_map_ldo14_voltage(struct regulator_dev *rdev, | |
202 | int min_uV, int max_uV) | |
203 | { | |
204 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
205 | int thresh, sel; | |
129eef96 EM |
206 | |
207 | if (check_range(info, min_uV, max_uV)) { | |
471d8d49 | 208 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); |
129eef96 EM |
209 | return -EINVAL; |
210 | } | |
211 | ||
70b4e786 | 212 | thresh = (info->max_uV + info->desc.min_uV) / 2; |
129eef96 | 213 | if (min_uV < thresh) { |
c972a029 AL |
214 | sel = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step); |
215 | sel |= 0x4; | |
129eef96 | 216 | } else { |
c972a029 | 217 | sel = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step); |
129eef96 EM |
218 | } |
219 | ||
c972a029 | 220 | return sel; |
129eef96 EM |
221 | } |
222 | ||
9447f35a | 223 | static int da9030_get_ldo14_voltage_sel(struct regulator_dev *rdev) |
129eef96 EM |
224 | { |
225 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 226 | struct device *da903x_dev = to_da903x_dev(rdev); |
129eef96 EM |
227 | uint8_t val, mask; |
228 | int ret; | |
229 | ||
230 | ret = da903x_read(da903x_dev, info->vol_reg, &val); | |
231 | if (ret) | |
232 | return ret; | |
233 | ||
234 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | |
235 | val = (val & mask) >> info->vol_shift; | |
236 | ||
9447f35a | 237 | return val; |
129eef96 EM |
238 | } |
239 | ||
d4eb56a1 AL |
240 | static int da9030_list_ldo14_voltage(struct regulator_dev *rdev, |
241 | unsigned selector) | |
242 | { | |
243 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
244 | int volt; | |
245 | ||
246 | if (selector & 0x4) | |
70b4e786 AL |
247 | volt = rdev->desc->min_uV + |
248 | rdev->desc->uV_step * (3 - (selector & ~0x4)); | |
d4eb56a1 | 249 | else |
70b4e786 AL |
250 | volt = (info->max_uV + rdev->desc->min_uV) / 2 + |
251 | rdev->desc->uV_step * (selector & ~0x4); | |
d4eb56a1 AL |
252 | |
253 | if (volt > info->max_uV) | |
254 | return -EINVAL; | |
255 | ||
256 | return volt; | |
257 | } | |
258 | ||
129eef96 | 259 | /* DA9034 specific operations */ |
c972a029 AL |
260 | static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev, |
261 | unsigned selector) | |
129eef96 EM |
262 | { |
263 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 264 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
265 | uint8_t val, mask; |
266 | int ret; | |
267 | ||
c972a029 | 268 | val = selector << info->vol_shift; |
129eef96 EM |
269 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
270 | ||
271 | ret = da903x_update(da9034_dev, info->vol_reg, val, mask); | |
272 | if (ret) | |
273 | return ret; | |
274 | ||
275 | ret = da903x_set_bits(da9034_dev, info->update_reg, | |
276 | 1 << info->update_bit); | |
277 | return ret; | |
278 | } | |
279 | ||
c972a029 AL |
280 | static int da9034_set_ldo12_voltage_sel(struct regulator_dev *rdev, |
281 | unsigned selector) | |
129eef96 EM |
282 | { |
283 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 284 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
285 | uint8_t val, mask; |
286 | ||
c972a029 AL |
287 | val = selector << info->vol_shift; |
288 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | |
289 | ||
290 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | |
291 | } | |
292 | ||
293 | static int da9034_map_ldo12_voltage(struct regulator_dev *rdev, | |
294 | int min_uV, int max_uV) | |
295 | { | |
296 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
297 | int sel; | |
298 | ||
129eef96 | 299 | if (check_range(info, min_uV, max_uV)) { |
471d8d49 | 300 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); |
129eef96 EM |
301 | return -EINVAL; |
302 | } | |
303 | ||
c972a029 AL |
304 | sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step); |
305 | sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel); | |
129eef96 | 306 | |
c972a029 | 307 | return sel; |
129eef96 EM |
308 | } |
309 | ||
9447f35a | 310 | static int da9034_get_ldo12_voltage_sel(struct regulator_dev *rdev) |
129eef96 EM |
311 | { |
312 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | |
1841c0f2 | 313 | struct device *da9034_dev = to_da903x_dev(rdev); |
129eef96 EM |
314 | uint8_t val, mask; |
315 | int ret; | |
316 | ||
317 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | |
318 | if (ret) | |
319 | return ret; | |
320 | ||
321 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | |
322 | val = (val & mask) >> info->vol_shift; | |
323 | ||
9447f35a | 324 | return val; |
129eef96 EM |
325 | } |
326 | ||
c1b60873 HZ |
327 | static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, |
328 | unsigned selector) | |
329 | { | |
9447f35a AL |
330 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
331 | int volt; | |
332 | ||
333 | if (selector >= 8) | |
70b4e786 | 334 | volt = 2700000 + rdev->desc->uV_step * (selector - 8); |
9447f35a | 335 | else |
70b4e786 | 336 | volt = rdev->desc->min_uV + rdev->desc->uV_step * selector; |
9447f35a AL |
337 | |
338 | if (volt > info->max_uV) | |
c1b60873 | 339 | return -EINVAL; |
9447f35a AL |
340 | |
341 | return volt; | |
c1b60873 HZ |
342 | } |
343 | ||
129eef96 | 344 | static struct regulator_ops da903x_regulator_ldo_ops = { |
c972a029 | 345 | .set_voltage_sel = da903x_set_ldo_voltage_sel, |
9447f35a | 346 | .get_voltage_sel = da903x_get_voltage_sel, |
70b4e786 | 347 | .list_voltage = regulator_list_voltage_linear, |
c972a029 | 348 | .map_voltage = regulator_map_voltage_linear, |
129eef96 EM |
349 | .enable = da903x_enable, |
350 | .disable = da903x_disable, | |
351 | .is_enabled = da903x_is_enabled, | |
352 | }; | |
353 | ||
354 | /* NOTE: this is dedicated for the insane DA9030 LDO14 */ | |
355 | static struct regulator_ops da9030_regulator_ldo14_ops = { | |
c972a029 | 356 | .set_voltage_sel = da9030_set_ldo14_voltage_sel, |
9447f35a | 357 | .get_voltage_sel = da9030_get_ldo14_voltage_sel, |
d4eb56a1 | 358 | .list_voltage = da9030_list_ldo14_voltage, |
c972a029 | 359 | .map_voltage = da9030_map_ldo14_voltage, |
129eef96 EM |
360 | .enable = da903x_enable, |
361 | .disable = da903x_disable, | |
362 | .is_enabled = da903x_is_enabled, | |
363 | }; | |
364 | ||
365 | /* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ | |
366 | static struct regulator_ops da9030_regulator_ldo1_15_ops = { | |
c972a029 | 367 | .set_voltage_sel = da9030_set_ldo1_15_voltage_sel, |
9447f35a | 368 | .get_voltage_sel = da903x_get_voltage_sel, |
70b4e786 | 369 | .list_voltage = regulator_list_voltage_linear, |
c972a029 | 370 | .map_voltage = regulator_map_voltage_linear, |
129eef96 EM |
371 | .enable = da903x_enable, |
372 | .disable = da903x_disable, | |
373 | .is_enabled = da903x_is_enabled, | |
374 | }; | |
375 | ||
376 | static struct regulator_ops da9034_regulator_dvc_ops = { | |
c972a029 | 377 | .set_voltage_sel = da9034_set_dvc_voltage_sel, |
9447f35a | 378 | .get_voltage_sel = da903x_get_voltage_sel, |
70b4e786 | 379 | .list_voltage = regulator_list_voltage_linear, |
c972a029 | 380 | .map_voltage = regulator_map_voltage_linear, |
129eef96 EM |
381 | .enable = da903x_enable, |
382 | .disable = da903x_disable, | |
383 | .is_enabled = da903x_is_enabled, | |
384 | }; | |
385 | ||
386 | /* NOTE: this is dedicated for the insane LDO12 */ | |
387 | static struct regulator_ops da9034_regulator_ldo12_ops = { | |
c972a029 | 388 | .set_voltage_sel = da9034_set_ldo12_voltage_sel, |
9447f35a | 389 | .get_voltage_sel = da9034_get_ldo12_voltage_sel, |
c1b60873 | 390 | .list_voltage = da9034_list_ldo12_voltage, |
c972a029 | 391 | .map_voltage = da9034_map_ldo12_voltage, |
129eef96 EM |
392 | .enable = da903x_enable, |
393 | .disable = da903x_disable, | |
394 | .is_enabled = da903x_is_enabled, | |
395 | }; | |
396 | ||
397 | #define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \ | |
398 | { \ | |
399 | .desc = { \ | |
400 | .name = "LDO" #_id, \ | |
401 | .ops = &da903x_regulator_ldo_ops, \ | |
402 | .type = REGULATOR_VOLTAGE, \ | |
403 | .id = _pmic##_ID_LDO##_id, \ | |
c1b60873 | 404 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ |
129eef96 | 405 | .owner = THIS_MODULE, \ |
70b4e786 AL |
406 | .min_uV = (min) * 1000, \ |
407 | .uV_step = (step) * 1000, \ | |
129eef96 | 408 | }, \ |
129eef96 | 409 | .max_uV = (max) * 1000, \ |
129eef96 EM |
410 | .vol_reg = _pmic##_##vreg, \ |
411 | .vol_shift = (shift), \ | |
412 | .vol_nbits = (nbits), \ | |
413 | .enable_reg = _pmic##_##ereg, \ | |
414 | .enable_bit = (ebit), \ | |
415 | } | |
416 | ||
c6db1828 | 417 | #define DA903x_DVC(_pmic, _id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ |
fc4f42e7 HZ |
418 | { \ |
419 | .desc = { \ | |
420 | .name = #_id, \ | |
421 | .ops = &da9034_regulator_dvc_ops, \ | |
422 | .type = REGULATOR_VOLTAGE, \ | |
c6db1828 | 423 | .id = _pmic##_ID_##_id, \ |
c1b60873 | 424 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ |
fc4f42e7 | 425 | .owner = THIS_MODULE, \ |
70b4e786 AL |
426 | .min_uV = (min) * 1000, \ |
427 | .uV_step = (step) * 1000, \ | |
fc4f42e7 | 428 | }, \ |
fc4f42e7 | 429 | .max_uV = (max) * 1000, \ |
c6db1828 | 430 | .vol_reg = _pmic##_##vreg, \ |
0198d116 HZ |
431 | .vol_shift = (0), \ |
432 | .vol_nbits = (nbits), \ | |
c6db1828 | 433 | .update_reg = _pmic##_##ureg, \ |
0198d116 | 434 | .update_bit = (ubit), \ |
c6db1828 | 435 | .enable_reg = _pmic##_##ereg, \ |
0198d116 HZ |
436 | .enable_bit = (ebit), \ |
437 | } | |
438 | ||
129eef96 EM |
439 | #define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ |
440 | DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit) | |
441 | ||
442 | #define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ | |
443 | DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit) | |
444 | ||
c6db1828 MR |
445 | #define DA9030_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ |
446 | DA903x_DVC(DA9030, _id, min, max, step, vreg, nbits, ureg, ubit, \ | |
447 | ereg, ebit) | |
448 | ||
449 | #define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ | |
450 | DA903x_DVC(DA9034, _id, min, max, step, vreg, nbits, ureg, ubit, \ | |
451 | ereg, ebit) | |
452 | ||
453 | #define DA9035_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ | |
454 | DA903x_DVC(DA9035, _id, min, max, step, vreg, nbits, ureg, ubit, \ | |
455 | ereg, ebit) | |
456 | ||
129eef96 EM |
457 | static struct da903x_regulator_info da903x_regulator_info[] = { |
458 | /* DA9030 */ | |
fc4f42e7 HZ |
459 | DA9030_DVC(BUCK2, 850, 1625, 25, BUCK2DVM1, 5, BUCK2DVM1, 7, RCTL11, 0), |
460 | ||
129eef96 EM |
461 | DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1), |
462 | DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2), | |
463 | DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3), | |
464 | DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4), | |
465 | DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5), | |
466 | DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6), | |
467 | DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7), | |
468 | DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0), | |
469 | DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1), | |
470 | DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2), | |
471 | DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3), | |
472 | DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4), | |
473 | DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4), | |
474 | DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5), | |
475 | DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6), | |
476 | DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7), | |
477 | DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2), | |
478 | DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1), | |
479 | DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */ | |
480 | ||
481 | /* DA9034 */ | |
e88267e1 HZ |
482 | DA9034_DVC(BUCK1, 725, 1500, 25, ADTV2, 5, VCC1, 0, OVER1, 0), |
483 | DA9034_DVC(BUCK2, 725, 1500, 25, CDTV2, 5, VCC1, 2, OVER1, 1), | |
484 | DA9034_DVC(LDO2, 725, 1500, 25, SDTV2, 5, VCC1, 4, OVER1, 2), | |
129eef96 EM |
485 | DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4), |
486 | ||
487 | DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5), | |
488 | DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6), | |
489 | DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0), | |
490 | DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1), | |
491 | DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2), | |
492 | DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3), | |
493 | DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4), | |
494 | DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5), | |
495 | DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6), | |
496 | DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7), | |
497 | DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0), | |
498 | DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1), | |
499 | DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */ | |
0198d116 HZ |
500 | |
501 | /* DA9035 */ | |
502 | DA9035_DVC(BUCK3, 1800, 2200, 100, 3DTV1, 3, VCC2, 0, OVER3, 3), | |
129eef96 EM |
503 | }; |
504 | ||
505 | static inline struct da903x_regulator_info *find_regulator_info(int id) | |
506 | { | |
507 | struct da903x_regulator_info *ri; | |
508 | int i; | |
509 | ||
510 | for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) { | |
511 | ri = &da903x_regulator_info[i]; | |
512 | if (ri->desc.id == id) | |
513 | return ri; | |
514 | } | |
515 | return NULL; | |
516 | } | |
517 | ||
518 | static int __devinit da903x_regulator_probe(struct platform_device *pdev) | |
519 | { | |
520 | struct da903x_regulator_info *ri = NULL; | |
521 | struct regulator_dev *rdev; | |
c172708d | 522 | struct regulator_config config = { }; |
129eef96 EM |
523 | |
524 | ri = find_regulator_info(pdev->id); | |
525 | if (ri == NULL) { | |
526 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); | |
527 | return -EINVAL; | |
528 | } | |
529 | ||
530 | /* Workaround for the weird LDO12 voltage setting */ | |
c1b60873 | 531 | if (ri->desc.id == DA9034_ID_LDO12) { |
129eef96 | 532 | ri->desc.ops = &da9034_regulator_ldo12_ops; |
9447f35a | 533 | ri->desc.n_voltages = 16; |
c1b60873 | 534 | } |
129eef96 EM |
535 | |
536 | if (ri->desc.id == DA9030_ID_LDO14) | |
537 | ri->desc.ops = &da9030_regulator_ldo14_ops; | |
538 | ||
539 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) | |
540 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; | |
541 | ||
c172708d | 542 | config.dev = &pdev->dev; |
fe53d18d | 543 | config.init_data = pdev->dev.platform_data; |
c172708d MB |
544 | config.driver_data = ri; |
545 | ||
546 | rdev = regulator_register(&ri->desc, &config); | |
129eef96 EM |
547 | if (IS_ERR(rdev)) { |
548 | dev_err(&pdev->dev, "failed to register regulator %s\n", | |
549 | ri->desc.name); | |
550 | return PTR_ERR(rdev); | |
551 | } | |
552 | ||
553 | platform_set_drvdata(pdev, rdev); | |
554 | return 0; | |
555 | } | |
556 | ||
557 | static int __devexit da903x_regulator_remove(struct platform_device *pdev) | |
558 | { | |
559 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | |
560 | ||
561 | regulator_unregister(rdev); | |
562 | return 0; | |
563 | } | |
564 | ||
565 | static struct platform_driver da903x_regulator_driver = { | |
566 | .driver = { | |
567 | .name = "da903x-regulator", | |
568 | .owner = THIS_MODULE, | |
569 | }, | |
570 | .probe = da903x_regulator_probe, | |
5b4662f0 | 571 | .remove = __devexit_p(da903x_regulator_remove), |
129eef96 EM |
572 | }; |
573 | ||
574 | static int __init da903x_regulator_init(void) | |
575 | { | |
576 | return platform_driver_register(&da903x_regulator_driver); | |
577 | } | |
5a1b22be | 578 | subsys_initcall(da903x_regulator_init); |
129eef96 EM |
579 | |
580 | static void __exit da903x_regulator_exit(void) | |
581 | { | |
582 | platform_driver_unregister(&da903x_regulator_driver); | |
583 | } | |
584 | module_exit(da903x_regulator_exit); | |
585 | ||
586 | MODULE_LICENSE("GPL"); | |
587 | MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>" | |
588 | "Mike Rapoport <mike@compulab.co.il>"); | |
589 | MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC"); | |
590 | MODULE_ALIAS("platform:da903x-regulator"); |