hid-saitek.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * HID driver for Saitek devices, currently only the PS1000 (USB gamepad).
  3. * Fixes the HID report descriptor by removing a non-existent axis and
  4. * clearing the constant bit on the input reports for buttons and d-pad.
  5. * (This module is based on "hid-ortek".)
  6. *
  7. * Copyright (c) 2012 Andreas Hübner
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. */
  15. #include <linux/device.h>
  16. #include <linux/hid.h>
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include "hid-ids.h"
  20. static __u8 *saitek_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  21. unsigned int *rsize)
  22. {
  23. if (*rsize == 137 && rdesc[20] == 0x09 && rdesc[21] == 0x33
  24. && rdesc[94] == 0x81 && rdesc[95] == 0x03
  25. && rdesc[110] == 0x81 && rdesc[111] == 0x03) {
  26. hid_info(hdev, "Fixing up Saitek PS1000 report descriptor\n");
  27. /* convert spurious axis to a "noop" Logical Minimum (0) */
  28. rdesc[20] = 0x15;
  29. rdesc[21] = 0x00;
  30. /* clear constant bit on buttons and d-pad */
  31. rdesc[95] = 0x02;
  32. rdesc[111] = 0x02;
  33. }
  34. return rdesc;
  35. }
  36. static const struct hid_device_id saitek_devices[] = {
  37. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000)},
  38. { }
  39. };
  40. MODULE_DEVICE_TABLE(hid, saitek_devices);
  41. static struct hid_driver saitek_driver = {
  42. .name = "saitek",
  43. .id_table = saitek_devices,
  44. .report_fixup = saitek_report_fixup
  45. };
  46. static int __init saitek_init(void)
  47. {
  48. return hid_register_driver(&saitek_driver);
  49. }
  50. static void __exit saitek_exit(void)
  51. {
  52. hid_unregister_driver(&saitek_driver);
  53. }
  54. module_init(saitek_init);
  55. module_exit(saitek_exit);
  56. MODULE_LICENSE("GPL");