Skip to content

Commit 4100500

Browse files
Russell Kingcjb
authored andcommitted
mmc: sdhci: clean up interrupt handling
sdhci interrupt handling is a mess; there is a lot of code doing very similar things. Let's clean this up a bit: 1. set's clear down cmd, data and bus power interrupts in one go - we're always going to handle these. 2. use a do { } while () loop for looping while there are pending interrupts. 3. group clearing of bits in intmask into one place. This results in the code becoming simpler and easier to read. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Tested-by: Markus Pargmann <mpa@pengutronix.de> Tested-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <chris@printf.net>
1 parent bf3b5ec commit 4100500

1 file changed

Lines changed: 58 additions & 66 deletions

File tree

‎drivers/mmc/host/sdhci.c‎

Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
24312431
{
24322432
irqreturn_t result;
24332433
struct sdhci_host *host = dev_id;
2434-
u32 intmask, unexpected = 0;
2434+
u32 intmask, mask, unexpected = 0;
24352435
int cardint = 0, max_loops = 16;
24362436

24372437
spin_lock(&host->lock);
@@ -2442,88 +2442,80 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
24422442
}
24432443

24442444
intmask = sdhci_readl(host, SDHCI_INT_STATUS);
2445-
24462445
if (!intmask || intmask == 0xffffffff) {
24472446
result = IRQ_NONE;
24482447
goto out;
24492448
}
24502449

2451-
again:
2452-
DBG("*** %s got interrupt: 0x%08x\n",
2453-
mmc_hostname(host->mmc), intmask);
2454-
2455-
if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
2456-
u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
2457-
SDHCI_CARD_PRESENT;
2458-
2459-
/*
2460-
* There is a observation on i.mx esdhc. INSERT bit will be
2461-
* immediately set again when it gets cleared, if a card is
2462-
* inserted. We have to mask the irq to prevent interrupt
2463-
* storm which will freeze the system. And the REMOVE gets
2464-
* the same situation.
2465-
*
2466-
* More testing are needed here to ensure it works for other
2467-
* platforms though.
2468-
*/
2469-
sdhci_mask_irqs(host, present ? SDHCI_INT_CARD_INSERT :
2470-
SDHCI_INT_CARD_REMOVE);
2471-
sdhci_unmask_irqs(host, present ? SDHCI_INT_CARD_REMOVE :
2472-
SDHCI_INT_CARD_INSERT);
2473-
2474-
sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
2475-
SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
2476-
intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
2477-
tasklet_schedule(&host->card_tasklet);
2478-
}
2450+
do {
2451+
/* Clear selected interrupts. */
2452+
mask = intmask & (SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
2453+
SDHCI_INT_BUS_POWER);
2454+
sdhci_writel(host, mask, SDHCI_INT_STATUS);
24792455

2480-
if (intmask & SDHCI_INT_CMD_MASK) {
2481-
sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
2482-
SDHCI_INT_STATUS);
2483-
sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
2484-
}
2456+
DBG("*** %s got interrupt: 0x%08x\n",
2457+
mmc_hostname(host->mmc), intmask);
24852458

2486-
if (intmask & SDHCI_INT_DATA_MASK) {
2487-
sdhci_writel(host, intmask & SDHCI_INT_DATA_MASK,
2488-
SDHCI_INT_STATUS);
2489-
sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
2490-
}
2459+
if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
2460+
u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
2461+
SDHCI_CARD_PRESENT;
24912462

2492-
intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
2463+
/*
2464+
* There is a observation on i.mx esdhc. INSERT
2465+
* bit will be immediately set again when it gets
2466+
* cleared, if a card is inserted. We have to mask
2467+
* the irq to prevent interrupt storm which will
2468+
* freeze the system. And the REMOVE gets the
2469+
* same situation.
2470+
*
2471+
* More testing are needed here to ensure it works
2472+
* for other platforms though.
2473+
*/
2474+
sdhci_mask_irqs(host, present ? SDHCI_INT_CARD_INSERT :
2475+
SDHCI_INT_CARD_REMOVE);
2476+
sdhci_unmask_irqs(host, present ? SDHCI_INT_CARD_REMOVE :
2477+
SDHCI_INT_CARD_INSERT);
2478+
2479+
sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
2480+
SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
2481+
tasklet_schedule(&host->card_tasklet);
2482+
}
24932483

2494-
intmask &= ~SDHCI_INT_ERROR;
2484+
if (intmask & SDHCI_INT_CMD_MASK)
2485+
sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
24952486

2496-
if (intmask & SDHCI_INT_BUS_POWER) {
2497-
pr_err("%s: Card is consuming too much power!\n",
2498-
mmc_hostname(host->mmc));
2499-
sdhci_writel(host, SDHCI_INT_BUS_POWER, SDHCI_INT_STATUS);
2500-
}
2487+
if (intmask & SDHCI_INT_DATA_MASK)
2488+
sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
25012489

2502-
intmask &= ~SDHCI_INT_BUS_POWER;
2490+
if (intmask & SDHCI_INT_BUS_POWER)
2491+
pr_err("%s: Card is consuming too much power!\n",
2492+
mmc_hostname(host->mmc));
25032493

2504-
if (intmask & SDHCI_INT_CARD_INT)
2505-
cardint = 1;
2494+
if (intmask & SDHCI_INT_CARD_INT)
2495+
cardint = 1;
25062496

2507-
intmask &= ~SDHCI_INT_CARD_INT;
2497+
intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
2498+
SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK |
2499+
SDHCI_INT_ERROR | SDHCI_INT_BUS_POWER |
2500+
SDHCI_INT_CARD_INT);
25082501

2509-
if (intmask) {
2510-
unexpected |= intmask;
2511-
sdhci_writel(host, intmask, SDHCI_INT_STATUS);
2512-
}
2502+
if (intmask) {
2503+
unexpected |= intmask;
2504+
sdhci_writel(host, intmask, SDHCI_INT_STATUS);
2505+
}
25132506

2514-
result = IRQ_HANDLED;
2507+
result = IRQ_HANDLED;
25152508

2516-
intmask = sdhci_readl(host, SDHCI_INT_STATUS);
2509+
intmask = sdhci_readl(host, SDHCI_INT_STATUS);
25172510

2518-
/*
2519-
* If we know we'll call the driver to signal SDIO IRQ, disregard
2520-
* further indications of Card Interrupt in the status to avoid a
2521-
* needless loop.
2522-
*/
2523-
if (cardint)
2524-
intmask &= ~SDHCI_INT_CARD_INT;
2525-
if (intmask && --max_loops)
2526-
goto again;
2511+
/*
2512+
* If we know we'll call the driver to signal SDIO IRQ,
2513+
* disregard further indications of Card Interrupt in
2514+
* the status to avoid a needless loop.
2515+
*/
2516+
if (cardint)
2517+
intmask &= ~SDHCI_INT_CARD_INT;
2518+
} while (intmask && --max_loops);
25272519
out:
25282520
spin_unlock(&host->lock);
25292521

0 commit comments

Comments
 (0)