lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 24 Apr 2012 16:36:03 -0700
From:	Rhyland Klein <rklein@...dia.com>
To:	Mark Brown <broonie@...nsource.wolfsonmicro.com>,
	Samuel Ortiz <sameo@...ux.intel.com>,
	Grant Likely <grant.likely@...retlab.ca>,
	Rob Herring <rob.herring@...xeda.com>,
	Liam Girdwood <lrg@...com>
CC:	<linux-kernel@...r.kernel.org>,
	<devicetree-discuss@...ts.ozlabs.org>,
	Rhyland Klein <rklein@...dia.com>
Subject: [PATCH 1/8 v2] regulator: add generic of node parsing for regulators

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@...dia.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ