From patchwork Fri May 19 02:09:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 764378 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wTXVM1zjjz9s1h for ; Fri, 19 May 2017 12:45:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="bEasNcWm"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id E6A7DC224DA; Fri, 19 May 2017 02:21:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8057AC22340; Fri, 19 May 2017 02:11:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 53FAFC2230B; Fri, 19 May 2017 02:10:41 +0000 (UTC) Received: from mail-oi0-f54.google.com (mail-oi0-f54.google.com [209.85.218.54]) by lists.denx.de (Postfix) with ESMTPS id D61B8C22194 for ; Fri, 19 May 2017 02:10:27 +0000 (UTC) Received: by mail-oi0-f54.google.com with SMTP id w10so76859684oif.0 for ; Thu, 18 May 2017 19:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=yoQal/s9eB3169iFuuPcN4v4YebGjuKoeU12x/cD5Mo=; b=bEasNcWmfmijy2Rd6viEK51VOfZnf5LOM8I7IBth03XfsCdjRF444e7KtEr4iASMez boFJg/l8QxcDmOUi4jaqK1MduPwkLSUELkjsHZ8/vHIDTmW0OJGTH/l16fcUw2+gHlM/ KbwdYRnU4x5nRChRz+nYDS25Hl7pNYwI+M+Mt9Lqo67kIExGtP+KpvsnZGeWU5O/5Po1 pM9tr8ry+zn74R5BpyOs/18xToylzWD0luX8oPQXXvW9ZGWZNBSYleRe279gK1rIuY4Y q97+l4c9hhvVIjaD00EactgezqaQtsd5rtgh+li2xYG/WP2fY/Z2Vbc1qqQhBvGbKRTz Fhkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=yoQal/s9eB3169iFuuPcN4v4YebGjuKoeU12x/cD5Mo=; b=b/rkxvwF2F22pu4i09EqLGFTHTSzB3jGhUgPq1eSt3Zhd8Gm1izZ3IuPoYDLiRq6G6 TBKnArCEzRdhyPb2iFjhzNERqM/6GJYuv0Kor9l3tuGC3i9mYP7u3k1DPC9yJs/+sD3l zyBLL59TUmiGamv9oGQ/vExTVbdXVJmJVlK9E930i/Sq87StQIjiBpEhX43lrHRQYsjN mdsaR2E/WH7b9nW9bIul8KPra6IjgljCuv6XdDdvmc3SmHrZKDu98M+XkgknzMpe9883 2BhQv/rg4HibuRGnDHB4p4J6alK0Gxa1wLKMkp5pLNfFW0eYy0M0N+6KFjJ2I5svD8EK CLtQ== X-Gm-Message-State: AODbwcDiZNIeviIKIeplODC7NxDH8MX1quAcMaofYyki+5b8c+d5HbAn IRpHL9KpkHw2sLli X-Received: by 10.157.38.200 with SMTP id i8mr4579212otd.25.1495159826632; Thu, 18 May 2017 19:10:26 -0700 (PDT) Received: from kaki.bld.corp.google.com ([100.100.184.96]) by smtp.gmail.com with ESMTPSA id f81sm3631150oih.1.2017.05.18.19.10.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 19:10:25 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 5E00E40563; Thu, 18 May 2017 20:10:25 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 18 May 2017 20:09:01 -0600 Message-Id: <20170519021002.1098-12-sjg@chromium.org> X-Mailer: git-send-email 2.13.0.303.g4ebf302169-goog In-Reply-To: <20170519021002.1098-1-sjg@chromium.org> References: <20170519021002.1098-1-sjg@chromium.org> Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH v3 11/72] dm: core: Add address operations on device tree references X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add functions to add addresses in the device tree using ofnode references. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None drivers/core/ofnode.c | 27 +++++++++++++++++++++++++++ include/dm/ofnode.h | 23 ++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index e6c9a28bae..ac312d6546 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,32 @@ int ofnode_read_size(ofnode node, const char *propname) return -EINVAL; } +fdt_addr_t ofnode_get_addr_index(ofnode node, int index) +{ + if (ofnode_is_np(node)) { + const __be32 *prop_val; + uint flags; + u64 size; + + prop_val = of_get_address( + (struct device_node *)ofnode_to_np(node), index, + &size, &flags); + if (!prop_val) + return FDT_ADDR_T_NONE; + return be32_to_cpup(prop_val); + } else { + return fdt_get_base_address(gd->fdt_blob, + ofnode_to_offset(node)); + } + + return FDT_ADDR_T_NONE; +} + +fdt_addr_t ofnode_get_addr(ofnode node) +{ + return ofnode_get_addr_index(node, 0); +} + int ofnode_stringlist_search(ofnode node, const char *property, const char *string) { diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index e8b33c158d..149622a0b2 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -245,7 +245,7 @@ int ofnode_read_s32_default(ofnode node, const char *propname, s32 def); const char *ofnode_read_string(ofnode node, const char *propname); /** - * ofnode_read_u32_array - Find and read an array of 32 bit integers + * ofnode_read_u32_array() - Find and read an array of 32 bit integers * * @node: valid node reference to read property from * @propname: name of the property to read @@ -317,6 +317,27 @@ const char *ofnode_get_name(ofnode node); int ofnode_read_size(ofnode node, const char *propname); /** + * ofnode_get_addr_index() - get an address from a node + * + * This reads the register address from a node + * + * @node: node to read from + * @index: Index of address to read (0 for first) + * @return address, or FDT_ADDR_T_NONE if not present or invalid + */ +phys_addr_t ofnode_get_addr_index(ofnode node, int index); + +/** + * ofnode_get_addr() - get an address from a node + * + * This reads the register address from a node + * + * @node: node to read from + * @return address, or FDT_ADDR_T_NONE if not present or invalid + */ +phys_addr_t ofnode_get_addr(ofnode node); + +/** * ofnode_stringlist_search() - find a string in a string list and return index * * Note that it is possible for this function to succeed on property values