[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230420192402.3695265-2-Naresh.Solanki@9elements.com>
Date: Thu, 20 Apr 2023 21:24:02 +0200
From: Naresh Solanki <naresh.solanki@...ements.com>
To: zev@...ilderbeest.net, Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>
Cc: Naresh Solanki <Naresh.Solanki@...ements.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 2/2] regulator: userspace-consumer: Support multiple supplies in DT
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@...ements.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
Powered by blists - more mailing lists