From patchwork Wed Jan 3 16:06:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liming Sun X-Patchwork-Id: 1882000 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 4T4vnB5F2Tz1ydb for ; Thu, 4 Jan 2024 03:09:50 +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 1rL3oK-0002d1-1c; Wed, 03 Jan 2024 16:09:40 +0000 Received: from mail-mw2nam12on2047.outbound.protection.outlook.com ([40.107.244.47] helo=NAM12-MW2-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 1rL3mb-0001d9-Kb for kernel-team@lists.ubuntu.com; Wed, 03 Jan 2024 16:08:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O8SFzpaOuTzclCyZTe09Rli3nWCW9UIc7PwBFkBRczmq7fhzkes63CwWIMEKRg0Re2xP3VHj07osN0cHObHmiJ+CTKwYTk8fmteM9jcz8hPigFPaR1xgqL4rubSw3li5mBeo644cIyNQrgz5rA/XK1VW7NBsvWsiztNL2grCdSjhY6Rl6e75w7y15+uMyJLCw4dezjSIM2PW8edYFvajCLaL/hjWwq/piUuQdzrdFb03hkgUPbEvI4l6De9zOsjuEiV7xk2PDlKuXK0weMhBy+LI2g+u1nk+CK65ZS90YdgxDD5eLdSiDYSSy/BqudOQIuGoQwhUOXAePC4S1v0Nyw== 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=A9TWjZ/C8QDOOjDGK+9VjEg+UN3dMzT0/KkL4SRzQug=; b=La6uziFo95pLzAg0HxaoU1hzOCfZ+etO2rWMYTp9cwHzOXSOq2RzLY6CGavDfKU46n53cH+Rsj2kVnH4LEQbGcKQsSVAcKzinfAiTbcQyFQUnM+OoGp09OXO90nlHTYr/S1yAKPwWXGJjB1T/934hzFhouLM21y9Qdp5hslPCqloPzzJ8VJ2D6bovdFXwMECiI/k686A2mjMVMy4oIH/WwP3zE1+o8UoltWw7f3kd4iDZOq211KfVHDOUFJuPJanyxcuhoZH/LiPzeQXf0WHXZdRVvacQNdP0x0q4SSN9guLPWUIXsSrDsXrkbEYrcGLUs44c5Ft0UQPHVxOnPOGaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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 DS7PR03CA0223.namprd03.prod.outlook.com (2603:10b6:5:3ba::18) by CY8PR12MB7097.namprd12.prod.outlook.com (2603:10b6:930:51::17) 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 16:07:48 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:5:3ba:cafe::73) by DS7PR03CA0223.outlook.office365.com (2603:10b6:5:3ba::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.25 via Frontend Transport; Wed, 3 Jan 2024 16:07:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) 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 16:07:48 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) 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 08:07:36 -0800 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) 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 08:07:35 -0800 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Wed, 3 Jan 2024 08:07:35 -0800 From: Liming Sun To: Subject: [PATCH v3 7/7] [SRU][J:linux-bluefield][PATCH v3 7/7] mmc: sdhci-of-dwcmshc: Add runtime PM operations Date: Wed, 3 Jan 2024 11:06:59 -0500 Message-ID: <20240103160659.144149-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: CY4PEPF0000EE3A:EE_|CY8PR12MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: 59039990-ee06-44dc-effb-08dc0c76214f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VN25oyc2kVWCbmXPPrRjCKyUxbee3U7b0YOPmvKXhaBy4++at8JgtDWh0QdpFnXuaqLPj4MJTAoh4NvpovlY5jjbizwrQBHoMuWDCMOT5PVsvRUQocDnhkxaIhUGrvbX7zDA1SpRvzFlIoxe+P3QADkrD+D3DuW9HJhFTtTvy8733B1nbWjYGl+2vBhabBrU55+ktnP6/uuYGFiTfys8imK3n6o5VMuqqwYL6AddG3aDmRSjtE+xNny3PwfUzi0Ezw6cwPQ0MQikcsSyy0H11wJNCSsjyPBLkUbGlLktMoG+AS93qOiHb7wZxC4Kv5b6B7QN7N2GQIUc6Ppj8fcpEZUvkRJf5bnXkSg+txRCtLzQunJuIxpasM2dvPjKV4zFvo5FI3Jz1WarZUZ26LnMo1Ja+WBN5aMiwEYoOxlVWDoqzsF+P8RgblV/JcOc/YQ9P7ED4umzg91xi+cHHOC8KT24u3H98D1FNtXmxcMN8QeJVowaB/R0uLQpgNW2hp9mNDZ7f7Be9AjhwCnpLEsgLJFpC3f0kC+95ku+qoRiEPMV3LnfX8VBGe49h4HNAAvl6pONofIf3zQXiBIZXrV3sBnQYgcnNZlirZwU+HpIHMKCJUm/lqVQBrNTBpyDlncdcBFyq4Lrh/YTnIin3CdsQvHxphMOgq802JGyhbtyuUMhx5eVu37zNe7ZrSSo+3ke16br8JHamR9jtHOtEAFyd6aK6X7LPqPexiaRka8taoQMd5QFCMky/yB/w8GXkQec4nmy46p1HHj6DSk75Ld7DSsKNwZL9URaJPx25QOzATCaezc0bhiYAENj/d8cejNd X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(396003)(136003)(376002)(39860400002)(346002)(230922051799003)(451199024)(1800799012)(82310400011)(186009)(64100799003)(36840700001)(40470700004)(46966006)(82740400003)(356005)(7636003)(36756003)(40480700001)(40460700003)(86362001)(7696005)(336012)(6666004)(966005)(83380400001)(47076005)(426003)(478600001)(4326008)(70586007)(70206006)(36860700001)(1076003)(26005)(6916009)(316002)(2616005)(54906003)(8936002)(8676002)(41300700001)(5660300002)(2906002)(133343001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2024 16:07:48.3391 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59039990-ee06-44dc-effb-08dc0c76214f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7097 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" 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 = {