blob: 2b03c9baac35c273b956da0e1300c3cc4429c889 [file] [log] [blame]
Stefan Kriwanek74bc6952011-05-27 18:40:29 +02001/*
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 Kriwanek785b05f2013-08-25 10:46:13 +02006 * Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
Stefan Kriwanek74bc6952011-05-27 18:40:29 +02007 */
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>
19#include <linux/usb.h>
20
21#include "hid-ids.h"
22#include "usbhid/usbhid.h"
23
24static const struct hid_device_id speedlink_devices[] = {
25 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE)},
26 { }
27};
28
29static int speedlink_input_mapping(struct hid_device *hdev,
30 struct hid_input *hi,
31 struct hid_field *field, struct hid_usage *usage,
32 unsigned long **bit, int *max)
33{
34 /*
35 * The Cezanne mouse has a second "keyboard" USB endpoint for it is
36 * able to map keyboard events to the button presses.
37 * It sends a standard keyboard report descriptor, though, whose
38 * LEDs we ignore.
39 */
40 switch (usage->hid & HID_USAGE_PAGE) {
41 case HID_UP_LED:
42 return -1;
43 }
44 return 0;
45}
46
47static int speedlink_event(struct hid_device *hdev, struct hid_field *field,
48 struct hid_usage *usage, __s32 value)
49{
50 /* No other conditions due to usage_table. */
Stefan Kriwanek785b05f2013-08-25 10:46:13 +020051
52 /* This fixes the "jumpy" cursor occuring due to invalid events sent
53 * by the device. Some devices only send them with value==+256, others
54 * don't. However, catching abs(value)>=256 is restrictive enough not
55 * to interfere with devices that were bug-free (has been tested).
56 */
57 if (abs(value) >= 256)
Stefan Kriwanek74bc6952011-05-27 18:40:29 +020058 return 1;
59 /* Drop useless distance 0 events (on button clicks etc.) as well */
60 if (value == 0)
61 return 1;
62
63 return 0;
64}
65
66MODULE_DEVICE_TABLE(hid, speedlink_devices);
67
68static const struct hid_usage_id speedlink_grabbed_usages[] = {
69 { HID_GD_X, EV_REL, 0 },
70 { HID_GD_Y, EV_REL, 1 },
71 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
72};
73
74static struct hid_driver speedlink_driver = {
75 .name = "speedlink",
76 .id_table = speedlink_devices,
77 .usage_table = speedlink_grabbed_usages,
78 .input_mapping = speedlink_input_mapping,
79 .event = speedlink_event,
80};
81
82static int __init speedlink_init(void)
83{
84 return hid_register_driver(&speedlink_driver);
85}
86
87static void __exit speedlink_exit(void)
88{
89 hid_unregister_driver(&speedlink_driver);
90}
91
92module_init(speedlink_init);
93module_exit(speedlink_exit);
94MODULE_LICENSE("GPL");