Lines Matching refs:wdata
48 struct wiimote_data *wdata = container_of(queue, struct wiimote_data, in wiimote_queue_worker() local
53 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue_worker()
55 while (wdata->queue.head != wdata->queue.tail) { in wiimote_queue_worker()
56 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue_worker()
57 ret = wiimote_hid_send(wdata->hdev, in wiimote_queue_worker()
58 wdata->queue.outq[wdata->queue.tail].data, in wiimote_queue_worker()
59 wdata->queue.outq[wdata->queue.tail].size); in wiimote_queue_worker()
61 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_queue_worker()
62 wiimote_cmd_abort(wdata); in wiimote_queue_worker()
63 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_queue_worker()
65 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue_worker()
67 wdata->queue.tail = (wdata->queue.tail + 1) % WIIMOTE_BUFSIZE; in wiimote_queue_worker()
70 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue_worker()
73 static void wiimote_queue(struct wiimote_data *wdata, const __u8 *buffer, in wiimote_queue() argument
80 hid_warn(wdata->hdev, "Sending too large output report\n"); in wiimote_queue()
82 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue()
96 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue()
98 memcpy(wdata->queue.outq[wdata->queue.head].data, buffer, count); in wiimote_queue()
99 wdata->queue.outq[wdata->queue.head].size = count; in wiimote_queue()
100 newhead = (wdata->queue.head + 1) % WIIMOTE_BUFSIZE; in wiimote_queue()
102 if (wdata->queue.head == wdata->queue.tail) { in wiimote_queue()
103 wdata->queue.head = newhead; in wiimote_queue()
104 schedule_work(&wdata->queue.worker); in wiimote_queue()
105 } else if (newhead != wdata->queue.tail) { in wiimote_queue()
106 wdata->queue.head = newhead; in wiimote_queue()
108 hid_warn(wdata->hdev, "Output queue is full"); in wiimote_queue()
115 wiimote_cmd_abort(wdata); in wiimote_queue()
117 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue()
127 static inline void wiiproto_keep_rumble(struct wiimote_data *wdata, __u8 *cmd1) in wiiproto_keep_rumble() argument
129 if (wdata->state.flags & WIIPROTO_FLAG_RUMBLE) in wiiproto_keep_rumble()
133 void wiiproto_req_rumble(struct wiimote_data *wdata, __u8 rumble) in wiiproto_req_rumble() argument
138 if (rumble == !!(wdata->state.flags & WIIPROTO_FLAG_RUMBLE)) in wiiproto_req_rumble()
142 wdata->state.flags |= WIIPROTO_FLAG_RUMBLE; in wiiproto_req_rumble()
144 wdata->state.flags &= ~WIIPROTO_FLAG_RUMBLE; in wiiproto_req_rumble()
149 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_rumble()
150 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_rumble()
153 void wiiproto_req_leds(struct wiimote_data *wdata, int leds) in wiiproto_req_leds() argument
158 if ((wdata->state.flags & WIIPROTO_FLAGS_LEDS) == leds) in wiiproto_req_leds()
160 wdata->state.flags = (wdata->state.flags & ~WIIPROTO_FLAGS_LEDS) | leds; in wiiproto_req_leds()
174 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_leds()
175 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_leds()
197 static __u8 select_drm(struct wiimote_data *wdata) in select_drm() argument
199 __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR; in select_drm()
202 ext = (wdata->state.flags & WIIPROTO_FLAG_EXT_USED) || in select_drm()
203 (wdata->state.flags & WIIPROTO_FLAG_MP_USED); in select_drm()
206 if (wdata->state.devtype == WIIMOTE_DEV_BALANCE_BOARD) { in select_drm()
214 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) { in select_drm()
229 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) { in select_drm()
243 void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) in wiiproto_req_drm() argument
247 if (wdata->state.flags & WIIPROTO_FLAG_DRM_LOCKED) in wiiproto_req_drm()
248 drm = wdata->state.drm; in wiiproto_req_drm()
250 drm = select_drm(wdata); in wiiproto_req_drm()
256 wdata->state.drm = drm; in wiiproto_req_drm()
257 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_drm()
258 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_drm()
261 void wiiproto_req_status(struct wiimote_data *wdata) in wiiproto_req_status() argument
268 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_status()
269 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_status()
272 void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) in wiiproto_req_accel() argument
275 if (accel == !!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) in wiiproto_req_accel()
279 wdata->state.flags |= WIIPROTO_FLAG_ACCEL; in wiiproto_req_accel()
281 wdata->state.flags &= ~WIIPROTO_FLAG_ACCEL; in wiiproto_req_accel()
283 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); in wiiproto_req_accel()
286 void wiiproto_req_ir1(struct wiimote_data *wdata, __u8 flags) in wiiproto_req_ir1() argument
293 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_ir1()
294 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_ir1()
297 void wiiproto_req_ir2(struct wiimote_data *wdata, __u8 flags) in wiiproto_req_ir2() argument
304 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_ir2()
305 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_ir2()
308 #define wiiproto_req_wreg(wdata, os, buf, sz) \ argument
309 wiiproto_req_wmem((wdata), false, (os), (buf), (sz))
311 #define wiiproto_req_weeprom(wdata, os, buf, sz) \ argument
312 wiiproto_req_wmem((wdata), true, (os), (buf), (sz))
314 static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom, in wiiproto_req_wmem() argument
320 hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size); in wiiproto_req_wmem()
335 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_wmem()
336 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_wmem()
339 void wiiproto_req_rmem(struct wiimote_data *wdata, bool eeprom, __u32 offset, in wiiproto_req_rmem() argument
345 hid_warn(wdata->hdev, "Invalid length %d rmem request\n", size); in wiiproto_req_rmem()
360 wiiproto_keep_rumble(wdata, &cmd[1]); in wiiproto_req_rmem()
361 wiimote_queue(wdata, cmd, sizeof(cmd)); in wiiproto_req_rmem()
365 int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset, in wiimote_cmd_write() argument
371 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_write()
372 wiimote_cmd_set(wdata, WIIPROTO_REQ_WMEM, 0); in wiimote_cmd_write()
373 wiiproto_req_wreg(wdata, offset, wmem, size); in wiimote_cmd_write()
374 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_write()
376 ret = wiimote_cmd_wait(wdata); in wiimote_cmd_write()
377 if (!ret && wdata->state.cmd_err) in wiimote_cmd_write()
384 ssize_t wiimote_cmd_read(struct wiimote_data *wdata, __u32 offset, __u8 *rmem, in wiimote_cmd_read() argument
390 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_read()
391 wdata->state.cmd_read_size = size; in wiimote_cmd_read()
392 wdata->state.cmd_read_buf = rmem; in wiimote_cmd_read()
393 wiimote_cmd_set(wdata, WIIPROTO_REQ_RMEM, offset & 0xffff); in wiimote_cmd_read()
394 wiiproto_req_rreg(wdata, offset, size); in wiimote_cmd_read()
395 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_read()
397 ret = wiimote_cmd_wait(wdata); in wiimote_cmd_read()
399 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_read()
400 wdata->state.cmd_read_buf = NULL; in wiimote_cmd_read()
401 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_read()
404 if (wdata->state.cmd_read_size == 0) in wiimote_cmd_read()
407 ret = wdata->state.cmd_read_size; in wiimote_cmd_read()
414 static int wiimote_cmd_init_ext(struct wiimote_data *wdata) in wiimote_cmd_init_ext() argument
421 ret = wiimote_cmd_write(wdata, 0xa400f0, &wmem, sizeof(wmem)); in wiimote_cmd_init_ext()
427 ret = wiimote_cmd_write(wdata, 0xa400fb, &wmem, sizeof(wmem)); in wiimote_cmd_init_ext()
435 static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem) in wiimote_cmd_read_ext() argument
440 ret = wiimote_cmd_read(wdata, 0xa400fa, rmem, 6); in wiimote_cmd_read_ext()
444 hid_dbg(wdata->hdev, "extension ID: %6phC\n", rmem); in wiimote_cmd_read_ext()
469 static int wiimote_cmd_init_mp(struct wiimote_data *wdata) in wiimote_cmd_init_mp() argument
476 ret = wiimote_cmd_write(wdata, 0xa600f0, &wmem, sizeof(wmem)); in wiimote_cmd_init_mp()
482 ret = wiimote_cmd_write(wdata, 0xa600fb, &wmem, sizeof(wmem)); in wiimote_cmd_init_mp()
490 static bool wiimote_cmd_map_mp(struct wiimote_data *wdata, __u8 exttype) in wiimote_cmd_map_mp() argument
509 return wiimote_cmd_write(wdata, 0xa600fe, &wmem, sizeof(wmem)); in wiimote_cmd_map_mp()
513 static bool wiimote_cmd_read_mp(struct wiimote_data *wdata, __u8 *rmem) in wiimote_cmd_read_mp() argument
518 ret = wiimote_cmd_read(wdata, 0xa600fa, rmem, 6); in wiimote_cmd_read_mp()
522 hid_dbg(wdata->hdev, "motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp()
527 hid_info(wdata->hdev, "unknown motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp()
533 static __u8 wiimote_cmd_read_mp_mapped(struct wiimote_data *wdata) in wiimote_cmd_read_mp_mapped() argument
539 ret = wiimote_cmd_read(wdata, 0xa400fa, rmem, 6); in wiimote_cmd_read_mp_mapped()
543 hid_dbg(wdata->hdev, "mapped motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp_mapped()
623 static void wiimote_modules_load(struct wiimote_data *wdata, in wiimote_modules_load() argument
641 wdata->input = input_allocate_device(); in wiimote_modules_load()
642 if (!wdata->input) in wiimote_modules_load()
645 input_set_drvdata(wdata->input, wdata); in wiimote_modules_load()
646 wdata->input->dev.parent = &wdata->hdev->dev; in wiimote_modules_load()
647 wdata->input->id.bustype = wdata->hdev->bus; in wiimote_modules_load()
648 wdata->input->id.vendor = wdata->hdev->vendor; in wiimote_modules_load()
649 wdata->input->id.product = wdata->hdev->product; in wiimote_modules_load()
650 wdata->input->id.version = wdata->hdev->version; in wiimote_modules_load()
651 wdata->input->name = WIIMOTE_NAME; in wiimote_modules_load()
659 ret = ops->probe(ops, wdata); in wiimote_modules_load()
664 if (wdata->input) { in wiimote_modules_load()
665 ret = input_register_device(wdata->input); in wiimote_modules_load()
670 spin_lock_irq(&wdata->state.lock); in wiimote_modules_load()
671 wdata->state.devtype = devtype; in wiimote_modules_load()
672 spin_unlock_irq(&wdata->state.lock); in wiimote_modules_load()
679 ops->remove(ops, wdata); in wiimote_modules_load()
682 if (wdata->input) { in wiimote_modules_load()
683 input_free_device(wdata->input); in wiimote_modules_load()
684 wdata->input = NULL; in wiimote_modules_load()
688 static void wiimote_modules_unload(struct wiimote_data *wdata) in wiimote_modules_unload() argument
694 mods = wiimote_devtype_mods[wdata->state.devtype]; in wiimote_modules_unload()
696 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_modules_unload()
697 wdata->state.devtype = WIIMOTE_DEV_UNKNOWN; in wiimote_modules_unload()
698 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_modules_unload()
704 if (wdata->input) { in wiimote_modules_unload()
705 input_get_device(wdata->input); in wiimote_modules_unload()
706 input_unregister_device(wdata->input); in wiimote_modules_unload()
712 ops->remove(ops, wdata); in wiimote_modules_unload()
715 if (wdata->input) { in wiimote_modules_unload()
716 input_put_device(wdata->input); in wiimote_modules_unload()
717 wdata->input = NULL; in wiimote_modules_unload()
723 static void wiimote_ext_load(struct wiimote_data *wdata, unsigned int ext) in wiimote_ext_load() argument
732 ret = ops->probe(ops, wdata); in wiimote_ext_load()
737 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_ext_load()
738 wdata->state.exttype = ext; in wiimote_ext_load()
739 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_ext_load()
742 static void wiimote_ext_unload(struct wiimote_data *wdata) in wiimote_ext_unload() argument
747 ops = wiimod_ext_table[wdata->state.exttype]; in wiimote_ext_unload()
749 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_ext_unload()
750 wdata->state.exttype = WIIMOTE_EXT_UNKNOWN; in wiimote_ext_unload()
751 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED; in wiimote_ext_unload()
752 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_ext_unload()
755 ops->remove(ops, wdata); in wiimote_ext_unload()
758 static void wiimote_mp_load(struct wiimote_data *wdata) in wiimote_mp_load() argument
767 ret = ops->probe(ops, wdata); in wiimote_mp_load()
772 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_mp_load()
773 wdata->state.mp = mode; in wiimote_mp_load()
774 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_mp_load()
777 static void wiimote_mp_unload(struct wiimote_data *wdata) in wiimote_mp_unload() argument
782 if (wdata->state.mp < 2) in wiimote_mp_unload()
787 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_mp_unload()
788 wdata->state.mp = 0; in wiimote_mp_unload()
789 wdata->state.flags &= ~WIIPROTO_FLAG_MP_USED; in wiimote_mp_unload()
790 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_mp_unload()
793 ops->remove(ops, wdata); in wiimote_mp_unload()
812 static void wiimote_init_set_type(struct wiimote_data *wdata, in wiimote_init_set_type() argument
819 vendor = wdata->hdev->vendor; in wiimote_init_set_type()
820 product = wdata->hdev->product; in wiimote_init_set_type()
821 name = wdata->hdev->name; in wiimote_init_set_type()
857 hid_info(wdata->hdev, "cannot detect device; NAME: %s VID: %04x PID: %04x EXT: %04x\n", in wiimote_init_set_type()
860 hid_info(wdata->hdev, "detected device: %s\n", in wiimote_init_set_type()
863 wiimote_modules_load(wdata, devtype); in wiimote_init_set_type()
866 static void wiimote_init_detect(struct wiimote_data *wdata) in wiimote_init_detect() argument
872 wiimote_cmd_acquire_noint(wdata); in wiimote_init_detect()
874 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
875 wdata->state.devtype = WIIMOTE_DEV_UNKNOWN; in wiimote_init_detect()
876 wiimote_cmd_set(wdata, WIIPROTO_REQ_SREQ, 0); in wiimote_init_detect()
877 wiiproto_req_status(wdata); in wiimote_init_detect()
878 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
880 ret = wiimote_cmd_wait_noint(wdata); in wiimote_init_detect()
884 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
885 ext = wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_detect()
886 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
891 wiimote_cmd_init_ext(wdata); in wiimote_init_detect()
892 exttype = wiimote_cmd_read_ext(wdata, extdata); in wiimote_init_detect()
895 wiimote_cmd_release(wdata); in wiimote_init_detect()
896 wiimote_init_set_type(wdata, exttype); in wiimote_init_detect()
899 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
900 if (!(wdata->state.flags & WIIPROTO_FLAG_BUILTIN_MP) && in wiimote_init_detect()
901 !(wdata->state.flags & WIIPROTO_FLAG_NO_MP)) in wiimote_init_detect()
902 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_detect()
903 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
912 static void wiimote_init_poll_mp(struct wiimote_data *wdata) in wiimote_init_poll_mp() argument
917 wiimote_cmd_acquire_noint(wdata); in wiimote_init_poll_mp()
918 wiimote_cmd_init_mp(wdata); in wiimote_init_poll_mp()
919 mp = wiimote_cmd_read_mp(wdata, mpdata); in wiimote_init_poll_mp()
920 wiimote_cmd_release(wdata); in wiimote_init_poll_mp()
924 if (!wdata->state.mp) { in wiimote_init_poll_mp()
925 hid_info(wdata->hdev, "detected extension: Nintendo Wii Motion Plus\n"); in wiimote_init_poll_mp()
926 wiimote_mp_load(wdata); in wiimote_init_poll_mp()
928 } else if (wdata->state.mp) { in wiimote_init_poll_mp()
929 wiimote_mp_unload(wdata); in wiimote_init_poll_mp()
932 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_poll_mp()
945 static bool wiimote_init_check(struct wiimote_data *wdata) in wiimote_init_check() argument
951 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
952 flags = wdata->state.flags; in wiimote_init_check()
953 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
955 wiimote_cmd_acquire_noint(wdata); in wiimote_init_check()
964 if (wdata->state.exttype == WIIMOTE_EXT_NONE && in wiimote_init_check()
965 wdata->state.mp > 0 && (flags & WIIPROTO_FLAG_MP_USED)) { in wiimote_init_check()
966 type = wiimote_cmd_read_mp_mapped(wdata); in wiimote_init_check()
969 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
970 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
971 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED); in wiimote_init_check()
972 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
973 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
976 hid_dbg(wdata->hdev, "state left: !EXT && MP\n"); in wiimote_init_check()
990 wdata->state.exttype != WIIMOTE_EXT_NONE) { in wiimote_init_check()
991 type = wiimote_cmd_read_ext(wdata, data); in wiimote_init_check()
992 ret = type == wdata->state.exttype; in wiimote_init_check()
994 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
995 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
996 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
997 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1000 hid_dbg(wdata->hdev, "state left: EXT && !MP\n"); in wiimote_init_check()
1016 wdata->state.exttype == WIIMOTE_EXT_NONE) { in wiimote_init_check()
1017 type = wiimote_cmd_read_ext(wdata, data); in wiimote_init_check()
1018 ret = type == wdata->state.exttype; in wiimote_init_check()
1020 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
1021 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
1022 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
1023 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED); in wiimote_init_check()
1024 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1027 hid_dbg(wdata->hdev, "state left: !EXT && !MP\n"); in wiimote_init_check()
1043 if (wdata->state.exttype != WIIMOTE_EXT_NONE && in wiimote_init_check()
1044 wdata->state.mp > 0 && (flags & WIIPROTO_FLAG_MP_USED)) { in wiimote_init_check()
1045 type = wiimote_cmd_read_mp_mapped(wdata); in wiimote_init_check()
1050 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
1051 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED); in wiimote_init_check()
1052 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
1053 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
1054 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1057 hid_dbg(wdata->hdev, "state left: EXT && MP\n"); in wiimote_init_check()
1069 wiimote_cmd_release(wdata); in wiimote_init_check()
1074 wiimote_init_poll_mp(wdata); in wiimote_init_check()
1098 static void wiimote_init_hotplug(struct wiimote_data *wdata) in wiimote_init_hotplug() argument
1104 hid_dbg(wdata->hdev, "detect extensions..\n"); in wiimote_init_hotplug()
1106 wiimote_cmd_acquire_noint(wdata); in wiimote_init_hotplug()
1108 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1111 flags = wdata->state.flags; in wiimote_init_hotplug()
1114 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1115 wdata->state.flags &= ~WIIPROTO_FLAG_MP_ACTIVE; in wiimote_init_hotplug()
1117 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1120 wiimote_cmd_init_ext(wdata); in wiimote_init_hotplug()
1124 wiimote_cmd_init_mp(wdata); in wiimote_init_hotplug()
1125 mp = wiimote_cmd_read_mp(wdata, mpdata); in wiimote_init_hotplug()
1127 exttype = wiimote_cmd_read_ext(wdata, extdata); in wiimote_init_hotplug()
1129 wiimote_cmd_release(wdata); in wiimote_init_hotplug()
1132 if (exttype != wdata->state.exttype) { in wiimote_init_hotplug()
1134 wiimote_ext_unload(wdata); in wiimote_init_hotplug()
1137 hid_info(wdata->hdev, "cannot detect extension; %6phC\n", in wiimote_init_hotplug()
1140 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1141 wdata->state.exttype = WIIMOTE_EXT_NONE; in wiimote_init_hotplug()
1142 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1144 hid_info(wdata->hdev, "detected extension: %s\n", in wiimote_init_hotplug()
1147 wiimote_ext_load(wdata, exttype); in wiimote_init_hotplug()
1153 if (!wdata->state.mp) { in wiimote_init_hotplug()
1154 hid_info(wdata->hdev, "detected extension: Nintendo Wii Motion Plus\n"); in wiimote_init_hotplug()
1155 wiimote_mp_load(wdata); in wiimote_init_hotplug()
1157 } else if (wdata->state.mp) { in wiimote_init_hotplug()
1158 wiimote_mp_unload(wdata); in wiimote_init_hotplug()
1167 wiimote_cmd_acquire_noint(wdata); in wiimote_init_hotplug()
1168 wiimote_cmd_map_mp(wdata, exttype); in wiimote_init_hotplug()
1169 wiimote_cmd_release(wdata); in wiimote_init_hotplug()
1172 del_timer_sync(&wdata->timer); in wiimote_init_hotplug()
1177 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_hotplug()
1180 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1184 wdata->state.flags |= WIIPROTO_FLAG_MP_ACTIVE; in wiimote_init_hotplug()
1185 if (wdata->state.exttype == WIIMOTE_EXT_NONE) { in wiimote_init_hotplug()
1186 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_hotplug()
1187 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in wiimote_init_hotplug()
1189 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_hotplug()
1190 wdata->state.flags |= WIIPROTO_FLAG_MP_PLUGGED; in wiimote_init_hotplug()
1191 wdata->state.flags |= WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1193 } else if (wdata->state.exttype != WIIMOTE_EXT_NONE) { in wiimote_init_hotplug()
1194 wdata->state.flags |= WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1198 wiiproto_req_status(wdata); in wiimote_init_hotplug()
1200 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1202 hid_dbg(wdata->hdev, "detected extensions: MP: %d EXT: %d\n", in wiimote_init_hotplug()
1203 wdata->state.mp, wdata->state.exttype); in wiimote_init_hotplug()
1208 struct wiimote_data *wdata = container_of(work, struct wiimote_data, in wiimote_init_worker() local
1212 if (wdata->state.devtype == WIIMOTE_DEV_PENDING) { in wiimote_init_worker()
1213 wiimote_init_detect(wdata); in wiimote_init_worker()
1217 if (changed || !wiimote_init_check(wdata)) in wiimote_init_worker()
1218 wiimote_init_hotplug(wdata); in wiimote_init_worker()
1221 kobject_uevent(&wdata->hdev->dev.kobj, KOBJ_CHANGE); in wiimote_init_worker()
1224 void __wiimote_schedule(struct wiimote_data *wdata) in __wiimote_schedule() argument
1226 if (!(wdata->state.flags & WIIPROTO_FLAG_EXITING)) in __wiimote_schedule()
1227 schedule_work(&wdata->init_worker); in __wiimote_schedule()
1230 static void wiimote_schedule(struct wiimote_data *wdata) in wiimote_schedule() argument
1234 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_schedule()
1235 __wiimote_schedule(wdata); in wiimote_schedule()
1236 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_schedule()
1241 struct wiimote_data *wdata = from_timer(wdata, t, timer); in wiimote_init_timeout() local
1243 wiimote_schedule(wdata); in wiimote_init_timeout()
1248 static void handler_keys(struct wiimote_data *wdata, const __u8 *payload) in handler_keys() argument
1253 ops = wiimod_ext_table[wdata->state.exttype]; in handler_keys()
1255 ops->in_keys(wdata, payload); in handler_keys()
1259 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_keys()
1263 ops->in_keys(wdata, payload); in handler_keys()
1269 static void handler_accel(struct wiimote_data *wdata, const __u8 *payload) in handler_accel() argument
1274 ops = wiimod_ext_table[wdata->state.exttype]; in handler_accel()
1276 ops->in_accel(wdata, payload); in handler_accel()
1280 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_accel()
1284 ops->in_accel(wdata, payload); in handler_accel()
1302 static void handler_ext(struct wiimote_data *wdata, const __u8 *payload, in handler_ext() argument
1321 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { in handler_ext()
1327 if (!(wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED)) { in handler_ext()
1328 hid_dbg(wdata->hdev, "MP hotplug: 1\n"); in handler_ext()
1329 wdata->state.flags |= WIIPROTO_FLAG_MP_PLUGGED; in handler_ext()
1330 __wiimote_schedule(wdata); in handler_ext()
1333 if (wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED) { in handler_ext()
1334 hid_dbg(wdata->hdev, "MP hotplug: 0\n"); in handler_ext()
1335 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in handler_ext()
1336 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in handler_ext()
1337 __wiimote_schedule(wdata); in handler_ext()
1348 if (!(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE) && !is_mp) in handler_ext()
1352 ops = wiimod_ext_table[wdata->state.exttype]; in handler_ext()
1354 ops->in_mp(wdata, payload); in handler_ext()
1357 ops->in_ext(wdata, payload); in handler_ext()
1364 ops->in_mp(wdata, payload); in handler_ext()
1367 ops->in_ext(wdata, payload); in handler_ext()
1372 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_ext()
1376 ops->in_mp(wdata, payload); in handler_ext()
1379 ops->in_ext(wdata, payload); in handler_ext()
1385 #define ir_to_input0(wdata, ir, packed) handler_ir((wdata), (ir), (packed), 0) argument
1386 #define ir_to_input1(wdata, ir, packed) handler_ir((wdata), (ir), (packed), 1) argument
1387 #define ir_to_input2(wdata, ir, packed) handler_ir((wdata), (ir), (packed), 2) argument
1388 #define ir_to_input3(wdata, ir, packed) handler_ir((wdata), (ir), (packed), 3) argument
1390 static void handler_ir(struct wiimote_data *wdata, const __u8 *payload, in handler_ir() argument
1396 ops = wiimod_ext_table[wdata->state.exttype]; in handler_ir()
1398 ops->in_ir(wdata, payload, packed, id); in handler_ir()
1402 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_ir()
1406 ops->in_ir(wdata, payload, packed, id); in handler_ir()
1413 static void handler_status_K(struct wiimote_data *wdata, in handler_status_K() argument
1416 handler_keys(wdata, payload); in handler_status_K()
1419 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); in handler_status_K()
1423 static void handler_status(struct wiimote_data *wdata, const __u8 *payload) in handler_status() argument
1425 handler_status_K(wdata, payload); in handler_status()
1429 if (!(wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED)) { in handler_status()
1430 hid_dbg(wdata->hdev, "EXT hotplug: 1\n"); in handler_status()
1431 wdata->state.flags |= WIIPROTO_FLAG_EXT_PLUGGED; in handler_status()
1432 __wiimote_schedule(wdata); in handler_status()
1435 if (wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED) { in handler_status()
1436 hid_dbg(wdata->hdev, "EXT hotplug: 0\n"); in handler_status()
1437 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in handler_status()
1438 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in handler_status()
1439 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in handler_status()
1440 wdata->state.flags &= ~WIIPROTO_FLAG_MP_ACTIVE; in handler_status()
1441 __wiimote_schedule(wdata); in handler_status()
1445 wdata->state.cmd_battery = payload[5]; in handler_status()
1446 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) in handler_status()
1447 wiimote_cmd_complete(wdata); in handler_status()
1451 static void handler_generic_K(struct wiimote_data *wdata, const __u8 *payload) in handler_generic_K() argument
1453 handler_keys(wdata, payload); in handler_generic_K()
1456 static void handler_data(struct wiimote_data *wdata, const __u8 *payload) in handler_data() argument
1462 handler_keys(wdata, payload); in handler_data()
1464 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_RMEM, offset)) { in handler_data()
1467 else if (size > wdata->state.cmd_read_size) in handler_data()
1468 size = wdata->state.cmd_read_size; in handler_data()
1470 wdata->state.cmd_read_size = size; in handler_data()
1471 if (wdata->state.cmd_read_buf) in handler_data()
1472 memcpy(wdata->state.cmd_read_buf, &payload[5], size); in handler_data()
1473 wiimote_cmd_complete(wdata); in handler_data()
1477 static void handler_return(struct wiimote_data *wdata, const __u8 *payload) in handler_return() argument
1482 handler_keys(wdata, payload); in handler_return()
1484 if (wiimote_cmd_pending(wdata, cmd, 0)) { in handler_return()
1485 wdata->state.cmd_err = err; in handler_return()
1486 wiimote_cmd_complete(wdata); in handler_return()
1488 hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err, in handler_return()
1493 static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KA() argument
1495 handler_keys(wdata, payload); in handler_drm_KA()
1496 handler_accel(wdata, payload); in handler_drm_KA()
1499 static void handler_drm_KE(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KE() argument
1501 handler_keys(wdata, payload); in handler_drm_KE()
1502 handler_ext(wdata, &payload[2], 8); in handler_drm_KE()
1505 static void handler_drm_KAI(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KAI() argument
1507 handler_keys(wdata, payload); in handler_drm_KAI()
1508 handler_accel(wdata, payload); in handler_drm_KAI()
1509 ir_to_input0(wdata, &payload[5], false); in handler_drm_KAI()
1510 ir_to_input1(wdata, &payload[8], false); in handler_drm_KAI()
1511 ir_to_input2(wdata, &payload[11], false); in handler_drm_KAI()
1512 ir_to_input3(wdata, &payload[14], false); in handler_drm_KAI()
1515 static void handler_drm_KEE(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KEE() argument
1517 handler_keys(wdata, payload); in handler_drm_KEE()
1518 handler_ext(wdata, &payload[2], 19); in handler_drm_KEE()
1521 static void handler_drm_KIE(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KIE() argument
1523 handler_keys(wdata, payload); in handler_drm_KIE()
1524 ir_to_input0(wdata, &payload[2], false); in handler_drm_KIE()
1525 ir_to_input1(wdata, &payload[4], true); in handler_drm_KIE()
1526 ir_to_input2(wdata, &payload[7], false); in handler_drm_KIE()
1527 ir_to_input3(wdata, &payload[9], true); in handler_drm_KIE()
1528 handler_ext(wdata, &payload[12], 9); in handler_drm_KIE()
1531 static void handler_drm_KAE(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KAE() argument
1533 handler_keys(wdata, payload); in handler_drm_KAE()
1534 handler_accel(wdata, payload); in handler_drm_KAE()
1535 handler_ext(wdata, &payload[5], 16); in handler_drm_KAE()
1538 static void handler_drm_KAIE(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_KAIE() argument
1540 handler_keys(wdata, payload); in handler_drm_KAIE()
1541 handler_accel(wdata, payload); in handler_drm_KAIE()
1542 ir_to_input0(wdata, &payload[5], false); in handler_drm_KAIE()
1543 ir_to_input1(wdata, &payload[7], true); in handler_drm_KAIE()
1544 ir_to_input2(wdata, &payload[10], false); in handler_drm_KAIE()
1545 ir_to_input3(wdata, &payload[12], true); in handler_drm_KAIE()
1546 handler_ext(wdata, &payload[15], 6); in handler_drm_KAIE()
1549 static void handler_drm_E(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_E() argument
1551 handler_ext(wdata, payload, 21); in handler_drm_E()
1554 static void handler_drm_SKAI1(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_SKAI1() argument
1556 handler_keys(wdata, payload); in handler_drm_SKAI1()
1558 wdata->state.accel_split[0] = payload[2]; in handler_drm_SKAI1()
1559 wdata->state.accel_split[1] = (payload[0] >> 1) & (0x10 | 0x20); in handler_drm_SKAI1()
1560 wdata->state.accel_split[1] |= (payload[1] << 1) & (0x40 | 0x80); in handler_drm_SKAI1()
1562 ir_to_input0(wdata, &payload[3], false); in handler_drm_SKAI1()
1563 ir_to_input1(wdata, &payload[12], false); in handler_drm_SKAI1()
1566 static void handler_drm_SKAI2(struct wiimote_data *wdata, const __u8 *payload) in handler_drm_SKAI2() argument
1570 handler_keys(wdata, payload); in handler_drm_SKAI2()
1572 wdata->state.accel_split[1] |= (payload[0] >> 5) & (0x01 | 0x02); in handler_drm_SKAI2()
1573 wdata->state.accel_split[1] |= (payload[1] >> 3) & (0x04 | 0x08); in handler_drm_SKAI2()
1577 buf[2] = wdata->state.accel_split[0]; in handler_drm_SKAI2()
1579 buf[4] = wdata->state.accel_split[1]; in handler_drm_SKAI2()
1580 handler_accel(wdata, buf); in handler_drm_SKAI2()
1582 ir_to_input2(wdata, &payload[3], false); in handler_drm_SKAI2()
1583 ir_to_input3(wdata, &payload[12], false); in handler_drm_SKAI2()
1589 void (*func)(struct wiimote_data *wdata, const __u8 *payload);
1623 struct wiimote_data *wdata = hid_get_drvdata(hdev); in wiimote_hid_event() local
1631 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_hid_event()
1636 h->func(wdata, &raw_data[1]); in wiimote_hid_event()
1645 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_hid_event()
1654 struct wiimote_data *wdata = dev_to_wii(dev); in wiimote_ext_show() local
1658 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_ext_show()
1659 type = wdata->state.exttype; in wiimote_ext_show()
1660 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_ext_show()
1688 struct wiimote_data *wdata = dev_to_wii(dev); in wiimote_ext_store() local
1691 wiimote_schedule(wdata); in wiimote_ext_store()
1706 struct wiimote_data *wdata = dev_to_wii(dev); in wiimote_dev_show() local
1710 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_dev_show()
1711 type = wdata->state.devtype; in wiimote_dev_show()
1712 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_dev_show()
1738 struct wiimote_data *wdata; in wiimote_create() local
1740 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); in wiimote_create()
1741 if (!wdata) in wiimote_create()
1744 wdata->hdev = hdev; in wiimote_create()
1745 hid_set_drvdata(hdev, wdata); in wiimote_create()
1747 spin_lock_init(&wdata->queue.lock); in wiimote_create()
1748 INIT_WORK(&wdata->queue.worker, wiimote_queue_worker); in wiimote_create()
1750 spin_lock_init(&wdata->state.lock); in wiimote_create()
1751 init_completion(&wdata->state.ready); in wiimote_create()
1752 mutex_init(&wdata->state.sync); in wiimote_create()
1753 wdata->state.drm = WIIPROTO_REQ_DRM_K; in wiimote_create()
1754 wdata->state.cmd_battery = 0xff; in wiimote_create()
1756 INIT_WORK(&wdata->init_worker, wiimote_init_worker); in wiimote_create()
1757 timer_setup(&wdata->timer, wiimote_init_timeout, 0); in wiimote_create()
1759 return wdata; in wiimote_create()
1762 static void wiimote_destroy(struct wiimote_data *wdata) in wiimote_destroy() argument
1766 wiidebug_deinit(wdata); in wiimote_destroy()
1769 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_destroy()
1770 wdata->state.flags |= WIIPROTO_FLAG_EXITING; in wiimote_destroy()
1771 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_destroy()
1773 cancel_work_sync(&wdata->init_worker); in wiimote_destroy()
1774 del_timer_sync(&wdata->timer); in wiimote_destroy()
1776 device_remove_file(&wdata->hdev->dev, &dev_attr_devtype); in wiimote_destroy()
1777 device_remove_file(&wdata->hdev->dev, &dev_attr_extension); in wiimote_destroy()
1779 wiimote_mp_unload(wdata); in wiimote_destroy()
1780 wiimote_ext_unload(wdata); in wiimote_destroy()
1781 wiimote_modules_unload(wdata); in wiimote_destroy()
1782 cancel_work_sync(&wdata->queue.worker); in wiimote_destroy()
1783 hid_hw_close(wdata->hdev); in wiimote_destroy()
1784 hid_hw_stop(wdata->hdev); in wiimote_destroy()
1786 kfree(wdata); in wiimote_destroy()
1792 struct wiimote_data *wdata; in wiimote_hid_probe() local
1797 wdata = wiimote_create(hdev); in wiimote_hid_probe()
1798 if (!wdata) { in wiimote_hid_probe()
1833 ret = wiidebug_init(wdata); in wiimote_hid_probe()
1840 wiimote_schedule(wdata); in wiimote_hid_probe()
1845 wiimote_destroy(wdata); in wiimote_hid_probe()
1849 device_remove_file(&wdata->hdev->dev, &dev_attr_extension); in wiimote_hid_probe()
1855 input_free_device(wdata->ir); in wiimote_hid_probe()
1856 input_free_device(wdata->accel); in wiimote_hid_probe()
1857 kfree(wdata); in wiimote_hid_probe()
1863 struct wiimote_data *wdata = hid_get_drvdata(hdev); in wiimote_hid_remove() local
1866 wiimote_destroy(wdata); in wiimote_hid_remove()