hid-xinmo.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * HID driver for Xin-Mo devices, currently only the Dual Arcade controller.
  3. * Fixes the negative axis event values (the devices sends -2) to match the
  4. * logical axis minimum of the HID report descriptor (the report announces
  5. * -1). It is needed because hid-input discards out of bounds values.
  6. * (This module is based on "hid-saitek" and "hid-lg".)
  7. *
  8. * Copyright (c) 2013 Olivier Scherler
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the Free
  13. * Software Foundation; either version 2 of the License, or (at your option)
  14. * any later version.
  15. */
  16. #include <linux/device.h>
  17. #include <linux/hid.h>
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include "hid-ids.h"
  21. /*
  22. * Fix negative events that are out of bounds.
  23. */
  24. static int xinmo_event(struct hid_device *hdev, struct hid_field *field,
  25. struct hid_usage *usage, __s32 value)
  26. {
  27. switch (usage->code) {
  28. case ABS_X:
  29. case ABS_Y:
  30. case ABS_Z:
  31. case ABS_RX:
  32. if (value < -1) {
  33. input_event(field->hidinput->input, usage->type,
  34. usage->code, -1);
  35. return 1;
  36. }
  37. break;
  38. }
  39. return 0;
  40. }
  41. static const struct hid_device_id xinmo_devices[] = {
  42. { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
  43. { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) },
  44. { }
  45. };
  46. MODULE_DEVICE_TABLE(hid, xinmo_devices);
  47. static struct hid_driver xinmo_driver = {
  48. .name = "xinmo",
  49. .id_table = xinmo_devices,
  50. .event = xinmo_event
  51. };
  52. module_hid_driver(xinmo_driver);
  53. MODULE_LICENSE("GPL");