From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: U-Boot Mailing List <u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org>
Cc: Albert ARIBAUD
<albert.u.boot-LhW3hqR2+23R7s880joybQ@public.gmane.org>,
Jerry Van Baren
<vanbaren-He//nVnquyzQT0dZR+AlfA@public.gmane.org>,
Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH 3/6] fdt: Add fdtdec functions to read byte array
Date: Fri, 2 Dec 2011 18:57:48 -0800 [thread overview]
Message-ID: <1322881071-11148-4-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1322881071-11148-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
From: Anton Staff <robotboy-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Sometimes we don't need a full cell for each value. This provides
a simple function to read a byte array, both with and without
copying it.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
include/fdtdec.h | 32 ++++++++++++++++++++++++++++++++
lib/fdtdec.c | 24 ++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 9871b81..f72d219 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -231,3 +231,35 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
* @return 0 if all ok or gpio was FDT_GPIO_NONE; -1 on error
*/
int fdtdec_setup_gpio(struct fdt_gpio_state *gpio);
+
+/**
+ * Look up a property in a node and return its contents in a byte
+ * array of given length. The property must have at least enough data for
+ * the array (count bytes). It may have more, but this will be ignored.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @param array array to fill with data
+ * @param count number of array elements
+ * @return 0 if ok, or -FDT_ERR_MISSING if the property is not found,
+ * or -FDT_ERR_BADLAYOUT if not enough data
+ */
+int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
+ u8 *array, int count);
+
+/**
+ * Look up a property in a node and return a pointer to its contents as a
+ * byte array of given length. The property must have at least enough data
+ * for the array (count bytes). It may have more, but this will be ignored.
+ * The data is not copied.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @param count number of array elements
+ * @return pointer to byte array if found, or NULL if the property is not
+ * found or there is not enough data
+ */
+const u8 *fdtdec_locate_byte_array(const void *blob, int node,
+ const char *prop_name, int count);
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 509b81f..90db53c 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -315,3 +315,27 @@ int fdtdec_setup_gpio(struct fdt_gpio_state *gpio)
return gpio_direction_input(gpio->gpio);
}
}
+
+int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
+ u8 *array, int count)
+{
+ const u8 *cell;
+ int err;
+
+ cell = get_prop_len(blob, node, prop_name, count, &err);
+ if (!err)
+ memcpy(array, cell, count);
+ return err;
+}
+
+const u8 *fdtdec_locate_byte_array(const void *blob, int node,
+ const char *prop_name, int count)
+{
+ const u8 *cell;
+ int err;
+
+ cell = get_prop_len(blob, node, prop_name, count, &err);
+ if (err)
+ return NULL;
+ return cell;
+}
--
1.7.3.1
next prev parent reply other threads:[~2011-12-03 2:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1322881071-11148-1-git-send-email-sjg@chromium.org>
[not found] ` <1322881071-11148-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-12-03 2:57 ` [PATCH 1/6] tegra: fdt: Add keyboard controller definition Simon Glass
2011-12-03 2:57 ` Simon Glass [this message]
[not found] ` <1322881071-11148-4-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-12-05 23:54 ` [PATCH 3/6] fdt: Add fdtdec functions to read byte array Stephen Warren
2011-12-06 0:27 ` Simon Glass
2011-12-03 2:57 ` [PATCH 2/6] tegra: fdt: Add keyboard definitions for Seaboard Simon Glass
[not found] ` <1322881071-11148-3-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-12-05 23:49 ` Stephen Warren
[not found] ` <1322881071-11148-5-git-send-email-sjg@chromium.org>
[not found] ` <1322881071-11148-5-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2011-12-07 22:02 ` [PATCH 4/6] tegra: Add tegra keyboard support Stephen Warren
[not found] ` <4EDFE259.9080201-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-12-08 21:56 ` Simon Glass
[not found] ` <CAPnjgZ3AP2d7kGqawm=CyySd=y0UfXAsYr4r0TvXaX+64pdUuA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-12 18:00 ` Stephen Warren
2011-12-12 18:10 ` Simon Glass
[not found] ` <CAPnjgZ1dskr04mNfdkTPVLjbv8EnJisQvt1YrYOjKSSa=AbhkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-12 18:31 ` Stephen Warren
2011-12-12 20:03 ` Simon Glass
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=1322881071-11148-4-git-send-email-sjg@chromium.org \
--to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=albert.u.boot-LhW3hqR2+23R7s880joybQ@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org \
--cc=vanbaren-He//nVnquyzQT0dZR+AlfA@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).