From patchwork Tue Nov 8 06:08:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Mao X-Patchwork-Id: 9416657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8073D60459 for ; Tue, 8 Nov 2016 06:11:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EE5C28AD9 for ; Tue, 8 Nov 2016 06:11:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6134C28AE4; Tue, 8 Nov 2016 06:11:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE27128AD9 for ; Tue, 8 Nov 2016 06:11:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3zcZ-0004mt-Ie; Tue, 08 Nov 2016 06:10:59 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3zbc-0003Ap-1q; Tue, 08 Nov 2016 06:10:04 +0000 Received: from mtkhts09.mediatek.inc [(172.21.101.70)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1548170437; Tue, 08 Nov 2016 14:09:35 +0800 Received: from mhfsdcap03.localdomain (10.17.3.153) by mtkhts09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.266.1; Tue, 8 Nov 2016 14:09:34 +0800 From: Yong Mao To: Ulf Hansson Subject: [PATCH 1/4] mmc: mediatek: Fix CMD6 timeout issue Date: Tue, 8 Nov 2016 14:08:58 +0800 Message-ID: <1478585341-6749-2-git-send-email-yong.mao@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1478585341-6749-1-git-send-email-yong.mao@mediatek.com> References: <1478585341-6749-1-git-send-email-yong.mao@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161107_221000_499091_FA2C5981 X-CRM114-Status: GOOD ( 18.27 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, YH Huang , Nicolas Boichat , Mathias Nyman , srv_heupstream@mediatek.com, Catalin Marinas , linux-mediatek@lists.infradead.org, Will Deacon , Douglas Anderson , yong mao , linux-kernel@vger.kernel.org, Chunfeng Yun , Rob Herring , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, Philipp Zabel , Matthias Brugger , linux-mmc@vger.kernel.org, Eddie Huang , Chaotian Jing Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: yong mao When initializing EMMC, after switch to HS400, it will issue CMD6 to change ext_csd, if first CMD6 got CRC error, the repeat CMD6 may get timeout, that's because SDCBSY was cleared by msdc_reset_hw() Signed-off-by: Yong Mao Signed-off-by: Chaotian Jing --- drivers/mmc/host/mtk-sd.c | 77 ++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index 84e9afc..b29683b 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -826,6 +826,15 @@ static bool msdc_cmd_done(struct msdc_host *host, int events, return true; } +static int msdc_card_busy(struct mmc_host *mmc) +{ + struct msdc_host *host = mmc_priv(mmc); + u32 status = readl(host->base + MSDC_PS); + + /* check if data0 is low */ + return !(status & BIT(16)); +} + /* It is the core layer's responsibility to ensure card status * is correct before issue a request. but host design do below * checks recommended. @@ -835,10 +844,20 @@ static inline bool msdc_cmd_is_ready(struct msdc_host *host, { /* The max busy time we can endure is 20ms */ unsigned long tmo = jiffies + msecs_to_jiffies(20); + u32 count = 0; + + if (in_interrupt()) { + while ((readl(host->base + SDC_STS) & SDC_STS_CMDBUSY) && + (count < 1000)) { + udelay(1); + count++; + } + } else { + while ((readl(host->base + SDC_STS) & SDC_STS_CMDBUSY) && + time_before(jiffies, tmo)) + cpu_relax(); + } - while ((readl(host->base + SDC_STS) & SDC_STS_CMDBUSY) && - time_before(jiffies, tmo)) - cpu_relax(); if (readl(host->base + SDC_STS) & SDC_STS_CMDBUSY) { dev_err(host->dev, "CMD bus busy detected\n"); host->error |= REQ_CMD_BUSY; @@ -846,17 +865,35 @@ static inline bool msdc_cmd_is_ready(struct msdc_host *host, return false; } - if (mmc_resp_type(cmd) == MMC_RSP_R1B || cmd->data) { - tmo = jiffies + msecs_to_jiffies(20); - /* R1B or with data, should check SDCBUSY */ - while ((readl(host->base + SDC_STS) & SDC_STS_SDCBUSY) && - time_before(jiffies, tmo)) - cpu_relax(); - if (readl(host->base + SDC_STS) & SDC_STS_SDCBUSY) { - dev_err(host->dev, "Controller busy detected\n"); - host->error |= REQ_CMD_BUSY; - msdc_cmd_done(host, MSDC_INT_CMDTMO, mrq, cmd); - return false; + if (cmd->opcode != MMC_SEND_STATUS) { + count = 0; + /* Consider that CMD6 crc error before card was init done, + * mmc_retune() will return directly as host->card is null. + * and CMD6 will retry 3 times, must ensure card is in transfer + * state when retry. + */ + tmo = jiffies + msecs_to_jiffies(60 * 1000); + while (1) { + if (msdc_card_busy(host->mmc)) { + if (in_interrupt()) { + udelay(1); + count++; + } else { + msleep_interruptible(10); + } + } else { + break; + } + /* Timeout if the device never + * leaves the program state. + */ + if (count > 1000 || time_after(jiffies, tmo)) { + pr_err("%s: Card stuck in programming state! %s\n", + mmc_hostname(host->mmc), __func__); + host->error |= REQ_CMD_BUSY; + msdc_cmd_done(host, MSDC_INT_CMDTMO, mrq, cmd); + return false; + } } } return true; @@ -1070,18 +1107,6 @@ static int msdc_ops_switch_volt(struct mmc_host *mmc, struct mmc_ios *ios) return ret; } -static int msdc_card_busy(struct mmc_host *mmc) -{ - struct msdc_host *host = mmc_priv(mmc); - u32 status = readl(host->base + MSDC_PS); - - /* check if any pin between dat[0:3] is low */ - if (((status >> 16) & 0xf) != 0xf) - return 1; - - return 0; -} - static void msdc_request_timeout(struct work_struct *work) { struct msdc_host *host = container_of(work, struct msdc_host,