appletouch.c 18 KB

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