aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse/appletouch.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/mouse/appletouch.c')
-rw-r--r--drivers/input/mouse/appletouch.c299
1 files changed, 138 insertions, 161 deletions
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index ce6fdec19e1..1f41ae94f26 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -2,12 +2,13 @@
2 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver 2 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver
3 * 3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net) 5 * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net)
6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net) 6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de) 7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com) 8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
9 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch) 9 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch)
10 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch) 10 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch)
11 * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de)
11 * 12 *
12 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs. 13 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
13 * 14 *
@@ -34,77 +35,64 @@
34#include <linux/module.h> 35#include <linux/module.h>
35#include <linux/usb/input.h> 36#include <linux/usb/input.h>
36 37
37/* Apple has powerbooks which have the keyboard with different Product IDs */ 38/* Type of touchpad */
38#define APPLE_VENDOR_ID 0x05AC 39enum atp_touchpad_type {
39 40 ATP_FOUNTAIN,
40/* These names come from Info.plist in AppleUSBTrackpad.kext */ 41 ATP_GEYSER1,
41#define FOUNTAIN_ANSI_PRODUCT_ID 0x020E 42 ATP_GEYSER2,
42#define FOUNTAIN_ISO_PRODUCT_ID 0x020F 43 ATP_GEYSER3,
43 44 ATP_GEYSER4
44#define FOUNTAIN_TP_ONLY_PRODUCT_ID 0x030A 45};
45
46#define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B
47
48#define GEYSER_ANSI_PRODUCT_ID 0x0214
49#define GEYSER_ISO_PRODUCT_ID 0x0215
50#define GEYSER_JIS_PRODUCT_ID 0x0216
51
52/* MacBook devices */
53#define GEYSER3_ANSI_PRODUCT_ID 0x0217
54#define GEYSER3_ISO_PRODUCT_ID 0x0218
55#define GEYSER3_JIS_PRODUCT_ID 0x0219
56
57/*
58 * Geyser IV: same as Geyser III according to Info.plist in AppleUSBTrackpad.kext
59 * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables
60 */
61#define GEYSER4_ANSI_PRODUCT_ID 0x021A
62#define GEYSER4_ISO_PRODUCT_ID 0x021B
63#define GEYSER4_JIS_PRODUCT_ID 0x021C
64
65#define GEYSER4_HF_ANSI_PRODUCT_ID 0x0229
66#define GEYSER4_HF_ISO_PRODUCT_ID 0x022A
67#define GEYSER4_HF_JIS_PRODUCT_ID 0x022B
68 46
69#define ATP_DEVICE(prod) \ 47#define ATP_DEVICE(prod, type) \
48{ \
70 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 49 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
71 USB_DEVICE_ID_MATCH_INT_CLASS | \ 50 USB_DEVICE_ID_MATCH_INT_CLASS | \
72 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ 51 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
73 .idVendor = APPLE_VENDOR_ID, \ 52 .idVendor = 0x05ac, /* Apple */ \
74 .idProduct = (prod), \ 53 .idProduct = (prod), \
75 .bInterfaceClass = 0x03, \ 54 .bInterfaceClass = 0x03, \
76 .bInterfaceProtocol = 0x02 55 .bInterfaceProtocol = 0x02, \
56 .driver_info = ATP_ ## type, \
57}
58
59/*
60 * Table of devices (Product IDs) that work with this driver.
61 * (The names come from Info.plist in AppleUSBTrackpad.kext,
62 * According to Info.plist Geyser IV is the same as Geyser III.)
63 */
77 64
78/* table of devices that work with this driver */
79static struct usb_device_id atp_table [] = { 65static struct usb_device_id atp_table [] = {
80 { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) }, 66 /* PowerBooks Feb 2005, iBooks G4 */
81 { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) }, 67 ATP_DEVICE(0x020e, FOUNTAIN), /* FOUNTAIN ANSI */
82 { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) }, 68 ATP_DEVICE(0x020f, FOUNTAIN), /* FOUNTAIN ISO */
83 { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) }, 69 ATP_DEVICE(0x030a, FOUNTAIN), /* FOUNTAIN TP ONLY */
70 ATP_DEVICE(0x030b, GEYSER1), /* GEYSER 1 TP ONLY */
84 71
85 /* PowerBooks Oct 2005 */ 72 /* PowerBooks Oct 2005 */
86 { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) }, 73 ATP_DEVICE(0x0214, GEYSER2), /* GEYSER 2 ANSI */
87 { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) }, 74 ATP_DEVICE(0x0215, GEYSER2), /* GEYSER 2 ISO */
88 { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) }, 75 ATP_DEVICE(0x0216, GEYSER2), /* GEYSER 2 JIS */
89 76
90 /* Core Duo MacBook & MacBook Pro */ 77 /* Core Duo MacBook & MacBook Pro */
91 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) }, 78 ATP_DEVICE(0x0217, GEYSER3), /* GEYSER 3 ANSI */
92 { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) }, 79 ATP_DEVICE(0x0218, GEYSER3), /* GEYSER 3 ISO */
93 { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) }, 80 ATP_DEVICE(0x0219, GEYSER3), /* GEYSER 3 JIS */
94 81
95 /* Core2 Duo MacBook & MacBook Pro */ 82 /* Core2 Duo MacBook & MacBook Pro */
96 { ATP_DEVICE(GEYSER4_ANSI_PRODUCT_ID) }, 83 ATP_DEVICE(0x021a, GEYSER4), /* GEYSER 4 ANSI */
97 { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) }, 84 ATP_DEVICE(0x021b, GEYSER4), /* GEYSER 4 ISO */
98 { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) }, 85 ATP_DEVICE(0x021c, GEYSER4), /* GEYSER 4 JIS */
99 86
100 { ATP_DEVICE(GEYSER4_HF_ANSI_PRODUCT_ID) }, 87 /* Core2 Duo MacBook3,1 */
101 { ATP_DEVICE(GEYSER4_HF_ISO_PRODUCT_ID) }, 88 ATP_DEVICE(0x0229, GEYSER4), /* GEYSER 4 HF ANSI */
102 { ATP_DEVICE(GEYSER4_HF_JIS_PRODUCT_ID) }, 89 ATP_DEVICE(0x022a, GEYSER4), /* GEYSER 4 HF ISO */
90 ATP_DEVICE(0x022b, GEYSER4), /* GEYSER 4 HF JIS */
103 91
104 /* Terminating entry */ 92 /* Terminating entry */
105 { } 93 { }
106}; 94};
107MODULE_DEVICE_TABLE (usb, atp_table); 95MODULE_DEVICE_TABLE(usb, atp_table);
108 96
109/* 97/*
110 * number of sensors. Note that only 16 instead of 26 X (horizontal) 98 * number of sensors. Note that only 16 instead of 26 X (horizontal)
@@ -124,9 +112,13 @@ MODULE_DEVICE_TABLE (usb, atp_table);
124 * We try to keep the touchpad aspect ratio while still doing only simple 112 * We try to keep the touchpad aspect ratio while still doing only simple
125 * arithmetics. 113 * arithmetics.
126 * The factors below give coordinates like: 114 * The factors below give coordinates like:
127 * 0 <= x < 960 on 12" and 15" Powerbooks 115 *
128 * 0 <= x < 1600 on 17" Powerbooks 116 * 0 <= x < 960 on 12" and 15" Powerbooks
129 * 0 <= y < 646 117 * 0 <= x < 1600 on 17" Powerbooks and 17" MacBook Pro
118 * 0 <= x < 1216 on MacBooks and 15" MacBook Pro
119 *
120 * 0 <= y < 646 on all Powerbooks
121 * 0 <= y < 774 on all MacBooks
130 */ 122 */
131#define ATP_XFACT 64 123#define ATP_XFACT 64
132#define ATP_YFACT 43 124#define ATP_YFACT 43
@@ -147,43 +139,46 @@ MODULE_DEVICE_TABLE (usb, atp_table);
147/* Structure to hold all of our device specific stuff */ 139/* Structure to hold all of our device specific stuff */
148struct atp { 140struct atp {
149 char phys[64]; 141 char phys[64];
150 struct usb_device * udev; /* usb device */ 142 struct usb_device *udev; /* usb device */
151 struct urb * urb; /* usb request block */ 143 struct urb *urb; /* usb request block */
152 signed char * data; /* transferred data */ 144 signed char *data; /* transferred data */
153 struct input_dev * input; /* input dev */ 145 struct input_dev *input; /* input dev */
154 unsigned char open; /* non-zero if opened */ 146 enum atp_touchpad_type type; /* type of touchpad */
155 unsigned char valid; /* are the sensors valid ? */ 147 bool open;
156 unsigned char size_detect_done; 148 bool valid; /* are the samples valid? */
157 unsigned char overflowwarn; /* overflow warning printed? */ 149 bool size_detect_done;
150 bool overflow_warned;
158 int x_old; /* last reported x/y, */ 151 int x_old; /* last reported x/y, */
159 int y_old; /* used for smoothing */ 152 int y_old; /* used for smoothing */
160 /* current value of the sensors */
161 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS]; 153 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
162 /* last value of the sensors */
163 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS]; 154 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
164 /* accumulated sensors */
165 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
166 int datalen; /* size of an USB urb transfer */ 156 int datalen; /* size of USB transfer */
167 int idlecount; /* number of empty packets */ 157 int idlecount; /* number of empty packets */
168 struct work_struct work; 158 struct work_struct work;
169}; 159};
170 160
171#define dbg_dump(msg, tab) \ 161#define dbg_dump(msg, tab) \
172 if (debug > 1) { \ 162 if (debug > 1) { \
173 int i; \ 163 int __i; \
174 printk("appletouch: %s %lld", msg, (long long)jiffies); \ 164 printk(KERN_DEBUG "appletouch: %s", msg); \
175 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \ 165 for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \
176 printk(" %02x", tab[i]); \ 166 printk(" %02x", tab[__i]); \
177 printk("\n"); \ 167 printk("\n"); \
178 } 168 }
179 169
180#define dprintk(format, a...) \ 170#define dprintk(format, a...) \
181 do { \ 171 do { \
182 if (debug) printk(KERN_DEBUG format, ##a); \ 172 if (debug) \
173 printk(KERN_DEBUG format, ##a); \
183 } while (0) 174 } while (0)
184 175
185MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Michael Hanselmann"); 176MODULE_AUTHOR("Johannes Berg");
186MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver"); 177MODULE_AUTHOR("Stelian Pop");
178MODULE_AUTHOR("Frank Arnold");
179MODULE_AUTHOR("Michael Hanselmann");
180MODULE_AUTHOR("Sven Anders");
181MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver");
187MODULE_LICENSE("GPL"); 182MODULE_LICENSE("GPL");
188 183
189/* 184/*
@@ -191,46 +186,14 @@ MODULE_LICENSE("GPL");
191 */ 186 */
192static int threshold = ATP_THRESHOLD; 187static int threshold = ATP_THRESHOLD;
193module_param(threshold, int, 0644); 188module_param(threshold, int, 0644);
194MODULE_PARM_DESC(threshold, "Discards any change in data from a sensor (trackpad has hundreds of these sensors) less than this value"); 189MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor"
190 " (the trackpad has many of these sensors)"
191 " less than this value.");
195 192
196static int debug = 1; 193static int debug;
197module_param(debug, int, 0644); 194module_param(debug, int, 0644);
198MODULE_PARM_DESC(debug, "Activate debugging output"); 195MODULE_PARM_DESC(debug, "Activate debugging output");
199 196
200static inline int atp_is_fountain(struct atp *dev)
201{
202 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
203
204 return productId == FOUNTAIN_ANSI_PRODUCT_ID ||
205 productId == FOUNTAIN_ISO_PRODUCT_ID ||
206 productId == FOUNTAIN_TP_ONLY_PRODUCT_ID;
207}
208
209/* Checks if the device a Geyser 2 (ANSI, ISO, JIS) */
210static inline int atp_is_geyser_2(struct atp *dev)
211{
212 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
213
214 return (productId == GEYSER_ANSI_PRODUCT_ID) ||
215 (productId == GEYSER_ISO_PRODUCT_ID) ||
216 (productId == GEYSER_JIS_PRODUCT_ID);
217}
218
219static inline int atp_is_geyser_3(struct atp *dev)
220{
221 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct);
222
223 return (productId == GEYSER3_ANSI_PRODUCT_ID) ||
224 (productId == GEYSER3_ISO_PRODUCT_ID) ||
225 (productId == GEYSER3_JIS_PRODUCT_ID) ||
226 (productId == GEYSER4_ANSI_PRODUCT_ID) ||
227 (productId == GEYSER4_ISO_PRODUCT_ID) ||
228 (productId == GEYSER4_JIS_PRODUCT_ID) ||
229 (productId == GEYSER4_HF_ANSI_PRODUCT_ID) ||
230 (productId == GEYSER4_HF_ISO_PRODUCT_ID) ||
231 (productId == GEYSER4_HF_JIS_PRODUCT_ID);
232}
233
234/* 197/*
235 * By default newer Geyser devices send standard USB HID mouse 198 * By default newer Geyser devices send standard USB HID mouse
236 * packets (Report ID 2). This code changes device mode, so it 199 * packets (Report ID 2). This code changes device mode, so it
@@ -240,6 +203,7 @@ static int atp_geyser_init(struct usb_device *udev)
240{ 203{
241 char data[8]; 204 char data[8];
242 int size; 205 int size;
206 int i;
243 207
244 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 208 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
245 ATP_GEYSER_MODE_READ_REQUEST_ID, 209 ATP_GEYSER_MODE_READ_REQUEST_ID,
@@ -248,8 +212,11 @@ static int atp_geyser_init(struct usb_device *udev)
248 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 212 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
249 213
250 if (size != 8) { 214 if (size != 8) {
251 err("Could not do mode read request from device" 215 dprintk("atp_geyser_init: read error\n");
252 " (Geyser Raw mode)"); 216 for (i = 0; i < 8; i++)
217 dprintk("appletouch[%d]: %d\n", i, data[i]);
218
219 err("Failed to read mode from device.");
253 return -EIO; 220 return -EIO;
254 } 221 }
255 222
@@ -263,8 +230,11 @@ static int atp_geyser_init(struct usb_device *udev)
263 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 230 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000);
264 231
265 if (size != 8) { 232 if (size != 8) {
266 err("Could not do mode write request to device" 233 dprintk("atp_geyser_init: write error\n");
267 " (Geyser Raw mode)"); 234 for (i = 0; i < 8; i++)
235 dprintk("appletouch[%d]: %d\n", i, data[i]);
236
237 err("Failed to request geyser raw mode");
268 return -EIO; 238 return -EIO;
269 } 239 }
270 return 0; 240 return 0;
@@ -280,15 +250,15 @@ static void atp_reinit(struct work_struct *work)
280 struct usb_device *udev = dev->udev; 250 struct usb_device *udev = dev->udev;
281 int retval; 251 int retval;
282 252
253 dprintk("appletouch: putting appletouch to sleep (reinit)\n");
283 dev->idlecount = 0; 254 dev->idlecount = 0;
284 255
285 atp_geyser_init(udev); 256 atp_geyser_init(udev);
286 257
287 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 258 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
288 if (retval) { 259 if (retval)
289 err("%s - usb_submit_urb failed with result %d", 260 err("atp_reinit: usb_submit_urb failed with error %d",
290 __FUNCTION__, retval); 261 retval);
291 }
292} 262}
293 263
294static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, 264static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
@@ -323,7 +293,8 @@ static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
323 * 293 *
324 * - Jason Parekh <jasonparekh@gmail.com> 294 * - Jason Parekh <jasonparekh@gmail.com>
325 */ 295 */
326 if (i < 1 || (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { 296 if (i < 1 ||
297 (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) {
327 (*fingers)++; 298 (*fingers)++;
328 is_increasing = 1; 299 is_increasing = 1;
329 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) { 300 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) {
@@ -331,11 +302,11 @@ static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
331 } 302 }
332 303
333 /* 304 /*
334 * Subtracts threshold so a high sensor that just passes the threshold 305 * Subtracts threshold so a high sensor that just passes the
335 * won't skew the calculated absolute coordinate. Fixes an issue 306 * threshold won't skew the calculated absolute coordinate.
336 * where slowly moving the mouse would occassionaly jump a number of 307 * Fixes an issue where slowly moving the mouse would
337 * pixels (let me restate--slowly moving the mouse makes this issue 308 * occasionally jump a number of pixels (slowly moving the
338 * most apparent). 309 * finger makes this issue most apparent.)
339 */ 310 */
340 pcum += (xy_sensors[i] - threshold) * i; 311 pcum += (xy_sensors[i] - threshold) * i;
341 psum += (xy_sensors[i] - threshold); 312 psum += (xy_sensors[i] - threshold);
@@ -356,7 +327,7 @@ static inline void atp_report_fingers(struct input_dev *input, int fingers)
356 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); 327 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
357} 328}
358 329
359static void atp_complete(struct urb* urb) 330static void atp_complete(struct urb *urb)
360{ 331{
361 int x, y, x_z, y_z, x_f, y_f; 332 int x, y, x_z, y_z, x_f, y_f;
362 int retval, i, j; 333 int retval, i, j;
@@ -368,22 +339,22 @@ static void atp_complete(struct urb* urb)
368 /* success */ 339 /* success */
369 break; 340 break;
370 case -EOVERFLOW: 341 case -EOVERFLOW:
371 if(!dev->overflowwarn) { 342 if (!dev->overflow_warned) {
372 printk(KERN_WARNING "appletouch: OVERFLOW with data " 343 printk(KERN_WARNING "appletouch: OVERFLOW with data "
373 "length %d, actual length is %d\n", 344 "length %d, actual length is %d\n",
374 dev->datalen, dev->urb->actual_length); 345 dev->datalen, dev->urb->actual_length);
375 dev->overflowwarn = 1; 346 dev->overflow_warned = true;
376 } 347 }
377 case -ECONNRESET: 348 case -ECONNRESET:
378 case -ENOENT: 349 case -ENOENT:
379 case -ESHUTDOWN: 350 case -ESHUTDOWN:
380 /* This urb is terminated, clean up */ 351 /* This urb is terminated, clean up */
381 dbg("%s - urb shutting down with status: %d", 352 dbg("atp_complete: urb shutting down with status: %d",
382 __FUNCTION__, urb->status); 353 urb->status);
383 return; 354 return;
384 default: 355 default:
385 dbg("%s - nonzero urb status received: %d", 356 dbg("atp_complete: nonzero urb status received: %d",
386 __FUNCTION__, urb->status); 357 urb->status);
387 goto exit; 358 goto exit;
388 } 359 }
389 360
@@ -396,7 +367,7 @@ static void atp_complete(struct urb* urb)
396 } 367 }
397 368
398 /* reorder the sensors values */ 369 /* reorder the sensors values */
399 if (atp_is_geyser_3(dev)) { 370 if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
400 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 371 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
401 372
402 /* 373 /*
@@ -415,7 +386,7 @@ static void atp_complete(struct urb* urb)
415 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; 386 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
416 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; 387 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
417 } 388 }
418 } else if (atp_is_geyser_2(dev)) { 389 } else if (dev->type == ATP_GEYSER2) {
419 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 390 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
420 391
421 /* 392 /*
@@ -438,7 +409,7 @@ static void atp_complete(struct urb* urb)
438 } else { 409 } else {
439 for (i = 0; i < 8; i++) { 410 for (i = 0; i < 8; i++) {
440 /* X values */ 411 /* X values */
441 dev->xy_cur[i ] = dev->data[5 * i + 2]; 412 dev->xy_cur[i + 0] = dev->data[5 * i + 2];
442 dev->xy_cur[i + 8] = dev->data[5 * i + 4]; 413 dev->xy_cur[i + 8] = dev->data[5 * i + 4];
443 dev->xy_cur[i + 16] = dev->data[5 * i + 42]; 414 dev->xy_cur[i + 16] = dev->data[5 * i + 42];
444 if (i < 2) 415 if (i < 2)
@@ -454,21 +425,22 @@ static void atp_complete(struct urb* urb)
454 425
455 if (!dev->valid) { 426 if (!dev->valid) {
456 /* first sample */ 427 /* first sample */
457 dev->valid = 1; 428 dev->valid = true;
458 dev->x_old = dev->y_old = -1; 429 dev->x_old = dev->y_old = -1;
459 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 430 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
460 431
461 if (dev->size_detect_done || 432 if (dev->size_detect_done ||
462 atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */ 433 dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */
463 goto exit; 434 goto exit;
464 435
465 /* 17" Powerbooks have extra X sensors */ 436 /* 17" Powerbooks have extra X sensors */
466 for (i = (atp_is_geyser_2(dev) ? 15 : 16); i < ATP_XSENSORS; i++) { 437 for (i = (dev->type == ATP_GEYSER2 ? 15 : 16);
438 i < ATP_XSENSORS; i++) {
467 if (!dev->xy_cur[i]) 439 if (!dev->xy_cur[i])
468 continue; 440 continue;
469 441
470 printk(KERN_INFO "appletouch: 17\" model detected.\n"); 442 printk(KERN_INFO "appletouch: 17\" model detected.\n");
471 if (atp_is_geyser_2(dev)) 443 if (dev->type == ATP_GEYSER2)
472 input_set_abs_params(dev->input, ABS_X, 0, 444 input_set_abs_params(dev->input, ABS_X, 0,
473 (20 - 1) * 445 (20 - 1) *
474 ATP_XFACT - 1, 446 ATP_XFACT - 1,
@@ -548,11 +520,15 @@ static void atp_complete(struct urb* urb)
548 * several hundred times a second. Re-initialization does not 520 * several hundred times a second. Re-initialization does not
549 * work on Fountain touchpads. 521 * work on Fountain touchpads.
550 */ 522 */
551 if (!atp_is_fountain(dev)) { 523 if (dev->type != ATP_FOUNTAIN) {
524 /*
525 * Button must not be pressed when entering suspend,
526 * otherwise we will never release the button.
527 */
552 if (!x && !y && !key) { 528 if (!x && !y && !key) {
553 dev->idlecount++; 529 dev->idlecount++;
554 if (dev->idlecount == 10) { 530 if (dev->idlecount == 10) {
555 dev->valid = 0; 531 dev->valid = false;
556 schedule_work(&dev->work); 532 schedule_work(&dev->work);
557 /* Don't resubmit urb here, wait for reinit */ 533 /* Don't resubmit urb here, wait for reinit */
558 return; 534 return;
@@ -561,12 +537,11 @@ static void atp_complete(struct urb* urb)
561 dev->idlecount = 0; 537 dev->idlecount = 0;
562 } 538 }
563 539
564exit: 540 exit:
565 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 541 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
566 if (retval) { 542 if (retval)
567 err("%s - usb_submit_urb failed with result %d", 543 err("atp_complete: usb_submit_urb failed with result %d",
568 __FUNCTION__, retval); 544 retval);
569 }
570} 545}
571 546
572static int atp_open(struct input_dev *input) 547static int atp_open(struct input_dev *input)
@@ -593,7 +568,7 @@ static int atp_handle_geyser(struct atp *dev)
593{ 568{
594 struct usb_device *udev = dev->udev; 569 struct usb_device *udev = dev->udev;
595 570
596 if (!atp_is_fountain(dev)) { 571 if (dev->type != ATP_FOUNTAIN) {
597 /* switch to raw sensor mode */ 572 /* switch to raw sensor mode */
598 if (atp_geyser_init(udev)) 573 if (atp_geyser_init(udev))
599 return -EIO; 574 return -EIO;
@@ -604,7 +579,8 @@ static int atp_handle_geyser(struct atp *dev)
604 return 0; 579 return 0;
605} 580}
606 581
607static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id) 582static int atp_probe(struct usb_interface *iface,
583 const struct usb_device_id *id)
608{ 584{
609 struct atp *dev; 585 struct atp *dev;
610 struct input_dev *input_dev; 586 struct input_dev *input_dev;
@@ -640,13 +616,12 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
640 616
641 dev->udev = udev; 617 dev->udev = udev;
642 dev->input = input_dev; 618 dev->input = input_dev;
643 dev->overflowwarn = 0; 619 dev->type = id->driver_info;
644 if (atp_is_geyser_3(dev)) 620 dev->overflow_warned = false;
645 dev->datalen = 64; 621 if (dev->type == ATP_FOUNTAIN || dev->type == ATP_GEYSER1)
646 else if (atp_is_geyser_2(dev))
647 dev->datalen = 64;
648 else
649 dev->datalen = 81; 622 dev->datalen = 81;
623 else
624 dev->datalen = 64;
650 625
651 dev->urb = usb_alloc_urb(0, GFP_KERNEL); 626 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
652 if (!dev->urb) 627 if (!dev->urb)
@@ -680,7 +655,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
680 655
681 set_bit(EV_ABS, input_dev->evbit); 656 set_bit(EV_ABS, input_dev->evbit);
682 657
683 if (atp_is_geyser_3(dev)) { 658 if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
684 /* 659 /*
685 * MacBook have 20 X sensors, 10 Y sensors 660 * MacBook have 20 X sensors, 10 Y sensors
686 */ 661 */
@@ -688,7 +663,7 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
688 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0); 663 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
689 input_set_abs_params(input_dev, ABS_Y, 0, 664 input_set_abs_params(input_dev, ABS_Y, 0,
690 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0); 665 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
691 } else if (atp_is_geyser_2(dev)) { 666 } else if (dev->type == ATP_GEYSER2) {
692 /* 667 /*
693 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected 668 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected
694 * later. 669 * later.
@@ -703,9 +678,11 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
703 * 17" models are detected later. 678 * 17" models are detected later.
704 */ 679 */
705 input_set_abs_params(input_dev, ABS_X, 0, 680 input_set_abs_params(input_dev, ABS_X, 0,
706 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0); 681 (16 - 1) * ATP_XFACT - 1,
682 ATP_FUZZ, 0);
707 input_set_abs_params(input_dev, ABS_Y, 0, 683 input_set_abs_params(input_dev, ABS_Y, 0,
708 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0); 684 (ATP_YSENSORS - 1) * ATP_YFACT - 1,
685 ATP_FUZZ, 0);
709 } 686 }
710 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 687 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
711 688
@@ -774,7 +751,7 @@ static int atp_suspend(struct usb_interface *iface, pm_message_t message)
774 struct atp *dev = usb_get_intfdata(iface); 751 struct atp *dev = usb_get_intfdata(iface);
775 752
776 usb_kill_urb(dev->urb); 753 usb_kill_urb(dev->urb);
777 dev->valid = 0; 754 dev->valid = false;
778 755
779 return 0; 756 return 0;
780} 757}