diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-05-05 17:13:06 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-06-03 05:07:05 -0400 |
commit | 45ec9fff8629dda47d0c7645174220bcf5d9b6ba (patch) | |
tree | 6edad63c4aab27f5ec74a3afa8a1174d600e2316 /drivers/hid | |
parent | 8b1fded7a352cbd926b314d3b42a538a848c15d8 (diff) |
HID: wiimote: remove old static extension support
We now have dynamic hotplug support so the old static extensions are no
longer needed nor used. Remove it along CONFIG_HID_WIIMOTE_EXT.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/Kconfig | 9 | ||||
-rw-r--r-- | drivers/hid/Makefile | 3 | ||||
-rw-r--r-- | drivers/hid/hid-wiimote-ext.c | 837 | ||||
-rw-r--r-- | drivers/hid/hid-wiimote.h | 19 |
4 files changed, 0 insertions, 868 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 76e2d5d5c23e..dc9adfedabdf 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -731,15 +731,6 @@ config HID_WIIMOTE | |||
731 | To compile this driver as a module, choose M here: the | 731 | To compile this driver as a module, choose M here: the |
732 | module will be called hid-wiimote. | 732 | module will be called hid-wiimote. |
733 | 733 | ||
734 | config HID_WIIMOTE_EXT | ||
735 | bool "Nintendo Wii Remote Extension support" | ||
736 | depends on HID_WIIMOTE | ||
737 | default HID_WIIMOTE | ||
738 | ---help--- | ||
739 | Support for extension controllers of the Nintendo Wii Remote. Say yes | ||
740 | here if you want to use the Nintendo Motion+, Nunchuck or Classic | ||
741 | extension controllers with your Wii Remote. | ||
742 | |||
743 | config HID_ZEROPLUS | 734 | config HID_ZEROPLUS |
744 | tristate "Zeroplus based game controller support" | 735 | tristate "Zeroplus based game controller support" |
745 | depends on HID | 736 | depends on HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 2c2222684043..6a1215b87be3 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -29,9 +29,6 @@ ifdef CONFIG_LOGIWHEELS_FF | |||
29 | endif | 29 | endif |
30 | 30 | ||
31 | hid-wiimote-y := hid-wiimote-core.o hid-wiimote-modules.o | 31 | hid-wiimote-y := hid-wiimote-core.o hid-wiimote-modules.o |
32 | ifdef CONFIG_HID_WIIMOTE_EXT | ||
33 | hid-wiimote-y += hid-wiimote-ext.o | ||
34 | endif | ||
35 | ifdef CONFIG_DEBUG_FS | 32 | ifdef CONFIG_DEBUG_FS |
36 | hid-wiimote-y += hid-wiimote-debug.o | 33 | hid-wiimote-y += hid-wiimote-debug.o |
37 | endif | 34 | endif |
diff --git a/drivers/hid/hid-wiimote-ext.c b/drivers/hid/hid-wiimote-ext.c deleted file mode 100644 index 267c89c46d3e..000000000000 --- a/drivers/hid/hid-wiimote-ext.c +++ /dev/null | |||
@@ -1,837 +0,0 @@ | |||
1 | /* | ||
2 | * HID driver for Nintendo Wii / Wii U peripheral extensions | ||
3 | * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com> | ||
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 | |||
13 | #include <linux/atomic.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | #include <linux/workqueue.h> | ||
17 | #include "hid-wiimote.h" | ||
18 | |||
19 | struct wiimote_ext { | ||
20 | struct wiimote_data *wdata; | ||
21 | struct work_struct worker; | ||
22 | struct input_dev *input; | ||
23 | struct input_dev *mp_input; | ||
24 | |||
25 | atomic_t opened; | ||
26 | atomic_t mp_opened; | ||
27 | bool plugged; | ||
28 | bool mp_plugged; | ||
29 | bool motionp; | ||
30 | __u8 ext_type; | ||
31 | __u16 calib[4][3]; | ||
32 | }; | ||
33 | |||
34 | enum wiiext_type { | ||
35 | WIIEXT_NONE, /* placeholder */ | ||
36 | WIIEXT_CLASSIC, /* Nintendo classic controller */ | ||
37 | WIIEXT_NUNCHUCK, /* Nintendo nunchuck controller */ | ||
38 | WIIEXT_BALANCE_BOARD, /* Nintendo balance board controller */ | ||
39 | }; | ||
40 | |||
41 | enum wiiext_keys { | ||
42 | WIIEXT_KEY_C, | ||
43 | WIIEXT_KEY_Z, | ||
44 | WIIEXT_KEY_A, | ||
45 | WIIEXT_KEY_B, | ||
46 | WIIEXT_KEY_X, | ||
47 | WIIEXT_KEY_Y, | ||
48 | WIIEXT_KEY_ZL, | ||
49 | WIIEXT_KEY_ZR, | ||
50 | WIIEXT_KEY_PLUS, | ||
51 | WIIEXT_KEY_MINUS, | ||
52 | WIIEXT_KEY_HOME, | ||
53 | WIIEXT_KEY_LEFT, | ||
54 | WIIEXT_KEY_RIGHT, | ||
55 | WIIEXT_KEY_UP, | ||
56 | WIIEXT_KEY_DOWN, | ||
57 | WIIEXT_KEY_LT, | ||
58 | WIIEXT_KEY_RT, | ||
59 | WIIEXT_KEY_COUNT | ||
60 | }; | ||
61 | |||
62 | static __u16 wiiext_keymap[] = { | ||
63 | BTN_C, /* WIIEXT_KEY_C */ | ||
64 | BTN_Z, /* WIIEXT_KEY_Z */ | ||
65 | BTN_A, /* WIIEXT_KEY_A */ | ||
66 | BTN_B, /* WIIEXT_KEY_B */ | ||
67 | BTN_X, /* WIIEXT_KEY_X */ | ||
68 | BTN_Y, /* WIIEXT_KEY_Y */ | ||
69 | BTN_TL2, /* WIIEXT_KEY_ZL */ | ||
70 | BTN_TR2, /* WIIEXT_KEY_ZR */ | ||
71 | KEY_NEXT, /* WIIEXT_KEY_PLUS */ | ||
72 | KEY_PREVIOUS, /* WIIEXT_KEY_MINUS */ | ||
73 | BTN_MODE, /* WIIEXT_KEY_HOME */ | ||
74 | KEY_LEFT, /* WIIEXT_KEY_LEFT */ | ||
75 | KEY_RIGHT, /* WIIEXT_KEY_RIGHT */ | ||
76 | KEY_UP, /* WIIEXT_KEY_UP */ | ||
77 | KEY_DOWN, /* WIIEXT_KEY_DOWN */ | ||
78 | BTN_TL, /* WIIEXT_KEY_LT */ | ||
79 | BTN_TR, /* WIIEXT_KEY_RT */ | ||
80 | }; | ||
81 | |||
82 | /* disable all extensions */ | ||
83 | static void ext_disable(struct wiimote_ext *ext) | ||
84 | { | ||
85 | unsigned long flags; | ||
86 | __u8 wmem = 0x55; | ||
87 | |||
88 | if (!wiimote_cmd_acquire(ext->wdata)) { | ||
89 | wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem)); | ||
90 | wiimote_cmd_release(ext->wdata); | ||
91 | } | ||
92 | |||
93 | spin_lock_irqsave(&ext->wdata->state.lock, flags); | ||
94 | ext->motionp = false; | ||
95 | ext->ext_type = WIIEXT_NONE; | ||
96 | wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL); | ||
97 | spin_unlock_irqrestore(&ext->wdata->state.lock, flags); | ||
98 | } | ||
99 | |||
100 | static bool motionp_read(struct wiimote_ext *ext) | ||
101 | { | ||
102 | __u8 rmem[2], wmem; | ||
103 | ssize_t ret; | ||
104 | bool avail = false; | ||
105 | |||
106 | if (!atomic_read(&ext->mp_opened)) | ||
107 | return false; | ||
108 | |||
109 | if (wiimote_cmd_acquire(ext->wdata)) | ||
110 | return false; | ||
111 | |||
112 | /* initialize motion plus */ | ||
113 | wmem = 0x55; | ||
114 | ret = wiimote_cmd_write(ext->wdata, 0xa600f0, &wmem, sizeof(wmem)); | ||
115 | if (ret) | ||
116 | goto error; | ||
117 | |||
118 | /* read motion plus ID */ | ||
119 | ret = wiimote_cmd_read(ext->wdata, 0xa600fe, rmem, 2); | ||
120 | if (ret == 2 || rmem[1] == 0x5) | ||
121 | avail = true; | ||
122 | |||
123 | error: | ||
124 | wiimote_cmd_release(ext->wdata); | ||
125 | return avail; | ||
126 | } | ||
127 | |||
128 | static __u8 ext_read(struct wiimote_ext *ext) | ||
129 | { | ||
130 | ssize_t ret; | ||
131 | __u8 buf[24], i, j, offs = 0; | ||
132 | __u8 rmem[2], wmem; | ||
133 | __u8 type = WIIEXT_NONE; | ||
134 | |||
135 | if (!ext->plugged || !atomic_read(&ext->opened)) | ||
136 | return WIIEXT_NONE; | ||
137 | |||
138 | if (wiimote_cmd_acquire(ext->wdata)) | ||
139 | return WIIEXT_NONE; | ||
140 | |||
141 | /* initialize extension */ | ||
142 | wmem = 0x55; | ||
143 | ret = wiimote_cmd_write(ext->wdata, 0xa400f0, &wmem, sizeof(wmem)); | ||
144 | if (!ret) { | ||
145 | /* disable encryption */ | ||
146 | wmem = 0x0; | ||
147 | wiimote_cmd_write(ext->wdata, 0xa400fb, &wmem, sizeof(wmem)); | ||
148 | } | ||
149 | |||
150 | /* read extension ID */ | ||
151 | ret = wiimote_cmd_read(ext->wdata, 0xa400fe, rmem, 2); | ||
152 | if (ret == 2) { | ||
153 | if (rmem[0] == 0 && rmem[1] == 0) | ||
154 | type = WIIEXT_NUNCHUCK; | ||
155 | else if (rmem[0] == 0x01 && rmem[1] == 0x01) | ||
156 | type = WIIEXT_CLASSIC; | ||
157 | else if (rmem[0] == 0x04 && rmem[1] == 0x02) | ||
158 | type = WIIEXT_BALANCE_BOARD; | ||
159 | } | ||
160 | |||
161 | /* get balance board calibration data */ | ||
162 | if (type == WIIEXT_BALANCE_BOARD) { | ||
163 | ret = wiimote_cmd_read(ext->wdata, 0xa40024, buf, 12); | ||
164 | ret += wiimote_cmd_read(ext->wdata, 0xa40024 + 12, | ||
165 | buf + 12, 12); | ||
166 | |||
167 | if (ret != 24) { | ||
168 | type = WIIEXT_NONE; | ||
169 | } else { | ||
170 | for (i = 0; i < 3; i++) { | ||
171 | for (j = 0; j < 4; j++) { | ||
172 | ext->calib[j][i] = buf[offs]; | ||
173 | ext->calib[j][i] <<= 8; | ||
174 | ext->calib[j][i] |= buf[offs + 1]; | ||
175 | offs += 2; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | wiimote_cmd_release(ext->wdata); | ||
182 | |||
183 | return type; | ||
184 | } | ||
185 | |||
186 | static void ext_enable(struct wiimote_ext *ext, bool motionp, __u8 ext_type) | ||
187 | { | ||
188 | unsigned long flags; | ||
189 | __u8 wmem; | ||
190 | int ret; | ||
191 | |||
192 | if (motionp) { | ||
193 | if (wiimote_cmd_acquire(ext->wdata)) | ||
194 | return; | ||
195 | |||
196 | if (ext_type == WIIEXT_CLASSIC) | ||
197 | wmem = 0x07; | ||
198 | else if (ext_type == WIIEXT_NUNCHUCK) | ||
199 | wmem = 0x05; | ||
200 | else | ||
201 | wmem = 0x04; | ||
202 | |||
203 | ret = wiimote_cmd_write(ext->wdata, 0xa600fe, &wmem, sizeof(wmem)); | ||
204 | wiimote_cmd_release(ext->wdata); | ||
205 | if (ret) | ||
206 | return; | ||
207 | } | ||
208 | |||
209 | spin_lock_irqsave(&ext->wdata->state.lock, flags); | ||
210 | ext->motionp = motionp; | ||
211 | ext->ext_type = ext_type; | ||
212 | wiiproto_req_drm(ext->wdata, WIIPROTO_REQ_NULL); | ||
213 | spin_unlock_irqrestore(&ext->wdata->state.lock, flags); | ||
214 | } | ||
215 | |||
216 | static void wiiext_worker(struct work_struct *work) | ||
217 | { | ||
218 | struct wiimote_ext *ext = container_of(work, struct wiimote_ext, | ||
219 | worker); | ||
220 | bool motionp; | ||
221 | __u8 ext_type; | ||
222 | |||
223 | ext_disable(ext); | ||
224 | motionp = motionp_read(ext); | ||
225 | ext_type = ext_read(ext); | ||
226 | ext_enable(ext, motionp, ext_type); | ||
227 | } | ||
228 | |||
229 | /* schedule work only once, otherwise mark for reschedule */ | ||
230 | static void wiiext_schedule(struct wiimote_ext *ext) | ||
231 | { | ||
232 | schedule_work(&ext->worker); | ||
233 | } | ||
234 | |||
235 | /* | ||
236 | * Reacts on extension port events | ||
237 | * Whenever the driver gets an event from the wiimote that an extension has been | ||
238 | * plugged or unplugged, this funtion shall be called. It checks what extensions | ||
239 | * are connected and initializes and activates them. | ||
240 | * This can be called in atomic context. The initialization is done in a | ||
241 | * separate worker thread. The state.lock spinlock must be held by the caller. | ||
242 | */ | ||
243 | void wiiext_event(struct wiimote_data *wdata, bool plugged) | ||
244 | { | ||
245 | if (!wdata->ext) | ||
246 | return; | ||
247 | |||
248 | if (wdata->ext->plugged == plugged) | ||
249 | return; | ||
250 | |||
251 | wdata->ext->plugged = plugged; | ||
252 | |||
253 | if (!plugged) | ||
254 | wdata->ext->mp_plugged = false; | ||
255 | |||
256 | /* | ||
257 | * We need to call wiiext_schedule(wdata->ext) here, however, the | ||
258 | * extension initialization logic is not fully understood and so | ||
259 | * automatic initialization is not supported, yet. | ||
260 | */ | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * Returns true if the current DRM mode should contain extension data and false | ||
265 | * if there is no interest in extension data. | ||
266 | * All supported extensions send 6 byte extension data so any DRM that contains | ||
267 | * extension bytes is fine. | ||
268 | * The caller must hold the state.lock spinlock. | ||
269 | */ | ||
270 | bool wiiext_active(struct wiimote_data *wdata) | ||
271 | { | ||
272 | if (!wdata->ext) | ||
273 | return false; | ||
274 | |||
275 | return wdata->ext->motionp || wdata->ext->ext_type; | ||
276 | } | ||
277 | |||
278 | static void handler_motionp(struct wiimote_ext *ext, const __u8 *payload) | ||
279 | { | ||
280 | __s32 x, y, z; | ||
281 | bool plugged; | ||
282 | |||
283 | /* | 8 7 6 5 4 3 | 2 | 1 | | ||
284 | * -----+------------------------------+-----+-----+ | ||
285 | * 1 | Yaw Speed <7:0> | | ||
286 | * 2 | Roll Speed <7:0> | | ||
287 | * 3 | Pitch Speed <7:0> | | ||
288 | * -----+------------------------------+-----+-----+ | ||
289 | * 4 | Yaw Speed <13:8> | Yaw |Pitch| | ||
290 | * -----+------------------------------+-----+-----+ | ||
291 | * 5 | Roll Speed <13:8> |Roll | Ext | | ||
292 | * -----+------------------------------+-----+-----+ | ||
293 | * 6 | Pitch Speed <13:8> | 1 | 0 | | ||
294 | * -----+------------------------------+-----+-----+ | ||
295 | * The single bits Yaw, Roll, Pitch in the lower right corner specify | ||
296 | * whether the wiimote is rotating fast (0) or slow (1). Speed for slow | ||
297 | * roation is 440 deg/s and for fast rotation 2000 deg/s. To get a | ||
298 | * linear scale we multiply by 2000/440 = ~4.5454 which is 18 for fast | ||
299 | * and 9 for slow. | ||
300 | * If the wiimote is not rotating the sensor reports 2^13 = 8192. | ||
301 | * Ext specifies whether an extension is connected to the motionp. | ||
302 | */ | ||
303 | |||
304 | x = payload[0]; | ||
305 | y = payload[1]; | ||
306 | z = payload[2]; | ||
307 | |||
308 | x |= (((__u16)payload[3]) << 6) & 0xff00; | ||
309 | y |= (((__u16)payload[4]) << 6) & 0xff00; | ||
310 | z |= (((__u16)payload[5]) << 6) & 0xff00; | ||
311 | |||
312 | x -= 8192; | ||
313 | y -= 8192; | ||
314 | z -= 8192; | ||
315 | |||
316 | if (!(payload[3] & 0x02)) | ||
317 | x *= 18; | ||
318 | else | ||
319 | x *= 9; | ||
320 | if (!(payload[4] & 0x02)) | ||
321 | y *= 18; | ||
322 | else | ||
323 | y *= 9; | ||
324 | if (!(payload[3] & 0x01)) | ||
325 | z *= 18; | ||
326 | else | ||
327 | z *= 9; | ||
328 | |||
329 | input_report_abs(ext->mp_input, ABS_RX, x); | ||
330 | input_report_abs(ext->mp_input, ABS_RY, y); | ||
331 | input_report_abs(ext->mp_input, ABS_RZ, z); | ||
332 | input_sync(ext->mp_input); | ||
333 | |||
334 | plugged = payload[5] & 0x01; | ||
335 | if (plugged != ext->mp_plugged) | ||
336 | ext->mp_plugged = plugged; | ||
337 | } | ||
338 | |||
339 | static void handler_nunchuck(struct wiimote_ext *ext, const __u8 *payload) | ||
340 | { | ||
341 | __s16 x, y, z, bx, by; | ||
342 | |||
343 | /* Byte | 8 7 | 6 5 | 4 3 | 2 | 1 | | ||
344 | * -----+----------+---------+---------+----+-----+ | ||
345 | * 1 | Button X <7:0> | | ||
346 | * 2 | Button Y <7:0> | | ||
347 | * -----+----------+---------+---------+----+-----+ | ||
348 | * 3 | Speed X <9:2> | | ||
349 | * 4 | Speed Y <9:2> | | ||
350 | * 5 | Speed Z <9:2> | | ||
351 | * -----+----------+---------+---------+----+-----+ | ||
352 | * 6 | Z <1:0> | Y <1:0> | X <1:0> | BC | BZ | | ||
353 | * -----+----------+---------+---------+----+-----+ | ||
354 | * Button X/Y is the analog stick. Speed X, Y and Z are the | ||
355 | * accelerometer data in the same format as the wiimote's accelerometer. | ||
356 | * The 6th byte contains the LSBs of the accelerometer data. | ||
357 | * BC and BZ are the C and Z buttons: 0 means pressed | ||
358 | * | ||
359 | * If reported interleaved with motionp, then the layout changes. The | ||
360 | * 5th and 6th byte changes to: | ||
361 | * -----+-----------------------------------+-----+ | ||
362 | * 5 | Speed Z <9:3> | EXT | | ||
363 | * -----+--------+-----+-----+----+----+----+-----+ | ||
364 | * 6 |Z <2:1> |Y <1>|X <1>| BC | BZ | 0 | 0 | | ||
365 | * -----+--------+-----+-----+----+----+----+-----+ | ||
366 | * All three accelerometer values lose their LSB. The other data is | ||
367 | * still available but slightly moved. | ||
368 | * | ||
369 | * Center data for button values is 128. Center value for accelerometer | ||
370 | * values it 512 / 0x200 | ||
371 | */ | ||
372 | |||
373 | bx = payload[0]; | ||
374 | by = payload[1]; | ||
375 | bx -= 128; | ||
376 | by -= 128; | ||
377 | |||
378 | x = payload[2] << 2; | ||
379 | y = payload[3] << 2; | ||
380 | z = payload[4] << 2; | ||
381 | |||
382 | if (ext->motionp) { | ||
383 | x |= (payload[5] >> 3) & 0x02; | ||
384 | y |= (payload[5] >> 4) & 0x02; | ||
385 | z &= ~0x4; | ||
386 | z |= (payload[5] >> 5) & 0x06; | ||
387 | } else { | ||
388 | x |= (payload[5] >> 2) & 0x03; | ||
389 | y |= (payload[5] >> 4) & 0x03; | ||
390 | z |= (payload[5] >> 6) & 0x03; | ||
391 | } | ||
392 | |||
393 | x -= 0x200; | ||
394 | y -= 0x200; | ||
395 | z -= 0x200; | ||
396 | |||
397 | input_report_abs(ext->input, ABS_HAT0X, bx); | ||
398 | input_report_abs(ext->input, ABS_HAT0Y, by); | ||
399 | |||
400 | input_report_abs(ext->input, ABS_RX, x); | ||
401 | input_report_abs(ext->input, ABS_RY, y); | ||
402 | input_report_abs(ext->input, ABS_RZ, z); | ||
403 | |||
404 | if (ext->motionp) { | ||
405 | input_report_key(ext->input, | ||
406 | wiiext_keymap[WIIEXT_KEY_Z], !(payload[5] & 0x04)); | ||
407 | input_report_key(ext->input, | ||
408 | wiiext_keymap[WIIEXT_KEY_C], !(payload[5] & 0x08)); | ||
409 | } else { | ||
410 | input_report_key(ext->input, | ||
411 | wiiext_keymap[WIIEXT_KEY_Z], !(payload[5] & 0x01)); | ||
412 | input_report_key(ext->input, | ||
413 | wiiext_keymap[WIIEXT_KEY_C], !(payload[5] & 0x02)); | ||
414 | } | ||
415 | |||
416 | input_sync(ext->input); | ||
417 | } | ||
418 | |||
419 | static void handler_classic(struct wiimote_ext *ext, const __u8 *payload) | ||
420 | { | ||
421 | __s8 rx, ry, lx, ly, lt, rt; | ||
422 | |||
423 | /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | | ||
424 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
425 | * 1 | RX <5:4> | LX <5:0> | | ||
426 | * 2 | RX <3:2> | LY <5:0> | | ||
427 | * -----+-----+-----+-----+-----------------------------+ | ||
428 | * 3 |RX<1>| LT <5:4> | RY <5:1> | | ||
429 | * -----+-----+-----------+-----------------------------+ | ||
430 | * 4 | LT <3:1> | RT <5:1> | | ||
431 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
432 | * 5 | BDR | BDD | BLT | B- | BH | B+ | BRT | 1 | | ||
433 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
434 | * 6 | BZL | BB | BY | BA | BX | BZR | BDL | BDU | | ||
435 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
436 | * All buttons are 0 if pressed | ||
437 | * RX and RY are right analog stick | ||
438 | * LX and LY are left analog stick | ||
439 | * LT is left trigger, RT is right trigger | ||
440 | * BLT is 0 if left trigger is fully pressed | ||
441 | * BRT is 0 if right trigger is fully pressed | ||
442 | * BDR, BDD, BDL, BDU form the D-Pad with right, down, left, up buttons | ||
443 | * BZL is left Z button and BZR is right Z button | ||
444 | * B-, BH, B+ are +, HOME and - buttons | ||
445 | * BB, BY, BA, BX are A, B, X, Y buttons | ||
446 | * LSB of RX, RY, LT, and RT are not transmitted and always 0. | ||
447 | * | ||
448 | * With motionp enabled it changes slightly to this: | ||
449 | * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | | ||
450 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
451 | * 1 | RX <4:3> | LX <5:1> | BDU | | ||
452 | * 2 | RX <2:1> | LY <5:1> | BDL | | ||
453 | * -----+-----+-----+-----+-----------------------+-----+ | ||
454 | * 3 |RX<0>| LT <4:3> | RY <4:0> | | ||
455 | * -----+-----+-----------+-----------------------------+ | ||
456 | * 4 | LT <2:0> | RT <4:0> | | ||
457 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
458 | * 5 | BDR | BDD | BLT | B- | BH | B+ | BRT | EXT | | ||
459 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
460 | * 6 | BZL | BB | BY | BA | BX | BZR | 0 | 0 | | ||
461 | * -----+-----+-----+-----+-----+-----+-----+-----+-----+ | ||
462 | * Only the LSBs of LX and LY are lost. BDU and BDL are moved, the rest | ||
463 | * is the same as before. | ||
464 | */ | ||
465 | |||
466 | if (ext->motionp) { | ||
467 | lx = payload[0] & 0x3e; | ||
468 | ly = payload[0] & 0x3e; | ||
469 | } else { | ||
470 | lx = payload[0] & 0x3f; | ||
471 | ly = payload[0] & 0x3f; | ||
472 | } | ||
473 | |||
474 | rx = (payload[0] >> 3) & 0x14; | ||
475 | rx |= (payload[1] >> 5) & 0x06; | ||
476 | rx |= (payload[2] >> 7) & 0x01; | ||
477 | ry = payload[2] & 0x1f; | ||
478 | |||
479 | rt = payload[3] & 0x1f; | ||
480 | lt = (payload[2] >> 2) & 0x18; | ||
481 | lt |= (payload[3] >> 5) & 0x07; | ||
482 | |||
483 | rx <<= 1; | ||
484 | ry <<= 1; | ||
485 | rt <<= 1; | ||
486 | lt <<= 1; | ||
487 | |||
488 | input_report_abs(ext->input, ABS_HAT1X, lx - 0x20); | ||
489 | input_report_abs(ext->input, ABS_HAT1Y, ly - 0x20); | ||
490 | input_report_abs(ext->input, ABS_HAT2X, rx - 0x20); | ||
491 | input_report_abs(ext->input, ABS_HAT2Y, ry - 0x20); | ||
492 | input_report_abs(ext->input, ABS_HAT3X, rt - 0x20); | ||
493 | input_report_abs(ext->input, ABS_HAT3Y, lt - 0x20); | ||
494 | |||
495 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_RIGHT], | ||
496 | !!(payload[4] & 0x80)); | ||
497 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_DOWN], | ||
498 | !!(payload[4] & 0x40)); | ||
499 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LT], | ||
500 | !!(payload[4] & 0x20)); | ||
501 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_MINUS], | ||
502 | !!(payload[4] & 0x10)); | ||
503 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_HOME], | ||
504 | !!(payload[4] & 0x08)); | ||
505 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_PLUS], | ||
506 | !!(payload[4] & 0x04)); | ||
507 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_RT], | ||
508 | !!(payload[4] & 0x02)); | ||
509 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_ZL], | ||
510 | !!(payload[5] & 0x80)); | ||
511 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_B], | ||
512 | !!(payload[5] & 0x40)); | ||
513 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_Y], | ||
514 | !!(payload[5] & 0x20)); | ||
515 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_A], | ||
516 | !!(payload[5] & 0x10)); | ||
517 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_X], | ||
518 | !!(payload[5] & 0x08)); | ||
519 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_ZR], | ||
520 | !!(payload[5] & 0x04)); | ||
521 | |||
522 | if (ext->motionp) { | ||
523 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_UP], | ||
524 | !!(payload[0] & 0x01)); | ||
525 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LEFT], | ||
526 | !!(payload[1] & 0x01)); | ||
527 | } else { | ||
528 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_UP], | ||
529 | !!(payload[5] & 0x01)); | ||
530 | input_report_key(ext->input, wiiext_keymap[WIIEXT_KEY_LEFT], | ||
531 | !!(payload[5] & 0x02)); | ||
532 | } | ||
533 | |||
534 | input_sync(ext->input); | ||
535 | } | ||
536 | |||
537 | static void handler_balance_board(struct wiimote_ext *ext, const __u8 *payload) | ||
538 | { | ||
539 | __s32 val[4], tmp; | ||
540 | unsigned int i; | ||
541 | |||
542 | /* Byte | 8 7 6 5 4 3 2 1 | | ||
543 | * -----+--------------------------+ | ||
544 | * 1 | Top Right <15:8> | | ||
545 | * 2 | Top Right <7:0> | | ||
546 | * -----+--------------------------+ | ||
547 | * 3 | Bottom Right <15:8> | | ||
548 | * 4 | Bottom Right <7:0> | | ||
549 | * -----+--------------------------+ | ||
550 | * 5 | Top Left <15:8> | | ||
551 | * 6 | Top Left <7:0> | | ||
552 | * -----+--------------------------+ | ||
553 | * 7 | Bottom Left <15:8> | | ||
554 | * 8 | Bottom Left <7:0> | | ||
555 | * -----+--------------------------+ | ||
556 | * | ||
557 | * These values represent the weight-measurements of the Wii-balance | ||
558 | * board with 16bit precision. | ||
559 | * | ||
560 | * The balance-board is never reported interleaved with motionp. | ||
561 | */ | ||
562 | |||
563 | val[0] = payload[0]; | ||
564 | val[0] <<= 8; | ||
565 | val[0] |= payload[1]; | ||
566 | |||
567 | val[1] = payload[2]; | ||
568 | val[1] <<= 8; | ||
569 | val[1] |= payload[3]; | ||
570 | |||
571 | val[2] = payload[4]; | ||
572 | val[2] <<= 8; | ||
573 | val[2] |= payload[5]; | ||
574 | |||
575 | val[3] = payload[6]; | ||
576 | val[3] <<= 8; | ||
577 | val[3] |= payload[7]; | ||
578 | |||
579 | /* apply calibration data */ | ||
580 | for (i = 0; i < 4; i++) { | ||
581 | if (val[i] < ext->calib[i][1]) { | ||
582 | tmp = val[i] - ext->calib[i][0]; | ||
583 | tmp *= 1700; | ||
584 | tmp /= ext->calib[i][1] - ext->calib[i][0]; | ||
585 | } else { | ||
586 | tmp = val[i] - ext->calib[i][1]; | ||
587 | tmp *= 1700; | ||
588 | tmp /= ext->calib[i][2] - ext->calib[i][1]; | ||
589 | tmp += 1700; | ||
590 | } | ||
591 | val[i] = tmp; | ||
592 | } | ||
593 | |||
594 | input_report_abs(ext->input, ABS_HAT0X, val[0]); | ||
595 | input_report_abs(ext->input, ABS_HAT0Y, val[1]); | ||
596 | input_report_abs(ext->input, ABS_HAT1X, val[2]); | ||
597 | input_report_abs(ext->input, ABS_HAT1Y, val[3]); | ||
598 | |||
599 | input_sync(ext->input); | ||
600 | } | ||
601 | |||
602 | /* call this with state.lock spinlock held */ | ||
603 | void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload) | ||
604 | { | ||
605 | struct wiimote_ext *ext = wdata->ext; | ||
606 | |||
607 | if (!ext) | ||
608 | return; | ||
609 | |||
610 | if (ext->motionp && (payload[5] & 0x02)) { | ||
611 | handler_motionp(ext, payload); | ||
612 | } else if (ext->ext_type == WIIEXT_NUNCHUCK) { | ||
613 | handler_nunchuck(ext, payload); | ||
614 | } else if (ext->ext_type == WIIEXT_CLASSIC) { | ||
615 | handler_classic(ext, payload); | ||
616 | } else if (ext->ext_type == WIIEXT_BALANCE_BOARD) { | ||
617 | handler_balance_board(ext, payload); | ||
618 | } | ||
619 | } | ||
620 | |||
621 | static ssize_t wiiext_show(struct device *dev, struct device_attribute *attr, | ||
622 | char *buf) | ||
623 | { | ||
624 | struct wiimote_data *wdata = dev_to_wii(dev); | ||
625 | __u8 type = WIIEXT_NONE; | ||
626 | bool motionp = false; | ||
627 | unsigned long flags; | ||
628 | |||
629 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
630 | if (wdata->ext) { | ||
631 | motionp = wdata->ext->motionp; | ||
632 | type = wdata->ext->ext_type; | ||
633 | } | ||
634 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
635 | |||
636 | if (type == WIIEXT_NUNCHUCK) { | ||
637 | if (motionp) | ||
638 | return sprintf(buf, "motionp+nunchuck\n"); | ||
639 | else | ||
640 | return sprintf(buf, "nunchuck\n"); | ||
641 | } else if (type == WIIEXT_CLASSIC) { | ||
642 | if (motionp) | ||
643 | return sprintf(buf, "motionp+classic\n"); | ||
644 | else | ||
645 | return sprintf(buf, "classic\n"); | ||
646 | } else if (type == WIIEXT_BALANCE_BOARD) { | ||
647 | if (motionp) | ||
648 | return sprintf(buf, "motionp+balanceboard\n"); | ||
649 | else | ||
650 | return sprintf(buf, "balanceboard\n"); | ||
651 | } else { | ||
652 | if (motionp) | ||
653 | return sprintf(buf, "motionp\n"); | ||
654 | else | ||
655 | return sprintf(buf, "none\n"); | ||
656 | } | ||
657 | } | ||
658 | |||
659 | static DEVICE_ATTR(extension, S_IRUGO, wiiext_show, NULL); | ||
660 | |||
661 | static int wiiext_input_open(struct input_dev *dev) | ||
662 | { | ||
663 | struct wiimote_ext *ext = input_get_drvdata(dev); | ||
664 | |||
665 | atomic_inc(&ext->opened); | ||
666 | wiiext_schedule(ext); | ||
667 | |||
668 | return 0; | ||
669 | } | ||
670 | |||
671 | static void wiiext_input_close(struct input_dev *dev) | ||
672 | { | ||
673 | struct wiimote_ext *ext = input_get_drvdata(dev); | ||
674 | |||
675 | atomic_dec(&ext->opened); | ||
676 | wiiext_schedule(ext); | ||
677 | } | ||
678 | |||
679 | static int wiiext_mp_open(struct input_dev *dev) | ||
680 | { | ||
681 | struct wiimote_ext *ext = input_get_drvdata(dev); | ||
682 | |||
683 | atomic_inc(&ext->mp_opened); | ||
684 | wiiext_schedule(ext); | ||
685 | |||
686 | return 0; | ||
687 | } | ||
688 | |||
689 | static void wiiext_mp_close(struct input_dev *dev) | ||
690 | { | ||
691 | struct wiimote_ext *ext = input_get_drvdata(dev); | ||
692 | |||
693 | atomic_dec(&ext->mp_opened); | ||
694 | wiiext_schedule(ext); | ||
695 | } | ||
696 | |||
697 | /* Initializes the extension driver of a wiimote */ | ||
698 | int wiiext_init(struct wiimote_data *wdata) | ||
699 | { | ||
700 | struct wiimote_ext *ext; | ||
701 | unsigned long flags; | ||
702 | int ret, i; | ||
703 | |||
704 | ext = kzalloc(sizeof(*ext), GFP_KERNEL); | ||
705 | if (!ext) | ||
706 | return -ENOMEM; | ||
707 | |||
708 | ext->wdata = wdata; | ||
709 | INIT_WORK(&ext->worker, wiiext_worker); | ||
710 | |||
711 | ext->input = input_allocate_device(); | ||
712 | if (!ext->input) { | ||
713 | ret = -ENOMEM; | ||
714 | goto err_input; | ||
715 | } | ||
716 | |||
717 | input_set_drvdata(ext->input, ext); | ||
718 | ext->input->open = wiiext_input_open; | ||
719 | ext->input->close = wiiext_input_close; | ||
720 | ext->input->dev.parent = &wdata->hdev->dev; | ||
721 | ext->input->id.bustype = wdata->hdev->bus; | ||
722 | ext->input->id.vendor = wdata->hdev->vendor; | ||
723 | ext->input->id.product = wdata->hdev->product; | ||
724 | ext->input->id.version = wdata->hdev->version; | ||
725 | ext->input->name = WIIMOTE_NAME " Extension"; | ||
726 | |||
727 | set_bit(EV_KEY, ext->input->evbit); | ||
728 | for (i = 0; i < WIIEXT_KEY_COUNT; ++i) | ||
729 | set_bit(wiiext_keymap[i], ext->input->keybit); | ||
730 | |||
731 | set_bit(EV_ABS, ext->input->evbit); | ||
732 | set_bit(ABS_HAT0X, ext->input->absbit); | ||
733 | set_bit(ABS_HAT0Y, ext->input->absbit); | ||
734 | set_bit(ABS_HAT1X, ext->input->absbit); | ||
735 | set_bit(ABS_HAT1Y, ext->input->absbit); | ||
736 | set_bit(ABS_HAT2X, ext->input->absbit); | ||
737 | set_bit(ABS_HAT2Y, ext->input->absbit); | ||
738 | set_bit(ABS_HAT3X, ext->input->absbit); | ||
739 | set_bit(ABS_HAT3Y, ext->input->absbit); | ||
740 | input_set_abs_params(ext->input, ABS_HAT0X, -120, 120, 2, 4); | ||
741 | input_set_abs_params(ext->input, ABS_HAT0Y, -120, 120, 2, 4); | ||
742 | input_set_abs_params(ext->input, ABS_HAT1X, -30, 30, 1, 1); | ||
743 | input_set_abs_params(ext->input, ABS_HAT1Y, -30, 30, 1, 1); | ||
744 | input_set_abs_params(ext->input, ABS_HAT2X, -30, 30, 1, 1); | ||
745 | input_set_abs_params(ext->input, ABS_HAT2Y, -30, 30, 1, 1); | ||
746 | input_set_abs_params(ext->input, ABS_HAT3X, -30, 30, 1, 1); | ||
747 | input_set_abs_params(ext->input, ABS_HAT3Y, -30, 30, 1, 1); | ||
748 | set_bit(ABS_RX, ext->input->absbit); | ||
749 | set_bit(ABS_RY, ext->input->absbit); | ||
750 | set_bit(ABS_RZ, ext->input->absbit); | ||
751 | input_set_abs_params(ext->input, ABS_RX, -500, 500, 2, 4); | ||
752 | input_set_abs_params(ext->input, ABS_RY, -500, 500, 2, 4); | ||
753 | input_set_abs_params(ext->input, ABS_RZ, -500, 500, 2, 4); | ||
754 | |||
755 | ret = input_register_device(ext->input); | ||
756 | if (ret) { | ||
757 | input_free_device(ext->input); | ||
758 | goto err_input; | ||
759 | } | ||
760 | |||
761 | ext->mp_input = input_allocate_device(); | ||
762 | if (!ext->mp_input) { | ||
763 | ret = -ENOMEM; | ||
764 | goto err_mp; | ||
765 | } | ||
766 | |||
767 | input_set_drvdata(ext->mp_input, ext); | ||
768 | ext->mp_input->open = wiiext_mp_open; | ||
769 | ext->mp_input->close = wiiext_mp_close; | ||
770 | ext->mp_input->dev.parent = &wdata->hdev->dev; | ||
771 | ext->mp_input->id.bustype = wdata->hdev->bus; | ||
772 | ext->mp_input->id.vendor = wdata->hdev->vendor; | ||
773 | ext->mp_input->id.product = wdata->hdev->product; | ||
774 | ext->mp_input->id.version = wdata->hdev->version; | ||
775 | ext->mp_input->name = WIIMOTE_NAME " Motion+"; | ||
776 | |||
777 | set_bit(EV_ABS, ext->mp_input->evbit); | ||
778 | set_bit(ABS_RX, ext->mp_input->absbit); | ||
779 | set_bit(ABS_RY, ext->mp_input->absbit); | ||
780 | set_bit(ABS_RZ, ext->mp_input->absbit); | ||
781 | input_set_abs_params(ext->mp_input, ABS_RX, -160000, 160000, 4, 8); | ||
782 | input_set_abs_params(ext->mp_input, ABS_RY, -160000, 160000, 4, 8); | ||
783 | input_set_abs_params(ext->mp_input, ABS_RZ, -160000, 160000, 4, 8); | ||
784 | |||
785 | ret = input_register_device(ext->mp_input); | ||
786 | if (ret) { | ||
787 | input_free_device(ext->mp_input); | ||
788 | goto err_mp; | ||
789 | } | ||
790 | |||
791 | ret = device_create_file(&wdata->hdev->dev, &dev_attr_extension); | ||
792 | if (ret) | ||
793 | goto err_dev; | ||
794 | |||
795 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
796 | wdata->ext = ext; | ||
797 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
798 | |||
799 | return 0; | ||
800 | |||
801 | err_dev: | ||
802 | input_unregister_device(ext->mp_input); | ||
803 | err_mp: | ||
804 | input_unregister_device(ext->input); | ||
805 | err_input: | ||
806 | kfree(ext); | ||
807 | return ret; | ||
808 | } | ||
809 | |||
810 | /* Deinitializes the extension driver of a wiimote */ | ||
811 | void wiiext_deinit(struct wiimote_data *wdata) | ||
812 | { | ||
813 | struct wiimote_ext *ext = wdata->ext; | ||
814 | unsigned long flags; | ||
815 | |||
816 | if (!ext) | ||
817 | return; | ||
818 | |||
819 | /* | ||
820 | * We first unset wdata->ext to avoid further input from the wiimote | ||
821 | * core. The worker thread does not access this pointer so it is not | ||
822 | * affected by this. | ||
823 | * We kill the worker after this so it does not get respawned during | ||
824 | * deinitialization. | ||
825 | */ | ||
826 | |||
827 | spin_lock_irqsave(&wdata->state.lock, flags); | ||
828 | wdata->ext = NULL; | ||
829 | spin_unlock_irqrestore(&wdata->state.lock, flags); | ||
830 | |||
831 | device_remove_file(&wdata->hdev->dev, &dev_attr_extension); | ||
832 | input_unregister_device(ext->mp_input); | ||
833 | input_unregister_device(ext->input); | ||
834 | |||
835 | cancel_work_sync(&ext->worker); | ||
836 | kfree(ext); | ||
837 | } | ||
diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h index 9f857c1cd84a..d406a398e54c 100644 --- a/drivers/hid/hid-wiimote.h +++ b/drivers/hid/hid-wiimote.h | |||
@@ -142,7 +142,6 @@ struct wiimote_data { | |||
142 | struct power_supply battery; | 142 | struct power_supply battery; |
143 | struct input_dev *mp; | 143 | struct input_dev *mp; |
144 | struct timer_list timer; | 144 | struct timer_list timer; |
145 | struct wiimote_ext *ext; | ||
146 | struct wiimote_debug *debug; | 145 | struct wiimote_debug *debug; |
147 | 146 | ||
148 | union { | 147 | union { |
@@ -270,24 +269,6 @@ extern ssize_t wiimote_cmd_read(struct wiimote_data *wdata, __u32 offset, | |||
270 | extern void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom, | 269 | extern void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom, |
271 | __u32 offset, __u16 size); | 270 | __u32 offset, __u16 size); |
272 | 271 | ||
273 | #ifdef CONFIG_HID_WIIMOTE_EXT | ||
274 | |||
275 | extern int wiiext_init(struct wiimote_data *wdata); | ||
276 | extern void wiiext_deinit(struct wiimote_data *wdata); | ||
277 | extern void wiiext_event(struct wiimote_data *wdata, bool plugged); | ||
278 | extern bool wiiext_active(struct wiimote_data *wdata); | ||
279 | extern void wiiext_handle(struct wiimote_data *wdata, const __u8 *payload); | ||
280 | |||
281 | #else | ||
282 | |||
283 | static inline int wiiext_init(void *u) { return 0; } | ||
284 | static inline void wiiext_deinit(void *u) { } | ||
285 | static inline void wiiext_event(void *u, bool p) { } | ||
286 | static inline bool wiiext_active(void *u) { return false; } | ||
287 | static inline void wiiext_handle(void *u, const __u8 *p) { } | ||
288 | |||
289 | #endif | ||
290 | |||
291 | #ifdef CONFIG_DEBUG_FS | 272 | #ifdef CONFIG_DEBUG_FS |
292 | 273 | ||
293 | extern int wiidebug_init(struct wiimote_data *wdata); | 274 | extern int wiidebug_init(struct wiimote_data *wdata); |