Lines Matching +full:controller +full:- +full:data
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
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");
130 { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
136 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
139 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
140 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
141 { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
142 { 0x045e, 0x0288, "Microsoft Xbox Controller S v2", 0, XTYPE_XBOX },
143 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
144 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
145 { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
147 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
148 { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
149 { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE },
150 { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
151 { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
153 { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
154 { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
158 { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
159 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
160 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
163 { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
164 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
165 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
166 { 0x05fe, 0x3030, "Chic Controller", 0, XTYPE_XBOX },
167 { 0x05fe, 0x3031, "Chic Controller", 0, XTYPE_XBOX },
173 { 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX },
181 { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
182 { 0x0738, 0x4586, "Mad Catz MicroCon Wireless Controller", 0, XTYPE_XBOX },
185 { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
187 { 0x0738, 0x4726, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
190 …{ 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX…
197 { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
200 { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
201 { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
206 { 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
207 { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
209 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
210 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
211 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
213 { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
215 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
217 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
218 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
219 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
220 { 0x0e6f, 0x0008, "After Glow Pro Controller", 0, XTYPE_XBOX },
223 { 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
224 { 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 },
225 { 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
226 { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
227 { 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
228 { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
229 { 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE },
231 { 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
232 { 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
233 { 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
236 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
240 { 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
241 { 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
242 { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
243 { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
244 { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
245 { 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
246 { 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
247 { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE },
248 { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
249 { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
250 { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
251 { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 },
253 { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 },
255 { 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 },
270 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
271 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
272 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
275 { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
277 { 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 },
282 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
284 { 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
285 { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
290 { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
291 { 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
292 { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
296 { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 },
300 { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
304 { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
314 …{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XB…
325 { 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 },
326 { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
327 { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
333 { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
334 { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
335 { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
336 { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
338 { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
339 { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
340 { 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
342 { 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
343 { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
345 { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
347 { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
352 { 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
354 { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
355 { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
357 { 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
362 { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
363 { 0x2dc8, 0x3106, "8BitDo Pro 2 Wired Controller", 0, XTYPE_XBOX360 },
370 { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
373 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
374 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
381 -1 /* terminating entry */
387 -1 /* terminating entry */
392 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
393 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
394 -1 /* terminating entry */
400 -1
403 static const signed short xpad360_btn[] = { /* buttons for x360 controller */
406 -1
412 -1 /* terminating entry */
417 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
418 -1 /* terminating entry */
424 -1
427 /* used when the controller has extra paddle buttons */
431 -1 /* terminating entry */
435 * Xbox 360 has a vendor-specific class, so we cannot match it with only
450 /* The Xbox One controller uses subclass 71 and protocol 208. */
461 { USB_INTERFACE_INFO('X', 'B', 0) }, /* Xbox USB-IF not-approved class */
462 XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 controller */
468 XPAD_XBOX360_VENDOR(0x046d), /* Logitech Xbox 360-style controllers */
469 XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
475 XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
502 XPAD_XBOX360_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller */
503 XPAD_XBOXONE_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller for Xbox */
507 XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
518 const u8 *data; member
526 .data = (_data), \
533 * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
534 * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
554 * which is a no-op for N < 128
584 * initialize the controller that was previously used in
592 * This packet is required to get additional input data
594 * We mostly do this right now to get paddle data
672 u8 data[XPAD_PKT_LEN]; member
694 unsigned char *idata; /* input data */
701 unsigned char *odata; /* output data */
715 int mapping; /* map d-pad to buttons or to axes */
732 * Completes a request by converting the data into events for the
736 * http://euc.jp/periphs/xbox-controller.ja.html
738 static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad_process_packet() argument
740 struct input_dev *dev = xpad->dev; in xpad_process_packet()
742 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_process_packet()
745 (__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad_process_packet()
747 ~(__s16) le16_to_cpup((__le16 *)(data + 14))); in xpad_process_packet()
751 (__s16) le16_to_cpup((__le16 *)(data + 16))); in xpad_process_packet()
753 ~(__s16) le16_to_cpup((__le16 *)(data + 18))); in xpad_process_packet()
757 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_process_packet()
758 input_report_key(dev, BTN_TL2, data[10]); in xpad_process_packet()
759 input_report_key(dev, BTN_TR2, data[11]); in xpad_process_packet()
761 input_report_abs(dev, ABS_Z, data[10]); in xpad_process_packet()
762 input_report_abs(dev, ABS_RZ, data[11]); in xpad_process_packet()
766 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_process_packet()
768 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad_process_packet()
769 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad_process_packet()
770 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad_process_packet()
771 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad_process_packet()
774 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad_process_packet()
776 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad_process_packet()
780 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad_process_packet()
781 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad_process_packet()
782 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad_process_packet()
783 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad_process_packet()
786 input_report_key(dev, BTN_A, data[4]); in xpad_process_packet()
787 input_report_key(dev, BTN_B, data[5]); in xpad_process_packet()
788 input_report_key(dev, BTN_X, data[6]); in xpad_process_packet()
789 input_report_key(dev, BTN_Y, data[7]); in xpad_process_packet()
792 input_report_key(dev, BTN_C, data[8]); in xpad_process_packet()
793 input_report_key(dev, BTN_Z, data[9]); in xpad_process_packet()
802 * Completes a request by converting the data into events for the
803 * input subsystem. It is version for xbox 360 controller
810 u16 cmd, unsigned char *data) in xpad360_process_packet() argument
812 /* valid pad data */ in xpad360_process_packet()
813 if (data[0] != 0x00) in xpad360_process_packet()
817 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad360_process_packet()
819 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad360_process_packet()
820 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad360_process_packet()
821 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad360_process_packet()
822 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad360_process_packet()
831 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad360_process_packet()
832 xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
834 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad360_process_packet()
836 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad360_process_packet()
840 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad360_process_packet()
841 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad360_process_packet()
844 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad360_process_packet()
845 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad360_process_packet()
848 input_report_key(dev, BTN_A, data[3] & BIT(4)); in xpad360_process_packet()
849 input_report_key(dev, BTN_B, data[3] & BIT(5)); in xpad360_process_packet()
850 input_report_key(dev, BTN_X, data[3] & BIT(6)); in xpad360_process_packet()
851 input_report_key(dev, BTN_Y, data[3] & BIT(7)); in xpad360_process_packet()
852 input_report_key(dev, BTN_TL, data[3] & BIT(0)); in xpad360_process_packet()
853 input_report_key(dev, BTN_TR, data[3] & BIT(1)); in xpad360_process_packet()
854 input_report_key(dev, BTN_MODE, data[3] & BIT(2)); in xpad360_process_packet()
856 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad360_process_packet()
859 (__s16) le16_to_cpup((__le16 *)(data + 6))); in xpad360_process_packet()
861 ~(__s16) le16_to_cpup((__le16 *)(data + 8))); in xpad360_process_packet()
865 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpad360_process_packet()
867 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad360_process_packet()
871 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad360_process_packet()
872 input_report_key(dev, BTN_TL2, data[4]); in xpad360_process_packet()
873 input_report_key(dev, BTN_TR2, data[5]); in xpad360_process_packet()
875 input_report_abs(dev, ABS_Z, data[4]); in xpad360_process_packet()
876 input_report_abs(dev, ABS_RZ, data[5]); in xpad360_process_packet()
882 if (xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
883 if (xpad->mode_btn_down_ts > 0 && xpad->pad_present && in xpad360_process_packet()
884 ((ktime_get_seconds() - xpad->mode_btn_down_ts) >= in xpad360_process_packet()
887 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
892 if (data[3] & BIT(2)) in xpad360_process_packet()
893 xpad->mode_btn_down_ts = ktime_get_seconds(); in xpad360_process_packet()
895 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
904 if (xpad->pad_present) { in xpad_presence_work()
908 dev_err(&xpad->dev->dev, in xpad_presence_work()
911 rcu_assign_pointer(xpad->x360w_dev, xpad->dev); in xpad_presence_work()
914 RCU_INIT_POINTER(xpad->x360w_dev, NULL); in xpad_presence_work()
927 * Completes a request by converting the data into events for the
928 * input subsystem. It is version for xbox 360 wireless controller.
931 * 00.1 - Status change: The controller or headset has connected/disconnected
933 * 01.7 - Controller present
934 * 01.6 - Headset present
935 * 01.1 - Pad state (Bytes 4+) valid
938 static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad360w_process_packet() argument
944 if (data[0] & 0x08) { in xpad360w_process_packet()
945 present = (data[1] & 0x80) != 0; in xpad360w_process_packet()
947 if (xpad->pad_present != present) { in xpad360w_process_packet()
948 xpad->pad_present = present; in xpad360w_process_packet()
949 schedule_work(&xpad->work); in xpad360w_process_packet()
953 /* Valid pad data */ in xpad360w_process_packet()
954 if (data[1] != 0x1) in xpad360w_process_packet()
958 dev = rcu_dereference(xpad->x360w_dev); in xpad360w_process_packet()
960 xpad360_process_packet(xpad, dev, cmd, &data[4]); in xpad360w_process_packet()
967 * Completes a request by converting the data into events for the
968 * input subsystem. This version is for the Xbox One controller.
973 static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpadone_process_packet() argument
975 struct input_dev *dev = xpad->dev; in xpadone_process_packet()
979 if (data[0] == GIP_CMD_VIRTUAL_KEY) { in xpadone_process_packet()
981 * The Xbox One S controller requires these reports to be in xpadone_process_packet()
985 if (data[1] == (GIP_OPT_ACK | GIP_OPT_INTERNAL)) in xpadone_process_packet()
986 xpadone_ack_mode_report(xpad, data[2]); in xpadone_process_packet()
988 input_report_key(dev, BTN_MODE, data[4] & GENMASK(1, 0)); in xpadone_process_packet()
992 } else if (data[0] == GIP_CMD_FIRMWARE) { in xpadone_process_packet()
994 if (xpad->packet_type == PKT_XBE2_FW_5_11) { in xpadone_process_packet()
995 /* Mute paddles if controller is in a custom profile slot in xpadone_process_packet()
999 if (data[19] != 0) in xpadone_process_packet()
1000 data[18] = 0; in xpadone_process_packet()
1003 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
1004 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
1005 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
1006 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1010 } else if (data[0] == GIP_CMD_INPUT) { /* The main valid packet type for inputs */ in xpadone_process_packet()
1012 input_report_key(dev, BTN_START, data[4] & BIT(2)); in xpadone_process_packet()
1013 input_report_key(dev, BTN_SELECT, data[4] & BIT(3)); in xpadone_process_packet()
1014 if (xpad->mapping & MAP_SELECT_BUTTON) in xpadone_process_packet()
1015 input_report_key(dev, KEY_RECORD, data[22] & BIT(0)); in xpadone_process_packet()
1018 input_report_key(dev, BTN_A, data[4] & BIT(4)); in xpadone_process_packet()
1019 input_report_key(dev, BTN_B, data[4] & BIT(5)); in xpadone_process_packet()
1020 input_report_key(dev, BTN_X, data[4] & BIT(6)); in xpadone_process_packet()
1021 input_report_key(dev, BTN_Y, data[4] & BIT(7)); in xpadone_process_packet()
1024 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpadone_process_packet()
1026 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & BIT(2)); in xpadone_process_packet()
1027 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & BIT(3)); in xpadone_process_packet()
1028 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & BIT(0)); in xpadone_process_packet()
1029 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & BIT(1)); in xpadone_process_packet()
1032 !!(data[5] & 0x08) - !!(data[5] & 0x04)); in xpadone_process_packet()
1034 !!(data[5] & 0x02) - !!(data[5] & 0x01)); in xpadone_process_packet()
1038 input_report_key(dev, BTN_TL, data[5] & BIT(4)); in xpadone_process_packet()
1039 input_report_key(dev, BTN_TR, data[5] & BIT(5)); in xpadone_process_packet()
1042 input_report_key(dev, BTN_THUMBL, data[5] & BIT(6)); in xpadone_process_packet()
1043 input_report_key(dev, BTN_THUMBR, data[5] & BIT(7)); in xpadone_process_packet()
1045 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpadone_process_packet()
1048 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpadone_process_packet()
1050 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpadone_process_packet()
1054 (__s16) le16_to_cpup((__le16 *)(data + 14))); in xpadone_process_packet()
1056 ~(__s16) le16_to_cpup((__le16 *)(data + 16))); in xpadone_process_packet()
1060 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpadone_process_packet()
1062 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1064 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1067 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1069 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1072 /* Profile button has a value of 0-3, so it is reported as an axis */ in xpadone_process_packet()
1073 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpadone_process_packet()
1074 input_report_abs(dev, ABS_PROFILE, data[34]); in xpadone_process_packet()
1078 if (xpad->mapping & MAP_PADDLES) { in xpadone_process_packet()
1079 if (xpad->packet_type == PKT_XBE1) { in xpadone_process_packet()
1080 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1084 if (memcmp(&data[4], &data[18], 2) != 0) in xpadone_process_packet()
1085 data[32] = 0; in xpadone_process_packet()
1087 /* OG Elite Series Controller paddle bits */ in xpadone_process_packet()
1088 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[32] & BIT(1)); in xpadone_process_packet()
1089 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[32] & BIT(3)); in xpadone_process_packet()
1090 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[32] & BIT(0)); in xpadone_process_packet()
1091 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[32] & BIT(2)); in xpadone_process_packet()
1092 } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { in xpadone_process_packet()
1093 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1097 if (data[19] != 0) in xpadone_process_packet()
1098 data[18] = 0; in xpadone_process_packet()
1101 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
1102 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
1103 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
1104 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1105 } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { in xpadone_process_packet()
1106 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1110 if (data[23] != 0) in xpadone_process_packet()
1111 data[22] = 0; in xpadone_process_packet()
1116 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[22] & BIT(0)); in xpadone_process_packet()
1117 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[22] & BIT(1)); in xpadone_process_packet()
1118 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[22] & BIT(2)); in xpadone_process_packet()
1119 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[22] & BIT(3)); in xpadone_process_packet()
1132 struct usb_xpad *xpad = urb->context; in xpad_irq_in()
1133 struct device *dev = &xpad->intf->dev; in xpad_irq_in()
1136 status = urb->status; in xpad_irq_in()
1142 case -ECONNRESET: in xpad_irq_in()
1143 case -ENOENT: in xpad_irq_in()
1144 case -ESHUTDOWN: in xpad_irq_in()
1146 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_in()
1150 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_in()
1155 switch (xpad->xtype) { in xpad_irq_in()
1157 xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); in xpad_irq_in()
1160 xpad360w_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1163 xpadone_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1166 xpad_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1172 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", in xpad_irq_in()
1176 /* Callers must hold xpad->odata_lock spinlock */
1181 if (xpad->xtype != XTYPE_XBOXONE) in xpad_prepare_next_init_packet()
1185 while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { in xpad_prepare_next_init_packet()
1186 init_packet = &xboxone_init_packets[xpad->init_seq++]; in xpad_prepare_next_init_packet()
1188 if (init_packet->idVendor != 0 && in xpad_prepare_next_init_packet()
1189 init_packet->idVendor != xpad->dev->id.vendor) in xpad_prepare_next_init_packet()
1192 if (init_packet->idProduct != 0 && in xpad_prepare_next_init_packet()
1193 init_packet->idProduct != xpad->dev->id.product) in xpad_prepare_next_init_packet()
1197 memcpy(xpad->odata, init_packet->data, init_packet->len); in xpad_prepare_next_init_packet()
1198 xpad->irq_out->transfer_buffer_length = init_packet->len; in xpad_prepare_next_init_packet()
1201 xpad->odata[2] = xpad->odata_serial++; in xpad_prepare_next_init_packet()
1208 /* Callers must hold xpad->odata_lock spinlock */
1219 if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) in xpad_prepare_next_out_packet()
1220 xpad->last_out_packet = 0; in xpad_prepare_next_out_packet()
1222 pkt = &xpad->out_packets[xpad->last_out_packet]; in xpad_prepare_next_out_packet()
1223 if (pkt->pending) { in xpad_prepare_next_out_packet()
1224 dev_dbg(&xpad->intf->dev, in xpad_prepare_next_out_packet()
1225 "%s - found pending output packet %d\n", in xpad_prepare_next_out_packet()
1226 __func__, xpad->last_out_packet); in xpad_prepare_next_out_packet()
1233 memcpy(xpad->odata, packet->data, packet->len); in xpad_prepare_next_out_packet()
1234 xpad->irq_out->transfer_buffer_length = packet->len; in xpad_prepare_next_out_packet()
1235 packet->pending = false; in xpad_prepare_next_out_packet()
1242 /* Callers must hold xpad->odata_lock spinlock */
1247 if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { in xpad_try_sending_next_out_packet()
1248 usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); in xpad_try_sending_next_out_packet()
1249 error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); in xpad_try_sending_next_out_packet()
1251 dev_err(&xpad->intf->dev, in xpad_try_sending_next_out_packet()
1252 "%s - usb_submit_urb failed with result %d\n", in xpad_try_sending_next_out_packet()
1254 usb_unanchor_urb(xpad->irq_out); in xpad_try_sending_next_out_packet()
1255 return -EIO; in xpad_try_sending_next_out_packet()
1258 xpad->irq_out_active = true; in xpad_try_sending_next_out_packet()
1266 struct usb_xpad *xpad = urb->context; in xpad_irq_out()
1267 struct device *dev = &xpad->intf->dev; in xpad_irq_out()
1268 int status = urb->status; in xpad_irq_out()
1272 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_irq_out()
1277 xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); in xpad_irq_out()
1280 case -ECONNRESET: in xpad_irq_out()
1281 case -ENOENT: in xpad_irq_out()
1282 case -ESHUTDOWN: in xpad_irq_out()
1284 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_out()
1286 xpad->irq_out_active = false; in xpad_irq_out()
1290 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_out()
1295 if (xpad->irq_out_active) { in xpad_irq_out()
1296 usb_anchor_urb(urb, &xpad->irq_out_anchor); in xpad_irq_out()
1300 "%s - usb_submit_urb failed with result %d\n", in xpad_irq_out()
1303 xpad->irq_out_active = false; in xpad_irq_out()
1307 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_irq_out()
1315 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_output()
1318 init_usb_anchor(&xpad->irq_out_anchor); in xpad_init_output()
1320 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_init_output()
1321 GFP_KERNEL, &xpad->odata_dma); in xpad_init_output()
1322 if (!xpad->odata) in xpad_init_output()
1323 return -ENOMEM; in xpad_init_output()
1325 spin_lock_init(&xpad->odata_lock); in xpad_init_output()
1327 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); in xpad_init_output()
1328 if (!xpad->irq_out) { in xpad_init_output()
1329 error = -ENOMEM; in xpad_init_output()
1333 usb_fill_int_urb(xpad->irq_out, xpad->udev, in xpad_init_output()
1334 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), in xpad_init_output()
1335 xpad->odata, XPAD_PKT_LEN, in xpad_init_output()
1336 xpad_irq_out, xpad, ep_irq_out->bInterval); in xpad_init_output()
1337 xpad->irq_out->transfer_dma = xpad->odata_dma; in xpad_init_output()
1338 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_init_output()
1343 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); in xpad_init_output()
1349 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_stop_output()
1350 if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, in xpad_stop_output()
1352 dev_warn(&xpad->intf->dev, in xpad_stop_output()
1354 usb_kill_anchored_urbs(&xpad->irq_out_anchor); in xpad_stop_output()
1361 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_deinit_output()
1362 usb_free_urb(xpad->irq_out); in xpad_deinit_output()
1363 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_deinit_output()
1364 xpad->odata, xpad->odata_dma); in xpad_deinit_output()
1371 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad_inquiry_pad_presence()
1375 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1377 packet->data[0] = 0x08; in xpad_inquiry_pad_presence()
1378 packet->data[1] = 0x00; in xpad_inquiry_pad_presence()
1379 packet->data[2] = 0x0F; in xpad_inquiry_pad_presence()
1380 packet->data[3] = 0xC0; in xpad_inquiry_pad_presence()
1381 packet->data[4] = 0x00; in xpad_inquiry_pad_presence()
1382 packet->data[5] = 0x00; in xpad_inquiry_pad_presence()
1383 packet->data[6] = 0x00; in xpad_inquiry_pad_presence()
1384 packet->data[7] = 0x00; in xpad_inquiry_pad_presence()
1385 packet->data[8] = 0x00; in xpad_inquiry_pad_presence()
1386 packet->data[9] = 0x00; in xpad_inquiry_pad_presence()
1387 packet->data[10] = 0x00; in xpad_inquiry_pad_presence()
1388 packet->data[11] = 0x00; in xpad_inquiry_pad_presence()
1389 packet->len = 12; in xpad_inquiry_pad_presence()
1390 packet->pending = true; in xpad_inquiry_pad_presence()
1393 xpad->last_out_packet = -1; in xpad_inquiry_pad_presence()
1396 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1406 if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) { in xpad_start_xbox_one()
1410 * Controller for Series X|S (0x20d6:0x200e) to report the in xpad_start_xbox_one()
1413 retval = usb_set_interface(xpad->udev, in xpad_start_xbox_one()
1416 dev_warn(&xpad->dev->dev, in xpad_start_xbox_one()
1421 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1428 xpad->init_seq = 0; in xpad_start_xbox_one()
1431 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1440 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpadone_ack_mode_report()
1446 spin_lock_irqsave(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1448 packet->len = sizeof(mode_report_ack); in xpadone_ack_mode_report()
1449 memcpy(packet->data, mode_report_ack, packet->len); in xpadone_ack_mode_report()
1450 packet->data[2] = seq_num; in xpadone_ack_mode_report()
1451 packet->pending = true; in xpadone_ack_mode_report()
1454 xpad->last_out_packet = -1; in xpadone_ack_mode_report()
1457 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1461 static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) in xpad_play_effect() argument
1464 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; in xpad_play_effect()
1470 if (effect->type != FF_RUMBLE) in xpad_play_effect()
1473 strong = effect->u.rumble.strong_magnitude; in xpad_play_effect()
1474 weak = effect->u.rumble.weak_magnitude; in xpad_play_effect()
1476 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_play_effect()
1478 switch (xpad->xtype) { in xpad_play_effect()
1480 packet->data[0] = 0x00; in xpad_play_effect()
1481 packet->data[1] = 0x06; in xpad_play_effect()
1482 packet->data[2] = 0x00; in xpad_play_effect()
1483 packet->data[3] = strong / 256; /* left actuator */ in xpad_play_effect()
1484 packet->data[4] = 0x00; in xpad_play_effect()
1485 packet->data[5] = weak / 256; /* right actuator */ in xpad_play_effect()
1486 packet->len = 6; in xpad_play_effect()
1487 packet->pending = true; in xpad_play_effect()
1491 packet->data[0] = 0x00; in xpad_play_effect()
1492 packet->data[1] = 0x08; in xpad_play_effect()
1493 packet->data[2] = 0x00; in xpad_play_effect()
1494 packet->data[3] = strong / 256; /* left actuator? */ in xpad_play_effect()
1495 packet->data[4] = weak / 256; /* right actuator? */ in xpad_play_effect()
1496 packet->data[5] = 0x00; in xpad_play_effect()
1497 packet->data[6] = 0x00; in xpad_play_effect()
1498 packet->data[7] = 0x00; in xpad_play_effect()
1499 packet->len = 8; in xpad_play_effect()
1500 packet->pending = true; in xpad_play_effect()
1504 packet->data[0] = 0x00; in xpad_play_effect()
1505 packet->data[1] = 0x01; in xpad_play_effect()
1506 packet->data[2] = 0x0F; in xpad_play_effect()
1507 packet->data[3] = 0xC0; in xpad_play_effect()
1508 packet->data[4] = 0x00; in xpad_play_effect()
1509 packet->data[5] = strong / 256; in xpad_play_effect()
1510 packet->data[6] = weak / 256; in xpad_play_effect()
1511 packet->data[7] = 0x00; in xpad_play_effect()
1512 packet->data[8] = 0x00; in xpad_play_effect()
1513 packet->data[9] = 0x00; in xpad_play_effect()
1514 packet->data[10] = 0x00; in xpad_play_effect()
1515 packet->data[11] = 0x00; in xpad_play_effect()
1516 packet->len = 12; in xpad_play_effect()
1517 packet->pending = true; in xpad_play_effect()
1521 packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */ in xpad_play_effect()
1522 packet->data[1] = 0x00; in xpad_play_effect()
1523 packet->data[2] = xpad->odata_serial++; in xpad_play_effect()
1524 packet->data[3] = GIP_PL_LEN(9); in xpad_play_effect()
1525 packet->data[4] = 0x00; in xpad_play_effect()
1526 packet->data[5] = GIP_MOTOR_ALL; in xpad_play_effect()
1527 packet->data[6] = 0x00; /* left trigger */ in xpad_play_effect()
1528 packet->data[7] = 0x00; /* right trigger */ in xpad_play_effect()
1529 packet->data[8] = strong / 512; /* left actuator */ in xpad_play_effect()
1530 packet->data[9] = weak / 512; /* right actuator */ in xpad_play_effect()
1531 packet->data[10] = 0xFF; /* on period */ in xpad_play_effect()
1532 packet->data[11] = 0x00; /* off period */ in xpad_play_effect()
1533 packet->data[12] = 0xFF; /* repeat count */ in xpad_play_effect()
1534 packet->len = 13; in xpad_play_effect()
1535 packet->pending = true; in xpad_play_effect()
1539 dev_dbg(&xpad->dev->dev, in xpad_play_effect()
1540 "%s - rumble command sent to unsupported xpad type: %d\n", in xpad_play_effect()
1541 __func__, xpad->xtype); in xpad_play_effect()
1542 retval = -EINVAL; in xpad_play_effect()
1549 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_play_effect()
1555 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_ff()
1558 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); in xpad_init_ff()
1560 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); in xpad_init_ff()
1584 * 2: 1/top-left blink, then on
1585 * 3: 2/top-right blink, then on
1586 * 4: 3/bottom-left blink, then on
1587 * 5: 4/bottom-right blink, then on
1588 * 6: 1/top-left on
1589 * 7: 2/top-right on
1590 * 8: 3/bottom-left on
1591 * 9: 4/bottom-right on
1602 &xpad->out_packets[XPAD_OUT_LED_IDX]; in xpad_send_led_command()
1607 spin_lock_irqsave(&xpad->odata_lock, flags); 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()
1638 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_send_led_command()
1647 led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); in xpad_identify_controller()
1656 xpad_send_led_command(xpad_led->xpad, value); in xpad_led_set()
1665 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) in xpad_led_probe()
1668 xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL); in xpad_led_probe()
1670 return -ENOMEM; in xpad_led_probe()
1672 xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL); in xpad_led_probe()
1673 if (xpad->pad_nr < 0) { in xpad_led_probe()
1674 error = xpad->pad_nr; in xpad_led_probe()
1678 snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); in xpad_led_probe()
1679 led->xpad = xpad; in xpad_led_probe()
1681 led_cdev = &led->led_cdev; in xpad_led_probe()
1682 led_cdev->name = led->name; in xpad_led_probe()
1683 led_cdev->brightness_set = xpad_led_set; in xpad_led_probe()
1684 led_cdev->flags = LED_CORE_SUSPENDRESUME; in xpad_led_probe()
1686 error = led_classdev_register(&xpad->udev->dev, led_cdev); in xpad_led_probe()
1695 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_probe()
1698 xpad->led = NULL; in xpad_led_probe()
1704 struct xpad_led *xpad_led = xpad->led; in xpad_led_disconnect()
1707 led_classdev_unregister(&xpad_led->led_cdev); in xpad_led_disconnect()
1708 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_disconnect()
1721 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) in xpad_start_input()
1722 return -EIO; in xpad_start_input()
1724 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_start_input()
1727 usb_kill_urb(xpad->irq_in); in xpad_start_input()
1731 if (xpad->xtype == XTYPE_XBOX360) { in xpad_start_input()
1733 * Some third-party controllers Xbox 360-style controllers in xpad_start_input()
1738 error = usb_control_msg_recv(xpad->udev, 0, in xpad_start_input()
1748 dev_warn(&xpad->dev->dev, in xpad_start_input()
1758 usb_kill_urb(xpad->irq_in); in xpad_stop_input()
1765 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad360w_poweroff_controller()
1767 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1769 packet->data[0] = 0x00; in xpad360w_poweroff_controller()
1770 packet->data[1] = 0x00; in xpad360w_poweroff_controller()
1771 packet->data[2] = 0x08; in xpad360w_poweroff_controller()
1772 packet->data[3] = 0xC0; in xpad360w_poweroff_controller()
1773 packet->data[4] = 0x00; in xpad360w_poweroff_controller()
1774 packet->data[5] = 0x00; in xpad360w_poweroff_controller()
1775 packet->data[6] = 0x00; in xpad360w_poweroff_controller()
1776 packet->data[7] = 0x00; in xpad360w_poweroff_controller()
1777 packet->data[8] = 0x00; in xpad360w_poweroff_controller()
1778 packet->data[9] = 0x00; in xpad360w_poweroff_controller()
1779 packet->data[10] = 0x00; in xpad360w_poweroff_controller()
1780 packet->data[11] = 0x00; in xpad360w_poweroff_controller()
1781 packet->len = 12; in xpad360w_poweroff_controller()
1782 packet->pending = true; in xpad360w_poweroff_controller()
1785 xpad->last_out_packet = -1; in xpad360w_poweroff_controller()
1788 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1795 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); in xpad360w_start_input()
1797 return -EIO; in xpad360w_start_input()
1801 * This will force the controller to resend connection packets. in xpad360w_start_input()
1808 usb_kill_urb(xpad->irq_in); in xpad360w_start_input()
1817 usb_kill_urb(xpad->irq_in); in xpad360w_stop_input()
1820 flush_work(&xpad->work); in xpad360w_stop_input()
1846 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); in xpad_set_up_abs()
1850 if (xpad->xtype == XTYPE_XBOXONE) in xpad_set_up_abs()
1856 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ in xpad_set_up_abs()
1857 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); in xpad_set_up_abs()
1870 if (xpad->input_created) { in xpad_deinit_input()
1871 xpad->input_created = false; in xpad_deinit_input()
1873 input_unregister_device(xpad->dev); in xpad_deinit_input()
1884 return -ENOMEM; in xpad_init_input()
1886 xpad->dev = input_dev; in xpad_init_input()
1887 input_dev->name = xpad->name; in xpad_init_input()
1888 input_dev->phys = xpad->phys; in xpad_init_input()
1889 usb_to_input_id(xpad->udev, &input_dev->id); in xpad_init_input()
1891 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1893 input_dev->id.product = 0x02a1; in xpad_init_input()
1896 input_dev->dev.parent = &xpad->intf->dev; in xpad_init_input()
1900 if (xpad->xtype != XTYPE_XBOX360W) { in xpad_init_input()
1901 input_dev->open = xpad_open; in xpad_init_input()
1902 input_dev->close = xpad_close; in xpad_init_input()
1905 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_init_input()
1915 /* set up model-specific ones */ in xpad_init_input()
1916 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || in xpad_init_input()
1917 xpad->xtype == XTYPE_XBOXONE) { in xpad_init_input()
1920 if (xpad->mapping & MAP_SELECT_BUTTON) in xpad_init_input()
1927 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_init_input()
1933 /* set up paddles if the controller has them */ in xpad_init_input()
1934 if (xpad->mapping & MAP_PADDLES) { in xpad_init_input()
1945 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad_init_input()
1946 xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1951 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_init_input()
1961 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_init_input()
1972 error = input_register_device(xpad->dev); in xpad_init_input()
1976 xpad->input_created = true; in xpad_init_input()
1995 if (intf->cur_altsetting->desc.bNumEndpoints != 2) in xpad_probe()
1996 return -ENODEV; in xpad_probe()
1999 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && in xpad_probe()
2000 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) in xpad_probe()
2006 return -ENOMEM; in xpad_probe()
2008 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); in xpad_probe()
2009 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); in xpad_probe()
2011 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, in xpad_probe()
2012 GFP_KERNEL, &xpad->idata_dma); in xpad_probe()
2013 if (!xpad->idata) { in xpad_probe()
2014 error = -ENOMEM; in xpad_probe()
2018 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); in xpad_probe()
2019 if (!xpad->irq_in) { in xpad_probe()
2020 error = -ENOMEM; in xpad_probe()
2024 xpad->udev = udev; in xpad_probe()
2025 xpad->intf = intf; in xpad_probe()
2026 xpad->mapping = xpad_device[i].mapping; in xpad_probe()
2027 xpad->xtype = xpad_device[i].xtype; in xpad_probe()
2028 xpad->name = xpad_device[i].name; in xpad_probe()
2029 xpad->packet_type = PKT_XB; in xpad_probe()
2030 INIT_WORK(&xpad->work, xpad_presence_work); in xpad_probe()
2032 if (xpad->xtype == XTYPE_UNKNOWN) { in xpad_probe()
2033 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { in xpad_probe()
2034 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) in xpad_probe()
2035 xpad->xtype = XTYPE_XBOX360W; in xpad_probe()
2036 else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) in xpad_probe()
2037 xpad->xtype = XTYPE_XBOXONE; in xpad_probe()
2039 xpad->xtype = XTYPE_XBOX360; in xpad_probe()
2041 xpad->xtype = XTYPE_XBOX; in xpad_probe()
2045 xpad->mapping |= MAP_DPAD_TO_BUTTONS; in xpad_probe()
2047 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; in xpad_probe()
2049 xpad->mapping |= MAP_STICKS_TO_NULL; in xpad_probe()
2052 if (xpad->xtype == XTYPE_XBOXONE && in xpad_probe()
2053 intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) { in xpad_probe()
2055 * The Xbox One controller lists three interfaces all with the in xpad_probe()
2059 error = -ENODEV; in xpad_probe()
2067 &intf->cur_altsetting->endpoint[i].desc; in xpad_probe()
2078 error = -ENODEV; in xpad_probe()
2086 usb_fill_int_urb(xpad->irq_in, udev, in xpad_probe()
2087 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), in xpad_probe()
2088 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, in xpad_probe()
2089 xpad, ep_irq_in->bInterval); in xpad_probe()
2090 xpad->irq_in->transfer_dma = xpad->idata_dma; in xpad_probe()
2091 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_probe()
2096 if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ in xpad_probe()
2097 if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { in xpad_probe()
2098 /* The original elite controller always uses the oldest in xpad_probe()
2101 xpad->packet_type = PKT_XBE1; in xpad_probe()
2102 } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { in xpad_probe()
2103 /* The elite 2 controller has seen multiple packet in xpad_probe()
2107 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { in xpad_probe()
2111 xpad->packet_type = PKT_XBE2_FW_OLD; in xpad_probe()
2112 } else if (le16_to_cpu(udev->descriptor.bcdDevice) < in xpad_probe()
2117 xpad->packet_type = PKT_XBE2_FW_5_EARLY; in xpad_probe()
2122 xpad->packet_type = PKT_XBE2_FW_5_11; in xpad_probe()
2127 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_probe()
2132 * exactly the message that a controller has arrived that in xpad_probe()
2145 udev->quirks |= USB_QUIRK_RESET_RESUME; in xpad_probe()
2156 usb_free_urb(xpad->irq_in); in xpad_probe()
2158 usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); in xpad_probe()
2168 if (xpad->xtype == XTYPE_XBOX360W) in xpad_disconnect()
2181 usb_free_urb(xpad->irq_in); in xpad_disconnect()
2182 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_disconnect()
2183 xpad->idata, xpad->idata_dma); in xpad_disconnect()
2193 struct input_dev *input = xpad->dev; in xpad_suspend()
2195 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_suspend()
2198 * they are notified when controller shows up in xpad_suspend()
2209 if (auto_poweroff && xpad->pad_present) in xpad_suspend()
2212 mutex_lock(&input->mutex); in xpad_suspend()
2215 mutex_unlock(&input->mutex); in xpad_suspend()
2226 struct input_dev *input = xpad->dev; in xpad_resume()
2229 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_resume()
2232 mutex_lock(&input->mutex); in xpad_resume()
2235 } else if (xpad->xtype == XTYPE_XBOXONE) { in xpad_resume()
2243 mutex_unlock(&input->mutex); in xpad_resume()
2260 MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");