Commit e894d0e3 authored by David Herrmann's avatar David Herrmann Committed by Jiri Kosina

HID: wiimote: Add wiimote device structure

Allocate wiimote device structure with all wiimote related data
when registering new wiimote devices.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 02fb72a0
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#define WIIMOTE_VERSION "0.1" #define WIIMOTE_VERSION "0.1"
#define WIIMOTE_NAME "Nintendo Wii Remote" #define WIIMOTE_NAME "Nintendo Wii Remote"
struct wiimote_data {
struct hid_device *hdev;
};
static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
u8 *raw_data, int size) u8 *raw_data, int size)
{ {
...@@ -26,31 +30,64 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, ...@@ -26,31 +30,64 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
return 0; return 0;
} }
static struct wiimote_data *wiimote_create(struct hid_device *hdev)
{
struct wiimote_data *wdata;
wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
if (!wdata)
return NULL;
wdata->hdev = hdev;
hid_set_drvdata(hdev, wdata);
return wdata;
}
static void wiimote_destroy(struct wiimote_data *wdata)
{
kfree(wdata);
}
static int wiimote_hid_probe(struct hid_device *hdev, static int wiimote_hid_probe(struct hid_device *hdev,
const struct hid_device_id *id) const struct hid_device_id *id)
{ {
struct wiimote_data *wdata;
int ret; int ret;
wdata = wiimote_create(hdev);
if (!wdata) {
hid_err(hdev, "Can't alloc device\n");
return -ENOMEM;
}
ret = hid_parse(hdev); ret = hid_parse(hdev);
if (ret) { if (ret) {
hid_err(hdev, "HID parse failed\n"); hid_err(hdev, "HID parse failed\n");
return ret; goto err;
} }
ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
if (ret) { if (ret) {
hid_err(hdev, "HW start failed\n"); hid_err(hdev, "HW start failed\n");
return ret; goto err;
} }
hid_info(hdev, "New device registered\n"); hid_info(hdev, "New device registered\n");
return 0; return 0;
err:
wiimote_destroy(wdata);
return ret;
} }
static void wiimote_hid_remove(struct hid_device *hdev) static void wiimote_hid_remove(struct hid_device *hdev)
{ {
struct wiimote_data *wdata = hid_get_drvdata(hdev);
hid_info(hdev, "Device removed\n"); hid_info(hdev, "Device removed\n");
hid_hw_stop(hdev); hid_hw_stop(hdev);
wiimote_destroy(wdata);
} }
static const struct hid_device_id wiimote_hid_devices[] = { static const struct hid_device_id wiimote_hid_devices[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment