differentiate between model and attachment of Thrustmaster's joysticks
PATCH 1/1 differentiate between model and attachment of Thrustmaster's joysticks
Make the driver differentiate between model and attachment of a Thrustmaster's steering wheel. What it was thought to be the model code is, in reality, a tuple <model, attachment>.
if a specific match is found then use the proper init code otherwise try anyway with the init code of a steering wheel of the same model but different attachment code; finally if no match is found keep old behavior and stop the init process.
Signed-off-by Dario Pagani <[email protected]>
Co-developed-by Kim Kuparinen <[email protected]>
Signed-off-by Kim Kuparinen <[email protected]>
--- drivers/hid/hid-thrustmaster.c | 57 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 21 deletions(-)
drivers/hid/hid-thrustmaster.c +36 -21
@@ -47,7 +47,8 @@ static const unsigned int setup_arr_sizes[] = {* and vice-versa */ struct tm_wheel_info { -uint16_t wheel_type; +uint8_t model; +uint8_t attachment;/* * See when the USB control out packet is prepared...
@@ -63,16 +64,17 @@ struct tm_wheel_info {* Note: TMX does not work as it requires 2 control packets */ static const struct tm_wheel_info tm_wheels_infos[] = { - {0x0306 ,0x0006 ,"Thrustmaster T150RS" }, - {0x0200 ,0x0005 ,"Thrustmaster T300RS (Missing Attachment)" }, - {0x0206 ,0x0005 ,"Thrustmaster T300RS" }, - {0x0209 ,0x0005 ,"Thrustmaster T300RS (Open Wheel Attachment)" }, - {0x0204 ,0x0005 ,"Thrustmaster T300 Ferrari Alcantara Edition" }, - {0x0002 ,0x0002 ,"Thrustmaster T500RS" } -//{0x0407, 0x0001, "Thrustmaster TMX"} + {0x00 ,0x02 ,0x0002 ,"Thrustmaster T500RS" }, + {0x02 ,0x00 ,0x0005 ,"Thrustmaster T300RS (Missing Attachment)" }, + {0x02 ,0x03 ,0x0005 ,"Thrustmaster T300RS (F1 attachment)" }, + {0x02 ,0x04 ,0x0005 ,"Thrustmaster T300 Ferrari Alcantara Edition" }, + {0x02 ,0x06 ,0x0005 ,"Thrustmaster T300RS" }, + {0x02 ,0x09 ,0x0005 ,"Thrustmaster T300RS (Open Wheel Attachment)" }, + {0x03 ,0x06 ,0x0006 ,"Thrustmaster T150RS" } +//{0x04, 0x07, 0x0001, "Thrustmaster TMX"} }; -static const uint8_t tm_wheels_infos_length =4 ; +static const uint8_t tm_wheels_infos_length =7 ;/* * This structs contains (in little endian) the response data
@@ -99,7 +101,8 @@ struct __packed tm_wheel_response* Seems to be the model code of the wheel * Read table thrustmaster_wheels to values */ -uint16_t model; +uint8_t attachment; +uint8_t model;uint16_t field2;uint16_t field3;
@@ -109,7 +112,8 @@ struct __packed tm_wheel_responsestruct __packed {uint16_t field0;uint16_t field1; -uint16_t model; +uint8_t attachment; +uint8_t model; } b; } data; };
@@ -211,7 +215,9 @@ static void thrustmaster_model_handler(struct urb *urb) {struct hid_device *hdev = urb->context;struct tm_wheel *tm_wheel =hid_get_drvdata (hdev); -uint16_t model =0 ; +uint8_t model =0 ; +uint8_t attachment =0 ; +uint8_t attachment_found;int i, ret;const struct tm_wheel_info *twi =NULL ;
@@ -220,22 +226,31 @@ static void thrustmaster_model_handler(struct urb *urb)return ; } -if (tm_wheel->response->type ==cpu_to_le16 (0x49 )) - model =le16_to_cpu (tm_wheel->response->data.a.model); -else if (tm_wheel->response->type ==cpu_to_le16 (0x47 )) - model =le16_to_cpu (tm_wheel->response->data.b.model); -else { +if (tm_wheel->response->type ==cpu_to_le16 (0x49 )) { + model = tm_wheel->response->data.a.model; + attachment = tm_wheel->response->data.a.attachment; + }else if (tm_wheel->response->type ==cpu_to_le16 (0x47 )) { + model = tm_wheel->response->data.b.model; + attachment = tm_wheel->response->data.b.attachment; + }else {hid_err (hdev,"Unknown packet type 0x%x, unable to proceed further with wheel init\n" , tm_wheel->response->type);return ; }for (i =0 ; i < tm_wheels_infos_length && !twi; i++) -if (tm_wheels_infos[i].wheel_type == model) +if (tm_wheels_infos[i].model == model) twi = tm_wheels_infos + i; -if (twi) -hid_info (hdev,"Wheel with model id 0x%x is a %s\n" , model, twi->wheel_name); -else { +if (twi) { +// Trying to find the best attachment +for (attachment_found = twi->attachment == attachment; !attachment_found && i < tm_wheels_infos_length && tm_wheels_infos[i].model == model; i++) +if (tm_wheels_infos[i].attachment == attachment) { + twi = tm_wheels_infos + i; + attachment_found =1 ; + } + +hid_info (hdev,"Wheel with (model, attachment) = (0x%x, 0x%x) is a %s. attachment_found=%u\n" , model, attachment, twi->wheel_name, attachment_found); + }else {hid_err (hdev,"Unknown wheel's model id 0x%x, unable to proceed further with wheel init\n" , model);return ; }
Signature · 1 line
2.25.1