From patchwork Fri Mar 20 06:11:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Walmsley X-Patchwork-Id: 6054451 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B59189F2A9 for ; Fri, 20 Mar 2015 06:18:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D30AB2049D for ; Fri, 20 Mar 2015 06:18:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DF1A02049E for ; Fri, 20 Mar 2015 06:18:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YYqE7-0007ZL-R2; Fri, 20 Mar 2015 06:16:11 +0000 Received: from utopia.booyaka.com ([74.50.51.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YYqDI-00063w-Nw for linux-arm-kernel@lists.infradead.org; Fri, 20 Mar 2015 06:15:24 +0000 Received: (qmail 2247 invoked by uid 1019); 20 Mar 2015 06:14:56 -0000 MBOX-Line: From nobody Fri Mar 20 00:11:02 2015 Subject: [PATCH v3 2/3] amba: tegra-ahb: detect and correct bogus base address From: Paul Walmsley To: linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org Date: Fri, 20 Mar 2015 00:11:02 -0600 Message-ID: <20150320061102.14355.95682.stgit@mcwayne> In-Reply-To: <20150320061102.14355.4781.stgit@mcwayne> References: <20150320061102.14355.4781.stgit@mcwayne> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150319_231521_018230_179EC687 X-CRM114-Status: GOOD ( 14.51 ) X-Spam-Score: -0.0 (/) Cc: Alexandre Courbot , Russell King , Stephen Warren , linux-kernel@vger.kernel.org, Thierry Reding , Paul Walmsley , Hiroshi DOYU X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >From a hardware SoC integration point of view, the starting address of this IP block in the existing Tegra SoC DT files is off by 4 bytes from the actual base address. Since we attempt to make old DT files forward-compatible with newer kernels, we cannot fix the IP block base address in old DT data. This patch works around the problem by detecting the four byte base address offset in the driver code, and correcting it if it's detected. (In general, IP block base addresses almost always have a null low byte.) Future SoC DT data for Tegra AHB should use the correct Tegra AHB base address, in cases where there is no DT data backward compatibility requirement. This patch is a revision of the patch originally titled "amba: tegra-ahb: use correct base address for future chip support". This revision implements changes requested by Russell King: http://marc.info/?l=linux-tegra&m=142658851825062&w=2 http://marc.info/?l=linux-tegra&m=142658873925178&w=2 Signed-off-by: Paul Walmsley Cc: Paul Walmsley Cc: Alexandre Courbot Cc: Hiroshi DOYU Cc: Russell King Cc: Stephen Warren Cc: Thierry Reding Cc: linux-kernel@vger.kernel.org --- drivers/amba/tegra-ahb.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c index 30759a55efe4..b0b688c481e8 100644 --- a/drivers/amba/tegra-ahb.c +++ b/drivers/amba/tegra-ahb.c @@ -82,6 +82,16 @@ #define AHB_ARBITRATION_XBAR_CTRL_SMMU_INIT_DONE BIT(17) +/* + * INCORRECT_BASE_ADDR_LOW_BYTE: Legacy kernel DT files for Tegra SoCs + * prior to Tegra124 generally use a physical base address ending in + * 0x4 for the AHB IP block. According to the TRM, the low byte + * should be 0x0. During device probing, this macro is used to detect + * whether the passed-in physical address is incorrect, and if so, to + * correct it. + */ +#define INCORRECT_BASE_ADDR_LOW_BYTE 0x4 + static struct platform_driver tegra_ahb_driver; static const u32 tegra_ahb_gizmo[] = { @@ -124,12 +134,12 @@ struct tegra_ahb { static inline u32 gizmo_readl(struct tegra_ahb *ahb, u32 offset) { - return readl(ahb->regs - 4 + offset); + return readl(ahb->regs + offset); } static inline void gizmo_writel(struct tegra_ahb *ahb, u32 value, u32 offset) { - writel(value, ahb->regs - 4 + offset); + writel(value, ahb->regs + offset); } #ifdef CONFIG_TEGRA_IOMMU_SMMU @@ -258,6 +268,15 @@ static int tegra_ahb_probe(struct platform_device *pdev) return -ENOMEM; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + + /* Correct the IP block base address if necessary */ + if (res && + (res->start & INCORRECT_BASE_ADDR_LOW_BYTE) == + INCORRECT_BASE_ADDR_LOW_BYTE) { + dev_warn(&pdev->dev, "incorrect AHB base address in DT data - enabling workaround\n"); + res->start -= INCORRECT_BASE_ADDR_LOW_BYTE; + } + ahb->regs = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(ahb->regs)) return PTR_ERR(ahb->regs);