From patchwork Mon Mar 4 14:16:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 224740 X-Patchwork-Delegate: sbabic@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 DBC522C0303 for ; Tue, 5 Mar 2013 01:16:58 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2FF894A026; Mon, 4 Mar 2013 15:16:57 +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 KdaWzUGyAoN9; Mon, 4 Mar 2013 15:16:56 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8938A4A027; Mon, 4 Mar 2013 15:16:55 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AC4FC4A027 for ; Mon, 4 Mar 2013 15:16:53 +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 K3pFdB31p+P8 for ; Mon, 4 Mar 2013 15:16:52 +0100 (CET) X-Greylist: delayed 18875 seconds by postgrey-1.27 at theia; Mon, 04 Mar 2013 15:16:50 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 smtp6-v.fe.bosch.de (smtp6-v.fe.bosch.de [139.15.237.11]) by theia.denx.de (Postfix) with ESMTPS id 9117E4A026 for ; Mon, 4 Mar 2013 15:16:50 +0100 (CET) Received: from vsmta14.fe.internet.bosch.com (unknown [10.4.98.54]) by imta24.fe.bosch.de (Postfix) with ESMTP id A5BFBD8022F for ; Mon, 4 Mar 2013 15:16:50 +0100 (CET) Received: from localhost (vsgw2.fe.internet.bosch.com [10.4.98.13]) by vsmta14.fe.internet.bosch.com (Postfix) with SMTP id 9C4EC1B40A0E for ; Mon, 4 Mar 2013 15:16:50 +0100 (CET) Received: from FE-HUB1000.de.bosch.com (10.4.103.107) by fe-hub06.de.bosch.com (10.3.153.133) with Microsoft SMTP Server (TLS) id 8.3.298.1; Mon, 4 Mar 2013 15:16:45 +0100 Received: from hi-z5661.hi.de.bosch.com (10.34.217.143) by FE-HUB1000.de.bosch.com (10.4.103.107) with Microsoft SMTP Server id 14.2.328.9; Mon, 4 Mar 2013 15:16:06 +0100 Received: from localhost.localdomain (localhost [127.0.0.1]) by hi-z5661.hi.de.bosch.com (Postfix) with ESMTP id 3FAB6407F9; Mon, 4 Mar 2013 15:16:06 +0100 (CET) From: Dirk Behme To: Date: Mon, 4 Mar 2013 15:16:02 +0100 Message-ID: <1362406562-17986-1-git-send-email-dirk.behme@de.bosch.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 Cc: Dirk Behme , Knut Wohlrab Subject: [U-Boot] [PATCH] imx-common: timer: fix 32-bit overflow 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Knut Wohlrab The i.MX6 common timer uses the 32-bit variable tbl (time base lower) to record the overflow of the 32-bit counter. I.e. if the counter overflows, the variable tbl does overflow, too. To capture this overflow, use the variable tbu (time base upper), too. Return the combined value of tbl and tbu. lastinc is unused then, remove it. Signed-off-by: Knut Wohlrab Signed-off-by: Dirk Behme Acked-by: Stefano Babic --- Note: This replaces the patch http://patchwork.ozlabs.org/patch/224646/ arch/arm/imx-common/timer.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) Index: freescale-u-boot-imx.git/arch/arm/imx-common/timer.c =================================================================== --- freescale-u-boot-imx.git.orig/arch/arm/imx-common/timer.c +++ freescale-u-boot-imx.git/arch/arm/imx-common/timer.c @@ -48,9 +48,6 @@ static struct mxc_gpt *cur_gpt = (struct DECLARE_GLOBAL_DATA_PTR; -#define timestamp (gd->arch.tbl) -#define lastinc (gd->arch.lastinc) - static inline unsigned long long tick_to_time(unsigned long long tick) { tick *= CONFIG_SYS_HZ; @@ -70,7 +67,6 @@ static inline unsigned long long us_to_t int timer_init(void) { int i; - ulong val; /* setup GP Timer 1 */ __raw_writel(GPTCR_SWR, &cur_gpt->control); @@ -85,9 +81,8 @@ int timer_init(void) i = __raw_readl(&cur_gpt->control); __raw_writel(i | GPTCR_CLKSOURCE_32 | GPTCR_TEN, &cur_gpt->control); - val = __raw_readl(&cur_gpt->counter); - lastinc = val / (MXC_CLK32 / CONFIG_SYS_HZ); - timestamp = 0; + gd->arch.tbl = __raw_readl(&cur_gpt->counter); + gd->arch.tbu = 0; return 0; } @@ -96,18 +91,11 @@ unsigned long long get_ticks(void) { ulong now = __raw_readl(&cur_gpt->counter); /* current tick value */ - if (now >= lastinc) { - /* - * normal mode (non roll) - * move stamp forward with absolut diff ticks - */ - timestamp += (now - lastinc); - } else { - /* we have rollover of incrementer */ - timestamp += (0xFFFFFFFF - lastinc) + now; - } - lastinc = now; - return timestamp; + /* increment tbu if tbl has rolled over */ + if (now < gd->arch.tbl) + gd->arch.tbu++; + gd->arch.tbl = now; + return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl; } ulong get_timer_masked(void)