blob: e47bdf92088ac6fdf51569f1566cf7454ea84361 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright (c) 1999-2001 Vojtech Pavlik
4 */
5
6/*
7 * Input driver event debug module - dumps all events into syslog
8 */
9
Joe Perchesda0c4902010-11-29 23:33:07 -080010#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/slab.h>
13#include <linux/module.h>
14#include <linux/input.h>
15#include <linux/init.h>
16#include <linux/device.h>
17
18MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
19MODULE_DESCRIPTION("Input driver event debug module");
20MODULE_LICENSE("GPL");
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
23{
Joe Perchesda0c4902010-11-29 23:33:07 -080024 printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
25 dev_name(&handle->dev->dev), type, code, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026}
27
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040028static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
29 const struct input_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 struct input_handle *handle;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040032 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040034 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
35 if (!handle)
36 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 handle->dev = dev;
39 handle->handler = handler;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040040 handle->name = "evbug";
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040042 error = input_register_handle(handle);
43 if (error)
44 goto err_free_handle;
45
46 error = input_open_device(handle);
47 if (error)
48 goto err_unregister_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Joe Perchesda0c4902010-11-29 23:33:07 -080050 printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
51 dev_name(&dev->dev),
52 dev->name ?: "unknown",
53 dev->phys ?: "unknown");
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040055 return 0;
56
57 err_unregister_handle:
58 input_unregister_handle(handle);
59 err_free_handle:
60 kfree(handle);
61 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
64static void evbug_disconnect(struct input_handle *handle)
65{
Joe Perchesda0c4902010-11-29 23:33:07 -080066 printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
67 dev_name(&handle->dev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 input_close_device(handle);
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040070 input_unregister_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 kfree(handle);
72}
73
Dmitry Torokhov66e66112006-09-14 01:31:59 -040074static const struct input_device_id evbug_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 { .driver_info = 1 }, /* Matches all devices */
76 { }, /* Terminating zero entry */
77};
78
79MODULE_DEVICE_TABLE(input, evbug_ids);
80
81static struct input_handler evbug_handler = {
82 .event = evbug_event,
83 .connect = evbug_connect,
84 .disconnect = evbug_disconnect,
85 .name = "evbug",
86 .id_table = evbug_ids,
87};
88
89static int __init evbug_init(void)
90{
Dmitry Torokhov4263cf02006-09-14 01:32:39 -040091 return input_register_handler(&evbug_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
94static void __exit evbug_exit(void)
95{
96 input_unregister_handler(&evbug_handler);
97}
98
99module_init(evbug_init);
100module_exit(evbug_exit);