hid-lg.c (da733563be5a9da26fe81d9f007262d00b846e22) hid-lg.c (8577dbf9d6eb07213caefb49e2017c177c5f023d)
1/*
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

--- 95 unchanged lines hidden (view full) ---

104/*
105 * Certain Logitech keyboards send in report #3 keys which are far
106 * above the logical maximum described in descriptor. This extends
107 * the original value of 0x28c of logical maximum to 0x104d
108 */
109static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
110 unsigned int *rsize)
111{
1/*
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

--- 95 unchanged lines hidden (view full) ---

104/*
105 * Certain Logitech keyboards send in report #3 keys which are far
106 * above the logical maximum described in descriptor. This extends
107 * the original value of 0x28c of logical maximum to 0x104d
108 */
109static __u8 *lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
110 unsigned int *rsize)
111{
112 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
112 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev);
113
113
114 if ((quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
114 if ((drv_data->quirks & LG_RDESC) && *rsize >= 90 && rdesc[83] == 0x26 &&
115 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
116 hid_info(hdev,
117 "fixing up Logitech keyboard report descriptor\n");
118 rdesc[84] = rdesc[89] = 0x4d;
119 rdesc[85] = rdesc[90] = 0x10;
120 }
115 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
116 hid_info(hdev,
117 "fixing up Logitech keyboard report descriptor\n");
118 rdesc[84] = rdesc[89] = 0x4d;
119 rdesc[85] = rdesc[90] = 0x10;
120 }
121 if ((quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
121 if ((drv_data->quirks & LG_RDESC_REL_ABS) && *rsize >= 50 &&
122 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
123 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
124 hid_info(hdev,
125 "fixing up rel/abs in Logitech report descriptor\n");
126 rdesc[33] = rdesc[50] = 0x02;
127 }
122 rdesc[32] == 0x81 && rdesc[33] == 0x06 &&
123 rdesc[49] == 0x81 && rdesc[50] == 0x06) {
124 hid_info(hdev,
125 "fixing up rel/abs in Logitech report descriptor\n");
126 rdesc[33] = rdesc[50] = 0x02;
127 }
128 if ((quirks & LG_FF4) && *rsize >= 101 &&
128 if ((drv_data->quirks & LG_FF4) && *rsize >= 101 &&
129 rdesc[41] == 0x95 && rdesc[42] == 0x0B &&
130 rdesc[47] == 0x05 && rdesc[48] == 0x09) {
131 hid_info(hdev, "fixing up Logitech Speed Force Wireless button descriptor\n");
132 rdesc[41] = 0x05;
133 rdesc[42] = 0x09;
134 rdesc[47] = 0x95;
135 rdesc[48] = 0x0B;
136 }

--- 136 unchanged lines hidden (view full) ---

273 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
274 174,167,152,161,112, 0, 0, 0,154, 0,
275 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
276 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 0, 0,183,184,185,186,187,
279 188,189,190,191,192,193,194, 0, 0, 0
280 };
129 rdesc[41] == 0x95 && rdesc[42] == 0x0B &&
130 rdesc[47] == 0x05 && rdesc[48] == 0x09) {
131 hid_info(hdev, "fixing up Logitech Speed Force Wireless button descriptor\n");
132 rdesc[41] = 0x05;
133 rdesc[42] = 0x09;
134 rdesc[47] = 0x95;
135 rdesc[48] = 0x0B;
136 }

--- 136 unchanged lines hidden (view full) ---

273 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
274 174,167,152,161,112, 0, 0, 0,154, 0,
275 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
276 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 0, 0,183,184,185,186,187,
279 188,189,190,191,192,193,194, 0, 0, 0
280 };
281 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
281 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev);
282 unsigned int hid = usage->hid;
283
284 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
285 lg_ultrax_remote_mapping(hi, usage, bit, max))
286 return 1;
287
288 if (hdev->product == USB_DEVICE_ID_DINOVO_MINI &&
289 lg_dinovo_mapping(hi, usage, bit, max))
290 return 1;
291
282 unsigned int hid = usage->hid;
283
284 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
285 lg_ultrax_remote_mapping(hi, usage, bit, max))
286 return 1;
287
288 if (hdev->product == USB_DEVICE_ID_DINOVO_MINI &&
289 lg_dinovo_mapping(hi, usage, bit, max))
290 return 1;
291
292 if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
292 if ((drv_data->quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
293 return 1;
294
295 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
296 return 0;
297
298 hid &= HID_USAGE;
299
300 /* Special handling for Logitech Cordless Desktop */
301 if (field->application == HID_GD_MOUSE) {
293 return 1;
294
295 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
296 return 0;
297
298 hid &= HID_USAGE;
299
300 /* Special handling for Logitech Cordless Desktop */
301 if (field->application == HID_GD_MOUSE) {
302 if ((quirks & LG_IGNORE_DOUBLED_WHEEL) &&
302 if ((drv_data->quirks & LG_IGNORE_DOUBLED_WHEEL) &&
303 (hid == 7 || hid == 8))
304 return -1;
305 } else {
303 (hid == 7 || hid == 8))
304 return -1;
305 } else {
306 if ((quirks & LG_EXPANDED_KEYMAP) &&
306 if ((drv_data->quirks & LG_EXPANDED_KEYMAP) &&
307 hid < ARRAY_SIZE(e_keymap) &&
308 e_keymap[hid] != 0) {
309 hid_map_usage(hi, usage, bit, max, EV_KEY,
310 e_keymap[hid]);
311 return 1;
312 }
313 }
314
315 return 0;
316}
317
318static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
319 struct hid_field *field, struct hid_usage *usage,
320 unsigned long **bit, int *max)
321{
307 hid < ARRAY_SIZE(e_keymap) &&
308 e_keymap[hid] != 0) {
309 hid_map_usage(hi, usage, bit, max, EV_KEY,
310 e_keymap[hid]);
311 return 1;
312 }
313 }
314
315 return 0;
316}
317
318static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
319 struct hid_field *field, struct hid_usage *usage,
320 unsigned long **bit, int *max)
321{
322 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
322 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev);
323
323
324 if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
324 if ((drv_data->quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
325 (field->flags & HID_MAIN_ITEM_RELATIVE))
326 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
327
325 (field->flags & HID_MAIN_ITEM_RELATIVE))
326 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
327
328 if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
328 if ((drv_data->quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
329 usage->type == EV_REL || usage->type == EV_ABS))
330 clear_bit(usage->code, *bit);
331
332 return 0;
333}
334
335static int lg_event(struct hid_device *hdev, struct hid_field *field,
336 struct hid_usage *usage, __s32 value)
337{
329 usage->type == EV_REL || usage->type == EV_ABS))
330 clear_bit(usage->code, *bit);
331
332 return 0;
333}
334
335static int lg_event(struct hid_device *hdev, struct hid_field *field,
336 struct hid_usage *usage, __s32 value)
337{
338 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
338 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev);
339
339
340 if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
340 if ((drv_data->quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
341 input_event(field->hidinput->input, usage->type, usage->code,
342 -value);
343 return 1;
344 }
345
346 return 0;
347}
348
349static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
350{
341 input_event(field->hidinput->input, usage->type, usage->code,
342 -value);
343 return 1;
344 }
345
346 return 0;
347}
348
349static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
350{
351 unsigned long quirks = id->driver_data;
352 unsigned int connect_mask = HID_CONNECT_DEFAULT;
351 unsigned int connect_mask = HID_CONNECT_DEFAULT;
352 struct lg_drv_data *drv_data;
353 int ret;
354
353 int ret;
354
355 hid_set_drvdata(hdev, (void *)quirks);
355 drv_data = kzalloc(sizeof(struct lg_drv_data), GFP_KERNEL);
356 if (!drv_data) {
357 hid_err(hdev, "Insufficient memory, cannot allocate driver data\n");
358 return -ENOMEM;
359 }
360 drv_data->quirks = id->driver_data;
361
362 hid_set_drvdata(hdev, (void *)drv_data);
356
363
357 if (quirks & LG_NOGET)
364 if (drv_data->quirks & LG_NOGET)
358 hdev->quirks |= HID_QUIRK_NOGET;
359
360 ret = hid_parse(hdev);
361 if (ret) {
362 hid_err(hdev, "parse failed\n");
363 goto err_free;
364 }
365
365 hdev->quirks |= HID_QUIRK_NOGET;
366
367 ret = hid_parse(hdev);
368 if (ret) {
369 hid_err(hdev, "parse failed\n");
370 goto err_free;
371 }
372
366 if (quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4))
373 if (drv_data->quirks & (LG_FF | LG_FF2 | LG_FF3 | LG_FF4))
367 connect_mask &= ~HID_CONNECT_FF;
368
369 ret = hid_hw_start(hdev, connect_mask);
370 if (ret) {
371 hid_err(hdev, "hw start failed\n");
372 goto err_free;
373 }
374

--- 12 unchanged lines hidden (view full) ---

387 /* Select random Address */
388 buf[1] = 0xB2;
389 get_random_bytes(&buf[2], 2);
390
391 ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
392 }
393 }
394
374 connect_mask &= ~HID_CONNECT_FF;
375
376 ret = hid_hw_start(hdev, connect_mask);
377 if (ret) {
378 hid_err(hdev, "hw start failed\n");
379 goto err_free;
380 }
381

--- 12 unchanged lines hidden (view full) ---

394 /* Select random Address */
395 buf[1] = 0xB2;
396 get_random_bytes(&buf[2], 2);
397
398 ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
399 }
400 }
401
395 if (quirks & LG_FF)
402 if (drv_data->quirks & LG_FF)
396 lgff_init(hdev);
403 lgff_init(hdev);
397 if (quirks & LG_FF2)
404 if (drv_data->quirks & LG_FF2)
398 lg2ff_init(hdev);
405 lg2ff_init(hdev);
399 if (quirks & LG_FF3)
406 if (drv_data->quirks & LG_FF3)
400 lg3ff_init(hdev);
407 lg3ff_init(hdev);
401 if (quirks & LG_FF4)
408 if (drv_data->quirks & LG_FF4)
402 lg4ff_init(hdev);
403
404 return 0;
405err_free:
409 lg4ff_init(hdev);
410
411 return 0;
412err_free:
413 kfree(drv_data);
406 return ret;
407}
408
409static void lg_remove(struct hid_device *hdev)
410{
414 return ret;
415}
416
417static void lg_remove(struct hid_device *hdev)
418{
411 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
412 if(quirks & LG_FF4)
419 struct lg_drv_data *drv_data = (struct lg_drv_data *)hid_get_drvdata(hdev);
420 if (drv_data->quirks & LG_FF4)
413 lg4ff_deinit(hdev);
414
415 hid_hw_stop(hdev);
421 lg4ff_deinit(hdev);
422
423 hid_hw_stop(hdev);
424 kfree(drv_data);
416}
417
418static const struct hid_device_id lg_devices[] = {
419 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
420 .driver_data = LG_RDESC | LG_WIRELESS },
421 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
422 .driver_data = LG_RDESC | LG_WIRELESS },
423 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),

--- 85 unchanged lines hidden ---
425}
426
427static const struct hid_device_id lg_devices[] = {
428 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
429 .driver_data = LG_RDESC | LG_WIRELESS },
430 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
431 .driver_data = LG_RDESC | LG_WIRELESS },
432 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),

--- 85 unchanged lines hidden ---