Lines Matching +full:ext +full:- +full:reset +full:- +full:output

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com>
17 #include "hid-ids.h"
18 #include "hid-wiimote.h"
20 /* output queue handling */
28 if (!hdev->ll_driver->output_report) in wiimote_hid_send()
29 return -ENODEV; in wiimote_hid_send()
33 return -ENOMEM; in wiimote_hid_send()
50 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue_worker()
52 while (wdata->queue.head != wdata->queue.tail) { in wiimote_queue_worker()
53 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue_worker()
54 ret = wiimote_hid_send(wdata->hdev, in wiimote_queue_worker()
55 wdata->queue.outq[wdata->queue.tail].data, in wiimote_queue_worker()
56 wdata->queue.outq[wdata->queue.tail].size); in wiimote_queue_worker()
58 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_queue_worker()
60 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_queue_worker()
62 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue_worker()
64 wdata->queue.tail = (wdata->queue.tail + 1) % WIIMOTE_BUFSIZE; in wiimote_queue_worker()
67 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue_worker()
77 hid_warn(wdata->hdev, "Sending too large output report\n"); in wiimote_queue()
79 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue()
84 * Copy new request into our output queue and check whether the in wiimote_queue()
93 spin_lock_irqsave(&wdata->queue.lock, flags); in wiimote_queue()
95 memcpy(wdata->queue.outq[wdata->queue.head].data, buffer, count); in wiimote_queue()
96 wdata->queue.outq[wdata->queue.head].size = count; in wiimote_queue()
97 newhead = (wdata->queue.head + 1) % WIIMOTE_BUFSIZE; in wiimote_queue()
99 if (wdata->queue.head == wdata->queue.tail) { in wiimote_queue()
100 wdata->queue.head = newhead; in wiimote_queue()
101 schedule_work(&wdata->queue.worker); in wiimote_queue()
102 } else if (newhead != wdata->queue.tail) { in wiimote_queue()
103 wdata->queue.head = newhead; in wiimote_queue()
105 hid_warn(wdata->hdev, "Output queue is full"); in wiimote_queue()
114 spin_unlock_irqrestore(&wdata->queue.lock, flags); in wiimote_queue()
118 * This sets the rumble bit on the given output report if rumble is
120 * \cmd1 must point to the second byte in the output report => &cmd[1]
121 * This must be called on nearly every output report before passing it
122 * into the output queue!
126 if (wdata->state.flags & WIIPROTO_FLAG_RUMBLE) in wiiproto_keep_rumble()
135 if (rumble == !!(wdata->state.flags & WIIPROTO_FLAG_RUMBLE)) in wiiproto_req_rumble()
139 wdata->state.flags |= WIIPROTO_FLAG_RUMBLE; in wiiproto_req_rumble()
141 wdata->state.flags &= ~WIIPROTO_FLAG_RUMBLE; in wiiproto_req_rumble()
155 if ((wdata->state.flags & WIIPROTO_FLAGS_LEDS) == leds) in wiiproto_req_leds()
157 wdata->state.flags = (wdata->state.flags & ~WIIPROTO_FLAGS_LEDS) | leds; in wiiproto_req_leds()
182 * - IR cam in extended or full mode disables any data transmission
185 * - IR cam with accelerometer and extension *_EXT8 is not supported.
189 * - *_EXT16 is only supported in combination with buttons and
196 __u8 ir = wdata->state.flags & WIIPROTO_FLAGS_IR; in select_drm()
197 bool ext; in select_drm() local
199 ext = (wdata->state.flags & WIIPROTO_FLAG_EXT_USED) || in select_drm()
200 (wdata->state.flags & WIIPROTO_FLAG_MP_USED); in select_drm()
202 /* some 3rd-party balance-boards are hard-coded to KEE, *sigh* */ in select_drm()
203 if (wdata->state.devtype == WIIMOTE_DEV_BALANCE_BOARD) { in select_drm()
204 if (ext) in select_drm()
211 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) { in select_drm()
226 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) { in select_drm()
227 if (ext) in select_drm()
232 if (ext) in select_drm()
244 if (wdata->state.flags & WIIPROTO_FLAG_DRM_LOCKED) in wiiproto_req_drm()
245 drm = wdata->state.drm; in wiiproto_req_drm()
253 wdata->state.drm = drm; in wiiproto_req_drm()
272 if (accel == !!(wdata->state.flags & WIIPROTO_FLAG_ACCEL)) in wiiproto_req_accel()
276 wdata->state.flags |= WIIPROTO_FLAG_ACCEL; in wiiproto_req_accel()
278 wdata->state.flags &= ~WIIPROTO_FLAG_ACCEL; in wiiproto_req_accel()
317 hid_warn(wdata->hdev, "Invalid length %d wmem request\n", size); in wiiproto_req_wmem()
342 hid_warn(wdata->hdev, "Invalid length %d rmem request\n", size); in wiiproto_req_rmem()
361 /* requries the cmd-mutex to be held */
368 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_write()
371 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_write()
374 if (!ret && wdata->state.cmd_err) in wiimote_cmd_write()
375 ret = -EIO; in wiimote_cmd_write()
380 /* requries the cmd-mutex to be held */
387 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_read()
388 wdata->state.cmd_read_size = size; in wiimote_cmd_read()
389 wdata->state.cmd_read_buf = rmem; in wiimote_cmd_read()
392 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_read()
396 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_cmd_read()
397 wdata->state.cmd_read_buf = NULL; in wiimote_cmd_read()
398 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_cmd_read()
401 if (wdata->state.cmd_read_size == 0) in wiimote_cmd_read()
402 ret = -EIO; in wiimote_cmd_read()
404 ret = wdata->state.cmd_read_size; in wiimote_cmd_read()
410 /* requires the cmd-mutex to be held */
431 /* requires the cmd-mutex to be held */
441 hid_dbg(wdata->hdev, "extension ID: %6phC\n", rmem); in wiimote_cmd_read_ext()
468 /* requires the cmd-mutex to be held */
489 /* requires the cmd-mutex to be held */
494 /* map MP with correct pass-through mode */ in wiimote_cmd_map_mp()
513 /* requires the cmd-mutex to be held */
523 hid_dbg(wdata->hdev, "motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp()
528 hid_info(wdata->hdev, "unknown motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp()
533 /* requires the cmd-mutex to be held */
544 hid_dbg(wdata->hdev, "mapped motion plus ID: %6phC\n", rmem); in wiimote_cmd_read_mp_mapped()
635 if (wiimod_table[*iter]->flags & WIIMOD_FLAG_INPUT) { in wiimote_modules_load()
642 wdata->input = input_allocate_device(); in wiimote_modules_load()
643 if (!wdata->input) in wiimote_modules_load()
646 input_set_drvdata(wdata->input, wdata); in wiimote_modules_load()
647 wdata->input->dev.parent = &wdata->hdev->dev; in wiimote_modules_load()
648 wdata->input->id.bustype = wdata->hdev->bus; in wiimote_modules_load()
649 wdata->input->id.vendor = wdata->hdev->vendor; in wiimote_modules_load()
650 wdata->input->id.product = wdata->hdev->product; in wiimote_modules_load()
651 wdata->input->id.version = wdata->hdev->version; in wiimote_modules_load()
652 wdata->input->name = WIIMOTE_NAME; in wiimote_modules_load()
657 if (!ops->probe) in wiimote_modules_load()
660 ret = ops->probe(ops, wdata); in wiimote_modules_load()
665 if (wdata->input) { in wiimote_modules_load()
666 ret = input_register_device(wdata->input); in wiimote_modules_load()
671 spin_lock_irq(&wdata->state.lock); in wiimote_modules_load()
672 wdata->state.devtype = devtype; in wiimote_modules_load()
673 spin_unlock_irq(&wdata->state.lock); in wiimote_modules_load()
677 for ( ; iter-- != mods; ) { in wiimote_modules_load()
679 if (ops->remove) in wiimote_modules_load()
680 ops->remove(ops, wdata); in wiimote_modules_load()
683 if (wdata->input) { in wiimote_modules_load()
684 input_free_device(wdata->input); in wiimote_modules_load()
685 wdata->input = NULL; in wiimote_modules_load()
695 mods = wiimote_devtype_mods[wdata->state.devtype]; in wiimote_modules_unload()
697 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_modules_unload()
698 wdata->state.devtype = WIIMOTE_DEV_UNKNOWN; in wiimote_modules_unload()
699 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_modules_unload()
705 if (wdata->input) { in wiimote_modules_unload()
706 input_get_device(wdata->input); in wiimote_modules_unload()
707 input_unregister_device(wdata->input); in wiimote_modules_unload()
710 for ( ; iter-- != mods; ) { in wiimote_modules_unload()
712 if (ops->remove) in wiimote_modules_unload()
713 ops->remove(ops, wdata); in wiimote_modules_unload()
716 if (wdata->input) { in wiimote_modules_unload()
717 input_put_device(wdata->input); in wiimote_modules_unload()
718 wdata->input = NULL; in wiimote_modules_unload()
724 static void wiimote_ext_load(struct wiimote_data *wdata, unsigned int ext) in wiimote_ext_load() argument
730 ops = wiimod_ext_table[ext]; in wiimote_ext_load()
732 if (ops->probe) { in wiimote_ext_load()
733 ret = ops->probe(ops, wdata); in wiimote_ext_load()
735 ext = WIIMOTE_EXT_UNKNOWN; in wiimote_ext_load()
738 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_ext_load()
739 wdata->state.exttype = ext; in wiimote_ext_load()
740 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_ext_load()
748 ops = wiimod_ext_table[wdata->state.exttype]; in wiimote_ext_unload()
750 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_ext_unload()
751 wdata->state.exttype = WIIMOTE_EXT_UNKNOWN; in wiimote_ext_unload()
752 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED; in wiimote_ext_unload()
753 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_ext_unload()
755 if (ops->remove) in wiimote_ext_unload()
756 ops->remove(ops, wdata); in wiimote_ext_unload()
767 if (ops->probe) { in wiimote_mp_load()
768 ret = ops->probe(ops, wdata); in wiimote_mp_load()
773 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_mp_load()
774 wdata->state.mp = mode; in wiimote_mp_load()
775 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_mp_load()
783 if (wdata->state.mp < 2) in wiimote_mp_unload()
788 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_mp_unload()
789 wdata->state.mp = 0; in wiimote_mp_unload()
790 wdata->state.flags &= ~WIIPROTO_FLAG_MP_USED; in wiimote_mp_unload()
791 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_mp_unload()
793 if (ops->remove) in wiimote_mp_unload()
794 ops->remove(ops, wdata); in wiimote_mp_unload()
797 /* device (re-)initialization and detection */
820 vendor = wdata->hdev->vendor; in wiimote_init_set_type()
821 product = wdata->hdev->product; in wiimote_init_set_type()
822 name = wdata->hdev->name; in wiimote_init_set_type()
832 if (!strcmp(name, "Nintendo RVL-CNT-01")) { in wiimote_init_set_type()
835 } else if (!strcmp(name, "Nintendo RVL-CNT-01-TR")) { in wiimote_init_set_type()
838 } else if (!strcmp(name, "Nintendo RVL-WBC-01")) { in wiimote_init_set_type()
841 } else if (!strcmp(name, "Nintendo RVL-CNT-01-UC")) { in wiimote_init_set_type()
858 hid_info(wdata->hdev, "cannot detect device; NAME: %s VID: %04x PID: %04x EXT: %04x\n", in wiimote_init_set_type()
861 hid_info(wdata->hdev, "detected device: %s\n", in wiimote_init_set_type()
870 bool ext; in wiimote_init_detect() local
875 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
876 wdata->state.devtype = WIIMOTE_DEV_UNKNOWN; in wiimote_init_detect()
879 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
885 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
886 ext = wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_detect()
887 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
889 if (!ext) in wiimote_init_detect()
900 spin_lock_irq(&wdata->state.lock); in wiimote_init_detect()
901 if (!(wdata->state.flags & WIIPROTO_FLAG_BUILTIN_MP) && in wiimote_init_detect()
902 !(wdata->state.flags & WIIPROTO_FLAG_NO_MP)) in wiimote_init_detect()
903 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_detect()
904 spin_unlock_irq(&wdata->state.lock); in wiimote_init_detect()
925 if (!wdata->state.mp) { in wiimote_init_poll_mp()
926 hid_info(wdata->hdev, "detected extension: Nintendo Wii Motion Plus\n"); in wiimote_init_poll_mp()
929 } else if (wdata->state.mp) { in wiimote_init_poll_mp()
933 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_poll_mp()
952 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
953 flags = wdata->state.flags; in wiimote_init_check()
954 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
963 * - If MP is unplugged/replugged, read_mp_mapped() fails in wiimote_init_check()
964 * - If EXT is plugged, MP_PLUGGED will get set */ in wiimote_init_check()
965 if (wdata->state.exttype == WIIMOTE_EXT_NONE && in wiimote_init_check()
966 wdata->state.mp > 0 && (flags & WIIPROTO_FLAG_MP_USED)) { in wiimote_init_check()
970 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
971 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
972 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED); in wiimote_init_check()
973 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
974 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
977 hid_dbg(wdata->hdev, "state left: !EXT && MP\n"); in wiimote_init_check()
988 * - If MP is plugged/unplugged, our timer detects it in wiimote_init_check()
989 * - If EXT is unplugged/replugged, EXT_ACTIVE will become unset */ in wiimote_init_check()
991 wdata->state.exttype != WIIMOTE_EXT_NONE) { in wiimote_init_check()
993 ret = type == wdata->state.exttype; in wiimote_init_check()
995 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
996 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
997 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
998 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1001 hid_dbg(wdata->hdev, "state left: EXT && !MP\n"); in wiimote_init_check()
1014 * - If MP is plugged/unplugged, our timer detects it in wiimote_init_check()
1015 * - If EXT is plugged, EXT_PLUGGED will be set */ in wiimote_init_check()
1017 wdata->state.exttype == WIIMOTE_EXT_NONE) { in wiimote_init_check()
1019 ret = type == wdata->state.exttype; in wiimote_init_check()
1021 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
1022 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
1023 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
1024 ret = ret && !(wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED); in wiimote_init_check()
1025 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1028 hid_dbg(wdata->hdev, "state left: !EXT && !MP\n"); in wiimote_init_check()
1036 /* The trickiest part is if both EXT and MP are active. We cannot read in wiimote_init_check()
1037 * the EXT ID, anymore, because MP is mapped over it. However, we use in wiimote_init_check()
1039 * - EXT_ACTIVE is unset whenever !MP_PLUGGED is sent in wiimote_init_check()
1040 * MP_PLUGGED might be re-sent again before we are scheduled, but in wiimote_init_check()
1044 if (wdata->state.exttype != WIIMOTE_EXT_NONE && in wiimote_init_check()
1045 wdata->state.mp > 0 && (flags & WIIPROTO_FLAG_MP_USED)) { in wiimote_init_check()
1051 spin_lock_irq(&wdata->state.lock); in wiimote_init_check()
1052 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED); in wiimote_init_check()
1053 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE); in wiimote_init_check()
1054 ret = ret && (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE); in wiimote_init_check()
1055 spin_unlock_irq(&wdata->state.lock); in wiimote_init_check()
1058 hid_dbg(wdata->hdev, "state left: EXT && MP\n"); in wiimote_init_check()
1094 * If we receive an hotplug event and the device-check failed, we deinitialize
1095 * the extension ports, re-read all extension IDs and set the device into
1106 hid_dbg(wdata->hdev, "detect extensions..\n"); in wiimote_init_hotplug()
1110 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1113 flags = wdata->state.flags; in wiimote_init_hotplug()
1116 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1117 wdata->state.flags &= ~WIIPROTO_FLAG_MP_ACTIVE; in wiimote_init_hotplug()
1119 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1134 if (exttype != wdata->state.exttype) { in wiimote_init_hotplug()
1139 hid_info(wdata->hdev, "cannot detect extension; %6phC\n", in wiimote_init_hotplug()
1142 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1143 wdata->state.exttype = WIIMOTE_EXT_NONE; in wiimote_init_hotplug()
1144 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1146 hid_info(wdata->hdev, "detected extension: %s\n", in wiimote_init_hotplug()
1155 if (!wdata->state.mp) { in wiimote_init_hotplug()
1156 hid_info(wdata->hdev, "detected extension: Nintendo Wii Motion Plus\n"); in wiimote_init_hotplug()
1159 } else if (wdata->state.mp) { in wiimote_init_hotplug()
1174 del_timer_sync(&wdata->timer); in wiimote_init_hotplug()
1179 mod_timer(&wdata->timer, jiffies + HZ * 4); in wiimote_init_hotplug()
1182 spin_lock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1186 wdata->state.flags |= WIIPROTO_FLAG_MP_ACTIVE; in wiimote_init_hotplug()
1187 if (wdata->state.exttype == WIIMOTE_EXT_NONE) { in wiimote_init_hotplug()
1188 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_hotplug()
1189 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in wiimote_init_hotplug()
1191 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in wiimote_init_hotplug()
1192 wdata->state.flags |= WIIPROTO_FLAG_MP_PLUGGED; in wiimote_init_hotplug()
1193 wdata->state.flags |= WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1195 } else if (wdata->state.exttype != WIIMOTE_EXT_NONE) { in wiimote_init_hotplug()
1196 wdata->state.flags |= WIIPROTO_FLAG_EXT_ACTIVE; in wiimote_init_hotplug()
1202 spin_unlock_irq(&wdata->state.lock); in wiimote_init_hotplug()
1204 hid_dbg(wdata->hdev, "detected extensions: MP: %d EXT: %d\n", in wiimote_init_hotplug()
1205 wdata->state.mp, wdata->state.exttype); in wiimote_init_hotplug()
1214 if (wdata->state.devtype == WIIMOTE_DEV_PENDING) { in wiimote_init_worker()
1223 kobject_uevent(&wdata->hdev->dev.kobj, KOBJ_CHANGE); in wiimote_init_worker()
1228 if (!(wdata->state.flags & WIIPROTO_FLAG_EXITING)) in __wiimote_schedule()
1229 schedule_work(&wdata->init_worker); in __wiimote_schedule()
1236 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_schedule()
1238 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_schedule()
1255 ops = wiimod_ext_table[wdata->state.exttype]; in handler_keys()
1256 if (ops->in_keys) { in handler_keys()
1257 ops->in_keys(wdata, payload); in handler_keys()
1261 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_keys()
1264 if (ops->in_keys) { in handler_keys()
1265 ops->in_keys(wdata, payload); in handler_keys()
1276 ops = wiimod_ext_table[wdata->state.exttype]; in handler_accel()
1277 if (ops->in_accel) { in handler_accel()
1278 ops->in_accel(wdata, payload); in handler_accel()
1282 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_accel()
1285 if (ops->in_accel) { in handler_accel()
1286 ops->in_accel(wdata, payload); in handler_accel()
1294 if (!ops->in_ext) in valid_ext_handler()
1296 if ((ops->flags & WIIMOD_FLAG_EXT8) && len < 8) in valid_ext_handler()
1298 if ((ops->flags & WIIMOD_FLAG_EXT16) && len < 16) in valid_ext_handler()
1323 if (wdata->state.flags & WIIPROTO_FLAG_MP_ACTIVE) { in handler_ext()
1329 if (!(wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED)) { in handler_ext()
1330 hid_dbg(wdata->hdev, "MP hotplug: 1\n"); in handler_ext()
1331 wdata->state.flags |= WIIPROTO_FLAG_MP_PLUGGED; in handler_ext()
1335 if (wdata->state.flags & WIIPROTO_FLAG_MP_PLUGGED) { in handler_ext()
1336 hid_dbg(wdata->hdev, "MP hotplug: 0\n"); in handler_ext()
1337 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in handler_ext()
1338 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in handler_ext()
1343 /* detect MP data that is sent interleaved with EXT data */ in handler_ext()
1349 /* ignore EXT events if no extension is active */ in handler_ext()
1350 if (!(wdata->state.flags & WIIPROTO_FLAG_EXT_ACTIVE) && !is_mp) in handler_ext()
1354 ops = wiimod_ext_table[wdata->state.exttype]; in handler_ext()
1355 if (is_mp && ops->in_mp) { in handler_ext()
1356 ops->in_mp(wdata, payload); in handler_ext()
1359 ops->in_ext(wdata, payload); in handler_ext()
1365 if (is_mp && ops->in_mp) { in handler_ext()
1366 ops->in_mp(wdata, payload); in handler_ext()
1369 ops->in_ext(wdata, payload); in handler_ext()
1374 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_ext()
1377 if (is_mp && ops->in_mp) { in handler_ext()
1378 ops->in_mp(wdata, payload); in handler_ext()
1381 ops->in_ext(wdata, payload); in handler_ext()
1398 ops = wiimod_ext_table[wdata->state.exttype]; in handler_ir()
1399 if (ops->in_ir) { in handler_ir()
1400 ops->in_ir(wdata, payload, packed, id); in handler_ir()
1404 mods = wiimote_devtype_mods[wdata->state.devtype]; in handler_ir()
1407 if (ops->in_ir) { in handler_ir()
1408 ops->in_ir(wdata, payload, packed, id); in handler_ir()
1420 /* on status reports the drm is reset so we need to resend the drm */ in handler_status_K()
1431 if (!(wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED)) { in handler_status()
1432 hid_dbg(wdata->hdev, "EXT hotplug: 1\n"); in handler_status()
1433 wdata->state.flags |= WIIPROTO_FLAG_EXT_PLUGGED; in handler_status()
1437 if (wdata->state.flags & WIIPROTO_FLAG_EXT_PLUGGED) { in handler_status()
1438 hid_dbg(wdata->hdev, "EXT hotplug: 0\n"); in handler_status()
1439 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_PLUGGED; in handler_status()
1440 wdata->state.flags &= ~WIIPROTO_FLAG_MP_PLUGGED; in handler_status()
1441 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_ACTIVE; in handler_status()
1442 wdata->state.flags &= ~WIIPROTO_FLAG_MP_ACTIVE; in handler_status()
1447 wdata->state.cmd_battery = payload[5]; in handler_status()
1469 else if (size > wdata->state.cmd_read_size) in handler_data()
1470 size = wdata->state.cmd_read_size; in handler_data()
1472 wdata->state.cmd_read_size = size; in handler_data()
1473 if (wdata->state.cmd_read_buf) in handler_data()
1474 memcpy(wdata->state.cmd_read_buf, &payload[5], size); in handler_data()
1487 wdata->state.cmd_err = err; in handler_return()
1490 hid_warn(wdata->hdev, "Remote error %u on req %u\n", err, in handler_return()
1560 wdata->state.accel_split[0] = payload[2]; in handler_drm_SKAI1()
1561 wdata->state.accel_split[1] = (payload[0] >> 1) & (0x10 | 0x20); in handler_drm_SKAI1()
1562 wdata->state.accel_split[1] |= (payload[1] << 1) & (0x40 | 0x80); in handler_drm_SKAI1()
1574 wdata->state.accel_split[1] |= (payload[0] >> 5) & (0x01 | 0x02); in handler_drm_SKAI2()
1575 wdata->state.accel_split[1] |= (payload[1] >> 3) & (0x04 | 0x08); in handler_drm_SKAI2()
1579 buf[2] = wdata->state.accel_split[0]; in handler_drm_SKAI2()
1581 buf[4] = wdata->state.accel_split[1]; in handler_drm_SKAI2()
1631 return -EINVAL; in wiimote_hid_event()
1635 if (h->id == raw_data[0] && h->size < size) { in wiimote_hid_event()
1636 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_hid_event()
1637 h->func(wdata, &raw_data[1]); in wiimote_hid_event()
1638 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_hid_event()
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()
1694 return -EINVAL; in wiimote_ext_store()
1711 spin_lock_irqsave(&wdata->state.lock, flags); in wiimote_dev_show()
1712 type = wdata->state.devtype; in wiimote_dev_show()
1713 spin_unlock_irqrestore(&wdata->state.lock, flags); in wiimote_dev_show()
1744 wdata->hdev = hdev; 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()
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 timer_shutdown_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()
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()
1795 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; in wiimote_hid_probe()
1800 return -ENOMEM; in wiimote_hid_probe()
1821 ret = device_create_file(&hdev->dev, &dev_attr_extension); in wiimote_hid_probe()
1827 ret = device_create_file(&hdev->dev, &dev_attr_devtype); 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()
1879 MODULE_PARM_DESC(dpad_as_analog, "Use D-Pad as main analog input");