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