bcm5974.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /*
  2. * Apple USB BCM5974 (Macbook Air and Penryn Macbook Pro) multitouch driver
  3. *
  4. * Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se)
  5. *
  6. * The USB initialization and package decoding was made by
  7. * Scott Shawcroft as part of the touchd user-space driver project:
  8. * Copyright (C) 2008 Scott Shawcroft (scott.shawcroft@gmail.com)
  9. *
  10. * The BCM5974 driver is based on the appletouch driver:
  11. * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
  12. * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net)
  13. * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
  14. * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
  15. * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
  16. * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
  17. * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. *
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/errno.h>
  36. #include <linux/init.h>
  37. #include <linux/slab.h>
  38. #include <linux/module.h>
  39. #include <linux/usb/input.h>
  40. #include <linux/hid.h>
  41. #include <linux/mutex.h>
  42. #include <linux/input/mt.h>
  43. #define USB_VENDOR_ID_APPLE 0x05ac
  44. /* MacbookAir, aka wellspring */
  45. #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223
  46. #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224
  47. #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225
  48. /* MacbookProPenryn, aka wellspring2 */
  49. #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230
  50. #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231
  51. #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232
  52. /* Macbook5,1 (unibody), aka wellspring3 */
  53. #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236
  54. #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237
  55. #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238
  56. /* MacbookAir3,2 (unibody), aka wellspring5 */
  57. #define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f
  58. #define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240
  59. #define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241
  60. /* MacbookAir3,1 (unibody), aka wellspring4 */
  61. #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242
  62. #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243
  63. #define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244
  64. /* Macbook8 (unibody, March 2011) */
  65. #define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245
  66. #define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246
  67. #define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247
  68. /* MacbookAir4,1 (unibody, July 2011) */
  69. #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI 0x0249
  70. #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO 0x024a
  71. #define USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS 0x024b
  72. /* MacbookAir4,2 (unibody, July 2011) */
  73. #define USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI 0x024c
  74. #define USB_DEVICE_ID_APPLE_WELLSPRING6_ISO 0x024d
  75. #define USB_DEVICE_ID_APPLE_WELLSPRING6_JIS 0x024e
  76. /* Macbook8,2 (unibody) */
  77. #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252
  78. #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253
  79. #define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254
  80. /* MacbookPro10,1 (unibody, June 2012) */
  81. #define USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI 0x0262
  82. #define USB_DEVICE_ID_APPLE_WELLSPRING7_ISO 0x0263
  83. #define USB_DEVICE_ID_APPLE_WELLSPRING7_JIS 0x0264
  84. /* MacbookPro10,2 (unibody, October 2012) */
  85. #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI 0x0259
  86. #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a
  87. #define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b
  88. /* MacbookAir6,2 (unibody, June 2013) */
  89. #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
  90. #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
  91. #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
  92. #define BCM5974_DEVICE(prod) { \
  93. .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
  94. USB_DEVICE_ID_MATCH_INT_CLASS | \
  95. USB_DEVICE_ID_MATCH_INT_PROTOCOL), \
  96. .idVendor = USB_VENDOR_ID_APPLE, \
  97. .idProduct = (prod), \
  98. .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
  99. .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE \
  100. }
  101. /* table of devices that work with this driver */
  102. static const struct usb_device_id bcm5974_table[] = {
  103. /* MacbookAir1.1 */
  104. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
  105. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
  106. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
  107. /* MacbookProPenryn */
  108. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
  109. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
  110. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
  111. /* Macbook5,1 */
  112. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
  113. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
  114. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
  115. /* MacbookAir3,2 */
  116. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI),
  117. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ISO),
  118. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_JIS),
  119. /* MacbookAir3,1 */
  120. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI),
  121. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO),
  122. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS),
  123. /* MacbookPro8 */
  124. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI),
  125. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ISO),
  126. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_JIS),
  127. /* MacbookAir4,1 */
  128. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI),
  129. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO),
  130. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
  131. /* MacbookAir4,2 */
  132. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI),
  133. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_ISO),
  134. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_JIS),
  135. /* MacbookPro8,2 */
  136. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
  137. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
  138. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
  139. /* MacbookPro10,1 */
  140. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI),
  141. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ISO),
  142. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_JIS),
  143. /* MacbookPro10,2 */
  144. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI),
  145. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO),
  146. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS),
  147. /* MacbookAir6,2 */
  148. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI),
  149. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_ISO),
  150. BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_JIS),
  151. /* Terminating entry */
  152. {}
  153. };
  154. MODULE_DEVICE_TABLE(usb, bcm5974_table);
  155. MODULE_AUTHOR("Henrik Rydberg");
  156. MODULE_DESCRIPTION("Apple USB BCM5974 multitouch driver");
  157. MODULE_LICENSE("GPL");
  158. #define dprintk(level, format, a...)\
  159. { if (debug >= level) printk(KERN_DEBUG format, ##a); }
  160. static int debug = 1;
  161. module_param(debug, int, 0644);
  162. MODULE_PARM_DESC(debug, "Activate debugging output");
  163. /* button data structure */
  164. struct bt_data {
  165. u8 unknown1; /* constant */
  166. u8 button; /* left button */
  167. u8 rel_x; /* relative x coordinate */
  168. u8 rel_y; /* relative y coordinate */
  169. };
  170. /* trackpad header types */
  171. enum tp_type {
  172. TYPE1, /* plain trackpad */
  173. TYPE2, /* button integrated in trackpad */
  174. TYPE3 /* additional header fields since June 2013 */
  175. };
  176. /* trackpad finger data offsets, le16-aligned */
  177. #define FINGER_TYPE1 (13 * sizeof(__le16))
  178. #define FINGER_TYPE2 (15 * sizeof(__le16))
  179. #define FINGER_TYPE3 (19 * sizeof(__le16))
  180. /* trackpad button data offsets */
  181. #define BUTTON_TYPE2 15
  182. #define BUTTON_TYPE3 23
  183. /* list of device capability bits */
  184. #define HAS_INTEGRATED_BUTTON 1
  185. /* trackpad finger structure, le16-aligned */
  186. struct tp_finger {
  187. __le16 origin; /* zero when switching track finger */
  188. __le16 abs_x; /* absolute x coodinate */
  189. __le16 abs_y; /* absolute y coodinate */
  190. __le16 rel_x; /* relative x coodinate */
  191. __le16 rel_y; /* relative y coodinate */
  192. __le16 tool_major; /* tool area, major axis */
  193. __le16 tool_minor; /* tool area, minor axis */
  194. __le16 orientation; /* 16384 when point, else 15 bit angle */
  195. __le16 touch_major; /* touch area, major axis */
  196. __le16 touch_minor; /* touch area, minor axis */
  197. __le16 unused[3]; /* zeros */
  198. __le16 multi; /* one finger: varies, more fingers: constant */
  199. } __attribute__((packed,aligned(2)));
  200. /* trackpad finger data size, empirically at least ten fingers */
  201. #define MAX_FINGERS 16
  202. #define SIZEOF_FINGER sizeof(struct tp_finger)
  203. #define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER)
  204. #define MAX_FINGER_ORIENTATION 16384
  205. /* device-specific parameters */
  206. struct bcm5974_param {
  207. int snratio; /* signal-to-noise ratio */
  208. int min; /* device minimum reading */
  209. int max; /* device maximum reading */
  210. };
  211. /* device-specific configuration */
  212. struct bcm5974_config {
  213. int ansi, iso, jis; /* the product id of this device */
  214. int caps; /* device capability bitmask */
  215. int bt_ep; /* the endpoint of the button interface */
  216. int bt_datalen; /* data length of the button interface */
  217. int tp_ep; /* the endpoint of the trackpad interface */
  218. enum tp_type tp_type; /* type of trackpad interface */
  219. int tp_offset; /* offset to trackpad finger data */
  220. int tp_datalen; /* data length of the trackpad interface */
  221. struct bcm5974_param p; /* finger pressure limits */
  222. struct bcm5974_param w; /* finger width limits */
  223. struct bcm5974_param x; /* horizontal limits */
  224. struct bcm5974_param y; /* vertical limits */
  225. struct bcm5974_param o; /* orientation limits */
  226. };
  227. /* logical device structure */
  228. struct bcm5974 {
  229. char phys[64];
  230. struct usb_device *udev; /* usb device */
  231. struct usb_interface *intf; /* our interface */
  232. struct input_dev *input; /* input dev */
  233. struct bcm5974_config cfg; /* device configuration */
  234. struct mutex pm_mutex; /* serialize access to open/suspend */
  235. int opened; /* 1: opened, 0: closed */
  236. struct urb *bt_urb; /* button usb request block */
  237. struct bt_data *bt_data; /* button transferred data */
  238. struct urb *tp_urb; /* trackpad usb request block */
  239. u8 *tp_data; /* trackpad transferred data */
  240. const struct tp_finger *index[MAX_FINGERS]; /* finger index data */
  241. struct input_mt_pos pos[MAX_FINGERS]; /* position array */
  242. int slots[MAX_FINGERS]; /* slot assignments */
  243. };
  244. /* logical signal quality */
  245. #define SN_PRESSURE 45 /* pressure signal-to-noise ratio */
  246. #define SN_WIDTH 25 /* width signal-to-noise ratio */
  247. #define SN_COORD 250 /* coordinate signal-to-noise ratio */
  248. #define SN_ORIENT 10 /* orientation signal-to-noise ratio */
  249. /* device constants */
  250. static const struct bcm5974_config bcm5974_config_table[] = {
  251. {
  252. USB_DEVICE_ID_APPLE_WELLSPRING_ANSI,
  253. USB_DEVICE_ID_APPLE_WELLSPRING_ISO,
  254. USB_DEVICE_ID_APPLE_WELLSPRING_JIS,
  255. 0,
  256. 0x84, sizeof(struct bt_data),
  257. 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
  258. { SN_PRESSURE, 0, 256 },
  259. { SN_WIDTH, 0, 2048 },
  260. { SN_COORD, -4824, 5342 },
  261. { SN_COORD, -172, 5820 },
  262. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  263. },
  264. {
  265. USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI,
  266. USB_DEVICE_ID_APPLE_WELLSPRING2_ISO,
  267. USB_DEVICE_ID_APPLE_WELLSPRING2_JIS,
  268. 0,
  269. 0x84, sizeof(struct bt_data),
  270. 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
  271. { SN_PRESSURE, 0, 256 },
  272. { SN_WIDTH, 0, 2048 },
  273. { SN_COORD, -4824, 4824 },
  274. { SN_COORD, -172, 4290 },
  275. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  276. },
  277. {
  278. USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI,
  279. USB_DEVICE_ID_APPLE_WELLSPRING3_ISO,
  280. USB_DEVICE_ID_APPLE_WELLSPRING3_JIS,
  281. HAS_INTEGRATED_BUTTON,
  282. 0x84, sizeof(struct bt_data),
  283. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  284. { SN_PRESSURE, 0, 300 },
  285. { SN_WIDTH, 0, 2048 },
  286. { SN_COORD, -4460, 5166 },
  287. { SN_COORD, -75, 6700 },
  288. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  289. },
  290. {
  291. USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI,
  292. USB_DEVICE_ID_APPLE_WELLSPRING4_ISO,
  293. USB_DEVICE_ID_APPLE_WELLSPRING4_JIS,
  294. HAS_INTEGRATED_BUTTON,
  295. 0x84, sizeof(struct bt_data),
  296. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  297. { SN_PRESSURE, 0, 300 },
  298. { SN_WIDTH, 0, 2048 },
  299. { SN_COORD, -4620, 5140 },
  300. { SN_COORD, -150, 6600 },
  301. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  302. },
  303. {
  304. USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI,
  305. USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO,
  306. USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS,
  307. HAS_INTEGRATED_BUTTON,
  308. 0x84, sizeof(struct bt_data),
  309. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  310. { SN_PRESSURE, 0, 300 },
  311. { SN_WIDTH, 0, 2048 },
  312. { SN_COORD, -4616, 5112 },
  313. { SN_COORD, -142, 5234 },
  314. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  315. },
  316. {
  317. USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI,
  318. USB_DEVICE_ID_APPLE_WELLSPRING5_ISO,
  319. USB_DEVICE_ID_APPLE_WELLSPRING5_JIS,
  320. HAS_INTEGRATED_BUTTON,
  321. 0x84, sizeof(struct bt_data),
  322. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  323. { SN_PRESSURE, 0, 300 },
  324. { SN_WIDTH, 0, 2048 },
  325. { SN_COORD, -4415, 5050 },
  326. { SN_COORD, -55, 6680 },
  327. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  328. },
  329. {
  330. USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI,
  331. USB_DEVICE_ID_APPLE_WELLSPRING6_ISO,
  332. USB_DEVICE_ID_APPLE_WELLSPRING6_JIS,
  333. HAS_INTEGRATED_BUTTON,
  334. 0x84, sizeof(struct bt_data),
  335. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  336. { SN_PRESSURE, 0, 300 },
  337. { SN_WIDTH, 0, 2048 },
  338. { SN_COORD, -4620, 5140 },
  339. { SN_COORD, -150, 6600 },
  340. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  341. },
  342. {
  343. USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI,
  344. USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO,
  345. USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS,
  346. HAS_INTEGRATED_BUTTON,
  347. 0x84, sizeof(struct bt_data),
  348. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  349. { SN_PRESSURE, 0, 300 },
  350. { SN_WIDTH, 0, 2048 },
  351. { SN_COORD, -4750, 5280 },
  352. { SN_COORD, -150, 6730 },
  353. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  354. },
  355. {
  356. USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI,
  357. USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO,
  358. USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS,
  359. HAS_INTEGRATED_BUTTON,
  360. 0x84, sizeof(struct bt_data),
  361. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  362. { SN_PRESSURE, 0, 300 },
  363. { SN_WIDTH, 0, 2048 },
  364. { SN_COORD, -4620, 5140 },
  365. { SN_COORD, -150, 6600 },
  366. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  367. },
  368. {
  369. USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI,
  370. USB_DEVICE_ID_APPLE_WELLSPRING7_ISO,
  371. USB_DEVICE_ID_APPLE_WELLSPRING7_JIS,
  372. HAS_INTEGRATED_BUTTON,
  373. 0x84, sizeof(struct bt_data),
  374. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  375. { SN_PRESSURE, 0, 300 },
  376. { SN_WIDTH, 0, 2048 },
  377. { SN_COORD, -4750, 5280 },
  378. { SN_COORD, -150, 6730 },
  379. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  380. },
  381. {
  382. USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI,
  383. USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO,
  384. USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS,
  385. HAS_INTEGRATED_BUTTON,
  386. 0x84, sizeof(struct bt_data),
  387. 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
  388. { SN_PRESSURE, 0, 300 },
  389. { SN_WIDTH, 0, 2048 },
  390. { SN_COORD, -4750, 5280 },
  391. { SN_COORD, -150, 6730 },
  392. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  393. },
  394. {
  395. USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI,
  396. USB_DEVICE_ID_APPLE_WELLSPRING8_ISO,
  397. USB_DEVICE_ID_APPLE_WELLSPRING8_JIS,
  398. HAS_INTEGRATED_BUTTON,
  399. 0, sizeof(struct bt_data),
  400. 0x83, TYPE3, FINGER_TYPE3, FINGER_TYPE3 + SIZEOF_ALL_FINGERS,
  401. { SN_PRESSURE, 0, 300 },
  402. { SN_WIDTH, 0, 2048 },
  403. { SN_COORD, -4620, 5140 },
  404. { SN_COORD, -150, 6600 },
  405. { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION }
  406. },
  407. {}
  408. };
  409. /* return the device-specific configuration by device */
  410. static const struct bcm5974_config *bcm5974_get_config(struct usb_device *udev)
  411. {
  412. u16 id = le16_to_cpu(udev->descriptor.idProduct);
  413. const struct bcm5974_config *cfg;
  414. for (cfg = bcm5974_config_table; cfg->ansi; ++cfg)
  415. if (cfg->ansi == id || cfg->iso == id || cfg->jis == id)
  416. return cfg;
  417. return bcm5974_config_table;
  418. }
  419. /* convert 16-bit little endian to signed integer */
  420. static inline int raw2int(__le16 x)
  421. {
  422. return (signed short)le16_to_cpu(x);
  423. }
  424. static void set_abs(struct input_dev *input, unsigned int code,
  425. const struct bcm5974_param *p)
  426. {
  427. int fuzz = p->snratio ? (p->max - p->min) / p->snratio : 0;
  428. input_set_abs_params(input, code, p->min, p->max, fuzz, 0);
  429. }
  430. /* setup which logical events to report */
  431. static void setup_events_to_report(struct input_dev *input_dev,
  432. const struct bcm5974_config *cfg)
  433. {
  434. __set_bit(EV_ABS, input_dev->evbit);
  435. /* for synaptics only */
  436. input_set_abs_params(input_dev, ABS_PRESSURE, 0, 256, 5, 0);
  437. input_set_abs_params(input_dev, ABS_TOOL_WIDTH, 0, 16, 0, 0);
  438. /* finger touch area */
  439. set_abs(input_dev, ABS_MT_TOUCH_MAJOR, &cfg->w);
  440. set_abs(input_dev, ABS_MT_TOUCH_MINOR, &cfg->w);
  441. /* finger approach area */
  442. set_abs(input_dev, ABS_MT_WIDTH_MAJOR, &cfg->w);
  443. set_abs(input_dev, ABS_MT_WIDTH_MINOR, &cfg->w);
  444. /* finger orientation */
  445. set_abs(input_dev, ABS_MT_ORIENTATION, &cfg->o);
  446. /* finger position */
  447. set_abs(input_dev, ABS_MT_POSITION_X, &cfg->x);
  448. set_abs(input_dev, ABS_MT_POSITION_Y, &cfg->y);
  449. __set_bit(EV_KEY, input_dev->evbit);
  450. __set_bit(BTN_LEFT, input_dev->keybit);
  451. if (cfg->caps & HAS_INTEGRATED_BUTTON)
  452. __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
  453. input_mt_init_slots(input_dev, MAX_FINGERS,
  454. INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK);
  455. }
  456. /* report button data as logical button state */
  457. static int report_bt_state(struct bcm5974 *dev, int size)
  458. {
  459. if (size != sizeof(struct bt_data))
  460. return -EIO;
  461. dprintk(7,
  462. "bcm5974: button data: %x %x %x %x\n",
  463. dev->bt_data->unknown1, dev->bt_data->button,
  464. dev->bt_data->rel_x, dev->bt_data->rel_y);
  465. input_report_key(dev->input, BTN_LEFT, dev->bt_data->button);
  466. input_sync(dev->input);
  467. return 0;
  468. }
  469. static void report_finger_data(struct input_dev *input, int slot,
  470. const struct input_mt_pos *pos,
  471. const struct tp_finger *f)
  472. {
  473. input_mt_slot(input, slot);
  474. input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
  475. input_report_abs(input, ABS_MT_TOUCH_MAJOR,
  476. raw2int(f->touch_major) << 1);
  477. input_report_abs(input, ABS_MT_TOUCH_MINOR,
  478. raw2int(f->touch_minor) << 1);
  479. input_report_abs(input, ABS_MT_WIDTH_MAJOR,
  480. raw2int(f->tool_major) << 1);
  481. input_report_abs(input, ABS_MT_WIDTH_MINOR,
  482. raw2int(f->tool_minor) << 1);
  483. input_report_abs(input, ABS_MT_ORIENTATION,
  484. MAX_FINGER_ORIENTATION - raw2int(f->orientation));
  485. input_report_abs(input, ABS_MT_POSITION_X, pos->x);
  486. input_report_abs(input, ABS_MT_POSITION_Y, pos->y);
  487. }
  488. static void report_synaptics_data(struct input_dev *input,
  489. const struct bcm5974_config *cfg,
  490. const struct tp_finger *f, int raw_n)
  491. {
  492. int abs_p = 0, abs_w = 0;
  493. if (raw_n) {
  494. int p = raw2int(f->touch_major);
  495. int w = raw2int(f->tool_major);
  496. if (p > 0 && raw2int(f->origin)) {
  497. abs_p = clamp_val(256 * p / cfg->p.max, 0, 255);
  498. abs_w = clamp_val(16 * w / cfg->w.max, 0, 15);
  499. }
  500. }
  501. input_report_abs(input, ABS_PRESSURE, abs_p);
  502. input_report_abs(input, ABS_TOOL_WIDTH, abs_w);
  503. }
  504. /* report trackpad data as logical trackpad state */
  505. static int report_tp_state(struct bcm5974 *dev, int size)
  506. {
  507. const struct bcm5974_config *c = &dev->cfg;
  508. const struct tp_finger *f;
  509. struct input_dev *input = dev->input;
  510. int raw_n, i, n = 0;
  511. if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0)
  512. return -EIO;
  513. /* finger data, le16-aligned */
  514. f = (const struct tp_finger *)(dev->tp_data + c->tp_offset);
  515. raw_n = (size - c->tp_offset) / SIZEOF_FINGER;
  516. for (i = 0; i < raw_n; i++) {
  517. if (raw2int(f[i].touch_major) == 0)
  518. continue;
  519. dev->pos[n].x = raw2int(f[i].abs_x);
  520. dev->pos[n].y = c->y.min + c->y.max - raw2int(f[i].abs_y);
  521. dev->index[n++] = &f[i];
  522. }
  523. input_mt_assign_slots(input, dev->slots, dev->pos, n);
  524. for (i = 0; i < n; i++)
  525. report_finger_data(input, dev->slots[i],
  526. &dev->pos[i], dev->index[i]);
  527. input_mt_sync_frame(input);
  528. report_synaptics_data(input, c, f, raw_n);
  529. /* type 2 reports button events via ibt only */
  530. if (c->tp_type == TYPE2) {
  531. int ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
  532. input_report_key(input, BTN_LEFT, ibt);
  533. }
  534. if (c->tp_type == TYPE3)
  535. input_report_key(input, BTN_LEFT, dev->tp_data[BUTTON_TYPE3]);
  536. input_sync(input);
  537. return 0;
  538. }
  539. /* Wellspring initialization constants */
  540. #define BCM5974_WELLSPRING_MODE_READ_REQUEST_ID 1
  541. #define BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID 9
  542. #define BCM5974_WELLSPRING_MODE_REQUEST_VALUE 0x300
  543. #define BCM5974_WELLSPRING_MODE_REQUEST_INDEX 0
  544. #define BCM5974_WELLSPRING_MODE_VENDOR_VALUE 0x01
  545. #define BCM5974_WELLSPRING_MODE_NORMAL_VALUE 0x08
  546. static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on)
  547. {
  548. int retval = 0, size;
  549. char *data;
  550. /* Type 3 does not require a mode switch */
  551. if (dev->cfg.tp_type == TYPE3)
  552. return 0;
  553. data = kmalloc(8, GFP_KERNEL);
  554. if (!data) {
  555. dev_err(&dev->intf->dev, "out of memory\n");
  556. retval = -ENOMEM;
  557. goto out;
  558. }
  559. /* read configuration */
  560. size = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
  561. BCM5974_WELLSPRING_MODE_READ_REQUEST_ID,
  562. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  563. BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
  564. BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
  565. if (size != 8) {
  566. dev_err(&dev->intf->dev, "could not read from device\n");
  567. retval = -EIO;
  568. goto out;
  569. }
  570. /* apply the mode switch */
  571. data[0] = on ?
  572. BCM5974_WELLSPRING_MODE_VENDOR_VALUE :
  573. BCM5974_WELLSPRING_MODE_NORMAL_VALUE;
  574. /* write configuration */
  575. size = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
  576. BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID,
  577. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  578. BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
  579. BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
  580. if (size != 8) {
  581. dev_err(&dev->intf->dev, "could not write to device\n");
  582. retval = -EIO;
  583. goto out;
  584. }
  585. dprintk(2, "bcm5974: switched to %s mode.\n",
  586. on ? "wellspring" : "normal");
  587. out:
  588. kfree(data);
  589. return retval;
  590. }
  591. static void bcm5974_irq_button(struct urb *urb)
  592. {
  593. struct bcm5974 *dev = urb->context;
  594. struct usb_interface *intf = dev->intf;
  595. int error;
  596. switch (urb->status) {
  597. case 0:
  598. break;
  599. case -EOVERFLOW:
  600. case -ECONNRESET:
  601. case -ENOENT:
  602. case -ESHUTDOWN:
  603. dev_dbg(&intf->dev, "button urb shutting down: %d\n",
  604. urb->status);
  605. return;
  606. default:
  607. dev_dbg(&intf->dev, "button urb status: %d\n", urb->status);
  608. goto exit;
  609. }
  610. if (report_bt_state(dev, dev->bt_urb->actual_length))
  611. dprintk(1, "bcm5974: bad button package, length: %d\n",
  612. dev->bt_urb->actual_length);
  613. exit:
  614. error = usb_submit_urb(dev->bt_urb, GFP_ATOMIC);
  615. if (error)
  616. dev_err(&intf->dev, "button urb failed: %d\n", error);
  617. }
  618. static void bcm5974_irq_trackpad(struct urb *urb)
  619. {
  620. struct bcm5974 *dev = urb->context;
  621. struct usb_interface *intf = dev->intf;
  622. int error;
  623. switch (urb->status) {
  624. case 0:
  625. break;
  626. case -EOVERFLOW:
  627. case -ECONNRESET:
  628. case -ENOENT:
  629. case -ESHUTDOWN:
  630. dev_dbg(&intf->dev, "trackpad urb shutting down: %d\n",
  631. urb->status);
  632. return;
  633. default:
  634. dev_dbg(&intf->dev, "trackpad urb status: %d\n", urb->status);
  635. goto exit;
  636. }
  637. /* control response ignored */
  638. if (dev->tp_urb->actual_length == 2)
  639. goto exit;
  640. if (report_tp_state(dev, dev->tp_urb->actual_length))
  641. dprintk(1, "bcm5974: bad trackpad package, length: %d\n",
  642. dev->tp_urb->actual_length);
  643. exit:
  644. error = usb_submit_urb(dev->tp_urb, GFP_ATOMIC);
  645. if (error)
  646. dev_err(&intf->dev, "trackpad urb failed: %d\n", error);
  647. }
  648. /*
  649. * The Wellspring trackpad, like many recent Apple trackpads, share
  650. * the usb device with the keyboard. Since keyboards are usually
  651. * handled by the HID system, the device ends up being handled by two
  652. * modules. Setting up the device therefore becomes slightly
  653. * complicated. To enable multitouch features, a mode switch is
  654. * required, which is usually applied via the control interface of the
  655. * device. It can be argued where this switch should take place. In
  656. * some drivers, like appletouch, the switch is made during
  657. * probe. However, the hid module may also alter the state of the
  658. * device, resulting in trackpad malfunction under certain
  659. * circumstances. To get around this problem, there is at least one
  660. * example that utilizes the USB_QUIRK_RESET_RESUME quirk in order to
  661. * receive a reset_resume request rather than the normal resume.
  662. * Since the implementation of reset_resume is equal to mode switch
  663. * plus start_traffic, it seems easier to always do the switch when
  664. * starting traffic on the device.
  665. */
  666. static int bcm5974_start_traffic(struct bcm5974 *dev)
  667. {
  668. int error;
  669. error = bcm5974_wellspring_mode(dev, true);
  670. if (error) {
  671. dprintk(1, "bcm5974: mode switch failed\n");
  672. goto err_out;
  673. }
  674. if (dev->bt_urb) {
  675. error = usb_submit_urb(dev->bt_urb, GFP_KERNEL);
  676. if (error)
  677. goto err_reset_mode;
  678. }
  679. error = usb_submit_urb(dev->tp_urb, GFP_KERNEL);
  680. if (error)
  681. goto err_kill_bt;
  682. return 0;
  683. err_kill_bt:
  684. usb_kill_urb(dev->bt_urb);
  685. err_reset_mode:
  686. bcm5974_wellspring_mode(dev, false);
  687. err_out:
  688. return error;
  689. }
  690. static void bcm5974_pause_traffic(struct bcm5974 *dev)
  691. {
  692. usb_kill_urb(dev->tp_urb);
  693. usb_kill_urb(dev->bt_urb);
  694. bcm5974_wellspring_mode(dev, false);
  695. }
  696. /*
  697. * The code below implements open/close and manual suspend/resume.
  698. * All functions may be called in random order.
  699. *
  700. * Opening a suspended device fails with EACCES - permission denied.
  701. *
  702. * Failing a resume leaves the device resumed but closed.
  703. */
  704. static int bcm5974_open(struct input_dev *input)
  705. {
  706. struct bcm5974 *dev = input_get_drvdata(input);
  707. int error;
  708. error = usb_autopm_get_interface(dev->intf);
  709. if (error)
  710. return error;
  711. mutex_lock(&dev->pm_mutex);
  712. error = bcm5974_start_traffic(dev);
  713. if (!error)
  714. dev->opened = 1;
  715. mutex_unlock(&dev->pm_mutex);
  716. if (error)
  717. usb_autopm_put_interface(dev->intf);
  718. return error;
  719. }
  720. static void bcm5974_close(struct input_dev *input)
  721. {
  722. struct bcm5974 *dev = input_get_drvdata(input);
  723. mutex_lock(&dev->pm_mutex);
  724. bcm5974_pause_traffic(dev);
  725. dev->opened = 0;
  726. mutex_unlock(&dev->pm_mutex);
  727. usb_autopm_put_interface(dev->intf);
  728. }
  729. static int bcm5974_suspend(struct usb_interface *iface, pm_message_t message)
  730. {
  731. struct bcm5974 *dev = usb_get_intfdata(iface);
  732. mutex_lock(&dev->pm_mutex);
  733. if (dev->opened)
  734. bcm5974_pause_traffic(dev);
  735. mutex_unlock(&dev->pm_mutex);
  736. return 0;
  737. }
  738. static int bcm5974_resume(struct usb_interface *iface)
  739. {
  740. struct bcm5974 *dev = usb_get_intfdata(iface);
  741. int error = 0;
  742. mutex_lock(&dev->pm_mutex);
  743. if (dev->opened)
  744. error = bcm5974_start_traffic(dev);
  745. mutex_unlock(&dev->pm_mutex);
  746. return error;
  747. }
  748. static int bcm5974_probe(struct usb_interface *iface,
  749. const struct usb_device_id *id)
  750. {
  751. struct usb_device *udev = interface_to_usbdev(iface);
  752. const struct bcm5974_config *cfg;
  753. struct bcm5974 *dev;
  754. struct input_dev *input_dev;
  755. int error = -ENOMEM;
  756. /* find the product index */
  757. cfg = bcm5974_get_config(udev);
  758. /* allocate memory for our device state and initialize it */
  759. dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL);
  760. input_dev = input_allocate_device();
  761. if (!dev || !input_dev) {
  762. dev_err(&iface->dev, "out of memory\n");
  763. goto err_free_devs;
  764. }
  765. dev->udev = udev;
  766. dev->intf = iface;
  767. dev->input = input_dev;
  768. dev->cfg = *cfg;
  769. mutex_init(&dev->pm_mutex);
  770. /* setup urbs */
  771. if (cfg->tp_type == TYPE1) {
  772. dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL);
  773. if (!dev->bt_urb)
  774. goto err_free_devs;
  775. }
  776. dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL);
  777. if (!dev->tp_urb)
  778. goto err_free_bt_urb;
  779. if (dev->bt_urb) {
  780. dev->bt_data = usb_alloc_coherent(dev->udev,
  781. dev->cfg.bt_datalen, GFP_KERNEL,
  782. &dev->bt_urb->transfer_dma);
  783. if (!dev->bt_data)
  784. goto err_free_urb;
  785. }
  786. dev->tp_data = usb_alloc_coherent(dev->udev,
  787. dev->cfg.tp_datalen, GFP_KERNEL,
  788. &dev->tp_urb->transfer_dma);
  789. if (!dev->tp_data)
  790. goto err_free_bt_buffer;
  791. if (dev->bt_urb)
  792. usb_fill_int_urb(dev->bt_urb, udev,
  793. usb_rcvintpipe(udev, cfg->bt_ep),
  794. dev->bt_data, dev->cfg.bt_datalen,
  795. bcm5974_irq_button, dev, 1);
  796. usb_fill_int_urb(dev->tp_urb, udev,
  797. usb_rcvintpipe(udev, cfg->tp_ep),
  798. dev->tp_data, dev->cfg.tp_datalen,
  799. bcm5974_irq_trackpad, dev, 1);
  800. /* create bcm5974 device */
  801. usb_make_path(udev, dev->phys, sizeof(dev->phys));
  802. strlcat(dev->phys, "/input0", sizeof(dev->phys));
  803. input_dev->name = "bcm5974";
  804. input_dev->phys = dev->phys;
  805. usb_to_input_id(dev->udev, &input_dev->id);
  806. /* report driver capabilities via the version field */
  807. input_dev->id.version = cfg->caps;
  808. input_dev->dev.parent = &iface->dev;
  809. input_set_drvdata(input_dev, dev);
  810. input_dev->open = bcm5974_open;
  811. input_dev->close = bcm5974_close;
  812. setup_events_to_report(input_dev, cfg);
  813. error = input_register_device(dev->input);
  814. if (error)
  815. goto err_free_buffer;
  816. /* save our data pointer in this interface device */
  817. usb_set_intfdata(iface, dev);
  818. return 0;
  819. err_free_buffer:
  820. usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
  821. dev->tp_data, dev->tp_urb->transfer_dma);
  822. err_free_bt_buffer:
  823. if (dev->bt_urb)
  824. usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
  825. dev->bt_data, dev->bt_urb->transfer_dma);
  826. err_free_urb:
  827. usb_free_urb(dev->tp_urb);
  828. err_free_bt_urb:
  829. usb_free_urb(dev->bt_urb);
  830. err_free_devs:
  831. usb_set_intfdata(iface, NULL);
  832. input_free_device(input_dev);
  833. kfree(dev);
  834. return error;
  835. }
  836. static void bcm5974_disconnect(struct usb_interface *iface)
  837. {
  838. struct bcm5974 *dev = usb_get_intfdata(iface);
  839. usb_set_intfdata(iface, NULL);
  840. input_unregister_device(dev->input);
  841. usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
  842. dev->tp_data, dev->tp_urb->transfer_dma);
  843. if (dev->bt_urb)
  844. usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
  845. dev->bt_data, dev->bt_urb->transfer_dma);
  846. usb_free_urb(dev->tp_urb);
  847. usb_free_urb(dev->bt_urb);
  848. kfree(dev);
  849. }
  850. static struct usb_driver bcm5974_driver = {
  851. .name = "bcm5974",
  852. .probe = bcm5974_probe,
  853. .disconnect = bcm5974_disconnect,
  854. .suspend = bcm5974_suspend,
  855. .resume = bcm5974_resume,
  856. .id_table = bcm5974_table,
  857. .supports_autosuspend = 1,
  858. };
  859. module_usb_driver(bcm5974_driver);