14 #include <linux/module.h>
17 #include <linux/bitops.h>
19 #include <linux/i2c.h>
24 #include <linux/slab.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
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
122 struct wm831x *wm831x = dcdc->
wm831x;
125 return wm831x_dcdc_set_mode_int(wm831x, reg, mode);
132 struct wm831x *wm831x = dcdc->
wm831x;
135 return wm831x_dcdc_set_mode_int(wm831x, reg, mode);
141 struct wm831x *wm831x = dcdc->
wm831x;
150 dev_dbg(wm831x->
dev,
"DCDC%d under voltage\n",
208 static int wm831x_buckv_list_voltage(
struct regulator_dev *rdev,
214 return 600000 + ((selector - 0x8) * 12500);
218 static int wm831x_buckv_map_voltage(
struct regulator_dev *rdev,
219 int min_uV,
int max_uV)
225 else if (min_uV <= 1800000)
226 vsel = ((min_uV - 600000) / 12500) + 8;
230 if (wm831x_buckv_list_voltage(rdev, vsel) > max_uV)
254 static int wm831x_buckv_set_voltage_sel(
struct regulator_dev *rdev,
258 struct wm831x *wm831x = dcdc->
wm831x;
265 return wm831x_buckv_set_dvs(rdev, 0);
268 return wm831x_buckv_set_dvs(rdev, 1);
280 ret = wm831x_buckv_set_dvs(rdev, 0);
298 "Failed to set DCDC DVS VSEL: %d\n", ret);
304 static int wm831x_buckv_set_suspend_voltage(
struct regulator_dev *rdev,
308 struct wm831x *wm831x = dcdc->
wm831x;
312 vsel = wm831x_buckv_map_voltage(rdev, uV, uV);
319 static int wm831x_buckv_get_voltage_sel(
struct regulator_dev *rdev)
330 static u16 wm831x_dcdc_ilim[] = {
331 125, 250, 375, 500, 625, 750, 875, 1000
334 static int wm831x_buckv_set_current_limit(
struct regulator_dev *rdev,
335 int min_uA,
int max_uA)
338 struct wm831x *wm831x = dcdc->
wm831x;
342 for (i =
ARRAY_SIZE(wm831x_dcdc_ilim) - 1; i >= 0; i--) {
343 if ((min_uA <= wm831x_dcdc_ilim[i]) &&
344 (wm831x_dcdc_ilim[i] <= max_uA))
353 static int wm831x_buckv_get_current_limit(
struct regulator_dev *rdev)
356 struct wm831x *wm831x = dcdc->
wm831x;
365 return wm831x_dcdc_ilim[
val];
369 .set_voltage_sel = wm831x_buckv_set_voltage_sel,
370 .get_voltage_sel = wm831x_buckv_get_voltage_sel,
371 .list_voltage = wm831x_buckv_list_voltage,
372 .map_voltage = wm831x_buckv_map_voltage,
373 .set_suspend_voltage = wm831x_buckv_set_suspend_voltage,
374 .set_current_limit = wm831x_buckv_set_current_limit,
375 .get_current_limit = wm831x_buckv_get_current_limit,
380 .get_status = wm831x_dcdc_get_status,
381 .get_mode = wm831x_dcdc_get_mode,
382 .set_mode = wm831x_dcdc_set_mode,
383 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
393 struct wm831x *wm831x = dcdc->
wm831x;
409 dev_err(wm831x->
dev,
"Failed to get %s DVS GPIO: %d\n",
424 dev_err(wm831x->
dev,
"Invalid DVS control source %d for %s\n",
439 dev_warn(wm831x->
dev,
"Failed to set DVS_VSEL: %d\n",
446 dev_err(wm831x->
dev,
"Failed to set %s DVS source: %d\n",
467 dev_dbg(&pdev->
dev,
"Probing DCDC%d\n",
id + 1);
472 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
496 dcdc->
desc.ops = &wm831x_buckv_ops;
499 dcdc->
desc.enable_mask = 1 <<
id;
503 dev_err(wm831x->
dev,
"Failed to read ON VSEL: %d\n", ret);
510 dev_err(wm831x->
dev,
"Failed to read DVS VSEL: %d\n", ret);
515 if (pdata && pdata->
dcdc[
id])
516 wm831x_buckv_dvs_init(dcdc, pdata->
dcdc[
id]->driver_data);
518 config.
dev = pdev->
dev.parent;
527 dev_err(wm831x->
dev,
"Failed to register DCDC%d: %d\n",
536 dev_err(&pdev->
dev,
"Failed to request UV IRQ %d: %d\n",
545 dev_err(&pdev->
dev,
"Failed to request HC IRQ %d: %d\n",
550 platform_set_drvdata(pdev, dcdc);
567 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
568 struct wm831x *wm831x = dcdc->
wm831x;
570 platform_set_drvdata(pdev,
NULL);
584 .probe = wm831x_buckv_probe,
587 .name =
"wm831x-buckv",
596 static int wm831x_buckp_set_suspend_voltage(
struct regulator_dev *rdev,
int uV)
599 struct wm831x *wm831x = dcdc->
wm831x;
615 .set_suspend_voltage = wm831x_buckp_set_suspend_voltage,
620 .get_status = wm831x_dcdc_get_status,
621 .get_mode = wm831x_dcdc_get_mode,
622 .set_mode = wm831x_dcdc_set_mode,
623 .set_suspend_mode = wm831x_dcdc_set_suspend_mode,
642 dev_dbg(&pdev->
dev,
"Probing DCDC%d\n",
id + 1);
647 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
671 dcdc->
desc.ops = &wm831x_buckp_ops;
676 dcdc->
desc.enable_mask = 1 <<
id;
677 dcdc->
desc.min_uV = 850000;
678 dcdc->
desc.uV_step = 25000;
680 config.
dev = pdev->
dev.parent;
689 dev_err(wm831x->
dev,
"Failed to register DCDC%d: %d\n",
698 dev_err(&pdev->
dev,
"Failed to request UV IRQ %d: %d\n",
703 platform_set_drvdata(pdev, dcdc);
715 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
717 platform_set_drvdata(pdev,
NULL);
727 .probe = wm831x_buckp_probe,
730 .name =
"wm831x-buckp",
739 static int wm831x_boostp_get_status(
struct regulator_dev *rdev)
742 struct wm831x *wm831x = dcdc->
wm831x;
751 dev_dbg(wm831x->
dev,
"DCDC%d under voltage\n",
767 .get_status = wm831x_boostp_get_status,
784 dev_dbg(&pdev->
dev,
"Probing DCDC%d\n",
id + 1);
791 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
809 dcdc->
desc.ops = &wm831x_boostp_ops;
812 dcdc->
desc.enable_mask = 1 <<
id;
814 config.
dev = pdev->
dev.parent;
823 dev_err(wm831x->
dev,
"Failed to register DCDC%d: %d\n",
833 dev_err(&pdev->
dev,
"Failed to request UV IRQ %d: %d\n",
838 platform_set_drvdata(pdev, dcdc);
850 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
852 platform_set_drvdata(pdev,
NULL);
862 .probe = wm831x_boostp_probe,
865 .name =
"wm831x-boostp",
877 #define WM831X_EPE_BASE 6
883 .get_status = wm831x_dcdc_get_status,
895 dev_dbg(&pdev->
dev,
"Probing EPE%d\n",
id + 1);
899 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
911 dcdc->
desc.ops = &wm831x_epe_ops;
915 dcdc->
desc.enable_mask = 1 << dcdc->
desc.id;
917 config.
dev = pdev->
dev.parent;
926 dev_err(wm831x->
dev,
"Failed to register EPE%d: %d\n",
931 platform_set_drvdata(pdev, dcdc);
941 struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev);
943 platform_set_drvdata(pdev,
NULL);
950 .probe = wm831x_epe_probe,
953 .name =
"wm831x-epe",
958 static int __init wm831x_dcdc_init(
void)
963 pr_err(
"Failed to register WM831x BUCKV driver: %d\n", ret);
967 pr_err(
"Failed to register WM831x BUCKP driver: %d\n", ret);
971 pr_err(
"Failed to register WM831x BOOST driver: %d\n", ret);
975 pr_err(
"Failed to register WM831x EPE driver: %d\n", ret);
981 static void __exit wm831x_dcdc_exit(
void)