hid-sjoy.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Force feedback support for SmartJoy PLUS PS2->USB adapter
  3. *
  4. * Copyright (c) 2009 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
  5. *
  6. * Based of hid-pl.c and hid-gaff.c
  7. * Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com>
  8. * Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info>
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. /* #define DEBUG */
  26. #include <linux/input.h>
  27. #include <linux/slab.h>
  28. #include <linux/hid.h>
  29. #include <linux/module.h>
  30. #include "hid-ids.h"
  31. #ifdef CONFIG_SMARTJOYPLUS_FF
  32. struct sjoyff_device {
  33. struct hid_report *report;
  34. };
  35. static int hid_sjoyff_play(struct input_dev *dev, void *data,
  36. struct ff_effect *effect)
  37. {
  38. struct hid_device *hid = input_get_drvdata(dev);
  39. struct sjoyff_device *sjoyff = data;
  40. u32 left, right;
  41. left = effect->u.rumble.strong_magnitude;
  42. right = effect->u.rumble.weak_magnitude;
  43. dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right);
  44. left = left * 0xff / 0xffff;
  45. right = (right != 0); /* on/off only */
  46. sjoyff->report->field[0]->value[1] = right;
  47. sjoyff->report->field[0]->value[2] = left;
  48. dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right);
  49. hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
  50. return 0;
  51. }
  52. static int sjoyff_init(struct hid_device *hid)
  53. {
  54. struct sjoyff_device *sjoyff;
  55. struct hid_report *report;
  56. struct hid_input *hidinput;
  57. struct list_head *report_list =
  58. &hid->report_enum[HID_OUTPUT_REPORT].report_list;
  59. struct list_head *report_ptr = report_list;
  60. struct input_dev *dev;
  61. int error;
  62. if (list_empty(report_list)) {
  63. hid_err(hid, "no output reports found\n");
  64. return -ENODEV;
  65. }
  66. list_for_each_entry(hidinput, &hid->inputs, list) {
  67. report_ptr = report_ptr->next;
  68. if (report_ptr == report_list) {
  69. hid_err(hid, "required output report is missing\n");
  70. return -ENODEV;
  71. }
  72. report = list_entry(report_ptr, struct hid_report, list);
  73. if (report->maxfield < 1) {
  74. hid_err(hid, "no fields in the report\n");
  75. return -ENODEV;
  76. }
  77. if (report->field[0]->report_count < 3) {
  78. hid_err(hid, "not enough values in the field\n");
  79. return -ENODEV;
  80. }
  81. sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL);
  82. if (!sjoyff)
  83. return -ENOMEM;
  84. dev = hidinput->input;
  85. set_bit(FF_RUMBLE, dev->ffbit);
  86. error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play);
  87. if (error) {
  88. kfree(sjoyff);
  89. return error;
  90. }
  91. sjoyff->report = report;
  92. sjoyff->report->field[0]->value[0] = 0x01;
  93. sjoyff->report->field[0]->value[1] = 0x00;
  94. sjoyff->report->field[0]->value[2] = 0x00;
  95. hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
  96. }
  97. hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
  98. return 0;
  99. }
  100. #else
  101. static inline int sjoyff_init(struct hid_device *hid)
  102. {
  103. return 0;
  104. }
  105. #endif
  106. static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
  107. {
  108. int ret;
  109. hdev->quirks |= id->driver_data;
  110. ret = hid_parse(hdev);
  111. if (ret) {
  112. hid_err(hdev, "parse failed\n");
  113. goto err;
  114. }
  115. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
  116. if (ret) {
  117. hid_err(hdev, "hw start failed\n");
  118. goto err;
  119. }
  120. sjoyff_init(hdev);
  121. return 0;
  122. err:
  123. return ret;
  124. }
  125. static const struct hid_device_id sjoy_devices[] = {
  126. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO),
  127. .driver_data = HID_QUIRK_NOGET },
  128. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO),
  129. .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
  130. HID_QUIRK_SKIP_OUTPUT_REPORTS },
  131. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO),
  132. .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
  133. HID_QUIRK_SKIP_OUTPUT_REPORTS },
  134. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
  135. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
  136. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD),
  137. .driver_data = HID_QUIRK_MULTI_INPUT |
  138. HID_QUIRK_SKIP_OUTPUT_REPORTS },
  139. { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII),
  140. .driver_data = HID_QUIRK_MULTI_INPUT |
  141. HID_QUIRK_SKIP_OUTPUT_REPORTS },
  142. { }
  143. };
  144. MODULE_DEVICE_TABLE(hid, sjoy_devices);
  145. static struct hid_driver sjoy_driver = {
  146. .name = "smartjoyplus",
  147. .id_table = sjoy_devices,
  148. .probe = sjoy_probe,
  149. };
  150. module_hid_driver(sjoy_driver);
  151. MODULE_LICENSE("GPL");
  152. MODULE_AUTHOR("Jussi Kivilinna");