From patchwork Thu Aug 29 07:42:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kever Yang X-Patchwork-Id: 1155075 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="p+eSz/Jj"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46Jvjf19L3z9s5b for ; Thu, 29 Aug 2019 17:43:16 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 12BD7C21E9F; Thu, 29 Aug 2019 07:43:12 +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 9F8CEC21C2C; Thu, 29 Aug 2019 07:43:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 81205C21C2C; Thu, 29 Aug 2019 07:43:09 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id D81F0C21C27 for ; Thu, 29 Aug 2019 07:43:08 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id i30so1481476pfk.9 for ; Thu, 29 Aug 2019 00:43:08 -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=POFsvx0tlis20Jxv7aKVlHLXMmUrkfcqMItnolA/An0=; b=p+eSz/JjpMyosuBrHXqGVnznHZK0AnGu46M18xGkjkE55a/Kqxt+T2QrU/f2xT2RLY Y0Gu5rNFJQXvIVe3+IE3Btg1mtz410JoF6y2jqgesQTS5EpqoKsK/jPUxkxfY5t/hwiP Hy8iaHQh2hnyW0x0peWD0xAuQiCE3EROUpGVSgY8oz1FfAuoVJYkV9d3V1Maba1G2TkC G5V40EwqapibXhDudjoXrsKBP60Se66k/MwDNHLkVvCO8z0DXF+tt2vOPpjc1LExL8W4 kfLPc1auWWD5XvWQ0r4CYJSPWF8nwp5zwWmHJcLAOKvFqtAaafNpTtErXdeu2U2Qxnmf wWEQ== 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=POFsvx0tlis20Jxv7aKVlHLXMmUrkfcqMItnolA/An0=; b=DONCOluoO9fOHuk5kIK3mz5IC2MEgEVoMXn7E7Mb280+AmAoQVORUoEW37vUOVnPnN 58nniZ8kpIPEaGr33Banyku24xoHIUqJihg58VhLteUwuD6ne4uJEQUm62sxLLqz+UYr G30/FOuK6xbTCv5E5ioaazRk9WwOn3ZbJWgN/nPAKPXuzBlbmo2KNdrVJ/yZP3wIhgmP Auq6MoK4brE3sjSOVa5hDGEVQZxIGoXeqnRrbrEUHpxZNWfydXJHuhIxsyABQdc4Hur0 wBmJSATBghRWrcjR6caJSlNzHMyMeNAY8ebgEehb1WcFdr/MFCaLuhHHsgXqHjUzaZvU PqQg== X-Gm-Message-State: APjAAAXVPVlr7LeRTCpS3i3hqGN43ExO+I0qKirHkGInTsdW8QZIkbwV jqy2foWaCHO1jLIjJkCwPhI0+0Ej X-Google-Smtp-Source: APXvYqxwv+aDhlrUT2NL/9KlZRgZHEH4PGv3/RNXYf9xIBXJtCKnQV7ehCsclaIe+fhpgg+XIrbp0g== X-Received: by 2002:a63:f857:: with SMTP id v23mr7025157pgj.228.1567064586935; Thu, 29 Aug 2019 00:43:06 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id h17sm1867780pfo.24.2019.08.29.00.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 00:43:06 -0700 (PDT) From: Kever Yang To: u-boot@lists.denx.de Date: Thu, 29 Aug 2019 15:42:41 +0800 Message-Id: <20190829074241.13985-1-kever.yang@rock-chips.com> X-Mailer: git-send-email 2.17.1 Cc: trini@konsulko.com Subject: [U-Boot] [PATCH v2] 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' will overflow if size bigger than 51.2MB after this fix, which should be enough for U-Boot; - 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, and we may use up to 150MHz clock. Fix them in this patch, the max timeout is about 6500 when size is 32MB after fix. Signed-off-by: Kever Yang --- Changes in v2: - use u32 instead of u64 to fix undefined reference to `__udivdi3' in arc architecure. drivers/mmc/dw_mmc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c index 22f6c7eefd..ebe7bcdd90 100644 --- a/drivers/mmc/dw_mmc.c +++ b/drivers/mmc/dw_mmc.c @@ -119,11 +119,12 @@ static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size) { unsigned int timeout; - timeout = size * 8 * 1000; /* counting in bits and msec */ - timeout *= 2; /* wait twice as long */ + timeout = size * 8; /* counting in bits */ + timeout *= 10; /* wait 10 times as long */ timeout /= mmc->clock; timeout /= mmc->bus_width; timeout /= mmc->ddr_mode ? 2 : 1; + timeout *= 1000; /* counting in msec */ timeout = (timeout < 1000) ? 1000 : timeout; return timeout;