blob: 814e90459b3b8848db8d4001a15ea0626b4a5ddc [file] [log] [blame]
Stelian Popf7214ff2005-09-08 10:19:48 +02001/*
Nicolas Boichat9effa972006-04-19 23:36:40 +02002 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
Stelian Popf7214ff2005-09-08 10:19:48 +02003 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
Johannes Berg7dce8692008-05-05 23:56:55 -04005 * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net)
Stelian Popf7214ff2005-09-08 10:19:48 +02006 * 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)
Michael Hanselmanne1e02c92005-12-21 00:50:23 -05009 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
Nicolas Boichat9effa972006-04-19 23:36:40 +020010 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
Johannes Berg7dce8692008-05-05 23:56:55 -040011 * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de)
Stelian Popf7214ff2005-09-08 10:19:48 +020012 *
13 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
30
Stelian Popf7214ff2005-09-08 10:19:48 +020031#include <linux/kernel.h>
32#include <linux/errno.h>
33#include <linux/init.h>
34#include <linux/slab.h>
35#include <linux/module.h>
David Brownellae0dadc2006-06-13 10:04:34 -070036#include <linux/usb/input.h>
Stelian Popf7214ff2005-09-08 10:19:48 +020037
38/* Apple has powerbooks which have the keyboard with different Product IDs */
39#define APPLE_VENDOR_ID 0x05AC
40
Michael Hanselmanne1e02c92005-12-21 00:50:23 -050041/* These names come from Info.plist in AppleUSBTrackpad.kext */
Johannes Berg7dce8692008-05-05 23:56:55 -040042
43/* PowerBooks Feb 2005 / iBooks */
Julien BLACHEe5d98322006-11-17 01:06:25 -050044#define FOUNTAIN_ANSI_PRODUCT_ID 0x020E
45#define FOUNTAIN_ISO_PRODUCT_ID 0x020F
46
47#define FOUNTAIN_TP_ONLY_PRODUCT_ID 0x030A
48
49#define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B
50
Johannes Berg7dce8692008-05-05 23:56:55 -040051/* PowerBooks Oct 2005 */
52#define GEYSER2_ANSI_PRODUCT_ID 0x0214
53#define GEYSER2_ISO_PRODUCT_ID 0x0215
54#define GEYSER2_JIS_PRODUCT_ID 0x0216
Michael Hanselmanne1e02c92005-12-21 00:50:23 -050055
Nicolas Boichat9effa972006-04-19 23:36:40 +020056/* MacBook devices */
Julien BLACHEe5d98322006-11-17 01:06:25 -050057#define GEYSER3_ANSI_PRODUCT_ID 0x0217
58#define GEYSER3_ISO_PRODUCT_ID 0x0218
59#define GEYSER3_JIS_PRODUCT_ID 0x0219
Nicolas Boichat9effa972006-04-19 23:36:40 +020060
Julien BLACHE009ad0e2006-11-17 01:06:13 -050061/*
Johannes Berg7dce8692008-05-05 23:56:55 -040062 * Geyser IV: same as Geyser III according to Info.plist in OSX's
63 * AppleUSBTrackpad.kext
Julien BLACHE009ad0e2006-11-17 01:06:13 -050064 * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables
65 */
Johannes Berg7dce8692008-05-05 23:56:55 -040066#define GEYSER4_ANSI_PRODUCT_ID 0x021A
67#define GEYSER4_ISO_PRODUCT_ID 0x021B
68#define GEYSER4_JIS_PRODUCT_ID 0x021C
Julien BLACHE009ad0e2006-11-17 01:06:13 -050069
Johannes Berg7dce8692008-05-05 23:56:55 -040070/* Macbook3,1 devices */
Tobias Mueller0035a1d2008-04-02 10:02:06 -040071#define GEYSER4_HF_ANSI_PRODUCT_ID 0x0229
72#define GEYSER4_HF_ISO_PRODUCT_ID 0x022A
73#define GEYSER4_HF_JIS_PRODUCT_ID 0x022B
74
Stelian Popf7214ff2005-09-08 10:19:48 +020075#define ATP_DEVICE(prod) \
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -050076 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
Stelian Popf7214ff2005-09-08 10:19:48 +020077 USB_DEVICE_ID_MATCH_INT_CLASS | \
78 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
79 .idVendor = APPLE_VENDOR_ID, \
80 .idProduct = (prod), \
81 .bInterfaceClass = 0x03, \
82 .bInterfaceProtocol = 0x02
83
84/* table of devices that work with this driver */
85static struct usb_device_id atp_table [] = {
Johannes Berg7dce8692008-05-05 23:56:55 -040086 /* PowerBooks Feb 2005, iBooks G4 */
Julien BLACHEe5d98322006-11-17 01:06:25 -050087 { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) },
88 { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) },
89 { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) },
90 { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) },
Michael Hanselmanne1e02c92005-12-21 00:50:23 -050091
92 /* PowerBooks Oct 2005 */
Johannes Berg7dce8692008-05-05 23:56:55 -040093 { ATP_DEVICE(GEYSER2_ANSI_PRODUCT_ID) },
94 { ATP_DEVICE(GEYSER2_ISO_PRODUCT_ID) },
95 { ATP_DEVICE(GEYSER2_JIS_PRODUCT_ID) },
Michael Hanselmanne1e02c92005-12-21 00:50:23 -050096
Julien BLACHE009ad0e2006-11-17 01:06:13 -050097 /* Core Duo MacBook & MacBook Pro */
Nicolas Boichat9effa972006-04-19 23:36:40 +020098 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) },
99 { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) },
100 { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) },
101
Julien BLACHE009ad0e2006-11-17 01:06:13 -0500102 /* Core2 Duo MacBook & MacBook Pro */
103 { ATP_DEVICE(GEYSER4_ANSI_PRODUCT_ID) },
104 { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) },
105 { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) },
106
Johannes Berg7dce8692008-05-05 23:56:55 -0400107 /* Core2 Duo MacBook3,1 */
Tobias Mueller0035a1d2008-04-02 10:02:06 -0400108 { ATP_DEVICE(GEYSER4_HF_ANSI_PRODUCT_ID) },
109 { ATP_DEVICE(GEYSER4_HF_ISO_PRODUCT_ID) },
110 { ATP_DEVICE(GEYSER4_HF_JIS_PRODUCT_ID) },
111
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500112 /* Terminating entry */
113 { }
Stelian Popf7214ff2005-09-08 10:19:48 +0200114};
Johannes Berg7dce8692008-05-05 23:56:55 -0400115MODULE_DEVICE_TABLE(usb, atp_table);
Stelian Popf7214ff2005-09-08 10:19:48 +0200116
Stelian Popf7214ff2005-09-08 10:19:48 +0200117/*
118 * number of sensors. Note that only 16 instead of 26 X (horizontal)
119 * sensors exist on 12" and 15" PowerBooks. All models have 16 Y
120 * (vertical) sensors.
121 */
122#define ATP_XSENSORS 26
123#define ATP_YSENSORS 16
124
125/* amount of fuzz this touchpad generates */
126#define ATP_FUZZ 16
127
128/* maximum pressure this driver will report */
129#define ATP_PRESSURE 300
130/*
131 * multiplication factor for the X and Y coordinates.
132 * We try to keep the touchpad aspect ratio while still doing only simple
133 * arithmetics.
134 * The factors below give coordinates like:
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500135 * 0 <= x < 960 on 12" and 15" Powerbooks
136 * 0 <= x < 1600 on 17" Powerbooks
137 * 0 <= y < 646
Stelian Popf7214ff2005-09-08 10:19:48 +0200138 */
139#define ATP_XFACT 64
140#define ATP_YFACT 43
141
142/*
143 * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is
144 * ignored.
145 */
146#define ATP_THRESHOLD 5
147
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400148/* Geyser initialization constants */
149#define ATP_GEYSER_MODE_READ_REQUEST_ID 1
150#define ATP_GEYSER_MODE_WRITE_REQUEST_ID 9
151#define ATP_GEYSER_MODE_REQUEST_VALUE 0x300
152#define ATP_GEYSER_MODE_REQUEST_INDEX 0
153#define ATP_GEYSER_MODE_VENDOR_VALUE 0x04
Nicolas Boichat9effa972006-04-19 23:36:40 +0200154
Stelian Popf7214ff2005-09-08 10:19:48 +0200155/* Structure to hold all of our device specific stuff */
156struct atp {
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500157 char phys[64];
Johannes Berg7dce8692008-05-05 23:56:55 -0400158 struct usb_device *udev; /* usb device */
159 struct urb *urb; /* usb request block */
160 signed char *data; /* transferred data */
161 struct input_dev *input; /* input dev */
162 bool open;
163 bool valid; /* are the samples valid? */
164 bool size_detect_done;
165 bool overflow_warned;
Stelian Popf7214ff2005-09-08 10:19:48 +0200166 int x_old; /* last reported x/y, */
167 int y_old; /* used for smoothing */
Stelian Popf7214ff2005-09-08 10:19:48 +0200168 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
Stelian Popf7214ff2005-09-08 10:19:48 +0200169 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
Stelian Popf7214ff2005-09-08 10:19:48 +0200170 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
Johannes Berg7dce8692008-05-05 23:56:55 -0400171 int datalen; /* size of USB transfer */
172 int idlecount; /* number of empty packets */
173 struct work_struct work;
Stelian Popf7214ff2005-09-08 10:19:48 +0200174};
175
176#define dbg_dump(msg, tab) \
177 if (debug > 1) { \
Johannes Berg7dce8692008-05-05 23:56:55 -0400178 int __i; \
179 printk(KERN_DEBUG "appletouch: %s", msg); \
180 for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \
181 printk(" %02x", tab[__i]); \
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500182 printk("\n"); \
Stelian Popf7214ff2005-09-08 10:19:48 +0200183 }
184
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500185#define dprintk(format, a...) \
Stelian Popf7214ff2005-09-08 10:19:48 +0200186 do { \
Johannes Berg7dce8692008-05-05 23:56:55 -0400187 if (debug) \
188 printk(KERN_DEBUG format, ##a); \
Stelian Popf7214ff2005-09-08 10:19:48 +0200189 } while (0)
190
Johannes Berg7dce8692008-05-05 23:56:55 -0400191MODULE_AUTHOR("Johannes Berg");
192MODULE_AUTHOR("Stelian Pop");
193MODULE_AUTHOR("Frank Arnold");
194MODULE_AUTHOR("Michael Hanselmann");
195MODULE_AUTHOR("Sven Anders");
196MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver");
Stelian Popf7214ff2005-09-08 10:19:48 +0200197MODULE_LICENSE("GPL");
198
Jason Parekh00081d32006-11-17 01:05:58 -0500199/*
200 * Make the threshold a module parameter
201 */
202static int threshold = ATP_THRESHOLD;
203module_param(threshold, int, 0644);
Johannes Berg7dce8692008-05-05 23:56:55 -0400204MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor"
205 " (the trackpad has many of these sensors)"
206 " less than this value.");
Jason Parekh00081d32006-11-17 01:05:58 -0500207
Johannes Berg7dce8692008-05-05 23:56:55 -0400208static int debug;
Stelian Popf7214ff2005-09-08 10:19:48 +0200209module_param(debug, int, 0644);
210MODULE_PARM_DESC(debug, "Activate debugging output");
211
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400212static inline int atp_is_fountain(struct atp *dev)
213{
214 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
215
216 return productId == FOUNTAIN_ANSI_PRODUCT_ID ||
217 productId == FOUNTAIN_ISO_PRODUCT_ID ||
218 productId == FOUNTAIN_TP_ONLY_PRODUCT_ID;
219}
220
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500221/* Checks if the device a Geyser 2 (ANSI, ISO, JIS) */
222static inline int atp_is_geyser_2(struct atp *dev)
223{
Nicolas Boichat9effa972006-04-19 23:36:40 +0200224 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500225
Johannes Berg7dce8692008-05-05 23:56:55 -0400226 return (productId == GEYSER2_ANSI_PRODUCT_ID) ||
227 (productId == GEYSER2_ISO_PRODUCT_ID) ||
228 (productId == GEYSER2_JIS_PRODUCT_ID);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500229}
230
Nicolas Boichat9effa972006-04-19 23:36:40 +0200231static inline int atp_is_geyser_3(struct atp *dev)
232{
233 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
234
235 return (productId == GEYSER3_ANSI_PRODUCT_ID) ||
236 (productId == GEYSER3_ISO_PRODUCT_ID) ||
Julien BLACHE009ad0e2006-11-17 01:06:13 -0500237 (productId == GEYSER3_JIS_PRODUCT_ID) ||
238 (productId == GEYSER4_ANSI_PRODUCT_ID) ||
239 (productId == GEYSER4_ISO_PRODUCT_ID) ||
Tobias Mueller0035a1d2008-04-02 10:02:06 -0400240 (productId == GEYSER4_JIS_PRODUCT_ID) ||
241 (productId == GEYSER4_HF_ANSI_PRODUCT_ID) ||
242 (productId == GEYSER4_HF_ISO_PRODUCT_ID) ||
243 (productId == GEYSER4_HF_JIS_PRODUCT_ID);
Nicolas Boichat9effa972006-04-19 23:36:40 +0200244}
245
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400246/*
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400247 * By default newer Geyser devices send standard USB HID mouse
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400248 * packets (Report ID 2). This code changes device mode, so it
249 * sends raw sensor reports (Report ID 5).
250 */
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400251static int atp_geyser_init(struct usb_device *udev)
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400252{
253 char data[8];
254 int size;
Johannes Berg7dce8692008-05-05 23:56:55 -0400255 int i;
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400256
257 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400258 ATP_GEYSER_MODE_READ_REQUEST_ID,
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400259 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400260 ATP_GEYSER_MODE_REQUEST_VALUE,
261 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400262
263 if (size != 8) {
Johannes Berg7dce8692008-05-05 23:56:55 -0400264 dprintk("atp_geyser_init: read error\n");
265 for (i = 0; i < 8; i++)
266 dprintk("appletouch[%d]: %d\n", i, data[i]);
267
268 err("Failed to read mode from device.");
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400269 return -EIO;
270 }
271
272 /* Apply the mode switch */
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400273 data[0] = ATP_GEYSER_MODE_VENDOR_VALUE;
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400274
275 size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400276 ATP_GEYSER_MODE_WRITE_REQUEST_ID,
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400277 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400278 ATP_GEYSER_MODE_REQUEST_VALUE,
279 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400280
281 if (size != 8) {
Johannes Berg7dce8692008-05-05 23:56:55 -0400282 dprintk("atp_geyser_init: write error\n");
283 for (i = 0; i < 8; i++)
284 dprintk("appletouch[%d]: %d\n", i, data[i]);
285
286 err("Failed to request geyser raw mode");
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400287 return -EIO;
288 }
289 return 0;
290}
291
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400292/*
293 * Reinitialise the device. This usually stops stream of empty packets
294 * coming from it.
295 */
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400296static void atp_reinit(struct work_struct *work)
297{
298 struct atp *dev = container_of(work, struct atp, work);
299 struct usb_device *udev = dev->udev;
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400300 int retval;
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400301
Johannes Berg7dce8692008-05-05 23:56:55 -0400302 dprintk("appletouch: putting appletouch to sleep (reinit)\n");
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400303 dev->idlecount = 0;
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400304
305 atp_geyser_init(udev);
306
307 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
Johannes Berg7dce8692008-05-05 23:56:55 -0400308 if (retval)
309 err("atp_reinit: usb_submit_urb failed with error %d",
310 retval);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400311}
312
Stelian Popf7214ff2005-09-08 10:19:48 +0200313static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
314 int *z, int *fingers)
315{
316 int i;
317 /* values to calculate mean */
318 int pcum = 0, psum = 0;
Jason Parekh00081d32006-11-17 01:05:58 -0500319 int is_increasing = 0;
Stelian Popf7214ff2005-09-08 10:19:48 +0200320
321 *fingers = 0;
322
323 for (i = 0; i < nb_sensors; i++) {
Jason Parekh00081d32006-11-17 01:05:58 -0500324 if (xy_sensors[i] < threshold) {
325 if (is_increasing)
326 is_increasing = 0;
327
Stelian Popf7214ff2005-09-08 10:19:48 +0200328 continue;
Jason Parekh00081d32006-11-17 01:05:58 -0500329 }
330
331 /*
332 * Makes the finger detection more versatile. For example,
333 * two fingers with no gap will be detected. Also, my
334 * tests show it less likely to have intermittent loss
335 * of multiple finger readings while moving around (scrolling).
336 *
337 * Changes the multiple finger detection to counting humps on
338 * sensors (transitions from nonincreasing to increasing)
339 * instead of counting transitions from low sensors (no
340 * finger reading) to high sensors (finger above
341 * sensor)
342 *
343 * - Jason Parekh <jasonparekh@gmail.com>
344 */
Johannes Berg7dce8692008-05-05 23:56:55 -0400345 if (i < 1 ||
346 (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) {
Stelian Popf7214ff2005-09-08 10:19:48 +0200347 (*fingers)++;
Jason Parekh00081d32006-11-17 01:05:58 -0500348 is_increasing = 1;
349 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) {
350 is_increasing = 0;
351 }
352
353 /*
Johannes Berg7dce8692008-05-05 23:56:55 -0400354 * Subtracts threshold so a high sensor that just passes the
355 * threshold won't skew the calculated absolute coordinate.
356 * Fixes an issue where slowly moving the mouse would
357 * occasionally jump a number of pixels (slowly moving the
358 * finger makes this issue most apparent.)
Jason Parekh00081d32006-11-17 01:05:58 -0500359 */
360 pcum += (xy_sensors[i] - threshold) * i;
361 psum += (xy_sensors[i] - threshold);
Stelian Popf7214ff2005-09-08 10:19:48 +0200362 }
363
364 if (psum > 0) {
365 *z = psum;
366 return pcum * fact / psum;
367 }
368
369 return 0;
370}
371
372static inline void atp_report_fingers(struct input_dev *input, int fingers)
373{
374 input_report_key(input, BTN_TOOL_FINGER, fingers == 1);
375 input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2);
376 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
377}
378
Johannes Berg7dce8692008-05-05 23:56:55 -0400379static void atp_complete(struct urb *urb)
Stelian Popf7214ff2005-09-08 10:19:48 +0200380{
381 int x, y, x_z, y_z, x_f, y_f;
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500382 int retval, i, j;
Thomas Rohwercb560732007-09-25 00:06:25 -0400383 int key;
Stelian Popf7214ff2005-09-08 10:19:48 +0200384 struct atp *dev = urb->context;
385
386 switch (urb->status) {
387 case 0:
388 /* success */
389 break;
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500390 case -EOVERFLOW:
Johannes Berg7dce8692008-05-05 23:56:55 -0400391 if (!dev->overflow_warned) {
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400392 printk(KERN_WARNING "appletouch: OVERFLOW with data "
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500393 "length %d, actual length is %d\n",
394 dev->datalen, dev->urb->actual_length);
Johannes Berg7dce8692008-05-05 23:56:55 -0400395 dev->overflow_warned = true;
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500396 }
Stelian Popf7214ff2005-09-08 10:19:48 +0200397 case -ECONNRESET:
398 case -ENOENT:
399 case -ESHUTDOWN:
400 /* This urb is terminated, clean up */
Johannes Berg7dce8692008-05-05 23:56:55 -0400401 dbg("atp_complete: urb shutting down with status: %d",
402 urb->status);
Stelian Popf7214ff2005-09-08 10:19:48 +0200403 return;
404 default:
Johannes Berg7dce8692008-05-05 23:56:55 -0400405 dbg("atp_complete: nonzero urb status received: %d",
406 urb->status);
Stelian Popf7214ff2005-09-08 10:19:48 +0200407 goto exit;
408 }
409
410 /* drop incomplete datasets */
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500411 if (dev->urb->actual_length != dev->datalen) {
Nicolas Boichat9effa972006-04-19 23:36:40 +0200412 dprintk("appletouch: incomplete data package"
413 " (first byte: %d, length: %d).\n",
414 dev->data[0], dev->urb->actual_length);
Stelian Popf7214ff2005-09-08 10:19:48 +0200415 goto exit;
416 }
417
418 /* reorder the sensors values */
Nicolas Boichat9effa972006-04-19 23:36:40 +0200419 if (atp_is_geyser_3(dev)) {
420 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
421
422 /*
423 * The values are laid out like this:
424 * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ...
425 * '-' is an unused value.
426 */
427
428 /* read X values */
429 for (i = 0, j = 19; i < 20; i += 2, j += 3) {
430 dev->xy_cur[i] = dev->data[j + 1];
431 dev->xy_cur[i + 1] = dev->data[j + 2];
432 }
433 /* read Y values */
434 for (i = 0, j = 1; i < 9; i += 2, j += 3) {
435 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
436 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
437 }
438 } else if (atp_is_geyser_2(dev)) {
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500439 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
Stelian Popf7214ff2005-09-08 10:19:48 +0200440
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500441 /*
442 * The values are laid out like this:
443 * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ...
444 * '-' is an unused value.
445 */
446
447 /* read X values */
448 for (i = 0, j = 19; i < 20; i += 2, j += 3) {
449 dev->xy_cur[i] = dev->data[j];
450 dev->xy_cur[i + 1] = dev->data[j + 1];
451 }
452
453 /* read Y values */
454 for (i = 0, j = 1; i < 9; i += 2, j += 3) {
455 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j];
456 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1];
457 }
458 } else {
459 for (i = 0; i < 8; i++) {
460 /* X values */
Johannes Berg7dce8692008-05-05 23:56:55 -0400461 dev->xy_cur[i + 0] = dev->data[5 * i + 2];
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500462 dev->xy_cur[i + 8] = dev->data[5 * i + 4];
463 dev->xy_cur[i + 16] = dev->data[5 * i + 42];
464 if (i < 2)
465 dev->xy_cur[i + 24] = dev->data[5 * i + 44];
466
467 /* Y values */
468 dev->xy_cur[i + 26] = dev->data[5 * i + 1];
469 dev->xy_cur[i + 34] = dev->data[5 * i + 3];
470 }
Stelian Popf7214ff2005-09-08 10:19:48 +0200471 }
472
473 dbg_dump("sample", dev->xy_cur);
474
475 if (!dev->valid) {
476 /* first sample */
Johannes Berg7dce8692008-05-05 23:56:55 -0400477 dev->valid = true;
Stelian Popf7214ff2005-09-08 10:19:48 +0200478 dev->x_old = dev->y_old = -1;
479 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
480
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400481 if (dev->size_detect_done ||
482 atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */
Nicolas Boichat9effa972006-04-19 23:36:40 +0200483 goto exit;
484
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500485 /* 17" Powerbooks have extra X sensors */
Johannes Berg7dce8692008-05-05 23:56:55 -0400486 for (i = (atp_is_geyser_2(dev) ? 15 : 16);
487 i < ATP_XSENSORS; i++) {
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400488 if (!dev->xy_cur[i])
489 continue;
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500490
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400491 printk(KERN_INFO "appletouch: 17\" model detected.\n");
492 if (atp_is_geyser_2(dev))
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500493 input_set_abs_params(dev->input, ABS_X, 0,
494 (20 - 1) *
495 ATP_XFACT - 1,
496 ATP_FUZZ, 0);
497 else
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500498 input_set_abs_params(dev->input, ABS_X, 0,
499 (ATP_XSENSORS - 1) *
Stelian Popf7214ff2005-09-08 10:19:48 +0200500 ATP_XFACT - 1,
501 ATP_FUZZ, 0);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500502 break;
503 }
Stelian Popf7214ff2005-09-08 10:19:48 +0200504
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400505 dev->size_detect_done = 1;
Stelian Popf7214ff2005-09-08 10:19:48 +0200506 goto exit;
507 }
508
509 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
510 /* accumulate the change */
511 signed char change = dev->xy_old[i] - dev->xy_cur[i];
512 dev->xy_acc[i] -= change;
513
514 /* prevent down drifting */
515 if (dev->xy_acc[i] < 0)
516 dev->xy_acc[i] = 0;
517 }
518
519 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
520
521 dbg_dump("accumulator", dev->xy_acc);
522
523 x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS,
524 ATP_XFACT, &x_z, &x_f);
525 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
526 ATP_YFACT, &y_z, &y_f);
Thomas Rohwercb560732007-09-25 00:06:25 -0400527 key = dev->data[dev->datalen - 1] & 1;
Stelian Popf7214ff2005-09-08 10:19:48 +0200528
529 if (x && y) {
530 if (dev->x_old != -1) {
531 x = (dev->x_old * 3 + x) >> 2;
532 y = (dev->y_old * 3 + y) >> 2;
533 dev->x_old = x;
534 dev->y_old = y;
535
536 if (debug > 1)
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400537 printk(KERN_DEBUG "appletouch: X: %3d Y: %3d "
Stelian Popf7214ff2005-09-08 10:19:48 +0200538 "Xz: %3d Yz: %3d\n",
539 x, y, x_z, y_z);
540
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500541 input_report_key(dev->input, BTN_TOUCH, 1);
542 input_report_abs(dev->input, ABS_X, x);
543 input_report_abs(dev->input, ABS_Y, y);
544 input_report_abs(dev->input, ABS_PRESSURE,
Stelian Popf7214ff2005-09-08 10:19:48 +0200545 min(ATP_PRESSURE, x_z + y_z));
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500546 atp_report_fingers(dev->input, max(x_f, y_f));
Stelian Popf7214ff2005-09-08 10:19:48 +0200547 }
548 dev->x_old = x;
549 dev->y_old = y;
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400550
551 } else if (!x && !y) {
Stelian Popf7214ff2005-09-08 10:19:48 +0200552
553 dev->x_old = dev->y_old = -1;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500554 input_report_key(dev->input, BTN_TOUCH, 0);
555 input_report_abs(dev->input, ABS_PRESSURE, 0);
556 atp_report_fingers(dev->input, 0);
Stelian Popf7214ff2005-09-08 10:19:48 +0200557
558 /* reset the accumulator on release */
559 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
Soeren Sonnenburg937ad5c2007-10-13 00:31:15 -0400560 }
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400561
Anton Ekblad46249ea2007-10-22 00:59:59 -0400562 input_report_key(dev->input, BTN_LEFT, key);
563 input_sync(dev->input);
564
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400565 /*
566 * Many Geysers will continue to send packets continually after
567 * the first touch unless reinitialised. Do so if it's been
568 * idle for a while in order to avoid waking the kernel up
569 * several hundred times a second. Re-initialization does not
570 * work on Fountain touchpads.
571 */
572 if (!atp_is_fountain(dev)) {
Johannes Berg7dce8692008-05-05 23:56:55 -0400573 /*
574 * Button must not be pressed when entering suspend,
575 * otherwise we will never release the button.
576 */
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400577 if (!x && !y && !key) {
578 dev->idlecount++;
579 if (dev->idlecount == 10) {
Johannes Berg7dce8692008-05-05 23:56:55 -0400580 dev->valid = false;
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400581 schedule_work(&dev->work);
582 /* Don't resubmit urb here, wait for reinit */
583 return;
584 }
585 } else
586 dev->idlecount = 0;
587 }
Stelian Popf7214ff2005-09-08 10:19:48 +0200588
Johannes Berg7dce8692008-05-05 23:56:55 -0400589 exit:
Stelian Popf7214ff2005-09-08 10:19:48 +0200590 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
Johannes Berg7dce8692008-05-05 23:56:55 -0400591 if (retval)
592 err("atp_complete: usb_submit_urb failed with result %d",
593 retval);
Stelian Popf7214ff2005-09-08 10:19:48 +0200594}
595
596static int atp_open(struct input_dev *input)
597{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400598 struct atp *dev = input_get_drvdata(input);
Stelian Popf7214ff2005-09-08 10:19:48 +0200599
600 if (usb_submit_urb(dev->urb, GFP_ATOMIC))
601 return -EIO;
602
603 dev->open = 1;
604 return 0;
605}
606
607static void atp_close(struct input_dev *input)
608{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400609 struct atp *dev = input_get_drvdata(input);
Stelian Popf7214ff2005-09-08 10:19:48 +0200610
611 usb_kill_urb(dev->urb);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400612 cancel_work_sync(&dev->work);
Stelian Popf7214ff2005-09-08 10:19:48 +0200613 dev->open = 0;
614}
615
Johannes Berg7dce8692008-05-05 23:56:55 -0400616static int atp_probe(struct usb_interface *iface,
617 const struct usb_device_id *id)
Stelian Popf7214ff2005-09-08 10:19:48 +0200618{
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500619 struct atp *dev;
620 struct input_dev *input_dev;
621 struct usb_device *udev = interface_to_usbdev(iface);
Stelian Popf7214ff2005-09-08 10:19:48 +0200622 struct usb_host_interface *iface_desc;
623 struct usb_endpoint_descriptor *endpoint;
624 int int_in_endpointAddr = 0;
Dmitry Torokhov50141862007-04-12 01:33:39 -0400625 int i, error = -ENOMEM;
Stelian Popf7214ff2005-09-08 10:19:48 +0200626
627 /* set up the endpoint information */
628 /* use only the first interrupt-in endpoint */
629 iface_desc = iface->cur_altsetting;
630 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
631 endpoint = &iface_desc->endpoint[i].desc;
Luiz Fernando N. Capitulino97b107c2006-09-27 11:58:53 -0700632 if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) {
Stelian Popf7214ff2005-09-08 10:19:48 +0200633 /* we found an interrupt in endpoint */
634 int_in_endpointAddr = endpoint->bEndpointAddress;
635 break;
636 }
637 }
638 if (!int_in_endpointAddr) {
Stelian Popf7214ff2005-09-08 10:19:48 +0200639 err("Could not find int-in endpoint");
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500640 return -EIO;
Stelian Popf7214ff2005-09-08 10:19:48 +0200641 }
642
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500643 /* allocate memory for our device state and initialize it */
644 dev = kzalloc(sizeof(struct atp), GFP_KERNEL);
645 input_dev = input_allocate_device();
646 if (!dev || !input_dev) {
647 err("Out of memory");
648 goto err_free_devs;
649 }
650
651 dev->udev = udev;
652 dev->input = input_dev;
Johannes Berg7dce8692008-05-05 23:56:55 -0400653 dev->overflow_warned = false;
Nicolas Boichat9effa972006-04-19 23:36:40 +0200654 if (atp_is_geyser_3(dev))
655 dev->datalen = 64;
656 else if (atp_is_geyser_2(dev))
657 dev->datalen = 64;
658 else
659 dev->datalen = 81;
660
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400661 if (!atp_is_fountain(dev)) {
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400662 /* switch to raw sensor mode */
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400663 if (atp_geyser_init(udev))
Nicolas Boichat9effa972006-04-19 23:36:40 +0200664 goto err_free_devs;
Nicolas Boichat9effa972006-04-19 23:36:40 +0200665
Dmitry Torokhov2a3e4802007-11-01 22:13:32 -0400666 printk(KERN_INFO "appletouch: Geyser mode initialized.\n");
Nicolas Boichat9effa972006-04-19 23:36:40 +0200667 }
Stelian Popf7214ff2005-09-08 10:19:48 +0200668
669 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400670 if (!dev->urb)
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500671 goto err_free_devs;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500672
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500673 dev->data = usb_buffer_alloc(dev->udev, dev->datalen, GFP_KERNEL,
Stelian Popf7214ff2005-09-08 10:19:48 +0200674 &dev->urb->transfer_dma);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400675 if (!dev->data)
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500676 goto err_free_urb;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500677
678 usb_fill_int_urb(dev->urb, udev,
679 usb_rcvintpipe(udev, int_in_endpointAddr),
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500680 dev->data, dev->datalen, atp_complete, dev, 1);
Stelian Popf7214ff2005-09-08 10:19:48 +0200681
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500682 usb_make_path(udev, dev->phys, sizeof(dev->phys));
683 strlcat(dev->phys, "/input0", sizeof(dev->phys));
Stelian Popf7214ff2005-09-08 10:19:48 +0200684
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500685 input_dev->name = "appletouch";
686 input_dev->phys = dev->phys;
687 usb_to_input_id(dev->udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400688 input_dev->dev.parent = &iface->dev;
Stelian Popf7214ff2005-09-08 10:19:48 +0200689
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400690 input_set_drvdata(input_dev, dev);
691
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500692 input_dev->open = atp_open;
693 input_dev->close = atp_close;
694
695 set_bit(EV_ABS, input_dev->evbit);
Stelian Popf7214ff2005-09-08 10:19:48 +0200696
Nicolas Boichat9effa972006-04-19 23:36:40 +0200697 if (atp_is_geyser_3(dev)) {
698 /*
699 * MacBook have 20 X sensors, 10 Y sensors
700 */
701 input_set_abs_params(input_dev, ABS_X, 0,
702 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
703 input_set_abs_params(input_dev, ABS_Y, 0,
704 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
705 } else if (atp_is_geyser_2(dev)) {
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500706 /*
707 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected
708 * later.
709 */
710 input_set_abs_params(input_dev, ABS_X, 0,
711 ((15 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
712 input_set_abs_params(input_dev, ABS_Y, 0,
713 ((9 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
714 } else {
715 /*
716 * 12" and 15" Powerbooks only have 16 x sensors,
717 * 17" models are detected later.
718 */
719 input_set_abs_params(input_dev, ABS_X, 0,
Johannes Berg7dce8692008-05-05 23:56:55 -0400720 (16 - 1) * ATP_XFACT - 1,
721 ATP_FUZZ, 0);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500722 input_set_abs_params(input_dev, ABS_Y, 0,
Johannes Berg7dce8692008-05-05 23:56:55 -0400723 (ATP_YSENSORS - 1) * ATP_YFACT - 1,
724 ATP_FUZZ, 0);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500725 }
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500726 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
Stelian Popf7214ff2005-09-08 10:19:48 +0200727
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500728 set_bit(EV_KEY, input_dev->evbit);
729 set_bit(BTN_TOUCH, input_dev->keybit);
730 set_bit(BTN_TOOL_FINGER, input_dev->keybit);
731 set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
732 set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
733 set_bit(BTN_LEFT, input_dev->keybit);
Stelian Popf7214ff2005-09-08 10:19:48 +0200734
Dmitry Torokhov50141862007-04-12 01:33:39 -0400735 error = input_register_device(dev->input);
736 if (error)
737 goto err_free_buffer;
Stelian Popf7214ff2005-09-08 10:19:48 +0200738
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500739 /* save our data pointer in this interface device */
740 usb_set_intfdata(iface, dev);
Stelian Popf7214ff2005-09-08 10:19:48 +0200741
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400742 INIT_WORK(&dev->work, atp_reinit);
743
Stelian Popf7214ff2005-09-08 10:19:48 +0200744 return 0;
745
Dmitry Torokhov50141862007-04-12 01:33:39 -0400746 err_free_buffer:
747 usb_buffer_free(dev->udev, dev->datalen,
748 dev->data, dev->urb->transfer_dma);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500749 err_free_urb:
Stelian Popf7214ff2005-09-08 10:19:48 +0200750 usb_free_urb(dev->urb);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500751 err_free_devs:
Stelian Popf7214ff2005-09-08 10:19:48 +0200752 usb_set_intfdata(iface, NULL);
Stelian Popf7214ff2005-09-08 10:19:48 +0200753 kfree(dev);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500754 input_free_device(input_dev);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400755 return error;
Stelian Popf7214ff2005-09-08 10:19:48 +0200756}
757
758static void atp_disconnect(struct usb_interface *iface)
759{
760 struct atp *dev = usb_get_intfdata(iface);
761
762 usb_set_intfdata(iface, NULL);
763 if (dev) {
764 usb_kill_urb(dev->urb);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500765 input_unregister_device(dev->input);
Michael Hanselmanne1e02c92005-12-21 00:50:23 -0500766 usb_buffer_free(dev->udev, dev->datalen,
Stelian Popf7214ff2005-09-08 10:19:48 +0200767 dev->data, dev->urb->transfer_dma);
Johannes Berg7af569a2006-07-19 15:39:46 +0200768 usb_free_urb(dev->urb);
Stelian Popf7214ff2005-09-08 10:19:48 +0200769 kfree(dev);
770 }
771 printk(KERN_INFO "input: appletouch disconnected\n");
772}
773
774static int atp_suspend(struct usb_interface *iface, pm_message_t message)
775{
776 struct atp *dev = usb_get_intfdata(iface);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400777
Stelian Popf7214ff2005-09-08 10:19:48 +0200778 usb_kill_urb(dev->urb);
Johannes Berg7dce8692008-05-05 23:56:55 -0400779 dev->valid = false;
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400780
Stelian Popf7214ff2005-09-08 10:19:48 +0200781 return 0;
782}
783
784static int atp_resume(struct usb_interface *iface)
785{
786 struct atp *dev = usb_get_intfdata(iface);
Soeren Sonnenburg5a6eb672007-07-20 00:29:32 -0400787
Stelian Popf7214ff2005-09-08 10:19:48 +0200788 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
789 return -EIO;
790
791 return 0;
792}
793
794static struct usb_driver atp_driver = {
Stelian Popf7214ff2005-09-08 10:19:48 +0200795 .name = "appletouch",
796 .probe = atp_probe,
797 .disconnect = atp_disconnect,
798 .suspend = atp_suspend,
799 .resume = atp_resume,
800 .id_table = atp_table,
801};
802
803static int __init atp_init(void)
804{
805 return usb_register(&atp_driver);
806}
807
808static void __exit atp_exit(void)
809{
810 usb_deregister(&atp_driver);
811}
812
813module_init(atp_init);
814module_exit(atp_exit);