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