[media] tm6000: don't use BKL at the driver
[linux-2.6-xlnx.git] / drivers / staging / tm6000 / tm6000-video.c
blob4a5fe6670fb4153ee83b66a49acb0cd61949ef6d
1 /*
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>
25 #include <linux/fs.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/mm.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"
43 #include "tm6000.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 */
57 /* Debug level */
58 int tm6000_debug;
59 EXPORT_SYMBOL_GPL(tm6000_debug);
61 /* supported controls */
62 static struct v4l2_queryctrl tm6000_qctrl[] = {
64 .id = V4L2_CID_BRIGHTNESS,
65 .type = V4L2_CTRL_TYPE_INTEGER,
66 .name = "Brightness",
67 .minimum = 0,
68 .maximum = 255,
69 .step = 1,
70 .default_value = 54,
71 .flags = 0,
72 }, {
73 .id = V4L2_CID_CONTRAST,
74 .type = V4L2_CTRL_TYPE_INTEGER,
75 .name = "Contrast",
76 .minimum = 0,
77 .maximum = 255,
78 .step = 0x1,
79 .default_value = 119,
80 .flags = 0,
81 }, {
82 .id = V4L2_CID_SATURATION,
83 .type = V4L2_CTRL_TYPE_INTEGER,
84 .name = "Saturation",
85 .minimum = 0,
86 .maximum = 255,
87 .step = 0x1,
88 .default_value = 112,
89 .flags = 0,
90 }, {
91 .id = V4L2_CID_HUE,
92 .type = V4L2_CTRL_TYPE_INTEGER,
93 .name = "Hue",
94 .minimum = -128,
95 .maximum = 127,
96 .step = 0x1,
97 .default_value = 0,
98 .flags = 0,
102 static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
104 static struct tm6000_fmt format[] = {
106 .name = "4:2:2, packed, YVY2",
107 .fourcc = V4L2_PIX_FMT_YUYV,
108 .depth = 16,
109 }, {
110 .name = "4:2:2, packed, UYVY",
111 .fourcc = V4L2_PIX_FMT_UYVY,
112 .depth = 16,
113 }, {
114 .name = "A/V + VBI mux packet",
115 .fourcc = V4L2_PIX_FMT_TM6000,
116 .depth = 16,
120 /* ------------------------------------------------------------------
121 DMA and thread functions
122 ------------------------------------------------------------------*/
124 #define norm_maxw(a) 720
125 #define norm_maxh(a) 576
127 #define norm_minw(a) norm_maxw(a)
128 #define norm_minh(a) norm_maxh(a)
131 * video-buf generic routine to get the next available buffer
133 static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
134 struct tm6000_buffer **buf)
136 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
137 char *outp;
139 if (list_empty(&dma_q->active)) {
140 dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
141 *buf = NULL;
142 return;
145 *buf = list_entry(dma_q->active.next,
146 struct tm6000_buffer, vb.queue);
148 if (!buf)
149 return;
151 /* Cleans up buffer - Usefull for testing for frame/URB loss */
152 outp = videobuf_to_vmalloc(&(*buf)->vb);
154 return;
158 * Announces that a buffer were filled and request the next
160 static inline void buffer_filled(struct tm6000_core *dev,
161 struct tm6000_dmaqueue *dma_q,
162 struct tm6000_buffer *buf)
164 /* Advice that buffer was filled */
165 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
166 buf->vb.state = VIDEOBUF_DONE;
167 buf->vb.field_count++;
168 do_gettimeofday(&buf->vb.ts);
170 list_del(&buf->vb.queue);
171 wake_up(&buf->vb.done);
174 const char *tm6000_msg_type[] = {
175 "unknown(0)", /* 0 */
176 "video", /* 1 */
177 "audio", /* 2 */
178 "vbi", /* 3 */
179 "pts", /* 4 */
180 "err", /* 5 */
181 "unknown(6)", /* 6 */
182 "unknown(7)", /* 7 */
186 * Identify the tm5600/6000 buffer header type and properly handles
188 static int copy_streams(u8 *data, unsigned long len,
189 struct urb *urb)
191 struct tm6000_dmaqueue *dma_q = urb->context;
192 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
193 u8 *ptr=data, *endp=data+len, c;
194 unsigned long header=0;
195 int rc=0;
196 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
197 struct tm6000_buffer *vbuf;
198 char *voutp = NULL;
199 unsigned int linewidth;
201 /* get video buffer */
202 get_next_buf (dma_q, &vbuf);
203 if (!vbuf)
204 return rc;
205 voutp = videobuf_to_vmalloc(&vbuf->vb);
206 if (!voutp)
207 return 0;
209 for (ptr = data; ptr < endp;) {
210 if (!dev->isoc_ctl.cmd) {
211 /* Header */
212 if (dev->isoc_ctl.tmp_buf_len > 0) {
213 /* from last urb or packet */
214 header = dev->isoc_ctl.tmp_buf;
215 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
216 memcpy ((u8 *)&header +
217 dev->isoc_ctl.tmp_buf_len,
218 ptr,
219 4 - dev->isoc_ctl.tmp_buf_len);
220 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
222 dev->isoc_ctl.tmp_buf_len = 0;
223 } else {
224 if (ptr + 3 >= endp) {
225 /* have incomplete header */
226 dev->isoc_ctl.tmp_buf_len = endp - ptr;
227 memcpy (&dev->isoc_ctl.tmp_buf, ptr,
228 dev->isoc_ctl.tmp_buf_len);
229 return rc;
231 /* Seek for sync */
232 for (; ptr < endp - 3; ptr++) {
233 if (*(ptr + 3) == 0x47)
234 break;
236 /* Get message header */
237 header = *(unsigned long *)ptr;
238 ptr += 4;
241 /* split the header fields */
242 c = (header >> 24) & 0xff;
243 size = ((header & 0x7e) << 1);
244 if (size > 0)
245 size -= 4;
246 block = (header >> 7) & 0xf;
247 field = (header >> 11) & 0x1;
248 line = (header >> 12) & 0x1ff;
249 cmd = (header >> 21) & 0x7;
250 /* Validates haeder fields */
251 if (size > TM6000_URB_MSG_LEN)
252 size = TM6000_URB_MSG_LEN;
253 pktsize = TM6000_URB_MSG_LEN;
254 /* calculate position in buffer
255 * and change the buffer
257 switch (cmd) {
258 case TM6000_URB_MSG_VIDEO:
259 if ((dev->isoc_ctl.vfield != field) &&
260 (field == 1)) {
261 /* Announces that a new buffer
262 * were filled
264 buffer_filled (dev, dma_q, vbuf);
265 dprintk (dev, V4L2_DEBUG_ISOC,
266 "new buffer filled\n");
267 get_next_buf (dma_q, &vbuf);
268 if (!vbuf)
269 return rc;
270 voutp = videobuf_to_vmalloc (&vbuf->vb);
271 if (!voutp)
272 return rc;
273 memset(voutp, 0, vbuf->vb.size);
275 linewidth = vbuf->vb.width << 1;
276 pos = ((line << 1) - field - 1) * linewidth +
277 block * TM6000_URB_MSG_LEN;
278 /* Don't allow to write out of the buffer */
279 if (pos + size > vbuf->vb.size)
280 cmd = TM6000_URB_MSG_ERR;
281 dev->isoc_ctl.vfield = field;
282 break;
283 case TM6000_URB_MSG_VBI:
284 break;
285 case TM6000_URB_MSG_AUDIO:
286 case TM6000_URB_MSG_PTS:
287 size = pktsize; /* Size is always 180 bytes */
288 break;
290 } else {
291 /* Continue the last copy */
292 cmd = dev->isoc_ctl.cmd;
293 size = dev->isoc_ctl.size;
294 pos = dev->isoc_ctl.pos;
295 pktsize = dev->isoc_ctl.pktsize;
297 cpysize = (endp - ptr > size) ? size : endp - ptr;
298 if (cpysize) {
299 /* copy data in different buffers */
300 switch (cmd) {
301 case TM6000_URB_MSG_VIDEO:
302 /* Fills video buffer */
303 if (vbuf)
304 memcpy (&voutp[pos], ptr, cpysize);
305 break;
306 case TM6000_URB_MSG_AUDIO:
307 /* Need some code to copy audio buffer */
308 if (dev->fourcc == V4L2_PIX_FMT_YUYV) {
309 /* Swap word bytes */
310 int i;
312 for (i = 0; i < cpysize; i += 2)
313 swab16s((u16 *)(ptr + i));
315 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
316 break;
317 case TM6000_URB_MSG_VBI:
318 /* Need some code to copy vbi buffer */
319 break;
320 case TM6000_URB_MSG_PTS:
321 /* Need some code to copy pts */
322 break;
325 if (ptr + pktsize > endp) {
326 /* End of URB packet, but cmd processing is not
327 * complete. Preserve the state for a next packet
329 dev->isoc_ctl.pos = pos + cpysize;
330 dev->isoc_ctl.size = size - cpysize;
331 dev->isoc_ctl.cmd = cmd;
332 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
333 ptr += endp - ptr;
334 } else {
335 dev->isoc_ctl.cmd = 0;
336 ptr += pktsize;
339 return 0;
343 * Identify the tm5600/6000 buffer header type and properly handles
345 static int copy_multiplexed(u8 *ptr, unsigned long len,
346 struct urb *urb)
348 struct tm6000_dmaqueue *dma_q = urb->context;
349 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
350 unsigned int pos=dev->isoc_ctl.pos,cpysize;
351 int rc=1;
352 struct tm6000_buffer *buf;
353 char *outp = NULL;
355 get_next_buf(dma_q, &buf);
356 if (buf)
357 outp = videobuf_to_vmalloc(&buf->vb);
359 if (!outp)
360 return 0;
362 while (len>0) {
363 cpysize=min(len,buf->vb.size-pos);
364 //printk("Copying %d bytes (max=%lu) from %p to %p[%u]\n",cpysize,(*buf)->vb.size,ptr,out_p,pos);
365 memcpy(&outp[pos], ptr, cpysize);
366 pos+=cpysize;
367 ptr+=cpysize;
368 len-=cpysize;
369 if (pos >= buf->vb.size) {
370 pos=0;
371 /* Announces that a new buffer were filled */
372 buffer_filled (dev, dma_q, buf);
373 dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
374 get_next_buf (dma_q, &buf);
375 if (!buf)
376 break;
377 outp = videobuf_to_vmalloc(&(buf->vb));
378 if (!outp)
379 return rc;
380 pos = 0;
384 dev->isoc_ctl.pos=pos;
385 return rc;
388 static void inline print_err_status (struct tm6000_core *dev,
389 int packet, int status)
391 char *errmsg = "Unknown";
393 switch(status) {
394 case -ENOENT:
395 errmsg = "unlinked synchronuously";
396 break;
397 case -ECONNRESET:
398 errmsg = "unlinked asynchronuously";
399 break;
400 case -ENOSR:
401 errmsg = "Buffer error (overrun)";
402 break;
403 case -EPIPE:
404 errmsg = "Stalled (device not responding)";
405 break;
406 case -EOVERFLOW:
407 errmsg = "Babble (bad cable?)";
408 break;
409 case -EPROTO:
410 errmsg = "Bit-stuff error (bad cable?)";
411 break;
412 case -EILSEQ:
413 errmsg = "CRC/Timeout (could be anything)";
414 break;
415 case -ETIME:
416 errmsg = "Device does not respond";
417 break;
419 if (packet<0) {
420 dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
421 status, errmsg);
422 } else {
423 dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
424 packet, status, errmsg);
430 * Controls the isoc copy of each urb packet
432 static inline int tm6000_isoc_copy(struct urb *urb)
434 struct tm6000_dmaqueue *dma_q = urb->context;
435 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
436 int i, len=0, rc=1, status;
437 char *p;
439 if (urb->status < 0) {
440 print_err_status (dev, -1, urb->status);
441 return 0;
444 for (i = 0; i < urb->number_of_packets; i++) {
445 status = urb->iso_frame_desc[i].status;
447 if (status<0) {
448 print_err_status (dev,i,status);
449 continue;
452 len = urb->iso_frame_desc[i].actual_length;
454 if (len > 0) {
455 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
456 if (!urb->iso_frame_desc[i].status) {
457 if ((dev->fourcc)==V4L2_PIX_FMT_TM6000) {
458 rc=copy_multiplexed(p, len, urb);
459 if (rc<=0)
460 return rc;
461 } else {
462 copy_streams(p, len, urb);
467 return rc;
470 /* ------------------------------------------------------------------
471 URB control
472 ------------------------------------------------------------------*/
475 * IRQ callback, called by URB callback
477 static void tm6000_irq_callback(struct urb *urb)
479 struct tm6000_dmaqueue *dma_q = urb->context;
480 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
481 int i;
483 if (!dev)
484 return;
486 spin_lock(&dev->slock);
487 tm6000_isoc_copy(urb);
488 spin_unlock(&dev->slock);
490 /* Reset urb buffers */
491 for (i = 0; i < urb->number_of_packets; i++) {
492 urb->iso_frame_desc[i].status = 0;
493 urb->iso_frame_desc[i].actual_length = 0;
496 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
497 if (urb->status)
498 tm6000_err("urb resubmit failed (error=%i)\n",
499 urb->status);
503 * Stop and Deallocate URBs
505 static void tm6000_uninit_isoc(struct tm6000_core *dev)
507 struct urb *urb;
508 int i;
510 dev->isoc_ctl.buf = NULL;
511 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
512 urb=dev->isoc_ctl.urb[i];
513 if (urb) {
514 usb_kill_urb(urb);
515 usb_unlink_urb(urb);
516 if (dev->isoc_ctl.transfer_buffer[i]) {
517 usb_free_coherent(dev->udev,
518 urb->transfer_buffer_length,
519 dev->isoc_ctl.transfer_buffer[i],
520 urb->transfer_dma);
522 usb_free_urb(urb);
523 dev->isoc_ctl.urb[i] = NULL;
525 dev->isoc_ctl.transfer_buffer[i] = NULL;
528 kfree (dev->isoc_ctl.urb);
529 kfree (dev->isoc_ctl.transfer_buffer);
531 dev->isoc_ctl.urb=NULL;
532 dev->isoc_ctl.transfer_buffer=NULL;
533 dev->isoc_ctl.num_bufs = 0;
537 * Allocate URBs and start IRQ
539 static int tm6000_prepare_isoc(struct tm6000_core *dev, unsigned int framesize)
541 struct tm6000_dmaqueue *dma_q = &dev->vidq;
542 int i, j, sb_size, pipe, size, max_packets, num_bufs = 8;
543 struct urb *urb;
545 /* De-allocates all pending stuff */
546 tm6000_uninit_isoc(dev);
548 usb_set_interface(dev->udev,
549 dev->isoc_in.bInterfaceNumber,
550 dev->isoc_in.bAlternateSetting);
552 pipe = usb_rcvisocpipe(dev->udev,
553 dev->isoc_in.endp->desc.bEndpointAddress &
554 USB_ENDPOINT_NUMBER_MASK);
556 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
558 if (size > dev->isoc_in.maxsize)
559 size = dev->isoc_in.maxsize;
561 dev->isoc_ctl.max_pkt_size = size;
563 max_packets = ( framesize + size - 1) / size;
565 if (max_packets > TM6000_MAX_ISO_PACKETS)
566 max_packets = TM6000_MAX_ISO_PACKETS;
568 sb_size = max_packets * size;
570 dev->isoc_ctl.num_bufs = num_bufs;
572 dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
573 if (!dev->isoc_ctl.urb) {
574 tm6000_err("cannot alloc memory for usb buffers\n");
575 return -ENOMEM;
578 dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
579 GFP_KERNEL);
580 if (!dev->isoc_ctl.transfer_buffer) {
581 tm6000_err("cannot allocate memory for usbtransfer\n");
582 kfree(dev->isoc_ctl.urb);
583 return -ENOMEM;
586 dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
587 " (%d bytes) of %d bytes each to handle %u size\n",
588 max_packets, num_bufs, sb_size,
589 dev->isoc_in.maxsize, size);
591 /* allocate urbs and transfer buffers */
592 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
593 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
594 if (!urb) {
595 tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
596 tm6000_uninit_isoc(dev);
597 usb_free_urb(urb);
598 return -ENOMEM;
600 dev->isoc_ctl.urb[i] = urb;
602 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
603 sb_size, GFP_KERNEL, &urb->transfer_dma);
604 if (!dev->isoc_ctl.transfer_buffer[i]) {
605 tm6000_err ("unable to allocate %i bytes for transfer"
606 " buffer %i%s\n",
607 sb_size, i,
608 in_interrupt()?" while in int":"");
609 tm6000_uninit_isoc(dev);
610 return -ENOMEM;
612 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
614 usb_fill_bulk_urb(urb, dev->udev, pipe,
615 dev->isoc_ctl.transfer_buffer[i], sb_size,
616 tm6000_irq_callback, dma_q);
617 urb->interval = dev->isoc_in.endp->desc.bInterval;
618 urb->number_of_packets = max_packets;
619 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
621 for (j = 0; j < max_packets; j++) {
622 urb->iso_frame_desc[j].offset = size * j;
623 urb->iso_frame_desc[j].length = size;
627 return 0;
630 static int tm6000_start_thread( struct tm6000_core *dev)
632 struct tm6000_dmaqueue *dma_q = &dev->vidq;
633 int i;
635 dma_q->frame=0;
636 dma_q->ini_jiffies=jiffies;
638 init_waitqueue_head(&dma_q->wq);
640 /* submit urbs and enables IRQ */
641 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
642 int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
643 if (rc) {
644 tm6000_err("submit of urb %i failed (error=%i)\n", i,
645 rc);
646 tm6000_uninit_isoc(dev);
647 return rc;
651 return 0;
654 /* ------------------------------------------------------------------
655 Videobuf operations
656 ------------------------------------------------------------------*/
658 static int
659 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
661 struct tm6000_fh *fh = vq->priv_data;
663 *size = fh->fmt->depth * fh->width * fh->height >> 3;
664 if (0 == *count)
665 *count = TM6000_DEF_BUF;
667 if (*count < TM6000_MIN_BUF) {
668 *count=TM6000_MIN_BUF;
671 while (*size * *count > vid_limit * 1024 * 1024)
672 (*count)--;
674 return 0;
677 static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
679 struct tm6000_fh *fh = vq->priv_data;
680 struct tm6000_core *dev = fh->dev;
681 unsigned long flags;
683 if (in_interrupt())
684 BUG();
686 /* We used to wait for the buffer to finish here, but this didn't work
687 because, as we were keeping the state as VIDEOBUF_QUEUED,
688 videobuf_queue_cancel marked it as finished for us.
689 (Also, it could wedge forever if the hardware was misconfigured.)
691 This should be safe; by the time we get here, the buffer isn't
692 queued anymore. If we ever start marking the buffers as
693 VIDEOBUF_ACTIVE, it won't be, though.
695 spin_lock_irqsave(&dev->slock, flags);
696 if (dev->isoc_ctl.buf == buf)
697 dev->isoc_ctl.buf = NULL;
698 spin_unlock_irqrestore(&dev->slock, flags);
700 videobuf_vmalloc_free(&buf->vb);
701 buf->vb.state = VIDEOBUF_NEEDS_INIT;
704 static int
705 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
706 enum v4l2_field field)
708 struct tm6000_fh *fh = vq->priv_data;
709 struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb);
710 struct tm6000_core *dev = fh->dev;
711 int rc = 0, urb_init = 0;
713 BUG_ON(NULL == fh->fmt);
716 /* FIXME: It assumes depth=2 */
717 /* The only currently supported format is 16 bits/pixel */
718 buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
719 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
720 return -EINVAL;
722 if (buf->fmt != fh->fmt ||
723 buf->vb.width != fh->width ||
724 buf->vb.height != fh->height ||
725 buf->vb.field != field) {
726 buf->fmt = fh->fmt;
727 buf->vb.width = fh->width;
728 buf->vb.height = fh->height;
729 buf->vb.field = field;
730 buf->vb.state = VIDEOBUF_NEEDS_INIT;
733 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
734 if (0 != (rc = videobuf_iolock(vq, &buf->vb, NULL)))
735 goto fail;
736 urb_init = 1;
739 if (!dev->isoc_ctl.num_bufs)
740 urb_init = 1;
742 if (urb_init) {
743 rc = tm6000_prepare_isoc(dev, buf->vb.size);
744 if (rc < 0)
745 goto fail;
747 rc = tm6000_start_thread(dev);
748 if (rc < 0)
749 goto fail;
753 buf->vb.state = VIDEOBUF_PREPARED;
754 return 0;
756 fail:
757 free_buffer(vq, buf);
758 return rc;
761 static void
762 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
764 struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb);
765 struct tm6000_fh *fh = vq->priv_data;
766 struct tm6000_core *dev = fh->dev;
767 struct tm6000_dmaqueue *vidq = &dev->vidq;
769 buf->vb.state = VIDEOBUF_QUEUED;
770 list_add_tail(&buf->vb.queue, &vidq->active);
773 static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
775 struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb);
777 free_buffer(vq,buf);
780 static struct videobuf_queue_ops tm6000_video_qops = {
781 .buf_setup = buffer_setup,
782 .buf_prepare = buffer_prepare,
783 .buf_queue = buffer_queue,
784 .buf_release = buffer_release,
787 /* ------------------------------------------------------------------
788 IOCTL handling
789 ------------------------------------------------------------------*/
791 static int res_get(struct tm6000_core *dev, struct tm6000_fh *fh)
793 /* is it free? */
794 if (dev->resources)
795 return 0;
796 /* it's free, grab it */
797 dev->resources =1;
798 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
799 return 1;
802 static int res_locked(struct tm6000_core *dev)
804 return (dev->resources);
807 static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
809 dev->resources = 0;
810 dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
813 /* ------------------------------------------------------------------
814 IOCTL vidioc handling
815 ------------------------------------------------------------------*/
816 static int vidioc_querycap (struct file *file, void *priv,
817 struct v4l2_capability *cap)
819 // struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
821 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
822 strlcpy(cap->card,"Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
823 // strlcpy(cap->bus_info, dev->udev->dev.bus_id, sizeof(cap->bus_info));
824 cap->version = TM6000_VERSION;
825 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
826 V4L2_CAP_STREAMING |
827 V4L2_CAP_TUNER |
828 V4L2_CAP_READWRITE;
829 return 0;
832 static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
833 struct v4l2_fmtdesc *f)
835 if (unlikely(f->index >= ARRAY_SIZE(format)))
836 return -EINVAL;
838 strlcpy(f->description,format[f->index].name,sizeof(f->description));
839 f->pixelformat = format[f->index].fourcc;
840 return 0;
843 static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
844 struct v4l2_format *f)
846 struct tm6000_fh *fh=priv;
848 f->fmt.pix.width = fh->width;
849 f->fmt.pix.height = fh->height;
850 f->fmt.pix.field = fh->vb_vidq.field;
851 f->fmt.pix.pixelformat = fh->fmt->fourcc;
852 f->fmt.pix.bytesperline =
853 (f->fmt.pix.width * fh->fmt->depth) >> 3;
854 f->fmt.pix.sizeimage =
855 f->fmt.pix.height * f->fmt.pix.bytesperline;
857 return (0);
860 static struct tm6000_fmt* format_by_fourcc(unsigned int fourcc)
862 unsigned int i;
864 for (i = 0; i < ARRAY_SIZE(format); i++)
865 if (format[i].fourcc == fourcc)
866 return format+i;
867 return NULL;
870 static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
871 struct v4l2_format *f)
873 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
874 struct tm6000_fmt *fmt;
875 enum v4l2_field field;
877 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
878 if (NULL == fmt) {
879 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)"
880 " invalid.\n", f->fmt.pix.pixelformat);
881 return -EINVAL;
884 field = f->fmt.pix.field;
886 if (field == V4L2_FIELD_ANY) {
887 // field=V4L2_FIELD_INTERLACED;
888 field=V4L2_FIELD_SEQ_TB;
889 } else if (V4L2_FIELD_INTERLACED != field) {
890 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
891 return -EINVAL;
894 tm6000_get_std_res (dev);
896 f->fmt.pix.width = dev->width;
897 f->fmt.pix.height = dev->height;
899 f->fmt.pix.width &= ~0x01;
901 f->fmt.pix.field = field;
903 f->fmt.pix.bytesperline =
904 (f->fmt.pix.width * fmt->depth) >> 3;
905 f->fmt.pix.sizeimage =
906 f->fmt.pix.height * f->fmt.pix.bytesperline;
908 return 0;
911 /*FIXME: This seems to be generic enough to be at videodev2 */
912 static int vidioc_s_fmt_vid_cap (struct file *file, void *priv,
913 struct v4l2_format *f)
915 struct tm6000_fh *fh=priv;
916 struct tm6000_core *dev = fh->dev;
917 int ret = vidioc_try_fmt_vid_cap(file,fh,f);
918 if (ret < 0)
919 return (ret);
921 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
922 fh->width = f->fmt.pix.width;
923 fh->height = f->fmt.pix.height;
924 fh->vb_vidq.field = f->fmt.pix.field;
925 fh->type = f->type;
927 dev->fourcc = f->fmt.pix.pixelformat;
929 tm6000_set_fourcc_format(dev);
931 return (0);
934 static int vidioc_reqbufs (struct file *file, void *priv,
935 struct v4l2_requestbuffers *p)
937 struct tm6000_fh *fh=priv;
939 return (videobuf_reqbufs(&fh->vb_vidq, p));
942 static int vidioc_querybuf (struct file *file, void *priv,
943 struct v4l2_buffer *p)
945 struct tm6000_fh *fh=priv;
947 return (videobuf_querybuf(&fh->vb_vidq, p));
950 static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
952 struct tm6000_fh *fh=priv;
954 return (videobuf_qbuf(&fh->vb_vidq, p));
957 static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
959 struct tm6000_fh *fh=priv;
961 return (videobuf_dqbuf(&fh->vb_vidq, p,
962 file->f_flags & O_NONBLOCK));
965 #ifdef CONFIG_VIDEO_V4L1_COMPAT
966 static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
968 struct tm6000_fh *fh=priv;
970 return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8);
972 #endif
974 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
976 struct tm6000_fh *fh=priv;
977 struct tm6000_core *dev = fh->dev;
979 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
980 return -EINVAL;
981 if (i != fh->type)
982 return -EINVAL;
984 if (!res_get(dev,fh))
985 return -EBUSY;
986 return (videobuf_streamon(&fh->vb_vidq));
989 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
991 struct tm6000_fh *fh=priv;
992 struct tm6000_core *dev = fh->dev;
994 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
995 return -EINVAL;
996 if (i != fh->type)
997 return -EINVAL;
999 videobuf_streamoff(&fh->vb_vidq);
1000 res_free(dev,fh);
1002 return (0);
1005 static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *norm)
1007 int rc=0;
1008 struct tm6000_fh *fh=priv;
1009 struct tm6000_core *dev = fh->dev;
1011 rc = tm6000_init_analog_mode(dev);
1013 fh->width = dev->width;
1014 fh->height = dev->height;
1016 if (rc<0)
1017 return rc;
1019 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1021 return 0;
1024 static int vidioc_enum_input (struct file *file, void *priv,
1025 struct v4l2_input *inp)
1027 switch (inp->index) {
1028 case TM6000_INPUT_TV:
1029 inp->type = V4L2_INPUT_TYPE_TUNER;
1030 strcpy(inp->name,"Television");
1031 break;
1032 case TM6000_INPUT_COMPOSITE:
1033 inp->type = V4L2_INPUT_TYPE_CAMERA;
1034 strcpy(inp->name,"Composite");
1035 break;
1036 case TM6000_INPUT_SVIDEO:
1037 inp->type = V4L2_INPUT_TYPE_CAMERA;
1038 strcpy(inp->name,"S-Video");
1039 break;
1040 default:
1041 return -EINVAL;
1043 inp->std = TM6000_STD;
1045 return 0;
1048 static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
1050 struct tm6000_fh *fh=priv;
1051 struct tm6000_core *dev = fh->dev;
1053 *i=dev->input;
1055 return 0;
1057 static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1059 struct tm6000_fh *fh=priv;
1060 struct tm6000_core *dev = fh->dev;
1061 int rc=0;
1062 char buf[1];
1064 switch (i) {
1065 case TM6000_INPUT_TV:
1066 dev->input=i;
1067 *buf=0;
1068 break;
1069 case TM6000_INPUT_COMPOSITE:
1070 case TM6000_INPUT_SVIDEO:
1071 dev->input=i;
1072 *buf=1;
1073 break;
1074 default:
1075 return -EINVAL;
1077 rc=tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR,
1078 REQ_03_SET_GET_MCU_PIN, 0x03, 1, buf, 1);
1080 if (!rc) {
1081 dev->input=i;
1082 rc=vidioc_s_std (file, priv, &dev->vfd->current_norm);
1085 return (rc);
1088 /* --- controls ---------------------------------------------- */
1089 static int vidioc_queryctrl (struct file *file, void *priv,
1090 struct v4l2_queryctrl *qc)
1092 int i;
1094 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1095 if (qc->id && qc->id == tm6000_qctrl[i].id) {
1096 memcpy(qc, &(tm6000_qctrl[i]),
1097 sizeof(*qc));
1098 return (0);
1101 return -EINVAL;
1104 static int vidioc_g_ctrl (struct file *file, void *priv,
1105 struct v4l2_control *ctrl)
1107 struct tm6000_fh *fh=priv;
1108 struct tm6000_core *dev = fh->dev;
1109 int val;
1111 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1112 switch (ctrl->id) {
1113 case V4L2_CID_CONTRAST:
1114 val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0);
1115 break;
1116 case V4L2_CID_BRIGHTNESS:
1117 val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0);
1118 return 0;
1119 case V4L2_CID_SATURATION:
1120 val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0);
1121 return 0;
1122 case V4L2_CID_HUE:
1123 val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0);
1124 return 0;
1125 default:
1126 return -EINVAL;
1129 if (val<0)
1130 return val;
1132 ctrl->value=val;
1134 return 0;
1136 static int vidioc_s_ctrl (struct file *file, void *priv,
1137 struct v4l2_control *ctrl)
1139 struct tm6000_fh *fh =priv;
1140 struct tm6000_core *dev = fh->dev;
1141 u8 val=ctrl->value;
1143 switch (ctrl->id) {
1144 case V4L2_CID_CONTRAST:
1145 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1146 return 0;
1147 case V4L2_CID_BRIGHTNESS:
1148 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1149 return 0;
1150 case V4L2_CID_SATURATION:
1151 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1152 return 0;
1153 case V4L2_CID_HUE:
1154 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1155 return 0;
1157 return -EINVAL;
1160 static int vidioc_g_tuner (struct file *file, void *priv,
1161 struct v4l2_tuner *t)
1163 struct tm6000_fh *fh =priv;
1164 struct tm6000_core *dev = fh->dev;
1166 if (unlikely(UNSET == dev->tuner_type))
1167 return -EINVAL;
1168 if (0 != t->index)
1169 return -EINVAL;
1171 strcpy(t->name, "Television");
1172 t->type = V4L2_TUNER_ANALOG_TV;
1173 t->capability = V4L2_TUNER_CAP_NORM;
1174 t->rangehigh = 0xffffffffUL;
1175 t->rxsubchans = V4L2_TUNER_SUB_MONO;
1177 return 0;
1180 static int vidioc_s_tuner (struct file *file, void *priv,
1181 struct v4l2_tuner *t)
1183 struct tm6000_fh *fh =priv;
1184 struct tm6000_core *dev = fh->dev;
1186 if (UNSET == dev->tuner_type)
1187 return -EINVAL;
1188 if (0 != t->index)
1189 return -EINVAL;
1191 return 0;
1194 static int vidioc_g_frequency (struct file *file, void *priv,
1195 struct v4l2_frequency *f)
1197 struct tm6000_fh *fh =priv;
1198 struct tm6000_core *dev = fh->dev;
1200 if (unlikely(UNSET == dev->tuner_type))
1201 return -EINVAL;
1203 f->type = V4L2_TUNER_ANALOG_TV;
1204 f->frequency = dev->freq;
1206 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1208 return 0;
1211 static int vidioc_s_frequency (struct file *file, void *priv,
1212 struct v4l2_frequency *f)
1214 struct tm6000_fh *fh =priv;
1215 struct tm6000_core *dev = fh->dev;
1217 if (unlikely(f->type != V4L2_TUNER_ANALOG_TV))
1218 return -EINVAL;
1220 if (unlikely(UNSET == dev->tuner_type))
1221 return -EINVAL;
1222 if (unlikely(f->tuner != 0))
1223 return -EINVAL;
1225 dev->freq = f->frequency;
1226 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1228 return 0;
1231 /* ------------------------------------------------------------------
1232 File operations for the device
1233 ------------------------------------------------------------------*/
1235 static int tm6000_open(struct file *file)
1237 struct video_device *vdev = video_devdata(file);
1238 struct tm6000_core *dev = video_drvdata(file);
1239 struct tm6000_fh *fh;
1240 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1241 int i,rc;
1243 printk(KERN_INFO "tm6000: open called (dev=%s)\n",
1244 video_device_node_name(vdev));
1246 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
1247 video_device_node_name(vdev));
1250 /* If more than one user, mutex should be added */
1251 dev->users++;
1253 dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
1254 video_device_node_name(vdev), v4l2_type_names[type],
1255 dev->users);
1257 /* allocate + initialize per filehandle data */
1258 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1259 if (NULL == fh) {
1260 dev->users--;
1261 return -ENOMEM;
1264 file->private_data = fh;
1265 fh->dev = dev;
1267 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1268 dev->fourcc = format[0].fourcc;
1270 fh->fmt = format_by_fourcc(dev->fourcc);
1272 tm6000_get_std_res (dev);
1274 fh->width = dev->width;
1275 fh->height = dev->height;
1277 dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
1278 "dev->vidq=0x%08lx\n",
1279 (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
1280 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1281 "queued=%d\n",list_empty(&dev->vidq.queued));
1282 dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
1283 "active=%d\n",list_empty(&dev->vidq.active));
1285 /* initialize hardware on analog mode */
1286 rc = tm6000_init_analog_mode(dev);
1287 if (rc < 0)
1288 return rc;
1290 if (dev->mode != TM6000_MODE_ANALOG) {
1291 /* Put all controls at a sane state */
1292 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1293 qctl_regs[i] = tm6000_qctrl[i].default_value;
1295 dev->mode = TM6000_MODE_ANALOG;
1298 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
1299 NULL, &dev->slock,
1300 fh->type,
1301 V4L2_FIELD_INTERLACED,
1302 sizeof(struct tm6000_buffer), fh, &dev->lock);
1304 return 0;
1307 static ssize_t
1308 tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1310 struct tm6000_fh *fh = file->private_data;
1312 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1313 if (res_locked(fh->dev))
1314 return -EBUSY;
1316 return videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
1317 file->f_flags & O_NONBLOCK);
1319 return 0;
1322 static unsigned int
1323 tm6000_poll(struct file *file, struct poll_table_struct *wait)
1325 struct tm6000_fh *fh = file->private_data;
1326 struct tm6000_buffer *buf;
1328 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1329 return POLLERR;
1331 if (res_get(fh->dev,fh)) {
1332 /* streaming capture */
1333 if (list_empty(&fh->vb_vidq.stream))
1334 return POLLERR;
1335 buf = list_entry(fh->vb_vidq.stream.next,struct tm6000_buffer,vb.stream);
1336 } else {
1337 /* read() capture */
1338 return videobuf_poll_stream(file, &fh->vb_vidq,
1339 wait);
1341 poll_wait(file, &buf->vb.done, wait);
1342 if (buf->vb.state == VIDEOBUF_DONE ||
1343 buf->vb.state == VIDEOBUF_ERROR)
1344 return POLLIN|POLLRDNORM;
1345 return 0;
1348 static int tm6000_release(struct file *file)
1350 struct tm6000_fh *fh = file->private_data;
1351 struct tm6000_core *dev = fh->dev;
1352 struct video_device *vdev = video_devdata(file);
1354 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
1355 video_device_node_name(vdev), dev->users);
1357 dev->users--;
1359 if (!dev->users) {
1360 tm6000_uninit_isoc(dev);
1361 videobuf_mmap_free(&fh->vb_vidq);
1364 kfree (fh);
1366 return 0;
1369 static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
1371 struct tm6000_fh *fh = file->private_data;
1372 int ret;
1374 ret=videobuf_mmap_mapper(&fh->vb_vidq, vma);
1376 return ret;
1379 static struct v4l2_file_operations tm6000_fops = {
1380 .owner = THIS_MODULE,
1381 .open = tm6000_open,
1382 .release = tm6000_release,
1383 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1384 .read = tm6000_read,
1385 .poll = tm6000_poll,
1386 .mmap = tm6000_mmap,
1389 static const struct v4l2_ioctl_ops video_ioctl_ops = {
1390 .vidioc_querycap = vidioc_querycap,
1391 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1392 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1393 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1394 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1395 .vidioc_s_std = vidioc_s_std,
1396 .vidioc_enum_input = vidioc_enum_input,
1397 .vidioc_g_input = vidioc_g_input,
1398 .vidioc_s_input = vidioc_s_input,
1399 .vidioc_queryctrl = vidioc_queryctrl,
1400 .vidioc_g_ctrl = vidioc_g_ctrl,
1401 .vidioc_s_ctrl = vidioc_s_ctrl,
1402 .vidioc_g_tuner = vidioc_g_tuner,
1403 .vidioc_s_tuner = vidioc_s_tuner,
1404 .vidioc_g_frequency = vidioc_g_frequency,
1405 .vidioc_s_frequency = vidioc_s_frequency,
1406 .vidioc_streamon = vidioc_streamon,
1407 .vidioc_streamoff = vidioc_streamoff,
1408 .vidioc_reqbufs = vidioc_reqbufs,
1409 .vidioc_querybuf = vidioc_querybuf,
1410 .vidioc_qbuf = vidioc_qbuf,
1411 .vidioc_dqbuf = vidioc_dqbuf,
1412 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1413 .vidiocgmbuf = vidiocgmbuf,
1414 #endif
1417 static struct video_device tm6000_template = {
1418 .name = "tm6000",
1419 .fops = &tm6000_fops,
1420 .ioctl_ops = &video_ioctl_ops,
1421 .release = video_device_release,
1422 .tvnorms = TM6000_STD,
1423 .current_norm = V4L2_STD_NTSC_M,
1426 /* -----------------------------------------------------------------
1427 Initialization and module stuff
1428 ------------------------------------------------------------------*/
1430 int tm6000_v4l2_register(struct tm6000_core *dev)
1432 int ret = -1;
1433 struct video_device *vfd;
1435 vfd = video_device_alloc();
1436 if(!vfd) {
1437 return -ENOMEM;
1439 dev->vfd = vfd;
1441 /* init video dma queues */
1442 INIT_LIST_HEAD(&dev->vidq.active);
1443 INIT_LIST_HEAD(&dev->vidq.queued);
1445 memcpy(dev->vfd, &tm6000_template, sizeof(*(dev->vfd)));
1446 dev->vfd->debug = tm6000_debug;
1447 dev->vfd->lock = &dev->lock;
1449 vfd->v4l2_dev = &dev->v4l2_dev;
1450 video_set_drvdata(vfd, dev);
1452 ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr);
1453 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1454 return ret;
1457 int tm6000_v4l2_unregister(struct tm6000_core *dev)
1459 video_unregister_device(dev->vfd);
1461 return 0;
1464 int tm6000_v4l2_exit(void)
1466 return 0;
1469 module_param(video_nr, int, 0);
1470 MODULE_PARM_DESC(video_nr,"Allow changing video device number");
1472 module_param_named (debug, tm6000_debug, int, 0444);
1473 MODULE_PARM_DESC(debug,"activates debug info");
1475 module_param(vid_limit,int,0644);
1476 MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");