aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/tps6524x-regulator.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-20 10:32:08 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-07-02 13:26:03 -0400
commit1e12dfc9681fed46fbc9fffc6aba9613908c1213 (patch)
tree26ff5bc9fb6140add172837f87339d5df9832313 /drivers/regulator/tps6524x-regulator.c
parentcac87fd34ebd79a954321f78acf38abcc69e1308 (diff)
regulator: tps6524x: Convert fixed ilimsel to table based
This patch refactors the code to get rid of the fixed_ilimsel and FIXED_ILIMSEL flag usage, and convert all the fixed ilimsel to table based (with one entry in the table). We can differentiate fixed ilimsel by checking info->n_ilimsels == 1, thus FIXED_ILIMSEL flag can be removed. This change makes the logic of the code simpler as all the ilimsels are table based now. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/tps6524x-regulator.c')
-rw-r--r--drivers/regulator/tps6524x-regulator.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c
index 48e37bd95a27..947ece933d90 100644
--- a/drivers/regulator/tps6524x-regulator.c
+++ b/drivers/regulator/tps6524x-regulator.c
@@ -110,8 +110,6 @@
110#define N_SWITCH 2 110#define N_SWITCH 2
111#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH) 111#define N_REGULATORS (N_DCDC + N_LDO + N_SWITCH)
112 112
113#define FIXED_ILIMSEL BIT(0)
114
115#define CMD_READ(reg) ((reg) << 6) 113#define CMD_READ(reg) ((reg) << 6)
116#define CMD_WRITE(reg) (BIT(5) | (reg) << 6) 114#define CMD_WRITE(reg) (BIT(5) | (reg) << 6)
117#define STAT_CLK BIT(3) 115#define STAT_CLK BIT(3)
@@ -130,9 +128,7 @@ struct supply_info {
130 int n_voltages; 128 int n_voltages;
131 const unsigned int *voltages; 129 const unsigned int *voltages;
132 int n_ilimsels; 130 int n_ilimsels;
133 const int *ilimsels; 131 const unsigned int *ilimsels;
134 int fixed_ilimsel;
135 int flags;
136 struct field enable, voltage, ilimsel; 132 struct field enable, voltage, ilimsel;
137}; 133};
138 134
@@ -353,24 +349,36 @@ static const unsigned int fixed_5000000_voltage[] = {
353 5000000 349 5000000
354}; 350};
355 351
356static const int ldo_ilimsel[] = { 352static const unsigned int ldo_ilimsel[] = {
357 400000, 1500000 353 400000, 1500000
358}; 354};
359 355
360static const int usb_ilimsel[] = { 356static const unsigned int usb_ilimsel[] = {
361 200000, 400000, 800000, 1000000 357 200000, 400000, 800000, 1000000
362}; 358};
363 359
360static const unsigned int fixed_2400000_ilimsel[] = {
361 2400000
362};
363
364static const unsigned int fixed_1200000_ilimsel[] = {
365 1200000
366};
367
368static const unsigned int fixed_400000_ilimsel[] = {
369 400000
370};
371
364#define __MK_FIELD(_reg, _mask, _shift) \ 372#define __MK_FIELD(_reg, _mask, _shift) \
365 { .reg = (_reg), .mask = (_mask), .shift = (_shift), } 373 { .reg = (_reg), .mask = (_mask), .shift = (_shift), }
366 374
367static const struct supply_info supply_info[N_REGULATORS] = { 375static const struct supply_info supply_info[N_REGULATORS] = {
368 { 376 {
369 .name = "DCDC1", 377 .name = "DCDC1",
370 .flags = FIXED_ILIMSEL,
371 .n_voltages = ARRAY_SIZE(dcdc1_voltages), 378 .n_voltages = ARRAY_SIZE(dcdc1_voltages),
372 .voltages = dcdc1_voltages, 379 .voltages = dcdc1_voltages,
373 .fixed_ilimsel = 2400000, 380 .n_ilimsels = ARRAY_SIZE(fixed_2400000_ilimsel),
381 .ilimsels = fixed_2400000_ilimsel,
374 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 382 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
375 DCDCDCDC1_EN_SHIFT), 383 DCDCDCDC1_EN_SHIFT),
376 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 384 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -378,10 +386,10 @@ static const struct supply_info supply_info[N_REGULATORS] = {
378 }, 386 },
379 { 387 {
380 .name = "DCDC2", 388 .name = "DCDC2",
381 .flags = FIXED_ILIMSEL,
382 .n_voltages = ARRAY_SIZE(dcdc2_voltages), 389 .n_voltages = ARRAY_SIZE(dcdc2_voltages),
383 .voltages = dcdc2_voltages, 390 .voltages = dcdc2_voltages,
384 .fixed_ilimsel = 1200000, 391 .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel),
392 .ilimsels = fixed_1200000_ilimsel,
385 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 393 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
386 DCDCDCDC2_EN_SHIFT), 394 DCDCDCDC2_EN_SHIFT),
387 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 395 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -389,10 +397,10 @@ static const struct supply_info supply_info[N_REGULATORS] = {
389 }, 397 },
390 { 398 {
391 .name = "DCDC3", 399 .name = "DCDC3",
392 .flags = FIXED_ILIMSEL,
393 .n_voltages = ARRAY_SIZE(dcdc3_voltages), 400 .n_voltages = ARRAY_SIZE(dcdc3_voltages),
394 .voltages = dcdc3_voltages, 401 .voltages = dcdc3_voltages,
395 .fixed_ilimsel = 1200000, 402 .n_ilimsels = ARRAY_SIZE(fixed_1200000_ilimsel),
403 .ilimsels = fixed_1200000_ilimsel,
396 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK, 404 .enable = __MK_FIELD(REG_DCDC_EN, DCDCDCDC_EN_MASK,
397 DCDCDCDC3_EN_SHIFT), 405 DCDCDCDC3_EN_SHIFT),
398 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK, 406 .voltage = __MK_FIELD(REG_DCDC_SET, DCDC_VDCDC_MASK,
@@ -439,8 +447,8 @@ static const struct supply_info supply_info[N_REGULATORS] = {
439 .name = "LCD", 447 .name = "LCD",
440 .n_voltages = ARRAY_SIZE(fixed_5000000_voltage), 448 .n_voltages = ARRAY_SIZE(fixed_5000000_voltage),
441 .voltages = fixed_5000000_voltage, 449 .voltages = fixed_5000000_voltage,
442 .flags = FIXED_ILIMSEL, 450 .n_ilimsels = ARRAY_SIZE(fixed_400000_ilimsel),
443 .fixed_ilimsel = 400000, 451 .ilimsels = fixed_400000_ilimsel,
444 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK, 452 .enable = __MK_FIELD(REG_BLOCK_EN, BLOCK_MASK,
445 BLOCK_LCD_SHIFT), 453 BLOCK_LCD_SHIFT),
446 }, 454 },
@@ -491,7 +499,7 @@ static int set_current_limit(struct regulator_dev *rdev, int min_uA,
491 hw = rdev_get_drvdata(rdev); 499 hw = rdev_get_drvdata(rdev);
492 info = &supply_info[rdev_get_id(rdev)]; 500 info = &supply_info[rdev_get_id(rdev)];
493 501
494 if (info->flags & FIXED_ILIMSEL) 502 if (info->n_ilimsels == 1)
495 return -EINVAL; 503 return -EINVAL;
496 504
497 for (i = 0; i < info->n_ilimsels; i++) 505 for (i = 0; i < info->n_ilimsels; i++)
@@ -514,8 +522,8 @@ static int get_current_limit(struct regulator_dev *rdev)
514 hw = rdev_get_drvdata(rdev); 522 hw = rdev_get_drvdata(rdev);
515 info = &supply_info[rdev_get_id(rdev)]; 523 info = &supply_info[rdev_get_id(rdev)];
516 524
517 if (info->flags & FIXED_ILIMSEL) 525 if (info->n_ilimsels == 1)
518 return info->fixed_ilimsel; 526 return info->ilimsels[0];
519 527
520 ret = read_field(hw, &info->ilimsel); 528 ret = read_field(hw, &info->ilimsel);
521 if (ret < 0) 529 if (ret < 0)