From: Naresh Solanki <naresh.solanki@9elements.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: zev@bewilderbeest.net,
Naresh Solanki <Naresh.Solanki@9elements.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] regulator: userspace-consumer: Retrieve supplies from DT
Date: Wed, 23 Aug 2023 22:35:30 +0200 [thread overview]
Message-ID: <20230823203531.1382044-1-Naresh.Solanki@9elements.com> (raw)
Instead of hardcoding a single supply, retrieve supplies from DT.
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
drivers/regulator/userspace-consumer.c | 43 ++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index a0b980022993..830681446807 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -153,11 +153,32 @@ static int regulator_userspace_notify(struct notifier_block *nb,
return NOTIFY_OK;
}
+#define SUPPLY_SUFFIX "-supply"
+#define SUPPLY_SUFFIX_LEN 7
+
+static int get_num_supplies(struct platform_device *pdev)
+{
+ struct property *prop;
+ int num_supplies = 0;
+
+ for_each_property_of_node(pdev->dev.of_node, prop) {
+ const char *prop_name = prop->name;
+ int len = strlen(prop_name);
+
+ if (len > SUPPLY_SUFFIX_LEN && \
+ strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0) {
+ num_supplies++;
+ }
+ }
+ return num_supplies;
+}
+
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;
+ struct property *prop;
int i, ret;
pdata = dev_get_platdata(&pdev->dev);
@@ -169,11 +190,27 @@ 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);
+ pdata->num_supplies = get_num_supplies(pdev);
+
+ pdata->supplies = devm_kzalloc(&pdev->dev, pdata->num_supplies * \
+ sizeof(*pdata->supplies), GFP_KERNEL);
if (!pdata->supplies)
return -ENOMEM;
- pdata->supplies[0].supply = "vout";
+
+ for_each_property_of_node(pdev->dev.of_node, prop) {
+ const char *prop_name = prop->name;
+ int len = strlen(prop_name);
+
+ if (len > 7 && \
+ strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0) {
+ char *supply_name = devm_kzalloc(&pdev->dev,
+ len - SUPPLY_SUFFIX_LEN + 1,
+ GFP_KERNEL);
+ strscpy(supply_name, prop_name, len - SUPPLY_SUFFIX_LEN);
+ supply_name[len - SUPPLY_SUFFIX_LEN] = '\0';
+ pdata->supplies[0].supply = supply_name;
+ }
+ }
}
if (pdata->num_supplies < 1) {
base-commit: 8950c4a350c188deb5f5b05df3244d4db82fe3d8
--
2.41.0
next reply other threads:[~2023-08-23 20:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 20:35 Naresh Solanki [this message]
2023-09-19 6:17 Naresh Solanki
2023-09-19 15:50 ` kernel test robot
2023-09-19 19:52 ` kernel test robot
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=20230823203531.1382044-1-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
Powered by JetHome