Skip to content

Commit

Permalink
mmc: sdhci: R1B command handling + MMC_CAP_ERASE.
Browse files Browse the repository at this point in the history
ERASE command needs R1B response, so fix R1B-type command
handling for SDHCI controller. For non-DAT commands using a busy
response, the cmd->cmd_timeout_ms (in ms) field is used for timeout
calculations.

Based on patch by Chuanxiao Dong <chuanxiao.dong@intel.com>
Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
  • Loading branch information
Andrei Warkentin authored and Chris Ball committed May 25, 2011
1 parent eaa02f7 commit a3c7778
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions drivers/mmc/host/sdhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

static unsigned int debug_quirks = 0;

static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
static void sdhci_finish_data(struct sdhci_host *);

static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
Expand Down Expand Up @@ -591,9 +590,10 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
data->sg_len, direction);
}

static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
{
u8 count;
struct mmc_data *data = cmd->data;
unsigned target_timeout, current_timeout;

/*
Expand All @@ -605,12 +605,16 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL)
return 0xE;

/* timeout in us */
target_timeout = data->timeout_ns / 1000 +
data->timeout_clks / host->clock;
/* Unspecified timeout, assume max */
if (!data && !cmd->cmd_timeout_ms)
return 0xE;

if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)
host->timeout_clk = host->clock / 1000;
/* timeout in us */
if (!data)
target_timeout = cmd->cmd_timeout_ms * 1000;
else
target_timeout = data->timeout_ns / 1000 +
data->timeout_clks / host->clock;

/*
* Figure out needed cycles.
Expand All @@ -632,8 +636,8 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
}

if (count >= 0xF) {
printk(KERN_WARNING "%s: Too large timeout requested!\n",
mmc_hostname(host->mmc));
printk(KERN_WARNING "%s: Too large timeout requested for CMD%d!\n",
mmc_hostname(host->mmc), cmd->opcode);
count = 0xE;
}

Expand All @@ -651,15 +655,21 @@ static void sdhci_set_transfer_irqs(struct sdhci_host *host)
sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
}

static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
{
u8 count;
u8 ctrl;
struct mmc_data *data = cmd->data;
int ret;

WARN_ON(host->data);

if (data == NULL)
if (data || (cmd->flags & MMC_RSP_BUSY)) {
count = sdhci_calc_timeout(host, cmd);
sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
}

if (!data)
return;

/* Sanity checks */
Expand All @@ -670,9 +680,6 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
host->data = data;
host->data_early = 0;

count = sdhci_calc_timeout(host, data);
sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL);

if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
host->flags |= SDHCI_REQ_USE_DMA;

Expand Down Expand Up @@ -920,7 +927,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)

host->cmd = cmd;

sdhci_prepare_data(host, cmd->data);
sdhci_prepare_data(host, cmd);

sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT);

Expand Down Expand Up @@ -1874,6 +1881,9 @@ int sdhci_add_host(struct sdhci_host *host)
if (caps & SDHCI_TIMEOUT_CLK_UNIT)
host->timeout_clk *= 1000;

if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)
host->timeout_clk = host->clock / 1000;

/*
* Set host parameters.
*/
Expand All @@ -1886,7 +1896,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_SDIO_IRQ | MMC_CAP_ERASE;

/*
* A controller may support 8-bit width, but the board itself
Expand Down

0 comments on commit a3c7778

Please sign in to comment.