2 * wm831x-dcdc.c -- DC-DC buck convertor 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/regulator/machine.h>
23 #include <linux/gpio.h>
24 #include <linux/slab.h>
26 #include <linux/mfd/wm831x/core.h>
27 #include <linux/mfd/wm831x/regulator.h>
28 #include <linux/mfd/wm831x/pdata.h>
30 #define WM831X_BUCKV_MAX_SELECTOR 0x68
31 #define WM831X_BUCKP_MAX_SELECTOR 0x66
33 #define WM831X_DCDC_MODE_FAST 0
34 #define WM831X_DCDC_MODE_NORMAL 1
35 #define WM831X_DCDC_MODE_IDLE 2
36 #define WM831X_DCDC_MODE_STANDBY 3
38 #define WM831X_DCDC_MAX_NAME 9
40 /* Register offsets in control block */
41 #define WM831X_DCDC_CONTROL_1 0
42 #define WM831X_DCDC_CONTROL_2 1
43 #define WM831X_DCDC_ON_CONFIG 2
44 #define WM831X_DCDC_SLEEP_CONTROL 3
45 #define WM831X_DCDC_DVS_CONTROL 4
52 char name
[WM831X_DCDC_MAX_NAME
];
53 char supply_name
[WM831X_DCDC_MAX_NAME
];
54 struct regulator_desc desc
;
56 struct wm831x
*wm831x
;
57 struct regulator_dev
*regulator
;
64 static unsigned int wm831x_dcdc_get_mode(struct regulator_dev
*rdev
)
67 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
68 struct wm831x
*wm831x
= dcdc
->wm831x
;
69 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
72 val
= wm831x_reg_read(wm831x
, reg
);
76 val
= (val
& WM831X_DC1_ON_MODE_MASK
) >> WM831X_DC1_ON_MODE_SHIFT
;
79 case WM831X_DCDC_MODE_FAST
:
80 return REGULATOR_MODE_FAST
;
81 case WM831X_DCDC_MODE_NORMAL
:
82 return REGULATOR_MODE_NORMAL
;
83 case WM831X_DCDC_MODE_STANDBY
:
84 return REGULATOR_MODE_STANDBY
;
85 case WM831X_DCDC_MODE_IDLE
:
86 return REGULATOR_MODE_IDLE
;
93 static int wm831x_dcdc_set_mode_int(struct wm831x
*wm831x
, int reg
,
99 case REGULATOR_MODE_FAST
:
100 val
= WM831X_DCDC_MODE_FAST
;
102 case REGULATOR_MODE_NORMAL
:
103 val
= WM831X_DCDC_MODE_NORMAL
;
105 case REGULATOR_MODE_STANDBY
:
106 val
= WM831X_DCDC_MODE_STANDBY
;
108 case REGULATOR_MODE_IDLE
:
109 val
= WM831X_DCDC_MODE_IDLE
;
115 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_ON_MODE_MASK
,
116 val
<< WM831X_DC1_ON_MODE_SHIFT
);
119 static int wm831x_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
121 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
122 struct wm831x
*wm831x
= dcdc
->wm831x
;
123 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
125 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
128 static int wm831x_dcdc_set_suspend_mode(struct regulator_dev
*rdev
,
131 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
132 struct wm831x
*wm831x
= dcdc
->wm831x
;
133 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
135 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
138 static int wm831x_dcdc_get_status(struct regulator_dev
*rdev
)
140 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
141 struct wm831x
*wm831x
= dcdc
->wm831x
;
144 /* First, check for errors */
145 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
149 if (ret
& (1 << rdev_get_id(rdev
))) {
150 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
151 rdev_get_id(rdev
) + 1);
152 return REGULATOR_STATUS_ERROR
;
155 /* DCDC1 and DCDC2 can additionally detect high voltage/current */
156 if (rdev_get_id(rdev
) < 2) {
157 if (ret
& (WM831X_DC1_OV_STS
<< rdev_get_id(rdev
))) {
158 dev_dbg(wm831x
->dev
, "DCDC%d over voltage\n",
159 rdev_get_id(rdev
) + 1);
160 return REGULATOR_STATUS_ERROR
;
163 if (ret
& (WM831X_DC1_HC_STS
<< rdev_get_id(rdev
))) {
164 dev_dbg(wm831x
->dev
, "DCDC%d over current\n",
165 rdev_get_id(rdev
) + 1);
166 return REGULATOR_STATUS_ERROR
;
170 /* Is the regulator on? */
171 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
174 if (!(ret
& (1 << rdev_get_id(rdev
))))
175 return REGULATOR_STATUS_OFF
;
177 /* TODO: When we handle hardware control modes so we can report the
179 return REGULATOR_STATUS_ON
;
182 static irqreturn_t
wm831x_dcdc_uv_irq(int irq
, void *data
)
184 struct wm831x_dcdc
*dcdc
= data
;
186 regulator_lock(dcdc
->regulator
);
187 regulator_notifier_call_chain(dcdc
->regulator
,
188 REGULATOR_EVENT_UNDER_VOLTAGE
,
190 regulator_unlock(dcdc
->regulator
);
195 static irqreturn_t
wm831x_dcdc_oc_irq(int irq
, void *data
)
197 struct wm831x_dcdc
*dcdc
= data
;
199 regulator_lock(dcdc
->regulator
);
200 regulator_notifier_call_chain(dcdc
->regulator
,
201 REGULATOR_EVENT_OVER_CURRENT
,
203 regulator_unlock(dcdc
->regulator
);
212 static const struct regulator_linear_range wm831x_buckv_ranges
[] = {
213 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
214 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
217 static int wm831x_buckv_set_dvs(struct regulator_dev
*rdev
, int state
)
219 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
221 if (state
== dcdc
->dvs_gpio_state
)
224 dcdc
->dvs_gpio_state
= state
;
225 gpio_set_value(dcdc
->dvs_gpio
, state
);
227 /* Should wait for DVS state change to be asserted if we have
228 * a GPIO for it, for now assume the device is configured
229 * for the fastest possible transition.
235 static int wm831x_buckv_set_voltage_sel(struct regulator_dev
*rdev
,
238 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
239 struct wm831x
*wm831x
= dcdc
->wm831x
;
240 int on_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
241 int dvs_reg
= dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
;
244 /* If this value is already set then do a GPIO update if we can */
245 if (dcdc
->dvs_gpio
&& dcdc
->on_vsel
== vsel
)
246 return wm831x_buckv_set_dvs(rdev
, 0);
248 if (dcdc
->dvs_gpio
&& dcdc
->dvs_vsel
== vsel
)
249 return wm831x_buckv_set_dvs(rdev
, 1);
251 /* Always set the ON status to the minimum voltage */
252 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_DC1_ON_VSEL_MASK
, vsel
);
255 dcdc
->on_vsel
= vsel
;
260 /* Kick the voltage transition now */
261 ret
= wm831x_buckv_set_dvs(rdev
, 0);
266 * If this VSEL is higher than the last one we've seen then
267 * remember it as the DVS VSEL. This is optimised for CPUfreq
268 * usage where we want to get to the highest voltage very
271 if (vsel
> dcdc
->dvs_vsel
) {
272 ret
= wm831x_set_bits(wm831x
, dvs_reg
,
273 WM831X_DC1_DVS_VSEL_MASK
,
276 dcdc
->dvs_vsel
= vsel
;
278 dev_warn(wm831x
->dev
,
279 "Failed to set DCDC DVS VSEL: %d\n", ret
);
285 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev
*rdev
,
288 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
289 struct wm831x
*wm831x
= dcdc
->wm831x
;
290 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
293 vsel
= regulator_map_voltage_linear_range(rdev
, uV
, uV
);
297 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_SLP_VSEL_MASK
, vsel
);
300 static int wm831x_buckv_get_voltage_sel(struct regulator_dev
*rdev
)
302 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
304 if (dcdc
->dvs_gpio
&& dcdc
->dvs_gpio_state
)
305 return dcdc
->dvs_vsel
;
307 return dcdc
->on_vsel
;
310 /* Current limit options */
311 static const unsigned int wm831x_dcdc_ilim
[] = {
312 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
315 static const struct regulator_ops wm831x_buckv_ops
= {
316 .set_voltage_sel
= wm831x_buckv_set_voltage_sel
,
317 .get_voltage_sel
= wm831x_buckv_get_voltage_sel
,
318 .list_voltage
= regulator_list_voltage_linear_range
,
319 .map_voltage
= regulator_map_voltage_linear_range
,
320 .set_suspend_voltage
= wm831x_buckv_set_suspend_voltage
,
321 .set_current_limit
= regulator_set_current_limit_regmap
,
322 .get_current_limit
= regulator_get_current_limit_regmap
,
324 .is_enabled
= regulator_is_enabled_regmap
,
325 .enable
= regulator_enable_regmap
,
326 .disable
= regulator_disable_regmap
,
327 .get_status
= wm831x_dcdc_get_status
,
328 .get_mode
= wm831x_dcdc_get_mode
,
329 .set_mode
= wm831x_dcdc_set_mode
,
330 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
334 * Set up DVS control. We just log errors since we can still run
335 * (with reduced performance) if we fail.
337 static void wm831x_buckv_dvs_init(struct platform_device
*pdev
,
338 struct wm831x_dcdc
*dcdc
,
339 struct wm831x_buckv_pdata
*pdata
)
341 struct wm831x
*wm831x
= dcdc
->wm831x
;
345 if (!pdata
|| !pdata
->dvs_gpio
)
348 /* gpiolib won't let us read the GPIO status so pick the higher
349 * of the two existing voltages so we take it as platform data.
351 dcdc
->dvs_gpio_state
= pdata
->dvs_init_state
;
353 ret
= devm_gpio_request_one(&pdev
->dev
, pdata
->dvs_gpio
,
354 dcdc
->dvs_gpio_state
? GPIOF_INIT_HIGH
: 0,
357 dev_err(wm831x
->dev
, "Failed to get %s DVS GPIO: %d\n",
362 dcdc
->dvs_gpio
= pdata
->dvs_gpio
;
364 switch (pdata
->dvs_control_src
) {
366 ctrl
= 2 << WM831X_DC1_DVS_SRC_SHIFT
;
369 ctrl
= 3 << WM831X_DC1_DVS_SRC_SHIFT
;
372 dev_err(wm831x
->dev
, "Invalid DVS control source %d for %s\n",
373 pdata
->dvs_control_src
, dcdc
->name
);
377 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
378 * to make bootstrapping a bit smoother.
380 if (!dcdc
->dvs_vsel
) {
381 ret
= wm831x_set_bits(wm831x
,
382 dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
383 WM831X_DC1_DVS_VSEL_MASK
, dcdc
->on_vsel
);
385 dcdc
->dvs_vsel
= dcdc
->on_vsel
;
387 dev_warn(wm831x
->dev
, "Failed to set DVS_VSEL: %d\n",
391 ret
= wm831x_set_bits(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
392 WM831X_DC1_DVS_SRC_MASK
, ctrl
);
394 dev_err(wm831x
->dev
, "Failed to set %s DVS source: %d\n",
399 static int wm831x_buckv_probe(struct platform_device
*pdev
)
401 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
402 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
403 struct regulator_config config
= { };
405 struct wm831x_dcdc
*dcdc
;
406 struct resource
*res
;
409 if (pdata
&& pdata
->wm831x_num
)
410 id
= (pdata
->wm831x_num
* 10) + 1;
415 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
417 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
422 dcdc
->wm831x
= wm831x
;
424 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
426 dev_err(&pdev
->dev
, "No REG resource\n");
430 dcdc
->base
= res
->start
;
432 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
433 dcdc
->desc
.name
= dcdc
->name
;
435 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
437 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
440 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
441 dcdc
->desc
.n_voltages
= WM831X_BUCKV_MAX_SELECTOR
+ 1;
442 dcdc
->desc
.linear_ranges
= wm831x_buckv_ranges
;
443 dcdc
->desc
.n_linear_ranges
= ARRAY_SIZE(wm831x_buckv_ranges
);
444 dcdc
->desc
.ops
= &wm831x_buckv_ops
;
445 dcdc
->desc
.owner
= THIS_MODULE
;
446 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
447 dcdc
->desc
.enable_mask
= 1 << id
;
448 dcdc
->desc
.csel_reg
= dcdc
->base
+ WM831X_DCDC_CONTROL_2
;
449 dcdc
->desc
.csel_mask
= WM831X_DC1_HC_THR_MASK
;
450 dcdc
->desc
.n_current_limits
= ARRAY_SIZE(wm831x_dcdc_ilim
);
451 dcdc
->desc
.curr_table
= wm831x_dcdc_ilim
;
453 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_ON_CONFIG
);
455 dev_err(wm831x
->dev
, "Failed to read ON VSEL: %d\n", ret
);
458 dcdc
->on_vsel
= ret
& WM831X_DC1_ON_VSEL_MASK
;
460 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
);
462 dev_err(wm831x
->dev
, "Failed to read DVS VSEL: %d\n", ret
);
465 dcdc
->dvs_vsel
= ret
& WM831X_DC1_DVS_VSEL_MASK
;
467 if (pdata
&& pdata
->dcdc
[id
])
468 wm831x_buckv_dvs_init(pdev
, dcdc
,
469 pdata
->dcdc
[id
]->driver_data
);
471 config
.dev
= pdev
->dev
.parent
;
473 config
.init_data
= pdata
->dcdc
[id
];
474 config
.driver_data
= dcdc
;
475 config
.regmap
= wm831x
->regmap
;
477 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
479 if (IS_ERR(dcdc
->regulator
)) {
480 ret
= PTR_ERR(dcdc
->regulator
);
481 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
486 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
487 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
489 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
492 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
497 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "HC"));
498 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
500 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
503 dev_err(&pdev
->dev
, "Failed to request HC IRQ %d: %d\n",
508 platform_set_drvdata(pdev
, dcdc
);
516 static struct platform_driver wm831x_buckv_driver
= {
517 .probe
= wm831x_buckv_probe
,
519 .name
= "wm831x-buckv",
527 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev
*rdev
, int uV
)
529 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
530 struct wm831x
*wm831x
= dcdc
->wm831x
;
531 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
534 sel
= regulator_map_voltage_linear(rdev
, uV
, uV
);
538 return wm831x_set_bits(wm831x
, reg
, WM831X_DC3_ON_VSEL_MASK
, sel
);
541 static const struct regulator_ops wm831x_buckp_ops
= {
542 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
543 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
544 .list_voltage
= regulator_list_voltage_linear
,
545 .map_voltage
= regulator_map_voltage_linear
,
546 .set_suspend_voltage
= wm831x_buckp_set_suspend_voltage
,
548 .is_enabled
= regulator_is_enabled_regmap
,
549 .enable
= regulator_enable_regmap
,
550 .disable
= regulator_disable_regmap
,
551 .get_status
= wm831x_dcdc_get_status
,
552 .get_mode
= wm831x_dcdc_get_mode
,
553 .set_mode
= wm831x_dcdc_set_mode
,
554 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
557 static int wm831x_buckp_probe(struct platform_device
*pdev
)
559 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
560 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
561 struct regulator_config config
= { };
563 struct wm831x_dcdc
*dcdc
;
564 struct resource
*res
;
567 if (pdata
&& pdata
->wm831x_num
)
568 id
= (pdata
->wm831x_num
* 10) + 1;
573 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
575 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
580 dcdc
->wm831x
= wm831x
;
582 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
584 dev_err(&pdev
->dev
, "No REG resource\n");
588 dcdc
->base
= res
->start
;
590 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
591 dcdc
->desc
.name
= dcdc
->name
;
593 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
595 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
598 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
599 dcdc
->desc
.n_voltages
= WM831X_BUCKP_MAX_SELECTOR
+ 1;
600 dcdc
->desc
.ops
= &wm831x_buckp_ops
;
601 dcdc
->desc
.owner
= THIS_MODULE
;
602 dcdc
->desc
.vsel_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
603 dcdc
->desc
.vsel_mask
= WM831X_DC3_ON_VSEL_MASK
;
604 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
605 dcdc
->desc
.enable_mask
= 1 << id
;
606 dcdc
->desc
.min_uV
= 850000;
607 dcdc
->desc
.uV_step
= 25000;
609 config
.dev
= pdev
->dev
.parent
;
611 config
.init_data
= pdata
->dcdc
[id
];
612 config
.driver_data
= dcdc
;
613 config
.regmap
= wm831x
->regmap
;
615 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
617 if (IS_ERR(dcdc
->regulator
)) {
618 ret
= PTR_ERR(dcdc
->regulator
);
619 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
624 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
625 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
627 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
630 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
635 platform_set_drvdata(pdev
, dcdc
);
643 static struct platform_driver wm831x_buckp_driver
= {
644 .probe
= wm831x_buckp_probe
,
646 .name
= "wm831x-buckp",
651 * DCDC boost convertors
654 static int wm831x_boostp_get_status(struct regulator_dev
*rdev
)
656 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
657 struct wm831x
*wm831x
= dcdc
->wm831x
;
660 /* First, check for errors */
661 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
665 if (ret
& (1 << rdev_get_id(rdev
))) {
666 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
667 rdev_get_id(rdev
) + 1);
668 return REGULATOR_STATUS_ERROR
;
671 /* Is the regulator on? */
672 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
675 if (ret
& (1 << rdev_get_id(rdev
)))
676 return REGULATOR_STATUS_ON
;
678 return REGULATOR_STATUS_OFF
;
681 static const struct regulator_ops wm831x_boostp_ops
= {
682 .get_status
= wm831x_boostp_get_status
,
684 .is_enabled
= regulator_is_enabled_regmap
,
685 .enable
= regulator_enable_regmap
,
686 .disable
= regulator_disable_regmap
,
689 static int wm831x_boostp_probe(struct platform_device
*pdev
)
691 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
692 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
693 struct regulator_config config
= { };
694 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
695 struct wm831x_dcdc
*dcdc
;
696 struct resource
*res
;
699 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
701 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
704 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
708 dcdc
->wm831x
= wm831x
;
710 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
712 dev_err(&pdev
->dev
, "No REG resource\n");
715 dcdc
->base
= res
->start
;
717 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
718 dcdc
->desc
.name
= dcdc
->name
;
720 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
721 dcdc
->desc
.ops
= &wm831x_boostp_ops
;
722 dcdc
->desc
.owner
= THIS_MODULE
;
723 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
724 dcdc
->desc
.enable_mask
= 1 << id
;
726 config
.dev
= pdev
->dev
.parent
;
728 config
.init_data
= pdata
->dcdc
[id
];
729 config
.driver_data
= dcdc
;
730 config
.regmap
= wm831x
->regmap
;
732 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
734 if (IS_ERR(dcdc
->regulator
)) {
735 ret
= PTR_ERR(dcdc
->regulator
);
736 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
741 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
742 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
744 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
748 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
753 platform_set_drvdata(pdev
, dcdc
);
758 static struct platform_driver wm831x_boostp_driver
= {
759 .probe
= wm831x_boostp_probe
,
761 .name
= "wm831x-boostp",
766 * External Power Enable
768 * These aren't actually DCDCs but look like them in hardware so share
772 #define WM831X_EPE_BASE 6
774 static const struct regulator_ops wm831x_epe_ops
= {
775 .is_enabled
= regulator_is_enabled_regmap
,
776 .enable
= regulator_enable_regmap
,
777 .disable
= regulator_disable_regmap
,
778 .get_status
= wm831x_dcdc_get_status
,
781 static int wm831x_epe_probe(struct platform_device
*pdev
)
783 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
784 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
785 struct regulator_config config
= { };
786 int id
= pdev
->id
% ARRAY_SIZE(pdata
->epe
);
787 struct wm831x_dcdc
*dcdc
;
790 dev_dbg(&pdev
->dev
, "Probing EPE%d\n", id
+ 1);
792 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
796 dcdc
->wm831x
= wm831x
;
798 /* For current parts this is correct; probably need to revisit
801 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "EPE%d", id
+ 1);
802 dcdc
->desc
.name
= dcdc
->name
;
803 dcdc
->desc
.id
= id
+ WM831X_EPE_BASE
; /* Offset in DCDC registers */
804 dcdc
->desc
.ops
= &wm831x_epe_ops
;
805 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
806 dcdc
->desc
.owner
= THIS_MODULE
;
807 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
808 dcdc
->desc
.enable_mask
= 1 << dcdc
->desc
.id
;
810 config
.dev
= pdev
->dev
.parent
;
812 config
.init_data
= pdata
->epe
[id
];
813 config
.driver_data
= dcdc
;
814 config
.regmap
= wm831x
->regmap
;
816 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
818 if (IS_ERR(dcdc
->regulator
)) {
819 ret
= PTR_ERR(dcdc
->regulator
);
820 dev_err(wm831x
->dev
, "Failed to register EPE%d: %d\n",
825 platform_set_drvdata(pdev
, dcdc
);
833 static struct platform_driver wm831x_epe_driver
= {
834 .probe
= wm831x_epe_probe
,
836 .name
= "wm831x-epe",
840 static struct platform_driver
* const drivers
[] = {
841 &wm831x_buckv_driver
,
842 &wm831x_buckp_driver
,
843 &wm831x_boostp_driver
,
847 static int __init
wm831x_dcdc_init(void)
849 return platform_register_drivers(drivers
, ARRAY_SIZE(drivers
));
851 subsys_initcall(wm831x_dcdc_init
);
853 static void __exit
wm831x_dcdc_exit(void)
855 platform_unregister_drivers(drivers
, ARRAY_SIZE(drivers
));
857 module_exit(wm831x_dcdc_exit
);
859 /* Module information */
860 MODULE_AUTHOR("Mark Brown");
861 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
862 MODULE_LICENSE("GPL");
863 MODULE_ALIAS("platform:wm831x-buckv");
864 MODULE_ALIAS("platform:wm831x-buckp");
865 MODULE_ALIAS("platform:wm831x-boostp");
866 MODULE_ALIAS("platform:wm831x-epe");