blob: 97ee75064a0e70d246c7064a50f7c6ccb79f3924 [file] [log] [blame]
Jiri Kosina10bd0652007-11-22 15:18:18 +01001/*
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 *
Jiri Kosina85c985f2008-01-10 17:40:18 +01007 * Copyright (c) 2007-2008 Jiri Kosina
Jiri Kosina10bd0652007-11-22 15:18:18 +01008 */
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
Jiri Slaby022e8c42008-05-16 11:49:18 +020019#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))
Jiri Kosina10bd0652007-11-22 15:18:18 +010021
Jiri Slaby022e8c42008-05-16 11:49:18 +020022#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, bit, \
23 max, EV_KEY, (c))
Jiri Kosina10bd0652007-11-22 15:18:18 +010024
Jiri Slaby022e8c42008-05-16 11:49:18 +020025static int quirk_belkin_wkbd(struct hid_usage *usage,
26 struct hid_input *hidinput, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +010027{
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
Jiri Slaby022e8c42008-05-16 11:49:18 +020041static int quirk_gyration_remote(struct hid_usage *usage,
42 struct hid_input *hidinput, unsigned long **bit, int *max)
Daniel Walkera7f32692008-07-04 15:23:10 +020043{
44 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
45 return 0;
46
Jiri Slaby022e8c42008-05-16 11:49:18 +020047 set_bit(EV_REP, hidinput->input->evbit);
Daniel Walkera7f32692008-07-04 15:23:10 +020048 switch(usage->hid & HID_USAGE) {
49 /* Reported on Gyration MCE Remote */
50 case 0x00d: map_key_clear(KEY_HOME); break;
51 case 0x024: map_key_clear(KEY_DVD); break;
52 case 0x025: map_key_clear(KEY_PVR); break;
53 case 0x046: map_key_clear(KEY_MEDIA); break;
54 case 0x047: map_key_clear(KEY_MP3); break;
55 case 0x049: map_key_clear(KEY_CAMERA); break;
56 case 0x04a: map_key_clear(KEY_VIDEO); break;
57
58 default:
59 return 0;
60 }
61 return 1;
62}
63
Jiri Slaby022e8c42008-05-16 11:49:18 +020064static int quirk_chicony_tactical_pad(struct hid_usage *usage,
65 struct hid_input *hidinput, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +010066{
67 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
68 return 0;
69
Jiri Slaby022e8c42008-05-16 11:49:18 +020070 set_bit(EV_REP, hidinput->input->evbit);
Jiri Kosina10bd0652007-11-22 15:18:18 +010071 switch (usage->hid & HID_USAGE) {
72 case 0xff01: map_key_clear(BTN_1); break;
73 case 0xff02: map_key_clear(BTN_2); break;
74 case 0xff03: map_key_clear(BTN_3); break;
75 case 0xff04: map_key_clear(BTN_4); break;
76 case 0xff05: map_key_clear(BTN_5); break;
77 case 0xff06: map_key_clear(BTN_6); break;
78 case 0xff07: map_key_clear(BTN_7); break;
79 case 0xff08: map_key_clear(BTN_8); break;
80 case 0xff09: map_key_clear(BTN_9); break;
81 case 0xff0a: map_key_clear(BTN_A); break;
82 case 0xff0b: map_key_clear(BTN_B); break;
83 default:
84 return 0;
85 }
86 return 1;
87}
88
Jiri Slaby022e8c42008-05-16 11:49:18 +020089static int quirk_petalynx_remote(struct hid_usage *usage,
90 struct hid_input *hidinput, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +010091{
92 if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
93 ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
94 return 0;
95
96 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
97 switch(usage->hid & HID_USAGE) {
98 case 0x05a: map_key_clear(KEY_TEXT); break;
99 case 0x05b: map_key_clear(KEY_RED); break;
100 case 0x05c: map_key_clear(KEY_GREEN); break;
101 case 0x05d: map_key_clear(KEY_YELLOW); break;
102 case 0x05e: map_key_clear(KEY_BLUE); break;
103 default:
104 return 0;
105 }
106
107 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
108 switch(usage->hid & HID_USAGE) {
109 case 0x0f6: map_key_clear(KEY_NEXT); break;
110 case 0x0fa: map_key_clear(KEY_BACK); break;
111 default:
112 return 0;
113 }
114 return 1;
115}
116
Jiri Slaby022e8c42008-05-16 11:49:18 +0200117static int quirk_cherry_genius_29e(struct hid_usage *usage,
118 struct hid_input *hidinput, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +0100119{
120 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
121 return 0;
122
123 switch (usage->hid & HID_USAGE) {
124 case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
125 case 0x157: map_key_clear(KEY_SPREADSHEET); break;
126 case 0x158: map_key_clear(KEY_PRESENTATION); break;
127 case 0x15c: map_key_clear(KEY_STOP); break;
128
129 default:
130 return 0;
131 }
132 return 1;
133}
134
Jiri Slaby022e8c42008-05-16 11:49:18 +0200135static int quirk_btc_8193(struct hid_usage *usage, struct hid_input *hidinput,
Fengguang Wu70d215c2007-12-07 16:35:14 +0800136 unsigned long **bit, int *max)
Jiri Kosina36ccaad62007-11-26 13:18:00 +0100137{
138 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
139 return 0;
140
141 switch (usage->hid & HID_USAGE) {
142 case 0x230: map_key(BTN_MOUSE); break;
143 case 0x231: map_rel(REL_WHEEL); break;
144 /*
145 * this keyboard has a scrollwheel implemented in
146 * totally broken way. We map this usage temporarily
147 * to HWHEEL and handle it in the event quirk handler
148 */
149 case 0x232: map_rel(REL_HWHEEL); break;
150
151 default:
152 return 0;
153 }
154 return 1;
155}
Jiri Kosina10bd0652007-11-22 15:18:18 +0100156
157#define VENDOR_ID_BELKIN 0x1020
158#define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
159
Jiri Kosina10bd0652007-11-22 15:18:18 +0100160#define VENDOR_ID_CHICONY 0x04f2
161#define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
162
Jiri Kosina36ccaad62007-11-26 13:18:00 +0100163#define VENDOR_ID_EZKEY 0x0518
164#define DEVICE_ID_BTC_8193 0x0002
165
Daniel Walkera7f32692008-07-04 15:23:10 +0200166#define VENDOR_ID_GYRATION 0x0c16
167#define DEVICE_ID_GYRATION_REMOTE 0x0002
168
Jiri Kosina10bd0652007-11-22 15:18:18 +0100169#define VENDOR_ID_MONTEREY 0x0566
170#define DEVICE_ID_GENIUS_KB29E 0x3004
171
172#define VENDOR_ID_PETALYNX 0x18b1
173#define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
174
175static const struct hid_input_blacklist {
176 __u16 idVendor;
177 __u16 idProduct;
Jiri Slaby022e8c42008-05-16 11:49:18 +0200178 int (*quirk)(struct hid_usage *, struct hid_input *, unsigned long **,
179 int *);
Jiri Kosina10bd0652007-11-22 15:18:18 +0100180} hid_input_blacklist[] = {
181 { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
182
Jiri Kosina10bd0652007-11-22 15:18:18 +0100183 { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
184
Jiri Kosina36ccaad62007-11-26 13:18:00 +0100185 { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
186
Daniel Walkera7f32692008-07-04 15:23:10 +0200187 { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
188
Jiri Kosina10bd0652007-11-22 15:18:18 +0100189 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
190
191 { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
Jiri Kosina5f1ab742008-03-14 16:53:07 +0100192
Jiri Slaby282bfd42008-03-28 17:06:41 +0100193 { 0, 0, NULL }
Jiri Kosina10bd0652007-11-22 15:18:18 +0100194};
195
196int hidinput_mapping_quirks(struct hid_usage *usage,
Jiri Slaby022e8c42008-05-16 11:49:18 +0200197 struct hid_input *hi, unsigned long **bit, int *max)
Jiri Kosina10bd0652007-11-22 15:18:18 +0100198{
Jiri Slaby022e8c42008-05-16 11:49:18 +0200199 struct hid_device *device = input_get_drvdata(hi->input);
Jiri Kosina10bd0652007-11-22 15:18:18 +0100200 int i = 0;
201
202 while (hid_input_blacklist[i].quirk) {
203 if (hid_input_blacklist[i].idVendor == device->vendor &&
204 hid_input_blacklist[i].idProduct == device->product)
Jiri Slaby022e8c42008-05-16 11:49:18 +0200205 return hid_input_blacklist[i].quirk(usage, hi, bit,
206 max);
Jiri Kosina10bd0652007-11-22 15:18:18 +0100207 i++;
208 }
209 return 0;
210}
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100211
Jiri Kosina68a1f2c2008-02-07 16:48:46 +0100212int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100213{
214 struct input_dev *input;
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100215
216 input = field->hidinput->input;
217
Jiri Kosina36ccaad62007-11-26 13:18:00 +0100218 /* handle the temporary quirky mapping to HWHEEL */
219 if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
220 usage->type == EV_REL && usage->code == REL_HWHEEL) {
221 input_event(input, usage->type, REL_WHEEL, -value);
Jiri Kosina68a1f2c2008-02-07 16:48:46 +0100222 return 1;
Jiri Kosina36ccaad62007-11-26 13:18:00 +0100223 }
Jiri Kosina32146dc2008-07-04 15:22:53 +0200224
225 /* Gyration MCE remote "Sleep" key */
226 if (hid->vendor == VENDOR_ID_GYRATION &&
227 hid->product == DEVICE_ID_GYRATION_REMOTE &&
228 (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
229 (usage->hid & 0xff) == 0x82) {
230 input_event(input, usage->type, usage->code, 1);
231 input_sync(input);
232 input_event(input, usage->type, usage->code, 0);
233 input_sync(input);
234 return 1;
235 }
Jiri Kosina68a1f2c2008-02-07 16:48:46 +0100236 return 0;
Jiri Kosina87bc2aa2007-11-23 13:16:02 +0100237}
238
Jiri Kosina10bd0652007-11-22 15:18:18 +0100239