From patchwork Mon Mar 13 14:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 1756327 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=JhwCS/lL; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pb0Cw1Qhyz1yWr for ; Tue, 14 Mar 2023 01:58:52 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0BC6585BBD; Mon, 13 Mar 2023 15:58:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="JhwCS/lL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D9C3185CCD; Mon, 13 Mar 2023 15:58:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1985683A35 for ; Mon, 13 Mar 2023 15:58:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eugen.hristev@collabora.com Received: from eugen-station.. (38sdl30m26.codetel.net.do [66.98.60.38]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madras.collabora.co.uk (Postfix) with ESMTPSA id C03986602FEB; Mon, 13 Mar 2023 14:58:38 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678719520; bh=1mFmnaT7VHn0jYLvEhrIz8BIbFVzDofgvSnWnZdDM9A=; h=From:To:Cc:Subject:Date:From; b=JhwCS/lL9+XPJzTb3uQOUPAmjVDLJ2cWMJB/stKPdrnPO5kNyclCN4cSPAwhhd3Xl RuiVBWvL89AxMtCp7CDGe32C5HDxB27PwcTaw+aW49JdJGzQSYwIGoCNdh10Q4ByxC ft0lgw2/IcwMP2BOmjxPkw/Jt+tVQCohSk1+Hymn8kUxrHhOCS9h4EpmEiTas3Im8l 6KQ63m7HhnaAOQHRmuLMfWItnqKQVIOsYozmi4RH7S9CxSoluW11TrejMx0XMWpPuA LhwcZXWY6PNTuEWoMmephL+Ar+iNtb+6SCYaiUbbAr29l/ZBVJL9XKw8CakKuWudyx kTXVOgSbP7F8A== From: Eugen Hristev To: kever.yang@rock-chips.com, jagan@edgeble.ai, u-boot@lists.denx.de, jonas@kwiboo.se, peng.fan@nxp.com, jh80.chung@samsung.com Cc: Ziyuan Xu , Jason Zhu , Eugen Hristev Subject: [PATCH] mmc: dw_mmc: reset controller after data error Date: Mon, 13 Mar 2023 16:58:31 +0200 Message-Id: <20230313145831.41997-1-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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 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 --- 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..7c302ee614f4 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; }