Commit 81d38428 authored by Pavel Pisa's avatar Pavel Pisa Committed by Russell King

[ARM] 3485/1: i.MX: MX1 SD/MMC fix of unintentional double start possibility

Patch from Pavel Pisa

The clock starting imxmci_start_clock() function contains hardware
issue workaround, which repeats start attempt, if SDHC does not react on
the first trial. But the second start attempt can be taken even, if the
first succeed and test code misses time limited clock running phase
due to delay caused by schedule to other task or some another device
interrupt. This change enables to detect such situation.
The performance is not issue, because usually at full clock rate
only about six loops in delay cycle are needed.
Signed-off-by: default avatarPavel Pisa <pisa@cmp.felk.cvut.cz>
Acked-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent e0a515bc
...@@ -102,6 +102,7 @@ struct imxmci_host { ...@@ -102,6 +102,7 @@ struct imxmci_host {
#define IMXMCI_PEND_CPU_DATA_b 5 #define IMXMCI_PEND_CPU_DATA_b 5
#define IMXMCI_PEND_CARD_XCHG_b 6 #define IMXMCI_PEND_CARD_XCHG_b 6
#define IMXMCI_PEND_SET_INIT_b 7 #define IMXMCI_PEND_SET_INIT_b 7
#define IMXMCI_PEND_STARTED_b 8
#define IMXMCI_PEND_IRQ_m (1 << IMXMCI_PEND_IRQ_b) #define IMXMCI_PEND_IRQ_m (1 << IMXMCI_PEND_IRQ_b)
#define IMXMCI_PEND_DMA_END_m (1 << IMXMCI_PEND_DMA_END_b) #define IMXMCI_PEND_DMA_END_m (1 << IMXMCI_PEND_DMA_END_b)
...@@ -111,6 +112,7 @@ struct imxmci_host { ...@@ -111,6 +112,7 @@ struct imxmci_host {
#define IMXMCI_PEND_CPU_DATA_m (1 << IMXMCI_PEND_CPU_DATA_b) #define IMXMCI_PEND_CPU_DATA_m (1 << IMXMCI_PEND_CPU_DATA_b)
#define IMXMCI_PEND_CARD_XCHG_m (1 << IMXMCI_PEND_CARD_XCHG_b) #define IMXMCI_PEND_CARD_XCHG_m (1 << IMXMCI_PEND_CARD_XCHG_b)
#define IMXMCI_PEND_SET_INIT_m (1 << IMXMCI_PEND_SET_INIT_b) #define IMXMCI_PEND_SET_INIT_m (1 << IMXMCI_PEND_SET_INIT_b)
#define IMXMCI_PEND_STARTED_m (1 << IMXMCI_PEND_STARTED_b)
static void imxmci_stop_clock(struct imxmci_host *host) static void imxmci_stop_clock(struct imxmci_host *host)
{ {
...@@ -131,23 +133,52 @@ static void imxmci_stop_clock(struct imxmci_host *host) ...@@ -131,23 +133,52 @@ static void imxmci_stop_clock(struct imxmci_host *host)
dev_dbg(mmc_dev(host->mmc), "imxmci_stop_clock blocked, no luck\n"); dev_dbg(mmc_dev(host->mmc), "imxmci_stop_clock blocked, no luck\n");
} }
static void imxmci_start_clock(struct imxmci_host *host) static int imxmci_start_clock(struct imxmci_host *host)
{ {
int i = 0; unsigned int trials = 0;
unsigned int delay_limit = 128;
unsigned long flags;
MMC_STR_STP_CLK &= ~STR_STP_CLK_STOP_CLK; MMC_STR_STP_CLK &= ~STR_STP_CLK_STOP_CLK;
while(i < 0x1000) {
if(!(i & 0x7f))
MMC_STR_STP_CLK |= STR_STP_CLK_START_CLK;
if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN) { clear_bit(IMXMCI_PEND_STARTED_b, &host->pending_events);
/* Check twice before cut */
/*
* Command start of the clock, this usually succeeds in less
* then 6 delay loops, but during card detection (low clockrate)
* it takes up to 5000 delay loops and sometimes fails for the first time
*/
MMC_STR_STP_CLK |= STR_STP_CLK_START_CLK;
do {
unsigned int delay = delay_limit;
while(delay--){
if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN) if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)
return; /* Check twice before cut */
if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)
return 0;
if(test_bit(IMXMCI_PEND_STARTED_b, &host->pending_events))
return 0;
} }
i++; local_irq_save(flags);
} /*
dev_dbg(mmc_dev(host->mmc), "imxmci_start_clock blocked, no luck\n"); * Ensure, that request is not doubled under all possible circumstances.
* It is possible, that cock running state is missed, because some other
* IRQ or schedule delays this function execution and the clocks has
* been already stopped by other means (response processing, SDHC HW)
*/
if(!test_bit(IMXMCI_PEND_STARTED_b, &host->pending_events))
MMC_STR_STP_CLK |= STR_STP_CLK_START_CLK;
local_irq_restore(flags);
} while(++trials<256);
dev_err(mmc_dev(host->mmc), "imxmci_start_clock blocked, no luck\n");
return -1;
} }
static void imxmci_softreset(void) static void imxmci_softreset(void)
...@@ -622,6 +653,7 @@ static irqreturn_t imxmci_irq(int irq, void *devid, struct pt_regs *regs) ...@@ -622,6 +653,7 @@ static irqreturn_t imxmci_irq(int irq, void *devid, struct pt_regs *regs)
atomic_set(&host->stuck_timeout, 0); atomic_set(&host->stuck_timeout, 0);
host->status_reg = stat; host->status_reg = stat;
set_bit(IMXMCI_PEND_IRQ_b, &host->pending_events); set_bit(IMXMCI_PEND_IRQ_b, &host->pending_events);
set_bit(IMXMCI_PEND_STARTED_b, &host->pending_events);
tasklet_schedule(&host->tasklet); tasklet_schedule(&host->tasklet);
return IRQ_RETVAL(handled);; return IRQ_RETVAL(handled);;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment