diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mfd/max8997.c | 73 | ||||
-rw-r--r-- | drivers/regulator/max8997.c | 148 |
2 files changed, 218 insertions, 3 deletions
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index f123517065e..abd5c80c7cf 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c | |||
@@ -21,8 +21,10 @@ | |||
21 | * This driver is based on max8998.c | 21 | * This driver is based on max8998.c |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/err.h> | ||
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
25 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/of_irq.h> | ||
26 | #include <linux/interrupt.h> | 28 | #include <linux/interrupt.h> |
27 | #include <linux/pm_runtime.h> | 29 | #include <linux/pm_runtime.h> |
28 | #include <linux/module.h> | 30 | #include <linux/module.h> |
@@ -47,6 +49,13 @@ static struct mfd_cell max8997_devs[] = { | |||
47 | { .name = "max8997-led", .id = 2 }, | 49 | { .name = "max8997-led", .id = 2 }, |
48 | }; | 50 | }; |
49 | 51 | ||
52 | #ifdef CONFIG_OF | ||
53 | static struct of_device_id __devinitdata max8997_pmic_dt_match[] = { | ||
54 | { .compatible = "maxim,max8997-pmic", .data = TYPE_MAX8997 }, | ||
55 | {}, | ||
56 | }; | ||
57 | #endif | ||
58 | |||
50 | int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) | 59 | int max8997_read_reg(struct i2c_client *i2c, u8 reg, u8 *dest) |
51 | { | 60 | { |
52 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); | 61 | struct max8997_dev *max8997 = i2c_get_clientdata(i2c); |
@@ -123,6 +132,58 @@ int max8997_update_reg(struct i2c_client *i2c, u8 reg, u8 val, u8 mask) | |||
123 | } | 132 | } |
124 | EXPORT_SYMBOL_GPL(max8997_update_reg); | 133 | EXPORT_SYMBOL_GPL(max8997_update_reg); |
125 | 134 | ||
135 | #ifdef CONFIG_OF | ||
136 | /* | ||
137 | * Only the common platform data elements for max8997 are parsed here from the | ||
138 | * device tree. Other sub-modules of max8997 such as pmic, rtc and others have | ||
139 | * to parse their own platform data elements from device tree. | ||
140 | * | ||
141 | * The max8997 platform data structure is instantiated here and the drivers for | ||
142 | * the sub-modules need not instantiate another instance while parsing their | ||
143 | * platform data. | ||
144 | */ | ||
145 | static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( | ||
146 | struct device *dev) | ||
147 | { | ||
148 | struct max8997_platform_data *pd; | ||
149 | |||
150 | pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); | ||
151 | if (!pd) { | ||
152 | dev_err(dev, "could not allocate memory for pdata\n"); | ||
153 | return ERR_PTR(-ENOMEM); | ||
154 | } | ||
155 | |||
156 | pd->ono = irq_of_parse_and_map(dev->of_node, 1); | ||
157 | |||
158 | /* | ||
159 | * ToDo: the 'wakeup' member in the platform data is more of a linux | ||
160 | * specfic information. Hence, there is no binding for that yet and | ||
161 | * not parsed here. | ||
162 | */ | ||
163 | |||
164 | return pd; | ||
165 | } | ||
166 | #else | ||
167 | static struct max8997_platform_data *max8997_i2c_parse_dt_pdata( | ||
168 | struct device *dev) | ||
169 | { | ||
170 | return 0; | ||
171 | } | ||
172 | #endif | ||
173 | |||
174 | static inline int max8997_i2c_get_driver_data(struct i2c_client *i2c, | ||
175 | const struct i2c_device_id *id) | ||
176 | { | ||
177 | #ifdef CONFIG_OF | ||
178 | if (i2c->dev.of_node) { | ||
179 | const struct of_device_id *match; | ||
180 | match = of_match_node(max8997_pmic_dt_match, i2c->dev.of_node); | ||
181 | return (int)match->data; | ||
182 | } | ||
183 | #endif | ||
184 | return (int)id->driver_data; | ||
185 | } | ||
186 | |||
126 | static int max8997_i2c_probe(struct i2c_client *i2c, | 187 | static int max8997_i2c_probe(struct i2c_client *i2c, |
127 | const struct i2c_device_id *id) | 188 | const struct i2c_device_id *id) |
128 | { | 189 | { |
@@ -137,12 +198,21 @@ static int max8997_i2c_probe(struct i2c_client *i2c, | |||
137 | i2c_set_clientdata(i2c, max8997); | 198 | i2c_set_clientdata(i2c, max8997); |
138 | max8997->dev = &i2c->dev; | 199 | max8997->dev = &i2c->dev; |
139 | max8997->i2c = i2c; | 200 | max8997->i2c = i2c; |
140 | max8997->type = id->driver_data; | 201 | max8997->type = max8997_i2c_get_driver_data(i2c, id); |
141 | max8997->irq = i2c->irq; | 202 | max8997->irq = i2c->irq; |
142 | 203 | ||
204 | if (max8997->dev->of_node) { | ||
205 | pdata = max8997_i2c_parse_dt_pdata(max8997->dev); | ||
206 | if (IS_ERR(pdata)) { | ||
207 | ret = PTR_ERR(pdata); | ||
208 | goto err; | ||
209 | } | ||
210 | } | ||
211 | |||
143 | if (!pdata) | 212 | if (!pdata) |
144 | goto err; | 213 | goto err; |
145 | 214 | ||
215 | max8997->pdata = pdata; | ||
146 | max8997->ono = pdata->ono; | 216 | max8997->ono = pdata->ono; |
147 | 217 | ||
148 | mutex_init(&max8997->iolock); | 218 | mutex_init(&max8997->iolock); |
@@ -434,6 +504,7 @@ static struct i2c_driver max8997_i2c_driver = { | |||
434 | .name = "max8997", | 504 | .name = "max8997", |
435 | .owner = THIS_MODULE, | 505 | .owner = THIS_MODULE, |
436 | .pm = &max8997_pm, | 506 | .pm = &max8997_pm, |
507 | .of_match_table = of_match_ptr(max8997_pmic_dt_match), | ||
437 | }, | 508 | }, |
438 | .probe = max8997_i2c_probe, | 509 | .probe = max8997_i2c_probe, |
439 | .remove = max8997_i2c_remove, | 510 | .remove = max8997_i2c_remove, |
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 64cf2ee38f6..b56c4326853 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 | ||
35 | struct max8997_data { | 37 | struct 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 | ||
939 | static 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 | |||
957 | static 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 | ||
1066 | static 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 | |||
936 | static __devinit int max8997_pmic_probe(struct platform_device *pdev) | 1073 | static __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(®ulators[id], &config); | 1252 | rdev[i] = regulator_register(®ulators[id], &config); |
1109 | if (IS_ERR(rdev[i])) { | 1253 | if (IS_ERR(rdev[i])) { |