Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for Speedlink Vicious and Divine Cezanne (USB mouse). |
| 3 | * Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from |
| 4 | * the HID descriptor. |
| 5 | * |
Stefan Kriwanek | 06bb521 | 2013-08-25 10:46:13 +0200 | [diff] [blame^] | 6 | * Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de> |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/hid.h> |
| 18 | #include <linux/module.h> |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 19 | |
| 20 | #include "hid-ids.h" |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 21 | |
| 22 | static const struct hid_device_id speedlink_devices[] = { |
| 23 | { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE)}, |
| 24 | { } |
| 25 | }; |
| 26 | |
| 27 | static int speedlink_input_mapping(struct hid_device *hdev, |
| 28 | struct hid_input *hi, |
| 29 | struct hid_field *field, struct hid_usage *usage, |
| 30 | unsigned long **bit, int *max) |
| 31 | { |
| 32 | /* |
| 33 | * The Cezanne mouse has a second "keyboard" USB endpoint for it is |
| 34 | * able to map keyboard events to the button presses. |
| 35 | * It sends a standard keyboard report descriptor, though, whose |
| 36 | * LEDs we ignore. |
| 37 | */ |
| 38 | switch (usage->hid & HID_USAGE_PAGE) { |
| 39 | case HID_UP_LED: |
| 40 | return -1; |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int speedlink_event(struct hid_device *hdev, struct hid_field *field, |
| 46 | struct hid_usage *usage, __s32 value) |
| 47 | { |
| 48 | /* No other conditions due to usage_table. */ |
Stefan Kriwanek | 06bb521 | 2013-08-25 10:46:13 +0200 | [diff] [blame^] | 49 | |
| 50 | /* This fixes the "jumpy" cursor occuring due to invalid events sent |
| 51 | * by the device. Some devices only send them with value==+256, others |
| 52 | * don't. However, catching abs(value)>=256 is restrictive enough not |
| 53 | * to interfere with devices that were bug-free (has been tested). |
| 54 | */ |
| 55 | if (abs(value) >= 256) |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 56 | return 1; |
| 57 | /* Drop useless distance 0 events (on button clicks etc.) as well */ |
| 58 | if (value == 0) |
| 59 | return 1; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | MODULE_DEVICE_TABLE(hid, speedlink_devices); |
| 65 | |
| 66 | static const struct hid_usage_id speedlink_grabbed_usages[] = { |
| 67 | { HID_GD_X, EV_REL, 0 }, |
| 68 | { HID_GD_Y, EV_REL, 1 }, |
| 69 | { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} |
| 70 | }; |
| 71 | |
| 72 | static struct hid_driver speedlink_driver = { |
| 73 | .name = "speedlink", |
| 74 | .id_table = speedlink_devices, |
| 75 | .usage_table = speedlink_grabbed_usages, |
| 76 | .input_mapping = speedlink_input_mapping, |
| 77 | .event = speedlink_event, |
| 78 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 79 | module_hid_driver(speedlink_driver); |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 80 | |
Stefan Kriwanek | 74bc695 | 2011-05-27 18:40:29 +0200 | [diff] [blame] | 81 | MODULE_LICENSE("GPL"); |