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");
131 { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
142 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
145 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
146 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
147 { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
148 { 0x045e, 0x0288, "Microsoft Xbox Controller S v2", 0, XTYPE_XBOX },
149 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
150 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
151 { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
153 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
154 { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
155 { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE },
156 { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
158 { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE },
159 { 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
160 { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
164 { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
165 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
166 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
169 { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
170 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
171 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
172 { 0x05fe, 0x3030, "Chic Controller", 0, XTYPE_XBOX },
173 { 0x05fe, 0x3031, "Chic Controller", 0, XTYPE_XBOX },
179 { 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX },
187 { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
188 { 0x0738, 0x4586, "Mad Catz MicroCon Wireless Controller", 0, XTYPE_XBOX },
191 { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
193 { 0x0738, 0x4726, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
196 …{ 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX…
203 { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
206 { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
207 { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
214 { 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
215 { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
217 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
218 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
219 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
221 { 0x0db0, 0x1901, "Micro Star International Xbox360 Controller for Windows", 0, XTYPE_XBOX360 },
222 { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
224 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
226 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
227 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
228 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
229 { 0x0e6f, 0x0008, "After Glow Pro Controller", 0, XTYPE_XBOX },
232 { 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
233 { 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 },
234 { 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
235 { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
236 { 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
237 { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
238 { 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE },
240 { 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
241 { 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
242 { 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
245 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
249 { 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
250 { 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
251 { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
252 { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
253 { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
254 { 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
255 { 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
256 { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE },
257 { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
258 { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
259 { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
260 { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 },
262 { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 },
264 { 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 },
279 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
280 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
281 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
284 { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
286 { 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 },
291 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
293 { 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
294 { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
300 { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
301 { 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
302 { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
306 { 0x17ef, 0x6182, "Lenovo Legion Controller for Windows", 0, XTYPE_XBOX360 },
307 { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 },
311 { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
315 { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
325 …{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XB…
336 { 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 },
337 { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
338 { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
344 { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
345 { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
346 { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
347 { 0x2345, 0xe00b, "Machenike G5 Pro Controller", 0, XTYPE_XBOX360 },
349 { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
350 { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
351 { 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
353 { 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
354 { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
356 { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
358 { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
362 { 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
365 { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
366 { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
368 { 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
375 { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
376 { 0x2dc8, 0x3106, "8BitDo Pro 2 Wired Controller", 0, XTYPE_XBOX360 },
377 { 0x2dc8, 0x310a, "8BitDo Ultimate 2C Wireless Controller", 0, XTYPE_XBOX360 },
378 { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
385 { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
388 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
389 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
396 -1 /* terminating entry */
402 -1 /* terminating entry */
407 BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
408 BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
409 -1 /* terminating entry */
415 -1
418 static const signed short xpad360_btn[] = { /* buttons for x360 controller */
421 -1
427 -1 /* terminating entry */
432 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
433 -1 /* terminating entry */
439 -1
442 /* used when the controller has extra paddle buttons */
446 -1 /* terminating entry */
450 * Xbox 360 has a vendor-specific class, so we cannot match it with only
465 /* The Xbox One controller uses subclass 71 and protocol 208. */
478 * macros - XPAD_XBOX360_VENDOR and XPAD_XBOXONE_VENDOR.
480 { USB_INTERFACE_INFO('X', 'B', 0) }, /* Xbox USB-IF not-approved class */
481 XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 controller */
488 XPAD_XBOX360_VENDOR(0x046d), /* Logitech Xbox 360-style controllers */
489 XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
496 XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */
497 XPAD_XBOX360_VENDOR(0x0db0), /* Micro Star International X-Box 360 controllers */
527 XPAD_XBOX360_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller */
528 XPAD_XBOXONE_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller for Xbox */
532 XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */
543 const u8 *data; member
551 .data = (_data), \
558 * - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
559 * - https://github.com/medusalix/xone/blob/master/bus/protocol.c
579 * which is a no-op for N < 128
609 * initialize the controller that was previously used in
617 * This packet is required to get additional input data
619 * We mostly do this right now to get paddle data
697 u8 data[XPAD_PKT_LEN]; member
719 unsigned char *idata; /* input data */
726 unsigned char *odata; /* output data */
740 int mapping; /* map d-pad to buttons or to axes */
757 * Completes a request by converting the data into events for the
761 * http://euc.jp/periphs/xbox-controller.ja.html
763 static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad_process_packet() argument
765 struct input_dev *dev = xpad->dev; in xpad_process_packet()
767 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_process_packet()
770 (__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad_process_packet()
772 ~(__s16) le16_to_cpup((__le16 *)(data + 14))); in xpad_process_packet()
776 (__s16) le16_to_cpup((__le16 *)(data + 16))); in xpad_process_packet()
778 ~(__s16) le16_to_cpup((__le16 *)(data + 18))); in xpad_process_packet()
782 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_process_packet()
783 input_report_key(dev, BTN_TL2, data[10]); in xpad_process_packet()
784 input_report_key(dev, BTN_TR2, data[11]); in xpad_process_packet()
786 input_report_abs(dev, ABS_Z, data[10]); in xpad_process_packet()
787 input_report_abs(dev, ABS_RZ, data[11]); in xpad_process_packet()
791 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_process_packet()
793 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad_process_packet()
794 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad_process_packet()
795 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad_process_packet()
796 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad_process_packet()
799 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad_process_packet()
801 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad_process_packet()
805 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad_process_packet()
806 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad_process_packet()
807 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad_process_packet()
808 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad_process_packet()
811 input_report_key(dev, BTN_A, data[4]); in xpad_process_packet()
812 input_report_key(dev, BTN_B, data[5]); in xpad_process_packet()
813 input_report_key(dev, BTN_X, data[6]); in xpad_process_packet()
814 input_report_key(dev, BTN_Y, data[7]); in xpad_process_packet()
817 input_report_key(dev, BTN_C, data[8]); in xpad_process_packet()
818 input_report_key(dev, BTN_Z, data[9]); in xpad_process_packet()
827 * Completes a request by converting the data into events for the
828 * input subsystem. It is version for xbox 360 controller
835 u16 cmd, unsigned char *data) in xpad360_process_packet() argument
837 /* valid pad data */ in xpad360_process_packet()
838 if (data[0] != 0x00) in xpad360_process_packet()
842 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad360_process_packet()
844 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & BIT(2)); in xpad360_process_packet()
845 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & BIT(3)); in xpad360_process_packet()
846 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & BIT(0)); in xpad360_process_packet()
847 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & BIT(1)); in xpad360_process_packet()
856 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad360_process_packet()
857 xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
859 !!(data[2] & 0x08) - !!(data[2] & 0x04)); in xpad360_process_packet()
861 !!(data[2] & 0x02) - !!(data[2] & 0x01)); in xpad360_process_packet()
865 input_report_key(dev, BTN_START, data[2] & BIT(4)); in xpad360_process_packet()
866 input_report_key(dev, BTN_SELECT, data[2] & BIT(5)); in xpad360_process_packet()
869 input_report_key(dev, BTN_THUMBL, data[2] & BIT(6)); in xpad360_process_packet()
870 input_report_key(dev, BTN_THUMBR, data[2] & BIT(7)); in xpad360_process_packet()
873 input_report_key(dev, BTN_A, data[3] & BIT(4)); in xpad360_process_packet()
874 input_report_key(dev, BTN_B, data[3] & BIT(5)); in xpad360_process_packet()
875 input_report_key(dev, BTN_X, data[3] & BIT(6)); in xpad360_process_packet()
876 input_report_key(dev, BTN_Y, data[3] & BIT(7)); in xpad360_process_packet()
877 input_report_key(dev, BTN_TL, data[3] & BIT(0)); in xpad360_process_packet()
878 input_report_key(dev, BTN_TR, data[3] & BIT(1)); in xpad360_process_packet()
879 input_report_key(dev, BTN_MODE, data[3] & BIT(2)); in xpad360_process_packet()
881 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad360_process_packet()
884 (__s16) le16_to_cpup((__le16 *)(data + 6))); in xpad360_process_packet()
886 ~(__s16) le16_to_cpup((__le16 *)(data + 8))); in xpad360_process_packet()
890 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpad360_process_packet()
892 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpad360_process_packet()
896 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad360_process_packet()
897 input_report_key(dev, BTN_TL2, data[4]); in xpad360_process_packet()
898 input_report_key(dev, BTN_TR2, data[5]); in xpad360_process_packet()
900 input_report_abs(dev, ABS_Z, data[4]); in xpad360_process_packet()
901 input_report_abs(dev, ABS_RZ, data[5]); in xpad360_process_packet()
907 if (xpad->xtype == XTYPE_XBOX360W) { in xpad360_process_packet()
908 if (xpad->mode_btn_down_ts > 0 && xpad->pad_present && in xpad360_process_packet()
909 ((ktime_get_seconds() - xpad->mode_btn_down_ts) >= in xpad360_process_packet()
912 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
917 if (data[3] & BIT(2)) in xpad360_process_packet()
918 xpad->mode_btn_down_ts = ktime_get_seconds(); in xpad360_process_packet()
920 xpad->mode_btn_down_ts = 0; in xpad360_process_packet()
929 if (xpad->pad_present) { in xpad_presence_work()
933 dev_err(&xpad->dev->dev, in xpad_presence_work()
936 rcu_assign_pointer(xpad->x360w_dev, xpad->dev); in xpad_presence_work()
939 RCU_INIT_POINTER(xpad->x360w_dev, NULL); in xpad_presence_work()
952 * Completes a request by converting the data into events for the
953 * input subsystem. It is version for xbox 360 wireless controller.
956 * 00.1 - Status change: The controller or headset has connected/disconnected
958 * 01.7 - Controller present
959 * 01.6 - Headset present
960 * 01.1 - Pad state (Bytes 4+) valid
963 static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpad360w_process_packet() argument
969 if (data[0] & 0x08) { in xpad360w_process_packet()
970 present = (data[1] & 0x80) != 0; in xpad360w_process_packet()
972 if (xpad->pad_present != present) { in xpad360w_process_packet()
973 xpad->pad_present = present; in xpad360w_process_packet()
974 schedule_work(&xpad->work); in xpad360w_process_packet()
978 /* Valid pad data */ in xpad360w_process_packet()
979 if (data[1] != 0x1) in xpad360w_process_packet()
983 dev = rcu_dereference(xpad->x360w_dev); in xpad360w_process_packet()
985 xpad360_process_packet(xpad, dev, cmd, &data[4]); in xpad360w_process_packet()
992 * Completes a request by converting the data into events for the
993 * input subsystem. This version is for the Xbox One controller.
998 static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) in xpadone_process_packet() argument
1000 struct input_dev *dev = xpad->dev; in xpadone_process_packet()
1004 if (data[0] == GIP_CMD_VIRTUAL_KEY) { in xpadone_process_packet()
1006 * The Xbox One S controller requires these reports to be in xpadone_process_packet()
1010 if (data[1] == (GIP_OPT_ACK | GIP_OPT_INTERNAL)) in xpadone_process_packet()
1011 xpadone_ack_mode_report(xpad, data[2]); in xpadone_process_packet()
1013 input_report_key(dev, BTN_MODE, data[4] & GENMASK(1, 0)); in xpadone_process_packet()
1017 } else if (data[0] == GIP_CMD_FIRMWARE) { in xpadone_process_packet()
1019 if (xpad->packet_type == PKT_XBE2_FW_5_11) { in xpadone_process_packet()
1020 /* Mute paddles if controller is in a custom profile slot in xpadone_process_packet()
1024 if (data[19] != 0) in xpadone_process_packet()
1025 data[18] = 0; in xpadone_process_packet()
1028 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
1029 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
1030 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
1031 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1035 } else if (data[0] == GIP_CMD_INPUT) { /* The main valid packet type for inputs */ in xpadone_process_packet()
1037 input_report_key(dev, BTN_START, data[4] & BIT(2)); in xpadone_process_packet()
1038 input_report_key(dev, BTN_SELECT, data[4] & BIT(3)); in xpadone_process_packet()
1039 if (xpad->mapping & MAP_SELECT_BUTTON) in xpadone_process_packet()
1040 input_report_key(dev, KEY_RECORD, data[22] & BIT(0)); in xpadone_process_packet()
1043 input_report_key(dev, BTN_A, data[4] & BIT(4)); in xpadone_process_packet()
1044 input_report_key(dev, BTN_B, data[4] & BIT(5)); in xpadone_process_packet()
1045 input_report_key(dev, BTN_X, data[4] & BIT(6)); in xpadone_process_packet()
1046 input_report_key(dev, BTN_Y, data[4] & BIT(7)); in xpadone_process_packet()
1049 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpadone_process_packet()
1051 input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & BIT(2)); in xpadone_process_packet()
1052 input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & BIT(3)); in xpadone_process_packet()
1053 input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & BIT(0)); in xpadone_process_packet()
1054 input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & BIT(1)); in xpadone_process_packet()
1057 !!(data[5] & 0x08) - !!(data[5] & 0x04)); in xpadone_process_packet()
1059 !!(data[5] & 0x02) - !!(data[5] & 0x01)); in xpadone_process_packet()
1063 input_report_key(dev, BTN_TL, data[5] & BIT(4)); in xpadone_process_packet()
1064 input_report_key(dev, BTN_TR, data[5] & BIT(5)); in xpadone_process_packet()
1067 input_report_key(dev, BTN_THUMBL, data[5] & BIT(6)); in xpadone_process_packet()
1068 input_report_key(dev, BTN_THUMBR, data[5] & BIT(7)); in xpadone_process_packet()
1070 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpadone_process_packet()
1073 (__s16) le16_to_cpup((__le16 *)(data + 10))); in xpadone_process_packet()
1075 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); in xpadone_process_packet()
1079 (__s16) le16_to_cpup((__le16 *)(data + 14))); in xpadone_process_packet()
1081 ~(__s16) le16_to_cpup((__le16 *)(data + 16))); in xpadone_process_packet()
1085 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpadone_process_packet()
1087 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1089 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1092 (__u16) le16_to_cpup((__le16 *)(data + 6))); in xpadone_process_packet()
1094 (__u16) le16_to_cpup((__le16 *)(data + 8))); in xpadone_process_packet()
1097 /* Profile button has a value of 0-3, so it is reported as an axis */ in xpadone_process_packet()
1098 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpadone_process_packet()
1099 input_report_abs(dev, ABS_PROFILE, data[34]); in xpadone_process_packet()
1103 if (xpad->mapping & MAP_PADDLES) { in xpadone_process_packet()
1104 if (xpad->packet_type == PKT_XBE1) { in xpadone_process_packet()
1105 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1109 if (memcmp(&data[4], &data[18], 2) != 0) in xpadone_process_packet()
1110 data[32] = 0; in xpadone_process_packet()
1112 /* OG Elite Series Controller paddle bits */ in xpadone_process_packet()
1113 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[32] & BIT(1)); in xpadone_process_packet()
1114 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[32] & BIT(3)); in xpadone_process_packet()
1115 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[32] & BIT(0)); in xpadone_process_packet()
1116 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[32] & BIT(2)); in xpadone_process_packet()
1117 } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { in xpadone_process_packet()
1118 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1122 if (data[19] != 0) in xpadone_process_packet()
1123 data[18] = 0; in xpadone_process_packet()
1126 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & BIT(0)); in xpadone_process_packet()
1127 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & BIT(1)); in xpadone_process_packet()
1128 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & BIT(2)); in xpadone_process_packet()
1129 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & BIT(3)); in xpadone_process_packet()
1130 } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { in xpadone_process_packet()
1131 /* Mute paddles if controller has a custom mapping applied. in xpadone_process_packet()
1135 if (data[23] != 0) in xpadone_process_packet()
1136 data[22] = 0; in xpadone_process_packet()
1141 input_report_key(dev, BTN_TRIGGER_HAPPY5, data[22] & BIT(0)); in xpadone_process_packet()
1142 input_report_key(dev, BTN_TRIGGER_HAPPY6, data[22] & BIT(1)); in xpadone_process_packet()
1143 input_report_key(dev, BTN_TRIGGER_HAPPY7, data[22] & BIT(2)); in xpadone_process_packet()
1144 input_report_key(dev, BTN_TRIGGER_HAPPY8, data[22] & BIT(3)); in xpadone_process_packet()
1157 struct usb_xpad *xpad = urb->context; in xpad_irq_in()
1158 struct device *dev = &xpad->intf->dev; in xpad_irq_in()
1161 status = urb->status; in xpad_irq_in()
1167 case -ECONNRESET: in xpad_irq_in()
1168 case -ENOENT: in xpad_irq_in()
1169 case -ESHUTDOWN: in xpad_irq_in()
1171 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_in()
1175 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_in()
1180 switch (xpad->xtype) { in xpad_irq_in()
1182 xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); in xpad_irq_in()
1185 xpad360w_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1188 xpadone_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1191 xpad_process_packet(xpad, 0, xpad->idata); in xpad_irq_in()
1197 dev_err(dev, "%s - usb_submit_urb failed with result %d\n", in xpad_irq_in()
1201 /* Callers must hold xpad->odata_lock spinlock */
1206 if (xpad->xtype != XTYPE_XBOXONE) in xpad_prepare_next_init_packet()
1210 while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { in xpad_prepare_next_init_packet()
1211 init_packet = &xboxone_init_packets[xpad->init_seq++]; in xpad_prepare_next_init_packet()
1213 if (init_packet->idVendor != 0 && in xpad_prepare_next_init_packet()
1214 init_packet->idVendor != xpad->dev->id.vendor) in xpad_prepare_next_init_packet()
1217 if (init_packet->idProduct != 0 && in xpad_prepare_next_init_packet()
1218 init_packet->idProduct != xpad->dev->id.product) in xpad_prepare_next_init_packet()
1222 memcpy(xpad->odata, init_packet->data, init_packet->len); in xpad_prepare_next_init_packet()
1223 xpad->irq_out->transfer_buffer_length = init_packet->len; in xpad_prepare_next_init_packet()
1226 xpad->odata[2] = xpad->odata_serial++; in xpad_prepare_next_init_packet()
1233 /* Callers must hold xpad->odata_lock spinlock */
1244 if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) in xpad_prepare_next_out_packet()
1245 xpad->last_out_packet = 0; in xpad_prepare_next_out_packet()
1247 pkt = &xpad->out_packets[xpad->last_out_packet]; in xpad_prepare_next_out_packet()
1248 if (pkt->pending) { in xpad_prepare_next_out_packet()
1249 dev_dbg(&xpad->intf->dev, in xpad_prepare_next_out_packet()
1250 "%s - found pending output packet %d\n", in xpad_prepare_next_out_packet()
1251 __func__, xpad->last_out_packet); in xpad_prepare_next_out_packet()
1258 memcpy(xpad->odata, packet->data, packet->len); in xpad_prepare_next_out_packet()
1259 xpad->irq_out->transfer_buffer_length = packet->len; in xpad_prepare_next_out_packet()
1260 packet->pending = false; in xpad_prepare_next_out_packet()
1267 /* Callers must hold xpad->odata_lock spinlock */
1272 if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { in xpad_try_sending_next_out_packet()
1273 usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); in xpad_try_sending_next_out_packet()
1274 error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); in xpad_try_sending_next_out_packet()
1276 dev_err(&xpad->intf->dev, in xpad_try_sending_next_out_packet()
1277 "%s - usb_submit_urb failed with result %d\n", in xpad_try_sending_next_out_packet()
1279 usb_unanchor_urb(xpad->irq_out); in xpad_try_sending_next_out_packet()
1280 return -EIO; in xpad_try_sending_next_out_packet()
1283 xpad->irq_out_active = true; in xpad_try_sending_next_out_packet()
1291 struct usb_xpad *xpad = urb->context; in xpad_irq_out()
1292 struct device *dev = &xpad->intf->dev; in xpad_irq_out()
1293 int status = urb->status; in xpad_irq_out()
1297 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_irq_out()
1302 xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); in xpad_irq_out()
1305 case -ECONNRESET: in xpad_irq_out()
1306 case -ENOENT: in xpad_irq_out()
1307 case -ESHUTDOWN: in xpad_irq_out()
1309 dev_dbg(dev, "%s - urb shutting down with status: %d\n", in xpad_irq_out()
1311 xpad->irq_out_active = false; in xpad_irq_out()
1315 dev_dbg(dev, "%s - nonzero urb status received: %d\n", in xpad_irq_out()
1320 if (xpad->irq_out_active) { in xpad_irq_out()
1321 usb_anchor_urb(urb, &xpad->irq_out_anchor); in xpad_irq_out()
1325 "%s - usb_submit_urb failed with result %d\n", in xpad_irq_out()
1328 xpad->irq_out_active = false; in xpad_irq_out()
1332 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_irq_out()
1340 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_output()
1343 init_usb_anchor(&xpad->irq_out_anchor); in xpad_init_output()
1345 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_init_output()
1346 GFP_KERNEL, &xpad->odata_dma); in xpad_init_output()
1347 if (!xpad->odata) in xpad_init_output()
1348 return -ENOMEM; in xpad_init_output()
1350 spin_lock_init(&xpad->odata_lock); in xpad_init_output()
1352 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); in xpad_init_output()
1353 if (!xpad->irq_out) { in xpad_init_output()
1354 error = -ENOMEM; in xpad_init_output()
1358 usb_fill_int_urb(xpad->irq_out, xpad->udev, in xpad_init_output()
1359 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), in xpad_init_output()
1360 xpad->odata, XPAD_PKT_LEN, in xpad_init_output()
1361 xpad_irq_out, xpad, ep_irq_out->bInterval); in xpad_init_output()
1362 xpad->irq_out->transfer_dma = xpad->odata_dma; in xpad_init_output()
1363 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_init_output()
1368 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); in xpad_init_output()
1374 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_stop_output()
1375 if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, in xpad_stop_output()
1377 dev_warn(&xpad->intf->dev, in xpad_stop_output()
1379 usb_kill_anchored_urbs(&xpad->irq_out_anchor); in xpad_stop_output()
1386 if (xpad->xtype != XTYPE_UNKNOWN) { in xpad_deinit_output()
1387 usb_free_urb(xpad->irq_out); in xpad_deinit_output()
1388 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_deinit_output()
1389 xpad->odata, xpad->odata_dma); in xpad_deinit_output()
1396 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad_inquiry_pad_presence()
1400 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1402 packet->data[0] = 0x08; in xpad_inquiry_pad_presence()
1403 packet->data[1] = 0x00; in xpad_inquiry_pad_presence()
1404 packet->data[2] = 0x0F; in xpad_inquiry_pad_presence()
1405 packet->data[3] = 0xC0; in xpad_inquiry_pad_presence()
1406 packet->data[4] = 0x00; in xpad_inquiry_pad_presence()
1407 packet->data[5] = 0x00; in xpad_inquiry_pad_presence()
1408 packet->data[6] = 0x00; in xpad_inquiry_pad_presence()
1409 packet->data[7] = 0x00; in xpad_inquiry_pad_presence()
1410 packet->data[8] = 0x00; in xpad_inquiry_pad_presence()
1411 packet->data[9] = 0x00; in xpad_inquiry_pad_presence()
1412 packet->data[10] = 0x00; in xpad_inquiry_pad_presence()
1413 packet->data[11] = 0x00; in xpad_inquiry_pad_presence()
1414 packet->len = 12; in xpad_inquiry_pad_presence()
1415 packet->pending = true; in xpad_inquiry_pad_presence()
1418 xpad->last_out_packet = -1; in xpad_inquiry_pad_presence()
1421 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_inquiry_pad_presence()
1431 if (usb_ifnum_to_if(xpad->udev, GIP_WIRED_INTF_AUDIO)) { in xpad_start_xbox_one()
1435 * Controller for Series X|S (0x20d6:0x200e) to report the in xpad_start_xbox_one()
1438 retval = usb_set_interface(xpad->udev, in xpad_start_xbox_one()
1441 dev_warn(&xpad->dev->dev, in xpad_start_xbox_one()
1446 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1453 xpad->init_seq = 0; in xpad_start_xbox_one()
1456 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_start_xbox_one()
1465 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpadone_ack_mode_report()
1471 spin_lock_irqsave(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1473 packet->len = sizeof(mode_report_ack); in xpadone_ack_mode_report()
1474 memcpy(packet->data, mode_report_ack, packet->len); in xpadone_ack_mode_report()
1475 packet->data[2] = seq_num; in xpadone_ack_mode_report()
1476 packet->pending = true; in xpadone_ack_mode_report()
1479 xpad->last_out_packet = -1; in xpadone_ack_mode_report()
1482 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpadone_ack_mode_report()
1486 static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) in xpad_play_effect() argument
1489 struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; in xpad_play_effect()
1495 if (effect->type != FF_RUMBLE) in xpad_play_effect()
1498 strong = effect->u.rumble.strong_magnitude; in xpad_play_effect()
1499 weak = effect->u.rumble.weak_magnitude; in xpad_play_effect()
1501 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_play_effect()
1503 switch (xpad->xtype) { in xpad_play_effect()
1505 packet->data[0] = 0x00; in xpad_play_effect()
1506 packet->data[1] = 0x06; in xpad_play_effect()
1507 packet->data[2] = 0x00; in xpad_play_effect()
1508 packet->data[3] = strong / 256; /* left actuator */ in xpad_play_effect()
1509 packet->data[4] = 0x00; in xpad_play_effect()
1510 packet->data[5] = weak / 256; /* right actuator */ in xpad_play_effect()
1511 packet->len = 6; in xpad_play_effect()
1512 packet->pending = true; in xpad_play_effect()
1516 packet->data[0] = 0x00; in xpad_play_effect()
1517 packet->data[1] = 0x08; in xpad_play_effect()
1518 packet->data[2] = 0x00; in xpad_play_effect()
1519 packet->data[3] = strong / 256; /* left actuator? */ in xpad_play_effect()
1520 packet->data[4] = weak / 256; /* right actuator? */ in xpad_play_effect()
1521 packet->data[5] = 0x00; in xpad_play_effect()
1522 packet->data[6] = 0x00; in xpad_play_effect()
1523 packet->data[7] = 0x00; in xpad_play_effect()
1524 packet->len = 8; in xpad_play_effect()
1525 packet->pending = true; in xpad_play_effect()
1529 packet->data[0] = 0x00; in xpad_play_effect()
1530 packet->data[1] = 0x01; in xpad_play_effect()
1531 packet->data[2] = 0x0F; in xpad_play_effect()
1532 packet->data[3] = 0xC0; in xpad_play_effect()
1533 packet->data[4] = 0x00; in xpad_play_effect()
1534 packet->data[5] = strong / 256; in xpad_play_effect()
1535 packet->data[6] = weak / 256; in xpad_play_effect()
1536 packet->data[7] = 0x00; in xpad_play_effect()
1537 packet->data[8] = 0x00; in xpad_play_effect()
1538 packet->data[9] = 0x00; in xpad_play_effect()
1539 packet->data[10] = 0x00; in xpad_play_effect()
1540 packet->data[11] = 0x00; in xpad_play_effect()
1541 packet->len = 12; in xpad_play_effect()
1542 packet->pending = true; in xpad_play_effect()
1546 packet->data[0] = GIP_CMD_RUMBLE; /* activate rumble */ in xpad_play_effect()
1547 packet->data[1] = 0x00; in xpad_play_effect()
1548 packet->data[2] = xpad->odata_serial++; in xpad_play_effect()
1549 packet->data[3] = GIP_PL_LEN(9); in xpad_play_effect()
1550 packet->data[4] = 0x00; in xpad_play_effect()
1551 packet->data[5] = GIP_MOTOR_ALL; in xpad_play_effect()
1552 packet->data[6] = 0x00; /* left trigger */ in xpad_play_effect()
1553 packet->data[7] = 0x00; /* right trigger */ in xpad_play_effect()
1554 packet->data[8] = strong / 512; /* left actuator */ in xpad_play_effect()
1555 packet->data[9] = weak / 512; /* right actuator */ in xpad_play_effect()
1556 packet->data[10] = 0xFF; /* on period */ in xpad_play_effect()
1557 packet->data[11] = 0x00; /* off period */ in xpad_play_effect()
1558 packet->data[12] = 0xFF; /* repeat count */ in xpad_play_effect()
1559 packet->len = 13; in xpad_play_effect()
1560 packet->pending = true; in xpad_play_effect()
1564 dev_dbg(&xpad->dev->dev, in xpad_play_effect()
1565 "%s - rumble command sent to unsupported xpad type: %d\n", in xpad_play_effect()
1566 __func__, xpad->xtype); in xpad_play_effect()
1567 retval = -EINVAL; in xpad_play_effect()
1574 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_play_effect()
1580 if (xpad->xtype == XTYPE_UNKNOWN) in xpad_init_ff()
1583 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); in xpad_init_ff()
1585 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); in xpad_init_ff()
1609 * 2: 1/top-left blink, then on
1610 * 3: 2/top-right blink, then on
1611 * 4: 3/bottom-left blink, then on
1612 * 5: 4/bottom-right blink, then on
1613 * 6: 1/top-left on
1614 * 7: 2/top-right on
1615 * 8: 3/bottom-left on
1616 * 9: 4/bottom-right on
1627 &xpad->out_packets[XPAD_OUT_LED_IDX]; in xpad_send_led_command()
1632 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad_send_led_command()
1634 switch (xpad->xtype) { in xpad_send_led_command()
1636 packet->data[0] = 0x01; in xpad_send_led_command()
1637 packet->data[1] = 0x03; in xpad_send_led_command()
1638 packet->data[2] = command; in xpad_send_led_command()
1639 packet->len = 3; in xpad_send_led_command()
1640 packet->pending = true; in xpad_send_led_command()
1644 packet->data[0] = 0x00; in xpad_send_led_command()
1645 packet->data[1] = 0x00; in xpad_send_led_command()
1646 packet->data[2] = 0x08; in xpad_send_led_command()
1647 packet->data[3] = 0x40 + command; in xpad_send_led_command()
1648 packet->data[4] = 0x00; in xpad_send_led_command()
1649 packet->data[5] = 0x00; in xpad_send_led_command()
1650 packet->data[6] = 0x00; in xpad_send_led_command()
1651 packet->data[7] = 0x00; in xpad_send_led_command()
1652 packet->data[8] = 0x00; in xpad_send_led_command()
1653 packet->data[9] = 0x00; in xpad_send_led_command()
1654 packet->data[10] = 0x00; in xpad_send_led_command()
1655 packet->data[11] = 0x00; in xpad_send_led_command()
1656 packet->len = 12; in xpad_send_led_command()
1657 packet->pending = true; in xpad_send_led_command()
1663 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad_send_led_command()
1672 led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); in xpad_identify_controller()
1681 xpad_send_led_command(xpad_led->xpad, value); in xpad_led_set()
1690 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) in xpad_led_probe()
1693 xpad->led = led = kzalloc(sizeof(*led), GFP_KERNEL); in xpad_led_probe()
1695 return -ENOMEM; in xpad_led_probe()
1697 xpad->pad_nr = ida_alloc(&xpad_pad_seq, GFP_KERNEL); in xpad_led_probe()
1698 if (xpad->pad_nr < 0) { in xpad_led_probe()
1699 error = xpad->pad_nr; in xpad_led_probe()
1703 snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); in xpad_led_probe()
1704 led->xpad = xpad; in xpad_led_probe()
1706 led_cdev = &led->led_cdev; in xpad_led_probe()
1707 led_cdev->name = led->name; in xpad_led_probe()
1708 led_cdev->brightness_set = xpad_led_set; in xpad_led_probe()
1709 led_cdev->flags = LED_CORE_SUSPENDRESUME; in xpad_led_probe()
1711 error = led_classdev_register(&xpad->udev->dev, led_cdev); in xpad_led_probe()
1720 ida_free(&xpad_pad_seq, xpad->pad_nr); in xpad_led_probe()
1723 xpad->led = NULL; in xpad_led_probe()
1729 struct xpad_led *xpad_led = xpad->led; in xpad_led_disconnect()
1732 led_classdev_unregister(&xpad_led->led_cdev); in xpad_led_disconnect()
1733 ida_free(&xpad_pad_seq, xpad->pad_nr); in xpad_led_disconnect()
1746 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) in xpad_start_input()
1747 return -EIO; in xpad_start_input()
1749 if (xpad->xtype == XTYPE_XBOXONE) { in xpad_start_input()
1752 usb_kill_urb(xpad->irq_in); in xpad_start_input()
1756 if (xpad->xtype == XTYPE_XBOX360) { in xpad_start_input()
1758 * Some third-party controllers Xbox 360-style controllers in xpad_start_input()
1763 error = usb_control_msg_recv(xpad->udev, 0, in xpad_start_input()
1773 dev_warn(&xpad->dev->dev, in xpad_start_input()
1783 usb_kill_urb(xpad->irq_in); in xpad_stop_input()
1790 &xpad->out_packets[XPAD_OUT_CMD_IDX]; in xpad360w_poweroff_controller()
1792 spin_lock_irqsave(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1794 packet->data[0] = 0x00; in xpad360w_poweroff_controller()
1795 packet->data[1] = 0x00; in xpad360w_poweroff_controller()
1796 packet->data[2] = 0x08; in xpad360w_poweroff_controller()
1797 packet->data[3] = 0xC0; in xpad360w_poweroff_controller()
1798 packet->data[4] = 0x00; in xpad360w_poweroff_controller()
1799 packet->data[5] = 0x00; in xpad360w_poweroff_controller()
1800 packet->data[6] = 0x00; in xpad360w_poweroff_controller()
1801 packet->data[7] = 0x00; in xpad360w_poweroff_controller()
1802 packet->data[8] = 0x00; in xpad360w_poweroff_controller()
1803 packet->data[9] = 0x00; in xpad360w_poweroff_controller()
1804 packet->data[10] = 0x00; in xpad360w_poweroff_controller()
1805 packet->data[11] = 0x00; in xpad360w_poweroff_controller()
1806 packet->len = 12; in xpad360w_poweroff_controller()
1807 packet->pending = true; in xpad360w_poweroff_controller()
1810 xpad->last_out_packet = -1; in xpad360w_poweroff_controller()
1813 spin_unlock_irqrestore(&xpad->odata_lock, flags); in xpad360w_poweroff_controller()
1820 error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); in xpad360w_start_input()
1822 return -EIO; in xpad360w_start_input()
1826 * This will force the controller to resend connection packets. in xpad360w_start_input()
1833 usb_kill_urb(xpad->irq_in); in xpad360w_start_input()
1842 usb_kill_urb(xpad->irq_in); in xpad360w_stop_input()
1845 flush_work(&xpad->work); in xpad360w_stop_input()
1871 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); in xpad_set_up_abs()
1875 if (xpad->xtype == XTYPE_XBOXONE) in xpad_set_up_abs()
1881 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ in xpad_set_up_abs()
1882 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); in xpad_set_up_abs()
1895 if (xpad->input_created) { in xpad_deinit_input()
1896 xpad->input_created = false; in xpad_deinit_input()
1898 input_unregister_device(xpad->dev); in xpad_deinit_input()
1909 return -ENOMEM; in xpad_init_input()
1911 xpad->dev = input_dev; in xpad_init_input()
1912 input_dev->name = xpad->name; in xpad_init_input()
1913 input_dev->phys = xpad->phys; in xpad_init_input()
1914 usb_to_input_id(xpad->udev, &input_dev->id); in xpad_init_input()
1916 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1918 input_dev->id.product = 0x02a1; in xpad_init_input()
1921 input_dev->dev.parent = &xpad->intf->dev; in xpad_init_input()
1925 if (xpad->xtype != XTYPE_XBOX360W) { in xpad_init_input()
1926 input_dev->open = xpad_open; in xpad_init_input()
1927 input_dev->close = xpad_close; in xpad_init_input()
1930 if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { in xpad_init_input()
1940 /* set up model-specific ones */ in xpad_init_input()
1941 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || in xpad_init_input()
1942 xpad->xtype == XTYPE_XBOXONE) { in xpad_init_input()
1945 if (xpad->mapping & MAP_SELECT_BUTTON) in xpad_init_input()
1952 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { in xpad_init_input()
1958 /* set up paddles if the controller has them */ in xpad_init_input()
1959 if (xpad->mapping & MAP_PADDLES) { in xpad_init_input()
1970 if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || in xpad_init_input()
1971 xpad->xtype == XTYPE_XBOX360W) { in xpad_init_input()
1976 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { in xpad_init_input()
1986 if (xpad->mapping & MAP_PROFILE_BUTTON) in xpad_init_input()
1997 error = input_register_device(xpad->dev); in xpad_init_input()
2001 xpad->input_created = true; in xpad_init_input()
2020 if (intf->cur_altsetting->desc.bNumEndpoints != 2) in xpad_probe()
2021 return -ENODEV; in xpad_probe()
2024 if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && in xpad_probe()
2025 (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) in xpad_probe()
2031 return -ENOMEM; in xpad_probe()
2033 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); in xpad_probe()
2034 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); in xpad_probe()
2036 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, in xpad_probe()
2037 GFP_KERNEL, &xpad->idata_dma); in xpad_probe()
2038 if (!xpad->idata) { in xpad_probe()
2039 error = -ENOMEM; in xpad_probe()
2043 xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); in xpad_probe()
2044 if (!xpad->irq_in) { in xpad_probe()
2045 error = -ENOMEM; in xpad_probe()
2049 xpad->udev = udev; in xpad_probe()
2050 xpad->intf = intf; in xpad_probe()
2051 xpad->mapping = xpad_device[i].mapping; in xpad_probe()
2052 xpad->xtype = xpad_device[i].xtype; in xpad_probe()
2053 xpad->name = xpad_device[i].name; in xpad_probe()
2054 xpad->packet_type = PKT_XB; in xpad_probe()
2055 INIT_WORK(&xpad->work, xpad_presence_work); in xpad_probe()
2057 if (xpad->xtype == XTYPE_UNKNOWN) { in xpad_probe()
2058 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { in xpad_probe()
2059 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) in xpad_probe()
2060 xpad->xtype = XTYPE_XBOX360W; in xpad_probe()
2061 else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) in xpad_probe()
2062 xpad->xtype = XTYPE_XBOXONE; in xpad_probe()
2064 xpad->xtype = XTYPE_XBOX360; in xpad_probe()
2066 xpad->xtype = XTYPE_XBOX; in xpad_probe()
2070 xpad->mapping |= MAP_DPAD_TO_BUTTONS; in xpad_probe()
2072 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; in xpad_probe()
2074 xpad->mapping |= MAP_STICKS_TO_NULL; in xpad_probe()
2077 if (xpad->xtype == XTYPE_XBOXONE && in xpad_probe()
2078 intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) { in xpad_probe()
2080 * The Xbox One controller lists three interfaces all with the in xpad_probe()
2084 error = -ENODEV; in xpad_probe()
2092 &intf->cur_altsetting->endpoint[i].desc; in xpad_probe()
2103 error = -ENODEV; in xpad_probe()
2111 usb_fill_int_urb(xpad->irq_in, udev, in xpad_probe()
2112 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), in xpad_probe()
2113 xpad->idata, XPAD_PKT_LEN, xpad_irq_in, in xpad_probe()
2114 xpad, ep_irq_in->bInterval); in xpad_probe()
2115 xpad->irq_in->transfer_dma = xpad->idata_dma; in xpad_probe()
2116 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in xpad_probe()
2121 if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ in xpad_probe()
2122 if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { in xpad_probe()
2123 /* The original elite controller always uses the oldest in xpad_probe()
2126 xpad->packet_type = PKT_XBE1; in xpad_probe()
2127 } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { in xpad_probe()
2128 /* The elite 2 controller has seen multiple packet in xpad_probe()
2132 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { in xpad_probe()
2136 xpad->packet_type = PKT_XBE2_FW_OLD; in xpad_probe()
2137 } else if (le16_to_cpu(udev->descriptor.bcdDevice) < in xpad_probe()
2142 xpad->packet_type = PKT_XBE2_FW_5_EARLY; in xpad_probe()
2147 xpad->packet_type = PKT_XBE2_FW_5_11; in xpad_probe()
2152 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_probe()
2157 * exactly the message that a controller has arrived that in xpad_probe()
2170 udev->quirks |= USB_QUIRK_RESET_RESUME; in xpad_probe()
2181 usb_free_urb(xpad->irq_in); in xpad_probe()
2183 usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); in xpad_probe()
2193 if (xpad->xtype == XTYPE_XBOX360W) in xpad_disconnect()
2206 usb_free_urb(xpad->irq_in); in xpad_disconnect()
2207 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, in xpad_disconnect()
2208 xpad->idata, xpad->idata_dma); in xpad_disconnect()
2218 struct input_dev *input = xpad->dev; in xpad_suspend()
2220 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_suspend()
2223 * they are notified when controller shows up in xpad_suspend()
2234 if (auto_poweroff && xpad->pad_present) in xpad_suspend()
2237 mutex_lock(&input->mutex); in xpad_suspend()
2240 mutex_unlock(&input->mutex); in xpad_suspend()
2251 struct input_dev *input = xpad->dev; in xpad_resume()
2254 if (xpad->xtype == XTYPE_XBOX360W) { in xpad_resume()
2257 mutex_lock(&input->mutex); in xpad_resume()
2260 } else if (xpad->xtype == XTYPE_XBOXONE) { in xpad_resume()
2268 mutex_unlock(&input->mutex); in xpad_resume()
2285 MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");