aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2011-07-05 07:45:10 -0400
committerJiri Kosina <jkosina@suse.cz>2011-07-11 08:30:22 -0400
commite894d0e3e06650510c70e50b317dfaba5295f4db (patch)
tree4c919254b49ccb68e2b5bf9113e4bb9bfb775269 /drivers/hid
parent02fb72a06ae1ed55b4373a4c678f25d70fd65902 (diff)
HID: wiimote: Add wiimote device structure
Allocate wiimote device structure with all wiimote related data when registering new wiimote devices. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-wiimote.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index ed4fe18c7fb5..ff7cf129710f 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -17,6 +17,10 @@
17#define WIIMOTE_VERSION "0.1" 17#define WIIMOTE_VERSION "0.1"
18#define WIIMOTE_NAME "Nintendo Wii Remote" 18#define WIIMOTE_NAME "Nintendo Wii Remote"
19 19
20struct wiimote_data {
21 struct hid_device *hdev;
22};
23
20static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, 24static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
21 u8 *raw_data, int size) 25 u8 *raw_data, int size)
22{ 26{
@@ -26,31 +30,64 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
26 return 0; 30 return 0;
27} 31}
28 32
33static struct wiimote_data *wiimote_create(struct hid_device *hdev)
34{
35 struct wiimote_data *wdata;
36
37 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
38 if (!wdata)
39 return NULL;
40
41 wdata->hdev = hdev;
42 hid_set_drvdata(hdev, wdata);
43
44 return wdata;
45}
46
47static void wiimote_destroy(struct wiimote_data *wdata)
48{
49 kfree(wdata);
50}
51
29static int wiimote_hid_probe(struct hid_device *hdev, 52static int wiimote_hid_probe(struct hid_device *hdev,
30 const struct hid_device_id *id) 53 const struct hid_device_id *id)
31{ 54{
55 struct wiimote_data *wdata;
32 int ret; 56 int ret;
33 57
58 wdata = wiimote_create(hdev);
59 if (!wdata) {
60 hid_err(hdev, "Can't alloc device\n");
61 return -ENOMEM;
62 }
63
34 ret = hid_parse(hdev); 64 ret = hid_parse(hdev);
35 if (ret) { 65 if (ret) {
36 hid_err(hdev, "HID parse failed\n"); 66 hid_err(hdev, "HID parse failed\n");
37 return ret; 67 goto err;
38 } 68 }
39 69
40 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); 70 ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
41 if (ret) { 71 if (ret) {
42 hid_err(hdev, "HW start failed\n"); 72 hid_err(hdev, "HW start failed\n");
43 return ret; 73 goto err;
44 } 74 }
45 75
46 hid_info(hdev, "New device registered\n"); 76 hid_info(hdev, "New device registered\n");
47 return 0; 77 return 0;
78
79err:
80 wiimote_destroy(wdata);
81 return ret;
48} 82}
49 83
50static void wiimote_hid_remove(struct hid_device *hdev) 84static void wiimote_hid_remove(struct hid_device *hdev)
51{ 85{
86 struct wiimote_data *wdata = hid_get_drvdata(hdev);
87
52 hid_info(hdev, "Device removed\n"); 88 hid_info(hdev, "Device removed\n");
53 hid_hw_stop(hdev); 89 hid_hw_stop(hdev);
90 wiimote_destroy(wdata);
54} 91}
55 92
56static const struct hid_device_id wiimote_hid_devices[] = { 93static const struct hid_device_id wiimote_hid_devices[] = {