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 */
463 mutex_lock(&dev
->lock
);
464 if (dev
->resources
& bit
) {
465 /* no, someone else uses it */
466 mutex_unlock(&dev
->lock
);
469 /* it's free, grab it */
470 fh
->resources
|= bit
;
471 dev
->resources
|= bit
;
472 dprintk("res: get %d\n",bit
);
473 mutex_unlock(&dev
->lock
);
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 BUG_ON((fh
->resources
& bits
) != bits
);
494 mutex_lock(&dev
->lock
);
495 fh
->resources
&= ~bits
;
496 dev
->resources
&= ~bits
;
497 dprintk("res: put %d\n",bits
);
498 mutex_unlock(&dev
->lock
);
501 /* ------------------------------------------------------------------ */
503 static void set_tvnorm(struct saa7134_dev
*dev
, struct saa7134_tvnorm
*norm
)
505 int luma_control
,sync_control
,mux
;
507 dprintk("set tv norm = %s\n",norm
->name
);
510 mux
= card_in(dev
,dev
->ctl_input
).vmux
;
511 luma_control
= norm
->luma_control
;
512 sync_control
= norm
->sync_control
;
515 luma_control
|= 0x80; /* svideo */
516 if (noninterlaced
|| dev
->nosignal
)
517 sync_control
|= 0x20;
520 dev
->crop_bounds
.left
= norm
->h_start
;
521 dev
->crop_defrect
.left
= norm
->h_start
;
522 dev
->crop_bounds
.width
= norm
->h_stop
- norm
->h_start
+1;
523 dev
->crop_defrect
.width
= norm
->h_stop
- norm
->h_start
+1;
525 dev
->crop_bounds
.top
= (norm
->vbi_v_stop_0
+1)*2;
526 dev
->crop_defrect
.top
= norm
->video_v_start
*2;
527 dev
->crop_bounds
.height
= ((norm
->id
& V4L2_STD_525_60
) ? 524 : 624)
528 - dev
->crop_bounds
.top
;
529 dev
->crop_defrect
.height
= (norm
->video_v_stop
- norm
->video_v_start
+1)*2;
531 dev
->crop_current
= dev
->crop_defrect
;
533 /* setup video decoder */
534 saa_writeb(SAA7134_INCR_DELAY
, 0x08);
535 saa_writeb(SAA7134_ANALOG_IN_CTRL1
, 0xc0 | mux
);
536 saa_writeb(SAA7134_ANALOG_IN_CTRL2
, 0x00);
538 saa_writeb(SAA7134_ANALOG_IN_CTRL3
, 0x90);
539 saa_writeb(SAA7134_ANALOG_IN_CTRL4
, 0x90);
540 saa_writeb(SAA7134_HSYNC_START
, 0xeb);
541 saa_writeb(SAA7134_HSYNC_STOP
, 0xe0);
542 saa_writeb(SAA7134_SOURCE_TIMING1
, norm
->src_timing
);
544 saa_writeb(SAA7134_SYNC_CTRL
, sync_control
);
545 saa_writeb(SAA7134_LUMA_CTRL
, luma_control
);
546 saa_writeb(SAA7134_DEC_LUMA_BRIGHT
, dev
->ctl_bright
);
547 saa_writeb(SAA7134_DEC_LUMA_CONTRAST
, dev
->ctl_contrast
);
549 saa_writeb(SAA7134_DEC_CHROMA_SATURATION
, dev
->ctl_saturation
);
550 saa_writeb(SAA7134_DEC_CHROMA_HUE
, dev
->ctl_hue
);
551 saa_writeb(SAA7134_CHROMA_CTRL1
, norm
->chroma_ctrl1
);
552 saa_writeb(SAA7134_CHROMA_GAIN
, norm
->chroma_gain
);
554 saa_writeb(SAA7134_CHROMA_CTRL2
, norm
->chroma_ctrl2
);
555 saa_writeb(SAA7134_MODE_DELAY_CTRL
, 0x00);
557 saa_writeb(SAA7134_ANALOG_ADC
, 0x01);
558 saa_writeb(SAA7134_VGATE_START
, 0x11);
559 saa_writeb(SAA7134_VGATE_STOP
, 0xfe);
560 saa_writeb(SAA7134_MISC_VGATE_MSB
, norm
->vgate_misc
);
561 saa_writeb(SAA7134_RAW_DATA_GAIN
, 0x40);
562 saa_writeb(SAA7134_RAW_DATA_OFFSET
, 0x80);
564 saa7134_i2c_call_clients(dev
,VIDIOC_S_STD
,&norm
->id
);
567 static void video_mux(struct saa7134_dev
*dev
, int input
)
569 dprintk("video input = %d [%s]\n",input
,card_in(dev
,input
).name
);
570 dev
->ctl_input
= input
;
571 set_tvnorm(dev
,dev
->tvnorm
);
572 saa7134_tvaudio_setinput(dev
,&card_in(dev
,input
));
575 static void set_h_prescale(struct saa7134_dev
*dev
, int task
, int prescale
)
577 static const struct {
584 /* XPSC XACL XC2_1 XDCG VPFY */
596 static const int count
= ARRAY_SIZE(vals
);
599 for (i
= 0; i
< count
; i
++)
600 if (vals
[i
].xpsc
== prescale
)
605 saa_writeb(SAA7134_H_PRESCALE(task
), vals
[i
].xpsc
);
606 saa_writeb(SAA7134_ACC_LENGTH(task
), vals
[i
].xacl
);
607 saa_writeb(SAA7134_LEVEL_CTRL(task
),
608 (vals
[i
].xc2_1
<< 3) | (vals
[i
].xdcg
));
609 saa_andorb(SAA7134_FIR_PREFILTER_CTRL(task
), 0x0f,
610 (vals
[i
].vpfy
<< 2) | vals
[i
].vpfy
);
613 static void set_v_scale(struct saa7134_dev
*dev
, int task
, int yscale
)
617 saa_writeb(SAA7134_V_SCALE_RATIO1(task
), yscale
& 0xff);
618 saa_writeb(SAA7134_V_SCALE_RATIO2(task
), yscale
>> 8);
620 mirror
= (dev
->ctl_mirror
) ? 0x02 : 0x00;
623 dprintk("yscale LPI yscale=%d\n",yscale
);
624 saa_writeb(SAA7134_V_FILTER(task
), 0x00 | mirror
);
625 saa_writeb(SAA7134_LUMA_CONTRAST(task
), 0x40);
626 saa_writeb(SAA7134_CHROMA_SATURATION(task
), 0x40);
629 val
= 0x40 * 1024 / yscale
;
630 dprintk("yscale ACM yscale=%d val=0x%x\n",yscale
,val
);
631 saa_writeb(SAA7134_V_FILTER(task
), 0x01 | mirror
);
632 saa_writeb(SAA7134_LUMA_CONTRAST(task
), val
);
633 saa_writeb(SAA7134_CHROMA_SATURATION(task
), val
);
635 saa_writeb(SAA7134_LUMA_BRIGHT(task
), 0x80);
638 static void set_size(struct saa7134_dev
*dev
, int task
,
639 int width
, int height
, int interlace
)
641 int prescale
,xscale
,yscale
,y_even
,y_odd
;
642 int h_start
, h_stop
, v_start
, v_stop
;
643 int div
= interlace
? 2 : 1;
645 /* setup video scaler */
646 h_start
= dev
->crop_current
.left
;
647 v_start
= dev
->crop_current
.top
/2;
648 h_stop
= (dev
->crop_current
.left
+ dev
->crop_current
.width
-1);
649 v_stop
= (dev
->crop_current
.top
+ dev
->crop_current
.height
-1)/2;
651 saa_writeb(SAA7134_VIDEO_H_START1(task
), h_start
& 0xff);
652 saa_writeb(SAA7134_VIDEO_H_START2(task
), h_start
>> 8);
653 saa_writeb(SAA7134_VIDEO_H_STOP1(task
), h_stop
& 0xff);
654 saa_writeb(SAA7134_VIDEO_H_STOP2(task
), h_stop
>> 8);
655 saa_writeb(SAA7134_VIDEO_V_START1(task
), v_start
& 0xff);
656 saa_writeb(SAA7134_VIDEO_V_START2(task
), v_start
>> 8);
657 saa_writeb(SAA7134_VIDEO_V_STOP1(task
), v_stop
& 0xff);
658 saa_writeb(SAA7134_VIDEO_V_STOP2(task
), v_stop
>> 8);
660 prescale
= dev
->crop_current
.width
/ width
;
663 xscale
= 1024 * dev
->crop_current
.width
/ prescale
/ width
;
664 yscale
= 512 * div
* dev
->crop_current
.height
/ height
;
665 dprintk("prescale=%d xscale=%d yscale=%d\n",prescale
,xscale
,yscale
);
666 set_h_prescale(dev
,task
,prescale
);
667 saa_writeb(SAA7134_H_SCALE_INC1(task
), xscale
& 0xff);
668 saa_writeb(SAA7134_H_SCALE_INC2(task
), xscale
>> 8);
669 set_v_scale(dev
,task
,yscale
);
671 saa_writeb(SAA7134_VIDEO_PIXELS1(task
), width
& 0xff);
672 saa_writeb(SAA7134_VIDEO_PIXELS2(task
), width
>> 8);
673 saa_writeb(SAA7134_VIDEO_LINES1(task
), height
/div
& 0xff);
674 saa_writeb(SAA7134_VIDEO_LINES2(task
), height
/div
>> 8);
676 /* deinterlace y offsets */
677 y_odd
= dev
->ctl_y_odd
;
678 y_even
= dev
->ctl_y_even
;
679 saa_writeb(SAA7134_V_PHASE_OFFSET0(task
), y_odd
);
680 saa_writeb(SAA7134_V_PHASE_OFFSET1(task
), y_even
);
681 saa_writeb(SAA7134_V_PHASE_OFFSET2(task
), y_odd
);
682 saa_writeb(SAA7134_V_PHASE_OFFSET3(task
), y_even
);
685 /* ------------------------------------------------------------------ */
693 static void sort_cliplist(struct cliplist
*cl
, int entries
)
695 struct cliplist swap
;
698 for (i
= entries
-2; i
>= 0; i
--) {
699 for (n
= 0, j
= 0; j
<= i
; j
++) {
700 if (cl
[j
].position
> cl
[j
+1].position
) {
712 static void set_cliplist(struct saa7134_dev
*dev
, int reg
,
713 struct cliplist
*cl
, int entries
, char *name
)
718 for (i
= 0; i
< entries
; i
++) {
719 winbits
|= cl
[i
].enable
;
720 winbits
&= ~cl
[i
].disable
;
721 if (i
< 15 && cl
[i
].position
== cl
[i
+1].position
)
723 saa_writeb(reg
+ 0, winbits
);
724 saa_writeb(reg
+ 2, cl
[i
].position
& 0xff);
725 saa_writeb(reg
+ 3, cl
[i
].position
>> 8);
726 dprintk("clip: %s winbits=%02x pos=%d\n",
727 name
,winbits
,cl
[i
].position
);
730 for (; reg
< 0x400; reg
+= 8) {
731 saa_writeb(reg
+ 0, 0);
732 saa_writeb(reg
+ 1, 0);
733 saa_writeb(reg
+ 2, 0);
734 saa_writeb(reg
+ 3, 0);
738 static int clip_range(int val
)
745 static int setup_clipping(struct saa7134_dev
*dev
, struct v4l2_clip
*clips
,
746 int nclips
, int interlace
)
748 struct cliplist col
[16], row
[16];
750 int div
= interlace
? 2 : 1;
752 memset(col
,0,sizeof(col
)); cols
= 0;
753 memset(row
,0,sizeof(row
)); rows
= 0;
754 for (i
= 0; i
< nclips
&& i
< 8; i
++) {
755 col
[cols
].position
= clip_range(clips
[i
].c
.left
);
756 col
[cols
].enable
= (1 << i
);
758 col
[cols
].position
= clip_range(clips
[i
].c
.left
+clips
[i
].c
.width
);
759 col
[cols
].disable
= (1 << i
);
761 row
[rows
].position
= clip_range(clips
[i
].c
.top
/ div
);
762 row
[rows
].enable
= (1 << i
);
764 row
[rows
].position
= clip_range((clips
[i
].c
.top
+ clips
[i
].c
.height
)
766 row
[rows
].disable
= (1 << i
);
769 sort_cliplist(col
,cols
);
770 sort_cliplist(row
,rows
);
771 set_cliplist(dev
,0x380,col
,cols
,"cols");
772 set_cliplist(dev
,0x384,row
,rows
,"rows");
776 static int verify_preview(struct saa7134_dev
*dev
, struct v4l2_window
*win
)
778 enum v4l2_field field
;
781 if (NULL
== dev
->ovbuf
.base
)
783 if (NULL
== dev
->ovfmt
)
785 if (win
->w
.width
< 48 || win
->w
.height
< 32)
787 if (win
->clipcount
> 2048)
791 maxw
= dev
->crop_current
.width
;
792 maxh
= dev
->crop_current
.height
;
794 if (V4L2_FIELD_ANY
== field
) {
795 field
= (win
->w
.height
> maxh
/2)
796 ? V4L2_FIELD_INTERLACED
801 case V4L2_FIELD_BOTTOM
:
804 case V4L2_FIELD_INTERLACED
:
811 if (win
->w
.width
> maxw
)
813 if (win
->w
.height
> maxh
)
814 win
->w
.height
= maxh
;
818 static int start_preview(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
)
820 unsigned long base
,control
,bpl
;
823 err
= verify_preview(dev
,&fh
->win
);
827 dev
->ovfield
= fh
->win
.field
;
828 dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
829 fh
->win
.w
.width
,fh
->win
.w
.height
,
830 fh
->win
.w
.left
,fh
->win
.w
.top
,
831 dev
->ovfmt
->name
,v4l2_field_names
[dev
->ovfield
]);
833 /* setup window + clipping */
834 set_size(dev
,TASK_B
,fh
->win
.w
.width
,fh
->win
.w
.height
,
835 V4L2_FIELD_HAS_BOTH(dev
->ovfield
));
836 setup_clipping(dev
,fh
->clips
,fh
->nclips
,
837 V4L2_FIELD_HAS_BOTH(dev
->ovfield
));
839 saa_andorb(SAA7134_DATA_PATH(TASK_B
), 0x3f, 0x03);
841 saa_andorb(SAA7134_DATA_PATH(TASK_B
), 0x3f, 0x01);
842 saa_writeb(SAA7134_OFMT_VIDEO_B
, dev
->ovfmt
->pm
| 0x20);
844 /* dma: setup channel 1 (= Video Task B) */
845 base
= (unsigned long)dev
->ovbuf
.base
;
846 base
+= dev
->ovbuf
.fmt
.bytesperline
* fh
->win
.w
.top
;
847 base
+= dev
->ovfmt
->depth
/8 * fh
->win
.w
.left
;
848 bpl
= dev
->ovbuf
.fmt
.bytesperline
;
849 control
= SAA7134_RS_CONTROL_BURST_16
;
850 if (dev
->ovfmt
->bswap
)
851 control
|= SAA7134_RS_CONTROL_BSWAP
;
852 if (dev
->ovfmt
->wswap
)
853 control
|= SAA7134_RS_CONTROL_WSWAP
;
854 if (V4L2_FIELD_HAS_BOTH(dev
->ovfield
)) {
855 saa_writel(SAA7134_RS_BA1(1),base
);
856 saa_writel(SAA7134_RS_BA2(1),base
+bpl
);
857 saa_writel(SAA7134_RS_PITCH(1),bpl
*2);
858 saa_writel(SAA7134_RS_CONTROL(1),control
);
860 saa_writel(SAA7134_RS_BA1(1),base
);
861 saa_writel(SAA7134_RS_BA2(1),base
);
862 saa_writel(SAA7134_RS_PITCH(1),bpl
);
863 saa_writel(SAA7134_RS_CONTROL(1),control
);
868 saa7134_set_dmabits(dev
);
873 static int stop_preview(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
)
876 saa7134_set_dmabits(dev
);
880 /* ------------------------------------------------------------------ */
882 static int buffer_activate(struct saa7134_dev
*dev
,
883 struct saa7134_buf
*buf
,
884 struct saa7134_buf
*next
)
886 unsigned long base
,control
,bpl
;
887 unsigned long bpl_uv
,lines_uv
,base2
,base3
,tmp
; /* planar */
889 dprintk("buffer_activate buf=%p\n",buf
);
890 buf
->vb
.state
= STATE_ACTIVE
;
893 set_size(dev
,TASK_A
,buf
->vb
.width
,buf
->vb
.height
,
894 V4L2_FIELD_HAS_BOTH(buf
->vb
.field
));
896 saa_andorb(SAA7134_DATA_PATH(TASK_A
), 0x3f, 0x03);
898 saa_andorb(SAA7134_DATA_PATH(TASK_A
), 0x3f, 0x01);
899 saa_writeb(SAA7134_OFMT_VIDEO_A
, buf
->fmt
->pm
);
901 /* DMA: setup channel 0 (= Video Task A0) */
902 base
= saa7134_buffer_base(buf
);
903 if (buf
->fmt
->planar
)
906 bpl
= (buf
->vb
.width
* buf
->fmt
->depth
) / 8;
907 control
= SAA7134_RS_CONTROL_BURST_16
|
908 SAA7134_RS_CONTROL_ME
|
909 (buf
->pt
->dma
>> 12);
911 control
|= SAA7134_RS_CONTROL_BSWAP
;
913 control
|= SAA7134_RS_CONTROL_WSWAP
;
914 if (V4L2_FIELD_HAS_BOTH(buf
->vb
.field
)) {
916 saa_writel(SAA7134_RS_BA1(0),base
);
917 saa_writel(SAA7134_RS_BA2(0),base
+bpl
);
918 saa_writel(SAA7134_RS_PITCH(0),bpl
*2);
921 saa_writel(SAA7134_RS_BA1(0),base
);
922 saa_writel(SAA7134_RS_BA2(0),base
);
923 saa_writel(SAA7134_RS_PITCH(0),bpl
);
925 saa_writel(SAA7134_RS_CONTROL(0),control
);
927 if (buf
->fmt
->planar
) {
928 /* DMA: setup channel 4+5 (= planar task A) */
929 bpl_uv
= bpl
>> buf
->fmt
->hshift
;
930 lines_uv
= buf
->vb
.height
>> buf
->fmt
->vshift
;
931 base2
= base
+ bpl
* buf
->vb
.height
;
932 base3
= base2
+ bpl_uv
* lines_uv
;
933 if (buf
->fmt
->uvswap
)
934 tmp
= base2
, base2
= base3
, base3
= tmp
;
935 dprintk("uv: bpl=%ld lines=%ld base2/3=%ld/%ld\n",
936 bpl_uv
,lines_uv
,base2
,base3
);
937 if (V4L2_FIELD_HAS_BOTH(buf
->vb
.field
)) {
939 saa_writel(SAA7134_RS_BA1(4),base2
);
940 saa_writel(SAA7134_RS_BA2(4),base2
+bpl_uv
);
941 saa_writel(SAA7134_RS_PITCH(4),bpl_uv
*2);
942 saa_writel(SAA7134_RS_BA1(5),base3
);
943 saa_writel(SAA7134_RS_BA2(5),base3
+bpl_uv
);
944 saa_writel(SAA7134_RS_PITCH(5),bpl_uv
*2);
947 saa_writel(SAA7134_RS_BA1(4),base2
);
948 saa_writel(SAA7134_RS_BA2(4),base2
);
949 saa_writel(SAA7134_RS_PITCH(4),bpl_uv
);
950 saa_writel(SAA7134_RS_BA1(5),base3
);
951 saa_writel(SAA7134_RS_BA2(5),base3
);
952 saa_writel(SAA7134_RS_PITCH(5),bpl_uv
);
954 saa_writel(SAA7134_RS_CONTROL(4),control
);
955 saa_writel(SAA7134_RS_CONTROL(5),control
);
959 saa7134_set_dmabits(dev
);
960 mod_timer(&dev
->video_q
.timeout
, jiffies
+BUFFER_TIMEOUT
);
964 static int buffer_prepare(struct videobuf_queue
*q
,
965 struct videobuf_buffer
*vb
,
966 enum v4l2_field field
)
968 struct saa7134_fh
*fh
= q
->priv_data
;
969 struct saa7134_dev
*dev
= fh
->dev
;
970 struct saa7134_buf
*buf
= container_of(vb
,struct saa7134_buf
,vb
);
977 if (fh
->width
< 48 ||
979 fh
->width
/4 > dev
->crop_current
.width
||
980 fh
->height
/4 > dev
->crop_current
.height
||
981 fh
->width
> dev
->crop_bounds
.width
||
982 fh
->height
> dev
->crop_bounds
.height
)
984 size
= (fh
->width
* fh
->height
* fh
->fmt
->depth
) >> 3;
985 if (0 != buf
->vb
.baddr
&& buf
->vb
.bsize
< size
)
988 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
989 vb
->i
,fh
->width
,fh
->height
,size
,v4l2_field_names
[field
],
991 if (buf
->vb
.width
!= fh
->width
||
992 buf
->vb
.height
!= fh
->height
||
993 buf
->vb
.size
!= size
||
994 buf
->vb
.field
!= field
||
995 buf
->fmt
!= fh
->fmt
) {
996 saa7134_dma_free(dev
,buf
);
999 if (STATE_NEEDS_INIT
== buf
->vb
.state
) {
1000 buf
->vb
.width
= fh
->width
;
1001 buf
->vb
.height
= fh
->height
;
1002 buf
->vb
.size
= size
;
1003 buf
->vb
.field
= field
;
1005 buf
->pt
= &fh
->pt_cap
;
1007 err
= videobuf_iolock(dev
->pci
,&buf
->vb
,&dev
->ovbuf
);
1010 err
= saa7134_pgtable_build(dev
->pci
,buf
->pt
,
1013 saa7134_buffer_startpage(buf
));
1017 buf
->vb
.state
= STATE_PREPARED
;
1018 buf
->activate
= buffer_activate
;
1022 saa7134_dma_free(dev
,buf
);
1027 buffer_setup(struct videobuf_queue
*q
, unsigned int *count
, unsigned int *size
)
1029 struct saa7134_fh
*fh
= q
->priv_data
;
1031 *size
= fh
->fmt
->depth
* fh
->width
* fh
->height
>> 3;
1034 *count
= saa7134_buffer_count(*size
,*count
);
1038 static void buffer_queue(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
1040 struct saa7134_fh
*fh
= q
->priv_data
;
1041 struct saa7134_buf
*buf
= container_of(vb
,struct saa7134_buf
,vb
);
1043 saa7134_buffer_queue(fh
->dev
,&fh
->dev
->video_q
,buf
);
1046 static void buffer_release(struct videobuf_queue
*q
, struct videobuf_buffer
*vb
)
1048 struct saa7134_fh
*fh
= q
->priv_data
;
1049 struct saa7134_buf
*buf
= container_of(vb
,struct saa7134_buf
,vb
);
1051 saa7134_dma_free(fh
->dev
,buf
);
1054 static struct videobuf_queue_ops video_qops
= {
1055 .buf_setup
= buffer_setup
,
1056 .buf_prepare
= buffer_prepare
,
1057 .buf_queue
= buffer_queue
,
1058 .buf_release
= buffer_release
,
1061 /* ------------------------------------------------------------------ */
1063 static int get_control(struct saa7134_dev
*dev
, struct v4l2_control
*c
)
1065 const struct v4l2_queryctrl
* ctrl
;
1067 ctrl
= ctrl_by_id(c
->id
);
1071 case V4L2_CID_BRIGHTNESS
:
1072 c
->value
= dev
->ctl_bright
;
1075 c
->value
= dev
->ctl_hue
;
1077 case V4L2_CID_CONTRAST
:
1078 c
->value
= dev
->ctl_contrast
;
1080 case V4L2_CID_SATURATION
:
1081 c
->value
= dev
->ctl_saturation
;
1083 case V4L2_CID_AUDIO_MUTE
:
1084 c
->value
= dev
->ctl_mute
;
1086 case V4L2_CID_AUDIO_VOLUME
:
1087 c
->value
= dev
->ctl_volume
;
1089 case V4L2_CID_PRIVATE_INVERT
:
1090 c
->value
= dev
->ctl_invert
;
1092 case V4L2_CID_HFLIP
:
1093 c
->value
= dev
->ctl_mirror
;
1095 case V4L2_CID_PRIVATE_Y_EVEN
:
1096 c
->value
= dev
->ctl_y_even
;
1098 case V4L2_CID_PRIVATE_Y_ODD
:
1099 c
->value
= dev
->ctl_y_odd
;
1101 case V4L2_CID_PRIVATE_AUTOMUTE
:
1102 c
->value
= dev
->ctl_automute
;
1110 static int set_control(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
,
1111 struct v4l2_control
*c
)
1113 const struct v4l2_queryctrl
* ctrl
;
1114 unsigned long flags
;
1115 int restart_overlay
= 0;
1117 ctrl
= ctrl_by_id(c
->id
);
1120 dprintk("set_control name=%s val=%d\n",ctrl
->name
,c
->value
);
1121 switch (ctrl
->type
) {
1122 case V4L2_CTRL_TYPE_BOOLEAN
:
1123 case V4L2_CTRL_TYPE_MENU
:
1124 case V4L2_CTRL_TYPE_INTEGER
:
1125 if (c
->value
< ctrl
->minimum
)
1126 c
->value
= ctrl
->minimum
;
1127 if (c
->value
> ctrl
->maximum
)
1128 c
->value
= ctrl
->maximum
;
1134 case V4L2_CID_BRIGHTNESS
:
1135 dev
->ctl_bright
= c
->value
;
1136 saa_writeb(SAA7134_DEC_LUMA_BRIGHT
, dev
->ctl_bright
);
1139 dev
->ctl_hue
= c
->value
;
1140 saa_writeb(SAA7134_DEC_CHROMA_HUE
, dev
->ctl_hue
);
1142 case V4L2_CID_CONTRAST
:
1143 dev
->ctl_contrast
= c
->value
;
1144 saa_writeb(SAA7134_DEC_LUMA_CONTRAST
,
1145 dev
->ctl_invert
? -dev
->ctl_contrast
: dev
->ctl_contrast
);
1147 case V4L2_CID_SATURATION
:
1148 dev
->ctl_saturation
= c
->value
;
1149 saa_writeb(SAA7134_DEC_CHROMA_SATURATION
,
1150 dev
->ctl_invert
? -dev
->ctl_saturation
: dev
->ctl_saturation
);
1152 case V4L2_CID_AUDIO_MUTE
:
1153 dev
->ctl_mute
= c
->value
;
1154 saa7134_tvaudio_setmute(dev
);
1156 case V4L2_CID_AUDIO_VOLUME
:
1157 dev
->ctl_volume
= c
->value
;
1158 saa7134_tvaudio_setvolume(dev
,dev
->ctl_volume
);
1160 case V4L2_CID_PRIVATE_INVERT
:
1161 dev
->ctl_invert
= c
->value
;
1162 saa_writeb(SAA7134_DEC_LUMA_CONTRAST
,
1163 dev
->ctl_invert
? -dev
->ctl_contrast
: dev
->ctl_contrast
);
1164 saa_writeb(SAA7134_DEC_CHROMA_SATURATION
,
1165 dev
->ctl_invert
? -dev
->ctl_saturation
: dev
->ctl_saturation
);
1167 case V4L2_CID_HFLIP
:
1168 dev
->ctl_mirror
= c
->value
;
1169 restart_overlay
= 1;
1171 case V4L2_CID_PRIVATE_Y_EVEN
:
1172 dev
->ctl_y_even
= c
->value
;
1173 restart_overlay
= 1;
1175 case V4L2_CID_PRIVATE_Y_ODD
:
1176 dev
->ctl_y_odd
= c
->value
;
1177 restart_overlay
= 1;
1179 case V4L2_CID_PRIVATE_AUTOMUTE
:
1180 dev
->ctl_automute
= c
->value
;
1181 if (dev
->tda9887_conf
) {
1182 if (dev
->ctl_automute
)
1183 dev
->tda9887_conf
|= TDA9887_AUTOMUTE
;
1185 dev
->tda9887_conf
&= ~TDA9887_AUTOMUTE
;
1186 saa7134_i2c_call_clients(dev
, TDA9887_SET_CONFIG
,
1187 &dev
->tda9887_conf
);
1193 if (restart_overlay
&& fh
&& res_check(fh
, RESOURCE_OVERLAY
)) {
1194 spin_lock_irqsave(&dev
->slock
,flags
);
1195 stop_preview(dev
,fh
);
1196 start_preview(dev
,fh
);
1197 spin_unlock_irqrestore(&dev
->slock
,flags
);
1202 /* ------------------------------------------------------------------ */
1204 static struct videobuf_queue
* saa7134_queue(struct saa7134_fh
*fh
)
1206 struct videobuf_queue
* q
= NULL
;
1209 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1212 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1221 static int saa7134_resource(struct saa7134_fh
*fh
)
1226 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1227 res
= RESOURCE_VIDEO
;
1229 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1238 static int video_open(struct inode
*inode
, struct file
*file
)
1240 int minor
= iminor(inode
);
1241 struct saa7134_dev
*h
,*dev
= NULL
;
1242 struct saa7134_fh
*fh
;
1243 struct list_head
*list
;
1244 enum v4l2_buf_type type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1246 list_for_each(list
,&saa7134_devlist
) {
1247 h
= list_entry(list
, struct saa7134_dev
, devlist
);
1248 if (h
->video_dev
&& (h
->video_dev
->minor
== minor
))
1250 if (h
->radio_dev
&& (h
->radio_dev
->minor
== minor
)) {
1254 if (h
->vbi_dev
&& (h
->vbi_dev
->minor
== minor
)) {
1255 type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
1262 dprintk("open minor=%d radio=%d type=%s\n",minor
,radio
,
1263 v4l2_type_names
[type
]);
1265 /* allocate + initialize per filehandle data */
1266 fh
= kzalloc(sizeof(*fh
),GFP_KERNEL
);
1269 file
->private_data
= fh
;
1273 fh
->fmt
= format_by_fourcc(V4L2_PIX_FMT_BGR24
);
1276 v4l2_prio_open(&dev
->prio
,&fh
->prio
);
1278 videobuf_queue_init(&fh
->cap
, &video_qops
,
1279 dev
->pci
, &dev
->slock
,
1280 V4L2_BUF_TYPE_VIDEO_CAPTURE
,
1281 V4L2_FIELD_INTERLACED
,
1282 sizeof(struct saa7134_buf
),
1284 videobuf_queue_init(&fh
->vbi
, &saa7134_vbi_qops
,
1285 dev
->pci
, &dev
->slock
,
1286 V4L2_BUF_TYPE_VBI_CAPTURE
,
1288 sizeof(struct saa7134_buf
),
1290 saa7134_pgtable_alloc(dev
->pci
,&fh
->pt_cap
);
1291 saa7134_pgtable_alloc(dev
->pci
,&fh
->pt_vbi
);
1294 /* switch to radio mode */
1295 saa7134_tvaudio_setinput(dev
,&card(dev
).radio
);
1296 saa7134_i2c_call_clients(dev
,AUDC_SET_RADIO
, NULL
);
1298 /* switch to video/vbi mode */
1299 video_mux(dev
,dev
->ctl_input
);
1305 video_read(struct file
*file
, char __user
*data
, size_t count
, loff_t
*ppos
)
1307 struct saa7134_fh
*fh
= file
->private_data
;
1310 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1311 if (res_locked(fh
->dev
,RESOURCE_VIDEO
))
1313 return videobuf_read_one(saa7134_queue(fh
),
1315 file
->f_flags
& O_NONBLOCK
);
1316 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1317 if (!res_get(fh
->dev
,fh
,RESOURCE_VBI
))
1319 return videobuf_read_stream(saa7134_queue(fh
),
1320 data
, count
, ppos
, 1,
1321 file
->f_flags
& O_NONBLOCK
);
1330 video_poll(struct file
*file
, struct poll_table_struct
*wait
)
1332 struct saa7134_fh
*fh
= file
->private_data
;
1333 struct videobuf_buffer
*buf
= NULL
;
1335 if (V4L2_BUF_TYPE_VBI_CAPTURE
== fh
->type
)
1336 return videobuf_poll_stream(file
, &fh
->vbi
, wait
);
1338 if (res_check(fh
,RESOURCE_VIDEO
)) {
1339 if (!list_empty(&fh
->cap
.stream
))
1340 buf
= list_entry(fh
->cap
.stream
.next
, struct videobuf_buffer
, stream
);
1342 mutex_lock(&fh
->cap
.lock
);
1343 if (UNSET
== fh
->cap
.read_off
) {
1344 /* need to capture a new frame */
1345 if (res_locked(fh
->dev
,RESOURCE_VIDEO
)) {
1346 mutex_unlock(&fh
->cap
.lock
);
1349 if (0 != fh
->cap
.ops
->buf_prepare(&fh
->cap
,fh
->cap
.read_buf
,fh
->cap
.field
)) {
1350 mutex_unlock(&fh
->cap
.lock
);
1353 fh
->cap
.ops
->buf_queue(&fh
->cap
,fh
->cap
.read_buf
);
1354 fh
->cap
.read_off
= 0;
1356 mutex_unlock(&fh
->cap
.lock
);
1357 buf
= fh
->cap
.read_buf
;
1363 poll_wait(file
, &buf
->done
, wait
);
1364 if (buf
->state
== STATE_DONE
||
1365 buf
->state
== STATE_ERROR
)
1366 return POLLIN
|POLLRDNORM
;
1370 static int video_release(struct inode
*inode
, struct file
*file
)
1372 struct saa7134_fh
*fh
= file
->private_data
;
1373 struct saa7134_dev
*dev
= fh
->dev
;
1374 unsigned long flags
;
1376 /* turn off overlay */
1377 if (res_check(fh
, RESOURCE_OVERLAY
)) {
1378 spin_lock_irqsave(&dev
->slock
,flags
);
1379 stop_preview(dev
,fh
);
1380 spin_unlock_irqrestore(&dev
->slock
,flags
);
1381 res_free(dev
,fh
,RESOURCE_OVERLAY
);
1384 /* stop video capture */
1385 if (res_check(fh
, RESOURCE_VIDEO
)) {
1386 videobuf_streamoff(&fh
->cap
);
1387 res_free(dev
,fh
,RESOURCE_VIDEO
);
1389 if (fh
->cap
.read_buf
) {
1390 buffer_release(&fh
->cap
,fh
->cap
.read_buf
);
1391 kfree(fh
->cap
.read_buf
);
1394 /* stop vbi capture */
1395 if (res_check(fh
, RESOURCE_VBI
)) {
1396 if (fh
->vbi
.streaming
)
1397 videobuf_streamoff(&fh
->vbi
);
1398 if (fh
->vbi
.reading
)
1399 videobuf_read_stop(&fh
->vbi
);
1400 res_free(dev
,fh
,RESOURCE_VBI
);
1403 /* ts-capture will not work in planar mode, so turn it off Hac: 04.05*/
1404 saa_andorb(SAA7134_OFMT_VIDEO_A
, 0x1f, 0);
1405 saa_andorb(SAA7134_OFMT_VIDEO_B
, 0x1f, 0);
1406 saa_andorb(SAA7134_OFMT_DATA_A
, 0x1f, 0);
1407 saa_andorb(SAA7134_OFMT_DATA_B
, 0x1f, 0);
1409 saa7134_i2c_call_clients(dev
, TUNER_SET_STANDBY
, NULL
);
1412 videobuf_mmap_free(&fh
->cap
);
1413 videobuf_mmap_free(&fh
->vbi
);
1414 saa7134_pgtable_free(dev
->pci
,&fh
->pt_cap
);
1415 saa7134_pgtable_free(dev
->pci
,&fh
->pt_vbi
);
1417 v4l2_prio_close(&dev
->prio
,&fh
->prio
);
1418 file
->private_data
= NULL
;
1424 video_mmap(struct file
*file
, struct vm_area_struct
* vma
)
1426 struct saa7134_fh
*fh
= file
->private_data
;
1428 return videobuf_mmap_mapper(saa7134_queue(fh
), vma
);
1431 /* ------------------------------------------------------------------ */
1433 static void saa7134_vbi_fmt(struct saa7134_dev
*dev
, struct v4l2_format
*f
)
1435 struct saa7134_tvnorm
*norm
= dev
->tvnorm
;
1437 f
->fmt
.vbi
.sampling_rate
= 6750000 * 4;
1438 f
->fmt
.vbi
.samples_per_line
= 2048 /* VBI_LINE_LENGTH */;
1439 f
->fmt
.vbi
.sample_format
= V4L2_PIX_FMT_GREY
;
1440 f
->fmt
.vbi
.offset
= 64 * 4;
1441 f
->fmt
.vbi
.start
[0] = norm
->vbi_v_start_0
;
1442 f
->fmt
.vbi
.count
[0] = norm
->vbi_v_stop_0
- norm
->vbi_v_start_0
+1;
1443 f
->fmt
.vbi
.start
[1] = norm
->vbi_v_start_1
;
1444 f
->fmt
.vbi
.count
[1] = f
->fmt
.vbi
.count
[0];
1445 f
->fmt
.vbi
.flags
= 0; /* VBI_UNSYNC VBI_INTERLACED */
1449 static int saa7134_g_fmt(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
,
1450 struct v4l2_format
*f
)
1453 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1454 memset(&f
->fmt
.pix
,0,sizeof(f
->fmt
.pix
));
1455 f
->fmt
.pix
.width
= fh
->width
;
1456 f
->fmt
.pix
.height
= fh
->height
;
1457 f
->fmt
.pix
.field
= fh
->cap
.field
;
1458 f
->fmt
.pix
.pixelformat
= fh
->fmt
->fourcc
;
1459 f
->fmt
.pix
.bytesperline
=
1460 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
1461 f
->fmt
.pix
.sizeimage
=
1462 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
1464 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1465 f
->fmt
.win
= fh
->win
;
1467 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1468 saa7134_vbi_fmt(dev
,f
);
1475 static int saa7134_try_fmt(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
,
1476 struct v4l2_format
*f
)
1481 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1483 struct saa7134_format
*fmt
;
1484 enum v4l2_field field
;
1485 unsigned int maxw
, maxh
;
1487 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1491 field
= f
->fmt
.pix
.field
;
1492 maxw
= min(dev
->crop_current
.width
*4, dev
->crop_bounds
.width
);
1493 maxh
= min(dev
->crop_current
.height
*4, dev
->crop_bounds
.height
);
1495 if (V4L2_FIELD_ANY
== field
) {
1496 field
= (f
->fmt
.pix
.height
> maxh
/2)
1497 ? V4L2_FIELD_INTERLACED
1498 : V4L2_FIELD_BOTTOM
;
1501 case V4L2_FIELD_TOP
:
1502 case V4L2_FIELD_BOTTOM
:
1505 case V4L2_FIELD_INTERLACED
:
1511 f
->fmt
.pix
.field
= field
;
1512 if (f
->fmt
.pix
.width
< 48)
1513 f
->fmt
.pix
.width
= 48;
1514 if (f
->fmt
.pix
.height
< 32)
1515 f
->fmt
.pix
.height
= 32;
1516 if (f
->fmt
.pix
.width
> maxw
)
1517 f
->fmt
.pix
.width
= maxw
;
1518 if (f
->fmt
.pix
.height
> maxh
)
1519 f
->fmt
.pix
.height
= maxh
;
1520 f
->fmt
.pix
.width
&= ~0x03;
1521 f
->fmt
.pix
.bytesperline
=
1522 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
1523 f
->fmt
.pix
.sizeimage
=
1524 f
->fmt
.pix
.height
* f
->fmt
.pix
.bytesperline
;
1528 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1529 err
= verify_preview(dev
,&f
->fmt
.win
);
1533 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1534 saa7134_vbi_fmt(dev
,f
);
1541 static int saa7134_s_fmt(struct saa7134_dev
*dev
, struct saa7134_fh
*fh
,
1542 struct v4l2_format
*f
)
1544 unsigned long flags
;
1548 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1549 err
= saa7134_try_fmt(dev
,fh
,f
);
1553 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
1554 fh
->width
= f
->fmt
.pix
.width
;
1555 fh
->height
= f
->fmt
.pix
.height
;
1556 fh
->cap
.field
= f
->fmt
.pix
.field
;
1558 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1559 err
= verify_preview(dev
,&f
->fmt
.win
);
1563 mutex_lock(&dev
->lock
);
1564 fh
->win
= f
->fmt
.win
;
1565 fh
->nclips
= f
->fmt
.win
.clipcount
;
1568 if (copy_from_user(fh
->clips
,f
->fmt
.win
.clips
,
1569 sizeof(struct v4l2_clip
)*fh
->nclips
)) {
1570 mutex_unlock(&dev
->lock
);
1574 if (res_check(fh
, RESOURCE_OVERLAY
)) {
1575 spin_lock_irqsave(&dev
->slock
,flags
);
1576 stop_preview(dev
,fh
);
1577 start_preview(dev
,fh
);
1578 spin_unlock_irqrestore(&dev
->slock
,flags
);
1580 mutex_unlock(&dev
->lock
);
1582 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1583 saa7134_vbi_fmt(dev
,f
);
1590 int saa7134_common_ioctl(struct saa7134_dev
*dev
,
1591 unsigned int cmd
, void *arg
)
1596 case VIDIOC_QUERYCTRL
:
1598 const struct v4l2_queryctrl
*ctrl
;
1599 struct v4l2_queryctrl
*c
= arg
;
1601 if ((c
->id
< V4L2_CID_BASE
||
1602 c
->id
>= V4L2_CID_LASTP1
) &&
1603 (c
->id
< V4L2_CID_PRIVATE_BASE
||
1604 c
->id
>= V4L2_CID_PRIVATE_LASTP1
))
1606 ctrl
= ctrl_by_id(c
->id
);
1607 *c
= (NULL
!= ctrl
) ? *ctrl
: no_ctrl
;
1611 return get_control(dev
,arg
);
1614 mutex_lock(&dev
->lock
);
1615 err
= set_control(dev
,NULL
,arg
);
1616 mutex_unlock(&dev
->lock
);
1619 /* --- input switching --------------------------------------- */
1620 case VIDIOC_ENUMINPUT
:
1622 struct v4l2_input
*i
= arg
;
1626 if (n
>= SAA7134_INPUT_MAX
)
1628 if (NULL
== card_in(dev
,i
->index
).name
)
1630 memset(i
,0,sizeof(*i
));
1632 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
1633 strcpy(i
->name
,card_in(dev
,n
).name
);
1634 if (card_in(dev
,n
).tv
)
1635 i
->type
= V4L2_INPUT_TYPE_TUNER
;
1637 if (n
== dev
->ctl_input
) {
1638 int v1
= saa_readb(SAA7134_STATUS_VIDEO1
);
1639 int v2
= saa_readb(SAA7134_STATUS_VIDEO2
);
1641 if (0 != (v1
& 0x40))
1642 i
->status
|= V4L2_IN_ST_NO_H_LOCK
;
1643 if (0 != (v2
& 0x40))
1644 i
->status
|= V4L2_IN_ST_NO_SYNC
;
1645 if (0 != (v2
& 0x0e))
1646 i
->status
|= V4L2_IN_ST_MACROVISION
;
1648 for (n
= 0; n
< TVNORMS
; n
++)
1649 i
->std
|= tvnorms
[n
].id
;
1652 case VIDIOC_G_INPUT
:
1655 *i
= dev
->ctl_input
;
1658 case VIDIOC_S_INPUT
:
1662 if (*i
< 0 || *i
>= SAA7134_INPUT_MAX
)
1664 if (NULL
== card_in(dev
,*i
).name
)
1666 mutex_lock(&dev
->lock
);
1668 mutex_unlock(&dev
->lock
);
1675 EXPORT_SYMBOL(saa7134_common_ioctl
);
1678 * This function is _not_ called directly, but from
1679 * video_generic_ioctl (and maybe others). userspace
1680 * copying is done already, arg is a kernel pointer.
1682 static int video_do_ioctl(struct inode
*inode
, struct file
*file
,
1683 unsigned int cmd
, void *arg
)
1685 struct saa7134_fh
*fh
= file
->private_data
;
1686 struct saa7134_dev
*dev
= fh
->dev
;
1687 unsigned long flags
;
1690 if (video_debug
> 1)
1691 v4l_print_ioctl(dev
->name
,cmd
);
1696 case VIDIOC_S_INPUT
:
1697 case VIDIOC_S_TUNER
:
1698 case VIDIOC_S_FREQUENCY
:
1699 err
= v4l2_prio_check(&dev
->prio
,&fh
->prio
);
1705 case VIDIOC_QUERYCAP
:
1707 struct v4l2_capability
*cap
= arg
;
1708 unsigned int tuner_type
= dev
->tuner_type
;
1710 memset(cap
,0,sizeof(*cap
));
1711 strcpy(cap
->driver
, "saa7134");
1712 strlcpy(cap
->card
, saa7134_boards
[dev
->board
].name
,
1714 sprintf(cap
->bus_info
,"PCI:%s",pci_name(dev
->pci
));
1715 cap
->version
= SAA7134_VERSION_CODE
;
1717 V4L2_CAP_VIDEO_CAPTURE
|
1718 V4L2_CAP_VIDEO_OVERLAY
|
1719 V4L2_CAP_VBI_CAPTURE
|
1720 V4L2_CAP_READWRITE
|
1721 V4L2_CAP_STREAMING
|
1724 if ((tuner_type
== TUNER_ABSENT
) || (tuner_type
== UNSET
))
1725 cap
->capabilities
&= ~V4L2_CAP_TUNER
;
1730 /* --- tv standards ------------------------------------------ */
1731 case VIDIOC_ENUMSTD
:
1733 struct v4l2_standard
*e
= arg
;
1739 err
= v4l2_video_std_construct(e
, tvnorms
[e
->index
].id
,
1740 tvnorms
[e
->index
].name
);
1748 v4l2_std_id
*id
= arg
;
1750 *id
= dev
->tvnorm
->id
;
1755 v4l2_std_id
*id
= arg
;
1758 for (i
= 0; i
< TVNORMS
; i
++)
1759 if (*id
== tvnorms
[i
].id
)
1762 for (i
= 0; i
< TVNORMS
; i
++)
1763 if (*id
& tvnorms
[i
].id
)
1768 mutex_lock(&dev
->lock
);
1769 if (res_check(fh
, RESOURCE_OVERLAY
)) {
1770 spin_lock_irqsave(&dev
->slock
,flags
);
1771 stop_preview(dev
,fh
);
1772 set_tvnorm(dev
,&tvnorms
[i
]);
1773 start_preview(dev
,fh
);
1774 spin_unlock_irqrestore(&dev
->slock
,flags
);
1776 set_tvnorm(dev
,&tvnorms
[i
]);
1777 saa7134_tvaudio_do_scan(dev
);
1778 mutex_unlock(&dev
->lock
);
1782 case VIDIOC_CROPCAP
:
1784 struct v4l2_cropcap
*cap
= arg
;
1786 if (cap
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1787 cap
->type
!= V4L2_BUF_TYPE_VIDEO_OVERLAY
)
1789 cap
->bounds
= dev
->crop_bounds
;
1790 cap
->defrect
= dev
->crop_defrect
;
1791 cap
->pixelaspect
.numerator
= 1;
1792 cap
->pixelaspect
.denominator
= 1;
1793 if (dev
->tvnorm
->id
& V4L2_STD_525_60
) {
1794 cap
->pixelaspect
.numerator
= 11;
1795 cap
->pixelaspect
.denominator
= 10;
1797 if (dev
->tvnorm
->id
& V4L2_STD_625_50
) {
1798 cap
->pixelaspect
.numerator
= 54;
1799 cap
->pixelaspect
.denominator
= 59;
1806 struct v4l2_crop
* crop
= arg
;
1808 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1809 crop
->type
!= V4L2_BUF_TYPE_VIDEO_OVERLAY
)
1811 crop
->c
= dev
->crop_current
;
1816 struct v4l2_crop
*crop
= arg
;
1817 struct v4l2_rect
*b
= &dev
->crop_bounds
;
1819 if (crop
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
&&
1820 crop
->type
!= V4L2_BUF_TYPE_VIDEO_OVERLAY
)
1822 if (crop
->c
.height
< 0)
1824 if (crop
->c
.width
< 0)
1827 if (res_locked(fh
->dev
,RESOURCE_OVERLAY
))
1829 if (res_locked(fh
->dev
,RESOURCE_VIDEO
))
1832 if (crop
->c
.top
< b
->top
)
1833 crop
->c
.top
= b
->top
;
1834 if (crop
->c
.top
> b
->top
+ b
->height
)
1835 crop
->c
.top
= b
->top
+ b
->height
;
1836 if (crop
->c
.height
> b
->top
- crop
->c
.top
+ b
->height
)
1837 crop
->c
.height
= b
->top
- crop
->c
.top
+ b
->height
;
1839 if (crop
->c
.left
< b
->left
)
1840 crop
->c
.left
= b
->left
;
1841 if (crop
->c
.left
> b
->left
+ b
->width
)
1842 crop
->c
.left
= b
->left
+ b
->width
;
1843 if (crop
->c
.width
> b
->left
- crop
->c
.left
+ b
->width
)
1844 crop
->c
.width
= b
->left
- crop
->c
.left
+ b
->width
;
1846 dev
->crop_current
= crop
->c
;
1850 /* --- tuner ioctls ------------------------------------------ */
1851 case VIDIOC_G_TUNER
:
1853 struct v4l2_tuner
*t
= arg
;
1858 memset(t
,0,sizeof(*t
));
1859 for (n
= 0; n
< SAA7134_INPUT_MAX
; n
++)
1860 if (card_in(dev
,n
).tv
)
1862 if (NULL
!= card_in(dev
,n
).name
) {
1863 strcpy(t
->name
, "Television");
1864 t
->type
= V4L2_TUNER_ANALOG_TV
;
1865 t
->capability
= V4L2_TUNER_CAP_NORM
|
1866 V4L2_TUNER_CAP_STEREO
|
1867 V4L2_TUNER_CAP_LANG1
|
1868 V4L2_TUNER_CAP_LANG2
;
1869 t
->rangehigh
= 0xffffffffUL
;
1870 t
->rxsubchans
= saa7134_tvaudio_getstereo(dev
);
1871 t
->audmode
= saa7134_tvaudio_rx2mode(t
->rxsubchans
);
1873 if (0 != (saa_readb(SAA7134_STATUS_VIDEO1
) & 0x03))
1877 case VIDIOC_S_TUNER
:
1879 struct v4l2_tuner
*t
= arg
;
1882 mode
= dev
->thread
.mode
;
1883 if (UNSET
== mode
) {
1884 rx
= saa7134_tvaudio_getstereo(dev
);
1885 mode
= saa7134_tvaudio_rx2mode(t
->rxsubchans
);
1887 if (mode
!= t
->audmode
) {
1888 dev
->thread
.mode
= t
->audmode
;
1892 case VIDIOC_G_FREQUENCY
:
1894 struct v4l2_frequency
*f
= arg
;
1896 memset(f
,0,sizeof(*f
));
1897 f
->type
= fh
->radio
? V4L2_TUNER_RADIO
: V4L2_TUNER_ANALOG_TV
;
1898 f
->frequency
= dev
->ctl_freq
;
1901 case VIDIOC_S_FREQUENCY
:
1903 struct v4l2_frequency
*f
= arg
;
1907 if (0 == fh
->radio
&& V4L2_TUNER_ANALOG_TV
!= f
->type
)
1909 if (1 == fh
->radio
&& V4L2_TUNER_RADIO
!= f
->type
)
1911 mutex_lock(&dev
->lock
);
1912 dev
->ctl_freq
= f
->frequency
;
1914 saa7134_i2c_call_clients(dev
,VIDIOC_S_FREQUENCY
,f
);
1916 saa7134_tvaudio_do_scan(dev
);
1917 mutex_unlock(&dev
->lock
);
1921 /* --- control ioctls ---------------------------------------- */
1922 case VIDIOC_ENUMINPUT
:
1923 case VIDIOC_G_INPUT
:
1924 case VIDIOC_S_INPUT
:
1925 case VIDIOC_QUERYCTRL
:
1928 return saa7134_common_ioctl(dev
, cmd
, arg
);
1930 case VIDIOC_G_AUDIO
:
1932 struct v4l2_audio
*a
= arg
;
1934 memset(a
,0,sizeof(*a
));
1935 strcpy(a
->name
,"audio");
1938 case VIDIOC_S_AUDIO
:
1942 struct v4l2_captureparm
*parm
= arg
;
1943 memset(parm
,0,sizeof(*parm
));
1947 case VIDIOC_G_PRIORITY
:
1949 enum v4l2_priority
*p
= arg
;
1951 *p
= v4l2_prio_max(&dev
->prio
);
1954 case VIDIOC_S_PRIORITY
:
1956 enum v4l2_priority
*prio
= arg
;
1958 return v4l2_prio_change(&dev
->prio
, &fh
->prio
, *prio
);
1961 /* --- preview ioctls ---------------------------------------- */
1962 case VIDIOC_ENUM_FMT
:
1964 struct v4l2_fmtdesc
*f
= arg
;
1965 enum v4l2_buf_type type
;
1971 case V4L2_BUF_TYPE_VIDEO_CAPTURE
:
1972 case V4L2_BUF_TYPE_VIDEO_OVERLAY
:
1973 if (index
>= FORMATS
)
1975 if (f
->type
== V4L2_BUF_TYPE_VIDEO_OVERLAY
&&
1976 formats
[index
].planar
)
1978 memset(f
,0,sizeof(*f
));
1981 strlcpy(f
->description
,formats
[index
].name
,sizeof(f
->description
));
1982 f
->pixelformat
= formats
[index
].fourcc
;
1984 case V4L2_BUF_TYPE_VBI_CAPTURE
:
1987 memset(f
,0,sizeof(*f
));
1990 f
->pixelformat
= V4L2_PIX_FMT_GREY
;
1991 strcpy(f
->description
,"vbi data");
2000 struct v4l2_framebuffer
*fb
= arg
;
2003 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
2008 struct v4l2_framebuffer
*fb
= arg
;
2009 struct saa7134_format
*fmt
;
2011 if(!capable(CAP_SYS_ADMIN
) &&
2012 !capable(CAP_SYS_RAWIO
))
2016 fmt
= format_by_fourcc(fb
->fmt
.pixelformat
);
2023 if (0 == dev
->ovbuf
.fmt
.bytesperline
)
2024 dev
->ovbuf
.fmt
.bytesperline
=
2025 dev
->ovbuf
.fmt
.width
*fmt
->depth
/8;
2028 case VIDIOC_OVERLAY
:
2033 if (!res_get(dev
,fh
,RESOURCE_OVERLAY
))
2035 spin_lock_irqsave(&dev
->slock
,flags
);
2036 start_preview(dev
,fh
);
2037 spin_unlock_irqrestore(&dev
->slock
,flags
);
2040 if (!res_check(fh
, RESOURCE_OVERLAY
))
2042 spin_lock_irqsave(&dev
->slock
,flags
);
2043 stop_preview(dev
,fh
);
2044 spin_unlock_irqrestore(&dev
->slock
,flags
);
2045 res_free(dev
,fh
,RESOURCE_OVERLAY
);
2050 /* --- capture ioctls ---------------------------------------- */
2053 struct v4l2_format
*f
= arg
;
2054 return saa7134_g_fmt(dev
,fh
,f
);
2058 struct v4l2_format
*f
= arg
;
2059 return saa7134_s_fmt(dev
,fh
,f
);
2061 case VIDIOC_TRY_FMT
:
2063 struct v4l2_format
*f
= arg
;
2064 return saa7134_try_fmt(dev
,fh
,f
);
2069 struct video_mbuf
*mbuf
= arg
;
2070 struct videobuf_queue
*q
;
2071 struct v4l2_requestbuffers req
;
2074 q
= saa7134_queue(fh
);
2075 memset(&req
,0,sizeof(req
));
2077 req
.count
= gbuffers
;
2078 req
.memory
= V4L2_MEMORY_MMAP
;
2079 err
= videobuf_reqbufs(q
,&req
);
2082 memset(mbuf
,0,sizeof(*mbuf
));
2083 mbuf
->frames
= req
.count
;
2085 for (i
= 0; i
< mbuf
->frames
; i
++) {
2086 mbuf
->offsets
[i
] = q
->bufs
[i
]->boff
;
2087 mbuf
->size
+= q
->bufs
[i
]->bsize
;
2092 case VIDIOC_REQBUFS
:
2093 return videobuf_reqbufs(saa7134_queue(fh
),arg
);
2095 case VIDIOC_QUERYBUF
:
2096 return videobuf_querybuf(saa7134_queue(fh
),arg
);
2099 return videobuf_qbuf(saa7134_queue(fh
),arg
);
2102 return videobuf_dqbuf(saa7134_queue(fh
),arg
,
2103 file
->f_flags
& O_NONBLOCK
);
2105 case VIDIOC_STREAMON
:
2107 int res
= saa7134_resource(fh
);
2109 if (!res_get(dev
,fh
,res
))
2111 return videobuf_streamon(saa7134_queue(fh
));
2113 case VIDIOC_STREAMOFF
:
2115 int res
= saa7134_resource(fh
);
2117 err
= videobuf_streamoff(saa7134_queue(fh
));
2120 res_free(dev
,fh
,res
);
2125 return v4l_compat_translate_ioctl(inode
,file
,cmd
,arg
,
2131 static int video_ioctl(struct inode
*inode
, struct file
*file
,
2132 unsigned int cmd
, unsigned long arg
)
2134 return video_usercopy(inode
, file
, cmd
, arg
, video_do_ioctl
);
2137 static int radio_do_ioctl(struct inode
*inode
, struct file
*file
,
2138 unsigned int cmd
, void *arg
)
2140 struct saa7134_fh
*fh
= file
->private_data
;
2141 struct saa7134_dev
*dev
= fh
->dev
;
2143 if (video_debug
> 1)
2144 v4l_print_ioctl(dev
->name
,cmd
);
2146 case VIDIOC_QUERYCAP
:
2148 struct v4l2_capability
*cap
= arg
;
2150 memset(cap
,0,sizeof(*cap
));
2151 strcpy(cap
->driver
, "saa7134");
2152 strlcpy(cap
->card
, saa7134_boards
[dev
->board
].name
,
2154 sprintf(cap
->bus_info
,"PCI:%s",pci_name(dev
->pci
));
2155 cap
->version
= SAA7134_VERSION_CODE
;
2156 cap
->capabilities
= V4L2_CAP_TUNER
;
2159 case VIDIOC_G_TUNER
:
2161 struct v4l2_tuner
*t
= arg
;
2166 memset(t
,0,sizeof(*t
));
2167 strcpy(t
->name
, "Radio");
2168 t
->type
= V4L2_TUNER_RADIO
;
2170 saa7134_i2c_call_clients(dev
, VIDIOC_G_TUNER
, t
);
2174 case VIDIOC_S_TUNER
:
2176 struct v4l2_tuner
*t
= arg
;
2181 saa7134_i2c_call_clients(dev
,VIDIOC_S_TUNER
,t
);
2185 case VIDIOC_ENUMINPUT
:
2187 struct v4l2_input
*i
= arg
;
2191 strcpy(i
->name
,"Radio");
2192 i
->type
= V4L2_INPUT_TYPE_TUNER
;
2195 case VIDIOC_G_INPUT
:
2201 case VIDIOC_G_AUDIO
:
2203 struct v4l2_audio
*a
= arg
;
2205 memset(a
,0,sizeof(*a
));
2206 strcpy(a
->name
,"Radio");
2211 v4l2_std_id
*id
= arg
;
2215 case VIDIOC_S_AUDIO
:
2216 case VIDIOC_S_INPUT
:
2220 case VIDIOC_QUERYCTRL
:
2222 const struct v4l2_queryctrl
*ctrl
;
2223 struct v4l2_queryctrl
*c
= arg
;
2225 if (c
->id
< V4L2_CID_BASE
||
2226 c
->id
>= V4L2_CID_LASTP1
)
2228 if (c
->id
== V4L2_CID_AUDIO_MUTE
) {
2229 ctrl
= ctrl_by_id(c
->id
);
2238 case VIDIOC_G_FREQUENCY
:
2239 case VIDIOC_S_FREQUENCY
:
2240 return video_do_ioctl(inode
,file
,cmd
,arg
);
2243 return v4l_compat_translate_ioctl(inode
,file
,cmd
,arg
,
2249 static int radio_ioctl(struct inode
*inode
, struct file
*file
,
2250 unsigned int cmd
, unsigned long arg
)
2252 return video_usercopy(inode
, file
, cmd
, arg
, radio_do_ioctl
);
2255 static struct file_operations video_fops
=
2257 .owner
= THIS_MODULE
,
2259 .release
= video_release
,
2263 .ioctl
= video_ioctl
,
2264 .compat_ioctl
= v4l_compat_ioctl32
,
2265 .llseek
= no_llseek
,
2268 static struct file_operations radio_fops
=
2270 .owner
= THIS_MODULE
,
2272 .release
= video_release
,
2273 .ioctl
= radio_ioctl
,
2274 .compat_ioctl
= v4l_compat_ioctl32
,
2275 .llseek
= no_llseek
,
2278 /* ----------------------------------------------------------- */
2279 /* exported stuff */
2281 struct video_device saa7134_video_template
=
2283 .name
= "saa7134-video",
2284 .type
= VID_TYPE_CAPTURE
|VID_TYPE_TUNER
|VID_TYPE_OVERLAY
|
2285 VID_TYPE_CLIPPING
|VID_TYPE_SCALES
,
2287 .fops
= &video_fops
,
2291 struct video_device saa7134_vbi_template
=
2293 .name
= "saa7134-vbi",
2294 .type
= VID_TYPE_TUNER
|VID_TYPE_TELETEXT
,
2296 .fops
= &video_fops
,
2300 struct video_device saa7134_radio_template
=
2302 .name
= "saa7134-radio",
2303 .type
= VID_TYPE_TUNER
,
2305 .fops
= &radio_fops
,
2309 int saa7134_video_init1(struct saa7134_dev
*dev
)
2311 /* sanitycheck insmod options */
2312 if (gbuffers
< 2 || gbuffers
> VIDEO_MAX_FRAME
)
2314 if (gbufsize
< 0 || gbufsize
> gbufsize_max
)
2315 gbufsize
= gbufsize_max
;
2316 gbufsize
= (gbufsize
+ PAGE_SIZE
- 1) & PAGE_MASK
;
2318 /* put some sensible defaults into the data structures ... */
2319 dev
->ctl_bright
= ctrl_by_id(V4L2_CID_BRIGHTNESS
)->default_value
;
2320 dev
->ctl_contrast
= ctrl_by_id(V4L2_CID_CONTRAST
)->default_value
;
2321 dev
->ctl_hue
= ctrl_by_id(V4L2_CID_HUE
)->default_value
;
2322 dev
->ctl_saturation
= ctrl_by_id(V4L2_CID_SATURATION
)->default_value
;
2323 dev
->ctl_volume
= ctrl_by_id(V4L2_CID_AUDIO_VOLUME
)->default_value
;
2324 dev
->ctl_mute
= 1; // ctrl_by_id(V4L2_CID_AUDIO_MUTE)->default_value;
2325 dev
->ctl_invert
= ctrl_by_id(V4L2_CID_PRIVATE_INVERT
)->default_value
;
2326 dev
->ctl_automute
= ctrl_by_id(V4L2_CID_PRIVATE_AUTOMUTE
)->default_value
;
2328 if (dev
->tda9887_conf
&& dev
->ctl_automute
)
2329 dev
->tda9887_conf
|= TDA9887_AUTOMUTE
;
2332 INIT_LIST_HEAD(&dev
->video_q
.queue
);
2333 init_timer(&dev
->video_q
.timeout
);
2334 dev
->video_q
.timeout
.function
= saa7134_buffer_timeout
;
2335 dev
->video_q
.timeout
.data
= (unsigned long)(&dev
->video_q
);
2336 dev
->video_q
.dev
= dev
;
2338 if (saa7134_boards
[dev
->board
].video_out
) {
2339 /* enable video output */
2340 int vo
= saa7134_boards
[dev
->board
].video_out
;
2342 unsigned int vid_port_opts
= saa7134_boards
[dev
->board
].vid_port_opts
;
2343 saa_writeb(SAA7134_VIDEO_PORT_CTRL0
, video_out
[vo
][0]);
2344 video_reg
= video_out
[vo
][1];
2345 if (vid_port_opts
& SET_T_CODE_POLARITY_NON_INVERTED
)
2346 video_reg
&= ~VP_T_CODE_P_INVERTED
;
2347 saa_writeb(SAA7134_VIDEO_PORT_CTRL1
, video_reg
);
2348 saa_writeb(SAA7134_VIDEO_PORT_CTRL2
, video_out
[vo
][2]);
2349 saa_writeb(SAA7134_VIDEO_PORT_CTRL3
, video_out
[vo
][3]);
2350 saa_writeb(SAA7134_VIDEO_PORT_CTRL4
, video_out
[vo
][4]);
2351 video_reg
= video_out
[vo
][5];
2352 if (vid_port_opts
& SET_CLOCK_NOT_DELAYED
)
2353 video_reg
&= ~VP_CLK_CTRL2_DELAYED
;
2354 if (vid_port_opts
& SET_CLOCK_INVERTED
)
2355 video_reg
|= VP_CLK_CTRL1_INVERTED
;
2356 saa_writeb(SAA7134_VIDEO_PORT_CTRL5
, video_reg
);
2357 video_reg
= video_out
[vo
][6];
2358 if (vid_port_opts
& SET_VSYNC_OFF
) {
2359 video_reg
&= ~VP_VS_TYPE_MASK
;
2360 video_reg
|= VP_VS_TYPE_OFF
;
2362 saa_writeb(SAA7134_VIDEO_PORT_CTRL6
, video_reg
);
2363 saa_writeb(SAA7134_VIDEO_PORT_CTRL7
, video_out
[vo
][7]);
2364 saa_writeb(SAA7134_VIDEO_PORT_CTRL8
, video_out
[vo
][8]);
2370 int saa7134_video_init2(struct saa7134_dev
*dev
)
2373 set_tvnorm(dev
,&tvnorms
[0]);
2375 saa7134_tvaudio_setmute(dev
);
2376 saa7134_tvaudio_setvolume(dev
,dev
->ctl_volume
);
2380 int saa7134_video_fini(struct saa7134_dev
*dev
)
2386 void saa7134_irq_video_intl(struct saa7134_dev
*dev
)
2388 static const char *st
[] = {
2389 "(no signal)", "NTSC", "PAL", "SECAM" };
2392 st1
= saa_readb(SAA7134_STATUS_VIDEO1
);
2393 st2
= saa_readb(SAA7134_STATUS_VIDEO2
);
2394 dprintk("DCSDT: pll: %s, sync: %s, norm: %s\n",
2395 (st1
& 0x40) ? "not locked" : "locked",
2396 (st2
& 0x40) ? "no" : "yes",
2398 dev
->nosignal
= (st1
& 0x40) || (st2
& 0x40);
2400 if (dev
->nosignal
) {
2401 /* no video signal -> mute audio */
2402 if (dev
->ctl_automute
)
2404 saa7134_tvaudio_setmute(dev
);
2405 saa_setb(SAA7134_SYNC_CTRL
, 0x20);
2407 /* wake up tvaudio audio carrier scan thread */
2408 saa7134_tvaudio_do_scan(dev
);
2410 saa_clearb(SAA7134_SYNC_CTRL
, 0x20);
2412 if (dev
->mops
&& dev
->mops
->signal_change
)
2413 dev
->mops
->signal_change(dev
);
2416 void saa7134_irq_video_done(struct saa7134_dev
*dev
, unsigned long status
)
2418 enum v4l2_field field
;
2420 spin_lock(&dev
->slock
);
2421 if (dev
->video_q
.curr
) {
2422 dev
->video_fieldcount
++;
2423 field
= dev
->video_q
.curr
->vb
.field
;
2424 if (V4L2_FIELD_HAS_BOTH(field
)) {
2425 /* make sure we have seen both fields */
2426 if ((status
& 0x10) == 0x00) {
2427 dev
->video_q
.curr
->top_seen
= 1;
2430 if (!dev
->video_q
.curr
->top_seen
)
2432 } else if (field
== V4L2_FIELD_TOP
) {
2433 if ((status
& 0x10) != 0x10)
2435 } else if (field
== V4L2_FIELD_BOTTOM
) {
2436 if ((status
& 0x10) != 0x00)
2439 dev
->video_q
.curr
->vb
.field_count
= dev
->video_fieldcount
;
2440 saa7134_buffer_finish(dev
,&dev
->video_q
,STATE_DONE
);
2442 saa7134_buffer_next(dev
,&dev
->video_q
);
2445 spin_unlock(&dev
->slock
);
2448 /* ----------------------------------------------------------- */