hid-pl.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Force feedback support for PantherLord/GreenAsia based devices
  3. *
  4. * The devices are distributed under various names and the same USB device ID
  5. * can be used in both adapters and actual game controllers.
  6. *
  7. * 0810:0001 "Twin USB Joystick"
  8. * - tested with PantherLord USB/PS2 2in1 Adapter
  9. * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT)
  10. *
  11. * 0e8f:0003 "GreenAsia Inc. USB Joystick "
  12. * - tested with K??ng Gaming gamepad
  13. *
  14. * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
  15. */
  16. /*
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. */
  31. /* #define DEBUG */
  32. #define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg)
  33. #include <linux/input.h>
  34. #include <linux/usb.h>
  35. #include <linux/hid.h>
  36. #include "hid-ids.h"
  37. #ifdef CONFIG_PANTHERLORD_FF
  38. #include "usbhid/usbhid.h"
  39. struct plff_device {
  40. struct hid_report *report;
  41. };
  42. static int hid_plff_play(struct input_dev *dev, void *data,
  43. struct ff_effect *effect)
  44. {
  45. struct hid_device *hid = input_get_drvdata(dev);
  46. struct plff_device *plff = data;
  47. int left, right;
  48. left = effect->u.rumble.strong_magnitude;
  49. right = effect->u.rumble.weak_magnitude;
  50. debug("called with 0x%04x 0x%04x", left, right);
  51. left = left * 0x7f / 0xffff;
  52. right = right * 0x7f / 0xffff;
  53. plff->report->field[0]->value[2] = left;
  54. plff->report->field[0]->value[3] = right;
  55. debug("running with 0x%02x 0x%02x", left, right);
  56. usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
  57. return 0;
  58. }
  59. static int plff_init(struct hid_device *hid)
  60. {
  61. struct plff_device *plff;
  62. struct hid_report *report;
  63. struct hid_input *hidinput;
  64. struct list_head *report_list =
  65. &hid->report_enum[HID_OUTPUT_REPORT].report_list;
  66. struct list_head *report_ptr = report_list;
  67. struct input_dev *dev;
  68. int error;
  69. /* The device contains one output report per physical device, all
  70. containing 1 field, which contains 4 ff00.0002 usages and 4 16bit
  71. absolute values.
  72. The input reports also contain a field which contains
  73. 8 ff00.0001 usages and 8 boolean values. Their meaning is
  74. currently unknown. */
  75. if (list_empty(report_list)) {
  76. dev_err(&hid->dev, "no output reports found\n");
  77. return -ENODEV;
  78. }
  79. list_for_each_entry(hidinput, &hid->inputs, list) {
  80. report_ptr = report_ptr->next;
  81. if (report_ptr == report_list) {
  82. dev_err(&hid->dev, "required output report is "
  83. "missing\n");
  84. return -ENODEV;
  85. }
  86. report = list_entry(report_ptr, struct hid_report, list);
  87. if (report->maxfield < 1) {
  88. dev_err(&hid->dev, "no fields in the report\n");
  89. return -ENODEV;
  90. }
  91. if (report->field[0]->report_count < 4) {
  92. dev_err(&hid->dev, "not enough values in the field\n");
  93. return -ENODEV;
  94. }
  95. plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL);
  96. if (!plff)
  97. return -ENOMEM;
  98. dev = hidinput->input;
  99. set_bit(FF_RUMBLE, dev->ffbit);
  100. error = input_ff_create_memless(dev, plff, hid_plff_play);
  101. if (error) {
  102. kfree(plff);
  103. return error;
  104. }
  105. plff->report = report;
  106. plff->report->field[0]->value[0] = 0x00;
  107. plff->report->field[0]->value[1] = 0x00;
  108. plff->report->field[0]->value[2] = 0x00;
  109. plff->report->field[0]->value[3] = 0x00;
  110. usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
  111. }
  112. dev_info(&hid->dev, "Force feedback for PantherLord/GreenAsia "
  113. "devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
  114. return 0;
  115. }
  116. #else
  117. static inline int plff_init(struct hid_device *hid)
  118. {
  119. return 0;
  120. }
  121. #endif
  122. static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
  123. {
  124. int ret;
  125. if (id->driver_data)
  126. hdev->quirks |= HID_QUIRK_MULTI_INPUT;
  127. ret = hid_parse(hdev);
  128. if (ret) {
  129. dev_err(&hdev->dev, "parse failed\n");
  130. goto err;
  131. }
  132. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
  133. if (ret) {
  134. dev_err(&hdev->dev, "hw start failed\n");
  135. goto err;
  136. }
  137. plff_init(hdev);
  138. return 0;
  139. err:
  140. return ret;
  141. }
  142. static const struct hid_device_id pl_devices[] = {
  143. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR),
  144. .driver_data = 1 }, /* Twin USB Joystick */
  145. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR),
  146. .driver_data = 1 }, /* Twin USB Joystick */
  147. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, /* GreenAsia Inc. USB Joystick */
  148. { }
  149. };
  150. MODULE_DEVICE_TABLE(hid, pl_devices);
  151. static struct hid_driver pl_driver = {
  152. .name = "pantherlord",
  153. .id_table = pl_devices,
  154. .probe = pl_probe,
  155. };
  156. static int pl_init(void)
  157. {
  158. return hid_register_driver(&pl_driver);
  159. }
  160. static void pl_exit(void)
  161. {
  162. hid_unregister_driver(&pl_driver);
  163. }
  164. module_init(pl_init);
  165. module_exit(pl_exit);
  166. MODULE_LICENSE("GPL");
  167. HID_COMPAT_LOAD_DRIVER(pantherlord);