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>
32 #define TM6000_BOARD_UNKNOWN 0
33 #define TM5600_BOARD_GENERIC 1
34 #define TM6000_BOARD_GENERIC 2
35 #define TM5600_BOARD_10MOONS_UT821 3
36 #define TM6000_BOARD_10MOONS_UT330 4
37 #define TM6000_BOARD_ADSTECH_DUAL_TV 5
39 #define TM6000_MAXBOARDS 16
40 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
42 module_param_array(card, int, NULL, 0444);
47 struct tm6000_capabilities caps;
49 int tuner_type; /* type of the tuner */
50 int tuner_addr; /* tuner address */
54 struct tm6000_board tm6000_boards[] = {
55 [TM6000_BOARD_UNKNOWN] = {
56 .name = "Unknown tm6000 video grabber",
61 [TM5600_BOARD_GENERIC] = {
62 .name = "Generic tm5600 board",
63 .tuner_type = TUNER_XC2028,
69 [TM6000_BOARD_GENERIC] = {
70 .name = "Generic tm6000 board",
71 .tuner_type = TUNER_XC2028,
78 [TM5600_BOARD_10MOONS_UT821] = {
79 .name = "10Moons UT 821",
80 .tuner_type = TUNER_XC2028,
87 [TM6000_BOARD_10MOONS_UT330] = {
88 .name = "10Moons UT 330",
89 .tuner_type = TUNER_XC2028,
98 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
99 .name = "ADSTECH Dual TV USB",
100 .tuner_type = TUNER_XC2028,
112 /* table of devices that work with this driver */
113 struct usb_device_id tm6000_id_table [] = {
114 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
115 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
119 static int tm6000_init_dev(struct tm6000_core *dev)
121 struct v4l2_frequency f;
124 mutex_init(&dev->lock);
126 mutex_lock(&dev->lock);
128 /* Initializa board-specific data */
129 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
130 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
132 dev->caps = tm6000_boards[dev->model].caps;
134 /* initialize hardware */
135 rc=tm6000_init (dev);
139 /* register i2c bus */
140 rc=tm6000_i2c_register(dev);
144 /* register and initialize V4L2 */
145 rc=tm6000_v4l2_register(dev);
150 request_module ("tuner");
151 // norm=V4L2_STD_NTSC_M;
152 dev->norm=V4L2_STD_PAL_M;
153 tm6000_i2c_call_clients(dev, VIDIOC_S_STD, &dev->norm);
155 /* configure tuner */
157 f.type = V4L2_TUNER_ANALOG_TV;
158 f.frequency = 3092; /* 193.25 MHz */
159 dev->freq = f.frequency;
161 tm6000_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
164 mutex_unlock(&dev->lock);
168 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
169 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
171 static void get_max_endpoint ( struct usb_device *usbdev,
173 struct usb_host_endpoint *curr_e,
174 unsigned int *maxsize,
175 struct usb_host_endpoint **ep )
177 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
178 unsigned int size = tmp & 0x7ff;
180 if (usbdev->speed == USB_SPEED_HIGH)
181 size = size * hb_mult (tmp);
186 printk("tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
187 msgtype, curr_e->desc.bEndpointAddress,
194 * checks for supported devices
196 static int tm6000_usb_probe(struct usb_interface *interface,
197 const struct usb_device_id *id)
199 struct usb_device *usbdev;
200 struct tm6000_core *dev = NULL;
206 usbdev=usb_get_dev(interface_to_usbdev(interface));
208 /* Selects the proper interface */
209 rc=usb_set_interface(usbdev,0,1);
213 /* Check to see next free device and mark as used */
214 nr=find_first_zero_bit(&tm6000_devused,TM6000_MAXBOARDS);
215 if (nr >= TM6000_MAXBOARDS) {
216 printk ("tm6000: Supports only %i em28xx boards.\n",TM6000_MAXBOARDS);
221 /* Create and initialize dev struct */
222 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
224 printk ("tm6000" ": out of memory!\n");
228 spin_lock_init(&dev->slock);
230 /* Increment usage count */
231 tm6000_devused|=1<<nr;
233 INIT_LIST_HEAD(&dev->tm6000_corelist);
235 dev->model=id->driver_info;
236 snprintf(dev->name, 29, "tm6000 #%d", nr);
239 switch (usbdev->speed) {
243 case USB_SPEED_UNKNOWN:
257 for (i = 0; i < interface->num_altsetting; i++) {
260 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
261 struct usb_host_endpoint *e;
264 e = &interface->altsetting[i].endpoint[ep];
266 dir_out = ((e->desc.bEndpointAddress &
267 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
269 printk("tm6000: alt %d, interface %i, class %i\n",
271 interface->altsetting[i].desc.bInterfaceNumber,
272 interface->altsetting[i].desc.bInterfaceClass);
274 switch (e->desc.bmAttributes) {
275 case USB_ENDPOINT_XFER_BULK:
277 get_max_endpoint (usbdev, "Bulk IN", e,
281 get_max_endpoint (usbdev, "Bulk OUT", e,
286 case USB_ENDPOINT_XFER_ISOC:
288 get_max_endpoint (usbdev, "ISOC IN", e,
292 get_max_endpoint (usbdev, "ISOC OUT", e,
301 if (interface->altsetting->desc.bAlternateSetting) {
302 printk("selecting alt setting %d\n",
303 interface->altsetting->desc.bAlternateSetting);
304 rc = usb_set_interface (usbdev,
305 interface->altsetting->desc.bInterfaceNumber,
306 interface->altsetting->desc.bAlternateSetting);
311 printk("tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
313 le16_to_cpu(dev->udev->descriptor.idVendor),
314 le16_to_cpu(dev->udev->descriptor.idProduct),
315 interface->altsetting->desc.bInterfaceNumber);
317 /* check if the the device has the iso in endpoint at the correct place */
319 printk("tm6000: probing error: no IN ISOC endpoint!\n");
325 /* save our data pointer in this interface device */
326 usb_set_intfdata(interface, dev);
328 printk("tm6000: Found %s\n", tm6000_boards[dev->model].name);
330 rc=tm6000_init_dev(dev);
338 tm6000_devused&=~(1<<nr);
346 * tm6000_usb_disconnect()
347 * called when the device gets diconencted
348 * video device will be unregistered on v4l2_close in case it is still open
350 static void tm6000_usb_disconnect(struct usb_interface *interface)
352 struct tm6000_core *dev = usb_get_intfdata(interface);
353 usb_set_intfdata(interface, NULL);
358 printk("tm6000: disconnecting %s\n", dev->name);
360 mutex_lock(&dev->lock);
362 tm6000_i2c_unregister(dev);
364 tm6000_v4l2_unregister(dev);
366 // wake_up_interruptible_all(&dev->open);
368 dev->state |= DEV_DISCONNECTED;
370 mutex_unlock(&dev->lock);
374 static struct usb_driver tm6000_usb_driver = {
376 .probe = tm6000_usb_probe,
377 .disconnect = tm6000_usb_disconnect,
378 .id_table = tm6000_id_table,
381 static int __init tm6000_module_init(void)
385 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
386 (TM6000_VERSION >> 16) & 0xff,
387 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
389 /* register this driver with the USB subsystem */
390 result = usb_register(&tm6000_usb_driver);
393 " usb_register failed. Error number %d.\n", result);
398 static void __exit tm6000_module_exit(void)
400 /* deregister at USB subsystem */
401 usb_deregister(&tm6000_usb_driver);
404 module_init(tm6000_module_init);
405 module_exit(tm6000_module_exit);
407 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000 USB2 adapter");
408 MODULE_AUTHOR("Mauro Carvalho Chehab");
409 MODULE_LICENSE("GPL");