blob: 25b10dcad90d52c38dce6069397a1df19f13c8d0 [file] [log] [blame]
Jiri Slaby78a849a682008-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
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/*
Jiri Kosina0fb21de2009-01-14 03:03:21 +010033 * Microsoft Wireless Desktop Receiver (Model 1028) has
Jiri Slaby78a849a682008-06-20 21:26:11 +020034 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
35 */
36static 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
Jiri Kosina0fb21de2009-01-14 03:03:21 +010041 if ((quirks & MS_RDESC) && rsize == 571 && rdesc[557] == 0x19 &&
Jiri Slaby78a849a682008-06-20 21:26:11 +020042 rdesc[559] == 0x29) {
43 dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver "
44 "Model 1028 report descriptor\n");
Jiri Kosina0fb21de2009-01-14 03:03:21 +010045 rdesc[557] = 0x35;
46 rdesc[559] = 0x45;
Jiri Slaby78a849a682008-06-20 21:26:11 +020047 }
48}
49
50#define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
51 EV_KEY, (c))
52static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
53 unsigned long **bit, int *max)
54{
55 struct input_dev *input = hi->input;
56
57 switch (usage->hid & HID_USAGE) {
58 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
59 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
60 case 0xff05:
61 set_bit(EV_REP, input->evbit);
62 ms_map_key_clear(KEY_F13);
63 set_bit(KEY_F14, input->keybit);
64 set_bit(KEY_F15, input->keybit);
65 set_bit(KEY_F16, input->keybit);
66 set_bit(KEY_F17, input->keybit);
67 set_bit(KEY_F18, input->keybit);
68 default:
69 return 0;
70 }
71 return 1;
72}
73
74static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
75 unsigned long **bit, int *max)
76{
77 set_bit(EV_REP, hi->input->evbit);
78 switch (usage->hid & HID_USAGE) {
79 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
80 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
81 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
82 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
83 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
84 default:
85 return 0;
86 }
87 return 1;
88}
89
90static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
91 struct hid_field *field, struct hid_usage *usage,
92 unsigned long **bit, int *max)
93{
94 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
95
96 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
97 return 0;
98
99 if (quirks & MS_ERGONOMY) {
100 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
101 if (ret)
102 return ret;
103 }
104
105 if ((quirks & MS_PRESENTER) &&
106 ms_presenter_8k_quirk(hi, usage, bit, max))
107 return 1;
108
109 return 0;
110}
111
112static int ms_event(struct hid_device *hdev, struct hid_field *field,
113 struct hid_usage *usage, __s32 value)
114{
115 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
116
117 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
118 !usage->type)
119 return 0;
120
121 /* Handling MS keyboards special buttons */
122 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
123 struct input_dev *input = field->hidinput->input;
124 static unsigned int last_key = 0;
125 unsigned int key = 0;
126 switch (value) {
127 case 0x01: key = KEY_F14; break;
128 case 0x02: key = KEY_F15; break;
129 case 0x04: key = KEY_F16; break;
130 case 0x08: key = KEY_F17; break;
131 case 0x10: key = KEY_F18; break;
132 }
133 if (key) {
134 input_event(input, usage->type, key, 1);
135 last_key = key;
136 } else
137 input_event(input, usage->type, last_key, 0);
138
139 return 1;
140 }
141
142 return 0;
143}
144
145static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
146{
147 unsigned long quirks = id->driver_data;
148 int ret;
149
150 hid_set_drvdata(hdev, (void *)quirks);
151
Jiri Slaby78a849a682008-06-20 21:26:11 +0200152 if (quirks & MS_NOGET)
153 hdev->quirks |= HID_QUIRK_NOGET;
154
155 ret = hid_parse(hdev);
156 if (ret) {
157 dev_err(&hdev->dev, "parse failed\n");
158 goto err_free;
159 }
160
Jiri Slaby93c10132008-06-27 00:04:24 +0200161 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
162 HID_CONNECT_HIDINPUT_FORCE : 0));
Jiri Slaby78a849a682008-06-20 21:26:11 +0200163 if (ret) {
164 dev_err(&hdev->dev, "hw start failed\n");
165 goto err_free;
166 }
167
168 return 0;
169err_free:
170 return ret;
171}
172
173static const struct hid_device_id ms_devices[] = {
174 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
175 .driver_data = MS_HIDINPUT },
176 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
177 .driver_data = MS_ERGONOMY },
178 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
179 .driver_data = MS_ERGONOMY | MS_RDESC },
180 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
181 .driver_data = MS_PRESENTER },
182 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
183 .driver_data = MS_NOGET },
184
185 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
186 .driver_data = MS_PRESENTER },
187 { }
188};
189MODULE_DEVICE_TABLE(hid, ms_devices);
190
191static struct hid_driver ms_driver = {
192 .name = "microsoft",
193 .id_table = ms_devices,
194 .report_fixup = ms_report_fixup,
195 .input_mapping = ms_input_mapping,
196 .event = ms_event,
197 .probe = ms_probe,
198};
199
200static int ms_init(void)
201{
202 return hid_register_driver(&ms_driver);
203}
204
205static void ms_exit(void)
206{
207 hid_unregister_driver(&ms_driver);
208}
209
210module_init(ms_init);
211module_exit(ms_exit);
212MODULE_LICENSE("GPL");
213
214HID_COMPAT_LOAD_DRIVER(microsoft);