aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-03-07 23:07:37 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-03-11 16:48:55 -0400
commit844775ef987aaf09a1ddea668f9acd17f9548062 (patch)
tree58bf93f23b6e7e01f49fe894e1ecac4bdad4876a
parent21c9e5f19ee68632d939f94a90fb33d3e6a111df (diff)
regulator: Simplify the implementation of tps65912_get_voltage_dcdc
Call tps65912_list_voltage_dcdc instead of duplicating the same code. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/tps65912-regulator.c112
1 files changed, 45 insertions, 67 deletions
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c
index da00d88f94b7..b685757a2b8e 100644
--- a/drivers/regulator/tps65912-regulator.c
+++ b/drivers/regulator/tps65912-regulator.c
@@ -506,66 +506,88 @@ static unsigned int tps65912_get_mode(struct regulator_dev *dev)
506 return mode; 506 return mode;
507} 507}
508 508
509static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) 509static int tps65912_list_voltage_dcdc(struct regulator_dev *dev,
510 unsigned selector)
510{ 511{
511 struct tps65912_reg *pmic = rdev_get_drvdata(dev); 512 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
512 struct tps65912 *mfd = pmic->mfd; 513 int range, voltage = 0, id = rdev_get_id(dev);
513 int id = rdev_get_id(dev), voltage = 0, range;
514 int opvsel = 0, avsel = 0, sr, vsel;
515 514
516 switch (id) { 515 switch (id) {
517 case TPS65912_REG_DCDC1: 516 case TPS65912_REG_DCDC1:
518 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP);
519 avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS);
520 range = pmic->dcdc1_range; 517 range = pmic->dcdc1_range;
521 break; 518 break;
522 case TPS65912_REG_DCDC2: 519 case TPS65912_REG_DCDC2:
523 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP);
524 avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS);
525 range = pmic->dcdc2_range; 520 range = pmic->dcdc2_range;
526 break; 521 break;
527 case TPS65912_REG_DCDC3: 522 case TPS65912_REG_DCDC3:
528 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP);
529 avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS);
530 range = pmic->dcdc3_range; 523 range = pmic->dcdc3_range;
531 break; 524 break;
532 case TPS65912_REG_DCDC4: 525 case TPS65912_REG_DCDC4:
533 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP);
534 avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS);
535 range = pmic->dcdc4_range; 526 range = pmic->dcdc4_range;
536 break; 527 break;
537 default: 528 default:
538 return -EINVAL; 529 return -EINVAL;
539 } 530 }
540 531
541 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
542 if (sr)
543 vsel = avsel;
544 else
545 vsel = opvsel;
546 vsel &= 0x3F;
547
548 switch (range) { 532 switch (range) {
549 case 0: 533 case 0:
550 /* 0.5 - 1.2875V in 12.5mV steps */ 534 /* 0.5 - 1.2875V in 12.5mV steps */
551 voltage = tps65912_vsel_to_uv_range0(vsel); 535 voltage = tps65912_vsel_to_uv_range0(selector);
552 break; 536 break;
553 case 1: 537 case 1:
554 /* 0.7 - 1.4875V in 12.5mV steps */ 538 /* 0.7 - 1.4875V in 12.5mV steps */
555 voltage = tps65912_vsel_to_uv_range1(vsel); 539 voltage = tps65912_vsel_to_uv_range1(selector);
556 break; 540 break;
557 case 2: 541 case 2:
558 /* 0.5 - 2.075V in 25mV steps */ 542 /* 0.5 - 2.075V in 25mV steps */
559 voltage = tps65912_vsel_to_uv_range2(vsel); 543 voltage = tps65912_vsel_to_uv_range2(selector);
560 break; 544 break;
561 case 3: 545 case 3:
562 /* 0.5 - 3.8V in 50mV steps */ 546 /* 0.5 - 3.8V in 50mV steps */
563 voltage = tps65912_vsel_to_uv_range3(vsel); 547 voltage = tps65912_vsel_to_uv_range3(selector);
564 break; 548 break;
565 } 549 }
566 return voltage; 550 return voltage;
567} 551}
568 552
553static int tps65912_get_voltage_dcdc(struct regulator_dev *dev)
554{
555 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
556 struct tps65912 *mfd = pmic->mfd;
557 int id = rdev_get_id(dev);
558 int opvsel = 0, avsel = 0, sr, vsel;
559
560 switch (id) {
561 case TPS65912_REG_DCDC1:
562 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC1_OP);
563 avsel = tps65912_reg_read(mfd, TPS65912_DCDC1_AVS);
564 break;
565 case TPS65912_REG_DCDC2:
566 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC2_OP);
567 avsel = tps65912_reg_read(mfd, TPS65912_DCDC2_AVS);
568 break;
569 case TPS65912_REG_DCDC3:
570 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC3_OP);
571 avsel = tps65912_reg_read(mfd, TPS65912_DCDC3_AVS);
572 break;
573 case TPS65912_REG_DCDC4:
574 opvsel = tps65912_reg_read(mfd, TPS65912_DCDC4_OP);
575 avsel = tps65912_reg_read(mfd, TPS65912_DCDC4_AVS);
576 break;
577 default:
578 return -EINVAL;
579 }
580
581 sr = (opvsel & OP_SELREG_MASK) >> OP_SELREG_SHIFT;
582 if (sr)
583 vsel = avsel;
584 else
585 vsel = opvsel;
586 vsel &= 0x3F;
587
588 return tps65912_list_voltage_dcdc(dev, vsel);
589}
590
569static int tps65912_set_voltage_dcdc(struct regulator_dev *dev, 591static int tps65912_set_voltage_dcdc(struct regulator_dev *dev,
570 unsigned selector) 592 unsigned selector)
571{ 593{
@@ -609,50 +631,6 @@ static int tps65912_set_voltage_ldo(struct regulator_dev *dev,
609 return tps65912_reg_write(mfd, reg, selector | value); 631 return tps65912_reg_write(mfd, reg, selector | value);
610} 632}
611 633
612static int tps65912_list_voltage_dcdc(struct regulator_dev *dev,
613 unsigned selector)
614{
615 struct tps65912_reg *pmic = rdev_get_drvdata(dev);
616 int range, voltage = 0, id = rdev_get_id(dev);
617
618 switch (id) {
619 case TPS65912_REG_DCDC1:
620 range = pmic->dcdc1_range;
621 break;
622 case TPS65912_REG_DCDC2:
623 range = pmic->dcdc2_range;
624 break;
625 case TPS65912_REG_DCDC3:
626 range = pmic->dcdc3_range;
627 break;
628 case TPS65912_REG_DCDC4:
629 range = pmic->dcdc4_range;
630 break;
631 default:
632 return -EINVAL;
633 }
634
635 switch (range) {
636 case 0:
637 /* 0.5 - 1.2875V in 12.5mV steps */
638 voltage = tps65912_vsel_to_uv_range0(selector);
639 break;
640 case 1:
641 /* 0.7 - 1.4875V in 12.5mV steps */
642 voltage = tps65912_vsel_to_uv_range1(selector);
643 break;
644 case 2:
645 /* 0.5 - 2.075V in 25mV steps */
646 voltage = tps65912_vsel_to_uv_range2(selector);
647 break;
648 case 3:
649 /* 0.5 - 3.8V in 50mV steps */
650 voltage = tps65912_vsel_to_uv_range3(selector);
651 break;
652 }
653 return voltage;
654}
655
656static int tps65912_list_voltage_ldo(struct regulator_dev *dev, 634static int tps65912_list_voltage_ldo(struct regulator_dev *dev,
657 unsigned selector) 635 unsigned selector)
658{ 636{