From patchwork Wed Jun 11 20:03:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Kayode via B4 Relay X-Patchwork-Id: 895667 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 B1EDC2BDC29; Wed, 11 Jun 2025 20:03:00 +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=1749672180; cv=none; b=UXwRI4Zbq1DSYaDIWRipkAQ1+yplucth8OX5kUCiccpFtwLzO4is5vMJNu4gi90gUfBi0b7uPDfMVWovcpC+FkzaMokoxyDrPALEcDfJccs3e1J6BkIWjHC53c9OD4CzewI4cKVDa46a+GYI95DzOzc0XSu2c7jMLvmq9uYqqis= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749672180; c=relaxed/simple; bh=cJT2EuxXe+/Es5N8Tk+Lislg1ISVab+68e2xEZ4C6JM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pHvKlw9w9hTiIdb6wR2U73OjaA4FXh+0bxN3+e4F9aY/r5qviEC0LOg9om6zcaWRQZ27FgGOiSKrvcBJYg7zv8V0frPXnud0HlcCuqRmicF2fG7W8e6VLjcQw4Rq0O3WPEDpT4U5aNXVaqKmjV8l+kWBoWUrKY0JfH4YHZvMdDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WrHa5vbr; 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="WrHa5vbr" Received: by smtp.kernel.org (Postfix) with ESMTPS id 327FCC4CEFE; Wed, 11 Jun 2025 20:03:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749672180; bh=cJT2EuxXe+/Es5N8Tk+Lislg1ISVab+68e2xEZ4C6JM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WrHa5vbrvsV4i8aNOsMbFcph+hMabA14SvdPasvm8chKGr7rD7nd9suaprUldrkPx 9737GCTe51jGSUPUSPYQufzR+bKK0Dr7PSVw3yt5tZ7bfDvYDeGQuBCrbjU4iFaU4W uQHVh88/EY1CFS0+j+Da3tFZcG6tZBdC3laF+nGOcsbY1I5WkQBn8e3hKIBvOnjZyW goIq914SGztcbvRlFPJy9/UC+59XaLpY6V0u+DDlmjJkVrkITsiiLilA2/gTymfF3i 0FHCbaCJx1UuV4IN/WPIWp8uJwFLI34YRVKUFx4Bsm6qfIpIQrexLU1UF7YPeAswPy Hhxyp1Er64Fdg== 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 27113C7113E; Wed, 11 Jun 2025 20:03:00 +0000 (UTC) From: Samuel Kayode via B4 Relay Date: Wed, 11 Jun 2025 16:03:01 -0400 Subject: [PATCH v6 4/6] input: pf1550: add onkey support Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250611-pf1550-v6-4-34f2ddfe045e@savoirfairelinux.com> References: <20250611-pf1550-v6-0-34f2ddfe045e@savoirfairelinux.com> In-Reply-To: <20250611-pf1550-v6-0-34f2ddfe045e@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 , Samuel Kayode , Abel Vesa X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1749672178; l=8036; i=samuel.kayode@savoirfairelinux.com; s=20250527; h=from:subject:message-id; bh=JS/l4QGiX7+nAuPrzFit8kIZwe3Eqs9OB3rvAc7d51w=; b=p5xAYewfEWVIJ7URB/SoCny/rrjuSluc18Nkv0zaydklEIjEvyS4Ow42le71XP2aXnvACIYI5 8nyuQ0G7sgFD0mzZUC+2V+gj4qw3hs9B7zi4g/ibJJJ0RPa7n5WUUD9 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. Signed-off-by: Samuel Kayode Reviewed-by: Frank Li --- 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 | 183 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index f5496ca0c0d2bfcb7968503ccd1844ff43bbc1c0..47b3c43ff0550f14d61990997976366436411adc 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. +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 6d91804d0a6f761a094e6c380f878f74c3054d63..c652337de464c1eeaf1515d0bc84d10de0cb3a74 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -62,6 +62,7 @@ obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o obj-$(CONFIG_INPUT_PCF8574) += pcf8574_keypad.o obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o +obj-$(CONFIG_INPUT_PF1550_ONKEY) += pf1550-onkey.o obj-$(CONFIG_INPUT_PM8941_PWRKEY) += pm8941-pwrkey.o obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR) += pm8xxx-vibrator.o obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY) += 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..7e604c5544066eefbd84abe7bdff767b8b8978ab --- /dev/null +++ b/drivers/input/misc/pf1550-onkey.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Driver for the PF1550 ON_KEY +// 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_dev *pf1550; + bool wakeup; + struct input_dev *input; +}; + +static irqreturn_t pf1550_onkey_irq_handler(int irq, void *data) +{ + struct onkey_drv_data *onkey = data; + struct platform_device *pdev = to_platform_device(onkey->dev); + int i, state, irq_type = -1; + + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) + if (irq == platform_get_irq(pdev, i)) + irq_type = i; + + switch (irq_type) { + case PF1550_ONKEY_IRQ_PUSHI: + state = 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 = 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; + int i, irq, error; + + onkey = devm_kzalloc(&pdev->dev, sizeof(*onkey), GFP_KERNEL); + if (!onkey) + return -ENOMEM; + + onkey->dev = &pdev->dev; + + onkey->pf1550 = dev_get_drvdata(pdev->dev.parent); + if (!onkey->pf1550->regmap) + return dev_err_probe(&pdev->dev, -ENODEV, + "failed to get regmap\n"); + + onkey->wakeup = device_property_read_bool(pdev->dev.parent, + "wakeup-source"); + + input = devm_input_allocate_device(&pdev->dev); + if (!input) + return dev_err_probe(&pdev->dev, -ENOMEM, + "failed to allocate the input device\n"); + + input->name = pdev->name; + input->phys = "pf1550-onkey/input0"; + input->id.bustype = BUS_HOST; + + input_set_capability(input, EV_KEY, KEY_POWER); + + onkey->input = input; + platform_set_drvdata(pdev, onkey); + + for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq = platform_get_irq(pdev, i); + if (irq < 0) + return irq; + + error = 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 = 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 = to_platform_device(dev); + struct onkey_drv_data *onkey = 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 = 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq = 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 = to_platform_device(dev); + struct onkey_drv_data *onkey = 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 = 0; i < PF1550_ONKEY_IRQ_NR; i++) { + irq = 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[] = { + { "pf1550-onkey", 0 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, pf1550_onkey_id); + +static struct platform_driver pf1550_onkey_driver = { + .driver = { + .name = "pf1550-onkey", + .pm = pm_sleep_ptr(&pf1550_onkey_pm_ops), + }, + .probe = pf1550_onkey_probe, + .id_table = pf1550_onkey_id, +}; +module_platform_driver(pf1550_onkey_driver); + +MODULE_AUTHOR("Freescale Semiconductor"); +MODULE_DESCRIPTION("PF1550 onkey Driver"); +MODULE_LICENSE("GPL");