From linux-arm-kernel-bounces@lists.arm.linux.org.uk Thu Mar  2 19:38:57 2006
Return-Path:
	<linux-arm-kernel-bounces+rpurdie=rpsys.net@lists.arm.linux.org.uk>
Received: from localhost (localhost [127.0.0.1]) by tim.rpsys.net
	(8.13.1/8.12.10) with ESMTP id k22JcvBr023626 for <rpurdie@rpsys.net>; Thu,
	2 Mar 2006 19:38:57 GMT
Received: from tim.rpsys.net ([127.0.0.1]) by localhost (tim.rpsys.net
	[127.0.0.1]) (amavisd-new, port 10024) with LMTP id 23299-07 for
	<rpurdie@rpsys.net>; Thu,  2 Mar 2006 19:38:56 +0000 (GMT)
Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [195.92.253.2]) by
	tim.rpsys.net (8.13.1/8.12.10) with ESMTP id k22JcrwQ023620
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for
	<rpurdie@rpsys.net>; Thu, 2 Mar 2006 19:38:54 GMT
Received: from [2002:d412:e8ba:1:201:3dff:fe00:156]
	(helo=lists.arm.linux.org.uk) by ZenIV.linux.org.uk with esmtpsa (Exim 4.52
	#1 (Red Hat Linux)) id 1FEtdJ-00018h-Ru; Thu, 02 Mar 2006 19:38:43 +0000
Received: from localhost ([127.0.0.1] helo=lists.arm.linux.org.uk) by
	lists.arm.linux.org.uk with esmtp (Exim 4.50) id 1FEtcy-0001ei-Hb; Thu, 02
	Mar 2006 19:38:20 +0000
Received: from flint.arm.linux.org.uk
	([2002:d412:e8ba:1:201:2ff:fe14:8fad]) by lists.arm.linux.org.uk with
	esmtpsa (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.50) id
	1FEqCU-0001Rk-LR for linux-arm-kernel@lists.arm.linux.org.uk; Thu, 02 Mar
	2006 15:58:49 +0000
Received: from linux by flint.arm.linux.org.uk with local (Exim 4.52) id
	1FEqCR-0007pV-Bj; Thu, 02 Mar 2006 15:58:43 +0000
Date: Thu, 2 Mar 2006 15:58:42 +0000
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Marcin Juszkiewicz <linux-arm@hrw.one.pl>, linux-arm-kernel@lists.arm.linux.org.uk, Pierre Ossman <drzeus@drzeus.cx>
Message-ID: <20060302155842.GA28902@flint.arm.linux.org.uk>
Mail-Followup-To: Marcin Juszkiewicz <linux-arm@hrw.one.pl>,
	linux-arm-kernel@lists.arm.linux.org.uk, Pierre Ossman <drzeus@drzeus.cx>
References: <200512132232.36817.linux-arm@hrw.one.pl>
	 <20060216163747.GE29468@flint.arm.linux.org.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20060216163747.GE29468@flint.arm.linux.org.uk>
User-Agent: Mutt/1.4.1i
Subject: Re: Problem with SD card on Zaurus C760
X-BeenThere: linux-arm-kernel@lists.arm.linux.org.uk
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: ARM Linux kernel discussions
	<linux-arm-kernel.lists.arm.linux.org.uk>
List-Unsubscribe:
	<http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel>,
	<mailto:linux-arm-kernel-request@lists.arm.linux.org.uk?subject=unsubscribe>
List-Archive: <http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel>
List-Post: <mailto:linux-arm-kernel@lists.arm.linux.org.uk>
List-Help:
	<mailto:linux-arm-kernel-request@lists.arm.linux.org.uk?subject=help>
List-Subscribe:
	<http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel>,
	<mailto:linux-arm-kernel-request@lists.arm.linux.org.uk?subject=subscribe>
Sender: linux-arm-kernel-bounces@lists.arm.linux.org.uk
Errors-To:
	linux-arm-kernel-bounces+rpurdie=rpsys.net+rpurdie=rpsys.net@lists.arm.linux.org.uk
X-Virus-Scanned: amavisd-new at rpsys.net
X-Evolution-Source: imap://richard@tim.rpsys.net/
Content-Transfer-Encoding: 8bit

It would be nice if _someone_ could test this patch please - it won't be
going anywhere near 2.6.16 until it's been confirmed that it fixes the
timeout issue.  It would be a shame if it's found afterwards to have
fixed a real valid problem.

Anyone?

On Thu, Feb 16, 2006 at 04:37:48PM +0000, Russell King - ARM Linux wrote:
> On Tue, Dec 13, 2005 at 10:32:36PM +0100, Marcin Juszkiewicz wrote:
> > I tried to increase timeout in pxamci.c:pxamci_setup_data() (which helped 
> > with my 256M SD card by Pretec) but even with timeout *= 4000 card fails.
> 
> Firstly, your 1GB SD card turned up this morning, thanks.
> 
> Okay, I think this patch should solve the data timeout issue.
> 
> There are two parts of the timeout calculation:
> 
> - card clock independent part (data->timeout_ns).  We calculated this
>   part of the timeout correctly using the hosts clock frequency.
> - card clock dependent part (data->timeout_clks).  We calculated this
>   using the hosts clock frequency, but this is in units of the card
>   clock frequency.
> 
> This meant that if a card specified a card clock dependent part, we
> would mis-calculate the timeout by an order of magnitude proportional
> to the clock divisor.
> 
> Is there any chance you can test this patch with your other problematical
> cards please?

diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -71,11 +71,6 @@ struct pxamci_host {
 	unsigned int		dma_dir;
 };
 
-static inline unsigned int ns_to_clocks(unsigned int ns)
-{
-	return (ns * (CLOCKRATE / 1000000) + 999) / 1000;
-}
-
 static void pxamci_stop_clock(struct pxamci_host *host)
 {
 	if (readl(host->base + MMC_STAT) & STAT_CLK_EN) {
@@ -119,6 +114,7 @@ static void pxamci_disable_irq(struct px
 static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
 {
 	unsigned int nob = data->blocks;
+	unsigned long long clks;
 	unsigned int timeout;
 	u32 dcmd;
 	int i;
@@ -131,7 +127,9 @@ static void pxamci_setup_data(struct pxa
 	writel(nob, host->base + MMC_NOB);
 	writel(1 << data->blksz_bits, host->base + MMC_BLKLEN);
 
-	timeout = ns_to_clocks(data->timeout_ns) + data->timeout_clks;
+	clks = (unsigned long long)data->timeout_ns * CLOCKRATE;
+	do_div(clks, 1000000000UL);
+	timeout = (unsigned int)clks + (data->timeout_clks << host->clkrt);
 	writel((timeout + 255) / 256, host->base + MMC_RDTO);
 
 	if (data->flags & MMC_DATA_READ) {

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

