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) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
19 #include <linux/device.h>
20 #include <linux/input.h>
21 #include <linux/hid.h>
22 #include <linux/module.h>
26 #define MS_HIDINPUT 0x01
27 #define MS_ERGONOMY 0x02
28 #define MS_PRESENTER 0x04
33 * Microsoft Wireless Desktop Receiver (Model 1028) has several
34 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
36 static void ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
39 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
41 if ((quirks & MS_RDESC) && rsize == 571 && rdesc[284] == 0x19 &&
42 rdesc[286] == 0x2a && rdesc[304] == 0x19 &&
43 rdesc[306] == 0x29 && rdesc[352] == 0x1a &&
44 rdesc[355] == 0x2a && rdesc[557] == 0x19 &&
46 dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver "
47 "Model 1028 report descriptor\n");
48 rdesc[284] = rdesc[304] = rdesc[557] = 0x35;
50 rdesc[286] = rdesc[355] = 0x46;
51 rdesc[306] = rdesc[559] = 0x45;
55 #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
57 static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
58 unsigned long **bit, int *max)
60 struct input_dev *input = hi->input;
62 switch (usage->hid & HID_USAGE) {
63 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
64 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
66 set_bit(EV_REP, input->evbit);
67 ms_map_key_clear(KEY_F13);
68 set_bit(KEY_F14, input->keybit);
69 set_bit(KEY_F15, input->keybit);
70 set_bit(KEY_F16, input->keybit);
71 set_bit(KEY_F17, input->keybit);
72 set_bit(KEY_F18, input->keybit);
79 static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
80 unsigned long **bit, int *max)
82 set_bit(EV_REP, hi->input->evbit);
83 switch (usage->hid & HID_USAGE) {
84 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
85 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
86 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
87 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
88 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
95 static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
96 struct hid_field *field, struct hid_usage *usage,
97 unsigned long **bit, int *max)
99 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
101 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
104 if (quirks & MS_ERGONOMY) {
105 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
110 if ((quirks & MS_PRESENTER) &&
111 ms_presenter_8k_quirk(hi, usage, bit, max))
117 static int ms_event(struct hid_device *hdev, struct hid_field *field,
118 struct hid_usage *usage, __s32 value)
120 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
122 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
126 /* Handling MS keyboards special buttons */
127 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
128 struct input_dev *input = field->hidinput->input;
129 static unsigned int last_key = 0;
130 unsigned int key = 0;
132 case 0x01: key = KEY_F14; break;
133 case 0x02: key = KEY_F15; break;
134 case 0x04: key = KEY_F16; break;
135 case 0x08: key = KEY_F17; break;
136 case 0x10: key = KEY_F18; break;
139 input_event(input, usage->type, key, 1);
142 input_event(input, usage->type, last_key, 0);
150 static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
152 unsigned long quirks = id->driver_data;
155 hid_set_drvdata(hdev, (void *)quirks);
157 if (quirks & MS_NOGET)
158 hdev->quirks |= HID_QUIRK_NOGET;
160 ret = hid_parse(hdev);
162 dev_err(&hdev->dev, "parse failed\n");
166 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
167 HID_CONNECT_HIDINPUT_FORCE : 0));
169 dev_err(&hdev->dev, "hw start failed\n");
178 static const struct hid_device_id ms_devices[] = {
179 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
180 .driver_data = MS_HIDINPUT },
181 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
182 .driver_data = MS_ERGONOMY },
183 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
184 .driver_data = MS_ERGONOMY | MS_RDESC },
185 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
186 .driver_data = MS_PRESENTER },
187 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
188 .driver_data = MS_NOGET },
190 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
191 .driver_data = MS_PRESENTER },
194 MODULE_DEVICE_TABLE(hid, ms_devices);
196 static struct hid_driver ms_driver = {
198 .id_table = ms_devices,
199 .report_fixup = ms_report_fixup,
200 .input_mapping = ms_input_mapping,
205 static int ms_init(void)
207 return hid_register_driver(&ms_driver);
210 static void ms_exit(void)
212 hid_unregister_driver(&ms_driver);
215 module_init(ms_init);
216 module_exit(ms_exit);
217 MODULE_LICENSE("GPL");
219 HID_COMPAT_LOAD_DRIVER(microsoft);