[MMC] sdhci: fix timeout loops in sdhci

The current timeout loop assume that jiffies are updated.  This might not be
the case depending on locks and if the kernel is compiled without preemption.
Change the system to use a counter and fixed delays.

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
This commit is contained in:
Pierre Ossman 2006-06-30 02:22:23 -07:00 committed by Russell King
parent 146ad66eac
commit 7cb2c76fa2
1 changed files with 16 additions and 13 deletions

View File

@ -371,17 +371,17 @@ static void sdhci_finish_data(struct sdhci_host *host)
static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
{ {
int flags; int flags;
u32 present; unsigned long timeout;
unsigned long max_jiffies;
WARN_ON(host->cmd); WARN_ON(host->cmd);
DBG("Sending cmd (%x)\n", cmd->opcode); DBG("Sending cmd (%x)\n", cmd->opcode);
/* Wait max 10 ms */ /* Wait max 10 ms */
max_jiffies = jiffies + (HZ + 99)/100; timeout = 10;
do { while (readl(host->ioaddr + SDHCI_PRESENT_STATE) &
if (time_after(jiffies, max_jiffies)) { (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
if (timeout == 0) {
printk(KERN_ERR "%s: Controller never released " printk(KERN_ERR "%s: Controller never released "
"inhibit bits. Please report this to " "inhibit bits. Please report this to "
BUGMAIL ".\n", mmc_hostname(host->mmc)); BUGMAIL ".\n", mmc_hostname(host->mmc));
@ -390,8 +390,9 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
tasklet_schedule(&host->finish_tasklet); tasklet_schedule(&host->finish_tasklet);
return; return;
} }
present = readl(host->ioaddr + SDHCI_PRESENT_STATE); timeout--;
} while (present & (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)); mdelay(1);
}
mod_timer(&host->timer, jiffies + 10 * HZ); mod_timer(&host->timer, jiffies + 10 * HZ);
@ -490,7 +491,7 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
{ {
int div; int div;
u16 clk; u16 clk;
unsigned long max_jiffies; unsigned long timeout;
if (clock == host->clock) if (clock == host->clock)
return; return;
@ -511,17 +512,19 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL); writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
/* Wait max 10 ms */ /* Wait max 10 ms */
max_jiffies = jiffies + (HZ + 99)/100; timeout = 10;
do { while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL))
if (time_after(jiffies, max_jiffies)) { & SDHCI_CLOCK_INT_STABLE)) {
if (timeout == 0) {
printk(KERN_ERR "%s: Internal clock never stabilised. " printk(KERN_ERR "%s: Internal clock never stabilised. "
"Please report this to " BUGMAIL ".\n", "Please report this to " BUGMAIL ".\n",
mmc_hostname(host->mmc)); mmc_hostname(host->mmc));
sdhci_dumpregs(host); sdhci_dumpregs(host);
return; return;
} }
clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL); timeout--;
} while (!(clk & SDHCI_CLOCK_INT_STABLE)); mdelay(1);
}
clk |= SDHCI_CLOCK_CARD_EN; clk |= SDHCI_CLOCK_CARD_EN;
writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL); writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);