From nobody Mon May 25 05:13:49 2026 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012018.outbound.protection.outlook.com [52.101.43.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAC663783B0; Mon, 18 May 2026 13:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111552; cv=fail; b=ZhVWb+lpeqc/HuPvjxijxhuq00DrJsTtHlOk/7E5+2OmvbJzeLYTlyjTRZv9hRcnUwI3gpwL26LxSvKuZFnZxNS3PNWvmShw66RJ26IXJfFDFB59Bz9q/poa2Ujd4czXteML3E0GAFed3ehk2uHSgJmu7aNoMCjYs2d0cntN2Vk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111552; c=relaxed/simple; bh=LYuLCRPHjNAErenZrN/zBeyGB0XfK/lLR9lwoNK7O9o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eXiJvSRgnUWfwvRbnqjjrNDm6uoyuklRSz8qgrNkQe4oNXfCoc6FuEz45JHAZ/JYQy0IY5diSw0h46jqYOUnQw/tVkImCrZepxPAjUMBy+c/e9QTgbI9MvxhQWQp8Ii3aropB7b5+exxMYwKYLXMdBYK+XN/EmupGJa9h2WZ0P4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=3jRooJ98; arc=fail smtp.client-ip=52.101.43.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3jRooJ98" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QHgz6d6ZXpRCMiTYah6KnVb6WNcQat/mESxxd/XjBFgYuCDulEeczzaqbRwyEUlb2O6gPE+PxMBHOFY8uJDcszairIMCOxuVsqzIMHqTfS60blOmrInk8lW50a1I7EoKc24qRMuRMbSenYZu5tPWJCbVKq2EY4CxaYc0a6/O9t5Ke0rNz2MAfvCo2JD76PpZygZbV6+OvGqIdv0YRTG6lO0JjenIpTbFzkXRShY+ynuPz3iLdrEMZ10JKmKrr15Foeywb2MQBeowKR3dIv0b8QB4LkNE6Wszs7NxbUfi0WLizu2EnbixDz2vtyM1+GQWWGe9MxyWpU73I4MRw0iorQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=C1rUBPHQMN5h4mXhxdI0K5a8ERARmgi3OLTCSaHDE3k=; b=b9lx9xEpLfWlNg8R8MZEvzYnX9XlywJMmI50OQ5gtil8FF3oAc4gDotDNGim0R4fxkJybj7WXddYvkDjeV8XSV/LqL99I4y1SnEDiVNiuqMjObbvm02J7VuZuyEa3L4I0bu+syH572/5GdaHA731TCpPy/1OhLgawCBWOqgyqfwHamPXNIQqHwIIx3jIHYdeoqbPwH/ZMx5WC1efsGmz24I6yYKf7fyNpJtuB6cMLA46t016pmIwUdydK1Wnij+In+QHX+cxuJoRh5TWBpM+AxrKnp8Hm8LRk9gUeLKaZNL67AP9JzIjlZwEJGRx9euTPIu1hzZbodKP1bPd7B6nJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=bootlin.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C1rUBPHQMN5h4mXhxdI0K5a8ERARmgi3OLTCSaHDE3k=; b=3jRooJ98IiOItPbdAd8tqr8JbptijIX3H60c6xqkGev0GundaAwwK695onMMoVLn0gY1pUpX06V4FBGg5IPAShvqsT5inW6IAQsXeG6QJp5tgBHD2B4oZlBhDSkhbKUfQudW2lW0pJN2xZM+8DDau3k17a6oGETUp+kTcSjFBoc= Received: from DS2PEPF00004562.namprd21.prod.outlook.com (2603:10b6:f:fc00::507) by SA1PR12MB7410.namprd12.prod.outlook.com (2603:10b6:806:2b4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.22; Mon, 18 May 2026 13:39:05 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:82c:400:0:1003:0:9) by DS2PEPF00004562.outlook.office365.com (2603:10b6:f:fc00::507) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.2 via Frontend Transport; Mon, 18 May 2026 13:39:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF000015CB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 13:39:04 +0000 Received: from ausmlimonci-lx1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 08:39:02 -0500 From: Mario Limonciello To: Shyam Sundar S K , Alexandre Belloni CC: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , , , , Thomas Gleixner , Mario Limonciello Subject: [PATCH 1/2] rtc: Add rtc_read_next_alarm() to read next expiring timer Date: Mon, 18 May 2026 08:38:52 -0500 Message-ID: <20260518133853.851027-2-mario.limonciello@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260518133853.851027-1-mario.limonciello@amd.com> References: <20260518133853.851027-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|SA1PR12MB7410:EE_ X-MS-Office365-Filtering-Correlation-Id: 3026bff2-3758-422f-1a9d-08deb4e2d3f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700016|1800799024|82310400026|11063799003|22082099003|56012099003|18002099003; X-Microsoft-Antispam-Message-Info: P9rr3tW/TIZV6neXyLE+kbe1/QXgXnFu7zAOQgmZA6YOFVi3bZmjaVnm4yOv6aQyEgHG4XgR6LNlMk4hAwcYHl2rT8tbktCS01DWGwpr7cjU8Qw/YiTM1VhCnCA6XqaE5Uk5pFqjtTGNhQilQwx1Mb+7YvUHIyXUCMi98hu42afhAf1sQ9S8nPbtMDpaagSn39BhNa1uzmzuKI7OeMLxJgIM+AACBkhcPd+c0pDlye95GV66dGf+fnoUoTEJZvIGB9jQZ/fAotQMySGHYsm1MsAHo7q69T71MM3RtLvGFSJNJB+kN9nD1YquBB7e1JZ3E6V7pwYHMB8z5qRMMETQZpNj8FFNae3M+wAEG5u1IPmJzyeULu9b0vBqnWWNwc66a14wD5lejrAOPkz/YDT+cosufX4oYhS93TxQMYuXH5XccbWsx6oR79J42P/w5AP0zSGt0H7tctFZghnkf370INpCUBN2iawg3xGLNlmfjbag55W9MXBtFKzxVWKQqX8MoP01VDsr4nnNc9ImEUIKM54cXPzMXv+5Jt0eSxZJWHyAcYj0yGD2K90eKW3RQYyctvjoeabYmdbyyAz7oWnCp5wpakLZsOOkS//hdCu6X2y/anW/GJ2zjDzVZ+rVlowHqKpmpe32pJAjJxr99yZXPXCA9dW0W2HRbodgh+1z9celceSb8Uhha5CqrzTtBAAu X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700016)(1800799024)(82310400026)(11063799003)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vg2yLTJqzlkcvO8bKs0vxr9+RS+bCEC9VJlAVOdzbtm15OgxAHxMspTH4V7tc06NhW5U1ttHmaMEwxZ98CypASBH++ByRfqq82WkfPpnNT3TEC5Um12nYPu16/ECb6QWeHzc/wZsSDkuU4FimCquDJlzMyR5u9KpW/2xBpfspD+Vee8Vz4yHzop8f2roClk6/DYKpZpZiao09HXIJZOzlgUR+rBYkmZq7W/jhVOEXx4mfoaMTnC84bt23fjz6BePU1ownmodCQ2zUAd1sJJMd96Ml6MOnDCFMrm0wNl7DnELkR096DhPn/MBC5eVQuN/yK5HVHbfHRsNMGT8I9ZLl0EZ90WnC8Szuf3dnjOG3gl1/klaQY6UJzsu5keY+NzWWja/IGWE6QuXW2tCogwDLu3OgEYcB9J+DyNnRSa63YIjtZLo/MNBQrLN/6cqhru2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 13:39:04.2836 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3026bff2-3758-422f-1a9d-08deb4e2d3f8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7410 Content-Type: text/plain; charset="utf-8" Add a new function rtc_read_next_alarm() that reads the next expiring alarm from the RTC timerqueue. This is different from rtc_read_alarm(), which only reads the aie_timer. The wakealarm sysfs file programs the rtc->aie_timer, whereas the alarmtimer suspend routine programs its own timer into the RTC timerqueue. Both timers end up in the RTC's timerqueue, and the first expiring timer is what gets armed in the hardware. This new function allows code to query which alarm will actually fire next, regardless of which subsystem programmed it. This is needed by platform code that needs to program secondary timers based on the actual next wakeup time. Link: https://lore.kernel.org/all/87ed50z0le.ffs@tglx Suggested-by: Thomas Gleixner Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Mario Limonciello --- drivers/rtc/interface.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/linux/rtc.h | 2 ++ 2 files changed, 44 insertions(+) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 1906f4884a834..dfcb32e272eb9 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -384,6 +384,48 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rt= c_wkalrm *alarm) return err; } =20 +/** + * rtc_read_next_alarm - read the next expiring alarm + * @rtc: RTC device + * @alarm: storage for the alarm information + * + * Read the next expiring alarm from the RTC timerqueue. This returns + * the alarm that will actually fire next, which may be different from + * rtc_read_alarm() if multiple timers are queued (e.g., alarmtimer + * and wakealarm sysfs both active). + * + * Returns 0 on success, -ENOENT if no alarm is pending, or other error. + */ +int rtc_read_next_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) +{ + struct timerqueue_node *next; + int err; + + if (!rtc || !alarm) + return -EINVAL; + + err =3D mutex_lock_interruptible(&rtc->ops_lock); + if (err) + return err; + + next =3D timerqueue_getnext(&rtc->timerqueue); + if (!next) { + err =3D -ENOENT; + goto unlock; + } + + memset(alarm, 0, sizeof(struct rtc_wkalrm)); + alarm->time =3D rtc_ktime_to_tm(next->expires); + alarm->enabled =3D 1; + alarm->pending =3D 0; + err =3D 0; + +unlock: + mutex_unlock(&rtc->ops_lock); + return err; +} +EXPORT_SYMBOL_GPL(rtc_read_next_alarm); + int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { int err; diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 95da051fb155d..c09fc22819d0c 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -190,6 +190,8 @@ extern int rtc_set_time(struct rtc_device *rtc, struct = rtc_time *tm); int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm); extern int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alrm); +extern int rtc_read_next_alarm(struct rtc_device *rtc, + struct rtc_wkalrm *alrm); extern int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alrm); extern int rtc_initialize_alarm(struct rtc_device *rtc, --=20 2.43.0 From nobody Mon May 25 05:13:49 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012009.outbound.protection.outlook.com [40.93.195.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 342E23F1653; Mon, 18 May 2026 13:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.9 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111553; cv=fail; b=OA+tPKYP0ObkDoIaPkoa/8nfdShLAWktYJVl1rAadZnORluvWPZxn9RRkrBYD6GKrkTvW+9z4qQNqz7FBrwQ+SP5FMQT5KwHYhxedyRCd/07JDDlbkP1T/D7U75NUMP7H50FXcRun04C94GttqCqFh+57u89auGwvco/HsYcMOo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779111553; c=relaxed/simple; bh=tI7QH4DFYaarys5Fjp42DkFCG6vXxhQ+I/o9FNxWbM4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P4/l9O6FuHsUeSiNcHhAkyMlj4dlV8sley0btXhQrsW/2hLwnv/A9EbtHx0+LQd2KduHwMKs82FpZ0u/+uJyW+QnUq7K0tp0laN7TqVbslGSXelyuCQRXJwRkRu5Ks78AAyMb6Q7H82ARDXgBLYwkMyGP9ouebgCj9xraNtE4g8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=BzGDarUX; arc=fail smtp.client-ip=40.93.195.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="BzGDarUX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BYnHl46dW9welzuQZAEg+W/MQdfLb9vZZnFILwSKqpfS0IfZL84+kiVP0EApo7ZypIedL/6LOpakVL1Zn3r65qgwfCIfii09qA0JIADYUP2jldcpadrV6NT0SDjE/v/0v6kT2x4mwp87BJH9aJZ1UcFUrz4dHqpOpHdb4CKfxa8TN4BQ9tu89PLtmEfpXbkBIGhyQlIADSbrbi4r9mqY9VYT+7BHA6Nq2tcIi+QqrOrk1XAJdtSVtK3PYyHJdsFvfl2akKlK9UlvBC3vab3JFNN7I8HFq+Sl7lsHRvtoPxWIblgFNVDed9kgrn93de8qRLdHuKSajDwSIP5VCJdutA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=oGrxSfgx9jUgbI3xaJUQk9EKdeW4sTzz1Yi1wx/8OPQ=; b=esXQkEZzsnuu2rOO3xwBpwiTzlFvXCmBKf+UWNJ8/B7ZByIvrhBqVJqdqPOFax8fQgFC7SMsUE2w8NYqgDTxBm5LBn4ZJnmjHVE6+HIVFjbPS7Zci7JSRdaLm+diZ8dbxxScE6Y99PoChkPFultXZoyPMbbrfXjXRqST1eFb34MeR1idu5CUrgQ8E3RPrujd3XpXp+f6xF+4BiRlFgwV7ocETWY4F+EAENGVC6lEFjQNs4NYHXxL6q7pfBTlz1LHotXXU5Fa0WoBXH2FDEaGw53Pn5SCWdJki1TsfSbg0N8oZrmWriMyfqjTxpXqLBg77JSGqqMcfr+csltlrKmoAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=bootlin.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oGrxSfgx9jUgbI3xaJUQk9EKdeW4sTzz1Yi1wx/8OPQ=; b=BzGDarUXF9qiwSj2ghiPgjUq0K2SNsQCeYC5D57XYstIQUFI6IC/D199QRKe6bSSa9D/429E9AwqDIio3uBxN27XnLH5l6yFG804KBx3I57l7HDWFOwg77+MDji+8nCKZVAPfv6+NTlRjxYUB5Bk/e6FKPoLWM+hvygM3g5MWt0= Received: from DS2PEPF0000455D.namprd21.prod.outlook.com (2603:10b6:f:fc00::515) by DS7PR12MB8249.namprd12.prod.outlook.com (2603:10b6:8:ea::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 13:39:06 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:82c:400:0:1003:0:9) by DS2PEPF0000455D.outlook.office365.com (2603:10b6:f:fc00::515) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.71.2 via Frontend Transport; Mon, 18 May 2026 13:39:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by SA2PEPF000015CB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 13:39:06 +0000 Received: from ausmlimonci-lx1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 08:39:03 -0500 From: Mario Limonciello To: Shyam Sundar S K , Alexandre Belloni CC: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , , , , Thomas Gleixner , Mario Limonciello Subject: [PATCH 2/2] platform/x86: amd-pmc: Fix S0i3 wakeup with alarmtimer Date: Mon, 18 May 2026 08:38:53 -0500 Message-ID: <20260518133853.851027-3-mario.limonciello@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260518133853.851027-1-mario.limonciello@amd.com> References: <20260518133853.851027-1-mario.limonciello@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|DS7PR12MB8249:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b4b411d-fc0b-4f38-b2f5-08deb4e2d4e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700016|1800799024|13003099007|11063799003|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: NQYDT7tjLisRtpozK5ttMBHgXrQtc9VOumecf5YZF9hxRkwfpmp30nKyRm92f4OJxHLSdCW7lcR1CcNTAtSzdPV0iBs5kM+exWRdWlnHpQgusKfMNyyT4RqcZWxEdFRew915vB7kfqfwbQAeBbXfTUkT86jLI7HtXxNzyMGVESAJYIlX9Xj06DLAv6ids8+79i94778O7rk8bBWS6KFgiXsXhEunrhN5CJrqI09h/tLhl9PUTKETCgc4CHKD732oqDkkGO7Jn3OgkSOvzwK8a/gMISmCzmXJ2HiJ4dYyYLOV9QzAkmhPw3Nnm7K0JqQEvuiETUZQoYcJehlv9Cm7MQT397FVutAOhvH/RFUxLWaITR8Wp5yaTghPDC4/w8IiF0M6kHZ8JqjwGRn32cKAt8Fk2/krXuV5HSy+8LCSIEkEyk6HZ+6FMjimYYDn9V5ZTjw0Axva4m/DfG2IoBKMsakjK2ZS+SPTkb4jrr68WykFkRGJC4IT+F9yU7otrzaj+v3B+QTcqZW0S3QG5DWrU62OeKVRBcS7eQCP/Y8lv+0QXN558AqUoxbWdMPg29vCbKoNoxwAxznMIviyEfIv8wX+e7bSCfupT6owfksaakPja22XHHbrd69uEvt2Ag8InR9UR581gmggJ2MdZ0rMVBdL1mP07S8c1XT9WI+HY3IPGVYnBeI9qVT/tqXRTTSr X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700016)(1800799024)(13003099007)(11063799003)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OTSShPaKLSqxbh0HicXKOCyKwNxfrbNo35nm/wicC9UBAgfyNFHCzaIsmDzAsRlTGmwmyBeA769YZXTA3sMPnL327xeZqeonPxVBzO+ckk8pdS6faKNi84iCC6Bf5a885RrGGKAthwQVYIjqwPKYn0/NT0gfH9gq/jGJ7wqHAOqS9D7t9gV+Wf6W5hGnycDgr8NnCXpT8kxnSDG5+9RYn+/8twhAyfepXM9DKfoKfPn8WNb1FD8f7VZc2Zqt+7wdeD/NsJW33wCnPwRkrfah7XenCUfNMt3DRD28JGdQvoNNOp4K3lsV9TFhOGYZXN9OkKbkDLh1rq0OWRQf2PwwSrCRw2PY/HEP/Pl8DzTzpZhUOCNEIg4mFQDmorYPS2O/O6T+7g8QyDTs6Ob/lcjVucGgSwzlXlg4mj2HYd49OwAAHtjZt0KZwCfCsovDw/9W X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 13:39:06.0218 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b4b411d-fc0b-4f38-b2f5-08deb4e2d4e9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8249 Content-Type: text/plain; charset="utf-8" It was reported that suspend-then-hibernate stopped working with modern systemd versions on AMD Cezanne systems. The reason for this breakage was because systemd switched to using alarmtimer instead of the wakealarm sysfs file. On AMD Cezanne systems, amd_pmc_verify_czn_rtc() programs a secondary timer with the alarm time. This was introduced by commit 59348401ebed ("platform/x86: amd-pmc: Add special handling for timer based S0i3 wakeup"). However, this function uses rtc_read_alarm(), which only reads the aie_timer, not the next expiring timer from the timerqueue. When both alarmtimer and wakealarm are active, the first expiring timer might be the alarmtimer, but amd_pmc_verify_czn_rtc() would only see the aie_timer, potentially missing the earlier alarm. Switch to rtc_read_next_alarm() to read whichever timer will fire next. Also handle -ENOENT (no alarm pending) explicitly as a non-error case. Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3591 Signed-off-by: Mario Limonciello --- drivers/platform/x86/amd/pmc/pmc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/amd/pmc/pmc.c b/drivers/platform/x86/amd/= pmc/pmc.c index 50f5784f2aa2e..8cd2db0ccaacd 100644 --- a/drivers/platform/x86/amd/pmc/pmc.c +++ b/drivers/platform/x86/amd/pmc/pmc.c @@ -595,9 +595,12 @@ static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *= pdev, u32 *arg) rtc_device =3D rtc_class_open("rtc0"); if (!rtc_device) return 0; - rc =3D rtc_read_alarm(rtc_device, &alarm); - if (rc) - return rc; + rc =3D rtc_read_next_alarm(rtc_device, &alarm); + if (rc) { + if (rc =3D=3D -ENOENT) + dev_dbg(pdev->dev, "no alarm pending\n"); + return rc =3D=3D -ENOENT ? 0 : rc; + } if (!alarm.enabled) { dev_dbg(pdev->dev, "alarm not enabled\n"); return 0; --=20 2.43.0