diff options
-rw-r--r-- | drivers/mmc/core/sd.c | 69 | ||||
-rw-r--r-- | drivers/mmc/host/sdhci.c | 31 | ||||
-rw-r--r-- | include/linux/mmc/host.h | 10 |
3 files changed, 60 insertions, 50 deletions
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 8460568e5213..441bdf472c99 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 */ | ||
521 | static 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 | |||
520 | static int sd_set_current_limit(struct mmc_card *card, u8 *status) | 545 | static 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 = { | |||
677 | int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) | 712 | int 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 | ||
712 | try_again: | 751 | try_again: |
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index d9966568143b..9a11dc39921c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
@@ -2906,53 +2906,28 @@ int sdhci_add_host(struct sdhci_host *host) | |||
2906 | } | 2906 | } |
2907 | 2907 | ||
2908 | if (caps[0] & SDHCI_CAN_VDD_330) { | 2908 | if (caps[0] & SDHCI_CAN_VDD_330) { |
2909 | int max_current_330; | ||
2910 | |||
2911 | ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; | 2909 | ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; |
2912 | 2910 | ||
2913 | max_current_330 = ((max_current_caps & | 2911 | mmc->max_current_330 = ((max_current_caps & |
2914 | SDHCI_MAX_CURRENT_330_MASK) >> | 2912 | SDHCI_MAX_CURRENT_330_MASK) >> |
2915 | SDHCI_MAX_CURRENT_330_SHIFT) * | 2913 | SDHCI_MAX_CURRENT_330_SHIFT) * |
2916 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2914 | SDHCI_MAX_CURRENT_MULTIPLIER; |
2917 | |||
2918 | if (max_current_330 > 150) | ||
2919 | mmc->caps |= MMC_CAP_SET_XPC_330; | ||
2920 | } | 2915 | } |
2921 | if (caps[0] & SDHCI_CAN_VDD_300) { | 2916 | if (caps[0] & SDHCI_CAN_VDD_300) { |
2922 | int max_current_300; | ||
2923 | |||
2924 | ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; | 2917 | ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; |
2925 | 2918 | ||
2926 | max_current_300 = ((max_current_caps & | 2919 | mmc->max_current_300 = ((max_current_caps & |
2927 | SDHCI_MAX_CURRENT_300_MASK) >> | 2920 | SDHCI_MAX_CURRENT_300_MASK) >> |
2928 | SDHCI_MAX_CURRENT_300_SHIFT) * | 2921 | SDHCI_MAX_CURRENT_300_SHIFT) * |
2929 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2922 | SDHCI_MAX_CURRENT_MULTIPLIER; |
2930 | |||
2931 | if (max_current_300 > 150) | ||
2932 | mmc->caps |= MMC_CAP_SET_XPC_300; | ||
2933 | } | 2923 | } |
2934 | if (caps[0] & SDHCI_CAN_VDD_180) { | 2924 | if (caps[0] & SDHCI_CAN_VDD_180) { |
2935 | int max_current_180; | ||
2936 | |||
2937 | ocr_avail |= MMC_VDD_165_195; | 2925 | ocr_avail |= MMC_VDD_165_195; |
2938 | 2926 | ||
2939 | max_current_180 = ((max_current_caps & | 2927 | mmc->max_current_180 = ((max_current_caps & |
2940 | SDHCI_MAX_CURRENT_180_MASK) >> | 2928 | SDHCI_MAX_CURRENT_180_MASK) >> |
2941 | SDHCI_MAX_CURRENT_180_SHIFT) * | 2929 | SDHCI_MAX_CURRENT_180_SHIFT) * |
2942 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2930 | SDHCI_MAX_CURRENT_MULTIPLIER; |
2943 | |||
2944 | if (max_current_180 > 150) | ||
2945 | mmc->caps |= MMC_CAP_SET_XPC_180; | ||
2946 | |||
2947 | /* Maximum current capabilities of the host at 1.8V */ | ||
2948 | if (max_current_180 >= 800) | ||
2949 | mmc->caps |= MMC_CAP_MAX_CURRENT_800; | ||
2950 | else if (max_current_180 >= 600) | ||
2951 | mmc->caps |= MMC_CAP_MAX_CURRENT_600; | ||
2952 | else if (max_current_180 >= 400) | ||
2953 | mmc->caps |= MMC_CAP_MAX_CURRENT_400; | ||
2954 | else if (max_current_180 >= 200) | ||
2955 | mmc->caps |= MMC_CAP_MAX_CURRENT_200; | ||
2956 | } | 2931 | } |
2957 | 2932 | ||
2958 | mmc->ocr_avail = ocr_avail; | 2933 | mmc->ocr_avail = ocr_avail; |
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 65c64ee578a7..f578a71d82a6 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h | |||
@@ -189,6 +189,9 @@ struct mmc_host { | |||
189 | u32 ocr_avail_sd; /* SD-specific OCR */ | 189 | u32 ocr_avail_sd; /* SD-specific OCR */ |
190 | u32 ocr_avail_mmc; /* MMC-specific OCR */ | 190 | u32 ocr_avail_mmc; /* MMC-specific OCR */ |
191 | struct notifier_block pm_notify; | 191 | struct notifier_block pm_notify; |
192 | u32 max_current_330; | ||
193 | u32 max_current_300; | ||
194 | u32 max_current_180; | ||
192 | 195 | ||
193 | #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */ | 196 | #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */ |
194 | #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */ | 197 | #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */ |
@@ -232,16 +235,9 @@ struct mmc_host { | |||
232 | #define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */ | 235 | #define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */ |
233 | #define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */ | 236 | #define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */ |
234 | #define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */ | 237 | #define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */ |
235 | #define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA current at 3.3V */ | ||
236 | #define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA current at 3.0V */ | ||
237 | #define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA current at 1.8V */ | ||
238 | #define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */ | 238 | #define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */ |
239 | #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */ | 239 | #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */ |
240 | #define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */ | 240 | #define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */ |
241 | #define MMC_CAP_MAX_CURRENT_200 (1 << 26) /* Host max current limit is 200mA */ | ||
242 | #define MMC_CAP_MAX_CURRENT_400 (1 << 27) /* Host max current limit is 400mA */ | ||
243 | #define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */ | ||
244 | #define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */ | ||
245 | #define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */ | 241 | #define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */ |
246 | #define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */ | 242 | #define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */ |
247 | 243 | ||