diff options
Diffstat (limited to 'include/linux/of.h')
-rw-r--r-- | include/linux/of.h | 153 |
1 files changed, 84 insertions, 69 deletions
diff --git a/include/linux/of.h b/include/linux/of.h index b59f2e41c7ce..83d1ac80c91e 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -169,35 +169,15 @@ static inline const char *of_node_full_name(const struct device_node *np) | |||
169 | 169 | ||
170 | extern struct device_node *of_find_node_by_name(struct device_node *from, | 170 | extern struct device_node *of_find_node_by_name(struct device_node *from, |
171 | const char *name); | 171 | const char *name); |
172 | #define for_each_node_by_name(dn, name) \ | ||
173 | for (dn = of_find_node_by_name(NULL, name); dn; \ | ||
174 | dn = of_find_node_by_name(dn, name)) | ||
175 | extern struct device_node *of_find_node_by_type(struct device_node *from, | 172 | extern struct device_node *of_find_node_by_type(struct device_node *from, |
176 | const char *type); | 173 | const char *type); |
177 | #define for_each_node_by_type(dn, type) \ | ||
178 | for (dn = of_find_node_by_type(NULL, type); dn; \ | ||
179 | dn = of_find_node_by_type(dn, type)) | ||
180 | extern struct device_node *of_find_compatible_node(struct device_node *from, | 174 | extern struct device_node *of_find_compatible_node(struct device_node *from, |
181 | const char *type, const char *compat); | 175 | const char *type, const char *compat); |
182 | #define for_each_compatible_node(dn, type, compatible) \ | ||
183 | for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ | ||
184 | dn = of_find_compatible_node(dn, type, compatible)) | ||
185 | extern struct device_node *of_find_matching_node_and_match( | 176 | extern struct device_node *of_find_matching_node_and_match( |
186 | struct device_node *from, | 177 | struct device_node *from, |
187 | const struct of_device_id *matches, | 178 | const struct of_device_id *matches, |
188 | const struct of_device_id **match); | 179 | const struct of_device_id **match); |
189 | static inline struct device_node *of_find_matching_node( | 180 | |
190 | struct device_node *from, | ||
191 | const struct of_device_id *matches) | ||
192 | { | ||
193 | return of_find_matching_node_and_match(from, matches, NULL); | ||
194 | } | ||
195 | #define for_each_matching_node(dn, matches) \ | ||
196 | for (dn = of_find_matching_node(NULL, matches); dn; \ | ||
197 | dn = of_find_matching_node(dn, matches)) | ||
198 | #define for_each_matching_node_and_match(dn, matches, match) \ | ||
199 | for (dn = of_find_matching_node_and_match(NULL, matches, match); \ | ||
200 | dn; dn = of_find_matching_node_and_match(dn, matches, match)) | ||
201 | extern struct device_node *of_find_node_by_path(const char *path); | 181 | extern struct device_node *of_find_node_by_path(const char *path); |
202 | extern struct device_node *of_find_node_by_phandle(phandle handle); | 182 | extern struct device_node *of_find_node_by_phandle(phandle handle); |
203 | extern struct device_node *of_get_parent(const struct device_node *node); | 183 | extern struct device_node *of_get_parent(const struct device_node *node); |
@@ -209,43 +189,11 @@ extern struct device_node *of_get_next_available_child( | |||
209 | 189 | ||
210 | extern struct device_node *of_get_child_by_name(const struct device_node *node, | 190 | extern struct device_node *of_get_child_by_name(const struct device_node *node, |
211 | const char *name); | 191 | const char *name); |
212 | #define for_each_child_of_node(parent, child) \ | ||
213 | for (child = of_get_next_child(parent, NULL); child != NULL; \ | ||
214 | child = of_get_next_child(parent, child)) | ||
215 | |||
216 | #define for_each_available_child_of_node(parent, child) \ | ||
217 | for (child = of_get_next_available_child(parent, NULL); child != NULL; \ | ||
218 | child = of_get_next_available_child(parent, child)) | ||
219 | |||
220 | static inline int of_get_child_count(const struct device_node *np) | ||
221 | { | ||
222 | struct device_node *child; | ||
223 | int num = 0; | ||
224 | |||
225 | for_each_child_of_node(np, child) | ||
226 | num++; | ||
227 | |||
228 | return num; | ||
229 | } | ||
230 | |||
231 | static inline int of_get_available_child_count(const struct device_node *np) | ||
232 | { | ||
233 | struct device_node *child; | ||
234 | int num = 0; | ||
235 | |||
236 | for_each_available_child_of_node(np, child) | ||
237 | num++; | ||
238 | |||
239 | return num; | ||
240 | } | ||
241 | 192 | ||
242 | /* cache lookup */ | 193 | /* cache lookup */ |
243 | extern struct device_node *of_find_next_cache_node(const struct device_node *); | 194 | extern struct device_node *of_find_next_cache_node(const struct device_node *); |
244 | extern struct device_node *of_find_node_with_property( | 195 | extern struct device_node *of_find_node_with_property( |
245 | struct device_node *from, const char *prop_name); | 196 | struct device_node *from, const char *prop_name); |
246 | #define for_each_node_with_property(dn, prop_name) \ | ||
247 | for (dn = of_find_node_with_property(NULL, prop_name); dn; \ | ||
248 | dn = of_find_node_with_property(dn, prop_name)) | ||
249 | 197 | ||
250 | extern struct property *of_find_property(const struct device_node *np, | 198 | extern struct property *of_find_property(const struct device_node *np, |
251 | const char *name, | 199 | const char *name, |
@@ -369,42 +317,53 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from, | |||
369 | return NULL; | 317 | return NULL; |
370 | } | 318 | } |
371 | 319 | ||
372 | static inline struct device_node *of_get_parent(const struct device_node *node) | 320 | static inline struct device_node *of_find_node_by_type(struct device_node *from, |
321 | const char *type) | ||
373 | { | 322 | { |
374 | return NULL; | 323 | return NULL; |
375 | } | 324 | } |
376 | 325 | ||
377 | static inline bool of_have_populated_dt(void) | 326 | static inline struct device_node *of_find_matching_node_and_match( |
327 | struct device_node *from, | ||
328 | const struct of_device_id *matches, | ||
329 | const struct of_device_id **match) | ||
378 | { | 330 | { |
379 | return false; | 331 | return NULL; |
380 | } | 332 | } |
381 | 333 | ||
382 | /* Kill an unused variable warning on a device_node pointer */ | 334 | static inline struct device_node *of_get_parent(const struct device_node *node) |
383 | static inline void __of_use_dn(const struct device_node *np) | ||
384 | { | 335 | { |
336 | return NULL; | ||
385 | } | 337 | } |
386 | 338 | ||
387 | #define for_each_child_of_node(parent, child) \ | 339 | static inline struct device_node *of_get_next_child( |
388 | while (__of_use_dn(parent), __of_use_dn(child), 0) | 340 | const struct device_node *node, struct device_node *prev) |
341 | { | ||
342 | return NULL; | ||
343 | } | ||
389 | 344 | ||
390 | #define for_each_available_child_of_node(parent, child) \ | 345 | static inline struct device_node *of_get_next_available_child( |
391 | while (0) | 346 | const struct device_node *node, struct device_node *prev) |
347 | { | ||
348 | return NULL; | ||
349 | } | ||
392 | 350 | ||
393 | static inline struct device_node *of_get_child_by_name( | 351 | static inline struct device_node *of_find_node_with_property( |
394 | const struct device_node *node, | 352 | struct device_node *from, const char *prop_name) |
395 | const char *name) | ||
396 | { | 353 | { |
397 | return NULL; | 354 | return NULL; |
398 | } | 355 | } |
399 | 356 | ||
400 | static inline int of_get_child_count(const struct device_node *np) | 357 | static inline bool of_have_populated_dt(void) |
401 | { | 358 | { |
402 | return 0; | 359 | return false; |
403 | } | 360 | } |
404 | 361 | ||
405 | static inline int of_get_available_child_count(const struct device_node *np) | 362 | static inline struct device_node *of_get_child_by_name( |
363 | const struct device_node *node, | ||
364 | const char *name) | ||
406 | { | 365 | { |
407 | return 0; | 366 | return NULL; |
408 | } | 367 | } |
409 | 368 | ||
410 | static inline int of_device_is_compatible(const struct device_node *device, | 369 | static inline int of_device_is_compatible(const struct device_node *device, |
@@ -577,6 +536,13 @@ extern int of_node_to_nid(struct device_node *np); | |||
577 | static inline int of_node_to_nid(struct device_node *device) { return 0; } | 536 | static inline int of_node_to_nid(struct device_node *device) { return 0; } |
578 | #endif | 537 | #endif |
579 | 538 | ||
539 | static inline struct device_node *of_find_matching_node( | ||
540 | struct device_node *from, | ||
541 | const struct of_device_id *matches) | ||
542 | { | ||
543 | return of_find_matching_node_and_match(from, matches, NULL); | ||
544 | } | ||
545 | |||
580 | /** | 546 | /** |
581 | * of_property_count_u8_elems - Count the number of u8 elements in a property | 547 | * of_property_count_u8_elems - Count the number of u8 elements in a property |
582 | * | 548 | * |
@@ -694,6 +660,55 @@ static inline int of_property_read_u32(const struct device_node *np, | |||
694 | s; \ | 660 | s; \ |
695 | s = of_prop_next_string(prop, s)) | 661 | s = of_prop_next_string(prop, s)) |
696 | 662 | ||
663 | #define for_each_node_by_name(dn, name) \ | ||
664 | for (dn = of_find_node_by_name(NULL, name); dn; \ | ||
665 | dn = of_find_node_by_name(dn, name)) | ||
666 | #define for_each_node_by_type(dn, type) \ | ||
667 | for (dn = of_find_node_by_type(NULL, type); dn; \ | ||
668 | dn = of_find_node_by_type(dn, type)) | ||
669 | #define for_each_compatible_node(dn, type, compatible) \ | ||
670 | for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ | ||
671 | dn = of_find_compatible_node(dn, type, compatible)) | ||
672 | #define for_each_matching_node(dn, matches) \ | ||
673 | for (dn = of_find_matching_node(NULL, matches); dn; \ | ||
674 | dn = of_find_matching_node(dn, matches)) | ||
675 | #define for_each_matching_node_and_match(dn, matches, match) \ | ||
676 | for (dn = of_find_matching_node_and_match(NULL, matches, match); \ | ||
677 | dn; dn = of_find_matching_node_and_match(dn, matches, match)) | ||
678 | |||
679 | #define for_each_child_of_node(parent, child) \ | ||
680 | for (child = of_get_next_child(parent, NULL); child != NULL; \ | ||
681 | child = of_get_next_child(parent, child)) | ||
682 | #define for_each_available_child_of_node(parent, child) \ | ||
683 | for (child = of_get_next_available_child(parent, NULL); child != NULL; \ | ||
684 | child = of_get_next_available_child(parent, child)) | ||
685 | |||
686 | #define for_each_node_with_property(dn, prop_name) \ | ||
687 | for (dn = of_find_node_with_property(NULL, prop_name); dn; \ | ||
688 | dn = of_find_node_with_property(dn, prop_name)) | ||
689 | |||
690 | static inline int of_get_child_count(const struct device_node *np) | ||
691 | { | ||
692 | struct device_node *child; | ||
693 | int num = 0; | ||
694 | |||
695 | for_each_child_of_node(np, child) | ||
696 | num++; | ||
697 | |||
698 | return num; | ||
699 | } | ||
700 | |||
701 | static inline int of_get_available_child_count(const struct device_node *np) | ||
702 | { | ||
703 | struct device_node *child; | ||
704 | int num = 0; | ||
705 | |||
706 | for_each_available_child_of_node(np, child) | ||
707 | num++; | ||
708 | |||
709 | return num; | ||
710 | } | ||
711 | |||
697 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) | 712 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) |
698 | extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *); | 713 | extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *); |
699 | extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop); | 714 | extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop); |