2 * tm6000-video.c - driver for TM5600/TM6000/TM6010 USB video capture devices
4 * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
6 * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
7 * - Fixed module load/unload
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation version 2
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/delay.h>
21 #include <linux/errno.h>
23 #include <linux/kernel.h>
24 #include <linux/slab.h>
26 #include <linux/ioport.h>
27 #include <linux/init.h>
28 #include <linux/sched.h>
29 #include <linux/random.h>
30 #include <linux/usb.h>
31 #include <linux/videodev2.h>
32 #include <media/v4l2-ioctl.h>
33 #include <media/v4l2-event.h>
34 #include <media/tuner.h>
35 #include <linux/interrupt.h>
36 #include <linux/kthread.h>
37 #include <linux/highmem.h>
38 #include <linux/freezer.h>
40 #include "tm6000-regs.h"
43 #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
45 /* Limits minimum and default number of buffers */
46 #define TM6000_MIN_BUF 4
47 #define TM6000_DEF_BUF 8
49 #define TM6000_NUM_URB_BUF 8
51 #define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
53 /* Declare static vars that will be used as parameters */
54 static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
55 static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
56 static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */
57 static bool keep_urb; /* keep urb buffers allocated */
61 EXPORT_SYMBOL_GPL(tm6000_debug);
63 static struct tm6000_fmt format[] = {
65 .name = "4:2:2, packed, YVY2",
66 .fourcc = V4L2_PIX_FMT_YUYV,
69 .name = "4:2:2, packed, UYVY",
70 .fourcc = V4L2_PIX_FMT_UYVY,
73 .name = "A/V + VBI mux packet",
74 .fourcc = V4L2_PIX_FMT_TM6000,
79 /* ------------------------------------------------------------------
80 * DMA and thread functions
81 * ------------------------------------------------------------------
84 #define norm_maxw(a) 720
85 #define norm_maxh(a) 576
87 #define norm_minw(a) norm_maxw(a)
88 #define norm_minh(a) norm_maxh(a)
91 * video-buf generic routine to get the next available buffer
93 static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
94 struct tm6000_buffer **buf)
96 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
98 if (list_empty(&dma_q->active)) {
99 dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
104 *buf = list_entry(dma_q->active.next,
105 struct tm6000_buffer, vb.queue);
109 * Announces that a buffer were filled and request the next
111 static inline void buffer_filled(struct tm6000_core *dev,
112 struct tm6000_dmaqueue *dma_q,
113 struct tm6000_buffer *buf)
115 /* Advice that buffer was filled */
116 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
117 buf->vb.state = VIDEOBUF_DONE;
118 buf->vb.field_count++;
119 v4l2_get_timestamp(&buf->vb.ts);
121 list_del(&buf->vb.queue);
122 wake_up(&buf->vb.done);
126 * Identify the tm5600/6000 buffer header type and properly handles
128 static int copy_streams(u8 *data, unsigned long len,
131 struct tm6000_dmaqueue *dma_q = urb->context;
132 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
133 u8 *ptr = data, *endp = data+len;
134 unsigned long header = 0;
136 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
137 struct tm6000_buffer *vbuf = NULL;
139 unsigned int linewidth;
142 /* get video buffer */
143 get_next_buf(dma_q, &vbuf);
147 voutp = videobuf_to_vmalloc(&vbuf->vb);
153 for (ptr = data; ptr < endp;) {
154 if (!dev->isoc_ctl.cmd) {
156 if (dev->isoc_ctl.tmp_buf_len > 0) {
157 /* from last urb or packet */
158 header = dev->isoc_ctl.tmp_buf;
159 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
160 memcpy((u8 *)&header +
161 dev->isoc_ctl.tmp_buf_len,
163 4 - dev->isoc_ctl.tmp_buf_len);
164 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
166 dev->isoc_ctl.tmp_buf_len = 0;
168 if (ptr + 3 >= endp) {
169 /* have incomplete header */
170 dev->isoc_ctl.tmp_buf_len = endp - ptr;
171 memcpy(&dev->isoc_ctl.tmp_buf, ptr,
172 dev->isoc_ctl.tmp_buf_len);
176 for (; ptr < endp - 3; ptr++) {
177 if (*(ptr + 3) == 0x47)
180 /* Get message header */
181 header = *(unsigned long *)ptr;
185 /* split the header fields */
186 size = ((header & 0x7e) << 1);
189 block = (header >> 7) & 0xf;
190 field = (header >> 11) & 0x1;
191 line = (header >> 12) & 0x1ff;
192 cmd = (header >> 21) & 0x7;
193 /* Validates haeder fields */
194 if (size > TM6000_URB_MSG_LEN)
195 size = TM6000_URB_MSG_LEN;
196 pktsize = TM6000_URB_MSG_LEN;
198 * calculate position in buffer and change the buffer
201 case TM6000_URB_MSG_VIDEO:
203 if ((dev->isoc_ctl.vfield != field) &&
206 * Announces that a new buffer
209 buffer_filled(dev, dma_q, vbuf);
210 dprintk(dev, V4L2_DEBUG_ISOC,
211 "new buffer filled\n");
212 get_next_buf(dma_q, &vbuf);
215 voutp = videobuf_to_vmalloc(&vbuf->vb);
218 memset(voutp, 0, vbuf->vb.size);
220 linewidth = vbuf->vb.width << 1;
221 pos = ((line << 1) - field - 1) *
222 linewidth + block * TM6000_URB_MSG_LEN;
223 /* Don't allow to write out of the buffer */
224 if (pos + size > vbuf->vb.size)
225 cmd = TM6000_URB_MSG_ERR;
226 dev->isoc_ctl.vfield = field;
229 case TM6000_URB_MSG_VBI:
231 case TM6000_URB_MSG_AUDIO:
232 case TM6000_URB_MSG_PTS:
233 size = pktsize; /* Size is always 180 bytes */
237 /* Continue the last copy */
238 cmd = dev->isoc_ctl.cmd;
239 size = dev->isoc_ctl.size;
240 pos = dev->isoc_ctl.pos;
241 pktsize = dev->isoc_ctl.pktsize;
242 field = dev->isoc_ctl.field;
244 cpysize = (endp - ptr > size) ? size : endp - ptr;
246 /* copy data in different buffers */
248 case TM6000_URB_MSG_VIDEO:
249 /* Fills video buffer */
251 memcpy(&voutp[pos], ptr, cpysize);
253 case TM6000_URB_MSG_AUDIO: {
255 for (i = 0; i < cpysize; i += 2)
256 swab16s((u16 *)(ptr + i));
258 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
261 case TM6000_URB_MSG_VBI:
262 /* Need some code to copy vbi buffer */
264 case TM6000_URB_MSG_PTS: {
265 /* Need some code to copy pts */
268 dprintk(dev, V4L2_DEBUG_ISOC, "field %d, PTS %x",
274 if (ptr + pktsize > endp) {
276 * End of URB packet, but cmd processing is not
277 * complete. Preserve the state for a next packet
279 dev->isoc_ctl.pos = pos + cpysize;
280 dev->isoc_ctl.size = size - cpysize;
281 dev->isoc_ctl.cmd = cmd;
282 dev->isoc_ctl.field = field;
283 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
286 dev->isoc_ctl.cmd = 0;
294 * Identify the tm5600/6000 buffer header type and properly handles
296 static int copy_multiplexed(u8 *ptr, unsigned long len,
299 struct tm6000_dmaqueue *dma_q = urb->context;
300 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
301 unsigned int pos = dev->isoc_ctl.pos, cpysize;
303 struct tm6000_buffer *buf;
306 get_next_buf(dma_q, &buf);
308 outp = videobuf_to_vmalloc(&buf->vb);
314 cpysize = min(len, buf->vb.size-pos);
315 memcpy(&outp[pos], ptr, cpysize);
319 if (pos >= buf->vb.size) {
321 /* Announces that a new buffer were filled */
322 buffer_filled(dev, dma_q, buf);
323 dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
324 get_next_buf(dma_q, &buf);
327 outp = videobuf_to_vmalloc(&(buf->vb));
334 dev->isoc_ctl.pos = pos;
338 static inline void print_err_status(struct tm6000_core *dev,
339 int packet, int status)
341 char *errmsg = "Unknown";
345 errmsg = "unlinked synchronously";
348 errmsg = "unlinked asynchronously";
351 errmsg = "Buffer error (overrun)";
354 errmsg = "Stalled (device not responding)";
357 errmsg = "Babble (bad cable?)";
360 errmsg = "Bit-stuff error (bad cable?)";
363 errmsg = "CRC/Timeout (could be anything)";
366 errmsg = "Device does not respond";
370 dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
373 dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
374 packet, status, errmsg);
380 * Controls the isoc copy of each urb packet
382 static inline int tm6000_isoc_copy(struct urb *urb)
384 struct tm6000_dmaqueue *dma_q = urb->context;
385 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
386 int i, len = 0, rc = 1, status;
389 if (urb->status < 0) {
390 print_err_status(dev, -1, urb->status);
394 for (i = 0; i < urb->number_of_packets; i++) {
395 status = urb->iso_frame_desc[i].status;
398 print_err_status(dev, i, status);
402 len = urb->iso_frame_desc[i].actual_length;
405 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
406 if (!urb->iso_frame_desc[i].status) {
407 if ((dev->fourcc) == V4L2_PIX_FMT_TM6000) {
408 rc = copy_multiplexed(p, len, urb);
412 copy_streams(p, len, urb);
420 /* ------------------------------------------------------------------
422 * ------------------------------------------------------------------
426 * IRQ callback, called by URB callback
428 static void tm6000_irq_callback(struct urb *urb)
430 struct tm6000_dmaqueue *dma_q = urb->context;
431 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
434 switch (urb->status) {
445 tm6000_err("urb completion error %d.\n", urb->status);
449 spin_lock(&dev->slock);
450 tm6000_isoc_copy(urb);
451 spin_unlock(&dev->slock);
453 /* Reset urb buffers */
454 for (i = 0; i < urb->number_of_packets; i++) {
455 urb->iso_frame_desc[i].status = 0;
456 urb->iso_frame_desc[i].actual_length = 0;
459 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
461 tm6000_err("urb resubmit failed (error=%i)\n",
466 * Allocate URB buffers
468 static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
470 int num_bufs = TM6000_NUM_URB_BUF;
476 dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
477 if (!dev->urb_buffer)
480 dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
484 for (i = 0; i < num_bufs; i++) {
485 dev->urb_buffer[i] = usb_alloc_coherent(
486 dev->udev, dev->urb_size,
487 GFP_KERNEL, &dev->urb_dma[i]);
488 if (!dev->urb_buffer[i]) {
489 tm6000_err("unable to allocate %i bytes for transfer buffer %i\n",
493 memset(dev->urb_buffer[i], 0, dev->urb_size);
502 static int tm6000_free_urb_buffers(struct tm6000_core *dev)
506 if (!dev->urb_buffer)
509 for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
510 if (dev->urb_buffer[i]) {
511 usb_free_coherent(dev->udev,
515 dev->urb_buffer[i] = NULL;
518 kfree(dev->urb_buffer);
520 dev->urb_buffer = NULL;
527 * Stop and Deallocate URBs
529 static void tm6000_uninit_isoc(struct tm6000_core *dev)
534 dev->isoc_ctl.buf = NULL;
535 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
536 urb = dev->isoc_ctl.urb[i];
541 dev->isoc_ctl.urb[i] = NULL;
543 dev->isoc_ctl.transfer_buffer[i] = NULL;
547 tm6000_free_urb_buffers(dev);
549 kfree(dev->isoc_ctl.urb);
550 kfree(dev->isoc_ctl.transfer_buffer);
552 dev->isoc_ctl.urb = NULL;
553 dev->isoc_ctl.transfer_buffer = NULL;
554 dev->isoc_ctl.num_bufs = 0;
558 * Assign URBs and start IRQ
560 static int tm6000_prepare_isoc(struct tm6000_core *dev)
562 struct tm6000_dmaqueue *dma_q = &dev->vidq;
563 int i, j, sb_size, pipe, size, max_packets;
564 int num_bufs = TM6000_NUM_URB_BUF;
567 /* De-allocates all pending stuff */
568 tm6000_uninit_isoc(dev);
569 /* Stop interrupt USB pipe */
570 tm6000_ir_int_stop(dev);
572 usb_set_interface(dev->udev,
573 dev->isoc_in.bInterfaceNumber,
574 dev->isoc_in.bAlternateSetting);
576 /* Start interrupt USB pipe */
577 tm6000_ir_int_start(dev);
579 pipe = usb_rcvisocpipe(dev->udev,
580 dev->isoc_in.endp->desc.bEndpointAddress &
581 USB_ENDPOINT_NUMBER_MASK);
583 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
585 if (size > dev->isoc_in.maxsize)
586 size = dev->isoc_in.maxsize;
588 dev->isoc_ctl.max_pkt_size = size;
590 max_packets = TM6000_MAX_ISO_PACKETS;
591 sb_size = max_packets * size;
592 dev->urb_size = sb_size;
594 dev->isoc_ctl.num_bufs = num_bufs;
596 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
597 if (!dev->isoc_ctl.urb)
600 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
602 if (!dev->isoc_ctl.transfer_buffer) {
603 kfree(dev->isoc_ctl.urb);
607 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets (%d bytes) of %d bytes each to handle %u size\n",
608 max_packets, num_bufs, sb_size,
609 dev->isoc_in.maxsize, size);
612 if (tm6000_alloc_urb_buffers(dev) < 0) {
613 tm6000_err("cannot allocate memory for urb buffers\n");
615 /* call free, as some buffers might have been allocated */
616 tm6000_free_urb_buffers(dev);
617 kfree(dev->isoc_ctl.urb);
618 kfree(dev->isoc_ctl.transfer_buffer);
622 /* allocate urbs and transfer buffers */
623 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
624 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
626 tm6000_uninit_isoc(dev);
627 tm6000_free_urb_buffers(dev);
630 dev->isoc_ctl.urb[i] = urb;
632 urb->transfer_dma = dev->urb_dma[i];
633 dev->isoc_ctl.transfer_buffer[i] = dev->urb_buffer[i];
635 usb_fill_bulk_urb(urb, dev->udev, pipe,
636 dev->isoc_ctl.transfer_buffer[i], sb_size,
637 tm6000_irq_callback, dma_q);
638 urb->interval = dev->isoc_in.endp->desc.bInterval;
639 urb->number_of_packets = max_packets;
640 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
642 for (j = 0; j < max_packets; j++) {
643 urb->iso_frame_desc[j].offset = size * j;
644 urb->iso_frame_desc[j].length = size;
651 static int tm6000_start_thread(struct tm6000_core *dev)
653 struct tm6000_dmaqueue *dma_q = &dev->vidq;
657 dma_q->ini_jiffies = jiffies;
659 init_waitqueue_head(&dma_q->wq);
661 /* submit urbs and enables IRQ */
662 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
663 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
665 tm6000_err("submit of urb %i failed (error=%i)\n", i,
667 tm6000_uninit_isoc(dev);
675 /* ------------------------------------------------------------------
676 * Videobuf operations
677 * ------------------------------------------------------------------
681 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
683 struct tm6000_fh *fh = vq->priv_data;
685 *size = fh->fmt->depth * fh->width * fh->height >> 3;
687 *count = TM6000_DEF_BUF;
689 if (*count < TM6000_MIN_BUF)
690 *count = TM6000_MIN_BUF;
692 while (*size * *count > vid_limit * 1024 * 1024)
698 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
700 struct tm6000_fh *fh = vq->priv_data;
701 struct tm6000_core *dev = fh->dev;
704 BUG_ON(in_interrupt());
706 /* We used to wait for the buffer to finish here, but this didn't work
707 because, as we were keeping the state as VIDEOBUF_QUEUED,
708 videobuf_queue_cancel marked it as finished for us.
709 (Also, it could wedge forever if the hardware was misconfigured.)
711 This should be safe; by the time we get here, the buffer isn't
712 queued anymore. If we ever start marking the buffers as
713 VIDEOBUF_ACTIVE, it won't be, though.
715 spin_lock_irqsave(&dev->slock, flags);
716 if (dev->isoc_ctl.buf == buf)
717 dev->isoc_ctl.buf = NULL;
718 spin_unlock_irqrestore(&dev->slock, flags);
720 videobuf_vmalloc_free(&buf->vb);
721 buf->vb.state = VIDEOBUF_NEEDS_INIT;
725 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
726 enum v4l2_field field)
728 struct tm6000_fh *fh = vq->priv_data;
729 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
730 struct tm6000_core *dev = fh->dev;
733 BUG_ON(NULL == fh->fmt);
736 /* FIXME: It assumes depth=2 */
737 /* The only currently supported format is 16 bits/pixel */
738 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
739 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
742 if (buf->fmt != fh->fmt ||
743 buf->vb.width != fh->width ||
744 buf->vb.height != fh->height ||
745 buf->vb.field != field) {
747 buf->vb.width = fh->width;
748 buf->vb.height = fh->height;
749 buf->vb.field = field;
750 buf->vb.state = VIDEOBUF_NEEDS_INIT;
753 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
754 rc = videobuf_iolock(vq, &buf->vb, NULL);
759 if (!dev->isoc_ctl.num_bufs) {
760 rc = tm6000_prepare_isoc(dev);
764 rc = tm6000_start_thread(dev);
770 buf->vb.state = VIDEOBUF_PREPARED;
774 free_buffer(vq, buf);
779 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
781 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
782 struct tm6000_fh *fh = vq->priv_data;
783 struct tm6000_core *dev = fh->dev;
784 struct tm6000_dmaqueue *vidq = &dev->vidq;
786 buf->vb.state = VIDEOBUF_QUEUED;
787 list_add_tail(&buf->vb.queue, &vidq->active);
790 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
792 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
794 free_buffer(vq, buf);
797 static const struct videobuf_queue_ops tm6000_video_qops = {
798 .buf_setup = buffer_setup,
799 .buf_prepare = buffer_prepare,
800 .buf_queue = buffer_queue,
801 .buf_release = buffer_release,
804 /* ------------------------------------------------------------------
806 * ------------------------------------------------------------------
809 static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
811 /* Is the current fh handling it? if so, that's OK */
812 if (dev->resources == fh && dev->is_res_read)
818 static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
820 /* Is the current fh handling it? if so, that's OK */
821 if (dev->resources == fh)
827 static bool res_get(struct tm6000_core *dev, struct tm6000_fh *fh,
830 /* Is the current fh handling it? if so, that's OK */
831 if (dev->resources == fh && dev->is_res_read == is_res_read)
840 dev->is_res_read = is_res_read;
841 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
845 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
847 /* Is the current fh handling it? if so, that's OK */
848 if (dev->resources != fh)
851 dev->resources = NULL;
852 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
855 /* ------------------------------------------------------------------
856 * IOCTL vidioc handling
857 * ------------------------------------------------------------------
859 static int vidioc_querycap(struct file *file, void *priv,
860 struct v4l2_capability *cap)
862 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
863 struct video_device *vdev = video_devdata(file);
865 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
866 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
867 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
868 if (dev->tuner_type != TUNER_ABSENT)
869 cap->device_caps |= V4L2_CAP_TUNER;
870 if (vdev->vfl_type == VFL_TYPE_GRABBER)
871 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
875 cap->device_caps |= V4L2_CAP_RADIO;
876 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
877 V4L2_CAP_RADIO | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
882 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
883 struct v4l2_fmtdesc *f)
885 if (f->index >= ARRAY_SIZE(format))
888 strlcpy(f->description, format[f->index].name, sizeof(f->description));
889 f->pixelformat = format[f->index].fourcc;
893 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
894 struct v4l2_format *f)
896 struct tm6000_fh *fh = priv;
898 f->fmt.pix.width = fh->width;
899 f->fmt.pix.height = fh->height;
900 f->fmt.pix.field = fh->vb_vidq.field;
901 f->fmt.pix.pixelformat = fh->fmt->fourcc;
902 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
903 f->fmt.pix.bytesperline =
904 (f->fmt.pix.width * fh->fmt->depth) >> 3;
905 f->fmt.pix.sizeimage =
906 f->fmt.pix.height * f->fmt.pix.bytesperline;
911 static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
915 for (i = 0; i < ARRAY_SIZE(format); i++)
916 if (format[i].fourcc == fourcc)
921 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
922 struct v4l2_format *f)
924 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
925 struct tm6000_fmt *fmt;
926 enum v4l2_field field;
928 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
930 dprintk(dev, 2, "Fourcc format (0x%08x) invalid.\n",
931 f->fmt.pix.pixelformat);
935 field = f->fmt.pix.field;
937 field = V4L2_FIELD_INTERLACED;
939 tm6000_get_std_res(dev);
941 f->fmt.pix.width = dev->width;
942 f->fmt.pix.height = dev->height;
944 f->fmt.pix.width &= ~0x01;
946 f->fmt.pix.field = field;
948 f->fmt.pix.bytesperline =
949 (f->fmt.pix.width * fmt->depth) >> 3;
950 f->fmt.pix.sizeimage =
951 f->fmt.pix.height * f->fmt.pix.bytesperline;
952 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
957 /*FIXME: This seems to be generic enough to be at videodev2 */
958 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
959 struct v4l2_format *f)
961 struct tm6000_fh *fh = priv;
962 struct tm6000_core *dev = fh->dev;
963 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
967 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
968 fh->width = f->fmt.pix.width;
969 fh->height = f->fmt.pix.height;
970 fh->vb_vidq.field = f->fmt.pix.field;
973 dev->fourcc = f->fmt.pix.pixelformat;
975 tm6000_set_fourcc_format(dev);
980 static int vidioc_reqbufs(struct file *file, void *priv,
981 struct v4l2_requestbuffers *p)
983 struct tm6000_fh *fh = priv;
985 return videobuf_reqbufs(&fh->vb_vidq, p);
988 static int vidioc_querybuf(struct file *file, void *priv,
989 struct v4l2_buffer *p)
991 struct tm6000_fh *fh = priv;
993 return videobuf_querybuf(&fh->vb_vidq, p);
996 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
998 struct tm6000_fh *fh = priv;
1000 return videobuf_qbuf(&fh->vb_vidq, p);
1003 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1005 struct tm6000_fh *fh = priv;
1007 return videobuf_dqbuf(&fh->vb_vidq, p,
1008 file->f_flags & O_NONBLOCK);
1011 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1013 struct tm6000_fh *fh = priv;
1014 struct tm6000_core *dev = fh->dev;
1016 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1021 if (!res_get(dev, fh, false))
1023 return videobuf_streamon(&fh->vb_vidq);
1026 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1028 struct tm6000_fh *fh = priv;
1029 struct tm6000_core *dev = fh->dev;
1031 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1037 videobuf_streamoff(&fh->vb_vidq);
1043 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1046 struct tm6000_fh *fh = priv;
1047 struct tm6000_core *dev = fh->dev;
1050 rc = tm6000_init_analog_mode(dev);
1052 fh->width = dev->width;
1053 fh->height = dev->height;
1058 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, dev->norm);
1063 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1065 struct tm6000_fh *fh = priv;
1066 struct tm6000_core *dev = fh->dev;
1072 static const char *iname[] = {
1073 [TM6000_INPUT_TV] = "Television",
1074 [TM6000_INPUT_COMPOSITE1] = "Composite 1",
1075 [TM6000_INPUT_COMPOSITE2] = "Composite 2",
1076 [TM6000_INPUT_SVIDEO] = "S-Video",
1079 static int vidioc_enum_input(struct file *file, void *priv,
1080 struct v4l2_input *i)
1082 struct tm6000_fh *fh = priv;
1083 struct tm6000_core *dev = fh->dev;
1090 if (!dev->vinput[n].type)
1095 if (dev->vinput[n].type == TM6000_INPUT_TV)
1096 i->type = V4L2_INPUT_TYPE_TUNER;
1098 i->type = V4L2_INPUT_TYPE_CAMERA;
1100 strcpy(i->name, iname[dev->vinput[n].type]);
1102 i->std = TM6000_STD;
1107 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1109 struct tm6000_fh *fh = priv;
1110 struct tm6000_core *dev = fh->dev;
1117 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1119 struct tm6000_fh *fh = priv;
1120 struct tm6000_core *dev = fh->dev;
1125 if (!dev->vinput[i].type)
1130 rc = vidioc_s_std(file, priv, dev->norm);
1135 /* --- controls ---------------------------------------------- */
1137 static int tm6000_s_ctrl(struct v4l2_ctrl *ctrl)
1139 struct tm6000_core *dev = container_of(ctrl->handler, struct tm6000_core, ctrl_handler);
1143 case V4L2_CID_CONTRAST:
1144 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1146 case V4L2_CID_BRIGHTNESS:
1147 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1149 case V4L2_CID_SATURATION:
1150 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1153 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1159 static const struct v4l2_ctrl_ops tm6000_ctrl_ops = {
1160 .s_ctrl = tm6000_s_ctrl,
1163 static int tm6000_radio_s_ctrl(struct v4l2_ctrl *ctrl)
1165 struct tm6000_core *dev = container_of(ctrl->handler,
1166 struct tm6000_core, radio_ctrl_handler);
1170 case V4L2_CID_AUDIO_MUTE:
1171 dev->ctl_mute = val;
1172 tm6000_tvaudio_set_mute(dev, val);
1174 case V4L2_CID_AUDIO_VOLUME:
1175 dev->ctl_volume = val;
1176 tm6000_set_volume(dev, val);
1182 static const struct v4l2_ctrl_ops tm6000_radio_ctrl_ops = {
1183 .s_ctrl = tm6000_radio_s_ctrl,
1186 static int vidioc_g_tuner(struct file *file, void *priv,
1187 struct v4l2_tuner *t)
1189 struct tm6000_fh *fh = priv;
1190 struct tm6000_core *dev = fh->dev;
1192 if (UNSET == dev->tuner_type)
1197 strcpy(t->name, "Television");
1198 t->type = V4L2_TUNER_ANALOG_TV;
1199 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO;
1200 t->rangehigh = 0xffffffffUL;
1201 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1203 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1205 t->audmode = dev->amode;
1210 static int vidioc_s_tuner(struct file *file, void *priv,
1211 const struct v4l2_tuner *t)
1213 struct tm6000_fh *fh = priv;
1214 struct tm6000_core *dev = fh->dev;
1216 if (UNSET == dev->tuner_type)
1221 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1222 dev->amode = V4L2_TUNER_MODE_STEREO;
1224 dev->amode = t->audmode;
1225 dprintk(dev, 3, "audio mode: %x\n", t->audmode);
1227 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1232 static int vidioc_g_frequency(struct file *file, void *priv,
1233 struct v4l2_frequency *f)
1235 struct tm6000_fh *fh = priv;
1236 struct tm6000_core *dev = fh->dev;
1238 if (UNSET == dev->tuner_type)
1243 f->frequency = dev->freq;
1245 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1250 static int vidioc_s_frequency(struct file *file, void *priv,
1251 const struct v4l2_frequency *f)
1253 struct tm6000_fh *fh = priv;
1254 struct tm6000_core *dev = fh->dev;
1256 if (UNSET == dev->tuner_type)
1261 dev->freq = f->frequency;
1262 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1267 static int radio_g_tuner(struct file *file, void *priv,
1268 struct v4l2_tuner *t)
1270 struct tm6000_fh *fh = file->private_data;
1271 struct tm6000_core *dev = fh->dev;
1276 memset(t, 0, sizeof(*t));
1277 strcpy(t->name, "Radio");
1278 t->type = V4L2_TUNER_RADIO;
1279 t->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
1280 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1281 t->audmode = V4L2_TUNER_MODE_STEREO;
1283 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1288 static int radio_s_tuner(struct file *file, void *priv,
1289 const struct v4l2_tuner *t)
1291 struct tm6000_fh *fh = file->private_data;
1292 struct tm6000_core *dev = fh->dev;
1296 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1300 /* ------------------------------------------------------------------
1301 File operations for the device
1302 ------------------------------------------------------------------*/
1304 static int __tm6000_open(struct file *file)
1306 struct video_device *vdev = video_devdata(file);
1307 struct tm6000_core *dev = video_drvdata(file);
1308 struct tm6000_fh *fh;
1309 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1313 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1314 video_device_node_name(vdev));
1316 switch (vdev->vfl_type) {
1317 case VFL_TYPE_GRABBER:
1318 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1321 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1323 case VFL_TYPE_RADIO:
1328 /* If more than one user, mutex should be added */
1331 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1332 video_device_node_name(vdev), v4l2_type_names[type],
1335 /* allocate + initialize per filehandle data */
1336 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1342 v4l2_fh_init(&fh->fh, vdev);
1343 file->private_data = fh;
1348 dev->fourcc = format[0].fourcc;
1350 fh->fmt = format_by_fourcc(dev->fourcc);
1352 tm6000_get_std_res(dev);
1354 fh->width = dev->width;
1355 fh->height = dev->height;
1357 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1358 (unsigned long)fh, (unsigned long)dev,
1359 (unsigned long)&dev->vidq);
1360 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty queued=%d\n",
1361 list_empty(&dev->vidq.queued));
1362 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty active=%d\n",
1363 list_empty(&dev->vidq.active));
1365 /* initialize hardware on analog mode */
1366 rc = tm6000_init_analog_mode(dev);
1368 v4l2_fh_exit(&fh->fh);
1373 dev->mode = TM6000_MODE_ANALOG;
1376 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1379 V4L2_FIELD_INTERLACED,
1380 sizeof(struct tm6000_buffer), fh, &dev->lock);
1382 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1383 tm6000_set_audio_rinput(dev);
1384 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1385 tm6000_prepare_isoc(dev);
1386 tm6000_start_thread(dev);
1388 v4l2_fh_add(&fh->fh);
1393 static int tm6000_open(struct file *file)
1395 struct video_device *vdev = video_devdata(file);
1398 mutex_lock(vdev->lock);
1399 res = __tm6000_open(file);
1400 mutex_unlock(vdev->lock);
1405 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1407 struct tm6000_fh *fh = file->private_data;
1408 struct tm6000_core *dev = fh->dev;
1410 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1413 if (!res_get(fh->dev, fh, true))
1416 if (mutex_lock_interruptible(&dev->lock))
1417 return -ERESTARTSYS;
1418 res = videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1419 file->f_flags & O_NONBLOCK);
1420 mutex_unlock(&dev->lock);
1427 __tm6000_poll(struct file *file, struct poll_table_struct *wait)
1429 unsigned long req_events = poll_requested_events(wait);
1430 struct tm6000_fh *fh = file->private_data;
1431 struct tm6000_buffer *buf;
1434 if (v4l2_event_pending(&fh->fh))
1436 else if (req_events & POLLPRI)
1437 poll_wait(file, &fh->fh.wait, wait);
1438 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1439 return res | POLLERR;
1441 if (!!is_res_streaming(fh->dev, fh))
1442 return res | POLLERR;
1444 if (!is_res_read(fh->dev, fh)) {
1445 /* streaming capture */
1446 if (list_empty(&fh->vb_vidq.stream))
1447 return res | POLLERR;
1448 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
1449 poll_wait(file, &buf->vb.done, wait);
1450 if (buf->vb.state == VIDEOBUF_DONE ||
1451 buf->vb.state == VIDEOBUF_ERROR)
1452 return res | POLLIN | POLLRDNORM;
1453 } else if (req_events & (POLLIN | POLLRDNORM)) {
1454 /* read() capture */
1455 return res | videobuf_poll_stream(file, &fh->vb_vidq, wait);
1460 static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
1462 struct tm6000_fh *fh = file->private_data;
1463 struct tm6000_core *dev = fh->dev;
1466 mutex_lock(&dev->lock);
1467 res = __tm6000_poll(file, wait);
1468 mutex_unlock(&dev->lock);
1472 static int tm6000_release(struct file *file)
1474 struct tm6000_fh *fh = file->private_data;
1475 struct tm6000_core *dev = fh->dev;
1476 struct video_device *vdev = video_devdata(file);
1478 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1479 video_device_node_name(vdev), dev->users);
1481 mutex_lock(&dev->lock);
1487 tm6000_uninit_isoc(dev);
1489 /* Stop interrupt USB pipe */
1490 tm6000_ir_int_stop(dev);
1492 usb_reset_configuration(dev->udev);
1494 if (dev->int_in.endp)
1495 usb_set_interface(dev->udev,
1496 dev->isoc_in.bInterfaceNumber, 2);
1498 usb_set_interface(dev->udev,
1499 dev->isoc_in.bInterfaceNumber, 0);
1501 /* Start interrupt USB pipe */
1502 tm6000_ir_int_start(dev);
1505 videobuf_mmap_free(&fh->vb_vidq);
1507 v4l2_fh_del(&fh->fh);
1508 v4l2_fh_exit(&fh->fh);
1510 mutex_unlock(&dev->lock);
1515 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1517 struct tm6000_fh *fh = file->private_data;
1518 struct tm6000_core *dev = fh->dev;
1521 if (mutex_lock_interruptible(&dev->lock))
1522 return -ERESTARTSYS;
1523 res = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1524 mutex_unlock(&dev->lock);
1528 static const struct v4l2_file_operations tm6000_fops = {
1529 .owner = THIS_MODULE,
1530 .open = tm6000_open,
1531 .release = tm6000_release,
1532 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1533 .read = tm6000_read,
1534 .poll = tm6000_poll,
1535 .mmap = tm6000_mmap,
1538 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1539 .vidioc_querycap = vidioc_querycap,
1540 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1541 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1542 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1543 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1544 .vidioc_s_std = vidioc_s_std,
1545 .vidioc_g_std = vidioc_g_std,
1546 .vidioc_enum_input = vidioc_enum_input,
1547 .vidioc_g_input = vidioc_g_input,
1548 .vidioc_s_input = vidioc_s_input,
1549 .vidioc_g_tuner = vidioc_g_tuner,
1550 .vidioc_s_tuner = vidioc_s_tuner,
1551 .vidioc_g_frequency = vidioc_g_frequency,
1552 .vidioc_s_frequency = vidioc_s_frequency,
1553 .vidioc_streamon = vidioc_streamon,
1554 .vidioc_streamoff = vidioc_streamoff,
1555 .vidioc_reqbufs = vidioc_reqbufs,
1556 .vidioc_querybuf = vidioc_querybuf,
1557 .vidioc_qbuf = vidioc_qbuf,
1558 .vidioc_dqbuf = vidioc_dqbuf,
1559 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1560 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1563 static struct video_device tm6000_template = {
1565 .fops = &tm6000_fops,
1566 .ioctl_ops = &video_ioctl_ops,
1567 .release = video_device_release_empty,
1568 .tvnorms = TM6000_STD,
1571 static const struct v4l2_file_operations radio_fops = {
1572 .owner = THIS_MODULE,
1573 .open = tm6000_open,
1574 .poll = v4l2_ctrl_poll,
1575 .release = tm6000_release,
1576 .unlocked_ioctl = video_ioctl2,
1579 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1580 .vidioc_querycap = vidioc_querycap,
1581 .vidioc_g_tuner = radio_g_tuner,
1582 .vidioc_s_tuner = radio_s_tuner,
1583 .vidioc_g_frequency = vidioc_g_frequency,
1584 .vidioc_s_frequency = vidioc_s_frequency,
1585 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1586 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1589 static struct video_device tm6000_radio_template = {
1591 .fops = &radio_fops,
1592 .ioctl_ops = &radio_ioctl_ops,
1595 /* -----------------------------------------------------------------
1596 * Initialization and module stuff
1597 * ------------------------------------------------------------------
1600 static void vdev_init(struct tm6000_core *dev,
1601 struct video_device *vfd,
1602 const struct video_device
1603 *template, const char *type_name)
1606 vfd->v4l2_dev = &dev->v4l2_dev;
1607 vfd->release = video_device_release_empty;
1608 vfd->lock = &dev->lock;
1610 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1612 video_set_drvdata(vfd, dev);
1615 int tm6000_v4l2_register(struct tm6000_core *dev)
1619 v4l2_ctrl_handler_init(&dev->ctrl_handler, 6);
1620 v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 2);
1621 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1622 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
1623 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1624 V4L2_CID_AUDIO_VOLUME, -15, 15, 1, 0);
1625 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1626 V4L2_CID_BRIGHTNESS, 0, 255, 1, 54);
1627 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1628 V4L2_CID_CONTRAST, 0, 255, 1, 119);
1629 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1630 V4L2_CID_SATURATION, 0, 255, 1, 112);
1631 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1632 V4L2_CID_HUE, -128, 127, 1, 0);
1633 v4l2_ctrl_add_handler(&dev->ctrl_handler,
1634 &dev->radio_ctrl_handler, NULL);
1636 if (dev->radio_ctrl_handler.error)
1637 ret = dev->radio_ctrl_handler.error;
1638 if (!ret && dev->ctrl_handler.error)
1639 ret = dev->ctrl_handler.error;
1643 vdev_init(dev, &dev->vfd, &tm6000_template, "video");
1645 dev->vfd.ctrl_handler = &dev->ctrl_handler;
1647 /* init video dma queues */
1648 INIT_LIST_HEAD(&dev->vidq.active);
1649 INIT_LIST_HEAD(&dev->vidq.queued);
1651 ret = video_register_device(&dev->vfd, VFL_TYPE_GRABBER, video_nr);
1654 printk(KERN_INFO "%s: can't register video device\n",
1659 printk(KERN_INFO "%s: registered device %s\n",
1660 dev->name, video_device_node_name(&dev->vfd));
1662 if (dev->caps.has_radio) {
1663 vdev_init(dev, &dev->radio_dev, &tm6000_radio_template,
1665 dev->radio_dev.ctrl_handler = &dev->radio_ctrl_handler;
1666 ret = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO,
1669 printk(KERN_INFO "%s: can't register radio device\n",
1674 printk(KERN_INFO "%s: registered device %s\n",
1675 dev->name, video_device_node_name(&dev->radio_dev));
1678 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1682 video_unregister_device(&dev->vfd);
1684 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1685 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
1689 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1691 video_unregister_device(&dev->vfd);
1693 /* if URB buffers are still allocated free them now */
1694 tm6000_free_urb_buffers(dev);
1696 video_unregister_device(&dev->radio_dev);
1700 int tm6000_v4l2_exit(void)
1705 module_param(video_nr, int, 0);
1706 MODULE_PARM_DESC(video_nr, "Allow changing video device number");
1708 module_param_named(debug, tm6000_debug, int, 0444);
1709 MODULE_PARM_DESC(debug, "activates debug info");
1711 module_param(vid_limit, int, 0644);
1712 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
1714 module_param(keep_urb, bool, 0);
1715 MODULE_PARM_DESC(keep_urb, "Keep urb buffers allocated even when the device is closed by the user");