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 <linux/slab.h>
28 #include <media/v4l2-common.h>
29 #include <media/tuner.h>
30 #include <media/tvaudio.h>
31 #include <media/i2c-addr.h>
34 #include "tm6000-regs.h"
35 #include "tuner-xc2028.h"
38 #define TM6000_BOARD_UNKNOWN 0
39 #define TM5600_BOARD_GENERIC 1
40 #define TM6000_BOARD_GENERIC 2
41 #define TM6010_BOARD_GENERIC 3
42 #define TM5600_BOARD_10MOONS_UT821 4
43 #define TM5600_BOARD_10MOONS_UT330 5
44 #define TM6000_BOARD_ADSTECH_DUAL_TV 6
45 #define TM6000_BOARD_FREECOM_AND_SIMILAR 7
46 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
47 #define TM6010_BOARD_HAUPPAUGE_900H 9
48 #define TM6010_BOARD_BEHOLD_WANDER 10
49 #define TM6010_BOARD_BEHOLD_VOYAGER 11
50 #define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
51 #define TM6010_BOARD_TWINHAN_TU501 13
53 #define TM6000_MAXBOARDS 16
54 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
56 module_param_array(card, int, NULL, 0444);
58 static unsigned long tm6000_devused;
64 struct tm6000_capabilities caps;
66 enum tm6000_devtype type; /* variant of the chipset */
67 int tuner_type; /* type of the tuner */
68 int tuner_addr; /* tuner address */
69 int demod_addr; /* demodulator address */
71 struct tm6000_gpio gpio;
74 struct tm6000_board tm6000_boards[] = {
75 [TM6000_BOARD_UNKNOWN] = {
76 .name = "Unknown tm6000 video grabber",
81 .tuner_reset = TM6000_GPIO_1,
84 [TM5600_BOARD_GENERIC] = {
85 .name = "Generic tm5600 board",
87 .tuner_type = TUNER_XC2028,
88 .tuner_addr = 0xc2 >> 1,
93 .tuner_reset = TM6000_GPIO_1,
96 [TM6000_BOARD_GENERIC] = {
97 .name = "Generic tm6000 board",
98 .tuner_type = TUNER_XC2028,
99 .tuner_addr = 0xc2 >> 1,
105 .tuner_reset = TM6000_GPIO_1,
108 [TM6010_BOARD_GENERIC] = {
109 .name = "Generic tm6010 board",
111 .tuner_type = TUNER_XC2028,
112 .tuner_addr = 0xc2 >> 1,
113 .demod_addr = 0x1e >> 1,
122 .tuner_reset = TM6010_GPIO_2,
123 .tuner_on = TM6010_GPIO_3,
124 .demod_reset = TM6010_GPIO_1,
125 .demod_on = TM6010_GPIO_4,
126 .power_led = TM6010_GPIO_7,
127 .dvb_led = TM6010_GPIO_5,
131 [TM5600_BOARD_10MOONS_UT821] = {
132 .name = "10Moons UT 821",
133 .tuner_type = TUNER_XC2028,
135 .tuner_addr = 0xc2 >> 1,
141 .tuner_reset = TM6000_GPIO_1,
144 [TM5600_BOARD_10MOONS_UT330] = {
145 .name = "10Moons UT 330",
146 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
147 .tuner_addr = 0xc8 >> 1,
155 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
156 .name = "ADSTECH Dual TV USB",
157 .tuner_type = TUNER_XC2028,
158 .tuner_addr = 0xc8 >> 1,
167 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
168 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
169 .tuner_type = TUNER_XC2028, /* has a XC3028 */
170 .tuner_addr = 0xc2 >> 1,
171 .demod_addr = 0x1e >> 1,
180 .tuner_reset = TM6000_GPIO_4,
183 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
184 .name = "ADSTECH Mini Dual TV USB",
185 .tuner_type = TUNER_XC2028, /* has a XC3028 */
186 .tuner_addr = 0xc8 >> 1,
187 .demod_addr = 0x1e >> 1,
195 .tuner_reset = TM6000_GPIO_4,
198 [TM6010_BOARD_HAUPPAUGE_900H] = {
199 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
200 .tuner_type = TUNER_XC2028, /* has a XC3028 */
201 .tuner_addr = 0xc2 >> 1,
202 .demod_addr = 0x1e >> 1,
212 .tuner_reset = TM6010_GPIO_2,
213 .tuner_on = TM6010_GPIO_3,
214 .demod_reset = TM6010_GPIO_1,
215 .demod_on = TM6010_GPIO_4,
216 .power_led = TM6010_GPIO_7,
217 .dvb_led = TM6010_GPIO_5,
221 [TM6010_BOARD_BEHOLD_WANDER] = {
222 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
223 .tuner_type = TUNER_XC5000,
224 .tuner_addr = 0xc2 >> 1,
225 .demod_addr = 0x1e >> 1,
235 .tuner_reset = TM6010_GPIO_0,
236 .demod_reset = TM6010_GPIO_1,
237 .power_led = TM6010_GPIO_6,
240 [TM6010_BOARD_BEHOLD_VOYAGER] = {
241 .name = "Beholder Voyager TV/FM USB2.0",
242 .tuner_type = TUNER_XC5000,
243 .tuner_addr = 0xc2 >> 1,
253 .tuner_reset = TM6010_GPIO_0,
254 .power_led = TM6010_GPIO_6,
257 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
258 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
259 .tuner_type = TUNER_XC2028, /* has a XC3028 */
260 .tuner_addr = 0xc2 >> 1,
261 .demod_addr = 0x1e >> 1,
271 .tuner_reset = TM6010_GPIO_2,
272 .tuner_on = TM6010_GPIO_3,
273 .demod_reset = TM6010_GPIO_1,
274 .demod_on = TM6010_GPIO_4,
275 .power_led = TM6010_GPIO_7,
276 .dvb_led = TM6010_GPIO_5,
280 [TM6010_BOARD_TWINHAN_TU501] = {
281 .name = "Twinhan TU501(704D1)",
282 .tuner_type = TUNER_XC2028, /* has a XC3028 */
283 .tuner_addr = 0xc2 >> 1,
284 .demod_addr = 0x1e >> 1,
294 .tuner_reset = TM6010_GPIO_2,
295 .tuner_on = TM6010_GPIO_3,
296 .demod_reset = TM6010_GPIO_1,
297 .demod_on = TM6010_GPIO_4,
298 .power_led = TM6010_GPIO_7,
299 .dvb_led = TM6010_GPIO_5,
305 /* table of devices that work with this driver */
306 struct usb_device_id tm6000_id_table[] = {
307 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
308 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
309 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
310 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
311 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
312 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
313 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
314 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
315 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
316 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
317 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
318 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
319 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
320 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
321 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
322 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
323 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
327 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
328 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
331 struct tm6000_core *dev = ptr;
333 if (dev->tuner_type != TUNER_XC5000)
337 case XC5000_TUNER_RESET:
338 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
339 dev->gpio.tuner_reset, 0x01);
341 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
342 dev->gpio.tuner_reset, 0x00);
344 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
345 dev->gpio.tuner_reset, 0x01);
352 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
354 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
357 struct tm6000_core *dev = ptr;
359 if (dev->tuner_type != TUNER_XC2028)
363 case XC2028_RESET_CLK:
364 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
367 rc = tm6000_i2c_reset(dev, 10);
369 case XC2028_TUNER_RESET:
370 /* Reset codes during load firmware */
373 /* newer tuner can faster reset */
374 switch (dev->model) {
375 case TM5600_BOARD_10MOONS_UT821:
376 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
377 dev->gpio.tuner_reset, 0x01);
378 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
381 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
382 dev->gpio.tuner_reset, 0x00);
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, 0x01);
388 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
391 case TM6010_BOARD_HAUPPAUGE_900H:
392 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
393 case TM6010_BOARD_TWINHAN_TU501:
394 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
395 dev->gpio.tuner_reset, 0x01);
397 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
398 dev->gpio.tuner_reset, 0x00);
400 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
401 dev->gpio.tuner_reset, 0x01);
405 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
406 dev->gpio.tuner_reset, 0x00);
408 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
409 dev->gpio.tuner_reset, 0x01);
415 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
421 rc = tm6000_i2c_reset(dev, 100);
428 int tm6000_cards_setup(struct tm6000_core *dev)
433 * Board-specific initialization sequence. Handles all GPIO
434 * initialization sequences that are board-specific.
435 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
436 * Probably, they're all based on some reference device. Due to that,
437 * there's a common routine at the end to handle those GPIO's. Devices
438 * that use different pinups or init sequences can just return at
439 * the board-specific session.
441 switch (dev->model) {
442 case TM6010_BOARD_HAUPPAUGE_900H:
443 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
444 case TM6010_BOARD_TWINHAN_TU501:
445 case TM6010_BOARD_GENERIC:
446 /* Turn xceive 3028 on */
447 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
449 /* Turn zarlink zl10353 on */
450 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
452 /* Reset zarlink zl10353 */
453 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
455 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
457 /* Turn zarlink zl10353 off */
458 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
461 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
463 /* Power led on (blue) */
464 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
466 /* DVB led off (orange) */
467 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
469 /* Turn zarlink zl10353 on */
470 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
473 case TM6010_BOARD_BEHOLD_WANDER:
474 /* Power led on (blue) */
475 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
477 /* Reset zarlink zl10353 */
478 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
480 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
483 case TM6010_BOARD_BEHOLD_VOYAGER:
484 /* Power led on (blue) */
485 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
493 * Default initialization. Most of the devices seem to use GPIO1
494 * and GPIO4.on the same way, so, this handles the common sequence
495 * used by most devices.
496 * If a device uses a different sequence or different GPIO pins for
497 * reset, just add the code at the board-specific part
500 if (dev->gpio.tuner_reset) {
501 for (i = 0; i < 2; i++) {
502 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
503 dev->gpio.tuner_reset, 0x00);
505 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
509 msleep(10); /* Just to be conservative */
510 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
511 dev->gpio.tuner_reset, 0x01);
513 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
519 rc = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
521 printk(KERN_DEBUG "board=0x%08x\n", rc);
525 printk(KERN_ERR "Tuner reset is not configured\n");
534 static void tm6000_config_tuner(struct tm6000_core *dev)
536 struct tuner_setup tun_setup;
538 /* Load tuner module */
539 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
540 "tuner", "tuner", dev->tuner_addr, NULL);
542 memset(&tun_setup, 0, sizeof(tun_setup));
543 tun_setup.type = dev->tuner_type;
544 tun_setup.addr = dev->tuner_addr;
546 tun_setup.mode_mask = 0;
547 if (dev->caps.has_tuner)
548 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
549 if (dev->caps.has_dvb)
550 tun_setup.mode_mask |= T_DIGITAL_TV;
552 switch (dev->tuner_type) {
554 tun_setup.tuner_callback = tm6000_tuner_callback;
557 tun_setup.tuner_callback = tm6000_xc5000_callback;
561 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
563 switch (dev->tuner_type) {
565 struct v4l2_priv_tun_config xc2028_cfg;
566 struct xc2028_ctrl ctl;
568 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
569 memset(&ctl, 0, sizeof(ctl));
572 ctl.read_not_reliable = 0;
574 ctl.demod = XC3028_FE_ZARLINK456;
577 xc2028_cfg.tuner = TUNER_XC2028;
578 xc2028_cfg.priv = &ctl;
580 switch (dev->model) {
581 case TM6010_BOARD_HAUPPAUGE_900H:
582 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
583 case TM6010_BOARD_TWINHAN_TU501:
584 ctl.fname = "xc3028L-v36.fw";
587 if (dev->dev_type == TM6010)
588 ctl.fname = "xc3028-v27.fw";
590 ctl.fname = "xc3028-v24.fw";
593 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
594 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
601 struct v4l2_priv_tun_config xc5000_cfg;
602 struct xc5000_config ctl = {
603 .i2c_address = dev->tuner_addr,
605 .radio_input = XC5000_RADIO_FM1,
608 xc5000_cfg.tuner = TUNER_XC5000;
609 xc5000_cfg.priv = &ctl;
612 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
617 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
622 static int tm6000_init_dev(struct tm6000_core *dev)
624 struct v4l2_frequency f;
627 mutex_init(&dev->lock);
629 mutex_lock(&dev->lock);
631 /* Initializa board-specific data */
632 dev->dev_type = tm6000_boards[dev->model].type;
633 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
634 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
636 dev->gpio = tm6000_boards[dev->model].gpio;
638 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
640 dev->caps = tm6000_boards[dev->model].caps;
642 /* initialize hardware */
643 rc = tm6000_init(dev);
647 rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
651 /* register i2c bus */
652 rc = tm6000_i2c_register(dev);
656 /* Default values for STD and resolutions */
659 dev->norm = V4L2_STD_PAL_M;
661 /* Configure tuner */
662 tm6000_config_tuner(dev);
664 /* Set video standard */
665 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
667 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
669 f.type = V4L2_TUNER_ANALOG_TV;
670 f.frequency = 3092; /* 193.25 MHz */
671 dev->freq = f.frequency;
672 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
674 if (dev->caps.has_tda9874)
675 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
676 "tvaudio", "tvaudio", I2C_ADDR_TDA9874, NULL);
678 /* register and initialize V4L2 */
679 rc = tm6000_v4l2_register(dev);
683 tm6000_add_into_devlist(dev);
685 tm6000_init_extension(dev);
687 if (dev->caps.has_dvb) {
688 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
694 #ifdef CONFIG_VIDEO_TM6000_DVB
695 rc = tm6000_dvb_register(dev);
703 mutex_unlock(&dev->lock);
707 v4l2_device_unregister(&dev->v4l2_dev);
710 mutex_unlock(&dev->lock);
714 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
715 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
717 static void get_max_endpoint(struct usb_device *udev,
718 struct usb_host_interface *alt,
720 struct usb_host_endpoint *curr_e,
721 struct tm6000_endpoint *tm_ep)
723 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
724 unsigned int size = tmp & 0x7ff;
726 if (udev->speed == USB_SPEED_HIGH)
727 size = size * hb_mult (tmp);
729 if (size > tm_ep->maxsize) {
730 tm_ep->endp = curr_e;
731 tm_ep->maxsize = size;
732 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
733 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
735 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
736 msgtype, curr_e->desc.bEndpointAddress,
743 * checks for supported devices
745 static int tm6000_usb_probe(struct usb_interface *interface,
746 const struct usb_device_id *id)
748 struct usb_device *usbdev;
749 struct tm6000_core *dev = NULL;
754 usbdev = usb_get_dev(interface_to_usbdev(interface));
756 /* Selects the proper interface */
757 rc = usb_set_interface(usbdev, 0, 1);
761 /* Check to see next free device and mark as used */
762 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
763 if (nr >= TM6000_MAXBOARDS) {
764 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
769 /* Create and initialize dev struct */
770 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
772 printk(KERN_ERR "tm6000" ": out of memory!\n");
776 spin_lock_init(&dev->slock);
778 /* Increment usage count */
779 tm6000_devused |= 1<<nr;
780 snprintf(dev->name, 29, "tm6000 #%d", nr);
782 dev->model = id->driver_info;
783 if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
784 dev->model = card[nr];
789 switch (usbdev->speed) {
793 case USB_SPEED_UNKNOWN:
807 for (i = 0; i < interface->num_altsetting; i++) {
810 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
811 struct usb_host_endpoint *e;
814 e = &interface->altsetting[i].endpoint[ep];
816 dir_out = ((e->desc.bEndpointAddress &
817 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
819 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
821 interface->altsetting[i].desc.bInterfaceNumber,
822 interface->altsetting[i].desc.bInterfaceClass);
824 switch (e->desc.bmAttributes) {
825 case USB_ENDPOINT_XFER_BULK:
827 get_max_endpoint(usbdev,
828 &interface->altsetting[i],
832 get_max_endpoint(usbdev,
833 &interface->altsetting[i],
838 case USB_ENDPOINT_XFER_ISOC:
840 get_max_endpoint(usbdev,
841 &interface->altsetting[i],
845 get_max_endpoint(usbdev,
846 &interface->altsetting[i],
856 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
858 le16_to_cpu(dev->udev->descriptor.idVendor),
859 le16_to_cpu(dev->udev->descriptor.idProduct),
860 interface->altsetting->desc.bInterfaceNumber);
862 /* check if the the device has the iso in endpoint at the correct place */
863 if (!dev->isoc_in.endp) {
864 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
870 /* save our data pointer in this interface device */
871 usb_set_intfdata(interface, dev);
873 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
875 rc = tm6000_init_dev(dev);
883 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
885 tm6000_devused &= ~(1<<nr);
893 * tm6000_usb_disconnect()
894 * called when the device gets diconencted
895 * video device will be unregistered on v4l2_close in case it is still open
897 static void tm6000_usb_disconnect(struct usb_interface *interface)
899 struct tm6000_core *dev = usb_get_intfdata(interface);
900 usb_set_intfdata(interface, NULL);
905 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
907 mutex_lock(&dev->lock);
909 #ifdef CONFIG_VIDEO_TM6000_DVB
911 tm6000_dvb_unregister(dev);
916 if (dev->gpio.power_led) {
917 switch (dev->model) {
918 case TM6010_BOARD_HAUPPAUGE_900H:
919 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
920 case TM6010_BOARD_TWINHAN_TU501:
922 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
923 dev->gpio.power_led, 0x01);
926 case TM6010_BOARD_BEHOLD_WANDER:
927 case TM6010_BOARD_BEHOLD_VOYAGER:
929 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
930 dev->gpio.power_led, 0x00);
935 tm6000_v4l2_unregister(dev);
937 tm6000_i2c_unregister(dev);
939 v4l2_device_unregister(&dev->v4l2_dev);
941 dev->state |= DEV_DISCONNECTED;
943 usb_put_dev(dev->udev);
945 tm6000_remove_from_devlist(dev);
946 tm6000_close_extension(dev);
948 mutex_unlock(&dev->lock);
952 static struct usb_driver tm6000_usb_driver = {
954 .probe = tm6000_usb_probe,
955 .disconnect = tm6000_usb_disconnect,
956 .id_table = tm6000_id_table,
959 static int __init tm6000_module_init(void)
963 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
964 (TM6000_VERSION >> 16) & 0xff,
965 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
967 /* register this driver with the USB subsystem */
968 result = usb_register(&tm6000_usb_driver);
970 printk(KERN_ERR "tm6000"
971 " usb_register failed. Error number %d.\n", result);
976 static void __exit tm6000_module_exit(void)
978 /* deregister at USB subsystem */
979 usb_deregister(&tm6000_usb_driver);
982 module_init(tm6000_module_init);
983 module_exit(tm6000_module_exit);
985 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
986 MODULE_AUTHOR("Mauro Carvalho Chehab");
987 MODULE_LICENSE("GPL");