HID: move reset leds quirk
[linux-2.6/mini2440.git] / drivers / hid / hid-logitech.c
blobdf27f9aadf26a0b9bffef4da34ee3cb303e6ff72
1 /*
2 * HID driver for some logitech "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) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
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.
19 #include <linux/device.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
23 #include "hid-ids.h"
25 #define LG_RDESC 0x001
26 #define LG_BAD_RELATIVE_KEYS 0x002
27 #define LG_DUPLICATE_USAGES 0x004
28 #define LG_RESET_LEDS 0x008
29 #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
36 * Certain Logitech keyboards send in report #3 keys which are far
37 * above the logical maximum described in descriptor. This extends
38 * the original value of 0x28c of logical maximum to 0x104d
40 static void lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
41 unsigned int rsize)
43 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
45 if ((quirks & LG_RDESC) && rsize >= 90 && rdesc[83] == 0x26 &&
46 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
47 dev_info(&hdev->dev, "fixing up Logitech keyboard report "
48 "descriptor\n");
49 rdesc[84] = rdesc[89] = 0x4d;
50 rdesc[85] = rdesc[90] = 0x10;
54 #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
55 EV_KEY, (c))
57 static int lg_ultrax_remote_mapping(struct hid_input *hi,
58 struct hid_usage *usage, unsigned long **bit, int *max)
60 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
61 return 0;
63 set_bit(EV_REP, hi->input->evbit);
64 switch (usage->hid & HID_USAGE) {
65 /* Reported on Logitech Ultra X Media Remote */
66 case 0x004: lg_map_key_clear(KEY_AGAIN); break;
67 case 0x00d: lg_map_key_clear(KEY_HOME); break;
68 case 0x024: lg_map_key_clear(KEY_SHUFFLE); break;
69 case 0x025: lg_map_key_clear(KEY_TV); break;
70 case 0x026: lg_map_key_clear(KEY_MENU); break;
71 case 0x031: lg_map_key_clear(KEY_AUDIO); break;
72 case 0x032: lg_map_key_clear(KEY_TEXT); break;
73 case 0x033: lg_map_key_clear(KEY_LAST); break;
74 case 0x047: lg_map_key_clear(KEY_MP3); break;
75 case 0x048: lg_map_key_clear(KEY_DVD); break;
76 case 0x049: lg_map_key_clear(KEY_MEDIA); break;
77 case 0x04a: lg_map_key_clear(KEY_VIDEO); break;
78 case 0x04b: lg_map_key_clear(KEY_ANGLE); break;
79 case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break;
80 case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break;
81 case 0x051: lg_map_key_clear(KEY_RED); break;
82 case 0x052: lg_map_key_clear(KEY_CLOSE); break;
84 default:
85 return 0;
87 return 1;
90 static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage,
91 unsigned long **bit, int *max)
93 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
94 return 0;
96 switch (usage->hid & HID_USAGE) {
97 case 0x1001: lg_map_key_clear(KEY_MESSENGER); break;
98 case 0x1003: lg_map_key_clear(KEY_SOUND); break;
99 case 0x1004: lg_map_key_clear(KEY_VIDEO); break;
100 case 0x1005: lg_map_key_clear(KEY_AUDIO); break;
101 case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break;
102 case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break;
103 case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break;
104 case 0x1013: lg_map_key_clear(KEY_CAMERA); break;
105 case 0x1014: lg_map_key_clear(KEY_MESSENGER); break;
106 case 0x1015: lg_map_key_clear(KEY_RECORD); break;
107 case 0x1016: lg_map_key_clear(KEY_PLAYER); break;
108 case 0x1017: lg_map_key_clear(KEY_EJECTCD); break;
109 case 0x1018: lg_map_key_clear(KEY_MEDIA); break;
110 case 0x1019: lg_map_key_clear(KEY_PROG1); break;
111 case 0x101a: lg_map_key_clear(KEY_PROG2); break;
112 case 0x101b: lg_map_key_clear(KEY_PROG3); break;
113 case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break;
114 case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break;
115 case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break;
116 case 0x1023: lg_map_key_clear(KEY_CLOSE); break;
117 case 0x1027: lg_map_key_clear(KEY_MENU); break;
118 /* this one is marked as 'Rotate' */
119 case 0x1028: lg_map_key_clear(KEY_ANGLE); break;
120 case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break;
121 case 0x102a: lg_map_key_clear(KEY_BACK); break;
122 case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
123 case 0x1041: lg_map_key_clear(KEY_BATTERY); break;
124 case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break;
125 case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break;
126 case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break;
127 case 0x1045: lg_map_key_clear(KEY_UNDO); break;
128 case 0x1046: lg_map_key_clear(KEY_REDO); break;
129 case 0x1047: lg_map_key_clear(KEY_PRINT); break;
130 case 0x1048: lg_map_key_clear(KEY_SAVE); break;
131 case 0x1049: lg_map_key_clear(KEY_PROG1); break;
132 case 0x104a: lg_map_key_clear(KEY_PROG2); break;
133 case 0x104b: lg_map_key_clear(KEY_PROG3); break;
134 case 0x104c: lg_map_key_clear(KEY_PROG4); break;
136 default:
137 return 0;
139 return 1;
142 static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
143 struct hid_field *field, struct hid_usage *usage,
144 unsigned long **bit, int *max)
146 /* extended mapping for certain Logitech hardware (Logitech cordless
147 desktop LX500) */
148 static const u8 e_keymap[] = {
149 0,216, 0,213,175,156, 0, 0, 0, 0,
150 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
151 174,167,152,161,112, 0, 0, 0,154, 0,
152 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
154 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
155 0, 0, 0, 0, 0,183,184,185,186,187,
156 188,189,190,191,192,193,194, 0, 0, 0
158 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
159 unsigned int hid = usage->hid;
161 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
162 lg_ultrax_remote_mapping(hi, usage, bit, max))
163 return 1;
165 if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
166 return 1;
168 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
169 return 0;
171 hid &= HID_USAGE;
173 /* Special handling for Logitech Cordless Desktop */
174 if (field->application == HID_GD_MOUSE) {
175 if ((quirks & LG_IGNORE_DOUBLED_WHEEL) &&
176 (hid == 7 || hid == 8))
177 return -1;
178 } else {
179 if ((quirks & LG_EXPANDED_KEYMAP) &&
180 hid < ARRAY_SIZE(e_keymap) &&
181 e_keymap[hid] != 0) {
182 hid_map_usage(hi, usage, bit, max, EV_KEY,
183 e_keymap[hid]);
184 return 1;
188 return 0;
191 static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
192 struct hid_field *field, struct hid_usage *usage,
193 unsigned long **bit, int *max)
195 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
197 if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
198 (field->flags & HID_MAIN_ITEM_RELATIVE))
199 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
201 if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
202 usage->type == EV_REL || usage->type == EV_ABS))
203 clear_bit(usage->code, *bit);
205 return 0;
208 static int lg_event(struct hid_device *hdev, struct hid_field *field,
209 struct hid_usage *usage, __s32 value)
211 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
213 if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
214 input_event(field->hidinput->input, usage->type, usage->code,
215 -value);
216 return 1;
219 return 0;
222 static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
224 unsigned long quirks = id->driver_data;
225 int ret;
227 hid_set_drvdata(hdev, (void *)quirks);
229 if (quirks & LG_NOGET)
230 hdev->quirks |= HID_QUIRK_NOGET;
232 ret = hid_parse(hdev);
233 if (ret) {
234 dev_err(&hdev->dev, "parse failed\n");
235 goto err_free;
238 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
239 if (ret) {
240 dev_err(&hdev->dev, "hw start failed\n");
241 goto err_free;
244 if (quirks & LG_RESET_LEDS)
245 usbhid_set_leds(hdev);
247 return 0;
248 err_free:
249 return ret;
252 static const struct hid_device_id lg_devices[] = {
253 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
254 .driver_data = LG_RDESC | LG_WIRELESS },
255 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
256 .driver_data = LG_RDESC | LG_WIRELESS },
257 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
258 .driver_data = LG_RDESC | LG_WIRELESS },
260 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
261 .driver_data = LG_BAD_RELATIVE_KEYS },
263 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP),
264 .driver_data = LG_DUPLICATE_USAGES },
265 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE),
266 .driver_data = LG_DUPLICATE_USAGES },
267 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI),
268 .driver_data = LG_DUPLICATE_USAGES },
270 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD),
271 .driver_data = LG_RESET_LEDS },
273 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD),
274 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
275 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500),
276 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
278 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3),
279 .driver_data = LG_INVERT_HWHEEL },
280 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150),
281 .driver_data = LG_INVERT_HWHEEL },
283 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D),
284 .driver_data = LG_NOGET },
285 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL),
286 .driver_data = LG_NOGET },
289 MODULE_DEVICE_TABLE(hid, lg_devices);
291 static struct hid_driver lg_driver = {
292 .name = "logitech",
293 .id_table = lg_devices,
294 .report_fixup = lg_report_fixup,
295 .input_mapping = lg_input_mapping,
296 .input_mapped = lg_input_mapped,
297 .event = lg_event,
298 .probe = lg_probe,
301 static int lg_init(void)
303 return hid_register_driver(&lg_driver);
306 static void lg_exit(void)
308 hid_unregister_driver(&lg_driver);
311 module_init(lg_init);
312 module_exit(lg_exit);
313 MODULE_LICENSE("GPL");
315 HID_COMPAT_LOAD_DRIVER(logitech);