blob: c75e7b7a61b32f42b9cb9aaa06b2da443e85b9f1 [file] [log] [blame]
Eric Miao129eef92008-08-27 04:16:08 +08001/*
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>
Paul Gortmaker65602c32011-07-17 16:28:23 -040015#include <linux/module.h>
Eric Miao129eef92008-08-27 04:16:08 +080016#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
Haojian Zhuang0198d112009-06-26 19:20:59 +080068/* 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
Eric Miao129eef92008-08-27 04:16:08 +080076struct da903x_regulator_info {
77 struct regulator_desc desc;
78
79 int min_uV;
80 int max_uV;
81 int step_uV;
82 int vol_reg;
83 int vol_shift;
84 int vol_nbits;
85 int update_reg;
86 int update_bit;
87 int enable_reg;
88 int enable_bit;
89};
90
Jonathan Cameron1841c0f2008-10-28 11:03:48 +000091static inline struct device *to_da903x_dev(struct regulator_dev *rdev)
92{
93 return rdev_get_dev(rdev)->parent->parent;
94}
95
Eric Miao129eef92008-08-27 04:16:08 +080096static inline int check_range(struct da903x_regulator_info *info,
97 int min_uV, int max_uV)
98{
99 if (min_uV < info->min_uV || min_uV > info->max_uV)
100 return -EINVAL;
101
102 return 0;
103}
104
105/* DA9030/DA9034 common operations */
106static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000107 int min_uV, int max_uV, unsigned *selector)
Eric Miao129eef92008-08-27 04:16:08 +0800108{
109 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000110 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800111 uint8_t val, mask;
112
113 if (check_range(info, min_uV, max_uV)) {
Mike Rapoport471d8d42008-11-24 18:43:00 +0200114 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800115 return -EINVAL;
116 }
117
Axel Linae76e832012-03-06 06:54:40 +0800118 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000119 *selector = val;
Eric Miao129eef92008-08-27 04:16:08 +0800120 val <<= info->vol_shift;
121 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
122
123 return da903x_update(da9034_dev, info->vol_reg, val, mask);
124}
125
Axel Lin9447f352012-05-08 19:47:47 +0800126static int da903x_get_voltage_sel(struct regulator_dev *rdev)
Eric Miao129eef92008-08-27 04:16:08 +0800127{
128 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000129 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800130 uint8_t val, mask;
131 int ret;
132
133 ret = da903x_read(da9034_dev, info->vol_reg, &val);
134 if (ret)
135 return ret;
136
137 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
138 val = (val & mask) >> info->vol_shift;
139
Axel Lin9447f352012-05-08 19:47:47 +0800140 return val;
Eric Miao129eef92008-08-27 04:16:08 +0800141}
142
143static int da903x_enable(struct regulator_dev *rdev)
144{
145 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000146 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800147
148 return da903x_set_bits(da9034_dev, info->enable_reg,
149 1 << info->enable_bit);
150}
151
152static int da903x_disable(struct regulator_dev *rdev)
153{
154 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000155 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800156
157 return da903x_clr_bits(da9034_dev, info->enable_reg,
158 1 << info->enable_bit);
159}
160
161static int da903x_is_enabled(struct regulator_dev *rdev)
162{
163 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000164 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800165 uint8_t reg_val;
166 int ret;
167
168 ret = da903x_read(da9034_dev, info->enable_reg, &reg_val);
169 if (ret)
170 return ret;
171
Mike Rapoport96186902008-11-25 10:19:52 +0200172 return !!(reg_val & (1 << info->enable_bit));
Eric Miao129eef92008-08-27 04:16:08 +0800173}
174
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800175static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector)
176{
177 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
178 int ret;
179
180 ret = info->min_uV + info->step_uV * selector;
181 if (ret > info->max_uV)
182 return -EINVAL;
183 return ret;
184}
185
Eric Miao129eef92008-08-27 04:16:08 +0800186/* DA9030 specific operations */
187static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000188 int min_uV, int max_uV,
189 unsigned *selector)
Eric Miao129eef92008-08-27 04:16:08 +0800190{
191 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000192 struct device *da903x_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800193 uint8_t val, mask;
194 int ret;
195
196 if (check_range(info, min_uV, max_uV)) {
Mike Rapoport471d8d42008-11-24 18:43:00 +0200197 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800198 return -EINVAL;
199 }
200
Axel Linae76e832012-03-06 06:54:40 +0800201 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000202 *selector = val;
Eric Miao129eef92008-08-27 04:16:08 +0800203 val <<= info->vol_shift;
204 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
205 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
206 mask |= DA9030_LDO_UNLOCK_MASK;
207
208 /* write twice */
209 ret = da903x_update(da903x_dev, info->vol_reg, val, mask);
210 if (ret)
211 return ret;
212
213 return da903x_update(da903x_dev, info->vol_reg, val, mask);
214}
215
216static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000217 int min_uV, int max_uV,
218 unsigned *selector)
Eric Miao129eef92008-08-27 04:16:08 +0800219{
220 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000221 struct device *da903x_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800222 uint8_t val, mask;
223 int thresh;
224
225 if (check_range(info, min_uV, max_uV)) {
Mike Rapoport471d8d42008-11-24 18:43:00 +0200226 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800227 return -EINVAL;
228 }
229
230 thresh = (info->max_uV + info->min_uV) / 2;
231 if (min_uV < thresh) {
Axel Linae76e832012-03-06 06:54:40 +0800232 val = DIV_ROUND_UP(thresh - min_uV, info->step_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800233 val |= 0x4;
234 } else {
Axel Linae76e832012-03-06 06:54:40 +0800235 val = DIV_ROUND_UP(min_uV - thresh, info->step_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800236 }
237
Mark Brown3a93f2a2010-11-10 14:38:29 +0000238 *selector = val;
Eric Miao129eef92008-08-27 04:16:08 +0800239 val <<= info->vol_shift;
240 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
241
242 return da903x_update(da903x_dev, info->vol_reg, val, mask);
243}
244
Axel Lin9447f352012-05-08 19:47:47 +0800245static int da9030_get_ldo14_voltage_sel(struct regulator_dev *rdev)
Eric Miao129eef92008-08-27 04:16:08 +0800246{
247 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000248 struct device *da903x_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800249 uint8_t val, mask;
250 int ret;
251
252 ret = da903x_read(da903x_dev, info->vol_reg, &val);
253 if (ret)
254 return ret;
255
256 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
257 val = (val & mask) >> info->vol_shift;
258
Axel Lin9447f352012-05-08 19:47:47 +0800259 return val;
Eric Miao129eef92008-08-27 04:16:08 +0800260}
261
Axel Lind4eb56a2012-05-08 19:46:10 +0800262static int da9030_list_ldo14_voltage(struct regulator_dev *rdev,
263 unsigned selector)
264{
265 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
266 int volt;
267
268 if (selector & 0x4)
269 volt = info->min_uV + info->step_uV * (3 - (selector & ~0x4));
270 else
271 volt = (info->max_uV + info->min_uV) / 2 +
272 info->step_uV * (selector & ~0x4);
273
274 if (volt > info->max_uV)
275 return -EINVAL;
276
277 return volt;
278}
279
Eric Miao129eef92008-08-27 04:16:08 +0800280/* DA9034 specific operations */
281static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000282 int min_uV, int max_uV, unsigned *selector)
Eric Miao129eef92008-08-27 04:16:08 +0800283{
284 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000285 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800286 uint8_t val, mask;
287 int ret;
288
289 if (check_range(info, min_uV, max_uV)) {
Mike Rapoport471d8d42008-11-24 18:43:00 +0200290 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800291 return -EINVAL;
292 }
293
Axel Linae76e832012-03-06 06:54:40 +0800294 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000295 *selector = val;
Eric Miao129eef92008-08-27 04:16:08 +0800296 val <<= info->vol_shift;
297 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
298
299 ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
300 if (ret)
301 return ret;
302
303 ret = da903x_set_bits(da9034_dev, info->update_reg,
304 1 << info->update_bit);
305 return ret;
306}
307
308static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
Mark Brown3a93f2a2010-11-10 14:38:29 +0000309 int min_uV, int max_uV, unsigned *selector)
Eric Miao129eef92008-08-27 04:16:08 +0800310{
311 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000312 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800313 uint8_t val, mask;
314
315 if (check_range(info, min_uV, max_uV)) {
Mike Rapoport471d8d42008-11-24 18:43:00 +0200316 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
Eric Miao129eef92008-08-27 04:16:08 +0800317 return -EINVAL;
318 }
319
Axel Linae76e832012-03-06 06:54:40 +0800320 val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
Haojian Zhuang55c1d7c2009-09-21 12:14:12 -0400321 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val);
Mark Brown3a93f2a2010-11-10 14:38:29 +0000322 *selector = val;
Eric Miao129eef92008-08-27 04:16:08 +0800323 val <<= info->vol_shift;
324 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
325
326 return da903x_update(da9034_dev, info->vol_reg, val, mask);
327}
328
Axel Lin9447f352012-05-08 19:47:47 +0800329static int da9034_get_ldo12_voltage_sel(struct regulator_dev *rdev)
Eric Miao129eef92008-08-27 04:16:08 +0800330{
331 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
Jonathan Cameron1841c0f2008-10-28 11:03:48 +0000332 struct device *da9034_dev = to_da903x_dev(rdev);
Eric Miao129eef92008-08-27 04:16:08 +0800333 uint8_t val, mask;
334 int ret;
335
336 ret = da903x_read(da9034_dev, info->vol_reg, &val);
337 if (ret)
338 return ret;
339
340 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
341 val = (val & mask) >> info->vol_shift;
342
Axel Lin9447f352012-05-08 19:47:47 +0800343 return val;
Eric Miao129eef92008-08-27 04:16:08 +0800344}
345
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800346static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
347 unsigned selector)
348{
Axel Lin9447f352012-05-08 19:47:47 +0800349 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
350 int volt;
351
352 if (selector >= 8)
353 volt = 2700000 + info->step_uV * (selector - 8);
354 else
355 volt = info->min_uV + info->step_uV * selector;
356
357 if (volt > info->max_uV)
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800358 return -EINVAL;
Axel Lin9447f352012-05-08 19:47:47 +0800359
360 return volt;
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800361}
362
Eric Miao129eef92008-08-27 04:16:08 +0800363static struct regulator_ops da903x_regulator_ldo_ops = {
364 .set_voltage = da903x_set_ldo_voltage,
Axel Lin9447f352012-05-08 19:47:47 +0800365 .get_voltage_sel = da903x_get_voltage_sel,
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800366 .list_voltage = da903x_list_voltage,
Eric Miao129eef92008-08-27 04:16:08 +0800367 .enable = da903x_enable,
368 .disable = da903x_disable,
369 .is_enabled = da903x_is_enabled,
370};
371
372/* NOTE: this is dedicated for the insane DA9030 LDO14 */
373static struct regulator_ops da9030_regulator_ldo14_ops = {
374 .set_voltage = da9030_set_ldo14_voltage,
Axel Lin9447f352012-05-08 19:47:47 +0800375 .get_voltage_sel = da9030_get_ldo14_voltage_sel,
Axel Lind4eb56a2012-05-08 19:46:10 +0800376 .list_voltage = da9030_list_ldo14_voltage,
Eric Miao129eef92008-08-27 04:16:08 +0800377 .enable = da903x_enable,
378 .disable = da903x_disable,
379 .is_enabled = da903x_is_enabled,
380};
381
382/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
383static struct regulator_ops da9030_regulator_ldo1_15_ops = {
384 .set_voltage = da9030_set_ldo1_15_voltage,
Axel Lin9447f352012-05-08 19:47:47 +0800385 .get_voltage_sel = da903x_get_voltage_sel,
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800386 .list_voltage = da903x_list_voltage,
Eric Miao129eef92008-08-27 04:16:08 +0800387 .enable = da903x_enable,
388 .disable = da903x_disable,
389 .is_enabled = da903x_is_enabled,
390};
391
392static struct regulator_ops da9034_regulator_dvc_ops = {
393 .set_voltage = da9034_set_dvc_voltage,
Axel Lin9447f352012-05-08 19:47:47 +0800394 .get_voltage_sel = da903x_get_voltage_sel,
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800395 .list_voltage = da903x_list_voltage,
Eric Miao129eef92008-08-27 04:16:08 +0800396 .enable = da903x_enable,
397 .disable = da903x_disable,
398 .is_enabled = da903x_is_enabled,
399};
400
401/* NOTE: this is dedicated for the insane LDO12 */
402static struct regulator_ops da9034_regulator_ldo12_ops = {
403 .set_voltage = da9034_set_ldo12_voltage,
Axel Lin9447f352012-05-08 19:47:47 +0800404 .get_voltage_sel = da9034_get_ldo12_voltage_sel,
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800405 .list_voltage = da9034_list_ldo12_voltage,
Eric Miao129eef92008-08-27 04:16:08 +0800406 .enable = da903x_enable,
407 .disable = da903x_disable,
408 .is_enabled = da903x_is_enabled,
409};
410
411#define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \
412{ \
413 .desc = { \
414 .name = "LDO" #_id, \
415 .ops = &da903x_regulator_ldo_ops, \
416 .type = REGULATOR_VOLTAGE, \
417 .id = _pmic##_ID_LDO##_id, \
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800418 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
Eric Miao129eef92008-08-27 04:16:08 +0800419 .owner = THIS_MODULE, \
420 }, \
421 .min_uV = (min) * 1000, \
422 .max_uV = (max) * 1000, \
423 .step_uV = (step) * 1000, \
424 .vol_reg = _pmic##_##vreg, \
425 .vol_shift = (shift), \
426 .vol_nbits = (nbits), \
427 .enable_reg = _pmic##_##ereg, \
428 .enable_bit = (ebit), \
429}
430
Mike Rapoportc6db1822009-07-26 13:33:04 +0300431#define DA903x_DVC(_pmic, _id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
Haojian Zhuangfc4f42e2009-07-08 17:57:24 +0800432{ \
433 .desc = { \
434 .name = #_id, \
435 .ops = &da9034_regulator_dvc_ops, \
436 .type = REGULATOR_VOLTAGE, \
Mike Rapoportc6db1822009-07-26 13:33:04 +0300437 .id = _pmic##_ID_##_id, \
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800438 .n_voltages = (step) ? ((max - min) / step + 1) : 1, \
Haojian Zhuangfc4f42e2009-07-08 17:57:24 +0800439 .owner = THIS_MODULE, \
440 }, \
441 .min_uV = (min) * 1000, \
442 .max_uV = (max) * 1000, \
443 .step_uV = (step) * 1000, \
Mike Rapoportc6db1822009-07-26 13:33:04 +0300444 .vol_reg = _pmic##_##vreg, \
Haojian Zhuangfc4f42e2009-07-08 17:57:24 +0800445 .vol_shift = (0), \
446 .vol_nbits = (nbits), \
Mike Rapoportc6db1822009-07-26 13:33:04 +0300447 .update_reg = _pmic##_##ureg, \
Haojian Zhuangfc4f42e2009-07-08 17:57:24 +0800448 .update_bit = (ubit), \
Mike Rapoportc6db1822009-07-26 13:33:04 +0300449 .enable_reg = _pmic##_##ereg, \
Haojian Zhuang0198d112009-06-26 19:20:59 +0800450 .enable_bit = (ebit), \
451}
452
Eric Miao129eef92008-08-27 04:16:08 +0800453#define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
454 DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
455
456#define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
457 DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
458
Mike Rapoportc6db1822009-07-26 13:33:04 +0300459#define DA9030_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
460 DA903x_DVC(DA9030, _id, min, max, step, vreg, nbits, ureg, ubit, \
461 ereg, ebit)
462
463#define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
464 DA903x_DVC(DA9034, _id, min, max, step, vreg, nbits, ureg, ubit, \
465 ereg, ebit)
466
467#define DA9035_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
468 DA903x_DVC(DA9035, _id, min, max, step, vreg, nbits, ureg, ubit, \
469 ereg, ebit)
470
Eric Miao129eef92008-08-27 04:16:08 +0800471static struct da903x_regulator_info da903x_regulator_info[] = {
472 /* DA9030 */
Haojian Zhuangfc4f42e2009-07-08 17:57:24 +0800473 DA9030_DVC(BUCK2, 850, 1625, 25, BUCK2DVM1, 5, BUCK2DVM1, 7, RCTL11, 0),
474
Eric Miao129eef92008-08-27 04:16:08 +0800475 DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1),
476 DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2),
477 DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3),
478 DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4),
479 DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5),
480 DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6),
481 DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7),
482 DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0),
483 DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1),
484 DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2),
485 DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3),
486 DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4),
487 DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4),
488 DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5),
489 DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6),
490 DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7),
491 DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2),
492 DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1),
493 DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */
494
495 /* DA9034 */
Haojian Zhuange88267e2009-07-09 17:52:30 +0800496 DA9034_DVC(BUCK1, 725, 1500, 25, ADTV2, 5, VCC1, 0, OVER1, 0),
497 DA9034_DVC(BUCK2, 725, 1500, 25, CDTV2, 5, VCC1, 2, OVER1, 1),
498 DA9034_DVC(LDO2, 725, 1500, 25, SDTV2, 5, VCC1, 4, OVER1, 2),
Eric Miao129eef92008-08-27 04:16:08 +0800499 DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4),
500
501 DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5),
502 DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6),
503 DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0),
504 DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1),
505 DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2),
506 DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3),
507 DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4),
508 DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5),
509 DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6),
510 DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7),
511 DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0),
512 DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1),
513 DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */
Haojian Zhuang0198d112009-06-26 19:20:59 +0800514
515 /* DA9035 */
516 DA9035_DVC(BUCK3, 1800, 2200, 100, 3DTV1, 3, VCC2, 0, OVER3, 3),
Eric Miao129eef92008-08-27 04:16:08 +0800517};
518
519static inline struct da903x_regulator_info *find_regulator_info(int id)
520{
521 struct da903x_regulator_info *ri;
522 int i;
523
524 for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) {
525 ri = &da903x_regulator_info[i];
526 if (ri->desc.id == id)
527 return ri;
528 }
529 return NULL;
530}
531
532static int __devinit da903x_regulator_probe(struct platform_device *pdev)
533{
534 struct da903x_regulator_info *ri = NULL;
535 struct regulator_dev *rdev;
Mark Brownc1727082012-04-04 00:50:22 +0100536 struct regulator_config config = { };
Eric Miao129eef92008-08-27 04:16:08 +0800537
538 ri = find_regulator_info(pdev->id);
539 if (ri == NULL) {
540 dev_err(&pdev->dev, "invalid regulator ID specified\n");
541 return -EINVAL;
542 }
543
544 /* Workaround for the weird LDO12 voltage setting */
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800545 if (ri->desc.id == DA9034_ID_LDO12) {
Eric Miao129eef92008-08-27 04:16:08 +0800546 ri->desc.ops = &da9034_regulator_ldo12_ops;
Axel Lin9447f352012-05-08 19:47:47 +0800547 ri->desc.n_voltages = 16;
Haojian Zhuangc1b60872009-07-10 16:03:36 +0800548 }
Eric Miao129eef92008-08-27 04:16:08 +0800549
550 if (ri->desc.id == DA9030_ID_LDO14)
551 ri->desc.ops = &da9030_regulator_ldo14_ops;
552
553 if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
554 ri->desc.ops = &da9030_regulator_ldo1_15_ops;
555
Mark Brownc1727082012-04-04 00:50:22 +0100556 config.dev = &pdev->dev;
Axel Linfe53d182012-04-10 13:49:24 +0800557 config.init_data = pdev->dev.platform_data;
Mark Brownc1727082012-04-04 00:50:22 +0100558 config.driver_data = ri;
559
560 rdev = regulator_register(&ri->desc, &config);
Eric Miao129eef92008-08-27 04:16:08 +0800561 if (IS_ERR(rdev)) {
562 dev_err(&pdev->dev, "failed to register regulator %s\n",
563 ri->desc.name);
564 return PTR_ERR(rdev);
565 }
566
567 platform_set_drvdata(pdev, rdev);
568 return 0;
569}
570
571static int __devexit da903x_regulator_remove(struct platform_device *pdev)
572{
573 struct regulator_dev *rdev = platform_get_drvdata(pdev);
574
575 regulator_unregister(rdev);
576 return 0;
577}
578
579static struct platform_driver da903x_regulator_driver = {
580 .driver = {
581 .name = "da903x-regulator",
582 .owner = THIS_MODULE,
583 },
584 .probe = da903x_regulator_probe,
Mike Frysinger5b4662f2009-05-15 14:50:33 -0400585 .remove = __devexit_p(da903x_regulator_remove),
Eric Miao129eef92008-08-27 04:16:08 +0800586};
587
588static int __init da903x_regulator_init(void)
589{
590 return platform_driver_register(&da903x_regulator_driver);
591}
Mark Brown5a1b22b2009-04-27 18:21:18 +0100592subsys_initcall(da903x_regulator_init);
Eric Miao129eef92008-08-27 04:16:08 +0800593
594static void __exit da903x_regulator_exit(void)
595{
596 platform_driver_unregister(&da903x_regulator_driver);
597}
598module_exit(da903x_regulator_exit);
599
600MODULE_LICENSE("GPL");
601MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
602 "Mike Rapoport <mike@compulab.co.il>");
603MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC");
604MODULE_ALIAS("platform:da903x-regulator");