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