From patchwork Fri Jan 3 08:41:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 854984 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013039.outbound.protection.outlook.com [52.101.67.39]) (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 7F3EC1CDA2E; Fri, 3 Jan 2025 08:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735893729; cv=fail; b=PJ/1zqBn0vMiW4jabA4z2FEeAcNBFEhiMjh2akMZW3m7xKcFrDwcOj4xuwqwXZ6j/b9MfH1+SXtYtpgudpF0/Atp0dUsIyiNDKPhy0FY49Gj4pmRQjjiY9yw4Xs4sJjzEM8lPY6ZBiQnPO3E8tHJp5f3ddROvVe91CBdvlRXdqw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735893729; c=relaxed/simple; bh=MtlGyF7f4IaQ5gXyjDyNBKstfyPBC/6xufVjFPOKlIQ=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=tq0SK/wdk++ZzMWBCHExITQKMq2AqBPPtiSsHYfnPXuWLyzbLzFbNqRIoRXeSCjdDlmshtYI1NiY/Tm5DM0bf73TWl28D6b7wrd/UEIzBlNhEgjgrGGdzia1MOL/jcqarHrfUzwaq+miek8kjhC+xlPy0S0rkoyWifeRUOdv87c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=SQQbuU/P; arc=fail smtp.client-ip=52.101.67.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="SQQbuU/P" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HIZYJBv1zHodPoR8UlsPvIFTyC734gJepvyWTq2DPyHmKVGqauYz5yNbfVLOJdiYkl/XoD8uZnXZWiriXMiDpiJDIDoZ29kOVXO9sfxr/WDKzlPuP69NUY37ADt0PPBv/wk3ygrQUB1lVZelYNgUHL1pMNGMDXFqgtIu9Sdm94XLty9jFbBFc71UkjEs/t4ww1OyViQ6hqROFRAqMp86ISlzhCAJ6qu0hAO5IvT0M5vTTpVLMA5WjZpt91wA+gw/WreGwrKaIF3biz01gf/JiRiMPCzdID/ftFCpT+KNSdxsfZJOLEeKNSaFT9GTWgpBU5lERF3P7DxYjwymHaQWvw== 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=GvJSucZCIwQtWFHFefZHH8o5izy9wD1tkxKMnEC2y5Q=; b=aACBxHw7G6D7OHprQyA72NYuDRI0Ip2BZWXxyxzYqLWWA/kYRgFfK+PjilFKXKS3tfM5hUeqMgz9PxO3Op9tzUm3/WDqnFpy0GdyfPg8KwxL/XhFJtzzGUAvh3y9u4fHxIrStxEej9kGKeMtfMG0uCMmC5Ct6TqJL4B1eW7tnIf0jxgie0qjURrsVKVe0ZPMYLaT9czWfxwdg6dWMpsoKOB7meGsM7lk9l0Gagp44nt7o/wo08o+osv5cPEpD0Ueg6DqzpdvZPcaRAVJ6EctjAjmaUulUzjKorqGOChvQDSG8pKo62vBt7wwAypAXvGI7Wa4QuJw1lwGzdUqjSlZYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GvJSucZCIwQtWFHFefZHH8o5izy9wD1tkxKMnEC2y5Q=; b=SQQbuU/Pc2kDdi0mMKNu2kHZ6WL/6I4ax1KRGRPL5uT10HLJL247RaP4UDTf964jmS+cCB1wbyOqrMYAngo1mOXCydsFNMKN8PsBjONCDk3eHQSEKd6RE6vjegnpAn03Ocn/ga1oICZ8TArFtG+BzMh7BEUxRFNV3uhORI0bdjCMJvZ8jQIyYqhqoOirXeFV0RZmt0Fwdn76PVdawpQ5DFpQvIbdLgasRs6xGJaRqnNFnijBGcElwBY8qPgRcbQtOh+R86P8yBoGy/BYLN1ewRVfIRUyaJCiAx6l/N7nb7RQgi4KLmg9qZwXW4lC6Iwd9tunu8y/dmAvZCoY/da5yA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) by GV1PR04MB9101.eurprd04.prod.outlook.com (2603:10a6:150:20::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.14; Fri, 3 Jan 2025 08:42:02 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%5]) with mapi id 15.20.8314.013; Fri, 3 Jan 2025 08:42:02 +0000 From: "Peng Fan (OSS)" Date: Fri, 03 Jan 2025 16:41:13 +0800 Subject: [PATCH v2 01/12] PM: sleep: wakeirq: Introduce device-managed variant of dev_pm_set_wake_irq Message-Id: <20250103-wake_irq-v2-1-e3aeff5e9966@nxp.com> References: <20250103-wake_irq-v2-0-e3aeff5e9966@nxp.com> In-Reply-To: <20250103-wake_irq-v2-0-e3aeff5e9966@nxp.com> To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , Dmitry Torokhov , Alexandre Belloni , Maxime Coquelin , Alexandre Torgue , Linus Walleij , Conor Dooley , Daire McNamara Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-rtc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-riscv@lists.infradead.org, Peng Fan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1735893689; l=2411; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=cZsxdEVfnwbWB6VyEJvR/aoyZKsWpsHQZXR8Pc5i6rY=; b=j1W2wjxkUyGXeKstwZDwXLHFSM2SgXzdNMFeRi14fZeVx9+ZZtiyM8Xe0hbxRmrqsALDiNlsh Z+I5HCmQOy9C3IoAIY6cIOYoh8iGZZWq0onr5AsZ4tjvecBnbvrw/8h X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR02CA0003.apcprd02.prod.outlook.com (2603:1096:4:194::13) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|GV1PR04MB9101:EE_ X-MS-Office365-Filtering-Correlation-Id: 605fc750-e430-4da8-2e5b-08dd2bd27e65 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|7416014|52116014|366016|1800799024|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?U7UcBL5QLKNo55cT/gAwsyw0Oy4/5j4?= =?utf-8?q?JnKGhugWTowujd9i9+fstyD3D681gwz/ppTkQuVZxqnBP+KKrke7eGHE1jh/78/FR?= =?utf-8?q?u5g+qFLSXf6l2k9B5NGO0eHC/8T1ZmnnMHAKslHbQ9OrtlZLZozKv1SPo6WxGK33j?= =?utf-8?q?B10ssgQMEmL16p33xrGvv7XrZUOj3ZMTvkAy+gPoThroNSuP0LqY0M9o9uWG3Gpuw?= =?utf-8?q?Zdoemb+JSX2YHpzaK2dnzmqKZH2Dlq2y33d/FNHXJlYyDIdUR/Og1pTpf5nq+QVO6?= =?utf-8?q?hdK/mL2dB4ycArZs24f0a/5Nr/1a0WNqonMVyeTTI/+3W6M3bulfAWCLl6ybQvR4N?= =?utf-8?q?UAJahi35boC/OWvKU727+/HeJsLciBjTg4g19Tx0qfZsaQ1o/2r7mU4WI+O8eTCr6?= =?utf-8?q?7HxCkq21HvCfOS4IHVUyAZNZXBDcBjZCbr4yoQuoMEZSs0D5rZoI+mWHsMo87fKoI?= =?utf-8?q?mcjoIKLRpwvgL5ZTKXsMxDr/roMjtUZYMIuO+AwxUjwv2wwrcl68egML0oNjEUbCq?= =?utf-8?q?UmqSczHMXTs6dHZ/MwwgeTbWgJRQukzpHz/s3d6hIFi9lfxqDCXdixKPSjWhCdxIa?= =?utf-8?q?tkhRl9/QGA4KsLpoZquFWaimQjtVG5MJPKzCMgofHGMxZUcRHsIdqq2ZbsyuOMztv?= =?utf-8?q?encIw0J7aUkBWOOGwAKQhrDEeA0D7ncmiKpNwDn+gy7MHblcOq8dWGX7fsmW10281?= =?utf-8?q?hMPGINzMgmMm7xeCE33oa3FpejkFySlvjs4efdm5/j3UXmYjaIbIuNGosJpDhLQQq?= =?utf-8?q?70UsUC19nGOQmi4+HZWLLpPvWryPHd/hDBSCt000Ula0R50gKjCNhzJHzSLuATICl?= =?utf-8?q?vzfqVzErAkk7wYhr5JwANb+Ym6tuuXPwqF8Br2scT/Hip1hDOflZXh09z/RE2IAQx?= =?utf-8?q?JoLAkxKBaHYvURCzlgVfyh2rcxmfocRz5qAUL9bvgLc862FnYqh+m84ofZKNxiC9z?= =?utf-8?q?TFl46IfqRykBr9Wc0vDm9jEt56ge41PxEEGWxFBL3EzBCHWAvDcv25WO83CZqr3PP?= =?utf-8?q?TfLvR5KUqvyhNoIFOnIWcj96QfZa9G5DIzyUydVMYk97lL9YxHG5Dm3LPRQaGpFGm?= =?utf-8?q?9UVK9Ohop+NZwmgd7nl5J7NThPNYxtrk3gb89V6xBJNypik5VuF63QX2riTtvPjjc?= =?utf-8?q?PNVmggZCXycqpTILogs1jKF0Og/fNkKkyBu17GT2cUcDSvk3vbgSMVYLEBWIqDGiQ?= =?utf-8?q?QRHoM1ZRReXUht9FRJzkk+upd6NusH4RHnIN7DTUvIdvjnNXpRBK4vNzadgWFSrGt?= =?utf-8?q?kXs25M/+mlCc9IFpzdiZ7IydEMYvHMgZTBbkVU6whsQdgWriOZO7DPPqIChduzP0k?= =?utf-8?q?0G48E+2oBNtNQWqjUAIjM+B0CzePgCOlLEDHpSQw15sLqw/B5uDG8hMyIPl80RSXm?= =?utf-8?q?pbb5jDd/5297ejyocQU27zIgfYhCwiSxw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8459.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(7416014)(52116014)(366016)(1800799024)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Nkbk70wrQDP1o0pnEo5JPxzSgpTY?= =?utf-8?q?32goA2yTO2BbMZsnbv8Q8jcV76nE8u+4EmpAXe16ifG11BBllQ8cteHEubpzlOGWh?= =?utf-8?q?KtFy98Mr5ThB/O1HlIW2tG6AyttgT6NEhmXYmggqYBEJmzlu42b7Ej4AVkhSXmm1B?= =?utf-8?q?JiCViorLFPoNpl0OZxG6LGKgZPgauDnr5j2vK3B2dAmJLn7yvlrtme+/Kn3pO5wWz?= =?utf-8?q?oSo1c7LG/L7zoAoakjlmxCu/1KiMpP9eNxu5YLTCpye7/SoqrVGYuC2aMmPLNvHid?= =?utf-8?q?/UoGczdM5MLAiGsBg5NpH43H1O65y619n2Mf1KUN0Wq7EWT3gNzHw66A+VnRZQvaO?= =?utf-8?q?iUr2AR4ITa1vQqfP9prFOVi5wMfa3EDoJWnmp/aNRlV54wPfXrZFM/8PVzU0jxfp0?= =?utf-8?q?jRGvPf4udPqtC8xjwjL2vQfUyfJgfrwiZ5ucV03ZO0P/OBz5c4EmSXSU0CUktiMxV?= =?utf-8?q?ilicsWiW5oEeA93foCpJWqRmH/uAt9PWWAPdQxLqIqbZepzkbhqzxSGKM91YBidxy?= =?utf-8?q?Bmk3qdJvZgafv0TgRPchXzS3PuTUzViuz34mSaT9knkkN1CvSlh5SFVeLLHFjezEP?= =?utf-8?q?0/HfyjwKUgwfPRP7nkYeK/tGVHZsw0LQwvJhjjiykhLdwlRYw3cQvXRX0j1R6mznX?= =?utf-8?q?ZjdNv91U1xYBtIJP7WnPfaCnoeO1ziwvKMoeYQrw2kouom7EBh3ct7Rhe3SS8zCam?= =?utf-8?q?z0WzxybQtooH8nP50Oo9031AliierJP6cEaw397/uOk2K5VNZA0l669KrbPylN/qd?= =?utf-8?q?/+H+tE821++3U/D2NGpg5SNolBAl/5UpNRtItaVpHJJVMJyDDEqlNfGTKiPrv8TZH?= =?utf-8?q?/wNpcDT+Ol2vhfvePcsVupe9UbRbWJGKktJi3fFCtBbcWEiASalGESfWgh+ZfEw93?= =?utf-8?q?T1eFRGAXfOZ5eq6mUkK9wUoUs+ZaPB8FjmgRRFukf4axH1DopEGizq1hL8062Yrix?= =?utf-8?q?+5Bwl6g2wp6Mvh6mJgwazSOt5XwJJTXxZnvqoZwKDYzAbdjgaIyUSH6oGla9ckuai?= =?utf-8?q?+5CccopQOSix4rtsJbC/0fhgu+VWSCT+qkjmDi5LgriducHMCFFlfa3fYH8xbLFZx?= =?utf-8?q?uWoHUbEY4b0vPAiamUaczd5aJHThW3/CRcQT5SJQD+F2exm/7D819gdz+3FDFzaEA?= =?utf-8?q?nJ1OaZzdH3FcIbjIA4KFiL25wBsP4BPmxgD3m+FJsehftz1xH5677OQ7chBE94WAB?= =?utf-8?q?b7PkdpAr9uj1jiIEdvMuqfA+WlEVelbaeXOcS0mdA99+0EJylUDhUsKQhVszyIWy/?= =?utf-8?q?VdRH2mHZwGNGX1hEBpWNYRItkeVxL6sPMaBiJgcuxbPxDwMCHzkasGfME9cgF8KE1?= =?utf-8?q?jNwCe2rtYP6QeZXCgDYF1N3nv5DrmfDT5v7LF3TOhBzJ/bZpgQYnkWnuabFpY8gH1?= =?utf-8?q?31zqqThp4IZQHmvINggWUjFZsozXSIydrATg3wkcwy6byVQb6UBQyon/M1s+piNJ5?= =?utf-8?q?UrNnTGYO8eagcj6H7EShnZ/+Rvp6aA0NNJ6pYBxTEWZ4cz+k+PeYzasmBY8JtHQPV?= =?utf-8?q?E/hLQgyuRLDD?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 605fc750-e430-4da8-2e5b-08dd2bd27e65 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jan 2025 08:42:02.1115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 92QI+cW0ykw8vms9yGkeLmFh4UlLy1EB87SyEeB8Gpy3Jd+fCGIdGBl9ExHcq4l5Ulkp12486k73j81I7QY44Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9101 From: Peng Fan Add device-managed variant of dev_pm_set_wake_irq which automatically clear the wake irq on device destruction to simplify error handling and resource management in drivers. Signed-off-by: Peng Fan --- drivers/base/power/wakeirq.c | 26 ++++++++++++++++++++++++++ include/linux/pm_wakeirq.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c index 5a5a9e978e85f3fc9d89cb7d43527dc1dd42a9b1..8aa28c08b2891f3af490175362cc1a759069bd50 100644 --- a/drivers/base/power/wakeirq.c +++ b/drivers/base/power/wakeirq.c @@ -103,6 +103,32 @@ void dev_pm_clear_wake_irq(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq); +static void devm_pm_clear_wake_irq(void *dev) +{ + dev_pm_clear_wake_irq(dev); +} + +/** + * devm_pm_set_wake_irq - device-managed variant of dev_pm_set_wake_irq + * @dev: Device entry + * @irq: Device IO interrupt + * + * + * Attach a device IO interrupt as a wake IRQ, same with dev_pm_set_wake_irq, + * but the device will be auto clear wake capability on driver detach. + */ +int devm_pm_set_wake_irq(struct device *dev, int irq) +{ + int ret; + + ret = dev_pm_set_wake_irq(dev, irq); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, devm_pm_clear_wake_irq, dev); +} +EXPORT_SYMBOL_GPL(devm_pm_set_wake_irq); + /** * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts * @irq: Device specific dedicated wake-up interrupt diff --git a/include/linux/pm_wakeirq.h b/include/linux/pm_wakeirq.h index d9642c6cf85211af603ce39e280a5b4de6617ee5..25b63ed51b765c2c6919f259668a12675330835e 100644 --- a/include/linux/pm_wakeirq.h +++ b/include/linux/pm_wakeirq.h @@ -10,6 +10,7 @@ extern int dev_pm_set_wake_irq(struct device *dev, int irq); extern int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq); extern int dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq); extern void dev_pm_clear_wake_irq(struct device *dev); +extern int devm_pm_set_wake_irq(struct device *dev, int irq); #else /* !CONFIG_PM */ @@ -32,5 +33,10 @@ static inline void dev_pm_clear_wake_irq(struct device *dev) { } +static inline int devm_pm_set_wake_irq(struct device *dev, int irq) +{ + return 0; +} + #endif /* CONFIG_PM */ #endif /* _LINUX_PM_WAKEIRQ_H */