18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * X-Box gamepad driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> 68c2ecf20Sopenharmony_ci * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>, 78c2ecf20Sopenharmony_ci * Steven Toth <steve@toth.demon.co.uk>, 88c2ecf20Sopenharmony_ci * Franz Lehner <franz@caos.at>, 98c2ecf20Sopenharmony_ci * Ivan Hawkes <blackhawk@ivanhawkes.com> 108c2ecf20Sopenharmony_ci * 2005 Dominic Cerquetti <binary1230@yahoo.com> 118c2ecf20Sopenharmony_ci * 2006 Adam Buchbinder <adam.buchbinder@gmail.com> 128c2ecf20Sopenharmony_ci * 2007 Jan Kratochvil <honza@jikos.cz> 138c2ecf20Sopenharmony_ci * 2010 Christoph Fritz <chf.fritz@googlemail.com> 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * This driver is based on: 168c2ecf20Sopenharmony_ci * - information from http://euc.jp/periphs/xbox-controller.ja.html 178c2ecf20Sopenharmony_ci * - the iForce driver drivers/char/joystick/iforce.c 188c2ecf20Sopenharmony_ci * - the skeleton-driver drivers/usb/usb-skeleton.c 198c2ecf20Sopenharmony_ci * - Xbox 360 information http://www.free60.org/wiki/Gamepad 208c2ecf20Sopenharmony_ci * - Xbox One information https://github.com/quantus/xbox-one-controller-protocol 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * Thanks to: 238c2ecf20Sopenharmony_ci * - ITO Takayuki for providing essential xpad information on his website 248c2ecf20Sopenharmony_ci * - Vojtech Pavlik - iforce driver / input subsystem 258c2ecf20Sopenharmony_ci * - Greg Kroah-Hartman - usb-skeleton driver 268c2ecf20Sopenharmony_ci * - XBOX Linux project - extra USB id's 278c2ecf20Sopenharmony_ci * - Pekka Pöyry (quantus) - Xbox One controller reverse engineering 288c2ecf20Sopenharmony_ci * 298c2ecf20Sopenharmony_ci * TODO: 308c2ecf20Sopenharmony_ci * - fine tune axes (especially trigger axes) 318c2ecf20Sopenharmony_ci * - fix "analog" buttons (reported as digital now) 328c2ecf20Sopenharmony_ci * - get rumble working 338c2ecf20Sopenharmony_ci * - need USB IDs for other dance pads 348c2ecf20Sopenharmony_ci * 358c2ecf20Sopenharmony_ci * History: 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller" 388c2ecf20Sopenharmony_ci * 398c2ecf20Sopenharmony_ci * 2002-07-02 - 0.0.2 : basic working version 408c2ecf20Sopenharmony_ci * - all axes and 9 of the 10 buttons work (german InterAct device) 418c2ecf20Sopenharmony_ci * - the black button does not work 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik 448c2ecf20Sopenharmony_ci * - indentation fixes 458c2ecf20Sopenharmony_ci * - usb + input init sequence fixes 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3 488c2ecf20Sopenharmony_ci * - verified the lack of HID and report descriptors 498c2ecf20Sopenharmony_ci * - verified that ALL buttons WORK 508c2ecf20Sopenharmony_ci * - fixed d-pad to axes mapping 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * 2002-07-17 - 0.0.5 : simplified d-pad handling 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * 2004-10-02 - 0.0.6 : DDR pad support 558c2ecf20Sopenharmony_ci * - borrowed from the XBOX linux kernel 568c2ecf20Sopenharmony_ci * - USB id's for commonly used dance pads are present 578c2ecf20Sopenharmony_ci * - dance pads will map D-PAD to buttons, not axes 588c2ecf20Sopenharmony_ci * - pass the module paramater 'dpad_to_buttons' to force 598c2ecf20Sopenharmony_ci * the D-PAD to map to buttons if your pad is not detected 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * Later changes can be tracked in SCM. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#include <linux/kernel.h> 658c2ecf20Sopenharmony_ci#include <linux/input.h> 668c2ecf20Sopenharmony_ci#include <linux/rcupdate.h> 678c2ecf20Sopenharmony_ci#include <linux/slab.h> 688c2ecf20Sopenharmony_ci#include <linux/stat.h> 698c2ecf20Sopenharmony_ci#include <linux/module.h> 708c2ecf20Sopenharmony_ci#include <linux/usb/input.h> 718c2ecf20Sopenharmony_ci#include <linux/usb/quirks.h> 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define XPAD_PKT_LEN 64 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* 768c2ecf20Sopenharmony_ci * xbox d-pads should map to buttons, as is required for DDR pads 778c2ecf20Sopenharmony_ci * but we map them to axes when possible to simplify things 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci#define MAP_DPAD_TO_BUTTONS (1 << 0) 808c2ecf20Sopenharmony_ci#define MAP_TRIGGERS_TO_BUTTONS (1 << 1) 818c2ecf20Sopenharmony_ci#define MAP_STICKS_TO_NULL (1 << 2) 828c2ecf20Sopenharmony_ci#define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \ 838c2ecf20Sopenharmony_ci MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define XTYPE_XBOX 0 868c2ecf20Sopenharmony_ci#define XTYPE_XBOX360 1 878c2ecf20Sopenharmony_ci#define XTYPE_XBOX360W 2 888c2ecf20Sopenharmony_ci#define XTYPE_XBOXONE 3 898c2ecf20Sopenharmony_ci#define XTYPE_UNKNOWN 4 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic bool dpad_to_buttons; 928c2ecf20Sopenharmony_cimodule_param(dpad_to_buttons, bool, S_IRUGO); 938c2ecf20Sopenharmony_ciMODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads"); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistatic bool triggers_to_buttons; 968c2ecf20Sopenharmony_cimodule_param(triggers_to_buttons, bool, S_IRUGO); 978c2ecf20Sopenharmony_ciMODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads"); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistatic bool sticks_to_null; 1008c2ecf20Sopenharmony_cimodule_param(sticks_to_null, bool, S_IRUGO); 1018c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads"); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic bool auto_poweroff = true; 1048c2ecf20Sopenharmony_cimodule_param(auto_poweroff, bool, S_IWUSR | S_IRUGO); 1058c2ecf20Sopenharmony_ciMODULE_PARM_DESC(auto_poweroff, "Power off wireless controllers on suspend"); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const struct xpad_device { 1088c2ecf20Sopenharmony_ci u16 idVendor; 1098c2ecf20Sopenharmony_ci u16 idProduct; 1108c2ecf20Sopenharmony_ci char *name; 1118c2ecf20Sopenharmony_ci u8 mapping; 1128c2ecf20Sopenharmony_ci u8 xtype; 1138c2ecf20Sopenharmony_ci} xpad_device[] = { 1148c2ecf20Sopenharmony_ci { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 }, 1158c2ecf20Sopenharmony_ci { 0x03eb, 0xff01, "Wooting One (Legacy)", 0, XTYPE_XBOX360 }, 1168c2ecf20Sopenharmony_ci { 0x03eb, 0xff02, "Wooting Two (Legacy)", 0, XTYPE_XBOX360 }, 1178c2ecf20Sopenharmony_ci { 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX }, 1188c2ecf20Sopenharmony_ci { 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX }, 1198c2ecf20Sopenharmony_ci { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX }, 1208c2ecf20Sopenharmony_ci { 0x044f, 0x0f10, "Thrustmaster Modena GT Wheel", 0, XTYPE_XBOX }, 1218c2ecf20Sopenharmony_ci { 0x044f, 0xb326, "Thrustmaster Gamepad GP XID", 0, XTYPE_XBOX360 }, 1228c2ecf20Sopenharmony_ci { 0x03f0, 0x0495, "HyperX Clutch Gladiate", 0, XTYPE_XBOXONE }, 1238c2ecf20Sopenharmony_ci { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX }, 1248c2ecf20Sopenharmony_ci { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX }, 1258c2ecf20Sopenharmony_ci { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX }, 1268c2ecf20Sopenharmony_ci { 0x045e, 0x0288, "Microsoft Xbox Controller S v2", 0, XTYPE_XBOX }, 1278c2ecf20Sopenharmony_ci { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX }, 1288c2ecf20Sopenharmony_ci { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 }, 1298c2ecf20Sopenharmony_ci { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 }, 1308c2ecf20Sopenharmony_ci { 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 1318c2ecf20Sopenharmony_ci { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE }, 1328c2ecf20Sopenharmony_ci { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE }, 1338c2ecf20Sopenharmony_ci { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE }, 1348c2ecf20Sopenharmony_ci { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE }, 1358c2ecf20Sopenharmony_ci { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 1368c2ecf20Sopenharmony_ci { 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 }, 1378c2ecf20Sopenharmony_ci { 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 }, 1388c2ecf20Sopenharmony_ci { 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 }, 1398c2ecf20Sopenharmony_ci { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 }, 1408c2ecf20Sopenharmony_ci { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX }, 1418c2ecf20Sopenharmony_ci { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX }, 1428c2ecf20Sopenharmony_ci { 0x046d, 0xca8a, "Logitech Precision Vibration Feedback Wheel", 0, XTYPE_XBOX }, 1438c2ecf20Sopenharmony_ci { 0x046d, 0xcaa3, "Logitech DriveFx Racing Wheel", 0, XTYPE_XBOX360 }, 1448c2ecf20Sopenharmony_ci { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 }, 1458c2ecf20Sopenharmony_ci { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX }, 1468c2ecf20Sopenharmony_ci { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX }, 1478c2ecf20Sopenharmony_ci { 0x05fe, 0x3030, "Chic Controller", 0, XTYPE_XBOX }, 1488c2ecf20Sopenharmony_ci { 0x05fe, 0x3031, "Chic Controller", 0, XTYPE_XBOX }, 1498c2ecf20Sopenharmony_ci { 0x062a, 0x0020, "Logic3 Xbox GamePad", 0, XTYPE_XBOX }, 1508c2ecf20Sopenharmony_ci { 0x062a, 0x0033, "Competition Pro Steering Wheel", 0, XTYPE_XBOX }, 1518c2ecf20Sopenharmony_ci { 0x06a3, 0x0200, "Saitek Racing Wheel", 0, XTYPE_XBOX }, 1528c2ecf20Sopenharmony_ci { 0x06a3, 0x0201, "Saitek Adrenalin", 0, XTYPE_XBOX }, 1538c2ecf20Sopenharmony_ci { 0x06a3, 0xf51a, "Saitek P3600", 0, XTYPE_XBOX360 }, 1548c2ecf20Sopenharmony_ci { 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX }, 1558c2ecf20Sopenharmony_ci { 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX }, 1568c2ecf20Sopenharmony_ci { 0x0738, 0x4520, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX }, 1578c2ecf20Sopenharmony_ci { 0x0738, 0x4522, "Mad Catz LumiCON", 0, XTYPE_XBOX }, 1588c2ecf20Sopenharmony_ci { 0x0738, 0x4526, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX }, 1598c2ecf20Sopenharmony_ci { 0x0738, 0x4530, "Mad Catz Universal MC2 Racing Wheel and Pedals", 0, XTYPE_XBOX }, 1608c2ecf20Sopenharmony_ci { 0x0738, 0x4536, "Mad Catz MicroCON", 0, XTYPE_XBOX }, 1618c2ecf20Sopenharmony_ci { 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 1628c2ecf20Sopenharmony_ci { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX }, 1638c2ecf20Sopenharmony_ci { 0x0738, 0x4586, "Mad Catz MicroCon Wireless Controller", 0, XTYPE_XBOX }, 1648c2ecf20Sopenharmony_ci { 0x0738, 0x4588, "Mad Catz Blaster", 0, XTYPE_XBOX }, 1658c2ecf20Sopenharmony_ci { 0x0738, 0x45ff, "Mad Catz Beat Pad (w/ Handle)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 1668c2ecf20Sopenharmony_ci { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 }, 1678c2ecf20Sopenharmony_ci { 0x0738, 0x4718, "Mad Catz Street Fighter IV FightStick SE", 0, XTYPE_XBOX360 }, 1688c2ecf20Sopenharmony_ci { 0x0738, 0x4726, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 }, 1698c2ecf20Sopenharmony_ci { 0x0738, 0x4728, "Mad Catz Street Fighter IV FightPad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 1708c2ecf20Sopenharmony_ci { 0x0738, 0x4736, "Mad Catz MicroCon Gamepad", 0, XTYPE_XBOX360 }, 1718c2ecf20Sopenharmony_ci { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 1728c2ecf20Sopenharmony_ci { 0x0738, 0x4740, "Mad Catz Beat Pad", 0, XTYPE_XBOX360 }, 1738c2ecf20Sopenharmony_ci { 0x0738, 0x4743, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 1748c2ecf20Sopenharmony_ci { 0x0738, 0x4758, "Mad Catz Arcade Game Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 1758c2ecf20Sopenharmony_ci { 0x0738, 0x4a01, "Mad Catz FightStick TE 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 1768c2ecf20Sopenharmony_ci { 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 1778c2ecf20Sopenharmony_ci { 0x0738, 0x9871, "Mad Catz Portable Drum", 0, XTYPE_XBOX360 }, 1788c2ecf20Sopenharmony_ci { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 }, 1798c2ecf20Sopenharmony_ci { 0x0738, 0xb738, "Mad Catz MVC2TE Stick 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 1808c2ecf20Sopenharmony_ci { 0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad", XTYPE_XBOX360 }, 1818c2ecf20Sopenharmony_ci { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 }, 1828c2ecf20Sopenharmony_ci { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 }, 1838c2ecf20Sopenharmony_ci { 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 }, 1848c2ecf20Sopenharmony_ci { 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 }, 1858c2ecf20Sopenharmony_ci { 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 }, 1868c2ecf20Sopenharmony_ci { 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX }, 1878c2ecf20Sopenharmony_ci { 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX }, 1888c2ecf20Sopenharmony_ci { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX }, 1898c2ecf20Sopenharmony_ci { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", DANCEPAD_MAP_CONFIG, XTYPE_XBOX }, 1908c2ecf20Sopenharmony_ci { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX }, 1918c2ecf20Sopenharmony_ci { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX }, 1928c2ecf20Sopenharmony_ci { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX }, 1938c2ecf20Sopenharmony_ci { 0x0d2f, 0x0002, "Andamiro Pump It Up pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 1948c2ecf20Sopenharmony_ci { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX }, 1958c2ecf20Sopenharmony_ci { 0x0e4c, 0x1103, "Radica Gamester Reflex", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX }, 1968c2ecf20Sopenharmony_ci { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX }, 1978c2ecf20Sopenharmony_ci { 0x0e4c, 0x3510, "Radica Gamester", 0, XTYPE_XBOX }, 1988c2ecf20Sopenharmony_ci { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX }, 1998c2ecf20Sopenharmony_ci { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX }, 2008c2ecf20Sopenharmony_ci { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX }, 2018c2ecf20Sopenharmony_ci { 0x0e6f, 0x0008, "After Glow Pro Controller", 0, XTYPE_XBOX }, 2028c2ecf20Sopenharmony_ci { 0x0e6f, 0x0105, "HSM3 Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 2038c2ecf20Sopenharmony_ci { 0x0e6f, 0x0113, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 2048c2ecf20Sopenharmony_ci { 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 }, 2058c2ecf20Sopenharmony_ci { 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 }, 2068c2ecf20Sopenharmony_ci { 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 }, 2078c2ecf20Sopenharmony_ci { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE }, 2088c2ecf20Sopenharmony_ci { 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2098c2ecf20Sopenharmony_ci { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE }, 2108c2ecf20Sopenharmony_ci { 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE }, 2118c2ecf20Sopenharmony_ci { 0x0e6f, 0x015c, "PDP Xbox One Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 2128c2ecf20Sopenharmony_ci { 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2138c2ecf20Sopenharmony_ci { 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2148c2ecf20Sopenharmony_ci { 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2158c2ecf20Sopenharmony_ci { 0x0e6f, 0x0164, "PDP Battlefield One", 0, XTYPE_XBOXONE }, 2168c2ecf20Sopenharmony_ci { 0x0e6f, 0x0165, "PDP Titanfall 2", 0, XTYPE_XBOXONE }, 2178c2ecf20Sopenharmony_ci { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 }, 2188c2ecf20Sopenharmony_ci { 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 2198c2ecf20Sopenharmony_ci { 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 2208c2ecf20Sopenharmony_ci { 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE }, 2218c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2228c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2238c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE }, 2248c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE }, 2258c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE }, 2268c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2278c2ecf20Sopenharmony_ci { 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE }, 2288c2ecf20Sopenharmony_ci { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE }, 2298c2ecf20Sopenharmony_ci { 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE }, 2308c2ecf20Sopenharmony_ci { 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE }, 2318c2ecf20Sopenharmony_ci { 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE }, 2328c2ecf20Sopenharmony_ci { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 }, 2338c2ecf20Sopenharmony_ci { 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE }, 2348c2ecf20Sopenharmony_ci { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 }, 2358c2ecf20Sopenharmony_ci { 0x0e6f, 0x0413, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 2368c2ecf20Sopenharmony_ci { 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 }, 2378c2ecf20Sopenharmony_ci { 0x0e6f, 0xf900, "PDP Afterglow AX.1", 0, XTYPE_XBOX360 }, 2388c2ecf20Sopenharmony_ci { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX }, 2398c2ecf20Sopenharmony_ci { 0x0e8f, 0x3008, "Generic xbox control (dealextreme)", 0, XTYPE_XBOX }, 2408c2ecf20Sopenharmony_ci { 0x0f0d, 0x000a, "Hori Co. DOA4 FightStick", 0, XTYPE_XBOX360 }, 2418c2ecf20Sopenharmony_ci { 0x0f0d, 0x000c, "Hori PadEX Turbo", 0, XTYPE_XBOX360 }, 2428c2ecf20Sopenharmony_ci { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2438c2ecf20Sopenharmony_ci { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2448c2ecf20Sopenharmony_ci { 0x0f0d, 0x001b, "Hori Real Arcade Pro VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2458c2ecf20Sopenharmony_ci { 0x0f0d, 0x0063, "Hori Real Arcade Pro Hayabusa (USA) Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 2468c2ecf20Sopenharmony_ci { 0x0f0d, 0x0067, "HORIPAD ONE", 0, XTYPE_XBOXONE }, 2478c2ecf20Sopenharmony_ci { 0x0f0d, 0x0078, "Hori Real Arcade Pro V Kai Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 2488c2ecf20Sopenharmony_ci { 0x0f0d, 0x00c5, "Hori Fighting Commander ONE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 2498c2ecf20Sopenharmony_ci { 0x0f30, 0x010b, "Philips Recoil", 0, XTYPE_XBOX }, 2508c2ecf20Sopenharmony_ci { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX }, 2518c2ecf20Sopenharmony_ci { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX }, 2528c2ecf20Sopenharmony_ci { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX }, 2538c2ecf20Sopenharmony_ci { 0x1038, 0x1430, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 }, 2548c2ecf20Sopenharmony_ci { 0x1038, 0x1431, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 }, 2558c2ecf20Sopenharmony_ci { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 }, 2568c2ecf20Sopenharmony_ci { 0x11ff, 0x0511, "PXN V900", 0, XTYPE_XBOX360 }, 2578c2ecf20Sopenharmony_ci { 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 }, 2588c2ecf20Sopenharmony_ci { 0x12ab, 0x0004, "Honey Bee Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 2598c2ecf20Sopenharmony_ci { 0x12ab, 0x0301, "PDP AFTERGLOW AX.1", 0, XTYPE_XBOX360 }, 2608c2ecf20Sopenharmony_ci { 0x12ab, 0x0303, "Mortal Kombat Klassic FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2618c2ecf20Sopenharmony_ci { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 2628c2ecf20Sopenharmony_ci { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 }, 2638c2ecf20Sopenharmony_ci { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 2648c2ecf20Sopenharmony_ci { 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 }, 2658c2ecf20Sopenharmony_ci { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 }, 2668c2ecf20Sopenharmony_ci { 0x146b, 0x0604, "Bigben Interactive DAIJA Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2678c2ecf20Sopenharmony_ci { 0x1532, 0x0a00, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE }, 2688c2ecf20Sopenharmony_ci { 0x1532, 0x0a03, "Razer Wildcat", 0, XTYPE_XBOXONE }, 2698c2ecf20Sopenharmony_ci { 0x1532, 0x0a29, "Razer Wolverine V2", 0, XTYPE_XBOXONE }, 2708c2ecf20Sopenharmony_ci { 0x15e4, 0x3f00, "Power A Mini Pro Elite", 0, XTYPE_XBOX360 }, 2718c2ecf20Sopenharmony_ci { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 }, 2728c2ecf20Sopenharmony_ci { 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 }, 2738c2ecf20Sopenharmony_ci { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 }, 2748c2ecf20Sopenharmony_ci { 0x1689, 0xfd00, "Razer Onza Tournament Edition", 0, XTYPE_XBOX360 }, 2758c2ecf20Sopenharmony_ci { 0x1689, 0xfd01, "Razer Onza Classic Edition", 0, XTYPE_XBOX360 }, 2768c2ecf20Sopenharmony_ci { 0x1689, 0xfe00, "Razer Sabertooth", 0, XTYPE_XBOX360 }, 2778c2ecf20Sopenharmony_ci { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 }, 2788c2ecf20Sopenharmony_ci { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 2798c2ecf20Sopenharmony_ci { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 2808c2ecf20Sopenharmony_ci { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 }, 2818c2ecf20Sopenharmony_ci { 0x1bad, 0xf018, "Mad Catz Street Fighter IV SE Fighting Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2828c2ecf20Sopenharmony_ci { 0x1bad, 0xf019, "Mad Catz Brawlstick for Xbox 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2838c2ecf20Sopenharmony_ci { 0x1bad, 0xf021, "Mad Cats Ghost Recon FS GamePad", 0, XTYPE_XBOX360 }, 2848c2ecf20Sopenharmony_ci { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 }, 2858c2ecf20Sopenharmony_ci { 0x1bad, 0xf025, "Mad Catz Call Of Duty", 0, XTYPE_XBOX360 }, 2868c2ecf20Sopenharmony_ci { 0x1bad, 0xf027, "Mad Catz FPS Pro", 0, XTYPE_XBOX360 }, 2878c2ecf20Sopenharmony_ci { 0x1bad, 0xf028, "Street Fighter IV FightPad", 0, XTYPE_XBOX360 }, 2888c2ecf20Sopenharmony_ci { 0x1bad, 0xf02e, "Mad Catz Fightpad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2898c2ecf20Sopenharmony_ci { 0x1bad, 0xf030, "Mad Catz Xbox 360 MC2 MicroCon Racing Wheel", 0, XTYPE_XBOX360 }, 2908c2ecf20Sopenharmony_ci { 0x1bad, 0xf036, "Mad Catz MicroCon GamePad Pro", 0, XTYPE_XBOX360 }, 2918c2ecf20Sopenharmony_ci { 0x1bad, 0xf038, "Street Fighter IV FightStick TE", 0, XTYPE_XBOX360 }, 2928c2ecf20Sopenharmony_ci { 0x1bad, 0xf039, "Mad Catz MvC2 TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2938c2ecf20Sopenharmony_ci { 0x1bad, 0xf03a, "Mad Catz SFxT Fightstick Pro", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2948c2ecf20Sopenharmony_ci { 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2958c2ecf20Sopenharmony_ci { 0x1bad, 0xf03e, "Mad Catz MLG FightStick TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2968c2ecf20Sopenharmony_ci { 0x1bad, 0xf03f, "Mad Catz FightStick SoulCaliber", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2978c2ecf20Sopenharmony_ci { 0x1bad, 0xf042, "Mad Catz FightStick TES+", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2988c2ecf20Sopenharmony_ci { 0x1bad, 0xf080, "Mad Catz FightStick TE2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 2998c2ecf20Sopenharmony_ci { 0x1bad, 0xf501, "HoriPad EX2 Turbo", 0, XTYPE_XBOX360 }, 3008c2ecf20Sopenharmony_ci { 0x1bad, 0xf502, "Hori Real Arcade Pro.VX SA", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3018c2ecf20Sopenharmony_ci { 0x1bad, 0xf503, "Hori Fighting Stick VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3028c2ecf20Sopenharmony_ci { 0x1bad, 0xf504, "Hori Real Arcade Pro. EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3038c2ecf20Sopenharmony_ci { 0x1bad, 0xf505, "Hori Fighting Stick EX2B", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3048c2ecf20Sopenharmony_ci { 0x1bad, 0xf506, "Hori Real Arcade Pro.EX Premium VLX", 0, XTYPE_XBOX360 }, 3058c2ecf20Sopenharmony_ci { 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 }, 3068c2ecf20Sopenharmony_ci { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 }, 3078c2ecf20Sopenharmony_ci { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 }, 3088c2ecf20Sopenharmony_ci { 0x1bad, 0xf904, "PDP Versus Fighting Pad", 0, XTYPE_XBOX360 }, 3098c2ecf20Sopenharmony_ci { 0x1bad, 0xf906, "MortalKombat FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3108c2ecf20Sopenharmony_ci { 0x1bad, 0xfa01, "MadCatz GamePad", 0, XTYPE_XBOX360 }, 3118c2ecf20Sopenharmony_ci { 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 }, 3128c2ecf20Sopenharmony_ci { 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 }, 3138c2ecf20Sopenharmony_ci { 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE }, 3148c2ecf20Sopenharmony_ci { 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE }, 3158c2ecf20Sopenharmony_ci { 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 }, 3168c2ecf20Sopenharmony_ci { 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE }, 3178c2ecf20Sopenharmony_ci { 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3188c2ecf20Sopenharmony_ci { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 }, 3198c2ecf20Sopenharmony_ci { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 }, 3208c2ecf20Sopenharmony_ci { 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 }, 3218c2ecf20Sopenharmony_ci { 0x24c6, 0x531a, "PowerA Pro Ex", 0, XTYPE_XBOX360 }, 3228c2ecf20Sopenharmony_ci { 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 }, 3238c2ecf20Sopenharmony_ci { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE }, 3248c2ecf20Sopenharmony_ci { 0x24c6, 0x542a, "Xbox ONE spectra", 0, XTYPE_XBOXONE }, 3258c2ecf20Sopenharmony_ci { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE }, 3268c2ecf20Sopenharmony_ci { 0x24c6, 0x5500, "Hori XBOX 360 EX 2 with Turbo", 0, XTYPE_XBOX360 }, 3278c2ecf20Sopenharmony_ci { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 }, 3288c2ecf20Sopenharmony_ci { 0x24c6, 0x5502, "Hori Fighting Stick VX Alt", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3298c2ecf20Sopenharmony_ci { 0x24c6, 0x5503, "Hori Fighting Edge", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3308c2ecf20Sopenharmony_ci { 0x24c6, 0x5506, "Hori SOULCALIBUR V Stick", 0, XTYPE_XBOX360 }, 3318c2ecf20Sopenharmony_ci { 0x24c6, 0x5510, "Hori Fighting Commander ONE (Xbox 360/PC Mode)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3328c2ecf20Sopenharmony_ci { 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 }, 3338c2ecf20Sopenharmony_ci { 0x24c6, 0x550e, "Hori Real Arcade Pro V Kai 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, 3348c2ecf20Sopenharmony_ci { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE }, 3358c2ecf20Sopenharmony_ci { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE }, 3368c2ecf20Sopenharmony_ci { 0x24c6, 0x5b00, "ThrustMaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 }, 3378c2ecf20Sopenharmony_ci { 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 }, 3388c2ecf20Sopenharmony_ci { 0x24c6, 0x5b03, "Thrustmaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 }, 3398c2ecf20Sopenharmony_ci { 0x24c6, 0x5d04, "Razer Sabertooth", 0, XTYPE_XBOX360 }, 3408c2ecf20Sopenharmony_ci { 0x24c6, 0xfafe, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 }, 3418c2ecf20Sopenharmony_ci { 0x2563, 0x058d, "OneXPlayer Gamepad", 0, XTYPE_XBOX360 }, 3428c2ecf20Sopenharmony_ci { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE }, 3438c2ecf20Sopenharmony_ci { 0x31e3, 0x1100, "Wooting One", 0, XTYPE_XBOX360 }, 3448c2ecf20Sopenharmony_ci { 0x31e3, 0x1200, "Wooting Two", 0, XTYPE_XBOX360 }, 3458c2ecf20Sopenharmony_ci { 0x31e3, 0x1210, "Wooting Lekker", 0, XTYPE_XBOX360 }, 3468c2ecf20Sopenharmony_ci { 0x31e3, 0x1220, "Wooting Two HE", 0, XTYPE_XBOX360 }, 3478c2ecf20Sopenharmony_ci { 0x31e3, 0x1300, "Wooting 60HE (AVR)", 0, XTYPE_XBOX360 }, 3488c2ecf20Sopenharmony_ci { 0x31e3, 0x1310, "Wooting 60HE (ARM)", 0, XTYPE_XBOX360 }, 3498c2ecf20Sopenharmony_ci { 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 }, 3508c2ecf20Sopenharmony_ci { 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX }, 3518c2ecf20Sopenharmony_ci { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX }, 3528c2ecf20Sopenharmony_ci { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN } 3538c2ecf20Sopenharmony_ci}; 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci/* buttons shared with xbox and xbox360 */ 3568c2ecf20Sopenharmony_cistatic const signed short xpad_common_btn[] = { 3578c2ecf20Sopenharmony_ci BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */ 3588c2ecf20Sopenharmony_ci BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */ 3598c2ecf20Sopenharmony_ci -1 /* terminating entry */ 3608c2ecf20Sopenharmony_ci}; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci/* original xbox controllers only */ 3638c2ecf20Sopenharmony_cistatic const signed short xpad_btn[] = { 3648c2ecf20Sopenharmony_ci BTN_C, BTN_Z, /* "analog" buttons */ 3658c2ecf20Sopenharmony_ci -1 /* terminating entry */ 3668c2ecf20Sopenharmony_ci}; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/* used when dpad is mapped to buttons */ 3698c2ecf20Sopenharmony_cistatic const signed short xpad_btn_pad[] = { 3708c2ecf20Sopenharmony_ci BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */ 3718c2ecf20Sopenharmony_ci BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */ 3728c2ecf20Sopenharmony_ci -1 /* terminating entry */ 3738c2ecf20Sopenharmony_ci}; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* used when triggers are mapped to buttons */ 3768c2ecf20Sopenharmony_cistatic const signed short xpad_btn_triggers[] = { 3778c2ecf20Sopenharmony_ci BTN_TL2, BTN_TR2, /* triggers left/right */ 3788c2ecf20Sopenharmony_ci -1 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic const signed short xpad360_btn[] = { /* buttons for x360 controller */ 3828c2ecf20Sopenharmony_ci BTN_TL, BTN_TR, /* Button LB/RB */ 3838c2ecf20Sopenharmony_ci BTN_MODE, /* The big X button */ 3848c2ecf20Sopenharmony_ci -1 3858c2ecf20Sopenharmony_ci}; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_cistatic const signed short xpad_abs[] = { 3888c2ecf20Sopenharmony_ci ABS_X, ABS_Y, /* left stick */ 3898c2ecf20Sopenharmony_ci ABS_RX, ABS_RY, /* right stick */ 3908c2ecf20Sopenharmony_ci -1 /* terminating entry */ 3918c2ecf20Sopenharmony_ci}; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci/* used when dpad is mapped to axes */ 3948c2ecf20Sopenharmony_cistatic const signed short xpad_abs_pad[] = { 3958c2ecf20Sopenharmony_ci ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */ 3968c2ecf20Sopenharmony_ci -1 /* terminating entry */ 3978c2ecf20Sopenharmony_ci}; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci/* used when triggers are mapped to axes */ 4008c2ecf20Sopenharmony_cistatic const signed short xpad_abs_triggers[] = { 4018c2ecf20Sopenharmony_ci ABS_Z, ABS_RZ, /* triggers left/right */ 4028c2ecf20Sopenharmony_ci -1 4038c2ecf20Sopenharmony_ci}; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci/* 4068c2ecf20Sopenharmony_ci * Xbox 360 has a vendor-specific class, so we cannot match it with only 4078c2ecf20Sopenharmony_ci * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we 4088c2ecf20Sopenharmony_ci * match against vendor id as well. Wired Xbox 360 devices have protocol 1, 4098c2ecf20Sopenharmony_ci * wireless controllers have protocol 129. 4108c2ecf20Sopenharmony_ci */ 4118c2ecf20Sopenharmony_ci#define XPAD_XBOX360_VENDOR_PROTOCOL(vend, pr) \ 4128c2ecf20Sopenharmony_ci .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \ 4138c2ecf20Sopenharmony_ci .idVendor = (vend), \ 4148c2ecf20Sopenharmony_ci .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \ 4158c2ecf20Sopenharmony_ci .bInterfaceSubClass = 93, \ 4168c2ecf20Sopenharmony_ci .bInterfaceProtocol = (pr) 4178c2ecf20Sopenharmony_ci#define XPAD_XBOX360_VENDOR(vend) \ 4188c2ecf20Sopenharmony_ci { XPAD_XBOX360_VENDOR_PROTOCOL((vend), 1) }, \ 4198c2ecf20Sopenharmony_ci { XPAD_XBOX360_VENDOR_PROTOCOL((vend), 129) } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci/* The Xbox One controller uses subclass 71 and protocol 208. */ 4228c2ecf20Sopenharmony_ci#define XPAD_XBOXONE_VENDOR_PROTOCOL(vend, pr) \ 4238c2ecf20Sopenharmony_ci .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \ 4248c2ecf20Sopenharmony_ci .idVendor = (vend), \ 4258c2ecf20Sopenharmony_ci .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \ 4268c2ecf20Sopenharmony_ci .bInterfaceSubClass = 71, \ 4278c2ecf20Sopenharmony_ci .bInterfaceProtocol = (pr) 4288c2ecf20Sopenharmony_ci#define XPAD_XBOXONE_VENDOR(vend) \ 4298c2ecf20Sopenharmony_ci { XPAD_XBOXONE_VENDOR_PROTOCOL((vend), 208) } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_cistatic const struct usb_device_id xpad_table[] = { 4328c2ecf20Sopenharmony_ci { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */ 4338c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 Controller */ 4348c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x03eb), /* Wooting Keyboards (Legacy) */ 4358c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x044f), /* Thrustmaster X-Box 360 controllers */ 4368c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x03f0), /* HP HyperX Xbox One Controllers */ 4378c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */ 4388c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x045e), /* Microsoft X-Box One controllers */ 4398c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */ 4408c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */ 4418c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x06a3), /* Saitek P3600 */ 4428c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */ 4438c2ecf20Sopenharmony_ci { USB_DEVICE(0x0738, 0x4540) }, /* Mad Catz Beat Pad */ 4448c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x0738), /* Mad Catz FightStick TE 2 */ 4458c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x07ff), /* Mad Catz GamePad */ 4468c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x0c12), /* Zeroplus X-Box 360 controllers */ 4478c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */ 4488c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x0e6f), /* 0x0e6f X-Box One controllers */ 4498c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */ 4508c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x0f0d), /* Hori Controllers */ 4518c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1038), /* SteelSeries Controllers */ 4528c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x11c9), /* Nacon GC100XF */ 4538c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x11ff), /* PXN V900 */ 4548c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1209), /* Ardwiino Controllers */ 4558c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */ 4568c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */ 4578c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */ 4588c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1532), /* Razer Sabertooth */ 4598c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x1532), /* Razer Wildcat */ 4608c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x15e4), /* Numark X-Box 360 controllers */ 4618c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x162e), /* Joytech X-Box 360 controllers */ 4628c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */ 4638c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */ 4648c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x20d6), /* PowerA Controllers */ 4658c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x20d6), /* PowerA Controllers */ 4668c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */ 4678c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA Controllers */ 4688c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x2563), /* OneXPlayer Gamepad */ 4698c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x260d), /* Dareu H101 */ 4708c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x2dc8), /* 8BitDo Pro 2 Wired Controller for Xbox */ 4718c2ecf20Sopenharmony_ci XPAD_XBOXONE_VENDOR(0x2e24), /* Hyperkin Duke X-Box One pad */ 4728c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x2f24), /* GameSir Controllers */ 4738c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x31e3), /* Wooting Keyboards */ 4748c2ecf20Sopenharmony_ci XPAD_XBOX360_VENDOR(0x3285), /* Nacon GC-100 */ 4758c2ecf20Sopenharmony_ci { } 4768c2ecf20Sopenharmony_ci}; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, xpad_table); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistruct xboxone_init_packet { 4818c2ecf20Sopenharmony_ci u16 idVendor; 4828c2ecf20Sopenharmony_ci u16 idProduct; 4838c2ecf20Sopenharmony_ci const u8 *data; 4848c2ecf20Sopenharmony_ci u8 len; 4858c2ecf20Sopenharmony_ci}; 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci#define XBOXONE_INIT_PKT(_vid, _pid, _data) \ 4888c2ecf20Sopenharmony_ci { \ 4898c2ecf20Sopenharmony_ci .idVendor = (_vid), \ 4908c2ecf20Sopenharmony_ci .idProduct = (_pid), \ 4918c2ecf20Sopenharmony_ci .data = (_data), \ 4928c2ecf20Sopenharmony_ci .len = ARRAY_SIZE(_data), \ 4938c2ecf20Sopenharmony_ci } 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci#define GIP_WIRED_INTF_DATA 0 4978c2ecf20Sopenharmony_ci#define GIP_WIRED_INTF_AUDIO 1 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci/* 5008c2ecf20Sopenharmony_ci * This packet is required for all Xbox One pads with 2015 5018c2ecf20Sopenharmony_ci * or later firmware installed (or present from the factory). 5028c2ecf20Sopenharmony_ci */ 5038c2ecf20Sopenharmony_cistatic const u8 xboxone_fw2015_init[] = { 5048c2ecf20Sopenharmony_ci 0x05, 0x20, 0x00, 0x01, 0x00 5058c2ecf20Sopenharmony_ci}; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci/* 5088c2ecf20Sopenharmony_ci * This packet is required for Xbox One S (0x045e:0x02ea) 5098c2ecf20Sopenharmony_ci * and Xbox One Elite Series 2 (0x045e:0x0b00) pads to 5108c2ecf20Sopenharmony_ci * initialize the controller that was previously used in 5118c2ecf20Sopenharmony_ci * Bluetooth mode. 5128c2ecf20Sopenharmony_ci */ 5138c2ecf20Sopenharmony_cistatic const u8 xboxone_s_init[] = { 5148c2ecf20Sopenharmony_ci 0x05, 0x20, 0x00, 0x0f, 0x06 5158c2ecf20Sopenharmony_ci}; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci/* 5188c2ecf20Sopenharmony_ci * This packet is required for the Titanfall 2 Xbox One pads 5198c2ecf20Sopenharmony_ci * (0x0e6f:0x0165) to finish initialization and for Hori pads 5208c2ecf20Sopenharmony_ci * (0x0f0d:0x0067) to make the analog sticks work. 5218c2ecf20Sopenharmony_ci */ 5228c2ecf20Sopenharmony_cistatic const u8 xboxone_hori_init[] = { 5238c2ecf20Sopenharmony_ci 0x01, 0x20, 0x00, 0x09, 0x00, 0x04, 0x20, 0x3a, 5248c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x80, 0x00 5258c2ecf20Sopenharmony_ci}; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci/* 5288c2ecf20Sopenharmony_ci * This packet is required for most (all?) of the PDP pads to start 5298c2ecf20Sopenharmony_ci * sending input reports. These pads include: (0x0e6f:0x02ab), 5308c2ecf20Sopenharmony_ci * (0x0e6f:0x02a4), (0x0e6f:0x02a6). 5318c2ecf20Sopenharmony_ci */ 5328c2ecf20Sopenharmony_cistatic const u8 xboxone_pdp_init1[] = { 5338c2ecf20Sopenharmony_ci 0x0a, 0x20, 0x00, 0x03, 0x00, 0x01, 0x14 5348c2ecf20Sopenharmony_ci}; 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci/* 5378c2ecf20Sopenharmony_ci * This packet is required for most (all?) of the PDP pads to start 5388c2ecf20Sopenharmony_ci * sending input reports. These pads include: (0x0e6f:0x02ab), 5398c2ecf20Sopenharmony_ci * (0x0e6f:0x02a4), (0x0e6f:0x02a6). 5408c2ecf20Sopenharmony_ci */ 5418c2ecf20Sopenharmony_cistatic const u8 xboxone_pdp_init2[] = { 5428c2ecf20Sopenharmony_ci 0x06, 0x20, 0x00, 0x02, 0x01, 0x00 5438c2ecf20Sopenharmony_ci}; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci/* 5468c2ecf20Sopenharmony_ci * A specific rumble packet is required for some PowerA pads to start 5478c2ecf20Sopenharmony_ci * sending input reports. One of those pads is (0x24c6:0x543a). 5488c2ecf20Sopenharmony_ci */ 5498c2ecf20Sopenharmony_cistatic const u8 xboxone_rumblebegin_init[] = { 5508c2ecf20Sopenharmony_ci 0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00, 5518c2ecf20Sopenharmony_ci 0x1D, 0x1D, 0xFF, 0x00, 0x00 5528c2ecf20Sopenharmony_ci}; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci/* 5558c2ecf20Sopenharmony_ci * A rumble packet with zero FF intensity will immediately 5568c2ecf20Sopenharmony_ci * terminate the rumbling required to init PowerA pads. 5578c2ecf20Sopenharmony_ci * This should happen fast enough that the motors don't 5588c2ecf20Sopenharmony_ci * spin up to enough speed to actually vibrate the gamepad. 5598c2ecf20Sopenharmony_ci */ 5608c2ecf20Sopenharmony_cistatic const u8 xboxone_rumbleend_init[] = { 5618c2ecf20Sopenharmony_ci 0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00, 5628c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00 5638c2ecf20Sopenharmony_ci}; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci/* 5668c2ecf20Sopenharmony_ci * This specifies the selection of init packets that a gamepad 5678c2ecf20Sopenharmony_ci * will be sent on init *and* the order in which they will be 5688c2ecf20Sopenharmony_ci * sent. The correct sequence number will be added when the 5698c2ecf20Sopenharmony_ci * packet is going to be sent. 5708c2ecf20Sopenharmony_ci */ 5718c2ecf20Sopenharmony_cistatic const struct xboxone_init_packet xboxone_init_packets[] = { 5728c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x0e6f, 0x0165, xboxone_hori_init), 5738c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x0f0d, 0x0067, xboxone_hori_init), 5748c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_fw2015_init), 5758c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x045e, 0x02ea, xboxone_s_init), 5768c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x045e, 0x0b00, xboxone_s_init), 5778c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init1), 5788c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init2), 5798c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init), 5808c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumblebegin_init), 5818c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumblebegin_init), 5828c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumbleend_init), 5838c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumbleend_init), 5848c2ecf20Sopenharmony_ci XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumbleend_init), 5858c2ecf20Sopenharmony_ci}; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cistruct xpad_output_packet { 5888c2ecf20Sopenharmony_ci u8 data[XPAD_PKT_LEN]; 5898c2ecf20Sopenharmony_ci u8 len; 5908c2ecf20Sopenharmony_ci bool pending; 5918c2ecf20Sopenharmony_ci}; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci#define XPAD_OUT_CMD_IDX 0 5948c2ecf20Sopenharmony_ci#define XPAD_OUT_FF_IDX 1 5958c2ecf20Sopenharmony_ci#define XPAD_OUT_LED_IDX (1 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF)) 5968c2ecf20Sopenharmony_ci#define XPAD_NUM_OUT_PACKETS (1 + \ 5978c2ecf20Sopenharmony_ci IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF) + \ 5988c2ecf20Sopenharmony_ci IS_ENABLED(CONFIG_JOYSTICK_XPAD_LEDS)) 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_cistruct usb_xpad { 6018c2ecf20Sopenharmony_ci struct input_dev *dev; /* input device interface */ 6028c2ecf20Sopenharmony_ci struct input_dev __rcu *x360w_dev; 6038c2ecf20Sopenharmony_ci struct usb_device *udev; /* usb device */ 6048c2ecf20Sopenharmony_ci struct usb_interface *intf; /* usb interface */ 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci bool pad_present; 6078c2ecf20Sopenharmony_ci bool input_created; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci struct urb *irq_in; /* urb for interrupt in report */ 6108c2ecf20Sopenharmony_ci unsigned char *idata; /* input data */ 6118c2ecf20Sopenharmony_ci dma_addr_t idata_dma; 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci struct urb *irq_out; /* urb for interrupt out report */ 6148c2ecf20Sopenharmony_ci struct usb_anchor irq_out_anchor; 6158c2ecf20Sopenharmony_ci bool irq_out_active; /* we must not use an active URB */ 6168c2ecf20Sopenharmony_ci u8 odata_serial; /* serial number for xbox one protocol */ 6178c2ecf20Sopenharmony_ci unsigned char *odata; /* output data */ 6188c2ecf20Sopenharmony_ci dma_addr_t odata_dma; 6198c2ecf20Sopenharmony_ci spinlock_t odata_lock; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci struct xpad_output_packet out_packets[XPAD_NUM_OUT_PACKETS]; 6228c2ecf20Sopenharmony_ci int last_out_packet; 6238c2ecf20Sopenharmony_ci int init_seq; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci#if defined(CONFIG_JOYSTICK_XPAD_LEDS) 6268c2ecf20Sopenharmony_ci struct xpad_led *led; 6278c2ecf20Sopenharmony_ci#endif 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci char phys[64]; /* physical device path */ 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci int mapping; /* map d-pad to buttons or to axes */ 6328c2ecf20Sopenharmony_ci int xtype; /* type of xbox device */ 6338c2ecf20Sopenharmony_ci int pad_nr; /* the order x360 pads were attached */ 6348c2ecf20Sopenharmony_ci const char *name; /* name of the device */ 6358c2ecf20Sopenharmony_ci struct work_struct work; /* init/remove device from callback */ 6368c2ecf20Sopenharmony_ci}; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_cistatic int xpad_init_input(struct usb_xpad *xpad); 6398c2ecf20Sopenharmony_cistatic void xpad_deinit_input(struct usb_xpad *xpad); 6408c2ecf20Sopenharmony_cistatic void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num); 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci/* 6438c2ecf20Sopenharmony_ci * xpad_process_packet 6448c2ecf20Sopenharmony_ci * 6458c2ecf20Sopenharmony_ci * Completes a request by converting the data into events for the 6468c2ecf20Sopenharmony_ci * input subsystem. 6478c2ecf20Sopenharmony_ci * 6488c2ecf20Sopenharmony_ci * The used report descriptor was taken from ITO Takayukis website: 6498c2ecf20Sopenharmony_ci * http://euc.jp/periphs/xbox-controller.ja.html 6508c2ecf20Sopenharmony_ci */ 6518c2ecf20Sopenharmony_cistatic void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) 6528c2ecf20Sopenharmony_ci{ 6538c2ecf20Sopenharmony_ci struct input_dev *dev = xpad->dev; 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 6568c2ecf20Sopenharmony_ci /* left stick */ 6578c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_X, 6588c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 12))); 6598c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Y, 6608c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 14))); 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci /* right stick */ 6638c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RX, 6648c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 16))); 6658c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RY, 6668c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 18))); 6678c2ecf20Sopenharmony_ci } 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci /* triggers left/right */ 6708c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 6718c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TL2, data[10]); 6728c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TR2, data[11]); 6738c2ecf20Sopenharmony_ci } else { 6748c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Z, data[10]); 6758c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RZ, data[11]); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci /* digital pad */ 6798c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 6808c2ecf20Sopenharmony_ci /* dpad as buttons (left, right, up, down) */ 6818c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04); 6828c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08); 6838c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01); 6848c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02); 6858c2ecf20Sopenharmony_ci } else { 6868c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0X, 6878c2ecf20Sopenharmony_ci !!(data[2] & 0x08) - !!(data[2] & 0x04)); 6888c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0Y, 6898c2ecf20Sopenharmony_ci !!(data[2] & 0x02) - !!(data[2] & 0x01)); 6908c2ecf20Sopenharmony_ci } 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci /* start/back buttons and stick press left/right */ 6938c2ecf20Sopenharmony_ci input_report_key(dev, BTN_START, data[2] & 0x10); 6948c2ecf20Sopenharmony_ci input_report_key(dev, BTN_SELECT, data[2] & 0x20); 6958c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBL, data[2] & 0x40); 6968c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBR, data[2] & 0x80); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci /* "analog" buttons A, B, X, Y */ 6998c2ecf20Sopenharmony_ci input_report_key(dev, BTN_A, data[4]); 7008c2ecf20Sopenharmony_ci input_report_key(dev, BTN_B, data[5]); 7018c2ecf20Sopenharmony_ci input_report_key(dev, BTN_X, data[6]); 7028c2ecf20Sopenharmony_ci input_report_key(dev, BTN_Y, data[7]); 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci /* "analog" buttons black, white */ 7058c2ecf20Sopenharmony_ci input_report_key(dev, BTN_C, data[8]); 7068c2ecf20Sopenharmony_ci input_report_key(dev, BTN_Z, data[9]); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci input_sync(dev); 7098c2ecf20Sopenharmony_ci} 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci/* 7128c2ecf20Sopenharmony_ci * xpad360_process_packet 7138c2ecf20Sopenharmony_ci * 7148c2ecf20Sopenharmony_ci * Completes a request by converting the data into events for the 7158c2ecf20Sopenharmony_ci * input subsystem. It is version for xbox 360 controller 7168c2ecf20Sopenharmony_ci * 7178c2ecf20Sopenharmony_ci * The used report descriptor was taken from: 7188c2ecf20Sopenharmony_ci * http://www.free60.org/wiki/Gamepad 7198c2ecf20Sopenharmony_ci */ 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_cistatic void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev, 7228c2ecf20Sopenharmony_ci u16 cmd, unsigned char *data) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci /* valid pad data */ 7258c2ecf20Sopenharmony_ci if (data[0] != 0x00) 7268c2ecf20Sopenharmony_ci return; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci /* digital pad */ 7298c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 7308c2ecf20Sopenharmony_ci /* dpad as buttons (left, right, up, down) */ 7318c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04); 7328c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08); 7338c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01); 7348c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02); 7358c2ecf20Sopenharmony_ci } 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci /* 7388c2ecf20Sopenharmony_ci * This should be a simple else block. However historically 7398c2ecf20Sopenharmony_ci * xbox360w has mapped DPAD to buttons while xbox360 did not. This 7408c2ecf20Sopenharmony_ci * made no sense, but now we can not just switch back and have to 7418c2ecf20Sopenharmony_ci * support both behaviors. 7428c2ecf20Sopenharmony_ci */ 7438c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || 7448c2ecf20Sopenharmony_ci xpad->xtype == XTYPE_XBOX360W) { 7458c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0X, 7468c2ecf20Sopenharmony_ci !!(data[2] & 0x08) - !!(data[2] & 0x04)); 7478c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0Y, 7488c2ecf20Sopenharmony_ci !!(data[2] & 0x02) - !!(data[2] & 0x01)); 7498c2ecf20Sopenharmony_ci } 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci /* start/back buttons */ 7528c2ecf20Sopenharmony_ci input_report_key(dev, BTN_START, data[2] & 0x10); 7538c2ecf20Sopenharmony_ci input_report_key(dev, BTN_SELECT, data[2] & 0x20); 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci /* stick press left/right */ 7568c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBL, data[2] & 0x40); 7578c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBR, data[2] & 0x80); 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci /* buttons A,B,X,Y,TL,TR and MODE */ 7608c2ecf20Sopenharmony_ci input_report_key(dev, BTN_A, data[3] & 0x10); 7618c2ecf20Sopenharmony_ci input_report_key(dev, BTN_B, data[3] & 0x20); 7628c2ecf20Sopenharmony_ci input_report_key(dev, BTN_X, data[3] & 0x40); 7638c2ecf20Sopenharmony_ci input_report_key(dev, BTN_Y, data[3] & 0x80); 7648c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TL, data[3] & 0x01); 7658c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TR, data[3] & 0x02); 7668c2ecf20Sopenharmony_ci input_report_key(dev, BTN_MODE, data[3] & 0x04); 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 7698c2ecf20Sopenharmony_ci /* left stick */ 7708c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_X, 7718c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 6))); 7728c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Y, 7738c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 8))); 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_ci /* right stick */ 7768c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RX, 7778c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 10))); 7788c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RY, 7798c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 7808c2ecf20Sopenharmony_ci } 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci /* triggers left/right */ 7838c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 7848c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TL2, data[4]); 7858c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TR2, data[5]); 7868c2ecf20Sopenharmony_ci } else { 7878c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Z, data[4]); 7888c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RZ, data[5]); 7898c2ecf20Sopenharmony_ci } 7908c2ecf20Sopenharmony_ci 7918c2ecf20Sopenharmony_ci input_sync(dev); 7928c2ecf20Sopenharmony_ci} 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_cistatic void xpad_presence_work(struct work_struct *work) 7958c2ecf20Sopenharmony_ci{ 7968c2ecf20Sopenharmony_ci struct usb_xpad *xpad = container_of(work, struct usb_xpad, work); 7978c2ecf20Sopenharmony_ci int error; 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci if (xpad->pad_present) { 8008c2ecf20Sopenharmony_ci error = xpad_init_input(xpad); 8018c2ecf20Sopenharmony_ci if (error) { 8028c2ecf20Sopenharmony_ci /* complain only, not much else we can do here */ 8038c2ecf20Sopenharmony_ci dev_err(&xpad->dev->dev, 8048c2ecf20Sopenharmony_ci "unable to init device: %d\n", error); 8058c2ecf20Sopenharmony_ci } else { 8068c2ecf20Sopenharmony_ci rcu_assign_pointer(xpad->x360w_dev, xpad->dev); 8078c2ecf20Sopenharmony_ci } 8088c2ecf20Sopenharmony_ci } else { 8098c2ecf20Sopenharmony_ci RCU_INIT_POINTER(xpad->x360w_dev, NULL); 8108c2ecf20Sopenharmony_ci synchronize_rcu(); 8118c2ecf20Sopenharmony_ci /* 8128c2ecf20Sopenharmony_ci * Now that we are sure xpad360w_process_packet is not 8138c2ecf20Sopenharmony_ci * using input device we can get rid of it. 8148c2ecf20Sopenharmony_ci */ 8158c2ecf20Sopenharmony_ci xpad_deinit_input(xpad); 8168c2ecf20Sopenharmony_ci } 8178c2ecf20Sopenharmony_ci} 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_ci/* 8208c2ecf20Sopenharmony_ci * xpad360w_process_packet 8218c2ecf20Sopenharmony_ci * 8228c2ecf20Sopenharmony_ci * Completes a request by converting the data into events for the 8238c2ecf20Sopenharmony_ci * input subsystem. It is version for xbox 360 wireless controller. 8248c2ecf20Sopenharmony_ci * 8258c2ecf20Sopenharmony_ci * Byte.Bit 8268c2ecf20Sopenharmony_ci * 00.1 - Status change: The controller or headset has connected/disconnected 8278c2ecf20Sopenharmony_ci * Bits 01.7 and 01.6 are valid 8288c2ecf20Sopenharmony_ci * 01.7 - Controller present 8298c2ecf20Sopenharmony_ci * 01.6 - Headset present 8308c2ecf20Sopenharmony_ci * 01.1 - Pad state (Bytes 4+) valid 8318c2ecf20Sopenharmony_ci * 8328c2ecf20Sopenharmony_ci */ 8338c2ecf20Sopenharmony_cistatic void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) 8348c2ecf20Sopenharmony_ci{ 8358c2ecf20Sopenharmony_ci struct input_dev *dev; 8368c2ecf20Sopenharmony_ci bool present; 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci /* Presence change */ 8398c2ecf20Sopenharmony_ci if (data[0] & 0x08) { 8408c2ecf20Sopenharmony_ci present = (data[1] & 0x80) != 0; 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci if (xpad->pad_present != present) { 8438c2ecf20Sopenharmony_ci xpad->pad_present = present; 8448c2ecf20Sopenharmony_ci schedule_work(&xpad->work); 8458c2ecf20Sopenharmony_ci } 8468c2ecf20Sopenharmony_ci } 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ci /* Valid pad data */ 8498c2ecf20Sopenharmony_ci if (data[1] != 0x1) 8508c2ecf20Sopenharmony_ci return; 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci rcu_read_lock(); 8538c2ecf20Sopenharmony_ci dev = rcu_dereference(xpad->x360w_dev); 8548c2ecf20Sopenharmony_ci if (dev) 8558c2ecf20Sopenharmony_ci xpad360_process_packet(xpad, dev, cmd, &data[4]); 8568c2ecf20Sopenharmony_ci rcu_read_unlock(); 8578c2ecf20Sopenharmony_ci} 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci/* 8608c2ecf20Sopenharmony_ci * xpadone_process_packet 8618c2ecf20Sopenharmony_ci * 8628c2ecf20Sopenharmony_ci * Completes a request by converting the data into events for the 8638c2ecf20Sopenharmony_ci * input subsystem. This version is for the Xbox One controller. 8648c2ecf20Sopenharmony_ci * 8658c2ecf20Sopenharmony_ci * The report format was gleaned from 8668c2ecf20Sopenharmony_ci * https://github.com/kylelemons/xbox/blob/master/xbox.go 8678c2ecf20Sopenharmony_ci */ 8688c2ecf20Sopenharmony_cistatic void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) 8698c2ecf20Sopenharmony_ci{ 8708c2ecf20Sopenharmony_ci struct input_dev *dev = xpad->dev; 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_ci /* the xbox button has its own special report */ 8738c2ecf20Sopenharmony_ci if (data[0] == 0X07) { 8748c2ecf20Sopenharmony_ci /* 8758c2ecf20Sopenharmony_ci * The Xbox One S controller requires these reports to be 8768c2ecf20Sopenharmony_ci * acked otherwise it continues sending them forever and 8778c2ecf20Sopenharmony_ci * won't report further mode button events. 8788c2ecf20Sopenharmony_ci */ 8798c2ecf20Sopenharmony_ci if (data[1] == 0x30) 8808c2ecf20Sopenharmony_ci xpadone_ack_mode_report(xpad, data[2]); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci input_report_key(dev, BTN_MODE, data[4] & 0x01); 8838c2ecf20Sopenharmony_ci input_sync(dev); 8848c2ecf20Sopenharmony_ci return; 8858c2ecf20Sopenharmony_ci } 8868c2ecf20Sopenharmony_ci /* check invalid packet */ 8878c2ecf20Sopenharmony_ci else if (data[0] != 0X20) 8888c2ecf20Sopenharmony_ci return; 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci /* menu/view buttons */ 8918c2ecf20Sopenharmony_ci input_report_key(dev, BTN_START, data[4] & 0x04); 8928c2ecf20Sopenharmony_ci input_report_key(dev, BTN_SELECT, data[4] & 0x08); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci /* buttons A,B,X,Y */ 8958c2ecf20Sopenharmony_ci input_report_key(dev, BTN_A, data[4] & 0x10); 8968c2ecf20Sopenharmony_ci input_report_key(dev, BTN_B, data[4] & 0x20); 8978c2ecf20Sopenharmony_ci input_report_key(dev, BTN_X, data[4] & 0x40); 8988c2ecf20Sopenharmony_ci input_report_key(dev, BTN_Y, data[4] & 0x80); 8998c2ecf20Sopenharmony_ci 9008c2ecf20Sopenharmony_ci /* digital pad */ 9018c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 9028c2ecf20Sopenharmony_ci /* dpad as buttons (left, right, up, down) */ 9038c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & 0x04); 9048c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & 0x08); 9058c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & 0x01); 9068c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & 0x02); 9078c2ecf20Sopenharmony_ci } else { 9088c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0X, 9098c2ecf20Sopenharmony_ci !!(data[5] & 0x08) - !!(data[5] & 0x04)); 9108c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_HAT0Y, 9118c2ecf20Sopenharmony_ci !!(data[5] & 0x02) - !!(data[5] & 0x01)); 9128c2ecf20Sopenharmony_ci } 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci /* TL/TR */ 9158c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TL, data[5] & 0x10); 9168c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TR, data[5] & 0x20); 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci /* stick press left/right */ 9198c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBL, data[5] & 0x40); 9208c2ecf20Sopenharmony_ci input_report_key(dev, BTN_THUMBR, data[5] & 0x80); 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 9238c2ecf20Sopenharmony_ci /* left stick */ 9248c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_X, 9258c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 10))); 9268c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Y, 9278c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci /* right stick */ 9308c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RX, 9318c2ecf20Sopenharmony_ci (__s16) le16_to_cpup((__le16 *)(data + 14))); 9328c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RY, 9338c2ecf20Sopenharmony_ci ~(__s16) le16_to_cpup((__le16 *)(data + 16))); 9348c2ecf20Sopenharmony_ci } 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci /* triggers left/right */ 9378c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 9388c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TL2, 9398c2ecf20Sopenharmony_ci (__u16) le16_to_cpup((__le16 *)(data + 6))); 9408c2ecf20Sopenharmony_ci input_report_key(dev, BTN_TR2, 9418c2ecf20Sopenharmony_ci (__u16) le16_to_cpup((__le16 *)(data + 8))); 9428c2ecf20Sopenharmony_ci } else { 9438c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_Z, 9448c2ecf20Sopenharmony_ci (__u16) le16_to_cpup((__le16 *)(data + 6))); 9458c2ecf20Sopenharmony_ci input_report_abs(dev, ABS_RZ, 9468c2ecf20Sopenharmony_ci (__u16) le16_to_cpup((__le16 *)(data + 8))); 9478c2ecf20Sopenharmony_ci } 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci input_sync(dev); 9508c2ecf20Sopenharmony_ci} 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_cistatic void xpad_irq_in(struct urb *urb) 9538c2ecf20Sopenharmony_ci{ 9548c2ecf20Sopenharmony_ci struct usb_xpad *xpad = urb->context; 9558c2ecf20Sopenharmony_ci struct device *dev = &xpad->intf->dev; 9568c2ecf20Sopenharmony_ci int retval, status; 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci status = urb->status; 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci switch (status) { 9618c2ecf20Sopenharmony_ci case 0: 9628c2ecf20Sopenharmony_ci /* success */ 9638c2ecf20Sopenharmony_ci break; 9648c2ecf20Sopenharmony_ci case -ECONNRESET: 9658c2ecf20Sopenharmony_ci case -ENOENT: 9668c2ecf20Sopenharmony_ci case -ESHUTDOWN: 9678c2ecf20Sopenharmony_ci /* this urb is terminated, clean up */ 9688c2ecf20Sopenharmony_ci dev_dbg(dev, "%s - urb shutting down with status: %d\n", 9698c2ecf20Sopenharmony_ci __func__, status); 9708c2ecf20Sopenharmony_ci return; 9718c2ecf20Sopenharmony_ci default: 9728c2ecf20Sopenharmony_ci dev_dbg(dev, "%s - nonzero urb status received: %d\n", 9738c2ecf20Sopenharmony_ci __func__, status); 9748c2ecf20Sopenharmony_ci goto exit; 9758c2ecf20Sopenharmony_ci } 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci switch (xpad->xtype) { 9788c2ecf20Sopenharmony_ci case XTYPE_XBOX360: 9798c2ecf20Sopenharmony_ci xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); 9808c2ecf20Sopenharmony_ci break; 9818c2ecf20Sopenharmony_ci case XTYPE_XBOX360W: 9828c2ecf20Sopenharmony_ci xpad360w_process_packet(xpad, 0, xpad->idata); 9838c2ecf20Sopenharmony_ci break; 9848c2ecf20Sopenharmony_ci case XTYPE_XBOXONE: 9858c2ecf20Sopenharmony_ci xpadone_process_packet(xpad, 0, xpad->idata); 9868c2ecf20Sopenharmony_ci break; 9878c2ecf20Sopenharmony_ci default: 9888c2ecf20Sopenharmony_ci xpad_process_packet(xpad, 0, xpad->idata); 9898c2ecf20Sopenharmony_ci } 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ciexit: 9928c2ecf20Sopenharmony_ci retval = usb_submit_urb(urb, GFP_ATOMIC); 9938c2ecf20Sopenharmony_ci if (retval) 9948c2ecf20Sopenharmony_ci dev_err(dev, "%s - usb_submit_urb failed with result %d\n", 9958c2ecf20Sopenharmony_ci __func__, retval); 9968c2ecf20Sopenharmony_ci} 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci/* Callers must hold xpad->odata_lock spinlock */ 9998c2ecf20Sopenharmony_cistatic bool xpad_prepare_next_init_packet(struct usb_xpad *xpad) 10008c2ecf20Sopenharmony_ci{ 10018c2ecf20Sopenharmony_ci const struct xboxone_init_packet *init_packet; 10028c2ecf20Sopenharmony_ci 10038c2ecf20Sopenharmony_ci if (xpad->xtype != XTYPE_XBOXONE) 10048c2ecf20Sopenharmony_ci return false; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci /* Perform initialization sequence for Xbox One pads that require it */ 10078c2ecf20Sopenharmony_ci while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) { 10088c2ecf20Sopenharmony_ci init_packet = &xboxone_init_packets[xpad->init_seq++]; 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci if (init_packet->idVendor != 0 && 10118c2ecf20Sopenharmony_ci init_packet->idVendor != xpad->dev->id.vendor) 10128c2ecf20Sopenharmony_ci continue; 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci if (init_packet->idProduct != 0 && 10158c2ecf20Sopenharmony_ci init_packet->idProduct != xpad->dev->id.product) 10168c2ecf20Sopenharmony_ci continue; 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_ci /* This packet applies to our device, so prepare to send it */ 10198c2ecf20Sopenharmony_ci memcpy(xpad->odata, init_packet->data, init_packet->len); 10208c2ecf20Sopenharmony_ci xpad->irq_out->transfer_buffer_length = init_packet->len; 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci /* Update packet with current sequence number */ 10238c2ecf20Sopenharmony_ci xpad->odata[2] = xpad->odata_serial++; 10248c2ecf20Sopenharmony_ci return true; 10258c2ecf20Sopenharmony_ci } 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci return false; 10288c2ecf20Sopenharmony_ci} 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci/* Callers must hold xpad->odata_lock spinlock */ 10318c2ecf20Sopenharmony_cistatic bool xpad_prepare_next_out_packet(struct usb_xpad *xpad) 10328c2ecf20Sopenharmony_ci{ 10338c2ecf20Sopenharmony_ci struct xpad_output_packet *pkt, *packet = NULL; 10348c2ecf20Sopenharmony_ci int i; 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci /* We may have init packets to send before we can send user commands */ 10378c2ecf20Sopenharmony_ci if (xpad_prepare_next_init_packet(xpad)) 10388c2ecf20Sopenharmony_ci return true; 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) { 10418c2ecf20Sopenharmony_ci if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) 10428c2ecf20Sopenharmony_ci xpad->last_out_packet = 0; 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci pkt = &xpad->out_packets[xpad->last_out_packet]; 10458c2ecf20Sopenharmony_ci if (pkt->pending) { 10468c2ecf20Sopenharmony_ci dev_dbg(&xpad->intf->dev, 10478c2ecf20Sopenharmony_ci "%s - found pending output packet %d\n", 10488c2ecf20Sopenharmony_ci __func__, xpad->last_out_packet); 10498c2ecf20Sopenharmony_ci packet = pkt; 10508c2ecf20Sopenharmony_ci break; 10518c2ecf20Sopenharmony_ci } 10528c2ecf20Sopenharmony_ci } 10538c2ecf20Sopenharmony_ci 10548c2ecf20Sopenharmony_ci if (packet) { 10558c2ecf20Sopenharmony_ci memcpy(xpad->odata, packet->data, packet->len); 10568c2ecf20Sopenharmony_ci xpad->irq_out->transfer_buffer_length = packet->len; 10578c2ecf20Sopenharmony_ci packet->pending = false; 10588c2ecf20Sopenharmony_ci return true; 10598c2ecf20Sopenharmony_ci } 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci return false; 10628c2ecf20Sopenharmony_ci} 10638c2ecf20Sopenharmony_ci 10648c2ecf20Sopenharmony_ci/* Callers must hold xpad->odata_lock spinlock */ 10658c2ecf20Sopenharmony_cistatic int xpad_try_sending_next_out_packet(struct usb_xpad *xpad) 10668c2ecf20Sopenharmony_ci{ 10678c2ecf20Sopenharmony_ci int error; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { 10708c2ecf20Sopenharmony_ci usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); 10718c2ecf20Sopenharmony_ci error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); 10728c2ecf20Sopenharmony_ci if (error) { 10738c2ecf20Sopenharmony_ci dev_err(&xpad->intf->dev, 10748c2ecf20Sopenharmony_ci "%s - usb_submit_urb failed with result %d\n", 10758c2ecf20Sopenharmony_ci __func__, error); 10768c2ecf20Sopenharmony_ci usb_unanchor_urb(xpad->irq_out); 10778c2ecf20Sopenharmony_ci return -EIO; 10788c2ecf20Sopenharmony_ci } 10798c2ecf20Sopenharmony_ci 10808c2ecf20Sopenharmony_ci xpad->irq_out_active = true; 10818c2ecf20Sopenharmony_ci } 10828c2ecf20Sopenharmony_ci 10838c2ecf20Sopenharmony_ci return 0; 10848c2ecf20Sopenharmony_ci} 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_cistatic void xpad_irq_out(struct urb *urb) 10878c2ecf20Sopenharmony_ci{ 10888c2ecf20Sopenharmony_ci struct usb_xpad *xpad = urb->context; 10898c2ecf20Sopenharmony_ci struct device *dev = &xpad->intf->dev; 10908c2ecf20Sopenharmony_ci int status = urb->status; 10918c2ecf20Sopenharmony_ci int error; 10928c2ecf20Sopenharmony_ci unsigned long flags; 10938c2ecf20Sopenharmony_ci 10948c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 10958c2ecf20Sopenharmony_ci 10968c2ecf20Sopenharmony_ci switch (status) { 10978c2ecf20Sopenharmony_ci case 0: 10988c2ecf20Sopenharmony_ci /* success */ 10998c2ecf20Sopenharmony_ci xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); 11008c2ecf20Sopenharmony_ci break; 11018c2ecf20Sopenharmony_ci 11028c2ecf20Sopenharmony_ci case -ECONNRESET: 11038c2ecf20Sopenharmony_ci case -ENOENT: 11048c2ecf20Sopenharmony_ci case -ESHUTDOWN: 11058c2ecf20Sopenharmony_ci /* this urb is terminated, clean up */ 11068c2ecf20Sopenharmony_ci dev_dbg(dev, "%s - urb shutting down with status: %d\n", 11078c2ecf20Sopenharmony_ci __func__, status); 11088c2ecf20Sopenharmony_ci xpad->irq_out_active = false; 11098c2ecf20Sopenharmony_ci break; 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci default: 11128c2ecf20Sopenharmony_ci dev_dbg(dev, "%s - nonzero urb status received: %d\n", 11138c2ecf20Sopenharmony_ci __func__, status); 11148c2ecf20Sopenharmony_ci break; 11158c2ecf20Sopenharmony_ci } 11168c2ecf20Sopenharmony_ci 11178c2ecf20Sopenharmony_ci if (xpad->irq_out_active) { 11188c2ecf20Sopenharmony_ci usb_anchor_urb(urb, &xpad->irq_out_anchor); 11198c2ecf20Sopenharmony_ci error = usb_submit_urb(urb, GFP_ATOMIC); 11208c2ecf20Sopenharmony_ci if (error) { 11218c2ecf20Sopenharmony_ci dev_err(dev, 11228c2ecf20Sopenharmony_ci "%s - usb_submit_urb failed with result %d\n", 11238c2ecf20Sopenharmony_ci __func__, error); 11248c2ecf20Sopenharmony_ci usb_unanchor_urb(urb); 11258c2ecf20Sopenharmony_ci xpad->irq_out_active = false; 11268c2ecf20Sopenharmony_ci } 11278c2ecf20Sopenharmony_ci } 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 11308c2ecf20Sopenharmony_ci} 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_cistatic int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, 11338c2ecf20Sopenharmony_ci struct usb_endpoint_descriptor *ep_irq_out) 11348c2ecf20Sopenharmony_ci{ 11358c2ecf20Sopenharmony_ci int error; 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_UNKNOWN) 11388c2ecf20Sopenharmony_ci return 0; 11398c2ecf20Sopenharmony_ci 11408c2ecf20Sopenharmony_ci init_usb_anchor(&xpad->irq_out_anchor); 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_ci xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, 11438c2ecf20Sopenharmony_ci GFP_KERNEL, &xpad->odata_dma); 11448c2ecf20Sopenharmony_ci if (!xpad->odata) 11458c2ecf20Sopenharmony_ci return -ENOMEM; 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci spin_lock_init(&xpad->odata_lock); 11488c2ecf20Sopenharmony_ci 11498c2ecf20Sopenharmony_ci xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); 11508c2ecf20Sopenharmony_ci if (!xpad->irq_out) { 11518c2ecf20Sopenharmony_ci error = -ENOMEM; 11528c2ecf20Sopenharmony_ci goto err_free_coherent; 11538c2ecf20Sopenharmony_ci } 11548c2ecf20Sopenharmony_ci 11558c2ecf20Sopenharmony_ci usb_fill_int_urb(xpad->irq_out, xpad->udev, 11568c2ecf20Sopenharmony_ci usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), 11578c2ecf20Sopenharmony_ci xpad->odata, XPAD_PKT_LEN, 11588c2ecf20Sopenharmony_ci xpad_irq_out, xpad, ep_irq_out->bInterval); 11598c2ecf20Sopenharmony_ci xpad->irq_out->transfer_dma = xpad->odata_dma; 11608c2ecf20Sopenharmony_ci xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 11618c2ecf20Sopenharmony_ci 11628c2ecf20Sopenharmony_ci return 0; 11638c2ecf20Sopenharmony_ci 11648c2ecf20Sopenharmony_cierr_free_coherent: 11658c2ecf20Sopenharmony_ci usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); 11668c2ecf20Sopenharmony_ci return error; 11678c2ecf20Sopenharmony_ci} 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_cistatic void xpad_stop_output(struct usb_xpad *xpad) 11708c2ecf20Sopenharmony_ci{ 11718c2ecf20Sopenharmony_ci if (xpad->xtype != XTYPE_UNKNOWN) { 11728c2ecf20Sopenharmony_ci if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, 11738c2ecf20Sopenharmony_ci 5000)) { 11748c2ecf20Sopenharmony_ci dev_warn(&xpad->intf->dev, 11758c2ecf20Sopenharmony_ci "timed out waiting for output URB to complete, killing\n"); 11768c2ecf20Sopenharmony_ci usb_kill_anchored_urbs(&xpad->irq_out_anchor); 11778c2ecf20Sopenharmony_ci } 11788c2ecf20Sopenharmony_ci } 11798c2ecf20Sopenharmony_ci} 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_cistatic void xpad_deinit_output(struct usb_xpad *xpad) 11828c2ecf20Sopenharmony_ci{ 11838c2ecf20Sopenharmony_ci if (xpad->xtype != XTYPE_UNKNOWN) { 11848c2ecf20Sopenharmony_ci usb_free_urb(xpad->irq_out); 11858c2ecf20Sopenharmony_ci usb_free_coherent(xpad->udev, XPAD_PKT_LEN, 11868c2ecf20Sopenharmony_ci xpad->odata, xpad->odata_dma); 11878c2ecf20Sopenharmony_ci } 11888c2ecf20Sopenharmony_ci} 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_cistatic int xpad_inquiry_pad_presence(struct usb_xpad *xpad) 11918c2ecf20Sopenharmony_ci{ 11928c2ecf20Sopenharmony_ci struct xpad_output_packet *packet = 11938c2ecf20Sopenharmony_ci &xpad->out_packets[XPAD_OUT_CMD_IDX]; 11948c2ecf20Sopenharmony_ci unsigned long flags; 11958c2ecf20Sopenharmony_ci int retval; 11968c2ecf20Sopenharmony_ci 11978c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_ci packet->data[0] = 0x08; 12008c2ecf20Sopenharmony_ci packet->data[1] = 0x00; 12018c2ecf20Sopenharmony_ci packet->data[2] = 0x0F; 12028c2ecf20Sopenharmony_ci packet->data[3] = 0xC0; 12038c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 12048c2ecf20Sopenharmony_ci packet->data[5] = 0x00; 12058c2ecf20Sopenharmony_ci packet->data[6] = 0x00; 12068c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 12078c2ecf20Sopenharmony_ci packet->data[8] = 0x00; 12088c2ecf20Sopenharmony_ci packet->data[9] = 0x00; 12098c2ecf20Sopenharmony_ci packet->data[10] = 0x00; 12108c2ecf20Sopenharmony_ci packet->data[11] = 0x00; 12118c2ecf20Sopenharmony_ci packet->len = 12; 12128c2ecf20Sopenharmony_ci packet->pending = true; 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_ci /* Reset the sequence so we send out presence first */ 12158c2ecf20Sopenharmony_ci xpad->last_out_packet = -1; 12168c2ecf20Sopenharmony_ci retval = xpad_try_sending_next_out_packet(xpad); 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci return retval; 12218c2ecf20Sopenharmony_ci} 12228c2ecf20Sopenharmony_ci 12238c2ecf20Sopenharmony_cistatic int xpad_start_xbox_one(struct usb_xpad *xpad) 12248c2ecf20Sopenharmony_ci{ 12258c2ecf20Sopenharmony_ci unsigned long flags; 12268c2ecf20Sopenharmony_ci int retval; 12278c2ecf20Sopenharmony_ci 12288c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 12298c2ecf20Sopenharmony_ci 12308c2ecf20Sopenharmony_ci /* 12318c2ecf20Sopenharmony_ci * Begin the init sequence by attempting to send a packet. 12328c2ecf20Sopenharmony_ci * We will cycle through the init packet sequence before 12338c2ecf20Sopenharmony_ci * sending any packets from the output ring. 12348c2ecf20Sopenharmony_ci */ 12358c2ecf20Sopenharmony_ci xpad->init_seq = 0; 12368c2ecf20Sopenharmony_ci retval = xpad_try_sending_next_out_packet(xpad); 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci return retval; 12418c2ecf20Sopenharmony_ci} 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_cistatic void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num) 12448c2ecf20Sopenharmony_ci{ 12458c2ecf20Sopenharmony_ci unsigned long flags; 12468c2ecf20Sopenharmony_ci struct xpad_output_packet *packet = 12478c2ecf20Sopenharmony_ci &xpad->out_packets[XPAD_OUT_CMD_IDX]; 12488c2ecf20Sopenharmony_ci static const u8 mode_report_ack[] = { 12498c2ecf20Sopenharmony_ci 0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02, 12508c2ecf20Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00 12518c2ecf20Sopenharmony_ci }; 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 12548c2ecf20Sopenharmony_ci 12558c2ecf20Sopenharmony_ci packet->len = sizeof(mode_report_ack); 12568c2ecf20Sopenharmony_ci memcpy(packet->data, mode_report_ack, packet->len); 12578c2ecf20Sopenharmony_ci packet->data[2] = seq_num; 12588c2ecf20Sopenharmony_ci packet->pending = true; 12598c2ecf20Sopenharmony_ci 12608c2ecf20Sopenharmony_ci /* Reset the sequence so we send out the ack now */ 12618c2ecf20Sopenharmony_ci xpad->last_out_packet = -1; 12628c2ecf20Sopenharmony_ci xpad_try_sending_next_out_packet(xpad); 12638c2ecf20Sopenharmony_ci 12648c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 12658c2ecf20Sopenharmony_ci} 12668c2ecf20Sopenharmony_ci 12678c2ecf20Sopenharmony_ci#ifdef CONFIG_JOYSTICK_XPAD_FF 12688c2ecf20Sopenharmony_cistatic int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) 12698c2ecf20Sopenharmony_ci{ 12708c2ecf20Sopenharmony_ci struct usb_xpad *xpad = input_get_drvdata(dev); 12718c2ecf20Sopenharmony_ci struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; 12728c2ecf20Sopenharmony_ci __u16 strong; 12738c2ecf20Sopenharmony_ci __u16 weak; 12748c2ecf20Sopenharmony_ci int retval; 12758c2ecf20Sopenharmony_ci unsigned long flags; 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci if (effect->type != FF_RUMBLE) 12788c2ecf20Sopenharmony_ci return 0; 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci strong = effect->u.rumble.strong_magnitude; 12818c2ecf20Sopenharmony_ci weak = effect->u.rumble.weak_magnitude; 12828c2ecf20Sopenharmony_ci 12838c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci switch (xpad->xtype) { 12868c2ecf20Sopenharmony_ci case XTYPE_XBOX: 12878c2ecf20Sopenharmony_ci packet->data[0] = 0x00; 12888c2ecf20Sopenharmony_ci packet->data[1] = 0x06; 12898c2ecf20Sopenharmony_ci packet->data[2] = 0x00; 12908c2ecf20Sopenharmony_ci packet->data[3] = strong / 256; /* left actuator */ 12918c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 12928c2ecf20Sopenharmony_ci packet->data[5] = weak / 256; /* right actuator */ 12938c2ecf20Sopenharmony_ci packet->len = 6; 12948c2ecf20Sopenharmony_ci packet->pending = true; 12958c2ecf20Sopenharmony_ci break; 12968c2ecf20Sopenharmony_ci 12978c2ecf20Sopenharmony_ci case XTYPE_XBOX360: 12988c2ecf20Sopenharmony_ci packet->data[0] = 0x00; 12998c2ecf20Sopenharmony_ci packet->data[1] = 0x08; 13008c2ecf20Sopenharmony_ci packet->data[2] = 0x00; 13018c2ecf20Sopenharmony_ci packet->data[3] = strong / 256; /* left actuator? */ 13028c2ecf20Sopenharmony_ci packet->data[4] = weak / 256; /* right actuator? */ 13038c2ecf20Sopenharmony_ci packet->data[5] = 0x00; 13048c2ecf20Sopenharmony_ci packet->data[6] = 0x00; 13058c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 13068c2ecf20Sopenharmony_ci packet->len = 8; 13078c2ecf20Sopenharmony_ci packet->pending = true; 13088c2ecf20Sopenharmony_ci break; 13098c2ecf20Sopenharmony_ci 13108c2ecf20Sopenharmony_ci case XTYPE_XBOX360W: 13118c2ecf20Sopenharmony_ci packet->data[0] = 0x00; 13128c2ecf20Sopenharmony_ci packet->data[1] = 0x01; 13138c2ecf20Sopenharmony_ci packet->data[2] = 0x0F; 13148c2ecf20Sopenharmony_ci packet->data[3] = 0xC0; 13158c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 13168c2ecf20Sopenharmony_ci packet->data[5] = strong / 256; 13178c2ecf20Sopenharmony_ci packet->data[6] = weak / 256; 13188c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 13198c2ecf20Sopenharmony_ci packet->data[8] = 0x00; 13208c2ecf20Sopenharmony_ci packet->data[9] = 0x00; 13218c2ecf20Sopenharmony_ci packet->data[10] = 0x00; 13228c2ecf20Sopenharmony_ci packet->data[11] = 0x00; 13238c2ecf20Sopenharmony_ci packet->len = 12; 13248c2ecf20Sopenharmony_ci packet->pending = true; 13258c2ecf20Sopenharmony_ci break; 13268c2ecf20Sopenharmony_ci 13278c2ecf20Sopenharmony_ci case XTYPE_XBOXONE: 13288c2ecf20Sopenharmony_ci packet->data[0] = 0x09; /* activate rumble */ 13298c2ecf20Sopenharmony_ci packet->data[1] = 0x00; 13308c2ecf20Sopenharmony_ci packet->data[2] = xpad->odata_serial++; 13318c2ecf20Sopenharmony_ci packet->data[3] = 0x09; 13328c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 13338c2ecf20Sopenharmony_ci packet->data[5] = 0x0F; 13348c2ecf20Sopenharmony_ci packet->data[6] = 0x00; 13358c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 13368c2ecf20Sopenharmony_ci packet->data[8] = strong / 512; /* left actuator */ 13378c2ecf20Sopenharmony_ci packet->data[9] = weak / 512; /* right actuator */ 13388c2ecf20Sopenharmony_ci packet->data[10] = 0xFF; /* on period */ 13398c2ecf20Sopenharmony_ci packet->data[11] = 0x00; /* off period */ 13408c2ecf20Sopenharmony_ci packet->data[12] = 0xFF; /* repeat count */ 13418c2ecf20Sopenharmony_ci packet->len = 13; 13428c2ecf20Sopenharmony_ci packet->pending = true; 13438c2ecf20Sopenharmony_ci break; 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci default: 13468c2ecf20Sopenharmony_ci dev_dbg(&xpad->dev->dev, 13478c2ecf20Sopenharmony_ci "%s - rumble command sent to unsupported xpad type: %d\n", 13488c2ecf20Sopenharmony_ci __func__, xpad->xtype); 13498c2ecf20Sopenharmony_ci retval = -EINVAL; 13508c2ecf20Sopenharmony_ci goto out; 13518c2ecf20Sopenharmony_ci } 13528c2ecf20Sopenharmony_ci 13538c2ecf20Sopenharmony_ci retval = xpad_try_sending_next_out_packet(xpad); 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ciout: 13568c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 13578c2ecf20Sopenharmony_ci return retval; 13588c2ecf20Sopenharmony_ci} 13598c2ecf20Sopenharmony_ci 13608c2ecf20Sopenharmony_cistatic int xpad_init_ff(struct usb_xpad *xpad) 13618c2ecf20Sopenharmony_ci{ 13628c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_UNKNOWN) 13638c2ecf20Sopenharmony_ci return 0; 13648c2ecf20Sopenharmony_ci 13658c2ecf20Sopenharmony_ci input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); 13668c2ecf20Sopenharmony_ci 13678c2ecf20Sopenharmony_ci return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); 13688c2ecf20Sopenharmony_ci} 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_ci#else 13718c2ecf20Sopenharmony_cistatic int xpad_init_ff(struct usb_xpad *xpad) { return 0; } 13728c2ecf20Sopenharmony_ci#endif 13738c2ecf20Sopenharmony_ci 13748c2ecf20Sopenharmony_ci#if defined(CONFIG_JOYSTICK_XPAD_LEDS) 13758c2ecf20Sopenharmony_ci#include <linux/leds.h> 13768c2ecf20Sopenharmony_ci#include <linux/idr.h> 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_cistatic DEFINE_IDA(xpad_pad_seq); 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_cistruct xpad_led { 13818c2ecf20Sopenharmony_ci char name[16]; 13828c2ecf20Sopenharmony_ci struct led_classdev led_cdev; 13838c2ecf20Sopenharmony_ci struct usb_xpad *xpad; 13848c2ecf20Sopenharmony_ci}; 13858c2ecf20Sopenharmony_ci 13868c2ecf20Sopenharmony_ci/** 13878c2ecf20Sopenharmony_ci * set the LEDs on Xbox360 / Wireless Controllers 13888c2ecf20Sopenharmony_ci * @param command 13898c2ecf20Sopenharmony_ci * 0: off 13908c2ecf20Sopenharmony_ci * 1: all blink, then previous setting 13918c2ecf20Sopenharmony_ci * 2: 1/top-left blink, then on 13928c2ecf20Sopenharmony_ci * 3: 2/top-right blink, then on 13938c2ecf20Sopenharmony_ci * 4: 3/bottom-left blink, then on 13948c2ecf20Sopenharmony_ci * 5: 4/bottom-right blink, then on 13958c2ecf20Sopenharmony_ci * 6: 1/top-left on 13968c2ecf20Sopenharmony_ci * 7: 2/top-right on 13978c2ecf20Sopenharmony_ci * 8: 3/bottom-left on 13988c2ecf20Sopenharmony_ci * 9: 4/bottom-right on 13998c2ecf20Sopenharmony_ci * 10: rotate 14008c2ecf20Sopenharmony_ci * 11: blink, based on previous setting 14018c2ecf20Sopenharmony_ci * 12: slow blink, based on previous setting 14028c2ecf20Sopenharmony_ci * 13: rotate with two lights 14038c2ecf20Sopenharmony_ci * 14: persistent slow all blink 14048c2ecf20Sopenharmony_ci * 15: blink once, then previous setting 14058c2ecf20Sopenharmony_ci */ 14068c2ecf20Sopenharmony_cistatic void xpad_send_led_command(struct usb_xpad *xpad, int command) 14078c2ecf20Sopenharmony_ci{ 14088c2ecf20Sopenharmony_ci struct xpad_output_packet *packet = 14098c2ecf20Sopenharmony_ci &xpad->out_packets[XPAD_OUT_LED_IDX]; 14108c2ecf20Sopenharmony_ci unsigned long flags; 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci command %= 16; 14138c2ecf20Sopenharmony_ci 14148c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 14158c2ecf20Sopenharmony_ci 14168c2ecf20Sopenharmony_ci switch (xpad->xtype) { 14178c2ecf20Sopenharmony_ci case XTYPE_XBOX360: 14188c2ecf20Sopenharmony_ci packet->data[0] = 0x01; 14198c2ecf20Sopenharmony_ci packet->data[1] = 0x03; 14208c2ecf20Sopenharmony_ci packet->data[2] = command; 14218c2ecf20Sopenharmony_ci packet->len = 3; 14228c2ecf20Sopenharmony_ci packet->pending = true; 14238c2ecf20Sopenharmony_ci break; 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci case XTYPE_XBOX360W: 14268c2ecf20Sopenharmony_ci packet->data[0] = 0x00; 14278c2ecf20Sopenharmony_ci packet->data[1] = 0x00; 14288c2ecf20Sopenharmony_ci packet->data[2] = 0x08; 14298c2ecf20Sopenharmony_ci packet->data[3] = 0x40 + command; 14308c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 14318c2ecf20Sopenharmony_ci packet->data[5] = 0x00; 14328c2ecf20Sopenharmony_ci packet->data[6] = 0x00; 14338c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 14348c2ecf20Sopenharmony_ci packet->data[8] = 0x00; 14358c2ecf20Sopenharmony_ci packet->data[9] = 0x00; 14368c2ecf20Sopenharmony_ci packet->data[10] = 0x00; 14378c2ecf20Sopenharmony_ci packet->data[11] = 0x00; 14388c2ecf20Sopenharmony_ci packet->len = 12; 14398c2ecf20Sopenharmony_ci packet->pending = true; 14408c2ecf20Sopenharmony_ci break; 14418c2ecf20Sopenharmony_ci } 14428c2ecf20Sopenharmony_ci 14438c2ecf20Sopenharmony_ci xpad_try_sending_next_out_packet(xpad); 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 14468c2ecf20Sopenharmony_ci} 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_ci/* 14498c2ecf20Sopenharmony_ci * Light up the segment corresponding to the pad number on 14508c2ecf20Sopenharmony_ci * Xbox 360 Controllers. 14518c2ecf20Sopenharmony_ci */ 14528c2ecf20Sopenharmony_cistatic void xpad_identify_controller(struct usb_xpad *xpad) 14538c2ecf20Sopenharmony_ci{ 14548c2ecf20Sopenharmony_ci led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); 14558c2ecf20Sopenharmony_ci} 14568c2ecf20Sopenharmony_ci 14578c2ecf20Sopenharmony_cistatic void xpad_led_set(struct led_classdev *led_cdev, 14588c2ecf20Sopenharmony_ci enum led_brightness value) 14598c2ecf20Sopenharmony_ci{ 14608c2ecf20Sopenharmony_ci struct xpad_led *xpad_led = container_of(led_cdev, 14618c2ecf20Sopenharmony_ci struct xpad_led, led_cdev); 14628c2ecf20Sopenharmony_ci 14638c2ecf20Sopenharmony_ci xpad_send_led_command(xpad_led->xpad, value); 14648c2ecf20Sopenharmony_ci} 14658c2ecf20Sopenharmony_ci 14668c2ecf20Sopenharmony_cistatic int xpad_led_probe(struct usb_xpad *xpad) 14678c2ecf20Sopenharmony_ci{ 14688c2ecf20Sopenharmony_ci struct xpad_led *led; 14698c2ecf20Sopenharmony_ci struct led_classdev *led_cdev; 14708c2ecf20Sopenharmony_ci int error; 14718c2ecf20Sopenharmony_ci 14728c2ecf20Sopenharmony_ci if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W) 14738c2ecf20Sopenharmony_ci return 0; 14748c2ecf20Sopenharmony_ci 14758c2ecf20Sopenharmony_ci xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL); 14768c2ecf20Sopenharmony_ci if (!led) 14778c2ecf20Sopenharmony_ci return -ENOMEM; 14788c2ecf20Sopenharmony_ci 14798c2ecf20Sopenharmony_ci xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL); 14808c2ecf20Sopenharmony_ci if (xpad->pad_nr < 0) { 14818c2ecf20Sopenharmony_ci error = xpad->pad_nr; 14828c2ecf20Sopenharmony_ci goto err_free_mem; 14838c2ecf20Sopenharmony_ci } 14848c2ecf20Sopenharmony_ci 14858c2ecf20Sopenharmony_ci snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr); 14868c2ecf20Sopenharmony_ci led->xpad = xpad; 14878c2ecf20Sopenharmony_ci 14888c2ecf20Sopenharmony_ci led_cdev = &led->led_cdev; 14898c2ecf20Sopenharmony_ci led_cdev->name = led->name; 14908c2ecf20Sopenharmony_ci led_cdev->brightness_set = xpad_led_set; 14918c2ecf20Sopenharmony_ci led_cdev->flags = LED_CORE_SUSPENDRESUME; 14928c2ecf20Sopenharmony_ci 14938c2ecf20Sopenharmony_ci error = led_classdev_register(&xpad->udev->dev, led_cdev); 14948c2ecf20Sopenharmony_ci if (error) 14958c2ecf20Sopenharmony_ci goto err_free_id; 14968c2ecf20Sopenharmony_ci 14978c2ecf20Sopenharmony_ci xpad_identify_controller(xpad); 14988c2ecf20Sopenharmony_ci 14998c2ecf20Sopenharmony_ci return 0; 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_cierr_free_id: 15028c2ecf20Sopenharmony_ci ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); 15038c2ecf20Sopenharmony_cierr_free_mem: 15048c2ecf20Sopenharmony_ci kfree(led); 15058c2ecf20Sopenharmony_ci xpad->led = NULL; 15068c2ecf20Sopenharmony_ci return error; 15078c2ecf20Sopenharmony_ci} 15088c2ecf20Sopenharmony_ci 15098c2ecf20Sopenharmony_cistatic void xpad_led_disconnect(struct usb_xpad *xpad) 15108c2ecf20Sopenharmony_ci{ 15118c2ecf20Sopenharmony_ci struct xpad_led *xpad_led = xpad->led; 15128c2ecf20Sopenharmony_ci 15138c2ecf20Sopenharmony_ci if (xpad_led) { 15148c2ecf20Sopenharmony_ci led_classdev_unregister(&xpad_led->led_cdev); 15158c2ecf20Sopenharmony_ci ida_simple_remove(&xpad_pad_seq, xpad->pad_nr); 15168c2ecf20Sopenharmony_ci kfree(xpad_led); 15178c2ecf20Sopenharmony_ci } 15188c2ecf20Sopenharmony_ci} 15198c2ecf20Sopenharmony_ci#else 15208c2ecf20Sopenharmony_cistatic int xpad_led_probe(struct usb_xpad *xpad) { return 0; } 15218c2ecf20Sopenharmony_cistatic void xpad_led_disconnect(struct usb_xpad *xpad) { } 15228c2ecf20Sopenharmony_ci#endif 15238c2ecf20Sopenharmony_ci 15248c2ecf20Sopenharmony_cistatic int xpad_start_input(struct usb_xpad *xpad) 15258c2ecf20Sopenharmony_ci{ 15268c2ecf20Sopenharmony_ci int error; 15278c2ecf20Sopenharmony_ci 15288c2ecf20Sopenharmony_ci if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) 15298c2ecf20Sopenharmony_ci return -EIO; 15308c2ecf20Sopenharmony_ci 15318c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOXONE) { 15328c2ecf20Sopenharmony_ci error = xpad_start_xbox_one(xpad); 15338c2ecf20Sopenharmony_ci if (error) { 15348c2ecf20Sopenharmony_ci usb_kill_urb(xpad->irq_in); 15358c2ecf20Sopenharmony_ci return error; 15368c2ecf20Sopenharmony_ci } 15378c2ecf20Sopenharmony_ci } 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci return 0; 15408c2ecf20Sopenharmony_ci} 15418c2ecf20Sopenharmony_ci 15428c2ecf20Sopenharmony_cistatic void xpad_stop_input(struct usb_xpad *xpad) 15438c2ecf20Sopenharmony_ci{ 15448c2ecf20Sopenharmony_ci usb_kill_urb(xpad->irq_in); 15458c2ecf20Sopenharmony_ci} 15468c2ecf20Sopenharmony_ci 15478c2ecf20Sopenharmony_cistatic void xpad360w_poweroff_controller(struct usb_xpad *xpad) 15488c2ecf20Sopenharmony_ci{ 15498c2ecf20Sopenharmony_ci unsigned long flags; 15508c2ecf20Sopenharmony_ci struct xpad_output_packet *packet = 15518c2ecf20Sopenharmony_ci &xpad->out_packets[XPAD_OUT_CMD_IDX]; 15528c2ecf20Sopenharmony_ci 15538c2ecf20Sopenharmony_ci spin_lock_irqsave(&xpad->odata_lock, flags); 15548c2ecf20Sopenharmony_ci 15558c2ecf20Sopenharmony_ci packet->data[0] = 0x00; 15568c2ecf20Sopenharmony_ci packet->data[1] = 0x00; 15578c2ecf20Sopenharmony_ci packet->data[2] = 0x08; 15588c2ecf20Sopenharmony_ci packet->data[3] = 0xC0; 15598c2ecf20Sopenharmony_ci packet->data[4] = 0x00; 15608c2ecf20Sopenharmony_ci packet->data[5] = 0x00; 15618c2ecf20Sopenharmony_ci packet->data[6] = 0x00; 15628c2ecf20Sopenharmony_ci packet->data[7] = 0x00; 15638c2ecf20Sopenharmony_ci packet->data[8] = 0x00; 15648c2ecf20Sopenharmony_ci packet->data[9] = 0x00; 15658c2ecf20Sopenharmony_ci packet->data[10] = 0x00; 15668c2ecf20Sopenharmony_ci packet->data[11] = 0x00; 15678c2ecf20Sopenharmony_ci packet->len = 12; 15688c2ecf20Sopenharmony_ci packet->pending = true; 15698c2ecf20Sopenharmony_ci 15708c2ecf20Sopenharmony_ci /* Reset the sequence so we send out poweroff now */ 15718c2ecf20Sopenharmony_ci xpad->last_out_packet = -1; 15728c2ecf20Sopenharmony_ci xpad_try_sending_next_out_packet(xpad); 15738c2ecf20Sopenharmony_ci 15748c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&xpad->odata_lock, flags); 15758c2ecf20Sopenharmony_ci} 15768c2ecf20Sopenharmony_ci 15778c2ecf20Sopenharmony_cistatic int xpad360w_start_input(struct usb_xpad *xpad) 15788c2ecf20Sopenharmony_ci{ 15798c2ecf20Sopenharmony_ci int error; 15808c2ecf20Sopenharmony_ci 15818c2ecf20Sopenharmony_ci error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); 15828c2ecf20Sopenharmony_ci if (error) 15838c2ecf20Sopenharmony_ci return -EIO; 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci /* 15868c2ecf20Sopenharmony_ci * Send presence packet. 15878c2ecf20Sopenharmony_ci * This will force the controller to resend connection packets. 15888c2ecf20Sopenharmony_ci * This is useful in the case we activate the module after the 15898c2ecf20Sopenharmony_ci * adapter has been plugged in, as it won't automatically 15908c2ecf20Sopenharmony_ci * send us info about the controllers. 15918c2ecf20Sopenharmony_ci */ 15928c2ecf20Sopenharmony_ci error = xpad_inquiry_pad_presence(xpad); 15938c2ecf20Sopenharmony_ci if (error) { 15948c2ecf20Sopenharmony_ci usb_kill_urb(xpad->irq_in); 15958c2ecf20Sopenharmony_ci return error; 15968c2ecf20Sopenharmony_ci } 15978c2ecf20Sopenharmony_ci 15988c2ecf20Sopenharmony_ci return 0; 15998c2ecf20Sopenharmony_ci} 16008c2ecf20Sopenharmony_ci 16018c2ecf20Sopenharmony_cistatic void xpad360w_stop_input(struct usb_xpad *xpad) 16028c2ecf20Sopenharmony_ci{ 16038c2ecf20Sopenharmony_ci usb_kill_urb(xpad->irq_in); 16048c2ecf20Sopenharmony_ci 16058c2ecf20Sopenharmony_ci /* Make sure we are done with presence work if it was scheduled */ 16068c2ecf20Sopenharmony_ci flush_work(&xpad->work); 16078c2ecf20Sopenharmony_ci} 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_cistatic int xpad_open(struct input_dev *dev) 16108c2ecf20Sopenharmony_ci{ 16118c2ecf20Sopenharmony_ci struct usb_xpad *xpad = input_get_drvdata(dev); 16128c2ecf20Sopenharmony_ci 16138c2ecf20Sopenharmony_ci return xpad_start_input(xpad); 16148c2ecf20Sopenharmony_ci} 16158c2ecf20Sopenharmony_ci 16168c2ecf20Sopenharmony_cistatic void xpad_close(struct input_dev *dev) 16178c2ecf20Sopenharmony_ci{ 16188c2ecf20Sopenharmony_ci struct usb_xpad *xpad = input_get_drvdata(dev); 16198c2ecf20Sopenharmony_ci 16208c2ecf20Sopenharmony_ci xpad_stop_input(xpad); 16218c2ecf20Sopenharmony_ci} 16228c2ecf20Sopenharmony_ci 16238c2ecf20Sopenharmony_cistatic void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) 16248c2ecf20Sopenharmony_ci{ 16258c2ecf20Sopenharmony_ci struct usb_xpad *xpad = input_get_drvdata(input_dev); 16268c2ecf20Sopenharmony_ci 16278c2ecf20Sopenharmony_ci switch (abs) { 16288c2ecf20Sopenharmony_ci case ABS_X: 16298c2ecf20Sopenharmony_ci case ABS_Y: 16308c2ecf20Sopenharmony_ci case ABS_RX: 16318c2ecf20Sopenharmony_ci case ABS_RY: /* the two sticks */ 16328c2ecf20Sopenharmony_ci input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); 16338c2ecf20Sopenharmony_ci break; 16348c2ecf20Sopenharmony_ci case ABS_Z: 16358c2ecf20Sopenharmony_ci case ABS_RZ: /* the triggers (if mapped to axes) */ 16368c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOXONE) 16378c2ecf20Sopenharmony_ci input_set_abs_params(input_dev, abs, 0, 1023, 0, 0); 16388c2ecf20Sopenharmony_ci else 16398c2ecf20Sopenharmony_ci input_set_abs_params(input_dev, abs, 0, 255, 0, 0); 16408c2ecf20Sopenharmony_ci break; 16418c2ecf20Sopenharmony_ci case ABS_HAT0X: 16428c2ecf20Sopenharmony_ci case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */ 16438c2ecf20Sopenharmony_ci input_set_abs_params(input_dev, abs, -1, 1, 0, 0); 16448c2ecf20Sopenharmony_ci break; 16458c2ecf20Sopenharmony_ci default: 16468c2ecf20Sopenharmony_ci input_set_abs_params(input_dev, abs, 0, 0, 0, 0); 16478c2ecf20Sopenharmony_ci break; 16488c2ecf20Sopenharmony_ci } 16498c2ecf20Sopenharmony_ci} 16508c2ecf20Sopenharmony_ci 16518c2ecf20Sopenharmony_cistatic void xpad_deinit_input(struct usb_xpad *xpad) 16528c2ecf20Sopenharmony_ci{ 16538c2ecf20Sopenharmony_ci if (xpad->input_created) { 16548c2ecf20Sopenharmony_ci xpad->input_created = false; 16558c2ecf20Sopenharmony_ci xpad_led_disconnect(xpad); 16568c2ecf20Sopenharmony_ci input_unregister_device(xpad->dev); 16578c2ecf20Sopenharmony_ci } 16588c2ecf20Sopenharmony_ci} 16598c2ecf20Sopenharmony_ci 16608c2ecf20Sopenharmony_cistatic int xpad_init_input(struct usb_xpad *xpad) 16618c2ecf20Sopenharmony_ci{ 16628c2ecf20Sopenharmony_ci struct input_dev *input_dev; 16638c2ecf20Sopenharmony_ci int i, error; 16648c2ecf20Sopenharmony_ci 16658c2ecf20Sopenharmony_ci input_dev = input_allocate_device(); 16668c2ecf20Sopenharmony_ci if (!input_dev) 16678c2ecf20Sopenharmony_ci return -ENOMEM; 16688c2ecf20Sopenharmony_ci 16698c2ecf20Sopenharmony_ci xpad->dev = input_dev; 16708c2ecf20Sopenharmony_ci input_dev->name = xpad->name; 16718c2ecf20Sopenharmony_ci input_dev->phys = xpad->phys; 16728c2ecf20Sopenharmony_ci usb_to_input_id(xpad->udev, &input_dev->id); 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360W) { 16758c2ecf20Sopenharmony_ci /* x360w controllers and the receiver have different ids */ 16768c2ecf20Sopenharmony_ci input_dev->id.product = 0x02a1; 16778c2ecf20Sopenharmony_ci } 16788c2ecf20Sopenharmony_ci 16798c2ecf20Sopenharmony_ci input_dev->dev.parent = &xpad->intf->dev; 16808c2ecf20Sopenharmony_ci 16818c2ecf20Sopenharmony_ci input_set_drvdata(input_dev, xpad); 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci if (xpad->xtype != XTYPE_XBOX360W) { 16848c2ecf20Sopenharmony_ci input_dev->open = xpad_open; 16858c2ecf20Sopenharmony_ci input_dev->close = xpad_close; 16868c2ecf20Sopenharmony_ci } 16878c2ecf20Sopenharmony_ci 16888c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 16898c2ecf20Sopenharmony_ci /* set up axes */ 16908c2ecf20Sopenharmony_ci for (i = 0; xpad_abs[i] >= 0; i++) 16918c2ecf20Sopenharmony_ci xpad_set_up_abs(input_dev, xpad_abs[i]); 16928c2ecf20Sopenharmony_ci } 16938c2ecf20Sopenharmony_ci 16948c2ecf20Sopenharmony_ci /* set up standard buttons */ 16958c2ecf20Sopenharmony_ci for (i = 0; xpad_common_btn[i] >= 0; i++) 16968c2ecf20Sopenharmony_ci input_set_capability(input_dev, EV_KEY, xpad_common_btn[i]); 16978c2ecf20Sopenharmony_ci 16988c2ecf20Sopenharmony_ci /* set up model-specific ones */ 16998c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W || 17008c2ecf20Sopenharmony_ci xpad->xtype == XTYPE_XBOXONE) { 17018c2ecf20Sopenharmony_ci for (i = 0; xpad360_btn[i] >= 0; i++) 17028c2ecf20Sopenharmony_ci input_set_capability(input_dev, EV_KEY, xpad360_btn[i]); 17038c2ecf20Sopenharmony_ci } else { 17048c2ecf20Sopenharmony_ci for (i = 0; xpad_btn[i] >= 0; i++) 17058c2ecf20Sopenharmony_ci input_set_capability(input_dev, EV_KEY, xpad_btn[i]); 17068c2ecf20Sopenharmony_ci } 17078c2ecf20Sopenharmony_ci 17088c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 17098c2ecf20Sopenharmony_ci for (i = 0; xpad_btn_pad[i] >= 0; i++) 17108c2ecf20Sopenharmony_ci input_set_capability(input_dev, EV_KEY, 17118c2ecf20Sopenharmony_ci xpad_btn_pad[i]); 17128c2ecf20Sopenharmony_ci } 17138c2ecf20Sopenharmony_ci 17148c2ecf20Sopenharmony_ci /* 17158c2ecf20Sopenharmony_ci * This should be a simple else block. However historically 17168c2ecf20Sopenharmony_ci * xbox360w has mapped DPAD to buttons while xbox360 did not. This 17178c2ecf20Sopenharmony_ci * made no sense, but now we can not just switch back and have to 17188c2ecf20Sopenharmony_ci * support both behaviors. 17198c2ecf20Sopenharmony_ci */ 17208c2ecf20Sopenharmony_ci if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) || 17218c2ecf20Sopenharmony_ci xpad->xtype == XTYPE_XBOX360W) { 17228c2ecf20Sopenharmony_ci for (i = 0; xpad_abs_pad[i] >= 0; i++) 17238c2ecf20Sopenharmony_ci xpad_set_up_abs(input_dev, xpad_abs_pad[i]); 17248c2ecf20Sopenharmony_ci } 17258c2ecf20Sopenharmony_ci 17268c2ecf20Sopenharmony_ci if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 17278c2ecf20Sopenharmony_ci for (i = 0; xpad_btn_triggers[i] >= 0; i++) 17288c2ecf20Sopenharmony_ci input_set_capability(input_dev, EV_KEY, 17298c2ecf20Sopenharmony_ci xpad_btn_triggers[i]); 17308c2ecf20Sopenharmony_ci } else { 17318c2ecf20Sopenharmony_ci for (i = 0; xpad_abs_triggers[i] >= 0; i++) 17328c2ecf20Sopenharmony_ci xpad_set_up_abs(input_dev, xpad_abs_triggers[i]); 17338c2ecf20Sopenharmony_ci } 17348c2ecf20Sopenharmony_ci 17358c2ecf20Sopenharmony_ci error = xpad_init_ff(xpad); 17368c2ecf20Sopenharmony_ci if (error) 17378c2ecf20Sopenharmony_ci goto err_free_input; 17388c2ecf20Sopenharmony_ci 17398c2ecf20Sopenharmony_ci error = xpad_led_probe(xpad); 17408c2ecf20Sopenharmony_ci if (error) 17418c2ecf20Sopenharmony_ci goto err_destroy_ff; 17428c2ecf20Sopenharmony_ci 17438c2ecf20Sopenharmony_ci error = input_register_device(xpad->dev); 17448c2ecf20Sopenharmony_ci if (error) 17458c2ecf20Sopenharmony_ci goto err_disconnect_led; 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci xpad->input_created = true; 17488c2ecf20Sopenharmony_ci return 0; 17498c2ecf20Sopenharmony_ci 17508c2ecf20Sopenharmony_cierr_disconnect_led: 17518c2ecf20Sopenharmony_ci xpad_led_disconnect(xpad); 17528c2ecf20Sopenharmony_cierr_destroy_ff: 17538c2ecf20Sopenharmony_ci input_ff_destroy(input_dev); 17548c2ecf20Sopenharmony_cierr_free_input: 17558c2ecf20Sopenharmony_ci input_free_device(input_dev); 17568c2ecf20Sopenharmony_ci return error; 17578c2ecf20Sopenharmony_ci} 17588c2ecf20Sopenharmony_ci 17598c2ecf20Sopenharmony_cistatic int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) 17608c2ecf20Sopenharmony_ci{ 17618c2ecf20Sopenharmony_ci struct usb_device *udev = interface_to_usbdev(intf); 17628c2ecf20Sopenharmony_ci struct usb_xpad *xpad; 17638c2ecf20Sopenharmony_ci struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out; 17648c2ecf20Sopenharmony_ci int i, error; 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci if (intf->cur_altsetting->desc.bNumEndpoints != 2) 17678c2ecf20Sopenharmony_ci return -ENODEV; 17688c2ecf20Sopenharmony_ci 17698c2ecf20Sopenharmony_ci for (i = 0; xpad_device[i].idVendor; i++) { 17708c2ecf20Sopenharmony_ci if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && 17718c2ecf20Sopenharmony_ci (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct)) 17728c2ecf20Sopenharmony_ci break; 17738c2ecf20Sopenharmony_ci } 17748c2ecf20Sopenharmony_ci 17758c2ecf20Sopenharmony_ci xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL); 17768c2ecf20Sopenharmony_ci if (!xpad) 17778c2ecf20Sopenharmony_ci return -ENOMEM; 17788c2ecf20Sopenharmony_ci 17798c2ecf20Sopenharmony_ci usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); 17808c2ecf20Sopenharmony_ci strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); 17818c2ecf20Sopenharmony_ci 17828c2ecf20Sopenharmony_ci xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, 17838c2ecf20Sopenharmony_ci GFP_KERNEL, &xpad->idata_dma); 17848c2ecf20Sopenharmony_ci if (!xpad->idata) { 17858c2ecf20Sopenharmony_ci error = -ENOMEM; 17868c2ecf20Sopenharmony_ci goto err_free_mem; 17878c2ecf20Sopenharmony_ci } 17888c2ecf20Sopenharmony_ci 17898c2ecf20Sopenharmony_ci xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); 17908c2ecf20Sopenharmony_ci if (!xpad->irq_in) { 17918c2ecf20Sopenharmony_ci error = -ENOMEM; 17928c2ecf20Sopenharmony_ci goto err_free_idata; 17938c2ecf20Sopenharmony_ci } 17948c2ecf20Sopenharmony_ci 17958c2ecf20Sopenharmony_ci xpad->udev = udev; 17968c2ecf20Sopenharmony_ci xpad->intf = intf; 17978c2ecf20Sopenharmony_ci xpad->mapping = xpad_device[i].mapping; 17988c2ecf20Sopenharmony_ci xpad->xtype = xpad_device[i].xtype; 17998c2ecf20Sopenharmony_ci xpad->name = xpad_device[i].name; 18008c2ecf20Sopenharmony_ci INIT_WORK(&xpad->work, xpad_presence_work); 18018c2ecf20Sopenharmony_ci 18028c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_UNKNOWN) { 18038c2ecf20Sopenharmony_ci if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { 18048c2ecf20Sopenharmony_ci if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) 18058c2ecf20Sopenharmony_ci xpad->xtype = XTYPE_XBOX360W; 18068c2ecf20Sopenharmony_ci else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208) 18078c2ecf20Sopenharmony_ci xpad->xtype = XTYPE_XBOXONE; 18088c2ecf20Sopenharmony_ci else 18098c2ecf20Sopenharmony_ci xpad->xtype = XTYPE_XBOX360; 18108c2ecf20Sopenharmony_ci } else { 18118c2ecf20Sopenharmony_ci xpad->xtype = XTYPE_XBOX; 18128c2ecf20Sopenharmony_ci } 18138c2ecf20Sopenharmony_ci 18148c2ecf20Sopenharmony_ci if (dpad_to_buttons) 18158c2ecf20Sopenharmony_ci xpad->mapping |= MAP_DPAD_TO_BUTTONS; 18168c2ecf20Sopenharmony_ci if (triggers_to_buttons) 18178c2ecf20Sopenharmony_ci xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS; 18188c2ecf20Sopenharmony_ci if (sticks_to_null) 18198c2ecf20Sopenharmony_ci xpad->mapping |= MAP_STICKS_TO_NULL; 18208c2ecf20Sopenharmony_ci } 18218c2ecf20Sopenharmony_ci 18228c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOXONE && 18238c2ecf20Sopenharmony_ci intf->cur_altsetting->desc.bInterfaceNumber != GIP_WIRED_INTF_DATA) { 18248c2ecf20Sopenharmony_ci /* 18258c2ecf20Sopenharmony_ci * The Xbox One controller lists three interfaces all with the 18268c2ecf20Sopenharmony_ci * same interface class, subclass and protocol. Differentiate by 18278c2ecf20Sopenharmony_ci * interface number. 18288c2ecf20Sopenharmony_ci */ 18298c2ecf20Sopenharmony_ci error = -ENODEV; 18308c2ecf20Sopenharmony_ci goto err_free_in_urb; 18318c2ecf20Sopenharmony_ci } 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci ep_irq_in = ep_irq_out = NULL; 18348c2ecf20Sopenharmony_ci 18358c2ecf20Sopenharmony_ci for (i = 0; i < 2; i++) { 18368c2ecf20Sopenharmony_ci struct usb_endpoint_descriptor *ep = 18378c2ecf20Sopenharmony_ci &intf->cur_altsetting->endpoint[i].desc; 18388c2ecf20Sopenharmony_ci 18398c2ecf20Sopenharmony_ci if (usb_endpoint_xfer_int(ep)) { 18408c2ecf20Sopenharmony_ci if (usb_endpoint_dir_in(ep)) 18418c2ecf20Sopenharmony_ci ep_irq_in = ep; 18428c2ecf20Sopenharmony_ci else 18438c2ecf20Sopenharmony_ci ep_irq_out = ep; 18448c2ecf20Sopenharmony_ci } 18458c2ecf20Sopenharmony_ci } 18468c2ecf20Sopenharmony_ci 18478c2ecf20Sopenharmony_ci if (!ep_irq_in || !ep_irq_out) { 18488c2ecf20Sopenharmony_ci error = -ENODEV; 18498c2ecf20Sopenharmony_ci goto err_free_in_urb; 18508c2ecf20Sopenharmony_ci } 18518c2ecf20Sopenharmony_ci 18528c2ecf20Sopenharmony_ci error = xpad_init_output(intf, xpad, ep_irq_out); 18538c2ecf20Sopenharmony_ci if (error) 18548c2ecf20Sopenharmony_ci goto err_free_in_urb; 18558c2ecf20Sopenharmony_ci 18568c2ecf20Sopenharmony_ci usb_fill_int_urb(xpad->irq_in, udev, 18578c2ecf20Sopenharmony_ci usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), 18588c2ecf20Sopenharmony_ci xpad->idata, XPAD_PKT_LEN, xpad_irq_in, 18598c2ecf20Sopenharmony_ci xpad, ep_irq_in->bInterval); 18608c2ecf20Sopenharmony_ci xpad->irq_in->transfer_dma = xpad->idata_dma; 18618c2ecf20Sopenharmony_ci xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_ci usb_set_intfdata(intf, xpad); 18648c2ecf20Sopenharmony_ci 18658c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360W) { 18668c2ecf20Sopenharmony_ci /* 18678c2ecf20Sopenharmony_ci * Submit the int URB immediately rather than waiting for open 18688c2ecf20Sopenharmony_ci * because we get status messages from the device whether 18698c2ecf20Sopenharmony_ci * or not any controllers are attached. In fact, it's 18708c2ecf20Sopenharmony_ci * exactly the message that a controller has arrived that 18718c2ecf20Sopenharmony_ci * we're waiting for. 18728c2ecf20Sopenharmony_ci */ 18738c2ecf20Sopenharmony_ci error = xpad360w_start_input(xpad); 18748c2ecf20Sopenharmony_ci if (error) 18758c2ecf20Sopenharmony_ci goto err_deinit_output; 18768c2ecf20Sopenharmony_ci /* 18778c2ecf20Sopenharmony_ci * Wireless controllers require RESET_RESUME to work properly 18788c2ecf20Sopenharmony_ci * after suspend. Ideally this quirk should be in usb core 18798c2ecf20Sopenharmony_ci * quirk list, but we have too many vendors producing these 18808c2ecf20Sopenharmony_ci * controllers and we'd need to maintain 2 identical lists 18818c2ecf20Sopenharmony_ci * here in this driver and in usb core. 18828c2ecf20Sopenharmony_ci */ 18838c2ecf20Sopenharmony_ci udev->quirks |= USB_QUIRK_RESET_RESUME; 18848c2ecf20Sopenharmony_ci } else { 18858c2ecf20Sopenharmony_ci error = xpad_init_input(xpad); 18868c2ecf20Sopenharmony_ci if (error) 18878c2ecf20Sopenharmony_ci goto err_deinit_output; 18888c2ecf20Sopenharmony_ci } 18898c2ecf20Sopenharmony_ci return 0; 18908c2ecf20Sopenharmony_ci 18918c2ecf20Sopenharmony_cierr_deinit_output: 18928c2ecf20Sopenharmony_ci xpad_deinit_output(xpad); 18938c2ecf20Sopenharmony_cierr_free_in_urb: 18948c2ecf20Sopenharmony_ci usb_free_urb(xpad->irq_in); 18958c2ecf20Sopenharmony_cierr_free_idata: 18968c2ecf20Sopenharmony_ci usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 18978c2ecf20Sopenharmony_cierr_free_mem: 18988c2ecf20Sopenharmony_ci kfree(xpad); 18998c2ecf20Sopenharmony_ci return error; 19008c2ecf20Sopenharmony_ci} 19018c2ecf20Sopenharmony_ci 19028c2ecf20Sopenharmony_cistatic void xpad_disconnect(struct usb_interface *intf) 19038c2ecf20Sopenharmony_ci{ 19048c2ecf20Sopenharmony_ci struct usb_xpad *xpad = usb_get_intfdata(intf); 19058c2ecf20Sopenharmony_ci 19068c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360W) 19078c2ecf20Sopenharmony_ci xpad360w_stop_input(xpad); 19088c2ecf20Sopenharmony_ci 19098c2ecf20Sopenharmony_ci xpad_deinit_input(xpad); 19108c2ecf20Sopenharmony_ci 19118c2ecf20Sopenharmony_ci /* 19128c2ecf20Sopenharmony_ci * Now that both input device and LED device are gone we can 19138c2ecf20Sopenharmony_ci * stop output URB. 19148c2ecf20Sopenharmony_ci */ 19158c2ecf20Sopenharmony_ci xpad_stop_output(xpad); 19168c2ecf20Sopenharmony_ci 19178c2ecf20Sopenharmony_ci xpad_deinit_output(xpad); 19188c2ecf20Sopenharmony_ci 19198c2ecf20Sopenharmony_ci usb_free_urb(xpad->irq_in); 19208c2ecf20Sopenharmony_ci usb_free_coherent(xpad->udev, XPAD_PKT_LEN, 19218c2ecf20Sopenharmony_ci xpad->idata, xpad->idata_dma); 19228c2ecf20Sopenharmony_ci 19238c2ecf20Sopenharmony_ci kfree(xpad); 19248c2ecf20Sopenharmony_ci 19258c2ecf20Sopenharmony_ci usb_set_intfdata(intf, NULL); 19268c2ecf20Sopenharmony_ci} 19278c2ecf20Sopenharmony_ci 19288c2ecf20Sopenharmony_cistatic int xpad_suspend(struct usb_interface *intf, pm_message_t message) 19298c2ecf20Sopenharmony_ci{ 19308c2ecf20Sopenharmony_ci struct usb_xpad *xpad = usb_get_intfdata(intf); 19318c2ecf20Sopenharmony_ci struct input_dev *input = xpad->dev; 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360W) { 19348c2ecf20Sopenharmony_ci /* 19358c2ecf20Sopenharmony_ci * Wireless controllers always listen to input so 19368c2ecf20Sopenharmony_ci * they are notified when controller shows up 19378c2ecf20Sopenharmony_ci * or goes away. 19388c2ecf20Sopenharmony_ci */ 19398c2ecf20Sopenharmony_ci xpad360w_stop_input(xpad); 19408c2ecf20Sopenharmony_ci 19418c2ecf20Sopenharmony_ci /* 19428c2ecf20Sopenharmony_ci * The wireless adapter is going off now, so the 19438c2ecf20Sopenharmony_ci * gamepads are going to become disconnected. 19448c2ecf20Sopenharmony_ci * Unless explicitly disabled, power them down 19458c2ecf20Sopenharmony_ci * so they don't just sit there flashing. 19468c2ecf20Sopenharmony_ci */ 19478c2ecf20Sopenharmony_ci if (auto_poweroff && xpad->pad_present) 19488c2ecf20Sopenharmony_ci xpad360w_poweroff_controller(xpad); 19498c2ecf20Sopenharmony_ci } else { 19508c2ecf20Sopenharmony_ci mutex_lock(&input->mutex); 19518c2ecf20Sopenharmony_ci if (input->users) 19528c2ecf20Sopenharmony_ci xpad_stop_input(xpad); 19538c2ecf20Sopenharmony_ci mutex_unlock(&input->mutex); 19548c2ecf20Sopenharmony_ci } 19558c2ecf20Sopenharmony_ci 19568c2ecf20Sopenharmony_ci xpad_stop_output(xpad); 19578c2ecf20Sopenharmony_ci 19588c2ecf20Sopenharmony_ci return 0; 19598c2ecf20Sopenharmony_ci} 19608c2ecf20Sopenharmony_ci 19618c2ecf20Sopenharmony_cistatic int xpad_resume(struct usb_interface *intf) 19628c2ecf20Sopenharmony_ci{ 19638c2ecf20Sopenharmony_ci struct usb_xpad *xpad = usb_get_intfdata(intf); 19648c2ecf20Sopenharmony_ci struct input_dev *input = xpad->dev; 19658c2ecf20Sopenharmony_ci int retval = 0; 19668c2ecf20Sopenharmony_ci 19678c2ecf20Sopenharmony_ci if (xpad->xtype == XTYPE_XBOX360W) { 19688c2ecf20Sopenharmony_ci retval = xpad360w_start_input(xpad); 19698c2ecf20Sopenharmony_ci } else { 19708c2ecf20Sopenharmony_ci mutex_lock(&input->mutex); 19718c2ecf20Sopenharmony_ci if (input->users) { 19728c2ecf20Sopenharmony_ci retval = xpad_start_input(xpad); 19738c2ecf20Sopenharmony_ci } else if (xpad->xtype == XTYPE_XBOXONE) { 19748c2ecf20Sopenharmony_ci /* 19758c2ecf20Sopenharmony_ci * Even if there are no users, we'll send Xbox One pads 19768c2ecf20Sopenharmony_ci * the startup sequence so they don't sit there and 19778c2ecf20Sopenharmony_ci * blink until somebody opens the input device again. 19788c2ecf20Sopenharmony_ci */ 19798c2ecf20Sopenharmony_ci retval = xpad_start_xbox_one(xpad); 19808c2ecf20Sopenharmony_ci } 19818c2ecf20Sopenharmony_ci mutex_unlock(&input->mutex); 19828c2ecf20Sopenharmony_ci } 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_ci return retval; 19858c2ecf20Sopenharmony_ci} 19868c2ecf20Sopenharmony_ci 19878c2ecf20Sopenharmony_cistatic struct usb_driver xpad_driver = { 19888c2ecf20Sopenharmony_ci .name = "xpad", 19898c2ecf20Sopenharmony_ci .probe = xpad_probe, 19908c2ecf20Sopenharmony_ci .disconnect = xpad_disconnect, 19918c2ecf20Sopenharmony_ci .suspend = xpad_suspend, 19928c2ecf20Sopenharmony_ci .resume = xpad_resume, 19938c2ecf20Sopenharmony_ci .id_table = xpad_table, 19948c2ecf20Sopenharmony_ci}; 19958c2ecf20Sopenharmony_ci 19968c2ecf20Sopenharmony_cimodule_usb_driver(xpad_driver); 19978c2ecf20Sopenharmony_ci 19988c2ecf20Sopenharmony_ciMODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>"); 19998c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("X-Box pad driver"); 20008c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 2001