diff options
author | Axel Lin <axel.lin@ingics.com> | 2012-12-26 03:30:44 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-12-27 12:34:49 -0500 |
commit | b79ca051bde531f10a2d280e2c73ef17ee4d970d (patch) | |
tree | 656435b4e923ed7af44605759ee79aee36ca76dc /drivers/regulator/max8997.c | |
parent | 24bd410905919696b705a2ce1df5e1d5d4d22032 (diff) |
regulator: max8997: Convert max8997_safeout_ops to set_voltage_sel and list_voltage_table
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/max8997.c')
-rw-r--r-- | drivers/regulator/max8997.c | 76 |
1 files changed, 18 insertions, 58 deletions
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 57e8907e9293..c30424a76f8d 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c | |||
@@ -54,6 +54,13 @@ struct max8997_data { | |||
54 | u8 saved_states[MAX8997_REG_MAX]; | 54 | u8 saved_states[MAX8997_REG_MAX]; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | static const unsigned int safeoutvolt[] = { | ||
58 | 4850000, | ||
59 | 4900000, | ||
60 | 4950000, | ||
61 | 3300000, | ||
62 | }; | ||
63 | |||
57 | static inline void max8997_set_gpio(struct max8997_data *max8997) | 64 | static inline void max8997_set_gpio(struct max8997_data *max8997) |
58 | { | 65 | { |
59 | int set3 = (max8997->buck125_gpioindex) & 0x1; | 66 | int set3 = (max8997->buck125_gpioindex) & 0x1; |
@@ -130,29 +137,6 @@ static const struct voltage_map_desc *reg_voltage_map[] = { | |||
130 | [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc, | 137 | [MAX8997_CHARGER_TOPOFF] = &topoff_current_map_desc, |
131 | }; | 138 | }; |
132 | 139 | ||
133 | static int max8997_list_voltage_safeout(struct regulator_dev *rdev, | ||
134 | unsigned int selector) | ||
135 | { | ||
136 | int rid = rdev_get_id(rdev); | ||
137 | |||
138 | if (rid == MAX8997_ESAFEOUT1 || rid == MAX8997_ESAFEOUT2) { | ||
139 | switch (selector) { | ||
140 | case 0: | ||
141 | return 4850000; | ||
142 | case 1: | ||
143 | return 4900000; | ||
144 | case 2: | ||
145 | return 4950000; | ||
146 | case 3: | ||
147 | return 3300000; | ||
148 | default: | ||
149 | return -EINVAL; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return -EINVAL; | ||
154 | } | ||
155 | |||
156 | static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, | 140 | static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, |
157 | unsigned int selector) | 141 | unsigned int selector) |
158 | { | 142 | { |
@@ -722,49 +706,23 @@ out: | |||
722 | return 0; | 706 | return 0; |
723 | } | 707 | } |
724 | 708 | ||
725 | static const int safeoutvolt[] = { | ||
726 | 3300000, | ||
727 | 4850000, | ||
728 | 4900000, | ||
729 | 4950000, | ||
730 | }; | ||
731 | |||
732 | /* For SAFEOUT1 and SAFEOUT2 */ | 709 | /* For SAFEOUT1 and SAFEOUT2 */ |
733 | static int max8997_set_voltage_safeout(struct regulator_dev *rdev, | 710 | static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev, |
734 | int min_uV, int max_uV, unsigned *selector) | 711 | unsigned selector) |
735 | { | 712 | { |
736 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); | 713 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
737 | struct i2c_client *i2c = max8997->iodev->i2c; | 714 | struct i2c_client *i2c = max8997->iodev->i2c; |
738 | int rid = rdev_get_id(rdev); | 715 | int rid = rdev_get_id(rdev); |
739 | int reg, shift = 0, mask, ret; | 716 | int reg, shift = 0, mask, ret; |
740 | int i = 0; | ||
741 | u8 val; | ||
742 | 717 | ||
743 | if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2) | 718 | if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2) |
744 | return -EINVAL; | 719 | return -EINVAL; |
745 | 720 | ||
746 | for (i = 0; i < ARRAY_SIZE(safeoutvolt); i++) { | ||
747 | if (min_uV <= safeoutvolt[i] && | ||
748 | max_uV >= safeoutvolt[i]) | ||
749 | break; | ||
750 | } | ||
751 | |||
752 | if (i >= ARRAY_SIZE(safeoutvolt)) | ||
753 | return -EINVAL; | ||
754 | |||
755 | if (i == 0) | ||
756 | val = 0x3; | ||
757 | else | ||
758 | val = i - 1; | ||
759 | |||
760 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); | 721 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
761 | if (ret) | 722 | if (ret) |
762 | return ret; | 723 | return ret; |
763 | 724 | ||
764 | ret = max8997_update_reg(i2c, reg, val << shift, mask << shift); | 725 | return max8997_update_reg(i2c, reg, selector << shift, mask << shift); |
765 | *selector = val; | ||
766 | |||
767 | return ret; | ||
768 | } | 726 | } |
769 | 727 | ||
770 | static int max8997_reg_disable_suspend(struct regulator_dev *rdev) | 728 | static int max8997_reg_disable_suspend(struct regulator_dev *rdev) |
@@ -824,12 +782,12 @@ static struct regulator_ops max8997_fixedvolt_ops = { | |||
824 | }; | 782 | }; |
825 | 783 | ||
826 | static struct regulator_ops max8997_safeout_ops = { | 784 | static struct regulator_ops max8997_safeout_ops = { |
827 | .list_voltage = max8997_list_voltage_safeout, | 785 | .list_voltage = regulator_list_voltage_table, |
828 | .is_enabled = max8997_reg_is_enabled, | 786 | .is_enabled = max8997_reg_is_enabled, |
829 | .enable = max8997_reg_enable, | 787 | .enable = max8997_reg_enable, |
830 | .disable = max8997_reg_disable, | 788 | .disable = max8997_reg_disable, |
831 | .get_voltage_sel = max8997_get_voltage_sel, | 789 | .get_voltage_sel = max8997_get_voltage_sel, |
832 | .set_voltage = max8997_set_voltage_safeout, | 790 | .set_voltage_sel = max8997_set_voltage_safeout_sel, |
833 | .set_suspend_disable = max8997_reg_disable_suspend, | 791 | .set_suspend_disable = max8997_reg_disable_suspend, |
834 | }; | 792 | }; |
835 | 793 | ||
@@ -1235,13 +1193,15 @@ static int max8997_pmic_probe(struct platform_device *pdev) | |||
1235 | int id = pdata->regulators[i].id; | 1193 | int id = pdata->regulators[i].id; |
1236 | 1194 | ||
1237 | desc = reg_voltage_map[id]; | 1195 | desc = reg_voltage_map[id]; |
1238 | if (desc) | 1196 | if (desc) { |
1239 | regulators[id].n_voltages = | 1197 | regulators[id].n_voltages = |
1240 | (desc->max - desc->min) / desc->step + 1; | 1198 | (desc->max - desc->min) / desc->step + 1; |
1241 | else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) | 1199 | } else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) { |
1242 | regulators[id].n_voltages = 4; | 1200 | regulators[id].volt_table = safeoutvolt; |
1243 | else if (id == MAX8997_CHARGER_CV) | 1201 | regulators[id].n_voltages = ARRAY_SIZE(safeoutvolt); |
1202 | } else if (id == MAX8997_CHARGER_CV) { | ||
1244 | regulators[id].n_voltages = 16; | 1203 | regulators[id].n_voltages = 16; |
1204 | } | ||
1245 | 1205 | ||
1246 | config.dev = max8997->dev; | 1206 | config.dev = max8997->dev; |
1247 | config.init_data = pdata->regulators[i].initdata; | 1207 | config.init_data = pdata->regulators[i].initdata; |