14 #include <linux/module.h>
17 #include <linux/bitops.h>
19 #include <linux/i2c.h>
22 #include <linux/slab.h>
28 #define WM831X_LDO_MAX_NAME 9
30 #define WM831X_LDO_CONTROL 0
31 #define WM831X_LDO_ON_CONTROL 1
32 #define WM831X_LDO_SLEEP_CONTROL 2
34 #define WM831X_ALIVE_LDO_ON_CONTROL 0
35 #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
65 #define WM831X_GP_LDO_SELECTOR_LOW 0xe
66 #define WM831X_GP_LDO_MAX_SELECTOR 0x1f
73 return 900000 + (selector * 50000);
82 int min_uV,
int max_uV)
88 else if (min_uV < 1700000)
89 vsel = ((min_uV - 900000) / 50000);
91 vsel = ((min_uV - 1700000) / 100000)
94 volt = wm831x_gp_ldo_list_voltage(rdev, vsel);
95 if (volt < min_uV || volt > max_uV)
101 static int wm831x_gp_ldo_set_suspend_voltage(
struct regulator_dev *rdev,
108 sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV);
115 static unsigned int wm831x_gp_ldo_get_mode(
struct regulator_dev *rdev)
118 struct wm831x *wm831x = ldo->
wm831x;
140 static int wm831x_gp_ldo_set_mode(
struct regulator_dev *rdev,
144 struct wm831x *wm831x = ldo->
wm831x;
153 WM831X_LDO1_ON_MODE, 0);
166 WM831X_LDO1_ON_MODE);
180 WM831X_LDO1_ON_MODE);
192 static int wm831x_gp_ldo_get_status(
struct regulator_dev *rdev)
195 struct wm831x *wm831x = ldo->
wm831x;
213 ret = wm831x_gp_ldo_get_mode(rdev);
220 static unsigned int wm831x_gp_ldo_get_optimum_mode(
struct regulator_dev *rdev,
222 int output_uV,
int load_uA)
233 .list_voltage = wm831x_gp_ldo_list_voltage,
234 .map_voltage = wm831x_gp_ldo_map_voltage,
237 .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
238 .get_mode = wm831x_gp_ldo_get_mode,
239 .set_mode = wm831x_gp_ldo_set_mode,
240 .get_status = wm831x_gp_ldo_get_status,
241 .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
266 dev_dbg(&pdev->
dev,
"Probing LDO%d\n",
id + 1);
270 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
294 ldo->
desc.ops = &wm831x_gp_ldo_ops;
299 ldo->
desc.enable_mask = 1 <<
id;
303 config.
dev = pdev->
dev.parent;
312 dev_err(wm831x->
dev,
"Failed to register LDO%d: %d\n",
322 dev_err(&pdev->
dev,
"Failed to request UV IRQ %d: %d\n",
327 platform_set_drvdata(pdev, ldo);
339 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
341 platform_set_drvdata(pdev,
NULL);
351 .probe = wm831x_gp_ldo_probe,
354 .name =
"wm831x-ldo",
364 #define WM831X_ALDO_SELECTOR_LOW 0xc
365 #define WM831X_ALDO_MAX_SELECTOR 0x1f
367 static int wm831x_aldo_list_voltage(
struct regulator_dev *rdev,
372 return 1000000 + (selector * 50000);
380 static int wm831x_aldo_map_voltage(
struct regulator_dev *rdev,
381 int min_uV,
int max_uV)
385 if (min_uV < 1000000)
387 else if (min_uV < 1700000)
388 vsel = ((min_uV - 1000000) / 50000);
390 vsel = ((min_uV - 1700000) / 100000)
393 volt = wm831x_aldo_list_voltage(rdev, vsel);
394 if (volt < min_uV || volt > max_uV)
401 static int wm831x_aldo_set_suspend_voltage(
struct regulator_dev *rdev,
405 struct wm831x *wm831x = ldo->
wm831x;
408 sel = wm831x_aldo_map_voltage(rdev, uV, uV);
415 static unsigned int wm831x_aldo_get_mode(
struct regulator_dev *rdev)
418 struct wm831x *wm831x = ldo->
wm831x;
436 struct wm831x *wm831x = ldo->
wm831x;
462 static int wm831x_aldo_get_status(
struct regulator_dev *rdev)
465 struct wm831x *wm831x = ldo->
wm831x;
483 ret = wm831x_aldo_get_mode(rdev);
491 .list_voltage = wm831x_aldo_list_voltage,
492 .map_voltage = wm831x_aldo_map_voltage,
495 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
496 .get_mode = wm831x_aldo_get_mode,
497 .set_mode = wm831x_aldo_set_mode,
498 .get_status = wm831x_aldo_get_status,
523 dev_dbg(&pdev->
dev,
"Probing LDO%d\n",
id + 1);
527 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
551 ldo->
desc.ops = &wm831x_aldo_ops;
556 ldo->
desc.enable_mask = 1 <<
id;
560 config.
dev = pdev->
dev.parent;
569 dev_err(wm831x->
dev,
"Failed to register LDO%d: %d\n",
578 dev_err(&pdev->
dev,
"Failed to request UV IRQ %d: %d\n",
583 platform_set_drvdata(pdev, ldo);
595 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
605 .probe = wm831x_aldo_probe,
608 .name =
"wm831x-aldo",
617 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
619 static int wm831x_alive_ldo_set_suspend_voltage(
struct regulator_dev *rdev,
623 struct wm831x *wm831x = ldo->
wm831x;
633 static int wm831x_alive_ldo_get_status(
struct regulator_dev *rdev)
636 struct wm831x *wm831x = ldo->
wm831x;
655 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
656 .get_status = wm831x_alive_ldo_get_status,
680 dev_dbg(&pdev->
dev,
"Probing LDO%d\n",
id + 1);
684 dev_err(&pdev->
dev,
"Unable to allocate private data\n");
708 ldo->
desc.ops = &wm831x_alive_ldo_ops;
713 ldo->
desc.enable_mask = 1 <<
id;
714 ldo->
desc.min_uV = 800000;
715 ldo->
desc.uV_step = 50000;
716 ldo->
desc.enable_time = 1000;
718 config.
dev = pdev->
dev.parent;
727 dev_err(wm831x->
dev,
"Failed to register LDO%d: %d\n",
732 platform_set_drvdata(pdev, ldo);
742 struct wm831x_ldo *ldo = platform_get_drvdata(pdev);
750 .probe = wm831x_alive_ldo_probe,
753 .name =
"wm831x-alive-ldo",
758 static int __init wm831x_ldo_init(
void)
764 pr_err(
"Failed to register WM831x GP LDO driver: %d\n", ret);
768 pr_err(
"Failed to register WM831x ALDO driver: %d\n", ret);
772 pr_err(
"Failed to register WM831x alive LDO driver: %d\n",
779 static void __exit wm831x_ldo_exit(
void)