appletouch.c 17 KB

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