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"
33 #define TM6000_BOARD_UNKNOWN 0
34 #define TM5600_BOARD_GENERIC 1
35 #define TM6000_BOARD_GENERIC 2
36 #define TM5600_BOARD_10MOONS_UT821 3
37 #define TM5600_BOARD_10MOONS_UT330 4
38 #define TM6000_BOARD_ADSTECH_DUAL_TV 5
39 #define TM6000_BOARD_FREECOM_AND_SIMILAR 6
41 #define TM6000_MAXBOARDS 16
42 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
44 module_param_array(card, int, NULL, 0444);
50 struct tm6000_capabilities caps;
52 int tuner_type; /* type of the tuner */
53 int tuner_addr; /* tuner address */
54 int demod_addr; /* demodulator address */
55 int gpio_addr_tun_reset; /* GPIO used for tuner reset */
59 struct tm6000_board tm6000_boards[] = {
60 [TM6000_BOARD_UNKNOWN] = {
61 .name = "Unknown tm6000 video grabber",
65 .gpio_addr_tun_reset = TM6000_GPIO_1,
67 [TM5600_BOARD_GENERIC] = {
68 .name = "Generic tm5600 board",
69 .tuner_type = TUNER_XC2028,
74 .gpio_addr_tun_reset = TM6000_GPIO_1,
76 [TM6000_BOARD_GENERIC] = {
77 .name = "Generic tm6000 board",
78 .tuner_type = TUNER_XC2028,
84 .gpio_addr_tun_reset = TM6000_GPIO_1,
86 [TM5600_BOARD_10MOONS_UT821] = {
87 .name = "10Moons UT 821",
88 .tuner_type = TUNER_XC2028,
94 .gpio_addr_tun_reset = TM6000_GPIO_1,
96 [TM5600_BOARD_10MOONS_UT330] = {
97 .name = "10Moons UT 330",
98 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
107 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
108 .name = "ADSTECH Dual TV USB",
109 .tuner_type = TUNER_XC2028,
119 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
120 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
121 .tuner_type = TUNER_XC2028,
130 .gpio_addr_tun_reset = TM6000_GPIO_4,
134 /* table of devices that work with this driver */
135 struct usb_device_id tm6000_id_table [] = {
136 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
137 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
138 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
142 static int tm6000_init_dev(struct tm6000_core *dev)
144 struct v4l2_frequency f;
147 mutex_init(&dev->lock);
149 mutex_lock(&dev->lock);
151 /* Initializa board-specific data */
152 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
153 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
154 dev->tuner_reset_gpio = tm6000_boards[dev->model].gpio_addr_tun_reset;
156 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
158 dev->caps = tm6000_boards[dev->model].caps;
160 /* initialize hardware */
161 rc=tm6000_init (dev);
165 /* register i2c bus */
166 rc=tm6000_i2c_register(dev);
170 /* register and initialize V4L2 */
171 rc=tm6000_v4l2_register(dev);
176 request_module ("tuner");
177 // norm=V4L2_STD_NTSC_M;
178 dev->norm=V4L2_STD_PAL_M;
179 tm6000_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
181 /* configure tuner */
183 f.type = V4L2_TUNER_ANALOG_TV;
184 f.frequency = 3092; /* 193.25 MHz */
185 dev->freq = f.frequency;
187 tm6000_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
188 if(dev->caps.has_dvb) {
189 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
194 #ifdef CONFIG_VIDEO_TM6000_DVB
195 rc = tm6000_dvb_register(dev);
204 mutex_unlock(&dev->lock);
208 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
209 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
211 static void get_max_endpoint ( struct usb_device *usbdev,
213 struct usb_host_endpoint *curr_e,
214 unsigned int *maxsize,
215 struct usb_host_endpoint **ep )
217 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
218 unsigned int size = tmp & 0x7ff;
220 if (usbdev->speed == USB_SPEED_HIGH)
221 size = size * hb_mult (tmp);
226 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
227 msgtype, curr_e->desc.bEndpointAddress,
234 * checks for supported devices
236 static int tm6000_usb_probe(struct usb_interface *interface,
237 const struct usb_device_id *id)
239 struct usb_device *usbdev;
240 struct tm6000_core *dev = NULL;
246 usbdev=usb_get_dev(interface_to_usbdev(interface));
248 /* Selects the proper interface */
249 rc=usb_set_interface(usbdev,0,1);
253 /* Check to see next free device and mark as used */
254 nr=find_first_zero_bit(&tm6000_devused,TM6000_MAXBOARDS);
255 if (nr >= TM6000_MAXBOARDS) {
256 printk ("tm6000: Supports only %i em28xx boards.\n",TM6000_MAXBOARDS);
261 /* Create and initialize dev struct */
262 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
264 printk ("tm6000" ": out of memory!\n");
268 spin_lock_init(&dev->slock);
270 /* Increment usage count */
271 tm6000_devused|=1<<nr;
272 snprintf(dev->name, 29, "tm6000 #%d", nr);
274 dev->model=id->driver_info;
275 if ((card[nr]>=0) && (card[nr]<ARRAY_SIZE(tm6000_boards))) {
279 INIT_LIST_HEAD(&dev->tm6000_corelist);
283 switch (usbdev->speed) {
287 case USB_SPEED_UNKNOWN:
301 for (i = 0; i < interface->num_altsetting; i++) {
304 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
305 struct usb_host_endpoint *e;
308 e = &interface->altsetting[i].endpoint[ep];
310 dir_out = ((e->desc.bEndpointAddress &
311 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
313 printk("tm6000: alt %d, interface %i, class %i\n",
315 interface->altsetting[i].desc.bInterfaceNumber,
316 interface->altsetting[i].desc.bInterfaceClass);
318 switch (e->desc.bmAttributes) {
319 case USB_ENDPOINT_XFER_BULK:
321 get_max_endpoint (usbdev, "Bulk IN", e,
325 get_max_endpoint (usbdev, "Bulk OUT", e,
330 case USB_ENDPOINT_XFER_ISOC:
332 get_max_endpoint (usbdev, "ISOC IN", e,
336 get_max_endpoint (usbdev, "ISOC OUT", e,
345 if (interface->altsetting->desc.bAlternateSetting) {
346 printk("selecting alt setting %d\n",
347 interface->altsetting->desc.bAlternateSetting);
348 rc = usb_set_interface (usbdev,
349 interface->altsetting->desc.bInterfaceNumber,
350 interface->altsetting->desc.bAlternateSetting);
355 printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
357 le16_to_cpu(dev->udev->descriptor.idVendor),
358 le16_to_cpu(dev->udev->descriptor.idProduct),
359 interface->altsetting->desc.bInterfaceNumber);
361 /* check if the the device has the iso in endpoint at the correct place */
363 printk("tm6000: probing error: no IN ISOC endpoint!\n");
369 /* save our data pointer in this interface device */
370 usb_set_intfdata(interface, dev);
372 printk("tm6000: Found %s\n", tm6000_boards[dev->model].name);
374 rc=tm6000_init_dev(dev);
382 tm6000_devused&=~(1<<nr);
390 * tm6000_usb_disconnect()
391 * called when the device gets diconencted
392 * video device will be unregistered on v4l2_close in case it is still open
394 static void tm6000_usb_disconnect(struct usb_interface *interface)
396 struct tm6000_core *dev = usb_get_intfdata(interface);
397 usb_set_intfdata(interface, NULL);
402 printk("tm6000: disconnecting %s\n", dev->name);
404 mutex_lock(&dev->lock);
406 #ifdef CONFIG_VIDEO_TM6000_DVB
408 tm6000_dvb_unregister(dev);
413 tm6000_v4l2_unregister(dev);
415 tm6000_i2c_unregister(dev);
417 // wake_up_interruptible_all(&dev->open);
419 dev->state |= DEV_DISCONNECTED;
421 usb_put_dev(dev->udev);
423 mutex_unlock(&dev->lock);
427 static struct usb_driver tm6000_usb_driver = {
429 .probe = tm6000_usb_probe,
430 .disconnect = tm6000_usb_disconnect,
431 .id_table = tm6000_id_table,
434 static int __init tm6000_module_init(void)
438 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
439 (TM6000_VERSION >> 16) & 0xff,
440 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
442 /* register this driver with the USB subsystem */
443 result = usb_register(&tm6000_usb_driver);
446 " usb_register failed. Error number %d.\n", result);
451 static void __exit tm6000_module_exit(void)
453 /* deregister at USB subsystem */
454 usb_deregister(&tm6000_usb_driver);
457 module_init(tm6000_module_init);
458 module_exit(tm6000_module_exit);
460 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000 USB2 adapter");
461 MODULE_AUTHOR("Mauro Carvalho Chehab");
462 MODULE_LICENSE("GPL");