diff options
author | Mark Brown <broonie@linaro.org> | 2013-07-02 18:35:42 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2013-07-15 06:20:33 -0400 |
commit | c36a1cdf96dd3a4e6b612d6847bff6c7086e358b (patch) | |
tree | 53e4db7c7c5bea7ae342f839e990688c125086e6 | |
parent | 5ff26a14c333113967f3abe5fcb81c8e49d282c0 (diff) |
regulator: wm8350: Convert to use linear ranges
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | drivers/regulator/wm8350-regulator.c | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 7f0fa22ef2aa..5453dd0105ed 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
@@ -542,41 +542,12 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev, | |||
542 | return 0; | 542 | return 0; |
543 | } | 543 | } |
544 | 544 | ||
545 | static int wm8350_ldo_list_voltage(struct regulator_dev *rdev, | 545 | static const struct regulator_linear_range wm8350_ldo_ranges[] = { |
546 | unsigned selector) | 546 | { .min_uV = 900000, .max_uV = 1750000, .min_sel = 0, .max_sel = 15, |
547 | { | 547 | .uV_step = 50000 }, |
548 | if (selector > WM8350_LDO1_VSEL_MASK) | 548 | { .min_uV = 1800000, .max_uV = 3300000, .min_sel = 16, .max_sel = 31, |
549 | return -EINVAL; | 549 | .uV_step = 100000 }, |
550 | 550 | }; | |
551 | if (selector < 16) | ||
552 | return (selector * 50000) + 900000; | ||
553 | else | ||
554 | return ((selector - 16) * 100000) + 1800000; | ||
555 | } | ||
556 | |||
557 | static 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 | 551 | ||
581 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) | 552 | static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
582 | { | 553 | { |
@@ -603,7 +574,7 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV) | |||
603 | return -EINVAL; | 574 | return -EINVAL; |
604 | } | 575 | } |
605 | 576 | ||
606 | sel = wm8350_ldo_map_voltage(rdev, uV, uV); | 577 | sel = regulator_map_voltage_linear_range(rdev, uV, uV); |
607 | if (sel < 0) | 578 | if (sel < 0) |
608 | return -EINVAL; | 579 | return -EINVAL; |
609 | 580 | ||
@@ -998,10 +969,10 @@ static struct regulator_ops wm8350_dcdc2_5_ops = { | |||
998 | }; | 969 | }; |
999 | 970 | ||
1000 | static struct regulator_ops wm8350_ldo_ops = { | 971 | static struct regulator_ops wm8350_ldo_ops = { |
1001 | .map_voltage = wm8350_ldo_map_voltage, | 972 | .map_voltage = regulator_map_voltage_linear_range, |
1002 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | 973 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
1003 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | 974 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
1004 | .list_voltage = wm8350_ldo_list_voltage, | 975 | .list_voltage = regulator_list_voltage_linear_range, |
1005 | .enable = regulator_enable_regmap, | 976 | .enable = regulator_enable_regmap, |
1006 | .disable = regulator_disable_regmap, | 977 | .disable = regulator_disable_regmap, |
1007 | .is_enabled = regulator_is_enabled_regmap, | 978 | .is_enabled = regulator_is_enabled_regmap, |
@@ -1108,6 +1079,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1108 | .irq = WM8350_IRQ_UV_LDO1, | 1079 | .irq = WM8350_IRQ_UV_LDO1, |
1109 | .type = REGULATOR_VOLTAGE, | 1080 | .type = REGULATOR_VOLTAGE, |
1110 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, | 1081 | .n_voltages = WM8350_LDO1_VSEL_MASK + 1, |
1082 | .linear_ranges = wm8350_ldo_ranges, | ||
1083 | .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges), | ||
1111 | .vsel_reg = WM8350_LDO1_CONTROL, | 1084 | .vsel_reg = WM8350_LDO1_CONTROL, |
1112 | .vsel_mask = WM8350_LDO1_VSEL_MASK, | 1085 | .vsel_mask = WM8350_LDO1_VSEL_MASK, |
1113 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | 1086 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, |
@@ -1121,6 +1094,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1121 | .irq = WM8350_IRQ_UV_LDO2, | 1094 | .irq = WM8350_IRQ_UV_LDO2, |
1122 | .type = REGULATOR_VOLTAGE, | 1095 | .type = REGULATOR_VOLTAGE, |
1123 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, | 1096 | .n_voltages = WM8350_LDO2_VSEL_MASK + 1, |
1097 | .linear_ranges = wm8350_ldo_ranges, | ||
1098 | .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges), | ||
1124 | .vsel_reg = WM8350_LDO2_CONTROL, | 1099 | .vsel_reg = WM8350_LDO2_CONTROL, |
1125 | .vsel_mask = WM8350_LDO2_VSEL_MASK, | 1100 | .vsel_mask = WM8350_LDO2_VSEL_MASK, |
1126 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | 1101 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, |
@@ -1134,6 +1109,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1134 | .irq = WM8350_IRQ_UV_LDO3, | 1109 | .irq = WM8350_IRQ_UV_LDO3, |
1135 | .type = REGULATOR_VOLTAGE, | 1110 | .type = REGULATOR_VOLTAGE, |
1136 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, | 1111 | .n_voltages = WM8350_LDO3_VSEL_MASK + 1, |
1112 | .linear_ranges = wm8350_ldo_ranges, | ||
1113 | .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges), | ||
1137 | .vsel_reg = WM8350_LDO3_CONTROL, | 1114 | .vsel_reg = WM8350_LDO3_CONTROL, |
1138 | .vsel_mask = WM8350_LDO3_VSEL_MASK, | 1115 | .vsel_mask = WM8350_LDO3_VSEL_MASK, |
1139 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | 1116 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, |
@@ -1147,6 +1124,8 @@ static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | |||
1147 | .irq = WM8350_IRQ_UV_LDO4, | 1124 | .irq = WM8350_IRQ_UV_LDO4, |
1148 | .type = REGULATOR_VOLTAGE, | 1125 | .type = REGULATOR_VOLTAGE, |
1149 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, | 1126 | .n_voltages = WM8350_LDO4_VSEL_MASK + 1, |
1127 | .linear_ranges = wm8350_ldo_ranges, | ||
1128 | .n_linear_ranges = ARRAY_SIZE(wm8350_ldo_ranges), | ||
1150 | .vsel_reg = WM8350_LDO4_CONTROL, | 1129 | .vsel_reg = WM8350_LDO4_CONTROL, |
1151 | .vsel_mask = WM8350_LDO4_VSEL_MASK, | 1130 | .vsel_mask = WM8350_LDO4_VSEL_MASK, |
1152 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, | 1131 | .enable_reg = WM8350_DCDC_LDO_REQUESTED, |