Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Apple USB BCM5974 (Macbook Air and Penryn Macbook Pro) multitouch driver |
| 3 | * |
| 4 | * Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se) |
| 5 | * |
| 6 | * The USB initialization and package decoding was made by |
| 7 | * Scott Shawcroft as part of the touchd user-space driver project: |
| 8 | * Copyright (C) 2008 Scott Shawcroft (scott.shawcroft@gmail.com) |
| 9 | * |
| 10 | * The BCM5974 driver is based on the appletouch driver: |
| 11 | * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) |
| 12 | * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net) |
| 13 | * Copyright (C) 2005 Stelian Pop (stelian@popies.net) |
| 14 | * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de) |
| 15 | * Copyright (C) 2005 Peter Osterlund (petero2@telia.com) |
| 16 | * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch) |
| 17 | * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch) |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/usb/input.h> |
| 41 | #include <linux/hid.h> |
| 42 | #include <linux/mutex.h> |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 43 | #include <linux/input/mt.h> |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 44 | |
| 45 | #define USB_VENDOR_ID_APPLE 0x05ac |
| 46 | |
| 47 | /* MacbookAir, aka wellspring */ |
| 48 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223 |
| 49 | #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224 |
| 50 | #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225 |
| 51 | /* MacbookProPenryn, aka wellspring2 */ |
| 52 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230 |
| 53 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231 |
| 54 | #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232 |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 55 | /* Macbook5,1 (unibody), aka wellspring3 */ |
| 56 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236 |
| 57 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237 |
| 58 | #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238 |
Edgar (gimli) Hucek | 6021afc | 2010-11-09 17:38:42 +0100 | [diff] [blame] | 59 | /* MacbookAir3,2 (unibody), aka wellspring5 */ |
| 60 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI 0x023f |
| 61 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_ISO 0x0240 |
| 62 | #define USB_DEVICE_ID_APPLE_WELLSPRING4_JIS 0x0241 |
| 63 | /* MacbookAir3,1 (unibody), aka wellspring4 */ |
| 64 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI 0x0242 |
| 65 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO 0x0243 |
| 66 | #define USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS 0x0244 |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 67 | /* Macbook8 (unibody, March 2011) */ |
| 68 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI 0x0245 |
| 69 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_ISO 0x0246 |
| 70 | #define USB_DEVICE_ID_APPLE_WELLSPRING5_JIS 0x0247 |
Pieter-Augustijn Van Malleghem | 1c601be | 2011-09-09 13:29:45 -0700 | [diff] [blame] | 71 | /* MacbookAir4,1 (unibody, July 2011) */ |
| 72 | #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI 0x0249 |
| 73 | #define USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO 0x024a |
| 74 | #define USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS 0x024b |
Joshua V. Dillon | db0b34b | 2011-08-08 23:45:14 -0700 | [diff] [blame] | 75 | /* MacbookAir4,2 (unibody, July 2011) */ |
| 76 | #define USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI 0x024c |
| 77 | #define USB_DEVICE_ID_APPLE_WELLSPRING6_ISO 0x024d |
| 78 | #define USB_DEVICE_ID_APPLE_WELLSPRING6_JIS 0x024e |
Andrew Drake | c331eb5 | 2011-08-16 11:07:39 -0700 | [diff] [blame] | 79 | /* Macbook8,2 (unibody) */ |
| 80 | #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252 |
| 81 | #define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253 |
| 82 | #define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254 |
Henrik Rydberg | 3dde22a | 2012-07-10 09:43:57 -0700 | [diff] [blame] | 83 | /* MacbookPro10,1 (unibody, June 2012) */ |
| 84 | #define USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI 0x0262 |
| 85 | #define USB_DEVICE_ID_APPLE_WELLSPRING7_ISO 0x0263 |
| 86 | #define USB_DEVICE_ID_APPLE_WELLSPRING7_JIS 0x0264 |
Dirk Hohndel | 8d80da9 | 2012-10-30 11:11:48 -0700 | [diff] [blame] | 87 | /* MacbookPro10,2 (unibody, October 2012) */ |
| 88 | #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI 0x0259 |
| 89 | #define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a |
| 90 | #define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 91 | /* MacbookAir6,2 (unibody, June 2013) */ |
| 92 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0291 |
| 93 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0292 |
| 94 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0293 |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 95 | |
| 96 | #define BCM5974_DEVICE(prod) { \ |
| 97 | .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ |
| 98 | USB_DEVICE_ID_MATCH_INT_CLASS | \ |
| 99 | USB_DEVICE_ID_MATCH_INT_PROTOCOL), \ |
| 100 | .idVendor = USB_VENDOR_ID_APPLE, \ |
| 101 | .idProduct = (prod), \ |
| 102 | .bInterfaceClass = USB_INTERFACE_CLASS_HID, \ |
| 103 | .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE \ |
| 104 | } |
| 105 | |
| 106 | /* table of devices that work with this driver */ |
Henrik Rydberg | 158e0fb | 2008-09-04 22:20:10 -0400 | [diff] [blame] | 107 | static const struct usb_device_id bcm5974_table[] = { |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 108 | /* MacbookAir1.1 */ |
| 109 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), |
| 110 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ISO), |
| 111 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_JIS), |
| 112 | /* MacbookProPenryn */ |
| 113 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI), |
| 114 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ISO), |
| 115 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_JIS), |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 116 | /* Macbook5,1 */ |
| 117 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI), |
| 118 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO), |
| 119 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS), |
Edgar (gimli) Hucek | 6021afc | 2010-11-09 17:38:42 +0100 | [diff] [blame] | 120 | /* MacbookAir3,2 */ |
| 121 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI), |
| 122 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_ISO), |
| 123 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4_JIS), |
| 124 | /* MacbookAir3,1 */ |
| 125 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI), |
| 126 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO), |
| 127 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS), |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 128 | /* MacbookPro8 */ |
| 129 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI), |
| 130 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_ISO), |
| 131 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5_JIS), |
Pieter-Augustijn Van Malleghem | 1c601be | 2011-09-09 13:29:45 -0700 | [diff] [blame] | 132 | /* MacbookAir4,1 */ |
| 133 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI), |
| 134 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO), |
| 135 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS), |
Joshua V. Dillon | db0b34b | 2011-08-08 23:45:14 -0700 | [diff] [blame] | 136 | /* MacbookAir4,2 */ |
| 137 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI), |
| 138 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_ISO), |
| 139 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING6_JIS), |
Andrew Drake | c331eb5 | 2011-08-16 11:07:39 -0700 | [diff] [blame] | 140 | /* MacbookPro8,2 */ |
| 141 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI), |
| 142 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO), |
| 143 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS), |
Henrik Rydberg | 3dde22a | 2012-07-10 09:43:57 -0700 | [diff] [blame] | 144 | /* MacbookPro10,1 */ |
| 145 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI), |
| 146 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_ISO), |
| 147 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7_JIS), |
Dirk Hohndel | 8d80da9 | 2012-10-30 11:11:48 -0700 | [diff] [blame] | 148 | /* MacbookPro10,2 */ |
| 149 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI), |
| 150 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO), |
| 151 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS), |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 152 | /* MacbookAir6,2 */ |
| 153 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI), |
| 154 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_ISO), |
| 155 | BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING8_JIS), |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 156 | /* Terminating entry */ |
| 157 | {} |
| 158 | }; |
| 159 | MODULE_DEVICE_TABLE(usb, bcm5974_table); |
| 160 | |
| 161 | MODULE_AUTHOR("Henrik Rydberg"); |
| 162 | MODULE_DESCRIPTION("Apple USB BCM5974 multitouch driver"); |
| 163 | MODULE_LICENSE("GPL"); |
| 164 | |
| 165 | #define dprintk(level, format, a...)\ |
| 166 | { if (debug >= level) printk(KERN_DEBUG format, ##a); } |
| 167 | |
| 168 | static int debug = 1; |
| 169 | module_param(debug, int, 0644); |
| 170 | MODULE_PARM_DESC(debug, "Activate debugging output"); |
| 171 | |
| 172 | /* button data structure */ |
| 173 | struct bt_data { |
| 174 | u8 unknown1; /* constant */ |
| 175 | u8 button; /* left button */ |
| 176 | u8 rel_x; /* relative x coordinate */ |
| 177 | u8 rel_y; /* relative y coordinate */ |
| 178 | }; |
| 179 | |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 180 | /* trackpad header types */ |
| 181 | enum tp_type { |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 182 | TYPE1, /* plain trackpad */ |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 183 | TYPE2, /* button integrated in trackpad */ |
| 184 | TYPE3 /* additional header fields since June 2013 */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 185 | }; |
| 186 | |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 187 | /* trackpad finger data offsets, le16-aligned */ |
| 188 | #define FINGER_TYPE1 (13 * sizeof(__le16)) |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 189 | #define FINGER_TYPE2 (15 * sizeof(__le16)) |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 190 | #define FINGER_TYPE3 (19 * sizeof(__le16)) |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 191 | |
| 192 | /* trackpad button data offsets */ |
| 193 | #define BUTTON_TYPE2 15 |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 194 | #define BUTTON_TYPE3 23 |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 195 | |
| 196 | /* list of device capability bits */ |
| 197 | #define HAS_INTEGRATED_BUTTON 1 |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 198 | |
| 199 | /* trackpad finger structure, le16-aligned */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 200 | struct tp_finger { |
Henrik Rydberg | 75e21e3 | 2008-09-04 22:28:23 -0400 | [diff] [blame] | 201 | __le16 origin; /* zero when switching track finger */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 202 | __le16 abs_x; /* absolute x coodinate */ |
| 203 | __le16 abs_y; /* absolute y coodinate */ |
| 204 | __le16 rel_x; /* relative x coodinate */ |
| 205 | __le16 rel_y; /* relative y coodinate */ |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 206 | __le16 tool_major; /* tool area, major axis */ |
| 207 | __le16 tool_minor; /* tool area, minor axis */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 208 | __le16 orientation; /* 16384 when point, else 15 bit angle */ |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 209 | __le16 touch_major; /* touch area, major axis */ |
| 210 | __le16 touch_minor; /* touch area, minor axis */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 211 | __le16 unused[3]; /* zeros */ |
| 212 | __le16 multi; /* one finger: varies, more fingers: constant */ |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 213 | } __attribute__((packed,aligned(2))); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 214 | |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 215 | /* trackpad finger data size, empirically at least ten fingers */ |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 216 | #define MAX_FINGERS 16 |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 217 | #define SIZEOF_FINGER sizeof(struct tp_finger) |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 218 | #define SIZEOF_ALL_FINGERS (MAX_FINGERS * SIZEOF_FINGER) |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 219 | #define MAX_FINGER_ORIENTATION 16384 |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 220 | |
| 221 | /* device-specific parameters */ |
| 222 | struct bcm5974_param { |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 223 | int snratio; /* signal-to-noise ratio */ |
| 224 | int min; /* device minimum reading */ |
| 225 | int max; /* device maximum reading */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | /* device-specific configuration */ |
| 229 | struct bcm5974_config { |
| 230 | int ansi, iso, jis; /* the product id of this device */ |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 231 | int caps; /* device capability bitmask */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 232 | int bt_ep; /* the endpoint of the button interface */ |
| 233 | int bt_datalen; /* data length of the button interface */ |
| 234 | int tp_ep; /* the endpoint of the trackpad interface */ |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 235 | enum tp_type tp_type; /* type of trackpad interface */ |
| 236 | int tp_offset; /* offset to trackpad finger data */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 237 | int tp_datalen; /* data length of the trackpad interface */ |
| 238 | struct bcm5974_param p; /* finger pressure limits */ |
| 239 | struct bcm5974_param w; /* finger width limits */ |
| 240 | struct bcm5974_param x; /* horizontal limits */ |
| 241 | struct bcm5974_param y; /* vertical limits */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 242 | struct bcm5974_param o; /* orientation limits */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | /* logical device structure */ |
| 246 | struct bcm5974 { |
| 247 | char phys[64]; |
| 248 | struct usb_device *udev; /* usb device */ |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 249 | struct usb_interface *intf; /* our interface */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 250 | struct input_dev *input; /* input dev */ |
| 251 | struct bcm5974_config cfg; /* device configuration */ |
| 252 | struct mutex pm_mutex; /* serialize access to open/suspend */ |
| 253 | int opened; /* 1: opened, 0: closed */ |
| 254 | struct urb *bt_urb; /* button usb request block */ |
| 255 | struct bt_data *bt_data; /* button transferred data */ |
| 256 | struct urb *tp_urb; /* trackpad usb request block */ |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 257 | u8 *tp_data; /* trackpad transferred data */ |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 258 | const struct tp_finger *index[MAX_FINGERS]; /* finger index data */ |
| 259 | struct input_mt_pos pos[MAX_FINGERS]; /* position array */ |
| 260 | int slots[MAX_FINGERS]; /* slot assignments */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 261 | }; |
| 262 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 263 | /* logical signal quality */ |
| 264 | #define SN_PRESSURE 45 /* pressure signal-to-noise ratio */ |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 265 | #define SN_WIDTH 25 /* width signal-to-noise ratio */ |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 266 | #define SN_COORD 250 /* coordinate signal-to-noise ratio */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 267 | #define SN_ORIENT 10 /* orientation signal-to-noise ratio */ |
Henrik Rydberg | 75e21e3 | 2008-09-04 22:28:23 -0400 | [diff] [blame] | 268 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 269 | /* device constants */ |
| 270 | static const struct bcm5974_config bcm5974_config_table[] = { |
| 271 | { |
| 272 | USB_DEVICE_ID_APPLE_WELLSPRING_ANSI, |
| 273 | USB_DEVICE_ID_APPLE_WELLSPRING_ISO, |
| 274 | USB_DEVICE_ID_APPLE_WELLSPRING_JIS, |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 275 | 0, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 276 | 0x84, sizeof(struct bt_data), |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 277 | 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 278 | { SN_PRESSURE, 0, 256 }, |
| 279 | { SN_WIDTH, 0, 2048 }, |
| 280 | { SN_COORD, -4824, 5342 }, |
| 281 | { SN_COORD, -172, 5820 }, |
| 282 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 283 | }, |
| 284 | { |
| 285 | USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI, |
| 286 | USB_DEVICE_ID_APPLE_WELLSPRING2_ISO, |
| 287 | USB_DEVICE_ID_APPLE_WELLSPRING2_JIS, |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 288 | 0, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 289 | 0x84, sizeof(struct bt_data), |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 290 | 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 291 | { SN_PRESSURE, 0, 256 }, |
| 292 | { SN_WIDTH, 0, 2048 }, |
| 293 | { SN_COORD, -4824, 4824 }, |
| 294 | { SN_COORD, -172, 4290 }, |
| 295 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 296 | }, |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 297 | { |
| 298 | USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI, |
| 299 | USB_DEVICE_ID_APPLE_WELLSPRING3_ISO, |
| 300 | USB_DEVICE_ID_APPLE_WELLSPRING3_JIS, |
| 301 | HAS_INTEGRATED_BUTTON, |
| 302 | 0x84, sizeof(struct bt_data), |
| 303 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 304 | { SN_PRESSURE, 0, 300 }, |
| 305 | { SN_WIDTH, 0, 2048 }, |
| 306 | { SN_COORD, -4460, 5166 }, |
| 307 | { SN_COORD, -75, 6700 }, |
| 308 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 309 | }, |
Edgar (gimli) Hucek | 6021afc | 2010-11-09 17:38:42 +0100 | [diff] [blame] | 310 | { |
| 311 | USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI, |
| 312 | USB_DEVICE_ID_APPLE_WELLSPRING4_ISO, |
| 313 | USB_DEVICE_ID_APPLE_WELLSPRING4_JIS, |
| 314 | HAS_INTEGRATED_BUTTON, |
| 315 | 0x84, sizeof(struct bt_data), |
| 316 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 317 | { SN_PRESSURE, 0, 300 }, |
| 318 | { SN_WIDTH, 0, 2048 }, |
| 319 | { SN_COORD, -4620, 5140 }, |
| 320 | { SN_COORD, -150, 6600 }, |
| 321 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Edgar (gimli) Hucek | 6021afc | 2010-11-09 17:38:42 +0100 | [diff] [blame] | 322 | }, |
| 323 | { |
| 324 | USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI, |
| 325 | USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO, |
| 326 | USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS, |
| 327 | HAS_INTEGRATED_BUTTON, |
| 328 | 0x84, sizeof(struct bt_data), |
| 329 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 330 | { SN_PRESSURE, 0, 300 }, |
| 331 | { SN_WIDTH, 0, 2048 }, |
| 332 | { SN_COORD, -4616, 5112 }, |
| 333 | { SN_COORD, -142, 5234 }, |
| 334 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Edgar (gimli) Hucek | 6021afc | 2010-11-09 17:38:42 +0100 | [diff] [blame] | 335 | }, |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 336 | { |
| 337 | USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI, |
| 338 | USB_DEVICE_ID_APPLE_WELLSPRING5_ISO, |
| 339 | USB_DEVICE_ID_APPLE_WELLSPRING5_JIS, |
| 340 | HAS_INTEGRATED_BUTTON, |
| 341 | 0x84, sizeof(struct bt_data), |
| 342 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 343 | { SN_PRESSURE, 0, 300 }, |
| 344 | { SN_WIDTH, 0, 2048 }, |
| 345 | { SN_COORD, -4415, 5050 }, |
| 346 | { SN_COORD, -55, 6680 }, |
| 347 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Andy Botting | 47340bd | 2011-03-12 20:27:22 -0800 | [diff] [blame] | 348 | }, |
Joshua V. Dillon | db0b34b | 2011-08-08 23:45:14 -0700 | [diff] [blame] | 349 | { |
| 350 | USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI, |
| 351 | USB_DEVICE_ID_APPLE_WELLSPRING6_ISO, |
| 352 | USB_DEVICE_ID_APPLE_WELLSPRING6_JIS, |
| 353 | HAS_INTEGRATED_BUTTON, |
| 354 | 0x84, sizeof(struct bt_data), |
| 355 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 356 | { SN_PRESSURE, 0, 300 }, |
| 357 | { SN_WIDTH, 0, 2048 }, |
| 358 | { SN_COORD, -4620, 5140 }, |
| 359 | { SN_COORD, -150, 6600 }, |
| 360 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Joshua V. Dillon | db0b34b | 2011-08-08 23:45:14 -0700 | [diff] [blame] | 361 | }, |
Andrew Drake | c331eb5 | 2011-08-16 11:07:39 -0700 | [diff] [blame] | 362 | { |
| 363 | USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI, |
| 364 | USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO, |
| 365 | USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS, |
| 366 | HAS_INTEGRATED_BUTTON, |
| 367 | 0x84, sizeof(struct bt_data), |
| 368 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 369 | { SN_PRESSURE, 0, 300 }, |
| 370 | { SN_WIDTH, 0, 2048 }, |
| 371 | { SN_COORD, -4750, 5280 }, |
| 372 | { SN_COORD, -150, 6730 }, |
| 373 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Andrew Drake | c331eb5 | 2011-08-16 11:07:39 -0700 | [diff] [blame] | 374 | }, |
Pieter-Augustijn Van Malleghem | 1c601be | 2011-09-09 13:29:45 -0700 | [diff] [blame] | 375 | { |
| 376 | USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI, |
| 377 | USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO, |
| 378 | USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS, |
| 379 | HAS_INTEGRATED_BUTTON, |
| 380 | 0x84, sizeof(struct bt_data), |
| 381 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 382 | { SN_PRESSURE, 0, 300 }, |
| 383 | { SN_WIDTH, 0, 2048 }, |
| 384 | { SN_COORD, -4620, 5140 }, |
| 385 | { SN_COORD, -150, 6600 }, |
| 386 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Pieter-Augustijn Van Malleghem | 1c601be | 2011-09-09 13:29:45 -0700 | [diff] [blame] | 387 | }, |
Henrik Rydberg | 3dde22a | 2012-07-10 09:43:57 -0700 | [diff] [blame] | 388 | { |
| 389 | USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI, |
| 390 | USB_DEVICE_ID_APPLE_WELLSPRING7_ISO, |
| 391 | USB_DEVICE_ID_APPLE_WELLSPRING7_JIS, |
| 392 | HAS_INTEGRATED_BUTTON, |
| 393 | 0x84, sizeof(struct bt_data), |
| 394 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 395 | { SN_PRESSURE, 0, 300 }, |
| 396 | { SN_WIDTH, 0, 2048 }, |
| 397 | { SN_COORD, -4750, 5280 }, |
| 398 | { SN_COORD, -150, 6730 }, |
| 399 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
Henrik Rydberg | 3dde22a | 2012-07-10 09:43:57 -0700 | [diff] [blame] | 400 | }, |
Dirk Hohndel | 8d80da9 | 2012-10-30 11:11:48 -0700 | [diff] [blame] | 401 | { |
| 402 | USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI, |
| 403 | USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO, |
| 404 | USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS, |
| 405 | HAS_INTEGRATED_BUTTON, |
| 406 | 0x84, sizeof(struct bt_data), |
| 407 | 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS, |
| 408 | { SN_PRESSURE, 0, 300 }, |
| 409 | { SN_WIDTH, 0, 2048 }, |
| 410 | { SN_COORD, -4750, 5280 }, |
| 411 | { SN_COORD, -150, 6730 }, |
| 412 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
| 413 | }, |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 414 | { |
| 415 | USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI, |
| 416 | USB_DEVICE_ID_APPLE_WELLSPRING8_ISO, |
| 417 | USB_DEVICE_ID_APPLE_WELLSPRING8_JIS, |
| 418 | HAS_INTEGRATED_BUTTON, |
| 419 | 0, sizeof(struct bt_data), |
| 420 | 0x83, TYPE3, FINGER_TYPE3, FINGER_TYPE3 + SIZEOF_ALL_FINGERS, |
| 421 | { SN_PRESSURE, 0, 300 }, |
| 422 | { SN_WIDTH, 0, 2048 }, |
| 423 | { SN_COORD, -4620, 5140 }, |
| 424 | { SN_COORD, -150, 6600 }, |
| 425 | { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION } |
| 426 | }, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 427 | {} |
| 428 | }; |
| 429 | |
| 430 | /* return the device-specific configuration by device */ |
| 431 | static const struct bcm5974_config *bcm5974_get_config(struct usb_device *udev) |
| 432 | { |
| 433 | u16 id = le16_to_cpu(udev->descriptor.idProduct); |
| 434 | const struct bcm5974_config *cfg; |
| 435 | |
| 436 | for (cfg = bcm5974_config_table; cfg->ansi; ++cfg) |
| 437 | if (cfg->ansi == id || cfg->iso == id || cfg->jis == id) |
| 438 | return cfg; |
| 439 | |
| 440 | return bcm5974_config_table; |
| 441 | } |
| 442 | |
| 443 | /* convert 16-bit little endian to signed integer */ |
| 444 | static inline int raw2int(__le16 x) |
| 445 | { |
| 446 | return (signed short)le16_to_cpu(x); |
| 447 | } |
| 448 | |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 449 | static void set_abs(struct input_dev *input, unsigned int code, |
| 450 | const struct bcm5974_param *p) |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 451 | { |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 452 | int fuzz = p->snratio ? (p->max - p->min) / p->snratio : 0; |
| 453 | input_set_abs_params(input, code, p->min, p->max, fuzz, 0); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /* setup which logical events to report */ |
| 457 | static void setup_events_to_report(struct input_dev *input_dev, |
| 458 | const struct bcm5974_config *cfg) |
| 459 | { |
| 460 | __set_bit(EV_ABS, input_dev->evbit); |
| 461 | |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 462 | /* for synaptics only */ |
| 463 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 256, 5, 0); |
| 464 | input_set_abs_params(input_dev, ABS_TOOL_WIDTH, 0, 16, 0, 0); |
| 465 | |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 466 | /* finger touch area */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 467 | set_abs(input_dev, ABS_MT_TOUCH_MAJOR, &cfg->w); |
| 468 | set_abs(input_dev, ABS_MT_TOUCH_MINOR, &cfg->w); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 469 | /* finger approach area */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 470 | set_abs(input_dev, ABS_MT_WIDTH_MAJOR, &cfg->w); |
| 471 | set_abs(input_dev, ABS_MT_WIDTH_MINOR, &cfg->w); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 472 | /* finger orientation */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 473 | set_abs(input_dev, ABS_MT_ORIENTATION, &cfg->o); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 474 | /* finger position */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 475 | set_abs(input_dev, ABS_MT_POSITION_X, &cfg->x); |
| 476 | set_abs(input_dev, ABS_MT_POSITION_Y, &cfg->y); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 477 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 478 | __set_bit(EV_KEY, input_dev->evbit); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 479 | __set_bit(BTN_LEFT, input_dev->keybit); |
Henrik Rydberg | c13aea0 | 2010-06-23 09:30:22 -0700 | [diff] [blame] | 480 | |
Jussi Pakkanen | 52965cc | 2012-01-10 23:04:16 -0800 | [diff] [blame] | 481 | if (cfg->caps & HAS_INTEGRATED_BUTTON) |
| 482 | __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); |
| 483 | |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 484 | input_mt_init_slots(input_dev, MAX_FINGERS, |
| 485 | INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /* report button data as logical button state */ |
| 489 | static int report_bt_state(struct bcm5974 *dev, int size) |
| 490 | { |
| 491 | if (size != sizeof(struct bt_data)) |
| 492 | return -EIO; |
| 493 | |
Henrik Rydberg | 5340219 | 2009-04-28 07:04:42 -0700 | [diff] [blame] | 494 | dprintk(7, |
| 495 | "bcm5974: button data: %x %x %x %x\n", |
| 496 | dev->bt_data->unknown1, dev->bt_data->button, |
| 497 | dev->bt_data->rel_x, dev->bt_data->rel_y); |
| 498 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 499 | input_report_key(dev->input, BTN_LEFT, dev->bt_data->button); |
| 500 | input_sync(dev->input); |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 505 | static void report_finger_data(struct input_dev *input, int slot, |
| 506 | const struct input_mt_pos *pos, |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 507 | const struct tp_finger *f) |
| 508 | { |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 509 | input_mt_slot(input, slot); |
| 510 | input_mt_report_slot_state(input, MT_TOOL_FINGER, true); |
| 511 | |
Henrik Rydberg | 57157be | 2010-08-31 17:27:02 -0700 | [diff] [blame] | 512 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 513 | raw2int(f->touch_major) << 1); |
Henrik Rydberg | 57157be | 2010-08-31 17:27:02 -0700 | [diff] [blame] | 514 | input_report_abs(input, ABS_MT_TOUCH_MINOR, |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 515 | raw2int(f->touch_minor) << 1); |
Henrik Rydberg | 57157be | 2010-08-31 17:27:02 -0700 | [diff] [blame] | 516 | input_report_abs(input, ABS_MT_WIDTH_MAJOR, |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 517 | raw2int(f->tool_major) << 1); |
Henrik Rydberg | 57157be | 2010-08-31 17:27:02 -0700 | [diff] [blame] | 518 | input_report_abs(input, ABS_MT_WIDTH_MINOR, |
Henrik Rydberg | f17953a | 2012-08-12 21:21:59 +0200 | [diff] [blame] | 519 | raw2int(f->tool_minor) << 1); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 520 | input_report_abs(input, ABS_MT_ORIENTATION, |
| 521 | MAX_FINGER_ORIENTATION - raw2int(f->orientation)); |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 522 | input_report_abs(input, ABS_MT_POSITION_X, pos->x); |
| 523 | input_report_abs(input, ABS_MT_POSITION_Y, pos->y); |
Henrik Rydberg | 6f2701b | 2010-01-06 00:32:48 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 526 | static void report_synaptics_data(struct input_dev *input, |
| 527 | const struct bcm5974_config *cfg, |
| 528 | const struct tp_finger *f, int raw_n) |
| 529 | { |
| 530 | int abs_p = 0, abs_w = 0; |
| 531 | |
| 532 | if (raw_n) { |
| 533 | int p = raw2int(f->touch_major); |
| 534 | int w = raw2int(f->tool_major); |
| 535 | if (p > 0 && raw2int(f->origin)) { |
| 536 | abs_p = clamp_val(256 * p / cfg->p.max, 0, 255); |
| 537 | abs_w = clamp_val(16 * w / cfg->w.max, 0, 15); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | input_report_abs(input, ABS_PRESSURE, abs_p); |
| 542 | input_report_abs(input, ABS_TOOL_WIDTH, abs_w); |
| 543 | } |
| 544 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 545 | /* report trackpad data as logical trackpad state */ |
| 546 | static int report_tp_state(struct bcm5974 *dev, int size) |
| 547 | { |
| 548 | const struct bcm5974_config *c = &dev->cfg; |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 549 | const struct tp_finger *f; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 550 | struct input_dev *input = dev->input; |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 551 | int raw_n, i, n = 0; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 552 | |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 553 | if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0) |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 554 | return -EIO; |
| 555 | |
Henrik Rydberg | 9894cf0 | 2009-04-27 11:52:42 -0700 | [diff] [blame] | 556 | /* finger data, le16-aligned */ |
| 557 | f = (const struct tp_finger *)(dev->tp_data + c->tp_offset); |
| 558 | raw_n = (size - c->tp_offset) / SIZEOF_FINGER; |
| 559 | |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 560 | for (i = 0; i < raw_n; i++) { |
| 561 | if (raw2int(f[i].touch_major) == 0) |
| 562 | continue; |
| 563 | dev->pos[n].x = raw2int(f[i].abs_x); |
| 564 | dev->pos[n].y = c->y.min + c->y.max - raw2int(f[i].abs_y); |
| 565 | dev->index[n++] = &f[i]; |
Henrik Rydberg | 75e21e3 | 2008-09-04 22:28:23 -0400 | [diff] [blame] | 566 | } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 567 | |
Henrik Rydberg | 51c80b7 | 2012-09-15 16:40:04 +0200 | [diff] [blame] | 568 | input_mt_assign_slots(input, dev->slots, dev->pos, n); |
| 569 | |
| 570 | for (i = 0; i < n; i++) |
| 571 | report_finger_data(input, dev->slots[i], |
| 572 | &dev->pos[i], dev->index[i]); |
| 573 | |
| 574 | input_mt_sync_frame(input); |
Henrik Rydberg | 5063511 | 2011-02-25 09:33:13 -0800 | [diff] [blame] | 575 | |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 576 | report_synaptics_data(input, c, f, raw_n); |
Henrik Rydberg | 75e21e3 | 2008-09-04 22:28:23 -0400 | [diff] [blame] | 577 | |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 578 | /* type 2 reports button events via ibt only */ |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 579 | if (c->tp_type == TYPE2) { |
| 580 | int ibt = raw2int(dev->tp_data[BUTTON_TYPE2]); |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 581 | input_report_key(input, BTN_LEFT, ibt); |
Henrik Rydberg | 0e72696 | 2012-09-15 09:49:51 +0200 | [diff] [blame] | 582 | } |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 583 | |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 584 | if (c->tp_type == TYPE3) |
| 585 | input_report_key(input, BTN_LEFT, dev->tp_data[BUTTON_TYPE3]); |
| 586 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 587 | input_sync(input); |
| 588 | |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | /* Wellspring initialization constants */ |
| 593 | #define BCM5974_WELLSPRING_MODE_READ_REQUEST_ID 1 |
| 594 | #define BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID 9 |
| 595 | #define BCM5974_WELLSPRING_MODE_REQUEST_VALUE 0x300 |
| 596 | #define BCM5974_WELLSPRING_MODE_REQUEST_INDEX 0 |
| 597 | #define BCM5974_WELLSPRING_MODE_VENDOR_VALUE 0x01 |
Henrik Rydberg | cd72ad3 | 2008-09-14 11:52:44 -0400 | [diff] [blame] | 598 | #define BCM5974_WELLSPRING_MODE_NORMAL_VALUE 0x08 |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 599 | |
Henrik Rydberg | cd72ad3 | 2008-09-14 11:52:44 -0400 | [diff] [blame] | 600 | static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on) |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 601 | { |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 602 | int retval = 0, size; |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 603 | char *data; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 604 | |
Dmitry Torokhov | 148c1c8 | 2013-07-01 11:47:51 -0700 | [diff] [blame] | 605 | /* Type 3 does not require a mode switch */ |
| 606 | if (dev->cfg.tp_type == TYPE3) |
| 607 | return 0; |
| 608 | |
| 609 | data = kmalloc(8, GFP_KERNEL); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 610 | if (!data) { |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 611 | dev_err(&dev->intf->dev, "out of memory\n"); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 612 | retval = -ENOMEM; |
| 613 | goto out; |
| 614 | } |
| 615 | |
| 616 | /* read configuration */ |
| 617 | size = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), |
| 618 | BCM5974_WELLSPRING_MODE_READ_REQUEST_ID, |
| 619 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 620 | BCM5974_WELLSPRING_MODE_REQUEST_VALUE, |
| 621 | BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000); |
| 622 | |
| 623 | if (size != 8) { |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 624 | dev_err(&dev->intf->dev, "could not read from device\n"); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 625 | retval = -EIO; |
| 626 | goto out; |
| 627 | } |
| 628 | |
| 629 | /* apply the mode switch */ |
Henrik Rydberg | cd72ad3 | 2008-09-14 11:52:44 -0400 | [diff] [blame] | 630 | data[0] = on ? |
| 631 | BCM5974_WELLSPRING_MODE_VENDOR_VALUE : |
| 632 | BCM5974_WELLSPRING_MODE_NORMAL_VALUE; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 633 | |
| 634 | /* write configuration */ |
| 635 | size = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), |
| 636 | BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID, |
| 637 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 638 | BCM5974_WELLSPRING_MODE_REQUEST_VALUE, |
| 639 | BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000); |
| 640 | |
| 641 | if (size != 8) { |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 642 | dev_err(&dev->intf->dev, "could not write to device\n"); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 643 | retval = -EIO; |
| 644 | goto out; |
| 645 | } |
| 646 | |
Henrik Rydberg | cd72ad3 | 2008-09-14 11:52:44 -0400 | [diff] [blame] | 647 | dprintk(2, "bcm5974: switched to %s mode.\n", |
| 648 | on ? "wellspring" : "normal"); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 649 | |
| 650 | out: |
| 651 | kfree(data); |
| 652 | return retval; |
| 653 | } |
| 654 | |
| 655 | static void bcm5974_irq_button(struct urb *urb) |
| 656 | { |
| 657 | struct bcm5974 *dev = urb->context; |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 658 | struct usb_interface *intf = dev->intf; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 659 | int error; |
| 660 | |
| 661 | switch (urb->status) { |
| 662 | case 0: |
| 663 | break; |
| 664 | case -EOVERFLOW: |
| 665 | case -ECONNRESET: |
| 666 | case -ENOENT: |
| 667 | case -ESHUTDOWN: |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 668 | dev_dbg(&intf->dev, "button urb shutting down: %d\n", |
Greg Kroah-Hartman | bd02876 | 2012-05-01 21:33:05 -0700 | [diff] [blame] | 669 | urb->status); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 670 | return; |
| 671 | default: |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 672 | dev_dbg(&intf->dev, "button urb status: %d\n", urb->status); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 673 | goto exit; |
| 674 | } |
| 675 | |
| 676 | if (report_bt_state(dev, dev->bt_urb->actual_length)) |
| 677 | dprintk(1, "bcm5974: bad button package, length: %d\n", |
| 678 | dev->bt_urb->actual_length); |
| 679 | |
| 680 | exit: |
| 681 | error = usb_submit_urb(dev->bt_urb, GFP_ATOMIC); |
| 682 | if (error) |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 683 | dev_err(&intf->dev, "button urb failed: %d\n", error); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void bcm5974_irq_trackpad(struct urb *urb) |
| 687 | { |
| 688 | struct bcm5974 *dev = urb->context; |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 689 | struct usb_interface *intf = dev->intf; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 690 | int error; |
| 691 | |
| 692 | switch (urb->status) { |
| 693 | case 0: |
| 694 | break; |
| 695 | case -EOVERFLOW: |
| 696 | case -ECONNRESET: |
| 697 | case -ENOENT: |
| 698 | case -ESHUTDOWN: |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 699 | dev_dbg(&intf->dev, "trackpad urb shutting down: %d\n", |
Greg Kroah-Hartman | bd02876 | 2012-05-01 21:33:05 -0700 | [diff] [blame] | 700 | urb->status); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 701 | return; |
| 702 | default: |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 703 | dev_dbg(&intf->dev, "trackpad urb status: %d\n", urb->status); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 704 | goto exit; |
| 705 | } |
| 706 | |
| 707 | /* control response ignored */ |
| 708 | if (dev->tp_urb->actual_length == 2) |
| 709 | goto exit; |
| 710 | |
| 711 | if (report_tp_state(dev, dev->tp_urb->actual_length)) |
| 712 | dprintk(1, "bcm5974: bad trackpad package, length: %d\n", |
| 713 | dev->tp_urb->actual_length); |
| 714 | |
| 715 | exit: |
| 716 | error = usb_submit_urb(dev->tp_urb, GFP_ATOMIC); |
| 717 | if (error) |
Greg Kroah-Hartman | ab943ca | 2012-05-04 15:33:02 -0700 | [diff] [blame] | 718 | dev_err(&intf->dev, "trackpad urb failed: %d\n", error); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * The Wellspring trackpad, like many recent Apple trackpads, share |
| 723 | * the usb device with the keyboard. Since keyboards are usually |
| 724 | * handled by the HID system, the device ends up being handled by two |
| 725 | * modules. Setting up the device therefore becomes slightly |
| 726 | * complicated. To enable multitouch features, a mode switch is |
| 727 | * required, which is usually applied via the control interface of the |
| 728 | * device. It can be argued where this switch should take place. In |
| 729 | * some drivers, like appletouch, the switch is made during |
| 730 | * probe. However, the hid module may also alter the state of the |
| 731 | * device, resulting in trackpad malfunction under certain |
| 732 | * circumstances. To get around this problem, there is at least one |
| 733 | * example that utilizes the USB_QUIRK_RESET_RESUME quirk in order to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 734 | * receive a reset_resume request rather than the normal resume. |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 735 | * Since the implementation of reset_resume is equal to mode switch |
| 736 | * plus start_traffic, it seems easier to always do the switch when |
| 737 | * starting traffic on the device. |
| 738 | */ |
| 739 | static int bcm5974_start_traffic(struct bcm5974 *dev) |
| 740 | { |
Luo Jinghua | 1719ec4 | 2010-06-08 01:01:48 -0700 | [diff] [blame] | 741 | int error; |
| 742 | |
| 743 | error = bcm5974_wellspring_mode(dev, true); |
| 744 | if (error) { |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 745 | dprintk(1, "bcm5974: mode switch failed\n"); |
Luo Jinghua | 1719ec4 | 2010-06-08 01:01:48 -0700 | [diff] [blame] | 746 | goto err_out; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 747 | } |
| 748 | |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 749 | if (dev->bt_urb) { |
| 750 | error = usb_submit_urb(dev->bt_urb, GFP_KERNEL); |
| 751 | if (error) |
| 752 | goto err_reset_mode; |
| 753 | } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 754 | |
Luo Jinghua | 1719ec4 | 2010-06-08 01:01:48 -0700 | [diff] [blame] | 755 | error = usb_submit_urb(dev->tp_urb, GFP_KERNEL); |
| 756 | if (error) |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 757 | goto err_kill_bt; |
| 758 | |
| 759 | return 0; |
| 760 | |
| 761 | err_kill_bt: |
| 762 | usb_kill_urb(dev->bt_urb); |
Luo Jinghua | 1719ec4 | 2010-06-08 01:01:48 -0700 | [diff] [blame] | 763 | err_reset_mode: |
| 764 | bcm5974_wellspring_mode(dev, false); |
| 765 | err_out: |
| 766 | return error; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static void bcm5974_pause_traffic(struct bcm5974 *dev) |
| 770 | { |
| 771 | usb_kill_urb(dev->tp_urb); |
| 772 | usb_kill_urb(dev->bt_urb); |
Henrik Rydberg | cd72ad3 | 2008-09-14 11:52:44 -0400 | [diff] [blame] | 773 | bcm5974_wellspring_mode(dev, false); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* |
| 777 | * The code below implements open/close and manual suspend/resume. |
| 778 | * All functions may be called in random order. |
| 779 | * |
| 780 | * Opening a suspended device fails with EACCES - permission denied. |
| 781 | * |
| 782 | * Failing a resume leaves the device resumed but closed. |
| 783 | */ |
| 784 | static int bcm5974_open(struct input_dev *input) |
| 785 | { |
| 786 | struct bcm5974 *dev = input_get_drvdata(input); |
| 787 | int error; |
| 788 | |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 789 | error = usb_autopm_get_interface(dev->intf); |
| 790 | if (error) |
| 791 | return error; |
| 792 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 793 | mutex_lock(&dev->pm_mutex); |
| 794 | |
| 795 | error = bcm5974_start_traffic(dev); |
| 796 | if (!error) |
| 797 | dev->opened = 1; |
| 798 | |
| 799 | mutex_unlock(&dev->pm_mutex); |
| 800 | |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 801 | if (error) |
| 802 | usb_autopm_put_interface(dev->intf); |
| 803 | |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 804 | return error; |
| 805 | } |
| 806 | |
| 807 | static void bcm5974_close(struct input_dev *input) |
| 808 | { |
| 809 | struct bcm5974 *dev = input_get_drvdata(input); |
| 810 | |
| 811 | mutex_lock(&dev->pm_mutex); |
| 812 | |
| 813 | bcm5974_pause_traffic(dev); |
| 814 | dev->opened = 0; |
| 815 | |
| 816 | mutex_unlock(&dev->pm_mutex); |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 817 | |
| 818 | usb_autopm_put_interface(dev->intf); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static int bcm5974_suspend(struct usb_interface *iface, pm_message_t message) |
| 822 | { |
| 823 | struct bcm5974 *dev = usb_get_intfdata(iface); |
| 824 | |
| 825 | mutex_lock(&dev->pm_mutex); |
| 826 | |
| 827 | if (dev->opened) |
| 828 | bcm5974_pause_traffic(dev); |
| 829 | |
| 830 | mutex_unlock(&dev->pm_mutex); |
| 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static int bcm5974_resume(struct usb_interface *iface) |
| 836 | { |
| 837 | struct bcm5974 *dev = usb_get_intfdata(iface); |
| 838 | int error = 0; |
| 839 | |
| 840 | mutex_lock(&dev->pm_mutex); |
| 841 | |
| 842 | if (dev->opened) |
| 843 | error = bcm5974_start_traffic(dev); |
| 844 | |
| 845 | mutex_unlock(&dev->pm_mutex); |
| 846 | |
| 847 | return error; |
| 848 | } |
| 849 | |
| 850 | static int bcm5974_probe(struct usb_interface *iface, |
| 851 | const struct usb_device_id *id) |
| 852 | { |
| 853 | struct usb_device *udev = interface_to_usbdev(iface); |
| 854 | const struct bcm5974_config *cfg; |
| 855 | struct bcm5974 *dev; |
| 856 | struct input_dev *input_dev; |
| 857 | int error = -ENOMEM; |
| 858 | |
| 859 | /* find the product index */ |
| 860 | cfg = bcm5974_get_config(udev); |
| 861 | |
| 862 | /* allocate memory for our device state and initialize it */ |
| 863 | dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL); |
| 864 | input_dev = input_allocate_device(); |
| 865 | if (!dev || !input_dev) { |
Greg Kroah-Hartman | 6c1d1b2 | 2012-04-25 14:48:31 -0700 | [diff] [blame] | 866 | dev_err(&iface->dev, "out of memory\n"); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 867 | goto err_free_devs; |
| 868 | } |
| 869 | |
| 870 | dev->udev = udev; |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 871 | dev->intf = iface; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 872 | dev->input = input_dev; |
| 873 | dev->cfg = *cfg; |
| 874 | mutex_init(&dev->pm_mutex); |
| 875 | |
| 876 | /* setup urbs */ |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 877 | if (cfg->tp_type == TYPE1) { |
| 878 | dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 879 | if (!dev->bt_urb) |
| 880 | goto err_free_devs; |
| 881 | } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 882 | |
| 883 | dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 884 | if (!dev->tp_urb) |
| 885 | goto err_free_bt_urb; |
| 886 | |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 887 | if (dev->bt_urb) { |
| 888 | dev->bt_data = usb_alloc_coherent(dev->udev, |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 889 | dev->cfg.bt_datalen, GFP_KERNEL, |
| 890 | &dev->bt_urb->transfer_dma); |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 891 | if (!dev->bt_data) |
| 892 | goto err_free_urb; |
| 893 | } |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 894 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 895 | dev->tp_data = usb_alloc_coherent(dev->udev, |
| 896 | dev->cfg.tp_datalen, GFP_KERNEL, |
| 897 | &dev->tp_urb->transfer_dma); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 898 | if (!dev->tp_data) |
| 899 | goto err_free_bt_buffer; |
| 900 | |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 901 | if (dev->bt_urb) |
| 902 | usb_fill_int_urb(dev->bt_urb, udev, |
| 903 | usb_rcvintpipe(udev, cfg->bt_ep), |
| 904 | dev->bt_data, dev->cfg.bt_datalen, |
| 905 | bcm5974_irq_button, dev, 1); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 906 | |
| 907 | usb_fill_int_urb(dev->tp_urb, udev, |
| 908 | usb_rcvintpipe(udev, cfg->tp_ep), |
| 909 | dev->tp_data, dev->cfg.tp_datalen, |
| 910 | bcm5974_irq_trackpad, dev, 1); |
| 911 | |
| 912 | /* create bcm5974 device */ |
| 913 | usb_make_path(udev, dev->phys, sizeof(dev->phys)); |
| 914 | strlcat(dev->phys, "/input0", sizeof(dev->phys)); |
| 915 | |
| 916 | input_dev->name = "bcm5974"; |
| 917 | input_dev->phys = dev->phys; |
| 918 | usb_to_input_id(dev->udev, &input_dev->id); |
Henrik Rydberg | 158e928 | 2009-04-28 07:03:54 -0700 | [diff] [blame] | 919 | /* report driver capabilities via the version field */ |
| 920 | input_dev->id.version = cfg->caps; |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 921 | input_dev->dev.parent = &iface->dev; |
| 922 | |
| 923 | input_set_drvdata(input_dev, dev); |
| 924 | |
| 925 | input_dev->open = bcm5974_open; |
| 926 | input_dev->close = bcm5974_close; |
| 927 | |
| 928 | setup_events_to_report(input_dev, cfg); |
| 929 | |
| 930 | error = input_register_device(dev->input); |
| 931 | if (error) |
| 932 | goto err_free_buffer; |
| 933 | |
| 934 | /* save our data pointer in this interface device */ |
| 935 | usb_set_intfdata(iface, dev); |
| 936 | |
| 937 | return 0; |
| 938 | |
| 939 | err_free_buffer: |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 940 | usb_free_coherent(dev->udev, dev->cfg.tp_datalen, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 941 | dev->tp_data, dev->tp_urb->transfer_dma); |
| 942 | err_free_bt_buffer: |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 943 | if (dev->bt_urb) |
| 944 | usb_free_coherent(dev->udev, dev->cfg.bt_datalen, |
| 945 | dev->bt_data, dev->bt_urb->transfer_dma); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 946 | err_free_urb: |
| 947 | usb_free_urb(dev->tp_urb); |
| 948 | err_free_bt_urb: |
| 949 | usb_free_urb(dev->bt_urb); |
| 950 | err_free_devs: |
| 951 | usb_set_intfdata(iface, NULL); |
| 952 | input_free_device(input_dev); |
| 953 | kfree(dev); |
| 954 | return error; |
| 955 | } |
| 956 | |
| 957 | static void bcm5974_disconnect(struct usb_interface *iface) |
| 958 | { |
| 959 | struct bcm5974 *dev = usb_get_intfdata(iface); |
| 960 | |
| 961 | usb_set_intfdata(iface, NULL); |
| 962 | |
| 963 | input_unregister_device(dev->input); |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 964 | usb_free_coherent(dev->udev, dev->cfg.tp_datalen, |
| 965 | dev->tp_data, dev->tp_urb->transfer_dma); |
Henrik Rydberg | 43f482b | 2012-08-13 00:18:44 +0200 | [diff] [blame] | 966 | if (dev->bt_urb) |
| 967 | usb_free_coherent(dev->udev, dev->cfg.bt_datalen, |
| 968 | dev->bt_data, dev->bt_urb->transfer_dma); |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 969 | usb_free_urb(dev->tp_urb); |
| 970 | usb_free_urb(dev->bt_urb); |
| 971 | kfree(dev); |
| 972 | } |
| 973 | |
| 974 | static struct usb_driver bcm5974_driver = { |
| 975 | .name = "bcm5974", |
| 976 | .probe = bcm5974_probe, |
| 977 | .disconnect = bcm5974_disconnect, |
| 978 | .suspend = bcm5974_suspend, |
| 979 | .resume = bcm5974_resume, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 980 | .id_table = bcm5974_table, |
Dmitry Torokhov | 88da765 | 2008-08-08 14:59:32 -0400 | [diff] [blame] | 981 | .supports_autosuspend = 1, |
Henrik Rydberg | f89bd95 | 2008-08-08 14:59:30 -0400 | [diff] [blame] | 982 | }; |
| 983 | |
Greg Kroah-Hartman | 08642e7 | 2011-11-18 09:48:31 -0800 | [diff] [blame] | 984 | module_usb_driver(bcm5974_driver); |