From patchwork Wed Jul 31 12:56:11 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: 13748721 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013052.outbound.protection.outlook.com [52.101.67.52]) (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 D37A61B3F0F; Wed, 31 Jul 2024 12:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430076; cv=fail; b=iv20/seAyMvtOK8CdGH+NxnNiSxej26l0QyJEr/ac1xdisBGwZW79UaAIwtZuTQ4bTqRPGelpQP0jmrxRfzydfNYdRh7+PeqyhGsDfp8mcheT4D6UGyTy0CTBfpIAnMt2tI2X2jBTBak+3uc1jc9UiE5RW92Z/MTln5aQVFWts4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722430076; c=relaxed/simple; bh=QQUxD+WrZ1BoCEejLUiFnTZSyCOU5Rftc8RYqexva2U=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Ek/7fkBsvIhCEWrhntDYm/UASiY6ew1nC35dmsMKLS0fvdY2PItsK/B6pZiYAPQJS3vtmypy4m0GSmG2N0fQ1Lc2eWL6bTNFhrYv3HSmKsBZ9bpXN8j/6z+yuqrYW7GajsSCieO4PIhSXgIgAOuSCuioCi/PjhPVvg/NODuRkTA= 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=hl9mXs/p; arc=fail smtp.client-ip=52.101.67.52 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="hl9mXs/p" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iw2f7C8tLgS2BGLiXIhpjxIGJwg9zfdK80Tgocb19NsZEsLFafMKF7tDJmN1kEQa1C1d70DvaGLMMHvRvs8y0WQBfKKjG5p+hoIZ+O8C6rb9Ul/GYTXzO6wIOjF33Vsn1JcqlcK0/mksULbxmyvH6Us+MZmD+JS9oqdhzFOJS4/s49NW2Hkdoax1BCL4iLfgkeNOZ4ExXqTBCJE+Ob1kFRpu/Ul59CU3JihZ5yoILHj8+j5hE9KvJid1fZr1TxyLrTOIpxxNgz0Cur7wqZI7hwPPTPJe0A2AbMx0pym9A1aeoZ92sKEQL5CSbVE35vLkyM0fLgJyZVoBJ9dqIjf8Pg== 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=4WPWBl+UNIF8UJOX1QJA+qTKK8dUxDTksPWRgdZNkUI=; b=lCpGzQw5JIaWsNw90G+JAAqvnLXsuAFCkIbiCe6dIMcivVAUAi9g9WEsQZCv/Gi45CdViWQgOsfGlepnfvMZ8Sptzg9Un5xmyFxsfbE8S0LczgzwQdD8KGBxiAerrrRmsJaOtt28+Pm6ZNF+pB92tZ3Z9+wpunJQFtK11N4qysDKSJHzbwnoxC4AYKTyDbHudlNoh6XuwATwRHSnYRLlUC7DyuH+b6/6Ej6HhLWSBpQ/oStq8ehMqoF30iQrHDX/1ZemGc44FzNGtPebGpI3BHQ9oS7vzPWnSUkt5EUwHz9CJqQW1BVBAQrcuZje/wXJ+FR+mgjaThHO3QdRvrgKaQ== 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=4WPWBl+UNIF8UJOX1QJA+qTKK8dUxDTksPWRgdZNkUI=; b=hl9mXs/pkYuGYXtgy16pN8kduYri4oiATn7eEbF2qMBvacet20MgA7saNIMWTTMr1j+5Rt9QjoNryt3RHNdSn4T9Hjl16/hg4eQL+mrpnJfLLfwjYmYE77FhLHRjxPA96058v8YhGTFgN1GTKto7iVS9DpQZAXUmIvWNn8Y5MGmBdfHZk70a5kMJ4+y4ZKZBu6Hy/IZ/eemHQv746mmqoPCaDuycViGgMCgu5xz5zGY8vKDDmHdiPYC2IWeSjHBIpYNX20lq3/7U3i4jfXPZeUCuTHtAeqGU1sgKvdCyBsPGFdK8nYUIhUwwHzhiedmj61KmHssnSRvZ2SDPnY+bdg== 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 AS8PR04MB7735.eurprd04.prod.outlook.com (2603:10a6:20b:2a5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.19; Wed, 31 Jul 2024 12:47:50 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%4]) with mapi id 15.20.7784.020; Wed, 31 Jul 2024 12:47:50 +0000 From: "Peng Fan (OSS)" Date: Wed, 31 Jul 2024 20:56:11 +0800 Subject: [PATCH v7 7/7] input: keyboard: support i.MX95 BBM module Message-Id: <20240731-imx95-bbm-misc-v2-v7-7-a41394365602@nxp.com> References: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@nxp.com> In-Reply-To: <20240731-imx95-bbm-misc-v2-v7-0-a41394365602@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Peng Fan , Alexandre Belloni , Dmitry Torokhov Cc: arm-scmi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-rtc@vger.kernel.org, linux-input@vger.kernel.org X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1722430577; l=8472; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=nWz3HeeWJlo8Xe0FnLKszmcU0B0giCY0FEpvD/2NDGs=; b=EeBKm/mxlzkHVZ43xChsPXtv+gjLWs1SubwDtlbFcta0NE71w4rksKlRu5qeAhJx0WEd0rJGY z83MSy8I0HDBpSxGZQ7h/HzFebi7HutXaRfQJgNmp9BFsA63l9/xrQK X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI2PR02CA0027.apcprd02.prod.outlook.com (2603:1096:4:195::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) Precedence: bulk X-Mailing-List: linux-input@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_|AS8PR04MB7735:EE_ X-MS-Office365-Filtering-Correlation-Id: 6bf38bcb-a461-42ba-6c5c-08dcb15efc53 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|366016|52116014|7416014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?e1kupNBy4C+/pdKu7ya0wNyFumTCSTE?= =?utf-8?q?gkozxN6NUBMMA7HklFDoYZMc/yggNhpO/htl49IWbi48W1BM9BBtfS8QUdfcvRfq3?= =?utf-8?q?BS+HNp9npcMoAY+IPLzJAkuxCqiLD+pvlGJA1pZFf3puLIomOw9DglqW4aa7kWgju?= =?utf-8?q?AvBR6YBTBKoEVV+0v+peMu/00yOqEzE0Dx+HkxAjtu261+t4vl7NEymEKdU/S96hz?= =?utf-8?q?6Ze/xwoGTgYRxUdSnhoCXpZB+8eW6KeWK2r6YMf3ap2hsdh5vVyJhhwwcK0JU7WTX?= =?utf-8?q?xQGN6cx2GqdPBYffJ+JWyG9w2MOwbvG0Auf5PtWzF0Emdd3qt/nxG30Yarn2R2AYC?= =?utf-8?q?wxYsiWJzcUWdp+Wi8iL8b3/p8rZnksmZy1NfGI2aI5dU2joPkdUZz9lX3qVW3rXbJ?= =?utf-8?q?Xw0gvq0FUgJmcuich3yZGRFLdfotehiVdQ5ZL8EWUrLeUnq7z4i99X4gbhptErZMk?= =?utf-8?q?qXdUGSH6ZwMhVxqvGx0T+bn2wbXB3H0e7n/kewmbtgDBkffkFyBC5qwJ82C5RVEHc?= =?utf-8?q?POG4qbnDmMcDsMujSJXrAdDOXrtOnPyeF9F+4H0IvXGx37f5Tb/mEIMaXpmtxqixQ?= =?utf-8?q?4l1iLOn2fVlkar68p9qQ21tylPSuK1Xn1VQoZxO6Fv0byyU1U2XUBRF/X4fEKHgDi?= =?utf-8?q?xfIbatC+Uj6QMIdKIMsG5kfT1+VOkR1DB9CW4kCWO+VYUOeuBAT5qCve2wBJhdQqN?= =?utf-8?q?ljfXrQDVIHZPywdRGZT1fUMmwlfgURQqMucZ67a6uq0JnI4WWNhShzxNCwv+AWtmO?= =?utf-8?q?AH3yVsDk6oPMESc5TsSnPuyyCSrMxazqdbGKaSrB200WzciQi3F3CCZLA17wPTfjF?= =?utf-8?q?Rud0AcQA4+5G8sH47eA6pMQe/jTuwss/1g5XIJ5dH2IVCYBVBPr1mYRhpYxBRjUOq?= =?utf-8?q?Qcdt3F4XUBeOg6ScWR8F+nkI0hgC0OJeikU1m7zOWa5EDtxhOaCwS2AsOxT4TBAT5?= =?utf-8?q?q1tAXcMpHkAh52BCliEkL2Cvvt9OMMNrRFnS/4YYhJNJU63tFqPUe9lRScdMnJlRC?= =?utf-8?q?8eeviLS1G04EgvotAg5yScnaPLHjZkLMPUw3sThQ3Qt+Jyw0QSHxh4lh0UZI64rRF?= =?utf-8?q?4P4tvfbtbQkGVNFeJccoIzUrCHyDeyAQ4FKI/EekVteeEK/+MIsquu6tYkLrqS59J?= =?utf-8?q?LXpKB/i9z5RGqkZ4tO1zcMC+4Nk1cDCcf6iAlzOVKQuY3DMQOTUbLz7+PNZHegIW/?= =?utf-8?q?fU8dJ7JCjIxhHqQXzDRiWQEA630RIQ8sgDqkmuERs62JQwlfw444JPRl7RvVEk29L?= =?utf-8?q?OGsL/TrbTMvzrl4CQPEF01DZ4odvjD143NHf9tM1zU15/T66qEe49T0nUFdqY7gZS?= =?utf-8?q?zb0I35jmueABwi0HF4uCiqWNUqdYRzwPAgVSLr7sy9bpcfTABXPaai8=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)(366016)(52116014)(7416014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hYzATW73Bt+2cjxxP8lNwRKGe8WN?= =?utf-8?q?ll2hx2fZRTniHTHwTKubzTCaXXO64hbfkTvbe+o//v3URQ0jah+XMTp4UmiPHBYPY?= =?utf-8?q?+wWf0/MPO0i9pFvQ2UG5qwRzY5c3v6Kb5C/89MBqaZ7TxUiM/Q3LywOW+5+xtEt6E?= =?utf-8?q?+eAfkHKUW91WZqog0rcqn/cbVjAN/3KoTMYYea9EdnwxoxFfFbx3tyRhcx78IX04J?= =?utf-8?q?Bbcwh6f971cFAiKE53HAdIPXtwnbGPqP4d5ms0Qbm0VEutGG3860y21pmDjogFVdY?= =?utf-8?q?urXlRRwmibsYzaZYg98qsadeiGWHXGwqaz8tHOrdkWhtf3KEu40mhzbe9pEiY0+9a?= =?utf-8?q?Mh6417yrFxk1HmLhMACxwIiu0zJMtin7h3/S1njCezlNRCtzqIdclDe9hDcN4NjnX?= =?utf-8?q?sKAN0ePpH2d1Naala+lfz2n6eoetRBIP4vaPA92TyL3pZ0z8tp94BYTajvRuLsFiq?= =?utf-8?q?q2Eb8QPqHQ4nGRyhRrBgF5D/ZKQ2ZMwxUWr5PvviZOyWPMxuk3Vtd1nUKq79d8+tn?= =?utf-8?q?wyq35o8nIrPUJ+dTPHsq7iFTeK8kkYuAuVU6KWhZG0s4PCMCFDMuUdSjwBwuE14CY?= =?utf-8?q?8FEid+cdddZEPPgnx079f0z4eQXLjl4cCb5BLYugFI24X4BlwlsGVAd1iQLvCPKzN?= =?utf-8?q?lt2mfoL9eH7HBJNNaEtHS5dRRMMZyDjGPoMiGHlIpRZHU+XL91QWE3U7gXPJFf5pO?= =?utf-8?q?X9aiFvjA7gx43C4FtyqKeAq1Jof2Dvlz50UW6PHYJzEViyhR0VkglhJIPWe5WcvLF?= =?utf-8?q?MMLiMeZlRVZqZ99HDknOE4Z4jfB007eQha8xXhwZ3+Zsohmi0bCPfcCs/yVy0lB0o?= =?utf-8?q?8gVZNgfYKCBwd8s10PHTE3XfqfOTn7zDmeYi8SugcqKQDj+JaIQLW3Bywxpq1dFVx?= =?utf-8?q?53da3I0NLqTcuxcHhKKU7jLXQ6/2FR0tPpAUlusDV5nRG5FXWHbA20ZjZKnIcG4y2?= =?utf-8?q?mkguZ2glIK15p1y0Uy6y7qz+drE8o1EtTsGAHeY/Re+nHCg7RLV6iGCPo0tKchV6a?= =?utf-8?q?61dl2cIdMwiDTCiT8kZ6gJbbkc0iu6VdqRFviZYT/bqFhLDbvO70T5irmH+hb9Ftm?= =?utf-8?q?oyvt7zxdw3/QFAMjUar0y5G/z7nNfSM8ltPVWmEWxx5m2P8aOto436y0SFTYhQ9Hy?= =?utf-8?q?qvOlOTIeobUHwVceYW+cHxbusFde2ReMlhnlWbkFXhZQFuNS0jE5S+Y32zJCP6HLq?= =?utf-8?q?f81NQHBTZJB80LMfF4MBCeq7xdNDi5QUNmz6ROk8lv+3TFyh966ltX3jGZimkS/dV?= =?utf-8?q?iQgwwFL8mZgy6Ad6DknK4jkCHxi9VTnYL4JbtyIJLV6N65I0DHfcHEooV0E1V+NKh?= =?utf-8?q?SgO6KQUn1Ll4v/mVCQ3qQnBWjMB9Q71aH/spMq28q+jPy7pAR3tFZpFgfqowa73QD?= =?utf-8?q?nFKRijovTs4CtvgOF1roh/j2bpjaz0s6PvTssbdjIQwtH8xWjB5nPI/Z7jezFudGV?= =?utf-8?q?lXY7YOrSK5C+5ZzOaUKIGlDMBEPfn1VDmzRyZly60uRBOF/ypItj6KB6VUnaOA686?= =?utf-8?q?qcZ838EZXf7z?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6bf38bcb-a461-42ba-6c5c-08dcb15efc53 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2024 12:47:49.9389 (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: XH0hTeTJy+DHltuEhZjfMn/U6hqdAiSqQkg63wqtFSA6JDB4q9sXwRyRICYczLOhTA3mFwKiAawHhkV42YCnGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7735 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 Acked-by: Dmitry Torokhov --- drivers/input/keyboard/Kconfig | 11 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/imx-sm-bbm-key.c | 236 ++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 72f9552cb571..a3301239b9a6 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -454,6 +454,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 b8d12a0524e0..5915e52eac28 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..ca430dbb61d0 --- /dev/null +++ b/drivers/input/keyboard/imx-sm-bbm-key.c @@ -0,0 +1,236 @@ +// 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); + + /* + * 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); + } + + schedule_delayed_work(&bbnsm->check_work, msecs_to_jiffies(DEBOUNCE_TIME)); + + 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 void scmi_imx_bbm_key_remove(struct scmi_device *sdev) +{ + struct device *dev = &sdev->dev; + struct scmi_imx_bbm *bbnsm = dev_get_drvdata(dev); + + device_init_wakeup(dev, false); + + cancel_delayed_work_sync(&bbnsm->check_work); +} + +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, + .remove = scmi_imx_bbm_key_remove, + .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");