linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yong Mao <yong.mao@mediatek.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Chaotian Jing <chaotian.jing@mediatek.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	<linux-mmc@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <srv_heupstream@mediatek.com>,
	yong mao <yong.mao@mediatek.com>
Subject: [PATCH 2/3] mmc: core: rocr verification
Date: Tue, 14 Apr 2020 11:40:10 +0800	[thread overview]
Message-ID: <1586835611-13857-3-git-send-email-yong.mao@mediatek.com> (raw)
In-Reply-To: <1586835611-13857-1-git-send-email-yong.mao@mediatek.com>

From: yong mao <yong.mao@mediatek.com>

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 <yong.mao@mediatek.com>
---
 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
-- 
1.9.1

  parent reply	other threads:[~2020-04-14  3:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14  3:40 Fix sdio reinit card fail issue Yong Mao
2020-04-14  3:40 ` [PATCH 1/3] mmc: core: need do mmc_power_cycle in mmc_sdio_resend_if_cond Yong Mao
2020-04-20 19:15   ` Matthias Kaehlcke
2020-04-21  7:03     ` yong.mao
2020-04-24 10:09   ` Ulf Hansson
2020-04-28  9:27     ` yong.mao
2020-04-28 12:13       ` Ulf Hansson
2020-04-29  8:20         ` yong.mao
2020-05-05 13:13           ` Ulf Hansson
2020-04-14  3:40 ` Yong Mao [this message]
2020-04-14  3:40 ` [PATCH 3/3] mmc: core: fix mmc_sdio_reinit_card fail issue Yong Mao
2020-04-22 22:46   ` Matthias Kaehlcke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1586835611-13857-3-git-send-email-yong.mao@mediatek.com \
    --to=yong.mao@mediatek.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=srv_heupstream@mediatek.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).