Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5483070rwb; Wed, 9 Aug 2023 05:05:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE83CMoFS9HLo6hfvnS3sfHYUiTYo+0YsEQ1PohRkRzwBPlxflqDQ9afLk39N5HItpKb5C8 X-Received: by 2002:a05:6a00:2d91:b0:687:2cba:67ad with SMTP id fb17-20020a056a002d9100b006872cba67admr16444511pfb.2.1691582752577; Wed, 09 Aug 2023 05:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691582752; cv=none; d=google.com; s=arc-20160816; b=XKYL7ZWSEVV5liRm6m748WcRF+P5y3T56LXWCPQi7gGP2/l5Qc15xbGXro5pzw5cwD rqKViib93rQK0vGRejDiKmzqU4o+t8o2KCgpoVhxbkMUog8n31qvm0jz/OP3QhfNAbJk FBSQHrqYT6x2o9jMKB2Tyodxqq6DYgE435PDVmTzC34pCfGMLAazQdYPDNwKzCBgKFLa 3V7VP8RCuGCAz+qpZH7E6JBpKVJuGupRjReMIM/I/+YKCOS8aZoSExhTFvoX6gRM+jG4 eMBWtVTbgAvIhHDQsx3DYJSBS5+r9BXCQbadsvRtnFGijZQteMNMoNmuBd/6uXEDj6F/ mDGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=iaYB/Ipn2a2m2D4N0I3VurARbvsG5OxcIS7VBhxmako=; fh=XUSfRY3ouCIumy+/umx5Y8UqIVKkZHTDmbuDH29dsWk=; b=Eu0FNjBE55b8OnRMhYgoMVG425C9CZwQeZDjGPnYpfnvzsu6CZnxgl6Ew9YuAS0u/A NiIeCm8jvRpF+1gwV+0lgoiiy9+Smvn0IgX2vRbe1sEzN4rVoOjlPHumzq+V8tIBnBRo rt+yittte/7IjRIccSvmi1hVjxYg7kwxxbzfX+smeuWWcNVEh6KabGtOCG/vnJGarPuV DQemBqjXtes15L4ZWxVm/wXWkOyTrDdcXFWn1gM2CNwmsQw5Ek4B4QpLDRBc0SCHzumd 74lFtooVMxD/xZ2/lwzS6dqOjQXDrbgl4Nm0+E9PTocHYDBqKsepkvhoPiOMAfEQ7VAy hPGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d4VL+01T; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca20-20020a056a02069400b00565307ee53bsi1797646pgb.439.2023.08.09.05.05.36; Wed, 09 Aug 2023 05:05:52 -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=@linaro.org header.s=google header.b=d4VL+01T; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232819AbjHIK71 (ORCPT + 99 others); Wed, 9 Aug 2023 06:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbjHIK7Z (ORCPT ); Wed, 9 Aug 2023 06:59:25 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CB1DED for ; Wed, 9 Aug 2023 03:59:24 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-585fd99ed8bso11075317b3.1 for ; Wed, 09 Aug 2023 03:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691578764; x=1692183564; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iaYB/Ipn2a2m2D4N0I3VurARbvsG5OxcIS7VBhxmako=; b=d4VL+01TABHXmsF/sknTHW8Rix2EH/NZaxjVqxatJUJtf08r7M+zh6yn+PA1us+AzV z3awp9BTZ2SGvAVHohC08w9xi18NAqlf+RppMRyqUQK0mLFwDujbuBKRT0tgpXbVWIke aq848fTgmA1SRmqy3cqqq14DDujIjW1G1iBJYQV53M0VYtgCxQNpMG+07HJCgi7gvKgS Kj/yC+kHVl8mfSdUD8fMH6jZMGo0/Qw4Z8dGgDVkeUoKILysPjl5CydscQykfuKaTwrL Ighftu4Ff/D7o+4a/6brj1dWeuOz5Csxqp1h3BZ0aOmOEM8fg8RHIt1RvZbXwNpit3tQ rOPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691578764; x=1692183564; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iaYB/Ipn2a2m2D4N0I3VurARbvsG5OxcIS7VBhxmako=; b=Sn3EKqDfn3CPI7GoA+DfyTpFMkdPxI/syK7HE7qAZo4uGGWWDezq0k6R3RBGrUxeJ2 09ixEcH0dbJOist51iY1kMi538Kjb3bX3l20Kn1cr5gjhjN5oXbbwSYCr1rQHKzpB4JP 9GQTKdlEUd7y8Wy647udfc0tTpIRdz9T39q9oVCieee9IG7GCvgzn5LRqn22EGBgUsZR AmRngJgyHiTM4eW5W1eQXvlSUE/hYv0UFQoq3eQFjsRSPPBIcwSn7m5CeEGItdH0jAIS FtQwvGvr7ZcQAnBl4af4hMybEQgpCEko4FBLc1A79vEEzNnq6c0kjg42/dw/Ency/MHj QDyg== X-Gm-Message-State: AOJu0YzkawTQJ4J/hvbvy7gRmlrd3i01zsevLfrL1a4XloupKLMK1hwu ZHiNsdB/iCLrzK1nTMBFR0AWTx9x4TB+TZF8R9ciQw== X-Received: by 2002:a0d:cb52:0:b0:577:186c:2a3c with SMTP id n79-20020a0dcb52000000b00577186c2a3cmr11621366ywd.19.1691578763825; Wed, 09 Aug 2023 03:59:23 -0700 (PDT) MIME-Version: 1.0 References: <79137159a833c164ea8ea3f05d8d6d9537db2f42.1683747334.git.limings@nvidia.com> <20230804233015.173957-1-limings@nvidia.com> In-Reply-To: <20230804233015.173957-1-limings@nvidia.com> From: Ulf Hansson Date: Wed, 9 Aug 2023 12:58:47 +0200 Message-ID: Subject: Re: [PATCH v6] mmc: sdhci-of-dwcmshc: Add runtime PM operations To: Liming Sun Cc: Adrian Hunter , David Thompson , Shawn Lin , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 Sat, 5 Aug 2023 at 01:30, 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 > --- > v5->v6: > - Address Adrian's more comments and add coordination between > runtime PM and system PM; > 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 | 72 ++++++++++++++++++++++++++++- > 1 file changed, 70 insertions(+), 2 deletions(-) > > diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c > index e68cd87998c8..aaf66358f626 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 > > @@ -548,9 +549,13 @@ static int dwcmshc_probe(struct platform_device *pdev) > > host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; > > + 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); > @@ -559,10 +564,15 @@ static int dwcmshc_probe(struct platform_device *pdev) > 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); > @@ -606,6 +616,12 @@ static int dwcmshc_suspend(struct device *dev) > if (ret) > return ret; > sdhci_suspend_host() is called a few lines above, which requires the host to be runtime resumed when called. This may not be the case here. To fix this there are in principle two options: 1) Call a pm_runtime_get_sync() around here and a corresponding pm_runtime_put_noidle() somewhere after you have called pm_runtime_force_suspend(). 2) Move away from using sdhci_suspend|resume_host(), but use sdhci_runtime_suspend|resume_host() instead. This requires some additional changes, but with the benefit that we can avoid runtime resuming the device upfront. In this case, sdhci_runtime_suspend|resume_host() should be called from dwcmshc_runtime_suspend|resume(). Moreover, we either need to move the entire clock mgmt from dwcmshc_suspend|resume() into the dwcmshc_runtime_suspend|resume() or call pm_runtime_get_noresume() before calling pm_runtime_force_suspend() and pm_runtime_put_noidle() just after it. > + ret = pm_runtime_force_suspend(dev); > + if (ret) { > + sdhci_resume_host(host); > + return ret; > + } > + > clk_disable_unprepare(pltfm_host->clk); > if (!IS_ERR(priv->bus_clk)) > clk_disable_unprepare(priv->bus_clk); > @@ -625,6 +641,10 @@ static int dwcmshc_resume(struct device *dev) > struct rk35xx_priv *rk_priv = priv->priv; > int ret; > > + ret = pm_runtime_force_resume(dev); > + if (ret) > + return ret; > + > ret = clk_prepare_enable(pltfm_host->clk); > if (ret) > return ret; > @@ -646,7 +666,55 @@ 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); > + 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); > + 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); > + > + dwcmshc_disable_card_clk(host); > + > + return 0; > +} > + > +static int dwcmshc_runtime_resume(struct device *dev) > +{ > + struct sdhci_host *host = dev_get_drvdata(dev); > + > + dwcmshc_enable_card_clk(host); > + > + return 0; > +} > + > +#endif > + > +static const struct dev_pm_ops dwcmshc_pmops = { > + SET_SYSTEM_SLEEP_PM_OPS(dwcmshc_suspend, dwcmshc_resume) > + SET_RUNTIME_PM_OPS(dwcmshc_runtime_suspend, > + dwcmshc_runtime_resume, NULL) > +}; > > static struct platform_driver sdhci_dwcmshc_driver = { > .driver = { Kind regards Uffe