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
);
174 if (list_empty(&dma_q
->active
)) {
175 dprintk(dev
, V4L2_DEBUG_QUEUE
, "No active queue to serve\n");
180 *buf
= list_entry(dma_q
->active
.next
,
181 struct tm6000_buffer
, vb
.queue
);
183 /* Cleans up buffer - Useful for testing for frame/URB loss */
184 outp
= videobuf_to_vmalloc(&(*buf
)->vb
);
190 * Announces that a buffer were filled and request the next
192 static inline void buffer_filled(struct tm6000_core
*dev
,
193 struct tm6000_dmaqueue
*dma_q
,
194 struct tm6000_buffer
*buf
)
196 /* Advice that buffer was filled */
197 dprintk(dev
, V4L2_DEBUG_ISOC
, "[%p/%d] wakeup\n", buf
, buf
->vb
.i
);
198 buf
->vb
.state
= VIDEOBUF_DONE
;
199 buf
->vb
.field_count
++;
200 do_gettimeofday(&buf
->vb
.ts
);
202 list_del(&buf
->vb
.queue
);
203 wake_up(&buf
->vb
.done
);
207 * Identify the tm5600/6000 buffer header type and properly handles
209 static int copy_streams(u8
*data
, unsigned long len
,
212 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
213 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
214 u8
*ptr
= data
, *endp
= data
+len
, c
;
215 unsigned long header
= 0;
217 unsigned int cmd
, cpysize
, pktsize
, size
, field
, block
, line
, pos
= 0;
218 struct tm6000_buffer
*vbuf
= NULL
;
220 unsigned int linewidth
;
223 /* get video buffer */
224 get_next_buf(dma_q
, &vbuf
);
228 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
234 for (ptr
= data
; ptr
< endp
;) {
235 if (!dev
->isoc_ctl
.cmd
) {
237 if (dev
->isoc_ctl
.tmp_buf_len
> 0) {
238 /* from last urb or packet */
239 header
= dev
->isoc_ctl
.tmp_buf
;
240 if (4 - dev
->isoc_ctl
.tmp_buf_len
> 0) {
241 memcpy((u8
*)&header
+
242 dev
->isoc_ctl
.tmp_buf_len
,
244 4 - dev
->isoc_ctl
.tmp_buf_len
);
245 ptr
+= 4 - dev
->isoc_ctl
.tmp_buf_len
;
247 dev
->isoc_ctl
.tmp_buf_len
= 0;
249 if (ptr
+ 3 >= endp
) {
250 /* have incomplete header */
251 dev
->isoc_ctl
.tmp_buf_len
= endp
- ptr
;
252 memcpy(&dev
->isoc_ctl
.tmp_buf
, ptr
,
253 dev
->isoc_ctl
.tmp_buf_len
);
257 for (; ptr
< endp
- 3; ptr
++) {
258 if (*(ptr
+ 3) == 0x47)
261 /* Get message header */
262 header
= *(unsigned long *)ptr
;
266 /* split the header fields */
267 c
= (header
>> 24) & 0xff;
268 size
= ((header
& 0x7e) << 1);
271 block
= (header
>> 7) & 0xf;
272 field
= (header
>> 11) & 0x1;
273 line
= (header
>> 12) & 0x1ff;
274 cmd
= (header
>> 21) & 0x7;
275 /* Validates haeder fields */
276 if (size
> TM6000_URB_MSG_LEN
)
277 size
= TM6000_URB_MSG_LEN
;
278 pktsize
= TM6000_URB_MSG_LEN
;
280 * calculate position in buffer and change the buffer
283 case TM6000_URB_MSG_VIDEO
:
285 if ((dev
->isoc_ctl
.vfield
!= field
) &&
288 * Announces that a new buffer
291 buffer_filled(dev
, dma_q
, vbuf
);
292 dprintk(dev
, V4L2_DEBUG_ISOC
,
293 "new buffer filled\n");
294 get_next_buf(dma_q
, &vbuf
);
297 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
300 memset(voutp
, 0, vbuf
->vb
.size
);
302 linewidth
= vbuf
->vb
.width
<< 1;
303 pos
= ((line
<< 1) - field
- 1) *
304 linewidth
+ block
* TM6000_URB_MSG_LEN
;
305 /* Don't allow to write out of the buffer */
306 if (pos
+ size
> vbuf
->vb
.size
)
307 cmd
= TM6000_URB_MSG_ERR
;
308 dev
->isoc_ctl
.vfield
= field
;
311 case TM6000_URB_MSG_VBI
:
313 case TM6000_URB_MSG_AUDIO
:
314 case TM6000_URB_MSG_PTS
:
315 size
= pktsize
; /* Size is always 180 bytes */
319 /* Continue the last copy */
320 cmd
= dev
->isoc_ctl
.cmd
;
321 size
= dev
->isoc_ctl
.size
;
322 pos
= dev
->isoc_ctl
.pos
;
323 pktsize
= dev
->isoc_ctl
.pktsize
;
324 field
= dev
->isoc_ctl
.field
;
326 cpysize
= (endp
- ptr
> size
) ? size
: endp
- ptr
;
328 /* copy data in different buffers */
330 case TM6000_URB_MSG_VIDEO
:
331 /* Fills video buffer */
333 memcpy(&voutp
[pos
], ptr
, cpysize
);
335 case TM6000_URB_MSG_AUDIO
: {
337 for (i
= 0; i
< cpysize
; i
+= 2)
338 swab16s((u16
*)(ptr
+ i
));
340 tm6000_call_fillbuf(dev
, TM6000_AUDIO
, ptr
, cpysize
);
343 case TM6000_URB_MSG_VBI
:
344 /* Need some code to copy vbi buffer */
346 case TM6000_URB_MSG_PTS
: {
347 /* Need some code to copy pts */
350 dprintk(dev
, V4L2_DEBUG_ISOC
, "field %d, PTS %x",
356 if (ptr
+ pktsize
> endp
) {
358 * End of URB packet, but cmd processing is not
359 * complete. Preserve the state for a next packet
361 dev
->isoc_ctl
.pos
= pos
+ cpysize
;
362 dev
->isoc_ctl
.size
= size
- cpysize
;
363 dev
->isoc_ctl
.cmd
= cmd
;
364 dev
->isoc_ctl
.field
= field
;
365 dev
->isoc_ctl
.pktsize
= pktsize
- (endp
- ptr
);
368 dev
->isoc_ctl
.cmd
= 0;
376 * Identify the tm5600/6000 buffer header type and properly handles
378 static int copy_multiplexed(u8
*ptr
, unsigned long len
,
381 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
382 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
383 unsigned int pos
= dev
->isoc_ctl
.pos
, cpysize
;
385 struct tm6000_buffer
*buf
;
388 get_next_buf(dma_q
, &buf
);
390 outp
= videobuf_to_vmalloc(&buf
->vb
);
396 cpysize
= min(len
, buf
->vb
.size
-pos
);
397 memcpy(&outp
[pos
], ptr
, cpysize
);
401 if (pos
>= buf
->vb
.size
) {
403 /* Announces that a new buffer were filled */
404 buffer_filled(dev
, dma_q
, buf
);
405 dprintk(dev
, V4L2_DEBUG_ISOC
, "new buffer filled\n");
406 get_next_buf(dma_q
, &buf
);
409 outp
= videobuf_to_vmalloc(&(buf
->vb
));
416 dev
->isoc_ctl
.pos
= pos
;
420 static inline void print_err_status(struct tm6000_core
*dev
,
421 int packet
, int status
)
423 char *errmsg
= "Unknown";
427 errmsg
= "unlinked synchronuously";
430 errmsg
= "unlinked asynchronuously";
433 errmsg
= "Buffer error (overrun)";
436 errmsg
= "Stalled (device not responding)";
439 errmsg
= "Babble (bad cable?)";
442 errmsg
= "Bit-stuff error (bad cable?)";
445 errmsg
= "CRC/Timeout (could be anything)";
448 errmsg
= "Device does not respond";
452 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB status %d [%s].\n",
455 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB packet %d, status %d [%s].\n",
456 packet
, status
, errmsg
);
462 * Controls the isoc copy of each urb packet
464 static inline int tm6000_isoc_copy(struct urb
*urb
)
466 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
467 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
468 int i
, len
= 0, rc
= 1, status
;
471 if (urb
->status
< 0) {
472 print_err_status(dev
, -1, urb
->status
);
476 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
477 status
= urb
->iso_frame_desc
[i
].status
;
480 print_err_status(dev
, i
, status
);
484 len
= urb
->iso_frame_desc
[i
].actual_length
;
487 p
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
488 if (!urb
->iso_frame_desc
[i
].status
) {
489 if ((dev
->fourcc
) == V4L2_PIX_FMT_TM6000
) {
490 rc
= copy_multiplexed(p
, len
, urb
);
494 copy_streams(p
, len
, urb
);
502 /* ------------------------------------------------------------------
504 * ------------------------------------------------------------------
508 * IRQ callback, called by URB callback
510 static void tm6000_irq_callback(struct urb
*urb
)
512 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
513 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
516 switch (urb
->status
) {
527 tm6000_err("urb completion error %d.\n", urb
->status
);
531 spin_lock(&dev
->slock
);
532 tm6000_isoc_copy(urb
);
533 spin_unlock(&dev
->slock
);
535 /* Reset urb buffers */
536 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
537 urb
->iso_frame_desc
[i
].status
= 0;
538 urb
->iso_frame_desc
[i
].actual_length
= 0;
541 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
543 tm6000_err("urb resubmit failed (error=%i)\n",
548 * Stop and Deallocate URBs
550 static void tm6000_uninit_isoc(struct tm6000_core
*dev
)
555 dev
->isoc_ctl
.buf
= NULL
;
556 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
557 urb
= dev
->isoc_ctl
.urb
[i
];
561 if (dev
->isoc_ctl
.transfer_buffer
[i
]) {
562 usb_free_coherent(dev
->udev
,
563 urb
->transfer_buffer_length
,
564 dev
->isoc_ctl
.transfer_buffer
[i
],
568 dev
->isoc_ctl
.urb
[i
] = NULL
;
570 dev
->isoc_ctl
.transfer_buffer
[i
] = NULL
;
573 kfree(dev
->isoc_ctl
.urb
);
574 kfree(dev
->isoc_ctl
.transfer_buffer
);
576 dev
->isoc_ctl
.urb
= NULL
;
577 dev
->isoc_ctl
.transfer_buffer
= NULL
;
578 dev
->isoc_ctl
.num_bufs
= 0;
582 * Allocate URBs and start IRQ
584 static int tm6000_prepare_isoc(struct tm6000_core
*dev
)
586 struct tm6000_dmaqueue
*dma_q
= &dev
->vidq
;
587 int i
, j
, sb_size
, pipe
, size
, max_packets
, num_bufs
= 8;
590 /* De-allocates all pending stuff */
591 tm6000_uninit_isoc(dev
);
592 /* Stop interrupt USB pipe */
593 tm6000_ir_int_stop(dev
);
595 usb_set_interface(dev
->udev
,
596 dev
->isoc_in
.bInterfaceNumber
,
597 dev
->isoc_in
.bAlternateSetting
);
599 /* Start interrupt USB pipe */
600 tm6000_ir_int_start(dev
);
602 pipe
= usb_rcvisocpipe(dev
->udev
,
603 dev
->isoc_in
.endp
->desc
.bEndpointAddress
&
604 USB_ENDPOINT_NUMBER_MASK
);
606 size
= usb_maxpacket(dev
->udev
, pipe
, usb_pipeout(pipe
));
608 if (size
> dev
->isoc_in
.maxsize
)
609 size
= dev
->isoc_in
.maxsize
;
611 dev
->isoc_ctl
.max_pkt_size
= size
;
613 max_packets
= TM6000_MAX_ISO_PACKETS
;
614 sb_size
= max_packets
* size
;
616 dev
->isoc_ctl
.num_bufs
= num_bufs
;
618 dev
->isoc_ctl
.urb
= kmalloc(sizeof(void *)*num_bufs
, GFP_KERNEL
);
619 if (!dev
->isoc_ctl
.urb
) {
620 tm6000_err("cannot alloc memory for usb buffers\n");
624 dev
->isoc_ctl
.transfer_buffer
= kmalloc(sizeof(void *)*num_bufs
,
626 if (!dev
->isoc_ctl
.transfer_buffer
) {
627 tm6000_err("cannot allocate memory for usbtransfer\n");
628 kfree(dev
->isoc_ctl
.urb
);
632 dprintk(dev
, V4L2_DEBUG_QUEUE
, "Allocating %d x %d packets"
633 " (%d bytes) of %d bytes each to handle %u size\n",
634 max_packets
, num_bufs
, sb_size
,
635 dev
->isoc_in
.maxsize
, size
);
637 /* allocate urbs and transfer buffers */
638 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
639 urb
= usb_alloc_urb(max_packets
, GFP_KERNEL
);
641 tm6000_err("cannot alloc isoc_ctl.urb %i\n", i
);
642 tm6000_uninit_isoc(dev
);
646 dev
->isoc_ctl
.urb
[i
] = urb
;
648 dev
->isoc_ctl
.transfer_buffer
[i
] = usb_alloc_coherent(dev
->udev
,
649 sb_size
, GFP_KERNEL
, &urb
->transfer_dma
);
650 if (!dev
->isoc_ctl
.transfer_buffer
[i
]) {
651 tm6000_err("unable to allocate %i bytes for transfer"
654 in_interrupt() ? " while in int" : "");
655 tm6000_uninit_isoc(dev
);
658 memset(dev
->isoc_ctl
.transfer_buffer
[i
], 0, sb_size
);
660 usb_fill_bulk_urb(urb
, dev
->udev
, pipe
,
661 dev
->isoc_ctl
.transfer_buffer
[i
], sb_size
,
662 tm6000_irq_callback
, dma_q
);
663 urb
->interval
= dev
->isoc_in
.endp
->desc
.bInterval
;
664 urb
->number_of_packets
= max_packets
;
665 urb
->transfer_flags
= URB_ISO_ASAP
| URB_NO_TRANSFER_DMA_MAP
;
667 for (j
= 0; j
< max_packets
; j
++) {
668 urb
->iso_frame_desc
[j
].offset
= size
* j
;
669 urb
->iso_frame_desc
[j
].length
= size
;
676 static int tm6000_start_thread(struct tm6000_core
*dev
)
678 struct tm6000_dmaqueue
*dma_q
= &dev
->vidq
;
682 dma_q
->ini_jiffies
= jiffies
;
684 init_waitqueue_head(&dma_q
->wq
);
686 /* submit urbs and enables IRQ */
687 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
688 int rc
= usb_submit_urb(dev
->isoc_ctl
.urb
[i
], GFP_ATOMIC
);
690 tm6000_err("submit of urb %i failed (error=%i)\n", i
,
692 tm6000_uninit_isoc(dev
);
700 /* ------------------------------------------------------------------
701 * Videobuf operations
702 * ------------------------------------------------------------------
706 buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
, unsigned int *size
)
708 struct tm6000_fh
*fh
= vq
->priv_data
;
710 *size
= fh
->fmt
->depth
* fh
->width
* fh
->height
>> 3;
712 *count
= TM6000_DEF_BUF
;
714 if (*count
< TM6000_MIN_BUF
)
715 *count
= TM6000_MIN_BUF
;
717 while (*size
* *count
> vid_limit
* 1024 * 1024)
723 static void free_buffer(struct videobuf_queue
*vq
, struct tm6000_buffer
*buf
)
725 struct tm6000_fh
*fh
= vq
->priv_data
;
726 struct tm6000_core
*dev
= fh
->dev
;
732 /* We used to wait for the buffer to finish here, but this didn't work
733 because, as we were keeping the state as VIDEOBUF_QUEUED,
734 videobuf_queue_cancel marked it as finished for us.
735 (Also, it could wedge forever if the hardware was misconfigured.)
737 This should be safe; by the time we get here, the buffer isn't
738 queued anymore. If we ever start marking the buffers as
739 VIDEOBUF_ACTIVE, it won't be, though.
741 spin_lock_irqsave(&dev
->slock
, flags
);
742 if (dev
->isoc_ctl
.buf
== buf
)
743 dev
->isoc_ctl
.buf
= NULL
;
744 spin_unlock_irqrestore(&dev
->slock
, flags
);
746 videobuf_vmalloc_free(&buf
->vb
);
747 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
751 buffer_prepare(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
,
752 enum v4l2_field field
)
754 struct tm6000_fh
*fh
= vq
->priv_data
;
755 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
756 struct tm6000_core
*dev
= fh
->dev
;
759 BUG_ON(NULL
== fh
->fmt
);
762 /* FIXME: It assumes depth=2 */
763 /* The only currently supported format is 16 bits/pixel */
764 buf
->vb
.size
= fh
->fmt
->depth
*fh
->width
*fh
->height
>> 3;
765 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
768 if (buf
->fmt
!= fh
->fmt
||
769 buf
->vb
.width
!= fh
->width
||
770 buf
->vb
.height
!= fh
->height
||
771 buf
->vb
.field
!= field
) {
773 buf
->vb
.width
= fh
->width
;
774 buf
->vb
.height
= fh
->height
;
775 buf
->vb
.field
= field
;
776 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
779 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
780 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
785 if (!dev
->isoc_ctl
.num_bufs
) {
786 rc
= tm6000_prepare_isoc(dev
);
790 rc
= tm6000_start_thread(dev
);
796 buf
->vb
.state
= VIDEOBUF_PREPARED
;
800 free_buffer(vq
, buf
);
805 buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
807 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
808 struct tm6000_fh
*fh
= vq
->priv_data
;
809 struct tm6000_core
*dev
= fh
->dev
;
810 struct tm6000_dmaqueue
*vidq
= &dev
->vidq
;
812 buf
->vb
.state
= VIDEOBUF_QUEUED
;
813 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
816 static void buffer_release(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
818 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
820 free_buffer(vq
, buf
);
823 static struct videobuf_queue_ops tm6000_video_qops
= {
824 .buf_setup
= buffer_setup
,
825 .buf_prepare
= buffer_prepare
,
826 .buf_queue
= buffer_queue
,
827 .buf_release
= buffer_release
,
830 /* ------------------------------------------------------------------
832 * ------------------------------------------------------------------
835 static bool is_res_read(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
837 /* Is the current fh handling it? if so, that's OK */
838 if (dev
->resources
== fh
&& dev
->is_res_read
)
844 static bool is_res_streaming(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
846 /* Is the current fh handling it? if so, that's OK */
847 if (dev
->resources
== fh
)
853 static bool res_get(struct tm6000_core
*dev
, struct tm6000_fh
*fh
,
856 /* Is the current fh handling it? if so, that's OK */
857 if (dev
->resources
== fh
&& dev
->is_res_read
== is_res_read
)
866 dev
->is_res_read
= is_res_read
;
867 dprintk(dev
, V4L2_DEBUG_RES_LOCK
, "res: get\n");
871 static void res_free(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
873 /* Is the current fh handling it? if so, that's OK */
874 if (dev
->resources
!= fh
)
877 dev
->resources
= NULL
;
878 dprintk(dev
, V4L2_DEBUG_RES_LOCK
, "res: put\n");
881 /* ------------------------------------------------------------------
882 * IOCTL vidioc handling
883 * ------------------------------------------------------------------
885 static int vidioc_querycap(struct file
*file
, void *priv
,
886 struct v4l2_capability
*cap
)
888 struct tm6000_core
*dev
= ((struct tm6000_fh
*)priv
)->dev
;
890 strlcpy(cap
->driver
, "tm6000", sizeof(cap
->driver
));
891 strlcpy(cap
->card
, "Trident TVMaster TM5600/6000/6010", sizeof(cap
->card
));
892 cap
->version
= TM6000_VERSION
;
893 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
|
898 if (dev
->tuner_type
!= TUNER_ABSENT
)
899 cap
->capabilities
|= V4L2_CAP_TUNER
;
904 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
905 struct v4l2_fmtdesc
*f
)
907 if (unlikely(f
->index
>= ARRAY_SIZE(format
)))
910 strlcpy(f
->description
, format
[f
->index
].name
, sizeof(f
->description
));
911 f
->pixelformat
= format
[f
->index
].fourcc
;
915 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
916 struct v4l2_format
*f
)
918 struct tm6000_fh
*fh
= priv
;
920 f
->fmt
.pix
.width
= fh
->width
;
921 f
->fmt
.pix
.height
= fh
->height
;
922 f
->fmt
.pix
.field
= fh
->vb_vidq
.field
;
923 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
924 f
->fmt
.pix
.bytesperline
=
925 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
926 f
->fmt
.pix
.sizeimage
=
927 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
932 static struct tm6000_fmt
*format_by_fourcc(unsigned int fourcc
)
936 for (i
= 0; i
< ARRAY_SIZE(format
); i
++)
937 if (format
[i
].fourcc
== fourcc
)
942 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
943 struct v4l2_format
*f
)
945 struct tm6000_core
*dev
= ((struct tm6000_fh
*)priv
)->dev
;
946 struct tm6000_fmt
*fmt
;
947 enum v4l2_field field
;
949 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
951 dprintk(dev
, V4L2_DEBUG_IOCTL_ARG
, "Fourcc format (0x%08x)"
952 " invalid.\n", f
->fmt
.pix
.pixelformat
);
956 field
= f
->fmt
.pix
.field
;
958 if (field
== V4L2_FIELD_ANY
)
959 field
= V4L2_FIELD_SEQ_TB
;
960 else if (V4L2_FIELD_INTERLACED
!= field
) {
961 dprintk(dev
, V4L2_DEBUG_IOCTL_ARG
, "Field type invalid.\n");
965 tm6000_get_std_res(dev
);
967 f
->fmt
.pix
.width
= dev
->width
;
968 f
->fmt
.pix
.height
= dev
->height
;
970 f
->fmt
.pix
.width
&= ~0x01;
972 f
->fmt
.pix
.field
= field
;
974 f
->fmt
.pix
.bytesperline
=
975 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
976 f
->fmt
.pix
.sizeimage
=
977 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
982 /*FIXME: This seems to be generic enough to be at videodev2 */
983 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
984 struct v4l2_format
*f
)
986 struct tm6000_fh
*fh
= priv
;
987 struct tm6000_core
*dev
= fh
->dev
;
988 int ret
= vidioc_try_fmt_vid_cap(file
, fh
, f
);
992 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
993 fh
->width
= f
->fmt
.pix
.width
;
994 fh
->height
= f
->fmt
.pix
.height
;
995 fh
->vb_vidq
.field
= f
->fmt
.pix
.field
;
998 dev
->fourcc
= f
->fmt
.pix
.pixelformat
;
1000 tm6000_set_fourcc_format(dev
);
1005 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1006 struct v4l2_requestbuffers
*p
)
1008 struct tm6000_fh
*fh
= priv
;
1010 return videobuf_reqbufs(&fh
->vb_vidq
, p
);
1013 static int vidioc_querybuf(struct file
*file
, void *priv
,
1014 struct v4l2_buffer
*p
)
1016 struct tm6000_fh
*fh
= priv
;
1018 return videobuf_querybuf(&fh
->vb_vidq
, p
);
1021 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1023 struct tm6000_fh
*fh
= priv
;
1025 return videobuf_qbuf(&fh
->vb_vidq
, p
);
1028 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1030 struct tm6000_fh
*fh
= priv
;
1032 return videobuf_dqbuf(&fh
->vb_vidq
, p
,
1033 file
->f_flags
& O_NONBLOCK
);
1036 static int vidioc_streamon(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1038 struct tm6000_fh
*fh
= priv
;
1039 struct tm6000_core
*dev
= fh
->dev
;
1041 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1046 if (!res_get(dev
, fh
, false))
1048 return videobuf_streamon(&fh
->vb_vidq
);
1051 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1053 struct tm6000_fh
*fh
= priv
;
1054 struct tm6000_core
*dev
= fh
->dev
;
1056 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1062 videobuf_streamoff(&fh
->vb_vidq
);
1068 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*norm
)
1071 struct tm6000_fh
*fh
= priv
;
1072 struct tm6000_core
*dev
= fh
->dev
;
1075 rc
= tm6000_init_analog_mode(dev
);
1077 fh
->width
= dev
->width
;
1078 fh
->height
= dev
->height
;
1083 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
1088 static const char *iname
[] = {
1089 [TM6000_INPUT_TV
] = "Television",
1090 [TM6000_INPUT_COMPOSITE1
] = "Composite 1",
1091 [TM6000_INPUT_COMPOSITE2
] = "Composite 2",
1092 [TM6000_INPUT_SVIDEO
] = "S-Video",
1095 static int vidioc_enum_input(struct file
*file
, void *priv
,
1096 struct v4l2_input
*i
)
1098 struct tm6000_fh
*fh
= priv
;
1099 struct tm6000_core
*dev
= fh
->dev
;
1106 if (!dev
->vinput
[n
].type
)
1111 if (dev
->vinput
[n
].type
== TM6000_INPUT_TV
)
1112 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1114 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1116 strcpy(i
->name
, iname
[dev
->vinput
[n
].type
]);
1118 i
->std
= TM6000_STD
;
1123 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1125 struct tm6000_fh
*fh
= priv
;
1126 struct tm6000_core
*dev
= fh
->dev
;
1133 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1135 struct tm6000_fh
*fh
= priv
;
1136 struct tm6000_core
*dev
= fh
->dev
;
1141 if (!dev
->vinput
[i
].type
)
1146 rc
= vidioc_s_std(file
, priv
, &dev
->vfd
->current_norm
);
1151 /* --- controls ---------------------------------------------- */
1152 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1153 struct v4l2_queryctrl
*qc
)
1157 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1158 if (qc
->id
&& qc
->id
== tm6000_qctrl
[i
].id
) {
1159 memcpy(qc
, &(tm6000_qctrl
[i
]),
1167 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1168 struct v4l2_control
*ctrl
)
1170 struct tm6000_fh
*fh
= priv
;
1171 struct tm6000_core
*dev
= fh
->dev
;
1174 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1176 case V4L2_CID_CONTRAST
:
1177 val
= tm6000_get_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, 0);
1179 case V4L2_CID_BRIGHTNESS
:
1180 val
= tm6000_get_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, 0);
1182 case V4L2_CID_SATURATION
:
1183 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, 0);
1186 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, 0);
1188 case V4L2_CID_AUDIO_MUTE
:
1189 val
= dev
->ctl_mute
;
1191 case V4L2_CID_AUDIO_VOLUME
:
1192 val
= dev
->ctl_volume
;
1205 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1206 struct v4l2_control
*ctrl
)
1208 struct tm6000_fh
*fh
= priv
;
1209 struct tm6000_core
*dev
= fh
->dev
;
1210 u8 val
= ctrl
->value
;
1213 case V4L2_CID_CONTRAST
:
1214 tm6000_set_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, val
);
1216 case V4L2_CID_BRIGHTNESS
:
1217 tm6000_set_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, val
);
1219 case V4L2_CID_SATURATION
:
1220 tm6000_set_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, val
);
1223 tm6000_set_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, val
);
1225 case V4L2_CID_AUDIO_MUTE
:
1226 dev
->ctl_mute
= val
;
1227 tm6000_tvaudio_set_mute(dev
, val
);
1229 case V4L2_CID_AUDIO_VOLUME
:
1230 dev
->ctl_volume
= val
;
1231 tm6000_set_volume(dev
, val
);
1237 static int vidioc_g_tuner(struct file
*file
, void *priv
,
1238 struct v4l2_tuner
*t
)
1240 struct tm6000_fh
*fh
= priv
;
1241 struct tm6000_core
*dev
= fh
->dev
;
1243 if (unlikely(UNSET
== dev
->tuner_type
))
1248 strcpy(t
->name
, "Television");
1249 t
->type
= V4L2_TUNER_ANALOG_TV
;
1250 t
->capability
= V4L2_TUNER_CAP_NORM
;
1251 t
->rangehigh
= 0xffffffffUL
;
1252 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1254 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1256 t
->audmode
= dev
->amode
;
1261 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1262 struct v4l2_tuner
*t
)
1264 struct tm6000_fh
*fh
= priv
;
1265 struct tm6000_core
*dev
= fh
->dev
;
1267 if (UNSET
== dev
->tuner_type
)
1272 dev
->amode
= t
->audmode
;
1273 dprintk(dev
, 3, "audio mode: %x\n", t
->audmode
);
1275 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1280 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1281 struct v4l2_frequency
*f
)
1283 struct tm6000_fh
*fh
= priv
;
1284 struct tm6000_core
*dev
= fh
->dev
;
1286 if (unlikely(UNSET
== dev
->tuner_type
))
1289 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1290 f
->frequency
= dev
->freq
;
1292 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_frequency
, f
);
1297 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1298 struct v4l2_frequency
*f
)
1300 struct tm6000_fh
*fh
= priv
;
1301 struct tm6000_core
*dev
= fh
->dev
;
1303 if (unlikely(UNSET
== dev
->tuner_type
))
1305 if (unlikely(f
->tuner
!= 0))
1307 if (0 == fh
->radio
&& V4L2_TUNER_ANALOG_TV
!= f
->type
)
1309 if (1 == fh
->radio
&& V4L2_TUNER_RADIO
!= f
->type
)
1312 dev
->freq
= f
->frequency
;
1313 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, f
);
1318 static int radio_querycap(struct file
*file
, void *priv
,
1319 struct v4l2_capability
*cap
)
1321 struct tm6000_fh
*fh
= file
->private_data
;
1322 struct tm6000_core
*dev
= fh
->dev
;
1324 strcpy(cap
->driver
, "tm6000");
1325 strlcpy(cap
->card
, dev
->name
, sizeof(dev
->name
));
1326 sprintf(cap
->bus_info
, "USB%04x:%04x",
1327 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
1328 le16_to_cpu(dev
->udev
->descriptor
.idProduct
));
1329 cap
->version
= dev
->dev_type
;
1330 cap
->capabilities
= V4L2_CAP_TUNER
|
1333 V4L2_CAP_READWRITE
|
1339 static int radio_g_tuner(struct file
*file
, void *priv
,
1340 struct v4l2_tuner
*t
)
1342 struct tm6000_fh
*fh
= file
->private_data
;
1343 struct tm6000_core
*dev
= fh
->dev
;
1348 memset(t
, 0, sizeof(*t
));
1349 strcpy(t
->name
, "Radio");
1350 t
->type
= V4L2_TUNER_RADIO
;
1351 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1353 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1358 static int radio_s_tuner(struct file
*file
, void *priv
,
1359 struct v4l2_tuner
*t
)
1361 struct tm6000_fh
*fh
= file
->private_data
;
1362 struct tm6000_core
*dev
= fh
->dev
;
1367 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1372 static int radio_enum_input(struct file
*file
, void *priv
,
1373 struct v4l2_input
*i
)
1375 struct tm6000_fh
*fh
= priv
;
1376 struct tm6000_core
*dev
= fh
->dev
;
1381 if (!dev
->rinput
.type
)
1384 strcpy(i
->name
, "Radio");
1385 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1390 static int radio_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
1392 struct tm6000_fh
*fh
= priv
;
1393 struct tm6000_core
*dev
= fh
->dev
;
1395 if (dev
->input
!= 5)
1398 *i
= dev
->input
- 5;
1403 static int radio_g_audio(struct file
*file
, void *priv
,
1404 struct v4l2_audio
*a
)
1406 memset(a
, 0, sizeof(*a
));
1407 strcpy(a
->name
, "Radio");
1411 static int radio_s_audio(struct file
*file
, void *priv
,
1412 struct v4l2_audio
*a
)
1417 static int radio_s_input(struct file
*filp
, void *priv
, unsigned int i
)
1419 struct tm6000_fh
*fh
= priv
;
1420 struct tm6000_core
*dev
= fh
->dev
;
1425 if (!dev
->rinput
.type
)
1433 static int radio_s_std(struct file
*file
, void *fh
, v4l2_std_id
*norm
)
1438 static int radio_queryctrl(struct file
*file
, void *priv
,
1439 struct v4l2_queryctrl
*c
)
1441 const struct v4l2_queryctrl
*ctrl
;
1443 if (c
->id
< V4L2_CID_BASE
||
1444 c
->id
>= V4L2_CID_LASTP1
)
1446 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
1447 ctrl
= ctrl_by_id(c
->id
);
1455 /* ------------------------------------------------------------------
1456 File operations for the device
1457 ------------------------------------------------------------------*/
1459 static int tm6000_open(struct file
*file
)
1461 struct video_device
*vdev
= video_devdata(file
);
1462 struct tm6000_core
*dev
= video_drvdata(file
);
1463 struct tm6000_fh
*fh
;
1464 enum v4l2_buf_type type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1468 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: open called (dev=%s)\n",
1469 video_device_node_name(vdev
));
1471 switch (vdev
->vfl_type
) {
1472 case VFL_TYPE_GRABBER
:
1473 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1476 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1478 case VFL_TYPE_RADIO
:
1483 /* If more than one user, mutex should be added */
1486 dprintk(dev
, V4L2_DEBUG_OPEN
, "open dev=%s type=%s users=%d\n",
1487 video_device_node_name(vdev
), v4l2_type_names
[type
],
1490 /* allocate + initialize per filehandle data */
1491 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1497 file
->private_data
= fh
;
1502 dev
->fourcc
= format
[0].fourcc
;
1504 fh
->fmt
= format_by_fourcc(dev
->fourcc
);
1506 tm6000_get_std_res(dev
);
1508 fh
->width
= dev
->width
;
1509 fh
->height
= dev
->height
;
1511 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: fh=0x%08lx, dev=0x%08lx, "
1512 "dev->vidq=0x%08lx\n",
1513 (unsigned long)fh
, (unsigned long)dev
,
1514 (unsigned long)&dev
->vidq
);
1515 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1516 "queued=%d\n", list_empty(&dev
->vidq
.queued
));
1517 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1518 "active=%d\n", list_empty(&dev
->vidq
.active
));
1520 /* initialize hardware on analog mode */
1521 rc
= tm6000_init_analog_mode(dev
);
1525 if (dev
->mode
!= TM6000_MODE_ANALOG
) {
1526 /* Put all controls at a sane state */
1527 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1528 qctl_regs
[i
] = tm6000_qctrl
[i
].default_value
;
1530 dev
->mode
= TM6000_MODE_ANALOG
;
1534 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &tm6000_video_qops
,
1537 V4L2_FIELD_INTERLACED
,
1538 sizeof(struct tm6000_buffer
), fh
, &dev
->lock
);
1540 dprintk(dev
, V4L2_DEBUG_OPEN
, "video_open: setting radio device\n");
1542 tm6000_set_audio_rinput(dev
);
1543 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_radio
);
1544 tm6000_prepare_isoc(dev
);
1545 tm6000_start_thread(dev
);
1552 tm6000_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*pos
)
1554 struct tm6000_fh
*fh
= file
->private_data
;
1556 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1557 if (!res_get(fh
->dev
, fh
, true))
1560 return videobuf_read_stream(&fh
->vb_vidq
, data
, count
, pos
, 0,
1561 file
->f_flags
& O_NONBLOCK
);
1567 tm6000_poll(struct file
*file
, struct poll_table_struct
*wait
)
1569 struct tm6000_fh
*fh
= file
->private_data
;
1570 struct tm6000_buffer
*buf
;
1572 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= fh
->type
)
1575 if (!!is_res_streaming(fh
->dev
, fh
))
1578 if (!is_res_read(fh
->dev
, fh
)) {
1579 /* streaming capture */
1580 if (list_empty(&fh
->vb_vidq
.stream
))
1582 buf
= list_entry(fh
->vb_vidq
.stream
.next
, struct tm6000_buffer
, vb
.stream
);
1584 /* read() capture */
1585 return videobuf_poll_stream(file
, &fh
->vb_vidq
, wait
);
1587 poll_wait(file
, &buf
->vb
.done
, wait
);
1588 if (buf
->vb
.state
== VIDEOBUF_DONE
||
1589 buf
->vb
.state
== VIDEOBUF_ERROR
)
1590 return POLLIN
| POLLRDNORM
;
1594 static int tm6000_release(struct file
*file
)
1596 struct tm6000_fh
*fh
= file
->private_data
;
1597 struct tm6000_core
*dev
= fh
->dev
;
1598 struct video_device
*vdev
= video_devdata(file
);
1600 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: close called (dev=%s, users=%d)\n",
1601 video_device_node_name(vdev
), dev
->users
);
1608 tm6000_uninit_isoc(dev
);
1610 /* Stop interrupt USB pipe */
1611 tm6000_ir_int_stop(dev
);
1613 usb_reset_configuration(dev
->udev
);
1615 if (dev
->int_in
.endp
)
1616 usb_set_interface(dev
->udev
,
1617 dev
->isoc_in
.bInterfaceNumber
, 2);
1619 usb_set_interface(dev
->udev
,
1620 dev
->isoc_in
.bInterfaceNumber
, 0);
1622 /* Start interrupt USB pipe */
1623 tm6000_ir_int_start(dev
);
1626 videobuf_mmap_free(&fh
->vb_vidq
);
1634 static int tm6000_mmap(struct file
*file
, struct vm_area_struct
* vma
)
1636 struct tm6000_fh
*fh
= file
->private_data
;
1638 return videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
1641 static struct v4l2_file_operations tm6000_fops
= {
1642 .owner
= THIS_MODULE
,
1643 .open
= tm6000_open
,
1644 .release
= tm6000_release
,
1645 .unlocked_ioctl
= video_ioctl2
, /* V4L2 ioctl handler */
1646 .read
= tm6000_read
,
1647 .poll
= tm6000_poll
,
1648 .mmap
= tm6000_mmap
,
1651 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1652 .vidioc_querycap
= vidioc_querycap
,
1653 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1654 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1655 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1656 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1657 .vidioc_s_std
= vidioc_s_std
,
1658 .vidioc_enum_input
= vidioc_enum_input
,
1659 .vidioc_g_input
= vidioc_g_input
,
1660 .vidioc_s_input
= vidioc_s_input
,
1661 .vidioc_queryctrl
= vidioc_queryctrl
,
1662 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1663 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1664 .vidioc_g_tuner
= vidioc_g_tuner
,
1665 .vidioc_s_tuner
= vidioc_s_tuner
,
1666 .vidioc_g_frequency
= vidioc_g_frequency
,
1667 .vidioc_s_frequency
= vidioc_s_frequency
,
1668 .vidioc_streamon
= vidioc_streamon
,
1669 .vidioc_streamoff
= vidioc_streamoff
,
1670 .vidioc_reqbufs
= vidioc_reqbufs
,
1671 .vidioc_querybuf
= vidioc_querybuf
,
1672 .vidioc_qbuf
= vidioc_qbuf
,
1673 .vidioc_dqbuf
= vidioc_dqbuf
,
1676 static struct video_device tm6000_template
= {
1678 .fops
= &tm6000_fops
,
1679 .ioctl_ops
= &video_ioctl_ops
,
1680 .release
= video_device_release
,
1681 .tvnorms
= TM6000_STD
,
1682 .current_norm
= V4L2_STD_NTSC_M
,
1685 static const struct v4l2_file_operations radio_fops
= {
1686 .owner
= THIS_MODULE
,
1687 .open
= tm6000_open
,
1688 .release
= tm6000_release
,
1689 .unlocked_ioctl
= video_ioctl2
,
1692 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
1693 .vidioc_querycap
= radio_querycap
,
1694 .vidioc_g_tuner
= radio_g_tuner
,
1695 .vidioc_enum_input
= radio_enum_input
,
1696 .vidioc_g_audio
= radio_g_audio
,
1697 .vidioc_s_tuner
= radio_s_tuner
,
1698 .vidioc_s_audio
= radio_s_audio
,
1699 .vidioc_s_input
= radio_s_input
,
1700 .vidioc_s_std
= radio_s_std
,
1701 .vidioc_queryctrl
= radio_queryctrl
,
1702 .vidioc_g_input
= radio_g_input
,
1703 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1704 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1705 .vidioc_g_frequency
= vidioc_g_frequency
,
1706 .vidioc_s_frequency
= vidioc_s_frequency
,
1709 static struct video_device tm6000_radio_template
= {
1711 .fops
= &radio_fops
,
1712 .ioctl_ops
= &radio_ioctl_ops
,
1715 /* -----------------------------------------------------------------
1716 * Initialization and module stuff
1717 * ------------------------------------------------------------------
1720 static struct video_device
*vdev_init(struct tm6000_core
*dev
,
1721 const struct video_device
1722 *template, const char *type_name
)
1724 struct video_device
*vfd
;
1726 vfd
= video_device_alloc();
1731 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1732 vfd
->release
= video_device_release
;
1733 vfd
->debug
= tm6000_debug
;
1734 vfd
->lock
= &dev
->lock
;
1736 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s", dev
->name
, type_name
);
1738 video_set_drvdata(vfd
, dev
);
1742 int tm6000_v4l2_register(struct tm6000_core
*dev
)
1746 dev
->vfd
= vdev_init(dev
, &tm6000_template
, "video");
1749 printk(KERN_INFO
"%s: can't register video device\n",
1754 /* init video dma queues */
1755 INIT_LIST_HEAD(&dev
->vidq
.active
);
1756 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1758 ret
= video_register_device(dev
->vfd
, VFL_TYPE_GRABBER
, video_nr
);
1761 printk(KERN_INFO
"%s: can't register video device\n",
1766 printk(KERN_INFO
"%s: registered device %s\n",
1767 dev
->name
, video_device_node_name(dev
->vfd
));
1769 if (dev
->caps
.has_radio
) {
1770 dev
->radio_dev
= vdev_init(dev
, &tm6000_radio_template
,
1772 if (!dev
->radio_dev
) {
1773 printk(KERN_INFO
"%s: can't register radio device\n",
1775 return ret
; /* FIXME release resource */
1778 ret
= video_register_device(dev
->radio_dev
, VFL_TYPE_RADIO
,
1781 printk(KERN_INFO
"%s: can't register radio device\n",
1783 return ret
; /* FIXME release resource */
1786 printk(KERN_INFO
"%s: registered device %s\n",
1787 dev
->name
, video_device_node_name(dev
->radio_dev
));
1790 printk(KERN_INFO
"Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret
);
1794 int tm6000_v4l2_unregister(struct tm6000_core
*dev
)
1796 video_unregister_device(dev
->vfd
);
1798 if (dev
->radio_dev
) {
1799 if (video_is_registered(dev
->radio_dev
))
1800 video_unregister_device(dev
->radio_dev
);
1802 video_device_release(dev
->radio_dev
);
1803 dev
->radio_dev
= NULL
;
1809 int tm6000_v4l2_exit(void)
1814 module_param(video_nr
, int, 0);
1815 MODULE_PARM_DESC(video_nr
, "Allow changing video device number");
1817 module_param_named(debug
, tm6000_debug
, int, 0444);
1818 MODULE_PARM_DESC(debug
, "activates debug info");
1820 module_param(vid_limit
, int, 0644);
1821 MODULE_PARM_DESC(vid_limit
, "capture memory limit in megabytes");