162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * When connected to the machine, the Thrustmaster wheels appear as
462306a36Sopenharmony_ci * a «generic» hid gamepad called "Thrustmaster FFB Wheel".
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * When in this mode not every functionality of the wheel, like the force feedback,
762306a36Sopenharmony_ci * are available. To enable all functionalities of a Thrustmaster wheel we have to send
862306a36Sopenharmony_ci * to it a specific USB CONTROL request with a code different for each wheel.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * This driver tries to understand which model of Thrustmaster wheel the generic
1162306a36Sopenharmony_ci * "Thrustmaster FFB Wheel" really is and then sends the appropriate control code.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * Copyright (c) 2020-2021 Dario Pagani <dario.pagani.146+linuxk@gmail.com>
1462306a36Sopenharmony_ci * Copyright (c) 2020-2021 Kim Kuparinen <kimi.h.kuparinen@gmail.com>
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci#include <linux/hid.h>
1762306a36Sopenharmony_ci#include <linux/usb.h>
1862306a36Sopenharmony_ci#include <linux/input.h>
1962306a36Sopenharmony_ci#include <linux/slab.h>
2062306a36Sopenharmony_ci#include <linux/module.h>
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/*
2362306a36Sopenharmony_ci * These interrupts are used to prevent a nasty crash when initializing the
2462306a36Sopenharmony_ci * T300RS. Used in thrustmaster_interrupts().
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cistatic const u8 setup_0[] = { 0x42, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2762306a36Sopenharmony_cistatic const u8 setup_1[] = { 0x0a, 0x04, 0x90, 0x03, 0x00, 0x00, 0x00, 0x00 };
2862306a36Sopenharmony_cistatic const u8 setup_2[] = { 0x0a, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00 };
2962306a36Sopenharmony_cistatic const u8 setup_3[] = { 0x0a, 0x04, 0x12, 0x10, 0x00, 0x00, 0x00, 0x00 };
3062306a36Sopenharmony_cistatic const u8 setup_4[] = { 0x0a, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00 };
3162306a36Sopenharmony_cistatic const u8 *const setup_arr[] = { setup_0, setup_1, setup_2, setup_3, setup_4 };
3262306a36Sopenharmony_cistatic const unsigned int setup_arr_sizes[] = {
3362306a36Sopenharmony_ci	ARRAY_SIZE(setup_0),
3462306a36Sopenharmony_ci	ARRAY_SIZE(setup_1),
3562306a36Sopenharmony_ci	ARRAY_SIZE(setup_2),
3662306a36Sopenharmony_ci	ARRAY_SIZE(setup_3),
3762306a36Sopenharmony_ci	ARRAY_SIZE(setup_4)
3862306a36Sopenharmony_ci};
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * This struct contains for each type of
4162306a36Sopenharmony_ci * Thrustmaster wheel
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * Note: The values are stored in the CPU
4462306a36Sopenharmony_ci * endianness, the USB protocols always use
4562306a36Sopenharmony_ci * little endian; the macro cpu_to_le[BIT]()
4662306a36Sopenharmony_ci * must be used when preparing USB packets
4762306a36Sopenharmony_ci * and vice-versa
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_cistruct tm_wheel_info {
5062306a36Sopenharmony_ci	uint16_t wheel_type;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	/*
5362306a36Sopenharmony_ci	 * See when the USB control out packet is prepared...
5462306a36Sopenharmony_ci	 * @TODO The TMX seems to require multiple control codes to switch.
5562306a36Sopenharmony_ci	 */
5662306a36Sopenharmony_ci	uint16_t switch_value;
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	char const *const wheel_name;
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/*
6262306a36Sopenharmony_ci * Known wheels.
6362306a36Sopenharmony_ci * Note: TMX does not work as it requires 2 control packets
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_cistatic const struct tm_wheel_info tm_wheels_infos[] = {
6662306a36Sopenharmony_ci	{0x0306, 0x0006, "Thrustmaster T150RS"},
6762306a36Sopenharmony_ci	{0x0200, 0x0005, "Thrustmaster T300RS (Missing Attachment)"},
6862306a36Sopenharmony_ci	{0x0206, 0x0005, "Thrustmaster T300RS"},
6962306a36Sopenharmony_ci	{0x0209, 0x0005, "Thrustmaster T300RS (Open Wheel Attachment)"},
7062306a36Sopenharmony_ci	{0x020a, 0x0005, "Thrustmaster T300RS (Sparco R383 Mod)"},
7162306a36Sopenharmony_ci	{0x0204, 0x0005, "Thrustmaster T300 Ferrari Alcantara Edition"},
7262306a36Sopenharmony_ci	{0x0002, 0x0002, "Thrustmaster T500RS"}
7362306a36Sopenharmony_ci	//{0x0407, 0x0001, "Thrustmaster TMX"}
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_cistatic const uint8_t tm_wheels_infos_length = 7;
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/*
7962306a36Sopenharmony_ci * This structs contains (in little endian) the response data
8062306a36Sopenharmony_ci * of the wheel to the request 73
8162306a36Sopenharmony_ci *
8262306a36Sopenharmony_ci * A sufficient research to understand what each field does is not
8362306a36Sopenharmony_ci * beign conducted yet. The position and meaning of fields are a
8462306a36Sopenharmony_ci * just a very optimistic guess based on instinct....
8562306a36Sopenharmony_ci */
8662306a36Sopenharmony_cistruct __packed tm_wheel_response
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	/*
8962306a36Sopenharmony_ci	 * Seems to be the type of packet
9062306a36Sopenharmony_ci	 * - 0x0049 if is data.a (15 bytes)
9162306a36Sopenharmony_ci	 * - 0x0047 if is data.b (7 bytes)
9262306a36Sopenharmony_ci	 */
9362306a36Sopenharmony_ci	uint16_t type;
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	union {
9662306a36Sopenharmony_ci		struct __packed {
9762306a36Sopenharmony_ci			uint16_t field0;
9862306a36Sopenharmony_ci			uint16_t field1;
9962306a36Sopenharmony_ci			/*
10062306a36Sopenharmony_ci			 * Seems to be the model code of the wheel
10162306a36Sopenharmony_ci			 * Read table thrustmaster_wheels to values
10262306a36Sopenharmony_ci			 */
10362306a36Sopenharmony_ci			uint16_t model;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci			uint16_t field2;
10662306a36Sopenharmony_ci			uint16_t field3;
10762306a36Sopenharmony_ci			uint16_t field4;
10862306a36Sopenharmony_ci			uint16_t field5;
10962306a36Sopenharmony_ci		} a;
11062306a36Sopenharmony_ci		struct __packed {
11162306a36Sopenharmony_ci			uint16_t field0;
11262306a36Sopenharmony_ci			uint16_t field1;
11362306a36Sopenharmony_ci			uint16_t model;
11462306a36Sopenharmony_ci		} b;
11562306a36Sopenharmony_ci	} data;
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_cistruct tm_wheel {
11962306a36Sopenharmony_ci	struct usb_device *usb_dev;
12062306a36Sopenharmony_ci	struct urb *urb;
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	struct usb_ctrlrequest *model_request;
12362306a36Sopenharmony_ci	struct tm_wheel_response *response;
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci	struct usb_ctrlrequest *change_request;
12662306a36Sopenharmony_ci};
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci/* The control packet to send to wheel */
12962306a36Sopenharmony_cistatic const struct usb_ctrlrequest model_request = {
13062306a36Sopenharmony_ci	.bRequestType = 0xc1,
13162306a36Sopenharmony_ci	.bRequest = 73,
13262306a36Sopenharmony_ci	.wValue = 0,
13362306a36Sopenharmony_ci	.wIndex = 0,
13462306a36Sopenharmony_ci	.wLength = cpu_to_le16(0x0010)
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistatic const struct usb_ctrlrequest change_request = {
13862306a36Sopenharmony_ci	.bRequestType = 0x41,
13962306a36Sopenharmony_ci	.bRequest = 83,
14062306a36Sopenharmony_ci	.wValue = 0, // Will be filled by the driver
14162306a36Sopenharmony_ci	.wIndex = 0,
14262306a36Sopenharmony_ci	.wLength = 0
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/*
14662306a36Sopenharmony_ci * On some setups initializing the T300RS crashes the kernel,
14762306a36Sopenharmony_ci * these interrupts fix that particular issue. So far they haven't caused any
14862306a36Sopenharmony_ci * adverse effects in other wheels.
14962306a36Sopenharmony_ci */
15062306a36Sopenharmony_cistatic void thrustmaster_interrupts(struct hid_device *hdev)
15162306a36Sopenharmony_ci{
15262306a36Sopenharmony_ci	int ret, trans, i, b_ep;
15362306a36Sopenharmony_ci	u8 *send_buf = kmalloc(256, GFP_KERNEL);
15462306a36Sopenharmony_ci	struct usb_host_endpoint *ep;
15562306a36Sopenharmony_ci	struct device *dev = &hdev->dev;
15662306a36Sopenharmony_ci	struct usb_interface *usbif = to_usb_interface(dev->parent);
15762306a36Sopenharmony_ci	struct usb_device *usbdev = interface_to_usbdev(usbif);
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	if (!send_buf) {
16062306a36Sopenharmony_ci		hid_err(hdev, "failed allocating send buffer\n");
16162306a36Sopenharmony_ci		return;
16262306a36Sopenharmony_ci	}
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	if (usbif->cur_altsetting->desc.bNumEndpoints < 2) {
16562306a36Sopenharmony_ci		kfree(send_buf);
16662306a36Sopenharmony_ci		hid_err(hdev, "Wrong number of endpoints?\n");
16762306a36Sopenharmony_ci		return;
16862306a36Sopenharmony_ci	}
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci	ep = &usbif->cur_altsetting->endpoint[1];
17162306a36Sopenharmony_ci	b_ep = ep->desc.bEndpointAddress;
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(setup_arr); ++i) {
17462306a36Sopenharmony_ci		memcpy(send_buf, setup_arr[i], setup_arr_sizes[i]);
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci		ret = usb_interrupt_msg(usbdev,
17762306a36Sopenharmony_ci			usb_sndintpipe(usbdev, b_ep),
17862306a36Sopenharmony_ci			send_buf,
17962306a36Sopenharmony_ci			setup_arr_sizes[i],
18062306a36Sopenharmony_ci			&trans,
18162306a36Sopenharmony_ci			USB_CTRL_SET_TIMEOUT);
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci		if (ret) {
18462306a36Sopenharmony_ci			hid_err(hdev, "setup data couldn't be sent\n");
18562306a36Sopenharmony_ci			kfree(send_buf);
18662306a36Sopenharmony_ci			return;
18762306a36Sopenharmony_ci		}
18862306a36Sopenharmony_ci	}
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	kfree(send_buf);
19162306a36Sopenharmony_ci}
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistatic void thrustmaster_change_handler(struct urb *urb)
19462306a36Sopenharmony_ci{
19562306a36Sopenharmony_ci	struct hid_device *hdev = urb->context;
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	// The wheel seems to kill himself before answering the host and therefore is violating the USB protocol...
19862306a36Sopenharmony_ci	if (urb->status == 0 || urb->status == -EPROTO || urb->status == -EPIPE)
19962306a36Sopenharmony_ci		hid_info(hdev, "Success?! The wheel should have been initialized!\n");
20062306a36Sopenharmony_ci	else
20162306a36Sopenharmony_ci		hid_warn(hdev, "URB to change wheel mode seems to have failed with error %d\n", urb->status);
20262306a36Sopenharmony_ci}
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci/*
20562306a36Sopenharmony_ci * Called by the USB subsystem when the wheel responses to our request
20662306a36Sopenharmony_ci * to get [what it seems to be] the wheel's model.
20762306a36Sopenharmony_ci *
20862306a36Sopenharmony_ci * If the model id is recognized then we send an opportune USB CONTROL REQUEST
20962306a36Sopenharmony_ci * to switch the wheel to its full capabilities
21062306a36Sopenharmony_ci */
21162306a36Sopenharmony_cistatic void thrustmaster_model_handler(struct urb *urb)
21262306a36Sopenharmony_ci{
21362306a36Sopenharmony_ci	struct hid_device *hdev = urb->context;
21462306a36Sopenharmony_ci	struct tm_wheel *tm_wheel = hid_get_drvdata(hdev);
21562306a36Sopenharmony_ci	uint16_t model = 0;
21662306a36Sopenharmony_ci	int i, ret;
21762306a36Sopenharmony_ci	const struct tm_wheel_info *twi = NULL;
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	if (urb->status) {
22062306a36Sopenharmony_ci		hid_err(hdev, "URB to get model id failed with error %d\n", urb->status);
22162306a36Sopenharmony_ci		return;
22262306a36Sopenharmony_ci	}
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci	if (tm_wheel->response->type == cpu_to_le16(0x49))
22562306a36Sopenharmony_ci		model = le16_to_cpu(tm_wheel->response->data.a.model);
22662306a36Sopenharmony_ci	else if (tm_wheel->response->type == cpu_to_le16(0x47))
22762306a36Sopenharmony_ci		model = le16_to_cpu(tm_wheel->response->data.b.model);
22862306a36Sopenharmony_ci	else {
22962306a36Sopenharmony_ci		hid_err(hdev, "Unknown packet type 0x%x, unable to proceed further with wheel init\n", tm_wheel->response->type);
23062306a36Sopenharmony_ci		return;
23162306a36Sopenharmony_ci	}
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci	for (i = 0; i < tm_wheels_infos_length && !twi; i++)
23462306a36Sopenharmony_ci		if (tm_wheels_infos[i].wheel_type == model)
23562306a36Sopenharmony_ci			twi = tm_wheels_infos + i;
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci	if (twi)
23862306a36Sopenharmony_ci		hid_info(hdev, "Wheel with model id 0x%x is a %s\n", model, twi->wheel_name);
23962306a36Sopenharmony_ci	else {
24062306a36Sopenharmony_ci		hid_err(hdev, "Unknown wheel's model id 0x%x, unable to proceed further with wheel init\n", model);
24162306a36Sopenharmony_ci		return;
24262306a36Sopenharmony_ci	}
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	tm_wheel->change_request->wValue = cpu_to_le16(twi->switch_value);
24562306a36Sopenharmony_ci	usb_fill_control_urb(
24662306a36Sopenharmony_ci		tm_wheel->urb,
24762306a36Sopenharmony_ci		tm_wheel->usb_dev,
24862306a36Sopenharmony_ci		usb_sndctrlpipe(tm_wheel->usb_dev, 0),
24962306a36Sopenharmony_ci		(char *)tm_wheel->change_request,
25062306a36Sopenharmony_ci		NULL, 0, // We do not expect any response from the wheel
25162306a36Sopenharmony_ci		thrustmaster_change_handler,
25262306a36Sopenharmony_ci		hdev
25362306a36Sopenharmony_ci	);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci	ret = usb_submit_urb(tm_wheel->urb, GFP_ATOMIC);
25662306a36Sopenharmony_ci	if (ret)
25762306a36Sopenharmony_ci		hid_err(hdev, "Error %d while submitting the change URB. I am unable to initialize this wheel...\n", ret);
25862306a36Sopenharmony_ci}
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_cistatic void thrustmaster_remove(struct hid_device *hdev)
26162306a36Sopenharmony_ci{
26262306a36Sopenharmony_ci	struct tm_wheel *tm_wheel = hid_get_drvdata(hdev);
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci	usb_kill_urb(tm_wheel->urb);
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci	kfree(tm_wheel->change_request);
26762306a36Sopenharmony_ci	kfree(tm_wheel->response);
26862306a36Sopenharmony_ci	kfree(tm_wheel->model_request);
26962306a36Sopenharmony_ci	usb_free_urb(tm_wheel->urb);
27062306a36Sopenharmony_ci	kfree(tm_wheel);
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci	hid_hw_stop(hdev);
27362306a36Sopenharmony_ci}
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci/*
27662306a36Sopenharmony_ci * Function called by HID when a hid Thrustmaster FFB wheel is connected to the host.
27762306a36Sopenharmony_ci * This function starts the hid dev, tries to allocate the tm_wheel data structure and
27862306a36Sopenharmony_ci * finally send an USB CONTROL REQUEST to the wheel to get [what it seems to be] its
27962306a36Sopenharmony_ci * model type.
28062306a36Sopenharmony_ci */
28162306a36Sopenharmony_cistatic int thrustmaster_probe(struct hid_device *hdev, const struct hid_device_id *id)
28262306a36Sopenharmony_ci{
28362306a36Sopenharmony_ci	int ret = 0;
28462306a36Sopenharmony_ci	struct tm_wheel *tm_wheel = NULL;
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci	if (!hid_is_usb(hdev))
28762306a36Sopenharmony_ci		return -EINVAL;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	ret = hid_parse(hdev);
29062306a36Sopenharmony_ci	if (ret) {
29162306a36Sopenharmony_ci		hid_err(hdev, "parse failed with error %d\n", ret);
29262306a36Sopenharmony_ci		goto error0;
29362306a36Sopenharmony_ci	}
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
29662306a36Sopenharmony_ci	if (ret) {
29762306a36Sopenharmony_ci		hid_err(hdev, "hw start failed with error %d\n", ret);
29862306a36Sopenharmony_ci		goto error0;
29962306a36Sopenharmony_ci	}
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci	// Now we allocate the tm_wheel
30262306a36Sopenharmony_ci	tm_wheel = kzalloc(sizeof(struct tm_wheel), GFP_KERNEL);
30362306a36Sopenharmony_ci	if (!tm_wheel) {
30462306a36Sopenharmony_ci		ret = -ENOMEM;
30562306a36Sopenharmony_ci		goto error1;
30662306a36Sopenharmony_ci	}
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci	tm_wheel->urb = usb_alloc_urb(0, GFP_ATOMIC);
30962306a36Sopenharmony_ci	if (!tm_wheel->urb) {
31062306a36Sopenharmony_ci		ret = -ENOMEM;
31162306a36Sopenharmony_ci		goto error2;
31262306a36Sopenharmony_ci	}
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_ci	tm_wheel->model_request = kmemdup(&model_request,
31562306a36Sopenharmony_ci					  sizeof(struct usb_ctrlrequest),
31662306a36Sopenharmony_ci					  GFP_KERNEL);
31762306a36Sopenharmony_ci	if (!tm_wheel->model_request) {
31862306a36Sopenharmony_ci		ret = -ENOMEM;
31962306a36Sopenharmony_ci		goto error3;
32062306a36Sopenharmony_ci	}
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci	tm_wheel->response = kzalloc(sizeof(struct tm_wheel_response), GFP_KERNEL);
32362306a36Sopenharmony_ci	if (!tm_wheel->response) {
32462306a36Sopenharmony_ci		ret = -ENOMEM;
32562306a36Sopenharmony_ci		goto error4;
32662306a36Sopenharmony_ci	}
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci	tm_wheel->change_request = kmemdup(&change_request,
32962306a36Sopenharmony_ci					   sizeof(struct usb_ctrlrequest),
33062306a36Sopenharmony_ci					   GFP_KERNEL);
33162306a36Sopenharmony_ci	if (!tm_wheel->change_request) {
33262306a36Sopenharmony_ci		ret = -ENOMEM;
33362306a36Sopenharmony_ci		goto error5;
33462306a36Sopenharmony_ci	}
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	tm_wheel->usb_dev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
33762306a36Sopenharmony_ci	hid_set_drvdata(hdev, tm_wheel);
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci	thrustmaster_interrupts(hdev);
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_ci	usb_fill_control_urb(
34262306a36Sopenharmony_ci		tm_wheel->urb,
34362306a36Sopenharmony_ci		tm_wheel->usb_dev,
34462306a36Sopenharmony_ci		usb_rcvctrlpipe(tm_wheel->usb_dev, 0),
34562306a36Sopenharmony_ci		(char *)tm_wheel->model_request,
34662306a36Sopenharmony_ci		tm_wheel->response,
34762306a36Sopenharmony_ci		sizeof(struct tm_wheel_response),
34862306a36Sopenharmony_ci		thrustmaster_model_handler,
34962306a36Sopenharmony_ci		hdev
35062306a36Sopenharmony_ci	);
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci	ret = usb_submit_urb(tm_wheel->urb, GFP_ATOMIC);
35362306a36Sopenharmony_ci	if (ret) {
35462306a36Sopenharmony_ci		hid_err(hdev, "Error %d while submitting the URB. I am unable to initialize this wheel...\n", ret);
35562306a36Sopenharmony_ci		goto error6;
35662306a36Sopenharmony_ci	}
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci	return ret;
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_cierror6: kfree(tm_wheel->change_request);
36162306a36Sopenharmony_cierror5: kfree(tm_wheel->response);
36262306a36Sopenharmony_cierror4: kfree(tm_wheel->model_request);
36362306a36Sopenharmony_cierror3: usb_free_urb(tm_wheel->urb);
36462306a36Sopenharmony_cierror2: kfree(tm_wheel);
36562306a36Sopenharmony_cierror1: hid_hw_stop(hdev);
36662306a36Sopenharmony_cierror0:
36762306a36Sopenharmony_ci	return ret;
36862306a36Sopenharmony_ci}
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_cistatic const struct hid_device_id thrustmaster_devices[] = {
37162306a36Sopenharmony_ci	{ HID_USB_DEVICE(0x044f, 0xb65d)},
37262306a36Sopenharmony_ci	{}
37362306a36Sopenharmony_ci};
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ciMODULE_DEVICE_TABLE(hid, thrustmaster_devices);
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_cistatic struct hid_driver thrustmaster_driver = {
37862306a36Sopenharmony_ci	.name = "hid-thrustmaster",
37962306a36Sopenharmony_ci	.id_table = thrustmaster_devices,
38062306a36Sopenharmony_ci	.probe = thrustmaster_probe,
38162306a36Sopenharmony_ci	.remove = thrustmaster_remove,
38262306a36Sopenharmony_ci};
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_cimodule_hid_driver(thrustmaster_driver);
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ciMODULE_AUTHOR("Dario Pagani <dario.pagani.146+linuxk@gmail.com>");
38762306a36Sopenharmony_ciMODULE_LICENSE("GPL");
38862306a36Sopenharmony_ciMODULE_DESCRIPTION("Driver to initialize some steering wheel joysticks from Thrustmaster");
38962306a36Sopenharmony_ci
390