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, 58 insertions, 86 deletions
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 47055f3f01b8..37b2a9ae52ef 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1223,8 +1223,16 @@ EXPORT_SYMBOL_GPL(sdhci_set_clock);
1223static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, 1223static void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
1224 unsigned short vdd) 1224 unsigned short vdd)
1225{ 1225{
1226 struct mmc_host *mmc = host->mmc;
1226 u8 pwr = 0; 1227 u8 pwr = 0;
1227 1228
1229 if (!IS_ERR(mmc->supply.vmmc)) {
1230 spin_unlock_irq(&host->lock);
1231 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd);
1232 spin_lock_irq(&host->lock);
1233 return;
1234 }
1235
1228 if (mode != MMC_POWER_OFF) { 1236 if (mode != MMC_POWER_OFF) {
1229 switch (1 << vdd) { 1237 switch (1 << vdd) {
1230 case MMC_VDD_165_195: 1238 case MMC_VDD_165_195:
@@ -1283,12 +1291,6 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
1283 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) 1291 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER)
1284 mdelay(10); 1292 mdelay(10);
1285 } 1293 }
1286
1287 if (host->vmmc) {
1288 spin_unlock_irq(&host->lock);
1289 mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd);
1290 spin_lock_irq(&host->lock);
1291 }
1292} 1294}
1293 1295
1294/*****************************************************************************\ 1296/*****************************************************************************\
@@ -1440,13 +1442,15 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1440{ 1442{
1441 unsigned long flags; 1443 unsigned long flags;
1442 u8 ctrl; 1444 u8 ctrl;
1445 struct mmc_host *mmc = host->mmc;
1443 1446
1444 spin_lock_irqsave(&host->lock, flags); 1447 spin_lock_irqsave(&host->lock, flags);
1445 1448
1446 if (host->flags & SDHCI_DEVICE_DEAD) { 1449 if (host->flags & SDHCI_DEVICE_DEAD) {
1447 spin_unlock_irqrestore(&host->lock, flags); 1450 spin_unlock_irqrestore(&host->lock, flags);
1448 if (host->vmmc && ios->power_mode == MMC_POWER_OFF) 1451 if (!IS_ERR(mmc->supply.vmmc) &&
1449 mmc_regulator_set_ocr(host->mmc, host->vmmc, 0); 1452 ios->power_mode == MMC_POWER_OFF)
1453 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
1450 return; 1454 return;
1451 } 1455 }
1452 1456
@@ -1530,7 +1534,6 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1530 host->ops->set_clock(host, host->clock); 1534 host->ops->set_clock(host, host->clock);
1531 } 1535 }
1532 1536
1533
1534 /* Reset SD Clock Enable */ 1537 /* Reset SD Clock Enable */
1535 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); 1538 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
1536 clk &= ~SDHCI_CLOCK_CARD_EN; 1539 clk &= ~SDHCI_CLOCK_CARD_EN;
@@ -1707,6 +1710,7 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1707static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, 1710static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1708 struct mmc_ios *ios) 1711 struct mmc_ios *ios)
1709{ 1712{
1713 struct mmc_host *mmc = host->mmc;
1710 u16 ctrl; 1714 u16 ctrl;
1711 int ret; 1715 int ret;
1712 1716
@@ -1725,11 +1729,12 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1725 ctrl &= ~SDHCI_CTRL_VDD_180; 1729 ctrl &= ~SDHCI_CTRL_VDD_180;
1726 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1730 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1727 1731
1728 if (host->vqmmc) { 1732 if (!IS_ERR(mmc->supply.vqmmc)) {
1729 ret = regulator_set_voltage(host->vqmmc, 2700000, 3600000); 1733 ret = regulator_set_voltage(mmc->supply.vqmmc, 2700000,
1734 3600000);
1730 if (ret) { 1735 if (ret) {
1731 pr_warning("%s: Switching to 3.3V signalling voltage " 1736 pr_warning("%s: Switching to 3.3V signalling voltage "
1732 " failed\n", mmc_hostname(host->mmc)); 1737 " failed\n", mmc_hostname(mmc));
1733 return -EIO; 1738 return -EIO;
1734 } 1739 }
1735 } 1740 }
@@ -1742,16 +1747,16 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1742 return 0; 1747 return 0;
1743 1748
1744 pr_warning("%s: 3.3V regulator output did not became stable\n", 1749 pr_warning("%s: 3.3V regulator output did not became stable\n",
1745 mmc_hostname(host->mmc)); 1750 mmc_hostname(mmc));
1746 1751
1747 return -EAGAIN; 1752 return -EAGAIN;
1748 case MMC_SIGNAL_VOLTAGE_180: 1753 case MMC_SIGNAL_VOLTAGE_180:
1749 if (host->vqmmc) { 1754 if (!IS_ERR(mmc->supply.vqmmc)) {
1750 ret = regulator_set_voltage(host->vqmmc, 1755 ret = regulator_set_voltage(mmc->supply.vqmmc,
1751 1700000, 1950000); 1756 1700000, 1950000);
1752 if (ret) { 1757 if (ret) {
1753 pr_warning("%s: Switching to 1.8V signalling voltage " 1758 pr_warning("%s: Switching to 1.8V signalling voltage "
1754 " failed\n", mmc_hostname(host->mmc)); 1759 " failed\n", mmc_hostname(mmc));
1755 return -EIO; 1760 return -EIO;
1756 } 1761 }
1757 } 1762 }
@@ -1763,24 +1768,22 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1763 ctrl |= SDHCI_CTRL_VDD_180; 1768 ctrl |= SDHCI_CTRL_VDD_180;
1764 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1769 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1765 1770
1766 /* Wait for 5ms */
1767 usleep_range(5000, 5500);
1768
1769 /* 1.8V regulator output should be stable within 5 ms */ 1771 /* 1.8V regulator output should be stable within 5 ms */
1770 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1772 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1771 if (ctrl & SDHCI_CTRL_VDD_180) 1773 if (ctrl & SDHCI_CTRL_VDD_180)
1772 return 0; 1774 return 0;
1773 1775
1774 pr_warning("%s: 1.8V regulator output did not became stable\n", 1776 pr_warning("%s: 1.8V regulator output did not became stable\n",
1775 mmc_hostname(host->mmc)); 1777 mmc_hostname(mmc));
1776 1778
1777 return -EAGAIN; 1779 return -EAGAIN;
1778 case MMC_SIGNAL_VOLTAGE_120: 1780 case MMC_SIGNAL_VOLTAGE_120:
1779 if (host->vqmmc) { 1781 if (!IS_ERR(mmc->supply.vqmmc)) {
1780 ret = regulator_set_voltage(host->vqmmc, 1100000, 1300000); 1782 ret = regulator_set_voltage(mmc->supply.vqmmc, 1100000,
1783 1300000);
1781 if (ret) { 1784 if (ret) {
1782 pr_warning("%s: Switching to 1.2V signalling voltage " 1785 pr_warning("%s: Switching to 1.2V signalling voltage "
1783 " failed\n", mmc_hostname(host->mmc)); 1786 " failed\n", mmc_hostname(mmc));
1784 return -EIO; 1787 return -EIO;
1785 } 1788 }
1786 } 1789 }
@@ -2643,7 +2646,6 @@ static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
2643int sdhci_runtime_suspend_host(struct sdhci_host *host) 2646int sdhci_runtime_suspend_host(struct sdhci_host *host)
2644{ 2647{
2645 unsigned long flags; 2648 unsigned long flags;
2646 int ret = 0;
2647 2649
2648 /* Disable tuning since we are suspending */ 2650 /* Disable tuning since we are suspending */
2649 if (host->flags & SDHCI_USING_RETUNING_TIMER) { 2651 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
@@ -2663,14 +2665,14 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
2663 host->runtime_suspended = true; 2665 host->runtime_suspended = true;
2664 spin_unlock_irqrestore(&host->lock, flags); 2666 spin_unlock_irqrestore(&host->lock, flags);
2665 2667
2666 return ret; 2668 return 0;
2667} 2669}
2668EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host); 2670EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host);
2669 2671
2670int sdhci_runtime_resume_host(struct sdhci_host *host) 2672int sdhci_runtime_resume_host(struct sdhci_host *host)
2671{ 2673{
2672 unsigned long flags; 2674 unsigned long flags;
2673 int ret = 0, host_flags = host->flags; 2675 int host_flags = host->flags;
2674 2676
2675 if (host_flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2677 if (host_flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2676 if (host->ops->enable_dma) 2678 if (host->ops->enable_dma)
@@ -2709,7 +2711,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2709 2711
2710 spin_unlock_irqrestore(&host->lock, flags); 2712 spin_unlock_irqrestore(&host->lock, flags);
2711 2713
2712 return ret; 2714 return 0;
2713} 2715}
2714EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host); 2716EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host);
2715 2717
@@ -2820,12 +2822,12 @@ int sdhci_add_host(struct sdhci_host *host)
2820 * (128) and potentially one alignment transfer for 2822 * (128) and potentially one alignment transfer for
2821 * each of those entries. 2823 * each of those entries.
2822 */ 2824 */
2823 host->adma_desc = dma_alloc_coherent(mmc_dev(host->mmc), 2825 host->adma_desc = dma_alloc_coherent(mmc_dev(mmc),
2824 ADMA_SIZE, &host->adma_addr, 2826 ADMA_SIZE, &host->adma_addr,
2825 GFP_KERNEL); 2827 GFP_KERNEL);
2826 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL); 2828 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL);
2827 if (!host->adma_desc || !host->align_buffer) { 2829 if (!host->adma_desc || !host->align_buffer) {
2828 dma_free_coherent(mmc_dev(host->mmc), ADMA_SIZE, 2830 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE,
2829 host->adma_desc, host->adma_addr); 2831 host->adma_desc, host->adma_addr);
2830 kfree(host->align_buffer); 2832 kfree(host->align_buffer);
2831 pr_warning("%s: Unable to allocate ADMA " 2833 pr_warning("%s: Unable to allocate ADMA "
@@ -2838,7 +2840,7 @@ int sdhci_add_host(struct sdhci_host *host)
2838 pr_warning("%s: unable to allocate aligned ADMA descriptor\n", 2840 pr_warning("%s: unable to allocate aligned ADMA descriptor\n",
2839 mmc_hostname(mmc)); 2841 mmc_hostname(mmc));
2840 host->flags &= ~SDHCI_USE_ADMA; 2842 host->flags &= ~SDHCI_USE_ADMA;
2841 dma_free_coherent(mmc_dev(host->mmc), ADMA_SIZE, 2843 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE,
2842 host->adma_desc, host->adma_addr); 2844 host->adma_desc, host->adma_addr);
2843 kfree(host->align_buffer); 2845 kfree(host->align_buffer);
2844 host->adma_desc = NULL; 2846 host->adma_desc = NULL;
@@ -2853,7 +2855,7 @@ int sdhci_add_host(struct sdhci_host *host)
2853 */ 2855 */
2854 if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) { 2856 if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) {
2855 host->dma_mask = DMA_BIT_MASK(64); 2857 host->dma_mask = DMA_BIT_MASK(64);
2856 mmc_dev(host->mmc)->dma_mask = &host->dma_mask; 2858 mmc_dev(mmc)->dma_mask = &host->dma_mask;
2857 } 2859 }
2858 2860
2859 if (host->version >= SDHCI_SPEC_300) 2861 if (host->version >= SDHCI_SPEC_300)
@@ -2959,28 +2961,25 @@ int sdhci_add_host(struct sdhci_host *host)
2959 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 2961 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2960 2962
2961 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && 2963 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
2962 !(host->mmc->caps & MMC_CAP_NONREMOVABLE)) 2964 !(mmc->caps & MMC_CAP_NONREMOVABLE))
2963 mmc->caps |= MMC_CAP_NEEDS_POLL; 2965 mmc->caps |= MMC_CAP_NEEDS_POLL;
2964 2966
2967 /* If there are external regulators, get them */
2968 if (mmc_regulator_get_supply(mmc) == -EPROBE_DEFER)
2969 return -EPROBE_DEFER;
2970
2965 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ 2971 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
2966 host->vqmmc = regulator_get_optional(mmc_dev(mmc), "vqmmc"); 2972 if (!IS_ERR(mmc->supply.vqmmc)) {
2967 if (IS_ERR_OR_NULL(host->vqmmc)) { 2973 ret = regulator_enable(mmc->supply.vqmmc);
2968 if (PTR_ERR(host->vqmmc) < 0) { 2974 if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 1700000,
2969 pr_info("%s: no vqmmc regulator found\n", 2975 1950000))
2970 mmc_hostname(mmc));
2971 host->vqmmc = NULL;
2972 }
2973 } else {
2974 ret = regulator_enable(host->vqmmc);
2975 if (!regulator_is_supported_voltage(host->vqmmc, 1700000,
2976 1950000))
2977 caps[1] &= ~(SDHCI_SUPPORT_SDR104 | 2976 caps[1] &= ~(SDHCI_SUPPORT_SDR104 |
2978 SDHCI_SUPPORT_SDR50 | 2977 SDHCI_SUPPORT_SDR50 |
2979 SDHCI_SUPPORT_DDR50); 2978 SDHCI_SUPPORT_DDR50);
2980 if (ret) { 2979 if (ret) {
2981 pr_warn("%s: Failed to enable vqmmc regulator: %d\n", 2980 pr_warn("%s: Failed to enable vqmmc regulator: %d\n",
2982 mmc_hostname(mmc), ret); 2981 mmc_hostname(mmc), ret);
2983 host->vqmmc = NULL; 2982 mmc->supply.vqmmc = NULL;
2984 } 2983 }
2985 } 2984 }
2986 2985
@@ -3041,34 +3040,6 @@ int sdhci_add_host(struct sdhci_host *host)
3041 3040
3042 ocr_avail = 0; 3041 ocr_avail = 0;
3043 3042
3044 host->vmmc = regulator_get_optional(mmc_dev(mmc), "vmmc");
3045 if (IS_ERR_OR_NULL(host->vmmc)) {
3046 if (PTR_ERR(host->vmmc) < 0) {
3047 pr_info("%s: no vmmc regulator found\n",
3048 mmc_hostname(mmc));
3049 host->vmmc = NULL;
3050 }
3051 }
3052
3053#ifdef CONFIG_REGULATOR
3054 /*
3055 * Voltage range check makes sense only if regulator reports
3056 * any voltage value.
3057 */
3058 if (host->vmmc && regulator_get_voltage(host->vmmc) > 0) {
3059 ret = regulator_is_supported_voltage(host->vmmc, 2700000,
3060 3600000);
3061 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330)))
3062 caps[0] &= ~SDHCI_CAN_VDD_330;
3063 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300)))
3064 caps[0] &= ~SDHCI_CAN_VDD_300;
3065 ret = regulator_is_supported_voltage(host->vmmc, 1700000,
3066 1950000);
3067 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180)))
3068 caps[0] &= ~SDHCI_CAN_VDD_180;
3069 }
3070#endif /* CONFIG_REGULATOR */
3071
3072 /* 3043 /*
3073 * According to SD Host Controller spec v3.00, if the Host System 3044 * According to SD Host Controller spec v3.00, if the Host System
3074 * can afford more than 150mA, Host Driver should set XPC to 1. Also 3045 * can afford more than 150mA, Host Driver should set XPC to 1. Also
@@ -3077,8 +3048,8 @@ int sdhci_add_host(struct sdhci_host *host)
3077 * value. 3048 * value.
3078 */ 3049 */
3079 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); 3050 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
3080 if (!max_current_caps && host->vmmc) { 3051 if (!max_current_caps && !IS_ERR(mmc->supply.vmmc)) {
3081 u32 curr = regulator_get_current_limit(host->vmmc); 3052 u32 curr = regulator_get_current_limit(mmc->supply.vmmc);
3082 if (curr > 0) { 3053 if (curr > 0) {
3083 3054
3084 /* convert to SDHCI_MAX_CURRENT format */ 3055 /* convert to SDHCI_MAX_CURRENT format */
@@ -3118,8 +3089,12 @@ int sdhci_add_host(struct sdhci_host *host)
3118 SDHCI_MAX_CURRENT_MULTIPLIER; 3089 SDHCI_MAX_CURRENT_MULTIPLIER;
3119 } 3090 }
3120 3091
3092 /* If OCR set by external regulators, use it instead */
3093 if (mmc->ocr_avail)
3094 ocr_avail = mmc->ocr_avail;
3095
3121 if (host->ocr_mask) 3096 if (host->ocr_mask)
3122 ocr_avail = host->ocr_mask; 3097 ocr_avail &= host->ocr_mask;
3123 3098
3124 mmc->ocr_avail = ocr_avail; 3099 mmc->ocr_avail = ocr_avail;
3125 mmc->ocr_avail_sdio = ocr_avail; 3100 mmc->ocr_avail_sdio = ocr_avail;
@@ -3273,6 +3248,7 @@ EXPORT_SYMBOL_GPL(sdhci_add_host);
3273 3248
3274void sdhci_remove_host(struct sdhci_host *host, int dead) 3249void sdhci_remove_host(struct sdhci_host *host, int dead)
3275{ 3250{
3251 struct mmc_host *mmc = host->mmc;
3276 unsigned long flags; 3252 unsigned long flags;
3277 3253
3278 if (dead) { 3254 if (dead) {
@@ -3282,7 +3258,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3282 3258
3283 if (host->mrq) { 3259 if (host->mrq) {
3284 pr_err("%s: Controller removed during " 3260 pr_err("%s: Controller removed during "
3285 " transfer!\n", mmc_hostname(host->mmc)); 3261 " transfer!\n", mmc_hostname(mmc));
3286 3262
3287 host->mrq->cmd->error = -ENOMEDIUM; 3263 host->mrq->cmd->error = -ENOMEDIUM;
3288 tasklet_schedule(&host->finish_tasklet); 3264 tasklet_schedule(&host->finish_tasklet);
@@ -3293,7 +3269,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3293 3269
3294 sdhci_disable_card_detection(host); 3270 sdhci_disable_card_detection(host);
3295 3271
3296 mmc_remove_host(host->mmc); 3272 mmc_remove_host(mmc);
3297 3273
3298#ifdef SDHCI_USE_LEDS_CLASS 3274#ifdef SDHCI_USE_LEDS_CLASS
3299 led_classdev_unregister(&host->led); 3275 led_classdev_unregister(&host->led);
@@ -3310,18 +3286,14 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3310 3286
3311 tasklet_kill(&host->finish_tasklet); 3287 tasklet_kill(&host->finish_tasklet);
3312 3288
3313 if (host->vmmc) { 3289 if (!IS_ERR(mmc->supply.vmmc))
3314 regulator_disable(host->vmmc); 3290 regulator_disable(mmc->supply.vmmc);
3315 regulator_put(host->vmmc);
3316 }
3317 3291
3318 if (host->vqmmc) { 3292 if (!IS_ERR(mmc->supply.vqmmc))
3319 regulator_disable(host->vqmmc); 3293 regulator_disable(mmc->supply.vqmmc);
3320 regulator_put(host->vqmmc);
3321 }
3322 3294
3323 if (host->adma_desc) 3295 if (host->adma_desc)
3324 dma_free_coherent(mmc_dev(host->mmc), ADMA_SIZE, 3296 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE,
3325 host->adma_desc, host->adma_addr); 3297 host->adma_desc, host->adma_addr);
3326 kfree(host->align_buffer); 3298 kfree(host->align_buffer);
3327 3299