aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2007-05-01 02:29:19 -0400
committerStephen Rothwell <sfr@canb.auug.org.au>2007-07-19 23:29:51 -0400
commit0081cbc3731de8ad4744ba433af51f17bf27eb9c (patch)
treeb03e5c4b7087ad78a230722850a29a72b2960663
parent97e873e5c8ad8711ce4cca080cff4eb5d21b3aeb (diff)
Consolidate of_device_is_compatible
The only difference here is that Sparc uses strncmp to match compatibility names while PowerPC uses strncasecmp. Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Paul Mackerras <paulus@samba.org> Acked-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/powerpc/kernel/prom.c25
-rw-r--r--arch/sparc/kernel/prom.c21
-rw-r--r--arch/sparc64/kernel/prom.c21
-rw-r--r--drivers/of/base.c24
-rw-r--r--include/asm-powerpc/prom.h2
-rw-r--r--include/asm-sparc/prom.h2
-rw-r--r--include/asm-sparc64/prom.h2
7 files changed, 30 insertions, 67 deletions
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 6c9419a4d70a..c009d2155f9c 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -1057,31 +1057,6 @@ void __init early_init_devtree(void *params)
1057} 1057}
1058 1058
1059 1059
1060/** Checks if the given "compat" string matches one of the strings in
1061 * the device's "compatible" property
1062 */
1063int of_device_is_compatible(const struct device_node *device,
1064 const char *compat)
1065{
1066 const char* cp;
1067 int cplen, l;
1068
1069 cp = of_get_property(device, "compatible", &cplen);
1070 if (cp == NULL)
1071 return 0;
1072 while (cplen > 0) {
1073 if (strncasecmp(cp, compat, strlen(compat)) == 0)
1074 return 1;
1075 l = strlen(cp) + 1;
1076 cp += l;
1077 cplen -= l;
1078 }
1079
1080 return 0;
1081}
1082EXPORT_SYMBOL(of_device_is_compatible);
1083
1084
1085/** 1060/**
1086 * Indicates whether the root node has a given value in its 1061 * Indicates whether the root node has a given value in its
1087 * compatible property. 1062 * compatible property.
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c
index ac3f3c29b174..f2ce0d48e102 100644
--- a/arch/sparc/kernel/prom.c
+++ b/arch/sparc/kernel/prom.c
@@ -32,27 +32,6 @@ static struct device_node *allnodes;
32 */ 32 */
33static DEFINE_RWLOCK(devtree_lock); 33static DEFINE_RWLOCK(devtree_lock);
34 34
35int of_device_is_compatible(const struct device_node *device,
36 const char *compat)
37{
38 const char* cp;
39 int cplen, l;
40
41 cp = of_get_property(device, "compatible", &cplen);
42 if (cp == NULL)
43 return 0;
44 while (cplen > 0) {
45 if (strncmp(cp, compat, strlen(compat)) == 0)
46 return 1;
47 l = strlen(cp) + 1;
48 cp += l;
49 cplen -= l;
50 }
51
52 return 0;
53}
54EXPORT_SYMBOL(of_device_is_compatible);
55
56struct device_node *of_get_parent(const struct device_node *node) 35struct device_node *of_get_parent(const struct device_node *node)
57{ 36{
58 struct device_node *np; 37 struct device_node *np;
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c
index 8f926d439c0f..4d6fb07f047f 100644
--- a/arch/sparc64/kernel/prom.c
+++ b/arch/sparc64/kernel/prom.c
@@ -37,27 +37,6 @@ static struct device_node *allnodes;
37 */ 37 */
38static DEFINE_RWLOCK(devtree_lock); 38static DEFINE_RWLOCK(devtree_lock);
39 39
40int of_device_is_compatible(const struct device_node *device,
41 const char *compat)
42{
43 const char* cp;
44 int cplen, l;
45
46 cp = of_get_property(device, "compatible", &cplen);
47 if (cp == NULL)
48 return 0;
49 while (cplen > 0) {
50 if (strncmp(cp, compat, strlen(compat)) == 0)
51 return 1;
52 l = strlen(cp) + 1;
53 cp += l;
54 cplen -= l;
55 }
56
57 return 0;
58}
59EXPORT_SYMBOL(of_device_is_compatible);
60
61struct device_node *of_get_parent(const struct device_node *node) 40struct device_node *of_get_parent(const struct device_node *node)
62{ 41{
63 struct device_node *np; 42 struct device_node *np;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 723d80d704e0..d6dc5e74c27c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -63,3 +63,27 @@ const void *of_get_property(const struct device_node *np, const char *name,
63 return pp ? pp->value : NULL; 63 return pp ? pp->value : NULL;
64} 64}
65EXPORT_SYMBOL(of_get_property); 65EXPORT_SYMBOL(of_get_property);
66
67/** Checks if the given "compat" string matches one of the strings in
68 * the device's "compatible" property
69 */
70int of_device_is_compatible(const struct device_node *device,
71 const char *compat)
72{
73 const char* cp;
74 int cplen, l;
75
76 cp = of_get_property(device, "compatible", &cplen);
77 if (cp == NULL)
78 return 0;
79 while (cplen > 0) {
80 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
81 return 1;
82 l = strlen(cp) + 1;
83 cp += l;
84 cplen -= l;
85 }
86
87 return 0;
88}
89EXPORT_SYMBOL(of_device_is_compatible);
diff --git a/include/asm-powerpc/prom.h b/include/asm-powerpc/prom.h
index 9fe0152ae245..b05f8f26940a 100644
--- a/include/asm-powerpc/prom.h
+++ b/include/asm-powerpc/prom.h
@@ -24,6 +24,8 @@
24#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1 24#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
25#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 25#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
26 26
27#define of_compat_cmp(s1, s2, l) strncasecmp((s1), (s2), (l))
28
27/* Definitions used by the flattened device tree */ 29/* Definitions used by the flattened device tree */
28#define OF_DT_HEADER 0xd00dfeed /* marker */ 30#define OF_DT_HEADER 0xd00dfeed /* marker */
29#define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ 31#define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h
index a8a121f6332b..c755c69404f7 100644
--- a/include/asm-sparc/prom.h
+++ b/include/asm-sparc/prom.h
@@ -23,6 +23,8 @@
23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2 23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
25 25
26#define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l))
27
26typedef u32 phandle; 28typedef u32 phandle;
27typedef u32 ihandle; 29typedef u32 ihandle;
28 30
diff --git a/include/asm-sparc64/prom.h b/include/asm-sparc64/prom.h
index c98d1545ee8d..040d198ee842 100644
--- a/include/asm-sparc64/prom.h
+++ b/include/asm-sparc64/prom.h
@@ -23,6 +23,8 @@
23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2 23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
25 25
26#define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l))
27
26typedef u32 phandle; 28typedef u32 phandle;
27typedef u32 ihandle; 29typedef u32 ihandle;
28 30