2 * HID driver for some microsoft "special" devices
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
8 * Copyright (c) 2008 Jiri Slaby
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)
18 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
25 #define MS_HIDINPUT 0x01
26 #define MS_ERGONOMY 0x02
27 #define MS_PRESENTER 0x04
30 #define MS_DUPLICATE_USAGES 0x20
31 #define MS_RDESC_3K 0x40
33 static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
36 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
39 * Microsoft Wireless Desktop Receiver (Model 1028) has
40 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
42 if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 &&
44 hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
48 /* the same as above (s/usage/physical/) */
49 if ((quirks & MS_RDESC_3K) && *rsize == 106 && rdesc[94] == 0x19 &&
50 rdesc[95] == 0x00 && rdesc[96] == 0x29 &&
58 #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
60 static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
61 unsigned long **bit, int *max)
63 struct input_dev *input = hi->input;
65 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
66 switch (usage->hid & HID_USAGE) {
68 * Microsoft uses these 2 reserved usage ids for 2 keys on
69 * the MS office kb labelled "Office Home" and "Task Pane".
72 ms_map_key_clear(KEY_PROG1);
75 ms_map_key_clear(KEY_PROG2);
81 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
84 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;
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);
95 hid_map_usage_clear(hi, usage, bit, max, EV_REL, REL_WHEEL);
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).
103 * This byte only gets send when another key in the same report
104 * changes state, and as such is useless, ignore it.
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);
122 static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
123 unsigned long **bit, int *max)
125 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
128 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;
141 static 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)
145 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
147 if (quirks & MS_ERGONOMY) {
148 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
153 if ((quirks & MS_PRESENTER) &&
154 ms_presenter_8k_quirk(hi, usage, bit, max))
160 static 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)
164 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
166 if (quirks & MS_DUPLICATE_USAGES)
167 clear_bit(usage->code, *bit);
172 static int ms_event(struct hid_device *hdev, struct hid_field *field,
173 struct hid_usage *usage, __s32 value)
175 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
176 struct input_dev *input;
178 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
182 input = field->hidinput->input;
184 /* Handling MS keyboards special buttons */
185 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);
193 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff01)) {
195 int step = ((value & 0x60) >> 5) + 1;
197 switch (value & 0x1f) {
199 input_report_rel(input, REL_WHEEL, step);
202 input_report_rel(input, REL_WHEEL, -step);
208 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
209 static unsigned int last_key = 0;
210 unsigned int key = 0;
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;
219 input_event(input, usage->type, key, 1);
222 input_event(input, usage->type, last_key, 0);
230 static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
232 unsigned long quirks = id->driver_data;
235 hid_set_drvdata(hdev, (void *)quirks);
237 if (quirks & MS_NOGET)
238 hdev->quirks |= HID_QUIRK_NOGET;
240 ret = hid_parse(hdev);
242 hid_err(hdev, "parse failed\n");
246 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
247 HID_CONNECT_HIDINPUT_FORCE : 0));
249 hid_err(hdev, "hw start failed\n");
258 static 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 },
261 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB),
262 .driver_data = MS_ERGONOMY },
263 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
264 .driver_data = MS_ERGONOMY },
265 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP),
266 .driver_data = MS_ERGONOMY },
267 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
268 .driver_data = MS_ERGONOMY | MS_RDESC },
269 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
270 .driver_data = MS_PRESENTER },
271 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K),
272 .driver_data = MS_ERGONOMY | MS_RDESC_3K },
273 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
274 .driver_data = MS_NOGET },
275 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
276 .driver_data = MS_DUPLICATE_USAGES },
278 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
279 .driver_data = MS_PRESENTER },
282 MODULE_DEVICE_TABLE(hid, ms_devices);
284 static struct hid_driver ms_driver = {
286 .id_table = ms_devices,
287 .report_fixup = ms_report_fixup,
288 .input_mapping = ms_input_mapping,
289 .input_mapped = ms_input_mapped,
293 module_hid_driver(ms_driver);
295 MODULE_LICENSE("GPL");