Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  HID driver for Speedlink Vicious and Divine Cezanne (USB mouse).
0004  *  Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from
0005  *  the HID descriptor.
0006  *
0007  *  Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
0008  */
0009 
0010 /*
0011  */
0012 
0013 #include <linux/device.h>
0014 #include <linux/hid.h>
0015 #include <linux/module.h>
0016 
0017 #include "hid-ids.h"
0018 
0019 static const struct hid_device_id speedlink_devices[] = {
0020     { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE)},
0021     { }
0022 };
0023 
0024 static int speedlink_input_mapping(struct hid_device *hdev,
0025         struct hid_input *hi,
0026         struct hid_field *field, struct hid_usage *usage,
0027         unsigned long **bit, int *max)
0028 {
0029     /*
0030      * The Cezanne mouse has a second "keyboard" USB endpoint for it is
0031      * able to map keyboard events to the button presses.
0032      * It sends a standard keyboard report descriptor, though, whose
0033      * LEDs we ignore.
0034      */
0035     switch (usage->hid & HID_USAGE_PAGE) {
0036     case HID_UP_LED:
0037         return -1;
0038     }
0039     return 0;
0040 }
0041 
0042 static int speedlink_event(struct hid_device *hdev, struct hid_field *field,
0043         struct hid_usage *usage, __s32 value)
0044 {
0045     /* No other conditions due to usage_table. */
0046 
0047     /* This fixes the "jumpy" cursor occuring due to invalid events sent
0048      * by the device. Some devices only send them with value==+256, others
0049      * don't. However, catching abs(value)>=256 is restrictive enough not
0050      * to interfere with devices that were bug-free (has been tested).
0051      */
0052     if (abs(value) >= 256)
0053         return 1;
0054     /* Drop useless distance 0 events (on button clicks etc.) as well */
0055     if (value == 0)
0056         return 1;
0057 
0058     return 0;
0059 }
0060 
0061 MODULE_DEVICE_TABLE(hid, speedlink_devices);
0062 
0063 static const struct hid_usage_id speedlink_grabbed_usages[] = {
0064     { HID_GD_X, EV_REL, 0 },
0065     { HID_GD_Y, EV_REL, 1 },
0066     { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
0067 };
0068 
0069 static struct hid_driver speedlink_driver = {
0070     .name = "speedlink",
0071     .id_table = speedlink_devices,
0072     .usage_table = speedlink_grabbed_usages,
0073     .input_mapping = speedlink_input_mapping,
0074     .event = speedlink_event,
0075 };
0076 module_hid_driver(speedlink_driver);
0077 
0078 MODULE_LICENSE("GPL");