3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "ivtv-driver.h"
22 #include "ivtv-version.h"
23 #include "ivtv-mailbox.h"
25 #include "ivtv-queue.h"
26 #include "ivtv-fileops.h"
28 #include "ivtv-routing.h"
29 #include "ivtv-streams.h"
31 #include "ivtv-ioctl.h"
32 #include "ivtv-gpio.h"
33 #include "ivtv-controls.h"
34 #include "ivtv-cards.h"
35 #include <media/i2c/saa7127.h>
36 #include <media/tveeprom.h>
37 #include <media/v4l2-event.h>
38 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
39 #include <linux/dvb/audio.h>
40 #include <linux/dvb/video.h>
43 u16
ivtv_service2vbi(int type
)
46 case V4L2_SLICED_TELETEXT_B
:
47 return IVTV_SLICED_TYPE_TELETEXT_B
;
48 case V4L2_SLICED_CAPTION_525
:
49 return IVTV_SLICED_TYPE_CAPTION_525
;
50 case V4L2_SLICED_WSS_625
:
51 return IVTV_SLICED_TYPE_WSS_625
;
53 return IVTV_SLICED_TYPE_VPS
;
59 static int valid_service_line(int field
, int line
, int is_pal
)
61 return (is_pal
&& line
>= 6 && (line
!= 23 || field
== 0)) ||
62 (!is_pal
&& line
>= 10 && line
< 22);
65 static u16
select_service_from_set(int field
, int line
, u16 set
, int is_pal
)
67 u16 valid_set
= (is_pal
? V4L2_SLICED_VBI_625
: V4L2_SLICED_VBI_525
);
70 set
= set
& valid_set
;
71 if (set
== 0 || !valid_service_line(field
, line
, is_pal
)) {
75 if (line
== 21 && (set
& V4L2_SLICED_CAPTION_525
))
76 return V4L2_SLICED_CAPTION_525
;
79 if (line
== 16 && field
== 0 && (set
& V4L2_SLICED_VPS
))
80 return V4L2_SLICED_VPS
;
81 if (line
== 23 && field
== 0 && (set
& V4L2_SLICED_WSS_625
))
82 return V4L2_SLICED_WSS_625
;
86 for (i
= 0; i
< 32; i
++) {
93 void ivtv_expand_service_set(struct v4l2_sliced_vbi_format
*fmt
, int is_pal
)
95 u16 set
= fmt
->service_set
;
99 for (f
= 0; f
< 2; f
++) {
100 for (l
= 0; l
< 24; l
++) {
101 fmt
->service_lines
[f
][l
] = select_service_from_set(f
, l
, set
, is_pal
);
106 static void check_service_set(struct v4l2_sliced_vbi_format
*fmt
, int is_pal
)
110 for (f
= 0; f
< 2; f
++) {
111 for (l
= 0; l
< 24; l
++) {
112 fmt
->service_lines
[f
][l
] = select_service_from_set(f
, l
, fmt
->service_lines
[f
][l
], is_pal
);
117 u16
ivtv_get_service_set(struct v4l2_sliced_vbi_format
*fmt
)
122 for (f
= 0; f
< 2; f
++) {
123 for (l
= 0; l
< 24; l
++) {
124 set
|= fmt
->service_lines
[f
][l
];
130 void ivtv_set_osd_alpha(struct ivtv
*itv
)
132 ivtv_vapi(itv
, CX2341X_OSD_SET_GLOBAL_ALPHA
, 3,
133 itv
->osd_global_alpha_state
, itv
->osd_global_alpha
, !itv
->osd_local_alpha_state
);
134 ivtv_vapi(itv
, CX2341X_OSD_SET_CHROMA_KEY
, 2, itv
->osd_chroma_key_state
, itv
->osd_chroma_key
);
137 int ivtv_set_speed(struct ivtv
*itv
, int speed
)
139 u32 data
[CX2341X_MBOX_MAX_DATA
];
140 int single_step
= (speed
== 1 || speed
== -1);
143 if (speed
== 0) speed
= 1000;
146 if (speed
== itv
->speed
&& !single_step
)
149 if (single_step
&& (speed
< 0) == (itv
->speed
< 0)) {
150 /* Single step video and no need to change direction */
151 ivtv_vapi(itv
, CX2341X_DEC_STEP_VIDEO
, 1, 0);
156 /* Need to change direction */
157 speed
= speed
< 0 ? -1000 : 1000;
159 data
[0] = (speed
> 1000 || speed
< -1000) ? 0x80000000 : 0;
160 data
[0] |= (speed
> 1000 || speed
< -1500) ? 0x40000000 : 0;
161 data
[1] = (speed
< 0);
162 data
[2] = speed
< 0 ? 3 : 7;
163 data
[3] = v4l2_ctrl_g_ctrl(itv
->cxhdl
.video_b_frames
);
164 data
[4] = (speed
== 1500 || speed
== 500) ? itv
->speed_mute_audio
: 0;
168 if (speed
== 1500 || speed
== -1500) data
[0] |= 1;
169 else if (speed
== 2000 || speed
== -2000) data
[0] |= 2;
170 else if (speed
> -1000 && speed
< 0) data
[0] |= (-1000 / speed
);
171 else if (speed
< 1000 && speed
> 0) data
[0] |= (1000 / speed
);
173 /* If not decoding, just change speed setting */
174 if (atomic_read(&itv
->decoding
) > 0) {
177 /* Stop all DMA and decoding activity */
178 ivtv_vapi(itv
, CX2341X_DEC_PAUSE_PLAYBACK
, 1, 0);
180 /* Wait for any DMA to finish */
181 mutex_unlock(&itv
->serialize_lock
);
182 prepare_to_wait(&itv
->dma_waitq
, &wait
, TASK_INTERRUPTIBLE
);
183 while (test_bit(IVTV_F_I_DMA
, &itv
->i_flags
)) {
184 got_sig
= signal_pending(current
);
190 finish_wait(&itv
->dma_waitq
, &wait
);
191 mutex_lock(&itv
->serialize_lock
);
195 /* Change Speed safely */
196 ivtv_api(itv
, CX2341X_DEC_SET_PLAYBACK_SPEED
, 7, data
);
197 IVTV_DEBUG_INFO("Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
198 data
[0], data
[1], data
[2], data
[3], data
[4], data
[5], data
[6]);
201 speed
= (speed
< 0) ? -1 : 1;
202 ivtv_vapi(itv
, CX2341X_DEC_STEP_VIDEO
, 1, 0);
208 static int ivtv_validate_speed(int cur_speed
, int new_speed
)
210 int fact
= new_speed
< 0 ? -1 : 1;
216 new_speed
= -new_speed
;
218 cur_speed
= -cur_speed
;
220 if (cur_speed
<= new_speed
) {
221 if (new_speed
> 1500)
223 if (new_speed
> 1000)
227 if (new_speed
>= 2000)
229 if (new_speed
>= 1500)
231 if (new_speed
>= 1000)
236 if (new_speed
== 1 || new_speed
== 1000)
237 return fact
* new_speed
;
240 new_speed
= 1000 / new_speed
;
241 if (1000 / cur_speed
== new_speed
)
242 new_speed
+= (cur_speed
< s
) ? -1 : 1;
243 if (new_speed
> 60) return 1000 / (fact
* 60);
244 return 1000 / (fact
* new_speed
);
247 static int ivtv_video_command(struct ivtv
*itv
, struct ivtv_open_id
*id
,
248 struct v4l2_decoder_cmd
*dc
, int try)
250 struct ivtv_stream
*s
= &itv
->streams
[IVTV_DEC_STREAM_TYPE_MPG
];
252 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
256 case V4L2_DEC_CMD_START
: {
257 dc
->flags
&= V4L2_DEC_CMD_START_MUTE_AUDIO
;
258 dc
->start
.speed
= ivtv_validate_speed(itv
->speed
, dc
->start
.speed
);
259 if (dc
->start
.speed
< 0)
260 dc
->start
.format
= V4L2_DEC_START_FMT_GOP
;
262 dc
->start
.format
= V4L2_DEC_START_FMT_NONE
;
263 if (dc
->start
.speed
!= 500 && dc
->start
.speed
!= 1500)
264 dc
->flags
= dc
->start
.speed
== 1000 ? 0 :
265 V4L2_DEC_CMD_START_MUTE_AUDIO
;
268 itv
->speed_mute_audio
= dc
->flags
& V4L2_DEC_CMD_START_MUTE_AUDIO
;
269 if (ivtv_set_output_mode(itv
, OUT_MPG
) != OUT_MPG
)
271 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
)) {
272 /* forces ivtv_set_speed to be called */
275 return ivtv_start_decoding(id
, dc
->start
.speed
);
278 case V4L2_DEC_CMD_STOP
:
279 dc
->flags
&= V4L2_DEC_CMD_STOP_IMMEDIATELY
| V4L2_DEC_CMD_STOP_TO_BLACK
;
280 if (dc
->flags
& V4L2_DEC_CMD_STOP_IMMEDIATELY
)
283 if (atomic_read(&itv
->decoding
) == 0)
285 if (itv
->output_mode
!= OUT_MPG
)
288 itv
->output_mode
= OUT_NONE
;
289 return ivtv_stop_v4l2_decode_stream(s
, dc
->flags
, dc
->stop
.pts
);
291 case V4L2_DEC_CMD_PAUSE
:
292 dc
->flags
&= V4L2_DEC_CMD_PAUSE_TO_BLACK
;
294 if (!atomic_read(&itv
->decoding
))
296 if (itv
->output_mode
!= OUT_MPG
)
298 if (atomic_read(&itv
->decoding
) > 0) {
299 ivtv_vapi(itv
, CX2341X_DEC_PAUSE_PLAYBACK
, 1,
300 (dc
->flags
& V4L2_DEC_CMD_PAUSE_TO_BLACK
) ? 1 : 0);
301 set_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
);
305 case V4L2_DEC_CMD_RESUME
:
308 if (!atomic_read(&itv
->decoding
))
310 if (itv
->output_mode
!= OUT_MPG
)
312 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
)) {
313 int speed
= itv
->speed
;
315 return ivtv_start_decoding(id
, speed
);
325 static int ivtv_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
327 struct ivtv
*itv
= fh2id(fh
)->itv
;
328 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
330 vbifmt
->reserved
[0] = 0;
331 vbifmt
->reserved
[1] = 0;
332 if (!(itv
->v4l2_cap
& V4L2_CAP_SLICED_VBI_OUTPUT
))
334 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
335 memset(vbifmt
->service_lines
, 0, sizeof(vbifmt
->service_lines
));
337 vbifmt
->service_lines
[0][21] = V4L2_SLICED_CAPTION_525
;
338 vbifmt
->service_lines
[1][21] = V4L2_SLICED_CAPTION_525
;
340 vbifmt
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
341 vbifmt
->service_lines
[0][16] = V4L2_SLICED_VPS
;
343 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
347 static int ivtv_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
349 struct ivtv_open_id
*id
= fh2id(fh
);
350 struct ivtv
*itv
= id
->itv
;
351 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
353 pixfmt
->width
= itv
->cxhdl
.width
;
354 pixfmt
->height
= itv
->cxhdl
.height
;
355 pixfmt
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
356 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
357 if (id
->type
== IVTV_ENC_STREAM_TYPE_YUV
) {
358 pixfmt
->pixelformat
= V4L2_PIX_FMT_HM12
;
359 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
360 pixfmt
->sizeimage
= pixfmt
->height
* 720 * 3 / 2;
361 pixfmt
->bytesperline
= 720;
363 pixfmt
->pixelformat
= V4L2_PIX_FMT_MPEG
;
364 pixfmt
->sizeimage
= 128 * 1024;
365 pixfmt
->bytesperline
= 0;
370 static int ivtv_g_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
372 struct ivtv
*itv
= fh2id(fh
)->itv
;
373 struct v4l2_vbi_format
*vbifmt
= &fmt
->fmt
.vbi
;
375 vbifmt
->sampling_rate
= 27000000;
376 vbifmt
->offset
= 248;
377 vbifmt
->samples_per_line
= itv
->vbi
.raw_decoder_line_size
- 4;
378 vbifmt
->sample_format
= V4L2_PIX_FMT_GREY
;
379 vbifmt
->start
[0] = itv
->vbi
.start
[0];
380 vbifmt
->start
[1] = itv
->vbi
.start
[1];
381 vbifmt
->count
[0] = vbifmt
->count
[1] = itv
->vbi
.count
;
383 vbifmt
->reserved
[0] = 0;
384 vbifmt
->reserved
[1] = 0;
388 static int ivtv_g_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
390 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
391 struct ivtv_open_id
*id
= fh2id(fh
);
392 struct ivtv
*itv
= id
->itv
;
394 vbifmt
->reserved
[0] = 0;
395 vbifmt
->reserved
[1] = 0;
396 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
398 if (id
->type
== IVTV_DEC_STREAM_TYPE_VBI
) {
399 vbifmt
->service_set
= itv
->is_50hz
? V4L2_SLICED_VBI_625
:
401 ivtv_expand_service_set(vbifmt
, itv
->is_50hz
);
402 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
406 v4l2_subdev_call(itv
->sd_video
, vbi
, g_sliced_fmt
, vbifmt
);
407 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
411 static int ivtv_g_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
413 struct ivtv_open_id
*id
= fh2id(fh
);
414 struct ivtv
*itv
= id
->itv
;
415 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
417 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
419 pixfmt
->width
= itv
->main_rect
.width
;
420 pixfmt
->height
= itv
->main_rect
.height
;
421 pixfmt
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
422 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
423 if (id
->type
== IVTV_DEC_STREAM_TYPE_YUV
) {
424 switch (itv
->yuv_info
.lace_mode
& IVTV_YUV_MODE_MASK
) {
425 case IVTV_YUV_MODE_INTERLACED
:
426 pixfmt
->field
= (itv
->yuv_info
.lace_mode
& IVTV_YUV_SYNC_MASK
) ?
427 V4L2_FIELD_INTERLACED_BT
: V4L2_FIELD_INTERLACED_TB
;
429 case IVTV_YUV_MODE_PROGRESSIVE
:
430 pixfmt
->field
= V4L2_FIELD_NONE
;
433 pixfmt
->field
= V4L2_FIELD_ANY
;
436 pixfmt
->pixelformat
= V4L2_PIX_FMT_HM12
;
437 pixfmt
->bytesperline
= 720;
438 pixfmt
->width
= itv
->yuv_info
.v4l2_src_w
;
439 pixfmt
->height
= itv
->yuv_info
.v4l2_src_h
;
440 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
442 1080 * ((pixfmt
->height
+ 31) & ~31);
444 pixfmt
->pixelformat
= V4L2_PIX_FMT_MPEG
;
445 pixfmt
->sizeimage
= 128 * 1024;
446 pixfmt
->bytesperline
= 0;
451 static int ivtv_g_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
453 struct ivtv
*itv
= fh2id(fh
)->itv
;
454 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
455 struct v4l2_window
*winfmt
= &fmt
->fmt
.win
;
457 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
459 if (!itv
->osd_video_pbase
)
461 winfmt
->chromakey
= itv
->osd_chroma_key
;
462 winfmt
->global_alpha
= itv
->osd_global_alpha
;
463 winfmt
->field
= V4L2_FIELD_INTERLACED
;
464 winfmt
->clips
= NULL
;
465 winfmt
->clipcount
= 0;
466 winfmt
->bitmap
= NULL
;
467 winfmt
->w
.top
= winfmt
->w
.left
= 0;
468 winfmt
->w
.width
= itv
->osd_rect
.width
;
469 winfmt
->w
.height
= itv
->osd_rect
.height
;
473 static int ivtv_try_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
475 return ivtv_g_fmt_sliced_vbi_out(file
, fh
, fmt
);
478 static int ivtv_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
480 struct ivtv_open_id
*id
= fh2id(fh
);
481 struct ivtv
*itv
= id
->itv
;
482 int w
= fmt
->fmt
.pix
.width
;
483 int h
= fmt
->fmt
.pix
.height
;
488 if (id
->type
== IVTV_ENC_STREAM_TYPE_YUV
) {
489 /* YUV height must be a multiple of 32 */
493 h
= min(h
, itv
->is_50hz
? 576 : 480);
495 ivtv_g_fmt_vid_cap(file
, fh
, fmt
);
496 fmt
->fmt
.pix
.width
= w
;
497 fmt
->fmt
.pix
.height
= h
;
501 static int ivtv_try_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
503 return ivtv_g_fmt_vbi_cap(file
, fh
, fmt
);
506 static int ivtv_try_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
508 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
509 struct ivtv_open_id
*id
= fh2id(fh
);
510 struct ivtv
*itv
= id
->itv
;
512 if (id
->type
== IVTV_DEC_STREAM_TYPE_VBI
)
513 return ivtv_g_fmt_sliced_vbi_cap(file
, fh
, fmt
);
515 /* set sliced VBI capture format */
516 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
517 vbifmt
->reserved
[0] = 0;
518 vbifmt
->reserved
[1] = 0;
520 if (vbifmt
->service_set
)
521 ivtv_expand_service_set(vbifmt
, itv
->is_50hz
);
522 check_service_set(vbifmt
, itv
->is_50hz
);
523 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
527 static int ivtv_try_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
529 struct ivtv_open_id
*id
= fh2id(fh
);
530 s32 w
= fmt
->fmt
.pix
.width
;
531 s32 h
= fmt
->fmt
.pix
.height
;
532 int field
= fmt
->fmt
.pix
.field
;
533 int ret
= ivtv_g_fmt_vid_out(file
, fh
, fmt
);
537 /* Why can the height be 576 even when the output is NTSC?
539 Internally the buffers of the PVR350 are always set to 720x576. The
540 decoded video frame will always be placed in the top left corner of
541 this buffer. For any video which is not 720x576, the buffer will
542 then be cropped to remove the unused right and lower areas, with
543 the remaining image being scaled by the hardware to fit the display
544 area. The video can be scaled both up and down, so a 720x480 video
545 can be displayed full-screen on PAL and a 720x576 video can be
546 displayed without cropping on NTSC.
548 Note that the scaling only occurs on the video stream, the osd
549 resolution is locked to the broadcast standard and not scaled.
551 Thanks to Ian Armstrong for this explanation. */
554 if (id
->type
== IVTV_DEC_STREAM_TYPE_YUV
)
555 fmt
->fmt
.pix
.field
= field
;
556 fmt
->fmt
.pix
.width
= w
;
557 fmt
->fmt
.pix
.height
= h
;
561 static int ivtv_try_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
563 struct ivtv
*itv
= fh2id(fh
)->itv
;
564 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
565 u32 chromakey
= fmt
->fmt
.win
.chromakey
;
566 u8 global_alpha
= fmt
->fmt
.win
.global_alpha
;
568 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
570 if (!itv
->osd_video_pbase
)
572 ivtv_g_fmt_vid_out_overlay(file
, fh
, fmt
);
573 fmt
->fmt
.win
.chromakey
= chromakey
;
574 fmt
->fmt
.win
.global_alpha
= global_alpha
;
578 static int ivtv_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
580 return ivtv_g_fmt_sliced_vbi_out(file
, fh
, fmt
);
583 static int ivtv_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
585 struct ivtv_open_id
*id
= fh2id(fh
);
586 struct ivtv
*itv
= id
->itv
;
587 struct v4l2_subdev_format format
= {
588 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
590 int ret
= ivtv_try_fmt_vid_cap(file
, fh
, fmt
);
591 int w
= fmt
->fmt
.pix
.width
;
592 int h
= fmt
->fmt
.pix
.height
;
597 if (itv
->cxhdl
.width
== w
&& itv
->cxhdl
.height
== h
)
600 if (atomic_read(&itv
->capturing
) > 0)
603 itv
->cxhdl
.width
= w
;
604 itv
->cxhdl
.height
= h
;
605 if (v4l2_ctrl_g_ctrl(itv
->cxhdl
.video_encoding
) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1
)
606 fmt
->fmt
.pix
.width
/= 2;
607 format
.format
.width
= fmt
->fmt
.pix
.width
;
608 format
.format
.height
= h
;
609 format
.format
.code
= MEDIA_BUS_FMT_FIXED
;
610 v4l2_subdev_call(itv
->sd_video
, pad
, set_fmt
, NULL
, &format
);
611 return ivtv_g_fmt_vid_cap(file
, fh
, fmt
);
614 static int ivtv_s_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
616 struct ivtv
*itv
= fh2id(fh
)->itv
;
618 if (!ivtv_raw_vbi(itv
) && atomic_read(&itv
->capturing
) > 0)
620 itv
->vbi
.sliced_in
->service_set
= 0;
621 itv
->vbi
.in
.type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
622 v4l2_subdev_call(itv
->sd_video
, vbi
, s_raw_fmt
, &fmt
->fmt
.vbi
);
623 return ivtv_g_fmt_vbi_cap(file
, fh
, fmt
);
626 static int ivtv_s_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
628 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
629 struct ivtv_open_id
*id
= fh2id(fh
);
630 struct ivtv
*itv
= id
->itv
;
631 int ret
= ivtv_try_fmt_sliced_vbi_cap(file
, fh
, fmt
);
633 if (ret
|| id
->type
== IVTV_DEC_STREAM_TYPE_VBI
)
636 check_service_set(vbifmt
, itv
->is_50hz
);
637 if (ivtv_raw_vbi(itv
) && atomic_read(&itv
->capturing
) > 0)
639 itv
->vbi
.in
.type
= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
;
640 v4l2_subdev_call(itv
->sd_video
, vbi
, s_sliced_fmt
, vbifmt
);
641 memcpy(itv
->vbi
.sliced_in
, vbifmt
, sizeof(*itv
->vbi
.sliced_in
));
645 static int ivtv_s_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
647 struct ivtv_open_id
*id
= fh2id(fh
);
648 struct ivtv
*itv
= id
->itv
;
649 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
650 int ret
= ivtv_try_fmt_vid_out(file
, fh
, fmt
);
655 if (id
->type
!= IVTV_DEC_STREAM_TYPE_YUV
)
658 /* Return now if we already have some frame data */
662 yi
->v4l2_src_w
= fmt
->fmt
.pix
.width
;
663 yi
->v4l2_src_h
= fmt
->fmt
.pix
.height
;
665 switch (fmt
->fmt
.pix
.field
) {
666 case V4L2_FIELD_NONE
:
667 yi
->lace_mode
= IVTV_YUV_MODE_PROGRESSIVE
;
670 yi
->lace_mode
= IVTV_YUV_MODE_AUTO
;
672 case V4L2_FIELD_INTERLACED_BT
:
674 IVTV_YUV_MODE_INTERLACED
|IVTV_YUV_SYNC_ODD
;
676 case V4L2_FIELD_INTERLACED_TB
:
678 yi
->lace_mode
= IVTV_YUV_MODE_INTERLACED
;
681 yi
->lace_sync_field
= (yi
->lace_mode
& IVTV_YUV_SYNC_MASK
) == IVTV_YUV_SYNC_EVEN
? 0 : 1;
683 if (test_bit(IVTV_F_I_DEC_YUV
, &itv
->i_flags
))
684 itv
->dma_data_req_size
=
685 1080 * ((yi
->v4l2_src_h
+ 31) & ~31);
690 static int ivtv_s_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
692 struct ivtv
*itv
= fh2id(fh
)->itv
;
693 int ret
= ivtv_try_fmt_vid_out_overlay(file
, fh
, fmt
);
696 itv
->osd_chroma_key
= fmt
->fmt
.win
.chromakey
;
697 itv
->osd_global_alpha
= fmt
->fmt
.win
.global_alpha
;
698 ivtv_set_osd_alpha(itv
);
703 #ifdef CONFIG_VIDEO_ADV_DEBUG
704 static int ivtv_itvc(struct ivtv
*itv
, bool get
, u64 reg
, u64
*val
)
706 volatile u8 __iomem
*reg_start
;
710 if (reg
>= IVTV_REG_OFFSET
&& reg
< IVTV_REG_OFFSET
+ IVTV_REG_SIZE
)
711 reg_start
= itv
->reg_mem
- IVTV_REG_OFFSET
;
712 else if (itv
->has_cx23415
&& reg
>= IVTV_DECODER_OFFSET
&&
713 reg
< IVTV_DECODER_OFFSET
+ IVTV_DECODER_SIZE
)
714 reg_start
= itv
->dec_mem
- IVTV_DECODER_OFFSET
;
715 else if (reg
< IVTV_ENCODER_SIZE
)
716 reg_start
= itv
->enc_mem
;
721 *val
= readl(reg
+ reg_start
);
723 writel(*val
, reg
+ reg_start
);
727 static int ivtv_g_register(struct file
*file
, void *fh
, struct v4l2_dbg_register
*reg
)
729 struct ivtv
*itv
= fh2id(fh
)->itv
;
732 return ivtv_itvc(itv
, true, reg
->reg
, ®
->val
);
735 static int ivtv_s_register(struct file
*file
, void *fh
, const struct v4l2_dbg_register
*reg
)
737 struct ivtv
*itv
= fh2id(fh
)->itv
;
740 return ivtv_itvc(itv
, false, reg
->reg
, &val
);
744 static int ivtv_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*vcap
)
746 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
747 struct ivtv
*itv
= id
->itv
;
748 struct ivtv_stream
*s
= &itv
->streams
[id
->type
];
750 strlcpy(vcap
->driver
, IVTV_DRIVER_NAME
, sizeof(vcap
->driver
));
751 strlcpy(vcap
->card
, itv
->card_name
, sizeof(vcap
->card
));
752 snprintf(vcap
->bus_info
, sizeof(vcap
->bus_info
), "PCI:%s", pci_name(itv
->pdev
));
753 vcap
->capabilities
= itv
->v4l2_cap
| V4L2_CAP_DEVICE_CAPS
;
754 vcap
->device_caps
= s
->caps
;
755 if ((s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
) &&
756 !itv
->osd_video_pbase
) {
757 vcap
->capabilities
&= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY
;
758 vcap
->device_caps
&= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY
;
763 static int ivtv_enumaudio(struct file
*file
, void *fh
, struct v4l2_audio
*vin
)
765 struct ivtv
*itv
= fh2id(fh
)->itv
;
767 return ivtv_get_audio_input(itv
, vin
->index
, vin
);
770 static int ivtv_g_audio(struct file
*file
, void *fh
, struct v4l2_audio
*vin
)
772 struct ivtv
*itv
= fh2id(fh
)->itv
;
774 vin
->index
= itv
->audio_input
;
775 return ivtv_get_audio_input(itv
, vin
->index
, vin
);
778 static int ivtv_s_audio(struct file
*file
, void *fh
, const struct v4l2_audio
*vout
)
780 struct ivtv
*itv
= fh2id(fh
)->itv
;
782 if (vout
->index
>= itv
->nof_audio_inputs
)
785 itv
->audio_input
= vout
->index
;
786 ivtv_audio_set_io(itv
);
791 static int ivtv_enumaudout(struct file
*file
, void *fh
, struct v4l2_audioout
*vin
)
793 struct ivtv
*itv
= fh2id(fh
)->itv
;
795 /* set it to defaults from our table */
796 return ivtv_get_audio_output(itv
, vin
->index
, vin
);
799 static int ivtv_g_audout(struct file
*file
, void *fh
, struct v4l2_audioout
*vin
)
801 struct ivtv
*itv
= fh2id(fh
)->itv
;
804 return ivtv_get_audio_output(itv
, vin
->index
, vin
);
807 static int ivtv_s_audout(struct file
*file
, void *fh
, const struct v4l2_audioout
*vout
)
809 struct ivtv
*itv
= fh2id(fh
)->itv
;
811 if (itv
->card
->video_outputs
== NULL
|| vout
->index
!= 0)
816 static int ivtv_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
818 struct ivtv
*itv
= fh2id(fh
)->itv
;
820 /* set it to defaults from our table */
821 return ivtv_get_input(itv
, vin
->index
, vin
);
824 static int ivtv_enum_output(struct file
*file
, void *fh
, struct v4l2_output
*vout
)
826 struct ivtv
*itv
= fh2id(fh
)->itv
;
828 return ivtv_get_output(itv
, vout
->index
, vout
);
831 static int ivtv_cropcap(struct file
*file
, void *fh
, struct v4l2_cropcap
*cropcap
)
833 struct ivtv_open_id
*id
= fh2id(fh
);
834 struct ivtv
*itv
= id
->itv
;
836 if (cropcap
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
837 cropcap
->pixelaspect
.numerator
= itv
->is_50hz
? 54 : 11;
838 cropcap
->pixelaspect
.denominator
= itv
->is_50hz
? 59 : 10;
839 } else if (cropcap
->type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
840 cropcap
->pixelaspect
.numerator
= itv
->is_out_50hz
? 54 : 11;
841 cropcap
->pixelaspect
.denominator
= itv
->is_out_50hz
? 59 : 10;
848 static int ivtv_s_selection(struct file
*file
, void *fh
,
849 struct v4l2_selection
*sel
)
851 struct ivtv_open_id
*id
= fh2id(fh
);
852 struct ivtv
*itv
= id
->itv
;
853 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
854 struct v4l2_rect r
= { 0, 0, 720, 0 };
855 int streamtype
= id
->type
;
857 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
858 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
861 if (sel
->target
!= V4L2_SEL_TGT_COMPOSE
)
865 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
866 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
869 r
.height
= itv
->is_out_50hz
? 576 : 480;
870 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
&& yi
->track_osd
) {
871 r
.width
= yi
->osd_full_w
;
872 r
.height
= yi
->osd_full_h
;
874 sel
->r
.width
= clamp(sel
->r
.width
, 16U, r
.width
);
875 sel
->r
.height
= clamp(sel
->r
.height
, 16U, r
.height
);
876 sel
->r
.left
= clamp_t(unsigned, sel
->r
.left
, 0, r
.width
- sel
->r
.width
);
877 sel
->r
.top
= clamp_t(unsigned, sel
->r
.top
, 0, r
.height
- sel
->r
.height
);
879 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
) {
880 yi
->main_rect
= sel
->r
;
883 if (!ivtv_vapi(itv
, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW
, 4,
884 sel
->r
.width
, sel
->r
.height
, sel
->r
.left
, sel
->r
.top
)) {
885 itv
->main_rect
= sel
->r
;
891 static int ivtv_g_selection(struct file
*file
, void *fh
,
892 struct v4l2_selection
*sel
)
894 struct ivtv_open_id
*id
= fh2id(fh
);
895 struct ivtv
*itv
= id
->itv
;
896 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
897 struct v4l2_rect r
= { 0, 0, 720, 0 };
898 int streamtype
= id
->type
;
900 if (sel
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
901 switch (sel
->target
) {
902 case V4L2_SEL_TGT_CROP_DEFAULT
:
903 case V4L2_SEL_TGT_CROP_BOUNDS
:
904 sel
->r
.top
= sel
->r
.left
= 0;
906 sel
->r
.height
= itv
->is_50hz
? 576 : 480;
913 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
914 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
917 switch (sel
->target
) {
918 case V4L2_SEL_TGT_COMPOSE
:
919 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
)
920 sel
->r
= yi
->main_rect
;
922 sel
->r
= itv
->main_rect
;
924 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
925 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
926 r
.height
= itv
->is_out_50hz
? 576 : 480;
927 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
&& yi
->track_osd
) {
928 r
.width
= yi
->osd_full_w
;
929 r
.height
= yi
->osd_full_h
;
937 static int ivtv_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
939 static const struct v4l2_fmtdesc hm12
= {
940 0, V4L2_BUF_TYPE_VIDEO_CAPTURE
, 0,
941 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12
,
944 static const struct v4l2_fmtdesc mpeg
= {
945 0, V4L2_BUF_TYPE_VIDEO_CAPTURE
, V4L2_FMT_FLAG_COMPRESSED
,
946 "MPEG", V4L2_PIX_FMT_MPEG
,
949 struct ivtv
*itv
= fh2id(fh
)->itv
;
950 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
954 if (s
->type
== IVTV_ENC_STREAM_TYPE_MPG
)
956 else if (s
->type
== IVTV_ENC_STREAM_TYPE_YUV
)
963 static int ivtv_enum_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
965 static const struct v4l2_fmtdesc hm12
= {
966 0, V4L2_BUF_TYPE_VIDEO_OUTPUT
, 0,
967 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12
,
970 static const struct v4l2_fmtdesc mpeg
= {
971 0, V4L2_BUF_TYPE_VIDEO_OUTPUT
, V4L2_FMT_FLAG_COMPRESSED
,
972 "MPEG", V4L2_PIX_FMT_MPEG
,
975 struct ivtv
*itv
= fh2id(fh
)->itv
;
976 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
980 if (s
->type
== IVTV_DEC_STREAM_TYPE_MPG
)
982 else if (s
->type
== IVTV_DEC_STREAM_TYPE_YUV
)
989 static int ivtv_g_input(struct file
*file
, void *fh
, unsigned int *i
)
991 struct ivtv
*itv
= fh2id(fh
)->itv
;
993 *i
= itv
->active_input
;
998 int ivtv_s_input(struct file
*file
, void *fh
, unsigned int inp
)
1000 struct ivtv
*itv
= fh2id(fh
)->itv
;
1004 if (inp
>= itv
->nof_inputs
)
1007 if (inp
== itv
->active_input
) {
1008 IVTV_DEBUG_INFO("Input unchanged\n");
1012 if (atomic_read(&itv
->capturing
) > 0) {
1016 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
1017 itv
->active_input
, inp
);
1019 itv
->active_input
= inp
;
1020 /* Set the audio input to whatever is appropriate for the
1022 itv
->audio_input
= itv
->card
->video_inputs
[inp
].audio_index
;
1024 if (itv
->card
->video_inputs
[inp
].video_type
== IVTV_CARD_INPUT_VID_TUNER
)
1025 std
= itv
->tuner_std
;
1028 for (i
= 0; i
<= IVTV_ENC_STREAM_TYPE_VBI
; i
++)
1029 itv
->streams
[i
].vdev
.tvnorms
= std
;
1031 /* prevent others from messing with the streams until
1032 we're finished changing inputs. */
1034 ivtv_video_set_io(itv
);
1035 ivtv_audio_set_io(itv
);
1041 static int ivtv_g_output(struct file
*file
, void *fh
, unsigned int *i
)
1043 struct ivtv
*itv
= fh2id(fh
)->itv
;
1045 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1048 *i
= itv
->active_output
;
1053 static int ivtv_s_output(struct file
*file
, void *fh
, unsigned int outp
)
1055 struct ivtv
*itv
= fh2id(fh
)->itv
;
1057 if (outp
>= itv
->card
->nof_outputs
)
1060 if (outp
== itv
->active_output
) {
1061 IVTV_DEBUG_INFO("Output unchanged\n");
1064 IVTV_DEBUG_INFO("Changing output from %d to %d\n",
1065 itv
->active_output
, outp
);
1067 itv
->active_output
= outp
;
1068 ivtv_call_hw(itv
, IVTV_HW_SAA7127
, video
, s_routing
,
1069 SAA7127_INPUT_TYPE_NORMAL
,
1070 itv
->card
->video_outputs
[outp
].video_output
, 0);
1075 static int ivtv_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*vf
)
1077 struct ivtv
*itv
= fh2id(fh
)->itv
;
1078 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1080 if (s
->vdev
.vfl_dir
)
1085 ivtv_call_all(itv
, tuner
, g_frequency
, vf
);
1089 int ivtv_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*vf
)
1091 struct ivtv
*itv
= fh2id(fh
)->itv
;
1092 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1094 if (s
->vdev
.vfl_dir
)
1100 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf
->frequency
);
1101 ivtv_call_all(itv
, tuner
, s_frequency
, vf
);
1106 static int ivtv_g_std(struct file
*file
, void *fh
, v4l2_std_id
*std
)
1108 struct ivtv
*itv
= fh2id(fh
)->itv
;
1114 void ivtv_s_std_enc(struct ivtv
*itv
, v4l2_std_id std
)
1117 itv
->is_60hz
= (std
& V4L2_STD_525_60
) ? 1 : 0;
1118 itv
->is_50hz
= !itv
->is_60hz
;
1119 cx2341x_handler_set_50hz(&itv
->cxhdl
, itv
->is_50hz
);
1120 itv
->cxhdl
.width
= 720;
1121 itv
->cxhdl
.height
= itv
->is_50hz
? 576 : 480;
1122 itv
->vbi
.count
= itv
->is_50hz
? 18 : 12;
1123 itv
->vbi
.start
[0] = itv
->is_50hz
? 6 : 10;
1124 itv
->vbi
.start
[1] = itv
->is_50hz
? 318 : 273;
1126 if (itv
->hw_flags
& IVTV_HW_CX25840
)
1127 itv
->vbi
.sliced_decoder_line_size
= itv
->is_60hz
? 272 : 284;
1130 ivtv_call_all(itv
, video
, s_std
, itv
->std
);
1133 void ivtv_s_std_dec(struct ivtv
*itv
, v4l2_std_id std
)
1135 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1139 /* set display standard */
1141 itv
->is_out_60hz
= (std
& V4L2_STD_525_60
) ? 1 : 0;
1142 itv
->is_out_50hz
= !itv
->is_out_60hz
;
1143 ivtv_call_all(itv
, video
, s_std_output
, itv
->std_out
);
1146 * The next firmware call is time sensitive. Time it to
1147 * avoid risk of a hard lock, by trying to ensure the call
1148 * happens within the first 100 lines of the top field.
1149 * Make 4 attempts to sync to the decoder before giving up.
1151 mutex_unlock(&itv
->serialize_lock
);
1152 for (f
= 0; f
< 4; f
++) {
1153 prepare_to_wait(&itv
->vsync_waitq
, &wait
,
1154 TASK_UNINTERRUPTIBLE
);
1155 if ((read_reg(IVTV_REG_DEC_LINE_FIELD
) >> 16) < 100)
1157 schedule_timeout(msecs_to_jiffies(25));
1159 finish_wait(&itv
->vsync_waitq
, &wait
);
1160 mutex_lock(&itv
->serialize_lock
);
1163 IVTV_WARN("Mode change failed to sync to decoder\n");
1165 ivtv_vapi(itv
, CX2341X_DEC_SET_STANDARD
, 1, itv
->is_out_50hz
);
1166 itv
->main_rect
.left
= 0;
1167 itv
->main_rect
.top
= 0;
1168 itv
->main_rect
.width
= 720;
1169 itv
->main_rect
.height
= itv
->is_out_50hz
? 576 : 480;
1170 ivtv_vapi(itv
, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW
, 4,
1171 720, itv
->main_rect
.height
, 0, 0);
1172 yi
->main_rect
= itv
->main_rect
;
1173 if (!itv
->osd_info
) {
1174 yi
->osd_full_w
= 720;
1175 yi
->osd_full_h
= itv
->is_out_50hz
? 576 : 480;
1179 static int ivtv_s_std(struct file
*file
, void *fh
, v4l2_std_id std
)
1181 struct ivtv
*itv
= fh2id(fh
)->itv
;
1183 if ((std
& V4L2_STD_ALL
) == 0)
1186 if (std
== itv
->std
)
1189 if (test_bit(IVTV_F_I_RADIO_USER
, &itv
->i_flags
) ||
1190 atomic_read(&itv
->capturing
) > 0 ||
1191 atomic_read(&itv
->decoding
) > 0) {
1192 /* Switching standard would mess with already running
1193 streams, prevent that by returning EBUSY. */
1197 IVTV_DEBUG_INFO("Switching standard to %llx.\n",
1198 (unsigned long long)itv
->std
);
1200 ivtv_s_std_enc(itv
, std
);
1201 if (itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
)
1202 ivtv_s_std_dec(itv
, std
);
1207 static int ivtv_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*vt
)
1209 struct ivtv_open_id
*id
= fh2id(fh
);
1210 struct ivtv
*itv
= id
->itv
;
1215 ivtv_call_all(itv
, tuner
, s_tuner
, vt
);
1220 static int ivtv_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*vt
)
1222 struct ivtv
*itv
= fh2id(fh
)->itv
;
1227 ivtv_call_all(itv
, tuner
, g_tuner
, vt
);
1229 if (vt
->type
== V4L2_TUNER_RADIO
)
1230 strlcpy(vt
->name
, "ivtv Radio Tuner", sizeof(vt
->name
));
1232 strlcpy(vt
->name
, "ivtv TV Tuner", sizeof(vt
->name
));
1236 static int ivtv_g_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_sliced_vbi_cap
*cap
)
1238 struct ivtv
*itv
= fh2id(fh
)->itv
;
1239 int set
= itv
->is_50hz
? V4L2_SLICED_VBI_625
: V4L2_SLICED_VBI_525
;
1242 if (cap
->type
== V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
) {
1243 for (f
= 0; f
< 2; f
++) {
1244 for (l
= 0; l
< 24; l
++) {
1245 if (valid_service_line(f
, l
, itv
->is_50hz
))
1246 cap
->service_lines
[f
][l
] = set
;
1249 } else if (cap
->type
== V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
) {
1250 if (!(itv
->v4l2_cap
& V4L2_CAP_SLICED_VBI_OUTPUT
))
1253 cap
->service_lines
[0][21] = V4L2_SLICED_CAPTION_525
;
1254 cap
->service_lines
[1][21] = V4L2_SLICED_CAPTION_525
;
1256 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
1257 cap
->service_lines
[0][16] = V4L2_SLICED_VPS
;
1264 for (f
= 0; f
< 2; f
++)
1265 for (l
= 0; l
< 24; l
++)
1266 set
|= cap
->service_lines
[f
][l
];
1267 cap
->service_set
= set
;
1271 static int ivtv_g_enc_index(struct file
*file
, void *fh
, struct v4l2_enc_idx
*idx
)
1273 struct ivtv
*itv
= fh2id(fh
)->itv
;
1274 struct v4l2_enc_idx_entry
*e
= idx
->entry
;
1278 entries
= (itv
->pgm_info_write_idx
+ IVTV_MAX_PGM_INDEX
- itv
->pgm_info_read_idx
) %
1280 if (entries
> V4L2_ENC_IDX_ENTRIES
)
1281 entries
= V4L2_ENC_IDX_ENTRIES
;
1283 idx
->entries_cap
= IVTV_MAX_PGM_INDEX
;
1284 if (!atomic_read(&itv
->capturing
))
1286 for (i
= 0; i
< entries
; i
++) {
1287 *e
= itv
->pgm_info
[(itv
->pgm_info_read_idx
+ i
) % IVTV_MAX_PGM_INDEX
];
1288 if ((e
->flags
& V4L2_ENC_IDX_FRAME_MASK
) <= V4L2_ENC_IDX_FRAME_B
) {
1293 itv
->pgm_info_read_idx
= (itv
->pgm_info_read_idx
+ idx
->entries
) % IVTV_MAX_PGM_INDEX
;
1297 static int ivtv_encoder_cmd(struct file
*file
, void *fh
, struct v4l2_encoder_cmd
*enc
)
1299 struct ivtv_open_id
*id
= fh2id(fh
);
1300 struct ivtv
*itv
= id
->itv
;
1304 case V4L2_ENC_CMD_START
:
1305 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1307 return ivtv_start_capture(id
);
1309 case V4L2_ENC_CMD_STOP
:
1310 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1311 enc
->flags
&= V4L2_ENC_CMD_STOP_AT_GOP_END
;
1312 ivtv_stop_capture(id
, enc
->flags
& V4L2_ENC_CMD_STOP_AT_GOP_END
);
1315 case V4L2_ENC_CMD_PAUSE
:
1316 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1319 if (!atomic_read(&itv
->capturing
))
1321 if (test_and_set_bit(IVTV_F_I_ENC_PAUSED
, &itv
->i_flags
))
1325 ivtv_vapi(itv
, CX2341X_ENC_PAUSE_ENCODER
, 1, 0);
1328 case V4L2_ENC_CMD_RESUME
:
1329 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1332 if (!atomic_read(&itv
->capturing
))
1335 if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED
, &itv
->i_flags
))
1338 ivtv_vapi(itv
, CX2341X_ENC_PAUSE_ENCODER
, 1, 1);
1342 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc
->cmd
);
1349 static int ivtv_try_encoder_cmd(struct file
*file
, void *fh
, struct v4l2_encoder_cmd
*enc
)
1351 struct ivtv
*itv
= fh2id(fh
)->itv
;
1354 case V4L2_ENC_CMD_START
:
1355 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1359 case V4L2_ENC_CMD_STOP
:
1360 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1361 enc
->flags
&= V4L2_ENC_CMD_STOP_AT_GOP_END
;
1364 case V4L2_ENC_CMD_PAUSE
:
1365 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1369 case V4L2_ENC_CMD_RESUME
:
1370 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1374 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc
->cmd
);
1379 static int ivtv_g_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*fb
)
1381 struct ivtv
*itv
= fh2id(fh
)->itv
;
1382 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1383 u32 data
[CX2341X_MBOX_MAX_DATA
];
1384 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1387 static u32 pixel_format
[16] = {
1388 V4L2_PIX_FMT_PAL8
, /* Uses a 256-entry RGB colormap */
1389 V4L2_PIX_FMT_RGB565
,
1390 V4L2_PIX_FMT_RGB555
,
1391 V4L2_PIX_FMT_RGB444
,
1396 V4L2_PIX_FMT_PAL8
, /* Uses a 256-entry YUV colormap */
1397 V4L2_PIX_FMT_YUV565
,
1398 V4L2_PIX_FMT_YUV555
,
1399 V4L2_PIX_FMT_YUV444
,
1406 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1408 if (!itv
->osd_video_pbase
)
1411 fb
->capability
= V4L2_FBUF_CAP_EXTERNOVERLAY
| V4L2_FBUF_CAP_CHROMAKEY
|
1412 V4L2_FBUF_CAP_GLOBAL_ALPHA
;
1414 ivtv_vapi_result(itv
, data
, CX2341X_OSD_GET_STATE
, 0);
1415 data
[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1416 pixfmt
= (data
[0] >> 3) & 0xf;
1418 fb
->fmt
.pixelformat
= pixel_format
[pixfmt
];
1419 fb
->fmt
.width
= itv
->osd_rect
.width
;
1420 fb
->fmt
.height
= itv
->osd_rect
.height
;
1421 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
1422 fb
->fmt
.bytesperline
= fb
->fmt
.width
;
1423 fb
->fmt
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1424 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
1425 if (fb
->fmt
.pixelformat
!= V4L2_PIX_FMT_PAL8
)
1426 fb
->fmt
.bytesperline
*= 2;
1427 if (fb
->fmt
.pixelformat
== V4L2_PIX_FMT_RGB32
||
1428 fb
->fmt
.pixelformat
== V4L2_PIX_FMT_YUV32
)
1429 fb
->fmt
.bytesperline
*= 2;
1430 fb
->fmt
.sizeimage
= fb
->fmt
.bytesperline
* fb
->fmt
.height
;
1431 fb
->base
= (void *)itv
->osd_video_pbase
;
1434 if (itv
->osd_chroma_key_state
)
1435 fb
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1437 if (itv
->osd_global_alpha_state
)
1438 fb
->flags
|= V4L2_FBUF_FLAG_GLOBAL_ALPHA
;
1441 fb
->flags
|= V4L2_FBUF_FLAG_OVERLAY
;
1445 /* no local alpha for RGB565 or unknown formats */
1446 if (pixfmt
== 1 || pixfmt
> 4)
1449 /* 16-bit formats have inverted local alpha */
1450 if (pixfmt
== 2 || pixfmt
== 3)
1451 fb
->capability
|= V4L2_FBUF_CAP_LOCAL_INV_ALPHA
;
1453 fb
->capability
|= V4L2_FBUF_CAP_LOCAL_ALPHA
;
1455 if (itv
->osd_local_alpha_state
) {
1456 /* 16-bit formats have inverted local alpha */
1457 if (pixfmt
== 2 || pixfmt
== 3)
1458 fb
->flags
|= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA
;
1460 fb
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1466 static int ivtv_s_fbuf(struct file
*file
, void *fh
, const struct v4l2_framebuffer
*fb
)
1468 struct ivtv_open_id
*id
= fh2id(fh
);
1469 struct ivtv
*itv
= id
->itv
;
1470 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1471 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1473 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1475 if (!itv
->osd_video_pbase
)
1478 itv
->osd_global_alpha_state
= (fb
->flags
& V4L2_FBUF_FLAG_GLOBAL_ALPHA
) != 0;
1479 itv
->osd_local_alpha_state
=
1480 (fb
->flags
& (V4L2_FBUF_FLAG_LOCAL_ALPHA
|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA
)) != 0;
1481 itv
->osd_chroma_key_state
= (fb
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) != 0;
1482 ivtv_set_osd_alpha(itv
);
1483 yi
->track_osd
= (fb
->flags
& V4L2_FBUF_FLAG_OVERLAY
) != 0;
1487 static int ivtv_overlay(struct file
*file
, void *fh
, unsigned int on
)
1489 struct ivtv_open_id
*id
= fh2id(fh
);
1490 struct ivtv
*itv
= id
->itv
;
1491 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1493 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1495 if (!itv
->osd_video_pbase
)
1498 ivtv_vapi(itv
, CX2341X_OSD_SET_STATE
, 1, on
!= 0);
1503 static int ivtv_subscribe_event(struct v4l2_fh
*fh
, const struct v4l2_event_subscription
*sub
)
1505 switch (sub
->type
) {
1506 case V4L2_EVENT_VSYNC
:
1507 case V4L2_EVENT_EOS
:
1508 return v4l2_event_subscribe(fh
, sub
, 0, NULL
);
1510 return v4l2_ctrl_subscribe_event(fh
, sub
);
1514 static int ivtv_log_status(struct file
*file
, void *fh
)
1516 struct ivtv
*itv
= fh2id(fh
)->itv
;
1517 u32 data
[CX2341X_MBOX_MAX_DATA
];
1519 int has_output
= itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
;
1520 struct v4l2_input vidin
;
1521 struct v4l2_audio audin
;
1524 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION
, itv
->card_name
);
1525 if (itv
->hw_flags
& IVTV_HW_TVEEPROM
) {
1528 ivtv_read_eeprom(itv
, &tv
);
1530 ivtv_call_all(itv
, core
, log_status
);
1531 ivtv_get_input(itv
, itv
->active_input
, &vidin
);
1532 ivtv_get_audio_input(itv
, itv
->audio_input
, &audin
);
1533 IVTV_INFO("Video Input: %s\n", vidin
.name
);
1534 IVTV_INFO("Audio Input: %s%s\n", audin
.name
,
1535 itv
->dualwatch_stereo_mode
== V4L2_MPEG_AUDIO_MODE_DUAL
?
1536 " (Bilingual)" : "");
1538 struct v4l2_output vidout
;
1539 struct v4l2_audioout audout
;
1540 int mode
= itv
->output_mode
;
1541 static const char * const output_modes
[5] = {
1548 static const char * const alpha_mode
[4] = {
1554 static const char * const pixel_format
[16] = {
1573 ivtv_get_output(itv
, itv
->active_output
, &vidout
);
1574 ivtv_get_audio_output(itv
, 0, &audout
);
1575 IVTV_INFO("Video Output: %s\n", vidout
.name
);
1576 if (mode
< 0 || mode
> OUT_PASSTHROUGH
)
1578 IVTV_INFO("Output Mode: %s\n", output_modes
[mode
]);
1579 ivtv_vapi_result(itv
, data
, CX2341X_OSD_GET_STATE
, 0);
1580 data
[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1581 IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1582 data
[0] & 1 ? "On" : "Off",
1583 alpha_mode
[(data
[0] >> 1) & 0x3],
1584 pixel_format
[(data
[0] >> 3) & 0xf]);
1586 IVTV_INFO("Tuner: %s\n",
1587 test_bit(IVTV_F_I_RADIO_USER
, &itv
->i_flags
) ? "Radio" : "TV");
1588 v4l2_ctrl_handler_log_status(&itv
->cxhdl
.hdl
, itv
->v4l2_dev
.name
);
1589 IVTV_INFO("Status flags: 0x%08lx\n", itv
->i_flags
);
1590 for (i
= 0; i
< IVTV_MAX_STREAMS
; i
++) {
1591 struct ivtv_stream
*s
= &itv
->streams
[i
];
1593 if (s
->vdev
.v4l2_dev
== NULL
|| s
->buffers
== 0)
1595 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s
->name
, s
->s_flags
,
1596 (s
->buffers
- s
->q_free
.buffers
) * 100 / s
->buffers
,
1597 (s
->buffers
* s
->buf_size
) / 1024, s
->buffers
);
1600 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n",
1601 (long long)itv
->mpg_data_received
,
1602 (long long)itv
->vbi_data_inserted
);
1606 static int ivtv_decoder_cmd(struct file
*file
, void *fh
, struct v4l2_decoder_cmd
*dec
)
1608 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
1609 struct ivtv
*itv
= id
->itv
;
1611 IVTV_DEBUG_IOCTL("VIDIOC_DECODER_CMD %d\n", dec
->cmd
);
1612 return ivtv_video_command(itv
, id
, dec
, false);
1615 static int ivtv_try_decoder_cmd(struct file
*file
, void *fh
, struct v4l2_decoder_cmd
*dec
)
1617 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
1618 struct ivtv
*itv
= id
->itv
;
1620 IVTV_DEBUG_IOCTL("VIDIOC_TRY_DECODER_CMD %d\n", dec
->cmd
);
1621 return ivtv_video_command(itv
, id
, dec
, true);
1624 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1625 static __inline__
void warn_deprecated_ioctl(const char *name
)
1627 pr_warn_once("warning: the %s ioctl is deprecated. Don't use it, as it will be removed soon\n",
1632 static int ivtv_decoder_ioctls(struct file
*filp
, unsigned int cmd
, void *arg
)
1634 struct ivtv_open_id
*id
= fh2id(filp
->private_data
);
1635 struct ivtv
*itv
= id
->itv
;
1636 struct ivtv_stream
*s
= &itv
->streams
[id
->type
];
1637 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1638 int nonblocking
= filp
->f_flags
& O_NONBLOCK
;
1639 unsigned long iarg
= (unsigned long)arg
;
1643 case IVTV_IOC_DMA_FRAME
: {
1644 struct ivtv_dma_frame
*args
= arg
;
1646 IVTV_DEBUG_IOCTL("IVTV_IOC_DMA_FRAME\n");
1647 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1649 if (args
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
1651 if (itv
->output_mode
== OUT_UDMA_YUV
&& args
->y_source
== NULL
)
1653 if (ivtv_start_decoding(id
, id
->type
)) {
1656 if (ivtv_set_output_mode(itv
, OUT_UDMA_YUV
) != OUT_UDMA_YUV
) {
1657 ivtv_release_stream(s
);
1660 /* Mark that this file handle started the UDMA_YUV mode */
1662 if (args
->y_source
== NULL
)
1664 return ivtv_yuv_prep_frame(itv
, args
);
1667 case IVTV_IOC_PASSTHROUGH_MODE
:
1668 IVTV_DEBUG_IOCTL("IVTV_IOC_PASSTHROUGH_MODE\n");
1669 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1671 return ivtv_passthrough_mode(itv
, *(int *)arg
!= 0);
1672 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1673 case VIDEO_GET_PTS
: {
1677 warn_deprecated_ioctl("VIDEO_GET_PTS");
1678 if (s
->type
< IVTV_DEC_STREAM_TYPE_MPG
) {
1682 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1684 return ivtv_g_pts_frame(itv
, pts
, &frame
);
1687 case VIDEO_GET_FRAME_COUNT
: {
1691 warn_deprecated_ioctl("VIDEO_GET_FRAME_COUNT");
1692 if (s
->type
< IVTV_DEC_STREAM_TYPE_MPG
) {
1696 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1698 return ivtv_g_pts_frame(itv
, &pts
, frame
);
1702 struct v4l2_decoder_cmd dc
;
1704 warn_deprecated_ioctl("VIDEO_PLAY");
1705 memset(&dc
, 0, sizeof(dc
));
1706 dc
.cmd
= V4L2_DEC_CMD_START
;
1707 return ivtv_video_command(itv
, id
, &dc
, 0);
1711 struct v4l2_decoder_cmd dc
;
1713 warn_deprecated_ioctl("VIDEO_STOP");
1714 memset(&dc
, 0, sizeof(dc
));
1715 dc
.cmd
= V4L2_DEC_CMD_STOP
;
1716 dc
.flags
= V4L2_DEC_CMD_STOP_TO_BLACK
| V4L2_DEC_CMD_STOP_IMMEDIATELY
;
1717 return ivtv_video_command(itv
, id
, &dc
, 0);
1720 case VIDEO_FREEZE
: {
1721 struct v4l2_decoder_cmd dc
;
1723 warn_deprecated_ioctl("VIDEO_FREEZE");
1724 memset(&dc
, 0, sizeof(dc
));
1725 dc
.cmd
= V4L2_DEC_CMD_PAUSE
;
1726 return ivtv_video_command(itv
, id
, &dc
, 0);
1729 case VIDEO_CONTINUE
: {
1730 struct v4l2_decoder_cmd dc
;
1732 warn_deprecated_ioctl("VIDEO_CONTINUE");
1733 memset(&dc
, 0, sizeof(dc
));
1734 dc
.cmd
= V4L2_DEC_CMD_RESUME
;
1735 return ivtv_video_command(itv
, id
, &dc
, 0);
1739 case VIDEO_TRY_COMMAND
: {
1740 /* Note: struct v4l2_decoder_cmd has the same layout as
1741 struct video_command */
1742 struct v4l2_decoder_cmd
*dc
= arg
;
1743 int try = (cmd
== VIDEO_TRY_COMMAND
);
1746 warn_deprecated_ioctl("VIDEO_TRY_COMMAND");
1748 warn_deprecated_ioctl("VIDEO_COMMAND");
1749 return ivtv_video_command(itv
, id
, dc
, try);
1752 case VIDEO_GET_EVENT
: {
1753 struct video_event
*ev
= arg
;
1756 warn_deprecated_ioctl("VIDEO_GET_EVENT");
1757 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1759 memset(ev
, 0, sizeof(*ev
));
1760 set_bit(IVTV_F_I_EV_VSYNC_ENABLED
, &itv
->i_flags
);
1763 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED
, &itv
->i_flags
))
1764 ev
->type
= VIDEO_EVENT_DECODER_STOPPED
;
1765 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC
, &itv
->i_flags
)) {
1766 ev
->type
= VIDEO_EVENT_VSYNC
;
1767 ev
->u
.vsync_field
= test_bit(IVTV_F_I_EV_VSYNC_FIELD
, &itv
->i_flags
) ?
1768 VIDEO_VSYNC_FIELD_ODD
: VIDEO_VSYNC_FIELD_EVEN
;
1769 if (itv
->output_mode
== OUT_UDMA_YUV
&&
1770 (itv
->yuv_info
.lace_mode
& IVTV_YUV_MODE_MASK
) ==
1771 IVTV_YUV_MODE_PROGRESSIVE
) {
1772 ev
->u
.vsync_field
= VIDEO_VSYNC_FIELD_PROGRESSIVE
;
1779 /* Wait for event. Note that serialize_lock is locked,
1780 so to allow other processes to access the driver while
1781 we are waiting unlock first and later lock again. */
1782 mutex_unlock(&itv
->serialize_lock
);
1783 prepare_to_wait(&itv
->event_waitq
, &wait
, TASK_INTERRUPTIBLE
);
1784 if (!test_bit(IVTV_F_I_EV_DEC_STOPPED
, &itv
->i_flags
) &&
1785 !test_bit(IVTV_F_I_EV_VSYNC
, &itv
->i_flags
))
1787 finish_wait(&itv
->event_waitq
, &wait
);
1788 mutex_lock(&itv
->serialize_lock
);
1789 if (signal_pending(current
)) {
1790 /* return if a signal was received */
1791 IVTV_DEBUG_INFO("User stopped wait for event\n");
1798 case VIDEO_SELECT_SOURCE
:
1799 warn_deprecated_ioctl("VIDEO_SELECT_SOURCE");
1800 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1802 return ivtv_passthrough_mode(itv
, iarg
== VIDEO_SOURCE_DEMUX
);
1804 case AUDIO_SET_MUTE
:
1805 warn_deprecated_ioctl("AUDIO_SET_MUTE");
1806 itv
->speed_mute_audio
= iarg
;
1809 case AUDIO_CHANNEL_SELECT
:
1810 warn_deprecated_ioctl("AUDIO_CHANNEL_SELECT");
1811 if (iarg
> AUDIO_STEREO_SWAPPED
)
1813 return v4l2_ctrl_s_ctrl(itv
->ctrl_audio_playback
, iarg
+ 1);
1815 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1816 warn_deprecated_ioctl("AUDIO_BILINGUAL_CHANNEL_SELECT");
1817 if (iarg
> AUDIO_STEREO_SWAPPED
)
1819 return v4l2_ctrl_s_ctrl(itv
->ctrl_audio_multilingual_playback
, iarg
+ 1);
1827 static long ivtv_default(struct file
*file
, void *fh
, bool valid_prio
,
1828 unsigned int cmd
, void *arg
)
1830 struct ivtv
*itv
= fh2id(fh
)->itv
;
1834 case IVTV_IOC_PASSTHROUGH_MODE
:
1835 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1839 case VIDEO_CONTINUE
:
1841 case VIDEO_SELECT_SOURCE
:
1842 case AUDIO_SET_MUTE
:
1843 case AUDIO_CHANNEL_SELECT
:
1844 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1851 case VIDIOC_INT_RESET
: {
1852 u32 val
= *(u32
*)arg
;
1854 if ((val
== 0 && itv
->options
.newi2c
) || (val
& 0x01))
1855 ivtv_reset_ir_gpio(itv
);
1857 v4l2_subdev_call(itv
->sd_video
, core
, reset
, 0);
1861 case IVTV_IOC_DMA_FRAME
:
1862 case IVTV_IOC_PASSTHROUGH_MODE
:
1863 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1865 case VIDEO_GET_FRAME_COUNT
:
1866 case VIDEO_GET_EVENT
:
1870 case VIDEO_CONTINUE
:
1872 case VIDEO_TRY_COMMAND
:
1873 case VIDEO_SELECT_SOURCE
:
1874 case AUDIO_SET_MUTE
:
1875 case AUDIO_CHANNEL_SELECT
:
1876 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1878 return ivtv_decoder_ioctls(file
, cmd
, (void *)arg
);
1886 static const struct v4l2_ioctl_ops ivtv_ioctl_ops
= {
1887 .vidioc_querycap
= ivtv_querycap
,
1888 .vidioc_s_audio
= ivtv_s_audio
,
1889 .vidioc_g_audio
= ivtv_g_audio
,
1890 .vidioc_enumaudio
= ivtv_enumaudio
,
1891 .vidioc_s_audout
= ivtv_s_audout
,
1892 .vidioc_g_audout
= ivtv_g_audout
,
1893 .vidioc_enum_input
= ivtv_enum_input
,
1894 .vidioc_enum_output
= ivtv_enum_output
,
1895 .vidioc_enumaudout
= ivtv_enumaudout
,
1896 .vidioc_cropcap
= ivtv_cropcap
,
1897 .vidioc_s_selection
= ivtv_s_selection
,
1898 .vidioc_g_selection
= ivtv_g_selection
,
1899 .vidioc_g_input
= ivtv_g_input
,
1900 .vidioc_s_input
= ivtv_s_input
,
1901 .vidioc_g_output
= ivtv_g_output
,
1902 .vidioc_s_output
= ivtv_s_output
,
1903 .vidioc_g_frequency
= ivtv_g_frequency
,
1904 .vidioc_s_frequency
= ivtv_s_frequency
,
1905 .vidioc_s_tuner
= ivtv_s_tuner
,
1906 .vidioc_g_tuner
= ivtv_g_tuner
,
1907 .vidioc_g_enc_index
= ivtv_g_enc_index
,
1908 .vidioc_g_fbuf
= ivtv_g_fbuf
,
1909 .vidioc_s_fbuf
= ivtv_s_fbuf
,
1910 .vidioc_g_std
= ivtv_g_std
,
1911 .vidioc_s_std
= ivtv_s_std
,
1912 .vidioc_overlay
= ivtv_overlay
,
1913 .vidioc_log_status
= ivtv_log_status
,
1914 .vidioc_enum_fmt_vid_cap
= ivtv_enum_fmt_vid_cap
,
1915 .vidioc_encoder_cmd
= ivtv_encoder_cmd
,
1916 .vidioc_try_encoder_cmd
= ivtv_try_encoder_cmd
,
1917 .vidioc_decoder_cmd
= ivtv_decoder_cmd
,
1918 .vidioc_try_decoder_cmd
= ivtv_try_decoder_cmd
,
1919 .vidioc_enum_fmt_vid_out
= ivtv_enum_fmt_vid_out
,
1920 .vidioc_g_fmt_vid_cap
= ivtv_g_fmt_vid_cap
,
1921 .vidioc_g_fmt_vbi_cap
= ivtv_g_fmt_vbi_cap
,
1922 .vidioc_g_fmt_sliced_vbi_cap
= ivtv_g_fmt_sliced_vbi_cap
,
1923 .vidioc_g_fmt_vid_out
= ivtv_g_fmt_vid_out
,
1924 .vidioc_g_fmt_vid_out_overlay
= ivtv_g_fmt_vid_out_overlay
,
1925 .vidioc_g_fmt_sliced_vbi_out
= ivtv_g_fmt_sliced_vbi_out
,
1926 .vidioc_s_fmt_vid_cap
= ivtv_s_fmt_vid_cap
,
1927 .vidioc_s_fmt_vbi_cap
= ivtv_s_fmt_vbi_cap
,
1928 .vidioc_s_fmt_sliced_vbi_cap
= ivtv_s_fmt_sliced_vbi_cap
,
1929 .vidioc_s_fmt_vid_out
= ivtv_s_fmt_vid_out
,
1930 .vidioc_s_fmt_vid_out_overlay
= ivtv_s_fmt_vid_out_overlay
,
1931 .vidioc_s_fmt_sliced_vbi_out
= ivtv_s_fmt_sliced_vbi_out
,
1932 .vidioc_try_fmt_vid_cap
= ivtv_try_fmt_vid_cap
,
1933 .vidioc_try_fmt_vbi_cap
= ivtv_try_fmt_vbi_cap
,
1934 .vidioc_try_fmt_sliced_vbi_cap
= ivtv_try_fmt_sliced_vbi_cap
,
1935 .vidioc_try_fmt_vid_out
= ivtv_try_fmt_vid_out
,
1936 .vidioc_try_fmt_vid_out_overlay
= ivtv_try_fmt_vid_out_overlay
,
1937 .vidioc_try_fmt_sliced_vbi_out
= ivtv_try_fmt_sliced_vbi_out
,
1938 .vidioc_g_sliced_vbi_cap
= ivtv_g_sliced_vbi_cap
,
1939 #ifdef CONFIG_VIDEO_ADV_DEBUG
1940 .vidioc_g_register
= ivtv_g_register
,
1941 .vidioc_s_register
= ivtv_s_register
,
1943 .vidioc_default
= ivtv_default
,
1944 .vidioc_subscribe_event
= ivtv_subscribe_event
,
1945 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1948 void ivtv_set_funcs(struct video_device
*vdev
)
1950 vdev
->ioctl_ops
= &ivtv_ioctl_ops
;