[PATCH] drivers/mci: fix read/write stalling
Robert Jarzmik
robert.jarzmik at free.fr
Mon Feb 27 17:45:28 EST 2012
If a read or write operation encounters an error, the card
might stay in "recv" or "data" state, and never get back to
"tran" state.
In these cases, the host is required to send a CMD12 (end
transmission) to switch the FSM of the card back to "tran"
state, as described in MMC Specification, chapter "Data
Transfer Mode".
Signed-off-by: Robert Jarzmik <robert.jarzmik at free.fr>
---
drivers/mci/mci-core.c | 31 ++++++++++---------------------
1 files changed, 10 insertions(+), 21 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 0bf4449..6432391 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -101,7 +101,7 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
static void *sector_buf;
/**
- * Write one block of data to the card
+ * Write one or several blocks of data to the card
* @param mci_dev MCI instance
* @param src Where to read from to write to the card
* @param blocknum Block number to write
@@ -140,23 +140,17 @@ static int mci_block_write(struct mci *mci, const void *src, int blocknum,
data.flags = MMC_DATA_WRITE;
ret = mci_send_cmd(mci, &cmd, &data);
- if (ret)
- return ret;
-
- if (blocks > 1) {
- mci_setup_cmd(&cmd,
- MMC_CMD_STOP_TRANSMISSION,
- 0, MMC_RSP_R1b);
- ret = mci_send_cmd(mci, &cmd, NULL);
- if (ret)
- return ret;
+
+ if (ret || blocks > 1) {
+ mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
+ mci_send_cmd(mci, &cmd, NULL);
}
return ret;
}
/**
- * Read one block of data from the card
+ * Read one or several block(s) of data from the card
* @param mci MCI instance
* @param dst Where to store the data read from the card
* @param blocknum Block number to read
@@ -186,15 +180,10 @@ static int mci_read_block(struct mci *mci, void *dst, int blocknum,
data.flags = MMC_DATA_READ;
ret = mci_send_cmd(mci, &cmd, &data);
- if (ret)
- return ret;
-
- if (blocks > 1) {
- mci_setup_cmd(&cmd,
- MMC_CMD_STOP_TRANSMISSION,
- 0,
- MMC_RSP_R1b);
- ret = mci_send_cmd(mci, &cmd, NULL);
+
+ if (ret || blocks > 1) {
+ mci_setup_cmd(&cmd, MMC_CMD_STOP_TRANSMISSION, 0, MMC_RSP_R1b);
+ mci_send_cmd(mci, &cmd, NULL);
}
return ret;
}
--
1.7.5.4
More information about the barebox
mailing list