55#include <linux/version.h>
66#include "hid-tmff2.h"
77
8+ /* Share t500rs_log_level across compilation units (level 3 = unknown-only) */
9+ extern int t500rs_log_level ;
10+
11+ /* Known vendor/opcode IDs managed by the driver (TX side) */
12+ static inline int tmff2_is_known_vendor_id (unsigned char id )
13+ {
14+ switch (id ) {
15+ case 0x01 : case 0x02 : case 0x03 : case 0x04 : case 0x05 :
16+ case 0x40 : case 0x41 : case 0x42 : case 0x43 :
17+ case 0x0a :
18+ return 1 ;
19+ default :
20+ return 0 ;
21+ }
22+ }
23+
824
925int open_mode = 1 ;
1026module_param (open_mode , int , 0660 );
@@ -242,8 +258,15 @@ static ssize_t gain_store(struct device *dev,
242258 }
243259
244260 gain = value ;
245- if (tmff2 -> set_gain ) /* if we can, update gain immediately */
246- tmff2 -> set_gain (tmff2 -> data , (GAIN_MAX * gain ) / GAIN_MAX );
261+ if (tmff2 -> set_gain ) {
262+ unsigned long flags ;
263+ spin_lock_irqsave (& tmff2 -> lock , flags );
264+ tmff2 -> pending_gain_value = GAIN_MAX ;
265+ tmff2 -> gain_pending = 1 ;
266+ spin_unlock_irqrestore (& tmff2 -> lock , flags );
267+ if (!delayed_work_pending (& tmff2 -> work ) && tmff2 -> allow_scheduling )
268+ schedule_delayed_work (& tmff2 -> work , 0 );
269+ }
247270
248271 return count ;
249272}
@@ -258,6 +281,7 @@ static DEVICE_ATTR_RW(gain);
258281static void tmff2_set_gain (struct input_dev * dev , uint16_t value )
259282{
260283 struct tmff2_device_entry * tmff2 = tmff2_from_input (dev );
284+ unsigned long flags ;
261285
262286 if (!tmff2 )
263287 return ;
@@ -267,13 +291,20 @@ static void tmff2_set_gain(struct input_dev *dev, uint16_t value)
267291 return ;
268292 }
269293
270- if (tmff2 -> set_gain (tmff2 -> data , (value * gain ) / GAIN_MAX ))
271- hid_warn (tmff2 -> hdev , "unable to set gain\n" );
294+ /* Defer to workqueue: store pending gain and schedule */
295+ spin_lock_irqsave (& tmff2 -> lock , flags );
296+ tmff2 -> pending_gain_value = value ;
297+ tmff2 -> gain_pending = 1 ;
298+ spin_unlock_irqrestore (& tmff2 -> lock , flags );
299+
300+ if (!delayed_work_pending (& tmff2 -> work ) && tmff2 -> allow_scheduling )
301+ schedule_delayed_work (& tmff2 -> work , 0 );
272302}
273303
274304static void tmff2_set_autocenter (struct input_dev * dev , uint16_t value )
275305{
276306 struct tmff2_device_entry * tmff2 = tmff2_from_input (dev );
307+ unsigned long flags ;
277308
278309 if (!tmff2 )
279310 return ;
@@ -283,8 +314,14 @@ static void tmff2_set_autocenter(struct input_dev *dev, uint16_t value)
283314 return ;
284315 }
285316
286- if (tmff2 -> set_autocenter (tmff2 -> data , value ))
287- hid_warn (tmff2 -> hdev , "unable to set autocenter\n" );
317+ /* Defer to workqueue: store pending autocenter and schedule */
318+ spin_lock_irqsave (& tmff2 -> lock , flags );
319+ tmff2 -> pending_autocenter_value = value ;
320+ tmff2 -> autocenter_pending = 1 ;
321+ spin_unlock_irqrestore (& tmff2 -> lock , flags );
322+
323+ if (!delayed_work_pending (& tmff2 -> work ) && tmff2 -> allow_scheduling )
324+ schedule_delayed_work (& tmff2 -> work , 0 );
288325}
289326
290327static void tmff2_work_handler (struct work_struct * w )
@@ -301,6 +338,30 @@ static void tmff2_work_handler(struct work_struct *w)
301338 if (!tmff2 )
302339 return ;
303340
341+ /* Apply pending control changes (gain/autocenter) in process context */
342+ {
343+ unsigned long f2 ;
344+ uint16_t pg = 0 , pac = 0 ;
345+ int do_gain = 0 , do_ac = 0 ;
346+ spin_lock_irqsave (& tmff2 -> lock , f2 );
347+ if (tmff2 -> gain_pending ) {
348+ pg = tmff2 -> pending_gain_value ;
349+ tmff2 -> gain_pending = 0 ;
350+ do_gain = 1 ;
351+ }
352+ if (tmff2 -> autocenter_pending ) {
353+ pac = tmff2 -> pending_autocenter_value ;
354+ tmff2 -> autocenter_pending = 0 ;
355+ do_ac = 1 ;
356+ }
357+ spin_unlock_irqrestore (& tmff2 -> lock , f2 );
358+
359+ if (do_gain && tmff2 -> set_gain )
360+ tmff2 -> set_gain (tmff2 -> data , (pg * gain ) / GAIN_MAX );
361+ if (do_ac && tmff2 -> set_autocenter )
362+ tmff2 -> set_autocenter (tmff2 -> data , pac );
363+ }
364+
304365 for (effect_id = 0 ; effect_id < tmff2 -> max_effects ; ++ effect_id ) {
305366 unsigned long actions = 0 ;
306367 struct tmff2_effect_state effect ;
@@ -694,6 +755,11 @@ static int tmff2_probe(struct hid_device *hdev, const struct hid_device_id *id)
694755 goto wheel_err ;
695756 break ;
696757
758+ case TMT500RS_PC_ID :
759+ if ((ret = t500rs_populate_api (tmff2 )))
760+ goto wheel_err ;
761+ break ;
762+
697763 case TMT248_PC_ID :
698764 if ((ret = t248_populate_api (tmff2 )))
699765 goto wheel_err ;
@@ -743,6 +809,7 @@ static int tmff2_probe(struct hid_device *hdev, const struct hid_device_id *id)
743809
744810#if LINUX_VERSION_CODE < KERNEL_VERSION (6 ,12 ,0 )
745811static __u8 * tmff2_report_fixup (struct hid_device * hdev , __u8 * rdesc ,
812+
746813 unsigned int * rsize )
747814#else
748815static const __u8 * tmff2_report_fixup (struct hid_device * hdev , __u8 * rdesc ,
@@ -778,6 +845,7 @@ static void tmff2_remove(struct hid_device *hdev)
778845 if (tmff2 -> params & PARAM_DAMPER_LEVEL )
779846 device_remove_file (dev , & dev_attr_damper_level );
780847
848+
781849 if (tmff2 -> params & PARAM_SPRING_LEVEL )
782850 device_remove_file (dev , & dev_attr_spring_level );
783851
@@ -802,6 +870,8 @@ static const struct hid_device_id tmff2_devices[] = {
802870 {HID_USB_DEVICE (USB_VENDOR_ID_THRUSTMASTER , TMT300RS_PS3_NORM_ID )},
803871 {HID_USB_DEVICE (USB_VENDOR_ID_THRUSTMASTER , TMT300RS_PS3_ADV_ID )},
804872 {HID_USB_DEVICE (USB_VENDOR_ID_THRUSTMASTER , TMT300RS_PS4_NORM_ID )},
873+ /* t500rs */
874+ {HID_USB_DEVICE (USB_VENDOR_ID_THRUSTMASTER , TMT500RS_PC_ID )},
805875 /* t248 PC*/
806876 {HID_USB_DEVICE (USB_VENDOR_ID_THRUSTMASTER , TMT248_PC_ID )},
807877 /* tx */
@@ -812,13 +882,42 @@ static const struct hid_device_id tmff2_devices[] = {
812882 {}
813883};
814884MODULE_DEVICE_TABLE (hid , tmff2_devices );
885+ static int tmff2_raw_event (struct hid_device * hdev , struct hid_report * report ,
886+ __u8 * data , int size )
887+ {
888+ /* At level 3: ignore normal input reports (axes/buttons) and idless reports;
889+ * only dump vendor/feature-like unknowns. */
890+ if (t500rs_log_level >= 3 && report && data && size > 0 ) {
891+ /* Skip input traffic entirely (these are the steering updates you saw). */
892+ if (report -> type == HID_INPUT_REPORT )
893+ return 0 ;
894+
895+ /* Use the real Report ID, not data[0] (id==0 means no Report ID). */
896+ if (report -> id == 0 )
897+ return 0 ;
898+
899+ if (!tmff2_is_known_vendor_id ((unsigned char )report -> id )) {
900+ char hex [3 * 64 + 4 ];
901+ int i , off = 0 , max = size > 64 ? 64 : size ;
902+ for (i = 0 ; i < max && off + 3 < sizeof (hex ); i ++ )
903+ off += scnprintf (hex + off , sizeof (hex ) - off , "%02x " , data [i ]);
904+ if (size > max )
905+ scnprintf (hex + off , sizeof (hex ) - off , "..." );
906+ hid_info (hdev , "HID RX UNKNOWN [type=%d id=0x%02x len=%d]: %s\n" ,
907+ report -> type , report -> id , size , hex );
908+ }
909+ }
910+ return 0 ; /* always pass through */
911+ }
912+
815913
816914static struct hid_driver tmff2_driver = {
817915 .name = "tmff2" ,
818916 .id_table = tmff2_devices ,
819917 .probe = tmff2_probe ,
820918 .remove = tmff2_remove ,
821919 .report_fixup = tmff2_report_fixup ,
920+ .raw_event = tmff2_raw_event ,
822921};
823922module_hid_driver (tmff2_driver );
824923
0 commit comments