hid-xinmo.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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");