devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laxman Dewangan <ldewangan@nvidia.com>
To: broonie@opensource.wolfsonmicro.com, lrg@ti.com,
	rob.herring@calxeda.com, grant.likely@secretlab.ca,
	swarren@wwwdotorg.org
Cc: sameo@linux.intel.com, devicetree-discuss@lists.ozlabs.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Laxman Dewangan <ldewangan@nvidia.com>
Subject: [PATCH 1/2] regulator: support for regulator match by regulator-compatible
Date: Tue, 19 Jun 2012 11:21:26 +0530	[thread overview]
Message-ID: <1340085087-6608-2-git-send-email-ldewangan@nvidia.com> (raw)
In-Reply-To: <1340085087-6608-1-git-send-email-ldewangan@nvidia.com>

Add API to match the chip regulator's id by the
property of "regulator-compatible" on regulator node.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
 drivers/regulator/of_regulator.c       |   61 ++++++++++++++++++++++++++++++++
 include/linux/regulator/of_regulator.h |   13 +++++++
 2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index e2a7310..3dc9be1 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -136,3 +136,64 @@ int of_regulator_match(struct device *dev, struct device_node *node,
 	return count;
 }
 EXPORT_SYMBOL_GPL(of_regulator_match);
+
+/**
+ * of_regulator_match_by_compatible - extract regulator init data when
+ * regulator-compatible matches.
+ * @dev: device requesting the data
+ * @node: parent device node of the regulators
+ * @matches: match table for the regulators
+ * @num_matches: number of entries in match table
+ *
+ * This function uses a match table specified by the regulator
+ * driver and looks up the corresponding init data in the device
+ * tree if regulator-compatible matches. Note that the match
+ * table is modified in place.
+ *
+ * Returns the number of matches found or a negative error code on failure.
+ */
+int of_regulator_match_by_compatible(struct device *dev,
+			struct device_node *node,
+			struct of_regulator_match *matches,
+			unsigned int num_matches)
+{
+	unsigned int count = 0;
+	unsigned int i;
+	const char *regulator_comp;
+	struct device_node *child;
+
+	if (!dev || !node)
+		return -EINVAL;
+
+	for_each_child_of_node(node, child) {
+		regulator_comp = of_get_property(child,
+					"regulator-compatible", NULL);
+		if (!regulator_comp) {
+			dev_err(dev, "regulator-compatible is missing for node %s\n",
+				child->name);
+			continue;
+		}
+		for (i = 0; i < num_matches; i++) {
+			struct of_regulator_match *match = &matches[i];
+			if (match->of_node)
+				continue;
+
+			if (strcmp(match->name, regulator_comp))
+				continue;
+
+			match->init_data =
+				of_get_regulator_init_data(dev, child);
+			if (!match->init_data) {
+				dev_err(dev,
+					"failed to parse DT for regulator %s\n",
+					child->name);
+				return -EINVAL;
+			}
+			match->of_node = child;
+			count++;
+		}
+	}
+
+	return count;
+}
+EXPORT_SYMBOL_GPL(of_regulator_match_by_compatible);
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index f921796..e3469a0 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -20,6 +20,11 @@ extern struct regulator_init_data
 extern int of_regulator_match(struct device *dev, struct device_node *node,
 			      struct of_regulator_match *matches,
 			      unsigned int num_matches);
+extern int of_regulator_match_by_compatible(struct device *dev,
+			struct device_node *node,
+			struct of_regulator_match *matches,
+			unsigned int num_matches);
+
 #else
 static inline struct regulator_init_data
 	*of_get_regulator_init_data(struct device *dev,
@@ -35,6 +40,14 @@ static inline int of_regulator_match(struct device *dev,
 {
 	return 0;
 }
+
+static inline int of_regulator_match_by_compatible(struct device *dev,
+			struct device_node *node,
+			struct of_regulator_match *matches,
+			unsigned int num_matches)
+{
+	return 0;
+}
 #endif /* CONFIG_OF */
 
 #endif /* __LINUX_OF_REG_H */
-- 
1.7.1.1

  reply	other threads:[~2012-06-19  5:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-19  5:51 [PATCH 0/2] regulator: tps65910: dt: identify regulator by prop regulator-compatible Laxman Dewangan
2012-06-19  5:51 ` Laxman Dewangan [this message]
2012-06-19  9:32   ` [PATCH 1/2] regulator: support for regulator match by regulator-compatible Mark Brown
2012-06-19  9:34     ` Laxman Dewangan
2012-06-19 10:43       ` Mark Brown
2012-06-19 10:37         ` Laxman Dewangan
2012-06-19 12:06         ` Laxman Dewangan
2012-06-19 12:18           ` Mark Brown
2012-06-19  5:51 ` [PATCH 2/2] regulator: tps65910: dt: identify regulator " Laxman Dewangan

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