diff options
Diffstat (limited to 'include/linux/of.h')
-rw-r--r-- | include/linux/of.h | 229 |
1 files changed, 160 insertions, 69 deletions
diff --git a/include/linux/of.h b/include/linux/of.h index 70c64ba17fa5..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,47 +189,17 @@ 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, |
252 | int *lenp); | 200 | int *lenp); |
201 | extern int of_property_count_elems_of_size(const struct device_node *np, | ||
202 | const char *propname, int elem_size); | ||
253 | extern int of_property_read_u32_index(const struct device_node *np, | 203 | extern int of_property_read_u32_index(const struct device_node *np, |
254 | const char *propname, | 204 | const char *propname, |
255 | u32 index, u32 *out_value); | 205 | u32 index, u32 *out_value); |
@@ -367,42 +317,53 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from, | |||
367 | return NULL; | 317 | return NULL; |
368 | } | 318 | } |
369 | 319 | ||
370 | 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) | ||
371 | { | 322 | { |
372 | return NULL; | 323 | return NULL; |
373 | } | 324 | } |
374 | 325 | ||
375 | 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) | ||
376 | { | 330 | { |
377 | return false; | 331 | return NULL; |
378 | } | 332 | } |
379 | 333 | ||
380 | /* Kill an unused variable warning on a device_node pointer */ | 334 | static inline struct device_node *of_get_parent(const struct device_node *node) |
381 | static inline void __of_use_dn(const struct device_node *np) | ||
382 | { | 335 | { |
336 | return NULL; | ||
383 | } | 337 | } |
384 | 338 | ||
385 | #define for_each_child_of_node(parent, child) \ | 339 | static inline struct device_node *of_get_next_child( |
386 | 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 | } | ||
387 | 344 | ||
388 | #define for_each_available_child_of_node(parent, child) \ | 345 | static inline struct device_node *of_get_next_available_child( |
389 | while (0) | 346 | const struct device_node *node, struct device_node *prev) |
347 | { | ||
348 | return NULL; | ||
349 | } | ||
390 | 350 | ||
391 | static inline struct device_node *of_get_child_by_name( | 351 | static inline struct device_node *of_find_node_with_property( |
392 | const struct device_node *node, | 352 | struct device_node *from, const char *prop_name) |
393 | const char *name) | ||
394 | { | 353 | { |
395 | return NULL; | 354 | return NULL; |
396 | } | 355 | } |
397 | 356 | ||
398 | static inline int of_get_child_count(const struct device_node *np) | 357 | static inline bool of_have_populated_dt(void) |
399 | { | 358 | { |
400 | return 0; | 359 | return false; |
401 | } | 360 | } |
402 | 361 | ||
403 | 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) | ||
404 | { | 365 | { |
405 | return 0; | 366 | return NULL; |
406 | } | 367 | } |
407 | 368 | ||
408 | 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, |
@@ -431,6 +392,12 @@ static inline struct device_node *of_find_compatible_node( | |||
431 | return NULL; | 392 | return NULL; |
432 | } | 393 | } |
433 | 394 | ||
395 | static inline int of_property_count_elems_of_size(const struct device_node *np, | ||
396 | const char *propname, int elem_size) | ||
397 | { | ||
398 | return -ENOSYS; | ||
399 | } | ||
400 | |||
434 | static inline int of_property_read_u32_index(const struct device_node *np, | 401 | static inline int of_property_read_u32_index(const struct device_node *np, |
435 | const char *propname, u32 index, u32 *out_value) | 402 | const char *propname, u32 index, u32 *out_value) |
436 | { | 403 | { |
@@ -569,6 +536,81 @@ extern int of_node_to_nid(struct device_node *np); | |||
569 | 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; } |
570 | #endif | 537 | #endif |
571 | 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 | |||
546 | /** | ||
547 | * of_property_count_u8_elems - Count the number of u8 elements in a property | ||
548 | * | ||
549 | * @np: device node from which the property value is to be read. | ||
550 | * @propname: name of the property to be searched. | ||
551 | * | ||
552 | * Search for a property in a device node and count the number of u8 elements | ||
553 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
554 | * not exist or its length does not match a multiple of u8 and -ENODATA if the | ||
555 | * property does not have a value. | ||
556 | */ | ||
557 | static inline int of_property_count_u8_elems(const struct device_node *np, | ||
558 | const char *propname) | ||
559 | { | ||
560 | return of_property_count_elems_of_size(np, propname, sizeof(u8)); | ||
561 | } | ||
562 | |||
563 | /** | ||
564 | * of_property_count_u16_elems - Count the number of u16 elements in a property | ||
565 | * | ||
566 | * @np: device node from which the property value is to be read. | ||
567 | * @propname: name of the property to be searched. | ||
568 | * | ||
569 | * Search for a property in a device node and count the number of u16 elements | ||
570 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
571 | * not exist or its length does not match a multiple of u16 and -ENODATA if the | ||
572 | * property does not have a value. | ||
573 | */ | ||
574 | static inline int of_property_count_u16_elems(const struct device_node *np, | ||
575 | const char *propname) | ||
576 | { | ||
577 | return of_property_count_elems_of_size(np, propname, sizeof(u16)); | ||
578 | } | ||
579 | |||
580 | /** | ||
581 | * of_property_count_u32_elems - Count the number of u32 elements in a property | ||
582 | * | ||
583 | * @np: device node from which the property value is to be read. | ||
584 | * @propname: name of the property to be searched. | ||
585 | * | ||
586 | * Search for a property in a device node and count the number of u32 elements | ||
587 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
588 | * not exist or its length does not match a multiple of u32 and -ENODATA if the | ||
589 | * property does not have a value. | ||
590 | */ | ||
591 | static inline int of_property_count_u32_elems(const struct device_node *np, | ||
592 | const char *propname) | ||
593 | { | ||
594 | return of_property_count_elems_of_size(np, propname, sizeof(u32)); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * of_property_count_u64_elems - Count the number of u64 elements in a property | ||
599 | * | ||
600 | * @np: device node from which the property value is to be read. | ||
601 | * @propname: name of the property to be searched. | ||
602 | * | ||
603 | * Search for a property in a device node and count the number of u64 elements | ||
604 | * in it. Returns number of elements on sucess, -EINVAL if the property does | ||
605 | * not exist or its length does not match a multiple of u64 and -ENODATA if the | ||
606 | * property does not have a value. | ||
607 | */ | ||
608 | static inline int of_property_count_u64_elems(const struct device_node *np, | ||
609 | const char *propname) | ||
610 | { | ||
611 | return of_property_count_elems_of_size(np, propname, sizeof(u64)); | ||
612 | } | ||
613 | |||
572 | /** | 614 | /** |
573 | * of_property_read_bool - Findfrom a property | 615 | * of_property_read_bool - Findfrom a property |
574 | * @np: device node from which the property value is to be read. | 616 | * @np: device node from which the property value is to be read. |
@@ -618,6 +660,55 @@ static inline int of_property_read_u32(const struct device_node *np, | |||
618 | s; \ | 660 | s; \ |
619 | s = of_prop_next_string(prop, s)) | 661 | s = of_prop_next_string(prop, s)) |
620 | 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 | |||
621 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) | 712 | #if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE) |
622 | 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 *); |
623 | 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); |