From patchwork Thu Sep 1 14:23:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 75227 Delivered-To: patch@linaro.org Received: by 10.140.29.8 with SMTP id a8csp327779qga; Thu, 1 Sep 2016 07:24:05 -0700 (PDT) X-Received: by 10.66.34.2 with SMTP id v2mr26950788pai.4.1472739845275; Thu, 01 Sep 2016 07:24:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m187si5952561pfb.130.2016.09.01.07.24.04; Thu, 01 Sep 2016 07:24:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755333AbcIAOXv (ORCPT + 27 others); Thu, 1 Sep 2016 10:23:51 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34164 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755211AbcIAOXr (ORCPT ); Thu, 1 Sep 2016 10:23:47 -0400 Received: by mail-pa0-f49.google.com with SMTP id fi15so30342370pac.1 for ; Thu, 01 Sep 2016 07:23:46 -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=smVwzvtbb6XWRiLCRlJp2PfHS1IU4i9IvhgGGsd8yw8=; b=WPFeDnvc6ZYP+79lvZVXOnPG9L7L6JJ3iuJDrl4EO68FFMzdFSE8Ul2iWKX8RFQ+kY 95zvgVnj73cF730HFz6OMr7QjPvt+yUqmfsuzdsmg04RD1BnR+OXOLqiTyT8epLRqo1K WbtlrVkbOVF6s5JUNO/QOS/hbqMnUBQmkupIQ= 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=smVwzvtbb6XWRiLCRlJp2PfHS1IU4i9IvhgGGsd8yw8=; b=iThXv4XLySIAbe9qliZN+NGwK91Tx9SK8WpcaVuh2h0s3oI9bCQ4JFQbnOUv1O3gQi 1/nB3kMWxj9u7H4c/9SyQYPjCrDH4GzpEeeql62EZPzL5DWZ3+vSjSfJSkgc3RUre/hC BA+ZnLjx5mpB0XHwpZ0KXfnoMSXvPORrtV5l9nj/mKGFqYrsIiJlWK5ZipvfkfqKYl+J GSSf1heurX7EbnOPjHpfJjcRs8PU3bj3Ef4RcQGBTi4gilZOF+EzcJvWV01NVTCB10zX XwUKzhVvJH9tPPsSsDwywtC+p7XOvrE8Io8sAr9HyUB4+pRolP6L3S3PocSba6CENDVy /7kg== X-Gm-Message-State: AE9vXwPnjDpP+rP/2h0LrwG64cdtoJnfkxPJFdEbHl3+h4Qb/DEaawnqT5jzttcIPO3n85Ws X-Received: by 10.66.191.234 with SMTP id hb10mr26782366pac.149.1472739826028; Thu, 01 Sep 2016 07:23:46 -0700 (PDT) Received: from blr-ubuntu-56.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id o80sm8179651pfa.67.2016.09.01.07.23.41 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Sep 2016 07:23:43 -0700 (PDT) From: Pramod Gurav To: linux-mmc@vger.kernel.org, linux-arm-msm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, ulf.hansson@linaro.org, Pramod Gurav Subject: [PATCH v3] mmc: sdhci-msm: Add pm_runtime and system PM support Date: Thu, 1 Sep 2016 19:53:35 +0530 Message-Id: <20160901142335.2396-1-pramod.gurav@linaro.org> X-Mailer: git-send-email 2.9.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 | 71 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) -- 2.9.3 diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c index 8ef44a2a..0ef4f29 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,61 @@ 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); + int ret; + + ret = sdhci_runtime_suspend_host(host); + if (ret) + return ret; + + 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 sdhci_runtime_resume_host(host); +} +#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, }, };