Merge tag 'csky-for-linus-4.20-fixup-dtb' of https://github.com/c-sky/csky-linux
[linux-block.git] / drivers / media / pci / ivtv / ivtv-ioctl.c
CommitLineData
1a0adaf3
HV
1/*
2 ioctl system call
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
5
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.
10
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.
15
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
19 */
20
21#include "ivtv-driver.h"
22#include "ivtv-version.h"
23#include "ivtv-mailbox.h"
24#include "ivtv-i2c.h"
25#include "ivtv-queue.h"
26#include "ivtv-fileops.h"
27#include "ivtv-vbi.h"
33c0fcad 28#include "ivtv-routing.h"
1a0adaf3
HV
29#include "ivtv-streams.h"
30#include "ivtv-yuv.h"
31#include "ivtv-ioctl.h"
32#include "ivtv-gpio.h"
33#include "ivtv-controls.h"
34#include "ivtv-cards.h"
b5dcee22 35#include <media/i2c/saa7127.h>
1a0adaf3 36#include <media/tveeprom.h>
09250193 37#include <media/v4l2-event.h>
66896380 38#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
04b72322 39#include <linux/compat.h>
1a0adaf3 40#include <linux/dvb/audio.h>
66896380
MCC
41#include <linux/dvb/video.h>
42#endif
1a0adaf3 43
feb5bce2 44u16 ivtv_service2vbi(int type)
1a0adaf3
HV
45{
46 switch (type) {
47 case V4L2_SLICED_TELETEXT_B:
48 return IVTV_SLICED_TYPE_TELETEXT_B;
49 case V4L2_SLICED_CAPTION_525:
50 return IVTV_SLICED_TYPE_CAPTION_525;
51 case V4L2_SLICED_WSS_625:
52 return IVTV_SLICED_TYPE_WSS_625;
53 case V4L2_SLICED_VPS:
54 return IVTV_SLICED_TYPE_VPS;
55 default:
56 return 0;
57 }
58}
59
60static int valid_service_line(int field, int line, int is_pal)
61{
62 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
63 (!is_pal && line >= 10 && line < 22);
64}
65
66static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
67{
68 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
69 int i;
70
71 set = set & valid_set;
72 if (set == 0 || !valid_service_line(field, line, is_pal)) {
73 return 0;
74 }
75 if (!is_pal) {
76 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
77 return V4L2_SLICED_CAPTION_525;
78 }
79 else {
80 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
81 return V4L2_SLICED_VPS;
82 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
83 return V4L2_SLICED_WSS_625;
84 if (line == 23)
85 return 0;
86 }
87 for (i = 0; i < 32; i++) {
88 if ((1 << i) & set)
89 return 1 << i;
90 }
91 return 0;
92}
93
feb5bce2 94void ivtv_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
1a0adaf3
HV
95{
96 u16 set = fmt->service_set;
97 int f, l;
98
99 fmt->service_set = 0;
100 for (f = 0; f < 2; f++) {
101 for (l = 0; l < 24; l++) {
102 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
103 }
104 }
105}
106
854ad9ab 107static void check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
1a0adaf3
HV
108{
109 int f, l;
1a0adaf3
HV
110
111 for (f = 0; f < 2; f++) {
112 for (l = 0; l < 24; l++) {
113 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
1a0adaf3
HV
114 }
115 }
1a0adaf3
HV
116}
117
feb5bce2 118u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt)
1a0adaf3
HV
119{
120 int f, l;
121 u16 set = 0;
122
123 for (f = 0; f < 2; f++) {
124 for (l = 0; l < 24; l++) {
125 set |= fmt->service_lines[f][l];
126 }
127 }
128 return set;
129}
130
1a0adaf3
HV
131void ivtv_set_osd_alpha(struct ivtv *itv)
132{
133 ivtv_vapi(itv, CX2341X_OSD_SET_GLOBAL_ALPHA, 3,
134 itv->osd_global_alpha_state, itv->osd_global_alpha, !itv->osd_local_alpha_state);
fd8b281a 135 ivtv_vapi(itv, CX2341X_OSD_SET_CHROMA_KEY, 2, itv->osd_chroma_key_state, itv->osd_chroma_key);
1a0adaf3
HV
136}
137
138int ivtv_set_speed(struct ivtv *itv, int speed)
139{
140 u32 data[CX2341X_MBOX_MAX_DATA];
1a0adaf3
HV
141 int single_step = (speed == 1 || speed == -1);
142 DEFINE_WAIT(wait);
143
144 if (speed == 0) speed = 1000;
145
146 /* No change? */
147 if (speed == itv->speed && !single_step)
148 return 0;
149
1a0adaf3
HV
150 if (single_step && (speed < 0) == (itv->speed < 0)) {
151 /* Single step video and no need to change direction */
152 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
153 itv->speed = speed;
154 return 0;
155 }
156 if (single_step)
157 /* Need to change direction */
158 speed = speed < 0 ? -1000 : 1000;
159
160 data[0] = (speed > 1000 || speed < -1000) ? 0x80000000 : 0;
161 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
162 data[1] = (speed < 0);
163 data[2] = speed < 0 ? 3 : 7;
f7b80e69 164 data[3] = v4l2_ctrl_g_ctrl(itv->cxhdl.video_b_frames);
1a0adaf3
HV
165 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0;
166 data[5] = 0;
167 data[6] = 0;
168
169 if (speed == 1500 || speed == -1500) data[0] |= 1;
170 else if (speed == 2000 || speed == -2000) data[0] |= 2;
171 else if (speed > -1000 && speed < 0) data[0] |= (-1000 / speed);
172 else if (speed < 1000 && speed > 0) data[0] |= (1000 / speed);
173
174 /* If not decoding, just change speed setting */
175 if (atomic_read(&itv->decoding) > 0) {
176 int got_sig = 0;
177
178 /* Stop all DMA and decoding activity */
179 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1, 0);
180
181 /* Wait for any DMA to finish */
cdc03781 182 mutex_unlock(&itv->serialize_lock);
1a0adaf3 183 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
ec105a42 184 while (test_bit(IVTV_F_I_DMA, &itv->i_flags)) {
1a0adaf3
HV
185 got_sig = signal_pending(current);
186 if (got_sig)
187 break;
188 got_sig = 0;
189 schedule();
190 }
191 finish_wait(&itv->dma_waitq, &wait);
cdc03781 192 mutex_lock(&itv->serialize_lock);
1a0adaf3
HV
193 if (got_sig)
194 return -EINTR;
195
196 /* Change Speed safely */
197 ivtv_api(itv, CX2341X_DEC_SET_PLAYBACK_SPEED, 7, data);
198 IVTV_DEBUG_INFO("Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
199 data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
200 }
201 if (single_step) {
202 speed = (speed < 0) ? -1 : 1;
203 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
204 }
205 itv->speed = speed;
206 return 0;
207}
208
209static int ivtv_validate_speed(int cur_speed, int new_speed)
210{
211 int fact = new_speed < 0 ? -1 : 1;
212 int s;
213
94dee760
HV
214 if (cur_speed == 0)
215 cur_speed = 1000;
216 if (new_speed < 0)
217 new_speed = -new_speed;
218 if (cur_speed < 0)
219 cur_speed = -cur_speed;
1a0adaf3
HV
220
221 if (cur_speed <= new_speed) {
94dee760
HV
222 if (new_speed > 1500)
223 return fact * 2000;
224 if (new_speed > 1000)
225 return fact * 1500;
1a0adaf3
HV
226 }
227 else {
94dee760
HV
228 if (new_speed >= 2000)
229 return fact * 2000;
230 if (new_speed >= 1500)
231 return fact * 1500;
232 if (new_speed >= 1000)
233 return fact * 1000;
1a0adaf3 234 }
94dee760
HV
235 if (new_speed == 0)
236 return 1000;
237 if (new_speed == 1 || new_speed == 1000)
238 return fact * new_speed;
1a0adaf3
HV
239
240 s = new_speed;
241 new_speed = 1000 / new_speed;
242 if (1000 / cur_speed == new_speed)
243 new_speed += (cur_speed < s) ? -1 : 1;
244 if (new_speed > 60) return 1000 / (fact * 60);
245 return 1000 / (fact * new_speed);
246}
247
248static int ivtv_video_command(struct ivtv *itv, struct ivtv_open_id *id,
da8ec560 249 struct v4l2_decoder_cmd *dc, int try)
1a0adaf3
HV
250{
251 struct ivtv_stream *s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
252
253 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
254 return -EINVAL;
255
da8ec560
HV
256 switch (dc->cmd) {
257 case V4L2_DEC_CMD_START: {
258 dc->flags &= V4L2_DEC_CMD_START_MUTE_AUDIO;
259 dc->start.speed = ivtv_validate_speed(itv->speed, dc->start.speed);
260 if (dc->start.speed < 0)
261 dc->start.format = V4L2_DEC_START_FMT_GOP;
262 else
263 dc->start.format = V4L2_DEC_START_FMT_NONE;
264 if (dc->start.speed != 500 && dc->start.speed != 1500)
265 dc->flags = dc->start.speed == 1000 ? 0 :
266 V4L2_DEC_CMD_START_MUTE_AUDIO;
1a0adaf3
HV
267 if (try) break;
268
da8ec560 269 itv->speed_mute_audio = dc->flags & V4L2_DEC_CMD_START_MUTE_AUDIO;
1a0adaf3
HV
270 if (ivtv_set_output_mode(itv, OUT_MPG) != OUT_MPG)
271 return -EBUSY;
ac425144
HV
272 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags)) {
273 /* forces ivtv_set_speed to be called */
274 itv->speed = 0;
275 }
da8ec560 276 return ivtv_start_decoding(id, dc->start.speed);
1a0adaf3
HV
277 }
278
da8ec560
HV
279 case V4L2_DEC_CMD_STOP:
280 dc->flags &= V4L2_DEC_CMD_STOP_IMMEDIATELY | V4L2_DEC_CMD_STOP_TO_BLACK;
281 if (dc->flags & V4L2_DEC_CMD_STOP_IMMEDIATELY)
282 dc->stop.pts = 0;
1a0adaf3
HV
283 if (try) break;
284 if (atomic_read(&itv->decoding) == 0)
285 return 0;
286 if (itv->output_mode != OUT_MPG)
287 return -EBUSY;
288
289 itv->output_mode = OUT_NONE;
da8ec560 290 return ivtv_stop_v4l2_decode_stream(s, dc->flags, dc->stop.pts);
1a0adaf3 291
da8ec560
HV
292 case V4L2_DEC_CMD_PAUSE:
293 dc->flags &= V4L2_DEC_CMD_PAUSE_TO_BLACK;
1a0adaf3 294 if (try) break;
1a806401
HV
295 if (!atomic_read(&itv->decoding))
296 return -EPERM;
1a0adaf3
HV
297 if (itv->output_mode != OUT_MPG)
298 return -EBUSY;
299 if (atomic_read(&itv->decoding) > 0) {
300 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1,
da8ec560 301 (dc->flags & V4L2_DEC_CMD_PAUSE_TO_BLACK) ? 1 : 0);
ac425144 302 set_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags);
1a0adaf3
HV
303 }
304 break;
305
da8ec560
HV
306 case V4L2_DEC_CMD_RESUME:
307 dc->flags = 0;
1a0adaf3 308 if (try) break;
1a806401
HV
309 if (!atomic_read(&itv->decoding))
310 return -EPERM;
1a0adaf3
HV
311 if (itv->output_mode != OUT_MPG)
312 return -EBUSY;
ac425144
HV
313 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags)) {
314 int speed = itv->speed;
315 itv->speed = 0;
316 return ivtv_start_decoding(id, speed);
1a0adaf3
HV
317 }
318 break;
319
320 default:
321 return -EINVAL;
322 }
323 return 0;
324}
325
3f038d80 326static int ivtv_g_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
1a0adaf3 327{
2f82441a 328 struct ivtv *itv = fh2id(fh)->itv;
3f038d80 329 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
1a0adaf3 330
e88360c0
HV
331 vbifmt->reserved[0] = 0;
332 vbifmt->reserved[1] = 0;
3f038d80
HV
333 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
334 return -EINVAL;
335 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
30634e8e 336 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
3f038d80
HV
337 if (itv->is_60hz) {
338 vbifmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
339 vbifmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
340 } else {
341 vbifmt->service_lines[0][23] = V4L2_SLICED_WSS_625;
342 vbifmt->service_lines[0][16] = V4L2_SLICED_VPS;
1a0adaf3 343 }
3f038d80
HV
344 vbifmt->service_set = ivtv_get_service_set(vbifmt);
345 return 0;
346}
1a0adaf3 347
3f038d80
HV
348static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
349{
2f82441a 350 struct ivtv_open_id *id = fh2id(fh);
3f038d80 351 struct ivtv *itv = id->itv;
e88360c0
HV
352 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
353
f7b80e69
HV
354 pixfmt->width = itv->cxhdl.width;
355 pixfmt->height = itv->cxhdl.height;
e88360c0
HV
356 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
357 pixfmt->field = V4L2_FIELD_INTERLACED;
e88360c0
HV
358 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
359 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
a4a78718
HV
360 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
361 pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
e88360c0 362 pixfmt->bytesperline = 720;
3f038d80 363 } else {
e88360c0
HV
364 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
365 pixfmt->sizeimage = 128 * 1024;
366 pixfmt->bytesperline = 0;
1a0adaf3
HV
367 }
368 return 0;
369}
370
3f038d80 371static int ivtv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
1a0adaf3 372{
2f82441a 373 struct ivtv *itv = fh2id(fh)->itv;
e88360c0
HV
374 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
375
376 vbifmt->sampling_rate = 27000000;
377 vbifmt->offset = 248;
378 vbifmt->samples_per_line = itv->vbi.raw_decoder_line_size - 4;
379 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
380 vbifmt->start[0] = itv->vbi.start[0];
381 vbifmt->start[1] = itv->vbi.start[1];
382 vbifmt->count[0] = vbifmt->count[1] = itv->vbi.count;
383 vbifmt->flags = 0;
384 vbifmt->reserved[0] = 0;
385 vbifmt->reserved[1] = 0;
3f038d80
HV
386 return 0;
387}
1a0adaf3 388
3f038d80
HV
389static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
390{
391 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
2f82441a 392 struct ivtv_open_id *id = fh2id(fh);
3f038d80 393 struct ivtv *itv = id->itv;
1a0adaf3 394
e88360c0
HV
395 vbifmt->reserved[0] = 0;
396 vbifmt->reserved[1] = 0;
3f038d80 397 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
1a0adaf3 398
3f038d80
HV
399 if (id->type == IVTV_DEC_STREAM_TYPE_VBI) {
400 vbifmt->service_set = itv->is_50hz ? V4L2_SLICED_VBI_625 :
401 V4L2_SLICED_VBI_525;
402 ivtv_expand_service_set(vbifmt, itv->is_50hz);
c5c46f26 403 vbifmt->service_set = ivtv_get_service_set(vbifmt);
3f038d80
HV
404 return 0;
405 }
77aded6b 406
4ff0790b 407 v4l2_subdev_call(itv->sd_video, vbi, g_sliced_fmt, vbifmt);
3f038d80
HV
408 vbifmt->service_set = ivtv_get_service_set(vbifmt);
409 return 0;
410}
77aded6b 411
3f038d80
HV
412static int ivtv_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
413{
2f82441a 414 struct ivtv_open_id *id = fh2id(fh);
3f038d80 415 struct ivtv *itv = id->itv;
e88360c0 416 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
77aded6b 417
3f038d80
HV
418 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
419 return -EINVAL;
e88360c0
HV
420 pixfmt->width = itv->main_rect.width;
421 pixfmt->height = itv->main_rect.height;
422 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
423 pixfmt->field = V4L2_FIELD_INTERLACED;
3f038d80
HV
424 if (id->type == IVTV_DEC_STREAM_TYPE_YUV) {
425 switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) {
426 case IVTV_YUV_MODE_INTERLACED:
e88360c0 427 pixfmt->field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ?
3f038d80
HV
428 V4L2_FIELD_INTERLACED_BT : V4L2_FIELD_INTERLACED_TB;
429 break;
430 case IVTV_YUV_MODE_PROGRESSIVE:
e88360c0 431 pixfmt->field = V4L2_FIELD_NONE;
3f038d80
HV
432 break;
433 default:
e88360c0 434 pixfmt->field = V4L2_FIELD_ANY;
3f038d80 435 break;
1a0adaf3 436 }
e88360c0
HV
437 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
438 pixfmt->bytesperline = 720;
439 pixfmt->width = itv->yuv_info.v4l2_src_w;
440 pixfmt->height = itv->yuv_info.v4l2_src_h;
3f038d80 441 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
e88360c0
HV
442 pixfmt->sizeimage =
443 1080 * ((pixfmt->height + 31) & ~31);
3f038d80 444 } else {
e88360c0
HV
445 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
446 pixfmt->sizeimage = 128 * 1024;
447 pixfmt->bytesperline = 0;
1a0adaf3 448 }
3f038d80
HV
449 return 0;
450}
1a0adaf3 451
3f038d80
HV
452static int ivtv_g_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
453{
2f82441a 454 struct ivtv *itv = fh2id(fh)->itv;
38a1421d 455 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
e88360c0 456 struct v4l2_window *winfmt = &fmt->fmt.win;
1a0adaf3 457
38a1421d
HV
458 if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
459 return -EINVAL;
460 if (!itv->osd_video_pbase)
3f038d80 461 return -EINVAL;
e88360c0
HV
462 winfmt->chromakey = itv->osd_chroma_key;
463 winfmt->global_alpha = itv->osd_global_alpha;
464 winfmt->field = V4L2_FIELD_INTERLACED;
465 winfmt->clips = NULL;
466 winfmt->clipcount = 0;
467 winfmt->bitmap = NULL;
468 winfmt->w.top = winfmt->w.left = 0;
469 winfmt->w.width = itv->osd_rect.width;
470 winfmt->w.height = itv->osd_rect.height;
3f038d80
HV
471 return 0;
472}
1a0adaf3 473
3f038d80
HV
474static int ivtv_try_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
475{
476 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
477}
1a0adaf3 478
3f038d80
HV
479static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
480{
2f82441a 481 struct ivtv_open_id *id = fh2id(fh);
3f038d80
HV
482 struct ivtv *itv = id->itv;
483 int w = fmt->fmt.pix.width;
484 int h = fmt->fmt.pix.height;
a4a78718 485 int min_h = 2;
3f038d80
HV
486
487 w = min(w, 720);
854ad9ab 488 w = max(w, 2);
a4a78718
HV
489 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
490 /* YUV height must be a multiple of 32 */
491 h &= ~0x1f;
492 min_h = 32;
493 }
3f038d80 494 h = min(h, itv->is_50hz ? 576 : 480);
a4a78718 495 h = max(h, min_h);
3f038d80
HV
496 ivtv_g_fmt_vid_cap(file, fh, fmt);
497 fmt->fmt.pix.width = w;
498 fmt->fmt.pix.height = h;
499 return 0;
500}
1a0adaf3 501
3f038d80
HV
502static int ivtv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
503{
504 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
505}
1a0adaf3 506
3f038d80
HV
507static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
508{
509 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
2f82441a 510 struct ivtv_open_id *id = fh2id(fh);
3f038d80 511 struct ivtv *itv = id->itv;
1a0adaf3 512
3f038d80
HV
513 if (id->type == IVTV_DEC_STREAM_TYPE_VBI)
514 return ivtv_g_fmt_sliced_vbi_cap(file, fh, fmt);
1a0adaf3
HV
515
516 /* set sliced VBI capture format */
517 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
e88360c0
HV
518 vbifmt->reserved[0] = 0;
519 vbifmt->reserved[1] = 0;
1a0adaf3
HV
520
521 if (vbifmt->service_set)
feb5bce2 522 ivtv_expand_service_set(vbifmt, itv->is_50hz);
3f038d80 523 check_service_set(vbifmt, itv->is_50hz);
feb5bce2 524 vbifmt->service_set = ivtv_get_service_set(vbifmt);
3f038d80
HV
525 return 0;
526}
527
528static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
529{
2f82441a 530 struct ivtv_open_id *id = fh2id(fh);
effc3466
HV
531 s32 w = fmt->fmt.pix.width;
532 s32 h = fmt->fmt.pix.height;
533 int field = fmt->fmt.pix.field;
534 int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
535
854ad9ab
HV
536 w = min(w, 720);
537 w = max(w, 2);
962d699e
HV
538 /* Why can the height be 576 even when the output is NTSC?
539
540 Internally the buffers of the PVR350 are always set to 720x576. The
541 decoded video frame will always be placed in the top left corner of
542 this buffer. For any video which is not 720x576, the buffer will
543 then be cropped to remove the unused right and lower areas, with
544 the remaining image being scaled by the hardware to fit the display
545 area. The video can be scaled both up and down, so a 720x480 video
546 can be displayed full-screen on PAL and a 720x576 video can be
547 displayed without cropping on NTSC.
548
549 Note that the scaling only occurs on the video stream, the osd
550 resolution is locked to the broadcast standard and not scaled.
551
552 Thanks to Ian Armstrong for this explanation. */
553 h = min(h, 576);
854ad9ab
HV
554 h = max(h, 2);
555 if (id->type == IVTV_DEC_STREAM_TYPE_YUV)
3f038d80 556 fmt->fmt.pix.field = field;
effc3466
HV
557 fmt->fmt.pix.width = w;
558 fmt->fmt.pix.height = h;
3f038d80
HV
559 return ret;
560}
561
562static int ivtv_try_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
563{
2f82441a 564 struct ivtv *itv = fh2id(fh)->itv;
38a1421d 565 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
e88360c0
HV
566 u32 chromakey = fmt->fmt.win.chromakey;
567 u8 global_alpha = fmt->fmt.win.global_alpha;
1a0adaf3 568
38a1421d
HV
569 if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
570 return -EINVAL;
571 if (!itv->osd_video_pbase)
3f038d80 572 return -EINVAL;
e88360c0
HV
573 ivtv_g_fmt_vid_out_overlay(file, fh, fmt);
574 fmt->fmt.win.chromakey = chromakey;
575 fmt->fmt.win.global_alpha = global_alpha;
3f038d80
HV
576 return 0;
577}
578
579static int ivtv_s_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
580{
581 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
582}
583
584static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
585{
2f82441a 586 struct ivtv_open_id *id = fh2id(fh);
3f038d80 587 struct ivtv *itv = id->itv;
ebf984bb
HV
588 struct v4l2_subdev_format format = {
589 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
590 };
effc3466 591 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
3f038d80
HV
592 int w = fmt->fmt.pix.width;
593 int h = fmt->fmt.pix.height;
3f038d80
HV
594
595 if (ret)
596 return ret;
597
f7b80e69 598 if (itv->cxhdl.width == w && itv->cxhdl.height == h)
1a0adaf3 599 return 0;
3f038d80
HV
600
601 if (atomic_read(&itv->capturing) > 0)
602 return -EBUSY;
603
f7b80e69
HV
604 itv->cxhdl.width = w;
605 itv->cxhdl.height = h;
606 if (v4l2_ctrl_g_ctrl(itv->cxhdl.video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
3f038d80 607 fmt->fmt.pix.width /= 2;
ebf984bb
HV
608 format.format.width = fmt->fmt.pix.width;
609 format.format.height = h;
610 format.format.code = MEDIA_BUS_FMT_FIXED;
611 v4l2_subdev_call(itv->sd_video, pad, set_fmt, NULL, &format);
3f038d80
HV
612 return ivtv_g_fmt_vid_cap(file, fh, fmt);
613}
614
615static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
616{
2f82441a 617 struct ivtv *itv = fh2id(fh)->itv;
3f038d80 618
a8b86435
HV
619 if (!ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
620 return -EBUSY;
3f038d80 621 itv->vbi.sliced_in->service_set = 0;
a8b86435 622 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
4ff0790b 623 v4l2_subdev_call(itv->sd_video, vbi, s_raw_fmt, &fmt->fmt.vbi);
3f038d80
HV
624 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
625}
626
627static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
628{
629 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
2f82441a 630 struct ivtv_open_id *id = fh2id(fh);
3f038d80
HV
631 struct ivtv *itv = id->itv;
632 int ret = ivtv_try_fmt_sliced_vbi_cap(file, fh, fmt);
633
634 if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI)
635 return ret;
636
854ad9ab 637 check_service_set(vbifmt, itv->is_50hz);
a8b86435 638 if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
1a0adaf3 639 return -EBUSY;
a8b86435 640 itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
4ff0790b 641 v4l2_subdev_call(itv->sd_video, vbi, s_sliced_fmt, vbifmt);
1a0adaf3
HV
642 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
643 return 0;
644}
645
3f038d80 646static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
1a0adaf3 647{
2f82441a 648 struct ivtv_open_id *id = fh2id(fh);
1a0adaf3 649 struct ivtv *itv = id->itv;
3f038d80
HV
650 struct yuv_playback_info *yi = &itv->yuv_info;
651 int ret = ivtv_try_fmt_vid_out(file, fh, fmt);
1a0adaf3 652
3f038d80
HV
653 if (ret)
654 return ret;
1a0adaf3 655
3f038d80
HV
656 if (id->type != IVTV_DEC_STREAM_TYPE_YUV)
657 return 0;
1a0adaf3 658
3f038d80
HV
659 /* Return now if we already have some frame data */
660 if (yi->stream_size)
661 return -EBUSY;
1a0adaf3 662
3f038d80
HV
663 yi->v4l2_src_w = fmt->fmt.pix.width;
664 yi->v4l2_src_h = fmt->fmt.pix.height;
2cc72095 665
3f038d80
HV
666 switch (fmt->fmt.pix.field) {
667 case V4L2_FIELD_NONE:
668 yi->lace_mode = IVTV_YUV_MODE_PROGRESSIVE;
1a0adaf3 669 break;
3f038d80
HV
670 case V4L2_FIELD_ANY:
671 yi->lace_mode = IVTV_YUV_MODE_AUTO;
672 break;
673 case V4L2_FIELD_INTERLACED_BT:
674 yi->lace_mode =
675 IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD;
676 break;
677 case V4L2_FIELD_INTERLACED_TB:
1a0adaf3 678 default:
3f038d80
HV
679 yi->lace_mode = IVTV_YUV_MODE_INTERLACED;
680 break;
1a0adaf3 681 }
3f038d80
HV
682 yi->lace_sync_field = (yi->lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1;
683
684 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
685 itv->dma_data_req_size =
686 1080 * ((yi->v4l2_src_h + 31) & ~31);
687
1a0adaf3
HV
688 return 0;
689}
690
3f038d80 691static int ivtv_s_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
1a0adaf3 692{
2f82441a 693 struct ivtv *itv = fh2id(fh)->itv;
3f038d80 694 int ret = ivtv_try_fmt_vid_out_overlay(file, fh, fmt);
1a0adaf3 695
3f038d80
HV
696 if (ret == 0) {
697 itv->osd_chroma_key = fmt->fmt.win.chromakey;
698 itv->osd_global_alpha = fmt->fmt.win.global_alpha;
699 ivtv_set_osd_alpha(itv);
77aded6b 700 }
3f038d80
HV
701 return ret;
702}
1a0adaf3 703
36ecd495 704#ifdef CONFIG_VIDEO_ADV_DEBUG
b5656e8b 705static int ivtv_itvc(struct ivtv *itv, bool get, u64 reg, u64 *val)
36ecd495 706{
adb65bc7 707 volatile u8 __iomem *reg_start;
36ecd495 708
e9dab589
HV
709 if (reg & 0x3)
710 return -EINVAL;
b5656e8b 711 if (reg >= IVTV_REG_OFFSET && reg < IVTV_REG_OFFSET + IVTV_REG_SIZE)
36ecd495 712 reg_start = itv->reg_mem - IVTV_REG_OFFSET;
b5656e8b
HV
713 else if (itv->has_cx23415 && reg >= IVTV_DECODER_OFFSET &&
714 reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE)
36ecd495 715 reg_start = itv->dec_mem - IVTV_DECODER_OFFSET;
b5656e8b 716 else if (reg < IVTV_ENCODER_SIZE)
36ecd495
HV
717 reg_start = itv->enc_mem;
718 else
719 return -EINVAL;
720
b5656e8b
HV
721 if (get)
722 *val = readl(reg + reg_start);
36ecd495 723 else
b5656e8b 724 writel(*val, reg + reg_start);
36ecd495
HV
725 return 0;
726}
727
aecde8b5 728static int ivtv_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
3f038d80 729{
2f82441a 730 struct ivtv *itv = fh2id(fh)->itv;
d46c17d7 731
4bd81936
HV
732 reg->size = 4;
733 return ivtv_itvc(itv, true, reg->reg, &reg->val);
3f038d80
HV
734}
735
977ba3b1 736static int ivtv_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg)
3f038d80 737{
2f82441a 738 struct ivtv *itv = fh2id(fh)->itv;
4bd81936 739 u64 val = reg->val;
d46c17d7 740
4bd81936 741 return ivtv_itvc(itv, false, reg->reg, &val);
3f038d80 742}
36ecd495 743#endif
1a0adaf3 744
3f038d80
HV
745static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vcap)
746{
d0c8b2d4
HV
747 struct ivtv_open_id *id = fh2id(file->private_data);
748 struct ivtv *itv = id->itv;
749 struct ivtv_stream *s = &itv->streams[id->type];
3f038d80 750
c0decac1
MCC
751 strscpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
752 strscpy(vcap->card, itv->card_name, sizeof(vcap->card));
8ac05ae3 753 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->pdev));
d0c8b2d4
HV
754 vcap->capabilities = itv->v4l2_cap | V4L2_CAP_DEVICE_CAPS;
755 vcap->device_caps = s->caps;
38a1421d
HV
756 if ((s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY) &&
757 !itv->osd_video_pbase) {
758 vcap->capabilities &= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
759 vcap->device_caps &= ~V4L2_CAP_VIDEO_OUTPUT_OVERLAY;
760 }
3f038d80
HV
761 return 0;
762}
1a0adaf3 763
3f038d80
HV
764static int ivtv_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
765{
2f82441a 766 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 767
3f038d80
HV
768 return ivtv_get_audio_input(itv, vin->index, vin);
769}
770
771static int ivtv_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
772{
2f82441a 773 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 774
3f038d80
HV
775 vin->index = itv->audio_input;
776 return ivtv_get_audio_input(itv, vin->index, vin);
777}
1a0adaf3 778
0e8025b9 779static int ivtv_s_audio(struct file *file, void *fh, const struct v4l2_audio *vout)
3f038d80 780{
2f82441a 781 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 782
3f038d80
HV
783 if (vout->index >= itv->nof_audio_inputs)
784 return -EINVAL;
1a0adaf3 785
3f038d80
HV
786 itv->audio_input = vout->index;
787 ivtv_audio_set_io(itv);
1a0adaf3 788
3f038d80
HV
789 return 0;
790}
1a0adaf3 791
3f038d80
HV
792static int ivtv_enumaudout(struct file *file, void *fh, struct v4l2_audioout *vin)
793{
2f82441a 794 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 795
3f038d80
HV
796 /* set it to defaults from our table */
797 return ivtv_get_audio_output(itv, vin->index, vin);
798}
1a0adaf3 799
3f038d80
HV
800static int ivtv_g_audout(struct file *file, void *fh, struct v4l2_audioout *vin)
801{
2f82441a 802 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 803
3f038d80
HV
804 vin->index = 0;
805 return ivtv_get_audio_output(itv, vin->index, vin);
806}
1a0adaf3 807
ba9425bc 808static int ivtv_s_audout(struct file *file, void *fh, const struct v4l2_audioout *vout)
3f038d80 809{
2f82441a 810 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 811
ba9425bc
HV
812 if (itv->card->video_outputs == NULL || vout->index != 0)
813 return -EINVAL;
814 return 0;
3f038d80 815}
1a0adaf3 816
3f038d80
HV
817static int ivtv_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
818{
2f82441a 819 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 820
3f038d80
HV
821 /* set it to defaults from our table */
822 return ivtv_get_input(itv, vin->index, vin);
823}
1a0adaf3 824
3f038d80
HV
825static int ivtv_enum_output(struct file *file, void *fh, struct v4l2_output *vout)
826{
2f82441a 827 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 828
3f038d80
HV
829 return ivtv_get_output(itv, vout->index, vout);
830}
987e00ba 831
3f038d80
HV
832static int ivtv_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
833{
2f82441a 834 struct ivtv_open_id *id = fh2id(fh);
3f038d80 835 struct ivtv *itv = id->itv;
3f038d80 836
3f038d80 837 if (cropcap->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
80954cbb
HV
838 cropcap->pixelaspect.numerator = itv->is_50hz ? 54 : 11;
839 cropcap->pixelaspect.denominator = itv->is_50hz ? 59 : 10;
bbc9fa2e 840 } else if (cropcap->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
80954cbb
HV
841 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 54 : 11;
842 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 59 : 10;
3f038d80 843 } else {
bbc9fa2e 844 return -EINVAL;
987e00ba 845 }
3f038d80
HV
846 return 0;
847}
848
bbc9fa2e
HV
849static int ivtv_s_selection(struct file *file, void *fh,
850 struct v4l2_selection *sel)
3f038d80 851{
2f82441a 852 struct ivtv_open_id *id = fh2id(fh);
3f038d80
HV
853 struct ivtv *itv = id->itv;
854 struct yuv_playback_info *yi = &itv->yuv_info;
bbc9fa2e
HV
855 struct v4l2_rect r = { 0, 0, 720, 0 };
856 int streamtype = id->type;
987e00ba 857
bbc9fa2e
HV
858 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
859 !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
860 return -EINVAL;
1a0adaf3 861
bbc9fa2e 862 if (sel->target != V4L2_SEL_TGT_COMPOSE)
c9aec06f 863 return -EINVAL;
bbc9fa2e
HV
864
865
866 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
867 !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
868 return -EINVAL;
869
870 r.height = itv->is_out_50hz ? 576 : 480;
871 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV && yi->track_osd) {
872 r.width = yi->osd_full_w;
873 r.height = yi->osd_full_h;
874 }
875 sel->r.width = clamp(sel->r.width, 16U, r.width);
876 sel->r.height = clamp(sel->r.height, 16U, r.height);
877 sel->r.left = clamp_t(unsigned, sel->r.left, 0, r.width - sel->r.width);
878 sel->r.top = clamp_t(unsigned, sel->r.top, 0, r.height - sel->r.height);
879
880 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
881 yi->main_rect = sel->r;
882 return 0;
883 }
884 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
885 sel->r.width, sel->r.height, sel->r.left, sel->r.top)) {
886 itv->main_rect = sel->r;
887 return 0;
1a0adaf3 888 }
3f038d80
HV
889 return -EINVAL;
890}
1a0adaf3 891
bbc9fa2e
HV
892static int ivtv_g_selection(struct file *file, void *fh,
893 struct v4l2_selection *sel)
3f038d80 894{
2f82441a 895 struct ivtv_open_id *id = fh2id(fh);
3f038d80
HV
896 struct ivtv *itv = id->itv;
897 struct yuv_playback_info *yi = &itv->yuv_info;
bbc9fa2e
HV
898 struct v4l2_rect r = { 0, 0, 720, 0 };
899 int streamtype = id->type;
900
901 if (sel->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
902 switch (sel->target) {
903 case V4L2_SEL_TGT_CROP_DEFAULT:
904 case V4L2_SEL_TGT_CROP_BOUNDS:
905 sel->r.top = sel->r.left = 0;
906 sel->r.width = 720;
907 sel->r.height = itv->is_50hz ? 576 : 480;
908 return 0;
909 default:
910 return -EINVAL;
911 }
912 }
1a0adaf3 913
bbc9fa2e
HV
914 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
915 !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
916 return -EINVAL;
3f038d80 917
bbc9fa2e
HV
918 switch (sel->target) {
919 case V4L2_SEL_TGT_COMPOSE:
3f038d80 920 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV)
bbc9fa2e 921 sel->r = yi->main_rect;
3f038d80 922 else
bbc9fa2e
HV
923 sel->r = itv->main_rect;
924 return 0;
925 case V4L2_SEL_TGT_COMPOSE_DEFAULT:
926 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
927 r.height = itv->is_out_50hz ? 576 : 480;
928 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV && yi->track_osd) {
929 r.width = yi->osd_full_w;
930 r.height = yi->osd_full_h;
931 }
932 sel->r = r;
3f038d80
HV
933 return 0;
934 }
935 return -EINVAL;
936}
937
938static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
939{
bfd063ce
HV
940 static const struct v4l2_fmtdesc hm12 = {
941 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 0,
942 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
943 { 0, 0, 0, 0 }
944 };
945 static const struct v4l2_fmtdesc mpeg = {
946 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FMT_FLAG_COMPRESSED,
947 "MPEG", V4L2_PIX_FMT_MPEG,
948 { 0, 0, 0, 0 }
3f038d80 949 };
bfd063ce
HV
950 struct ivtv *itv = fh2id(fh)->itv;
951 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80 952
bfd063ce
HV
953 if (fmt->index)
954 return -EINVAL;
955 if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
956 *fmt = mpeg;
957 else if (s->type == IVTV_ENC_STREAM_TYPE_YUV)
958 *fmt = hm12;
959 else
c9aec06f 960 return -EINVAL;
3f038d80
HV
961 return 0;
962}
1a0adaf3 963
3f038d80
HV
964static int ivtv_enum_fmt_vid_out(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
965{
bfd063ce
HV
966 static const struct v4l2_fmtdesc hm12 = {
967 0, V4L2_BUF_TYPE_VIDEO_OUTPUT, 0,
968 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
969 { 0, 0, 0, 0 }
970 };
971 static const struct v4l2_fmtdesc mpeg = {
972 0, V4L2_BUF_TYPE_VIDEO_OUTPUT, V4L2_FMT_FLAG_COMPRESSED,
973 "MPEG", V4L2_PIX_FMT_MPEG,
974 { 0, 0, 0, 0 }
3f038d80 975 };
bfd063ce
HV
976 struct ivtv *itv = fh2id(fh)->itv;
977 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80 978
bfd063ce 979 if (fmt->index)
3f038d80 980 return -EINVAL;
bfd063ce
HV
981 if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
982 *fmt = mpeg;
983 else if (s->type == IVTV_DEC_STREAM_TYPE_YUV)
984 *fmt = hm12;
985 else
3f038d80 986 return -EINVAL;
3f038d80
HV
987 return 0;
988}
989
990static int ivtv_g_input(struct file *file, void *fh, unsigned int *i)
991{
2f82441a 992 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
993
994 *i = itv->active_input;
995
996 return 0;
997}
998
999int ivtv_s_input(struct file *file, void *fh, unsigned int inp)
1000{
2f82441a 1001 struct ivtv *itv = fh2id(fh)->itv;
f659f0e7
HV
1002 v4l2_std_id std;
1003 int i;
3f038d80 1004
d6eb0b99 1005 if (inp >= itv->nof_inputs)
3f038d80
HV
1006 return -EINVAL;
1007
1008 if (inp == itv->active_input) {
1009 IVTV_DEBUG_INFO("Input unchanged\n");
1a0adaf3
HV
1010 return 0;
1011 }
1012
3f038d80
HV
1013 if (atomic_read(&itv->capturing) > 0) {
1014 return -EBUSY;
1a0adaf3
HV
1015 }
1016
3f038d80
HV
1017 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
1018 itv->active_input, inp);
1a0adaf3 1019
3f038d80
HV
1020 itv->active_input = inp;
1021 /* Set the audio input to whatever is appropriate for the
1022 input type. */
1023 itv->audio_input = itv->card->video_inputs[inp].audio_index;
1a0adaf3 1024
f659f0e7
HV
1025 if (itv->card->video_inputs[inp].video_type == IVTV_CARD_INPUT_VID_TUNER)
1026 std = itv->tuner_std;
1027 else
1028 std = V4L2_STD_ALL;
1029 for (i = 0; i <= IVTV_ENC_STREAM_TYPE_VBI; i++)
635d62f0 1030 itv->streams[i].vdev.tvnorms = std;
f659f0e7 1031
3f038d80
HV
1032 /* prevent others from messing with the streams until
1033 we're finished changing inputs. */
1034 ivtv_mute(itv);
1035 ivtv_video_set_io(itv);
1036 ivtv_audio_set_io(itv);
1037 ivtv_unmute(itv);
1038
1039 return 0;
1040}
1a0adaf3 1041
3f038d80
HV
1042static int ivtv_g_output(struct file *file, void *fh, unsigned int *i)
1043{
2f82441a 1044 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 1045
3f038d80
HV
1046 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1047 return -EINVAL;
1048
1049 *i = itv->active_output;
1050
1051 return 0;
1052}
1053
1054static int ivtv_s_output(struct file *file, void *fh, unsigned int outp)
1055{
2f82441a 1056 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1057
1058 if (outp >= itv->card->nof_outputs)
1059 return -EINVAL;
1060
1061 if (outp == itv->active_output) {
1062 IVTV_DEBUG_INFO("Output unchanged\n");
1063 return 0;
1a0adaf3 1064 }
3f038d80
HV
1065 IVTV_DEBUG_INFO("Changing output from %d to %d\n",
1066 itv->active_output, outp);
1a0adaf3 1067
3f038d80 1068 itv->active_output = outp;
5325b427
HV
1069 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing,
1070 SAA7127_INPUT_TYPE_NORMAL,
1071 itv->card->video_outputs[outp].video_output, 0);
3f038d80
HV
1072
1073 return 0;
1074}
1075
1076static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1077{
2f82441a 1078 struct ivtv *itv = fh2id(fh)->itv;
dff274fd 1079 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80 1080
635d62f0 1081 if (s->vdev.vfl_dir)
dff274fd 1082 return -ENOTTY;
3f038d80
HV
1083 if (vf->tuner != 0)
1084 return -EINVAL;
1085
67ec09fd 1086 ivtv_call_all(itv, tuner, g_frequency, vf);
3f038d80
HV
1087 return 0;
1088}
1089
b530a447 1090int ivtv_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *vf)
3f038d80 1091{
2f82441a 1092 struct ivtv *itv = fh2id(fh)->itv;
dff274fd 1093 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80 1094
635d62f0 1095 if (s->vdev.vfl_dir)
dff274fd 1096 return -ENOTTY;
3f038d80
HV
1097 if (vf->tuner != 0)
1098 return -EINVAL;
1099
1100 ivtv_mute(itv);
1101 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
67ec09fd 1102 ivtv_call_all(itv, tuner, s_frequency, vf);
3f038d80
HV
1103 ivtv_unmute(itv);
1104 return 0;
1105}
1106
1107static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std)
1108{
2f82441a 1109 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1110
1111 *std = itv->std;
1112 return 0;
1113}
1114
314527ac 1115void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id std)
3f038d80 1116{
314527ac
HV
1117 itv->std = std;
1118 itv->is_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
f7b80e69
HV
1119 itv->is_50hz = !itv->is_60hz;
1120 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1121 itv->cxhdl.width = 720;
1122 itv->cxhdl.height = itv->is_50hz ? 576 : 480;
3f038d80
HV
1123 itv->vbi.count = itv->is_50hz ? 18 : 12;
1124 itv->vbi.start[0] = itv->is_50hz ? 6 : 10;
1125 itv->vbi.start[1] = itv->is_50hz ? 318 : 273;
1126
1127 if (itv->hw_flags & IVTV_HW_CX25840)
1128 itv->vbi.sliced_decoder_line_size = itv->is_60hz ? 272 : 284;
1129
3f038d80 1130 /* Tuner */
8774bed9 1131 ivtv_call_all(itv, video, s_std, itv->std);
c5874c92 1132}
3f038d80 1133
314527ac 1134void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id std)
c5874c92
IA
1135{
1136 struct yuv_playback_info *yi = &itv->yuv_info;
1137 DEFINE_WAIT(wait);
1138 int f;
1139
1140 /* set display standard */
314527ac
HV
1141 itv->std_out = std;
1142 itv->is_out_60hz = (std & V4L2_STD_525_60) ? 1 : 0;
c5874c92
IA
1143 itv->is_out_50hz = !itv->is_out_60hz;
1144 ivtv_call_all(itv, video, s_std_output, itv->std_out);
1145
1146 /*
1147 * The next firmware call is time sensitive. Time it to
1148 * avoid risk of a hard lock, by trying to ensure the call
1149 * happens within the first 100 lines of the top field.
1150 * Make 4 attempts to sync to the decoder before giving up.
1151 */
cdc03781 1152 mutex_unlock(&itv->serialize_lock);
c5874c92
IA
1153 for (f = 0; f < 4; f++) {
1154 prepare_to_wait(&itv->vsync_waitq, &wait,
1155 TASK_UNINTERRUPTIBLE);
1156 if ((read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16) < 100)
1157 break;
1158 schedule_timeout(msecs_to_jiffies(25));
3f038d80 1159 }
c5874c92 1160 finish_wait(&itv->vsync_waitq, &wait);
cdc03781 1161 mutex_lock(&itv->serialize_lock);
c5874c92
IA
1162
1163 if (f == 4)
1164 IVTV_WARN("Mode change failed to sync to decoder\n");
1165
1166 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1167 itv->main_rect.left = 0;
1168 itv->main_rect.top = 0;
1169 itv->main_rect.width = 720;
1170 itv->main_rect.height = itv->is_out_50hz ? 576 : 480;
1171 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1172 720, itv->main_rect.height, 0, 0);
1173 yi->main_rect = itv->main_rect;
1174 if (!itv->osd_info) {
1175 yi->osd_full_w = 720;
1176 yi->osd_full_h = itv->is_out_50hz ? 576 : 480;
1177 }
1178}
1179
314527ac 1180static int ivtv_s_std(struct file *file, void *fh, v4l2_std_id std)
c5874c92
IA
1181{
1182 struct ivtv *itv = fh2id(fh)->itv;
1183
314527ac 1184 if ((std & V4L2_STD_ALL) == 0)
c5874c92
IA
1185 return -EINVAL;
1186
314527ac 1187 if (std == itv->std)
c5874c92
IA
1188 return 0;
1189
1190 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
1191 atomic_read(&itv->capturing) > 0 ||
1192 atomic_read(&itv->decoding) > 0) {
1193 /* Switching standard would mess with already running
1194 streams, prevent that by returning EBUSY. */
1195 return -EBUSY;
1196 }
1197
1198 IVTV_DEBUG_INFO("Switching standard to %llx.\n",
1199 (unsigned long long)itv->std);
1200
1201 ivtv_s_std_enc(itv, std);
1202 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
1203 ivtv_s_std_dec(itv, std);
1204
3f038d80
HV
1205 return 0;
1206}
1207
2f73c7c5 1208static int ivtv_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *vt)
3f038d80 1209{
2f82441a 1210 struct ivtv_open_id *id = fh2id(fh);
3f038d80
HV
1211 struct ivtv *itv = id->itv;
1212
1213 if (vt->index != 0)
1214 return -EINVAL;
1215
67ec09fd 1216 ivtv_call_all(itv, tuner, s_tuner, vt);
3f038d80
HV
1217
1218 return 0;
1219}
1220
1221static int ivtv_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1222{
2f82441a 1223 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1224
1225 if (vt->index != 0)
1226 return -EINVAL;
1227
67ec09fd 1228 ivtv_call_all(itv, tuner, g_tuner, vt);
3f038d80 1229
d118e294 1230 if (vt->type == V4L2_TUNER_RADIO)
c0decac1 1231 strscpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
d118e294 1232 else
c0decac1 1233 strscpy(vt->name, "ivtv TV Tuner", sizeof(vt->name));
3f038d80
HV
1234 return 0;
1235}
1a0adaf3 1236
3f038d80
HV
1237static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced_vbi_cap *cap)
1238{
2f82441a 1239 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1240 int set = itv->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
1241 int f, l;
3f038d80 1242
79afcb10 1243 if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
3f038d80
HV
1244 for (f = 0; f < 2; f++) {
1245 for (l = 0; l < 24; l++) {
1246 if (valid_service_line(f, l, itv->is_50hz))
1247 cap->service_lines[f][l] = set;
1248 }
1249 }
2b5d9480 1250 } else if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
3f038d80 1251 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
1a0adaf3 1252 return -EINVAL;
3f038d80
HV
1253 if (itv->is_60hz) {
1254 cap->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
1255 cap->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
1256 } else {
1257 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
1258 cap->service_lines[0][16] = V4L2_SLICED_VPS;
1a0adaf3 1259 }
2b5d9480
HV
1260 } else {
1261 return -EINVAL;
1a0adaf3 1262 }
2b5d9480
HV
1263
1264 set = 0;
1265 for (f = 0; f < 2; f++)
1266 for (l = 0; l < 24; l++)
1267 set |= cap->service_lines[f][l];
1268 cap->service_set = set;
1269 return 0;
3f038d80 1270}
1a0adaf3 1271
3f038d80
HV
1272static int ivtv_g_enc_index(struct file *file, void *fh, struct v4l2_enc_idx *idx)
1273{
2f82441a 1274 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1275 struct v4l2_enc_idx_entry *e = idx->entry;
1276 int entries;
1277 int i;
1a0adaf3 1278
3f038d80
HV
1279 entries = (itv->pgm_info_write_idx + IVTV_MAX_PGM_INDEX - itv->pgm_info_read_idx) %
1280 IVTV_MAX_PGM_INDEX;
1281 if (entries > V4L2_ENC_IDX_ENTRIES)
1282 entries = V4L2_ENC_IDX_ENTRIES;
1283 idx->entries = 0;
1a806401
HV
1284 idx->entries_cap = IVTV_MAX_PGM_INDEX;
1285 if (!atomic_read(&itv->capturing))
1286 return 0;
3f038d80
HV
1287 for (i = 0; i < entries; i++) {
1288 *e = itv->pgm_info[(itv->pgm_info_read_idx + i) % IVTV_MAX_PGM_INDEX];
1289 if ((e->flags & V4L2_ENC_IDX_FRAME_MASK) <= V4L2_ENC_IDX_FRAME_B) {
1290 idx->entries++;
1291 e++;
1292 }
1a0adaf3 1293 }
3f038d80
HV
1294 itv->pgm_info_read_idx = (itv->pgm_info_read_idx + idx->entries) % IVTV_MAX_PGM_INDEX;
1295 return 0;
1296}
1a0adaf3 1297
3f038d80
HV
1298static int ivtv_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1299{
2f82441a 1300 struct ivtv_open_id *id = fh2id(fh);
3f038d80 1301 struct ivtv *itv = id->itv;
1a0adaf3 1302
1a0adaf3 1303
3f038d80
HV
1304 switch (enc->cmd) {
1305 case V4L2_ENC_CMD_START:
1306 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1307 enc->flags = 0;
1308 return ivtv_start_capture(id);
1a0adaf3 1309
3f038d80
HV
1310 case V4L2_ENC_CMD_STOP:
1311 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1312 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1313 ivtv_stop_capture(id, enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
1314 return 0;
1a0adaf3 1315
3f038d80
HV
1316 case V4L2_ENC_CMD_PAUSE:
1317 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1318 enc->flags = 0;
1a0adaf3 1319
3f038d80
HV
1320 if (!atomic_read(&itv->capturing))
1321 return -EPERM;
1322 if (test_and_set_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1323 return 0;
1a0adaf3 1324
3f038d80
HV
1325 ivtv_mute(itv);
1326 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 0);
1a0adaf3 1327 break;
1a0adaf3 1328
3f038d80
HV
1329 case V4L2_ENC_CMD_RESUME:
1330 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1331 enc->flags = 0;
1a0adaf3 1332
3f038d80
HV
1333 if (!atomic_read(&itv->capturing))
1334 return -EPERM;
1a0adaf3 1335
3f038d80
HV
1336 if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1337 return 0;
1a0adaf3 1338
3f038d80
HV
1339 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1);
1340 ivtv_unmute(itv);
1a0adaf3 1341 break;
3f038d80
HV
1342 default:
1343 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1344 return -EINVAL;
1a0adaf3
HV
1345 }
1346
3f038d80
HV
1347 return 0;
1348}
1a0adaf3 1349
3f038d80
HV
1350static int ivtv_try_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1351{
2f82441a 1352 struct ivtv *itv = fh2id(fh)->itv;
1a0adaf3 1353
3f038d80
HV
1354 switch (enc->cmd) {
1355 case V4L2_ENC_CMD_START:
1356 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1357 enc->flags = 0;
1358 return 0;
1a0adaf3 1359
3f038d80
HV
1360 case V4L2_ENC_CMD_STOP:
1361 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1362 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1363 return 0;
1a0adaf3 1364
3f038d80
HV
1365 case V4L2_ENC_CMD_PAUSE:
1366 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1367 enc->flags = 0;
1368 return 0;
1a0adaf3 1369
3f038d80
HV
1370 case V4L2_ENC_CMD_RESUME:
1371 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1372 enc->flags = 0;
1373 return 0;
1374 default:
1375 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1376 return -EINVAL;
1a0adaf3 1377 }
3f038d80 1378}
1a0adaf3 1379
3f038d80
HV
1380static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1381{
2f82441a 1382 struct ivtv *itv = fh2id(fh)->itv;
38a1421d 1383 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80
HV
1384 u32 data[CX2341X_MBOX_MAX_DATA];
1385 struct yuv_playback_info *yi = &itv->yuv_info;
1386
1387 int pixfmt;
1388 static u32 pixel_format[16] = {
1389 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry RGB colormap */
1390 V4L2_PIX_FMT_RGB565,
1391 V4L2_PIX_FMT_RGB555,
1392 V4L2_PIX_FMT_RGB444,
1393 V4L2_PIX_FMT_RGB32,
1394 0,
1395 0,
1396 0,
1397 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry YUV colormap */
1398 V4L2_PIX_FMT_YUV565,
1399 V4L2_PIX_FMT_YUV555,
1400 V4L2_PIX_FMT_YUV444,
1401 V4L2_PIX_FMT_YUV32,
1402 0,
1403 0,
1404 0,
1405 };
1406
38a1421d
HV
1407 if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1408 return -ENOTTY;
37f89f95 1409 if (!itv->osd_video_pbase)
38a1421d 1410 return -ENOTTY;
1a0adaf3 1411
3f038d80
HV
1412 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY |
1413 V4L2_FBUF_CAP_GLOBAL_ALPHA;
d4e7ee36 1414
3f038d80
HV
1415 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1416 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1417 pixfmt = (data[0] >> 3) & 0xf;
d4e7ee36 1418
3f038d80
HV
1419 fb->fmt.pixelformat = pixel_format[pixfmt];
1420 fb->fmt.width = itv->osd_rect.width;
1421 fb->fmt.height = itv->osd_rect.height;
5cf2cc48
HV
1422 fb->fmt.field = V4L2_FIELD_INTERLACED;
1423 fb->fmt.bytesperline = fb->fmt.width;
37f89f95
HV
1424 fb->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
1425 fb->fmt.field = V4L2_FIELD_INTERLACED;
5cf2cc48
HV
1426 if (fb->fmt.pixelformat != V4L2_PIX_FMT_PAL8)
1427 fb->fmt.bytesperline *= 2;
1428 if (fb->fmt.pixelformat == V4L2_PIX_FMT_RGB32 ||
1429 fb->fmt.pixelformat == V4L2_PIX_FMT_YUV32)
1430 fb->fmt.bytesperline *= 2;
37f89f95 1431 fb->fmt.sizeimage = fb->fmt.bytesperline * fb->fmt.height;
3f038d80 1432 fb->base = (void *)itv->osd_video_pbase;
5cf2cc48 1433 fb->flags = 0;
d4e7ee36 1434
3f038d80
HV
1435 if (itv->osd_chroma_key_state)
1436 fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
d4e7ee36 1437
3f038d80
HV
1438 if (itv->osd_global_alpha_state)
1439 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
d4e7ee36 1440
ec9faa1c
IA
1441 if (yi->track_osd)
1442 fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
1443
3f038d80 1444 pixfmt &= 7;
d4e7ee36 1445
3f038d80
HV
1446 /* no local alpha for RGB565 or unknown formats */
1447 if (pixfmt == 1 || pixfmt > 4)
1448 return 0;
1449
1450 /* 16-bit formats have inverted local alpha */
1451 if (pixfmt == 2 || pixfmt == 3)
1452 fb->capability |= V4L2_FBUF_CAP_LOCAL_INV_ALPHA;
1453 else
1454 fb->capability |= V4L2_FBUF_CAP_LOCAL_ALPHA;
1455
1456 if (itv->osd_local_alpha_state) {
2d4d5f11
HV
1457 /* 16-bit formats have inverted local alpha */
1458 if (pixfmt == 2 || pixfmt == 3)
3f038d80 1459 fb->flags |= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA;
2d4d5f11 1460 else
3f038d80 1461 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
d4e7ee36 1462 }
3f038d80
HV
1463
1464 return 0;
1465}
d4e7ee36 1466
e6eb28c2 1467static int ivtv_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuffer *fb)
3f038d80 1468{
2f82441a 1469 struct ivtv_open_id *id = fh2id(fh);
3f038d80 1470 struct ivtv *itv = id->itv;
38a1421d 1471 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
3f038d80 1472 struct yuv_playback_info *yi = &itv->yuv_info;
d4e7ee36 1473
38a1421d
HV
1474 if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1475 return -ENOTTY;
37f89f95 1476 if (!itv->osd_video_pbase)
38a1421d 1477 return -ENOTTY;
d4e7ee36 1478
3f038d80
HV
1479 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0;
1480 itv->osd_local_alpha_state =
1481 (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0;
1482 itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
1483 ivtv_set_osd_alpha(itv);
1484 yi->track_osd = (fb->flags & V4L2_FBUF_FLAG_OVERLAY) != 0;
e6eb28c2 1485 return 0;
3f038d80
HV
1486}
1487
1488static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
1489{
2f82441a 1490 struct ivtv_open_id *id = fh2id(fh);
3f038d80 1491 struct ivtv *itv = id->itv;
38a1421d 1492 struct ivtv_stream *s = &itv->streams[fh2id(fh)->type];
7c03a448 1493
38a1421d
HV
1494 if (!(s->caps & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1495 return -ENOTTY;
1496 if (!itv->osd_video_pbase)
1497 return -ENOTTY;
1a0adaf3 1498
3f038d80 1499 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, on != 0);
1a0adaf3 1500
3f038d80
HV
1501 return 0;
1502}
1503
85f5fe39 1504static int ivtv_subscribe_event(struct v4l2_fh *fh, const struct v4l2_event_subscription *sub)
09250193
HV
1505{
1506 switch (sub->type) {
1507 case V4L2_EVENT_VSYNC:
1508 case V4L2_EVENT_EOS:
c53c2549 1509 return v4l2_event_subscribe(fh, sub, 0, NULL);
09250193 1510 default:
88b172f9 1511 return v4l2_ctrl_subscribe_event(fh, sub);
09250193 1512 }
09250193
HV
1513}
1514
3f038d80
HV
1515static int ivtv_log_status(struct file *file, void *fh)
1516{
2f82441a 1517 struct ivtv *itv = fh2id(fh)->itv;
3f038d80
HV
1518 u32 data[CX2341X_MBOX_MAX_DATA];
1519
1520 int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT;
1521 struct v4l2_input vidin;
1522 struct v4l2_audio audin;
1523 int i;
1524
3f038d80
HV
1525 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name);
1526 if (itv->hw_flags & IVTV_HW_TVEEPROM) {
1527 struct tveeprom tv;
1528
1529 ivtv_read_eeprom(itv, &tv);
1530 }
67ec09fd 1531 ivtv_call_all(itv, core, log_status);
3f038d80
HV
1532 ivtv_get_input(itv, itv->active_input, &vidin);
1533 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1534 IVTV_INFO("Video Input: %s\n", vidin.name);
1535 IVTV_INFO("Audio Input: %s%s\n", audin.name,
3725d531
HV
1536 itv->dualwatch_stereo_mode == V4L2_MPEG_AUDIO_MODE_DUAL ?
1537 " (Bilingual)" : "");
3f038d80
HV
1538 if (has_output) {
1539 struct v4l2_output vidout;
1540 struct v4l2_audioout audout;
1541 int mode = itv->output_mode;
1542 static const char * const output_modes[5] = {
1543 "None",
1544 "MPEG Streaming",
1545 "YUV Streaming",
1546 "YUV Frames",
1547 "Passthrough",
1548 };
3f038d80
HV
1549 static const char * const alpha_mode[4] = {
1550 "None",
1551 "Global",
1552 "Local",
1553 "Global and Local"
1554 };
1555 static const char * const pixel_format[16] = {
1556 "ARGB Indexed",
1557 "RGB 5:6:5",
1558 "ARGB 1:5:5:5",
1559 "ARGB 1:4:4:4",
1560 "ARGB 8:8:8:8",
1561 "5",
1562 "6",
1563 "7",
1564 "AYUV Indexed",
1565 "YUV 5:6:5",
1566 "AYUV 1:5:5:5",
1567 "AYUV 1:4:4:4",
1568 "AYUV 8:8:8:8",
1569 "13",
1570 "14",
1571 "15",
1572 };
1573
1574 ivtv_get_output(itv, itv->active_output, &vidout);
1575 ivtv_get_audio_output(itv, 0, &audout);
1576 IVTV_INFO("Video Output: %s\n", vidout.name);
3f038d80
HV
1577 if (mode < 0 || mode > OUT_PASSTHROUGH)
1578 mode = OUT_NONE;
1579 IVTV_INFO("Output Mode: %s\n", output_modes[mode]);
1580 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1581 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1582 IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1583 data[0] & 1 ? "On" : "Off",
1584 alpha_mode[(data[0] >> 1) & 0x3],
1585 pixel_format[(data[0] >> 3) & 0xf]);
1a0adaf3 1586 }
3f038d80
HV
1587 IVTV_INFO("Tuner: %s\n",
1588 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
eb2ba855 1589 v4l2_ctrl_handler_log_status(&itv->cxhdl.hdl, itv->v4l2_dev.name);
3f038d80
HV
1590 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1591 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1592 struct ivtv_stream *s = &itv->streams[i];
1a0adaf3 1593
635d62f0 1594 if (s->vdev.v4l2_dev == NULL || s->buffers == 0)
3f038d80
HV
1595 continue;
1596 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags,
1597 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
1598 (s->buffers * s->buf_size) / 1024, s->buffers);
1a0adaf3 1599 }
3f038d80 1600
67ec09fd
HV
1601 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n",
1602 (long long)itv->mpg_data_received,
1603 (long long)itv->vbi_data_inserted);
1a0adaf3
HV
1604 return 0;
1605}
1606
da8ec560
HV
1607static int ivtv_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *dec)
1608{
1609 struct ivtv_open_id *id = fh2id(file->private_data);
1610 struct ivtv *itv = id->itv;
1611
1612 IVTV_DEBUG_IOCTL("VIDIOC_DECODER_CMD %d\n", dec->cmd);
1613 return ivtv_video_command(itv, id, dec, false);
1614}
1615
1616static int ivtv_try_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *dec)
1617{
1618 struct ivtv_open_id *id = fh2id(file->private_data);
1619 struct ivtv *itv = id->itv;
1620
1621 IVTV_DEBUG_IOCTL("VIDIOC_TRY_DECODER_CMD %d\n", dec->cmd);
1622 return ivtv_video_command(itv, id, dec, true);
1623}
1624
66896380
MCC
1625#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1626static __inline__ void warn_deprecated_ioctl(const char *name)
1627{
1628 pr_warn_once("warning: the %s ioctl is deprecated. Don't use it, as it will be removed soon\n",
1629 name);
1630}
04b72322
AB
1631
1632#ifdef CONFIG_COMPAT
1633struct compat_video_event {
1634 __s32 type;
1635 /* unused, make sure to use atomic time for y2038 if it ever gets used */
1636 compat_long_t timestamp;
1637 union {
1638 video_size_t size;
1639 unsigned int frame_rate; /* in frames per 1000sec */
1640 unsigned char vsync_field; /* unknown/odd/even/progressive */
1641 } u;
1642};
1643#define VIDEO_GET_EVENT32 _IOR('o', 28, struct compat_video_event)
1644#endif
1645
66896380
MCC
1646#endif
1647
d4e7ee36 1648static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1a0adaf3 1649{
09250193 1650 struct ivtv_open_id *id = fh2id(filp->private_data);
1a0adaf3 1651 struct ivtv *itv = id->itv;
1a0adaf3 1652 struct ivtv_stream *s = &itv->streams[id->type];
66896380
MCC
1653#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1654 int nonblocking = filp->f_flags & O_NONBLOCK;
ce68025e 1655 unsigned long iarg = (unsigned long)arg;
66896380 1656#endif
1a0adaf3
HV
1657
1658 switch (cmd) {
1659 case IVTV_IOC_DMA_FRAME: {
1660 struct ivtv_dma_frame *args = arg;
1661
1662 IVTV_DEBUG_IOCTL("IVTV_IOC_DMA_FRAME\n");
1663 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1664 return -EINVAL;
1665 if (args->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1666 return -EINVAL;
1667 if (itv->output_mode == OUT_UDMA_YUV && args->y_source == NULL)
1668 return 0;
42b03fe1 1669 if (ivtv_start_decoding(id, id->type)) {
1a0adaf3
HV
1670 return -EBUSY;
1671 }
1672 if (ivtv_set_output_mode(itv, OUT_UDMA_YUV) != OUT_UDMA_YUV) {
1673 ivtv_release_stream(s);
1674 return -EBUSY;
1675 }
ad8ff0f1
HV
1676 /* Mark that this file handle started the UDMA_YUV mode */
1677 id->yuv_frames = 1;
1a0adaf3
HV
1678 if (args->y_source == NULL)
1679 return 0;
1680 return ivtv_yuv_prep_frame(itv, args);
1681 }
1682
6e82a6a2
HV
1683 case IVTV_IOC_PASSTHROUGH_MODE:
1684 IVTV_DEBUG_IOCTL("IVTV_IOC_PASSTHROUGH_MODE\n");
1685 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1686 return -EINVAL;
1687 return ivtv_passthrough_mode(itv, *(int *)arg != 0);
66896380 1688#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
1a0adaf3 1689 case VIDEO_GET_PTS: {
debf8001
HV
1690 s64 *pts = arg;
1691 s64 frame;
1a0adaf3 1692
66896380 1693 warn_deprecated_ioctl("VIDEO_GET_PTS");
1a0adaf3
HV
1694 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1695 *pts = s->dma_pts;
1696 break;
1697 }
1698 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1699 return -EINVAL;
debf8001 1700 return ivtv_g_pts_frame(itv, pts, &frame);
1a0adaf3
HV
1701 }
1702
1703 case VIDEO_GET_FRAME_COUNT: {
debf8001
HV
1704 s64 *frame = arg;
1705 s64 pts;
1a0adaf3 1706
66896380 1707 warn_deprecated_ioctl("VIDEO_GET_FRAME_COUNT");
1a0adaf3
HV
1708 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1709 *frame = 0;
1710 break;
1711 }
1712 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1713 return -EINVAL;
debf8001 1714 return ivtv_g_pts_frame(itv, &pts, frame);
1a0adaf3
HV
1715 }
1716
1717 case VIDEO_PLAY: {
da8ec560 1718 struct v4l2_decoder_cmd dc;
1a0adaf3 1719
66896380 1720 warn_deprecated_ioctl("VIDEO_PLAY");
da8ec560
HV
1721 memset(&dc, 0, sizeof(dc));
1722 dc.cmd = V4L2_DEC_CMD_START;
1723 return ivtv_video_command(itv, id, &dc, 0);
1a0adaf3
HV
1724 }
1725
1726 case VIDEO_STOP: {
da8ec560 1727 struct v4l2_decoder_cmd dc;
1a0adaf3 1728
66896380 1729 warn_deprecated_ioctl("VIDEO_STOP");
da8ec560
HV
1730 memset(&dc, 0, sizeof(dc));
1731 dc.cmd = V4L2_DEC_CMD_STOP;
1732 dc.flags = V4L2_DEC_CMD_STOP_TO_BLACK | V4L2_DEC_CMD_STOP_IMMEDIATELY;
1733 return ivtv_video_command(itv, id, &dc, 0);
1a0adaf3
HV
1734 }
1735
1736 case VIDEO_FREEZE: {
da8ec560 1737 struct v4l2_decoder_cmd dc;
1a0adaf3 1738
66896380 1739 warn_deprecated_ioctl("VIDEO_FREEZE");
da8ec560
HV
1740 memset(&dc, 0, sizeof(dc));
1741 dc.cmd = V4L2_DEC_CMD_PAUSE;
1742 return ivtv_video_command(itv, id, &dc, 0);
1a0adaf3
HV
1743 }
1744
1745 case VIDEO_CONTINUE: {
da8ec560 1746 struct v4l2_decoder_cmd dc;
1a0adaf3 1747
66896380 1748 warn_deprecated_ioctl("VIDEO_CONTINUE");
da8ec560
HV
1749 memset(&dc, 0, sizeof(dc));
1750 dc.cmd = V4L2_DEC_CMD_RESUME;
1751 return ivtv_video_command(itv, id, &dc, 0);
1a0adaf3
HV
1752 }
1753
1754 case VIDEO_COMMAND:
1755 case VIDEO_TRY_COMMAND: {
da8ec560
HV
1756 /* Note: struct v4l2_decoder_cmd has the same layout as
1757 struct video_command */
1758 struct v4l2_decoder_cmd *dc = arg;
1a0adaf3
HV
1759 int try = (cmd == VIDEO_TRY_COMMAND);
1760
1761 if (try)
66896380 1762 warn_deprecated_ioctl("VIDEO_TRY_COMMAND");
1a0adaf3 1763 else
66896380 1764 warn_deprecated_ioctl("VIDEO_COMMAND");
da8ec560 1765 return ivtv_video_command(itv, id, dc, try);
1a0adaf3
HV
1766 }
1767
04b72322
AB
1768#ifdef CONFIG_COMPAT
1769 case VIDEO_GET_EVENT32:
1770#endif
1a0adaf3 1771 case VIDEO_GET_EVENT: {
04b72322
AB
1772#ifdef CONFIG_COMPAT
1773 struct compat_video_event *ev32 = arg;
1774#endif
1a0adaf3
HV
1775 struct video_event *ev = arg;
1776 DEFINE_WAIT(wait);
1777
66896380 1778 warn_deprecated_ioctl("VIDEO_GET_EVENT");
1a0adaf3
HV
1779 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1780 return -EINVAL;
1781 memset(ev, 0, sizeof(*ev));
1782 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
1783
1784 while (1) {
1785 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
1786 ev->type = VIDEO_EVENT_DECODER_STOPPED;
1787 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags)) {
04b72322
AB
1788 unsigned char vsync_field;
1789
1a0adaf3 1790 ev->type = VIDEO_EVENT_VSYNC;
04b72322 1791 vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ?
037c86c5
HV
1792 VIDEO_VSYNC_FIELD_ODD : VIDEO_VSYNC_FIELD_EVEN;
1793 if (itv->output_mode == OUT_UDMA_YUV &&
1794 (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) ==
1795 IVTV_YUV_MODE_PROGRESSIVE) {
04b72322 1796 vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE;
037c86c5 1797 }
04b72322
AB
1798#ifdef CONFIG_COMPAT
1799 if (cmd == VIDEO_GET_EVENT32)
1800 ev32->u.vsync_field = vsync_field;
1801 else
1802#endif
1803 ev->u.vsync_field = vsync_field;
1a0adaf3
HV
1804 }
1805 if (ev->type)
1806 return 0;
1807 if (nonblocking)
1808 return -EAGAIN;
baa4072d
HV
1809 /* Wait for event. Note that serialize_lock is locked,
1810 so to allow other processes to access the driver while
1811 we are waiting unlock first and later lock again. */
1812 mutex_unlock(&itv->serialize_lock);
1a0adaf3 1813 prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE);
ec105a42
HV
1814 if (!test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags) &&
1815 !test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags))
1a0adaf3
HV
1816 schedule();
1817 finish_wait(&itv->event_waitq, &wait);
baa4072d 1818 mutex_lock(&itv->serialize_lock);
1a0adaf3
HV
1819 if (signal_pending(current)) {
1820 /* return if a signal was received */
1821 IVTV_DEBUG_INFO("User stopped wait for event\n");
1822 return -EINTR;
1823 }
1824 }
1825 break;
1826 }
1827
ce68025e 1828 case VIDEO_SELECT_SOURCE:
66896380 1829 warn_deprecated_ioctl("VIDEO_SELECT_SOURCE");
ce68025e
HV
1830 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1831 return -EINVAL;
1832 return ivtv_passthrough_mode(itv, iarg == VIDEO_SOURCE_DEMUX);
1833
1834 case AUDIO_SET_MUTE:
66896380 1835 warn_deprecated_ioctl("AUDIO_SET_MUTE");
ce68025e
HV
1836 itv->speed_mute_audio = iarg;
1837 return 0;
1838
1839 case AUDIO_CHANNEL_SELECT:
66896380 1840 warn_deprecated_ioctl("AUDIO_CHANNEL_SELECT");
ce68025e
HV
1841 if (iarg > AUDIO_STEREO_SWAPPED)
1842 return -EINVAL;
bc169e35 1843 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_playback, iarg + 1);
ce68025e
HV
1844
1845 case AUDIO_BILINGUAL_CHANNEL_SELECT:
66896380 1846 warn_deprecated_ioctl("AUDIO_BILINGUAL_CHANNEL_SELECT");
ce68025e
HV
1847 if (iarg > AUDIO_STEREO_SWAPPED)
1848 return -EINVAL;
bc169e35 1849 return v4l2_ctrl_s_ctrl(itv->ctrl_audio_multilingual_playback, iarg + 1);
66896380 1850#endif
1a0adaf3
HV
1851 default:
1852 return -EINVAL;
1853 }
1854 return 0;
1855}
1856
99cd47bc 1857static long ivtv_default(struct file *file, void *fh, bool valid_prio,
6d43be77 1858 unsigned int cmd, void *arg)
1a0adaf3 1859{
2f82441a 1860 struct ivtv *itv = fh2id(fh)->itv;
d46c17d7 1861
cc0a2d41
HV
1862 if (!valid_prio) {
1863 switch (cmd) {
6e82a6a2 1864 case IVTV_IOC_PASSTHROUGH_MODE:
66896380 1865#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
cc0a2d41
HV
1866 case VIDEO_PLAY:
1867 case VIDEO_STOP:
1868 case VIDEO_FREEZE:
1869 case VIDEO_CONTINUE:
1870 case VIDEO_COMMAND:
1871 case VIDEO_SELECT_SOURCE:
1872 case AUDIO_SET_MUTE:
1873 case AUDIO_CHANNEL_SELECT:
1874 case AUDIO_BILINGUAL_CHANNEL_SELECT:
66896380 1875#endif
cc0a2d41
HV
1876 return -EBUSY;
1877 }
1878 }
1879
1a0adaf3 1880 switch (cmd) {
3f038d80
HV
1881 case VIDIOC_INT_RESET: {
1882 u32 val = *(u32 *)arg;
1a0adaf3 1883
3f038d80
HV
1884 if ((val == 0 && itv->options.newi2c) || (val & 0x01))
1885 ivtv_reset_ir_gpio(itv);
1886 if (val & 0x02)
67ec09fd 1887 v4l2_subdev_call(itv->sd_video, core, reset, 0);
3f038d80
HV
1888 break;
1889 }
1a0adaf3 1890
ac9575f7 1891 case IVTV_IOC_DMA_FRAME:
6e82a6a2 1892 case IVTV_IOC_PASSTHROUGH_MODE:
66896380 1893#ifdef CONFIG_VIDEO_IVTV_DEPRECATED_IOCTLS
ac9575f7
HV
1894 case VIDEO_GET_PTS:
1895 case VIDEO_GET_FRAME_COUNT:
1896 case VIDEO_GET_EVENT:
1897 case VIDEO_PLAY:
1898 case VIDEO_STOP:
1899 case VIDEO_FREEZE:
1900 case VIDEO_CONTINUE:
1901 case VIDEO_COMMAND:
1902 case VIDEO_TRY_COMMAND:
ce68025e
HV
1903 case VIDEO_SELECT_SOURCE:
1904 case AUDIO_SET_MUTE:
1905 case AUDIO_CHANNEL_SELECT:
1906 case AUDIO_BILINGUAL_CHANNEL_SELECT:
66896380 1907#endif
ac9575f7
HV
1908 return ivtv_decoder_ioctls(file, cmd, (void *)arg);
1909
1a0adaf3 1910 default:
d1c754a9 1911 return -ENOTTY;
1a0adaf3
HV
1912 }
1913 return 0;
1914}
1915
a399810c 1916static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
6e6a8b5a
MCC
1917 .vidioc_querycap = ivtv_querycap,
1918 .vidioc_s_audio = ivtv_s_audio,
1919 .vidioc_g_audio = ivtv_g_audio,
1920 .vidioc_enumaudio = ivtv_enumaudio,
1921 .vidioc_s_audout = ivtv_s_audout,
1922 .vidioc_g_audout = ivtv_g_audout,
1923 .vidioc_enum_input = ivtv_enum_input,
1924 .vidioc_enum_output = ivtv_enum_output,
1925 .vidioc_enumaudout = ivtv_enumaudout,
1926 .vidioc_cropcap = ivtv_cropcap,
bbc9fa2e
HV
1927 .vidioc_s_selection = ivtv_s_selection,
1928 .vidioc_g_selection = ivtv_g_selection,
6e6a8b5a
MCC
1929 .vidioc_g_input = ivtv_g_input,
1930 .vidioc_s_input = ivtv_s_input,
1931 .vidioc_g_output = ivtv_g_output,
1932 .vidioc_s_output = ivtv_s_output,
1933 .vidioc_g_frequency = ivtv_g_frequency,
1934 .vidioc_s_frequency = ivtv_s_frequency,
1935 .vidioc_s_tuner = ivtv_s_tuner,
1936 .vidioc_g_tuner = ivtv_g_tuner,
1937 .vidioc_g_enc_index = ivtv_g_enc_index,
a399810c
HV
1938 .vidioc_g_fbuf = ivtv_g_fbuf,
1939 .vidioc_s_fbuf = ivtv_s_fbuf,
6e6a8b5a
MCC
1940 .vidioc_g_std = ivtv_g_std,
1941 .vidioc_s_std = ivtv_s_std,
a399810c
HV
1942 .vidioc_overlay = ivtv_overlay,
1943 .vidioc_log_status = ivtv_log_status,
6e6a8b5a
MCC
1944 .vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap,
1945 .vidioc_encoder_cmd = ivtv_encoder_cmd,
1946 .vidioc_try_encoder_cmd = ivtv_try_encoder_cmd,
da8ec560
HV
1947 .vidioc_decoder_cmd = ivtv_decoder_cmd,
1948 .vidioc_try_decoder_cmd = ivtv_try_decoder_cmd,
6e6a8b5a
MCC
1949 .vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out,
1950 .vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap,
a399810c
HV
1951 .vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap,
1952 .vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap,
1953 .vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out,
1954 .vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay,
1955 .vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out,
6e6a8b5a
MCC
1956 .vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap,
1957 .vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap,
a399810c
HV
1958 .vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap,
1959 .vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out,
1960 .vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay,
1961 .vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out,
6e6a8b5a 1962 .vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap,
a399810c
HV
1963 .vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap,
1964 .vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap,
6e6a8b5a 1965 .vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out,
a399810c 1966 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay,
6e6a8b5a
MCC
1967 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out,
1968 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap,
36ecd495 1969#ifdef CONFIG_VIDEO_ADV_DEBUG
6e6a8b5a
MCC
1970 .vidioc_g_register = ivtv_g_register,
1971 .vidioc_s_register = ivtv_s_register,
36ecd495 1972#endif
6e6a8b5a
MCC
1973 .vidioc_default = ivtv_default,
1974 .vidioc_subscribe_event = ivtv_subscribe_event,
1975 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
a399810c
HV
1976};
1977
1978void ivtv_set_funcs(struct video_device *vdev)
1979{
1980 vdev->ioctl_ops = &ivtv_ioctl_ops;
3f038d80 1981}