diff options
author | Pierre Ossman <drzeus@drzeus.cx> | 2006-06-18 08:34:37 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2006-09-07 08:18:40 -0400 |
commit | 385e3227d4d83ab13d7767c4bb3593b0256bf246 (patch) | |
tree | 91f532e07753c44a905116f5a7d0e3bdcfca7f0a | |
parent | f57b225e432d80ee46f48536cc55ea6cf62c5570 (diff) |
[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>
-rw-r--r-- | drivers/mmc/mmc.c | 15 | ||||
-rw-r--r-- | drivers/mmc/mmc_block.c | 44 |
2 files changed, 49 insertions, 10 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 33525bdf2ab6..c0c7ef2a8b28 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c | |||
@@ -912,6 +912,7 @@ static void mmc_read_scrs(struct mmc_host *host) | |||
912 | struct mmc_request mrq; | 912 | struct mmc_request mrq; |
913 | struct mmc_command cmd; | 913 | struct mmc_command cmd; |
914 | struct mmc_data data; | 914 | struct mmc_data data; |
915 | unsigned int timeout_us; | ||
915 | 916 | ||
916 | struct scatterlist sg; | 917 | struct scatterlist sg; |
917 | 918 | ||
@@ -947,8 +948,18 @@ static void mmc_read_scrs(struct mmc_host *host) | |||
947 | 948 | ||
948 | memset(&data, 0, sizeof(struct mmc_data)); | 949 | memset(&data, 0, sizeof(struct mmc_data)); |
949 | 950 | ||
950 | data.timeout_ns = card->csd.tacc_ns * 10; | 951 | data.timeout_ns = card->csd.tacc_ns * 100; |
951 | data.timeout_clks = card->csd.tacc_clks * 10; | 952 | data.timeout_clks = card->csd.tacc_clks * 100; |
953 | |||
954 | timeout_us = data.timeout_ns / 1000; | ||
955 | timeout_us += data.timeout_clks * 1000 / | ||
956 | (host->ios.clock / 1000); | ||
957 | |||
958 | if (timeout_us > 100000) { | ||
959 | data.timeout_ns = 100000000; | ||
960 | data.timeout_clks = 0; | ||
961 | } | ||
962 | |||
952 | data.blksz_bits = 3; | 963 | data.blksz_bits = 3; |
953 | data.blksz = 1 << 3; | 964 | data.blksz = 1 << 3; |
954 | data.blocks = 1; | 965 | data.blocks = 1; |
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c index 115cc21094b9..515fb227eba7 100644 --- a/drivers/mmc/mmc_block.c +++ b/drivers/mmc/mmc_block.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | 31 | ||
32 | #include <linux/mmc/card.h> | 32 | #include <linux/mmc/card.h> |
33 | #include <linux/mmc/host.h> | ||
33 | #include <linux/mmc/protocol.h> | 34 | #include <linux/mmc/protocol.h> |
34 | 35 | ||
35 | #include <asm/system.h> | 36 | #include <asm/system.h> |
@@ -171,8 +172,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
171 | 172 | ||
172 | brq.cmd.arg = req->sector << 9; | 173 | brq.cmd.arg = req->sector << 9; |
173 | brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; | 174 | brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
174 | brq.data.timeout_ns = card->csd.tacc_ns * 10; | ||
175 | brq.data.timeout_clks = card->csd.tacc_clks * 10; | ||
176 | brq.data.blksz_bits = md->block_bits; | 175 | brq.data.blksz_bits = md->block_bits; |
177 | brq.data.blksz = 1 << md->block_bits; | 176 | brq.data.blksz = 1 << md->block_bits; |
178 | brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); | 177 | 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) | |||
180 | brq.stop.arg = 0; | 179 | brq.stop.arg = 0; |
181 | brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC; | 180 | brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC; |
182 | 181 | ||
182 | brq.data.timeout_ns = card->csd.tacc_ns * 10; | ||
183 | brq.data.timeout_clks = card->csd.tacc_clks * 10; | ||
184 | |||
185 | /* | ||
186 | * Scale up the timeout by the r2w factor | ||
187 | */ | ||
188 | if (rq_data_dir(req) == WRITE) { | ||
189 | brq.data.timeout_ns <<= card->csd.r2w_factor; | ||
190 | brq.data.timeout_clks <<= card->csd.r2w_factor; | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * SD cards use a 100 multiplier and has a upper limit | ||
195 | */ | ||
196 | if (mmc_card_sd(card)) { | ||
197 | unsigned int limit_us, timeout_us; | ||
198 | |||
199 | brq.data.timeout_ns *= 10; | ||
200 | brq.data.timeout_clks *= 10; | ||
201 | |||
202 | if (rq_data_dir(req) == READ) | ||
203 | limit_us = 100000; | ||
204 | else | ||
205 | limit_us = 250000; | ||
206 | |||
207 | timeout_us = brq.data.timeout_ns / 1000; | ||
208 | timeout_us += brq.data.timeout_clks * 1000 / | ||
209 | (card->host->ios.clock / 1000); | ||
210 | |||
211 | if (timeout_us > limit_us) { | ||
212 | brq.data.timeout_ns = limit_us * 1000; | ||
213 | brq.data.timeout_clks = 0; | ||
214 | } | ||
215 | } | ||
216 | |||
183 | if (rq_data_dir(req) == READ) { | 217 | if (rq_data_dir(req) == READ) { |
184 | brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; | 218 | brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; |
185 | brq.data.flags |= MMC_DATA_READ; | 219 | brq.data.flags |= MMC_DATA_READ; |
@@ -187,12 +221,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
187 | brq.cmd.opcode = MMC_WRITE_BLOCK; | 221 | brq.cmd.opcode = MMC_WRITE_BLOCK; |
188 | brq.data.flags |= MMC_DATA_WRITE; | 222 | brq.data.flags |= MMC_DATA_WRITE; |
189 | brq.data.blocks = 1; | 223 | brq.data.blocks = 1; |
190 | |||
191 | /* | ||
192 | * Scale up the timeout by the r2w factor | ||
193 | */ | ||
194 | brq.data.timeout_ns <<= card->csd.r2w_factor; | ||
195 | brq.data.timeout_clks <<= card->csd.r2w_factor; | ||
196 | } | 224 | } |
197 | 225 | ||
198 | if (brq.data.blocks > 1) { | 226 | if (brq.data.blocks > 1) { |