0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/input.h>
0019 #include <linux/slab.h>
0020 #include <linux/hid.h>
0021 #include <linux/module.h>
0022
0023 #include "hid-ids.h"
0024
0025 #ifdef CONFIG_HID_ACRUX_FF
0026
0027 struct axff_device {
0028 struct hid_report *report;
0029 };
0030
0031 static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
0032 {
0033 struct hid_device *hid = input_get_drvdata(dev);
0034 struct axff_device *axff = data;
0035 struct hid_report *report = axff->report;
0036 int field_count = 0;
0037 int left, right;
0038 int i, j;
0039
0040 left = effect->u.rumble.strong_magnitude;
0041 right = effect->u.rumble.weak_magnitude;
0042
0043 dbg_hid("called with 0x%04x 0x%04x", left, right);
0044
0045 left = left * 0xff / 0xffff;
0046 right = right * 0xff / 0xffff;
0047
0048 for (i = 0; i < report->maxfield; i++) {
0049 for (j = 0; j < report->field[i]->report_count; j++) {
0050 report->field[i]->value[j] =
0051 field_count % 2 ? right : left;
0052 field_count++;
0053 }
0054 }
0055
0056 dbg_hid("running with 0x%02x 0x%02x", left, right);
0057 hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
0058
0059 return 0;
0060 }
0061
0062 static int axff_init(struct hid_device *hid)
0063 {
0064 struct axff_device *axff;
0065 struct hid_report *report;
0066 struct hid_input *hidinput;
0067 struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
0068 struct input_dev *dev;
0069 int field_count = 0;
0070 int i, j;
0071 int error;
0072
0073 if (list_empty(&hid->inputs)) {
0074 hid_err(hid, "no inputs found\n");
0075 return -ENODEV;
0076 }
0077 hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
0078 dev = hidinput->input;
0079
0080 if (list_empty(report_list)) {
0081 hid_err(hid, "no output reports found\n");
0082 return -ENODEV;
0083 }
0084
0085 report = list_first_entry(report_list, struct hid_report, list);
0086 for (i = 0; i < report->maxfield; i++) {
0087 for (j = 0; j < report->field[i]->report_count; j++) {
0088 report->field[i]->value[j] = 0x00;
0089 field_count++;
0090 }
0091 }
0092
0093 if (field_count < 4 && hid->product != 0xf705) {
0094 hid_err(hid, "not enough fields in the report: %d\n",
0095 field_count);
0096 return -ENODEV;
0097 }
0098
0099 axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
0100 if (!axff)
0101 return -ENOMEM;
0102
0103 set_bit(FF_RUMBLE, dev->ffbit);
0104
0105 error = input_ff_create_memless(dev, axff, axff_play);
0106 if (error)
0107 goto err_free_mem;
0108
0109 axff->report = report;
0110 hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
0111
0112 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <x0r@dv-life.ru>\n");
0113
0114 return 0;
0115
0116 err_free_mem:
0117 kfree(axff);
0118 return error;
0119 }
0120 #else
0121 static inline int axff_init(struct hid_device *hid)
0122 {
0123 return 0;
0124 }
0125 #endif
0126
0127 static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
0128 {
0129 int error;
0130
0131 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
0132
0133 error = hid_parse(hdev);
0134 if (error) {
0135 hid_err(hdev, "parse failed\n");
0136 return error;
0137 }
0138
0139 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
0140 if (error) {
0141 hid_err(hdev, "hw start failed\n");
0142 return error;
0143 }
0144
0145 error = axff_init(hdev);
0146 if (error) {
0147
0148
0149
0150
0151 hid_warn(hdev,
0152 "Failed to enable force feedback support, error: %d\n",
0153 error);
0154 }
0155
0156
0157
0158
0159
0160 error = hid_hw_open(hdev);
0161 if (error) {
0162 dev_err(&hdev->dev, "hw open failed\n");
0163 hid_hw_stop(hdev);
0164 return error;
0165 }
0166
0167 return 0;
0168 }
0169
0170 static void ax_remove(struct hid_device *hdev)
0171 {
0172 hid_hw_close(hdev);
0173 hid_hw_stop(hdev);
0174 }
0175
0176 static const struct hid_device_id ax_devices[] = {
0177 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
0178 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705), },
0179 { }
0180 };
0181 MODULE_DEVICE_TABLE(hid, ax_devices);
0182
0183 static struct hid_driver ax_driver = {
0184 .name = "acrux",
0185 .id_table = ax_devices,
0186 .probe = ax_probe,
0187 .remove = ax_remove,
0188 };
0189 module_hid_driver(ax_driver);
0190
0191 MODULE_AUTHOR("Sergei Kolzun");
0192 MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
0193 MODULE_LICENSE("GPL");