xpad.c 31 KB

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