From patchwork Thu Apr 8 13:43:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rabin Vincent X-Patchwork-Id: 71744 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: wd@gemini.denx.de Delivered-To: wd@gemini.denx.de Received: from diddl.denx.de (diddl.denx.de [10.0.0.6]) by gemini.denx.de (Postfix) with ESMTP id ACD531051E73 for ; Thu, 8 Apr 2010 15:48:21 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id A74D7C913116 for ; Thu, 8 Apr 2010 15:48:20 +0200 (CEST) Received: from pop.mnet-online.de by diddl.denx.de with POP3 (fetchmail-6.3.9) for (single-drop); Thu, 08 Apr 2010 15:48:20 +0200 (CEST) Received: from murder (svr19.m-online.net [192.168.3.147]) by backend2 (Cyrus v2.2.12) with LMTPA; Thu, 08 Apr 2010 15:45:30 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend3.pop.m-online.net (Cyrus v2.2.13) with LMTPA; Thu, 08 Apr 2010 15:45:29 +0200 Received: from scanner-1.m-online.net (unknown [192.168.8.165]) by mail.m-online.net (Postfix) with ESMTP id D867220010F; Thu, 8 Apr 2010 15:45:29 +0200 (CEST) Received: from mxin-1.m-online.net ([192.168.6.164]) by scanner-1.m-online.net (scanner-1.m-online.net [192.168.8.165]) (amavisd-new, port 10026) with ESMTP id 03463-04-5; Thu, 8 Apr 2010 15:45:28 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-1.m-online.net (Postfix) with ESMTP id 6B4B046C0A0; Thu, 8 Apr 2010 15:45:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8253728156; Thu, 8 Apr 2010 15:44:35 +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 h7I6FRtSBaYv; Thu, 8 Apr 2010 15:44:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF3FD28176; Thu, 8 Apr 2010 15:44:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D5C42816F for ; Thu, 8 Apr 2010 15:44:07 +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 1LaIpvWuo5f8 for ; Thu, 8 Apr 2010 15:44:06 +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 eu1sys200aog114.obsmtp.com (eu1sys200aog114.obsmtp.com [207.126.144.137]) by theia.denx.de (Postfix) with ESMTPS id 63B6A28162 for ; Thu, 8 Apr 2010 15:43:57 +0200 (CEST) Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob114.postini.com ([207.126.147.11]) with SMTP ID DSNKS73dnCMXFD/xfV3e7eGyPiEJYaGTI8sl@postini.com; Thu, 08 Apr 2010 13:43:59 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4BC8AFD; Thu, 8 Apr 2010 13:43:56 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0C3CE15D7; Thu, 8 Apr 2010 13:43:56 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 6198BA8095; Thu, 8 Apr 2010 15:43:49 +0200 (CEST) Received: from localhost (10.201.54.39) by exdcvycastm022.EQ1STM.local (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.1.393.1; Thu, 8 Apr 2010 15:43:55 +0200 From: Rabin Vincent To: Date: Thu, 8 Apr 2010 19:13:15 +0530 Message-ID: <1270734200-17762-9-git-send-email-rabin.vincent@stericsson.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1270734200-17762-8-git-send-email-rabin.vincent@stericsson.com> References: <1270734200-17762-1-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-2-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-3-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-4-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-5-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-6-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-7-git-send-email-rabin.vincent@stericsson.com> <1270734200-17762-8-git-send-email-rabin.vincent@stericsson.com> MIME-Version: 1.0 Cc: STEricsson_nomadik_linux@list.st.com, Michael Brandt , Alessandro Rubini Subject: [U-Boot] [PATCHv2 08/13] nomadik-mtu: support configurable clock rates X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 X-Virus-Scanned: by amavisd-new at m-online.net Change the Nomadik MTU driver to get the clock rate and prescaler from the config file. Also remove the hardcoded divisors and do the calculations based on the configured rate. Acked-by: Alessandro Rubini Acked-by: Michael Brandt Signed-off-by: Rabin Vincent --- drivers/misc/nomadik_mtu.c | 23 ++++++++++++----------- include/configs/nhk8815.h | 3 +++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/misc/nomadik_mtu.c b/drivers/misc/nomadik_mtu.c index 0aeeb63..612ab34 100644 --- a/drivers/misc/nomadik_mtu.c +++ b/drivers/misc/nomadik_mtu.c @@ -22,6 +22,7 @@ #include #include +#include struct mtu { uint imsc; @@ -42,14 +43,6 @@ struct mtu { #define MTU_CRn_PRESCALE_256 0x08 #define MTU_CRn_32BITS 0x02 -/* - * The timer is a decrementer, we'll left it free running at 2.4MHz. - * We have 2.4 ticks per microsecond and an overflow in almost 30min - */ -#define TIMER_CLOCK (24 * 100 * 1000) -#define COUNT_TO_USEC(x) ((x) * 5 / 12) /* overflows at 6min */ -#define USEC_TO_COUNT(x) ((x) * 12 / 5) /* overflows at 6min */ - static const struct mtu_timer *timer = &((struct mtu *) CONFIG_SYS_TIMERBASE)->timer[0]; @@ -59,10 +52,18 @@ static ulong read_timer(void) return 0 - readl(&timer->val); } +static unsigned long usec_to_count(unsigned long long usec) +{ + unsigned long long count = usec * CONFIG_NOMADIK_MTU_CLOCK; + do_div(count, 1000000); + return count; +} + /* Configure a free-running, auto-wrap counter with no prescaler */ int timer_init(void) { - writel(MTU_CRn_ENA | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS, &timer->cr); + writel(MTU_CRn_ENA | CONFIG_NOMADIK_MTU_PRESCALE | MTU_CRn_32BITS, + &timer->cr); reset_timer(); return 0; } @@ -85,7 +86,7 @@ void reset_timer(void) /* Return how many HZ passed since "base" */ ulong get_timer(ulong base) { - ulong hz = read_timer() / (TIMER_CLOCK / CONFIG_SYS_HZ); + ulong hz = read_timer() / (CONFIG_NOMADIK_MTU_CLOCK / CONFIG_SYS_HZ); return hz - base; } @@ -95,7 +96,7 @@ void __udelay(unsigned long usec) ulong ini, end; ini = read_timer(); - end = ini + USEC_TO_COUNT(usec); + end = ini + usec_to_count(usec); while ((signed)(end - read_timer()) > 0) ; } diff --git a/include/configs/nhk8815.h b/include/configs/nhk8815.h index c7700b3..2f8294b 100644 --- a/include/configs/nhk8815.h +++ b/include/configs/nhk8815.h @@ -98,6 +98,9 @@ #define CONFIG_SYS_HZ 1000 /* Mandatory... */ #define CONFIG_SYS_TIMERBASE 0x101E2000 #define CONFIG_NOMADIK_MTU +/* We have 2.4 ticks per microsecond and an overflow in almost 30min */ +#define CONFIG_NOMADIK_MTU_CLOCK (24 * 100 * 1000) +#define CONFIG_NOMADIK_MTU_PRESCALE MTU_CRn_PRESCALE_1 /* GPIO */ #define CONFIG_NOMADIK_GPIO