^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) * Force feedback support for DragonRise Inc. game controllers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * From what I have gathered, these devices are mass produced in China and are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * distributed under several vendors. They often share the same design as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * the original PlayStation DualShock controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 0079:0006 "DragonRise Inc. Generic USB Joystick "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * - tested with a Tesun USB-703 game controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2009 Richard Walmsley <richwalm@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #ifdef CONFIG_DRAGONRISE_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct drff_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int drff_play(struct input_dev *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct hid_device *hid = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct drff_device *drff = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int strong, weak;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) strong = effect->u.rumble.strong_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) weak = effect->u.rumble.weak_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) dbg_hid("called with 0x%04x 0x%04x", strong, weak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (strong || weak) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) strong = strong * 0xff / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) weak = weak * 0xff / 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* While reverse engineering this device, I found that when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) this value is set, it causes the strong rumble to function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) at a near maximum speed, so we'll bypass it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (weak == 0x0a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) weak = 0x0b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) drff->report->field[0]->value[0] = 0x51;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) drff->report->field[0]->value[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) drff->report->field[0]->value[2] = weak;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) drff->report->field[0]->value[4] = strong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) hid_hw_request(hid, drff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) drff->report->field[0]->value[0] = 0xfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) drff->report->field[0]->value[1] = 0xfe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) drff->report->field[0]->value[0] = 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) drff->report->field[0]->value[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) drff->report->field[0]->value[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) drff->report->field[0]->value[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) dbg_hid("running with 0x%02x 0x%02x", strong, weak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) hid_hw_request(hid, drff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static int drff_init(struct hid_device *hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct drff_device *drff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct hid_report *report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct list_head *report_list =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) &hid->report_enum[HID_OUTPUT_REPORT].report_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (list_empty(&hid->inputs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) hid_err(hid, "no inputs found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dev = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (list_empty(report_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) hid_err(hid, "no output reports found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) report = list_first_entry(report_list, struct hid_report, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (report->maxfield < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) hid_err(hid, "no fields in the report\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (report->field[0]->report_count < 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) hid_err(hid, "not enough values in the field\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) drff = kzalloc(sizeof(struct drff_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (!drff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) set_bit(FF_RUMBLE, dev->ffbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) error = input_ff_create_memless(dev, drff, drff_play);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) kfree(drff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) drff->report = report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) drff->report->field[0]->value[0] = 0xf3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) drff->report->field[0]->value[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) drff->report->field[0]->value[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) drff->report->field[0]->value[3] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) drff->report->field[0]->value[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) drff->report->field[0]->value[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) drff->report->field[0]->value[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) hid_hw_request(hid, drff->report, HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) hid_info(hid, "Force Feedback for DragonRise Inc. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) "game controllers by Richard Walmsley <richwalm@gmail.com>\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static inline int drff_init(struct hid_device *hid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * The original descriptor of joystick with PID 0x0011, represented by DVTech PC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * JS19. It seems both copied from another device and a result of confusion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * either about the specification or about the program used to create the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * descriptor. In any case, it's a wonder it works on Windows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Usage Page (Desktop), ; Generic desktop controls (01h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Usage (Joystick), ; Joystick (04h, application collection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Collection (Application),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * Collection (Logical),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * Report Size (8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * Report Count (5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * Logical Minimum (0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Logical Maximum (255),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * Physical Minimum (0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * Physical Maximum (255),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * Usage (X), ; X (30h, dynamic value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * Usage (X), ; X (30h, dynamic value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Usage (X), ; X (30h, dynamic value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Usage (X), ; X (30h, dynamic value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Usage (Y), ; Y (31h, dynamic value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * Input (Variable),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * Report Size (4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * Report Count (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Logical Maximum (7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Physical Maximum (315),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * Unit (Degrees),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Usage (00h),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * Input (Variable, Null State),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Report Size (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Report Count (10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Logical Maximum (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * Physical Maximum (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * Usage Page (Button), ; Button (09h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * Usage Minimum (01h),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Usage Maximum (0Ah),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * Input (Variable),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Usage Page (FF00h), ; FF00h, vendor-defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Report Size (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Report Count (10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * Logical Maximum (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * Physical Maximum (1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * Usage (01h),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Input (Variable),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * End Collection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Collection (Logical),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Report Size (8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * Report Count (4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Physical Maximum (255),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * Logical Maximum (255),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * Usage (02h),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Output (Variable),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * End Collection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * End Collection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Size of the original descriptor of the PID 0x0011 joystick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define PID0011_RDESC_ORIG_SIZE 101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* Fixed report descriptor for PID 0x011 joystick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static __u8 pid0011_rdesc_fixed[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 0x05, 0x01, /* Usage Page (Desktop), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 0x09, 0x04, /* Usage (Joystick), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 0xA1, 0x01, /* Collection (Application), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 0xA1, 0x02, /* Collection (Logical), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 0x14, /* Logical Minimum (0), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 0x75, 0x08, /* Report Size (8), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 0x95, 0x03, /* Report Count (3), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 0x81, 0x01, /* Input (Constant), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 0x95, 0x02, /* Report Count (2), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 0x09, 0x30, /* Usage (X), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 0x09, 0x31, /* Usage (Y), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 0x75, 0x01, /* Report Size (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 0x95, 0x04, /* Report Count (4), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 0x81, 0x01, /* Input (Constant), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 0x25, 0x01, /* Logical Maximum (1), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 0x95, 0x0A, /* Report Count (10), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 0x05, 0x09, /* Usage Page (Button), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 0x19, 0x01, /* Usage Minimum (01h), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 0x29, 0x0A, /* Usage Maximum (0Ah), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 0x81, 0x02, /* Input (Variable), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 0x95, 0x0A, /* Report Count (10), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 0x81, 0x01, /* Input (Constant), */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 0xC0, /* End Collection, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 0xC0 /* End Collection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) switch (hdev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case 0x0011:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (*rsize == PID0011_RDESC_ORIG_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) rdesc = pid0011_rdesc_fixed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *rsize = sizeof(pid0011_rdesc_fixed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define map_abs(c) hid_map_usage(hi, usage, bit, max, EV_ABS, (c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int dr_input_mapping(struct hid_device *hdev, struct hid_input *hi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct hid_field *field, struct hid_usage *usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned long **bit, int *max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) switch (usage->hid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * revert to the old hid-input behavior where axes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * can be randomly assigned when hid->usage is reused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (field->flags & HID_MAIN_ITEM_RELATIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) map_rel(usage->hid & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) map_abs(usage->hid & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dev_dbg(&hdev->dev, "DragonRise Inc. HID hardware probe...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) switch (hdev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case 0x0006:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret = drff_init(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) dev_err(&hdev->dev, "force feedback init failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static const struct hid_device_id dr_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) MODULE_DEVICE_TABLE(hid, dr_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static struct hid_driver dr_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .name = "dragonrise",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .id_table = dr_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .report_fixup = dr_report_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .probe = dr_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .input_mapping = dr_input_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) module_hid_driver(dr_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) MODULE_LICENSE("GPL");