devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rhyland Klein <rklein@nvidia.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>, Liam Girdwood <lrg@ti.com>
Cc: linux-kernel@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org,
	Rhyland Klein <rklein@nvidia.com>
Subject: [PATCH 1/8 v2] regulator: add generic of node parsing for regulators
Date: Tue, 24 Apr 2012 16:36:03 -0700	[thread overview]
Message-ID: <1335310570-12455-2-git-send-email-rklein@nvidia.com> (raw)
In-Reply-To: <1335310570-12455-1-git-send-email-rklein@nvidia.com>

As more regulators are moved to support dt, more drivers are going to need
to do lookups to find nodes associated with specific regulators. Add this
helper function which will find all the regulator_init_data for a series of
regulators and do some minimal dt validation checks.

Signed-off-by: Rhyland Klein <rklein@nvidia.com>
---
 v2: split off from tps65910 particular code to a more generic form based
     on initial reviews.

 drivers/regulator/of_regulator.c       |   42 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |    9 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 679734d..45a5f85 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -85,3 +85,45 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
 	return init_data;
 }
 EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
+
+/**
+ * of_find_regulator_init_data_from_device - extract all regulator_init_data
+ * @dev: device requesting for regulator_init_data
+ * @node: device node from which to look for the regulators
+ * @names: array of the names of the regulators for which to look for nodes
+ * @init_data: array of regulator_init_data structure pointers to populate
+ * @num_regulators: the max number of regulators expected
+ *
+ * This function populates the array of regulator_init_data structures by
+ * finding the device_nodes which respresent each regulator and extracting
+ * data. Returns 0 on success.
+ */
+int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	struct device_node *child = NULL;
+	int idx = 0;
+
+	if (!dev || !node)
+		return -EINVAL;
+
+	for (idx = 0; idx < num_regulators; idx++) {
+		struct device_node *np = of_find_node_by_name(node, names[idx]);
+
+		/* didn't find a match, thats fine */
+		if (!np)
+			continue;
+
+		/* parse regulator init data from node */
+		init_data[idx] = of_get_regulator_init_data(dev, np);
+		if (!init_data[idx]) {
+			dev_err(dev, "failed to parse dt for regulator %s\n",
+				child->name);
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_find_regulator_init_data_from_device);
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index 769704f..0c65dcb 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -10,6 +10,9 @@
 extern struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
 				    struct device_node *node);
+extern int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators);
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
@@ -17,6 +20,12 @@ static inline struct regulator_init_data
 {
 	return NULL;
 }
+static inline int of_find_regulator_init_data_from_device(struct device *dev,
+	struct device_node *node, const char * const names[],
+	struct regulator_init_data **init_data, int num_regulators)
+{
+	return 0;
+}
 #endif /* CONFIG_OF */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.0.4

  reply	other threads:[~2012-04-24 23:36 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-24 23:36 [PATCH 0/8 v2] Update TPS65910 to boot using devicetree Rhyland Klein
2012-04-24 23:36 ` Rhyland Klein [this message]
     [not found] ` <1335310570-12455-1-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2012-04-24 23:36   ` [PATCH 2/8 v2] regulator: add node validation checks Rhyland Klein
2012-04-24 23:36 ` [PATCH 3/8 v2] mfd: tps65910: Commonize regmap access through header Rhyland Klein
2012-05-17 23:52   ` Grant Likely
2012-04-24 23:36 ` [PATCH 4/8 v2] regulator: tps65910: Add device tree bindings Rhyland Klein
2012-05-17 23:53   ` Grant Likely
2012-04-24 23:36 ` [PATCH 5/8 v2] mfd: tps65910: Add device-tree support Rhyland Klein
2012-05-17 23:55   ` Grant Likely
2012-04-24 23:36 ` [PATCH 6/8 v2] regulator: tps65910 regulator: add device tree support Rhyland Klein
2012-04-24 23:36 ` [PATCH 7/8 v2] mfd: tps65910-irq: Add devicetree init support Rhyland Klein
2012-05-18  0:00   ` Grant Likely
2012-04-24 23:36 ` [PATCH 8/8 v2] ARM: Tegra: Add support for TPS65910 PMIC Rhyland Klein

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=1335310570-12455-2-git-send-email-rklein@nvidia.com \
    --to=rklein@nvidia.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=rob.herring@calxeda.com \
    --cc=sameo@linux.intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).