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/tuner.h>
38 #include <linux/interrupt.h>
39 #include <linux/kthread.h>
40 #include <linux/highmem.h>
41 #include <linux/freezer.h>
43 #include "tm6000-regs.h"
46 #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
48 /* Limits minimum and default number of buffers */
49 #define TM6000_MIN_BUF 4
50 #define TM6000_DEF_BUF 8
52 #define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
54 /* Declare static vars that will be used as parameters */
55 static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
56 static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
57 static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */
61 EXPORT_SYMBOL_GPL(tm6000_debug);
63 static const struct v4l2_queryctrl no_ctrl = {
65 .flags = V4L2_CTRL_FLAG_DISABLED,
68 /* supported controls */
69 static struct v4l2_queryctrl tm6000_qctrl[] = {
71 .id = V4L2_CID_BRIGHTNESS,
72 .type = V4L2_CTRL_TYPE_INTEGER,
80 .id = V4L2_CID_CONTRAST,
81 .type = V4L2_CTRL_TYPE_INTEGER,
89 .id = V4L2_CID_SATURATION,
90 .type = V4L2_CTRL_TYPE_INTEGER,
99 .type = V4L2_CTRL_TYPE_INTEGER,
109 .id = V4L2_CID_AUDIO_MUTE,
113 .type = V4L2_CTRL_TYPE_BOOLEAN,
115 .id = V4L2_CID_AUDIO_VOLUME,
121 .type = V4L2_CTRL_TYPE_INTEGER,
125 static const unsigned int CTRLS = ARRAY_SIZE(tm6000_qctrl);
126 static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
128 static struct tm6000_fmt format[] = {
130 .name = "4:2:2, packed, YVY2",
131 .fourcc = V4L2_PIX_FMT_YUYV,
134 .name = "4:2:2, packed, UYVY",
135 .fourcc = V4L2_PIX_FMT_UYVY,
138 .name = "A/V + VBI mux packet",
139 .fourcc = V4L2_PIX_FMT_TM6000,
144 static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
148 for (i = 0; i < CTRLS; i++)
149 if (tm6000_qctrl[i].id == id)
150 return tm6000_qctrl+i;
154 /* ------------------------------------------------------------------
155 * DMA and thread functions
156 * ------------------------------------------------------------------
159 #define norm_maxw(a) 720
160 #define norm_maxh(a) 576
162 #define norm_minw(a) norm_maxw(a)
163 #define norm_minh(a) norm_maxh(a)
166 * video-buf generic routine to get the next available buffer
168 static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
169 struct tm6000_buffer **buf)
171 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);
184 * Announces that a buffer were filled and request the next
186 static inline void buffer_filled(struct tm6000_core *dev,
187 struct tm6000_dmaqueue *dma_q,
188 struct tm6000_buffer *buf)
190 /* Advice that buffer was filled */
191 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
192 buf->vb.state = VIDEOBUF_DONE;
193 buf->vb.field_count++;
194 do_gettimeofday(&buf->vb.ts);
196 list_del(&buf->vb.queue);
197 wake_up(&buf->vb.done);
201 * Identify the tm5600/6000 buffer header type and properly handles
203 static int copy_streams(u8 *data, unsigned long len,
206 struct tm6000_dmaqueue *dma_q = urb->context;
207 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
208 u8 *ptr = data, *endp = data+len;
209 unsigned long header = 0;
211 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
212 struct tm6000_buffer *vbuf = NULL;
214 unsigned int linewidth;
217 /* get video buffer */
218 get_next_buf(dma_q, &vbuf);
222 voutp = videobuf_to_vmalloc(&vbuf->vb);
228 for (ptr = data; ptr < endp;) {
229 if (!dev->isoc_ctl.cmd) {
231 if (dev->isoc_ctl.tmp_buf_len > 0) {
232 /* from last urb or packet */
233 header = dev->isoc_ctl.tmp_buf;
234 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
235 memcpy((u8 *)&header +
236 dev->isoc_ctl.tmp_buf_len,
238 4 - dev->isoc_ctl.tmp_buf_len);
239 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
241 dev->isoc_ctl.tmp_buf_len = 0;
243 if (ptr + 3 >= endp) {
244 /* have incomplete header */
245 dev->isoc_ctl.tmp_buf_len = endp - ptr;
246 memcpy(&dev->isoc_ctl.tmp_buf, ptr,
247 dev->isoc_ctl.tmp_buf_len);
251 for (; ptr < endp - 3; ptr++) {
252 if (*(ptr + 3) == 0x47)
255 /* Get message header */
256 header = *(unsigned long *)ptr;
260 /* split the header fields */
261 size = ((header & 0x7e) << 1);
264 block = (header >> 7) & 0xf;
265 field = (header >> 11) & 0x1;
266 line = (header >> 12) & 0x1ff;
267 cmd = (header >> 21) & 0x7;
268 /* Validates haeder fields */
269 if (size > TM6000_URB_MSG_LEN)
270 size = TM6000_URB_MSG_LEN;
271 pktsize = TM6000_URB_MSG_LEN;
273 * calculate position in buffer and change the buffer
276 case TM6000_URB_MSG_VIDEO:
278 if ((dev->isoc_ctl.vfield != field) &&
281 * Announces that a new buffer
284 buffer_filled(dev, dma_q, vbuf);
285 dprintk(dev, V4L2_DEBUG_ISOC,
286 "new buffer filled\n");
287 get_next_buf(dma_q, &vbuf);
290 voutp = videobuf_to_vmalloc(&vbuf->vb);
293 memset(voutp, 0, vbuf->vb.size);
295 linewidth = vbuf->vb.width << 1;
296 pos = ((line << 1) - field - 1) *
297 linewidth + block * TM6000_URB_MSG_LEN;
298 /* Don't allow to write out of the buffer */
299 if (pos + size > vbuf->vb.size)
300 cmd = TM6000_URB_MSG_ERR;
301 dev->isoc_ctl.vfield = field;
304 case TM6000_URB_MSG_VBI:
306 case TM6000_URB_MSG_AUDIO:
307 case TM6000_URB_MSG_PTS:
308 size = pktsize; /* Size is always 180 bytes */
312 /* Continue the last copy */
313 cmd = dev->isoc_ctl.cmd;
314 size = dev->isoc_ctl.size;
315 pos = dev->isoc_ctl.pos;
316 pktsize = dev->isoc_ctl.pktsize;
317 field = dev->isoc_ctl.field;
319 cpysize = (endp - ptr > size) ? size : endp - ptr;
321 /* copy data in different buffers */
323 case TM6000_URB_MSG_VIDEO:
324 /* Fills video buffer */
326 memcpy(&voutp[pos], ptr, cpysize);
328 case TM6000_URB_MSG_AUDIO: {
330 for (i = 0; i < cpysize; i += 2)
331 swab16s((u16 *)(ptr + i));
333 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
336 case TM6000_URB_MSG_VBI:
337 /* Need some code to copy vbi buffer */
339 case TM6000_URB_MSG_PTS: {
340 /* Need some code to copy pts */
343 dprintk(dev, V4L2_DEBUG_ISOC, "field %d, PTS %x",
349 if (ptr + pktsize > endp) {
351 * End of URB packet, but cmd processing is not
352 * complete. Preserve the state for a next packet
354 dev->isoc_ctl.pos = pos + cpysize;
355 dev->isoc_ctl.size = size - cpysize;
356 dev->isoc_ctl.cmd = cmd;
357 dev->isoc_ctl.field = field;
358 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
361 dev->isoc_ctl.cmd = 0;
369 * Identify the tm5600/6000 buffer header type and properly handles
371 static int copy_multiplexed(u8 *ptr, unsigned long len,
374 struct tm6000_dmaqueue *dma_q = urb->context;
375 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
376 unsigned int pos = dev->isoc_ctl.pos, cpysize;
378 struct tm6000_buffer *buf;
381 get_next_buf(dma_q, &buf);
383 outp = videobuf_to_vmalloc(&buf->vb);
389 cpysize = min(len, buf->vb.size-pos);
390 memcpy(&outp[pos], ptr, cpysize);
394 if (pos >= buf->vb.size) {
396 /* Announces that a new buffer were filled */
397 buffer_filled(dev, dma_q, buf);
398 dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
399 get_next_buf(dma_q, &buf);
402 outp = videobuf_to_vmalloc(&(buf->vb));
409 dev->isoc_ctl.pos = pos;
413 static inline void print_err_status(struct tm6000_core *dev,
414 int packet, int status)
416 char *errmsg = "Unknown";
420 errmsg = "unlinked synchronuously";
423 errmsg = "unlinked asynchronuously";
426 errmsg = "Buffer error (overrun)";
429 errmsg = "Stalled (device not responding)";
432 errmsg = "Babble (bad cable?)";
435 errmsg = "Bit-stuff error (bad cable?)";
438 errmsg = "CRC/Timeout (could be anything)";
441 errmsg = "Device does not respond";
445 dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
448 dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
449 packet, status, errmsg);
455 * Controls the isoc copy of each urb packet
457 static inline int tm6000_isoc_copy(struct urb *urb)
459 struct tm6000_dmaqueue *dma_q = urb->context;
460 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
461 int i, len = 0, rc = 1, status;
464 if (urb->status < 0) {
465 print_err_status(dev, -1, urb->status);
469 for (i = 0; i < urb->number_of_packets; i++) {
470 status = urb->iso_frame_desc[i].status;
473 print_err_status(dev, i, status);
477 len = urb->iso_frame_desc[i].actual_length;
480 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
481 if (!urb->iso_frame_desc[i].status) {
482 if ((dev->fourcc) == V4L2_PIX_FMT_TM6000) {
483 rc = copy_multiplexed(p, len, urb);
487 copy_streams(p, len, urb);
495 /* ------------------------------------------------------------------
497 * ------------------------------------------------------------------
501 * IRQ callback, called by URB callback
503 static void tm6000_irq_callback(struct urb *urb)
505 struct tm6000_dmaqueue *dma_q = urb->context;
506 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
509 switch (urb->status) {
520 tm6000_err("urb completion error %d.\n", urb->status);
524 spin_lock(&dev->slock);
525 tm6000_isoc_copy(urb);
526 spin_unlock(&dev->slock);
528 /* Reset urb buffers */
529 for (i = 0; i < urb->number_of_packets; i++) {
530 urb->iso_frame_desc[i].status = 0;
531 urb->iso_frame_desc[i].actual_length = 0;
534 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
536 tm6000_err("urb resubmit failed (error=%i)\n",
541 * Stop and Deallocate URBs
543 static void tm6000_uninit_isoc(struct tm6000_core *dev)
548 dev->isoc_ctl.buf = NULL;
549 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
550 urb = dev->isoc_ctl.urb[i];
554 if (dev->isoc_ctl.transfer_buffer[i]) {
555 usb_free_coherent(dev->udev,
556 urb->transfer_buffer_length,
557 dev->isoc_ctl.transfer_buffer[i],
561 dev->isoc_ctl.urb[i] = NULL;
563 dev->isoc_ctl.transfer_buffer[i] = NULL;
566 kfree(dev->isoc_ctl.urb);
567 kfree(dev->isoc_ctl.transfer_buffer);
569 dev->isoc_ctl.urb = NULL;
570 dev->isoc_ctl.transfer_buffer = NULL;
571 dev->isoc_ctl.num_bufs = 0;
575 * Allocate URBs and start IRQ
577 static int tm6000_prepare_isoc(struct tm6000_core *dev)
579 struct tm6000_dmaqueue *dma_q = &dev->vidq;
580 int i, j, sb_size, pipe, size, max_packets, num_bufs = 8;
583 /* De-allocates all pending stuff */
584 tm6000_uninit_isoc(dev);
585 /* Stop interrupt USB pipe */
586 tm6000_ir_int_stop(dev);
588 usb_set_interface(dev->udev,
589 dev->isoc_in.bInterfaceNumber,
590 dev->isoc_in.bAlternateSetting);
592 /* Start interrupt USB pipe */
593 tm6000_ir_int_start(dev);
595 pipe = usb_rcvisocpipe(dev->udev,
596 dev->isoc_in.endp->desc.bEndpointAddress &
597 USB_ENDPOINT_NUMBER_MASK);
599 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
601 if (size > dev->isoc_in.maxsize)
602 size = dev->isoc_in.maxsize;
604 dev->isoc_ctl.max_pkt_size = size;
606 max_packets = TM6000_MAX_ISO_PACKETS;
607 sb_size = max_packets * size;
609 dev->isoc_ctl.num_bufs = num_bufs;
611 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
612 if (!dev->isoc_ctl.urb) {
613 tm6000_err("cannot alloc memory for usb buffers\n");
617 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
619 if (!dev->isoc_ctl.transfer_buffer) {
620 tm6000_err("cannot allocate memory for usbtransfer\n");
621 kfree(dev->isoc_ctl.urb);
625 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
626 " (%d bytes) of %d bytes each to handle %u size\n",
627 max_packets, num_bufs, sb_size,
628 dev->isoc_in.maxsize, size);
630 /* allocate urbs and transfer buffers */
631 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
632 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
634 tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
635 tm6000_uninit_isoc(dev);
639 dev->isoc_ctl.urb[i] = urb;
641 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
642 sb_size, GFP_KERNEL, &urb->transfer_dma);
643 if (!dev->isoc_ctl.transfer_buffer[i]) {
644 tm6000_err("unable to allocate %i bytes for transfer"
647 in_interrupt() ? " while in int" : "");
648 tm6000_uninit_isoc(dev);
651 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
653 usb_fill_bulk_urb(urb, dev->udev, pipe,
654 dev->isoc_ctl.transfer_buffer[i], sb_size,
655 tm6000_irq_callback, dma_q);
656 urb->interval = dev->isoc_in.endp->desc.bInterval;
657 urb->number_of_packets = max_packets;
658 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
660 for (j = 0; j < max_packets; j++) {
661 urb->iso_frame_desc[j].offset = size * j;
662 urb->iso_frame_desc[j].length = size;
669 static int tm6000_start_thread(struct tm6000_core *dev)
671 struct tm6000_dmaqueue *dma_q = &dev->vidq;
675 dma_q->ini_jiffies = jiffies;
677 init_waitqueue_head(&dma_q->wq);
679 /* submit urbs and enables IRQ */
680 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
681 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
683 tm6000_err("submit of urb %i failed (error=%i)\n", i,
685 tm6000_uninit_isoc(dev);
693 /* ------------------------------------------------------------------
694 * Videobuf operations
695 * ------------------------------------------------------------------
699 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
701 struct tm6000_fh *fh = vq->priv_data;
703 *size = fh->fmt->depth * fh->width * fh->height >> 3;
705 *count = TM6000_DEF_BUF;
707 if (*count < TM6000_MIN_BUF)
708 *count = TM6000_MIN_BUF;
710 while (*size * *count > vid_limit * 1024 * 1024)
716 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
718 struct tm6000_fh *fh = vq->priv_data;
719 struct tm6000_core *dev = fh->dev;
725 /* We used to wait for the buffer to finish here, but this didn't work
726 because, as we were keeping the state as VIDEOBUF_QUEUED,
727 videobuf_queue_cancel marked it as finished for us.
728 (Also, it could wedge forever if the hardware was misconfigured.)
730 This should be safe; by the time we get here, the buffer isn't
731 queued anymore. If we ever start marking the buffers as
732 VIDEOBUF_ACTIVE, it won't be, though.
734 spin_lock_irqsave(&dev->slock, flags);
735 if (dev->isoc_ctl.buf == buf)
736 dev->isoc_ctl.buf = NULL;
737 spin_unlock_irqrestore(&dev->slock, flags);
739 videobuf_vmalloc_free(&buf->vb);
740 buf->vb.state = VIDEOBUF_NEEDS_INIT;
744 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
745 enum v4l2_field field)
747 struct tm6000_fh *fh = vq->priv_data;
748 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
749 struct tm6000_core *dev = fh->dev;
752 BUG_ON(NULL == fh->fmt);
755 /* FIXME: It assumes depth=2 */
756 /* The only currently supported format is 16 bits/pixel */
757 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
758 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
761 if (buf->fmt != fh->fmt ||
762 buf->vb.width != fh->width ||
763 buf->vb.height != fh->height ||
764 buf->vb.field != field) {
766 buf->vb.width = fh->width;
767 buf->vb.height = fh->height;
768 buf->vb.field = field;
769 buf->vb.state = VIDEOBUF_NEEDS_INIT;
772 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
773 rc = videobuf_iolock(vq, &buf->vb, NULL);
778 if (!dev->isoc_ctl.num_bufs) {
779 rc = tm6000_prepare_isoc(dev);
783 rc = tm6000_start_thread(dev);
789 buf->vb.state = VIDEOBUF_PREPARED;
793 free_buffer(vq, buf);
798 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
800 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
801 struct tm6000_fh *fh = vq->priv_data;
802 struct tm6000_core *dev = fh->dev;
803 struct tm6000_dmaqueue *vidq = &dev->vidq;
805 buf->vb.state = VIDEOBUF_QUEUED;
806 list_add_tail(&buf->vb.queue, &vidq->active);
809 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
811 struct tm6000_buffer *buf = container_of(vb, struct tm6000_buffer, vb);
813 free_buffer(vq, buf);
816 static struct videobuf_queue_ops tm6000_video_qops = {
817 .buf_setup = buffer_setup,
818 .buf_prepare = buffer_prepare,
819 .buf_queue = buffer_queue,
820 .buf_release = buffer_release,
823 /* ------------------------------------------------------------------
825 * ------------------------------------------------------------------
828 static bool is_res_read(struct tm6000_core *dev, struct tm6000_fh *fh)
830 /* Is the current fh handling it? if so, that's OK */
831 if (dev->resources == fh && dev->is_res_read)
837 static bool is_res_streaming(struct tm6000_core *dev, struct tm6000_fh *fh)
839 /* Is the current fh handling it? if so, that's OK */
840 if (dev->resources == fh)
846 static bool res_get(struct tm6000_core *dev, struct tm6000_fh *fh,
849 /* Is the current fh handling it? if so, that's OK */
850 if (dev->resources == fh && dev->is_res_read == is_res_read)
859 dev->is_res_read = is_res_read;
860 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
864 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
866 /* Is the current fh handling it? if so, that's OK */
867 if (dev->resources != fh)
870 dev->resources = NULL;
871 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
874 /* ------------------------------------------------------------------
875 * IOCTL vidioc handling
876 * ------------------------------------------------------------------
878 static int vidioc_querycap(struct file *file, void *priv,
879 struct v4l2_capability *cap)
881 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
883 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
884 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
885 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
890 if (dev->tuner_type != TUNER_ABSENT)
891 cap->capabilities |= V4L2_CAP_TUNER;
896 static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
897 struct v4l2_fmtdesc *f)
899 if (unlikely(f->index >= ARRAY_SIZE(format)))
902 strlcpy(f->description, format[f->index].name, sizeof(f->description));
903 f->pixelformat = format[f->index].fourcc;
907 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
908 struct v4l2_format *f)
910 struct tm6000_fh *fh = priv;
912 f->fmt.pix.width = fh->width;
913 f->fmt.pix.height = fh->height;
914 f->fmt.pix.field = fh->vb_vidq.field;
915 f->fmt.pix.pixelformat = fh->fmt->fourcc;
916 f->fmt.pix.bytesperline =
917 (f->fmt.pix.width * fh->fmt->depth) >> 3;
918 f->fmt.pix.sizeimage =
919 f->fmt.pix.height * f->fmt.pix.bytesperline;
924 static struct tm6000_fmt *format_by_fourcc(unsigned int fourcc)
928 for (i = 0; i < ARRAY_SIZE(format); i++)
929 if (format[i].fourcc == fourcc)
934 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
935 struct v4l2_format *f)
937 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
938 struct tm6000_fmt *fmt;
939 enum v4l2_field field;
941 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
943 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)"
944 " invalid.\n", f->fmt.pix.pixelformat);
948 field = f->fmt.pix.field;
950 if (field == V4L2_FIELD_ANY)
951 field = V4L2_FIELD_SEQ_TB;
952 else if (V4L2_FIELD_INTERLACED != field) {
953 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
957 tm6000_get_std_res(dev);
959 f->fmt.pix.width = dev->width;
960 f->fmt.pix.height = dev->height;
962 f->fmt.pix.width &= ~0x01;
964 f->fmt.pix.field = field;
966 f->fmt.pix.bytesperline =
967 (f->fmt.pix.width * fmt->depth) >> 3;
968 f->fmt.pix.sizeimage =
969 f->fmt.pix.height * f->fmt.pix.bytesperline;
974 /*FIXME: This seems to be generic enough to be at videodev2 */
975 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
976 struct v4l2_format *f)
978 struct tm6000_fh *fh = priv;
979 struct tm6000_core *dev = fh->dev;
980 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
984 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
985 fh->width = f->fmt.pix.width;
986 fh->height = f->fmt.pix.height;
987 fh->vb_vidq.field = f->fmt.pix.field;
990 dev->fourcc = f->fmt.pix.pixelformat;
992 tm6000_set_fourcc_format(dev);
997 static int vidioc_reqbufs(struct file *file, void *priv,
998 struct v4l2_requestbuffers *p)
1000 struct tm6000_fh *fh = priv;
1002 return videobuf_reqbufs(&fh->vb_vidq, p);
1005 static int vidioc_querybuf(struct file *file, void *priv,
1006 struct v4l2_buffer *p)
1008 struct tm6000_fh *fh = priv;
1010 return videobuf_querybuf(&fh->vb_vidq, p);
1013 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1015 struct tm6000_fh *fh = priv;
1017 return videobuf_qbuf(&fh->vb_vidq, p);
1020 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1022 struct tm6000_fh *fh = priv;
1024 return videobuf_dqbuf(&fh->vb_vidq, p,
1025 file->f_flags & O_NONBLOCK);
1028 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1030 struct tm6000_fh *fh = priv;
1031 struct tm6000_core *dev = fh->dev;
1033 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1038 if (!res_get(dev, fh, false))
1040 return videobuf_streamon(&fh->vb_vidq);
1043 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1045 struct tm6000_fh *fh = priv;
1046 struct tm6000_core *dev = fh->dev;
1048 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 const char *iname[] = {
1081 [TM6000_INPUT_TV] = "Television",
1082 [TM6000_INPUT_COMPOSITE1] = "Composite 1",
1083 [TM6000_INPUT_COMPOSITE2] = "Composite 2",
1084 [TM6000_INPUT_SVIDEO] = "S-Video",
1087 static int vidioc_enum_input(struct file *file, void *priv,
1088 struct v4l2_input *i)
1090 struct tm6000_fh *fh = priv;
1091 struct tm6000_core *dev = fh->dev;
1098 if (!dev->vinput[n].type)
1103 if (dev->vinput[n].type == TM6000_INPUT_TV)
1104 i->type = V4L2_INPUT_TYPE_TUNER;
1106 i->type = V4L2_INPUT_TYPE_CAMERA;
1108 strcpy(i->name, iname[dev->vinput[n].type]);
1110 i->std = TM6000_STD;
1115 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1117 struct tm6000_fh *fh = priv;
1118 struct tm6000_core *dev = fh->dev;
1125 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1127 struct tm6000_fh *fh = priv;
1128 struct tm6000_core *dev = fh->dev;
1133 if (!dev->vinput[i].type)
1138 rc = vidioc_s_std(file, priv, &dev->vfd->current_norm);
1143 /* --- controls ---------------------------------------------- */
1144 static int vidioc_queryctrl(struct file *file, void *priv,
1145 struct v4l2_queryctrl *qc)
1149 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1150 if (qc->id && qc->id == tm6000_qctrl[i].id) {
1151 memcpy(qc, &(tm6000_qctrl[i]),
1159 static int vidioc_g_ctrl(struct file *file, void *priv,
1160 struct v4l2_control *ctrl)
1162 struct tm6000_fh *fh = priv;
1163 struct tm6000_core *dev = fh->dev;
1166 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1168 case V4L2_CID_CONTRAST:
1169 val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0);
1171 case V4L2_CID_BRIGHTNESS:
1172 val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0);
1174 case V4L2_CID_SATURATION:
1175 val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0);
1178 val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0);
1180 case V4L2_CID_AUDIO_MUTE:
1181 val = dev->ctl_mute;
1183 case V4L2_CID_AUDIO_VOLUME:
1184 val = dev->ctl_volume;
1197 static int vidioc_s_ctrl(struct file *file, void *priv,
1198 struct v4l2_control *ctrl)
1200 struct tm6000_fh *fh = priv;
1201 struct tm6000_core *dev = fh->dev;
1202 u8 val = ctrl->value;
1205 case V4L2_CID_CONTRAST:
1206 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1208 case V4L2_CID_BRIGHTNESS:
1209 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1211 case V4L2_CID_SATURATION:
1212 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1215 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1217 case V4L2_CID_AUDIO_MUTE:
1218 dev->ctl_mute = val;
1219 tm6000_tvaudio_set_mute(dev, val);
1221 case V4L2_CID_AUDIO_VOLUME:
1222 dev->ctl_volume = val;
1223 tm6000_set_volume(dev, val);
1229 static int vidioc_g_tuner(struct file *file, void *priv,
1230 struct v4l2_tuner *t)
1232 struct tm6000_fh *fh = priv;
1233 struct tm6000_core *dev = fh->dev;
1235 if (unlikely(UNSET == dev->tuner_type))
1240 strcpy(t->name, "Television");
1241 t->type = V4L2_TUNER_ANALOG_TV;
1242 t->capability = V4L2_TUNER_CAP_NORM;
1243 t->rangehigh = 0xffffffffUL;
1244 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1246 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1248 t->audmode = dev->amode;
1253 static int vidioc_s_tuner(struct file *file, void *priv,
1254 struct v4l2_tuner *t)
1256 struct tm6000_fh *fh = priv;
1257 struct tm6000_core *dev = fh->dev;
1259 if (UNSET == dev->tuner_type)
1264 dev->amode = t->audmode;
1265 dprintk(dev, 3, "audio mode: %x\n", t->audmode);
1267 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1272 static int vidioc_g_frequency(struct file *file, void *priv,
1273 struct v4l2_frequency *f)
1275 struct tm6000_fh *fh = priv;
1276 struct tm6000_core *dev = fh->dev;
1278 if (unlikely(UNSET == dev->tuner_type))
1281 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1282 f->frequency = dev->freq;
1284 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1289 static int vidioc_s_frequency(struct file *file, void *priv,
1290 struct v4l2_frequency *f)
1292 struct tm6000_fh *fh = priv;
1293 struct tm6000_core *dev = fh->dev;
1295 if (unlikely(UNSET == dev->tuner_type))
1297 if (unlikely(f->tuner != 0))
1299 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
1301 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1304 dev->freq = f->frequency;
1305 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1310 static int radio_querycap(struct file *file, void *priv,
1311 struct v4l2_capability *cap)
1313 struct tm6000_fh *fh = file->private_data;
1314 struct tm6000_core *dev = fh->dev;
1316 strcpy(cap->driver, "tm6000");
1317 strlcpy(cap->card, dev->name, sizeof(dev->name));
1318 sprintf(cap->bus_info, "USB%04x:%04x",
1319 le16_to_cpu(dev->udev->descriptor.idVendor),
1320 le16_to_cpu(dev->udev->descriptor.idProduct));
1321 cap->version = dev->dev_type;
1322 cap->capabilities = V4L2_CAP_TUNER |
1325 V4L2_CAP_READWRITE |
1331 static int radio_g_tuner(struct file *file, void *priv,
1332 struct v4l2_tuner *t)
1334 struct tm6000_fh *fh = file->private_data;
1335 struct tm6000_core *dev = fh->dev;
1340 memset(t, 0, sizeof(*t));
1341 strcpy(t->name, "Radio");
1342 t->type = V4L2_TUNER_RADIO;
1343 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1345 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1350 static int radio_s_tuner(struct file *file, void *priv,
1351 struct v4l2_tuner *t)
1353 struct tm6000_fh *fh = file->private_data;
1354 struct tm6000_core *dev = fh->dev;
1359 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1364 static int radio_enum_input(struct file *file, void *priv,
1365 struct v4l2_input *i)
1367 struct tm6000_fh *fh = priv;
1368 struct tm6000_core *dev = fh->dev;
1373 if (!dev->rinput.type)
1376 strcpy(i->name, "Radio");
1377 i->type = V4L2_INPUT_TYPE_TUNER;
1382 static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
1384 struct tm6000_fh *fh = priv;
1385 struct tm6000_core *dev = fh->dev;
1387 if (dev->input != 5)
1390 *i = dev->input - 5;
1395 static int radio_g_audio(struct file *file, void *priv,
1396 struct v4l2_audio *a)
1398 memset(a, 0, sizeof(*a));
1399 strcpy(a->name, "Radio");
1403 static int radio_s_audio(struct file *file, void *priv,
1404 const struct v4l2_audio *a)
1409 static int radio_s_input(struct file *filp, void *priv, unsigned int i)
1411 struct tm6000_fh *fh = priv;
1412 struct tm6000_core *dev = fh->dev;
1417 if (!dev->rinput.type)
1425 static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
1430 static int radio_queryctrl(struct file *file, void *priv,
1431 struct v4l2_queryctrl *c)
1433 const struct v4l2_queryctrl *ctrl;
1435 if (c->id < V4L2_CID_BASE ||
1436 c->id >= V4L2_CID_LASTP1)
1438 if (c->id == V4L2_CID_AUDIO_MUTE) {
1439 ctrl = ctrl_by_id(c->id);
1447 /* ------------------------------------------------------------------
1448 File operations for the device
1449 ------------------------------------------------------------------*/
1451 static int __tm6000_open(struct file *file)
1453 struct video_device *vdev = video_devdata(file);
1454 struct tm6000_core *dev = video_drvdata(file);
1455 struct tm6000_fh *fh;
1456 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1460 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1461 video_device_node_name(vdev));
1463 switch (vdev->vfl_type) {
1464 case VFL_TYPE_GRABBER:
1465 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1468 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1470 case VFL_TYPE_RADIO:
1475 /* If more than one user, mutex should be added */
1478 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1479 video_device_node_name(vdev), v4l2_type_names[type],
1482 /* allocate + initialize per filehandle data */
1483 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1489 file->private_data = fh;
1494 dev->fourcc = format[0].fourcc;
1496 fh->fmt = format_by_fourcc(dev->fourcc);
1498 tm6000_get_std_res(dev);
1500 fh->width = dev->width;
1501 fh->height = dev->height;
1503 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
1504 "dev->vidq=0x%08lx\n",
1505 (unsigned long)fh, (unsigned long)dev,
1506 (unsigned long)&dev->vidq);
1507 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1508 "queued=%d\n", list_empty(&dev->vidq.queued));
1509 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1510 "active=%d\n", list_empty(&dev->vidq.active));
1512 /* initialize hardware on analog mode */
1513 rc = tm6000_init_analog_mode(dev);
1517 if (dev->mode != TM6000_MODE_ANALOG) {
1518 /* Put all controls at a sane state */
1519 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1520 qctl_regs[i] = tm6000_qctrl[i].default_value;
1522 dev->mode = TM6000_MODE_ANALOG;
1526 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1529 V4L2_FIELD_INTERLACED,
1530 sizeof(struct tm6000_buffer), fh, &dev->lock);
1532 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1534 tm6000_set_audio_rinput(dev);
1535 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1536 tm6000_prepare_isoc(dev);
1537 tm6000_start_thread(dev);
1543 static int tm6000_open(struct file *file)
1545 struct video_device *vdev = video_devdata(file);
1548 mutex_lock(vdev->lock);
1549 res = __tm6000_open(file);
1550 mutex_unlock(vdev->lock);
1555 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1557 struct tm6000_fh *fh = file->private_data;
1558 struct tm6000_core *dev = fh->dev;
1560 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1563 if (!res_get(fh->dev, fh, true))
1566 if (mutex_lock_interruptible(&dev->lock))
1567 return -ERESTARTSYS;
1568 res = videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1569 file->f_flags & O_NONBLOCK);
1570 mutex_unlock(&dev->lock);
1577 __tm6000_poll(struct file *file, struct poll_table_struct *wait)
1579 struct tm6000_fh *fh = file->private_data;
1580 struct tm6000_buffer *buf;
1582 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1585 if (!!is_res_streaming(fh->dev, fh))
1588 if (!is_res_read(fh->dev, fh)) {
1589 /* streaming capture */
1590 if (list_empty(&fh->vb_vidq.stream))
1592 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
1594 /* read() capture */
1595 return videobuf_poll_stream(file, &fh->vb_vidq, wait);
1597 poll_wait(file, &buf->vb.done, wait);
1598 if (buf->vb.state == VIDEOBUF_DONE ||
1599 buf->vb.state == VIDEOBUF_ERROR)
1600 return POLLIN | POLLRDNORM;
1604 static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
1606 struct tm6000_fh *fh = file->private_data;
1607 struct tm6000_core *dev = fh->dev;
1610 mutex_lock(&dev->lock);
1611 res = __tm6000_poll(file, wait);
1612 mutex_unlock(&dev->lock);
1616 static int tm6000_release(struct file *file)
1618 struct tm6000_fh *fh = file->private_data;
1619 struct tm6000_core *dev = fh->dev;
1620 struct video_device *vdev = video_devdata(file);
1622 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1623 video_device_node_name(vdev), dev->users);
1625 mutex_lock(&dev->lock);
1631 tm6000_uninit_isoc(dev);
1633 /* Stop interrupt USB pipe */
1634 tm6000_ir_int_stop(dev);
1636 usb_reset_configuration(dev->udev);
1638 if (dev->int_in.endp)
1639 usb_set_interface(dev->udev,
1640 dev->isoc_in.bInterfaceNumber, 2);
1642 usb_set_interface(dev->udev,
1643 dev->isoc_in.bInterfaceNumber, 0);
1645 /* Start interrupt USB pipe */
1646 tm6000_ir_int_start(dev);
1649 videobuf_mmap_free(&fh->vb_vidq);
1653 mutex_unlock(&dev->lock);
1658 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1660 struct tm6000_fh *fh = file->private_data;
1661 struct tm6000_core *dev = fh->dev;
1664 if (mutex_lock_interruptible(&dev->lock))
1665 return -ERESTARTSYS;
1666 res = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1667 mutex_unlock(&dev->lock);
1671 static struct v4l2_file_operations tm6000_fops = {
1672 .owner = THIS_MODULE,
1673 .open = tm6000_open,
1674 .release = tm6000_release,
1675 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1676 .read = tm6000_read,
1677 .poll = tm6000_poll,
1678 .mmap = tm6000_mmap,
1681 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1682 .vidioc_querycap = vidioc_querycap,
1683 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1684 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1685 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1686 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1687 .vidioc_s_std = vidioc_s_std,
1688 .vidioc_enum_input = vidioc_enum_input,
1689 .vidioc_g_input = vidioc_g_input,
1690 .vidioc_s_input = vidioc_s_input,
1691 .vidioc_queryctrl = vidioc_queryctrl,
1692 .vidioc_g_ctrl = vidioc_g_ctrl,
1693 .vidioc_s_ctrl = vidioc_s_ctrl,
1694 .vidioc_g_tuner = vidioc_g_tuner,
1695 .vidioc_s_tuner = vidioc_s_tuner,
1696 .vidioc_g_frequency = vidioc_g_frequency,
1697 .vidioc_s_frequency = vidioc_s_frequency,
1698 .vidioc_streamon = vidioc_streamon,
1699 .vidioc_streamoff = vidioc_streamoff,
1700 .vidioc_reqbufs = vidioc_reqbufs,
1701 .vidioc_querybuf = vidioc_querybuf,
1702 .vidioc_qbuf = vidioc_qbuf,
1703 .vidioc_dqbuf = vidioc_dqbuf,
1706 static struct video_device tm6000_template = {
1708 .fops = &tm6000_fops,
1709 .ioctl_ops = &video_ioctl_ops,
1710 .release = video_device_release,
1711 .tvnorms = TM6000_STD,
1712 .current_norm = V4L2_STD_NTSC_M,
1715 static const struct v4l2_file_operations radio_fops = {
1716 .owner = THIS_MODULE,
1717 .open = tm6000_open,
1718 .release = tm6000_release,
1719 .unlocked_ioctl = video_ioctl2,
1722 static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1723 .vidioc_querycap = radio_querycap,
1724 .vidioc_g_tuner = radio_g_tuner,
1725 .vidioc_enum_input = radio_enum_input,
1726 .vidioc_g_audio = radio_g_audio,
1727 .vidioc_s_tuner = radio_s_tuner,
1728 .vidioc_s_audio = radio_s_audio,
1729 .vidioc_s_input = radio_s_input,
1730 .vidioc_s_std = radio_s_std,
1731 .vidioc_queryctrl = radio_queryctrl,
1732 .vidioc_g_input = radio_g_input,
1733 .vidioc_g_ctrl = vidioc_g_ctrl,
1734 .vidioc_s_ctrl = vidioc_s_ctrl,
1735 .vidioc_g_frequency = vidioc_g_frequency,
1736 .vidioc_s_frequency = vidioc_s_frequency,
1739 static struct video_device tm6000_radio_template = {
1741 .fops = &radio_fops,
1742 .ioctl_ops = &radio_ioctl_ops,
1745 /* -----------------------------------------------------------------
1746 * Initialization and module stuff
1747 * ------------------------------------------------------------------
1750 static struct video_device *vdev_init(struct tm6000_core *dev,
1751 const struct video_device
1752 *template, const char *type_name)
1754 struct video_device *vfd;
1756 vfd = video_device_alloc();
1761 vfd->v4l2_dev = &dev->v4l2_dev;
1762 vfd->release = video_device_release;
1763 vfd->debug = tm6000_debug;
1764 vfd->lock = &dev->lock;
1766 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1768 video_set_drvdata(vfd, dev);
1772 int tm6000_v4l2_register(struct tm6000_core *dev)
1776 dev->vfd = vdev_init(dev, &tm6000_template, "video");
1779 printk(KERN_INFO "%s: can't register video device\n",
1784 /* init video dma queues */
1785 INIT_LIST_HEAD(&dev->vidq.active);
1786 INIT_LIST_HEAD(&dev->vidq.queued);
1788 ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr);
1791 printk(KERN_INFO "%s: can't register video device\n",
1796 printk(KERN_INFO "%s: registered device %s\n",
1797 dev->name, video_device_node_name(dev->vfd));
1799 if (dev->caps.has_radio) {
1800 dev->radio_dev = vdev_init(dev, &tm6000_radio_template,
1802 if (!dev->radio_dev) {
1803 printk(KERN_INFO "%s: can't register radio device\n",
1806 return ret; /* FIXME release resource */
1809 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
1812 printk(KERN_INFO "%s: can't register radio device\n",
1814 return ret; /* FIXME release resource */
1817 printk(KERN_INFO "%s: registered device %s\n",
1818 dev->name, video_device_node_name(dev->radio_dev));
1821 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1825 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1827 video_unregister_device(dev->vfd);
1829 if (dev->radio_dev) {
1830 if (video_is_registered(dev->radio_dev))
1831 video_unregister_device(dev->radio_dev);
1833 video_device_release(dev->radio_dev);
1834 dev->radio_dev = NULL;
1840 int tm6000_v4l2_exit(void)
1845 module_param(video_nr, int, 0);
1846 MODULE_PARM_DESC(video_nr, "Allow changing video device number");
1848 module_param_named(debug, tm6000_debug, int, 0444);
1849 MODULE_PARM_DESC(debug, "activates debug info");
1851 module_param(vid_limit, int, 0644);
1852 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");