aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
authorAaron Lu <aaron.lu@amd.com>2012-07-04 01:31:48 -0400
committerChris Ball <cjb@laptop.org>2012-07-22 15:25:52 -0400
commit55c4665ea0a42fd6427826bfce96eb4b0389262a (patch)
tree66d4bd77e16325ce64bc247c3dee107b5144af36 /drivers/mmc/core
parent94c18149451e9ae91a669bc33370273327d7da81 (diff)
mmc: sd: Fix sd current limit setting
Host has different current capabilities at different voltages, we need to record these settings seperately. The defined voltages are 1.8/3.0/3.3. For other voltages, we do not touch current limit setting. Before we set the current limit for the sd card, find out the host's operating voltage first and then find out the current capabilities of the host at that voltage to set the current limit. Signed-off-by: Aaron Lu <aaron.lu@amd.com> Reviewed-by: Philip Rakity <prakity@marvell.com> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/sd.c69
1 files changed, 54 insertions, 15 deletions
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 8460568e521..441bdf472c9 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -517,15 +517,54 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
517 return 0; 517 return 0;
518} 518}
519 519
520/* Get host's max current setting at its current voltage */
521static u32 sd_get_host_max_current(struct mmc_host *host)
522{
523 u32 voltage, max_current;
524
525 voltage = 1 << host->ios.vdd;
526 switch (voltage) {
527 case MMC_VDD_165_195:
528 max_current = host->max_current_180;
529 break;
530 case MMC_VDD_29_30:
531 case MMC_VDD_30_31:
532 max_current = host->max_current_300;
533 break;
534 case MMC_VDD_32_33:
535 case MMC_VDD_33_34:
536 max_current = host->max_current_330;
537 break;
538 default:
539 max_current = 0;
540 }
541
542 return max_current;
543}
544
520static int sd_set_current_limit(struct mmc_card *card, u8 *status) 545static int sd_set_current_limit(struct mmc_card *card, u8 *status)
521{ 546{
522 int current_limit = SD_SET_CURRENT_NO_CHANGE; 547 int current_limit = SD_SET_CURRENT_NO_CHANGE;
523 int err; 548 int err;
549 u32 max_current;
524 550
525 /* 551 /*
526 * Current limit switch is only defined for SDR50, SDR104, and DDR50 552 * Current limit switch is only defined for SDR50, SDR104, and DDR50
527 * bus speed modes. For other bus speed modes, we do not change the 553 * bus speed modes. For other bus speed modes, we do not change the
528 * current limit. 554 * current limit.
555 */
556 if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) &&
557 (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) &&
558 (card->sd_bus_speed != UHS_DDR50_BUS_SPEED))
559 return 0;
560
561 /*
562 * Host has different current capabilities when operating at
563 * different voltages, so find out its max current first.
564 */
565 max_current = sd_get_host_max_current(card->host);
566
567 /*
529 * We only check host's capability here, if we set a limit that is 568 * We only check host's capability here, if we set a limit that is
530 * higher than the card's maximum current, the card will be using its 569 * higher than the card's maximum current, the card will be using its
531 * maximum current, e.g. if the card's maximum current is 300ma, and 570 * maximum current, e.g. if the card's maximum current is 300ma, and
@@ -533,18 +572,14 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
533 * when we set current limit to 400/600/800ma, the card will draw its 572 * when we set current limit to 400/600/800ma, the card will draw its
534 * maximum 300ma from the host. 573 * maximum 300ma from the host.
535 */ 574 */
536 if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || 575 if (max_current >= 800)
537 (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || 576 current_limit = SD_SET_CURRENT_LIMIT_800;
538 (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { 577 else if (max_current >= 600)
539 if (card->host->caps & MMC_CAP_MAX_CURRENT_800) 578 current_limit = SD_SET_CURRENT_LIMIT_600;
540 current_limit = SD_SET_CURRENT_LIMIT_800; 579 else if (max_current >= 400)
541 else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) 580 current_limit = SD_SET_CURRENT_LIMIT_400;
542 current_limit = SD_SET_CURRENT_LIMIT_600; 581 else if (max_current >= 200)
543 else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) 582 current_limit = SD_SET_CURRENT_LIMIT_200;
544 current_limit = SD_SET_CURRENT_LIMIT_400;
545 else if (card->host->caps & MMC_CAP_MAX_CURRENT_200)
546 current_limit = SD_SET_CURRENT_LIMIT_200;
547 }
548 583
549 if (current_limit != SD_SET_CURRENT_NO_CHANGE) { 584 if (current_limit != SD_SET_CURRENT_NO_CHANGE) {
550 err = mmc_sd_switch(card, 1, 3, current_limit, status); 585 err = mmc_sd_switch(card, 1, 3, current_limit, status);
@@ -677,6 +712,7 @@ struct device_type sd_type = {
677int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) 712int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
678{ 713{
679 int err; 714 int err;
715 u32 max_current;
680 716
681 /* 717 /*
682 * Since we're changing the OCR value, we seem to 718 * Since we're changing the OCR value, we seem to
@@ -704,9 +740,12 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
704 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)) 740 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
705 ocr |= SD_OCR_S18R; 741 ocr |= SD_OCR_S18R;
706 742
707 /* If the host can supply more than 150mA, XPC should be set to 1. */ 743 /*
708 if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 | 744 * If the host can supply more than 150mA at current voltage,
709 MMC_CAP_SET_XPC_180)) 745 * XPC should be set to 1.
746 */
747 max_current = sd_get_host_max_current(host);
748 if (max_current > 150)
710 ocr |= SD_OCR_XPC; 749 ocr |= SD_OCR_XPC;
711 750
712try_again: 751try_again: