aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/mc13xxx-regulator-core.c
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2011-12-21 10:00:46 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-12-22 06:10:45 -0500
commit93bcb23b38f634e8fb4ddda0d3f4862fda5cedae (patch)
tree9f087497a7511022c8e740c3e16bb3703efc4fda /drivers/regulator/mc13xxx-regulator-core.c
parent3a5d03158d0174ae700e15b63eab2023f27aeb88 (diff)
regulator: mc13892: add device tree probe support
It adds device tree probe support for mc13892-regulator driver. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/mc13xxx-regulator-core.c')
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index 6532853a6ef5..80ecafef1bc3 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -18,12 +18,14 @@
18#include <linux/mfd/mc13xxx.h> 18#include <linux/mfd/mc13xxx.h>
19#include <linux/regulator/machine.h> 19#include <linux/regulator/machine.h>
20#include <linux/regulator/driver.h> 20#include <linux/regulator/driver.h>
21#include <linux/regulator/of_regulator.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/init.h> 25#include <linux/init.h>
25#include <linux/err.h> 26#include <linux/err.h>
26#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/of.h>
27#include "mc13xxx.h" 29#include "mc13xxx.h"
28 30
29static int mc13xxx_regulator_enable(struct regulator_dev *rdev) 31static int mc13xxx_regulator_enable(struct regulator_dev *rdev)
@@ -236,6 +238,61 @@ int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev)
236} 238}
237EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled); 239EXPORT_SYMBOL_GPL(mc13xxx_sw_regulator_is_enabled);
238 240
241#ifdef CONFIG_OF
242int __devinit mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
243{
244 struct device_node *parent, *child;
245 int num = 0;
246
247 of_node_get(pdev->dev.parent->of_node);
248 parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
249 if (!parent)
250 return -ENODEV;
251
252 for_each_child_of_node(parent, child)
253 num++;
254
255 return num;
256}
257
258struct mc13xxx_regulator_init_data * __devinit mc13xxx_parse_regulators_dt(
259 struct platform_device *pdev, struct mc13xxx_regulator *regulators,
260 int num_regulators)
261{
262 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
263 struct mc13xxx_regulator_init_data *data, *p;
264 struct device_node *parent, *child;
265 int i;
266
267 of_node_get(pdev->dev.parent->of_node);
268 parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
269 if (!parent)
270 return NULL;
271
272 data = devm_kzalloc(&pdev->dev, sizeof(*data) * priv->num_regulators,
273 GFP_KERNEL);
274 if (!data)
275 return NULL;
276 p = data;
277
278 for_each_child_of_node(parent, child) {
279 for (i = 0; i < num_regulators; i++) {
280 if (!of_node_cmp(child->name,
281 regulators[i].desc.name)) {
282 p->id = i;
283 p->init_data = of_get_regulator_init_data(
284 &pdev->dev, child);
285 p->node = child;
286 p++;
287 break;
288 }
289 }
290 }
291
292 return data;
293}
294#endif
295
239MODULE_LICENSE("GPL v2"); 296MODULE_LICENSE("GPL v2");
240MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>"); 297MODULE_AUTHOR("Yong Shen <yong.shen@linaro.org>");
241MODULE_DESCRIPTION("Regulator Driver for Freescale MC13xxx PMIC"); 298MODULE_DESCRIPTION("Regulator Driver for Freescale MC13xxx PMIC");