2 tm6000-cards.c - driver for TM5600/TM6000 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>
31 #include "tm6000-regs.h"
32 #include "tuner-xc2028.h"
34 #define TM6000_BOARD_UNKNOWN 0
35 #define TM5600_BOARD_GENERIC 1
36 #define TM6000_BOARD_GENERIC 2
37 #define TM6010_BOARD_GENERIC 3
38 #define TM5600_BOARD_10MOONS_UT821 4
39 #define TM5600_BOARD_10MOONS_UT330 5
40 #define TM6000_BOARD_ADSTECH_DUAL_TV 6
41 #define TM6000_BOARD_FREECOM_AND_SIMILAR 7
42 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
43 #define TM6010_BOARD_HAUPPAUGE_900H 9
45 #define TM6000_MAXBOARDS 16
46 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
48 module_param_array(card, int, NULL, 0444);
50 static unsigned long tm6000_devused;
56 struct tm6000_capabilities caps;
58 enum tm6000_devtype type; /* variant of the chipset */
59 int tuner_type; /* type of the tuner */
60 int tuner_addr; /* tuner address */
61 int demod_addr; /* demodulator address */
62 int gpio_addr_tun_reset; /* GPIO used for tuner reset */
65 struct tm6000_board tm6000_boards[] = {
66 [TM6000_BOARD_UNKNOWN] = {
67 .name = "Unknown tm6000 video grabber",
71 .gpio_addr_tun_reset = TM6000_GPIO_1,
73 [TM5600_BOARD_GENERIC] = {
74 .name = "Generic tm5600 board",
76 .tuner_type = TUNER_XC2028,
81 .gpio_addr_tun_reset = TM6000_GPIO_1,
83 [TM6000_BOARD_GENERIC] = {
84 .name = "Generic tm6000 board",
85 .tuner_type = TUNER_XC2028,
91 .gpio_addr_tun_reset = TM6000_GPIO_1,
93 [TM6010_BOARD_GENERIC] = {
94 .name = "Generic tm6010 board",
96 .tuner_type = TUNER_XC2028,
102 .gpio_addr_tun_reset = TM6010_GPIO_4,
104 [TM5600_BOARD_10MOONS_UT821] = {
105 .name = "10Moons UT 821",
106 .tuner_type = TUNER_XC2028,
113 .gpio_addr_tun_reset = TM6000_GPIO_1,
115 [TM5600_BOARD_10MOONS_UT330] = {
116 .name = "10Moons UT 330",
117 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
126 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
127 .name = "ADSTECH Dual TV USB",
128 .tuner_type = TUNER_XC2028,
138 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
139 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
140 .tuner_type = TUNER_XC2028, /* has a XC3028 */
150 .gpio_addr_tun_reset = TM6000_GPIO_4,
152 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
153 .name = "ADSTECH Mini Dual TV USB",
154 .tuner_type = TUNER_XC2028, /* has a XC3028 */
163 .gpio_addr_tun_reset = TM6000_GPIO_4,
165 [TM6010_BOARD_HAUPPAUGE_900H] = {
166 .name = "Hauppauge HVR-900H",
167 .tuner_type = TUNER_XC2028, /* has a XC3028 */
177 .gpio_addr_tun_reset = TM6000_GPIO_2,
181 /* table of devices that work with this driver */
182 struct usb_device_id tm6000_id_table [] = {
183 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
184 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
185 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
186 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
187 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
188 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
192 static void tm6000_config_tuner (struct tm6000_core *dev)
194 request_module ("tuner");
196 if (dev->tuner_type == TUNER_XC2028) {
197 struct v4l2_priv_tun_config xc2028_cfg;
198 struct xc2028_ctrl ctl;
200 memset (&ctl,0,sizeof(ctl));
203 ctl.read_not_reliable = 1;
206 xc2028_cfg.tuner = TUNER_XC2028;
207 xc2028_cfg.priv = &ctl;
210 case TM6010_BOARD_HAUPPAUGE_900H:
211 ctl.fname = "xc3028L-v36.fw";
214 if (dev->dev_type == TM6010)
215 ctl.fname = "xc3028-v27.fw";
217 ctl.fname = "tm6000-xc3028.fw";
220 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
222 tm6000_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
226 static int tm6000_init_dev(struct tm6000_core *dev)
228 struct v4l2_frequency f;
231 mutex_init(&dev->lock);
233 mutex_lock(&dev->lock);
235 /* Initializa board-specific data */
236 dev->dev_type = tm6000_boards[dev->model].type;
237 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
238 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
239 dev->tuner_reset_gpio = tm6000_boards[dev->model].gpio_addr_tun_reset;
241 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
243 dev->caps = tm6000_boards[dev->model].caps;
245 /* initialize hardware */
246 rc=tm6000_init (dev);
250 /* register i2c bus */
251 rc=tm6000_i2c_register(dev);
255 /* register and initialize V4L2 */
256 rc=tm6000_v4l2_register(dev);
260 /* Default values for STD and resolutions */
263 dev->norm = V4L2_STD_PAL_M;
265 /* Configure tuner */
266 tm6000_config_tuner (dev);
268 /* Set video standard */
269 tm6000_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
271 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
273 f.type = V4L2_TUNER_ANALOG_TV;
274 f.frequency = 3092; /* 193.25 MHz */
275 dev->freq = f.frequency;
276 tm6000_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
278 if(dev->caps.has_dvb) {
279 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
284 #ifdef CONFIG_VIDEO_TM6000_DVB
285 rc = tm6000_dvb_register(dev);
294 mutex_unlock(&dev->lock);
298 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
299 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
301 static void get_max_endpoint ( struct usb_device *usbdev,
303 struct usb_host_endpoint *curr_e,
304 unsigned int *maxsize,
305 struct usb_host_endpoint **ep )
307 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
308 unsigned int size = tmp & 0x7ff;
310 if (usbdev->speed == USB_SPEED_HIGH)
311 size = size * hb_mult (tmp);
316 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
317 msgtype, curr_e->desc.bEndpointAddress,
324 * checks for supported devices
326 static int tm6000_usb_probe(struct usb_interface *interface,
327 const struct usb_device_id *id)
329 struct usb_device *usbdev;
330 struct tm6000_core *dev = NULL;
336 usbdev=usb_get_dev(interface_to_usbdev(interface));
338 /* Selects the proper interface */
339 rc=usb_set_interface(usbdev,0,1);
343 /* Check to see next free device and mark as used */
344 nr=find_first_zero_bit(&tm6000_devused,TM6000_MAXBOARDS);
345 if (nr >= TM6000_MAXBOARDS) {
346 printk ("tm6000: Supports only %i em28xx boards.\n",TM6000_MAXBOARDS);
351 /* Create and initialize dev struct */
352 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
354 printk ("tm6000" ": out of memory!\n");
358 spin_lock_init(&dev->slock);
360 /* Increment usage count */
361 tm6000_devused|=1<<nr;
362 snprintf(dev->name, 29, "tm6000 #%d", nr);
364 dev->model=id->driver_info;
365 if ((card[nr]>=0) && (card[nr]<ARRAY_SIZE(tm6000_boards))) {
369 INIT_LIST_HEAD(&dev->tm6000_corelist);
373 switch (usbdev->speed) {
377 case USB_SPEED_UNKNOWN:
391 for (i = 0; i < interface->num_altsetting; i++) {
394 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
395 struct usb_host_endpoint *e;
398 e = &interface->altsetting[i].endpoint[ep];
400 dir_out = ((e->desc.bEndpointAddress &
401 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
403 printk("tm6000: alt %d, interface %i, class %i\n",
405 interface->altsetting[i].desc.bInterfaceNumber,
406 interface->altsetting[i].desc.bInterfaceClass);
408 switch (e->desc.bmAttributes) {
409 case USB_ENDPOINT_XFER_BULK:
411 get_max_endpoint (usbdev, "Bulk IN", e,
415 get_max_endpoint (usbdev, "Bulk OUT", e,
420 case USB_ENDPOINT_XFER_ISOC:
422 get_max_endpoint (usbdev, "ISOC IN", e,
426 get_max_endpoint (usbdev, "ISOC OUT", e,
436 printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
438 le16_to_cpu(dev->udev->descriptor.idVendor),
439 le16_to_cpu(dev->udev->descriptor.idProduct),
440 interface->altsetting->desc.bInterfaceNumber);
442 /* check if the the device has the iso in endpoint at the correct place */
444 printk("tm6000: probing error: no IN ISOC endpoint!\n");
450 /* save our data pointer in this interface device */
451 usb_set_intfdata(interface, dev);
453 printk("tm6000: Found %s\n", tm6000_boards[dev->model].name);
455 rc=tm6000_init_dev(dev);
463 tm6000_devused&=~(1<<nr);
471 * tm6000_usb_disconnect()
472 * called when the device gets diconencted
473 * video device will be unregistered on v4l2_close in case it is still open
475 static void tm6000_usb_disconnect(struct usb_interface *interface)
477 struct tm6000_core *dev = usb_get_intfdata(interface);
478 usb_set_intfdata(interface, NULL);
483 printk("tm6000: disconnecting %s\n", dev->name);
485 mutex_lock(&dev->lock);
487 #ifdef CONFIG_VIDEO_TM6000_DVB
489 tm6000_dvb_unregister(dev);
494 tm6000_v4l2_unregister(dev);
496 tm6000_i2c_unregister(dev);
498 // wake_up_interruptible_all(&dev->open);
500 dev->state |= DEV_DISCONNECTED;
502 usb_put_dev(dev->udev);
504 mutex_unlock(&dev->lock);
508 static struct usb_driver tm6000_usb_driver = {
510 .probe = tm6000_usb_probe,
511 .disconnect = tm6000_usb_disconnect,
512 .id_table = tm6000_id_table,
515 static int __init tm6000_module_init(void)
519 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
520 (TM6000_VERSION >> 16) & 0xff,
521 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
523 /* register this driver with the USB subsystem */
524 result = usb_register(&tm6000_usb_driver);
527 " usb_register failed. Error number %d.\n", result);
532 static void __exit tm6000_module_exit(void)
534 /* deregister at USB subsystem */
535 usb_deregister(&tm6000_usb_driver);
538 module_init(tm6000_module_init);
539 module_exit(tm6000_module_exit);
541 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000 USB2 adapter");
542 MODULE_AUTHOR("Mauro Carvalho Chehab");
543 MODULE_LICENSE("GPL");