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-audio.h"
29 #include "ivtv-video.h"
30 #include "ivtv-streams.h"
32 #include "ivtv-ioctl.h"
33 #include "ivtv-gpio.h"
34 #include "ivtv-controls.h"
35 #include "ivtv-cards.h"
36 #include <media/saa7127.h>
37 #include <media/tveeprom.h>
38 #include <media/v4l2-chip-ident.h>
39 #include <linux/dvb/audio.h>
40 #include <linux/i2c-id.h>
42 u16 service2vbi(int type)
45 case V4L2_SLICED_TELETEXT_B:
46 return IVTV_SLICED_TYPE_TELETEXT_B;
47 case V4L2_SLICED_CAPTION_525:
48 return IVTV_SLICED_TYPE_CAPTION_525;
49 case V4L2_SLICED_WSS_625:
50 return IVTV_SLICED_TYPE_WSS_625;
52 return IVTV_SLICED_TYPE_VPS;
58 static int valid_service_line(int field, int line, int is_pal)
60 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
61 (!is_pal && line >= 10 && line < 22);
64 static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
66 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
69 set = set & valid_set;
70 if (set == 0 || !valid_service_line(field, line, is_pal)) {
74 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
75 return V4L2_SLICED_CAPTION_525;
78 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
79 return V4L2_SLICED_VPS;
80 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
81 return V4L2_SLICED_WSS_625;
85 for (i = 0; i < 32; i++) {
92 void expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
94 u16 set = fmt->service_set;
98 for (f = 0; f < 2; f++) {
99 for (l = 0; l < 24; l++) {
100 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
105 static int 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);
113 set |= fmt->service_lines[f][l];
119 u16 get_service_set(struct v4l2_sliced_vbi_format *fmt)
124 for (f = 0; f < 2; f++) {
125 for (l = 0; l < 24; l++) {
126 set |= fmt->service_lines[f][l];
132 static const struct {
136 { V4L2_STD_PAL_BG | V4L2_STD_PAL_H, "PAL-BGH" },
137 { V4L2_STD_PAL_DK, "PAL-DK" },
138 { V4L2_STD_PAL_I, "PAL-I" },
139 { V4L2_STD_PAL_M, "PAL-M" },
140 { V4L2_STD_PAL_N, "PAL-N" },
141 { V4L2_STD_PAL_Nc, "PAL-Nc" },
142 { V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H, "SECAM-BGH" },
143 { V4L2_STD_SECAM_DK, "SECAM-DK" },
144 { V4L2_STD_SECAM_L, "SECAM-L" },
145 { V4L2_STD_SECAM_LC, "SECAM-L'" },
146 { V4L2_STD_NTSC_M, "NTSC-M" },
147 { V4L2_STD_NTSC_M_JP, "NTSC-J" },
148 { V4L2_STD_NTSC_M_KR, "NTSC-K" },
151 static const struct v4l2_standard ivtv_std_60hz =
153 .frameperiod = {.numerator = 1001, .denominator = 30000},
157 static const struct v4l2_standard ivtv_std_50hz =
159 .frameperiod = {.numerator = 1, .denominator = 25},
163 void ivtv_set_osd_alpha(struct ivtv *itv)
165 ivtv_vapi(itv, CX2341X_OSD_SET_GLOBAL_ALPHA, 3,
166 itv->osd_global_alpha_state, itv->osd_global_alpha, !itv->osd_local_alpha_state);
167 ivtv_vapi(itv, CX2341X_OSD_SET_CHROMA_KEY, 2, itv->osd_color_key_state, itv->osd_color_key);
170 int ivtv_set_speed(struct ivtv *itv, int speed)
172 u32 data[CX2341X_MBOX_MAX_DATA];
173 struct ivtv_stream *s;
174 int single_step = (speed == 1 || speed == -1);
177 if (speed == 0) speed = 1000;
180 if (speed == itv->speed && !single_step)
183 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
185 if (single_step && (speed < 0) == (itv->speed < 0)) {
186 /* Single step video and no need to change direction */
187 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
192 /* Need to change direction */
193 speed = speed < 0 ? -1000 : 1000;
195 data[0] = (speed > 1000 || speed < -1000) ? 0x80000000 : 0;
196 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
197 data[1] = (speed < 0);
198 data[2] = speed < 0 ? 3 : 7;
199 data[3] = itv->params.video_b_frames;
200 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0;
204 if (speed == 1500 || speed == -1500) data[0] |= 1;
205 else if (speed == 2000 || speed == -2000) data[0] |= 2;
206 else if (speed > -1000 && speed < 0) data[0] |= (-1000 / speed);
207 else if (speed < 1000 && speed > 0) data[0] |= (1000 / speed);
209 /* If not decoding, just change speed setting */
210 if (atomic_read(&itv->decoding) > 0) {
213 /* Stop all DMA and decoding activity */
214 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1, 0);
216 /* Wait for any DMA to finish */
217 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
218 while (itv->i_flags & IVTV_F_I_DMA) {
219 got_sig = signal_pending(current);
225 finish_wait(&itv->dma_waitq, &wait);
229 /* Change Speed safely */
230 ivtv_api(itv, CX2341X_DEC_SET_PLAYBACK_SPEED, 7, data);
231 IVTV_DEBUG_INFO("Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
232 data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
235 speed = (speed < 0) ? -1 : 1;
236 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
242 static int ivtv_validate_speed(int cur_speed, int new_speed)
244 int fact = new_speed < 0 ? -1 : 1;
247 if (new_speed < 0) new_speed = -new_speed;
248 if (cur_speed < 0) cur_speed = -cur_speed;
250 if (cur_speed <= new_speed) {
251 if (new_speed > 1500) return fact * 2000;
252 if (new_speed > 1000) return fact * 1500;
255 if (new_speed >= 2000) return fact * 2000;
256 if (new_speed >= 1500) return fact * 1500;
257 if (new_speed >= 1000) return fact * 1000;
259 if (new_speed == 0) return 1000;
260 if (new_speed == 1 || new_speed == 1000) return fact * new_speed;
263 new_speed = 1000 / new_speed;
264 if (1000 / cur_speed == new_speed)
265 new_speed += (cur_speed < s) ? -1 : 1;
266 if (new_speed > 60) return 1000 / (fact * 60);
267 return 1000 / (fact * new_speed);
270 static int ivtv_video_command(struct ivtv *itv, struct ivtv_open_id *id,
271 struct video_command *vc, int try)
273 struct ivtv_stream *s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
275 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
279 case VIDEO_CMD_PLAY: {
281 vc->play.speed = ivtv_validate_speed(itv->speed, vc->play.speed);
282 if (vc->play.speed < 0)
283 vc->play.format = VIDEO_PLAY_FMT_GOP;
286 if (ivtv_set_output_mode(itv, OUT_MPG) != OUT_MPG)
288 return ivtv_start_decoding(id, vc->play.speed);
292 vc->flags &= VIDEO_CMD_STOP_IMMEDIATELY|VIDEO_CMD_STOP_TO_BLACK;
293 if (vc->flags & VIDEO_CMD_STOP_IMMEDIATELY)
296 if (atomic_read(&itv->decoding) == 0)
298 if (itv->output_mode != OUT_MPG)
301 itv->output_mode = OUT_NONE;
302 return ivtv_stop_v4l2_decode_stream(s, vc->flags, vc->stop.pts);
304 case VIDEO_CMD_FREEZE:
305 vc->flags &= VIDEO_CMD_FREEZE_TO_BLACK;
307 if (itv->output_mode != OUT_MPG)
309 if (atomic_read(&itv->decoding) > 0) {
310 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1,
311 (vc->flags & VIDEO_CMD_FREEZE_TO_BLACK) ? 1 : 0);
315 case VIDEO_CMD_CONTINUE:
318 if (itv->output_mode != OUT_MPG)
320 if (atomic_read(&itv->decoding) > 0) {
321 ivtv_vapi(itv, CX2341X_DEC_START_PLAYBACK, 2, 0, 0);
331 static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg)
333 struct v4l2_register *regs = arg;
335 volatile u8 __iomem *reg_start;
337 if (!capable(CAP_SYS_ADMIN))
339 if (regs->reg >= IVTV_REG_OFFSET && regs->reg < IVTV_REG_OFFSET + IVTV_REG_SIZE)
340 reg_start = itv->reg_mem - IVTV_REG_OFFSET;
341 else if (itv->has_cx23415 && regs->reg >= IVTV_DECODER_OFFSET &&
342 regs->reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE)
343 reg_start = itv->dec_mem - IVTV_DECODER_OFFSET;
344 else if (regs->reg >= 0 && regs->reg < IVTV_ENCODER_SIZE)
345 reg_start = itv->enc_mem;
349 spin_lock_irqsave(&ivtv_cards_lock, flags);
350 if (cmd == VIDIOC_DBG_G_REGISTER) {
351 regs->val = readl(regs->reg + reg_start);
353 writel(regs->val, regs->reg + reg_start);
355 spin_unlock_irqrestore(&ivtv_cards_lock, flags);
359 static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fmt)
362 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
363 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
365 fmt->fmt.pix.width = itv->main_rect.width;
366 fmt->fmt.pix.height = itv->main_rect.height;
367 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
368 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
369 if (itv->output_mode == OUT_UDMA_YUV) {
370 switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) {
371 case IVTV_YUV_MODE_INTERLACED:
372 fmt->fmt.pix.field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ?
373 V4L2_FIELD_INTERLACED_BT : V4L2_FIELD_INTERLACED_TB;
375 case IVTV_YUV_MODE_PROGRESSIVE:
376 fmt->fmt.pix.field = V4L2_FIELD_NONE;
379 fmt->fmt.pix.field = V4L2_FIELD_ANY;
382 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
383 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
384 fmt->fmt.pix.sizeimage =
385 fmt->fmt.pix.height * fmt->fmt.pix.width +
386 fmt->fmt.pix.height * (fmt->fmt.pix.width / 2);
388 else if (itv->output_mode == OUT_YUV ||
389 streamtype == IVTV_ENC_STREAM_TYPE_YUV ||
390 streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
391 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
392 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
393 fmt->fmt.pix.sizeimage =
394 fmt->fmt.pix.height * fmt->fmt.pix.width +
395 fmt->fmt.pix.height * (fmt->fmt.pix.width / 2);
397 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
398 fmt->fmt.pix.sizeimage = 128 * 1024;
402 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
403 fmt->fmt.pix.width = itv->params.width;
404 fmt->fmt.pix.height = itv->params.height;
405 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
406 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
407 if (streamtype == IVTV_ENC_STREAM_TYPE_YUV ||
408 streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
409 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_HM12;
410 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
411 fmt->fmt.pix.sizeimage =
412 fmt->fmt.pix.height * fmt->fmt.pix.width +
413 fmt->fmt.pix.height * (fmt->fmt.pix.width / 2);
415 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
416 fmt->fmt.pix.sizeimage = 128 * 1024;
420 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
421 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
423 fmt->fmt.win.chromakey = itv->osd_color_key;
424 fmt->fmt.win.global_alpha = itv->osd_global_alpha;
427 case V4L2_BUF_TYPE_VBI_CAPTURE:
428 fmt->fmt.vbi.sampling_rate = 27000000;
429 fmt->fmt.vbi.offset = 248;
430 fmt->fmt.vbi.samples_per_line = itv->vbi.raw_decoder_line_size - 4;
431 fmt->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
432 fmt->fmt.vbi.start[0] = itv->vbi.start[0];
433 fmt->fmt.vbi.start[1] = itv->vbi.start[1];
434 fmt->fmt.vbi.count[0] = fmt->fmt.vbi.count[1] = itv->vbi.count;
437 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
439 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
441 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
443 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
444 memset(vbifmt->reserved, 0, sizeof(vbifmt->reserved));
445 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
447 vbifmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
448 vbifmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
450 vbifmt->service_lines[0][23] = V4L2_SLICED_WSS_625;
451 vbifmt->service_lines[0][16] = V4L2_SLICED_VPS;
453 vbifmt->service_set = get_service_set(vbifmt);
457 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
459 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
461 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
462 memset(vbifmt->reserved, 0, sizeof(vbifmt->reserved));
463 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
465 if (streamtype == IVTV_DEC_STREAM_TYPE_VBI) {
466 vbifmt->service_set = itv->is_50hz ? V4L2_SLICED_VBI_625 :
468 expand_service_set(vbifmt, itv->is_50hz);
472 itv->video_dec_func(itv, VIDIOC_G_FMT, fmt);
473 vbifmt->service_set = get_service_set(vbifmt);
476 case V4L2_BUF_TYPE_VBI_OUTPUT:
477 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
484 static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
485 struct v4l2_format *fmt, int set_fmt)
487 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
490 if (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
494 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
496 field = fmt->fmt.pix.field;
499 r.width = fmt->fmt.pix.width;
500 r.height = fmt->fmt.pix.height;
501 ivtv_get_fmt(itv, streamtype, fmt);
502 if (itv->output_mode != OUT_UDMA_YUV) {
503 /* TODO: would setting the rect also be valid for this mode? */
504 fmt->fmt.pix.width = r.width;
505 fmt->fmt.pix.height = r.height;
507 if (itv->output_mode == OUT_UDMA_YUV) {
508 /* TODO: add checks for validity */
509 fmt->fmt.pix.field = field;
512 if (itv->output_mode == OUT_UDMA_YUV) {
514 case V4L2_FIELD_NONE:
515 itv->yuv_info.lace_mode = IVTV_YUV_MODE_PROGRESSIVE;
518 itv->yuv_info.lace_mode = IVTV_YUV_MODE_AUTO;
520 case V4L2_FIELD_INTERLACED_BT:
521 itv->yuv_info.lace_mode =
522 IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD;
524 case V4L2_FIELD_INTERLACED_TB:
526 itv->yuv_info.lace_mode = IVTV_YUV_MODE_INTERLACED;
529 itv->yuv_info.lace_sync_field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1;
531 /* Force update of yuv registers */
532 itv->yuv_info.yuv_forced_update = 1;
535 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
536 r.width, r.height, r.left, r.top))
544 if (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY) {
545 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
548 itv->osd_color_key = fmt->fmt.win.chromakey;
549 itv->osd_global_alpha = fmt->fmt.win.global_alpha;
550 ivtv_set_osd_alpha(itv);
555 /* set window size */
556 if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
557 int w = fmt->fmt.pix.width;
558 int h = fmt->fmt.pix.height;
560 if (w > 720) w = 720;
561 else if (w < 1) w = 1;
562 if (h > (itv->is_50hz ? 576 : 480)) h = (itv->is_50hz ? 576 : 480);
563 else if (h < 2) h = 2;
564 ivtv_get_fmt(itv, streamtype, fmt);
565 fmt->fmt.pix.width = w;
566 fmt->fmt.pix.height = h;
568 if (!set_fmt || (itv->params.width == w && itv->params.height == h))
570 if (atomic_read(&itv->capturing) > 0)
573 itv->params.width = w;
574 itv->params.height = h;
575 if (w != 720 || h != (itv->is_50hz ? 576 : 480))
576 itv->params.video_temporal_filter = 0;
578 itv->params.video_temporal_filter = 8;
579 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
580 return ivtv_get_fmt(itv, streamtype, fmt);
583 /* set raw VBI format */
584 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
585 if (set_fmt && streamtype == IVTV_ENC_STREAM_TYPE_VBI &&
586 itv->vbi.sliced_in->service_set &&
587 atomic_read(&itv->capturing) > 0) {
591 itv->vbi.sliced_in->service_set = 0;
592 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in);
594 return ivtv_get_fmt(itv, streamtype, fmt);
597 /* set sliced VBI output
598 In principle the user could request that only certain
599 VBI types are output and that the others are ignored.
600 I.e., suppress CC in the even fields or only output
601 WSS and no VPS. Currently though there is no choice. */
602 if (fmt->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
603 return ivtv_get_fmt(itv, streamtype, fmt);
605 /* any else but sliced VBI capture is an error */
606 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
609 if (streamtype == IVTV_DEC_STREAM_TYPE_VBI)
610 return ivtv_get_fmt(itv, streamtype, fmt);
612 /* set sliced VBI capture format */
613 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
614 memset(vbifmt->reserved, 0, sizeof(vbifmt->reserved));
616 if (vbifmt->service_set)
617 expand_service_set(vbifmt, itv->is_50hz);
618 set = check_service_set(vbifmt, itv->is_50hz);
619 vbifmt->service_set = get_service_set(vbifmt);
625 if (atomic_read(&itv->capturing) > 0 && itv->vbi.sliced_in->service_set == 0) {
628 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
629 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
633 static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
635 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
636 struct ivtv *itv = id->itv;
637 struct v4l2_register *reg = arg;
640 /* ioctls to allow direct access to the encoder registers for testing */
641 case VIDIOC_DBG_G_REGISTER:
642 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
643 return ivtv_itvc(itv, cmd, arg);
644 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
645 return ivtv_i2c_id(itv, reg->match_chip, cmd, arg);
646 return ivtv_call_i2c_client(itv, reg->match_chip, cmd, arg);
648 case VIDIOC_DBG_S_REGISTER:
649 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
650 return ivtv_itvc(itv, cmd, arg);
651 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
652 return ivtv_i2c_id(itv, reg->match_chip, cmd, arg);
653 return ivtv_call_i2c_client(itv, reg->match_chip, cmd, arg);
655 case VIDIOC_G_CHIP_IDENT: {
656 struct v4l2_chip_ident *chip = arg;
658 chip->ident = V4L2_IDENT_NONE;
660 if (reg->match_type == V4L2_CHIP_MATCH_HOST) {
661 if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) {
662 struct v4l2_chip_ident *chip = arg;
664 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416;
668 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
669 return ivtv_i2c_id(itv, reg->match_chip, cmd, arg);
670 if (reg->match_type == V4L2_CHIP_MATCH_I2C_ADDR)
671 return ivtv_call_i2c_client(itv, reg->match_chip, cmd, arg);
675 case VIDIOC_INT_S_AUDIO_ROUTING: {
676 struct v4l2_routing *route = arg;
678 ivtv_audio_set_route(itv, route);
682 case VIDIOC_INT_RESET:
683 ivtv_reset_ir_gpio(itv);
692 int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg)
694 struct ivtv_open_id *id = NULL;
696 if (filp) id = (struct ivtv_open_id *)filp->private_data;
699 case VIDIOC_G_PRIORITY:
701 enum v4l2_priority *p = arg;
703 *p = v4l2_prio_max(&itv->prio);
707 case VIDIOC_S_PRIORITY:
709 enum v4l2_priority *prio = arg;
711 return v4l2_prio_change(&itv->prio, &id->prio, *prio);
714 case VIDIOC_QUERYCAP:{
715 struct v4l2_capability *vcap = arg;
717 memset(vcap, 0, sizeof(*vcap));
718 strcpy(vcap->driver, IVTV_DRIVER_NAME); /* driver name */
719 strcpy(vcap->card, itv->card_name); /* card type */
720 strcpy(vcap->bus_info, pci_name(itv->dev)); /* bus info... */
721 vcap->version = IVTV_DRIVER_VERSION; /* version */
722 vcap->capabilities = itv->v4l2_cap; /* capabilities */
724 /* reserved.. must set to 0! */
725 vcap->reserved[0] = vcap->reserved[1] =
726 vcap->reserved[2] = vcap->reserved[3] = 0;
730 case VIDIOC_ENUMAUDIO:{
731 struct v4l2_audio *vin = arg;
733 return ivtv_get_audio_input(itv, vin->index, vin);
736 case VIDIOC_G_AUDIO:{
737 struct v4l2_audio *vin = arg;
739 vin->index = itv->audio_input;
740 return ivtv_get_audio_input(itv, vin->index, vin);
743 case VIDIOC_S_AUDIO:{
744 struct v4l2_audio *vout = arg;
746 if (vout->index >= itv->nof_audio_inputs)
748 itv->audio_input = vout->index;
749 ivtv_audio_set_io(itv);
753 case VIDIOC_ENUMAUDOUT:{
754 struct v4l2_audioout *vin = arg;
756 /* set it to defaults from our table */
757 return ivtv_get_audio_output(itv, vin->index, vin);
760 case VIDIOC_G_AUDOUT:{
761 struct v4l2_audioout *vin = arg;
764 return ivtv_get_audio_output(itv, vin->index, vin);
767 case VIDIOC_S_AUDOUT:{
768 struct v4l2_audioout *vout = arg;
770 return ivtv_get_audio_output(itv, vout->index, vout);
773 case VIDIOC_ENUMINPUT:{
774 struct v4l2_input *vin = arg;
776 /* set it to defaults from our table */
777 return ivtv_get_input(itv, vin->index, vin);
780 case VIDIOC_ENUMOUTPUT:{
781 struct v4l2_output *vout = arg;
783 return ivtv_get_output(itv, vout->index, vout);
788 struct v4l2_format *fmt = arg;
790 return ivtv_try_or_set_fmt(itv, id->type, fmt, cmd == VIDIOC_S_FMT);
794 struct v4l2_format *fmt = arg;
795 int type = fmt->type;
797 memset(fmt, 0, sizeof(*fmt));
799 return ivtv_get_fmt(itv, id->type, fmt);
802 case VIDIOC_S_CROP: {
803 struct v4l2_crop *crop = arg;
805 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
807 return itv->video_dec_func(itv, VIDIOC_S_CROP, arg);
810 case VIDIOC_G_CROP: {
811 struct v4l2_crop *crop = arg;
813 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
815 return itv->video_dec_func(itv, VIDIOC_G_CROP, arg);
818 case VIDIOC_ENUM_FMT: {
819 static struct v4l2_fmtdesc formats[] = {
821 "HM12 (YUV 4:1:1)", V4L2_PIX_FMT_HM12,
824 { 1, 0, V4L2_FMT_FLAG_COMPRESSED,
825 "MPEG", V4L2_PIX_FMT_MPEG,
829 struct v4l2_fmtdesc *fmt = arg;
830 enum v4l2_buf_type type = fmt->type;
833 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
835 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
836 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
844 *fmt = formats[fmt->index];
849 case VIDIOC_G_INPUT:{
850 *(int *)arg = itv->active_input;
854 case VIDIOC_S_INPUT:{
855 int inp = *(int *)arg;
857 if (inp < 0 || inp >= itv->nof_inputs)
860 if (inp == itv->active_input) {
861 IVTV_DEBUG_INFO("Input unchanged\n");
864 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
865 itv->active_input, inp);
867 itv->active_input = inp;
868 /* Set the audio input to whatever is appropriate for the
870 itv->audio_input = itv->card->video_inputs[inp].audio_index;
872 /* prevent others from messing with the streams until
873 we're finished changing inputs. */
875 ivtv_video_set_io(itv);
876 ivtv_audio_set_io(itv);
881 case VIDIOC_G_OUTPUT:{
882 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
884 *(int *)arg = itv->active_output;
888 case VIDIOC_S_OUTPUT:{
889 int outp = *(int *)arg;
890 struct v4l2_routing route;
892 if (outp >= itv->card->nof_outputs)
895 if (outp == itv->active_output) {
896 IVTV_DEBUG_INFO("Output unchanged\n");
899 IVTV_DEBUG_INFO("Changing output from %d to %d\n",
900 itv->active_output, outp);
902 itv->active_output = outp;
903 route.input = SAA7127_INPUT_TYPE_NORMAL;
904 route.output = itv->card->video_outputs[outp].video_output;
905 ivtv_saa7127(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
909 case VIDIOC_G_FREQUENCY:{
910 struct v4l2_frequency *vf = arg;
914 ivtv_call_i2c_clients(itv, cmd, arg);
918 case VIDIOC_S_FREQUENCY:{
919 struct v4l2_frequency vf = *(struct v4l2_frequency *)arg;
925 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf.frequency);
926 ivtv_call_i2c_clients(itv, cmd, &vf);
931 case VIDIOC_ENUMSTD:{
932 struct v4l2_standard *vs = arg;
935 if (idx < 0 || idx >= ARRAY_SIZE(enum_stds))
938 *vs = (enum_stds[idx].std & V4L2_STD_525_60) ?
939 ivtv_std_60hz : ivtv_std_50hz;
941 vs->id = enum_stds[idx].std;
942 strcpy(vs->name, enum_stds[idx].name);
947 *(v4l2_std_id *) arg = itv->std;
952 v4l2_std_id std = *(v4l2_std_id *) arg;
954 if ((std & V4L2_STD_ALL) == 0)
960 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
961 atomic_read(&itv->capturing) > 0 ||
962 atomic_read(&itv->decoding) > 0) {
963 /* Switching standard would turn off the radio or mess
964 with already running streams, prevent that by
970 itv->is_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
971 itv->params.is_50hz = itv->is_50hz = !itv->is_60hz;
972 itv->params.width = 720;
973 itv->params.height = itv->is_50hz ? 576 : 480;
974 itv->vbi.count = itv->is_50hz ? 18 : 12;
975 itv->vbi.start[0] = itv->is_50hz ? 6 : 10;
976 itv->vbi.start[1] = itv->is_50hz ? 318 : 273;
977 if (itv->hw_flags & IVTV_HW_CX25840) {
978 itv->vbi.sliced_decoder_line_size = itv->is_60hz ? 272 : 284;
980 IVTV_DEBUG_INFO("Switching standard to %llx.\n", itv->std);
983 ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std);
985 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
986 /* set display standard */
988 itv->is_out_60hz = itv->is_60hz;
989 itv->is_out_50hz = itv->is_50hz;
990 ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std_out);
991 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
992 itv->main_rect.left = itv->main_rect.top = 0;
993 itv->main_rect.width = 720;
994 itv->main_rect.height = itv->params.height;
995 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
996 720, itv->main_rect.height, 0, 0);
1001 case VIDIOC_S_TUNER: { /* Setting tuner can only set audio mode */
1002 struct v4l2_tuner *vt = arg;
1007 ivtv_call_i2c_clients(itv, VIDIOC_S_TUNER, vt);
1011 case VIDIOC_G_TUNER: {
1012 struct v4l2_tuner *vt = arg;
1017 memset(vt, 0, sizeof(*vt));
1018 ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, vt);
1020 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
1021 strcpy(vt->name, "ivtv Radio Tuner");
1022 vt->type = V4L2_TUNER_RADIO;
1024 strcpy(vt->name, "ivtv TV Tuner");
1025 vt->type = V4L2_TUNER_ANALOG_TV;
1030 case VIDIOC_G_SLICED_VBI_CAP: {
1031 struct v4l2_sliced_vbi_cap *cap = arg;
1032 int set = itv->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
1034 enum v4l2_buf_type type = cap->type;
1036 memset(cap, 0, sizeof(*cap));
1038 if (type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
1039 for (f = 0; f < 2; f++) {
1040 for (l = 0; l < 24; l++) {
1041 if (valid_service_line(f, l, itv->is_50hz)) {
1042 cap->service_lines[f][l] = set;
1048 if (type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
1049 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
1052 cap->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
1053 cap->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
1055 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
1056 cap->service_lines[0][16] = V4L2_SLICED_VPS;
1063 case VIDIOC_G_ENC_INDEX: {
1064 struct v4l2_enc_idx *idx = arg;
1067 idx->entries = (itv->pgm_info_write_idx + IVTV_MAX_PGM_INDEX - itv->pgm_info_read_idx) %
1069 if (idx->entries > V4L2_ENC_IDX_ENTRIES)
1070 idx->entries = V4L2_ENC_IDX_ENTRIES;
1071 for (i = 0; i < idx->entries; i++) {
1072 idx->entry[i] = itv->pgm_info[(itv->pgm_info_read_idx + i) % IVTV_MAX_PGM_INDEX];
1074 itv->pgm_info_read_idx = (itv->pgm_info_read_idx + idx->entries) % IVTV_MAX_PGM_INDEX;
1078 case VIDIOC_ENCODER_CMD:
1079 case VIDIOC_TRY_ENCODER_CMD: {
1080 struct v4l2_encoder_cmd *enc = arg;
1081 int try = cmd == VIDIOC_TRY_ENCODER_CMD;
1083 memset(&enc->raw, 0, sizeof(enc->raw));
1085 case V4L2_ENC_CMD_START:
1089 return ivtv_start_capture(id);
1091 case V4L2_ENC_CMD_STOP:
1092 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1095 ivtv_stop_capture(id, enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
1098 case V4L2_ENC_CMD_PAUSE:
1102 if (!atomic_read(&itv->capturing))
1104 if (test_and_set_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1107 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 0);
1110 case V4L2_ENC_CMD_RESUME:
1114 if (!atomic_read(&itv->capturing))
1116 if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1118 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1);
1127 case VIDIOC_G_FBUF: {
1128 struct v4l2_framebuffer *fb = arg;
1130 memset(fb, 0, sizeof(*fb));
1131 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1133 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY |
1134 V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_GLOBAL_ALPHA;
1135 fb->fmt.pixelformat = itv->osd_pixelformat;
1136 fb->fmt.width = itv->osd_rect.width;
1137 fb->fmt.height = itv->osd_rect.height;
1138 fb->base = (void *)itv->osd_video_pbase;
1139 if (itv->osd_global_alpha_state)
1140 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
1141 if (itv->osd_local_alpha_state)
1142 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1143 if (itv->osd_color_key_state)
1144 fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
1148 case VIDIOC_S_FBUF: {
1149 struct v4l2_framebuffer *fb = arg;
1151 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1153 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0;
1154 itv->osd_local_alpha_state = (fb->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) != 0;
1155 itv->osd_color_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
1159 case VIDIOC_LOG_STATUS:
1161 int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT;
1162 struct v4l2_input vidin;
1163 struct v4l2_audio audin;
1166 IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num);
1167 if (itv->hw_flags & IVTV_HW_TVEEPROM) {
1170 ivtv_read_eeprom(itv, &tv);
1172 ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL);
1173 ivtv_get_input(itv, itv->active_input, &vidin);
1174 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1175 IVTV_INFO("Video Input: %s\n", vidin.name);
1176 IVTV_INFO("Audio Input: %s\n", audin.name);
1178 struct v4l2_output vidout;
1179 struct v4l2_audioout audout;
1180 int mode = itv->output_mode;
1181 static const char * const output_modes[] = {
1189 ivtv_get_output(itv, itv->active_output, &vidout);
1190 ivtv_get_audio_output(itv, 0, &audout);
1191 IVTV_INFO("Video Output: %s\n", vidout.name);
1192 IVTV_INFO("Audio Output: %s\n", audout.name);
1193 if (mode < 0 || mode > OUT_PASSTHROUGH)
1195 IVTV_INFO("Output Mode: %s\n", output_modes[mode]);
1197 IVTV_INFO("Tuner: %s\n",
1198 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1199 cx2341x_log_status(&itv->params, itv->name);
1200 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1201 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1202 struct ivtv_stream *s = &itv->streams[i];
1204 if (s->v4l2dev == NULL || s->buffers == 0)
1206 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags,
1207 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
1208 (s->buffers * s->buf_size) / 1024, s->buffers);
1210 IVTV_INFO("Read MPEG/VBI: %lld/%lld bytes\n", itv->mpg_data_received, itv->vbi_data_inserted);
1211 IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num);
1221 static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1223 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1224 struct ivtv *itv = id->itv;
1225 int nonblocking = filp->f_flags & O_NONBLOCK;
1226 struct ivtv_stream *s = &itv->streams[id->type];
1229 case IVTV_IOC_DMA_FRAME: {
1230 struct ivtv_dma_frame *args = arg;
1232 IVTV_DEBUG_IOCTL("IVTV_IOC_DMA_FRAME\n");
1233 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1235 if (args->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1237 if (itv->output_mode == OUT_UDMA_YUV && args->y_source == NULL)
1239 if (ivtv_claim_stream(id, id->type)) {
1242 if (ivtv_set_output_mode(itv, OUT_UDMA_YUV) != OUT_UDMA_YUV) {
1243 ivtv_release_stream(s);
1246 if (args->y_source == NULL)
1248 return ivtv_yuv_prep_frame(itv, args);
1251 case VIDEO_GET_PTS: {
1252 u32 data[CX2341X_MBOX_MAX_DATA];
1255 IVTV_DEBUG_IOCTL("VIDEO_GET_PTS\n");
1256 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1260 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1263 if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
1264 *pts = (u64) ((u64)itv->last_dec_timing[2] << 32) |
1265 (u64)itv->last_dec_timing[1];
1269 if (atomic_read(&itv->decoding)) {
1270 if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
1271 IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
1274 memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
1275 set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
1276 *pts = (u64) ((u64) data[2] << 32) | (u64) data[1];
1277 /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
1282 case VIDEO_GET_FRAME_COUNT: {
1283 u32 data[CX2341X_MBOX_MAX_DATA];
1286 IVTV_DEBUG_IOCTL("VIDEO_GET_FRAME_COUNT\n");
1287 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1291 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1294 if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
1295 *frame = itv->last_dec_timing[0];
1299 if (atomic_read(&itv->decoding)) {
1300 if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
1301 IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
1304 memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
1305 set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
1312 struct video_command vc;
1314 IVTV_DEBUG_IOCTL("VIDEO_PLAY\n");
1315 memset(&vc, 0, sizeof(vc));
1316 vc.cmd = VIDEO_CMD_PLAY;
1317 return ivtv_video_command(itv, id, &vc, 0);
1321 struct video_command vc;
1323 IVTV_DEBUG_IOCTL("VIDEO_STOP\n");
1324 memset(&vc, 0, sizeof(vc));
1325 vc.cmd = VIDEO_CMD_STOP;
1326 vc.flags = VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY;
1327 return ivtv_video_command(itv, id, &vc, 0);
1330 case VIDEO_FREEZE: {
1331 struct video_command vc;
1333 IVTV_DEBUG_IOCTL("VIDEO_FREEZE\n");
1334 memset(&vc, 0, sizeof(vc));
1335 vc.cmd = VIDEO_CMD_FREEZE;
1336 return ivtv_video_command(itv, id, &vc, 0);
1339 case VIDEO_CONTINUE: {
1340 struct video_command vc;
1342 IVTV_DEBUG_IOCTL("VIDEO_CONTINUE\n");
1343 memset(&vc, 0, sizeof(vc));
1344 vc.cmd = VIDEO_CMD_CONTINUE;
1345 return ivtv_video_command(itv, id, &vc, 0);
1349 case VIDEO_TRY_COMMAND: {
1350 struct video_command *vc = arg;
1351 int try = (cmd == VIDEO_TRY_COMMAND);
1354 IVTV_DEBUG_IOCTL("VIDEO_TRY_COMMAND\n");
1356 IVTV_DEBUG_IOCTL("VIDEO_COMMAND\n");
1357 return ivtv_video_command(itv, id, vc, try);
1360 case VIDEO_GET_EVENT: {
1361 struct video_event *ev = arg;
1364 IVTV_DEBUG_IOCTL("VIDEO_GET_EVENT\n");
1365 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1367 memset(ev, 0, sizeof(*ev));
1368 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
1371 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
1372 ev->type = VIDEO_EVENT_DECODER_STOPPED;
1373 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags)) {
1374 ev->type = VIDEO_EVENT_VSYNC;
1375 ev->u.vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ?
1376 VIDEO_VSYNC_FIELD_ODD : VIDEO_VSYNC_FIELD_EVEN;
1377 if (itv->output_mode == OUT_UDMA_YUV &&
1378 (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) ==
1379 IVTV_YUV_MODE_PROGRESSIVE) {
1380 ev->u.vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE;
1387 /* wait for event */
1388 prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE);
1389 if ((itv->i_flags & (IVTV_F_I_EV_DEC_STOPPED|IVTV_F_I_EV_VSYNC)) == 0)
1391 finish_wait(&itv->event_waitq, &wait);
1392 if (signal_pending(current)) {
1393 /* return if a signal was received */
1394 IVTV_DEBUG_INFO("User stopped wait for event\n");
1407 static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1408 unsigned int cmd, void *arg)
1410 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1411 struct ivtv *itv = id->itv;
1414 /* check priority */
1418 case VIDIOC_S_INPUT:
1419 case VIDIOC_S_OUTPUT:
1420 case VIDIOC_S_TUNER:
1421 case VIDIOC_S_FREQUENCY:
1424 case VIDIOC_S_AUDIO:
1425 case VIDIOC_S_AUDOUT:
1426 case VIDIOC_S_EXT_CTRLS:
1428 ret = v4l2_prio_check(&itv->prio, &id->prio);
1434 case VIDIOC_DBG_G_REGISTER:
1435 case VIDIOC_DBG_S_REGISTER:
1436 case VIDIOC_G_CHIP_IDENT:
1437 case VIDIOC_INT_S_AUDIO_ROUTING:
1438 case VIDIOC_INT_RESET:
1439 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1440 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1441 v4l_printk_ioctl(cmd);
1443 return ivtv_debug_ioctls(filp, cmd, arg);
1445 case VIDIOC_G_PRIORITY:
1446 case VIDIOC_S_PRIORITY:
1447 case VIDIOC_QUERYCAP:
1448 case VIDIOC_ENUMINPUT:
1449 case VIDIOC_G_INPUT:
1450 case VIDIOC_S_INPUT:
1451 case VIDIOC_ENUMOUTPUT:
1452 case VIDIOC_G_OUTPUT:
1453 case VIDIOC_S_OUTPUT:
1456 case VIDIOC_TRY_FMT:
1457 case VIDIOC_ENUM_FMT:
1460 case VIDIOC_G_FREQUENCY:
1461 case VIDIOC_S_FREQUENCY:
1462 case VIDIOC_ENUMSTD:
1465 case VIDIOC_S_TUNER:
1466 case VIDIOC_G_TUNER:
1467 case VIDIOC_ENUMAUDIO:
1468 case VIDIOC_S_AUDIO:
1469 case VIDIOC_G_AUDIO:
1470 case VIDIOC_ENUMAUDOUT:
1471 case VIDIOC_S_AUDOUT:
1472 case VIDIOC_G_AUDOUT:
1473 case VIDIOC_G_SLICED_VBI_CAP:
1474 case VIDIOC_LOG_STATUS:
1475 case VIDIOC_G_ENC_INDEX:
1476 case VIDIOC_ENCODER_CMD:
1477 case VIDIOC_TRY_ENCODER_CMD:
1480 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1481 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1482 v4l_printk_ioctl(cmd);
1484 return ivtv_v4l2_ioctls(itv, filp, cmd, arg);
1486 case VIDIOC_QUERYMENU:
1487 case VIDIOC_QUERYCTRL:
1490 case VIDIOC_S_EXT_CTRLS:
1491 case VIDIOC_G_EXT_CTRLS:
1492 case VIDIOC_TRY_EXT_CTRLS:
1493 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1494 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1495 v4l_printk_ioctl(cmd);
1497 return ivtv_control_ioctls(itv, cmd, arg);
1499 case IVTV_IOC_DMA_FRAME:
1501 case VIDEO_GET_FRAME_COUNT:
1502 case VIDEO_GET_EVENT:
1506 case VIDEO_CONTINUE:
1508 case VIDEO_TRY_COMMAND:
1509 return ivtv_decoder_ioctls(filp, cmd, arg);
1511 case 0x00005401: /* Handle isatty() calls */
1514 return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
1515 ivtv_v4l2_do_ioctl);
1520 int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1523 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1524 struct ivtv *itv = id->itv;
1526 /* Filter dvb ioctls that cannot be handled by video_usercopy */
1528 case VIDEO_SELECT_SOURCE:
1529 IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
1530 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1532 return ivtv_passthrough_mode(itv, arg == VIDEO_SOURCE_DEMUX);
1534 case AUDIO_SET_MUTE:
1535 IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
1536 itv->speed_mute_audio = arg;
1539 case AUDIO_CHANNEL_SELECT:
1540 IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
1541 if (arg > AUDIO_STEREO_SWAPPED)
1543 itv->audio_stereo_mode = arg;
1544 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
1547 case AUDIO_BILINGUAL_CHANNEL_SELECT:
1548 IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
1549 if (arg > AUDIO_STEREO_SWAPPED)
1551 itv->audio_bilingual_mode = arg;
1552 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
1558 return video_usercopy(inode, filp, cmd, arg, ivtv_v4l2_do_ioctl);