diff options
Diffstat (limited to 'drivers/regulator/da9055-regulator.c')
-rw-r--r-- | drivers/regulator/da9055-regulator.c | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c index 7f340206d329..9516317e1a9f 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_get_child_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 ret; | ||
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 int 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) |
@@ -576,7 +637,9 @@ static int da9055_regulator_probe(struct platform_device *pdev) | |||
576 | /* Only LDO 5 and 6 has got the over current interrupt */ | 637 | /* Only LDO 5 and 6 has got the over current interrupt */ |
577 | if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) { | 638 | if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) { |
578 | irq = platform_get_irq_byname(pdev, "REGULATOR"); | 639 | irq = platform_get_irq_byname(pdev, "REGULATOR"); |
579 | irq = regmap_irq_get_virq(da9055->irq_data, irq); | 640 | if (irq < 0) |
641 | return irq; | ||
642 | |||
580 | ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, | 643 | ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, |
581 | da9055_ldo5_6_oc_irq, | 644 | da9055_ldo5_6_oc_irq, |
582 | IRQF_TRIGGER_HIGH | | 645 | IRQF_TRIGGER_HIGH | |