2 * Apple USB BCM5974 (Macbook Air and Penryn Macbook Pro) multitouch driver
4 * Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se)
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)
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)
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.
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.
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.
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>
44 #define USB_VENDOR_ID_APPLE 0x05ac
46 /* MacbookAir, aka wellspring */
47 #define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223
48 #define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224
49 #define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225
50 /* MacbookProPenryn, aka wellspring2 */
51 #define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230
52 #define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231
53 #define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232
54 /* Macbook5,1 (unibody), aka wellspring3 */
55 #define USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI 0x0236
56 #define USB_DEVICE_ID_APPLE_WELLSPRING3_ISO 0x0237
57 #define USB_DEVICE_ID_APPLE_WELLSPRING3_JIS 0x0238
59 #define BCM5974_DEVICE(prod) { \
60 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \
61 USB_DEVICE_ID_MATCH_INT_CLASS | \
62 USB_DEVICE_ID_MATCH_INT_PROTOCOL), \
63 .idVendor = USB_VENDOR_ID_APPLE, \
64 .idProduct = (prod), \
65 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
66 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE \
69 /* table of devices that work with this driver */
70 static const struct usb_device_id bcm5974_table[] = {
72 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
73 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
74 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
75 /* MacbookProPenryn */
76 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
77 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
78 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
80 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI),
81 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_ISO),
82 BCM5974_DEVICE(USB_DEVICE_ID_APPLE_WELLSPRING3_JIS),
83 /* Terminating entry */
86 MODULE_DEVICE_TABLE(usb, bcm5974_table);
88 MODULE_AUTHOR("Henrik Rydberg");
89 MODULE_DESCRIPTION("Apple USB BCM5974 multitouch driver");
90 MODULE_LICENSE("GPL");
92 #define dprintk(level, format, a...)\
93 { if (debug >= level) printk(KERN_DEBUG format, ##a); }
96 module_param(debug, int, 0644);
97 MODULE_PARM_DESC(debug, "Activate debugging output");
99 /* button data structure */
101 u8 unknown1; /* constant */
102 u8 button; /* left button */
103 u8 rel_x; /* relative x coordinate */
104 u8 rel_y; /* relative y coordinate */
107 /* trackpad header types */
109 TYPE1, /* plain trackpad */
110 TYPE2 /* button integrated in trackpad */
113 /* trackpad finger data offsets, le16-aligned */
114 #define FINGER_TYPE1 (13 * sizeof(__le16))
115 #define FINGER_TYPE2 (15 * sizeof(__le16))
117 /* trackpad button data offsets */
118 #define BUTTON_TYPE2 15
120 /* list of device capability bits */
121 #define HAS_INTEGRATED_BUTTON 1
123 /* trackpad finger structure, le16-aligned */
125 __le16 origin; /* zero when switching track finger */
126 __le16 abs_x; /* absolute x coodinate */
127 __le16 abs_y; /* absolute y coodinate */
128 __le16 rel_x; /* relative x coodinate */
129 __le16 rel_y; /* relative y coodinate */
130 __le16 size_major; /* finger size, major axis? */
131 __le16 size_minor; /* finger size, minor axis? */
132 __le16 orientation; /* 16384 when point, else 15 bit angle */
133 __le16 force_major; /* trackpad force, major axis? */
134 __le16 force_minor; /* trackpad force, minor axis? */
135 __le16 unused[3]; /* zeros */
136 __le16 multi; /* one finger: varies, more fingers: constant */
137 } __attribute__((packed,aligned(2)));
139 /* trackpad finger data size, empirically at least ten fingers */
140 #define SIZEOF_FINGER sizeof(struct tp_finger)
141 #define SIZEOF_ALL_FINGERS (16 * SIZEOF_FINGER)
143 /* device-specific parameters */
144 struct bcm5974_param {
145 int dim; /* logical dimension */
146 int fuzz; /* logical noise value */
147 int devmin; /* device minimum reading */
148 int devmax; /* device maximum reading */
151 /* device-specific configuration */
152 struct bcm5974_config {
153 int ansi, iso, jis; /* the product id of this device */
154 int caps; /* device capability bitmask */
155 int bt_ep; /* the endpoint of the button interface */
156 int bt_datalen; /* data length of the button interface */
157 int tp_ep; /* the endpoint of the trackpad interface */
158 enum tp_type tp_type; /* type of trackpad interface */
159 int tp_offset; /* offset to trackpad finger data */
160 int tp_datalen; /* data length of the trackpad interface */
161 struct bcm5974_param p; /* finger pressure limits */
162 struct bcm5974_param w; /* finger width limits */
163 struct bcm5974_param x; /* horizontal limits */
164 struct bcm5974_param y; /* vertical limits */
167 /* logical device structure */
170 struct usb_device *udev; /* usb device */
171 struct usb_interface *intf; /* our interface */
172 struct input_dev *input; /* input dev */
173 struct bcm5974_config cfg; /* device configuration */
174 struct mutex pm_mutex; /* serialize access to open/suspend */
175 int opened; /* 1: opened, 0: closed */
176 struct urb *bt_urb; /* button usb request block */
177 struct bt_data *bt_data; /* button transferred data */
178 struct urb *tp_urb; /* trackpad usb request block */
179 u8 *tp_data; /* trackpad transferred data */
180 int fingers; /* number of fingers on trackpad */
183 /* logical dimensions */
184 #define DIM_PRESSURE 256 /* maximum finger pressure */
185 #define DIM_WIDTH 16 /* maximum finger width */
186 #define DIM_X 1280 /* maximum trackpad x value */
187 #define DIM_Y 800 /* maximum trackpad y value */
189 /* logical signal quality */
190 #define SN_PRESSURE 45 /* pressure signal-to-noise ratio */
191 #define SN_WIDTH 100 /* width signal-to-noise ratio */
192 #define SN_COORD 250 /* coordinate signal-to-noise ratio */
194 /* pressure thresholds */
195 #define PRESSURE_LOW (2 * DIM_PRESSURE / SN_PRESSURE)
196 #define PRESSURE_HIGH (3 * PRESSURE_LOW)
198 /* device constants */
199 static const struct bcm5974_config bcm5974_config_table[] = {
201 USB_DEVICE_ID_APPLE_WELLSPRING_ANSI,
202 USB_DEVICE_ID_APPLE_WELLSPRING_ISO,
203 USB_DEVICE_ID_APPLE_WELLSPRING_JIS,
205 0x84, sizeof(struct bt_data),
206 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
207 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 256 },
208 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
209 { DIM_X, DIM_X / SN_COORD, -4824, 5342 },
210 { DIM_Y, DIM_Y / SN_COORD, -172, 5820 }
213 USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI,
214 USB_DEVICE_ID_APPLE_WELLSPRING2_ISO,
215 USB_DEVICE_ID_APPLE_WELLSPRING2_JIS,
217 0x84, sizeof(struct bt_data),
218 0x81, TYPE1, FINGER_TYPE1, FINGER_TYPE1 + SIZEOF_ALL_FINGERS,
219 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 256 },
220 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
221 { DIM_X, DIM_X / SN_COORD, -4824, 4824 },
222 { DIM_Y, DIM_Y / SN_COORD, -172, 4290 }
225 USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI,
226 USB_DEVICE_ID_APPLE_WELLSPRING3_ISO,
227 USB_DEVICE_ID_APPLE_WELLSPRING3_JIS,
228 HAS_INTEGRATED_BUTTON,
229 0x84, sizeof(struct bt_data),
230 0x81, TYPE2, FINGER_TYPE2, FINGER_TYPE2 + SIZEOF_ALL_FINGERS,
231 { DIM_PRESSURE, DIM_PRESSURE / SN_PRESSURE, 0, 300 },
232 { DIM_WIDTH, DIM_WIDTH / SN_WIDTH, 0, 2048 },
233 { DIM_X, DIM_X / SN_COORD, -4460, 5166 },
234 { DIM_Y, DIM_Y / SN_COORD, -75, 6700 }
239 /* return the device-specific configuration by device */
240 static const struct bcm5974_config *bcm5974_get_config(struct usb_device *udev)
242 u16 id = le16_to_cpu(udev->descriptor.idProduct);
243 const struct bcm5974_config *cfg;
245 for (cfg = bcm5974_config_table; cfg->ansi; ++cfg)
246 if (cfg->ansi == id || cfg->iso == id || cfg->jis == id)
249 return bcm5974_config_table;
252 /* convert 16-bit little endian to signed integer */
253 static inline int raw2int(__le16 x)
255 return (signed short)le16_to_cpu(x);
258 /* scale device data to logical dimensions (asserts devmin < devmax) */
259 static inline int int2scale(const struct bcm5974_param *p, int x)
261 return x * p->dim / (p->devmax - p->devmin);
264 /* all logical value ranges are [0,dim). */
265 static inline int int2bound(const struct bcm5974_param *p, int x)
267 int s = int2scale(p, x);
269 return clamp_val(s, 0, p->dim - 1);
272 /* setup which logical events to report */
273 static void setup_events_to_report(struct input_dev *input_dev,
274 const struct bcm5974_config *cfg)
276 __set_bit(EV_ABS, input_dev->evbit);
278 input_set_abs_params(input_dev, ABS_PRESSURE,
279 0, cfg->p.dim, cfg->p.fuzz, 0);
280 input_set_abs_params(input_dev, ABS_TOOL_WIDTH,
281 0, cfg->w.dim, cfg->w.fuzz, 0);
282 input_set_abs_params(input_dev, ABS_X,
283 0, cfg->x.dim, cfg->x.fuzz, 0);
284 input_set_abs_params(input_dev, ABS_Y,
285 0, cfg->y.dim, cfg->y.fuzz, 0);
287 __set_bit(EV_KEY, input_dev->evbit);
288 __set_bit(BTN_TOUCH, input_dev->keybit);
289 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
290 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
291 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
292 __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit);
293 __set_bit(BTN_LEFT, input_dev->keybit);
296 /* report button data as logical button state */
297 static int report_bt_state(struct bcm5974 *dev, int size)
299 if (size != sizeof(struct bt_data))
303 "bcm5974: button data: %x %x %x %x\n",
304 dev->bt_data->unknown1, dev->bt_data->button,
305 dev->bt_data->rel_x, dev->bt_data->rel_y);
307 input_report_key(dev->input, BTN_LEFT, dev->bt_data->button);
308 input_sync(dev->input);
313 /* report trackpad data as logical trackpad state */
314 static int report_tp_state(struct bcm5974 *dev, int size)
316 const struct bcm5974_config *c = &dev->cfg;
317 const struct tp_finger *f;
318 struct input_dev *input = dev->input;
319 int raw_p, raw_w, raw_x, raw_y, raw_n;
320 int ptest = 0, origin = 0, ibt = 0, nmin = 0, nmax = 0;
321 int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
323 if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0)
326 /* finger data, le16-aligned */
327 f = (const struct tp_finger *)(dev->tp_data + c->tp_offset);
328 raw_n = (size - c->tp_offset) / SIZEOF_FINGER;
330 /* always track the first finger; when detached, start over */
332 raw_p = raw2int(f->force_major);
333 raw_w = raw2int(f->size_major);
334 raw_x = raw2int(f->abs_x);
335 raw_y = raw2int(f->abs_y);
339 "raw: p: %+05d w: %+05d x: %+05d y: %+05d n: %d\n",
340 raw_p, raw_w, raw_x, raw_y, raw_n);
342 ptest = int2bound(&c->p, raw_p);
343 origin = raw2int(f->origin);
345 /* set the integrated button if applicable */
346 if (c->tp_type == TYPE2)
347 ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
350 /* while tracking finger still valid, count all fingers */
351 if (ptest > PRESSURE_LOW && origin) {
353 abs_w = int2bound(&c->w, raw_w);
354 abs_x = int2bound(&c->x, raw_x - c->x.devmin);
355 abs_y = int2bound(&c->y, c->y.devmax - raw_y);
357 ptest = int2bound(&c->p, raw2int(f->force_major));
358 if (ptest > PRESSURE_LOW)
360 if (ptest > PRESSURE_HIGH)
366 if (dev->fingers < nmin)
368 if (dev->fingers > nmax)
371 input_report_key(input, BTN_TOUCH, dev->fingers > 0);
372 input_report_key(input, BTN_TOOL_FINGER, dev->fingers == 1);
373 input_report_key(input, BTN_TOOL_DOUBLETAP, dev->fingers == 2);
374 input_report_key(input, BTN_TOOL_TRIPLETAP, dev->fingers == 3);
375 input_report_key(input, BTN_TOOL_QUADTAP, dev->fingers > 3);
377 input_report_abs(input, ABS_PRESSURE, abs_p);
378 input_report_abs(input, ABS_TOOL_WIDTH, abs_w);
381 input_report_abs(input, ABS_X, abs_x);
382 input_report_abs(input, ABS_Y, abs_y);
385 "bcm5974: abs: p: %+05d w: %+05d x: %+05d y: %+05d "
386 "nmin: %d nmax: %d n: %d ibt: %d\n", abs_p, abs_w,
387 abs_x, abs_y, nmin, nmax, dev->fingers, ibt);
391 /* type 2 reports button events via ibt only */
392 if (c->tp_type == TYPE2)
393 input_report_key(input, BTN_LEFT, ibt);
400 /* Wellspring initialization constants */
401 #define BCM5974_WELLSPRING_MODE_READ_REQUEST_ID 1
402 #define BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID 9
403 #define BCM5974_WELLSPRING_MODE_REQUEST_VALUE 0x300
404 #define BCM5974_WELLSPRING_MODE_REQUEST_INDEX 0
405 #define BCM5974_WELLSPRING_MODE_VENDOR_VALUE 0x01
406 #define BCM5974_WELLSPRING_MODE_NORMAL_VALUE 0x08
408 static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on)
410 char *data = kmalloc(8, GFP_KERNEL);
411 int retval = 0, size;
414 err("bcm5974: out of memory");
419 /* read configuration */
420 size = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
421 BCM5974_WELLSPRING_MODE_READ_REQUEST_ID,
422 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
423 BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
424 BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
427 err("bcm5974: could not read from device");
432 /* apply the mode switch */
434 BCM5974_WELLSPRING_MODE_VENDOR_VALUE :
435 BCM5974_WELLSPRING_MODE_NORMAL_VALUE;
437 /* write configuration */
438 size = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
439 BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID,
440 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
441 BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
442 BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
445 err("bcm5974: could not write to device");
450 dprintk(2, "bcm5974: switched to %s mode.\n",
451 on ? "wellspring" : "normal");
458 static void bcm5974_irq_button(struct urb *urb)
460 struct bcm5974 *dev = urb->context;
463 switch (urb->status) {
470 dbg("bcm5974: button urb shutting down: %d", urb->status);
473 dbg("bcm5974: button urb status: %d", urb->status);
477 if (report_bt_state(dev, dev->bt_urb->actual_length))
478 dprintk(1, "bcm5974: bad button package, length: %d\n",
479 dev->bt_urb->actual_length);
482 error = usb_submit_urb(dev->bt_urb, GFP_ATOMIC);
484 err("bcm5974: button urb failed: %d", error);
487 static void bcm5974_irq_trackpad(struct urb *urb)
489 struct bcm5974 *dev = urb->context;
492 switch (urb->status) {
499 dbg("bcm5974: trackpad urb shutting down: %d", urb->status);
502 dbg("bcm5974: trackpad urb status: %d", urb->status);
506 /* control response ignored */
507 if (dev->tp_urb->actual_length == 2)
510 if (report_tp_state(dev, dev->tp_urb->actual_length))
511 dprintk(1, "bcm5974: bad trackpad package, length: %d\n",
512 dev->tp_urb->actual_length);
515 error = usb_submit_urb(dev->tp_urb, GFP_ATOMIC);
517 err("bcm5974: trackpad urb failed: %d", error);
521 * The Wellspring trackpad, like many recent Apple trackpads, share
522 * the usb device with the keyboard. Since keyboards are usually
523 * handled by the HID system, the device ends up being handled by two
524 * modules. Setting up the device therefore becomes slightly
525 * complicated. To enable multitouch features, a mode switch is
526 * required, which is usually applied via the control interface of the
527 * device. It can be argued where this switch should take place. In
528 * some drivers, like appletouch, the switch is made during
529 * probe. However, the hid module may also alter the state of the
530 * device, resulting in trackpad malfunction under certain
531 * circumstances. To get around this problem, there is at least one
532 * example that utilizes the USB_QUIRK_RESET_RESUME quirk in order to
533 * recieve a reset_resume request rather than the normal resume.
534 * Since the implementation of reset_resume is equal to mode switch
535 * plus start_traffic, it seems easier to always do the switch when
536 * starting traffic on the device.
538 static int bcm5974_start_traffic(struct bcm5974 *dev)
540 if (bcm5974_wellspring_mode(dev, true)) {
541 dprintk(1, "bcm5974: mode switch failed\n");
545 if (usb_submit_urb(dev->bt_urb, GFP_KERNEL))
548 if (usb_submit_urb(dev->tp_urb, GFP_KERNEL))
554 usb_kill_urb(dev->bt_urb);
559 static void bcm5974_pause_traffic(struct bcm5974 *dev)
561 usb_kill_urb(dev->tp_urb);
562 usb_kill_urb(dev->bt_urb);
563 bcm5974_wellspring_mode(dev, false);
567 * The code below implements open/close and manual suspend/resume.
568 * All functions may be called in random order.
570 * Opening a suspended device fails with EACCES - permission denied.
572 * Failing a resume leaves the device resumed but closed.
574 static int bcm5974_open(struct input_dev *input)
576 struct bcm5974 *dev = input_get_drvdata(input);
579 error = usb_autopm_get_interface(dev->intf);
583 mutex_lock(&dev->pm_mutex);
585 error = bcm5974_start_traffic(dev);
589 mutex_unlock(&dev->pm_mutex);
592 usb_autopm_put_interface(dev->intf);
597 static void bcm5974_close(struct input_dev *input)
599 struct bcm5974 *dev = input_get_drvdata(input);
601 mutex_lock(&dev->pm_mutex);
603 bcm5974_pause_traffic(dev);
606 mutex_unlock(&dev->pm_mutex);
608 usb_autopm_put_interface(dev->intf);
611 static int bcm5974_suspend(struct usb_interface *iface, pm_message_t message)
613 struct bcm5974 *dev = usb_get_intfdata(iface);
615 mutex_lock(&dev->pm_mutex);
618 bcm5974_pause_traffic(dev);
620 mutex_unlock(&dev->pm_mutex);
625 static int bcm5974_resume(struct usb_interface *iface)
627 struct bcm5974 *dev = usb_get_intfdata(iface);
630 mutex_lock(&dev->pm_mutex);
633 error = bcm5974_start_traffic(dev);
635 mutex_unlock(&dev->pm_mutex);
640 static int bcm5974_probe(struct usb_interface *iface,
641 const struct usb_device_id *id)
643 struct usb_device *udev = interface_to_usbdev(iface);
644 const struct bcm5974_config *cfg;
646 struct input_dev *input_dev;
649 /* find the product index */
650 cfg = bcm5974_get_config(udev);
652 /* allocate memory for our device state and initialize it */
653 dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL);
654 input_dev = input_allocate_device();
655 if (!dev || !input_dev) {
656 err("bcm5974: out of memory");
662 dev->input = input_dev;
664 mutex_init(&dev->pm_mutex);
667 dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL);
671 dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL);
673 goto err_free_bt_urb;
675 dev->bt_data = usb_buffer_alloc(dev->udev,
676 dev->cfg.bt_datalen, GFP_KERNEL,
677 &dev->bt_urb->transfer_dma);
681 dev->tp_data = usb_buffer_alloc(dev->udev,
682 dev->cfg.tp_datalen, GFP_KERNEL,
683 &dev->tp_urb->transfer_dma);
685 goto err_free_bt_buffer;
687 usb_fill_int_urb(dev->bt_urb, udev,
688 usb_rcvintpipe(udev, cfg->bt_ep),
689 dev->bt_data, dev->cfg.bt_datalen,
690 bcm5974_irq_button, dev, 1);
692 usb_fill_int_urb(dev->tp_urb, udev,
693 usb_rcvintpipe(udev, cfg->tp_ep),
694 dev->tp_data, dev->cfg.tp_datalen,
695 bcm5974_irq_trackpad, dev, 1);
697 /* create bcm5974 device */
698 usb_make_path(udev, dev->phys, sizeof(dev->phys));
699 strlcat(dev->phys, "/input0", sizeof(dev->phys));
701 input_dev->name = "bcm5974";
702 input_dev->phys = dev->phys;
703 usb_to_input_id(dev->udev, &input_dev->id);
704 /* report driver capabilities via the version field */
705 input_dev->id.version = cfg->caps;
706 input_dev->dev.parent = &iface->dev;
708 input_set_drvdata(input_dev, dev);
710 input_dev->open = bcm5974_open;
711 input_dev->close = bcm5974_close;
713 setup_events_to_report(input_dev, cfg);
715 error = input_register_device(dev->input);
717 goto err_free_buffer;
719 /* save our data pointer in this interface device */
720 usb_set_intfdata(iface, dev);
725 usb_buffer_free(dev->udev, dev->cfg.tp_datalen,
726 dev->tp_data, dev->tp_urb->transfer_dma);
728 usb_buffer_free(dev->udev, dev->cfg.bt_datalen,
729 dev->bt_data, dev->bt_urb->transfer_dma);
731 usb_free_urb(dev->tp_urb);
733 usb_free_urb(dev->bt_urb);
735 usb_set_intfdata(iface, NULL);
736 input_free_device(input_dev);
741 static void bcm5974_disconnect(struct usb_interface *iface)
743 struct bcm5974 *dev = usb_get_intfdata(iface);
745 usb_set_intfdata(iface, NULL);
747 input_unregister_device(dev->input);
748 usb_buffer_free(dev->udev, dev->cfg.tp_datalen,
749 dev->tp_data, dev->tp_urb->transfer_dma);
750 usb_buffer_free(dev->udev, dev->cfg.bt_datalen,
751 dev->bt_data, dev->bt_urb->transfer_dma);
752 usb_free_urb(dev->tp_urb);
753 usb_free_urb(dev->bt_urb);
757 static struct usb_driver bcm5974_driver = {
759 .probe = bcm5974_probe,
760 .disconnect = bcm5974_disconnect,
761 .suspend = bcm5974_suspend,
762 .resume = bcm5974_resume,
763 .reset_resume = bcm5974_resume,
764 .id_table = bcm5974_table,
765 .supports_autosuspend = 1,
768 static int __init bcm5974_init(void)
770 return usb_register(&bcm5974_driver);
773 static void __exit bcm5974_exit(void)
775 usb_deregister(&bcm5974_driver);
778 module_init(bcm5974_init);
779 module_exit(bcm5974_exit);