0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg)
0030
0031 #include <linux/input.h>
0032 #include <linux/slab.h>
0033 #include <linux/module.h>
0034 #include <linux/hid.h>
0035
0036 #include "hid-ids.h"
0037
0038 #ifdef CONFIG_PANTHERLORD_FF
0039
0040 struct plff_device {
0041 struct hid_report *report;
0042 s32 maxval;
0043 s32 *strong;
0044 s32 *weak;
0045 };
0046
0047 static int hid_plff_play(struct input_dev *dev, void *data,
0048 struct ff_effect *effect)
0049 {
0050 struct hid_device *hid = input_get_drvdata(dev);
0051 struct plff_device *plff = data;
0052 int left, right;
0053
0054 left = effect->u.rumble.strong_magnitude;
0055 right = effect->u.rumble.weak_magnitude;
0056 debug("called with 0x%04x 0x%04x", left, right);
0057
0058 left = left * plff->maxval / 0xffff;
0059 right = right * plff->maxval / 0xffff;
0060
0061 *plff->strong = left;
0062 *plff->weak = right;
0063 debug("running with 0x%02x 0x%02x", left, right);
0064 hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT);
0065
0066 return 0;
0067 }
0068
0069 static int plff_init(struct hid_device *hid)
0070 {
0071 struct plff_device *plff;
0072 struct hid_report *report;
0073 struct hid_input *hidinput;
0074 struct list_head *report_list =
0075 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
0076 struct list_head *report_ptr = report_list;
0077 struct input_dev *dev;
0078 int error;
0079 s32 maxval;
0080 s32 *strong;
0081 s32 *weak;
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 if (list_empty(report_list)) {
0097 hid_err(hid, "no output reports found\n");
0098 return -ENODEV;
0099 }
0100
0101 list_for_each_entry(hidinput, &hid->inputs, list) {
0102
0103 report_ptr = report_ptr->next;
0104
0105 if (report_ptr == report_list) {
0106 hid_err(hid, "required output report is missing\n");
0107 return -ENODEV;
0108 }
0109
0110 report = list_entry(report_ptr, struct hid_report, list);
0111 if (report->maxfield < 1) {
0112 hid_err(hid, "no fields in the report\n");
0113 return -ENODEV;
0114 }
0115
0116 maxval = 0x7f;
0117 if (report->field[0]->report_count >= 4) {
0118 report->field[0]->value[0] = 0x00;
0119 report->field[0]->value[1] = 0x00;
0120 strong = &report->field[0]->value[2];
0121 weak = &report->field[0]->value[3];
0122 debug("detected single-field device");
0123 } else if (report->field[0]->maxusage == 1 &&
0124 report->field[0]->usage[0].hid ==
0125 (HID_UP_LED | 0x43) &&
0126 report->maxfield >= 4 &&
0127 report->field[0]->report_count >= 1 &&
0128 report->field[1]->report_count >= 1 &&
0129 report->field[2]->report_count >= 1 &&
0130 report->field[3]->report_count >= 1) {
0131 report->field[0]->value[0] = 0x00;
0132 report->field[1]->value[0] = 0x00;
0133 strong = &report->field[2]->value[0];
0134 weak = &report->field[3]->value[0];
0135 if (hid->vendor == USB_VENDOR_ID_JESS2)
0136 maxval = 0xff;
0137 debug("detected 4-field device");
0138 } else {
0139 hid_err(hid, "not enough fields or values\n");
0140 return -ENODEV;
0141 }
0142
0143 plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL);
0144 if (!plff)
0145 return -ENOMEM;
0146
0147 dev = hidinput->input;
0148
0149 set_bit(FF_RUMBLE, dev->ffbit);
0150
0151 error = input_ff_create_memless(dev, plff, hid_plff_play);
0152 if (error) {
0153 kfree(plff);
0154 return error;
0155 }
0156
0157 plff->report = report;
0158 plff->strong = strong;
0159 plff->weak = weak;
0160 plff->maxval = maxval;
0161
0162 *strong = 0x00;
0163 *weak = 0x00;
0164 hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT);
0165 }
0166
0167 hid_info(hid, "Force feedback for PantherLord/GreenAsia devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
0168
0169 return 0;
0170 }
0171 #else
0172 static inline int plff_init(struct hid_device *hid)
0173 {
0174 return 0;
0175 }
0176 #endif
0177
0178 static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
0179 {
0180 int ret;
0181
0182 if (id->driver_data)
0183 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
0184
0185 ret = hid_parse(hdev);
0186 if (ret) {
0187 hid_err(hdev, "parse failed\n");
0188 goto err;
0189 }
0190
0191 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
0192 if (ret) {
0193 hid_err(hdev, "hw start failed\n");
0194 goto err;
0195 }
0196
0197 plff_init(hdev);
0198
0199 return 0;
0200 err:
0201 return ret;
0202 }
0203
0204 static const struct hid_device_id pl_devices[] = {
0205 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR),
0206 .driver_data = 1 },
0207 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR),
0208 .driver_data = 1 },
0209 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), },
0210 { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD), },
0211 { }
0212 };
0213 MODULE_DEVICE_TABLE(hid, pl_devices);
0214
0215 static struct hid_driver pl_driver = {
0216 .name = "pantherlord",
0217 .id_table = pl_devices,
0218 .probe = pl_probe,
0219 };
0220 module_hid_driver(pl_driver);
0221
0222 MODULE_LICENSE("GPL");