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.
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/ioport.h>
30 #include <linux/init.h>
31 #include <linux/sched.h>
32 #include <linux/random.h>
33 #include <linux/version.h>
34 #include <linux/usb.h>
35 #include <linux/videodev2.h>
36 #include <media/v4l2-ioctl.h>
37 #include <linux/interrupt.h>
38 #include <linux/kthread.h>
39 #include <linux/highmem.h>
40 #include <linux/freezer.h>
42 #include "tm6000-regs.h"
45 #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
47 /* Limits minimum and default number of buffers */
48 #define TM6000_MIN_BUF 4
49 #define TM6000_DEF_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 */
60 EXPORT_SYMBOL_GPL(tm6000_debug);
62 static const struct v4l2_queryctrl no_ctrl = {
64 .flags = V4L2_CTRL_FLAG_DISABLED,
67 /* supported controls */
68 static struct v4l2_queryctrl tm6000_qctrl[] = {
70 .id = V4L2_CID_BRIGHTNESS,
71 .type = V4L2_CTRL_TYPE_INTEGER,
79 .id = V4L2_CID_CONTRAST,
80 .type = V4L2_CTRL_TYPE_INTEGER,
88 .id = V4L2_CID_SATURATION,
89 .type = V4L2_CTRL_TYPE_INTEGER,
98 .type = V4L2_CTRL_TYPE_INTEGER,
108 .id = V4L2_CID_AUDIO_MUTE,
112 .type = V4L2_CTRL_TYPE_BOOLEAN,
114 .id = V4L2_CID_AUDIO_VOLUME,
120 .type = V4L2_CTRL_TYPE_INTEGER,
124 static const unsigned int CTRLS = ARRAY_SIZE(tm6000_qctrl);
125 static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
127 static struct tm6000_fmt format[] = {
129 .name = "4:2:2, packed, YVY2",
130 .fourcc = V4L2_PIX_FMT_YUYV,
133 .name = "4:2:2, packed, UYVY",
134 .fourcc = V4L2_PIX_FMT_UYVY,
137 .name = "A/V + VBI mux packet",
138 .fourcc = V4L2_PIX_FMT_TM6000,
143 static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
147 for (i = 0; i < CTRLS; i++)
148 if (tm6000_qctrl[i].id == id)
149 return tm6000_qctrl+i;
153 /* ------------------------------------------------------------------
154 * DMA and thread functions
155 * ------------------------------------------------------------------
158 #define norm_maxw(a) 720
159 #define norm_maxh(a) 576
161 #define norm_minw(a) norm_maxw(a)
162 #define norm_minh(a) norm_maxh(a)
165 * video-buf generic routine to get the next available buffer
167 static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
168 struct tm6000_buffer **buf)
170 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
173 if (list_empty(&dma_q->active)) {
174 dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
179 *buf = list_entry(dma_q->active.next,
180 struct tm6000_buffer, vb.queue);
185 /* Cleans up buffer - Useful for testing for frame/URB loss */
186 outp = videobuf_to_vmalloc(&(*buf)->vb);
192 * Announces that a buffer were filled and request the next
194 static inline void buffer_filled(struct tm6000_core *dev,
195 struct tm6000_dmaqueue *dma_q,
196 struct tm6000_buffer *buf)
198 /* Advice that buffer was filled */
199 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
200 buf->vb.state = VIDEOBUF_DONE;
201 buf->vb.field_count++;
202 do_gettimeofday(&buf->vb.ts);
204 list_del(&buf->vb.queue);
205 wake_up(&buf->vb.done);
208 const char *tm6000_msg_type[] = {
209 "unknown(0)", /* 0 */
215 "unknown(6)", /* 6 */
216 "unknown(7)", /* 7 */
220 * Identify the tm5600/6000 buffer header type and properly handles
222 static int copy_streams(u8 *data, unsigned long len,
225 struct tm6000_dmaqueue *dma_q = urb->context;
226 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
227 u8 *ptr = data, *endp = data+len, c;
228 unsigned long header = 0;
230 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
231 struct tm6000_buffer *vbuf;
233 unsigned int linewidth;
236 /* get video buffer */
237 get_next_buf(dma_q, &vbuf);
241 voutp = videobuf_to_vmalloc(&vbuf->vb);
247 for (ptr = data; ptr < endp;) {
248 if (!dev->isoc_ctl.cmd) {
250 if (dev->isoc_ctl.tmp_buf_len > 0) {
251 /* from last urb or packet */
252 header = dev->isoc_ctl.tmp_buf;
253 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
254 memcpy((u8 *)&header +
255 dev->isoc_ctl.tmp_buf_len,
257 4 - dev->isoc_ctl.tmp_buf_len);
258 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
260 dev->isoc_ctl.tmp_buf_len = 0;
262 if (ptr + 3 >= endp) {
263 /* have incomplete header */
264 dev->isoc_ctl.tmp_buf_len = endp - ptr;
265 memcpy(&dev->isoc_ctl.tmp_buf, ptr,
266 dev->isoc_ctl.tmp_buf_len);
270 for (; ptr < endp - 3; ptr++) {
271 if (*(ptr + 3) == 0x47)
274 /* Get message header */
275 header = *(unsigned long *)ptr;
279 /* split the header fields */
280 c = (header >> 24) & 0xff;
281 size = ((header & 0x7e) << 1);
284 block = (header >> 7) & 0xf;
285 field = (header >> 11) & 0x1;
286 line = (header >> 12) & 0x1ff;
287 cmd = (header >> 21) & 0x7;
288 /* Validates haeder fields */
289 if (size > TM6000_URB_MSG_LEN)
290 size = TM6000_URB_MSG_LEN;
291 pktsize = TM6000_URB_MSG_LEN;
292 /* calculate position in buffer
293 * and change the buffer
296 case TM6000_URB_MSG_VIDEO:
298 if ((dev->isoc_ctl.vfield != field) &&
300 /* Announces that a new buffer
303 buffer_filled(dev, dma_q, vbuf);
304 dprintk(dev, V4L2_DEBUG_ISOC,
305 "new buffer filled\n");
306 get_next_buf(dma_q, &vbuf);
309 voutp = videobuf_to_vmalloc(&vbuf->vb);
312 memset(voutp, 0, vbuf->vb.size);
314 linewidth = vbuf->vb.width << 1;
315 pos = ((line << 1) - field - 1) *
316 linewidth + block * TM6000_URB_MSG_LEN;
317 /* Don't allow to write out of the buffer */
318 if (pos + size > vbuf->vb.size)
319 cmd = TM6000_URB_MSG_ERR;
320 dev->isoc_ctl.vfield = field;
323 case TM6000_URB_MSG_VBI:
325 case TM6000_URB_MSG_AUDIO:
326 case TM6000_URB_MSG_PTS:
327 size = pktsize; /* Size is always 180 bytes */
331 /* Continue the last copy */
332 cmd = dev->isoc_ctl.cmd;
333 size = dev->isoc_ctl.size;
334 pos = dev->isoc_ctl.pos;
335 pktsize = dev->isoc_ctl.pktsize;
337 cpysize = (endp - ptr > size) ? size : endp - ptr;
339 /* copy data in different buffers */
341 case TM6000_URB_MSG_VIDEO:
342 /* Fills video buffer */
344 memcpy(&voutp[pos], ptr, cpysize);
346 case TM6000_URB_MSG_AUDIO:
347 /* Need some code to copy audio buffer */
348 if (dev->fourcc == V4L2_PIX_FMT_YUYV) {
349 /* Swap word bytes */
352 for (i = 0; i < cpysize; i += 2)
353 swab16s((u16 *)(ptr + i));
355 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
357 case TM6000_URB_MSG_VBI:
358 /* Need some code to copy vbi buffer */
360 case TM6000_URB_MSG_PTS:
361 /* Need some code to copy pts */
365 if (ptr + pktsize > endp) {
366 /* End of URB packet, but cmd processing is not
367 * complete. Preserve the state for a next packet
369 dev->isoc_ctl.pos = pos + cpysize;
370 dev->isoc_ctl.size = size - cpysize;
371 dev->isoc_ctl.cmd = cmd;
372 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
375 dev->isoc_ctl.cmd = 0;
383 * Identify the tm5600/6000 buffer header type and properly handles
385 static int copy_multiplexed(u8 *ptr, unsigned long len,
388 struct tm6000_dmaqueue *dma_q = urb->context;
389 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
390 unsigned int pos = dev->isoc_ctl.pos, cpysize;
392 struct tm6000_buffer *buf;
395 get_next_buf(dma_q, &buf);
397 outp = videobuf_to_vmalloc(&buf->vb);
403 cpysize = min(len, buf->vb.size-pos);
404 memcpy(&outp[pos], ptr, cpysize);
408 if (pos >= buf->vb.size) {
410 /* Announces that a new buffer were filled */
411 buffer_filled(dev, dma_q, buf);
412 dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
413 get_next_buf(dma_q, &buf);
416 outp = videobuf_to_vmalloc(&(buf->vb));
423 dev->isoc_ctl.pos = pos;
427 static inline void print_err_status(struct tm6000_core *dev,
428 int packet, int status)
430 char *errmsg = "Unknown";
434 errmsg = "unlinked synchronuously";
437 errmsg = "unlinked asynchronuously";
440 errmsg = "Buffer error (overrun)";
443 errmsg = "Stalled (device not responding)";
446 errmsg = "Babble (bad cable?)";
449 errmsg = "Bit-stuff error (bad cable?)";
452 errmsg = "CRC/Timeout (could be anything)";
455 errmsg = "Device does not respond";
459 dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
462 dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
463 packet, status, errmsg);
469 * Controls the isoc copy of each urb packet
471 static inline int tm6000_isoc_copy(struct urb *urb)
473 struct tm6000_dmaqueue *dma_q = urb->context;
474 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
475 int i, len = 0, rc = 1, status;
478 if (urb->status < 0) {
479 print_err_status(dev, -1, urb->status);
483 for (i = 0; i < urb->number_of_packets; i++) {
484 status = urb->iso_frame_desc[i].status;
487 print_err_status(dev, i, status);
491 len = urb->iso_frame_desc[i].actual_length;
494 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
495 if (!urb->iso_frame_desc[i].status) {
496 if ((dev->fourcc) == V4L2_PIX_FMT_TM6000) {
497 rc = copy_multiplexed(p, len, urb);
501 copy_streams(p, len, urb);
509 /* ------------------------------------------------------------------
511 * ------------------------------------------------------------------
515 * IRQ callback, called by URB callback
517 static void tm6000_irq_callback(struct urb *urb)
519 struct tm6000_dmaqueue *dma_q = urb->context;
520 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
526 spin_lock(&dev->slock);
527 tm6000_isoc_copy(urb);
528 spin_unlock(&dev->slock);
530 /* Reset urb buffers */
531 for (i = 0; i < urb->number_of_packets; i++) {
532 urb->iso_frame_desc[i].status = 0;
533 urb->iso_frame_desc[i].actual_length = 0;
536 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
538 tm6000_err("urb resubmit failed (error=%i)\n",
543 * Stop and Deallocate URBs
545 static void tm6000_uninit_isoc(struct tm6000_core *dev)
550 dev->isoc_ctl.buf = NULL;
551 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
552 urb = dev->isoc_ctl.urb[i];
556 if (dev->isoc_ctl.transfer_buffer[i]) {
557 usb_free_coherent(dev->udev,
558 urb->transfer_buffer_length,
559 dev->isoc_ctl.transfer_buffer[i],
563 dev->isoc_ctl.urb[i] = NULL;
565 dev->isoc_ctl.transfer_buffer[i] = NULL;
568 kfree(dev->isoc_ctl.urb);
569 kfree(dev->isoc_ctl.transfer_buffer);
571 dev->isoc_ctl.urb = NULL;
572 dev->isoc_ctl.transfer_buffer = NULL;
573 dev->isoc_ctl.num_bufs = 0;
577 * Allocate URBs and start IRQ
579 static int tm6000_prepare_isoc(struct tm6000_core *dev)
581 struct tm6000_dmaqueue *dma_q = &dev->vidq;
582 int i, j, sb_size, pipe, size, max_packets, num_bufs = 8;
585 /* De-allocates all pending stuff */
586 tm6000_uninit_isoc(dev);
587 /* Stop interrupt USB pipe */
588 tm6000_ir_int_stop(dev);
590 usb_set_interface(dev->udev,
591 dev->isoc_in.bInterfaceNumber,
592 dev->isoc_in.bAlternateSetting);
594 /* Start interrupt USB pipe */
595 tm6000_ir_int_start(dev);
597 pipe = usb_rcvisocpipe(dev->udev,
598 dev->isoc_in.endp->desc.bEndpointAddress &
599 USB_ENDPOINT_NUMBER_MASK);
601 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
603 if (size > dev->isoc_in.maxsize)
604 size = dev->isoc_in.maxsize;
606 dev->isoc_ctl.max_pkt_size = size;
608 max_packets = TM6000_MAX_ISO_PACKETS;
609 sb_size = max_packets * size;
611 dev->isoc_ctl.num_bufs = num_bufs;
613 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
614 if (!dev->isoc_ctl.urb) {
615 tm6000_err("cannot alloc memory for usb buffers\n");
619 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
621 if (!dev->isoc_ctl.transfer_buffer) {
622 tm6000_err("cannot allocate memory for usbtransfer\n");
623 kfree(dev->isoc_ctl.urb);
627 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
628 " (%d bytes) of %d bytes each to handle %u size\n",
629 max_packets, num_bufs, sb_size,
630 dev->isoc_in.maxsize, size);
632 /* allocate urbs and transfer buffers */
633 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
634 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
636 tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
637 tm6000_uninit_isoc(dev);
641 dev->isoc_ctl.urb[i] = urb;
643 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
644 sb_size, GFP_KERNEL, &urb->transfer_dma);
645 if (!dev->isoc_ctl.transfer_buffer[i]) {
646 tm6000_err("unable to allocate %i bytes for transfer"
649 in_interrupt() ? " while in int" : "");
650 tm6000_uninit_isoc(dev);
653 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
655 usb_fill_bulk_urb(urb, dev->udev, pipe,
656 dev->isoc_ctl.transfer_buffer[i], sb_size,
657 tm6000_irq_callback, dma_q);
658 urb->interval = dev->isoc_in.endp->desc.bInterval;
659 urb->number_of_packets = max_packets;
660 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
662 for (j = 0; j < max_packets; j++) {
663 urb->iso_frame_desc[j].offset = size * j;
664 urb->iso_frame_desc[j].length = size;
671 static int tm6000_start_thread(struct tm6000_core *dev)
673 struct tm6000_dmaqueue *dma_q = &dev->vidq;
677 dma_q->ini_jiffies = jiffies;
679 init_waitqueue_head(&dma_q->wq);
681 /* submit urbs and enables IRQ */
682 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
683 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
685 tm6000_err("submit of urb %i failed (error=%i)\n", i,
687 tm6000_uninit_isoc(dev);
695 /* ------------------------------------------------------------------
696 * Videobuf operations
697 * ------------------------------------------------------------------
701 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
703 struct tm6000_fh *fh = vq->priv_data;
705 *size = fh->fmt->depth * fh->width * fh->height >> 3;
707 *count = TM6000_DEF_BUF;
709 if (*count < TM6000_MIN_BUF)
710 *count = TM6000_MIN_BUF;
712 while (*size * *count > vid_limit * 1024 * 1024)
718 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
720 struct tm6000_fh *fh = vq->priv_data;
721 struct tm6000_core *dev = fh->dev;
727 /* We used to wait for the buffer to finish here, but this didn't work
728 because, as we were keeping the state as VIDEOBUF_QUEUED,
729 videobuf_queue_cancel marked it as finished for us.
730 (Also, it could wedge forever if the hardware was misconfigured.)
732 This should be safe; by the time we get here, the buffer isn't
733 queued anymore. If we ever start marking the buffers as
734 VIDEOBUF_ACTIVE, it won't be, though.
736 spin_lock_irqsave(&dev->slock, flags);
737 if (dev->isoc_ctl.buf == buf)
738 dev->isoc_ctl.buf = NULL;
739 spin_unlock_irqrestore(&dev->slock, flags);
741 videobuf_vmalloc_free(&buf->vb);
742 buf->vb.state = VIDEOBUF_NEEDS_INIT;
746 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
747 enum v4l2_field field)
749 struct tm6000_fh *fh = vq->priv_data;
750 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
751 struct tm6000_core *dev = fh->dev;
752 int rc = 0, urb_init = 0;
754 BUG_ON(NULL == fh->fmt);
757 /* FIXME: It assumes depth=2 */
758 /* The only currently supported format is 16 bits/pixel */
759 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
760 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
763 if (buf->fmt != fh->fmt ||
764 buf->vb.width != fh->width ||
765 buf->vb.height != fh->height ||
766 buf->vb.field != field) {
768 buf->vb.width = fh->width;
769 buf->vb.height = fh->height;
770 buf->vb.field = field;
771 buf->vb.state = VIDEOBUF_NEEDS_INIT;
774 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
775 if (0 != (rc = videobuf_iolock(vq, &buf->vb, NULL)))
780 if (!dev->isoc_ctl.num_bufs)
784 rc = tm6000_prepare_isoc(dev);
788 rc = tm6000_start_thread(dev);
794 buf->vb.state = VIDEOBUF_PREPARED;
798 free_buffer(vq, buf);
803 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
805 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
806 struct tm6000_fh *fh = vq->priv_data;
807 struct tm6000_core *dev = fh->dev;
808 struct tm6000_dmaqueue *vidq = &dev->vidq;
810 buf->vb.state = VIDEOBUF_QUEUED;
811 list_add_tail(&buf->vb.queue, &vidq->active);
814 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
816 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
818 free_buffer(vq, buf);
821 static struct videobuf_queue_ops tm6000_video_qops = {
822 .buf_setup = buffer_setup,
823 .buf_prepare = buffer_prepare,
824 .buf_queue = buffer_queue,
825 .buf_release = buffer_release,
828 /* ------------------------------------------------------------------
830 * ------------------------------------------------------------------
833 static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
835 /* Is the current fh handling it? if so, that's OK */
836 if (dev->resources == fh && dev->is_res_read)
842 static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
844 /* Is the current fh handling it? if so, that's OK */
845 if (dev->resources == fh)
851 static bool res_get(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 && dev->is_res_read == is_res_read)
864 dev->is_res_read = is_res_read;
865 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
869 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
871 /* Is the current fh handling it? if so, that's OK */
872 if (dev->resources != fh)
875 dev->resources = NULL;
876 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
879 /* ------------------------------------------------------------------
880 * IOCTL vidioc handling
881 * ------------------------------------------------------------------
883 static int vidioc_querycap(struct file *file, void *priv,
884 struct v4l2_capability *cap)
887 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
888 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
889 cap->version = TM6000_VERSION;
890 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
897 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
898 struct v4l2_fmtdesc *f)
900 if (unlikely(f->index >= ARRAY_SIZE(format)))
903 strlcpy(f->description, format[f->index].name, sizeof(f->description));
904 f->pixelformat = format[f->index].fourcc;
908 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
909 struct v4l2_format *f)
911 struct tm6000_fh *fh = priv;
913 f->fmt.pix.width = fh->width;
914 f->fmt.pix.height = fh->height;
915 f->fmt.pix.field = fh->vb_vidq.field;
916 f->fmt.pix.pixelformat = fh->fmt->fourcc;
917 f->fmt.pix.bytesperline =
918 (f->fmt.pix.width * fh->fmt->depth) >> 3;
919 f->fmt.pix.sizeimage =
920 f->fmt.pix.height * f->fmt.pix.bytesperline;
925 static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
929 for (i = 0; i < ARRAY_SIZE(format); i++)
930 if (format[i].fourcc == fourcc)
935 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
936 struct v4l2_format *f)
938 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
939 struct tm6000_fmt *fmt;
940 enum v4l2_field field;
942 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
944 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)"
945 " invalid.\n", f->fmt.pix.pixelformat);
949 field = f->fmt.pix.field;
951 if (field == V4L2_FIELD_ANY)
952 field = V4L2_FIELD_SEQ_TB;
953 else if (V4L2_FIELD_INTERLACED != field) {
954 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
958 tm6000_get_std_res(dev);
960 f->fmt.pix.width = dev->width;
961 f->fmt.pix.height = dev->height;
963 f->fmt.pix.width &= ~0x01;
965 f->fmt.pix.field = field;
967 f->fmt.pix.bytesperline =
968 (f->fmt.pix.width * fmt->depth) >> 3;
969 f->fmt.pix.sizeimage =
970 f->fmt.pix.height * f->fmt.pix.bytesperline;
975 /*FIXME: This seems to be generic enough to be at videodev2 */
976 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
977 struct v4l2_format *f)
979 struct tm6000_fh *fh = priv;
980 struct tm6000_core *dev = fh->dev;
981 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
985 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
986 fh->width = f->fmt.pix.width;
987 fh->height = f->fmt.pix.height;
988 fh->vb_vidq.field = f->fmt.pix.field;
991 dev->fourcc = f->fmt.pix.pixelformat;
993 tm6000_set_fourcc_format(dev);
998 static int vidioc_reqbufs(struct file *file, void *priv,
999 struct v4l2_requestbuffers *p)
1001 struct tm6000_fh *fh = priv;
1003 return videobuf_reqbufs(&fh->vb_vidq, p);
1006 static int vidioc_querybuf(struct file *file, void *priv,
1007 struct v4l2_buffer *p)
1009 struct tm6000_fh *fh = priv;
1011 return videobuf_querybuf(&fh->vb_vidq, p);
1014 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1016 struct tm6000_fh *fh = priv;
1018 return videobuf_qbuf(&fh->vb_vidq, p);
1021 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1023 struct tm6000_fh *fh = priv;
1025 return videobuf_dqbuf(&fh->vb_vidq, p,
1026 file->f_flags & O_NONBLOCK);
1029 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1031 struct tm6000_fh *fh = priv;
1032 struct tm6000_core *dev = fh->dev;
1034 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1039 if (!res_get(dev, fh, false))
1041 return (videobuf_streamon(&fh->vb_vidq));
1044 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1046 struct tm6000_fh *fh=priv;
1047 struct tm6000_core *dev = fh->dev;
1049 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1054 videobuf_streamoff(&fh->vb_vidq);
1060 static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *norm)
1063 struct tm6000_fh *fh=priv;
1064 struct tm6000_core *dev = fh->dev;
1067 rc = tm6000_init_analog_mode(dev);
1069 fh->width = dev->width;
1070 fh->height = dev->height;
1075 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1080 static int vidioc_enum_input(struct file *file, void *priv,
1081 struct v4l2_input *inp)
1083 struct tm6000_fh *fh = priv;
1084 struct tm6000_core *dev = fh->dev;
1086 switch (inp->index) {
1087 case TM6000_INPUT_TV:
1088 inp->type = V4L2_INPUT_TYPE_TUNER;
1089 strcpy(inp->name, "Television");
1091 case TM6000_INPUT_COMPOSITE:
1092 if (dev->caps.has_input_comp) {
1093 inp->type = V4L2_INPUT_TYPE_CAMERA;
1094 strcpy(inp->name, "Composite");
1098 case TM6000_INPUT_SVIDEO:
1099 if (dev->caps.has_input_svid) {
1100 inp->type = V4L2_INPUT_TYPE_CAMERA;
1101 strcpy(inp->name, "S-Video");
1108 inp->std = TM6000_STD;
1113 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1115 struct tm6000_fh *fh = priv;
1116 struct tm6000_core *dev = fh->dev;
1122 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1124 struct tm6000_fh *fh = priv;
1125 struct tm6000_core *dev = fh->dev;
1130 case TM6000_INPUT_TV:
1134 case TM6000_INPUT_COMPOSITE:
1135 case TM6000_INPUT_SVIDEO:
1142 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR,
1143 REQ_03_SET_GET_MCU_PIN, 0x03, 1, buf, 1);
1147 rc = vidioc_s_std(file, priv, &dev->vfd->current_norm);
1153 /* --- controls ---------------------------------------------- */
1154 static int vidioc_queryctrl(struct file *file, void *priv,
1155 struct v4l2_queryctrl *qc)
1159 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1160 if (qc->id && qc->id == tm6000_qctrl[i].id) {
1161 memcpy(qc, &(tm6000_qctrl[i]),
1169 static int vidioc_g_ctrl(struct file *file, void *priv,
1170 struct v4l2_control *ctrl)
1172 struct tm6000_fh *fh = priv;
1173 struct tm6000_core *dev = fh->dev;
1176 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1178 case V4L2_CID_CONTRAST:
1179 val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0);
1181 case V4L2_CID_BRIGHTNESS:
1182 val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0);
1184 case V4L2_CID_SATURATION:
1185 val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0);
1188 val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0);
1190 case V4L2_CID_AUDIO_MUTE:
1191 val = dev->ctl_mute;
1193 case V4L2_CID_AUDIO_VOLUME:
1194 val = dev->ctl_volume;
1207 static int vidioc_s_ctrl(struct file *file, void *priv,
1208 struct v4l2_control *ctrl)
1210 struct tm6000_fh *fh = priv;
1211 struct tm6000_core *dev = fh->dev;
1212 u8 val = ctrl->value;
1215 case V4L2_CID_CONTRAST:
1216 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1218 case V4L2_CID_BRIGHTNESS:
1219 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1221 case V4L2_CID_SATURATION:
1222 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1225 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1227 case V4L2_CID_AUDIO_MUTE:
1228 dev->ctl_mute = val;
1229 tm6000_tvaudio_set_mute(dev, val);
1231 case V4L2_CID_AUDIO_VOLUME:
1232 dev->ctl_volume = val;
1233 tm6000_set_volume(dev, val);
1239 static int vidioc_g_tuner(struct file *file, void *priv,
1240 struct v4l2_tuner *t)
1242 struct tm6000_fh *fh = priv;
1243 struct tm6000_core *dev = fh->dev;
1245 if (unlikely(UNSET == dev->tuner_type))
1250 strcpy(t->name, "Television");
1251 t->type = V4L2_TUNER_ANALOG_TV;
1252 t->capability = V4L2_TUNER_CAP_NORM;
1253 t->rangehigh = 0xffffffffUL;
1254 t->rxsubchans = V4L2_TUNER_SUB_MONO;
1259 static int vidioc_s_tuner(struct file *file, void *priv,
1260 struct v4l2_tuner *t)
1262 struct tm6000_fh *fh = priv;
1263 struct tm6000_core *dev = fh->dev;
1265 if (UNSET == dev->tuner_type)
1273 static int vidioc_g_frequency(struct file *file, void *priv,
1274 struct v4l2_frequency *f)
1276 struct tm6000_fh *fh = priv;
1277 struct tm6000_core *dev = fh->dev;
1279 if (unlikely(UNSET == dev->tuner_type))
1282 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1283 f->frequency = dev->freq;
1285 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1290 static int vidioc_s_frequency(struct file *file, void *priv,
1291 struct v4l2_frequency *f)
1293 struct tm6000_fh *fh = priv;
1294 struct tm6000_core *dev = fh->dev;
1296 if (unlikely(UNSET == dev->tuner_type))
1298 if (unlikely(f->tuner != 0))
1300 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
1302 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1305 dev->freq = f->frequency;
1306 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1311 static int radio_querycap(struct file *file, void *priv,
1312 struct v4l2_capability *cap)
1314 struct tm6000_fh *fh = file->private_data;
1315 struct tm6000_core *dev = fh->dev;
1317 strcpy(cap->driver, "tm6000");
1318 strlcpy(cap->card, dev->name, sizeof(dev->name));
1319 sprintf(cap->bus_info, "USB%04x:%04x",
1320 le16_to_cpu(dev->udev->descriptor.idVendor),
1321 le16_to_cpu(dev->udev->descriptor.idProduct));
1322 cap->version = dev->dev_type;
1323 cap->capabilities = V4L2_CAP_TUNER;
1328 static int radio_g_tuner(struct file *file, void *priv,
1329 struct v4l2_tuner *t)
1331 struct tm6000_fh *fh = file->private_data;
1332 struct tm6000_core *dev = fh->dev;
1337 memset(t, 0, sizeof(*t));
1338 strcpy(t->name, "Radio");
1339 t->type = V4L2_TUNER_RADIO;
1341 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1343 if ((dev->aradio == TM6000_AIP_LINE1) ||
1344 (dev->aradio == TM6000_AIP_LINE2)) {
1345 t->rxsubchans = V4L2_TUNER_SUB_MONO;
1348 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1354 static int radio_s_tuner(struct file *file, void *priv,
1355 struct v4l2_tuner *t)
1357 struct tm6000_fh *fh = file->private_data;
1358 struct tm6000_core *dev = fh->dev;
1363 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1368 static int radio_enum_input(struct file *file, void *priv,
1369 struct v4l2_input *i)
1374 strcpy(i->name, "Radio");
1375 i->type = V4L2_INPUT_TYPE_TUNER;
1380 static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
1386 static int radio_g_audio(struct file *file, void *priv,
1387 struct v4l2_audio *a)
1389 memset(a, 0, sizeof(*a));
1390 strcpy(a->name, "Radio");
1394 static int radio_s_audio(struct file *file, void *priv,
1395 struct v4l2_audio *a)
1400 static int radio_s_input(struct file *filp, void *priv, unsigned int i)
1405 static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
1410 static int radio_queryctrl(struct file *file, void *priv,
1411 struct v4l2_queryctrl *c)
1413 const struct v4l2_queryctrl *ctrl;
1415 if (c->id < V4L2_CID_BASE ||
1416 c->id >= V4L2_CID_LASTP1)
1418 if (c->id == V4L2_CID_AUDIO_MUTE) {
1419 ctrl = ctrl_by_id(c->id);
1427 /* ------------------------------------------------------------------
1428 File operations for the device
1429 ------------------------------------------------------------------*/
1431 static int tm6000_open(struct file *file)
1433 struct video_device *vdev = video_devdata(file);
1434 struct tm6000_core *dev = video_drvdata(file);
1435 struct tm6000_fh *fh;
1436 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1440 printk(KERN_INFO "tm6000: open called (dev=%s)\n",
1441 video_device_node_name(vdev));
1443 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1444 video_device_node_name(vdev));
1446 switch (vdev->vfl_type) {
1447 case VFL_TYPE_GRABBER:
1448 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1451 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1453 case VFL_TYPE_RADIO:
1458 /* If more than one user, mutex should be added */
1461 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1462 video_device_node_name(vdev), v4l2_type_names[type],
1465 /* allocate + initialize per filehandle data */
1466 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1472 file->private_data = fh;
1477 dev->fourcc = format[0].fourcc;
1479 fh->fmt = format_by_fourcc(dev->fourcc);
1481 tm6000_get_std_res (dev);
1483 fh->width = dev->width;
1484 fh->height = dev->height;
1486 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
1487 "dev->vidq=0x%08lx\n",
1488 (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
1489 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1490 "queued=%d\n",list_empty(&dev->vidq.queued));
1491 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1492 "active=%d\n",list_empty(&dev->vidq.active));
1494 /* initialize hardware on analog mode */
1495 rc = tm6000_init_analog_mode(dev);
1499 if (dev->mode != TM6000_MODE_ANALOG) {
1500 /* Put all controls at a sane state */
1501 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1502 qctl_regs[i] = tm6000_qctrl[i].default_value;
1504 dev->mode = TM6000_MODE_ANALOG;
1507 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1510 V4L2_FIELD_INTERLACED,
1511 sizeof(struct tm6000_buffer), fh, &dev->lock);
1514 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1515 tm6000_set_audio_input(dev, dev->aradio);
1516 tm6000_set_volume(dev, dev->ctl_volume);
1517 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1518 tm6000_prepare_isoc(dev);
1519 tm6000_start_thread(dev);
1522 tm6000_set_audio_input(dev, dev->avideo);
1523 tm6000_set_volume(dev, dev->ctl_volume);
1530 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1532 struct tm6000_fh *fh = file->private_data;
1534 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1535 if (!res_get(fh->dev, fh, true))
1538 return videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1539 file->f_flags & O_NONBLOCK);
1545 tm6000_poll(struct file *file, struct poll_table_struct *wait)
1547 struct tm6000_fh *fh = file->private_data;
1548 struct tm6000_buffer *buf;
1550 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1553 if (!!is_res_streaming(fh->dev, fh))
1556 if (!is_res_read(fh->dev, fh)) {
1557 /* streaming capture */
1558 if (list_empty(&fh->vb_vidq.stream))
1560 buf = list_entry(fh->vb_vidq.stream.next,struct tm6000_buffer,vb.stream);
1562 /* read() capture */
1563 return videobuf_poll_stream(file, &fh->vb_vidq,
1566 poll_wait(file, &buf->vb.done, wait);
1567 if (buf->vb.state == VIDEOBUF_DONE ||
1568 buf->vb.state == VIDEOBUF_ERROR)
1569 return POLLIN | POLLRDNORM;
1573 static int tm6000_release(struct file *file)
1575 struct tm6000_fh *fh = file->private_data;
1576 struct tm6000_core *dev = fh->dev;
1577 struct video_device *vdev = video_devdata(file);
1579 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1580 video_device_node_name(vdev), dev->users);
1586 tm6000_uninit_isoc(dev);
1587 videobuf_mmap_free(&fh->vb_vidq);
1595 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1597 struct tm6000_fh *fh = file->private_data;
1600 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1605 static struct v4l2_file_operations tm6000_fops = {
1606 .owner = THIS_MODULE,
1607 .open = tm6000_open,
1608 .release = tm6000_release,
1609 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1610 .read = tm6000_read,
1611 .poll = tm6000_poll,
1612 .mmap = tm6000_mmap,
1615 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1616 .vidioc_querycap = vidioc_querycap,
1617 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1618 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1619 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1620 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1621 .vidioc_s_std = vidioc_s_std,
1622 .vidioc_enum_input = vidioc_enum_input,
1623 .vidioc_g_input = vidioc_g_input,
1624 .vidioc_s_input = vidioc_s_input,
1625 .vidioc_queryctrl = vidioc_queryctrl,
1626 .vidioc_g_ctrl = vidioc_g_ctrl,
1627 .vidioc_s_ctrl = vidioc_s_ctrl,
1628 .vidioc_g_tuner = vidioc_g_tuner,
1629 .vidioc_s_tuner = vidioc_s_tuner,
1630 .vidioc_g_frequency = vidioc_g_frequency,
1631 .vidioc_s_frequency = vidioc_s_frequency,
1632 .vidioc_streamon = vidioc_streamon,
1633 .vidioc_streamoff = vidioc_streamoff,
1634 .vidioc_reqbufs = vidioc_reqbufs,
1635 .vidioc_querybuf = vidioc_querybuf,
1636 .vidioc_qbuf = vidioc_qbuf,
1637 .vidioc_dqbuf = vidioc_dqbuf,
1640 static struct video_device tm6000_template = {
1642 .fops = &tm6000_fops,
1643 .ioctl_ops = &video_ioctl_ops,
1644 .release = video_device_release,
1645 .tvnorms = TM6000_STD,
1646 .current_norm = V4L2_STD_NTSC_M,
1649 static const struct v4l2_file_operations radio_fops = {
1650 .owner = THIS_MODULE,
1651 .open = tm6000_open,
1652 .release = tm6000_release,
1653 .ioctl = video_ioctl2,
1656 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1657 .vidioc_querycap = radio_querycap,
1658 .vidioc_g_tuner = radio_g_tuner,
1659 .vidioc_enum_input = radio_enum_input,
1660 .vidioc_g_audio = radio_g_audio,
1661 .vidioc_s_tuner = radio_s_tuner,
1662 .vidioc_s_audio = radio_s_audio,
1663 .vidioc_s_input = radio_s_input,
1664 .vidioc_s_std = radio_s_std,
1665 .vidioc_queryctrl = radio_queryctrl,
1666 .vidioc_g_input = radio_g_input,
1667 .vidioc_g_ctrl = vidioc_g_ctrl,
1668 .vidioc_s_ctrl = vidioc_s_ctrl,
1669 .vidioc_g_frequency = vidioc_g_frequency,
1670 .vidioc_s_frequency = vidioc_s_frequency,
1673 struct video_device tm6000_radio_template = {
1675 .fops = &radio_fops,
1676 .ioctl_ops = &radio_ioctl_ops,
1679 /* -----------------------------------------------------------------
1680 * Initialization and module stuff
1681 * ------------------------------------------------------------------
1684 static struct video_device *vdev_init(struct tm6000_core *dev,
1685 const struct video_device
1686 *template, const char *type_name)
1688 struct video_device *vfd;
1690 vfd = video_device_alloc();
1695 vfd->v4l2_dev = &dev->v4l2_dev;
1696 vfd->release = video_device_release;
1697 vfd->debug = tm6000_debug;
1698 vfd->lock = &dev->lock;
1700 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1702 video_set_drvdata(vfd, dev);
1706 int tm6000_v4l2_register(struct tm6000_core *dev)
1710 dev->vfd = vdev_init(dev, &tm6000_template, "video");
1713 printk(KERN_INFO "%s: can't register video device\n",
1718 /* init video dma queues */
1719 INIT_LIST_HEAD(&dev->vidq.active);
1720 INIT_LIST_HEAD(&dev->vidq.queued);
1722 ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr);
1725 printk(KERN_INFO "%s: can't register video device\n",
1730 printk(KERN_INFO "%s: registered device %s\n",
1731 dev->name, video_device_node_name(dev->vfd));
1733 dev->radio_dev = vdev_init(dev, &tm6000_radio_template,
1735 if (!dev->radio_dev) {
1736 printk(KERN_INFO "%s: can't register radio device\n",
1738 return ret; /* FIXME release resource */
1741 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
1744 printk(KERN_INFO "%s: can't register radio device\n",
1746 return ret; /* FIXME release resource */
1749 printk(KERN_INFO "%s: registered device %s\n",
1750 dev->name, video_device_node_name(dev->radio_dev));
1752 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1756 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1758 video_unregister_device(dev->vfd);
1760 if (dev->radio_dev) {
1761 if (video_is_registered(dev->radio_dev))
1762 video_unregister_device(dev->radio_dev);
1764 video_device_release(dev->radio_dev);
1765 dev->radio_dev = NULL;
1771 int tm6000_v4l2_exit(void)
1776 module_param(video_nr, int, 0);
1777 MODULE_PARM_DESC(video_nr, "Allow changing video device number");
1779 module_param_named(debug, tm6000_debug, int, 0444);
1780 MODULE_PARM_DESC(debug, "activates debug info");
1782 module_param(vid_limit, int, 0644);
1783 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");