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>
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>
30 #include <linux/usb.h>
34 #ifdef CONFIG_HOLTEK_FF
35 #include "usbhid/usbhid.h"
37 MODULE_LICENSE("GPL");
38 MODULE_AUTHOR("Anssi Hannula <anssi.hannula@iki.fi>");
39 MODULE_DESCRIPTION("Force feedback support for Holtek On Line Grip based devices");
42 * These commands and parameters are currently known:
45 * 01 set effect parameters
46 * 02 play specified effect
47 * 03 stop specified effect
50 * (the difference between 04 and 06 isn't known; win driver
51 * sends 06,04 on application init, and 06 otherwise)
53 * Commands 01 and 02 need to be sent as pairs, i.e. you need to send 01
56 * The rest of the bytes are parameters. Command 01 takes all of them, and
57 * commands 02,03 take only the effect id.
60 * bits 0-3: effect id:
61 * 1: very strong rumble
62 * 2: periodic rumble, short intervals
63 * 3: very strong rumble
64 * 4: periodic rumble, long intervals
65 * 5: weak periodic rumble, long intervals
66 * 6: weak periodic rumble, short intervals
67 * 7: periodic rumble, short intervals
68 * 8: strong periodic rumble, short intervals
69 * 9: very strong rumble
71 * b: very strong periodic rumble, very short intervals
73 * bit 6: right (weak) motor enabled
74 * bit 7: left (strong) motor enabled
76 * bytes 2-3: time in milliseconds, big-endian
77 * bytes 5-6: unknown (win driver seems to use at least 10e0 with effect 1
78 * and 0014 with effect 6)
80 * bits 0-3: effect magnitude
83 #define HOLTEKFF_MSG_LENGTH 7
85 static const u8 start_effect_1
[] = { 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
86 static const u8 stop_all4
[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
87 static const u8 stop_all6
[] = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
89 struct holtekff_device
{
90 struct hid_field
*field
;
93 static void holtekff_send(struct holtekff_device
*holtekff
,
94 struct hid_device
*hid
,
95 const u8 data
[HOLTEKFF_MSG_LENGTH
])
99 for (i
= 0; i
< HOLTEKFF_MSG_LENGTH
; i
++) {
100 holtekff
->field
->value
[i
] = data
[i
];
103 dbg_hid("sending %*ph\n", 7, data
);
105 usbhid_submit_report(hid
, holtekff
->field
->report
, USB_DIR_OUT
);
108 static int holtekff_play(struct input_dev
*dev
, void *data
,
109 struct ff_effect
*effect
)
111 struct hid_device
*hid
= input_get_drvdata(dev
);
112 struct holtekff_device
*holtekff
= data
;
114 /* effect type 1, length 65535 msec */
115 u8 buf
[HOLTEKFF_MSG_LENGTH
] =
116 { 0x01, 0x01, 0xff, 0xff, 0x10, 0xe0, 0x00 };
118 left
= effect
->u
.rumble
.strong_magnitude
;
119 right
= effect
->u
.rumble
.weak_magnitude
;
120 dbg_hid("called with 0x%04x 0x%04x\n", left
, right
);
122 if (!left
&& !right
) {
123 holtekff_send(holtekff
, hid
, stop_all6
);
132 /* The device takes a single magnitude, so we just sum them up. */
133 buf
[6] = min(0xf, (left
>> 12) + (right
>> 12));
135 holtekff_send(holtekff
, hid
, buf
);
136 holtekff_send(holtekff
, hid
, start_effect_1
);
141 static int holtekff_init(struct hid_device
*hid
)
143 struct holtekff_device
*holtekff
;
144 struct hid_report
*report
;
145 struct hid_input
*hidinput
= list_entry(hid
->inputs
.next
,
146 struct hid_input
, list
);
147 struct list_head
*report_list
=
148 &hid
->report_enum
[HID_OUTPUT_REPORT
].report_list
;
149 struct input_dev
*dev
= hidinput
->input
;
152 if (list_empty(report_list
)) {
153 hid_err(hid
, "no output report found\n");
157 report
= list_entry(report_list
->next
, struct hid_report
, list
);
159 if (report
->maxfield
< 1 || report
->field
[0]->report_count
!= 7) {
160 hid_err(hid
, "unexpected output report layout\n");
164 holtekff
= kzalloc(sizeof(*holtekff
), GFP_KERNEL
);
168 set_bit(FF_RUMBLE
, dev
->ffbit
);
170 holtekff
->field
= report
->field
[0];
172 /* initialize the same way as win driver does */
173 holtekff_send(holtekff
, hid
, stop_all4
);
174 holtekff_send(holtekff
, hid
, stop_all6
);
176 error
= input_ff_create_memless(dev
, holtekff
, holtekff_play
);
182 hid_info(hid
, "Force feedback for Holtek On Line Grip based devices by Anssi Hannula <anssi.hannula@iki.fi>\n");
187 static inline int holtekff_init(struct hid_device
*hid
)
193 static int holtek_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
197 ret
= hid_parse(hdev
);
199 hid_err(hdev
, "parse failed\n");
203 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
& ~HID_CONNECT_FF
);
205 hid_err(hdev
, "hw start failed\n");
216 static const struct hid_device_id holtek_devices
[] = {
217 { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK
, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP
) },
220 MODULE_DEVICE_TABLE(hid
, holtek_devices
);
222 static struct hid_driver holtek_driver
= {
224 .id_table
= holtek_devices
,
225 .probe
= holtek_probe
,
227 module_hid_driver(holtek_driver
);