hid-speedlink.c 2.3 KB

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