diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2008-01-08 14:20:40 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-01-16 22:53:22 -0500 |
commit | 283029d16a882539ab0027afd94ac52858d050b2 (patch) | |
tree | 78ad81fba51de1fbafd30706f162dc9315690e8b /drivers/of | |
parent | 91bbbe22dbd6d156b7059af13adb26a978a45661 (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')
-rw-r--r-- | drivers/of/base.c | 58 | ||||
-rw-r--r-- | drivers/of/device.c | 29 |
2 files changed, 58 insertions, 29 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 | } |
275 | EXPORT_SYMBOL(of_find_compatible_node); | 275 | EXPORT_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 | */ | ||
284 | const 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 | } | ||
304 | EXPORT_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 | */ | ||
318 | struct 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 | } | ||
333 | EXPORT_SYMBOL(of_find_matching_node); | ||
diff --git a/drivers/of/device.c b/drivers/of/device.c index 6245f060fb77..29681c4b700b 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c | |||
@@ -10,35 +10,6 @@ | |||
10 | #include <asm/errno.h> | 10 | #include <asm/errno.h> |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * of_match_node - Tell if an device_node has a matching of_match structure | ||
14 | * @ids: array of of device match structures to search in | ||
15 | * @node: the of device structure to match against | ||
16 | * | ||
17 | * Low level utility function used by device matching. | ||
18 | */ | ||
19 | const struct of_device_id *of_match_node(const struct of_device_id *matches, | ||
20 | const struct device_node *node) | ||
21 | { | ||
22 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { | ||
23 | int match = 1; | ||
24 | if (matches->name[0]) | ||
25 | match &= node->name | ||
26 | && !strcmp(matches->name, node->name); | ||
27 | if (matches->type[0]) | ||
28 | match &= node->type | ||
29 | && !strcmp(matches->type, node->type); | ||
30 | if (matches->compatible[0]) | ||
31 | match &= of_device_is_compatible(node, | ||
32 | matches->compatible); | ||
33 | if (match) | ||
34 | return matches; | ||
35 | matches++; | ||
36 | } | ||
37 | return NULL; | ||
38 | } | ||
39 | EXPORT_SYMBOL(of_match_node); | ||
40 | |||
41 | /** | ||
42 | * of_match_device - Tell if an of_device structure has a matching | 13 | * of_match_device - Tell if an of_device structure has a matching |
43 | * of_match structure | 14 | * of_match structure |
44 | * @ids: array of of device match structures to search in | 15 | * @ids: array of of device match structures to search in |