diff mbox

[U-Boot,2/2] fdt: Add new fdt_create_phandle helper

Message ID 1312179781-27813-3-git-send-email-galak@kernel.crashing.org
State Accepted
Commit 10aeabd18657edf6d65e45bd4c63a48cc794fef0
Delegated to: Kumar Gala
Headers show

Commit Message

Kumar Gala Aug. 1, 2011, 6:23 a.m. UTC
Add a helper function that will return a phandle value for the given
node.  If the node doesn't have a phandle already one will be created.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
 common/fdt_support.c  |   20 ++++++++++++++++++++
 include/fdt_support.h |    1 +
 2 files changed, 21 insertions(+), 0 deletions(-)

Comments

Jerry Van Baren Aug. 2, 2011, 2:15 a.m. UTC | #1
On 08/01/2011 02:23 AM, Kumar Gala wrote:
> Add a helper function that will return a phandle value for the given
> node.  If the node doesn't have a phandle already one will be created.
>
> Signed-off-by: Kumar Gala<galak@kernel.crashing.org>

Acked-by: Gerald Van Baren <vanbaren@cideas.com>

> ---
>   common/fdt_support.c  |   20 ++++++++++++++++++++
>   include/fdt_support.h |    1 +
>   2 files changed, 21 insertions(+), 0 deletions(-)

[snip]

Thanks,
gvb
diff mbox

Patch

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 8f7323d..46aa842 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1235,6 +1235,26 @@  int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle)
 	return ret;
 }
 
+/*
+ * fdt_create_phandle: Create a phandle property for the given node
+ *
+ * @fdt: ptr to device tree
+ * @nodeoffset: node to update
+ */
+int fdt_create_phandle(void *fdt, int nodeoffset)
+{
+	/* see if there is a phandle already */
+	int phandle = fdt_get_phandle(fdt, nodeoffset);
+
+	/* if we got 0, means no phandle so create one */
+	if (phandle == 0) {
+		phandle = fdt_alloc_phandle(fdt);
+		fdt_set_phandle(fdt, nodeoffset, phandle);
+	}
+
+	return phandle;
+}
+
 #if defined(CONFIG_VIDEO)
 int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf)
 {
diff --git a/include/fdt_support.h b/include/fdt_support.h
index fdb9307..8f06aac 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -90,6 +90,7 @@  int fdt_node_offset_by_compat_reg(void *blob, const char *compat,
 					phys_addr_t compat_off);
 int fdt_alloc_phandle(void *blob);
 int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle);
+int fdt_create_phandle(void *fdt, int nodeoffset);
 int fdt_add_edid(void *blob, const char *compat, unsigned char *buf);
 
 int fdt_verify_alias_address(void *fdt, int anode, const char *alias,