diff options
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 47 |
1 files changed, 47 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. |