devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Devicetree Discuss <devicetree-discuss@lists.ozlabs.org>,
	Tom Warren <twarren@nvidia.com>,
	Jerry Van Baren <vanbaren@cideas.com>
Subject: [PATCH v3 02/23] fdt: Add function to return next compatible subnode
Date: Mon,  2 Apr 2012 16:18:42 -0700	[thread overview]
Message-ID: <1333408743-28720-3-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1333408743-28720-1-git-send-email-sjg@chromium.org>

We need to iterate through subnodes of a parent, looking only at
compatible nodes. Add a utility function to do this for us.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v3:
- Add new fdtdec_next_compatible_subnode() patch

 include/fdtdec.h |   17 +++++++++++++++++
 lib/fdtdec.c     |   15 +++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 84f0768..0351a25 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -117,6 +117,23 @@ int fdtdec_next_compatible(const void *blob, int node,
 		enum fdt_compat_id id);
 
 /**
+ * Find the next compatible subnode for a peripheral.
+ *
+ * Do the first call with node set to the parent and depth = 0. This
+ * function will return the offset of the next compatible node. Next time
+ * you call this function, pass the node value returned last time, with
+ * depth unchanged, and the next node will be provided.
+ *
+ * @param blob		FDT blob to use
+ * @param node		Start node for search
+ * @param id		Compatible ID to look for (enum fdt_compat_id)
+ * @param depthp	Current depth (set to 0 before first call)
+ * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
+ */
+int fdtdec_next_compatible_subnode(const void *blob, int node,
+		enum fdt_compat_id id, int *depthp);
+
+/**
  * Look up an address property in a node and return it as an address.
  * The property must hold either one address with no trailing data or
  * one address with a length. This is only tested on 32-bit machines.
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 4a5ab71..76d3808 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -133,6 +133,21 @@ int fdtdec_next_compatible(const void *blob, int node,
 	return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
 }
 
+int fdtdec_next_compatible_subnode(const void *blob, int node,
+		enum fdt_compat_id id, int *depthp)
+{
+	do {
+		node = fdt_next_node(blob, node, depthp);
+	} while (*depthp > 1);
+
+	/* If this is a direct subnode, and compatible, return it */
+	if (*depthp == 1 && 0 == fdt_node_check_compatible(
+						blob, node, compat_names[id]))
+		return node;
+
+	return -FDT_ERR_NOTFOUND;
+}
+
 int fdtdec_next_alias(const void *blob, const char *name,
 		enum fdt_compat_id id, int *upto)
 {
-- 
1.7.7.3

       reply	other threads:[~2012-04-02 23:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1333408743-28720-1-git-send-email-sjg@chromium.org>
2012-04-02 23:18 ` Simon Glass [this message]
     [not found] ` <1333408743-28720-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-04-02 23:18   ` [PATCH v3 01/23] fdt: Add function to locate an array in the device tree Simon Glass
2012-04-02 23:19   ` [PATCH v3 20/23] fdt: tegra: Add EMC node to " Simon Glass
2012-04-02 23:19   ` [PATCH v3 22/23] tegra: fdt: Add EMC data for Tegra2 Seaboard Simon Glass
2012-04-03  5:22     ` Olof Johansson
2012-04-04  0:47       ` Simon Glass
2012-04-05 21:58         ` 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=1333408743-28720-3-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=twarren@nvidia.com \
    --cc=u-boot@lists.denx.de \
    --cc=vanbaren@cideas.com \
    /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).