bcm5974.c 31 KB

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