xpad.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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. int pad_present;
  238. struct urb *irq_in; /* urb for interrupt in report */
  239. unsigned char *idata; /* input data */
  240. dma_addr_t idata_dma;
  241. struct urb *bulk_out;
  242. unsigned char *bdata;
  243. #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
  244. struct urb *irq_out; /* urb for interrupt out report */
  245. unsigned char *odata; /* output data */
  246. dma_addr_t odata_dma;
  247. struct mutex odata_mutex;
  248. #endif
  249. #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
  250. struct xpad_led *led;
  251. #endif
  252. char phys[64]; /* physical device path */
  253. int mapping; /* map d-pad to buttons or to axes */
  254. int xtype; /* type of xbox device */
  255. };
  256. /*
  257. * xpad_process_packet
  258. *
  259. * Completes a request by converting the data into events for the
  260. * input subsystem.
  261. *
  262. * The used report descriptor was taken from ITO Takayukis website:
  263. * http://euc.jp/periphs/xbox-controller.ja.html
  264. */
  265. static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
  266. {
  267. struct input_dev *dev = xpad->dev;
  268. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  269. /* left stick */
  270. input_report_abs(dev, ABS_X,
  271. (__s16) le16_to_cpup((__le16 *)(data + 12)));
  272. input_report_abs(dev, ABS_Y,
  273. ~(__s16) le16_to_cpup((__le16 *)(data + 14)));
  274. /* right stick */
  275. input_report_abs(dev, ABS_RX,
  276. (__s16) le16_to_cpup((__le16 *)(data + 16)));
  277. input_report_abs(dev, ABS_RY,
  278. ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
  279. }
  280. /* triggers left/right */
  281. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  282. input_report_key(dev, BTN_TL2, data[10]);
  283. input_report_key(dev, BTN_TR2, data[11]);
  284. } else {
  285. input_report_abs(dev, ABS_Z, data[10]);
  286. input_report_abs(dev, ABS_RZ, data[11]);
  287. }
  288. /* digital pad */
  289. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  290. /* dpad as buttons (left, right, up, down) */
  291. input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
  292. input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
  293. input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
  294. input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
  295. } else {
  296. input_report_abs(dev, ABS_HAT0X,
  297. !!(data[2] & 0x08) - !!(data[2] & 0x04));
  298. input_report_abs(dev, ABS_HAT0Y,
  299. !!(data[2] & 0x02) - !!(data[2] & 0x01));
  300. }
  301. /* start/back buttons and stick press left/right */
  302. input_report_key(dev, BTN_START, data[2] & 0x10);
  303. input_report_key(dev, BTN_SELECT, data[2] & 0x20);
  304. input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
  305. input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
  306. /* "analog" buttons A, B, X, Y */
  307. input_report_key(dev, BTN_A, data[4]);
  308. input_report_key(dev, BTN_B, data[5]);
  309. input_report_key(dev, BTN_X, data[6]);
  310. input_report_key(dev, BTN_Y, data[7]);
  311. /* "analog" buttons black, white */
  312. input_report_key(dev, BTN_C, data[8]);
  313. input_report_key(dev, BTN_Z, data[9]);
  314. input_sync(dev);
  315. }
  316. /*
  317. * xpad360_process_packet
  318. *
  319. * Completes a request by converting the data into events for the
  320. * input subsystem. It is version for xbox 360 controller
  321. *
  322. * The used report descriptor was taken from:
  323. * http://www.free60.org/wiki/Gamepad
  324. */
  325. static void xpad360_process_packet(struct usb_xpad *xpad,
  326. u16 cmd, unsigned char *data)
  327. {
  328. struct input_dev *dev = xpad->dev;
  329. /* digital pad */
  330. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  331. /* dpad as buttons (left, right, up, down) */
  332. input_report_key(dev, BTN_TRIGGER_HAPPY1, data[2] & 0x04);
  333. input_report_key(dev, BTN_TRIGGER_HAPPY2, data[2] & 0x08);
  334. input_report_key(dev, BTN_TRIGGER_HAPPY3, data[2] & 0x01);
  335. input_report_key(dev, BTN_TRIGGER_HAPPY4, data[2] & 0x02);
  336. } else {
  337. input_report_abs(dev, ABS_HAT0X,
  338. !!(data[2] & 0x08) - !!(data[2] & 0x04));
  339. input_report_abs(dev, ABS_HAT0Y,
  340. !!(data[2] & 0x02) - !!(data[2] & 0x01));
  341. }
  342. /* start/back buttons */
  343. input_report_key(dev, BTN_START, data[2] & 0x10);
  344. input_report_key(dev, BTN_SELECT, data[2] & 0x20);
  345. /* stick press left/right */
  346. input_report_key(dev, BTN_THUMBL, data[2] & 0x40);
  347. input_report_key(dev, BTN_THUMBR, data[2] & 0x80);
  348. /* buttons A,B,X,Y,TL,TR and MODE */
  349. input_report_key(dev, BTN_A, data[3] & 0x10);
  350. input_report_key(dev, BTN_B, data[3] & 0x20);
  351. input_report_key(dev, BTN_X, data[3] & 0x40);
  352. input_report_key(dev, BTN_Y, data[3] & 0x80);
  353. input_report_key(dev, BTN_TL, data[3] & 0x01);
  354. input_report_key(dev, BTN_TR, data[3] & 0x02);
  355. input_report_key(dev, BTN_MODE, data[3] & 0x04);
  356. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  357. /* left stick */
  358. input_report_abs(dev, ABS_X,
  359. (__s16) le16_to_cpup((__le16 *)(data + 6)));
  360. input_report_abs(dev, ABS_Y,
  361. ~(__s16) le16_to_cpup((__le16 *)(data + 8)));
  362. /* right stick */
  363. input_report_abs(dev, ABS_RX,
  364. (__s16) le16_to_cpup((__le16 *)(data + 10)));
  365. input_report_abs(dev, ABS_RY,
  366. ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
  367. }
  368. /* triggers left/right */
  369. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  370. input_report_key(dev, BTN_TL2, data[4]);
  371. input_report_key(dev, BTN_TR2, data[5]);
  372. } else {
  373. input_report_abs(dev, ABS_Z, data[4]);
  374. input_report_abs(dev, ABS_RZ, data[5]);
  375. }
  376. input_sync(dev);
  377. }
  378. /*
  379. * xpad360w_process_packet
  380. *
  381. * Completes a request by converting the data into events for the
  382. * input subsystem. It is version for xbox 360 wireless controller.
  383. *
  384. * Byte.Bit
  385. * 00.1 - Status change: The controller or headset has connected/disconnected
  386. * Bits 01.7 and 01.6 are valid
  387. * 01.7 - Controller present
  388. * 01.6 - Headset present
  389. * 01.1 - Pad state (Bytes 4+) valid
  390. *
  391. */
  392. static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
  393. {
  394. /* Presence change */
  395. if (data[0] & 0x08) {
  396. if (data[1] & 0x80) {
  397. xpad->pad_present = 1;
  398. usb_submit_urb(xpad->bulk_out, GFP_ATOMIC);
  399. } else
  400. xpad->pad_present = 0;
  401. }
  402. /* Valid pad data */
  403. if (!(data[1] & 0x1))
  404. return;
  405. xpad360_process_packet(xpad, cmd, &data[4]);
  406. }
  407. static void xpad_irq_in(struct urb *urb)
  408. {
  409. struct usb_xpad *xpad = urb->context;
  410. int retval, status;
  411. status = urb->status;
  412. switch (status) {
  413. case 0:
  414. /* success */
  415. break;
  416. case -ECONNRESET:
  417. case -ENOENT:
  418. case -ESHUTDOWN:
  419. /* this urb is terminated, clean up */
  420. dbg("%s - urb shutting down with status: %d",
  421. __func__, status);
  422. return;
  423. default:
  424. dbg("%s - nonzero urb status received: %d",
  425. __func__, status);
  426. goto exit;
  427. }
  428. switch (xpad->xtype) {
  429. case XTYPE_XBOX360:
  430. xpad360_process_packet(xpad, 0, xpad->idata);
  431. break;
  432. case XTYPE_XBOX360W:
  433. xpad360w_process_packet(xpad, 0, xpad->idata);
  434. break;
  435. default:
  436. xpad_process_packet(xpad, 0, xpad->idata);
  437. }
  438. exit:
  439. retval = usb_submit_urb(urb, GFP_ATOMIC);
  440. if (retval)
  441. err ("%s - usb_submit_urb failed with result %d",
  442. __func__, retval);
  443. }
  444. static void xpad_bulk_out(struct urb *urb)
  445. {
  446. switch (urb->status) {
  447. case 0:
  448. /* success */
  449. break;
  450. case -ECONNRESET:
  451. case -ENOENT:
  452. case -ESHUTDOWN:
  453. /* this urb is terminated, clean up */
  454. dbg("%s - urb shutting down with status: %d", __func__, urb->status);
  455. break;
  456. default:
  457. dbg("%s - nonzero urb status received: %d", __func__, urb->status);
  458. }
  459. }
  460. #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
  461. static void xpad_irq_out(struct urb *urb)
  462. {
  463. int retval, status;
  464. status = urb->status;
  465. switch (status) {
  466. case 0:
  467. /* success */
  468. return;
  469. case -ECONNRESET:
  470. case -ENOENT:
  471. case -ESHUTDOWN:
  472. /* this urb is terminated, clean up */
  473. dbg("%s - urb shutting down with status: %d", __func__, status);
  474. return;
  475. default:
  476. dbg("%s - nonzero urb status received: %d", __func__, status);
  477. goto exit;
  478. }
  479. exit:
  480. retval = usb_submit_urb(urb, GFP_ATOMIC);
  481. if (retval)
  482. err("%s - usb_submit_urb failed with result %d",
  483. __func__, retval);
  484. }
  485. static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
  486. {
  487. struct usb_endpoint_descriptor *ep_irq_out;
  488. int error;
  489. if (xpad->xtype == XTYPE_UNKNOWN)
  490. return 0;
  491. xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
  492. GFP_KERNEL, &xpad->odata_dma);
  493. if (!xpad->odata) {
  494. error = -ENOMEM;
  495. goto fail1;
  496. }
  497. mutex_init(&xpad->odata_mutex);
  498. xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
  499. if (!xpad->irq_out) {
  500. error = -ENOMEM;
  501. goto fail2;
  502. }
  503. ep_irq_out = &intf->cur_altsetting->endpoint[1].desc;
  504. usb_fill_int_urb(xpad->irq_out, xpad->udev,
  505. usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
  506. xpad->odata, XPAD_PKT_LEN,
  507. xpad_irq_out, xpad, ep_irq_out->bInterval);
  508. xpad->irq_out->transfer_dma = xpad->odata_dma;
  509. xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  510. return 0;
  511. fail2: usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
  512. fail1: return error;
  513. }
  514. static void xpad_stop_output(struct usb_xpad *xpad)
  515. {
  516. if (xpad->xtype != XTYPE_UNKNOWN)
  517. usb_kill_urb(xpad->irq_out);
  518. }
  519. static void xpad_deinit_output(struct usb_xpad *xpad)
  520. {
  521. if (xpad->xtype != XTYPE_UNKNOWN) {
  522. usb_free_urb(xpad->irq_out);
  523. usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
  524. xpad->odata, xpad->odata_dma);
  525. }
  526. }
  527. #else
  528. static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; }
  529. static void xpad_deinit_output(struct usb_xpad *xpad) {}
  530. static void xpad_stop_output(struct usb_xpad *xpad) {}
  531. #endif
  532. #ifdef CONFIG_JOYSTICK_XPAD_FF
  533. static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
  534. {
  535. struct usb_xpad *xpad = input_get_drvdata(dev);
  536. if (effect->type == FF_RUMBLE) {
  537. __u16 strong = effect->u.rumble.strong_magnitude;
  538. __u16 weak = effect->u.rumble.weak_magnitude;
  539. switch (xpad->xtype) {
  540. case XTYPE_XBOX:
  541. xpad->odata[0] = 0x00;
  542. xpad->odata[1] = 0x06;
  543. xpad->odata[2] = 0x00;
  544. xpad->odata[3] = strong / 256; /* left actuator */
  545. xpad->odata[4] = 0x00;
  546. xpad->odata[5] = weak / 256; /* right actuator */
  547. xpad->irq_out->transfer_buffer_length = 6;
  548. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  549. case XTYPE_XBOX360:
  550. xpad->odata[0] = 0x00;
  551. xpad->odata[1] = 0x08;
  552. xpad->odata[2] = 0x00;
  553. xpad->odata[3] = strong / 256; /* left actuator? */
  554. xpad->odata[4] = weak / 256; /* right actuator? */
  555. xpad->odata[5] = 0x00;
  556. xpad->odata[6] = 0x00;
  557. xpad->odata[7] = 0x00;
  558. xpad->irq_out->transfer_buffer_length = 8;
  559. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  560. case XTYPE_XBOX360W:
  561. xpad->odata[0] = 0x00;
  562. xpad->odata[1] = 0x01;
  563. xpad->odata[2] = 0x0F;
  564. xpad->odata[3] = 0xC0;
  565. xpad->odata[4] = 0x00;
  566. xpad->odata[5] = strong / 256;
  567. xpad->odata[6] = weak / 256;
  568. xpad->odata[7] = 0x00;
  569. xpad->odata[8] = 0x00;
  570. xpad->odata[9] = 0x00;
  571. xpad->odata[10] = 0x00;
  572. xpad->odata[11] = 0x00;
  573. xpad->irq_out->transfer_buffer_length = 12;
  574. return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
  575. default:
  576. dbg("%s - rumble command sent to unsupported xpad type: %d",
  577. __func__, xpad->xtype);
  578. return -1;
  579. }
  580. }
  581. return 0;
  582. }
  583. static int xpad_init_ff(struct usb_xpad *xpad)
  584. {
  585. if (xpad->xtype == XTYPE_UNKNOWN)
  586. return 0;
  587. input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
  588. return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
  589. }
  590. #else
  591. static int xpad_init_ff(struct usb_xpad *xpad) { return 0; }
  592. #endif
  593. #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
  594. #include <linux/leds.h>
  595. struct xpad_led {
  596. char name[16];
  597. struct led_classdev led_cdev;
  598. struct usb_xpad *xpad;
  599. };
  600. static void xpad_send_led_command(struct usb_xpad *xpad, int command)
  601. {
  602. if (command >= 0 && command < 14) {
  603. mutex_lock(&xpad->odata_mutex);
  604. xpad->odata[0] = 0x01;
  605. xpad->odata[1] = 0x03;
  606. xpad->odata[2] = command;
  607. xpad->irq_out->transfer_buffer_length = 3;
  608. usb_submit_urb(xpad->irq_out, GFP_KERNEL);
  609. mutex_unlock(&xpad->odata_mutex);
  610. }
  611. }
  612. static void xpad_led_set(struct led_classdev *led_cdev,
  613. enum led_brightness value)
  614. {
  615. struct xpad_led *xpad_led = container_of(led_cdev,
  616. struct xpad_led, led_cdev);
  617. xpad_send_led_command(xpad_led->xpad, value);
  618. }
  619. static int xpad_led_probe(struct usb_xpad *xpad)
  620. {
  621. static atomic_t led_seq = ATOMIC_INIT(0);
  622. long led_no;
  623. struct xpad_led *led;
  624. struct led_classdev *led_cdev;
  625. int error;
  626. if (xpad->xtype != XTYPE_XBOX360)
  627. return 0;
  628. xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL);
  629. if (!led)
  630. return -ENOMEM;
  631. led_no = (long)atomic_inc_return(&led_seq) - 1;
  632. snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
  633. led->xpad = xpad;
  634. led_cdev = &led->led_cdev;
  635. led_cdev->name = led->name;
  636. led_cdev->brightness_set = xpad_led_set;
  637. error = led_classdev_register(&xpad->udev->dev, led_cdev);
  638. if (error) {
  639. kfree(led);
  640. xpad->led = NULL;
  641. return error;
  642. }
  643. /*
  644. * Light up the segment corresponding to controller number
  645. */
  646. xpad_send_led_command(xpad, (led_no % 4) + 2);
  647. return 0;
  648. }
  649. static void xpad_led_disconnect(struct usb_xpad *xpad)
  650. {
  651. struct xpad_led *xpad_led = xpad->led;
  652. if (xpad_led) {
  653. led_classdev_unregister(&xpad_led->led_cdev);
  654. kfree(xpad_led);
  655. }
  656. }
  657. #else
  658. static int xpad_led_probe(struct usb_xpad *xpad) { return 0; }
  659. static void xpad_led_disconnect(struct usb_xpad *xpad) { }
  660. #endif
  661. static int xpad_open(struct input_dev *dev)
  662. {
  663. struct usb_xpad *xpad = input_get_drvdata(dev);
  664. /* URB was submitted in probe */
  665. if(xpad->xtype == XTYPE_XBOX360W)
  666. return 0;
  667. xpad->irq_in->dev = xpad->udev;
  668. if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
  669. return -EIO;
  670. return 0;
  671. }
  672. static void xpad_close(struct input_dev *dev)
  673. {
  674. struct usb_xpad *xpad = input_get_drvdata(dev);
  675. if (xpad->xtype != XTYPE_XBOX360W)
  676. usb_kill_urb(xpad->irq_in);
  677. xpad_stop_output(xpad);
  678. }
  679. static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
  680. {
  681. set_bit(abs, input_dev->absbit);
  682. switch (abs) {
  683. case ABS_X:
  684. case ABS_Y:
  685. case ABS_RX:
  686. case ABS_RY: /* the two sticks */
  687. input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128);
  688. break;
  689. case ABS_Z:
  690. case ABS_RZ: /* the triggers (if mapped to axes) */
  691. input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
  692. break;
  693. case ABS_HAT0X:
  694. case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */
  695. input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
  696. break;
  697. }
  698. }
  699. static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id)
  700. {
  701. struct usb_device *udev = interface_to_usbdev(intf);
  702. struct usb_xpad *xpad;
  703. struct input_dev *input_dev;
  704. struct usb_endpoint_descriptor *ep_irq_in;
  705. int i, error;
  706. for (i = 0; xpad_device[i].idVendor; i++) {
  707. if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&
  708. (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))
  709. break;
  710. }
  711. xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);
  712. input_dev = input_allocate_device();
  713. if (!xpad || !input_dev) {
  714. error = -ENOMEM;
  715. goto fail1;
  716. }
  717. xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN,
  718. GFP_KERNEL, &xpad->idata_dma);
  719. if (!xpad->idata) {
  720. error = -ENOMEM;
  721. goto fail1;
  722. }
  723. xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
  724. if (!xpad->irq_in) {
  725. error = -ENOMEM;
  726. goto fail2;
  727. }
  728. xpad->udev = udev;
  729. xpad->mapping = xpad_device[i].mapping;
  730. xpad->xtype = xpad_device[i].xtype;
  731. if (xpad->xtype == XTYPE_UNKNOWN) {
  732. if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
  733. if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
  734. xpad->xtype = XTYPE_XBOX360W;
  735. else
  736. xpad->xtype = XTYPE_XBOX360;
  737. } else
  738. xpad->xtype = XTYPE_XBOX;
  739. if (dpad_to_buttons)
  740. xpad->mapping |= MAP_DPAD_TO_BUTTONS;
  741. if (triggers_to_buttons)
  742. xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS;
  743. if (sticks_to_null)
  744. xpad->mapping |= MAP_STICKS_TO_NULL;
  745. }
  746. xpad->dev = input_dev;
  747. usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
  748. strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
  749. input_dev->name = xpad_device[i].name;
  750. input_dev->phys = xpad->phys;
  751. usb_to_input_id(udev, &input_dev->id);
  752. input_dev->dev.parent = &intf->dev;
  753. input_set_drvdata(input_dev, xpad);
  754. input_dev->open = xpad_open;
  755. input_dev->close = xpad_close;
  756. input_dev->evbit[0] = BIT_MASK(EV_KEY);
  757. if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
  758. input_dev->evbit[0] |= BIT_MASK(EV_ABS);
  759. /* set up axes */
  760. for (i = 0; xpad_abs[i] >= 0; i++)
  761. xpad_set_up_abs(input_dev, xpad_abs[i]);
  762. }
  763. /* set up standard buttons */
  764. for (i = 0; xpad_common_btn[i] >= 0; i++)
  765. __set_bit(xpad_common_btn[i], input_dev->keybit);
  766. /* set up model-specific ones */
  767. if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) {
  768. for (i = 0; xpad360_btn[i] >= 0; i++)
  769. __set_bit(xpad360_btn[i], input_dev->keybit);
  770. } else {
  771. for (i = 0; xpad_btn[i] >= 0; i++)
  772. __set_bit(xpad_btn[i], input_dev->keybit);
  773. }
  774. if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
  775. for (i = 0; xpad_btn_pad[i] >= 0; i++)
  776. __set_bit(xpad_btn_pad[i], input_dev->keybit);
  777. } else {
  778. for (i = 0; xpad_abs_pad[i] >= 0; i++)
  779. xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
  780. }
  781. if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
  782. for (i = 0; xpad_btn_triggers[i] >= 0; i++)
  783. __set_bit(xpad_btn_triggers[i], input_dev->keybit);
  784. } else {
  785. for (i = 0; xpad_abs_triggers[i] >= 0; i++)
  786. xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
  787. }
  788. error = xpad_init_output(intf, xpad);
  789. if (error)
  790. goto fail3;
  791. error = xpad_init_ff(xpad);
  792. if (error)
  793. goto fail4;
  794. error = xpad_led_probe(xpad);
  795. if (error)
  796. goto fail5;
  797. ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
  798. usb_fill_int_urb(xpad->irq_in, udev,
  799. usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
  800. xpad->idata, XPAD_PKT_LEN, xpad_irq_in,
  801. xpad, ep_irq_in->bInterval);
  802. xpad->irq_in->transfer_dma = xpad->idata_dma;
  803. xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  804. error = input_register_device(xpad->dev);
  805. if (error)
  806. goto fail6;
  807. usb_set_intfdata(intf, xpad);
  808. if (xpad->xtype == XTYPE_XBOX360W) {
  809. /*
  810. * Setup the message to set the LEDs on the
  811. * controller when it shows up
  812. */
  813. xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);
  814. if (!xpad->bulk_out) {
  815. error = -ENOMEM;
  816. goto fail7;
  817. }
  818. xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);
  819. if (!xpad->bdata) {
  820. error = -ENOMEM;
  821. goto fail8;
  822. }
  823. xpad->bdata[2] = 0x08;
  824. switch (intf->cur_altsetting->desc.bInterfaceNumber) {
  825. case 0:
  826. xpad->bdata[3] = 0x42;
  827. break;
  828. case 2:
  829. xpad->bdata[3] = 0x43;
  830. break;
  831. case 4:
  832. xpad->bdata[3] = 0x44;
  833. break;
  834. case 6:
  835. xpad->bdata[3] = 0x45;
  836. }
  837. ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
  838. if (usb_endpoint_is_bulk_out(ep_irq_in)) {
  839. usb_fill_bulk_urb(xpad->bulk_out, udev,
  840. usb_sndbulkpipe(udev,
  841. ep_irq_in->bEndpointAddress),
  842. xpad->bdata, XPAD_PKT_LEN,
  843. xpad_bulk_out, xpad);
  844. } else {
  845. usb_fill_int_urb(xpad->bulk_out, udev,
  846. usb_sndintpipe(udev,
  847. ep_irq_in->bEndpointAddress),
  848. xpad->bdata, XPAD_PKT_LEN,
  849. xpad_bulk_out, xpad, 0);
  850. }
  851. /*
  852. * Submit the int URB immediately rather than waiting for open
  853. * because we get status messages from the device whether
  854. * or not any controllers are attached. In fact, it's
  855. * exactly the message that a controller has arrived that
  856. * we're waiting for.
  857. */
  858. xpad->irq_in->dev = xpad->udev;
  859. error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
  860. if (error)
  861. goto fail9;
  862. }
  863. return 0;
  864. fail9: kfree(xpad->bdata);
  865. fail8: usb_free_urb(xpad->bulk_out);
  866. fail7: input_unregister_device(input_dev);
  867. input_dev = NULL;
  868. fail6: xpad_led_disconnect(xpad);
  869. fail5: if (input_dev)
  870. input_ff_destroy(input_dev);
  871. fail4: xpad_deinit_output(xpad);
  872. fail3: usb_free_urb(xpad->irq_in);
  873. fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
  874. fail1: input_free_device(input_dev);
  875. kfree(xpad);
  876. return error;
  877. }
  878. static void xpad_disconnect(struct usb_interface *intf)
  879. {
  880. struct usb_xpad *xpad = usb_get_intfdata (intf);
  881. xpad_led_disconnect(xpad);
  882. input_unregister_device(xpad->dev);
  883. xpad_deinit_output(xpad);
  884. if (xpad->xtype == XTYPE_XBOX360W) {
  885. usb_kill_urb(xpad->bulk_out);
  886. usb_free_urb(xpad->bulk_out);
  887. usb_kill_urb(xpad->irq_in);
  888. }
  889. usb_free_urb(xpad->irq_in);
  890. usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
  891. xpad->idata, xpad->idata_dma);
  892. kfree(xpad->bdata);
  893. kfree(xpad);
  894. usb_set_intfdata(intf, NULL);
  895. }
  896. static struct usb_driver xpad_driver = {
  897. .name = "xpad",
  898. .probe = xpad_probe,
  899. .disconnect = xpad_disconnect,
  900. .id_table = xpad_table,
  901. };
  902. module_usb_driver(xpad_driver);
  903. MODULE_AUTHOR(DRIVER_AUTHOR);
  904. MODULE_DESCRIPTION(DRIVER_DESC);
  905. MODULE_LICENSE("GPL");