[U-Boot] [PATCH 1/3] core: Add function to get device for ofnode

Mario Six mario.six at gdsys.cc
Wed Mar 28 12:37:13 UTC 2018


It's sometimes useful to get the device associated with a given ofnode.
Implement a function to implement this lookup operation.

Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
 drivers/core/ofnode.c | 15 +++++++++++++++
 include/dm/ofnode.h   |  8 ++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 4e4532651f..ca002063b3 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -16,6 +16,21 @@
 #include <linux/err.h>
 #include <linux/ioport.h>
 
+struct udevice *ofnode_dev(ofnode node)
+{
+	struct uclass *uc;
+	struct udevice *dev;
+
+	list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+		list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+			if (ofnode_equal(dev_ofnode(dev), node))
+				return dev;
+		}
+	}
+
+	return NULL;
+}
+
 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 {
 	assert(ofnode_valid(node));
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 0d008404f9..aec205eb80 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -193,6 +193,14 @@ static inline ofnode ofnode_null(void)
 	return node;
 }
 
+/**
+ * ofnode_dev() - Get the device associated with a given ofnode
+ *
+ * @node:	valid node reference to get the corresponding device for
+ * @return a pointer to the udevice if OK, NULL on error
+ */
+struct udevice *ofnode_dev(ofnode node);
+
 /**
  * ofnode_read_u32() - Read a 32-bit integer from a property
  *
-- 
2.16.1



More information about the U-Boot mailing list