From patchwork Fri Jun 21 07:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 13706941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6A2AC2BA1A for ; Fri, 21 Jun 2024 07:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To: In-Reply-To:References:Message-Id:Content-Transfer-Encoding:Content-Type: Subject:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=C0ggd5wKMv4U80GyDOSu2OoINrWdvdDCP012GJn8Wwo=; b=gbmg0ytYf5Q8bGCE7E05NHOzat QpphFzSC2agCqfug729cSRevz0r2n9PPhvGgP82d6urJCoX5g4KiAU4EYL9Z6pGNrKKHgz7iM/oqG clA7m+lsKiutS0Vzg01HpskntUiqPOp4gtlMuZjaE7klyOt+/wdM1fL4DwIW5USTmtRlgwsZ4WLzx yIVUwOvuhT8O3i259CO2jKZkUI12G5MU5Yi+AwbhL6fWIQzCVVZMLmpnKXhnhrotVHn95WuAQr/ch 8WGel9BWns8J6Kw8y+06jN4SnGwHolIHnmnEnVWv1I/0MclbeYY+cwwNG4L7BWiBY4zxSWTVr2sqr 46/pPPvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKYQz-000000085wE-3Nlz; Fri, 21 Jun 2024 07:11:45 +0000 Received: from mail-am0eur02on2061c.outbound.protection.outlook.com ([2a01:111:f403:2606::61c] helo=EUR02-AM0-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKYQn-000000085pV-1xZl for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2024 07:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UU0/0mE/X+O4K5UjG1TcSkT5OUab5vVdoPOn3BlVWk9g/kPhXLx8dl5LsOqnRM2mG2OjsDWKvXWLethoWjc19u5igx32QDMculzwlfuGc8oArswDLdN9IcIM6TILFt2VDTWWIHOI4VaXdEnoN1p1Yy48slVb7qOuuiuYtE3PE7nYDqbMJdWALGnDXvd5qdSATBP3QNTFhECc4upGSsfF9v5pbgsIbgT9AXdDu5Ky/MateZQR0TyYlKQAqm+tfDjwhFJHP8TSFBBANzYvQ2vIJIuvFJHJVZAOGfbg6ZYzI6tYo2kKMuTZ5zpmFgN0UWBWhbmjvKSc/kW/1+vahp7wxA== 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=C0ggd5wKMv4U80GyDOSu2OoINrWdvdDCP012GJn8Wwo=; b=Y4F7JYzIlkNCS547gfRhNWOuWH5j9fnaIj7nNMFvGpshPO6+l/i/xT1ZQlMugO1DogCg7AJ2vy0ANvE9ev2wkc0WB26mn/CwRRI4GBwq9qD5ymkG8v+fPP/NyMHDSJEhkKl70bU3S5kyrDgrCZ25X3GX3EIFnhjML8HVa5ck2XAkay9ObNbflKt/HPfh7IR+oWng6rsZNuv1aE4TV1uJmcm7lbuZN0VIvGMhD008Wq6vvPXUp4c73Gi/udi8mVoawIb+H4/xQ98KOuWpA8Ai9r4MAV6Vb+zkreW+DoUknNDqFEwGigTbTzwSO8dtBsmBke0VMW+FzBMLX5yhcW1yWQ== 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=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C0ggd5wKMv4U80GyDOSu2OoINrWdvdDCP012GJn8Wwo=; b=e1C1w/sAWUm7Ru2rMJ3VfPnkm/TC+thyHFIOqCYlHdbM/oPyjLdXxL6t8zxMQtAtLhM9aqHG0bhi0aakk0wdWMajxAQ9E+POMXKJNjyizW7YaQfPpWwzIR1idPpv+H+XZkWvQ4MUaQ004EoNT0riHQLxSiGHklkbcfZPchz0Vv0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) by GV1PR04MB10426.eurprd04.prod.outlook.com (2603:10a6:150:1cc::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Fri, 21 Jun 2024 06:56:26 +0000 Received: from AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256]) by AM6PR04MB5941.eurprd04.prod.outlook.com ([fe80::9f4e:b695:f5f0:5256%4]) with mapi id 15.20.7698.017; Fri, 21 Jun 2024 06:56:25 +0000 From: "Peng Fan (OSS)" Date: Fri, 21 Jun 2024 15:04:42 +0800 Subject: [PATCH v5 7/7] input: keyboard: support i.MX95 BBM module Message-Id: <20240621-imx95-bbm-misc-v2-v5-7-b85a6bf778cb@nxp.com> References: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> In-Reply-To: <20240621-imx95-bbm-misc-v2-v5-0-b85a6bf778cb@nxp.com> To: Jonathan Corbet , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peng Fan , Alexandre Belloni , Dmitry Torokhov Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, arm-scmi@vger.kernel.org, linux-rtc@vger.kernel.org, linux-input@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1718953487; l=8179; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=ChfkEJX/72hXEL9g1a8O55kYUMOihK4KW1T6yM6QP7s=; b=478Kz2I4jFt9FPxkAK98lmXfjQPwSEDRoU4ChGwdkT9MAJDo+jB1gg6nuORaR7bm8I4KVBzUT JqOZH3l/a+MBl6n63yUIcLj2DjBKNKzwAa0dT3pjhv+bJ+NRxUa3F+5 X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR01CA0122.apcprd01.prod.exchangelabs.com (2603:1096:4:40::26) To AM6PR04MB5941.eurprd04.prod.outlook.com (2603:10a6:20b:9e::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB5941:EE_|GV1PR04MB10426:EE_ X-MS-Office365-Filtering-Correlation-Id: d4a72654-60e5-466f-3f9f-08dc91bf448f X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|366013|52116011|7416011|376011|921017|38350700011; X-Microsoft-Antispam-Message-Info: =?utf-8?q?AFuYzA8dFOGnmoNS4NIRR9+KFs/Cp4H?= =?utf-8?q?aqZyhuq3XNKaG8KVUYedjqaz1vwbd1wVDeZacyojGv0DHas75GcOfSpmEzfo0Sbi9?= =?utf-8?q?7QJuHh65HMi3+hpwPbRi3cdWKE3XNYfcTqmiidE9fdmLAXDO5ttVHnxvMlPUUikbg?= =?utf-8?q?b6Nb11HonfskJd+nZCihc6rq90+akkNnSSI1qYnLGOPsGqDYY5kbVaQTs2ErxioUR?= =?utf-8?q?VqmUqIEV4qFIPJG9xfI6iy6y4dgtkT5F5kYqSdy+ppq93q/D3JfitwGh0mMUGzurj?= =?utf-8?q?4QPotCrxP+YY18SiOSrkpc9Zkt+ElePN9HH8NOr2JeCUpZmarDVua9fBYF8A1DE28?= =?utf-8?q?4hMdrYtd4VBB8/CoipyAYvmlOwx23IDO+NDKfp6ES3YmcRULTjrquJS3T8IrrO76G?= =?utf-8?q?CJWfkdT22qNqKkl6+3H+wtsb1L9CIxq7hMnYPqprq8zVen1zLcdenz2F05YoT6dQg?= =?utf-8?q?PcRs/Vj5zBPrHjnLhzmrilBGcyi3ZHL6OHr2HfZgF4yDcB7UsLbLjQ2jPOC5poz12?= =?utf-8?q?4GNUCBXrIWsjRxglqNe/tGE6Ots7cFHGcsWbVw7Vootz9HwEtFiGEJThXyxXWYS4d?= =?utf-8?q?0x83ubygUnZdXJ3kVrA5BplRzkh9QmTb6+D2X5EAPi+0l8I0SuBEixUcrRU8Cgj/h?= =?utf-8?q?FQIsM5GI3XxVm27f/nPVviAcH9F3Kpemd8P+EkJjEapyPVdoTGWiJHXjINHu0ynaQ?= =?utf-8?q?OT4NhjDmonho4sr5GZNbHPXI3LA7ZF3nBEv1s2WBX8jsP/Sn2YtZpSvvXFZqt2R/U?= =?utf-8?q?Ao1dSzzr09VXKv3OZkKgDy2x4DU/oOP+AZirY14NIMHELaCHzwVsVAnokso9R/Cx7?= =?utf-8?q?2/cuquSl54h3kuXJhGcWnvMnYY7+t0q/baeyfphrgFjCd4TwNbL5AwhC91Rq4lVhZ?= =?utf-8?q?8kBAfD0kq1rtpWzZ0EMZEpcuswkuz27M99FGhdxlsxNfvciFXA8XUwWmj7vFTTeMi?= =?utf-8?q?xBgJVSX2SsBe66MezEvcI+UvfNCiL+6NfgJpiUzZE4v+Y2/DdzRuwblBuHKhHjlgo?= =?utf-8?q?ugrhv27QPF01cNvXDqigWWe02fuS0CS/3JKm8LJASfHQBcQD/gIXQNuraD6YzsCNM?= =?utf-8?q?BKmo2k/Z8VkAkcf1EyaJW1nHeL7udHDP0E5VXinmizrCh9YwjRah2HU6QppBPjuz5?= =?utf-8?q?4gkgzqMQ6L6USAy2S7yGs6u1nCPa+gohJDn+l9xA3OA0vKNfs+J1d+gn91o+fNUih?= =?utf-8?q?qQ4PiG4ZFkVJ5lzSgfY+lipspgG33Y2az/mr4uoR8ghue/u5UqbYlK+Z0SuRznsY9?= =?utf-8?q?Td51u6IhNDVmB3CaCUpsU71h5LCHaqQomtpM9YBLIYnyiEmT1ewQnUv9wdJJfm3RS?= =?utf-8?q?XC9Ucfurwpn1?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB5941.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(1800799021)(366013)(52116011)(7416011)(376011)(921017)(38350700011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SC2arv7oPPDRuk5Q+IBSP904f4aR?= =?utf-8?q?LrMg1M0YPPDKTWcdxQ4lIzVlxdtkC1fYXmp07iV6g7GTa43Q225OYaNUlMv+l4d3y?= =?utf-8?q?RygZtPt1s6YBOZQjuiO46P2aDC2lLngnVMakktr24Egpl01laGw88AOEvxXntnA1u?= =?utf-8?q?RVHoB+Gkv14B1/Mosdx0FiJrA2Lrp9vkGOnGcWQQOWviCeX/zUZeuoh23phOj8dtT?= =?utf-8?q?4q8ZPgqmmEFbT4sQGbfLH393yMnreB2jfkpKSMHZgErdTpPB/sM0VPpdEwwZcnpU4?= =?utf-8?q?DzmRobVIv5mFZ+oLCx69qoDrFGk2JOkL0GGgW2RlAa6PUNVqGSXO/QoeSXJMz1m0q?= =?utf-8?q?kW6IOA1jdYiRaHog6A5ygkd/KBk6XHJayv5ia45C5qzezubD4j5KXbkjXBisz86KO?= =?utf-8?q?KNn6MtmVsfPLKe3hlD75eyssm6yrB9iAOdO7Q5XnF/QlOpCTo7t58Ukhy+Cw5ufek?= =?utf-8?q?559C6yaGQ4xtu+bNmhfjH+zWzZXPqLHNJ0T9YTydID7pj07Wf/ksm3BBVpq+shVPy?= =?utf-8?q?CvQH+5hKn2ua4zLlhr9vw1PHmzf/lZ1y6+YDzpATanX3wwTIM9FhxvDAvRU9BKNW0?= =?utf-8?q?AKDUzMzYEk/mLoj/f69tvcCZ95fV2hoywX1HHr4FMBlgxAWfBMMrCRlNmYAidZBJT?= =?utf-8?q?5t1O4PKuVlSzv0RSc+R2qAAjMfYfC6d8FJc74YibKrjylbj1SyjH1nhCP+BjSDFUJ?= =?utf-8?q?1y5K+wXKghyynkucGm/TLCEKLD6dUWBQv5lU7isszIrg8fyfDokSvBdb2R2wfNLbp?= =?utf-8?q?SEtbXc6M2qR3dTrQ3ynpuwhRDfXP3n4A9sp4miB6LC5hvVNm40GZT2T8Tmb8gC7DB?= =?utf-8?q?S84VR7PIbuVxKMuR9yN7xeWGbHy3M5nJYDNxE9kKjZdnuX8zhI+66L0Z50hjudjbf?= =?utf-8?q?gtNi35ReASd1sGz1gByJjeda7MWNja0ibv5wUcAXMT55wPVwVb15nqEXjfQZJeFUV?= =?utf-8?q?drhvfSNs4Yg+j9wn5apXt7wnJU3kSMk6Eu2/IlW6QOZzqYHaAWFULdTlW0Ydllbaa?= =?utf-8?q?fvzn2rYUYbs7HdrbBGJqUZ0iCGNPDG/FRyUKRSN0rXb+YNQ8p+iWDh/IRaFMtLSNP?= =?utf-8?q?67PsFCstAEdzNP5upWJUxU1SZzJQM7F5wWo5aqeuZk/r6k4N7OTn2x1Glad8r4hIM?= =?utf-8?q?R9tD4lLNK2EL9+e84abul7xvUCxNx6OVn97fsktPO/JEO8cdiqhPbpKEsVMQQ1wo2?= =?utf-8?q?BsKM0OveBrQDS6NSIExJYanvTPLCOe6c9GQDK1UNrn0fv2IQ+mntQyIXU+rKOUOpi?= =?utf-8?q?mf9Xv7fI5RUt3zklolu9AYGam1CcbQT/0Xk0pTypAg7ZzbDlAglvm+ccYf8K/yT5Z?= =?utf-8?q?td6aIKBUj2dPW5/fcmhVlgUtFSIcgvXhOZfBOEpdPs6KTzYO1UB3Hl64fRDZ1vcu+?= =?utf-8?q?c2hraocC/naBu5h+XjXGdb/OzwCsXzkJotuIcYge35nK1AyUA6NzyhuYMNWAN2vY0?= =?utf-8?q?LBxo7WbsujukDEG//AIut6GjMoIQbY0FrJVn+jqwV+SPKgUbw0S2Ztox0FzBeEDD4?= =?utf-8?q?8CEhJMEkk7PY?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4a72654-60e5-466f-3f9f-08dc91bf448f X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB5941.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2024 06:56:25.5987 (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: SmTeL7EWNsEbLfOuXKP+NFRvyoE5Stss07R2Nnwa9hzyawP3qzhdO7EGgjkCNJd6jsKUxVnvuNg7LInI1tyxcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB10426 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240621_001133_962983_AA08A051 X-CRM114-Status: GOOD ( 20.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Peng Fan The BBM module provides BUTTON feature. To i.MX95, this module is managed by System Manager and exported using System Management Control Interface(SCMI). Linux could use i.MX SCMI BBM Extension protocol to use BUTTON feature. This driver is to use SCMI interface to enable pwrkey. Signed-off-by: Peng Fan --- drivers/input/keyboard/Kconfig | 11 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/imx-sm-bbm-key.c | 225 ++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 1d0c5f4c0f99..1c3fef7d34af 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -466,6 +466,17 @@ config KEYBOARD_IMX To compile this driver as a module, choose M here: the module will be called imx_keypad. +config KEYBOARD_IMX_BBM_SCMI + tristate "IMX BBM SCMI Key Driver" + depends on IMX_SCMI_BBM_EXT || COMPILE_TEST + default y if ARCH_MXC + help + This is the BBM key driver for NXP i.MX SoCs managed through + SCMI protocol. + + To compile this driver as a module, choose M here: the + module will be called scmi-imx-bbm-key. + config KEYBOARD_IMX_SC_KEY tristate "IMX SCU Key Driver" depends on IMX_SCU diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index aecef00c5d09..624c90adde89 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_KEYBOARD_IPAQ_MICRO) += ipaq-micro-keys.o obj-$(CONFIG_KEYBOARD_IQS62X) += iqs62x-keys.o obj-$(CONFIG_KEYBOARD_IMX) += imx_keypad.o obj-$(CONFIG_KEYBOARD_IMX_SC_KEY) += imx_sc_key.o +obj-$(CONFIG_KEYBOARD_IMX_BBM_SCMI) += imx-sm-bbm-key.o obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o obj-$(CONFIG_KEYBOARD_HP7XX) += jornada720_kbd.o obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o diff --git a/drivers/input/keyboard/imx-sm-bbm-key.c b/drivers/input/keyboard/imx-sm-bbm-key.c new file mode 100644 index 000000000000..907dad383b8f --- /dev/null +++ b/drivers/input/keyboard/imx-sm-bbm-key.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2024 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBOUNCE_TIME 30 +#define REPEAT_INTERVAL 60 + +struct scmi_imx_bbm { + struct scmi_protocol_handle *ph; + const struct scmi_imx_bbm_proto_ops *ops; + struct notifier_block nb; + int keycode; + int keystate; /* 1:pressed */ + bool suspended; + struct delayed_work check_work; + struct input_dev *input; +}; + +static void scmi_imx_bbm_pwrkey_check_for_events(struct work_struct *work) +{ + struct scmi_imx_bbm *bbnsm = container_of(to_delayed_work(work), + struct scmi_imx_bbm, check_work); + struct scmi_protocol_handle *ph = bbnsm->ph; + struct input_dev *input = bbnsm->input; + u32 state = 0; + int ret; + + ret = bbnsm->ops->button_get(ph, &state); + if (ret) { + pr_err("%s: %d\n", __func__, ret); + return; + } + + pr_debug("%s: state: %d, keystate %d\n", __func__, state, bbnsm->keystate); + + /* only report new event if status changed */ + if (state ^ bbnsm->keystate) { + bbnsm->keystate = state; + input_event(input, EV_KEY, bbnsm->keycode, state); + input_sync(input); + pm_relax(bbnsm->input->dev.parent); + pr_debug("EV_KEY: %x\n", bbnsm->keycode); + } + + /* repeat check if pressed long */ + if (state) + schedule_delayed_work(&bbnsm->check_work, msecs_to_jiffies(REPEAT_INTERVAL)); +} + +static int scmi_imx_bbm_pwrkey_event(struct scmi_imx_bbm *bbnsm) +{ + struct input_dev *input = bbnsm->input; + + pm_wakeup_event(input->dev.parent, 0); + + schedule_delayed_work(&bbnsm->check_work, msecs_to_jiffies(DEBOUNCE_TIME)); + + /* + * Directly report key event after resume to make no key press + * event is missed. + */ + if (READ_ONCE(bbnsm->suspended)) { + bbnsm->keystate = 1; + input_event(input, EV_KEY, bbnsm->keycode, 1); + input_sync(input); + WRITE_ONCE(bbnsm->suspended, false); + } + + return 0; +} + +static void scmi_imx_bbm_pwrkey_act(void *pdata) +{ + struct scmi_imx_bbm *bbnsm = pdata; + + cancel_delayed_work_sync(&bbnsm->check_work); +} + +static int scmi_imx_bbm_key_notifier(struct notifier_block *nb, unsigned long event, void *data) +{ + struct scmi_imx_bbm *bbnsm = container_of(nb, struct scmi_imx_bbm, nb); + struct scmi_imx_bbm_notif_report *r = data; + + if (r->is_button) { + pr_debug("BBM Button Power key pressed\n"); + scmi_imx_bbm_pwrkey_event(bbnsm); + } else { + /* Should never reach here */ + pr_err("Unexpected BBM event: %s\n", __func__); + } + + return 0; +} + +static int scmi_imx_bbm_pwrkey_init(struct scmi_device *sdev) +{ + const struct scmi_handle *handle = sdev->handle; + struct device *dev = &sdev->dev; + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + struct input_dev *input; + int ret; + + if (device_property_read_u32(dev, "linux,code", &bbnsm->keycode)) { + bbnsm->keycode = KEY_POWER; + dev_warn(dev, "key code is not specified, using default KEY_POWER\n"); + } + + INIT_DELAYED_WORK(&bbnsm->check_work, scmi_imx_bbm_pwrkey_check_for_events); + + input = devm_input_allocate_device(dev); + if (!input) { + dev_err(dev, "failed to allocate the input device for SCMI IMX BBM\n"); + return -ENOMEM; + } + + input->name = dev_name(dev); + input->phys = "bbnsm-pwrkey/input0"; + input->id.bustype = BUS_HOST; + + input_set_capability(input, EV_KEY, bbnsm->keycode); + + ret = devm_add_action_or_reset(dev, scmi_imx_bbm_pwrkey_act, bbnsm); + if (ret) { + dev_err(dev, "failed to register remove action\n"); + return ret; + } + + bbnsm->input = input; + + bbnsm->nb.notifier_call = &scmi_imx_bbm_key_notifier; + ret = handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_BBM, + SCMI_EVENT_IMX_BBM_BUTTON, + NULL, &bbnsm->nb); + + if (ret) + dev_err(dev, "Failed to register BBM Button Events %d:", ret); + + ret = input_register_device(input); + if (ret) { + dev_err(dev, "failed to register input device\n"); + return ret; + } + + return 0; +} + +static int scmi_imx_bbm_key_probe(struct scmi_device *sdev) +{ + const struct scmi_handle *handle = sdev->handle; + struct device *dev = &sdev->dev; + struct scmi_protocol_handle *ph; + struct scmi_imx_bbm *bbnsm; + int ret; + + if (!handle) + return -ENODEV; + + bbnsm = devm_kzalloc(dev, sizeof(*bbnsm), GFP_KERNEL); + if (!bbnsm) + return -ENOMEM; + + bbnsm->ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_BBM, &ph); + if (IS_ERR(bbnsm->ops)) + return PTR_ERR(bbnsm->ops); + + bbnsm->ph = ph; + + device_init_wakeup(dev, true); + + dev_set_drvdata(dev, bbnsm); + + ret = scmi_imx_bbm_pwrkey_init(sdev); + if (ret) + device_init_wakeup(dev, false); + + return ret; +} + +static int __maybe_unused scmi_imx_bbm_key_suspend(struct device *dev) +{ + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + + WRITE_ONCE(bbnsm->suspended, true); + + return 0; +} + +static int __maybe_unused scmi_imx_bbm_key_resume(struct device *dev) +{ + return 0; +} + +static SIMPLE_DEV_PM_OPS(scmi_imx_bbm_pm_key_ops, scmi_imx_bbm_key_suspend, + scmi_imx_bbm_key_resume); + +static const struct scmi_device_id scmi_id_table[] = { + { SCMI_PROTOCOL_IMX_BBM, "imx-bbm-key" }, + { }, +}; +MODULE_DEVICE_TABLE(scmi, scmi_id_table); + +static struct scmi_driver scmi_imx_bbm_key_driver = { + .driver = { + .pm = &scmi_imx_bbm_pm_key_ops, + }, + .name = "scmi-imx-bbm-key", + .probe = scmi_imx_bbm_key_probe, + .id_table = scmi_id_table, +}; +module_scmi_driver(scmi_imx_bbm_key_driver); + +MODULE_AUTHOR("Peng Fan "); +MODULE_DESCRIPTION("IMX SM BBM Key driver"); +MODULE_LICENSE("GPL");