blob: c0d0b121ae7ea975e1c8c5d03d6a3942849efe40 [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
10/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
Joe Perchesda0c4902010-11-29 23:33:07 -080013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/input.h>
18#include <linux/init.h>
19#include <linux/device.h>
20
21MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
22MODULE_DESCRIPTION("Input driver event debug module");
23MODULE_LICENSE("GPL");
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
26{
Joe Perchesda0c4902010-11-29 23:33:07 -080027 printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
28 dev_name(&handle->dev->dev), type, code, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040031static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
32 const struct input_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 struct input_handle *handle;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040035 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040037 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
38 if (!handle)
39 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 handle->dev = dev;
42 handle->handler = handler;
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040043 handle->name = "evbug";
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040045 error = input_register_handle(handle);
46 if (error)
47 goto err_free_handle;
48
49 error = input_open_device(handle);
50 if (error)
51 goto err_unregister_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Joe Perchesda0c4902010-11-29 23:33:07 -080053 printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
54 dev_name(&dev->dev),
55 dev->name ?: "unknown",
56 dev->phys ?: "unknown");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040058 return 0;
59
60 err_unregister_handle:
61 input_unregister_handle(handle);
62 err_free_handle:
63 kfree(handle);
64 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67static void evbug_disconnect(struct input_handle *handle)
68{
Joe Perchesda0c4902010-11-29 23:33:07 -080069 printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
70 dev_name(&handle->dev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 input_close_device(handle);
Dmitry Torokhov5b2a08262007-04-12 01:29:46 -040073 input_unregister_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 kfree(handle);
75}
76
Dmitry Torokhov66e66112006-09-14 01:31:59 -040077static const struct input_device_id evbug_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 { .driver_info = 1 }, /* Matches all devices */
79 { }, /* Terminating zero entry */
80};
81
82MODULE_DEVICE_TABLE(input, evbug_ids);
83
84static struct input_handler evbug_handler = {
85 .event = evbug_event,
86 .connect = evbug_connect,
87 .disconnect = evbug_disconnect,
88 .name = "evbug",
89 .id_table = evbug_ids,
90};
91
92static int __init evbug_init(void)
93{
Dmitry Torokhov4263cf02006-09-14 01:32:39 -040094 return input_register_handler(&evbug_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
97static void __exit evbug_exit(void)
98{
99 input_unregister_handler(&evbug_handler);
100}
101
102module_init(evbug_init);
103module_exit(evbug_exit);