From patchwork Thu Nov 11 09:05:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chuanxiao.Dong" X-Patchwork-Id: 316882 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAB96tRu008735 for ; Thu, 11 Nov 2010 09:07:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752376Ab0KKJHK (ORCPT ); Thu, 11 Nov 2010 04:07:10 -0500 Received: from mga09.intel.com ([134.134.136.24]:13608 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1749667Ab0KKJHI convert rfc822-to-8bit (ORCPT ); Thu, 11 Nov 2010 04:07:08 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 11 Nov 2010 01:07:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.59,181,1288594800"; d="scan'208,223";a="572472917" Received: from unknown (HELO intel.com) ([172.16.120.128]) by orsmga002.jf.intel.com with ESMTP; 11 Nov 2010 01:07:07 -0800 Date: Thu, 11 Nov 2010 17:05:19 +0800 From: "Chuanxiao.Dong" To: cjb@laptop.org Cc: adrian.hunter@nokia.com, linux-mmc@vger.kernel.org Subject: [PATCH v1 1/3]Add erase timeout calculation routine for sdhci host Message-ID: <20101111090519.GB18170@intel.com> Reply-To: "Chuanxiao.Dong" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 11 Nov 2010 09:07:11 +0000 (UTC) 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;