1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1999-2001 Vojtech Pavlik
7 * Input driver event debug module - dumps all events into syslog
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/slab.h>
13 #include <linux/module.h>
14 #include <linux/input.h>
15 #include <linux/init.h>
16 #include <linux/device.h>
18 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
19 MODULE_DESCRIPTION("Input driver event debug module");
20 MODULE_LICENSE("GPL");
22 static void evbug_event(struct input_handle
*handle
, unsigned int type
, unsigned int code
, int value
)
24 printk(KERN_DEBUG
pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
25 dev_name(&handle
->dev
->dev
), type
, code
, value
);
28 static int evbug_connect(struct input_handler
*handler
, struct input_dev
*dev
,
29 const struct input_device_id
*id
)
31 struct input_handle
*handle
;
34 handle
= kzalloc(sizeof(struct input_handle
), GFP_KERNEL
);
39 handle
->handler
= handler
;
40 handle
->name
= "evbug";
42 error
= input_register_handle(handle
);
46 error
= input_open_device(handle
);
48 goto err_unregister_handle
;
50 printk(KERN_DEBUG
pr_fmt("Connected device: %s (%s at %s)\n"),
52 dev
->name
?: "unknown",
53 dev
->phys
?: "unknown");
57 err_unregister_handle
:
58 input_unregister_handle(handle
);
64 static void evbug_disconnect(struct input_handle
*handle
)
66 printk(KERN_DEBUG
pr_fmt("Disconnected device: %s\n"),
67 dev_name(&handle
->dev
->dev
));
69 input_close_device(handle
);
70 input_unregister_handle(handle
);
74 static const struct input_device_id evbug_ids
[] = {
75 { .driver_info
= 1 }, /* Matches all devices */
76 { }, /* Terminating zero entry */
79 MODULE_DEVICE_TABLE(input
, evbug_ids
);
81 static struct input_handler evbug_handler
= {
83 .connect
= evbug_connect
,
84 .disconnect
= evbug_disconnect
,
86 .id_table
= evbug_ids
,
89 static int __init
evbug_init(void)
91 return input_register_handler(&evbug_handler
);
94 static void __exit
evbug_exit(void)
96 input_unregister_handler(&evbug_handler
);
99 module_init(evbug_init
);
100 module_exit(evbug_exit
);