]> git.sur5r.net Git - u-boot/commitdiff
dm: core: Add a way to find an ofnode by compatible string
authorSimon Glass <sjg@chromium.org>
Mon, 11 Jun 2018 19:07:13 +0000 (13:07 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 9 Jul 2018 15:11:00 +0000 (09:11 -0600)
Add an ofnode_by_compatible() to allow iterating through ofnodes with a
given compatible string.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/ofnode.c
include/dm/ofnode.h

index b2b02e4abfbacc7c7b7a31c3a5567f0e8bc1dfb5..29375397e04ffa3fe173091aa1eb79dbe9fb775e 100644 (file)
@@ -729,3 +729,15 @@ int ofnode_device_is_compatible(ofnode node, const char *compat)
                                                  ofnode_to_offset(node),
                                                  compat);
 }
+
+ofnode ofnode_by_compatible(ofnode from, const char *compat)
+{
+       if (of_live_active()) {
+               return np_to_ofnode(of_find_compatible_node(
+                       (struct device_node *)ofnode_to_np(from), NULL,
+                       compat));
+       } else {
+               return offset_to_ofnode(fdt_node_offset_by_compatible(
+                               gd->fdt_blob, ofnode_to_offset(from), compat));
+       }
+}
index 61c42311f8e51e35ef274f65d48a33030ed782db..cd08a7e4d02806be0feed6e7472fb5b12d5ef12a 100644 (file)
@@ -678,6 +678,17 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res);
 int ofnode_read_resource_byname(ofnode node, const char *name,
                                struct resource *res);
 
+/**
+ * ofnode_by_compatible() - Find the next compatible node
+ *
+ * Find the next node after @from that is compatible with @compat
+ *
+ * @from: ofnode to start from (use ofnode_null() to start at the beginning)
+ * @compat: Compatible string to match
+ * @return ofnode found, or ofnode_null() if none
+ */
+ofnode ofnode_by_compatible(ofnode from, const char *compat);
+
 /**
  * ofnode_for_each_subnode() - iterate over all subnodes of a parent
  *