bcm5974.c 30 KB

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