hid-speedlink.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Stefan Kriwanek <mail@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. /* Fix "jumpy" cursor (invalid events sent by device). */
  44. if (value == 256)
  45. return 1;
  46. /* Drop useless distance 0 events (on button clicks etc.) as well */
  47. if (value == 0)
  48. return 1;
  49. return 0;
  50. }
  51. MODULE_DEVICE_TABLE(hid, speedlink_devices);
  52. static const struct hid_usage_id speedlink_grabbed_usages[] = {
  53. { HID_GD_X, EV_REL, 0 },
  54. { HID_GD_Y, EV_REL, 1 },
  55. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
  56. };
  57. static struct hid_driver speedlink_driver = {
  58. .name = "speedlink",
  59. .id_table = speedlink_devices,
  60. .usage_table = speedlink_grabbed_usages,
  61. .input_mapping = speedlink_input_mapping,
  62. .event = speedlink_event,
  63. };
  64. module_hid_driver(speedlink_driver);
  65. MODULE_LICENSE("GPL");