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 | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 6 | * Copyright (C) 2005-2008 Stelian Pop (stelian@popies.net) |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 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> |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 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 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 37 | /* |
| 38 | * Note: We try to keep the touchpad aspect ratio while still doing only |
| 39 | * simple arithmetics: |
| 40 | * 0 <= x <= (xsensors - 1) * xfact |
| 41 | * 0 <= y <= (ysensors - 1) * yfact |
| 42 | */ |
| 43 | struct atp_info { |
| 44 | int xsensors; /* number of X sensors */ |
| 45 | int xsensors_17; /* 17" models have more sensors */ |
| 46 | int ysensors; /* number of Y sensors */ |
| 47 | int xfact; /* X multiplication factor */ |
| 48 | int yfact; /* Y multiplication factor */ |
| 49 | int datalen; /* size of USB transfers */ |
| 50 | void (*callback)(struct urb *); /* callback function */ |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 51 | int fuzz; /* fuzz touchpad generates */ |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 52 | }; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 53 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 54 | static void atp_complete_geyser_1_2(struct urb *urb); |
| 55 | static void atp_complete_geyser_3_4(struct urb *urb); |
| 56 | |
| 57 | static const struct atp_info fountain_info = { |
| 58 | .xsensors = 16, |
| 59 | .xsensors_17 = 26, |
| 60 | .ysensors = 16, |
| 61 | .xfact = 64, |
| 62 | .yfact = 43, |
| 63 | .datalen = 81, |
| 64 | .callback = atp_complete_geyser_1_2, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 65 | .fuzz = 16, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static const struct atp_info geyser1_info = { |
| 69 | .xsensors = 16, |
| 70 | .xsensors_17 = 26, |
| 71 | .ysensors = 16, |
| 72 | .xfact = 64, |
| 73 | .yfact = 43, |
| 74 | .datalen = 81, |
| 75 | .callback = atp_complete_geyser_1_2, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 76 | .fuzz = 16, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const struct atp_info geyser2_info = { |
| 80 | .xsensors = 15, |
| 81 | .xsensors_17 = 20, |
| 82 | .ysensors = 9, |
| 83 | .xfact = 64, |
| 84 | .yfact = 43, |
| 85 | .datalen = 64, |
| 86 | .callback = atp_complete_geyser_1_2, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 87 | .fuzz = 0, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static const struct atp_info geyser3_info = { |
| 91 | .xsensors = 20, |
| 92 | .ysensors = 10, |
| 93 | .xfact = 64, |
| 94 | .yfact = 64, |
| 95 | .datalen = 64, |
| 96 | .callback = atp_complete_geyser_3_4, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 97 | .fuzz = 0, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static const struct atp_info geyser4_info = { |
| 101 | .xsensors = 20, |
| 102 | .ysensors = 10, |
| 103 | .xfact = 64, |
| 104 | .yfact = 64, |
| 105 | .datalen = 64, |
| 106 | .callback = atp_complete_geyser_3_4, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 107 | .fuzz = 0, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #define ATP_DEVICE(prod, info) \ |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 111 | { \ |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 112 | .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 113 | USB_DEVICE_ID_MATCH_INT_CLASS | \ |
| 114 | USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 115 | .idVendor = 0x05ac, /* Apple */ \ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 116 | .idProduct = (prod), \ |
| 117 | .bInterfaceClass = 0x03, \ |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 118 | .bInterfaceProtocol = 0x02, \ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 119 | .driver_info = (unsigned long) &info, \ |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 120 | } |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 121 | |
Sven Anders | e9542df | 2008-05-05 23:57:10 -0400 | [diff] [blame] | 122 | /* |
| 123 | * Table of devices (Product IDs) that work with this driver. |
| 124 | * (The names come from Info.plist in AppleUSBTrackpad.kext, |
| 125 | * According to Info.plist Geyser IV is the same as Geyser III.) |
| 126 | */ |
| 127 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 128 | static struct usb_device_id atp_table[] = { |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 129 | /* PowerBooks Feb 2005, iBooks G4 */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 130 | ATP_DEVICE(0x020e, fountain_info), /* FOUNTAIN ANSI */ |
| 131 | ATP_DEVICE(0x020f, fountain_info), /* FOUNTAIN ISO */ |
| 132 | ATP_DEVICE(0x030a, fountain_info), /* FOUNTAIN TP ONLY */ |
| 133 | ATP_DEVICE(0x030b, geyser1_info), /* GEYSER 1 TP ONLY */ |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 134 | |
| 135 | /* PowerBooks Oct 2005 */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 136 | ATP_DEVICE(0x0214, geyser2_info), /* GEYSER 2 ANSI */ |
| 137 | ATP_DEVICE(0x0215, geyser2_info), /* GEYSER 2 ISO */ |
| 138 | ATP_DEVICE(0x0216, geyser2_info), /* GEYSER 2 JIS */ |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 139 | |
Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 140 | /* Core Duo MacBook & MacBook Pro */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 141 | ATP_DEVICE(0x0217, geyser3_info), /* GEYSER 3 ANSI */ |
| 142 | ATP_DEVICE(0x0218, geyser3_info), /* GEYSER 3 ISO */ |
| 143 | ATP_DEVICE(0x0219, geyser3_info), /* GEYSER 3 JIS */ |
Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 144 | |
Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 145 | /* Core2 Duo MacBook & MacBook Pro */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 146 | ATP_DEVICE(0x021a, geyser4_info), /* GEYSER 4 ANSI */ |
| 147 | ATP_DEVICE(0x021b, geyser4_info), /* GEYSER 4 ISO */ |
| 148 | ATP_DEVICE(0x021c, geyser4_info), /* GEYSER 4 JIS */ |
Julien BLACHE | 009ad0e | 2006-11-17 01:06:13 -0500 | [diff] [blame] | 149 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 150 | /* Core2 Duo MacBook3,1 */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 151 | ATP_DEVICE(0x0229, geyser4_info), /* GEYSER 4 HF ANSI */ |
| 152 | ATP_DEVICE(0x022a, geyser4_info), /* GEYSER 4 HF ISO */ |
| 153 | ATP_DEVICE(0x022b, geyser4_info), /* GEYSER 4 HF JIS */ |
Tobias Mueller | 0035a1d | 2008-04-02 10:02:06 -0400 | [diff] [blame] | 154 | |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 155 | /* Terminating entry */ |
| 156 | { } |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 157 | }; |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 158 | MODULE_DEVICE_TABLE(usb, atp_table); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 159 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 160 | /* maximum number of sensors */ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 161 | #define ATP_XSENSORS 26 |
| 162 | #define ATP_YSENSORS 16 |
| 163 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 164 | /* maximum pressure this driver will report */ |
| 165 | #define ATP_PRESSURE 300 |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is |
| 169 | * ignored. |
| 170 | */ |
| 171 | #define ATP_THRESHOLD 5 |
| 172 | |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 173 | /* Geyser initialization constants */ |
| 174 | #define ATP_GEYSER_MODE_READ_REQUEST_ID 1 |
| 175 | #define ATP_GEYSER_MODE_WRITE_REQUEST_ID 9 |
| 176 | #define ATP_GEYSER_MODE_REQUEST_VALUE 0x300 |
| 177 | #define ATP_GEYSER_MODE_REQUEST_INDEX 0 |
| 178 | #define ATP_GEYSER_MODE_VENDOR_VALUE 0x04 |
Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 179 | |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 180 | /** |
| 181 | * enum atp_status_bits - status bit meanings |
| 182 | * |
| 183 | * These constants represent the meaning of the status bits. |
| 184 | * (only Geyser 3/4) |
| 185 | * |
| 186 | * @ATP_STATUS_BUTTON: The button was pressed |
| 187 | * @ATP_STATUS_BASE_UPDATE: Update of the base values (untouched pad) |
| 188 | * @ATP_STATUS_FROM_RESET: Reset previously performed |
| 189 | */ |
| 190 | enum atp_status_bits { |
| 191 | ATP_STATUS_BUTTON = BIT(0), |
| 192 | ATP_STATUS_BASE_UPDATE = BIT(2), |
| 193 | ATP_STATUS_FROM_RESET = BIT(4), |
| 194 | }; |
| 195 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 196 | /* Structure to hold all of our device specific stuff */ |
| 197 | struct atp { |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 198 | char phys[64]; |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 199 | struct usb_device *udev; /* usb device */ |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 200 | struct usb_interface *intf; /* usb interface */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 201 | struct urb *urb; /* usb request block */ |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 202 | u8 *data; /* transferred data */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 203 | struct input_dev *input; /* input dev */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 204 | const struct atp_info *info; /* touchpad model */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 205 | bool open; |
| 206 | bool valid; /* are the samples valid? */ |
| 207 | bool size_detect_done; |
| 208 | bool overflow_warned; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 209 | int x_old; /* last reported x/y, */ |
| 210 | int y_old; /* used for smoothing */ |
Benjamin Herrenschmidt | 6e49c1a | 2010-08-09 13:48:08 +1000 | [diff] [blame] | 211 | signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS]; |
| 212 | signed char xy_old[ATP_XSENSORS + ATP_YSENSORS]; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 213 | int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 214 | int idlecount; /* number of empty packets */ |
| 215 | struct work_struct work; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | #define dbg_dump(msg, tab) \ |
| 219 | if (debug > 1) { \ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 220 | int __i; \ |
| 221 | printk(KERN_DEBUG "appletouch: %s", msg); \ |
| 222 | for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \ |
| 223 | printk(" %02x", tab[__i]); \ |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 224 | printk("\n"); \ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 227 | #define dprintk(format, a...) \ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 228 | do { \ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 229 | if (debug) \ |
| 230 | printk(KERN_DEBUG format, ##a); \ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 231 | } while (0) |
| 232 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 233 | MODULE_AUTHOR("Johannes Berg"); |
| 234 | MODULE_AUTHOR("Stelian Pop"); |
| 235 | MODULE_AUTHOR("Frank Arnold"); |
| 236 | MODULE_AUTHOR("Michael Hanselmann"); |
| 237 | MODULE_AUTHOR("Sven Anders"); |
| 238 | MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver"); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 239 | MODULE_LICENSE("GPL"); |
| 240 | |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 241 | /* |
| 242 | * Make the threshold a module parameter |
| 243 | */ |
| 244 | static int threshold = ATP_THRESHOLD; |
| 245 | module_param(threshold, int, 0644); |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 246 | MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor" |
| 247 | " (the trackpad has many of these sensors)" |
| 248 | " less than this value."); |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 249 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 250 | static int debug; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 251 | module_param(debug, int, 0644); |
| 252 | MODULE_PARM_DESC(debug, "Activate debugging output"); |
| 253 | |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 254 | /* |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 255 | * By default newer Geyser devices send standard USB HID mouse |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 256 | * packets (Report ID 2). This code changes device mode, so it |
| 257 | * sends raw sensor reports (Report ID 5). |
| 258 | */ |
Greg Kroah-Hartman | 80f8594 | 2012-05-01 20:56:47 -0400 | [diff] [blame] | 259 | static int atp_geyser_init(struct atp *dev) |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 260 | { |
Greg Kroah-Hartman | 80f8594 | 2012-05-01 20:56:47 -0400 | [diff] [blame] | 261 | struct usb_device *udev = dev->udev; |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 262 | char *data; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 263 | int size; |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 264 | int i; |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 265 | int ret; |
| 266 | |
| 267 | data = kmalloc(8, GFP_KERNEL); |
| 268 | if (!data) { |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 269 | dev_err(&dev->intf->dev, "Out of memory\n"); |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 270 | return -ENOMEM; |
| 271 | } |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 272 | |
| 273 | size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 274 | ATP_GEYSER_MODE_READ_REQUEST_ID, |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 275 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 276 | ATP_GEYSER_MODE_REQUEST_VALUE, |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 277 | ATP_GEYSER_MODE_REQUEST_INDEX, data, 8, 5000); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 278 | |
| 279 | if (size != 8) { |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 280 | dprintk("atp_geyser_init: read error\n"); |
| 281 | for (i = 0; i < 8; i++) |
| 282 | dprintk("appletouch[%d]: %d\n", i, data[i]); |
| 283 | |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 284 | dev_err(&dev->intf->dev, "Failed to read mode from device.\n"); |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 285 | ret = -EIO; |
| 286 | goto out_free; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* Apply the mode switch */ |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 290 | data[0] = ATP_GEYSER_MODE_VENDOR_VALUE; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 291 | |
| 292 | size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 293 | ATP_GEYSER_MODE_WRITE_REQUEST_ID, |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 294 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 295 | ATP_GEYSER_MODE_REQUEST_VALUE, |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 296 | ATP_GEYSER_MODE_REQUEST_INDEX, data, 8, 5000); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 297 | |
| 298 | if (size != 8) { |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 299 | dprintk("atp_geyser_init: write error\n"); |
| 300 | for (i = 0; i < 8; i++) |
| 301 | dprintk("appletouch[%d]: %d\n", i, data[i]); |
| 302 | |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 303 | dev_err(&dev->intf->dev, "Failed to request geyser raw mode\n"); |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 304 | ret = -EIO; |
| 305 | goto out_free; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 306 | } |
Bob Copeland | 0385c5e | 2009-04-28 07:49:53 -0700 | [diff] [blame] | 307 | ret = 0; |
| 308 | out_free: |
| 309 | kfree(data); |
| 310 | return ret; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 311 | } |
| 312 | |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 313 | /* |
| 314 | * Reinitialise the device. This usually stops stream of empty packets |
| 315 | * coming from it. |
| 316 | */ |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 317 | static void atp_reinit(struct work_struct *work) |
| 318 | { |
| 319 | struct atp *dev = container_of(work, struct atp, work); |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 320 | int retval; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 321 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 322 | dprintk("appletouch: putting appletouch to sleep (reinit)\n"); |
Greg Kroah-Hartman | 80f8594 | 2012-05-01 20:56:47 -0400 | [diff] [blame] | 323 | atp_geyser_init(dev); |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 324 | |
| 325 | retval = usb_submit_urb(dev->urb, GFP_ATOMIC); |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 326 | if (retval) |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 327 | dev_err(&dev->intf->dev, |
Greg Kroah-Hartman | 9c113dc | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 328 | "atp_reinit: usb_submit_urb failed with error %d\n", |
| 329 | retval); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 330 | } |
| 331 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 332 | static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, |
| 333 | int *z, int *fingers) |
| 334 | { |
| 335 | int i; |
| 336 | /* values to calculate mean */ |
| 337 | int pcum = 0, psum = 0; |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 338 | int is_increasing = 0; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 339 | |
| 340 | *fingers = 0; |
| 341 | |
| 342 | for (i = 0; i < nb_sensors; i++) { |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 343 | if (xy_sensors[i] < threshold) { |
| 344 | if (is_increasing) |
| 345 | is_increasing = 0; |
| 346 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 347 | continue; |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Makes the finger detection more versatile. For example, |
| 352 | * two fingers with no gap will be detected. Also, my |
| 353 | * tests show it less likely to have intermittent loss |
| 354 | * of multiple finger readings while moving around (scrolling). |
| 355 | * |
| 356 | * Changes the multiple finger detection to counting humps on |
| 357 | * sensors (transitions from nonincreasing to increasing) |
| 358 | * instead of counting transitions from low sensors (no |
| 359 | * finger reading) to high sensors (finger above |
| 360 | * sensor) |
| 361 | * |
| 362 | * - Jason Parekh <jasonparekh@gmail.com> |
| 363 | */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 364 | if (i < 1 || |
| 365 | (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 366 | (*fingers)++; |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 367 | is_increasing = 1; |
Jeremy Huddleston | 05e882f | 2009-06-03 07:29:39 -0700 | [diff] [blame] | 368 | } else if (i > 0 && (xy_sensors[i - 1] - xy_sensors[i] > threshold)) { |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 369 | is_increasing = 0; |
| 370 | } |
| 371 | |
| 372 | /* |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 373 | * Subtracts threshold so a high sensor that just passes the |
| 374 | * threshold won't skew the calculated absolute coordinate. |
| 375 | * Fixes an issue where slowly moving the mouse would |
| 376 | * occasionally jump a number of pixels (slowly moving the |
| 377 | * finger makes this issue most apparent.) |
Jason Parekh | 00081d3 | 2006-11-17 01:05:58 -0500 | [diff] [blame] | 378 | */ |
| 379 | pcum += (xy_sensors[i] - threshold) * i; |
| 380 | psum += (xy_sensors[i] - threshold); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | if (psum > 0) { |
| 384 | *z = psum; |
| 385 | return pcum * fact / psum; |
| 386 | } |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static inline void atp_report_fingers(struct input_dev *input, int fingers) |
| 392 | { |
| 393 | input_report_key(input, BTN_TOOL_FINGER, fingers == 1); |
| 394 | input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2); |
| 395 | input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); |
| 396 | } |
| 397 | |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 398 | /* Check URB status and for correct length of data package */ |
| 399 | |
| 400 | #define ATP_URB_STATUS_SUCCESS 0 |
| 401 | #define ATP_URB_STATUS_ERROR 1 |
| 402 | #define ATP_URB_STATUS_ERROR_FATAL 2 |
| 403 | |
| 404 | static int atp_status_check(struct urb *urb) |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 405 | { |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 406 | struct atp *dev = urb->context; |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 407 | struct usb_interface *intf = dev->intf; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 408 | |
| 409 | switch (urb->status) { |
| 410 | case 0: |
| 411 | /* success */ |
| 412 | break; |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 413 | case -EOVERFLOW: |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 414 | if (!dev->overflow_warned) { |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 415 | dev_warn(&intf->dev, |
Greg Kroah-Hartman | 67946d1 | 2012-05-01 21:33:04 -0700 | [diff] [blame] | 416 | "appletouch: OVERFLOW with data length %d, actual length is %d\n", |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 417 | dev->info->datalen, dev->urb->actual_length); |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 418 | dev->overflow_warned = true; |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 419 | } |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 420 | case -ECONNRESET: |
| 421 | case -ENOENT: |
| 422 | case -ESHUTDOWN: |
| 423 | /* This urb is terminated, clean up */ |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 424 | dev_dbg(&intf->dev, |
Greg Kroah-Hartman | 67946d1 | 2012-05-01 21:33:04 -0700 | [diff] [blame] | 425 | "atp_complete: urb shutting down with status: %d\n", |
| 426 | urb->status); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 427 | return ATP_URB_STATUS_ERROR_FATAL; |
| 428 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 429 | default: |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 430 | dev_dbg(&intf->dev, |
Greg Kroah-Hartman | 67946d1 | 2012-05-01 21:33:04 -0700 | [diff] [blame] | 431 | "atp_complete: nonzero urb status received: %d\n", |
| 432 | urb->status); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 433 | return ATP_URB_STATUS_ERROR; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* drop incomplete datasets */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 437 | if (dev->urb->actual_length != dev->info->datalen) { |
Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 438 | dprintk("appletouch: incomplete data package" |
| 439 | " (first byte: %d, length: %d).\n", |
| 440 | dev->data[0], dev->urb->actual_length); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 441 | return ATP_URB_STATUS_ERROR; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 442 | } |
| 443 | |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 444 | return ATP_URB_STATUS_SUCCESS; |
| 445 | } |
| 446 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 447 | static void atp_detect_size(struct atp *dev) |
| 448 | { |
| 449 | int i; |
| 450 | |
| 451 | /* 17" Powerbooks have extra X sensors */ |
| 452 | for (i = dev->info->xsensors; i < ATP_XSENSORS; i++) { |
| 453 | if (dev->xy_cur[i]) { |
| 454 | |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 455 | dev_info(&dev->intf->dev, |
Greg Kroah-Hartman | 67946d1 | 2012-05-01 21:33:04 -0700 | [diff] [blame] | 456 | "appletouch: 17\" model detected.\n"); |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 457 | |
| 458 | input_set_abs_params(dev->input, ABS_X, 0, |
| 459 | (dev->info->xsensors_17 - 1) * |
| 460 | dev->info->xfact - 1, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 461 | dev->info->fuzz, 0); |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 467 | /* |
| 468 | * USB interrupt callback functions |
| 469 | */ |
| 470 | |
| 471 | /* Interrupt function for older touchpads: FOUNTAIN/GEYSER1/GEYSER2 */ |
| 472 | |
| 473 | static void atp_complete_geyser_1_2(struct urb *urb) |
| 474 | { |
| 475 | int x, y, x_z, y_z, x_f, y_f; |
| 476 | int retval, i, j; |
| 477 | int key; |
| 478 | struct atp *dev = urb->context; |
| 479 | int status = atp_status_check(urb); |
| 480 | |
| 481 | if (status == ATP_URB_STATUS_ERROR_FATAL) |
| 482 | return; |
| 483 | else if (status == ATP_URB_STATUS_ERROR) |
| 484 | goto exit; |
| 485 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 486 | /* reorder the sensors values */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 487 | if (dev->info == &geyser2_info) { |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 488 | memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 489 | |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 490 | /* |
| 491 | * The values are laid out like this: |
| 492 | * Y1, Y2, -, Y3, Y4, -, ..., X1, X2, -, X3, X4, -, ... |
| 493 | * '-' is an unused value. |
| 494 | */ |
| 495 | |
| 496 | /* read X values */ |
| 497 | for (i = 0, j = 19; i < 20; i += 2, j += 3) { |
| 498 | dev->xy_cur[i] = dev->data[j]; |
| 499 | dev->xy_cur[i + 1] = dev->data[j + 1]; |
| 500 | } |
| 501 | |
| 502 | /* read Y values */ |
| 503 | for (i = 0, j = 1; i < 9; i += 2, j += 3) { |
| 504 | dev->xy_cur[ATP_XSENSORS + i] = dev->data[j]; |
| 505 | dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 1]; |
| 506 | } |
| 507 | } else { |
| 508 | for (i = 0; i < 8; i++) { |
| 509 | /* X values */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 510 | dev->xy_cur[i + 0] = dev->data[5 * i + 2]; |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 511 | dev->xy_cur[i + 8] = dev->data[5 * i + 4]; |
| 512 | dev->xy_cur[i + 16] = dev->data[5 * i + 42]; |
| 513 | if (i < 2) |
| 514 | dev->xy_cur[i + 24] = dev->data[5 * i + 44]; |
| 515 | |
| 516 | /* Y values */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 517 | dev->xy_cur[ATP_XSENSORS + i] = dev->data[5 * i + 1]; |
| 518 | dev->xy_cur[ATP_XSENSORS + i + 8] = dev->data[5 * i + 3]; |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 519 | } |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | dbg_dump("sample", dev->xy_cur); |
| 523 | |
| 524 | if (!dev->valid) { |
| 525 | /* first sample */ |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 526 | dev->valid = true; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 527 | dev->x_old = dev->y_old = -1; |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 528 | |
| 529 | /* Store first sample */ |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 530 | memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); |
| 531 | |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 532 | /* Perform size detection, if not done already */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 533 | if (unlikely(!dev->size_detect_done)) { |
| 534 | atp_detect_size(dev); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 535 | dev->size_detect_done = 1; |
Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 536 | goto exit; |
Michael Hanselmann | e1e02c9 | 2005-12-21 00:50:23 -0500 | [diff] [blame] | 537 | } |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 538 | } |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 539 | |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 540 | for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { |
| 541 | /* accumulate the change */ |
Benjamin Herrenschmidt | 6e49c1a | 2010-08-09 13:48:08 +1000 | [diff] [blame] | 542 | signed char change = dev->xy_old[i] - dev->xy_cur[i]; |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 543 | dev->xy_acc[i] -= change; |
| 544 | |
| 545 | /* prevent down drifting */ |
| 546 | if (dev->xy_acc[i] < 0) |
| 547 | dev->xy_acc[i] = 0; |
| 548 | } |
| 549 | |
| 550 | memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); |
| 551 | |
| 552 | dbg_dump("accumulator", dev->xy_acc); |
| 553 | |
| 554 | x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 555 | dev->info->xfact, &x_z, &x_f); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 556 | y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 557 | dev->info->yfact, &y_z, &y_f); |
| 558 | key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON; |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 559 | |
| 560 | if (x && y) { |
| 561 | if (dev->x_old != -1) { |
| 562 | x = (dev->x_old * 3 + x) >> 2; |
| 563 | y = (dev->y_old * 3 + y) >> 2; |
| 564 | dev->x_old = x; |
| 565 | dev->y_old = y; |
| 566 | |
| 567 | if (debug > 1) |
| 568 | printk(KERN_DEBUG "appletouch: " |
| 569 | "X: %3d Y: %3d Xz: %3d Yz: %3d\n", |
| 570 | x, y, x_z, y_z); |
| 571 | |
| 572 | input_report_key(dev->input, BTN_TOUCH, 1); |
| 573 | input_report_abs(dev->input, ABS_X, x); |
| 574 | input_report_abs(dev->input, ABS_Y, y); |
| 575 | input_report_abs(dev->input, ABS_PRESSURE, |
| 576 | min(ATP_PRESSURE, x_z + y_z)); |
| 577 | atp_report_fingers(dev->input, max(x_f, y_f)); |
| 578 | } |
| 579 | dev->x_old = x; |
| 580 | dev->y_old = y; |
| 581 | |
| 582 | } else if (!x && !y) { |
| 583 | |
| 584 | dev->x_old = dev->y_old = -1; |
| 585 | input_report_key(dev->input, BTN_TOUCH, 0); |
| 586 | input_report_abs(dev->input, ABS_PRESSURE, 0); |
| 587 | atp_report_fingers(dev->input, 0); |
| 588 | |
| 589 | /* reset the accumulator on release */ |
| 590 | memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); |
| 591 | } |
| 592 | |
| 593 | input_report_key(dev->input, BTN_LEFT, key); |
| 594 | input_sync(dev->input); |
| 595 | |
| 596 | exit: |
| 597 | retval = usb_submit_urb(dev->urb, GFP_ATOMIC); |
| 598 | if (retval) |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 599 | dev_err(&dev->intf->dev, |
Greg Kroah-Hartman | 9c113dc | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 600 | "atp_complete: usb_submit_urb failed with result %d\n", |
| 601 | retval); |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* Interrupt function for older touchpads: GEYSER3/GEYSER4 */ |
| 605 | |
| 606 | static void atp_complete_geyser_3_4(struct urb *urb) |
| 607 | { |
| 608 | int x, y, x_z, y_z, x_f, y_f; |
| 609 | int retval, i, j; |
| 610 | int key; |
| 611 | struct atp *dev = urb->context; |
| 612 | int status = atp_status_check(urb); |
| 613 | |
| 614 | if (status == ATP_URB_STATUS_ERROR_FATAL) |
| 615 | return; |
| 616 | else if (status == ATP_URB_STATUS_ERROR) |
| 617 | goto exit; |
| 618 | |
| 619 | /* Reorder the sensors values: |
| 620 | * |
| 621 | * The values are laid out like this: |
| 622 | * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ... |
| 623 | * '-' is an unused value. |
| 624 | */ |
| 625 | |
| 626 | /* read X values */ |
| 627 | for (i = 0, j = 19; i < 20; i += 2, j += 3) { |
| 628 | dev->xy_cur[i] = dev->data[j + 1]; |
| 629 | dev->xy_cur[i + 1] = dev->data[j + 2]; |
| 630 | } |
| 631 | /* read Y values */ |
| 632 | for (i = 0, j = 1; i < 9; i += 2, j += 3) { |
| 633 | dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; |
| 634 | dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; |
| 635 | } |
| 636 | |
| 637 | dbg_dump("sample", dev->xy_cur); |
| 638 | |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 639 | /* Just update the base values (i.e. touchpad in untouched state) */ |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 640 | if (dev->data[dev->info->datalen - 1] & ATP_STATUS_BASE_UPDATE) { |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 641 | |
Joe Perches | d745b53 | 2010-10-30 17:19:49 -0700 | [diff] [blame] | 642 | dprintk("appletouch: updated base values\n"); |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 643 | |
| 644 | memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 645 | goto exit; |
| 646 | } |
| 647 | |
| 648 | for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 649 | /* calculate the change */ |
| 650 | dev->xy_acc[i] = dev->xy_cur[i] - dev->xy_old[i]; |
| 651 | |
| 652 | /* this is a round-robin value, so couple with that */ |
| 653 | if (dev->xy_acc[i] > 127) |
| 654 | dev->xy_acc[i] -= 256; |
| 655 | |
| 656 | if (dev->xy_acc[i] < -127) |
| 657 | dev->xy_acc[i] += 256; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 658 | |
| 659 | /* prevent down drifting */ |
| 660 | if (dev->xy_acc[i] < 0) |
| 661 | dev->xy_acc[i] = 0; |
| 662 | } |
| 663 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 664 | dbg_dump("accumulator", dev->xy_acc); |
| 665 | |
| 666 | x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 667 | dev->info->xfact, &x_z, &x_f); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 668 | y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 669 | dev->info->yfact, &y_z, &y_f); |
| 670 | key = dev->data[dev->info->datalen - 1] & ATP_STATUS_BUTTON; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 671 | |
| 672 | if (x && y) { |
| 673 | if (dev->x_old != -1) { |
| 674 | x = (dev->x_old * 3 + x) >> 2; |
| 675 | y = (dev->y_old * 3 + y) >> 2; |
| 676 | dev->x_old = x; |
| 677 | dev->y_old = y; |
| 678 | |
| 679 | if (debug > 1) |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 680 | printk(KERN_DEBUG "appletouch: X: %3d Y: %3d " |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 681 | "Xz: %3d Yz: %3d\n", |
| 682 | x, y, x_z, y_z); |
| 683 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 684 | input_report_key(dev->input, BTN_TOUCH, 1); |
| 685 | input_report_abs(dev->input, ABS_X, x); |
| 686 | input_report_abs(dev->input, ABS_Y, y); |
| 687 | input_report_abs(dev->input, ABS_PRESSURE, |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 688 | min(ATP_PRESSURE, x_z + y_z)); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 689 | atp_report_fingers(dev->input, max(x_f, y_f)); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 690 | } |
| 691 | dev->x_old = x; |
| 692 | dev->y_old = y; |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 693 | |
| 694 | } else if (!x && !y) { |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 695 | |
| 696 | dev->x_old = dev->y_old = -1; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 697 | input_report_key(dev->input, BTN_TOUCH, 0); |
| 698 | input_report_abs(dev->input, ABS_PRESSURE, 0); |
| 699 | atp_report_fingers(dev->input, 0); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 700 | |
| 701 | /* reset the accumulator on release */ |
| 702 | memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); |
Soeren Sonnenburg | 937ad5c | 2007-10-13 00:31:15 -0400 | [diff] [blame] | 703 | } |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 704 | |
Anton Ekblad | 46249ea | 2007-10-22 00:59:59 -0400 | [diff] [blame] | 705 | input_report_key(dev->input, BTN_LEFT, key); |
| 706 | input_sync(dev->input); |
| 707 | |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 708 | /* |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 709 | * Geysers 3/4 will continue to send packets continually after |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 710 | * the first touch unless reinitialised. Do so if it's been |
| 711 | * idle for a while in order to avoid waking the kernel up |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 712 | * several hundred times a second. |
Dmitry Torokhov | 2a3e480 | 2007-11-01 22:13:32 -0400 | [diff] [blame] | 713 | */ |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 714 | |
| 715 | /* |
| 716 | * Button must not be pressed when entering suspend, |
| 717 | * otherwise we will never release the button. |
| 718 | */ |
| 719 | if (!x && !y && !key) { |
| 720 | dev->idlecount++; |
| 721 | if (dev->idlecount == 10) { |
Sven Anders | 82a196f | 2008-08-08 16:31:33 -0400 | [diff] [blame] | 722 | dev->x_old = dev->y_old = -1; |
| 723 | dev->idlecount = 0; |
Sven Anders | d83d213 | 2008-08-08 16:31:31 -0400 | [diff] [blame] | 724 | schedule_work(&dev->work); |
| 725 | /* Don't resubmit urb here, wait for reinit */ |
| 726 | return; |
| 727 | } |
| 728 | } else |
| 729 | dev->idlecount = 0; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 730 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 731 | exit: |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 732 | retval = usb_submit_urb(dev->urb, GFP_ATOMIC); |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 733 | if (retval) |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 734 | dev_err(&dev->intf->dev, |
Greg Kroah-Hartman | 9c113dc | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 735 | "atp_complete: usb_submit_urb failed with result %d\n", |
| 736 | retval); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | static int atp_open(struct input_dev *input) |
| 740 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 741 | struct atp *dev = input_get_drvdata(input); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 742 | |
| 743 | if (usb_submit_urb(dev->urb, GFP_ATOMIC)) |
| 744 | return -EIO; |
| 745 | |
| 746 | dev->open = 1; |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | static void atp_close(struct input_dev *input) |
| 751 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 752 | struct atp *dev = input_get_drvdata(input); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 753 | |
| 754 | usb_kill_urb(dev->urb); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 755 | cancel_work_sync(&dev->work); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 756 | dev->open = 0; |
| 757 | } |
| 758 | |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 759 | static int atp_handle_geyser(struct atp *dev) |
| 760 | { |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 761 | if (dev->info != &fountain_info) { |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 762 | /* switch to raw sensor mode */ |
Greg Kroah-Hartman | 80f8594 | 2012-05-01 20:56:47 -0400 | [diff] [blame] | 763 | if (atp_geyser_init(dev)) |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 764 | return -EIO; |
| 765 | |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 766 | dev_info(&dev->intf->dev, "Geyser mode initialized.\n"); |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 772 | static int atp_probe(struct usb_interface *iface, |
| 773 | const struct usb_device_id *id) |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 774 | { |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 775 | struct atp *dev; |
| 776 | struct input_dev *input_dev; |
| 777 | struct usb_device *udev = interface_to_usbdev(iface); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 778 | struct usb_host_interface *iface_desc; |
| 779 | struct usb_endpoint_descriptor *endpoint; |
| 780 | int int_in_endpointAddr = 0; |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 781 | int i, error = -ENOMEM; |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 782 | const struct atp_info *info = (const struct atp_info *)id->driver_info; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 783 | |
| 784 | /* set up the endpoint information */ |
| 785 | /* use only the first interrupt-in endpoint */ |
| 786 | iface_desc = iface->cur_altsetting; |
| 787 | for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { |
| 788 | endpoint = &iface_desc->endpoint[i].desc; |
Luiz Fernando N. Capitulino | 97b107c | 2006-09-27 11:58:53 -0700 | [diff] [blame] | 789 | if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) { |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 790 | /* we found an interrupt in endpoint */ |
| 791 | int_in_endpointAddr = endpoint->bEndpointAddress; |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | if (!int_in_endpointAddr) { |
Greg Kroah-Hartman | 9c113dc | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 796 | dev_err(&iface->dev, "Could not find int-in endpoint\n"); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 797 | return -EIO; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 798 | } |
| 799 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 800 | /* allocate memory for our device state and initialize it */ |
| 801 | dev = kzalloc(sizeof(struct atp), GFP_KERNEL); |
| 802 | input_dev = input_allocate_device(); |
| 803 | if (!dev || !input_dev) { |
Greg Kroah-Hartman | 9c113dc | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 804 | dev_err(&iface->dev, "Out of memory\n"); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 805 | goto err_free_devs; |
| 806 | } |
| 807 | |
| 808 | dev->udev = udev; |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 809 | dev->intf = iface; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 810 | dev->input = input_dev; |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 811 | dev->info = info; |
Johannes Berg | 7dce869 | 2008-05-05 23:56:55 -0400 | [diff] [blame] | 812 | dev->overflow_warned = false; |
Nicolas Boichat | 9effa97 | 2006-04-19 23:36:40 +0200 | [diff] [blame] | 813 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 814 | dev->urb = usb_alloc_urb(0, GFP_KERNEL); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 815 | if (!dev->urb) |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 816 | goto err_free_devs; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 817 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 818 | dev->data = usb_alloc_coherent(dev->udev, dev->info->datalen, GFP_KERNEL, |
| 819 | &dev->urb->transfer_dma); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 820 | if (!dev->data) |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 821 | goto err_free_urb; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 822 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 823 | usb_fill_int_urb(dev->urb, udev, |
| 824 | usb_rcvintpipe(udev, int_in_endpointAddr), |
| 825 | dev->data, dev->info->datalen, |
| 826 | dev->info->callback, dev, 1); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 827 | |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 828 | error = atp_handle_geyser(dev); |
| 829 | if (error) |
| 830 | goto err_free_buffer; |
| 831 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 832 | usb_make_path(udev, dev->phys, sizeof(dev->phys)); |
| 833 | strlcat(dev->phys, "/input0", sizeof(dev->phys)); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 834 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 835 | input_dev->name = "appletouch"; |
| 836 | input_dev->phys = dev->phys; |
| 837 | usb_to_input_id(dev->udev, &input_dev->id); |
Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 838 | input_dev->dev.parent = &iface->dev; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 839 | |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 840 | input_set_drvdata(input_dev, dev); |
| 841 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 842 | input_dev->open = atp_open; |
| 843 | input_dev->close = atp_close; |
| 844 | |
| 845 | set_bit(EV_ABS, input_dev->evbit); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 846 | |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 847 | input_set_abs_params(input_dev, ABS_X, 0, |
| 848 | (dev->info->xsensors - 1) * dev->info->xfact - 1, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 849 | dev->info->fuzz, 0); |
Stelian Pop | 0977967 | 2008-10-28 23:20:46 -0400 | [diff] [blame] | 850 | input_set_abs_params(input_dev, ABS_Y, 0, |
| 851 | (dev->info->ysensors - 1) * dev->info->yfact - 1, |
Clinton Sprain | 703e148 | 2014-03-26 14:10:43 -0700 | [diff] [blame^] | 852 | dev->info->fuzz, 0); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 853 | 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] | 854 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 855 | set_bit(EV_KEY, input_dev->evbit); |
| 856 | set_bit(BTN_TOUCH, input_dev->keybit); |
| 857 | set_bit(BTN_TOOL_FINGER, input_dev->keybit); |
| 858 | set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); |
| 859 | set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); |
| 860 | set_bit(BTN_LEFT, input_dev->keybit); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 861 | |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 862 | error = input_register_device(dev->input); |
| 863 | if (error) |
| 864 | goto err_free_buffer; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 865 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 866 | /* save our data pointer in this interface device */ |
| 867 | usb_set_intfdata(iface, dev); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 868 | |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 869 | INIT_WORK(&dev->work, atp_reinit); |
| 870 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 871 | return 0; |
| 872 | |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 873 | err_free_buffer: |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 874 | usb_free_coherent(dev->udev, dev->info->datalen, |
| 875 | dev->data, dev->urb->transfer_dma); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 876 | err_free_urb: |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 877 | usb_free_urb(dev->urb); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 878 | err_free_devs: |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 879 | usb_set_intfdata(iface, NULL); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 880 | kfree(dev); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 881 | input_free_device(input_dev); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 882 | return error; |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | static void atp_disconnect(struct usb_interface *iface) |
| 886 | { |
| 887 | struct atp *dev = usb_get_intfdata(iface); |
| 888 | |
| 889 | usb_set_intfdata(iface, NULL); |
| 890 | if (dev) { |
| 891 | usb_kill_urb(dev->urb); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 892 | input_unregister_device(dev->input); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 893 | usb_free_coherent(dev->udev, dev->info->datalen, |
| 894 | dev->data, dev->urb->transfer_dma); |
Johannes Berg | 7af569a | 2006-07-19 15:39:46 +0200 | [diff] [blame] | 895 | usb_free_urb(dev->urb); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 896 | kfree(dev); |
| 897 | } |
Greg Kroah-Hartman | 2d744b0 | 2012-05-04 15:33:01 -0700 | [diff] [blame] | 898 | dev_info(&iface->dev, "input: appletouch disconnected\n"); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 901 | static int atp_recover(struct atp *dev) |
| 902 | { |
| 903 | int error; |
| 904 | |
| 905 | error = atp_handle_geyser(dev); |
| 906 | if (error) |
| 907 | return error; |
| 908 | |
| 909 | if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) |
| 910 | return -EIO; |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 915 | static int atp_suspend(struct usb_interface *iface, pm_message_t message) |
| 916 | { |
| 917 | struct atp *dev = usb_get_intfdata(iface); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 918 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 919 | usb_kill_urb(dev->urb); |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | static int atp_resume(struct usb_interface *iface) |
| 924 | { |
| 925 | struct atp *dev = usb_get_intfdata(iface); |
Soeren Sonnenburg | 5a6eb67 | 2007-07-20 00:29:32 -0400 | [diff] [blame] | 926 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 927 | if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) |
| 928 | return -EIO; |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 933 | static int atp_reset_resume(struct usb_interface *iface) |
| 934 | { |
| 935 | struct atp *dev = usb_get_intfdata(iface); |
| 936 | |
| 937 | return atp_recover(dev); |
| 938 | } |
| 939 | |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 940 | static struct usb_driver atp_driver = { |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 941 | .name = "appletouch", |
| 942 | .probe = atp_probe, |
| 943 | .disconnect = atp_disconnect, |
| 944 | .suspend = atp_suspend, |
| 945 | .resume = atp_resume, |
Oliver Neukum | 90d95ef | 2008-06-17 11:56:55 -0400 | [diff] [blame] | 946 | .reset_resume = atp_reset_resume, |
Stelian Pop | f7214ff | 2005-09-08 10:19:48 +0200 | [diff] [blame] | 947 | .id_table = atp_table, |
| 948 | }; |
| 949 | |
Greg Kroah-Hartman | 08642e7 | 2011-11-18 09:48:31 -0800 | [diff] [blame] | 950 | module_usb_driver(atp_driver); |