812-mmc-layerscape-support.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. From b31046c51c72232363711f0c623df08bf28c37e4 Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Mon, 25 Sep 2017 12:21:30 +0800
  4. Subject: [PATCH] mmc: layerscape support
  5. This is a integrated patch for layerscape mmc support.
  6. Adrian Hunter <[email protected]>
  7. Jaehoon Chung <[email protected]>
  8. Masahiro Yamada <[email protected]>
  9. Signed-off-by: Yangbo Lu <[email protected]>
  10. ---
  11. drivers/mmc/host/Kconfig | 1 +
  12. drivers/mmc/host/sdhci-esdhc.h | 52 +++++---
  13. drivers/mmc/host/sdhci-of-esdhc.c | 251 ++++++++++++++++++++++++++++++++++++--
  14. drivers/mmc/host/sdhci.c | 45 ++++---
  15. drivers/mmc/host/sdhci.h | 3 +
  16. 5 files changed, 306 insertions(+), 46 deletions(-)
  17. --- a/drivers/mmc/host/Kconfig
  18. +++ b/drivers/mmc/host/Kconfig
  19. @@ -144,6 +144,7 @@ config MMC_SDHCI_OF_ESDHC
  20. depends on MMC_SDHCI_PLTFM
  21. depends on PPC || ARCH_MXC || ARCH_LAYERSCAPE
  22. select MMC_SDHCI_IO_ACCESSORS
  23. + select FSL_GUTS
  24. help
  25. This selects the Freescale eSDHC controller support.
  26. --- a/drivers/mmc/host/sdhci-esdhc.h
  27. +++ b/drivers/mmc/host/sdhci-esdhc.h
  28. @@ -24,30 +24,46 @@
  29. SDHCI_QUIRK_PIO_NEEDS_DELAY | \
  30. SDHCI_QUIRK_NO_HISPD_BIT)
  31. -#define ESDHC_PROCTL 0x28
  32. -
  33. -#define ESDHC_SYSTEM_CONTROL 0x2c
  34. -#define ESDHC_CLOCK_MASK 0x0000fff0
  35. -#define ESDHC_PREDIV_SHIFT 8
  36. -#define ESDHC_DIVIDER_SHIFT 4
  37. -#define ESDHC_CLOCK_PEREN 0x00000004
  38. -#define ESDHC_CLOCK_HCKEN 0x00000002
  39. -#define ESDHC_CLOCK_IPGEN 0x00000001
  40. -
  41. /* pltfm-specific */
  42. #define ESDHC_HOST_CONTROL_LE 0x20
  43. /*
  44. - * P2020 interpretation of the SDHCI_HOST_CONTROL register
  45. + * eSDHC register definition
  46. */
  47. -#define ESDHC_CTRL_4BITBUS (0x1 << 1)
  48. -#define ESDHC_CTRL_8BITBUS (0x2 << 1)
  49. -#define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
  50. -
  51. -/* OF-specific */
  52. -#define ESDHC_DMA_SYSCTL 0x40c
  53. -#define ESDHC_DMA_SNOOP 0x00000040
  54. -#define ESDHC_HOST_CONTROL_RES 0x01
  55. +/* Present State Register */
  56. +#define ESDHC_PRSSTAT 0x24
  57. +#define ESDHC_CLOCK_STABLE 0x00000008
  58. +
  59. +/* Protocol Control Register */
  60. +#define ESDHC_PROCTL 0x28
  61. +#define ESDHC_VOLT_SEL 0x00000400
  62. +#define ESDHC_CTRL_4BITBUS (0x1 << 1)
  63. +#define ESDHC_CTRL_8BITBUS (0x2 << 1)
  64. +#define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1)
  65. +#define ESDHC_HOST_CONTROL_RES 0x01
  66. +
  67. +/* System Control Register */
  68. +#define ESDHC_SYSTEM_CONTROL 0x2c
  69. +#define ESDHC_CLOCK_MASK 0x0000fff0
  70. +#define ESDHC_PREDIV_SHIFT 8
  71. +#define ESDHC_DIVIDER_SHIFT 4
  72. +#define ESDHC_CLOCK_SDCLKEN 0x00000008
  73. +#define ESDHC_CLOCK_PEREN 0x00000004
  74. +#define ESDHC_CLOCK_HCKEN 0x00000002
  75. +#define ESDHC_CLOCK_IPGEN 0x00000001
  76. +
  77. +/* Host Controller Capabilities Register 2 */
  78. +#define ESDHC_CAPABILITIES_1 0x114
  79. +
  80. +/* Tuning Block Control Register */
  81. +#define ESDHC_TBCTL 0x120
  82. +#define ESDHC_TB_EN 0x00000004
  83. +
  84. +/* Control Register for DMA transfer */
  85. +#define ESDHC_DMA_SYSCTL 0x40c
  86. +#define ESDHC_PERIPHERAL_CLK_SEL 0x00080000
  87. +#define ESDHC_FLUSH_ASYNC_FIFO 0x00040000
  88. +#define ESDHC_DMA_SNOOP 0x00000040
  89. #endif /* _DRIVERS_MMC_SDHCI_ESDHC_H */
  90. --- a/drivers/mmc/host/sdhci-of-esdhc.c
  91. +++ b/drivers/mmc/host/sdhci-of-esdhc.c
  92. @@ -16,8 +16,12 @@
  93. #include <linux/err.h>
  94. #include <linux/io.h>
  95. #include <linux/of.h>
  96. +#include <linux/of_address.h>
  97. #include <linux/delay.h>
  98. #include <linux/module.h>
  99. +#include <linux/sys_soc.h>
  100. +#include <linux/clk.h>
  101. +#include <linux/ktime.h>
  102. #include <linux/mmc/host.h>
  103. #include "sdhci-pltfm.h"
  104. #include "sdhci-esdhc.h"
  105. @@ -28,8 +32,12 @@
  106. struct sdhci_esdhc {
  107. u8 vendor_ver;
  108. u8 spec_ver;
  109. + bool quirk_incorrect_hostver;
  110. + unsigned int peripheral_clock;
  111. };
  112. +static void esdhc_clock_enable(struct sdhci_host *host, bool enable);
  113. +
  114. /**
  115. * esdhc_read*_fixup - Fixup the value read from incompatible eSDHC register
  116. * to make it compatible with SD spec.
  117. @@ -80,6 +88,17 @@ static u32 esdhc_readl_fixup(struct sdhc
  118. return ret;
  119. }
  120. + /*
  121. + * DTS properties of mmc host are used to enable each speed mode
  122. + * according to soc and board capability. So clean up
  123. + * SDR50/SDR104/DDR50 support bits here.
  124. + */
  125. + if (spec_reg == SDHCI_CAPABILITIES_1) {
  126. + ret = value & (~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
  127. + SDHCI_SUPPORT_DDR50));
  128. + return ret;
  129. + }
  130. +
  131. ret = value;
  132. return ret;
  133. }
  134. @@ -87,6 +106,8 @@ static u32 esdhc_readl_fixup(struct sdhc
  135. static u16 esdhc_readw_fixup(struct sdhci_host *host,
  136. int spec_reg, u32 value)
  137. {
  138. + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  139. + struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  140. u16 ret;
  141. int shift = (spec_reg & 0x2) * 8;
  142. @@ -94,6 +115,12 @@ static u16 esdhc_readw_fixup(struct sdhc
  143. ret = value & 0xffff;
  144. else
  145. ret = (value >> shift) & 0xffff;
  146. + /* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
  147. + * vendor version and spec version information.
  148. + */
  149. + if ((spec_reg == SDHCI_HOST_VERSION) &&
  150. + (esdhc->quirk_incorrect_hostver))
  151. + ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200;
  152. return ret;
  153. }
  154. @@ -235,7 +262,11 @@ static u32 esdhc_be_readl(struct sdhci_h
  155. u32 ret;
  156. u32 value;
  157. - value = ioread32be(host->ioaddr + reg);
  158. + if (reg == SDHCI_CAPABILITIES_1)
  159. + value = ioread32be(host->ioaddr + ESDHC_CAPABILITIES_1);
  160. + else
  161. + value = ioread32be(host->ioaddr + reg);
  162. +
  163. ret = esdhc_readl_fixup(host, reg, value);
  164. return ret;
  165. @@ -246,7 +277,11 @@ static u32 esdhc_le_readl(struct sdhci_h
  166. u32 ret;
  167. u32 value;
  168. - value = ioread32(host->ioaddr + reg);
  169. + if (reg == SDHCI_CAPABILITIES_1)
  170. + value = ioread32(host->ioaddr + ESDHC_CAPABILITIES_1);
  171. + else
  172. + value = ioread32(host->ioaddr + reg);
  173. +
  174. ret = esdhc_readl_fixup(host, reg, value);
  175. return ret;
  176. @@ -404,15 +439,25 @@ static int esdhc_of_enable_dma(struct sd
  177. static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
  178. {
  179. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  180. + struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  181. - return pltfm_host->clock;
  182. + if (esdhc->peripheral_clock)
  183. + return esdhc->peripheral_clock;
  184. + else
  185. + return pltfm_host->clock;
  186. }
  187. static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
  188. {
  189. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  190. + struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  191. + unsigned int clock;
  192. - return pltfm_host->clock / 256 / 16;
  193. + if (esdhc->peripheral_clock)
  194. + clock = esdhc->peripheral_clock;
  195. + else
  196. + clock = pltfm_host->clock;
  197. + return clock / 256 / 16;
  198. }
  199. static void esdhc_of_set_clock(struct sdhci_host *host, unsigned int clock)
  200. @@ -421,17 +466,34 @@ static void esdhc_of_set_clock(struct sd
  201. struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
  202. int pre_div = 1;
  203. int div = 1;
  204. + ktime_t timeout;
  205. u32 temp;
  206. host->mmc->actual_clock = 0;
  207. - if (clock == 0)
  208. + if (clock == 0) {
  209. + esdhc_clock_enable(host, false);
  210. return;
  211. + }
  212. /* Workaround to start pre_div at 2 for VNN < VENDOR_V_23 */
  213. if (esdhc->vendor_ver < VENDOR_V_23)
  214. pre_div = 2;
  215. + /*
  216. + * Limit SD clock to 167MHz for ls1046a according to its datasheet
  217. + */
  218. + if (clock > 167000000 &&
  219. + of_find_compatible_node(NULL, NULL, "fsl,ls1046a-esdhc"))
  220. + clock = 167000000;
  221. +
  222. + /*
  223. + * Limit SD clock to 125MHz for ls1012a according to its datasheet
  224. + */
  225. + if (clock > 125000000 &&
  226. + of_find_compatible_node(NULL, NULL, "fsl,ls1012a-esdhc"))
  227. + clock = 125000000;
  228. +
  229. /* Workaround to reduce the clock frequency for p1010 esdhc */
  230. if (of_find_compatible_node(NULL, NULL, "fsl,p1010-esdhc")) {
  231. if (clock > 20000000)
  232. @@ -441,8 +503,8 @@ static void esdhc_of_set_clock(struct sd
  233. }
  234. temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  235. - temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN
  236. - | ESDHC_CLOCK_MASK);
  237. + temp &= ~(ESDHC_CLOCK_SDCLKEN | ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN |
  238. + ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
  239. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  240. while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
  241. @@ -462,7 +524,20 @@ static void esdhc_of_set_clock(struct sd
  242. | (div << ESDHC_DIVIDER_SHIFT)
  243. | (pre_div << ESDHC_PREDIV_SHIFT));
  244. sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  245. - mdelay(1);
  246. +
  247. + /* Wait max 20 ms */
  248. + timeout = ktime_add_ms(ktime_get(), 20);
  249. + while (!(sdhci_readl(host, ESDHC_PRSSTAT) & ESDHC_CLOCK_STABLE)) {
  250. + if (ktime_after(ktime_get(), timeout)) {
  251. + pr_err("%s: Internal clock never stabilised.\n",
  252. + mmc_hostname(host->mmc));
  253. + return;
  254. + }
  255. + udelay(10);
  256. + }
  257. +
  258. + temp |= ESDHC_CLOCK_SDCLKEN;
  259. + sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL);
  260. }
  261. static void esdhc_pltfm_set_bus_width(struct sdhci_host *host, int width)
  262. @@ -487,6 +562,33 @@ static void esdhc_pltfm_set_bus_width(st
  263. sdhci_writel(host, ctrl, ESDHC_PROCTL);
  264. }
  265. +static void esdhc_clock_enable(struct sdhci_host *host, bool enable)
  266. +{
  267. + u32 val;
  268. + ktime_t timeout;
  269. +
  270. + val = sdhci_readl(host, ESDHC_SYSTEM_CONTROL);
  271. +
  272. + if (enable)
  273. + val |= ESDHC_CLOCK_SDCLKEN;
  274. + else
  275. + val &= ~ESDHC_CLOCK_SDCLKEN;
  276. +
  277. + sdhci_writel(host, val, ESDHC_SYSTEM_CONTROL);
  278. +
  279. + /* Wait max 20 ms */
  280. + timeout = ktime_add_ms(ktime_get(), 20);
  281. + val = ESDHC_CLOCK_STABLE;
  282. + while (!(sdhci_readl(host, ESDHC_PRSSTAT) & val)) {
  283. + if (ktime_after(ktime_get(), timeout)) {
  284. + pr_err("%s: Internal clock never stabilised.\n",
  285. + mmc_hostname(host->mmc));
  286. + break;
  287. + }
  288. + udelay(10);
  289. + }
  290. +}
  291. +
  292. static void esdhc_reset(struct sdhci_host *host, u8 mask)
  293. {
  294. sdhci_reset(host, mask);
  295. @@ -495,6 +597,95 @@ static void esdhc_reset(struct sdhci_hos
  296. sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
  297. }
  298. +/* The SCFG, Supplemental Configuration Unit, provides SoC specific
  299. + * configuration and status registers for the device. There is a
  300. + * SDHC IO VSEL control register on SCFG for some platforms. It's
  301. + * used to support SDHC IO voltage switching.
  302. + */
  303. +static const struct of_device_id scfg_device_ids[] = {
  304. + { .compatible = "fsl,t1040-scfg", },
  305. + { .compatible = "fsl,ls1012a-scfg", },
  306. + { .compatible = "fsl,ls1046a-scfg", },
  307. + {}
  308. +};
  309. +
  310. +/* SDHC IO VSEL control register definition */
  311. +#define SCFG_SDHCIOVSELCR 0x408
  312. +#define SDHCIOVSELCR_TGLEN 0x80000000
  313. +#define SDHCIOVSELCR_VSELVAL 0x60000000
  314. +#define SDHCIOVSELCR_SDHC_VS 0x00000001
  315. +
  316. +static int esdhc_signal_voltage_switch(struct mmc_host *mmc,
  317. + struct mmc_ios *ios)
  318. +{
  319. + struct sdhci_host *host = mmc_priv(mmc);
  320. + struct device_node *scfg_node;
  321. + void __iomem *scfg_base = NULL;
  322. + u32 sdhciovselcr;
  323. + u32 val;
  324. +
  325. + /*
  326. + * Signal Voltage Switching is only applicable for Host Controllers
  327. + * v3.00 and above.
  328. + */
  329. + if (host->version < SDHCI_SPEC_300)
  330. + return 0;
  331. +
  332. + val = sdhci_readl(host, ESDHC_PROCTL);
  333. +
  334. + switch (ios->signal_voltage) {
  335. + case MMC_SIGNAL_VOLTAGE_330:
  336. + val &= ~ESDHC_VOLT_SEL;
  337. + sdhci_writel(host, val, ESDHC_PROCTL);
  338. + return 0;
  339. + case MMC_SIGNAL_VOLTAGE_180:
  340. + scfg_node = of_find_matching_node(NULL, scfg_device_ids);
  341. + if (scfg_node)
  342. + scfg_base = of_iomap(scfg_node, 0);
  343. + if (scfg_base) {
  344. + sdhciovselcr = SDHCIOVSELCR_TGLEN |
  345. + SDHCIOVSELCR_VSELVAL;
  346. + iowrite32be(sdhciovselcr,
  347. + scfg_base + SCFG_SDHCIOVSELCR);
  348. +
  349. + val |= ESDHC_VOLT_SEL;
  350. + sdhci_writel(host, val, ESDHC_PROCTL);
  351. + mdelay(5);
  352. +
  353. + sdhciovselcr = SDHCIOVSELCR_TGLEN |
  354. + SDHCIOVSELCR_SDHC_VS;
  355. + iowrite32be(sdhciovselcr,
  356. + scfg_base + SCFG_SDHCIOVSELCR);
  357. + iounmap(scfg_base);
  358. + } else {
  359. + val |= ESDHC_VOLT_SEL;
  360. + sdhci_writel(host, val, ESDHC_PROCTL);
  361. + }
  362. + return 0;
  363. + default:
  364. + return 0;
  365. + }
  366. +}
  367. +
  368. +static int esdhc_execute_tuning(struct mmc_host *mmc, u32 opcode)
  369. +{
  370. + struct sdhci_host *host = mmc_priv(mmc);
  371. + u32 val;
  372. +
  373. + /* Use tuning block for tuning procedure */
  374. + esdhc_clock_enable(host, false);
  375. + val = sdhci_readl(host, ESDHC_DMA_SYSCTL);
  376. + val |= ESDHC_FLUSH_ASYNC_FIFO;
  377. + sdhci_writel(host, val, ESDHC_DMA_SYSCTL);
  378. +
  379. + val = sdhci_readl(host, ESDHC_TBCTL);
  380. + val |= ESDHC_TB_EN;
  381. + sdhci_writel(host, val, ESDHC_TBCTL);
  382. + esdhc_clock_enable(host, true);
  383. +
  384. + return sdhci_execute_tuning(mmc, opcode);
  385. +}
  386. +
  387. #ifdef CONFIG_PM_SLEEP
  388. static u32 esdhc_proctl;
  389. static int esdhc_of_suspend(struct device *dev)
  390. @@ -575,10 +766,19 @@ static const struct sdhci_pltfm_data sdh
  391. .ops = &sdhci_esdhc_le_ops,
  392. };
  393. +static struct soc_device_attribute soc_incorrect_hostver[] = {
  394. + { .family = "QorIQ T4240", .revision = "1.0", },
  395. + { .family = "QorIQ T4240", .revision = "2.0", },
  396. + { },
  397. +};
  398. +
  399. static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
  400. {
  401. struct sdhci_pltfm_host *pltfm_host;
  402. struct sdhci_esdhc *esdhc;
  403. + struct device_node *np;
  404. + struct clk *clk;
  405. + u32 val;
  406. u16 host_ver;
  407. pltfm_host = sdhci_priv(host);
  408. @@ -588,6 +788,36 @@ static void esdhc_init(struct platform_d
  409. esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
  410. SDHCI_VENDOR_VER_SHIFT;
  411. esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;
  412. + if (soc_device_match(soc_incorrect_hostver))
  413. + esdhc->quirk_incorrect_hostver = true;
  414. + else
  415. + esdhc->quirk_incorrect_hostver = false;
  416. +
  417. + np = pdev->dev.of_node;
  418. + clk = of_clk_get(np, 0);
  419. + if (!IS_ERR(clk)) {
  420. + /*
  421. + * esdhc->peripheral_clock would be assigned with a value
  422. + * which is eSDHC base clock when use periperal clock.
  423. + * For ls1046a, the clock value got by common clk API is
  424. + * peripheral clock while the eSDHC base clock is 1/2
  425. + * peripheral clock.
  426. + */
  427. + if (of_device_is_compatible(np, "fsl,ls1046a-esdhc"))
  428. + esdhc->peripheral_clock = clk_get_rate(clk) / 2;
  429. + else
  430. + esdhc->peripheral_clock = clk_get_rate(clk);
  431. +
  432. + clk_put(clk);
  433. + }
  434. +
  435. + if (esdhc->peripheral_clock) {
  436. + esdhc_clock_enable(host, false);
  437. + val = sdhci_readl(host, ESDHC_DMA_SYSCTL);
  438. + val |= ESDHC_PERIPHERAL_CLK_SEL;
  439. + sdhci_writel(host, val, ESDHC_DMA_SYSCTL);
  440. + esdhc_clock_enable(host, true);
  441. + }
  442. }
  443. static int sdhci_esdhc_probe(struct platform_device *pdev)
  444. @@ -610,6 +840,11 @@ static int sdhci_esdhc_probe(struct plat
  445. if (IS_ERR(host))
  446. return PTR_ERR(host);
  447. + host->mmc_host_ops.start_signal_voltage_switch =
  448. + esdhc_signal_voltage_switch;
  449. + host->mmc_host_ops.execute_tuning = esdhc_execute_tuning;
  450. + host->tuning_delay = 1;
  451. +
  452. esdhc_init(pdev, host);
  453. sdhci_get_of_property(pdev);
  454. --- a/drivers/mmc/host/sdhci.c
  455. +++ b/drivers/mmc/host/sdhci.c
  456. @@ -1624,26 +1624,24 @@ static void sdhci_set_ios(struct mmc_hos
  457. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  458. - if ((ios->timing == MMC_TIMING_SD_HS ||
  459. - ios->timing == MMC_TIMING_MMC_HS)
  460. - && !(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT))
  461. - ctrl |= SDHCI_CTRL_HISPD;
  462. - else
  463. - ctrl &= ~SDHCI_CTRL_HISPD;
  464. + if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) {
  465. + if ((ios->timing == MMC_TIMING_SD_HS ||
  466. + ios->timing == MMC_TIMING_MMC_HS ||
  467. + ios->timing == MMC_TIMING_MMC_HS400 ||
  468. + ios->timing == MMC_TIMING_MMC_HS200 ||
  469. + ios->timing == MMC_TIMING_MMC_DDR52 ||
  470. + ios->timing == MMC_TIMING_UHS_SDR50 ||
  471. + ios->timing == MMC_TIMING_UHS_SDR104 ||
  472. + ios->timing == MMC_TIMING_UHS_DDR50 ||
  473. + ios->timing == MMC_TIMING_UHS_SDR25))
  474. + ctrl |= SDHCI_CTRL_HISPD;
  475. + else
  476. + ctrl &= ~SDHCI_CTRL_HISPD;
  477. + }
  478. if (host->version >= SDHCI_SPEC_300) {
  479. u16 clk, ctrl_2;
  480. - /* In case of UHS-I modes, set High Speed Enable */
  481. - if ((ios->timing == MMC_TIMING_MMC_HS400) ||
  482. - (ios->timing == MMC_TIMING_MMC_HS200) ||
  483. - (ios->timing == MMC_TIMING_MMC_DDR52) ||
  484. - (ios->timing == MMC_TIMING_UHS_SDR50) ||
  485. - (ios->timing == MMC_TIMING_UHS_SDR104) ||
  486. - (ios->timing == MMC_TIMING_UHS_DDR50) ||
  487. - (ios->timing == MMC_TIMING_UHS_SDR25))
  488. - ctrl |= SDHCI_CTRL_HISPD;
  489. -
  490. if (!host->preset_enabled) {
  491. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  492. /*
  493. @@ -1956,7 +1954,7 @@ static int sdhci_prepare_hs400_tuning(st
  494. return 0;
  495. }
  496. -static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
  497. +int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
  498. {
  499. struct sdhci_host *host = mmc_priv(mmc);
  500. u16 ctrl;
  501. @@ -2015,6 +2013,9 @@ static int sdhci_execute_tuning(struct m
  502. return err;
  503. }
  504. + if (host->tuning_delay < 0)
  505. + host->tuning_delay = opcode == MMC_SEND_TUNING_BLOCK;
  506. +
  507. ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
  508. ctrl |= SDHCI_CTRL_EXEC_TUNING;
  509. if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND)
  510. @@ -2127,9 +2128,10 @@ static int sdhci_execute_tuning(struct m
  511. ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
  512. - /* eMMC spec does not require a delay between tuning cycles */
  513. - if (opcode == MMC_SEND_TUNING_BLOCK)
  514. - mdelay(1);
  515. + /* Spec does not require a delay between tuning cycles */
  516. + if (host->tuning_delay > 0)
  517. + mdelay(host->tuning_delay);
  518. +
  519. } while (ctrl & SDHCI_CTRL_EXEC_TUNING);
  520. /*
  521. @@ -2165,6 +2167,7 @@ out_unlock:
  522. spin_unlock_irqrestore(&host->lock, flags);
  523. return err;
  524. }
  525. +EXPORT_SYMBOL_GPL(sdhci_execute_tuning);
  526. static int sdhci_select_drive_strength(struct mmc_card *card,
  527. unsigned int max_dtr, int host_drv,
  528. @@ -2997,6 +3000,8 @@ struct sdhci_host *sdhci_alloc_host(stru
  529. host->flags = SDHCI_SIGNALING_330;
  530. + host->tuning_delay = -1;
  531. +
  532. return host;
  533. }
  534. --- a/drivers/mmc/host/sdhci.h
  535. +++ b/drivers/mmc/host/sdhci.h
  536. @@ -524,6 +524,8 @@ struct sdhci_host {
  537. #define SDHCI_TUNING_MODE_1 0
  538. #define SDHCI_TUNING_MODE_2 1
  539. #define SDHCI_TUNING_MODE_3 2
  540. + /* Delay (ms) between tuning commands */
  541. + int tuning_delay;
  542. unsigned long private[0] ____cacheline_aligned;
  543. };
  544. @@ -689,6 +691,7 @@ void sdhci_set_power_noreg(struct sdhci_
  545. void sdhci_set_bus_width(struct sdhci_host *host, int width);
  546. void sdhci_reset(struct sdhci_host *host, u8 mask);
  547. void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing);
  548. +int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
  549. #ifdef CONFIG_PM
  550. extern int sdhci_suspend_host(struct sdhci_host *host);