Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  HID driver for Xin-Mo devices, currently only the Dual Arcade controller.
0004  *  Fixes the negative axis event values (the devices sends -2) to match the
0005  *  logical axis minimum of the HID report descriptor (the report announces
0006  *  -1). It is needed because hid-input discards out of bounds values.
0007  *  (This module is based on "hid-saitek" and "hid-lg".)
0008  *
0009  *  Copyright (c) 2013 Olivier Scherler
0010  */
0011 
0012 /*
0013  */
0014 
0015 #include <linux/device.h>
0016 #include <linux/hid.h>
0017 #include <linux/module.h>
0018 #include <linux/kernel.h>
0019 
0020 #include "hid-ids.h"
0021 
0022 /*
0023  * Fix negative events that are out of bounds.
0024  */
0025 static int xinmo_event(struct hid_device *hdev, struct hid_field *field,
0026         struct hid_usage *usage, __s32 value)
0027 {
0028     switch (usage->code) {
0029     case ABS_X:
0030     case ABS_Y:
0031     case ABS_Z:
0032     case ABS_RX:
0033         if (value < -1) {
0034             input_event(field->hidinput->input, usage->type,
0035                 usage->code, -1);
0036             return 1;
0037         }
0038         break;
0039     }
0040 
0041     return 0;
0042 }
0043 
0044 static const struct hid_device_id xinmo_devices[] = {
0045     { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
0046     { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) },
0047     { }
0048 };
0049 
0050 MODULE_DEVICE_TABLE(hid, xinmo_devices);
0051 
0052 static struct hid_driver xinmo_driver = {
0053     .name = "xinmo",
0054     .id_table = xinmo_devices,
0055     .event = xinmo_event
0056 };
0057 
0058 module_hid_driver(xinmo_driver);
0059 MODULE_LICENSE("GPL");