2 * wm831x-ldo.c -- LDO driver for the WM831x series
4 * Copyright 2009 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/bitops.h>
18 #include <linux/err.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/slab.h>
24 #include <linux/mfd/wm831x/core.h>
25 #include <linux/mfd/wm831x/regulator.h>
26 #include <linux/mfd/wm831x/pdata.h>
28 #define WM831X_LDO_MAX_NAME 6
30 #define WM831X_LDO_CONTROL 0
31 #define WM831X_LDO_ON_CONTROL 1
32 #define WM831X_LDO_SLEEP_CONTROL 2
34 #define WM831X_ALIVE_LDO_ON_CONTROL 0
35 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
38 char name
[WM831X_LDO_MAX_NAME
];
39 struct regulator_desc desc
;
41 struct wm831x
*wm831x
;
42 struct regulator_dev
*regulator
;
49 static int wm831x_ldo_is_enabled(struct regulator_dev
*rdev
)
51 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
52 struct wm831x
*wm831x
= ldo
->wm831x
;
53 int mask
= 1 << rdev_get_id(rdev
);
56 reg
= wm831x_reg_read(wm831x
, WM831X_LDO_ENABLE
);
66 static int wm831x_ldo_enable(struct regulator_dev
*rdev
)
68 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
69 struct wm831x
*wm831x
= ldo
->wm831x
;
70 int mask
= 1 << rdev_get_id(rdev
);
72 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, mask
);
75 static int wm831x_ldo_disable(struct regulator_dev
*rdev
)
77 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
78 struct wm831x
*wm831x
= ldo
->wm831x
;
79 int mask
= 1 << rdev_get_id(rdev
);
81 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, 0);
84 static irqreturn_t
wm831x_ldo_uv_irq(int irq
, void *data
)
86 struct wm831x_ldo
*ldo
= data
;
88 regulator_notifier_call_chain(ldo
->regulator
,
89 REGULATOR_EVENT_UNDER_VOLTAGE
,
96 * General purpose LDOs
99 #define WM831X_GP_LDO_SELECTOR_LOW 0xe
100 #define WM831X_GP_LDO_MAX_SELECTOR 0x1f
102 static int wm831x_gp_ldo_list_voltage(struct regulator_dev
*rdev
,
103 unsigned int selector
)
105 /* 0.9-1.6V in 50mV steps */
106 if (selector
<= WM831X_GP_LDO_SELECTOR_LOW
)
107 return 900000 + (selector
* 50000);
108 /* 1.7-3.3V in 50mV steps */
109 if (selector
<= WM831X_GP_LDO_MAX_SELECTOR
)
110 return 1600000 + ((selector
- WM831X_GP_LDO_SELECTOR_LOW
)
115 static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
116 int min_uV
, int max_uV
,
119 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
120 struct wm831x
*wm831x
= ldo
->wm831x
;
125 else if (min_uV
< 1700000)
126 vsel
= ((min_uV
- 900000) / 50000);
128 vsel
= ((min_uV
- 1700000) / 100000)
129 + WM831X_GP_LDO_SELECTOR_LOW
+ 1;
131 ret
= wm831x_gp_ldo_list_voltage(rdev
, vsel
);
134 if (ret
< min_uV
|| ret
> max_uV
)
139 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO1_ON_VSEL_MASK
, vsel
);
142 static int wm831x_gp_ldo_set_voltage(struct regulator_dev
*rdev
,
143 int min_uV
, int max_uV
,
146 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
147 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
149 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
,
153 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
156 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
157 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
158 unsigned int selector
;
160 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, uV
, uV
, &selector
);
163 static int wm831x_gp_ldo_get_voltage_sel(struct regulator_dev
*rdev
)
165 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
166 struct wm831x
*wm831x
= ldo
->wm831x
;
167 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
170 ret
= wm831x_reg_read(wm831x
, reg
);
174 ret
&= WM831X_LDO1_ON_VSEL_MASK
;
179 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev
*rdev
)
181 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
182 struct wm831x
*wm831x
= ldo
->wm831x
;
183 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
184 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
187 ret
= wm831x_reg_read(wm831x
, on_reg
);
191 if (!(ret
& WM831X_LDO1_ON_MODE
))
192 return REGULATOR_MODE_NORMAL
;
194 ret
= wm831x_reg_read(wm831x
, ctrl_reg
);
198 if (ret
& WM831X_LDO1_LP_MODE
)
199 return REGULATOR_MODE_STANDBY
;
201 return REGULATOR_MODE_IDLE
;
204 static int wm831x_gp_ldo_set_mode(struct regulator_dev
*rdev
,
207 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
208 struct wm831x
*wm831x
= ldo
->wm831x
;
209 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
210 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
215 case REGULATOR_MODE_NORMAL
:
216 ret
= wm831x_set_bits(wm831x
, on_reg
,
217 WM831X_LDO1_ON_MODE
, 0);
222 case REGULATOR_MODE_IDLE
:
223 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
224 WM831X_LDO1_LP_MODE
, 0);
228 ret
= wm831x_set_bits(wm831x
, on_reg
,
230 WM831X_LDO1_ON_MODE
);
235 case REGULATOR_MODE_STANDBY
:
236 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
238 WM831X_LDO1_LP_MODE
);
242 ret
= wm831x_set_bits(wm831x
, on_reg
,
244 WM831X_LDO1_ON_MODE
);
256 static int wm831x_gp_ldo_get_status(struct regulator_dev
*rdev
)
258 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
259 struct wm831x
*wm831x
= ldo
->wm831x
;
260 int mask
= 1 << rdev_get_id(rdev
);
263 /* Is the regulator on? */
264 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
268 return REGULATOR_STATUS_OFF
;
270 /* Is it reporting under voltage? */
271 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
273 return REGULATOR_STATUS_ERROR
;
275 ret
= wm831x_gp_ldo_get_mode(rdev
);
279 return regulator_mode_to_status(ret
);
282 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev
*rdev
,
284 int output_uV
, int load_uA
)
287 return REGULATOR_MODE_STANDBY
;
289 return REGULATOR_MODE_IDLE
;
290 return REGULATOR_MODE_NORMAL
;
294 static struct regulator_ops wm831x_gp_ldo_ops
= {
295 .list_voltage
= wm831x_gp_ldo_list_voltage
,
296 .get_voltage_sel
= wm831x_gp_ldo_get_voltage_sel
,
297 .set_voltage
= wm831x_gp_ldo_set_voltage
,
298 .set_suspend_voltage
= wm831x_gp_ldo_set_suspend_voltage
,
299 .get_mode
= wm831x_gp_ldo_get_mode
,
300 .set_mode
= wm831x_gp_ldo_set_mode
,
301 .get_status
= wm831x_gp_ldo_get_status
,
302 .get_optimum_mode
= wm831x_gp_ldo_get_optimum_mode
,
304 .is_enabled
= wm831x_ldo_is_enabled
,
305 .enable
= wm831x_ldo_enable
,
306 .disable
= wm831x_ldo_disable
,
309 static __devinit
int wm831x_gp_ldo_probe(struct platform_device
*pdev
)
311 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
312 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
314 struct wm831x_ldo
*ldo
;
315 struct resource
*res
;
318 if (pdata
&& pdata
->wm831x_num
)
319 id
= (pdata
->wm831x_num
* 10) + 1;
324 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
326 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
329 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_ldo
), GFP_KERNEL
);
331 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
335 ldo
->wm831x
= wm831x
;
337 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
339 dev_err(&pdev
->dev
, "No I/O resource\n");
343 ldo
->base
= res
->start
;
345 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
346 ldo
->desc
.name
= ldo
->name
;
348 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
349 ldo
->desc
.n_voltages
= WM831X_GP_LDO_MAX_SELECTOR
+ 1;
350 ldo
->desc
.ops
= &wm831x_gp_ldo_ops
;
351 ldo
->desc
.owner
= THIS_MODULE
;
353 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
354 pdata
->ldo
[id
], ldo
, NULL
);
355 if (IS_ERR(ldo
->regulator
)) {
356 ret
= PTR_ERR(ldo
->regulator
);
357 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
362 irq
= platform_get_irq_byname(pdev
, "UV");
363 ret
= request_threaded_irq(irq
, NULL
, wm831x_ldo_uv_irq
,
364 IRQF_TRIGGER_RISING
, ldo
->name
,
367 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
372 platform_set_drvdata(pdev
, ldo
);
377 regulator_unregister(ldo
->regulator
);
382 static __devexit
int wm831x_gp_ldo_remove(struct platform_device
*pdev
)
384 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
386 platform_set_drvdata(pdev
, NULL
);
388 free_irq(platform_get_irq_byname(pdev
, "UV"), ldo
);
389 regulator_unregister(ldo
->regulator
);
394 static struct platform_driver wm831x_gp_ldo_driver
= {
395 .probe
= wm831x_gp_ldo_probe
,
396 .remove
= __devexit_p(wm831x_gp_ldo_remove
),
398 .name
= "wm831x-ldo",
399 .owner
= THIS_MODULE
,
408 #define WM831X_ALDO_SELECTOR_LOW 0xc
409 #define WM831X_ALDO_MAX_SELECTOR 0x1f
411 static int wm831x_aldo_list_voltage(struct regulator_dev
*rdev
,
412 unsigned int selector
)
414 /* 1-1.6V in 50mV steps */
415 if (selector
<= WM831X_ALDO_SELECTOR_LOW
)
416 return 1000000 + (selector
* 50000);
417 /* 1.7-3.5V in 50mV steps */
418 if (selector
<= WM831X_ALDO_MAX_SELECTOR
)
419 return 1600000 + ((selector
- WM831X_ALDO_SELECTOR_LOW
)
424 static int wm831x_aldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
425 int min_uV
, int max_uV
,
428 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
429 struct wm831x
*wm831x
= ldo
->wm831x
;
432 if (min_uV
< 1000000)
434 else if (min_uV
< 1700000)
435 vsel
= ((min_uV
- 1000000) / 50000);
437 vsel
= ((min_uV
- 1700000) / 100000)
438 + WM831X_ALDO_SELECTOR_LOW
+ 1;
440 ret
= wm831x_aldo_list_voltage(rdev
, vsel
);
443 if (ret
< min_uV
|| ret
> max_uV
)
448 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO7_ON_VSEL_MASK
, vsel
);
451 static int wm831x_aldo_set_voltage(struct regulator_dev
*rdev
,
452 int min_uV
, int max_uV
, unsigned *selector
)
454 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
455 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
457 return wm831x_aldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
,
461 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev
*rdev
,
464 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
465 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
466 unsigned int selector
;
468 return wm831x_aldo_set_voltage_int(rdev
, reg
, uV
, uV
, &selector
);
471 static int wm831x_aldo_get_voltage_sel(struct regulator_dev
*rdev
)
473 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
474 struct wm831x
*wm831x
= ldo
->wm831x
;
475 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
478 ret
= wm831x_reg_read(wm831x
, reg
);
482 ret
&= WM831X_LDO7_ON_VSEL_MASK
;
487 static unsigned int wm831x_aldo_get_mode(struct regulator_dev
*rdev
)
489 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
490 struct wm831x
*wm831x
= ldo
->wm831x
;
491 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
494 ret
= wm831x_reg_read(wm831x
, on_reg
);
498 if (ret
& WM831X_LDO7_ON_MODE
)
499 return REGULATOR_MODE_IDLE
;
501 return REGULATOR_MODE_NORMAL
;
504 static int wm831x_aldo_set_mode(struct regulator_dev
*rdev
,
507 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
508 struct wm831x
*wm831x
= ldo
->wm831x
;
509 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
514 case REGULATOR_MODE_NORMAL
:
515 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_LDO7_ON_MODE
, 0);
520 case REGULATOR_MODE_IDLE
:
521 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_LDO7_ON_MODE
,
522 WM831X_LDO7_ON_MODE
);
534 static int wm831x_aldo_get_status(struct regulator_dev
*rdev
)
536 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
537 struct wm831x
*wm831x
= ldo
->wm831x
;
538 int mask
= 1 << rdev_get_id(rdev
);
541 /* Is the regulator on? */
542 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
546 return REGULATOR_STATUS_OFF
;
548 /* Is it reporting under voltage? */
549 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
551 return REGULATOR_STATUS_ERROR
;
553 ret
= wm831x_aldo_get_mode(rdev
);
557 return regulator_mode_to_status(ret
);
560 static struct regulator_ops wm831x_aldo_ops
= {
561 .list_voltage
= wm831x_aldo_list_voltage
,
562 .get_voltage_sel
= wm831x_aldo_get_voltage_sel
,
563 .set_voltage
= wm831x_aldo_set_voltage
,
564 .set_suspend_voltage
= wm831x_aldo_set_suspend_voltage
,
565 .get_mode
= wm831x_aldo_get_mode
,
566 .set_mode
= wm831x_aldo_set_mode
,
567 .get_status
= wm831x_aldo_get_status
,
569 .is_enabled
= wm831x_ldo_is_enabled
,
570 .enable
= wm831x_ldo_enable
,
571 .disable
= wm831x_ldo_disable
,
574 static __devinit
int wm831x_aldo_probe(struct platform_device
*pdev
)
576 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
577 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
579 struct wm831x_ldo
*ldo
;
580 struct resource
*res
;
583 if (pdata
&& pdata
->wm831x_num
)
584 id
= (pdata
->wm831x_num
* 10) + 1;
589 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
591 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
594 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_ldo
), GFP_KERNEL
);
596 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
600 ldo
->wm831x
= wm831x
;
602 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
604 dev_err(&pdev
->dev
, "No I/O resource\n");
608 ldo
->base
= res
->start
;
610 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
611 ldo
->desc
.name
= ldo
->name
;
613 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
614 ldo
->desc
.n_voltages
= WM831X_ALDO_MAX_SELECTOR
+ 1;
615 ldo
->desc
.ops
= &wm831x_aldo_ops
;
616 ldo
->desc
.owner
= THIS_MODULE
;
618 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
619 pdata
->ldo
[id
], ldo
, NULL
);
620 if (IS_ERR(ldo
->regulator
)) {
621 ret
= PTR_ERR(ldo
->regulator
);
622 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
627 irq
= platform_get_irq_byname(pdev
, "UV");
628 ret
= request_threaded_irq(irq
, NULL
, wm831x_ldo_uv_irq
,
629 IRQF_TRIGGER_RISING
, ldo
->name
, ldo
);
631 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
636 platform_set_drvdata(pdev
, ldo
);
641 regulator_unregister(ldo
->regulator
);
646 static __devexit
int wm831x_aldo_remove(struct platform_device
*pdev
)
648 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
650 free_irq(platform_get_irq_byname(pdev
, "UV"), ldo
);
651 regulator_unregister(ldo
->regulator
);
656 static struct platform_driver wm831x_aldo_driver
= {
657 .probe
= wm831x_aldo_probe
,
658 .remove
= __devexit_p(wm831x_aldo_remove
),
660 .name
= "wm831x-aldo",
661 .owner
= THIS_MODULE
,
669 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
671 static int wm831x_alive_ldo_list_voltage(struct regulator_dev
*rdev
,
672 unsigned int selector
)
674 /* 0.8-1.55V in 50mV steps */
675 if (selector
<= WM831X_ALIVE_LDO_MAX_SELECTOR
)
676 return 800000 + (selector
* 50000);
680 static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev
*rdev
,
682 int min_uV
, int max_uV
,
685 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
686 struct wm831x
*wm831x
= ldo
->wm831x
;
689 vsel
= (min_uV
- 800000) / 50000;
691 ret
= wm831x_alive_ldo_list_voltage(rdev
, vsel
);
694 if (ret
< min_uV
|| ret
> max_uV
)
699 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO11_ON_VSEL_MASK
, vsel
);
702 static int wm831x_alive_ldo_set_voltage(struct regulator_dev
*rdev
,
703 int min_uV
, int max_uV
,
706 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
707 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
709 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
,
713 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
716 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
717 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_SLEEP_CONTROL
;
720 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, uV
, uV
, &selector
);
723 static int wm831x_alive_ldo_get_voltage_sel(struct regulator_dev
*rdev
)
725 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
726 struct wm831x
*wm831x
= ldo
->wm831x
;
727 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
730 ret
= wm831x_reg_read(wm831x
, reg
);
734 ret
&= WM831X_LDO11_ON_VSEL_MASK
;
739 static int wm831x_alive_ldo_get_status(struct regulator_dev
*rdev
)
741 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
742 struct wm831x
*wm831x
= ldo
->wm831x
;
743 int mask
= 1 << rdev_get_id(rdev
);
746 /* Is the regulator on? */
747 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
751 return REGULATOR_STATUS_ON
;
753 return REGULATOR_STATUS_OFF
;
756 static struct regulator_ops wm831x_alive_ldo_ops
= {
757 .list_voltage
= wm831x_alive_ldo_list_voltage
,
758 .get_voltage_sel
= wm831x_alive_ldo_get_voltage_sel
,
759 .set_voltage
= wm831x_alive_ldo_set_voltage
,
760 .set_suspend_voltage
= wm831x_alive_ldo_set_suspend_voltage
,
761 .get_status
= wm831x_alive_ldo_get_status
,
763 .is_enabled
= wm831x_ldo_is_enabled
,
764 .enable
= wm831x_ldo_enable
,
765 .disable
= wm831x_ldo_disable
,
768 static __devinit
int wm831x_alive_ldo_probe(struct platform_device
*pdev
)
770 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
771 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
773 struct wm831x_ldo
*ldo
;
774 struct resource
*res
;
777 if (pdata
&& pdata
->wm831x_num
)
778 id
= (pdata
->wm831x_num
* 10) + 1;
784 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
786 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
789 ldo
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_ldo
), GFP_KERNEL
);
791 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
795 ldo
->wm831x
= wm831x
;
797 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
799 dev_err(&pdev
->dev
, "No I/O resource\n");
803 ldo
->base
= res
->start
;
805 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
806 ldo
->desc
.name
= ldo
->name
;
808 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
809 ldo
->desc
.n_voltages
= WM831X_ALIVE_LDO_MAX_SELECTOR
+ 1;
810 ldo
->desc
.ops
= &wm831x_alive_ldo_ops
;
811 ldo
->desc
.owner
= THIS_MODULE
;
813 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
814 pdata
->ldo
[id
], ldo
, NULL
);
815 if (IS_ERR(ldo
->regulator
)) {
816 ret
= PTR_ERR(ldo
->regulator
);
817 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
822 platform_set_drvdata(pdev
, ldo
);
830 static __devexit
int wm831x_alive_ldo_remove(struct platform_device
*pdev
)
832 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
834 regulator_unregister(ldo
->regulator
);
839 static struct platform_driver wm831x_alive_ldo_driver
= {
840 .probe
= wm831x_alive_ldo_probe
,
841 .remove
= __devexit_p(wm831x_alive_ldo_remove
),
843 .name
= "wm831x-alive-ldo",
844 .owner
= THIS_MODULE
,
848 static int __init
wm831x_ldo_init(void)
852 ret
= platform_driver_register(&wm831x_gp_ldo_driver
);
854 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret
);
856 ret
= platform_driver_register(&wm831x_aldo_driver
);
858 pr_err("Failed to register WM831x ALDO driver: %d\n", ret
);
860 ret
= platform_driver_register(&wm831x_alive_ldo_driver
);
862 pr_err("Failed to register WM831x alive LDO driver: %d\n",
867 subsys_initcall(wm831x_ldo_init
);
869 static void __exit
wm831x_ldo_exit(void)
871 platform_driver_unregister(&wm831x_alive_ldo_driver
);
872 platform_driver_unregister(&wm831x_aldo_driver
);
873 platform_driver_unregister(&wm831x_gp_ldo_driver
);
875 module_exit(wm831x_ldo_exit
);
877 /* Module information */
878 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
879 MODULE_DESCRIPTION("WM831x LDO driver");
880 MODULE_LICENSE("GPL");
881 MODULE_ALIAS("platform:wm831x-ldo");
882 MODULE_ALIAS("platform:wm831x-aldo");
883 MODULE_ALIAS("platform:wm831x-aliveldo");