summaryrefslogtreecommitdiffstats
path: root/drivers/mmc/mmc_block.c
diff options
context:
space:
mode:
authorPierre Ossman <drzeus@drzeus.cx>2006-06-18 14:34:37 +0200
committerRussell King <rmk+kernel@arm.linux.org.uk>2006-09-07 13:18:40 +0100
commit385e3227d4d83ab13d7767c4bb3593b0256bf246 (patch)
tree91f532e07753c44a905116f5a7d0e3bdcfca7f0a /drivers/mmc/mmc_block.c
parentf57b225e432d80ee46f48536cc55ea6cf62c5570 (diff)
downloadop-kernel-dev-385e3227d4d83ab13d7767c4bb3593b0256bf246.zip
op-kernel-dev-385e3227d4d83ab13d7767c4bb3593b0256bf246.tar.gz
[MMC] Fix SD timeout calculation
Secure Digital cards use a different algorithm to calculate the timeout for data transfers. Using the MMC one works often, but not always. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/mmc/mmc_block.c')
-rw-r--r--drivers/mmc/mmc_block.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index 115cc21..515fb22 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -30,6 +30,7 @@
#include <linux/mutex.h>
#include <linux/mmc/card.h>
+#include <linux/mmc/host.h>
#include <linux/mmc/protocol.h>
#include <asm/system.h>
@@ -171,8 +172,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
brq.cmd.arg = req->sector << 9;
brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
- brq.data.timeout_ns = card->csd.tacc_ns * 10;
- brq.data.timeout_clks = card->csd.tacc_clks * 10;
brq.data.blksz_bits = md->block_bits;
brq.data.blksz = 1 << md->block_bits;
brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
@@ -180,6 +179,41 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
brq.stop.arg = 0;
brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
+ brq.data.timeout_ns = card->csd.tacc_ns * 10;
+ brq.data.timeout_clks = card->csd.tacc_clks * 10;
+
+ /*
+ * Scale up the timeout by the r2w factor
+ */
+ if (rq_data_dir(req) == WRITE) {
+ brq.data.timeout_ns <<= card->csd.r2w_factor;
+ brq.data.timeout_clks <<= card->csd.r2w_factor;
+ }
+
+ /*
+ * SD cards use a 100 multiplier and has a upper limit
+ */
+ if (mmc_card_sd(card)) {
+ unsigned int limit_us, timeout_us;
+
+ brq.data.timeout_ns *= 10;
+ brq.data.timeout_clks *= 10;
+
+ if (rq_data_dir(req) == READ)
+ limit_us = 100000;
+ else
+ limit_us = 250000;
+
+ timeout_us = brq.data.timeout_ns / 1000;
+ timeout_us += brq.data.timeout_clks * 1000 /
+ (card->host->ios.clock / 1000);
+
+ if (timeout_us > limit_us) {
+ brq.data.timeout_ns = limit_us * 1000;
+ brq.data.timeout_clks = 0;
+ }
+ }
+
if (rq_data_dir(req) == READ) {
brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK;
brq.data.flags |= MMC_DATA_READ;
@@ -187,12 +221,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
brq.cmd.opcode = MMC_WRITE_BLOCK;
brq.data.flags |= MMC_DATA_WRITE;
brq.data.blocks = 1;
-
- /*
- * Scale up the timeout by the r2w factor
- */
- brq.data.timeout_ns <<= card->csd.r2w_factor;
- brq.data.timeout_clks <<= card->csd.r2w_factor;
}
if (brq.data.blocks > 1) {
OpenPOWER on IntegriCloud