blob: d82d75bb11f78b591483233bc294aaf3a5939a72 [file] [log] [blame]
Ignaz Forster04561c52010-11-01 15:13:37 -04001/*
2 * Force feedback support for EMS Trio Linker Plus II
3 *
4 * Copyright (c) 2010 Ignaz Forster <ignaz.forster@gmx.de>
5 */
6
7/*
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.
12 *
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.
17 *
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
21 */
22
23
24#include <linux/hid.h>
25#include <linux/input.h>
Paul Gortmaker8f86a2c2011-07-03 13:39:48 -040026#include <linux/module.h>
Ignaz Forster04561c52010-11-01 15:13:37 -040027
28#include "hid-ids.h"
Ignaz Forster04561c52010-11-01 15:13:37 -040029
30struct emsff_device {
31 struct hid_report *report;
32};
33
34static int emsff_play(struct input_dev *dev, void *data,
35 struct ff_effect *effect)
36{
37 struct hid_device *hid = input_get_drvdata(dev);
38 struct emsff_device *emsff = data;
39 int weak, strong;
40
41 weak = effect->u.rumble.weak_magnitude;
42 strong = effect->u.rumble.strong_magnitude;
43
44 dbg_hid("called with 0x%04x 0x%04x\n", strong, weak);
45
46 weak = weak * 0xff / 0xffff;
47 strong = strong * 0xff / 0xffff;
48
49 emsff->report->field[0]->value[1] = weak;
50 emsff->report->field[0]->value[2] = strong;
51
52 dbg_hid("running with 0x%02x 0x%02x\n", strong, weak);
Benjamin Tissoiresd88142722013-02-25 11:31:46 +010053 hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
Ignaz Forster04561c52010-11-01 15:13:37 -040054
55 return 0;
56}
57
58static int emsff_init(struct hid_device *hid)
59{
60 struct emsff_device *emsff;
61 struct hid_report *report;
62 struct hid_input *hidinput = list_first_entry(&hid->inputs,
63 struct hid_input, list);
64 struct list_head *report_list =
65 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
66 struct input_dev *dev = hidinput->input;
67 int error;
68
69 if (list_empty(report_list)) {
Joe Perches4291ee32010-12-09 19:29:03 -080070 hid_err(hid, "no output reports found\n");
Ignaz Forster04561c52010-11-01 15:13:37 -040071 return -ENODEV;
72 }
73
74 report = list_first_entry(report_list, struct hid_report, list);
75 if (report->maxfield < 1) {
Joe Perches4291ee32010-12-09 19:29:03 -080076 hid_err(hid, "no fields in the report\n");
Ignaz Forster04561c52010-11-01 15:13:37 -040077 return -ENODEV;
78 }
79
80 if (report->field[0]->report_count < 7) {
Joe Perches4291ee32010-12-09 19:29:03 -080081 hid_err(hid, "not enough values in the field\n");
Ignaz Forster04561c52010-11-01 15:13:37 -040082 return -ENODEV;
83 }
84
85 emsff = kzalloc(sizeof(struct emsff_device), GFP_KERNEL);
86 if (!emsff)
87 return -ENOMEM;
88
89 set_bit(FF_RUMBLE, dev->ffbit);
90
91 error = input_ff_create_memless(dev, emsff, emsff_play);
92 if (error) {
93 kfree(emsff);
94 return error;
95 }
96
97 emsff->report = report;
98 emsff->report->field[0]->value[0] = 0x01;
99 emsff->report->field[0]->value[1] = 0x00;
100 emsff->report->field[0]->value[2] = 0x00;
101 emsff->report->field[0]->value[3] = 0x00;
102 emsff->report->field[0]->value[4] = 0x00;
103 emsff->report->field[0]->value[5] = 0x00;
104 emsff->report->field[0]->value[6] = 0x00;
Benjamin Tissoiresd88142722013-02-25 11:31:46 +0100105 hid_hw_request(hid, emsff->report, HID_REQ_SET_REPORT);
Ignaz Forster04561c52010-11-01 15:13:37 -0400106
Joe Perches4291ee32010-12-09 19:29:03 -0800107 hid_info(hid, "force feedback for EMS based devices by Ignaz Forster <ignaz.forster@gmx.de>\n");
Ignaz Forster04561c52010-11-01 15:13:37 -0400108
109 return 0;
110}
111
112static int ems_probe(struct hid_device *hdev, const struct hid_device_id *id)
113{
114 int ret;
115
116 ret = hid_parse(hdev);
117 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800118 hid_err(hdev, "parse failed\n");
Ignaz Forster04561c52010-11-01 15:13:37 -0400119 goto err;
120 }
121
122 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
123 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800124 hid_err(hdev, "hw start failed\n");
Ignaz Forster04561c52010-11-01 15:13:37 -0400125 goto err;
126 }
127
Axel Lin2dcd9542011-07-19 16:14:04 +0800128 ret = emsff_init(hdev);
129 if (ret) {
130 dev_err(&hdev->dev, "force feedback init failed\n");
131 hid_hw_stop(hdev);
132 goto err;
133 }
Ignaz Forster04561c52010-11-01 15:13:37 -0400134
135 return 0;
136err:
137 return ret;
138}
139
140static const struct hid_device_id ems_devices[] = {
Jiri Kosina05ee2832011-12-21 00:29:19 +0100141 { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
Ignaz Forster04561c52010-11-01 15:13:37 -0400142 { }
143};
144MODULE_DEVICE_TABLE(hid, ems_devices);
145
146static struct hid_driver ems_driver = {
147 .name = "hkems",
148 .id_table = ems_devices,
149 .probe = ems_probe,
150};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700151module_hid_driver(ems_driver);
Ignaz Forster04561c52010-11-01 15:13:37 -0400152
Ignaz Forster04561c52010-11-01 15:13:37 -0400153MODULE_LICENSE("GPL");
154