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
)
118 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
119 struct wm831x
*wm831x
= ldo
->wm831x
;
124 else if (min_uV
< 1700000)
125 vsel
= ((min_uV
- 900000) / 50000);
127 vsel
= ((min_uV
- 1700000) / 100000)
128 + WM831X_GP_LDO_SELECTOR_LOW
+ 1;
130 ret
= wm831x_gp_ldo_list_voltage(rdev
, vsel
);
133 if (ret
< min_uV
|| ret
> max_uV
)
136 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO1_ON_VSEL_MASK
, vsel
);
139 static int wm831x_gp_ldo_set_voltage(struct regulator_dev
*rdev
,
140 int min_uV
, int max_uV
)
142 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
143 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
145 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
148 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
151 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
152 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
154 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
157 static int wm831x_gp_ldo_get_voltage(struct regulator_dev
*rdev
)
159 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
160 struct wm831x
*wm831x
= ldo
->wm831x
;
161 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
164 ret
= wm831x_reg_read(wm831x
, reg
);
168 ret
&= WM831X_LDO1_ON_VSEL_MASK
;
170 return wm831x_gp_ldo_list_voltage(rdev
, ret
);
173 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev
*rdev
)
175 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
176 struct wm831x
*wm831x
= ldo
->wm831x
;
177 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
178 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
181 ret
= wm831x_reg_read(wm831x
, on_reg
);
185 if (!(ret
& WM831X_LDO1_ON_MODE
))
186 return REGULATOR_MODE_NORMAL
;
188 ret
= wm831x_reg_read(wm831x
, ctrl_reg
);
192 if (ret
& WM831X_LDO1_LP_MODE
)
193 return REGULATOR_MODE_STANDBY
;
195 return REGULATOR_MODE_IDLE
;
198 static int wm831x_gp_ldo_set_mode(struct regulator_dev
*rdev
,
201 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
202 struct wm831x
*wm831x
= ldo
->wm831x
;
203 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
204 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
209 case REGULATOR_MODE_NORMAL
:
210 ret
= wm831x_set_bits(wm831x
, on_reg
,
211 WM831X_LDO1_ON_MODE
, 0);
216 case REGULATOR_MODE_IDLE
:
217 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
219 WM831X_LDO1_LP_MODE
);
223 ret
= wm831x_set_bits(wm831x
, on_reg
,
225 WM831X_LDO1_ON_MODE
);
229 case REGULATOR_MODE_STANDBY
:
230 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
231 WM831X_LDO1_LP_MODE
, 0);
235 ret
= wm831x_set_bits(wm831x
, on_reg
,
237 WM831X_LDO1_ON_MODE
);
249 static int wm831x_gp_ldo_get_status(struct regulator_dev
*rdev
)
251 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
252 struct wm831x
*wm831x
= ldo
->wm831x
;
253 int mask
= 1 << rdev_get_id(rdev
);
256 /* Is the regulator on? */
257 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
261 return REGULATOR_STATUS_OFF
;
263 /* Is it reporting under voltage? */
264 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
266 return REGULATOR_STATUS_ERROR
;
268 ret
= wm831x_gp_ldo_get_mode(rdev
);
272 return regulator_mode_to_status(ret
);
275 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev
*rdev
,
277 int output_uV
, int load_uA
)
280 return REGULATOR_MODE_STANDBY
;
282 return REGULATOR_MODE_IDLE
;
283 return REGULATOR_MODE_NORMAL
;
287 static struct regulator_ops wm831x_gp_ldo_ops
= {
288 .list_voltage
= wm831x_gp_ldo_list_voltage
,
289 .get_voltage
= wm831x_gp_ldo_get_voltage
,
290 .set_voltage
= wm831x_gp_ldo_set_voltage
,
291 .set_suspend_voltage
= wm831x_gp_ldo_set_suspend_voltage
,
292 .get_mode
= wm831x_gp_ldo_get_mode
,
293 .set_mode
= wm831x_gp_ldo_set_mode
,
294 .get_status
= wm831x_gp_ldo_get_status
,
295 .get_optimum_mode
= wm831x_gp_ldo_get_optimum_mode
,
297 .is_enabled
= wm831x_ldo_is_enabled
,
298 .enable
= wm831x_ldo_enable
,
299 .disable
= wm831x_ldo_disable
,
302 static __devinit
int wm831x_gp_ldo_probe(struct platform_device
*pdev
)
304 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
305 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
306 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
307 struct wm831x_ldo
*ldo
;
308 struct resource
*res
;
311 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
313 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
316 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
318 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
322 ldo
->wm831x
= wm831x
;
324 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
326 dev_err(&pdev
->dev
, "No I/O resource\n");
330 ldo
->base
= res
->start
;
332 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
333 ldo
->desc
.name
= ldo
->name
;
335 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
336 ldo
->desc
.n_voltages
= WM831X_GP_LDO_MAX_SELECTOR
+ 1;
337 ldo
->desc
.ops
= &wm831x_gp_ldo_ops
;
338 ldo
->desc
.owner
= THIS_MODULE
;
340 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
341 pdata
->ldo
[id
], ldo
);
342 if (IS_ERR(ldo
->regulator
)) {
343 ret
= PTR_ERR(ldo
->regulator
);
344 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
349 irq
= platform_get_irq_byname(pdev
, "UV");
350 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
351 IRQF_TRIGGER_RISING
, ldo
->name
,
354 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
359 platform_set_drvdata(pdev
, ldo
);
364 regulator_unregister(ldo
->regulator
);
370 static __devexit
int wm831x_gp_ldo_remove(struct platform_device
*pdev
)
372 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
373 struct wm831x
*wm831x
= ldo
->wm831x
;
375 platform_set_drvdata(pdev
, NULL
);
377 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
378 regulator_unregister(ldo
->regulator
);
384 static struct platform_driver wm831x_gp_ldo_driver
= {
385 .probe
= wm831x_gp_ldo_probe
,
386 .remove
= __devexit_p(wm831x_gp_ldo_remove
),
388 .name
= "wm831x-ldo",
389 .owner
= THIS_MODULE
,
398 #define WM831X_ALDO_SELECTOR_LOW 0xc
399 #define WM831X_ALDO_MAX_SELECTOR 0x1f
401 static int wm831x_aldo_list_voltage(struct regulator_dev
*rdev
,
402 unsigned int selector
)
404 /* 1-1.6V in 50mV steps */
405 if (selector
<= WM831X_ALDO_SELECTOR_LOW
)
406 return 1000000 + (selector
* 50000);
407 /* 1.7-3.5V in 50mV steps */
408 if (selector
<= WM831X_ALDO_MAX_SELECTOR
)
409 return 1600000 + ((selector
- WM831X_ALDO_SELECTOR_LOW
)
414 static int wm831x_aldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
415 int min_uV
, int max_uV
)
417 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
418 struct wm831x
*wm831x
= ldo
->wm831x
;
421 if (min_uV
< 1000000)
423 else if (min_uV
< 1700000)
424 vsel
= ((min_uV
- 1000000) / 50000);
426 vsel
= ((min_uV
- 1700000) / 100000)
427 + WM831X_ALDO_SELECTOR_LOW
+ 1;
429 ret
= wm831x_aldo_list_voltage(rdev
, vsel
);
432 if (ret
< min_uV
|| ret
> max_uV
)
435 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO7_ON_VSEL_MASK
, vsel
);
438 static int wm831x_aldo_set_voltage(struct regulator_dev
*rdev
,
439 int min_uV
, int max_uV
)
441 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
442 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
444 return wm831x_aldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
447 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev
*rdev
,
450 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
451 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
453 return wm831x_aldo_set_voltage_int(rdev
, reg
, uV
, uV
);
456 static int wm831x_aldo_get_voltage(struct regulator_dev
*rdev
)
458 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
459 struct wm831x
*wm831x
= ldo
->wm831x
;
460 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
463 ret
= wm831x_reg_read(wm831x
, reg
);
467 ret
&= WM831X_LDO7_ON_VSEL_MASK
;
469 return wm831x_aldo_list_voltage(rdev
, ret
);
472 static unsigned int wm831x_aldo_get_mode(struct regulator_dev
*rdev
)
474 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
475 struct wm831x
*wm831x
= ldo
->wm831x
;
476 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
479 ret
= wm831x_reg_read(wm831x
, on_reg
);
483 if (ret
& WM831X_LDO7_ON_MODE
)
484 return REGULATOR_MODE_IDLE
;
486 return REGULATOR_MODE_NORMAL
;
489 static int wm831x_aldo_set_mode(struct regulator_dev
*rdev
,
492 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
493 struct wm831x
*wm831x
= ldo
->wm831x
;
494 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
495 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
500 case REGULATOR_MODE_NORMAL
:
501 ret
= wm831x_set_bits(wm831x
, on_reg
,
502 WM831X_LDO7_ON_MODE
, 0);
507 case REGULATOR_MODE_IDLE
:
508 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
510 WM831X_LDO7_ON_MODE
);
522 static int wm831x_aldo_get_status(struct regulator_dev
*rdev
)
524 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
525 struct wm831x
*wm831x
= ldo
->wm831x
;
526 int mask
= 1 << rdev_get_id(rdev
);
529 /* Is the regulator on? */
530 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
534 return REGULATOR_STATUS_OFF
;
536 /* Is it reporting under voltage? */
537 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
539 return REGULATOR_STATUS_ERROR
;
541 ret
= wm831x_aldo_get_mode(rdev
);
545 return regulator_mode_to_status(ret
);
548 static struct regulator_ops wm831x_aldo_ops
= {
549 .list_voltage
= wm831x_aldo_list_voltage
,
550 .get_voltage
= wm831x_aldo_get_voltage
,
551 .set_voltage
= wm831x_aldo_set_voltage
,
552 .set_suspend_voltage
= wm831x_aldo_set_suspend_voltage
,
553 .get_mode
= wm831x_aldo_get_mode
,
554 .set_mode
= wm831x_aldo_set_mode
,
555 .get_status
= wm831x_aldo_get_status
,
557 .is_enabled
= wm831x_ldo_is_enabled
,
558 .enable
= wm831x_ldo_enable
,
559 .disable
= wm831x_ldo_disable
,
562 static __devinit
int wm831x_aldo_probe(struct platform_device
*pdev
)
564 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
565 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
566 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
567 struct wm831x_ldo
*ldo
;
568 struct resource
*res
;
571 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
573 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
576 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
578 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
582 ldo
->wm831x
= wm831x
;
584 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
586 dev_err(&pdev
->dev
, "No I/O resource\n");
590 ldo
->base
= res
->start
;
592 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
593 ldo
->desc
.name
= ldo
->name
;
595 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
596 ldo
->desc
.n_voltages
= WM831X_ALDO_MAX_SELECTOR
+ 1;
597 ldo
->desc
.ops
= &wm831x_aldo_ops
;
598 ldo
->desc
.owner
= THIS_MODULE
;
600 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
601 pdata
->ldo
[id
], ldo
);
602 if (IS_ERR(ldo
->regulator
)) {
603 ret
= PTR_ERR(ldo
->regulator
);
604 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
609 irq
= platform_get_irq_byname(pdev
, "UV");
610 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
611 IRQF_TRIGGER_RISING
, ldo
->name
,
614 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
619 platform_set_drvdata(pdev
, ldo
);
624 regulator_unregister(ldo
->regulator
);
630 static __devexit
int wm831x_aldo_remove(struct platform_device
*pdev
)
632 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
633 struct wm831x
*wm831x
= ldo
->wm831x
;
635 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
636 regulator_unregister(ldo
->regulator
);
642 static struct platform_driver wm831x_aldo_driver
= {
643 .probe
= wm831x_aldo_probe
,
644 .remove
= __devexit_p(wm831x_aldo_remove
),
646 .name
= "wm831x-aldo",
647 .owner
= THIS_MODULE
,
655 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
657 static int wm831x_alive_ldo_list_voltage(struct regulator_dev
*rdev
,
658 unsigned int selector
)
660 /* 0.8-1.55V in 50mV steps */
661 if (selector
<= WM831X_ALIVE_LDO_MAX_SELECTOR
)
662 return 800000 + (selector
* 50000);
666 static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev
*rdev
,
668 int min_uV
, int max_uV
)
670 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
671 struct wm831x
*wm831x
= ldo
->wm831x
;
674 vsel
= (min_uV
- 800000) / 50000;
676 ret
= wm831x_alive_ldo_list_voltage(rdev
, vsel
);
679 if (ret
< min_uV
|| ret
> max_uV
)
682 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO11_ON_VSEL_MASK
, vsel
);
685 static int wm831x_alive_ldo_set_voltage(struct regulator_dev
*rdev
,
686 int min_uV
, int max_uV
)
688 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
689 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
691 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
694 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
697 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
698 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_SLEEP_CONTROL
;
700 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
703 static int wm831x_alive_ldo_get_voltage(struct regulator_dev
*rdev
)
705 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
706 struct wm831x
*wm831x
= ldo
->wm831x
;
707 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
710 ret
= wm831x_reg_read(wm831x
, reg
);
714 ret
&= WM831X_LDO11_ON_VSEL_MASK
;
716 return wm831x_alive_ldo_list_voltage(rdev
, ret
);
719 static int wm831x_alive_ldo_get_status(struct regulator_dev
*rdev
)
721 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
722 struct wm831x
*wm831x
= ldo
->wm831x
;
723 int mask
= 1 << rdev_get_id(rdev
);
726 /* Is the regulator on? */
727 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
731 return REGULATOR_STATUS_ON
;
733 return REGULATOR_STATUS_OFF
;
736 static struct regulator_ops wm831x_alive_ldo_ops
= {
737 .list_voltage
= wm831x_alive_ldo_list_voltage
,
738 .get_voltage
= wm831x_alive_ldo_get_voltage
,
739 .set_voltage
= wm831x_alive_ldo_set_voltage
,
740 .set_suspend_voltage
= wm831x_alive_ldo_set_suspend_voltage
,
741 .get_status
= wm831x_alive_ldo_get_status
,
743 .is_enabled
= wm831x_ldo_is_enabled
,
744 .enable
= wm831x_ldo_enable
,
745 .disable
= wm831x_ldo_disable
,
748 static __devinit
int wm831x_alive_ldo_probe(struct platform_device
*pdev
)
750 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
751 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
752 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
753 struct wm831x_ldo
*ldo
;
754 struct resource
*res
;
757 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
759 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
762 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
764 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
768 ldo
->wm831x
= wm831x
;
770 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
772 dev_err(&pdev
->dev
, "No I/O resource\n");
776 ldo
->base
= res
->start
;
778 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
779 ldo
->desc
.name
= ldo
->name
;
781 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
782 ldo
->desc
.n_voltages
= WM831X_ALIVE_LDO_MAX_SELECTOR
+ 1;
783 ldo
->desc
.ops
= &wm831x_alive_ldo_ops
;
784 ldo
->desc
.owner
= THIS_MODULE
;
786 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
787 pdata
->ldo
[id
], ldo
);
788 if (IS_ERR(ldo
->regulator
)) {
789 ret
= PTR_ERR(ldo
->regulator
);
790 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
795 platform_set_drvdata(pdev
, ldo
);
804 static __devexit
int wm831x_alive_ldo_remove(struct platform_device
*pdev
)
806 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
808 regulator_unregister(ldo
->regulator
);
814 static struct platform_driver wm831x_alive_ldo_driver
= {
815 .probe
= wm831x_alive_ldo_probe
,
816 .remove
= __devexit_p(wm831x_alive_ldo_remove
),
818 .name
= "wm831x-alive-ldo",
819 .owner
= THIS_MODULE
,
823 static int __init
wm831x_ldo_init(void)
827 ret
= platform_driver_register(&wm831x_gp_ldo_driver
);
829 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret
);
831 ret
= platform_driver_register(&wm831x_aldo_driver
);
833 pr_err("Failed to register WM831x ALDO driver: %d\n", ret
);
835 ret
= platform_driver_register(&wm831x_alive_ldo_driver
);
837 pr_err("Failed to register WM831x alive LDO driver: %d\n",
842 subsys_initcall(wm831x_ldo_init
);
844 static void __exit
wm831x_ldo_exit(void)
846 platform_driver_unregister(&wm831x_alive_ldo_driver
);
847 platform_driver_unregister(&wm831x_aldo_driver
);
848 platform_driver_unregister(&wm831x_gp_ldo_driver
);
850 module_exit(wm831x_ldo_exit
);
852 /* Module information */
853 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
854 MODULE_DESCRIPTION("WM831x LDO driver");
855 MODULE_LICENSE("GPL");
856 MODULE_ALIAS("platform:wm831x-ldo");
857 MODULE_ALIAS("platform:wm831x-aldo");
858 MODULE_ALIAS("platform:wm831x-aliveldo");