summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-tmff.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-10-02 12:17:24 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-10-02 12:17:24 -0700
commit3f1fe48a36b0b6722dc3fd421d93512bac138e9a (patch)
treeb767d7f6e26bc64334d3f14f8422d187239dc45d /drivers/hid/hid-tmff.c
downloadlinux-stable-3f1fe48a36b0b6722dc3fd421d93512bac138e9a.tar.gz
linux-stable-3f1fe48a36b0b6722dc3fd421d93512bac138e9a.zip
Merge tag 'io_uring-7.3-20261002' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linuxgrafted
Pull io_uring fixes from Jens Axboe: - Fix a task_work add use-after-free with SQPOLL. The sqpoll thread could pop and complete the last request while io_req_normal_work_add() was still looking at them after the mpscq push. Use the same approach as DEFER_TASKRUN to protect from that, holding an RCU read lock across the add, and have exit wait for an RCU grace period for SQPOLL rings as well. - CQE32 ring fixes: correct the free entry check for 32b CQEs, zero the big_cqe for aux CQEs, and only post the dummy skip CQE on CQE_MIXED rings - Mark the source filter table as COW when cloning bpf filters, so registering another filter on the source doesn't modify the shared table in place - Initialize the task context before running the BPF loop - Requeue zcrx multishot receives stopped by a local resource - End a TX_TIMESTAMP multishot cmd when the CQ is full (lollipopkit) * tag 'io_uring-7.3-20261002' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: io_uring: fix task_work add use-after-free with SQPOLL io_uring/cmd_net: end TX_TIMESTAMP multishot when the CQ is full io_uring/zcrx: requeue multishot receives stopped by a local resource io_uring: initialize task context before running the BPF loop io_uring: zero big_cqe for aux CQEs on CQE32 rings io_uring: fix free entry check for 32b CQEs on CQE32 rings io_uring: only post the dummy skip CQE on CQE_MIXED rings io_uring/bpf_filter: mark source as COW when cloning filters
Diffstat (limited to 'drivers/hid/hid-tmff.c')
-rw-r--r--drivers/hid/hid-tmff.c251
1 files changed, 251 insertions, 0 deletions
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
new file mode 100644
index 000000000..303769b07
--- /dev/null
+++ b/drivers/hid/hid-tmff.c
@@ -0,0 +1,251 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Force feedback support for various HID compliant devices by ThrustMaster:
+ * ThrustMaster FireStorm Dual Power 2
+ * and possibly others whose device ids haven't been added.
+ *
+ * Modified to support ThrustMaster devices by Zinx Verituse
+ * on 2003-01-25 from the Logitech force feedback driver,
+ * which is by Johann Deneux.
+ *
+ * Copyright (c) 2003 Zinx Verituse <zinx@epicsol.org>
+ * Copyright (c) 2002 Johann Deneux
+ */
+
+/*
+ */
+
+#include <linux/hid.h>
+#include <linux/input.h>
+#include <linux/math64.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+
+#include "hid-ids.h"
+
+#define THRUSTMASTER_DEVICE_ID_2_IN_1_DT 0xb320
+
+static const signed short ff_rumble[] = {
+ FF_RUMBLE,
+ -1
+};
+
+static const signed short ff_joystick[] = {
+ FF_CONSTANT,
+ -1
+};
+
+#ifdef CONFIG_THRUSTMASTER_FF
+
+/* Usages for thrustmaster devices I know about */
+#define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb)
+
+struct tmff_device {
+ struct hid_report *report;
+ struct hid_field *ff_field;
+};
+
+/* Changes values from 0 to 0xffff into values from minimum to maximum */
+static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum)
+{
+ s64 ret;
+
+ ret = div_s64((s64)in * ((s64)maximum - minimum), 0xffff) + minimum;
+ if (ret < minimum)
+ return minimum;
+ if (ret > maximum)
+ return maximum;
+ return ret;
+}
+
+/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
+static inline int tmff_scale_s8(int in, int minimum, int maximum)
+{
+ s64 ret;
+
+ ret = div_s64((s64)(in + 0x80) * ((s64)maximum - minimum), 0xff) + minimum;
+ if (ret < minimum)
+ return minimum;
+ if (ret > maximum)
+ return maximum;
+ return ret;
+}
+
+static int tmff_play(struct input_dev *dev, void *data,
+ struct ff_effect *effect)
+{
+ struct hid_device *hid = input_get_drvdata(dev);
+ struct tmff_device *tmff = data;
+ struct hid_field *ff_field = tmff->ff_field;
+ int x, y;
+ int left, right; /* Rumbling */
+
+ switch (effect->type) {
+ case FF_CONSTANT:
+ x = tmff_scale_s8(effect->u.ramp.start_level,
+ ff_field->logical_minimum,
+ ff_field->logical_maximum);
+ y = tmff_scale_s8(effect->u.ramp.end_level,
+ ff_field->logical_minimum,
+ ff_field->logical_maximum);
+
+ dbg_hid("(x, y)=(%04x, %04x)\n", x, y);
+ ff_field->value[0] = x;
+ ff_field->value[1] = y;
+ hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
+ break;
+
+ case FF_RUMBLE:
+ left = tmff_scale_u16(effect->u.rumble.weak_magnitude,
+ ff_field->logical_minimum,
+ ff_field->logical_maximum);
+ right = tmff_scale_u16(effect->u.rumble.strong_magnitude,
+ ff_field->logical_minimum,
+ ff_field->logical_maximum);
+
+ /* 2-in-1 strong motor is left */
+ if (hid->product == THRUSTMASTER_DEVICE_ID_2_IN_1_DT)
+ swap(left, right);
+
+ dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
+ ff_field->value[0] = left;
+ ff_field->value[1] = right;
+ hid_hw_request(hid, tmff->report, HID_REQ_SET_REPORT);
+ break;
+ }
+ return 0;
+}
+
+static int tm_input_configured(struct hid_device *hid, struct hid_input *hidinput)
+{
+ struct tmff_device *tmff;
+ struct hid_report *report;
+ struct list_head *report_list;
+ struct input_dev *input_dev = hidinput->input;
+ const struct hid_device_id *id;
+ const signed short *ff_bits;
+ int error;
+ int i;
+
+ if (!list_is_first(&hidinput->list, &hid->inputs))
+ return 0;
+
+ id = hid_match_device(hid, hid->driver);
+ if (!id)
+ return -ENODEV;
+
+ ff_bits = (void *)id->driver_data;
+
+ tmff = kzalloc_obj(struct tmff_device);
+ if (!tmff)
+ return -ENOMEM;
+
+ /* Find the report to use */
+ report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
+ list_for_each_entry(report, report_list, list) {
+ int fieldnum;
+
+ for (fieldnum = 0; fieldnum < report->maxfield; ++fieldnum) {
+ struct hid_field *field = report->field[fieldnum];
+
+ if (field->maxusage <= 0)
+ continue;
+
+ switch (field->usage[0].hid) {
+ case THRUSTMASTER_USAGE_FF:
+ if (field->report_count < 2) {
+ hid_warn(hid, "ignoring FF field with report_count < 2\n");
+ continue;
+ }
+
+ if (field->logical_maximum ==
+ field->logical_minimum) {
+ hid_warn(hid, "ignoring FF field with logical_maximum == logical_minimum\n");
+ continue;
+ }
+
+ if (tmff->report && tmff->report != report) {
+ hid_warn(hid, "ignoring FF field in other report\n");
+ continue;
+ }
+
+ if (tmff->ff_field && tmff->ff_field != field) {
+ hid_warn(hid, "ignoring duplicate FF field\n");
+ continue;
+ }
+
+ tmff->report = report;
+ tmff->ff_field = field;
+
+ for (i = 0; ff_bits[i] >= 0; i++)
+ set_bit(ff_bits[i], input_dev->ffbit);
+
+ break;
+
+ default:
+ hid_warn(hid, "ignoring unknown output usage %08x\n",
+ field->usage[0].hid);
+ continue;
+ }
+ }
+ }
+
+ if (!tmff->report) {
+ hid_err(hid, "can't find FF field in output reports\n");
+ error = -ENODEV;
+ goto fail;
+ }
+
+ error = input_ff_create_memless(input_dev, tmff, tmff_play);
+ if (error)
+ goto fail;
+
+ hid_info(hid, "force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>\n");
+ return 0;
+
+fail:
+ kfree(tmff);
+ return error;
+}
+#else
+static inline int tm_input_configured(struct hid_device *hid,
+ struct hid_input *hidinput)
+{
+ return 0;
+}
+#endif
+
+static const struct hid_device_id tm_devices[] = {
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300),
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304), /* FireStorm Dual Power 2 (and 3) */
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, THRUSTMASTER_DEVICE_ID_2_IN_1_DT), /* Dual Trigger 2-in-1 */
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323), /* Dual Trigger 3-in-1 (PC Mode) */
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324), /* Dual Trigger 3-in-1 (PS3 Mode) */
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605), /* NASCAR PRO FF2 Wheel */
+ .driver_data = (unsigned long)ff_joystick },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651), /* FGT Rumble Force Wheel */
+ .driver_data = (unsigned long)ff_rumble },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653), /* RGT Force Feedback CLUTCH Raging Wheel */
+ .driver_data = (unsigned long)ff_joystick },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */
+ .driver_data = (unsigned long)ff_joystick },
+ { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a), /* F430 Force Feedback Wheel */
+ .driver_data = (unsigned long)ff_joystick },
+ { }
+};
+MODULE_DEVICE_TABLE(hid, tm_devices);
+
+static struct hid_driver tm_driver = {
+ .name = "thrustmaster",
+ .id_table = tm_devices,
+ .input_configured = tm_input_configured,
+};
+module_hid_driver(tm_driver);
+
+MODULE_DESCRIPTION("Force feedback support for various HID compliant devices by ThrustMaster");
+MODULE_LICENSE("GPL");