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
51 #define TM6000_MAXBOARDS 16
52 static unsigned int card
[] = {[0 ... (TM6000_MAXBOARDS
- 1)] = UNSET
};
54 module_param_array(card
, int, NULL
, 0444);
56 static unsigned long tm6000_devused
;
62 struct tm6000_capabilities caps
;
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 */
71 struct tm6000_board tm6000_boards
[] = {
72 [TM6000_BOARD_UNKNOWN
] = {
73 .name
= "Unknown tm6000 video grabber",
77 .gpio_addr_tun_reset
= TM6000_GPIO_1
,
79 [TM5600_BOARD_GENERIC
] = {
80 .name
= "Generic tm5600 board",
82 .tuner_type
= TUNER_XC2028
,
83 .tuner_addr
= 0xc2 >> 1,
87 .gpio_addr_tun_reset
= TM6000_GPIO_1
,
89 [TM6000_BOARD_GENERIC
] = {
90 .name
= "Generic tm6000 board",
91 .tuner_type
= TUNER_XC2028
,
92 .tuner_addr
= 0xc2 >> 1,
97 .gpio_addr_tun_reset
= TM6000_GPIO_1
,
99 [TM6010_BOARD_GENERIC
] = {
100 .name
= "Generic tm6010 board",
102 .tuner_type
= TUNER_XC2028
,
103 .tuner_addr
= 0xc2 >> 1,
108 .gpio_addr_tun_reset
= TM6010_GPIO_4
,
110 [TM5600_BOARD_10MOONS_UT821
] = {
111 .name
= "10Moons UT 821",
112 .tuner_type
= TUNER_XC2028
,
114 .tuner_addr
= 0xc2 >> 1,
119 .gpio_addr_tun_reset
= TM6000_GPIO_1
,
121 [TM5600_BOARD_10MOONS_UT330
] = {
122 .name
= "10Moons UT 330",
123 .tuner_type
= TUNER_PHILIPS_FQ1216AME_MK4
,
124 .tuner_addr
= 0xc8 >> 1,
132 [TM6000_BOARD_ADSTECH_DUAL_TV
] = {
133 .name
= "ADSTECH Dual TV USB",
134 .tuner_type
= TUNER_XC2028
,
135 .tuner_addr
= 0xc8 >> 1,
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,
156 .gpio_addr_tun_reset
= TM6000_GPIO_4
,
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,
169 .gpio_addr_tun_reset
= TM6000_GPIO_4
,
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,
183 .gpio_addr_tun_reset
= TM6000_GPIO_2
,
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,
198 .gpio_addr_tun_reset
= TM6000_GPIO_2
,
200 [TM6010_BOARD_BEHOLD_VOYAGER
] = {
201 .name
= "Beholder Voyager TV/FM USB2.0",
202 .tuner_type
= TUNER_XC5000
,
203 .tuner_addr
= 0xc2 >> 1,
212 .gpio_addr_tun_reset
= TM6000_GPIO_2
,
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,
227 .gpio_addr_tun_reset
= TM6010_GPIO_2
,
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
},
245 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
247 int tm6000_tuner_callback(void *ptr
, int component
, int command
, int arg
)
250 struct tm6000_core
*dev
= ptr
;
252 if (dev
->tuner_type
!=TUNER_XC2028
)
256 case XC2028_RESET_CLK
:
257 tm6000_set_reg (dev
, REQ_04_EN_DISABLE_MCU_INT
,
260 rc
=tm6000_set_reg (dev
, REQ_03_SET_GET_MCU_PIN
,
265 rc
=tm6000_set_reg (dev
, REQ_03_SET_GET_MCU_PIN
,
268 case XC2028_TUNER_RESET
:
269 /* Reset codes during load firmware */
272 /* newer tuner can faster reset */
273 switch (dev
->model
) {
274 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
275 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
276 dev
->tuner_reset_gpio
, 0x01);
278 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
279 dev
->tuner_reset_gpio
, 0x00);
281 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
282 dev
->tuner_reset_gpio
, 0x01);
286 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
287 dev
->tuner_reset_gpio
, 0x00);
289 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
290 dev
->tuner_reset_gpio
, 0x01);
296 tm6000_set_reg (dev
, REQ_04_EN_DISABLE_MCU_INT
,
302 rc
=tm6000_set_reg (dev
, REQ_03_SET_GET_MCU_PIN
,
307 rc
=tm6000_set_reg (dev
, REQ_03_SET_GET_MCU_PIN
,
316 int tm6000_cards_setup(struct tm6000_core
*dev
)
321 * Board-specific initialization sequence. Handles all GPIO
322 * initialization sequences that are board-specific.
323 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
324 * Probably, they're all based on some reference device. Due to that,
325 * there's a common routine at the end to handle those GPIO's. Devices
326 * that use different pinups or init sequences can just return at
327 * the board-specific session.
329 switch (dev
->model
) {
330 case TM6010_BOARD_HAUPPAUGE_900H
:
331 /* Turn xceive 3028 on */
332 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_3
, 0x01);
335 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
336 /* Turn zarlink zl10353 on */
337 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_4
, 0x00);
339 /* Reset zarlink zl10353 */
340 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_1
, 0x00);
342 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_1
, 0x01);
344 /* Turn zarlink zl10353 off */
345 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_4
, 0x01);
348 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_0
, 0x01);
350 /* Power led on (blue) */
351 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_7
, 0x00);
353 /* DVB led off (orange) */
354 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_5
, 0x01);
356 /* Turn zarlink zl10353 on */
357 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6010_GPIO_4
, 0x00);
365 * Default initialization. Most of the devices seem to use GPIO1
366 * and GPIO4.on the same way, so, this handles the common sequence
367 * used by most devices.
368 * If a device uses a different sequence or different GPIO pins for
369 * reset, just add the code at the board-specific part
371 for (i
= 0; i
< 2; i
++) {
372 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
373 dev
->tuner_reset_gpio
, 0x00);
375 printk(KERN_ERR
"Error %i doing GPIO1 reset\n", rc
);
379 msleep(10); /* Just to be conservative */
380 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
381 dev
->tuner_reset_gpio
, 0x01);
383 printk(KERN_ERR
"Error %i doing GPIO1 reset\n", rc
);
388 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6000_GPIO_4
, 0);
390 printk(KERN_ERR
"Error %i doing GPIO4 reset\n", rc
);
395 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, TM6000_GPIO_4
, 1);
397 printk(KERN_ERR
"Error %i doing GPIO4 reset\n", rc
);
402 rc
= tm6000_get_reg16(dev
, 0x40, 0, 0);
404 printk(KERN_DEBUG
"board=%d\n", rc
);
413 static void tm6000_config_tuner (struct tm6000_core
*dev
)
415 struct tuner_setup tun_setup
;
417 /* Load tuner module */
418 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
419 "tuner", "tuner",dev
->tuner_addr
, NULL
);
421 memset(&tun_setup
, 0, sizeof(tun_setup
));
422 tun_setup
.type
= dev
->tuner_type
;
423 tun_setup
.addr
= dev
->tuner_addr
;
424 tun_setup
.mode_mask
= T_ANALOG_TV
| T_RADIO
| T_DIGITAL_TV
;
425 tun_setup
.tuner_callback
= tm6000_tuner_callback
;
427 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_type_addr
, &tun_setup
);
429 if (dev
->tuner_type
== TUNER_XC2028
) {
430 struct v4l2_priv_tun_config xc2028_cfg
;
431 struct xc2028_ctrl ctl
;
433 memset(&xc2028_cfg
, 0, sizeof(xc2028_cfg
));
434 memset (&ctl
,0,sizeof(ctl
));
437 ctl
.read_not_reliable
= 0;
439 ctl
.demod
= XC3028_FE_ZARLINK456
;
442 xc2028_cfg
.tuner
= TUNER_XC2028
;
443 xc2028_cfg
.priv
= &ctl
;
446 case TM6010_BOARD_HAUPPAUGE_900H
:
447 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
448 ctl
.fname
= "xc3028L-v36.fw";
451 if (dev
->dev_type
== TM6010
)
452 ctl
.fname
= "xc3028-v27.fw";
454 ctl
.fname
= "tm6000-xc3028.fw";
457 printk(KERN_INFO
"Setting firmware parameters for xc2028\n");
459 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_config
,
464 static int tm6000_init_dev(struct tm6000_core
*dev
)
466 struct v4l2_frequency f
;
469 mutex_init(&dev
->lock
);
471 mutex_lock(&dev
->lock
);
473 /* Initializa board-specific data */
474 dev
->dev_type
= tm6000_boards
[dev
->model
].type
;
475 dev
->tuner_type
= tm6000_boards
[dev
->model
].tuner_type
;
476 dev
->tuner_addr
= tm6000_boards
[dev
->model
].tuner_addr
;
477 dev
->tuner_reset_gpio
= tm6000_boards
[dev
->model
].gpio_addr_tun_reset
;
479 dev
->demod_addr
= tm6000_boards
[dev
->model
].demod_addr
;
481 dev
->caps
= tm6000_boards
[dev
->model
].caps
;
483 /* initialize hardware */
484 rc
=tm6000_init (dev
);
488 rc
= v4l2_device_register(&dev
->udev
->dev
, &dev
->v4l2_dev
);
492 /* register i2c bus */
493 rc
=tm6000_i2c_register(dev
);
497 /* Default values for STD and resolutions */
500 dev
->norm
= V4L2_STD_PAL_M
;
502 /* Configure tuner */
503 tm6000_config_tuner (dev
);
505 /* Set video standard */
506 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
508 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
510 f
.type
= V4L2_TUNER_ANALOG_TV
;
511 f
.frequency
= 3092; /* 193.25 MHz */
512 dev
->freq
= f
.frequency
;
513 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, &f
);
515 if (dev
->caps
.has_tda9874
)
516 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
517 "tvaudio", "tvaudio", I2C_ADDR_TDA9874
, NULL
);
519 /* register and initialize V4L2 */
520 rc
=tm6000_v4l2_register(dev
);
524 if(dev
->caps
.has_dvb
) {
525 dev
->dvb
= kzalloc(sizeof(*(dev
->dvb
)), GFP_KERNEL
);
531 #ifdef CONFIG_VIDEO_TM6000_DVB
532 rc
= tm6000_dvb_register(dev
);
540 mutex_unlock(&dev
->lock
);
544 v4l2_device_unregister(&dev
->v4l2_dev
);
547 mutex_unlock(&dev
->lock
);
551 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
552 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
554 static void get_max_endpoint ( struct usb_device
*usbdev
,
556 struct usb_host_endpoint
*curr_e
,
557 unsigned int *maxsize
,
558 struct usb_host_endpoint
**ep
)
560 u16 tmp
= le16_to_cpu(curr_e
->desc
.wMaxPacketSize
);
561 unsigned int size
= tmp
& 0x7ff;
563 if (usbdev
->speed
== USB_SPEED_HIGH
)
564 size
= size
* hb_mult (tmp
);
569 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
570 msgtype
, curr_e
->desc
.bEndpointAddress
,
577 * checks for supported devices
579 static int tm6000_usb_probe(struct usb_interface
*interface
,
580 const struct usb_device_id
*id
)
582 struct usb_device
*usbdev
;
583 struct tm6000_core
*dev
= NULL
;
589 usbdev
=usb_get_dev(interface_to_usbdev(interface
));
591 /* Selects the proper interface */
592 rc
=usb_set_interface(usbdev
,0,1);
596 /* Check to see next free device and mark as used */
597 nr
=find_first_zero_bit(&tm6000_devused
,TM6000_MAXBOARDS
);
598 if (nr
>= TM6000_MAXBOARDS
) {
599 printk ("tm6000: Supports only %i tm60xx boards.\n",TM6000_MAXBOARDS
);
604 /* Create and initialize dev struct */
605 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
607 printk ("tm6000" ": out of memory!\n");
611 spin_lock_init(&dev
->slock
);
613 /* Increment usage count */
614 tm6000_devused
|=1<<nr
;
615 snprintf(dev
->name
, 29, "tm6000 #%d", nr
);
617 dev
->model
=id
->driver_info
;
618 if ((card
[nr
]>=0) && (card
[nr
]<ARRAY_SIZE(tm6000_boards
))) {
622 INIT_LIST_HEAD(&dev
->tm6000_corelist
);
626 switch (usbdev
->speed
) {
630 case USB_SPEED_UNKNOWN
:
644 for (i
= 0; i
< interface
->num_altsetting
; i
++) {
647 for (ep
= 0; ep
< interface
->altsetting
[i
].desc
.bNumEndpoints
; ep
++) {
648 struct usb_host_endpoint
*e
;
651 e
= &interface
->altsetting
[i
].endpoint
[ep
];
653 dir_out
= ((e
->desc
.bEndpointAddress
&
654 USB_ENDPOINT_DIR_MASK
) == USB_DIR_OUT
);
656 printk("tm6000: alt %d, interface %i, class %i\n",
658 interface
->altsetting
[i
].desc
.bInterfaceNumber
,
659 interface
->altsetting
[i
].desc
.bInterfaceClass
);
661 switch (e
->desc
.bmAttributes
) {
662 case USB_ENDPOINT_XFER_BULK
:
664 get_max_endpoint (usbdev
, "Bulk IN", e
,
668 get_max_endpoint (usbdev
, "Bulk OUT", e
,
673 case USB_ENDPOINT_XFER_ISOC
:
675 get_max_endpoint (usbdev
, "ISOC IN", e
,
679 get_max_endpoint (usbdev
, "ISOC OUT", e
,
689 printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
691 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
692 le16_to_cpu(dev
->udev
->descriptor
.idProduct
),
693 interface
->altsetting
->desc
.bInterfaceNumber
);
695 /* check if the the device has the iso in endpoint at the correct place */
697 printk("tm6000: probing error: no IN ISOC endpoint!\n");
703 /* save our data pointer in this interface device */
704 usb_set_intfdata(interface
, dev
);
706 printk("tm6000: Found %s\n", tm6000_boards
[dev
->model
].name
);
708 rc
=tm6000_init_dev(dev
);
716 printk("tm6000: Error %d while registering\n", rc
);
718 tm6000_devused
&=~(1<<nr
);
726 * tm6000_usb_disconnect()
727 * called when the device gets diconencted
728 * video device will be unregistered on v4l2_close in case it is still open
730 static void tm6000_usb_disconnect(struct usb_interface
*interface
)
732 struct tm6000_core
*dev
= usb_get_intfdata(interface
);
733 usb_set_intfdata(interface
, NULL
);
738 printk("tm6000: disconnecting %s\n", dev
->name
);
740 mutex_lock(&dev
->lock
);
742 #ifdef CONFIG_VIDEO_TM6000_DVB
744 tm6000_dvb_unregister(dev
);
749 tm6000_v4l2_unregister(dev
);
751 tm6000_i2c_unregister(dev
);
753 v4l2_device_unregister(&dev
->v4l2_dev
);
755 // wake_up_interruptible_all(&dev->open);
757 dev
->state
|= DEV_DISCONNECTED
;
759 usb_put_dev(dev
->udev
);
761 mutex_unlock(&dev
->lock
);
765 static struct usb_driver tm6000_usb_driver
= {
767 .probe
= tm6000_usb_probe
,
768 .disconnect
= tm6000_usb_disconnect
,
769 .id_table
= tm6000_id_table
,
772 static int __init
tm6000_module_init(void)
776 printk(KERN_INFO
"tm6000" " v4l2 driver version %d.%d.%d loaded\n",
777 (TM6000_VERSION
>> 16) & 0xff,
778 (TM6000_VERSION
>> 8) & 0xff, TM6000_VERSION
& 0xff);
780 /* register this driver with the USB subsystem */
781 result
= usb_register(&tm6000_usb_driver
);
784 " usb_register failed. Error number %d.\n", result
);
789 static void __exit
tm6000_module_exit(void)
791 /* deregister at USB subsystem */
792 usb_deregister(&tm6000_usb_driver
);
795 module_init(tm6000_module_init
);
796 module_exit(tm6000_module_exit
);
798 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
799 MODULE_AUTHOR("Mauro Carvalho Chehab");
800 MODULE_LICENSE("GPL");