linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: mc13783: Add device tree probe support
@ 2013-04-07 17:02 Alexander Shiyan
  2013-04-07 19:21 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Shiyan @ 2013-04-07 17:02 UTC (permalink / raw)
  To: linux-arm-kernel

Patch adds device tree probe support for mc13783-regulator driver.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/regulator/mc13783-regulator.c      | 55 ++++++++++++++++++++++--------
 drivers/regulator/mc13xxx-regulator-core.c |  2 ++
 2 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index c46c670..fba8d5e 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -398,33 +398,62 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
 	struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
 	struct mc13xxx_regulator_platform_data *pdata =
 		dev_get_platdata(&pdev->dev);
-	struct mc13xxx_regulator_init_data *init_data;
+	struct mc13xxx_regulator_init_data *mc13xxx_data;
 	struct regulator_config config = { };
-	int i, ret;
+	int i, ret, num_regulators, num_parsed;
 
-	dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id);
+	num_regulators = mc13xxx_get_num_regulators_dt(pdev);
 
-	if (!pdata)
+	if (num_regulators <= 0 && pdata)
+		num_regulators = pdata->num_regulators;
+	if (num_regulators <= 0)
 		return -EINVAL;
 
+	num_parsed = num_regulators;
+
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +
-			pdata->num_regulators * sizeof(priv->regulators[0]),
+			num_regulators * sizeof(priv->regulators[0]),
 			GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
+	priv->num_regulators = num_regulators;
 	priv->mc13xxx_regulators = mc13783_regulators;
 	priv->mc13xxx = mc13783;
+	platform_set_drvdata(pdev, priv);
 
-	for (i = 0; i < pdata->num_regulators; i++) {
-		struct regulator_desc *desc;
+	mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13783_regulators,
+					ARRAY_SIZE(mc13783_regulators),
+					&num_parsed);
+	if (num_parsed != num_regulators) {
+		dev_warn(&pdev->dev,
+		"parsed %d != regulators %d - check your device tree!\n",
+			num_parsed, num_regulators);
 
-		init_data = &pdata->regulators[i];
-		desc = &mc13783_regulators[init_data->id].desc;
+		num_regulators = num_parsed;
+		priv->num_regulators = num_regulators;
+	}
+
+	for (i = 0; i < num_regulators; i++) {
+		struct regulator_init_data *init_data;
+		struct regulator_desc *desc;
+		struct device_node *node = NULL;
+		int id;
+
+		if (mc13xxx_data) {
+			id = mc13xxx_data[i].id;
+			init_data = mc13xxx_data[i].init_data;
+			node = mc13xxx_data[i].node;
+		} else {
+			id = pdata->regulators[i].id;
+			init_data = pdata->regulators[i].init_data;
+		}
+		desc = &mc13783_regulators[id].desc;
 
 		config.dev = &pdev->dev;
-		config.init_data = init_data->init_data;
+		config.init_data = init_data;
 		config.driver_data = priv;
+		config.of_node = node;
 
 		priv->regulators[i] = regulator_register(desc, &config);
 		if (IS_ERR(priv->regulators[i])) {
@@ -435,8 +464,6 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
 		}
 	}
 
-	platform_set_drvdata(pdev, priv);
-
 	return 0;
 err:
 	while (--i >= 0)
@@ -448,13 +475,11 @@ err:
 static int mc13783_regulator_remove(struct platform_device *pdev)
 {
 	struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
-	struct mc13xxx_regulator_platform_data *pdata =
-		dev_get_platdata(&pdev->dev);
 	int i;
 
 	platform_set_drvdata(pdev, NULL);
 
-	for (i = 0; i < pdata->num_regulators; i++)
+	for (i = 0; i < priv->num_regulators; i++)
 		regulator_unregister(priv->regulators[i]);
 
 	return 0;
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index 23cf9f9..836e21e 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -205,6 +205,8 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
 
 	for_each_child_of_node(parent, child) {
 		for (i = 0; i < num_regulators; i++) {
+			if (!regulators[i].desc.name)
+				continue;
 			if (!of_node_cmp(child->name,
 					 regulators[i].desc.name)) {
 
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] regulator: mc13783: Add device tree probe support
  2013-04-07 17:02 [PATCH] regulator: mc13783: Add device tree probe support Alexander Shiyan
@ 2013-04-07 19:21 ` Mark Brown
  2013-04-08 16:46   ` Re[2]: " Alexander Shiyan
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2013-04-07 19:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 07, 2013 at 09:02:11PM +0400, Alexander Shiyan wrote:
> Patch adds device tree probe support for mc13783-regulator driver.

I'd expect to see a document describing the binding for any new binding.

> +	if (num_parsed != num_regulators) {
> +		dev_warn(&pdev->dev,
> +		"parsed %d != regulators %d - check your device tree!\n",
> +			num_parsed, num_regulators);
>  
> -		init_data = &pdata->regulators[i];
> -		desc = &mc13783_regulators[init_data->id].desc;
> +		num_regulators = num_parsed;
> +		priv->num_regulators = num_regulators;

Why is this something we warn about?  Users should be able to omit
unused regulators, no point in adding nodes that don't have any real
information.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130407/e27f66d2/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re[2]: [PATCH] regulator: mc13783: Add device tree probe support
  2013-04-07 19:21 ` Mark Brown
@ 2013-04-08 16:46   ` Alexander Shiyan
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Shiyan @ 2013-04-08 16:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hello.

> On Sun, Apr 07, 2013 at 09:02:11PM +0400, Alexander Shiyan wrote:
> > Patch adds device tree probe support for mc13783-regulator driver.
> 
> I'd expect to see a document describing the binding for any new binding.
OK.
 
> > +	if (num_parsed != num_regulators) {
> > +		dev_warn(&pdev->dev,
> > +		"parsed %d != regulators %d - check your device tree!\n",
> > +			num_parsed, num_regulators);
> >  
> > -		init_data = &pdata->regulators[i];
> > -		desc = &mc13783_regulators[init_data->id].desc;
> > +		num_regulators = num_parsed;
> > +		priv->num_regulators = num_regulators;
> 
> Why is this something we warn about?  Users should be able to omit
> unused regulators, no point in adding nodes that don't have any real
> information.

Warning is appear on nonexistent regulators names only.
I will rewrite warning procedure in the v2 globally for mc13xx.
Thanks.

---

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-08 16:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-07 17:02 [PATCH] regulator: mc13783: Add device tree probe support Alexander Shiyan
2013-04-07 19:21 ` Mark Brown
2013-04-08 16:46   ` Re[2]: " Alexander Shiyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).