hid-axff.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #ifdef CONFIG_HID_ACRUX_FF
  34. #include "usbhid/usbhid.h"
  35. struct axff_device {
  36. struct hid_report *report;
  37. };
  38. static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
  39. {
  40. struct hid_device *hid = input_get_drvdata(dev);
  41. struct axff_device *axff = data;
  42. int left, right;
  43. left = effect->u.rumble.strong_magnitude;
  44. right = effect->u.rumble.weak_magnitude;
  45. dbg_hid("called with 0x%04x 0x%04x", left, right);
  46. left = left * 0xff / 0xffff;
  47. right = right * 0xff / 0xffff;
  48. axff->report->field[0]->value[0] = left;
  49. axff->report->field[1]->value[0] = right;
  50. axff->report->field[2]->value[0] = left;
  51. axff->report->field[3]->value[0] = right;
  52. dbg_hid("running with 0x%02x 0x%02x", left, right);
  53. usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
  54. return 0;
  55. }
  56. static int axff_init(struct hid_device *hid)
  57. {
  58. struct axff_device *axff;
  59. struct hid_report *report;
  60. struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
  61. struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
  62. struct input_dev *dev = hidinput->input;
  63. int error;
  64. if (list_empty(report_list)) {
  65. hid_err(hid, "no output reports found\n");
  66. return -ENODEV;
  67. }
  68. report = list_first_entry(report_list, struct hid_report, list);
  69. if (report->maxfield < 4) {
  70. hid_err(hid, "no fields in the report: %d\n", report->maxfield);
  71. return -ENODEV;
  72. }
  73. axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
  74. if (!axff)
  75. return -ENOMEM;
  76. set_bit(FF_RUMBLE, dev->ffbit);
  77. error = input_ff_create_memless(dev, axff, axff_play);
  78. if (error)
  79. goto err_free_mem;
  80. axff->report = report;
  81. axff->report->field[0]->value[0] = 0x00;
  82. axff->report->field[1]->value[0] = 0x00;
  83. axff->report->field[2]->value[0] = 0x00;
  84. axff->report->field[3]->value[0] = 0x00;
  85. usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
  86. hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
  87. return 0;
  88. err_free_mem:
  89. kfree(axff);
  90. return error;
  91. }
  92. #else
  93. static inline int axff_init(struct hid_device *hid)
  94. {
  95. return 0;
  96. }
  97. #endif
  98. static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
  99. {
  100. int error;
  101. dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
  102. error = hid_parse(hdev);
  103. if (error) {
  104. hid_err(hdev, "parse failed\n");
  105. return error;
  106. }
  107. error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
  108. if (error) {
  109. hid_err(hdev, "hw start failed\n");
  110. return error;
  111. }
  112. error = axff_init(hdev);
  113. if (error) {
  114. /*
  115. * Do not fail device initialization completely as device
  116. * may still be partially operable, just warn.
  117. */
  118. hid_warn(hdev,
  119. "Failed to enable force feedback support, error: %d\n",
  120. error);
  121. }
  122. /*
  123. * We need to start polling device right away, otherwise
  124. * it will go into a coma.
  125. */
  126. error = hid_hw_open(hdev);
  127. if (error) {
  128. dev_err(&hdev->dev, "hw open failed\n");
  129. return error;
  130. }
  131. return 0;
  132. }
  133. static void ax_remove(struct hid_device *hdev)
  134. {
  135. hid_hw_close(hdev);
  136. hid_hw_stop(hdev);
  137. }
  138. static const struct hid_device_id ax_devices[] = {
  139. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
  140. { }
  141. };
  142. MODULE_DEVICE_TABLE(hid, ax_devices);
  143. static struct hid_driver ax_driver = {
  144. .name = "acrux",
  145. .id_table = ax_devices,
  146. .probe = ax_probe,
  147. .remove = ax_remove,
  148. };
  149. static int __init ax_init(void)
  150. {
  151. return hid_register_driver(&ax_driver);
  152. }
  153. static void __exit ax_exit(void)
  154. {
  155. hid_unregister_driver(&ax_driver);
  156. }
  157. module_init(ax_init);
  158. module_exit(ax_exit);
  159. MODULE_AUTHOR("Sergei Kolzun");
  160. MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
  161. MODULE_LICENSE("GPL");