diff options
author | Adam Thomson <Adam.Thomson.Opensource@diasemi.com> | 2014-02-06 13:03:13 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-07 11:30:02 -0500 |
commit | 8b61a28d616a34beaa425873acd37a8b12929455 (patch) | |
tree | 11b65f4c4ef83074a2af4ec7ef544f7b201728f4 | |
parent | 38dbfb59d1175ef458d006556061adeaa8751b72 (diff) |
regulator: da9055: Add DT support
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | drivers/regulator/da9055-regulator.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 7f340206d329..d90f785829c4 100644 --- a/drivers/regulator/da9055-regulator.c +++ b/drivers/regulator/da9055-regulator.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/regulator/driver.h> | 20 | #include <linux/regulator/driver.h> |
21 | #include <linux/regulator/machine.h> | 21 | #include <linux/regulator/machine.h> |
22 | #include <linux/of.h> | ||
23 | #include <linux/regulator/of_regulator.h> | ||
22 | 24 | ||
23 | #include <linux/mfd/da9055/core.h> | 25 | #include <linux/mfd/da9055/core.h> |
24 | #include <linux/mfd/da9055/reg.h> | 26 | #include <linux/mfd/da9055/reg.h> |
@@ -446,6 +448,9 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, | |||
446 | struct da9055_regulator_info *info = regulator->info; | 448 | struct da9055_regulator_info *info = regulator->info; |
447 | int ret = 0; | 449 | int ret = 0; |
448 | 450 | ||
451 | if (!pdata) | ||
452 | return 0; | ||
453 | |||
449 | if (pdata->gpio_ren && pdata->gpio_ren[id]) { | 454 | if (pdata->gpio_ren && pdata->gpio_ren[id]) { |
450 | char name[18]; | 455 | char name[18]; |
451 | int gpio_mux = pdata->gpio_ren[id]; | 456 | int gpio_mux = pdata->gpio_ren[id]; |
@@ -530,6 +535,59 @@ static inline struct da9055_regulator_info *find_regulator_info(int id) | |||
530 | return NULL; | 535 | return NULL; |
531 | } | 536 | } |
532 | 537 | ||
538 | #ifdef CONFIG_OF | ||
539 | static struct of_regulator_match da9055_reg_matches[] = { | ||
540 | { .name = "BUCK1", }, | ||
541 | { .name = "BUCK2", }, | ||
542 | { .name = "LDO1", }, | ||
543 | { .name = "LDO2", }, | ||
544 | { .name = "LDO3", }, | ||
545 | { .name = "LDO4", }, | ||
546 | { .name = "LDO5", }, | ||
547 | { .name = "LDO6", }, | ||
548 | }; | ||
549 | |||
550 | static int da9055_regulator_dt_init(struct platform_device *pdev, | ||
551 | struct da9055_regulator *regulator, | ||
552 | struct regulator_config *config, | ||
553 | int regid) | ||
554 | { | ||
555 | struct device_node *nproot, *np; | ||
556 | int ret; | ||
557 | |||
558 | nproot = of_node_get(pdev->dev.parent->of_node); | ||
559 | if (!nproot) | ||
560 | return -ENODEV; | ||
561 | |||
562 | np = of_find_node_by_name(nproot, "regulators"); | ||
563 | if (!np) | ||
564 | return -ENODEV; | ||
565 | |||
566 | ret = of_regulator_match(&pdev->dev, np, &da9055_reg_matches[regid], 1); | ||
567 | of_node_put(nproot); | ||
568 | if (ret < 0) { | ||
569 | dev_err(&pdev->dev, "Error matching regulator: %d\n", ret); | ||
570 | return -ENODEV; | ||
571 | } | ||
572 | |||
573 | config->init_data = da9055_reg_matches[regid].init_data; | ||
574 | config->of_node = da9055_reg_matches[regid].of_node; | ||
575 | |||
576 | if (!config->of_node) | ||
577 | return -ENODEV; | ||
578 | |||
579 | return 0; | ||
580 | } | ||
581 | #else | ||
582 | static inline da9055_regulator_dt_init(struct platform_device *pdev, | ||
583 | struct da9055_regulator *regulator, | ||
584 | struct regulator_config *config, | ||
585 | int regid) | ||
586 | { | ||
587 | return -ENODEV; | ||
588 | } | ||
589 | #endif /* CONFIG_OF */ | ||
590 | |||
533 | static int da9055_regulator_probe(struct platform_device *pdev) | 591 | static int da9055_regulator_probe(struct platform_device *pdev) |
534 | { | 592 | { |
535 | struct regulator_config config = { }; | 593 | struct regulator_config config = { }; |
@@ -538,9 +596,6 @@ static int da9055_regulator_probe(struct platform_device *pdev) | |||
538 | struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); | 596 | struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); |
539 | int ret, irq; | 597 | int ret, irq; |
540 | 598 | ||
541 | if (pdata == NULL || pdata->regulators[pdev->id] == NULL) | ||
542 | return -ENODEV; | ||
543 | |||
544 | regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator), | 599 | regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator), |
545 | GFP_KERNEL); | 600 | GFP_KERNEL); |
546 | if (!regulator) | 601 | if (!regulator) |
@@ -557,8 +612,14 @@ static int da9055_regulator_probe(struct platform_device *pdev) | |||
557 | config.driver_data = regulator; | 612 | config.driver_data = regulator; |
558 | config.regmap = da9055->regmap; | 613 | config.regmap = da9055->regmap; |
559 | 614 | ||
560 | if (pdata && pdata->regulators) | 615 | if (pdata && pdata->regulators) { |
561 | config.init_data = pdata->regulators[pdev->id]; | 616 | config.init_data = pdata->regulators[pdev->id]; |
617 | } else { | ||
618 | ret = da9055_regulator_dt_init(pdev, regulator, &config, | ||
619 | pdev->id); | ||
620 | if (ret < 0) | ||
621 | return ret; | ||
622 | } | ||
562 | 623 | ||
563 | ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); | 624 | ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); |
564 | if (ret < 0) | 625 | if (ret < 0) |