summaryrefslogtreecommitdiffstats
path: root/drivers/input/specialkeys.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/specialkeys.c')
-rw-r--r--drivers/input/specialkeys.c36
1 files changed, 36 insertions, 0 deletions
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);