Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 302253
b: refs/heads/master
c: 1c8fa58
h: refs/heads/master
i:
  302251: d292219
v: v3
  • Loading branch information
Thierry Reding authored and Mark Brown committed May 4, 2012
1 parent 9f8e3ad commit b1ca844
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 82caa9780a85a97e45e4df6e1f228279707bdcfe
refs/heads/master: 1c8fa58f4750e9ad722fbf899866c312ffabab67
47 changes: 47 additions & 0 deletions trunk/drivers/regulator/of_regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>

static void of_get_regulation_constraints(struct device_node *np,
struct regulator_init_data **init_data)
Expand Down Expand Up @@ -85,3 +86,49 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
return init_data;
}
EXPORT_SYMBOL_GPL(of_get_regulator_init_data);

/**
* of_regulator_match - extract regulator init data
* @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. 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(struct device *dev, struct device_node *node,
struct of_regulator_match *matches,
unsigned int num_matches)
{
unsigned int count = 0;
unsigned int i;

if (!dev || !node)
return -EINVAL;

for (i = 0; i < num_matches; i++) {
struct of_regulator_match *match = &matches[i];
struct device_node *child;

child = of_find_node_by_name(node, match->name);
if (!child)
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);
18 changes: 18 additions & 0 deletions trunk/include/linux/regulator/of_regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,35 @@
#ifndef __LINUX_OF_REG_H
#define __LINUX_OF_REG_H

struct of_regulator_match {
const char *name;
void *driver_data;
struct regulator_init_data *init_data;
struct device_node *of_node;
};

#if defined(CONFIG_OF)
extern struct regulator_init_data
*of_get_regulator_init_data(struct device *dev,
struct device_node *node);
extern int of_regulator_match(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,
struct device_node *node)
{
return NULL;
}

static inline int of_regulator_match(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 */

0 comments on commit b1ca844

Please sign in to comment.