From patchwork Wed Jan 3 18:32:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liming Sun X-Patchwork-Id: 1882170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T4z0Y5j2Qz1yQ5 for ; Thu, 4 Jan 2024 05:34:53 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rL64j-0003j3-WE; Wed, 03 Jan 2024 18:34:46 +0000 Received: from mail-bn7nam10on2043.outbound.protection.outlook.com ([40.107.92.43] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rL63W-0002tD-JR for kernel-team@lists.ubuntu.com; Wed, 03 Jan 2024 18:33:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Le+33312erUzvW/LdEyfHVA276A+hdzZmkCTJQ1qTBRvdIRijM6Zwz0yEiILoxlNrec9VsL2luaexJtkCidt0OcP8oc62sZWn+xwzKtsPDj+VTYU6iXDKsdjNw7alxU3YcCw7nKhdZQvAE4rrLjwUBLhOuOgSA1hX2dqaJtxUhWHymh90dnM2WbBRVtcZc23YtUmgB1ZiMZFwTP+U38kN35kjp63iMw4SAC255wk4D1bDPV1ucUHb92tKc8UTGr+jtOWMMfqhkjpb4n7rTBn4rNJ2HV1ofm0Ayx8jPROOmGxWCUsy4ME2MqFasqCR6vxg51Rh6f/30c8vnXguKMiYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6Vei0exMdG1pgxtJgQQGI5Ldrc6EiSEkeNFEunlLGS0=; b=LedYNmrQOVpIP21zwR1rgZii/Wc98+05DPjBtBKMexghePdN+S+7rtpSljOHg07cRtWlMwgFvEZK/2kc9nGs2uBlBwwGKD+Mer0qlx4bz0VKRva/65e6gZrOKHvwDbt5TOxxwfJRoAV/0nowHpJzTx2bnfpzWJo5MdBwUrzYfUeAi5yT+ltvvYSgNgF+c95tIJmOvY+cYUVO6YAr7cabyaPJBHvempXy7eIHDeiTOp24UoRp8OiURarBZI71ezW3ftaHQElVFEhNlfH7ynVk6g0OeIJvRVNyoY7iY9yiQVzMpwwtK3ygf3Ifak7CjwHyGYcKaVxMLdaA379T14txGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from BYAPR06CA0038.namprd06.prod.outlook.com (2603:10b6:a03:14b::15) by IA0PR12MB7580.namprd12.prod.outlook.com (2603:10b6:208:43b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.25; Wed, 3 Jan 2024 18:33:26 +0000 Received: from DS3PEPF000099E2.namprd04.prod.outlook.com (2603:10b6:a03:14b:cafe::d1) by BYAPR06CA0038.outlook.office365.com (2603:10b6:a03:14b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.20 via Frontend Transport; Wed, 3 Jan 2024 18:33:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DS3PEPF000099E2.mail.protection.outlook.com (10.167.17.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.9 via Frontend Transport; Wed, 3 Jan 2024 18:33:26 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 3 Jan 2024 10:33:11 -0800 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 3 Jan 2024 10:33:10 -0800 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Wed, 3 Jan 2024 10:33:10 -0800 From: Liming Sun To: Subject: [SRU][J:linux-bluefield][PATCH v4 7/7] mmc: sdhci-of-dwcmshc: Add runtime PM operations Date: Wed, 3 Jan 2024 13:32:50 -0500 Message-ID: <20240103183250.215811-8-limings@nvidia.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <7315e47661ea7ae98ccffaee3c4d921c8de7ef07.1702924774.git.limings@nvidia.com> References: <7315e47661ea7ae98ccffaee3c4d921c8de7ef07.1702924774.git.limings@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E2:EE_|IA0PR12MB7580:EE_ X-MS-Office365-Filtering-Correlation-Id: 297456b0-c0bc-440a-1c09-08dc0c8a7983 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7H7c2oxqrIl8ZKeAxk130+VsE3pmF5gtPW7Lthft6WobdLyyH1QpMaw32VvVfZdGrNuQ1mxhTDfq9A7Mp1atR+aF2Yw3TyyXd8fGrD1KV/Htb4tgzZ7DLKOM00p5G5+cyzo55ALNFQebCYBLaF9qlKP5C1TiAw63ZiqjxkeHJSs7HMs++HHl8HBCa9i2h3l+9586AvGZl8+4m0BIinqOqUc8A1n8bopOG3veNkgIXSC2EXKEJZ8RU5jSWqz9zj9MO7Foo8pwRks617Wc0YxEhTxnPIxvkIsdOapS6BDLo/hmRF0RTgrmtD4HKYm8fl2NSm05SofUkQY4FfidRCvwaaomRCO9xUWWyknrxdzYXd/hSjJ4C3RE/TJmjHqRIeopY2Um+L9eOuaxEvQ83tlfnlRZlfxsnALrsfi+sAJ2ETSXF9JGI+2iautYlpPvpUSedBZ5lKxuilklvi7OZM0FSIvYbW2WMEJVpIAv4gu6KCoINftM5jhSlrcwnpzM+450LW1TMnnttxaKVk93NYazce1vvpi7LID5HfIUdYrYv8BOLKGuDJ4c5AhEZraJqwoDp5LGCZoY7tnOAIRNB7KhWfFhM9ssRcN+VT7quGBkBN1xqCnmV7S/DFahO7yjD7sgk/1fxcRCzrNFMDMcOV4/VWI/zwZAD0JGk4TVHi3cYGmON4vwgqtL+al/MjOoiPhMzVymAQnRuMEpyWrxAUbj5A9I+PuI1FlY+9jdRKjjmOv6RHJh80UN53hLDuQFjmPgzDi3jniApPVz5O4VQSj/h5iRtNDp9jW9Y/jvyQi9cOQ= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(39860400002)(376002)(396003)(346002)(230922051799003)(1800799012)(64100799003)(82310400011)(186009)(451199024)(40470700004)(46966006)(36840700001)(40460700003)(40480700001)(426003)(336012)(83380400001)(1076003)(26005)(36756003)(86362001)(6666004)(7636003)(82740400003)(356005)(8676002)(4326008)(41300700001)(47076005)(8936002)(5660300002)(54906003)(2616005)(7696005)(36860700001)(70586007)(70206006)(316002)(6916009)(478600001)(966005)(2906002)(133343001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2024 18:33:26.1860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 297456b0-c0bc-440a-1c09-08dc0c8a7983 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7580 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Sun , Ulf Hansson , David Thompson , Adrian Hunter Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2046657 This commit implements the runtime PM operations to disable eMMC card clock when idle. Reviewed-by: David Thompson Signed-off-by: Liming Sun Acked-by: Adrian Hunter Link: https://lore.kernel.org/r/20230822195929.168552-2-limings@nvidia.com Signed-off-by: Ulf Hansson (cherry picked from commit 48fe8fadbe5e03edfd83315c331b171a9ae245a4) Signed-off-by: Liming Sun --- drivers/mmc/host/sdhci-of-dwcmshc.c | 73 +++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index bb0fe18be5dc..689a297c10ca 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -461,12 +463,27 @@ static int dwcmshc_probe(struct platform_device *pdev) host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; - err = sdhci_add_host(host); + 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; + + err = __sdhci_add_host(host); + if (err) + goto err_setup_host; + + pm_runtime_put(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); @@ -506,6 +523,8 @@ static int dwcmshc_suspend(struct device *dev) struct rk35xx_priv *rk_priv = priv->priv; int ret; + pm_runtime_resume(dev); + ret = sdhci_suspend_host(host); if (ret) return ret; @@ -565,7 +584,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 = {