aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-02-19 07:42:49 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-02-19 07:42:49 -0500
commit6a244cadb00fa1abc31dcae6f771f4a7b9e86a1b (patch)
tree42136021e803a831e42e1098f6846c07f705eb3d /drivers/regulator
parent1fe230175ebfefe381e8d744e30baa39b4917f70 (diff)
parentb79ca051bde531f10a2d280e2c73ef17ee4d970d (diff)
Merge remote-tracking branch 'regulator/topic/max8997' into regulator-next
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/max8997.c81
1 files changed, 20 insertions, 61 deletions
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 836908ce505e..5556a15743fd 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
57static const unsigned int safeoutvolt[] = {
58 4850000,
59 4900000,
60 4950000,
61 3300000,
62};
63
57static inline void max8997_set_gpio(struct max8997_data *max8997) 64static 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
133static 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
156static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev, 140static int max8997_list_voltage_charger_cv(struct regulator_dev *rdev,
157 unsigned int selector) 141 unsigned int selector)
158{ 142{
@@ -522,7 +506,7 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev,
522 return ret; 506 return ret;
523} 507}
524 508
525static int max8997_set_voltage_ldobuck_time_sel(struct regulator_dev *rdev, 509static int max8997_set_voltage_buck_time_sel(struct regulator_dev *rdev,
526 unsigned int old_selector, 510 unsigned int old_selector,
527 unsigned int new_selector) 511 unsigned int new_selector)
528{ 512{
@@ -720,49 +704,23 @@ out:
720 return 0; 704 return 0;
721} 705}
722 706
723static const int safeoutvolt[] = {
724 3300000,
725 4850000,
726 4900000,
727 4950000,
728};
729
730/* For SAFEOUT1 and SAFEOUT2 */ 707/* For SAFEOUT1 and SAFEOUT2 */
731static int max8997_set_voltage_safeout(struct regulator_dev *rdev, 708static int max8997_set_voltage_safeout_sel(struct regulator_dev *rdev,
732 int min_uV, int max_uV, unsigned *selector) 709 unsigned selector)
733{ 710{
734 struct max8997_data *max8997 = rdev_get_drvdata(rdev); 711 struct max8997_data *max8997 = rdev_get_drvdata(rdev);
735 struct i2c_client *i2c = max8997->iodev->i2c; 712 struct i2c_client *i2c = max8997->iodev->i2c;
736 int rid = rdev_get_id(rdev); 713 int rid = rdev_get_id(rdev);
737 int reg, shift = 0, mask, ret; 714 int reg, shift = 0, mask, ret;
738 int i = 0;
739 u8 val;
740 715
741 if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2) 716 if (rid != MAX8997_ESAFEOUT1 && rid != MAX8997_ESAFEOUT2)
742 return -EINVAL; 717 return -EINVAL;
743 718
744 for (i = 0; i < ARRAY_SIZE(safeoutvolt); i++) {
745 if (min_uV <= safeoutvolt[i] &&
746 max_uV >= safeoutvolt[i])
747 break;
748 }
749
750 if (i >= ARRAY_SIZE(safeoutvolt))
751 return -EINVAL;
752
753 if (i == 0)
754 val = 0x3;
755 else
756 val = i - 1;
757
758 ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask); 719 ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask);
759 if (ret) 720 if (ret)
760 return ret; 721 return ret;
761 722
762 ret = max8997_update_reg(i2c, reg, val << shift, mask << shift); 723 return max8997_update_reg(i2c, reg, selector << shift, mask << shift);
763 *selector = val;
764
765 return ret;
766} 724}
767 725
768static int max8997_reg_disable_suspend(struct regulator_dev *rdev) 726static int max8997_reg_disable_suspend(struct regulator_dev *rdev)
@@ -799,7 +757,6 @@ static struct regulator_ops max8997_ldo_ops = {
799 .disable = max8997_reg_disable, 757 .disable = max8997_reg_disable,
800 .get_voltage_sel = max8997_get_voltage_sel, 758 .get_voltage_sel = max8997_get_voltage_sel,
801 .set_voltage = max8997_set_voltage_ldobuck, 759 .set_voltage = max8997_set_voltage_ldobuck,
802 .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel,
803 .set_suspend_disable = max8997_reg_disable_suspend, 760 .set_suspend_disable = max8997_reg_disable_suspend,
804}; 761};
805 762
@@ -810,7 +767,7 @@ static struct regulator_ops max8997_buck_ops = {
810 .disable = max8997_reg_disable, 767 .disable = max8997_reg_disable,
811 .get_voltage_sel = max8997_get_voltage_sel, 768 .get_voltage_sel = max8997_get_voltage_sel,
812 .set_voltage = max8997_set_voltage_buck, 769 .set_voltage = max8997_set_voltage_buck,
813 .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel, 770 .set_voltage_time_sel = max8997_set_voltage_buck_time_sel,
814 .set_suspend_disable = max8997_reg_disable_suspend, 771 .set_suspend_disable = max8997_reg_disable_suspend,
815}; 772};
816 773
@@ -823,12 +780,12 @@ static struct regulator_ops max8997_fixedvolt_ops = {
823}; 780};
824 781
825static struct regulator_ops max8997_safeout_ops = { 782static struct regulator_ops max8997_safeout_ops = {
826 .list_voltage = max8997_list_voltage_safeout, 783 .list_voltage = regulator_list_voltage_table,
827 .is_enabled = max8997_reg_is_enabled, 784 .is_enabled = max8997_reg_is_enabled,
828 .enable = max8997_reg_enable, 785 .enable = max8997_reg_enable,
829 .disable = max8997_reg_disable, 786 .disable = max8997_reg_disable,
830 .get_voltage_sel = max8997_get_voltage_sel, 787 .get_voltage_sel = max8997_get_voltage_sel,
831 .set_voltage = max8997_set_voltage_safeout, 788 .set_voltage_sel = max8997_set_voltage_safeout_sel,
832 .set_suspend_disable = max8997_reg_disable_suspend, 789 .set_suspend_disable = max8997_reg_disable_suspend,
833}; 790};
834 791
@@ -1233,13 +1190,15 @@ static int max8997_pmic_probe(struct platform_device *pdev)
1233 int id = pdata->regulators[i].id; 1190 int id = pdata->regulators[i].id;
1234 1191
1235 desc = reg_voltage_map[id]; 1192 desc = reg_voltage_map[id];
1236 if (desc) 1193 if (desc) {
1237 regulators[id].n_voltages = 1194 regulators[id].n_voltages =
1238 (desc->max - desc->min) / desc->step + 1; 1195 (desc->max - desc->min) / desc->step + 1;
1239 else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) 1196 } else if (id == MAX8997_ESAFEOUT1 || id == MAX8997_ESAFEOUT2) {
1240 regulators[id].n_voltages = 4; 1197 regulators[id].volt_table = safeoutvolt;
1241 else if (id == MAX8997_CHARGER_CV) 1198 regulators[id].n_voltages = ARRAY_SIZE(safeoutvolt);
1199 } else if (id == MAX8997_CHARGER_CV) {
1242 regulators[id].n_voltages = 16; 1200 regulators[id].n_voltages = 16;
1201 }
1243 1202
1244 config.dev = max8997->dev; 1203 config.dev = max8997->dev;
1245 config.init_data = pdata->regulators[i].initdata; 1204 config.init_data = pdata->regulators[i].initdata;