From patchwork Tue Apr 19 17:44:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 718591 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 p3JHjwjr004515 for ; Tue, 19 Apr 2011 17:46:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522Ab1DSRp6 (ORCPT ); Tue, 19 Apr 2011 13:45:58 -0400 Received: from opensource.wolfsonmicro.com ([80.75.67.52]:43874 "EHLO opensource2.wolfsonmicro.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752378Ab1DSRp5 (ORCPT ); Tue, 19 Apr 2011 13:45:57 -0400 Received: from finisterre.wolfsonmicro.main (unknown [87.246.78.26]) by opensource2.wolfsonmicro.com (Postfix) with ESMTPSA id 4C2BC11018E; Tue, 19 Apr 2011 18:45:56 +0100 (BST) Received: from broonie by finisterre.wolfsonmicro.main with local (Exim 4.74) (envelope-from ) id 1QCF02-0001F5-Co; Tue, 19 Apr 2011 18:46:06 +0100 From: Mark Brown To: Chris Ball , Andrei Warkentin , patches@opensource.wolfsonmicro.com Cc: linux-mmc@vger.kernel.org, Mark Brown Subject: [PATCH] mmc: sdhci: Fix SDHCI_QUIRK_TIMEOUT_USES_SDCLK Date: Tue, 19 Apr 2011 18:44:17 +0100 Message-Id: <1303235057-4745-1-git-send-email-broonie@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.4.1 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.6 (demeter1.kernel.org [140.211.167.41]); Tue, 19 Apr 2011 17:46:09 +0000 (UTC) Commit 373e6a (mmc: sdhci: R1B command handling + MMC_CAP_ERASE) moved the handling of SDHCI_QUIRK_TIMEOUT_USES_SDCLK from sdhci_calc_timeout() to sdhci_add_host(). This causes division by zero errors on at least the S3C SDHCI controller as the quirk implementation needs host->clock set to work but host->clock has not been set when sdhci_add_host() is called. Fix this by backing out that portion of the change, the clock may vary at runtime anyway. It does occur to me that we may want to move the quirk to where we set the clock but this seems more invasive and I'm concerned about undesirable side effects. Signed-off-by: Mark Brown --- drivers/mmc/host/sdhci.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index f79dead..da57bdb 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -616,6 +616,9 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) target_timeout = data->timeout_ns / 1000 + data->timeout_clks / host->clock; + if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK) + host->timeout_clk = host->clock / 1000; + /* * Figure out needed cycles. * We do this in steps in order to fit inside a 32 bit int. @@ -626,6 +629,7 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) * => * (1) / (2) > 2^6 */ + BUG_ON(!host->timeout_clk); count = 0; current_timeout = (1 << 13) * 1000 / host->timeout_clk; while (current_timeout < target_timeout) { @@ -1894,9 +1898,6 @@ 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. */