Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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