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
32 static __u8
*ms_report_fixup(struct hid_device
*hdev
, __u8
*rdesc
,
35 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
38 * Microsoft Wireless Desktop Receiver (Model 1028) has
39 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
41 if ((quirks
& MS_RDESC
) && *rsize
== 571 && rdesc
[557] == 0x19 &&
43 hid_info(hdev
, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
50 #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
52 static int ms_ergonomy_kb_quirk(struct hid_input
*hi
, struct hid_usage
*usage
,
53 unsigned long **bit
, int *max
)
55 struct input_dev
*input
= hi
->input
;
57 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_CONSUMER
) {
58 switch (usage
->hid
& HID_USAGE
) {
60 * Microsoft uses these 2 reserved usage ids for 2 keys on
61 * the MS office kb labelled "Office Home" and "Task Pane".
64 ms_map_key_clear(KEY_PROG1
);
67 ms_map_key_clear(KEY_PROG2
);
73 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_MSVENDOR
)
76 switch (usage
->hid
& HID_USAGE
) {
77 case 0xfd06: ms_map_key_clear(KEY_CHAT
); break;
78 case 0xfd07: ms_map_key_clear(KEY_PHONE
); break;
80 /* Special keypad keys */
81 ms_map_key_clear(KEY_KPEQUAL
);
82 set_bit(KEY_KPLEFTPAREN
, input
->keybit
);
83 set_bit(KEY_KPRIGHTPAREN
, input
->keybit
);
87 hid_map_usage_clear(hi
, usage
, bit
, max
, EV_REL
, REL_WHEEL
);
91 * This byte contains a copy of the modifier keys byte of a
92 * standard hid keyboard report, as send by interface 0
93 * (this usage is found on interface 1).
95 * This byte only gets send when another key in the same report
96 * changes state, and as such is useless, ignore it.
100 set_bit(EV_REP
, input
->evbit
);
101 ms_map_key_clear(KEY_F13
);
102 set_bit(KEY_F14
, input
->keybit
);
103 set_bit(KEY_F15
, input
->keybit
);
104 set_bit(KEY_F16
, input
->keybit
);
105 set_bit(KEY_F17
, input
->keybit
);
106 set_bit(KEY_F18
, input
->keybit
);
114 static int ms_presenter_8k_quirk(struct hid_input
*hi
, struct hid_usage
*usage
,
115 unsigned long **bit
, int *max
)
117 if ((usage
->hid
& HID_USAGE_PAGE
) != HID_UP_MSVENDOR
)
120 set_bit(EV_REP
, hi
->input
->evbit
);
121 switch (usage
->hid
& HID_USAGE
) {
122 case 0xfd08: ms_map_key_clear(KEY_FORWARD
); break;
123 case 0xfd09: ms_map_key_clear(KEY_BACK
); break;
124 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE
); break;
125 case 0xfd0e: ms_map_key_clear(KEY_CLOSE
); break;
126 case 0xfd0f: ms_map_key_clear(KEY_PLAY
); break;
133 static int ms_input_mapping(struct hid_device
*hdev
, struct hid_input
*hi
,
134 struct hid_field
*field
, struct hid_usage
*usage
,
135 unsigned long **bit
, int *max
)
137 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
139 if (quirks
& MS_ERGONOMY
) {
140 int ret
= ms_ergonomy_kb_quirk(hi
, usage
, bit
, max
);
145 if ((quirks
& MS_PRESENTER
) &&
146 ms_presenter_8k_quirk(hi
, usage
, bit
, max
))
152 static int ms_input_mapped(struct hid_device
*hdev
, struct hid_input
*hi
,
153 struct hid_field
*field
, struct hid_usage
*usage
,
154 unsigned long **bit
, int *max
)
156 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
158 if (quirks
& MS_DUPLICATE_USAGES
)
159 clear_bit(usage
->code
, *bit
);
164 static int ms_event(struct hid_device
*hdev
, struct hid_field
*field
,
165 struct hid_usage
*usage
, __s32 value
)
167 unsigned long quirks
= (unsigned long)hid_get_drvdata(hdev
);
168 struct input_dev
*input
;
170 if (!(hdev
->claimed
& HID_CLAIMED_INPUT
) || !field
->hidinput
||
174 input
= field
->hidinput
->input
;
176 /* Handling MS keyboards special buttons */
177 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff00)) {
178 /* Special keypad keys */
179 input_report_key(input
, KEY_KPEQUAL
, value
& 0x01);
180 input_report_key(input
, KEY_KPLEFTPAREN
, value
& 0x02);
181 input_report_key(input
, KEY_KPRIGHTPAREN
, value
& 0x04);
185 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff01)) {
187 int step
= ((value
& 0x60) >> 5) + 1;
189 switch (value
& 0x1f) {
191 input_report_rel(input
, REL_WHEEL
, step
);
194 input_report_rel(input
, REL_WHEEL
, -step
);
200 if (quirks
& MS_ERGONOMY
&& usage
->hid
== (HID_UP_MSVENDOR
| 0xff05)) {
201 static unsigned int last_key
= 0;
202 unsigned int key
= 0;
204 case 0x01: key
= KEY_F14
; break;
205 case 0x02: key
= KEY_F15
; break;
206 case 0x04: key
= KEY_F16
; break;
207 case 0x08: key
= KEY_F17
; break;
208 case 0x10: key
= KEY_F18
; break;
211 input_event(input
, usage
->type
, key
, 1);
214 input_event(input
, usage
->type
, last_key
, 0);
222 static int ms_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
224 unsigned long quirks
= id
->driver_data
;
227 hid_set_drvdata(hdev
, (void *)quirks
);
229 if (quirks
& MS_NOGET
)
230 hdev
->quirks
|= HID_QUIRK_NOGET
;
232 ret
= hid_parse(hdev
);
234 hid_err(hdev
, "parse failed\n");
238 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
| ((quirks
& MS_HIDINPUT
) ?
239 HID_CONNECT_HIDINPUT_FORCE
: 0));
241 hid_err(hdev
, "hw start failed\n");
250 static const struct hid_device_id ms_devices
[] = {
251 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_SIDEWINDER_GV
),
252 .driver_data
= MS_HIDINPUT
},
253 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_OFFICE_KB
),
254 .driver_data
= MS_ERGONOMY
},
255 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K
),
256 .driver_data
= MS_ERGONOMY
},
257 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE4K_JP
),
258 .driver_data
= MS_ERGONOMY
},
259 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_NE7K
),
260 .driver_data
= MS_ERGONOMY
},
261 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_LK6K
),
262 .driver_data
= MS_ERGONOMY
| MS_RDESC
},
263 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_USB
),
264 .driver_data
= MS_PRESENTER
},
265 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K
),
266 .driver_data
= MS_ERGONOMY
},
267 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K
),
268 .driver_data
= MS_ERGONOMY
},
269 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600
),
270 .driver_data
= MS_ERGONOMY
},
271 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1
),
272 .driver_data
= MS_ERGONOMY
},
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
},
277 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3
),
278 .driver_data
= MS_HIDINPUT
},
279 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2
),
280 .driver_data
= MS_HIDINPUT
},
281 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP
),
282 .driver_data
= MS_HIDINPUT
},
283 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_TYPE_COVER_PRO_4_JP
),
284 .driver_data
= MS_HIDINPUT
},
285 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_POWER_COVER
),
286 .driver_data
= MS_HIDINPUT
},
287 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_COMFORT_KEYBOARD
),
288 .driver_data
= MS_ERGONOMY
},
290 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT
, USB_DEVICE_ID_MS_PRESENTER_8K_BT
),
291 .driver_data
= MS_PRESENTER
},
294 MODULE_DEVICE_TABLE(hid
, ms_devices
);
296 static struct hid_driver ms_driver
= {
298 .id_table
= ms_devices
,
299 .report_fixup
= ms_report_fixup
,
300 .input_mapping
= ms_input_mapping
,
301 .input_mapped
= ms_input_mapped
,
305 module_hid_driver(ms_driver
);
307 MODULE_LICENSE("GPL");