diff options
Diffstat (limited to 'drivers/regulator/wm831x-ldo.c')
-rw-r--r-- | drivers/regulator/wm831x-ldo.c | 131 |
1 files changed, 40 insertions, 91 deletions
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index a9a28d8ac185..5cb70ca1e98d 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c | |||
@@ -78,13 +78,10 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, | |||
78 | return -EINVAL; | 78 | return -EINVAL; |
79 | } | 79 | } |
80 | 80 | ||
81 | static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, | 81 | static int wm831x_gp_ldo_map_voltage(struct regulator_dev *rdev, |
82 | int min_uV, int max_uV, | 82 | int min_uV, int max_uV) |
83 | unsigned *selector) | ||
84 | { | 83 | { |
85 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 84 | int volt, vsel; |
86 | struct wm831x *wm831x = ldo->wm831x; | ||
87 | int vsel, ret; | ||
88 | 85 | ||
89 | if (min_uV < 900000) | 86 | if (min_uV < 900000) |
90 | vsel = 0; | 87 | vsel = 0; |
@@ -94,36 +91,25 @@ static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, | |||
94 | vsel = ((min_uV - 1700000) / 100000) | 91 | vsel = ((min_uV - 1700000) / 100000) |
95 | + WM831X_GP_LDO_SELECTOR_LOW + 1; | 92 | + WM831X_GP_LDO_SELECTOR_LOW + 1; |
96 | 93 | ||
97 | ret = wm831x_gp_ldo_list_voltage(rdev, vsel); | 94 | volt = wm831x_gp_ldo_list_voltage(rdev, vsel); |
98 | if (ret < 0) | 95 | if (volt < min_uV || volt > max_uV) |
99 | return ret; | ||
100 | if (ret < min_uV || ret > max_uV) | ||
101 | return -EINVAL; | 96 | return -EINVAL; |
102 | 97 | ||
103 | *selector = vsel; | 98 | return vsel; |
104 | |||
105 | return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); | ||
106 | } | ||
107 | |||
108 | static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, | ||
109 | int min_uV, int max_uV, | ||
110 | unsigned *selector) | ||
111 | { | ||
112 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
113 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
114 | |||
115 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
116 | selector); | ||
117 | } | 99 | } |
118 | 100 | ||
119 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, | 101 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
120 | int uV) | 102 | int uV) |
121 | { | 103 | { |
122 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 104 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
123 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 105 | struct wm831x *wm831x = ldo->wm831x; |
124 | unsigned int selector; | 106 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
125 | 107 | ||
126 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 108 | sel = wm831x_gp_ldo_map_voltage(rdev, uV, uV); |
109 | if (sel < 0) | ||
110 | return sel; | ||
111 | |||
112 | return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel); | ||
127 | } | 113 | } |
128 | 114 | ||
129 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) | 115 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) |
@@ -243,8 +229,9 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, | |||
243 | 229 | ||
244 | static struct regulator_ops wm831x_gp_ldo_ops = { | 230 | static struct regulator_ops wm831x_gp_ldo_ops = { |
245 | .list_voltage = wm831x_gp_ldo_list_voltage, | 231 | .list_voltage = wm831x_gp_ldo_list_voltage, |
232 | .map_voltage = wm831x_gp_ldo_map_voltage, | ||
246 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 233 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
247 | .set_voltage = wm831x_gp_ldo_set_voltage, | 234 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
248 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, | 235 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, |
249 | .get_mode = wm831x_gp_ldo_get_mode, | 236 | .get_mode = wm831x_gp_ldo_get_mode, |
250 | .set_mode = wm831x_gp_ldo_set_mode, | 237 | .set_mode = wm831x_gp_ldo_set_mode, |
@@ -384,13 +371,10 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, | |||
384 | return -EINVAL; | 371 | return -EINVAL; |
385 | } | 372 | } |
386 | 373 | ||
387 | static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, | 374 | static int wm831x_aldo_map_voltage(struct regulator_dev *rdev, |
388 | int min_uV, int max_uV, | 375 | int min_uV, int max_uV) |
389 | unsigned *selector) | ||
390 | { | 376 | { |
391 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 377 | int volt, vsel; |
392 | struct wm831x *wm831x = ldo->wm831x; | ||
393 | int vsel, ret; | ||
394 | 378 | ||
395 | if (min_uV < 1000000) | 379 | if (min_uV < 1000000) |
396 | vsel = 0; | 380 | vsel = 0; |
@@ -400,35 +384,26 @@ static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, | |||
400 | vsel = ((min_uV - 1700000) / 100000) | 384 | vsel = ((min_uV - 1700000) / 100000) |
401 | + WM831X_ALDO_SELECTOR_LOW + 1; | 385 | + WM831X_ALDO_SELECTOR_LOW + 1; |
402 | 386 | ||
403 | ret = wm831x_aldo_list_voltage(rdev, vsel); | 387 | volt = wm831x_aldo_list_voltage(rdev, vsel); |
404 | if (ret < 0) | 388 | if (volt < min_uV || volt > max_uV) |
405 | return ret; | ||
406 | if (ret < min_uV || ret > max_uV) | ||
407 | return -EINVAL; | 389 | return -EINVAL; |
408 | 390 | ||
409 | *selector = vsel; | 391 | return vsel; |
410 | |||
411 | return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); | ||
412 | } | ||
413 | |||
414 | static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, | ||
415 | int min_uV, int max_uV, unsigned *selector) | ||
416 | { | ||
417 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
418 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
419 | 392 | ||
420 | return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
421 | selector); | ||
422 | } | 393 | } |
423 | 394 | ||
424 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, | 395 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, |
425 | int uV) | 396 | int uV) |
426 | { | 397 | { |
427 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 398 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
428 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; | 399 | struct wm831x *wm831x = ldo->wm831x; |
429 | unsigned int selector; | 400 | int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
401 | |||
402 | sel = wm831x_aldo_map_voltage(rdev, uV, uV); | ||
403 | if (sel < 0) | ||
404 | return sel; | ||
430 | 405 | ||
431 | return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 406 | return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel); |
432 | } | 407 | } |
433 | 408 | ||
434 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) | 409 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) |
@@ -506,8 +481,9 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev) | |||
506 | 481 | ||
507 | static struct regulator_ops wm831x_aldo_ops = { | 482 | static struct regulator_ops wm831x_aldo_ops = { |
508 | .list_voltage = wm831x_aldo_list_voltage, | 483 | .list_voltage = wm831x_aldo_list_voltage, |
484 | .map_voltage = wm831x_aldo_map_voltage, | ||
509 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 485 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
510 | .set_voltage = wm831x_aldo_set_voltage, | 486 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
511 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, | 487 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, |
512 | .get_mode = wm831x_aldo_get_mode, | 488 | .get_mode = wm831x_aldo_get_mode, |
513 | .set_mode = wm831x_aldo_set_mode, | 489 | .set_mode = wm831x_aldo_set_mode, |
@@ -628,47 +604,18 @@ static struct platform_driver wm831x_aldo_driver = { | |||
628 | 604 | ||
629 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf | 605 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf |
630 | 606 | ||
631 | static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, | ||
632 | int reg, | ||
633 | int min_uV, int max_uV, | ||
634 | unsigned *selector) | ||
635 | { | ||
636 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
637 | struct wm831x *wm831x = ldo->wm831x; | ||
638 | int vsel, ret; | ||
639 | |||
640 | vsel = (min_uV - 800000) / 50000; | ||
641 | |||
642 | ret = regulator_list_voltage_linear(rdev, vsel); | ||
643 | if (ret < 0) | ||
644 | return ret; | ||
645 | if (ret < min_uV || ret > max_uV) | ||
646 | return -EINVAL; | ||
647 | |||
648 | *selector = vsel; | ||
649 | |||
650 | return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); | ||
651 | } | ||
652 | |||
653 | static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, | ||
654 | int min_uV, int max_uV, | ||
655 | unsigned *selector) | ||
656 | { | ||
657 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
658 | int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; | ||
659 | |||
660 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, | ||
661 | selector); | ||
662 | } | ||
663 | |||
664 | static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, | 607 | static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
665 | int uV) | 608 | int uV) |
666 | { | 609 | { |
667 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 610 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
668 | int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; | 611 | struct wm831x *wm831x = ldo->wm831x; |
669 | unsigned selector; | 612 | int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; |
613 | |||
614 | sel = regulator_map_voltage_linear(rdev, uV, uV); | ||
615 | if (sel < 0) | ||
616 | return sel; | ||
670 | 617 | ||
671 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 618 | return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel); |
672 | } | 619 | } |
673 | 620 | ||
674 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | 621 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) |
@@ -690,8 +637,9 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | |||
690 | 637 | ||
691 | static struct regulator_ops wm831x_alive_ldo_ops = { | 638 | static struct regulator_ops wm831x_alive_ldo_ops = { |
692 | .list_voltage = regulator_list_voltage_linear, | 639 | .list_voltage = regulator_list_voltage_linear, |
640 | .map_voltage = regulator_map_voltage_linear, | ||
693 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 641 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
694 | .set_voltage = wm831x_alive_ldo_set_voltage, | 642 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
695 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, | 643 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, |
696 | .get_status = wm831x_alive_ldo_get_status, | 644 | .get_status = wm831x_alive_ldo_get_status, |
697 | 645 | ||
@@ -753,6 +701,7 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) | |||
753 | ldo->desc.enable_mask = 1 << id; | 701 | ldo->desc.enable_mask = 1 << id; |
754 | ldo->desc.min_uV = 800000; | 702 | ldo->desc.min_uV = 800000; |
755 | ldo->desc.uV_step = 50000; | 703 | ldo->desc.uV_step = 50000; |
704 | ldo->desc.enable_time = 1000; | ||
756 | 705 | ||
757 | config.dev = pdev->dev.parent; | 706 | config.dev = pdev->dev.parent; |
758 | if (pdata) | 707 | if (pdata) |