diff options
-rw-r--r-- | drivers/mmc/mmc.c | 140 | ||||
-rw-r--r-- | drivers/mmc/mmc_block.c | 8 | ||||
-rw-r--r-- | include/linux/mmc/card.h | 3 | ||||
-rw-r--r-- | include/linux/mmc/mmc.h | 1 | ||||
-rw-r--r-- | include/linux/mmc/protocol.h | 13 |
5 files changed, 135 insertions, 30 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 105f419d08cb..b48c277312de 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c | |||
@@ -289,7 +289,10 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card, | |||
289 | else | 289 | else |
290 | limit_us = 100000; | 290 | limit_us = 100000; |
291 | 291 | ||
292 | if (timeout_us > limit_us) { | 292 | /* |
293 | * SDHC cards always use these fixed values. | ||
294 | */ | ||
295 | if (timeout_us > limit_us || mmc_card_blockaddr(card)) { | ||
293 | data->timeout_ns = limit_us * 1000; | 296 | data->timeout_ns = limit_us * 1000; |
294 | data->timeout_clks = 0; | 297 | data->timeout_clks = 0; |
295 | } | 298 | } |
@@ -372,7 +375,7 @@ static inline void mmc_set_ios(struct mmc_host *host) | |||
372 | mmc_hostname(host), ios->clock, ios->bus_mode, | 375 | mmc_hostname(host), ios->clock, ios->bus_mode, |
373 | ios->power_mode, ios->chip_select, ios->vdd, | 376 | ios->power_mode, ios->chip_select, ios->vdd, |
374 | ios->bus_width); | 377 | ios->bus_width); |
375 | 378 | ||
376 | host->ops->set_ios(host, ios); | 379 | host->ops->set_ios(host, ios); |
377 | } | 380 | } |
378 | 381 | ||
@@ -588,34 +591,65 @@ static void mmc_decode_csd(struct mmc_card *card) | |||
588 | 591 | ||
589 | if (mmc_card_sd(card)) { | 592 | if (mmc_card_sd(card)) { |
590 | csd_struct = UNSTUFF_BITS(resp, 126, 2); | 593 | csd_struct = UNSTUFF_BITS(resp, 126, 2); |
591 | if (csd_struct != 0) { | 594 | |
595 | switch (csd_struct) { | ||
596 | case 0: | ||
597 | m = UNSTUFF_BITS(resp, 115, 4); | ||
598 | e = UNSTUFF_BITS(resp, 112, 3); | ||
599 | csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; | ||
600 | csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; | ||
601 | |||
602 | m = UNSTUFF_BITS(resp, 99, 4); | ||
603 | e = UNSTUFF_BITS(resp, 96, 3); | ||
604 | csd->max_dtr = tran_exp[e] * tran_mant[m]; | ||
605 | csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); | ||
606 | |||
607 | e = UNSTUFF_BITS(resp, 47, 3); | ||
608 | m = UNSTUFF_BITS(resp, 62, 12); | ||
609 | csd->capacity = (1 + m) << (e + 2); | ||
610 | |||
611 | csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); | ||
612 | csd->read_partial = UNSTUFF_BITS(resp, 79, 1); | ||
613 | csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); | ||
614 | csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); | ||
615 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); | ||
616 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); | ||
617 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); | ||
618 | break; | ||
619 | case 1: | ||
620 | /* | ||
621 | * This is a block-addressed SDHC card. Most | ||
622 | * interesting fields are unused and have fixed | ||
623 | * values. To avoid getting tripped by buggy cards, | ||
624 | * we assume those fixed values ourselves. | ||
625 | */ | ||
626 | mmc_card_set_blockaddr(card); | ||
627 | |||
628 | csd->tacc_ns = 0; /* Unused */ | ||
629 | csd->tacc_clks = 0; /* Unused */ | ||
630 | |||
631 | m = UNSTUFF_BITS(resp, 99, 4); | ||
632 | e = UNSTUFF_BITS(resp, 96, 3); | ||
633 | csd->max_dtr = tran_exp[e] * tran_mant[m]; | ||
634 | csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); | ||
635 | |||
636 | m = UNSTUFF_BITS(resp, 48, 22); | ||
637 | csd->capacity = (1 + m) << 10; | ||
638 | |||
639 | csd->read_blkbits = 9; | ||
640 | csd->read_partial = 0; | ||
641 | csd->write_misalign = 0; | ||
642 | csd->read_misalign = 0; | ||
643 | csd->r2w_factor = 4; /* Unused */ | ||
644 | csd->write_blkbits = 9; | ||
645 | csd->write_partial = 0; | ||
646 | break; | ||
647 | default: | ||
592 | printk("%s: unrecognised CSD structure version %d\n", | 648 | printk("%s: unrecognised CSD structure version %d\n", |
593 | mmc_hostname(card->host), csd_struct); | 649 | mmc_hostname(card->host), csd_struct); |
594 | mmc_card_set_bad(card); | 650 | mmc_card_set_bad(card); |
595 | return; | 651 | return; |
596 | } | 652 | } |
597 | |||
598 | m = UNSTUFF_BITS(resp, 115, 4); | ||
599 | e = UNSTUFF_BITS(resp, 112, 3); | ||
600 | csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; | ||
601 | csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; | ||
602 | |||
603 | m = UNSTUFF_BITS(resp, 99, 4); | ||
604 | e = UNSTUFF_BITS(resp, 96, 3); | ||
605 | csd->max_dtr = tran_exp[e] * tran_mant[m]; | ||
606 | csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); | ||
607 | |||
608 | e = UNSTUFF_BITS(resp, 47, 3); | ||
609 | m = UNSTUFF_BITS(resp, 62, 12); | ||
610 | csd->capacity = (1 + m) << (e + 2); | ||
611 | |||
612 | csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); | ||
613 | csd->read_partial = UNSTUFF_BITS(resp, 79, 1); | ||
614 | csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); | ||
615 | csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); | ||
616 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); | ||
617 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); | ||
618 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); | ||
619 | } else { | 653 | } else { |
620 | /* | 654 | /* |
621 | * We only understand CSD structure v1.1 and v1.2. | 655 | * We only understand CSD structure v1.1 and v1.2. |
@@ -848,6 +882,41 @@ static int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) | |||
848 | return err; | 882 | return err; |
849 | } | 883 | } |
850 | 884 | ||
885 | static int mmc_send_if_cond(struct mmc_host *host, u32 ocr, int *rsd2) | ||
886 | { | ||
887 | struct mmc_command cmd; | ||
888 | int err, sd2; | ||
889 | static const u8 test_pattern = 0xAA; | ||
890 | |||
891 | /* | ||
892 | * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND | ||
893 | * before SD_APP_OP_COND. This command will harmlessly fail for | ||
894 | * SD 1.0 cards. | ||
895 | */ | ||
896 | cmd.opcode = SD_SEND_IF_COND; | ||
897 | cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern; | ||
898 | cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR; | ||
899 | |||
900 | err = mmc_wait_for_cmd(host, &cmd, 0); | ||
901 | if (err == MMC_ERR_NONE) { | ||
902 | if ((cmd.resp[0] & 0xFF) == test_pattern) { | ||
903 | sd2 = 1; | ||
904 | } else { | ||
905 | sd2 = 0; | ||
906 | err = MMC_ERR_FAILED; | ||
907 | } | ||
908 | } else { | ||
909 | /* | ||
910 | * Treat errors as SD 1.0 card. | ||
911 | */ | ||
912 | sd2 = 0; | ||
913 | err = MMC_ERR_NONE; | ||
914 | } | ||
915 | if (rsd2) | ||
916 | *rsd2 = sd2; | ||
917 | return err; | ||
918 | } | ||
919 | |||
851 | /* | 920 | /* |
852 | * Discover cards by requesting their CID. If this command | 921 | * Discover cards by requesting their CID. If this command |
853 | * times out, it is not an error; there are no further cards | 922 | * times out, it is not an error; there are no further cards |
@@ -1334,6 +1403,10 @@ static void mmc_setup(struct mmc_host *host) | |||
1334 | mmc_power_up(host); | 1403 | mmc_power_up(host); |
1335 | mmc_idle_cards(host); | 1404 | mmc_idle_cards(host); |
1336 | 1405 | ||
1406 | err = mmc_send_if_cond(host, host->ocr_avail, NULL); | ||
1407 | if (err != MMC_ERR_NONE) { | ||
1408 | return; | ||
1409 | } | ||
1337 | err = mmc_send_app_op_cond(host, 0, &ocr); | 1410 | err = mmc_send_app_op_cond(host, 0, &ocr); |
1338 | 1411 | ||
1339 | /* | 1412 | /* |
@@ -1386,10 +1459,21 @@ static void mmc_setup(struct mmc_host *host) | |||
1386 | * all get the idea that they should be ready for CMD2. | 1459 | * all get the idea that they should be ready for CMD2. |
1387 | * (My SanDisk card seems to need this.) | 1460 | * (My SanDisk card seems to need this.) |
1388 | */ | 1461 | */ |
1389 | if (host->mode == MMC_MODE_SD) | 1462 | if (host->mode == MMC_MODE_SD) { |
1390 | mmc_send_app_op_cond(host, host->ocr, NULL); | 1463 | int err, sd2; |
1391 | else | 1464 | err = mmc_send_if_cond(host, host->ocr, &sd2); |
1465 | if (err == MMC_ERR_NONE) { | ||
1466 | /* | ||
1467 | * If SD_SEND_IF_COND indicates an SD 2.0 | ||
1468 | * compliant card and we should set bit 30 | ||
1469 | * of the ocr to indicate that we can handle | ||
1470 | * block-addressed SDHC cards. | ||
1471 | */ | ||
1472 | mmc_send_app_op_cond(host, host->ocr | (sd2 << 30), NULL); | ||
1473 | } | ||
1474 | } else { | ||
1392 | mmc_send_op_cond(host, host->ocr, NULL); | 1475 | mmc_send_op_cond(host, host->ocr, NULL); |
1476 | } | ||
1393 | 1477 | ||
1394 | mmc_discover_cards(host); | 1478 | mmc_discover_cards(host); |
1395 | 1479 | ||
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c index 87713572293f..5a4eacac0bbe 100644 --- a/drivers/mmc/mmc_block.c +++ b/drivers/mmc/mmc_block.c | |||
@@ -237,7 +237,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
237 | brq.mrq.cmd = &brq.cmd; | 237 | brq.mrq.cmd = &brq.cmd; |
238 | brq.mrq.data = &brq.data; | 238 | brq.mrq.data = &brq.data; |
239 | 239 | ||
240 | brq.cmd.arg = req->sector << 9; | 240 | brq.cmd.arg = req->sector; |
241 | if (!mmc_card_blockaddr(card)) | ||
242 | brq.cmd.arg <<= 9; | ||
241 | brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; | 243 | brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
242 | brq.data.blksz = 1 << md->block_bits; | 244 | brq.data.blksz = 1 << md->block_bits; |
243 | brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); | 245 | brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); |
@@ -494,6 +496,10 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card) | |||
494 | struct mmc_command cmd; | 496 | struct mmc_command cmd; |
495 | int err; | 497 | int err; |
496 | 498 | ||
499 | /* Block-addressed cards ignore MMC_SET_BLOCKLEN. */ | ||
500 | if (mmc_card_blockaddr(card)) | ||
501 | return 0; | ||
502 | |||
497 | mmc_card_claim_host(card); | 503 | mmc_card_claim_host(card); |
498 | cmd.opcode = MMC_SET_BLOCKLEN; | 504 | cmd.opcode = MMC_SET_BLOCKLEN; |
499 | cmd.arg = 1 << md->block_bits; | 505 | cmd.arg = 1 << md->block_bits; |
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index d0e6a5497614..e45712acfac5 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h | |||
@@ -71,6 +71,7 @@ struct mmc_card { | |||
71 | #define MMC_STATE_SDCARD (1<<3) /* is an SD card */ | 71 | #define MMC_STATE_SDCARD (1<<3) /* is an SD card */ |
72 | #define MMC_STATE_READONLY (1<<4) /* card is read-only */ | 72 | #define MMC_STATE_READONLY (1<<4) /* card is read-only */ |
73 | #define MMC_STATE_HIGHSPEED (1<<5) /* card is in high speed mode */ | 73 | #define MMC_STATE_HIGHSPEED (1<<5) /* card is in high speed mode */ |
74 | #define MMC_STATE_BLOCKADDR (1<<6) /* card uses block-addressing */ | ||
74 | u32 raw_cid[4]; /* raw card CID */ | 75 | u32 raw_cid[4]; /* raw card CID */ |
75 | u32 raw_csd[4]; /* raw card CSD */ | 76 | u32 raw_csd[4]; /* raw card CSD */ |
76 | u32 raw_scr[2]; /* raw card SCR */ | 77 | u32 raw_scr[2]; /* raw card SCR */ |
@@ -87,6 +88,7 @@ struct mmc_card { | |||
87 | #define mmc_card_sd(c) ((c)->state & MMC_STATE_SDCARD) | 88 | #define mmc_card_sd(c) ((c)->state & MMC_STATE_SDCARD) |
88 | #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) | 89 | #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) |
89 | #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) | 90 | #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) |
91 | #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) | ||
90 | 92 | ||
91 | #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) | 93 | #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) |
92 | #define mmc_card_set_dead(c) ((c)->state |= MMC_STATE_DEAD) | 94 | #define mmc_card_set_dead(c) ((c)->state |= MMC_STATE_DEAD) |
@@ -94,6 +96,7 @@ struct mmc_card { | |||
94 | #define mmc_card_set_sd(c) ((c)->state |= MMC_STATE_SDCARD) | 96 | #define mmc_card_set_sd(c) ((c)->state |= MMC_STATE_SDCARD) |
95 | #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) | 97 | #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) |
96 | #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) | 98 | #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) |
99 | #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) | ||
97 | 100 | ||
98 | #define mmc_card_name(c) ((c)->cid.prod_name) | 101 | #define mmc_card_name(c) ((c)->cid.prod_name) |
99 | #define mmc_card_id(c) ((c)->dev.bus_id) | 102 | #define mmc_card_id(c) ((c)->dev.bus_id) |
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index bcf24909d677..cdc54be804f1 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h | |||
@@ -43,6 +43,7 @@ struct mmc_command { | |||
43 | #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC) | 43 | #define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC) |
44 | #define MMC_RSP_R3 (MMC_RSP_PRESENT) | 44 | #define MMC_RSP_R3 (MMC_RSP_PRESENT) |
45 | #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) | 45 | #define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) |
46 | #define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) | ||
46 | 47 | ||
47 | #define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE)) | 48 | #define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE)) |
48 | 49 | ||
diff --git a/include/linux/mmc/protocol.h b/include/linux/mmc/protocol.h index 2dce60c43f4b..c90b6768329d 100644 --- a/include/linux/mmc/protocol.h +++ b/include/linux/mmc/protocol.h | |||
@@ -79,9 +79,12 @@ | |||
79 | #define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */ | 79 | #define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */ |
80 | 80 | ||
81 | /* SD commands type argument response */ | 81 | /* SD commands type argument response */ |
82 | /* class 8 */ | 82 | /* class 0 */ |
83 | /* This is basically the same command as for MMC with some quirks. */ | 83 | /* This is basically the same command as for MMC with some quirks. */ |
84 | #define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ | 84 | #define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ |
85 | #define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ | ||
86 | |||
87 | /* class 10 */ | ||
85 | #define SD_SWITCH 6 /* adtc [31:0] See below R1 */ | 88 | #define SD_SWITCH 6 /* adtc [31:0] See below R1 */ |
86 | 89 | ||
87 | /* Application commands */ | 90 | /* Application commands */ |
@@ -115,6 +118,14 @@ | |||
115 | */ | 118 | */ |
116 | 119 | ||
117 | /* | 120 | /* |
121 | * SD_SEND_IF_COND argument format: | ||
122 | * | ||
123 | * [31:12] Reserved (0) | ||
124 | * [11:8] Host Voltage Supply Flags | ||
125 | * [7:0] Check Pattern (0xAA) | ||
126 | */ | ||
127 | |||
128 | /* | ||
118 | MMC status in R1 | 129 | MMC status in R1 |
119 | Type | 130 | Type |
120 | e : error bit | 131 | e : error bit |