Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5885703rwb; Tue, 1 Aug 2023 09:10:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFIyFMlE06NNzDRIs1trzSDuvJP7/UGu5aOwQF3OHYOfEiEglij+20cHjCDLBmVJfgaapdO X-Received: by 2002:a17:902:b7c8:b0:1bb:b226:52a0 with SMTP id v8-20020a170902b7c800b001bbb22652a0mr10697592plz.44.1690906199951; Tue, 01 Aug 2023 09:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690906199; cv=none; d=google.com; s=arc-20160816; b=WvbRF3zR9SG/rfy/5RRK7ZUbI8EcYMZ9B0cZ7nU04u23lfTvadg3Ch8daApLT9EdK5 n7T1FHSv/1zovB1pb/vNHhch5ZCea6g7fBA0/8Pj6TwZfGzG9sXks3XMw93zSme5tHMz FECDOXi0/d3F9eoY13XetgTfctsw4h6AHC+SGHhQcE0UYSjMd5+v19ZnSSWhv6qQNi5m JcKlWuaXuAYf+jcLD658vkRh0Iq82HSG/Zs6VN1jZ6k2EsTaGBBJ1cspJzegmF/lRZ0R F191BZz0IfGgE1REXqtegH9prxbPu4wAL5wtff5PNpLtHdjkCEluSUoZAJsWjsgEjdHV Pn3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=ORn24FSmg01xnlmsGB4n+Q4GpwFokv2P5zW02tnmM7g=; fh=1x8Rw/wnMpO4ADsrSW9RyJCZgfDR0zA1B7jyFw19Bss=; b=Ym/7LzUgz0/EBgSB6TfPlrXP4ZWNyw/Y+4//LZCYs3xaaYk3xiEyyN9XdjaDg3e3nt hM7caImiLf1WAxSckQ+X9oVmDqpy/nvRkRYsbd9l9Dfr7zYdnvpYS8RAmxm5OEdPIkAp fDDvwdy+HadEuQDSB6Fxh5fqNh193eRx5Tgqmp4fQILMKiV0RFwf9H3synZydkmp4Xt1 KZ6Lme10qHYzlS1U+SbY39j5DQDvfYy4QdNetRJzvVtBwYwbUHaU/TFrcxlakkpvNls6 OpfXRMLIbfbIWVfBnmmiL1kL+ABIaJfXnwc0lyJw0OhP6wnBjcep/AO2qaDbmvrA/SmV 5Lbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HcmnZlDa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a170902a3c600b001b9ce7a85cbsi9214207plb.281.2023.08.01.09.09.40; Tue, 01 Aug 2023 09:09:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HcmnZlDa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234145AbjHAPgw (ORCPT + 99 others); Tue, 1 Aug 2023 11:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234141AbjHAPgu (ORCPT ); Tue, 1 Aug 2023 11:36:50 -0400 Received: from mgamail.intel.com (unknown [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E878E1B0; Tue, 1 Aug 2023 08:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690904209; x=1722440209; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=NkcmWqH8lFlBt8JVs8Fywn256uGO6JM0+7urScRc4+c=; b=HcmnZlDasiGeZ3F0q7F5Ur5xOe/ocoHmnT071UI/vU/hEQ7svbYVotG7 ydzlYx5ttZmRMl2eI0+mcQn4BTbIRmaNs3/kVhw6BrCYz3Jy72gJVzxoU vLXwdA2Da9wMXULMXfL9agIi/XS3JXeVPoOc2FM2Hg2J/fSKHGFUgWylN zBboh8wt40ipHXDhziaFrOmGsV9G8OWHuJK5AProsk4zY7ML8DtUYbXWd E5phDMP6QGmb+ALYS9ah0jjTSvQ/PNtAuEl6ZLoYQdHaQOJKBuhfowH7g emLDL5Gm+jiSiH7VbGn3qK2p6Qv7yM8G2x5KWJwk6vfhTfLeaCVL5rkFy g==; X-IronPort-AV: E=McAfee;i="6600,9927,10789"; a="435657872" X-IronPort-AV: E=Sophos;i="6.01,247,1684825200"; d="scan'208";a="435657872" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2023 08:36:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10789"; a="794237498" X-IronPort-AV: E=Sophos;i="6.01,247,1684825200"; d="scan'208";a="794237498" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.249.38.126]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Aug 2023 08:36:46 -0700 Message-ID: Date: Tue, 1 Aug 2023 18:36:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.13.1 Subject: Re: [PATCH v5] mmc: sdhci-of-dwcmshc: Add runtime PM operations Content-Language: en-US To: Liming Sun , Ulf Hansson , David Thompson , Shawn Lin Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org References: <79137159a833c164ea8ea3f05d8d6d9537db2f42.1683747334.git.limings@nvidia.com> <20230728122052.296488-1-limings@nvidia.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <20230728122052.296488-1-limings@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/07/23 15:20, Liming Sun wrote: > This commit implements the runtime PM operations to disable eMMC > card clock when idle. > > Reviewed-by: David Thompson > Signed-off-by: Liming Sun > --- > v4->v5: > - Address Adrian's comment to move the pm_enable to the end to > avoid race; > v3->v4: > - Fix compiling reported by 'kernel test robot'; > v2->v3: > - Revise the commit message; > v1->v2: > Updates for comments from Ulf: > - Make the runtime PM logic generic for sdhci-of-dwcmshc; > v1: Initial version. > --- > drivers/mmc/host/sdhci-of-dwcmshc.c | 54 ++++++++++++++++++++++++++++- > 1 file changed, 53 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c > index e68cd87998c8..5cee42d72257 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 > > @@ -559,6 +560,8 @@ static int dwcmshc_probe(struct platform_device *pdev) > if (err) > goto err_setup_host; > > + devm_pm_runtime_enable(dev); By default, runtime PM regards the device as not active, so typically drivers will use something like pm_runtime_set_active() prior to pm_runtime_enable(dev) In fact it is better to enable before adding the host but increment the usage count to prevent runtime suspend. That means adding some get/puts, ending up with something like: + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); err = sdhci_setup_host(host); if (err) - goto err_clk; + goto err_rpm; if (rk_priv) dwcmshc_rk35xx_postinit(host, priv); err = __sdhci_add_host(host); if (err) goto err_setup_host; + pm_runtime_put_sync(dev); return 0; err_setup_host: sdhci_cleanup_host(host); + err_rpm: + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); err_clk: clk_disable_unprepare(pltfm_host->clk); clk_disable_unprepare(priv->bus_clk); if (rk_priv) clk_bulk_disable_unprepare(RK35xx_MAX_CLKS, rk_priv->rockchip_clks); free_pltfm: sdhci_pltfm_free(pdev); return err; > + > return 0; > > err_setup_host: > @@ -646,7 +649,56 @@ static int dwcmshc_resume(struct device *dev) > } > #endif > > -static SIMPLE_DEV_PM_OPS(dwcmshc_pmops, dwcmshc_suspend, dwcmshc_resume); > +#ifdef CONFIG_PM > + > +static void dwcmshc_enable_card_clk(struct sdhci_host *host) > +{ > + u16 ctrl; > + > + ctrl = sdhci_readw(host, SDHCI_CLOCK_CONTROL); You could save an mmio write: if (ctrl & SDHCI_CLOCK_INT_EN && !(ctrl & SDHCI_CLOCK_CARD_EN)) { > + ctrl |= SDHCI_CLOCK_CARD_EN; > + sdhci_writew(host, ctrl, SDHCI_CLOCK_CONTROL); } > +} > + > +static void dwcmshc_disable_card_clk(struct sdhci_host *host) > +{ > + u16 ctrl; > + > + ctrl = sdhci_readw(host, SDHCI_CLOCK_CONTROL); You could save an mmio write: if (ctrl & SDHCI_CLOCK_CARD_EN) { > + ctrl &= ~SDHCI_CLOCK_CARD_EN; > + sdhci_writew(host, ctrl, SDHCI_CLOCK_CONTROL); } > +} > + > +static int dwcmshc_runtime_suspend(struct device *dev) > +{ > + struct sdhci_host *host = dev_get_drvdata(dev); > + int ret = 0; ret doesn't need initialization > + > + ret = sdhci_runtime_suspend_host(host); If you *only* want to disable the card clock, then it is probably not necessary to call sdhci_runtime_suspend_host() and sdhci_runtime_resume_host(). > + if (!ret) > + dwcmshc_disable_card_clk(host); > + > + return ret; > +} > + > +static int dwcmshc_runtime_resume(struct device *dev) > +{ > + struct sdhci_host *host = dev_get_drvdata(dev); > + int ret = 0; ret isn't needed > + > + dwcmshc_enable_card_clk(host); > + ret = sdhci_runtime_resume_host(host, 0); just return sdhci_runtime_resume_host(host, 0); > + > + return ret; > +} > + > +#endif > + > +static const struct dev_pm_ops dwcmshc_pmops = { > + SET_SYSTEM_SLEEP_PM_OPS(dwcmshc_suspend, dwcmshc_resume) Typically you need a way to coordinate runtime PM and system PM, refer: https://www.kernel.org/doc/html/latest/power/runtime_pm.html#runtime-pm-and-system-sleep > + SET_RUNTIME_PM_OPS(dwcmshc_runtime_suspend, > + dwcmshc_runtime_resume, NULL) > +}; > > static struct platform_driver sdhci_dwcmshc_driver = { > .driver = {