0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <linux/input.h>
0024 #include <linux/slab.h>
0025 #include <linux/hid.h>
0026 #include <linux/module.h>
0027
0028 #include "hid-ids.h"
0029
0030 struct mf_device {
0031 struct hid_report *report;
0032 };
0033
0034 static int mf_play(struct input_dev *dev, void *data, struct ff_effect *effect)
0035 {
0036 struct hid_device *hid = input_get_drvdata(dev);
0037 struct mf_device *mf = data;
0038 int strong, weak;
0039
0040 strong = effect->u.rumble.strong_magnitude;
0041 weak = effect->u.rumble.weak_magnitude;
0042
0043 dbg_hid("Called with 0x%04x 0x%04x.\n", strong, weak);
0044
0045 strong = strong * 0xff / 0xffff;
0046 weak = weak * 0xff / 0xffff;
0047
0048 dbg_hid("Running with 0x%02x 0x%02x.\n", strong, weak);
0049
0050 mf->report->field[0]->value[0] = weak;
0051 mf->report->field[0]->value[1] = strong;
0052 hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT);
0053
0054 return 0;
0055 }
0056
0057 static int mf_init(struct hid_device *hid)
0058 {
0059 struct mf_device *mf;
0060
0061 struct list_head *report_list =
0062 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
0063
0064 struct list_head *report_ptr;
0065 struct hid_report *report;
0066
0067 struct list_head *input_ptr = &hid->inputs;
0068 struct hid_input *input;
0069
0070 struct input_dev *dev;
0071
0072 int error;
0073
0074
0075 list_for_each(report_ptr, report_list) {
0076 report = list_entry(report_ptr, struct hid_report, list);
0077
0078 if (report->maxfield < 1 || report->field[0]->report_count < 2) {
0079 hid_err(hid, "Invalid report, this should never happen!\n");
0080 return -ENODEV;
0081 }
0082
0083 if (list_is_last(input_ptr, &hid->inputs)) {
0084 hid_err(hid, "Missing input, this should never happen!\n");
0085 return -ENODEV;
0086 }
0087
0088 input_ptr = input_ptr->next;
0089 input = list_entry(input_ptr, struct hid_input, list);
0090
0091 mf = kzalloc(sizeof(struct mf_device), GFP_KERNEL);
0092 if (!mf)
0093 return -ENOMEM;
0094
0095 dev = input->input;
0096 set_bit(FF_RUMBLE, dev->ffbit);
0097
0098 error = input_ff_create_memless(dev, mf, mf_play);
0099 if (error) {
0100 kfree(mf);
0101 return error;
0102 }
0103
0104 mf->report = report;
0105 mf->report->field[0]->value[0] = 0x00;
0106 mf->report->field[0]->value[1] = 0x00;
0107 hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT);
0108 }
0109
0110 hid_info(hid, "Force feedback for HJZ Mayflash game controller "
0111 "adapters by Marcel Hasler <mahasler@gmail.com>\n");
0112
0113 return 0;
0114 }
0115
0116 static int mf_probe(struct hid_device *hid, const struct hid_device_id *id)
0117 {
0118 int error;
0119
0120 dev_dbg(&hid->dev, "Mayflash HID hardware probe...\n");
0121
0122
0123 hid->quirks |= id->driver_data;
0124
0125 error = hid_parse(hid);
0126 if (error) {
0127 hid_err(hid, "HID parse failed.\n");
0128 return error;
0129 }
0130
0131 error = hid_hw_start(hid, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
0132 if (error) {
0133 hid_err(hid, "HID hw start failed\n");
0134 return error;
0135 }
0136
0137 error = mf_init(hid);
0138 if (error) {
0139 hid_err(hid, "Force feedback init failed.\n");
0140 hid_hw_stop(hid);
0141 return error;
0142 }
0143
0144 return 0;
0145 }
0146
0147 static const struct hid_device_id mf_devices[] = {
0148 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3),
0149 .driver_data = HID_QUIRK_MULTI_INPUT },
0150 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_DOLPHINBAR),
0151 .driver_data = HID_QUIRK_MULTI_INPUT },
0152 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE1),
0153 .driver_data = HID_QUIRK_MULTI_INPUT },
0154 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE2),
0155 .driver_data = 0 },
0156 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_GAMECUBE3),
0157 .driver_data = HID_QUIRK_MULTI_INPUT },
0158 { }
0159 };
0160 MODULE_DEVICE_TABLE(hid, mf_devices);
0161
0162 static struct hid_driver mf_driver = {
0163 .name = "hid_mf",
0164 .id_table = mf_devices,
0165 .probe = mf_probe,
0166 };
0167 module_hid_driver(mf_driver);
0168
0169 MODULE_LICENSE("GPL");