From patchwork Wed Oct 2 08:30:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 2973381 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C4A2ABFF0B for ; Wed, 2 Oct 2013 08:31:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FC212012C for ; Wed, 2 Oct 2013 08:31:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 489D320204 for ; Wed, 2 Oct 2013 08:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753377Ab3JBIbM (ORCPT ); Wed, 2 Oct 2013 04:31:12 -0400 Received: from mail-la0-f54.google.com ([209.85.215.54]:60401 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753151Ab3JBIbL (ORCPT ); Wed, 2 Oct 2013 04:31:11 -0400 Received: by mail-la0-f54.google.com with SMTP id ea20so340236lab.41 for ; Wed, 02 Oct 2013 01:31:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bQE0hSnYdC3lvLX1cVsCAKD5plSKlnwfIRe/tl29WLs=; b=er7t2K/hCJM7g1NAWXZCkOxiwZDYQN+pOrB/NUuyn9RKyc+LNlxN32SIwRfuXMwfEb hsDfbZoO3O7ErSBcaNT3uhHUf8Jfi7/0FlU9/P1owh3PzYiL47wuVdgXL6E/a4hc+FSh 3MM6BqxDTVwjTxrXRzo3vsq8i69g5k8uStE9Sc3IH1emTL20y/h395uyo4YP/T7eY3xe mHAl9ewUaX2tn3A6A5i2XnuSBLHyWHLpVpU2+ndw8TL2D2dcIrd1f9XZ5ZS0BMTJtJuG TZnPgg7+tc8iMtIJJV7tNdU/2uVxYTfVM374rQcQZfl7pTV56z8yVNtiHw0XANbrLRk0 zvuQ== X-Gm-Message-State: ALoCoQmzq/myTUWNlLERijUshQtMYrJ9AILBnqAlm+s9515sxnFT5WbHZPGT5/i9yfmzUObMbf+n X-Received: by 10.152.28.105 with SMTP id a9mr475083lah.41.1380702669710; Wed, 02 Oct 2013 01:31:09 -0700 (PDT) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id e4sm890041lba.15.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Oct 2013 01:31:08 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Chris Ball Cc: Ulf Hansson , Guennadi Liakhovetski Subject: [PATCH 5/7] mmc: sd_mmcif: Move clock handling into runtime PM callbacks Date: Wed, 2 Oct 2013 10:30:49 +0200 Message-Id: <1380702651-13389-6-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1380702651-13389-1-git-send-email-ulf.hansson@linaro.org> References: <1380702651-13389-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement callbacks for runtime suspend|resume and leave the clock to be handled from there. The .set_ios function is still capable of using the interal registers to gate the clock when the frequency is zero, but the operations needed towards the clk API is now handled from the runtime callbacks. From now on, CONFIG_PM_RUNTIME is required handle power save with full clock gating at request inactivity. Cc: Guennadi Liakhovetski Signed-off-by: Ulf Hansson --- drivers/mmc/host/sh_mmcif.c | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index f4532dc..e234856 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c @@ -964,19 +964,6 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) sh_mmcif_start_cmd(host, mrq); } -static int sh_mmcif_clk_update(struct sh_mmcif_host *host) -{ - int ret = clk_prepare_enable(host->hclk); - - if (!ret) { - host->clk = clk_get_rate(host->hclk); - host->mmc->f_max = host->clk / 2; - host->mmc->f_min = host->clk / 512; - } - - return ret; -} - static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios) { struct mmc_host *mmc = host->mmc; @@ -1021,7 +1008,6 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) } } if (host->power) { - clk_disable_unprepare(host->hclk); host->power = false; if (ios->power_mode == MMC_POWER_OFF) sh_mmcif_set_power(host, ios); @@ -1032,7 +1018,6 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (ios->clock) { if (!host->power) { - sh_mmcif_clk_update(host); host->power = true; sh_mmcif_sync_reset(host); } @@ -1440,9 +1425,16 @@ static int sh_mmcif_probe(struct platform_device *pdev) dev_err(&pdev->dev, "cannot get clock: %d\n", ret); goto eofparse; } - ret = sh_mmcif_clk_update(host); - if (ret < 0) + + ret = clk_prepare_enable(host->hclk); + if (ret) { + dev_err(&pdev->dev, "cannot enable clock: %d\n", ret); goto eclkupdate; + } + + host->clk = clk_get_rate(host->hclk); + host->mmc->f_max = host->clk / 2; + host->mmc->f_min = host->clk / 512; INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work); @@ -1478,7 +1470,6 @@ static int sh_mmcif_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - clk_disable_unprepare(host->hclk); ret = mmc_add_host(mmc); if (ret < 0) goto emmcaddh; @@ -1568,6 +1559,24 @@ static int sh_mmcif_resume(struct device *dev) } #endif +#ifdef CONFIG_PM_RUNTIME +static int sh_mmcif_runtime_suspend(struct device *dev) +{ + struct sh_mmcif_host *host = dev_get_drvdata(dev); + + clk_disable_unprepare(host->hclk); + return 0; +} + +static int sh_mmcif_runtime_resume(struct device *dev) +{ + struct sh_mmcif_host *host = dev_get_drvdata(dev); + + clk_prepare_enable(host->hclk); + return 0; +} +#endif + static const struct of_device_id mmcif_of_match[] = { { .compatible = "renesas,sh-mmcif" }, { } @@ -1576,6 +1585,8 @@ MODULE_DEVICE_TABLE(of, mmcif_of_match); static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(sh_mmcif_suspend, sh_mmcif_resume) + SET_RUNTIME_PM_OPS(sh_mmcif_runtime_suspend, sh_mmcif_runtime_resume, + NULL) }; static struct platform_driver sh_mmcif_driver = {