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