0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/input.h>
0018 #include <linux/slab.h>
0019 #include <linux/hid.h>
0020 #include <linux/module.h>
0021 #include "hid-ids.h"
0022
0023 #ifdef CONFIG_SMARTJOYPLUS_FF
0024
0025 struct sjoyff_device {
0026 struct hid_report *report;
0027 };
0028
0029 static int hid_sjoyff_play(struct input_dev *dev, void *data,
0030 struct ff_effect *effect)
0031 {
0032 struct hid_device *hid = input_get_drvdata(dev);
0033 struct sjoyff_device *sjoyff = data;
0034 u32 left, right;
0035
0036 left = effect->u.rumble.strong_magnitude;
0037 right = effect->u.rumble.weak_magnitude;
0038 dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right);
0039
0040 left = left * 0xff / 0xffff;
0041 right = (right != 0);
0042
0043 sjoyff->report->field[0]->value[1] = right;
0044 sjoyff->report->field[0]->value[2] = left;
0045 dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right);
0046 hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
0047
0048 return 0;
0049 }
0050
0051 static int sjoyff_init(struct hid_device *hid)
0052 {
0053 struct sjoyff_device *sjoyff;
0054 struct hid_report *report;
0055 struct hid_input *hidinput;
0056 struct list_head *report_list =
0057 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
0058 struct list_head *report_ptr = report_list;
0059 struct input_dev *dev;
0060 int error;
0061
0062 if (list_empty(report_list)) {
0063 hid_err(hid, "no output reports found\n");
0064 return -ENODEV;
0065 }
0066
0067 list_for_each_entry(hidinput, &hid->inputs, list) {
0068 report_ptr = report_ptr->next;
0069
0070 if (report_ptr == report_list) {
0071 hid_err(hid, "required output report is missing\n");
0072 return -ENODEV;
0073 }
0074
0075 report = list_entry(report_ptr, struct hid_report, list);
0076 if (report->maxfield < 1) {
0077 hid_err(hid, "no fields in the report\n");
0078 return -ENODEV;
0079 }
0080
0081 if (report->field[0]->report_count < 3) {
0082 hid_err(hid, "not enough values in the field\n");
0083 return -ENODEV;
0084 }
0085
0086 sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL);
0087 if (!sjoyff)
0088 return -ENOMEM;
0089
0090 dev = hidinput->input;
0091
0092 set_bit(FF_RUMBLE, dev->ffbit);
0093
0094 error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play);
0095 if (error) {
0096 kfree(sjoyff);
0097 return error;
0098 }
0099
0100 sjoyff->report = report;
0101 sjoyff->report->field[0]->value[0] = 0x01;
0102 sjoyff->report->field[0]->value[1] = 0x00;
0103 sjoyff->report->field[0]->value[2] = 0x00;
0104 hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT);
0105 }
0106
0107 hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
0108
0109 return 0;
0110 }
0111 #else
0112 static inline int sjoyff_init(struct hid_device *hid)
0113 {
0114 return 0;
0115 }
0116 #endif
0117
0118 static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
0119 {
0120 int ret;
0121
0122 hdev->quirks |= id->driver_data;
0123
0124 ret = hid_parse(hdev);
0125 if (ret) {
0126 hid_err(hdev, "parse failed\n");
0127 goto err;
0128 }
0129
0130 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
0131 if (ret) {
0132 hid_err(hdev, "hw start failed\n");
0133 goto err;
0134 }
0135
0136 sjoyff_init(hdev);
0137
0138 return 0;
0139 err:
0140 return ret;
0141 }
0142
0143 static const struct hid_device_id sjoy_devices[] = {
0144 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO),
0145 .driver_data = HID_QUIRK_NOGET },
0146 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO),
0147 .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
0148 HID_QUIRK_SKIP_OUTPUT_REPORTS },
0149 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO),
0150 .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
0151 HID_QUIRK_SKIP_OUTPUT_REPORTS },
0152 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
0153 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
0154 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD),
0155 .driver_data = HID_QUIRK_MULTI_INPUT |
0156 HID_QUIRK_SKIP_OUTPUT_REPORTS },
0157 { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII),
0158 .driver_data = HID_QUIRK_MULTI_INPUT |
0159 HID_QUIRK_SKIP_OUTPUT_REPORTS },
0160 { }
0161 };
0162 MODULE_DEVICE_TABLE(hid, sjoy_devices);
0163
0164 static struct hid_driver sjoy_driver = {
0165 .name = "smartjoyplus",
0166 .id_table = sjoy_devices,
0167 .probe = sjoy_probe,
0168 };
0169 module_hid_driver(sjoy_driver);
0170
0171 MODULE_LICENSE("GPL");
0172 MODULE_AUTHOR("Jussi Kivilinna");
0173