aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshish Jangam <ashish.jangam@kpitcummins.com>2012-11-01 04:27:56 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-11-15 00:29:49 -0500
commitf6130be652d0b4fbf710d83a816298c007e59ed1 (patch)
treefe095e64c811ccba1fbb7193fb74f2d7ab331d13
parent77b67063bb6bce6d475e910d3b886a606d0d91f7 (diff)
regulator: DA9055 regulator driver
This is the Regulator patch for the DA9055 PMIC and has got dependency on the DA9055 MFD core. This patch support all of the DA9055 regulators. The output voltages are fully programmable through I2C interface only. The platform data with regulation constraints is passed down from the board to the regulator. This patch is functionaly tested on SMDK6410 board. DA9055 Evaluation board was connected to the SMDK6410 board. Signed-off-by: David Dajun Chen <dchen@diasemi.com> Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/Kconfig10
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/da9055-regulator.c663
-rw-r--r--include/linux/mfd/da9055/pdata.h27
4 files changed, 698 insertions, 3 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 67d47b59a66d..a162573d4944 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -109,6 +109,16 @@ config REGULATOR_DA9052
109 This driver supports the voltage regulators of DA9052-BC and 109 This driver supports the voltage regulators of DA9052-BC and
110 DA9053-AA/Bx PMIC. 110 DA9053-AA/Bx PMIC.
111 111
112config REGULATOR_DA9055
113 tristate "Dialog Semiconductor DA9055 regulators"
114 depends on MFD_DA9055
115 help
116 Say y here to support the BUCKs and LDOs regulators found on
117 Dialog Semiconductor DA9055 PMIC.
118
119 This driver can also be built as a module. If so, the module
120 will be called da9055-regulator.
121
112config REGULATOR_FAN53555 122config REGULATOR_FAN53555
113 tristate "Fairchild FAN53555 Regulator" 123 tristate "Fairchild FAN53555 Regulator"
114 depends on I2C 124 depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index e431eed8a878..4b754e958aed 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
18obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o 18obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
19obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 19obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o 20obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
21obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
21obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o 22obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
22obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o 23obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
23obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o 24obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
new file mode 100644
index 000000000000..8994178b371c
--- /dev/null
+++ b/drivers/regulator/da9055-regulator.c
@@ -0,0 +1,663 @@
1/*
2* Regulator driver for DA9055 PMIC
3*
4* Copyright(c) 2012 Dialog Semiconductor Ltd.
5*
6* Author: David Dajun Chen <dchen@diasemi.com>
7*
8* This program is free software; you can redistribute it and/or modify
9* it under the terms of the GNU General Public License as published by
10* the Free Software Foundation; either version 2 of the License, or
11* (at your option) any later version.
12*
13*/
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/gpio.h>
19#include <linux/platform_device.h>
20#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h>
22
23#include <linux/mfd/da9055/core.h>
24#include <linux/mfd/da9055/reg.h>
25#include <linux/mfd/da9055/pdata.h>
26
27#define DA9055_MIN_UA 0
28#define DA9055_MAX_UA 3
29
30#define DA9055_LDO_MODE_SYNC 0
31#define DA9055_LDO_MODE_SLEEP 1
32
33#define DA9055_BUCK_MODE_SLEEP 1
34#define DA9055_BUCK_MODE_SYNC 2
35#define DA9055_BUCK_MODE_AUTO 3
36
37/* DA9055 REGULATOR IDs */
38#define DA9055_ID_BUCK1 0
39#define DA9055_ID_BUCK2 1
40#define DA9055_ID_LDO1 2
41#define DA9055_ID_LDO2 3
42#define DA9055_ID_LDO3 4
43#define DA9055_ID_LDO4 5
44#define DA9055_ID_LDO5 6
45#define DA9055_ID_LDO6 7
46
47/* DA9055 BUCK current limit */
48static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 };
49
50struct da9055_conf_reg {
51 int reg;
52 int sel_mask;
53 int en_mask;
54};
55
56struct da9055_volt_reg {
57 int reg_a;
58 int reg_b;
59 int sl_shift;
60 int v_offset;
61 int v_mask;
62 int v_shift;
63};
64
65struct da9055_mode_reg {
66 int reg;
67 int mask;
68 int shift;
69};
70
71struct da9055_regulator_info {
72 struct regulator_desc reg_desc;
73 struct da9055_conf_reg conf;
74 struct da9055_volt_reg volt;
75 struct da9055_mode_reg mode;
76};
77
78struct da9055_regulator {
79 struct da9055 *da9055;
80 struct da9055_regulator_info *info;
81 struct regulator_dev *rdev;
82 enum gpio_select reg_rselect;
83};
84
85static unsigned int da9055_buck_get_mode(struct regulator_dev *rdev)
86{
87 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
88 struct da9055_regulator_info *info = regulator->info;
89 int ret, mode = 0;
90
91 ret = da9055_reg_read(regulator->da9055, info->mode.reg);
92 if (ret < 0)
93 return ret;
94
95 switch ((ret & info->mode.mask) >> info->mode.shift) {
96 case DA9055_BUCK_MODE_SYNC:
97 mode = REGULATOR_MODE_FAST;
98 break;
99 case DA9055_BUCK_MODE_AUTO:
100 mode = REGULATOR_MODE_NORMAL;
101 break;
102 case DA9055_BUCK_MODE_SLEEP:
103 mode = REGULATOR_MODE_STANDBY;
104 break;
105 }
106
107 return mode;
108}
109
110static int da9055_buck_set_mode(struct regulator_dev *rdev,
111 unsigned int mode)
112{
113 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
114 struct da9055_regulator_info *info = regulator->info;
115 int val = 0;
116
117 switch (mode) {
118 case REGULATOR_MODE_FAST:
119 val = DA9055_BUCK_MODE_SYNC << info->mode.shift;
120 break;
121 case REGULATOR_MODE_NORMAL:
122 val = DA9055_BUCK_MODE_AUTO << info->mode.shift;
123 break;
124 case REGULATOR_MODE_STANDBY:
125 val = DA9055_BUCK_MODE_SLEEP << info->mode.shift;
126 break;
127 }
128
129 return da9055_reg_update(regulator->da9055, info->mode.reg,
130 info->mode.mask, val);
131}
132
133static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
134{
135 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
136 struct da9055_regulator_info *info = regulator->info;
137 int ret;
138
139 ret = da9055_reg_read(regulator->da9055, info->volt.reg_b);
140 if (ret < 0)
141 return ret;
142
143 if (ret >> info->volt.sl_shift)
144 return REGULATOR_MODE_STANDBY;
145 else
146 return REGULATOR_MODE_NORMAL;
147}
148
149static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
150{
151 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
152 struct da9055_regulator_info *info = regulator->info;
153 struct da9055_volt_reg volt = info->volt;
154 int val = 0;
155
156 switch (mode) {
157 case REGULATOR_MODE_NORMAL:
158 case REGULATOR_MODE_FAST:
159 val = DA9055_LDO_MODE_SYNC;
160 break;
161 case REGULATOR_MODE_STANDBY:
162 val = DA9055_LDO_MODE_SLEEP;
163 break;
164 }
165
166 return da9055_reg_update(regulator->da9055, volt.reg_b,
167 1 << volt.sl_shift,
168 val << volt.sl_shift);
169}
170
171static int da9055_buck_get_current_limit(struct regulator_dev *rdev)
172{
173 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
174 struct da9055_regulator_info *info = regulator->info;
175 int ret;
176
177 ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM);
178 if (ret < 0)
179 return ret;
180
181 ret &= info->mode.mask;
182 return da9055_current_limits[ret >> info->mode.shift];
183}
184
185static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
186 int max_uA)
187{
188 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
189 struct da9055_regulator_info *info = regulator->info;
190 int i, val = 0;
191
192 if (min_uA > da9055_current_limits[DA9055_MAX_UA] ||
193 max_uA < da9055_current_limits[DA9055_MIN_UA])
194 return -EINVAL;
195
196 for (i = 0; i < ARRAY_SIZE(da9055_current_limits); i++) {
197 if (min_uA <= da9055_current_limits[i]) {
198 val = i;
199 break;
200 }
201 }
202
203 return da9055_reg_update(regulator->da9055, DA9055_REG_BUCK_LIM,
204 info->mode.mask, val << info->mode.shift);
205}
206
207static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
208{
209 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
210 struct da9055_regulator_info *info = regulator->info;
211 struct da9055_volt_reg volt = info->volt;
212 int ret, sel;
213
214 /*
215 * There are two voltage register set A & B for voltage ramping but
216 * either one of then can be active therefore we first determine
217 * the active register set.
218 */
219 ret = da9055_reg_read(regulator->da9055, info->conf.reg);
220 if (ret < 0)
221 return ret;
222
223 ret &= info->conf.sel_mask;
224
225 /* Get the voltage for the active register set A/B */
226 if (ret == DA9055_REGUALTOR_SET_A)
227 ret = da9055_reg_read(regulator->da9055, volt.reg_a);
228 else
229 ret = da9055_reg_read(regulator->da9055, volt.reg_b);
230
231 if (ret < 0)
232 return ret;
233
234 sel = (ret & volt.v_mask);
235 if (sel <= volt.v_offset)
236 return 0;
237 else
238 return sel;
239}
240
241static int da9055_regulator_set_voltage_bits(struct regulator_dev *rdev,
242 unsigned int reg,
243 unsigned int selector)
244{
245 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
246 struct da9055_regulator_info *info = regulator->info;
247
248 /* Takes care of voltage range that does not start with 0 offset. */
249 selector += info->volt.v_offset;
250
251 /* Set the voltage */
252 return da9055_reg_update(regulator->da9055, reg, info->volt.v_mask,
253 selector);
254
255}
256
257static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
258 unsigned int selector)
259{
260 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
261 struct da9055_regulator_info *info = regulator->info;
262 int ret;
263
264 /*
265 * Regulator register set A/B is not selected through GPIO therefore
266 * we use default register set A for voltage ramping.
267 */
268 if (regulator->reg_rselect == NO_GPIO) {
269 /* Select register set A */
270 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
271 info->conf.sel_mask, DA9055_SEL_REG_A);
272 if (ret < 0)
273 return ret;
274
275 /* Set the voltage */
276 return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_a,
277 selector);
278 }
279
280 /*
281 * Here regulator register set A/B is selected through GPIO.
282 * Therefore we first determine the selected register set A/B and
283 * then set the desired voltage for that register set A/B.
284 */
285 ret = da9055_reg_read(regulator->da9055, info->conf.reg);
286 if (ret < 0)
287 return ret;
288
289 ret &= info->conf.sel_mask;
290
291 /* Set the voltage */
292 if (ret == DA9055_REGUALTOR_SET_A)
293 return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_a,
294 selector);
295 else
296 return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_b,
297 selector);
298}
299
300static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
301 int uV)
302{
303 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
304 struct da9055_regulator_info *info = regulator->info;
305 int ret;
306
307 /* Select register set B for suspend voltage ramping. */
308 if (regulator->reg_rselect == NO_GPIO) {
309 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
310 info->conf.sel_mask, DA9055_SEL_REG_B);
311 if (ret < 0)
312 return ret;
313 }
314
315 ret = regulator_map_voltage_linear(rdev, uV, uV);
316 if (ret < 0)
317 return ret;
318
319 return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_b, ret);
320}
321
322static int da9055_suspend_enable(struct regulator_dev *rdev)
323{
324 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
325 struct da9055_regulator_info *info = regulator->info;
326
327 /* Select register set B for voltage ramping. */
328 if (regulator->reg_rselect == NO_GPIO)
329 return da9055_reg_update(regulator->da9055, info->conf.reg,
330 info->conf.sel_mask, DA9055_SEL_REG_B);
331 else
332 return 0;
333}
334
335static int da9055_suspend_disable(struct regulator_dev *rdev)
336{
337 struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
338 struct da9055_regulator_info *info = regulator->info;
339
340 /* Diselect register set B. */
341 if (regulator->reg_rselect == NO_GPIO)
342 return da9055_reg_update(regulator->da9055, info->conf.reg,
343 info->conf.sel_mask, DA9055_SEL_REG_A);
344 else
345 return 0;
346}
347
348static struct regulator_ops da9055_buck_ops = {
349 .get_mode = da9055_buck_get_mode,
350 .set_mode = da9055_buck_set_mode,
351
352 .get_current_limit = da9055_buck_get_current_limit,
353 .set_current_limit = da9055_buck_set_current_limit,
354
355 .get_voltage_sel = da9055_regulator_get_voltage_sel,
356 .set_voltage_sel = da9055_regulator_set_voltage_sel,
357 .list_voltage = regulator_list_voltage_linear,
358 .map_voltage = regulator_map_voltage_linear,
359 .is_enabled = regulator_is_enabled_regmap,
360 .enable = regulator_enable_regmap,
361 .disable = regulator_disable_regmap,
362
363 .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
364 .set_suspend_enable = da9055_suspend_enable,
365 .set_suspend_disable = da9055_suspend_disable,
366 .set_suspend_mode = da9055_buck_set_mode,
367};
368
369static struct regulator_ops da9055_ldo_ops = {
370 .get_mode = da9055_ldo_get_mode,
371 .set_mode = da9055_ldo_set_mode,
372
373 .get_voltage_sel = da9055_regulator_get_voltage_sel,
374 .set_voltage_sel = da9055_regulator_set_voltage_sel,
375 .list_voltage = regulator_list_voltage_linear,
376 .map_voltage = regulator_map_voltage_linear,
377 .is_enabled = regulator_is_enabled_regmap,
378 .enable = regulator_enable_regmap,
379 .disable = regulator_disable_regmap,
380
381 .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
382 .set_suspend_enable = da9055_suspend_enable,
383 .set_suspend_disable = da9055_suspend_disable,
384 .set_suspend_mode = da9055_ldo_set_mode,
385
386};
387
388#define DA9055_LDO(_id, step, min, max, vbits, voffset) \
389{\
390 .reg_desc = {\
391 .name = #_id,\
392 .ops = &da9055_ldo_ops,\
393 .type = REGULATOR_VOLTAGE,\
394 .id = DA9055_ID_##_id,\
395 .n_voltages = (max - min) / step + 1, \
396 .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
397 .enable_mask = 1, \
398 .min_uV = (min) * 1000,\
399 .uV_step = (step) * 1000,\
400 .owner = THIS_MODULE,\
401 },\
402 .conf = {\
403 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
404 .sel_mask = (1 << 4),\
405 .en_mask = 1,\
406 },\
407 .volt = {\
408 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
409 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
410 .sl_shift = 7,\
411 .v_offset = (voffset),\
412 .v_mask = (1 << (vbits)) - 1,\
413 .v_shift = (vbits),\
414 },\
415}
416
417#define DA9055_BUCK(_id, step, min, max, vbits, voffset, mbits, sbits) \
418{\
419 .reg_desc = {\
420 .name = #_id,\
421 .ops = &da9055_buck_ops,\
422 .type = REGULATOR_VOLTAGE,\
423 .id = DA9055_ID_##_id,\
424 .n_voltages = (max - min) / step + 1, \
425 .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
426 .enable_mask = 1,\
427 .min_uV = (min) * 1000,\
428 .uV_step = (step) * 1000,\
429 .owner = THIS_MODULE,\
430 },\
431 .conf = {\
432 .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
433 .sel_mask = (1 << 4),\
434 .en_mask = 1,\
435 },\
436 .volt = {\
437 .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
438 .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
439 .sl_shift = 7,\
440 .v_offset = (voffset),\
441 .v_mask = (1 << (vbits)) - 1,\
442 .v_shift = (vbits),\
443 },\
444 .mode = {\
445 .reg = DA9055_REG_BCORE_MODE,\
446 .mask = (mbits),\
447 .shift = (sbits),\
448 },\
449}
450
451static struct da9055_regulator_info da9055_regulator_info[] = {
452 DA9055_BUCK(BUCK1, 25, 725, 2075, 6, 9, 0xc, 2),
453 DA9055_BUCK(BUCK2, 25, 925, 2500, 6, 0, 3, 0),
454 DA9055_LDO(LDO1, 50, 900, 3300, 6, 2),
455 DA9055_LDO(LDO2, 50, 900, 3300, 6, 3),
456 DA9055_LDO(LDO3, 50, 900, 3300, 6, 2),
457 DA9055_LDO(LDO4, 50, 900, 3300, 6, 2),
458 DA9055_LDO(LDO5, 50, 900, 2750, 6, 2),
459 DA9055_LDO(LDO6, 20, 900, 3300, 7, 0),
460};
461
462/*
463 * Configures regulator to be controlled either through GPIO 1 or 2.
464 * GPIO can control regulator state and/or select the regulator register
465 * set A/B for voltage ramping.
466 */
467static __devinit int da9055_gpio_init(struct da9055_regulator *regulator,
468 struct regulator_config *config,
469 struct da9055_pdata *pdata, int id)
470{
471 struct da9055_regulator_info *info = regulator->info;
472 int ret = 0;
473
474 if (pdata->gpio_ren && pdata->gpio_ren[id]) {
475 char name[18];
476 int gpio_mux = pdata->gpio_ren[id];
477
478 config->ena_gpio = pdata->ena_gpio[id];
479 config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
480 config->ena_gpio_invert = 1;
481
482 /*
483 * GPI pin is muxed with regulator to control the
484 * regulator state.
485 */
486 sprintf(name, "DA9055 GPI %d", gpio_mux);
487 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
488 name);
489 if (ret < 0)
490 goto err;
491
492 /*
493 * Let the regulator know that its state is controlled
494 * through GPI.
495 */
496 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
497 DA9055_E_GPI_MASK,
498 pdata->reg_ren[id]
499 << DA9055_E_GPI_SHIFT);
500 if (ret < 0)
501 goto err;
502 }
503
504 if (pdata->gpio_rsel && pdata->gpio_ren[id]) {
505 char name[18];
506 int gpio_mux = pdata->gpio_rsel[id];
507
508 regulator->reg_rselect = pdata->reg_rsel[id];
509
510 /*
511 * GPI pin is muxed with regulator to select the
512 * regulator register set A/B for voltage ramping.
513 */
514 sprintf(name, "DA9055 GPI %d", gpio_mux);
515 ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
516 name);
517 if (ret < 0)
518 goto err;
519
520 /*
521 * Let the regulator know that its register set A/B
522 * will be selected through GPI for voltage ramping.
523 */
524 ret = da9055_reg_update(regulator->da9055, info->conf.reg,
525 DA9055_V_GPI_MASK,
526 pdata->reg_rsel[id]
527 << DA9055_V_GPI_SHIFT);
528 }
529
530err:
531 return ret;
532}
533
534static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data)
535{
536 struct da9055_regulator *regulator = data;
537
538 regulator_notifier_call_chain(regulator->rdev,
539 REGULATOR_EVENT_OVER_CURRENT, NULL);
540
541 return IRQ_HANDLED;
542}
543
544static inline struct da9055_regulator_info *find_regulator_info(int id)
545{
546 struct da9055_regulator_info *info;
547 int i;
548
549 for (i = 0; i < ARRAY_SIZE(da9055_regulator_info); i++) {
550 info = &da9055_regulator_info[i];
551 if (info->reg_desc.id == id)
552 return info;
553 }
554
555 return NULL;
556}
557
558static int __devinit da9055_regulator_probe(struct platform_device *pdev)
559{
560 struct regulator_config config = { };
561 struct da9055_regulator *regulator;
562 struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
563 struct da9055_pdata *pdata = da9055->dev->platform_data;
564 int ret, irq;
565
566 if (pdata == NULL || pdata->regulators[pdev->id] == NULL)
567 return -ENODEV;
568
569 regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator),
570 GFP_KERNEL);
571 if (!regulator)
572 return -ENOMEM;
573
574 regulator->info = find_regulator_info(pdev->id);
575 if (regulator->info == NULL) {
576 dev_err(&pdev->dev, "invalid regulator ID specified\n");
577 return -EINVAL;
578 }
579
580 regulator->da9055 = da9055;
581 config.dev = &pdev->dev;
582 config.driver_data = regulator;
583 config.regmap = da9055->regmap;
584
585 if (pdata && pdata->regulators)
586 config.init_data = pdata->regulators[pdev->id];
587
588 ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
589 if (ret < 0)
590 return ret;
591
592 regulator->rdev = regulator_register(&regulator->info->reg_desc,
593 &config);
594 if (IS_ERR(regulator->rdev)) {
595 dev_err(&pdev->dev, "Failed to register regulator %s\n",
596 regulator->info->reg_desc.name);
597 ret = PTR_ERR(regulator->rdev);
598 return ret;
599 }
600
601 /* Only LDO 5 and 6 has got the over current interrupt */
602 if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) {
603 irq = platform_get_irq_byname(pdev, "REGULATOR");
604 irq = regmap_irq_get_virq(da9055->irq_data, irq);
605 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
606 da9055_ldo5_6_oc_irq,
607 IRQF_TRIGGER_HIGH |
608 IRQF_ONESHOT |
609 IRQF_PROBE_SHARED,
610 pdev->name, regulator);
611 if (ret != 0) {
612 if (ret != -EBUSY) {
613 dev_err(&pdev->dev,
614 "Failed to request Regulator IRQ %d: %d\n",
615 irq, ret);
616 goto err_regulator;
617 }
618 }
619 }
620
621 platform_set_drvdata(pdev, regulator);
622
623 return 0;
624
625err_regulator:
626 regulator_unregister(regulator->rdev);
627 return ret;
628}
629
630static int __devexit da9055_regulator_remove(struct platform_device *pdev)
631{
632 struct da9055_regulator *regulator = platform_get_drvdata(pdev);
633
634 regulator_unregister(regulator->rdev);
635
636 return 0;
637}
638
639static struct platform_driver da9055_regulator_driver = {
640 .probe = da9055_regulator_probe,
641 .remove = __devexit_p(da9055_regulator_remove),
642 .driver = {
643 .name = "da9055-regulator",
644 .owner = THIS_MODULE,
645 },
646};
647
648static int __init da9055_regulator_init(void)
649{
650 return platform_driver_register(&da9055_regulator_driver);
651}
652subsys_initcall(da9055_regulator_init);
653
654static void __exit da9055_regulator_exit(void)
655{
656 platform_driver_unregister(&da9055_regulator_driver);
657}
658module_exit(da9055_regulator_exit);
659
660MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
661MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9055 PMIC");
662MODULE_LICENSE("GPL");
663MODULE_ALIAS("platform:da9055-regulator");
diff --git a/include/linux/mfd/da9055/pdata.h b/include/linux/mfd/da9055/pdata.h
index 147293b4471d..f87a6c172a91 100644
--- a/include/linux/mfd/da9055/pdata.h
+++ b/include/linux/mfd/da9055/pdata.h
@@ -25,8 +25,29 @@ struct da9055_pdata {
25 int gpio_base; 25 int gpio_base;
26 26
27 struct regulator_init_data *regulators[DA9055_MAX_REGULATORS]; 27 struct regulator_init_data *regulators[DA9055_MAX_REGULATORS];
28 bool reset_enable; /* Enable RTC in RESET Mode */ 28 /* Enable RTC in RESET Mode */
29 enum gpio_select *gpio_rsel; /* Select regulator set thru GPIO 1/2 */ 29 bool reset_enable;
30 enum gpio_select *gpio_ren; /* Enable regulator thru GPIO 1/2 */ 30 /*
31 * GPI muxed pin to control
32 * regulator state A/B, 0 if not available.
33 */
34 int *gpio_ren;
35 /*
36 * GPI muxed pin to control
37 * regulator set, 0 if not available.
38 */
39 int *gpio_rsel;
40 /*
41 * Regulator mode control bits value (GPI offset) that
42 * that controls the regulator state, 0 if not available.
43 */
44 enum gpio_select *reg_ren;
45 /*
46 * Regulator mode control bits value (GPI offset) that
47 * controls the regulator set A/B, 0 if not available.
48 */
49 enum gpio_select *reg_rsel;
50 /* GPIOs to enable regulator, 0 if not available */
51 int *ena_gpio;
31}; 52};
32#endif /* __DA9055_PDATA_H */ 53#endif /* __DA9055_PDATA_H */