aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/wm8350-regulator.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-12 08:10:26 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-17 15:53:58 -0400
commitc705742201260afd08b05ff84674507735e2b16b (patch)
treed946afc8f6910ea758786cb39db93999892222ad /drivers/regulator/wm8350-regulator.c
parenta967fbfaca0a979fc34c1097b37d824039a709b1 (diff)
regulator: wm8350: Reuse map_voltage() to get selector of a given uV
Reuse map_voltage() to get the selector of a given uV. Then we can remove wm8350_ldo_mvolts_to_val() and wm8350_dcdc_mvolts_to_val(). Also remove unused wm8350_dcdc_val_to_mvolts() function. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/wm8350-regulator.c')
-rw-r--r--drivers/regulator/wm8350-regulator.c127
1 files changed, 50 insertions, 77 deletions
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index c4913be3e1b4..7f0fa22ef2aa 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -108,24 +108,6 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting)
108 return -EINVAL; 108 return -EINVAL;
109} 109}
110 110
111static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
112{
113 if (mV < 1800)
114 return (mV - 900) / 50;
115 else
116 return ((mV - 1800) / 100) + 16;
117}
118
119static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
120{
121 return (val * 25) + 850;
122}
123
124static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
125{
126 return (mV - 850) / 25;
127}
128
129static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA, 111static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
130 int max_uA) 112 int max_uA)
131{ 113{
@@ -353,19 +335,10 @@ EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
353static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV) 335static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
354{ 336{
355 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 337 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
356 int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev); 338 int sel, volt_reg, dcdc = rdev_get_id(rdev);
357 u16 val; 339 u16 val;
358 340
359 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV); 341 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, uV / 1000);
360
361 if (mV && (mV < 850 || mV > 4025)) {
362 dev_err(wm8350->dev,
363 "DCDC%d suspend voltage %d mV out of range\n",
364 dcdc, mV);
365 return -EINVAL;
366 }
367 if (mV == 0)
368 mV = 850;
369 342
370 switch (dcdc) { 343 switch (dcdc) {
371 case WM8350_DCDC_1: 344 case WM8350_DCDC_1:
@@ -386,10 +359,13 @@ static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
386 return -EINVAL; 359 return -EINVAL;
387 } 360 }
388 361
362 sel = regulator_map_voltage_linear(rdev, uV, uV);
363 if (sel < 0)
364 return -EINVAL;
365
389 /* all DCDCs have same mV bits */ 366 /* all DCDCs have same mV bits */
390 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK; 367 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
391 wm8350_reg_write(wm8350, volt_reg, 368 wm8350_reg_write(wm8350, volt_reg, val | sel);
392 val | wm8350_dcdc_mvolts_to_val(mV));
393 return 0; 369 return 0;
394} 370}
395 371
@@ -566,19 +542,49 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
566 return 0; 542 return 0;
567} 543}
568 544
545static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
546 unsigned selector)
547{
548 if (selector > WM8350_LDO1_VSEL_MASK)
549 return -EINVAL;
550
551 if (selector < 16)
552 return (selector * 50000) + 900000;
553 else
554 return ((selector - 16) * 100000) + 1800000;
555}
556
557static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
558 int max_uV)
559{
560 int volt, sel;
561 int min_mV = min_uV / 1000;
562 int max_mV = max_uV / 1000;
563
564 if (min_mV < 900 || min_mV > 3300)
565 return -EINVAL;
566 if (max_mV < 900 || max_mV > 3300)
567 return -EINVAL;
568
569 if (min_mV < 1800) /* step size is 50mV < 1800mV */
570 sel = DIV_ROUND_UP(min_uV - 900, 50);
571 else /* step size is 100mV > 1800mV */
572 sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;
573
574 volt = wm8350_ldo_list_voltage(rdev, sel);
575 if (volt < min_uV || volt > max_uV)
576 return -EINVAL;
577
578 return sel;
579}
580
569static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) 581static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
570{ 582{
571 struct wm8350 *wm8350 = rdev_get_drvdata(rdev); 583 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
572 int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev); 584 int sel, volt_reg, ldo = rdev_get_id(rdev);
573 u16 val; 585 u16 val;
574 586
575 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV); 587 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, uV / 1000);
576
577 if (mV < 900 || mV > 3300) {
578 dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
579 ldo, mV);
580 return -EINVAL;
581 }
582 588
583 switch (ldo) { 589 switch (ldo) {
584 case WM8350_LDO_1: 590 case WM8350_LDO_1:
@@ -597,10 +603,13 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
597 return -EINVAL; 603 return -EINVAL;
598 } 604 }
599 605
606 sel = wm8350_ldo_map_voltage(rdev, uV, uV);
607 if (sel < 0)
608 return -EINVAL;
609
600 /* all LDOs have same mV bits */ 610 /* all LDOs have same mV bits */
601 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK; 611 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
602 wm8350_reg_write(wm8350, volt_reg, 612 wm8350_reg_write(wm8350, volt_reg, val | sel);
603 val | wm8350_ldo_mvolts_to_val(mV));
604 return 0; 613 return 0;
605} 614}
606 615
@@ -662,42 +671,6 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
662 return 0; 671 return 0;
663} 672}
664 673
665static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
666 unsigned selector)
667{
668 if (selector > WM8350_LDO1_VSEL_MASK)
669 return -EINVAL;
670
671 if (selector < 16)
672 return (selector * 50000) + 900000;
673 else
674 return ((selector - 16) * 100000) + 1800000;
675}
676
677static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
678 int max_uV)
679{
680 int volt, sel;
681 int min_mV = min_uV / 1000;
682 int max_mV = max_uV / 1000;
683
684 if (min_mV < 900 || min_mV > 3300)
685 return -EINVAL;
686 if (max_mV < 900 || max_mV > 3300)
687 return -EINVAL;
688
689 if (min_mV < 1800) /* step size is 50mV < 1800mV */
690 sel = DIV_ROUND_UP(min_uV - 900, 50);
691 else /* step size is 100mV > 1800mV */
692 sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;
693
694 volt = wm8350_ldo_list_voltage(rdev, sel);
695 if (volt < min_uV || volt > max_uV)
696 return -EINVAL;
697
698 return sel;
699}
700
701int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start, 674int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
702 u16 stop, u16 fault) 675 u16 stop, u16 fault)
703{ 676{