summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2018-05-08 11:18:54 +0200
committerPatrick Georgi <pgeorgi@google.com>2018-06-14 09:25:41 +0000
commitc38960d7f3fd929fa916ac696fcfb8a7b5534c8d (patch)
treeceb82c1e80e285494cf1f941e87c264707b85809 /src/lib
parent79d26c7a83fd2b14cc9a787e7820824931336d85 (diff)
downloadcoreboot-c38960d7f3fd929fa916ac696fcfb8a7b5534c8d.tar.xz
lib/device_tree: Add method to get phandle
Add a method to retrieve a node's phandle. Useful for board specific devicetree manipulations. Change-Id: I966151ad7e82fc678ab4f56cf9b5868ef39398e0 Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/26191 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/device_tree.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index 0a88c1f886..de14c15536 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.
*