From patchwork Tue Apr 4 23:30:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liming Sun X-Patchwork-Id: 1765239 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=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=ChDr1179; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (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 4PrkXG0rp4z1yYs for ; Wed, 5 Apr 2023 09:30:38 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pjq6j-00053M-20; Tue, 04 Apr 2023 23:30:33 +0000 Received: from mail-dm6nam10on2065.outbound.protection.outlook.com ([40.107.93.65] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pjq6g-00052X-Cs for kernel-team@lists.ubuntu.com; Tue, 04 Apr 2023 23:30:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LfxAIS4g3ImQaBEHZLwy6Lv8uOay2EyLBsDducIQSn4NHjmT76L8wfXVcOswUdJsmiwhB+CuInFOcWrU5XtT04PWAN51gbj0fShVPUA/y+dJoRxccYj421e4pUgrYeGgox1QBLvF0zDMgwTVbttLcB2d+xj4V/lEDEw0d+vSoV8sCRgdtduOw8Oh1PhbNAFItkLjHbCzMLQUsNFl6ZKH2Q9dyL+JA2rSOcHEWogkuP1PWZdcfTCbcPSVI9wW37baN2oopUy9irNwPtPY4FTMChRAKJSnXJM6gB4DEz5AU7xyYJ6eiroy1EU8AjUQ/INxCWOaQOAjetGK/pO6EuawZg== 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=6xigxLFYrNSLyhPqKJYFqHfI0WUIxOPVTxFGQjEvWwQ=; b=TT3zOyiNiSP2WoDv8jhBR7Mo01lNsqOpa+qqUwJal5MP3vmDZyEcc93e1kCx0DCaBW5bvQ+C+QtrzDSwDzpyxylDRpQln5iG13PjPpwLnVu5pUH9vFDGVroKhCGbQyQSaBw5Kcwl9CrplrBe1b9IpRw3LLKIBc5vChhV5tBrmIZgwmGXsSbwpMPIGJs20jar8oR9NSII7ZETtiQ28X9afmJWyUIvB35MPP4UMMBnaZcINSBFlZEw0yZyCuNQYjR8tP+wDeO3qS66xe3Gn5L8wXIQyXAA67Fca7vfWzOM81mywwA2tESQgijyE7AghH8tyyY32Q3gThDhuzcTUAZX+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6xigxLFYrNSLyhPqKJYFqHfI0WUIxOPVTxFGQjEvWwQ=; b=ChDr1179TFOkEBIwHlIMZnbxhP+3BZSMtiiMUBi5BU1gSHfM/mv7a/ApxhMU7C5VR+/P7F+p224e8eta17/zdzrJ1UwFeCpRRvMM9shpn6fuHLj/I7mChshB9KWTNwZwLc0pzhjN71TP4ycIT8BhLoj7gDTiiNWEWEqNX8ary5VZW1w6XVgawg+NX5NGYgbLAS1RVe1yuPHhA4HcCTIaU++poZZyBjwW7m5C7GZUeIZlp27+jnWuglD/ovZGcvLisKZ9++0JXV9wyrjl92n7IqYMO7jJehQDmdpVSRZu5CVKQ4ZgOdPM2eAjWFz00k86VTqCjAsAvuls5vZbTSTMDg== Received: from MW4P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::30) by SJ2PR12MB8954.namprd12.prod.outlook.com (2603:10b6:a03:541::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 4 Apr 2023 23:30:28 +0000 Received: from CO1NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8b:cafe::c2) by MW4P221CA0025.outlook.office365.com (2603:10b6:303:8b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.22 via Frontend Transport; Tue, 4 Apr 2023 23:30:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) 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.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CO1NAM11FT011.mail.protection.outlook.com (10.13.175.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.26 via Frontend Transport; Tue, 4 Apr 2023 23:30:27 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 4 Apr 2023 16:30:14 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) 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.37; Tue, 4 Apr 2023 16:30:13 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 4 Apr 2023 16:30:13 -0700 From: Liming Sun To: Subject: [PATCH v1 1/1] [SRU][J:linux-bluefield][PATCH v1 1/1] UBUNTU: SAUCE: mmc: sdhci-of-dwcmshc: Add runtime PM operations for BlueField-3 Date: Tue, 4 Apr 2023 19:30:00 -0400 Message-ID: X-Mailer: git-send-email 2.30.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT011:EE_|SJ2PR12MB8954:EE_ X-MS-Office365-Filtering-Correlation-Id: 48474b3e-2fb2-41fd-4c49-08db356492b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ER2djJKZuApQ8Fvzo38wRyotfPqjpSoExliYTELpS6/abQEIBYg9w8CiIGCQqFw2B0mg3FuNdo+qaaHTHL/w4FpCsyfAYo6uMc0GPxyWCuxi98tzLD1P8nDoiddeCfxlXc1ABLEOfI3vP96sYUFy7XyK93FEyOsKwPnhiVqQjvRvtPh06gL9dTF4F9CKSxRwmx69hM5aRqGDRVqfjUbW40vbU990XIH9wxbvH+BXWQhCfP8g3V+zqY15vgAtFFCjjyj/TwS5gBNZyt+kwxYoVMh/UQ5rQCNaapUpBTZLQE3+eiBttOMXPlDT4b8/Lfmhwztczq+/wA1HHbgfzNKi3LRa106K6hkemHP6ZHDVt7zqxkxg4xgeM03bmBPiezct4uf6mNQL+AvR7v+9hlhiVwfPepmJcDCUmu4QvBg6LCHu+7qjIWHjlDrK3krhJYXALouOQSNm4Ivkk4jbTDW1t5jO+FQRm9f2hfM8ZWDh5YutpW/NJNH0MCxnASMKSmhblB8Ak1nko5iN0bSgauJhCFgoAuPGS+sKGaqx7nzwdUqFbHT5vsahDKYQ+cTPaQRxuU1aVQlN/thx/TC2kHbFkQvdp8Hq2vnbIiIXoEZ/bR0k/ox7ZZ/cDFp0hGan9/vUA8NDi01FJDSAOFRZrhbpfa9OIUw1RD3kFjDaloYp1W9shXdZFKdSJAVnTyP5y9PfS9T2sICik2pIlKdrxJscoswZVeYTFF3q08q6WQdbian9erb+IiD02UktFHoC1U2ZHJtXfgiLM465C5MRCn3Bbwr3NCQyajWk8WX2+fqd9mCr8wAIWLh8DhA7jH9TrGOe X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(346002)(396003)(136003)(451199021)(36840700001)(40470700004)(46966006)(478600001)(54906003)(316002)(6916009)(70206006)(70586007)(8676002)(336012)(26005)(426003)(186003)(2616005)(83380400001)(47076005)(36756003)(2906002)(40460700003)(82310400005)(7696005)(107886003)(6666004)(966005)(4326008)(7636003)(36860700001)(356005)(86362001)(5660300002)(82740400003)(8936002)(40480700001)(41300700001)(133343001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 23:30:27.6476 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48474b3e-2fb2-41fd-4c49-08db356492b5 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.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8954 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 , Khalil Blaiech Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" This commit implements the runtime PM operations For BlueField-3 SoC to disable eMMC card clock when idle. BugLink: https://bugs.launchpad.net/ubuntu/+source/linux-bluefield/+bug/2015307 Reviewed-by: Khalil Blaiech Signed-off-by: Liming Sun --- drivers/mmc/host/sdhci-of-dwcmshc.c | 103 +++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index 9b14febc8f0e..44fd58014b7f 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 @@ -74,6 +75,22 @@ struct dwcmshc_priv { void *priv; /* pointer to SoC private stuff */ }; +/* Last jiffies when entering idle state */ +static uint64_t idle_last_jiffies; + +/* Total jiffies in idle state */ +static uint64_t idle_total_jiffies; + +/* Total idle time */ +static int idle_time; +module_param(idle_time, int, 0444); +MODULE_PARM_DESC(idle_time, "idle time (seconds)"); + +/* The current idle state */ +static int idle_state; +module_param(idle_state, int, 0444); +MODULE_PARM_DESC(idle_state, "idle state (0: not idle, 1: idle)"); + /* * If DMA addr spans 128MB boundary, we split the DMA transfer into two * so that each DMA transfer doesn't exceed the boundary. @@ -456,6 +473,7 @@ static int dwcmshc_probe(struct platform_device *pdev) #ifdef CONFIG_ACPI if (pltfm_data == &sdhci_dwcmshc_bf3_pdata) { sdhci_enable_v4_mode(host); + pm_runtime_enable(dev); } #endif @@ -550,7 +568,90 @@ static int dwcmshc_resume(struct device *dev) } #endif -static SIMPLE_DEV_PM_OPS(dwcmshc_pmops, dwcmshc_suspend, dwcmshc_resume); +#ifdef CONFIG_PM + +#ifdef CONFIG_ACPI +static void dwcmshc_enable_card_clk(struct sdhci_host *host) +{ + u16 ctrl; + + ctrl = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + 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); + ctrl &= ~SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, ctrl, SDHCI_CLOCK_CONTROL); +} +#endif + +static int dwcmshc_runtime_suspend(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + const struct sdhci_pltfm_data *pltfm_data; + int ret = 0; + + pltfm_data = device_get_match_data(dev); + if (!pltfm_data) + return -ENODEV; + +#ifdef CONFIG_ACPI + if (pltfm_data == &sdhci_dwcmshc_bf3_pdata) { + ret = sdhci_runtime_suspend_host(host); + if (!ret) { + dwcmshc_disable_card_clk(host); + + if (!idle_state) { + idle_state = 1; + idle_last_jiffies = jiffies; + } + } + } +#endif + + return ret; +} + +static int dwcmshc_runtime_resume(struct device *dev) +{ + struct sdhci_host *host = dev_get_drvdata(dev); + const struct sdhci_pltfm_data *pltfm_data; + int ret = 0; + + pltfm_data = device_get_match_data(dev); + if (!pltfm_data) + return -ENODEV; + +#ifdef CONFIG_ACPI + if (pltfm_data == &sdhci_dwcmshc_bf3_pdata) { + dwcmshc_enable_card_clk(host); + + if (idle_state) { + idle_state = 0; + idle_total_jiffies = jiffies - idle_last_jiffies; + idle_time += jiffies_to_msecs( + idle_total_jiffies) / 1000; + } + + ret = sdhci_runtime_resume_host(host, 0); + } +#endif + + return ret; +} + +#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 = {