>From e2b3bc79dd1f76b21701e5e6757121c89f7add71 Mon Sep 17 00:00:00 2001 From: Chuanxiao Dong <[email protected]> Date: Sat, 13 Nov 2010 19:41:45 +0800 Subject: [PATCH 2/4] mmc: add erase timeout calculation routine for sdhci host
Erase command needs R1b response which means after HD handle a CMD_RESPONSE interrupt, driver also need to wait for a while. For SDHCI host controller, HD also need to handle a DATA_END interrupt. During device handle erase cmd, if the blocks need to be erased are too many, some SDHCI host controller maybe launch a TIMEOUT interrupt before the erase cmd finishing. To avoid this kind of situation, SDHCI HD need to calculate a correct timeout value before issuing erase cmd. Patch added a routine to implement this. Signed-off-by: Chuanxiao Dong <[email protected]> --- drivers/mmc/core/core.c | 4 ++++ drivers/mmc/host/sdhci.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index d464252..3df86c1 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -168,6 +168,9 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) mrq->cmd->error = 0; mrq->cmd->mrq = mrq; + if (mrq->cmd->opcode != MMC_ERASE) + mrq->cmd->erase_timeout = 0; + if (mrq->data) { BUG_ON(mrq->data->blksz > host->max_blk_size); BUG_ON(mrq->data->blocks > host->max_blk_count); @@ -188,6 +191,7 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) mrq->data->stop = mrq->stop; mrq->stop->error = 0; mrq->stop->mrq = mrq; + mrq->stop->erase_timeout = 0; } } host->ops->request(host, mrq); diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index f6a2b8a..f855efc 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -927,6 +927,48 @@ static void sdhci_clock_reset(struct sdhci_host *host) } } +static void sdhci_set_erasetimeout(struct sdhci_host *host, + unsigned int erase_timeout) +{ + u64 current_timeout; + int count = 0xe; + /* + * If the host controller provides us with an incorrect timeout + * value, just skip the check and use 0xE. The hardware may take + * longer to time out, but that's much better than having a too-short + * timeout value. + */ + if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) + goto out; + + if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK) + host->timeout_clk = host->clock / 1000; + + /* Caculate the MAX timeout time for host controller */ + + /* Timeout in ms */ + count = 0xe; + current_timeout = (1 << 27) / host->timeout_clk; + while (current_timeout > erase_timeout) { + current_timeout >>= 1; + count--; + if (count == 0) + break; + } + + if (count == 0xe) { + /* host controller should disable timeout interrupt + * here. But right now some host controller timeout + * interrupt cannot be disabled + * */ + pr_warn("warning: device may have not enough time " + "to wait for erase cmd finishing\n"); + } else + count += 1; +out: + sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); +} + static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) { int flags; @@ -997,6 +1039,9 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) if (host->quirks & SDHCI_QUIRK_SERIALIZE) sdhci_clock_reset(host); + if (cmd->erase_timeout) + sdhci_set_erasetimeout(host, cmd->erase_timeout); + sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); } @@ -1943,6 +1988,7 @@ int sdhci_add_host(struct sdhci_host *host) mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; mmc->f_max = host->max_clk; mmc->caps |= MMC_CAP_SDIO_IRQ; + mmc->caps |= MMC_CAP_ERASE; if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; -- 1.6.6.1 _______________________________________________ MeeGo-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
