mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/8] mci: core: check switch error for switch command
Date: Tue, 14 Nov 2023 14:30:01 +0100	[thread overview]
Message-ID: <20231114133007.3662931-2-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20231114133007.3662931-1-m.felsch@pengutronix.de>

From: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>

check whether SWITCH_ERROR is set, if set the device did not switch to
the expected mode as requested by the SWITCH command.

Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
[m.felsch@pengutronix.de: align commit message and minor cleanups]
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/mci/mci-core.c | 15 ++++++++++++++-
 include/mci.h          |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index bc049c80298b..1276920e1604 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -494,7 +494,9 @@ int mci_send_ext_csd(struct mci *mci, char *ext_csd)
  */
 int mci_switch(struct mci *mci, unsigned index, unsigned value)
 {
+	unsigned int status;
 	struct mci_cmd cmd;
+	int ret;
 
 	mci_setup_cmd(&cmd, MMC_CMD_SWITCH,
 		(MMC_SWITCH_MODE_WRITE_BYTE << 24) |
@@ -502,7 +504,18 @@ int mci_switch(struct mci *mci, unsigned index, unsigned value)
 		(value << 8),
 		 MMC_RSP_R1b);
 
-	return mci_send_cmd(mci, &cmd, NULL);
+	ret = mci_send_cmd(mci, &cmd, NULL);
+	if (ret)
+		return ret;
+
+	ret = mci_send_status(mci, &status);
+	if (ret)
+		return ret;
+
+	if (status & R1_SWITCH_ERROR)
+		return -EIO;
+
+	return 0;
 }
 
 static blkcnt_t mci_calc_blk_cnt(blkcnt_t cap, unsigned shift)
diff --git a/include/mci.h b/include/mci.h
index 616c7c3cae5c..f38384613728 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -319,6 +319,7 @@
 #define R1_STATUS(x)			(x & 0xFFF9A000)
 #define R1_CURRENT_STATE(x)		((x & 0x00001E00) >> 9)	/* sx, b (4 bits) */
 #define R1_READY_FOR_DATA 		(1 << 8)		/* sx, a */
+#define R1_SWITCH_ERROR			(1 << 7)
 #define R1_APP_CMD			(1 << 5)
 
 #define R1_STATUS_MASK			(~0x0206BF7F)
-- 
2.39.2




  reply	other threads:[~2023-11-14 13:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 13:30 [PATCH 1/8] mci: correct ENH_ATTRIBUTE_EN_MASK bit mask Marco Felsch
2023-11-14 13:30 ` Marco Felsch [this message]
2023-11-14 13:30 ` [PATCH 3/8] commands: mmc: add write_reliability subcommand Marco Felsch
2023-11-14 13:30 ` [PATCH 4/8] commands: mmc: add partition_complete subcommand Marco Felsch
2023-11-14 13:30 ` [PATCH 5/8] commands: mmc: deprecate -c option Marco Felsch
2023-11-14 13:30 ` [PATCH 6/8] mci: export mci_get_ext_csd as helper Marco Felsch
2023-11-14 13:30 ` [PATCH 7/8] mci: core: cosmetic cleanup mci_register Marco Felsch
2023-11-14 13:30 ` [PATCH 8/8] mci: core: add partitioning_completed device parameter Marco Felsch
2023-11-15 13:05 ` [PATCH 1/8] mci: correct ENH_ATTRIBUTE_EN_MASK bit mask Sascha Hauer

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=20231114133007.3662931-2-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.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