blob: e5c699b6c6f30656e8150a012eac160fccfd26e6 [file] [log] [blame]
Jiri Slaby78a849a2008-06-20 21:26:11 +02001/*
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
Ari Savolainen23c10be2011-07-11 21:42:52 +030026#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#define MS_DUPLICATE_USAGES 0x20
Jiri Slaby78a849a2008-06-20 21:26:11 +020032
33/*
Jiri Kosina0fb21de2009-01-14 03:03:21 +010034 * Microsoft Wireless Desktop Receiver (Model 1028) has
Jiri Slaby78a849a2008-06-20 21:26:11 +020035 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
36 */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040037static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
38 unsigned int *rsize)
Jiri Slaby78a849a2008-06-20 21:26:11 +020039{
40 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
41
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040042 if ((quirks & MS_RDESC) && *rsize == 571 && rdesc[557] == 0x19 &&
Jiri Slaby78a849a2008-06-20 21:26:11 +020043 rdesc[559] == 0x29) {
Joe Perches4291ee32010-12-09 19:29:03 -080044 hid_info(hdev, "fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
Jiri Kosina0fb21de2009-01-14 03:03:21 +010045 rdesc[557] = 0x35;
46 rdesc[559] = 0x45;
Jiri Slaby78a849a2008-06-20 21:26:11 +020047 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +040048 return rdesc;
Jiri Slaby78a849a2008-06-20 21:26:11 +020049}
50
51#define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
52 EV_KEY, (c))
53static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
54 unsigned long **bit, int *max)
55{
56 struct input_dev *input = hi->input;
57
58 switch (usage->hid & HID_USAGE) {
59 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
60 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
61 case 0xff05:
62 set_bit(EV_REP, input->evbit);
63 ms_map_key_clear(KEY_F13);
64 set_bit(KEY_F14, input->keybit);
65 set_bit(KEY_F15, input->keybit);
66 set_bit(KEY_F16, input->keybit);
67 set_bit(KEY_F17, input->keybit);
68 set_bit(KEY_F18, input->keybit);
69 default:
70 return 0;
71 }
72 return 1;
73}
74
75static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
76 unsigned long **bit, int *max)
77{
78 set_bit(EV_REP, hi->input->evbit);
79 switch (usage->hid & HID_USAGE) {
80 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
81 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
82 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
83 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
84 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
85 default:
86 return 0;
87 }
88 return 1;
89}
90
91static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
92 struct hid_field *field, struct hid_usage *usage,
93 unsigned long **bit, int *max)
94{
95 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
96
97 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
98 return 0;
99
100 if (quirks & MS_ERGONOMY) {
101 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
102 if (ret)
103 return ret;
104 }
105
106 if ((quirks & MS_PRESENTER) &&
107 ms_presenter_8k_quirk(hi, usage, bit, max))
108 return 1;
109
110 return 0;
111}
112
Ari Savolainen23c10be2011-07-11 21:42:52 +0300113static int ms_input_mapped(struct hid_device *hdev, struct hid_input *hi,
114 struct hid_field *field, struct hid_usage *usage,
115 unsigned long **bit, int *max)
116{
117 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
118
119 if (quirks & MS_DUPLICATE_USAGES)
120 clear_bit(usage->code, *bit);
121
122 return 0;
123}
124
Jiri Slaby78a849a2008-06-20 21:26:11 +0200125static int ms_event(struct hid_device *hdev, struct hid_field *field,
126 struct hid_usage *usage, __s32 value)
127{
128 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
129
130 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
131 !usage->type)
132 return 0;
133
134 /* Handling MS keyboards special buttons */
135 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
136 struct input_dev *input = field->hidinput->input;
137 static unsigned int last_key = 0;
138 unsigned int key = 0;
139 switch (value) {
140 case 0x01: key = KEY_F14; break;
141 case 0x02: key = KEY_F15; break;
142 case 0x04: key = KEY_F16; break;
143 case 0x08: key = KEY_F17; break;
144 case 0x10: key = KEY_F18; break;
145 }
146 if (key) {
147 input_event(input, usage->type, key, 1);
148 last_key = key;
149 } else
150 input_event(input, usage->type, last_key, 0);
151
152 return 1;
153 }
154
155 return 0;
156}
157
158static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
159{
160 unsigned long quirks = id->driver_data;
161 int ret;
162
163 hid_set_drvdata(hdev, (void *)quirks);
164
Jiri Slaby78a849a2008-06-20 21:26:11 +0200165 if (quirks & MS_NOGET)
166 hdev->quirks |= HID_QUIRK_NOGET;
167
168 ret = hid_parse(hdev);
169 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800170 hid_err(hdev, "parse failed\n");
Jiri Slaby78a849a2008-06-20 21:26:11 +0200171 goto err_free;
172 }
173
Jiri Slaby93c10132008-06-27 00:04:24 +0200174 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
175 HID_CONNECT_HIDINPUT_FORCE : 0));
Jiri Slaby78a849a2008-06-20 21:26:11 +0200176 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800177 hid_err(hdev, "hw start failed\n");
Jiri Slaby78a849a2008-06-20 21:26:11 +0200178 goto err_free;
179 }
180
181 return 0;
182err_free:
183 return ret;
184}
185
186static const struct hid_device_id ms_devices[] = {
187 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
188 .driver_data = MS_HIDINPUT },
189 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
190 .driver_data = MS_ERGONOMY },
191 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
192 .driver_data = MS_ERGONOMY | MS_RDESC },
193 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
194 .driver_data = MS_PRESENTER },
Jiri Kosinaf3b83d72011-06-13 23:08:18 +0300195 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K),
196 .driver_data = MS_ERGONOMY },
Jiri Slaby78a849a2008-06-20 21:26:11 +0200197 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
198 .driver_data = MS_NOGET },
Ari Savolainen23c10be2011-07-11 21:42:52 +0300199 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500),
200 .driver_data = MS_DUPLICATE_USAGES },
Jiri Slaby78a849a2008-06-20 21:26:11 +0200201
202 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
203 .driver_data = MS_PRESENTER },
204 { }
205};
206MODULE_DEVICE_TABLE(hid, ms_devices);
207
208static struct hid_driver ms_driver = {
209 .name = "microsoft",
210 .id_table = ms_devices,
211 .report_fixup = ms_report_fixup,
212 .input_mapping = ms_input_mapping,
Ari Savolainen23c10be2011-07-11 21:42:52 +0300213 .input_mapped = ms_input_mapped,
Jiri Slaby78a849a2008-06-20 21:26:11 +0200214 .event = ms_event,
215 .probe = ms_probe,
216};
217
Peter Huewea24f4232009-07-02 19:08:38 +0200218static int __init ms_init(void)
Jiri Slaby78a849a2008-06-20 21:26:11 +0200219{
220 return hid_register_driver(&ms_driver);
221}
222
Peter Huewea24f4232009-07-02 19:08:38 +0200223static void __exit ms_exit(void)
Jiri Slaby78a849a2008-06-20 21:26:11 +0200224{
225 hid_unregister_driver(&ms_driver);
226}
227
228module_init(ms_init);
229module_exit(ms_exit);
230MODULE_LICENSE("GPL");