2 tm6000-cards.c - driver for TM5600/TM6000/TM6010 USB video capture devices
4 Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
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
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.
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.
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>
33 #include "tm6000-regs.h"
34 #include "tuner-xc2028.h"
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 #define TM6010_BOARD_TWINHAN_TU501 13
52 #define TM6000_MAXBOARDS 16
53 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
55 module_param_array(card, int, NULL, 0444);
57 static unsigned long tm6000_devused;
63 struct tm6000_capabilities caps;
65 enum tm6000_devtype type; /* variant of the chipset */
66 int tuner_type; /* type of the tuner */
67 int tuner_addr; /* tuner address */
68 int demod_addr; /* demodulator address */
70 struct tm6000_gpio gpio;
73 struct tm6000_board tm6000_boards[] = {
74 [TM6000_BOARD_UNKNOWN] = {
75 .name = "Unknown tm6000 video grabber",
80 .tuner_reset = TM6000_GPIO_1,
83 [TM5600_BOARD_GENERIC] = {
84 .name = "Generic tm5600 board",
86 .tuner_type = TUNER_XC2028,
87 .tuner_addr = 0xc2 >> 1,
92 .tuner_reset = TM6000_GPIO_1,
95 [TM6000_BOARD_GENERIC] = {
96 .name = "Generic tm6000 board",
97 .tuner_type = TUNER_XC2028,
98 .tuner_addr = 0xc2 >> 1,
104 .tuner_reset = TM6000_GPIO_1,
107 [TM6010_BOARD_GENERIC] = {
108 .name = "Generic tm6010 board",
110 .tuner_type = TUNER_XC2028,
111 .tuner_addr = 0xc2 >> 1,
112 .demod_addr = 0x1e >> 1,
121 .tuner_reset = TM6010_GPIO_2,
122 .tuner_on = TM6010_GPIO_3,
123 .demod_reset = TM6010_GPIO_1,
124 .demod_on = TM6010_GPIO_4,
125 .power_led = TM6010_GPIO_7,
126 .dvb_led = TM6010_GPIO_5,
130 [TM5600_BOARD_10MOONS_UT821] = {
131 .name = "10Moons UT 821",
132 .tuner_type = TUNER_XC2028,
134 .tuner_addr = 0xc2 >> 1,
140 .tuner_reset = TM6000_GPIO_1,
143 [TM5600_BOARD_10MOONS_UT330] = {
144 .name = "10Moons UT 330",
145 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
146 .tuner_addr = 0xc8 >> 1,
154 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
155 .name = "ADSTECH Dual TV USB",
156 .tuner_type = TUNER_XC2028,
157 .tuner_addr = 0xc8 >> 1,
166 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
167 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
168 .tuner_type = TUNER_XC2028, /* has a XC3028 */
169 .tuner_addr = 0xc2 >> 1,
170 .demod_addr = 0x1e >> 1,
179 .tuner_reset = TM6000_GPIO_4,
182 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
183 .name = "ADSTECH Mini Dual TV USB",
184 .tuner_type = TUNER_XC2028, /* has a XC3028 */
185 .tuner_addr = 0xc8 >> 1,
186 .demod_addr = 0x1e >> 1,
194 .tuner_reset = TM6000_GPIO_4,
197 [TM6010_BOARD_HAUPPAUGE_900H] = {
198 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
199 .tuner_type = TUNER_XC2028, /* has a XC3028 */
200 .tuner_addr = 0xc2 >> 1,
201 .demod_addr = 0x1e >> 1,
211 .tuner_reset = TM6010_GPIO_2,
212 .tuner_on = TM6010_GPIO_3,
213 .demod_reset = TM6010_GPIO_1,
214 .demod_on = TM6010_GPIO_4,
215 .power_led = TM6010_GPIO_7,
216 .dvb_led = TM6010_GPIO_5,
220 [TM6010_BOARD_BEHOLD_WANDER] = {
221 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
222 .tuner_type = TUNER_XC5000,
223 .tuner_addr = 0xc2 >> 1,
224 .demod_addr = 0x1e >> 1,
234 .tuner_reset = TM6010_GPIO_0,
235 .demod_reset = TM6010_GPIO_1,
236 .power_led = TM6010_GPIO_6,
239 [TM6010_BOARD_BEHOLD_VOYAGER] = {
240 .name = "Beholder Voyager TV/FM USB2.0",
241 .tuner_type = TUNER_XC5000,
242 .tuner_addr = 0xc2 >> 1,
252 .tuner_reset = TM6010_GPIO_0,
253 .power_led = TM6010_GPIO_6,
256 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
257 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
258 .tuner_type = TUNER_XC2028, /* has a XC3028 */
259 .tuner_addr = 0xc2 >> 1,
260 .demod_addr = 0x1e >> 1,
270 .tuner_reset = TM6010_GPIO_2,
271 .tuner_on = TM6010_GPIO_3,
272 .demod_reset = TM6010_GPIO_1,
273 .demod_on = TM6010_GPIO_4,
274 .power_led = TM6010_GPIO_7,
275 .dvb_led = TM6010_GPIO_5,
279 [TM6010_BOARD_TWINHAN_TU501] = {
280 .name = "Twinhan TU501(704D1)",
281 .tuner_type = TUNER_XC2028, /* has a XC3028 */
282 .tuner_addr = 0xc2 >> 1,
283 .demod_addr = 0x1e >> 1,
293 .tuner_reset = TM6010_GPIO_2,
294 .tuner_on = TM6010_GPIO_3,
295 .demod_reset = TM6010_GPIO_1,
296 .demod_on = TM6010_GPIO_4,
297 .power_led = TM6010_GPIO_7,
298 .dvb_led = TM6010_GPIO_5,
304 /* table of devices that work with this driver */
305 struct usb_device_id tm6000_id_table[] = {
306 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
307 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
308 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
309 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
310 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
311 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
312 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
313 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
314 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
315 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
316 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
317 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
318 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
319 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
320 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
321 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
322 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
326 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
327 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
330 struct tm6000_core *dev = ptr;
332 if (dev->tuner_type != TUNER_XC5000)
336 case XC5000_TUNER_RESET:
337 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
338 dev->gpio.tuner_reset, 0x01);
340 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
341 dev->gpio.tuner_reset, 0x00);
343 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
344 dev->gpio.tuner_reset, 0x01);
351 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
353 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
356 struct tm6000_core *dev = ptr;
358 if (dev->tuner_type != TUNER_XC2028)
362 case XC2028_RESET_CLK:
363 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
366 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
371 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
374 case XC2028_TUNER_RESET:
375 /* Reset codes during load firmware */
378 /* newer tuner can faster reset */
379 switch (dev->model) {
380 case TM5600_BOARD_10MOONS_UT821:
381 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
382 dev->gpio.tuner_reset, 0x01);
383 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
386 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
387 dev->gpio.tuner_reset, 0x00);
388 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
391 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
392 dev->gpio.tuner_reset, 0x01);
393 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
396 case TM6010_BOARD_HAUPPAUGE_900H:
397 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
398 case TM6010_BOARD_TWINHAN_TU501:
399 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
400 dev->gpio.tuner_reset, 0x01);
402 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
403 dev->gpio.tuner_reset, 0x00);
405 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
406 dev->gpio.tuner_reset, 0x01);
410 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
411 dev->gpio.tuner_reset, 0x00);
413 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
414 dev->gpio.tuner_reset, 0x01);
420 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
426 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
431 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
440 int tm6000_cards_setup(struct tm6000_core *dev)
445 * Board-specific initialization sequence. Handles all GPIO
446 * initialization sequences that are board-specific.
447 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
448 * Probably, they're all based on some reference device. Due to that,
449 * there's a common routine at the end to handle those GPIO's. Devices
450 * that use different pinups or init sequences can just return at
451 * the board-specific session.
453 switch (dev->model) {
454 case TM6010_BOARD_HAUPPAUGE_900H:
455 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
456 case TM6010_BOARD_TWINHAN_TU501:
457 case TM6010_BOARD_GENERIC:
458 /* Turn xceive 3028 on */
459 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
461 /* Turn zarlink zl10353 on */
462 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
464 /* Reset zarlink zl10353 */
465 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
467 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
469 /* Turn zarlink zl10353 off */
470 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
473 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
475 /* Power led on (blue) */
476 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
478 /* DVB led off (orange) */
479 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
481 /* Turn zarlink zl10353 on */
482 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
485 case TM6010_BOARD_BEHOLD_WANDER:
486 /* Power led on (blue) */
487 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
489 /* Reset zarlink zl10353 */
490 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
492 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
495 case TM6010_BOARD_BEHOLD_VOYAGER:
496 /* Power led on (blue) */
497 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
505 * Default initialization. Most of the devices seem to use GPIO1
506 * and GPIO4.on the same way, so, this handles the common sequence
507 * used by most devices.
508 * If a device uses a different sequence or different GPIO pins for
509 * reset, just add the code at the board-specific part
512 if (dev->gpio.tuner_reset) {
513 for (i = 0; i < 2; i++) {
514 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
515 dev->gpio.tuner_reset, 0x00);
517 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
521 msleep(10); /* Just to be conservative */
522 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
523 dev->gpio.tuner_reset, 0x01);
525 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
531 rc = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
533 printk(KERN_DEBUG "board=0x%08x\n", rc);
537 printk(KERN_ERR "Tuner reset is not configured\n");
546 static void tm6000_config_tuner(struct tm6000_core *dev)
548 struct tuner_setup tun_setup;
550 /* Load tuner module */
551 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
552 "tuner", "tuner", dev->tuner_addr, NULL);
554 memset(&tun_setup, 0, sizeof(tun_setup));
555 tun_setup.type = dev->tuner_type;
556 tun_setup.addr = dev->tuner_addr;
558 tun_setup.mode_mask = 0;
559 if (dev->caps.has_tuner)
560 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
561 if (dev->caps.has_dvb)
562 tun_setup.mode_mask |= T_DIGITAL_TV;
564 switch (dev->tuner_type) {
566 tun_setup.tuner_callback = tm6000_tuner_callback;;
569 tun_setup.tuner_callback = tm6000_xc5000_callback;
573 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
575 switch (dev->tuner_type) {
577 struct v4l2_priv_tun_config xc2028_cfg;
578 struct xc2028_ctrl ctl;
580 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
581 memset(&ctl, 0, sizeof(ctl));
584 ctl.read_not_reliable = 0;
586 ctl.demod = XC3028_FE_ZARLINK456;
589 xc2028_cfg.tuner = TUNER_XC2028;
590 xc2028_cfg.priv = &ctl;
592 switch (dev->model) {
593 case TM6010_BOARD_HAUPPAUGE_900H:
594 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
595 case TM6010_BOARD_TWINHAN_TU501:
596 ctl.fname = "xc3028L-v36.fw";
599 if (dev->dev_type == TM6010)
600 ctl.fname = "xc3028-v27.fw";
602 ctl.fname = "xc3028-v24.fw";
605 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
606 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
613 struct v4l2_priv_tun_config xc5000_cfg;
614 struct xc5000_config ctl = {
615 .i2c_address = dev->tuner_addr,
617 .radio_input = XC5000_RADIO_FM1,
620 xc5000_cfg.tuner = TUNER_XC5000;
621 xc5000_cfg.priv = &ctl;
624 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
629 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
634 static int tm6000_init_dev(struct tm6000_core *dev)
636 struct v4l2_frequency f;
639 mutex_init(&dev->lock);
641 mutex_lock(&dev->lock);
643 /* Initializa board-specific data */
644 dev->dev_type = tm6000_boards[dev->model].type;
645 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
646 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
648 dev->gpio = tm6000_boards[dev->model].gpio;
650 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
652 dev->caps = tm6000_boards[dev->model].caps;
654 /* initialize hardware */
655 rc = tm6000_init(dev);
659 rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
663 /* register i2c bus */
664 rc = tm6000_i2c_register(dev);
668 /* Default values for STD and resolutions */
671 dev->norm = V4L2_STD_PAL_M;
673 /* Configure tuner */
674 tm6000_config_tuner(dev);
676 /* Set video standard */
677 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
679 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
681 f.type = V4L2_TUNER_ANALOG_TV;
682 f.frequency = 3092; /* 193.25 MHz */
683 dev->freq = f.frequency;
684 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
686 if (dev->caps.has_tda9874)
687 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
688 "tvaudio", "tvaudio", I2C_ADDR_TDA9874, NULL);
690 /* register and initialize V4L2 */
691 rc = tm6000_v4l2_register(dev);
695 if (dev->caps.has_dvb) {
696 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
702 #ifdef CONFIG_VIDEO_TM6000_DVB
703 rc = tm6000_dvb_register(dev);
711 mutex_unlock(&dev->lock);
715 v4l2_device_unregister(&dev->v4l2_dev);
718 mutex_unlock(&dev->lock);
722 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
723 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
725 static void get_max_endpoint(struct usb_device *udev,
726 struct usb_host_interface *alt,
728 struct usb_host_endpoint *curr_e,
729 struct tm6000_endpoint *tm_ep)
731 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
732 unsigned int size = tmp & 0x7ff;
734 if (udev->speed == USB_SPEED_HIGH)
735 size = size * hb_mult (tmp);
737 if (size > tm_ep->maxsize) {
738 tm_ep->endp = curr_e;
739 tm_ep->maxsize = size;
740 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
741 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
743 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
744 msgtype, curr_e->desc.bEndpointAddress,
751 * checks for supported devices
753 static int tm6000_usb_probe(struct usb_interface *interface,
754 const struct usb_device_id *id)
756 struct usb_device *usbdev;
757 struct tm6000_core *dev = NULL;
762 usbdev = usb_get_dev(interface_to_usbdev(interface));
764 /* Selects the proper interface */
765 rc = usb_set_interface(usbdev, 0, 1);
769 /* Check to see next free device and mark as used */
770 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
771 if (nr >= TM6000_MAXBOARDS) {
772 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
777 /* Create and initialize dev struct */
778 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
780 printk(KERN_ERR "tm6000" ": out of memory!\n");
784 spin_lock_init(&dev->slock);
786 /* Increment usage count */
787 tm6000_devused |= 1<<nr;
788 snprintf(dev->name, 29, "tm6000 #%d", nr);
790 dev->model = id->driver_info;
791 if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
792 dev->model = card[nr];
797 switch (usbdev->speed) {
801 case USB_SPEED_UNKNOWN:
815 for (i = 0; i < interface->num_altsetting; i++) {
818 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
819 struct usb_host_endpoint *e;
822 e = &interface->altsetting[i].endpoint[ep];
824 dir_out = ((e->desc.bEndpointAddress &
825 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
827 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
829 interface->altsetting[i].desc.bInterfaceNumber,
830 interface->altsetting[i].desc.bInterfaceClass);
832 switch (e->desc.bmAttributes) {
833 case USB_ENDPOINT_XFER_BULK:
835 get_max_endpoint(usbdev,
836 &interface->altsetting[i],
840 get_max_endpoint(usbdev,
841 &interface->altsetting[i],
846 case USB_ENDPOINT_XFER_ISOC:
848 get_max_endpoint(usbdev,
849 &interface->altsetting[i],
853 get_max_endpoint(usbdev,
854 &interface->altsetting[i],
864 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
866 le16_to_cpu(dev->udev->descriptor.idVendor),
867 le16_to_cpu(dev->udev->descriptor.idProduct),
868 interface->altsetting->desc.bInterfaceNumber);
870 /* check if the the device has the iso in endpoint at the correct place */
871 if (!dev->isoc_in.endp) {
872 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
878 /* save our data pointer in this interface device */
879 usb_set_intfdata(interface, dev);
881 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
883 rc = tm6000_init_dev(dev);
891 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
893 tm6000_devused &= ~(1<<nr);
901 * tm6000_usb_disconnect()
902 * called when the device gets diconencted
903 * video device will be unregistered on v4l2_close in case it is still open
905 static void tm6000_usb_disconnect(struct usb_interface *interface)
907 struct tm6000_core *dev = usb_get_intfdata(interface);
908 usb_set_intfdata(interface, NULL);
913 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
915 mutex_lock(&dev->lock);
917 #ifdef CONFIG_VIDEO_TM6000_DVB
919 tm6000_dvb_unregister(dev);
924 tm6000_v4l2_unregister(dev);
926 tm6000_i2c_unregister(dev);
928 v4l2_device_unregister(&dev->v4l2_dev);
930 dev->state |= DEV_DISCONNECTED;
932 usb_put_dev(dev->udev);
934 mutex_unlock(&dev->lock);
938 static struct usb_driver tm6000_usb_driver = {
940 .probe = tm6000_usb_probe,
941 .disconnect = tm6000_usb_disconnect,
942 .id_table = tm6000_id_table,
945 static int __init tm6000_module_init(void)
949 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
950 (TM6000_VERSION >> 16) & 0xff,
951 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
953 /* register this driver with the USB subsystem */
954 result = usb_register(&tm6000_usb_driver);
956 printk(KERN_ERR "tm6000"
957 " usb_register failed. Error number %d.\n", result);
962 static void __exit tm6000_module_exit(void)
964 /* deregister at USB subsystem */
965 usb_deregister(&tm6000_usb_driver);
968 module_init(tm6000_module_init);
969 module_exit(tm6000_module_exit);
971 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
972 MODULE_AUTHOR("Mauro Carvalho Chehab");
973 MODULE_LICENSE("GPL");