[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251020-twl6030-button-v1-2-93e4644ac974@kernel.org>
Date: Mon, 20 Oct 2025 14:31:59 +0200
From: akemnade@...nel.org
To: Lee Jones <lee@...nel.org>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Andreas Kemnade <andreas@...nade.info>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
Tony Lindgren <tony@...mide.com>, Kevin Hilman <khilman@...nel.org>
Cc: devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-input@...r.kernel.org, linux-omap@...r.kernel.org,
Andreas Kemnade <akemnade@...nel.org>
Subject: [PATCH 2/3] Input: add TWL603x power button
From: Andreas Kemnade <andreas@...nade.info>
Like the TWL4030, these PMICs also have a power button feature, so add
a driver for it.
Signed-off-by: Andreas Kemnade <andreas@...nade.info>
---
drivers/input/misc/Kconfig | 10 +++
drivers/input/misc/Makefile | 1 +
drivers/input/misc/twl6030-pwrbutton.c | 111 +++++++++++++++++++++++++++++++++
3 files changed, 122 insertions(+)
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index cc2558630797e..5e2d1a5116502 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -569,6 +569,16 @@ config INPUT_TWL4030_VIBRA
To compile this driver as a module, choose M here. The module will
be called twl4030_vibra.
+config INPUT_TWL6030_PWRBUTTON
+ tristate "TWL6030 Power button Driver"
+ depends on TWL4030_CORE
+ help
+ Say Y here if you want to enable power key reporting via the
+ TWL6030 family of chips.
+
+ To compile this driver as a module, choose M here. The module will
+ be called twl4030_pwrbutton.
+
config INPUT_TWL6040_VIBRA
tristate "Support for TWL6040 Vibrator"
depends on TWL6040_CORE
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index f5ebfa9d99831..596c013261f44 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_INPUT_TPS65219_PWRBUTTON) += tps65219-pwrbutton.o
obj-$(CONFIG_INPUT_TPS6594_PWRBUTTON) += tps6594-pwrbutton.o
obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o
obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
+obj-$(CONFIG_INPUT_TWL6030_PWRBUTTON) += twl6030-pwrbutton.o
obj-$(CONFIG_INPUT_TWL6040_VIBRA) += twl6040-vibra.o
obj-$(CONFIG_INPUT_UINPUT) += uinput.o
obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
diff --git a/drivers/input/misc/twl6030-pwrbutton.c b/drivers/input/misc/twl6030-pwrbutton.c
new file mode 100644
index 0000000000000..fb3d8dcc9088a
--- /dev/null
+++ b/drivers/input/misc/twl6030-pwrbutton.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/**
+ * TWL603x power button input driver
+ *
+ * Copyright (C) 2024 Andreas Kemnade <andreas@...nade.info>
+ *
+ * based on older 6030 driver found in a v3.0 vendor kernel
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/bits.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/twl.h>
+
+#define PWR_PWRON_IRQ BIT(0)
+
+#define STS_HW_CONDITIONS 0x2
+
+static irqreturn_t powerbutton_irq(int irq, void *_pwr)
+{
+ struct input_dev *pwr = _pwr;
+ int err;
+ u8 value;
+
+ err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &value, STS_HW_CONDITIONS);
+ if (err)
+ return IRQ_HANDLED;
+
+ pm_wakeup_event(pwr->dev.parent, 0);
+ input_report_key(pwr, KEY_POWER, value & PWR_PWRON_IRQ);
+ input_sync(pwr);
+
+ return IRQ_HANDLED;
+}
+
+static int twl6030_pwrbutton_probe(struct platform_device *pdev)
+{
+ struct input_dev *pwr;
+ int irq = platform_get_irq(pdev, 0);
+ int err;
+
+ pwr = devm_input_allocate_device(&pdev->dev);
+ if (!pwr) {
+ dev_err(&pdev->dev, "Can't allocate power button\n");
+ return -ENOMEM;
+ }
+
+ input_set_capability(pwr, EV_KEY, KEY_POWER);
+ pwr->name = "twl6030_pwrbutton";
+ pwr->phys = "twl6030_pwrbutton/input0";
+ pwr->dev.parent = &pdev->dev;
+
+ err = devm_request_threaded_irq(&pdev->dev, irq, NULL, powerbutton_irq,
+ IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
+ IRQF_ONESHOT,
+ "twl6030_pwrbutton", pwr);
+ if (err < 0) {
+ dev_err(&pdev->dev, "Can't get IRQ for pwrbutton: %d\n", err);
+ return err;
+ }
+
+ err = input_register_device(pwr);
+ if (err) {
+ dev_err(&pdev->dev, "Can't register power button: %d\n", err);
+ return err;
+ }
+
+ err = twl6030_interrupt_unmask(0x01, REG_INT_MSK_LINE_A);
+ if (err < 0)
+ return err;
+
+ err = twl6030_interrupt_unmask(0x01, REG_INT_MSK_STS_A);
+ if (err < 0)
+ return err;
+
+ device_init_wakeup(&pdev->dev, true);
+
+ return 0;
+}
+
+static void twl6030_pwrbutton_remove(struct platform_device *pdev)
+{
+ twl6030_interrupt_mask(0x01, REG_INT_MSK_LINE_A);
+ twl6030_interrupt_mask(0x01, REG_INT_MSK_STS_A);
+}
+
+static const struct of_device_id twl6030_pwrbutton_dt_match_table[] = {
+ { .compatible = "ti,twl6030-pwrbutton" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, twl6030_pwrbutton_dt_match_table);
+
+static struct platform_driver twl6030_pwrbutton_driver = {
+ .probe = twl6030_pwrbutton_probe,
+ .remove = twl6030_pwrbutton_remove,
+ .driver = {
+ .name = "twl6030_pwrbutton",
+ .of_match_table = of_match_ptr(twl6030_pwrbutton_dt_match_table),
+ },
+};
+module_platform_driver(twl6030_pwrbutton_driver);
+
+MODULE_ALIAS("platform:twl6030_pwrbutton");
+MODULE_DESCRIPTION("Phoenix Power Button");
+MODULE_LICENSE("GPL");
--
2.47.3
Powered by blists - more mailing lists