2 * HID driver for Nintendo Wiimote devices
3 * Copyright (c) 2011 David Herrmann
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/hid.h>
14 #include <linux/module.h>
17 #define WIIMOTE_VERSION "0.1"
18 #define WIIMOTE_NAME "Nintendo Wii Remote"
21 struct hid_device
*hdev
;
24 static int wiimote_hid_event(struct hid_device
*hdev
, struct hid_report
*report
,
25 u8
*raw_data
, int size
)
33 static struct wiimote_data
*wiimote_create(struct hid_device
*hdev
)
35 struct wiimote_data
*wdata
;
37 wdata
= kzalloc(sizeof(*wdata
), GFP_KERNEL
);
42 hid_set_drvdata(hdev
, wdata
);
47 static void wiimote_destroy(struct wiimote_data
*wdata
)
52 static int wiimote_hid_probe(struct hid_device
*hdev
,
53 const struct hid_device_id
*id
)
55 struct wiimote_data
*wdata
;
58 wdata
= wiimote_create(hdev
);
60 hid_err(hdev
, "Can't alloc device\n");
64 ret
= hid_parse(hdev
);
66 hid_err(hdev
, "HID parse failed\n");
70 ret
= hid_hw_start(hdev
, HID_CONNECT_HIDRAW
);
72 hid_err(hdev
, "HW start failed\n");
76 hid_info(hdev
, "New device registered\n");
80 wiimote_destroy(wdata
);
84 static void wiimote_hid_remove(struct hid_device
*hdev
)
86 struct wiimote_data
*wdata
= hid_get_drvdata(hdev
);
88 hid_info(hdev
, "Device removed\n");
90 wiimote_destroy(wdata
);
93 static const struct hid_device_id wiimote_hid_devices
[] = {
94 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO
,
95 USB_DEVICE_ID_NINTENDO_WIIMOTE
) },
98 MODULE_DEVICE_TABLE(hid
, wiimote_hid_devices
);
100 static struct hid_driver wiimote_hid_driver
= {
102 .id_table
= wiimote_hid_devices
,
103 .probe
= wiimote_hid_probe
,
104 .remove
= wiimote_hid_remove
,
105 .raw_event
= wiimote_hid_event
,
108 static int __init
wiimote_init(void)
112 ret
= hid_register_driver(&wiimote_hid_driver
);
114 pr_err("Can't register wiimote hid driver\n");
119 static void __exit
wiimote_exit(void)
121 hid_unregister_driver(&wiimote_hid_driver
);
124 module_init(wiimote_init
);
125 module_exit(wiimote_exit
);
126 MODULE_LICENSE("GPL");
127 MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
128 MODULE_DESCRIPTION(WIIMOTE_NAME
" Device Driver");
129 MODULE_VERSION(WIIMOTE_VERSION
);