From nobody Wed Oct 1 21:33:59 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D7E228137D; Wed, 1 Oct 2025 15:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759333362; cv=none; b=Q0clWEvNGo7c35B36MVwzm6f2QAfC3jYngDXt3rTMCRj30VrI3rg9LMrW/4I0+n9hQpsfSv4R2u8ksohn4YEUXZXE2xV+dDrNe4uKbgg1YmDcRxP68GXHckle3oKbcSOM6Hdyfq/9VsP0/J2xmC2lcvzrh3+HehqohXBUM6jV5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759333362; c=relaxed/simple; bh=vWsSbOnmTbzOaRXKRWHpqUZjm/wtCmmXNV5NSSbCJJI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VsA/bc92q5yGCVBpFrx3bkjNfnpqLaaJ/tn37OfeUQ592h6XpGZLIFxQe0FsIjRjfP0yTyriDTAvDx7FjQeoIjueirV3d2Z90VgdeIZQEwGWAg9cyUGdKKf60vbIvfiBdbKZ3eGu0pC9exog/9lylrSpVTHdQlNQ7zONXlZoJBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X6lk02Ku; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X6lk02Ku" Received: by smtp.kernel.org (Postfix) with ESMTPS id 424C5C4CEFE; Wed, 1 Oct 2025 15:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759333362; bh=vWsSbOnmTbzOaRXKRWHpqUZjm/wtCmmXNV5NSSbCJJI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=X6lk02KuK14i0QBpNasLxQ2jzj1cW+yJ7eUFfomg+p95KFDh6JJ59B3ruuzd4ewza ay+8K4XHwHcRrJi+E5b7xSrqbslJGCDhue2u0I8yLVSCUKLjXkTS99CA4v5fgswQa9 ib4/brFPqsNGds6V/Eo38coyRKCjsgpf9qJkWl1xydd1z96Jlw1fe4ShyfFiSPe+jh a6YBvfelrKD4Dlkj7jCI9lxAuwmHC2RsFWGitVdaZTt7hAPx/VbV0OdeUQUXSg8aZ5 MgDV10ggY8D9jC4CueFX0mQmHY0SqLN8A4rlBp6uk8zq4p7mx0Bt5jRVbVaNbcPhPN g4RaTeI7EXTPQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263A2CAC5BB; Wed, 1 Oct 2025 15:42:42 +0000 (UTC) From: Samuel Kayode via B4 Relay Date: Wed, 01 Oct 2025 11:42:40 -0400 Subject: [PATCH v12 4/6] input: pf1550: add onkey support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251001-pf1550-v12-4-a3302aa41687@savoirfairelinux.com> References: <20251001-pf1550-v12-0-a3302aa41687@savoirfairelinux.com> In-Reply-To: <20251001-pf1550-v12-0-a3302aa41687@savoirfairelinux.com> To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Liam Girdwood , Mark Brown , Dmitry Torokhov , Sebastian Reichel , Frank Li Cc: imx@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, linux-pm@vger.kernel.org, Abel Vesa , Abel Vesa , Robin Gong , Robin Gong , Enric Balletbo i Serra , Sean Nyekjaer , Christophe JAILLET , Samuel Kayode , Abel Vesa , Frank Li X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1759333360; l=8949; i=samuel.kayode@savoirfairelinux.com; s=20250527; h=from:subject:message-id; bh=0s7SKBUt7nAhM1EAt4/u4DUx3xAzyPcauJh/PwKP0oM=; b=D0wGPdQU7QrXEHdzcZiwReoQKcQo9T3UVTNBKY5UBlKJebIMrHSAKZ9QrfWCDdoeDQyue0aG4 usaPJQj2HPYBhF6SXWIlIuwkXMfvvgXdsm85VKyM827NRggDNEa2mEK X-Developer-Key: i=samuel.kayode@savoirfairelinux.com; a=ed25519; pk=TPSQGQ5kywnnPyGs0EQqLajLFbdDu17ahXz8/gxMfio= X-Endpoint-Received: by B4 Relay for samuel.kayode@savoirfairelinux.com/20250527 with auth_id=412 X-Original-From: Samuel Kayode Reply-To: samuel.kayode@savoirfairelinux.com From: Samuel Kayode Add support for the onkey of the pf1550 PMIC. Acked-by: Dmitry Torokhov Reviewed-by: Frank Li Tested-by: Sean Nyekjaer Signed-off-by: Samuel Kayode --- v10: - Use regmap_clear_bits instead of regmap_write v9: - Requested by Sean: - Add support for disabling power down of system by onkey v8: - Pick up `Acked-by` tag from Dmitry - Use C++ for SPDX license header comment and C type for rest of license comment v7: - Use reverese christmas tree style - Drop unecessary 0 in id table's driver data v4: - Address Dmitry's feedback - Drop irq variable in onkey_drv_data - Drop keycode variable in onkey_drv_data - Define wakeup as type bool - Use platform_get_irq - Use type const for struct pf1550_dev in onkey_drv_data - Replace (error < 0) with (error) in if statement when applicable - No need to define driver_data in table id - Define driver.pm with pm_sleep_ptr v3: - Address Dmitry's feedback - Drop compatible string - Remove dependency on OF - Use generic device properties - Drop unnecessary includes - Drop unnecessary initializations in probe - Always use the KEY_POWER property for onkey->keycode - Do mapping of irqs in MFD driver - Define onkey->input before interrupts are active - Drop unnecessary input_free_device since devm - Manage onkey irqs instead of the main interrupt line. - Fix integer overflow when unmasking onkey irqs in onkey_resume. v2: - Add driver for onkey --- drivers/input/misc/Kconfig | 11 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/pf1550-onkey.c | 197 ++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 209 insertions(+) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 0fb21c99a5e3d1230d7f40f99e0c2d360bbe80e8..4312a1f533e370b4bbef439bcea= e8f0969712249 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -179,6 +179,17 @@ config INPUT_PCSPKR To compile this driver as a module, choose M here: the module will be called pcspkr. =20 +config INPUT_PF1550_ONKEY + tristate "NXP PF1550 Onkey support" + depends on MFD_PF1550 + help + Say Y here if you want support for PF1550 PMIC. Onkey can trigger + release and 1s(push hold), 2s, 3s, 4s, 8s interrupt for long press + detect. + + To compile this driver as a module, choose M here. The module will be + called pf1550-onkey. + config INPUT_PM8941_PWRKEY tristate "Qualcomm PM8941 power key support" depends on MFD_SPMI_PMIC diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index d468c8140b93da5bb537e8a3baea2b90e7bb4229..bbf1aa7bec4f10274af5ffcb5a5= 651bf7c776dc6 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -61,6 +61,7 @@ obj-$(CONFIG_INPUT_PALMAS_PWRBUTTON) +=3D palmas-pwrbutto= n.o obj-$(CONFIG_INPUT_PCAP) +=3D pcap_keys.o obj-$(CONFIG_INPUT_PCF8574) +=3D pcf8574_keypad.o obj-$(CONFIG_INPUT_PCSPKR) +=3D pcspkr.o +obj-$(CONFIG_INPUT_PF1550_ONKEY) +=3D pf1550-onkey.o obj-$(CONFIG_INPUT_PM8941_PWRKEY) +=3D pm8941-pwrkey.o obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR) +=3D pm8xxx-vibrator.o obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) +=3D pmic8xxx-pwrkey.o diff --git a/drivers/input/misc/pf1550-onkey.c b/drivers/input/misc/pf1550-= onkey.c new file mode 100644 index 0000000000000000000000000000000000000000..9be6377151cb3be824ab34ff37f= 983196b909324 --- /dev/null +++ b/drivers/input/misc/pf1550-onkey.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for the PF1550 ONKEY + * Copyright (C) 2016 Freescale Semiconductor, Inc. All Rights Reserved. + * + * Portions Copyright (c) 2025 Savoir-faire Linux Inc. + * Samuel Kayode + */ + +#include +#include +#include +#include +#include +#include +#include + +#define PF1550_ONKEY_IRQ_NR 6 + +struct onkey_drv_data { + struct device *dev; + const struct pf1550_ddata *pf1550; + bool wakeup; + struct input_dev *input; +}; + +static irqreturn_t pf1550_onkey_irq_handler(int irq, void *data) +{ + struct onkey_drv_data *onkey =3D data; + struct platform_device *pdev =3D to_platform_device(onkey->dev); + int i, state, irq_type =3D -1; + + for (i =3D 0; i < PF1550_ONKEY_IRQ_NR; i++) + if (irq =3D=3D platform_get_irq(pdev, i)) + irq_type =3D i; + + switch (irq_type) { + case PF1550_ONKEY_IRQ_PUSHI: + state =3D 0; + break; + case PF1550_ONKEY_IRQ_1SI: + case PF1550_ONKEY_IRQ_2SI: + case PF1550_ONKEY_IRQ_3SI: + case PF1550_ONKEY_IRQ_4SI: + case PF1550_ONKEY_IRQ_8SI: + state =3D 1; + break; + default: + dev_err(onkey->dev, "onkey interrupt: irq %d occurred\n", + irq_type); + return IRQ_HANDLED; + } + + input_event(onkey->input, EV_KEY, KEY_POWER, state); + input_sync(onkey->input); + + return IRQ_HANDLED; +} + +static int pf1550_onkey_probe(struct platform_device *pdev) +{ + struct onkey_drv_data *onkey; + struct input_dev *input; + bool key_power =3D false; + int i, irq, error; + + onkey =3D devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); + if (!onkey) + return -ENOMEM; + + onkey->dev =3D &pdev->dev; + + onkey->pf1550 =3D dev_get_drvdata(pdev->dev.parent); + if (!onkey->pf1550->regmap) + return dev_err_probe(&pdev->dev, -ENODEV, + "failed to get regmap\n"); + + onkey->wakeup =3D device_property_read_bool(pdev->dev.parent, + "wakeup-source"); + + if (device_property_read_bool(pdev->dev.parent, + "nxp,disable-key-power")) { + error =3D regmap_clear_bits(onkey->pf1550->regmap, + PF1550_PMIC_REG_PWRCTRL1, + PF1550_ONKEY_RST_EN); + if (error) + return dev_err_probe(&pdev->dev, error, + "failed: disable turn system off"); + } else { + key_power =3D true; + } + + input =3D devm_input_allocate_device(&pdev->dev); + if (!input) + return dev_err_probe(&pdev->dev, -ENOMEM, + "failed to allocate the input device\n"); + + input->name =3D pdev->name; + input->phys =3D "pf1550-onkey/input0"; + input->id.bustype =3D BUS_HOST; + + if (key_power) + input_set_capability(input, EV_KEY, KEY_POWER); + + onkey->input =3D input; + platform_set_drvdata(pdev, onkey); + + for (i =3D 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq =3D platform_get_irq(pdev, i); + if (irq < 0) + return irq; + + error =3D devm_request_threaded_irq(&pdev->dev, irq, NULL, + pf1550_onkey_irq_handler, + IRQF_NO_SUSPEND, + "pf1550-onkey", onkey); + if (error) + return dev_err_probe(&pdev->dev, error, + "failed: irq request (IRQ: %d)\n", + i); + } + + error =3D input_register_device(input); + if (error) + return dev_err_probe(&pdev->dev, error, + "failed to register input device\n"); + + device_init_wakeup(&pdev->dev, onkey->wakeup); + + return 0; +} + +static int pf1550_onkey_suspend(struct device *dev) +{ + struct platform_device *pdev =3D to_platform_device(dev); + struct onkey_drv_data *onkey =3D platform_get_drvdata(pdev); + int i, irq; + + if (!device_may_wakeup(&pdev->dev)) + regmap_write(onkey->pf1550->regmap, + PF1550_PMIC_REG_ONKEY_INT_MASK0, + ONKEY_IRQ_PUSHI | ONKEY_IRQ_1SI | ONKEY_IRQ_2SI | + ONKEY_IRQ_3SI | ONKEY_IRQ_4SI | ONKEY_IRQ_8SI); + else + for (i =3D 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq =3D platform_get_irq(pdev, i); + if (irq > 0) + enable_irq_wake(irq); + } + + return 0; +} + +static int pf1550_onkey_resume(struct device *dev) +{ + struct platform_device *pdev =3D to_platform_device(dev); + struct onkey_drv_data *onkey =3D platform_get_drvdata(pdev); + int i, irq; + + if (!device_may_wakeup(&pdev->dev)) + regmap_write(onkey->pf1550->regmap, + PF1550_PMIC_REG_ONKEY_INT_MASK0, + ~((u8)(ONKEY_IRQ_PUSHI | ONKEY_IRQ_1SI | + ONKEY_IRQ_2SI | ONKEY_IRQ_3SI | ONKEY_IRQ_4SI | + ONKEY_IRQ_8SI))); + else + for (i =3D 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq =3D platform_get_irq(pdev, i); + if (irq > 0) + disable_irq_wake(irq); + } + + return 0; +} + +static SIMPLE_DEV_PM_OPS(pf1550_onkey_pm_ops, pf1550_onkey_suspend, + pf1550_onkey_resume); + +static const struct platform_device_id pf1550_onkey_id[] =3D { + { "pf1550-onkey", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, pf1550_onkey_id); + +static struct platform_driver pf1550_onkey_driver =3D { + .driver =3D { + .name =3D "pf1550-onkey", + .pm =3D pm_sleep_ptr(&pf1550_onkey_pm_ops), + }, + .probe =3D pf1550_onkey_probe, + .id_table =3D pf1550_onkey_id, +}; +module_platform_driver(pf1550_onkey_driver); + +MODULE_AUTHOR("Freescale Semiconductor"); +MODULE_DESCRIPTION("PF1550 onkey Driver"); +MODULE_LICENSE("GPL"); --=20 2.50.1