kgdboc: reset input devices (keyboards) when exiting debugger

Use the newly exported input_reset_device() call to reset LED state and
mark all keys/buttons as released on all keyboard-like devices when
exiting the debugger.

[jason.wessel@windriver.com: fix compile without keyboard input driver]
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+59
+59
drivers/serial/kgdboc.c
··· 18 18 #include <linux/tty.h> 19 19 #include <linux/console.h> 20 20 #include <linux/vt_kern.h> 21 + #include <linux/input.h> 21 22 22 23 #define MAX_CONFIG_LEN 40 23 24 ··· 38 37 static int kgdb_tty_line; 39 38 40 39 #ifdef CONFIG_KDB_KEYBOARD 40 + static int kgdboc_reset_connect(struct input_handler *handler, 41 + struct input_dev *dev, 42 + const struct input_device_id *id) 43 + { 44 + input_reset_device(dev); 45 + 46 + /* Retrun an error - we do not want to bind, just to reset */ 47 + return -ENODEV; 48 + } 49 + 50 + static void kgdboc_reset_disconnect(struct input_handle *handle) 51 + { 52 + /* We do not expect anyone to actually bind to us */ 53 + BUG(); 54 + } 55 + 56 + static const struct input_device_id kgdboc_reset_ids[] = { 57 + { 58 + .flags = INPUT_DEVICE_ID_MATCH_EVBIT, 59 + .evbit = { BIT_MASK(EV_KEY) }, 60 + }, 61 + { } 62 + }; 63 + 64 + static struct input_handler kgdboc_reset_handler = { 65 + .connect = kgdboc_reset_connect, 66 + .disconnect = kgdboc_reset_disconnect, 67 + .name = "kgdboc_reset", 68 + .id_table = kgdboc_reset_ids, 69 + }; 70 + 71 + static DEFINE_MUTEX(kgdboc_reset_mutex); 72 + 73 + static void kgdboc_restore_input_helper(struct work_struct *dummy) 74 + { 75 + /* 76 + * We need to take a mutex to prevent several instances of 77 + * this work running on different CPUs so they don't try 78 + * to register again already registered handler. 79 + */ 80 + mutex_lock(&kgdboc_reset_mutex); 81 + 82 + if (input_register_handler(&kgdboc_reset_handler) == 0) 83 + input_unregister_handler(&kgdboc_reset_handler); 84 + 85 + mutex_unlock(&kgdboc_reset_mutex); 86 + } 87 + 88 + static DECLARE_WORK(kgdboc_restore_input_work, kgdboc_restore_input_helper); 89 + 90 + static void kgdboc_restore_input(void) 91 + { 92 + schedule_work(&kgdboc_restore_input_work); 93 + } 94 + 41 95 static int kgdboc_register_kbd(char **cptr) 42 96 { 43 97 if (strncmp(*cptr, "kbd", 3) == 0) { ··· 120 64 i--; 121 65 } 122 66 } 67 + flush_work_sync(&kgdboc_restore_input_work); 123 68 } 124 69 #else /* ! CONFIG_KDB_KEYBOARD */ 125 70 #define kgdboc_register_kbd(x) 0 126 71 #define kgdboc_unregister_kbd() 72 + #define kgdboc_restore_input() 127 73 #endif /* ! CONFIG_KDB_KEYBOARD */ 128 74 129 75 static int kgdboc_option_setup(char *opt) ··· 289 231 dbg_restore_graphics = 0; 290 232 con_debug_leave(); 291 233 } 234 + kgdboc_restore_input(); 292 235 } 293 236 294 237 static struct kgdb_io kgdboc_io_ops = {