Lines Matching +full:digital +full:- +full:input +full:- +full:open +full:- +full:circuit +full:- +full:detection

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
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
66 #include <linux/input.h>
71 #include <linux/usb/input.h>
77 * xbox d-pads should map to buttons, as is required for DDR pads
96 /* Send power-off packet to xpad360w after holding the mode button for this many
109 MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads");
131 { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
145 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
146 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
149 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
150 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
151 { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
153 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
154 { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
155 { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE },
156 { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
158 { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
159 { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
169 { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
171 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
203 { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
206 { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
207 { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
217 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
219 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
245 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
251 { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
252 { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
253 { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
257 { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
284 { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
291 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
302 { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
315 { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
325 …{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XB…
358 { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
378 { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
385 { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
388 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
389 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
396 -1 /* terminating entry */
402 -1 /* terminating entry */
407 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
408 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
409 -1 /* terminating entry */
415 -1
421 -1
427 -1 /* terminating entry */
432 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
433 -1 /* terminating entry */
439 -1
446 -1 /* terminating entry */
450 * Xbox 360 has a vendor-specific class, so we cannot match it with only
478 * macros - XPAD_XBOX360_VENDOR and XPAD_XBOXONE_VENDOR.
480 { USB_INTERFACE_INFO('X', 'B', 0) }, /* Xbox USB-IF not-approved class */
488 XPAD_XBOX360_VENDOR(0x046d), /* Logitech Xbox 360-style controllers */
489 XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
496 XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
497 XPAD_XBOX360_VENDOR(0x0db0), /* Micro Star International X-Box 360 controllers */
532 XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
556 * starting with xbox one, the game input protocol is used
558 * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
559 * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
579 * which is a no-op for N < 128
617 * This packet is required to get additional input data
637 * sending input reports. These pads include: (0x0e6f:0x02ab),
646 * sending input reports. These pads include: (0x0e6f:0x02ab),
655 * sending input reports. One of those pads is (0x24c6:0x543a).
710 struct input_dev *dev; /* input device interface */
719 unsigned char *idata; /* input data */
740 int mapping; /* map d-pad to buttons or to axes */
758 * input subsystem.
761 * http://euc.jp/periphs/xbox-controller.ja.html
765 struct input_dev *dev = xpad->dev; in xpad_process_packet()
767 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_process_packet()
782 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_process_packet()
790 /* digital pad */ in xpad_process_packet()
791 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_process_packet()
799 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad_process_packet()
801 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad_process_packet()
828 * input subsystem. It is version for xbox 360 controller
841 /* digital pad */ in xpad360_process_packet()
842 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad360_process_packet()
856 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad360_process_packet()
857 xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
859 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad360_process_packet()
861 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad360_process_packet()
881 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad360_process_packet()
896 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad360_process_packet()
907 if (xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
908 if (xpad->mode_btn_down_ts > 0 && xpad->pad_present && in xpad360_process_packet()
909 ((ktime_get_seconds() - xpad->mode_btn_down_ts) >= in xpad360_process_packet()
912 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
918 xpad->mode_btn_down_ts = ktime_get_seconds(); in xpad360_process_packet()
920 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
929 if (xpad->pad_present) { in xpad_presence_work()
933 dev_err(&xpad->dev->dev, in xpad_presence_work()
936 rcu_assign_pointer(xpad->x360w_dev, xpad->dev); in xpad_presence_work()
939 RCU_INIT_POINTER(xpad->x360w_dev, NULL); in xpad_presence_work()
943 * using input device we can get rid of it. in xpad_presence_work()
953 * input subsystem. It is version for xbox 360 wireless controller.
956 * 00.1 - Status change: The controller or headset has connected/disconnected
958 * 01.7 - Controller present
959 * 01.6 - Headset present
960 * 01.1 - Pad state (Bytes 4+) valid
972 if (xpad->pad_present != present) { in xpad360w_process_packet()
973 xpad->pad_present = present; in xpad360w_process_packet()
974 schedule_work(&xpad->work); in xpad360w_process_packet()
983 dev = rcu_dereference(xpad->x360w_dev); in xpad360w_process_packet()
993 * input subsystem. This version is for the Xbox One controller.
1000 struct input_dev *dev = xpad->dev; in xpadone_process_packet()
1019 if (xpad->packet_type == PKT_XBE2_FW_5_11) { in xpadone_process_packet()
1039 if (xpad->mapping & MAP_SELECT_BUTTON) in xpadone_process_packet()
1048 /* digital pad */ in xpadone_process_packet()
1049 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpadone_process_packet()
1057 !!(data[5] & 0x08) - !!(data[5] & 0x04)); in xpadone_process_packet()
1059 !!(data[5] & 0x02) - !!(data[5] & 0x01)); in xpadone_process_packet()
1070 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpadone_process_packet()
1085 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpadone_process_packet()
1097 /* Profile button has a value of 0-3, so it is reported as an axis */ in xpadone_process_packet()
1098 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpadone_process_packet()
1103 if (xpad->mapping & MAP_PADDLES) { in xpadone_process_packet()
1104 if (xpad->packet_type == PKT_XBE1) { in xpadone_process_packet()
1117 } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { in xpadone_process_packet()
1130 } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { in xpadone_process_packet()
1157 struct usb_xpad *xpad = urb->context; in xpad_irq_in()
1158 struct device *dev = &xpad->intf->dev; in xpad_irq_in()
1161 status = urb->status; in xpad_irq_in()
1167 case -ECONNRESET: in xpad_irq_in()
1168 case -ENOENT: in xpad_irq_in()
1169 case -ESHUTDOWN: in xpad_irq_in()
1171 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_in()
1175 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_in()
1180 switch (xpad->xtype) { in xpad_irq_in()
1182 xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); in xpad_irq_in()
1185 xpad360w_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1188 xpadone_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1191 xpad_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1197 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", in xpad_irq_in()
1201 /* Callers must hold xpad->odata_lock spinlock */
1206 if (xpad->xtype != XTYPE_XBOXONE) in xpad_prepare_next_init_packet()
1210 while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { in xpad_prepare_next_init_packet()
1211 init_packet = &xboxone_init_packets[xpad->init_seq++]; in xpad_prepare_next_init_packet()
1213 if (init_packet->idVendor != 0 && in xpad_prepare_next_init_packet()
1214 init_packet->idVendor != xpad->dev->id.vendor) in xpad_prepare_next_init_packet()
1217 if (init_packet->idProduct != 0 && in xpad_prepare_next_init_packet()
1218 init_packet->idProduct != xpad->dev->id.product) in xpad_prepare_next_init_packet()
1222 memcpy(xpad->odata, init_packet->data, init_packet->len); in xpad_prepare_next_init_packet()
1223 xpad->irq_out->transfer_buffer_length = init_packet->len; in xpad_prepare_next_init_packet()
1226 xpad->odata[2] = xpad->odata_serial++; in xpad_prepare_next_init_packet()
1233 /* Callers must hold xpad->odata_lock spinlock */
1244 if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) in xpad_prepare_next_out_packet()
1245 xpad->last_out_packet = 0; in xpad_prepare_next_out_packet()
1247 pkt = &xpad->out_packets[xpad->last_out_packet]; in xpad_prepare_next_out_packet()
1248 if (pkt->pending) { in xpad_prepare_next_out_packet()
1249 dev_dbg(&xpad->intf->dev, in xpad_prepare_next_out_packet()
1250 "%s - found pending output packet %d\n", in xpad_prepare_next_out_packet()
1251 __func__, xpad->last_out_packet); in xpad_prepare_next_out_packet()
1258 memcpy(xpad->odata, packet->data, packet->len); in xpad_prepare_next_out_packet()
1259 xpad->irq_out->transfer_buffer_length = packet->len; in xpad_prepare_next_out_packet()
1260 packet->pending = false; in xpad_prepare_next_out_packet()
1267 /* Callers must hold xpad->odata_lock spinlock */
1272 if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { in xpad_try_sending_next_out_packet()
1273 usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); in xpad_try_sending_next_out_packet()
1274 error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); in xpad_try_sending_next_out_packet()
1276 dev_err(&xpad->intf->dev, in xpad_try_sending_next_out_packet()
1277 "%s - usb_submit_urb failed with result %d\n", in xpad_try_sending_next_out_packet()
1279 usb_unanchor_urb(xpad->irq_out); in xpad_try_sending_next_out_packet()
1280 return -EIO; in xpad_try_sending_next_out_packet()
1283 xpad->irq_out_active = true; in xpad_try_sending_next_out_packet()
1291 struct usb_xpad *xpad = urb->context; in xpad_irq_out()
1292 struct device *dev = &xpad->intf->dev; in xpad_irq_out()
1293 int status = urb->status; in xpad_irq_out()
1296 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad_irq_out()
1301 xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); in xpad_irq_out()
1304 case -ECONNRESET: in xpad_irq_out()
1305 case -ENOENT: in xpad_irq_out()
1306 case -ESHUTDOWN: in xpad_irq_out()
1308 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_out()
1310 xpad->irq_out_active = false; in xpad_irq_out()
1314 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_out()
1319 if (xpad->irq_out_active) { in xpad_irq_out()
1320 usb_anchor_urb(urb, &xpad->irq_out_anchor); in xpad_irq_out()
1324 "%s - usb_submit_urb failed with result %d\n", in xpad_irq_out()
1327 xpad->irq_out_active = false; in xpad_irq_out()
1337 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_output()
1340 init_usb_anchor(&xpad->irq_out_anchor); in xpad_init_output()
1342 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_init_output()
1343 GFP_KERNEL, &xpad->odata_dma); in xpad_init_output()
1344 if (!xpad->odata) in xpad_init_output()
1345 return -ENOMEM; in xpad_init_output()
1347 spin_lock_init(&xpad->odata_lock); in xpad_init_output()
1349 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); in xpad_init_output()
1350 if (!xpad->irq_out) { in xpad_init_output()
1351 error = -ENOMEM; in xpad_init_output()
1355 usb_fill_int_urb(xpad->irq_out, xpad->udev, in xpad_init_output()
1356 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), in xpad_init_output()
1357 xpad->odata, XPAD_PKT_LEN, in xpad_init_output()
1358 xpad_irq_out, xpad, ep_irq_out->bInterval); in xpad_init_output()
1359 xpad->irq_out->transfer_dma = xpad->odata_dma; in xpad_init_output()
1360 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_init_output()
1365 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); in xpad_init_output()
1371 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_stop_output()
1372 if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, in xpad_stop_output()
1374 dev_warn(&xpad->intf->dev, in xpad_stop_output()
1376 usb_kill_anchored_urbs(&xpad->irq_out_anchor); in xpad_stop_output()
1383 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_deinit_output()
1384 usb_free_urb(xpad->irq_out); in xpad_deinit_output()
1385 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_deinit_output()
1386 xpad->odata, xpad->odata_dma); in xpad_deinit_output()
1393 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad_inquiry_pad_presence()
1395 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad_inquiry_pad_presence()
1397 packet->data[0] = 0x08; in xpad_inquiry_pad_presence()
1398 packet->data[1] = 0x00; in xpad_inquiry_pad_presence()
1399 packet->data[2] = 0x0F; in xpad_inquiry_pad_presence()
1400 packet->data[3] = 0xC0; in xpad_inquiry_pad_presence()
1401 packet->data[4] = 0x00; in xpad_inquiry_pad_presence()
1402 packet->data[5] = 0x00; in xpad_inquiry_pad_presence()
1403 packet->data[6] = 0x00; in xpad_inquiry_pad_presence()
1404 packet->data[7] = 0x00; in xpad_inquiry_pad_presence()
1405 packet->data[8] = 0x00; in xpad_inquiry_pad_presence()
1406 packet->data[9] = 0x00; in xpad_inquiry_pad_presence()
1407 packet->data[10] = 0x00; in xpad_inquiry_pad_presence()
1408 packet->data[11] = 0x00; in xpad_inquiry_pad_presence()
1409 packet->len = 12; in xpad_inquiry_pad_presence()
1410 packet->pending = true; in xpad_inquiry_pad_presence()
1413 xpad->last_out_packet = -1; in xpad_inquiry_pad_presence()
1421 if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) { in xpad_start_xbox_one()
1428 error = usb_set_interface(xpad->udev, in xpad_start_xbox_one()
1431 dev_warn(&xpad->dev->dev, in xpad_start_xbox_one()
1436 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad_start_xbox_one()
1443 xpad->init_seq = 0; in xpad_start_xbox_one()
1450 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpadone_ack_mode_report()
1456 guard(spinlock_irqsave)(&xpad->odata_lock); in xpadone_ack_mode_report()
1458 packet->len = sizeof(mode_report_ack); in xpadone_ack_mode_report()
1459 memcpy(packet->data, mode_report_ack, packet->len); in xpadone_ack_mode_report()
1460 packet->data[2] = seq_num; in xpadone_ack_mode_report()
1461 packet->pending = true; in xpadone_ack_mode_report()
1464 xpad->last_out_packet = -1; in xpadone_ack_mode_report()
1472 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; in xpad_play_effect()
1476 if (effect->type != FF_RUMBLE) in xpad_play_effect()
1479 strong = effect->u.rumble.strong_magnitude; in xpad_play_effect()
1480 weak = effect->u.rumble.weak_magnitude; in xpad_play_effect()
1482 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad_play_effect()
1484 switch (xpad->xtype) { in xpad_play_effect()
1486 packet->data[0] = 0x00; in xpad_play_effect()
1487 packet->data[1] = 0x06; in xpad_play_effect()
1488 packet->data[2] = 0x00; in xpad_play_effect()
1489 packet->data[3] = strong / 256; /* left actuator */ in xpad_play_effect()
1490 packet->data[4] = 0x00; in xpad_play_effect()
1491 packet->data[5] = weak / 256; /* right actuator */ in xpad_play_effect()
1492 packet->len = 6; in xpad_play_effect()
1493 packet->pending = true; in xpad_play_effect()
1497 packet->data[0] = 0x00; in xpad_play_effect()
1498 packet->data[1] = 0x08; in xpad_play_effect()
1499 packet->data[2] = 0x00; in xpad_play_effect()
1500 packet->data[3] = strong / 256; /* left actuator? */ in xpad_play_effect()
1501 packet->data[4] = weak / 256; /* right actuator? */ in xpad_play_effect()
1502 packet->data[5] = 0x00; in xpad_play_effect()
1503 packet->data[6] = 0x00; in xpad_play_effect()
1504 packet->data[7] = 0x00; in xpad_play_effect()
1505 packet->len = 8; in xpad_play_effect()
1506 packet->pending = true; in xpad_play_effect()
1510 packet->data[0] = 0x00; in xpad_play_effect()
1511 packet->data[1] = 0x01; in xpad_play_effect()
1512 packet->data[2] = 0x0F; in xpad_play_effect()
1513 packet->data[3] = 0xC0; in xpad_play_effect()
1514 packet->data[4] = 0x00; in xpad_play_effect()
1515 packet->data[5] = strong / 256; in xpad_play_effect()
1516 packet->data[6] = weak / 256; in xpad_play_effect()
1517 packet->data[7] = 0x00; in xpad_play_effect()
1518 packet->data[8] = 0x00; in xpad_play_effect()
1519 packet->data[9] = 0x00; in xpad_play_effect()
1520 packet->data[10] = 0x00; in xpad_play_effect()
1521 packet->data[11] = 0x00; in xpad_play_effect()
1522 packet->len = 12; in xpad_play_effect()
1523 packet->pending = true; in xpad_play_effect()
1527 packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */ in xpad_play_effect()
1528 packet->data[1] = 0x00; in xpad_play_effect()
1529 packet->data[2] = xpad->odata_serial++; in xpad_play_effect()
1530 packet->data[3] = GIP_PL_LEN(9); in xpad_play_effect()
1531 packet->data[4] = 0x00; in xpad_play_effect()
1532 packet->data[5] = GIP_MOTOR_ALL; in xpad_play_effect()
1533 packet->data[6] = 0x00; /* left trigger */ in xpad_play_effect()
1534 packet->data[7] = 0x00; /* right trigger */ in xpad_play_effect()
1535 packet->data[8] = strong / 512; /* left actuator */ in xpad_play_effect()
1536 packet->data[9] = weak / 512; /* right actuator */ in xpad_play_effect()
1537 packet->data[10] = 0xFF; /* on period */ in xpad_play_effect()
1538 packet->data[11] = 0x00; /* off period */ in xpad_play_effect()
1539 packet->data[12] = 0xFF; /* repeat count */ in xpad_play_effect()
1540 packet->len = 13; in xpad_play_effect()
1541 packet->pending = true; in xpad_play_effect()
1545 dev_dbg(&xpad->dev->dev, in xpad_play_effect()
1546 "%s - rumble command sent to unsupported xpad type: %d\n", in xpad_play_effect()
1547 __func__, xpad->xtype); in xpad_play_effect()
1548 return -EINVAL; in xpad_play_effect()
1556 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_ff()
1559 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); in xpad_init_ff()
1561 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); in xpad_init_ff()
1585 * 2: 1/top-left blink, then on
1586 * 3: 2/top-right blink, then on
1587 * 4: 3/bottom-left blink, then on
1588 * 5: 4/bottom-right blink, then on
1589 * 6: 1/top-left on
1590 * 7: 2/top-right on
1591 * 8: 3/bottom-left on
1592 * 9: 4/bottom-right on
1603 &xpad->out_packets[XPAD_OUT_LED_IDX]; in xpad_send_led_command()
1607 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad_send_led_command()
1609 switch (xpad->xtype) { in xpad_send_led_command()
1611 packet->data[0] = 0x01; in xpad_send_led_command()
1612 packet->data[1] = 0x03; in xpad_send_led_command()
1613 packet->data[2] = command; in xpad_send_led_command()
1614 packet->len = 3; in xpad_send_led_command()
1615 packet->pending = true; in xpad_send_led_command()
1619 packet->data[0] = 0x00; in xpad_send_led_command()
1620 packet->data[1] = 0x00; in xpad_send_led_command()
1621 packet->data[2] = 0x08; in xpad_send_led_command()
1622 packet->data[3] = 0x40 + command; in xpad_send_led_command()
1623 packet->data[4] = 0x00; in xpad_send_led_command()
1624 packet->data[5] = 0x00; in xpad_send_led_command()
1625 packet->data[6] = 0x00; in xpad_send_led_command()
1626 packet->data[7] = 0x00; in xpad_send_led_command()
1627 packet->data[8] = 0x00; in xpad_send_led_command()
1628 packet->data[9] = 0x00; in xpad_send_led_command()
1629 packet->data[10] = 0x00; in xpad_send_led_command()
1630 packet->data[11] = 0x00; in xpad_send_led_command()
1631 packet->len = 12; in xpad_send_led_command()
1632 packet->pending = true; in xpad_send_led_command()
1645 led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); in xpad_identify_controller()
1654 xpad_send_led_command(xpad_led->xpad, value); in xpad_led_set()
1663 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) in xpad_led_probe()
1666 xpad->led = led = kzalloc(sizeof(*led), GFP_KERNEL); in xpad_led_probe()
1668 return -ENOMEM; in xpad_led_probe()
1670 xpad->pad_nr = ida_alloc(&xpad_pad_seq, GFP_KERNEL); in xpad_led_probe()
1671 if (xpad->pad_nr < 0) { in xpad_led_probe()
1672 error = xpad->pad_nr; in xpad_led_probe()
1676 snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); in xpad_led_probe()
1677 led->xpad = xpad; in xpad_led_probe()
1679 led_cdev = &led->led_cdev; in xpad_led_probe()
1680 led_cdev->name = led->name; in xpad_led_probe()
1681 led_cdev->brightness_set = xpad_led_set; in xpad_led_probe()
1682 led_cdev->flags = LED_CORE_SUSPENDRESUME; in xpad_led_probe()
1684 error = led_classdev_register(&xpad->udev->dev, led_cdev); in xpad_led_probe()
1693 ida_free(&xpad_pad_seq, xpad->pad_nr); in xpad_led_probe()
1696 xpad->led = NULL; in xpad_led_probe()
1702 struct xpad_led *xpad_led = xpad->led; in xpad_led_disconnect()
1705 led_classdev_unregister(&xpad_led->led_cdev); in xpad_led_disconnect()
1706 ida_free(&xpad_pad_seq, xpad->pad_nr); in xpad_led_disconnect()
1719 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) in xpad_start_input()
1720 return -EIO; in xpad_start_input()
1722 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_start_input()
1725 usb_kill_urb(xpad->irq_in); in xpad_start_input()
1729 if (xpad->xtype == XTYPE_XBOX360) { in xpad_start_input()
1731 * Some third-party controllers Xbox 360-style controllers in xpad_start_input()
1736 error = usb_control_msg_recv(xpad->udev, 0, in xpad_start_input()
1746 dev_warn(&xpad->dev->dev, in xpad_start_input()
1756 usb_kill_urb(xpad->irq_in); in xpad_stop_input()
1762 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad360w_poweroff_controller()
1764 guard(spinlock_irqsave)(&xpad->odata_lock); in xpad360w_poweroff_controller()
1766 packet->data[0] = 0x00; in xpad360w_poweroff_controller()
1767 packet->data[1] = 0x00; in xpad360w_poweroff_controller()
1768 packet->data[2] = 0x08; in xpad360w_poweroff_controller()
1769 packet->data[3] = 0xC0; in xpad360w_poweroff_controller()
1770 packet->data[4] = 0x00; in xpad360w_poweroff_controller()
1771 packet->data[5] = 0x00; in xpad360w_poweroff_controller()
1772 packet->data[6] = 0x00; in xpad360w_poweroff_controller()
1773 packet->data[7] = 0x00; in xpad360w_poweroff_controller()
1774 packet->data[8] = 0x00; in xpad360w_poweroff_controller()
1775 packet->data[9] = 0x00; in xpad360w_poweroff_controller()
1776 packet->data[10] = 0x00; in xpad360w_poweroff_controller()
1777 packet->data[11] = 0x00; in xpad360w_poweroff_controller()
1778 packet->len = 12; in xpad360w_poweroff_controller()
1779 packet->pending = true; in xpad360w_poweroff_controller()
1782 xpad->last_out_packet = -1; in xpad360w_poweroff_controller()
1790 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); in xpad360w_start_input()
1792 return -EIO; in xpad360w_start_input()
1803 usb_kill_urb(xpad->irq_in); in xpad360w_start_input()
1812 usb_kill_urb(xpad->irq_in); in xpad360w_stop_input()
1815 flush_work(&xpad->work); in xpad360w_stop_input()
1841 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); in xpad_set_up_abs()
1845 if (xpad->xtype == XTYPE_XBOXONE) in xpad_set_up_abs()
1851 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ in xpad_set_up_abs()
1852 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); in xpad_set_up_abs()
1865 if (xpad->input_created) { in xpad_deinit_input()
1866 xpad->input_created = false; in xpad_deinit_input()
1868 input_unregister_device(xpad->dev); in xpad_deinit_input()
1879 return -ENOMEM; in xpad_init_input()
1881 xpad->dev = input_dev; in xpad_init_input()
1882 input_dev->name = xpad->name; in xpad_init_input()
1883 input_dev->phys = xpad->phys; in xpad_init_input()
1884 usb_to_input_id(xpad->udev, &input_dev->id); in xpad_init_input()
1886 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1888 input_dev->id.product = 0x02a1; in xpad_init_input()
1891 input_dev->dev.parent = &xpad->intf->dev; in xpad_init_input()
1895 if (xpad->xtype != XTYPE_XBOX360W) { in xpad_init_input()
1896 input_dev->open = xpad_open; in xpad_init_input()
1897 input_dev->close = xpad_close; in xpad_init_input()
1900 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_init_input()
1910 /* set up model-specific ones */ in xpad_init_input()
1911 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || in xpad_init_input()
1912 xpad->xtype == XTYPE_XBOXONE) { in xpad_init_input()
1915 if (xpad->mapping & MAP_SELECT_BUTTON) in xpad_init_input()
1922 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_init_input()
1929 if (xpad->mapping & MAP_PADDLES) { in xpad_init_input()
1940 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad_init_input()
1941 xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1946 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_init_input()
1956 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_init_input()
1967 error = input_register_device(xpad->dev); in xpad_init_input()
1971 xpad->input_created = true; in xpad_init_input()
1990 if (intf->cur_altsetting->desc.bNumEndpoints != 2) in xpad_probe()
1991 return -ENODEV; in xpad_probe()
1994 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && in xpad_probe()
1995 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) in xpad_probe()
2001 return -ENOMEM; in xpad_probe()
2003 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); in xpad_probe()
2004 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); in xpad_probe()
2006 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, in xpad_probe()
2007 GFP_KERNEL, &xpad->idata_dma); in xpad_probe()
2008 if (!xpad->idata) { in xpad_probe()
2009 error = -ENOMEM; in xpad_probe()
2013 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); in xpad_probe()
2014 if (!xpad->irq_in) { in xpad_probe()
2015 error = -ENOMEM; in xpad_probe()
2019 xpad->udev = udev; in xpad_probe()
2020 xpad->intf = intf; in xpad_probe()
2021 xpad->mapping = xpad_device[i].mapping; in xpad_probe()
2022 xpad->xtype = xpad_device[i].xtype; in xpad_probe()
2023 xpad->name = xpad_device[i].name; in xpad_probe()
2024 xpad->packet_type = PKT_XB; in xpad_probe()
2025 INIT_WORK(&xpad->work, xpad_presence_work); in xpad_probe()
2027 if (xpad->xtype == XTYPE_UNKNOWN) { in xpad_probe()
2028 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { in xpad_probe()
2029 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) in xpad_probe()
2030 xpad->xtype = XTYPE_XBOX360W; in xpad_probe()
2031 else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) in xpad_probe()
2032 xpad->xtype = XTYPE_XBOXONE; in xpad_probe()
2034 xpad->xtype = XTYPE_XBOX360; in xpad_probe()
2036 xpad->xtype = XTYPE_XBOX; in xpad_probe()
2040 xpad->mapping |= MAP_DPAD_TO_BUTTONS; in xpad_probe()
2042 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; in xpad_probe()
2044 xpad->mapping |= MAP_STICKS_TO_NULL; in xpad_probe()
2047 if (xpad->xtype == XTYPE_XBOXONE && in xpad_probe()
2048 intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) { in xpad_probe()
2054 error = -ENODEV; in xpad_probe()
2062 &intf->cur_altsetting->endpoint[i].desc; in xpad_probe()
2073 error = -ENODEV; in xpad_probe()
2081 usb_fill_int_urb(xpad->irq_in, udev, in xpad_probe()
2082 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), in xpad_probe()
2083 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, in xpad_probe()
2084 xpad, ep_irq_in->bInterval); in xpad_probe()
2085 xpad->irq_in->transfer_dma = xpad->idata_dma; in xpad_probe()
2086 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_probe()
2090 /* Packet type detection */ in xpad_probe()
2091 if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ in xpad_probe()
2092 if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { in xpad_probe()
2096 xpad->packet_type = PKT_XBE1; in xpad_probe()
2097 } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { in xpad_probe()
2102 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { in xpad_probe()
2106 xpad->packet_type = PKT_XBE2_FW_OLD; in xpad_probe()
2107 } else if (le16_to_cpu(udev->descriptor.bcdDevice) < in xpad_probe()
2112 xpad->packet_type = PKT_XBE2_FW_5_EARLY; in xpad_probe()
2117 xpad->packet_type = PKT_XBE2_FW_5_11; in xpad_probe()
2122 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_probe()
2124 * Submit the int URB immediately rather than waiting for open in xpad_probe()
2140 udev->quirks |= USB_QUIRK_RESET_RESUME; in xpad_probe()
2151 usb_free_urb(xpad->irq_in); in xpad_probe()
2153 usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); in xpad_probe()
2163 if (xpad->xtype == XTYPE_XBOX360W) in xpad_disconnect()
2169 * Now that both input device and LED device are gone we can in xpad_disconnect()
2176 usb_free_urb(xpad->irq_in); in xpad_disconnect()
2177 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_disconnect()
2178 xpad->idata, xpad->idata_dma); in xpad_disconnect()
2188 struct input_dev *input = xpad->dev; in xpad_suspend() local
2190 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_suspend()
2192 * Wireless controllers always listen to input so in xpad_suspend()
2204 if (auto_poweroff && xpad->pad_present) in xpad_suspend()
2207 guard(mutex)(&input->mutex); in xpad_suspend()
2209 if (input_device_enabled(input)) in xpad_suspend()
2221 struct input_dev *input = xpad->dev; in xpad_resume() local
2223 if (xpad->xtype == XTYPE_XBOX360W) in xpad_resume()
2226 guard(mutex)(&input->mutex); in xpad_resume()
2228 if (input_device_enabled(input)) in xpad_resume()
2231 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_resume()
2235 * blink until somebody opens the input device again. in xpad_resume()
2254 MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");