From patchwork Mon Jan 30 07:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 648859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 706F5C54EAA for ; Mon, 30 Jan 2023 07:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjA3Hnx (ORCPT ); Mon, 30 Jan 2023 02:43:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbjA3Hnw (ORCPT ); Mon, 30 Jan 2023 02:43:52 -0500 Received: from mail-m11875.qiye.163.com (mail-m11875.qiye.163.com [115.236.118.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E391633D for ; Sun, 29 Jan 2023 23:43:50 -0800 (PST) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11875.qiye.163.com (Hmail) with ESMTPA id B0E122801DD; Mon, 30 Jan 2023 15:38:19 +0800 (CST) From: Shawn Lin To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, Adrian Hunter , linux-rockchip@lists.infradead.org, Shawn Lin Subject: [PATCH 2/3] mmc: sdhci-of-dwcmshc: Add runtime PM support Date: Mon, 30 Jan 2023 15:38:04 +0800 Message-Id: <1675064285-25425-3-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1675064285-25425-1-git-send-email-shawn.lin@rock-chips.com> References: <1675064285-25425-1-git-send-email-shawn.lin@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJSktLSjdXWS1ZQUlXWQ8JGhUIEh9ZQVkaSEgfVhodTkpMTE8dGB1IH1UTARMWGhIXJB QOD1lXWRgSC1lBWU5DVUlJVUxVSkpPWVdZFhoPEhUdFFlBWU9LSFVKSktISkxVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6M006Txw*MT0PLjgROBI9TSwX MRMKCj9VSlVKTUxOS01PSEtLSElDVTMWGhIXVQgTGgwVVRcSFTsJFBgQVhgTEgsIVRgUFkVZV1kS C1lBWU5DVUlJVUxVSkpPWVdZCAFZQUhNT0o3Bg++ X-HM-Tid: 0a86019cd1392eb1kusnb0e122801dd Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This patch adds runtime PM support. Signed-off-by: Shawn Lin --- drivers/mmc/host/sdhci-of-dwcmshc.c | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index 46b1ce7..951f9e8 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -551,6 +552,13 @@ static int dwcmshc_probe(struct platform_device *pdev) if (err) goto err_setup_host; + 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); + pm_runtime_put_autosuspend(&pdev->dev); + return 0; err_setup_host: @@ -580,6 +588,11 @@ static int dwcmshc_remove(struct platform_device *pdev) if (rk_priv) clk_bulk_disable_unprepare(RK35xx_MAX_CLKS, rk_priv->rockchip_clks); + + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + sdhci_pltfm_free(pdev); return 0; @@ -636,9 +649,42 @@ static int dwcmshc_resume(struct device *dev) return sdhci_resume_host(host); } + +static int dwcmshc_runtime_suspend(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + u16 data; + int ret; + + ret = sdhci_runtime_suspend_host(host); + if (ret) + return ret; + + data = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + data &= ~SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, data, SDHCI_CLOCK_CONTROL); + + return 0; +} + +static int dwcmshc_runtime_resume(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + u16 data; + + data = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + data |= SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, data, SDHCI_CLOCK_CONTROL); + + return sdhci_runtime_resume_host(host, 0); +} #endif -static SIMPLE_DEV_PM_OPS(dwcmshc_pmops, dwcmshc_suspend, dwcmshc_resume); +static const struct dev_pm_ops dwcmshc_pmops = { + SET_SYSTEM_SLEEP_PM_OPS(dwcmshc_runtime_suspend, + dwcmshc_runtime_resume) + SET_RUNTIME_PM_OPS(dwcmshc_suspend, dwcmshc_resume, NULL) +}; static struct platform_driver sdhci_dwcmshc_driver = { .driver = { From patchwork Mon Jan 30 07:38:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 648858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF94FC636CB for ; Mon, 30 Jan 2023 07:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbjA3Hny (ORCPT ); Mon, 30 Jan 2023 02:43:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbjA3Hnw (ORCPT ); Mon, 30 Jan 2023 02:43:52 -0500 Received: from mail-m11875.qiye.163.com (mail-m11875.qiye.163.com [115.236.118.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7403E166D8 for ; Sun, 29 Jan 2023 23:43:50 -0800 (PST) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11875.qiye.163.com (Hmail) with ESMTPA id AFB76280238; Mon, 30 Jan 2023 15:38:25 +0800 (CST) From: Shawn Lin To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, Adrian Hunter , linux-rockchip@lists.infradead.org, Shawn Lin Subject: [PATCH 3/3] mmc: sdhci-of-dwcmshc: Add host software queue support Date: Mon, 30 Jan 2023 15:38:05 +0800 Message-Id: <1675064285-25425-4-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1675064285-25425-1-git-send-email-shawn.lin@rock-chips.com> References: <1675064285-25425-1-git-send-email-shawn.lin@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJSktLSjdXWS1ZQUlXWQ8JGhUIEh9ZQVkaGUtMVhgdSE8eT0lITEIeTFUTARMWGhIXJB QOD1lXWRgSC1lBWU5DVUlJVUxVSkpPWVdZFhoPEhUdFFlBWU9LSFVKSktISkxVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PBQ6Lww*Az0IUTgBAhxITS4t NCkaCjNVSlVKTUxOS01PSEtNSUhNVTMWGhIXVQgTGgwVVRcSFTsJFBgQVhgTEgsIVRgUFkVZV1kS C1lBWU5DVUlJVUxVSkpPWVdZCAFZQUhMQ0g3Bg++ X-HM-Tid: 0a86019ce8a52eb1kusnafb76280238 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Signed-off-by: Shawn Lin --- drivers/mmc/host/sdhci-of-dwcmshc.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index 951f9e8..516f74a 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -20,6 +20,7 @@ #include #include "sdhci-pltfm.h" +#include "mmc_hsq.h" #define SDHCI_DWCMSHC_ARG2_STUFF GENMASK(31, 16) @@ -331,6 +332,14 @@ static void rk35xx_sdhci_reset(struct sdhci_host *host, u8 mask) sdhci_reset(host, mask); } +static void sdhci_dwcmshc_request_done(struct sdhci_host *host, struct mmc_request *mrq) +{ + if (mmc_hsq_finalize_request(host->mmc, mrq)) + return; + + mmc_request_done(host->mmc, mrq); +} + static const struct sdhci_ops sdhci_dwcmshc_ops = { .set_clock = sdhci_set_clock, .set_bus_width = sdhci_set_bus_width, @@ -347,6 +356,7 @@ static const struct sdhci_ops sdhci_dwcmshc_rk35xx_ops = { .get_max_clock = sdhci_pltfm_clk_get_max_clock, .reset = rk35xx_sdhci_reset, .adma_write_desc = dwcmshc_adma_write_desc, + .request_done = sdhci_dwcmshc_request_done, }; static const struct sdhci_pltfm_data sdhci_dwcmshc_pdata = { @@ -462,6 +472,7 @@ static int dwcmshc_probe(struct platform_device *pdev) struct dwcmshc_priv *priv; struct rk35xx_priv *rk_priv = NULL; const struct sdhci_pltfm_data *pltfm_data; + struct mmc_hsq *hsq; int err; u32 extra; @@ -515,6 +526,16 @@ static int dwcmshc_probe(struct platform_device *pdev) host->mmc_host_ops.request = dwcmshc_request; host->mmc_host_ops.hs400_enhanced_strobe = dwcmshc_hs400_enhanced_strobe; + hsq = devm_kzalloc(&pdev->dev, sizeof(*hsq), GFP_KERNEL); + if (!hsq) { + err = -ENOMEM; + goto err_clk; + } + + err = mmc_hsq_init(hsq, host->mmc); + if (err) + goto err_clk; + if (pltfm_data == &sdhci_dwcmshc_rk35xx_pdata) { rk_priv = devm_kzalloc(&pdev->dev, sizeof(struct rk35xx_priv), GFP_KERNEL); if (!rk_priv) { @@ -607,6 +628,8 @@ static int dwcmshc_suspend(struct device *dev) struct rk35xx_priv *rk_priv = priv->priv; int ret; + mmc_hsq_suspend(host->mmc); + ret = sdhci_suspend_host(host); if (ret) return ret; @@ -647,7 +670,11 @@ static int dwcmshc_resume(struct device *dev) return ret; } - return sdhci_resume_host(host); + ret = sdhci_resume_host(host); + if (ret) + return ret; + + return mmc_hsq_resume(host->mmc); } static int dwcmshc_runtime_suspend(struct device *dev)