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>
32 #include <media/rc-map.h>
35 #include "tm6000-regs.h"
36 #include "tuner-xc2028.h"
39 #define TM6000_BOARD_UNKNOWN 0
40 #define TM5600_BOARD_GENERIC 1
41 #define TM6000_BOARD_GENERIC 2
42 #define TM6010_BOARD_GENERIC 3
43 #define TM5600_BOARD_10MOONS_UT821 4
44 #define TM5600_BOARD_10MOONS_UT330 5
45 #define TM6000_BOARD_ADSTECH_DUAL_TV 6
46 #define TM6000_BOARD_FREECOM_AND_SIMILAR 7
47 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
48 #define TM6010_BOARD_HAUPPAUGE_900H 9
49 #define TM6010_BOARD_BEHOLD_WANDER 10
50 #define TM6010_BOARD_BEHOLD_VOYAGER 11
51 #define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
52 #define TM6010_BOARD_TWINHAN_TU501 13
54 #define TM6000_MAXBOARDS 16
55 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
57 module_param_array(card, int, NULL, 0444);
59 static unsigned long tm6000_devused;
65 struct tm6000_capabilities caps;
67 enum tm6000_devtype type; /* variant of the chipset */
68 int tuner_type; /* type of the tuner */
69 int tuner_addr; /* tuner address */
70 int demod_addr; /* demodulator address */
72 struct tm6000_gpio gpio;
77 struct tm6000_board tm6000_boards[] = {
78 [TM6000_BOARD_UNKNOWN] = {
79 .name = "Unknown tm6000 video grabber",
84 .tuner_reset = TM6000_GPIO_1,
87 [TM5600_BOARD_GENERIC] = {
88 .name = "Generic tm5600 board",
90 .tuner_type = TUNER_XC2028,
91 .tuner_addr = 0xc2 >> 1,
96 .tuner_reset = TM6000_GPIO_1,
99 [TM6000_BOARD_GENERIC] = {
100 .name = "Generic tm6000 board",
101 .tuner_type = TUNER_XC2028,
102 .tuner_addr = 0xc2 >> 1,
108 .tuner_reset = TM6000_GPIO_1,
111 [TM6010_BOARD_GENERIC] = {
112 .name = "Generic tm6010 board",
114 .tuner_type = TUNER_XC2028,
115 .tuner_addr = 0xc2 >> 1,
116 .demod_addr = 0x1e >> 1,
125 .tuner_reset = TM6010_GPIO_2,
126 .tuner_on = TM6010_GPIO_3,
127 .demod_reset = TM6010_GPIO_1,
128 .demod_on = TM6010_GPIO_4,
129 .power_led = TM6010_GPIO_7,
130 .dvb_led = TM6010_GPIO_5,
134 [TM5600_BOARD_10MOONS_UT821] = {
135 .name = "10Moons UT 821",
136 .tuner_type = TUNER_XC2028,
138 .tuner_addr = 0xc2 >> 1,
144 .tuner_reset = TM6000_GPIO_1,
147 [TM5600_BOARD_10MOONS_UT330] = {
148 .name = "10Moons UT 330",
149 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
150 .tuner_addr = 0xc8 >> 1,
158 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
159 .name = "ADSTECH Dual TV USB",
160 .tuner_type = TUNER_XC2028,
161 .tuner_addr = 0xc8 >> 1,
170 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
171 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
172 .tuner_type = TUNER_XC2028, /* has a XC3028 */
173 .tuner_addr = 0xc2 >> 1,
174 .demod_addr = 0x1e >> 1,
183 .tuner_reset = TM6000_GPIO_4,
186 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
187 .name = "ADSTECH Mini Dual TV USB",
188 .tuner_type = TUNER_XC2028, /* has a XC3028 */
189 .tuner_addr = 0xc8 >> 1,
190 .demod_addr = 0x1e >> 1,
198 .tuner_reset = TM6000_GPIO_4,
201 [TM6010_BOARD_HAUPPAUGE_900H] = {
202 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
203 .tuner_type = TUNER_XC2028, /* has a XC3028 */
204 .tuner_addr = 0xc2 >> 1,
205 .demod_addr = 0x1e >> 1,
215 .tuner_reset = TM6010_GPIO_2,
216 .tuner_on = TM6010_GPIO_3,
217 .demod_reset = TM6010_GPIO_1,
218 .demod_on = TM6010_GPIO_4,
219 .power_led = TM6010_GPIO_7,
220 .dvb_led = TM6010_GPIO_5,
224 [TM6010_BOARD_BEHOLD_WANDER] = {
225 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
226 .tuner_type = TUNER_XC5000,
227 .tuner_addr = 0xc2 >> 1,
228 .demod_addr = 0x1e >> 1,
238 .tuner_reset = TM6010_GPIO_0,
239 .demod_reset = TM6010_GPIO_1,
240 .power_led = TM6010_GPIO_6,
243 [TM6010_BOARD_BEHOLD_VOYAGER] = {
244 .name = "Beholder Voyager TV/FM USB2.0",
245 .tuner_type = TUNER_XC5000,
246 .tuner_addr = 0xc2 >> 1,
256 .tuner_reset = TM6010_GPIO_0,
257 .power_led = TM6010_GPIO_6,
260 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
261 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
262 .tuner_type = TUNER_XC2028, /* has a XC3028 */
263 .tuner_addr = 0xc2 >> 1,
264 .demod_addr = 0x1e >> 1,
274 .tuner_reset = TM6010_GPIO_2,
275 .tuner_on = TM6010_GPIO_3,
276 .demod_reset = TM6010_GPIO_1,
277 .demod_on = TM6010_GPIO_4,
278 .power_led = TM6010_GPIO_7,
279 .dvb_led = TM6010_GPIO_5,
282 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
284 [TM6010_BOARD_TWINHAN_TU501] = {
285 .name = "Twinhan TU501(704D1)",
286 .tuner_type = TUNER_XC2028, /* has a XC3028 */
287 .tuner_addr = 0xc2 >> 1,
288 .demod_addr = 0x1e >> 1,
298 .tuner_reset = TM6010_GPIO_2,
299 .tuner_on = TM6010_GPIO_3,
300 .demod_reset = TM6010_GPIO_1,
301 .demod_on = TM6010_GPIO_4,
302 .power_led = TM6010_GPIO_7,
303 .dvb_led = TM6010_GPIO_5,
309 /* table of devices that work with this driver */
310 struct usb_device_id tm6000_id_table[] = {
311 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
312 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
313 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
314 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
315 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
316 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
317 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
318 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
319 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
320 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
321 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
322 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
323 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
324 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
325 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
326 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
327 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
331 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
332 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
335 struct tm6000_core *dev = ptr;
337 if (dev->tuner_type != TUNER_XC5000)
341 case XC5000_TUNER_RESET:
342 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
343 dev->gpio.tuner_reset, 0x01);
345 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
346 dev->gpio.tuner_reset, 0x00);
348 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
349 dev->gpio.tuner_reset, 0x01);
354 EXPORT_SYMBOL_GPL(tm6000_xc5000_callback);
356 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
358 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
361 struct tm6000_core *dev = ptr;
363 if (dev->tuner_type != TUNER_XC2028)
367 case XC2028_RESET_CLK:
368 tm6000_ir_wait(dev, 0);
370 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
373 rc = tm6000_i2c_reset(dev, 10);
375 case XC2028_TUNER_RESET:
376 /* Reset codes during load firmware */
379 /* newer tuner can faster reset */
380 switch (dev->model) {
381 case TM5600_BOARD_10MOONS_UT821:
382 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
383 dev->gpio.tuner_reset, 0x01);
384 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
387 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
388 dev->gpio.tuner_reset, 0x00);
389 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
392 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
393 dev->gpio.tuner_reset, 0x01);
394 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
397 case TM6010_BOARD_HAUPPAUGE_900H:
398 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
399 case TM6010_BOARD_TWINHAN_TU501:
400 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
401 dev->gpio.tuner_reset, 0x01);
403 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
404 dev->gpio.tuner_reset, 0x00);
406 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
407 dev->gpio.tuner_reset, 0x01);
411 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
412 dev->gpio.tuner_reset, 0x00);
414 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
415 dev->gpio.tuner_reset, 0x01);
420 tm6000_ir_wait(dev, 1);
423 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
428 rc = tm6000_i2c_reset(dev, 100);
434 EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
436 int tm6000_cards_setup(struct tm6000_core *dev)
441 * Board-specific initialization sequence. Handles all GPIO
442 * initialization sequences that are board-specific.
443 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
444 * Probably, they're all based on some reference device. Due to that,
445 * there's a common routine at the end to handle those GPIO's. Devices
446 * that use different pinups or init sequences can just return at
447 * the board-specific session.
449 switch (dev->model) {
450 case TM6010_BOARD_HAUPPAUGE_900H:
451 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
452 case TM6010_BOARD_TWINHAN_TU501:
453 case TM6010_BOARD_GENERIC:
454 /* Turn xceive 3028 on */
455 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
457 /* Turn zarlink zl10353 on */
458 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
460 /* Reset zarlink zl10353 */
461 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
463 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
465 /* Turn zarlink zl10353 off */
466 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
469 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
471 /* Power led on (blue) */
472 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
474 /* DVB led off (orange) */
475 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
477 /* Turn zarlink zl10353 on */
478 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
481 case TM6010_BOARD_BEHOLD_WANDER:
482 /* Power led on (blue) */
483 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
485 /* Reset zarlink zl10353 */
486 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
488 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
491 case TM6010_BOARD_BEHOLD_VOYAGER:
492 /* Power led on (blue) */
493 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
501 * Default initialization. Most of the devices seem to use GPIO1
502 * and GPIO4.on the same way, so, this handles the common sequence
503 * used by most devices.
504 * If a device uses a different sequence or different GPIO pins for
505 * reset, just add the code at the board-specific part
508 if (dev->gpio.tuner_reset) {
509 for (i = 0; i < 2; i++) {
510 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
511 dev->gpio.tuner_reset, 0x00);
513 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
517 msleep(10); /* Just to be conservative */
518 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
519 dev->gpio.tuner_reset, 0x01);
521 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
527 rc = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
529 printk(KERN_DEBUG "board=0x%08x\n", rc);
533 printk(KERN_ERR "Tuner reset is not configured\n");
542 static void tm6000_config_tuner(struct tm6000_core *dev)
544 struct tuner_setup tun_setup;
546 /* Load tuner module */
547 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
548 NULL, "tuner", dev->tuner_addr, NULL);
550 memset(&tun_setup, 0, sizeof(tun_setup));
551 tun_setup.type = dev->tuner_type;
552 tun_setup.addr = dev->tuner_addr;
554 tun_setup.mode_mask = 0;
555 if (dev->caps.has_tuner)
556 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
557 if (dev->caps.has_dvb)
558 tun_setup.mode_mask |= T_DIGITAL_TV;
560 switch (dev->tuner_type) {
562 tun_setup.tuner_callback = tm6000_tuner_callback;
565 tun_setup.tuner_callback = tm6000_xc5000_callback;
569 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
571 switch (dev->tuner_type) {
573 struct v4l2_priv_tun_config xc2028_cfg;
574 struct xc2028_ctrl ctl;
576 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
577 memset(&ctl, 0, sizeof(ctl));
580 ctl.read_not_reliable = 0;
582 ctl.demod = XC3028_FE_ZARLINK456;
585 xc2028_cfg.tuner = TUNER_XC2028;
586 xc2028_cfg.priv = &ctl;
588 switch (dev->model) {
589 case TM6010_BOARD_HAUPPAUGE_900H:
590 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
591 case TM6010_BOARD_TWINHAN_TU501:
592 ctl.fname = "xc3028L-v36.fw";
595 if (dev->dev_type == TM6010)
596 ctl.fname = "xc3028-v27.fw";
598 ctl.fname = "xc3028-v24.fw";
601 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
602 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
609 struct v4l2_priv_tun_config xc5000_cfg;
610 struct xc5000_config ctl = {
611 .i2c_address = dev->tuner_addr,
613 .radio_input = XC5000_RADIO_FM1,
616 xc5000_cfg.tuner = TUNER_XC5000;
617 xc5000_cfg.priv = &ctl;
620 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
625 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
630 static int tm6000_init_dev(struct tm6000_core *dev)
632 struct v4l2_frequency f;
635 mutex_init(&dev->lock);
637 mutex_lock(&dev->lock);
639 /* Initializa board-specific data */
640 dev->dev_type = tm6000_boards[dev->model].type;
641 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
642 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
644 dev->gpio = tm6000_boards[dev->model].gpio;
646 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
648 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
650 dev->caps = tm6000_boards[dev->model].caps;
652 /* initialize hardware */
653 rc = tm6000_init(dev);
657 rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
661 /* register i2c bus */
662 rc = tm6000_i2c_register(dev);
666 /* Default values for STD and resolutions */
669 dev->norm = V4L2_STD_PAL_M;
671 /* Configure tuner */
672 tm6000_config_tuner(dev);
674 /* Set video standard */
675 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
677 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
679 f.type = V4L2_TUNER_ANALOG_TV;
680 f.frequency = 3092; /* 193.25 MHz */
681 dev->freq = f.frequency;
682 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
684 if (dev->caps.has_tda9874)
685 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
686 NULL, "tvaudio", I2C_ADDR_TDA9874, NULL);
688 /* register and initialize V4L2 */
689 rc = tm6000_v4l2_register(dev);
693 tm6000_add_into_devlist(dev);
694 tm6000_init_extension(dev);
698 mutex_unlock(&dev->lock);
702 mutex_unlock(&dev->lock);
706 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
707 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
709 static void get_max_endpoint(struct usb_device *udev,
710 struct usb_host_interface *alt,
712 struct usb_host_endpoint *curr_e,
713 struct tm6000_endpoint *tm_ep)
715 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
716 unsigned int size = tmp & 0x7ff;
718 if (udev->speed == USB_SPEED_HIGH)
719 size = size * hb_mult(tmp);
721 if (size > tm_ep->maxsize) {
722 tm_ep->endp = curr_e;
723 tm_ep->maxsize = size;
724 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
725 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
727 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
728 msgtype, curr_e->desc.bEndpointAddress,
735 * checks for supported devices
737 static int tm6000_usb_probe(struct usb_interface *interface,
738 const struct usb_device_id *id)
740 struct usb_device *usbdev;
741 struct tm6000_core *dev = NULL;
746 usbdev = usb_get_dev(interface_to_usbdev(interface));
748 /* Selects the proper interface */
749 rc = usb_set_interface(usbdev, 0, 1);
753 /* Check to see next free device and mark as used */
754 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
755 if (nr >= TM6000_MAXBOARDS) {
756 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
761 /* Create and initialize dev struct */
762 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
764 printk(KERN_ERR "tm6000" ": out of memory!\n");
768 spin_lock_init(&dev->slock);
770 /* Increment usage count */
771 tm6000_devused |= 1<<nr;
772 snprintf(dev->name, 29, "tm6000 #%d", nr);
774 dev->model = id->driver_info;
775 if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
776 dev->model = card[nr];
781 switch (usbdev->speed) {
785 case USB_SPEED_UNKNOWN:
799 for (i = 0; i < interface->num_altsetting; i++) {
802 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
803 struct usb_host_endpoint *e;
806 e = &interface->altsetting[i].endpoint[ep];
808 dir_out = ((e->desc.bEndpointAddress &
809 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
811 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
813 interface->altsetting[i].desc.bInterfaceNumber,
814 interface->altsetting[i].desc.bInterfaceClass);
816 switch (e->desc.bmAttributes) {
817 case USB_ENDPOINT_XFER_BULK:
819 get_max_endpoint(usbdev,
820 &interface->altsetting[i],
824 get_max_endpoint(usbdev,
825 &interface->altsetting[i],
830 case USB_ENDPOINT_XFER_ISOC:
832 get_max_endpoint(usbdev,
833 &interface->altsetting[i],
837 get_max_endpoint(usbdev,
838 &interface->altsetting[i],
843 case USB_ENDPOINT_XFER_INT:
845 get_max_endpoint(usbdev,
846 &interface->altsetting[i],
850 get_max_endpoint(usbdev,
851 &interface->altsetting[i],
861 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
863 le16_to_cpu(dev->udev->descriptor.idVendor),
864 le16_to_cpu(dev->udev->descriptor.idProduct),
865 interface->altsetting->desc.bInterfaceNumber);
867 /* check if the the device has the iso in endpoint at the correct place */
868 if (!dev->isoc_in.endp) {
869 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
875 /* save our data pointer in this interface device */
876 usb_set_intfdata(interface, dev);
878 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
880 rc = tm6000_init_dev(dev);
888 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
890 tm6000_devused &= ~(1<<nr);
898 * tm6000_usb_disconnect()
899 * called when the device gets diconencted
900 * video device will be unregistered on v4l2_close in case it is still open
902 static void tm6000_usb_disconnect(struct usb_interface *interface)
904 struct tm6000_core *dev = usb_get_intfdata(interface);
905 usb_set_intfdata(interface, NULL);
910 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
914 if (dev->gpio.power_led) {
915 switch (dev->model) {
916 case TM6010_BOARD_HAUPPAUGE_900H:
917 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
918 case TM6010_BOARD_TWINHAN_TU501:
920 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
921 dev->gpio.power_led, 0x01);
924 case TM6010_BOARD_BEHOLD_WANDER:
925 case TM6010_BOARD_BEHOLD_VOYAGER:
927 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
928 dev->gpio.power_led, 0x00);
933 tm6000_v4l2_unregister(dev);
935 tm6000_i2c_unregister(dev);
937 v4l2_device_unregister(&dev->v4l2_dev);
939 dev->state |= DEV_DISCONNECTED;
941 usb_put_dev(dev->udev);
943 tm6000_close_extension(dev);
944 tm6000_remove_from_devlist(dev);
949 static struct usb_driver tm6000_usb_driver = {
951 .probe = tm6000_usb_probe,
952 .disconnect = tm6000_usb_disconnect,
953 .id_table = tm6000_id_table,
956 static int __init tm6000_module_init(void)
960 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
961 (TM6000_VERSION >> 16) & 0xff,
962 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
964 /* register this driver with the USB subsystem */
965 result = usb_register(&tm6000_usb_driver);
967 printk(KERN_ERR "tm6000"
968 " usb_register failed. Error number %d.\n", result);
973 static void __exit tm6000_module_exit(void)
975 /* deregister at USB subsystem */
976 usb_deregister(&tm6000_usb_driver);
979 module_init(tm6000_module_init);
980 module_exit(tm6000_module_exit);
982 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
983 MODULE_AUTHOR("Mauro Carvalho Chehab");
984 MODULE_LICENSE("GPL");