From patchwork Fri Oct 4 15:22:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 280653 X-Patchwork-Delegate: trini@ti.com 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 A3C232C00C2 for ; Sat, 5 Oct 2013 01:25:27 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 692B94A0AB; Fri, 4 Oct 2013 17:25:01 +0200 (CEST) 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 mFqBBj5BiqNu; Fri, 4 Oct 2013 17:25:01 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 975404A0D8; Fri, 4 Oct 2013 17:23:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5281A4A067 for ; Fri, 4 Oct 2013 17:23:41 +0200 (CEST) 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 5L-FHZaetQQ6 for ; Fri, 4 Oct 2013 17:23:35 +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 mail-ie0-f174.google.com (mail-ie0-f174.google.com [209.85.223.174]) by theia.denx.de (Postfix) with ESMTPS id 5F6D44A087 for ; Fri, 4 Oct 2013 17:23:16 +0200 (CEST) Received: by mail-ie0-f174.google.com with SMTP id u16so9376475iet.33 for ; Fri, 04 Oct 2013 08:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gEfO1D+p+1edoBjkvPwB/5+MRNdcpPJZKijSPFjEa5I=; b=NaIomF8DlX2OntMkw7ZE3R8zLc1sj7ii3T83d1D41Jf9n8zyseWOrCwlvYbniPvRAv yLU79kCcyLElc4HXO7Y624fpv6sBtCSCvLlxZW6ssAmUYGlr3EISPB3/3ND6XbHhwX7S E6boUYzSCSDTbviNijk0sizT56GkNrVkuM8EalkhIyb0TzlzVkZdES/xvkX1F8iavE4E E02rhgFmYTapWzYq+Zgiq1J3OKBR2CVWCwo2IyxhV6PEgmBELB3DhQCpSzKdPZ4bywbr Xhpe3Q4C5NHQFklVtREu6X/aEYvC+Mi+9/ZTbPWy3eekZkA4v6QM2VpveErDubZ55GZO 77ow== X-Received: by 10.43.129.197 with SMTP id hj5mr666322icc.84.1380900194840; Fri, 04 Oct 2013 08:23:14 -0700 (PDT) Received: from rob-laptop.calxeda.com ([173.226.190.126]) by mx.google.com with ESMTPSA id f5sm7421998igc.4.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Oct 2013 08:23:14 -0700 (PDT) From: Rob Herring To: u-boot@lists.denx.de Date: Fri, 4 Oct 2013 10:22:44 -0500 Message-Id: <1380900168-23791-6-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380900168-23791-1-git-send-email-robherring2@gmail.com> References: <1378671174-18535-1-git-send-email-robherring2@gmail.com> <1380900168-23791-1-git-send-email-robherring2@gmail.com> Cc: Rob Herring Subject: [U-Boot] [PATCH v2 5/9] ARM: mx25: convert to common timer code 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Rob Herring Convert mx25 to use the commmon timer code. Signed-off-by: Rob Herring --- v2: - Use GPT struct for register offset arch/arm/cpu/arm926ejs/mx25/timer.c | 117 ------------------------------------ include/configs/mx25pdk.h | 4 ++ include/configs/tx25.h | 5 +- include/configs/zmx25.h | 6 ++ 4 files changed, 14 insertions(+), 118 deletions(-) diff --git a/arch/arm/cpu/arm926ejs/mx25/timer.c b/arch/arm/cpu/arm926ejs/mx25/timer.c index 42b6076..7f19791 100644 --- a/arch/arm/cpu/arm926ejs/mx25/timer.c +++ b/arch/arm/cpu/arm926ejs/mx25/timer.c @@ -21,65 +21,8 @@ */ #include -#include #include #include -#include - -DECLARE_GLOBAL_DATA_PTR; - -#define timestamp (gd->arch.tbl) -#define lastinc (gd->arch.lastinc) - -/* - * "time" is measured in 1 / CONFIG_SYS_HZ seconds, - * "tick" is internal timer period - */ -#ifdef CONFIG_MX25_TIMER_HIGH_PRECISION -/* ~0.4% error - measured with stop-watch on 100s boot-delay */ -static inline unsigned long long tick_to_time(unsigned long long tick) -{ - tick *= CONFIG_SYS_HZ; - do_div(tick, MXC_CLK32); - return tick; -} - -static inline unsigned long long time_to_tick(unsigned long long time) -{ - time *= MXC_CLK32; - do_div(time, CONFIG_SYS_HZ); - return time; -} - -static inline unsigned long long us_to_tick(unsigned long long us) -{ - us = us * MXC_CLK32 + 999999; - do_div(us, 1000000); - return us; -} -#else -/* ~2% error */ -#define TICK_PER_TIME ((MXC_CLK32 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ) -#define US_PER_TICK (1000000 / MXC_CLK32) - -static inline unsigned long long tick_to_time(unsigned long long tick) -{ - do_div(tick, TICK_PER_TIME); - return tick; -} - -static inline unsigned long long time_to_tick(unsigned long long time) -{ - return time * TICK_PER_TIME; -} - -static inline unsigned long long us_to_tick(unsigned long long us) -{ - us += US_PER_TICK - 1; - do_div(us, US_PER_TICK); - return us; -} -#endif /* nothing really to do with interrupts, just starts up a counter. */ /* The 32KHz 32-bit timer overruns in 134217 seconds */ @@ -104,63 +47,3 @@ int timer_init(void) return 0; } - -unsigned long long get_ticks(void) -{ - struct gpt_regs *gpt = (struct gpt_regs *)IMX_GPT1_BASE; - ulong now = readl(&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; -} - -ulong get_timer_masked(void) -{ - /* - * get_ticks() returns a long long (64 bit), it wraps in - * 2^64 / MXC_CLK32 = 2^64 / 2^15 = 2^49 ~ 5 * 10^14 (s) ~ - * 5 * 10^9 days... and get_ticks() * CONFIG_SYS_HZ wraps in - * 5 * 10^6 days - long enough. - */ - return tick_to_time(get_ticks()); -} - -ulong get_timer(ulong base) -{ - return get_timer_masked() - base; -} - -/* delay x useconds AND preserve advance timstamp value */ -void __udelay(unsigned long usec) -{ - unsigned long long tmp; - ulong tmo; - - tmo = us_to_tick(usec); - tmp = get_ticks() + tmo; /* get current timestamp */ - - while (get_ticks() < tmp) /* loop till event */ - /*NOP*/; -} - -/* - * This function is derived from PowerPC code (timebase clock frequency). - * On ARM it returns the number of timer ticks per second. - */ -ulong get_tbclk(void) -{ - ulong tbclk; - - tbclk = MXC_CLK32; - return tbclk; -} diff --git a/include/configs/mx25pdk.h b/include/configs/mx25pdk.h index 543c415..0a9f442 100644 --- a/include/configs/mx25pdk.h +++ b/include/configs/mx25pdk.h @@ -16,6 +16,10 @@ #define CONFIG_SYS_TEXT_BASE 0x81200000 #define CONFIG_MXC_GPIO +#define CONFIG_SYS_TIMER_RATE 32768 +#define CONFIG_SYS_TIMER_COUNTER \ + (&((struct gpt_regs *)IMX_GPT1_BASE)->counter) + #define CONFIG_DISPLAY_CPUINFO #define CONFIG_DISPLAY_BOARDINFO diff --git a/include/configs/tx25.h b/include/configs/tx25.h index 93dd3c5..beea612 100644 --- a/include/configs/tx25.h +++ b/include/configs/tx25.h @@ -16,6 +16,9 @@ #define CONFIG_MX25 #define CONFIG_MX25_CLK32 32000 /* OSC32K frequency */ #define CONFIG_SYS_HZ 1000 +#define CONFIG_SYS_TIMER_RATE CONFIG_MX25_CLK32 +#define CONFIG_SYS_TIMER_COUNTER \ + (&((struct gpt_regs *)IMX_GPT1_BASE)->counter) #define CONFIG_SYS_MONITOR_LEN (256 << 10) /* 256 kB for U-Boot */ diff --git a/include/configs/zmx25.h b/include/configs/zmx25.h index 765b849..ee48429 100644 --- a/include/configs/zmx25.h +++ b/include/configs/zmx25.h @@ -10,11 +10,17 @@ #ifndef __CONFIG_H #define __CONFIG_H +#include + #define CONFIG_ARM926EJS /* arm926ejs CPU core */ #define CONFIG_MX25 #define CONFIG_SYS_HZ 1000 #define CONFIG_SYS_TEXT_BASE 0xA0000000 +#define CONFIG_SYS_TIMER_RATE 32768 +#define CONFIG_SYS_TIMER_COUNTER \ + (&((struct gpt_regs *)IMX_GPT1_BASE)->counter) + #define CONFIG_MACH_TYPE MACH_TYPE_ZMX25 /* * Environment settings