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 | 29d2806 | 2011-09-06 13:50:34 +0200 | [diff] [blame] | 13 | #include <linux/completion.h> |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 14 | #include <linux/device.h> |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 15 | #include <linux/hid.h> |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 16 | #include <linux/input.h> |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 17 | #include <linux/leds.h> |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 18 | #include <linux/module.h> |
David Herrmann | 29d2806 | 2011-09-06 13:50:34 +0200 | [diff] [blame] | 19 | #include <linux/mutex.h> |
David Herrmann | 23c063c | 2011-07-05 13:45:14 +0200 | [diff] [blame] | 20 | #include <linux/spinlock.h> |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 21 | #include "hid-ids.h" |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 22 | |
| 23 | #define WIIMOTE_VERSION "0.1" |
| 24 | #define WIIMOTE_NAME "Nintendo Wii Remote" |
David Herrmann | 23c063c | 2011-07-05 13:45:14 +0200 | [diff] [blame] | 25 | #define WIIMOTE_BUFSIZE 32 |
| 26 | |
| 27 | struct wiimote_buf { |
| 28 | __u8 data[HID_MAX_BUFFER_SIZE]; |
| 29 | size_t size; |
| 30 | }; |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 31 | |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 32 | struct wiimote_state { |
| 33 | spinlock_t lock; |
| 34 | __u8 flags; |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 35 | __u8 accel_split[2]; |
David Herrmann | 29d2806 | 2011-09-06 13:50:34 +0200 | [diff] [blame] | 36 | |
| 37 | /* synchronous cmd requests */ |
| 38 | struct mutex sync; |
| 39 | struct completion ready; |
| 40 | int cmd; |
| 41 | __u32 opt; |
David Herrmann | 33e8401 | 2011-09-06 13:50:35 +0200 | [diff] [blame^] | 42 | |
| 43 | /* results of synchronous requests */ |
| 44 | __u8 cmd_err; |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 47 | struct wiimote_data { |
| 48 | struct hid_device *hdev; |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 49 | struct input_dev *input; |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 50 | struct led_classdev *leds[4]; |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 51 | struct input_dev *accel; |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 52 | struct input_dev *ir; |
David Herrmann | 23c063c | 2011-07-05 13:45:14 +0200 | [diff] [blame] | 53 | |
| 54 | spinlock_t qlock; |
| 55 | __u8 head; |
| 56 | __u8 tail; |
| 57 | struct wiimote_buf outq[WIIMOTE_BUFSIZE]; |
| 58 | struct work_struct worker; |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 59 | |
| 60 | struct wiimote_state state; |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
David Herrmann | c003ec2 | 2011-09-06 13:50:26 +0200 | [diff] [blame] | 63 | #define WIIPROTO_FLAG_LED1 0x01 |
| 64 | #define WIIPROTO_FLAG_LED2 0x02 |
| 65 | #define WIIPROTO_FLAG_LED3 0x04 |
| 66 | #define WIIPROTO_FLAG_LED4 0x08 |
| 67 | #define WIIPROTO_FLAG_RUMBLE 0x10 |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 68 | #define WIIPROTO_FLAG_ACCEL 0x20 |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 69 | #define WIIPROTO_FLAG_IR_BASIC 0x40 |
| 70 | #define WIIPROTO_FLAG_IR_EXT 0x80 |
| 71 | #define WIIPROTO_FLAG_IR_FULL 0xc0 /* IR_BASIC | IR_EXT */ |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 72 | #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \ |
| 73 | WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4) |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 74 | #define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \ |
| 75 | WIIPROTO_FLAG_IR_FULL) |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 76 | |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 77 | /* return flag for led \num */ |
| 78 | #define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1)) |
| 79 | |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 80 | enum wiiproto_reqs { |
David Herrmann | 2cb5e4b | 2011-08-17 11:43:23 +0200 | [diff] [blame] | 81 | WIIPROTO_REQ_NULL = 0x0, |
David Herrmann | c003ec2 | 2011-09-06 13:50:26 +0200 | [diff] [blame] | 82 | WIIPROTO_REQ_RUMBLE = 0x10, |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 83 | WIIPROTO_REQ_LED = 0x11, |
David Herrmann | 2cb5e4b | 2011-08-17 11:43:23 +0200 | [diff] [blame] | 84 | WIIPROTO_REQ_DRM = 0x12, |
David Herrmann | be1ecd6 | 2011-09-06 13:50:33 +0200 | [diff] [blame] | 85 | WIIPROTO_REQ_WMEM = 0x16, |
| 86 | WIIPROTO_REQ_RMEM = 0x17, |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 87 | WIIPROTO_REQ_STATUS = 0x20, |
David Herrmann | be1ecd6 | 2011-09-06 13:50:33 +0200 | [diff] [blame] | 88 | WIIPROTO_REQ_DATA = 0x21, |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 89 | WIIPROTO_REQ_RETURN = 0x22, |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 90 | WIIPROTO_REQ_DRM_K = 0x30, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 91 | WIIPROTO_REQ_DRM_KA = 0x31, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 92 | WIIPROTO_REQ_DRM_KE = 0x32, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 93 | WIIPROTO_REQ_DRM_KAI = 0x33, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 94 | WIIPROTO_REQ_DRM_KEE = 0x34, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 95 | WIIPROTO_REQ_DRM_KAE = 0x35, |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 96 | WIIPROTO_REQ_DRM_KIE = 0x36, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 97 | WIIPROTO_REQ_DRM_KAIE = 0x37, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 98 | WIIPROTO_REQ_DRM_E = 0x3d, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 99 | WIIPROTO_REQ_DRM_SKAI1 = 0x3e, |
| 100 | WIIPROTO_REQ_DRM_SKAI2 = 0x3f, |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | enum wiiproto_keys { |
| 104 | WIIPROTO_KEY_LEFT, |
| 105 | WIIPROTO_KEY_RIGHT, |
| 106 | WIIPROTO_KEY_UP, |
| 107 | WIIPROTO_KEY_DOWN, |
| 108 | WIIPROTO_KEY_PLUS, |
| 109 | WIIPROTO_KEY_MINUS, |
| 110 | WIIPROTO_KEY_ONE, |
| 111 | WIIPROTO_KEY_TWO, |
| 112 | WIIPROTO_KEY_A, |
| 113 | WIIPROTO_KEY_B, |
| 114 | WIIPROTO_KEY_HOME, |
| 115 | WIIPROTO_KEY_COUNT |
| 116 | }; |
| 117 | |
| 118 | static __u16 wiiproto_keymap[] = { |
| 119 | KEY_LEFT, /* WIIPROTO_KEY_LEFT */ |
| 120 | KEY_RIGHT, /* WIIPROTO_KEY_RIGHT */ |
| 121 | KEY_UP, /* WIIPROTO_KEY_UP */ |
| 122 | KEY_DOWN, /* WIIPROTO_KEY_DOWN */ |
| 123 | KEY_NEXT, /* WIIPROTO_KEY_PLUS */ |
| 124 | KEY_PREVIOUS, /* WIIPROTO_KEY_MINUS */ |
| 125 | BTN_1, /* WIIPROTO_KEY_ONE */ |
| 126 | BTN_2, /* WIIPROTO_KEY_TWO */ |
| 127 | BTN_A, /* WIIPROTO_KEY_A */ |
| 128 | BTN_B, /* WIIPROTO_KEY_B */ |
| 129 | BTN_MODE, /* WIIPROTO_KEY_HOME */ |
| 130 | }; |
| 131 | |
David Herrmann | 29d2806 | 2011-09-06 13:50:34 +0200 | [diff] [blame] | 132 | /* requires the state.lock spinlock to be held */ |
| 133 | static inline bool wiimote_cmd_pending(struct wiimote_data *wdata, int cmd, |
| 134 | __u32 opt) |
| 135 | { |
| 136 | return wdata->state.cmd == cmd && wdata->state.opt == opt; |
| 137 | } |
| 138 | |
| 139 | /* requires the state.lock spinlock to be held */ |
| 140 | static inline void wiimote_cmd_complete(struct wiimote_data *wdata) |
| 141 | { |
| 142 | wdata->state.cmd = WIIPROTO_REQ_NULL; |
| 143 | complete(&wdata->state.ready); |
| 144 | } |
| 145 | |
| 146 | static inline int wiimote_cmd_acquire(struct wiimote_data *wdata) |
| 147 | { |
| 148 | return mutex_lock_interruptible(&wdata->state.sync) ? -ERESTARTSYS : 0; |
| 149 | } |
| 150 | |
| 151 | /* requires the state.lock spinlock to be held */ |
| 152 | static inline void wiimote_cmd_set(struct wiimote_data *wdata, int cmd, |
| 153 | __u32 opt) |
| 154 | { |
| 155 | INIT_COMPLETION(wdata->state.ready); |
| 156 | wdata->state.cmd = cmd; |
| 157 | wdata->state.opt = opt; |
| 158 | } |
| 159 | |
| 160 | static inline void wiimote_cmd_release(struct wiimote_data *wdata) |
| 161 | { |
| 162 | mutex_unlock(&wdata->state.sync); |
| 163 | } |
| 164 | |
| 165 | static inline int wiimote_cmd_wait(struct wiimote_data *wdata) |
| 166 | { |
| 167 | int ret; |
| 168 | |
| 169 | ret = wait_for_completion_interruptible_timeout(&wdata->state.ready, HZ); |
| 170 | if (ret < 0) |
| 171 | return -ERESTARTSYS; |
| 172 | else if (ret == 0) |
| 173 | return -EIO; |
| 174 | else |
| 175 | return 0; |
| 176 | } |
| 177 | |
David Herrmann | 0c218f14 | 2011-07-05 13:45:13 +0200 | [diff] [blame] | 178 | static ssize_t wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, |
| 179 | size_t count) |
| 180 | { |
| 181 | __u8 *buf; |
| 182 | ssize_t ret; |
| 183 | |
| 184 | if (!hdev->hid_output_raw_report) |
| 185 | return -ENODEV; |
| 186 | |
| 187 | buf = kmemdup(buffer, count, GFP_KERNEL); |
| 188 | if (!buf) |
| 189 | return -ENOMEM; |
| 190 | |
| 191 | ret = hdev->hid_output_raw_report(hdev, buf, count, HID_OUTPUT_REPORT); |
| 192 | |
| 193 | kfree(buf); |
| 194 | return ret; |
| 195 | } |
| 196 | |
David Herrmann | 23c063c | 2011-07-05 13:45:14 +0200 | [diff] [blame] | 197 | static void wiimote_worker(struct work_struct *work) |
| 198 | { |
| 199 | struct wiimote_data *wdata = container_of(work, struct wiimote_data, |
| 200 | worker); |
| 201 | unsigned long flags; |
| 202 | |
| 203 | spin_lock_irqsave(&wdata->qlock, flags); |
| 204 | |
| 205 | while (wdata->head != wdata->tail) { |
| 206 | spin_unlock_irqrestore(&wdata->qlock, flags); |
| 207 | wiimote_hid_send(wdata->hdev, wdata->outq[wdata->tail].data, |
| 208 | wdata->outq[wdata->tail].size); |
| 209 | spin_lock_irqsave(&wdata->qlock, flags); |
| 210 | |
| 211 | wdata->tail = (wdata->tail + 1) % WIIMOTE_BUFSIZE; |
| 212 | } |
| 213 | |
| 214 | spin_unlock_irqrestore(&wdata->qlock, flags); |
| 215 | } |
| 216 | |
| 217 | static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, |
| 218 | size_t count) |
| 219 | { |
| 220 | unsigned long flags; |
| 221 | __u8 newhead; |
| 222 | |
| 223 | if (count > HID_MAX_BUFFER_SIZE) { |
| 224 | hid_warn(wdata->hdev, "Sending too large output report\n"); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Copy new request into our output queue and check whether the |
| 230 | * queue is full. If it is full, discard this request. |
| 231 | * If it is empty we need to start a new worker that will |
| 232 | * send out the buffer to the hid device. |
| 233 | * If the queue is not empty, then there must be a worker |
| 234 | * that is currently sending out our buffer and this worker |
| 235 | * will reschedule itself until the queue is empty. |
| 236 | */ |
| 237 | |
| 238 | spin_lock_irqsave(&wdata->qlock, flags); |
| 239 | |
| 240 | memcpy(wdata->outq[wdata->head].data, buffer, count); |
| 241 | wdata->outq[wdata->head].size = count; |
| 242 | newhead = (wdata->head + 1) % WIIMOTE_BUFSIZE; |
| 243 | |
| 244 | if (wdata->head == wdata->tail) { |
| 245 | wdata->head = newhead; |
| 246 | schedule_work(&wdata->worker); |
| 247 | } else if (newhead != wdata->tail) { |
| 248 | wdata->head = newhead; |
| 249 | } else { |
| 250 | hid_warn(wdata->hdev, "Output queue is full"); |
| 251 | } |
| 252 | |
| 253 | spin_unlock_irqrestore(&wdata->qlock, flags); |
| 254 | } |
| 255 | |
David Herrmann | c003ec2 | 2011-09-06 13:50:26 +0200 | [diff] [blame] | 256 | /* |
| 257 | * This sets the rumble bit on the given output report if rumble is |
| 258 | * currently enabled. |
| 259 | * \cmd1 must point to the second byte in the output report => &cmd[1] |
| 260 | * This must be called on nearly every output report before passing it |
| 261 | * into the output queue! |
| 262 | */ |
| 263 | static inline void wiiproto_keep_rumble(struct wiimote_data *wdata, __u8 *cmd1) |
| 264 | { |
| 265 | if (wdata->state.flags & WIIPROTO_FLAG_RUMBLE) |
| 266 | *cmd1 |= 0x01; |
| 267 | } |
| 268 | |
| 269 | static void wiiproto_req_rumble(struct wiimote_data *wdata, __u8 rumble) |
| 270 | { |
| 271 | __u8 cmd[2]; |
| 272 | |
| 273 | rumble = !!rumble; |
| 274 | if (rumble == !!(wdata->state.flags & WIIPROTO_FLAG_RUMBLE)) |
| 275 | return; |
| 276 | |
| 277 | if (rumble) |
| 278 | wdata->state.flags |= WIIPROTO_FLAG_RUMBLE; |
| 279 | else |
| 280 | wdata->state.flags &= ~WIIPROTO_FLAG_RUMBLE; |
| 281 | |
| 282 | cmd[0] = WIIPROTO_REQ_RUMBLE; |
| 283 | cmd[1] = 0; |
| 284 | |
| 285 | wiiproto_keep_rumble(wdata, &cmd[1]); |
| 286 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
| 287 | } |
| 288 | |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 289 | static void wiiproto_req_leds(struct wiimote_data *wdata, int leds) |
| 290 | { |
| 291 | __u8 cmd[2]; |
| 292 | |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 293 | leds &= WIIPROTO_FLAGS_LEDS; |
| 294 | if ((wdata->state.flags & WIIPROTO_FLAGS_LEDS) == leds) |
| 295 | return; |
| 296 | wdata->state.flags = (wdata->state.flags & ~WIIPROTO_FLAGS_LEDS) | leds; |
| 297 | |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 298 | cmd[0] = WIIPROTO_REQ_LED; |
| 299 | cmd[1] = 0; |
| 300 | |
| 301 | if (leds & WIIPROTO_FLAG_LED1) |
| 302 | cmd[1] |= 0x10; |
| 303 | if (leds & WIIPROTO_FLAG_LED2) |
| 304 | cmd[1] |= 0x20; |
| 305 | if (leds & WIIPROTO_FLAG_LED3) |
| 306 | cmd[1] |= 0x40; |
| 307 | if (leds & WIIPROTO_FLAG_LED4) |
| 308 | cmd[1] |= 0x80; |
| 309 | |
David Herrmann | c003ec2 | 2011-09-06 13:50:26 +0200 | [diff] [blame] | 310 | wiiproto_keep_rumble(wdata, &cmd[1]); |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 311 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
| 312 | } |
| 313 | |
David Herrmann | 2cb5e4b | 2011-08-17 11:43:23 +0200 | [diff] [blame] | 314 | /* |
| 315 | * Check what peripherals of the wiimote are currently |
| 316 | * active and select a proper DRM that supports all of |
| 317 | * the requested data inputs. |
| 318 | */ |
| 319 | static __u8 select_drm(struct wiimote_data *wdata) |
| 320 | { |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 321 | __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR; |
| 322 | |
| 323 | if (ir == WIIPROTO_FLAG_IR_BASIC) { |
| 324 | if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) |
| 325 | return WIIPROTO_REQ_DRM_KAIE; |
| 326 | else |
| 327 | return WIIPROTO_REQ_DRM_KIE; |
| 328 | } else if (ir == WIIPROTO_FLAG_IR_EXT) { |
| 329 | return WIIPROTO_REQ_DRM_KAI; |
| 330 | } else if (ir == WIIPROTO_FLAG_IR_FULL) { |
| 331 | return WIIPROTO_REQ_DRM_SKAI1; |
| 332 | } else { |
| 333 | if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) |
| 334 | return WIIPROTO_REQ_DRM_KA; |
| 335 | else |
| 336 | return WIIPROTO_REQ_DRM_K; |
| 337 | } |
David Herrmann | 2cb5e4b | 2011-08-17 11:43:23 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) |
| 341 | { |
| 342 | __u8 cmd[3]; |
| 343 | |
| 344 | if (drm == WIIPROTO_REQ_NULL) |
| 345 | drm = select_drm(wdata); |
| 346 | |
| 347 | cmd[0] = WIIPROTO_REQ_DRM; |
| 348 | cmd[1] = 0; |
| 349 | cmd[2] = drm; |
| 350 | |
David Herrmann | c003ec2 | 2011-09-06 13:50:26 +0200 | [diff] [blame] | 351 | wiiproto_keep_rumble(wdata, &cmd[1]); |
David Herrmann | 2cb5e4b | 2011-08-17 11:43:23 +0200 | [diff] [blame] | 352 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
| 353 | } |
| 354 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 355 | static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) |
| 356 | { |
| 357 | accel = !!accel; |
| 358 | if (accel == !!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) |
| 359 | return; |
| 360 | |
| 361 | if (accel) |
| 362 | wdata->state.flags |= WIIPROTO_FLAG_ACCEL; |
| 363 | else |
| 364 | wdata->state.flags &= ~WIIPROTO_FLAG_ACCEL; |
| 365 | |
| 366 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
| 367 | } |
| 368 | |
David Herrmann | be1ecd6 | 2011-09-06 13:50:33 +0200 | [diff] [blame] | 369 | #define wiiproto_req_wreg(wdata, os, buf, sz) \ |
| 370 | wiiproto_req_wmem((wdata), false, (os), (buf), (sz)) |
| 371 | |
| 372 | #define wiiproto_req_weeprom(wdata, os, buf, sz) \ |
| 373 | wiiproto_req_wmem((wdata), true, (os), (buf), (sz)) |
| 374 | |
| 375 | static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom, |
| 376 | __u32 offset, const __u8 *buf, __u8 size) |
| 377 | { |
| 378 | __u8 cmd[22]; |
| 379 | |
| 380 | if (size > 16 || size == 0) { |
| 381 | hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | memset(cmd, 0, sizeof(cmd)); |
| 386 | cmd[0] = WIIPROTO_REQ_WMEM; |
| 387 | cmd[2] = (offset >> 16) & 0xff; |
| 388 | cmd[3] = (offset >> 8) & 0xff; |
| 389 | cmd[4] = offset & 0xff; |
| 390 | cmd[5] = size; |
| 391 | memcpy(&cmd[6], buf, size); |
| 392 | |
| 393 | if (!eeprom) |
| 394 | cmd[1] |= 0x04; |
| 395 | |
| 396 | wiiproto_keep_rumble(wdata, &cmd[1]); |
| 397 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
| 398 | } |
| 399 | |
David Herrmann | 33e8401 | 2011-09-06 13:50:35 +0200 | [diff] [blame^] | 400 | /* requries the cmd-mutex to be held */ |
| 401 | static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset, |
| 402 | const __u8 *wmem, __u8 size) |
| 403 | { |
| 404 | unsigned long flags; |
| 405 | int ret; |
| 406 | |
| 407 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 408 | wiimote_cmd_set(wdata, WIIPROTO_REQ_WMEM, 0); |
| 409 | wiiproto_req_wreg(wdata, offset, wmem, size); |
| 410 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 411 | |
| 412 | ret = wiimote_cmd_wait(wdata); |
| 413 | if (!ret && wdata->state.cmd_err) |
| 414 | ret = -EIO; |
| 415 | |
| 416 | return ret; |
| 417 | } |
| 418 | |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 419 | static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) |
| 420 | { |
| 421 | struct wiimote_data *wdata; |
| 422 | struct device *dev = led_dev->dev->parent; |
| 423 | int i; |
| 424 | unsigned long flags; |
| 425 | bool value = false; |
David Herrmann | 3c1c2fc | 2011-07-05 13:45:19 +0200 | [diff] [blame] | 426 | |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 427 | wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev)); |
| 428 | |
| 429 | for (i = 0; i < 4; ++i) { |
| 430 | if (wdata->leds[i] == led_dev) { |
| 431 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 432 | value = wdata->state.flags & WIIPROTO_FLAG_LED(i + 1); |
| 433 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 434 | break; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return value ? LED_FULL : LED_OFF; |
| 439 | } |
| 440 | |
| 441 | static void wiimote_leds_set(struct led_classdev *led_dev, |
| 442 | enum led_brightness value) |
| 443 | { |
| 444 | struct wiimote_data *wdata; |
| 445 | struct device *dev = led_dev->dev->parent; |
| 446 | int i; |
| 447 | unsigned long flags; |
| 448 | __u8 state, flag; |
| 449 | |
| 450 | wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev)); |
| 451 | |
| 452 | for (i = 0; i < 4; ++i) { |
| 453 | if (wdata->leds[i] == led_dev) { |
| 454 | flag = WIIPROTO_FLAG_LED(i + 1); |
| 455 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 456 | state = wdata->state.flags; |
| 457 | if (value == LED_OFF) |
| 458 | wiiproto_req_leds(wdata, state & ~flag); |
| 459 | else |
| 460 | wiiproto_req_leds(wdata, state | flag); |
| 461 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | } |
David Herrmann | 3c1c2fc | 2011-07-05 13:45:19 +0200 | [diff] [blame] | 466 | |
David Herrmann | d020be9 | 2011-09-06 13:50:27 +0200 | [diff] [blame] | 467 | static int wiimote_ff_play(struct input_dev *dev, void *data, |
| 468 | struct ff_effect *eff) |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 469 | { |
David Herrmann | d020be9 | 2011-09-06 13:50:27 +0200 | [diff] [blame] | 470 | struct wiimote_data *wdata = input_get_drvdata(dev); |
| 471 | __u8 value; |
| 472 | unsigned long flags; |
| 473 | |
| 474 | /* |
| 475 | * The wiimote supports only a single rumble motor so if any magnitude |
| 476 | * is set to non-zero then we start the rumble motor. If both are set to |
| 477 | * zero, we stop the rumble motor. |
| 478 | */ |
| 479 | |
| 480 | if (eff->u.rumble.strong_magnitude || eff->u.rumble.weak_magnitude) |
| 481 | value = 1; |
| 482 | else |
| 483 | value = 0; |
| 484 | |
| 485 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 486 | wiiproto_req_rumble(wdata, value); |
| 487 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 488 | |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
David Herrmann | 26af174 | 2011-08-17 11:43:21 +0200 | [diff] [blame] | 492 | static int wiimote_input_open(struct input_dev *dev) |
| 493 | { |
| 494 | struct wiimote_data *wdata = input_get_drvdata(dev); |
| 495 | |
| 496 | return hid_hw_open(wdata->hdev); |
| 497 | } |
| 498 | |
| 499 | static void wiimote_input_close(struct input_dev *dev) |
| 500 | { |
| 501 | struct wiimote_data *wdata = input_get_drvdata(dev); |
| 502 | |
| 503 | hid_hw_close(wdata->hdev); |
| 504 | } |
| 505 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 506 | static int wiimote_accel_open(struct input_dev *dev) |
| 507 | { |
| 508 | struct wiimote_data *wdata = input_get_drvdata(dev); |
| 509 | int ret; |
| 510 | unsigned long flags; |
| 511 | |
| 512 | ret = hid_hw_open(wdata->hdev); |
| 513 | if (ret) |
| 514 | return ret; |
| 515 | |
| 516 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 517 | wiiproto_req_accel(wdata, true); |
| 518 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static void wiimote_accel_close(struct input_dev *dev) |
| 524 | { |
| 525 | struct wiimote_data *wdata = input_get_drvdata(dev); |
| 526 | unsigned long flags; |
| 527 | |
| 528 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 529 | wiiproto_req_accel(wdata, false); |
| 530 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 531 | |
| 532 | hid_hw_close(wdata->hdev); |
| 533 | } |
| 534 | |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 535 | static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) |
| 536 | { |
| 537 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_LEFT], |
| 538 | !!(payload[0] & 0x01)); |
| 539 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_RIGHT], |
| 540 | !!(payload[0] & 0x02)); |
| 541 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_DOWN], |
| 542 | !!(payload[0] & 0x04)); |
| 543 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_UP], |
| 544 | !!(payload[0] & 0x08)); |
| 545 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_PLUS], |
| 546 | !!(payload[0] & 0x10)); |
| 547 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_TWO], |
| 548 | !!(payload[1] & 0x01)); |
| 549 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_ONE], |
| 550 | !!(payload[1] & 0x02)); |
| 551 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_B], |
| 552 | !!(payload[1] & 0x04)); |
| 553 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_A], |
| 554 | !!(payload[1] & 0x08)); |
| 555 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_MINUS], |
| 556 | !!(payload[1] & 0x10)); |
| 557 | input_report_key(wdata->input, wiiproto_keymap[WIIPROTO_KEY_HOME], |
| 558 | !!(payload[1] & 0x80)); |
| 559 | input_sync(wdata->input); |
| 560 | } |
| 561 | |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 562 | static void handler_accel(struct wiimote_data *wdata, const __u8 *payload) |
| 563 | { |
| 564 | __u16 x, y, z; |
| 565 | |
| 566 | if (!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) |
| 567 | return; |
| 568 | |
| 569 | /* |
| 570 | * payload is: BB BB XX YY ZZ |
| 571 | * Accelerometer data is encoded into 3 10bit values. XX, YY and ZZ |
| 572 | * contain the upper 8 bits of each value. The lower 2 bits are |
| 573 | * contained in the buttons data BB BB. |
| 574 | * Bits 6 and 7 of the first buttons byte BB is the lower 2 bits of the |
| 575 | * X accel value. Bit 5 of the second buttons byte is the 2nd bit of Y |
| 576 | * accel value and bit 6 is the second bit of the Z value. |
| 577 | * The first bit of Y and Z values is not available and always set to 0. |
| 578 | * 0x200 is returned on no movement. |
| 579 | */ |
| 580 | |
| 581 | x = payload[2] << 2; |
| 582 | y = payload[3] << 2; |
| 583 | z = payload[4] << 2; |
| 584 | |
| 585 | x |= (payload[0] >> 5) & 0x3; |
| 586 | y |= (payload[1] >> 4) & 0x2; |
| 587 | z |= (payload[1] >> 5) & 0x2; |
| 588 | |
| 589 | input_report_abs(wdata->accel, ABS_RX, x - 0x200); |
| 590 | input_report_abs(wdata->accel, ABS_RY, y - 0x200); |
| 591 | input_report_abs(wdata->accel, ABS_RZ, z - 0x200); |
| 592 | input_sync(wdata->accel); |
| 593 | } |
| 594 | |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 595 | #define ir_to_input0(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ |
| 596 | ABS_HAT0X, ABS_HAT0Y) |
| 597 | #define ir_to_input1(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ |
| 598 | ABS_HAT1X, ABS_HAT1Y) |
| 599 | #define ir_to_input2(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ |
| 600 | ABS_HAT2X, ABS_HAT2Y) |
| 601 | #define ir_to_input3(wdata, ir, packed) __ir_to_input((wdata), (ir), (packed), \ |
| 602 | ABS_HAT3X, ABS_HAT3Y) |
| 603 | |
| 604 | static void __ir_to_input(struct wiimote_data *wdata, const __u8 *ir, |
| 605 | bool packed, __u8 xid, __u8 yid) |
| 606 | { |
| 607 | __u16 x, y; |
| 608 | |
| 609 | if (!(wdata->state.flags & WIIPROTO_FLAGS_IR)) |
| 610 | return; |
| 611 | |
| 612 | /* |
| 613 | * Basic IR data is encoded into 3 bytes. The first two bytes are the |
| 614 | * upper 8 bit of the X/Y data, the 3rd byte contains the lower 2 bits |
| 615 | * of both. |
| 616 | * If data is packed, then the 3rd byte is put first and slightly |
| 617 | * reordered. This allows to interleave packed and non-packed data to |
| 618 | * have two IR sets in 5 bytes instead of 6. |
| 619 | * The resulting 10bit X/Y values are passed to the ABS_HATXY input dev. |
| 620 | */ |
| 621 | |
| 622 | if (packed) { |
| 623 | x = ir[1] << 2; |
| 624 | y = ir[2] << 2; |
| 625 | |
| 626 | x |= ir[0] & 0x3; |
| 627 | y |= (ir[0] >> 2) & 0x3; |
| 628 | } else { |
| 629 | x = ir[0] << 2; |
| 630 | y = ir[1] << 2; |
| 631 | |
| 632 | x |= (ir[2] >> 4) & 0x3; |
| 633 | y |= (ir[2] >> 6) & 0x3; |
| 634 | } |
| 635 | |
| 636 | input_report_abs(wdata->ir, xid, x); |
| 637 | input_report_abs(wdata->ir, yid, y); |
| 638 | } |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 639 | |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 640 | static void handler_status(struct wiimote_data *wdata, const __u8 *payload) |
| 641 | { |
| 642 | handler_keys(wdata, payload); |
| 643 | |
| 644 | /* on status reports the drm is reset so we need to resend the drm */ |
| 645 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
| 646 | } |
| 647 | |
David Herrmann | be1ecd6 | 2011-09-06 13:50:33 +0200 | [diff] [blame] | 648 | static void handler_data(struct wiimote_data *wdata, const __u8 *payload) |
| 649 | { |
| 650 | handler_keys(wdata, payload); |
| 651 | } |
| 652 | |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 653 | static void handler_return(struct wiimote_data *wdata, const __u8 *payload) |
| 654 | { |
| 655 | __u8 err = payload[3]; |
| 656 | __u8 cmd = payload[2]; |
| 657 | |
| 658 | handler_keys(wdata, payload); |
| 659 | |
David Herrmann | 33e8401 | 2011-09-06 13:50:35 +0200 | [diff] [blame^] | 660 | if (wiimote_cmd_pending(wdata, cmd, 0)) { |
| 661 | wdata->state.cmd_err = err; |
| 662 | wiimote_cmd_complete(wdata); |
| 663 | } else if (err) { |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 664 | hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err, |
| 665 | cmd); |
David Herrmann | 33e8401 | 2011-09-06 13:50:35 +0200 | [diff] [blame^] | 666 | } |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 667 | } |
| 668 | |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 669 | static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload) |
| 670 | { |
| 671 | handler_keys(wdata, payload); |
| 672 | handler_accel(wdata, payload); |
| 673 | } |
| 674 | |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 675 | static void handler_drm_KE(struct wiimote_data *wdata, const __u8 *payload) |
| 676 | { |
| 677 | handler_keys(wdata, payload); |
| 678 | } |
| 679 | |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 680 | static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload) |
| 681 | { |
| 682 | handler_keys(wdata, payload); |
| 683 | handler_accel(wdata, payload); |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 684 | ir_to_input0(wdata, &payload[5], false); |
| 685 | ir_to_input1(wdata, &payload[8], false); |
| 686 | ir_to_input2(wdata, &payload[11], false); |
| 687 | ir_to_input3(wdata, &payload[14], false); |
| 688 | input_sync(wdata->ir); |
| 689 | } |
| 690 | |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 691 | static void handler_drm_KEE(struct wiimote_data *wdata, const __u8 *payload) |
| 692 | { |
| 693 | handler_keys(wdata, payload); |
| 694 | } |
| 695 | |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 696 | static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload) |
| 697 | { |
| 698 | handler_keys(wdata, payload); |
| 699 | ir_to_input0(wdata, &payload[2], false); |
| 700 | ir_to_input1(wdata, &payload[4], true); |
| 701 | ir_to_input2(wdata, &payload[7], false); |
| 702 | ir_to_input3(wdata, &payload[9], true); |
| 703 | input_sync(wdata->ir); |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static void handler_drm_KAE(struct wiimote_data *wdata, const __u8 *payload) |
| 707 | { |
| 708 | handler_keys(wdata, payload); |
| 709 | handler_accel(wdata, payload); |
| 710 | } |
| 711 | |
| 712 | static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload) |
| 713 | { |
| 714 | handler_keys(wdata, payload); |
| 715 | handler_accel(wdata, payload); |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 716 | ir_to_input0(wdata, &payload[5], false); |
| 717 | ir_to_input1(wdata, &payload[7], true); |
| 718 | ir_to_input2(wdata, &payload[10], false); |
| 719 | ir_to_input3(wdata, &payload[12], true); |
| 720 | input_sync(wdata->ir); |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 721 | } |
| 722 | |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 723 | static void handler_drm_E(struct wiimote_data *wdata, const __u8 *payload) |
| 724 | { |
| 725 | } |
| 726 | |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 727 | static void handler_drm_SKAI1(struct wiimote_data *wdata, const __u8 *payload) |
| 728 | { |
| 729 | handler_keys(wdata, payload); |
| 730 | |
| 731 | wdata->state.accel_split[0] = payload[2]; |
| 732 | wdata->state.accel_split[1] = (payload[0] >> 1) & (0x10 | 0x20); |
| 733 | wdata->state.accel_split[1] |= (payload[1] << 1) & (0x40 | 0x80); |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 734 | |
| 735 | ir_to_input0(wdata, &payload[3], false); |
| 736 | ir_to_input1(wdata, &payload[12], false); |
| 737 | input_sync(wdata->ir); |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | static void handler_drm_SKAI2(struct wiimote_data *wdata, const __u8 *payload) |
| 741 | { |
| 742 | __u8 buf[5]; |
| 743 | |
| 744 | handler_keys(wdata, payload); |
| 745 | |
| 746 | wdata->state.accel_split[1] |= (payload[0] >> 5) & (0x01 | 0x02); |
| 747 | wdata->state.accel_split[1] |= (payload[1] >> 3) & (0x04 | 0x08); |
| 748 | |
| 749 | buf[0] = 0; |
| 750 | buf[1] = 0; |
| 751 | buf[2] = wdata->state.accel_split[0]; |
| 752 | buf[3] = payload[2]; |
| 753 | buf[4] = wdata->state.accel_split[1]; |
| 754 | handler_accel(wdata, buf); |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 755 | |
| 756 | ir_to_input2(wdata, &payload[3], false); |
| 757 | ir_to_input3(wdata, &payload[12], false); |
| 758 | input_sync(wdata->ir); |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 759 | } |
| 760 | |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 761 | struct wiiproto_handler { |
| 762 | __u8 id; |
| 763 | size_t size; |
| 764 | void (*func)(struct wiimote_data *wdata, const __u8 *payload); |
| 765 | }; |
| 766 | |
| 767 | static struct wiiproto_handler handlers[] = { |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 768 | { .id = WIIPROTO_REQ_STATUS, .size = 6, .func = handler_status }, |
David Herrmann | be1ecd6 | 2011-09-06 13:50:33 +0200 | [diff] [blame] | 769 | { .id = WIIPROTO_REQ_DATA, .size = 21, .func = handler_data }, |
David Herrmann | c87019e | 2011-08-17 11:43:24 +0200 | [diff] [blame] | 770 | { .id = WIIPROTO_REQ_RETURN, .size = 4, .func = handler_return }, |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 771 | { .id = WIIPROTO_REQ_DRM_K, .size = 2, .func = handler_keys }, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 772 | { .id = WIIPROTO_REQ_DRM_KA, .size = 5, .func = handler_drm_KA }, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 773 | { .id = WIIPROTO_REQ_DRM_KE, .size = 10, .func = handler_drm_KE }, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 774 | { .id = WIIPROTO_REQ_DRM_KAI, .size = 17, .func = handler_drm_KAI }, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 775 | { .id = WIIPROTO_REQ_DRM_KEE, .size = 21, .func = handler_drm_KEE }, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 776 | { .id = WIIPROTO_REQ_DRM_KAE, .size = 21, .func = handler_drm_KAE }, |
David Herrmann | eac39e7 | 2011-09-06 13:50:31 +0200 | [diff] [blame] | 777 | { .id = WIIPROTO_REQ_DRM_KIE, .size = 21, .func = handler_drm_KIE }, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 778 | { .id = WIIPROTO_REQ_DRM_KAIE, .size = 21, .func = handler_drm_KAIE }, |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 779 | { .id = WIIPROTO_REQ_DRM_E, .size = 21, .func = handler_drm_E }, |
David Herrmann | efcf918 | 2011-09-06 13:50:29 +0200 | [diff] [blame] | 780 | { .id = WIIPROTO_REQ_DRM_SKAI1, .size = 21, .func = handler_drm_SKAI1 }, |
| 781 | { .id = WIIPROTO_REQ_DRM_SKAI2, .size = 21, .func = handler_drm_SKAI2 }, |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 782 | { .id = 0 } |
| 783 | }; |
| 784 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 785 | static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, |
| 786 | u8 *raw_data, int size) |
| 787 | { |
David Herrmann | 4d36e97 | 2011-07-05 13:45:12 +0200 | [diff] [blame] | 788 | struct wiimote_data *wdata = hid_get_drvdata(hdev); |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 789 | struct wiiproto_handler *h; |
| 790 | int i; |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 791 | unsigned long flags; |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 792 | bool handled = false; |
David Herrmann | 4d36e97 | 2011-07-05 13:45:12 +0200 | [diff] [blame] | 793 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 794 | if (size < 1) |
| 795 | return -EINVAL; |
| 796 | |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 797 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 798 | |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 799 | for (i = 0; handlers[i].id; ++i) { |
| 800 | h = &handlers[i]; |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 801 | if (h->id == raw_data[0] && h->size < size) { |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 802 | h->func(wdata, &raw_data[1]); |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 803 | handled = true; |
| 804 | } |
David Herrmann | a4d1919 | 2011-07-05 13:45:15 +0200 | [diff] [blame] | 805 | } |
| 806 | |
David Herrmann | 7336b9f | 2011-09-06 13:50:32 +0200 | [diff] [blame] | 807 | if (!handled) |
| 808 | hid_warn(hdev, "Unhandled report %hhu size %d\n", raw_data[0], |
| 809 | size); |
| 810 | |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 811 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 812 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 813 | return 0; |
| 814 | } |
| 815 | |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 816 | static void wiimote_leds_destroy(struct wiimote_data *wdata) |
| 817 | { |
| 818 | int i; |
| 819 | struct led_classdev *led; |
| 820 | |
| 821 | for (i = 0; i < 4; ++i) { |
| 822 | if (wdata->leds[i]) { |
| 823 | led = wdata->leds[i]; |
| 824 | wdata->leds[i] = NULL; |
| 825 | led_classdev_unregister(led); |
| 826 | kfree(led); |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | static int wiimote_leds_create(struct wiimote_data *wdata) |
| 832 | { |
| 833 | int i, ret; |
| 834 | struct device *dev = &wdata->hdev->dev; |
| 835 | size_t namesz = strlen(dev_name(dev)) + 9; |
| 836 | struct led_classdev *led; |
| 837 | char *name; |
| 838 | |
| 839 | for (i = 0; i < 4; ++i) { |
| 840 | led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL); |
| 841 | if (!led) { |
| 842 | ret = -ENOMEM; |
| 843 | goto err; |
| 844 | } |
| 845 | name = (void*)&led[1]; |
| 846 | snprintf(name, namesz, "%s:blue:p%d", dev_name(dev), i); |
| 847 | led->name = name; |
| 848 | led->brightness = 0; |
| 849 | led->max_brightness = 1; |
| 850 | led->brightness_get = wiimote_leds_get; |
| 851 | led->brightness_set = wiimote_leds_set; |
| 852 | |
| 853 | ret = led_classdev_register(dev, led); |
| 854 | if (ret) { |
| 855 | kfree(led); |
| 856 | goto err; |
| 857 | } |
| 858 | wdata->leds[i] = led; |
| 859 | } |
| 860 | |
| 861 | return 0; |
| 862 | |
| 863 | err: |
| 864 | wiimote_leds_destroy(wdata); |
| 865 | return ret; |
| 866 | } |
| 867 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 868 | static struct wiimote_data *wiimote_create(struct hid_device *hdev) |
| 869 | { |
| 870 | struct wiimote_data *wdata; |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 871 | int i; |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 872 | |
| 873 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); |
| 874 | if (!wdata) |
| 875 | return NULL; |
| 876 | |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 877 | wdata->input = input_allocate_device(); |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 878 | if (!wdata->input) |
| 879 | goto err; |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 880 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 881 | wdata->hdev = hdev; |
| 882 | hid_set_drvdata(hdev, wdata); |
| 883 | |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 884 | input_set_drvdata(wdata->input, wdata); |
David Herrmann | 26af174 | 2011-08-17 11:43:21 +0200 | [diff] [blame] | 885 | wdata->input->open = wiimote_input_open; |
| 886 | wdata->input->close = wiimote_input_close; |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 887 | wdata->input->dev.parent = &wdata->hdev->dev; |
| 888 | wdata->input->id.bustype = wdata->hdev->bus; |
| 889 | wdata->input->id.vendor = wdata->hdev->vendor; |
| 890 | wdata->input->id.product = wdata->hdev->product; |
| 891 | wdata->input->id.version = wdata->hdev->version; |
| 892 | wdata->input->name = WIIMOTE_NAME; |
| 893 | |
David Herrmann | 1abb9ad | 2011-07-05 13:45:16 +0200 | [diff] [blame] | 894 | set_bit(EV_KEY, wdata->input->evbit); |
| 895 | for (i = 0; i < WIIPROTO_KEY_COUNT; ++i) |
| 896 | set_bit(wiiproto_keymap[i], wdata->input->keybit); |
| 897 | |
David Herrmann | d020be9 | 2011-09-06 13:50:27 +0200 | [diff] [blame] | 898 | set_bit(FF_RUMBLE, wdata->input->ffbit); |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 899 | if (input_ff_create_memless(wdata->input, NULL, wiimote_ff_play)) |
| 900 | goto err_input; |
| 901 | |
| 902 | wdata->accel = input_allocate_device(); |
| 903 | if (!wdata->accel) |
| 904 | goto err_input; |
| 905 | |
| 906 | input_set_drvdata(wdata->accel, wdata); |
| 907 | wdata->accel->open = wiimote_accel_open; |
| 908 | wdata->accel->close = wiimote_accel_close; |
| 909 | wdata->accel->dev.parent = &wdata->hdev->dev; |
| 910 | wdata->accel->id.bustype = wdata->hdev->bus; |
| 911 | wdata->accel->id.vendor = wdata->hdev->vendor; |
| 912 | wdata->accel->id.product = wdata->hdev->product; |
| 913 | wdata->accel->id.version = wdata->hdev->version; |
| 914 | wdata->accel->name = WIIMOTE_NAME " Accelerometer"; |
| 915 | |
| 916 | set_bit(EV_ABS, wdata->accel->evbit); |
| 917 | set_bit(ABS_RX, wdata->accel->absbit); |
| 918 | set_bit(ABS_RY, wdata->accel->absbit); |
| 919 | set_bit(ABS_RZ, wdata->accel->absbit); |
| 920 | input_set_abs_params(wdata->accel, ABS_RX, -500, 500, 2, 4); |
| 921 | input_set_abs_params(wdata->accel, ABS_RY, -500, 500, 2, 4); |
| 922 | input_set_abs_params(wdata->accel, ABS_RZ, -500, 500, 2, 4); |
David Herrmann | d020be9 | 2011-09-06 13:50:27 +0200 | [diff] [blame] | 923 | |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 924 | wdata->ir = input_allocate_device(); |
| 925 | if (!wdata->ir) |
| 926 | goto err_ir; |
| 927 | |
| 928 | input_set_drvdata(wdata->ir, wdata); |
| 929 | wdata->ir->dev.parent = &wdata->hdev->dev; |
| 930 | wdata->ir->id.bustype = wdata->hdev->bus; |
| 931 | wdata->ir->id.vendor = wdata->hdev->vendor; |
| 932 | wdata->ir->id.product = wdata->hdev->product; |
| 933 | wdata->ir->id.version = wdata->hdev->version; |
| 934 | wdata->ir->name = WIIMOTE_NAME " IR"; |
| 935 | |
| 936 | set_bit(EV_ABS, wdata->ir->evbit); |
| 937 | set_bit(ABS_HAT0X, wdata->ir->absbit); |
| 938 | set_bit(ABS_HAT0Y, wdata->ir->absbit); |
| 939 | set_bit(ABS_HAT1X, wdata->ir->absbit); |
| 940 | set_bit(ABS_HAT1Y, wdata->ir->absbit); |
| 941 | set_bit(ABS_HAT2X, wdata->ir->absbit); |
| 942 | set_bit(ABS_HAT2Y, wdata->ir->absbit); |
| 943 | set_bit(ABS_HAT3X, wdata->ir->absbit); |
| 944 | set_bit(ABS_HAT3Y, wdata->ir->absbit); |
| 945 | input_set_abs_params(wdata->ir, ABS_HAT0X, 0, 1023, 2, 4); |
| 946 | input_set_abs_params(wdata->ir, ABS_HAT0Y, 0, 767, 2, 4); |
| 947 | input_set_abs_params(wdata->ir, ABS_HAT1X, 0, 1023, 2, 4); |
| 948 | input_set_abs_params(wdata->ir, ABS_HAT1Y, 0, 767, 2, 4); |
| 949 | input_set_abs_params(wdata->ir, ABS_HAT2X, 0, 1023, 2, 4); |
| 950 | input_set_abs_params(wdata->ir, ABS_HAT2Y, 0, 767, 2, 4); |
| 951 | input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4); |
| 952 | input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4); |
| 953 | |
David Herrmann | 23c063c | 2011-07-05 13:45:14 +0200 | [diff] [blame] | 954 | spin_lock_init(&wdata->qlock); |
| 955 | INIT_WORK(&wdata->worker, wiimote_worker); |
| 956 | |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 957 | spin_lock_init(&wdata->state.lock); |
David Herrmann | 29d2806 | 2011-09-06 13:50:34 +0200 | [diff] [blame] | 958 | init_completion(&wdata->state.ready); |
| 959 | mutex_init(&wdata->state.sync); |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 960 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 961 | return wdata; |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 962 | |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 963 | err_ir: |
| 964 | input_free_device(wdata->accel); |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 965 | err_input: |
| 966 | input_free_device(wdata->input); |
| 967 | err: |
| 968 | kfree(wdata); |
| 969 | return NULL; |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static void wiimote_destroy(struct wiimote_data *wdata) |
| 973 | { |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 974 | wiimote_leds_destroy(wdata); |
David Herrmann | 3989ef6 | 2011-08-17 11:43:20 +0200 | [diff] [blame] | 975 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 976 | input_unregister_device(wdata->accel); |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 977 | input_unregister_device(wdata->ir); |
David Herrmann | 3989ef6 | 2011-08-17 11:43:20 +0200 | [diff] [blame] | 978 | input_unregister_device(wdata->input); |
| 979 | cancel_work_sync(&wdata->worker); |
| 980 | hid_hw_stop(wdata->hdev); |
| 981 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 982 | kfree(wdata); |
| 983 | } |
| 984 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 985 | static int wiimote_hid_probe(struct hid_device *hdev, |
| 986 | const struct hid_device_id *id) |
| 987 | { |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 988 | struct wiimote_data *wdata; |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 989 | int ret; |
| 990 | |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 991 | wdata = wiimote_create(hdev); |
| 992 | if (!wdata) { |
| 993 | hid_err(hdev, "Can't alloc device\n"); |
| 994 | return -ENOMEM; |
| 995 | } |
| 996 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 997 | ret = hid_parse(hdev); |
| 998 | if (ret) { |
| 999 | hid_err(hdev, "HID parse failed\n"); |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1000 | goto err; |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); |
| 1004 | if (ret) { |
| 1005 | hid_err(hdev, "HW start failed\n"); |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1006 | goto err; |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1007 | } |
| 1008 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 1009 | ret = input_register_device(wdata->accel); |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 1010 | if (ret) { |
| 1011 | hid_err(hdev, "Cannot register input device\n"); |
| 1012 | goto err_stop; |
| 1013 | } |
| 1014 | |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 1015 | ret = input_register_device(wdata->ir); |
| 1016 | if (ret) { |
| 1017 | hid_err(hdev, "Cannot register input device\n"); |
| 1018 | goto err_ir; |
| 1019 | } |
| 1020 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 1021 | ret = input_register_device(wdata->input); |
| 1022 | if (ret) { |
| 1023 | hid_err(hdev, "Cannot register input device\n"); |
| 1024 | goto err_input; |
| 1025 | } |
| 1026 | |
David Herrmann | 23a5a4a | 2011-08-17 11:43:22 +0200 | [diff] [blame] | 1027 | ret = wiimote_leds_create(wdata); |
David Herrmann | 3989ef6 | 2011-08-17 11:43:20 +0200 | [diff] [blame] | 1028 | if (ret) |
| 1029 | goto err_free; |
| 1030 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1031 | hid_info(hdev, "New device registered\n"); |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 1032 | |
| 1033 | /* by default set led1 after device initialization */ |
| 1034 | spin_lock_irq(&wdata->state.lock); |
David Herrmann | db30834 | 2011-07-05 13:45:17 +0200 | [diff] [blame] | 1035 | wiiproto_req_leds(wdata, WIIPROTO_FLAG_LED1); |
David Herrmann | 32a0d9a | 2011-07-05 13:45:18 +0200 | [diff] [blame] | 1036 | spin_unlock_irq(&wdata->state.lock); |
| 1037 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1038 | return 0; |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1039 | |
David Herrmann | 3989ef6 | 2011-08-17 11:43:20 +0200 | [diff] [blame] | 1040 | err_free: |
| 1041 | wiimote_destroy(wdata); |
| 1042 | return ret; |
| 1043 | |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 1044 | err_input: |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 1045 | input_unregister_device(wdata->ir); |
| 1046 | wdata->ir = NULL; |
| 1047 | err_ir: |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 1048 | input_unregister_device(wdata->accel); |
| 1049 | wdata->accel = NULL; |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 1050 | err_stop: |
| 1051 | hid_hw_stop(hdev); |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1052 | err: |
David Herrmann | f363e4f | 2011-09-06 13:50:30 +0200 | [diff] [blame] | 1053 | input_free_device(wdata->ir); |
David Herrmann | 98a558a | 2011-09-06 13:50:28 +0200 | [diff] [blame] | 1054 | input_free_device(wdata->accel); |
David Herrmann | 672bc4e | 2011-07-05 13:45:11 +0200 | [diff] [blame] | 1055 | input_free_device(wdata->input); |
David Herrmann | 3989ef6 | 2011-08-17 11:43:20 +0200 | [diff] [blame] | 1056 | kfree(wdata); |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1057 | return ret; |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static void wiimote_hid_remove(struct hid_device *hdev) |
| 1061 | { |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1062 | struct wiimote_data *wdata = hid_get_drvdata(hdev); |
| 1063 | |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1064 | hid_info(hdev, "Device removed\n"); |
David Herrmann | e894d0e | 2011-07-05 13:45:10 +0200 | [diff] [blame] | 1065 | wiimote_destroy(wdata); |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static const struct hid_device_id wiimote_hid_devices[] = { |
| 1069 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, |
| 1070 | USB_DEVICE_ID_NINTENDO_WIIMOTE) }, |
| 1071 | { } |
| 1072 | }; |
| 1073 | MODULE_DEVICE_TABLE(hid, wiimote_hid_devices); |
| 1074 | |
| 1075 | static struct hid_driver wiimote_hid_driver = { |
| 1076 | .name = "wiimote", |
| 1077 | .id_table = wiimote_hid_devices, |
| 1078 | .probe = wiimote_hid_probe, |
| 1079 | .remove = wiimote_hid_remove, |
| 1080 | .raw_event = wiimote_hid_event, |
| 1081 | }; |
| 1082 | |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 1083 | static int __init wiimote_init(void) |
| 1084 | { |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1085 | int ret; |
| 1086 | |
| 1087 | ret = hid_register_driver(&wiimote_hid_driver); |
| 1088 | if (ret) |
| 1089 | pr_err("Can't register wiimote hid driver\n"); |
| 1090 | |
| 1091 | return ret; |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static void __exit wiimote_exit(void) |
| 1095 | { |
David Herrmann | 02fb72a | 2011-07-05 13:45:09 +0200 | [diff] [blame] | 1096 | hid_unregister_driver(&wiimote_hid_driver); |
David Herrmann | fb51b44 | 2011-07-05 13:45:08 +0200 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | module_init(wiimote_init); |
| 1100 | module_exit(wiimote_exit); |
| 1101 | MODULE_LICENSE("GPL"); |
| 1102 | MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); |
| 1103 | MODULE_DESCRIPTION(WIIMOTE_NAME " Device Driver"); |
| 1104 | MODULE_VERSION(WIIMOTE_VERSION); |