1 // SPDX-License-Identifier: GPL-2.0+
3 // wm831x-dcdc.c -- DC-DC buck converter driver for the WM831x series
5 // Copyright 2009 Wolfson Microelectronics PLC.
7 // Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
12 #include <linux/bitops.h>
13 #include <linux/err.h>
14 #include <linux/i2c.h>
15 #include <linux/platform_device.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/regulator/machine.h>
18 #include <linux/gpio/consumer.h>
19 #include <linux/slab.h>
21 #include <linux/mfd/wm831x/core.h>
22 #include <linux/mfd/wm831x/regulator.h>
23 #include <linux/mfd/wm831x/pdata.h>
25 #define WM831X_BUCKV_MAX_SELECTOR 0x68
26 #define WM831X_BUCKP_MAX_SELECTOR 0x66
28 #define WM831X_DCDC_MODE_FAST 0
29 #define WM831X_DCDC_MODE_NORMAL 1
30 #define WM831X_DCDC_MODE_IDLE 2
31 #define WM831X_DCDC_MODE_STANDBY 3
33 #define WM831X_DCDC_MAX_NAME 9
35 /* Register offsets in control block */
36 #define WM831X_DCDC_CONTROL_1 0
37 #define WM831X_DCDC_CONTROL_2 1
38 #define WM831X_DCDC_ON_CONFIG 2
39 #define WM831X_DCDC_SLEEP_CONTROL 3
40 #define WM831X_DCDC_DVS_CONTROL 4
47 char name
[WM831X_DCDC_MAX_NAME
];
48 char supply_name
[WM831X_DCDC_MAX_NAME
];
49 struct regulator_desc desc
;
51 struct wm831x
*wm831x
;
52 struct regulator_dev
*regulator
;
53 struct gpio_desc
*dvs_gpiod
;
59 static unsigned int wm831x_dcdc_get_mode(struct regulator_dev
*rdev
)
62 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
63 struct wm831x
*wm831x
= dcdc
->wm831x
;
64 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
67 val
= wm831x_reg_read(wm831x
, reg
);
71 val
= (val
& WM831X_DC1_ON_MODE_MASK
) >> WM831X_DC1_ON_MODE_SHIFT
;
74 case WM831X_DCDC_MODE_FAST
:
75 return REGULATOR_MODE_FAST
;
76 case WM831X_DCDC_MODE_NORMAL
:
77 return REGULATOR_MODE_NORMAL
;
78 case WM831X_DCDC_MODE_STANDBY
:
79 return REGULATOR_MODE_STANDBY
;
80 case WM831X_DCDC_MODE_IDLE
:
81 return REGULATOR_MODE_IDLE
;
88 static int wm831x_dcdc_set_mode_int(struct wm831x
*wm831x
, int reg
,
94 case REGULATOR_MODE_FAST
:
95 val
= WM831X_DCDC_MODE_FAST
;
97 case REGULATOR_MODE_NORMAL
:
98 val
= WM831X_DCDC_MODE_NORMAL
;
100 case REGULATOR_MODE_STANDBY
:
101 val
= WM831X_DCDC_MODE_STANDBY
;
103 case REGULATOR_MODE_IDLE
:
104 val
= WM831X_DCDC_MODE_IDLE
;
110 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_ON_MODE_MASK
,
111 val
<< WM831X_DC1_ON_MODE_SHIFT
);
114 static int wm831x_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
116 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
117 struct wm831x
*wm831x
= dcdc
->wm831x
;
118 u16 reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
120 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
123 static int wm831x_dcdc_set_suspend_mode(struct regulator_dev
*rdev
,
126 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
127 struct wm831x
*wm831x
= dcdc
->wm831x
;
128 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
130 return wm831x_dcdc_set_mode_int(wm831x
, reg
, mode
);
133 static int wm831x_dcdc_get_status(struct regulator_dev
*rdev
)
135 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
136 struct wm831x
*wm831x
= dcdc
->wm831x
;
139 /* First, check for errors */
140 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
144 if (ret
& (1 << rdev_get_id(rdev
))) {
145 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
146 rdev_get_id(rdev
) + 1);
147 return REGULATOR_STATUS_ERROR
;
150 /* DCDC1 and DCDC2 can additionally detect high voltage/current */
151 if (rdev_get_id(rdev
) < 2) {
152 if (ret
& (WM831X_DC1_OV_STS
<< rdev_get_id(rdev
))) {
153 dev_dbg(wm831x
->dev
, "DCDC%d over voltage\n",
154 rdev_get_id(rdev
) + 1);
155 return REGULATOR_STATUS_ERROR
;
158 if (ret
& (WM831X_DC1_HC_STS
<< rdev_get_id(rdev
))) {
159 dev_dbg(wm831x
->dev
, "DCDC%d over current\n",
160 rdev_get_id(rdev
) + 1);
161 return REGULATOR_STATUS_ERROR
;
165 /* Is the regulator on? */
166 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
169 if (!(ret
& (1 << rdev_get_id(rdev
))))
170 return REGULATOR_STATUS_OFF
;
172 /* TODO: When we handle hardware control modes so we can report the
174 return REGULATOR_STATUS_ON
;
177 static irqreturn_t
wm831x_dcdc_uv_irq(int irq
, void *data
)
179 struct wm831x_dcdc
*dcdc
= data
;
181 regulator_notifier_call_chain(dcdc
->regulator
,
182 REGULATOR_EVENT_UNDER_VOLTAGE
,
188 static irqreturn_t
wm831x_dcdc_oc_irq(int irq
, void *data
)
190 struct wm831x_dcdc
*dcdc
= data
;
192 regulator_notifier_call_chain(dcdc
->regulator
,
193 REGULATOR_EVENT_OVER_CURRENT
,
203 static const struct linear_range wm831x_buckv_ranges
[] = {
204 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
205 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
208 static int wm831x_buckv_set_dvs(struct regulator_dev
*rdev
, int state
)
210 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
212 if (state
== dcdc
->dvs_gpio_state
)
215 dcdc
->dvs_gpio_state
= state
;
216 gpiod_set_value(dcdc
->dvs_gpiod
, state
);
218 /* Should wait for DVS state change to be asserted if we have
219 * a GPIO for it, for now assume the device is configured
220 * for the fastest possible transition.
226 static int wm831x_buckv_set_voltage_sel(struct regulator_dev
*rdev
,
229 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
230 struct wm831x
*wm831x
= dcdc
->wm831x
;
231 int on_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
232 int dvs_reg
= dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
;
235 /* If this value is already set then do a GPIO update if we can */
236 if (dcdc
->dvs_gpiod
&& dcdc
->on_vsel
== vsel
)
237 return wm831x_buckv_set_dvs(rdev
, 0);
239 if (dcdc
->dvs_gpiod
&& dcdc
->dvs_vsel
== vsel
)
240 return wm831x_buckv_set_dvs(rdev
, 1);
242 /* Always set the ON status to the minimum voltage */
243 ret
= wm831x_set_bits(wm831x
, on_reg
, WM831X_DC1_ON_VSEL_MASK
, vsel
);
246 dcdc
->on_vsel
= vsel
;
248 if (!dcdc
->dvs_gpiod
)
251 /* Kick the voltage transition now */
252 ret
= wm831x_buckv_set_dvs(rdev
, 0);
257 * If this VSEL is higher than the last one we've seen then
258 * remember it as the DVS VSEL. This is optimised for CPUfreq
259 * usage where we want to get to the highest voltage very
262 if (vsel
> dcdc
->dvs_vsel
) {
263 ret
= wm831x_set_bits(wm831x
, dvs_reg
,
264 WM831X_DC1_DVS_VSEL_MASK
,
267 dcdc
->dvs_vsel
= vsel
;
269 dev_warn(wm831x
->dev
,
270 "Failed to set DCDC DVS VSEL: %d\n", ret
);
276 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev
*rdev
,
279 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
280 struct wm831x
*wm831x
= dcdc
->wm831x
;
281 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
284 vsel
= regulator_map_voltage_linear_range(rdev
, uV
, uV
);
288 return wm831x_set_bits(wm831x
, reg
, WM831X_DC1_SLP_VSEL_MASK
, vsel
);
291 static int wm831x_buckv_get_voltage_sel(struct regulator_dev
*rdev
)
293 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
295 if (dcdc
->dvs_gpiod
&& dcdc
->dvs_gpio_state
)
296 return dcdc
->dvs_vsel
;
298 return dcdc
->on_vsel
;
301 /* Current limit options */
302 static const unsigned int wm831x_dcdc_ilim
[] = {
303 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
306 static const struct regulator_ops wm831x_buckv_ops
= {
307 .set_voltage_sel
= wm831x_buckv_set_voltage_sel
,
308 .get_voltage_sel
= wm831x_buckv_get_voltage_sel
,
309 .list_voltage
= regulator_list_voltage_linear_range
,
310 .map_voltage
= regulator_map_voltage_linear_range
,
311 .set_suspend_voltage
= wm831x_buckv_set_suspend_voltage
,
312 .set_current_limit
= regulator_set_current_limit_regmap
,
313 .get_current_limit
= regulator_get_current_limit_regmap
,
315 .is_enabled
= regulator_is_enabled_regmap
,
316 .enable
= regulator_enable_regmap
,
317 .disable
= regulator_disable_regmap
,
318 .get_status
= wm831x_dcdc_get_status
,
319 .get_mode
= wm831x_dcdc_get_mode
,
320 .set_mode
= wm831x_dcdc_set_mode
,
321 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
325 * Set up DVS control. We just log errors since we can still run
326 * (with reduced performance) if we fail.
328 static void wm831x_buckv_dvs_init(struct platform_device
*pdev
,
329 struct wm831x_dcdc
*dcdc
,
330 struct wm831x_buckv_pdata
*pdata
)
332 struct wm831x
*wm831x
= dcdc
->wm831x
;
339 /* gpiolib won't let us read the GPIO status so pick the higher
340 * of the two existing voltages so we take it as platform data.
342 dcdc
->dvs_gpio_state
= pdata
->dvs_init_state
;
344 dcdc
->dvs_gpiod
= devm_gpiod_get(&pdev
->dev
, "dvs",
345 dcdc
->dvs_gpio_state
? GPIOD_OUT_HIGH
: GPIOD_OUT_LOW
);
346 if (IS_ERR(dcdc
->dvs_gpiod
)) {
347 dev_err(wm831x
->dev
, "Failed to get %s DVS GPIO: %ld\n",
348 dcdc
->name
, PTR_ERR(dcdc
->dvs_gpiod
));
352 switch (pdata
->dvs_control_src
) {
354 ctrl
= 2 << WM831X_DC1_DVS_SRC_SHIFT
;
357 ctrl
= 3 << WM831X_DC1_DVS_SRC_SHIFT
;
360 dev_err(wm831x
->dev
, "Invalid DVS control source %d for %s\n",
361 pdata
->dvs_control_src
, dcdc
->name
);
365 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
366 * to make bootstrapping a bit smoother.
368 if (!dcdc
->dvs_vsel
) {
369 ret
= wm831x_set_bits(wm831x
,
370 dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
371 WM831X_DC1_DVS_VSEL_MASK
, dcdc
->on_vsel
);
373 dcdc
->dvs_vsel
= dcdc
->on_vsel
;
375 dev_warn(wm831x
->dev
, "Failed to set DVS_VSEL: %d\n",
379 ret
= wm831x_set_bits(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
,
380 WM831X_DC1_DVS_SRC_MASK
, ctrl
);
382 dev_err(wm831x
->dev
, "Failed to set %s DVS source: %d\n",
387 static int wm831x_buckv_probe(struct platform_device
*pdev
)
389 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
390 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
391 struct regulator_config config
= { };
393 struct wm831x_dcdc
*dcdc
;
394 struct resource
*res
;
397 if (pdata
&& pdata
->wm831x_num
)
398 id
= (pdata
->wm831x_num
* 10) + 1;
403 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
405 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
410 dcdc
->wm831x
= wm831x
;
412 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
414 dev_err(&pdev
->dev
, "No REG resource\n");
418 dcdc
->base
= res
->start
;
420 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
421 dcdc
->desc
.name
= dcdc
->name
;
423 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
425 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
428 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
429 dcdc
->desc
.n_voltages
= WM831X_BUCKV_MAX_SELECTOR
+ 1;
430 dcdc
->desc
.linear_ranges
= wm831x_buckv_ranges
;
431 dcdc
->desc
.n_linear_ranges
= ARRAY_SIZE(wm831x_buckv_ranges
);
432 dcdc
->desc
.ops
= &wm831x_buckv_ops
;
433 dcdc
->desc
.owner
= THIS_MODULE
;
434 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
435 dcdc
->desc
.enable_mask
= 1 << id
;
436 dcdc
->desc
.csel_reg
= dcdc
->base
+ WM831X_DCDC_CONTROL_2
;
437 dcdc
->desc
.csel_mask
= WM831X_DC1_HC_THR_MASK
;
438 dcdc
->desc
.n_current_limits
= ARRAY_SIZE(wm831x_dcdc_ilim
);
439 dcdc
->desc
.curr_table
= wm831x_dcdc_ilim
;
441 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_ON_CONFIG
);
443 dev_err(wm831x
->dev
, "Failed to read ON VSEL: %d\n", ret
);
446 dcdc
->on_vsel
= ret
& WM831X_DC1_ON_VSEL_MASK
;
448 ret
= wm831x_reg_read(wm831x
, dcdc
->base
+ WM831X_DCDC_DVS_CONTROL
);
450 dev_err(wm831x
->dev
, "Failed to read DVS VSEL: %d\n", ret
);
453 dcdc
->dvs_vsel
= ret
& WM831X_DC1_DVS_VSEL_MASK
;
455 if (pdata
&& pdata
->dcdc
[id
])
456 wm831x_buckv_dvs_init(pdev
, dcdc
,
457 pdata
->dcdc
[id
]->driver_data
);
459 config
.dev
= pdev
->dev
.parent
;
461 config
.init_data
= pdata
->dcdc
[id
];
462 config
.driver_data
= dcdc
;
463 config
.regmap
= wm831x
->regmap
;
465 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
467 if (IS_ERR(dcdc
->regulator
)) {
468 ret
= PTR_ERR(dcdc
->regulator
);
469 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
474 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
475 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
477 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
480 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
485 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "HC"));
486 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
488 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
491 dev_err(&pdev
->dev
, "Failed to request HC IRQ %d: %d\n",
496 platform_set_drvdata(pdev
, dcdc
);
504 static struct platform_driver wm831x_buckv_driver
= {
505 .probe
= wm831x_buckv_probe
,
507 .name
= "wm831x-buckv",
508 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
516 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev
*rdev
, int uV
)
518 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
519 struct wm831x
*wm831x
= dcdc
->wm831x
;
520 u16 reg
= dcdc
->base
+ WM831X_DCDC_SLEEP_CONTROL
;
523 sel
= regulator_map_voltage_linear(rdev
, uV
, uV
);
527 return wm831x_set_bits(wm831x
, reg
, WM831X_DC3_ON_VSEL_MASK
, sel
);
530 static const struct regulator_ops wm831x_buckp_ops
= {
531 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
532 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
533 .list_voltage
= regulator_list_voltage_linear
,
534 .map_voltage
= regulator_map_voltage_linear
,
535 .set_suspend_voltage
= wm831x_buckp_set_suspend_voltage
,
537 .is_enabled
= regulator_is_enabled_regmap
,
538 .enable
= regulator_enable_regmap
,
539 .disable
= regulator_disable_regmap
,
540 .get_status
= wm831x_dcdc_get_status
,
541 .get_mode
= wm831x_dcdc_get_mode
,
542 .set_mode
= wm831x_dcdc_set_mode
,
543 .set_suspend_mode
= wm831x_dcdc_set_suspend_mode
,
546 static int wm831x_buckp_probe(struct platform_device
*pdev
)
548 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
549 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
550 struct regulator_config config
= { };
552 struct wm831x_dcdc
*dcdc
;
553 struct resource
*res
;
556 if (pdata
&& pdata
->wm831x_num
)
557 id
= (pdata
->wm831x_num
* 10) + 1;
562 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
564 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
),
569 dcdc
->wm831x
= wm831x
;
571 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
573 dev_err(&pdev
->dev
, "No REG resource\n");
577 dcdc
->base
= res
->start
;
579 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
580 dcdc
->desc
.name
= dcdc
->name
;
582 snprintf(dcdc
->supply_name
, sizeof(dcdc
->supply_name
),
584 dcdc
->desc
.supply_name
= dcdc
->supply_name
;
587 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
588 dcdc
->desc
.n_voltages
= WM831X_BUCKP_MAX_SELECTOR
+ 1;
589 dcdc
->desc
.ops
= &wm831x_buckp_ops
;
590 dcdc
->desc
.owner
= THIS_MODULE
;
591 dcdc
->desc
.vsel_reg
= dcdc
->base
+ WM831X_DCDC_ON_CONFIG
;
592 dcdc
->desc
.vsel_mask
= WM831X_DC3_ON_VSEL_MASK
;
593 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
594 dcdc
->desc
.enable_mask
= 1 << id
;
595 dcdc
->desc
.min_uV
= 850000;
596 dcdc
->desc
.uV_step
= 25000;
598 config
.dev
= pdev
->dev
.parent
;
600 config
.init_data
= pdata
->dcdc
[id
];
601 config
.driver_data
= dcdc
;
602 config
.regmap
= wm831x
->regmap
;
604 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
606 if (IS_ERR(dcdc
->regulator
)) {
607 ret
= PTR_ERR(dcdc
->regulator
);
608 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
613 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
614 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
616 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
619 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
624 platform_set_drvdata(pdev
, dcdc
);
632 static struct platform_driver wm831x_buckp_driver
= {
633 .probe
= wm831x_buckp_probe
,
635 .name
= "wm831x-buckp",
636 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
641 * DCDC boost convertors
644 static int wm831x_boostp_get_status(struct regulator_dev
*rdev
)
646 struct wm831x_dcdc
*dcdc
= rdev_get_drvdata(rdev
);
647 struct wm831x
*wm831x
= dcdc
->wm831x
;
650 /* First, check for errors */
651 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_UV_STATUS
);
655 if (ret
& (1 << rdev_get_id(rdev
))) {
656 dev_dbg(wm831x
->dev
, "DCDC%d under voltage\n",
657 rdev_get_id(rdev
) + 1);
658 return REGULATOR_STATUS_ERROR
;
661 /* Is the regulator on? */
662 ret
= wm831x_reg_read(wm831x
, WM831X_DCDC_STATUS
);
665 if (ret
& (1 << rdev_get_id(rdev
)))
666 return REGULATOR_STATUS_ON
;
668 return REGULATOR_STATUS_OFF
;
671 static const struct regulator_ops wm831x_boostp_ops
= {
672 .get_status
= wm831x_boostp_get_status
,
674 .is_enabled
= regulator_is_enabled_regmap
,
675 .enable
= regulator_enable_regmap
,
676 .disable
= regulator_disable_regmap
,
679 static int wm831x_boostp_probe(struct platform_device
*pdev
)
681 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
682 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
683 struct regulator_config config
= { };
684 int id
= pdev
->id
% ARRAY_SIZE(pdata
->dcdc
);
685 struct wm831x_dcdc
*dcdc
;
686 struct resource
*res
;
689 dev_dbg(&pdev
->dev
, "Probing DCDC%d\n", id
+ 1);
691 if (pdata
== NULL
|| pdata
->dcdc
[id
] == NULL
)
694 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
698 dcdc
->wm831x
= wm831x
;
700 res
= platform_get_resource(pdev
, IORESOURCE_REG
, 0);
702 dev_err(&pdev
->dev
, "No REG resource\n");
705 dcdc
->base
= res
->start
;
707 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "DCDC%d", id
+ 1);
708 dcdc
->desc
.name
= dcdc
->name
;
710 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
711 dcdc
->desc
.ops
= &wm831x_boostp_ops
;
712 dcdc
->desc
.owner
= THIS_MODULE
;
713 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
714 dcdc
->desc
.enable_mask
= 1 << id
;
716 config
.dev
= pdev
->dev
.parent
;
718 config
.init_data
= pdata
->dcdc
[id
];
719 config
.driver_data
= dcdc
;
720 config
.regmap
= wm831x
->regmap
;
722 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
724 if (IS_ERR(dcdc
->regulator
)) {
725 ret
= PTR_ERR(dcdc
->regulator
);
726 dev_err(wm831x
->dev
, "Failed to register DCDC%d: %d\n",
731 irq
= wm831x_irq(wm831x
, platform_get_irq_byname(pdev
, "UV"));
732 ret
= devm_request_threaded_irq(&pdev
->dev
, irq
, NULL
,
734 IRQF_TRIGGER_RISING
| IRQF_ONESHOT
,
738 dev_err(&pdev
->dev
, "Failed to request UV IRQ %d: %d\n",
743 platform_set_drvdata(pdev
, dcdc
);
748 static struct platform_driver wm831x_boostp_driver
= {
749 .probe
= wm831x_boostp_probe
,
751 .name
= "wm831x-boostp",
752 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
757 * External Power Enable
759 * These aren't actually DCDCs but look like them in hardware so share
763 #define WM831X_EPE_BASE 6
765 static const struct regulator_ops wm831x_epe_ops
= {
766 .is_enabled
= regulator_is_enabled_regmap
,
767 .enable
= regulator_enable_regmap
,
768 .disable
= regulator_disable_regmap
,
769 .get_status
= wm831x_dcdc_get_status
,
772 static int wm831x_epe_probe(struct platform_device
*pdev
)
774 struct wm831x
*wm831x
= dev_get_drvdata(pdev
->dev
.parent
);
775 struct wm831x_pdata
*pdata
= dev_get_platdata(wm831x
->dev
);
776 struct regulator_config config
= { };
777 int id
= pdev
->id
% ARRAY_SIZE(pdata
->epe
);
778 struct wm831x_dcdc
*dcdc
;
781 dev_dbg(&pdev
->dev
, "Probing EPE%d\n", id
+ 1);
783 dcdc
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm831x_dcdc
), GFP_KERNEL
);
787 dcdc
->wm831x
= wm831x
;
789 /* For current parts this is correct; probably need to revisit
792 snprintf(dcdc
->name
, sizeof(dcdc
->name
), "EPE%d", id
+ 1);
793 dcdc
->desc
.name
= dcdc
->name
;
794 dcdc
->desc
.id
= id
+ WM831X_EPE_BASE
; /* Offset in DCDC registers */
795 dcdc
->desc
.ops
= &wm831x_epe_ops
;
796 dcdc
->desc
.type
= REGULATOR_VOLTAGE
;
797 dcdc
->desc
.owner
= THIS_MODULE
;
798 dcdc
->desc
.enable_reg
= WM831X_DCDC_ENABLE
;
799 dcdc
->desc
.enable_mask
= 1 << dcdc
->desc
.id
;
801 config
.dev
= pdev
->dev
.parent
;
803 config
.init_data
= pdata
->epe
[id
];
804 config
.driver_data
= dcdc
;
805 config
.regmap
= wm831x
->regmap
;
807 dcdc
->regulator
= devm_regulator_register(&pdev
->dev
, &dcdc
->desc
,
809 if (IS_ERR(dcdc
->regulator
)) {
810 ret
= PTR_ERR(dcdc
->regulator
);
811 dev_err(wm831x
->dev
, "Failed to register EPE%d: %d\n",
816 platform_set_drvdata(pdev
, dcdc
);
824 static struct platform_driver wm831x_epe_driver
= {
825 .probe
= wm831x_epe_probe
,
827 .name
= "wm831x-epe",
828 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
832 static struct platform_driver
* const drivers
[] = {
833 &wm831x_buckv_driver
,
834 &wm831x_buckp_driver
,
835 &wm831x_boostp_driver
,
839 static int __init
wm831x_dcdc_init(void)
841 return platform_register_drivers(drivers
, ARRAY_SIZE(drivers
));
843 subsys_initcall(wm831x_dcdc_init
);
845 static void __exit
wm831x_dcdc_exit(void)
847 platform_unregister_drivers(drivers
, ARRAY_SIZE(drivers
));
849 module_exit(wm831x_dcdc_exit
);
851 /* Module information */
852 MODULE_AUTHOR("Mark Brown");
853 MODULE_DESCRIPTION("WM831x DC-DC convertor driver");
854 MODULE_LICENSE("GPL");
855 MODULE_ALIAS("platform:wm831x-buckv");
856 MODULE_ALIAS("platform:wm831x-buckp");
857 MODULE_ALIAS("platform:wm831x-boostp");
858 MODULE_ALIAS("platform:wm831x-epe");