aboutsummaryrefslogtreecommitdiff
path: root/hid-tminit.c
blob: 16c25fffee69afce52b048c20e80d8898ebad03a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <linux/hid.h>
#include <linux/module.h>
#include <linux/slab.h>

#include "tminit.h"

static int thrustmaster_hid_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
	int ret = 0;
	struct tm_wheel *tm_wheel = kzalloc(sizeof(struct tm_wheel), GFP_KERNEL);
	struct usb_interface *interface = to_usb_interface(hdev->dev.parent);

	if (!tm_wheel) {
		return -ENOMEM;
	}

	ret = hid_parse(hdev);
	if (ret) {
		hid_err(hdev, "parse failed with error %d\n", ret);
		goto error;
	}

	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
	if (ret) {
		hid_err(hdev, "hw start failed with error %d\n", ret);
		goto error;
	}

	hid_set_drvdata(hdev, tm_wheel);
	ret = thrustmaster_probe(tm_wheel, interface);
	if (ret) {
		goto error1;
	}

	return ret;

error1: hid_hw_stop(hdev);
error:  kfree(tm_wheel);
	return ret;
}

static void thrustmaster_hid_disconnect(struct hid_device *hdev)
{
	struct tm_wheel *tm_wheel = hid_get_drvdata(hdev);
	thrustmaster_disconnect(tm_wheel);
	hid_hw_stop(hdev);
}

static const struct hid_device_id thrustmaster_hid_devices[] = {
	{ HID_USB_DEVICE(0x044f, 0xb65d) },
	{ HID_USB_DEVICE(0x044f, 0xb664) },
	{ HID_USB_DEVICE(0x044f, 0xb69c) },
	{}
};

MODULE_DEVICE_TABLE(hid, thrustmaster_hid_devices);

static struct hid_driver thrustmaster_driver = {
	.name = "hid-thrustmaster",
	.id_table = thrustmaster_hid_devices,
	.probe = thrustmaster_hid_probe,
	.remove = thrustmaster_hid_disconnect,
};

module_hid_driver(thrustmaster_driver);

MODULE_AUTHOR("Dario Pagani <dario.pagani.146+linuxk@gmail.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Driver to initialize some steering wheel joysticks from Thrustmaster");