mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2] input: add handler for reset and power key input events
Date: Mon,  9 Sep 2019 10:06:09 +0200	[thread overview]
Message-ID: <20190909080609.2235-1-a.fatoum@pengutronix.de> (raw)

Kernel device trees may indicate linux,code = KEY_POWER or KEY_RESTART,
mostly for gpio-keys. Make barebox able to act on them by registering an
appropriate input notifier.

Suggested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
 - announce reset/power on info log level, so users are aware why it
   happens. Suggested by Oleksij
---
 drivers/input/Kconfig       |  6 ++++++
 drivers/input/Makefile      |  1 +
 drivers/input/specialkeys.c | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 drivers/input/specialkeys.c

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1f89ae3892dc..be061683fb0a 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -64,4 +64,10 @@ config KEYBOARD_USB
 	help
 	  This driver implements support for usb keyboard.
 
+config INPUT_SPECIALKEYS
+	bool "Special keys handler"
+	select INPUT
+	help
+	  Say Y here to handle key events like KEY_RESTART and KEY_POWER.
+
 endmenu
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index e694a98d1087..36a4204d5308 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
 obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o
 obj-$(CONFIG_KEYBOARD_IMX_KEYPAD) += imx_keypad.o
 obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o
+obj-$(CONFIG_INPUT_SPECIALKEYS)	+= specialkeys.o
diff --git a/drivers/input/specialkeys.c b/drivers/input/specialkeys.c
new file mode 100644
index 000000000000..ff29b8455d7a
--- /dev/null
+++ b/drivers/input/specialkeys.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2019 Ahmad Fatoum, Pengutronix
+
+#include <common.h>
+#include <restart.h>
+#include <poweroff.h>
+#include <init.h>
+#include <input/input.h>
+#include <dt-bindings/input/linux-event-codes.h>
+
+static void input_specialkeys_notify(struct input_notifier *in,
+				     struct input_event *ev)
+{
+	switch (ev->code) {
+	case KEY_RESTART:
+		pr_info("Triggering reset due to special key.\n", ev->code);
+		restart_machine();
+		break;
+
+	case KEY_POWER:
+		pr_info("Triggering poweroff due to special key.\n", ev->code);
+		poweroff_machine();
+		break;
+	}
+
+	pr_debug("ignoring code: %d\n", ev->code);
+}
+
+static struct input_notifier notifier;
+
+static int input_specialkeys_init(void)
+{
+	notifier.notify = input_specialkeys_notify;
+	return input_register_notfier(&notifier);
+}
+late_initcall(input_specialkeys_init);
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2019-09-09  8:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09  8:06 Ahmad Fatoum [this message]
2019-09-09  9:04 ` Sascha Hauer

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=20190909080609.2235-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=o.rempel@pengutronix.de \
    /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