18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * HID driver for Xin-Mo devices, currently only the Dual Arcade controller. 48c2ecf20Sopenharmony_ci * Fixes the negative axis event values (the devices sends -2) to match the 58c2ecf20Sopenharmony_ci * logical axis minimum of the HID report descriptor (the report announces 68c2ecf20Sopenharmony_ci * -1). It is needed because hid-input discards out of bounds values. 78c2ecf20Sopenharmony_ci * (This module is based on "hid-saitek" and "hid-lg".) 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (c) 2013 Olivier Scherler 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/device.h> 168c2ecf20Sopenharmony_ci#include <linux/hid.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/kernel.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include "hid-ids.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * Fix negative events that are out of bounds. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_cistatic int xinmo_event(struct hid_device *hdev, struct hid_field *field, 268c2ecf20Sopenharmony_ci struct hid_usage *usage, __s32 value) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci switch (usage->code) { 298c2ecf20Sopenharmony_ci case ABS_X: 308c2ecf20Sopenharmony_ci case ABS_Y: 318c2ecf20Sopenharmony_ci case ABS_Z: 328c2ecf20Sopenharmony_ci case ABS_RX: 338c2ecf20Sopenharmony_ci if (value < -1) { 348c2ecf20Sopenharmony_ci input_event(field->hidinput->input, usage->type, 358c2ecf20Sopenharmony_ci usage->code, -1); 368c2ecf20Sopenharmony_ci return 1; 378c2ecf20Sopenharmony_ci } 388c2ecf20Sopenharmony_ci break; 398c2ecf20Sopenharmony_ci } 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci return 0; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const struct hid_device_id xinmo_devices[] = { 458c2ecf20Sopenharmony_ci { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) }, 468c2ecf20Sopenharmony_ci { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_THT_2P_ARCADE) }, 478c2ecf20Sopenharmony_ci { } 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(hid, xinmo_devices); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic struct hid_driver xinmo_driver = { 538c2ecf20Sopenharmony_ci .name = "xinmo", 548c2ecf20Sopenharmony_ci .id_table = xinmo_devices, 558c2ecf20Sopenharmony_ci .event = xinmo_event 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cimodule_hid_driver(xinmo_driver); 598c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 60