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