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_GREENASIA_FF
0024
0025 struct gaff_device {
0026 struct hid_report *report;
0027 };
0028
0029 static int hid_gaff_play(struct input_dev *dev, void *data,
0030 struct ff_effect *effect)
0031 {
0032 struct hid_device *hid = input_get_drvdata(dev);
0033 struct gaff_device *gaff = data;
0034 int left, right;
0035
0036 left = effect->u.rumble.strong_magnitude;
0037 right = effect->u.rumble.weak_magnitude;
0038
0039 dbg_hid("called with 0x%04x 0x%04x", left, right);
0040
0041 left = left * 0xfe / 0xffff;
0042 right = right * 0xfe / 0xffff;
0043
0044 gaff->report->field[0]->value[0] = 0x51;
0045 gaff->report->field[0]->value[1] = 0x0;
0046 gaff->report->field[0]->value[2] = right;
0047 gaff->report->field[0]->value[3] = 0;
0048 gaff->report->field[0]->value[4] = left;
0049 gaff->report->field[0]->value[5] = 0;
0050 dbg_hid("running with 0x%02x 0x%02x", left, right);
0051 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
0052
0053 gaff->report->field[0]->value[0] = 0xfa;
0054 gaff->report->field[0]->value[1] = 0xfe;
0055 gaff->report->field[0]->value[2] = 0x0;
0056 gaff->report->field[0]->value[4] = 0x0;
0057
0058 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
0059
0060 return 0;
0061 }
0062
0063 static int gaff_init(struct hid_device *hid)
0064 {
0065 struct gaff_device *gaff;
0066 struct hid_report *report;
0067 struct hid_input *hidinput;
0068 struct list_head *report_list =
0069 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
0070 struct list_head *report_ptr = report_list;
0071 struct input_dev *dev;
0072 int error;
0073
0074 if (list_empty(&hid->inputs)) {
0075 hid_err(hid, "no inputs found\n");
0076 return -ENODEV;
0077 }
0078 hidinput = list_entry(hid->inputs.next, struct hid_input, list);
0079 dev = hidinput->input;
0080
0081 if (list_empty(report_list)) {
0082 hid_err(hid, "no output reports found\n");
0083 return -ENODEV;
0084 }
0085
0086 report_ptr = report_ptr->next;
0087
0088 report = list_entry(report_ptr, struct hid_report, list);
0089 if (report->maxfield < 1) {
0090 hid_err(hid, "no fields in the report\n");
0091 return -ENODEV;
0092 }
0093
0094 if (report->field[0]->report_count < 6) {
0095 hid_err(hid, "not enough values in the field\n");
0096 return -ENODEV;
0097 }
0098
0099 gaff = kzalloc(sizeof(struct gaff_device), GFP_KERNEL);
0100 if (!gaff)
0101 return -ENOMEM;
0102
0103 set_bit(FF_RUMBLE, dev->ffbit);
0104
0105 error = input_ff_create_memless(dev, gaff, hid_gaff_play);
0106 if (error) {
0107 kfree(gaff);
0108 return error;
0109 }
0110
0111 gaff->report = report;
0112 gaff->report->field[0]->value[0] = 0x51;
0113 gaff->report->field[0]->value[1] = 0x00;
0114 gaff->report->field[0]->value[2] = 0x00;
0115 gaff->report->field[0]->value[3] = 0x00;
0116 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
0117
0118 gaff->report->field[0]->value[0] = 0xfa;
0119 gaff->report->field[0]->value[1] = 0xfe;
0120
0121 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
0122
0123 hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
0124
0125 return 0;
0126 }
0127 #else
0128 static inline int gaff_init(struct hid_device *hdev)
0129 {
0130 return 0;
0131 }
0132 #endif
0133
0134 static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id)
0135 {
0136 int ret;
0137
0138 dev_dbg(&hdev->dev, "Greenasia HID hardware probe...");
0139
0140 ret = hid_parse(hdev);
0141 if (ret) {
0142 hid_err(hdev, "parse failed\n");
0143 goto err;
0144 }
0145
0146 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
0147 if (ret) {
0148 hid_err(hdev, "hw start failed\n");
0149 goto err;
0150 }
0151
0152 gaff_init(hdev);
0153
0154 return 0;
0155 err:
0156 return ret;
0157 }
0158
0159 static const struct hid_device_id ga_devices[] = {
0160 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012), },
0161 { }
0162 };
0163 MODULE_DEVICE_TABLE(hid, ga_devices);
0164
0165 static struct hid_driver ga_driver = {
0166 .name = "greenasia",
0167 .id_table = ga_devices,
0168 .probe = ga_probe,
0169 };
0170 module_hid_driver(ga_driver);
0171
0172 MODULE_LICENSE("GPL");