hid-speedlink.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for Speedlink Vicious and Divine Cezanne (USB mouse).
  4. * Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from
  5. * the HID descriptor.
  6. *
  7. * Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
  8. */
  9. /*
  10. */
  11. #include <linux/device.h>
  12. #include <linux/hid.h>
  13. #include <linux/module.h>
  14. #include "hid-ids.h"
  15. static const struct hid_device_id speedlink_devices[] = {
  16. { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE)},
  17. { }
  18. };
  19. static int speedlink_input_mapping(struct hid_device *hdev,
  20. struct hid_input *hi,
  21. struct hid_field *field, struct hid_usage *usage,
  22. unsigned long **bit, int *max)
  23. {
  24. /*
  25. * The Cezanne mouse has a second "keyboard" USB endpoint for it is
  26. * able to map keyboard events to the button presses.
  27. * It sends a standard keyboard report descriptor, though, whose
  28. * LEDs we ignore.
  29. */
  30. switch (usage->hid & HID_USAGE_PAGE) {
  31. case HID_UP_LED:
  32. return -1;
  33. }
  34. return 0;
  35. }
  36. static int speedlink_event(struct hid_device *hdev, struct hid_field *field,
  37. struct hid_usage *usage, __s32 value)
  38. {
  39. /* No other conditions due to usage_table. */
  40. /* This fixes the "jumpy" cursor occuring due to invalid events sent
  41. * by the device. Some devices only send them with value==+256, others
  42. * don't. However, catching abs(value)>=256 is restrictive enough not
  43. * to interfere with devices that were bug-free (has been tested).
  44. */
  45. if (abs(value) >= 256)
  46. return 1;
  47. /* Drop useless distance 0 events (on button clicks etc.) as well */
  48. if (value == 0)
  49. return 1;
  50. return 0;
  51. }
  52. MODULE_DEVICE_TABLE(hid, speedlink_devices);
  53. static const struct hid_usage_id speedlink_grabbed_usages[] = {
  54. { HID_GD_X, EV_REL, 0 },
  55. { HID_GD_Y, EV_REL, 1 },
  56. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  57. };
  58. static struct hid_driver speedlink_driver = {
  59. .name = "speedlink",
  60. .id_table = speedlink_devices,
  61. .usage_table = speedlink_grabbed_usages,
  62. .input_mapping = speedlink_input_mapping,
  63. .event = speedlink_event,
  64. };
  65. module_hid_driver(speedlink_driver);
  66. MODULE_LICENSE("GPL");