From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/6] fdt_support: split fdt_getprop_u32_default
Date: Fri, 11 Apr 2014 17:09:40 +0200 [thread overview]
Message-ID: <1397228985-17740-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1397228985-17740-1-git-send-email-agraf@suse.de>
We already have a nice helper to give us a property cell value with default
fall back from a path. Split that into two helpers - one for the old path
based lookup and one to give us a value based on a node offset.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
common/fdt_support.c | 38 ++++++++++++++++++++++++++++++++------
include/fdt_support.h | 2 ++
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index f9f358e..cc0bf76 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -50,6 +50,37 @@ static void write_cell(u8 *addr, u64 val, int size)
}
/**
+ * fdt_getprop_u32_default_node - Return a node's property or a default
+ *
+ * @fdt: ptr to device tree
+ * @off: offset of node
+ * @cell: cell offset in property
+ * @prop: property name
+ * @dflt: default value if the property isn't found
+ *
+ * Convenience function to return a node's property or a default value if
+ * the property doesn't exist.
+ */
+u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
+ const char *prop, const u32 dflt)
+{
+ const fdt32_t *val;
+ int len;
+
+ val = fdt_getprop(fdt, off, prop, &len);
+
+ /* Check if property exists */
+ if (!val)
+ return dflt;
+
+ /* Check if property is long enough */
+ if (len < ((cell + 1) * sizeof(uint32_t)))
+ return dflt;
+
+ return fdt32_to_cpu(*val);
+}
+
+/**
* fdt_getprop_u32_default - Find a node and return it's property or a default
*
* @fdt: ptr to device tree
@@ -63,18 +94,13 @@ static void write_cell(u8 *addr, u64 val, int size)
u32 fdt_getprop_u32_default(const void *fdt, const char *path,
const char *prop, const u32 dflt)
{
- const fdt32_t *val;
int off;
off = fdt_path_offset(fdt, path);
if (off < 0)
return dflt;
- val = fdt_getprop(fdt, off, prop, NULL);
- if (val)
- return fdt32_to_cpu(*val);
- else
- return dflt;
+ return fdt_getprop_u32_default_node(fdt, off, 0, prop, dflt);
}
/**
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 9871e2f..3e1be57 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -12,6 +12,8 @@
#include <libfdt.h>
+u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
+ const char *prop, const u32 dflt);
u32 fdt_getprop_u32_default(const void *fdt, const char *path,
const char *prop, const u32 dflt);
int fdt_chosen(void *fdt, int force);
--
1.7.10.4
next prev parent reply other threads:[~2014-04-11 15:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-11 15:09 [U-Boot] [PATCH v5 0/6] PPC 85xx: Add support for QEMU's ppce500 PV machine Alexander Graf
2014-04-11 15:09 ` Alexander Graf [this message]
2014-04-11 15:09 ` [U-Boot] [PATCH 2/6] fdt_support: Add helper function to read "ranges" property Alexander Graf
2014-04-11 15:09 ` [U-Boot] [PATCH 3/6] PPC: 85xx: Remove IVOR reset Alexander Graf
2014-04-17 0:46 ` York Sun
2014-04-17 7:16 ` Alexander Graf
2014-04-11 15:09 ` [U-Boot] [PATCH 4/6] PPC: 85xx: Generalize DDR TLB mapping function Alexander Graf
2014-04-11 15:09 ` [U-Boot] [PATCH 5/6] PPC 85xx: Add ELF entry point Alexander Graf
2014-04-11 15:09 ` [U-Boot] [PATCH 6/6] PPC 85xx: Add qemu-ppce500 machine Alexander Graf
2014-04-11 23:18 ` [U-Boot] [PATCH v5 0/6] PPC 85xx: Add support for QEMU's ppce500 PV machine Scott Wood
2014-04-23 21:46 ` York Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397228985-17740-2-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox