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