From patchwork Thu Sep 16 06:46:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaehoon Chung X-Patchwork-Id: 184692 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 o8G6kr4R012702 for ; Thu, 16 Sep 2010 06:46:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752835Ab0IPGqw (ORCPT ); Thu, 16 Sep 2010 02:46:52 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:49323 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752400Ab0IPGqw (ORCPT ); Thu, 16 Sep 2010 02:46:52 -0400 Received: from epmmp1 (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Sun Java(tm) System Messaging Server 7u3-15.01 64bit (built Feb 12 2010)) with ESMTP id <0L8T00IIMUU2J5D0@mailout4.samsung.com> for linux-mmc@vger.kernel.org; Thu, 16 Sep 2010 15:46:50 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0L8T00KDXUU2LX@mmp1.samsung.com> for linux-mmc@vger.kernel.org; Thu, 16 Sep 2010 15:46:50 +0900 (KST) Received: from [127.0.0.1] ([10.89.53.131]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.4675); Thu, 16 Sep 2010 15:46:50 +0900 Date: Thu, 16 Sep 2010 15:46:50 +0900 From: Jaehoon Chung Subject: [RFC RESEND] sdhci-s3c: support clock enable/disable (clock-gating) To: linux-mmc@vger.kernel.org Cc: Kyungmin Park , matt@console-pimps.org, Andrew Morton , Marek Szyprowski , Kukjin Kim , Chris Ball Message-id: <4C91BD5A.1040804@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=EUC-KR Content-transfer-encoding: 7BIT User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ko; rv:1.9.2.4) Gecko/20100608 Thunderbird/3.1 X-OriginalArrivalTime: 16 Sep 2010 06:46:50.0565 (UTC) FILETIME=[F0D61F50:01CB556A] 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, 16 Sep 2010 06:46:53 +0000 (UTC) diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index 71ad416..9b430fb 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c @@ -47,6 +47,7 @@ struct sdhci_s3c { unsigned int cur_clk; int ext_cd_irq; int ext_cd_gpio; + int flag; struct clk *clk_io; struct clk *clk_bus[MAX_BUS_CLK]; @@ -232,10 +233,45 @@ static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host) return min; } +static int sdhci_s3c_enable_clk(struct sdhci_host *host) +{ + struct sdhci_s3c *sc = to_s3c(host); + + if (sc->flag != 1) { + clk_disable(sc->clk_io); + clk_disable(sc->clk_bus[sc->cur_clk]); + } + + if (sc->host->clk_cnt == 0) { + clk_enable(sc->clk_io); + clk_enable(sc->clk_bus[sc->cur_clk]); + sc->host->clk_cnt++; + sc->flag = 1; + } + + return 0; +} + +static int sdhci_s3c_disable_clk(struct sdhci_host *host, int lazy) +{ + struct sdhci_s3c *sc = to_s3c(host); + + if (sc->host->clk_cnt) { + clk_disable(sc->clk_io); + clk_disable(sc->clk_bus[sc->cur_clk]); + if (sc->host->clk_cnt) + sc->host->clk_cnt--; + } + + return 0; +} + static struct sdhci_ops sdhci_s3c_ops = { .get_max_clock = sdhci_s3c_get_max_clk, .set_clock = sdhci_s3c_set_clock, .get_min_clock = sdhci_s3c_get_min_clock, + .enable = sdhci_s3c_enable_clk, + .disable = sdhci_s3c_disable_clk, }; static void sdhci_s3c_notify_change(struct platform_device *dev, int state) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 401527d..fa2e55d 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1245,7 +1245,37 @@ out: spin_unlock_irqrestore(&host->lock, flags); } +static int sdhci_enable_clk(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + int ret = 0; + + if (host->old_clock != 0 && host->clock == 0) { + if (host->ops->enable) + ret = host->ops->enable(host); + sdhci_set_clock(host, host->old_clock); + } + + return ret; +} + +static int sdhci_disable_clk(struct mmc_host *mmc, int lazy) +{ + struct sdhci_host *host = mmc_priv(mmc); + int ret = 0; + + if (host->clock != 0) { + host->old_clock = host->clock; + sdhci_set_clock(host, 0); + if (host->ops->disable) + ret = host->ops->disable(host, lazy); + } + return ret; +} + static const struct mmc_host_ops sdhci_ops = { + .enable = sdhci_enable_clk, + .disable = sdhci_disable_clk, .request = sdhci_request, .set_ios = sdhci_set_ios, .get_ro = sdhci_get_ro, diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index d316bc7..0c6f143 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -278,6 +278,8 @@ struct sdhci_host { unsigned int timeout_clk; /* Timeout freq (KHz) */ unsigned int clock; /* Current clock (MHz) */ + unsigned int old_clock; /* Old clock (MHz) */ + unsigned int clk_cnt; /* Clock user count */ u8 pwr; /* Current voltage */ struct mmc_request *mrq; /* Current request */ @@ -323,6 +325,8 @@ struct sdhci_ops { unsigned int (*get_max_clock)(struct sdhci_host *host); unsigned int (*get_min_clock)(struct sdhci_host *host); unsigned int (*get_timeout_clock)(struct sdhci_host *host); + int (*enable)(struct sdhci_host *host); + int (*disable)(struct sdhci_host *host, int lazy); }; #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS