1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <linux/device.h>
37#include <linux/hid.h>
38#include <linux/input.h>
39#include <linux/spinlock.h>
40#include "hid-wiimote.h"
41
42
43
44
45
46
47
48
49
50
51static const __u16 wiimod_keys_map[] = {
52 KEY_LEFT,
53 KEY_RIGHT,
54 KEY_UP,
55 KEY_DOWN,
56 KEY_NEXT,
57 KEY_PREVIOUS,
58 BTN_1,
59 BTN_2,
60 BTN_A,
61 BTN_B,
62 BTN_MODE,
63};
64
65static void wiimod_keys_in_keys(struct wiimote_data *wdata, const __u8 *keys)
66{
67 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_LEFT],
68 !!(keys[0] & 0x01));
69 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_RIGHT],
70 !!(keys[0] & 0x02));
71 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_DOWN],
72 !!(keys[0] & 0x04));
73 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_UP],
74 !!(keys[0] & 0x08));
75 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_PLUS],
76 !!(keys[0] & 0x10));
77 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_TWO],
78 !!(keys[1] & 0x01));
79 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_ONE],
80 !!(keys[1] & 0x02));
81 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_B],
82 !!(keys[1] & 0x04));
83 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_A],
84 !!(keys[1] & 0x08));
85 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_MINUS],
86 !!(keys[1] & 0x10));
87 input_report_key(wdata->input, wiimod_keys_map[WIIPROTO_KEY_HOME],
88 !!(keys[1] & 0x80));
89 input_sync(wdata->input);
90}
91
92static int wiimod_keys_probe(const struct wiimod_ops *ops,
93 struct wiimote_data *wdata)
94{
95 unsigned int i;
96
97 set_bit(EV_KEY, wdata->input->evbit);
98 for (i = 0; i < WIIPROTO_KEY_COUNT; ++i)
99 set_bit(wiimod_keys_map[i], wdata->input->keybit);
100
101 return 0;
102}
103
104static const struct wiimod_ops wiimod_keys = {
105 .flags = WIIMOD_FLAG_INPUT,
106 .arg = 0,
107 .probe = wiimod_keys_probe,
108 .remove = NULL,
109 .in_keys = wiimod_keys_in_keys,
110};
111
112
113
114
115
116
117
118
119
120
121
122
123static void wiimod_rumble_worker(struct work_struct *work)
124{
125 struct wiimote_data *wdata = container_of(work, struct wiimote_data,
126 rumble_worker);
127
128 spin_lock_irq(&wdata->state.lock);
129 wiiproto_req_rumble(wdata, wdata->state.cache_rumble);
130 spin_unlock_irq(&wdata->state.lock);
131}
132
133static int wiimod_rumble_play(struct input_dev *dev, void *data,
134 struct ff_effect *eff)
135{
136 struct wiimote_data *wdata = input_get_drvdata(dev);
137 __u8 value;
138
139
140
141
142
143
144
145 if (eff->u.rumble.strong_magnitude || eff->u.rumble.weak_magnitude)
146 value = 1;
147 else
148 value = 0;
149
150
151
152 wdata->state.cache_rumble = value;
153 schedule_work(&wdata->rumble_worker);
154
155 return 0;
156}
157
158static int wiimod_rumble_probe(const struct wiimod_ops *ops,
159 struct wiimote_data *wdata)
160{
161 INIT_WORK(&wdata->rumble_worker, wiimod_rumble_worker);
162
163 set_bit(FF_RUMBLE, wdata->input->ffbit);
164 if (input_ff_create_memless(wdata->input, NULL, wiimod_rumble_play))
165 return -ENOMEM;
166
167 return 0;
168}
169
170static void wiimod_rumble_remove(const struct wiimod_ops *ops,
171 struct wiimote_data *wdata)
172{
173 unsigned long flags;
174
175 cancel_work_sync(&wdata->rumble_worker);
176
177 spin_lock_irqsave(&wdata->state.lock, flags);
178 wiiproto_req_rumble(wdata, 0);
179 spin_unlock_irqrestore(&wdata->state.lock, flags);
180}
181
182static const struct wiimod_ops wiimod_rumble = {
183 .flags = WIIMOD_FLAG_INPUT,
184 .arg = 0,
185 .probe = wiimod_rumble_probe,
186 .remove = wiimod_rumble_remove,
187};
188
189
190
191
192
193
194
195
196
197static enum power_supply_property wiimod_battery_props[] = {
198 POWER_SUPPLY_PROP_CAPACITY,
199 POWER_SUPPLY_PROP_SCOPE,
200};
201
202static int wiimod_battery_get_property(struct power_supply *psy,
203 enum power_supply_property psp,
204 union power_supply_propval *val)
205{
206 struct wiimote_data *wdata = container_of(psy, struct wiimote_data,
207 battery);
208 int ret = 0, state;
209 unsigned long flags;
210
211 if (psp == POWER_SUPPLY_PROP_SCOPE) {
212 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
213 return 0;
214 } else if (psp != POWER_SUPPLY_PROP_CAPACITY) {
215 return -EINVAL;
216 }
217
218 ret = wiimote_cmd_acquire(wdata);
219 if (ret)
220 return ret;
221
222 spin_lock_irqsave(&wdata->state.lock, flags);
223 wiimote_cmd_set(wdata, WIIPROTO_REQ_SREQ, 0);
224 wiiproto_req_status(wdata);
225 spin_unlock_irqrestore(&wdata->state.lock, flags);
226
227 wiimote_cmd_wait(wdata);
228 wiimote_cmd_release(wdata);
229
230 spin_lock_irqsave(&wdata->state.lock, flags);
231 state = wdata->state.cmd_battery;
232 spin_unlock_irqrestore(&wdata->state.lock, flags);
233
234 val->intval = state * 100 / 255;
235 return ret;
236}
237
238static int wiimod_battery_probe(const struct wiimod_ops *ops,
239 struct wiimote_data *wdata)
240{
241 int ret;
242
243 wdata->battery.properties = wiimod_battery_props;
244 wdata->battery.num_properties = ARRAY_SIZE(wiimod_battery_props);
245 wdata->battery.get_property = wiimod_battery_get_property;
246 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
247 wdata->battery.use_for_apm = 0;
248 wdata->battery.name = kasprintf(GFP_KERNEL, "wiimote_battery_%s",
249 wdata->hdev->uniq);
250 if (!wdata->battery.name)
251 return -ENOMEM;
252
253 ret = power_supply_register(&wdata->hdev->dev, &wdata->battery);
254 if (ret) {
255 hid_err(wdata->hdev, "cannot register battery device\n");
256 goto err_free;
257 }
258
259 power_supply_powers(&wdata->battery, &wdata->hdev->dev);
260 return 0;
261
262err_free:
263 kfree(wdata->battery.name);
264 wdata->battery.name = NULL;
265 return ret;
266}
267
268static void wiimod_battery_remove(const struct wiimod_ops *ops,
269 struct wiimote_data *wdata)
270{
271 if (!wdata->battery.name)
272 return;
273
274 power_supply_unregister(&wdata->battery);
275 kfree(wdata->battery.name);
276 wdata->battery.name = NULL;
277}
278
279static const struct wiimod_ops wiimod_battery = {
280 .flags = 0,
281 .arg = 0,
282 .probe = wiimod_battery_probe,
283 .remove = wiimod_battery_remove,
284};
285
286
287
288
289
290
291
292
293
294static enum led_brightness wiimod_led_get(struct led_classdev *led_dev)
295{
296 struct wiimote_data *wdata;
297 struct device *dev = led_dev->dev->parent;
298 int i;
299 unsigned long flags;
300 bool value = false;
301
302 wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev));
303
304 for (i = 0; i < 4; ++i) {
305 if (wdata->leds[i] == led_dev) {
306 spin_lock_irqsave(&wdata->state.lock, flags);
307 value = wdata->state.flags & WIIPROTO_FLAG_LED(i + 1);
308 spin_unlock_irqrestore(&wdata->state.lock, flags);
309 break;
310 }
311 }
312
313 return value ? LED_FULL : LED_OFF;
314}
315
316static void wiimod_led_set(struct led_classdev *led_dev,
317 enum led_brightness value)
318{
319 struct wiimote_data *wdata;
320 struct device *dev = led_dev->dev->parent;
321 int i;
322 unsigned long flags;
323 __u8 state, flag;
324
325 wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev));
326
327 for (i = 0; i < 4; ++i) {
328 if (wdata->leds[i] == led_dev) {
329 flag = WIIPROTO_FLAG_LED(i + 1);
330 spin_lock_irqsave(&wdata->state.lock, flags);
331 state = wdata->state.flags;
332 if (value == LED_OFF)
333 wiiproto_req_leds(wdata, state & ~flag);
334 else
335 wiiproto_req_leds(wdata, state | flag);
336 spin_unlock_irqrestore(&wdata->state.lock, flags);
337 break;
338 }
339 }
340}
341
342static int wiimod_led_probe(const struct wiimod_ops *ops,
343 struct wiimote_data *wdata)
344{
345 struct device *dev = &wdata->hdev->dev;
346 size_t namesz = strlen(dev_name(dev)) + 9;
347 struct led_classdev *led;
348 unsigned long flags;
349 char *name;
350 int ret;
351
352 led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
353 if (!led)
354 return -ENOMEM;
355
356 name = (void*)&led[1];
357 snprintf(name, namesz, "%s:blue:p%lu", dev_name(dev), ops->arg);
358 led->name = name;
359 led->brightness = 0;
360 led->max_brightness = 1;
361 led->brightness_get = wiimod_led_get;
362 led->brightness_set = wiimod_led_set;
363
364 wdata->leds[ops->arg] = led;
365 ret = led_classdev_register(dev, led);
366 if (ret)
367 goto err_free;
368
369
370 if (ops->arg == 0) {
371 spin_lock_irqsave(&wdata->state.lock, flags);
372 wiiproto_req_leds(wdata, WIIPROTO_FLAG_LED1);
373 spin_unlock_irqrestore(&wdata->state.lock, flags);
374 }
375
376 return 0;
377
378err_free:
379 wdata->leds[ops->arg] = NULL;
380 kfree(led);
381 return ret;
382}
383
384static void wiimod_led_remove(const struct wiimod_ops *ops,
385 struct wiimote_data *wdata)
386{
387 if (!wdata->leds[ops->arg])
388 return;
389
390 led_classdev_unregister(wdata->leds[ops->arg]);
391 kfree(wdata->leds[ops->arg]);
392 wdata->leds[ops->arg] = NULL;
393}
394
395static const struct wiimod_ops wiimod_leds[4] = {
396 {
397 .flags = 0,
398 .arg = 0,
399 .probe = wiimod_led_probe,
400 .remove = wiimod_led_remove,
401 },
402 {
403 .flags = 0,
404 .arg = 1,
405 .probe = wiimod_led_probe,
406 .remove = wiimod_led_remove,
407 },
408 {
409 .flags = 0,
410 .arg = 2,
411 .probe = wiimod_led_probe,
412 .remove = wiimod_led_remove,
413 },
414 {
415 .flags = 0,
416 .arg = 3,
417 .probe = wiimod_led_probe,
418 .remove = wiimod_led_remove,
419 },
420};
421
422
423
424
425
426
427
428
429static void wiimod_accel_in_accel(struct wiimote_data *wdata,
430 const __u8 *accel)
431{
432 __u16 x, y, z;
433
434 if (!(wdata->state.flags & WIIPROTO_FLAG_ACCEL))
435 return;
436
437
438
439
440
441
442
443
444
445
446
447
448
449 x = accel[2] << 2;
450 y = accel[3] << 2;
451 z = accel[4] << 2;
452
453 x |= (accel[0] >> 5) & 0x3;
454 y |= (accel[1] >> 4) & 0x2;
455 z |= (accel[1] >> 5) & 0x2;
456
457 input_report_abs(wdata->accel, ABS_RX, x - 0x200);
458 input_report_abs(wdata->accel, ABS_RY, y - 0x200);
459 input_report_abs(wdata->accel, ABS_RZ, z - 0x200);
460 input_sync(wdata->accel);
461}
462
463static int wiimod_accel_open(struct input_dev *dev)
464{
465 struct wiimote_data *wdata = input_get_drvdata(dev);
466 unsigned long flags;
467
468 spin_lock_irqsave(&wdata->state.lock, flags);
469 wiiproto_req_accel(wdata, true);
470 spin_unlock_irqrestore(&wdata->state.lock, flags);
471
472 return 0;
473}
474
475static void wiimod_accel_close(struct input_dev *dev)
476{
477 struct wiimote_data *wdata = input_get_drvdata(dev);
478 unsigned long flags;
479
480 spin_lock_irqsave(&wdata->state.lock, flags);
481 wiiproto_req_accel(wdata, false);
482 spin_unlock_irqrestore(&wdata->state.lock, flags);
483}
484
485static int wiimod_accel_probe(const struct wiimod_ops *ops,
486 struct wiimote_data *wdata)
487{
488 int ret;
489
490 wdata->accel = input_allocate_device();
491 if (!wdata->accel)
492 return -ENOMEM;
493
494 input_set_drvdata(wdata->accel, wdata);
495 wdata->accel->open = wiimod_accel_open;
496 wdata->accel->close = wiimod_accel_close;
497 wdata->accel->dev.parent = &wdata->hdev->dev;
498 wdata->accel->id.bustype = wdata->hdev->bus;
499 wdata->accel->id.vendor = wdata->hdev->vendor;
500 wdata->accel->id.product = wdata->hdev->product;
501 wdata->accel->id.version = wdata->hdev->version;
502 wdata->accel->name = WIIMOTE_NAME " Accelerometer";
503
504 set_bit(EV_ABS, wdata->accel->evbit);
505 set_bit(ABS_RX, wdata->accel->absbit);
506 set_bit(ABS_RY, wdata->accel->absbit);
507 set_bit(ABS_RZ, wdata->accel->absbit);
508 input_set_abs_params(wdata->accel, ABS_RX, -500, 500, 2, 4);
509 input_set_abs_params(wdata->accel, ABS_RY, -500, 500, 2, 4);
510 input_set_abs_params(wdata->accel, ABS_RZ, -500, 500, 2, 4);
511
512 ret = input_register_device(wdata->accel);
513 if (ret) {
514 hid_err(wdata->hdev, "cannot register input device\n");
515 goto err_free;
516 }
517
518 return 0;
519
520err_free:
521 input_free_device(wdata->accel);
522 wdata->accel = NULL;
523 return ret;
524}
525
526static void wiimod_accel_remove(const struct wiimod_ops *ops,
527 struct wiimote_data *wdata)
528{
529 if (!wdata->accel)
530 return;
531
532 input_unregister_device(wdata->accel);
533 wdata->accel = NULL;
534}
535
536static const struct wiimod_ops wiimod_accel = {
537 .flags = 0,
538 .arg = 0,
539 .probe = wiimod_accel_probe,
540 .remove = wiimod_accel_remove,
541 .in_accel = wiimod_accel_in_accel,
542};
543
544
545
546
547
548
549
550
551
552
553
554static void wiimod_ir_in_ir(struct wiimote_data *wdata, const __u8 *ir,
555 bool packed, unsigned int id)
556{
557 __u16 x, y;
558 __u8 xid, yid;
559 bool sync = false;
560
561 if (!(wdata->state.flags & WIIPROTO_FLAGS_IR))
562 return;
563
564 switch (id) {
565 case 0:
566 xid = ABS_HAT0X;
567 yid = ABS_HAT0Y;
568 break;
569 case 1:
570 xid = ABS_HAT1X;
571 yid = ABS_HAT1Y;
572 break;
573 case 2:
574 xid = ABS_HAT2X;
575 yid = ABS_HAT2Y;
576 break;
577 case 3:
578 xid = ABS_HAT3X;
579 yid = ABS_HAT3Y;
580 sync = true;
581 break;
582 default:
583 return;
584 }
585
586
587
588
589
590
591
592
593
594
595
596 if (packed) {
597 x = ir[1] | ((ir[0] & 0x03) << 8);
598 y = ir[2] | ((ir[0] & 0x0c) << 6);
599 } else {
600 x = ir[0] | ((ir[2] & 0x30) << 4);
601 y = ir[1] | ((ir[2] & 0xc0) << 2);
602 }
603
604 input_report_abs(wdata->ir, xid, x);
605 input_report_abs(wdata->ir, yid, y);
606
607 if (sync)
608 input_sync(wdata->ir);
609}
610
611static int wiimod_ir_change(struct wiimote_data *wdata, __u16 mode)
612{
613 int ret;
614 unsigned long flags;
615 __u8 format = 0;
616 static const __u8 data_enable[] = { 0x01 };
617 static const __u8 data_sens1[] = { 0x02, 0x00, 0x00, 0x71, 0x01,
618 0x00, 0xaa, 0x00, 0x64 };
619 static const __u8 data_sens2[] = { 0x63, 0x03 };
620 static const __u8 data_fin[] = { 0x08 };
621
622 spin_lock_irqsave(&wdata->state.lock, flags);
623
624 if (mode == (wdata->state.flags & WIIPROTO_FLAGS_IR)) {
625 spin_unlock_irqrestore(&wdata->state.lock, flags);
626 return 0;
627 }
628
629 if (mode == 0) {
630 wdata->state.flags &= ~WIIPROTO_FLAGS_IR;
631 wiiproto_req_ir1(wdata, 0);
632 wiiproto_req_ir2(wdata, 0);
633 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
634 spin_unlock_irqrestore(&wdata->state.lock, flags);
635 return 0;
636 }
637
638 spin_unlock_irqrestore(&wdata->state.lock, flags);
639
640 ret = wiimote_cmd_acquire(wdata);
641 if (ret)
642 return ret;
643
644
645 spin_lock_irqsave(&wdata->state.lock, flags);
646 wiimote_cmd_set(wdata, WIIPROTO_REQ_IR1, 0);
647 wiiproto_req_ir1(wdata, 0x06);
648 spin_unlock_irqrestore(&wdata->state.lock, flags);
649
650 ret = wiimote_cmd_wait(wdata);
651 if (ret)
652 goto unlock;
653 if (wdata->state.cmd_err) {
654 ret = -EIO;
655 goto unlock;
656 }
657
658
659 spin_lock_irqsave(&wdata->state.lock, flags);
660 wiimote_cmd_set(wdata, WIIPROTO_REQ_IR2, 0);
661 wiiproto_req_ir2(wdata, 0x06);
662 spin_unlock_irqrestore(&wdata->state.lock, flags);
663
664 ret = wiimote_cmd_wait(wdata);
665 if (ret)
666 goto unlock;
667 if (wdata->state.cmd_err) {
668 ret = -EIO;
669 goto unlock;
670 }
671
672
673 ret = wiimote_cmd_write(wdata, 0xb00030, data_enable,
674 sizeof(data_enable));
675 if (ret)
676 goto unlock;
677
678
679 ret = wiimote_cmd_write(wdata, 0xb00000, data_sens1,
680 sizeof(data_sens1));
681 if (ret)
682 goto unlock;
683
684
685 ret = wiimote_cmd_write(wdata, 0xb0001a, data_sens2,
686 sizeof(data_sens2));
687 if (ret)
688 goto unlock;
689
690
691 switch (mode) {
692 case WIIPROTO_FLAG_IR_FULL:
693 format = 5;
694 break;
695 case WIIPROTO_FLAG_IR_EXT:
696 format = 3;
697 break;
698 case WIIPROTO_FLAG_IR_BASIC:
699 format = 1;
700 break;
701 }
702 ret = wiimote_cmd_write(wdata, 0xb00033, &format, sizeof(format));
703 if (ret)
704 goto unlock;
705
706
707 ret = wiimote_cmd_write(wdata, 0xb00030, data_fin, sizeof(data_fin));
708 if (ret)
709 goto unlock;
710
711
712 spin_lock_irqsave(&wdata->state.lock, flags);
713 wdata->state.flags &= ~WIIPROTO_FLAGS_IR;
714 wdata->state.flags |= mode & WIIPROTO_FLAGS_IR;
715 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
716 spin_unlock_irqrestore(&wdata->state.lock, flags);
717
718unlock:
719 wiimote_cmd_release(wdata);
720 return ret;
721}
722
723static int wiimod_ir_open(struct input_dev *dev)
724{
725 struct wiimote_data *wdata = input_get_drvdata(dev);
726
727 return wiimod_ir_change(wdata, WIIPROTO_FLAG_IR_BASIC);
728}
729
730static void wiimod_ir_close(struct input_dev *dev)
731{
732 struct wiimote_data *wdata = input_get_drvdata(dev);
733
734 wiimod_ir_change(wdata, 0);
735}
736
737static int wiimod_ir_probe(const struct wiimod_ops *ops,
738 struct wiimote_data *wdata)
739{
740 int ret;
741
742 wdata->ir = input_allocate_device();
743 if (!wdata->ir)
744 return -ENOMEM;
745
746 input_set_drvdata(wdata->ir, wdata);
747 wdata->ir->open = wiimod_ir_open;
748 wdata->ir->close = wiimod_ir_close;
749 wdata->ir->dev.parent = &wdata->hdev->dev;
750 wdata->ir->id.bustype = wdata->hdev->bus;
751 wdata->ir->id.vendor = wdata->hdev->vendor;
752 wdata->ir->id.product = wdata->hdev->product;
753 wdata->ir->id.version = wdata->hdev->version;
754 wdata->ir->name = WIIMOTE_NAME " IR";
755
756 set_bit(EV_ABS, wdata->ir->evbit);
757 set_bit(ABS_HAT0X, wdata->ir->absbit);
758 set_bit(ABS_HAT0Y, wdata->ir->absbit);
759 set_bit(ABS_HAT1X, wdata->ir->absbit);
760 set_bit(ABS_HAT1Y, wdata->ir->absbit);
761 set_bit(ABS_HAT2X, wdata->ir->absbit);
762 set_bit(ABS_HAT2Y, wdata->ir->absbit);
763 set_bit(ABS_HAT3X, wdata->ir->absbit);
764 set_bit(ABS_HAT3Y, wdata->ir->absbit);
765 input_set_abs_params(wdata->ir, ABS_HAT0X, 0, 1023, 2, 4);
766 input_set_abs_params(wdata->ir, ABS_HAT0Y, 0, 767, 2, 4);
767 input_set_abs_params(wdata->ir, ABS_HAT1X, 0, 1023, 2, 4);
768 input_set_abs_params(wdata->ir, ABS_HAT1Y, 0, 767, 2, 4);
769 input_set_abs_params(wdata->ir, ABS_HAT2X, 0, 1023, 2, 4);
770 input_set_abs_params(wdata->ir, ABS_HAT2Y, 0, 767, 2, 4);
771 input_set_abs_params(wdata->ir, ABS_HAT3X, 0, 1023, 2, 4);
772 input_set_abs_params(wdata->ir, ABS_HAT3Y, 0, 767, 2, 4);
773
774 ret = input_register_device(wdata->ir);
775 if (ret) {
776 hid_err(wdata->hdev, "cannot register input device\n");
777 goto err_free;
778 }
779
780 return 0;
781
782err_free:
783 input_free_device(wdata->ir);
784 wdata->ir = NULL;
785 return ret;
786}
787
788static void wiimod_ir_remove(const struct wiimod_ops *ops,
789 struct wiimote_data *wdata)
790{
791 if (!wdata->ir)
792 return;
793
794 input_unregister_device(wdata->ir);
795 wdata->ir = NULL;
796}
797
798static const struct wiimod_ops wiimod_ir = {
799 .flags = 0,
800 .arg = 0,
801 .probe = wiimod_ir_probe,
802 .remove = wiimod_ir_remove,
803 .in_ir = wiimod_ir_in_ir,
804};
805
806
807
808
809
810
811
812
813enum wiimod_nunchuk_keys {
814 WIIMOD_NUNCHUK_KEY_C,
815 WIIMOD_NUNCHUK_KEY_Z,
816 WIIMOD_NUNCHUK_KEY_NUM,
817};
818
819static const __u16 wiimod_nunchuk_map[] = {
820 BTN_C,
821 BTN_Z,
822};
823
824static void wiimod_nunchuk_in_ext(struct wiimote_data *wdata, const __u8 *ext)
825{
826 __s16 x, y, z, bx, by;
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858 bx = ext[0];
859 by = ext[1];
860 bx -= 128;
861 by -= 128;
862
863 x = ext[2] << 2;
864 y = ext[3] << 2;
865 z = ext[4] << 2;
866
867 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
868 x |= (ext[5] >> 3) & 0x02;
869 y |= (ext[5] >> 4) & 0x02;
870 z &= ~0x4;
871 z |= (ext[5] >> 5) & 0x06;
872 } else {
873 x |= (ext[5] >> 2) & 0x03;
874 y |= (ext[5] >> 4) & 0x03;
875 z |= (ext[5] >> 6) & 0x03;
876 }
877
878 x -= 0x200;
879 y -= 0x200;
880 z -= 0x200;
881
882 input_report_abs(wdata->extension.input, ABS_HAT0X, bx);
883 input_report_abs(wdata->extension.input, ABS_HAT0Y, by);
884
885 input_report_abs(wdata->extension.input, ABS_RX, x);
886 input_report_abs(wdata->extension.input, ABS_RY, y);
887 input_report_abs(wdata->extension.input, ABS_RZ, z);
888
889 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
890 input_report_key(wdata->extension.input,
891 wiimod_nunchuk_map[WIIMOD_NUNCHUK_KEY_Z],
892 !(ext[5] & 0x04));
893 input_report_key(wdata->extension.input,
894 wiimod_nunchuk_map[WIIMOD_NUNCHUK_KEY_C],
895 !(ext[5] & 0x08));
896 } else {
897 input_report_key(wdata->extension.input,
898 wiimod_nunchuk_map[WIIMOD_NUNCHUK_KEY_Z],
899 !(ext[5] & 0x01));
900 input_report_key(wdata->extension.input,
901 wiimod_nunchuk_map[WIIMOD_NUNCHUK_KEY_C],
902 !(ext[5] & 0x02));
903 }
904
905 input_sync(wdata->extension.input);
906}
907
908static int wiimod_nunchuk_open(struct input_dev *dev)
909{
910 struct wiimote_data *wdata = input_get_drvdata(dev);
911 unsigned long flags;
912
913 spin_lock_irqsave(&wdata->state.lock, flags);
914 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
915 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
916 spin_unlock_irqrestore(&wdata->state.lock, flags);
917
918 return 0;
919}
920
921static void wiimod_nunchuk_close(struct input_dev *dev)
922{
923 struct wiimote_data *wdata = input_get_drvdata(dev);
924 unsigned long flags;
925
926 spin_lock_irqsave(&wdata->state.lock, flags);
927 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
928 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
929 spin_unlock_irqrestore(&wdata->state.lock, flags);
930}
931
932static int wiimod_nunchuk_probe(const struct wiimod_ops *ops,
933 struct wiimote_data *wdata)
934{
935 int ret, i;
936
937 wdata->extension.input = input_allocate_device();
938 if (!wdata->extension.input)
939 return -ENOMEM;
940
941 input_set_drvdata(wdata->extension.input, wdata);
942 wdata->extension.input->open = wiimod_nunchuk_open;
943 wdata->extension.input->close = wiimod_nunchuk_close;
944 wdata->extension.input->dev.parent = &wdata->hdev->dev;
945 wdata->extension.input->id.bustype = wdata->hdev->bus;
946 wdata->extension.input->id.vendor = wdata->hdev->vendor;
947 wdata->extension.input->id.product = wdata->hdev->product;
948 wdata->extension.input->id.version = wdata->hdev->version;
949 wdata->extension.input->name = WIIMOTE_NAME " Nunchuk";
950
951 set_bit(EV_KEY, wdata->extension.input->evbit);
952 for (i = 0; i < WIIMOD_NUNCHUK_KEY_NUM; ++i)
953 set_bit(wiimod_nunchuk_map[i],
954 wdata->extension.input->keybit);
955
956 set_bit(EV_ABS, wdata->extension.input->evbit);
957 set_bit(ABS_HAT0X, wdata->extension.input->absbit);
958 set_bit(ABS_HAT0Y, wdata->extension.input->absbit);
959 input_set_abs_params(wdata->extension.input,
960 ABS_HAT0X, -120, 120, 2, 4);
961 input_set_abs_params(wdata->extension.input,
962 ABS_HAT0Y, -120, 120, 2, 4);
963 set_bit(ABS_RX, wdata->extension.input->absbit);
964 set_bit(ABS_RY, wdata->extension.input->absbit);
965 set_bit(ABS_RZ, wdata->extension.input->absbit);
966 input_set_abs_params(wdata->extension.input,
967 ABS_RX, -500, 500, 2, 4);
968 input_set_abs_params(wdata->extension.input,
969 ABS_RY, -500, 500, 2, 4);
970 input_set_abs_params(wdata->extension.input,
971 ABS_RZ, -500, 500, 2, 4);
972
973 ret = input_register_device(wdata->extension.input);
974 if (ret)
975 goto err_free;
976
977 return 0;
978
979err_free:
980 input_free_device(wdata->extension.input);
981 wdata->extension.input = NULL;
982 return ret;
983}
984
985static void wiimod_nunchuk_remove(const struct wiimod_ops *ops,
986 struct wiimote_data *wdata)
987{
988 if (!wdata->extension.input)
989 return;
990
991 input_unregister_device(wdata->extension.input);
992 wdata->extension.input = NULL;
993}
994
995static const struct wiimod_ops wiimod_nunchuk = {
996 .flags = 0,
997 .arg = 0,
998 .probe = wiimod_nunchuk_probe,
999 .remove = wiimod_nunchuk_remove,
1000 .in_ext = wiimod_nunchuk_in_ext,
1001};
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011enum wiimod_classic_keys {
1012 WIIMOD_CLASSIC_KEY_A,
1013 WIIMOD_CLASSIC_KEY_B,
1014 WIIMOD_CLASSIC_KEY_X,
1015 WIIMOD_CLASSIC_KEY_Y,
1016 WIIMOD_CLASSIC_KEY_ZL,
1017 WIIMOD_CLASSIC_KEY_ZR,
1018 WIIMOD_CLASSIC_KEY_PLUS,
1019 WIIMOD_CLASSIC_KEY_MINUS,
1020 WIIMOD_CLASSIC_KEY_HOME,
1021 WIIMOD_CLASSIC_KEY_LEFT,
1022 WIIMOD_CLASSIC_KEY_RIGHT,
1023 WIIMOD_CLASSIC_KEY_UP,
1024 WIIMOD_CLASSIC_KEY_DOWN,
1025 WIIMOD_CLASSIC_KEY_LT,
1026 WIIMOD_CLASSIC_KEY_RT,
1027 WIIMOD_CLASSIC_KEY_NUM,
1028};
1029
1030static const __u16 wiimod_classic_map[] = {
1031 BTN_A,
1032 BTN_B,
1033 BTN_X,
1034 BTN_Y,
1035 BTN_TL2,
1036 BTN_TR2,
1037 KEY_NEXT,
1038 KEY_PREVIOUS,
1039 BTN_MODE,
1040 KEY_LEFT,
1041 KEY_RIGHT,
1042 KEY_UP,
1043 KEY_DOWN,
1044 BTN_TL,
1045 BTN_TR,
1046};
1047
1048static void wiimod_classic_in_ext(struct wiimote_data *wdata, const __u8 *ext)
1049{
1050 __s8 rx, ry, lx, ly, lt, rt;
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
1096 lx = ext[0] & 0x3e;
1097 ly = ext[1] & 0x3e;
1098 } else {
1099 lx = ext[0] & 0x3f;
1100 ly = ext[1] & 0x3f;
1101 }
1102
1103 rx = (ext[0] >> 3) & 0x18;
1104 rx |= (ext[1] >> 5) & 0x06;
1105 rx |= (ext[2] >> 7) & 0x01;
1106 ry = ext[2] & 0x1f;
1107
1108 rt = ext[3] & 0x1f;
1109 lt = (ext[2] >> 2) & 0x18;
1110 lt |= (ext[3] >> 5) & 0x07;
1111
1112 rx <<= 1;
1113 ry <<= 1;
1114 rt <<= 1;
1115 lt <<= 1;
1116
1117 input_report_abs(wdata->extension.input, ABS_HAT1X, lx - 0x20);
1118 input_report_abs(wdata->extension.input, ABS_HAT1Y, ly - 0x20);
1119 input_report_abs(wdata->extension.input, ABS_HAT2X, rx - 0x20);
1120 input_report_abs(wdata->extension.input, ABS_HAT2Y, ry - 0x20);
1121 input_report_abs(wdata->extension.input, ABS_HAT3X, rt);
1122 input_report_abs(wdata->extension.input, ABS_HAT3Y, lt);
1123
1124 input_report_key(wdata->extension.input,
1125 wiimod_classic_map[WIIMOD_CLASSIC_KEY_RIGHT],
1126 !(ext[4] & 0x80));
1127 input_report_key(wdata->extension.input,
1128 wiimod_classic_map[WIIMOD_CLASSIC_KEY_DOWN],
1129 !(ext[4] & 0x40));
1130 input_report_key(wdata->extension.input,
1131 wiimod_classic_map[WIIMOD_CLASSIC_KEY_LT],
1132 !(ext[4] & 0x20));
1133 input_report_key(wdata->extension.input,
1134 wiimod_classic_map[WIIMOD_CLASSIC_KEY_MINUS],
1135 !(ext[4] & 0x10));
1136 input_report_key(wdata->extension.input,
1137 wiimod_classic_map[WIIMOD_CLASSIC_KEY_HOME],
1138 !(ext[4] & 0x08));
1139 input_report_key(wdata->extension.input,
1140 wiimod_classic_map[WIIMOD_CLASSIC_KEY_PLUS],
1141 !(ext[4] & 0x04));
1142 input_report_key(wdata->extension.input,
1143 wiimod_classic_map[WIIMOD_CLASSIC_KEY_RT],
1144 !(ext[4] & 0x02));
1145 input_report_key(wdata->extension.input,
1146 wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZL],
1147 !(ext[5] & 0x80));
1148 input_report_key(wdata->extension.input,
1149 wiimod_classic_map[WIIMOD_CLASSIC_KEY_B],
1150 !(ext[5] & 0x40));
1151 input_report_key(wdata->extension.input,
1152 wiimod_classic_map[WIIMOD_CLASSIC_KEY_Y],
1153 !(ext[5] & 0x20));
1154 input_report_key(wdata->extension.input,
1155 wiimod_classic_map[WIIMOD_CLASSIC_KEY_A],
1156 !(ext[5] & 0x10));
1157 input_report_key(wdata->extension.input,
1158 wiimod_classic_map[WIIMOD_CLASSIC_KEY_X],
1159 !(ext[5] & 0x08));
1160 input_report_key(wdata->extension.input,
1161 wiimod_classic_map[WIIMOD_CLASSIC_KEY_ZR],
1162 !(ext[5] & 0x04));
1163
1164 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) {
1165 input_report_key(wdata->extension.input,
1166 wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1167 !(ext[1] & 0x01));
1168 input_report_key(wdata->extension.input,
1169 wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1170 !(ext[0] & 0x01));
1171 } else {
1172 input_report_key(wdata->extension.input,
1173 wiimod_classic_map[WIIMOD_CLASSIC_KEY_LEFT],
1174 !(ext[5] & 0x02));
1175 input_report_key(wdata->extension.input,
1176 wiimod_classic_map[WIIMOD_CLASSIC_KEY_UP],
1177 !(ext[5] & 0x01));
1178 }
1179
1180 input_sync(wdata->extension.input);
1181}
1182
1183static int wiimod_classic_open(struct input_dev *dev)
1184{
1185 struct wiimote_data *wdata = input_get_drvdata(dev);
1186 unsigned long flags;
1187
1188 spin_lock_irqsave(&wdata->state.lock, flags);
1189 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
1190 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1191 spin_unlock_irqrestore(&wdata->state.lock, flags);
1192
1193 return 0;
1194}
1195
1196static void wiimod_classic_close(struct input_dev *dev)
1197{
1198 struct wiimote_data *wdata = input_get_drvdata(dev);
1199 unsigned long flags;
1200
1201 spin_lock_irqsave(&wdata->state.lock, flags);
1202 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
1203 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1204 spin_unlock_irqrestore(&wdata->state.lock, flags);
1205}
1206
1207static int wiimod_classic_probe(const struct wiimod_ops *ops,
1208 struct wiimote_data *wdata)
1209{
1210 int ret, i;
1211
1212 wdata->extension.input = input_allocate_device();
1213 if (!wdata->extension.input)
1214 return -ENOMEM;
1215
1216 input_set_drvdata(wdata->extension.input, wdata);
1217 wdata->extension.input->open = wiimod_classic_open;
1218 wdata->extension.input->close = wiimod_classic_close;
1219 wdata->extension.input->dev.parent = &wdata->hdev->dev;
1220 wdata->extension.input->id.bustype = wdata->hdev->bus;
1221 wdata->extension.input->id.vendor = wdata->hdev->vendor;
1222 wdata->extension.input->id.product = wdata->hdev->product;
1223 wdata->extension.input->id.version = wdata->hdev->version;
1224 wdata->extension.input->name = WIIMOTE_NAME " Classic Controller";
1225
1226 set_bit(EV_KEY, wdata->extension.input->evbit);
1227 for (i = 0; i < WIIMOD_CLASSIC_KEY_NUM; ++i)
1228 set_bit(wiimod_classic_map[i],
1229 wdata->extension.input->keybit);
1230
1231 set_bit(EV_ABS, wdata->extension.input->evbit);
1232 set_bit(ABS_HAT1X, wdata->extension.input->absbit);
1233 set_bit(ABS_HAT1Y, wdata->extension.input->absbit);
1234 set_bit(ABS_HAT2X, wdata->extension.input->absbit);
1235 set_bit(ABS_HAT2Y, wdata->extension.input->absbit);
1236 set_bit(ABS_HAT3X, wdata->extension.input->absbit);
1237 set_bit(ABS_HAT3Y, wdata->extension.input->absbit);
1238 input_set_abs_params(wdata->extension.input,
1239 ABS_HAT1X, -30, 30, 1, 1);
1240 input_set_abs_params(wdata->extension.input,
1241 ABS_HAT1Y, -30, 30, 1, 1);
1242 input_set_abs_params(wdata->extension.input,
1243 ABS_HAT2X, -30, 30, 1, 1);
1244 input_set_abs_params(wdata->extension.input,
1245 ABS_HAT2Y, -30, 30, 1, 1);
1246 input_set_abs_params(wdata->extension.input,
1247 ABS_HAT3X, -30, 30, 1, 1);
1248 input_set_abs_params(wdata->extension.input,
1249 ABS_HAT3Y, -30, 30, 1, 1);
1250
1251 ret = input_register_device(wdata->extension.input);
1252 if (ret)
1253 goto err_free;
1254
1255 return 0;
1256
1257err_free:
1258 input_free_device(wdata->extension.input);
1259 wdata->extension.input = NULL;
1260 return ret;
1261}
1262
1263static void wiimod_classic_remove(const struct wiimod_ops *ops,
1264 struct wiimote_data *wdata)
1265{
1266 if (!wdata->extension.input)
1267 return;
1268
1269 input_unregister_device(wdata->extension.input);
1270 wdata->extension.input = NULL;
1271}
1272
1273static const struct wiimod_ops wiimod_classic = {
1274 .flags = 0,
1275 .arg = 0,
1276 .probe = wiimod_classic_probe,
1277 .remove = wiimod_classic_remove,
1278 .in_ext = wiimod_classic_in_ext,
1279};
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294static void wiimod_bboard_in_keys(struct wiimote_data *wdata, const __u8 *keys)
1295{
1296 input_report_key(wdata->extension.input, BTN_A,
1297 !!(keys[1] & 0x08));
1298 input_sync(wdata->extension.input);
1299}
1300
1301static void wiimod_bboard_in_ext(struct wiimote_data *wdata,
1302 const __u8 *ext)
1303{
1304 __s32 val[4], tmp, div;
1305 unsigned int i;
1306 struct wiimote_state *s = &wdata->state;
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332 val[0] = ext[0];
1333 val[0] <<= 8;
1334 val[0] |= ext[1];
1335
1336 val[1] = ext[2];
1337 val[1] <<= 8;
1338 val[1] |= ext[3];
1339
1340 val[2] = ext[4];
1341 val[2] <<= 8;
1342 val[2] |= ext[5];
1343
1344 val[3] = ext[6];
1345 val[3] <<= 8;
1346 val[3] |= ext[7];
1347
1348
1349 for (i = 0; i < 4; i++) {
1350 if (val[i] <= s->calib_bboard[i][0]) {
1351 tmp = 0;
1352 } else if (val[i] < s->calib_bboard[i][1]) {
1353 tmp = val[i] - s->calib_bboard[i][0];
1354 tmp *= 1700;
1355 div = s->calib_bboard[i][1] - s->calib_bboard[i][0];
1356 tmp /= div ? div : 1;
1357 } else {
1358 tmp = val[i] - s->calib_bboard[i][1];
1359 tmp *= 1700;
1360 div = s->calib_bboard[i][2] - s->calib_bboard[i][1];
1361 tmp /= div ? div : 1;
1362 tmp += 1700;
1363 }
1364 val[i] = tmp;
1365 }
1366
1367 input_report_abs(wdata->extension.input, ABS_HAT0X, val[0]);
1368 input_report_abs(wdata->extension.input, ABS_HAT0Y, val[1]);
1369 input_report_abs(wdata->extension.input, ABS_HAT1X, val[2]);
1370 input_report_abs(wdata->extension.input, ABS_HAT1Y, val[3]);
1371 input_sync(wdata->extension.input);
1372}
1373
1374static int wiimod_bboard_open(struct input_dev *dev)
1375{
1376 struct wiimote_data *wdata = input_get_drvdata(dev);
1377 unsigned long flags;
1378
1379 spin_lock_irqsave(&wdata->state.lock, flags);
1380 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
1381 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1382 spin_unlock_irqrestore(&wdata->state.lock, flags);
1383
1384 return 0;
1385}
1386
1387static void wiimod_bboard_close(struct input_dev *dev)
1388{
1389 struct wiimote_data *wdata = input_get_drvdata(dev);
1390 unsigned long flags;
1391
1392 spin_lock_irqsave(&wdata->state.lock, flags);
1393 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
1394 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1395 spin_unlock_irqrestore(&wdata->state.lock, flags);
1396}
1397
1398static ssize_t wiimod_bboard_calib_show(struct device *dev,
1399 struct device_attribute *attr,
1400 char *out)
1401{
1402 struct wiimote_data *wdata = dev_to_wii(dev);
1403 int i, j, ret;
1404 __u16 val;
1405 __u8 buf[24], offs;
1406
1407 ret = wiimote_cmd_acquire(wdata);
1408 if (ret)
1409 return ret;
1410
1411 ret = wiimote_cmd_read(wdata, 0xa40024, buf, 12);
1412 if (ret != 12) {
1413 wiimote_cmd_release(wdata);
1414 return ret < 0 ? ret : -EIO;
1415 }
1416 ret = wiimote_cmd_read(wdata, 0xa40024 + 12, buf + 12, 12);
1417 if (ret != 12) {
1418 wiimote_cmd_release(wdata);
1419 return ret < 0 ? ret : -EIO;
1420 }
1421
1422 wiimote_cmd_release(wdata);
1423
1424 spin_lock_irq(&wdata->state.lock);
1425 offs = 0;
1426 for (i = 0; i < 3; ++i) {
1427 for (j = 0; j < 4; ++j) {
1428 wdata->state.calib_bboard[j][i] = buf[offs];
1429 wdata->state.calib_bboard[j][i] <<= 8;
1430 wdata->state.calib_bboard[j][i] |= buf[offs + 1];
1431 offs += 2;
1432 }
1433 }
1434 spin_unlock_irq(&wdata->state.lock);
1435
1436 ret = 0;
1437 for (i = 0; i < 3; ++i) {
1438 for (j = 0; j < 4; ++j) {
1439 val = wdata->state.calib_bboard[j][i];
1440 if (i == 2 && j == 3)
1441 ret += sprintf(&out[ret], "%04x\n", val);
1442 else
1443 ret += sprintf(&out[ret], "%04x:", val);
1444 }
1445 }
1446
1447 return ret;
1448}
1449
1450static DEVICE_ATTR(bboard_calib, S_IRUGO, wiimod_bboard_calib_show, NULL);
1451
1452static int wiimod_bboard_probe(const struct wiimod_ops *ops,
1453 struct wiimote_data *wdata)
1454{
1455 int ret, i, j;
1456 __u8 buf[24], offs;
1457
1458 wiimote_cmd_acquire_noint(wdata);
1459
1460 ret = wiimote_cmd_read(wdata, 0xa40024, buf, 12);
1461 if (ret != 12) {
1462 wiimote_cmd_release(wdata);
1463 return ret < 0 ? ret : -EIO;
1464 }
1465 ret = wiimote_cmd_read(wdata, 0xa40024 + 12, buf + 12, 12);
1466 if (ret != 12) {
1467 wiimote_cmd_release(wdata);
1468 return ret < 0 ? ret : -EIO;
1469 }
1470
1471 wiimote_cmd_release(wdata);
1472
1473 offs = 0;
1474 for (i = 0; i < 3; ++i) {
1475 for (j = 0; j < 4; ++j) {
1476 wdata->state.calib_bboard[j][i] = buf[offs];
1477 wdata->state.calib_bboard[j][i] <<= 8;
1478 wdata->state.calib_bboard[j][i] |= buf[offs + 1];
1479 offs += 2;
1480 }
1481 }
1482
1483 wdata->extension.input = input_allocate_device();
1484 if (!wdata->extension.input)
1485 return -ENOMEM;
1486
1487 ret = device_create_file(&wdata->hdev->dev,
1488 &dev_attr_bboard_calib);
1489 if (ret) {
1490 hid_err(wdata->hdev, "cannot create sysfs attribute\n");
1491 goto err_free;
1492 }
1493
1494 input_set_drvdata(wdata->extension.input, wdata);
1495 wdata->extension.input->open = wiimod_bboard_open;
1496 wdata->extension.input->close = wiimod_bboard_close;
1497 wdata->extension.input->dev.parent = &wdata->hdev->dev;
1498 wdata->extension.input->id.bustype = wdata->hdev->bus;
1499 wdata->extension.input->id.vendor = wdata->hdev->vendor;
1500 wdata->extension.input->id.product = wdata->hdev->product;
1501 wdata->extension.input->id.version = wdata->hdev->version;
1502 wdata->extension.input->name = WIIMOTE_NAME " Balance Board";
1503
1504 set_bit(EV_KEY, wdata->extension.input->evbit);
1505 set_bit(BTN_A, wdata->extension.input->keybit);
1506
1507 set_bit(EV_ABS, wdata->extension.input->evbit);
1508 set_bit(ABS_HAT0X, wdata->extension.input->absbit);
1509 set_bit(ABS_HAT0Y, wdata->extension.input->absbit);
1510 set_bit(ABS_HAT1X, wdata->extension.input->absbit);
1511 set_bit(ABS_HAT1Y, wdata->extension.input->absbit);
1512 input_set_abs_params(wdata->extension.input,
1513 ABS_HAT0X, 0, 65535, 2, 4);
1514 input_set_abs_params(wdata->extension.input,
1515 ABS_HAT0Y, 0, 65535, 2, 4);
1516 input_set_abs_params(wdata->extension.input,
1517 ABS_HAT1X, 0, 65535, 2, 4);
1518 input_set_abs_params(wdata->extension.input,
1519 ABS_HAT1Y, 0, 65535, 2, 4);
1520
1521 ret = input_register_device(wdata->extension.input);
1522 if (ret)
1523 goto err_file;
1524
1525 return 0;
1526
1527err_file:
1528 device_remove_file(&wdata->hdev->dev,
1529 &dev_attr_bboard_calib);
1530err_free:
1531 input_free_device(wdata->extension.input);
1532 wdata->extension.input = NULL;
1533 return ret;
1534}
1535
1536static void wiimod_bboard_remove(const struct wiimod_ops *ops,
1537 struct wiimote_data *wdata)
1538{
1539 if (!wdata->extension.input)
1540 return;
1541
1542 input_unregister_device(wdata->extension.input);
1543 wdata->extension.input = NULL;
1544 device_remove_file(&wdata->hdev->dev,
1545 &dev_attr_bboard_calib);
1546}
1547
1548static const struct wiimod_ops wiimod_bboard = {
1549 .flags = WIIMOD_FLAG_EXT8,
1550 .arg = 0,
1551 .probe = wiimod_bboard_probe,
1552 .remove = wiimod_bboard_remove,
1553 .in_keys = wiimod_bboard_in_keys,
1554 .in_ext = wiimod_bboard_in_ext,
1555};
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567enum wiimod_pro_keys {
1568 WIIMOD_PRO_KEY_A,
1569 WIIMOD_PRO_KEY_B,
1570 WIIMOD_PRO_KEY_X,
1571 WIIMOD_PRO_KEY_Y,
1572 WIIMOD_PRO_KEY_PLUS,
1573 WIIMOD_PRO_KEY_MINUS,
1574 WIIMOD_PRO_KEY_HOME,
1575 WIIMOD_PRO_KEY_LEFT,
1576 WIIMOD_PRO_KEY_RIGHT,
1577 WIIMOD_PRO_KEY_UP,
1578 WIIMOD_PRO_KEY_DOWN,
1579 WIIMOD_PRO_KEY_TL,
1580 WIIMOD_PRO_KEY_TR,
1581 WIIMOD_PRO_KEY_ZL,
1582 WIIMOD_PRO_KEY_ZR,
1583 WIIMOD_PRO_KEY_THUMBL,
1584 WIIMOD_PRO_KEY_THUMBR,
1585 WIIMOD_PRO_KEY_NUM,
1586};
1587
1588static const __u16 wiimod_pro_map[] = {
1589 BTN_EAST,
1590 BTN_SOUTH,
1591 BTN_NORTH,
1592 BTN_WEST,
1593 BTN_START,
1594 BTN_SELECT,
1595 BTN_MODE,
1596 BTN_DPAD_LEFT,
1597 BTN_DPAD_RIGHT,
1598 BTN_DPAD_UP,
1599 BTN_DPAD_DOWN,
1600 BTN_TL,
1601 BTN_TR,
1602 BTN_TL2,
1603 BTN_TR2,
1604 BTN_THUMBL,
1605 BTN_THUMBR,
1606};
1607
1608static void wiimod_pro_in_ext(struct wiimote_data *wdata, const __u8 *ext)
1609{
1610 __s16 rx, ry, lx, ly;
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653 lx = (ext[0] & 0xff) | ((ext[1] & 0x0f) << 8);
1654 rx = (ext[2] & 0xff) | ((ext[3] & 0x0f) << 8);
1655 ly = (ext[4] & 0xff) | ((ext[5] & 0x0f) << 8);
1656 ry = (ext[6] & 0xff) | ((ext[7] & 0x0f) << 8);
1657
1658
1659 lx -= 0x800;
1660 ly = 0x800 - ly;
1661 rx -= 0x800;
1662 ry = 0x800 - ry;
1663
1664
1665
1666
1667
1668
1669 if (!(wdata->state.flags & WIIPROTO_FLAG_PRO_CALIB_DONE)) {
1670 wdata->state.flags |= WIIPROTO_FLAG_PRO_CALIB_DONE;
1671 if (abs(lx) < 500)
1672 wdata->state.calib_pro_sticks[0] = -lx;
1673 if (abs(ly) < 500)
1674 wdata->state.calib_pro_sticks[1] = -ly;
1675 if (abs(rx) < 500)
1676 wdata->state.calib_pro_sticks[2] = -rx;
1677 if (abs(ry) < 500)
1678 wdata->state.calib_pro_sticks[3] = -ry;
1679 }
1680
1681
1682 lx += wdata->state.calib_pro_sticks[0];
1683 ly += wdata->state.calib_pro_sticks[1];
1684 rx += wdata->state.calib_pro_sticks[2];
1685 ry += wdata->state.calib_pro_sticks[3];
1686
1687 input_report_abs(wdata->extension.input, ABS_X, lx);
1688 input_report_abs(wdata->extension.input, ABS_Y, ly);
1689 input_report_abs(wdata->extension.input, ABS_RX, rx);
1690 input_report_abs(wdata->extension.input, ABS_RY, ry);
1691
1692 input_report_key(wdata->extension.input,
1693 wiimod_pro_map[WIIMOD_PRO_KEY_RIGHT],
1694 !(ext[8] & 0x80));
1695 input_report_key(wdata->extension.input,
1696 wiimod_pro_map[WIIMOD_PRO_KEY_DOWN],
1697 !(ext[8] & 0x40));
1698 input_report_key(wdata->extension.input,
1699 wiimod_pro_map[WIIMOD_PRO_KEY_TL],
1700 !(ext[8] & 0x20));
1701 input_report_key(wdata->extension.input,
1702 wiimod_pro_map[WIIMOD_PRO_KEY_MINUS],
1703 !(ext[8] & 0x10));
1704 input_report_key(wdata->extension.input,
1705 wiimod_pro_map[WIIMOD_PRO_KEY_HOME],
1706 !(ext[8] & 0x08));
1707 input_report_key(wdata->extension.input,
1708 wiimod_pro_map[WIIMOD_PRO_KEY_PLUS],
1709 !(ext[8] & 0x04));
1710 input_report_key(wdata->extension.input,
1711 wiimod_pro_map[WIIMOD_PRO_KEY_TR],
1712 !(ext[8] & 0x02));
1713
1714 input_report_key(wdata->extension.input,
1715 wiimod_pro_map[WIIMOD_PRO_KEY_ZL],
1716 !(ext[9] & 0x80));
1717 input_report_key(wdata->extension.input,
1718 wiimod_pro_map[WIIMOD_PRO_KEY_B],
1719 !(ext[9] & 0x40));
1720 input_report_key(wdata->extension.input,
1721 wiimod_pro_map[WIIMOD_PRO_KEY_Y],
1722 !(ext[9] & 0x20));
1723 input_report_key(wdata->extension.input,
1724 wiimod_pro_map[WIIMOD_PRO_KEY_A],
1725 !(ext[9] & 0x10));
1726 input_report_key(wdata->extension.input,
1727 wiimod_pro_map[WIIMOD_PRO_KEY_X],
1728 !(ext[9] & 0x08));
1729 input_report_key(wdata->extension.input,
1730 wiimod_pro_map[WIIMOD_PRO_KEY_ZR],
1731 !(ext[9] & 0x04));
1732 input_report_key(wdata->extension.input,
1733 wiimod_pro_map[WIIMOD_PRO_KEY_LEFT],
1734 !(ext[9] & 0x02));
1735 input_report_key(wdata->extension.input,
1736 wiimod_pro_map[WIIMOD_PRO_KEY_UP],
1737 !(ext[9] & 0x01));
1738
1739 input_report_key(wdata->extension.input,
1740 wiimod_pro_map[WIIMOD_PRO_KEY_THUMBL],
1741 !(ext[10] & 0x02));
1742 input_report_key(wdata->extension.input,
1743 wiimod_pro_map[WIIMOD_PRO_KEY_THUMBR],
1744 !(ext[10] & 0x01));
1745
1746 input_sync(wdata->extension.input);
1747}
1748
1749static int wiimod_pro_open(struct input_dev *dev)
1750{
1751 struct wiimote_data *wdata = input_get_drvdata(dev);
1752 unsigned long flags;
1753
1754 spin_lock_irqsave(&wdata->state.lock, flags);
1755 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
1756 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1757 spin_unlock_irqrestore(&wdata->state.lock, flags);
1758
1759 return 0;
1760}
1761
1762static void wiimod_pro_close(struct input_dev *dev)
1763{
1764 struct wiimote_data *wdata = input_get_drvdata(dev);
1765 unsigned long flags;
1766
1767 spin_lock_irqsave(&wdata->state.lock, flags);
1768 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
1769 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1770 spin_unlock_irqrestore(&wdata->state.lock, flags);
1771}
1772
1773static int wiimod_pro_play(struct input_dev *dev, void *data,
1774 struct ff_effect *eff)
1775{
1776 struct wiimote_data *wdata = input_get_drvdata(dev);
1777 __u8 value;
1778
1779
1780
1781
1782
1783
1784
1785 if (eff->u.rumble.strong_magnitude || eff->u.rumble.weak_magnitude)
1786 value = 1;
1787 else
1788 value = 0;
1789
1790
1791
1792 wdata->state.cache_rumble = value;
1793 schedule_work(&wdata->rumble_worker);
1794
1795 return 0;
1796}
1797
1798static ssize_t wiimod_pro_calib_show(struct device *dev,
1799 struct device_attribute *attr,
1800 char *out)
1801{
1802 struct wiimote_data *wdata = dev_to_wii(dev);
1803 int r;
1804
1805 r = 0;
1806 r += sprintf(&out[r], "%+06hd:", wdata->state.calib_pro_sticks[0]);
1807 r += sprintf(&out[r], "%+06hd ", wdata->state.calib_pro_sticks[1]);
1808 r += sprintf(&out[r], "%+06hd:", wdata->state.calib_pro_sticks[2]);
1809 r += sprintf(&out[r], "%+06hd\n", wdata->state.calib_pro_sticks[3]);
1810
1811 return r;
1812}
1813
1814static ssize_t wiimod_pro_calib_store(struct device *dev,
1815 struct device_attribute *attr,
1816 const char *buf, size_t count)
1817{
1818 struct wiimote_data *wdata = dev_to_wii(dev);
1819 int r;
1820 s16 x1, y1, x2, y2;
1821
1822 if (!strncmp(buf, "scan\n", 5)) {
1823 spin_lock_irq(&wdata->state.lock);
1824 wdata->state.flags &= ~WIIPROTO_FLAG_PRO_CALIB_DONE;
1825 spin_unlock_irq(&wdata->state.lock);
1826 } else {
1827 r = sscanf(buf, "%hd:%hd %hd:%hd", &x1, &y1, &x2, &y2);
1828 if (r != 4)
1829 return -EINVAL;
1830
1831 spin_lock_irq(&wdata->state.lock);
1832 wdata->state.flags |= WIIPROTO_FLAG_PRO_CALIB_DONE;
1833 spin_unlock_irq(&wdata->state.lock);
1834
1835 wdata->state.calib_pro_sticks[0] = x1;
1836 wdata->state.calib_pro_sticks[1] = y1;
1837 wdata->state.calib_pro_sticks[2] = x2;
1838 wdata->state.calib_pro_sticks[3] = y2;
1839 }
1840
1841 return strnlen(buf, PAGE_SIZE);
1842}
1843
1844static DEVICE_ATTR(pro_calib, S_IRUGO|S_IWUSR|S_IWGRP, wiimod_pro_calib_show,
1845 wiimod_pro_calib_store);
1846
1847static int wiimod_pro_probe(const struct wiimod_ops *ops,
1848 struct wiimote_data *wdata)
1849{
1850 int ret, i;
1851 unsigned long flags;
1852
1853 INIT_WORK(&wdata->rumble_worker, wiimod_rumble_worker);
1854 wdata->state.calib_pro_sticks[0] = 0;
1855 wdata->state.calib_pro_sticks[1] = 0;
1856 wdata->state.calib_pro_sticks[2] = 0;
1857 wdata->state.calib_pro_sticks[3] = 0;
1858
1859 spin_lock_irqsave(&wdata->state.lock, flags);
1860 wdata->state.flags &= ~WIIPROTO_FLAG_PRO_CALIB_DONE;
1861 spin_unlock_irqrestore(&wdata->state.lock, flags);
1862
1863 wdata->extension.input = input_allocate_device();
1864 if (!wdata->extension.input)
1865 return -ENOMEM;
1866
1867 set_bit(FF_RUMBLE, wdata->extension.input->ffbit);
1868 input_set_drvdata(wdata->extension.input, wdata);
1869
1870 if (input_ff_create_memless(wdata->extension.input, NULL,
1871 wiimod_pro_play)) {
1872 ret = -ENOMEM;
1873 goto err_free;
1874 }
1875
1876 ret = device_create_file(&wdata->hdev->dev,
1877 &dev_attr_pro_calib);
1878 if (ret) {
1879 hid_err(wdata->hdev, "cannot create sysfs attribute\n");
1880 goto err_free;
1881 }
1882
1883 wdata->extension.input->open = wiimod_pro_open;
1884 wdata->extension.input->close = wiimod_pro_close;
1885 wdata->extension.input->dev.parent = &wdata->hdev->dev;
1886 wdata->extension.input->id.bustype = wdata->hdev->bus;
1887 wdata->extension.input->id.vendor = wdata->hdev->vendor;
1888 wdata->extension.input->id.product = wdata->hdev->product;
1889 wdata->extension.input->id.version = wdata->hdev->version;
1890 wdata->extension.input->name = WIIMOTE_NAME " Pro Controller";
1891
1892 set_bit(EV_KEY, wdata->extension.input->evbit);
1893 for (i = 0; i < WIIMOD_PRO_KEY_NUM; ++i)
1894 set_bit(wiimod_pro_map[i],
1895 wdata->extension.input->keybit);
1896
1897 set_bit(EV_ABS, wdata->extension.input->evbit);
1898 set_bit(ABS_X, wdata->extension.input->absbit);
1899 set_bit(ABS_Y, wdata->extension.input->absbit);
1900 set_bit(ABS_RX, wdata->extension.input->absbit);
1901 set_bit(ABS_RY, wdata->extension.input->absbit);
1902 input_set_abs_params(wdata->extension.input,
1903 ABS_X, -0x400, 0x400, 4, 100);
1904 input_set_abs_params(wdata->extension.input,
1905 ABS_Y, -0x400, 0x400, 4, 100);
1906 input_set_abs_params(wdata->extension.input,
1907 ABS_RX, -0x400, 0x400, 4, 100);
1908 input_set_abs_params(wdata->extension.input,
1909 ABS_RY, -0x400, 0x400, 4, 100);
1910
1911 ret = input_register_device(wdata->extension.input);
1912 if (ret)
1913 goto err_file;
1914
1915 return 0;
1916
1917err_file:
1918 device_remove_file(&wdata->hdev->dev,
1919 &dev_attr_pro_calib);
1920err_free:
1921 input_free_device(wdata->extension.input);
1922 wdata->extension.input = NULL;
1923 return ret;
1924}
1925
1926static void wiimod_pro_remove(const struct wiimod_ops *ops,
1927 struct wiimote_data *wdata)
1928{
1929 unsigned long flags;
1930
1931 if (!wdata->extension.input)
1932 return;
1933
1934 input_unregister_device(wdata->extension.input);
1935 wdata->extension.input = NULL;
1936 cancel_work_sync(&wdata->rumble_worker);
1937 device_remove_file(&wdata->hdev->dev,
1938 &dev_attr_pro_calib);
1939
1940 spin_lock_irqsave(&wdata->state.lock, flags);
1941 wiiproto_req_rumble(wdata, 0);
1942 spin_unlock_irqrestore(&wdata->state.lock, flags);
1943}
1944
1945static const struct wiimod_ops wiimod_pro = {
1946 .flags = WIIMOD_FLAG_EXT16,
1947 .arg = 0,
1948 .probe = wiimod_pro_probe,
1949 .remove = wiimod_pro_remove,
1950 .in_ext = wiimod_pro_in_ext,
1951};
1952
1953
1954
1955
1956
1957
1958
1959
1960static int wiimod_builtin_mp_probe(const struct wiimod_ops *ops,
1961 struct wiimote_data *wdata)
1962{
1963 unsigned long flags;
1964
1965 spin_lock_irqsave(&wdata->state.lock, flags);
1966 wdata->state.flags |= WIIPROTO_FLAG_BUILTIN_MP;
1967 spin_unlock_irqrestore(&wdata->state.lock, flags);
1968
1969 return 0;
1970}
1971
1972static void wiimod_builtin_mp_remove(const struct wiimod_ops *ops,
1973 struct wiimote_data *wdata)
1974{
1975 unsigned long flags;
1976
1977 spin_lock_irqsave(&wdata->state.lock, flags);
1978 wdata->state.flags |= WIIPROTO_FLAG_BUILTIN_MP;
1979 spin_unlock_irqrestore(&wdata->state.lock, flags);
1980}
1981
1982static const struct wiimod_ops wiimod_builtin_mp = {
1983 .flags = 0,
1984 .arg = 0,
1985 .probe = wiimod_builtin_mp_probe,
1986 .remove = wiimod_builtin_mp_remove,
1987};
1988
1989
1990
1991
1992
1993
1994
1995
1996static int wiimod_no_mp_probe(const struct wiimod_ops *ops,
1997 struct wiimote_data *wdata)
1998{
1999 unsigned long flags;
2000
2001 spin_lock_irqsave(&wdata->state.lock, flags);
2002 wdata->state.flags |= WIIPROTO_FLAG_NO_MP;
2003 spin_unlock_irqrestore(&wdata->state.lock, flags);
2004
2005 return 0;
2006}
2007
2008static void wiimod_no_mp_remove(const struct wiimod_ops *ops,
2009 struct wiimote_data *wdata)
2010{
2011 unsigned long flags;
2012
2013 spin_lock_irqsave(&wdata->state.lock, flags);
2014 wdata->state.flags |= WIIPROTO_FLAG_NO_MP;
2015 spin_unlock_irqrestore(&wdata->state.lock, flags);
2016}
2017
2018static const struct wiimod_ops wiimod_no_mp = {
2019 .flags = 0,
2020 .arg = 0,
2021 .probe = wiimod_no_mp_probe,
2022 .remove = wiimod_no_mp_remove,
2023};
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035static void wiimod_mp_in_mp(struct wiimote_data *wdata, const __u8 *ext)
2036{
2037 __s32 x, y, z;
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061 x = ext[0];
2062 y = ext[1];
2063 z = ext[2];
2064
2065 x |= (((__u16)ext[3]) << 6) & 0xff00;
2066 y |= (((__u16)ext[4]) << 6) & 0xff00;
2067 z |= (((__u16)ext[5]) << 6) & 0xff00;
2068
2069 x -= 8192;
2070 y -= 8192;
2071 z -= 8192;
2072
2073 if (!(ext[3] & 0x02))
2074 x *= 18;
2075 else
2076 x *= 9;
2077 if (!(ext[4] & 0x02))
2078 y *= 18;
2079 else
2080 y *= 9;
2081 if (!(ext[3] & 0x01))
2082 z *= 18;
2083 else
2084 z *= 9;
2085
2086 input_report_abs(wdata->mp, ABS_RX, x);
2087 input_report_abs(wdata->mp, ABS_RY, y);
2088 input_report_abs(wdata->mp, ABS_RZ, z);
2089 input_sync(wdata->mp);
2090}
2091
2092static int wiimod_mp_open(struct input_dev *dev)
2093{
2094 struct wiimote_data *wdata = input_get_drvdata(dev);
2095 unsigned long flags;
2096
2097 spin_lock_irqsave(&wdata->state.lock, flags);
2098 wdata->state.flags |= WIIPROTO_FLAG_MP_USED;
2099 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
2100 __wiimote_schedule(wdata);
2101 spin_unlock_irqrestore(&wdata->state.lock, flags);
2102
2103 return 0;
2104}
2105
2106static void wiimod_mp_close(struct input_dev *dev)
2107{
2108 struct wiimote_data *wdata = input_get_drvdata(dev);
2109 unsigned long flags;
2110
2111 spin_lock_irqsave(&wdata->state.lock, flags);
2112 wdata->state.flags &= ~WIIPROTO_FLAG_MP_USED;
2113 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
2114 __wiimote_schedule(wdata);
2115 spin_unlock_irqrestore(&wdata->state.lock, flags);
2116}
2117
2118static int wiimod_mp_probe(const struct wiimod_ops *ops,
2119 struct wiimote_data *wdata)
2120{
2121 int ret;
2122
2123 wdata->mp = input_allocate_device();
2124 if (!wdata->mp)
2125 return -ENOMEM;
2126
2127 input_set_drvdata(wdata->mp, wdata);
2128 wdata->mp->open = wiimod_mp_open;
2129 wdata->mp->close = wiimod_mp_close;
2130 wdata->mp->dev.parent = &wdata->hdev->dev;
2131 wdata->mp->id.bustype = wdata->hdev->bus;
2132 wdata->mp->id.vendor = wdata->hdev->vendor;
2133 wdata->mp->id.product = wdata->hdev->product;
2134 wdata->mp->id.version = wdata->hdev->version;
2135 wdata->mp->name = WIIMOTE_NAME " Motion Plus";
2136
2137 set_bit(EV_ABS, wdata->mp->evbit);
2138 set_bit(ABS_RX, wdata->mp->absbit);
2139 set_bit(ABS_RY, wdata->mp->absbit);
2140 set_bit(ABS_RZ, wdata->mp->absbit);
2141 input_set_abs_params(wdata->mp,
2142 ABS_RX, -16000, 16000, 4, 8);
2143 input_set_abs_params(wdata->mp,
2144 ABS_RY, -16000, 16000, 4, 8);
2145 input_set_abs_params(wdata->mp,
2146 ABS_RZ, -16000, 16000, 4, 8);
2147
2148 ret = input_register_device(wdata->mp);
2149 if (ret)
2150 goto err_free;
2151
2152 return 0;
2153
2154err_free:
2155 input_free_device(wdata->mp);
2156 wdata->mp = NULL;
2157 return ret;
2158}
2159
2160static void wiimod_mp_remove(const struct wiimod_ops *ops,
2161 struct wiimote_data *wdata)
2162{
2163 if (!wdata->mp)
2164 return;
2165
2166 input_unregister_device(wdata->mp);
2167 wdata->mp = NULL;
2168}
2169
2170const struct wiimod_ops wiimod_mp = {
2171 .flags = 0,
2172 .arg = 0,
2173 .probe = wiimod_mp_probe,
2174 .remove = wiimod_mp_remove,
2175 .in_mp = wiimod_mp_in_mp,
2176};
2177
2178
2179
2180static const struct wiimod_ops wiimod_dummy;
2181
2182const struct wiimod_ops *wiimod_table[WIIMOD_NUM] = {
2183 [WIIMOD_KEYS] = &wiimod_keys,
2184 [WIIMOD_RUMBLE] = &wiimod_rumble,
2185 [WIIMOD_BATTERY] = &wiimod_battery,
2186 [WIIMOD_LED1] = &wiimod_leds[0],
2187 [WIIMOD_LED2] = &wiimod_leds[1],
2188 [WIIMOD_LED3] = &wiimod_leds[2],
2189 [WIIMOD_LED4] = &wiimod_leds[3],
2190 [WIIMOD_ACCEL] = &wiimod_accel,
2191 [WIIMOD_IR] = &wiimod_ir,
2192 [WIIMOD_BUILTIN_MP] = &wiimod_builtin_mp,
2193 [WIIMOD_NO_MP] = &wiimod_no_mp,
2194};
2195
2196const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM] = {
2197 [WIIMOTE_EXT_NONE] = &wiimod_dummy,
2198 [WIIMOTE_EXT_UNKNOWN] = &wiimod_dummy,
2199 [WIIMOTE_EXT_NUNCHUK] = &wiimod_nunchuk,
2200 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic,
2201 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard,
2202 [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro,
2203};
2204