Lines Matching +full:is +full:- +full:wired

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
15 * This driver is based on:
16 * - information from http://euc.jp/periphs/xbox-controller.ja.html
17 * - the iForce driver drivers/char/joystick/iforce.c
18 * - the skeleton-driver drivers/usb/usb-skeleton.c
19 * - Xbox 360 information http://www.free60.org/wiki/Gamepad
20 * - Xbox One information https://github.com/quantus/xbox-one-controller-protocol
23 * - ITO Takayuki for providing essential xpad information on his website
24 * - Vojtech Pavlik - iforce driver / input subsystem
25 * - Greg Kroah-Hartman - usb-skeleton driver
26 * - Xbox Linux project - extra USB IDs
27 * - Pekka Pöyry (quantus) - Xbox One controller reverse-engineering
30 * - fine tune axes (especially trigger axes)
31 * - fix "analog" buttons (reported as digital now)
32 * - get rumble working
33 * - need USB IDs for other dance pads
37 * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller"
39 * 2002-07-02 - 0.0.2 : basic working version
40 * - all axes and 9 of the 10 buttons work (german InterAct device)
41 * - the black button does not work
43 * 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik
44 * - indentation fixes
45 * - usb + input init sequence fixes
47 * 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3
48 * - verified the lack of HID and report descriptors
49 * - verified that ALL buttons WORK
50 * - fixed d-pad to axes mapping
52 * 2002-07-17 - 0.0.5 : simplified d-pad handling
54 * 2004-10-02 - 0.0.6 : DDR pad support
55 * - borrowed from the Xbox Linux kernel
56 * - USB id's for commonly used dance pads are present
57 * - dance pads will map D-PAD to buttons, not axes
58 * - pass the module paramater 'dpad_to_buttons' to force
59 * the D-PAD to map to buttons if your pad is not detected
77 * xbox d-pads should map to buttons, as is required for DDR pads
97 /* Send power-off packet to xpad360w after holding the mode button for this many
110 MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads");
132 { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
135 { 0x03f0, 0x038D, "HyperX Clutch", 0, XTYPE_XBOX360 }, /* wired */
147 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
148 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
151 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
152 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
153 { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
156 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
157 { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
158 { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE },
159 { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
161 { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
162 { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
172 { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
174 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
195 { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
200 …{ 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX…
207 { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
210 { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
211 { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
221 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
223 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
236 { 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
238 { 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
239 { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
241 { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
244 { 0x0e6f, 0x015d, "PDP Mirror's Edge Official Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
250 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
256 { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
257 { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
258 { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
262 { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
263 { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
264 { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
294 { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
301 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
310 { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
312 { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
336 …{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XB…
356 { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
357 { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
358 { 0x20d6, 0x2064, "PowerA Wired Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
359 { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
362 { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
366 { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
368 { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
370 { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
389 { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
390 { 0x2dc8, 0x3106, "8BitDo Ultimate Wireless / Pro 2 Wired Controller", 0, XTYPE_XBOX360 },
395 { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
396 { 0x2e24, 0x1688, "Hyperkin X91 X-Box One pad", 0, XTYPE_XBOXONE },
406 { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
410 { 0x3285, 0x0663, "Nacon Evol-X", 0, XTYPE_XBOXONE },
415 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
416 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
423 -1 /* terminating entry */
429 -1 /* terminating entry */
432 /* used when dpad is mapped to buttons */
434 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
435 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
436 -1 /* terminating entry */
442 -1
448 -1
454 -1 /* terminating entry */
457 /* used when dpad is mapped to axes */
459 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
460 -1 /* terminating entry */
466 -1
473 -1 /* terminating entry */
477 * Xbox 360 has a vendor-specific class, so we cannot match it with only
479 * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
505 * macros - XPAD_XBOX360_VENDOR and XPAD_XBOXONE_VENDOR.
507 { USB_INTERFACE_INFO('X', 'B', 0) }, /* Xbox USB-IF not-approved class */
516 XPAD_XBOX360_VENDOR(0x046d), /* Logitech Xbox 360-style controllers */
517 XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
524 XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
525 XPAD_XBOX360_VENDOR(0x0db0), /* Micro Star International X-Box 360 controllers */
563 XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
564 XPAD_XBOXONE_VENDOR(0x3285), /* Nacon Evol-X */
589 * starting with xbox one, the game input protocol is used
591 * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
592 * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
612 * which is a no-op for N < 128
632 * This packet is required for all Xbox One pads with 2015
640 * This packet is required for Xbox One S (0x045e:0x02ea)
650 * This packet is required to get additional input data
659 * This packet is required for the Titanfall 2 Xbox One pads
669 * This packet is required for most (all?) of the PDP pads to start
678 * This packet is required for most (all?) of the PDP pads to start
687 * A specific rumble packet is required for some PowerA pads to start
688 * sending input reports. One of those pads is (0x24c6:0x543a).
710 * packet is going to be sent.
775 int mapping; /* map d-pad to buttons or to axes */
796 * http://euc.jp/periphs/xbox-controller.ja.html
800 struct input_dev *dev = xpad->dev; in xpad_process_packet()
802 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_process_packet()
817 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_process_packet()
826 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_process_packet()
834 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad_process_packet()
836 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad_process_packet()
863 * input subsystem. It is version for xbox 360 controller
877 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad360_process_packet()
891 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad360_process_packet()
892 xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
894 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad360_process_packet()
896 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad360_process_packet()
916 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad360_process_packet()
931 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad360_process_packet()
942 if (xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
943 if (xpad->mode_btn_down_ts > 0 && xpad->pad_present && in xpad360_process_packet()
944 ((ktime_get_seconds() - xpad->mode_btn_down_ts) >= in xpad360_process_packet()
947 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
953 xpad->mode_btn_down_ts = ktime_get_seconds(); in xpad360_process_packet()
955 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
964 if (xpad->pad_present) { in xpad_presence_work()
968 dev_err(&xpad->dev->dev, in xpad_presence_work()
971 rcu_assign_pointer(xpad->x360w_dev, xpad->dev); in xpad_presence_work()
974 RCU_INIT_POINTER(xpad->x360w_dev, NULL); in xpad_presence_work()
977 * Now that we are sure xpad360w_process_packet is not in xpad_presence_work()
988 * input subsystem. It is version for xbox 360 wireless controller.
991 * 00.1 - Status change: The controller or headset has connected/disconnected
993 * 01.7 - Controller present
994 * 01.6 - Headset present
995 * 01.1 - Pad state (Bytes 4+) valid
1007 if (xpad->pad_present != present) { in xpad360w_process_packet()
1008 xpad->pad_present = present; in xpad360w_process_packet()
1009 schedule_work(&xpad->work); in xpad360w_process_packet()
1018 dev = rcu_dereference(xpad->x360w_dev); in xpad360w_process_packet()
1028 * input subsystem. This version is for the Xbox One controller.
1035 struct input_dev *dev = xpad->dev; in xpadone_process_packet()
1054 if (xpad->packet_type == PKT_XBE2_FW_5_11) { in xpadone_process_packet()
1055 /* Mute paddles if controller is in a custom profile slot in xpadone_process_packet()
1074 if (xpad->mapping & MAP_SHARE_BUTTON) { in xpadone_process_packet()
1075 if (xpad->mapping & MAP_SHARE_OFFSET) in xpadone_process_packet()
1076 input_report_key(dev, KEY_RECORD, data[len - 26] & BIT(0)); in xpadone_process_packet()
1078 input_report_key(dev, KEY_RECORD, data[len - 18] & BIT(0)); in xpadone_process_packet()
1088 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpadone_process_packet()
1096 !!(data[5] & 0x08) - !!(data[5] & 0x04)); in xpadone_process_packet()
1098 !!(data[5] & 0x02) - !!(data[5] & 0x01)); in xpadone_process_packet()
1109 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpadone_process_packet()
1124 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpadone_process_packet()
1136 /* Profile button has a value of 0-3, so it is reported as an axis */ in xpadone_process_packet()
1137 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpadone_process_packet()
1142 if (xpad->mapping & MAP_PADDLES) { in xpadone_process_packet()
1143 if (xpad->packet_type == PKT_XBE1) { in xpadone_process_packet()
1156 } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { in xpadone_process_packet()
1169 } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { in xpadone_process_packet()
1196 struct usb_xpad *xpad = urb->context; in xpad_irq_in()
1197 struct device *dev = &xpad->intf->dev; in xpad_irq_in()
1200 status = urb->status; in xpad_irq_in()
1206 case -ECONNRESET: in xpad_irq_in()
1207 case -ENOENT: in xpad_irq_in()
1208 case -ESHUTDOWN: in xpad_irq_in()
1209 /* this urb is terminated, clean up */ in xpad_irq_in()
1210 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_in()
1214 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_in()
1219 switch (xpad->xtype) { in xpad_irq_in()
1221 xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); in xpad_irq_in()
1224 xpad360w_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1227 xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length); in xpad_irq_in()
1230 xpad_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1236 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", in xpad_irq_in()
1240 /* Callers must hold xpad->odata_lock spinlock */
1245 if (xpad->xtype != XTYPE_XBOXONE) in xpad_prepare_next_init_packet()
1249 while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { in xpad_prepare_next_init_packet()
1250 init_packet = &xboxone_init_packets[xpad->init_seq++]; in xpad_prepare_next_init_packet()
1252 if (init_packet->idVendor != 0 && in xpad_prepare_next_init_packet()
1253 init_packet->idVendor != xpad->dev->id.vendor) in xpad_prepare_next_init_packet()
1256 if (init_packet->idProduct != 0 && in xpad_prepare_next_init_packet()
1257 init_packet->idProduct != xpad->dev->id.product) in xpad_prepare_next_init_packet()
1261 memcpy(xpad->odata, init_packet->data, init_packet->len); in xpad_prepare_next_init_packet()
1262 xpad->irq_out->transfer_buffer_length = init_packet->len; in xpad_prepare_next_init_packet()
1265 xpad->odata[2] = xpad->odata_serial++; in xpad_prepare_next_init_packet()
1272 /* Callers must hold xpad->odata_lock spinlock */
1283 if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) in xpad_prepare_next_out_packet()
1284 xpad->last_out_packet = 0; in xpad_prepare_next_out_packet()
1286 pkt = &xpad->out_packets[xpad->last_out_packet]; in xpad_prepare_next_out_packet()
1287 if (pkt->pending) { in xpad_prepare_next_out_packet()
1288 dev_dbg(&xpad->intf->dev, in xpad_prepare_next_out_packet()
1289 "%s - found pending output packet %d\n", in xpad_prepare_next_out_packet()
1290 __func__, xpad->last_out_packet); in xpad_prepare_next_out_packet()
1297 memcpy(xpad->odata, packet->data, packet->len); in xpad_prepare_next_out_packet()
1298 xpad->irq_out->transfer_buffer_length = packet->len; in xpad_prepare_next_out_packet()
1299 packet->pending = false; in xpad_prepare_next_out_packet()
1306 /* Callers must hold xpad->odata_lock spinlock */
1311 if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { in xpad_try_sending_next_out_packet()
1312 usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); in xpad_try_sending_next_out_packet()
1313 error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); in xpad_try_sending_next_out_packet()
1315 dev_err(&xpad->intf->dev, in xpad_try_sending_next_out_packet()
1316 "%s - usb_submit_urb failed with result %d\n", in xpad_try_sending_next_out_packet()
1318 usb_unanchor_urb(xpad->irq_out); in xpad_try_sending_next_out_packet()
1319 return -EIO; in xpad_try_sending_next_out_packet()
1322 xpad->irq_out_active = true; in xpad_try_sending_next_out_packet()
1330 struct usb_xpad *xpad = urb->context; in xpad_irq_out()
1331 struct device *dev = &xpad->intf->dev; in xpad_irq_out()
1332 int status = urb->status; in xpad_irq_out()
1336 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_irq_out()
1341 xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); in xpad_irq_out()
1344 case -ECONNRESET: in xpad_irq_out()
1345 case -ENOENT: in xpad_irq_out()
1346 case -ESHUTDOWN: in xpad_irq_out()
1347 /* this urb is terminated, clean up */ in xpad_irq_out()
1348 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_out()
1350 xpad->irq_out_active = false; in xpad_irq_out()
1354 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_out()
1359 if (xpad->irq_out_active) { in xpad_irq_out()
1360 usb_anchor_urb(urb, &xpad->irq_out_anchor); in xpad_irq_out()
1364 "%s - usb_submit_urb failed with result %d\n", in xpad_irq_out()
1367 xpad->irq_out_active = false; in xpad_irq_out()
1371 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_irq_out()
1379 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_output()
1382 init_usb_anchor(&xpad->irq_out_anchor); in xpad_init_output()
1384 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_init_output()
1385 GFP_KERNEL, &xpad->odata_dma); in xpad_init_output()
1386 if (!xpad->odata) in xpad_init_output()
1387 return -ENOMEM; in xpad_init_output()
1389 spin_lock_init(&xpad->odata_lock); in xpad_init_output()
1391 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); in xpad_init_output()
1392 if (!xpad->irq_out) { in xpad_init_output()
1393 error = -ENOMEM; in xpad_init_output()
1397 usb_fill_int_urb(xpad->irq_out, xpad->udev, in xpad_init_output()
1398 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), in xpad_init_output()
1399 xpad->odata, XPAD_PKT_LEN, in xpad_init_output()
1400 xpad_irq_out, xpad, ep_irq_out->bInterval); in xpad_init_output()
1401 xpad->irq_out->transfer_dma = xpad->odata_dma; in xpad_init_output()
1402 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_init_output()
1407 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); in xpad_init_output()
1413 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_stop_output()
1414 if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, in xpad_stop_output()
1416 dev_warn(&xpad->intf->dev, in xpad_stop_output()
1418 usb_kill_anchored_urbs(&xpad->irq_out_anchor); in xpad_stop_output()
1425 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_deinit_output()
1426 usb_free_urb(xpad->irq_out); in xpad_deinit_output()
1427 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_deinit_output()
1428 xpad->odata, xpad->odata_dma); in xpad_deinit_output()
1435 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad_inquiry_pad_presence()
1439 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1441 packet->data[0] = 0x08; in xpad_inquiry_pad_presence()
1442 packet->data[1] = 0x00; in xpad_inquiry_pad_presence()
1443 packet->data[2] = 0x0F; in xpad_inquiry_pad_presence()
1444 packet->data[3] = 0xC0; in xpad_inquiry_pad_presence()
1445 packet->data[4] = 0x00; in xpad_inquiry_pad_presence()
1446 packet->data[5] = 0x00; in xpad_inquiry_pad_presence()
1447 packet->data[6] = 0x00; in xpad_inquiry_pad_presence()
1448 packet->data[7] = 0x00; in xpad_inquiry_pad_presence()
1449 packet->data[8] = 0x00; in xpad_inquiry_pad_presence()
1450 packet->data[9] = 0x00; in xpad_inquiry_pad_presence()
1451 packet->data[10] = 0x00; in xpad_inquiry_pad_presence()
1452 packet->data[11] = 0x00; in xpad_inquiry_pad_presence()
1453 packet->len = 12; in xpad_inquiry_pad_presence()
1454 packet->pending = true; in xpad_inquiry_pad_presence()
1457 xpad->last_out_packet = -1; in xpad_inquiry_pad_presence()
1460 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1470 if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) { in xpad_start_xbox_one()
1472 * Explicitly disable the audio interface. This is needed in xpad_start_xbox_one()
1473 * for some controllers, such as the PowerA Enhanced Wired in xpad_start_xbox_one()
1477 retval = usb_set_interface(xpad->udev, in xpad_start_xbox_one()
1480 dev_warn(&xpad->dev->dev, in xpad_start_xbox_one()
1485 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1492 xpad->init_seq = 0; in xpad_start_xbox_one()
1495 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1504 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpadone_ack_mode_report()
1510 spin_lock_irqsave(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1512 packet->len = sizeof(mode_report_ack); in xpadone_ack_mode_report()
1513 memcpy(packet->data, mode_report_ack, packet->len); in xpadone_ack_mode_report()
1514 packet->data[2] = seq_num; in xpadone_ack_mode_report()
1515 packet->pending = true; in xpadone_ack_mode_report()
1518 xpad->last_out_packet = -1; in xpadone_ack_mode_report()
1521 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1528 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; in xpad_play_effect()
1534 if (effect->type != FF_RUMBLE) in xpad_play_effect()
1537 strong = effect->u.rumble.strong_magnitude; in xpad_play_effect()
1538 weak = effect->u.rumble.weak_magnitude; in xpad_play_effect()
1540 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_play_effect()
1542 switch (xpad->xtype) { in xpad_play_effect()
1544 packet->data[0] = 0x00; in xpad_play_effect()
1545 packet->data[1] = 0x06; in xpad_play_effect()
1546 packet->data[2] = 0x00; in xpad_play_effect()
1547 packet->data[3] = strong / 256; /* left actuator */ in xpad_play_effect()
1548 packet->data[4] = 0x00; in xpad_play_effect()
1549 packet->data[5] = weak / 256; /* right actuator */ in xpad_play_effect()
1550 packet->len = 6; in xpad_play_effect()
1551 packet->pending = true; in xpad_play_effect()
1555 packet->data[0] = 0x00; in xpad_play_effect()
1556 packet->data[1] = 0x08; in xpad_play_effect()
1557 packet->data[2] = 0x00; in xpad_play_effect()
1558 packet->data[3] = strong / 256; /* left actuator? */ in xpad_play_effect()
1559 packet->data[4] = weak / 256; /* right actuator? */ in xpad_play_effect()
1560 packet->data[5] = 0x00; in xpad_play_effect()
1561 packet->data[6] = 0x00; in xpad_play_effect()
1562 packet->data[7] = 0x00; in xpad_play_effect()
1563 packet->len = 8; in xpad_play_effect()
1564 packet->pending = true; in xpad_play_effect()
1568 packet->data[0] = 0x00; in xpad_play_effect()
1569 packet->data[1] = 0x01; in xpad_play_effect()
1570 packet->data[2] = 0x0F; in xpad_play_effect()
1571 packet->data[3] = 0xC0; in xpad_play_effect()
1572 packet->data[4] = 0x00; in xpad_play_effect()
1573 packet->data[5] = strong / 256; in xpad_play_effect()
1574 packet->data[6] = weak / 256; in xpad_play_effect()
1575 packet->data[7] = 0x00; in xpad_play_effect()
1576 packet->data[8] = 0x00; in xpad_play_effect()
1577 packet->data[9] = 0x00; in xpad_play_effect()
1578 packet->data[10] = 0x00; in xpad_play_effect()
1579 packet->data[11] = 0x00; in xpad_play_effect()
1580 packet->len = 12; in xpad_play_effect()
1581 packet->pending = true; in xpad_play_effect()
1585 packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */ in xpad_play_effect()
1586 packet->data[1] = 0x00; in xpad_play_effect()
1587 packet->data[2] = xpad->odata_serial++; in xpad_play_effect()
1588 packet->data[3] = GIP_PL_LEN(9); in xpad_play_effect()
1589 packet->data[4] = 0x00; in xpad_play_effect()
1590 packet->data[5] = GIP_MOTOR_ALL; in xpad_play_effect()
1591 packet->data[6] = 0x00; /* left trigger */ in xpad_play_effect()
1592 packet->data[7] = 0x00; /* right trigger */ in xpad_play_effect()
1593 packet->data[8] = strong / 512; /* left actuator */ in xpad_play_effect()
1594 packet->data[9] = weak / 512; /* right actuator */ in xpad_play_effect()
1595 packet->data[10] = 0xFF; /* on period */ in xpad_play_effect()
1596 packet->data[11] = 0x00; /* off period */ in xpad_play_effect()
1597 packet->data[12] = 0xFF; /* repeat count */ in xpad_play_effect()
1598 packet->len = 13; in xpad_play_effect()
1599 packet->pending = true; in xpad_play_effect()
1603 dev_dbg(&xpad->dev->dev, in xpad_play_effect()
1604 "%s - rumble command sent to unsupported xpad type: %d\n", in xpad_play_effect()
1605 __func__, xpad->xtype); in xpad_play_effect()
1606 retval = -EINVAL; in xpad_play_effect()
1613 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_play_effect()
1619 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_ff()
1622 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); in xpad_init_ff()
1624 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); in xpad_init_ff()
1648 * 2: 1/top-left blink, then on
1649 * 3: 2/top-right blink, then on
1650 * 4: 3/bottom-left blink, then on
1651 * 5: 4/bottom-right blink, then on
1652 * 6: 1/top-left on
1653 * 7: 2/top-right on
1654 * 8: 3/bottom-left on
1655 * 9: 4/bottom-right on
1666 &xpad->out_packets[XPAD_OUT_LED_IDX]; in xpad_send_led_command()
1671 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_send_led_command()
1673 switch (xpad->xtype) { in xpad_send_led_command()
1675 packet->data[0] = 0x01; in xpad_send_led_command()
1676 packet->data[1] = 0x03; in xpad_send_led_command()
1677 packet->data[2] = command; in xpad_send_led_command()
1678 packet->len = 3; in xpad_send_led_command()
1679 packet->pending = true; in xpad_send_led_command()
1683 packet->data[0] = 0x00; in xpad_send_led_command()
1684 packet->data[1] = 0x00; in xpad_send_led_command()
1685 packet->data[2] = 0x08; in xpad_send_led_command()
1686 packet->data[3] = 0x40 + command; in xpad_send_led_command()
1687 packet->data[4] = 0x00; in xpad_send_led_command()
1688 packet->data[5] = 0x00; in xpad_send_led_command()
1689 packet->data[6] = 0x00; in xpad_send_led_command()
1690 packet->data[7] = 0x00; in xpad_send_led_command()
1691 packet->data[8] = 0x00; in xpad_send_led_command()
1692 packet->data[9] = 0x00; in xpad_send_led_command()
1693 packet->data[10] = 0x00; in xpad_send_led_command()
1694 packet->data[11] = 0x00; in xpad_send_led_command()
1695 packet->len = 12; in xpad_send_led_command()
1696 packet->pending = true; in xpad_send_led_command()
1702 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_send_led_command()
1711 led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); in xpad_identify_controller()
1720 xpad_send_led_command(xpad_led->xpad, value); in xpad_led_set()
1729 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) in xpad_led_probe()
1732 xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL); in xpad_led_probe()
1734 return -ENOMEM; in xpad_led_probe()
1736 xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL); in xpad_led_probe()
1737 if (xpad->pad_nr < 0) { in xpad_led_probe()
1738 error = xpad->pad_nr; in xpad_led_probe()
1742 snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); in xpad_led_probe()
1743 led->xpad = xpad; in xpad_led_probe()
1745 led_cdev = &led->led_cdev; in xpad_led_probe()
1746 led_cdev->name = led->name; in xpad_led_probe()
1747 led_cdev->brightness_set = xpad_led_set; in xpad_led_probe()
1748 led_cdev->flags = LED_CORE_SUSPENDRESUME; in xpad_led_probe()
1750 error = led_classdev_register(&xpad->udev->dev, led_cdev); in xpad_led_probe()
1759 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_probe()
1762 xpad->led = NULL; in xpad_led_probe()
1768 struct xpad_led *xpad_led = xpad->led; in xpad_led_disconnect()
1771 led_classdev_unregister(&xpad_led->led_cdev); in xpad_led_disconnect()
1772 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_disconnect()
1785 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) in xpad_start_input()
1786 return -EIO; in xpad_start_input()
1788 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_start_input()
1791 usb_kill_urb(xpad->irq_in); in xpad_start_input()
1795 if (xpad->xtype == XTYPE_XBOX360) { in xpad_start_input()
1797 * Some third-party controllers Xbox 360-style controllers in xpad_start_input()
1802 error = usb_control_msg_recv(xpad->udev, 0, in xpad_start_input()
1812 dev_warn(&xpad->dev->dev, in xpad_start_input()
1822 usb_kill_urb(xpad->irq_in); in xpad_stop_input()
1829 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad360w_poweroff_controller()
1831 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1833 packet->data[0] = 0x00; in xpad360w_poweroff_controller()
1834 packet->data[1] = 0x00; in xpad360w_poweroff_controller()
1835 packet->data[2] = 0x08; in xpad360w_poweroff_controller()
1836 packet->data[3] = 0xC0; in xpad360w_poweroff_controller()
1837 packet->data[4] = 0x00; in xpad360w_poweroff_controller()
1838 packet->data[5] = 0x00; in xpad360w_poweroff_controller()
1839 packet->data[6] = 0x00; in xpad360w_poweroff_controller()
1840 packet->data[7] = 0x00; in xpad360w_poweroff_controller()
1841 packet->data[8] = 0x00; in xpad360w_poweroff_controller()
1842 packet->data[9] = 0x00; in xpad360w_poweroff_controller()
1843 packet->data[10] = 0x00; in xpad360w_poweroff_controller()
1844 packet->data[11] = 0x00; in xpad360w_poweroff_controller()
1845 packet->len = 12; in xpad360w_poweroff_controller()
1846 packet->pending = true; in xpad360w_poweroff_controller()
1849 xpad->last_out_packet = -1; in xpad360w_poweroff_controller()
1852 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1859 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); in xpad360w_start_input()
1861 return -EIO; in xpad360w_start_input()
1866 * This is useful in the case we activate the module after the in xpad360w_start_input()
1872 usb_kill_urb(xpad->irq_in); in xpad360w_start_input()
1881 usb_kill_urb(xpad->irq_in); in xpad360w_stop_input()
1884 flush_work(&xpad->work); in xpad360w_stop_input()
1910 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); in xpad_set_up_abs()
1914 if (xpad->xtype == XTYPE_XBOXONE) in xpad_set_up_abs()
1920 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ in xpad_set_up_abs()
1921 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); in xpad_set_up_abs()
1934 if (xpad->input_created) { in xpad_deinit_input()
1935 xpad->input_created = false; in xpad_deinit_input()
1937 input_unregister_device(xpad->dev); in xpad_deinit_input()
1948 return -ENOMEM; in xpad_init_input()
1950 xpad->dev = input_dev; in xpad_init_input()
1951 input_dev->name = xpad->name; in xpad_init_input()
1952 input_dev->phys = xpad->phys; in xpad_init_input()
1953 usb_to_input_id(xpad->udev, &input_dev->id); in xpad_init_input()
1955 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1957 input_dev->id.product = 0x02a1; in xpad_init_input()
1960 input_dev->dev.parent = &xpad->intf->dev; in xpad_init_input()
1964 if (xpad->xtype != XTYPE_XBOX360W) { in xpad_init_input()
1965 input_dev->open = xpad_open; in xpad_init_input()
1966 input_dev->close = xpad_close; in xpad_init_input()
1969 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_init_input()
1979 /* set up model-specific ones */ in xpad_init_input()
1980 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || in xpad_init_input()
1981 xpad->xtype == XTYPE_XBOXONE) { in xpad_init_input()
1984 if (xpad->mapping & MAP_SHARE_BUTTON) in xpad_init_input()
1991 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_init_input()
1998 if (xpad->mapping & MAP_PADDLES) { in xpad_init_input()
2009 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad_init_input()
2010 xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
2015 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_init_input()
2025 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_init_input()
2036 error = input_register_device(xpad->dev); in xpad_init_input()
2040 xpad->input_created = true; in xpad_init_input()
2059 if (intf->cur_altsetting->desc.bNumEndpoints != 2) in xpad_probe()
2060 return -ENODEV; in xpad_probe()
2063 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && in xpad_probe()
2064 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) in xpad_probe()
2070 return -ENOMEM; in xpad_probe()
2072 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); in xpad_probe()
2073 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); in xpad_probe()
2075 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, in xpad_probe()
2076 GFP_KERNEL, &xpad->idata_dma); in xpad_probe()
2077 if (!xpad->idata) { in xpad_probe()
2078 error = -ENOMEM; in xpad_probe()
2082 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); in xpad_probe()
2083 if (!xpad->irq_in) { in xpad_probe()
2084 error = -ENOMEM; in xpad_probe()
2088 xpad->udev = udev; in xpad_probe()
2089 xpad->intf = intf; in xpad_probe()
2090 xpad->mapping = xpad_device[i].mapping; in xpad_probe()
2091 xpad->xtype = xpad_device[i].xtype; in xpad_probe()
2092 xpad->name = xpad_device[i].name; in xpad_probe()
2093 xpad->packet_type = PKT_XB; in xpad_probe()
2094 INIT_WORK(&xpad->work, xpad_presence_work); in xpad_probe()
2096 if (xpad->xtype == XTYPE_UNKNOWN) { in xpad_probe()
2097 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { in xpad_probe()
2098 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) in xpad_probe()
2099 xpad->xtype = XTYPE_XBOX360W; in xpad_probe()
2100 else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) in xpad_probe()
2101 xpad->xtype = XTYPE_XBOXONE; in xpad_probe()
2103 xpad->xtype = XTYPE_XBOX360; in xpad_probe()
2105 xpad->xtype = XTYPE_XBOX; in xpad_probe()
2109 xpad->mapping |= MAP_DPAD_TO_BUTTONS; in xpad_probe()
2111 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; in xpad_probe()
2113 xpad->mapping |= MAP_STICKS_TO_NULL; in xpad_probe()
2116 if (xpad->xtype == XTYPE_XBOXONE && in xpad_probe()
2117 intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) { in xpad_probe()
2123 error = -ENODEV; in xpad_probe()
2131 &intf->cur_altsetting->endpoint[i].desc; in xpad_probe()
2142 error = -ENODEV; in xpad_probe()
2150 usb_fill_int_urb(xpad->irq_in, udev, in xpad_probe()
2151 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), in xpad_probe()
2152 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, in xpad_probe()
2153 xpad, ep_irq_in->bInterval); in xpad_probe()
2154 xpad->irq_in->transfer_dma = xpad->idata_dma; in xpad_probe()
2155 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_probe()
2160 if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ in xpad_probe()
2161 if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { in xpad_probe()
2165 xpad->packet_type = PKT_XBE1; in xpad_probe()
2166 } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { in xpad_probe()
2171 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { in xpad_probe()
2172 /* This is the format that the Elite 2 used in xpad_probe()
2175 xpad->packet_type = PKT_XBE2_FW_OLD; in xpad_probe()
2176 } else if (le16_to_cpu(udev->descriptor.bcdDevice) < in xpad_probe()
2178 /* This is the format that the Elite 2 used in xpad_probe()
2181 xpad->packet_type = PKT_XBE2_FW_5_EARLY; in xpad_probe()
2186 xpad->packet_type = PKT_XBE2_FW_5_11; in xpad_probe()
2191 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_probe()
2209 udev->quirks |= USB_QUIRK_RESET_RESUME; in xpad_probe()
2220 usb_free_urb(xpad->irq_in); in xpad_probe()
2222 usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); in xpad_probe()
2232 if (xpad->xtype == XTYPE_XBOX360W) in xpad_disconnect()
2245 usb_free_urb(xpad->irq_in); in xpad_disconnect()
2246 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_disconnect()
2247 xpad->idata, xpad->idata_dma); in xpad_disconnect()
2257 struct input_dev *input = xpad->dev; in xpad_suspend()
2259 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_suspend()
2268 * The wireless adapter is going off now, so the in xpad_suspend()
2273 if (auto_poweroff && xpad->pad_present) in xpad_suspend()
2276 mutex_lock(&input->mutex); in xpad_suspend()
2279 mutex_unlock(&input->mutex); in xpad_suspend()
2290 struct input_dev *input = xpad->dev; in xpad_resume()
2293 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_resume()
2296 mutex_lock(&input->mutex); in xpad_resume()
2299 } else if (xpad->xtype == XTYPE_XBOXONE) { in xpad_resume()
2307 mutex_unlock(&input->mutex); in xpad_resume()
2324 MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");