[Bluetooth] Add full quirk implementation for btusb driver
[linux-2.6.git] / drivers / bluetooth / btusb.c
1 /*
2  *
3  *  Generic Bluetooth USB driver
4  *
5  *  Copyright (C) 2005-2007  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
30 #include <linux/errno.h>
31 #include <linux/skbuff.h>
32
33 #include <linux/usb.h>
34
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
37
38 //#define CONFIG_BT_HCIBTUSB_DEBUG
39 #ifndef CONFIG_BT_HCIBTUSB_DEBUG
40 #undef  BT_DBG
41 #define BT_DBG(D...)
42 #endif
43
44 #define VERSION "0.2"
45
46 static int ignore_dga;
47 static int ignore_csr;
48 static int ignore_sniffer;
49 static int disable_scofix;
50 static int force_scofix;
51 static int reset;
52
53 static struct usb_driver btusb_driver;
54
55 #define BTUSB_IGNORE            0x01
56 #define BTUSB_RESET             0x02
57 #define BTUSB_DIGIANSWER        0x04
58 #define BTUSB_CSR               0x08
59 #define BTUSB_SNIFFER           0x10
60 #define BTUSB_BCM92035          0x20
61 #define BTUSB_BROKEN_ISOC       0x40
62 #define BTUSB_WRONG_SCO_MTU     0x80
63
64 static struct usb_device_id btusb_table[] = {
65         /* Generic Bluetooth USB device */
66         { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
67
68         /* AVM BlueFRITZ! USB v2.0 */
69         { USB_DEVICE(0x057c, 0x3800) },
70
71         /* Bluetooth Ultraport Module from IBM */
72         { USB_DEVICE(0x04bf, 0x030a) },
73
74         /* ALPS Modules with non-standard id */
75         { USB_DEVICE(0x044e, 0x3001) },
76         { USB_DEVICE(0x044e, 0x3002) },
77
78         /* Ericsson with non-standard id */
79         { USB_DEVICE(0x0bdb, 0x1002) },
80
81         /* Canyon CN-BTU1 with HID interfaces */
82         { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_RESET },
83
84         { }     /* Terminating entry */
85 };
86
87 MODULE_DEVICE_TABLE(usb, btusb_table);
88
89 static struct usb_device_id blacklist_table[] = {
90         /* CSR BlueCore devices */
91         { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
92
93         /* Broadcom BCM2033 without firmware */
94         { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
95
96         /* Broadcom BCM2035 */
97         { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
98         { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
99
100         /* Broadcom BCM2045 */
101         { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
102         { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
103
104         /* Broadcom BCM2046 */
105         { USB_DEVICE(0x0a5c, 0x2151), .driver_info = BTUSB_RESET },
106
107         /* IBM/Lenovo ThinkPad with Broadcom chip */
108         { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
109         { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
110
111         /* Targus ACB10US */
112         { USB_DEVICE(0x0a5c, 0x2100), .driver_info = BTUSB_RESET },
113
114         /* ANYCOM Bluetooth USB-200 and USB-250 */
115         { USB_DEVICE(0x0a5c, 0x2111), .driver_info = BTUSB_RESET },
116
117         /* HP laptop with Broadcom chip */
118         { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
119
120         /* Dell laptop with Broadcom chip */
121         { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
122
123         /* Dell Wireless 370 */
124         { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
125
126         /* Dell Wireless 410 */
127         { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
128
129         /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
130         { USB_DEVICE(0x045e, 0x009c), .driver_info = BTUSB_RESET },
131
132         /* Kensington Bluetooth USB adapter */
133         { USB_DEVICE(0x047d, 0x105d), .driver_info = BTUSB_RESET },
134         { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
135
136         /* ISSC Bluetooth Adapter v3.1 */
137         { USB_DEVICE(0x1131, 0x1001), .driver_info = BTUSB_RESET },
138
139         /* RTX Telecom based adapters with buggy SCO support */
140         { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
141         { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
142
143         /* CONWISE Technology based adapters with buggy SCO support */
144         { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
145
146         /* Belkin F8T012 and F8T013 devices */
147         { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
148         { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
149
150         /* Digianswer devices */
151         { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
152         { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
153
154         /* CSR BlueCore Bluetooth Sniffer */
155         { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
156
157         /* Frontline ComProbe Bluetooth Sniffer */
158         { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
159
160         { }     /* Terminating entry */
161 };
162
163 #define BTUSB_INTR_RUNNING      0
164 #define BTUSB_BULK_RUNNING      1
165
166 struct btusb_data {
167         struct hci_dev       *hdev;
168         struct usb_device    *udev;
169
170         spinlock_t lock;
171
172         unsigned long flags;
173
174         struct work_struct work;
175
176         struct usb_anchor tx_anchor;
177         struct usb_anchor intr_anchor;
178         struct usb_anchor bulk_anchor;
179
180         struct usb_endpoint_descriptor *intr_ep;
181         struct usb_endpoint_descriptor *bulk_tx_ep;
182         struct usb_endpoint_descriptor *bulk_rx_ep;
183 };
184
185 static void btusb_intr_complete(struct urb *urb)
186 {
187         struct hci_dev *hdev = urb->context;
188         struct btusb_data *data = hdev->driver_data;
189         int err;
190
191         BT_DBG("%s urb %p status %d count %d", hdev->name,
192                                         urb, urb->status, urb->actual_length);
193
194         if (!test_bit(HCI_RUNNING, &hdev->flags))
195                 return;
196
197         if (urb->status == 0) {
198                 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
199                                                 urb->transfer_buffer,
200                                                 urb->actual_length) < 0) {
201                         BT_ERR("%s corrupted event packet", hdev->name);
202                         hdev->stat.err_rx++;
203                 }
204         }
205
206         if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
207                 return;
208
209         usb_anchor_urb(urb, &data->intr_anchor);
210
211         err = usb_submit_urb(urb, GFP_ATOMIC);
212         if (err < 0) {
213                 BT_ERR("%s urb %p failed to resubmit (%d)",
214                                                 hdev->name, urb, -err);
215                 usb_unanchor_urb(urb);
216         }
217 }
218
219 static inline int btusb_submit_intr_urb(struct hci_dev *hdev)
220 {
221         struct btusb_data *data = hdev->driver_data;
222         struct urb *urb;
223         unsigned char *buf;
224         unsigned int pipe;
225         int err, size;
226
227         BT_DBG("%s", hdev->name);
228
229         urb = usb_alloc_urb(0, GFP_ATOMIC);
230         if (!urb)
231                 return -ENOMEM;
232
233         size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
234
235         buf = kmalloc(size, GFP_ATOMIC);
236         if (!buf) {
237                 usb_free_urb(urb);
238                 return -ENOMEM;
239         }
240
241         pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
242
243         usb_fill_int_urb(urb, data->udev, pipe, buf, size,
244                                                 btusb_intr_complete, hdev,
245                                                 data->intr_ep->bInterval);
246
247         urb->transfer_flags |= URB_FREE_BUFFER;
248
249         usb_anchor_urb(urb, &data->intr_anchor);
250
251         err = usb_submit_urb(urb, GFP_ATOMIC);
252         if (err < 0) {
253                 BT_ERR("%s urb %p submission failed (%d)",
254                                                 hdev->name, urb, -err);
255                 usb_unanchor_urb(urb);
256                 kfree(buf);
257         }
258
259         usb_free_urb(urb);
260
261         return err;
262 }
263
264 static void btusb_bulk_complete(struct urb *urb)
265 {
266         struct hci_dev *hdev = urb->context;
267         struct btusb_data *data = hdev->driver_data;
268         int err;
269
270         BT_DBG("%s urb %p status %d count %d", hdev->name,
271                                         urb, urb->status, urb->actual_length);
272
273         if (!test_bit(HCI_RUNNING, &hdev->flags))
274                 return;
275
276         if (urb->status == 0) {
277                 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
278                                                 urb->transfer_buffer,
279                                                 urb->actual_length) < 0) {
280                         BT_ERR("%s corrupted ACL packet", hdev->name);
281                         hdev->stat.err_rx++;
282                 }
283         }
284
285         if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
286                 return;
287
288         usb_anchor_urb(urb, &data->bulk_anchor);
289
290         err = usb_submit_urb(urb, GFP_ATOMIC);
291         if (err < 0) {
292                 BT_ERR("%s urb %p failed to resubmit (%d)",
293                                                 hdev->name, urb, -err);
294                 usb_unanchor_urb(urb);
295         }
296 }
297
298 static inline int btusb_submit_bulk_urb(struct hci_dev *hdev)
299 {
300         struct btusb_data *data = hdev->driver_data;
301         struct urb *urb;
302         unsigned char *buf;
303         unsigned int pipe;
304         int err, size;
305
306         BT_DBG("%s", hdev->name);
307
308         urb = usb_alloc_urb(0, GFP_KERNEL);
309         if (!urb)
310                 return -ENOMEM;
311
312         size = le16_to_cpu(data->bulk_rx_ep->wMaxPacketSize);
313
314         buf = kmalloc(size, GFP_KERNEL);
315         if (!buf) {
316                 usb_free_urb(urb);
317                 return -ENOMEM;
318         }
319
320         pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
321
322         usb_fill_bulk_urb(urb, data->udev, pipe,
323                                         buf, size, btusb_bulk_complete, hdev);
324
325         urb->transfer_flags |= URB_FREE_BUFFER;
326
327         usb_anchor_urb(urb, &data->bulk_anchor);
328
329         err = usb_submit_urb(urb, GFP_KERNEL);
330         if (err < 0) {
331                 BT_ERR("%s urb %p submission failed (%d)",
332                                                 hdev->name, urb, -err);
333                 usb_unanchor_urb(urb);
334                 kfree(buf);
335         }
336
337         usb_free_urb(urb);
338
339         return err;
340 }
341
342 static void btusb_tx_complete(struct urb *urb)
343 {
344         struct sk_buff *skb = urb->context;
345         struct hci_dev *hdev = (struct hci_dev *) skb->dev;
346
347         BT_DBG("%s urb %p status %d count %d", hdev->name,
348                                         urb, urb->status, urb->actual_length);
349
350         if (!test_bit(HCI_RUNNING, &hdev->flags))
351                 goto done;
352
353         if (!urb->status)
354                 hdev->stat.byte_tx += urb->transfer_buffer_length;
355         else
356                 hdev->stat.err_tx++;
357
358 done:
359         kfree(urb->setup_packet);
360
361         kfree_skb(skb);
362 }
363
364 static int btusb_open(struct hci_dev *hdev)
365 {
366         struct btusb_data *data = hdev->driver_data;
367         int err;
368
369         BT_DBG("%s", hdev->name);
370
371         if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
372                 return 0;
373
374         if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
375                 return 0;
376
377         err = btusb_submit_intr_urb(hdev);
378         if (err < 0) {
379                 clear_bit(BTUSB_INTR_RUNNING, &hdev->flags);
380                 clear_bit(HCI_RUNNING, &hdev->flags);
381         }
382
383         return err;
384 }
385
386 static int btusb_close(struct hci_dev *hdev)
387 {
388         struct btusb_data *data = hdev->driver_data;
389
390         BT_DBG("%s", hdev->name);
391
392         if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
393                 return 0;
394
395         clear_bit(BTUSB_BULK_RUNNING, &data->flags);
396         usb_kill_anchored_urbs(&data->bulk_anchor);
397
398         clear_bit(BTUSB_INTR_RUNNING, &data->flags);
399         usb_kill_anchored_urbs(&data->intr_anchor);
400
401         return 0;
402 }
403
404 static int btusb_flush(struct hci_dev *hdev)
405 {
406         struct btusb_data *data = hdev->driver_data;
407
408         BT_DBG("%s", hdev->name);
409
410         usb_kill_anchored_urbs(&data->tx_anchor);
411
412         return 0;
413 }
414
415 static int btusb_send_frame(struct sk_buff *skb)
416 {
417         struct hci_dev *hdev = (struct hci_dev *) skb->dev;
418         struct btusb_data *data = hdev->driver_data;
419         struct usb_ctrlrequest *dr;
420         struct urb *urb;
421         unsigned int pipe;
422         int err;
423
424         BT_DBG("%s", hdev->name);
425
426         if (!test_bit(HCI_RUNNING, &hdev->flags))
427                 return -EBUSY;
428
429         switch (bt_cb(skb)->pkt_type) {
430         case HCI_COMMAND_PKT:
431                 urb = usb_alloc_urb(0, GFP_ATOMIC);
432                 if (!urb)
433                         return -ENOMEM;
434
435                 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
436                 if (!dr) {
437                         usb_free_urb(urb);
438                         return -ENOMEM;
439                 }
440
441                 dr->bRequestType = USB_TYPE_CLASS;
442                 dr->bRequest     = 0;
443                 dr->wIndex       = 0;
444                 dr->wValue       = 0;
445                 dr->wLength      = __cpu_to_le16(skb->len);
446
447                 pipe = usb_sndctrlpipe(data->udev, 0x00);
448
449                 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
450                                 skb->data, skb->len, btusb_tx_complete, skb);
451
452                 hdev->stat.cmd_tx++;
453                 break;
454
455         case HCI_ACLDATA_PKT:
456                 urb = usb_alloc_urb(0, GFP_ATOMIC);
457                 if (!urb)
458                         return -ENOMEM;
459
460                 pipe = usb_sndbulkpipe(data->udev,
461                                         data->bulk_tx_ep->bEndpointAddress);
462
463                 usb_fill_bulk_urb(urb, data->udev, pipe,
464                                 skb->data, skb->len, btusb_tx_complete, skb);
465
466                 hdev->stat.acl_tx++;
467                 break;
468
469         case HCI_SCODATA_PKT:
470                 hdev->stat.sco_tx++;
471                 kfree_skb(skb);
472                 return 0;
473
474         default:
475                 return -EILSEQ;
476         }
477
478         usb_anchor_urb(urb, &data->tx_anchor);
479
480         err = usb_submit_urb(urb, GFP_ATOMIC);
481         if (err < 0) {
482                 BT_ERR("%s urb %p submission failed", hdev->name, urb);
483                 kfree(urb->setup_packet);
484                 usb_unanchor_urb(urb);
485         }
486
487         usb_free_urb(urb);
488
489         return err;
490 }
491
492 static void btusb_destruct(struct hci_dev *hdev)
493 {
494         struct btusb_data *data = hdev->driver_data;
495
496         BT_DBG("%s", hdev->name);
497
498         kfree(data);
499 }
500
501 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
502 {
503         struct btusb_data *data = hdev->driver_data;
504
505         BT_DBG("%s evt %d", hdev->name, evt);
506
507         if (evt == HCI_NOTIFY_CONN_ADD || evt == HCI_NOTIFY_CONN_DEL)
508                 schedule_work(&data->work);
509 }
510
511 static void btusb_work(struct work_struct *work)
512 {
513         struct btusb_data *data = container_of(work, struct btusb_data, work);
514         struct hci_dev *hdev = data->hdev;
515
516         if (hdev->conn_hash.acl_num == 0) {
517                 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
518                 usb_kill_anchored_urbs(&data->bulk_anchor);
519                 return;
520         }
521
522         if (!test_and_set_bit(BTUSB_BULK_RUNNING, &data->flags)) {
523                 if (btusb_submit_bulk_urb(hdev) < 0)
524                         clear_bit(BTUSB_BULK_RUNNING, &data->flags);
525                 else
526                         btusb_submit_bulk_urb(hdev);
527         }
528 }
529
530 static int btusb_probe(struct usb_interface *intf,
531                                 const struct usb_device_id *id)
532 {
533         struct usb_endpoint_descriptor *ep_desc;
534         struct btusb_data *data;
535         struct hci_dev *hdev;
536         int i, err;
537
538         BT_DBG("intf %p id %p", intf, id);
539
540         /* interface numbers are hardcoded in the spec */
541         if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
542                 return -ENODEV;
543
544         if (!id->driver_info) {
545                 const struct usb_device_id *match;
546                 match = usb_match_id(intf, blacklist_table);
547                 if (match)
548                         id = match;
549         }
550
551         if (id->driver_info == BTUSB_IGNORE)
552                 return -ENODEV;
553
554         if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
555                 return -ENODEV;
556
557         if (ignore_csr && id->driver_info & BTUSB_CSR)
558                 return -ENODEV;
559
560         if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
561                 return -ENODEV;
562
563         data = kzalloc(sizeof(*data), GFP_KERNEL);
564         if (!data)
565                 return -ENOMEM;
566
567         for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
568                 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
569
570                 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
571                         data->intr_ep = ep_desc;
572                         continue;
573                 }
574
575                 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
576                         data->bulk_tx_ep = ep_desc;
577                         continue;
578                 }
579
580                 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
581                         data->bulk_rx_ep = ep_desc;
582                         continue;
583                 }
584         }
585
586         if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
587                 kfree(data);
588                 return -ENODEV;
589         }
590
591         data->udev = interface_to_usbdev(intf);
592
593         spin_lock_init(&data->lock);
594
595         INIT_WORK(&data->work, btusb_work);
596
597         init_usb_anchor(&data->tx_anchor);
598         init_usb_anchor(&data->intr_anchor);
599         init_usb_anchor(&data->bulk_anchor);
600
601         hdev = hci_alloc_dev();
602         if (!hdev) {
603                 kfree(data);
604                 return -ENOMEM;
605         }
606
607         hdev->type = HCI_USB;
608         hdev->driver_data = data;
609
610         data->hdev = hdev;
611
612         SET_HCIDEV_DEV(hdev, &intf->dev);
613
614         hdev->open     = btusb_open;
615         hdev->close    = btusb_close;
616         hdev->flush    = btusb_flush;
617         hdev->send     = btusb_send_frame;
618         hdev->destruct = btusb_destruct;
619         hdev->notify   = btusb_notify;
620
621         hdev->owner = THIS_MODULE;
622
623         if (reset || id->driver_info & BTUSB_RESET)
624                 set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
625
626         if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
627                 if (!disable_scofix)
628                         set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
629         }
630
631         if (id->driver_info & BTUSB_SNIFFER) {
632                 struct usb_device *udev = interface_to_usbdev(intf);
633
634                 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
635                         set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
636         }
637
638         if (id->driver_info & BTUSB_BCM92035) {
639                 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
640                 struct sk_buff *skb;
641
642                 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
643                 if (skb) {
644                         memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
645                         skb_queue_tail(&hdev->driver_init, skb);
646                 }
647         }
648
649         err = hci_register_dev(hdev);
650         if (err < 0) {
651                 hci_free_dev(hdev);
652                 kfree(data);
653                 return err;
654         }
655
656         usb_set_intfdata(intf, data);
657
658         return 0;
659 }
660
661 static void btusb_disconnect(struct usb_interface *intf)
662 {
663         struct btusb_data *data = usb_get_intfdata(intf);
664         struct hci_dev *hdev;
665
666         BT_DBG("intf %p", intf);
667
668         if (!data)
669                 return;
670
671         hdev = data->hdev;
672
673         usb_set_intfdata(intf, NULL);
674
675         hci_unregister_dev(hdev);
676
677         hci_free_dev(hdev);
678 }
679
680 static struct usb_driver btusb_driver = {
681         .name           = "btusb",
682         .probe          = btusb_probe,
683         .disconnect     = btusb_disconnect,
684         .id_table       = btusb_table,
685 };
686
687 static int __init btusb_init(void)
688 {
689         BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
690
691         return usb_register(&btusb_driver);
692 }
693
694 static void __exit btusb_exit(void)
695 {
696         usb_deregister(&btusb_driver);
697 }
698
699 module_init(btusb_init);
700 module_exit(btusb_exit);
701
702 module_param(ignore_dga, bool, 0644);
703 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
704
705 module_param(ignore_csr, bool, 0644);
706 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
707
708 module_param(ignore_sniffer, bool, 0644);
709 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
710
711 module_param(disable_scofix, bool, 0644);
712 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
713
714 module_param(force_scofix, bool, 0644);
715 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
716
717 module_param(reset, bool, 0644);
718 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
719
720 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
721 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
722 MODULE_VERSION(VERSION);
723 MODULE_LICENSE("GPL");