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>
23 #include <linux/mfd/wm831x/core.h>
24 #include <linux/mfd/wm831x/regulator.h>
25 #include <linux/mfd/wm831x/pdata.h>
27 #define WM831X_LDO_MAX_NAME 6
29 #define WM831X_LDO_CONTROL 0
30 #define WM831X_LDO_ON_CONTROL 1
31 #define WM831X_LDO_SLEEP_CONTROL 2
33 #define WM831X_ALIVE_LDO_ON_CONTROL 0
34 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
37 char name
[WM831X_LDO_MAX_NAME
];
38 struct regulator_desc desc
;
40 struct wm831x
*wm831x
;
41 struct regulator_dev
*regulator
;
48 static int wm831x_ldo_is_enabled(struct regulator_dev
*rdev
)
50 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
51 struct wm831x
*wm831x
= ldo
->wm831x
;
52 int mask
= 1 << rdev_get_id(rdev
);
55 reg
= wm831x_reg_read(wm831x
, WM831X_LDO_ENABLE
);
65 static int wm831x_ldo_enable(struct regulator_dev
*rdev
)
67 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
68 struct wm831x
*wm831x
= ldo
->wm831x
;
69 int mask
= 1 << rdev_get_id(rdev
);
71 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, mask
);
74 static int wm831x_ldo_disable(struct regulator_dev
*rdev
)
76 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
77 struct wm831x
*wm831x
= ldo
->wm831x
;
78 int mask
= 1 << rdev_get_id(rdev
);
80 return wm831x_set_bits(wm831x
, WM831X_LDO_ENABLE
, mask
, 0);
83 static irqreturn_t
wm831x_ldo_uv_irq(int irq
, void *data
)
85 struct wm831x_ldo
*ldo
= data
;
87 regulator_notifier_call_chain(ldo
->regulator
,
88 REGULATOR_EVENT_UNDER_VOLTAGE
,
95 * General purpose LDOs
98 #define WM831X_GP_LDO_SELECTOR_LOW 0xe
99 #define WM831X_GP_LDO_MAX_SELECTOR 0x1f
101 static int wm831x_gp_ldo_list_voltage(struct regulator_dev
*rdev
,
102 unsigned int selector
)
104 /* 0.9-1.6V in 50mV steps */
105 if (selector
<= WM831X_GP_LDO_SELECTOR_LOW
)
106 return 900000 + (selector
* 50000);
107 /* 1.7-3.3V in 50mV steps */
108 if (selector
<= WM831X_GP_LDO_MAX_SELECTOR
)
109 return 1600000 + ((selector
- WM831X_GP_LDO_SELECTOR_LOW
)
114 static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
115 int min_uV
, int max_uV
)
117 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
118 struct wm831x
*wm831x
= ldo
->wm831x
;
123 else if (min_uV
< 1700000)
124 vsel
= ((min_uV
- 900000) / 50000);
126 vsel
= ((min_uV
- 1700000) / 100000)
127 + WM831X_GP_LDO_SELECTOR_LOW
+ 1;
129 ret
= wm831x_gp_ldo_list_voltage(rdev
, vsel
);
132 if (ret
< min_uV
|| ret
> max_uV
)
135 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO1_ON_VSEL_MASK
, vsel
);
138 static int wm831x_gp_ldo_set_voltage(struct regulator_dev
*rdev
,
139 int min_uV
, int max_uV
)
141 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
142 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
144 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
147 static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
150 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
151 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
153 return wm831x_gp_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
156 static int wm831x_gp_ldo_get_voltage(struct regulator_dev
*rdev
)
158 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
159 struct wm831x
*wm831x
= ldo
->wm831x
;
160 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
163 ret
= wm831x_reg_read(wm831x
, reg
);
167 ret
&= WM831X_LDO1_ON_VSEL_MASK
;
169 return wm831x_gp_ldo_list_voltage(rdev
, ret
);
172 static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev
*rdev
)
174 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
175 struct wm831x
*wm831x
= ldo
->wm831x
;
176 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
177 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
180 ret
= wm831x_reg_read(wm831x
, on_reg
);
184 if (!(ret
& WM831X_LDO1_ON_MODE
))
185 return REGULATOR_MODE_NORMAL
;
187 ret
= wm831x_reg_read(wm831x
, ctrl_reg
);
191 if (ret
& WM831X_LDO1_LP_MODE
)
192 return REGULATOR_MODE_STANDBY
;
194 return REGULATOR_MODE_IDLE
;
197 static int wm831x_gp_ldo_set_mode(struct regulator_dev
*rdev
,
200 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
201 struct wm831x
*wm831x
= ldo
->wm831x
;
202 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
203 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
208 case REGULATOR_MODE_NORMAL
:
209 ret
= wm831x_set_bits(wm831x
, on_reg
,
210 WM831X_LDO1_ON_MODE
, 0);
215 case REGULATOR_MODE_IDLE
:
216 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
218 WM831X_LDO1_LP_MODE
);
222 ret
= wm831x_set_bits(wm831x
, on_reg
,
224 WM831X_LDO1_ON_MODE
);
228 case REGULATOR_MODE_STANDBY
:
229 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
230 WM831X_LDO1_LP_MODE
, 0);
234 ret
= wm831x_set_bits(wm831x
, on_reg
,
236 WM831X_LDO1_ON_MODE
);
248 static int wm831x_gp_ldo_get_status(struct regulator_dev
*rdev
)
250 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
251 struct wm831x
*wm831x
= ldo
->wm831x
;
252 int mask
= 1 << rdev_get_id(rdev
);
255 /* Is the regulator on? */
256 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
260 return REGULATOR_STATUS_OFF
;
262 /* Is it reporting under voltage? */
263 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
265 return REGULATOR_STATUS_ERROR
;
267 ret
= wm831x_gp_ldo_get_mode(rdev
);
271 return regulator_mode_to_status(ret
);
274 static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev
*rdev
,
276 int output_uV
, int load_uA
)
279 return REGULATOR_MODE_STANDBY
;
281 return REGULATOR_MODE_IDLE
;
282 return REGULATOR_MODE_NORMAL
;
286 static struct regulator_ops wm831x_gp_ldo_ops
= {
287 .list_voltage
= wm831x_gp_ldo_list_voltage
,
288 .get_voltage
= wm831x_gp_ldo_get_voltage
,
289 .set_voltage
= wm831x_gp_ldo_set_voltage
,
290 .set_suspend_voltage
= wm831x_gp_ldo_set_suspend_voltage
,
291 .get_mode
= wm831x_gp_ldo_get_mode
,
292 .set_mode
= wm831x_gp_ldo_set_mode
,
293 .get_status
= wm831x_gp_ldo_get_status
,
294 .get_optimum_mode
= wm831x_gp_ldo_get_optimum_mode
,
296 .is_enabled
= wm831x_ldo_is_enabled
,
297 .enable
= wm831x_ldo_enable
,
298 .disable
= wm831x_ldo_disable
,
301 static __devinit
int wm831x_gp_ldo_probe(struct platform_device
*pdev
)
303 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
304 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
305 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
306 struct wm831x_ldo
*ldo
;
307 struct resource
*res
;
310 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
312 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
315 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
317 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
321 ldo
->wm831x
= wm831x
;
323 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
325 dev_err(&pdev
->dev
, "No I/O resource\n");
329 ldo
->base
= res
->start
;
331 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
332 ldo
->desc
.name
= ldo
->name
;
334 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
335 ldo
->desc
.n_voltages
= WM831X_GP_LDO_MAX_SELECTOR
+ 1;
336 ldo
->desc
.ops
= &wm831x_gp_ldo_ops
;
337 ldo
->desc
.owner
= THIS_MODULE
;
339 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
340 pdata
->ldo
[id
], ldo
);
341 if (IS_ERR(ldo
->regulator
)) {
342 ret
= PTR_ERR(ldo
->regulator
);
343 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
348 irq
= platform_get_irq_byname(pdev
, "UV");
349 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
350 IRQF_TRIGGER_RISING
, ldo
->name
,
353 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
358 platform_set_drvdata(pdev
, ldo
);
363 regulator_unregister(ldo
->regulator
);
369 static __devexit
int wm831x_gp_ldo_remove(struct platform_device
*pdev
)
371 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
372 struct wm831x
*wm831x
= ldo
->wm831x
;
374 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
375 regulator_unregister(ldo
->regulator
);
381 static struct platform_driver wm831x_gp_ldo_driver
= {
382 .probe
= wm831x_gp_ldo_probe
,
383 .remove
= __devexit_p(wm831x_gp_ldo_remove
),
385 .name
= "wm831x-ldo",
394 #define WM831X_ALDO_SELECTOR_LOW 0xc
395 #define WM831X_ALDO_MAX_SELECTOR 0x1f
397 static int wm831x_aldo_list_voltage(struct regulator_dev
*rdev
,
398 unsigned int selector
)
400 /* 1-1.6V in 50mV steps */
401 if (selector
<= WM831X_ALDO_SELECTOR_LOW
)
402 return 1000000 + (selector
* 50000);
403 /* 1.7-3.5V in 50mV steps */
404 if (selector
<= WM831X_ALDO_MAX_SELECTOR
)
405 return 1600000 + ((selector
- WM831X_ALDO_SELECTOR_LOW
)
410 static int wm831x_aldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
411 int min_uV
, int max_uV
)
413 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
414 struct wm831x
*wm831x
= ldo
->wm831x
;
417 if (min_uV
< 1000000)
419 else if (min_uV
< 1700000)
420 vsel
= ((min_uV
- 1000000) / 50000);
422 vsel
= ((min_uV
- 1700000) / 100000)
423 + WM831X_ALDO_SELECTOR_LOW
+ 1;
425 ret
= wm831x_aldo_list_voltage(rdev
, vsel
);
428 if (ret
< min_uV
|| ret
> max_uV
)
431 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO7_ON_VSEL_MASK
, vsel
);
434 static int wm831x_aldo_set_voltage(struct regulator_dev
*rdev
,
435 int min_uV
, int max_uV
)
437 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
438 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
440 return wm831x_aldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
443 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev
*rdev
,
446 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
447 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
449 return wm831x_aldo_set_voltage_int(rdev
, reg
, uV
, uV
);
452 static int wm831x_aldo_get_voltage(struct regulator_dev
*rdev
)
454 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
455 struct wm831x
*wm831x
= ldo
->wm831x
;
456 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
459 ret
= wm831x_reg_read(wm831x
, reg
);
463 ret
&= WM831X_LDO7_ON_VSEL_MASK
;
465 return wm831x_aldo_list_voltage(rdev
, ret
);
468 static unsigned int wm831x_aldo_get_mode(struct regulator_dev
*rdev
)
470 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
471 struct wm831x
*wm831x
= ldo
->wm831x
;
472 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
475 ret
= wm831x_reg_read(wm831x
, on_reg
);
479 if (ret
& WM831X_LDO7_ON_MODE
)
480 return REGULATOR_MODE_IDLE
;
482 return REGULATOR_MODE_NORMAL
;
485 static int wm831x_aldo_set_mode(struct regulator_dev
*rdev
,
488 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
489 struct wm831x
*wm831x
= ldo
->wm831x
;
490 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
491 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
496 case REGULATOR_MODE_NORMAL
:
497 ret
= wm831x_set_bits(wm831x
, on_reg
,
498 WM831X_LDO7_ON_MODE
, 0);
503 case REGULATOR_MODE_IDLE
:
504 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
506 WM831X_LDO7_ON_MODE
);
518 static int wm831x_aldo_get_status(struct regulator_dev
*rdev
)
520 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
521 struct wm831x
*wm831x
= ldo
->wm831x
;
522 int mask
= 1 << rdev_get_id(rdev
);
525 /* Is the regulator on? */
526 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
530 return REGULATOR_STATUS_OFF
;
532 /* Is it reporting under voltage? */
533 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
535 return REGULATOR_STATUS_ERROR
;
537 ret
= wm831x_aldo_get_mode(rdev
);
541 return regulator_mode_to_status(ret
);
544 static struct regulator_ops wm831x_aldo_ops
= {
545 .list_voltage
= wm831x_aldo_list_voltage
,
546 .get_voltage
= wm831x_aldo_get_voltage
,
547 .set_voltage
= wm831x_aldo_set_voltage
,
548 .set_suspend_voltage
= wm831x_aldo_set_suspend_voltage
,
549 .get_mode
= wm831x_aldo_get_mode
,
550 .set_mode
= wm831x_aldo_set_mode
,
551 .get_status
= wm831x_aldo_get_status
,
553 .is_enabled
= wm831x_ldo_is_enabled
,
554 .enable
= wm831x_ldo_enable
,
555 .disable
= wm831x_ldo_disable
,
558 static __devinit
int wm831x_aldo_probe(struct platform_device
*pdev
)
560 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
561 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
562 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
563 struct wm831x_ldo
*ldo
;
564 struct resource
*res
;
567 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
569 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
572 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
574 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
578 ldo
->wm831x
= wm831x
;
580 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
582 dev_err(&pdev
->dev
, "No I/O resource\n");
586 ldo
->base
= res
->start
;
588 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
589 ldo
->desc
.name
= ldo
->name
;
591 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
592 ldo
->desc
.n_voltages
= WM831X_ALDO_MAX_SELECTOR
+ 1;
593 ldo
->desc
.ops
= &wm831x_aldo_ops
;
594 ldo
->desc
.owner
= THIS_MODULE
;
596 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
597 pdata
->ldo
[id
], ldo
);
598 if (IS_ERR(ldo
->regulator
)) {
599 ret
= PTR_ERR(ldo
->regulator
);
600 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
605 irq
= platform_get_irq_byname(pdev
, "UV");
606 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
607 IRQF_TRIGGER_RISING
, ldo
->name
,
610 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
615 platform_set_drvdata(pdev
, ldo
);
620 regulator_unregister(ldo
->regulator
);
626 static __devexit
int wm831x_aldo_remove(struct platform_device
*pdev
)
628 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
629 struct wm831x
*wm831x
= ldo
->wm831x
;
631 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
632 regulator_unregister(ldo
->regulator
);
638 static struct platform_driver wm831x_aldo_driver
= {
639 .probe
= wm831x_aldo_probe
,
640 .remove
= __devexit_p(wm831x_aldo_remove
),
642 .name
= "wm831x-aldo",
650 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
652 static int wm831x_alive_ldo_list_voltage(struct regulator_dev
*rdev
,
653 unsigned int selector
)
655 /* 0.8-1.55V in 50mV steps */
656 if (selector
<= WM831X_ALIVE_LDO_MAX_SELECTOR
)
657 return 800000 + (selector
* 50000);
661 static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev
*rdev
,
663 int min_uV
, int max_uV
)
665 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
666 struct wm831x
*wm831x
= ldo
->wm831x
;
669 vsel
= (min_uV
- 800000) / 50000;
671 ret
= wm831x_alive_ldo_list_voltage(rdev
, vsel
);
674 if (ret
< min_uV
|| ret
> max_uV
)
677 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO11_ON_VSEL_MASK
, vsel
);
680 static int wm831x_alive_ldo_set_voltage(struct regulator_dev
*rdev
,
681 int min_uV
, int max_uV
)
683 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
684 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
686 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
689 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
692 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
693 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_SLEEP_CONTROL
;
695 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
698 static int wm831x_alive_ldo_get_voltage(struct regulator_dev
*rdev
)
700 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
701 struct wm831x
*wm831x
= ldo
->wm831x
;
702 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
705 ret
= wm831x_reg_read(wm831x
, reg
);
709 ret
&= WM831X_LDO11_ON_VSEL_MASK
;
711 return wm831x_alive_ldo_list_voltage(rdev
, ret
);
714 static int wm831x_alive_ldo_get_status(struct regulator_dev
*rdev
)
716 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
717 struct wm831x
*wm831x
= ldo
->wm831x
;
718 int mask
= 1 << rdev_get_id(rdev
);
721 /* Is the regulator on? */
722 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
726 return REGULATOR_STATUS_ON
;
728 return REGULATOR_STATUS_OFF
;
731 static struct regulator_ops wm831x_alive_ldo_ops
= {
732 .list_voltage
= wm831x_alive_ldo_list_voltage
,
733 .get_voltage
= wm831x_alive_ldo_get_voltage
,
734 .set_voltage
= wm831x_alive_ldo_set_voltage
,
735 .set_suspend_voltage
= wm831x_alive_ldo_set_suspend_voltage
,
736 .get_status
= wm831x_alive_ldo_get_status
,
738 .is_enabled
= wm831x_ldo_is_enabled
,
739 .enable
= wm831x_ldo_enable
,
740 .disable
= wm831x_ldo_disable
,
743 static __devinit
int wm831x_alive_ldo_probe(struct platform_device
*pdev
)
745 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
746 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
747 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
748 struct wm831x_ldo
*ldo
;
749 struct resource
*res
;
752 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
754 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
757 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
759 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
763 ldo
->wm831x
= wm831x
;
765 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
767 dev_err(&pdev
->dev
, "No I/O resource\n");
771 ldo
->base
= res
->start
;
773 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
774 ldo
->desc
.name
= ldo
->name
;
776 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
777 ldo
->desc
.n_voltages
= WM831X_ALIVE_LDO_MAX_SELECTOR
+ 1;
778 ldo
->desc
.ops
= &wm831x_alive_ldo_ops
;
779 ldo
->desc
.owner
= THIS_MODULE
;
781 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
782 pdata
->ldo
[id
], ldo
);
783 if (IS_ERR(ldo
->regulator
)) {
784 ret
= PTR_ERR(ldo
->regulator
);
785 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
790 platform_set_drvdata(pdev
, ldo
);
799 static __devexit
int wm831x_alive_ldo_remove(struct platform_device
*pdev
)
801 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
803 regulator_unregister(ldo
->regulator
);
809 static struct platform_driver wm831x_alive_ldo_driver
= {
810 .probe
= wm831x_alive_ldo_probe
,
811 .remove
= __devexit_p(wm831x_alive_ldo_remove
),
813 .name
= "wm831x-alive-ldo",
817 static int __init
wm831x_ldo_init(void)
821 ret
= platform_driver_register(&wm831x_gp_ldo_driver
);
823 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret
);
825 ret
= platform_driver_register(&wm831x_aldo_driver
);
827 pr_err("Failed to register WM831x ALDO driver: %d\n", ret
);
829 ret
= platform_driver_register(&wm831x_alive_ldo_driver
);
831 pr_err("Failed to register WM831x alive LDO driver: %d\n",
836 subsys_initcall(wm831x_ldo_init
);
838 static void __exit
wm831x_ldo_exit(void)
840 platform_driver_unregister(&wm831x_alive_ldo_driver
);
841 platform_driver_unregister(&wm831x_aldo_driver
);
842 platform_driver_unregister(&wm831x_gp_ldo_driver
);
844 module_exit(wm831x_ldo_exit
);
846 /* Module information */
847 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
848 MODULE_DESCRIPTION("WM831x LDO driver");
849 MODULE_LICENSE("GPL");
850 MODULE_ALIAS("platform:wm831x-ldo");
851 MODULE_ALIAS("platform:wm831x-aldo");
852 MODULE_ALIAS("platform:wm831x-aliveldo");