1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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>
43
44#define USB_VENDOR_ID_APPLE 0x05ac
45
46
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
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
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
58
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 \
67}
68
69
70static const struct usb_device_id bcm5974_table[] = {
71
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
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),
79
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
84 {}
85};
86MODULE_DEVICE_TABLE(usb, bcm5974_table);
87
88MODULE_AUTHOR("Henrik Rydberg");
89MODULE_DESCRIPTION("Apple USB BCM5974 multitouch driver");
90MODULE_LICENSE("GPL");
91
92#define dprintk(level, format, a...)\
93 { if (debug >= level) printk(KERN_DEBUG format, ##a); }
94
95static int debug = 1;
96module_param(debug, int, 0644);
97MODULE_PARM_DESC(debug, "Activate debugging output");
98
99
100struct bt_data {
101 u8 unknown1;
102 u8 button;
103 u8 rel_x;
104 u8 rel_y;
105};
106
107
108enum tp_type {
109 TYPE1,
110 TYPE2
111};
112
113
114#define FINGER_TYPE1 (13 * sizeof(__le16))
115#define FINGER_TYPE2 (15 * sizeof(__le16))
116
117
118#define BUTTON_TYPE2 15
119
120
121#define HAS_INTEGRATED_BUTTON 1
122
123
124struct tp_finger {
125 __le16 origin;
126 __le16 abs_x;
127 __le16 abs_y;
128 __le16 rel_x;
129 __le16 rel_y;
130 __le16 size_major;
131 __le16 size_minor;
132 __le16 orientation;
133 __le16 force_major;
134 __le16 force_minor;
135 __le16 unused[3];
136 __le16 multi;
137} __attribute__((packed,aligned(2)));
138
139
140#define SIZEOF_FINGER sizeof(struct tp_finger)
141#define SIZEOF_ALL_FINGERS (16 * SIZEOF_FINGER)
142
143
144struct bcm5974_param {
145 int dim;
146 int fuzz;
147 int devmin;
148 int devmax;
149};
150
151
152struct bcm5974_config {
153 int ansi, iso, jis;
154 int caps;
155 int bt_ep;
156 int bt_datalen;
157 int tp_ep;
158 enum tp_type tp_type;
159 int tp_offset;
160 int tp_datalen;
161 struct bcm5974_param p;
162 struct bcm5974_param w;
163 struct bcm5974_param x;
164 struct bcm5974_param y;
165};
166
167
168struct bcm5974 {
169 char phys[64];
170 struct usb_device *udev;
171 struct usb_interface *intf;
172 struct input_dev *input;
173 struct bcm5974_config cfg;
174 struct mutex pm_mutex;
175 int opened;
176 struct urb *bt_urb;
177 struct bt_data *bt_data;
178 struct urb *tp_urb;
179 u8 *tp_data;
180 int fingers;
181};
182
183
184#define DIM_PRESSURE 256
185#define DIM_WIDTH 16
186#define DIM_X 1280
187#define DIM_Y 800
188
189
190#define SN_PRESSURE 45
191#define SN_WIDTH 100
192#define SN_COORD 250
193
194
195#define PRESSURE_LOW (2 * DIM_PRESSURE / SN_PRESSURE)
196#define PRESSURE_HIGH (3 * PRESSURE_LOW)
197
198
199static const struct bcm5974_config bcm5974_config_table[] = {
200 {
201 USB_DEVICE_ID_APPLE_WELLSPRING_ANSI,
202 USB_DEVICE_ID_APPLE_WELLSPRING_ISO,
203 USB_DEVICE_ID_APPLE_WELLSPRING_JIS,
204 0,
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 }
211 },
212 {
213 USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI,
214 USB_DEVICE_ID_APPLE_WELLSPRING2_ISO,
215 USB_DEVICE_ID_APPLE_WELLSPRING2_JIS,
216 0,
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 }
223 },
224 {
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 }
235 },
236 {}
237};
238
239
240static const struct bcm5974_config *bcm5974_get_config(struct usb_device *udev)
241{
242 u16 id = le16_to_cpu(udev->descriptor.idProduct);
243 const struct bcm5974_config *cfg;
244
245 for (cfg = bcm5974_config_table; cfg->ansi; ++cfg)
246 if (cfg->ansi == id || cfg->iso == id || cfg->jis == id)
247 return cfg;
248
249 return bcm5974_config_table;
250}
251
252
253static inline int raw2int(__le16 x)
254{
255 return (signed short)le16_to_cpu(x);
256}
257
258
259static inline int int2scale(const struct bcm5974_param *p, int x)
260{
261 return x * p->dim / (p->devmax - p->devmin);
262}
263
264
265static inline int int2bound(const struct bcm5974_param *p, int x)
266{
267 int s = int2scale(p, x);
268
269 return clamp_val(s, 0, p->dim - 1);
270}
271
272
273static void setup_events_to_report(struct input_dev *input_dev,
274 const struct bcm5974_config *cfg)
275{
276 __set_bit(EV_ABS, input_dev->evbit);
277
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);
286
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);
294}
295
296
297static int report_bt_state(struct bcm5974 *dev, int size)
298{
299 if (size != sizeof(struct bt_data))
300 return -EIO;
301
302 dprintk(7,
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);
306
307 input_report_key(dev->input, BTN_LEFT, dev->bt_data->button);
308 input_sync(dev->input);
309
310 return 0;
311}
312
313
314static int report_tp_state(struct bcm5974 *dev, int size)
315{
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, origin, ibt = 0, nmin = 0, nmax = 0;
321 int abs_p = 0, abs_w = 0, abs_x = 0, abs_y = 0;
322
323 if (size < c->tp_offset || (size - c->tp_offset) % SIZEOF_FINGER != 0)
324 return -EIO;
325
326
327 f = (const struct tp_finger *)(dev->tp_data + c->tp_offset);
328 raw_n = (size - c->tp_offset) / SIZEOF_FINGER;
329
330
331 if (raw_n) {
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);
336
337 dprintk(9,
338 "bcm5974: "
339 "raw: p: %+05d w: %+05d x: %+05d y: %+05d n: %d\n",
340 raw_p, raw_w, raw_x, raw_y, raw_n);
341
342 ptest = int2bound(&c->p, raw_p);
343 origin = raw2int(f->origin);
344
345
346 if (c->tp_type == TYPE2)
347 ibt = raw2int(dev->tp_data[BUTTON_TYPE2]);
348
349
350 if (ptest > PRESSURE_LOW && origin) {
351 abs_p = ptest;
352 abs_w = int2bound(&c->w, raw_w);
353 abs_x = int2bound(&c->x, raw_x - c->x.devmin);
354 abs_y = int2bound(&c->y, c->y.devmax - raw_y);
355 while (raw_n--) {
356 ptest = int2bound(&c->p,
357 raw2int(f->force_major));
358 if (ptest > PRESSURE_LOW)
359 nmax++;
360 if (ptest > PRESSURE_HIGH)
361 nmin++;
362 f++;
363 }
364 }
365 }
366
367 if (dev->fingers < nmin)
368 dev->fingers = nmin;
369 if (dev->fingers > nmax)
370 dev->fingers = nmax;
371
372 input_report_key(input, BTN_TOUCH, dev->fingers > 0);
373 input_report_key(input, BTN_TOOL_FINGER, dev->fingers == 1);
374 input_report_key(input, BTN_TOOL_DOUBLETAP, dev->fingers == 2);
375 input_report_key(input, BTN_TOOL_TRIPLETAP, dev->fingers == 3);
376 input_report_key(input, BTN_TOOL_QUADTAP, dev->fingers > 3);
377
378 input_report_abs(input, ABS_PRESSURE, abs_p);
379 input_report_abs(input, ABS_TOOL_WIDTH, abs_w);
380
381 if (abs_p) {
382 input_report_abs(input, ABS_X, abs_x);
383 input_report_abs(input, ABS_Y, abs_y);
384
385 dprintk(8,
386 "bcm5974: abs: p: %+05d w: %+05d x: %+05d y: %+05d "
387 "nmin: %d nmax: %d n: %d ibt: %d\n", abs_p, abs_w,
388 abs_x, abs_y, nmin, nmax, dev->fingers, ibt);
389
390 }
391
392
393 if (c->tp_type == TYPE2)
394 input_report_key(input, BTN_LEFT, ibt);
395
396 input_sync(input);
397
398 return 0;
399}
400
401
402#define BCM5974_WELLSPRING_MODE_READ_REQUEST_ID 1
403#define BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID 9
404#define BCM5974_WELLSPRING_MODE_REQUEST_VALUE 0x300
405#define BCM5974_WELLSPRING_MODE_REQUEST_INDEX 0
406#define BCM5974_WELLSPRING_MODE_VENDOR_VALUE 0x01
407#define BCM5974_WELLSPRING_MODE_NORMAL_VALUE 0x08
408
409static int bcm5974_wellspring_mode(struct bcm5974 *dev, bool on)
410{
411 char *data = kmalloc(8, GFP_KERNEL);
412 int retval = 0, size;
413
414 if (!data) {
415 err("bcm5974: out of memory");
416 retval = -ENOMEM;
417 goto out;
418 }
419
420
421 size = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
422 BCM5974_WELLSPRING_MODE_READ_REQUEST_ID,
423 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
424 BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
425 BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
426
427 if (size != 8) {
428 err("bcm5974: could not read from device");
429 retval = -EIO;
430 goto out;
431 }
432
433
434 data[0] = on ?
435 BCM5974_WELLSPRING_MODE_VENDOR_VALUE :
436 BCM5974_WELLSPRING_MODE_NORMAL_VALUE;
437
438
439 size = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
440 BCM5974_WELLSPRING_MODE_WRITE_REQUEST_ID,
441 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
442 BCM5974_WELLSPRING_MODE_REQUEST_VALUE,
443 BCM5974_WELLSPRING_MODE_REQUEST_INDEX, data, 8, 5000);
444
445 if (size != 8) {
446 err("bcm5974: could not write to device");
447 retval = -EIO;
448 goto out;
449 }
450
451 dprintk(2, "bcm5974: switched to %s mode.\n",
452 on ? "wellspring" : "normal");
453
454 out:
455 kfree(data);
456 return retval;
457}
458
459static void bcm5974_irq_button(struct urb *urb)
460{
461 struct bcm5974 *dev = urb->context;
462 int error;
463
464 switch (urb->status) {
465 case 0:
466 break;
467 case -EOVERFLOW:
468 case -ECONNRESET:
469 case -ENOENT:
470 case -ESHUTDOWN:
471 dbg("bcm5974: button urb shutting down: %d", urb->status);
472 return;
473 default:
474 dbg("bcm5974: button urb status: %d", urb->status);
475 goto exit;
476 }
477
478 if (report_bt_state(dev, dev->bt_urb->actual_length))
479 dprintk(1, "bcm5974: bad button package, length: %d\n",
480 dev->bt_urb->actual_length);
481
482exit:
483 error = usb_submit_urb(dev->bt_urb, GFP_ATOMIC);
484 if (error)
485 err("bcm5974: button urb failed: %d", error);
486}
487
488static void bcm5974_irq_trackpad(struct urb *urb)
489{
490 struct bcm5974 *dev = urb->context;
491 int error;
492
493 switch (urb->status) {
494 case 0:
495 break;
496 case -EOVERFLOW:
497 case -ECONNRESET:
498 case -ENOENT:
499 case -ESHUTDOWN:
500 dbg("bcm5974: trackpad urb shutting down: %d", urb->status);
501 return;
502 default:
503 dbg("bcm5974: trackpad urb status: %d", urb->status);
504 goto exit;
505 }
506
507
508 if (dev->tp_urb->actual_length == 2)
509 goto exit;
510
511 if (report_tp_state(dev, dev->tp_urb->actual_length))
512 dprintk(1, "bcm5974: bad trackpad package, length: %d\n",
513 dev->tp_urb->actual_length);
514
515exit:
516 error = usb_submit_urb(dev->tp_urb, GFP_ATOMIC);
517 if (error)
518 err("bcm5974: trackpad urb failed: %d", error);
519}
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539static int bcm5974_start_traffic(struct bcm5974 *dev)
540{
541 if (bcm5974_wellspring_mode(dev, true)) {
542 dprintk(1, "bcm5974: mode switch failed\n");
543 goto error;
544 }
545
546 if (usb_submit_urb(dev->bt_urb, GFP_KERNEL))
547 goto error;
548
549 if (usb_submit_urb(dev->tp_urb, GFP_KERNEL))
550 goto err_kill_bt;
551
552 return 0;
553
554err_kill_bt:
555 usb_kill_urb(dev->bt_urb);
556error:
557 return -EIO;
558}
559
560static void bcm5974_pause_traffic(struct bcm5974 *dev)
561{
562 usb_kill_urb(dev->tp_urb);
563 usb_kill_urb(dev->bt_urb);
564 bcm5974_wellspring_mode(dev, false);
565}
566
567
568
569
570
571
572
573
574
575static int bcm5974_open(struct input_dev *input)
576{
577 struct bcm5974 *dev = input_get_drvdata(input);
578 int error;
579
580 error = usb_autopm_get_interface(dev->intf);
581 if (error)
582 return error;
583
584 mutex_lock(&dev->pm_mutex);
585
586 error = bcm5974_start_traffic(dev);
587 if (!error)
588 dev->opened = 1;
589
590 mutex_unlock(&dev->pm_mutex);
591
592 if (error)
593 usb_autopm_put_interface(dev->intf);
594
595 return error;
596}
597
598static void bcm5974_close(struct input_dev *input)
599{
600 struct bcm5974 *dev = input_get_drvdata(input);
601
602 mutex_lock(&dev->pm_mutex);
603
604 bcm5974_pause_traffic(dev);
605 dev->opened = 0;
606
607 mutex_unlock(&dev->pm_mutex);
608
609 usb_autopm_put_interface(dev->intf);
610}
611
612static int bcm5974_suspend(struct usb_interface *iface, pm_message_t message)
613{
614 struct bcm5974 *dev = usb_get_intfdata(iface);
615
616 mutex_lock(&dev->pm_mutex);
617
618 if (dev->opened)
619 bcm5974_pause_traffic(dev);
620
621 mutex_unlock(&dev->pm_mutex);
622
623 return 0;
624}
625
626static int bcm5974_resume(struct usb_interface *iface)
627{
628 struct bcm5974 *dev = usb_get_intfdata(iface);
629 int error = 0;
630
631 mutex_lock(&dev->pm_mutex);
632
633 if (dev->opened)
634 error = bcm5974_start_traffic(dev);
635
636 mutex_unlock(&dev->pm_mutex);
637
638 return error;
639}
640
641static int bcm5974_probe(struct usb_interface *iface,
642 const struct usb_device_id *id)
643{
644 struct usb_device *udev = interface_to_usbdev(iface);
645 const struct bcm5974_config *cfg;
646 struct bcm5974 *dev;
647 struct input_dev *input_dev;
648 int error = -ENOMEM;
649
650
651 cfg = bcm5974_get_config(udev);
652
653
654 dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL);
655 input_dev = input_allocate_device();
656 if (!dev || !input_dev) {
657 err("bcm5974: out of memory");
658 goto err_free_devs;
659 }
660
661 dev->udev = udev;
662 dev->intf = iface;
663 dev->input = input_dev;
664 dev->cfg = *cfg;
665 mutex_init(&dev->pm_mutex);
666
667
668 dev->bt_urb = usb_alloc_urb(0, GFP_KERNEL);
669 if (!dev->bt_urb)
670 goto err_free_devs;
671
672 dev->tp_urb = usb_alloc_urb(0, GFP_KERNEL);
673 if (!dev->tp_urb)
674 goto err_free_bt_urb;
675
676 dev->bt_data = usb_buffer_alloc(dev->udev,
677 dev->cfg.bt_datalen, GFP_KERNEL,
678 &dev->bt_urb->transfer_dma);
679 if (!dev->bt_data)
680 goto err_free_urb;
681
682 dev->tp_data = usb_buffer_alloc(dev->udev,
683 dev->cfg.tp_datalen, GFP_KERNEL,
684 &dev->tp_urb->transfer_dma);
685 if (!dev->tp_data)
686 goto err_free_bt_buffer;
687
688 usb_fill_int_urb(dev->bt_urb, udev,
689 usb_rcvintpipe(udev, cfg->bt_ep),
690 dev->bt_data, dev->cfg.bt_datalen,
691 bcm5974_irq_button, dev, 1);
692
693 usb_fill_int_urb(dev->tp_urb, udev,
694 usb_rcvintpipe(udev, cfg->tp_ep),
695 dev->tp_data, dev->cfg.tp_datalen,
696 bcm5974_irq_trackpad, dev, 1);
697
698
699 usb_make_path(udev, dev->phys, sizeof(dev->phys));
700 strlcat(dev->phys, "/input0", sizeof(dev->phys));
701
702 input_dev->name = "bcm5974";
703 input_dev->phys = dev->phys;
704 usb_to_input_id(dev->udev, &input_dev->id);
705
706 input_dev->id.version = cfg->caps;
707 input_dev->dev.parent = &iface->dev;
708
709 input_set_drvdata(input_dev, dev);
710
711 input_dev->open = bcm5974_open;
712 input_dev->close = bcm5974_close;
713
714 setup_events_to_report(input_dev, cfg);
715
716 error = input_register_device(dev->input);
717 if (error)
718 goto err_free_buffer;
719
720
721 usb_set_intfdata(iface, dev);
722
723 return 0;
724
725err_free_buffer:
726 usb_buffer_free(dev->udev, dev->cfg.tp_datalen,
727 dev->tp_data, dev->tp_urb->transfer_dma);
728err_free_bt_buffer:
729 usb_buffer_free(dev->udev, dev->cfg.bt_datalen,
730 dev->bt_data, dev->bt_urb->transfer_dma);
731err_free_urb:
732 usb_free_urb(dev->tp_urb);
733err_free_bt_urb:
734 usb_free_urb(dev->bt_urb);
735err_free_devs:
736 usb_set_intfdata(iface, NULL);
737 input_free_device(input_dev);
738 kfree(dev);
739 return error;
740}
741
742static void bcm5974_disconnect(struct usb_interface *iface)
743{
744 struct bcm5974 *dev = usb_get_intfdata(iface);
745
746 usb_set_intfdata(iface, NULL);
747
748 input_unregister_device(dev->input);
749 usb_buffer_free(dev->udev, dev->cfg.tp_datalen,
750 dev->tp_data, dev->tp_urb->transfer_dma);
751 usb_buffer_free(dev->udev, dev->cfg.bt_datalen,
752 dev->bt_data, dev->bt_urb->transfer_dma);
753 usb_free_urb(dev->tp_urb);
754 usb_free_urb(dev->bt_urb);
755 kfree(dev);
756}
757
758static struct usb_driver bcm5974_driver = {
759 .name = "bcm5974",
760 .probe = bcm5974_probe,
761 .disconnect = bcm5974_disconnect,
762 .suspend = bcm5974_suspend,
763 .resume = bcm5974_resume,
764 .reset_resume = bcm5974_resume,
765 .id_table = bcm5974_table,
766 .supports_autosuspend = 1,
767};
768
769static int __init bcm5974_init(void)
770{
771 return usb_register(&bcm5974_driver);
772}
773
774static void __exit bcm5974_exit(void)
775{
776 usb_deregister(&bcm5974_driver);
777}
778
779module_init(bcm5974_init);
780module_exit(bcm5974_exit);
781
782