hid-axff.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Force feedback support for ACRUX game controllers
  3. *
  4. * From what I have gathered, these devices are mass produced in China
  5. * by several vendors. They often share the same design as the original
  6. * Xbox 360 controller.
  7. *
  8. * 1a34:0802 "ACRUX USB GAMEPAD 8116"
  9. * - tested with a EXEQ EQ-PCU-02090 game controller.
  10. *
  11. * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru>
  12. */
  13. /*
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #include <linux/input.h>
  29. #include <linux/slab.h>
  30. #include <linux/usb.h>
  31. #include <linux/hid.h>
  32. #include "hid-ids.h"
  33. #include "usbhid/usbhid.h"
  34. struct axff_device {
  35. struct hid_report *report;
  36. };
  37. static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
  38. {
  39. struct hid_device *hid = input_get_drvdata(dev);
  40. struct axff_device *axff = data;
  41. int left, right;
  42. left = effect->u.rumble.strong_magnitude;
  43. right = effect->u.rumble.weak_magnitude;
  44. dbg_hid("called with 0x%04x 0x%04x", left, right);
  45. left = left * 0xff / 0xffff;
  46. right = right * 0xff / 0xffff;
  47. axff->report->field[0]->value[0] = left;
  48. axff->report->field[1]->value[0] = right;
  49. axff->report->field[2]->value[0] = left;
  50. axff->report->field[3]->value[0] = right;
  51. dbg_hid("running with 0x%02x 0x%02x", left, right);
  52. usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
  53. return 0;
  54. }
  55. static int axff_init(struct hid_device *hid)
  56. {
  57. struct axff_device *axff;
  58. struct hid_report *report;
  59. struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
  60. struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
  61. struct input_dev *dev = hidinput->input;
  62. int error;
  63. if (list_empty(report_list)) {
  64. hid_err(hid, "no output reports found\n");
  65. return -ENODEV;
  66. }
  67. report = list_first_entry(report_list, struct hid_report, list);
  68. if (report->maxfield < 4) {
  69. hid_err(hid, "no fields in the report: %d\n", report->maxfield);
  70. return -ENODEV;
  71. }
  72. axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
  73. if (!axff)
  74. return -ENOMEM;
  75. set_bit(FF_RUMBLE, dev->ffbit);
  76. error = input_ff_create_memless(dev, axff, axff_play);
  77. if (error)
  78. goto err_free_mem;
  79. axff->report = report;
  80. axff->report->field[0]->value[0] = 0x00;
  81. axff->report->field[1]->value[0] = 0x00;
  82. axff->report->field[2]->value[0] = 0x00;
  83. axff->report->field[3]->value[0] = 0x00;
  84. usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
  85. hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
  86. return 0;
  87. err_free_mem:
  88. kfree(axff);
  89. return error;
  90. }
  91. static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
  92. {
  93. int error;
  94. dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
  95. error = hid_parse(hdev);
  96. if (error) {
  97. hid_err(hdev, "parse failed\n");
  98. return error;
  99. }
  100. error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
  101. if (error) {
  102. hid_err(hdev, "hw start failed\n");
  103. return error;
  104. }
  105. error = axff_init(hdev);
  106. if (error) {
  107. /*
  108. * Do not fail device initialization completely as device
  109. * may still be partially operable, just warn.
  110. */
  111. hid_warn(hdev,
  112. "Failed to enable force feedback support, error: %d\n",
  113. error);
  114. }
  115. return 0;
  116. }
  117. static const struct hid_device_id ax_devices[] = {
  118. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
  119. { }
  120. };
  121. MODULE_DEVICE_TABLE(hid, ax_devices);
  122. static struct hid_driver ax_driver = {
  123. .name = "acrux",
  124. .id_table = ax_devices,
  125. .probe = ax_probe,
  126. };
  127. static int __init ax_init(void)
  128. {
  129. return hid_register_driver(&ax_driver);
  130. }
  131. static void __exit ax_exit(void)
  132. {
  133. hid_unregister_driver(&ax_driver);
  134. }
  135. module_init(ax_init);
  136. module_exit(ax_exit);
  137. MODULE_AUTHOR("Sergei Kolzun");
  138. MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
  139. MODULE_LICENSE("GPL");