2 * tm6000-video.c - driver for TM5600/TM6000/TM6010 USB video capture devices
4 * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
6 * Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
7 * - Fixed module load/unload
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation version 2
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/errno.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/ioport.h>
30 #include <linux/init.h>
31 #include <linux/sched.h>
32 #include <linux/random.h>
33 #include <linux/version.h>
34 #include <linux/usb.h>
35 #include <linux/videodev2.h>
36 #include <media/v4l2-ioctl.h>
37 #include <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
);
186 /* Cleans up buffer - Useful for testing for frame/URB loss */
187 outp
= videobuf_to_vmalloc(&(*buf
)->vb
);
193 * Announces that a buffer were filled and request the next
195 static inline void buffer_filled(struct tm6000_core
*dev
,
196 struct tm6000_dmaqueue
*dma_q
,
197 struct tm6000_buffer
*buf
)
199 /* Advice that buffer was filled */
200 dprintk(dev
, V4L2_DEBUG_ISOC
, "[%p/%d] wakeup\n", buf
, buf
->vb
.i
);
201 buf
->vb
.state
= VIDEOBUF_DONE
;
202 buf
->vb
.field_count
++;
203 do_gettimeofday(&buf
->vb
.ts
);
205 list_del(&buf
->vb
.queue
);
206 wake_up(&buf
->vb
.done
);
209 const char *tm6000_msg_type
[] = {
210 "unknown(0)", /* 0 */
216 "unknown(6)", /* 6 */
217 "unknown(7)", /* 7 */
221 * Identify the tm5600/6000 buffer header type and properly handles
223 static int copy_streams(u8
*data
, unsigned long len
,
226 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
227 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
228 u8
*ptr
= data
, *endp
= data
+len
, c
;
229 unsigned long header
= 0;
231 unsigned int cmd
, cpysize
, pktsize
, size
, field
, block
, line
, pos
= 0;
232 struct tm6000_buffer
*vbuf
= NULL
;
234 unsigned int linewidth
;
237 /* get video buffer */
238 get_next_buf(dma_q
, &vbuf
);
242 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
248 for (ptr
= data
; ptr
< endp
;) {
249 if (!dev
->isoc_ctl
.cmd
) {
251 if (dev
->isoc_ctl
.tmp_buf_len
> 0) {
252 /* from last urb or packet */
253 header
= dev
->isoc_ctl
.tmp_buf
;
254 if (4 - dev
->isoc_ctl
.tmp_buf_len
> 0) {
255 memcpy((u8
*)&header
+
256 dev
->isoc_ctl
.tmp_buf_len
,
258 4 - dev
->isoc_ctl
.tmp_buf_len
);
259 ptr
+= 4 - dev
->isoc_ctl
.tmp_buf_len
;
261 dev
->isoc_ctl
.tmp_buf_len
= 0;
263 if (ptr
+ 3 >= endp
) {
264 /* have incomplete header */
265 dev
->isoc_ctl
.tmp_buf_len
= endp
- ptr
;
266 memcpy(&dev
->isoc_ctl
.tmp_buf
, ptr
,
267 dev
->isoc_ctl
.tmp_buf_len
);
271 for (; ptr
< endp
- 3; ptr
++) {
272 if (*(ptr
+ 3) == 0x47)
275 /* Get message header */
276 header
= *(unsigned long *)ptr
;
280 /* split the header fields */
281 c
= (header
>> 24) & 0xff;
282 size
= ((header
& 0x7e) << 1);
285 block
= (header
>> 7) & 0xf;
286 field
= (header
>> 11) & 0x1;
287 line
= (header
>> 12) & 0x1ff;
288 cmd
= (header
>> 21) & 0x7;
289 /* Validates haeder fields */
290 if (size
> TM6000_URB_MSG_LEN
)
291 size
= TM6000_URB_MSG_LEN
;
292 pktsize
= TM6000_URB_MSG_LEN
;
293 /* calculate position in buffer
294 * and change the buffer
297 case TM6000_URB_MSG_VIDEO
:
299 if ((dev
->isoc_ctl
.vfield
!= field
) &&
301 /* Announces that a new buffer
304 buffer_filled(dev
, dma_q
, vbuf
);
305 dprintk(dev
, V4L2_DEBUG_ISOC
,
306 "new buffer filled\n");
307 get_next_buf(dma_q
, &vbuf
);
310 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
313 memset(voutp
, 0, vbuf
->vb
.size
);
315 linewidth
= vbuf
->vb
.width
<< 1;
316 pos
= ((line
<< 1) - field
- 1) *
317 linewidth
+ block
* TM6000_URB_MSG_LEN
;
318 /* Don't allow to write out of the buffer */
319 if (pos
+ size
> vbuf
->vb
.size
)
320 cmd
= TM6000_URB_MSG_ERR
;
321 dev
->isoc_ctl
.vfield
= field
;
324 case TM6000_URB_MSG_VBI
:
326 case TM6000_URB_MSG_AUDIO
:
327 case TM6000_URB_MSG_PTS
:
328 size
= pktsize
; /* Size is always 180 bytes */
332 /* Continue the last copy */
333 cmd
= dev
->isoc_ctl
.cmd
;
334 size
= dev
->isoc_ctl
.size
;
335 pos
= dev
->isoc_ctl
.pos
;
336 pktsize
= dev
->isoc_ctl
.pktsize
;
337 field
= dev
->isoc_ctl
.field
;
339 cpysize
= (endp
- ptr
> size
) ? size
: endp
- ptr
;
341 /* copy data in different buffers */
343 case TM6000_URB_MSG_VIDEO
:
344 /* Fills video buffer */
346 memcpy(&voutp
[pos
], ptr
, cpysize
);
348 case TM6000_URB_MSG_AUDIO
: {
350 for (i
= 0; i
< cpysize
; i
+= 2)
351 swab16s((u16
*)(ptr
+ i
));
353 tm6000_call_fillbuf(dev
, TM6000_AUDIO
, ptr
, cpysize
);
356 case TM6000_URB_MSG_VBI
:
357 /* Need some code to copy vbi buffer */
359 case TM6000_URB_MSG_PTS
: {
360 /* Need some code to copy pts */
363 dprintk(dev
, V4L2_DEBUG_ISOC
, "field %d, PTS %x",
369 if (ptr
+ pktsize
> endp
) {
370 /* End of URB packet, but cmd processing is not
371 * complete. Preserve the state for a next packet
373 dev
->isoc_ctl
.pos
= pos
+ cpysize
;
374 dev
->isoc_ctl
.size
= size
- cpysize
;
375 dev
->isoc_ctl
.cmd
= cmd
;
376 dev
->isoc_ctl
.field
= field
;
377 dev
->isoc_ctl
.pktsize
= pktsize
- (endp
- ptr
);
380 dev
->isoc_ctl
.cmd
= 0;
388 * Identify the tm5600/6000 buffer header type and properly handles
390 static int copy_multiplexed(u8
*ptr
, unsigned long len
,
393 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
394 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
395 unsigned int pos
= dev
->isoc_ctl
.pos
, cpysize
;
397 struct tm6000_buffer
*buf
;
400 get_next_buf(dma_q
, &buf
);
402 outp
= videobuf_to_vmalloc(&buf
->vb
);
408 cpysize
= min(len
, buf
->vb
.size
-pos
);
409 memcpy(&outp
[pos
], ptr
, cpysize
);
413 if (pos
>= buf
->vb
.size
) {
415 /* Announces that a new buffer were filled */
416 buffer_filled(dev
, dma_q
, buf
);
417 dprintk(dev
, V4L2_DEBUG_ISOC
, "new buffer filled\n");
418 get_next_buf(dma_q
, &buf
);
421 outp
= videobuf_to_vmalloc(&(buf
->vb
));
428 dev
->isoc_ctl
.pos
= pos
;
432 static inline void print_err_status(struct tm6000_core
*dev
,
433 int packet
, int status
)
435 char *errmsg
= "Unknown";
439 errmsg
= "unlinked synchronuously";
442 errmsg
= "unlinked asynchronuously";
445 errmsg
= "Buffer error (overrun)";
448 errmsg
= "Stalled (device not responding)";
451 errmsg
= "Babble (bad cable?)";
454 errmsg
= "Bit-stuff error (bad cable?)";
457 errmsg
= "CRC/Timeout (could be anything)";
460 errmsg
= "Device does not respond";
464 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB status %d [%s].\n",
467 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB packet %d, status %d [%s].\n",
468 packet
, status
, errmsg
);
474 * Controls the isoc copy of each urb packet
476 static inline int tm6000_isoc_copy(struct urb
*urb
)
478 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
479 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
480 int i
, len
= 0, rc
= 1, status
;
483 if (urb
->status
< 0) {
484 print_err_status(dev
, -1, urb
->status
);
488 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
489 status
= urb
->iso_frame_desc
[i
].status
;
492 print_err_status(dev
, i
, status
);
496 len
= urb
->iso_frame_desc
[i
].actual_length
;
499 p
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
500 if (!urb
->iso_frame_desc
[i
].status
) {
501 if ((dev
->fourcc
) == V4L2_PIX_FMT_TM6000
) {
502 rc
= copy_multiplexed(p
, len
, urb
);
506 copy_streams(p
, len
, urb
);
514 /* ------------------------------------------------------------------
516 * ------------------------------------------------------------------
520 * IRQ callback, called by URB callback
522 static void tm6000_irq_callback(struct urb
*urb
)
524 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
525 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
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
;
757 int rc
= 0, urb_init
= 0;
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
);
786 if (!dev
->isoc_ctl
.num_bufs
)
790 rc
= tm6000_prepare_isoc(dev
);
794 rc
= tm6000_start_thread(dev
);
800 buf
->vb
.state
= VIDEOBUF_PREPARED
;
804 free_buffer(vq
, buf
);
809 buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
811 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
812 struct tm6000_fh
*fh
= vq
->priv_data
;
813 struct tm6000_core
*dev
= fh
->dev
;
814 struct tm6000_dmaqueue
*vidq
= &dev
->vidq
;
816 buf
->vb
.state
= VIDEOBUF_QUEUED
;
817 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
820 static void buffer_release(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
822 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
824 free_buffer(vq
, buf
);
827 static struct videobuf_queue_ops tm6000_video_qops
= {
828 .buf_setup
= buffer_setup
,
829 .buf_prepare
= buffer_prepare
,
830 .buf_queue
= buffer_queue
,
831 .buf_release
= buffer_release
,
834 /* ------------------------------------------------------------------
836 * ------------------------------------------------------------------
839 static bool is_res_read(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
841 /* Is the current fh handling it? if so, that's OK */
842 if (dev
->resources
== fh
&& dev
->is_res_read
)
848 static bool is_res_streaming(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
850 /* Is the current fh handling it? if so, that's OK */
851 if (dev
->resources
== fh
)
857 static bool res_get(struct tm6000_core
*dev
, struct tm6000_fh
*fh
,
860 /* Is the current fh handling it? if so, that's OK */
861 if (dev
->resources
== fh
&& dev
->is_res_read
== is_res_read
)
870 dev
->is_res_read
= is_res_read
;
871 dprintk(dev
, V4L2_DEBUG_RES_LOCK
, "res: get\n");
875 static void res_free(struct tm6000_core
*dev
, struct tm6000_fh
*fh
)
877 /* Is the current fh handling it? if so, that's OK */
878 if (dev
->resources
!= fh
)
881 dev
->resources
= NULL
;
882 dprintk(dev
, V4L2_DEBUG_RES_LOCK
, "res: put\n");
885 /* ------------------------------------------------------------------
886 * IOCTL vidioc handling
887 * ------------------------------------------------------------------
889 static int vidioc_querycap(struct file
*file
, void *priv
,
890 struct v4l2_capability
*cap
)
892 struct tm6000_core
*dev
= ((struct tm6000_fh
*)priv
)->dev
;
894 strlcpy(cap
->driver
, "tm6000", sizeof(cap
->driver
));
895 strlcpy(cap
->card
, "Trident TVMaster TM5600/6000/6010", sizeof(cap
->card
));
896 cap
->version
= TM6000_VERSION
;
897 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
|
902 if (dev
->tuner_type
!= TUNER_ABSENT
)
903 cap
->capabilities
|= V4L2_CAP_TUNER
;
908 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
909 struct v4l2_fmtdesc
*f
)
911 if (unlikely(f
->index
>= ARRAY_SIZE(format
)))
914 strlcpy(f
->description
, format
[f
->index
].name
, sizeof(f
->description
));
915 f
->pixelformat
= format
[f
->index
].fourcc
;
919 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
920 struct v4l2_format
*f
)
922 struct tm6000_fh
*fh
= priv
;
924 f
->fmt
.pix
.width
= fh
->width
;
925 f
->fmt
.pix
.height
= fh
->height
;
926 f
->fmt
.pix
.field
= fh
->vb_vidq
.field
;
927 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
928 f
->fmt
.pix
.bytesperline
=
929 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
930 f
->fmt
.pix
.sizeimage
=
931 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
936 static struct tm6000_fmt
*format_by_fourcc(unsigned int fourcc
)
940 for (i
= 0; i
< ARRAY_SIZE(format
); i
++)
941 if (format
[i
].fourcc
== fourcc
)
946 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
947 struct v4l2_format
*f
)
949 struct tm6000_core
*dev
= ((struct tm6000_fh
*)priv
)->dev
;
950 struct tm6000_fmt
*fmt
;
951 enum v4l2_field field
;
953 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
955 dprintk(dev
, V4L2_DEBUG_IOCTL_ARG
, "Fourcc format (0x%08x)"
956 " invalid.\n", f
->fmt
.pix
.pixelformat
);
960 field
= f
->fmt
.pix
.field
;
962 if (field
== V4L2_FIELD_ANY
)
963 field
= V4L2_FIELD_SEQ_TB
;
964 else if (V4L2_FIELD_INTERLACED
!= field
) {
965 dprintk(dev
, V4L2_DEBUG_IOCTL_ARG
, "Field type invalid.\n");
969 tm6000_get_std_res(dev
);
971 f
->fmt
.pix
.width
= dev
->width
;
972 f
->fmt
.pix
.height
= dev
->height
;
974 f
->fmt
.pix
.width
&= ~0x01;
976 f
->fmt
.pix
.field
= field
;
978 f
->fmt
.pix
.bytesperline
=
979 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
980 f
->fmt
.pix
.sizeimage
=
981 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
986 /*FIXME: This seems to be generic enough to be at videodev2 */
987 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
988 struct v4l2_format
*f
)
990 struct tm6000_fh
*fh
= priv
;
991 struct tm6000_core
*dev
= fh
->dev
;
992 int ret
= vidioc_try_fmt_vid_cap(file
, fh
, f
);
996 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
997 fh
->width
= f
->fmt
.pix
.width
;
998 fh
->height
= f
->fmt
.pix
.height
;
999 fh
->vb_vidq
.field
= f
->fmt
.pix
.field
;
1002 dev
->fourcc
= f
->fmt
.pix
.pixelformat
;
1004 tm6000_set_fourcc_format(dev
);
1009 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1010 struct v4l2_requestbuffers
*p
)
1012 struct tm6000_fh
*fh
= priv
;
1014 return videobuf_reqbufs(&fh
->vb_vidq
, p
);
1017 static int vidioc_querybuf(struct file
*file
, void *priv
,
1018 struct v4l2_buffer
*p
)
1020 struct tm6000_fh
*fh
= priv
;
1022 return videobuf_querybuf(&fh
->vb_vidq
, p
);
1025 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1027 struct tm6000_fh
*fh
= priv
;
1029 return videobuf_qbuf(&fh
->vb_vidq
, p
);
1032 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
1034 struct tm6000_fh
*fh
= priv
;
1036 return videobuf_dqbuf(&fh
->vb_vidq
, p
,
1037 file
->f_flags
& O_NONBLOCK
);
1040 static int vidioc_streamon(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1042 struct tm6000_fh
*fh
= priv
;
1043 struct tm6000_core
*dev
= fh
->dev
;
1045 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1050 if (!res_get(dev
, fh
, false))
1052 return videobuf_streamon(&fh
->vb_vidq
);
1055 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
1057 struct tm6000_fh
*fh
= priv
;
1058 struct tm6000_core
*dev
= fh
->dev
;
1060 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1065 videobuf_streamoff(&fh
->vb_vidq
);
1071 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*norm
)
1074 struct tm6000_fh
*fh
= priv
;
1075 struct tm6000_core
*dev
= fh
->dev
;
1078 rc
= tm6000_init_analog_mode(dev
);
1080 fh
->width
= dev
->width
;
1081 fh
->height
= dev
->height
;
1086 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
1091 static const char *iname
[] = {
1092 [TM6000_INPUT_TV
] = "Television",
1093 [TM6000_INPUT_COMPOSITE1
] = "Composite 1",
1094 [TM6000_INPUT_COMPOSITE2
] = "Composite 2",
1095 [TM6000_INPUT_SVIDEO
] = "S-Video",
1098 static int vidioc_enum_input(struct file
*file
, void *priv
,
1099 struct v4l2_input
*i
)
1101 struct tm6000_fh
*fh
= priv
;
1102 struct tm6000_core
*dev
= fh
->dev
;
1109 if (!dev
->vinput
[n
].type
)
1114 if (dev
->vinput
[n
].type
== TM6000_INPUT_TV
)
1115 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1117 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1119 strcpy(i
->name
, iname
[dev
->vinput
[n
].type
]);
1121 i
->std
= TM6000_STD
;
1126 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1128 struct tm6000_fh
*fh
= priv
;
1129 struct tm6000_core
*dev
= fh
->dev
;
1136 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1138 struct tm6000_fh
*fh
= priv
;
1139 struct tm6000_core
*dev
= fh
->dev
;
1144 if (!dev
->vinput
[i
].type
)
1149 rc
= vidioc_s_std(file
, priv
, &dev
->vfd
->current_norm
);
1154 /* --- controls ---------------------------------------------- */
1155 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1156 struct v4l2_queryctrl
*qc
)
1160 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1161 if (qc
->id
&& qc
->id
== tm6000_qctrl
[i
].id
) {
1162 memcpy(qc
, &(tm6000_qctrl
[i
]),
1170 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1171 struct v4l2_control
*ctrl
)
1173 struct tm6000_fh
*fh
= priv
;
1174 struct tm6000_core
*dev
= fh
->dev
;
1177 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1179 case V4L2_CID_CONTRAST
:
1180 val
= tm6000_get_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, 0);
1182 case V4L2_CID_BRIGHTNESS
:
1183 val
= tm6000_get_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, 0);
1185 case V4L2_CID_SATURATION
:
1186 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, 0);
1189 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, 0);
1191 case V4L2_CID_AUDIO_MUTE
:
1192 val
= dev
->ctl_mute
;
1194 case V4L2_CID_AUDIO_VOLUME
:
1195 val
= dev
->ctl_volume
;
1208 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1209 struct v4l2_control
*ctrl
)
1211 struct tm6000_fh
*fh
= priv
;
1212 struct tm6000_core
*dev
= fh
->dev
;
1213 u8 val
= ctrl
->value
;
1216 case V4L2_CID_CONTRAST
:
1217 tm6000_set_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, val
);
1219 case V4L2_CID_BRIGHTNESS
:
1220 tm6000_set_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, val
);
1222 case V4L2_CID_SATURATION
:
1223 tm6000_set_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, val
);
1226 tm6000_set_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, val
);
1228 case V4L2_CID_AUDIO_MUTE
:
1229 dev
->ctl_mute
= val
;
1230 tm6000_tvaudio_set_mute(dev
, val
);
1232 case V4L2_CID_AUDIO_VOLUME
:
1233 dev
->ctl_volume
= val
;
1234 tm6000_set_volume(dev
, val
);
1240 static int vidioc_g_tuner(struct file
*file
, void *priv
,
1241 struct v4l2_tuner
*t
)
1243 struct tm6000_fh
*fh
= priv
;
1244 struct tm6000_core
*dev
= fh
->dev
;
1246 if (unlikely(UNSET
== dev
->tuner_type
))
1251 strcpy(t
->name
, "Television");
1252 t
->type
= V4L2_TUNER_ANALOG_TV
;
1253 t
->capability
= V4L2_TUNER_CAP_NORM
;
1254 t
->rangehigh
= 0xffffffffUL
;
1255 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1257 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1259 t
->audmode
= dev
->amode
;
1264 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1265 struct v4l2_tuner
*t
)
1267 struct tm6000_fh
*fh
= priv
;
1268 struct tm6000_core
*dev
= fh
->dev
;
1270 if (UNSET
== dev
->tuner_type
)
1275 dev
->amode
= t
->audmode
;
1276 dprintk(dev
, 3, "audio mode: %x\n", t
->audmode
);
1278 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1283 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1284 struct v4l2_frequency
*f
)
1286 struct tm6000_fh
*fh
= priv
;
1287 struct tm6000_core
*dev
= fh
->dev
;
1289 if (unlikely(UNSET
== dev
->tuner_type
))
1292 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1293 f
->frequency
= dev
->freq
;
1295 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_frequency
, f
);
1300 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1301 struct v4l2_frequency
*f
)
1303 struct tm6000_fh
*fh
= priv
;
1304 struct tm6000_core
*dev
= fh
->dev
;
1306 if (unlikely(UNSET
== dev
->tuner_type
))
1308 if (unlikely(f
->tuner
!= 0))
1310 if (0 == fh
->radio
&& V4L2_TUNER_ANALOG_TV
!= f
->type
)
1312 if (1 == fh
->radio
&& V4L2_TUNER_RADIO
!= f
->type
)
1315 dev
->freq
= f
->frequency
;
1316 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, f
);
1321 static int radio_querycap(struct file
*file
, void *priv
,
1322 struct v4l2_capability
*cap
)
1324 struct tm6000_fh
*fh
= file
->private_data
;
1325 struct tm6000_core
*dev
= fh
->dev
;
1327 strcpy(cap
->driver
, "tm6000");
1328 strlcpy(cap
->card
, dev
->name
, sizeof(dev
->name
));
1329 sprintf(cap
->bus_info
, "USB%04x:%04x",
1330 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
1331 le16_to_cpu(dev
->udev
->descriptor
.idProduct
));
1332 cap
->version
= dev
->dev_type
;
1333 cap
->capabilities
= V4L2_CAP_TUNER
|
1336 V4L2_CAP_READWRITE
|
1342 static int radio_g_tuner(struct file
*file
, void *priv
,
1343 struct v4l2_tuner
*t
)
1345 struct tm6000_fh
*fh
= file
->private_data
;
1346 struct tm6000_core
*dev
= fh
->dev
;
1351 memset(t
, 0, sizeof(*t
));
1352 strcpy(t
->name
, "Radio");
1353 t
->type
= V4L2_TUNER_RADIO
;
1354 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1356 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1361 static int radio_s_tuner(struct file
*file
, void *priv
,
1362 struct v4l2_tuner
*t
)
1364 struct tm6000_fh
*fh
= file
->private_data
;
1365 struct tm6000_core
*dev
= fh
->dev
;
1370 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1375 static int radio_enum_input(struct file
*file
, void *priv
,
1376 struct v4l2_input
*i
)
1378 struct tm6000_fh
*fh
= priv
;
1379 struct tm6000_core
*dev
= fh
->dev
;
1384 if (!dev
->rinput
.type
)
1387 strcpy(i
->name
, "Radio");
1388 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1393 static int radio_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
1395 struct tm6000_fh
*fh
= priv
;
1396 struct tm6000_core
*dev
= fh
->dev
;
1398 if (dev
->input
!= 5)
1401 *i
= dev
->input
- 5;
1406 static int radio_g_audio(struct file
*file
, void *priv
,
1407 struct v4l2_audio
*a
)
1409 memset(a
, 0, sizeof(*a
));
1410 strcpy(a
->name
, "Radio");
1414 static int radio_s_audio(struct file
*file
, void *priv
,
1415 struct v4l2_audio
*a
)
1420 static int radio_s_input(struct file
*filp
, void *priv
, unsigned int i
)
1422 struct tm6000_fh
*fh
= priv
;
1423 struct tm6000_core
*dev
= fh
->dev
;
1428 if (!dev
->rinput
.type
)
1436 static int radio_s_std(struct file
*file
, void *fh
, v4l2_std_id
*norm
)
1441 static int radio_queryctrl(struct file
*file
, void *priv
,
1442 struct v4l2_queryctrl
*c
)
1444 const struct v4l2_queryctrl
*ctrl
;
1446 if (c
->id
< V4L2_CID_BASE
||
1447 c
->id
>= V4L2_CID_LASTP1
)
1449 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
1450 ctrl
= ctrl_by_id(c
->id
);
1458 /* ------------------------------------------------------------------
1459 File operations for the device
1460 ------------------------------------------------------------------*/
1462 static int tm6000_open(struct file
*file
)
1464 struct video_device
*vdev
= video_devdata(file
);
1465 struct tm6000_core
*dev
= video_drvdata(file
);
1466 struct tm6000_fh
*fh
;
1467 enum v4l2_buf_type type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1471 printk(KERN_INFO
"tm6000: open called (dev=%s)\n",
1472 video_device_node_name(vdev
));
1474 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: open called (dev=%s)\n",
1475 video_device_node_name(vdev
));
1477 switch (vdev
->vfl_type
) {
1478 case VFL_TYPE_GRABBER
:
1479 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1482 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1484 case VFL_TYPE_RADIO
:
1489 /* If more than one user, mutex should be added */
1492 dprintk(dev
, V4L2_DEBUG_OPEN
, "open dev=%s type=%s users=%d\n",
1493 video_device_node_name(vdev
), v4l2_type_names
[type
],
1496 /* allocate + initialize per filehandle data */
1497 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1503 file
->private_data
= fh
;
1508 dev
->fourcc
= format
[0].fourcc
;
1510 fh
->fmt
= format_by_fourcc(dev
->fourcc
);
1512 tm6000_get_std_res(dev
);
1514 fh
->width
= dev
->width
;
1515 fh
->height
= dev
->height
;
1517 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: fh=0x%08lx, dev=0x%08lx, "
1518 "dev->vidq=0x%08lx\n",
1519 (unsigned long)fh
, (unsigned long)dev
, (unsigned long)&dev
->vidq
);
1520 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1521 "queued=%d\n", list_empty(&dev
->vidq
.queued
));
1522 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1523 "active=%d\n", list_empty(&dev
->vidq
.active
));
1525 /* initialize hardware on analog mode */
1526 rc
= tm6000_init_analog_mode(dev
);
1530 if (dev
->mode
!= TM6000_MODE_ANALOG
) {
1531 /* Put all controls at a sane state */
1532 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1533 qctl_regs
[i
] = tm6000_qctrl
[i
].default_value
;
1535 dev
->mode
= TM6000_MODE_ANALOG
;
1538 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &tm6000_video_qops
,
1541 V4L2_FIELD_INTERLACED
,
1542 sizeof(struct tm6000_buffer
), fh
, &dev
->lock
);
1545 dprintk(dev
, V4L2_DEBUG_OPEN
, "video_open: setting radio device\n");
1547 tm6000_set_audio_rinput(dev
);
1548 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_radio
);
1549 tm6000_prepare_isoc(dev
);
1550 tm6000_start_thread(dev
);
1557 tm6000_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*pos
)
1559 struct tm6000_fh
*fh
= file
->private_data
;
1561 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1562 if (!res_get(fh
->dev
, fh
, true))
1565 return videobuf_read_stream(&fh
->vb_vidq
, data
, count
, pos
, 0,
1566 file
->f_flags
& O_NONBLOCK
);
1572 tm6000_poll(struct file
*file
, struct poll_table_struct
*wait
)
1574 struct tm6000_fh
*fh
= file
->private_data
;
1575 struct tm6000_buffer
*buf
;
1577 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= fh
->type
)
1580 if (!!is_res_streaming(fh
->dev
, fh
))
1583 if (!is_res_read(fh
->dev
, fh
)) {
1584 /* streaming capture */
1585 if (list_empty(&fh
->vb_vidq
.stream
))
1587 buf
= list_entry(fh
->vb_vidq
.stream
.next
, struct tm6000_buffer
, vb
.stream
);
1589 /* read() capture */
1590 return videobuf_poll_stream(file
, &fh
->vb_vidq
,
1593 poll_wait(file
, &buf
->vb
.done
, wait
);
1594 if (buf
->vb
.state
== VIDEOBUF_DONE
||
1595 buf
->vb
.state
== VIDEOBUF_ERROR
)
1596 return POLLIN
| POLLRDNORM
;
1600 static int tm6000_release(struct file
*file
)
1602 struct tm6000_fh
*fh
= file
->private_data
;
1603 struct tm6000_core
*dev
= fh
->dev
;
1604 struct video_device
*vdev
= video_devdata(file
);
1606 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: close called (dev=%s, users=%d)\n",
1607 video_device_node_name(vdev
), dev
->users
);
1613 tm6000_uninit_isoc(dev
);
1614 videobuf_mmap_free(&fh
->vb_vidq
);
1622 static int tm6000_mmap(struct file
*file
, struct vm_area_struct
* vma
)
1624 struct tm6000_fh
*fh
= file
->private_data
;
1627 ret
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
1632 static struct v4l2_file_operations tm6000_fops
= {
1633 .owner
= THIS_MODULE
,
1634 .open
= tm6000_open
,
1635 .release
= tm6000_release
,
1636 .unlocked_ioctl
= video_ioctl2
, /* V4L2 ioctl handler */
1637 .read
= tm6000_read
,
1638 .poll
= tm6000_poll
,
1639 .mmap
= tm6000_mmap
,
1642 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1643 .vidioc_querycap
= vidioc_querycap
,
1644 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1645 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1646 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1647 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1648 .vidioc_s_std
= vidioc_s_std
,
1649 .vidioc_enum_input
= vidioc_enum_input
,
1650 .vidioc_g_input
= vidioc_g_input
,
1651 .vidioc_s_input
= vidioc_s_input
,
1652 .vidioc_queryctrl
= vidioc_queryctrl
,
1653 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1654 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1655 .vidioc_g_tuner
= vidioc_g_tuner
,
1656 .vidioc_s_tuner
= vidioc_s_tuner
,
1657 .vidioc_g_frequency
= vidioc_g_frequency
,
1658 .vidioc_s_frequency
= vidioc_s_frequency
,
1659 .vidioc_streamon
= vidioc_streamon
,
1660 .vidioc_streamoff
= vidioc_streamoff
,
1661 .vidioc_reqbufs
= vidioc_reqbufs
,
1662 .vidioc_querybuf
= vidioc_querybuf
,
1663 .vidioc_qbuf
= vidioc_qbuf
,
1664 .vidioc_dqbuf
= vidioc_dqbuf
,
1667 static struct video_device tm6000_template
= {
1669 .fops
= &tm6000_fops
,
1670 .ioctl_ops
= &video_ioctl_ops
,
1671 .release
= video_device_release
,
1672 .tvnorms
= TM6000_STD
,
1673 .current_norm
= V4L2_STD_NTSC_M
,
1676 static const struct v4l2_file_operations radio_fops
= {
1677 .owner
= THIS_MODULE
,
1678 .open
= tm6000_open
,
1679 .release
= tm6000_release
,
1680 .unlocked_ioctl
= video_ioctl2
,
1683 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
1684 .vidioc_querycap
= radio_querycap
,
1685 .vidioc_g_tuner
= radio_g_tuner
,
1686 .vidioc_enum_input
= radio_enum_input
,
1687 .vidioc_g_audio
= radio_g_audio
,
1688 .vidioc_s_tuner
= radio_s_tuner
,
1689 .vidioc_s_audio
= radio_s_audio
,
1690 .vidioc_s_input
= radio_s_input
,
1691 .vidioc_s_std
= radio_s_std
,
1692 .vidioc_queryctrl
= radio_queryctrl
,
1693 .vidioc_g_input
= radio_g_input
,
1694 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1695 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1696 .vidioc_g_frequency
= vidioc_g_frequency
,
1697 .vidioc_s_frequency
= vidioc_s_frequency
,
1700 struct video_device tm6000_radio_template
= {
1702 .fops
= &radio_fops
,
1703 .ioctl_ops
= &radio_ioctl_ops
,
1706 /* -----------------------------------------------------------------
1707 * Initialization and module stuff
1708 * ------------------------------------------------------------------
1711 static struct video_device
*vdev_init(struct tm6000_core
*dev
,
1712 const struct video_device
1713 *template, const char *type_name
)
1715 struct video_device
*vfd
;
1717 vfd
= video_device_alloc();
1722 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1723 vfd
->release
= video_device_release
;
1724 vfd
->debug
= tm6000_debug
;
1725 vfd
->lock
= &dev
->lock
;
1727 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s", dev
->name
, type_name
);
1729 video_set_drvdata(vfd
, dev
);
1733 int tm6000_v4l2_register(struct tm6000_core
*dev
)
1737 dev
->vfd
= vdev_init(dev
, &tm6000_template
, "video");
1740 printk(KERN_INFO
"%s: can't register video device\n",
1745 /* init video dma queues */
1746 INIT_LIST_HEAD(&dev
->vidq
.active
);
1747 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1749 ret
= video_register_device(dev
->vfd
, VFL_TYPE_GRABBER
, video_nr
);
1752 printk(KERN_INFO
"%s: can't register video device\n",
1757 printk(KERN_INFO
"%s: registered device %s\n",
1758 dev
->name
, video_device_node_name(dev
->vfd
));
1760 if (dev
->caps
.has_radio
) {
1761 dev
->radio_dev
= vdev_init(dev
, &tm6000_radio_template
,
1763 if (!dev
->radio_dev
) {
1764 printk(KERN_INFO
"%s: can't register radio device\n",
1766 return ret
; /* FIXME release resource */
1769 ret
= video_register_device(dev
->radio_dev
, VFL_TYPE_RADIO
,
1772 printk(KERN_INFO
"%s: can't register radio device\n",
1774 return ret
; /* FIXME release resource */
1777 printk(KERN_INFO
"%s: registered device %s\n",
1778 dev
->name
, video_device_node_name(dev
->radio_dev
));
1781 printk(KERN_INFO
"Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret
);
1785 int tm6000_v4l2_unregister(struct tm6000_core
*dev
)
1787 video_unregister_device(dev
->vfd
);
1789 if (dev
->radio_dev
) {
1790 if (video_is_registered(dev
->radio_dev
))
1791 video_unregister_device(dev
->radio_dev
);
1793 video_device_release(dev
->radio_dev
);
1794 dev
->radio_dev
= NULL
;
1800 int tm6000_v4l2_exit(void)
1805 module_param(video_nr
, int, 0);
1806 MODULE_PARM_DESC(video_nr
, "Allow changing video device number");
1808 module_param_named(debug
, tm6000_debug
, int, 0444);
1809 MODULE_PARM_DESC(debug
, "activates debug info");
1811 module_param(vid_limit
, int, 0644);
1812 MODULE_PARM_DESC(vid_limit
, "capture memory limit in megabytes");