From patchwork Tue Jan 8 02:16:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Liu X-Patchwork-Id: 1943701 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id AB6C34020F for ; Tue, 8 Jan 2013 02:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487Ab3AHCSy (ORCPT ); Mon, 7 Jan 2013 21:18:54 -0500 Received: from na3sys009aog128.obsmtp.com ([74.125.149.141]:43961 "EHLO na3sys009aog128.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750785Ab3AHCSx (ORCPT ); Mon, 7 Jan 2013 21:18:53 -0500 Received: from MSI-MTA.marvell.com ([65.219.4.132]) (using TLSv1) by na3sys009aob128.postini.com ([74.125.148.12]) with SMTP ID DSNKUOuB54lwphdeNVPwvwWwZIFDxcm+caqL@postini.com; Mon, 07 Jan 2013 18:18:52 PST Received: from maili.marvell.com ([10.68.76.210]) by MSI-MTA.marvell.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 7 Jan 2013 18:17:19 -0800 Received: from kliu5-desktop.marvell.com (unknown [10.38.36.240]) by maili.marvell.com (Postfix) with ESMTP id 8E3864E510; Mon, 7 Jan 2013 18:17:15 -0800 (PST) From: Kevin Liu To: linux-mmc@vger.kernel.org, Chris Ball , Andy Shevchenko , Mark Brown , Adrian Hunter Cc: Philip Rakity , Aaron Lu , Shawn Guo , Ulf Hansson , Johan Rudholm , Daniel Drake , Guennadi Liakhovetski , Jerry Huang , Alexander Stein , Girish K S , Haijun Zhang , Viresh Kumar , Heiko Stuebner , Thomas Abraham , Chander Kashyap , Jaehoon Chung , Sebastian Hesselbarth , Zhangfei Gao , Haojian Zhuang , Chao Xie , Kevin Liu , Kevin Liu Subject: [PATCH v3 1/2] mmc: sdhci: update timeout clock setting if SDCLK is used Date: Tue, 8 Jan 2013 10:16:58 +0800 Message-Id: <1357611419-4179-1-git-send-email-kliu5@marvell.com> X-Mailer: git-send-email 1.7.9.5 X-OriginalArrivalTime: 08 Jan 2013 02:17:19.0617 (UTC) FILETIME=[49420710:01CDED46] Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org 1. If SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK is selected, getting timeout through register or callback function is useless. So skip current redundant code. 2. If SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK is selected, host uses SDCLK instead of TMCLK for data timeouts. So host->timeout_clk and mmc->max_discard_to should be updated accordingly when SDCLK changed. 3. If callback function get_timeout_clock is used, the timeout clock will be returned directly and no need to multiply by the timeout clock unit read from register. Signed-off-by: Kevin Liu --- drivers/mmc/host/sdhci.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 04af0fd..38a6cf3 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1082,6 +1082,12 @@ static void sdhci_finish_command(struct sdhci_host *host) } } +static inline void sdhci_set_max_discard_to(struct sdhci_host *host) +{ + if (host->timeout_clk) + host->mmc->max_discard_to = (1 << 27) / host->timeout_clk; +} + static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) { int div = 0; /* Initialized for compiler warning */ @@ -1094,6 +1100,12 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) host->mmc->actual_clock = 0; + if ((host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK) && clock) { + /* The lowest allowed timeout clock frequency is 1Khz */ + host->timeout_clk = (clock + 999) / 1000; + sdhci_set_max_discard_to(host); + } + if (host->ops->set_clock) { host->ops->set_clock(host, clock); if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) @@ -2828,25 +2840,24 @@ int sdhci_add_host(struct sdhci_host *host) } else mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; - host->timeout_clk = - (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT; - if (host->timeout_clk == 0) { - if (host->ops->get_timeout_clock) { - host->timeout_clk = host->ops->get_timeout_clock(host); - } else if (!(host->quirks & - SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { - pr_err("%s: Hardware doesn't specify timeout clock " - "frequency.\n", mmc_hostname(mmc)); - return -ENODEV; + if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { + host->timeout_clk = (caps[0] & SDHCI_TIMEOUT_CLK_MASK) >> + SDHCI_TIMEOUT_CLK_SHIFT; + if (host->timeout_clk == 0) { + if (host->ops->get_timeout_clock) { + host->timeout_clk = + host->ops->get_timeout_clock(host); + } else { + pr_err("%s: Hardware doesn't specify timeout " + "clock frequency.\n", mmc_hostname(mmc)); + return -ENODEV; + } + } else if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT) { + host->timeout_clk *= 1000; } + sdhci_set_max_discard_to(host); } - if (caps[0] & SDHCI_TIMEOUT_CLK_UNIT) - host->timeout_clk *= 1000; - - if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK) - host->timeout_clk = mmc->f_max / 1000; - mmc->max_discard_to = (1 << 27) / host->timeout_clk; mmc->caps |= MMC_CAP_SDIO_IRQ | MMC_CAP_ERASE | MMC_CAP_CMD23;