diff options
author | Thierry Reding <thierry.reding@avionic-design.de> | 2012-04-26 10:52:20 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-05-04 08:25:15 -0400 |
commit | 1c8fa58f4750e9ad722fbf899866c312ffabab67 (patch) | |
tree | bd7aa14a3d78d17da9eb7c7638a66562f78b6f9f /drivers/regulator | |
parent | 82caa9780a85a97e45e4df6e1f228279707bdcfe (diff) |
regulator: Add generic DT parsing for regulators
Looking up init data for regulators found on chips is a common operation
that can be handled in a generic way. The new helper function introduced
by this patch looks up the children of a given node by names specified
in a match table and fills that match table with information parsed from
the DT.
This is based on work by Rhyland Klein <rklein@nvidia.com>.
Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/of_regulator.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 679734d26a1..56593b75168 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/of.h> | 15 | #include <linux/of.h> |
16 | #include <linux/regulator/machine.h> | 16 | #include <linux/regulator/machine.h> |
17 | #include <linux/regulator/of_regulator.h> | ||
17 | 18 | ||
18 | static void of_get_regulation_constraints(struct device_node *np, | 19 | static void of_get_regulation_constraints(struct device_node *np, |
19 | struct regulator_init_data **init_data) | 20 | struct regulator_init_data **init_data) |
@@ -85,3 +86,49 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, | |||
85 | return init_data; | 86 | return init_data; |
86 | } | 87 | } |
87 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); | 88 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); |
89 | |||
90 | /** | ||
91 | * of_regulator_match - extract regulator init data | ||
92 | * @dev: device requesting the data | ||
93 | * @node: parent device node of the regulators | ||
94 | * @matches: match table for the regulators | ||
95 | * @num_matches: number of entries in match table | ||
96 | * | ||
97 | * This function uses a match table specified by the regulator driver and | ||
98 | * looks up the corresponding init data in the device tree. Note that the | ||
99 | * match table is modified in place. | ||
100 | * | ||
101 | * Returns the number of matches found or a negative error code on failure. | ||
102 | */ | ||
103 | int of_regulator_match(struct device *dev, struct device_node *node, | ||
104 | struct of_regulator_match *matches, | ||
105 | unsigned int num_matches) | ||
106 | { | ||
107 | unsigned int count = 0; | ||
108 | unsigned int i; | ||
109 | |||
110 | if (!dev || !node) | ||
111 | return -EINVAL; | ||
112 | |||
113 | for (i = 0; i < num_matches; i++) { | ||
114 | struct of_regulator_match *match = &matches[i]; | ||
115 | struct device_node *child; | ||
116 | |||
117 | child = of_find_node_by_name(node, match->name); | ||
118 | if (!child) | ||
119 | continue; | ||
120 | |||
121 | match->init_data = of_get_regulator_init_data(dev, child); | ||
122 | if (!match->init_data) { | ||
123 | dev_err(dev, "failed to parse DT for regulator %s\n", | ||
124 | child->name); | ||
125 | return -EINVAL; | ||
126 | } | ||
127 | |||
128 | match->of_node = child; | ||
129 | count++; | ||
130 | } | ||
131 | |||
132 | return count; | ||
133 | } | ||
134 | EXPORT_SYMBOL_GPL(of_regulator_match); | ||