public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kumar Gala <galak@kernel.crashing.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] fdt: Add fdt_node_offset_by_compat_reg helper
Date: Sun,  4 Jul 2010 13:18:38 -0500	[thread overview]
Message-ID: <1278267518-13779-2-git-send-email-galak@kernel.crashing.org> (raw)
In-Reply-To: <1278267518-13779-1-git-send-email-galak@kernel.crashing.org>

Given a compatiable string and physical address try and find a node that
matches.  This is useful when we want to find a specific device node to
update (for example if we have multiple PCI nodes we can use the
physical address to distinquish them when trying to update the device
tree).

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

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 70ad81d..718b635 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1125,3 +1125,30 @@ u64 fdt_translate_address(void *blob, int node_offset, const u32 *in_addr)
 {
 	return __of_translate_address(blob, node_offset, in_addr, "ranges");
 }
+
+/**
+ * fdt_node_offset_by_compat_reg: Find a node that matches compatiable and
+ * who's reg property matches a physical cpu address
+ *
+ * @blob: ptr to device tree
+ * @compat: compatiable string to match
+ * @compat_off: property name
+ *
+ */
+int fdt_node_offset_by_compat_reg(void *blob, const char *compat,
+					phys_addr_t compat_off)
+{
+	int len, off = fdt_node_offset_by_compatible(blob, -1, compat);
+	while (off != -FDT_ERR_NOTFOUND) {
+		u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len);
+		if (reg) {
+			if (compat_off == fdt_translate_address(blob, off, reg))
+				return off;
+		}
+		off = fdt_node_offset_by_compatible(blob, off, compat);
+	}
+
+	return -FDT_ERR_NOTFOUND;
+}
+
+
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 78c38b2..54af9fe 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -84,6 +84,8 @@ int fdt_fixup_nor_flash_size(void *blob, int cs, u32 size);
 void fdt_fixup_mtdparts(void *fdt, void *node_info, int node_info_size);
 void fdt_del_node_and_alias(void *blob, const char *alias);
 u64 fdt_translate_address(void *blob, int node_offset, const u32 *in_addr);
+int fdt_node_offset_by_compat_reg(void *blob, const char *compat,
+					phys_addr_t compat_off);
 
 #endif /* ifdef CONFIG_OF_LIBFDT */
 #endif /* ifndef __FDT_SUPPORT_H */
-- 
1.6.0.6

  reply	other threads:[~2010-07-04 18:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-04 18:18 [U-Boot] [PATCH 1/2] fdt: Add fdt_translate_address to convert reg node to cpu phys addr Kumar Gala
2010-07-04 18:18 ` Kumar Gala [this message]
2010-07-17 15:49   ` [U-Boot] [PATCH 2/2] fdt: Add fdt_node_offset_by_compat_reg helper Kumar Gala
2010-07-18  2:59     ` Jerry Van Baren
2010-07-21  5:35       ` Kumar Gala
2010-07-17 15:49 ` [U-Boot] [PATCH 1/2] fdt: Add fdt_translate_address to convert reg node to cpu phys addr Kumar Gala
2010-07-18  3:00   ` Jerry Van Baren
2010-07-21  5:35     ` Kumar Gala

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=1278267518-13779-2-git-send-email-galak@kernel.crashing.org \
    --to=galak@kernel.crashing.org \
    --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