]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/hid/hid-input-quirks.c
HID: move usage input mapping to hid.h
[linux-2.6-omap-h63xx.git] / drivers / hid / hid-input-quirks.c
1 /*
2  *  HID-input usage mapping quirks
3  *
4  *  This is used to handle HID-input mappings for devices violating
5  *  HUT 1.12 specification.
6  *
7  * Copyright (c) 2007-2008 Jiri Kosina
8  */
9
10 /*
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
14  */
15
16 #include <linux/input.h>
17 #include <linux/hid.h>
18
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))
21
22 #define map_key_clear(c)        hid_map_usage_clear(hidinput, usage, bit, \
23                 max, EV_KEY, (c))
24
25 static int quirk_belkin_wkbd(struct hid_usage *usage,
26                 struct hid_input *hidinput, unsigned long **bit, int *max)
27 {
28         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
29                 return 0;
30
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;
35                 default:
36                         return 0;
37         }
38         return 1;
39 }
40
41 static int quirk_cherry_cymotion(struct hid_usage *usage,
42                 struct hid_input *hidinput, unsigned long **bit, int *max)
43 {
44         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
45                 return 0;
46
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;
51                 default:
52                         return 0;
53         }
54         return 1;
55 }
56
57 static int quirk_logitech_ultrax_remote(struct hid_usage *usage,
58                 struct hid_input *hidinput, unsigned long **bit, int *max)
59 {
60         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
61                 return 0;
62
63         set_bit(EV_REP, hidinput->input->evbit);
64         switch(usage->hid & HID_USAGE) {
65                 /* Reported on Logitech Ultra X Media Remote */
66                 case 0x004: map_key_clear(KEY_AGAIN);           break;
67                 case 0x00d: map_key_clear(KEY_HOME);            break;
68                 case 0x024: map_key_clear(KEY_SHUFFLE);         break;
69                 case 0x025: map_key_clear(KEY_TV);              break;
70                 case 0x026: map_key_clear(KEY_MENU);            break;
71                 case 0x031: map_key_clear(KEY_AUDIO);           break;
72                 case 0x032: map_key_clear(KEY_TEXT);            break;
73                 case 0x033: map_key_clear(KEY_LAST);            break;
74                 case 0x047: map_key_clear(KEY_MP3);             break;
75                 case 0x048: map_key_clear(KEY_DVD);             break;
76                 case 0x049: map_key_clear(KEY_MEDIA);           break;
77                 case 0x04a: map_key_clear(KEY_VIDEO);           break;
78                 case 0x04b: map_key_clear(KEY_ANGLE);           break;
79                 case 0x04c: map_key_clear(KEY_LANGUAGE);        break;
80                 case 0x04d: map_key_clear(KEY_SUBTITLE);        break;
81                 case 0x051: map_key_clear(KEY_RED);             break;
82                 case 0x052: map_key_clear(KEY_CLOSE);           break;
83
84                 default:
85                         return 0;
86         }
87         return 1;
88 }
89
90 static int quirk_gyration_remote(struct hid_usage *usage,
91                 struct hid_input *hidinput, unsigned long **bit, int *max)
92 {
93         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
94                 return 0;
95
96         set_bit(EV_REP, hidinput->input->evbit);
97         switch(usage->hid & HID_USAGE) {
98                 /* Reported on Gyration MCE Remote */
99                 case 0x00d: map_key_clear(KEY_HOME);            break;
100                 case 0x024: map_key_clear(KEY_DVD);             break;
101                 case 0x025: map_key_clear(KEY_PVR);             break;
102                 case 0x046: map_key_clear(KEY_MEDIA);           break;
103                 case 0x047: map_key_clear(KEY_MP3);             break;
104                 case 0x049: map_key_clear(KEY_CAMERA);          break;
105                 case 0x04a: map_key_clear(KEY_VIDEO);           break;
106
107                 default:
108                         return 0;
109         }
110         return 1;
111 }
112
113 static int quirk_chicony_tactical_pad(struct hid_usage *usage,
114                 struct hid_input *hidinput, unsigned long **bit, int *max)
115 {
116         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
117                 return 0;
118
119         set_bit(EV_REP, hidinput->input->evbit);
120         switch (usage->hid & HID_USAGE) {
121                 case 0xff01: map_key_clear(BTN_1);              break;
122                 case 0xff02: map_key_clear(BTN_2);              break;
123                 case 0xff03: map_key_clear(BTN_3);              break;
124                 case 0xff04: map_key_clear(BTN_4);              break;
125                 case 0xff05: map_key_clear(BTN_5);              break;
126                 case 0xff06: map_key_clear(BTN_6);              break;
127                 case 0xff07: map_key_clear(BTN_7);              break;
128                 case 0xff08: map_key_clear(BTN_8);              break;
129                 case 0xff09: map_key_clear(BTN_9);              break;
130                 case 0xff0a: map_key_clear(BTN_A);              break;
131                 case 0xff0b: map_key_clear(BTN_B);              break;
132                 default:
133                         return 0;
134         }
135         return 1;
136 }
137
138 static int quirk_microsoft_ergonomy_kb(struct hid_usage *usage,
139                 struct hid_input *hidinput, unsigned long **bit, int *max)
140 {
141         struct input_dev *input = hidinput->input;
142
143         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
144                 return 0;
145
146         switch(usage->hid & HID_USAGE) {
147                 case 0xfd06: map_key_clear(KEY_CHAT);           break;
148                 case 0xfd07: map_key_clear(KEY_PHONE);          break;
149                 case 0xff05:
150                         set_bit(EV_REP, input->evbit);
151                         map_key_clear(KEY_F13);
152                         set_bit(KEY_F14, input->keybit);
153                         set_bit(KEY_F15, input->keybit);
154                         set_bit(KEY_F16, input->keybit);
155                         set_bit(KEY_F17, input->keybit);
156                         set_bit(KEY_F18, input->keybit);
157                 default:
158                         return 0;
159         }
160         return 1;
161 }
162
163 static int quirk_microsoft_presenter_8k(struct hid_usage *usage,
164                 struct hid_input *hidinput, unsigned long **bit, int *max)
165 {
166         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
167                 return 0;
168
169         set_bit(EV_REP, hidinput->input->evbit);
170         switch(usage->hid & HID_USAGE) {
171                 case 0xfd08: map_key_clear(KEY_FORWARD);        break;
172                 case 0xfd09: map_key_clear(KEY_BACK);           break;
173                 case 0xfd0b: map_key_clear(KEY_PLAYPAUSE);      break;
174                 case 0xfd0e: map_key_clear(KEY_CLOSE);          break;
175                 case 0xfd0f: map_key_clear(KEY_PLAY);           break;
176                 default:
177                         return 0;
178         }
179         return 1;
180 }
181
182 static int quirk_petalynx_remote(struct hid_usage *usage,
183                 struct hid_input *hidinput, unsigned long **bit, int *max)
184 {
185         if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
186                         ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
187                 return 0;
188
189         if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
190                 switch(usage->hid & HID_USAGE) {
191                         case 0x05a: map_key_clear(KEY_TEXT);            break;
192                         case 0x05b: map_key_clear(KEY_RED);             break;
193                         case 0x05c: map_key_clear(KEY_GREEN);           break;
194                         case 0x05d: map_key_clear(KEY_YELLOW);          break;
195                         case 0x05e: map_key_clear(KEY_BLUE);            break;
196                         default:
197                                 return 0;
198                 }
199
200         if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
201                 switch(usage->hid & HID_USAGE) {
202                         case 0x0f6: map_key_clear(KEY_NEXT);            break;
203                         case 0x0fa: map_key_clear(KEY_BACK);            break;
204                         default:
205                                 return 0;
206                 }
207         return 1;
208 }
209
210 static int quirk_logitech_wireless(struct hid_usage *usage,
211                 struct hid_input *hidinput, unsigned long **bit, int *max)
212 {
213         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
214                 return 0;
215
216         switch (usage->hid & HID_USAGE) {
217                 case 0x1001: map_key_clear(KEY_MESSENGER);      break;
218                 case 0x1003: map_key_clear(KEY_SOUND);          break;
219                 case 0x1004: map_key_clear(KEY_VIDEO);          break;
220                 case 0x1005: map_key_clear(KEY_AUDIO);          break;
221                 case 0x100a: map_key_clear(KEY_DOCUMENTS);      break;
222                 case 0x1011: map_key_clear(KEY_PREVIOUSSONG);   break;
223                 case 0x1012: map_key_clear(KEY_NEXTSONG);       break;
224                 case 0x1013: map_key_clear(KEY_CAMERA);         break;
225                 case 0x1014: map_key_clear(KEY_MESSENGER);      break;
226                 case 0x1015: map_key_clear(KEY_RECORD);         break;
227                 case 0x1016: map_key_clear(KEY_PLAYER);         break;
228                 case 0x1017: map_key_clear(KEY_EJECTCD);        break;
229                 case 0x1018: map_key_clear(KEY_MEDIA);          break;
230                 case 0x1019: map_key_clear(KEY_PROG1);          break;
231                 case 0x101a: map_key_clear(KEY_PROG2);          break;
232                 case 0x101b: map_key_clear(KEY_PROG3);          break;
233                 case 0x101f: map_key_clear(KEY_ZOOMIN);         break;
234                 case 0x1020: map_key_clear(KEY_ZOOMOUT);        break;
235                 case 0x1021: map_key_clear(KEY_ZOOMRESET);      break;
236                 case 0x1023: map_key_clear(KEY_CLOSE);          break;
237                 case 0x1027: map_key_clear(KEY_MENU);           break;
238                 /* this one is marked as 'Rotate' */
239                 case 0x1028: map_key_clear(KEY_ANGLE);          break;
240                 case 0x1029: map_key_clear(KEY_SHUFFLE);        break;
241                 case 0x102a: map_key_clear(KEY_BACK);           break;
242                 case 0x102b: map_key_clear(KEY_CYCLEWINDOWS);   break;
243                 case 0x1041: map_key_clear(KEY_BATTERY);        break;
244                 case 0x1042: map_key_clear(KEY_WORDPROCESSOR);  break;
245                 case 0x1043: map_key_clear(KEY_SPREADSHEET);    break;
246                 case 0x1044: map_key_clear(KEY_PRESENTATION);   break;
247                 case 0x1045: map_key_clear(KEY_UNDO);           break;
248                 case 0x1046: map_key_clear(KEY_REDO);           break;
249                 case 0x1047: map_key_clear(KEY_PRINT);          break;
250                 case 0x1048: map_key_clear(KEY_SAVE);           break;
251                 case 0x1049: map_key_clear(KEY_PROG1);          break;
252                 case 0x104a: map_key_clear(KEY_PROG2);          break;
253                 case 0x104b: map_key_clear(KEY_PROG3);          break;
254                 case 0x104c: map_key_clear(KEY_PROG4);          break;
255
256                 default:
257                         return 0;
258         }
259         return 1;
260 }
261
262 static int quirk_cherry_genius_29e(struct hid_usage *usage,
263                 struct hid_input *hidinput, unsigned long **bit, int *max)
264 {
265         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
266                 return 0;
267
268         switch (usage->hid & HID_USAGE) {
269                 case 0x156: map_key_clear(KEY_WORDPROCESSOR);   break;
270                 case 0x157: map_key_clear(KEY_SPREADSHEET);     break;
271                 case 0x158: map_key_clear(KEY_PRESENTATION);    break;
272                 case 0x15c: map_key_clear(KEY_STOP);            break;
273
274                 default:
275                         return 0;
276         }
277         return 1;
278 }
279
280 static int quirk_btc_8193(struct hid_usage *usage, struct hid_input *hidinput,
281                               unsigned long **bit, int *max)
282 {
283         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
284                 return 0;
285
286         switch (usage->hid & HID_USAGE) {
287                 case 0x230: map_key(BTN_MOUSE);                 break;
288                 case 0x231: map_rel(REL_WHEEL);                 break;
289                 /* 
290                  * this keyboard has a scrollwheel implemented in
291                  * totally broken way. We map this usage temporarily
292                  * to HWHEEL and handle it in the event quirk handler
293                  */
294                 case 0x232: map_rel(REL_HWHEEL);                break;
295
296                 default:
297                         return 0;
298         }
299         return 1;
300 }
301
302 static int quirk_sunplus_wdesktop(struct hid_usage *usage,
303                 struct hid_input *hidinput, unsigned long **bit, int *max)
304 {
305         if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
306                 return 0;
307
308         switch (usage->hid & HID_USAGE) {
309                 case 0x2003: map_key_clear(KEY_ZOOMIN);         break;
310                 case 0x2103: map_key_clear(KEY_ZOOMOUT);        break;
311                 default:
312                         return 0;
313         }
314         return 1;
315 }
316
317 #define VENDOR_ID_BELKIN                        0x1020
318 #define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD      0x0006
319
320 #define VENDOR_ID_CHERRY                        0x046a
321 #define DEVICE_ID_CHERRY_CYMOTION               0x0023
322
323 #define VENDOR_ID_CHICONY                       0x04f2
324 #define DEVICE_ID_CHICONY_TACTICAL_PAD          0x0418
325
326 #define VENDOR_ID_EZKEY                         0x0518
327 #define DEVICE_ID_BTC_8193                      0x0002
328
329 #define VENDOR_ID_GYRATION                      0x0c16
330 #define DEVICE_ID_GYRATION_REMOTE               0x0002
331
332 #define VENDOR_ID_LOGITECH                      0x046d
333 #define DEVICE_ID_LOGITECH_RECEIVER             0xc101
334 #define DEVICE_ID_S510_RECEIVER                 0xc50c
335 #define DEVICE_ID_S510_RECEIVER_2               0xc517
336 #define DEVICE_ID_MX3000_RECEIVER               0xc513
337
338 #define VENDOR_ID_MICROSOFT                     0x045e
339 #define DEVICE_ID_MS4K                          0x00db
340 #define DEVICE_ID_MS6K                          0x00f9
341 #define DEVICE_IS_MS_PRESENTER_8K_BT            0x0701
342 #define DEVICE_ID_MS_PRESENTER_8K_USB           0x0713
343
344 #define VENDOR_ID_MONTEREY                      0x0566
345 #define DEVICE_ID_GENIUS_KB29E                  0x3004
346
347 #define VENDOR_ID_PETALYNX                      0x18b1
348 #define DEVICE_ID_PETALYNX_MAXTER_REMOTE        0x0037
349
350 #define VENDOR_ID_SUNPLUS                       0x04fc
351 #define DEVICE_ID_SUNPLUS_WDESKTOP              0x05d8
352
353 static const struct hid_input_blacklist {
354         __u16 idVendor;
355         __u16 idProduct;
356         int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
357                         int *);
358 } hid_input_blacklist[] = {
359         { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
360
361         { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion },
362
363         { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
364
365         { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
366
367         { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
368
369         { VENDOR_ID_LOGITECH, DEVICE_ID_LOGITECH_RECEIVER, quirk_logitech_ultrax_remote },
370         { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER, quirk_logitech_wireless },
371         { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER_2, quirk_logitech_wireless },
372         { VENDOR_ID_LOGITECH, DEVICE_ID_MX3000_RECEIVER, quirk_logitech_wireless },
373
374         { VENDOR_ID_MICROSOFT, DEVICE_ID_MS4K, quirk_microsoft_ergonomy_kb },
375         { VENDOR_ID_MICROSOFT, DEVICE_ID_MS6K, quirk_microsoft_ergonomy_kb },
376         { VENDOR_ID_MICROSOFT, DEVICE_IS_MS_PRESENTER_8K_BT, quirk_microsoft_presenter_8k },
377         { VENDOR_ID_MICROSOFT, DEVICE_ID_MS_PRESENTER_8K_USB, quirk_microsoft_presenter_8k },
378
379         { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
380
381         { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
382
383         { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop },
384
385         { 0, 0, NULL }
386 };
387
388 int hidinput_mapping_quirks(struct hid_usage *usage, 
389                 struct hid_input *hi, unsigned long **bit, int *max)
390 {
391         struct hid_device *device = input_get_drvdata(hi->input);
392         int i = 0;
393         
394         while (hid_input_blacklist[i].quirk) {
395                 if (hid_input_blacklist[i].idVendor == device->vendor &&
396                                 hid_input_blacklist[i].idProduct == device->product)
397                         return hid_input_blacklist[i].quirk(usage, hi, bit,
398                                         max);
399                 i++;
400         }
401         return 0;
402 }
403
404 int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
405 {
406         struct input_dev *input;
407
408         input = field->hidinput->input;
409
410         if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
411                 || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) {
412                 if (value) hid->quirks |=  HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
413                 else       hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
414                 return 1;
415         }
416
417         if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
418                         (usage->type == EV_REL) &&
419                         (usage->code == REL_WHEEL)) {
420                 hid->delayed_value = value;
421                 return 1;
422         }
423
424         if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
425                         (usage->hid == 0x000100b8)) {
426                 input_event(input, EV_REL, value ? REL_HWHEEL : REL_WHEEL, hid->delayed_value);
427                 return 1;
428         }
429
430         if ((hid->quirks & HID_QUIRK_INVERT_HWHEEL) && (usage->code == REL_HWHEEL)) {
431                 input_event(input, usage->type, usage->code, -value);
432                 return 1;
433         }
434
435         if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON) && (usage->code == REL_WHEEL)) {
436                 input_event(input, usage->type, REL_HWHEEL, value);
437                 return 1;
438         }
439
440         if ((hid->quirks & HID_QUIRK_APPLE_HAS_FN) && hidinput_apple_event(hid, input, usage, value))
441                 return 1;
442
443         /* Handling MS keyboards special buttons */
444         if (hid->quirks & HID_QUIRK_MICROSOFT_KEYS && 
445                         usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
446                 int key = 0;
447                 static int last_key = 0;
448                 switch (value) {
449                         case 0x01: key = KEY_F14; break;
450                         case 0x02: key = KEY_F15; break;
451                         case 0x04: key = KEY_F16; break;
452                         case 0x08: key = KEY_F17; break;
453                         case 0x10: key = KEY_F18; break;
454                         default: break;
455                 }
456                 if (key) {
457                         input_event(input, usage->type, key, 1);
458                         last_key = key;
459                 } else {
460                         input_event(input, usage->type, last_key, 0);
461                 }
462         }
463
464         /* handle the temporary quirky mapping to HWHEEL */
465         if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
466                         usage->type == EV_REL && usage->code == REL_HWHEEL) {
467                 input_event(input, usage->type, REL_WHEEL, -value);
468                 return 1;
469         }
470
471         /* Gyration MCE remote "Sleep" key */
472         if (hid->vendor == VENDOR_ID_GYRATION &&
473             hid->product == DEVICE_ID_GYRATION_REMOTE &&
474             (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
475             (usage->hid & 0xff) == 0x82) {
476                 input_event(input, usage->type, usage->code, 1);
477                 input_sync(input);
478                 input_event(input, usage->type, usage->code, 0);
479                 input_sync(input);
480                 return 1;
481         }
482         return 0;
483 }
484
485