evbug.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/slab.h>
  28. #include <linux/module.h>
  29. #include <linux/input.h>
  30. #include <linux/init.h>
  31. #include <linux/device.h>
  32. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  33. MODULE_DESCRIPTION("Input driver event debug module");
  34. MODULE_LICENSE("GPL");
  35. static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  36. {
  37. printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
  38. dev_name(&handle->dev->dev), type, code, value);
  39. }
  40. static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
  41. const struct input_device_id *id)
  42. {
  43. struct input_handle *handle;
  44. int error;
  45. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  46. if (!handle)
  47. return -ENOMEM;
  48. handle->dev = dev;
  49. handle->handler = handler;
  50. handle->name = "evbug";
  51. error = input_register_handle(handle);
  52. if (error)
  53. goto err_free_handle;
  54. error = input_open_device(handle);
  55. if (error)
  56. goto err_unregister_handle;
  57. printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
  58. dev_name(&dev->dev),
  59. dev->name ?: "unknown",
  60. dev->phys ?: "unknown");
  61. return 0;
  62. err_unregister_handle:
  63. input_unregister_handle(handle);
  64. err_free_handle:
  65. kfree(handle);
  66. return error;
  67. }
  68. static void evbug_disconnect(struct input_handle *handle)
  69. {
  70. printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
  71. dev_name(&handle->dev->dev));
  72. input_close_device(handle);
  73. input_unregister_handle(handle);
  74. kfree(handle);
  75. }
  76. static const struct input_device_id evbug_ids[] = {
  77. { .driver_info = 1 }, /* Matches all devices */
  78. { }, /* Terminating zero entry */
  79. };
  80. MODULE_DEVICE_TABLE(input, evbug_ids);
  81. static 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. static int __init evbug_init(void)
  89. {
  90. return input_register_handler(&evbug_handler);
  91. }
  92. static void __exit evbug_exit(void)
  93. {
  94. input_unregister_handler(&evbug_handler);
  95. }
  96. module_init(evbug_init);
  97. module_exit(evbug_exit);