1 // SPDX-License-Identifier: GPL-2.0-or-later
4 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
5 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
9 #include "ivtv-driver.h"
10 #include "ivtv-version.h"
11 #include "ivtv-mailbox.h"
13 #include "ivtv-queue.h"
14 #include "ivtv-fileops.h"
16 #include "ivtv-routing.h"
17 #include "ivtv-streams.h"
19 #include "ivtv-ioctl.h"
20 #include "ivtv-gpio.h"
21 #include "ivtv-controls.h"
22 #include "ivtv-cards.h"
23 #include <media/i2c/saa7127.h>
24 #include <media/tveeprom.h>
25 #include <media/v4l2-event.h>
26 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
27 #include <linux/compat.h>
28 #include <linux/dvb/audio.h>
29 #include <linux/dvb/video.h>
32 u16
ivtv_service2vbi(int type
)
35 case V4L2_SLICED_TELETEXT_B
:
36 return IVTV_SLICED_TYPE_TELETEXT_B
;
37 case V4L2_SLICED_CAPTION_525
:
38 return IVTV_SLICED_TYPE_CAPTION_525
;
39 case V4L2_SLICED_WSS_625
:
40 return IVTV_SLICED_TYPE_WSS_625
;
42 return IVTV_SLICED_TYPE_VPS
;
48 static int valid_service_line(int field
, int line
, int is_pal
)
50 return (is_pal
&& line
>= 6 && (line
!= 23 || field
== 0)) ||
51 (!is_pal
&& line
>= 10 && line
< 22);
54 static u16
select_service_from_set(int field
, int line
, u16 set
, int is_pal
)
56 u16 valid_set
= (is_pal
? V4L2_SLICED_VBI_625
: V4L2_SLICED_VBI_525
);
59 set
= set
& valid_set
;
60 if (set
== 0 || !valid_service_line(field
, line
, is_pal
)) {
64 if (line
== 21 && (set
& V4L2_SLICED_CAPTION_525
))
65 return V4L2_SLICED_CAPTION_525
;
68 if (line
== 16 && field
== 0 && (set
& V4L2_SLICED_VPS
))
69 return V4L2_SLICED_VPS
;
70 if (line
== 23 && field
== 0 && (set
& V4L2_SLICED_WSS_625
))
71 return V4L2_SLICED_WSS_625
;
75 for (i
= 0; i
< 32; i
++) {
82 void ivtv_expand_service_set(struct v4l2_sliced_vbi_format
*fmt
, int is_pal
)
84 u16 set
= fmt
->service_set
;
88 for (f
= 0; f
< 2; f
++) {
89 for (l
= 0; l
< 24; l
++) {
90 fmt
->service_lines
[f
][l
] = select_service_from_set(f
, l
, set
, is_pal
);
95 static void check_service_set(struct v4l2_sliced_vbi_format
*fmt
, int is_pal
)
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
, fmt
->service_lines
[f
][l
], is_pal
);
106 u16
ivtv_get_service_set(struct v4l2_sliced_vbi_format
*fmt
)
111 for (f
= 0; f
< 2; f
++) {
112 for (l
= 0; l
< 24; l
++) {
113 set
|= fmt
->service_lines
[f
][l
];
119 void ivtv_set_osd_alpha(struct ivtv
*itv
)
121 ivtv_vapi(itv
, CX2341X_OSD_SET_GLOBAL_ALPHA
, 3,
122 itv
->osd_global_alpha_state
, itv
->osd_global_alpha
, !itv
->osd_local_alpha_state
);
123 ivtv_vapi(itv
, CX2341X_OSD_SET_CHROMA_KEY
, 2, itv
->osd_chroma_key_state
, itv
->osd_chroma_key
);
126 int ivtv_set_speed(struct ivtv
*itv
, int speed
)
128 u32 data
[CX2341X_MBOX_MAX_DATA
];
129 int single_step
= (speed
== 1 || speed
== -1);
132 if (speed
== 0) speed
= 1000;
135 if (speed
== itv
->speed
&& !single_step
)
138 if (single_step
&& (speed
< 0) == (itv
->speed
< 0)) {
139 /* Single step video and no need to change direction */
140 ivtv_vapi(itv
, CX2341X_DEC_STEP_VIDEO
, 1, 0);
145 /* Need to change direction */
146 speed
= speed
< 0 ? -1000 : 1000;
148 data
[0] = (speed
> 1000 || speed
< -1000) ? 0x80000000 : 0;
149 data
[0] |= (speed
> 1000 || speed
< -1500) ? 0x40000000 : 0;
150 data
[1] = (speed
< 0);
151 data
[2] = speed
< 0 ? 3 : 7;
152 data
[3] = v4l2_ctrl_g_ctrl(itv
->cxhdl
.video_b_frames
);
153 data
[4] = (speed
== 1500 || speed
== 500) ? itv
->speed_mute_audio
: 0;
157 if (speed
== 1500 || speed
== -1500) data
[0] |= 1;
158 else if (speed
== 2000 || speed
== -2000) data
[0] |= 2;
159 else if (speed
> -1000 && speed
< 0) data
[0] |= (-1000 / speed
);
160 else if (speed
< 1000 && speed
> 0) data
[0] |= (1000 / speed
);
162 /* If not decoding, just change speed setting */
163 if (atomic_read(&itv
->decoding
) > 0) {
166 /* Stop all DMA and decoding activity */
167 ivtv_vapi(itv
, CX2341X_DEC_PAUSE_PLAYBACK
, 1, 0);
169 /* Wait for any DMA to finish */
170 mutex_unlock(&itv
->serialize_lock
);
171 prepare_to_wait(&itv
->dma_waitq
, &wait
, TASK_INTERRUPTIBLE
);
172 while (test_bit(IVTV_F_I_DMA
, &itv
->i_flags
)) {
173 got_sig
= signal_pending(current
);
179 finish_wait(&itv
->dma_waitq
, &wait
);
180 mutex_lock(&itv
->serialize_lock
);
184 /* Change Speed safely */
185 ivtv_api(itv
, CX2341X_DEC_SET_PLAYBACK_SPEED
, 7, data
);
186 IVTV_DEBUG_INFO("Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
187 data
[0], data
[1], data
[2], data
[3], data
[4], data
[5], data
[6]);
190 speed
= (speed
< 0) ? -1 : 1;
191 ivtv_vapi(itv
, CX2341X_DEC_STEP_VIDEO
, 1, 0);
197 static int ivtv_validate_speed(int cur_speed
, int new_speed
)
199 int fact
= new_speed
< 0 ? -1 : 1;
205 new_speed
= -new_speed
;
207 cur_speed
= -cur_speed
;
209 if (cur_speed
<= new_speed
) {
210 if (new_speed
> 1500)
212 if (new_speed
> 1000)
216 if (new_speed
>= 2000)
218 if (new_speed
>= 1500)
220 if (new_speed
>= 1000)
225 if (new_speed
== 1 || new_speed
== 1000)
226 return fact
* new_speed
;
229 new_speed
= 1000 / new_speed
;
230 if (1000 / cur_speed
== new_speed
)
231 new_speed
+= (cur_speed
< s
) ? -1 : 1;
232 if (new_speed
> 60) return 1000 / (fact
* 60);
233 return 1000 / (fact
* new_speed
);
236 static int ivtv_video_command(struct ivtv
*itv
, struct ivtv_open_id
*id
,
237 struct v4l2_decoder_cmd
*dc
, int try)
239 struct ivtv_stream
*s
= &itv
->streams
[IVTV_DEC_STREAM_TYPE_MPG
];
241 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
245 case V4L2_DEC_CMD_START
: {
246 dc
->flags
&= V4L2_DEC_CMD_START_MUTE_AUDIO
;
247 dc
->start
.speed
= ivtv_validate_speed(itv
->speed
, dc
->start
.speed
);
248 if (dc
->start
.speed
< 0)
249 dc
->start
.format
= V4L2_DEC_START_FMT_GOP
;
251 dc
->start
.format
= V4L2_DEC_START_FMT_NONE
;
252 if (dc
->start
.speed
!= 500 && dc
->start
.speed
!= 1500)
253 dc
->flags
= dc
->start
.speed
== 1000 ? 0 :
254 V4L2_DEC_CMD_START_MUTE_AUDIO
;
257 itv
->speed_mute_audio
= dc
->flags
& V4L2_DEC_CMD_START_MUTE_AUDIO
;
258 if (ivtv_set_output_mode(itv
, OUT_MPG
) != OUT_MPG
)
260 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
)) {
261 /* forces ivtv_set_speed to be called */
264 return ivtv_start_decoding(id
, dc
->start
.speed
);
267 case V4L2_DEC_CMD_STOP
:
268 dc
->flags
&= V4L2_DEC_CMD_STOP_IMMEDIATELY
| V4L2_DEC_CMD_STOP_TO_BLACK
;
269 if (dc
->flags
& V4L2_DEC_CMD_STOP_IMMEDIATELY
)
272 if (atomic_read(&itv
->decoding
) == 0)
274 if (itv
->output_mode
!= OUT_MPG
)
277 itv
->output_mode
= OUT_NONE
;
278 return ivtv_stop_v4l2_decode_stream(s
, dc
->flags
, dc
->stop
.pts
);
280 case V4L2_DEC_CMD_PAUSE
:
281 dc
->flags
&= V4L2_DEC_CMD_PAUSE_TO_BLACK
;
283 if (!atomic_read(&itv
->decoding
))
285 if (itv
->output_mode
!= OUT_MPG
)
287 if (atomic_read(&itv
->decoding
) > 0) {
288 ivtv_vapi(itv
, CX2341X_DEC_PAUSE_PLAYBACK
, 1,
289 (dc
->flags
& V4L2_DEC_CMD_PAUSE_TO_BLACK
) ? 1 : 0);
290 set_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
);
294 case V4L2_DEC_CMD_RESUME
:
297 if (!atomic_read(&itv
->decoding
))
299 if (itv
->output_mode
!= OUT_MPG
)
301 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED
, &itv
->i_flags
)) {
302 int speed
= itv
->speed
;
304 return ivtv_start_decoding(id
, speed
);
314 static int ivtv_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
316 struct ivtv
*itv
= fh2id(fh
)->itv
;
317 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
319 vbifmt
->reserved
[0] = 0;
320 vbifmt
->reserved
[1] = 0;
321 if (!(itv
->v4l2_cap
& V4L2_CAP_SLICED_VBI_OUTPUT
))
323 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
324 memset(vbifmt
->service_lines
, 0, sizeof(vbifmt
->service_lines
));
326 vbifmt
->service_lines
[0][21] = V4L2_SLICED_CAPTION_525
;
327 vbifmt
->service_lines
[1][21] = V4L2_SLICED_CAPTION_525
;
329 vbifmt
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
330 vbifmt
->service_lines
[0][16] = V4L2_SLICED_VPS
;
332 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
336 static int ivtv_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
338 struct ivtv_open_id
*id
= fh2id(fh
);
339 struct ivtv
*itv
= id
->itv
;
340 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
342 pixfmt
->width
= itv
->cxhdl
.width
;
343 pixfmt
->height
= itv
->cxhdl
.height
;
344 pixfmt
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
345 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
346 if (id
->type
== IVTV_ENC_STREAM_TYPE_YUV
) {
347 pixfmt
->pixelformat
= V4L2_PIX_FMT_HM12
;
348 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
349 pixfmt
->sizeimage
= pixfmt
->height
* 720 * 3 / 2;
350 pixfmt
->bytesperline
= 720;
352 pixfmt
->pixelformat
= V4L2_PIX_FMT_MPEG
;
353 pixfmt
->sizeimage
= 128 * 1024;
354 pixfmt
->bytesperline
= 0;
359 static int ivtv_g_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
361 struct ivtv
*itv
= fh2id(fh
)->itv
;
362 struct v4l2_vbi_format
*vbifmt
= &fmt
->fmt
.vbi
;
364 vbifmt
->sampling_rate
= 27000000;
365 vbifmt
->offset
= 248;
366 vbifmt
->samples_per_line
= itv
->vbi
.raw_decoder_line_size
- 4;
367 vbifmt
->sample_format
= V4L2_PIX_FMT_GREY
;
368 vbifmt
->start
[0] = itv
->vbi
.start
[0];
369 vbifmt
->start
[1] = itv
->vbi
.start
[1];
370 vbifmt
->count
[0] = vbifmt
->count
[1] = itv
->vbi
.count
;
372 vbifmt
->reserved
[0] = 0;
373 vbifmt
->reserved
[1] = 0;
377 static int ivtv_g_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
379 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
380 struct ivtv_open_id
*id
= fh2id(fh
);
381 struct ivtv
*itv
= id
->itv
;
383 vbifmt
->reserved
[0] = 0;
384 vbifmt
->reserved
[1] = 0;
385 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
387 if (id
->type
== IVTV_DEC_STREAM_TYPE_VBI
) {
388 vbifmt
->service_set
= itv
->is_50hz
? V4L2_SLICED_VBI_625
:
390 ivtv_expand_service_set(vbifmt
, itv
->is_50hz
);
391 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
395 v4l2_subdev_call(itv
->sd_video
, vbi
, g_sliced_fmt
, vbifmt
);
396 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
400 static int ivtv_g_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
402 struct ivtv_open_id
*id
= fh2id(fh
);
403 struct ivtv
*itv
= id
->itv
;
404 struct v4l2_pix_format
*pixfmt
= &fmt
->fmt
.pix
;
406 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
408 pixfmt
->width
= itv
->main_rect
.width
;
409 pixfmt
->height
= itv
->main_rect
.height
;
410 pixfmt
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
411 pixfmt
->field
= V4L2_FIELD_INTERLACED
;
412 if (id
->type
== IVTV_DEC_STREAM_TYPE_YUV
) {
413 switch (itv
->yuv_info
.lace_mode
& IVTV_YUV_MODE_MASK
) {
414 case IVTV_YUV_MODE_INTERLACED
:
415 pixfmt
->field
= (itv
->yuv_info
.lace_mode
& IVTV_YUV_SYNC_MASK
) ?
416 V4L2_FIELD_INTERLACED_BT
: V4L2_FIELD_INTERLACED_TB
;
418 case IVTV_YUV_MODE_PROGRESSIVE
:
419 pixfmt
->field
= V4L2_FIELD_NONE
;
422 pixfmt
->field
= V4L2_FIELD_ANY
;
425 pixfmt
->pixelformat
= V4L2_PIX_FMT_HM12
;
426 pixfmt
->bytesperline
= 720;
427 pixfmt
->width
= itv
->yuv_info
.v4l2_src_w
;
428 pixfmt
->height
= itv
->yuv_info
.v4l2_src_h
;
429 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
431 1080 * ((pixfmt
->height
+ 31) & ~31);
433 pixfmt
->pixelformat
= V4L2_PIX_FMT_MPEG
;
434 pixfmt
->sizeimage
= 128 * 1024;
435 pixfmt
->bytesperline
= 0;
440 static int ivtv_g_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
442 struct ivtv
*itv
= fh2id(fh
)->itv
;
443 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
444 struct v4l2_window
*winfmt
= &fmt
->fmt
.win
;
446 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
448 if (!itv
->osd_video_pbase
)
450 winfmt
->chromakey
= itv
->osd_chroma_key
;
451 winfmt
->global_alpha
= itv
->osd_global_alpha
;
452 winfmt
->field
= V4L2_FIELD_INTERLACED
;
453 winfmt
->clips
= NULL
;
454 winfmt
->clipcount
= 0;
455 winfmt
->bitmap
= NULL
;
456 winfmt
->w
.top
= winfmt
->w
.left
= 0;
457 winfmt
->w
.width
= itv
->osd_rect
.width
;
458 winfmt
->w
.height
= itv
->osd_rect
.height
;
462 static int ivtv_try_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
464 return ivtv_g_fmt_sliced_vbi_out(file
, fh
, fmt
);
467 static int ivtv_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
469 struct ivtv_open_id
*id
= fh2id(fh
);
470 struct ivtv
*itv
= id
->itv
;
471 int w
= fmt
->fmt
.pix
.width
;
472 int h
= fmt
->fmt
.pix
.height
;
477 if (id
->type
== IVTV_ENC_STREAM_TYPE_YUV
) {
478 /* YUV height must be a multiple of 32 */
482 h
= min(h
, itv
->is_50hz
? 576 : 480);
484 ivtv_g_fmt_vid_cap(file
, fh
, fmt
);
485 fmt
->fmt
.pix
.width
= w
;
486 fmt
->fmt
.pix
.height
= h
;
490 static int ivtv_try_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
492 return ivtv_g_fmt_vbi_cap(file
, fh
, fmt
);
495 static int ivtv_try_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
497 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
498 struct ivtv_open_id
*id
= fh2id(fh
);
499 struct ivtv
*itv
= id
->itv
;
501 if (id
->type
== IVTV_DEC_STREAM_TYPE_VBI
)
502 return ivtv_g_fmt_sliced_vbi_cap(file
, fh
, fmt
);
504 /* set sliced VBI capture format */
505 vbifmt
->io_size
= sizeof(struct v4l2_sliced_vbi_data
) * 36;
506 vbifmt
->reserved
[0] = 0;
507 vbifmt
->reserved
[1] = 0;
509 if (vbifmt
->service_set
)
510 ivtv_expand_service_set(vbifmt
, itv
->is_50hz
);
511 check_service_set(vbifmt
, itv
->is_50hz
);
512 vbifmt
->service_set
= ivtv_get_service_set(vbifmt
);
516 static int ivtv_try_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
518 struct ivtv_open_id
*id
= fh2id(fh
);
519 s32 w
= fmt
->fmt
.pix
.width
;
520 s32 h
= fmt
->fmt
.pix
.height
;
521 int field
= fmt
->fmt
.pix
.field
;
522 int ret
= ivtv_g_fmt_vid_out(file
, fh
, fmt
);
526 /* Why can the height be 576 even when the output is NTSC?
528 Internally the buffers of the PVR350 are always set to 720x576. The
529 decoded video frame will always be placed in the top left corner of
530 this buffer. For any video which is not 720x576, the buffer will
531 then be cropped to remove the unused right and lower areas, with
532 the remaining image being scaled by the hardware to fit the display
533 area. The video can be scaled both up and down, so a 720x480 video
534 can be displayed full-screen on PAL and a 720x576 video can be
535 displayed without cropping on NTSC.
537 Note that the scaling only occurs on the video stream, the osd
538 resolution is locked to the broadcast standard and not scaled.
540 Thanks to Ian Armstrong for this explanation. */
543 if (id
->type
== IVTV_DEC_STREAM_TYPE_YUV
)
544 fmt
->fmt
.pix
.field
= field
;
545 fmt
->fmt
.pix
.width
= w
;
546 fmt
->fmt
.pix
.height
= h
;
550 static int ivtv_try_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
552 struct ivtv
*itv
= fh2id(fh
)->itv
;
553 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
554 u32 chromakey
= fmt
->fmt
.win
.chromakey
;
555 u8 global_alpha
= fmt
->fmt
.win
.global_alpha
;
557 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
559 if (!itv
->osd_video_pbase
)
561 ivtv_g_fmt_vid_out_overlay(file
, fh
, fmt
);
562 fmt
->fmt
.win
.chromakey
= chromakey
;
563 fmt
->fmt
.win
.global_alpha
= global_alpha
;
567 static int ivtv_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
569 return ivtv_g_fmt_sliced_vbi_out(file
, fh
, fmt
);
572 static int ivtv_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
574 struct ivtv_open_id
*id
= fh2id(fh
);
575 struct ivtv
*itv
= id
->itv
;
576 struct v4l2_subdev_format format
= {
577 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
579 int ret
= ivtv_try_fmt_vid_cap(file
, fh
, fmt
);
580 int w
= fmt
->fmt
.pix
.width
;
581 int h
= fmt
->fmt
.pix
.height
;
586 if (itv
->cxhdl
.width
== w
&& itv
->cxhdl
.height
== h
)
589 if (atomic_read(&itv
->capturing
) > 0)
592 itv
->cxhdl
.width
= w
;
593 itv
->cxhdl
.height
= h
;
594 if (v4l2_ctrl_g_ctrl(itv
->cxhdl
.video_encoding
) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1
)
595 fmt
->fmt
.pix
.width
/= 2;
596 format
.format
.width
= fmt
->fmt
.pix
.width
;
597 format
.format
.height
= h
;
598 format
.format
.code
= MEDIA_BUS_FMT_FIXED
;
599 v4l2_subdev_call(itv
->sd_video
, pad
, set_fmt
, NULL
, &format
);
600 return ivtv_g_fmt_vid_cap(file
, fh
, fmt
);
603 static int ivtv_s_fmt_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
605 struct ivtv
*itv
= fh2id(fh
)->itv
;
607 if (!ivtv_raw_vbi(itv
) && atomic_read(&itv
->capturing
) > 0)
609 itv
->vbi
.sliced_in
->service_set
= 0;
610 itv
->vbi
.in
.type
= V4L2_BUF_TYPE_VBI_CAPTURE
;
611 v4l2_subdev_call(itv
->sd_video
, vbi
, s_raw_fmt
, &fmt
->fmt
.vbi
);
612 return ivtv_g_fmt_vbi_cap(file
, fh
, fmt
);
615 static int ivtv_s_fmt_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
617 struct v4l2_sliced_vbi_format
*vbifmt
= &fmt
->fmt
.sliced
;
618 struct ivtv_open_id
*id
= fh2id(fh
);
619 struct ivtv
*itv
= id
->itv
;
620 int ret
= ivtv_try_fmt_sliced_vbi_cap(file
, fh
, fmt
);
622 if (ret
|| id
->type
== IVTV_DEC_STREAM_TYPE_VBI
)
625 check_service_set(vbifmt
, itv
->is_50hz
);
626 if (ivtv_raw_vbi(itv
) && atomic_read(&itv
->capturing
) > 0)
628 itv
->vbi
.in
.type
= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
;
629 v4l2_subdev_call(itv
->sd_video
, vbi
, s_sliced_fmt
, vbifmt
);
630 memcpy(itv
->vbi
.sliced_in
, vbifmt
, sizeof(*itv
->vbi
.sliced_in
));
634 static int ivtv_s_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
636 struct ivtv_open_id
*id
= fh2id(fh
);
637 struct ivtv
*itv
= id
->itv
;
638 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
639 int ret
= ivtv_try_fmt_vid_out(file
, fh
, fmt
);
644 if (id
->type
!= IVTV_DEC_STREAM_TYPE_YUV
)
647 /* Return now if we already have some frame data */
651 yi
->v4l2_src_w
= fmt
->fmt
.pix
.width
;
652 yi
->v4l2_src_h
= fmt
->fmt
.pix
.height
;
654 switch (fmt
->fmt
.pix
.field
) {
655 case V4L2_FIELD_NONE
:
656 yi
->lace_mode
= IVTV_YUV_MODE_PROGRESSIVE
;
659 yi
->lace_mode
= IVTV_YUV_MODE_AUTO
;
661 case V4L2_FIELD_INTERLACED_BT
:
663 IVTV_YUV_MODE_INTERLACED
|IVTV_YUV_SYNC_ODD
;
665 case V4L2_FIELD_INTERLACED_TB
:
667 yi
->lace_mode
= IVTV_YUV_MODE_INTERLACED
;
670 yi
->lace_sync_field
= (yi
->lace_mode
& IVTV_YUV_SYNC_MASK
) == IVTV_YUV_SYNC_EVEN
? 0 : 1;
672 if (test_bit(IVTV_F_I_DEC_YUV
, &itv
->i_flags
))
673 itv
->dma_data_req_size
=
674 1080 * ((yi
->v4l2_src_h
+ 31) & ~31);
679 static int ivtv_s_fmt_vid_out_overlay(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
681 struct ivtv
*itv
= fh2id(fh
)->itv
;
682 int ret
= ivtv_try_fmt_vid_out_overlay(file
, fh
, fmt
);
685 itv
->osd_chroma_key
= fmt
->fmt
.win
.chromakey
;
686 itv
->osd_global_alpha
= fmt
->fmt
.win
.global_alpha
;
687 ivtv_set_osd_alpha(itv
);
692 #ifdef CONFIG_VIDEO_ADV_DEBUG
693 static int ivtv_itvc(struct ivtv
*itv
, bool get
, u64 reg
, u64
*val
)
695 volatile u8 __iomem
*reg_start
;
699 if (reg
>= IVTV_REG_OFFSET
&& reg
< IVTV_REG_OFFSET
+ IVTV_REG_SIZE
)
700 reg_start
= itv
->reg_mem
- IVTV_REG_OFFSET
;
701 else if (itv
->has_cx23415
&& reg
>= IVTV_DECODER_OFFSET
&&
702 reg
< IVTV_DECODER_OFFSET
+ IVTV_DECODER_SIZE
)
703 reg_start
= itv
->dec_mem
- IVTV_DECODER_OFFSET
;
704 else if (reg
< IVTV_ENCODER_SIZE
)
705 reg_start
= itv
->enc_mem
;
710 *val
= readl(reg
+ reg_start
);
712 writel(*val
, reg
+ reg_start
);
716 static int ivtv_g_register(struct file
*file
, void *fh
, struct v4l2_dbg_register
*reg
)
718 struct ivtv
*itv
= fh2id(fh
)->itv
;
721 return ivtv_itvc(itv
, true, reg
->reg
, ®
->val
);
724 static int ivtv_s_register(struct file
*file
, void *fh
, const struct v4l2_dbg_register
*reg
)
726 struct ivtv
*itv
= fh2id(fh
)->itv
;
729 return ivtv_itvc(itv
, false, reg
->reg
, &val
);
733 static int ivtv_querycap(struct file
*file
, void *fh
, struct v4l2_capability
*vcap
)
735 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
736 struct ivtv
*itv
= id
->itv
;
738 strscpy(vcap
->driver
, IVTV_DRIVER_NAME
, sizeof(vcap
->driver
));
739 strscpy(vcap
->card
, itv
->card_name
, sizeof(vcap
->card
));
740 snprintf(vcap
->bus_info
, sizeof(vcap
->bus_info
), "PCI:%s", pci_name(itv
->pdev
));
741 vcap
->capabilities
= itv
->v4l2_cap
| V4L2_CAP_DEVICE_CAPS
;
745 static int ivtv_enumaudio(struct file
*file
, void *fh
, struct v4l2_audio
*vin
)
747 struct ivtv
*itv
= fh2id(fh
)->itv
;
749 return ivtv_get_audio_input(itv
, vin
->index
, vin
);
752 static int ivtv_g_audio(struct file
*file
, void *fh
, struct v4l2_audio
*vin
)
754 struct ivtv
*itv
= fh2id(fh
)->itv
;
756 vin
->index
= itv
->audio_input
;
757 return ivtv_get_audio_input(itv
, vin
->index
, vin
);
760 static int ivtv_s_audio(struct file
*file
, void *fh
, const struct v4l2_audio
*vout
)
762 struct ivtv
*itv
= fh2id(fh
)->itv
;
764 if (vout
->index
>= itv
->nof_audio_inputs
)
767 itv
->audio_input
= vout
->index
;
768 ivtv_audio_set_io(itv
);
773 static int ivtv_enumaudout(struct file
*file
, void *fh
, struct v4l2_audioout
*vin
)
775 struct ivtv
*itv
= fh2id(fh
)->itv
;
777 /* set it to defaults from our table */
778 return ivtv_get_audio_output(itv
, vin
->index
, vin
);
781 static int ivtv_g_audout(struct file
*file
, void *fh
, struct v4l2_audioout
*vin
)
783 struct ivtv
*itv
= fh2id(fh
)->itv
;
786 return ivtv_get_audio_output(itv
, vin
->index
, vin
);
789 static int ivtv_s_audout(struct file
*file
, void *fh
, const struct v4l2_audioout
*vout
)
791 struct ivtv
*itv
= fh2id(fh
)->itv
;
793 if (itv
->card
->video_outputs
== NULL
|| vout
->index
!= 0)
798 static int ivtv_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
800 struct ivtv
*itv
= fh2id(fh
)->itv
;
802 /* set it to defaults from our table */
803 return ivtv_get_input(itv
, vin
->index
, vin
);
806 static int ivtv_enum_output(struct file
*file
, void *fh
, struct v4l2_output
*vout
)
808 struct ivtv
*itv
= fh2id(fh
)->itv
;
810 return ivtv_get_output(itv
, vout
->index
, vout
);
813 static int ivtv_g_pixelaspect(struct file
*file
, void *fh
,
814 int type
, struct v4l2_fract
*f
)
816 struct ivtv_open_id
*id
= fh2id(fh
);
817 struct ivtv
*itv
= id
->itv
;
819 if (type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
820 f
->numerator
= itv
->is_50hz
? 54 : 11;
821 f
->denominator
= itv
->is_50hz
? 59 : 10;
822 } else if (type
== V4L2_BUF_TYPE_VIDEO_OUTPUT
) {
823 f
->numerator
= itv
->is_out_50hz
? 54 : 11;
824 f
->denominator
= itv
->is_out_50hz
? 59 : 10;
831 static int ivtv_s_selection(struct file
*file
, void *fh
,
832 struct v4l2_selection
*sel
)
834 struct ivtv_open_id
*id
= fh2id(fh
);
835 struct ivtv
*itv
= id
->itv
;
836 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
837 struct v4l2_rect r
= { 0, 0, 720, 0 };
838 int streamtype
= id
->type
;
840 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
841 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
844 if (sel
->target
!= V4L2_SEL_TGT_COMPOSE
)
848 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
849 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
852 r
.height
= itv
->is_out_50hz
? 576 : 480;
853 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
&& yi
->track_osd
) {
854 r
.width
= yi
->osd_full_w
;
855 r
.height
= yi
->osd_full_h
;
857 sel
->r
.width
= clamp(sel
->r
.width
, 16U, r
.width
);
858 sel
->r
.height
= clamp(sel
->r
.height
, 16U, r
.height
);
859 sel
->r
.left
= clamp_t(unsigned, sel
->r
.left
, 0, r
.width
- sel
->r
.width
);
860 sel
->r
.top
= clamp_t(unsigned, sel
->r
.top
, 0, r
.height
- sel
->r
.height
);
862 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
) {
863 yi
->main_rect
= sel
->r
;
866 if (!ivtv_vapi(itv
, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW
, 4,
867 sel
->r
.width
, sel
->r
.height
, sel
->r
.left
, sel
->r
.top
)) {
868 itv
->main_rect
= sel
->r
;
874 static int ivtv_g_selection(struct file
*file
, void *fh
,
875 struct v4l2_selection
*sel
)
877 struct ivtv_open_id
*id
= fh2id(fh
);
878 struct ivtv
*itv
= id
->itv
;
879 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
880 struct v4l2_rect r
= { 0, 0, 720, 0 };
881 int streamtype
= id
->type
;
883 if (sel
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
884 switch (sel
->target
) {
885 case V4L2_SEL_TGT_CROP_DEFAULT
:
886 case V4L2_SEL_TGT_CROP_BOUNDS
:
887 sel
->r
.top
= sel
->r
.left
= 0;
889 sel
->r
.height
= itv
->is_50hz
? 576 : 480;
896 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
897 !(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
900 switch (sel
->target
) {
901 case V4L2_SEL_TGT_COMPOSE
:
902 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
)
903 sel
->r
= yi
->main_rect
;
905 sel
->r
= itv
->main_rect
;
907 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
908 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
909 r
.height
= itv
->is_out_50hz
? 576 : 480;
910 if (streamtype
== IVTV_DEC_STREAM_TYPE_YUV
&& yi
->track_osd
) {
911 r
.width
= yi
->osd_full_w
;
912 r
.height
= yi
->osd_full_h
;
920 static int ivtv_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
922 static const struct v4l2_fmtdesc hm12
= {
923 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
924 .description
= "HM12 (YUV 4:2:0)",
925 .pixelformat
= V4L2_PIX_FMT_HM12
,
927 static const struct v4l2_fmtdesc mpeg
= {
928 .type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
,
929 .flags
= V4L2_FMT_FLAG_COMPRESSED
,
930 .description
= "MPEG",
931 .pixelformat
= V4L2_PIX_FMT_MPEG
,
933 struct ivtv
*itv
= fh2id(fh
)->itv
;
934 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
938 if (s
->type
== IVTV_ENC_STREAM_TYPE_MPG
)
940 else if (s
->type
== IVTV_ENC_STREAM_TYPE_YUV
)
947 static int ivtv_enum_fmt_vid_out(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
949 static const struct v4l2_fmtdesc hm12
= {
950 .type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
,
951 .description
= "HM12 (YUV 4:2:0)",
952 .pixelformat
= V4L2_PIX_FMT_HM12
,
954 static const struct v4l2_fmtdesc mpeg
= {
955 .type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
,
956 .flags
= V4L2_FMT_FLAG_COMPRESSED
,
957 .description
= "MPEG",
958 .pixelformat
= V4L2_PIX_FMT_MPEG
,
960 struct ivtv
*itv
= fh2id(fh
)->itv
;
961 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
965 if (s
->type
== IVTV_DEC_STREAM_TYPE_MPG
)
967 else if (s
->type
== IVTV_DEC_STREAM_TYPE_YUV
)
974 static int ivtv_g_input(struct file
*file
, void *fh
, unsigned int *i
)
976 struct ivtv
*itv
= fh2id(fh
)->itv
;
978 *i
= itv
->active_input
;
983 int ivtv_s_input(struct file
*file
, void *fh
, unsigned int inp
)
985 struct ivtv
*itv
= fh2id(fh
)->itv
;
989 if (inp
>= itv
->nof_inputs
)
992 if (inp
== itv
->active_input
) {
993 IVTV_DEBUG_INFO("Input unchanged\n");
997 if (atomic_read(&itv
->capturing
) > 0) {
1001 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
1002 itv
->active_input
, inp
);
1004 itv
->active_input
= inp
;
1005 /* Set the audio input to whatever is appropriate for the
1007 itv
->audio_input
= itv
->card
->video_inputs
[inp
].audio_index
;
1009 if (itv
->card
->video_inputs
[inp
].video_type
== IVTV_CARD_INPUT_VID_TUNER
)
1010 std
= itv
->tuner_std
;
1013 for (i
= 0; i
<= IVTV_ENC_STREAM_TYPE_VBI
; i
++)
1014 itv
->streams
[i
].vdev
.tvnorms
= std
;
1016 /* prevent others from messing with the streams until
1017 we're finished changing inputs. */
1019 ivtv_video_set_io(itv
);
1020 ivtv_audio_set_io(itv
);
1026 static int ivtv_g_output(struct file
*file
, void *fh
, unsigned int *i
)
1028 struct ivtv
*itv
= fh2id(fh
)->itv
;
1030 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1033 *i
= itv
->active_output
;
1038 static int ivtv_s_output(struct file
*file
, void *fh
, unsigned int outp
)
1040 struct ivtv
*itv
= fh2id(fh
)->itv
;
1042 if (outp
>= itv
->card
->nof_outputs
)
1045 if (outp
== itv
->active_output
) {
1046 IVTV_DEBUG_INFO("Output unchanged\n");
1049 IVTV_DEBUG_INFO("Changing output from %d to %d\n",
1050 itv
->active_output
, outp
);
1052 itv
->active_output
= outp
;
1053 ivtv_call_hw(itv
, IVTV_HW_SAA7127
, video
, s_routing
,
1054 SAA7127_INPUT_TYPE_NORMAL
,
1055 itv
->card
->video_outputs
[outp
].video_output
, 0);
1060 static int ivtv_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*vf
)
1062 struct ivtv
*itv
= fh2id(fh
)->itv
;
1063 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1065 if (s
->vdev
.vfl_dir
)
1070 ivtv_call_all(itv
, tuner
, g_frequency
, vf
);
1074 int ivtv_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*vf
)
1076 struct ivtv
*itv
= fh2id(fh
)->itv
;
1077 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1079 if (s
->vdev
.vfl_dir
)
1085 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf
->frequency
);
1086 ivtv_call_all(itv
, tuner
, s_frequency
, vf
);
1091 static int ivtv_g_std(struct file
*file
, void *fh
, v4l2_std_id
*std
)
1093 struct ivtv
*itv
= fh2id(fh
)->itv
;
1099 void ivtv_s_std_enc(struct ivtv
*itv
, v4l2_std_id std
)
1102 itv
->is_60hz
= (std
& V4L2_STD_525_60
) ? 1 : 0;
1103 itv
->is_50hz
= !itv
->is_60hz
;
1104 cx2341x_handler_set_50hz(&itv
->cxhdl
, itv
->is_50hz
);
1105 itv
->cxhdl
.width
= 720;
1106 itv
->cxhdl
.height
= itv
->is_50hz
? 576 : 480;
1107 itv
->vbi
.count
= itv
->is_50hz
? 18 : 12;
1108 itv
->vbi
.start
[0] = itv
->is_50hz
? 6 : 10;
1109 itv
->vbi
.start
[1] = itv
->is_50hz
? 318 : 273;
1111 if (itv
->hw_flags
& IVTV_HW_CX25840
)
1112 itv
->vbi
.sliced_decoder_line_size
= itv
->is_60hz
? 272 : 284;
1115 ivtv_call_all(itv
, video
, s_std
, itv
->std
);
1118 void ivtv_s_std_dec(struct ivtv
*itv
, v4l2_std_id std
)
1120 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1124 /* set display standard */
1126 itv
->is_out_60hz
= (std
& V4L2_STD_525_60
) ? 1 : 0;
1127 itv
->is_out_50hz
= !itv
->is_out_60hz
;
1128 ivtv_call_all(itv
, video
, s_std_output
, itv
->std_out
);
1131 * The next firmware call is time sensitive. Time it to
1132 * avoid risk of a hard lock, by trying to ensure the call
1133 * happens within the first 100 lines of the top field.
1134 * Make 4 attempts to sync to the decoder before giving up.
1136 mutex_unlock(&itv
->serialize_lock
);
1137 for (f
= 0; f
< 4; f
++) {
1138 prepare_to_wait(&itv
->vsync_waitq
, &wait
,
1139 TASK_UNINTERRUPTIBLE
);
1140 if ((read_reg(IVTV_REG_DEC_LINE_FIELD
) >> 16) < 100)
1142 schedule_timeout(msecs_to_jiffies(25));
1144 finish_wait(&itv
->vsync_waitq
, &wait
);
1145 mutex_lock(&itv
->serialize_lock
);
1148 IVTV_WARN("Mode change failed to sync to decoder\n");
1150 ivtv_vapi(itv
, CX2341X_DEC_SET_STANDARD
, 1, itv
->is_out_50hz
);
1151 itv
->main_rect
.left
= 0;
1152 itv
->main_rect
.top
= 0;
1153 itv
->main_rect
.width
= 720;
1154 itv
->main_rect
.height
= itv
->is_out_50hz
? 576 : 480;
1155 ivtv_vapi(itv
, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW
, 4,
1156 720, itv
->main_rect
.height
, 0, 0);
1157 yi
->main_rect
= itv
->main_rect
;
1158 if (!itv
->osd_info
) {
1159 yi
->osd_full_w
= 720;
1160 yi
->osd_full_h
= itv
->is_out_50hz
? 576 : 480;
1164 static int ivtv_s_std(struct file
*file
, void *fh
, v4l2_std_id std
)
1166 struct ivtv
*itv
= fh2id(fh
)->itv
;
1168 if ((std
& V4L2_STD_ALL
) == 0)
1171 if (std
== itv
->std
)
1174 if (test_bit(IVTV_F_I_RADIO_USER
, &itv
->i_flags
) ||
1175 atomic_read(&itv
->capturing
) > 0 ||
1176 atomic_read(&itv
->decoding
) > 0) {
1177 /* Switching standard would mess with already running
1178 streams, prevent that by returning EBUSY. */
1182 IVTV_DEBUG_INFO("Switching standard to %llx.\n",
1183 (unsigned long long)itv
->std
);
1185 ivtv_s_std_enc(itv
, std
);
1186 if (itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
)
1187 ivtv_s_std_dec(itv
, std
);
1192 static int ivtv_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*vt
)
1194 struct ivtv_open_id
*id
= fh2id(fh
);
1195 struct ivtv
*itv
= id
->itv
;
1200 ivtv_call_all(itv
, tuner
, s_tuner
, vt
);
1205 static int ivtv_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*vt
)
1207 struct ivtv
*itv
= fh2id(fh
)->itv
;
1212 ivtv_call_all(itv
, tuner
, g_tuner
, vt
);
1214 if (vt
->type
== V4L2_TUNER_RADIO
)
1215 strscpy(vt
->name
, "ivtv Radio Tuner", sizeof(vt
->name
));
1217 strscpy(vt
->name
, "ivtv TV Tuner", sizeof(vt
->name
));
1221 static int ivtv_g_sliced_vbi_cap(struct file
*file
, void *fh
, struct v4l2_sliced_vbi_cap
*cap
)
1223 struct ivtv
*itv
= fh2id(fh
)->itv
;
1224 int set
= itv
->is_50hz
? V4L2_SLICED_VBI_625
: V4L2_SLICED_VBI_525
;
1227 if (cap
->type
== V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
) {
1228 for (f
= 0; f
< 2; f
++) {
1229 for (l
= 0; l
< 24; l
++) {
1230 if (valid_service_line(f
, l
, itv
->is_50hz
))
1231 cap
->service_lines
[f
][l
] = set
;
1234 } else if (cap
->type
== V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
) {
1235 if (!(itv
->v4l2_cap
& V4L2_CAP_SLICED_VBI_OUTPUT
))
1238 cap
->service_lines
[0][21] = V4L2_SLICED_CAPTION_525
;
1239 cap
->service_lines
[1][21] = V4L2_SLICED_CAPTION_525
;
1241 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
1242 cap
->service_lines
[0][16] = V4L2_SLICED_VPS
;
1249 for (f
= 0; f
< 2; f
++)
1250 for (l
= 0; l
< 24; l
++)
1251 set
|= cap
->service_lines
[f
][l
];
1252 cap
->service_set
= set
;
1256 static int ivtv_g_enc_index(struct file
*file
, void *fh
, struct v4l2_enc_idx
*idx
)
1258 struct ivtv
*itv
= fh2id(fh
)->itv
;
1259 struct v4l2_enc_idx_entry
*e
= idx
->entry
;
1263 entries
= (itv
->pgm_info_write_idx
+ IVTV_MAX_PGM_INDEX
- itv
->pgm_info_read_idx
) %
1265 if (entries
> V4L2_ENC_IDX_ENTRIES
)
1266 entries
= V4L2_ENC_IDX_ENTRIES
;
1268 idx
->entries_cap
= IVTV_MAX_PGM_INDEX
;
1269 if (!atomic_read(&itv
->capturing
))
1271 for (i
= 0; i
< entries
; i
++) {
1272 *e
= itv
->pgm_info
[(itv
->pgm_info_read_idx
+ i
) % IVTV_MAX_PGM_INDEX
];
1273 if ((e
->flags
& V4L2_ENC_IDX_FRAME_MASK
) <= V4L2_ENC_IDX_FRAME_B
) {
1278 itv
->pgm_info_read_idx
= (itv
->pgm_info_read_idx
+ idx
->entries
) % IVTV_MAX_PGM_INDEX
;
1282 static int ivtv_encoder_cmd(struct file
*file
, void *fh
, struct v4l2_encoder_cmd
*enc
)
1284 struct ivtv_open_id
*id
= fh2id(fh
);
1285 struct ivtv
*itv
= id
->itv
;
1289 case V4L2_ENC_CMD_START
:
1290 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1292 return ivtv_start_capture(id
);
1294 case V4L2_ENC_CMD_STOP
:
1295 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1296 enc
->flags
&= V4L2_ENC_CMD_STOP_AT_GOP_END
;
1297 ivtv_stop_capture(id
, enc
->flags
& V4L2_ENC_CMD_STOP_AT_GOP_END
);
1300 case V4L2_ENC_CMD_PAUSE
:
1301 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1304 if (!atomic_read(&itv
->capturing
))
1306 if (test_and_set_bit(IVTV_F_I_ENC_PAUSED
, &itv
->i_flags
))
1310 ivtv_vapi(itv
, CX2341X_ENC_PAUSE_ENCODER
, 1, 0);
1313 case V4L2_ENC_CMD_RESUME
:
1314 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1317 if (!atomic_read(&itv
->capturing
))
1320 if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED
, &itv
->i_flags
))
1323 ivtv_vapi(itv
, CX2341X_ENC_PAUSE_ENCODER
, 1, 1);
1327 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc
->cmd
);
1334 static int ivtv_try_encoder_cmd(struct file
*file
, void *fh
, struct v4l2_encoder_cmd
*enc
)
1336 struct ivtv
*itv
= fh2id(fh
)->itv
;
1339 case V4L2_ENC_CMD_START
:
1340 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1344 case V4L2_ENC_CMD_STOP
:
1345 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1346 enc
->flags
&= V4L2_ENC_CMD_STOP_AT_GOP_END
;
1349 case V4L2_ENC_CMD_PAUSE
:
1350 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1354 case V4L2_ENC_CMD_RESUME
:
1355 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1359 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc
->cmd
);
1364 static int ivtv_g_fbuf(struct file
*file
, void *fh
, struct v4l2_framebuffer
*fb
)
1366 struct ivtv
*itv
= fh2id(fh
)->itv
;
1367 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1368 u32 data
[CX2341X_MBOX_MAX_DATA
];
1369 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1372 static u32 pixel_format
[16] = {
1373 V4L2_PIX_FMT_PAL8
, /* Uses a 256-entry RGB colormap */
1374 V4L2_PIX_FMT_RGB565
,
1375 V4L2_PIX_FMT_RGB555
,
1376 V4L2_PIX_FMT_RGB444
,
1381 V4L2_PIX_FMT_PAL8
, /* Uses a 256-entry YUV colormap */
1382 V4L2_PIX_FMT_YUV565
,
1383 V4L2_PIX_FMT_YUV555
,
1384 V4L2_PIX_FMT_YUV444
,
1391 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1393 if (!itv
->osd_video_pbase
)
1396 fb
->capability
= V4L2_FBUF_CAP_EXTERNOVERLAY
| V4L2_FBUF_CAP_CHROMAKEY
|
1397 V4L2_FBUF_CAP_GLOBAL_ALPHA
;
1399 ivtv_vapi_result(itv
, data
, CX2341X_OSD_GET_STATE
, 0);
1400 data
[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1401 pixfmt
= (data
[0] >> 3) & 0xf;
1403 fb
->fmt
.pixelformat
= pixel_format
[pixfmt
];
1404 fb
->fmt
.width
= itv
->osd_rect
.width
;
1405 fb
->fmt
.height
= itv
->osd_rect
.height
;
1406 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
1407 fb
->fmt
.bytesperline
= fb
->fmt
.width
;
1408 fb
->fmt
.colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1409 fb
->fmt
.field
= V4L2_FIELD_INTERLACED
;
1410 if (fb
->fmt
.pixelformat
!= V4L2_PIX_FMT_PAL8
)
1411 fb
->fmt
.bytesperline
*= 2;
1412 if (fb
->fmt
.pixelformat
== V4L2_PIX_FMT_RGB32
||
1413 fb
->fmt
.pixelformat
== V4L2_PIX_FMT_YUV32
)
1414 fb
->fmt
.bytesperline
*= 2;
1415 fb
->fmt
.sizeimage
= fb
->fmt
.bytesperline
* fb
->fmt
.height
;
1416 fb
->base
= (void *)itv
->osd_video_pbase
;
1419 if (itv
->osd_chroma_key_state
)
1420 fb
->flags
|= V4L2_FBUF_FLAG_CHROMAKEY
;
1422 if (itv
->osd_global_alpha_state
)
1423 fb
->flags
|= V4L2_FBUF_FLAG_GLOBAL_ALPHA
;
1426 fb
->flags
|= V4L2_FBUF_FLAG_OVERLAY
;
1430 /* no local alpha for RGB565 or unknown formats */
1431 if (pixfmt
== 1 || pixfmt
> 4)
1434 /* 16-bit formats have inverted local alpha */
1435 if (pixfmt
== 2 || pixfmt
== 3)
1436 fb
->capability
|= V4L2_FBUF_CAP_LOCAL_INV_ALPHA
;
1438 fb
->capability
|= V4L2_FBUF_CAP_LOCAL_ALPHA
;
1440 if (itv
->osd_local_alpha_state
) {
1441 /* 16-bit formats have inverted local alpha */
1442 if (pixfmt
== 2 || pixfmt
== 3)
1443 fb
->flags
|= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA
;
1445 fb
->flags
|= V4L2_FBUF_FLAG_LOCAL_ALPHA
;
1451 static int ivtv_s_fbuf(struct file
*file
, void *fh
, const struct v4l2_framebuffer
*fb
)
1453 struct ivtv_open_id
*id
= fh2id(fh
);
1454 struct ivtv
*itv
= id
->itv
;
1455 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1456 struct yuv_playback_info
*yi
= &itv
->yuv_info
;
1458 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1460 if (!itv
->osd_video_pbase
)
1463 itv
->osd_global_alpha_state
= (fb
->flags
& V4L2_FBUF_FLAG_GLOBAL_ALPHA
) != 0;
1464 itv
->osd_local_alpha_state
=
1465 (fb
->flags
& (V4L2_FBUF_FLAG_LOCAL_ALPHA
|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA
)) != 0;
1466 itv
->osd_chroma_key_state
= (fb
->flags
& V4L2_FBUF_FLAG_CHROMAKEY
) != 0;
1467 ivtv_set_osd_alpha(itv
);
1468 yi
->track_osd
= (fb
->flags
& V4L2_FBUF_FLAG_OVERLAY
) != 0;
1472 static int ivtv_overlay(struct file
*file
, void *fh
, unsigned int on
)
1474 struct ivtv_open_id
*id
= fh2id(fh
);
1475 struct ivtv
*itv
= id
->itv
;
1476 struct ivtv_stream
*s
= &itv
->streams
[fh2id(fh
)->type
];
1478 if (!(s
->caps
& V4L2_CAP_VIDEO_OUTPUT_OVERLAY
))
1480 if (!itv
->osd_video_pbase
)
1483 ivtv_vapi(itv
, CX2341X_OSD_SET_STATE
, 1, on
!= 0);
1488 static int ivtv_subscribe_event(struct v4l2_fh
*fh
, const struct v4l2_event_subscription
*sub
)
1490 switch (sub
->type
) {
1491 case V4L2_EVENT_VSYNC
:
1492 case V4L2_EVENT_EOS
:
1493 return v4l2_event_subscribe(fh
, sub
, 0, NULL
);
1495 return v4l2_ctrl_subscribe_event(fh
, sub
);
1499 static int ivtv_log_status(struct file
*file
, void *fh
)
1501 struct ivtv
*itv
= fh2id(fh
)->itv
;
1502 u32 data
[CX2341X_MBOX_MAX_DATA
];
1504 int has_output
= itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
;
1505 struct v4l2_input vidin
;
1506 struct v4l2_audio audin
;
1509 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION
, itv
->card_name
);
1510 if (itv
->hw_flags
& IVTV_HW_TVEEPROM
) {
1513 ivtv_read_eeprom(itv
, &tv
);
1515 ivtv_call_all(itv
, core
, log_status
);
1516 ivtv_get_input(itv
, itv
->active_input
, &vidin
);
1517 ivtv_get_audio_input(itv
, itv
->audio_input
, &audin
);
1518 IVTV_INFO("Video Input: %s\n", vidin
.name
);
1519 IVTV_INFO("Audio Input: %s%s\n", audin
.name
,
1520 itv
->dualwatch_stereo_mode
== V4L2_MPEG_AUDIO_MODE_DUAL
?
1521 " (Bilingual)" : "");
1523 struct v4l2_output vidout
;
1524 struct v4l2_audioout audout
;
1525 int mode
= itv
->output_mode
;
1526 static const char * const output_modes
[5] = {
1533 static const char * const alpha_mode
[4] = {
1539 static const char * const pixel_format
[16] = {
1558 ivtv_get_output(itv
, itv
->active_output
, &vidout
);
1559 ivtv_get_audio_output(itv
, 0, &audout
);
1560 IVTV_INFO("Video Output: %s\n", vidout
.name
);
1561 if (mode
< 0 || mode
> OUT_PASSTHROUGH
)
1563 IVTV_INFO("Output Mode: %s\n", output_modes
[mode
]);
1564 ivtv_vapi_result(itv
, data
, CX2341X_OSD_GET_STATE
, 0);
1565 data
[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1566 IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1567 data
[0] & 1 ? "On" : "Off",
1568 alpha_mode
[(data
[0] >> 1) & 0x3],
1569 pixel_format
[(data
[0] >> 3) & 0xf]);
1571 IVTV_INFO("Tuner: %s\n",
1572 test_bit(IVTV_F_I_RADIO_USER
, &itv
->i_flags
) ? "Radio" : "TV");
1573 v4l2_ctrl_handler_log_status(&itv
->cxhdl
.hdl
, itv
->v4l2_dev
.name
);
1574 IVTV_INFO("Status flags: 0x%08lx\n", itv
->i_flags
);
1575 for (i
= 0; i
< IVTV_MAX_STREAMS
; i
++) {
1576 struct ivtv_stream
*s
= &itv
->streams
[i
];
1578 if (s
->vdev
.v4l2_dev
== NULL
|| s
->buffers
== 0)
1580 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s
->name
, s
->s_flags
,
1581 (s
->buffers
- s
->q_free
.buffers
) * 100 / s
->buffers
,
1582 (s
->buffers
* s
->buf_size
) / 1024, s
->buffers
);
1585 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n",
1586 (long long)itv
->mpg_data_received
,
1587 (long long)itv
->vbi_data_inserted
);
1591 static int ivtv_decoder_cmd(struct file
*file
, void *fh
, struct v4l2_decoder_cmd
*dec
)
1593 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
1594 struct ivtv
*itv
= id
->itv
;
1596 IVTV_DEBUG_IOCTL("VIDIOC_DECODER_CMD %d\n", dec
->cmd
);
1597 return ivtv_video_command(itv
, id
, dec
, false);
1600 static int ivtv_try_decoder_cmd(struct file
*file
, void *fh
, struct v4l2_decoder_cmd
*dec
)
1602 struct ivtv_open_id
*id
= fh2id(file
->private_data
);
1603 struct ivtv
*itv
= id
->itv
;
1605 IVTV_DEBUG_IOCTL("VIDIOC_TRY_DECODER_CMD %d\n", dec
->cmd
);
1606 return ivtv_video_command(itv
, id
, dec
, true);
1609 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1610 static __inline__
void warn_deprecated_ioctl(const char *name
)
1612 pr_warn_once("warning: the %s ioctl is deprecated. Don't use it, as it will be removed soon\n",
1616 #ifdef CONFIG_COMPAT
1617 struct compat_video_event
{
1619 /* unused, make sure to use atomic time for y2038 if it ever gets used */
1620 compat_long_t timestamp
;
1623 unsigned int frame_rate
; /* in frames per 1000sec */
1624 unsigned char vsync_field
; /* unknown/odd/even/progressive */
1627 #define VIDEO_GET_EVENT32 _IOR('o', 28, struct compat_video_event)
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 #ifdef CONFIG_COMPAT
1753 case VIDEO_GET_EVENT32
:
1755 case VIDEO_GET_EVENT
: {
1756 #ifdef CONFIG_COMPAT
1757 struct compat_video_event
*ev32
= arg
;
1759 struct video_event
*ev
= arg
;
1762 warn_deprecated_ioctl("VIDEO_GET_EVENT");
1763 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1765 memset(ev
, 0, sizeof(*ev
));
1766 set_bit(IVTV_F_I_EV_VSYNC_ENABLED
, &itv
->i_flags
);
1769 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED
, &itv
->i_flags
))
1770 ev
->type
= VIDEO_EVENT_DECODER_STOPPED
;
1771 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC
, &itv
->i_flags
)) {
1772 unsigned char vsync_field
;
1774 ev
->type
= VIDEO_EVENT_VSYNC
;
1775 vsync_field
= test_bit(IVTV_F_I_EV_VSYNC_FIELD
, &itv
->i_flags
) ?
1776 VIDEO_VSYNC_FIELD_ODD
: VIDEO_VSYNC_FIELD_EVEN
;
1777 if (itv
->output_mode
== OUT_UDMA_YUV
&&
1778 (itv
->yuv_info
.lace_mode
& IVTV_YUV_MODE_MASK
) ==
1779 IVTV_YUV_MODE_PROGRESSIVE
) {
1780 vsync_field
= VIDEO_VSYNC_FIELD_PROGRESSIVE
;
1782 #ifdef CONFIG_COMPAT
1783 if (cmd
== VIDEO_GET_EVENT32
)
1784 ev32
->u
.vsync_field
= vsync_field
;
1787 ev
->u
.vsync_field
= vsync_field
;
1793 /* Wait for event. Note that serialize_lock is locked,
1794 so to allow other processes to access the driver while
1795 we are waiting unlock first and later lock again. */
1796 mutex_unlock(&itv
->serialize_lock
);
1797 prepare_to_wait(&itv
->event_waitq
, &wait
, TASK_INTERRUPTIBLE
);
1798 if (!test_bit(IVTV_F_I_EV_DEC_STOPPED
, &itv
->i_flags
) &&
1799 !test_bit(IVTV_F_I_EV_VSYNC
, &itv
->i_flags
))
1801 finish_wait(&itv
->event_waitq
, &wait
);
1802 mutex_lock(&itv
->serialize_lock
);
1803 if (signal_pending(current
)) {
1804 /* return if a signal was received */
1805 IVTV_DEBUG_INFO("User stopped wait for event\n");
1812 case VIDEO_SELECT_SOURCE
:
1813 warn_deprecated_ioctl("VIDEO_SELECT_SOURCE");
1814 if (!(itv
->v4l2_cap
& V4L2_CAP_VIDEO_OUTPUT
))
1816 return ivtv_passthrough_mode(itv
, iarg
== VIDEO_SOURCE_DEMUX
);
1818 case AUDIO_SET_MUTE
:
1819 warn_deprecated_ioctl("AUDIO_SET_MUTE");
1820 itv
->speed_mute_audio
= iarg
;
1823 case AUDIO_CHANNEL_SELECT
:
1824 warn_deprecated_ioctl("AUDIO_CHANNEL_SELECT");
1825 if (iarg
> AUDIO_STEREO_SWAPPED
)
1827 return v4l2_ctrl_s_ctrl(itv
->ctrl_audio_playback
, iarg
+ 1);
1829 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1830 warn_deprecated_ioctl("AUDIO_BILINGUAL_CHANNEL_SELECT");
1831 if (iarg
> AUDIO_STEREO_SWAPPED
)
1833 return v4l2_ctrl_s_ctrl(itv
->ctrl_audio_multilingual_playback
, iarg
+ 1);
1841 static long ivtv_default(struct file
*file
, void *fh
, bool valid_prio
,
1842 unsigned int cmd
, void *arg
)
1844 struct ivtv
*itv
= fh2id(fh
)->itv
;
1848 case IVTV_IOC_PASSTHROUGH_MODE
:
1849 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1853 case VIDEO_CONTINUE
:
1855 case VIDEO_SELECT_SOURCE
:
1856 case AUDIO_SET_MUTE
:
1857 case AUDIO_CHANNEL_SELECT
:
1858 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1865 case VIDIOC_INT_RESET
: {
1866 u32 val
= *(u32
*)arg
;
1868 if ((val
== 0 && itv
->options
.newi2c
) || (val
& 0x01))
1869 ivtv_reset_ir_gpio(itv
);
1871 v4l2_subdev_call(itv
->sd_video
, core
, reset
, 0);
1875 case IVTV_IOC_DMA_FRAME
:
1876 case IVTV_IOC_PASSTHROUGH_MODE
:
1877 #ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1879 case VIDEO_GET_FRAME_COUNT
:
1880 case VIDEO_GET_EVENT
:
1884 case VIDEO_CONTINUE
:
1886 case VIDEO_TRY_COMMAND
:
1887 case VIDEO_SELECT_SOURCE
:
1888 case AUDIO_SET_MUTE
:
1889 case AUDIO_CHANNEL_SELECT
:
1890 case AUDIO_BILINGUAL_CHANNEL_SELECT
:
1892 return ivtv_decoder_ioctls(file
, cmd
, (void *)arg
);
1900 static const struct v4l2_ioctl_ops ivtv_ioctl_ops
= {
1901 .vidioc_querycap
= ivtv_querycap
,
1902 .vidioc_s_audio
= ivtv_s_audio
,
1903 .vidioc_g_audio
= ivtv_g_audio
,
1904 .vidioc_enumaudio
= ivtv_enumaudio
,
1905 .vidioc_s_audout
= ivtv_s_audout
,
1906 .vidioc_g_audout
= ivtv_g_audout
,
1907 .vidioc_enum_input
= ivtv_enum_input
,
1908 .vidioc_enum_output
= ivtv_enum_output
,
1909 .vidioc_enumaudout
= ivtv_enumaudout
,
1910 .vidioc_g_pixelaspect
= ivtv_g_pixelaspect
,
1911 .vidioc_s_selection
= ivtv_s_selection
,
1912 .vidioc_g_selection
= ivtv_g_selection
,
1913 .vidioc_g_input
= ivtv_g_input
,
1914 .vidioc_s_input
= ivtv_s_input
,
1915 .vidioc_g_output
= ivtv_g_output
,
1916 .vidioc_s_output
= ivtv_s_output
,
1917 .vidioc_g_frequency
= ivtv_g_frequency
,
1918 .vidioc_s_frequency
= ivtv_s_frequency
,
1919 .vidioc_s_tuner
= ivtv_s_tuner
,
1920 .vidioc_g_tuner
= ivtv_g_tuner
,
1921 .vidioc_g_enc_index
= ivtv_g_enc_index
,
1922 .vidioc_g_fbuf
= ivtv_g_fbuf
,
1923 .vidioc_s_fbuf
= ivtv_s_fbuf
,
1924 .vidioc_g_std
= ivtv_g_std
,
1925 .vidioc_s_std
= ivtv_s_std
,
1926 .vidioc_overlay
= ivtv_overlay
,
1927 .vidioc_log_status
= ivtv_log_status
,
1928 .vidioc_enum_fmt_vid_cap
= ivtv_enum_fmt_vid_cap
,
1929 .vidioc_encoder_cmd
= ivtv_encoder_cmd
,
1930 .vidioc_try_encoder_cmd
= ivtv_try_encoder_cmd
,
1931 .vidioc_decoder_cmd
= ivtv_decoder_cmd
,
1932 .vidioc_try_decoder_cmd
= ivtv_try_decoder_cmd
,
1933 .vidioc_enum_fmt_vid_out
= ivtv_enum_fmt_vid_out
,
1934 .vidioc_g_fmt_vid_cap
= ivtv_g_fmt_vid_cap
,
1935 .vidioc_g_fmt_vbi_cap
= ivtv_g_fmt_vbi_cap
,
1936 .vidioc_g_fmt_sliced_vbi_cap
= ivtv_g_fmt_sliced_vbi_cap
,
1937 .vidioc_g_fmt_vid_out
= ivtv_g_fmt_vid_out
,
1938 .vidioc_g_fmt_vid_out_overlay
= ivtv_g_fmt_vid_out_overlay
,
1939 .vidioc_g_fmt_sliced_vbi_out
= ivtv_g_fmt_sliced_vbi_out
,
1940 .vidioc_s_fmt_vid_cap
= ivtv_s_fmt_vid_cap
,
1941 .vidioc_s_fmt_vbi_cap
= ivtv_s_fmt_vbi_cap
,
1942 .vidioc_s_fmt_sliced_vbi_cap
= ivtv_s_fmt_sliced_vbi_cap
,
1943 .vidioc_s_fmt_vid_out
= ivtv_s_fmt_vid_out
,
1944 .vidioc_s_fmt_vid_out_overlay
= ivtv_s_fmt_vid_out_overlay
,
1945 .vidioc_s_fmt_sliced_vbi_out
= ivtv_s_fmt_sliced_vbi_out
,
1946 .vidioc_try_fmt_vid_cap
= ivtv_try_fmt_vid_cap
,
1947 .vidioc_try_fmt_vbi_cap
= ivtv_try_fmt_vbi_cap
,
1948 .vidioc_try_fmt_sliced_vbi_cap
= ivtv_try_fmt_sliced_vbi_cap
,
1949 .vidioc_try_fmt_vid_out
= ivtv_try_fmt_vid_out
,
1950 .vidioc_try_fmt_vid_out_overlay
= ivtv_try_fmt_vid_out_overlay
,
1951 .vidioc_try_fmt_sliced_vbi_out
= ivtv_try_fmt_sliced_vbi_out
,
1952 .vidioc_g_sliced_vbi_cap
= ivtv_g_sliced_vbi_cap
,
1953 #ifdef CONFIG_VIDEO_ADV_DEBUG
1954 .vidioc_g_register
= ivtv_g_register
,
1955 .vidioc_s_register
= ivtv_s_register
,
1957 .vidioc_default
= ivtv_default
,
1958 .vidioc_subscribe_event
= ivtv_subscribe_event
,
1959 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
1962 void ivtv_set_funcs(struct video_device
*vdev
)
1964 vdev
->ioctl_ops
= &ivtv_ioctl_ops
;