aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--arch/powerpc/kernel/ibmebus.c1
-rw-r--r--arch/powerpc/kernel/of_platform.c1
-rw-r--r--arch/powerpc/platforms/celleb/io-workarounds.c1
-rw-r--r--arch/powerpc/platforms/celleb/pci.c1
-rw-r--r--drivers/net/ibm_newemac/core.c1
-rw-r--r--drivers/of/base.c58
-rw-r--r--drivers/of/device.c29
-rw-r--r--drivers/serial/mpc52xx_uart.c3
-rw-r--r--include/linux/of.h8
-rw-r--r--include/linux/of_device.h2
10 files changed, 73 insertions, 32 deletions
diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
index caae49ff0668..3b708449f731 100644
--- a/arch/powerpc/kernel/ibmebus.c
+++ b/arch/powerpc/kernel/ibmebus.c
@@ -41,6 +41,7 @@
41#include <linux/kobject.h> 41#include <linux/kobject.h>
42#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/of.h>
44#include <linux/of_platform.h> 45#include <linux/of_platform.h>
45#include <asm/ibmebus.h> 46#include <asm/ibmebus.h>
46#include <asm/abs_addr.h> 47#include <asm/abs_addr.h>
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index de36e235a60a..7a3cafbe8af9 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -19,6 +19,7 @@
19#include <linux/mod_devicetable.h> 19#include <linux/mod_devicetable.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/of.h>
22#include <linux/of_device.h> 23#include <linux/of_device.h>
23#include <linux/of_platform.h> 24#include <linux/of_platform.h>
24 25
diff --git a/arch/powerpc/platforms/celleb/io-workarounds.c b/arch/powerpc/platforms/celleb/io-workarounds.c
index b939c0e98af8..423339be1bac 100644
--- a/arch/powerpc/platforms/celleb/io-workarounds.c
+++ b/arch/powerpc/platforms/celleb/io-workarounds.c
@@ -22,6 +22,7 @@
22 22
23#undef DEBUG 23#undef DEBUG
24 24
25#include <linux/of.h>
25#include <linux/of_device.h> 26#include <linux/of_device.h>
26#include <linux/irq.h> 27#include <linux/irq.h>
27 28
diff --git a/arch/powerpc/platforms/celleb/pci.c b/arch/powerpc/platforms/celleb/pci.c
index 5d399e038c23..51b390d34e4d 100644
--- a/arch/powerpc/platforms/celleb/pci.c
+++ b/arch/powerpc/platforms/celleb/pci.c
@@ -31,6 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/bootmem.h> 32#include <linux/bootmem.h>
33#include <linux/pci_regs.h> 33#include <linux/pci_regs.h>
34#include <linux/of.h>
34#include <linux/of_device.h> 35#include <linux/of_device.h>
35 36
36#include <asm/io.h> 37#include <asm/io.h>
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index cb06280dced5..fced441face6 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -37,6 +37,7 @@
37#include <linux/mii.h> 37#include <linux/mii.h>
38#include <linux/bitops.h> 38#include <linux/bitops.h>
39#include <linux/workqueue.h> 39#include <linux/workqueue.h>
40#include <linux/of.h>
40 41
41#include <asm/processor.h> 42#include <asm/processor.h>
42#include <asm/io.h> 43#include <asm/io.h>
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);
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 */
19const 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}
39EXPORT_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
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index ec36ad78d2fe..7e3ba8b455a8 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -72,7 +72,8 @@
72#include <asm/io.h> 72#include <asm/io.h>
73 73
74#if defined(CONFIG_PPC_MERGE) 74#if defined(CONFIG_PPC_MERGE)
75#include <asm/of_platform.h> 75#include <linux/of.h>
76#include <linux/of_platform.h>
76#else 77#else
77#include <linux/platform_device.h> 78#include <linux/platform_device.h>
78#endif 79#endif
diff --git a/include/linux/of.h b/include/linux/of.h
index c65af7bd1e9c..b5f33efcb8e2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/bitops.h> 19#include <linux/bitops.h>
20#include <linux/mod_devicetable.h>
20 21
21#include <asm/prom.h> 22#include <asm/prom.h>
22 23
@@ -41,6 +42,11 @@ extern struct device_node *of_find_compatible_node(struct device_node *from,
41#define for_each_compatible_node(dn, type, compatible) \ 42#define for_each_compatible_node(dn, type, compatible) \
42 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ 43 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
43 dn = of_find_compatible_node(dn, type, compatible)) 44 dn = of_find_compatible_node(dn, type, compatible))
45extern struct device_node *of_find_matching_node(struct device_node *from,
46 const struct of_device_id *matches);
47#define for_each_matching_node(dn, matches) \
48 for (dn = of_find_matching_node(NULL, matches); dn; \
49 dn = of_find_matching_node(dn, matches))
44extern struct device_node *of_find_node_by_path(const char *path); 50extern struct device_node *of_find_node_by_path(const char *path);
45extern struct device_node *of_find_node_by_phandle(phandle handle); 51extern struct device_node *of_find_node_by_phandle(phandle handle);
46extern struct device_node *of_get_parent(const struct device_node *node); 52extern struct device_node *of_get_parent(const struct device_node *node);
@@ -60,5 +66,7 @@ extern const void *of_get_property(const struct device_node *node,
60 int *lenp); 66 int *lenp);
61extern int of_n_addr_cells(struct device_node *np); 67extern int of_n_addr_cells(struct device_node *np);
62extern int of_n_size_cells(struct device_node *np); 68extern int of_n_size_cells(struct device_node *np);
69extern const struct of_device_id *of_match_node(
70 const struct of_device_id *matches, const struct device_node *node);
63 71
64#endif /* _LINUX_OF_H */ 72#endif /* _LINUX_OF_H */
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 212bffb2b174..6dc11959770c 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -10,8 +10,6 @@
10 10
11#define to_of_device(d) container_of(d, struct of_device, dev) 11#define to_of_device(d) container_of(d, struct of_device, dev)
12 12
13extern const struct of_device_id *of_match_node(
14 const struct of_device_id *matches, const struct device_node *node);
15extern const struct of_device_id *of_match_device( 13extern const struct of_device_id *of_match_device(
16 const struct of_device_id *matches, const struct of_device *dev); 14 const struct of_device_id *matches, const struct of_device *dev);
17 15