From patchwork Thu Sep 1 10:10:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 9308745 X-Patchwork-Delegate: agross@codeaurora.org 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 0214B60865 for ; Thu, 1 Sep 2016 10:11:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E708A2923A for ; Thu, 1 Sep 2016 10:11:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBA87292D8; Thu, 1 Sep 2016 10:11:30 +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=unavailable 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 681A62923A for ; Thu, 1 Sep 2016 10:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754112AbcIAKL1 (ORCPT ); Thu, 1 Sep 2016 06:11:27 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:33685 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751340AbcIAKLE (ORCPT ); Thu, 1 Sep 2016 06:11:04 -0400 Received: by mail-pf0-f171.google.com with SMTP id g202so6854572pfb.0 for ; Thu, 01 Sep 2016 03:10:29 -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=N4m3qPs4/sTz0C52hLB+/2O38HDKSwx6OPeu7DUBHAw=; b=fciMvGI+Pd4sr9AK8JAEN+TCic6w4Ii+SN0ggWW3iVHGq+ilvO0RUDpzn9QyjZa093 F1yTIs34eKVM94XZ9hvBHV3w2wldmyajJP6ev3B8jbImvPbppnygWqpday6Ap8dc4vZE x0GyhMi0CQzIuK8Zylw4zh08z+Z1FY0DlugF4= 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=N4m3qPs4/sTz0C52hLB+/2O38HDKSwx6OPeu7DUBHAw=; b=JaRKs4BtBHJaH7TRE1neSTOTL+CKZbvzz7MR0SPWdDJgn9TaMYZlwUD3xR4UVdCL+Z LC22vMESH7Sjos002ZRshfhskf09/NTWxYDi6WioSOkL90VDcJmB1LKTY8MgTZCkCqQG hHFYHCjHhuf5LgkE9s7WrRYjklwpvHasbMEteuFWbPHTQT6VWOjcQLZ/2w5Yvk5eKXB3 nh/BB/CZjR0B8Sp5+V2LKxCoOTvKdEB5jHVefu7L1w+EwZyhiXezeBrm6CQSUytpX3hJ UM0Z3079Nil2a1mBFl5Kd5TQidE4uc4X6+3letUFdkFgnQ6xzUBJL/Ceyt7ZxatxDJkg uEkw== X-Gm-Message-State: AE9vXwMr6t0FZW/Hnn8yT/NIeOEA9eQsqjZBEuQqsovIrporNEgUkgmNTmz7q505asanlVbO X-Received: by 10.98.6.68 with SMTP id 65mr9441263pfg.116.1472724629236; Thu, 01 Sep 2016 03:10:29 -0700 (PDT) Received: from blr-ubuntu-56.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id y200sm6297970pfb.13.2016.09.01.03.10.26 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Sep 2016 03:10:28 -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 v2] mmc: sdhci-msm: Add pm_runtime and system PM support Date: Thu, 1 Sep 2016 15:40:21 +0530 Message-Id: <20160901101021.26371-1-pramod.gurav@linaro.org> X-Mailer: git-send-email 2.9.3 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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. Signed-off-by: Pramod Gurav --- 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 | 82 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c index 8ef44a2a..8273a71 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,72 @@ static int sdhci_msm_remove(struct platform_device *pdev) return 0; } +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); +} + +static int sdhci_msm_suspend(struct device *dev) +{ + pm_runtime_force_suspend(dev); + + return 0; +} + +static int sdhci_msm_resume(struct device *dev) +{ + pm_runtime_force_resume(dev); + + return 0; +} + +static const struct dev_pm_ops sdhci_msm_pm_ops = { + SET_LATE_SYSTEM_SLEEP_PM_OPS(sdhci_msm_suspend, sdhci_msm_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, }, };