2 * Auvitek AU0828 USB Bridge (Analog video support)
4 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
5 * Copyright (C) 2005-2008 Auvitek International, Ltd.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * As published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * VBI support is not yet working
26 * The hardware scaler supported is unimplemented
27 * AC97 audio support is unimplemented (only i2s audio mode)
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/device.h>
34 #include <linux/suspend.h>
35 #include <linux/version.h>
36 #include <media/v4l2-common.h>
37 #include <media/v4l2-ioctl.h>
38 #include <media/v4l2-chip-ident.h>
39 #include <media/tuner.h>
41 #include "au0828-reg.h"
43 static LIST_HEAD(au0828_devlist
);
44 static DEFINE_MUTEX(au0828_sysfs_lock
);
46 #define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1)
48 /* ------------------------------------------------------------------
50 ------------------------------------------------------------------*/
52 static unsigned int isoc_debug
;
53 module_param(isoc_debug
, int, 0644);
54 MODULE_PARM_DESC(isoc_debug
, "enable debug messages [isoc transfers]");
56 #define au0828_isocdbg(fmt, arg...) \
59 printk(KERN_INFO "au0828 %s :"fmt, \
64 static inline void print_err_status(struct au0828_dev
*dev
,
65 int packet
, int status
)
67 char *errmsg
= "Unknown";
71 errmsg
= "unlinked synchronuously";
74 errmsg
= "unlinked asynchronuously";
77 errmsg
= "Buffer error (overrun)";
80 errmsg
= "Stalled (device not responding)";
83 errmsg
= "Babble (bad cable?)";
86 errmsg
= "Bit-stuff error (bad cable?)";
89 errmsg
= "CRC/Timeout (could be anything)";
92 errmsg
= "Device does not respond";
96 au0828_isocdbg("URB status %d [%s].\n", status
, errmsg
);
98 au0828_isocdbg("URB packet %d, status %d [%s].\n",
99 packet
, status
, errmsg
);
103 static int check_dev(struct au0828_dev
*dev
)
105 if (dev
->dev_state
& DEV_DISCONNECTED
) {
106 printk(KERN_INFO
"v4l2 ioctl: device not present\n");
110 if (dev
->dev_state
& DEV_MISCONFIGURED
) {
111 printk(KERN_INFO
"v4l2 ioctl: device is misconfigured; "
112 "close and open it again\n");
119 * IRQ callback, called by URB callback
121 static void au0828_irq_callback(struct urb
*urb
)
123 struct au0828_dmaqueue
*dma_q
= urb
->context
;
124 struct au0828_dev
*dev
= container_of(dma_q
, struct au0828_dev
, vidq
);
127 switch (urb
->status
) {
128 case 0: /* success */
129 case -ETIMEDOUT
: /* NAK */
131 case -ECONNRESET
: /* kill */
134 au0828_isocdbg("au0828_irq_callback called: status kill\n");
136 default: /* unknown error */
137 au0828_isocdbg("urb completition error %d.\n", urb
->status
);
141 /* Copy data from URB */
142 spin_lock(&dev
->slock
);
143 rc
= dev
->isoc_ctl
.isoc_copy(dev
, urb
);
144 spin_unlock(&dev
->slock
);
146 /* Reset urb buffers */
147 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
148 urb
->iso_frame_desc
[i
].status
= 0;
149 urb
->iso_frame_desc
[i
].actual_length
= 0;
153 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
155 au0828_isocdbg("urb resubmit failed (error=%i)\n",
161 * Stop and Deallocate URBs
163 void au0828_uninit_isoc(struct au0828_dev
*dev
)
168 au0828_isocdbg("au0828: called au0828_uninit_isoc\n");
170 dev
->isoc_ctl
.nfields
= -1;
171 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
172 urb
= dev
->isoc_ctl
.urb
[i
];
174 if (!irqs_disabled())
179 if (dev
->isoc_ctl
.transfer_buffer
[i
]) {
180 usb_buffer_free(dev
->usbdev
,
181 urb
->transfer_buffer_length
,
182 dev
->isoc_ctl
.transfer_buffer
[i
],
186 dev
->isoc_ctl
.urb
[i
] = NULL
;
188 dev
->isoc_ctl
.transfer_buffer
[i
] = NULL
;
191 kfree(dev
->isoc_ctl
.urb
);
192 kfree(dev
->isoc_ctl
.transfer_buffer
);
194 dev
->isoc_ctl
.urb
= NULL
;
195 dev
->isoc_ctl
.transfer_buffer
= NULL
;
196 dev
->isoc_ctl
.num_bufs
= 0;
200 * Allocate URBs and start IRQ
202 int au0828_init_isoc(struct au0828_dev
*dev
, int max_packets
,
203 int num_bufs
, int max_pkt_size
,
204 int (*isoc_copy
) (struct au0828_dev
*dev
, struct urb
*urb
))
206 struct au0828_dmaqueue
*dma_q
= &dev
->vidq
;
213 au0828_isocdbg("au0828: called au0828_prepare_isoc\n");
215 /* De-allocates all pending stuff */
216 au0828_uninit_isoc(dev
);
218 dev
->isoc_ctl
.isoc_copy
= isoc_copy
;
219 dev
->isoc_ctl
.num_bufs
= num_bufs
;
221 dev
->isoc_ctl
.urb
= kzalloc(sizeof(void *)*num_bufs
, GFP_KERNEL
);
222 if (!dev
->isoc_ctl
.urb
) {
223 au0828_isocdbg("cannot alloc memory for usb buffers\n");
227 dev
->isoc_ctl
.transfer_buffer
= kzalloc(sizeof(void *)*num_bufs
,
229 if (!dev
->isoc_ctl
.transfer_buffer
) {
230 au0828_isocdbg("cannot allocate memory for usb transfer\n");
231 kfree(dev
->isoc_ctl
.urb
);
235 dev
->isoc_ctl
.max_pkt_size
= max_pkt_size
;
236 dev
->isoc_ctl
.buf
= NULL
;
238 sb_size
= max_packets
* dev
->isoc_ctl
.max_pkt_size
;
240 /* allocate urbs and transfer buffers */
241 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
242 urb
= usb_alloc_urb(max_packets
, GFP_KERNEL
);
244 au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i
);
245 au0828_uninit_isoc(dev
);
248 dev
->isoc_ctl
.urb
[i
] = urb
;
250 dev
->isoc_ctl
.transfer_buffer
[i
] = usb_buffer_alloc(dev
->usbdev
,
251 sb_size
, GFP_KERNEL
, &urb
->transfer_dma
);
252 if (!dev
->isoc_ctl
.transfer_buffer
[i
]) {
253 printk("unable to allocate %i bytes for transfer"
256 in_interrupt() ? " while in int" : "");
257 au0828_uninit_isoc(dev
);
260 memset(dev
->isoc_ctl
.transfer_buffer
[i
], 0, sb_size
);
262 pipe
= usb_rcvisocpipe(dev
->usbdev
,
263 dev
->isoc_in_endpointaddr
),
265 usb_fill_int_urb(urb
, dev
->usbdev
, pipe
,
266 dev
->isoc_ctl
.transfer_buffer
[i
], sb_size
,
267 au0828_irq_callback
, dma_q
, 1);
269 urb
->number_of_packets
= max_packets
;
270 urb
->transfer_flags
= URB_ISO_ASAP
| URB_NO_TRANSFER_DMA_MAP
;
273 for (j
= 0; j
< max_packets
; j
++) {
274 urb
->iso_frame_desc
[j
].offset
= k
;
275 urb
->iso_frame_desc
[j
].length
=
276 dev
->isoc_ctl
.max_pkt_size
;
277 k
+= dev
->isoc_ctl
.max_pkt_size
;
281 init_waitqueue_head(&dma_q
->wq
);
283 /* submit urbs and enables IRQ */
284 for (i
= 0; i
< dev
->isoc_ctl
.num_bufs
; i
++) {
285 rc
= usb_submit_urb(dev
->isoc_ctl
.urb
[i
], GFP_ATOMIC
);
287 au0828_isocdbg("submit of urb %i failed (error=%i)\n",
289 au0828_uninit_isoc(dev
);
298 * Announces that a buffer were filled and request the next
300 static inline void buffer_filled(struct au0828_dev
*dev
,
301 struct au0828_dmaqueue
*dma_q
,
302 struct au0828_buffer
*buf
)
304 /* Advice that buffer was filled */
305 au0828_isocdbg("[%p/%d] wakeup\n", buf
, buf
->vb
.i
);
307 buf
->vb
.state
= VIDEOBUF_DONE
;
308 buf
->vb
.field_count
++;
309 do_gettimeofday(&buf
->vb
.ts
);
311 dev
->isoc_ctl
.buf
= NULL
;
313 list_del(&buf
->vb
.queue
);
314 wake_up(&buf
->vb
.done
);
318 * Identify the buffer header type and properly handles
320 static void au0828_copy_video(struct au0828_dev
*dev
,
321 struct au0828_dmaqueue
*dma_q
,
322 struct au0828_buffer
*buf
,
324 unsigned char *outp
, unsigned long len
)
326 void *fieldstart
, *startwrite
, *startread
;
327 int linesdone
, currlinedone
, offset
, lencopy
, remain
;
328 int bytesperline
= dev
->width
<< 1; /* Assumes 16-bit depth @@@@ */
330 if (dma_q
->pos
+ len
> buf
->vb
.size
)
331 len
= buf
->vb
.size
- dma_q
->pos
;
336 /* Interlaces frame */
340 fieldstart
= outp
+ bytesperline
;
342 linesdone
= dma_q
->pos
/ bytesperline
;
343 currlinedone
= dma_q
->pos
% bytesperline
;
344 offset
= linesdone
* bytesperline
* 2 + currlinedone
;
345 startwrite
= fieldstart
+ offset
;
346 lencopy
= bytesperline
- currlinedone
;
347 lencopy
= lencopy
> remain
? remain
: lencopy
;
349 if ((char *)startwrite
+ lencopy
> (char *)outp
+ buf
->vb
.size
) {
350 au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
351 ((char *)startwrite
+ lencopy
) -
352 ((char *)outp
+ buf
->vb
.size
));
353 remain
= (char *)outp
+ buf
->vb
.size
- (char *)startwrite
;
358 memcpy(startwrite
, startread
, lencopy
);
363 startwrite
+= lencopy
+ bytesperline
;
364 startread
+= lencopy
;
365 if (bytesperline
> remain
)
368 lencopy
= bytesperline
;
370 if ((char *)startwrite
+ lencopy
> (char *)outp
+
372 au0828_isocdbg("Overflow %zi bytes past buf end (2)\n",
373 ((char *)startwrite
+ lencopy
) -
374 ((char *)outp
+ buf
->vb
.size
));
375 lencopy
= remain
= (char *)outp
+ buf
->vb
.size
-
381 memcpy(startwrite
, startread
, lencopy
);
387 /* We have enough data to check for greenscreen */
388 if (outp
[0] < 0x60 && outp
[1440] < 0x60)
389 dev
->greenscreen_detected
= 1;
396 * video-buf generic routine to get the next available buffer
398 static inline void get_next_buf(struct au0828_dmaqueue
*dma_q
,
399 struct au0828_buffer
**buf
)
401 struct au0828_dev
*dev
= container_of(dma_q
, struct au0828_dev
, vidq
);
403 if (list_empty(&dma_q
->active
)) {
404 au0828_isocdbg("No active queue to serve\n");
405 dev
->isoc_ctl
.buf
= NULL
;
410 /* Get the next buffer */
411 *buf
= list_entry(dma_q
->active
.next
, struct au0828_buffer
, vb
.queue
);
412 dev
->isoc_ctl
.buf
= *buf
;
418 * Controls the isoc copy of each urb packet
420 static inline int au0828_isoc_copy(struct au0828_dev
*dev
, struct urb
*urb
)
422 struct au0828_buffer
*buf
;
423 struct au0828_dmaqueue
*dma_q
= urb
->context
;
424 unsigned char *outp
= NULL
;
425 int i
, len
= 0, rc
= 1;
432 if ((dev
->dev_state
& DEV_DISCONNECTED
) ||
433 (dev
->dev_state
& DEV_MISCONFIGURED
))
436 if (urb
->status
< 0) {
437 print_err_status(dev
, -1, urb
->status
);
438 if (urb
->status
== -ENOENT
)
442 buf
= dev
->isoc_ctl
.buf
;
444 outp
= videobuf_to_vmalloc(&buf
->vb
);
446 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
447 int status
= urb
->iso_frame_desc
[i
].status
;
450 print_err_status(dev
, i
, status
);
451 if (urb
->iso_frame_desc
[i
].status
!= -EPROTO
)
455 if (urb
->iso_frame_desc
[i
].actual_length
<= 0)
458 if (urb
->iso_frame_desc
[i
].actual_length
>
460 au0828_isocdbg("packet bigger than packet size");
464 p
= urb
->transfer_buffer
+ urb
->iso_frame_desc
[i
].offset
;
466 len
= urb
->iso_frame_desc
[i
].actual_length
- 4;
472 au0828_isocdbg("Video frame %s\n",
473 (fbyte
& 0x40) ? "odd" : "even");
474 if (!(fbyte
& 0x40)) {
476 buffer_filled(dev
, dma_q
, buf
);
477 get_next_buf(dma_q
, &buf
);
481 outp
= videobuf_to_vmalloc(&buf
->vb
);
494 au0828_copy_video(dev
, dma_q
, buf
, p
, outp
, len
);
500 buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
,
503 struct au0828_fh
*fh
= vq
->priv_data
;
504 *size
= (fh
->dev
->width
* fh
->dev
->height
* 16 + 7) >> 3;
507 *count
= AU0828_DEF_BUF
;
509 if (*count
< AU0828_MIN_BUF
)
510 *count
= AU0828_MIN_BUF
;
514 /* This is called *without* dev->slock held; please keep it that way */
515 static void free_buffer(struct videobuf_queue
*vq
, struct au0828_buffer
*buf
)
517 struct au0828_fh
*fh
= vq
->priv_data
;
518 struct au0828_dev
*dev
= fh
->dev
;
519 unsigned long flags
= 0;
523 /* We used to wait for the buffer to finish here, but this didn't work
524 because, as we were keeping the state as VIDEOBUF_QUEUED,
525 videobuf_queue_cancel marked it as finished for us.
526 (Also, it could wedge forever if the hardware was misconfigured.)
528 This should be safe; by the time we get here, the buffer isn't
529 queued anymore. If we ever start marking the buffers as
530 VIDEOBUF_ACTIVE, it won't be, though.
532 spin_lock_irqsave(&dev
->slock
, flags
);
533 if (dev
->isoc_ctl
.buf
== buf
)
534 dev
->isoc_ctl
.buf
= NULL
;
535 spin_unlock_irqrestore(&dev
->slock
, flags
);
537 videobuf_vmalloc_free(&buf
->vb
);
538 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
542 buffer_prepare(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
,
543 enum v4l2_field field
)
545 struct au0828_fh
*fh
= vq
->priv_data
;
546 struct au0828_buffer
*buf
= container_of(vb
, struct au0828_buffer
, vb
);
547 struct au0828_dev
*dev
= fh
->dev
;
548 int rc
= 0, urb_init
= 0;
550 buf
->vb
.size
= (fh
->dev
->width
* fh
->dev
->height
* 16 + 7) >> 3;
552 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< buf
->vb
.size
)
555 buf
->vb
.width
= dev
->width
;
556 buf
->vb
.height
= dev
->height
;
557 buf
->vb
.field
= field
;
559 if (VIDEOBUF_NEEDS_INIT
== buf
->vb
.state
) {
560 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
562 printk(KERN_INFO
"videobuf_iolock failed\n");
567 if (!dev
->isoc_ctl
.num_bufs
)
571 rc
= au0828_init_isoc(dev
, AU0828_ISO_PACKETS_PER_URB
,
572 AU0828_MAX_ISO_BUFS
, dev
->max_pkt_size
,
575 printk(KERN_INFO
"au0828_init_isoc failed\n");
580 buf
->vb
.state
= VIDEOBUF_PREPARED
;
584 free_buffer(vq
, buf
);
589 buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
591 struct au0828_buffer
*buf
= container_of(vb
,
592 struct au0828_buffer
,
594 struct au0828_fh
*fh
= vq
->priv_data
;
595 struct au0828_dev
*dev
= fh
->dev
;
596 struct au0828_dmaqueue
*vidq
= &dev
->vidq
;
598 buf
->vb
.state
= VIDEOBUF_QUEUED
;
599 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
602 static void buffer_release(struct videobuf_queue
*vq
,
603 struct videobuf_buffer
*vb
)
605 struct au0828_buffer
*buf
= container_of(vb
,
606 struct au0828_buffer
,
609 free_buffer(vq
, buf
);
612 static struct videobuf_queue_ops au0828_video_qops
= {
613 .buf_setup
= buffer_setup
,
614 .buf_prepare
= buffer_prepare
,
615 .buf_queue
= buffer_queue
,
616 .buf_release
= buffer_release
,
619 /* ------------------------------------------------------------------
621 ------------------------------------------------------------------*/
623 static int au0828_i2s_init(struct au0828_dev
*dev
)
625 /* Enable i2s mode */
626 au0828_writereg(dev
, AU0828_AUDIOCTRL_50C
, 0x01);
631 * Auvitek au0828 analog stream enable
632 * Please set interface0 to AS5 before enable the stream
634 int au0828_analog_stream_enable(struct au0828_dev
*d
)
636 dprintk(1, "au0828_analog_stream_enable called\n");
637 au0828_writereg(d
, AU0828_SENSORCTRL_VBI_103
, 0x00);
638 au0828_writereg(d
, 0x106, 0x00);
640 au0828_writereg(d
, 0x110, 0x00);
641 au0828_writereg(d
, 0x111, 0x00);
642 au0828_writereg(d
, 0x114, 0xa0);
643 au0828_writereg(d
, 0x115, 0x05);
645 au0828_writereg(d
, 0x112, 0x02);
646 au0828_writereg(d
, 0x113, 0x00);
647 au0828_writereg(d
, 0x116, 0xf2);
648 au0828_writereg(d
, 0x117, 0x00);
649 au0828_writereg(d
, AU0828_SENSORCTRL_100
, 0xb3);
654 int au0828_analog_stream_disable(struct au0828_dev
*d
)
656 dprintk(1, "au0828_analog_stream_disable called\n");
657 au0828_writereg(d
, AU0828_SENSORCTRL_100
, 0x0);
661 void au0828_analog_stream_reset(struct au0828_dev
*dev
)
663 dprintk(1, "au0828_analog_stream_reset called\n");
664 au0828_writereg(dev
, AU0828_SENSORCTRL_100
, 0x0);
666 au0828_writereg(dev
, AU0828_SENSORCTRL_100
, 0xb3);
670 * Some operations needs to stop current streaming
672 static int au0828_stream_interrupt(struct au0828_dev
*dev
)
676 dev
->stream_state
= STREAM_INTERRUPT
;
677 if (dev
->dev_state
== DEV_DISCONNECTED
)
680 dev
->dev_state
= DEV_MISCONFIGURED
;
681 dprintk(1, "%s device is misconfigured!\n", __func__
);
688 * au0828_release_resources
689 * unregister v4l2 devices
691 void au0828_analog_unregister(struct au0828_dev
*dev
)
693 dprintk(1, "au0828_release_resources called\n");
694 mutex_lock(&au0828_sysfs_lock
);
697 list_del(&dev
->au0828list
);
698 video_unregister_device(dev
->vdev
);
701 video_unregister_device(dev
->vbi_dev
);
703 mutex_unlock(&au0828_sysfs_lock
);
707 /* Usage lock check functions */
708 static int res_get(struct au0828_fh
*fh
)
710 struct au0828_dev
*dev
= fh
->dev
;
713 /* This instance already has stream_on */
725 static int res_check(struct au0828_fh
*fh
)
727 return fh
->stream_on
;
730 static void res_free(struct au0828_fh
*fh
)
732 struct au0828_dev
*dev
= fh
->dev
;
738 static int au0828_v4l2_open(struct file
*filp
)
740 int minor
= video_devdata(filp
)->minor
;
742 struct au0828_dev
*h
, *dev
= NULL
;
743 struct au0828_fh
*fh
;
745 struct list_head
*list
;
747 list_for_each(list
, &au0828_devlist
) {
748 h
= list_entry(list
, struct au0828_dev
, au0828list
);
749 if (h
->vdev
->minor
== minor
) {
751 type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
753 #ifdef VBI_IS_WORKING
754 if (h
->vbi_dev
->minor
== minor
) {
756 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
764 fh
= kzalloc(sizeof(struct au0828_fh
), GFP_KERNEL
);
766 dprintk(1, "Failed allocate au0828_fh struct!\n");
772 filp
->private_data
= fh
;
774 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
&& dev
->users
== 0) {
775 /* set au0828 interface0 to AS5 here again */
776 ret
= usb_set_interface(dev
->usbdev
, 0, 5);
778 printk(KERN_INFO
"Au0828 can't set alternate to 5!\n");
781 dev
->width
= NTSC_STD_W
;
782 dev
->height
= NTSC_STD_H
;
783 dev
->frame_size
= dev
->width
* dev
->height
* 2;
784 dev
->field_size
= dev
->width
* dev
->height
;
785 dev
->bytesperline
= dev
->width
* 2;
787 au0828_analog_stream_enable(dev
);
788 au0828_analog_stream_reset(dev
);
790 /* If we were doing ac97 instead of i2s, it would go here...*/
791 au0828_i2s_init(dev
);
793 dev
->stream_state
= STREAM_OFF
;
794 dev
->dev_state
|= DEV_INITIALIZED
;
799 videobuf_queue_vmalloc_init(&fh
->vb_vidq
, &au0828_video_qops
,
800 NULL
, &dev
->slock
, fh
->type
,
801 V4L2_FIELD_INTERLACED
,
802 sizeof(struct au0828_buffer
), fh
);
807 static int au0828_v4l2_close(struct file
*filp
)
810 struct au0828_fh
*fh
= filp
->private_data
;
811 struct au0828_dev
*dev
= fh
->dev
;
813 mutex_lock(&dev
->lock
);
817 if (dev
->users
== 1) {
818 videobuf_stop(&fh
->vb_vidq
);
819 videobuf_mmap_free(&fh
->vb_vidq
);
821 if (dev
->dev_state
& DEV_DISCONNECTED
) {
822 au0828_analog_unregister(dev
);
823 mutex_unlock(&dev
->lock
);
828 au0828_analog_stream_disable(dev
);
830 au0828_uninit_isoc(dev
);
832 /* Save some power by putting tuner to sleep */
833 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_standby
);
835 /* When close the device, set the usb intf0 into alt0 to free
837 ret
= usb_set_interface(dev
->usbdev
, 0, 0);
839 printk(KERN_INFO
"Au0828 can't set alternate to 0!\n");
844 wake_up_interruptible_nr(&dev
->open
, 1);
845 mutex_unlock(&dev
->lock
);
849 static ssize_t
au0828_v4l2_read(struct file
*filp
, char __user
*buf
,
850 size_t count
, loff_t
*pos
)
852 struct au0828_fh
*fh
= filp
->private_data
;
853 struct au0828_dev
*dev
= fh
->dev
;
860 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
861 mutex_lock(&dev
->lock
);
863 mutex_unlock(&dev
->lock
);
865 if (unlikely(rc
< 0))
868 return videobuf_read_stream(&fh
->vb_vidq
, buf
, count
, pos
, 0,
869 filp
->f_flags
& O_NONBLOCK
);
874 static unsigned int au0828_v4l2_poll(struct file
*filp
, poll_table
*wait
)
876 struct au0828_fh
*fh
= filp
->private_data
;
877 struct au0828_dev
*dev
= fh
->dev
;
884 mutex_lock(&dev
->lock
);
886 mutex_unlock(&dev
->lock
);
888 if (unlikely(rc
< 0))
891 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= fh
->type
)
894 return videobuf_poll_stream(filp
, &fh
->vb_vidq
, wait
);
897 static int au0828_v4l2_mmap(struct file
*filp
, struct vm_area_struct
*vma
)
899 struct au0828_fh
*fh
= filp
->private_data
;
900 struct au0828_dev
*dev
= fh
->dev
;
907 mutex_lock(&dev
->lock
);
909 mutex_unlock(&dev
->lock
);
911 if (unlikely(rc
< 0))
914 rc
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
919 static int au0828_set_format(struct au0828_dev
*dev
, unsigned int cmd
,
920 struct v4l2_format
*format
)
923 int width
= format
->fmt
.pix
.width
;
924 int height
= format
->fmt
.pix
.height
;
925 unsigned int maxwidth
, maxheight
;
930 #ifdef VBI_IS_WORKING
931 if (format
->type
== V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
) {
932 dprintk(1, "VBI format set: to be supported!\n");
935 if (format
->type
== V4L2_BUF_TYPE_VBI_CAPTURE
)
938 if (format
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
941 /* If they are demanding a format other than the one we support,
942 bail out (tvtime asks for UYVY and then retries with YUYV) */
943 if (format
->fmt
.pix
.pixelformat
!= V4L2_PIX_FMT_UYVY
)
946 /* format->fmt.pix.width only support 720 and height 480 */
952 format
->fmt
.pix
.width
= width
;
953 format
->fmt
.pix
.height
= height
;
954 format
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_UYVY
;
955 format
->fmt
.pix
.bytesperline
= width
* 2;
956 format
->fmt
.pix
.sizeimage
= width
* height
* 2;
957 format
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
958 format
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
960 if (cmd
== VIDIOC_TRY_FMT
)
963 /* maybe set new image format, driver current only support 720*480 */
965 dev
->height
= height
;
966 dev
->frame_size
= width
* height
* 2;
967 dev
->field_size
= width
* height
;
968 dev
->bytesperline
= width
* 2;
970 if (dev
->stream_state
== STREAM_ON
) {
971 dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n");
972 ret
= au0828_stream_interrupt(dev
);
974 dprintk(1, "error interrupting video stream!\n");
979 /* set au0828 interface0 to AS5 here again */
980 ret
= usb_set_interface(dev
->usbdev
, 0, 5);
982 printk(KERN_INFO
"Au0828 can't set alt setting to 5!\n");
986 au0828_analog_stream_enable(dev
);
992 static int vidioc_queryctrl(struct file
*file
, void *priv
,
993 struct v4l2_queryctrl
*qc
)
995 struct au0828_fh
*fh
= priv
;
996 struct au0828_dev
*dev
= fh
->dev
;
997 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, queryctrl
, qc
);
1004 static int vidioc_querycap(struct file
*file
, void *priv
,
1005 struct v4l2_capability
*cap
)
1007 struct au0828_fh
*fh
= priv
;
1008 struct au0828_dev
*dev
= fh
->dev
;
1010 strlcpy(cap
->driver
, "au0828", sizeof(cap
->driver
));
1011 strlcpy(cap
->card
, dev
->board
.name
, sizeof(cap
->card
));
1012 strlcpy(cap
->bus_info
, dev
->v4l2_dev
.name
, sizeof(cap
->bus_info
));
1014 cap
->version
= AU0828_VERSION_CODE
;
1016 /*set the device capabilities */
1017 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
|
1018 #ifdef VBI_IS_WORKING
1019 V4L2_CAP_VBI_CAPTURE
|
1022 V4L2_CAP_READWRITE
|
1023 V4L2_CAP_STREAMING
|
1028 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
1029 struct v4l2_fmtdesc
*f
)
1034 f
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1035 strcpy(f
->description
, "Packed YUV2");
1038 f
->pixelformat
= V4L2_PIX_FMT_UYVY
;
1043 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
1044 struct v4l2_format
*f
)
1046 struct au0828_fh
*fh
= priv
;
1047 struct au0828_dev
*dev
= fh
->dev
;
1049 f
->fmt
.pix
.width
= dev
->width
;
1050 f
->fmt
.pix
.height
= dev
->height
;
1051 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_UYVY
;
1052 f
->fmt
.pix
.bytesperline
= dev
->bytesperline
;
1053 f
->fmt
.pix
.sizeimage
= dev
->frame_size
;
1054 f
->fmt
.pix
.colorspace
= V4L2_COLORSPACE_SMPTE170M
; /* NTSC/PAL */
1055 f
->fmt
.pix
.field
= V4L2_FIELD_INTERLACED
;
1059 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
1060 struct v4l2_format
*f
)
1062 struct au0828_fh
*fh
= priv
;
1063 struct au0828_dev
*dev
= fh
->dev
;
1065 return au0828_set_format(dev
, VIDIOC_TRY_FMT
, f
);
1068 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
1069 struct v4l2_format
*f
)
1071 struct au0828_fh
*fh
= priv
;
1072 struct au0828_dev
*dev
= fh
->dev
;
1075 if (videobuf_queue_is_busy(&fh
->vb_vidq
)) {
1076 printk(KERN_INFO
"%s queue busy\n", __func__
);
1081 if (dev
->stream_on
&& !fh
->stream_on
) {
1082 printk(KERN_INFO
"%s device in use by another fh\n", __func__
);
1087 return au0828_set_format(dev
, VIDIOC_S_FMT
, f
);
1092 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
* norm
)
1094 struct au0828_fh
*fh
= priv
;
1095 struct au0828_dev
*dev
= fh
->dev
;
1097 /* FIXME: when we support something other than NTSC, we are going to
1098 have to make the au0828 bridge adjust the size of its capture
1099 buffer, which is currently hardcoded at 720x480 */
1101 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, *norm
);
1105 static int vidioc_enum_input(struct file
*file
, void *priv
,
1106 struct v4l2_input
*input
)
1108 struct au0828_fh
*fh
= priv
;
1109 struct au0828_dev
*dev
= fh
->dev
;
1112 static const char *inames
[] = {
1113 [AU0828_VMUX_UNDEFINED
] = "Undefined",
1114 [AU0828_VMUX_COMPOSITE
] = "Composite",
1115 [AU0828_VMUX_SVIDEO
] = "S-Video",
1116 [AU0828_VMUX_CABLE
] = "Cable TV",
1117 [AU0828_VMUX_TELEVISION
] = "Television",
1118 [AU0828_VMUX_DVB
] = "DVB",
1119 [AU0828_VMUX_DEBUG
] = "tv debug"
1124 if (tmp
> AU0828_MAX_INPUT
)
1126 if (AUVI_INPUT(tmp
).type
== 0)
1130 strcpy(input
->name
, inames
[AUVI_INPUT(tmp
).type
]);
1131 if ((AUVI_INPUT(tmp
).type
== AU0828_VMUX_TELEVISION
) ||
1132 (AUVI_INPUT(tmp
).type
== AU0828_VMUX_CABLE
))
1133 input
->type
|= V4L2_INPUT_TYPE_TUNER
;
1135 input
->type
|= V4L2_INPUT_TYPE_CAMERA
;
1137 input
->std
= dev
->vdev
->tvnorms
;
1142 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
1144 struct au0828_fh
*fh
= priv
;
1145 struct au0828_dev
*dev
= fh
->dev
;
1146 *i
= dev
->ctrl_input
;
1150 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int index
)
1152 struct au0828_fh
*fh
= priv
;
1153 struct au0828_dev
*dev
= fh
->dev
;
1156 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__
,
1158 if (index
>= AU0828_MAX_INPUT
)
1160 if (AUVI_INPUT(index
).type
== 0)
1162 dev
->ctrl_input
= index
;
1164 switch (AUVI_INPUT(index
).type
) {
1165 case AU0828_VMUX_SVIDEO
:
1166 dev
->input_type
= AU0828_VMUX_SVIDEO
;
1168 case AU0828_VMUX_COMPOSITE
:
1169 dev
->input_type
= AU0828_VMUX_COMPOSITE
;
1171 case AU0828_VMUX_TELEVISION
:
1172 dev
->input_type
= AU0828_VMUX_TELEVISION
;
1175 dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n",
1176 AUVI_INPUT(index
).type
);
1180 v4l2_device_call_all(&dev
->v4l2_dev
, 0, video
, s_routing
,
1181 AUVI_INPUT(index
).vmux
, 0, 0);
1183 for (i
= 0; i
< AU0828_MAX_INPUT
; i
++) {
1185 if (AUVI_INPUT(i
).audio_setup
== NULL
)
1193 (AUVI_INPUT(i
).audio_setup
)(dev
, enable
);
1195 /* Make sure we leave it turned on if some
1196 other input is routed to this callback */
1197 if ((AUVI_INPUT(i
).audio_setup
) !=
1198 ((AUVI_INPUT(index
).audio_setup
))) {
1199 (AUVI_INPUT(i
).audio_setup
)(dev
, enable
);
1204 v4l2_device_call_all(&dev
->v4l2_dev
, 0, audio
, s_routing
,
1205 AUVI_INPUT(index
).amux
, 0, 0);
1209 static int vidioc_g_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1211 struct au0828_fh
*fh
= priv
;
1212 struct au0828_dev
*dev
= fh
->dev
;
1213 unsigned int index
= a
->index
;
1218 index
= dev
->ctrl_ainput
;
1220 strcpy(a
->name
, "Television");
1222 strcpy(a
->name
, "Line in");
1224 a
->capability
= V4L2_AUDCAP_STEREO
;
1229 static int vidioc_s_audio(struct file
*file
, void *priv
, struct v4l2_audio
*a
)
1231 struct au0828_fh
*fh
= priv
;
1232 struct au0828_dev
*dev
= fh
->dev
;
1233 if (a
->index
!= dev
->ctrl_ainput
)
1238 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
1239 struct v4l2_control
*ctrl
)
1241 struct au0828_fh
*fh
= priv
;
1242 struct au0828_dev
*dev
= fh
->dev
;
1244 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, g_ctrl
, ctrl
);
1249 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1250 struct v4l2_control
*ctrl
)
1252 struct au0828_fh
*fh
= priv
;
1253 struct au0828_dev
*dev
= fh
->dev
;
1254 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_ctrl
, ctrl
);
1258 static int vidioc_g_tuner(struct file
*file
, void *priv
, struct v4l2_tuner
*t
)
1260 struct au0828_fh
*fh
= priv
;
1261 struct au0828_dev
*dev
= fh
->dev
;
1266 strcpy(t
->name
, "Auvitek tuner");
1267 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, g_tuner
, t
);
1271 static int vidioc_s_tuner(struct file
*file
, void *priv
,
1272 struct v4l2_tuner
*t
)
1274 struct au0828_fh
*fh
= priv
;
1275 struct au0828_dev
*dev
= fh
->dev
;
1280 t
->type
= V4L2_TUNER_ANALOG_TV
;
1281 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_tuner
, t
);
1282 dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t
->signal
,
1288 static int vidioc_g_frequency(struct file
*file
, void *priv
,
1289 struct v4l2_frequency
*freq
)
1291 struct au0828_fh
*fh
= priv
;
1292 struct au0828_dev
*dev
= fh
->dev
;
1294 freq
->type
= V4L2_TUNER_ANALOG_TV
;
1295 freq
->frequency
= dev
->ctrl_freq
;
1299 static int vidioc_s_frequency(struct file
*file
, void *priv
,
1300 struct v4l2_frequency
*freq
)
1302 struct au0828_fh
*fh
= priv
;
1303 struct au0828_dev
*dev
= fh
->dev
;
1305 if (freq
->tuner
!= 0)
1307 if (freq
->type
!= V4L2_TUNER_ANALOG_TV
)
1310 dev
->ctrl_freq
= freq
->frequency
;
1312 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, freq
);
1314 au0828_analog_stream_reset(dev
);
1319 static int vidioc_g_chip_ident(struct file
*file
, void *priv
,
1320 struct v4l2_dbg_chip_ident
*chip
)
1322 struct au0828_fh
*fh
= priv
;
1323 struct au0828_dev
*dev
= fh
->dev
;
1324 chip
->ident
= V4L2_IDENT_NONE
;
1327 if (v4l2_chip_match_host(&chip
->match
)) {
1328 chip
->ident
= V4L2_IDENT_AU0828
;
1332 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, g_chip_ident
, chip
);
1333 if (chip
->ident
== V4L2_IDENT_NONE
)
1339 static int vidioc_cropcap(struct file
*file
, void *priv
,
1340 struct v4l2_cropcap
*cc
)
1342 struct au0828_fh
*fh
= priv
;
1343 struct au0828_dev
*dev
= fh
->dev
;
1345 if (cc
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1348 cc
->bounds
.left
= 0;
1350 cc
->bounds
.width
= dev
->width
;
1351 cc
->bounds
.height
= dev
->height
;
1353 cc
->defrect
= cc
->bounds
;
1355 cc
->pixelaspect
.numerator
= 54;
1356 cc
->pixelaspect
.denominator
= 59;
1361 static int vidioc_streamon(struct file
*file
, void *priv
,
1362 enum v4l2_buf_type type
)
1364 struct au0828_fh
*fh
= priv
;
1365 struct au0828_dev
*dev
= fh
->dev
;
1368 rc
= check_dev(dev
);
1372 if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1373 au0828_analog_stream_enable(dev
);
1374 v4l2_device_call_all(&dev
->v4l2_dev
, 0, video
, s_stream
, 1);
1377 mutex_lock(&dev
->lock
);
1380 if (likely(rc
>= 0))
1381 rc
= videobuf_streamon(&fh
->vb_vidq
);
1382 mutex_unlock(&dev
->lock
);
1387 static int vidioc_streamoff(struct file
*file
, void *priv
,
1388 enum v4l2_buf_type type
)
1390 struct au0828_fh
*fh
= priv
;
1391 struct au0828_dev
*dev
= fh
->dev
;
1396 rc
= check_dev(dev
);
1400 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1402 if (type
!= fh
->type
)
1405 if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1406 v4l2_device_call_all(&dev
->v4l2_dev
, 0, video
, s_stream
, 0);
1407 ret
= au0828_stream_interrupt(dev
);
1412 for (i
= 0; i
< AU0828_MAX_INPUT
; i
++) {
1413 if (AUVI_INPUT(i
).audio_setup
== NULL
)
1415 (AUVI_INPUT(i
).audio_setup
)(dev
, 0);
1418 mutex_lock(&dev
->lock
);
1419 videobuf_streamoff(&fh
->vb_vidq
);
1421 mutex_unlock(&dev
->lock
);
1426 #ifdef CONFIG_VIDEO_ADV_DEBUG
1427 static int vidioc_g_register(struct file
*file
, void *priv
,
1428 struct v4l2_dbg_register
*reg
)
1430 struct au0828_fh
*fh
= priv
;
1431 struct au0828_dev
*dev
= fh
->dev
;
1433 switch (reg
->match
.type
) {
1434 case V4L2_CHIP_MATCH_I2C_DRIVER
:
1435 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, g_register
, reg
);
1442 static int vidioc_s_register(struct file
*file
, void *priv
,
1443 struct v4l2_dbg_register
*reg
)
1445 struct au0828_fh
*fh
= priv
;
1446 struct au0828_dev
*dev
= fh
->dev
;
1448 switch (reg
->match
.type
) {
1449 case V4L2_CHIP_MATCH_I2C_DRIVER
:
1450 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_register
, reg
);
1459 static int vidioc_reqbufs(struct file
*file
, void *priv
,
1460 struct v4l2_requestbuffers
*rb
)
1462 struct au0828_fh
*fh
= priv
;
1463 struct au0828_dev
*dev
= fh
->dev
;
1466 rc
= check_dev(dev
);
1470 return videobuf_reqbufs(&fh
->vb_vidq
, rb
);
1473 static int vidioc_querybuf(struct file
*file
, void *priv
,
1474 struct v4l2_buffer
*b
)
1476 struct au0828_fh
*fh
= priv
;
1477 struct au0828_dev
*dev
= fh
->dev
;
1480 rc
= check_dev(dev
);
1484 return videobuf_querybuf(&fh
->vb_vidq
, b
);
1487 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1489 struct au0828_fh
*fh
= priv
;
1490 struct au0828_dev
*dev
= fh
->dev
;
1493 rc
= check_dev(dev
);
1497 return videobuf_qbuf(&fh
->vb_vidq
, b
);
1500 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
1502 struct au0828_fh
*fh
= priv
;
1503 struct au0828_dev
*dev
= fh
->dev
;
1506 rc
= check_dev(dev
);
1510 /* Workaround for a bug in the au0828 hardware design that sometimes
1511 results in the colorspace being inverted */
1512 if (dev
->greenscreen_detected
== 1) {
1513 dprintk(1, "Detected green frame. Resetting stream...\n");
1514 au0828_analog_stream_reset(dev
);
1515 dev
->greenscreen_detected
= 0;
1518 return videobuf_dqbuf(&fh
->vb_vidq
, b
, file
->f_flags
& O_NONBLOCK
);
1521 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1522 static int vidiocgmbuf(struct file
*file
, void *priv
, struct video_mbuf
*mbuf
)
1524 struct au0828_fh
*fh
= priv
;
1526 return videobuf_cgmbuf(&fh
->vb_vidq
, mbuf
, 8);
1530 static struct v4l2_file_operations au0828_v4l_fops
= {
1531 .owner
= THIS_MODULE
,
1532 .open
= au0828_v4l2_open
,
1533 .release
= au0828_v4l2_close
,
1534 .read
= au0828_v4l2_read
,
1535 .poll
= au0828_v4l2_poll
,
1536 .mmap
= au0828_v4l2_mmap
,
1537 .ioctl
= video_ioctl2
,
1540 static const struct v4l2_ioctl_ops video_ioctl_ops
= {
1541 .vidioc_querycap
= vidioc_querycap
,
1542 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1543 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1544 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1545 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1546 #ifdef VBI_IS_WORKING
1547 .vidioc_g_fmt_vbi_cap
= vidioc_g_fmt_vbi_cap
,
1548 .vidioc_try_fmt_vbi_cap
= vidioc_s_fmt_vbi_cap
,
1549 .vidioc_s_fmt_vbi_cap
= vidioc_s_fmt_vbi_cap
,
1551 .vidioc_g_audio
= vidioc_g_audio
,
1552 .vidioc_s_audio
= vidioc_s_audio
,
1553 .vidioc_cropcap
= vidioc_cropcap
,
1554 #ifdef VBI_IS_WORKING
1555 .vidioc_g_fmt_sliced_vbi_cap
= vidioc_g_fmt_sliced_vbi_cap
,
1556 .vidioc_try_fmt_sliced_vbi_cap
= vidioc_try_set_sliced_vbi_cap
,
1557 .vidioc_s_fmt_sliced_vbi_cap
= vidioc_try_set_sliced_vbi_cap
,
1559 .vidioc_reqbufs
= vidioc_reqbufs
,
1560 .vidioc_querybuf
= vidioc_querybuf
,
1561 .vidioc_qbuf
= vidioc_qbuf
,
1562 .vidioc_dqbuf
= vidioc_dqbuf
,
1563 .vidioc_s_std
= vidioc_s_std
,
1564 .vidioc_enum_input
= vidioc_enum_input
,
1565 .vidioc_g_input
= vidioc_g_input
,
1566 .vidioc_s_input
= vidioc_s_input
,
1567 .vidioc_queryctrl
= vidioc_queryctrl
,
1568 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1569 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1570 .vidioc_streamon
= vidioc_streamon
,
1571 .vidioc_streamoff
= vidioc_streamoff
,
1572 .vidioc_g_tuner
= vidioc_g_tuner
,
1573 .vidioc_s_tuner
= vidioc_s_tuner
,
1574 .vidioc_g_frequency
= vidioc_g_frequency
,
1575 .vidioc_s_frequency
= vidioc_s_frequency
,
1576 #ifdef CONFIG_VIDEO_ADV_DEBUG
1577 .vidioc_g_register
= vidioc_g_register
,
1578 .vidioc_s_register
= vidioc_s_register
,
1580 .vidioc_g_chip_ident
= vidioc_g_chip_ident
,
1581 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1582 .vidiocgmbuf
= vidiocgmbuf
,
1586 static const struct video_device au0828_video_template
= {
1587 .fops
= &au0828_v4l_fops
,
1588 .release
= video_device_release
,
1589 .ioctl_ops
= &video_ioctl_ops
,
1591 .tvnorms
= V4L2_STD_NTSC_M
,
1592 .current_norm
= V4L2_STD_NTSC_M
,
1595 /**************************************************************************/
1597 int au0828_analog_register(struct au0828_dev
*dev
,
1598 struct usb_interface
*interface
)
1600 int retval
= -ENOMEM
;
1601 struct usb_host_interface
*iface_desc
;
1602 struct usb_endpoint_descriptor
*endpoint
;
1605 dprintk(1, "au0828_analog_register called!\n");
1607 /* set au0828 usb interface0 to as5 */
1608 retval
= usb_set_interface(dev
->usbdev
,
1609 interface
->cur_altsetting
->desc
.bInterfaceNumber
, 5);
1611 printk(KERN_INFO
"Failure setting usb interface0 to as5\n");
1615 /* Figure out which endpoint has the isoc interface */
1616 iface_desc
= interface
->cur_altsetting
;
1617 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; i
++) {
1618 endpoint
= &iface_desc
->endpoint
[i
].desc
;
1619 if (((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1621 ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1622 == USB_ENDPOINT_XFER_ISOC
)) {
1624 /* we find our isoc in endpoint */
1625 u16 tmp
= le16_to_cpu(endpoint
->wMaxPacketSize
);
1626 dev
->max_pkt_size
= (tmp
& 0x07ff) *
1627 (((tmp
& 0x1800) >> 11) + 1);
1628 dev
->isoc_in_endpointaddr
= endpoint
->bEndpointAddress
;
1631 if (!(dev
->isoc_in_endpointaddr
)) {
1632 printk(KERN_INFO
"Could not locate isoc endpoint\n");
1637 init_waitqueue_head(&dev
->open
);
1638 spin_lock_init(&dev
->slock
);
1639 mutex_init(&dev
->lock
);
1641 INIT_LIST_HEAD(&dev
->vidq
.active
);
1642 INIT_LIST_HEAD(&dev
->vidq
.queued
);
1644 dev
->width
= NTSC_STD_W
;
1645 dev
->height
= NTSC_STD_H
;
1646 dev
->field_size
= dev
->width
* dev
->height
;
1647 dev
->frame_size
= dev
->field_size
<< 1;
1648 dev
->bytesperline
= dev
->width
<< 1;
1649 dev
->ctrl_ainput
= 0;
1651 /* allocate and fill v4l2 video struct */
1652 dev
->vdev
= video_device_alloc();
1653 if (NULL
== dev
->vdev
) {
1654 dprintk(1, "Can't allocate video_device.\n");
1658 #ifdef VBI_IS_WORKING
1659 dev
->vbi_dev
= video_device_alloc();
1660 if (NULL
== dev
->vbi_dev
) {
1661 dprintk(1, "Can't allocate vbi_device.\n");
1667 /* Fill the video capture device struct */
1668 *dev
->vdev
= au0828_video_template
;
1669 dev
->vdev
->parent
= &dev
->usbdev
->dev
;
1670 strcpy(dev
->vdev
->name
, "au0828a video");
1672 #ifdef VBI_IS_WORKING
1673 /* Setup the VBI device */
1674 *dev
->vbi_dev
= au0828_video_template
;
1675 dev
->vbi_dev
->parent
= &dev
->usbdev
->dev
;
1676 strcpy(dev
->vbi_dev
->name
, "au0828a vbi");
1679 list_add_tail(&dev
->au0828list
, &au0828_devlist
);
1681 /* Register the v4l2 device */
1682 retval
= video_register_device(dev
->vdev
, VFL_TYPE_GRABBER
, -1);
1684 dprintk(1, "unable to register video device (error = %d).\n",
1686 list_del(&dev
->au0828list
);
1687 video_device_release(dev
->vdev
);
1691 #ifdef VBI_IS_WORKING
1692 /* Register the vbi device */
1693 retval
= video_register_device(dev
->vbi_dev
, VFL_TYPE_VBI
, -1);
1695 dprintk(1, "unable to register vbi device (error = %d).\n",
1697 list_del(&dev
->au0828list
);
1698 video_device_release(dev
->vbi_dev
);
1699 video_device_release(dev
->vdev
);
1704 dprintk(1, "%s completed!\n", __func__
);