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 BIT(0)
26 #define MS_ERGONOMY BIT(1)
27 #define MS_PRESENTER BIT(2)
28 #define MS_RDESC BIT(3)
29 #define MS_NOGET BIT(4)
30 #define MS_DUPLICATE_USAGES BIT(5)
31 #define MS_SURFACE_DIAL BIT(6)
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");
51 #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
53 static int ms_ergonomy_kb_quirk(struct hid_input
*hi
, struct hid_usage
*usage
,
54 unsigned long **bit
, int *max
)
56 struct input_dev
*input
= hi
->input
;
58 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_CONSUMER
) {
59 switch (usage
->hid
& HID_USAGE
) {
61 * Microsoft uses these 2 reserved usage ids for 2 keys on
62 * the MS office kb labelled "Office Home" and "Task Pane".
65 ms_map_key_clear(KEY_PROG1
);
68 ms_map_key_clear(KEY_PROG2
);
74 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_MSVENDOR
)
77 switch (usage
->hid
& HID_USAGE
) {
78 case 0xfd06: ms_map_key_clear(KEY_CHAT
); break;
79 case 0xfd07: ms_map_key_clear(KEY_PHONE
); break;
81 /* Special keypad keys */
82 ms_map_key_clear(KEY_KPEQUAL
);
83 set_bit(KEY_KPLEFTPAREN
, input
->keybit
);
84 set_bit(KEY_KPRIGHTPAREN
, input
->keybit
);
88 hid_map_usage_clear(hi
, usage
, bit
, max
, EV_REL
, REL_WHEEL
);
92 * This byte contains a copy of the modifier keys byte of a
93 * standard hid keyboard report, as send by interface 0
94 * (this usage is found on interface 1).
96 * This byte only gets send when another key in the same report
97 * changes state, and as such is useless, ignore it.
101 set_bit(EV_REP
, input
->evbit
);
102 ms_map_key_clear(KEY_F13
);
103 set_bit(KEY_F14
, input
->keybit
);
104 set_bit(KEY_F15
, input
->keybit
);
105 set_bit(KEY_F16
, input
->keybit
);
106 set_bit(KEY_F17
, input
->keybit
);
107 set_bit(KEY_F18
, input
->keybit
);
115 static int ms_presenter_8k_quirk(struct hid_input
*hi
, struct hid_usage
*usage
,
116 unsigned long **bit
, int *max
)
118 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_MSVENDOR
)
121 set_bit(EV_REP
, hi
->input
->evbit
);
122 switch (usage
->hid
& HID_USAGE
) {
123 case 0xfd08: ms_map_key_clear(KEY_FORWARD
); break;
124 case 0xfd09: ms_map_key_clear(KEY_BACK
); break;
125 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE
); break;
126 case 0xfd0e: ms_map_key_clear(KEY_CLOSE
); break;
127 case 0xfd0f: ms_map_key_clear(KEY_PLAY
); break;
134 static int ms_surface_dial_quirk(struct hid_input
*hi
, struct hid_field
*field
,
135 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
137 switch (usage
->hid
& HID_USAGE_PAGE
) {
140 case HID_UP_DIGITIZER
:
141 /* ignore those axis */
144 switch (usage
->hid
) {
149 case HID_GD_RFKILL_BTN
:
150 /* ignore those axis */
158 static int ms_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
159 struct hid_field
*field
, struct hid_usage
*usage
,
160 unsigned long **bit
, int *max
)
162 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
164 if (quirks
& MS_ERGONOMY
) {
165 int ret
= ms_ergonomy_kb_quirk(hi
, usage
, bit
, max
);
170 if ((quirks
& MS_PRESENTER
) &&
171 ms_presenter_8k_quirk(hi
, usage
, bit
, max
))
174 if (quirks
& MS_SURFACE_DIAL
) {
175 int ret
= ms_surface_dial_quirk(hi
, field
, usage
, bit
, max
);
184 static int ms_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
185 struct hid_field
*field
, struct hid_usage
*usage
,
186 unsigned long **bit
, int *max
)
188 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
190 if (quirks
& MS_DUPLICATE_USAGES
)
191 clear_bit(usage
->code
, *bit
);
196 static int ms_event(struct hid_device
*hdev
, struct hid_field
*field
,
197 struct hid_usage
*usage
, __s32 value
)
199 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
200 struct input_dev
*input
;
202 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
) || !field
->hidinput
||
206 input
= field
->hidinput
->input
;
208 /* Handling MS keyboards special buttons */
209 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff00)) {
210 /* Special keypad keys */
211 input_report_key(input
, KEY_KPEQUAL
, value
& 0x01);
212 input_report_key(input
, KEY_KPLEFTPAREN
, value
& 0x02);
213 input_report_key(input
, KEY_KPRIGHTPAREN
, value
& 0x04);
217 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff01)) {
219 int step
= ((value
& 0x60) >> 5) + 1;
221 switch (value
& 0x1f) {
223 input_report_rel(input
, REL_WHEEL
, step
);
226 input_report_rel(input
, REL_WHEEL
, -step
);
232 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff05)) {
233 static unsigned int last_key
= 0;
234 unsigned int key
= 0;
236 case 0x01: key
= KEY_F14
; break;
237 case 0x02: key
= KEY_F15
; break;
238 case 0x04: key
= KEY_F16
; break;
239 case 0x08: key
= KEY_F17
; break;
240 case 0x10: key
= KEY_F18
; break;
243 input_event(input
, usage
->type
, key
, 1);
246 input_event(input
, usage
->type
, last_key
, 0);
254 static int ms_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
256 unsigned long quirks
= id
->driver_data
;
259 hid_set_drvdata(hdev
, (void *)quirks
);
261 if (quirks
& MS_NOGET
)
262 hdev
->quirks
|= HID_QUIRK_NOGET
;
264 if (quirks
& MS_SURFACE_DIAL
)
265 hdev
->quirks
|= HID_QUIRK_INPUT_PER_APP
;
267 ret
= hid_parse(hdev
);
269 hid_err(hdev
, "parse failed\n");
273 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
| ((quirks
& MS_HIDINPUT
) ?
274 HID_CONNECT_HIDINPUT_FORCE
: 0));
276 hid_err(hdev
, "hw start failed\n");
285 static const struct hid_device_id ms_devices
[] = {
286 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_SIDEWINDER_GV
),
287 .driver_data
= MS_HIDINPUT
},
288 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_OFFICE_KB
),
289 .driver_data
= MS_ERGONOMY
},
290 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K
),
291 .driver_data
= MS_ERGONOMY
},
292 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K_JP
),
293 .driver_data
= MS_ERGONOMY
},
294 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE7K
),
295 .driver_data
= MS_ERGONOMY
},
296 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_LK6K
),
297 .driver_data
= MS_ERGONOMY
| MS_RDESC
},
298 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_USB
),
299 .driver_data
= MS_PRESENTER
},
300 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K
),
301 .driver_data
= MS_ERGONOMY
},
302 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K
),
303 .driver_data
= MS_ERGONOMY
},
304 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600
),
305 .driver_data
= MS_ERGONOMY
},
306 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1
),
307 .driver_data
= MS_ERGONOMY
},
308 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0
),
309 .driver_data
= MS_NOGET
},
310 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500
),
311 .driver_data
= MS_DUPLICATE_USAGES
},
312 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_POWER_COVER
),
313 .driver_data
= MS_HIDINPUT
},
314 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_COMFORT_KEYBOARD
),
315 .driver_data
= MS_ERGONOMY
},
317 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_BT
),
318 .driver_data
= MS_PRESENTER
},
319 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT
, 0x091B),
320 .driver_data
= MS_SURFACE_DIAL
},
323 MODULE_DEVICE_TABLE(hid
, ms_devices
);
325 static struct hid_driver ms_driver
= {
327 .id_table
= ms_devices
,
328 .report_fixup
= ms_report_fixup
,
329 .input_mapping
= ms_input_mapping
,
330 .input_mapped
= ms_input_mapped
,
334 module_hid_driver(ms_driver
);
336 MODULE_LICENSE("GPL");