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 platform_set_drvdata(pdev
, NULL
);
376 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
377 regulator_unregister(ldo
->regulator
);
383 static struct platform_driver wm831x_gp_ldo_driver
= {
384 .probe
= wm831x_gp_ldo_probe
,
385 .remove
= __devexit_p(wm831x_gp_ldo_remove
),
387 .name
= "wm831x-ldo",
388 .owner
= THIS_MODULE
,
397 #define WM831X_ALDO_SELECTOR_LOW 0xc
398 #define WM831X_ALDO_MAX_SELECTOR 0x1f
400 static int wm831x_aldo_list_voltage(struct regulator_dev
*rdev
,
401 unsigned int selector
)
403 /* 1-1.6V in 50mV steps */
404 if (selector
<= WM831X_ALDO_SELECTOR_LOW
)
405 return 1000000 + (selector
* 50000);
406 /* 1.7-3.5V in 50mV steps */
407 if (selector
<= WM831X_ALDO_MAX_SELECTOR
)
408 return 1600000 + ((selector
- WM831X_ALDO_SELECTOR_LOW
)
413 static int wm831x_aldo_set_voltage_int(struct regulator_dev
*rdev
, int reg
,
414 int min_uV
, int max_uV
)
416 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
417 struct wm831x
*wm831x
= ldo
->wm831x
;
420 if (min_uV
< 1000000)
422 else if (min_uV
< 1700000)
423 vsel
= ((min_uV
- 1000000) / 50000);
425 vsel
= ((min_uV
- 1700000) / 100000)
426 + WM831X_ALDO_SELECTOR_LOW
+ 1;
428 ret
= wm831x_aldo_list_voltage(rdev
, vsel
);
431 if (ret
< min_uV
|| ret
> max_uV
)
434 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO7_ON_VSEL_MASK
, vsel
);
437 static int wm831x_aldo_set_voltage(struct regulator_dev
*rdev
,
438 int min_uV
, int max_uV
)
440 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
441 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
443 return wm831x_aldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
446 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev
*rdev
,
449 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
450 int reg
= ldo
->base
+ WM831X_LDO_SLEEP_CONTROL
;
452 return wm831x_aldo_set_voltage_int(rdev
, reg
, uV
, uV
);
455 static int wm831x_aldo_get_voltage(struct regulator_dev
*rdev
)
457 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
458 struct wm831x
*wm831x
= ldo
->wm831x
;
459 int reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
462 ret
= wm831x_reg_read(wm831x
, reg
);
466 ret
&= WM831X_LDO7_ON_VSEL_MASK
;
468 return wm831x_aldo_list_voltage(rdev
, ret
);
471 static unsigned int wm831x_aldo_get_mode(struct regulator_dev
*rdev
)
473 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
474 struct wm831x
*wm831x
= ldo
->wm831x
;
475 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
478 ret
= wm831x_reg_read(wm831x
, on_reg
);
482 if (ret
& WM831X_LDO7_ON_MODE
)
483 return REGULATOR_MODE_IDLE
;
485 return REGULATOR_MODE_NORMAL
;
488 static int wm831x_aldo_set_mode(struct regulator_dev
*rdev
,
491 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
492 struct wm831x
*wm831x
= ldo
->wm831x
;
493 int ctrl_reg
= ldo
->base
+ WM831X_LDO_CONTROL
;
494 int on_reg
= ldo
->base
+ WM831X_LDO_ON_CONTROL
;
499 case REGULATOR_MODE_NORMAL
:
500 ret
= wm831x_set_bits(wm831x
, on_reg
,
501 WM831X_LDO7_ON_MODE
, 0);
506 case REGULATOR_MODE_IDLE
:
507 ret
= wm831x_set_bits(wm831x
, ctrl_reg
,
509 WM831X_LDO7_ON_MODE
);
521 static int wm831x_aldo_get_status(struct regulator_dev
*rdev
)
523 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
524 struct wm831x
*wm831x
= ldo
->wm831x
;
525 int mask
= 1 << rdev_get_id(rdev
);
528 /* Is the regulator on? */
529 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
533 return REGULATOR_STATUS_OFF
;
535 /* Is it reporting under voltage? */
536 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_UV_STATUS
);
538 return REGULATOR_STATUS_ERROR
;
540 ret
= wm831x_aldo_get_mode(rdev
);
544 return regulator_mode_to_status(ret
);
547 static struct regulator_ops wm831x_aldo_ops
= {
548 .list_voltage
= wm831x_aldo_list_voltage
,
549 .get_voltage
= wm831x_aldo_get_voltage
,
550 .set_voltage
= wm831x_aldo_set_voltage
,
551 .set_suspend_voltage
= wm831x_aldo_set_suspend_voltage
,
552 .get_mode
= wm831x_aldo_get_mode
,
553 .set_mode
= wm831x_aldo_set_mode
,
554 .get_status
= wm831x_aldo_get_status
,
556 .is_enabled
= wm831x_ldo_is_enabled
,
557 .enable
= wm831x_ldo_enable
,
558 .disable
= wm831x_ldo_disable
,
561 static __devinit
int wm831x_aldo_probe(struct platform_device
*pdev
)
563 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
564 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
565 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
566 struct wm831x_ldo
*ldo
;
567 struct resource
*res
;
570 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
572 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
575 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
577 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
581 ldo
->wm831x
= wm831x
;
583 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
585 dev_err(&pdev
->dev
, "No I/O resource\n");
589 ldo
->base
= res
->start
;
591 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
592 ldo
->desc
.name
= ldo
->name
;
594 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
595 ldo
->desc
.n_voltages
= WM831X_ALDO_MAX_SELECTOR
+ 1;
596 ldo
->desc
.ops
= &wm831x_aldo_ops
;
597 ldo
->desc
.owner
= THIS_MODULE
;
599 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
600 pdata
->ldo
[id
], ldo
);
601 if (IS_ERR(ldo
->regulator
)) {
602 ret
= PTR_ERR(ldo
->regulator
);
603 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
608 irq
= platform_get_irq_byname(pdev
, "UV");
609 ret
= wm831x_request_irq(wm831x
, irq
, wm831x_ldo_uv_irq
,
610 IRQF_TRIGGER_RISING
, ldo
->name
,
613 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
618 platform_set_drvdata(pdev
, ldo
);
623 regulator_unregister(ldo
->regulator
);
629 static __devexit
int wm831x_aldo_remove(struct platform_device
*pdev
)
631 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
632 struct wm831x
*wm831x
= ldo
->wm831x
;
634 wm831x_free_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"), ldo
);
635 regulator_unregister(ldo
->regulator
);
641 static struct platform_driver wm831x_aldo_driver
= {
642 .probe
= wm831x_aldo_probe
,
643 .remove
= __devexit_p(wm831x_aldo_remove
),
645 .name
= "wm831x-aldo",
646 .owner
= THIS_MODULE
,
654 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
656 static int wm831x_alive_ldo_list_voltage(struct regulator_dev
*rdev
,
657 unsigned int selector
)
659 /* 0.8-1.55V in 50mV steps */
660 if (selector
<= WM831X_ALIVE_LDO_MAX_SELECTOR
)
661 return 800000 + (selector
* 50000);
665 static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev
*rdev
,
667 int min_uV
, int max_uV
)
669 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
670 struct wm831x
*wm831x
= ldo
->wm831x
;
673 vsel
= (min_uV
- 800000) / 50000;
675 ret
= wm831x_alive_ldo_list_voltage(rdev
, vsel
);
678 if (ret
< min_uV
|| ret
> max_uV
)
681 return wm831x_set_bits(wm831x
, reg
, WM831X_LDO11_ON_VSEL_MASK
, vsel
);
684 static int wm831x_alive_ldo_set_voltage(struct regulator_dev
*rdev
,
685 int min_uV
, int max_uV
)
687 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
688 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
690 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, min_uV
, max_uV
);
693 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev
*rdev
,
696 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
697 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_SLEEP_CONTROL
;
699 return wm831x_alive_ldo_set_voltage_int(rdev
, reg
, uV
, uV
);
702 static int wm831x_alive_ldo_get_voltage(struct regulator_dev
*rdev
)
704 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
705 struct wm831x
*wm831x
= ldo
->wm831x
;
706 int reg
= ldo
->base
+ WM831X_ALIVE_LDO_ON_CONTROL
;
709 ret
= wm831x_reg_read(wm831x
, reg
);
713 ret
&= WM831X_LDO11_ON_VSEL_MASK
;
715 return wm831x_alive_ldo_list_voltage(rdev
, ret
);
718 static int wm831x_alive_ldo_get_status(struct regulator_dev
*rdev
)
720 struct wm831x_ldo
*ldo
= rdev_get_drvdata(rdev
);
721 struct wm831x
*wm831x
= ldo
->wm831x
;
722 int mask
= 1 << rdev_get_id(rdev
);
725 /* Is the regulator on? */
726 ret
= wm831x_reg_read(wm831x
, WM831X_LDO_STATUS
);
730 return REGULATOR_STATUS_ON
;
732 return REGULATOR_STATUS_OFF
;
735 static struct regulator_ops wm831x_alive_ldo_ops
= {
736 .list_voltage
= wm831x_alive_ldo_list_voltage
,
737 .get_voltage
= wm831x_alive_ldo_get_voltage
,
738 .set_voltage
= wm831x_alive_ldo_set_voltage
,
739 .set_suspend_voltage
= wm831x_alive_ldo_set_suspend_voltage
,
740 .get_status
= wm831x_alive_ldo_get_status
,
742 .is_enabled
= wm831x_ldo_is_enabled
,
743 .enable
= wm831x_ldo_enable
,
744 .disable
= wm831x_ldo_disable
,
747 static __devinit
int wm831x_alive_ldo_probe(struct platform_device
*pdev
)
749 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
750 struct wm831x_pdata
*pdata
= wm831x
->dev
->platform_data
;
751 int id
= pdev
->id
% ARRAY_SIZE(pdata
->ldo
);
752 struct wm831x_ldo
*ldo
;
753 struct resource
*res
;
756 dev_dbg(&pdev
->dev
, "Probing LDO%d\n", id
+ 1);
758 if (pdata
== NULL
|| pdata
->ldo
[id
] == NULL
)
761 ldo
= kzalloc(sizeof(struct wm831x_ldo
), GFP_KERNEL
);
763 dev_err(&pdev
->dev
, "Unable to allocate private data\n");
767 ldo
->wm831x
= wm831x
;
769 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
771 dev_err(&pdev
->dev
, "No I/O resource\n");
775 ldo
->base
= res
->start
;
777 snprintf(ldo
->name
, sizeof(ldo
->name
), "LDO%d", id
+ 1);
778 ldo
->desc
.name
= ldo
->name
;
780 ldo
->desc
.type
= REGULATOR_VOLTAGE
;
781 ldo
->desc
.n_voltages
= WM831X_ALIVE_LDO_MAX_SELECTOR
+ 1;
782 ldo
->desc
.ops
= &wm831x_alive_ldo_ops
;
783 ldo
->desc
.owner
= THIS_MODULE
;
785 ldo
->regulator
= regulator_register(&ldo
->desc
, &pdev
->dev
,
786 pdata
->ldo
[id
], ldo
);
787 if (IS_ERR(ldo
->regulator
)) {
788 ret
= PTR_ERR(ldo
->regulator
);
789 dev_err(wm831x
->dev
, "Failed to register LDO%d: %d\n",
794 platform_set_drvdata(pdev
, ldo
);
803 static __devexit
int wm831x_alive_ldo_remove(struct platform_device
*pdev
)
805 struct wm831x_ldo
*ldo
= platform_get_drvdata(pdev
);
807 regulator_unregister(ldo
->regulator
);
813 static struct platform_driver wm831x_alive_ldo_driver
= {
814 .probe
= wm831x_alive_ldo_probe
,
815 .remove
= __devexit_p(wm831x_alive_ldo_remove
),
817 .name
= "wm831x-alive-ldo",
818 .owner
= THIS_MODULE
,
822 static int __init
wm831x_ldo_init(void)
826 ret
= platform_driver_register(&wm831x_gp_ldo_driver
);
828 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret
);
830 ret
= platform_driver_register(&wm831x_aldo_driver
);
832 pr_err("Failed to register WM831x ALDO driver: %d\n", ret
);
834 ret
= platform_driver_register(&wm831x_alive_ldo_driver
);
836 pr_err("Failed to register WM831x alive LDO driver: %d\n",
841 subsys_initcall(wm831x_ldo_init
);
843 static void __exit
wm831x_ldo_exit(void)
845 platform_driver_unregister(&wm831x_alive_ldo_driver
);
846 platform_driver_unregister(&wm831x_aldo_driver
);
847 platform_driver_unregister(&wm831x_gp_ldo_driver
);
849 module_exit(wm831x_ldo_exit
);
851 /* Module information */
852 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
853 MODULE_DESCRIPTION("WM831x LDO driver");
854 MODULE_LICENSE("GPL");
855 MODULE_ALIAS("platform:wm831x-ldo");
856 MODULE_ALIAS("platform:wm831x-aldo");
857 MODULE_ALIAS("platform:wm831x-aliveldo");