diff options
| -rw-r--r-- | drivers/of/base.c | 47 | ||||
| -rw-r--r-- | include/linux/of.h | 33 |
2 files changed, 80 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 466e3c8582f0..9095b8290150 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
| @@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex); | |||
| 54 | */ | 54 | */ |
| 55 | DEFINE_RAW_SPINLOCK(devtree_lock); | 55 | DEFINE_RAW_SPINLOCK(devtree_lock); |
| 56 | 56 | ||
| 57 | bool of_node_name_eq(const struct device_node *np, const char *name) | ||
| 58 | { | ||
| 59 | const char *node_name; | ||
| 60 | size_t len; | ||
| 61 | |||
| 62 | if (!np) | ||
| 63 | return false; | ||
| 64 | |||
| 65 | node_name = kbasename(np->full_name); | ||
| 66 | len = strchrnul(node_name, '@') - node_name; | ||
| 67 | |||
| 68 | return (strlen(name) == len) && (strncmp(node_name, name, len) == 0); | ||
| 69 | } | ||
| 70 | |||
| 71 | bool of_node_name_prefix(const struct device_node *np, const char *prefix) | ||
| 72 | { | ||
| 73 | if (!np) | ||
| 74 | return false; | ||
| 75 | |||
| 76 | return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0; | ||
| 77 | } | ||
| 78 | |||
| 57 | int of_n_addr_cells(struct device_node *np) | 79 | int of_n_addr_cells(struct device_node *np) |
| 58 | { | 80 | { |
| 59 | u32 cells; | 81 | u32 cells; |
| @@ -720,6 +742,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node, | |||
| 720 | EXPORT_SYMBOL(of_get_next_available_child); | 742 | EXPORT_SYMBOL(of_get_next_available_child); |
| 721 | 743 | ||
| 722 | /** | 744 | /** |
| 745 | * of_get_compatible_child - Find compatible child node | ||
| 746 | * @parent: parent node | ||
| 747 | * @compatible: compatible string | ||
| 748 | * | ||
| 749 | * Lookup child node whose compatible property contains the given compatible | ||
| 750 | * string. | ||
| 751 | * | ||
| 752 | * Returns a node pointer with refcount incremented, use of_node_put() on it | ||
| 753 | * when done; or NULL if not found. | ||
| 754 | */ | ||
| 755 | struct device_node *of_get_compatible_child(const struct device_node *parent, | ||
| 756 | const char *compatible) | ||
| 757 | { | ||
| 758 | struct device_node *child; | ||
| 759 | |||
| 760 | for_each_child_of_node(parent, child) { | ||
| 761 | if (of_device_is_compatible(child, compatible)) | ||
| 762 | break; | ||
| 763 | } | ||
| 764 | |||
| 765 | return child; | ||
| 766 | } | ||
| 767 | EXPORT_SYMBOL(of_get_compatible_child); | ||
| 768 | |||
| 769 | /** | ||
| 723 | * of_get_child_by_name - Find the child node by name for a given parent | 770 | * of_get_child_by_name - Find the child node by name for a given parent |
| 724 | * @node: parent node | 771 | * @node: parent node |
| 725 | * @name: child name to look for. | 772 | * @name: child name to look for. |
diff --git a/include/linux/of.h b/include/linux/of.h index 4d25e4f952d9..99b0ebf49632 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
| @@ -256,6 +256,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) | |||
| 256 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) | 256 | #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) |
| 257 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) | 257 | #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) |
| 258 | 258 | ||
| 259 | extern bool of_node_name_eq(const struct device_node *np, const char *name); | ||
| 260 | extern bool of_node_name_prefix(const struct device_node *np, const char *prefix); | ||
| 261 | |||
| 259 | static inline const char *of_node_full_name(const struct device_node *np) | 262 | static inline const char *of_node_full_name(const struct device_node *np) |
| 260 | { | 263 | { |
| 261 | return np ? np->full_name : "<no-node>"; | 264 | return np ? np->full_name : "<no-node>"; |
| @@ -290,6 +293,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node, | |||
| 290 | extern struct device_node *of_get_next_available_child( | 293 | extern struct device_node *of_get_next_available_child( |
| 291 | const struct device_node *node, struct device_node *prev); | 294 | const struct device_node *node, struct device_node *prev); |
| 292 | 295 | ||
| 296 | extern struct device_node *of_get_compatible_child(const struct device_node *parent, | ||
| 297 | const char *compatible); | ||
| 293 | extern struct device_node *of_get_child_by_name(const struct device_node *node, | 298 | extern struct device_node *of_get_child_by_name(const struct device_node *node, |
| 294 | const char *name); | 299 | const char *name); |
| 295 | 300 | ||
| @@ -561,6 +566,16 @@ static inline struct device_node *to_of_node(const struct fwnode_handle *fwnode) | |||
| 561 | return NULL; | 566 | return NULL; |
| 562 | } | 567 | } |
| 563 | 568 | ||
| 569 | static inline bool of_node_name_eq(const struct device_node *np, const char *name) | ||
| 570 | { | ||
| 571 | return false; | ||
| 572 | } | ||
| 573 | |||
| 574 | static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) | ||
| 575 | { | ||
| 576 | return false; | ||
| 577 | } | ||
| 578 | |||
| 564 | static inline const char* of_node_full_name(const struct device_node *np) | 579 | static inline const char* of_node_full_name(const struct device_node *np) |
| 565 | { | 580 | { |
| 566 | return "<no-node>"; | 581 | return "<no-node>"; |
| @@ -632,6 +647,12 @@ static inline bool of_have_populated_dt(void) | |||
| 632 | return false; | 647 | return false; |
| 633 | } | 648 | } |
| 634 | 649 | ||
| 650 | static inline struct device_node *of_get_compatible_child(const struct device_node *parent, | ||
| 651 | const char *compatible) | ||
| 652 | { | ||
| 653 | return NULL; | ||
| 654 | } | ||
| 655 | |||
| 635 | static inline struct device_node *of_get_child_by_name( | 656 | static inline struct device_node *of_get_child_by_name( |
| 636 | const struct device_node *node, | 657 | const struct device_node *node, |
| 637 | const char *name) | 658 | const char *name) |
| @@ -967,6 +988,18 @@ static inline struct device_node *of_find_matching_node( | |||
| 967 | return of_find_matching_node_and_match(from, matches, NULL); | 988 | return of_find_matching_node_and_match(from, matches, NULL); |
| 968 | } | 989 | } |
| 969 | 990 | ||
| 991 | static inline const char *of_node_get_device_type(const struct device_node *np) | ||
| 992 | { | ||
| 993 | return of_get_property(np, "type", NULL); | ||
| 994 | } | ||
| 995 | |||
| 996 | static inline bool of_node_is_type(const struct device_node *np, const char *type) | ||
| 997 | { | ||
| 998 | const char *match = of_node_get_device_type(np); | ||
| 999 | |||
| 1000 | return np && match && type && !strcmp(match, type); | ||
| 1001 | } | ||
| 1002 | |||
| 970 | /** | 1003 | /** |
| 971 | * of_property_count_u8_elems - Count the number of u8 elements in a property | 1004 | * of_property_count_u8_elems - Count the number of u8 elements in a property |
| 972 | * | 1005 | * |
