aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-wiimote.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/hid-wiimote.c')
-rw-r--r--drivers/hid/hid-wiimote.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index ff7cf129710f..deaf23207812 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -10,7 +10,9 @@
10 * any later version. 10 * any later version.
11 */ 11 */
12 12
13#include <linux/device.h>
13#include <linux/hid.h> 14#include <linux/hid.h>
15#include <linux/input.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include "hid-ids.h" 17#include "hid-ids.h"
16 18
@@ -19,8 +21,15 @@
19 21
20struct wiimote_data { 22struct wiimote_data {
21 struct hid_device *hdev; 23 struct hid_device *hdev;
24 struct input_dev *input;
22}; 25};
23 26
27static int wiimote_input_event(struct input_dev *dev, unsigned int type,
28 unsigned int code, int value)
29{
30 return 0;
31}
32
24static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, 33static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
25 u8 *raw_data, int size) 34 u8 *raw_data, int size)
26{ 35{
@@ -38,9 +47,24 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
38 if (!wdata) 47 if (!wdata)
39 return NULL; 48 return NULL;
40 49
50 wdata->input = input_allocate_device();
51 if (!wdata->input) {
52 kfree(wdata);
53 return NULL;
54 }
55
41 wdata->hdev = hdev; 56 wdata->hdev = hdev;
42 hid_set_drvdata(hdev, wdata); 57 hid_set_drvdata(hdev, wdata);
43 58
59 input_set_drvdata(wdata->input, wdata);
60 wdata->input->event = wiimote_input_event;
61 wdata->input->dev.parent = &wdata->hdev->dev;
62 wdata->input->id.bustype = wdata->hdev->bus;
63 wdata->input->id.vendor = wdata->hdev->vendor;
64 wdata->input->id.product = wdata->hdev->product;
65 wdata->input->id.version = wdata->hdev->version;
66 wdata->input->name = WIIMOTE_NAME;
67
44 return wdata; 68 return wdata;
45} 69}
46 70
@@ -73,10 +97,19 @@ static int wiimote_hid_probe(struct hid_device *hdev,
73 goto err; 97 goto err;
74 } 98 }
75 99
100 ret = input_register_device(wdata->input);
101 if (ret) {
102 hid_err(hdev, "Cannot register input device\n");
103 goto err_stop;
104 }
105
76 hid_info(hdev, "New device registered\n"); 106 hid_info(hdev, "New device registered\n");
77 return 0; 107 return 0;
78 108
109err_stop:
110 hid_hw_stop(hdev);
79err: 111err:
112 input_free_device(wdata->input);
80 wiimote_destroy(wdata); 113 wiimote_destroy(wdata);
81 return ret; 114 return ret;
82} 115}
@@ -87,6 +120,7 @@ static void wiimote_hid_remove(struct hid_device *hdev)
87 120
88 hid_info(hdev, "Device removed\n"); 121 hid_info(hdev, "Device removed\n");
89 hid_hw_stop(hdev); 122 hid_hw_stop(hdev);
123 input_unregister_device(wdata->input);
90 wiimote_destroy(wdata); 124 wiimote_destroy(wdata);
91} 125}
92 126