diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-12-09 22:43:17 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-12-09 22:43:17 -0500 |
commit | e6120461e57700312648037be06adee3a764fd62 (patch) | |
tree | 8b5582e2c4e06832702d9d2ec5a8fc3714dbd301 /drivers/regulator | |
parent | adca48f7c61c53708a1f1ed567e0447ccb2b3b96 (diff) | |
parent | bdc4baacebdae1e90124b62a66607faec1a0a7fb (diff) |
Merge remote-tracking branch 'regulator/topic/palmas' into regulator-next
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/palmas-regulator.c | 121 |
1 files changed, 38 insertions, 83 deletions
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c index fd27a43a9fbc..e915629a25cf 100644 --- a/drivers/regulator/palmas-regulator.c +++ b/drivers/regulator/palmas-regulator.c | |||
@@ -309,68 +309,22 @@ static int palmas_list_voltage_smps(struct regulator_dev *dev, | |||
309 | int id = rdev_get_id(dev); | 309 | int id = rdev_get_id(dev); |
310 | int mult = 1; | 310 | int mult = 1; |
311 | 311 | ||
312 | if (!selector) | ||
313 | return 0; | ||
314 | |||
315 | /* Read the multiplier set in VSEL register to return | 312 | /* Read the multiplier set in VSEL register to return |
316 | * the correct voltage. | 313 | * the correct voltage. |
317 | */ | 314 | */ |
318 | if (pmic->range[id]) | 315 | if (pmic->range[id]) |
319 | mult = 2; | 316 | mult = 2; |
320 | 317 | ||
321 | /* Voltage is (0.49V + (selector * 0.01V)) * RANGE | 318 | if (selector == 0) |
322 | * as defined in data sheet. RANGE is either x1 or x2 | 319 | return 0; |
323 | */ | 320 | else if (selector < 6) |
324 | return (490000 + (selector * 10000)) * mult; | 321 | return 500000 * mult; |
325 | } | 322 | else |
326 | 323 | /* Voltage is linear mapping starting from selector 6, | |
327 | static int palmas_get_voltage_smps_sel(struct regulator_dev *dev) | 324 | * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE |
328 | { | 325 | * RANGE is either x1 or x2 |
329 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | 326 | */ |
330 | int id = rdev_get_id(dev); | 327 | return (490000 + ((selector - 5) * 10000)) * mult; |
331 | int selector; | ||
332 | unsigned int reg; | ||
333 | unsigned int addr; | ||
334 | |||
335 | addr = palmas_regs_info[id].vsel_addr; | ||
336 | |||
337 | palmas_smps_read(pmic->palmas, addr, ®); | ||
338 | |||
339 | selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK; | ||
340 | |||
341 | /* Adjust selector to match list_voltage ranges */ | ||
342 | if ((selector > 0) && (selector < 6)) | ||
343 | selector = 6; | ||
344 | if (!selector) | ||
345 | selector = 5; | ||
346 | if (selector > 121) | ||
347 | selector = 121; | ||
348 | selector -= 5; | ||
349 | |||
350 | return selector; | ||
351 | } | ||
352 | |||
353 | static int palmas_set_voltage_smps_sel(struct regulator_dev *dev, | ||
354 | unsigned selector) | ||
355 | { | ||
356 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
357 | int id = rdev_get_id(dev); | ||
358 | unsigned int reg = 0; | ||
359 | unsigned int addr; | ||
360 | |||
361 | addr = palmas_regs_info[id].vsel_addr; | ||
362 | |||
363 | /* Make sure we don't change the value of RANGE */ | ||
364 | if (pmic->range[id]) | ||
365 | reg |= PALMAS_SMPS12_VOLTAGE_RANGE; | ||
366 | |||
367 | /* Adjust the linux selector into range used in VSEL register */ | ||
368 | if (selector) | ||
369 | reg |= selector + 5; | ||
370 | |||
371 | palmas_smps_write(pmic->palmas, addr, reg); | ||
372 | |||
373 | return 0; | ||
374 | } | 328 | } |
375 | 329 | ||
376 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, | 330 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, |
@@ -386,11 +340,11 @@ static int palmas_map_voltage_smps(struct regulator_dev *rdev, | |||
386 | if (pmic->range[id]) { /* RANGE is x2 */ | 340 | if (pmic->range[id]) { /* RANGE is x2 */ |
387 | if (min_uV < 1000000) | 341 | if (min_uV < 1000000) |
388 | min_uV = 1000000; | 342 | min_uV = 1000000; |
389 | ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1; | 343 | ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6; |
390 | } else { /* RANGE is x1 */ | 344 | } else { /* RANGE is x1 */ |
391 | if (min_uV < 500000) | 345 | if (min_uV < 500000) |
392 | min_uV = 500000; | 346 | min_uV = 500000; |
393 | ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1; | 347 | ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6; |
394 | } | 348 | } |
395 | 349 | ||
396 | /* Map back into a voltage to verify we're still in bounds */ | 350 | /* Map back into a voltage to verify we're still in bounds */ |
@@ -407,8 +361,8 @@ static struct regulator_ops palmas_ops_smps = { | |||
407 | .disable = palmas_disable_smps, | 361 | .disable = palmas_disable_smps, |
408 | .set_mode = palmas_set_mode_smps, | 362 | .set_mode = palmas_set_mode_smps, |
409 | .get_mode = palmas_get_mode_smps, | 363 | .get_mode = palmas_get_mode_smps, |
410 | .get_voltage_sel = palmas_get_voltage_smps_sel, | 364 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
411 | .set_voltage_sel = palmas_set_voltage_smps_sel, | 365 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
412 | .list_voltage = palmas_list_voltage_smps, | 366 | .list_voltage = palmas_list_voltage_smps, |
413 | .map_voltage = palmas_map_voltage_smps, | 367 | .map_voltage = palmas_map_voltage_smps, |
414 | }; | 368 | }; |
@@ -703,6 +657,14 @@ static int palmas_probe(struct platform_device *pdev) | |||
703 | continue; | 657 | continue; |
704 | } | 658 | } |
705 | 659 | ||
660 | /* Initialise sleep/init values from platform data */ | ||
661 | if (pdata && pdata->reg_init[id]) { | ||
662 | reg_init = pdata->reg_init[id]; | ||
663 | ret = palmas_smps_init(palmas, id, reg_init); | ||
664 | if (ret) | ||
665 | goto err_unregister_regulator; | ||
666 | } | ||
667 | |||
706 | /* Register the regulators */ | 668 | /* Register the regulators */ |
707 | pmic->desc[id].name = palmas_regs_info[id].name; | 669 | pmic->desc[id].name = palmas_regs_info[id].name; |
708 | pmic->desc[id].id = id; | 670 | pmic->desc[id].id = id; |
@@ -723,29 +685,11 @@ static int palmas_probe(struct platform_device *pdev) | |||
723 | pmic->desc[id].uV_step = 1250000; | 685 | pmic->desc[id].uV_step = 1250000; |
724 | break; | 686 | break; |
725 | default: | 687 | default: |
726 | pmic->desc[id].ops = &palmas_ops_smps; | 688 | /* |
727 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; | 689 | * Read and store the RANGE bit for later use |
728 | } | 690 | * This must be done before regulator is probed, |
729 | 691 | * otherwise we error in probe with unsupportable ranges. | |
730 | pmic->desc[id].type = REGULATOR_VOLTAGE; | 692 | */ |
731 | pmic->desc[id].owner = THIS_MODULE; | ||
732 | |||
733 | /* Initialise sleep/init values from platform data */ | ||
734 | if (pdata) { | ||
735 | reg_init = pdata->reg_init[id]; | ||
736 | if (reg_init) { | ||
737 | ret = palmas_smps_init(palmas, id, reg_init); | ||
738 | if (ret) | ||
739 | goto err_unregister_regulator; | ||
740 | } | ||
741 | } | ||
742 | |||
743 | /* | ||
744 | * read and store the RANGE bit for later use | ||
745 | * This must be done before regulator is probed otherwise | ||
746 | * we error in probe with unsuportable ranges. | ||
747 | */ | ||
748 | if (id != PALMAS_REG_SMPS10) { | ||
749 | addr = palmas_regs_info[id].vsel_addr; | 693 | addr = palmas_regs_info[id].vsel_addr; |
750 | 694 | ||
751 | ret = palmas_smps_read(pmic->palmas, addr, ®); | 695 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
@@ -753,8 +697,19 @@ static int palmas_probe(struct platform_device *pdev) | |||
753 | goto err_unregister_regulator; | 697 | goto err_unregister_regulator; |
754 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) | 698 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) |
755 | pmic->range[id] = 1; | 699 | pmic->range[id] = 1; |
700 | |||
701 | pmic->desc[id].ops = &palmas_ops_smps; | ||
702 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; | ||
703 | pmic->desc[id].vsel_reg = | ||
704 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, | ||
705 | palmas_regs_info[id].vsel_addr); | ||
706 | pmic->desc[id].vsel_mask = | ||
707 | PALMAS_SMPS12_VOLTAGE_VSEL_MASK; | ||
756 | } | 708 | } |
757 | 709 | ||
710 | pmic->desc[id].type = REGULATOR_VOLTAGE; | ||
711 | pmic->desc[id].owner = THIS_MODULE; | ||
712 | |||
758 | if (pdata) | 713 | if (pdata) |
759 | config.init_data = pdata->reg_data[id]; | 714 | config.init_data = pdata->reg_data[id]; |
760 | else | 715 | else |