diff options
Diffstat (limited to 'drivers/regulator/lp3972.c')
-rw-r--r-- | drivers/regulator/lp3972.c | 102 |
1 files changed, 36 insertions, 66 deletions
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index de073df7d344..3cdc755d9b22 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -74,54 +74,40 @@ struct lp3972 { | |||
74 | #define LP3972_OVER2_LDO4_EN BIT(4) | 74 | #define LP3972_OVER2_LDO4_EN BIT(4) |
75 | #define LP3972_OVER1_S_EN BIT(2) | 75 | #define LP3972_OVER1_S_EN BIT(2) |
76 | 76 | ||
77 | static const int ldo1_voltage_map[] = { | 77 | static const unsigned int ldo1_voltage_map[] = { |
78 | 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875, | 78 | 1700000, 1725000, 1750000, 1775000, 1800000, 1825000, 1850000, 1875000, |
79 | 1900, 1925, 1950, 1975, 2000, | 79 | 1900000, 1925000, 1950000, 1975000, 2000000, |
80 | }; | 80 | }; |
81 | 81 | ||
82 | static const int ldo23_voltage_map[] = { | 82 | static const unsigned int ldo23_voltage_map[] = { |
83 | 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, | 83 | 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, |
84 | 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, | 84 | 2600000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, |
85 | }; | 85 | }; |
86 | 86 | ||
87 | static const int ldo4_voltage_map[] = { | 87 | static const unsigned int ldo4_voltage_map[] = { |
88 | 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, | 88 | 1000000, 1050000, 1100000, 1150000, 1200000, 1250000, 1300000, 1350000, |
89 | 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, | 89 | 1400000, 1500000, 1800000, 1900000, 2500000, 2800000, 3000000, 3300000, |
90 | }; | 90 | }; |
91 | 91 | ||
92 | static const int ldo5_voltage_map[] = { | 92 | static const unsigned int ldo5_voltage_map[] = { |
93 | 0, 0, 0, 0, 0, 850, 875, 900, | 93 | 0, 0, 0, 0, 0, 850000, 875000, 900000, |
94 | 925, 950, 975, 1000, 1025, 1050, 1075, 1100, | 94 | 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000, |
95 | 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, | 95 | 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, |
96 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 96 | 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, |
97 | }; | 97 | }; |
98 | 98 | ||
99 | static const int buck1_voltage_map[] = { | 99 | static const unsigned int buck1_voltage_map[] = { |
100 | 725, 750, 775, 800, 825, 850, 875, 900, | 100 | 725000, 750000, 775000, 800000, 825000, 850000, 875000, 900000, |
101 | 925, 950, 975, 1000, 1025, 1050, 1075, 1100, | 101 | 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, 1100000, |
102 | 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, | 102 | 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, |
103 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 103 | 1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000, |
104 | }; | 104 | }; |
105 | 105 | ||
106 | static const int buck23_voltage_map[] = { | 106 | static const unsigned int buck23_voltage_map[] = { |
107 | 0, 800, 850, 900, 950, 1000, 1050, 1100, | 107 | 0, 800000, 850000, 900000, 950000, 1000000, 1050000, 1100000, |
108 | 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, | 108 | 1150000, 1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, |
109 | 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, | 109 | 1550000, 1600000, 1650000, 1700000, 1800000, 1900000, 2500000, 2800000, |
110 | 3000, 3300, | 110 | 3000000, 3300000, |
111 | }; | ||
112 | |||
113 | static const int *ldo_voltage_map[] = { | ||
114 | ldo1_voltage_map, | ||
115 | ldo23_voltage_map, | ||
116 | ldo23_voltage_map, | ||
117 | ldo4_voltage_map, | ||
118 | ldo5_voltage_map, | ||
119 | }; | ||
120 | |||
121 | static const int *buck_voltage_map[] = { | ||
122 | buck1_voltage_map, | ||
123 | buck23_voltage_map, | ||
124 | buck23_voltage_map, | ||
125 | }; | 111 | }; |
126 | 112 | ||
127 | static const int ldo_output_enable_mask[] = { | 113 | static const int ldo_output_enable_mask[] = { |
@@ -160,7 +146,6 @@ static const int buck_base_addr[] = { | |||
160 | LP3972_B3TV_REG, | 146 | LP3972_B3TV_REG, |
161 | }; | 147 | }; |
162 | 148 | ||
163 | #define LP3972_LDO_VOL_VALUE_MAP(x) (ldo_voltage_map[x]) | ||
164 | #define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x]) | 149 | #define LP3972_LDO_OUTPUT_ENABLE_MASK(x) (ldo_output_enable_mask[x]) |
165 | #define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x]) | 150 | #define LP3972_LDO_OUTPUT_ENABLE_REG(x) (ldo_output_enable_addr[x]) |
166 | 151 | ||
@@ -177,7 +162,6 @@ static const int buck_base_addr[] = { | |||
177 | #define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00) | 162 | #define LP3972_LDO_VOL_MIN_IDX(x) (((x) == 4) ? 0x05 : 0x00) |
178 | #define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c) | 163 | #define LP3972_LDO_VOL_MAX_IDX(x) ((x) ? (((x) == 4) ? 0x1f : 0x0f) : 0x0c) |
179 | 164 | ||
180 | #define LP3972_BUCK_VOL_VALUE_MAP(x) (buck_voltage_map[x]) | ||
181 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) | 165 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) |
182 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) | 166 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) |
183 | #define LP3972_BUCK_VOL_MASK 0x1f | 167 | #define LP3972_BUCK_VOL_MASK 0x1f |
@@ -242,17 +226,6 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val) | |||
242 | return ret; | 226 | return ret; |
243 | } | 227 | } |
244 | 228 | ||
245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | ||
246 | { | ||
247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | ||
248 | |||
249 | if (index < LP3972_LDO_VOL_MIN_IDX(ldo) || | ||
250 | index > LP3972_LDO_VOL_MAX_IDX(ldo)) | ||
251 | return -EINVAL; | ||
252 | |||
253 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; | ||
254 | } | ||
255 | |||
256 | static int lp3972_ldo_is_enabled(struct regulator_dev *dev) | 229 | static int lp3972_ldo_is_enabled(struct regulator_dev *dev) |
257 | { | 230 | { |
258 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 231 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
@@ -294,7 +267,7 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | |||
294 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); | 267 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); |
295 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; | 268 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; |
296 | 269 | ||
297 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; | 270 | return dev->desc->volt_table[val]; |
298 | } | 271 | } |
299 | 272 | ||
300 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, | 273 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, |
@@ -337,7 +310,7 @@ static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, | |||
337 | } | 310 | } |
338 | 311 | ||
339 | static struct regulator_ops lp3972_ldo_ops = { | 312 | static struct regulator_ops lp3972_ldo_ops = { |
340 | .list_voltage = lp3972_ldo_list_voltage, | 313 | .list_voltage = regulator_list_voltage_table, |
341 | .is_enabled = lp3972_ldo_is_enabled, | 314 | .is_enabled = lp3972_ldo_is_enabled, |
342 | .enable = lp3972_ldo_enable, | 315 | .enable = lp3972_ldo_enable, |
343 | .disable = lp3972_ldo_disable, | 316 | .disable = lp3972_ldo_disable, |
@@ -345,17 +318,6 @@ static struct regulator_ops lp3972_ldo_ops = { | |||
345 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, | 318 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, |
346 | }; | 319 | }; |
347 | 320 | ||
348 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | ||
349 | { | ||
350 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | ||
351 | |||
352 | if (index < LP3972_BUCK_VOL_MIN_IDX(buck) || | ||
353 | index > LP3972_BUCK_VOL_MAX_IDX(buck)) | ||
354 | return -EINVAL; | ||
355 | |||
356 | return 1000 * buck_voltage_map[buck][index]; | ||
357 | } | ||
358 | |||
359 | static int lp3972_dcdc_is_enabled(struct regulator_dev *dev) | 321 | static int lp3972_dcdc_is_enabled(struct regulator_dev *dev) |
360 | { | 322 | { |
361 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 323 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
@@ -401,7 +363,7 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) | |||
401 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); | 363 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); |
402 | reg &= LP3972_BUCK_VOL_MASK; | 364 | reg &= LP3972_BUCK_VOL_MASK; |
403 | if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) | 365 | if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) |
404 | val = 1000 * buck_voltage_map[buck][reg]; | 366 | val = dev->desc->volt_table[reg]; |
405 | else { | 367 | else { |
406 | val = 0; | 368 | val = 0; |
407 | dev_warn(&dev->dev, "chip reported incorrect voltage value." | 369 | dev_warn(&dev->dev, "chip reported incorrect voltage value." |
@@ -436,7 +398,7 @@ static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, | |||
436 | } | 398 | } |
437 | 399 | ||
438 | static struct regulator_ops lp3972_dcdc_ops = { | 400 | static struct regulator_ops lp3972_dcdc_ops = { |
439 | .list_voltage = lp3972_dcdc_list_voltage, | 401 | .list_voltage = regulator_list_voltage_table, |
440 | .is_enabled = lp3972_dcdc_is_enabled, | 402 | .is_enabled = lp3972_dcdc_is_enabled, |
441 | .enable = lp3972_dcdc_enable, | 403 | .enable = lp3972_dcdc_enable, |
442 | .disable = lp3972_dcdc_disable, | 404 | .disable = lp3972_dcdc_disable, |
@@ -450,6 +412,7 @@ static const struct regulator_desc regulators[] = { | |||
450 | .id = LP3972_LDO1, | 412 | .id = LP3972_LDO1, |
451 | .ops = &lp3972_ldo_ops, | 413 | .ops = &lp3972_ldo_ops, |
452 | .n_voltages = ARRAY_SIZE(ldo1_voltage_map), | 414 | .n_voltages = ARRAY_SIZE(ldo1_voltage_map), |
415 | .volt_table = ldo1_voltage_map, | ||
453 | .type = REGULATOR_VOLTAGE, | 416 | .type = REGULATOR_VOLTAGE, |
454 | .owner = THIS_MODULE, | 417 | .owner = THIS_MODULE, |
455 | }, | 418 | }, |
@@ -458,6 +421,7 @@ static const struct regulator_desc regulators[] = { | |||
458 | .id = LP3972_LDO2, | 421 | .id = LP3972_LDO2, |
459 | .ops = &lp3972_ldo_ops, | 422 | .ops = &lp3972_ldo_ops, |
460 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), | 423 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), |
424 | .volt_table = ldo23_voltage_map, | ||
461 | .type = REGULATOR_VOLTAGE, | 425 | .type = REGULATOR_VOLTAGE, |
462 | .owner = THIS_MODULE, | 426 | .owner = THIS_MODULE, |
463 | }, | 427 | }, |
@@ -466,6 +430,7 @@ static const struct regulator_desc regulators[] = { | |||
466 | .id = LP3972_LDO3, | 430 | .id = LP3972_LDO3, |
467 | .ops = &lp3972_ldo_ops, | 431 | .ops = &lp3972_ldo_ops, |
468 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), | 432 | .n_voltages = ARRAY_SIZE(ldo23_voltage_map), |
433 | .volt_table = ldo23_voltage_map, | ||
469 | .type = REGULATOR_VOLTAGE, | 434 | .type = REGULATOR_VOLTAGE, |
470 | .owner = THIS_MODULE, | 435 | .owner = THIS_MODULE, |
471 | }, | 436 | }, |
@@ -474,6 +439,7 @@ static const struct regulator_desc regulators[] = { | |||
474 | .id = LP3972_LDO4, | 439 | .id = LP3972_LDO4, |
475 | .ops = &lp3972_ldo_ops, | 440 | .ops = &lp3972_ldo_ops, |
476 | .n_voltages = ARRAY_SIZE(ldo4_voltage_map), | 441 | .n_voltages = ARRAY_SIZE(ldo4_voltage_map), |
442 | .volt_table = ldo4_voltage_map, | ||
477 | .type = REGULATOR_VOLTAGE, | 443 | .type = REGULATOR_VOLTAGE, |
478 | .owner = THIS_MODULE, | 444 | .owner = THIS_MODULE, |
479 | }, | 445 | }, |
@@ -482,6 +448,7 @@ static const struct regulator_desc regulators[] = { | |||
482 | .id = LP3972_LDO5, | 448 | .id = LP3972_LDO5, |
483 | .ops = &lp3972_ldo_ops, | 449 | .ops = &lp3972_ldo_ops, |
484 | .n_voltages = ARRAY_SIZE(ldo5_voltage_map), | 450 | .n_voltages = ARRAY_SIZE(ldo5_voltage_map), |
451 | .volt_table = ldo5_voltage_map, | ||
485 | .type = REGULATOR_VOLTAGE, | 452 | .type = REGULATOR_VOLTAGE, |
486 | .owner = THIS_MODULE, | 453 | .owner = THIS_MODULE, |
487 | }, | 454 | }, |
@@ -490,6 +457,7 @@ static const struct regulator_desc regulators[] = { | |||
490 | .id = LP3972_DCDC1, | 457 | .id = LP3972_DCDC1, |
491 | .ops = &lp3972_dcdc_ops, | 458 | .ops = &lp3972_dcdc_ops, |
492 | .n_voltages = ARRAY_SIZE(buck1_voltage_map), | 459 | .n_voltages = ARRAY_SIZE(buck1_voltage_map), |
460 | .volt_table = buck1_voltage_map, | ||
493 | .type = REGULATOR_VOLTAGE, | 461 | .type = REGULATOR_VOLTAGE, |
494 | .owner = THIS_MODULE, | 462 | .owner = THIS_MODULE, |
495 | }, | 463 | }, |
@@ -498,6 +466,7 @@ static const struct regulator_desc regulators[] = { | |||
498 | .id = LP3972_DCDC2, | 466 | .id = LP3972_DCDC2, |
499 | .ops = &lp3972_dcdc_ops, | 467 | .ops = &lp3972_dcdc_ops, |
500 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), | 468 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), |
469 | .volt_table = buck23_voltage_map, | ||
501 | .type = REGULATOR_VOLTAGE, | 470 | .type = REGULATOR_VOLTAGE, |
502 | .owner = THIS_MODULE, | 471 | .owner = THIS_MODULE, |
503 | }, | 472 | }, |
@@ -506,6 +475,7 @@ static const struct regulator_desc regulators[] = { | |||
506 | .id = LP3972_DCDC3, | 475 | .id = LP3972_DCDC3, |
507 | .ops = &lp3972_dcdc_ops, | 476 | .ops = &lp3972_dcdc_ops, |
508 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), | 477 | .n_voltages = ARRAY_SIZE(buck23_voltage_map), |
478 | .volt_table = buck23_voltage_map, | ||
509 | .type = REGULATOR_VOLTAGE, | 479 | .type = REGULATOR_VOLTAGE, |
510 | .owner = THIS_MODULE, | 480 | .owner = THIS_MODULE, |
511 | }, | 481 | }, |