mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / hid / hid-microsoft.c
blob8dfc58ac9d52c2a6ba570f03003c38378933e7ec
1 /*
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
9 */
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)
15 * any later version.
18 #include <linux/device.h>
19 #include <linux/input.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
23 #include "hid-ids.h"
25 #define MS_HIDINPUT 0x01
26 #define MS_ERGONOMY 0x02
27 #define MS_PRESENTER 0x04
28 #define MS_RDESC 0x08
29 #define MS_NOGET 0x10
30 #define MS_DUPLICATE_USAGES 0x20
31 #define MS_RDESC_3K 0x40
33 static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
34 unsigned int *rsize)
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 &&
43 rdesc[559] == 0x29) {
44 hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
45 rdesc[557] = 0x35;
46 rdesc[559] = 0x45;
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 &&
51 rdesc[97] == 0xff) {
52 rdesc[94] = 0x35;
53 rdesc[96] = 0x45;
55 return rdesc;
58 #define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
59 EV_KEY, (c))
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 switch (usage->hid & HID_USAGE) {
66 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
67 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
68 case 0xff00:
69 /* Special keypad keys */
70 ms_map_key_clear(KEY_KPEQUAL);
71 set_bit(KEY_KPLEFTPAREN, input->keybit);
72 set_bit(KEY_KPRIGHTPAREN, input->keybit);
73 break;
74 case 0xff01:
75 /* Scroll wheel */
76 hid_map_usage_clear(hi, usage, bit, max, EV_REL, REL_WHEEL);
77 break;
78 case 0xff02:
80 * This byte contains a copy of the modifier keys byte of a
81 * standard hid keyboard report, as send by interface 0
82 * (this usage is found on interface 1).
84 * This byte only gets send when another key in the same report
85 * changes state, and as such is useless, ignore it.
87 return -1;
88 case 0xff05:
89 set_bit(EV_REP, input->evbit);
90 ms_map_key_clear(KEY_F13);
91 set_bit(KEY_F14, input->keybit);
92 set_bit(KEY_F15, input->keybit);
93 set_bit(KEY_F16, input->keybit);
94 set_bit(KEY_F17, input->keybit);
95 set_bit(KEY_F18, input->keybit);
96 default:
97 return 0;
99 return 1;
102 static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
103 unsigned long **bit, int *max)
105 set_bit(EV_REP, hi->input->evbit);
106 switch (usage->hid & HID_USAGE) {
107 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
108 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
109 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
110 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
111 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
112 default:
113 return 0;
115 return 1;
118 static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
119 struct hid_field *field, struct hid_usage *usage,
120 unsigned long **bit, int *max)
122 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
124 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
125 return 0;
127 if (quirks & MS_ERGONOMY) {
128 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
129 if (ret)
130 return ret;
133 if ((quirks & MS_PRESENTER) &&
134 ms_presenter_8k_quirk(hi, usage, bit, max))
135 return 1;
137 return 0;
140 static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi,
141 struct hid_field *field, struct hid_usage *usage,
142 unsigned long **bit, int *max)
144 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
146 if (quirks & MS_DUPLICATE_USAGES)
147 clear_bit(usage->code, *bit);
149 return 0;
152 static int ms_event(struct hid_device *hdev, struct hid_field *field,
153 struct hid_usage *usage, __s32 value)
155 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
156 struct input_dev *input;
158 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
159 !usage->type)
160 return 0;
162 input = field->hidinput->input;
164 /* Handling MS keyboards special buttons */
165 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff00)) {
166 /* Special keypad keys */
167 input_report_key(input, KEY_KPEQUAL, value & 0x01);
168 input_report_key(input, KEY_KPLEFTPAREN, value & 0x02);
169 input_report_key(input, KEY_KPRIGHTPAREN, value & 0x04);
170 return 1;
173 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff01)) {
174 /* Scroll wheel */
175 int step = ((value & 0x60) >> 5) + 1;
177 switch (value & 0x1f) {
178 case 0x01:
179 input_report_rel(input, REL_WHEEL, step);
180 break;
181 case 0x1f:
182 input_report_rel(input, REL_WHEEL, -step);
183 break;
185 return 1;
188 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
189 static unsigned int last_key = 0;
190 unsigned int key = 0;
191 switch (value) {
192 case 0x01: key = KEY_F14; break;
193 case 0x02: key = KEY_F15; break;
194 case 0x04: key = KEY_F16; break;
195 case 0x08: key = KEY_F17; break;
196 case 0x10: key = KEY_F18; break;
198 if (key) {
199 input_event(input, usage->type, key, 1);
200 last_key = key;
201 } else
202 input_event(input, usage->type, last_key, 0);
204 return 1;
207 return 0;
210 static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
212 unsigned long quirks = id->driver_data;
213 int ret;
215 hid_set_drvdata(hdev, (void *)quirks);
217 if (quirks & MS_NOGET)
218 hdev->quirks |= HID_QUIRK_NOGET;
220 ret = hid_parse(hdev);
221 if (ret) {
222 hid_err(hdev, "parse failed\n");
223 goto err_free;
226 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
227 HID_CONNECT_HIDINPUT_FORCE : 0));
228 if (ret) {
229 hid_err(hdev, "hw start failed\n");
230 goto err_free;
233 return 0;
234 err_free:
235 return ret;
238 static const struct hid_device_id ms_devices[] = {
239 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
240 .driver_data = MS_HIDINPUT },
241 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB),
242 .driver_data = MS_ERGONOMY },
243 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
244 .driver_data = MS_ERGONOMY },
245 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP),
246 .driver_data = MS_ERGONOMY },
247 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE7K),
248 .driver_data = MS_ERGONOMY },
249 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
250 .driver_data = MS_ERGONOMY | MS_RDESC },
251 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
252 .driver_data = MS_PRESENTER },
253 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K),
254 .driver_data = MS_ERGONOMY | MS_RDESC_3K },
255 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K),
256 .driver_data = MS_ERGONOMY },
257 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600),
258 .driver_data = MS_ERGONOMY },
259 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3KV1),
260 .driver_data = MS_ERGONOMY },
261 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
262 .driver_data = MS_NOGET },
263 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
264 .driver_data = MS_DUPLICATE_USAGES },
265 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3),
266 .driver_data = MS_HIDINPUT },
267 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_2),
268 .driver_data = MS_HIDINPUT },
269 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_PRO_3_JP),
270 .driver_data = MS_HIDINPUT },
271 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3),
272 .driver_data = MS_HIDINPUT },
273 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_POWER_COVER),
274 .driver_data = MS_HIDINPUT },
275 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD),
276 .driver_data = MS_ERGONOMY},
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 = {
285 .name = "microsoft",
286 .id_table = ms_devices,
287 .report_fixup = ms_report_fixup,
288 .input_mapping = ms_input_mapping,
289 .input_mapped = ms_input_mapped,
290 .event = ms_event,
291 .probe = ms_probe,
293 module_hid_driver(ms_driver);
295 MODULE_LICENSE("GPL");