3 * device driver for philips saa7134 based TV cards
4 * video4linux video interface
6 * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
30 #include "saa7134-reg.h"
32 #include <media/v4l2-common.h>
34 /* Include V4L1 specific functions. Should be removed soon */
35 #include <linux/videodev.h>
37 /* ------------------------------------------------------------------ */
39 static unsigned int video_debug = 0;
40 static unsigned int gbuffers = 8;
41 static unsigned int noninterlaced = 0;
42 static unsigned int gbufsize = 720*576*4;
43 static unsigned int gbufsize_max = 720*576*4;
44 module_param(video_debug, int, 0644);
45 MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
46 module_param(gbuffers, int, 0444);
47 MODULE_PARM_DESC(gbuffers,"number of capture buffers, range 2-32");
48 module_param(noninterlaced, int, 0644);
49 MODULE_PARM_DESC(noninterlaced,"video input is noninterlaced");
51 #define dprintk(fmt, arg...) if (video_debug) \
52 printk(KERN_DEBUG "%s/video: " fmt, dev->name , ## arg)
54 /* ------------------------------------------------------------------ */
55 /* Defines for Video Output Port Register at address 0x191 */
57 /* Bit 0: VIP code T bit polarity */
59 #define VP_T_CODE_P_NON_INVERTED 0x00
60 #define VP_T_CODE_P_INVERTED 0x01
62 /* ------------------------------------------------------------------ */
63 /* Defines for Video Output Port Register at address 0x195 */
65 /* Bit 2: Video output clock delay control */
67 #define VP_CLK_CTRL2_NOT_DELAYED 0x00
68 #define VP_CLK_CTRL2_DELAYED 0x04
70 /* Bit 1: Video output clock invert control */
72 #define VP_CLK_CTRL1_NON_INVERTED 0x00
73 #define VP_CLK_CTRL1_INVERTED 0x02
75 /* ------------------------------------------------------------------ */
76 /* Defines for Video Output Port Register at address 0x196 */
78 /* Bits 2 to 0: VSYNC pin video vertical sync type */
80 #define VP_VS_TYPE_MASK 0x07
82 #define VP_VS_TYPE_OFF 0x00
83 #define VP_VS_TYPE_V123 0x01
84 #define VP_VS_TYPE_V_ITU 0x02
85 #define VP_VS_TYPE_VGATE_L 0x03
86 #define VP_VS_TYPE_RESERVED1 0x04
87 #define VP_VS_TYPE_RESERVED2 0x05
88 #define VP_VS_TYPE_F_ITU 0x06
89 #define VP_VS_TYPE_SC_FID 0x07
91 /* ------------------------------------------------------------------ */
92 /* data structs for video */
94 static int video_out[][9] = {
95 [CCIR656] = { 0x00, 0xb1, 0x00, 0xa1, 0x00, 0x04, 0x06, 0x00, 0x00 },
98 static struct saa7134_format formats[] = {
100 .name = "8 bpp gray",
101 .fourcc = V4L2_PIX_FMT_GREY,
105 .name = "15 bpp RGB, le",
106 .fourcc = V4L2_PIX_FMT_RGB555,
110 .name = "15 bpp RGB, be",
111 .fourcc = V4L2_PIX_FMT_RGB555X,
116 .name = "16 bpp RGB, le",
117 .fourcc = V4L2_PIX_FMT_RGB565,
121 .name = "16 bpp RGB, be",
122 .fourcc = V4L2_PIX_FMT_RGB565X,
127 .name = "24 bpp RGB, le",
128 .fourcc = V4L2_PIX_FMT_BGR24,
132 .name = "24 bpp RGB, be",
133 .fourcc = V4L2_PIX_FMT_RGB24,
138 .name = "32 bpp RGB, le",
139 .fourcc = V4L2_PIX_FMT_BGR32,
143 .name = "32 bpp RGB, be",
144 .fourcc = V4L2_PIX_FMT_RGB32,
150 .name = "4:2:2 packed, YUYV",
151 .fourcc = V4L2_PIX_FMT_YUYV,
157 .name = "4:2:2 packed, UYVY",
158 .fourcc = V4L2_PIX_FMT_UYVY,
163 .name = "4:2:2 planar, Y-Cb-Cr",
164 .fourcc = V4L2_PIX_FMT_YUV422P,
172 .name = "4:2:0 planar, Y-Cb-Cr",
173 .fourcc = V4L2_PIX_FMT_YUV420,
181 .name = "4:2:0 planar, Y-Cb-Cr",
182 .fourcc = V4L2_PIX_FMT_YVU420,
192 #define FORMATS ARRAY_SIZE(formats)
194 #define NORM_625_50 \
197 .video_v_start = 24, \
198 .video_v_stop = 311, \
199 .vbi_v_start_0 = 7, \
200 .vbi_v_stop_0 = 22, \
201 .vbi_v_start_1 = 319, \
204 #define NORM_525_60 \
207 .video_v_start = 23, \
208 .video_v_stop = 262, \
209 .vbi_v_start_0 = 10, \
210 .vbi_v_stop_0 = 21, \
211 .vbi_v_start_1 = 273, \
214 static struct saa7134_tvnorm tvnorms[] = {
216 .name = "PAL", /* autodetect */
220 .sync_control = 0x18,
221 .luma_control = 0x40,
222 .chroma_ctrl1 = 0x81,
224 .chroma_ctrl2 = 0x06,
229 .id = V4L2_STD_PAL_BG,
232 .sync_control = 0x18,
233 .luma_control = 0x40,
234 .chroma_ctrl1 = 0x81,
236 .chroma_ctrl2 = 0x06,
241 .id = V4L2_STD_PAL_I,
244 .sync_control = 0x18,
245 .luma_control = 0x40,
246 .chroma_ctrl1 = 0x81,
248 .chroma_ctrl2 = 0x06,
253 .id = V4L2_STD_PAL_DK,
256 .sync_control = 0x18,
257 .luma_control = 0x40,
258 .chroma_ctrl1 = 0x81,
260 .chroma_ctrl2 = 0x06,
268 .sync_control = 0x59,
269 .luma_control = 0x40,
270 .chroma_ctrl1 = 0x89,
272 .chroma_ctrl2 = 0x0e,
277 .id = V4L2_STD_SECAM,
280 .sync_control = 0x18, /* old: 0x58, */
281 .luma_control = 0x1b,
282 .chroma_ctrl1 = 0xd1,
284 .chroma_ctrl2 = 0x00,
289 .id = V4L2_STD_PAL_M,
292 .sync_control = 0x59,
293 .luma_control = 0x40,
294 .chroma_ctrl1 = 0xb9,
296 .chroma_ctrl2 = 0x0e,
301 .id = V4L2_STD_PAL_Nc,
304 .sync_control = 0x18,
305 .luma_control = 0x40,
306 .chroma_ctrl1 = 0xa1,
308 .chroma_ctrl2 = 0x06,
313 .id = V4L2_STD_PAL_60,
321 .vbi_v_start_1 = 273,
324 .sync_control = 0x18,
325 .luma_control = 0x40,
326 .chroma_ctrl1 = 0x81,
328 .chroma_ctrl2 = 0x06,
332 #define TVNORMS ARRAY_SIZE(tvnorms)
334 #define V4L2_CID_PRIVATE_INVERT (V4L2_CID_PRIVATE_BASE + 0)
335 #define V4L2_CID_PRIVATE_Y_ODD (V4L2_CID_PRIVATE_BASE + 1)
336 #define V4L2_CID_PRIVATE_Y_EVEN (V4L2_CID_PRIVATE_BASE + 2)
337 #define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 3)
338 #define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 4)
340 static const struct v4l2_queryctrl no_ctrl = {
342 .flags = V4L2_CTRL_FLAG_DISABLED,
344 static const struct v4l2_queryctrl video_ctrls[] = {
347 .id = V4L2_CID_BRIGHTNESS,
348 .name = "Brightness",
352 .default_value = 128,
353 .type = V4L2_CTRL_TYPE_INTEGER,
355 .id = V4L2_CID_CONTRAST,
361 .type = V4L2_CTRL_TYPE_INTEGER,
363 .id = V4L2_CID_SATURATION,
364 .name = "Saturation",
369 .type = V4L2_CTRL_TYPE_INTEGER,
377 .type = V4L2_CTRL_TYPE_INTEGER,
379 .id = V4L2_CID_HFLIP,
383 .type = V4L2_CTRL_TYPE_BOOLEAN,
387 .id = V4L2_CID_AUDIO_MUTE,
391 .type = V4L2_CTRL_TYPE_BOOLEAN,
393 .id = V4L2_CID_AUDIO_VOLUME,
399 .type = V4L2_CTRL_TYPE_INTEGER,
401 /* --- private --- */
403 .id = V4L2_CID_PRIVATE_INVERT,
407 .type = V4L2_CTRL_TYPE_BOOLEAN,
409 .id = V4L2_CID_PRIVATE_Y_ODD,
410 .name = "y offset odd field",
414 .type = V4L2_CTRL_TYPE_INTEGER,
416 .id = V4L2_CID_PRIVATE_Y_EVEN,
417 .name = "y offset even field",
421 .type = V4L2_CTRL_TYPE_INTEGER,
423 .id = V4L2_CID_PRIVATE_AUTOMUTE,
428 .type = V4L2_CTRL_TYPE_BOOLEAN,
431 static const unsigned int CTRLS = ARRAY_SIZE(video_ctrls);
433 static const struct v4l2_queryctrl* ctrl_by_id(unsigned int id)
437 for (i = 0; i < CTRLS; i++)
438 if (video_ctrls[i].id == id)
439 return video_ctrls+i;
443 static struct saa7134_format* format_by_fourcc(unsigned int fourcc)
447 for (i = 0; i < FORMATS; i++)
448 if (formats[i].fourcc == fourcc)
453 /* ----------------------------------------------------------------------- */
454 /* resource management */
456 static int res_get(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bit)
458 if (fh->resources & bit)
459 /* have it already allocated */
464 if (dev->resources & bit) {
465 /* no, someone else uses it */
469 /* it's free, grab it */
470 fh->resources |= bit;
471 dev->resources |= bit;
472 dprintk("res: get %d\n",bit);
478 int res_check(struct saa7134_fh *fh, unsigned int bit)
480 return (fh->resources & bit);
484 int res_locked(struct saa7134_dev *dev, unsigned int bit)
486 return (dev->resources & bit);
490 void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
492 if ((fh->resources & bits) != bits)
496 fh->resources &= ~bits;
497 dev->resources &= ~bits;
498 dprintk("res: put %d\n",bits);
502 /* ------------------------------------------------------------------ */
504 static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
506 int luma_control,sync_control,mux;
508 dprintk("set tv norm = %s\n",norm->name);
511 mux = card_in(dev,dev->ctl_input).vmux;
512 luma_control = norm->luma_control;
513 sync_control = norm->sync_control;
516 luma_control |= 0x80; /* svideo */
517 if (noninterlaced || dev->nosignal)
518 sync_control |= 0x20;
521 dev->crop_bounds.left = norm->h_start;
522 dev->crop_defrect.left = norm->h_start;
523 dev->crop_bounds.width = norm->h_stop - norm->h_start +1;
524 dev->crop_defrect.width = norm->h_stop - norm->h_start +1;
526 dev->crop_bounds.top = (norm->vbi_v_stop_0+1)*2;
527 dev->crop_defrect.top = norm->video_v_start*2;
528 dev->crop_bounds.height = ((norm->id & V4L2_STD_525_60) ? 524 : 624)
529 - dev->crop_bounds.top;
530 dev->crop_defrect.height = (norm->video_v_stop - norm->video_v_start +1)*2;
532 dev->crop_current = dev->crop_defrect;
534 /* setup video decoder */
535 saa_writeb(SAA7134_INCR_DELAY, 0x08);
536 saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux);
537 saa_writeb(SAA7134_ANALOG_IN_CTRL2, 0x00);
539 saa_writeb(SAA7134_ANALOG_IN_CTRL3, 0x90);
540 saa_writeb(SAA7134_ANALOG_IN_CTRL4, 0x90);
541 saa_writeb(SAA7134_HSYNC_START, 0xeb);
542 saa_writeb(SAA7134_HSYNC_STOP, 0xe0);
543 saa_writeb(SAA7134_SOURCE_TIMING1, norm->src_timing);
545 saa_writeb(SAA7134_SYNC_CTRL, sync_control);
546 saa_writeb(SAA7134_LUMA_CTRL, luma_control);
547 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
548 saa_writeb(SAA7134_DEC_LUMA_CONTRAST, dev->ctl_contrast);
550 saa_writeb(SAA7134_DEC_CHROMA_SATURATION, dev->ctl_saturation);
551 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
552 saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1);
553 saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain);
555 saa_writeb(SAA7134_CHROMA_CTRL2, norm->chroma_ctrl2);
556 saa_writeb(SAA7134_MODE_DELAY_CTRL, 0x00);
558 saa_writeb(SAA7134_ANALOG_ADC, 0x01);
559 saa_writeb(SAA7134_VGATE_START, 0x11);
560 saa_writeb(SAA7134_VGATE_STOP, 0xfe);
561 saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc);
562 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40);
563 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80);
565 saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id);
568 static void video_mux(struct saa7134_dev *dev, int input)
570 dprintk("video input = %d [%s]\n",input,card_in(dev,input).name);
571 dev->ctl_input = input;
572 set_tvnorm(dev,dev->tvnorm);
573 saa7134_tvaudio_setinput(dev,&card_in(dev,input));
576 static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
578 static const struct {
585 /* XPSC XACL XC2_1 XDCG VPFY */
597 static const int count = ARRAY_SIZE(vals);
600 for (i = 0; i < count; i++)
601 if (vals[i].xpsc == prescale)
606 saa_writeb(SAA7134_H_PRESCALE(task), vals[i].xpsc);
607 saa_writeb(SAA7134_ACC_LENGTH(task), vals[i].xacl);
608 saa_writeb(SAA7134_LEVEL_CTRL(task),
609 (vals[i].xc2_1 << 3) | (vals[i].xdcg));
610 saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task), 0x0f,
611 (vals[i].vpfy << 2) | vals[i].vpfy);
614 static void set_v_scale(struct saa7134_dev *dev, int task, int yscale)
618 saa_writeb(SAA7134_V_SCALE_RATIO1(task), yscale & 0xff);
619 saa_writeb(SAA7134_V_SCALE_RATIO2(task), yscale >> 8);
621 mirror = (dev->ctl_mirror) ? 0x02 : 0x00;
624 dprintk("yscale LPI yscale=%d\n",yscale);
625 saa_writeb(SAA7134_V_FILTER(task), 0x00 | mirror);
626 saa_writeb(SAA7134_LUMA_CONTRAST(task), 0x40);
627 saa_writeb(SAA7134_CHROMA_SATURATION(task), 0x40);
630 val = 0x40 * 1024 / yscale;
631 dprintk("yscale ACM yscale=%d val=0x%x\n",yscale,val);
632 saa_writeb(SAA7134_V_FILTER(task), 0x01 | mirror);
633 saa_writeb(SAA7134_LUMA_CONTRAST(task), val);
634 saa_writeb(SAA7134_CHROMA_SATURATION(task), val);
636 saa_writeb(SAA7134_LUMA_BRIGHT(task), 0x80);
639 static void set_size(struct saa7134_dev *dev, int task,
640 int width, int height, int interlace)
642 int prescale,xscale,yscale,y_even,y_odd;
643 int h_start, h_stop, v_start, v_stop;
644 int div = interlace ? 2 : 1;
646 /* setup video scaler */
647 h_start = dev->crop_current.left;
648 v_start = dev->crop_current.top/2;
649 h_stop = (dev->crop_current.left + dev->crop_current.width -1);
650 v_stop = (dev->crop_current.top + dev->crop_current.height -1)/2;
652 saa_writeb(SAA7134_VIDEO_H_START1(task), h_start & 0xff);
653 saa_writeb(SAA7134_VIDEO_H_START2(task), h_start >> 8);
654 saa_writeb(SAA7134_VIDEO_H_STOP1(task), h_stop & 0xff);
655 saa_writeb(SAA7134_VIDEO_H_STOP2(task), h_stop >> 8);
656 saa_writeb(SAA7134_VIDEO_V_START1(task), v_start & 0xff);
657 saa_writeb(SAA7134_VIDEO_V_START2(task), v_start >> 8);
658 saa_writeb(SAA7134_VIDEO_V_STOP1(task), v_stop & 0xff);
659 saa_writeb(SAA7134_VIDEO_V_STOP2(task), v_stop >> 8);
661 prescale = dev->crop_current.width / width;
664 xscale = 1024 * dev->crop_current.width / prescale / width;
665 yscale = 512 * div * dev->crop_current.height / height;
666 dprintk("prescale=%d xscale=%d yscale=%d\n",prescale,xscale,yscale);
667 set_h_prescale(dev,task,prescale);
668 saa_writeb(SAA7134_H_SCALE_INC1(task), xscale & 0xff);
669 saa_writeb(SAA7134_H_SCALE_INC2(task), xscale >> 8);
670 set_v_scale(dev,task,yscale);
672 saa_writeb(SAA7134_VIDEO_PIXELS1(task), width & 0xff);
673 saa_writeb(SAA7134_VIDEO_PIXELS2(task), width >> 8);
674 saa_writeb(SAA7134_VIDEO_LINES1(task), height/div & 0xff);
675 saa_writeb(SAA7134_VIDEO_LINES2(task), height/div >> 8);
677 /* deinterlace y offsets */
678 y_odd = dev->ctl_y_odd;
679 y_even = dev->ctl_y_even;
680 saa_writeb(SAA7134_V_PHASE_OFFSET0(task), y_odd);
681 saa_writeb(SAA7134_V_PHASE_OFFSET1(task), y_even);
682 saa_writeb(SAA7134_V_PHASE_OFFSET2(task), y_odd);
683 saa_writeb(SAA7134_V_PHASE_OFFSET3(task), y_even);
686 /* ------------------------------------------------------------------ */
694 static void sort_cliplist(struct cliplist *cl, int entries)
696 struct cliplist swap;
699 for (i = entries-2; i >= 0; i--) {
700 for (n = 0, j = 0; j <= i; j++) {
701 if (cl[j].position > cl[j+1].position) {
713 static void set_cliplist(struct saa7134_dev *dev, int reg,
714 struct cliplist *cl, int entries, char *name)
719 for (i = 0; i < entries; i++) {
720 winbits |= cl[i].enable;
721 winbits &= ~cl[i].disable;
722 if (i < 15 && cl[i].position == cl[i+1].position)
724 saa_writeb(reg + 0, winbits);
725 saa_writeb(reg + 2, cl[i].position & 0xff);
726 saa_writeb(reg + 3, cl[i].position >> 8);
727 dprintk("clip: %s winbits=%02x pos=%d\n",
728 name,winbits,cl[i].position);
731 for (; reg < 0x400; reg += 8) {
732 saa_writeb(reg+ 0, 0);
733 saa_writeb(reg + 1, 0);
734 saa_writeb(reg + 2, 0);
735 saa_writeb(reg + 3, 0);
739 static int clip_range(int val)
746 static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
747 int nclips, int interlace)
749 struct cliplist col[16], row[16];
751 int div = interlace ? 2 : 1;
753 memset(col,0,sizeof(col)); cols = 0;
754 memset(row,0,sizeof(row)); rows = 0;
755 for (i = 0; i < nclips && i < 8; i++) {
756 col[cols].position = clip_range(clips[i].c.left);
757 col[cols].enable = (1 << i);
759 col[cols].position = clip_range(clips[i].c.left+clips[i].c.width);
760 col[cols].disable = (1 << i);
762 row[rows].position = clip_range(clips[i].c.top / div);
763 row[rows].enable = (1 << i);
765 row[rows].position = clip_range((clips[i].c.top + clips[i].c.height)
767 row[rows].disable = (1 << i);
770 sort_cliplist(col,cols);
771 sort_cliplist(row,rows);
772 set_cliplist(dev,0x380,col,cols,"cols");
773 set_cliplist(dev,0x384,row,rows,"rows");
777 static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win)
779 enum v4l2_field field;
782 if (NULL == dev->ovbuf.base)
784 if (NULL == dev->ovfmt)
786 if (win->w.width < 48 || win->w.height < 32)
788 if (win->clipcount > 2048)
792 maxw = dev->crop_current.width;
793 maxh = dev->crop_current.height;
795 if (V4L2_FIELD_ANY == field) {
796 field = (win->w.height > maxh/2)
797 ? V4L2_FIELD_INTERLACED
802 case V4L2_FIELD_BOTTOM:
805 case V4L2_FIELD_INTERLACED:
812 if (win->w.width > maxw)
814 if (win->w.height > maxh)
815 win->w.height = maxh;
819 static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
821 unsigned long base,control,bpl;
824 err = verify_preview(dev,&fh->win);
828 dev->ovfield = fh->win.field;
829 dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
830 fh->win.w.width,fh->win.w.height,
831 fh->win.w.left,fh->win.w.top,
832 dev->ovfmt->name,v4l2_field_names[dev->ovfield]);
834 /* setup window + clipping */
835 set_size(dev,TASK_B,fh->win.w.width,fh->win.w.height,
836 V4L2_FIELD_HAS_BOTH(dev->ovfield));
837 setup_clipping(dev,fh->clips,fh->nclips,
838 V4L2_FIELD_HAS_BOTH(dev->ovfield));
840 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03);
842 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x01);
843 saa_writeb(SAA7134_OFMT_VIDEO_B, dev->ovfmt->pm | 0x20);
845 /* dma: setup channel 1 (= Video Task B) */
846 base = (unsigned long)dev->ovbuf.base;
847 base += dev->ovbuf.fmt.bytesperline * fh->win.w.top;
848 base += dev->ovfmt->depth/8 * fh->win.w.left;
849 bpl = dev->ovbuf.fmt.bytesperline;
850 control = SAA7134_RS_CONTROL_BURST_16;
851 if (dev->ovfmt->bswap)
852 control |= SAA7134_RS_CONTROL_BSWAP;
853 if (dev->ovfmt->wswap)
854 control |= SAA7134_RS_CONTROL_WSWAP;
855 if (V4L2_FIELD_HAS_BOTH(dev->ovfield)) {
856 saa_writel(SAA7134_RS_BA1(1),base);
857 saa_writel(SAA7134_RS_BA2(1),base+bpl);
858 saa_writel(SAA7134_RS_PITCH(1),bpl*2);
859 saa_writel(SAA7134_RS_CONTROL(1),control);
861 saa_writel(SAA7134_RS_BA1(1),base);
862 saa_writel(SAA7134_RS_BA2(1),base);
863 saa_writel(SAA7134_RS_PITCH(1),bpl);
864 saa_writel(SAA7134_RS_CONTROL(1),control);
869 saa7134_set_dmabits(dev);
874 static int stop_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
877 saa7134_set_dmabits(dev);
881 /* ------------------------------------------------------------------ */
883 static int buffer_activate(struct saa7134_dev *dev,
884 struct saa7134_buf *buf,
885 struct saa7134_buf *next)
887 unsigned long base,control,bpl;
888 unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
890 dprintk("buffer_activate buf=%p\n",buf);
891 buf->vb.state = STATE_ACTIVE;
894 set_size(dev,TASK_A,buf->vb.width,buf->vb.height,
895 V4L2_FIELD_HAS_BOTH(buf->vb.field));
897 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x03);
899 saa_andorb(SAA7134_DATA_PATH(TASK_A), 0x3f, 0x01);
900 saa_writeb(SAA7134_OFMT_VIDEO_A, buf->fmt->pm);
902 /* DMA: setup channel 0 (= Video Task A0) */
903 base = saa7134_buffer_base(buf);
904 if (buf->fmt->planar)
907 bpl = (buf->vb.width * buf->fmt->depth) / 8;
908 control = SAA7134_RS_CONTROL_BURST_16 |
909 SAA7134_RS_CONTROL_ME |
910 (buf->pt->dma >> 12);
912 control |= SAA7134_RS_CONTROL_BSWAP;
914 control |= SAA7134_RS_CONTROL_WSWAP;
915 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
917 saa_writel(SAA7134_RS_BA1(0),base);
918 saa_writel(SAA7134_RS_BA2(0),base+bpl);
919 saa_writel(SAA7134_RS_PITCH(0),bpl*2);
922 saa_writel(SAA7134_RS_BA1(0),base);
923 saa_writel(SAA7134_RS_BA2(0),base);
924 saa_writel(SAA7134_RS_PITCH(0),bpl);
926 saa_writel(SAA7134_RS_CONTROL(0),control);
928 if (buf->fmt->planar) {
929 /* DMA: setup channel 4+5 (= planar task A) */
930 bpl_uv = bpl >> buf->fmt->hshift;
931 lines_uv = buf->vb.height >> buf->fmt->vshift;
932 base2 = base + bpl * buf->vb.height;
933 base3 = base2 + bpl_uv * lines_uv;
934 if (buf->fmt->uvswap)
935 tmp = base2, base2 = base3, base3 = tmp;
936 dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
937 bpl_uv,lines_uv,base2,base3);
938 if (V4L2_FIELD_HAS_BOTH(buf->vb.field)) {
940 saa_writel(SAA7134_RS_BA1(4),base2);
941 saa_writel(SAA7134_RS_BA2(4),base2+bpl_uv);
942 saa_writel(SAA7134_RS_PITCH(4),bpl_uv*2);
943 saa_writel(SAA7134_RS_BA1(5),base3);
944 saa_writel(SAA7134_RS_BA2(5),base3+bpl_uv);
945 saa_writel(SAA7134_RS_PITCH(5),bpl_uv*2);
948 saa_writel(SAA7134_RS_BA1(4),base2);
949 saa_writel(SAA7134_RS_BA2(4),base2);
950 saa_writel(SAA7134_RS_PITCH(4),bpl_uv);
951 saa_writel(SAA7134_RS_BA1(5),base3);
952 saa_writel(SAA7134_RS_BA2(5),base3);
953 saa_writel(SAA7134_RS_PITCH(5),bpl_uv);
955 saa_writel(SAA7134_RS_CONTROL(4),control);
956 saa_writel(SAA7134_RS_CONTROL(5),control);
960 saa7134_set_dmabits(dev);
961 mod_timer(&dev->video_q.timeout, jiffies+BUFFER_TIMEOUT);
965 static int buffer_prepare(struct videobuf_queue *q,
966 struct videobuf_buffer *vb,
967 enum v4l2_field field)
969 struct saa7134_fh *fh = q->priv_data;
970 struct saa7134_dev *dev = fh->dev;
971 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
978 if (fh->width < 48 ||
980 fh->width/4 > dev->crop_current.width ||
981 fh->height/4 > dev->crop_current.height ||
982 fh->width > dev->crop_bounds.width ||
983 fh->height > dev->crop_bounds.height)
985 size = (fh->width * fh->height * fh->fmt->depth) >> 3;
986 if (0 != buf->vb.baddr && buf->vb.bsize < size)
989 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
990 vb->i,fh->width,fh->height,size,v4l2_field_names[field],
992 if (buf->vb.width != fh->width ||
993 buf->vb.height != fh->height ||
994 buf->vb.size != size ||
995 buf->vb.field != field ||
996 buf->fmt != fh->fmt) {
997 saa7134_dma_free(dev,buf);
1000 if (STATE_NEEDS_INIT == buf->vb.state) {
1001 buf->vb.width = fh->width;
1002 buf->vb.height = fh->height;
1003 buf->vb.size = size;
1004 buf->vb.field = field;
1006 buf->pt = &fh->pt_cap;
1008 err = videobuf_iolock(dev->pci,&buf->vb,&dev->ovbuf);
1011 err = saa7134_pgtable_build(dev->pci,buf->pt,
1014 saa7134_buffer_startpage(buf));
1018 buf->vb.state = STATE_PREPARED;
1019 buf->activate = buffer_activate;
1023 saa7134_dma_free(dev,buf);
1028 buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
1030 struct saa7134_fh *fh = q->priv_data;
1032 *size = fh->fmt->depth * fh->width * fh->height >> 3;
1035 *count = saa7134_buffer_count(*size,*count);
1039 static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
1041 struct saa7134_fh *fh = q->priv_data;
1042 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1044 saa7134_buffer_queue(fh->dev,&fh->dev->video_q,buf);
1047 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
1049 struct saa7134_fh *fh = q->priv_data;
1050 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
1052 saa7134_dma_free(fh->dev,buf);
1055 static struct videobuf_queue_ops video_qops = {
1056 .buf_setup = buffer_setup,
1057 .buf_prepare = buffer_prepare,
1058 .buf_queue = buffer_queue,
1059 .buf_release = buffer_release,
1062 /* ------------------------------------------------------------------ */
1064 static int get_control(struct saa7134_dev *dev, struct v4l2_control *c)
1066 const struct v4l2_queryctrl* ctrl;
1068 ctrl = ctrl_by_id(c->id);
1072 case V4L2_CID_BRIGHTNESS:
1073 c->value = dev->ctl_bright;
1076 c->value = dev->ctl_hue;
1078 case V4L2_CID_CONTRAST:
1079 c->value = dev->ctl_contrast;
1081 case V4L2_CID_SATURATION:
1082 c->value = dev->ctl_saturation;
1084 case V4L2_CID_AUDIO_MUTE:
1085 c->value = dev->ctl_mute;
1087 case V4L2_CID_AUDIO_VOLUME:
1088 c->value = dev->ctl_volume;
1090 case V4L2_CID_PRIVATE_INVERT:
1091 c->value = dev->ctl_invert;
1093 case V4L2_CID_HFLIP:
1094 c->value = dev->ctl_mirror;
1096 case V4L2_CID_PRIVATE_Y_EVEN:
1097 c->value = dev->ctl_y_even;
1099 case V4L2_CID_PRIVATE_Y_ODD:
1100 c->value = dev->ctl_y_odd;
1102 case V4L2_CID_PRIVATE_AUTOMUTE:
1103 c->value = dev->ctl_automute;
1111 static int set_control(struct saa7134_dev *dev, struct saa7134_fh *fh,
1112 struct v4l2_control *c)
1114 const struct v4l2_queryctrl* ctrl;
1115 unsigned long flags;
1116 int restart_overlay = 0;
1118 ctrl = ctrl_by_id(c->id);
1121 dprintk("set_control name=%s val=%d\n",ctrl->name,c->value);
1122 switch (ctrl->type) {
1123 case V4L2_CTRL_TYPE_BOOLEAN:
1124 case V4L2_CTRL_TYPE_MENU:
1125 case V4L2_CTRL_TYPE_INTEGER:
1126 if (c->value < ctrl->minimum)
1127 c->value = ctrl->minimum;
1128 if (c->value > ctrl->maximum)
1129 c->value = ctrl->maximum;
1135 case V4L2_CID_BRIGHTNESS:
1136 dev->ctl_bright = c->value;
1137 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
1140 dev->ctl_hue = c->value;
1141 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
1143 case V4L2_CID_CONTRAST:
1144 dev->ctl_contrast = c->value;
1145 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1146 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1148 case V4L2_CID_SATURATION:
1149 dev->ctl_saturation = c->value;
1150 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1151 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1153 case V4L2_CID_AUDIO_MUTE:
1154 dev->ctl_mute = c->value;
1155 saa7134_tvaudio_setmute(dev);
1157 case V4L2_CID_AUDIO_VOLUME:
1158 dev->ctl_volume = c->value;
1159 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
1161 case V4L2_CID_PRIVATE_INVERT:
1162 dev->ctl_invert = c->value;
1163 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
1164 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
1165 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
1166 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
1168 case V4L2_CID_HFLIP:
1169 dev->ctl_mirror = c->value;
1170 restart_overlay = 1;
1172 case V4L2_CID_PRIVATE_Y_EVEN:
1173 dev->ctl_y_even = c->value;
1174 restart_overlay = 1;
1176 case V4L2_CID_PRIVATE_Y_ODD:
1177 dev->ctl_y_odd = c->value;
1178 restart_overlay = 1;
1180 case V4L2_CID_PRIVATE_AUTOMUTE:
1181 dev->ctl_automute = c->value;
1182 if (dev->tda9887_conf) {
1183 if (dev->ctl_automute)
1184 dev->tda9887_conf |= TDA9887_AUTOMUTE;
1186 dev->tda9887_conf &= ~TDA9887_AUTOMUTE;
1187 saa7134_i2c_call_clients(dev, TDA9887_SET_CONFIG,
1188 &dev->tda9887_conf);
1194 if (restart_overlay && fh && res_check(fh, RESOURCE_OVERLAY)) {
1195 spin_lock_irqsave(&dev->slock,flags);
1196 stop_preview(dev,fh);
1197 start_preview(dev,fh);
1198 spin_unlock_irqrestore(&dev->slock,flags);
1203 /* ------------------------------------------------------------------ */
1205 static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh)
1207 struct videobuf_queue* q = NULL;
1210 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1213 case V4L2_BUF_TYPE_VBI_CAPTURE:
1222 static int saa7134_resource(struct saa7134_fh *fh)
1227 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1228 res = RESOURCE_VIDEO;
1230 case V4L2_BUF_TYPE_VBI_CAPTURE:
1239 static int video_open(struct inode *inode, struct file *file)
1241 int minor = iminor(inode);
1242 struct saa7134_dev *h,*dev = NULL;
1243 struct saa7134_fh *fh;
1244 struct list_head *list;
1245 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1247 list_for_each(list,&saa7134_devlist) {
1248 h = list_entry(list, struct saa7134_dev, devlist);
1249 if (h->video_dev && (h->video_dev->minor == minor))
1251 if (h->radio_dev && (h->radio_dev->minor == minor)) {
1255 if (h->vbi_dev && (h->vbi_dev->minor == minor)) {
1256 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1263 dprintk("open minor=%d radio=%d type=%s\n",minor,radio,
1264 v4l2_type_names[type]);
1266 /* allocate + initialize per filehandle data */
1267 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1270 file->private_data = fh;
1274 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
1277 v4l2_prio_open(&dev->prio,&fh->prio);
1279 videobuf_queue_init(&fh->cap, &video_qops,
1280 dev->pci, &dev->slock,
1281 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1282 V4L2_FIELD_INTERLACED,
1283 sizeof(struct saa7134_buf),
1285 videobuf_queue_init(&fh->vbi, &saa7134_vbi_qops,
1286 dev->pci, &dev->slock,
1287 V4L2_BUF_TYPE_VBI_CAPTURE,
1289 sizeof(struct saa7134_buf),
1291 saa7134_pgtable_alloc(dev->pci,&fh->pt_cap);
1292 saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi);
1295 /* switch to radio mode */
1296 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1297 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO, NULL);
1299 /* switch to video/vbi mode */
1300 video_mux(dev,dev->ctl_input);
1306 video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1308 struct saa7134_fh *fh = file->private_data;
1311 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1312 if (res_locked(fh->dev,RESOURCE_VIDEO))
1314 return videobuf_read_one(saa7134_queue(fh),
1316 file->f_flags & O_NONBLOCK);
1317 case V4L2_BUF_TYPE_VBI_CAPTURE:
1318 if (!res_get(fh->dev,fh,RESOURCE_VBI))
1320 return videobuf_read_stream(saa7134_queue(fh),
1321 data, count, ppos, 1,
1322 file->f_flags & O_NONBLOCK);
1331 video_poll(struct file *file, struct poll_table_struct *wait)
1333 struct saa7134_fh *fh = file->private_data;
1334 struct videobuf_buffer *buf = NULL;
1336 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)
1337 return videobuf_poll_stream(file, &fh->vbi, wait);
1339 if (res_check(fh,RESOURCE_VIDEO)) {
1340 if (!list_empty(&fh->cap.stream))
1341 buf = list_entry(fh->cap.stream.next, struct videobuf_buffer, stream);
1343 down(&fh->cap.lock);
1344 if (UNSET == fh->cap.read_off) {
1345 /* need to capture a new frame */
1346 if (res_locked(fh->dev,RESOURCE_VIDEO)) {
1350 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,fh->cap.field)) {
1354 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
1355 fh->cap.read_off = 0;
1358 buf = fh->cap.read_buf;
1364 poll_wait(file, &buf->done, wait);
1365 if (buf->state == STATE_DONE ||
1366 buf->state == STATE_ERROR)
1367 return POLLIN|POLLRDNORM;
1371 static int video_release(struct inode *inode, struct file *file)
1373 struct saa7134_fh *fh = file->private_data;
1374 struct saa7134_dev *dev = fh->dev;
1375 unsigned long flags;
1377 /* turn off overlay */
1378 if (res_check(fh, RESOURCE_OVERLAY)) {
1379 spin_lock_irqsave(&dev->slock,flags);
1380 stop_preview(dev,fh);
1381 spin_unlock_irqrestore(&dev->slock,flags);
1382 res_free(dev,fh,RESOURCE_OVERLAY);
1385 /* stop video capture */
1386 if (res_check(fh, RESOURCE_VIDEO)) {
1387 videobuf_streamoff(&fh->cap);
1388 res_free(dev,fh,RESOURCE_VIDEO);
1390 if (fh->cap.read_buf) {
1391 buffer_release(&fh->cap,fh->cap.read_buf);
1392 kfree(fh->cap.read_buf);
1395 /* stop vbi capture */
1396 if (res_check(fh, RESOURCE_VBI)) {
1397 if (fh->vbi.streaming)
1398 videobuf_streamoff(&fh->vbi);
1399 if (fh->vbi.reading)
1400 videobuf_read_stop(&fh->vbi);
1401 res_free(dev,fh,RESOURCE_VBI);
1404 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1405 saa_andorb(SAA7134_OFMT_VIDEO_A, 0x1f, 0);
1406 saa_andorb(SAA7134_OFMT_VIDEO_B, 0x1f, 0);
1407 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1408 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1410 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1413 videobuf_mmap_free(&fh->cap);
1414 videobuf_mmap_free(&fh->vbi);
1415 saa7134_pgtable_free(dev->pci,&fh->pt_cap);
1416 saa7134_pgtable_free(dev->pci,&fh->pt_vbi);
1418 v4l2_prio_close(&dev->prio,&fh->prio);
1419 file->private_data = NULL;
1425 video_mmap(struct file *file, struct vm_area_struct * vma)
1427 struct saa7134_fh *fh = file->private_data;
1429 return videobuf_mmap_mapper(saa7134_queue(fh), vma);
1432 /* ------------------------------------------------------------------ */
1434 static void saa7134_vbi_fmt(struct saa7134_dev *dev, struct v4l2_format *f)
1436 struct saa7134_tvnorm *norm = dev->tvnorm;
1438 f->fmt.vbi.sampling_rate = 6750000 * 4;
1439 f->fmt.vbi.samples_per_line = 2048 /* VBI_LINE_LENGTH */;
1440 f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1441 f->fmt.vbi.offset = 64 * 4;
1442 f->fmt.vbi.start[0] = norm->vbi_v_start_0;
1443 f->fmt.vbi.count[0] = norm->vbi_v_stop_0 - norm->vbi_v_start_0 +1;
1444 f->fmt.vbi.start[1] = norm->vbi_v_start_1;
1445 f->fmt.vbi.count[1] = f->fmt.vbi.count[0];
1446 f->fmt.vbi.flags = 0; /* VBI_UNSYNC VBI_INTERLACED */
1450 static int saa7134_g_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1451 struct v4l2_format *f)
1454 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1455 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
1456 f->fmt.pix.width = fh->width;
1457 f->fmt.pix.height = fh->height;
1458 f->fmt.pix.field = fh->cap.field;
1459 f->fmt.pix.pixelformat = fh->fmt->fourcc;
1460 f->fmt.pix.bytesperline =
1461 (f->fmt.pix.width * fh->fmt->depth) >> 3;
1462 f->fmt.pix.sizeimage =
1463 f->fmt.pix.height * f->fmt.pix.bytesperline;
1465 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1466 f->fmt.win = fh->win;
1468 case V4L2_BUF_TYPE_VBI_CAPTURE:
1469 saa7134_vbi_fmt(dev,f);
1476 static int saa7134_try_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1477 struct v4l2_format *f)
1482 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1484 struct saa7134_format *fmt;
1485 enum v4l2_field field;
1486 unsigned int maxw, maxh;
1488 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1492 field = f->fmt.pix.field;
1493 maxw = min(dev->crop_current.width*4, dev->crop_bounds.width);
1494 maxh = min(dev->crop_current.height*4, dev->crop_bounds.height);
1496 if (V4L2_FIELD_ANY == field) {
1497 field = (f->fmt.pix.height > maxh/2)
1498 ? V4L2_FIELD_INTERLACED
1499 : V4L2_FIELD_BOTTOM;
1502 case V4L2_FIELD_TOP:
1503 case V4L2_FIELD_BOTTOM:
1506 case V4L2_FIELD_INTERLACED:
1512 f->fmt.pix.field = field;
1513 if (f->fmt.pix.width < 48)
1514 f->fmt.pix.width = 48;
1515 if (f->fmt.pix.height < 32)
1516 f->fmt.pix.height = 32;
1517 if (f->fmt.pix.width > maxw)
1518 f->fmt.pix.width = maxw;
1519 if (f->fmt.pix.height > maxh)
1520 f->fmt.pix.height = maxh;
1521 f->fmt.pix.width &= ~0x03;
1522 f->fmt.pix.bytesperline =
1523 (f->fmt.pix.width * fmt->depth) >> 3;
1524 f->fmt.pix.sizeimage =
1525 f->fmt.pix.height * f->fmt.pix.bytesperline;
1529 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1530 err = verify_preview(dev,&f->fmt.win);
1534 case V4L2_BUF_TYPE_VBI_CAPTURE:
1535 saa7134_vbi_fmt(dev,f);
1542 static int saa7134_s_fmt(struct saa7134_dev *dev, struct saa7134_fh *fh,
1543 struct v4l2_format *f)
1545 unsigned long flags;
1549 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1550 err = saa7134_try_fmt(dev,fh,f);
1554 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1555 fh->width = f->fmt.pix.width;
1556 fh->height = f->fmt.pix.height;
1557 fh->cap.field = f->fmt.pix.field;
1559 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1560 err = verify_preview(dev,&f->fmt.win);
1565 fh->win = f->fmt.win;
1566 fh->nclips = f->fmt.win.clipcount;
1569 if (copy_from_user(fh->clips,f->fmt.win.clips,
1570 sizeof(struct v4l2_clip)*fh->nclips)) {
1575 if (res_check(fh, RESOURCE_OVERLAY)) {
1576 spin_lock_irqsave(&dev->slock,flags);
1577 stop_preview(dev,fh);
1578 start_preview(dev,fh);
1579 spin_unlock_irqrestore(&dev->slock,flags);
1583 case V4L2_BUF_TYPE_VBI_CAPTURE:
1584 saa7134_vbi_fmt(dev,f);
1591 int saa7134_common_ioctl(struct saa7134_dev *dev,
1592 unsigned int cmd, void *arg)
1597 case VIDIOC_QUERYCTRL:
1599 const struct v4l2_queryctrl *ctrl;
1600 struct v4l2_queryctrl *c = arg;
1602 if ((c->id < V4L2_CID_BASE ||
1603 c->id >= V4L2_CID_LASTP1) &&
1604 (c->id < V4L2_CID_PRIVATE_BASE ||
1605 c->id >= V4L2_CID_PRIVATE_LASTP1))
1607 ctrl = ctrl_by_id(c->id);
1608 *c = (NULL != ctrl) ? *ctrl : no_ctrl;
1612 return get_control(dev,arg);
1616 err = set_control(dev,NULL,arg);
1620 /* --- input switching --------------------------------------- */
1621 case VIDIOC_ENUMINPUT:
1623 struct v4l2_input *i = arg;
1627 if (n >= SAA7134_INPUT_MAX)
1629 if (NULL == card_in(dev,i->index).name)
1631 memset(i,0,sizeof(*i));
1633 i->type = V4L2_INPUT_TYPE_CAMERA;
1634 strcpy(i->name,card_in(dev,n).name);
1635 if (card_in(dev,n).tv)
1636 i->type = V4L2_INPUT_TYPE_TUNER;
1638 if (n == dev->ctl_input) {
1639 int v1 = saa_readb(SAA7134_STATUS_VIDEO1);
1640 int v2 = saa_readb(SAA7134_STATUS_VIDEO2);
1642 if (0 != (v1 & 0x40))
1643 i->status |= V4L2_IN_ST_NO_H_LOCK;
1644 if (0 != (v2 & 0x40))
1645 i->status |= V4L2_IN_ST_NO_SYNC;
1646 if (0 != (v2 & 0x0e))
1647 i->status |= V4L2_IN_ST_MACROVISION;
1649 for (n = 0; n < TVNORMS; n++)
1650 i->std |= tvnorms[n].id;
1653 case VIDIOC_G_INPUT:
1656 *i = dev->ctl_input;
1659 case VIDIOC_S_INPUT:
1663 if (*i < 0 || *i >= SAA7134_INPUT_MAX)
1665 if (NULL == card_in(dev,*i).name)
1676 EXPORT_SYMBOL(saa7134_common_ioctl);
1679 * This function is _not_ called directly, but from
1680 * video_generic_ioctl (and maybe others). userspace
1681 * copying is done already, arg is a kernel pointer.
1683 static int video_do_ioctl(struct inode *inode, struct file *file,
1684 unsigned int cmd, void *arg)
1686 struct saa7134_fh *fh = file->private_data;
1687 struct saa7134_dev *dev = fh->dev;
1688 unsigned long flags;
1691 if (video_debug > 1)
1692 v4l_print_ioctl(dev->name,cmd);
1697 case VIDIOC_S_INPUT:
1698 case VIDIOC_S_TUNER:
1699 case VIDIOC_S_FREQUENCY:
1700 err = v4l2_prio_check(&dev->prio,&fh->prio);
1706 case VIDIOC_QUERYCAP:
1708 struct v4l2_capability *cap = arg;
1709 unsigned int tuner_type = dev->tuner_type;
1711 memset(cap,0,sizeof(*cap));
1712 strcpy(cap->driver, "saa7134");
1713 strlcpy(cap->card, saa7134_boards[dev->board].name,
1715 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1716 cap->version = SAA7134_VERSION_CODE;
1718 V4L2_CAP_VIDEO_CAPTURE |
1719 V4L2_CAP_VIDEO_OVERLAY |
1720 V4L2_CAP_VBI_CAPTURE |
1721 V4L2_CAP_READWRITE |
1722 V4L2_CAP_STREAMING |
1725 if ((tuner_type == TUNER_ABSENT) || (tuner_type == UNSET))
1726 cap->capabilities &= ~V4L2_CAP_TUNER;
1731 /* --- tv standards ------------------------------------------ */
1732 case VIDIOC_ENUMSTD:
1734 struct v4l2_standard *e = arg;
1740 err = v4l2_video_std_construct(e, tvnorms[e->index].id,
1741 tvnorms[e->index].name);
1749 v4l2_std_id *id = arg;
1751 *id = dev->tvnorm->id;
1756 v4l2_std_id *id = arg;
1759 for (i = 0; i < TVNORMS; i++)
1760 if (*id == tvnorms[i].id)
1763 for (i = 0; i < TVNORMS; i++)
1764 if (*id & tvnorms[i].id)
1770 if (res_check(fh, RESOURCE_OVERLAY)) {
1771 spin_lock_irqsave(&dev->slock,flags);
1772 stop_preview(dev,fh);
1773 set_tvnorm(dev,&tvnorms[i]);
1774 start_preview(dev,fh);
1775 spin_unlock_irqrestore(&dev->slock,flags);
1777 set_tvnorm(dev,&tvnorms[i]);
1778 saa7134_tvaudio_do_scan(dev);
1783 case VIDIOC_CROPCAP:
1785 struct v4l2_cropcap *cap = arg;
1787 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1788 cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1790 cap->bounds = dev->crop_bounds;
1791 cap->defrect = dev->crop_defrect;
1792 cap->pixelaspect.numerator = 1;
1793 cap->pixelaspect.denominator = 1;
1794 if (dev->tvnorm->id & V4L2_STD_525_60) {
1795 cap->pixelaspect.numerator = 11;
1796 cap->pixelaspect.denominator = 10;
1798 if (dev->tvnorm->id & V4L2_STD_625_50) {
1799 cap->pixelaspect.numerator = 54;
1800 cap->pixelaspect.denominator = 59;
1807 struct v4l2_crop * crop = arg;
1809 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1810 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1812 crop->c = dev->crop_current;
1817 struct v4l2_crop *crop = arg;
1818 struct v4l2_rect *b = &dev->crop_bounds;
1820 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1821 crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
1823 if (crop->c.height < 0)
1825 if (crop->c.width < 0)
1828 if (res_locked(fh->dev,RESOURCE_OVERLAY))
1830 if (res_locked(fh->dev,RESOURCE_VIDEO))
1833 if (crop->c.top < b->top)
1834 crop->c.top = b->top;
1835 if (crop->c.top > b->top + b->height)
1836 crop->c.top = b->top + b->height;
1837 if (crop->c.height > b->top - crop->c.top + b->height)
1838 crop->c.height = b->top - crop->c.top + b->height;
1840 if (crop->c.left < b->left)
1841 crop->c.left = b->left;
1842 if (crop->c.left > b->left + b->width)
1843 crop->c.left = b->left + b->width;
1844 if (crop->c.width > b->left - crop->c.left + b->width)
1845 crop->c.width = b->left - crop->c.left + b->width;
1847 dev->crop_current = crop->c;
1851 /* --- tuner ioctls ------------------------------------------ */
1852 case VIDIOC_G_TUNER:
1854 struct v4l2_tuner *t = arg;
1859 memset(t,0,sizeof(*t));
1860 for (n = 0; n < SAA7134_INPUT_MAX; n++)
1861 if (card_in(dev,n).tv)
1863 if (NULL != card_in(dev,n).name) {
1864 strcpy(t->name, "Television");
1865 t->type = V4L2_TUNER_ANALOG_TV;
1866 t->capability = V4L2_TUNER_CAP_NORM |
1867 V4L2_TUNER_CAP_STEREO |
1868 V4L2_TUNER_CAP_LANG1 |
1869 V4L2_TUNER_CAP_LANG2;
1870 t->rangehigh = 0xffffffffUL;
1871 t->rxsubchans = saa7134_tvaudio_getstereo(dev);
1872 t->audmode = saa7134_tvaudio_rx2mode(t->rxsubchans);
1874 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1) & 0x03))
1878 case VIDIOC_S_TUNER:
1880 struct v4l2_tuner *t = arg;
1883 mode = dev->thread.mode;
1884 if (UNSET == mode) {
1885 rx = saa7134_tvaudio_getstereo(dev);
1886 mode = saa7134_tvaudio_rx2mode(t->rxsubchans);
1888 if (mode != t->audmode) {
1889 dev->thread.mode = t->audmode;
1893 case VIDIOC_G_FREQUENCY:
1895 struct v4l2_frequency *f = arg;
1897 memset(f,0,sizeof(*f));
1898 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1899 f->frequency = dev->ctl_freq;
1902 case VIDIOC_S_FREQUENCY:
1904 struct v4l2_frequency *f = arg;
1908 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
1910 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1913 dev->ctl_freq = f->frequency;
1915 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,f);
1917 saa7134_tvaudio_do_scan(dev);
1922 /* --- control ioctls ---------------------------------------- */
1923 case VIDIOC_ENUMINPUT:
1924 case VIDIOC_G_INPUT:
1925 case VIDIOC_S_INPUT:
1926 case VIDIOC_QUERYCTRL:
1929 return saa7134_common_ioctl(dev, cmd, arg);
1931 case VIDIOC_G_AUDIO:
1933 struct v4l2_audio *a = arg;
1935 memset(a,0,sizeof(*a));
1936 strcpy(a->name,"audio");
1939 case VIDIOC_S_AUDIO:
1943 struct v4l2_captureparm *parm = arg;
1944 memset(parm,0,sizeof(*parm));
1948 case VIDIOC_G_PRIORITY:
1950 enum v4l2_priority *p = arg;
1952 *p = v4l2_prio_max(&dev->prio);
1955 case VIDIOC_S_PRIORITY:
1957 enum v4l2_priority *prio = arg;
1959 return v4l2_prio_change(&dev->prio, &fh->prio, *prio);
1962 /* --- preview ioctls ---------------------------------------- */
1963 case VIDIOC_ENUM_FMT:
1965 struct v4l2_fmtdesc *f = arg;
1966 enum v4l2_buf_type type;
1972 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1973 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1974 if (index >= FORMATS)
1976 if (f->type == V4L2_BUF_TYPE_VIDEO_OVERLAY &&
1977 formats[index].planar)
1979 memset(f,0,sizeof(*f));
1982 strlcpy(f->description,formats[index].name,sizeof(f->description));
1983 f->pixelformat = formats[index].fourcc;
1985 case V4L2_BUF_TYPE_VBI_CAPTURE:
1988 memset(f,0,sizeof(*f));
1991 f->pixelformat = V4L2_PIX_FMT_GREY;
1992 strcpy(f->description,"vbi data");
2001 struct v4l2_framebuffer *fb = arg;
2004 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2009 struct v4l2_framebuffer *fb = arg;
2010 struct saa7134_format *fmt;
2012 if(!capable(CAP_SYS_ADMIN) &&
2013 !capable(CAP_SYS_RAWIO))
2017 fmt = format_by_fourcc(fb->fmt.pixelformat);
2024 if (0 == dev->ovbuf.fmt.bytesperline)
2025 dev->ovbuf.fmt.bytesperline =
2026 dev->ovbuf.fmt.width*fmt->depth/8;
2029 case VIDIOC_OVERLAY:
2034 if (!res_get(dev,fh,RESOURCE_OVERLAY))
2036 spin_lock_irqsave(&dev->slock,flags);
2037 start_preview(dev,fh);
2038 spin_unlock_irqrestore(&dev->slock,flags);
2041 if (!res_check(fh, RESOURCE_OVERLAY))
2043 spin_lock_irqsave(&dev->slock,flags);
2044 stop_preview(dev,fh);
2045 spin_unlock_irqrestore(&dev->slock,flags);
2046 res_free(dev,fh,RESOURCE_OVERLAY);
2051 /* --- capture ioctls ---------------------------------------- */
2054 struct v4l2_format *f = arg;
2055 return saa7134_g_fmt(dev,fh,f);
2059 struct v4l2_format *f = arg;
2060 return saa7134_s_fmt(dev,fh,f);
2062 case VIDIOC_TRY_FMT:
2064 struct v4l2_format *f = arg;
2065 return saa7134_try_fmt(dev,fh,f);
2070 struct video_mbuf *mbuf = arg;
2071 struct videobuf_queue *q;
2072 struct v4l2_requestbuffers req;
2075 q = saa7134_queue(fh);
2076 memset(&req,0,sizeof(req));
2078 req.count = gbuffers;
2079 req.memory = V4L2_MEMORY_MMAP;
2080 err = videobuf_reqbufs(q,&req);
2083 memset(mbuf,0,sizeof(*mbuf));
2084 mbuf->frames = req.count;
2086 for (i = 0; i < mbuf->frames; i++) {
2087 mbuf->offsets[i] = q->bufs[i]->boff;
2088 mbuf->size += q->bufs[i]->bsize;
2093 case VIDIOC_REQBUFS:
2094 return videobuf_reqbufs(saa7134_queue(fh),arg);
2096 case VIDIOC_QUERYBUF:
2097 return videobuf_querybuf(saa7134_queue(fh),arg);
2100 return videobuf_qbuf(saa7134_queue(fh),arg);
2103 return videobuf_dqbuf(saa7134_queue(fh),arg,
2104 file->f_flags & O_NONBLOCK);
2106 case VIDIOC_STREAMON:
2108 int res = saa7134_resource(fh);
2110 if (!res_get(dev,fh,res))
2112 return videobuf_streamon(saa7134_queue(fh));
2114 case VIDIOC_STREAMOFF:
2116 int res = saa7134_resource(fh);
2118 err = videobuf_streamoff(saa7134_queue(fh));
2121 res_free(dev,fh,res);
2126 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
2132 static int video_ioctl(struct inode *inode, struct file *file,
2133 unsigned int cmd, unsigned long arg)
2135 return video_usercopy(inode, file, cmd, arg, video_do_ioctl);
2138 static int radio_do_ioctl(struct inode *inode, struct file *file,
2139 unsigned int cmd, void *arg)
2141 struct saa7134_fh *fh = file->private_data;
2142 struct saa7134_dev *dev = fh->dev;
2144 if (video_debug > 1)
2145 v4l_print_ioctl(dev->name,cmd);
2147 case VIDIOC_QUERYCAP:
2149 struct v4l2_capability *cap = arg;
2151 memset(cap,0,sizeof(*cap));
2152 strcpy(cap->driver, "saa7134");
2153 strlcpy(cap->card, saa7134_boards[dev->board].name,
2155 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
2156 cap->version = SAA7134_VERSION_CODE;
2157 cap->capabilities = V4L2_CAP_TUNER;
2160 case VIDIOC_G_TUNER:
2162 struct v4l2_tuner *t = arg;
2167 memset(t,0,sizeof(*t));
2168 strcpy(t->name, "Radio");
2169 t->type = V4L2_TUNER_RADIO;
2171 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t);
2175 case VIDIOC_S_TUNER:
2177 struct v4l2_tuner *t = arg;
2182 saa7134_i2c_call_clients(dev,VIDIOC_S_TUNER,t);
2186 case VIDIOC_ENUMINPUT:
2188 struct v4l2_input *i = arg;
2192 strcpy(i->name,"Radio");
2193 i->type = V4L2_INPUT_TYPE_TUNER;
2196 case VIDIOC_G_INPUT:
2202 case VIDIOC_G_AUDIO:
2204 struct v4l2_audio *a = arg;
2206 memset(a,0,sizeof(*a));
2207 strcpy(a->name,"Radio");
2212 v4l2_std_id *id = arg;
2216 case VIDIOC_S_AUDIO:
2217 case VIDIOC_S_INPUT:
2221 case VIDIOC_QUERYCTRL:
2223 const struct v4l2_queryctrl *ctrl;
2224 struct v4l2_queryctrl *c = arg;
2226 if (c->id < V4L2_CID_BASE ||
2227 c->id >= V4L2_CID_LASTP1)
2229 if (c->id == V4L2_CID_AUDIO_MUTE) {
2230 ctrl = ctrl_by_id(c->id);
2239 case VIDIOC_G_FREQUENCY:
2240 case VIDIOC_S_FREQUENCY:
2241 return video_do_ioctl(inode,file,cmd,arg);
2244 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
2250 static int radio_ioctl(struct inode *inode, struct file *file,
2251 unsigned int cmd, unsigned long arg)
2253 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
2256 static struct file_operations video_fops =
2258 .owner = THIS_MODULE,
2260 .release = video_release,
2264 .ioctl = video_ioctl,
2265 .compat_ioctl = v4l_compat_ioctl32,
2266 .llseek = no_llseek,
2269 static struct file_operations radio_fops =
2271 .owner = THIS_MODULE,
2273 .release = video_release,
2274 .ioctl = radio_ioctl,
2275 .compat_ioctl = v4l_compat_ioctl32,
2276 .llseek = no_llseek,
2279 /* ----------------------------------------------------------- */
2280 /* exported stuff */
2282 struct video_device saa7134_video_template =
2284 .name = "saa7134-video",
2285 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY|
2286 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
2288 .fops = &video_fops,
2292 struct video_device saa7134_vbi_template =
2294 .name = "saa7134-vbi",
2295 .type = VID_TYPE_TUNER|VID_TYPE_TELETEXT,
2297 .fops = &video_fops,
2301 struct video_device saa7134_radio_template =
2303 .name = "saa7134-radio",
2304 .type = VID_TYPE_TUNER,
2306 .fops = &radio_fops,
2310 int saa7134_video_init1(struct saa7134_dev *dev)
2312 /* sanitycheck insmod options */
2313 if (gbuffers < 2 || gbuffers > VIDEO_MAX_FRAME)
2315 if (gbufsize < 0 || gbufsize > gbufsize_max)
2316 gbufsize = gbufsize_max;
2317 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK;
2319 /* put some sensible defaults into the data structures ... */
2320 dev->ctl_bright = ctrl_by_id(V4L2_CID_BRIGHTNESS)->default_value;
2321 dev->ctl_contrast = ctrl_by_id(V4L2_CID_CONTRAST)->default_value;
2322 dev->ctl_hue = ctrl_by_id(V4L2_CID_HUE)->default_value;
2323 dev->ctl_saturation = ctrl_by_id(V4L2_CID_SATURATION)->default_value;
2324 dev->ctl_volume = ctrl_by_id(V4L2_CID_AUDIO_VOLUME)->default_value;
2325 dev->ctl_mute = 1; // ctrl_by_id(V4L2_CID_AUDIO_MUTE)->default_value;
2326 dev->ctl_invert = ctrl_by_id(V4L2_CID_PRIVATE_INVERT)->default_value;
2327 dev->ctl_automute = ctrl_by_id(V4L2_CID_PRIVATE_AUTOMUTE)->default_value;
2329 if (dev->tda9887_conf && dev->ctl_automute)
2330 dev->tda9887_conf |= TDA9887_AUTOMUTE;
2333 INIT_LIST_HEAD(&dev->video_q.queue);
2334 init_timer(&dev->video_q.timeout);
2335 dev->video_q.timeout.function = saa7134_buffer_timeout;
2336 dev->video_q.timeout.data = (unsigned long)(&dev->video_q);
2337 dev->video_q.dev = dev;
2339 if (saa7134_boards[dev->board].video_out) {
2340 /* enable video output */
2341 int vo = saa7134_boards[dev->board].video_out;
2343 unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts;
2344 saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]);
2345 video_reg = video_out[vo][1];
2346 if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED)
2347 video_reg &= ~VP_T_CODE_P_INVERTED;
2348 saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg);
2349 saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]);
2350 saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]);
2351 saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]);
2352 video_reg = video_out[vo][5];
2353 if (vid_port_opts & SET_CLOCK_NOT_DELAYED)
2354 video_reg &= ~VP_CLK_CTRL2_DELAYED;
2355 if (vid_port_opts & SET_CLOCK_INVERTED)
2356 video_reg |= VP_CLK_CTRL1_INVERTED;
2357 saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg);
2358 video_reg = video_out[vo][6];
2359 if (vid_port_opts & SET_VSYNC_OFF) {
2360 video_reg &= ~VP_VS_TYPE_MASK;
2361 video_reg |= VP_VS_TYPE_OFF;
2363 saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg);
2364 saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]);
2365 saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]);
2371 int saa7134_video_init2(struct saa7134_dev *dev)
2374 set_tvnorm(dev,&tvnorms[0]);
2376 saa7134_tvaudio_setmute(dev);
2377 saa7134_tvaudio_setvolume(dev,dev->ctl_volume);
2381 int saa7134_video_fini(struct saa7134_dev *dev)
2387 void saa7134_irq_video_intl(struct saa7134_dev *dev)
2389 static const char *st[] = {
2390 "(no signal)", "NTSC", "PAL", "SECAM" };
2393 st1 = saa_readb(SAA7134_STATUS_VIDEO1);
2394 st2 = saa_readb(SAA7134_STATUS_VIDEO2);
2395 dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n",
2396 (st1 & 0x40) ? "not locked" : "locked",
2397 (st2 & 0x40) ? "no" : "yes",
2399 dev->nosignal = (st1 & 0x40) || (st2 & 0x40);
2401 if (dev->nosignal) {
2402 /* no video signal -> mute audio */
2403 if (dev->ctl_automute)
2405 saa7134_tvaudio_setmute(dev);
2406 saa_setb(SAA7134_SYNC_CTRL, 0x20);
2408 /* wake up tvaudio audio carrier scan thread */
2409 saa7134_tvaudio_do_scan(dev);
2411 saa_clearb(SAA7134_SYNC_CTRL, 0x20);
2413 if (dev->mops && dev->mops->signal_change)
2414 dev->mops->signal_change(dev);
2417 void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
2419 enum v4l2_field field;
2421 spin_lock(&dev->slock);
2422 if (dev->video_q.curr) {
2423 dev->video_fieldcount++;
2424 field = dev->video_q.curr->vb.field;
2425 if (V4L2_FIELD_HAS_BOTH(field)) {
2426 /* make sure we have seen both fields */
2427 if ((status & 0x10) == 0x00) {
2428 dev->video_q.curr->top_seen = 1;
2431 if (!dev->video_q.curr->top_seen)
2433 } else if (field == V4L2_FIELD_TOP) {
2434 if ((status & 0x10) != 0x10)
2436 } else if (field == V4L2_FIELD_BOTTOM) {
2437 if ((status & 0x10) != 0x00)
2440 dev->video_q.curr->vb.field_count = dev->video_fieldcount;
2441 saa7134_buffer_finish(dev,&dev->video_q,STATE_DONE);
2443 saa7134_buffer_next(dev,&dev->video_q);
2446 spin_unlock(&dev->slock);
2449 /* ----------------------------------------------------------- */