evbug.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 1999-2001 Vojtech Pavlik
  4. */
  5. /*
  6. * Input driver event debug module - dumps all events into syslog
  7. */
  8. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9. #include <linux/slab.h>
  10. #include <linux/module.h>
  11. #include <linux/input.h>
  12. #include <linux/init.h>
  13. #include <linux/device.h>
  14. MODULE_AUTHOR("Vojtech Pavlik <[email protected]>");
  15. MODULE_DESCRIPTION("Input driver event debug module");
  16. MODULE_LICENSE("GPL");
  17. static void evbug_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  18. {
  19. printk(KERN_DEBUG pr_fmt("Event. Dev: %s, Type: %d, Code: %d, Value: %d\n"),
  20. dev_name(&handle->dev->dev), type, code, value);
  21. }
  22. static int evbug_connect(struct input_handler *handler, struct input_dev *dev,
  23. const struct input_device_id *id)
  24. {
  25. struct input_handle *handle;
  26. int error;
  27. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  28. if (!handle)
  29. return -ENOMEM;
  30. handle->dev = dev;
  31. handle->handler = handler;
  32. handle->name = "evbug";
  33. error = input_register_handle(handle);
  34. if (error)
  35. goto err_free_handle;
  36. error = input_open_device(handle);
  37. if (error)
  38. goto err_unregister_handle;
  39. printk(KERN_DEBUG pr_fmt("Connected device: %s (%s at %s)\n"),
  40. dev_name(&dev->dev),
  41. dev->name ?: "unknown",
  42. dev->phys ?: "unknown");
  43. return 0;
  44. err_unregister_handle:
  45. input_unregister_handle(handle);
  46. err_free_handle:
  47. kfree(handle);
  48. return error;
  49. }
  50. static void evbug_disconnect(struct input_handle *handle)
  51. {
  52. printk(KERN_DEBUG pr_fmt("Disconnected device: %s\n"),
  53. dev_name(&handle->dev->dev));
  54. input_close_device(handle);
  55. input_unregister_handle(handle);
  56. kfree(handle);
  57. }
  58. static const struct input_device_id evbug_ids[] = {
  59. { .driver_info = 1 }, /* Matches all devices */
  60. { }, /* Terminating zero entry */
  61. };
  62. MODULE_DEVICE_TABLE(input, evbug_ids);
  63. static struct input_handler evbug_handler = {
  64. .event = evbug_event,
  65. .connect = evbug_connect,
  66. .disconnect = evbug_disconnect,
  67. .name = "evbug",
  68. .id_table = evbug_ids,
  69. };
  70. static int __init evbug_init(void)
  71. {
  72. return input_register_handler(&evbug_handler);
  73. }
  74. static void __exit evbug_exit(void)
  75. {
  76. input_unregister_handler(&evbug_handler);
  77. }
  78. module_init(evbug_init);
  79. module_exit(evbug_exit);