blob: 5419c1c1f621b675fd9e3948814b80081d5e989e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Joe Perchesda0c4902010-11-29 23:33:07 -080025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/slab.h>
28#include <linux/module.h>
29#include <linux/input.h>
30#include <linux/init.h>
31#include <linux/device.h>
32
33MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
34MODULE_DESCRIPTION("Input driver event debug module");
35MODULE_LICENSE("GPL");
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
38{
Joe Perchesda0c4902010-11-29 23:33:07 -080039 printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
40 dev_name(&handle->dev->dev), type, code, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040043static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
44 const struct input_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 struct input_handle *handle;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040047 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040049 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
50 if (!handle)
51 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 handle->dev = dev;
54 handle->handler = handler;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040055 handle->name = "evbug";
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040057 error = input_register_handle(handle);
58 if (error)
59 goto err_free_handle;
60
61 error = input_open_device(handle);
62 if (error)
63 goto err_unregister_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Joe Perchesda0c4902010-11-29 23:33:07 -080065 printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
66 dev_name(&dev->dev),
67 dev->name ?: "unknown",
68 dev->phys ?: "unknown");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040070 return 0;
71
72 err_unregister_handle:
73 input_unregister_handle(handle);
74 err_free_handle:
75 kfree(handle);
76 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79static void evbug_disconnect(struct input_handle *handle)
80{
Joe Perchesda0c4902010-11-29 23:33:07 -080081 printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
82 dev_name(&handle->dev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 input_close_device(handle);
Dmitry Torokhov5b2a08262007-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);