blob: 8e28f1dc40a608313062794eea44022f3820cf26 [file] [log] [blame]
Jiri Slaby5f22a792008-05-16 11:49:19 +02001/*
2 * HID driver for some logitech "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/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
Jiri Slaby606bd0a2008-07-04 23:06:45 +020024#include "hid-lg.h"
Jiri Slaby5f22a792008-05-16 11:49:19 +020025
26#define LG_RDESC 0x001
27#define LG_BAD_RELATIVE_KEYS 0x002
28#define LG_DUPLICATE_USAGES 0x004
Jiri Slaby5f22a792008-05-16 11:49:19 +020029#define LG_EXPANDED_KEYMAP 0x010
30#define LG_IGNORE_DOUBLED_WHEEL 0x020
31#define LG_WIRELESS 0x040
32#define LG_INVERT_HWHEEL 0x080
33#define LG_NOGET 0x100
Jiri Slaby606bd0a2008-07-04 23:06:45 +020034#define LG_FF 0x200
35#define LG_FF2 0x400
Jiri Kosina24985cf2009-11-13 10:45:53 +010036#define LG_RDESC_REL_ABS 0x800
Jiri Slaby5f22a792008-05-16 11:49:19 +020037
38/*
39 * Certain Logitech keyboards send in report #3 keys which are far
40 * above the logical maximum described in descriptor. This extends
41 * the original value of 0x28c of logical maximum to 0x104d
42 */
43static void lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
44 unsigned int rsize)
45{
46 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
47
48 if ((quirks & LG_RDESC) && rsize >= 90 && rdesc[83] == 0x26 &&
49 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
50 dev_info(&hdev->dev, "fixing up Logitech keyboard report "
51 "descriptor\n");
52 rdesc[84] = rdesc[89] = 0x4d;
53 rdesc[85] = rdesc[90] = 0x10;
54 }
Jiri Kosina24985cf2009-11-13 10:45:53 +010055 if ((quirks & LG_RDESC_REL_ABS) && rsize >= 50 &&
56 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
57 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
58 dev_info(&hdev->dev, "fixing up rel/abs in Logitech "
59 "report descriptor\n");
60 rdesc[33] = rdesc[50] = 0x02;
61 }
Jiri Slaby5f22a792008-05-16 11:49:19 +020062}
63
64#define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
65 EV_KEY, (c))
66
67static int lg_ultrax_remote_mapping(struct hid_input *hi,
68 struct hid_usage *usage, unsigned long **bit, int *max)
69{
70 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
71 return 0;
72
73 set_bit(EV_REP, hi->input->evbit);
74 switch (usage->hid & HID_USAGE) {
75 /* Reported on Logitech Ultra X Media Remote */
76 case 0x004: lg_map_key_clear(KEY_AGAIN); break;
77 case 0x00d: lg_map_key_clear(KEY_HOME); break;
78 case 0x024: lg_map_key_clear(KEY_SHUFFLE); break;
79 case 0x025: lg_map_key_clear(KEY_TV); break;
80 case 0x026: lg_map_key_clear(KEY_MENU); break;
81 case 0x031: lg_map_key_clear(KEY_AUDIO); break;
82 case 0x032: lg_map_key_clear(KEY_TEXT); break;
83 case 0x033: lg_map_key_clear(KEY_LAST); break;
84 case 0x047: lg_map_key_clear(KEY_MP3); break;
85 case 0x048: lg_map_key_clear(KEY_DVD); break;
86 case 0x049: lg_map_key_clear(KEY_MEDIA); break;
87 case 0x04a: lg_map_key_clear(KEY_VIDEO); break;
88 case 0x04b: lg_map_key_clear(KEY_ANGLE); break;
89 case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break;
90 case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break;
91 case 0x051: lg_map_key_clear(KEY_RED); break;
92 case 0x052: lg_map_key_clear(KEY_CLOSE); break;
93
94 default:
95 return 0;
96 }
97 return 1;
98}
99
100static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage,
101 unsigned long **bit, int *max)
102{
103 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
104 return 0;
105
106 switch (usage->hid & HID_USAGE) {
107 case 0x1001: lg_map_key_clear(KEY_MESSENGER); break;
108 case 0x1003: lg_map_key_clear(KEY_SOUND); break;
109 case 0x1004: lg_map_key_clear(KEY_VIDEO); break;
110 case 0x1005: lg_map_key_clear(KEY_AUDIO); break;
111 case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break;
112 case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break;
113 case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break;
114 case 0x1013: lg_map_key_clear(KEY_CAMERA); break;
115 case 0x1014: lg_map_key_clear(KEY_MESSENGER); break;
116 case 0x1015: lg_map_key_clear(KEY_RECORD); break;
117 case 0x1016: lg_map_key_clear(KEY_PLAYER); break;
118 case 0x1017: lg_map_key_clear(KEY_EJECTCD); break;
119 case 0x1018: lg_map_key_clear(KEY_MEDIA); break;
120 case 0x1019: lg_map_key_clear(KEY_PROG1); break;
121 case 0x101a: lg_map_key_clear(KEY_PROG2); break;
122 case 0x101b: lg_map_key_clear(KEY_PROG3); break;
123 case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break;
124 case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break;
125 case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break;
126 case 0x1023: lg_map_key_clear(KEY_CLOSE); break;
127 case 0x1027: lg_map_key_clear(KEY_MENU); break;
128 /* this one is marked as 'Rotate' */
129 case 0x1028: lg_map_key_clear(KEY_ANGLE); break;
130 case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break;
131 case 0x102a: lg_map_key_clear(KEY_BACK); break;
132 case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
133 case 0x1041: lg_map_key_clear(KEY_BATTERY); break;
134 case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break;
135 case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break;
136 case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break;
137 case 0x1045: lg_map_key_clear(KEY_UNDO); break;
138 case 0x1046: lg_map_key_clear(KEY_REDO); break;
139 case 0x1047: lg_map_key_clear(KEY_PRINT); break;
140 case 0x1048: lg_map_key_clear(KEY_SAVE); break;
141 case 0x1049: lg_map_key_clear(KEY_PROG1); break;
142 case 0x104a: lg_map_key_clear(KEY_PROG2); break;
143 case 0x104b: lg_map_key_clear(KEY_PROG3); break;
144 case 0x104c: lg_map_key_clear(KEY_PROG4); break;
145
146 default:
147 return 0;
148 }
149 return 1;
150}
151
152static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
153 struct hid_field *field, struct hid_usage *usage,
154 unsigned long **bit, int *max)
155{
156 /* extended mapping for certain Logitech hardware (Logitech cordless
157 desktop LX500) */
158 static const u8 e_keymap[] = {
159 0,216, 0,213,175,156, 0, 0, 0, 0,
160 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
161 174,167,152,161,112, 0, 0, 0,154, 0,
162 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
165 0, 0, 0, 0, 0,183,184,185,186,187,
166 188,189,190,191,192,193,194, 0, 0, 0
167 };
168 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
169 unsigned int hid = usage->hid;
170
171 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
172 lg_ultrax_remote_mapping(hi, usage, bit, max))
173 return 1;
174
175 if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
176 return 1;
177
178 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
179 return 0;
180
181 hid &= HID_USAGE;
182
183 /* Special handling for Logitech Cordless Desktop */
184 if (field->application == HID_GD_MOUSE) {
185 if ((quirks & LG_IGNORE_DOUBLED_WHEEL) &&
186 (hid == 7 || hid == 8))
187 return -1;
188 } else {
189 if ((quirks & LG_EXPANDED_KEYMAP) &&
190 hid < ARRAY_SIZE(e_keymap) &&
191 e_keymap[hid] != 0) {
192 hid_map_usage(hi, usage, bit, max, EV_KEY,
193 e_keymap[hid]);
194 return 1;
195 }
196 }
197
198 return 0;
199}
200
201static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
202 struct hid_field *field, struct hid_usage *usage,
203 unsigned long **bit, int *max)
204{
205 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
206
207 if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
208 (field->flags & HID_MAIN_ITEM_RELATIVE))
209 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
210
211 if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
212 usage->type == EV_REL || usage->type == EV_ABS))
213 clear_bit(usage->code, *bit);
214
215 return 0;
216}
217
218static int lg_event(struct hid_device *hdev, struct hid_field *field,
219 struct hid_usage *usage, __s32 value)
220{
221 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
222
223 if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
224 input_event(field->hidinput->input, usage->type, usage->code,
225 -value);
226 return 1;
227 }
228
229 return 0;
230}
231
232static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
233{
234 unsigned long quirks = id->driver_data;
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200235 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Jiri Slaby5f22a792008-05-16 11:49:19 +0200236 int ret;
237
238 hid_set_drvdata(hdev, (void *)quirks);
239
Jiri Slaby5f22a792008-05-16 11:49:19 +0200240 if (quirks & LG_NOGET)
241 hdev->quirks |= HID_QUIRK_NOGET;
242
243 ret = hid_parse(hdev);
244 if (ret) {
245 dev_err(&hdev->dev, "parse failed\n");
246 goto err_free;
247 }
248
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200249 if (quirks & (LG_FF | LG_FF2))
250 connect_mask &= ~HID_CONNECT_FF;
251
252 ret = hid_hw_start(hdev, connect_mask);
Jiri Slaby5f22a792008-05-16 11:49:19 +0200253 if (ret) {
254 dev_err(&hdev->dev, "hw start failed\n");
255 goto err_free;
256 }
257
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200258 if (quirks & LG_FF)
259 lgff_init(hdev);
260 if (quirks & LG_FF2)
261 lg2ff_init(hdev);
262
Jiri Slaby5f22a792008-05-16 11:49:19 +0200263 return 0;
264err_free:
265 return ret;
266}
267
268static const struct hid_device_id lg_devices[] = {
269 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
270 .driver_data = LG_RDESC | LG_WIRELESS },
271 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
272 .driver_data = LG_RDESC | LG_WIRELESS },
273 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
274 .driver_data = LG_RDESC | LG_WIRELESS },
275
276 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
277 .driver_data = LG_BAD_RELATIVE_KEYS },
278
279 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP),
280 .driver_data = LG_DUPLICATE_USAGES },
281 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE),
282 .driver_data = LG_DUPLICATE_USAGES },
283 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI),
284 .driver_data = LG_DUPLICATE_USAGES },
285
Jiri Slaby5f22a792008-05-16 11:49:19 +0200286 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD),
287 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
288 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500),
289 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
290
Jiri Slaby5f22a792008-05-16 11:49:19 +0200291 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D),
292 .driver_data = LG_NOGET },
293 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL),
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200294 .driver_data = LG_NOGET | LG_FF },
295
296 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD),
297 .driver_data = LG_FF },
298 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2),
299 .driver_data = LG_FF },
300 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D),
301 .driver_data = LG_FF },
302 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO),
303 .driver_data = LG_FF },
304 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL),
305 .driver_data = LG_FF },
306 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2),
307 .driver_data = LG_FF },
Christophe Borivant243b7062009-04-17 11:39:39 +0200308 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL),
309 .driver_data = LG_FF },
Jiri Kosinafd30ea82009-06-23 12:11:31 +0200310 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ),
311 .driver_data = LG_FF },
Jiri Slaby606bd0a2008-07-04 23:06:45 +0200312 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
313 .driver_data = LG_FF2 },
Jiri Kosina24985cf2009-11-13 10:45:53 +0100314 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR),
315 .driver_data = LG_RDESC_REL_ABS },
316 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER),
317 .driver_data = LG_RDESC_REL_ABS },
Jiri Slaby5f22a792008-05-16 11:49:19 +0200318 { }
319};
Jiri Kosina24985cf2009-11-13 10:45:53 +0100320
Jiri Slaby5f22a792008-05-16 11:49:19 +0200321MODULE_DEVICE_TABLE(hid, lg_devices);
322
323static struct hid_driver lg_driver = {
324 .name = "logitech",
325 .id_table = lg_devices,
326 .report_fixup = lg_report_fixup,
327 .input_mapping = lg_input_mapping,
328 .input_mapped = lg_input_mapped,
329 .event = lg_event,
330 .probe = lg_probe,
331};
332
Peter Huewea24f4232009-07-02 19:08:38 +0200333static int __init lg_init(void)
Jiri Slaby5f22a792008-05-16 11:49:19 +0200334{
335 return hid_register_driver(&lg_driver);
336}
337
Peter Huewea24f4232009-07-02 19:08:38 +0200338static void __exit lg_exit(void)
Jiri Slaby5f22a792008-05-16 11:49:19 +0200339{
340 hid_unregister_driver(&lg_driver);
341}
342
343module_init(lg_init);
344module_exit(lg_exit);
345MODULE_LICENSE("GPL");