From patchwork Fri Aug 23 09:05:23 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: 13774780 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013006.outbound.protection.outlook.com [52.101.67.6]) (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 628D3185E7A; Fri, 23 Aug 2024 08:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.6 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403447; cv=fail; b=KnmFdCRXqk5sERcFYjOB8SuG2MMypa+5h2uaf6/65c156Dl6qN/pFEAIKneCdZ97+fEnFQflj+ORk8J5cXHh9mfnn2MNYQHwmtBPIucWQ3JZ8aDCjh6B9D64bT7TKHr6B0/L+D3euiPfX3ihSVPzZrpmOe+79BMjCepncOwhlfQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724403447; c=relaxed/simple; bh=kxc2eMKo0SVpN4AB/VCrof0om0KnqGLBnf+CDyaUvMI=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=QebUt3CUvkHryxWD1F5tlx3iDUYvkr0YRxXUFnHDb/Y/Blk+u8iwtJULMgp1IbN8LPnn9GvNLWDQ+2dhH97KNLW0o9DgIkIZYm5yfuCduiKeEzA80xFaoeDGj4DH/zsKa1Ha8DwOWl56khtAuOpfu6psf2v75nOVi/lZ527XvEA= 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=FsEEpEbR; arc=fail smtp.client-ip=52.101.67.6 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="FsEEpEbR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kpij4SS1cQ54AW18dYMCid13TI+bny1rpx9XE/yAQD/tl8nj9gbufppNN3DLQya8xPbaTAckFI6/rZs9Vzp9+FcmnZXhCyPYiFuF+cIcuAj71i+/yINeiq3lVDRqudfw61BDLcB39038dQZbcZCGbCLS7RO1gLfid1bkNNBK9Ov6QXHh8wkphhFrk5DAtIlwNu6hUAOZym1lG/Jq+nHwfvLu/1oQu2NtjAuYvRXRFTjwA0csp2jPOJONeBHzUZ9z7qeEteoMzphDEi6v++0dpEiei0ApJ1zoRQaS673JW+RaQzbu33uPf+VKg0tNm/ud1/W3zf/Ce59kcdVGhj1lIQ== 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=VwVO40Kbuaig/BZztDwJec5em76QDLNVCraOKEbMZg0=; b=qALvMGGBoIc0rmpTqOxIxw37JH6YiTdyCTrWv0I40f6ZvzVn+cRE+fZMzr2gOZzYhXbjKbXlZxFi5B30+HK+Zw7eArccmQK5AsGpqqPEd7Moxu2UCnnfD0cC+7F2cT5SjtHne5VPBHQwp8jeDZTyA9YJTRLZoHgOcqjj0J/H0I2LJHcplUgkKiyRmZccpGL9bDrJ9okVov8YEXhWMZ8UpuCPfgL1JuxAIy6CUUNErec7re1OgsDVjeheOJZNsXk7ztTWVryxu4hc8pNCfx+kTdhJGsPlJ0yJYDFDGWxOGGxBSyRDhtzxTTTWBb/InH5PLtRl0LWEt9NnTsPxwdaRCQ== 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=VwVO40Kbuaig/BZztDwJec5em76QDLNVCraOKEbMZg0=; b=FsEEpEbRCaUcGGbeP9PGJ63XpVeUmMWAY8pw5Oj8fsjBZE/1CQrZzexol6YTZylmxF/yp7c58zV+Ohg54s7yvmI67aWZ8mbsMp32mPlVGPcmwsNPicyGJ7/7s8kkroRWTKvECGLWlJWuNCea9pWq5d3ItP3qMzVFdbxogkQBQsqAHIFXKWFC3RxEenRn+P3fhwA2QfWxUQuV6dY0etdFA+m34rddzIaaOmOaB1KYXd5x/84BWPhfeQY8/GdljT9j1wDSMISzGHigwefzBu7XlKSK10DoqRsv40zTtxdzMb9fzW18H7SBzYOmm15wHWVdaAj8K4/VvbedkvMEWhS7LA== 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 DBAPR04MB7271.eurprd04.prod.outlook.com (2603:10a6:10:1a6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Fri, 23 Aug 2024 08:57:22 +0000 Received: from PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630]) by PAXPR04MB8459.eurprd04.prod.outlook.com ([fe80::165a:30a2:5835:9630%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 08:57:22 +0000 From: "Peng Fan (OSS)" Date: Fri, 23 Aug 2024 17:05:23 +0800 Subject: [PATCH v8 7/7] input: keyboard: support i.MX95 BBM module Message-Id: <20240823-imx95-bbm-misc-v2-v8-7-e600ed9e9271@nxp.com> References: <20240823-imx95-bbm-misc-v2-v8-0-e600ed9e9271@nxp.com> In-Reply-To: <20240823-imx95-bbm-misc-v2-v8-0-e600ed9e9271@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=1724403944; l=8234; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=sBgFKxgc7cdv86yg3Whp2f3mLa6n9LiELZb9Y0Qgs7w=; b=3W6TfSHzhGlTGIFXb/Sq/VuSvXyypK5QU2RUIMyP1lXLuhiXl3qxqa1iQzJO4cLJpppoy7wvL NmlVg2jAf1rBN+IVFIxDgoefBntCoOw8z4sWnCFI5MCaASTwp5Okj7P X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SG2PR01CA0173.apcprd01.prod.exchangelabs.com (2603:1096:4:28::29) 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_|DBAPR04MB7271:EE_ X-MS-Office365-Filtering-Correlation-Id: bbbebbe4-0d6c-4260-a3cd-08dcc35199f5 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|376014|7416014|1800799024|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?ltpHiDlf8qRaxkleVuTdWmoZq3zbN6U?= =?utf-8?q?LQDL6JG5yOgfj8C8kx3sGd5kAChOHZv9KRj5zqLLWJkbHloHUPM0LttHGrh4qEfBA?= =?utf-8?q?ov3AUK6tNlVJNkRrUKHAP9y/dsn+82nhOMXUIShAe8S8RYBOBIyDBnlS3V5A+ltqn?= =?utf-8?q?HyZps25cOfYR/YoM9X0PhWkgX+dJ2TrvQiu11VTwB5FolnlvV8g1To3Ksvvv5kVlP?= =?utf-8?q?0YVvl0YK9Pa71miaUQPRMPLWn+t9dTjfxlBVwBDvvk5ug+QDE8irJwLLDBSjNBJ1q?= =?utf-8?q?zod2LaUo23gWUhjyZBsjluKvQ52Ay/mWyIutMZGVIg11P7Q86KUfrpAmbTNQ/GOLb?= =?utf-8?q?cDOWNCG2wEc/uozNRqie7z82nuWRpo8ma9meeRMW+Kbs8cm/cAWHKhy32V7g5eHTV?= =?utf-8?q?DvM2XU5XOo3BZ5pLcZ93XXqCjwKt7Xeg4JHazQR2ENH2612iyRBk6C/2ED3j3Br9b?= =?utf-8?q?6dZ02d+ncbJ9THqNFFNQwQdtvzRQCwfjZgfCQPBGoXYOVY/cfBqFz6La4LK6m5mza?= =?utf-8?q?MV2qLI3GyWbFoZbgR1SQutq1BF4g9+pFo47v8ootv7z059Jz078VXmk89cMFMRdbx?= =?utf-8?q?gkf2dVzxACA/4/+F6DufR/1V4xjl7TQEh7Rq8KQxm25mzEb4OLRM8Qn2T3Hhz39vb?= =?utf-8?q?rMsMeoF2FPALUO2jEAL1pxK5nXfLQJNePNVr6jmboS7MXeACQOs02A09C4NUMCXWx?= =?utf-8?q?p4OFFXqWdeSR7ci5wnJqijIDMlQsQUf4o9M0nlgFvI6WFS8aGWvzjkGfpJxsM/9uA?= =?utf-8?q?4+b4GcuVTDogwdNN6v2xip+XLrAXvdAC/1xHCBWKRZLN79axLho8SnGvyq9gbrX1H?= =?utf-8?q?K6YAavKzG6VDn4QvWApk0nYD1ClnEqYkEdaHwT+d3I/lAi50c7J3AhtOci8xBDcv9?= =?utf-8?q?ZUpJbH5bKmOq/1Xi8u98QZsoUGSov06ryZSEn3TTuEVn9bKU/XlO+gXgFvn+3x1Im?= =?utf-8?q?9zbD2VN1XsW2ufCxrhk/8eTIr5Jgi6m5HbF8zgcLvpxv+u2RuLSZP3m4ii5ngA8WD?= =?utf-8?q?vneovtFlKJYttu4Nt/J78oGBZgO+q5PX1ccalBItZQ8wVUpVjUIMK/PZMc+PKOLO7?= =?utf-8?q?kbCp2z1VR/rXieoGx8GiXTqWSWrcgUysrwz+xMVQ2bPxFAf6CZsMRf3SlfxCHmIi/?= =?utf-8?q?zheqgitMJr9pHW7mdHK7ShuX/y+vny8dsI/ETeuhmqpncM+usYKifIzBxUjzauZB1?= =?utf-8?q?QH7z1MCcyHtVkO9ErUR1E+bsIr7DU0HrbmDhsf+bZ+CZQDPo/TEqzq6bINciQoW0o?= =?utf-8?q?Gols0uCbxiNU5nfACQ+w5qDdk8fxSyBZF2Gy5U++17zk8cjENvxJN76xUQJffJsmP?= =?utf-8?q?TZ15x+LspEuXjchpFBv1z7PbeDRYoPWIkZ1xhrS3sJ5BMKYbL/lnXso=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)(376014)(7416014)(1800799024)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?R31BB3swEwVIqeWfAjIWdOnPprwx?= =?utf-8?q?2RQ7BfRFJGdgw7ppOYGFkSKmYEZ0uwpBEuoVOR5vnf7NqVTJl37fLyzL0sejw3FAC?= =?utf-8?q?fwk8W9HpXucHAgTeE9dAZljZH/ON1qFV7Mqr71WkE2gxkz6GzeY3/x9fZAd1//PXd?= =?utf-8?q?SXR7BCCgL4nh839+0OCtw5tpIkRER0c4qz8w4w4X9B+4OSMzD05pFRy1DPByMf/dG?= =?utf-8?q?GRTBiLimSl5omhHfbI6R66mKXnQ+S02aqVQzyB3mcTIT238VyHxNEXovPaeoLBYXG?= =?utf-8?q?kHeEsmSV+s8OqmWdqKKxbvUmVAqZsfr79Hra0DcSWmZq8sMVzgqwatVvLUR+AxxRg?= =?utf-8?q?CE0h/XvY6CHAyeaAcJqEDD4pdXu+sbnvqcSzNL5XAf3IbZ9hH8nYf+pGBydFbRTcM?= =?utf-8?q?ByXC2QdNps81lpObFe1D6sHxyLoNKYUbrTq4s8fPWuCF1BmHV+k+4uM0N8GdpD7rE?= =?utf-8?q?JXrNK5wxh2G0HWwnPyccb2mfLaFeHOwkxA7/VadN8fn/6FwUUM7NuuuTyR1x+oy1H?= =?utf-8?q?DN3zAu1TbXGxn13ZtMfBSBK1E0YgZ4wqA1S27FzTcCU+mx1++2NcSUbCG2EOf2Hfg?= =?utf-8?q?iJPCWxnVsnLFxgv6nV5NoG/YQkKgxEy3Q5HPSCPWfx8pCOCnSB9ccEhNgQOg0e14M?= =?utf-8?q?LLxewfnRDgP7M0oFlQ95db89Da1y+Ap2xI0BehDn1wdIK7KM4zIs9Zg+8hraHZMCj?= =?utf-8?q?DtOv4Qh22E+pZfQV6Fb+xzxpkc14QzdBaY69xclCYmYwfdEuhZGqD1ywaygrd1Xam?= =?utf-8?q?ZCv/L0WSxNKhNqpah9QRXPASR40gnQnrIbNTuW7F0QaFRk411H5zusmm0bTXKaApA?= =?utf-8?q?3rmdDHgdPxSt9mCZvR5s+3E/2m7Z5BJkixfQsnOiGwV5T4ObLAXmZt55p/4M6znTh?= =?utf-8?q?CuPKb1QdXqKb2i/0QMh5856VPxtJbeFz578E8mX8PCwhAz+awwDUOFupp9ew7hB2y?= =?utf-8?q?6R912eYZXenBeG0mn+vstPhKp+K9GXXeCPZeWlxNC5TxQX65qAdQTBCpX7Vba8xeO?= =?utf-8?q?0V17sOvQM87qP2EeVAF0U8TNeafV4GEu3DzHYGirg+9xd+94s58UXoIJQoTDt6OPf?= =?utf-8?q?mkbiyz16r9/fkqudx6tCjL9A5z3Ayw60OKNQwGpdqnjY3Z804u45b5HvJZux86cRX?= =?utf-8?q?NnAhTjcKajP6ZUjtcjKMXptp16Vvke4NjPV6xbAkmOmpbmbWjuDzuzOOuQLEOQE3m?= =?utf-8?q?5rMuhYzxeGAirdg15Gz62Mv9IS7/qHjKoVJVld9QyJe67EoCaiH0XyCsS+ywvpWhE?= =?utf-8?q?Uw2RCJVDXQh0sTuM99tenmTg7U8AdGCAElWJ5YK3MQg0ael4nG+HO8An9nPONGt6O?= =?utf-8?q?S/ZfCtgXwZDrSWV5M07vh9iveSW1QNurYnejFiHZkzgUPARsIiLnUby09jLysRdE8?= =?utf-8?q?27euusDBV2jZj86wMHnUn2WrQDMP637dT/ZS3/TEzBTorcensmfIcy/WMrPKCX0QI?= =?utf-8?q?RZ83bNpV5R5Mi9tIP8u/AJ9rN0SRLgafVmadOMJNQ/gVmFWPuWG5GBLOvLisuxhlo?= =?utf-8?q?GQyBNXSVyLRL?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbbebbe4-0d6c-4260-a3cd-08dcc35199f5 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 08:57:22.3720 (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: NX6BawmhwsvRj7fCFTggvMsyyjGYapeA0GnX72h39q4sPcZbPXW4m7OgLHERFHYVpZfitbI6iNZfpmGkAultfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7271 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. Acked-by: Dmitry Torokhov 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 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..96486bd23d60 --- /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); + + /* + * 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 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");