Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * X-Box gamepad driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *               2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *                    Steven Toth <steve@toth.demon.co.uk>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *                    Franz Lehner <franz@caos.at>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *                    Ivan Hawkes <blackhawk@ivanhawkes.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *               2005 Dominic Cerquetti <binary1230@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *               2006 Adam Buchbinder <adam.buchbinder@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *               2007 Jan Kratochvil <honza@jikos.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *               2010 Christoph Fritz <chf.fritz@googlemail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * This driver is based on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *  - information from     http://euc.jp/periphs/xbox-controller.ja.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *  - the iForce driver    drivers/char/joystick/iforce.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *  - the skeleton-driver  drivers/usb/usb-skeleton.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *  - Xbox 360 information http://www.free60.org/wiki/Gamepad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *  - Xbox One information https://github.com/quantus/xbox-one-controller-protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * Thanks to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *  - ITO Takayuki for providing essential xpad information on his website
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *  - Vojtech Pavlik     - iforce driver / input subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *  - Greg Kroah-Hartman - usb-skeleton driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *  - XBOX Linux project - extra USB id's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *  - Pekka Pöyry (quantus) - Xbox One controller reverse engineering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *  - fine tune axes (especially trigger axes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *  - fix "analog" buttons (reported as digital now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *  - get rumble working
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *  - need USB IDs for other dance pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * History:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * 2002-07-02 - 0.0.2 : basic working version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *  - all axes and 9 of the 10 buttons work (german InterAct device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *  - the black button does not work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *  - indentation fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *  - usb + input init sequence fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  *  - verified the lack of HID and report descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  *  - verified that ALL buttons WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  *  - fixed d-pad to axes mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  * 2002-07-17 - 0.0.5 : simplified d-pad handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  * 2004-10-02 - 0.0.6 : DDR pad support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  *  - borrowed from the XBOX linux kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  *  - USB id's for commonly used dance pads are present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  *  - dance pads will map D-PAD to buttons, not axes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  *  - pass the module paramater 'dpad_to_buttons' to force
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  *    the D-PAD to map to buttons if your pad is not detected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * Later changes can be tracked in SCM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <linux/usb/quirks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #define XPAD_PKT_LEN 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * xbox d-pads should map to buttons, as is required for DDR pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * but we map them to axes when possible to simplify things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define MAP_DPAD_TO_BUTTONS		(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define MAP_TRIGGERS_TO_BUTTONS		(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define MAP_STICKS_TO_NULL		(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define DANCEPAD_MAP_CONFIG	(MAP_DPAD_TO_BUTTONS |			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 				MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define XTYPE_XBOX        0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define XTYPE_XBOX360     1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define XTYPE_XBOX360W    2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define XTYPE_XBOXONE     3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #define XTYPE_UNKNOWN     4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) static bool dpad_to_buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) module_param(dpad_to_buttons, bool, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static bool triggers_to_buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) module_param(triggers_to_buttons, bool, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static bool sticks_to_null;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) module_param(sticks_to_null, bool, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) MODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static bool auto_poweroff = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) module_param(auto_poweroff, bool, S_IWUSR | S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) MODULE_PARM_DESC(auto_poweroff, "Power off wireless controllers on suspend");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static const struct xpad_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	u16 idVendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	u16 idProduct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	u8 mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	u8 xtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) } xpad_device[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	{ 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	{ 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	{ 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	{ 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	{ 0x044f, 0x0f10, "Thrustmaster Modena GT Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	{ 0x044f, 0xb326, "Thrustmaster Gamepad GP XID", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	{ 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	{ 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	{ 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	{ 0x045e, 0x0288, "Microsoft Xbox Controller S v2", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	{ 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	{ 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	{ 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	{ 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	{ 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	{ 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	{ 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	{ 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	{ 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	{ 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	{ 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	{ 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	{ 0x046d, 0xca8a, "Logitech Precision Vibration Feedback Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	{ 0x046d, 0xcaa3, "Logitech DriveFx Racing Wheel", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	{ 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	{ 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	{ 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	{ 0x05fe, 0x3030, "Chic Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	{ 0x05fe, 0x3031, "Chic Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	{ 0x062a, 0x0020, "Logic3 Xbox GamePad", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	{ 0x062a, 0x0033, "Competition Pro Steering Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	{ 0x06a3, 0x0200, "Saitek Racing Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	{ 0x06a3, 0x0201, "Saitek Adrenalin", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	{ 0x06a3, 0xf51a, "Saitek P3600", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	{ 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	{ 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	{ 0x0738, 0x4520, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	{ 0x0738, 0x4522, "Mad Catz LumiCON", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	{ 0x0738, 0x4526, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	{ 0x0738, 0x4530, "Mad Catz Universal MC2 Racing Wheel and Pedals", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	{ 0x0738, 0x4536, "Mad Catz MicroCON", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	{ 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	{ 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	{ 0x0738, 0x4586, "Mad Catz MicroCon Wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	{ 0x0738, 0x4588, "Mad Catz Blaster", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	{ 0x0738, 0x45ff, "Mad Catz Beat Pad (w/ Handle)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	{ 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	{ 0x0738, 0x4718, "Mad Catz Street Fighter IV FightStick SE", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	{ 0x0738, 0x4726, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	{ 0x0738, 0x4728, "Mad Catz Street Fighter IV FightPad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	{ 0x0738, 0x4736, "Mad Catz MicroCon Gamepad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	{ 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	{ 0x0738, 0x4740, "Mad Catz Beat Pad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	{ 0x0738, 0x4743, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	{ 0x0738, 0x4758, "Mad Catz Arcade Game Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	{ 0x0738, 0x4a01, "Mad Catz FightStick TE 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	{ 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	{ 0x0738, 0x9871, "Mad Catz Portable Drum", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	{ 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	{ 0x0738, 0xb738, "Mad Catz MVC2TE Stick 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	{ 0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad", XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	{ 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	{ 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	{ 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	{ 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	{ 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	{ 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	{ 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	{ 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	{ 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", DANCEPAD_MAP_CONFIG, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	{ 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	{ 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	{ 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	{ 0x0d2f, 0x0002, "Andamiro Pump It Up pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	{ 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	{ 0x0e4c, 0x1103, "Radica Gamester Reflex", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	{ 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	{ 0x0e4c, 0x3510, "Radica Gamester", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	{ 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	{ 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	{ 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	{ 0x0e6f, 0x0008, "After Glow Pro Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	{ 0x0e6f, 0x0105, "HSM3 Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	{ 0x0e6f, 0x0113, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	{ 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	{ 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	{ 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	{ 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	{ 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	{ 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	{ 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	{ 0x0e6f, 0x015c, "PDP Xbox One Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	{ 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	{ 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	{ 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	{ 0x0e6f, 0x0164, "PDP Battlefield One", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	{ 0x0e6f, 0x0165, "PDP Titanfall 2", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	{ 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	{ 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	{ 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	{ 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	{ 0x0e6f, 0x02a0, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	{ 0x0e6f, 0x02a1, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	{ 0x0e6f, 0x02a2, "PDP Wired Controller for Xbox One - Crimson Red", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	{ 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	{ 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	{ 0x0e6f, 0x02a7, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	{ 0x0e6f, 0x02a8, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	{ 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	{ 0x0e6f, 0x02ad, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	{ 0x0e6f, 0x02b3, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	{ 0x0e6f, 0x02b8, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	{ 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	{ 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	{ 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	{ 0x0e6f, 0x0413, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	{ 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	{ 0x0e6f, 0xf900, "PDP Afterglow AX.1", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	{ 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	{ 0x0e8f, 0x3008, "Generic xbox control (dealextreme)", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	{ 0x0f0d, 0x000a, "Hori Co. DOA4 FightStick", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	{ 0x0f0d, 0x000c, "Hori PadEX Turbo", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	{ 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	{ 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	{ 0x0f0d, 0x001b, "Hori Real Arcade Pro VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	{ 0x0f0d, 0x0063, "Hori Real Arcade Pro Hayabusa (USA) Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	{ 0x0f0d, 0x0067, "HORIPAD ONE", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	{ 0x0f0d, 0x0078, "Hori Real Arcade Pro V Kai Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	{ 0x0f30, 0x010b, "Philips Recoil", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	{ 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	{ 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	{ 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	{ 0x1038, 0x1430, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	{ 0x1038, 0x1431, "SteelSeries Stratus Duo", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	{ 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	{ 0x1209, 0x2882, "Ardwiino Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	{ 0x12ab, 0x0004, "Honey Bee Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	{ 0x12ab, 0x0301, "PDP AFTERGLOW AX.1", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	{ 0x12ab, 0x0303, "Mortal Kombat Klassic FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	{ 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	{ 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	{ 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	{ 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	{ 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	{ 0x1532, 0x0037, "Razer Sabertooth", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	{ 0x1532, 0x0a00, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	{ 0x1532, 0x0a03, "Razer Wildcat", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	{ 0x15e4, 0x3f00, "Power A Mini Pro Elite", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	{ 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	{ 0x15e4, 0x3f10, "Batarang Xbox 360 controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	{ 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	{ 0x1689, 0xfd00, "Razer Onza Tournament Edition", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	{ 0x1689, 0xfd01, "Razer Onza Classic Edition", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	{ 0x1689, 0xfe00, "Razer Sabertooth", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	{ 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	{ 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	{ 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	{ 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	{ 0x1bad, 0xf018, "Mad Catz Street Fighter IV SE Fighting Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	{ 0x1bad, 0xf019, "Mad Catz Brawlstick for Xbox 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	{ 0x1bad, 0xf021, "Mad Cats Ghost Recon FS GamePad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	{ 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	{ 0x1bad, 0xf025, "Mad Catz Call Of Duty", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	{ 0x1bad, 0xf027, "Mad Catz FPS Pro", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	{ 0x1bad, 0xf028, "Street Fighter IV FightPad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	{ 0x1bad, 0xf02e, "Mad Catz Fightpad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	{ 0x1bad, 0xf030, "Mad Catz Xbox 360 MC2 MicroCon Racing Wheel", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	{ 0x1bad, 0xf036, "Mad Catz MicroCon GamePad Pro", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	{ 0x1bad, 0xf038, "Street Fighter IV FightStick TE", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	{ 0x1bad, 0xf039, "Mad Catz MvC2 TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	{ 0x1bad, 0xf03a, "Mad Catz SFxT Fightstick Pro", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	{ 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	{ 0x1bad, 0xf03e, "Mad Catz MLG FightStick TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	{ 0x1bad, 0xf03f, "Mad Catz FightStick SoulCaliber", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	{ 0x1bad, 0xf042, "Mad Catz FightStick TES+", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	{ 0x1bad, 0xf080, "Mad Catz FightStick TE2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	{ 0x1bad, 0xf501, "HoriPad EX2 Turbo", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	{ 0x1bad, 0xf502, "Hori Real Arcade Pro.VX SA", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	{ 0x1bad, 0xf503, "Hori Fighting Stick VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	{ 0x1bad, 0xf504, "Hori Real Arcade Pro. EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	{ 0x1bad, 0xf505, "Hori Fighting Stick EX2B", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	{ 0x1bad, 0xf506, "Hori Real Arcade Pro.EX Premium VLX", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	{ 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	{ 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	{ 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	{ 0x1bad, 0xf904, "PDP Versus Fighting Pad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	{ 0x1bad, 0xf906, "MortalKombat FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	{ 0x1bad, 0xfa01, "MadCatz GamePad", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	{ 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	{ 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	{ 0x20d6, 0x2001, "BDA Xbox Series X Wired Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	{ 0x20d6, 0x2009, "PowerA Enhanced Wired Controller for Xbox Series X|S", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	{ 0x20d6, 0x281f, "PowerA Wired Controller For Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	{ 0x2e24, 0x0652, "Hyperkin Duke X-Box One pad", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	{ 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	{ 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	{ 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	{ 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	{ 0x24c6, 0x531a, "PowerA Pro Ex", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	{ 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	{ 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	{ 0x24c6, 0x542a, "Xbox ONE spectra", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	{ 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	{ 0x24c6, 0x5500, "Hori XBOX 360 EX 2 with Turbo", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	{ 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	{ 0x24c6, 0x5502, "Hori Fighting Stick VX Alt", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	{ 0x24c6, 0x5503, "Hori Fighting Edge", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	{ 0x24c6, 0x5506, "Hori SOULCALIBUR V Stick", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	{ 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	{ 0x24c6, 0x550e, "Hori Real Arcade Pro V Kai 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	{ 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	{ 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	{ 0x24c6, 0x5b00, "ThrustMaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	{ 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	{ 0x24c6, 0x5b03, "Thrustmaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	{ 0x24c6, 0x5d04, "Razer Sabertooth", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	{ 0x24c6, 0xfafe, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	{ 0x3285, 0x0607, "Nacon GC-100", 0, XTYPE_XBOX360 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	{ 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	{ 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	{ 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) /* buttons shared with xbox and xbox360 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) static const signed short xpad_common_btn[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	BTN_A, BTN_B, BTN_X, BTN_Y,			/* "analog" buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR,	/* start/back/sticks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	-1						/* terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) /* original xbox controllers only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) static const signed short xpad_btn[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	BTN_C, BTN_Z,		/* "analog" buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	-1			/* terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) /* used when dpad is mapped to buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) static const signed short xpad_btn_pad[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2,		/* d-pad left, right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4,		/* d-pad up, down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	-1				/* terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /* used when triggers are mapped to buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) static const signed short xpad_btn_triggers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	BTN_TL2, BTN_TR2,		/* triggers left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) static const signed short xpad360_btn[] = {  /* buttons for x360 controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	BTN_TL, BTN_TR,		/* Button LB/RB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	BTN_MODE,		/* The big X button */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) static const signed short xpad_abs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	ABS_X, ABS_Y,		/* left stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	ABS_RX, ABS_RY,		/* right stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	-1			/* terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) /* used when dpad is mapped to axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) static const signed short xpad_abs_pad[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	ABS_HAT0X, ABS_HAT0Y,	/* d-pad axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	-1			/* terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) /* used when triggers are mapped to axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) static const signed short xpad_abs_triggers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	ABS_Z, ABS_RZ,		/* triggers left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)  * Xbox 360 has a vendor-specific class, so we cannot match it with only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)  * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)  * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394)  * wireless controllers have protocol 129.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) #define XPAD_XBOX360_VENDOR_PROTOCOL(vend, pr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	.match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	.idVendor = (vend), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	.bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	.bInterfaceSubClass = 93, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	.bInterfaceProtocol = (pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) #define XPAD_XBOX360_VENDOR(vend) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	{ XPAD_XBOX360_VENDOR_PROTOCOL((vend), 1) }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	{ XPAD_XBOX360_VENDOR_PROTOCOL((vend), 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) /* The Xbox One controller uses subclass 71 and protocol 208. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) #define XPAD_XBOXONE_VENDOR_PROTOCOL(vend, pr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	.match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	.idVendor = (vend), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	.bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	.bInterfaceSubClass = 71, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	.bInterfaceProtocol = (pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) #define XPAD_XBOXONE_VENDOR(vend) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	{ XPAD_XBOXONE_VENDOR_PROTOCOL((vend), 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) static const struct usb_device_id xpad_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	{ USB_INTERFACE_INFO('X', 'B', 0) },	/* X-Box USB-IF not approved class */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	XPAD_XBOX360_VENDOR(0x0079),		/* GPD Win 2 Controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	XPAD_XBOX360_VENDOR(0x044f),		/* Thrustmaster X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	XPAD_XBOX360_VENDOR(0x045e),		/* Microsoft X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	XPAD_XBOXONE_VENDOR(0x045e),		/* Microsoft X-Box One controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	XPAD_XBOX360_VENDOR(0x046d),		/* Logitech X-Box 360 style controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	XPAD_XBOX360_VENDOR(0x056e),		/* Elecom JC-U3613M */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	XPAD_XBOX360_VENDOR(0x06a3),		/* Saitek P3600 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	XPAD_XBOX360_VENDOR(0x0738),		/* Mad Catz X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	{ USB_DEVICE(0x0738, 0x4540) },		/* Mad Catz Beat Pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	XPAD_XBOXONE_VENDOR(0x0738),		/* Mad Catz FightStick TE 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	XPAD_XBOX360_VENDOR(0x07ff),		/* Mad Catz GamePad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	XPAD_XBOX360_VENDOR(0x0e6f),		/* 0x0e6f X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	XPAD_XBOXONE_VENDOR(0x0e6f),		/* 0x0e6f X-Box One controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	XPAD_XBOX360_VENDOR(0x0f0d),		/* Hori Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	XPAD_XBOXONE_VENDOR(0x0f0d),		/* Hori Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	XPAD_XBOX360_VENDOR(0x1038),		/* SteelSeries Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	XPAD_XBOX360_VENDOR(0x11c9),		/* Nacon GC100XF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	XPAD_XBOX360_VENDOR(0x1209),		/* Ardwiino Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	XPAD_XBOX360_VENDOR(0x12ab),		/* X-Box 360 dance pads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	XPAD_XBOX360_VENDOR(0x1430),		/* RedOctane X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	XPAD_XBOX360_VENDOR(0x146b),		/* BigBen Interactive Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	XPAD_XBOX360_VENDOR(0x1532),		/* Razer Sabertooth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	XPAD_XBOXONE_VENDOR(0x1532),		/* Razer Wildcat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	XPAD_XBOX360_VENDOR(0x15e4),		/* Numark X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	XPAD_XBOX360_VENDOR(0x162e),		/* Joytech X-Box 360 controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	XPAD_XBOX360_VENDOR(0x1689),		/* Razer Onza */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	XPAD_XBOX360_VENDOR(0x1bad),		/* Harminix Rock Band Guitar and Drums */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	XPAD_XBOX360_VENDOR(0x20d6),		/* PowerA Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	XPAD_XBOXONE_VENDOR(0x20d6),		/* PowerA Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	XPAD_XBOX360_VENDOR(0x24c6),		/* PowerA Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	XPAD_XBOXONE_VENDOR(0x24c6),		/* PowerA Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	XPAD_XBOXONE_VENDOR(0x2e24),		/* Hyperkin Duke X-Box One pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	XPAD_XBOX360_VENDOR(0x2f24),		/* GameSir Controllers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	XPAD_XBOX360_VENDOR(0x3285),		/* Nacon GC-100 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) MODULE_DEVICE_TABLE(usb, xpad_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) struct xboxone_init_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	u16 idVendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	u16 idProduct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	const u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) #define XBOXONE_INIT_PKT(_vid, _pid, _data)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	{						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		.idVendor	= (_vid),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		.idProduct	= (_pid),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		.data		= (_data),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		.len		= ARRAY_SIZE(_data),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  * This packet is required for all Xbox One pads with 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475)  * or later firmware installed (or present from the factory).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static const u8 xboxone_fw2015_init[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	0x05, 0x20, 0x00, 0x01, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  * This packet is required for Xbox One S (0x045e:0x02ea)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  * and Xbox One Elite Series 2 (0x045e:0x0b00) pads to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  * initialize the controller that was previously used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)  * Bluetooth mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) static const u8 xboxone_s_init[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	0x05, 0x20, 0x00, 0x0f, 0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492)  * This packet is required for the Titanfall 2 Xbox One pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)  * (0x0e6f:0x0165) to finish initialization and for Hori pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494)  * (0x0f0d:0x0067) to make the analog sticks work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) static const u8 xboxone_hori_init[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	0x01, 0x20, 0x00, 0x09, 0x00, 0x04, 0x20, 0x3a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	0x00, 0x00, 0x00, 0x80, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)  * This packet is required for most (all?) of the PDP pads to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)  * sending input reports. These pads include: (0x0e6f:0x02ab),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)  * (0x0e6f:0x02a4), (0x0e6f:0x02a6).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) static const u8 xboxone_pdp_init1[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	0x0a, 0x20, 0x00, 0x03, 0x00, 0x01, 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511)  * This packet is required for most (all?) of the PDP pads to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)  * sending input reports. These pads include: (0x0e6f:0x02ab),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)  * (0x0e6f:0x02a4), (0x0e6f:0x02a6).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) static const u8 xboxone_pdp_init2[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	0x06, 0x20, 0x00, 0x02, 0x01, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  * A specific rumble packet is required for some PowerA pads to start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  * sending input reports. One of those pads is (0x24c6:0x543a).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) static const u8 xboxone_rumblebegin_init[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	0x1D, 0x1D, 0xFF, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  * A rumble packet with zero FF intensity will immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  * terminate the rumbling required to init PowerA pads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  * This should happen fast enough that the motors don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * spin up to enough speed to actually vibrate the gamepad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) static const u8 xboxone_rumbleend_init[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)  * This specifies the selection of init packets that a gamepad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  * will be sent on init *and* the order in which they will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  * sent. The correct sequence number will be added when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  * packet is going to be sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) static const struct xboxone_init_packet xboxone_init_packets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	XBOXONE_INIT_PKT(0x0e6f, 0x0165, xboxone_hori_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	XBOXONE_INIT_PKT(0x0f0d, 0x0067, xboxone_hori_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_fw2015_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	XBOXONE_INIT_PKT(0x045e, 0x02ea, xboxone_s_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	XBOXONE_INIT_PKT(0x045e, 0x0b00, xboxone_s_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumblebegin_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumblebegin_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumbleend_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumbleend_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumbleend_init),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) struct xpad_output_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	u8 data[XPAD_PKT_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	bool pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) #define XPAD_OUT_CMD_IDX	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) #define XPAD_OUT_FF_IDX		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) #define XPAD_OUT_LED_IDX	(1 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) #define XPAD_NUM_OUT_PACKETS	(1 + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 				 IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 				 IS_ENABLED(CONFIG_JOYSTICK_XPAD_LEDS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) struct usb_xpad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	struct input_dev *dev;		/* input device interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	struct input_dev __rcu *x360w_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	struct usb_device *udev;	/* usb device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	struct usb_interface *intf;	/* usb interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	bool pad_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	bool input_created;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	struct urb *irq_in;		/* urb for interrupt in report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	unsigned char *idata;		/* input data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	dma_addr_t idata_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	struct urb *irq_out;		/* urb for interrupt out report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	struct usb_anchor irq_out_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	bool irq_out_active;		/* we must not use an active URB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	u8 odata_serial;		/* serial number for xbox one protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	unsigned char *odata;		/* output data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	dma_addr_t odata_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	spinlock_t odata_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct xpad_output_packet out_packets[XPAD_NUM_OUT_PACKETS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	int last_out_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	int init_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	struct xpad_led *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	char phys[64];			/* physical device path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	int mapping;			/* map d-pad to buttons or to axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	int xtype;			/* type of xbox device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	int pad_nr;			/* the order x360 pads were attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	const char *name;		/* name of the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	struct work_struct work;	/* init/remove device from callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) static int xpad_init_input(struct usb_xpad *xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) static void xpad_deinit_input(struct usb_xpad *xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617)  *	xpad_process_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619)  *	Completes a request by converting the data into events for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620)  *	input subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)  *	The used report descriptor was taken from ITO Takayukis website:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  *	 http://euc.jp/periphs/xbox-controller.ja.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	struct input_dev *dev = xpad->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		/* left stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		input_report_abs(dev, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 				 (__s16) le16_to_cpup((__le16 *)(data + 12)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		input_report_abs(dev, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		/* right stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		input_report_abs(dev, ABS_RX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 				 (__s16) le16_to_cpup((__le16 *)(data + 16)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		input_report_abs(dev, ABS_RY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	/* triggers left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		input_report_key(dev, BTN_TL2, data[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		input_report_key(dev, BTN_TR2, data[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		input_report_abs(dev, ABS_Z, data[10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		input_report_abs(dev, ABS_RZ, data[11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	/* digital pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		/* dpad as buttons (left, right, up, down) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		input_report_abs(dev, ABS_HAT0X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		input_report_abs(dev, ABS_HAT0Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	/* start/back buttons and stick press left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	input_report_key(dev, BTN_START,  data[2] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	input_report_key(dev, BTN_SELECT, data[2] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	/* "analog" buttons A, B, X, Y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	input_report_key(dev, BTN_A, data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	input_report_key(dev, BTN_B, data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	input_report_key(dev, BTN_X, data[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	input_report_key(dev, BTN_Y, data[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	/* "analog" buttons black, white */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	input_report_key(dev, BTN_C, data[8]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	input_report_key(dev, BTN_Z, data[9]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686)  *	xpad360_process_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688)  *	Completes a request by converting the data into events for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)  *	input subsystem. It is version for xbox 360 controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691)  *	The used report descriptor was taken from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692)  *		http://www.free60.org/wiki/Gamepad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 				   u16 cmd, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	/* valid pad data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	if (data[0] != 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	/* digital pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		/* dpad as buttons (left, right, up, down) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	 * This should be a simple else block. However historically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	 * xbox360w has mapped DPAD to buttons while xbox360 did not. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	 * made no sense, but now we can not just switch back and have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	 * support both behaviors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	    xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		input_report_abs(dev, ABS_HAT0X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 				 !!(data[2] & 0x08) - !!(data[2] & 0x04));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		input_report_abs(dev, ABS_HAT0Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 				 !!(data[2] & 0x02) - !!(data[2] & 0x01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	/* start/back buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	input_report_key(dev, BTN_START,  data[2] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	input_report_key(dev, BTN_SELECT, data[2] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	/* stick press left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	/* buttons A,B,X,Y,TL,TR and MODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	input_report_key(dev, BTN_A,	data[3] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	input_report_key(dev, BTN_B,	data[3] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	input_report_key(dev, BTN_X,	data[3] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	input_report_key(dev, BTN_Y,	data[3] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	input_report_key(dev, BTN_TL,	data[3] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	input_report_key(dev, BTN_TR,	data[3] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	input_report_key(dev, BTN_MODE,	data[3] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		/* left stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		input_report_abs(dev, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				 (__s16) le16_to_cpup((__le16 *)(data + 6)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		input_report_abs(dev, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		/* right stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		input_report_abs(dev, ABS_RX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				 (__s16) le16_to_cpup((__le16 *)(data + 10)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		input_report_abs(dev, ABS_RY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	/* triggers left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		input_report_key(dev, BTN_TL2, data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		input_report_key(dev, BTN_TR2, data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		input_report_abs(dev, ABS_Z, data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		input_report_abs(dev, ABS_RZ, data[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static void xpad_presence_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	struct usb_xpad *xpad = container_of(work, struct usb_xpad, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (xpad->pad_present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		error = xpad_init_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			/* complain only, not much else we can do here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 			dev_err(&xpad->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 				"unable to init device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			rcu_assign_pointer(xpad->x360w_dev, xpad->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		RCU_INIT_POINTER(xpad->x360w_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		 * Now that we are sure xpad360w_process_packet is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		 * using input device we can get rid of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		xpad_deinit_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794)  * xpad360w_process_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796)  * Completes a request by converting the data into events for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797)  * input subsystem. It is version for xbox 360 wireless controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799)  * Byte.Bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800)  * 00.1 - Status change: The controller or headset has connected/disconnected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801)  *                       Bits 01.7 and 01.6 are valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802)  * 01.7 - Controller present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803)  * 01.6 - Headset present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)  * 01.1 - Pad state (Bytes 4+) valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	bool present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	/* Presence change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	if (data[0] & 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		present = (data[1] & 0x80) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		if (xpad->pad_present != present) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			xpad->pad_present = present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			schedule_work(&xpad->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	/* Valid pad data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	if (data[1] != 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	dev = rcu_dereference(xpad->x360w_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		xpad360_process_packet(xpad, dev, cmd, &data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)  *	xpadone_process_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836)  *	Completes a request by converting the data into events for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837)  *	input subsystem. This version is for the Xbox One controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)  *	The report format was gleaned from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)  *	https://github.com/kylelemons/xbox/blob/master/xbox.go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	struct input_dev *dev = xpad->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	/* the xbox button has its own special report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	if (data[0] == 0X07) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		 * The Xbox One S controller requires these reports to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		 * acked otherwise it continues sending them forever and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		 * won't report further mode button events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		if (data[1] == 0x30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			xpadone_ack_mode_report(xpad, data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		input_report_key(dev, BTN_MODE, data[4] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	/* check invalid packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	else if (data[0] != 0X20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	/* menu/view buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	input_report_key(dev, BTN_START,  data[4] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	input_report_key(dev, BTN_SELECT, data[4] & 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	/* buttons A,B,X,Y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	input_report_key(dev, BTN_A,	data[4] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	input_report_key(dev, BTN_B,	data[4] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	input_report_key(dev, BTN_X,	data[4] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	input_report_key(dev, BTN_Y,	data[4] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	/* digital pad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		/* dpad as buttons (left, right, up, down) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		input_report_abs(dev, ABS_HAT0X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 				 !!(data[5] & 0x08) - !!(data[5] & 0x04));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		input_report_abs(dev, ABS_HAT0Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				 !!(data[5] & 0x02) - !!(data[5] & 0x01));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	/* TL/TR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	input_report_key(dev, BTN_TL,	data[5] & 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	input_report_key(dev, BTN_TR,	data[5] & 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	/* stick press left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	input_report_key(dev, BTN_THUMBL, data[5] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	input_report_key(dev, BTN_THUMBR, data[5] & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		/* left stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		input_report_abs(dev, ABS_X,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 				 (__s16) le16_to_cpup((__le16 *)(data + 10)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		input_report_abs(dev, ABS_Y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		/* right stick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		input_report_abs(dev, ABS_RX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 				 (__s16) le16_to_cpup((__le16 *)(data + 14)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		input_report_abs(dev, ABS_RY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 				 ~(__s16) le16_to_cpup((__le16 *)(data + 16)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	/* triggers left/right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		input_report_key(dev, BTN_TL2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 				 (__u16) le16_to_cpup((__le16 *)(data + 6)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		input_report_key(dev, BTN_TR2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 				 (__u16) le16_to_cpup((__le16 *)(data + 8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		input_report_abs(dev, ABS_Z,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 				 (__u16) le16_to_cpup((__le16 *)(data + 6)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		input_report_abs(dev, ABS_RZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 				 (__u16) le16_to_cpup((__le16 *)(data + 8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) static void xpad_irq_in(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	struct usb_xpad *xpad = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	struct device *dev = &xpad->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	int retval, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		/* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		dev_dbg(dev, "%s - urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		dev_dbg(dev, "%s - nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	switch (xpad->xtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	case XTYPE_XBOX360:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	case XTYPE_XBOX360W:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		xpad360w_process_packet(xpad, 0, xpad->idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	case XTYPE_XBOXONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		xpadone_process_packet(xpad, 0, xpad->idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		xpad_process_packet(xpad, 0, xpad->idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) /* Callers must hold xpad->odata_lock spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) static bool xpad_prepare_next_init_packet(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	const struct xboxone_init_packet *init_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if (xpad->xtype != XTYPE_XBOXONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	/* Perform initialization sequence for Xbox One pads that require it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		init_packet = &xboxone_init_packets[xpad->init_seq++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		if (init_packet->idVendor != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		    init_packet->idVendor != xpad->dev->id.vendor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		if (init_packet->idProduct != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		    init_packet->idProduct != xpad->dev->id.product)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		/* This packet applies to our device, so prepare to send it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		memcpy(xpad->odata, init_packet->data, init_packet->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 		xpad->irq_out->transfer_buffer_length = init_packet->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		/* Update packet with current sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		xpad->odata[2] = xpad->odata_serial++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) /* Callers must hold xpad->odata_lock spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static bool xpad_prepare_next_out_packet(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	struct xpad_output_packet *pkt, *packet = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	/* We may have init packets to send before we can send user commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	if (xpad_prepare_next_init_packet(xpad))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 			xpad->last_out_packet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		pkt = &xpad->out_packets[xpad->last_out_packet];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		if (pkt->pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			dev_dbg(&xpad->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				"%s - found pending output packet %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				__func__, xpad->last_out_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 			packet = pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		memcpy(xpad->odata, packet->data, packet->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		xpad->irq_out->transfer_buffer_length = packet->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		packet->pending = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* Callers must hold xpad->odata_lock spinlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static int xpad_try_sending_next_out_packet(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			dev_err(&xpad->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 				"%s - usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 				__func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			usb_unanchor_urb(xpad->irq_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		xpad->irq_out_active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static void xpad_irq_out(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	struct usb_xpad *xpad = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	struct device *dev = &xpad->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		xpad->irq_out_active = xpad_prepare_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		/* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		dev_dbg(dev, "%s - urb shutting down with status: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		xpad->irq_out_active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		dev_dbg(dev, "%s - nonzero urb status received: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			__func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	if (xpad->irq_out_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		usb_anchor_urb(urb, &xpad->irq_out_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		error = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 				"%s - usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				__func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 			usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			xpad->irq_out_active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			struct usb_endpoint_descriptor *ep_irq_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (xpad->xtype == XTYPE_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	init_usb_anchor(&xpad->irq_out_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 					 GFP_KERNEL, &xpad->odata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	if (!xpad->odata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	spin_lock_init(&xpad->odata_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	if (!xpad->irq_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		goto err_free_coherent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	usb_fill_int_urb(xpad->irq_out, xpad->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 			 xpad->odata, XPAD_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			 xpad_irq_out, xpad, ep_irq_out->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	xpad->irq_out->transfer_dma = xpad->odata_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) err_free_coherent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static void xpad_stop_output(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	if (xpad->xtype != XTYPE_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 						   5000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 			dev_warn(&xpad->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 				 "timed out waiting for output URB to complete, killing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 			usb_kill_anchored_urbs(&xpad->irq_out_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) static void xpad_deinit_output(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (xpad->xtype != XTYPE_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		usb_free_urb(xpad->irq_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 				xpad->odata, xpad->odata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static int xpad_inquiry_pad_presence(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	struct xpad_output_packet *packet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 			&xpad->out_packets[XPAD_OUT_CMD_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	packet->data[0] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	packet->data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	packet->data[2] = 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	packet->data[3] = 0xC0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	packet->data[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	packet->data[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	packet->data[8] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	packet->data[9] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	packet->data[10] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	packet->data[11] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	packet->len = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	/* Reset the sequence so we send out presence first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	xpad->last_out_packet = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	retval = xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static int xpad_start_xbox_one(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	 * Begin the init sequence by attempting to send a packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	 * We will cycle through the init packet sequence before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	 * sending any packets from the output ring.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	xpad->init_seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	retval = xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	struct xpad_output_packet *packet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			&xpad->out_packets[XPAD_OUT_CMD_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	static const u8 mode_report_ack[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		0x00, 0x00, 0x00, 0x00, 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	packet->len = sizeof(mode_report_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	memcpy(packet->data, mode_report_ack, packet->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	packet->data[2] = seq_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	/* Reset the sequence so we send out the ack now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	xpad->last_out_packet = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) #ifdef CONFIG_JOYSTICK_XPAD_FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	struct usb_xpad *xpad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	__u16 strong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	__u16 weak;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	if (effect->type != FF_RUMBLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	strong = effect->u.rumble.strong_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	weak = effect->u.rumble.weak_magnitude;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	switch (xpad->xtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	case XTYPE_XBOX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		packet->data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		packet->data[1] = 0x06;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		packet->data[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		packet->data[3] = strong / 256;	/* left actuator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		packet->data[5] = weak / 256;	/* right actuator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		packet->len = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	case XTYPE_XBOX360:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		packet->data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		packet->data[1] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		packet->data[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		packet->data[3] = strong / 256;  /* left actuator? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		packet->data[4] = weak / 256;	/* right actuator? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		packet->data[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		packet->data[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		packet->len = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	case XTYPE_XBOX360W:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		packet->data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		packet->data[1] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		packet->data[2] = 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		packet->data[3] = 0xC0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		packet->data[5] = strong / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		packet->data[6] = weak / 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		packet->data[8] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		packet->data[9] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		packet->data[10] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		packet->data[11] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		packet->len = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	case XTYPE_XBOXONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 		packet->data[0] = 0x09; /* activate rumble */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		packet->data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		packet->data[2] = xpad->odata_serial++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		packet->data[3] = 0x09;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		packet->data[5] = 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		packet->data[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		packet->data[8] = strong / 512;	/* left actuator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		packet->data[9] = weak / 512;	/* right actuator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		packet->data[10] = 0xFF; /* on period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		packet->data[11] = 0x00; /* off period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		packet->data[12] = 0xFF; /* repeat count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		packet->len = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		dev_dbg(&xpad->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 			"%s - rumble command sent to unsupported xpad type: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			__func__, xpad->xtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	retval = xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) static int xpad_init_ff(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	if (xpad->xtype == XTYPE_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) static int xpad_init_ff(struct usb_xpad *xpad) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) static DEFINE_IDA(xpad_pad_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) struct xpad_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	char name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	struct led_classdev led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	struct usb_xpad *xpad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)  * set the LEDs on Xbox360 / Wireless Controllers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)  * @param command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)  *  0: off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)  *  1: all blink, then previous setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)  *  2: 1/top-left blink, then on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)  *  3: 2/top-right blink, then on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)  *  4: 3/bottom-left blink, then on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)  *  5: 4/bottom-right blink, then on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)  *  6: 1/top-left on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)  *  7: 2/top-right on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)  *  8: 3/bottom-left on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)  *  9: 4/bottom-right on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)  * 10: rotate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)  * 11: blink, based on previous setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)  * 12: slow blink, based on previous setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)  * 13: rotate with two lights
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)  * 14: persistent slow all blink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)  * 15: blink once, then previous setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static void xpad_send_led_command(struct usb_xpad *xpad, int command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	struct xpad_output_packet *packet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 			&xpad->out_packets[XPAD_OUT_LED_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	command %= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	switch (xpad->xtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	case XTYPE_XBOX360:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		packet->data[0] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		packet->data[1] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		packet->data[2] = command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		packet->len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	case XTYPE_XBOX360W:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		packet->data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		packet->data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		packet->data[2] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		packet->data[3] = 0x40 + command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		packet->data[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		packet->data[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 		packet->data[8] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		packet->data[9] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		packet->data[10] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		packet->data[11] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		packet->len = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)  * Light up the segment corresponding to the pad number on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)  * Xbox 360 Controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) static void xpad_identify_controller(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) static void xpad_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 			 enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	struct xpad_led *xpad_led = container_of(led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 						 struct xpad_led, led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	xpad_send_led_command(xpad_led->xpad, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) static int xpad_led_probe(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	struct xpad_led *led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	struct led_classdev *led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX360W)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	if (!led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	xpad->pad_nr = ida_simple_get(&xpad_pad_seq, 0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	if (xpad->pad_nr < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		error = xpad->pad_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	snprintf(led->name, sizeof(led->name), "xpad%d", xpad->pad_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	led->xpad = xpad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	led_cdev = &led->led_cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	led_cdev->name = led->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	led_cdev->brightness_set = xpad_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	led_cdev->flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	error = led_classdev_register(&xpad->udev->dev, led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		goto err_free_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	xpad_identify_controller(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) err_free_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	ida_simple_remove(&xpad_pad_seq, xpad->pad_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	kfree(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	xpad->led = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) static void xpad_led_disconnect(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	struct xpad_led *xpad_led = xpad->led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	if (xpad_led) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		led_classdev_unregister(&xpad_led->led_cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		ida_simple_remove(&xpad_pad_seq, xpad->pad_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		kfree(xpad_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static int xpad_led_probe(struct usb_xpad *xpad) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) static void xpad_led_disconnect(struct usb_xpad *xpad) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) static int xpad_start_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	if (xpad->xtype == XTYPE_XBOXONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		error = xpad_start_xbox_one(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 			usb_kill_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) static void xpad_stop_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	usb_kill_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static void xpad360w_poweroff_controller(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	struct xpad_output_packet *packet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			&xpad->out_packets[XPAD_OUT_CMD_IDX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	spin_lock_irqsave(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	packet->data[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	packet->data[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	packet->data[2] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	packet->data[3] = 0xC0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	packet->data[4] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	packet->data[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	packet->data[6] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	packet->data[7] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	packet->data[8] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	packet->data[9] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	packet->data[10] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	packet->data[11] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	packet->len = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	packet->pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	/* Reset the sequence so we send out poweroff now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	xpad->last_out_packet = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	xpad_try_sending_next_out_packet(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	spin_unlock_irqrestore(&xpad->odata_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) static int xpad360w_start_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	 * Send presence packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	 * This will force the controller to resend connection packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	 * This is useful in the case we activate the module after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	 * adapter has been plugged in, as it won't automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	 * send us info about the controllers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	error = xpad_inquiry_pad_presence(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		usb_kill_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) static void xpad360w_stop_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	usb_kill_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	/* Make sure we are done with presence work if it was scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	flush_work(&xpad->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) static int xpad_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	struct usb_xpad *xpad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	return xpad_start_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) static void xpad_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	struct usb_xpad *xpad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	xpad_stop_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	struct usb_xpad *xpad = input_get_drvdata(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	switch (abs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	case ABS_X:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	case ABS_Y:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	case ABS_RX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	case ABS_RY:	/* the two sticks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	case ABS_Z:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	case ABS_RZ:	/* the triggers (if mapped to axes) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		if (xpad->xtype == XTYPE_XBOXONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 			input_set_abs_params(input_dev, abs, 0, 1023, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 			input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	case ABS_HAT0X:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	case ABS_HAT0Y:	/* the d-pad (only if dpad is mapped to axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		input_set_abs_params(input_dev, abs, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) static void xpad_deinit_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	if (xpad->input_created) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		xpad->input_created = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		xpad_led_disconnect(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		input_unregister_device(xpad->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) static int xpad_init_input(struct usb_xpad *xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	xpad->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	input_dev->name = xpad->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	input_dev->phys = xpad->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	usb_to_input_id(xpad->udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	if (xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		/* x360w controllers and the receiver have different ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 		input_dev->id.product = 0x02a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	input_dev->dev.parent = &xpad->intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	input_set_drvdata(input_dev, xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	if (xpad->xtype != XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		input_dev->open = xpad_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		input_dev->close = xpad_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		/* set up axes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		for (i = 0; xpad_abs[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 			xpad_set_up_abs(input_dev, xpad_abs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	/* set up standard buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	for (i = 0; xpad_common_btn[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		input_set_capability(input_dev, EV_KEY, xpad_common_btn[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	/* set up model-specific ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	    xpad->xtype == XTYPE_XBOXONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		for (i = 0; xpad360_btn[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 			input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		for (i = 0; xpad_btn[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 			input_set_capability(input_dev, EV_KEY, xpad_btn[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		for (i = 0; xpad_btn_pad[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			input_set_capability(input_dev, EV_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 					     xpad_btn_pad[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	 * This should be a simple else block. However historically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	 * xbox360w has mapped DPAD to buttons while xbox360 did not. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	 * made no sense, but now we can not just switch back and have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	 * support both behaviors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	if (!(xpad->mapping & MAP_DPAD_TO_BUTTONS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	    xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 		for (i = 0; xpad_abs_pad[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		for (i = 0; xpad_btn_triggers[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 			input_set_capability(input_dev, EV_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 					     xpad_btn_triggers[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 		for (i = 0; xpad_abs_triggers[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 			xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	error = xpad_init_ff(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 		goto err_free_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	error = xpad_led_probe(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		goto err_destroy_ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	error = input_register_device(xpad->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		goto err_disconnect_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	xpad->input_created = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) err_disconnect_led:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	xpad_led_disconnect(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) err_destroy_ff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	input_ff_destroy(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) err_free_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	struct usb_xpad *xpad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	int i, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	if (intf->cur_altsetting->desc.bNumEndpoints != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	for (i = 0; xpad_device[i].idVendor; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		    (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	if (!xpad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 					 GFP_KERNEL, &xpad->idata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	if (!xpad->idata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	if (!xpad->irq_in) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 		error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 		goto err_free_idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	xpad->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	xpad->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	xpad->mapping = xpad_device[i].mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	xpad->xtype = xpad_device[i].xtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	xpad->name = xpad_device[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	INIT_WORK(&xpad->work, xpad_presence_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	if (xpad->xtype == XTYPE_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 		if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 			if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 				xpad->xtype = XTYPE_XBOX360W;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 			else if (intf->cur_altsetting->desc.bInterfaceProtocol == 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 				xpad->xtype = XTYPE_XBOXONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 				xpad->xtype = XTYPE_XBOX360;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 			xpad->xtype = XTYPE_XBOX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 		if (dpad_to_buttons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 			xpad->mapping |= MAP_DPAD_TO_BUTTONS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 		if (triggers_to_buttons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 			xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		if (sticks_to_null)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 			xpad->mapping |= MAP_STICKS_TO_NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	if (xpad->xtype == XTYPE_XBOXONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	    intf->cur_altsetting->desc.bInterfaceNumber != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		 * The Xbox One controller lists three interfaces all with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 		 * same interface class, subclass and protocol. Differentiate by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		 * interface number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		goto err_free_in_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	ep_irq_in = ep_irq_out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		struct usb_endpoint_descriptor *ep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 				&intf->cur_altsetting->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		if (usb_endpoint_xfer_int(ep)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 			if (usb_endpoint_dir_in(ep))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 				ep_irq_in = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 				ep_irq_out = ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	if (!ep_irq_in || !ep_irq_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 		error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 		goto err_free_in_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	error = xpad_init_output(intf, xpad, ep_irq_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		goto err_free_in_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	usb_fill_int_urb(xpad->irq_in, udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 			 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 			 xpad, ep_irq_in->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	xpad->irq_in->transfer_dma = xpad->idata_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	usb_set_intfdata(intf, xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	if (xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		 * Submit the int URB immediately rather than waiting for open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		 * because we get status messages from the device whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		 * or not any controllers are attached.  In fact, it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		 * exactly the message that a controller has arrived that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		 * we're waiting for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 		error = xpad360w_start_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 			goto err_deinit_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		 * Wireless controllers require RESET_RESUME to work properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 		 * after suspend. Ideally this quirk should be in usb core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		 * quirk list, but we have too many vendors producing these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 		 * controllers and we'd need to maintain 2 identical lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		 * here in this driver and in usb core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		udev->quirks |= USB_QUIRK_RESET_RESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 		error = xpad_init_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			goto err_deinit_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) err_deinit_output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	xpad_deinit_output(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) err_free_in_urb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	usb_free_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) err_free_idata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	kfree(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) static void xpad_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	struct usb_xpad *xpad = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	if (xpad->xtype == XTYPE_XBOX360W)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		xpad360w_stop_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	xpad_deinit_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	 * Now that both input device and LED device are gone we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	 * stop output URB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	xpad_stop_output(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	xpad_deinit_output(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	usb_free_urb(xpad->irq_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 			xpad->idata, xpad->idata_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	kfree(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) static int xpad_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	struct usb_xpad *xpad = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	struct input_dev *input = xpad->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	if (xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 		 * Wireless controllers always listen to input so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		 * they are notified when controller shows up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 		 * or goes away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		xpad360w_stop_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 		 * The wireless adapter is going off now, so the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		 * gamepads are going to become disconnected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		 * Unless explicitly disabled, power them down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 		 * so they don't just sit there flashing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		if (auto_poweroff && xpad->pad_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 			xpad360w_poweroff_controller(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		mutex_lock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		if (input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 			xpad_stop_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		mutex_unlock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	xpad_stop_output(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) static int xpad_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	struct usb_xpad *xpad = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	struct input_dev *input = xpad->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	if (xpad->xtype == XTYPE_XBOX360W) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		retval = xpad360w_start_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		mutex_lock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		if (input->users) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 			retval = xpad_start_input(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 		} else if (xpad->xtype == XTYPE_XBOXONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 			 * Even if there are no users, we'll send Xbox One pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 			 * the startup sequence so they don't sit there and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 			 * blink until somebody opens the input device again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 			retval = xpad_start_xbox_one(xpad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		mutex_unlock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) static struct usb_driver xpad_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	.name		= "xpad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	.probe		= xpad_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	.disconnect	= xpad_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	.suspend	= xpad_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	.resume		= xpad_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	.reset_resume	= xpad_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	.id_table	= xpad_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) module_usb_driver(xpad_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) MODULE_AUTHOR("Marko Friedemann <mfr@bmx-chemnitz.de>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) MODULE_DESCRIPTION("X-Box pad driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) MODULE_LICENSE("GPL");