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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/module.h>
24 #include <linux/delay.h>
25 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/sched.h>
33 #include <linux/random.h>
34 #include <linux/usb.h>
35 #include <linux/videodev2.h>
36 #include <media/v4l2-ioctl.h>
37 #include <media/v4l2-event.h>
38 #include <media/tuner.h>
39 #include <linux/interrupt.h>
40 #include <linux/kthread.h>
41 #include <linux/highmem.h>
42 #include <linux/freezer.h>
44 #include "tm6000-regs.h"
47 #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
49 /* Limits minimum and default number of buffers */
50 #define TM6000_MIN_BUF 4
51 #define TM6000_DEF_BUF 8
53 #define TM6000_NUM_URB_BUF 8
55 #define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
57 /* Declare static vars that will be used as parameters */
58 static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
59 static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
60 static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */
61 static bool keep_urb; /* keep urb buffers allocated */
65 EXPORT_SYMBOL_GPL(tm6000_debug);
67 static struct tm6000_fmt format[] = {
69 .name = "4:2:2, packed, YVY2",
70 .fourcc = V4L2_PIX_FMT_YUYV,
73 .name = "4:2:2, packed, UYVY",
74 .fourcc = V4L2_PIX_FMT_UYVY,
77 .name = "A/V + VBI mux packet",
78 .fourcc = V4L2_PIX_FMT_TM6000,
83 /* ------------------------------------------------------------------
84 * DMA and thread functions
85 * ------------------------------------------------------------------
88 #define norm_maxw(a) 720
89 #define norm_maxh(a) 576
91 #define norm_minw(a) norm_maxw(a)
92 #define norm_minh(a) norm_maxh(a)
95 * video-buf generic routine to get the next available buffer
97 static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
98 struct tm6000_buffer **buf)
100 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
102 if (list_empty(&dma_q->active)) {
103 dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
108 *buf = list_entry(dma_q->active.next,
109 struct tm6000_buffer, vb.queue);
113 * Announces that a buffer were filled and request the next
115 static inline void buffer_filled(struct tm6000_core *dev,
116 struct tm6000_dmaqueue *dma_q,
117 struct tm6000_buffer *buf)
119 /* Advice that buffer was filled */
120 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
121 buf->vb.state = VIDEOBUF_DONE;
122 buf->vb.field_count++;
123 v4l2_get_timestamp(&buf->vb.ts);
125 list_del(&buf->vb.queue);
126 wake_up(&buf->vb.done);
130 * Identify the tm5600/6000 buffer header type and properly handles
132 static int copy_streams(u8 *data, unsigned long len,
135 struct tm6000_dmaqueue *dma_q = urb->context;
136 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
137 u8 *ptr = data, *endp = data+len;
138 unsigned long header = 0;
140 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
141 struct tm6000_buffer *vbuf = NULL;
143 unsigned int linewidth;
146 /* get video buffer */
147 get_next_buf(dma_q, &vbuf);
151 voutp = videobuf_to_vmalloc(&vbuf->vb);
157 for (ptr = data; ptr < endp;) {
158 if (!dev->isoc_ctl.cmd) {
160 if (dev->isoc_ctl.tmp_buf_len > 0) {
161 /* from last urb or packet */
162 header = dev->isoc_ctl.tmp_buf;
163 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
164 memcpy((u8 *)&header +
165 dev->isoc_ctl.tmp_buf_len,
167 4 - dev->isoc_ctl.tmp_buf_len);
168 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
170 dev->isoc_ctl.tmp_buf_len = 0;
172 if (ptr + 3 >= endp) {
173 /* have incomplete header */
174 dev->isoc_ctl.tmp_buf_len = endp - ptr;
175 memcpy(&dev->isoc_ctl.tmp_buf, ptr,
176 dev->isoc_ctl.tmp_buf_len);
180 for (; ptr < endp - 3; ptr++) {
181 if (*(ptr + 3) == 0x47)
184 /* Get message header */
185 header = *(unsigned long *)ptr;
189 /* split the header fields */
190 size = ((header & 0x7e) << 1);
193 block = (header >> 7) & 0xf;
194 field = (header >> 11) & 0x1;
195 line = (header >> 12) & 0x1ff;
196 cmd = (header >> 21) & 0x7;
197 /* Validates haeder fields */
198 if (size > TM6000_URB_MSG_LEN)
199 size = TM6000_URB_MSG_LEN;
200 pktsize = TM6000_URB_MSG_LEN;
202 * calculate position in buffer and change the buffer
205 case TM6000_URB_MSG_VIDEO:
207 if ((dev->isoc_ctl.vfield != field) &&
210 * Announces that a new buffer
213 buffer_filled(dev, dma_q, vbuf);
214 dprintk(dev, V4L2_DEBUG_ISOC,
215 "new buffer filled\n");
216 get_next_buf(dma_q, &vbuf);
219 voutp = videobuf_to_vmalloc(&vbuf->vb);
222 memset(voutp, 0, vbuf->vb.size);
224 linewidth = vbuf->vb.width << 1;
225 pos = ((line << 1) - field - 1) *
226 linewidth + block * TM6000_URB_MSG_LEN;
227 /* Don't allow to write out of the buffer */
228 if (pos + size > vbuf->vb.size)
229 cmd = TM6000_URB_MSG_ERR;
230 dev->isoc_ctl.vfield = field;
233 case TM6000_URB_MSG_VBI:
235 case TM6000_URB_MSG_AUDIO:
236 case TM6000_URB_MSG_PTS:
237 size = pktsize; /* Size is always 180 bytes */
241 /* Continue the last copy */
242 cmd = dev->isoc_ctl.cmd;
243 size = dev->isoc_ctl.size;
244 pos = dev->isoc_ctl.pos;
245 pktsize = dev->isoc_ctl.pktsize;
246 field = dev->isoc_ctl.field;
248 cpysize = (endp - ptr > size) ? size : endp - ptr;
250 /* copy data in different buffers */
252 case TM6000_URB_MSG_VIDEO:
253 /* Fills video buffer */
255 memcpy(&voutp[pos], ptr, cpysize);
257 case TM6000_URB_MSG_AUDIO: {
259 for (i = 0; i < cpysize; i += 2)
260 swab16s((u16 *)(ptr + i));
262 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
265 case TM6000_URB_MSG_VBI:
266 /* Need some code to copy vbi buffer */
268 case TM6000_URB_MSG_PTS: {
269 /* Need some code to copy pts */
272 dprintk(dev, V4L2_DEBUG_ISOC, "field %d, PTS %x",
278 if (ptr + pktsize > endp) {
280 * End of URB packet, but cmd processing is not
281 * complete. Preserve the state for a next packet
283 dev->isoc_ctl.pos = pos + cpysize;
284 dev->isoc_ctl.size = size - cpysize;
285 dev->isoc_ctl.cmd = cmd;
286 dev->isoc_ctl.field = field;
287 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
290 dev->isoc_ctl.cmd = 0;
298 * Identify the tm5600/6000 buffer header type and properly handles
300 static int copy_multiplexed(u8 *ptr, unsigned long len,
303 struct tm6000_dmaqueue *dma_q = urb->context;
304 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
305 unsigned int pos = dev->isoc_ctl.pos, cpysize;
307 struct tm6000_buffer *buf;
310 get_next_buf(dma_q, &buf);
312 outp = videobuf_to_vmalloc(&buf->vb);
318 cpysize = min(len, buf->vb.size-pos);
319 memcpy(&outp[pos], ptr, cpysize);
323 if (pos >= buf->vb.size) {
325 /* Announces that a new buffer were filled */
326 buffer_filled(dev, dma_q, buf);
327 dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
328 get_next_buf(dma_q, &buf);
331 outp = videobuf_to_vmalloc(&(buf->vb));
338 dev->isoc_ctl.pos = pos;
342 static inline void print_err_status(struct tm6000_core *dev,
343 int packet, int status)
345 char *errmsg = "Unknown";
349 errmsg = "unlinked synchronuously";
352 errmsg = "unlinked asynchronuously";
355 errmsg = "Buffer error (overrun)";
358 errmsg = "Stalled (device not responding)";
361 errmsg = "Babble (bad cable?)";
364 errmsg = "Bit-stuff error (bad cable?)";
367 errmsg = "CRC/Timeout (could be anything)";
370 errmsg = "Device does not respond";
374 dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
377 dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
378 packet, status, errmsg);
384 * Controls the isoc copy of each urb packet
386 static inline int tm6000_isoc_copy(struct urb *urb)
388 struct tm6000_dmaqueue *dma_q = urb->context;
389 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
390 int i, len = 0, rc = 1, status;
393 if (urb->status < 0) {
394 print_err_status(dev, -1, urb->status);
398 for (i = 0; i < urb->number_of_packets; i++) {
399 status = urb->iso_frame_desc[i].status;
402 print_err_status(dev, i, status);
406 len = urb->iso_frame_desc[i].actual_length;
409 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
410 if (!urb->iso_frame_desc[i].status) {
411 if ((dev->fourcc) == V4L2_PIX_FMT_TM6000) {
412 rc = copy_multiplexed(p, len, urb);
416 copy_streams(p, len, urb);
424 /* ------------------------------------------------------------------
426 * ------------------------------------------------------------------
430 * IRQ callback, called by URB callback
432 static void tm6000_irq_callback(struct urb *urb)
434 struct tm6000_dmaqueue *dma_q = urb->context;
435 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
438 switch (urb->status) {
449 tm6000_err("urb completion error %d.\n", urb->status);
453 spin_lock(&dev->slock);
454 tm6000_isoc_copy(urb);
455 spin_unlock(&dev->slock);
457 /* Reset urb buffers */
458 for (i = 0; i < urb->number_of_packets; i++) {
459 urb->iso_frame_desc[i].status = 0;
460 urb->iso_frame_desc[i].actual_length = 0;
463 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
465 tm6000_err("urb resubmit failed (error=%i)\n",
470 * Allocate URB buffers
472 static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
474 int num_bufs = TM6000_NUM_URB_BUF;
477 if (dev->urb_buffer != NULL)
480 dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
481 if (!dev->urb_buffer) {
482 tm6000_err("cannot allocate memory for urb buffers\n");
486 dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
488 tm6000_err("cannot allocate memory for urb dma pointers\n");
492 for (i = 0; i < num_bufs; i++) {
493 dev->urb_buffer[i] = usb_alloc_coherent(
494 dev->udev, dev->urb_size,
495 GFP_KERNEL, &dev->urb_dma[i]);
496 if (!dev->urb_buffer[i]) {
497 tm6000_err("unable to allocate %i bytes for transfer buffer %i\n",
501 memset(dev->urb_buffer[i], 0, dev->urb_size);
510 static int tm6000_free_urb_buffers(struct tm6000_core *dev)
514 if (dev->urb_buffer == NULL)
517 for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
518 if (dev->urb_buffer[i]) {
519 usb_free_coherent(dev->udev,
523 dev->urb_buffer[i] = NULL;
526 kfree(dev->urb_buffer);
528 dev->urb_buffer = NULL;
535 * Stop and Deallocate URBs
537 static void tm6000_uninit_isoc(struct tm6000_core *dev)
542 dev->isoc_ctl.buf = NULL;
543 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
544 urb = dev->isoc_ctl.urb[i];
549 dev->isoc_ctl.urb[i] = NULL;
551 dev->isoc_ctl.transfer_buffer[i] = NULL;
555 tm6000_free_urb_buffers(dev);
557 kfree(dev->isoc_ctl.urb);
558 kfree(dev->isoc_ctl.transfer_buffer);
560 dev->isoc_ctl.urb = NULL;
561 dev->isoc_ctl.transfer_buffer = NULL;
562 dev->isoc_ctl.num_bufs = 0;
566 * Assign URBs and start IRQ
568 static int tm6000_prepare_isoc(struct tm6000_core *dev)
570 struct tm6000_dmaqueue *dma_q = &dev->vidq;
571 int i, j, sb_size, pipe, size, max_packets;
572 int num_bufs = TM6000_NUM_URB_BUF;
575 /* De-allocates all pending stuff */
576 tm6000_uninit_isoc(dev);
577 /* Stop interrupt USB pipe */
578 tm6000_ir_int_stop(dev);
580 usb_set_interface(dev->udev,
581 dev->isoc_in.bInterfaceNumber,
582 dev->isoc_in.bAlternateSetting);
584 /* Start interrupt USB pipe */
585 tm6000_ir_int_start(dev);
587 pipe = usb_rcvisocpipe(dev->udev,
588 dev->isoc_in.endp->desc.bEndpointAddress &
589 USB_ENDPOINT_NUMBER_MASK);
591 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
593 if (size > dev->isoc_in.maxsize)
594 size = dev->isoc_in.maxsize;
596 dev->isoc_ctl.max_pkt_size = size;
598 max_packets = TM6000_MAX_ISO_PACKETS;
599 sb_size = max_packets * size;
600 dev->urb_size = sb_size;
602 dev->isoc_ctl.num_bufs = num_bufs;
604 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
605 if (!dev->isoc_ctl.urb) {
606 tm6000_err("cannot alloc memory for usb buffers\n");
610 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
612 if (!dev->isoc_ctl.transfer_buffer) {
613 tm6000_err("cannot allocate memory for usbtransfer\n");
614 kfree(dev->isoc_ctl.urb);
618 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
619 " (%d bytes) of %d bytes each to handle %u size\n",
620 max_packets, num_bufs, sb_size,
621 dev->isoc_in.maxsize, size);
624 if (tm6000_alloc_urb_buffers(dev) < 0) {
625 tm6000_err("cannot allocate memory for urb buffers\n");
627 /* call free, as some buffers might have been allocated */
628 tm6000_free_urb_buffers(dev);
629 kfree(dev->isoc_ctl.urb);
630 kfree(dev->isoc_ctl.transfer_buffer);
634 /* allocate urbs and transfer buffers */
635 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
636 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
638 tm6000_uninit_isoc(dev);
642 dev->isoc_ctl.urb[i] = urb;
644 urb->transfer_dma = dev->urb_dma[i];
645 dev->isoc_ctl.transfer_buffer[i] = dev->urb_buffer[i];
647 usb_fill_bulk_urb(urb, dev->udev, pipe,
648 dev->isoc_ctl.transfer_buffer[i], sb_size,
649 tm6000_irq_callback, dma_q);
650 urb->interval = dev->isoc_in.endp->desc.bInterval;
651 urb->number_of_packets = max_packets;
652 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
654 for (j = 0; j < max_packets; j++) {
655 urb->iso_frame_desc[j].offset = size * j;
656 urb->iso_frame_desc[j].length = size;
663 static int tm6000_start_thread(struct tm6000_core *dev)
665 struct tm6000_dmaqueue *dma_q = &dev->vidq;
669 dma_q->ini_jiffies = jiffies;
671 init_waitqueue_head(&dma_q->wq);
673 /* submit urbs and enables IRQ */
674 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
675 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
677 tm6000_err("submit of urb %i failed (error=%i)\n", i,
679 tm6000_uninit_isoc(dev);
687 /* ------------------------------------------------------------------
688 * Videobuf operations
689 * ------------------------------------------------------------------
693 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
695 struct tm6000_fh *fh = vq->priv_data;
697 *size = fh->fmt->depth * fh->width * fh->height >> 3;
699 *count = TM6000_DEF_BUF;
701 if (*count < TM6000_MIN_BUF)
702 *count = TM6000_MIN_BUF;
704 while (*size * *count > vid_limit * 1024 * 1024)
710 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
712 struct tm6000_fh *fh = vq->priv_data;
713 struct tm6000_core *dev = fh->dev;
716 BUG_ON(in_interrupt());
718 /* We used to wait for the buffer to finish here, but this didn't work
719 because, as we were keeping the state as VIDEOBUF_QUEUED,
720 videobuf_queue_cancel marked it as finished for us.
721 (Also, it could wedge forever if the hardware was misconfigured.)
723 This should be safe; by the time we get here, the buffer isn't
724 queued anymore. If we ever start marking the buffers as
725 VIDEOBUF_ACTIVE, it won't be, though.
727 spin_lock_irqsave(&dev->slock, flags);
728 if (dev->isoc_ctl.buf == buf)
729 dev->isoc_ctl.buf = NULL;
730 spin_unlock_irqrestore(&dev->slock, flags);
732 videobuf_vmalloc_free(&buf->vb);
733 buf->vb.state = VIDEOBUF_NEEDS_INIT;
737 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
738 enum v4l2_field field)
740 struct tm6000_fh *fh = vq->priv_data;
741 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
742 struct tm6000_core *dev = fh->dev;
745 BUG_ON(NULL == fh->fmt);
748 /* FIXME: It assumes depth=2 */
749 /* The only currently supported format is 16 bits/pixel */
750 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
751 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
754 if (buf->fmt != fh->fmt ||
755 buf->vb.width != fh->width ||
756 buf->vb.height != fh->height ||
757 buf->vb.field != field) {
759 buf->vb.width = fh->width;
760 buf->vb.height = fh->height;
761 buf->vb.field = field;
762 buf->vb.state = VIDEOBUF_NEEDS_INIT;
765 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
766 rc = videobuf_iolock(vq, &buf->vb, NULL);
771 if (!dev->isoc_ctl.num_bufs) {
772 rc = tm6000_prepare_isoc(dev);
776 rc = tm6000_start_thread(dev);
782 buf->vb.state = VIDEOBUF_PREPARED;
786 free_buffer(vq, buf);
791 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
793 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
794 struct tm6000_fh *fh = vq->priv_data;
795 struct tm6000_core *dev = fh->dev;
796 struct tm6000_dmaqueue *vidq = &dev->vidq;
798 buf->vb.state = VIDEOBUF_QUEUED;
799 list_add_tail(&buf->vb.queue, &vidq->active);
802 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
804 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
806 free_buffer(vq, buf);
809 static struct videobuf_queue_ops tm6000_video_qops = {
810 .buf_setup = buffer_setup,
811 .buf_prepare = buffer_prepare,
812 .buf_queue = buffer_queue,
813 .buf_release = buffer_release,
816 /* ------------------------------------------------------------------
818 * ------------------------------------------------------------------
821 static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
823 /* Is the current fh handling it? if so, that's OK */
824 if (dev->resources == fh && dev->is_res_read)
830 static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
832 /* Is the current fh handling it? if so, that's OK */
833 if (dev->resources == fh)
839 static bool res_get(struct tm6000_core *dev, struct tm6000_fh *fh,
842 /* Is the current fh handling it? if so, that's OK */
843 if (dev->resources == fh && dev->is_res_read == is_res_read)
852 dev->is_res_read = is_res_read;
853 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
857 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
859 /* Is the current fh handling it? if so, that's OK */
860 if (dev->resources != fh)
863 dev->resources = NULL;
864 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
867 /* ------------------------------------------------------------------
868 * IOCTL vidioc handling
869 * ------------------------------------------------------------------
871 static int vidioc_querycap(struct file *file, void *priv,
872 struct v4l2_capability *cap)
874 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
875 struct video_device *vdev = video_devdata(file);
877 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
878 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
879 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
880 if (dev->tuner_type != TUNER_ABSENT)
881 cap->device_caps |= V4L2_CAP_TUNER;
882 if (vdev->vfl_type == VFL_TYPE_GRABBER)
883 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
887 cap->device_caps |= V4L2_CAP_RADIO;
888 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
889 V4L2_CAP_RADIO | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
894 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
895 struct v4l2_fmtdesc *f)
897 if (f->index >= ARRAY_SIZE(format))
900 strlcpy(f->description, format[f->index].name, sizeof(f->description));
901 f->pixelformat = format[f->index].fourcc;
905 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
906 struct v4l2_format *f)
908 struct tm6000_fh *fh = priv;
910 f->fmt.pix.width = fh->width;
911 f->fmt.pix.height = fh->height;
912 f->fmt.pix.field = fh->vb_vidq.field;
913 f->fmt.pix.pixelformat = fh->fmt->fourcc;
914 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
915 f->fmt.pix.bytesperline =
916 (f->fmt.pix.width * fh->fmt->depth) >> 3;
917 f->fmt.pix.sizeimage =
918 f->fmt.pix.height * f->fmt.pix.bytesperline;
923 static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
927 for (i = 0; i < ARRAY_SIZE(format); i++)
928 if (format[i].fourcc == fourcc)
933 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
934 struct v4l2_format *f)
936 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
937 struct tm6000_fmt *fmt;
938 enum v4l2_field field;
940 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
942 dprintk(dev, 2, "Fourcc format (0x%08x)"
943 " invalid.\n", f->fmt.pix.pixelformat);
947 field = f->fmt.pix.field;
949 field = V4L2_FIELD_INTERLACED;
951 tm6000_get_std_res(dev);
953 f->fmt.pix.width = dev->width;
954 f->fmt.pix.height = dev->height;
956 f->fmt.pix.width &= ~0x01;
958 f->fmt.pix.field = field;
960 f->fmt.pix.bytesperline =
961 (f->fmt.pix.width * fmt->depth) >> 3;
962 f->fmt.pix.sizeimage =
963 f->fmt.pix.height * f->fmt.pix.bytesperline;
964 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
969 /*FIXME: This seems to be generic enough to be at videodev2 */
970 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
971 struct v4l2_format *f)
973 struct tm6000_fh *fh = priv;
974 struct tm6000_core *dev = fh->dev;
975 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
979 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
980 fh->width = f->fmt.pix.width;
981 fh->height = f->fmt.pix.height;
982 fh->vb_vidq.field = f->fmt.pix.field;
985 dev->fourcc = f->fmt.pix.pixelformat;
987 tm6000_set_fourcc_format(dev);
992 static int vidioc_reqbufs(struct file *file, void *priv,
993 struct v4l2_requestbuffers *p)
995 struct tm6000_fh *fh = priv;
997 return videobuf_reqbufs(&fh->vb_vidq, p);
1000 static int vidioc_querybuf(struct file *file, void *priv,
1001 struct v4l2_buffer *p)
1003 struct tm6000_fh *fh = priv;
1005 return videobuf_querybuf(&fh->vb_vidq, p);
1008 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1010 struct tm6000_fh *fh = priv;
1012 return videobuf_qbuf(&fh->vb_vidq, p);
1015 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1017 struct tm6000_fh *fh = priv;
1019 return videobuf_dqbuf(&fh->vb_vidq, p,
1020 file->f_flags & O_NONBLOCK);
1023 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1025 struct tm6000_fh *fh = priv;
1026 struct tm6000_core *dev = fh->dev;
1028 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1033 if (!res_get(dev, fh, false))
1035 return videobuf_streamon(&fh->vb_vidq);
1038 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1040 struct tm6000_fh *fh = priv;
1041 struct tm6000_core *dev = fh->dev;
1043 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1049 videobuf_streamoff(&fh->vb_vidq);
1055 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1058 struct tm6000_fh *fh = priv;
1059 struct tm6000_core *dev = fh->dev;
1062 rc = tm6000_init_analog_mode(dev);
1064 fh->width = dev->width;
1065 fh->height = dev->height;
1070 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, dev->norm);
1075 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1077 struct tm6000_fh *fh = priv;
1078 struct tm6000_core *dev = fh->dev;
1084 static const char *iname[] = {
1085 [TM6000_INPUT_TV] = "Television",
1086 [TM6000_INPUT_COMPOSITE1] = "Composite 1",
1087 [TM6000_INPUT_COMPOSITE2] = "Composite 2",
1088 [TM6000_INPUT_SVIDEO] = "S-Video",
1091 static int vidioc_enum_input(struct file *file, void *priv,
1092 struct v4l2_input *i)
1094 struct tm6000_fh *fh = priv;
1095 struct tm6000_core *dev = fh->dev;
1102 if (!dev->vinput[n].type)
1107 if (dev->vinput[n].type == TM6000_INPUT_TV)
1108 i->type = V4L2_INPUT_TYPE_TUNER;
1110 i->type = V4L2_INPUT_TYPE_CAMERA;
1112 strcpy(i->name, iname[dev->vinput[n].type]);
1114 i->std = TM6000_STD;
1119 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1121 struct tm6000_fh *fh = priv;
1122 struct tm6000_core *dev = fh->dev;
1129 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1131 struct tm6000_fh *fh = priv;
1132 struct tm6000_core *dev = fh->dev;
1137 if (!dev->vinput[i].type)
1142 rc = vidioc_s_std(file, priv, dev->norm);
1147 /* --- controls ---------------------------------------------- */
1149 static int tm6000_s_ctrl(struct v4l2_ctrl *ctrl)
1151 struct tm6000_core *dev = container_of(ctrl->handler, struct tm6000_core, ctrl_handler);
1155 case V4L2_CID_CONTRAST:
1156 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1158 case V4L2_CID_BRIGHTNESS:
1159 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1161 case V4L2_CID_SATURATION:
1162 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1165 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1171 static const struct v4l2_ctrl_ops tm6000_ctrl_ops = {
1172 .s_ctrl = tm6000_s_ctrl,
1175 static int tm6000_radio_s_ctrl(struct v4l2_ctrl *ctrl)
1177 struct tm6000_core *dev = container_of(ctrl->handler,
1178 struct tm6000_core, radio_ctrl_handler);
1182 case V4L2_CID_AUDIO_MUTE:
1183 dev->ctl_mute = val;
1184 tm6000_tvaudio_set_mute(dev, val);
1186 case V4L2_CID_AUDIO_VOLUME:
1187 dev->ctl_volume = val;
1188 tm6000_set_volume(dev, val);
1194 static const struct v4l2_ctrl_ops tm6000_radio_ctrl_ops = {
1195 .s_ctrl = tm6000_radio_s_ctrl,
1198 static int vidioc_g_tuner(struct file *file, void *priv,
1199 struct v4l2_tuner *t)
1201 struct tm6000_fh *fh = priv;
1202 struct tm6000_core *dev = fh->dev;
1204 if (UNSET == dev->tuner_type)
1209 strcpy(t->name, "Television");
1210 t->type = V4L2_TUNER_ANALOG_TV;
1211 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO;
1212 t->rangehigh = 0xffffffffUL;
1213 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1215 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1217 t->audmode = dev->amode;
1222 static int vidioc_s_tuner(struct file *file, void *priv,
1223 const struct v4l2_tuner *t)
1225 struct tm6000_fh *fh = priv;
1226 struct tm6000_core *dev = fh->dev;
1228 if (UNSET == dev->tuner_type)
1233 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1234 dev->amode = V4L2_TUNER_MODE_STEREO;
1236 dev->amode = t->audmode;
1237 dprintk(dev, 3, "audio mode: %x\n", t->audmode);
1239 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1244 static int vidioc_g_frequency(struct file *file, void *priv,
1245 struct v4l2_frequency *f)
1247 struct tm6000_fh *fh = priv;
1248 struct tm6000_core *dev = fh->dev;
1250 if (UNSET == dev->tuner_type)
1255 f->frequency = dev->freq;
1257 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1262 static int vidioc_s_frequency(struct file *file, void *priv,
1263 const struct v4l2_frequency *f)
1265 struct tm6000_fh *fh = priv;
1266 struct tm6000_core *dev = fh->dev;
1268 if (UNSET == dev->tuner_type)
1273 dev->freq = f->frequency;
1274 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1279 static int radio_g_tuner(struct file *file, void *priv,
1280 struct v4l2_tuner *t)
1282 struct tm6000_fh *fh = file->private_data;
1283 struct tm6000_core *dev = fh->dev;
1288 memset(t, 0, sizeof(*t));
1289 strcpy(t->name, "Radio");
1290 t->type = V4L2_TUNER_RADIO;
1291 t->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
1292 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1293 t->audmode = V4L2_TUNER_MODE_STEREO;
1295 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1300 static int radio_s_tuner(struct file *file, void *priv,
1301 const struct v4l2_tuner *t)
1303 struct tm6000_fh *fh = file->private_data;
1304 struct tm6000_core *dev = fh->dev;
1308 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1312 /* ------------------------------------------------------------------
1313 File operations for the device
1314 ------------------------------------------------------------------*/
1316 static int __tm6000_open(struct file *file)
1318 struct video_device *vdev = video_devdata(file);
1319 struct tm6000_core *dev = video_drvdata(file);
1320 struct tm6000_fh *fh;
1321 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1325 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1326 video_device_node_name(vdev));
1328 switch (vdev->vfl_type) {
1329 case VFL_TYPE_GRABBER:
1330 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1333 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1335 case VFL_TYPE_RADIO:
1340 /* If more than one user, mutex should be added */
1343 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1344 video_device_node_name(vdev), v4l2_type_names[type],
1347 /* allocate + initialize per filehandle data */
1348 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1354 v4l2_fh_init(&fh->fh, vdev);
1355 file->private_data = fh;
1360 dev->fourcc = format[0].fourcc;
1362 fh->fmt = format_by_fourcc(dev->fourcc);
1364 tm6000_get_std_res(dev);
1366 fh->width = dev->width;
1367 fh->height = dev->height;
1369 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
1370 "dev->vidq=0x%08lx\n",
1371 (unsigned long)fh, (unsigned long)dev,
1372 (unsigned long)&dev->vidq);
1373 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1374 "queued=%d\n", list_empty(&dev->vidq.queued));
1375 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1376 "active=%d\n", list_empty(&dev->vidq.active));
1378 /* initialize hardware on analog mode */
1379 rc = tm6000_init_analog_mode(dev);
1383 dev->mode = TM6000_MODE_ANALOG;
1386 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1389 V4L2_FIELD_INTERLACED,
1390 sizeof(struct tm6000_buffer), fh, &dev->lock);
1392 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1393 tm6000_set_audio_rinput(dev);
1394 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1395 tm6000_prepare_isoc(dev);
1396 tm6000_start_thread(dev);
1398 v4l2_fh_add(&fh->fh);
1403 static int tm6000_open(struct file *file)
1405 struct video_device *vdev = video_devdata(file);
1408 mutex_lock(vdev->lock);
1409 res = __tm6000_open(file);
1410 mutex_unlock(vdev->lock);
1415 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1417 struct tm6000_fh *fh = file->private_data;
1418 struct tm6000_core *dev = fh->dev;
1420 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1423 if (!res_get(fh->dev, fh, true))
1426 if (mutex_lock_interruptible(&dev->lock))
1427 return -ERESTARTSYS;
1428 res = videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1429 file->f_flags & O_NONBLOCK);
1430 mutex_unlock(&dev->lock);
1437 __tm6000_poll(struct file *file, struct poll_table_struct *wait)
1439 unsigned long req_events = poll_requested_events(wait);
1440 struct tm6000_fh *fh = file->private_data;
1441 struct tm6000_buffer *buf;
1444 if (v4l2_event_pending(&fh->fh))
1446 else if (req_events & POLLPRI)
1447 poll_wait(file, &fh->fh.wait, wait);
1448 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1449 return res | POLLERR;
1451 if (!!is_res_streaming(fh->dev, fh))
1452 return res | POLLERR;
1454 if (!is_res_read(fh->dev, fh)) {
1455 /* streaming capture */
1456 if (list_empty(&fh->vb_vidq.stream))
1457 return res | POLLERR;
1458 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
1459 poll_wait(file, &buf->vb.done, wait);
1460 if (buf->vb.state == VIDEOBUF_DONE ||
1461 buf->vb.state == VIDEOBUF_ERROR)
1462 return res | POLLIN | POLLRDNORM;
1463 } else if (req_events & (POLLIN | POLLRDNORM)) {
1464 /* read() capture */
1465 return res | videobuf_poll_stream(file, &fh->vb_vidq, wait);
1470 static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
1472 struct tm6000_fh *fh = file->private_data;
1473 struct tm6000_core *dev = fh->dev;
1476 mutex_lock(&dev->lock);
1477 res = __tm6000_poll(file, wait);
1478 mutex_unlock(&dev->lock);
1482 static int tm6000_release(struct file *file)
1484 struct tm6000_fh *fh = file->private_data;
1485 struct tm6000_core *dev = fh->dev;
1486 struct video_device *vdev = video_devdata(file);
1488 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1489 video_device_node_name(vdev), dev->users);
1491 mutex_lock(&dev->lock);
1497 tm6000_uninit_isoc(dev);
1499 /* Stop interrupt USB pipe */
1500 tm6000_ir_int_stop(dev);
1502 usb_reset_configuration(dev->udev);
1504 if (dev->int_in.endp)
1505 usb_set_interface(dev->udev,
1506 dev->isoc_in.bInterfaceNumber, 2);
1508 usb_set_interface(dev->udev,
1509 dev->isoc_in.bInterfaceNumber, 0);
1511 /* Start interrupt USB pipe */
1512 tm6000_ir_int_start(dev);
1515 videobuf_mmap_free(&fh->vb_vidq);
1517 v4l2_fh_del(&fh->fh);
1518 v4l2_fh_exit(&fh->fh);
1520 mutex_unlock(&dev->lock);
1525 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1527 struct tm6000_fh *fh = file->private_data;
1528 struct tm6000_core *dev = fh->dev;
1531 if (mutex_lock_interruptible(&dev->lock))
1532 return -ERESTARTSYS;
1533 res = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1534 mutex_unlock(&dev->lock);
1538 static struct v4l2_file_operations tm6000_fops = {
1539 .owner = THIS_MODULE,
1540 .open = tm6000_open,
1541 .release = tm6000_release,
1542 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1543 .read = tm6000_read,
1544 .poll = tm6000_poll,
1545 .mmap = tm6000_mmap,
1548 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1549 .vidioc_querycap = vidioc_querycap,
1550 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1551 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1552 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1553 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1554 .vidioc_s_std = vidioc_s_std,
1555 .vidioc_g_std = vidioc_g_std,
1556 .vidioc_enum_input = vidioc_enum_input,
1557 .vidioc_g_input = vidioc_g_input,
1558 .vidioc_s_input = vidioc_s_input,
1559 .vidioc_g_tuner = vidioc_g_tuner,
1560 .vidioc_s_tuner = vidioc_s_tuner,
1561 .vidioc_g_frequency = vidioc_g_frequency,
1562 .vidioc_s_frequency = vidioc_s_frequency,
1563 .vidioc_streamon = vidioc_streamon,
1564 .vidioc_streamoff = vidioc_streamoff,
1565 .vidioc_reqbufs = vidioc_reqbufs,
1566 .vidioc_querybuf = vidioc_querybuf,
1567 .vidioc_qbuf = vidioc_qbuf,
1568 .vidioc_dqbuf = vidioc_dqbuf,
1569 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1570 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1573 static struct video_device tm6000_template = {
1575 .fops = &tm6000_fops,
1576 .ioctl_ops = &video_ioctl_ops,
1577 .release = video_device_release_empty,
1578 .tvnorms = TM6000_STD,
1581 static const struct v4l2_file_operations radio_fops = {
1582 .owner = THIS_MODULE,
1583 .open = tm6000_open,
1584 .poll = v4l2_ctrl_poll,
1585 .release = tm6000_release,
1586 .unlocked_ioctl = video_ioctl2,
1589 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1590 .vidioc_querycap = vidioc_querycap,
1591 .vidioc_g_tuner = radio_g_tuner,
1592 .vidioc_s_tuner = radio_s_tuner,
1593 .vidioc_g_frequency = vidioc_g_frequency,
1594 .vidioc_s_frequency = vidioc_s_frequency,
1595 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1596 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1599 static struct video_device tm6000_radio_template = {
1601 .fops = &radio_fops,
1602 .ioctl_ops = &radio_ioctl_ops,
1605 /* -----------------------------------------------------------------
1606 * Initialization and module stuff
1607 * ------------------------------------------------------------------
1610 static void vdev_init(struct tm6000_core *dev,
1611 struct video_device *vfd,
1612 const struct video_device
1613 *template, const char *type_name)
1616 vfd->v4l2_dev = &dev->v4l2_dev;
1617 vfd->release = video_device_release_empty;
1618 vfd->lock = &dev->lock;
1620 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1622 video_set_drvdata(vfd, dev);
1625 int tm6000_v4l2_register(struct tm6000_core *dev)
1629 v4l2_ctrl_handler_init(&dev->ctrl_handler, 6);
1630 v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 2);
1631 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1632 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
1633 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1634 V4L2_CID_AUDIO_VOLUME, -15, 15, 1, 0);
1635 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1636 V4L2_CID_BRIGHTNESS, 0, 255, 1, 54);
1637 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1638 V4L2_CID_CONTRAST, 0, 255, 1, 119);
1639 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1640 V4L2_CID_SATURATION, 0, 255, 1, 112);
1641 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1642 V4L2_CID_HUE, -128, 127, 1, 0);
1643 v4l2_ctrl_add_handler(&dev->ctrl_handler,
1644 &dev->radio_ctrl_handler, NULL);
1646 if (dev->radio_ctrl_handler.error)
1647 ret = dev->radio_ctrl_handler.error;
1648 if (!ret && dev->ctrl_handler.error)
1649 ret = dev->ctrl_handler.error;
1653 vdev_init(dev, &dev->vfd, &tm6000_template, "video");
1655 dev->vfd.ctrl_handler = &dev->ctrl_handler;
1657 /* init video dma queues */
1658 INIT_LIST_HEAD(&dev->vidq.active);
1659 INIT_LIST_HEAD(&dev->vidq.queued);
1661 ret = video_register_device(&dev->vfd, VFL_TYPE_GRABBER, video_nr);
1664 printk(KERN_INFO "%s: can't register video device\n",
1669 printk(KERN_INFO "%s: registered device %s\n",
1670 dev->name, video_device_node_name(&dev->vfd));
1672 if (dev->caps.has_radio) {
1673 vdev_init(dev, &dev->radio_dev, &tm6000_radio_template,
1675 dev->radio_dev.ctrl_handler = &dev->radio_ctrl_handler;
1676 ret = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO,
1679 printk(KERN_INFO "%s: can't register radio device\n",
1684 printk(KERN_INFO "%s: registered device %s\n",
1685 dev->name, video_device_node_name(&dev->radio_dev));
1688 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1692 video_unregister_device(&dev->vfd);
1694 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1695 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
1699 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1701 video_unregister_device(&dev->vfd);
1703 /* if URB buffers are still allocated free them now */
1704 tm6000_free_urb_buffers(dev);
1706 video_unregister_device(&dev->radio_dev);
1710 int tm6000_v4l2_exit(void)
1715 module_param(video_nr, int, 0);
1716 MODULE_PARM_DESC(video_nr, "Allow changing video device number");
1718 module_param_named(debug, tm6000_debug, int, 0444);
1719 MODULE_PARM_DESC(debug, "activates debug info");
1721 module_param(vid_limit, int, 0644);
1722 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
1724 module_param(keep_urb, bool, 0);
1725 MODULE_PARM_DESC(keep_urb, "Keep urb buffers allocated even when the device is closed by the user");