From patchwork Thu Jul 18 07:41:59 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: 13736144 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 6C866C3DA49 for ; Thu, 18 Jul 2024 07:36:34 +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=4WPWBl+UNIF8UJOX1QJA+qTKK8dUxDTksPWRgdZNkUI=; b=V3Q/raUzmEXaauB9w1PlMkj0Sc fUz5E9aQpT8rhH6JX/5iC5OJOXxgzOFUPW9abtuiZQimm4x5lH6N7b+9yqT1rsfRgHmL61i9InCZK YgdXmzP0qUsdyFk0FGyKUUNw56B7XyHoIEeS0uz0FAQEQprmaPlo5/aepI11++OG0U3VxK8RUYF5p SJ7lmNLKwed5XiFMHsfSX+MfhTOmmA9sw2vsehrzNw9mXpKUZf+I7R8Z7j4H9YxhEfyNBGhME/nam a1RjXErEWDddwegmfoBuenx+0TX+mkVPRZSyipkmPSw/MQ7D28aP/emdYXoZd3FigdGCNff4Yvf2a RJ+bfmww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sULga-0000000GEI3-1KoN; Thu, 18 Jul 2024 07:36:20 +0000 Received: from mail-westeuropeazlp170110003.outbound.protection.outlook.com ([2a01:111:f403:c201::3] helo=AS8PR04CU009.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sULe5-0000000GD7X-42Zq for linux-arm-kernel@lists.infradead.org; Thu, 18 Jul 2024 07:33:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hiwiWVLkC7dwXmJ/adWmM0Y5GJmhq3HJCpc4nhkm1UGyM5fFMqpHN4nji+Sd4F3SBoQtULPKCJh7bvzDzPw2F2/T2rUQj8b6qX7rVmCFlQx7351+j8UyBeQUsGsUb++0vjR/VY15ED6zaUDFh5ryQ5JINC31CjZS1FKUuhWQ/ge/vZWbfYys/lc+hKRZhBTTcQZHQD8sZ8/kwnUFtdx1ZXjzujqB5fbIknOoz9HAQZFXNL6a5gYB+nrKURp31MuLQ04ynVM+5w1oGhL96oWB6P/qb27fWPaPTp5q3wPX7EHL3jzwtrdZZH/hiKkfx3yimVoRicD+EM31uzbAYqk9hw== 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=aS+BdSN3NqLADKNj1nlmWVrgegNOsTP8HGqb/PTXwg/GO59dYTLzUwAd8xLoaPRl1NjW189gQOOJjxZ6hxam3es5+zNcbCLL7c/X3+Ft6P0dU5VBjS3060onAcqDOHN5YzDoHomquQJpUq2sDU8lL3GWzKryw8cwLyoE3gLYTjQv35SssKg560PUhndHBnFabG1BNLx87ue1zWFV+OLgE2YsQNLiw2xZflYhLGg18Bcc64hBsRUqYqLNfxG/9JIDSbYImuLihOj8x+qj1XcMrwEozHMWqJHDOZKL4NBEnrcw1G6xwrRp2e9uk2gTImmoxN/get7y69F9AacY4vgb6g== 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=4WPWBl+UNIF8UJOX1QJA+qTKK8dUxDTksPWRgdZNkUI=; b=DG0hbsbjchVgWlJv49SQOCRhEUXWHckJP0bCt9HnA/5O5x6diZtfNybVxbb+0PM1m9bakVTxhYBgJU9MiyowvAdytMCEFj6WIYv58Tu16269pe+BTCNOGelFuiZratVEl2T6Mc+/9vY/3Fibj7CrQfNHB8NssvXlObyCEMYPUdc= 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 DU4PR04MB10457.eurprd04.prod.outlook.com (2603:10a6:10:561::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Thu, 18 Jul 2024 07:33:40 +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.7762.020; Thu, 18 Jul 2024 07:33:40 +0000 From: "Peng Fan (OSS)" Date: Thu, 18 Jul 2024 15:41:59 +0800 Subject: [PATCH v6 7/7] input: keyboard: support i.MX95 BBM module Message-Id: <20240718-imx95-bbm-misc-v2-v6-7-18f008e16e9d@nxp.com> References: <20240718-imx95-bbm-misc-v2-v6-0-18f008e16e9d@nxp.com> In-Reply-To: <20240718-imx95-bbm-misc-v2-v6-0-18f008e16e9d@nxp.com> To: Sudeep Holla , Cristian Marussi , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Alexandre Belloni , Dmitry Torokhov Cc: Peng Fan , 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.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1721288528; l=8472; i=peng.fan@nxp.com; s=20230812; h=from:subject:message-id; bh=nWz3HeeWJlo8Xe0FnLKszmcU0B0giCY0FEpvD/2NDGs=; b=2LwFJyfPwkShGF6fAE7m8kv76JyQbnZ9LjRRuVpVoHPTCyrD0KHGdQZkeZAOVFX5GNRDkCMME lBejm0vpv6fCVbMqseqIXsLXc3bpnC04W22h2XXTZ35Fffiut2vminC X-Developer-Key: i=peng.fan@nxp.com; a=ed25519; pk=I4sJg7atIT1g63H7bb5lDRGR2gJW14RKDD0wFL8TT1g= X-ClientProxiedBy: SI1PR02CA0046.apcprd02.prod.outlook.com (2603:1096:4:1f5::14) To PAXPR04MB8459.eurprd04.prod.outlook.com (2603:10a6:102:1da::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8459:EE_|DU4PR04MB10457:EE_ X-MS-Office365-Filtering-Correlation-Id: ffd4a4cf-0137-479a-73c1-08dca6fbf195 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|1800799024|366016|52116014|376014|7416014|921020|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?cIvL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Kk70kNNS53WVS?= =?utf-8?q?uicGdByLr7jQzV8RSyEB5Ev/2zckXODo3RJ/pFQg3wi1lTtfVtgZkayfY9goJ33P8?= =?utf-8?q?8rTKi8Jn4nrmA0RCgxLH7EJ8sXF3GKB0NlV+6K+JQEA9iaENyJgjjwC8j8/yaCiY/?= =?utf-8?q?JS4Wx7vYk0SZe5LFubq0JNu/ADPhmaThUhhNvQyIQx69z60YKnEECl/Br1IMlWKGX?= =?utf-8?q?Y9htsyO4Rx6SWCSZXa8stpckH85l/M6H5LhlFX+ehpE3ReiV9KWAOV6Nk7LWbafGv?= =?utf-8?q?7cNjE5W+G2BNwyhImS5nE/bqDqbsIPFQ64M5LbgLAvbfHQkHvr0TcYddl4TFamTQB?= =?utf-8?q?R6/thVzdQyDvbBv3Ibmt9doRGyc1rjtY1XNpIjaacmrtWtXyDcNPTQi0ejfvQsDJs?= =?utf-8?q?3DVaSDkpf6irQNndataTfahygDxiBKRDTB2i5zKlRh4DE0relgVWXr0+nUss6pgIW?= =?utf-8?q?18OFabx99zEvGrd/kY+R96oLZ1e4beGFRJnEf+QKinRUZHViVFF3nLY=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)(1800799024)(366016)(52116014)(376014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?60Z1KGBmyuMq09QMJB8Q5FmeC7L1?= =?utf-8?q?2jX0JguKyFlTCXbvvuf/rWLKR1w6RO9dydgx/90CGNOQw3mHiPVjuklcMFzzOFe6P?= =?utf-8?q?HCWortNMQn0AKRZuRRjL2i+3nm5XpXtfLvaQVqwlqlqaZqK+fm5h6g4eGHnWg9oje?= =?utf-8?q?R99zenAuwig72iXNGbmsHRg6DQ8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deTvwwFe0y2JihvMXwGnGPpsIN1uiUFpsH?= =?utf-8?q?dyyR/ug6qFlsO9CjdMJJWkPYgBwWkvfLuSpHZ4OZwa4h7QLq+Igg1ibuQLTvOcfkF?= =?utf-8?q?BinCqIj5EJEgJs5ag7y41NUBlaWwWHTQagEFsEMQW4al26FrhFa/FpF01d2X6UZIn?= =?utf-8?q?AoFCYOSbd2Svuy4mqc29A9UWDefX/WLB74osOf4DEGFMzemQyfc3ZnGhpK1LSuzvH?= =?utf-8?q?rAHvfVhZ++gjQ9PnM/v1I2BLmQfn7VVV2PWLuX2wyFXS/jnR9nnH3oT6fQi+cshhL?= =?utf-8?q?rGGmU+UnX3PFotxAvDBtAqgPN53S7/qqOnh8KMHjhxkzO+UNyO3SRDfAZGf40Nbx4?= =?utf-8?q?/KyOl1Oy7WVkg352Zl93Ez2t23UW6buln2EGiEKgMfd4aafr6350trY1hpakuX9bh?= =?utf-8?q?s4fLJjjW9SeBh7shLkrZ08mmgFdUu8YaMZFm9eNmmRycr5rctt6B22Hugj3KM9vvx?= =?utf-8?q?MSZMtJyVVDZl?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ffd4a4cf-0137-479a-73c1-08dca6fbf195 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8459.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2024 07:33:40.1177 (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: gWdzkB4hZSegQuDweBotwSZqJK0aYUA2ADUHv7EJnR6FWIsGnqG8vj/foNvGryqVX8zHaEAtLYfV12j9LnIl9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10457 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240718_003347_234886_328A7F23 X-CRM114-Status: GOOD ( 19.69 ) 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 | 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");