V4L/DVB: tm6000: add tuner parameter for DVB devices
[cascardo/linux.git] / drivers / staging / tm6000 / tm6000-cards.c
1 /*
2    tm6000-cards.c - driver for TM5600/TM6000 USB video capture devices
3
4    Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation version 2
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/i2c.h>
25 #include <linux/usb.h>
26 #include <linux/version.h>
27 #include <media/v4l2-common.h>
28 #include <media/tuner.h>
29 #include <media/tvaudio.h>
30 #include <media/i2c-addr.h>
31
32 #include "tm6000.h"
33 #include "tm6000-regs.h"
34 #include "tuner-xc2028.h"
35 #include "xc5000.h"
36
37 #define TM6000_BOARD_UNKNOWN                    0
38 #define TM5600_BOARD_GENERIC                    1
39 #define TM6000_BOARD_GENERIC                    2
40 #define TM6010_BOARD_GENERIC                    3
41 #define TM5600_BOARD_10MOONS_UT821              4
42 #define TM5600_BOARD_10MOONS_UT330              5
43 #define TM6000_BOARD_ADSTECH_DUAL_TV            6
44 #define TM6000_BOARD_FREECOM_AND_SIMILAR        7
45 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV       8
46 #define TM6010_BOARD_HAUPPAUGE_900H             9
47 #define TM6010_BOARD_BEHOLD_WANDER              10
48 #define TM6010_BOARD_BEHOLD_VOYAGER             11
49 #define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
50
51 #define TM6000_MAXBOARDS        16
52 static unsigned int card[]     = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
53
54 module_param_array(card,  int, NULL, 0444);
55
56 static unsigned long tm6000_devused;
57
58
59 struct tm6000_board {
60         char            *name;
61
62         struct tm6000_capabilities caps;
63
64         enum            tm6000_devtype type;    /* variant of the chipset */
65         int             tuner_type;     /* type of the tuner */
66         int             tuner_addr;     /* tuner address */
67         int             demod_addr;     /* demodulator address */
68         int             gpio_addr_tun_reset;    /* GPIO used for tuner reset */
69 };
70
71 struct tm6000_board tm6000_boards[] = {
72         [TM6000_BOARD_UNKNOWN] = {
73                 .name         = "Unknown tm6000 video grabber",
74                 .caps = {
75                         .has_tuner    = 1,
76                 },
77                 .gpio_addr_tun_reset = TM6000_GPIO_1,
78         },
79         [TM5600_BOARD_GENERIC] = {
80                 .name         = "Generic tm5600 board",
81                 .type         = TM5600,
82                 .tuner_type   = TUNER_XC2028,
83                 .tuner_addr   = 0xc2 >> 1,
84                 .caps = {
85                         .has_tuner      = 1,
86                 },
87                 .gpio_addr_tun_reset = TM6000_GPIO_1,
88         },
89         [TM6000_BOARD_GENERIC] = {
90                 .name         = "Generic tm6000 board",
91                 .tuner_type   = TUNER_XC2028,
92                 .tuner_addr   = 0xc2 >> 1,
93                 .caps = {
94                         .has_tuner      = 1,
95                         .has_dvb        = 1,
96                 },
97                 .gpio_addr_tun_reset = TM6000_GPIO_1,
98         },
99         [TM6010_BOARD_GENERIC] = {
100                 .name         = "Generic tm6010 board",
101                 .type         = TM6010,
102                 .tuner_type   = TUNER_XC2028,
103                 .tuner_addr   = 0xc2 >> 1,
104                 .caps = {
105                         .has_tuner      = 1,
106                         .has_dvb        = 1,
107                 },
108                 .gpio_addr_tun_reset = TM6010_GPIO_4,
109         },
110         [TM5600_BOARD_10MOONS_UT821] = {
111                 .name         = "10Moons UT 821",
112                 .tuner_type   = TUNER_XC2028,
113                 .type         = TM5600,
114                 .tuner_addr   = 0xc2 >> 1,
115                 .caps = {
116                         .has_tuner    = 1,
117                         .has_eeprom   = 1,
118                 },
119                 .gpio_addr_tun_reset = TM6000_GPIO_1,
120         },
121         [TM5600_BOARD_10MOONS_UT330] = {
122                 .name         = "10Moons UT 330",
123                 .tuner_type   = TUNER_PHILIPS_FQ1216AME_MK4,
124                 .tuner_addr   = 0xc8 >> 1,
125                 .caps = {
126                         .has_tuner    = 1,
127                         .has_dvb      = 0,
128                         .has_zl10353  = 0,
129                         .has_eeprom   = 1,
130                 },
131         },
132         [TM6000_BOARD_ADSTECH_DUAL_TV] = {
133                 .name         = "ADSTECH Dual TV USB",
134                 .tuner_type   = TUNER_XC2028,
135                 .tuner_addr   = 0xc8 >> 1,
136                 .caps = {
137                         .has_tuner    = 1,
138                         .has_tda9874  = 1,
139                         .has_dvb      = 1,
140                         .has_zl10353  = 1,
141                         .has_eeprom   = 1,
142                 },
143         },
144         [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
145                 .name         = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
146                 .tuner_type   = TUNER_XC2028, /* has a XC3028 */
147                 .tuner_addr   = 0xc2 >> 1,
148                 .demod_addr   = 0x1e >> 1,
149                 .caps = {
150                         .has_tuner    = 1,
151                         .has_dvb      = 1,
152                         .has_zl10353  = 1,
153                         .has_eeprom   = 0,
154                         .has_remote   = 1,
155                 },
156                 .gpio_addr_tun_reset = TM6000_GPIO_4,
157         },
158         [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
159                 .name         = "ADSTECH Mini Dual TV USB",
160                 .tuner_type   = TUNER_XC2028, /* has a XC3028 */
161                 .tuner_addr   = 0xc8 >> 1,
162                 .demod_addr   = 0x1e >> 1,
163                 .caps = {
164                         .has_tuner    = 1,
165                         .has_dvb      = 1,
166                         .has_zl10353  = 1,
167                         .has_eeprom   = 0,
168                 },
169                 .gpio_addr_tun_reset = TM6000_GPIO_4,
170         },
171         [TM6010_BOARD_HAUPPAUGE_900H] = {
172                 .name         = "Hauppauge HVR-900H",
173                 .tuner_type   = TUNER_XC2028, /* has a XC3028 */
174                 .tuner_addr   = 0xc2 >> 1,
175                 .demod_addr   = 0x1e >> 1,
176                 .type         = TM6010,
177                 .caps = {
178                         .has_tuner    = 1,
179                         .has_dvb      = 1,
180                         .has_zl10353  = 1,
181                         .has_eeprom   = 1,
182                 },
183                 .gpio_addr_tun_reset = TM6000_GPIO_2,
184         },
185         [TM6010_BOARD_BEHOLD_WANDER] = {
186                 .name         = "Beholder Wander DVB-T/TV/FM USB2.0",
187                 .tuner_type   = TUNER_XC5000,
188                 .tuner_addr   = 0xc2 >> 1,
189                 .demod_addr   = 0x1e >> 1,
190                 .type         = TM6010,
191                 .caps = {
192                         .has_tuner    = 1,
193                         .has_dvb      = 1,
194                         .has_zl10353  = 1,
195                         .has_eeprom   = 1,
196                         .has_remote   = 1,
197                 },
198                 .gpio_addr_tun_reset = TM6000_GPIO_2,
199         },
200         [TM6010_BOARD_BEHOLD_VOYAGER] = {
201                 .name         = "Beholder Voyager TV/FM USB2.0",
202                 .tuner_type   = TUNER_XC5000,
203                 .tuner_addr   = 0xc2 >> 1,
204                 .type         = TM6010,
205                 .caps = {
206                         .has_tuner    = 1,
207                         .has_dvb      = 0,
208                         .has_zl10353  = 0,
209                         .has_eeprom   = 1,
210                         .has_remote   = 1,
211                 },
212                 .gpio_addr_tun_reset = TM6000_GPIO_2,
213         },
214         [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
215                 .name         = "Terratec Cinergy Hybrid XE",
216                 .tuner_type   = TUNER_XC2028, /* has a XC3028 */
217                 .tuner_addr   = 0xc2 >> 1,
218                 .demod_addr   = 0x1e >> 1,
219                 .type         = TM6010,
220                 .caps = {
221                         .has_tuner    = 1,
222                         .has_dvb      = 1,
223                         .has_zl10353  = 1,
224                         .has_eeprom   = 1,
225                         .has_remote   = 1,
226                 },
227                 .gpio_addr_tun_reset = TM6010_GPIO_2,
228         }
229 };
230
231 /* table of devices that work with this driver */
232 struct usb_device_id tm6000_id_table [] = {
233         { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
234         { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
235         { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
236         { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
237         { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
238         { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
239         { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
240         { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
241         { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
242         { },
243 };
244
245 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
246
247 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
248 {
249         int rc=0;
250         struct tm6000_core *dev = ptr;
251
252         if (dev->tuner_type!=TUNER_XC2028)
253                 return 0;
254
255         switch (command) {
256         case XC2028_RESET_CLK:
257                 tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT,
258                                         0x02, arg);
259                 msleep(10);
260                 rc=tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
261                                         TM6000_GPIO_CLK, 0);
262                 if (rc<0)
263                         return rc;
264                 msleep(10);
265                 rc=tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
266                                         TM6000_GPIO_CLK, 1);
267                 break;
268         case XC2028_TUNER_RESET:
269                 /* Reset codes during load firmware */
270                 switch (arg) {
271                 case 0:
272                         tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
273                                         dev->tuner_reset_gpio, 0x00);
274                         msleep(130);
275                         tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
276                                         dev->tuner_reset_gpio, 0x01);
277                         msleep(130);
278                         break;
279                 case 1:
280                         tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT,
281                                                 0x02, 0x01);
282                         msleep(10);
283                         break;
284
285                 case 2:
286                         rc=tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
287                                                 TM6000_GPIO_CLK, 0);
288                         if (rc<0)
289                                 return rc;
290                         msleep(100);
291                         rc=tm6000_set_reg (dev, REQ_03_SET_GET_MCU_PIN,
292                                                 TM6000_GPIO_CLK, 1);
293                         msleep(100);
294                         break;
295                 }
296         }
297         return (rc);
298 }
299
300 static void tm6000_config_tuner (struct tm6000_core *dev)
301 {
302         struct tuner_setup           tun_setup;
303
304         /* Load tuner module */
305         v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
306                 "tuner", "tuner",dev->tuner_addr, NULL);
307
308         memset(&tun_setup, 0, sizeof(tun_setup));
309         tun_setup.type   = dev->tuner_type;
310         tun_setup.addr   = dev->tuner_addr;
311         tun_setup.mode_mask = T_ANALOG_TV | T_RADIO | T_DIGITAL_TV;
312         tun_setup.tuner_callback = tm6000_tuner_callback;
313
314         v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
315
316         if (dev->tuner_type == TUNER_XC2028) {
317                 struct v4l2_priv_tun_config  xc2028_cfg;
318                 struct xc2028_ctrl           ctl;
319
320                 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
321                 memset (&ctl,0,sizeof(ctl));
322
323                 ctl.input1 = 1;
324                 ctl.read_not_reliable = 0;
325                 ctl.msleep = 10;
326                 ctl.demod = XC3028_FE_ZARLINK456;
327                 ctl.vhfbw7 = 1;
328                 ctl.uhfbw8 = 1;
329                 xc2028_cfg.tuner = TUNER_XC2028;
330                 xc2028_cfg.priv  = &ctl;
331
332                 switch(dev->model) {
333                 case TM6010_BOARD_HAUPPAUGE_900H:
334                 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
335                         ctl.fname = "xc3028L-v36.fw";
336                         break;
337                 default:
338                         if (dev->dev_type == TM6010)
339                                 ctl.fname = "xc3028-v27.fw";
340                         else
341                                 ctl.fname = "tm6000-xc3028.fw";
342                 }
343
344                 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
345
346                 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
347                                      &xc2028_cfg);
348         }
349 }
350
351 static int tm6000_init_dev(struct tm6000_core *dev)
352 {
353         struct v4l2_frequency f;
354         int rc = 0;
355
356         mutex_init(&dev->lock);
357
358         mutex_lock(&dev->lock);
359
360         /* Initializa board-specific data */
361         dev->dev_type   = tm6000_boards[dev->model].type;
362         dev->tuner_type = tm6000_boards[dev->model].tuner_type;
363         dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
364         dev->tuner_reset_gpio = tm6000_boards[dev->model].gpio_addr_tun_reset;
365
366         dev->demod_addr = tm6000_boards[dev->model].demod_addr;
367
368         dev->caps = tm6000_boards[dev->model].caps;
369
370         /* initialize hardware */
371         rc=tm6000_init (dev);
372         if (rc<0)
373                 goto err;
374
375         rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
376         if (rc < 0)
377                 goto err;
378
379         /* register i2c bus */
380         rc=tm6000_i2c_register(dev);
381         if (rc<0)
382                 goto err;
383
384         /* register and initialize V4L2 */
385         rc=tm6000_v4l2_register(dev);
386         if (rc<0)
387                 goto err;
388
389         /* Default values for STD and resolutions */
390         dev->width = 720;
391         dev->height = 480;
392         dev->norm = V4L2_STD_PAL_M;
393
394         /* Configure tuner */
395         tm6000_config_tuner (dev);
396
397         /* Set video standard */
398         v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
399
400         /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
401         f.tuner = 0;
402         f.type = V4L2_TUNER_ANALOG_TV;
403         f.frequency = 3092;     /* 193.25 MHz */
404         dev->freq = f.frequency;
405         v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
406
407         if (dev->caps.has_tda9874)
408                 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
409                         "tvaudio", "tvaudio", I2C_ADDR_TDA9874, NULL);
410
411         if(dev->caps.has_dvb) {
412                 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
413                 if(!dev->dvb) {
414                         rc = -ENOMEM;
415                         goto err2;
416                 }
417 #ifdef CONFIG_VIDEO_TM6000_DVB
418                 rc = tm6000_dvb_register(dev);
419                 if(rc < 0) {
420                         kfree(dev->dvb);
421                         dev->dvb = NULL;
422                         goto err2;
423                 }
424 #endif
425         }
426         return 0;
427
428 err2:
429         v4l2_device_unregister(&dev->v4l2_dev);
430
431 err:
432         mutex_unlock(&dev->lock);
433         return rc;
434 }
435
436 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
437 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
438
439 static void get_max_endpoint (  struct usb_device *usbdev,
440                                 char *msgtype,
441                                 struct usb_host_endpoint *curr_e,
442                                 unsigned int *maxsize,
443                                 struct usb_host_endpoint **ep  )
444 {
445         u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
446         unsigned int size = tmp & 0x7ff;
447
448         if (usbdev->speed == USB_SPEED_HIGH)
449                 size = size * hb_mult (tmp);
450
451         if (size>*maxsize) {
452                 *ep = curr_e;
453                 *maxsize = size;
454                 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
455                                         msgtype, curr_e->desc.bEndpointAddress,
456                                         size);
457         }
458 }
459
460 /*
461  * tm6000_usb_probe()
462  * checks for supported devices
463  */
464 static int tm6000_usb_probe(struct usb_interface *interface,
465                             const struct usb_device_id *id)
466 {
467         struct usb_device *usbdev;
468         struct tm6000_core *dev = NULL;
469         int i,rc=0;
470         int nr=0;
471         char *speed;
472
473
474         usbdev=usb_get_dev(interface_to_usbdev(interface));
475
476         /* Selects the proper interface */
477         rc=usb_set_interface(usbdev,0,1);
478         if (rc<0)
479                 goto err;
480
481         /* Check to see next free device and mark as used */
482         nr=find_first_zero_bit(&tm6000_devused,TM6000_MAXBOARDS);
483         if (nr >= TM6000_MAXBOARDS) {
484                 printk ("tm6000: Supports only %i tm60xx boards.\n",TM6000_MAXBOARDS);
485                 usb_put_dev(usbdev);
486                 return -ENOMEM;
487         }
488
489         /* Create and initialize dev struct */
490         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
491         if (dev == NULL) {
492                 printk ("tm6000" ": out of memory!\n");
493                 usb_put_dev(usbdev);
494                 return -ENOMEM;
495         }
496         spin_lock_init(&dev->slock);
497
498         /* Increment usage count */
499         tm6000_devused|=1<<nr;
500         snprintf(dev->name, 29, "tm6000 #%d", nr);
501
502         dev->model=id->driver_info;
503         if ((card[nr]>=0) && (card[nr]<ARRAY_SIZE(tm6000_boards))) {
504                 dev->model=card[nr];
505         }
506
507         INIT_LIST_HEAD(&dev->tm6000_corelist);
508         dev->udev= usbdev;
509         dev->devno=nr;
510
511         switch (usbdev->speed) {
512         case USB_SPEED_LOW:
513                 speed = "1.5";
514                 break;
515         case USB_SPEED_UNKNOWN:
516         case USB_SPEED_FULL:
517                 speed = "12";
518                 break;
519         case USB_SPEED_HIGH:
520                 speed = "480";
521                 break;
522         default:
523                 speed = "unknown";
524         }
525
526
527
528         /* Get endpoints */
529         for (i = 0; i < interface->num_altsetting; i++) {
530                 int ep;
531
532                 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
533                         struct usb_host_endpoint        *e;
534                         int dir_out;
535
536                         e = &interface->altsetting[i].endpoint[ep];
537
538                         dir_out = ((e->desc.bEndpointAddress &
539                                         USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
540
541                         printk("tm6000: alt %d, interface %i, class %i\n",
542                                i,
543                                interface->altsetting[i].desc.bInterfaceNumber,
544                                interface->altsetting[i].desc.bInterfaceClass);
545
546                         switch (e->desc.bmAttributes) {
547                         case USB_ENDPOINT_XFER_BULK:
548                                 if (!dir_out) {
549                                         get_max_endpoint (usbdev, "Bulk IN", e,
550                                                         &dev->max_bulk_in,
551                                                         &dev->bulk_in);
552                                 } else {
553                                         get_max_endpoint (usbdev, "Bulk OUT", e,
554                                                         &dev->max_bulk_out,
555                                                         &dev->bulk_out);
556                                 }
557                                 break;
558                         case USB_ENDPOINT_XFER_ISOC:
559                                 if (!dir_out) {
560                                         get_max_endpoint (usbdev, "ISOC IN", e,
561                                                         &dev->max_isoc_in,
562                                                         &dev->isoc_in);
563                                 } else {
564                                         get_max_endpoint (usbdev, "ISOC OUT", e,
565                                                         &dev->max_isoc_out,
566                                                         &dev->isoc_out);
567                                 }
568                                 break;
569                         }
570                 }
571         }
572
573
574         printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
575                 speed,
576                 le16_to_cpu(dev->udev->descriptor.idVendor),
577                 le16_to_cpu(dev->udev->descriptor.idProduct),
578                 interface->altsetting->desc.bInterfaceNumber);
579
580 /* check if the the device has the iso in endpoint at the correct place */
581         if (!dev->isoc_in) {
582                 printk("tm6000: probing error: no IN ISOC endpoint!\n");
583                 rc= -ENODEV;
584
585                 goto err;
586         }
587
588         /* save our data pointer in this interface device */
589         usb_set_intfdata(interface, dev);
590
591         printk("tm6000: Found %s\n", tm6000_boards[dev->model].name);
592
593         rc=tm6000_init_dev(dev);
594
595         if (rc<0)
596                 goto err;
597
598         return 0;
599
600 err:
601         printk("tm6000: Error %d while registering\n", rc);
602
603         tm6000_devused&=~(1<<nr);
604         usb_put_dev(usbdev);
605
606         kfree(dev);
607         return rc;
608 }
609
610 /*
611  * tm6000_usb_disconnect()
612  * called when the device gets diconencted
613  * video device will be unregistered on v4l2_close in case it is still open
614  */
615 static void tm6000_usb_disconnect(struct usb_interface *interface)
616 {
617         struct tm6000_core *dev = usb_get_intfdata(interface);
618         usb_set_intfdata(interface, NULL);
619
620         if (!dev)
621                 return;
622
623         printk("tm6000: disconnecting %s\n", dev->name);
624
625         mutex_lock(&dev->lock);
626
627 #ifdef CONFIG_VIDEO_TM6000_DVB
628         if(dev->dvb) {
629                 tm6000_dvb_unregister(dev);
630                 kfree(dev->dvb);
631         }
632 #endif
633
634         tm6000_v4l2_unregister(dev);
635
636         tm6000_i2c_unregister(dev);
637
638         v4l2_device_unregister(&dev->v4l2_dev);
639
640 //      wake_up_interruptible_all(&dev->open);
641
642         dev->state |= DEV_DISCONNECTED;
643
644         usb_put_dev(dev->udev);
645
646         mutex_unlock(&dev->lock);
647         kfree(dev);
648 }
649
650 static struct usb_driver tm6000_usb_driver = {
651                 .name = "tm6000",
652                 .probe = tm6000_usb_probe,
653                 .disconnect = tm6000_usb_disconnect,
654                 .id_table = tm6000_id_table,
655 };
656
657 static int __init tm6000_module_init(void)
658 {
659         int result;
660
661         printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
662                (TM6000_VERSION  >> 16) & 0xff,
663                (TM6000_VERSION  >> 8) & 0xff, TM6000_VERSION  & 0xff);
664
665         /* register this driver with the USB subsystem */
666         result = usb_register(&tm6000_usb_driver);
667         if (result)
668                 printk("tm6000"
669                            " usb_register failed. Error number %d.\n", result);
670
671         return result;
672 }
673
674 static void __exit tm6000_module_exit(void)
675 {
676         /* deregister at USB subsystem */
677         usb_deregister(&tm6000_usb_driver);
678 }
679
680 module_init(tm6000_module_init);
681 module_exit(tm6000_module_exit);
682
683 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000 USB2 adapter");
684 MODULE_AUTHOR("Mauro Carvalho Chehab");
685 MODULE_LICENSE("GPL");