Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Olivier Scherler | cb2c9e3 | 2013-07-27 19:20:02 +0200 | [diff] [blame] | 2 | /* |
| 3 | * HID driver for Xin-Mo devices, currently only the Dual Arcade controller. |
| 4 | * Fixes the negative axis event values (the devices sends -2) to match the |
| 5 | * logical axis minimum of the HID report descriptor (the report announces |
| 6 | * -1). It is needed because hid-input discards out of bounds values. |
| 7 | * (This module is based on "hid-saitek" and "hid-lg".) |
| 8 | * |
| 9 | * Copyright (c) 2013 Olivier Scherler |
| 10 | */ |
| 11 | |
| 12 | /* |
Olivier Scherler | cb2c9e3 | 2013-07-27 19:20:02 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/hid.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | |
| 20 | #include "hid-ids.h" |
| 21 | |
| 22 | /* |
| 23 | * Fix negative events that are out of bounds. |
| 24 | */ |
| 25 | static int xinmo_event(struct hid_device *hdev, struct hid_field *field, |
| 26 | struct hid_usage *usage, __s32 value) |
| 27 | { |
| 28 | switch (usage->code) { |
| 29 | case ABS_X: |
| 30 | case ABS_Y: |
| 31 | case ABS_Z: |
| 32 | case ABS_RX: |
| 33 | if (value < -1) { |
| 34 | input_event(field->hidinput->input, usage->type, |
| 35 | usage->code, -1); |
| 36 | return 1; |
| 37 | } |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static const struct hid_device_id xinmo_devices[] = { |
| 45 | { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) }, |
Peter Stein | 9257821 | 2017-02-17 00:00:50 -0800 | [diff] [blame] | 46 | { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) }, |
Olivier Scherler | cb2c9e3 | 2013-07-27 19:20:02 +0200 | [diff] [blame] | 47 | { } |
| 48 | }; |
| 49 | |
| 50 | MODULE_DEVICE_TABLE(hid, xinmo_devices); |
| 51 | |
| 52 | static struct hid_driver xinmo_driver = { |
| 53 | .name = "xinmo", |
| 54 | .id_table = xinmo_devices, |
| 55 | .event = xinmo_event |
| 56 | }; |
| 57 | |
Wei Yongjun | c0b20fd | 2013-08-23 11:06:19 +0800 | [diff] [blame] | 58 | module_hid_driver(xinmo_driver); |
Olivier Scherler | cb2c9e3 | 2013-07-27 19:20:02 +0200 | [diff] [blame] | 59 | MODULE_LICENSE("GPL"); |