2 * HID-input usage mapping quirks
4 * This is used to handle HID-input mappings for devices violating
5 * HUT 1.12 specification.
7 * Copyright (c) 2007-2008 Jiri Kosina
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License
16 #include <linux/input.h>
17 #include <linux/hid.h>
19 #define map_rel(c) hid_map_usage(hidinput, usage, bit, max, EV_REL, (c))
20 #define map_key(c) hid_map_usage(hidinput, usage, bit, max, EV_KEY, (c))
22 #define map_key_clear(c) hid_map_usage_clear(hidinput, usage, bit, \
25 static int quirk_belkin_wkbd(struct hid_usage *usage,
26 struct hid_input *hidinput, unsigned long **bit, int *max)
28 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
31 switch (usage->hid & HID_USAGE) {
32 case 0x03a: map_key_clear(KEY_SOUND); break;
33 case 0x03b: map_key_clear(KEY_CAMERA); break;
34 case 0x03c: map_key_clear(KEY_DOCUMENTS); break;
41 static int quirk_cherry_cymotion(struct hid_usage *usage,
42 struct hid_input *hidinput, unsigned long **bit, int *max)
44 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
47 switch (usage->hid & HID_USAGE) {
48 case 0x301: map_key_clear(KEY_PROG1); break;
49 case 0x302: map_key_clear(KEY_PROG2); break;
50 case 0x303: map_key_clear(KEY_PROG3); break;
57 static int quirk_gyration_remote(struct hid_usage *usage,
58 struct hid_input *hidinput, unsigned long **bit, int *max)
60 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
63 set_bit(EV_REP, hidinput->input->evbit);
64 switch(usage->hid & HID_USAGE) {
65 /* Reported on Gyration MCE Remote */
66 case 0x00d: map_key_clear(KEY_HOME); break;
67 case 0x024: map_key_clear(KEY_DVD); break;
68 case 0x025: map_key_clear(KEY_PVR); break;
69 case 0x046: map_key_clear(KEY_MEDIA); break;
70 case 0x047: map_key_clear(KEY_MP3); break;
71 case 0x049: map_key_clear(KEY_CAMERA); break;
72 case 0x04a: map_key_clear(KEY_VIDEO); break;
80 static int quirk_chicony_tactical_pad(struct hid_usage *usage,
81 struct hid_input *hidinput, unsigned long **bit, int *max)
83 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
86 set_bit(EV_REP, hidinput->input->evbit);
87 switch (usage->hid & HID_USAGE) {
88 case 0xff01: map_key_clear(BTN_1); break;
89 case 0xff02: map_key_clear(BTN_2); break;
90 case 0xff03: map_key_clear(BTN_3); break;
91 case 0xff04: map_key_clear(BTN_4); break;
92 case 0xff05: map_key_clear(BTN_5); break;
93 case 0xff06: map_key_clear(BTN_6); break;
94 case 0xff07: map_key_clear(BTN_7); break;
95 case 0xff08: map_key_clear(BTN_8); break;
96 case 0xff09: map_key_clear(BTN_9); break;
97 case 0xff0a: map_key_clear(BTN_A); break;
98 case 0xff0b: map_key_clear(BTN_B); break;
105 static int quirk_microsoft_ergonomy_kb(struct hid_usage *usage,
106 struct hid_input *hidinput, unsigned long **bit, int *max)
108 struct input_dev *input = hidinput->input;
110 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
113 switch(usage->hid & HID_USAGE) {
114 case 0xfd06: map_key_clear(KEY_CHAT); break;
115 case 0xfd07: map_key_clear(KEY_PHONE); break;
117 set_bit(EV_REP, input->evbit);
118 map_key_clear(KEY_F13);
119 set_bit(KEY_F14, input->keybit);
120 set_bit(KEY_F15, input->keybit);
121 set_bit(KEY_F16, input->keybit);
122 set_bit(KEY_F17, input->keybit);
123 set_bit(KEY_F18, input->keybit);
130 static int quirk_microsoft_presenter_8k(struct hid_usage *usage,
131 struct hid_input *hidinput, unsigned long **bit, int *max)
133 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
136 set_bit(EV_REP, hidinput->input->evbit);
137 switch(usage->hid & HID_USAGE) {
138 case 0xfd08: map_key_clear(KEY_FORWARD); break;
139 case 0xfd09: map_key_clear(KEY_BACK); break;
140 case 0xfd0b: map_key_clear(KEY_PLAYPAUSE); break;
141 case 0xfd0e: map_key_clear(KEY_CLOSE); break;
142 case 0xfd0f: map_key_clear(KEY_PLAY); break;
149 static int quirk_petalynx_remote(struct hid_usage *usage,
150 struct hid_input *hidinput, unsigned long **bit, int *max)
152 if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
153 ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
156 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
157 switch(usage->hid & HID_USAGE) {
158 case 0x05a: map_key_clear(KEY_TEXT); break;
159 case 0x05b: map_key_clear(KEY_RED); break;
160 case 0x05c: map_key_clear(KEY_GREEN); break;
161 case 0x05d: map_key_clear(KEY_YELLOW); break;
162 case 0x05e: map_key_clear(KEY_BLUE); break;
167 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
168 switch(usage->hid & HID_USAGE) {
169 case 0x0f6: map_key_clear(KEY_NEXT); break;
170 case 0x0fa: map_key_clear(KEY_BACK); break;
177 static int quirk_cherry_genius_29e(struct hid_usage *usage,
178 struct hid_input *hidinput, unsigned long **bit, int *max)
180 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
183 switch (usage->hid & HID_USAGE) {
184 case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
185 case 0x157: map_key_clear(KEY_SPREADSHEET); break;
186 case 0x158: map_key_clear(KEY_PRESENTATION); break;
187 case 0x15c: map_key_clear(KEY_STOP); break;
195 static int quirk_btc_8193(struct hid_usage *usage, struct hid_input *hidinput,
196 unsigned long **bit, int *max)
198 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
201 switch (usage->hid & HID_USAGE) {
202 case 0x230: map_key(BTN_MOUSE); break;
203 case 0x231: map_rel(REL_WHEEL); break;
205 * this keyboard has a scrollwheel implemented in
206 * totally broken way. We map this usage temporarily
207 * to HWHEEL and handle it in the event quirk handler
209 case 0x232: map_rel(REL_HWHEEL); break;
217 static int quirk_sunplus_wdesktop(struct hid_usage *usage,
218 struct hid_input *hidinput, unsigned long **bit, int *max)
220 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
223 switch (usage->hid & HID_USAGE) {
224 case 0x2003: map_key_clear(KEY_ZOOMIN); break;
225 case 0x2103: map_key_clear(KEY_ZOOMOUT); break;
232 #define VENDOR_ID_BELKIN 0x1020
233 #define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
235 #define VENDOR_ID_CHERRY 0x046a
236 #define DEVICE_ID_CHERRY_CYMOTION 0x0023
238 #define VENDOR_ID_CHICONY 0x04f2
239 #define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
241 #define VENDOR_ID_EZKEY 0x0518
242 #define DEVICE_ID_BTC_8193 0x0002
244 #define VENDOR_ID_GYRATION 0x0c16
245 #define DEVICE_ID_GYRATION_REMOTE 0x0002
247 #define VENDOR_ID_MICROSOFT 0x045e
248 #define DEVICE_ID_MS4K 0x00db
249 #define DEVICE_ID_MS6K 0x00f9
250 #define DEVICE_IS_MS_PRESENTER_8K_BT 0x0701
251 #define DEVICE_ID_MS_PRESENTER_8K_USB 0x0713
253 #define VENDOR_ID_MONTEREY 0x0566
254 #define DEVICE_ID_GENIUS_KB29E 0x3004
256 #define VENDOR_ID_PETALYNX 0x18b1
257 #define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
259 #define VENDOR_ID_SUNPLUS 0x04fc
260 #define DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
262 static const struct hid_input_blacklist {
265 int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
267 } hid_input_blacklist[] = {
268 { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
270 { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion },
272 { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
274 { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
276 { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
278 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS4K, quirk_microsoft_ergonomy_kb },
279 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS6K, quirk_microsoft_ergonomy_kb },
280 { VENDOR_ID_MICROSOFT, DEVICE_IS_MS_PRESENTER_8K_BT, quirk_microsoft_presenter_8k },
281 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS_PRESENTER_8K_USB, quirk_microsoft_presenter_8k },
283 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
285 { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
287 { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop },
292 int hidinput_mapping_quirks(struct hid_usage *usage,
293 struct hid_input *hi, unsigned long **bit, int *max)
295 struct hid_device *device = input_get_drvdata(hi->input);
298 while (hid_input_blacklist[i].quirk) {
299 if (hid_input_blacklist[i].idVendor == device->vendor &&
300 hid_input_blacklist[i].idProduct == device->product)
301 return hid_input_blacklist[i].quirk(usage, hi, bit,
308 int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
310 struct input_dev *input;
312 input = field->hidinput->input;
314 if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
315 || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) {
316 if (value) hid->quirks |= HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
317 else hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
321 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
322 (usage->type == EV_REL) &&
323 (usage->code == REL_WHEEL)) {
324 hid->delayed_value = value;
328 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
329 (usage->hid == 0x000100b8)) {
330 input_event(input, EV_REL, value ? REL_HWHEEL : REL_WHEEL, hid->delayed_value);
334 if ((hid->quirks & HID_QUIRK_INVERT_HWHEEL) && (usage->code == REL_HWHEEL)) {
335 input_event(input, usage->type, usage->code, -value);
339 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON) && (usage->code == REL_WHEEL)) {
340 input_event(input, usage->type, REL_HWHEEL, value);
344 if ((hid->quirks & HID_QUIRK_APPLE_HAS_FN) && hidinput_apple_event(hid, input, usage, value))
347 /* Handling MS keyboards special buttons */
348 if (hid->quirks & HID_QUIRK_MICROSOFT_KEYS &&
349 usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
351 static int last_key = 0;
353 case 0x01: key = KEY_F14; break;
354 case 0x02: key = KEY_F15; break;
355 case 0x04: key = KEY_F16; break;
356 case 0x08: key = KEY_F17; break;
357 case 0x10: key = KEY_F18; break;
361 input_event(input, usage->type, key, 1);
364 input_event(input, usage->type, last_key, 0);
368 /* handle the temporary quirky mapping to HWHEEL */
369 if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
370 usage->type == EV_REL && usage->code == REL_HWHEEL) {
371 input_event(input, usage->type, REL_WHEEL, -value);
375 /* Gyration MCE remote "Sleep" key */
376 if (hid->vendor == VENDOR_ID_GYRATION &&
377 hid->product == DEVICE_ID_GYRATION_REMOTE &&
378 (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
379 (usage->hid & 0xff) == 0x82) {
380 input_event(input, usage->type, usage->code, 1);
382 input_event(input, usage->type, usage->code, 0);