aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/prom.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc/kernel/prom.c')
-rw-r--r--arch/sparc/kernel/prom.c173
1 files changed, 2 insertions, 171 deletions
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c
index eed140b3c739..012f98346bcd 100644
--- a/arch/sparc/kernel/prom.c
+++ b/arch/sparc/kernel/prom.c
@@ -25,73 +25,9 @@
25#include <asm/prom.h> 25#include <asm/prom.h>
26#include <asm/oplib.h> 26#include <asm/oplib.h>
27 27
28static struct device_node *allnodes; 28extern struct device_node *allnodes; /* temporary while merging */
29 29
30/* use when traversing tree through the allnext, child, sibling, 30extern rwlock_t devtree_lock; /* temporary while merging */
31 * or parent members of struct device_node.
32 */
33static DEFINE_RWLOCK(devtree_lock);
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)
57{
58 struct device_node *np;
59
60 if (!node)
61 return NULL;
62
63 np = node->parent;
64
65 return np;
66}
67EXPORT_SYMBOL(of_get_parent);
68
69struct device_node *of_get_next_child(const struct device_node *node,
70 struct device_node *prev)
71{
72 struct device_node *next;
73
74 next = prev ? prev->sibling : node->child;
75 for (; next != 0; next = next->sibling) {
76 break;
77 }
78
79 return next;
80}
81EXPORT_SYMBOL(of_get_next_child);
82
83struct device_node *of_find_node_by_path(const char *path)
84{
85 struct device_node *np = allnodes;
86
87 for (; np != 0; np = np->allnext) {
88 if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
89 break;
90 }
91
92 return np;
93}
94EXPORT_SYMBOL(of_find_node_by_path);
95 31
96struct device_node *of_find_node_by_phandle(phandle handle) 32struct device_node *of_find_node_by_phandle(phandle handle)
97{ 33{
@@ -105,81 +41,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
105} 41}
106EXPORT_SYMBOL(of_find_node_by_phandle); 42EXPORT_SYMBOL(of_find_node_by_phandle);
107 43
108struct device_node *of_find_node_by_name(struct device_node *from,
109 const char *name)
110{
111 struct device_node *np;
112
113 np = from ? from->allnext : allnodes;
114 for (; np != NULL; np = np->allnext)
115 if (np->name != NULL && strcmp(np->name, name) == 0)
116 break;
117
118 return np;
119}
120EXPORT_SYMBOL(of_find_node_by_name);
121
122struct device_node *of_find_node_by_type(struct device_node *from,
123 const char *type)
124{
125 struct device_node *np;
126
127 np = from ? from->allnext : allnodes;
128 for (; np != 0; np = np->allnext)
129 if (np->type != 0 && strcmp(np->type, type) == 0)
130 break;
131
132 return np;
133}
134EXPORT_SYMBOL(of_find_node_by_type);
135
136struct device_node *of_find_compatible_node(struct device_node *from,
137 const char *type, const char *compatible)
138{
139 struct device_node *np;
140
141 np = from ? from->allnext : allnodes;
142 for (; np != 0; np = np->allnext) {
143 if (type != NULL
144 && !(np->type != 0 && strcmp(np->type, type) == 0))
145 continue;
146 if (of_device_is_compatible(np, compatible))
147 break;
148 }
149
150 return np;
151}
152EXPORT_SYMBOL(of_find_compatible_node);
153
154struct property *of_find_property(const struct device_node *np,
155 const char *name,
156 int *lenp)
157{
158 struct property *pp;
159
160 for (pp = np->properties; pp != 0; pp = pp->next) {
161 if (strcasecmp(pp->name, name) == 0) {
162 if (lenp != 0)
163 *lenp = pp->length;
164 break;
165 }
166 }
167 return pp;
168}
169EXPORT_SYMBOL(of_find_property);
170
171/*
172 * Find a property with a given name for a given node
173 * and return the value.
174 */
175const void *of_get_property(const struct device_node *np, const char *name,
176 int *lenp)
177{
178 struct property *pp = of_find_property(np,name,lenp);
179 return pp ? pp->value : NULL;
180}
181EXPORT_SYMBOL(of_get_property);
182
183int of_getintprop_default(struct device_node *np, const char *name, int def) 44int of_getintprop_default(struct device_node *np, const char *name, int def)
184{ 45{
185 struct property *prop; 46 struct property *prop;
@@ -193,36 +54,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def)
193} 54}
194EXPORT_SYMBOL(of_getintprop_default); 55EXPORT_SYMBOL(of_getintprop_default);
195 56
196int of_n_addr_cells(struct device_node *np)
197{
198 const int* ip;
199 do {
200 if (np->parent)
201 np = np->parent;
202 ip = of_get_property(np, "#address-cells", NULL);
203 if (ip != NULL)
204 return *ip;
205 } while (np->parent);
206 /* No #address-cells property for the root node, default to 2 */
207 return 2;
208}
209EXPORT_SYMBOL(of_n_addr_cells);
210
211int of_n_size_cells(struct device_node *np)
212{
213 const int* ip;
214 do {
215 if (np->parent)
216 np = np->parent;
217 ip = of_get_property(np, "#size-cells", NULL);
218 if (ip != NULL)
219 return *ip;
220 } while (np->parent);
221 /* No #size-cells property for the root node, default to 1 */
222 return 1;
223}
224EXPORT_SYMBOL(of_n_size_cells);
225
226int of_set_property(struct device_node *dp, const char *name, void *val, int len) 57int of_set_property(struct device_node *dp, const char *name, void *val, int len)
227{ 58{
228 struct property **prevp; 59 struct property **prevp;