18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  HID driver for Speedlink Vicious and Divine Cezanne (USB mouse).
48c2ecf20Sopenharmony_ci *  Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from
58c2ecf20Sopenharmony_ci *  the HID descriptor.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/device.h>
148c2ecf20Sopenharmony_ci#include <linux/hid.h>
158c2ecf20Sopenharmony_ci#include <linux/module.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "hid-ids.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic const struct hid_device_id speedlink_devices[] = {
208c2ecf20Sopenharmony_ci	{ HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE)},
218c2ecf20Sopenharmony_ci	{ }
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic int speedlink_input_mapping(struct hid_device *hdev,
258c2ecf20Sopenharmony_ci		struct hid_input *hi,
268c2ecf20Sopenharmony_ci		struct hid_field *field, struct hid_usage *usage,
278c2ecf20Sopenharmony_ci		unsigned long **bit, int *max)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	/*
308c2ecf20Sopenharmony_ci	 * The Cezanne mouse has a second "keyboard" USB endpoint for it is
318c2ecf20Sopenharmony_ci	 * able to map keyboard events to the button presses.
328c2ecf20Sopenharmony_ci	 * It sends a standard keyboard report descriptor, though, whose
338c2ecf20Sopenharmony_ci	 * LEDs we ignore.
348c2ecf20Sopenharmony_ci	 */
358c2ecf20Sopenharmony_ci	switch (usage->hid & HID_USAGE_PAGE) {
368c2ecf20Sopenharmony_ci	case HID_UP_LED:
378c2ecf20Sopenharmony_ci		return -1;
388c2ecf20Sopenharmony_ci	}
398c2ecf20Sopenharmony_ci	return 0;
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic int speedlink_event(struct hid_device *hdev, struct hid_field *field,
438c2ecf20Sopenharmony_ci		struct hid_usage *usage, __s32 value)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	/* No other conditions due to usage_table. */
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* This fixes the "jumpy" cursor occuring due to invalid events sent
488c2ecf20Sopenharmony_ci	 * by the device. Some devices only send them with value==+256, others
498c2ecf20Sopenharmony_ci	 * don't. However, catching abs(value)>=256 is restrictive enough not
508c2ecf20Sopenharmony_ci	 * to interfere with devices that were bug-free (has been tested).
518c2ecf20Sopenharmony_ci	 */
528c2ecf20Sopenharmony_ci	if (abs(value) >= 256)
538c2ecf20Sopenharmony_ci		return 1;
548c2ecf20Sopenharmony_ci	/* Drop useless distance 0 events (on button clicks etc.) as well */
558c2ecf20Sopenharmony_ci	if (value == 0)
568c2ecf20Sopenharmony_ci		return 1;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	return 0;
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, speedlink_devices);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic const struct hid_usage_id speedlink_grabbed_usages[] = {
648c2ecf20Sopenharmony_ci	{ HID_GD_X, EV_REL, 0 },
658c2ecf20Sopenharmony_ci	{ HID_GD_Y, EV_REL, 1 },
668c2ecf20Sopenharmony_ci	{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic struct hid_driver speedlink_driver = {
708c2ecf20Sopenharmony_ci	.name = "speedlink",
718c2ecf20Sopenharmony_ci	.id_table = speedlink_devices,
728c2ecf20Sopenharmony_ci	.usage_table = speedlink_grabbed_usages,
738c2ecf20Sopenharmony_ci	.input_mapping = speedlink_input_mapping,
748c2ecf20Sopenharmony_ci	.event = speedlink_event,
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_cimodule_hid_driver(speedlink_driver);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
79