From patchwork Tue Oct 18 10:16:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 77969 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp806448qge; Tue, 18 Oct 2016 03:16:42 -0700 (PDT) X-Received: by 10.99.188.1 with SMTP id q1mr496511pge.145.1476785802678; Tue, 18 Oct 2016 03:16:42 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5si34911004pfe.244.2016.10.18.03.16.40; Tue, 18 Oct 2016 03:16:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755551AbcJRKQj (ORCPT + 14 others); Tue, 18 Oct 2016 06:16:39 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35600 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbcJRKQh (ORCPT ); Tue, 18 Oct 2016 06:16:37 -0400 Received: by mail-pf0-f172.google.com with SMTP id s8so92437613pfj.2 for ; Tue, 18 Oct 2016 03:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=35x0Ngs9BFMnF8Y5ZMtKjpckEcix9q4xlALwaGNCBfo=; b=O2DWLuMMUQ5HYi4YCxrKX1LsALS0xtmfuso8OkBfMba3c6rdHk916mb1KI2+JVH6B0 u1Q42ye8INvC6c61Hh0ahZVcE7q/27ClI0un8d4/qQOvtNh8BM2jq6bqql+//ZYb3BRW pmpSbVMaq1VQvaEUsSKI/YY8Q5R1VBN+hu8Xs= 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; bh=35x0Ngs9BFMnF8Y5ZMtKjpckEcix9q4xlALwaGNCBfo=; b=MR4guwiKaWM+CBPnu33tiwWUpvojbbNw8FjjubJbUAHqye5ACKKjuE7YprO58qhCau fxzxTIqrpPzjfqgHPqBeP/LiBrKM3QBJXyCTR41VMXj/jWGyeWZIc5xPqDNNfPEeePA/ XkG7cw4Ojx6rh97ax/YmuqyFOb7taCDqw4Arb3cK9T8HtlEhTv9+FP0a4/TmUvopOa5M gcTX8PStp5Wa1frsLIpEfWAxYl7/gPKv0rNCIlDZRPAS03y+9ONvivfhkhiUhwIZsvuj ZqKW2d1j4RMCBQTz4yaVix3WSmShRUSUeY3XhHKR5q9vLSYj20KL3sn4aipn1cHvotx+ Wb5Q== X-Gm-Message-State: AA6/9Rkdk+zXMZ9R8elu8l7juCJvydZlsoxCwV/VL4jGGCOE17cORBkZ2XGZnxRlSc6uSK7e X-Received: by 10.98.196.17 with SMTP id y17mr3561375pff.172.1476785796805; Tue, 18 Oct 2016 03:16:36 -0700 (PDT) Received: from blr-ubuntu-56.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id t7sm54673884pfa.22.2016.10.18.03.16.33 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Oct 2016 03:16:36 -0700 (PDT) From: Pramod Gurav To: ulf.hansson@linaro.org, adrian.hunter@intel.com, linux-mmc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, riteshh@codeaurora.org, Pramod Gurav Subject: [PATCH v4] mmc: sdhci-msm: Add pm_runtime and system PM support Date: Tue, 18 Oct 2016 15:46:24 +0530 Message-Id: <20161018101624.27946-1-pramod.gurav@linaro.org> X-Mailer: git-send-email 2.9.3 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Provides runtime PM callbacks to enable and disable clock resources when idle. Also support system PM callbacks to be called during system suspend and resume. Signed-off-by: Pramod Gurav --- Tested on DB410C. Changes in v4: - Remove calls to sdhci_runtime_resume_host/sdhci_runtime_suspend_host from runtime callbacks as sdhc msm controller is capable of restoring it's register values after clocks are disabled and re-enabled. Changes in v3: - Added CONFIG_PM around runtime pm function. - Replaced msm suspend/resume with generic function directly - Use SET_SYSTEM_SLEEP_PM_OPS instead of late version Changes in v2: - Moved pm_rutime enabling before adding host - Handled pm_rutime in remove - Changed runtime handling with reference from sdhci-of-at91.c drivers/mmc/host/sdhci-msm.c | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c index 8ef44a2a..33ec809 100644 --- a/drivers/mmc/host/sdhci-msm.c +++ b/drivers/mmc/host/sdhci-msm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "sdhci-pltfm.h" @@ -658,12 +659,26 @@ static int sdhci_msm_probe(struct platform_device *pdev) goto clk_disable; } + pm_runtime_get_noresume(&pdev->dev); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + pm_runtime_set_autosuspend_delay(&pdev->dev, 50); + pm_runtime_use_autosuspend(&pdev->dev); + ret = sdhci_add_host(host); if (ret) - goto clk_disable; + goto pm_runtime_disable; + + platform_set_drvdata(pdev, host); + + pm_runtime_put_autosuspend(&pdev->dev); return 0; +pm_runtime_disable: + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); clk_disable: clk_disable_unprepare(msm_host->clk); pclk_disable: @@ -685,6 +700,11 @@ static int sdhci_msm_remove(struct platform_device *pdev) 0xffffffff); sdhci_remove_host(host, dead); + + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + clk_disable_unprepare(msm_host->clk); clk_disable_unprepare(msm_host->pclk); if (!IS_ERR(msm_host->bus_clk)) @@ -693,12 +713,56 @@ static int sdhci_msm_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM +static int sdhci_msm_runtime_suspend(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host); + + clk_disable_unprepare(msm_host->clk); + clk_disable_unprepare(msm_host->pclk); + + return 0; +} + +static int sdhci_msm_runtime_resume(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host); + int ret; + + ret = clk_prepare_enable(msm_host->clk); + if (ret) { + dev_err(dev, "clk_enable failed: %d\n", ret); + return ret; + } + ret = clk_prepare_enable(msm_host->pclk); + if (ret) { + dev_err(dev, "clk_enable failed: %d\n", ret); + clk_disable_unprepare(msm_host->clk); + return ret; + } + + return 0; +} +#endif + +static const struct dev_pm_ops sdhci_msm_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume, + NULL) +}; + static struct platform_driver sdhci_msm_driver = { .probe = sdhci_msm_probe, .remove = sdhci_msm_remove, .driver = { .name = "sdhci_msm", .of_match_table = sdhci_msm_dt_match, + .pm = &sdhci_msm_pm_ops, }, };