Skip to content

Commit 5a436cc

Browse files
ahunter6storulf
authored andcommitted
mmc: sdhci: Optimize delay loops
The delay loops for reset and clock enable always take at least 1 ms because they use mdelay(1). However they can take a lot less time e.g. less than 50us. Use ktime and reduce the delay to 10 microseconds per loop. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Tested-by: Ludovic Desroches <ludovic.desroches@microchip.com>
1 parent 660fc73 commit 5a436cc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

drivers/mmc/host/sdhci.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include <linux/delay.h>
17+
#include <linux/ktime.h>
1718
#include <linux/highmem.h>
1819
#include <linux/io.h>
1920
#include <linux/module.h>
@@ -165,7 +166,7 @@ static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
165166

166167
void sdhci_reset(struct sdhci_host *host, u8 mask)
167168
{
168-
unsigned long timeout;
169+
ktime_t timeout;
169170

170171
sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
171172

@@ -177,18 +178,17 @@ void sdhci_reset(struct sdhci_host *host, u8 mask)
177178
}
178179

179180
/* Wait max 100 ms */
180-
timeout = 100;
181+
timeout = ktime_add_ms(ktime_get(), 100);
181182

182183
/* hw clears the bit when it's done */
183184
while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
184-
if (timeout == 0) {
185+
if (ktime_after(ktime_get(), timeout)) {
185186
pr_err("%s: Reset 0x%x never completed.\n",
186187
mmc_hostname(host->mmc), (int)mask);
187188
sdhci_dumpregs(host);
188189
return;
189190
}
190-
timeout--;
191-
mdelay(1);
191+
udelay(10);
192192
}
193193
}
194194
EXPORT_SYMBOL_GPL(sdhci_reset);
@@ -1346,24 +1346,23 @@ EXPORT_SYMBOL_GPL(sdhci_calc_clk);
13461346

13471347
void sdhci_enable_clk(struct sdhci_host *host, u16 clk)
13481348
{
1349-
unsigned long timeout;
1349+
ktime_t timeout;
13501350

13511351
clk |= SDHCI_CLOCK_INT_EN;
13521352
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
13531353

13541354
/* Wait max 20 ms */
1355-
timeout = 20;
1355+
timeout = ktime_add_ms(ktime_get(), 20);
13561356
while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
13571357
& SDHCI_CLOCK_INT_STABLE)) {
1358-
if (timeout == 0) {
1358+
if (ktime_after(ktime_get(), timeout)) {
13591359
pr_err("%s: Internal clock never stabilised.\n",
13601360
mmc_hostname(host->mmc));
13611361
sdhci_dumpregs(host);
13621362
return;
13631363
}
1364-
timeout--;
13651364
spin_unlock_irq(&host->lock);
1366-
usleep_range(900, 1100);
1365+
udelay(10);
13671366
spin_lock_irq(&host->lock);
13681367
}
13691368

0 commit comments

Comments
 (0)