| 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) | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 5 |  * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net) | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 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) | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 11 |  * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de) | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 12 |  * | 
 | 13 |  * Thanks to Alex Harper <basilisk@foobox.net> for his inputs. | 
 | 14 |  * | 
 | 15 |  * This program is free software; you can redistribute it and/or modify | 
 | 16 |  * it under the terms of the GNU General Public License as published by | 
 | 17 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 18 |  * (at your option) any later version. | 
 | 19 |  * | 
 | 20 |  * This program is distributed in the hope that it will be useful, | 
 | 21 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 22 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 23 |  * GNU General Public License for more details. | 
 | 24 |  * | 
 | 25 |  * You should have received a copy of the GNU General Public License | 
 | 26 |  * along with this program; if not, write to the Free Software | 
 | 27 |  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
 | 28 |  * | 
 | 29 |  */ | 
 | 30 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 31 | #include <linux/kernel.h> | 
 | 32 | #include <linux/errno.h> | 
 | 33 | #include <linux/init.h> | 
 | 34 | #include <linux/slab.h> | 
 | 35 | #include <linux/module.h> | 
| David Brownell | ae0dadc | 2006-06-13 10:04:34 -0700 | [diff] [blame] | 36 | #include <linux/usb/input.h> | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 37 |  | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 38 | /* Type of touchpad */ | 
 | 39 | enum atp_touchpad_type { | 
 | 40 | 	ATP_FOUNTAIN, | 
 | 41 | 	ATP_GEYSER1, | 
 | 42 | 	ATP_GEYSER2, | 
 | 43 | 	ATP_GEYSER3, | 
 | 44 | 	ATP_GEYSER4 | 
 | 45 | }; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 46 |  | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 47 | #define ATP_DEVICE(prod, type)					\ | 
 | 48 | {								\ | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 49 | 	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |		\ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 50 | 		       USB_DEVICE_ID_MATCH_INT_CLASS |		\ | 
 | 51 | 		       USB_DEVICE_ID_MATCH_INT_PROTOCOL,	\ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 52 | 	.idVendor = 0x05ac, /* Apple */				\ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 53 | 	.idProduct = (prod),					\ | 
 | 54 | 	.bInterfaceClass = 0x03,				\ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 55 | 	.bInterfaceProtocol = 0x02,				\ | 
 | 56 | 	.driver_info = ATP_ ## type,				\ | 
 | 57 | } | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 58 |  | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 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 |  */ | 
 | 64 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 65 | static struct usb_device_id atp_table [] = { | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 66 | 	/* PowerBooks Feb 2005, iBooks G4 */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 67 | 	ATP_DEVICE(0x020e, FOUNTAIN),	/* FOUNTAIN ANSI */ | 
 | 68 | 	ATP_DEVICE(0x020f, FOUNTAIN),	/* FOUNTAIN ISO */ | 
 | 69 | 	ATP_DEVICE(0x030a, FOUNTAIN),	/* FOUNTAIN TP ONLY */ | 
 | 70 | 	ATP_DEVICE(0x030b, GEYSER1),	/* GEYSER 1 TP ONLY */ | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 71 |  | 
 | 72 | 	/* PowerBooks Oct 2005 */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 73 | 	ATP_DEVICE(0x0214, GEYSER2),	/* GEYSER 2 ANSI */ | 
 | 74 | 	ATP_DEVICE(0x0215, GEYSER2),	/* GEYSER 2 ISO */ | 
 | 75 | 	ATP_DEVICE(0x0216, GEYSER2),	/* GEYSER 2 JIS */ | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 76 |  | 
| Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 77 | 	/* Core Duo MacBook & MacBook Pro */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 78 | 	ATP_DEVICE(0x0217, GEYSER3),	/* GEYSER 3 ANSI */ | 
 | 79 | 	ATP_DEVICE(0x0218, GEYSER3),	/* GEYSER 3 ISO */ | 
 | 80 | 	ATP_DEVICE(0x0219, GEYSER3),	/* GEYSER 3 JIS */ | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 81 |  | 
| Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 82 | 	/* Core2 Duo MacBook & MacBook Pro */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 83 | 	ATP_DEVICE(0x021a, GEYSER4),	/* GEYSER 4 ANSI */ | 
 | 84 | 	ATP_DEVICE(0x021b, GEYSER4),	/* GEYSER 4 ISO */ | 
 | 85 | 	ATP_DEVICE(0x021c, GEYSER4),	/* GEYSER 4 JIS */ | 
| Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 86 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 87 | 	/* Core2 Duo MacBook3,1 */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 88 | 	ATP_DEVICE(0x0229, GEYSER4),	/* GEYSER 4 HF ANSI */ | 
 | 89 | 	ATP_DEVICE(0x022a, GEYSER4),	/* GEYSER 4 HF ISO */ | 
 | 90 | 	ATP_DEVICE(0x022b, GEYSER4),	/* GEYSER 4 HF JIS */ | 
| Tobias Mueller | 0035a1d | 2008-04-02 10:02:06 -0400 | [diff] [blame] | 91 |  | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 92 | 	/* Terminating entry */ | 
 | 93 | 	{ } | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 94 | }; | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 95 | MODULE_DEVICE_TABLE(usb, atp_table); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 96 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 97 | /* | 
 | 98 |  * number of sensors. Note that only 16 instead of 26 X (horizontal) | 
 | 99 |  * sensors exist on 12" and 15" PowerBooks. All models have 16 Y | 
 | 100 |  * (vertical) sensors. | 
 | 101 |  */ | 
 | 102 | #define ATP_XSENSORS	26 | 
 | 103 | #define ATP_YSENSORS	16 | 
 | 104 |  | 
 | 105 | /* amount of fuzz this touchpad generates */ | 
 | 106 | #define ATP_FUZZ	16 | 
 | 107 |  | 
 | 108 | /* maximum pressure this driver will report */ | 
 | 109 | #define ATP_PRESSURE	300 | 
 | 110 | /* | 
 | 111 |  * multiplication factor for the X and Y coordinates. | 
 | 112 |  * We try to keep the touchpad aspect ratio while still doing only simple | 
 | 113 |  * arithmetics. | 
 | 114 |  * The factors below give coordinates like: | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 115 |  * | 
 | 116 |  *      0 <= x <  960 on 12" and 15" Powerbooks | 
 | 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 | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 122 |  */ | 
 | 123 | #define ATP_XFACT	64 | 
 | 124 | #define ATP_YFACT	43 | 
 | 125 |  | 
 | 126 | /* | 
 | 127 |  * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is | 
 | 128 |  * ignored. | 
 | 129 |  */ | 
 | 130 | #define ATP_THRESHOLD	 5 | 
 | 131 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 132 | /* Geyser initialization constants */ | 
 | 133 | #define ATP_GEYSER_MODE_READ_REQUEST_ID		1 | 
 | 134 | #define ATP_GEYSER_MODE_WRITE_REQUEST_ID	9 | 
 | 135 | #define ATP_GEYSER_MODE_REQUEST_VALUE		0x300 | 
 | 136 | #define ATP_GEYSER_MODE_REQUEST_INDEX		0 | 
 | 137 | #define ATP_GEYSER_MODE_VENDOR_VALUE		0x04 | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 138 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 139 | /* Structure to hold all of our device specific stuff */ | 
 | 140 | struct atp { | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 141 | 	char			phys[64]; | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 142 | 	struct usb_device	*udev;		/* usb device */ | 
 | 143 | 	struct urb		*urb;		/* usb request block */ | 
 | 144 | 	signed char		*data;		/* transferred data */ | 
 | 145 | 	struct input_dev	*input;		/* input dev */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 146 | 	enum atp_touchpad_type	type;		/* type of touchpad */ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 147 | 	bool			open; | 
 | 148 | 	bool			valid;		/* are the samples valid? */ | 
 | 149 | 	bool			size_detect_done; | 
 | 150 | 	bool			overflow_warned; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 151 | 	int			x_old;		/* last reported x/y, */ | 
 | 152 | 	int			y_old;		/* used for smoothing */ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 153 | 	signed char		xy_cur[ATP_XSENSORS + ATP_YSENSORS]; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 154 | 	signed char		xy_old[ATP_XSENSORS + ATP_YSENSORS]; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 155 | 	int			xy_acc[ATP_XSENSORS + ATP_YSENSORS]; | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 156 | 	int			datalen;	/* size of USB transfer */ | 
 | 157 | 	int			idlecount;	/* number of empty packets */ | 
 | 158 | 	struct work_struct	work; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 159 | }; | 
 | 160 |  | 
 | 161 | #define dbg_dump(msg, tab) \ | 
 | 162 | 	if (debug > 1) {						\ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 163 | 		int __i;						\ | 
 | 164 | 		printk(KERN_DEBUG "appletouch: %s", msg);		\ | 
 | 165 | 		for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++)	\ | 
 | 166 | 			printk(" %02x", tab[__i]);			\ | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 167 | 		printk("\n");						\ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 168 | 	} | 
 | 169 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 170 | #define dprintk(format, a...)						\ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 171 | 	do {								\ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 172 | 		if (debug)						\ | 
 | 173 | 			printk(KERN_DEBUG format, ##a);			\ | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 174 | 	} while (0) | 
 | 175 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 176 | MODULE_AUTHOR("Johannes Berg"); | 
 | 177 | MODULE_AUTHOR("Stelian Pop"); | 
 | 178 | MODULE_AUTHOR("Frank Arnold"); | 
 | 179 | MODULE_AUTHOR("Michael Hanselmann"); | 
 | 180 | MODULE_AUTHOR("Sven Anders"); | 
 | 181 | MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver"); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 182 | MODULE_LICENSE("GPL"); | 
 | 183 |  | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 184 | /* | 
 | 185 |  * Make the threshold a module parameter | 
 | 186 |  */ | 
 | 187 | static int threshold = ATP_THRESHOLD; | 
 | 188 | module_param(threshold, int, 0644); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 189 | MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor" | 
 | 190 | 			    " (the trackpad has many of these sensors)" | 
 | 191 | 			    " less than this value."); | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 192 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 193 | static int debug; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 194 | module_param(debug, int, 0644); | 
 | 195 | MODULE_PARM_DESC(debug, "Activate debugging output"); | 
 | 196 |  | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 197 | /* | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 198 |  * By default newer Geyser devices send standard USB HID mouse | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 199 |  * packets (Report ID 2). This code changes device mode, so it | 
 | 200 |  * sends raw sensor reports (Report ID 5). | 
 | 201 |  */ | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 202 | static int atp_geyser_init(struct usb_device *udev) | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 203 | { | 
 | 204 | 	char data[8]; | 
 | 205 | 	int size; | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 206 | 	int i; | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 207 |  | 
 | 208 | 	size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 209 | 			ATP_GEYSER_MODE_READ_REQUEST_ID, | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 210 | 			USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 211 | 			ATP_GEYSER_MODE_REQUEST_VALUE, | 
 | 212 | 			ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 213 |  | 
 | 214 | 	if (size != 8) { | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 215 | 		dprintk("atp_geyser_init: read error\n"); | 
 | 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."); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 220 | 		return -EIO; | 
 | 221 | 	} | 
 | 222 |  | 
 | 223 | 	/* Apply the mode switch */ | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 224 | 	data[0] = ATP_GEYSER_MODE_VENDOR_VALUE; | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 225 |  | 
 | 226 | 	size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 227 | 			ATP_GEYSER_MODE_WRITE_REQUEST_ID, | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 228 | 			USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 229 | 			ATP_GEYSER_MODE_REQUEST_VALUE, | 
 | 230 | 			ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 231 |  | 
 | 232 | 	if (size != 8) { | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 233 | 		dprintk("atp_geyser_init: write error\n"); | 
 | 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"); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 238 | 		return -EIO; | 
 | 239 | 	} | 
 | 240 | 	return 0; | 
 | 241 | } | 
 | 242 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 243 | /* | 
 | 244 |  * Reinitialise the device. This usually stops stream of empty packets | 
 | 245 |  * coming from it. | 
 | 246 |  */ | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 247 | static void atp_reinit(struct work_struct *work) | 
 | 248 | { | 
 | 249 | 	struct atp *dev = container_of(work, struct atp, work); | 
 | 250 | 	struct usb_device *udev = dev->udev; | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 251 | 	int retval; | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 252 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 253 | 	dprintk("appletouch: putting appletouch to sleep (reinit)\n"); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 254 | 	dev->idlecount = 0; | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 255 |  | 
 | 256 | 	atp_geyser_init(udev); | 
 | 257 |  | 
 | 258 | 	retval = usb_submit_urb(dev->urb, GFP_ATOMIC); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 259 | 	if (retval) | 
 | 260 | 		err("atp_reinit: usb_submit_urb failed with error %d", | 
 | 261 | 		    retval); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 262 | } | 
 | 263 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 264 | static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, | 
 | 265 | 			     int *z, int *fingers) | 
 | 266 | { | 
 | 267 | 	int i; | 
 | 268 | 	/* values to calculate mean */ | 
 | 269 | 	int pcum = 0, psum = 0; | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 270 | 	int is_increasing = 0; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 271 |  | 
 | 272 | 	*fingers = 0; | 
 | 273 |  | 
 | 274 | 	for (i = 0; i < nb_sensors; i++) { | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 275 | 		if (xy_sensors[i] < threshold) { | 
 | 276 | 			if (is_increasing) | 
 | 277 | 				is_increasing = 0; | 
 | 278 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 279 | 			continue; | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 280 | 		} | 
 | 281 |  | 
 | 282 | 		/* | 
 | 283 | 		 * Makes the finger detection more versatile.  For example, | 
 | 284 | 		 * two fingers with no gap will be detected.  Also, my | 
 | 285 | 		 * tests show it less likely to have intermittent loss | 
 | 286 | 		 * of multiple finger readings while moving around (scrolling). | 
 | 287 | 		 * | 
 | 288 | 		 * Changes the multiple finger detection to counting humps on | 
 | 289 | 		 * sensors (transitions from nonincreasing to increasing) | 
 | 290 | 		 * instead of counting transitions from low sensors (no | 
 | 291 | 		 * finger reading) to high sensors (finger above | 
 | 292 | 		 * sensor) | 
 | 293 | 		 * | 
 | 294 | 		 * - Jason Parekh <jasonparekh@gmail.com> | 
 | 295 | 		 */ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 296 | 		if (i < 1 || | 
 | 297 | 		    (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 298 | 			(*fingers)++; | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 299 | 			is_increasing = 1; | 
 | 300 | 		} else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) { | 
 | 301 | 			is_increasing = 0; | 
 | 302 | 		} | 
 | 303 |  | 
 | 304 | 		/* | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 305 | 		 * Subtracts threshold so a high sensor that just passes the | 
 | 306 | 		 * threshold won't skew the calculated absolute coordinate. | 
 | 307 | 		 * Fixes an issue where slowly moving the mouse would | 
 | 308 | 		 * occasionally jump a number of pixels (slowly moving the | 
 | 309 | 		 * finger makes this issue most apparent.) | 
| Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 310 | 		 */ | 
 | 311 | 		pcum += (xy_sensors[i] - threshold) * i; | 
 | 312 | 		psum += (xy_sensors[i] - threshold); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 313 | 	} | 
 | 314 |  | 
 | 315 | 	if (psum > 0) { | 
 | 316 | 		*z = psum; | 
 | 317 | 		return pcum * fact / psum; | 
 | 318 | 	} | 
 | 319 |  | 
 | 320 | 	return 0; | 
 | 321 | } | 
 | 322 |  | 
 | 323 | static inline void atp_report_fingers(struct input_dev *input, int fingers) | 
 | 324 | { | 
 | 325 | 	input_report_key(input, BTN_TOOL_FINGER, fingers == 1); | 
 | 326 | 	input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2); | 
 | 327 | 	input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); | 
 | 328 | } | 
 | 329 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 330 | static void atp_complete(struct urb *urb) | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 331 | { | 
 | 332 | 	int x, y, x_z, y_z, x_f, y_f; | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 333 | 	int retval, i, j; | 
| Thomas Rohwer | cb56073 | 2007-09-25 00:06:25 -0400 | [diff] [blame] | 334 | 	int key; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 335 | 	struct atp *dev = urb->context; | 
 | 336 |  | 
 | 337 | 	switch (urb->status) { | 
 | 338 | 	case 0: | 
 | 339 | 		/* success */ | 
 | 340 | 		break; | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 341 | 	case -EOVERFLOW: | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 342 | 		if (!dev->overflow_warned) { | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 343 | 			printk(KERN_WARNING "appletouch: OVERFLOW with data " | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 344 | 				"length %d, actual length is %d\n", | 
 | 345 | 				dev->datalen, dev->urb->actual_length); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 346 | 			dev->overflow_warned = true; | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 347 | 		} | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 348 | 	case -ECONNRESET: | 
 | 349 | 	case -ENOENT: | 
 | 350 | 	case -ESHUTDOWN: | 
 | 351 | 		/* This urb is terminated, clean up */ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 352 | 		dbg("atp_complete: urb shutting down with status: %d", | 
 | 353 | 		    urb->status); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 354 | 		return; | 
 | 355 | 	default: | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 356 | 		dbg("atp_complete: nonzero urb status received: %d", | 
 | 357 | 		    urb->status); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 358 | 		goto exit; | 
 | 359 | 	} | 
 | 360 |  | 
 | 361 | 	/* drop incomplete datasets */ | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 362 | 	if (dev->urb->actual_length != dev->datalen) { | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 363 | 		dprintk("appletouch: incomplete data package" | 
 | 364 | 			" (first byte: %d, length: %d).\n", | 
 | 365 | 			dev->data[0], dev->urb->actual_length); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 366 | 		goto exit; | 
 | 367 | 	} | 
 | 368 |  | 
 | 369 | 	/* reorder the sensors values */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 370 | 	if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) { | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 371 | 		memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); | 
 | 372 |  | 
 | 373 | 		/* | 
 | 374 | 		 * The values are laid out like this: | 
 | 375 | 		 * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ... | 
 | 376 | 		 * '-' is an unused value. | 
 | 377 | 		 */ | 
 | 378 |  | 
 | 379 | 		/* read X values */ | 
 | 380 | 		for (i = 0, j = 19; i < 20; i += 2, j += 3) { | 
 | 381 | 			dev->xy_cur[i] = dev->data[j + 1]; | 
 | 382 | 			dev->xy_cur[i + 1] = dev->data[j + 2]; | 
 | 383 | 		} | 
 | 384 | 		/* read Y values */ | 
 | 385 | 		for (i = 0, j = 1; i < 9; i += 2, j += 3) { | 
 | 386 | 			dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; | 
 | 387 | 			dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; | 
 | 388 | 		} | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 389 | 	} else if (dev->type == ATP_GEYSER2) { | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 390 | 		memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 391 |  | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 392 | 		/* | 
 | 393 | 		 * The values are laid out like this: | 
 | 394 | 		 * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ... | 
 | 395 | 		 * '-' is an unused value. | 
 | 396 | 		 */ | 
 | 397 |  | 
 | 398 | 		/* read X values */ | 
 | 399 | 		for (i = 0, j = 19; i < 20; i += 2, j += 3) { | 
 | 400 | 			dev->xy_cur[i] = dev->data[j]; | 
 | 401 | 			dev->xy_cur[i + 1] = dev->data[j + 1]; | 
 | 402 | 		} | 
 | 403 |  | 
 | 404 | 		/* read Y values */ | 
 | 405 | 		for (i = 0, j = 1; i < 9; i += 2, j += 3) { | 
 | 406 | 			dev->xy_cur[ATP_XSENSORS + i] = dev->data[j]; | 
 | 407 | 			dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1]; | 
 | 408 | 		} | 
 | 409 | 	} else { | 
 | 410 | 		for (i = 0; i < 8; i++) { | 
 | 411 | 			/* X values */ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 412 | 			dev->xy_cur[i +  0] = dev->data[5 * i +  2]; | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 413 | 			dev->xy_cur[i +  8] = dev->data[5 * i +  4]; | 
 | 414 | 			dev->xy_cur[i + 16] = dev->data[5 * i + 42]; | 
 | 415 | 			if (i < 2) | 
 | 416 | 				dev->xy_cur[i + 24] = dev->data[5 * i + 44]; | 
 | 417 |  | 
 | 418 | 			/* Y values */ | 
 | 419 | 			dev->xy_cur[i + 26] = dev->data[5 * i +  1]; | 
 | 420 | 			dev->xy_cur[i + 34] = dev->data[5 * i +  3]; | 
 | 421 | 		} | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 422 | 	} | 
 | 423 |  | 
 | 424 | 	dbg_dump("sample", dev->xy_cur); | 
 | 425 |  | 
 | 426 | 	if (!dev->valid) { | 
 | 427 | 		/* first sample */ | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 428 | 		dev->valid = true; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 429 | 		dev->x_old = dev->y_old = -1; | 
 | 430 | 		memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); | 
 | 431 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 432 | 		if (dev->size_detect_done || | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 433 | 		    dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */ | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 434 | 			goto exit; | 
 | 435 |  | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 436 | 		/* 17" Powerbooks have extra X sensors */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 437 | 		for (i = (dev->type == ATP_GEYSER2 ? 15 : 16); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 438 | 		     i < ATP_XSENSORS; i++) { | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 439 | 			if (!dev->xy_cur[i]) | 
 | 440 | 				continue; | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 441 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 442 | 			printk(KERN_INFO "appletouch: 17\" model detected.\n"); | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 443 | 			if (dev->type == ATP_GEYSER2) | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 444 | 				input_set_abs_params(dev->input, ABS_X, 0, | 
 | 445 | 						     (20 - 1) * | 
 | 446 | 						     ATP_XFACT - 1, | 
 | 447 | 						     ATP_FUZZ, 0); | 
 | 448 | 			else | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 449 | 				input_set_abs_params(dev->input, ABS_X, 0, | 
 | 450 | 						     (ATP_XSENSORS - 1) * | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 451 | 						     ATP_XFACT - 1, | 
 | 452 | 						     ATP_FUZZ, 0); | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 453 | 			break; | 
 | 454 | 		} | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 455 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 456 | 		dev->size_detect_done = 1; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 457 | 		goto exit; | 
 | 458 | 	} | 
 | 459 |  | 
 | 460 | 	for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { | 
 | 461 | 		/* accumulate the change */ | 
 | 462 | 		signed char change = dev->xy_old[i] - dev->xy_cur[i]; | 
 | 463 | 		dev->xy_acc[i] -= change; | 
 | 464 |  | 
 | 465 | 		/* prevent down drifting */ | 
 | 466 | 		if (dev->xy_acc[i] < 0) | 
 | 467 | 			dev->xy_acc[i] = 0; | 
 | 468 | 	} | 
 | 469 |  | 
 | 470 | 	memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); | 
 | 471 |  | 
 | 472 | 	dbg_dump("accumulator", dev->xy_acc); | 
 | 473 |  | 
 | 474 | 	x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS, | 
 | 475 | 			      ATP_XFACT, &x_z, &x_f); | 
 | 476 | 	y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, | 
 | 477 | 			      ATP_YFACT, &y_z, &y_f); | 
| Thomas Rohwer | cb56073 | 2007-09-25 00:06:25 -0400 | [diff] [blame] | 478 | 	key = dev->data[dev->datalen - 1] & 1; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 479 |  | 
 | 480 | 	if (x && y) { | 
 | 481 | 		if (dev->x_old != -1) { | 
 | 482 | 			x = (dev->x_old * 3 + x) >> 2; | 
 | 483 | 			y = (dev->y_old * 3 + y) >> 2; | 
 | 484 | 			dev->x_old = x; | 
 | 485 | 			dev->y_old = y; | 
 | 486 |  | 
 | 487 | 			if (debug > 1) | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 488 | 				printk(KERN_DEBUG "appletouch: X: %3d Y: %3d " | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 489 | 				       "Xz: %3d Yz: %3d\n", | 
 | 490 | 				       x, y, x_z, y_z); | 
 | 491 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 492 | 			input_report_key(dev->input, BTN_TOUCH, 1); | 
 | 493 | 			input_report_abs(dev->input, ABS_X, x); | 
 | 494 | 			input_report_abs(dev->input, ABS_Y, y); | 
 | 495 | 			input_report_abs(dev->input, ABS_PRESSURE, | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 496 | 					 min(ATP_PRESSURE, x_z + y_z)); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 497 | 			atp_report_fingers(dev->input, max(x_f, y_f)); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 498 | 		} | 
 | 499 | 		dev->x_old = x; | 
 | 500 | 		dev->y_old = y; | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 501 |  | 
 | 502 | 	} else if (!x && !y) { | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 503 |  | 
 | 504 | 		dev->x_old = dev->y_old = -1; | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 505 | 		input_report_key(dev->input, BTN_TOUCH, 0); | 
 | 506 | 		input_report_abs(dev->input, ABS_PRESSURE, 0); | 
 | 507 | 		atp_report_fingers(dev->input, 0); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 508 |  | 
 | 509 | 		/* reset the accumulator on release */ | 
 | 510 | 		memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); | 
| Soeren Sonnenburg | 937ad5c | 2007-10-13 00:31:15 -0400 | [diff] [blame] | 511 | 	} | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 512 |  | 
| Anton Ekblad | 46249ea | 2007-10-22 00:59:59 -0400 | [diff] [blame] | 513 | 	input_report_key(dev->input, BTN_LEFT, key); | 
 | 514 | 	input_sync(dev->input); | 
 | 515 |  | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 516 | 	/* | 
 | 517 | 	 * Many Geysers will continue to send packets continually after | 
 | 518 | 	 * the first touch unless reinitialised. Do so if it's been | 
 | 519 | 	 * idle for a while in order to avoid waking the kernel up | 
 | 520 | 	 * several hundred times a second. Re-initialization does not | 
 | 521 | 	 * work on Fountain touchpads. | 
 | 522 | 	 */ | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 523 | 	if (dev->type != ATP_FOUNTAIN) { | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 524 | 		/* | 
 | 525 | 		 * Button must not be pressed when entering suspend, | 
 | 526 | 		 * otherwise we will never release the button. | 
 | 527 | 		 */ | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 528 | 		if (!x && !y && !key) { | 
 | 529 | 			dev->idlecount++; | 
 | 530 | 			if (dev->idlecount == 10) { | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 531 | 				dev->valid = false; | 
| Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 532 | 				schedule_work(&dev->work); | 
 | 533 | 				/* Don't resubmit urb here, wait for reinit */ | 
 | 534 | 				return; | 
 | 535 | 			} | 
 | 536 | 		} else | 
 | 537 | 			dev->idlecount = 0; | 
 | 538 | 	} | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 539 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 540 |  exit: | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 541 | 	retval = usb_submit_urb(dev->urb, GFP_ATOMIC); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 542 | 	if (retval) | 
 | 543 | 		err("atp_complete: usb_submit_urb failed with result %d", | 
 | 544 | 		    retval); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 545 | } | 
 | 546 |  | 
 | 547 | static int atp_open(struct input_dev *input) | 
 | 548 | { | 
| Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 549 | 	struct atp *dev = input_get_drvdata(input); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 550 |  | 
 | 551 | 	if (usb_submit_urb(dev->urb, GFP_ATOMIC)) | 
 | 552 | 		return -EIO; | 
 | 553 |  | 
 | 554 | 	dev->open = 1; | 
 | 555 | 	return 0; | 
 | 556 | } | 
 | 557 |  | 
 | 558 | static void atp_close(struct input_dev *input) | 
 | 559 | { | 
| Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 560 | 	struct atp *dev = input_get_drvdata(input); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 561 |  | 
 | 562 | 	usb_kill_urb(dev->urb); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 563 | 	cancel_work_sync(&dev->work); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 564 | 	dev->open = 0; | 
 | 565 | } | 
 | 566 |  | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 567 | static int atp_handle_geyser(struct atp *dev) | 
 | 568 | { | 
 | 569 | 	struct usb_device *udev = dev->udev; | 
 | 570 |  | 
| Dmitry Torokhov | 15439dd | 2008-06-17 12:02:44 -0400 | [diff] [blame] | 571 | 	if (dev->type != ATP_FOUNTAIN) { | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 572 | 		/* switch to raw sensor mode */ | 
 | 573 | 		if (atp_geyser_init(udev)) | 
 | 574 | 			return -EIO; | 
 | 575 |  | 
 | 576 | 		printk(KERN_INFO "appletouch: Geyser mode initialized.\n"); | 
 | 577 | 	} | 
 | 578 |  | 
 | 579 | 	return 0; | 
 | 580 | } | 
 | 581 |  | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 582 | static int atp_probe(struct usb_interface *iface, | 
 | 583 | 		     const struct usb_device_id *id) | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 584 | { | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 585 | 	struct atp *dev; | 
 | 586 | 	struct input_dev *input_dev; | 
 | 587 | 	struct usb_device *udev = interface_to_usbdev(iface); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 588 | 	struct usb_host_interface *iface_desc; | 
 | 589 | 	struct usb_endpoint_descriptor *endpoint; | 
 | 590 | 	int int_in_endpointAddr = 0; | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 591 | 	int i, error = -ENOMEM; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 592 |  | 
 | 593 | 	/* set up the endpoint information */ | 
 | 594 | 	/* use only the first interrupt-in endpoint */ | 
 | 595 | 	iface_desc = iface->cur_altsetting; | 
 | 596 | 	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { | 
 | 597 | 		endpoint = &iface_desc->endpoint[i].desc; | 
| Luiz Fernando N. Capitulino | 97b107c | 2006-09-27 11:58:53 -0700 | [diff] [blame] | 598 | 		if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) { | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 599 | 			/* we found an interrupt in endpoint */ | 
 | 600 | 			int_in_endpointAddr = endpoint->bEndpointAddress; | 
 | 601 | 			break; | 
 | 602 | 		} | 
 | 603 | 	} | 
 | 604 | 	if (!int_in_endpointAddr) { | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 605 | 		err("Could not find int-in endpoint"); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 606 | 		return -EIO; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 607 | 	} | 
 | 608 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 609 | 	/* allocate memory for our device state and initialize it */ | 
 | 610 | 	dev = kzalloc(sizeof(struct atp), GFP_KERNEL); | 
 | 611 | 	input_dev = input_allocate_device(); | 
 | 612 | 	if (!dev || !input_dev) { | 
 | 613 | 		err("Out of memory"); | 
 | 614 | 		goto err_free_devs; | 
 | 615 | 	} | 
 | 616 |  | 
 | 617 | 	dev->udev = udev; | 
 | 618 | 	dev->input = input_dev; | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 619 | 	dev->type = id->driver_info; | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 620 | 	dev->overflow_warned = false; | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 621 | 	if (dev->type == ATP_FOUNTAIN || dev->type == ATP_GEYSER1) | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 622 | 		dev->datalen = 81; | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 623 | 	else | 
 | 624 | 		dev->datalen = 64; | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 625 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 626 | 	dev->urb = usb_alloc_urb(0, GFP_KERNEL); | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 627 | 	if (!dev->urb) | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 628 | 		goto err_free_devs; | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 629 |  | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 630 | 	dev->data = usb_buffer_alloc(dev->udev, dev->datalen, GFP_KERNEL, | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 631 | 				     &dev->urb->transfer_dma); | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 632 | 	if (!dev->data) | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 633 | 		goto err_free_urb; | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 634 |  | 
 | 635 | 	usb_fill_int_urb(dev->urb, udev, | 
 | 636 | 			 usb_rcvintpipe(udev, int_in_endpointAddr), | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 637 | 			 dev->data, dev->datalen, atp_complete, dev, 1); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 638 |  | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 639 | 	error = atp_handle_geyser(dev); | 
 | 640 | 	if (error) | 
 | 641 | 		goto err_free_buffer; | 
 | 642 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 643 | 	usb_make_path(udev, dev->phys, sizeof(dev->phys)); | 
 | 644 | 	strlcat(dev->phys, "/input0", sizeof(dev->phys)); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 645 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 646 | 	input_dev->name = "appletouch"; | 
 | 647 | 	input_dev->phys = dev->phys; | 
 | 648 | 	usb_to_input_id(dev->udev, &input_dev->id); | 
| Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 649 | 	input_dev->dev.parent = &iface->dev; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 650 |  | 
| Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 651 | 	input_set_drvdata(input_dev, dev); | 
 | 652 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 653 | 	input_dev->open = atp_open; | 
 | 654 | 	input_dev->close = atp_close; | 
 | 655 |  | 
 | 656 | 	set_bit(EV_ABS, input_dev->evbit); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 657 |  | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 658 | 	if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) { | 
| Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 659 | 		/* | 
 | 660 | 		 * MacBook have 20 X sensors, 10 Y sensors | 
 | 661 | 		 */ | 
 | 662 | 		input_set_abs_params(input_dev, ABS_X, 0, | 
 | 663 | 				     ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0); | 
 | 664 | 		input_set_abs_params(input_dev, ABS_Y, 0, | 
 | 665 | 				     ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0); | 
| Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 666 | 	} else if (dev->type == ATP_GEYSER2) { | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 667 | 		/* | 
 | 668 | 		 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected | 
 | 669 | 		 * later. | 
 | 670 | 		 */ | 
 | 671 | 		input_set_abs_params(input_dev, ABS_X, 0, | 
 | 672 | 				     ((15 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0); | 
 | 673 | 		input_set_abs_params(input_dev, ABS_Y, 0, | 
 | 674 | 				     ((9 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0); | 
 | 675 | 	} else { | 
 | 676 | 		/* | 
 | 677 | 		 * 12" and 15" Powerbooks only have 16 x sensors, | 
 | 678 | 		 * 17" models are detected later. | 
 | 679 | 		 */ | 
 | 680 | 		input_set_abs_params(input_dev, ABS_X, 0, | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 681 | 				     (16 - 1) * ATP_XFACT - 1, | 
 | 682 | 				     ATP_FUZZ, 0); | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 683 | 		input_set_abs_params(input_dev, ABS_Y, 0, | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 684 | 				     (ATP_YSENSORS - 1) * ATP_YFACT - 1, | 
 | 685 | 				     ATP_FUZZ, 0); | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 686 | 	} | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 687 | 	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] | 688 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 689 | 	set_bit(EV_KEY, input_dev->evbit); | 
 | 690 | 	set_bit(BTN_TOUCH, input_dev->keybit); | 
 | 691 | 	set_bit(BTN_TOOL_FINGER, input_dev->keybit); | 
 | 692 | 	set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); | 
 | 693 | 	set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); | 
 | 694 | 	set_bit(BTN_LEFT, input_dev->keybit); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 695 |  | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 696 | 	error = input_register_device(dev->input); | 
 | 697 | 	if (error) | 
 | 698 | 		goto err_free_buffer; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 699 |  | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 700 | 	/* save our data pointer in this interface device */ | 
 | 701 | 	usb_set_intfdata(iface, dev); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 702 |  | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 703 | 	INIT_WORK(&dev->work, atp_reinit); | 
 | 704 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 705 | 	return 0; | 
 | 706 |  | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 707 |  err_free_buffer: | 
 | 708 | 	usb_buffer_free(dev->udev, dev->datalen, | 
 | 709 | 			dev->data, dev->urb->transfer_dma); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 710 |  err_free_urb: | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 711 | 	usb_free_urb(dev->urb); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 712 |  err_free_devs: | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 713 | 	usb_set_intfdata(iface, NULL); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 714 | 	kfree(dev); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 715 | 	input_free_device(input_dev); | 
| Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 716 | 	return error; | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 717 | } | 
 | 718 |  | 
 | 719 | static void atp_disconnect(struct usb_interface *iface) | 
 | 720 | { | 
 | 721 | 	struct atp *dev = usb_get_intfdata(iface); | 
 | 722 |  | 
 | 723 | 	usb_set_intfdata(iface, NULL); | 
 | 724 | 	if (dev) { | 
 | 725 | 		usb_kill_urb(dev->urb); | 
| Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 726 | 		input_unregister_device(dev->input); | 
| Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 727 | 		usb_buffer_free(dev->udev, dev->datalen, | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 728 | 				dev->data, dev->urb->transfer_dma); | 
| Johannes Berg | 7af569a | 2006-07-19 15:39:46 +0200 | [diff] [blame] | 729 | 		usb_free_urb(dev->urb); | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 730 | 		kfree(dev); | 
 | 731 | 	} | 
 | 732 | 	printk(KERN_INFO "input: appletouch disconnected\n"); | 
 | 733 | } | 
 | 734 |  | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 735 | static int atp_recover(struct atp *dev) | 
 | 736 | { | 
 | 737 | 	int error; | 
 | 738 |  | 
 | 739 | 	error = atp_handle_geyser(dev); | 
 | 740 | 	if (error) | 
 | 741 | 		return error; | 
 | 742 |  | 
 | 743 | 	if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) | 
 | 744 | 		return -EIO; | 
 | 745 |  | 
 | 746 | 	return 0; | 
 | 747 | } | 
 | 748 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 749 | static int atp_suspend(struct usb_interface *iface, pm_message_t message) | 
 | 750 | { | 
 | 751 | 	struct atp *dev = usb_get_intfdata(iface); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 752 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 753 | 	usb_kill_urb(dev->urb); | 
| Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 754 | 	dev->valid = false; | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 755 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 756 | 	return 0; | 
 | 757 | } | 
 | 758 |  | 
 | 759 | static int atp_resume(struct usb_interface *iface) | 
 | 760 | { | 
 | 761 | 	struct atp *dev = usb_get_intfdata(iface); | 
| Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 762 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 763 | 	if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) | 
 | 764 | 		return -EIO; | 
 | 765 |  | 
 | 766 | 	return 0; | 
 | 767 | } | 
 | 768 |  | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 769 | static int atp_reset_resume(struct usb_interface *iface) | 
 | 770 | { | 
 | 771 | 	struct atp *dev = usb_get_intfdata(iface); | 
 | 772 |  | 
 | 773 | 	return atp_recover(dev); | 
 | 774 | } | 
 | 775 |  | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 776 | static struct usb_driver atp_driver = { | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 777 | 	.name		= "appletouch", | 
 | 778 | 	.probe		= atp_probe, | 
 | 779 | 	.disconnect	= atp_disconnect, | 
 | 780 | 	.suspend	= atp_suspend, | 
 | 781 | 	.resume		= atp_resume, | 
| Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 782 | 	.reset_resume	= atp_reset_resume, | 
| Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 783 | 	.id_table	= atp_table, | 
 | 784 | }; | 
 | 785 |  | 
 | 786 | static int __init atp_init(void) | 
 | 787 | { | 
 | 788 | 	return usb_register(&atp_driver); | 
 | 789 | } | 
 | 790 |  | 
 | 791 | static void __exit atp_exit(void) | 
 | 792 | { | 
 | 793 | 	usb_deregister(&atp_driver); | 
 | 794 | } | 
 | 795 |  | 
 | 796 | module_init(atp_init); | 
 | 797 | module_exit(atp_exit); |