Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (c) 1999-2001 Vojtech Pavlik |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * Input driver event debug module - dumps all events into syslog |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | * Should you need to contact me, the author, you can do so either by |
| 25 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: |
| 26 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic |
| 27 | */ |
| 28 | |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/input.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/device.h> |
| 34 | |
| 35 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 36 | MODULE_DESCRIPTION("Input driver event debug module"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value) |
| 40 | { |
Dmitry Torokhov | 66e6611 | 2006-09-14 01:31:59 -0400 | [diff] [blame] | 41 | printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n", |
Dmitry Torokhov | 8195612 | 2008-06-02 01:02:52 -0400 | [diff] [blame] | 42 | handle->dev->dev.bus_id, type, code, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 45 | static int evbug_connect(struct input_handler *handler, struct input_dev *dev, |
| 46 | const struct input_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | struct input_handle *handle; |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 49 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 51 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); |
| 52 | if (!handle) |
| 53 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | handle->dev = dev; |
| 56 | handle->handler = handler; |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 57 | handle->name = "evbug"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 59 | error = input_register_handle(handle); |
| 60 | if (error) |
| 61 | goto err_free_handle; |
| 62 | |
| 63 | error = input_open_device(handle); |
| 64 | if (error) |
| 65 | goto err_unregister_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Dmitry Torokhov | 8195612 | 2008-06-02 01:02:52 -0400 | [diff] [blame] | 67 | printk(KERN_DEBUG "evbug.c: Connected device: %s (%s at %s)\n", |
| 68 | dev->dev.bus_id, |
| 69 | dev->name ?: "unknown", |
| 70 | dev->phys ?: "unknown"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 72 | return 0; |
| 73 | |
| 74 | err_unregister_handle: |
| 75 | input_unregister_handle(handle); |
| 76 | err_free_handle: |
| 77 | kfree(handle); |
| 78 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void evbug_disconnect(struct input_handle *handle) |
| 82 | { |
Dmitry Torokhov | 8195612 | 2008-06-02 01:02:52 -0400 | [diff] [blame] | 83 | printk(KERN_DEBUG "evbug.c: Disconnected device: %s\n", |
| 84 | handle->dev->dev.bus_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | input_close_device(handle); |
Dmitry Torokhov | 5b2a082 | 2007-04-12 01:29:46 -0400 | [diff] [blame] | 87 | input_unregister_handle(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | kfree(handle); |
| 89 | } |
| 90 | |
Dmitry Torokhov | 66e6611 | 2006-09-14 01:31:59 -0400 | [diff] [blame] | 91 | static const struct input_device_id evbug_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { .driver_info = 1 }, /* Matches all devices */ |
| 93 | { }, /* Terminating zero entry */ |
| 94 | }; |
| 95 | |
| 96 | MODULE_DEVICE_TABLE(input, evbug_ids); |
| 97 | |
| 98 | static struct input_handler evbug_handler = { |
| 99 | .event = evbug_event, |
| 100 | .connect = evbug_connect, |
| 101 | .disconnect = evbug_disconnect, |
| 102 | .name = "evbug", |
| 103 | .id_table = evbug_ids, |
| 104 | }; |
| 105 | |
| 106 | static int __init evbug_init(void) |
| 107 | { |
Dmitry Torokhov | 4263cf0 | 2006-09-14 01:32:39 -0400 | [diff] [blame] | 108 | return input_register_handler(&evbug_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static void __exit evbug_exit(void) |
| 112 | { |
| 113 | input_unregister_handler(&evbug_handler); |
| 114 | } |
| 115 | |
| 116 | module_init(evbug_init); |
| 117 | module_exit(evbug_exit); |