From patchwork Tue Apr 14 03:40:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Mao X-Patchwork-Id: 11486643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7651E912 for ; Tue, 14 Apr 2020 03:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F13C2075E for ; Tue, 14 Apr 2020 03:41:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="WOKQGFXH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404878AbgDNDk7 (ORCPT ); Mon, 13 Apr 2020 23:40:59 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:19563 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2404874AbgDNDk6 (ORCPT ); Mon, 13 Apr 2020 23:40:58 -0400 X-UUID: 130231d2b9d145989eaf1c2be2eb8a40-20200414 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=pXbuHYf29wq9I5dB9+bPlMg2JqoQVfcEPpb8kdg9al4=; b=WOKQGFXHfVI/VIGaXPZyHMPLRnupYoN2y/YqVZyftVjEx5/1eO3QiaNVZ+qhCrR1RzQUfwVGQ1GkE36pkUftFDezbcphpkGR5yCmmSvCUaK4YdK4URSmesoEiFBg6udCBwd3Wo+TXG3cAsRD+/favOs723Knrt/6oO2Oky6Rm5Y=; X-UUID: 130231d2b9d145989eaf1c2be2eb8a40-20200414 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1549726525; Tue, 14 Apr 2020 11:40:55 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 14 Apr 2020 11:40:54 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 14 Apr 2020 11:40:49 +0800 From: Yong Mao To: Ulf Hansson CC: Chaotian Jing , Matthias Brugger , , , , , , yong mao Subject: [PATCH 1/3] mmc: core: need do mmc_power_cycle in mmc_sdio_resend_if_cond Date: Tue, 14 Apr 2020 11:40:09 +0800 Message-ID: <1586835611-13857-2-git-send-email-yong.mao@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> References: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: yong mao When mmc_sdio_resned_if_cond is invoked, it indicates the SDIO device is not in the right state. In this condition, the previous implementation of mmc_sdio_resend_if_cond can't make sure SDIO device be back to idle state. mmc_power_cycle can reset the SDIO device by HW and also make sure SDIO device enter to idle state correctly. Signed-off-by: Yong Mao --- drivers/mmc/core/sdio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index ebb387a..ada0a80 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -546,6 +546,7 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card) static void mmc_sdio_resend_if_cond(struct mmc_host *host, struct mmc_card *card) { + mmc_power_cycle(host, host->card->ocr); sdio_reset(host); mmc_go_idle(host); mmc_send_if_cond(host, host->ocr_avail); From patchwork Tue Apr 14 03:40:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Mao X-Patchwork-Id: 11486635 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D599912 for ; Tue, 14 Apr 2020 03:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6570520768 for ; Tue, 14 Apr 2020 03:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="qMawx4L1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404885AbgDNDk7 (ORCPT ); Mon, 13 Apr 2020 23:40:59 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:9307 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2404876AbgDNDk7 (ORCPT ); Mon, 13 Apr 2020 23:40:59 -0400 X-UUID: b47fd18de3554a16b50955e8fdc3d0e0-20200414 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=JsY5/5MxfWy5R02rcWXL2W12h0vpsAqE2P25DGsOcwQ=; b=qMawx4L1R/SjXIumd+N18jT98mhib9GBHE/6xKN4SzsESCYRKHzRFy2RFV/S12IkcmRMtOP8nuA40Yr4WSdE1IqQrgFlKhNQXzUB0F78b2+qDR+6rcKIBXyD4YvKtI9zOZ1r+tTLDm5AIXe9awqXheBy1WtQ/Qr88X2Bb4VKYGQ=; X-UUID: b47fd18de3554a16b50955e8fdc3d0e0-20200414 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 903558651; Tue, 14 Apr 2020 11:40:55 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 14 Apr 2020 11:40:55 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 14 Apr 2020 11:40:49 +0800 From: Yong Mao To: Ulf Hansson CC: Chaotian Jing , Matthias Brugger , , , , , , yong mao Subject: [PATCH 2/3] mmc: core: rocr verification Date: Tue, 14 Apr 2020 11:40:10 +0800 Message-ID: <1586835611-13857-3-git-send-email-yong.mao@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> References: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: yong mao Some UHS SDIO devices can't enter to stable state after changing the voltage from 1.8v to 3.3v even after a power cycle. Verifying the rocr and the result of mmc_set_signal_voltage, if it is not expected, power cycle SDIO device and re-initialize it again. Thus will re-initialize the SDIO device successfully. Signed-off-by: Yong Mao --- drivers/mmc/core/sdio.c | 14 +++++++++++++- include/linux/mmc/sdio.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index ada0a80..f173cad 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -553,6 +553,12 @@ static void mmc_sdio_resend_if_cond(struct mmc_host *host, mmc_remove_card(card); } +static bool mmc_sdio_valid_rocr(u32 rocr) +{ + return (rocr & MMC_CARD_BUSY) && R4_OCR(rocr) && + R4_FUNCTION_NUMBER(rocr); +} + /* * Handle the detection and initialisation of a card. * @@ -605,6 +611,12 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, goto err; } + if (!mmc_sdio_valid_rocr(rocr)) { + mmc_sdio_resend_if_cond(host, card); + retries--; + goto try_again; + } + if ((rocr & R4_MEMORY_PRESENT) && mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) { card->type = MMC_TYPE_SD_COMBO; @@ -646,7 +658,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, */ if (rocr & ocr & R4_18V_PRESENT) { err = mmc_set_uhs_voltage(host, ocr_card); - if (err == -EAGAIN) { + if (err == -EAGAIN || err == -EILSEQ) { mmc_sdio_resend_if_cond(host, card); retries--; goto try_again; diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h index e287699..03e23ec 100644 --- a/include/linux/mmc/sdio.h +++ b/include/linux/mmc/sdio.h @@ -36,6 +36,8 @@ #define R4_18V_PRESENT (1<<24) #define R4_MEMORY_PRESENT (1 << 27) +#define R4_OCR(x) ((x) & 0xFFFFFF) +#define R4_FUNCTION_NUMBER(x) (((x) & 0x70000000) >> 28) /* SDIO status in R5 From patchwork Tue Apr 14 03:40:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Mao X-Patchwork-Id: 11486637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3E0B912 for ; Tue, 14 Apr 2020 03:41:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB513206C0 for ; Tue, 14 Apr 2020 03:41:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="hkvI7C/d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404895AbgDNDlB (ORCPT ); Mon, 13 Apr 2020 23:41:01 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:16151 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2404877AbgDNDlA (ORCPT ); Mon, 13 Apr 2020 23:41:00 -0400 X-UUID: aaf2067a1a0a453a9baad549a1a15e3e-20200414 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=SkuybeaYmadFxyJ4GbnzpSoKVqrqaPzUzjiC/dZm8Jw=; b=hkvI7C/dlEUsEq1OtfZDTkkdZYWqJRrvmDlVyaNOzUUgfMFRs3x87M9ol+nyAEx207mmqnfjd8XdDA5P5g1wneraCwvjb7gQnhQyyfXkNQ8AAz4qJphyricLL4AY2mrD6ZySm0KKvesrFlKCLpctnN3ZGCnENaAduj2cP4HmkMo=; X-UUID: aaf2067a1a0a453a9baad549a1a15e3e-20200414 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 925647458; Tue, 14 Apr 2020 11:40:57 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 14 Apr 2020 11:40:55 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 14 Apr 2020 11:40:50 +0800 From: Yong Mao To: Ulf Hansson CC: Chaotian Jing , Matthias Brugger , , , , , , yong mao Subject: [PATCH 3/3] mmc: core: fix mmc_sdio_reinit_card fail issue Date: Tue, 14 Apr 2020 11:40:11 +0800 Message-ID: <1586835611-13857-4-git-send-email-yong.mao@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> References: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: yong mao If SDIO device is initialized by UHS mode, it will run with 1.8v power. In this mode, mmc_go_idle may not make SDIO device go idle successfully in some special SDIO device. And then it can't be re-initialized successfully. According to the logic in sdio_reset_comm and mmc_sdio_sw_reset, invoking mmc_set_clock(host, host->f_min) before mmc_send_io_op_cond can make this SDIO device back to right state. Signed-off-by: Yong Mao --- drivers/mmc/core/sdio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index f173cad..dc4dc63 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -850,6 +850,7 @@ static int mmc_sdio_reinit_card(struct mmc_host *host) sdio_reset(host); mmc_go_idle(host); + mmc_set_clock(host, host->f_min); mmc_send_if_cond(host, host->card->ocr); ret = mmc_send_io_op_cond(host, 0, NULL);