From patchwork Wed Aug 14 08:38:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 1146845 X-Patchwork-Delegate: van.freenix@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jiNxA782"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 467jfn0TVrz9sDB for ; Wed, 14 Aug 2019 18:38:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3BE94C21DC1; Wed, 14 Aug 2019 08:38:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 76267C21C27; Wed, 14 Aug 2019 08:38:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4095EC21C27; Wed, 14 Aug 2019 08:38:46 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 9B880C21BE5 for ; Wed, 14 Aug 2019 08:38:45 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id u17so52726494pgi.6 for ; Wed, 14 Aug 2019 01:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=6BKM4BsuJqIQxbZoZKVnp0KydLdWg4ScRC3s/tiJgpI=; b=jiNxA782r80DWTmY09fmpBOt5dgJjnALYF8wgniyVI3PsI67QM1nJv8iwwN/Ajhoq6 xaZDSAbAeIum9eZNHsVMWYJoQhoYOKol83XpSGyuUEMH0f5BM55Qj+5MyDmqRs3FUN7I 9D2DjL1s2cismTUJS2cLez9mAjWcJa0O8Bx7MqkH4+lTFklilSkvCaF7QFCpkcDzX1XM 3l6AlEYX9lBhxLFyOECyvA8H0aXixPpRI6RJxZSWmMoJXk2e3MDdZWLWkEk1D61SgYmh fcUCX4jWIPv81/bOJKvDvDJcHd5eDVouulS8N7fWCCerPdtG8TLhgM74IRYFGRiog/PR 1ujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=6BKM4BsuJqIQxbZoZKVnp0KydLdWg4ScRC3s/tiJgpI=; b=CxbcWFW5yOPYPlCFcCAt1z4yTRok0fbicNVOk4Iwep9sudjHzYFGbhXSe32+9WBS45 1IvWE/NC3qZrOKz+VLkEA4hZkaLd3xV1J9n2igEQFXNUCe0CgXLHtz+BTOKLrJvugWMC ReRutm8wzpz170cG/0RhB4QKpDpgvgIPf4glZRmfr/SGwhe5FWp2yJ+GqbXVYxOpzoBd 0qNw80sXPAMFHBwVsZDEo+G0aAh9TY1XlhpUoYQ4KgIMJID1MI+aEWDkpNz1rPew96OW JWwnN925zwYC6eYOxTrUw+Bv3CXnIMg8JUg0OojAXe8tPMDye6b3ZWsYPgvsppvtT3k8 /gkQ== X-Gm-Message-State: APjAAAV0ajTpNI1YHGIOWxqSiftB8UlMl23HY5/3BdrUOu5n2t/uPgA5 eSgTTtevjYrofQr0Z87M2xHl/a0YOao= X-Google-Smtp-Source: APXvYqzKPJ55NzT70cXSqIWJHVwiUCT2Hp9AW0A3WmtPO7PlqRi1I2i+5D/2pKFiydSVGr8Y9JNzjA== X-Received: by 2002:a62:8281:: with SMTP id w123mr14841596pfd.36.1565771923850; Wed, 14 Aug 2019 01:38:43 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id z68sm104838810pgz.88.2019.08.14.01.38.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 01:38:43 -0700 (PDT) From: Kever Yang To: u-boot@lists.denx.de Date: Wed, 14 Aug 2019 16:38:19 +0800 Message-Id: <20190814083819.5784-1-kever.yang@rock-chips.com> X-Mailer: git-send-email 2.17.1 Cc: trini@konsulko.com Subject: [U-Boot] [PATCH] mmc: dw_mmc: fix timeout calculate method X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" There are two cases not been considered: - use uint for timeout, it will overflow when size bigger than 512KB for it *8*1000 at the beginning, but we may use size up to 32MB; - The timeout is using clock speed for data rate, but the device may not have such high speed, eg. clock is 52MHz while the device write speed may be less than 10MB/s. Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix. Signed-off-by: Kever Yang --- drivers/mmc/dw_mmc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 22f6c7eefd..2cb61ba184 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -117,10 +117,10 @@ static int dwmci_fifo_ready(struct dwmci_host *host, u32 bit, u32 *len) static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size) { - unsigned int timeout; + u64 timeout; - timeout = size * 8 * 1000; /* counting in bits and msec */ - timeout *= 2; /* wait twice as long */ + timeout = (u64)size * 8 * 1000; /* counting in bits and msec */ + timeout *= 10; /* wait 10 times as long */ timeout /= mmc->clock; timeout /= mmc->bus_width; timeout /= mmc->ddr_mode ? 2 : 1;