* [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host
@ 2010-11-11 9:05 Chuanxiao.Dong
2010-11-11 9:33 ` Wolfram Sang
0 siblings, 1 reply; 5+ messages in thread
From: Chuanxiao.Dong @ 2010-11-11 9:05 UTC (permalink / raw)
To: cjb; +Cc: adrian.hunter, linux-mmc
>From 04704a1c769dc4d15b5fb54d65d8ad46f6c5f57a Mon Sep 17 00:00:00 2001
From: Chuanxiao Dong <chuanxiao.dong@intel.com>
Date: Thu, 11 Nov 2010 13:42:32 +0800
Subject: [PATCH 1/3] 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 <chuanxiao.dong@intel.com>
---
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 8bf542c..d48bb26 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -170,6 +170,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);
@@ -190,6 +193,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;
}
}
mmc_host_clk_ungate(host);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 154cbf8..79fcca2 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -879,6 +879,48 @@ static void sdhci_finish_data(struct sdhci_host *host)
tasklet_schedule(&host->finish_tasklet);
}
+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;
@@ -946,6 +988,9 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
if (cmd->data)
flags |= SDHCI_CMD_DATA;
+ if (cmd->erase_timeout)
+ sdhci_set_erasetimeout(host, cmd->erase_timeout);
+
sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
}
@@ -1857,6 +1902,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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host
2010-11-11 9:05 [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host Chuanxiao.Dong
@ 2010-11-11 9:33 ` Wolfram Sang
2010-11-11 10:01 ` Dong, Chuanxiao
0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2010-11-11 9:33 UTC (permalink / raw)
To: Chuanxiao.Dong; +Cc: cjb, adrian.hunter, linux-mmc
[-- Attachment #1: Type: text/plain, Size: 1612 bytes --]
On Thu, Nov 11, 2010 at 05:05:19PM +0800, Chuanxiao.Dong wrote:
> From 04704a1c769dc4d15b5fb54d65d8ad46f6c5f57a Mon Sep 17 00:00:00 2001
> From: Chuanxiao Dong <chuanxiao.dong@intel.com>
> Date: Thu, 11 Nov 2010 13:42:32 +0800
> Subject: [PATCH 1/3] 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.
Just a formal thing I noticed on a glimpse...
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 154cbf8..79fcca2 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -879,6 +879,48 @@ static void sdhci_finish_data(struct sdhci_host *host)
> tasklet_schedule(&host->finish_tasklet);
> }
>
> +static void sdhci_set_erasetimeout(struct sdhci_host *host,
> + unsigned int erase_timeout)
> +{
> + u64 current_timeout;
> + int count = 0xe;
I'd suggest a define with a speaking name instead of all the hardcoded 0xe.
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host
2010-11-11 9:33 ` Wolfram Sang
@ 2010-11-11 10:01 ` Dong, Chuanxiao
2010-11-11 10:15 ` Wolfram Sang
0 siblings, 1 reply; 5+ messages in thread
From: Dong, Chuanxiao @ 2010-11-11 10:01 UTC (permalink / raw)
To: Wolfram Sang
Cc: cjb@laptop.org, adrian.hunter@nokia.com,
linux-mmc@vger.kernel.org
Hi wolfram
>
> Just a formal thing I noticed on a glimpse...
>
You mean can directly set the TIMEOUT CONTROL register to be the maximum value?
And any comment about patch2 and patch3?
> > diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index
> > 154cbf8..79fcca2 100644
> > --- a/drivers/mmc/host/sdhci.c
> > +++ b/drivers/mmc/host/sdhci.c
> > @@ -879,6 +879,48 @@ static void sdhci_finish_data(struct sdhci_host *host)
> > tasklet_schedule(&host->finish_tasklet);
> > }
> >
> > +static void sdhci_set_erasetimeout(struct sdhci_host *host,
> > + unsigned int erase_timeout)
> > +{
> > + u64 current_timeout;
> > + int count = 0xe;
>
> I'd suggest a define with a speaking name instead of all the hardcoded 0xe.
Ok, will fix it in the next version submission.
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host
2010-11-11 10:01 ` Dong, Chuanxiao
@ 2010-11-11 10:15 ` Wolfram Sang
2010-11-11 10:23 ` Dong, Chuanxiao
0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2010-11-11 10:15 UTC (permalink / raw)
To: Dong, Chuanxiao
Cc: cjb@laptop.org, adrian.hunter@nokia.com,
linux-mmc@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 569 bytes --]
On Thu, Nov 11, 2010 at 06:01:23PM +0800, Dong, Chuanxiao wrote:
> Hi wolfram
> >
> > Just a formal thing I noticed on a glimpse...
> >
> You mean can directly set the TIMEOUT CONTROL register to be the maximum value?
Well, just use a #define instead of 0xe. I did not mean more :)
> And any comment about patch2 and patch3?
Sadly not. No resources left currently :(
Regards,
Wolfram
--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host
2010-11-11 10:15 ` Wolfram Sang
@ 2010-11-11 10:23 ` Dong, Chuanxiao
0 siblings, 0 replies; 5+ messages in thread
From: Dong, Chuanxiao @ 2010-11-11 10:23 UTC (permalink / raw)
To: Wolfram Sang
Cc: cjb@laptop.org, adrian.hunter@nokia.com,
linux-mmc@vger.kernel.org
> > You mean can directly set the TIMEOUT CONTROL register to be the maximum
> value?
>
> Well, just use a #define instead of 0xe. I did not mean more :)
>
> > And any comment about patch2 and patch3?
>
> Sadly not. No resources left currently :(
Never matter, thanks.
Regards
Chuanxiao
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-11-11 10:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-11 9:05 [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host Chuanxiao.Dong
2010-11-11 9:33 ` Wolfram Sang
2010-11-11 10:01 ` Dong, Chuanxiao
2010-11-11 10:15 ` Wolfram Sang
2010-11-11 10:23 ` Dong, Chuanxiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox