aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/ab3100.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2013-04-22 05:57:25 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-04-24 05:54:07 -0400
commit8735bc2fe69c3cd18c54dc1b993106dbeb7618be (patch)
treeda94df9dade17e043d043f605b66473f75b2137b /drivers/regulator/ab3100.c
parent9b31835341004022ea2862116de05fea50b8d1e4 (diff)
regulator: ab3100: device tree support
This implements device tree support for the AB3100 regulators driver. The initial settings are moved out of platform data and into the driver for the device tree case, as it appears that there is no way to supply this as AUXDATA for an I2C device. The style and bindings are heavily inspired by Lee Jones' style for AB8500. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/ab3100.c')
-rw-r--r--drivers/regulator/ab3100.c123
1 files changed, 117 insertions, 6 deletions
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 740735d1cca0..be1e6ad64830 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -17,6 +17,8 @@
17#include <linux/regulator/driver.h> 17#include <linux/regulator/driver.h>
18#include <linux/mfd/ab3100.h> 18#include <linux/mfd/ab3100.h>
19#include <linux/mfd/abx500.h> 19#include <linux/mfd/abx500.h>
20#include <linux/of.h>
21#include <linux/regulator/of_regulator.h>
20 22
21/* LDO registers and some handy masking definitions for AB3100 */ 23/* LDO registers and some handy masking definitions for AB3100 */
22#define AB3100_LDO_A 0x40 24#define AB3100_LDO_A 0x40
@@ -345,7 +347,11 @@ static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
345{ 347{
346 struct ab3100_regulator *abreg = rdev_get_drvdata(reg); 348 struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
347 349
348 return abreg->plfdata->external_voltage; 350 if (abreg->plfdata)
351 return abreg->plfdata->external_voltage;
352 else
353 /* TODO: encode external voltage into device tree */
354 return 0;
349} 355}
350 356
351static struct regulator_ops regulator_ops_fixed = { 357static struct regulator_ops regulator_ops_fixed = {
@@ -490,6 +496,8 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
490 496
491static int ab3100_regulator_register(struct platform_device *pdev, 497static int ab3100_regulator_register(struct platform_device *pdev,
492 struct ab3100_platform_data *plfdata, 498 struct ab3100_platform_data *plfdata,
499 struct regulator_init_data *init_data,
500 struct device_node *np,
493 int id) 501 int id)
494{ 502{
495 struct regulator_desc *desc; 503 struct regulator_desc *desc;
@@ -518,9 +526,11 @@ static int ab3100_regulator_register(struct platform_device *pdev,
518 */ 526 */
519 reg->dev = &pdev->dev; 527 reg->dev = &pdev->dev;
520 if (plfdata) { 528 if (plfdata) {
521 /* This will be replaced by device tree data */
522 reg->plfdata = plfdata; 529 reg->plfdata = plfdata;
523 config.init_data = &plfdata->reg_constraints[i]; 530 config.init_data = &plfdata->reg_constraints[i];
531 } else if (np) {
532 config.of_node = np;
533 config.init_data = init_data;
524 } 534 }
525 config.dev = &pdev->dev; 535 config.dev = &pdev->dev;
526 config.driver_data = reg; 536 config.driver_data = reg;
@@ -540,15 +550,103 @@ static int ab3100_regulator_register(struct platform_device *pdev,
540 return 0; 550 return 0;
541} 551}
542 552
553static struct of_regulator_match ab3100_regulator_matches[] = {
554 { .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, },
555 { .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, },
556 { .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, },
557 { .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, },
558 { .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F },
559 { .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G },
560 { .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H },
561 { .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K },
562 { .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT },
563 { .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK },
564};
565
543/* 566/*
544 * NOTE: the following functions are regulators pluralis - it is the 567 * Initial settings of ab3100 registers.
545 * binding to the AB3100 core driver and the parent platform device 568 * Common for below LDO regulator settings are that
546 * for all the different regulators. 569 * bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0).
570 * Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode.
547 */ 571 */
572/* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */
573#define LDO_A_SETTING 0x16
574/* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */
575#define LDO_C_SETTING 0x10
576/* LDO_D 0x10: 2.65V, ON, sleep mode not used */
577#define LDO_D_SETTING 0x10
578/* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */
579#define LDO_E_SETTING 0x10
580/* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */
581#define LDO_E_SLEEP_SETTING 0x00
582/* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */
583#define LDO_F_SETTING 0xD0
584/* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */
585#define LDO_G_SETTING 0x00
586/* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */
587#define LDO_H_SETTING 0x18
588/* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */
589#define LDO_K_SETTING 0x00
590/* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */
591#define LDO_EXT_SETTING 0x00
592/* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */
593#define BUCK_SETTING 0x7D
594/* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */
595#define BUCK_SLEEP_SETTING 0xAC
596
597static const u8 ab3100_reg_initvals[] = {
598 LDO_A_SETTING,
599 LDO_C_SETTING,
600 LDO_E_SETTING,
601 LDO_E_SLEEP_SETTING,
602 LDO_F_SETTING,
603 LDO_G_SETTING,
604 LDO_H_SETTING,
605 LDO_K_SETTING,
606 LDO_EXT_SETTING,
607 BUCK_SETTING,
608 BUCK_SLEEP_SETTING,
609 LDO_D_SETTING,
610};
611
612static int
613ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
614{
615 int err, i;
616
617 /*
618 * Set up the regulator registers, as was previously done with
619 * platform data.
620 */
621 /* Set up regulators */
622 for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
623 err = abx500_set_register_interruptible(&pdev->dev, 0,
624 ab3100_reg_init_order[i],
625 ab3100_reg_initvals[i]);
626 if (err) {
627 dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
628 err);
629 return err;
630 }
631 }
632
633 for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) {
634 err = ab3100_regulator_register(
635 pdev, NULL, ab3100_regulator_matches[i].init_data,
636 ab3100_regulator_matches[i].of_node,
637 (int) ab3100_regulator_matches[i].driver_data);
638 if (err)
639 return err;
640 }
641
642 return 0;
643}
644
548 645
549static int ab3100_regulators_probe(struct platform_device *pdev) 646static int ab3100_regulators_probe(struct platform_device *pdev)
550{ 647{
551 struct ab3100_platform_data *plfdata = pdev->dev.platform_data; 648 struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
649 struct device_node *np = pdev->dev.of_node;
552 int err = 0; 650 int err = 0;
553 u8 data; 651 u8 data;
554 int i; 652 int i;
@@ -567,6 +665,18 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
567 dev_notice(&pdev->dev, 665 dev_notice(&pdev->dev,
568 "chip is in inactive mode (Cold start)\n"); 666 "chip is in inactive mode (Cold start)\n");
569 667
668 if (np) {
669 err = of_regulator_match(&pdev->dev, np,
670 ab3100_regulator_matches,
671 ARRAY_SIZE(ab3100_regulator_matches));
672 if (err < 0) {
673 dev_err(&pdev->dev,
674 "Error parsing regulator init data: %d\n", err);
675 return err;
676 }
677 return ab3100_regulator_of_probe(pdev, np);
678 }
679
570 /* Set up regulators */ 680 /* Set up regulators */
571 for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) { 681 for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
572 err = abx500_set_register_interruptible(&pdev->dev, 0, 682 err = abx500_set_register_interruptible(&pdev->dev, 0,
@@ -583,7 +693,8 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
583 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 693 for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
584 struct regulator_desc *desc = &ab3100_regulator_desc[i]; 694 struct regulator_desc *desc = &ab3100_regulator_desc[i];
585 695
586 err = ab3100_regulator_register(pdev, plfdata, desc->id); 696 err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
697 desc->id);
587 if (err) 698 if (err)
588 return err; 699 return err;
589 } 700 }