mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Naresh Solanki <naresh.solanki@9elements.com>
To: zev@bewilderbeest.net, Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>
Cc: Naresh Solanki <Naresh.Solanki@9elements.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] regulator: userspace-consumer: Support multiple supplies in DT
Date: Thu, 20 Apr 2023 21:24:02 +0200	[thread overview]
Message-ID: <20230420192402.3695265-2-Naresh.Solanki@9elements.com> (raw)
In-Reply-To: <20230420192402.3695265-1-Naresh.Solanki@9elements.com>

Add support for optional DT property 'regulator-supplies' to handle
connectors with multiple supplies.

If this property is present, it will determine all regulator supplies.
Otherwise, the 'vout' supply will be used as a fallback.

This change improves support for some connector output like PCIe
connectors on mainboards that can be powered by 12V and 3.3V supplies.

Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
...
Change in V2:
- Update commit message
- Code improved to add fallback if the property isn't used.
---
 drivers/regulator/userspace-consumer.c | 33 +++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 97f075ed68c9..aaa0189d6dab 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -120,7 +120,10 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 	struct regulator_userspace_consumer_data tmpdata;
 	struct regulator_userspace_consumer_data *pdata;
 	struct userspace_consumer_data *drvdata;
-	int ret;
+	struct device_node *np = pdev->dev.of_node;
+	struct property *prop;
+	const char *supply;
+	int ret, count = 0;
 
 	pdata = dev_get_platdata(&pdev->dev);
 	if (!pdata) {
@@ -131,11 +134,29 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 		memset(pdata, 0, sizeof(*pdata));
 
 		pdata->no_autoswitch = true;
-		pdata->num_supplies = 1;
-		pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies), GFP_KERNEL);
-		if (!pdata->supplies)
-			return -ENOMEM;
-		pdata->supplies[0].supply = "vout";
+
+		if (of_find_property(np, "regulator-supplies", NULL)) {
+			pdata->num_supplies = of_property_count_strings(np, "regulator-supplies");
+			if (pdata->num_supplies < 1) {
+				dev_err(&pdev->dev,
+					"could not parse property regulator-supplies\n");
+				return -EINVAL;
+			}
+			pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies) *
+						       pdata->num_supplies, GFP_KERNEL);
+			if (!pdata->supplies)
+				return -ENOMEM;
+			of_property_for_each_string(np, "regulator-supplies", prop, supply) {
+				pdata->supplies[count++].supply = supply;
+			}
+		} else {
+			pdata->num_supplies = 1;
+			pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies),
+						       GFP_KERNEL);
+			if (!pdata->supplies)
+				return -ENOMEM;
+			pdata->supplies[0].supply = "vout";
+		}
 	}
 
 	if (pdata->num_supplies < 1) {
-- 
2.39.1


  reply	other threads:[~2023-04-20 19:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 19:24 [PATCH v2 1/2] dt-bindings: regulator: Add support for multiple supplies Naresh Solanki
2023-04-20 19:24 ` Naresh Solanki [this message]
2023-04-21 21:36 ` Rob Herring
2023-04-24  8:52   ` Naresh Solanki
2023-05-03  8:03     ` Naresh Solanki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230420192402.3695265-2-Naresh.Solanki@9elements.com \
    --to=naresh.solanki@9elements.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zev@bewilderbeest.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®