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 synchronuously";
348 errmsg = "unlinked asynchronuously";
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;
473 if (dev->urb_buffer != NULL)
476 dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
477 if (!dev->urb_buffer) {
478 tm6000_err("cannot allocate memory for urb buffers\n");
482 dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
484 tm6000_err("cannot allocate memory for urb dma pointers\n");
488 for (i = 0; i < num_bufs; i++) {
489 dev->urb_buffer[i] = usb_alloc_coherent(
490 dev->udev, dev->urb_size,
491 GFP_KERNEL, &dev->urb_dma[i]);
492 if (!dev->urb_buffer[i]) {
493 tm6000_err("unable to allocate %i bytes for transfer buffer %i\n",
497 memset(dev->urb_buffer[i], 0, dev->urb_size);
506 static int tm6000_free_urb_buffers(struct tm6000_core *dev)
510 if (dev->urb_buffer == NULL)
513 for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
514 if (dev->urb_buffer[i]) {
515 usb_free_coherent(dev->udev,
519 dev->urb_buffer[i] = NULL;
522 kfree(dev->urb_buffer);
524 dev->urb_buffer = NULL;
531 * Stop and Deallocate URBs
533 static void tm6000_uninit_isoc(struct tm6000_core *dev)
538 dev->isoc_ctl.buf = NULL;
539 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
540 urb = dev->isoc_ctl.urb[i];
545 dev->isoc_ctl.urb[i] = NULL;
547 dev->isoc_ctl.transfer_buffer[i] = NULL;
551 tm6000_free_urb_buffers(dev);
553 kfree(dev->isoc_ctl.urb);
554 kfree(dev->isoc_ctl.transfer_buffer);
556 dev->isoc_ctl.urb = NULL;
557 dev->isoc_ctl.transfer_buffer = NULL;
558 dev->isoc_ctl.num_bufs = 0;
562 * Assign URBs and start IRQ
564 static int tm6000_prepare_isoc(struct tm6000_core *dev)
566 struct tm6000_dmaqueue *dma_q = &dev->vidq;
567 int i, j, sb_size, pipe, size, max_packets;
568 int num_bufs = TM6000_NUM_URB_BUF;
571 /* De-allocates all pending stuff */
572 tm6000_uninit_isoc(dev);
573 /* Stop interrupt USB pipe */
574 tm6000_ir_int_stop(dev);
576 usb_set_interface(dev->udev,
577 dev->isoc_in.bInterfaceNumber,
578 dev->isoc_in.bAlternateSetting);
580 /* Start interrupt USB pipe */
581 tm6000_ir_int_start(dev);
583 pipe = usb_rcvisocpipe(dev->udev,
584 dev->isoc_in.endp->desc.bEndpointAddress &
585 USB_ENDPOINT_NUMBER_MASK);
587 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
589 if (size > dev->isoc_in.maxsize)
590 size = dev->isoc_in.maxsize;
592 dev->isoc_ctl.max_pkt_size = size;
594 max_packets = TM6000_MAX_ISO_PACKETS;
595 sb_size = max_packets * size;
596 dev->urb_size = sb_size;
598 dev->isoc_ctl.num_bufs = num_bufs;
600 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
601 if (!dev->isoc_ctl.urb) {
602 tm6000_err("cannot alloc memory for usb buffers\n");
606 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
608 if (!dev->isoc_ctl.transfer_buffer) {
609 tm6000_err("cannot allocate memory for usbtransfer\n");
610 kfree(dev->isoc_ctl.urb);
614 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets (%d bytes) of %d bytes each to handle %u size\n",
615 max_packets, num_bufs, sb_size,
616 dev->isoc_in.maxsize, size);
619 if (tm6000_alloc_urb_buffers(dev) < 0) {
620 tm6000_err("cannot allocate memory for urb buffers\n");
622 /* call free, as some buffers might have been allocated */
623 tm6000_free_urb_buffers(dev);
624 kfree(dev->isoc_ctl.urb);
625 kfree(dev->isoc_ctl.transfer_buffer);
629 /* allocate urbs and transfer buffers */
630 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
631 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
633 tm6000_uninit_isoc(dev);
634 tm6000_free_urb_buffers(dev);
637 dev->isoc_ctl.urb[i] = urb;
639 urb->transfer_dma = dev->urb_dma[i];
640 dev->isoc_ctl.transfer_buffer[i] = dev->urb_buffer[i];
642 usb_fill_bulk_urb(urb, dev->udev, pipe,
643 dev->isoc_ctl.transfer_buffer[i], sb_size,
644 tm6000_irq_callback, dma_q);
645 urb->interval = dev->isoc_in.endp->desc.bInterval;
646 urb->number_of_packets = max_packets;
647 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
649 for (j = 0; j < max_packets; j++) {
650 urb->iso_frame_desc[j].offset = size * j;
651 urb->iso_frame_desc[j].length = size;
658 static int tm6000_start_thread(struct tm6000_core *dev)
660 struct tm6000_dmaqueue *dma_q = &dev->vidq;
664 dma_q->ini_jiffies = jiffies;
666 init_waitqueue_head(&dma_q->wq);
668 /* submit urbs and enables IRQ */
669 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
670 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
672 tm6000_err("submit of urb %i failed (error=%i)\n", i,
674 tm6000_uninit_isoc(dev);
682 /* ------------------------------------------------------------------
683 * Videobuf operations
684 * ------------------------------------------------------------------
688 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
690 struct tm6000_fh *fh = vq->priv_data;
692 *size = fh->fmt->depth * fh->width * fh->height >> 3;
694 *count = TM6000_DEF_BUF;
696 if (*count < TM6000_MIN_BUF)
697 *count = TM6000_MIN_BUF;
699 while (*size * *count > vid_limit * 1024 * 1024)
705 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
707 struct tm6000_fh *fh = vq->priv_data;
708 struct tm6000_core *dev = fh->dev;
711 BUG_ON(in_interrupt());
713 /* We used to wait for the buffer to finish here, but this didn't work
714 because, as we were keeping the state as VIDEOBUF_QUEUED,
715 videobuf_queue_cancel marked it as finished for us.
716 (Also, it could wedge forever if the hardware was misconfigured.)
718 This should be safe; by the time we get here, the buffer isn't
719 queued anymore. If we ever start marking the buffers as
720 VIDEOBUF_ACTIVE, it won't be, though.
722 spin_lock_irqsave(&dev->slock, flags);
723 if (dev->isoc_ctl.buf == buf)
724 dev->isoc_ctl.buf = NULL;
725 spin_unlock_irqrestore(&dev->slock, flags);
727 videobuf_vmalloc_free(&buf->vb);
728 buf->vb.state = VIDEOBUF_NEEDS_INIT;
732 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
733 enum v4l2_field field)
735 struct tm6000_fh *fh = vq->priv_data;
736 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
737 struct tm6000_core *dev = fh->dev;
740 BUG_ON(NULL == fh->fmt);
743 /* FIXME: It assumes depth=2 */
744 /* The only currently supported format is 16 bits/pixel */
745 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
746 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
749 if (buf->fmt != fh->fmt ||
750 buf->vb.width != fh->width ||
751 buf->vb.height != fh->height ||
752 buf->vb.field != field) {
754 buf->vb.width = fh->width;
755 buf->vb.height = fh->height;
756 buf->vb.field = field;
757 buf->vb.state = VIDEOBUF_NEEDS_INIT;
760 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
761 rc = videobuf_iolock(vq, &buf->vb, NULL);
766 if (!dev->isoc_ctl.num_bufs) {
767 rc = tm6000_prepare_isoc(dev);
771 rc = tm6000_start_thread(dev);
777 buf->vb.state = VIDEOBUF_PREPARED;
781 free_buffer(vq, buf);
786 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
788 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
789 struct tm6000_fh *fh = vq->priv_data;
790 struct tm6000_core *dev = fh->dev;
791 struct tm6000_dmaqueue *vidq = &dev->vidq;
793 buf->vb.state = VIDEOBUF_QUEUED;
794 list_add_tail(&buf->vb.queue, &vidq->active);
797 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
799 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
801 free_buffer(vq, buf);
804 static struct videobuf_queue_ops tm6000_video_qops = {
805 .buf_setup = buffer_setup,
806 .buf_prepare = buffer_prepare,
807 .buf_queue = buffer_queue,
808 .buf_release = buffer_release,
811 /* ------------------------------------------------------------------
813 * ------------------------------------------------------------------
816 static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
818 /* Is the current fh handling it? if so, that's OK */
819 if (dev->resources == fh && dev->is_res_read)
825 static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
827 /* Is the current fh handling it? if so, that's OK */
828 if (dev->resources == fh)
834 static bool res_get(struct tm6000_core *dev, struct tm6000_fh *fh,
837 /* Is the current fh handling it? if so, that's OK */
838 if (dev->resources == fh && dev->is_res_read == is_res_read)
847 dev->is_res_read = is_res_read;
848 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
852 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
854 /* Is the current fh handling it? if so, that's OK */
855 if (dev->resources != fh)
858 dev->resources = NULL;
859 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
862 /* ------------------------------------------------------------------
863 * IOCTL vidioc handling
864 * ------------------------------------------------------------------
866 static int vidioc_querycap(struct file *file, void *priv,
867 struct v4l2_capability *cap)
869 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
870 struct video_device *vdev = video_devdata(file);
872 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
873 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
874 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
875 if (dev->tuner_type != TUNER_ABSENT)
876 cap->device_caps |= V4L2_CAP_TUNER;
877 if (vdev->vfl_type == VFL_TYPE_GRABBER)
878 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
882 cap->device_caps |= V4L2_CAP_RADIO;
883 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
884 V4L2_CAP_RADIO | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
889 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
890 struct v4l2_fmtdesc *f)
892 if (f->index >= ARRAY_SIZE(format))
895 strlcpy(f->description, format[f->index].name, sizeof(f->description));
896 f->pixelformat = format[f->index].fourcc;
900 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
901 struct v4l2_format *f)
903 struct tm6000_fh *fh = priv;
905 f->fmt.pix.width = fh->width;
906 f->fmt.pix.height = fh->height;
907 f->fmt.pix.field = fh->vb_vidq.field;
908 f->fmt.pix.pixelformat = fh->fmt->fourcc;
909 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
910 f->fmt.pix.bytesperline =
911 (f->fmt.pix.width * fh->fmt->depth) >> 3;
912 f->fmt.pix.sizeimage =
913 f->fmt.pix.height * f->fmt.pix.bytesperline;
918 static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
922 for (i = 0; i < ARRAY_SIZE(format); i++)
923 if (format[i].fourcc == fourcc)
928 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
929 struct v4l2_format *f)
931 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
932 struct tm6000_fmt *fmt;
933 enum v4l2_field field;
935 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
937 dprintk(dev, 2, "Fourcc format (0x%08x) invalid.\n",
938 f->fmt.pix.pixelformat);
942 field = f->fmt.pix.field;
944 field = V4L2_FIELD_INTERLACED;
946 tm6000_get_std_res(dev);
948 f->fmt.pix.width = dev->width;
949 f->fmt.pix.height = dev->height;
951 f->fmt.pix.width &= ~0x01;
953 f->fmt.pix.field = field;
955 f->fmt.pix.bytesperline =
956 (f->fmt.pix.width * fmt->depth) >> 3;
957 f->fmt.pix.sizeimage =
958 f->fmt.pix.height * f->fmt.pix.bytesperline;
959 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
964 /*FIXME: This seems to be generic enough to be at videodev2 */
965 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
966 struct v4l2_format *f)
968 struct tm6000_fh *fh = priv;
969 struct tm6000_core *dev = fh->dev;
970 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
974 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
975 fh->width = f->fmt.pix.width;
976 fh->height = f->fmt.pix.height;
977 fh->vb_vidq.field = f->fmt.pix.field;
980 dev->fourcc = f->fmt.pix.pixelformat;
982 tm6000_set_fourcc_format(dev);
987 static int vidioc_reqbufs(struct file *file, void *priv,
988 struct v4l2_requestbuffers *p)
990 struct tm6000_fh *fh = priv;
992 return videobuf_reqbufs(&fh->vb_vidq, p);
995 static int vidioc_querybuf(struct file *file, void *priv,
996 struct v4l2_buffer *p)
998 struct tm6000_fh *fh = priv;
1000 return videobuf_querybuf(&fh->vb_vidq, p);
1003 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1005 struct tm6000_fh *fh = priv;
1007 return videobuf_qbuf(&fh->vb_vidq, p);
1010 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1012 struct tm6000_fh *fh = priv;
1014 return videobuf_dqbuf(&fh->vb_vidq, p,
1015 file->f_flags & O_NONBLOCK);
1018 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1020 struct tm6000_fh *fh = priv;
1021 struct tm6000_core *dev = fh->dev;
1023 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1028 if (!res_get(dev, fh, false))
1030 return videobuf_streamon(&fh->vb_vidq);
1033 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1035 struct tm6000_fh *fh = priv;
1036 struct tm6000_core *dev = fh->dev;
1038 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1044 videobuf_streamoff(&fh->vb_vidq);
1050 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1053 struct tm6000_fh *fh = priv;
1054 struct tm6000_core *dev = fh->dev;
1057 rc = tm6000_init_analog_mode(dev);
1059 fh->width = dev->width;
1060 fh->height = dev->height;
1065 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_std, dev->norm);
1070 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1072 struct tm6000_fh *fh = priv;
1073 struct tm6000_core *dev = fh->dev;
1079 static const char *iname[] = {
1080 [TM6000_INPUT_TV] = "Television",
1081 [TM6000_INPUT_COMPOSITE1] = "Composite 1",
1082 [TM6000_INPUT_COMPOSITE2] = "Composite 2",
1083 [TM6000_INPUT_SVIDEO] = "S-Video",
1086 static int vidioc_enum_input(struct file *file, void *priv,
1087 struct v4l2_input *i)
1089 struct tm6000_fh *fh = priv;
1090 struct tm6000_core *dev = fh->dev;
1097 if (!dev->vinput[n].type)
1102 if (dev->vinput[n].type == TM6000_INPUT_TV)
1103 i->type = V4L2_INPUT_TYPE_TUNER;
1105 i->type = V4L2_INPUT_TYPE_CAMERA;
1107 strcpy(i->name, iname[dev->vinput[n].type]);
1109 i->std = TM6000_STD;
1114 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1116 struct tm6000_fh *fh = priv;
1117 struct tm6000_core *dev = fh->dev;
1124 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1126 struct tm6000_fh *fh = priv;
1127 struct tm6000_core *dev = fh->dev;
1132 if (!dev->vinput[i].type)
1137 rc = vidioc_s_std(file, priv, dev->norm);
1142 /* --- controls ---------------------------------------------- */
1144 static int tm6000_s_ctrl(struct v4l2_ctrl *ctrl)
1146 struct tm6000_core *dev = container_of(ctrl->handler, struct tm6000_core, ctrl_handler);
1150 case V4L2_CID_CONTRAST:
1151 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1153 case V4L2_CID_BRIGHTNESS:
1154 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1156 case V4L2_CID_SATURATION:
1157 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1160 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1166 static const struct v4l2_ctrl_ops tm6000_ctrl_ops = {
1167 .s_ctrl = tm6000_s_ctrl,
1170 static int tm6000_radio_s_ctrl(struct v4l2_ctrl *ctrl)
1172 struct tm6000_core *dev = container_of(ctrl->handler,
1173 struct tm6000_core, radio_ctrl_handler);
1177 case V4L2_CID_AUDIO_MUTE:
1178 dev->ctl_mute = val;
1179 tm6000_tvaudio_set_mute(dev, val);
1181 case V4L2_CID_AUDIO_VOLUME:
1182 dev->ctl_volume = val;
1183 tm6000_set_volume(dev, val);
1189 static const struct v4l2_ctrl_ops tm6000_radio_ctrl_ops = {
1190 .s_ctrl = tm6000_radio_s_ctrl,
1193 static int vidioc_g_tuner(struct file *file, void *priv,
1194 struct v4l2_tuner *t)
1196 struct tm6000_fh *fh = priv;
1197 struct tm6000_core *dev = fh->dev;
1199 if (UNSET == dev->tuner_type)
1204 strcpy(t->name, "Television");
1205 t->type = V4L2_TUNER_ANALOG_TV;
1206 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO;
1207 t->rangehigh = 0xffffffffUL;
1208 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1210 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1212 t->audmode = dev->amode;
1217 static int vidioc_s_tuner(struct file *file, void *priv,
1218 const struct v4l2_tuner *t)
1220 struct tm6000_fh *fh = priv;
1221 struct tm6000_core *dev = fh->dev;
1223 if (UNSET == dev->tuner_type)
1228 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1229 dev->amode = V4L2_TUNER_MODE_STEREO;
1231 dev->amode = t->audmode;
1232 dprintk(dev, 3, "audio mode: %x\n", t->audmode);
1234 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1239 static int vidioc_g_frequency(struct file *file, void *priv,
1240 struct v4l2_frequency *f)
1242 struct tm6000_fh *fh = priv;
1243 struct tm6000_core *dev = fh->dev;
1245 if (UNSET == dev->tuner_type)
1250 f->frequency = dev->freq;
1252 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1257 static int vidioc_s_frequency(struct file *file, void *priv,
1258 const struct v4l2_frequency *f)
1260 struct tm6000_fh *fh = priv;
1261 struct tm6000_core *dev = fh->dev;
1263 if (UNSET == dev->tuner_type)
1268 dev->freq = f->frequency;
1269 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1274 static int radio_g_tuner(struct file *file, void *priv,
1275 struct v4l2_tuner *t)
1277 struct tm6000_fh *fh = file->private_data;
1278 struct tm6000_core *dev = fh->dev;
1283 memset(t, 0, sizeof(*t));
1284 strcpy(t->name, "Radio");
1285 t->type = V4L2_TUNER_RADIO;
1286 t->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
1287 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1288 t->audmode = V4L2_TUNER_MODE_STEREO;
1290 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1295 static int radio_s_tuner(struct file *file, void *priv,
1296 const struct v4l2_tuner *t)
1298 struct tm6000_fh *fh = file->private_data;
1299 struct tm6000_core *dev = fh->dev;
1303 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1307 /* ------------------------------------------------------------------
1308 File operations for the device
1309 ------------------------------------------------------------------*/
1311 static int __tm6000_open(struct file *file)
1313 struct video_device *vdev = video_devdata(file);
1314 struct tm6000_core *dev = video_drvdata(file);
1315 struct tm6000_fh *fh;
1316 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1320 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1321 video_device_node_name(vdev));
1323 switch (vdev->vfl_type) {
1324 case VFL_TYPE_GRABBER:
1325 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1328 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1330 case VFL_TYPE_RADIO:
1335 /* If more than one user, mutex should be added */
1338 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1339 video_device_node_name(vdev), v4l2_type_names[type],
1342 /* allocate + initialize per filehandle data */
1343 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1349 v4l2_fh_init(&fh->fh, vdev);
1350 file->private_data = fh;
1355 dev->fourcc = format[0].fourcc;
1357 fh->fmt = format_by_fourcc(dev->fourcc);
1359 tm6000_get_std_res(dev);
1361 fh->width = dev->width;
1362 fh->height = dev->height;
1364 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1365 (unsigned long)fh, (unsigned long)dev,
1366 (unsigned long)&dev->vidq);
1367 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty queued=%d\n",
1368 list_empty(&dev->vidq.queued));
1369 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty active=%d\n",
1370 list_empty(&dev->vidq.active));
1372 /* initialize hardware on analog mode */
1373 rc = tm6000_init_analog_mode(dev);
1375 v4l2_fh_exit(&fh->fh);
1380 dev->mode = TM6000_MODE_ANALOG;
1383 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1386 V4L2_FIELD_INTERLACED,
1387 sizeof(struct tm6000_buffer), fh, &dev->lock);
1389 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1390 tm6000_set_audio_rinput(dev);
1391 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1392 tm6000_prepare_isoc(dev);
1393 tm6000_start_thread(dev);
1395 v4l2_fh_add(&fh->fh);
1400 static int tm6000_open(struct file *file)
1402 struct video_device *vdev = video_devdata(file);
1405 mutex_lock(vdev->lock);
1406 res = __tm6000_open(file);
1407 mutex_unlock(vdev->lock);
1412 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1414 struct tm6000_fh *fh = file->private_data;
1415 struct tm6000_core *dev = fh->dev;
1417 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1420 if (!res_get(fh->dev, fh, true))
1423 if (mutex_lock_interruptible(&dev->lock))
1424 return -ERESTARTSYS;
1425 res = videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1426 file->f_flags & O_NONBLOCK);
1427 mutex_unlock(&dev->lock);
1434 __tm6000_poll(struct file *file, struct poll_table_struct *wait)
1436 unsigned long req_events = poll_requested_events(wait);
1437 struct tm6000_fh *fh = file->private_data;
1438 struct tm6000_buffer *buf;
1441 if (v4l2_event_pending(&fh->fh))
1443 else if (req_events & POLLPRI)
1444 poll_wait(file, &fh->fh.wait, wait);
1445 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1446 return res | POLLERR;
1448 if (!!is_res_streaming(fh->dev, fh))
1449 return res | POLLERR;
1451 if (!is_res_read(fh->dev, fh)) {
1452 /* streaming capture */
1453 if (list_empty(&fh->vb_vidq.stream))
1454 return res | POLLERR;
1455 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
1456 poll_wait(file, &buf->vb.done, wait);
1457 if (buf->vb.state == VIDEOBUF_DONE ||
1458 buf->vb.state == VIDEOBUF_ERROR)
1459 return res | POLLIN | POLLRDNORM;
1460 } else if (req_events & (POLLIN | POLLRDNORM)) {
1461 /* read() capture */
1462 return res | videobuf_poll_stream(file, &fh->vb_vidq, wait);
1467 static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
1469 struct tm6000_fh *fh = file->private_data;
1470 struct tm6000_core *dev = fh->dev;
1473 mutex_lock(&dev->lock);
1474 res = __tm6000_poll(file, wait);
1475 mutex_unlock(&dev->lock);
1479 static int tm6000_release(struct file *file)
1481 struct tm6000_fh *fh = file->private_data;
1482 struct tm6000_core *dev = fh->dev;
1483 struct video_device *vdev = video_devdata(file);
1485 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1486 video_device_node_name(vdev), dev->users);
1488 mutex_lock(&dev->lock);
1494 tm6000_uninit_isoc(dev);
1496 /* Stop interrupt USB pipe */
1497 tm6000_ir_int_stop(dev);
1499 usb_reset_configuration(dev->udev);
1501 if (dev->int_in.endp)
1502 usb_set_interface(dev->udev,
1503 dev->isoc_in.bInterfaceNumber, 2);
1505 usb_set_interface(dev->udev,
1506 dev->isoc_in.bInterfaceNumber, 0);
1508 /* Start interrupt USB pipe */
1509 tm6000_ir_int_start(dev);
1512 videobuf_mmap_free(&fh->vb_vidq);
1514 v4l2_fh_del(&fh->fh);
1515 v4l2_fh_exit(&fh->fh);
1517 mutex_unlock(&dev->lock);
1522 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1524 struct tm6000_fh *fh = file->private_data;
1525 struct tm6000_core *dev = fh->dev;
1528 if (mutex_lock_interruptible(&dev->lock))
1529 return -ERESTARTSYS;
1530 res = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1531 mutex_unlock(&dev->lock);
1535 static const struct v4l2_file_operations tm6000_fops = {
1536 .owner = THIS_MODULE,
1537 .open = tm6000_open,
1538 .release = tm6000_release,
1539 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1540 .read = tm6000_read,
1541 .poll = tm6000_poll,
1542 .mmap = tm6000_mmap,
1545 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1546 .vidioc_querycap = vidioc_querycap,
1547 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1548 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1549 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1550 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1551 .vidioc_s_std = vidioc_s_std,
1552 .vidioc_g_std = vidioc_g_std,
1553 .vidioc_enum_input = vidioc_enum_input,
1554 .vidioc_g_input = vidioc_g_input,
1555 .vidioc_s_input = vidioc_s_input,
1556 .vidioc_g_tuner = vidioc_g_tuner,
1557 .vidioc_s_tuner = vidioc_s_tuner,
1558 .vidioc_g_frequency = vidioc_g_frequency,
1559 .vidioc_s_frequency = vidioc_s_frequency,
1560 .vidioc_streamon = vidioc_streamon,
1561 .vidioc_streamoff = vidioc_streamoff,
1562 .vidioc_reqbufs = vidioc_reqbufs,
1563 .vidioc_querybuf = vidioc_querybuf,
1564 .vidioc_qbuf = vidioc_qbuf,
1565 .vidioc_dqbuf = vidioc_dqbuf,
1566 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1567 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1570 static struct video_device tm6000_template = {
1572 .fops = &tm6000_fops,
1573 .ioctl_ops = &video_ioctl_ops,
1574 .release = video_device_release_empty,
1575 .tvnorms = TM6000_STD,
1578 static const struct v4l2_file_operations radio_fops = {
1579 .owner = THIS_MODULE,
1580 .open = tm6000_open,
1581 .poll = v4l2_ctrl_poll,
1582 .release = tm6000_release,
1583 .unlocked_ioctl = video_ioctl2,
1586 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1587 .vidioc_querycap = vidioc_querycap,
1588 .vidioc_g_tuner = radio_g_tuner,
1589 .vidioc_s_tuner = radio_s_tuner,
1590 .vidioc_g_frequency = vidioc_g_frequency,
1591 .vidioc_s_frequency = vidioc_s_frequency,
1592 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1593 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1596 static struct video_device tm6000_radio_template = {
1598 .fops = &radio_fops,
1599 .ioctl_ops = &radio_ioctl_ops,
1602 /* -----------------------------------------------------------------
1603 * Initialization and module stuff
1604 * ------------------------------------------------------------------
1607 static void vdev_init(struct tm6000_core *dev,
1608 struct video_device *vfd,
1609 const struct video_device
1610 *template, const char *type_name)
1613 vfd->v4l2_dev = &dev->v4l2_dev;
1614 vfd->release = video_device_release_empty;
1615 vfd->lock = &dev->lock;
1617 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1619 video_set_drvdata(vfd, dev);
1622 int tm6000_v4l2_register(struct tm6000_core *dev)
1626 v4l2_ctrl_handler_init(&dev->ctrl_handler, 6);
1627 v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 2);
1628 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1629 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
1630 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1631 V4L2_CID_AUDIO_VOLUME, -15, 15, 1, 0);
1632 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1633 V4L2_CID_BRIGHTNESS, 0, 255, 1, 54);
1634 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1635 V4L2_CID_CONTRAST, 0, 255, 1, 119);
1636 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1637 V4L2_CID_SATURATION, 0, 255, 1, 112);
1638 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1639 V4L2_CID_HUE, -128, 127, 1, 0);
1640 v4l2_ctrl_add_handler(&dev->ctrl_handler,
1641 &dev->radio_ctrl_handler, NULL);
1643 if (dev->radio_ctrl_handler.error)
1644 ret = dev->radio_ctrl_handler.error;
1645 if (!ret && dev->ctrl_handler.error)
1646 ret = dev->ctrl_handler.error;
1650 vdev_init(dev, &dev->vfd, &tm6000_template, "video");
1652 dev->vfd.ctrl_handler = &dev->ctrl_handler;
1654 /* init video dma queues */
1655 INIT_LIST_HEAD(&dev->vidq.active);
1656 INIT_LIST_HEAD(&dev->vidq.queued);
1658 ret = video_register_device(&dev->vfd, VFL_TYPE_GRABBER, video_nr);
1661 printk(KERN_INFO "%s: can't register video device\n",
1666 printk(KERN_INFO "%s: registered device %s\n",
1667 dev->name, video_device_node_name(&dev->vfd));
1669 if (dev->caps.has_radio) {
1670 vdev_init(dev, &dev->radio_dev, &tm6000_radio_template,
1672 dev->radio_dev.ctrl_handler = &dev->radio_ctrl_handler;
1673 ret = video_register_device(&dev->radio_dev, VFL_TYPE_RADIO,
1676 printk(KERN_INFO "%s: can't register radio device\n",
1681 printk(KERN_INFO "%s: registered device %s\n",
1682 dev->name, video_device_node_name(&dev->radio_dev));
1685 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1689 video_unregister_device(&dev->vfd);
1691 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1692 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
1696 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1698 video_unregister_device(&dev->vfd);
1700 /* if URB buffers are still allocated free them now */
1701 tm6000_free_urb_buffers(dev);
1703 video_unregister_device(&dev->radio_dev);
1707 int tm6000_v4l2_exit(void)
1712 module_param(video_nr, int, 0);
1713 MODULE_PARM_DESC(video_nr, "Allow changing video device number");
1715 module_param_named(debug, tm6000_debug, int, 0444);
1716 MODULE_PARM_DESC(debug, "activates debug info");
1718 module_param(vid_limit, int, 0644);
1719 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
1721 module_param(keep_urb, bool, 0);
1722 MODULE_PARM_DESC(keep_urb, "Keep urb buffers allocated even when the device is closed by the user");