From patchwork Fri Oct 21 06:42:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 9388109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BDB46607F0 for ; Fri, 21 Oct 2016 06:42:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE74D29E19 for ; Fri, 21 Oct 2016 06:42:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A297A29E1F; Fri, 21 Oct 2016 06:42:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19EDE29E19 for ; Fri, 21 Oct 2016 06:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753751AbcJUGmP (ORCPT ); Fri, 21 Oct 2016 02:42:15 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:33890 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754105AbcJUGmO (ORCPT ); Fri, 21 Oct 2016 02:42:14 -0400 Received: by mail-pf0-f178.google.com with SMTP id r16so51448753pfg.1 for ; Thu, 20 Oct 2016 23:42:14 -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=ZOu6O+oZSiB/hzdDiqmXjyLzf+YkREQtcFqGlbdl7yo=; b=fVpTwUIrTFbjdHphBW6Lp9kftsC/O2OOp76F4KZHtk/Ary89e9D7SVjEO7KjvxrexX Bv8kuftIXWUhlV8+fX4pUljUnz96VMWFRLTChw1XKaQYV5REu6kHEQUnCPu+AV5t3XiP fN40A+cCns4krs9Q5br9vZrdTiiRD3ZOb0FAw= 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=ZOu6O+oZSiB/hzdDiqmXjyLzf+YkREQtcFqGlbdl7yo=; b=i1LCJlYQS/n17zx8vf13T2eqJQqhxjUsjJ5QUfLHrmyOGqptIRlvOZK12xcrbwOJKU SFXyo4oYN5ExObiFdkAtdBL/bu6oMNZBWjCkhZynhEOPbTUa/ozykck0iQ9Hi43y9ZdD FR6sNbbqx0xpzJhqWWYEmSw6aAf6qQJwS3TEaUzdllbMgbCkijFJjonytW7UbWKEjRMV jdLdTDCoEmD0sWghAd2qCo/ZngWy56XPpBzWYwTcjYye8BFL5i6PN1KMJkDzGuRFlzZp RqtAorBt6QrAVBWMUen7qLTQxVTdlYDC+2+Ehv3wnMTLd04bBDbqp53xL7YRmr33ggaQ UQ9g== X-Gm-Message-State: AA6/9Rk51jPhBQag29cbx6YLEGof25n8CcpOQltK47uejUsxyyeduI7j76QvysU/60kb4DcR X-Received: by 10.99.204.5 with SMTP id x5mr7094741pgf.96.1477032133465; Thu, 20 Oct 2016 23:42:13 -0700 (PDT) Received: from blr-ubuntu-56.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id d89sm1937511pfe.32.2016.10.20.23.42.09 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 23:42:13 -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 v5] mmc: sdhci-msm: Add pm_runtime and system PM support Date: Fri, 21 Oct 2016 12:12:04 +0530 Message-Id: <20161021064204.10889-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 X-Virus-Scanned: ClamAV using ClamSMTP 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. Reviewed-by: Ritesh Harjani Reviewed-by: Georgi Djakov Tested-by: Ritesh Harjani Signed-off-by: Pramod Gurav --- Tested on DB410C. Changes in v5: - Added pm_runtime_mark_last_busy in probe before calling autosuspend - included clock names in error logs - Used micro instead of constant for autosuspend delay - Removed platform_set_drvdata in probe as sdhci_pltfm_init does it. - Aligned PM ops structure with the parenthesis 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 | 68 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c index 8ef44a2a..795f16f 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" @@ -68,6 +69,7 @@ #define CMUX_SHIFT_PHASE_SHIFT 24 #define CMUX_SHIFT_PHASE_MASK (7 << CMUX_SHIFT_PHASE_SHIFT) +#define MSM_MMC_AUTOSUSPEND_DELAY_MS 50 struct sdhci_msm_host { struct platform_device *pdev; void __iomem *core_mem; /* MSM SDCC mapped address */ @@ -658,12 +660,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, + MSM_MMC_AUTOSUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(&pdev->dev); + ret = sdhci_add_host(host); if (ret) - goto clk_disable; + goto pm_runtime_disable; + + pm_runtime_mark_last_busy(&pdev->dev); + 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 +701,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 +714,57 @@ 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 for core_clk: %d\n", ret); + return ret; + } + ret = clk_prepare_enable(msm_host->pclk); + if (ret) { + dev_err(dev, "clk_enable failed for iface_clk: %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, }, };