From bc24ae6701928ec7f3ff1fbf127701b7225d6abc Mon Sep 17 00:00:00 2001 From: Yadwinder Singh Brar Date: Thu, 5 Jul 2012 09:28:25 +0530 Subject: [PATCH] --- yaml --- r: 312615 b: refs/heads/master c: 4706fcab9b064e6077404ccb6c5ca9c188758068 h: refs/heads/master i: 312613: f7028153da7280231feb3c524918d3ccf6370c7b 312611: b4af9e03d310b17787ca7e4d297dfbd82027992d 312607: 3ee5bf6476d035318ee279789982c386d0daae02 v: v3 --- [refs] | 2 +- trunk/drivers/regulator/max77686.c | 58 +++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/[refs] b/[refs] index b107f5e5ce50..236184571839 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 6c3b956b94a6547d26c805db7c505429e54e7573 +refs/heads/master: 4706fcab9b064e6077404ccb6c5ca9c188758068 diff --git a/trunk/drivers/regulator/max77686.c b/trunk/drivers/regulator/max77686.c index 23f956a6c5f2..fc695eb3886e 100644 --- a/trunk/drivers/regulator/max77686.c +++ b/trunk/drivers/regulator/max77686.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -233,6 +234,50 @@ static struct regulator_desc regulators[] = { regulator_desc_buck(9), }; +#ifdef CONFIG_OF +static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, + struct max77686_platform_data *pdata) +{ + struct device_node *pmic_np, *regulators_np; + struct max77686_regulator_data *rdata; + struct of_regulator_match rmatch; + unsigned int i; + + pmic_np = iodev->dev->of_node; + regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators"); + if (!regulators_np) { + dev_err(iodev->dev, "could not find regulators sub-node\n"); + return -EINVAL; + } + + pdata->num_regulators = ARRAY_SIZE(regulators); + rdata = devm_kzalloc(iodev->dev, sizeof(*rdata) * + pdata->num_regulators, GFP_KERNEL); + if (!rdata) { + dev_err(iodev->dev, + "could not allocate memory for regulator data\n"); + return -ENOMEM; + } + + for (i = 0; i < pdata->num_regulators; i++) { + rmatch.name = regulators[i].name; + rmatch.init_data = NULL; + of_regulator_match(iodev->dev, regulators_np, &rmatch, 1); + rdata[i].initdata = rmatch.init_data; + } + + pdata->regulators = rdata; + + return 0; +} +#else +static int max77686_pmic_dt_parse_pdata(struct max77686_dev *iodev, + struct max77686_platform_data *pdata) +{ + return 0; +} +#endif /* CONFIG_OF */ + static __devinit int max77686_pmic_probe(struct platform_device *pdev) { struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); @@ -245,7 +290,18 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "%s\n", __func__); - if (!pdata || pdata->num_regulators != MAX77686_REGULATORS) { + if (!pdata) { + dev_err(&pdev->dev, "no platform data found for regulator\n"); + return -ENODEV; + } + + if (iodev->dev->of_node) { + ret = max77686_pmic_dt_parse_pdata(iodev, pdata); + if (ret) + return ret; + } + + if (pdata->num_regulators != MAX77686_REGULATORS) { dev_err(&pdev->dev, "Invalid initial data for regulator's initialiation\n"); return -EINVAL;