From patchwork Mon Mar 25 09:27:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Liu X-Patchwork-Id: 2329481 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 1A8ED3FD8C for ; Mon, 25 Mar 2013 09:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758165Ab3CYJ2x (ORCPT ); Mon, 25 Mar 2013 05:28:53 -0400 Received: from na3sys009aog134.obsmtp.com ([74.125.149.83]:38274 "EHLO na3sys009aog134.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758164Ab3CYJ2w (ORCPT ); Mon, 25 Mar 2013 05:28:52 -0400 Received: from sc-owa02.marvell.com ([199.233.58.137]) (using TLSv1) by na3sys009aob134.postini.com ([74.125.148.12]) with SMTP ID DSNKUVAYt/dylAAdnOaGdoMwW1v3/kyPhdct@postini.com; Mon, 25 Mar 2013 02:28:52 PDT Received: from maili.marvell.com (10.93.76.43) by sc-owa02.marvell.com (10.93.76.22) with Microsoft SMTP Server id 8.3.213.0; Mon, 25 Mar 2013 02:25:13 -0700 Received: from kliu5-desktop.marvell.com (unknown [10.38.36.240]) by maili.marvell.com (Postfix) with ESMTP id D88284E517; Mon, 25 Mar 2013 02:24:57 -0700 (PDT) From: Kevin Liu To: , Chris Ball , Jerry Huang , Chunhe Lan , Guennadi Liakhovetski , Sujit Reddy Thumma , Jaehoon Chung , Aaron Lu , Ulf Hansson , Wei WANG , Fabio Estevam CC: Stephen Warren , Adrian Hunter , Philip Rakity , Shawn Guo , Johan Rudholm , Girish K S , Haijun Zhang , Zhangfei Gao , Haojian Zhuang , Chao Xie , Kevin Liu , Kevin Liu Subject: [PATCH RESEND v5] mmc: sdhci: enhance data timeout clock setting if SDCLK is used Date: Mon, 25 Mar 2013 17:27:23 +0800 Message-ID: <1364203643-13233-1-git-send-email-kliu5@marvell.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 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. Currently, no host drivers implemented get_timeout_clock. So this change won't introduce any impact to current code. Signed-off-by: Kevin Liu Acked-by: Andy Shevchenko --- drivers/mmc/host/sdhci.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 2ea429c..577bfa3 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1114,6 +1114,11 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host) return preset; } +static inline void sdhci_set_max_discard_to(struct sdhci_host *host) +{ + 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 */ @@ -1126,6 +1131,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 = DIV_ROUND_UP(clock, 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) @@ -2875,25 +2886,26 @@ 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); + } + if (host->timeout_clk == 0) { + 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;