2 * Force feedback support for EMS Trio Linker Plus II
4 * Copyright (c) 2010 Ignaz Forster <ignaz.forster@gmx.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/hid.h>
25 #include <linux/input.h>
26 #include <linux/module.h>
31 struct hid_report *report;
34 static int emsff_play(struct input_dev *dev, void *data,
35 struct ff_effect *effect)
37 struct hid_device *hid = input_get_drvdata(dev);
38 struct emsff_device *emsff = data;
41 weak = effect->u.rumble.weak_magnitude;
42 strong = effect->u.rumble.strong_magnitude;
44 dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
46 weak = weak * 0xff / 0xffff;
47 strong = strong * 0xff / 0xffff;
49 emsff->report->field[0]->value[1] = weak;
50 emsff->report->field[0]->value[2] = strong;
52 dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
53 hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
58 static int emsff_init(struct hid_device *hid)
60 struct emsff_device *emsff;
61 struct hid_report *report;
62 struct hid_input *hidinput;
63 struct list_head *report_list =
64 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
65 struct input_dev *dev;
68 if (list_empty(&hid->inputs)) {
69 hid_err(hid, "no inputs found\n");
72 hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
73 dev = hidinput->input;
75 if (list_empty(report_list)) {
76 hid_err(hid, "no output reports found\n");
80 report = list_first_entry(report_list, struct hid_report, list);
81 if (report->maxfield < 1) {
82 hid_err(hid, "no fields in the report\n");
86 if (report->field[0]->report_count < 7) {
87 hid_err(hid, "not enough values in the field\n");
91 emsff = kzalloc(sizeof(struct emsff_device), GFP_KERNEL);
95 set_bit(FF_RUMBLE, dev->ffbit);
97 error = input_ff_create_memless(dev, emsff, emsff_play);
103 emsff->report = report;
104 emsff->report->field[0]->value[0] = 0x01;
105 emsff->report->field[0]->value[1] = 0x00;
106 emsff->report->field[0]->value[2] = 0x00;
107 emsff->report->field[0]->value[3] = 0x00;
108 emsff->report->field[0]->value[4] = 0x00;
109 emsff->report->field[0]->value[5] = 0x00;
110 emsff->report->field[0]->value[6] = 0x00;
111 hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
113 hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
118 static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
122 ret = hid_parse(hdev);
124 hid_err(hdev, "parse failed\n");
128 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
130 hid_err(hdev, "hw start failed\n");
134 ret = emsff_init(hdev);
136 dev_err(&hdev->dev, "force feedback init failed\n");
146 static const struct hid_device_id ems_devices[] = {
147 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
150 MODULE_DEVICE_TABLE(hid, ems_devices);
152 static struct hid_driver ems_driver = {
154 .id_table = ems_devices,
157 module_hid_driver(ems_driver);
159 MODULE_LICENSE("GPL");