evbug.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 1999-2001 Vojtech Pavlik
  3. */
  4. /*
  5. * Input driver event debug module - dumps all events into syslog
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Should you need to contact me, the author, you can do so either by
  23. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  24. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  25. */
  26. #include <linux/slab.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/init.h>
  30. #include <linux/device.h>
  31. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  32. MODULE_DESCRIPTION("Input driver event debug module");
  33. MODULE_LICENSE("GPL");
  34. static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  35. {
  36. printk(KERN_DEBUG "evbug.c: Event. Dev: %s, Type: %d, Code: %d, Value: %d\n",
  37. handle->dev->dev.bus_id, type, code, value);
  38. }
  39. static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
  40. const struct input_device_id *id)
  41. {
  42. struct input_handle *handle;
  43. int error;
  44. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  45. if (!handle)
  46. return -ENOMEM;
  47. handle->dev = dev;
  48. handle->handler = handler;
  49. handle->name = "evbug";
  50. error = input_register_handle(handle);
  51. if (error)
  52. goto err_free_handle;
  53. error = input_open_device(handle);
  54. if (error)
  55. goto err_unregister_handle;
  56. printk(KERN_DEBUG "evbug.c: Connected device: %s (%s at %s)\n",
  57. dev->dev.bus_id,
  58. dev->name ?: "unknown",
  59. dev->phys ?: "unknown");
  60. return 0;
  61. err_unregister_handle:
  62. input_unregister_handle(handle);
  63. err_free_handle:
  64. kfree(handle);
  65. return error;
  66. }
  67. static void evbug_disconnect(struct input_handle *handle)
  68. {
  69. printk(KERN_DEBUG "evbug.c: Disconnected device: %s\n",
  70. handle->dev->dev.bus_id);
  71. input_close_device(handle);
  72. input_unregister_handle(handle);
  73. kfree(handle);
  74. }
  75. static const struct input_device_id evbug_ids[] = {
  76. { .driver_info = 1 }, /* Matches all devices */
  77. { }, /* Terminating zero entry */
  78. };
  79. MODULE_DEVICE_TABLE(input, evbug_ids);
  80. static struct input_handler evbug_handler = {
  81. .event = evbug_event,
  82. .connect = evbug_connect,
  83. .disconnect = evbug_disconnect,
  84. .name = "evbug",
  85. .id_table = evbug_ids,
  86. };
  87. static int __init evbug_init(void)
  88. {
  89. return input_register_handler(&evbug_handler);
  90. }
  91. static void __exit evbug_exit(void)
  92. {
  93. input_unregister_handler(&evbug_handler);
  94. }
  95. module_init(evbug_init);
  96. module_exit(evbug_exit);