Merge tag 'asoc-v5.0' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[sfrench/cifs-2.6.git] / drivers / of / base.c
index 466e3c8582f0fd62628b90872b2046971e064776..74eaedd5b860f1c1fd42faa187d5cda802d0ae8e 100644 (file)
@@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex);
  */
 DEFINE_RAW_SPINLOCK(devtree_lock);
 
+bool of_node_name_eq(const struct device_node *np, const char *name)
+{
+       const char *node_name;
+       size_t len;
+
+       if (!np)
+               return false;
+
+       node_name = kbasename(np->full_name);
+       len = strchrnul(node_name, '@') - node_name;
+
+       return (strlen(name) == len) && (strncmp(node_name, name, len) == 0);
+}
+
+bool of_node_name_prefix(const struct device_node *np, const char *prefix)
+{
+       if (!np)
+               return false;
+
+       return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0;
+}
+
 int of_n_addr_cells(struct device_node *np)
 {
        u32 cells;
@@ -118,6 +140,9 @@ void of_populate_phandle_cache(void)
                if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL)
                        phandles++;
 
+       if (!phandles)
+               goto out;
+
        cache_entries = roundup_pow_of_two(phandles);
        phandle_cache_mask = cache_entries - 1;
 
@@ -719,6 +744,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_next_available_child);
 
+/**
+ * of_get_compatible_child - Find compatible child node
+ * @parent:    parent node
+ * @compatible:        compatible string
+ *
+ * Lookup child node whose compatible property contains the given compatible
+ * string.
+ *
+ * Returns a node pointer with refcount incremented, use of_node_put() on it
+ * when done; or NULL if not found.
+ */
+struct device_node *of_get_compatible_child(const struct device_node *parent,
+                               const char *compatible)
+{
+       struct device_node *child;
+
+       for_each_child_of_node(parent, child) {
+               if (of_device_is_compatible(child, compatible))
+                       break;
+       }
+
+       return child;
+}
+EXPORT_SYMBOL(of_get_compatible_child);
+
 /**
  *     of_get_child_by_name - Find the child node by name for a given parent
  *     @node:  parent node