Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: palmas: Add DT support

Add DT support to palmas regulator. This involved a little change to
the platform data structure. Regulator information can now come from
platform data or DT.

Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Graeme Gregory and committed by
Samuel Ortiz
a361cd9f 7cc4c92f

+119 -8
+119 -8
drivers/regulator/palmas-regulator.c
··· 22 22 #include <linux/slab.h> 23 23 #include <linux/regmap.h> 24 24 #include <linux/mfd/palmas.h> 25 + #include <linux/of.h> 26 + #include <linux/of_platform.h> 27 + #include <linux/regulator/of_regulator.h> 25 28 26 29 struct regs_info { 27 30 char *name; ··· 606 603 return 0; 607 604 } 608 605 606 + static struct of_regulator_match palmas_matches[] = { 607 + { .name = "smps12", }, 608 + { .name = "smps123", }, 609 + { .name = "smps3", }, 610 + { .name = "smps45", }, 611 + { .name = "smps457", }, 612 + { .name = "smps6", }, 613 + { .name = "smps7", }, 614 + { .name = "smps8", }, 615 + { .name = "smps9", }, 616 + { .name = "smps10", }, 617 + { .name = "ldo1", }, 618 + { .name = "ldo2", }, 619 + { .name = "ldo3", }, 620 + { .name = "ldo4", }, 621 + { .name = "ldo5", }, 622 + { .name = "ldo6", }, 623 + { .name = "ldo7", }, 624 + { .name = "ldo8", }, 625 + { .name = "ldo9", }, 626 + { .name = "ldoln", }, 627 + { .name = "ldousb", }, 628 + }; 629 + 630 + static void __devinit palmas_dt_to_pdata(struct device *dev, 631 + struct device_node *node, 632 + struct palmas_pmic_platform_data *pdata) 633 + { 634 + struct device_node *regulators; 635 + u32 prop; 636 + int idx, ret; 637 + 638 + regulators = of_find_node_by_name(node, "regulators"); 639 + if (!regulators) { 640 + dev_info(dev, "regulator node not found\n"); 641 + return; 642 + } 643 + 644 + ret = of_regulator_match(dev, regulators, palmas_matches, 645 + PALMAS_NUM_REGS); 646 + if (ret < 0) { 647 + dev_err(dev, "Error parsing regulator init data: %d\n", ret); 648 + return; 649 + } 650 + 651 + for (idx = 0; idx < PALMAS_NUM_REGS; idx++) { 652 + if (!palmas_matches[idx].init_data || 653 + !palmas_matches[idx].of_node) 654 + continue; 655 + 656 + pdata->reg_data[idx] = palmas_matches[idx].init_data; 657 + 658 + pdata->reg_init[idx] = devm_kzalloc(dev, 659 + sizeof(struct palmas_reg_init), GFP_KERNEL); 660 + 661 + ret = of_property_read_u32(palmas_matches[idx].of_node, 662 + "ti,warm_reset", &prop); 663 + if (!ret) 664 + pdata->reg_init[idx]->warm_reset = prop; 665 + 666 + ret = of_property_read_u32(palmas_matches[idx].of_node, 667 + "ti,roof_floor", &prop); 668 + if (!ret) 669 + pdata->reg_init[idx]->roof_floor = prop; 670 + 671 + ret = of_property_read_u32(palmas_matches[idx].of_node, 672 + "ti,mode_sleep", &prop); 673 + if (!ret) 674 + pdata->reg_init[idx]->mode_sleep = prop; 675 + 676 + ret = of_property_read_u32(palmas_matches[idx].of_node, 677 + "ti,warm_reset", &prop); 678 + if (!ret) 679 + pdata->reg_init[idx]->warm_reset = prop; 680 + 681 + ret = of_property_read_u32(palmas_matches[idx].of_node, 682 + "ti,tstep", &prop); 683 + if (!ret) 684 + pdata->reg_init[idx]->tstep = prop; 685 + 686 + ret = of_property_read_u32(palmas_matches[idx].of_node, 687 + "ti,vsel", &prop); 688 + if (!ret) 689 + pdata->reg_init[idx]->vsel = prop; 690 + } 691 + 692 + ret = of_property_read_u32(node, "ti,ldo6_vibrator", &prop); 693 + if (!ret) 694 + pdata->ldo6_vibrator = prop; 695 + } 696 + 697 + 609 698 static __devinit int palmas_probe(struct platform_device *pdev) 610 699 { 611 700 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); 612 701 struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data; 702 + struct device_node *node = pdev->dev.of_node; 613 703 struct regulator_dev *rdev; 614 704 struct regulator_config config = { }; 615 705 struct palmas_pmic *pmic; ··· 710 614 int id = 0, ret; 711 615 unsigned int addr, reg; 712 616 713 - if (!pdata) 714 - return -EINVAL; 715 - if (!pdata->reg_data) 716 - return -EINVAL; 617 + if (node && !pdata) { 618 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 619 + 620 + if (!pdata) 621 + return -ENOMEM; 622 + 623 + palmas_dt_to_pdata(&pdev->dev, node, pdata); 624 + } 717 625 718 626 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); 719 627 if (!pmic) ··· 794 694 pmic->desc[id].owner = THIS_MODULE; 795 695 796 696 /* Initialise sleep/init values from platform data */ 797 - if (pdata && pdata->reg_init) { 697 + if (pdata) { 798 698 reg_init = pdata->reg_init[id]; 799 699 if (reg_init) { 800 700 ret = palmas_smps_init(palmas, id, reg_init); ··· 818 718 pmic->range[id] = 1; 819 719 } 820 720 821 - if (pdata && pdata->reg_data) 721 + if (pdata) 822 722 config.init_data = pdata->reg_data[id]; 823 723 else 824 724 config.init_data = NULL; 725 + 726 + config.of_node = palmas_matches[id].of_node; 825 727 826 728 rdev = regulator_register(&pmic->desc[id], &config); 827 729 if (IS_ERR(rdev)) { ··· 858 756 palmas_regs_info[id].ctrl_addr); 859 757 pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; 860 758 861 - if (pdata && pdata->reg_data) 759 + if (pdata) 862 760 config.init_data = pdata->reg_data[id]; 863 761 else 864 762 config.init_data = NULL; 763 + 764 + config.of_node = palmas_matches[id].of_node; 865 765 866 766 rdev = regulator_register(&pmic->desc[id], &config); 867 767 if (IS_ERR(rdev)) { ··· 878 774 pmic->rdev[id] = rdev; 879 775 880 776 /* Initialise sleep/init values from platform data */ 881 - if (pdata->reg_init) { 777 + if (pdata) { 882 778 reg_init = pdata->reg_init[id]; 883 779 if (reg_init) { 884 780 ret = palmas_ldo_init(palmas, id, reg_init); ··· 906 802 return 0; 907 803 } 908 804 805 + static struct of_device_id __devinitdata of_palmas_match_tbl[] = { 806 + { .compatible = "ti,palmas-pmic", }, 807 + { /* end */ } 808 + }; 809 + 909 810 static struct platform_driver palmas_driver = { 910 811 .driver = { 911 812 .name = "palmas-pmic", 813 + .of_match_table = of_palmas_match_tbl, 912 814 .owner = THIS_MODULE, 913 815 }, 914 816 .probe = palmas_probe, ··· 937 827 MODULE_DESCRIPTION("Palmas voltage regulator driver"); 938 828 MODULE_LICENSE("GPL"); 939 829 MODULE_ALIAS("platform:palmas-pmic"); 830 + MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);