diff options
Diffstat (limited to 'drivers/hid/hid-microsoft.c')
-rw-r--r-- | drivers/hid/hid-microsoft.c | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c new file mode 100644 index 000000000000..1fa8b813d441 --- /dev/null +++ b/drivers/hid/hid-microsoft.c | |||
@@ -0,0 +1,220 @@ | |||
1 | /* | ||
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 | ||
8 | * Copyright (c) 2007 Paul Walmsley | ||
9 | * Copyright (c) 2008 Jiri Slaby | ||
10 | */ | ||
11 | |||
12 | /* | ||
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) | ||
16 | * any later version. | ||
17 | */ | ||
18 | |||
19 | #include <linux/device.h> | ||
20 | #include <linux/input.h> | ||
21 | #include <linux/hid.h> | ||
22 | #include <linux/module.h> | ||
23 | |||
24 | #include "hid-ids.h" | ||
25 | |||
26 | #define MS_HIDINPUT 0x01 | ||
27 | #define MS_ERGONOMY 0x02 | ||
28 | #define MS_PRESENTER 0x04 | ||
29 | #define MS_RDESC 0x08 | ||
30 | #define MS_NOGET 0x10 | ||
31 | |||
32 | /* | ||
33 | * Microsoft Wireless Desktop Receiver (Model 1028) has several | ||
34 | * 'Usage Min/Max' where it ought to have 'Physical Min/Max' | ||
35 | */ | ||
36 | static void ms_report_fixup(struct hid_device *hdev, __u8 *rdesc, | ||
37 | unsigned int rsize) | ||
38 | { | ||
39 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
40 | |||
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 && | ||
45 | rdesc[559] == 0x29) { | ||
46 | dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver " | ||
47 | "Model 1028 report descriptor\n"); | ||
48 | rdesc[284] = rdesc[304] = rdesc[557] = 0x35; | ||
49 | rdesc[352] = 0x36; | ||
50 | rdesc[286] = rdesc[355] = 0x46; | ||
51 | rdesc[306] = rdesc[559] = 0x45; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ | ||
56 | EV_KEY, (c)) | ||
57 | static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage, | ||
58 | unsigned long **bit, int *max) | ||
59 | { | ||
60 | struct input_dev *input = hi->input; | ||
61 | |||
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; | ||
65 | case 0xff05: | ||
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); | ||
73 | default: | ||
74 | return 0; | ||
75 | } | ||
76 | return 1; | ||
77 | } | ||
78 | |||
79 | static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage, | ||
80 | unsigned long **bit, int *max) | ||
81 | { | ||
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; | ||
89 | default: | ||
90 | return 0; | ||
91 | } | ||
92 | return 1; | ||
93 | } | ||
94 | |||
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) | ||
98 | { | ||
99 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
100 | |||
101 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR) | ||
102 | return 0; | ||
103 | |||
104 | if (quirks & MS_ERGONOMY) { | ||
105 | int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max); | ||
106 | if (ret) | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | if ((quirks & MS_PRESENTER) && | ||
111 | ms_presenter_8k_quirk(hi, usage, bit, max)) | ||
112 | return 1; | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | static int ms_event(struct hid_device *hdev, struct hid_field *field, | ||
118 | struct hid_usage *usage, __s32 value) | ||
119 | { | ||
120 | unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); | ||
121 | |||
122 | if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput || | ||
123 | !usage->type) | ||
124 | return 0; | ||
125 | |||
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; | ||
131 | switch (value) { | ||
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; | ||
137 | } | ||
138 | if (key) { | ||
139 | input_event(input, usage->type, key, 1); | ||
140 | last_key = key; | ||
141 | } else | ||
142 | input_event(input, usage->type, last_key, 0); | ||
143 | |||
144 | return 1; | ||
145 | } | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
151 | { | ||
152 | unsigned long quirks = id->driver_data; | ||
153 | int ret; | ||
154 | |||
155 | hid_set_drvdata(hdev, (void *)quirks); | ||
156 | |||
157 | if (quirks & MS_HIDINPUT) | ||
158 | hdev->quirks |= HID_QUIRK_HIDINPUT; | ||
159 | if (quirks & MS_NOGET) | ||
160 | hdev->quirks |= HID_QUIRK_NOGET; | ||
161 | |||
162 | ret = hid_parse(hdev); | ||
163 | if (ret) { | ||
164 | dev_err(&hdev->dev, "parse failed\n"); | ||
165 | goto err_free; | ||
166 | } | ||
167 | |||
168 | ret = hid_hw_start(hdev); | ||
169 | if (ret) { | ||
170 | dev_err(&hdev->dev, "hw start failed\n"); | ||
171 | goto err_free; | ||
172 | } | ||
173 | |||
174 | return 0; | ||
175 | err_free: | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | static const struct hid_device_id ms_devices[] = { | ||
180 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV), | ||
181 | .driver_data = MS_HIDINPUT }, | ||
182 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K), | ||
183 | .driver_data = MS_ERGONOMY }, | ||
184 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K), | ||
185 | .driver_data = MS_ERGONOMY | MS_RDESC }, | ||
186 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB), | ||
187 | .driver_data = MS_PRESENTER }, | ||
188 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0), | ||
189 | .driver_data = MS_NOGET }, | ||
190 | |||
191 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), | ||
192 | .driver_data = MS_PRESENTER }, | ||
193 | { } | ||
194 | }; | ||
195 | MODULE_DEVICE_TABLE(hid, ms_devices); | ||
196 | |||
197 | static struct hid_driver ms_driver = { | ||
198 | .name = "microsoft", | ||
199 | .id_table = ms_devices, | ||
200 | .report_fixup = ms_report_fixup, | ||
201 | .input_mapping = ms_input_mapping, | ||
202 | .event = ms_event, | ||
203 | .probe = ms_probe, | ||
204 | }; | ||
205 | |||
206 | static int ms_init(void) | ||
207 | { | ||
208 | return hid_register_driver(&ms_driver); | ||
209 | } | ||
210 | |||
211 | static void ms_exit(void) | ||
212 | { | ||
213 | hid_unregister_driver(&ms_driver); | ||
214 | } | ||
215 | |||
216 | module_init(ms_init); | ||
217 | module_exit(ms_exit); | ||
218 | MODULE_LICENSE("GPL"); | ||
219 | |||
220 | HID_COMPAT_LOAD_DRIVER(microsoft); | ||