summaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2019-09-09 10:06:09 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-09-09 11:03:53 +0200
commitea06d25a931324f8c082d13522c9125468cec317 (patch)
treed371672ff16489845e6b7c51bf24be6afbfaf2fc /drivers/input
parent66bd3f1c4cc3b76ef40f95dd2ee5a5c60d22c446 (diff)
downloadbarebox-ea06d25a931324f8c082d13522c9125468cec317.tar.gz
barebox-ea06d25a931324f8c082d13522c9125468cec317.tar.xz
input: add handler for reset and power key input events
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/Kconfig6
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/specialkeys.c36
3 files changed, 43 insertions, 0 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1f89ae3892..be061683fb 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 e694a98d10..36a4204d53 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 0000000000..ff29b8455d
--- /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);