diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-02-19 07:42:50 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-02-19 07:42:50 -0500 |
commit | c99f21c2763f2071dc09eb4cb26cff866e19a1c5 (patch) | |
tree | 0812b7fbd318778aa8206a53cef86cf780e2e545 /drivers/regulator | |
parent | e11c4515e3aca5bfc005fe0c6b3be6bbb1485807 (diff) | |
parent | 2c8a5dcaa4143dfedf956a5349216ded3c3ad085 (diff) |
Merge remote-tracking branch 'regulator/topic/mc13892' into regulator-next
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/mc13892-regulator.c | 111 | ||||
-rw-r--r-- | drivers/regulator/mc13xxx-regulator-core.c | 10 | ||||
-rw-r--r-- | drivers/regulator/mc13xxx.h | 4 |
3 files changed, 103 insertions, 22 deletions
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index 0d84b1f33199..9891aec47b57 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c | |||
@@ -164,6 +164,14 @@ static const unsigned int mc13892_sw1[] = { | |||
164 | 1350000, 1375000 | 164 | 1350000, 1375000 |
165 | }; | 165 | }; |
166 | 166 | ||
167 | /* | ||
168 | * Note: this table is used to derive SWxVSEL by index into | ||
169 | * the array. Offset the values by the index of 1100000uV | ||
170 | * to get the actual register value for that voltage selector | ||
171 | * if the HI bit is to be set as well. | ||
172 | */ | ||
173 | #define MC13892_SWxHI_SEL_OFFSET 20 | ||
174 | |||
167 | static const unsigned int mc13892_sw[] = { | 175 | static const unsigned int mc13892_sw[] = { |
168 | 600000, 625000, 650000, 675000, 700000, 725000, | 176 | 600000, 625000, 650000, 675000, 700000, 725000, |
169 | 750000, 775000, 800000, 825000, 850000, 875000, | 177 | 750000, 775000, 800000, 825000, 850000, 875000, |
@@ -239,7 +247,6 @@ static const unsigned int mc13892_pwgtdrv[] = { | |||
239 | }; | 247 | }; |
240 | 248 | ||
241 | static struct regulator_ops mc13892_gpo_regulator_ops; | 249 | static struct regulator_ops mc13892_gpo_regulator_ops; |
242 | /* sw regulators need special care due to the "hi bit" */ | ||
243 | static struct regulator_ops mc13892_sw_regulator_ops; | 250 | static struct regulator_ops mc13892_sw_regulator_ops; |
244 | 251 | ||
245 | 252 | ||
@@ -396,7 +403,7 @@ static int mc13892_sw_regulator_get_voltage_sel(struct regulator_dev *rdev) | |||
396 | { | 403 | { |
397 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | 404 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
398 | int ret, id = rdev_get_id(rdev); | 405 | int ret, id = rdev_get_id(rdev); |
399 | unsigned int val; | 406 | unsigned int val, selector; |
400 | 407 | ||
401 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | 408 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); |
402 | 409 | ||
@@ -407,12 +414,28 @@ static int mc13892_sw_regulator_get_voltage_sel(struct regulator_dev *rdev) | |||
407 | if (ret) | 414 | if (ret) |
408 | return ret; | 415 | return ret; |
409 | 416 | ||
410 | val = (val & mc13892_regulators[id].vsel_mask) | 417 | /* |
411 | >> mc13892_regulators[id].vsel_shift; | 418 | * Figure out if the HI bit is set inside the switcher mode register |
419 | * since this means the selector value we return is at a different | ||
420 | * offset into the selector table. | ||
421 | * | ||
422 | * According to the MC13892 documentation note 59 (Table 47) the SW1 | ||
423 | * buck switcher does not support output range programming therefore | ||
424 | * the HI bit must always remain 0. So do not do anything strange if | ||
425 | * our register is MC13892_SWITCHERS0. | ||
426 | */ | ||
427 | |||
428 | selector = val & mc13892_regulators[id].vsel_mask; | ||
429 | |||
430 | if ((mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) && | ||
431 | (val & MC13892_SWITCHERS0_SWxHI)) { | ||
432 | selector += MC13892_SWxHI_SEL_OFFSET; | ||
433 | } | ||
412 | 434 | ||
413 | dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); | 435 | dev_dbg(rdev_get_dev(rdev), "%s id: %d val: 0x%08x selector: %d\n", |
436 | __func__, id, val, selector); | ||
414 | 437 | ||
415 | return val; | 438 | return selector; |
416 | } | 439 | } |
417 | 440 | ||
418 | static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, | 441 | static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, |
@@ -425,18 +448,35 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, | |||
425 | 448 | ||
426 | volt = rdev->desc->volt_table[selector]; | 449 | volt = rdev->desc->volt_table[selector]; |
427 | mask = mc13892_regulators[id].vsel_mask; | 450 | mask = mc13892_regulators[id].vsel_mask; |
428 | reg_value = selector << mc13892_regulators[id].vsel_shift; | 451 | reg_value = selector; |
429 | 452 | ||
430 | if (volt > 1375000) { | 453 | /* |
431 | mask |= MC13892_SWITCHERS0_SWxHI; | 454 | * Don't mess with the HI bit or support HI voltage offsets for SW1. |
432 | reg_value |= MC13892_SWITCHERS0_SWxHI; | 455 | * |
433 | } else if (volt < 1100000) { | 456 | * Since the get_voltage_sel callback has given a fudged value for |
434 | mask |= MC13892_SWITCHERS0_SWxHI; | 457 | * the selector offset, we need to back out that offset if HI is |
435 | reg_value &= ~MC13892_SWITCHERS0_SWxHI; | 458 | * to be set so we write the correct value to the register. |
459 | * | ||
460 | * The HI bit addition and selector offset handling COULD be more | ||
461 | * complicated by shifting and masking off the voltage selector part | ||
462 | * of the register then logical OR it back in, but since the selector | ||
463 | * is at bits 4:0 there is very little point. This makes the whole | ||
464 | * thing more readable and we do far less work. | ||
465 | */ | ||
466 | |||
467 | if (mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) { | ||
468 | if (volt > 1375000) { | ||
469 | reg_value -= MC13892_SWxHI_SEL_OFFSET; | ||
470 | reg_value |= MC13892_SWITCHERS0_SWxHI; | ||
471 | mask |= MC13892_SWITCHERS0_SWxHI; | ||
472 | } else if (volt < 1100000) { | ||
473 | reg_value &= ~MC13892_SWITCHERS0_SWxHI; | ||
474 | mask |= MC13892_SWITCHERS0_SWxHI; | ||
475 | } | ||
436 | } | 476 | } |
437 | 477 | ||
438 | mc13xxx_lock(priv->mc13xxx); | 478 | mc13xxx_lock(priv->mc13xxx); |
439 | ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask, | 479 | ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg, mask, |
440 | reg_value); | 480 | reg_value); |
441 | mc13xxx_unlock(priv->mc13xxx); | 481 | mc13xxx_unlock(priv->mc13xxx); |
442 | 482 | ||
@@ -495,15 +535,18 @@ static int mc13892_regulator_probe(struct platform_device *pdev) | |||
495 | struct mc13xxx_regulator_init_data *mc13xxx_data; | 535 | struct mc13xxx_regulator_init_data *mc13xxx_data; |
496 | struct regulator_config config = { }; | 536 | struct regulator_config config = { }; |
497 | int i, ret; | 537 | int i, ret; |
498 | int num_regulators = 0; | 538 | int num_regulators = 0, num_parsed; |
499 | u32 val; | 539 | u32 val; |
500 | 540 | ||
501 | num_regulators = mc13xxx_get_num_regulators_dt(pdev); | 541 | num_regulators = mc13xxx_get_num_regulators_dt(pdev); |
542 | |||
502 | if (num_regulators <= 0 && pdata) | 543 | if (num_regulators <= 0 && pdata) |
503 | num_regulators = pdata->num_regulators; | 544 | num_regulators = pdata->num_regulators; |
504 | if (num_regulators <= 0) | 545 | if (num_regulators <= 0) |
505 | return -EINVAL; | 546 | return -EINVAL; |
506 | 547 | ||
548 | num_parsed = num_regulators; | ||
549 | |||
507 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + | 550 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + |
508 | num_regulators * sizeof(priv->regulators[0]), | 551 | num_regulators * sizeof(priv->regulators[0]), |
509 | GFP_KERNEL); | 552 | GFP_KERNEL); |
@@ -520,7 +563,7 @@ static int mc13892_regulator_probe(struct platform_device *pdev) | |||
520 | if (ret) | 563 | if (ret) |
521 | goto err_unlock; | 564 | goto err_unlock; |
522 | 565 | ||
523 | /* enable switch auto mode */ | 566 | /* enable switch auto mode (on 2.0A silicon only) */ |
524 | if ((val & 0x0000FFFF) == 0x45d0) { | 567 | if ((val & 0x0000FFFF) == 0x45d0) { |
525 | ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4, | 568 | ret = mc13xxx_reg_rmw(mc13892, MC13892_SWITCHERS4, |
526 | MC13892_SWITCHERS4_SW1MODE_M | | 569 | MC13892_SWITCHERS4_SW1MODE_M | |
@@ -546,7 +589,39 @@ static int mc13892_regulator_probe(struct platform_device *pdev) | |||
546 | = mc13892_vcam_get_mode; | 589 | = mc13892_vcam_get_mode; |
547 | 590 | ||
548 | mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators, | 591 | mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators, |
549 | ARRAY_SIZE(mc13892_regulators)); | 592 | ARRAY_SIZE(mc13892_regulators), |
593 | &num_parsed); | ||
594 | |||
595 | /* | ||
596 | * Perform a little sanity check on the regulator tree - if we found | ||
597 | * a number of regulators from mc13xxx_get_num_regulators_dt and | ||
598 | * then parsed a smaller number in mc13xxx_parse_regulators_dt then | ||
599 | * there is a regulator defined in the regulators node which has | ||
600 | * not matched any usable regulator in the driver. In this case, | ||
601 | * there is one missing and what will happen is the first regulator | ||
602 | * will get registered again. | ||
603 | * | ||
604 | * Fix this by basically making our number of registerable regulators | ||
605 | * equal to the number of regulators we parsed. We are allocating | ||
606 | * too much memory for priv, but this is unavoidable at this point. | ||
607 | * | ||
608 | * As an example of how this can happen, try making a typo in your | ||
609 | * regulators node (vviohi {} instead of viohi {}) so that the name | ||
610 | * does not match.. | ||
611 | * | ||
612 | * The check will basically pass for platform data (non-DT) because | ||
613 | * mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed. | ||
614 | * | ||
615 | */ | ||
616 | if (num_parsed != num_regulators) { | ||
617 | dev_warn(&pdev->dev, | ||
618 | "parsed %d != regulators %d - check your device tree!\n", | ||
619 | num_parsed, num_regulators); | ||
620 | |||
621 | num_regulators = num_parsed; | ||
622 | priv->num_regulators = num_regulators; | ||
623 | } | ||
624 | |||
550 | for (i = 0; i < num_regulators; i++) { | 625 | for (i = 0; i < num_regulators; i++) { |
551 | struct regulator_init_data *init_data; | 626 | struct regulator_init_data *init_data; |
552 | struct regulator_desc *desc; | 627 | struct regulator_desc *desc; |
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c index 4ed89c654110..2ecf1d8b6a94 100644 --- a/drivers/regulator/mc13xxx-regulator-core.c +++ b/drivers/regulator/mc13xxx-regulator-core.c | |||
@@ -181,12 +181,14 @@ EXPORT_SYMBOL_GPL(mc13xxx_get_num_regulators_dt); | |||
181 | 181 | ||
182 | struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( | 182 | struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
183 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, | 183 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
184 | int num_regulators) | 184 | int num_regulators, int *num_parsed) |
185 | { | 185 | { |
186 | struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); | 186 | struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); |
187 | struct mc13xxx_regulator_init_data *data, *p; | 187 | struct mc13xxx_regulator_init_data *data, *p; |
188 | struct device_node *parent, *child; | 188 | struct device_node *parent, *child; |
189 | int i; | 189 | int i, parsed = 0; |
190 | |||
191 | *num_parsed = 0; | ||
190 | 192 | ||
191 | of_node_get(pdev->dev.parent->of_node); | 193 | of_node_get(pdev->dev.parent->of_node); |
192 | parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators"); | 194 | parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators"); |
@@ -203,16 +205,20 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( | |||
203 | for (i = 0; i < num_regulators; i++) { | 205 | for (i = 0; i < num_regulators; i++) { |
204 | if (!of_node_cmp(child->name, | 206 | if (!of_node_cmp(child->name, |
205 | regulators[i].desc.name)) { | 207 | regulators[i].desc.name)) { |
208 | |||
206 | p->id = i; | 209 | p->id = i; |
207 | p->init_data = of_get_regulator_init_data( | 210 | p->init_data = of_get_regulator_init_data( |
208 | &pdev->dev, child); | 211 | &pdev->dev, child); |
209 | p->node = child; | 212 | p->node = child; |
210 | p++; | 213 | p++; |
214 | |||
215 | parsed++; | ||
211 | break; | 216 | break; |
212 | } | 217 | } |
213 | } | 218 | } |
214 | } | 219 | } |
215 | 220 | ||
221 | *num_parsed = parsed; | ||
216 | return data; | 222 | return data; |
217 | } | 223 | } |
218 | EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt); | 224 | EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt); |
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h index 06c8903f182a..007f83387fd6 100644 --- a/drivers/regulator/mc13xxx.h +++ b/drivers/regulator/mc13xxx.h | |||
@@ -39,7 +39,7 @@ extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, | |||
39 | extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); | 39 | extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev); |
40 | extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( | 40 | extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
41 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, | 41 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
42 | int num_regulators); | 42 | int num_regulators, int *num_parsed); |
43 | #else | 43 | #else |
44 | static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) | 44 | static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) |
45 | { | 45 | { |
@@ -48,7 +48,7 @@ static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev) | |||
48 | 48 | ||
49 | static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( | 49 | static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt( |
50 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, | 50 | struct platform_device *pdev, struct mc13xxx_regulator *regulators, |
51 | int num_regulators) | 51 | int num_regulators, int *num_parsed) |
52 | { | 52 | { |
53 | return NULL; | 53 | return NULL; |
54 | } | 54 | } |