aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@linaro.org>2013-09-01 08:50:12 -0400
committerMark Brown <broonie@linaro.org>2013-09-01 08:50:12 -0400
commitbca3523b2283ac6e81e37d56ddebef1786ac6557 (patch)
tree502051d5631779c30efb9d401d2e29832df85c31
parent099c60622417c25b5454061a54cedf5b5132650d (diff)
parent6290d60656e9f4f5a0071bafa798370ab35978a0 (diff)
Merge remote-tracking branch 'regulator/topic/linear-range' into regulator-next
-rw-r--r--drivers/regulator/tps65217-regulator.c182
-rw-r--r--include/linux/mfd/tps65217.h19
2 files changed, 37 insertions, 164 deletions
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c
index 2df4616621f5..90861d68a0b0 100644
--- a/drivers/regulator/tps65217-regulator.c
+++ b/drivers/regulator/tps65217-regulator.c
@@ -27,7 +27,7 @@
27#include <linux/regulator/machine.h> 27#include <linux/regulator/machine.h>
28#include <linux/mfd/tps65217.h> 28#include <linux/mfd/tps65217.h>
29 29
30#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t) \ 30#define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t, _lr, _nlr) \
31 { \ 31 { \
32 .name = _name, \ 32 .name = _name, \
33 .id = _id, \ 33 .id = _id, \
@@ -40,17 +40,10 @@
40 .enable_reg = TPS65217_REG_ENABLE, \ 40 .enable_reg = TPS65217_REG_ENABLE, \
41 .enable_mask = _em, \ 41 .enable_mask = _em, \
42 .volt_table = _t, \ 42 .volt_table = _t, \
43 .linear_ranges = _lr, \
44 .n_linear_ranges = _nlr, \
43 } \ 45 } \
44 46
45#define TPS65217_INFO(_nm, _min, _max, _f1, _f2) \
46 { \
47 .name = _nm, \
48 .min_uV = _min, \
49 .max_uV = _max, \
50 .vsel_to_uv = _f1, \
51 .uv_to_vsel = _f2, \
52 }
53
54static const unsigned int LDO1_VSEL_table[] = { 47static const unsigned int LDO1_VSEL_table[] = {
55 1000000, 1100000, 1200000, 1250000, 48 1000000, 1100000, 1200000, 1250000,
56 1300000, 1350000, 1400000, 1500000, 49 1300000, 1350000, 1400000, 1500000,
@@ -58,88 +51,26 @@ static const unsigned int LDO1_VSEL_table[] = {
58 2800000, 3000000, 3100000, 3300000, 51 2800000, 3000000, 3100000, 3300000,
59}; 52};
60 53
61static int tps65217_vsel_to_uv1(unsigned int vsel) 54static const struct regulator_linear_range tps65217_uv1_ranges[] = {
62{ 55 { .min_uV = 900000, .max_uV = 1500000, .min_sel = 0, .max_sel = 24,
63 int uV = 0; 56 .uV_step = 25000 },
64 57 { .min_uV = 1550000, .max_uV = 1800000, .min_sel = 25, .max_sel = 30,
65 if (vsel > 63) 58 .uV_step = 50000 },
66 return -EINVAL; 59 { .min_uV = 1850000, .max_uV = 2900000, .min_sel = 31, .max_sel = 52,
67 60 .uV_step = 50000 },
68 if (vsel <= 24) 61 { .min_uV = 3000000, .max_uV = 3200000, .min_sel = 53, .max_sel = 55,
69 uV = vsel * 25000 + 900000; 62 .uV_step = 100000 },
70 else if (vsel <= 52) 63 { .min_uV = 3300000, .max_uV = 3300000, .min_sel = 56, .max_sel = 62,
71 uV = (vsel - 24) * 50000 + 1500000; 64 .uV_step = 0 },
72 else if (vsel < 56) 65};
73 uV = (vsel - 52) * 100000 + 2900000;
74 else
75 uV = 3300000;
76
77 return uV;
78}
79
80static int tps65217_uv_to_vsel1(int uV, unsigned int *vsel)
81{
82 if (uV < 0 || uV > 3300000)
83 return -EINVAL;
84
85 if (uV <= 1500000)
86 *vsel = DIV_ROUND_UP(uV - 900000, 25000);
87 else if (uV <= 2900000)
88 *vsel = 24 + DIV_ROUND_UP(uV - 1500000, 50000);
89 else if (uV < 3300000)
90 *vsel = 52 + DIV_ROUND_UP(uV - 2900000, 100000);
91 else
92 *vsel = 56;
93
94 return 0;
95}
96
97static int tps65217_vsel_to_uv2(unsigned int vsel)
98{
99 int uV = 0;
100
101 if (vsel > 31)
102 return -EINVAL;
103
104 if (vsel <= 8)
105 uV = vsel * 50000 + 1500000;
106 else if (vsel <= 13)
107 uV = (vsel - 8) * 100000 + 1900000;
108 else
109 uV = (vsel - 13) * 50000 + 2400000;
110
111 return uV;
112}
113
114static int tps65217_uv_to_vsel2(int uV, unsigned int *vsel)
115{
116 if (uV < 0 || uV > 3300000)
117 return -EINVAL;
118
119 if (uV <= 1900000)
120 *vsel = DIV_ROUND_UP(uV - 1500000, 50000);
121 else if (uV <= 2400000)
122 *vsel = 8 + DIV_ROUND_UP(uV - 1900000, 100000);
123 else
124 *vsel = 13 + DIV_ROUND_UP(uV - 2400000, 50000);
125
126 return 0;
127}
128 66
129static struct tps_info tps65217_pmic_regs[] = { 67static const struct regulator_linear_range tps65217_uv2_ranges[] = {
130 TPS65217_INFO("DCDC1", 900000, 1800000, tps65217_vsel_to_uv1, 68 { .min_uV = 1500000, .max_uV = 1900000, .min_sel = 0, .max_sel = 8,
131 tps65217_uv_to_vsel1), 69 .uV_step = 50000 },
132 TPS65217_INFO("DCDC2", 900000, 3300000, tps65217_vsel_to_uv1, 70 { .min_uV = 2000000, .max_uV = 2400000, .min_sel = 9, .max_sel = 13,
133 tps65217_uv_to_vsel1), 71 .uV_step = 100000 },
134 TPS65217_INFO("DCDC3", 900000, 1500000, tps65217_vsel_to_uv1, 72 { .min_uV = 2450000, .max_uV = 3300000, .min_sel = 14, .max_sel = 31,
135 tps65217_uv_to_vsel1), 73 .uV_step = 50000 },
136 TPS65217_INFO("LDO1", 1000000, 3300000, NULL, NULL),
137 TPS65217_INFO("LDO2", 900000, 3300000, tps65217_vsel_to_uv1,
138 tps65217_uv_to_vsel1),
139 TPS65217_INFO("LDO3", 1800000, 3300000, tps65217_vsel_to_uv2,
140 tps65217_uv_to_vsel2),
141 TPS65217_INFO("LDO4", 1800000, 3300000, tps65217_vsel_to_uv2,
142 tps65217_uv_to_vsel2),
143}; 74};
144 75
145static int tps65217_pmic_enable(struct regulator_dev *dev) 76static int tps65217_pmic_enable(struct regulator_dev *dev)
@@ -192,49 +123,6 @@ static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev,
192 return ret; 123 return ret;
193} 124}
194 125
195static int tps65217_pmic_map_voltage(struct regulator_dev *dev,
196 int min_uV, int max_uV)
197{
198
199 struct tps65217 *tps = rdev_get_drvdata(dev);
200 unsigned int sel, rid = rdev_get_id(dev);
201 int ret;
202
203 /* LDO1 uses regulator_map_voltage_iterate() */
204 if (rid == TPS65217_LDO_1)
205 return -EINVAL;
206
207 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
208 return -EINVAL;
209
210 if (min_uV < tps->info[rid]->min_uV)
211 min_uV = tps->info[rid]->min_uV;
212
213 if (max_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV)
214 return -EINVAL;
215
216 ret = tps->info[rid]->uv_to_vsel(min_uV, &sel);
217 if (ret)
218 return ret;
219
220 return sel;
221}
222
223static int tps65217_pmic_list_voltage(struct regulator_dev *dev,
224 unsigned selector)
225{
226 struct tps65217 *tps = rdev_get_drvdata(dev);
227 unsigned int rid = rdev_get_id(dev);
228
229 if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4)
230 return -EINVAL;
231
232 if (selector >= dev->desc->n_voltages)
233 return -EINVAL;
234
235 return tps->info[rid]->vsel_to_uv(selector);
236}
237
238/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ 126/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
239static struct regulator_ops tps65217_pmic_ops = { 127static struct regulator_ops tps65217_pmic_ops = {
240 .is_enabled = regulator_is_enabled_regmap, 128 .is_enabled = regulator_is_enabled_regmap,
@@ -242,8 +130,8 @@ static struct regulator_ops tps65217_pmic_ops = {
242 .disable = tps65217_pmic_disable, 130 .disable = tps65217_pmic_disable,
243 .get_voltage_sel = regulator_get_voltage_sel_regmap, 131 .get_voltage_sel = regulator_get_voltage_sel_regmap,
244 .set_voltage_sel = tps65217_pmic_set_voltage_sel, 132 .set_voltage_sel = tps65217_pmic_set_voltage_sel,
245 .list_voltage = tps65217_pmic_list_voltage, 133 .list_voltage = regulator_list_voltage_linear_range,
246 .map_voltage = tps65217_pmic_map_voltage, 134 .map_voltage = regulator_map_voltage_linear_range,
247}; 135};
248 136
249/* Operations permitted on LDO1 */ 137/* Operations permitted on LDO1 */
@@ -259,27 +147,33 @@ static struct regulator_ops tps65217_pmic_ldo1_ops = {
259static const struct regulator_desc regulators[] = { 147static const struct regulator_desc regulators[] = {
260 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64, 148 TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64,
261 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK, 149 TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK,
262 TPS65217_ENABLE_DC1_EN, NULL), 150 TPS65217_ENABLE_DC1_EN, NULL, tps65217_uv1_ranges,
151 2), /* DCDC1 voltage range: 900000 ~ 1800000 */
263 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64, 152 TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64,
264 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK, 153 TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK,
265 TPS65217_ENABLE_DC2_EN, NULL), 154 TPS65217_ENABLE_DC2_EN, NULL, tps65217_uv1_ranges,
155 ARRAY_SIZE(tps65217_uv1_ranges)),
266 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64, 156 TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64,
267 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK, 157 TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK,
268 TPS65217_ENABLE_DC3_EN, NULL), 158 TPS65217_ENABLE_DC3_EN, NULL, tps65217_uv1_ranges,
159 1), /* DCDC3 voltage range: 900000 ~ 1500000 */
269 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16, 160 TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16,
270 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK, 161 TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK,
271 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table), 162 TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table, NULL, 0),
272 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64, 163 TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64,
273 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK, 164 TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK,
274 TPS65217_ENABLE_LDO2_EN, NULL), 165 TPS65217_ENABLE_LDO2_EN, NULL, tps65217_uv1_ranges,
166 ARRAY_SIZE(tps65217_uv1_ranges)),
275 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32, 167 TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32,
276 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, 168 TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK,
277 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, 169 TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN,
278 NULL), 170 NULL, tps65217_uv2_ranges,
171 ARRAY_SIZE(tps65217_uv2_ranges)),
279 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32, 172 TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32,
280 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, 173 TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK,
281 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, 174 TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN,
282 NULL), 175 NULL, tps65217_uv2_ranges,
176 ARRAY_SIZE(tps65217_uv2_ranges)),
283}; 177};
284 178
285#ifdef CONFIG_OF 179#ifdef CONFIG_OF
@@ -368,8 +262,6 @@ static int tps65217_regulator_probe(struct platform_device *pdev)
368 continue; 262 continue;
369 263
370 /* Register the regulators */ 264 /* Register the regulators */
371 tps->info[i] = &tps65217_pmic_regs[i];
372
373 config.dev = tps->dev; 265 config.dev = tps->dev;
374 config.init_data = reg_data; 266 config.init_data = reg_data;
375 config.driver_data = tps; 267 config.driver_data = tps;
diff --git a/include/linux/mfd/tps65217.h b/include/linux/mfd/tps65217.h
index 29eab2bd3dfa..a5a7f0130e96 100644
--- a/include/linux/mfd/tps65217.h
+++ b/include/linux/mfd/tps65217.h
@@ -244,24 +244,6 @@ struct tps65217_board {
244}; 244};
245 245
246/** 246/**
247 * struct tps_info - packages regulator constraints
248 * @name: Voltage regulator name
249 * @min_uV: minimum micro volts
250 * @max_uV: minimum micro volts
251 * @vsel_to_uv: Function pointer to get voltage from selector
252 * @uv_to_vsel: Function pointer to get selector from voltage
253 *
254 * This data is used to check the regualtor voltage limits while setting.
255 */
256struct tps_info {
257 const char *name;
258 int min_uV;
259 int max_uV;
260 int (*vsel_to_uv)(unsigned int vsel);
261 int (*uv_to_vsel)(int uV, unsigned int *vsel);
262};
263
264/**
265 * struct tps65217 - tps65217 sub-driver chip access routines 247 * struct tps65217 - tps65217 sub-driver chip access routines
266 * 248 *
267 * Device data may be used to access the TPS65217 chip 249 * Device data may be used to access the TPS65217 chip
@@ -273,7 +255,6 @@ struct tps65217 {
273 unsigned int id; 255 unsigned int id;
274 struct regulator_desc desc[TPS65217_NUM_REGULATOR]; 256 struct regulator_desc desc[TPS65217_NUM_REGULATOR];
275 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR]; 257 struct regulator_dev *rdev[TPS65217_NUM_REGULATOR];
276 struct tps_info *info[TPS65217_NUM_REGULATOR];
277 struct regmap *regmap; 258 struct regmap *regmap;
278}; 259};
279 260