diff options
Diffstat (limited to 'drivers/mmc/host/sdhci.c')
-rw-r--r-- | drivers/mmc/host/sdhci.c | 80 |
1 files changed, 54 insertions, 26 deletions
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index cbb245b58538..f1a488ee432f 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
@@ -259,8 +259,6 @@ static void sdhci_reinit(struct sdhci_host *host) | |||
259 | 259 | ||
260 | del_timer_sync(&host->tuning_timer); | 260 | del_timer_sync(&host->tuning_timer); |
261 | host->flags &= ~SDHCI_NEEDS_RETUNING; | 261 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
262 | host->mmc->max_blk_count = | ||
263 | (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; | ||
264 | } | 262 | } |
265 | sdhci_enable_card_detection(host); | 263 | sdhci_enable_card_detection(host); |
266 | } | 264 | } |
@@ -1273,6 +1271,12 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned char mode, | |||
1273 | spin_unlock_irq(&host->lock); | 1271 | spin_unlock_irq(&host->lock); |
1274 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); | 1272 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); |
1275 | spin_lock_irq(&host->lock); | 1273 | spin_lock_irq(&host->lock); |
1274 | |||
1275 | if (mode != MMC_POWER_OFF) | ||
1276 | sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); | ||
1277 | else | ||
1278 | sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); | ||
1279 | |||
1276 | return; | 1280 | return; |
1277 | } | 1281 | } |
1278 | 1282 | ||
@@ -1353,6 +1357,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
1353 | 1357 | ||
1354 | sdhci_runtime_pm_get(host); | 1358 | sdhci_runtime_pm_get(host); |
1355 | 1359 | ||
1360 | present = mmc_gpio_get_cd(host->mmc); | ||
1361 | |||
1356 | spin_lock_irqsave(&host->lock, flags); | 1362 | spin_lock_irqsave(&host->lock, flags); |
1357 | 1363 | ||
1358 | WARN_ON(host->mrq != NULL); | 1364 | WARN_ON(host->mrq != NULL); |
@@ -1381,7 +1387,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
1381 | * zero: cd-gpio is used, and card is removed | 1387 | * zero: cd-gpio is used, and card is removed |
1382 | * one: cd-gpio is used, and card is present | 1388 | * one: cd-gpio is used, and card is present |
1383 | */ | 1389 | */ |
1384 | present = mmc_gpio_get_cd(host->mmc); | ||
1385 | if (present < 0) { | 1390 | if (present < 0) { |
1386 | /* If polling, assume that the card is always present. */ | 1391 | /* If polling, assume that the card is always present. */ |
1387 | if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) | 1392 | if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) |
@@ -1880,6 +1885,18 @@ static int sdhci_card_busy(struct mmc_host *mmc) | |||
1880 | return !(present_state & SDHCI_DATA_LVL_MASK); | 1885 | return !(present_state & SDHCI_DATA_LVL_MASK); |
1881 | } | 1886 | } |
1882 | 1887 | ||
1888 | static int sdhci_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios) | ||
1889 | { | ||
1890 | struct sdhci_host *host = mmc_priv(mmc); | ||
1891 | unsigned long flags; | ||
1892 | |||
1893 | spin_lock_irqsave(&host->lock, flags); | ||
1894 | host->flags |= SDHCI_HS400_TUNING; | ||
1895 | spin_unlock_irqrestore(&host->lock, flags); | ||
1896 | |||
1897 | return 0; | ||
1898 | } | ||
1899 | |||
1883 | static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) | 1900 | static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) |
1884 | { | 1901 | { |
1885 | struct sdhci_host *host = mmc_priv(mmc); | 1902 | struct sdhci_host *host = mmc_priv(mmc); |
@@ -1887,10 +1904,18 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) | |||
1887 | int tuning_loop_counter = MAX_TUNING_LOOP; | 1904 | int tuning_loop_counter = MAX_TUNING_LOOP; |
1888 | int err = 0; | 1905 | int err = 0; |
1889 | unsigned long flags; | 1906 | unsigned long flags; |
1907 | unsigned int tuning_count = 0; | ||
1908 | bool hs400_tuning; | ||
1890 | 1909 | ||
1891 | sdhci_runtime_pm_get(host); | 1910 | sdhci_runtime_pm_get(host); |
1892 | spin_lock_irqsave(&host->lock, flags); | 1911 | spin_lock_irqsave(&host->lock, flags); |
1893 | 1912 | ||
1913 | hs400_tuning = host->flags & SDHCI_HS400_TUNING; | ||
1914 | host->flags &= ~SDHCI_HS400_TUNING; | ||
1915 | |||
1916 | if (host->tuning_mode == SDHCI_TUNING_MODE_1) | ||
1917 | tuning_count = host->tuning_count; | ||
1918 | |||
1894 | /* | 1919 | /* |
1895 | * The Host Controller needs tuning only in case of SDR104 mode | 1920 | * The Host Controller needs tuning only in case of SDR104 mode |
1896 | * and for SDR50 mode when Use Tuning for SDR50 is set in the | 1921 | * and for SDR50 mode when Use Tuning for SDR50 is set in the |
@@ -1899,8 +1924,20 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) | |||
1899 | * tuning function has to be executed. | 1924 | * tuning function has to be executed. |
1900 | */ | 1925 | */ |
1901 | switch (host->timing) { | 1926 | switch (host->timing) { |
1927 | /* HS400 tuning is done in HS200 mode */ | ||
1902 | case MMC_TIMING_MMC_HS400: | 1928 | case MMC_TIMING_MMC_HS400: |
1929 | err = -EINVAL; | ||
1930 | goto out_unlock; | ||
1931 | |||
1903 | case MMC_TIMING_MMC_HS200: | 1932 | case MMC_TIMING_MMC_HS200: |
1933 | /* | ||
1934 | * Periodic re-tuning for HS400 is not expected to be needed, so | ||
1935 | * disable it here. | ||
1936 | */ | ||
1937 | if (hs400_tuning) | ||
1938 | tuning_count = 0; | ||
1939 | break; | ||
1940 | |||
1904 | case MMC_TIMING_UHS_SDR104: | 1941 | case MMC_TIMING_UHS_SDR104: |
1905 | break; | 1942 | break; |
1906 | 1943 | ||
@@ -1911,9 +1948,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) | |||
1911 | /* FALLTHROUGH */ | 1948 | /* FALLTHROUGH */ |
1912 | 1949 | ||
1913 | default: | 1950 | default: |
1914 | spin_unlock_irqrestore(&host->lock, flags); | 1951 | goto out_unlock; |
1915 | sdhci_runtime_pm_put(host); | ||
1916 | return 0; | ||
1917 | } | 1952 | } |
1918 | 1953 | ||
1919 | if (host->ops->platform_execute_tuning) { | 1954 | if (host->ops->platform_execute_tuning) { |
@@ -2037,24 +2072,11 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) | |||
2037 | } | 2072 | } |
2038 | 2073 | ||
2039 | out: | 2074 | out: |
2040 | /* | 2075 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
2041 | * If this is the very first time we are here, we start the retuning | 2076 | |
2042 | * timer. Since only during the first time, SDHCI_NEEDS_RETUNING | 2077 | if (tuning_count) { |
2043 | * flag won't be set, we check this condition before actually starting | ||
2044 | * the timer. | ||
2045 | */ | ||
2046 | if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && | ||
2047 | (host->tuning_mode == SDHCI_TUNING_MODE_1)) { | ||
2048 | host->flags |= SDHCI_USING_RETUNING_TIMER; | 2078 | host->flags |= SDHCI_USING_RETUNING_TIMER; |
2049 | mod_timer(&host->tuning_timer, jiffies + | 2079 | mod_timer(&host->tuning_timer, jiffies + tuning_count * HZ); |
2050 | host->tuning_count * HZ); | ||
2051 | /* Tuning mode 1 limits the maximum data length to 4MB */ | ||
2052 | mmc->max_blk_count = (4 * 1024 * 1024) / mmc->max_blk_size; | ||
2053 | } else if (host->flags & SDHCI_USING_RETUNING_TIMER) { | ||
2054 | host->flags &= ~SDHCI_NEEDS_RETUNING; | ||
2055 | /* Reload the new initial value for timer */ | ||
2056 | mod_timer(&host->tuning_timer, jiffies + | ||
2057 | host->tuning_count * HZ); | ||
2058 | } | 2080 | } |
2059 | 2081 | ||
2060 | /* | 2082 | /* |
@@ -2070,6 +2092,7 @@ out: | |||
2070 | 2092 | ||
2071 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); | 2093 | sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); |
2072 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); | 2094 | sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); |
2095 | out_unlock: | ||
2073 | spin_unlock_irqrestore(&host->lock, flags); | 2096 | spin_unlock_irqrestore(&host->lock, flags); |
2074 | sdhci_runtime_pm_put(host); | 2097 | sdhci_runtime_pm_put(host); |
2075 | 2098 | ||
@@ -2110,15 +2133,18 @@ static void sdhci_card_event(struct mmc_host *mmc) | |||
2110 | { | 2133 | { |
2111 | struct sdhci_host *host = mmc_priv(mmc); | 2134 | struct sdhci_host *host = mmc_priv(mmc); |
2112 | unsigned long flags; | 2135 | unsigned long flags; |
2136 | int present; | ||
2113 | 2137 | ||
2114 | /* First check if client has provided their own card event */ | 2138 | /* First check if client has provided their own card event */ |
2115 | if (host->ops->card_event) | 2139 | if (host->ops->card_event) |
2116 | host->ops->card_event(host); | 2140 | host->ops->card_event(host); |
2117 | 2141 | ||
2142 | present = sdhci_do_get_cd(host); | ||
2143 | |||
2118 | spin_lock_irqsave(&host->lock, flags); | 2144 | spin_lock_irqsave(&host->lock, flags); |
2119 | 2145 | ||
2120 | /* Check host->mrq first in case we are runtime suspended */ | 2146 | /* Check host->mrq first in case we are runtime suspended */ |
2121 | if (host->mrq && !sdhci_do_get_cd(host)) { | 2147 | if (host->mrq && !present) { |
2122 | pr_err("%s: Card removed during transfer!\n", | 2148 | pr_err("%s: Card removed during transfer!\n", |
2123 | mmc_hostname(host->mmc)); | 2149 | mmc_hostname(host->mmc)); |
2124 | pr_err("%s: Resetting controller.\n", | 2150 | pr_err("%s: Resetting controller.\n", |
@@ -2142,6 +2168,7 @@ static const struct mmc_host_ops sdhci_ops = { | |||
2142 | .hw_reset = sdhci_hw_reset, | 2168 | .hw_reset = sdhci_hw_reset, |
2143 | .enable_sdio_irq = sdhci_enable_sdio_irq, | 2169 | .enable_sdio_irq = sdhci_enable_sdio_irq, |
2144 | .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, | 2170 | .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, |
2171 | .prepare_hs400_tuning = sdhci_prepare_hs400_tuning, | ||
2145 | .execute_tuning = sdhci_execute_tuning, | 2172 | .execute_tuning = sdhci_execute_tuning, |
2146 | .card_event = sdhci_card_event, | 2173 | .card_event = sdhci_card_event, |
2147 | .card_busy = sdhci_card_busy, | 2174 | .card_busy = sdhci_card_busy, |
@@ -3260,8 +3287,9 @@ int sdhci_add_host(struct sdhci_host *host) | |||
3260 | mmc->max_segs = SDHCI_MAX_SEGS; | 3287 | mmc->max_segs = SDHCI_MAX_SEGS; |
3261 | 3288 | ||
3262 | /* | 3289 | /* |
3263 | * Maximum number of sectors in one transfer. Limited by DMA boundary | 3290 | * Maximum number of sectors in one transfer. Limited by SDMA boundary |
3264 | * size (512KiB). | 3291 | * size (512KiB). Note some tuning modes impose a 4MiB limit, but this |
3292 | * is less anyway. | ||
3265 | */ | 3293 | */ |
3266 | mmc->max_req_size = 524288; | 3294 | mmc->max_req_size = 524288; |
3267 | 3295 | ||