[PATCH 2/8] mci: core: check switch error for switch command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: LI Qingwu <Qing-wu.Li@xxxxxxxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxxxxxx>
[m.felsch@xxxxxxxxxxxxxx: align commit message and minor cleanups]
Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx>
---
 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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux