devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: akemnade@kernel.org
To: Lee Jones <lee@kernel.org>, Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	Andreas Kemnade <andreas@kemnade.info>,
	 Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	 Tony Lindgren <tony@atomide.com>,
	Kevin Hilman <khilman@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-input@vger.kernel.org, linux-omap@vger.kernel.org,
	 Andreas Kemnade <akemnade@kernel.org>
Subject: [PATCH 2/3] Input: add TWL603x power button
Date: Mon, 20 Oct 2025 14:31:59 +0200	[thread overview]
Message-ID: <20251020-twl6030-button-v1-2-93e4644ac974@kernel.org> (raw)
In-Reply-To: <20251020-twl6030-button-v1-0-93e4644ac974@kernel.org>

From: Andreas Kemnade <andreas@kemnade.info>

Like the TWL4030, these PMICs also have a power button feature, so add
a driver for it.

Signed-off-by: Andreas Kemnade <andreas@kemnade.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@kemnade.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


  parent reply	other threads:[~2025-10-20 12:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20 12:31 [PATCH 0/3] mfd: twl603x: add power button akemnade
2025-10-20 12:31 ` [PATCH 1/3] dt-bindings: mfd: twl: enable power button also for twl603x akemnade
2025-10-21  7:10   ` Krzysztof Kozlowski
2025-10-21  8:45     ` Andreas Kemnade
2025-10-21  9:58       ` Krzysztof Kozlowski
2025-10-21 16:36         ` Andreas Kemnade
2025-10-21 17:18           ` Krzysztof Kozlowski
2025-10-22  8:55             ` Andreas Kemnade
2025-10-20 12:31 ` akemnade [this message]
2025-10-21  7:07   ` [PATCH 2/3] Input: add TWL603x power button Krzysztof Kozlowski
2025-10-21 17:58   ` Dmitry Torokhov
2025-10-22 12:44     ` Andreas Kemnade
2025-10-22 18:48       ` Dmitry Torokhov
2025-10-23 18:56         ` Andreas Kemnade
2025-10-20 12:32 ` [PATCH 3/3] ARM: dts: ti/omap: omap4-epson-embt2ws: add powerbutton akemnade

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251020-twl6030-button-v1-2-93e4644ac974@kernel.org \
    --to=akemnade@kernel.org \
    --cc=andreas@kemnade.info \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=khilman@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).