xpad.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. /*
  2. * X-Box gamepad driver
  3. *
  4. * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
  5. * 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>,
  6. * Steven Toth <steve@toth.demon.co.uk>,
  7. * Franz Lehner <franz@caos.at>,
  8. * Ivan Hawkes <blackhawk@ivanhawkes.com>
  9. * 2005 Dominic Cerquetti <binary1230@yahoo.com>
  10. * 2006 Adam Buchbinder <adam.buchbinder@gmail.com>
  11. * 2007 Jan Kratochvil <honza@jikos.cz>
  12. * 2010 Christoph Fritz <chf.fritz@googlemail.com>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. *
  29. * This driver is based on:
  30. * - information from http://euc.jp/periphs/xbox-controller.ja.html
  31. * - the iForce driver drivers/char/joystick/iforce.c
  32. * - the skeleton-driver drivers/usb/usb-skeleton.c
  33. * - Xbox 360 information http://www.free60.org/wiki/Gamepad
  34. *
  35. * Thanks to:
  36. * - ITO Takayuki for providing essential xpad information on his website
  37. * - Vojtech Pavlik - iforce driver / input subsystem
  38. * - Greg Kroah-Hartman - usb-skeleton driver
  39. * - XBOX Linux project - extra USB id's
  40. *
  41. * TODO:
  42. * - fine tune axes (especially trigger axes)
  43. * - fix "analog" buttons (reported as digital now)
  44. * - get rumble working
  45. * - need USB IDs for other dance pads
  46. *
  47. * History:
  48. *
  49. * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller"
  50. *
  51. * 2002-07-02 - 0.0.2 : basic working version
  52. * - all axes and 9 of the 10 buttons work (german InterAct device)
  53. * - the black button does not work
  54. *
  55. * 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik
  56. * - indentation fixes
  57. * - usb + input init sequence fixes
  58. *
  59. * 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3
  60. * - verified the lack of HID and report descriptors
  61. * - verified that ALL buttons WORK
  62. * - fixed d-pad to axes mapping
  63. *
  64. * 2002-07-17 - 0.0.5 : simplified d-pad handling
  65. *
  66. * 2004-10-02 - 0.0.6 : DDR pad support
  67. * - borrowed from the XBOX linux kernel
  68. * - USB id's for commonly used dance pads are present
  69. * - dance pads will map D-PAD to buttons, not axes
  70. * - pass the module paramater 'dpad_to_buttons' to force
  71. * the D-PAD to map to buttons if your pad is not detected
  72. *
  73. * Later changes can be tracked in SCM.
  74. */
  75. #include <linux/kernel.h>
  76. #include <linux/init.h>
  77. #include <linux/slab.h>
  78. #include <linux/stat.h>
  79. #include <linux/module.h>
  80. #include <linux/usb/input.h>
  81. #define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>"
  82. #define DRIVER_DESC "X-Box pad driver"
  83. #define XPAD_PKT_LEN 32
  84. /* xbox d-pads should map to buttons, as is required for DDR pads
  85. but we map them to axes when possible to simplify things */
  86. #define MAP_DPAD_TO_BUTTONS (1 << 0)
  87. #define MAP_TRIGGERS_TO_BUTTONS (1 << 1)
  88. #define MAP_STICKS_TO_NULL (1 << 2)
  89. #define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \
  90. MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
  91. #define XTYPE_XBOX 0
  92. #define XTYPE_XBOX360 1
  93. #define XTYPE_XBOX360W 2
  94. #define XTYPE_UNKNOWN 3
  95. static bool dpad_to_buttons;
  96. module_param(dpad_to_buttons, bool, S_IRUGO);
  97. MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads");
  98. static bool triggers_to_buttons;
  99. module_param(triggers_to_buttons, bool, S_IRUGO);
  100. MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads");
  101. static bool sticks_to_null;
  102. module_param(sticks_to_null, bool, S_IRUGO);
  103. MODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads");
  104. static const struct xpad_device {
  105. u16 idVendor;
  106. u16 idProduct;
  107. char *name;
  108. u8 mapping;
  109. u8 xtype;
  110. } xpad_device[] = {
  111. { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
  112. { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
  113. { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
  114. { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
  115. { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
  116. { 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
  117. { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
  118. { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
  119. { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
  120. { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
  121. { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
  122. { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
  123. { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
  124. { 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX },
  125. { 0x0738, 0x4522, "Mad Catz LumiCON", 0, XTYPE_XBOX },
  126. { 0x0738, 0x4526, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
  127. { 0x0738, 0x4536, "Mad Catz MicroCON", 0, XTYPE_XBOX },
  128. { 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
  129. { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
  130. { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
  131. { 0x0738, 0x4728, "Mad Catz Street Fighter IV FightPad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
  132. { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
  133. { 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
  134. { 0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad", XTYPE_XBOX360 },
  135. { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
  136. { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", DANCEPAD_MAP_CONFIG, XTYPE_XBOX },
  137. { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
  138. { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
  139. { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
  140. { 0x0d2f, 0x0002, "Andamiro Pump It Up pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
  141. { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
  142. { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
  143. { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
  144. { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
  145. { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
  146. { 0x0e6f, 0x0105, "HSM3 Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
  147. { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
  148. { 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
  149. { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
  150. { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
  151. { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
  152. { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
  153. { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
  154. { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
  155. { 0x12ab, 0x0004, "Honey Bee Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
  156. { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
  157. { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
  158. { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
  159. { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
  160. { 0x1689, 0xfd00, "Razer Onza Tournament Edition", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
  161. { 0x1689, 0xfd01, "Razer Onza Classic Edition", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
  162. { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 },
  163. { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
  164. { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
  165. { 0x1bad, 0xf028, "Street Fighter IV FightPad", 0, XTYPE_XBOX360 },
  166. { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
  167. { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
  168. { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
  169. { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
  170. { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
  171. };
  172. /* buttons shared with xbox and xbox360 */
  173. static const signed short xpad_common_btn[] = {
  174. BTN_A, BTN_B, BTN_X, BTN_Y, /* "analog" buttons */
  175. BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */
  176. -1 /* terminating entry */
  177. };
  178. /* original xbox controllers only */
  179. static const signed short xpad_btn[] = {
  180. BTN_C, BTN_Z, /* "analog" buttons */
  181. -1 /* terminating entry */
  182. };
  183. /* used when dpad is mapped to buttons */
  184. static const signed short xpad_btn_pad[] = {
  185. BTN_TRIGGER_HAPPY1, BTN_TRIGGER_HAPPY2, /* d-pad left, right */
  186. BTN_TRIGGER_HAPPY3, BTN_TRIGGER_HAPPY4, /* d-pad up, down */
  187. -1 /* terminating entry */
  188. };
  189. /* used when triggers are mapped to buttons */
  190. static const signed short xpad_btn_triggers[] = {
  191. BTN_TL2, BTN_TR2, /* triggers left/right */
  192. -1
  193. };
  194. static const signed short xpad360_btn[] = { /* buttons for x360 controller */
  195. BTN_TL, BTN_TR, /* Button LB/RB */
  196. BTN_MODE, /* The big X button */
  197. -1
  198. };
  199. static const signed short xpad_abs[] = {
  200. ABS_X, ABS_Y, /* left stick */
  201. ABS_RX, ABS_RY, /* right stick */
  202. -1 /* terminating entry */
  203. };
  204. /* used when dpad is mapped to axes */
  205. static const signed short xpad_abs_pad[] = {
  206. ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
  207. -1 /* terminating entry */
  208. };
  209. /* used when triggers are mapped to axes */
  210. static const signed short xpad_abs_triggers[] = {
  211. ABS_Z, ABS_RZ, /* triggers left/right */
  212. -1
  213. };
  214. /* Xbox 360 has a vendor-specific class, so we cannot match it with only
  215. * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
  216. * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
  217. * wireless controllers have protocol 129. */
  218. #define XPAD_XBOX360_VENDOR_PROTOCOL(vend,pr) \
  219. .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
  220. .idVendor = (vend), \
  221. .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
  222. .bInterfaceSubClass = 93, \
  223. .bInterfaceProtocol = (pr)
  224. #define XPAD_XBOX360_VENDOR(vend) \
  225. { XPAD_XBOX360_VENDOR_PROTOCOL(vend,1) }, \
  226. { XPAD_XBOX360_VENDOR_PROTOCOL(vend,129) }
  227. static struct usb_device_id xpad_table[] = {
  228. { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
  229. XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
  230. XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
  231. XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
  232. { USB_DEVICE(0x0738, 0x4540) }, /* Mad Catz Beat Pad */
  233. XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
  234. XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */
  235. XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
  236. XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */
  237. XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */
  238. XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */
  239. XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */
  240. XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */
  241. { }
  242. };
  243. MODULE_DEVICE_TABLE(usb, xpad_table);
  244. struct usb_xpad {
  245. struct input_dev *dev; /* input device interface */
  246. struct usb_device *udev; /* usb device */
  247. struct usb_interface *intf; /* usb interface */
  248. int pad_present;
  249. struct urb *irq_in; /* urb for interrupt in report */
  250. unsigned char *idata; /* input data */
  251. dma_addr_t idata_dma;
  252. struct urb *bulk_out;
  253. unsigned char *bdata;
  254. #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
  255. struct urb *irq_out; /* urb for interrupt out report */
  256. unsigned char *odata; /* output data */
  257. dma_addr_t odata_dma;
  258. struct mutex odata_mutex;
  259. #endif
  260. #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
  261. struct xpad_led *led;
  262. #endif
  263. char phys[64]; /* physical device path */
  264. int mapping; /* map d-pad to buttons or to axes */
  265. int xtype; /* type of xbox device */
  266. };
  267. /*
  268. * xpad_process_packet
  269. *
  270. * Completes a request by converting the data into events for the
  271. * input subsystem.
  272. *
  273. * The used report descriptor was taken from ITO Takayukis website:
  274. * http://euc.jp/periphs/xbox-controller.ja.html
  275. */
  276. static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
  277. {
  278. struct input_dev *dev = xpad->dev;
  279. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  280. /* left stick */
  281. input_report_abs(dev, ABS_X,
  282. (__s16) le16_to_cpup((__le16 *)(data + 12)));
  283. input_report_abs(dev, ABS_Y,
  284. ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
  285. /* right stick */
  286. input_report_abs(dev, ABS_RX,
  287. (__s16) le16_to_cpup((__le16 *)(data + 16)));
  288. input_report_abs(dev, ABS_RY,
  289. ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
  290. }
  291. /* triggers left/right */
  292. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  293. input_report_key(dev, BTN_TL2, data[10]);
  294. input_report_key(dev, BTN_TR2, data[11]);
  295. } else {
  296. input_report_abs(dev, ABS_Z, data[10]);
  297. input_report_abs(dev, ABS_RZ, data[11]);
  298. }
  299. /* digital pad */
  300. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  301. /* dpad as buttons (left, right, up, down) */
  302. input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
  303. input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
  304. input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
  305. input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
  306. } else {
  307. input_report_abs(dev, ABS_HAT0X,
  308. !!(data[2] & 0x08) - !!(data[2] & 0x04));
  309. input_report_abs(dev, ABS_HAT0Y,
  310. !!(data[2] & 0x02) - !!(data[2] & 0x01));
  311. }
  312. /* start/back buttons and stick press left/right */
  313. input_report_key(dev, BTN_START, data[2] & 0x10);
  314. input_report_key(dev, BTN_SELECT, data[2] & 0x20);
  315. input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
  316. input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
  317. /* "analog" buttons A, B, X, Y */
  318. input_report_key(dev, BTN_A, data[4]);
  319. input_report_key(dev, BTN_B, data[5]);
  320. input_report_key(dev, BTN_X, data[6]);
  321. input_report_key(dev, BTN_Y, data[7]);
  322. /* "analog" buttons black, white */
  323. input_report_key(dev, BTN_C, data[8]);
  324. input_report_key(dev, BTN_Z, data[9]);
  325. input_sync(dev);
  326. }
  327. /*
  328. * xpad360_process_packet
  329. *
  330. * Completes a request by converting the data into events for the
  331. * input subsystem. It is version for xbox 360 controller
  332. *
  333. * The used report descriptor was taken from:
  334. * http://www.free60.org/wiki/Gamepad
  335. */
  336. static void xpad360_process_packet(struct usb_xpad *xpad,
  337. u16 cmd, unsigned char *data)
  338. {
  339. struct input_dev *dev = xpad->dev;
  340. /* digital pad */
  341. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  342. /* dpad as buttons (left, right, up, down) */
  343. input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
  344. input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
  345. input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
  346. input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
  347. } else {
  348. input_report_abs(dev, ABS_HAT0X,
  349. !!(data[2] & 0x08) - !!(data[2] & 0x04));
  350. input_report_abs(dev, ABS_HAT0Y,
  351. !!(data[2] & 0x02) - !!(data[2] & 0x01));
  352. }
  353. /* start/back buttons */
  354. input_report_key(dev, BTN_START, data[2] & 0x10);
  355. input_report_key(dev, BTN_SELECT, data[2] & 0x20);
  356. /* stick press left/right */
  357. input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
  358. input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
  359. /* buttons A,B,X,Y,TL,TR and MODE */
  360. input_report_key(dev, BTN_A, data[3] & 0x10);
  361. input_report_key(dev, BTN_B, data[3] & 0x20);
  362. input_report_key(dev, BTN_X, data[3] & 0x40);
  363. input_report_key(dev, BTN_Y, data[3] & 0x80);
  364. input_report_key(dev, BTN_TL, data[3] & 0x01);
  365. input_report_key(dev, BTN_TR, data[3] & 0x02);
  366. input_report_key(dev, BTN_MODE, data[3] & 0x04);
  367. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  368. /* left stick */
  369. input_report_abs(dev, ABS_X,
  370. (__s16) le16_to_cpup((__le16 *)(data + 6)));
  371. input_report_abs(dev, ABS_Y,
  372. ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
  373. /* right stick */
  374. input_report_abs(dev, ABS_RX,
  375. (__s16) le16_to_cpup((__le16 *)(data + 10)));
  376. input_report_abs(dev, ABS_RY,
  377. ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
  378. }
  379. /* triggers left/right */
  380. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  381. input_report_key(dev, BTN_TL2, data[4]);
  382. input_report_key(dev, BTN_TR2, data[5]);
  383. } else {
  384. input_report_abs(dev, ABS_Z, data[4]);
  385. input_report_abs(dev, ABS_RZ, data[5]);
  386. }
  387. input_sync(dev);
  388. }
  389. /*
  390. * xpad360w_process_packet
  391. *
  392. * Completes a request by converting the data into events for the
  393. * input subsystem. It is version for xbox 360 wireless controller.
  394. *
  395. * Byte.Bit
  396. * 00.1 - Status change: The controller or headset has connected/disconnected
  397. * Bits 01.7 and 01.6 are valid
  398. * 01.7 - Controller present
  399. * 01.6 - Headset present
  400. * 01.1 - Pad state (Bytes 4+) valid
  401. *
  402. */
  403. static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
  404. {
  405. /* Presence change */
  406. if (data[0] & 0x08) {
  407. if (data[1] & 0x80) {
  408. xpad->pad_present = 1;
  409. usb_submit_urb(xpad->bulk_out, GFP_ATOMIC);
  410. } else
  411. xpad->pad_present = 0;
  412. }
  413. /* Valid pad data */
  414. if (!(data[1] & 0x1))
  415. return;
  416. xpad360_process_packet(xpad, cmd, &data[4]);
  417. }
  418. static void xpad_irq_in(struct urb *urb)
  419. {
  420. struct usb_xpad *xpad = urb->context;
  421. struct device *dev = &xpad->intf->dev;
  422. int retval, status;
  423. status = urb->status;
  424. switch (status) {
  425. case 0:
  426. /* success */
  427. break;
  428. case -ECONNRESET:
  429. case -ENOENT:
  430. case -ESHUTDOWN:
  431. /* this urb is terminated, clean up */
  432. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  433. __func__, status);
  434. return;
  435. default:
  436. dev_dbg(dev, "%s - nonzero urb status received: %d\n",
  437. __func__, status);
  438. goto exit;
  439. }
  440. switch (xpad->xtype) {
  441. case XTYPE_XBOX360:
  442. xpad360_process_packet(xpad, 0, xpad->idata);
  443. break;
  444. case XTYPE_XBOX360W:
  445. xpad360w_process_packet(xpad, 0, xpad->idata);
  446. break;
  447. default:
  448. xpad_process_packet(xpad, 0, xpad->idata);
  449. }
  450. exit:
  451. retval = usb_submit_urb(urb, GFP_ATOMIC);
  452. if (retval)
  453. dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
  454. __func__, retval);
  455. }
  456. static void xpad_bulk_out(struct urb *urb)
  457. {
  458. struct usb_xpad *xpad = urb->context;
  459. struct device *dev = &xpad->intf->dev;
  460. switch (urb->status) {
  461. case 0:
  462. /* success */
  463. break;
  464. case -ECONNRESET:
  465. case -ENOENT:
  466. case -ESHUTDOWN:
  467. /* this urb is terminated, clean up */
  468. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  469. __func__, urb->status);
  470. break;
  471. default:
  472. dev_dbg(dev, "%s - nonzero urb status received: %d\n",
  473. __func__, urb->status);
  474. }
  475. }
  476. #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
  477. static void xpad_irq_out(struct urb *urb)
  478. {
  479. struct usb_xpad *xpad = urb->context;
  480. struct device *dev = &xpad->intf->dev;
  481. int retval, status;
  482. status = urb->status;
  483. switch (status) {
  484. case 0:
  485. /* success */
  486. return;
  487. case -ECONNRESET:
  488. case -ENOENT:
  489. case -ESHUTDOWN:
  490. /* this urb is terminated, clean up */
  491. dev_dbg(dev, "%s - urb shutting down with status: %d\n",
  492. __func__, status);
  493. return;
  494. default:
  495. dev_dbg(dev, "%s - nonzero urb status received: %d\n",
  496. __func__, status);
  497. goto exit;
  498. }
  499. exit:
  500. retval = usb_submit_urb(urb, GFP_ATOMIC);
  501. if (retval)
  502. dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
  503. __func__, retval);
  504. }
  505. static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
  506. {
  507. struct usb_endpoint_descriptor *ep_irq_out;
  508. int error;
  509. if (xpad->xtype == XTYPE_UNKNOWN)
  510. return 0;
  511. xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
  512. GFP_KERNEL, &xpad->odata_dma);
  513. if (!xpad->odata) {
  514. error = -ENOMEM;
  515. goto fail1;
  516. }
  517. mutex_init(&xpad->odata_mutex);
  518. xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
  519. if (!xpad->irq_out) {
  520. error = -ENOMEM;
  521. goto fail2;
  522. }
  523. ep_irq_out = &intf->cur_altsetting->endpoint[1].desc;
  524. usb_fill_int_urb(xpad->irq_out, xpad->udev,
  525. usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
  526. xpad->odata, XPAD_PKT_LEN,
  527. xpad_irq_out, xpad, ep_irq_out->bInterval);
  528. xpad->irq_out->transfer_dma = xpad->odata_dma;
  529. xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  530. return 0;
  531. fail2: usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
  532. fail1: return error;
  533. }
  534. static void xpad_stop_output(struct usb_xpad *xpad)
  535. {
  536. if (xpad->xtype != XTYPE_UNKNOWN)
  537. usb_kill_urb(xpad->irq_out);
  538. }
  539. static void xpad_deinit_output(struct usb_xpad *xpad)
  540. {
  541. if (xpad->xtype != XTYPE_UNKNOWN) {
  542. usb_free_urb(xpad->irq_out);
  543. usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
  544. xpad->odata, xpad->odata_dma);
  545. }
  546. }
  547. #else
  548. static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; }
  549. static void xpad_deinit_output(struct usb_xpad *xpad) {}
  550. static void xpad_stop_output(struct usb_xpad *xpad) {}
  551. #endif
  552. #ifdef CONFIG_JOYSTICK_XPAD_FF
  553. static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
  554. {
  555. struct usb_xpad *xpad = input_get_drvdata(dev);
  556. if (effect->type == FF_RUMBLE) {
  557. __u16 strong = effect->u.rumble.strong_magnitude;
  558. __u16 weak = effect->u.rumble.weak_magnitude;
  559. switch (xpad->xtype) {
  560. case XTYPE_XBOX:
  561. xpad->odata[0] = 0x00;
  562. xpad->odata[1] = 0x06;
  563. xpad->odata[2] = 0x00;
  564. xpad->odata[3] = strong / 256; /* left actuator */
  565. xpad->odata[4] = 0x00;
  566. xpad->odata[5] = weak / 256; /* right actuator */
  567. xpad->irq_out->transfer_buffer_length = 6;
  568. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  569. case XTYPE_XBOX360:
  570. xpad->odata[0] = 0x00;
  571. xpad->odata[1] = 0x08;
  572. xpad->odata[2] = 0x00;
  573. xpad->odata[3] = strong / 256; /* left actuator? */
  574. xpad->odata[4] = weak / 256; /* right actuator? */
  575. xpad->odata[5] = 0x00;
  576. xpad->odata[6] = 0x00;
  577. xpad->odata[7] = 0x00;
  578. xpad->irq_out->transfer_buffer_length = 8;
  579. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  580. case XTYPE_XBOX360W:
  581. xpad->odata[0] = 0x00;
  582. xpad->odata[1] = 0x01;
  583. xpad->odata[2] = 0x0F;
  584. xpad->odata[3] = 0xC0;
  585. xpad->odata[4] = 0x00;
  586. xpad->odata[5] = strong / 256;
  587. xpad->odata[6] = weak / 256;
  588. xpad->odata[7] = 0x00;
  589. xpad->odata[8] = 0x00;
  590. xpad->odata[9] = 0x00;
  591. xpad->odata[10] = 0x00;
  592. xpad->odata[11] = 0x00;
  593. xpad->irq_out->transfer_buffer_length = 12;
  594. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  595. default:
  596. dev_dbg(&xpad->dev->dev,
  597. "%s - rumble command sent to unsupported xpad type: %d\n",
  598. __func__, xpad->xtype);
  599. return -1;
  600. }
  601. }
  602. return 0;
  603. }
  604. static int xpad_init_ff(struct usb_xpad *xpad)
  605. {
  606. if (xpad->xtype == XTYPE_UNKNOWN)
  607. return 0;
  608. input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
  609. return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
  610. }
  611. #else
  612. static int xpad_init_ff(struct usb_xpad *xpad) { return 0; }
  613. #endif
  614. #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
  615. #include <linux/leds.h>
  616. struct xpad_led {
  617. char name[16];
  618. struct led_classdev led_cdev;
  619. struct usb_xpad *xpad;
  620. };
  621. static void xpad_send_led_command(struct usb_xpad *xpad, int command)
  622. {
  623. if (command >= 0 && command < 14) {
  624. mutex_lock(&xpad->odata_mutex);
  625. xpad->odata[0] = 0x01;
  626. xpad->odata[1] = 0x03;
  627. xpad->odata[2] = command;
  628. xpad->irq_out->transfer_buffer_length = 3;
  629. usb_submit_urb(xpad->irq_out, GFP_KERNEL);
  630. mutex_unlock(&xpad->odata_mutex);
  631. }
  632. }
  633. static void xpad_led_set(struct led_classdev *led_cdev,
  634. enum led_brightness value)
  635. {
  636. struct xpad_led *xpad_led = container_of(led_cdev,
  637. struct xpad_led, led_cdev);
  638. xpad_send_led_command(xpad_led->xpad, value);
  639. }
  640. static int xpad_led_probe(struct usb_xpad *xpad)
  641. {
  642. static atomic_t led_seq = ATOMIC_INIT(0);
  643. long led_no;
  644. struct xpad_led *led;
  645. struct led_classdev *led_cdev;
  646. int error;
  647. if (xpad->xtype != XTYPE_XBOX360)
  648. return 0;
  649. xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL);
  650. if (!led)
  651. return -ENOMEM;
  652. led_no = (long)atomic_inc_return(&led_seq) - 1;
  653. snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
  654. led->xpad = xpad;
  655. led_cdev = &led->led_cdev;
  656. led_cdev->name = led->name;
  657. led_cdev->brightness_set = xpad_led_set;
  658. error = led_classdev_register(&xpad->udev->dev, led_cdev);
  659. if (error) {
  660. kfree(led);
  661. xpad->led = NULL;
  662. return error;
  663. }
  664. /*
  665. * Light up the segment corresponding to controller number
  666. */
  667. xpad_send_led_command(xpad, (led_no % 4) + 2);
  668. return 0;
  669. }
  670. static void xpad_led_disconnect(struct usb_xpad *xpad)
  671. {
  672. struct xpad_led *xpad_led = xpad->led;
  673. if (xpad_led) {
  674. led_classdev_unregister(&xpad_led->led_cdev);
  675. kfree(xpad_led);
  676. }
  677. }
  678. #else
  679. static int xpad_led_probe(struct usb_xpad *xpad) { return 0; }
  680. static void xpad_led_disconnect(struct usb_xpad *xpad) { }
  681. #endif
  682. static int xpad_open(struct input_dev *dev)
  683. {
  684. struct usb_xpad *xpad = input_get_drvdata(dev);
  685. /* URB was submitted in probe */
  686. if (xpad->xtype == XTYPE_XBOX360W)
  687. return 0;
  688. xpad->irq_in->dev = xpad->udev;
  689. if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
  690. return -EIO;
  691. return 0;
  692. }
  693. static void xpad_close(struct input_dev *dev)
  694. {
  695. struct usb_xpad *xpad = input_get_drvdata(dev);
  696. if (xpad->xtype != XTYPE_XBOX360W)
  697. usb_kill_urb(xpad->irq_in);
  698. xpad_stop_output(xpad);
  699. }
  700. static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
  701. {
  702. set_bit(abs, input_dev->absbit);
  703. switch (abs) {
  704. case ABS_X:
  705. case ABS_Y:
  706. case ABS_RX:
  707. case ABS_RY: /* the two sticks */
  708. input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128);
  709. break;
  710. case ABS_Z:
  711. case ABS_RZ: /* the triggers (if mapped to axes) */
  712. input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
  713. break;
  714. case ABS_HAT0X:
  715. case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */
  716. input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
  717. break;
  718. }
  719. }
  720. static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
  721. {
  722. struct usb_device *udev = interface_to_usbdev(intf);
  723. struct usb_xpad *xpad;
  724. struct input_dev *input_dev;
  725. struct usb_endpoint_descriptor *ep_irq_in;
  726. int i, error;
  727. for (i = 0; xpad_device[i].idVendor; i++) {
  728. if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
  729. (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
  730. break;
  731. }
  732. xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
  733. input_dev = input_allocate_device();
  734. if (!xpad || !input_dev) {
  735. error = -ENOMEM;
  736. goto fail1;
  737. }
  738. xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN,
  739. GFP_KERNEL, &xpad->idata_dma);
  740. if (!xpad->idata) {
  741. error = -ENOMEM;
  742. goto fail1;
  743. }
  744. xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
  745. if (!xpad->irq_in) {
  746. error = -ENOMEM;
  747. goto fail2;
  748. }
  749. xpad->udev = udev;
  750. xpad->intf = intf;
  751. xpad->mapping = xpad_device[i].mapping;
  752. xpad->xtype = xpad_device[i].xtype;
  753. if (xpad->xtype == XTYPE_UNKNOWN) {
  754. if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
  755. if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
  756. xpad->xtype = XTYPE_XBOX360W;
  757. else
  758. xpad->xtype = XTYPE_XBOX360;
  759. } else
  760. xpad->xtype = XTYPE_XBOX;
  761. if (dpad_to_buttons)
  762. xpad->mapping |= MAP_DPAD_TO_BUTTONS;
  763. if (triggers_to_buttons)
  764. xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS;
  765. if (sticks_to_null)
  766. xpad->mapping |= MAP_STICKS_TO_NULL;
  767. }
  768. xpad->dev = input_dev;
  769. usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
  770. strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
  771. input_dev->name = xpad_device[i].name;
  772. input_dev->phys = xpad->phys;
  773. usb_to_input_id(udev, &input_dev->id);
  774. input_dev->dev.parent = &intf->dev;
  775. input_set_drvdata(input_dev, xpad);
  776. input_dev->open = xpad_open;
  777. input_dev->close = xpad_close;
  778. input_dev->evbit[0] = BIT_MASK(EV_KEY);
  779. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  780. input_dev->evbit[0] |= BIT_MASK(EV_ABS);
  781. /* set up axes */
  782. for (i = 0; xpad_abs[i] >= 0; i++)
  783. xpad_set_up_abs(input_dev, xpad_abs[i]);
  784. }
  785. /* set up standard buttons */
  786. for (i = 0; xpad_common_btn[i] >= 0; i++)
  787. __set_bit(xpad_common_btn[i], input_dev->keybit);
  788. /* set up model-specific ones */
  789. if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) {
  790. for (i = 0; xpad360_btn[i] >= 0; i++)
  791. __set_bit(xpad360_btn[i], input_dev->keybit);
  792. } else {
  793. for (i = 0; xpad_btn[i] >= 0; i++)
  794. __set_bit(xpad_btn[i], input_dev->keybit);
  795. }
  796. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  797. for (i = 0; xpad_btn_pad[i] >= 0; i++)
  798. __set_bit(xpad_btn_pad[i], input_dev->keybit);
  799. } else {
  800. for (i = 0; xpad_abs_pad[i] >= 0; i++)
  801. xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
  802. }
  803. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  804. for (i = 0; xpad_btn_triggers[i] >= 0; i++)
  805. __set_bit(xpad_btn_triggers[i], input_dev->keybit);
  806. } else {
  807. for (i = 0; xpad_abs_triggers[i] >= 0; i++)
  808. xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
  809. }
  810. error = xpad_init_output(intf, xpad);
  811. if (error)
  812. goto fail3;
  813. error = xpad_init_ff(xpad);
  814. if (error)
  815. goto fail4;
  816. error = xpad_led_probe(xpad);
  817. if (error)
  818. goto fail5;
  819. ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
  820. usb_fill_int_urb(xpad->irq_in, udev,
  821. usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
  822. xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
  823. xpad, ep_irq_in->bInterval);
  824. xpad->irq_in->transfer_dma = xpad->idata_dma;
  825. xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  826. error = input_register_device(xpad->dev);
  827. if (error)
  828. goto fail6;
  829. usb_set_intfdata(intf, xpad);
  830. if (xpad->xtype == XTYPE_XBOX360W) {
  831. /*
  832. * Setup the message to set the LEDs on the
  833. * controller when it shows up
  834. */
  835. xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
  836. if (!xpad->bulk_out) {
  837. error = -ENOMEM;
  838. goto fail7;
  839. }
  840. xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
  841. if (!xpad->bdata) {
  842. error = -ENOMEM;
  843. goto fail8;
  844. }
  845. xpad->bdata[2] = 0x08;
  846. switch (intf->cur_altsetting->desc.bInterfaceNumber) {
  847. case 0:
  848. xpad->bdata[3] = 0x42;
  849. break;
  850. case 2:
  851. xpad->bdata[3] = 0x43;
  852. break;
  853. case 4:
  854. xpad->bdata[3] = 0x44;
  855. break;
  856. case 6:
  857. xpad->bdata[3] = 0x45;
  858. }
  859. ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
  860. usb_fill_bulk_urb(xpad->bulk_out, udev,
  861. usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress),
  862. xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad);
  863. /*
  864. * Submit the int URB immediately rather than waiting for open
  865. * because we get status messages from the device whether
  866. * or not any controllers are attached. In fact, it's
  867. * exactly the message that a controller has arrived that
  868. * we're waiting for.
  869. */
  870. xpad->irq_in->dev = xpad->udev;
  871. error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
  872. if (error)
  873. goto fail9;
  874. }
  875. return 0;
  876. fail9: kfree(xpad->bdata);
  877. fail8: usb_free_urb(xpad->bulk_out);
  878. fail7: input_unregister_device(input_dev);
  879. input_dev = NULL;
  880. fail6: xpad_led_disconnect(xpad);
  881. fail5: if (input_dev)
  882. input_ff_destroy(input_dev);
  883. fail4: xpad_deinit_output(xpad);
  884. fail3: usb_free_urb(xpad->irq_in);
  885. fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
  886. fail1: input_free_device(input_dev);
  887. kfree(xpad);
  888. return error;
  889. }
  890. static void xpad_disconnect(struct usb_interface *intf)
  891. {
  892. struct usb_xpad *xpad = usb_get_intfdata (intf);
  893. xpad_led_disconnect(xpad);
  894. input_unregister_device(xpad->dev);
  895. xpad_deinit_output(xpad);
  896. if (xpad->xtype == XTYPE_XBOX360W) {
  897. usb_kill_urb(xpad->bulk_out);
  898. usb_free_urb(xpad->bulk_out);
  899. usb_kill_urb(xpad->irq_in);
  900. }
  901. usb_free_urb(xpad->irq_in);
  902. usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
  903. xpad->idata, xpad->idata_dma);
  904. kfree(xpad->bdata);
  905. kfree(xpad);
  906. usb_set_intfdata(intf, NULL);
  907. }
  908. static struct usb_driver xpad_driver = {
  909. .name = "xpad",
  910. .probe = xpad_probe,
  911. .disconnect = xpad_disconnect,
  912. .id_table = xpad_table,
  913. };
  914. module_usb_driver(xpad_driver);
  915. MODULE_AUTHOR(DRIVER_AUTHOR);
  916. MODULE_DESCRIPTION(DRIVER_DESC);
  917. MODULE_LICENSE("GPL");