blob: e924d555536cf7fb1b221af4c15e51112df107c8 [file] [log] [blame]
Jiri Slaby78a849a682008-06-20 21:26:11 +02001/*
2 * HID driver for some microsoft "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
Jiri Slaby78a849a682008-06-20 21:26:11 +02008 * Copyright (c) 2008 Jiri Slaby
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#include <linux/device.h>
19#include <linux/input.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
Ari Savolainen23c10be2011-07-11 21:42:52 +030025#define MS_HIDINPUT 0x01
26#define MS_ERGONOMY 0x02
27#define MS_PRESENTER 0x04
28#define MS_RDESC 0x08
29#define MS_NOGET 0x10
30#define MS_DUPLICATE_USAGES 0x20
Jiri Slaby3ccc60f2012-10-19 13:28:46 +020031#define MS_RDESC_3K 0x40
Jiri Slaby78a849a682008-06-20 21:26:11 +020032
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040033static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
34 unsigned int *rsize)
Jiri Slaby78a849a682008-06-20 21:26:11 +020035{
36 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
37
Jiri Slaby3ccc60f2012-10-19 13:28:46 +020038 /*
39 * Microsoft Wireless Desktop Receiver (Model 1028) has
40 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
41 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040042 if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 &&
Jiri Slaby78a849a682008-06-20 21:26:11 +020043 rdesc[559] == 0x29) {
Joe Perches4291ee32010-12-09 19:29:03 -080044 hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
Jiri Kosina0fb21de2009-01-14 03:03:21 +010045 rdesc[557] = 0x35;
46 rdesc[559] = 0x45;
Jiri Slaby78a849a682008-06-20 21:26:11 +020047 }
Jiri Slaby3ccc60f2012-10-19 13:28:46 +020048 /* the same as above (s/usage/physical/) */
Jiri Slaby6b904662012-11-12 10:16:09 +010049 if ((quirks & MS_RDESC_3K) && *rsize == 106 && rdesc[94] == 0x19 &&
50 rdesc[95] == 0x00 && rdesc[96] == 0x29 &&
51 rdesc[97] == 0xff) {
Jiri Slaby3ccc60f2012-10-19 13:28:46 +020052 rdesc[94] = 0x35;
53 rdesc[96] = 0x45;
54 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040055 return rdesc;
Jiri Slaby78a849a682008-06-20 21:26:11 +020056}
57
58#define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
59 EV_KEY, (c))
60static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
61 unsigned long **bit, int *max)
62{
63 struct input_dev *input = hi->input;
64
Hans de Goede34e75dc2014-01-29 17:57:44 +010065 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
66 switch (usage->hid & HID_USAGE) {
67 /*
68 * Microsoft uses these 2 reserved usage ids for 2 keys on
69 * the MS office kb labelled "Office Home" and "Task Pane".
70 */
71 case 0x29d:
72 ms_map_key_clear(KEY_PROG1);
73 return 1;
74 case 0x29e:
75 ms_map_key_clear(KEY_PROG2);
76 return 1;
77 }
78 return 0;
79 }
80
Hans de Goedeaac59f62014-01-29 17:57:42 +010081 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
82 return 0;
83
Jiri Slaby78a849a682008-06-20 21:26:11 +020084 switch (usage->hid & HID_USAGE) {
85 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
86 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
Hans de Goede3faed1a2014-01-29 17:57:43 +010087 case 0xff00:
88 /* Special keypad keys */
89 ms_map_key_clear(KEY_KPEQUAL);
90 set_bit(KEY_KPLEFTPAREN, input->keybit);
91 set_bit(KEY_KPRIGHTPAREN, input->keybit);
92 break;
93 case 0xff01:
94 /* Scroll wheel */
95 hid_map_usage_clear(hi, usage, bit, max, EV_REL, REL_WHEEL);
96 break;
97 case 0xff02:
98 /*
99 * This byte contains a copy of the modifier keys byte of a
100 * standard hid keyboard report, as send by interface 0
101 * (this usage is found on interface 1).
102 *
103 * This byte only gets send when another key in the same report
104 * changes state, and as such is useless, ignore it.
105 */
106 return -1;
Jiri Slaby78a849a682008-06-20 21:26:11 +0200107 case 0xff05:
108 set_bit(EV_REP, input->evbit);
109 ms_map_key_clear(KEY_F13);
110 set_bit(KEY_F14, input->keybit);
111 set_bit(KEY_F15, input->keybit);
112 set_bit(KEY_F16, input->keybit);
113 set_bit(KEY_F17, input->keybit);
114 set_bit(KEY_F18, input->keybit);
Jiri Kosinab2b98ea2013-12-15 18:25:26 +0100115 break;
Jiri Slaby78a849a682008-06-20 21:26:11 +0200116 default:
117 return 0;
118 }
119 return 1;
120}
121
122static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
123 unsigned long **bit, int *max)
124{
Hans de Goedeaac59f62014-01-29 17:57:42 +0100125 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
126 return 0;
127
Jiri Slaby78a849a682008-06-20 21:26:11 +0200128 set_bit(EV_REP, hi->input->evbit);
129 switch (usage->hid & HID_USAGE) {
130 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
131 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
132 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
133 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
134 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
135 default:
136 return 0;
137 }
138 return 1;
139}
140
141static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
142 struct hid_field *field, struct hid_usage *usage,
143 unsigned long **bit, int *max)
144{
145 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
146
Jiri Slaby78a849a682008-06-20 21:26:11 +0200147 if (quirks & MS_ERGONOMY) {
148 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
149 if (ret)
150 return ret;
151 }
152
153 if ((quirks & MS_PRESENTER) &&
154 ms_presenter_8k_quirk(hi, usage, bit, max))
155 return 1;
156
157 return 0;
158}
159
Ari Savolainen23c10be2011-07-11 21:42:52 +0300160static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi,
161 struct hid_field *field, struct hid_usage *usage,
162 unsigned long **bit, int *max)
163{
164 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
165
166 if (quirks & MS_DUPLICATE_USAGES)
167 clear_bit(usage->code, *bit);
168
169 return 0;
170}
171
Jiri Slaby78a849a682008-06-20 21:26:11 +0200172static int ms_event(struct hid_device *hdev, struct hid_field *field,
173 struct hid_usage *usage, __s32 value)
174{
175 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
Hans de Goede3faed1a2014-01-29 17:57:43 +0100176 struct input_dev *input;
Jiri Slaby78a849a682008-06-20 21:26:11 +0200177
178 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
179 !usage->type)
180 return 0;
181
Hans de Goede3faed1a2014-01-29 17:57:43 +0100182 input = field->hidinput->input;
183
Jiri Slaby78a849a682008-06-20 21:26:11 +0200184 /* Handling MS keyboards special buttons */
Hans de Goede3faed1a2014-01-29 17:57:43 +0100185 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff00)) {
186 /* Special keypad keys */
187 input_report_key(input, KEY_KPEQUAL, value & 0x01);
188 input_report_key(input, KEY_KPLEFTPAREN, value & 0x02);
189 input_report_key(input, KEY_KPRIGHTPAREN, value & 0x04);
190 return 1;
191 }
192
193 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff01)) {
194 /* Scroll wheel */
195 int step = ((value & 0x60) >> 5) + 1;
196
197 switch (value & 0x1f) {
198 case 0x01:
199 input_report_rel(input, REL_WHEEL, step);
200 break;
201 case 0x1f:
202 input_report_rel(input, REL_WHEEL, -step);
203 break;
204 }
205 return 1;
206 }
207
Jiri Slaby78a849a682008-06-20 21:26:11 +0200208 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
Jiri Slaby78a849a682008-06-20 21:26:11 +0200209 static unsigned int last_key = 0;
210 unsigned int key = 0;
211 switch (value) {
212 case 0x01: key = KEY_F14; break;
213 case 0x02: key = KEY_F15; break;
214 case 0x04: key = KEY_F16; break;
215 case 0x08: key = KEY_F17; break;
216 case 0x10: key = KEY_F18; break;
217 }
218 if (key) {
219 input_event(input, usage->type, key, 1);
220 last_key = key;
221 } else
222 input_event(input, usage->type, last_key, 0);
223
224 return 1;
225 }
226
227 return 0;
228}
229
230static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
231{
232 unsigned long quirks = id->driver_data;
233 int ret;
234
235 hid_set_drvdata(hdev, (void *)quirks);
236
Jiri Slaby78a849a682008-06-20 21:26:11 +0200237 if (quirks & MS_NOGET)
238 hdev->quirks |= HID_QUIRK_NOGET;
239
240 ret = hid_parse(hdev);
241 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800242 hid_err(hdev, "parse failed\n");
Jiri Slaby78a849a682008-06-20 21:26:11 +0200243 goto err_free;
244 }
245
Jiri Slaby93c10132008-06-27 00:04:24 +0200246 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
247 HID_CONNECT_HIDINPUT_FORCE : 0));
Jiri Slaby78a849a682008-06-20 21:26:11 +0200248 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800249 hid_err(hdev, "hw start failed\n");
Jiri Slaby78a849a682008-06-20 21:26:11 +0200250 goto err_free;
251 }
252
253 return 0;
254err_free:
255 return ret;
256}
257
258static const struct hid_device_id ms_devices[] = {
259 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
260 .driver_data = MS_HIDINPUT },
Hans de Goede3faed1a2014-01-29 17:57:43 +0100261 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB),
262 .driver_data = MS_ERGONOMY },
Jiri Slaby78a849a682008-06-20 21:26:11 +0200263 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
264 .driver_data = MS_ERGONOMY },
Adam Jiang89759e22013-04-29 13:27:31 +0900265 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP),
266 .driver_data = MS_ERGONOMY },
Jakub Sitnickief567cf2015-02-21 20:51:08 +0100267 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K),
268 .driver_data = MS_ERGONOMY },
Jiri Slaby78a849a682008-06-20 21:26:11 +0200269 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
270 .driver_data = MS_ERGONOMY | MS_RDESC },
271 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
272 .driver_data = MS_PRESENTER },
Jiri Kosinaf3b83d72011-06-13 23:08:18 +0300273 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K),
Jiri Slaby3ccc60f2012-10-19 13:28:46 +0200274 .driver_data = MS_ERGONOMY | MS_RDESC_3K },
Alistair Leslie-Hughesc847a892016-04-04 20:51:40 +1000275 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K),
276 .driver_data = MS_ERGONOMY },
277 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600),
278 .driver_data = MS_ERGONOMY },
279 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1),
280 .driver_data = MS_ERGONOMY },
Jiri Slaby78a849a682008-06-20 21:26:11 +0200281 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
282 .driver_data = MS_NOGET },
Ari Savolainen23c10be2011-07-11 21:42:52 +0300283 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
284 .driver_data = MS_DUPLICATE_USAGES },
Stephen Just0439de72015-07-22 20:11:40 -0700285 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3),
Alan Wube3b1632014-11-03 18:26:12 -0800286 .driver_data = MS_HIDINPUT },
Donavan Lancec6956eb2015-09-15 12:44:54 -0400287 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2),
288 .driver_data = MS_HIDINPUT },
Stephen Just0439de72015-07-22 20:11:40 -0700289 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP),
290 .driver_data = MS_HIDINPUT },
291 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3),
Alan Wu5e7e9e92015-01-06 18:32:51 -0800292 .driver_data = MS_HIDINPUT },
Raimund Roth18eec2c2015-06-08 11:11:38 +0200293 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER),
294 .driver_data = MS_HIDINPUT },
Slava Bacherikovf9a82c22016-03-11 18:57:24 +0200295 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD),
296 .driver_data = MS_ERGONOMY},
Jiri Slaby78a849a682008-06-20 21:26:11 +0200297
298 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
299 .driver_data = MS_PRESENTER },
300 { }
301};
302MODULE_DEVICE_TABLE(hid, ms_devices);
303
304static struct hid_driver ms_driver = {
305 .name = "microsoft",
306 .id_table = ms_devices,
307 .report_fixup = ms_report_fixup,
308 .input_mapping = ms_input_mapping,
Ari Savolainen23c10be2011-07-11 21:42:52 +0300309 .input_mapped = ms_input_mapped,
Jiri Slaby78a849a682008-06-20 21:26:11 +0200310 .event = ms_event,
311 .probe = ms_probe,
312};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700313module_hid_driver(ms_driver);
Jiri Slaby78a849a682008-06-20 21:26:11 +0200314
Jiri Slaby78a849a682008-06-20 21:26:11 +0200315MODULE_LICENSE("GPL");