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/usb.h>
34 #include <linux/videodev2.h>
35 #include <media/v4l2-ioctl.h>
36 #include <media/tuner.h>
37 #include <linux/interrupt.h>
38 #include <linux/kthread.h>
39 #include <linux/highmem.h>
40 #include <linux/freezer.h>
42 #include "tm6000-regs.h"
45 #define BUFFER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */
47 /* Limits minimum and default number of buffers */
48 #define TM6000_MIN_BUF 4
49 #define TM6000_DEF_BUF 8
51 #define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
53 /* Declare static vars that will be used as parameters */
54 static unsigned int vid_limit
= 16; /* Video memory limit, in Mb */
55 static int video_nr
= -1; /* /dev/videoN, -1 for autodetect */
56 static int radio_nr
= -1; /* /dev/radioN, -1 for autodetect */
60 EXPORT_SYMBOL_GPL(tm6000_debug
);
62 static const struct v4l2_queryctrl no_ctrl
= {
64 .flags
= V4L2_CTRL_FLAG_DISABLED
,
67 /* supported controls */
68 static struct v4l2_queryctrl tm6000_qctrl
[] = {
70 .id
= V4L2_CID_BRIGHTNESS
,
71 .type
= V4L2_CTRL_TYPE_INTEGER
,
79 .id
= V4L2_CID_CONTRAST
,
80 .type
= V4L2_CTRL_TYPE_INTEGER
,
88 .id
= V4L2_CID_SATURATION
,
89 .type
= V4L2_CTRL_TYPE_INTEGER
,
98 .type
= V4L2_CTRL_TYPE_INTEGER
,
108 .id
= V4L2_CID_AUDIO_MUTE
,
112 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
114 .id
= V4L2_CID_AUDIO_VOLUME
,
120 .type
= V4L2_CTRL_TYPE_INTEGER
,
124 static const unsigned int CTRLS
= ARRAY_SIZE(tm6000_qctrl
);
125 static int qctl_regs
[ARRAY_SIZE(tm6000_qctrl
)];
127 static struct tm6000_fmt format
[] = {
129 .name
= "4:2:2, packed, YVY2",
130 .fourcc
= V4L2_PIX_FMT_YUYV
,
133 .name
= "4:2:2, packed, UYVY",
134 .fourcc
= V4L2_PIX_FMT_UYVY
,
137 .name
= "A/V + VBI mux packet",
138 .fourcc
= V4L2_PIX_FMT_TM6000
,
143 static const struct v4l2_queryctrl
*ctrl_by_id(unsigned int id
)
147 for (i
= 0; i
< CTRLS
; i
++)
148 if (tm6000_qctrl
[i
].id
== id
)
149 return tm6000_qctrl
+i
;
153 /* ------------------------------------------------------------------
154 * DMA and thread functions
155 * ------------------------------------------------------------------
158 #define norm_maxw(a) 720
159 #define norm_maxh(a) 576
161 #define norm_minw(a) norm_maxw(a)
162 #define norm_minh(a) norm_maxh(a)
165 * video-buf generic routine to get the next available buffer
167 static inline void get_next_buf(struct tm6000_dmaqueue
*dma_q
,
168 struct tm6000_buffer
**buf
)
170 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
173 if (list_empty(&dma_q
->active
)) {
174 dprintk(dev
, V4L2_DEBUG_QUEUE
, "No active queue to serve\n");
179 *buf
= list_entry(dma_q
->active
.next
,
180 struct tm6000_buffer
, vb
.queue
);
182 /* Cleans up buffer - Useful for testing for frame/URB loss */
183 outp
= videobuf_to_vmalloc(&(*buf
)->vb
);
189 * Announces that a buffer were filled and request the next
191 static inline void buffer_filled(struct tm6000_core
*dev
,
192 struct tm6000_dmaqueue
*dma_q
,
193 struct tm6000_buffer
*buf
)
195 /* Advice that buffer was filled */
196 dprintk(dev
, V4L2_DEBUG_ISOC
, "[%p/%d] wakeup\n", buf
, buf
->vb
.i
);
197 buf
->vb
.state
= VIDEOBUF_DONE
;
198 buf
->vb
.field_count
++;
199 do_gettimeofday(&buf
->vb
.ts
);
201 list_del(&buf
->vb
.queue
);
202 wake_up(&buf
->vb
.done
);
205 const char *tm6000_msg_type
[] = {
206 "unknown(0)", /* 0 */
212 "unknown(6)", /* 6 */
213 "unknown(7)", /* 7 */
217 * Identify the tm5600/6000 buffer header type and properly handles
219 static int copy_streams(u8
*data
, unsigned long len
,
222 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
223 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
224 u8
*ptr
= data
, *endp
= data
+len
, c
;
225 unsigned long header
= 0;
227 unsigned int cmd
, cpysize
, pktsize
, size
, field
, block
, line
, pos
= 0;
228 struct tm6000_buffer
*vbuf
= NULL
;
230 unsigned int linewidth
;
233 /* get video buffer */
234 get_next_buf(dma_q
, &vbuf
);
238 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
244 for (ptr
= data
; ptr
< endp
;) {
245 if (!dev
->isoc_ctl
.cmd
) {
247 if (dev
->isoc_ctl
.tmp_buf_len
> 0) {
248 /* from last urb or packet */
249 header
= dev
->isoc_ctl
.tmp_buf
;
250 if (4 - dev
->isoc_ctl
.tmp_buf_len
> 0) {
251 memcpy((u8
*)&header
+
252 dev
->isoc_ctl
.tmp_buf_len
,
254 4 - dev
->isoc_ctl
.tmp_buf_len
);
255 ptr
+= 4 - dev
->isoc_ctl
.tmp_buf_len
;
257 dev
->isoc_ctl
.tmp_buf_len
= 0;
259 if (ptr
+ 3 >= endp
) {
260 /* have incomplete header */
261 dev
->isoc_ctl
.tmp_buf_len
= endp
- ptr
;
262 memcpy(&dev
->isoc_ctl
.tmp_buf
, ptr
,
263 dev
->isoc_ctl
.tmp_buf_len
);
267 for (; ptr
< endp
- 3; ptr
++) {
268 if (*(ptr
+ 3) == 0x47)
271 /* Get message header */
272 header
= *(unsigned long *)ptr
;
276 /* split the header fields */
277 c
= (header
>> 24) & 0xff;
278 size
= ((header
& 0x7e) << 1);
281 block
= (header
>> 7) & 0xf;
282 field
= (header
>> 11) & 0x1;
283 line
= (header
>> 12) & 0x1ff;
284 cmd
= (header
>> 21) & 0x7;
285 /* Validates haeder fields */
286 if (size
> TM6000_URB_MSG_LEN
)
287 size
= TM6000_URB_MSG_LEN
;
288 pktsize
= TM6000_URB_MSG_LEN
;
289 /* calculate position in buffer
290 * and change the buffer
293 case TM6000_URB_MSG_VIDEO
:
295 if ((dev
->isoc_ctl
.vfield
!= field
) &&
297 /* Announces that a new buffer
300 buffer_filled(dev
, dma_q
, vbuf
);
301 dprintk(dev
, V4L2_DEBUG_ISOC
,
302 "new buffer filled\n");
303 get_next_buf(dma_q
, &vbuf
);
306 voutp
= videobuf_to_vmalloc(&vbuf
->vb
);
309 memset(voutp
, 0, vbuf
->vb
.size
);
311 linewidth
= vbuf
->vb
.width
<< 1;
312 pos
= ((line
<< 1) - field
- 1) *
313 linewidth
+ block
* TM6000_URB_MSG_LEN
;
314 /* Don't allow to write out of the buffer */
315 if (pos
+ size
> vbuf
->vb
.size
)
316 cmd
= TM6000_URB_MSG_ERR
;
317 dev
->isoc_ctl
.vfield
= field
;
320 case TM6000_URB_MSG_VBI
:
322 case TM6000_URB_MSG_AUDIO
:
323 case TM6000_URB_MSG_PTS
:
324 size
= pktsize
; /* Size is always 180 bytes */
328 /* Continue the last copy */
329 cmd
= dev
->isoc_ctl
.cmd
;
330 size
= dev
->isoc_ctl
.size
;
331 pos
= dev
->isoc_ctl
.pos
;
332 pktsize
= dev
->isoc_ctl
.pktsize
;
333 field
= dev
->isoc_ctl
.field
;
335 cpysize
= (endp
- ptr
> size
) ? size
: endp
- ptr
;
337 /* copy data in different buffers */
339 case TM6000_URB_MSG_VIDEO
:
340 /* Fills video buffer */
342 memcpy(&voutp
[pos
], ptr
, cpysize
);
344 case TM6000_URB_MSG_AUDIO
: {
346 for (i
= 0; i
< cpysize
; i
+= 2)
347 swab16s((u16
*)(ptr
+ i
));
349 tm6000_call_fillbuf(dev
, TM6000_AUDIO
, ptr
, cpysize
);
352 case TM6000_URB_MSG_VBI
:
353 /* Need some code to copy vbi buffer */
355 case TM6000_URB_MSG_PTS
: {
356 /* Need some code to copy pts */
359 dprintk(dev
, V4L2_DEBUG_ISOC
, "field %d, PTS %x",
365 if (ptr
+ pktsize
> endp
) {
366 /* End of URB packet, but cmd processing is not
367 * complete. Preserve the state for a next packet
369 dev
->isoc_ctl
.pos
= pos
+ cpysize
;
370 dev
->isoc_ctl
.size
= size
- cpysize
;
371 dev
->isoc_ctl
.cmd
= cmd
;
372 dev
->isoc_ctl
.field
= field
;
373 dev
->isoc_ctl
.pktsize
= pktsize
- (endp
- ptr
);
376 dev
->isoc_ctl
.cmd
= 0;
384 * Identify the tm5600/6000 buffer header type and properly handles
386 static int copy_multiplexed(u8
*ptr
, unsigned long len
,
389 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
390 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
391 unsigned int pos
= dev
->isoc_ctl
.pos
, cpysize
;
393 struct tm6000_buffer
*buf
;
396 get_next_buf(dma_q
, &buf
);
398 outp
= videobuf_to_vmalloc(&buf
->vb
);
404 cpysize
= min(len
, buf
->vb
.size
-pos
);
405 memcpy(&outp
[pos
], ptr
, cpysize
);
409 if (pos
>= buf
->vb
.size
) {
411 /* Announces that a new buffer were filled */
412 buffer_filled(dev
, dma_q
, buf
);
413 dprintk(dev
, V4L2_DEBUG_ISOC
, "new buffer filled\n");
414 get_next_buf(dma_q
, &buf
);
417 outp
= videobuf_to_vmalloc(&(buf
->vb
));
424 dev
->isoc_ctl
.pos
= pos
;
428 static inline void print_err_status(struct tm6000_core
*dev
,
429 int packet
, int status
)
431 char *errmsg
= "Unknown";
435 errmsg
= "unlinked synchronuously";
438 errmsg
= "unlinked asynchronuously";
441 errmsg
= "Buffer error (overrun)";
444 errmsg
= "Stalled (device not responding)";
447 errmsg
= "Babble (bad cable?)";
450 errmsg
= "Bit-stuff error (bad cable?)";
453 errmsg
= "CRC/Timeout (could be anything)";
456 errmsg
= "Device does not respond";
460 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB status %d [%s].\n",
463 dprintk(dev
, V4L2_DEBUG_QUEUE
, "URB packet %d, status %d [%s].\n",
464 packet
, status
, errmsg
);
470 * Controls the isoc copy of each urb packet
472 static inline int tm6000_isoc_copy(struct urb
*urb
)
474 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
475 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
476 int i
, len
= 0, rc
= 1, status
;
479 if (urb
->status
< 0) {
480 print_err_status(dev
, -1, urb
->status
);
484 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
485 status
= urb
->iso_frame_desc
[i
].status
;
488 print_err_status(dev
, i
, status
);
492 len
= urb
->iso_frame_desc
[i
].actual_length
;
495 p
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
496 if (!urb
->iso_frame_desc
[i
].status
) {
497 if ((dev
->fourcc
) == V4L2_PIX_FMT_TM6000
) {
498 rc
= copy_multiplexed(p
, len
, urb
);
502 copy_streams(p
, len
, urb
);
510 /* ------------------------------------------------------------------
512 * ------------------------------------------------------------------
516 * IRQ callback, called by URB callback
518 static void tm6000_irq_callback(struct urb
*urb
)
520 struct tm6000_dmaqueue
*dma_q
= urb
->context
;
521 struct tm6000_core
*dev
= container_of(dma_q
, struct tm6000_core
, vidq
);
527 spin_lock(&dev
->slock
);
528 tm6000_isoc_copy(urb
);
529 spin_unlock(&dev
->slock
);
531 /* Reset urb buffers */
532 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
533 urb
->iso_frame_desc
[i
].status
= 0;
534 urb
->iso_frame_desc
[i
].actual_length
= 0;
537 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
539 tm6000_err("urb resubmit failed (error=%i)\n",
544 * Stop and Deallocate URBs
546 static void tm6000_uninit_isoc(struct tm6000_core
*dev
)
551 dev
->isoc_ctl
.buf
= NULL
;
552 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
553 urb
= dev
->isoc_ctl
.urb
[i
];
557 if (dev
->isoc_ctl
.transfer_buffer
[i
]) {
558 usb_free_coherent(dev
->udev
,
559 urb
->transfer_buffer_length
,
560 dev
->isoc_ctl
.transfer_buffer
[i
],
564 dev
->isoc_ctl
.urb
[i
] = NULL
;
566 dev
->isoc_ctl
.transfer_buffer
[i
] = NULL
;
569 kfree(dev
->isoc_ctl
.urb
);
570 kfree(dev
->isoc_ctl
.transfer_buffer
);
572 dev
->isoc_ctl
.urb
= NULL
;
573 dev
->isoc_ctl
.transfer_buffer
= NULL
;
574 dev
->isoc_ctl
.num_bufs
= 0;
578 * Allocate URBs and start IRQ
580 static int tm6000_prepare_isoc(struct tm6000_core
*dev
)
582 struct tm6000_dmaqueue
*dma_q
= &dev
->vidq
;
583 int i
, j
, sb_size
, pipe
, size
, max_packets
, num_bufs
= 8;
586 /* De-allocates all pending stuff */
587 tm6000_uninit_isoc(dev
);
588 /* Stop interrupt USB pipe */
589 tm6000_ir_int_stop(dev
);
591 usb_set_interface(dev
->udev
,
592 dev
->isoc_in
.bInterfaceNumber
,
593 dev
->isoc_in
.bAlternateSetting
);
595 /* Start interrupt USB pipe */
596 tm6000_ir_int_start(dev
);
598 pipe
= usb_rcvisocpipe(dev
->udev
,
599 dev
->isoc_in
.endp
->desc
.bEndpointAddress
&
600 USB_ENDPOINT_NUMBER_MASK
);
602 size
= usb_maxpacket(dev
->udev
, pipe
, usb_pipeout(pipe
));
604 if (size
> dev
->isoc_in
.maxsize
)
605 size
= dev
->isoc_in
.maxsize
;
607 dev
->isoc_ctl
.max_pkt_size
= size
;
609 max_packets
= TM6000_MAX_ISO_PACKETS
;
610 sb_size
= max_packets
* size
;
612 dev
->isoc_ctl
.num_bufs
= num_bufs
;
614 dev
->isoc_ctl
.urb
= kmalloc(sizeof(void *)*num_bufs
, GFP_KERNEL
);
615 if (!dev
->isoc_ctl
.urb
) {
616 tm6000_err("cannot alloc memory for usb buffers\n");
620 dev
->isoc_ctl
.transfer_buffer
= kmalloc(sizeof(void *)*num_bufs
,
622 if (!dev
->isoc_ctl
.transfer_buffer
) {
623 tm6000_err("cannot allocate memory for usbtransfer\n");
624 kfree(dev
->isoc_ctl
.urb
);
628 dprintk(dev
, V4L2_DEBUG_QUEUE
, "Allocating %d x %d packets"
629 " (%d bytes) of %d bytes each to handle %u size\n",
630 max_packets
, num_bufs
, sb_size
,
631 dev
->isoc_in
.maxsize
, size
);
633 /* allocate urbs and transfer buffers */
634 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
635 urb
= usb_alloc_urb(max_packets
, GFP_KERNEL
);
637 tm6000_err("cannot alloc isoc_ctl.urb %i\n", i
);
638 tm6000_uninit_isoc(dev
);
642 dev
->isoc_ctl
.urb
[i
] = urb
;
644 dev
->isoc_ctl
.transfer_buffer
[i
] = usb_alloc_coherent(dev
->udev
,
645 sb_size
, GFP_KERNEL
, &urb
->transfer_dma
);
646 if (!dev
->isoc_ctl
.transfer_buffer
[i
]) {
647 tm6000_err("unable to allocate %i bytes for transfer"
650 in_interrupt() ? " while in int" : "");
651 tm6000_uninit_isoc(dev
);
654 memset(dev
->isoc_ctl
.transfer_buffer
[i
], 0, sb_size
);
656 usb_fill_bulk_urb(urb
, dev
->udev
, pipe
,
657 dev
->isoc_ctl
.transfer_buffer
[i
], sb_size
,
658 tm6000_irq_callback
, dma_q
);
659 urb
->interval
= dev
->isoc_in
.endp
->desc
.bInterval
;
660 urb
->number_of_packets
= max_packets
;
661 urb
->transfer_flags
= URB_ISO_ASAP
| URB_NO_TRANSFER_DMA_MAP
;
663 for (j
= 0; j
< max_packets
; j
++) {
664 urb
->iso_frame_desc
[j
].offset
= size
* j
;
665 urb
->iso_frame_desc
[j
].length
= size
;
672 static int tm6000_start_thread(struct tm6000_core
*dev
)
674 struct tm6000_dmaqueue
*dma_q
= &dev
->vidq
;
678 dma_q
->ini_jiffies
= jiffies
;
680 init_waitqueue_head(&dma_q
->wq
);
682 /* submit urbs and enables IRQ */
683 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
684 int rc
= usb_submit_urb(dev
->isoc_ctl
.urb
[i
], GFP_ATOMIC
);
686 tm6000_err("submit of urb %i failed (error=%i)\n", i
,
688 tm6000_uninit_isoc(dev
);
696 /* ------------------------------------------------------------------
697 * Videobuf operations
698 * ------------------------------------------------------------------
702 buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
, unsigned int *size
)
704 struct tm6000_fh
*fh
= vq
->priv_data
;
706 *size
= fh
->fmt
->depth
* fh
->width
* fh
->height
>> 3;
708 *count
= TM6000_DEF_BUF
;
710 if (*count
< TM6000_MIN_BUF
)
711 *count
= TM6000_MIN_BUF
;
713 while (*size
* *count
> vid_limit
* 1024 * 1024)
719 static void free_buffer(struct videobuf_queue
*vq
, struct tm6000_buffer
*buf
)
721 struct tm6000_fh
*fh
= vq
->priv_data
;
722 struct tm6000_core
*dev
= fh
->dev
;
728 /* We used to wait for the buffer to finish here, but this didn't work
729 because, as we were keeping the state as VIDEOBUF_QUEUED,
730 videobuf_queue_cancel marked it as finished for us.
731 (Also, it could wedge forever if the hardware was misconfigured.)
733 This should be safe; by the time we get here, the buffer isn't
734 queued anymore. If we ever start marking the buffers as
735 VIDEOBUF_ACTIVE, it won't be, though.
737 spin_lock_irqsave(&dev
->slock
, flags
);
738 if (dev
->isoc_ctl
.buf
== buf
)
739 dev
->isoc_ctl
.buf
= NULL
;
740 spin_unlock_irqrestore(&dev
->slock
, flags
);
742 videobuf_vmalloc_free(&buf
->vb
);
743 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
747 buffer_prepare(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
,
748 enum v4l2_field field
)
750 struct tm6000_fh
*fh
= vq
->priv_data
;
751 struct tm6000_buffer
*buf
= container_of(vb
, struct tm6000_buffer
, vb
);
752 struct tm6000_core
*dev
= fh
->dev
;
753 int rc
= 0, urb_init
= 0;
755 BUG_ON(NULL
== fh
->fmt
);
758 /* FIXME: It assumes depth=2 */
759 /* The only currently supported format is 16 bits/pixel */
760 buf
->vb
.size
= fh
->fmt
->depth
*fh
->width
*fh
->height
>> 3;
761 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
764 if (buf
->fmt
!= fh
->fmt
||
765 buf
->vb
.width
!= fh
->width
||
766 buf
->vb
.height
!= fh
->height
||
767 buf
->vb
.field
!= field
) {
769 buf
->vb
.width
= fh
->width
;
770 buf
->vb
.height
= fh
->height
;
771 buf
->vb
.field
= field
;
772 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
775 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
776 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
782 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
)
1061 videobuf_streamoff(&fh
->vb_vidq
);
1067 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*norm
)
1070 struct tm6000_fh
*fh
= priv
;
1071 struct tm6000_core
*dev
= fh
->dev
;
1074 rc
= tm6000_init_analog_mode(dev
);
1076 fh
->width
= dev
->width
;
1077 fh
->height
= dev
->height
;
1082 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
1087 static const char *iname
[] = {
1088 [TM6000_INPUT_TV
] = "Television",
1089 [TM6000_INPUT_COMPOSITE1
] = "Composite 1",
1090 [TM6000_INPUT_COMPOSITE2
] = "Composite 2",
1091 [TM6000_INPUT_SVIDEO
] = "S-Video",
1094 static int vidioc_enum_input(struct file
*file
, void *priv
,
1095 struct v4l2_input
*i
)
1097 struct tm6000_fh
*fh
= priv
;
1098 struct tm6000_core
*dev
= fh
->dev
;
1105 if (!dev
->vinput
[n
].type
)
1110 if (dev
->vinput
[n
].type
== TM6000_INPUT_TV
)
1111 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1113 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1115 strcpy(i
->name
, iname
[dev
->vinput
[n
].type
]);
1117 i
->std
= TM6000_STD
;
1122 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1124 struct tm6000_fh
*fh
= priv
;
1125 struct tm6000_core
*dev
= fh
->dev
;
1132 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
1134 struct tm6000_fh
*fh
= priv
;
1135 struct tm6000_core
*dev
= fh
->dev
;
1140 if (!dev
->vinput
[i
].type
)
1145 rc
= vidioc_s_std(file
, priv
, &dev
->vfd
->current_norm
);
1150 /* --- controls ---------------------------------------------- */
1151 static int vidioc_queryctrl(struct file
*file
, void *priv
,
1152 struct v4l2_queryctrl
*qc
)
1156 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1157 if (qc
->id
&& qc
->id
== tm6000_qctrl
[i
].id
) {
1158 memcpy(qc
, &(tm6000_qctrl
[i
]),
1166 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1167 struct v4l2_control
*ctrl
)
1169 struct tm6000_fh
*fh
= priv
;
1170 struct tm6000_core
*dev
= fh
->dev
;
1173 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1175 case V4L2_CID_CONTRAST
:
1176 val
= tm6000_get_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, 0);
1178 case V4L2_CID_BRIGHTNESS
:
1179 val
= tm6000_get_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, 0);
1181 case V4L2_CID_SATURATION
:
1182 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, 0);
1185 val
= tm6000_get_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, 0);
1187 case V4L2_CID_AUDIO_MUTE
:
1188 val
= dev
->ctl_mute
;
1190 case V4L2_CID_AUDIO_VOLUME
:
1191 val
= dev
->ctl_volume
;
1204 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1205 struct v4l2_control
*ctrl
)
1207 struct tm6000_fh
*fh
= priv
;
1208 struct tm6000_core
*dev
= fh
->dev
;
1209 u8 val
= ctrl
->value
;
1212 case V4L2_CID_CONTRAST
:
1213 tm6000_set_reg(dev
, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ
, val
);
1215 case V4L2_CID_BRIGHTNESS
:
1216 tm6000_set_reg(dev
, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ
, val
);
1218 case V4L2_CID_SATURATION
:
1219 tm6000_set_reg(dev
, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ
, val
);
1222 tm6000_set_reg(dev
, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ
, val
);
1224 case V4L2_CID_AUDIO_MUTE
:
1225 dev
->ctl_mute
= val
;
1226 tm6000_tvaudio_set_mute(dev
, val
);
1228 case V4L2_CID_AUDIO_VOLUME
:
1229 dev
->ctl_volume
= val
;
1230 tm6000_set_volume(dev
, val
);
1236 static int vidioc_g_tuner(struct file
*file
, void *priv
,
1237 struct v4l2_tuner
*t
)
1239 struct tm6000_fh
*fh
= priv
;
1240 struct tm6000_core
*dev
= fh
->dev
;
1242 if (unlikely(UNSET
== dev
->tuner_type
))
1247 strcpy(t
->name
, "Television");
1248 t
->type
= V4L2_TUNER_ANALOG_TV
;
1249 t
->capability
= V4L2_TUNER_CAP_NORM
;
1250 t
->rangehigh
= 0xffffffffUL
;
1251 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1253 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1255 t
->audmode
= dev
->amode
;
1260 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1261 struct v4l2_tuner
*t
)
1263 struct tm6000_fh
*fh
= priv
;
1264 struct tm6000_core
*dev
= fh
->dev
;
1266 if (UNSET
== dev
->tuner_type
)
1271 dev
->amode
= t
->audmode
;
1272 dprintk(dev
, 3, "audio mode: %x\n", t
->audmode
);
1274 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1279 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1280 struct v4l2_frequency
*f
)
1282 struct tm6000_fh
*fh
= priv
;
1283 struct tm6000_core
*dev
= fh
->dev
;
1285 if (unlikely(UNSET
== dev
->tuner_type
))
1288 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1289 f
->frequency
= dev
->freq
;
1291 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_frequency
, f
);
1296 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1297 struct v4l2_frequency
*f
)
1299 struct tm6000_fh
*fh
= priv
;
1300 struct tm6000_core
*dev
= fh
->dev
;
1302 if (unlikely(UNSET
== dev
->tuner_type
))
1304 if (unlikely(f
->tuner
!= 0))
1306 if (0 == fh
->radio
&& V4L2_TUNER_ANALOG_TV
!= f
->type
)
1308 if (1 == fh
->radio
&& V4L2_TUNER_RADIO
!= f
->type
)
1311 dev
->freq
= f
->frequency
;
1312 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, f
);
1317 static int radio_querycap(struct file
*file
, void *priv
,
1318 struct v4l2_capability
*cap
)
1320 struct tm6000_fh
*fh
= file
->private_data
;
1321 struct tm6000_core
*dev
= fh
->dev
;
1323 strcpy(cap
->driver
, "tm6000");
1324 strlcpy(cap
->card
, dev
->name
, sizeof(dev
->name
));
1325 sprintf(cap
->bus_info
, "USB%04x:%04x",
1326 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
1327 le16_to_cpu(dev
->udev
->descriptor
.idProduct
));
1328 cap
->version
= dev
->dev_type
;
1329 cap
->capabilities
= V4L2_CAP_TUNER
|
1332 V4L2_CAP_READWRITE
|
1338 static int radio_g_tuner(struct file
*file
, void *priv
,
1339 struct v4l2_tuner
*t
)
1341 struct tm6000_fh
*fh
= file
->private_data
;
1342 struct tm6000_core
*dev
= fh
->dev
;
1347 memset(t
, 0, sizeof(*t
));
1348 strcpy(t
->name
, "Radio");
1349 t
->type
= V4L2_TUNER_RADIO
;
1350 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
1352 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1357 static int radio_s_tuner(struct file
*file
, void *priv
,
1358 struct v4l2_tuner
*t
)
1360 struct tm6000_fh
*fh
= file
->private_data
;
1361 struct tm6000_core
*dev
= fh
->dev
;
1366 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1371 static int radio_enum_input(struct file
*file
, void *priv
,
1372 struct v4l2_input
*i
)
1374 struct tm6000_fh
*fh
= priv
;
1375 struct tm6000_core
*dev
= fh
->dev
;
1380 if (!dev
->rinput
.type
)
1383 strcpy(i
->name
, "Radio");
1384 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1389 static int radio_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
1391 struct tm6000_fh
*fh
= priv
;
1392 struct tm6000_core
*dev
= fh
->dev
;
1394 if (dev
->input
!= 5)
1397 *i
= dev
->input
- 5;
1402 static int radio_g_audio(struct file
*file
, void *priv
,
1403 struct v4l2_audio
*a
)
1405 memset(a
, 0, sizeof(*a
));
1406 strcpy(a
->name
, "Radio");
1410 static int radio_s_audio(struct file
*file
, void *priv
,
1411 struct v4l2_audio
*a
)
1416 static int radio_s_input(struct file
*filp
, void *priv
, unsigned int i
)
1418 struct tm6000_fh
*fh
= priv
;
1419 struct tm6000_core
*dev
= fh
->dev
;
1424 if (!dev
->rinput
.type
)
1432 static int radio_s_std(struct file
*file
, void *fh
, v4l2_std_id
*norm
)
1437 static int radio_queryctrl(struct file
*file
, void *priv
,
1438 struct v4l2_queryctrl
*c
)
1440 const struct v4l2_queryctrl
*ctrl
;
1442 if (c
->id
< V4L2_CID_BASE
||
1443 c
->id
>= V4L2_CID_LASTP1
)
1445 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
1446 ctrl
= ctrl_by_id(c
->id
);
1454 /* ------------------------------------------------------------------
1455 File operations for the device
1456 ------------------------------------------------------------------*/
1458 static int tm6000_open(struct file
*file
)
1460 struct video_device
*vdev
= video_devdata(file
);
1461 struct tm6000_core
*dev
= video_drvdata(file
);
1462 struct tm6000_fh
*fh
;
1463 enum v4l2_buf_type type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1467 printk(KERN_INFO
"tm6000: open called (dev=%s)\n",
1468 video_device_node_name(vdev
));
1470 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: open called (dev=%s)\n",
1471 video_device_node_name(vdev
));
1473 switch (vdev
->vfl_type
) {
1474 case VFL_TYPE_GRABBER
:
1475 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1478 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1480 case VFL_TYPE_RADIO
:
1485 /* If more than one user, mutex should be added */
1488 dprintk(dev
, V4L2_DEBUG_OPEN
, "open dev=%s type=%s users=%d\n",
1489 video_device_node_name(vdev
), v4l2_type_names
[type
],
1492 /* allocate + initialize per filehandle data */
1493 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1499 file
->private_data
= fh
;
1504 dev
->fourcc
= format
[0].fourcc
;
1506 fh
->fmt
= format_by_fourcc(dev
->fourcc
);
1508 tm6000_get_std_res(dev
);
1510 fh
->width
= dev
->width
;
1511 fh
->height
= dev
->height
;
1513 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: fh=0x%08lx, dev=0x%08lx, "
1514 "dev->vidq=0x%08lx\n",
1515 (unsigned long)fh
, (unsigned long)dev
, (unsigned long)&dev
->vidq
);
1516 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1517 "queued=%d\n", list_empty(&dev
->vidq
.queued
));
1518 dprintk(dev
, V4L2_DEBUG_OPEN
, "Open: list_empty "
1519 "active=%d\n", list_empty(&dev
->vidq
.active
));
1521 /* initialize hardware on analog mode */
1522 rc
= tm6000_init_analog_mode(dev
);
1526 if (dev
->mode
!= TM6000_MODE_ANALOG
) {
1527 /* Put all controls at a sane state */
1528 for (i
= 0; i
< ARRAY_SIZE(tm6000_qctrl
); i
++)
1529 qctl_regs
[i
] = tm6000_qctrl
[i
].default_value
;
1531 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
);
1541 dprintk(dev
, V4L2_DEBUG_OPEN
, "video_open: setting radio device\n");
1543 tm6000_set_audio_rinput(dev
);
1544 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_radio
);
1545 tm6000_prepare_isoc(dev
);
1546 tm6000_start_thread(dev
);
1553 tm6000_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*pos
)
1555 struct tm6000_fh
*fh
= file
->private_data
;
1557 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1558 if (!res_get(fh
->dev
, fh
, true))
1561 return videobuf_read_stream(&fh
->vb_vidq
, data
, count
, pos
, 0,
1562 file
->f_flags
& O_NONBLOCK
);
1568 tm6000_poll(struct file
*file
, struct poll_table_struct
*wait
)
1570 struct tm6000_fh
*fh
= file
->private_data
;
1571 struct tm6000_buffer
*buf
;
1573 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= fh
->type
)
1576 if (!!is_res_streaming(fh
->dev
, fh
))
1579 if (!is_res_read(fh
->dev
, fh
)) {
1580 /* streaming capture */
1581 if (list_empty(&fh
->vb_vidq
.stream
))
1583 buf
= list_entry(fh
->vb_vidq
.stream
.next
, struct tm6000_buffer
, vb
.stream
);
1585 /* read() capture */
1586 return videobuf_poll_stream(file
, &fh
->vb_vidq
,
1589 poll_wait(file
, &buf
->vb
.done
, wait
);
1590 if (buf
->vb
.state
== VIDEOBUF_DONE
||
1591 buf
->vb
.state
== VIDEOBUF_ERROR
)
1592 return POLLIN
| POLLRDNORM
;
1596 static int tm6000_release(struct file
*file
)
1598 struct tm6000_fh
*fh
= file
->private_data
;
1599 struct tm6000_core
*dev
= fh
->dev
;
1600 struct video_device
*vdev
= video_devdata(file
);
1602 dprintk(dev
, V4L2_DEBUG_OPEN
, "tm6000: close called (dev=%s, users=%d)\n",
1603 video_device_node_name(vdev
), dev
->users
);
1609 tm6000_uninit_isoc(dev
);
1610 videobuf_mmap_free(&fh
->vb_vidq
);
1618 static int tm6000_mmap(struct file
*file
, struct vm_area_struct
* vma
)
1620 struct tm6000_fh
*fh
= file
->private_data
;
1623 ret
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
1628 static struct v4l2_file_operations tm6000_fops
= {
1629 .owner
= THIS_MODULE
,
1630 .open
= tm6000_open
,
1631 .release
= tm6000_release
,
1632 .unlocked_ioctl
= video_ioctl2
, /* V4L2 ioctl handler */
1633 .read
= tm6000_read
,
1634 .poll
= tm6000_poll
,
1635 .mmap
= tm6000_mmap
,
1638 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1639 .vidioc_querycap
= vidioc_querycap
,
1640 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1641 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1642 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1643 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1644 .vidioc_s_std
= vidioc_s_std
,
1645 .vidioc_enum_input
= vidioc_enum_input
,
1646 .vidioc_g_input
= vidioc_g_input
,
1647 .vidioc_s_input
= vidioc_s_input
,
1648 .vidioc_queryctrl
= vidioc_queryctrl
,
1649 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1650 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1651 .vidioc_g_tuner
= vidioc_g_tuner
,
1652 .vidioc_s_tuner
= vidioc_s_tuner
,
1653 .vidioc_g_frequency
= vidioc_g_frequency
,
1654 .vidioc_s_frequency
= vidioc_s_frequency
,
1655 .vidioc_streamon
= vidioc_streamon
,
1656 .vidioc_streamoff
= vidioc_streamoff
,
1657 .vidioc_reqbufs
= vidioc_reqbufs
,
1658 .vidioc_querybuf
= vidioc_querybuf
,
1659 .vidioc_qbuf
= vidioc_qbuf
,
1660 .vidioc_dqbuf
= vidioc_dqbuf
,
1663 static struct video_device tm6000_template
= {
1665 .fops
= &tm6000_fops
,
1666 .ioctl_ops
= &video_ioctl_ops
,
1667 .release
= video_device_release
,
1668 .tvnorms
= TM6000_STD
,
1669 .current_norm
= V4L2_STD_NTSC_M
,
1672 static const struct v4l2_file_operations radio_fops
= {
1673 .owner
= THIS_MODULE
,
1674 .open
= tm6000_open
,
1675 .release
= tm6000_release
,
1676 .unlocked_ioctl
= video_ioctl2
,
1679 static const struct v4l2_ioctl_ops radio_ioctl_ops
= {
1680 .vidioc_querycap
= radio_querycap
,
1681 .vidioc_g_tuner
= radio_g_tuner
,
1682 .vidioc_enum_input
= radio_enum_input
,
1683 .vidioc_g_audio
= radio_g_audio
,
1684 .vidioc_s_tuner
= radio_s_tuner
,
1685 .vidioc_s_audio
= radio_s_audio
,
1686 .vidioc_s_input
= radio_s_input
,
1687 .vidioc_s_std
= radio_s_std
,
1688 .vidioc_queryctrl
= radio_queryctrl
,
1689 .vidioc_g_input
= radio_g_input
,
1690 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1691 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1692 .vidioc_g_frequency
= vidioc_g_frequency
,
1693 .vidioc_s_frequency
= vidioc_s_frequency
,
1696 struct video_device tm6000_radio_template
= {
1698 .fops
= &radio_fops
,
1699 .ioctl_ops
= &radio_ioctl_ops
,
1702 /* -----------------------------------------------------------------
1703 * Initialization and module stuff
1704 * ------------------------------------------------------------------
1707 static struct video_device
*vdev_init(struct tm6000_core
*dev
,
1708 const struct video_device
1709 *template, const char *type_name
)
1711 struct video_device
*vfd
;
1713 vfd
= video_device_alloc();
1718 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1719 vfd
->release
= video_device_release
;
1720 vfd
->debug
= tm6000_debug
;
1721 vfd
->lock
= &dev
->lock
;
1723 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s", dev
->name
, type_name
);
1725 video_set_drvdata(vfd
, dev
);
1729 int tm6000_v4l2_register(struct tm6000_core
*dev
)
1733 dev
->vfd
= vdev_init(dev
, &tm6000_template
, "video");
1736 printk(KERN_INFO
"%s: can't register video device\n",
1741 /* init video dma queues */
1742 INIT_LIST_HEAD(&dev
->vidq
.active
);
1743 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1745 ret
= video_register_device(dev
->vfd
, VFL_TYPE_GRABBER
, video_nr
);
1748 printk(KERN_INFO
"%s: can't register video device\n",
1753 printk(KERN_INFO
"%s: registered device %s\n",
1754 dev
->name
, video_device_node_name(dev
->vfd
));
1756 if (dev
->caps
.has_radio
) {
1757 dev
->radio_dev
= vdev_init(dev
, &tm6000_radio_template
,
1759 if (!dev
->radio_dev
) {
1760 printk(KERN_INFO
"%s: can't register radio device\n",
1762 return ret
; /* FIXME release resource */
1765 ret
= video_register_device(dev
->radio_dev
, VFL_TYPE_RADIO
,
1768 printk(KERN_INFO
"%s: can't register radio device\n",
1770 return ret
; /* FIXME release resource */
1773 printk(KERN_INFO
"%s: registered device %s\n",
1774 dev
->name
, video_device_node_name(dev
->radio_dev
));
1777 printk(KERN_INFO
"Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret
);
1781 int tm6000_v4l2_unregister(struct tm6000_core
*dev
)
1783 video_unregister_device(dev
->vfd
);
1785 if (dev
->radio_dev
) {
1786 if (video_is_registered(dev
->radio_dev
))
1787 video_unregister_device(dev
->radio_dev
);
1789 video_device_release(dev
->radio_dev
);
1790 dev
->radio_dev
= NULL
;
1796 int tm6000_v4l2_exit(void)
1801 module_param(video_nr
, int, 0);
1802 MODULE_PARM_DESC(video_nr
, "Allow changing video device number");
1804 module_param_named(debug
, tm6000_debug
, int, 0444);
1805 MODULE_PARM_DESC(debug
, "activates debug info");
1807 module_param(vid_limit
, int, 0644);
1808 MODULE_PARM_DESC(vid_limit
, "capture memory limit in megabytes");