diff options
author | Yadwinder Singh Brar <yadi.brar01@gmail.com> | 2012-07-04 23:58:25 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-05 08:42:06 -0400 |
commit | 4706fcab9b064e6077404ccb6c5ca9c188758068 (patch) | |
tree | 66568c93ff3355ae1200597f2aee8aea813f69a2 /drivers | |
parent | 6c3b956b94a6547d26c805db7c505429e54e7573 (diff) |
regulator: max77686: Add device tree support.
This patch device tree support for regulator driver. It uses the parent
(mfd's) DT node to parse the regulator data for max77686.
Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/regulator/max77686.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index 23f956a6c5f2..fc695eb3886e 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
32 | #include <linux/regulator/driver.h> | 32 | #include <linux/regulator/driver.h> |
33 | #include <linux/regulator/machine.h> | 33 | #include <linux/regulator/machine.h> |
34 | #include <linux/regulator/of_regulator.h> | ||
34 | #include <linux/mfd/max77686.h> | 35 | #include <linux/mfd/max77686.h> |
35 | #include <linux/mfd/max77686-private.h> | 36 | #include <linux/mfd/max77686-private.h> |
36 | 37 | ||
@@ -233,6 +234,50 @@ static struct regulator_desc regulators[] = { | |||
233 | regulator_desc_buck(9), | 234 | regulator_desc_buck(9), |
234 | }; | 235 | }; |
235 | 236 | ||
237 | #ifdef CONFIG_OF | ||
238 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, | ||
239 | struct max77686_platform_data *pdata) | ||
240 | { | ||
241 | struct device_node *pmic_np, *regulators_np; | ||
242 | struct max77686_regulator_data *rdata; | ||
243 | struct of_regulator_match rmatch; | ||
244 | unsigned int i; | ||
245 | |||
246 | pmic_np = iodev->dev->of_node; | ||
247 | regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators"); | ||
248 | if (!regulators_np) { | ||
249 | dev_err(iodev->dev, "could not find regulators sub-node\n"); | ||
250 | return -EINVAL; | ||
251 | } | ||
252 | |||
253 | pdata->num_regulators = ARRAY_SIZE(regulators); | ||
254 | rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * | ||
255 | pdata->num_regulators, GFP_KERNEL); | ||
256 | if (!rdata) { | ||
257 | dev_err(iodev->dev, | ||
258 | "could not allocate memory for regulator data\n"); | ||
259 | return -ENOMEM; | ||
260 | } | ||
261 | |||
262 | for (i = 0; i < pdata->num_regulators; i++) { | ||
263 | rmatch.name = regulators[i].name; | ||
264 | rmatch.init_data = NULL; | ||
265 | of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); | ||
266 | rdata[i].initdata = rmatch.init_data; | ||
267 | } | ||
268 | |||
269 | pdata->regulators = rdata; | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | #else | ||
274 | static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, | ||
275 | struct max77686_platform_data *pdata) | ||
276 | { | ||
277 | return 0; | ||
278 | } | ||
279 | #endif /* CONFIG_OF */ | ||
280 | |||
236 | static __devinit int max77686_pmic_probe(struct platform_device *pdev) | 281 | static __devinit int max77686_pmic_probe(struct platform_device *pdev) |
237 | { | 282 | { |
238 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 283 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
@@ -245,7 +290,18 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev) | |||
245 | 290 | ||
246 | dev_dbg(&pdev->dev, "%s\n", __func__); | 291 | dev_dbg(&pdev->dev, "%s\n", __func__); |
247 | 292 | ||
248 | if (!pdata || pdata->num_regulators != MAX77686_REGULATORS) { | 293 | if (!pdata) { |
294 | dev_err(&pdev->dev, "no platform data found for regulator\n"); | ||
295 | return -ENODEV; | ||
296 | } | ||
297 | |||
298 | if (iodev->dev->of_node) { | ||
299 | ret = max77686_pmic_dt_parse_pdata(iodev, pdata); | ||
300 | if (ret) | ||
301 | return ret; | ||
302 | } | ||
303 | |||
304 | if (pdata->num_regulators != MAX77686_REGULATORS) { | ||
249 | dev_err(&pdev->dev, | 305 | dev_err(&pdev->dev, |
250 | "Invalid initial data for regulator's initialiation\n"); | 306 | "Invalid initial data for regulator's initialiation\n"); |
251 | return -EINVAL; | 307 | return -EINVAL; |