aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/max8997.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/max8997.c')
-rw-r--r--drivers/regulator/max8997.c148
1 files changed, 146 insertions, 2 deletions
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 64cf2ee38f6c..b56c4326853d 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -24,6 +24,7 @@
24#include <linux/bug.h> 24#include <linux/bug.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/gpio.h> 26#include <linux/gpio.h>
27#include <linux/of_gpio.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/module.h> 29#include <linux/module.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
@@ -31,6 +32,7 @@
31#include <linux/regulator/machine.h> 32#include <linux/regulator/machine.h>
32#include <linux/mfd/max8997.h> 33#include <linux/mfd/max8997.h>
33#include <linux/mfd/max8997-private.h> 34#include <linux/mfd/max8997-private.h>
35#include <linux/regulator/of_regulator.h>
34 36
35struct max8997_data { 37struct max8997_data {
36 struct device *dev; 38 struct device *dev;
@@ -933,10 +935,145 @@ static struct regulator_desc regulators[] = {
933 max8997_charger_fixedstate_ops), 935 max8997_charger_fixedstate_ops),
934}; 936};
935 937
938#ifdef CONFIG_OF
939static int max8997_pmic_dt_parse_dvs_gpio(struct max8997_dev *iodev,
940 struct max8997_platform_data *pdata,
941 struct device_node *pmic_np)
942{
943 int i, gpio;
944
945 for (i = 0; i < 3; i++) {
946 gpio = of_get_named_gpio(pmic_np,
947 "max8997,pmic-buck125-dvs-gpios", i);
948 if (!gpio_is_valid(gpio)) {
949 dev_err(iodev->dev, "invalid gpio[%d]: %d\n", i, gpio);
950 return -EINVAL;
951 }
952 pdata->buck125_gpios[i] = gpio;
953 }
954 return 0;
955}
956
957static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
958 struct max8997_platform_data *pdata)
959{
960 struct device_node *pmic_np, *regulators_np, *reg_np;
961 struct max8997_regulator_data *rdata;
962 unsigned int i, dvs_voltage_nr = 1, ret;
963
964 pmic_np = iodev->dev->of_node;
965 if (!pmic_np) {
966 dev_err(iodev->dev, "could not find pmic sub-node\n");
967 return -ENODEV;
968 }
969
970 regulators_np = of_find_node_by_name(pmic_np, "regulators");
971 if (!regulators_np) {
972 dev_err(iodev->dev, "could not find regulators sub-node\n");
973 return -EINVAL;
974 }
975
976 /* count the number of regulators to be supported in pmic */
977 pdata->num_regulators = 0;
978 for_each_child_of_node(regulators_np, reg_np)
979 pdata->num_regulators++;
980
981 rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) *
982 pdata->num_regulators, GFP_KERNEL);
983 if (!rdata) {
984 dev_err(iodev->dev, "could not allocate memory for "
985 "regulator data\n");
986 return -ENOMEM;
987 }
988
989 pdata->regulators = rdata;
990 for_each_child_of_node(regulators_np, reg_np) {
991 for (i = 0; i < ARRAY_SIZE(regulators); i++)
992 if (!of_node_cmp(reg_np->name, regulators[i].name))
993 break;
994
995 if (i == ARRAY_SIZE(regulators)) {
996 dev_warn(iodev->dev, "don't know how to configure "
997 "regulator %s\n", reg_np->name);
998 continue;
999 }
1000
1001 rdata->id = i;
1002 rdata->initdata = of_get_regulator_init_data(
1003 iodev->dev, reg_np);
1004 rdata->reg_node = reg_np;
1005 rdata++;
1006 }
1007
1008 if (of_get_property(pmic_np, "max8997,pmic-buck1-uses-gpio-dvs", NULL))
1009 pdata->buck1_gpiodvs = true;
1010
1011 if (of_get_property(pmic_np, "max8997,pmic-buck2-uses-gpio-dvs", NULL))
1012 pdata->buck2_gpiodvs = true;
1013
1014 if (of_get_property(pmic_np, "max8997,pmic-buck5-uses-gpio-dvs", NULL))
1015 pdata->buck5_gpiodvs = true;
1016
1017 if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||
1018 pdata->buck5_gpiodvs) {
1019 ret = max8997_pmic_dt_parse_dvs_gpio(iodev, pdata, pmic_np);
1020 if (ret)
1021 return -EINVAL;
1022
1023 if (of_property_read_u32(pmic_np,
1024 "max8997,pmic-buck125-default-dvs-idx",
1025 &pdata->buck125_default_idx)) {
1026 pdata->buck125_default_idx = 0;
1027 } else {
1028 if (pdata->buck125_default_idx >= 8) {
1029 pdata->buck125_default_idx = 0;
1030 dev_info(iodev->dev, "invalid value for "
1031 "default dvs index, using 0 instead\n");
1032 }
1033 }
1034
1035 if (of_get_property(pmic_np,
1036 "max8997,pmic-ignore-gpiodvs-side-effect", NULL))
1037 pdata->ignore_gpiodvs_side_effect = true;
1038
1039 dvs_voltage_nr = 8;
1040 }
1041
1042 if (of_property_read_u32_array(pmic_np,
1043 "max8997,pmic-buck1-dvs-voltage",
1044 pdata->buck1_voltage, dvs_voltage_nr)) {
1045 dev_err(iodev->dev, "buck1 voltages not specified\n");
1046 return -EINVAL;
1047 }
1048
1049 if (of_property_read_u32_array(pmic_np,
1050 "max8997,pmic-buck2-dvs-voltage",
1051 pdata->buck2_voltage, dvs_voltage_nr)) {
1052 dev_err(iodev->dev, "buck2 voltages not specified\n");
1053 return -EINVAL;
1054 }
1055
1056 if (of_property_read_u32_array(pmic_np,
1057 "max8997,pmic-buck5-dvs-voltage",
1058 pdata->buck5_voltage, dvs_voltage_nr)) {
1059 dev_err(iodev->dev, "buck5 voltages not specified\n");
1060 return -EINVAL;
1061 }
1062
1063 return 0;
1064}
1065#else
1066static int max8997_pmic_dt_parse_pdata(struct max8997_dev *iodev,
1067 struct max8997_platform_data *pdata)
1068{
1069 return 0;
1070}
1071#endif /* CONFIG_OF */
1072
936static __devinit int max8997_pmic_probe(struct platform_device *pdev) 1073static __devinit int max8997_pmic_probe(struct platform_device *pdev)
937{ 1074{
938 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); 1075 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
939 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); 1076 struct max8997_platform_data *pdata = iodev->pdata;
940 struct regulator_config config = { }; 1077 struct regulator_config config = { };
941 struct regulator_dev **rdev; 1078 struct regulator_dev **rdev;
942 struct max8997_data *max8997; 1079 struct max8997_data *max8997;
@@ -944,11 +1081,17 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
944 int i, ret, size, nr_dvs; 1081 int i, ret, size, nr_dvs;
945 u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0; 1082 u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0;
946 1083
947 if (!pdata) { 1084 if (IS_ERR_OR_NULL(pdata)) {
948 dev_err(pdev->dev.parent, "No platform init data supplied.\n"); 1085 dev_err(pdev->dev.parent, "No platform init data supplied.\n");
949 return -ENODEV; 1086 return -ENODEV;
950 } 1087 }
951 1088
1089 if (iodev->dev->of_node) {
1090 ret = max8997_pmic_dt_parse_pdata(iodev, pdata);
1091 if (ret)
1092 return ret;
1093 }
1094
952 max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), 1095 max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data),
953 GFP_KERNEL); 1096 GFP_KERNEL);
954 if (!max8997) 1097 if (!max8997)
@@ -1104,6 +1247,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
1104 config.dev = max8997->dev; 1247 config.dev = max8997->dev;
1105 config.init_data = pdata->regulators[i].initdata; 1248 config.init_data = pdata->regulators[i].initdata;
1106 config.driver_data = max8997; 1249 config.driver_data = max8997;
1250 config.of_node = pdata->regulators[i].reg_node;
1107 1251
1108 rdev[i] = regulator_register(&regulators[id], &config); 1252 rdev[i] = regulator_register(&regulators[id], &config);
1109 if (IS_ERR(rdev[i])) { 1253 if (IS_ERR(rdev[i])) {