Blame view

drivers/input/evbug.c 3.1 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
   *  Copyright (c) 1999-2001 Vojtech Pavlik
   */
  
  /*
   *  Input driver event debug module - dumps all events into syslog
   */
  
  /*
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   *
   * Should you need to contact me, the author, you can do so either by
   * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
   * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
   */
da0c49011   Joe Perches   Input: use pr_fmt...
28
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
34
35
36
37
  #include <linux/slab.h>
  #include <linux/module.h>
  #include <linux/input.h>
  #include <linux/init.h>
  #include <linux/device.h>
  
  MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  MODULE_DESCRIPTION("Input driver event debug module");
  MODULE_LICENSE("GPL");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
  static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  {
da0c49011   Joe Perches   Input: use pr_fmt...
40
41
42
  	printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d
  "),
  	       dev_name(&handle->dev->dev), type, code, value);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  }
5b2a08262   Dmitry Torokhov   Input: rework han...
44
45
  static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
  			 const struct input_device_id *id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  {
  	struct input_handle *handle;
5b2a08262   Dmitry Torokhov   Input: rework han...
48
  	int error;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49

5b2a08262   Dmitry Torokhov   Input: rework han...
50
51
52
  	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  	if (!handle)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
  
  	handle->dev = dev;
  	handle->handler = handler;
5b2a08262   Dmitry Torokhov   Input: rework han...
56
57
58
59
60
  	handle->name = "evbug";
  
  	error = input_register_handle(handle);
  	if (error)
  		goto err_free_handle;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61

5b2a08262   Dmitry Torokhov   Input: rework han...
62
63
64
  	error = input_open_device(handle);
  	if (error)
  		goto err_unregister_handle;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65

da0c49011   Joe Perches   Input: use pr_fmt...
66
67
68
69
70
  	printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)
  "),
  	       dev_name(&dev->dev),
  	       dev->name ?: "unknown",
  	       dev->phys ?: "unknown");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71

5b2a08262   Dmitry Torokhov   Input: rework han...
72
73
74
75
76
77
78
  	return 0;
  
   err_unregister_handle:
  	input_unregister_handle(handle);
   err_free_handle:
  	kfree(handle);
  	return error;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
82
  }
  
  static void evbug_disconnect(struct input_handle *handle)
  {
da0c49011   Joe Perches   Input: use pr_fmt...
83
84
85
  	printk(KERN_DEBUG pr_fmt("Disconnected device: %s
  "),
  	       dev_name(&handle->dev->dev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
  
  	input_close_device(handle);
5b2a08262   Dmitry Torokhov   Input: rework han...
88
  	input_unregister_handle(handle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
90
  	kfree(handle);
  }
66e661188   Dmitry Torokhov   Input: constify i...
91
  static const struct input_device_id evbug_ids[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  	{ .driver_info = 1 },	/* Matches all devices */
  	{ },			/* Terminating zero entry */
  };
  
  MODULE_DEVICE_TABLE(input, evbug_ids);
  
  static struct input_handler evbug_handler = {
  	.event =	evbug_event,
  	.connect =	evbug_connect,
  	.disconnect =	evbug_disconnect,
  	.name =		"evbug",
  	.id_table =	evbug_ids,
  };
  
  static int __init evbug_init(void)
  {
4263cf0fa   Dmitry Torokhov   Input: make input...
108
  	return input_register_handler(&evbug_handler);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
111
112
113
114
115
116
117
  }
  
  static void __exit evbug_exit(void)
  {
  	input_unregister_handler(&evbug_handler);
  }
  
  module_init(evbug_init);
  module_exit(evbug_exit);