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