Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D38B8C77B6E for ; Fri, 14 Apr 2023 08:49:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0321F85EA5; Fri, 14 Apr 2023 10:49:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7A8A285EC1; Fri, 14 Apr 2023 10:49:32 +0200 (CEST) Received: from mail-m11880.qiye.163.com (mail-m11880.qiye.163.com [115.236.118.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ECAC385E73 for ; Fri, 14 Apr 2023 10:49:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kever.yang@rock-chips.com Received: from [172.16.12.93] (unknown [58.22.7.114]) by mail-m11880.qiye.163.com (Hmail) with ESMTPA id 5F1AB2016D; Fri, 14 Apr 2023 16:49:13 +0800 (CST) Message-ID: Date: Fri, 14 Apr 2023 16:49:13 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v2] mmc: dw_mmc: reset controller after data error Content-Language: en-US To: Eugen Hristev , u-boot@lists.denx.de Cc: jh80.chung@samsung.com, peng.fan@nxp.com, jonas@kwiboo.se, jagan@edgeble.ai, Ziyuan Xu , Jason Zhu References: <20230403104446.222320-1-eugen.hristev@collabora.com> From: Kever Yang In-Reply-To: <20230403104446.222320-1-eugen.hristev@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGU9PGlZOGE9NHUJNHklOTR5VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpMVUpLS1VLWQ Y+ X-HM-Tid: 0a877ef451cc2eb6kusn5f1ab2016d X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Mzo6ATo4PD0KMCEUHUg5Vjcz L08aCS1VSlVKTUNKT01JSk5PSk9IVTMWGhIXVRAeDR4JVQIaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFITUlLNwY+ X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 2023/4/3 18:44, Eugen Hristev wrote: > From: Ziyuan Xu > > Per dw_mmc databook, it's recommended to reset the host controller if > some data-related error occurred. > Implement a reset mechanism. > > Signed-off-by: Ziyuan Xu > Co-developed-by: Jason Zhu > Signed-off-by: Jason Zhu > [eugen.hristev@collabora.com: modified a bit the variables initialization] > Signed-off-by: Eugen Hristev Reviewed-by: Kever Yang Thanks, - Kever > --- > Changes in v2: > - actually decrement the reset timeout timer > > drivers/mmc/dw_mmc.c | 20 +++++++++++++++++++- > 1 file changed, 19 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c > index 5085a3b491da..d6cad998b0cd 100644 > --- a/drivers/mmc/dw_mmc.c > +++ b/drivers/mmc/dw_mmc.c > @@ -138,7 +138,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) > { > struct mmc *mmc = host->mmc; > int ret = 0; > - u32 timeout, mask, size, i, len = 0; > + u32 timeout, reset_timeout = 100, status, ctrl, mask, size, i, len = 0; > u32 *buf = NULL; > ulong start = get_timer(0); > u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> > @@ -159,6 +159,24 @@ static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) > /* Error during data transfer. */ > if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) { > debug("%s: DATA ERROR!\n", __func__); > + > + dwmci_wait_reset(host, DWMCI_RESET_ALL); > + dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | > + DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); > + > + do { > + status = dwmci_readl(host, DWMCI_CMD); > + if (!reset_timeout--) > + break; > + udelay(100); > + } while (status & DWMCI_CMD_START); > + > + if (!host->fifo_mode) { > + ctrl = dwmci_readl(host, DWMCI_BMOD); > + ctrl |= DWMCI_BMOD_IDMAC_RESET; > + dwmci_writel(host, DWMCI_BMOD, ctrl); > + } > + > ret = -EINVAL; > break; > }