From: Naresh Solanki <naresh.solanki@9elements.com>
To: linux-kernel@vger.kernel.org, Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: Laxman Dewangan <ldewangan@nvidia.com>,
Naresh Solanki <Naresh.Solanki@9elements.com>
Subject: [PATCH v4 3/4] regulator: output-supply: Add devicetree support
Date: Thu, 7 Jul 2022 10:18:25 +0200 [thread overview]
Message-ID: <20220707081826.953449-4-Naresh.Solanki@9elements.com> (raw)
In-Reply-To: <20220707081826.953449-1-Naresh.Solanki@9elements.com>
From: Laxman Dewangan <ldewangan@nvidia.com>
Add DT support of the regulator driver output-supply.
The supply names for this driver is provided through DT properties
so that proper regulator(s) handle can be acquired.
Board DT can configure the output-supply driver to
* set regulator name
* turn on at boot time
* specific regulator handles that needs to be controlled by the driver.
Post boot facilitate control of regulator(s) from sysfs.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
drivers/regulator/userspace-consumer.c | 47 ++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 8ca28664776e..b424a0ddf582 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -18,6 +18,7 @@
#include <linux/regulator/consumer.h>
#include <linux/regulator/userspace-consumer.h>
#include <linux/slab.h>
+#include <linux/of.h>
struct userspace_consumer_data {
const char *name;
@@ -100,6 +101,40 @@ static const struct attribute_group attr_group = {
.attrs = attributes,
};
+static struct regulator_userspace_consumer_data *get_pdata_from_dt_node(
+ struct platform_device *pdev)
+{
+ struct regulator_userspace_consumer_data *pdata;
+ struct device_node *np = pdev->dev.of_node;
+ struct property *prop;
+ const char *supply;
+ int num_supplies;
+ int count = 0;
+
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return ERR_PTR(-ENOMEM);
+
+ pdata->name = of_get_property(np, "regulator-name", NULL);
+ pdata->init_on = of_property_read_bool(np, "regulator-boot-on");
+ num_supplies = of_property_count_strings(np, "regulator-supplies");
+ if (num_supplies < 0) {
+ dev_err(&pdev->dev,
+ "could not parse property regulator-supplies\n");
+ return ERR_PTR(-EINVAL);
+ }
+ pdata->num_supplies = num_supplies;
+ pdata->supplies = devm_kzalloc(&pdev->dev, num_supplies *
+ sizeof(*pdata->supplies), GFP_KERNEL);
+ if (!pdata->supplies)
+ return ERR_PTR(-ENOMEM);
+
+ of_property_for_each_string(np, "regulator-supplies", prop, supply)
+ pdata->supplies[count++].supply = supply;
+
+ return pdata;
+}
+
static int regulator_userspace_consumer_probe(struct platform_device *pdev)
{
struct regulator_userspace_consumer_data *pdata;
@@ -107,6 +142,11 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
int ret;
pdata = dev_get_platdata(&pdev->dev);
+ if (!pdata && pdev->dev.of_node) {
+ pdata = get_pdata_from_dt_node(pdev);
+ if (IS_ERR(pdata))
+ return PTR_ERR(pdata);
+ }
if (!pdata)
return -EINVAL;
@@ -166,11 +206,18 @@ static int regulator_userspace_consumer_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id regulator_userspace_consumer_of_match[] = {
+ { .compatible = "9elements,output-supply", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, regulator_userspace_consumer_of_match);
+
static struct platform_driver regulator_userspace_consumer_driver = {
.probe = regulator_userspace_consumer_probe,
.remove = regulator_userspace_consumer_remove,
.driver = {
.name = "reg-userspace-consumer",
+ .of_match_table = regulator_userspace_consumer_of_match,
},
};
--
2.35.3
next prev parent reply other threads:[~2022-07-07 8:20 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-07 8:18 [PATCH v4 0/4] regulator: output-supply DT support Naresh Solanki
2022-07-07 8:18 ` [PATCH v4 1/4] dt-bindings: vendor-prefixes: add 9elements Naresh Solanki
2022-07-11 22:19 ` Rob Herring
2022-07-07 8:18 ` [PATCH v4 2/4] dt-bindings: regulator: add bindings for output-supply Naresh Solanki
2022-07-08 18:33 ` Mark Brown
2022-07-14 14:02 ` Rob Herring
2022-07-14 14:10 ` Rob Herring
2022-07-14 14:14 ` Mark Brown
2022-07-14 14:23 ` Rob Herring
2022-07-14 14:42 ` Mark Brown
2022-07-14 15:07 ` Rob Herring
2022-07-14 15:54 ` Mark Brown
2022-07-14 16:59 ` Rob Herring
2022-07-14 17:50 ` Mark Brown
2022-07-21 8:33 ` Zev Weiss
2022-07-21 11:05 ` Mark Brown
2022-07-07 8:18 ` Naresh Solanki [this message]
2022-07-07 8:18 ` [PATCH v4 4/4] regulator: output-supply: Add Notification support Naresh Solanki
2022-07-11 19:11 ` [PATCH v4 0/4] regulator: output-supply DT support Mark Brown
2022-07-14 14:17 ` Rob Herring
2022-07-14 18:24 ` Mark Brown
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=20220707081826.953449-4-Naresh.Solanki@9elements.com \
--to=naresh.solanki@9elements.com \
--cc=broonie@kernel.org \
--cc=ldewangan@nvidia.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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