Lines Matching +full:controller +full:- +full:data

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * X-Box gamepad driver
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 id's
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");
131 { 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 },
269 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
270 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
271 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
274 { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
275 { 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 },
280 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
282 { 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
283 { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
289 { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
290 { 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
291 { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
295 { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 },
299 { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
303 { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
313 …{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XB…
324 { 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 },
325 { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
326 { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
332 { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
333 { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
334 { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
335 { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
337 { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
338 { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
339 { 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
341 { 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
342 { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
344 { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
346 { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
351 { 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
353 { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
354 { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
356 { 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
361 { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
368 { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
370 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
371 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
378 -1 /* terminating entry */
384 -1 /* terminating entry */
389 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
390 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
391 -1 /* terminating entry */
397 -1
400 static const signed short xpad360_btn[] = { /* buttons for x360 controller */
403 -1
409 -1 /* terminating entry */
414 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
415 -1 /* terminating entry */
421 -1
424 /* used when the controller has extra paddle buttons */
428 -1 /* terminating entry */
432 * Xbox 360 has a vendor-specific class, so we cannot match it with only
447 /* The Xbox One controller uses subclass 71 and protocol 208. */
458 { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
459 XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 Controller */
461 XPAD_XBOX360_VENDOR(0x044f), /* Thrustmaster X-Box 360 controllers */
462 XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
463 XPAD_XBOXONE_VENDOR(0x045e), /* Microsoft X-Box One controllers */
464 XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
465 XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
467 XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
471 XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
472 XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
473 XPAD_XBOXONE_VENDOR(0x0e6f), /* 0x0e6f X-Box One controllers */
479 XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */
480 XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
484 XPAD_XBOX360_VENDOR(0x15e4), /* Numark X-Box 360 controllers */
485 XPAD_XBOX360_VENDOR(0x162e), /* Joytech X-Box 360 controllers */
495 XPAD_XBOXONE_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller for Xbox */
496 XPAD_XBOXONE_VENDOR(0x2e24), /* Hyperkin Duke X-Box One pad */
499 XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
508 const u8 *data; member
516 .data = (_data), \
523 * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
524 * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
544 * which is a no-op for N < 128
571 * initialize the controller that was previously used in
579 * This packet is required to get additional input data
581 * We mostly do this right now to get paddle data
659 u8 data[XPAD_PKT_LEN]; member
681 unsigned char *idata; /* input data */
688 unsigned char *odata; /* output data */
702 int mapping; /* map d-pad to buttons or to axes */
719 * Completes a request by converting the data into events for the
723 * http://euc.jp/periphs/xbox-controller.ja.html
725 static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad_process_packet() argument
727 struct input_dev *dev = xpad->dev; in xpad_process_packet()
729 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_process_packet()
732 (__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad_process_packet()
734 ~(__s16) le16_to_cpup((__le16 *)(data + 14))); in xpad_process_packet()
738 (__s16) le16_to_cpup((__le16 *)(data + 16))); in xpad_process_packet()
740 ~(__s16) le16_to_cpup((__le16 *)(data + 18))); in xpad_process_packet()
744 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_process_packet()
745 input_report_key(dev, BTN_TL2, data[10]); in xpad_process_packet()
746 input_report_key(dev, BTN_TR2, data[11]); in xpad_process_packet()
748 input_report_abs(dev, ABS_Z, data[10]); in xpad_process_packet()
749 input_report_abs(dev, ABS_RZ, data[11]); in xpad_process_packet()
753 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_process_packet()
755 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad_process_packet()
756 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad_process_packet()
757 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad_process_packet()
758 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad_process_packet()
761 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad_process_packet()
763 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad_process_packet()
767 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad_process_packet()
768 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad_process_packet()
769 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad_process_packet()
770 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad_process_packet()
773 input_report_key(dev, BTN_A, data[4]); in xpad_process_packet()
774 input_report_key(dev, BTN_B, data[5]); in xpad_process_packet()
775 input_report_key(dev, BTN_X, data[6]); in xpad_process_packet()
776 input_report_key(dev, BTN_Y, data[7]); in xpad_process_packet()
779 input_report_key(dev, BTN_C, data[8]); in xpad_process_packet()
780 input_report_key(dev, BTN_Z, data[9]); in xpad_process_packet()
782 /* Profile button has a value of 0-3, so it is reported as an axis */ in xpad_process_packet()
783 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_process_packet()
784 input_report_abs(dev, ABS_PROFILE, data[34]); in xpad_process_packet()
792 * Completes a request by converting the data into events for the
793 * input subsystem. It is version for xbox 360 controller
800 u16 cmd, unsigned char *data) in xpad360_process_packet() argument
802 /* valid pad data */ in xpad360_process_packet()
803 if (data[0] != 0x00) in xpad360_process_packet()
807 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad360_process_packet()
809 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad360_process_packet()
810 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad360_process_packet()
811 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad360_process_packet()
812 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad360_process_packet()
821 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad360_process_packet()
822 xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
824 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad360_process_packet()
826 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad360_process_packet()
830 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad360_process_packet()
831 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad360_process_packet()
834 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad360_process_packet()
835 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad360_process_packet()
838 input_report_key(dev, BTN_A, data[3] & BIT(4)); in xpad360_process_packet()
839 input_report_key(dev, BTN_B, data[3] & BIT(5)); in xpad360_process_packet()
840 input_report_key(dev, BTN_X, data[3] & BIT(6)); in xpad360_process_packet()
841 input_report_key(dev, BTN_Y, data[3] & BIT(7)); in xpad360_process_packet()
842 input_report_key(dev, BTN_TL, data[3] & BIT(0)); in xpad360_process_packet()
843 input_report_key(dev, BTN_TR, data[3] & BIT(1)); in xpad360_process_packet()
844 input_report_key(dev, BTN_MODE, data[3] & BIT(2)); in xpad360_process_packet()
846 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad360_process_packet()
849 (__s16) le16_to_cpup((__le16 *)(data + 6))); in xpad360_process_packet()
851 ~(__s16) le16_to_cpup((__le16 *)(data + 8))); in xpad360_process_packet()
855 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpad360_process_packet()
857 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad360_process_packet()
861 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad360_process_packet()
862 input_report_key(dev, BTN_TL2, data[4]); in xpad360_process_packet()
863 input_report_key(dev, BTN_TR2, data[5]); in xpad360_process_packet()
865 input_report_abs(dev, ABS_Z, data[4]); in xpad360_process_packet()
866 input_report_abs(dev, ABS_RZ, data[5]); in xpad360_process_packet()
872 if (xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
873 if (xpad->mode_btn_down_ts > 0 && xpad->pad_present && in xpad360_process_packet()
874 ((ktime_get_seconds() - xpad->mode_btn_down_ts) >= in xpad360_process_packet()
877 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
882 if (data[3] & BIT(2)) in xpad360_process_packet()
883 xpad->mode_btn_down_ts = ktime_get_seconds(); in xpad360_process_packet()
885 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
894 if (xpad->pad_present) { in xpad_presence_work()
898 dev_err(&xpad->dev->dev, in xpad_presence_work()
901 rcu_assign_pointer(xpad->x360w_dev, xpad->dev); in xpad_presence_work()
904 RCU_INIT_POINTER(xpad->x360w_dev, NULL); in xpad_presence_work()
917 * Completes a request by converting the data into events for the
918 * input subsystem. It is version for xbox 360 wireless controller.
921 * 00.1 - Status change: The controller or headset has connected/disconnected
923 * 01.7 - Controller present
924 * 01.6 - Headset present
925 * 01.1 - Pad state (Bytes 4+) valid
928 static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad360w_process_packet() argument
934 if (data[0] & 0x08) { in xpad360w_process_packet()
935 present = (data[1] & 0x80) != 0; in xpad360w_process_packet()
937 if (xpad->pad_present != present) { in xpad360w_process_packet()
938 xpad->pad_present = present; in xpad360w_process_packet()
939 schedule_work(&xpad->work); in xpad360w_process_packet()
943 /* Valid pad data */ in xpad360w_process_packet()
944 if (data[1] != 0x1) in xpad360w_process_packet()
948 dev = rcu_dereference(xpad->x360w_dev); in xpad360w_process_packet()
950 xpad360_process_packet(xpad, dev, cmd, &data[4]); in xpad360w_process_packet()
957 * Completes a request by converting the data into events for the
958 * input subsystem. This version is for the Xbox One controller.
963 static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpadone_process_packet() argument
965 struct input_dev *dev = xpad->dev; in xpadone_process_packet()
969 if (data[0] == GIP_CMD_VIRTUAL_KEY) { in xpadone_process_packet()
971 * The Xbox One S controller requires these reports to be in xpadone_process_packet()
975 if (data[1] == (GIP_OPT_ACK | GIP_OPT_INTERNAL)) in xpadone_process_packet()
976 xpadone_ack_mode_report(xpad, data[2]); in xpadone_process_packet()
978 input_report_key(dev, BTN_MODE, data[4] & GENMASK(1, 0)); in xpadone_process_packet()
982 } else if (data[0] == GIP_CMD_FIRMWARE) { in xpadone_process_packet()
984 if (xpad->packet_type == PKT_XBE2_FW_5_11) { in xpadone_process_packet()
985 /* Mute paddles if controller is in a custom profile slot in xpadone_process_packet()
989 if (data[19] != 0) in xpadone_process_packet()
990 data[18] = 0; in xpadone_process_packet()
993 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
994 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
995 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
996 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1000 } else if (data[0] == GIP_CMD_INPUT) { /* The main valid packet type for inputs */ in xpadone_process_packet()
1002 input_report_key(dev, BTN_START, data[4] & BIT(2)); in xpadone_process_packet()
1003 input_report_key(dev, BTN_SELECT, data[4] & BIT(3)); in xpadone_process_packet()
1004 if (xpad->mapping & MAP_SELECT_BUTTON) in xpadone_process_packet()
1005 input_report_key(dev, KEY_RECORD, data[22] & BIT(0)); in xpadone_process_packet()
1008 input_report_key(dev, BTN_A, data[4] & BIT(4)); in xpadone_process_packet()
1009 input_report_key(dev, BTN_B, data[4] & BIT(5)); in xpadone_process_packet()
1010 input_report_key(dev, BTN_X, data[4] & BIT(6)); in xpadone_process_packet()
1011 input_report_key(dev, BTN_Y, data[4] & BIT(7)); in xpadone_process_packet()
1014 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpadone_process_packet()
1016 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & BIT(2)); in xpadone_process_packet()
1017 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & BIT(3)); in xpadone_process_packet()
1018 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & BIT(0)); in xpadone_process_packet()
1019 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & BIT(1)); in xpadone_process_packet()
1022 !!(data[5] & 0x08) - !!(data[5] & 0x04)); in xpadone_process_packet()
1024 !!(data[5] & 0x02) - !!(data[5] & 0x01)); in xpadone_process_packet()
1028 input_report_key(dev, BTN_TL, data[5] & BIT(4)); in xpadone_process_packet()
1029 input_report_key(dev, BTN_TR, data[5] & BIT(5)); in xpadone_process_packet()
1032 input_report_key(dev, BTN_THUMBL, data[5] & BIT(6)); in xpadone_process_packet()
1033 input_report_key(dev, BTN_THUMBR, data[5] & BIT(7)); in xpadone_process_packet()
1035 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpadone_process_packet()
1038 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpadone_process_packet()
1040 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpadone_process_packet()
1044 (__s16) le16_to_cpup((__le16 *)(data + 14))); in xpadone_process_packet()
1046 ~(__s16) le16_to_cpup((__le16 *)(data + 16))); in xpadone_process_packet()
1050 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpadone_process_packet()
1052 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1054 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1057 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1059 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1064 if (xpad->mapping & MAP_PADDLES) { in xpadone_process_packet()
1065 if (xpad->packet_type == PKT_XBE1) { in xpadone_process_packet()
1066 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1070 if (memcmp(&data[4], &data[18], 2) != 0) in xpadone_process_packet()
1071 data[32] = 0; in xpadone_process_packet()
1073 /* OG Elite Series Controller paddle bits */ in xpadone_process_packet()
1074 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[32] & BIT(1)); in xpadone_process_packet()
1075 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[32] & BIT(3)); in xpadone_process_packet()
1076 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[32] & BIT(0)); in xpadone_process_packet()
1077 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[32] & BIT(2)); in xpadone_process_packet()
1078 } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { in xpadone_process_packet()
1079 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1083 if (data[19] != 0) in xpadone_process_packet()
1084 data[18] = 0; in xpadone_process_packet()
1087 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
1088 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
1089 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
1090 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1091 } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { in xpadone_process_packet()
1092 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1096 if (data[23] != 0) in xpadone_process_packet()
1097 data[22] = 0; in xpadone_process_packet()
1102 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[22] & BIT(0)); in xpadone_process_packet()
1103 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[22] & BIT(1)); in xpadone_process_packet()
1104 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[22] & BIT(2)); in xpadone_process_packet()
1105 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[22] & BIT(3)); in xpadone_process_packet()
1118 struct usb_xpad *xpad = urb->context; in xpad_irq_in()
1119 struct device *dev = &xpad->intf->dev; in xpad_irq_in()
1122 status = urb->status; in xpad_irq_in()
1128 case -ECONNRESET: in xpad_irq_in()
1129 case -ENOENT: in xpad_irq_in()
1130 case -ESHUTDOWN: in xpad_irq_in()
1132 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_in()
1136 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_in()
1141 switch (xpad->xtype) { in xpad_irq_in()
1143 xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); in xpad_irq_in()
1146 xpad360w_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1149 xpadone_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1152 xpad_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1158 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", in xpad_irq_in()
1162 /* Callers must hold xpad->odata_lock spinlock */
1167 if (xpad->xtype != XTYPE_XBOXONE) in xpad_prepare_next_init_packet()
1171 while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { in xpad_prepare_next_init_packet()
1172 init_packet = &xboxone_init_packets[xpad->init_seq++]; in xpad_prepare_next_init_packet()
1174 if (init_packet->idVendor != 0 && in xpad_prepare_next_init_packet()
1175 init_packet->idVendor != xpad->dev->id.vendor) in xpad_prepare_next_init_packet()
1178 if (init_packet->idProduct != 0 && in xpad_prepare_next_init_packet()
1179 init_packet->idProduct != xpad->dev->id.product) in xpad_prepare_next_init_packet()
1183 memcpy(xpad->odata, init_packet->data, init_packet->len); in xpad_prepare_next_init_packet()
1184 xpad->irq_out->transfer_buffer_length = init_packet->len; in xpad_prepare_next_init_packet()
1187 xpad->odata[2] = xpad->odata_serial++; in xpad_prepare_next_init_packet()
1194 /* Callers must hold xpad->odata_lock spinlock */
1205 if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) in xpad_prepare_next_out_packet()
1206 xpad->last_out_packet = 0; in xpad_prepare_next_out_packet()
1208 pkt = &xpad->out_packets[xpad->last_out_packet]; in xpad_prepare_next_out_packet()
1209 if (pkt->pending) { in xpad_prepare_next_out_packet()
1210 dev_dbg(&xpad->intf->dev, in xpad_prepare_next_out_packet()
1211 "%s - found pending output packet %d\n", in xpad_prepare_next_out_packet()
1212 __func__, xpad->last_out_packet); in xpad_prepare_next_out_packet()
1219 memcpy(xpad->odata, packet->data, packet->len); in xpad_prepare_next_out_packet()
1220 xpad->irq_out->transfer_buffer_length = packet->len; in xpad_prepare_next_out_packet()
1221 packet->pending = false; in xpad_prepare_next_out_packet()
1228 /* Callers must hold xpad->odata_lock spinlock */
1233 if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { in xpad_try_sending_next_out_packet()
1234 usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); in xpad_try_sending_next_out_packet()
1235 error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); in xpad_try_sending_next_out_packet()
1237 dev_err(&xpad->intf->dev, in xpad_try_sending_next_out_packet()
1238 "%s - usb_submit_urb failed with result %d\n", in xpad_try_sending_next_out_packet()
1240 usb_unanchor_urb(xpad->irq_out); in xpad_try_sending_next_out_packet()
1241 return -EIO; in xpad_try_sending_next_out_packet()
1244 xpad->irq_out_active = true; in xpad_try_sending_next_out_packet()
1252 struct usb_xpad *xpad = urb->context; in xpad_irq_out()
1253 struct device *dev = &xpad->intf->dev; in xpad_irq_out()
1254 int status = urb->status; in xpad_irq_out()
1258 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_irq_out()
1263 xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); in xpad_irq_out()
1266 case -ECONNRESET: in xpad_irq_out()
1267 case -ENOENT: in xpad_irq_out()
1268 case -ESHUTDOWN: in xpad_irq_out()
1270 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_out()
1272 xpad->irq_out_active = false; in xpad_irq_out()
1276 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_out()
1281 if (xpad->irq_out_active) { in xpad_irq_out()
1282 usb_anchor_urb(urb, &xpad->irq_out_anchor); in xpad_irq_out()
1286 "%s - usb_submit_urb failed with result %d\n", in xpad_irq_out()
1289 xpad->irq_out_active = false; in xpad_irq_out()
1293 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_irq_out()
1301 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_output()
1304 init_usb_anchor(&xpad->irq_out_anchor); in xpad_init_output()
1306 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_init_output()
1307 GFP_KERNEL, &xpad->odata_dma); in xpad_init_output()
1308 if (!xpad->odata) in xpad_init_output()
1309 return -ENOMEM; in xpad_init_output()
1311 spin_lock_init(&xpad->odata_lock); in xpad_init_output()
1313 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); in xpad_init_output()
1314 if (!xpad->irq_out) { in xpad_init_output()
1315 error = -ENOMEM; in xpad_init_output()
1319 usb_fill_int_urb(xpad->irq_out, xpad->udev, in xpad_init_output()
1320 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), in xpad_init_output()
1321 xpad->odata, XPAD_PKT_LEN, in xpad_init_output()
1322 xpad_irq_out, xpad, ep_irq_out->bInterval); in xpad_init_output()
1323 xpad->irq_out->transfer_dma = xpad->odata_dma; in xpad_init_output()
1324 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_init_output()
1329 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); in xpad_init_output()
1335 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_stop_output()
1336 if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, in xpad_stop_output()
1338 dev_warn(&xpad->intf->dev, in xpad_stop_output()
1340 usb_kill_anchored_urbs(&xpad->irq_out_anchor); in xpad_stop_output()
1347 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_deinit_output()
1348 usb_free_urb(xpad->irq_out); in xpad_deinit_output()
1349 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_deinit_output()
1350 xpad->odata, xpad->odata_dma); in xpad_deinit_output()
1357 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad_inquiry_pad_presence()
1361 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1363 packet->data[0] = 0x08; in xpad_inquiry_pad_presence()
1364 packet->data[1] = 0x00; in xpad_inquiry_pad_presence()
1365 packet->data[2] = 0x0F; in xpad_inquiry_pad_presence()
1366 packet->data[3] = 0xC0; in xpad_inquiry_pad_presence()
1367 packet->data[4] = 0x00; in xpad_inquiry_pad_presence()
1368 packet->data[5] = 0x00; in xpad_inquiry_pad_presence()
1369 packet->data[6] = 0x00; in xpad_inquiry_pad_presence()
1370 packet->data[7] = 0x00; in xpad_inquiry_pad_presence()
1371 packet->data[8] = 0x00; in xpad_inquiry_pad_presence()
1372 packet->data[9] = 0x00; in xpad_inquiry_pad_presence()
1373 packet->data[10] = 0x00; in xpad_inquiry_pad_presence()
1374 packet->data[11] = 0x00; in xpad_inquiry_pad_presence()
1375 packet->len = 12; in xpad_inquiry_pad_presence()
1376 packet->pending = true; in xpad_inquiry_pad_presence()
1379 xpad->last_out_packet = -1; in xpad_inquiry_pad_presence()
1382 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1392 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1399 xpad->init_seq = 0; in xpad_start_xbox_one()
1402 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1411 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpadone_ack_mode_report()
1417 spin_lock_irqsave(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1419 packet->len = sizeof(mode_report_ack); in xpadone_ack_mode_report()
1420 memcpy(packet->data, mode_report_ack, packet->len); in xpadone_ack_mode_report()
1421 packet->data[2] = seq_num; in xpadone_ack_mode_report()
1422 packet->pending = true; in xpadone_ack_mode_report()
1425 xpad->last_out_packet = -1; in xpadone_ack_mode_report()
1428 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1432 static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) in xpad_play_effect() argument
1435 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; in xpad_play_effect()
1441 if (effect->type != FF_RUMBLE) in xpad_play_effect()
1444 strong = effect->u.rumble.strong_magnitude; in xpad_play_effect()
1445 weak = effect->u.rumble.weak_magnitude; in xpad_play_effect()
1447 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_play_effect()
1449 switch (xpad->xtype) { in xpad_play_effect()
1451 packet->data[0] = 0x00; in xpad_play_effect()
1452 packet->data[1] = 0x06; in xpad_play_effect()
1453 packet->data[2] = 0x00; in xpad_play_effect()
1454 packet->data[3] = strong / 256; /* left actuator */ in xpad_play_effect()
1455 packet->data[4] = 0x00; in xpad_play_effect()
1456 packet->data[5] = weak / 256; /* right actuator */ in xpad_play_effect()
1457 packet->len = 6; in xpad_play_effect()
1458 packet->pending = true; in xpad_play_effect()
1462 packet->data[0] = 0x00; in xpad_play_effect()
1463 packet->data[1] = 0x08; in xpad_play_effect()
1464 packet->data[2] = 0x00; in xpad_play_effect()
1465 packet->data[3] = strong / 256; /* left actuator? */ in xpad_play_effect()
1466 packet->data[4] = weak / 256; /* right actuator? */ in xpad_play_effect()
1467 packet->data[5] = 0x00; in xpad_play_effect()
1468 packet->data[6] = 0x00; in xpad_play_effect()
1469 packet->data[7] = 0x00; in xpad_play_effect()
1470 packet->len = 8; in xpad_play_effect()
1471 packet->pending = true; in xpad_play_effect()
1475 packet->data[0] = 0x00; in xpad_play_effect()
1476 packet->data[1] = 0x01; in xpad_play_effect()
1477 packet->data[2] = 0x0F; in xpad_play_effect()
1478 packet->data[3] = 0xC0; in xpad_play_effect()
1479 packet->data[4] = 0x00; in xpad_play_effect()
1480 packet->data[5] = strong / 256; in xpad_play_effect()
1481 packet->data[6] = weak / 256; in xpad_play_effect()
1482 packet->data[7] = 0x00; in xpad_play_effect()
1483 packet->data[8] = 0x00; in xpad_play_effect()
1484 packet->data[9] = 0x00; in xpad_play_effect()
1485 packet->data[10] = 0x00; in xpad_play_effect()
1486 packet->data[11] = 0x00; in xpad_play_effect()
1487 packet->len = 12; in xpad_play_effect()
1488 packet->pending = true; in xpad_play_effect()
1492 packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */ in xpad_play_effect()
1493 packet->data[1] = 0x00; in xpad_play_effect()
1494 packet->data[2] = xpad->odata_serial++; in xpad_play_effect()
1495 packet->data[3] = GIP_PL_LEN(9); in xpad_play_effect()
1496 packet->data[4] = 0x00; in xpad_play_effect()
1497 packet->data[5] = GIP_MOTOR_ALL; in xpad_play_effect()
1498 packet->data[6] = 0x00; /* left trigger */ in xpad_play_effect()
1499 packet->data[7] = 0x00; /* right trigger */ in xpad_play_effect()
1500 packet->data[8] = strong / 512; /* left actuator */ in xpad_play_effect()
1501 packet->data[9] = weak / 512; /* right actuator */ in xpad_play_effect()
1502 packet->data[10] = 0xFF; /* on period */ in xpad_play_effect()
1503 packet->data[11] = 0x00; /* off period */ in xpad_play_effect()
1504 packet->data[12] = 0xFF; /* repeat count */ in xpad_play_effect()
1505 packet->len = 13; in xpad_play_effect()
1506 packet->pending = true; in xpad_play_effect()
1510 dev_dbg(&xpad->dev->dev, in xpad_play_effect()
1511 "%s - rumble command sent to unsupported xpad type: %d\n", in xpad_play_effect()
1512 __func__, xpad->xtype); in xpad_play_effect()
1513 retval = -EINVAL; in xpad_play_effect()
1520 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_play_effect()
1526 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_ff()
1529 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); in xpad_init_ff()
1531 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); in xpad_init_ff()
1555 * 2: 1/top-left blink, then on
1556 * 3: 2/top-right blink, then on
1557 * 4: 3/bottom-left blink, then on
1558 * 5: 4/bottom-right blink, then on
1559 * 6: 1/top-left on
1560 * 7: 2/top-right on
1561 * 8: 3/bottom-left on
1562 * 9: 4/bottom-right on
1573 &xpad->out_packets[XPAD_OUT_LED_IDX]; in xpad_send_led_command()
1578 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_send_led_command()
1580 switch (xpad->xtype) { in xpad_send_led_command()
1582 packet->data[0] = 0x01; in xpad_send_led_command()
1583 packet->data[1] = 0x03; in xpad_send_led_command()
1584 packet->data[2] = command; in xpad_send_led_command()
1585 packet->len = 3; in xpad_send_led_command()
1586 packet->pending = true; in xpad_send_led_command()
1590 packet->data[0] = 0x00; in xpad_send_led_command()
1591 packet->data[1] = 0x00; in xpad_send_led_command()
1592 packet->data[2] = 0x08; in xpad_send_led_command()
1593 packet->data[3] = 0x40 + command; in xpad_send_led_command()
1594 packet->data[4] = 0x00; in xpad_send_led_command()
1595 packet->data[5] = 0x00; in xpad_send_led_command()
1596 packet->data[6] = 0x00; in xpad_send_led_command()
1597 packet->data[7] = 0x00; in xpad_send_led_command()
1598 packet->data[8] = 0x00; in xpad_send_led_command()
1599 packet->data[9] = 0x00; in xpad_send_led_command()
1600 packet->data[10] = 0x00; in xpad_send_led_command()
1601 packet->data[11] = 0x00; in xpad_send_led_command()
1602 packet->len = 12; in xpad_send_led_command()
1603 packet->pending = true; in xpad_send_led_command()
1609 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_send_led_command()
1618 led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); in xpad_identify_controller()
1627 xpad_send_led_command(xpad_led->xpad, value); in xpad_led_set()
1636 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) in xpad_led_probe()
1639 xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL); in xpad_led_probe()
1641 return -ENOMEM; in xpad_led_probe()
1643 xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL); in xpad_led_probe()
1644 if (xpad->pad_nr < 0) { in xpad_led_probe()
1645 error = xpad->pad_nr; in xpad_led_probe()
1649 snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); in xpad_led_probe()
1650 led->xpad = xpad; in xpad_led_probe()
1652 led_cdev = &led->led_cdev; in xpad_led_probe()
1653 led_cdev->name = led->name; in xpad_led_probe()
1654 led_cdev->brightness_set = xpad_led_set; in xpad_led_probe()
1655 led_cdev->flags = LED_CORE_SUSPENDRESUME; in xpad_led_probe()
1657 error = led_classdev_register(&xpad->udev->dev, led_cdev); in xpad_led_probe()
1666 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_probe()
1669 xpad->led = NULL; in xpad_led_probe()
1675 struct xpad_led *xpad_led = xpad->led; in xpad_led_disconnect()
1678 led_classdev_unregister(&xpad_led->led_cdev); in xpad_led_disconnect()
1679 ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); in xpad_led_disconnect()
1692 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) in xpad_start_input()
1693 return -EIO; in xpad_start_input()
1695 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_start_input()
1698 usb_kill_urb(xpad->irq_in); in xpad_start_input()
1708 usb_kill_urb(xpad->irq_in); in xpad_stop_input()
1715 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad360w_poweroff_controller()
1717 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1719 packet->data[0] = 0x00; in xpad360w_poweroff_controller()
1720 packet->data[1] = 0x00; in xpad360w_poweroff_controller()
1721 packet->data[2] = 0x08; in xpad360w_poweroff_controller()
1722 packet->data[3] = 0xC0; in xpad360w_poweroff_controller()
1723 packet->data[4] = 0x00; in xpad360w_poweroff_controller()
1724 packet->data[5] = 0x00; in xpad360w_poweroff_controller()
1725 packet->data[6] = 0x00; in xpad360w_poweroff_controller()
1726 packet->data[7] = 0x00; in xpad360w_poweroff_controller()
1727 packet->data[8] = 0x00; in xpad360w_poweroff_controller()
1728 packet->data[9] = 0x00; in xpad360w_poweroff_controller()
1729 packet->data[10] = 0x00; in xpad360w_poweroff_controller()
1730 packet->data[11] = 0x00; in xpad360w_poweroff_controller()
1731 packet->len = 12; in xpad360w_poweroff_controller()
1732 packet->pending = true; in xpad360w_poweroff_controller()
1735 xpad->last_out_packet = -1; in xpad360w_poweroff_controller()
1738 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1745 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); in xpad360w_start_input()
1747 return -EIO; in xpad360w_start_input()
1751 * This will force the controller to resend connection packets. in xpad360w_start_input()
1758 usb_kill_urb(xpad->irq_in); in xpad360w_start_input()
1767 usb_kill_urb(xpad->irq_in); in xpad360w_stop_input()
1770 flush_work(&xpad->work); in xpad360w_stop_input()
1796 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); in xpad_set_up_abs()
1800 if (xpad->xtype == XTYPE_XBOXONE) in xpad_set_up_abs()
1806 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ in xpad_set_up_abs()
1807 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); in xpad_set_up_abs()
1820 if (xpad->input_created) { in xpad_deinit_input()
1821 xpad->input_created = false; in xpad_deinit_input()
1823 input_unregister_device(xpad->dev); in xpad_deinit_input()
1834 return -ENOMEM; in xpad_init_input()
1836 xpad->dev = input_dev; in xpad_init_input()
1837 input_dev->name = xpad->name; in xpad_init_input()
1838 input_dev->phys = xpad->phys; in xpad_init_input()
1839 usb_to_input_id(xpad->udev, &input_dev->id); in xpad_init_input()
1841 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1843 input_dev->id.product = 0x02a1; in xpad_init_input()
1846 input_dev->dev.parent = &xpad->intf->dev; in xpad_init_input()
1850 if (xpad->xtype != XTYPE_XBOX360W) { in xpad_init_input()
1851 input_dev->open = xpad_open; in xpad_init_input()
1852 input_dev->close = xpad_close; in xpad_init_input()
1855 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_init_input()
1865 /* set up model-specific ones */ in xpad_init_input()
1866 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || in xpad_init_input()
1867 xpad->xtype == XTYPE_XBOXONE) { in xpad_init_input()
1870 if (xpad->mapping & MAP_SELECT_BUTTON) in xpad_init_input()
1877 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_init_input()
1883 /* set up paddles if the controller has them */ in xpad_init_input()
1884 if (xpad->mapping & MAP_PADDLES) { in xpad_init_input()
1895 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad_init_input()
1896 xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1901 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_init_input()
1911 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_init_input()
1922 error = input_register_device(xpad->dev); in xpad_init_input()
1926 xpad->input_created = true; in xpad_init_input()
1945 if (intf->cur_altsetting->desc.bNumEndpoints != 2) in xpad_probe()
1946 return -ENODEV; in xpad_probe()
1949 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && in xpad_probe()
1950 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) in xpad_probe()
1956 return -ENOMEM; in xpad_probe()
1958 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); in xpad_probe()
1959 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); in xpad_probe()
1961 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, in xpad_probe()
1962 GFP_KERNEL, &xpad->idata_dma); in xpad_probe()
1963 if (!xpad->idata) { in xpad_probe()
1964 error = -ENOMEM; in xpad_probe()
1968 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); in xpad_probe()
1969 if (!xpad->irq_in) { in xpad_probe()
1970 error = -ENOMEM; in xpad_probe()
1974 xpad->udev = udev; in xpad_probe()
1975 xpad->intf = intf; in xpad_probe()
1976 xpad->mapping = xpad_device[i].mapping; in xpad_probe()
1977 xpad->xtype = xpad_device[i].xtype; in xpad_probe()
1978 xpad->name = xpad_device[i].name; in xpad_probe()
1979 xpad->packet_type = PKT_XB; in xpad_probe()
1980 INIT_WORK(&xpad->work, xpad_presence_work); in xpad_probe()
1982 if (xpad->xtype == XTYPE_UNKNOWN) { in xpad_probe()
1983 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { in xpad_probe()
1984 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) in xpad_probe()
1985 xpad->xtype = XTYPE_XBOX360W; in xpad_probe()
1986 else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) in xpad_probe()
1987 xpad->xtype = XTYPE_XBOXONE; in xpad_probe()
1989 xpad->xtype = XTYPE_XBOX360; in xpad_probe()
1991 xpad->xtype = XTYPE_XBOX; in xpad_probe()
1995 xpad->mapping |= MAP_DPAD_TO_BUTTONS; in xpad_probe()
1997 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; in xpad_probe()
1999 xpad->mapping |= MAP_STICKS_TO_NULL; in xpad_probe()
2002 if (xpad->xtype == XTYPE_XBOXONE && in xpad_probe()
2003 intf->cur_altsetting->desc.bInterfaceNumber != 0) { in xpad_probe()
2005 * The Xbox One controller lists three interfaces all with the in xpad_probe()
2009 error = -ENODEV; in xpad_probe()
2017 &intf->cur_altsetting->endpoint[i].desc; in xpad_probe()
2028 error = -ENODEV; in xpad_probe()
2036 usb_fill_int_urb(xpad->irq_in, udev, in xpad_probe()
2037 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), in xpad_probe()
2038 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, in xpad_probe()
2039 xpad, ep_irq_in->bInterval); in xpad_probe()
2040 xpad->irq_in->transfer_dma = xpad->idata_dma; in xpad_probe()
2041 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_probe()
2046 if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ in xpad_probe()
2047 if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { in xpad_probe()
2048 /* The original elite controller always uses the oldest in xpad_probe()
2051 xpad->packet_type = PKT_XBE1; in xpad_probe()
2052 } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { in xpad_probe()
2053 /* The elite 2 controller has seen multiple packet in xpad_probe()
2057 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { in xpad_probe()
2061 xpad->packet_type = PKT_XBE2_FW_OLD; in xpad_probe()
2062 } else if (le16_to_cpu(udev->descriptor.bcdDevice) < in xpad_probe()
2067 xpad->packet_type = PKT_XBE2_FW_5_EARLY; in xpad_probe()
2072 xpad->packet_type = PKT_XBE2_FW_5_11; in xpad_probe()
2077 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_probe()
2082 * exactly the message that a controller has arrived that in xpad_probe()
2095 udev->quirks |= USB_QUIRK_RESET_RESUME; in xpad_probe()
2106 usb_free_urb(xpad->irq_in); in xpad_probe()
2108 usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); in xpad_probe()
2118 if (xpad->xtype == XTYPE_XBOX360W) in xpad_disconnect()
2131 usb_free_urb(xpad->irq_in); in xpad_disconnect()
2132 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_disconnect()
2133 xpad->idata, xpad->idata_dma); in xpad_disconnect()
2143 struct input_dev *input = xpad->dev; in xpad_suspend()
2145 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_suspend()
2148 * they are notified when controller shows up in xpad_suspend()
2159 if (auto_poweroff && xpad->pad_present) in xpad_suspend()
2162 mutex_lock(&input->mutex); in xpad_suspend()
2165 mutex_unlock(&input->mutex); in xpad_suspend()
2176 struct input_dev *input = xpad->dev; in xpad_resume()
2179 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_resume()
2182 mutex_lock(&input->mutex); in xpad_resume()
2185 } else if (xpad->xtype == XTYPE_XBOXONE) { in xpad_resume()
2193 mutex_unlock(&input->mutex); in xpad_resume()
2210 MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");
2211 MODULE_DESCRIPTION("X-Box pad driver");