Re: [PATCH 1/3] input: Add keyreset driver.

2015-10-27 Thread Dmitry Torokhov
Hi Bálint,

On Tue, Oct 27, 2015 at 09:32:33AM +0100, Bálint Czobor wrote:
> From: Arve Hjønnevåg 
> 
> Add a platform device in the board file to specify a reset key-combo.
> The first time the key-combo is detected a work function that syncs
> the filesystems is scheduled. If all the keys are released and then
> pressed again, it calls panic. Reboot on panic should be set for
> this to work.

Mathieu Poirier integrated keyreset functionality into sysrq, see
3d289517dfd48f6487efda81543c3dda8b0e66f2 and
154b7a489a5b1d808323b933b04864958c2f1056

Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] input: Add keyreset driver.

2015-10-27 Thread Bálint Czobor
From: Arve Hjønnevåg 

Add a platform device in the board file to specify a reset key-combo.
The first time the key-combo is detected a work function that syncs
the filesystems is scheduled. If all the keys are released and then
pressed again, it calls panic. Reboot on panic should be set for
this to work.

Signed-off-by: Arve Hjønnevåg 
Signed-off-by: Bálint Czobor 
---
 drivers/input/Kconfig|9 ++
 drivers/input/Makefile   |1 +
 drivers/input/keyreset.c |  239 ++
 include/linux/keyreset.h |   28 ++
 4 files changed, 277 insertions(+)
 create mode 100644 drivers/input/keyreset.c
 create mode 100644 include/linux/keyreset.h

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index a35532e..47a5143 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -187,6 +187,15 @@ config INPUT_APMPOWER
  To compile this driver as a module, choose M here: the
  module will be called apm-power.

+config INPUT_KEYRESET
+   tristate "Reset key"
+   depends on INPUT
+   ---help---
+ Say Y here if you want to reboot when some keys are pressed;
+
+ To compile this driver as a module, choose M here: the
+ module will be called keyreset.
+
 comment "Input Device Drivers"

 source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 0c9302c..f3749d5 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN)   += touchscreen/
 obj-$(CONFIG_INPUT_MISC)   += misc/

 obj-$(CONFIG_INPUT_APMPOWER)   += apm-power.o
+obj-$(CONFIG_INPUT_KEYRESET)   += keyreset.o
diff --git a/drivers/input/keyreset.c b/drivers/input/keyreset.c
new file mode 100644
index 000..36208fe
--- /dev/null
+++ b/drivers/input/keyreset.c
@@ -0,0 +1,239 @@
+/* drivers/input/keyreset.c
+ *
+ * Copyright (C) 2008 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+struct keyreset_state {
+   struct input_handler input_handler;
+   unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long upbit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long key[BITS_TO_LONGS(KEY_CNT)];
+   spinlock_t lock;
+   int key_down_target;
+   int key_down;
+   int key_up;
+   int restart_disabled;
+   int (*reset_fn)(void);
+};
+
+int restart_requested;
+static void deferred_restart(struct work_struct *dummy)
+{
+   restart_requested = 2;
+   sys_sync();
+   restart_requested = 3;
+   kernel_restart(NULL);
+}
+static DECLARE_WORK(restart_work, deferred_restart);
+
+static void keyreset_event(struct input_handle *handle, unsigned int type,
+  unsigned int code, int value)
+{
+   unsigned long flags;
+   struct keyreset_state *state = handle->private;
+
+   if (type != EV_KEY)
+   return;
+
+   if (code >= KEY_MAX)
+   return;
+
+   if (!test_bit(code, state->keybit))
+   return;
+
+   spin_lock_irqsave(>lock, flags);
+   if (!test_bit(code, state->key) == !value)
+   goto done;
+   __change_bit(code, state->key);
+   if (test_bit(code, state->upbit)) {
+   if (value) {
+   state->restart_disabled = 1;
+   state->key_up++;
+   } else
+   state->key_up--;
+   } else {
+   if (value)
+   state->key_down++;
+   else
+   state->key_down--;
+   }
+   if (state->key_down == 0 && state->key_up == 0)
+   state->restart_disabled = 0;
+
+   pr_debug("reset key changed %d %d new state %d-%d-%d\n", code, value,
+state->key_down, state->key_up, state->restart_disabled);
+
+   if (value && !state->restart_disabled &&
+   state->key_down == state->key_down_target) {
+   state->restart_disabled = 1;
+   if (restart_requested)
+   panic("keyboard reset failed, %d", restart_requested);
+   if (state->reset_fn) {
+   restart_requested = state->reset_fn();
+   } else {
+   pr_info("keyboard reset\n");
+   schedule_work(_work);
+   restart_requested = 1;
+   }
+   }
+done:
+   spin_unlock_irqrestore(>lock, flags);
+}
+

[PATCH 1/3] input: Add keyreset driver.

2015-10-27 Thread Bálint Czobor
From: Arve Hjønnevåg 

Add a platform device in the board file to specify a reset key-combo.
The first time the key-combo is detected a work function that syncs
the filesystems is scheduled. If all the keys are released and then
pressed again, it calls panic. Reboot on panic should be set for
this to work.

Signed-off-by: Arve Hjønnevåg 
Signed-off-by: Bálint Czobor 
---
 drivers/input/Kconfig|9 ++
 drivers/input/Makefile   |1 +
 drivers/input/keyreset.c |  239 ++
 include/linux/keyreset.h |   28 ++
 4 files changed, 277 insertions(+)
 create mode 100644 drivers/input/keyreset.c
 create mode 100644 include/linux/keyreset.h

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index a35532e..47a5143 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -187,6 +187,15 @@ config INPUT_APMPOWER
  To compile this driver as a module, choose M here: the
  module will be called apm-power.

+config INPUT_KEYRESET
+   tristate "Reset key"
+   depends on INPUT
+   ---help---
+ Say Y here if you want to reboot when some keys are pressed;
+
+ To compile this driver as a module, choose M here: the
+ module will be called keyreset.
+
 comment "Input Device Drivers"

 source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 0c9302c..f3749d5 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -26,3 +26,4 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN)   += touchscreen/
 obj-$(CONFIG_INPUT_MISC)   += misc/

 obj-$(CONFIG_INPUT_APMPOWER)   += apm-power.o
+obj-$(CONFIG_INPUT_KEYRESET)   += keyreset.o
diff --git a/drivers/input/keyreset.c b/drivers/input/keyreset.c
new file mode 100644
index 000..36208fe
--- /dev/null
+++ b/drivers/input/keyreset.c
@@ -0,0 +1,239 @@
+/* drivers/input/keyreset.c
+ *
+ * Copyright (C) 2008 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+struct keyreset_state {
+   struct input_handler input_handler;
+   unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long upbit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long key[BITS_TO_LONGS(KEY_CNT)];
+   spinlock_t lock;
+   int key_down_target;
+   int key_down;
+   int key_up;
+   int restart_disabled;
+   int (*reset_fn)(void);
+};
+
+int restart_requested;
+static void deferred_restart(struct work_struct *dummy)
+{
+   restart_requested = 2;
+   sys_sync();
+   restart_requested = 3;
+   kernel_restart(NULL);
+}
+static DECLARE_WORK(restart_work, deferred_restart);
+
+static void keyreset_event(struct input_handle *handle, unsigned int type,
+  unsigned int code, int value)
+{
+   unsigned long flags;
+   struct keyreset_state *state = handle->private;
+
+   if (type != EV_KEY)
+   return;
+
+   if (code >= KEY_MAX)
+   return;
+
+   if (!test_bit(code, state->keybit))
+   return;
+
+   spin_lock_irqsave(>lock, flags);
+   if (!test_bit(code, state->key) == !value)
+   goto done;
+   __change_bit(code, state->key);
+   if (test_bit(code, state->upbit)) {
+   if (value) {
+   state->restart_disabled = 1;
+   state->key_up++;
+   } else
+   state->key_up--;
+   } else {
+   if (value)
+   state->key_down++;
+   else
+   state->key_down--;
+   }
+   if (state->key_down == 0 && state->key_up == 0)
+   state->restart_disabled = 0;
+
+   pr_debug("reset key changed %d %d new state %d-%d-%d\n", code, value,
+state->key_down, state->key_up, state->restart_disabled);
+
+   if (value && !state->restart_disabled &&
+   state->key_down == state->key_down_target) {
+   state->restart_disabled = 1;
+   if (restart_requested)
+   panic("keyboard reset failed, %d", restart_requested);
+   if (state->reset_fn) {
+   restart_requested = state->reset_fn();
+   } else {
+   pr_info("keyboard reset\n");
+   schedule_work(_work);
+   restart_requested = 1;
+   }
+   }

Re: [PATCH 1/3] input: Add keyreset driver.

2015-10-27 Thread Dmitry Torokhov
Hi Bálint,

On Tue, Oct 27, 2015 at 09:32:33AM +0100, Bálint Czobor wrote:
> From: Arve Hjønnevåg 
> 
> Add a platform device in the board file to specify a reset key-combo.
> The first time the key-combo is detected a work function that syncs
> the filesystems is scheduled. If all the keys are released and then
> pressed again, it calls panic. Reboot on panic should be set for
> this to work.

Mathieu Poirier integrated keyreset functionality into sysrq, see
3d289517dfd48f6487efda81543c3dda8b0e66f2 and
154b7a489a5b1d808323b933b04864958c2f1056

Thanks.

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/