From patchwork Wed Nov 30 06:24:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 700871 X-Patchwork-Delegate: sjg@chromium.org 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 3tT9Pr1y5Tz9t2g for ; Wed, 30 Nov 2016 17:25:04 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CD871A75B4; Wed, 30 Nov 2016 07:25:01 +0100 (CET) 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 djzYfpT85wFJ; Wed, 30 Nov 2016 07:25:01 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6043DA7593; Wed, 30 Nov 2016 07:25:01 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 64662A7593 for ; Wed, 30 Nov 2016 07:24:58 +0100 (CET) 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 EJl0EcuLojiu for ; Wed, 30 Nov 2016 07:24:58 +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 mx2.mailbox.org (mx2.mailbox.org [80.241.60.215]) by theia.denx.de (Postfix) with ESMTPS id 304CAA7573 for ; Wed, 30 Nov 2016 07:24:54 +0100 (CET) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 2A6B843A20; Wed, 30 Nov 2016 07:24:54 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id Zz614GXBfpAb; Wed, 30 Nov 2016 07:24:48 +0100 (CET) From: Stefan Roese To: u-boot@lists.denx.de Date: Wed, 30 Nov 2016 07:24:47 +0100 Message-Id: <20161130062447.3708-1-sr@denx.de> Subject: [U-Boot] [PATCH v2] dm: core: Add dev_get_addr_size_index() to retrieve addr and size X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" The currently available functions accessing the 'reg' property of a device only retrieve the address. Sometimes its also necessary to retrieve the size described by the 'reg' property. This patch adds the new function dev_get_addr_size_index() which retrieves both, the address and the size described by the 'reg' property. Signed-off-by: Stefan Roese Cc: Simon Glass Acked-by: Simon Glass --- v2: - Account 'index' in fdtdec_get_addr_size_auto_noparent() as spotted by Simon drivers/core/device.c | 22 ++++++++++++++++++++++ include/dm/device.h | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index dcf5d9df7d..ed553d70a6 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -693,6 +693,28 @@ fdt_addr_t dev_get_addr_index(struct udevice *dev, int index) #endif } +fdt_addr_t dev_get_addr_size_index(struct udevice *dev, int index, + fdt_size_t *size) +{ +#if CONFIG_IS_ENABLED(OF_CONTROL) + /* + * Only get the size in this first call. We'll get the addr in the + * next call to the exisiting dev_get_xxx function which handles + * all config options. + */ + fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, dev->of_offset, + "reg", index, size, false); + + /* + * Get the base address via the existing function which handles + * all Kconfig cases + */ + return dev_get_addr_index(dev, index); +#else + return FDT_ADDR_T_NONE; +#endif +} + fdt_addr_t dev_get_addr_name(struct udevice *dev, const char *name) { #if CONFIG_IS_ENABLED(OF_CONTROL) diff --git a/include/dm/device.h b/include/dm/device.h index babf8ac8f0..9948bd49fa 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -497,6 +497,22 @@ void *dev_map_physmem(struct udevice *dev, unsigned long size); fdt_addr_t dev_get_addr_index(struct udevice *dev, int index); /** + * dev_get_addr_size_index() - Get the indexed reg property of a device + * + * Returns the address and size specified in the 'reg' property of a device. + * + * @dev: Pointer to a device + * @index: the 'reg' property can hold a list of pairs + * and @index is used to select which one is required + * @size: Pointer to size varible - this function returns the size + * specified in the 'reg' property here + * + * @return addr + */ +fdt_addr_t dev_get_addr_size_index(struct udevice *dev, int index, + fdt_size_t *size); + +/** * dev_get_addr_name() - Get the reg property of a device, indexed by name * * @dev: Pointer to a device