From patchwork Thu Mar 3 03:48:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Priyanka Jain X-Patchwork-Id: 85220 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 837F2B70AF for ; Thu, 3 Mar 2011 14:49:18 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5F17F2807D; Thu, 3 Mar 2011 04:49:14 +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 KEozRnTbfYwc; Thu, 3 Mar 2011 04:49:14 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 808FA28087; Thu, 3 Mar 2011 04:49:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 55E7828087 for ; Thu, 3 Mar 2011 04:49:09 +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 W9RyqeWzOppM for ; Thu, 3 Mar 2011 04:49:07 +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 TX2EHSOBE005.bigfish.com (tx2ehsobe003.messaging.microsoft.com [65.55.88.13]) by theia.denx.de (Postfix) with ESMTPS id 0F1DA2807D for ; Thu, 3 Mar 2011 04:49:04 +0100 (CET) Received: from mail73-tx2-R.bigfish.com (10.9.14.240) by TX2EHSOBE005.bigfish.com (10.9.40.25) with Microsoft SMTP Server id 14.1.225.8; Thu, 3 Mar 2011 03:49:03 +0000 Received: from mail73-tx2 (localhost.localdomain [127.0.0.1]) by mail73-tx2-R.bigfish.com (Postfix) with ESMTP id 14DA4C183CA; Thu, 3 Mar 2011 03:49:03 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh2a8h668h) X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:de01egw01.freescale.net; RD:de01egw01.freescale.net; EFVD:NLI Received: from mail73-tx2 (localhost.localdomain [127.0.0.1]) by mail73-tx2 (MessageSwitch) id 1299124142786424_20620; Thu, 3 Mar 2011 03:49:02 +0000 (UTC) Received: from TX2EHSMHS049.bigfish.com (unknown [10.9.14.250]) by mail73-tx2.bigfish.com (Postfix) with ESMTP id BBE1C1C68050; Thu, 3 Mar 2011 03:49:02 +0000 (UTC) Received: from de01egw01.freescale.net (192.88.165.102) by TX2EHSMHS049.bigfish.com (10.9.99.149) with Microsoft SMTP Server (TLS) id 14.1.225.8; Thu, 3 Mar 2011 03:49:02 +0000 Received: from az33smr01.freescale.net (az33smr01.freescale.net [10.64.34.199]) by de01egw01.freescale.net (8.14.3/8.14.3) with ESMTP id p233n0Cd009599; Wed, 2 Mar 2011 20:49:01 -0700 (MST) Received: from lc1106.zin33.ap.freescale.net (lc1106.zin33.ap.freescale.net [10.232.3.106]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p233mwBM018766; Wed, 2 Mar 2011 21:48:59 -0600 (CST) Received: by lc1106.zin33.ap.freescale.net (Postfix, from userid 65011109) id 2BCC8C06B; Thu, 3 Mar 2011 09:18:57 +0530 (IST) From: Priyanka Jain To: Date: Thu, 3 Mar 2011 09:18:56 +0530 Message-ID: <1299124136-26859-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 Tested-by: Stefano Babic --- 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)