Merge tag 'devicetree-fixes-for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux

Pull devicetree updates from Rob Herring:
"A couple of new helper functions in preparation for some tree wide
clean-ups.

I'm sending these new helpers now for rc2 in order to simplify the
dependencies on subsequent cleanups across the tree in 4.20"

* tag 'devicetree-fixes-for-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux:
of: Add device_type access helper functions
of: add node name compare helper functions
of: add helper to lookup compatible child node

Changed files
+80
drivers
of
include
linux
+47
drivers/of/base.c
··· 54 54 */ 55 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 79 int of_n_addr_cells(struct device_node *np) 58 80 { 59 81 u32 cells; ··· 740 718 return next; 741 719 } 742 720 EXPORT_SYMBOL(of_get_next_available_child); 721 + 722 + /** 723 + * of_get_compatible_child - Find compatible child node 724 + * @parent: parent node 725 + * @compatible: compatible string 726 + * 727 + * Lookup child node whose compatible property contains the given compatible 728 + * string. 729 + * 730 + * Returns a node pointer with refcount incremented, use of_node_put() on it 731 + * when done; or NULL if not found. 732 + */ 733 + struct device_node *of_get_compatible_child(const struct device_node *parent, 734 + const char *compatible) 735 + { 736 + struct device_node *child; 737 + 738 + for_each_child_of_node(parent, child) { 739 + if (of_device_is_compatible(child, compatible)) 740 + break; 741 + } 742 + 743 + return child; 744 + } 745 + EXPORT_SYMBOL(of_get_compatible_child); 743 746 744 747 /** 745 748 * of_get_child_by_name - Find the child node by name for a given parent
+33
include/linux/of.h
··· 256 256 #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 257 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 262 static inline const char *of_node_full_name(const struct device_node *np) 260 263 { 261 264 return np ? np->full_name : "<no-node>"; ··· 293 290 extern struct device_node *of_get_next_available_child( 294 291 const struct device_node *node, struct device_node *prev); 295 292 293 + extern struct device_node *of_get_compatible_child(const struct device_node *parent, 294 + const char *compatible); 296 295 extern struct device_node *of_get_child_by_name(const struct device_node *node, 297 296 const char *name); 298 297 ··· 566 561 return NULL; 567 562 } 568 563 564 + static inline bool of_node_name_eq(const struct device_node *np, const char *name) 565 + { 566 + return false; 567 + } 568 + 569 + static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) 570 + { 571 + return false; 572 + } 573 + 569 574 static inline const char* of_node_full_name(const struct device_node *np) 570 575 { 571 576 return "<no-node>"; ··· 645 630 static inline bool of_have_populated_dt(void) 646 631 { 647 632 return false; 633 + } 634 + 635 + static inline struct device_node *of_get_compatible_child(const struct device_node *parent, 636 + const char *compatible) 637 + { 638 + return NULL; 648 639 } 649 640 650 641 static inline struct device_node *of_get_child_by_name( ··· 986 965 const struct of_device_id *matches) 987 966 { 988 967 return of_find_matching_node_and_match(from, matches, NULL); 968 + } 969 + 970 + static inline const char *of_node_get_device_type(const struct device_node *np) 971 + { 972 + return of_get_property(np, "type", NULL); 973 + } 974 + 975 + static inline bool of_node_is_type(const struct device_node *np, const char *type) 976 + { 977 + const char *match = of_node_get_device_type(np); 978 + 979 + return np && match && type && !strcmp(match, type); 989 980 } 990 981 991 982 /**