[PATCH v2 1/3] dm: core: Add of_match_node helper function

Biju Das biju.das.jz at bp.renesas.com
Mon Nov 2 16:09:57 CET 2020


Add of_match_node() helper function to iterate over the device tree
and tell if a device_node has a matching of_match structure.

Signed-off-by: Biju Das <biju.das.jz at bp.renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj at bp.renesas.com>
---
v1->v2:
  * No Change. 
  Ref: https://patchwork.ozlabs.org/project/uboot/patch/20201030140303.11773-1-biju.das.jz@bp.renesas.com/
---
 drivers/core/device.c | 21 +++++++++++++++++++++
 include/dm/device.h   | 13 +++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 4b3dcb3b37..348d63dc59 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -1010,6 +1010,27 @@ bool of_machine_is_compatible(const char *compat)
 	return !fdt_node_check_compatible(fdt, 0, compat);
 }
 
+static
+const struct udevice_id *__of_match_node(const struct udevice_id *matches,
+					 const ofnode node)
+{
+	if (!matches)
+		return NULL;
+
+	for (; matches && matches->compatible; matches++) {
+		if (ofnode_device_is_compatible(node, matches->compatible))
+			return matches;
+	}
+
+	return NULL;
+}
+
+const struct udevice_id *of_match_node(const struct udevice_id *matches,
+				       const ofnode node)
+{
+	return __of_match_node(matches, node);
+}
+
 int dev_disable_by_path(const char *path)
 {
 	struct uclass *uc;
diff --git a/include/dm/device.h b/include/dm/device.h
index 5bef484247..4c357d46ec 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -754,6 +754,19 @@ bool device_is_compatible(const struct udevice *dev, const char *compat);
  */
 bool of_machine_is_compatible(const char *compat);
 
+/**
+ * of_match_node() - Tell if a device_node has a matching of_match structure
+ *
+ *
+ * Low level utility function used by device matching.
+ *
+ * @matches:	array of of device match structures to search in
+ * @node:	the of device structure to match against
+ * @return matching structure on success, NULL if the match is not found
+ */
+const struct udevice_id *of_match_node(const struct udevice_id *matches,
+				       const ofnode node);
+
 /**
  * dev_disable_by_path() - Disable a device given its device tree path
  *
-- 
2.17.1



More information about the U-Boot mailing list