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_lock(dcdc->regulator);
182 regulator_notifier_call_chain(dcdc->regulator,
183 REGULATOR_EVENT_UNDER_VOLTAGE,
185 regulator_unlock(dcdc->regulator);
190 static irqreturn_t wm831x_dcdc_oc_irq(int irq, void *data)
192 struct wm831x_dcdc *dcdc = data;
194 regulator_lock(dcdc->regulator);
195 regulator_notifier_call_chain(dcdc->regulator,
196 REGULATOR_EVENT_OVER_CURRENT,
198 regulator_unlock(dcdc->regulator);
207 static const struct linear_range wm831x_buckv_ranges[] = {
208 REGULATOR_LINEAR_RANGE(600000, 0, 0x7, 0),
209 REGULATOR_LINEAR_RANGE(600000, 0x8, 0x68, 12500),
212 static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
214 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
216 if (state == dcdc->dvs_gpio_state)
219 dcdc->dvs_gpio_state = state;
220 gpiod_set_value(dcdc->dvs_gpiod, state);
222 /* Should wait for DVS state change to be asserted if we have
223 * a GPIO for it, for now assume the device is configured
224 * for the fastest possible transition.
230 static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
233 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
234 struct wm831x *wm831x = dcdc->wm831x;
235 int on_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
236 int dvs_reg = dcdc->base + WM831X_DCDC_DVS_CONTROL;
239 /* If this value is already set then do a GPIO update if we can */
240 if (dcdc->dvs_gpiod && dcdc->on_vsel == vsel)
241 return wm831x_buckv_set_dvs(rdev, 0);
243 if (dcdc->dvs_gpiod && dcdc->dvs_vsel == vsel)
244 return wm831x_buckv_set_dvs(rdev, 1);
246 /* Always set the ON status to the minimum voltage */
247 ret = wm831x_set_bits(wm831x, on_reg, WM831X_DC1_ON_VSEL_MASK, vsel);
250 dcdc->on_vsel = vsel;
252 if (!dcdc->dvs_gpiod)
255 /* Kick the voltage transition now */
256 ret = wm831x_buckv_set_dvs(rdev, 0);
261 * If this VSEL is higher than the last one we've seen then
262 * remember it as the DVS VSEL. This is optimised for CPUfreq
263 * usage where we want to get to the highest voltage very
266 if (vsel > dcdc->dvs_vsel) {
267 ret = wm831x_set_bits(wm831x, dvs_reg,
268 WM831X_DC1_DVS_VSEL_MASK,
271 dcdc->dvs_vsel = vsel;
273 dev_warn(wm831x->dev,
274 "Failed to set DCDC DVS VSEL: %d\n", ret);
280 static int wm831x_buckv_set_suspend_voltage(struct regulator_dev *rdev,
283 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
284 struct wm831x *wm831x = dcdc->wm831x;
285 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
288 vsel = regulator_map_voltage_linear_range(rdev, uV, uV);
292 return wm831x_set_bits(wm831x, reg, WM831X_DC1_SLP_VSEL_MASK, vsel);
295 static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
297 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
299 if (dcdc->dvs_gpiod && dcdc->dvs_gpio_state)
300 return dcdc->dvs_vsel;
302 return dcdc->on_vsel;
305 /* Current limit options */
306 static const unsigned int wm831x_dcdc_ilim[] = {
307 125000, 250000, 375000, 500000, 625000, 750000, 875000, 1000000
310 static const struct regulator_ops wm831x_buckv_ops = {
311 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
312 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
313 .list_voltage = regulator_list_voltage_linear_range,
314 .map_voltage = regulator_map_voltage_linear_range,
315 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
316 .set_current_limit = regulator_set_current_limit_regmap,
317 .get_current_limit = regulator_get_current_limit_regmap,
319 .is_enabled = regulator_is_enabled_regmap,
320 .enable = regulator_enable_regmap,
321 .disable = regulator_disable_regmap,
322 .get_status = wm831x_dcdc_get_status,
323 .get_mode = wm831x_dcdc_get_mode,
324 .set_mode = wm831x_dcdc_set_mode,
325 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
329 * Set up DVS control. We just log errors since we can still run
330 * (with reduced performance) if we fail.
332 static void wm831x_buckv_dvs_init(struct platform_device *pdev,
333 struct wm831x_dcdc *dcdc,
334 struct wm831x_buckv_pdata *pdata)
336 struct wm831x *wm831x = dcdc->wm831x;
343 /* gpiolib won't let us read the GPIO status so pick the higher
344 * of the two existing voltages so we take it as platform data.
346 dcdc->dvs_gpio_state = pdata->dvs_init_state;
348 dcdc->dvs_gpiod = devm_gpiod_get(&pdev->dev, "dvs",
349 dcdc->dvs_gpio_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
350 if (IS_ERR(dcdc->dvs_gpiod)) {
351 dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %ld\n",
352 dcdc->name, PTR_ERR(dcdc->dvs_gpiod));
356 switch (pdata->dvs_control_src) {
358 ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;
361 ctrl = 3 << WM831X_DC1_DVS_SRC_SHIFT;
364 dev_err(wm831x->dev, "Invalid DVS control source %d for %s\n",
365 pdata->dvs_control_src, dcdc->name);
369 /* If DVS_VSEL is set to the minimum value then raise it to ON_VSEL
370 * to make bootstrapping a bit smoother.
372 if (!dcdc->dvs_vsel) {
373 ret = wm831x_set_bits(wm831x,
374 dcdc->base + WM831X_DCDC_DVS_CONTROL,
375 WM831X_DC1_DVS_VSEL_MASK, dcdc->on_vsel);
377 dcdc->dvs_vsel = dcdc->on_vsel;
379 dev_warn(wm831x->dev, "Failed to set DVS_VSEL: %d\n",
383 ret = wm831x_set_bits(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL,
384 WM831X_DC1_DVS_SRC_MASK, ctrl);
386 dev_err(wm831x->dev, "Failed to set %s DVS source: %d\n",
391 static int wm831x_buckv_probe(struct platform_device *pdev)
393 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
394 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
395 struct regulator_config config = { };
397 struct wm831x_dcdc *dcdc;
398 struct resource *res;
401 if (pdata && pdata->wm831x_num)
402 id = (pdata->wm831x_num * 10) + 1;
407 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
409 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
414 dcdc->wm831x = wm831x;
416 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
418 dev_err(&pdev->dev, "No REG resource\n");
422 dcdc->base = res->start;
424 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
425 dcdc->desc.name = dcdc->name;
427 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
429 dcdc->desc.supply_name = dcdc->supply_name;
432 dcdc->desc.type = REGULATOR_VOLTAGE;
433 dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1;
434 dcdc->desc.linear_ranges = wm831x_buckv_ranges;
435 dcdc->desc.n_linear_ranges = ARRAY_SIZE(wm831x_buckv_ranges);
436 dcdc->desc.ops = &wm831x_buckv_ops;
437 dcdc->desc.owner = THIS_MODULE;
438 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
439 dcdc->desc.enable_mask = 1 << id;
440 dcdc->desc.csel_reg = dcdc->base + WM831X_DCDC_CONTROL_2;
441 dcdc->desc.csel_mask = WM831X_DC1_HC_THR_MASK;
442 dcdc->desc.n_current_limits = ARRAY_SIZE(wm831x_dcdc_ilim);
443 dcdc->desc.curr_table = wm831x_dcdc_ilim;
445 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG);
447 dev_err(wm831x->dev, "Failed to read ON VSEL: %d\n", ret);
450 dcdc->on_vsel = ret & WM831X_DC1_ON_VSEL_MASK;
452 ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_DVS_CONTROL);
454 dev_err(wm831x->dev, "Failed to read DVS VSEL: %d\n", ret);
457 dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK;
459 if (pdata && pdata->dcdc[id])
460 wm831x_buckv_dvs_init(pdev, dcdc,
461 pdata->dcdc[id]->driver_data);
463 config.dev = pdev->dev.parent;
465 config.init_data = pdata->dcdc[id];
466 config.driver_data = dcdc;
467 config.regmap = wm831x->regmap;
469 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
471 if (IS_ERR(dcdc->regulator)) {
472 ret = PTR_ERR(dcdc->regulator);
473 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
478 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
479 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
481 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
484 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
489 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "HC"));
490 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
492 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
495 dev_err(&pdev->dev, "Failed to request HC IRQ %d: %d\n",
500 platform_set_drvdata(pdev, dcdc);
508 static struct platform_driver wm831x_buckv_driver = {
509 .probe = wm831x_buckv_probe,
511 .name = "wm831x-buckv",
519 static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, int uV)
521 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
522 struct wm831x *wm831x = dcdc->wm831x;
523 u16 reg = dcdc->base + WM831X_DCDC_SLEEP_CONTROL;
526 sel = regulator_map_voltage_linear(rdev, uV, uV);
530 return wm831x_set_bits(wm831x, reg, WM831X_DC3_ON_VSEL_MASK, sel);
533 static const struct regulator_ops wm831x_buckp_ops = {
534 .set_voltage_sel = regulator_set_voltage_sel_regmap,
535 .get_voltage_sel = regulator_get_voltage_sel_regmap,
536 .list_voltage = regulator_list_voltage_linear,
537 .map_voltage = regulator_map_voltage_linear,
538 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
540 .is_enabled = regulator_is_enabled_regmap,
541 .enable = regulator_enable_regmap,
542 .disable = regulator_disable_regmap,
543 .get_status = wm831x_dcdc_get_status,
544 .get_mode = wm831x_dcdc_get_mode,
545 .set_mode = wm831x_dcdc_set_mode,
546 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
549 static int wm831x_buckp_probe(struct platform_device *pdev)
551 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
552 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
553 struct regulator_config config = { };
555 struct wm831x_dcdc *dcdc;
556 struct resource *res;
559 if (pdata && pdata->wm831x_num)
560 id = (pdata->wm831x_num * 10) + 1;
565 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
567 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc),
572 dcdc->wm831x = wm831x;
574 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
576 dev_err(&pdev->dev, "No REG resource\n");
580 dcdc->base = res->start;
582 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
583 dcdc->desc.name = dcdc->name;
585 snprintf(dcdc->supply_name, sizeof(dcdc->supply_name),
587 dcdc->desc.supply_name = dcdc->supply_name;
590 dcdc->desc.type = REGULATOR_VOLTAGE;
591 dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1;
592 dcdc->desc.ops = &wm831x_buckp_ops;
593 dcdc->desc.owner = THIS_MODULE;
594 dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG;
595 dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK;
596 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
597 dcdc->desc.enable_mask = 1 << id;
598 dcdc->desc.min_uV = 850000;
599 dcdc->desc.uV_step = 25000;
601 config.dev = pdev->dev.parent;
603 config.init_data = pdata->dcdc[id];
604 config.driver_data = dcdc;
605 config.regmap = wm831x->regmap;
607 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
609 if (IS_ERR(dcdc->regulator)) {
610 ret = PTR_ERR(dcdc->regulator);
611 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
616 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
617 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
619 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
622 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
627 platform_set_drvdata(pdev, dcdc);
635 static struct platform_driver wm831x_buckp_driver = {
636 .probe = wm831x_buckp_probe,
638 .name = "wm831x-buckp",
643 * DCDC boost convertors
646 static int wm831x_boostp_get_status(struct regulator_dev *rdev)
648 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
649 struct wm831x *wm831x = dcdc->wm831x;
652 /* First, check for errors */
653 ret = wm831x_reg_read(wm831x, WM831X_DCDC_UV_STATUS);
657 if (ret & (1 << rdev_get_id(rdev))) {
658 dev_dbg(wm831x->dev, "DCDC%d under voltage\n",
659 rdev_get_id(rdev) + 1);
660 return REGULATOR_STATUS_ERROR;
663 /* Is the regulator on? */
664 ret = wm831x_reg_read(wm831x, WM831X_DCDC_STATUS);
667 if (ret & (1 << rdev_get_id(rdev)))
668 return REGULATOR_STATUS_ON;
670 return REGULATOR_STATUS_OFF;
673 static const struct regulator_ops wm831x_boostp_ops = {
674 .get_status = wm831x_boostp_get_status,
676 .is_enabled = regulator_is_enabled_regmap,
677 .enable = regulator_enable_regmap,
678 .disable = regulator_disable_regmap,
681 static int wm831x_boostp_probe(struct platform_device *pdev)
683 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
684 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
685 struct regulator_config config = { };
686 int id = pdev->id % ARRAY_SIZE(pdata->dcdc);
687 struct wm831x_dcdc *dcdc;
688 struct resource *res;
691 dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1);
693 if (pdata == NULL || pdata->dcdc[id] == NULL)
696 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
700 dcdc->wm831x = wm831x;
702 res = platform_get_resource(pdev, IORESOURCE_REG, 0);
704 dev_err(&pdev->dev, "No REG resource\n");
707 dcdc->base = res->start;
709 snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1);
710 dcdc->desc.name = dcdc->name;
712 dcdc->desc.type = REGULATOR_VOLTAGE;
713 dcdc->desc.ops = &wm831x_boostp_ops;
714 dcdc->desc.owner = THIS_MODULE;
715 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
716 dcdc->desc.enable_mask = 1 << id;
718 config.dev = pdev->dev.parent;
720 config.init_data = pdata->dcdc[id];
721 config.driver_data = dcdc;
722 config.regmap = wm831x->regmap;
724 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
726 if (IS_ERR(dcdc->regulator)) {
727 ret = PTR_ERR(dcdc->regulator);
728 dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n",
733 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
734 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
736 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
740 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
745 platform_set_drvdata(pdev, dcdc);
750 static struct platform_driver wm831x_boostp_driver = {
751 .probe = wm831x_boostp_probe,
753 .name = "wm831x-boostp",
758 * External Power Enable
760 * These aren't actually DCDCs but look like them in hardware so share
764 #define WM831X_EPE_BASE 6
766 static const struct regulator_ops wm831x_epe_ops = {
767 .is_enabled = regulator_is_enabled_regmap,
768 .enable = regulator_enable_regmap,
769 .disable = regulator_disable_regmap,
770 .get_status = wm831x_dcdc_get_status,
773 static int wm831x_epe_probe(struct platform_device *pdev)
775 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
776 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
777 struct regulator_config config = { };
778 int id = pdev->id % ARRAY_SIZE(pdata->epe);
779 struct wm831x_dcdc *dcdc;
782 dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1);
784 dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL);
788 dcdc->wm831x = wm831x;
790 /* For current parts this is correct; probably need to revisit
793 snprintf(dcdc->name, sizeof(dcdc->name), "EPE%d", id + 1);
794 dcdc->desc.name = dcdc->name;
795 dcdc->desc.id = id + WM831X_EPE_BASE; /* Offset in DCDC registers */
796 dcdc->desc.ops = &wm831x_epe_ops;
797 dcdc->desc.type = REGULATOR_VOLTAGE;
798 dcdc->desc.owner = THIS_MODULE;
799 dcdc->desc.enable_reg = WM831X_DCDC_ENABLE;
800 dcdc->desc.enable_mask = 1 << dcdc->desc.id;
802 config.dev = pdev->dev.parent;
804 config.init_data = pdata->epe[id];
805 config.driver_data = dcdc;
806 config.regmap = wm831x->regmap;
808 dcdc->regulator = devm_regulator_register(&pdev->dev, &dcdc->desc,
810 if (IS_ERR(dcdc->regulator)) {
811 ret = PTR_ERR(dcdc->regulator);
812 dev_err(wm831x->dev, "Failed to register EPE%d: %d\n",
817 platform_set_drvdata(pdev, dcdc);
825 static struct platform_driver wm831x_epe_driver = {
826 .probe = wm831x_epe_probe,
828 .name = "wm831x-epe",
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");