From patchwork Wed Mar 2 04:29:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Priyanka Jain X-Patchwork-Id: 85025 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 827CEB714E for ; Wed, 2 Mar 2011 15:30:07 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D2A1128135; Wed, 2 Mar 2011 05:30:03 +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 6tBeZino3U4g; Wed, 2 Mar 2011 05:30:03 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7BDFF2811D; Wed, 2 Mar 2011 05:30:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3A8CA2811D for ; Wed, 2 Mar 2011 05:30:00 +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 eXNenB5JZHqB for ; Wed, 2 Mar 2011 05:29:59 +0100 (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 DB3EHSOBE005.bigfish.com (db3ehsobe005.messaging.microsoft.com [213.199.154.143]) by theia.denx.de (Postfix) with ESMTPS id 072E4280DF for ; Wed, 2 Mar 2011 05:29:57 +0100 (CET) Received: from mail58-db3-R.bigfish.com (10.3.81.251) by DB3EHSOBE005.bigfish.com (10.3.84.25) with Microsoft SMTP Server id 14.1.225.8; Wed, 2 Mar 2011 04:29:56 +0000 Received: from mail58-db3 (localhost.localdomain [127.0.0.1]) by mail58-db3-R.bigfish.com (Postfix) with ESMTP id B13023903AD; Wed, 2 Mar 2011 04:29:56 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh2a8h668h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:de01egw01.freescale.net; RD:de01egw01.freescale.net; EFVD:NLI Received: from mail58-db3 (localhost.localdomain [127.0.0.1]) by mail58-db3 (MessageSwitch) id 129904019699002_9268; Wed, 2 Mar 2011 04:29:56 +0000 (UTC) Received: from DB3EHSMHS002.bigfish.com (unknown [10.3.81.246]) by mail58-db3.bigfish.com (Postfix) with ESMTP id 0B6D8A10053; Wed, 2 Mar 2011 04:29:56 +0000 (UTC) Received: from de01egw01.freescale.net (192.88.165.102) by DB3EHSMHS002.bigfish.com (10.3.87.102) with Microsoft SMTP Server (TLS) id 14.1.225.8; Wed, 2 Mar 2011 04:29:55 +0000 Received: from az33smr02.freescale.net (az33smr02.freescale.net [10.64.34.200]) by de01egw01.freescale.net (8.14.3/8.14.3) with ESMTP id p224ToZ0023574; Tue, 1 Mar 2011 21:29:50 -0700 (MST) Received: from lc1106.zin33.ap.freescale.net (lc1106.zin33.ap.freescale.net [10.232.3.106]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p224TlcD022282; Tue, 1 Mar 2011 22:29:47 -0600 (CST) Received: by lc1106.zin33.ap.freescale.net (Postfix, from userid 65011109) id 25BE9C06A; Wed, 2 Mar 2011 09:59:46 +0530 (IST) From: Priyanka Jain To: Date: Wed, 2 Mar 2011 09:59:45 +0530 Message-ID: <1299040185-21345-1-git-send-email-Priyanka.Jain@freescale.com> X-Mailer: git-send-email 1.6.5.6 MIME-Version: 1.0 X-OriginatorOrg: freescale.net Cc: Priyanka Jain , Andy Fleming , Kumar Gala Subject: [U-Boot] [PATCH][v3] fsl_esdhc: Correcting esdhc timeout counter calculation 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 - Timeout counter value is set as DTOCV bits in SYSCTL register For counter value set as timeout, Timeout period = (2^(timeout + 13)) SD Clock cycles - As per 4.6.2.2 section of SD Card specification v2.00, host should cofigure timeout period value to minimum 0.25 sec. - Number of SD Clock cycles for 0.25sec should be minimum (SD Clock/sec * 0.25 sec) SD Clock cycles = (mmc->tran_speed * 1/4) SD Clock cycles - Calculating timeout based on (2^(timeout + 13)) >= mmc->tran_speed * 1/4 Taking log2 both the sides and rounding up to next power of 2 => timeout + 13 = log2(mmc->tran_speed/4) + 1 Signed-off-by: Priyanka Jain Signed-off-by: Andy Fleming Signed-off-by: Kumar Gala Acked-by: Mingkai Hu --- Changes for v3: Including code changes of v1 as suggested by Stefano Babic Changes for v2: Added proper description as suggested by Wolfgang Denk drivers/mmc/fsl_esdhc.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c index a368fe6..359d939 100644 --- a/drivers/mmc/fsl_esdhc.c +++ b/drivers/mmc/fsl_esdhc.c @@ -207,7 +207,21 @@ static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data) esdhc_write32(®s->blkattr, data->blocks << 16 | data->blocksize); /* Calculate the timeout period for data transactions */ - timeout = fls(mmc->tran_speed/10) - 1; + /* + * 1)Timeout period = (2^(timeout+13)) SD Clock cycles + * 2)Timeout period should be minimum 0.250sec as per SD Card spec + * So, Number of SD Clock cycles for 0.25sec should be minimum + * (SD Clock/sec * 0.25 sec) SD Clock cycles + * = (mmc->tran_speed * 1/4) SD Clock cycles + * As 1) >= 2) + * => (2^(timeout+13)) >= mmc->tran_speed * 1/4 + * Taking log2 both the sides + * => timeout + 13 >= log2(mmc->tran_speed/4) + * Rounding up to next power of 2 + * => timeout + 13 = log2(mmc->tran_speed/4) + 1 + * => timeout + 13 = fls(mmc->tran_speed/4) + */ + timeout = fls(mmc->tran_speed/4); timeout -= 13; if (timeout > 14)