David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HID driver for Nintendo Wiimote devices |
| 3 | * Copyright (c) 2011 David Herrmann |
| 4 | */ |
| 5 | |
| 6 | /* |
| 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) |
| 10 | * any later version. |
| 11 | */ |
| 12 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame^] | 13 | #include <linux/hid.h> |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 14 | #include <linux/module.h> |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame^] | 15 | #include "hid-ids.h" |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 16 | |
| 17 | #define WIIMOTE_VERSION "0.1" |
| 18 | #define WIIMOTE_NAME "Nintendo Wii Remote" |
| 19 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame^] | 20 | static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, |
| 21 | u8 *raw_data, int size) |
| 22 | { |
| 23 | if (size < 1) |
| 24 | return -EINVAL; |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static int wiimote_hid_probe(struct hid_device *hdev, |
| 30 | const struct hid_device_id *id) |
| 31 | { |
| 32 | int ret; |
| 33 | |
| 34 | ret = hid_parse(hdev); |
| 35 | if (ret) { |
| 36 | hid_err(hdev, "HID parse failed\n"); |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); |
| 41 | if (ret) { |
| 42 | hid_err(hdev, "HW start failed\n"); |
| 43 | return ret; |
| 44 | } |
| 45 | |
| 46 | hid_info(hdev, "New device registered\n"); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static void wiimote_hid_remove(struct hid_device *hdev) |
| 51 | { |
| 52 | hid_info(hdev, "Device removed\n"); |
| 53 | hid_hw_stop(hdev); |
| 54 | } |
| 55 | |
| 56 | static const struct hid_device_id wiimote_hid_devices[] = { |
| 57 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, |
| 58 | USB_DEVICE_ID_NINTENDO_WIIMOTE) }, |
| 59 | { } |
| 60 | }; |
| 61 | MODULE_DEVICE_TABLE(hid, wiimote_hid_devices); |
| 62 | |
| 63 | static struct hid_driver wiimote_hid_driver = { |
| 64 | .name = "wiimote", |
| 65 | .id_table = wiimote_hid_devices, |
| 66 | .probe = wiimote_hid_probe, |
| 67 | .remove = wiimote_hid_remove, |
| 68 | .raw_event = wiimote_hid_event, |
| 69 | }; |
| 70 | |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 71 | static int __init wiimote_init(void) |
| 72 | { |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame^] | 73 | int ret; |
| 74 | |
| 75 | ret = hid_register_driver(&wiimote_hid_driver); |
| 76 | if (ret) |
| 77 | pr_err("Can't register wiimote hid driver\n"); |
| 78 | |
| 79 | return ret; |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void __exit wiimote_exit(void) |
| 83 | { |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame^] | 84 | hid_unregister_driver(&wiimote_hid_driver); |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | module_init(wiimote_init); |
| 88 | module_exit(wiimote_exit); |
| 89 | MODULE_LICENSE("GPL"); |
| 90 | MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); |
| 91 | MODULE_DESCRIPTION(WIIMOTE_NAME " Device Driver"); |
| 92 | MODULE_VERSION(WIIMOTE_VERSION); |