aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/sdhci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/host/sdhci.c')
-rw-r--r--drivers/mmc/host/sdhci.c144
1 files changed, 88 insertions, 56 deletions
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index f4b8b4db3a9a..9a11dc39921c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/mmc/mmc.h> 28#include <linux/mmc/mmc.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/card.h>
30 31
31#include "sdhci.h" 32#include "sdhci.h"
32 33
@@ -244,6 +245,19 @@ static void sdhci_init(struct sdhci_host *host, int soft)
244static void sdhci_reinit(struct sdhci_host *host) 245static void sdhci_reinit(struct sdhci_host *host)
245{ 246{
246 sdhci_init(host, 0); 247 sdhci_init(host, 0);
248 /*
249 * Retuning stuffs are affected by different cards inserted and only
250 * applicable to UHS-I cards. So reset these fields to their initial
251 * value when card is removed.
252 */
253 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
254 host->flags &= ~SDHCI_USING_RETUNING_TIMER;
255
256 del_timer_sync(&host->tuning_timer);
257 host->flags &= ~SDHCI_NEEDS_RETUNING;
258 host->mmc->max_blk_count =
259 (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
260 }
247 sdhci_enable_card_detection(host); 261 sdhci_enable_card_detection(host);
248} 262}
249 263
@@ -1245,6 +1259,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1245 struct sdhci_host *host; 1259 struct sdhci_host *host;
1246 bool present; 1260 bool present;
1247 unsigned long flags; 1261 unsigned long flags;
1262 u32 tuning_opcode;
1248 1263
1249 host = mmc_priv(mmc); 1264 host = mmc_priv(mmc);
1250 1265
@@ -1292,8 +1307,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1292 */ 1307 */
1293 if ((host->flags & SDHCI_NEEDS_RETUNING) && 1308 if ((host->flags & SDHCI_NEEDS_RETUNING) &&
1294 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { 1309 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) {
1310 /* eMMC uses cmd21 while sd and sdio use cmd19 */
1311 tuning_opcode = mmc->card->type == MMC_TYPE_MMC ?
1312 MMC_SEND_TUNING_BLOCK_HS200 :
1313 MMC_SEND_TUNING_BLOCK;
1295 spin_unlock_irqrestore(&host->lock, flags); 1314 spin_unlock_irqrestore(&host->lock, flags);
1296 sdhci_execute_tuning(mmc, mrq->cmd->opcode); 1315 sdhci_execute_tuning(mmc, tuning_opcode);
1297 spin_lock_irqsave(&host->lock, flags); 1316 spin_lock_irqsave(&host->lock, flags);
1298 1317
1299 /* Restore original mmc_request structure */ 1318 /* Restore original mmc_request structure */
@@ -1663,11 +1682,15 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1663 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); 1682 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
1664 pwr &= ~SDHCI_POWER_ON; 1683 pwr &= ~SDHCI_POWER_ON;
1665 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1684 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1685 if (host->vmmc)
1686 regulator_disable(host->vmmc);
1666 1687
1667 /* Wait for 1ms as per the spec */ 1688 /* Wait for 1ms as per the spec */
1668 usleep_range(1000, 1500); 1689 usleep_range(1000, 1500);
1669 pwr |= SDHCI_POWER_ON; 1690 pwr |= SDHCI_POWER_ON;
1670 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1691 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1692 if (host->vmmc)
1693 regulator_enable(host->vmmc);
1671 1694
1672 pr_info(DRIVER_NAME ": Switching to 1.8V signalling " 1695 pr_info(DRIVER_NAME ": Switching to 1.8V signalling "
1673 "voltage failed, retrying with S18R set to 0\n"); 1696 "voltage failed, retrying with S18R set to 0\n");
@@ -1855,6 +1878,7 @@ out:
1855 */ 1878 */
1856 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && 1879 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
1857 (host->tuning_mode == SDHCI_TUNING_MODE_1)) { 1880 (host->tuning_mode == SDHCI_TUNING_MODE_1)) {
1881 host->flags |= SDHCI_USING_RETUNING_TIMER;
1858 mod_timer(&host->tuning_timer, jiffies + 1882 mod_timer(&host->tuning_timer, jiffies +
1859 host->tuning_count * HZ); 1883 host->tuning_count * HZ);
1860 /* Tuning mode 1 limits the maximum data length to 4MB */ 1884 /* Tuning mode 1 limits the maximum data length to 4MB */
@@ -1872,10 +1896,10 @@ out:
1872 * try tuning again at a later time, when the re-tuning timer expires. 1896 * try tuning again at a later time, when the re-tuning timer expires.
1873 * So for these controllers, we return 0. Since there might be other 1897 * So for these controllers, we return 0. Since there might be other
1874 * controllers who do not have this capability, we return error for 1898 * controllers who do not have this capability, we return error for
1875 * them. 1899 * them. SDHCI_USING_RETUNING_TIMER means the host is currently using
1900 * a retuning timer to do the retuning for the card.
1876 */ 1901 */
1877 if (err && host->tuning_count && 1902 if (err && (host->flags & SDHCI_USING_RETUNING_TIMER))
1878 host->tuning_mode == SDHCI_TUNING_MODE_1)
1879 err = 0; 1903 err = 0;
1880 1904
1881 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); 1905 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
@@ -2382,7 +2406,6 @@ out:
2382int sdhci_suspend_host(struct sdhci_host *host) 2406int sdhci_suspend_host(struct sdhci_host *host)
2383{ 2407{
2384 int ret; 2408 int ret;
2385 bool has_tuning_timer;
2386 2409
2387 if (host->ops->platform_suspend) 2410 if (host->ops->platform_suspend)
2388 host->ops->platform_suspend(host); 2411 host->ops->platform_suspend(host);
@@ -2390,16 +2413,14 @@ int sdhci_suspend_host(struct sdhci_host *host)
2390 sdhci_disable_card_detection(host); 2413 sdhci_disable_card_detection(host);
2391 2414
2392 /* Disable tuning since we are suspending */ 2415 /* Disable tuning since we are suspending */
2393 has_tuning_timer = host->version >= SDHCI_SPEC_300 && 2416 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2394 host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
2395 if (has_tuning_timer) {
2396 del_timer_sync(&host->tuning_timer); 2417 del_timer_sync(&host->tuning_timer);
2397 host->flags &= ~SDHCI_NEEDS_RETUNING; 2418 host->flags &= ~SDHCI_NEEDS_RETUNING;
2398 } 2419 }
2399 2420
2400 ret = mmc_suspend_host(host->mmc); 2421 ret = mmc_suspend_host(host->mmc);
2401 if (ret) { 2422 if (ret) {
2402 if (has_tuning_timer) { 2423 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2403 host->flags |= SDHCI_NEEDS_RETUNING; 2424 host->flags |= SDHCI_NEEDS_RETUNING;
2404 mod_timer(&host->tuning_timer, jiffies + 2425 mod_timer(&host->tuning_timer, jiffies +
2405 host->tuning_count * HZ); 2426 host->tuning_count * HZ);
@@ -2450,8 +2471,7 @@ int sdhci_resume_host(struct sdhci_host *host)
2450 host->ops->platform_resume(host); 2471 host->ops->platform_resume(host);
2451 2472
2452 /* Set the re-tuning expiration flag */ 2473 /* Set the re-tuning expiration flag */
2453 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2474 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2454 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2455 host->flags |= SDHCI_NEEDS_RETUNING; 2475 host->flags |= SDHCI_NEEDS_RETUNING;
2456 2476
2457 return ret; 2477 return ret;
@@ -2490,8 +2510,7 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
2490 int ret = 0; 2510 int ret = 0;
2491 2511
2492 /* Disable tuning since we are suspending */ 2512 /* Disable tuning since we are suspending */
2493 if (host->version >= SDHCI_SPEC_300 && 2513 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2494 host->tuning_mode == SDHCI_TUNING_MODE_1) {
2495 del_timer_sync(&host->tuning_timer); 2514 del_timer_sync(&host->tuning_timer);
2496 host->flags &= ~SDHCI_NEEDS_RETUNING; 2515 host->flags &= ~SDHCI_NEEDS_RETUNING;
2497 } 2516 }
@@ -2532,8 +2551,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2532 sdhci_do_enable_preset_value(host, true); 2551 sdhci_do_enable_preset_value(host, true);
2533 2552
2534 /* Set the re-tuning expiration flag */ 2553 /* Set the re-tuning expiration flag */
2535 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2554 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2536 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2537 host->flags |= SDHCI_NEEDS_RETUNING; 2555 host->flags |= SDHCI_NEEDS_RETUNING;
2538 2556
2539 spin_lock_irqsave(&host->lock, flags); 2557 spin_lock_irqsave(&host->lock, flags);
@@ -2584,7 +2602,7 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
2584int sdhci_add_host(struct sdhci_host *host) 2602int sdhci_add_host(struct sdhci_host *host)
2585{ 2603{
2586 struct mmc_host *mmc; 2604 struct mmc_host *mmc;
2587 u32 caps[2]; 2605 u32 caps[2] = {0, 0};
2588 u32 max_current_caps; 2606 u32 max_current_caps;
2589 unsigned int ocr_avail; 2607 unsigned int ocr_avail;
2590 int ret; 2608 int ret;
@@ -2614,8 +2632,10 @@ int sdhci_add_host(struct sdhci_host *host)
2614 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : 2632 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
2615 sdhci_readl(host, SDHCI_CAPABILITIES); 2633 sdhci_readl(host, SDHCI_CAPABILITIES);
2616 2634
2617 caps[1] = (host->version >= SDHCI_SPEC_300) ? 2635 if (host->version >= SDHCI_SPEC_300)
2618 sdhci_readl(host, SDHCI_CAPABILITIES_1) : 0; 2636 caps[1] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ?
2637 host->caps1 :
2638 sdhci_readl(host, SDHCI_CAPABILITIES_1);
2619 2639
2620 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 2640 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
2621 host->flags |= SDHCI_USE_SDMA; 2641 host->flags |= SDHCI_USE_SDMA;
@@ -2779,7 +2799,7 @@ int sdhci_add_host(struct sdhci_host *host)
2779 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 2799 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2780 2800
2781 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && 2801 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
2782 mmc_card_is_removable(mmc)) 2802 !(host->mmc->caps & MMC_CAP_NONREMOVABLE))
2783 mmc->caps |= MMC_CAP_NEEDS_POLL; 2803 mmc->caps |= MMC_CAP_NEEDS_POLL;
2784 2804
2785 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ 2805 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */
@@ -2837,6 +2857,30 @@ int sdhci_add_host(struct sdhci_host *host)
2837 SDHCI_RETUNING_MODE_SHIFT; 2857 SDHCI_RETUNING_MODE_SHIFT;
2838 2858
2839 ocr_avail = 0; 2859 ocr_avail = 0;
2860
2861 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2862 if (IS_ERR(host->vmmc)) {
2863 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
2864 host->vmmc = NULL;
2865 }
2866
2867#ifdef CONFIG_REGULATOR
2868 if (host->vmmc) {
2869 ret = regulator_is_supported_voltage(host->vmmc, 3300000,
2870 3300000);
2871 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330)))
2872 caps[0] &= ~SDHCI_CAN_VDD_330;
2873 ret = regulator_is_supported_voltage(host->vmmc, 3000000,
2874 3000000);
2875 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300)))
2876 caps[0] &= ~SDHCI_CAN_VDD_300;
2877 ret = regulator_is_supported_voltage(host->vmmc, 1800000,
2878 1800000);
2879 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180)))
2880 caps[0] &= ~SDHCI_CAN_VDD_180;
2881 }
2882#endif /* CONFIG_REGULATOR */
2883
2840 /* 2884 /*
2841 * According to SD Host Controller spec v3.00, if the Host System 2885 * According to SD Host Controller spec v3.00, if the Host System
2842 * can afford more than 150mA, Host Driver should set XPC to 1. Also 2886 * can afford more than 150mA, Host Driver should set XPC to 1. Also
@@ -2845,55 +2889,45 @@ int sdhci_add_host(struct sdhci_host *host)
2845 * value. 2889 * value.
2846 */ 2890 */
2847 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); 2891 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
2892 if (!max_current_caps && host->vmmc) {
2893 u32 curr = regulator_get_current_limit(host->vmmc);
2894 if (curr > 0) {
2895
2896 /* convert to SDHCI_MAX_CURRENT format */
2897 curr = curr/1000; /* convert to mA */
2898 curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER;
2899
2900 curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT);
2901 max_current_caps =
2902 (curr << SDHCI_MAX_CURRENT_330_SHIFT) |
2903 (curr << SDHCI_MAX_CURRENT_300_SHIFT) |
2904 (curr << SDHCI_MAX_CURRENT_180_SHIFT);
2905 }
2906 }
2848 2907
2849 if (caps[0] & SDHCI_CAN_VDD_330) { 2908 if (caps[0] & SDHCI_CAN_VDD_330) {
2850 int max_current_330;
2851
2852 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; 2909 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
2853 2910
2854 max_current_330 = ((max_current_caps & 2911 mmc->max_current_330 = ((max_current_caps &
2855 SDHCI_MAX_CURRENT_330_MASK) >> 2912 SDHCI_MAX_CURRENT_330_MASK) >>
2856 SDHCI_MAX_CURRENT_330_SHIFT) * 2913 SDHCI_MAX_CURRENT_330_SHIFT) *
2857 SDHCI_MAX_CURRENT_MULTIPLIER; 2914 SDHCI_MAX_CURRENT_MULTIPLIER;
2858
2859 if (max_current_330 > 150)
2860 mmc->caps |= MMC_CAP_SET_XPC_330;
2861 } 2915 }
2862 if (caps[0] & SDHCI_CAN_VDD_300) { 2916 if (caps[0] & SDHCI_CAN_VDD_300) {
2863 int max_current_300;
2864
2865 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; 2917 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
2866 2918
2867 max_current_300 = ((max_current_caps & 2919 mmc->max_current_300 = ((max_current_caps &
2868 SDHCI_MAX_CURRENT_300_MASK) >> 2920 SDHCI_MAX_CURRENT_300_MASK) >>
2869 SDHCI_MAX_CURRENT_300_SHIFT) * 2921 SDHCI_MAX_CURRENT_300_SHIFT) *
2870 SDHCI_MAX_CURRENT_MULTIPLIER; 2922 SDHCI_MAX_CURRENT_MULTIPLIER;
2871
2872 if (max_current_300 > 150)
2873 mmc->caps |= MMC_CAP_SET_XPC_300;
2874 } 2923 }
2875 if (caps[0] & SDHCI_CAN_VDD_180) { 2924 if (caps[0] & SDHCI_CAN_VDD_180) {
2876 int max_current_180;
2877
2878 ocr_avail |= MMC_VDD_165_195; 2925 ocr_avail |= MMC_VDD_165_195;
2879 2926
2880 max_current_180 = ((max_current_caps & 2927 mmc->max_current_180 = ((max_current_caps &
2881 SDHCI_MAX_CURRENT_180_MASK) >> 2928 SDHCI_MAX_CURRENT_180_MASK) >>
2882 SDHCI_MAX_CURRENT_180_SHIFT) * 2929 SDHCI_MAX_CURRENT_180_SHIFT) *
2883 SDHCI_MAX_CURRENT_MULTIPLIER; 2930 SDHCI_MAX_CURRENT_MULTIPLIER;
2884
2885 if (max_current_180 > 150)
2886 mmc->caps |= MMC_CAP_SET_XPC_180;
2887
2888 /* Maximum current capabilities of the host at 1.8V */
2889 if (max_current_180 >= 800)
2890 mmc->caps |= MMC_CAP_MAX_CURRENT_800;
2891 else if (max_current_180 >= 600)
2892 mmc->caps |= MMC_CAP_MAX_CURRENT_600;
2893 else if (max_current_180 >= 400)
2894 mmc->caps |= MMC_CAP_MAX_CURRENT_400;
2895 else
2896 mmc->caps |= MMC_CAP_MAX_CURRENT_200;
2897 } 2931 }
2898 2932
2899 mmc->ocr_avail = ocr_avail; 2933 mmc->ocr_avail = ocr_avail;
@@ -2992,13 +3026,10 @@ int sdhci_add_host(struct sdhci_host *host)
2992 3026
2993 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, 3027 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
2994 mmc_hostname(mmc), host); 3028 mmc_hostname(mmc), host);
2995 if (ret) 3029 if (ret) {
3030 pr_err("%s: Failed to request IRQ %d: %d\n",
3031 mmc_hostname(mmc), host->irq, ret);
2996 goto untasklet; 3032 goto untasklet;
2997
2998 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2999 if (IS_ERR(host->vmmc)) {
3000 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
3001 host->vmmc = NULL;
3002 } 3033 }
3003 3034
3004 sdhci_init(host, 0); 3035 sdhci_init(host, 0);
@@ -3016,8 +3047,11 @@ int sdhci_add_host(struct sdhci_host *host)
3016 host->led.brightness_set = sdhci_led_control; 3047 host->led.brightness_set = sdhci_led_control;
3017 3048
3018 ret = led_classdev_register(mmc_dev(mmc), &host->led); 3049 ret = led_classdev_register(mmc_dev(mmc), &host->led);
3019 if (ret) 3050 if (ret) {
3051 pr_err("%s: Failed to register LED device: %d\n",
3052 mmc_hostname(mmc), ret);
3020 goto reset; 3053 goto reset;
3054 }
3021#endif 3055#endif
3022 3056
3023 mmiowb(); 3057 mmiowb();
@@ -3081,8 +3115,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3081 free_irq(host->irq, host); 3115 free_irq(host->irq, host);
3082 3116
3083 del_timer_sync(&host->timer); 3117 del_timer_sync(&host->timer);
3084 if (host->version >= SDHCI_SPEC_300)
3085 del_timer_sync(&host->tuning_timer);
3086 3118
3087 tasklet_kill(&host->card_tasklet); 3119 tasklet_kill(&host->card_tasklet);
3088 tasklet_kill(&host->finish_tasklet); 3120 tasklet_kill(&host->finish_tasklet);