aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/sdhci.c
diff options
context:
space:
mode:
authorArindam Nath <arindam.nath@amd.com>2011-05-05 02:48:57 -0400
committerChris Ball <cjb@laptop.org>2011-05-24 21:04:38 -0400
commitf2119df6b764609af4baceb68caf1e848c1c8aa7 (patch)
tree3c234b150d7add419cd07e15929b94b8c3baec63 /drivers/mmc/host/sdhci.c
parentcb87ea28ed9e75a41eb456bfcb547b4e6f10e750 (diff)
mmc: sd: add support for signal voltage switch procedure
Host Controller v3.00 adds another Capabilities register. Apart from other things, this new register indicates whether the Host Controller supports SDR50, SDR104, and DDR50 UHS-I modes. The spec doesn't mention about explicit support for SDR12 and SDR25 UHS-I modes, so the Host Controller v3.00 should support them by default. Also if the controller supports SDR104 mode, it will also support SDR50 mode as well. So depending on the host support, we set the corresponding MMC_CAP_* flags. One more new register. Host Control2 is added in v3.00, which is used during Signal Voltage Switch procedure described below. Since as per v3.00 spec, UHS-I supported hosts should set S18R to 1, we set S18R (bit 24) of OCR before sending ACMD41. We also need to set XPC (bit 28) of OCR in case the host can supply >150mA. This support is indicated by the Maximum Current Capabilities register of the Host Controller. If the response of ACMD41 has both CCS and S18A set, we start the signal voltage switch procedure, which if successfull, will switch the card from 3.3V signalling to 1.8V signalling. Signal voltage switch procedure adds support for a new command CMD11 in the Physical Layer Spec v3.01. As part of this procedure, we need to set 1.8V Signalling Enable (bit 3) of Host Control2 register, which if remains set after 5ms, means the switch to 1.8V signalling is successfull. Otherwise, we clear bit 24 of OCR and retry the initialization sequence. When we remove the card, and insert the same or another card, we need to make sure that we start with 3.3V signalling voltage. So we call mmc_set_signal_voltage() with MMC_SIGNAL_VOLTAGE_330 set so that we are back to 3.3V signalling voltage before we actually start initializing the card. Tested by Zhangfei Gao with a Toshiba uhs card and general hs card, on mmp2 in SDMA mode. Signed-off-by: Arindam Nath <arindam.nath@amd.com> Reviewed-by: Philip Rakity <prakity@marvell.com> Tested-by: Philip Rakity <prakity@marvell.com> Acked-by: Zhangfei Gao <zhangfei.gao@marvell.com> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/host/sdhci.c')
-rw-r--r--drivers/mmc/host/sdhci.c192
1 files changed, 179 insertions, 13 deletions
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index e5cfe70dc23b..4e2031449a23 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -83,6 +83,8 @@ static void sdhci_dumpregs(struct sdhci_host *host)
83 printk(KERN_DEBUG DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n", 83 printk(KERN_DEBUG DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n",
84 sdhci_readw(host, SDHCI_COMMAND), 84 sdhci_readw(host, SDHCI_COMMAND),
85 sdhci_readl(host, SDHCI_MAX_CURRENT)); 85 sdhci_readl(host, SDHCI_MAX_CURRENT));
86 printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n",
87 sdhci_readw(host, SDHCI_HOST_CONTROL2));
86 88
87 if (host->flags & SDHCI_USE_ADMA) 89 if (host->flags & SDHCI_USE_ADMA)
88 printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n", 90 printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
@@ -1323,11 +1325,114 @@ out:
1323 spin_unlock_irqrestore(&host->lock, flags); 1325 spin_unlock_irqrestore(&host->lock, flags);
1324} 1326}
1325 1327
1328static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1329 struct mmc_ios *ios)
1330{
1331 struct sdhci_host *host;
1332 u8 pwr;
1333 u16 clk, ctrl;
1334 u32 present_state;
1335
1336 host = mmc_priv(mmc);
1337
1338 /*
1339 * Signal Voltage Switching is only applicable for Host Controllers
1340 * v3.00 and above.
1341 */
1342 if (host->version < SDHCI_SPEC_300)
1343 return 0;
1344
1345 /*
1346 * We first check whether the request is to set signalling voltage
1347 * to 3.3V. If so, we change the voltage to 3.3V and return quickly.
1348 */
1349 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1350 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) {
1351 /* Set 1.8V Signal Enable in the Host Control2 register to 0 */
1352 ctrl &= ~SDHCI_CTRL_VDD_180;
1353 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1354
1355 /* Wait for 5ms */
1356 usleep_range(5000, 5500);
1357
1358 /* 3.3V regulator output should be stable within 5 ms */
1359 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1360 if (!(ctrl & SDHCI_CTRL_VDD_180))
1361 return 0;
1362 else {
1363 printk(KERN_INFO DRIVER_NAME ": Switching to 3.3V "
1364 "signalling voltage failed\n");
1365 return -EIO;
1366 }
1367 } else if (!(ctrl & SDHCI_CTRL_VDD_180) &&
1368 (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180)) {
1369 /* Stop SDCLK */
1370 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
1371 clk &= ~SDHCI_CLOCK_CARD_EN;
1372 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
1373
1374 /* Check whether DAT[3:0] is 0000 */
1375 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
1376 if (!((present_state & SDHCI_DATA_LVL_MASK) >>
1377 SDHCI_DATA_LVL_SHIFT)) {
1378 /*
1379 * Enable 1.8V Signal Enable in the Host Control2
1380 * register
1381 */
1382 ctrl |= SDHCI_CTRL_VDD_180;
1383 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1384
1385 /* Wait for 5ms */
1386 usleep_range(5000, 5500);
1387
1388 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1389 if (ctrl & SDHCI_CTRL_VDD_180) {
1390 /* Provide SDCLK again and wait for 1ms*/
1391 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
1392 clk |= SDHCI_CLOCK_CARD_EN;
1393 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
1394 usleep_range(1000, 1500);
1395
1396 /*
1397 * If DAT[3:0] level is 1111b, then the card
1398 * was successfully switched to 1.8V signaling.
1399 */
1400 present_state = sdhci_readl(host,
1401 SDHCI_PRESENT_STATE);
1402 if ((present_state & SDHCI_DATA_LVL_MASK) ==
1403 SDHCI_DATA_LVL_MASK)
1404 return 0;
1405 }
1406 }
1407
1408 /*
1409 * If we are here, that means the switch to 1.8V signaling
1410 * failed. We power cycle the card, and retry initialization
1411 * sequence by setting S18R to 0.
1412 */
1413 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
1414 pwr &= ~SDHCI_POWER_ON;
1415 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1416
1417 /* Wait for 1ms as per the spec */
1418 usleep_range(1000, 1500);
1419 pwr |= SDHCI_POWER_ON;
1420 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1421
1422 printk(KERN_INFO DRIVER_NAME ": Switching to 1.8V signalling "
1423 "voltage failed, retrying with S18R set to 0\n");
1424 return -EAGAIN;
1425 } else
1426 /* No signal voltage switch required */
1427 return 0;
1428}
1429
1326static const struct mmc_host_ops sdhci_ops = { 1430static const struct mmc_host_ops sdhci_ops = {
1327 .request = sdhci_request, 1431 .request = sdhci_request,
1328 .set_ios = sdhci_set_ios, 1432 .set_ios = sdhci_set_ios,
1329 .get_ro = sdhci_get_ro, 1433 .get_ro = sdhci_get_ro,
1330 .enable_sdio_irq = sdhci_enable_sdio_irq, 1434 .enable_sdio_irq = sdhci_enable_sdio_irq,
1435 .start_signal_voltage_switch = sdhci_start_signal_voltage_switch,
1331}; 1436};
1332 1437
1333/*****************************************************************************\ 1438/*****************************************************************************\
@@ -1808,7 +1913,9 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
1808int sdhci_add_host(struct sdhci_host *host) 1913int sdhci_add_host(struct sdhci_host *host)
1809{ 1914{
1810 struct mmc_host *mmc; 1915 struct mmc_host *mmc;
1811 unsigned int caps, ocr_avail; 1916 u32 caps[2];
1917 u32 max_current_caps;
1918 unsigned int ocr_avail;
1812 int ret; 1919 int ret;
1813 1920
1814 WARN_ON(host == NULL); 1921 WARN_ON(host == NULL);
@@ -1831,12 +1938,15 @@ int sdhci_add_host(struct sdhci_host *host)
1831 host->version); 1938 host->version);
1832 } 1939 }
1833 1940
1834 caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : 1941 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
1835 sdhci_readl(host, SDHCI_CAPABILITIES); 1942 sdhci_readl(host, SDHCI_CAPABILITIES);
1836 1943
1944 caps[1] = (host->version >= SDHCI_SPEC_300) ?
1945 sdhci_readl(host, SDHCI_CAPABILITIES_1) : 0;
1946
1837 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 1947 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
1838 host->flags |= SDHCI_USE_SDMA; 1948 host->flags |= SDHCI_USE_SDMA;
1839 else if (!(caps & SDHCI_CAN_DO_SDMA)) 1949 else if (!(caps[0] & SDHCI_CAN_DO_SDMA))
1840 DBG("Controller doesn't have SDMA capability\n"); 1950 DBG("Controller doesn't have SDMA capability\n");
1841 else 1951 else
1842 host->flags |= SDHCI_USE_SDMA; 1952 host->flags |= SDHCI_USE_SDMA;
@@ -1847,7 +1957,8 @@ int sdhci_add_host(struct sdhci_host *host)
1847 host->flags &= ~SDHCI_USE_SDMA; 1957 host->flags &= ~SDHCI_USE_SDMA;
1848 } 1958 }
1849 1959
1850 if ((host->version >= SDHCI_SPEC_200) && (caps & SDHCI_CAN_DO_ADMA2)) 1960 if ((host->version >= SDHCI_SPEC_200) &&
1961 (caps[0] & SDHCI_CAN_DO_ADMA2))
1851 host->flags |= SDHCI_USE_ADMA; 1962 host->flags |= SDHCI_USE_ADMA;
1852 1963
1853 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && 1964 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
@@ -1897,10 +2008,10 @@ int sdhci_add_host(struct sdhci_host *host)
1897 } 2008 }
1898 2009
1899 if (host->version >= SDHCI_SPEC_300) 2010 if (host->version >= SDHCI_SPEC_300)
1900 host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK) 2011 host->max_clk = (caps[0] & SDHCI_CLOCK_V3_BASE_MASK)
1901 >> SDHCI_CLOCK_BASE_SHIFT; 2012 >> SDHCI_CLOCK_BASE_SHIFT;
1902 else 2013 else
1903 host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) 2014 host->max_clk = (caps[0] & SDHCI_CLOCK_BASE_MASK)
1904 >> SDHCI_CLOCK_BASE_SHIFT; 2015 >> SDHCI_CLOCK_BASE_SHIFT;
1905 2016
1906 host->max_clk *= 1000000; 2017 host->max_clk *= 1000000;
@@ -1916,7 +2027,7 @@ int sdhci_add_host(struct sdhci_host *host)
1916 } 2027 }
1917 2028
1918 host->timeout_clk = 2029 host->timeout_clk =
1919 (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT; 2030 (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
1920 if (host->timeout_clk == 0) { 2031 if (host->timeout_clk == 0) {
1921 if (host->ops->get_timeout_clock) { 2032 if (host->ops->get_timeout_clock) {
1922 host->timeout_clk = host->ops->get_timeout_clock(host); 2033 host->timeout_clk = host->ops->get_timeout_clock(host);
@@ -1928,7 +2039,7 @@ int sdhci_add_host(struct sdhci_host *host)
1928 return -ENODEV; 2039 return -ENODEV;
1929 } 2040 }
1930 } 2041 }
1931 if (caps & SDHCI_TIMEOUT_CLK_UNIT) 2042 if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT)
1932 host->timeout_clk *= 1000; 2043 host->timeout_clk *= 1000;
1933 2044
1934 /* 2045 /*
@@ -1955,21 +2066,76 @@ int sdhci_add_host(struct sdhci_host *host)
1955 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) 2066 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
1956 mmc->caps |= MMC_CAP_4_BIT_DATA; 2067 mmc->caps |= MMC_CAP_4_BIT_DATA;
1957 2068
1958 if (caps & SDHCI_CAN_DO_HISPD) 2069 if (caps[0] & SDHCI_CAN_DO_HISPD)
1959 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 2070 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
1960 2071
1961 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && 2072 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
1962 mmc_card_is_removable(mmc)) 2073 mmc_card_is_removable(mmc))
1963 mmc->caps |= MMC_CAP_NEEDS_POLL; 2074 mmc->caps |= MMC_CAP_NEEDS_POLL;
1964 2075
2076 /* UHS-I mode(s) supported by the host controller. */
2077 if (host->version >= SDHCI_SPEC_300)
2078 mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
2079
2080 /* SDR104 supports also implies SDR50 support */
2081 if (caps[1] & SDHCI_SUPPORT_SDR104)
2082 mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50;
2083 else if (caps[1] & SDHCI_SUPPORT_SDR50)
2084 mmc->caps |= MMC_CAP_UHS_SDR50;
2085
2086 if (caps[1] & SDHCI_SUPPORT_DDR50)
2087 mmc->caps |= MMC_CAP_UHS_DDR50;
2088
1965 ocr_avail = 0; 2089 ocr_avail = 0;
1966 if (caps & SDHCI_CAN_VDD_330) 2090 /*
2091 * According to SD Host Controller spec v3.00, if the Host System
2092 * can afford more than 150mA, Host Driver should set XPC to 1. Also
2093 * the value is meaningful only if Voltage Support in the Capabilities
2094 * register is set. The actual current value is 4 times the register
2095 * value.
2096 */
2097 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
2098
2099 if (caps[0] & SDHCI_CAN_VDD_330) {
2100 int max_current_330;
2101
1967 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; 2102 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
1968 if (caps & SDHCI_CAN_VDD_300) 2103
2104 max_current_330 = ((max_current_caps &
2105 SDHCI_MAX_CURRENT_330_MASK) >>
2106 SDHCI_MAX_CURRENT_330_SHIFT) *
2107 SDHCI_MAX_CURRENT_MULTIPLIER;
2108
2109 if (max_current_330 > 150)
2110 mmc->caps |= MMC_CAP_SET_XPC_330;
2111 }
2112 if (caps[0] & SDHCI_CAN_VDD_300) {
2113 int max_current_300;
2114
1969 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; 2115 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
1970 if (caps & SDHCI_CAN_VDD_180) 2116
2117 max_current_300 = ((max_current_caps &
2118 SDHCI_MAX_CURRENT_300_MASK) >>
2119 SDHCI_MAX_CURRENT_300_SHIFT) *
2120 SDHCI_MAX_CURRENT_MULTIPLIER;
2121
2122 if (max_current_300 > 150)
2123 mmc->caps |= MMC_CAP_SET_XPC_300;
2124 }
2125 if (caps[0] & SDHCI_CAN_VDD_180) {
2126 int max_current_180;
2127
1971 ocr_avail |= MMC_VDD_165_195; 2128 ocr_avail |= MMC_VDD_165_195;
1972 2129
2130 max_current_180 = ((max_current_caps &
2131 SDHCI_MAX_CURRENT_180_MASK) >>
2132 SDHCI_MAX_CURRENT_180_SHIFT) *
2133 SDHCI_MAX_CURRENT_MULTIPLIER;
2134
2135 if (max_current_180 > 150)
2136 mmc->caps |= MMC_CAP_SET_XPC_180;
2137 }
2138
1973 mmc->ocr_avail = ocr_avail; 2139 mmc->ocr_avail = ocr_avail;
1974 mmc->ocr_avail_sdio = ocr_avail; 2140 mmc->ocr_avail_sdio = ocr_avail;
1975 if (host->ocr_avail_sdio) 2141 if (host->ocr_avail_sdio)
@@ -2029,7 +2195,7 @@ int sdhci_add_host(struct sdhci_host *host)
2029 if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) { 2195 if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
2030 mmc->max_blk_size = 2; 2196 mmc->max_blk_size = 2;
2031 } else { 2197 } else {
2032 mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> 2198 mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
2033 SDHCI_MAX_BLOCK_SHIFT; 2199 SDHCI_MAX_BLOCK_SHIFT;
2034 if (mmc->max_blk_size >= 3) { 2200 if (mmc->max_blk_size >= 3) {
2035 printk(KERN_WARNING "%s: Invalid maximum block size, " 2201 printk(KERN_WARNING "%s: Invalid maximum block size, "