aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/tps65023-regulator.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-19 05:12:18 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-19 07:06:26 -0400
commitba3bd8a301c76838faded10dbe2ecdfdc2eb5d7e (patch)
tree15584b5813a1286b95bb6b7df3d0d9cef7a5199f /drivers/regulator/tps65023-regulator.c
parent2c19ad43d1a4b0e376a0c764e3c2350afd018fac (diff)
regulator: tps65023: Convert to regulator_list_voltage_table
In current mapping table settings, min_uV/max_uV are always equal to volt_table[0] and volt_table[table_len -1]. Thus remove min_uV and max_uV from struct tps_info. The table based mapping with table_len == 1 means fixed voltage. So we don't need fixed flag to differentiate if it is fixed or not. This patch adds DCDC_FIXED_3300000_VSEL_table and DCDC_FIXED_1800000_VSEL_table for fixed voltage cases. So we can convert tps65023_dcdc_ops to regulator_list_voltage_table. This makes the code simpler. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/tps65023-regulator.c')
-rw-r--r--drivers/regulator/tps65023-regulator.c153
1 files changed, 49 insertions, 104 deletions
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index df8b70d76f9e..45f4eeb221f7 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -91,48 +91,53 @@
91#define TPS65023_MAX_REG_ID TPS65023_LDO_2 91#define TPS65023_MAX_REG_ID TPS65023_LDO_2
92 92
93/* Supported voltage values for regulators */ 93/* Supported voltage values for regulators */
94static const u16 VCORE_VSEL_table[] = { 94static const unsigned int VCORE_VSEL_table[] = {
95 800, 825, 850, 875, 95 800000, 825000, 850000, 875000,
96 900, 925, 950, 975, 96 900000, 925000, 950000, 975000,
97 1000, 1025, 1050, 1075, 97 1000000, 1025000, 1050000, 1075000,
98 1100, 1125, 1150, 1175, 98 1100000, 1125000, 1150000, 1175000,
99 1200, 1225, 1250, 1275, 99 1200000, 1225000, 1250000, 1275000,
100 1300, 1325, 1350, 1375, 100 1300000, 1325000, 1350000, 1375000,
101 1400, 1425, 1450, 1475, 101 1400000, 1425000, 1450000, 1475000,
102 1500, 1525, 1550, 1600, 102 1500000, 1525000, 1550000, 1600000,
103};
104
105static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = {
106 3300000,
107};
108
109static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = {
110 1800000,
103}; 111};
104 112
105/* Supported voltage values for LDO regulators for tps65020 */ 113/* Supported voltage values for LDO regulators for tps65020 */
106static const u16 TPS65020_LDO1_VSEL_table[] = { 114static const unsigned int TPS65020_LDO1_VSEL_table[] = {
107 1000, 1050, 1100, 1300, 115 1000000, 1050000, 1100000, 1300000,
108 1800, 2500, 3000, 3300, 116 1800000, 2500000, 3000000, 3300000,
109}; 117};
110 118
111static const u16 TPS65020_LDO2_VSEL_table[] = { 119static const unsigned int TPS65020_LDO2_VSEL_table[] = {
112 1000, 1050, 1100, 1300, 120 1000000, 1050000, 1100000, 1300000,
113 1800, 2500, 3000, 3300, 121 1800000, 2500000, 3000000, 3300000,
114}; 122};
115 123
116/* Supported voltage values for LDO regulators 124/* Supported voltage values for LDO regulators
117 * for tps65021 and tps65023 */ 125 * for tps65021 and tps65023 */
118static const u16 TPS65023_LDO1_VSEL_table[] = { 126static const unsigned int TPS65023_LDO1_VSEL_table[] = {
119 1000, 1100, 1300, 1800, 127 1000000, 1100000, 1300000, 1800000,
120 2200, 2600, 2800, 3150, 128 2200000, 2600000, 2800000, 3150000,
121}; 129};
122 130
123static const u16 TPS65023_LDO2_VSEL_table[] = { 131static const unsigned int TPS65023_LDO2_VSEL_table[] = {
124 1050, 1200, 1300, 1800, 132 1050000, 1200000, 1300000, 1800000,
125 2500, 2800, 3000, 3300, 133 2500000, 2800000, 3000000, 3300000,
126}; 134};
127 135
128/* Regulator specific details */ 136/* Regulator specific details */
129struct tps_info { 137struct tps_info {
130 const char *name; 138 const char *name;
131 unsigned min_uV;
132 unsigned max_uV;
133 bool fixed;
134 u8 table_len; 139 u8 table_len;
135 const u16 *table; 140 const unsigned int *table;
136}; 141};
137 142
138/* PMIC details */ 143/* PMIC details */
@@ -164,9 +169,9 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
164 if (ret != 0) 169 if (ret != 0)
165 return ret; 170 return ret;
166 data &= (tps->info[dcdc]->table_len - 1); 171 data &= (tps->info[dcdc]->table_len - 1);
167 return tps->info[dcdc]->table[data] * 1000; 172 return tps->info[dcdc]->table[data];
168 } else 173 } else
169 return tps->info[dcdc]->min_uV; 174 return tps->info[dcdc]->table[0];
170} 175}
171 176
172static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, 177static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
@@ -208,7 +213,7 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
208 213
209 data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)); 214 data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1));
210 data &= (tps->info[ldo]->table_len - 1); 215 data &= (tps->info[ldo]->table_len - 1);
211 return tps->info[ldo]->table[data] * 1000; 216 return tps->info[ldo]->table[data];
212} 217}
213 218
214static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev, 219static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev,
@@ -222,39 +227,6 @@ static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev,
222 selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index)); 227 selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index));
223} 228}
224 229
225static int tps65023_dcdc_list_voltage(struct regulator_dev *dev,
226 unsigned selector)
227{
228 struct tps_pmic *tps = rdev_get_drvdata(dev);
229 int dcdc = rdev_get_id(dev);
230
231 if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
232 return -EINVAL;
233
234 if (dcdc == tps->core_regulator) {
235 if (selector >= tps->info[dcdc]->table_len)
236 return -EINVAL;
237 else
238 return tps->info[dcdc]->table[selector] * 1000;
239 } else
240 return tps->info[dcdc]->min_uV;
241}
242
243static int tps65023_ldo_list_voltage(struct regulator_dev *dev,
244 unsigned selector)
245{
246 struct tps_pmic *tps = rdev_get_drvdata(dev);
247 int ldo = rdev_get_id(dev);
248
249 if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2)
250 return -EINVAL;
251
252 if (selector >= tps->info[ldo]->table_len)
253 return -EINVAL;
254 else
255 return tps->info[ldo]->table[selector] * 1000;
256}
257
258/* Operations permitted on VDCDCx */ 230/* Operations permitted on VDCDCx */
259static struct regulator_ops tps65023_dcdc_ops = { 231static struct regulator_ops tps65023_dcdc_ops = {
260 .is_enabled = regulator_is_enabled_regmap, 232 .is_enabled = regulator_is_enabled_regmap,
@@ -262,7 +234,7 @@ static struct regulator_ops tps65023_dcdc_ops = {
262 .disable = regulator_disable_regmap, 234 .disable = regulator_disable_regmap,
263 .get_voltage = tps65023_dcdc_get_voltage, 235 .get_voltage = tps65023_dcdc_get_voltage,
264 .set_voltage_sel = tps65023_dcdc_set_voltage_sel, 236 .set_voltage_sel = tps65023_dcdc_set_voltage_sel,
265 .list_voltage = tps65023_dcdc_list_voltage, 237 .list_voltage = regulator_list_voltage_table,
266}; 238};
267 239
268/* Operations permitted on LDOx */ 240/* Operations permitted on LDOx */
@@ -272,7 +244,7 @@ static struct regulator_ops tps65023_ldo_ops = {
272 .disable = regulator_disable_regmap, 244 .disable = regulator_disable_regmap,
273 .get_voltage = tps65023_ldo_get_voltage, 245 .get_voltage = tps65023_ldo_get_voltage,
274 .set_voltage_sel = tps65023_ldo_set_voltage_sel, 246 .set_voltage_sel = tps65023_ldo_set_voltage_sel,
275 .list_voltage = tps65023_ldo_list_voltage, 247 .list_voltage = regulator_list_voltage_table,
276}; 248};
277 249
278static struct regmap_config tps65023_regmap_config = { 250static struct regmap_config tps65023_regmap_config = {
@@ -324,10 +296,8 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
324 296
325 tps->desc[i].name = info->name; 297 tps->desc[i].name = info->name;
326 tps->desc[i].id = i; 298 tps->desc[i].id = i;
327 if (info->fixed) 299 tps->desc[i].n_voltages = info->table_len;
328 tps->desc[i].n_voltages = 1; 300 tps->desc[i].volt_table = info->table;
329 else
330 tps->desc[i].n_voltages = info->table_len;
331 tps->desc[i].ops = (i > TPS65023_DCDC_3 ? 301 tps->desc[i].ops = (i > TPS65023_DCDC_3 ?
332 &tps65023_ldo_ops : &tps65023_dcdc_ops); 302 &tps65023_ldo_ops : &tps65023_dcdc_ops);
333 tps->desc[i].type = REGULATOR_VOLTAGE; 303 tps->desc[i].type = REGULATOR_VOLTAGE;
@@ -387,35 +357,26 @@ static int __devexit tps_65023_remove(struct i2c_client *client)
387static const struct tps_info tps65020_regs[] = { 357static const struct tps_info tps65020_regs[] = {
388 { 358 {
389 .name = "VDCDC1", 359 .name = "VDCDC1",
390 .min_uV = 3300000, 360 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
391 .max_uV = 3300000, 361 .table = DCDC_FIXED_3300000_VSEL_table,
392 .fixed = 1,
393 }, 362 },
394 { 363 {
395 .name = "VDCDC2", 364 .name = "VDCDC2",
396 .min_uV = 1800000, 365 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
397 .max_uV = 1800000, 366 .table = DCDC_FIXED_1800000_VSEL_table,
398 .fixed = 1,
399 }, 367 },
400 { 368 {
401 .name = "VDCDC3", 369 .name = "VDCDC3",
402 .min_uV = 800000,
403 .max_uV = 1600000,
404 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 370 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
405 .table = VCORE_VSEL_table, 371 .table = VCORE_VSEL_table,
406 }, 372 },
407
408 { 373 {
409 .name = "LDO1", 374 .name = "LDO1",
410 .min_uV = 1000000,
411 .max_uV = 3150000,
412 .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), 375 .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table),
413 .table = TPS65020_LDO1_VSEL_table, 376 .table = TPS65020_LDO1_VSEL_table,
414 }, 377 },
415 { 378 {
416 .name = "LDO2", 379 .name = "LDO2",
417 .min_uV = 1050000,
418 .max_uV = 3300000,
419 .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), 380 .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table),
420 .table = TPS65020_LDO2_VSEL_table, 381 .table = TPS65020_LDO2_VSEL_table,
421 }, 382 },
@@ -424,34 +385,26 @@ static const struct tps_info tps65020_regs[] = {
424static const struct tps_info tps65021_regs[] = { 385static const struct tps_info tps65021_regs[] = {
425 { 386 {
426 .name = "VDCDC1", 387 .name = "VDCDC1",
427 .min_uV = 3300000, 388 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
428 .max_uV = 3300000, 389 .table = DCDC_FIXED_3300000_VSEL_table,
429 .fixed = 1,
430 }, 390 },
431 { 391 {
432 .name = "VDCDC2", 392 .name = "VDCDC2",
433 .min_uV = 1800000, 393 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
434 .max_uV = 1800000, 394 .table = DCDC_FIXED_1800000_VSEL_table,
435 .fixed = 1,
436 }, 395 },
437 { 396 {
438 .name = "VDCDC3", 397 .name = "VDCDC3",
439 .min_uV = 800000,
440 .max_uV = 1600000,
441 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 398 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
442 .table = VCORE_VSEL_table, 399 .table = VCORE_VSEL_table,
443 }, 400 },
444 { 401 {
445 .name = "LDO1", 402 .name = "LDO1",
446 .min_uV = 1000000,
447 .max_uV = 3150000,
448 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 403 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
449 .table = TPS65023_LDO1_VSEL_table, 404 .table = TPS65023_LDO1_VSEL_table,
450 }, 405 },
451 { 406 {
452 .name = "LDO2", 407 .name = "LDO2",
453 .min_uV = 1050000,
454 .max_uV = 3300000,
455 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 408 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
456 .table = TPS65023_LDO2_VSEL_table, 409 .table = TPS65023_LDO2_VSEL_table,
457 }, 410 },
@@ -460,34 +413,26 @@ static const struct tps_info tps65021_regs[] = {
460static const struct tps_info tps65023_regs[] = { 413static const struct tps_info tps65023_regs[] = {
461 { 414 {
462 .name = "VDCDC1", 415 .name = "VDCDC1",
463 .min_uV = 800000,
464 .max_uV = 1600000,
465 .table_len = ARRAY_SIZE(VCORE_VSEL_table), 416 .table_len = ARRAY_SIZE(VCORE_VSEL_table),
466 .table = VCORE_VSEL_table, 417 .table = VCORE_VSEL_table,
467 }, 418 },
468 { 419 {
469 .name = "VDCDC2", 420 .name = "VDCDC2",
470 .min_uV = 3300000, 421 .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table),
471 .max_uV = 3300000, 422 .table = DCDC_FIXED_3300000_VSEL_table,
472 .fixed = 1,
473 }, 423 },
474 { 424 {
475 .name = "VDCDC3", 425 .name = "VDCDC3",
476 .min_uV = 1800000, 426 .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table),
477 .max_uV = 1800000, 427 .table = DCDC_FIXED_1800000_VSEL_table,
478 .fixed = 1,
479 }, 428 },
480 { 429 {
481 .name = "LDO1", 430 .name = "LDO1",
482 .min_uV = 1000000,
483 .max_uV = 3150000,
484 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 431 .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table),
485 .table = TPS65023_LDO1_VSEL_table, 432 .table = TPS65023_LDO1_VSEL_table,
486 }, 433 },
487 { 434 {
488 .name = "LDO2", 435 .name = "LDO2",
489 .min_uV = 1050000,
490 .max_uV = 3300000,
491 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 436 .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table),
492 .table = TPS65023_LDO2_VSEL_table, 437 .table = TPS65023_LDO2_VSEL_table,
493 }, 438 },