aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2008-01-08 14:20:40 -0500
committerPaul Mackerras <paulus@samba.org>2008-01-16 22:53:22 -0500
commit283029d16a882539ab0027afd94ac52858d050b2 (patch)
tree78ad81fba51de1fbafd30706f162dc9315690e8b /drivers/of/base.c
parent91bbbe22dbd6d156b7059af13adb26a978a45661 (diff)
[POWERPC] Add of_find_matching_node() helper function
Similar to of_find_compatible_node(), of_find_matching_node() and for_each_matching_node() allow you to iterate over the device tree looking for specific nodes, except that they take of_device_id tables instead of strings. This also moves of_match_node() from driver/of/device.c to driver/of/base.c to colocate it with the of_find_matching_node which depends on it. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9377f3bc410a..b306fef1ac41 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -273,3 +273,61 @@ struct device_node *of_find_compatible_node(struct device_node *from,
273 return np; 273 return np;
274} 274}
275EXPORT_SYMBOL(of_find_compatible_node); 275EXPORT_SYMBOL(of_find_compatible_node);
276
277/**
278 * of_match_node - Tell if an device_node has a matching of_match structure
279 * @matches: array of of device match structures to search in
280 * @node: the of device structure to match against
281 *
282 * Low level utility function used by device matching.
283 */
284const struct of_device_id *of_match_node(const struct of_device_id *matches,
285 const struct device_node *node)
286{
287 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
288 int match = 1;
289 if (matches->name[0])
290 match &= node->name
291 && !strcmp(matches->name, node->name);
292 if (matches->type[0])
293 match &= node->type
294 && !strcmp(matches->type, node->type);
295 if (matches->compatible[0])
296 match &= of_device_is_compatible(node,
297 matches->compatible);
298 if (match)
299 return matches;
300 matches++;
301 }
302 return NULL;
303}
304EXPORT_SYMBOL(of_match_node);
305
306/**
307 * of_find_matching_node - Find a node based on an of_device_id match
308 * table.
309 * @from: The node to start searching from or NULL, the node
310 * you pass will not be searched, only the next one
311 * will; typically, you pass what the previous call
312 * returned. of_node_put() will be called on it
313 * @matches: array of of device match structures to search in
314 *
315 * Returns a node pointer with refcount incremented, use
316 * of_node_put() on it when done.
317 */
318struct device_node *of_find_matching_node(struct device_node *from,
319 const struct of_device_id *matches)
320{
321 struct device_node *np;
322
323 read_lock(&devtree_lock);
324 np = from ? from->allnext : allnodes;
325 for (; np; np = np->allnext) {
326 if (of_match_node(matches, np) && of_node_get(np))
327 break;
328 }
329 of_node_put(from);
330 read_unlock(&devtree_lock);
331 return np;
332}
333EXPORT_SYMBOL(of_find_matching_node);