Skip to content

Commit 5c93516

Browse files
diandersstorulf
authored andcommitted
mmc: dw_mmc: Add a timeout for sending CMD11
In the Designware databook's description of the "Voltage Switch Normal Scenario" it instructs us to set a timer and fail the voltage change if we don't see the voltage change interrupt within 2ms. Let's implement that. Without implementing this I have often been able to reproduce a hang while trying to send CMD11 on an rk3288-based board while constantly ejecting and inserting UHS cards. Signed-off-by: Doug Anderson <dianders@chromium.org> Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 488b8d6 commit 5c93516

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

drivers/mmc/host/dw_mmc.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,15 @@ static void __dw_mci_start_request(struct dw_mci *host,
10211021

10221022
dw_mci_start_command(host, cmd, cmdflags);
10231023

1024+
if (cmd->opcode == SD_SWITCH_VOLTAGE) {
1025+
/*
1026+
* Databook says to fail after 2ms w/ no response; give an
1027+
* extra jiffy just in case we're about to roll over.
1028+
*/
1029+
mod_timer(&host->cmd11_timer,
1030+
jiffies + msecs_to_jiffies(2) + 1);
1031+
}
1032+
10241033
if (mrq->stop)
10251034
host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
10261035
else
@@ -2159,6 +2168,8 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
21592168
/* Check volt switch first, since it can look like an error */
21602169
if ((host->state == STATE_SENDING_CMD11) &&
21612170
(pending & SDMMC_INT_VOLT_SWITCH)) {
2171+
del_timer(&host->cmd11_timer);
2172+
21622173
mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
21632174
pending &= ~SDMMC_INT_VOLT_SWITCH;
21642175
dw_mci_cmd_interrupt(host, pending);
@@ -2572,6 +2583,18 @@ static bool dw_mci_reset(struct dw_mci *host)
25722583
return ret;
25732584
}
25742585

2586+
static void dw_mci_cmd11_timer(unsigned long arg)
2587+
{
2588+
struct dw_mci *host = (struct dw_mci *)arg;
2589+
2590+
if (host->state != STATE_SENDING_CMD11)
2591+
dev_info(host->dev, "Unexpected CMD11 timeout\n");
2592+
2593+
host->cmd_status = SDMMC_INT_RTO;
2594+
set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
2595+
tasklet_schedule(&host->tasklet);
2596+
}
2597+
25752598
#ifdef CONFIG_OF
25762599
static struct dw_mci_of_quirks {
25772600
char *quirk;
@@ -2746,6 +2769,9 @@ int dw_mci_probe(struct dw_mci *host)
27462769
}
27472770
}
27482771

2772+
setup_timer(&host->cmd11_timer,
2773+
dw_mci_cmd11_timer, (unsigned long)host);
2774+
27492775
host->quirks = host->pdata->quirks;
27502776

27512777
spin_lock_init(&host->lock);

include/linux/mmc/dw_mmc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ struct dw_mci {
202202
int irq;
203203

204204
int sdio_id0;
205+
206+
struct timer_list cmd11_timer;
205207
};
206208

207209
/* DMA ops for Internal/External DMAC interface */

0 commit comments

Comments
 (0)