Revert "ALSA: hda: Flush interrupts on disabling"
[linux/fpc-iii.git] / drivers / hid / hid-holtekff.c
blob3e84551cca9c5f1ab4991a5757b24e242a107411
1 /*
2 * Force feedback support for Holtek On Line Grip based gamepads
4 * These include at least a Brazilian "Clone Joypad Super Power Fire"
5 * which uses vendor ID 0x1241 and identifies as "HOLTEK On Line Grip".
7 * Copyright (c) 2011 Anssi Hannula <anssi.hannula@iki.fi>
8 */
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/hid.h>
27 #include <linux/input.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
31 #include "hid-ids.h"
33 #ifdef CONFIG_HOLTEK_FF
35 MODULE_LICENSE("GPL");
36 MODULE_AUTHOR("Anssi Hannula <anssi.hannula@iki.fi>");
37 MODULE_DESCRIPTION("Force feedback support for Holtek On Line Grip based devices");
40 * These commands and parameters are currently known:
42 * byte 0: command id:
43 * 01 set effect parameters
44 * 02 play specified effect
45 * 03 stop specified effect
46 * 04 stop all effects
47 * 06 stop all effects
48 * (the difference between 04 and 06 isn't known; win driver
49 * sends 06,04 on application init, and 06 otherwise)
51 * Commands 01 and 02 need to be sent as pairs, i.e. you need to send 01
52 * before each 02.
54 * The rest of the bytes are parameters. Command 01 takes all of them, and
55 * commands 02,03 take only the effect id.
57 * byte 1:
58 * bits 0-3: effect id:
59 * 1: very strong rumble
60 * 2: periodic rumble, short intervals
61 * 3: very strong rumble
62 * 4: periodic rumble, long intervals
63 * 5: weak periodic rumble, long intervals
64 * 6: weak periodic rumble, short intervals
65 * 7: periodic rumble, short intervals
66 * 8: strong periodic rumble, short intervals
67 * 9: very strong rumble
68 * a: causes an error
69 * b: very strong periodic rumble, very short intervals
70 * c-f: nothing
71 * bit 6: right (weak) motor enabled
72 * bit 7: left (strong) motor enabled
74 * bytes 2-3: time in milliseconds, big-endian
75 * bytes 5-6: unknown (win driver seems to use at least 10e0 with effect 1
76 * and 0014 with effect 6)
77 * byte 7:
78 * bits 0-3: effect magnitude
81 #define HOLTEKFF_MSG_LENGTH 7
83 static const u8 start_effect_1[] = { 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
84 static const u8 stop_all4[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
85 static const u8 stop_all6[] = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
87 struct holtekff_device {
88 struct hid_field *field;
91 static void holtekff_send(struct holtekff_device *holtekff,
92 struct hid_device *hid,
93 const u8 data[HOLTEKFF_MSG_LENGTH])
95 int i;
97 for (i = 0; i < HOLTEKFF_MSG_LENGTH; i++) {
98 holtekff->field->value[i] = data[i];
101 dbg_hid("sending %7ph\n", data);
103 hid_hw_request(hid, holtekff->field->report, HID_REQ_SET_REPORT);
106 static int holtekff_play(struct input_dev *dev, void *data,
107 struct ff_effect *effect)
109 struct hid_device *hid = input_get_drvdata(dev);
110 struct holtekff_device *holtekff = data;
111 int left, right;
112 /* effect type 1, length 65535 msec */
113 u8 buf[HOLTEKFF_MSG_LENGTH] =
114 { 0x01, 0x01, 0xff, 0xff, 0x10, 0xe0, 0x00 };
116 left = effect->u.rumble.strong_magnitude;
117 right = effect->u.rumble.weak_magnitude;
118 dbg_hid("called with 0x%04x 0x%04x\n", left, right);
120 if (!left && !right) {
121 holtekff_send(holtekff, hid, stop_all6);
122 return 0;
125 if (left)
126 buf[1] |= 0x80;
127 if (right)
128 buf[1] |= 0x40;
130 /* The device takes a single magnitude, so we just sum them up. */
131 buf[6] = min(0xf, (left >> 12) + (right >> 12));
133 holtekff_send(holtekff, hid, buf);
134 holtekff_send(holtekff, hid, start_effect_1);
136 return 0;
139 static int holtekff_init(struct hid_device *hid)
141 struct holtekff_device *holtekff;
142 struct hid_report *report;
143 struct hid_input *hidinput;
144 struct list_head *report_list =
145 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
146 struct input_dev *dev;
147 int error;
149 if (list_empty(&hid->inputs)) {
150 hid_err(hid, "no inputs found\n");
151 return -ENODEV;
153 hidinput = list_entry(hid->inputs.next, struct hid_input, list);
154 dev = hidinput->input;
156 if (list_empty(report_list)) {
157 hid_err(hid, "no output report found\n");
158 return -ENODEV;
161 report = list_entry(report_list->next, struct hid_report, list);
163 if (report->maxfield < 1 || report->field[0]->report_count != 7) {
164 hid_err(hid, "unexpected output report layout\n");
165 return -ENODEV;
168 holtekff = kzalloc(sizeof(*holtekff), GFP_KERNEL);
169 if (!holtekff)
170 return -ENOMEM;
172 set_bit(FF_RUMBLE, dev->ffbit);
174 holtekff->field = report->field[0];
176 /* initialize the same way as win driver does */
177 holtekff_send(holtekff, hid, stop_all4);
178 holtekff_send(holtekff, hid, stop_all6);
180 error = input_ff_create_memless(dev, holtekff, holtekff_play);
181 if (error) {
182 kfree(holtekff);
183 return error;
186 hid_info(hid, "Force feedback for Holtek On Line Grip based devices by Anssi Hannula <anssi.hannula@iki.fi>\n");
188 return 0;
190 #else
191 static inline int holtekff_init(struct hid_device *hid)
193 return 0;
195 #endif
197 static int holtek_probe(struct hid_device *hdev, const struct hid_device_id *id)
199 int ret;
201 ret = hid_parse(hdev);
202 if (ret) {
203 hid_err(hdev, "parse failed\n");
204 goto err;
207 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
208 if (ret) {
209 hid_err(hdev, "hw start failed\n");
210 goto err;
213 holtekff_init(hdev);
215 return 0;
216 err:
217 return ret;
220 static const struct hid_device_id holtek_devices[] = {
221 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
224 MODULE_DEVICE_TABLE(hid, holtek_devices);
226 static struct hid_driver holtek_driver = {
227 .name = "holtek",
228 .id_table = holtek_devices,
229 .probe = holtek_probe,
231 module_hid_driver(holtek_driver);