From patchwork Thu Apr 21 05:11:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 612948 X-Patchwork-Delegate: hs@denx.de 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 3qr7S76Gh8z9t3c for ; Thu, 21 Apr 2016 16:01:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0F137A77CB; Thu, 21 Apr 2016 07:50:42 +0200 (CEST) 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 ImHl9FKltSYk; Thu, 21 Apr 2016 07:50:41 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2D3D3B3874; Thu, 21 Apr 2016 07:44:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EFC90A7610 for ; Thu, 21 Apr 2016 07:12:45 +0200 (CEST) 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 yuChUVRxa9Gd for ; Thu, 21 Apr 2016 07:12:20 +0200 (CEST) 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 sohosted5.com (ns2.sohosted5.com [195.8.208.35]) by theia.denx.de (Postfix) with ESMTPS id CF784A74D6 for ; Thu, 21 Apr 2016 07:11:37 +0200 (CEST) Received: from stefan-work.fritz.box ([185.22.143.102]) by sohosted5.com with MailEnable ESMTP; Thu, 21 Apr 2016 07:11:35 +0200 From: Stefan Roese To: u-boot@lists.denx.de Date: Thu, 21 Apr 2016 07:11:34 +0200 Message-Id: <1461215494-8613-1-git-send-email-sr@denx.de> X-Mailer: git-send-email 2.8.1 X-ME-Bayesian: 0.000000 Subject: [U-Boot] [PATCH v2] dm: core: Add dev_get_addr_ptr() to return a pointer to the reg address 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" On some platforms (e.g. x86), the return value of dev_get_addr() can't be assigned to a pointer type variable directly. As there might be a difference between the size of fdt_addr_t and the pointer type. On x86 for example, "fdt_addr_t" is 64bit but "void *" only 32bit. So assigning the register base directly in dev_get_addr() results in this compilation warning: warning: cast to pointer from integer of different size This patch introduces the new function dev_get_addr_ptr() that returns a pointer to the 'reg' address that can be used by drivers in this case. Signed-off-by: Stefan Roese Reviewed-by: Simon Glass Reviewed-by: Bin Meng Acked-by: Simon Glass --- v2: - Mention error condition in function prototype as suggested by Simon drivers/core/device.c | 5 +++++ include/dm/device.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index 269087a..1322991 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -673,6 +673,11 @@ fdt_addr_t dev_get_addr(struct udevice *dev) return dev_get_addr_index(dev, 0); } +void *dev_get_addr_ptr(struct udevice *dev) +{ + return (void *)(uintptr_t)dev_get_addr_index(dev, 0); +} + bool device_has_children(struct udevice *dev) { return !list_empty(&dev->child_head); diff --git a/include/dm/device.h b/include/dm/device.h index dad7591..8970fc0 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -454,6 +454,16 @@ int device_find_next_child(struct udevice **devp); fdt_addr_t dev_get_addr(struct udevice *dev); /** + * dev_get_addr_ptr() - Return pointer to the address of the reg property + * of a device + * + * @dev: Pointer to a device + * + * @return Pointer to addr, or NULL if there is no such property + */ +void *dev_get_addr_ptr(struct udevice *dev); + +/** * dev_get_addr_index() - Get the indexed reg property of a device * * @dev: Pointer to a device