From patchwork Sun Jan 15 00:47:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 136119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C3117B6F62 for ; Sun, 15 Jan 2012 11:48:31 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2429A28134; Sun, 15 Jan 2012 01:48:30 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9zsmrelVNf7R; Sun, 15 Jan 2012 01:48:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 59CEE28135; Sun, 15 Jan 2012 01:48:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5C21928137 for ; Sun, 15 Jan 2012 01:48:14 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wVW85-dccQBq for ; Sun, 15 Jan 2012 01:48:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yw0-f74.google.com (mail-yw0-f74.google.com [209.85.213.74]) by theia.denx.de (Postfix) with ESMTPS id C48692813A for ; Sun, 15 Jan 2012 01:48:00 +0100 (CET) Received: by yhjj52 with SMTP id j52so189796yhj.3 for ; Sat, 14 Jan 2012 16:47:57 -0800 (PST) Received: by 10.236.131.138 with SMTP id m10mr9247474yhi.7.1326588477763; Sat, 14 Jan 2012 16:47:57 -0800 (PST) Received: by 10.236.131.138 with SMTP id m10mr9247444yhi.7.1326588477699; Sat, 14 Jan 2012 16:47:57 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id l40si5662525anq.0.2012.01.14.16.47.57 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sat, 14 Jan 2012 16:47:57 -0800 (PST) Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by wpzn4.hot.corp.google.com (Postfix) with ESMTPS id 9A9811E004D; Sat, 14 Jan 2012 16:47:57 -0800 (PST) Received: from glucid-laptop-imager.hot.corp.google.com ([172.29.161.24]) by wpaz9.hot.corp.google.com with ESMTP id q0F0ltmG007187; Sat, 14 Jan 2012 16:47:55 -0800 Received: by glucid-laptop-imager.hot.corp.google.com (Postfix, from userid 121222) id 7025434E533; Sat, 14 Jan 2012 16:47:55 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Sat, 14 Jan 2012 16:47:13 -0800 Message-Id: <1326588449-1794-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326588449-1794-1-git-send-email-sjg@chromium.org> References: <1326588449-1794-1-git-send-email-sjg@chromium.org> X-System-Of-Record: true Cc: Devicetree Discuss , Tom Warren , Jerry Van Baren Subject: [U-Boot] [PATCH 01/17] fdt: Add function to look up a phandle's register address X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This is a commonly-used requirement, so add a function to support it easily. Signed-off-by: Simon Glass --- include/fdtdec.h | 13 +++++++++++++ lib/fdtdec.c | 11 +++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index e705124..81ce3f6 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -239,6 +239,19 @@ const char *fdtdec_get_compatible(enum fdt_compat_id id); int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name); /** + * Look up a phandle and follow it to its node. Then return the register + * address of that node as a pointer. This can be used to access the + * peripheral directly. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @return pointer to node's register address + */ +void *fdtdec_lookup_phandle_reg(const void *blob, int node, + const char *prop_name); + +/** * Look up a property in a node and return its contents in an integer * array of given length. The property must have at least enough data for * the array (4*count bytes). It may have more, but this will be ignored. diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 48abf02..bcb2343 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -311,6 +311,17 @@ int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name) return lookup; } +void *fdtdec_lookup_phandle_reg(const void *blob, int node, + const char *prop_name) +{ + int lookup; + + lookup = fdtdec_lookup_phandle(blob, node, prop_name); + if (lookup < 0) + return NULL; + return (void *)fdtdec_get_addr(blob, lookup, "reg"); +} + /** * Look up a property in a node and check that it has a minimum length. *