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 TM5600_BOARD_10MOONS_UT821 3
38 #define TM5600_BOARD_10MOONS_UT330 4
39 #define TM6000_BOARD_ADSTECH_DUAL_TV 5
40 #define TM6000_BOARD_FREECOM_AND_SIMILAR 6
41 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 7
43 #define TM6000_MAXBOARDS 16
44 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
46 module_param_array(card, int, NULL, 0444);
48 static unsigned long tm6000_devused;
54 struct tm6000_capabilities caps;
56 int tuner_type; /* type of the tuner */
57 int tuner_addr; /* tuner address */
58 int demod_addr; /* demodulator address */
59 int gpio_addr_tun_reset; /* GPIO used for tuner reset */
62 struct tm6000_board tm6000_boards[] = {
63 [TM6000_BOARD_UNKNOWN] = {
64 .name = "Unknown tm6000 video grabber",
68 .gpio_addr_tun_reset = TM6000_GPIO_1,
70 [TM5600_BOARD_GENERIC] = {
71 .name = "Generic tm5600 board",
72 .tuner_type = TUNER_XC2028,
77 .gpio_addr_tun_reset = TM6000_GPIO_1,
79 [TM6000_BOARD_GENERIC] = {
80 .name = "Generic tm6000 board",
81 .tuner_type = TUNER_XC2028,
87 .gpio_addr_tun_reset = TM6000_GPIO_1,
89 [TM5600_BOARD_10MOONS_UT821] = {
90 .name = "10Moons UT 821",
91 .tuner_type = TUNER_XC2028,
97 .gpio_addr_tun_reset = TM6000_GPIO_1,
99 [TM5600_BOARD_10MOONS_UT330] = {
100 .name = "10Moons UT 330",
101 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
110 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
111 .name = "ADSTECH Dual TV USB",
112 .tuner_type = TUNER_XC2028,
122 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
123 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
124 .tuner_type = TUNER_XC2028, /* has a XC3028 */
134 .gpio_addr_tun_reset = TM6000_GPIO_4,
136 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
137 .name = "ADSTECH Mini Dual TV USB",
138 .tuner_type = TUNER_XC2028, /* has a XC3028 */
147 .gpio_addr_tun_reset = TM6000_GPIO_4,
151 /* table of devices that work with this driver */
152 struct usb_device_id tm6000_id_table [] = {
153 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
154 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
155 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
156 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
160 static void tm6000_config_tuner (struct tm6000_core *dev)
162 struct v4l2_priv_tun_config xc2028_cfg;
163 struct xc2028_ctrl ctl;
165 memset (&ctl,0,sizeof(ctl));
167 request_module ("tuner");
169 if (dev->tuner_type == TUNER_XC2028) {
170 ctl.fname = "tm6000-xc3028.fw";
173 xc2028_cfg.tuner = TUNER_XC2028;
174 xc2028_cfg.priv = &ctl;
176 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
178 tm6000_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
182 static int tm6000_init_dev(struct tm6000_core *dev)
184 struct v4l2_frequency f;
187 mutex_init(&dev->lock);
189 mutex_lock(&dev->lock);
191 /* Initializa board-specific data */
192 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
193 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
194 dev->tuner_reset_gpio = tm6000_boards[dev->model].gpio_addr_tun_reset;
196 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
198 dev->caps = tm6000_boards[dev->model].caps;
200 /* initialize hardware */
201 rc=tm6000_init (dev);
205 /* register i2c bus */
206 rc=tm6000_i2c_register(dev);
210 /* register and initialize V4L2 */
211 rc=tm6000_v4l2_register(dev);
215 /* Default values for STD and resolutions */
218 dev->norm = V4L2_STD_PAL_M;
220 /* Configure tuner */
221 tm6000_config_tuner (dev);
223 /* Set video standard */
224 tm6000_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
226 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
228 f.type = V4L2_TUNER_ANALOG_TV;
229 f.frequency = 3092; /* 193.25 MHz */
230 dev->freq = f.frequency;
231 tm6000_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
233 if(dev->caps.has_dvb) {
234 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
239 #ifdef CONFIG_VIDEO_TM6000_DVB
240 rc = tm6000_dvb_register(dev);
249 mutex_unlock(&dev->lock);
253 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
254 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
256 static void get_max_endpoint ( struct usb_device *usbdev,
258 struct usb_host_endpoint *curr_e,
259 unsigned int *maxsize,
260 struct usb_host_endpoint **ep )
262 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
263 unsigned int size = tmp & 0x7ff;
265 if (usbdev->speed == USB_SPEED_HIGH)
266 size = size * hb_mult (tmp);
271 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
272 msgtype, curr_e->desc.bEndpointAddress,
279 * checks for supported devices
281 static int tm6000_usb_probe(struct usb_interface *interface,
282 const struct usb_device_id *id)
284 struct usb_device *usbdev;
285 struct tm6000_core *dev = NULL;
291 usbdev=usb_get_dev(interface_to_usbdev(interface));
293 /* Selects the proper interface */
294 rc=usb_set_interface(usbdev,0,1);
298 /* Check to see next free device and mark as used */
299 nr=find_first_zero_bit(&tm6000_devused,TM6000_MAXBOARDS);
300 if (nr >= TM6000_MAXBOARDS) {
301 printk ("tm6000: Supports only %i em28xx boards.\n",TM6000_MAXBOARDS);
306 /* Create and initialize dev struct */
307 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
309 printk ("tm6000" ": out of memory!\n");
313 spin_lock_init(&dev->slock);
315 /* Increment usage count */
316 tm6000_devused|=1<<nr;
317 snprintf(dev->name, 29, "tm6000 #%d", nr);
319 dev->model=id->driver_info;
320 if ((card[nr]>=0) && (card[nr]<ARRAY_SIZE(tm6000_boards))) {
324 INIT_LIST_HEAD(&dev->tm6000_corelist);
328 switch (usbdev->speed) {
332 case USB_SPEED_UNKNOWN:
346 for (i = 0; i < interface->num_altsetting; i++) {
349 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
350 struct usb_host_endpoint *e;
353 e = &interface->altsetting[i].endpoint[ep];
355 dir_out = ((e->desc.bEndpointAddress &
356 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
358 printk("tm6000: alt %d, interface %i, class %i\n",
360 interface->altsetting[i].desc.bInterfaceNumber,
361 interface->altsetting[i].desc.bInterfaceClass);
363 switch (e->desc.bmAttributes) {
364 case USB_ENDPOINT_XFER_BULK:
366 get_max_endpoint (usbdev, "Bulk IN", e,
370 get_max_endpoint (usbdev, "Bulk OUT", e,
375 case USB_ENDPOINT_XFER_ISOC:
377 get_max_endpoint (usbdev, "ISOC IN", e,
381 get_max_endpoint (usbdev, "ISOC OUT", e,
390 if (interface->altsetting->desc.bAlternateSetting) {
391 printk("selecting alt setting %d\n",
392 interface->altsetting->desc.bAlternateSetting);
393 rc = usb_set_interface (usbdev,
394 interface->altsetting->desc.bInterfaceNumber,
395 interface->altsetting->desc.bAlternateSetting);
400 printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
402 le16_to_cpu(dev->udev->descriptor.idVendor),
403 le16_to_cpu(dev->udev->descriptor.idProduct),
404 interface->altsetting->desc.bInterfaceNumber);
406 /* check if the the device has the iso in endpoint at the correct place */
408 printk("tm6000: probing error: no IN ISOC endpoint!\n");
414 /* save our data pointer in this interface device */
415 usb_set_intfdata(interface, dev);
417 printk("tm6000: Found %s\n", tm6000_boards[dev->model].name);
419 rc=tm6000_init_dev(dev);
427 tm6000_devused&=~(1<<nr);
435 * tm6000_usb_disconnect()
436 * called when the device gets diconencted
437 * video device will be unregistered on v4l2_close in case it is still open
439 static void tm6000_usb_disconnect(struct usb_interface *interface)
441 struct tm6000_core *dev = usb_get_intfdata(interface);
442 usb_set_intfdata(interface, NULL);
447 printk("tm6000: disconnecting %s\n", dev->name);
449 mutex_lock(&dev->lock);
451 #ifdef CONFIG_VIDEO_TM6000_DVB
453 tm6000_dvb_unregister(dev);
458 tm6000_v4l2_unregister(dev);
460 tm6000_i2c_unregister(dev);
462 // wake_up_interruptible_all(&dev->open);
464 dev->state |= DEV_DISCONNECTED;
466 usb_put_dev(dev->udev);
468 mutex_unlock(&dev->lock);
472 static struct usb_driver tm6000_usb_driver = {
474 .probe = tm6000_usb_probe,
475 .disconnect = tm6000_usb_disconnect,
476 .id_table = tm6000_id_table,
479 static int __init tm6000_module_init(void)
483 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
484 (TM6000_VERSION >> 16) & 0xff,
485 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
487 /* register this driver with the USB subsystem */
488 result = usb_register(&tm6000_usb_driver);
491 " usb_register failed. Error number %d.\n", result);
496 static void __exit tm6000_module_exit(void)
498 /* deregister at USB subsystem */
499 usb_deregister(&tm6000_usb_driver);
502 module_init(tm6000_module_init);
503 module_exit(tm6000_module_exit);
505 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000 USB2 adapter");
506 MODULE_AUTHOR("Mauro Carvalho Chehab");
507 MODULE_LICENSE("GPL");