summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/device_tree.h2
-rw-r--r--src/lib/device_tree.c22
2 files changed, 24 insertions, 0 deletions
diff --git a/src/include/device_tree.h b/src/include/device_tree.h
index 107fcf6a48b5..54aecb98b8f2 100644
--- a/src/include/device_tree.h
+++ b/src/include/device_tree.h
@@ -147,6 +147,8 @@ struct device_tree_node *dt_find_next_compat_child(struct device_tree_node *pare
// Look up a node relative to a parent node, through its property value.
struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent, const char *name,
void *data, size_t size);
+// Return the phandle
+uint32_t dt_get_phandle(struct device_tree_node *node);
// Write src into *dest as a 'length'-byte big-endian integer.
void dt_write_int(u8 *dest, u64 src, size_t length);
// Add different kinds of properties to a node, or update existing ones.
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index 0a88c1f88676..de14c1553636 100644
--- a/src/lib/device_tree.c
+++ b/src/lib/device_tree.c
@@ -725,6 +725,28 @@ struct device_tree_node *dt_find_prop_value(struct device_tree_node *parent,
return NULL;
}
+/**
+ * Find the phandle of a node.
+ *
+ * @param node Pointer to node containing the phandle
+ * @return Zero on error, the phandle on success
+ */
+uint32_t dt_get_phandle(struct device_tree_node *node)
+{
+ uint32_t *phandle;
+ size_t len;
+
+ dt_find_bin_prop(node, "phandle", (void **)&phandle, &len);
+ if (phandle != NULL && len == sizeof(*phandle))
+ return be32_to_cpu(*phandle);
+
+ dt_find_bin_prop(node, "linux,phandle", (void **)&phandle, &len);
+ if (phandle != NULL && len == sizeof(*phandle))
+ return be32_to_cpu(*phandle);
+
+ return 0;
+}
+
/*
* Write an arbitrary sized big-endian integer into a pointer.
*