appletouch.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
  3. *
  4. * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
  5. * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net)
  6. * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
  7. * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
  8. * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
  9. * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
  10. * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
  11. *
  12. * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. */
  29. #include <linux/config.h>
  30. #include <linux/kernel.h>
  31. #include <linux/errno.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/module.h>
  35. #include <linux/usb.h>
  36. #include <linux/input.h>
  37. #include <linux/usb_input.h>
  38. /* Apple has powerbooks which have the keyboard with different Product IDs */
  39. #define APPLE_VENDOR_ID 0x05AC
  40. /* These names come from Info.plist in AppleUSBTrackpad.kext */
  41. #define GEYSER_ANSI_PRODUCT_ID 0x0214
  42. #define GEYSER_ISO_PRODUCT_ID 0x0215
  43. #define GEYSER_JIS_PRODUCT_ID 0x0216
  44. /* MacBook devices */
  45. #define GEYSER3_ANSI_PRODUCT_ID 0x0217
  46. #define GEYSER3_ISO_PRODUCT_ID 0x0218
  47. #define GEYSER3_JIS_PRODUCT_ID 0x0219
  48. #define ATP_DEVICE(prod) \
  49. .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
  50. USB_DEVICE_ID_MATCH_INT_CLASS | \
  51. USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
  52. .idVendor = APPLE_VENDOR_ID, \
  53. .idProduct = (prod), \
  54. .bInterfaceClass = 0x03, \
  55. .bInterfaceProtocol = 0x02
  56. /* table of devices that work with this driver */
  57. static struct usb_device_id atp_table [] = {
  58. { ATP_DEVICE(0x020E) },
  59. { ATP_DEVICE(0x020F) },
  60. { ATP_DEVICE(0x030A) },
  61. { ATP_DEVICE(0x030B) },
  62. /* PowerBooks Oct 2005 */
  63. { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) },
  64. { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) },
  65. { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) },
  66. { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) },
  67. { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) },
  68. { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) },
  69. /* Terminating entry */
  70. { }
  71. };
  72. MODULE_DEVICE_TABLE (usb, atp_table);
  73. /*
  74. * number of sensors. Note that only 16 instead of 26 X (horizontal)
  75. * sensors exist on 12" and 15" PowerBooks. All models have 16 Y
  76. * (vertical) sensors.
  77. */
  78. #define ATP_XSENSORS 26
  79. #define ATP_YSENSORS 16
  80. /* amount of fuzz this touchpad generates */
  81. #define ATP_FUZZ 16
  82. /* maximum pressure this driver will report */
  83. #define ATP_PRESSURE 300
  84. /*
  85. * multiplication factor for the X and Y coordinates.
  86. * We try to keep the touchpad aspect ratio while still doing only simple
  87. * arithmetics.
  88. * The factors below give coordinates like:
  89. * 0 <= x < 960 on 12" and 15" Powerbooks
  90. * 0 <= x < 1600 on 17" Powerbooks
  91. * 0 <= y < 646
  92. */
  93. #define ATP_XFACT 64
  94. #define ATP_YFACT 43
  95. /*
  96. * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is
  97. * ignored.
  98. */
  99. #define ATP_THRESHOLD 5
  100. /* MacBook Pro (Geyser 3) initialization constants */
  101. #define ATP_GEYSER3_MODE_READ_REQUEST_ID 1
  102. #define ATP_GEYSER3_MODE_WRITE_REQUEST_ID 9
  103. #define ATP_GEYSER3_MODE_REQUEST_VALUE 0x300
  104. #define ATP_GEYSER3_MODE_REQUEST_INDEX 0
  105. #define ATP_GEYSER3_MODE_VENDOR_VALUE 0x04
  106. /* Structure to hold all of our device specific stuff */
  107. struct atp {
  108. char phys[64];
  109. struct usb_device * udev; /* usb device */
  110. struct urb * urb; /* usb request block */
  111. signed char * data; /* transferred data */
  112. int open; /* non-zero if opened */
  113. struct input_dev *input; /* input dev */
  114. int valid; /* are the sensors valid ? */
  115. int x_old; /* last reported x/y, */
  116. int y_old; /* used for smoothing */
  117. /* current value of the sensors */
  118. signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
  119. /* last value of the sensors */
  120. signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
  121. /* accumulated sensors */
  122. int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
  123. int overflowwarn; /* overflow warning printed? */
  124. int datalen; /* size of an USB urb transfer */
  125. };
  126. #define dbg_dump(msg, tab) \
  127. if (debug > 1) { \
  128. int i; \
  129. printk("appletouch: %s %lld", msg, (long long)jiffies); \
  130. for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \
  131. printk(" %02x", tab[i]); \
  132. printk("\n"); \
  133. }
  134. #define dprintk(format, a...) \
  135. do { \
  136. if (debug) printk(format, ##a); \
  137. } while (0)
  138. MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Michael Hanselmann");
  139. MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver");
  140. MODULE_LICENSE("GPL");
  141. static int debug = 1;
  142. module_param(debug, int, 0644);
  143. MODULE_PARM_DESC(debug, "Activate debugging output");
  144. /* Checks if the device a Geyser 2 (ANSI, ISO, JIS) */
  145. static inline int atp_is_geyser_2(struct atp *dev)
  146. {
  147. u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
  148. return (productId == GEYSER_ANSI_PRODUCT_ID) ||
  149. (productId == GEYSER_ISO_PRODUCT_ID) ||
  150. (productId == GEYSER_JIS_PRODUCT_ID);
  151. }
  152. static inline int atp_is_geyser_3(struct atp *dev)
  153. {
  154. u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
  155. return (productId == GEYSER3_ANSI_PRODUCT_ID) ||
  156. (productId == GEYSER3_ISO_PRODUCT_ID) ||
  157. (productId == GEYSER3_JIS_PRODUCT_ID);
  158. }
  159. static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
  160. int *z, int *fingers)
  161. {
  162. int i;
  163. /* values to calculate mean */
  164. int pcum = 0, psum = 0;
  165. *fingers = 0;
  166. for (i = 0; i < nb_sensors; i++) {
  167. if (xy_sensors[i] < ATP_THRESHOLD)
  168. continue;
  169. if ((i - 1 < 0) || (xy_sensors[i - 1] < ATP_THRESHOLD))
  170. (*fingers)++;
  171. pcum += xy_sensors[i] * i;
  172. psum += xy_sensors[i];
  173. }
  174. if (psum > 0) {
  175. *z = psum;
  176. return pcum * fact / psum;
  177. }
  178. return 0;
  179. }
  180. static inline void atp_report_fingers(struct input_dev *input, int fingers)
  181. {
  182. input_report_key(input, BTN_TOOL_FINGER, fingers == 1);
  183. input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2);
  184. input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
  185. }
  186. static void atp_complete(struct urb* urb, struct pt_regs* regs)
  187. {
  188. int x, y, x_z, y_z, x_f, y_f;
  189. int retval, i, j;
  190. struct atp *dev = urb->context;
  191. switch (urb->status) {
  192. case 0:
  193. /* success */
  194. break;
  195. case -EOVERFLOW:
  196. if(!dev->overflowwarn) {
  197. printk("appletouch: OVERFLOW with data "
  198. "length %d, actual length is %d\n",
  199. dev->datalen, dev->urb->actual_length);
  200. dev->overflowwarn = 1;
  201. }
  202. case -ECONNRESET:
  203. case -ENOENT:
  204. case -ESHUTDOWN:
  205. /* This urb is terminated, clean up */
  206. dbg("%s - urb shutting down with status: %d",
  207. __FUNCTION__, urb->status);
  208. return;
  209. default:
  210. dbg("%s - nonzero urb status received: %d",
  211. __FUNCTION__, urb->status);
  212. goto exit;
  213. }
  214. /* drop incomplete datasets */
  215. if (dev->urb->actual_length != dev->datalen) {
  216. dprintk("appletouch: incomplete data package"
  217. " (first byte: %d, length: %d).\n",
  218. dev->data[0], dev->urb->actual_length);
  219. goto exit;
  220. }
  221. /* reorder the sensors values */
  222. if (atp_is_geyser_3(dev)) {
  223. memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
  224. /*
  225. * The values are laid out like this:
  226. * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ...
  227. * '-' is an unused value.
  228. */
  229. /* read X values */
  230. for (i = 0, j = 19; i < 20; i += 2, j += 3) {
  231. dev->xy_cur[i] = dev->data[j + 1];
  232. dev->xy_cur[i + 1] = dev->data[j + 2];
  233. }
  234. /* read Y values */
  235. for (i = 0, j = 1; i < 9; i += 2, j += 3) {
  236. dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
  237. dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
  238. }
  239. } else if (atp_is_geyser_2(dev)) {
  240. memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
  241. /*
  242. * The values are laid out like this:
  243. * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ...
  244. * '-' is an unused value.
  245. */
  246. /* read X values */
  247. for (i = 0, j = 19; i < 20; i += 2, j += 3) {
  248. dev->xy_cur[i] = dev->data[j];
  249. dev->xy_cur[i + 1] = dev->data[j + 1];
  250. }
  251. /* read Y values */
  252. for (i = 0, j = 1; i < 9; i += 2, j += 3) {
  253. dev->xy_cur[ATP_XSENSORS + i] = dev->data[j];
  254. dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1];
  255. }
  256. } else {
  257. for (i = 0; i < 8; i++) {
  258. /* X values */
  259. dev->xy_cur[i ] = dev->data[5 * i + 2];
  260. dev->xy_cur[i + 8] = dev->data[5 * i + 4];
  261. dev->xy_cur[i + 16] = dev->data[5 * i + 42];
  262. if (i < 2)
  263. dev->xy_cur[i + 24] = dev->data[5 * i + 44];
  264. /* Y values */
  265. dev->xy_cur[i + 26] = dev->data[5 * i + 1];
  266. dev->xy_cur[i + 34] = dev->data[5 * i + 3];
  267. }
  268. }
  269. dbg_dump("sample", dev->xy_cur);
  270. if (!dev->valid) {
  271. /* first sample */
  272. dev->valid = 1;
  273. dev->x_old = dev->y_old = -1;
  274. memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
  275. if (atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */
  276. goto exit;
  277. /* 17" Powerbooks have extra X sensors */
  278. for (i = (atp_is_geyser_2(dev)?15:16); i < ATP_XSENSORS; i++) {
  279. if (!dev->xy_cur[i]) continue;
  280. printk("appletouch: 17\" model detected.\n");
  281. if(atp_is_geyser_2(dev))
  282. input_set_abs_params(dev->input, ABS_X, 0,
  283. (20 - 1) *
  284. ATP_XFACT - 1,
  285. ATP_FUZZ, 0);
  286. else
  287. input_set_abs_params(dev->input, ABS_X, 0,
  288. (ATP_XSENSORS - 1) *
  289. ATP_XFACT - 1,
  290. ATP_FUZZ, 0);
  291. break;
  292. }
  293. goto exit;
  294. }
  295. for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
  296. /* accumulate the change */
  297. signed char change = dev->xy_old[i] - dev->xy_cur[i];
  298. dev->xy_acc[i] -= change;
  299. /* prevent down drifting */
  300. if (dev->xy_acc[i] < 0)
  301. dev->xy_acc[i] = 0;
  302. }
  303. memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
  304. dbg_dump("accumulator", dev->xy_acc);
  305. x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS,
  306. ATP_XFACT, &x_z, &x_f);
  307. y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
  308. ATP_YFACT, &y_z, &y_f);
  309. if (x && y) {
  310. if (dev->x_old != -1) {
  311. x = (dev->x_old * 3 + x) >> 2;
  312. y = (dev->y_old * 3 + y) >> 2;
  313. dev->x_old = x;
  314. dev->y_old = y;
  315. if (debug > 1)
  316. printk("appletouch: X: %3d Y: %3d "
  317. "Xz: %3d Yz: %3d\n",
  318. x, y, x_z, y_z);
  319. input_report_key(dev->input, BTN_TOUCH, 1);
  320. input_report_abs(dev->input, ABS_X, x);
  321. input_report_abs(dev->input, ABS_Y, y);
  322. input_report_abs(dev->input, ABS_PRESSURE,
  323. min(ATP_PRESSURE, x_z + y_z));
  324. atp_report_fingers(dev->input, max(x_f, y_f));
  325. }
  326. dev->x_old = x;
  327. dev->y_old = y;
  328. }
  329. else if (!x && !y) {
  330. dev->x_old = dev->y_old = -1;
  331. input_report_key(dev->input, BTN_TOUCH, 0);
  332. input_report_abs(dev->input, ABS_PRESSURE, 0);
  333. atp_report_fingers(dev->input, 0);
  334. /* reset the accumulator on release */
  335. memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
  336. }
  337. input_report_key(dev->input, BTN_LEFT,
  338. !!dev->data[dev->datalen - 1]);
  339. input_sync(dev->input);
  340. exit:
  341. retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
  342. if (retval) {
  343. err("%s - usb_submit_urb failed with result %d",
  344. __FUNCTION__, retval);
  345. }
  346. }
  347. static int atp_open(struct input_dev *input)
  348. {
  349. struct atp *dev = input->private;
  350. if (usb_submit_urb(dev->urb, GFP_ATOMIC))
  351. return -EIO;
  352. dev->open = 1;
  353. return 0;
  354. }
  355. static void atp_close(struct input_dev *input)
  356. {
  357. struct atp *dev = input->private;
  358. usb_kill_urb(dev->urb);
  359. dev->open = 0;
  360. }
  361. static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id)
  362. {
  363. struct atp *dev;
  364. struct input_dev *input_dev;
  365. struct usb_device *udev = interface_to_usbdev(iface);
  366. struct usb_host_interface *iface_desc;
  367. struct usb_endpoint_descriptor *endpoint;
  368. int int_in_endpointAddr = 0;
  369. int i, retval = -ENOMEM;
  370. /* set up the endpoint information */
  371. /* use only the first interrupt-in endpoint */
  372. iface_desc = iface->cur_altsetting;
  373. for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
  374. endpoint = &iface_desc->endpoint[i].desc;
  375. if (!int_in_endpointAddr &&
  376. (endpoint->bEndpointAddress & USB_DIR_IN) &&
  377. ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  378. == USB_ENDPOINT_XFER_INT)) {
  379. /* we found an interrupt in endpoint */
  380. int_in_endpointAddr = endpoint->bEndpointAddress;
  381. break;
  382. }
  383. }
  384. if (!int_in_endpointAddr) {
  385. err("Could not find int-in endpoint");
  386. return -EIO;
  387. }
  388. /* allocate memory for our device state and initialize it */
  389. dev = kzalloc(sizeof(struct atp), GFP_KERNEL);
  390. input_dev = input_allocate_device();
  391. if (!dev || !input_dev) {
  392. err("Out of memory");
  393. goto err_free_devs;
  394. }
  395. dev->udev = udev;
  396. dev->input = input_dev;
  397. dev->overflowwarn = 0;
  398. if (atp_is_geyser_3(dev))
  399. dev->datalen = 64;
  400. else if (atp_is_geyser_2(dev))
  401. dev->datalen = 64;
  402. else
  403. dev->datalen = 81;
  404. if (atp_is_geyser_3(dev)) {
  405. /*
  406. * By default Geyser 3 device sends standard USB HID mouse
  407. * packets (Report ID 2). This code changes device mode, so it
  408. * sends raw sensor reports (Report ID 5).
  409. */
  410. char data[8];
  411. int size;
  412. size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
  413. ATP_GEYSER3_MODE_READ_REQUEST_ID,
  414. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  415. ATP_GEYSER3_MODE_REQUEST_VALUE,
  416. ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
  417. if (size != 8) {
  418. err("Could not do mode read request from device"
  419. " (Geyser 3 mode)");
  420. goto err_free_devs;
  421. }
  422. /* Apply the mode switch */
  423. data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE;
  424. size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
  425. ATP_GEYSER3_MODE_WRITE_REQUEST_ID,
  426. USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  427. ATP_GEYSER3_MODE_REQUEST_VALUE,
  428. ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
  429. if (size != 8) {
  430. err("Could not do mode write request to device"
  431. " (Geyser 3 mode)");
  432. goto err_free_devs;
  433. }
  434. printk("appletouch Geyser 3 inited.\n");
  435. }
  436. dev->urb = usb_alloc_urb(0, GFP_KERNEL);
  437. if (!dev->urb) {
  438. retval = -ENOMEM;
  439. goto err_free_devs;
  440. }
  441. dev->data = usb_buffer_alloc(dev->udev, dev->datalen, GFP_KERNEL,
  442. &dev->urb->transfer_dma);
  443. if (!dev->data) {
  444. retval = -ENOMEM;
  445. goto err_free_urb;
  446. }
  447. usb_fill_int_urb(dev->urb, udev,
  448. usb_rcvintpipe(udev, int_in_endpointAddr),
  449. dev->data, dev->datalen, atp_complete, dev, 1);
  450. usb_make_path(udev, dev->phys, sizeof(dev->phys));
  451. strlcat(dev->phys, "/input0", sizeof(dev->phys));
  452. input_dev->name = "appletouch";
  453. input_dev->phys = dev->phys;
  454. usb_to_input_id(dev->udev, &input_dev->id);
  455. input_dev->cdev.dev = &iface->dev;
  456. input_dev->private = dev;
  457. input_dev->open = atp_open;
  458. input_dev->close = atp_close;
  459. set_bit(EV_ABS, input_dev->evbit);
  460. if (atp_is_geyser_3(dev)) {
  461. /*
  462. * MacBook have 20 X sensors, 10 Y sensors
  463. */
  464. input_set_abs_params(input_dev, ABS_X, 0,
  465. ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
  466. input_set_abs_params(input_dev, ABS_Y, 0,
  467. ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
  468. } else if (atp_is_geyser_2(dev)) {
  469. /*
  470. * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected
  471. * later.
  472. */
  473. input_set_abs_params(input_dev, ABS_X, 0,
  474. ((15 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
  475. input_set_abs_params(input_dev, ABS_Y, 0,
  476. ((9 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
  477. } else {
  478. /*
  479. * 12" and 15" Powerbooks only have 16 x sensors,
  480. * 17" models are detected later.
  481. */
  482. input_set_abs_params(input_dev, ABS_X, 0,
  483. (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0);
  484. input_set_abs_params(input_dev, ABS_Y, 0,
  485. (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0);
  486. }
  487. input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
  488. set_bit(EV_KEY, input_dev->evbit);
  489. set_bit(BTN_TOUCH, input_dev->keybit);
  490. set_bit(BTN_TOOL_FINGER, input_dev->keybit);
  491. set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
  492. set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
  493. set_bit(BTN_LEFT, input_dev->keybit);
  494. input_register_device(dev->input);
  495. /* save our data pointer in this interface device */
  496. usb_set_intfdata(iface, dev);
  497. return 0;
  498. err_free_urb:
  499. usb_free_urb(dev->urb);
  500. err_free_devs:
  501. usb_set_intfdata(iface, NULL);
  502. kfree(dev);
  503. input_free_device(input_dev);
  504. return retval;
  505. }
  506. static void atp_disconnect(struct usb_interface *iface)
  507. {
  508. struct atp *dev = usb_get_intfdata(iface);
  509. usb_set_intfdata(iface, NULL);
  510. if (dev) {
  511. usb_kill_urb(dev->urb);
  512. input_unregister_device(dev->input);
  513. usb_free_urb(dev->urb);
  514. usb_buffer_free(dev->udev, dev->datalen,
  515. dev->data, dev->urb->transfer_dma);
  516. kfree(dev);
  517. }
  518. printk(KERN_INFO "input: appletouch disconnected\n");
  519. }
  520. static int atp_suspend(struct usb_interface *iface, pm_message_t message)
  521. {
  522. struct atp *dev = usb_get_intfdata(iface);
  523. usb_kill_urb(dev->urb);
  524. dev->valid = 0;
  525. return 0;
  526. }
  527. static int atp_resume(struct usb_interface *iface)
  528. {
  529. struct atp *dev = usb_get_intfdata(iface);
  530. if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
  531. return -EIO;
  532. return 0;
  533. }
  534. static struct usb_driver atp_driver = {
  535. .name = "appletouch",
  536. .probe = atp_probe,
  537. .disconnect = atp_disconnect,
  538. .suspend = atp_suspend,
  539. .resume = atp_resume,
  540. .id_table = atp_table,
  541. };
  542. static int __init atp_init(void)
  543. {
  544. return usb_register(&atp_driver);
  545. }
  546. static void __exit atp_exit(void)
  547. {
  548. usb_deregister(&atp_driver);
  549. }
  550. module_init(atp_init);
  551. module_exit(atp_exit);