aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2007-01-04 09:57:32 -0500
committerPierre Ossman <drzeus@drzeus.cx>2007-02-04 14:54:07 -0500
commitfba68bd2dab1ac99af3c5a963ec9581cfa9f1725 (patch)
tree72c43ca8611ebef145e17862189609eb28ecb2d3 /drivers/mmc
parent9e9dc5f29f2eb65153a15c4fdb12b4382e3a75b2 (diff)
mmc: Add support for SDHC cards
Thanks to the generous donation of an SDHC card by John Gilmore, and the surprisingly enlightened decision by the SD Card Association to publish useful specs, I've been able to bash out support for SDHC. The changes are not too profound: i) Add a card flag indicating the card uses block level addressing and check it in the block driver. As we never took advantage of byte-level addressing, this simply involves skipping the block -> byte translation when sending commands. ii) The layout of the CSD is changed - a set of fields are discarded to make space for a larger C_SIZE. We did not reference any of the discarded fields except those related to the C_SIZE. iii) Read and write timeouts are fixed values and not calculated from CSD values. iv) Before invoking SEND_APP_OP_COND, we must invoke the new SEND_IF_COND to inform the card we support SDHC. Signed-off-by: Philipl Langdale <philipl@overt.org> Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/mmc.c140
-rw-r--r--drivers/mmc/mmc_block.c8
2 files changed, 119 insertions, 29 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
885static 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;