blob: e67bf1b15cf3a3f9f1a4809a9780d0a935a98e8f [file] [log] [blame]
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001/*
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"
Hans Verkuil33c0fca2007-08-23 06:32:46 -030028#include "ivtv-routing.h"
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030029#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"
35#include <media/saa7127.h>
36#include <media/tveeprom.h>
37#include <media/v4l2-chip-ident.h>
38#include <linux/dvb/audio.h>
39#include <linux/i2c-id.h>
40
Hans Verkuilfeb5bce2008-05-01 09:22:13 -030041u16 ivtv_service2vbi(int type)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030042{
43 switch (type) {
44 case V4L2_SLICED_TELETEXT_B:
45 return IVTV_SLICED_TYPE_TELETEXT_B;
46 case V4L2_SLICED_CAPTION_525:
47 return IVTV_SLICED_TYPE_CAPTION_525;
48 case V4L2_SLICED_WSS_625:
49 return IVTV_SLICED_TYPE_WSS_625;
50 case V4L2_SLICED_VPS:
51 return IVTV_SLICED_TYPE_VPS;
52 default:
53 return 0;
54 }
55}
56
57static int valid_service_line(int field, int line, int is_pal)
58{
59 return (is_pal && line >= 6 && (line != 23 || field == 0)) ||
60 (!is_pal && line >= 10 && line < 22);
61}
62
63static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
64{
65 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
66 int i;
67
68 set = set & valid_set;
69 if (set == 0 || !valid_service_line(field, line, is_pal)) {
70 return 0;
71 }
72 if (!is_pal) {
73 if (line == 21 && (set & V4L2_SLICED_CAPTION_525))
74 return V4L2_SLICED_CAPTION_525;
75 }
76 else {
77 if (line == 16 && field == 0 && (set & V4L2_SLICED_VPS))
78 return V4L2_SLICED_VPS;
79 if (line == 23 && field == 0 && (set & V4L2_SLICED_WSS_625))
80 return V4L2_SLICED_WSS_625;
81 if (line == 23)
82 return 0;
83 }
84 for (i = 0; i < 32; i++) {
85 if ((1 << i) & set)
86 return 1 << i;
87 }
88 return 0;
89}
90
Hans Verkuilfeb5bce2008-05-01 09:22:13 -030091void ivtv_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -030092{
93 u16 set = fmt->service_set;
94 int f, l;
95
96 fmt->service_set = 0;
97 for (f = 0; f < 2; f++) {
98 for (l = 0; l < 24; l++) {
99 fmt->service_lines[f][l] = select_service_from_set(f, l, set, is_pal);
100 }
101 }
102}
103
104static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
105{
106 int f, l;
107 u16 set = 0;
108
109 for (f = 0; f < 2; f++) {
110 for (l = 0; l < 24; l++) {
111 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
112 set |= fmt->service_lines[f][l];
113 }
114 }
115 return set != 0;
116}
117
Hans Verkuilfeb5bce2008-05-01 09:22:13 -0300118u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300119{
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
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300131void 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);
Hans Verkuilfd8b2812007-08-23 10:13:15 -0300135 ivtv_vapi(itv, CX2341X_OSD_SET_CHROMA_KEY, 2, itv->osd_chroma_key_state, itv->osd_chroma_key);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300136}
137
138int ivtv_set_speed(struct ivtv *itv, int speed)
139{
140 u32 data[CX2341X_MBOX_MAX_DATA];
141 struct ivtv_stream *s;
142 int single_step = (speed == 1 || speed == -1);
143 DEFINE_WAIT(wait);
144
145 if (speed == 0) speed = 1000;
146
147 /* No change? */
148 if (speed == itv->speed && !single_step)
149 return 0;
150
151 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
152
153 if (single_step && (speed < 0) == (itv->speed < 0)) {
154 /* Single step video and no need to change direction */
155 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
156 itv->speed = speed;
157 return 0;
158 }
159 if (single_step)
160 /* Need to change direction */
161 speed = speed < 0 ? -1000 : 1000;
162
163 data[0] = (speed > 1000 || speed < -1000) ? 0x80000000 : 0;
164 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
165 data[1] = (speed < 0);
166 data[2] = speed < 0 ? 3 : 7;
167 data[3] = itv->params.video_b_frames;
168 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0;
169 data[5] = 0;
170 data[6] = 0;
171
172 if (speed == 1500 || speed == -1500) data[0] |= 1;
173 else if (speed == 2000 || speed == -2000) data[0] |= 2;
174 else if (speed > -1000 && speed < 0) data[0] |= (-1000 / speed);
175 else if (speed < 1000 && speed > 0) data[0] |= (1000 / speed);
176
177 /* If not decoding, just change speed setting */
178 if (atomic_read(&itv->decoding) > 0) {
179 int got_sig = 0;
180
181 /* Stop all DMA and decoding activity */
182 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1, 0);
183
184 /* Wait for any DMA to finish */
185 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
186 while (itv->i_flags & IVTV_F_I_DMA) {
187 got_sig = signal_pending(current);
188 if (got_sig)
189 break;
190 got_sig = 0;
191 schedule();
192 }
193 finish_wait(&itv->dma_waitq, &wait);
194 if (got_sig)
195 return -EINTR;
196
197 /* Change Speed safely */
198 ivtv_api(itv, CX2341X_DEC_SET_PLAYBACK_SPEED, 7, data);
199 IVTV_DEBUG_INFO("Setting Speed to 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
200 data[0], data[1], data[2], data[3], data[4], data[5], data[6]);
201 }
202 if (single_step) {
203 speed = (speed < 0) ? -1 : 1;
204 ivtv_vapi(itv, CX2341X_DEC_STEP_VIDEO, 1, 0);
205 }
206 itv->speed = speed;
207 return 0;
208}
209
210static int ivtv_validate_speed(int cur_speed, int new_speed)
211{
212 int fact = new_speed < 0 ? -1 : 1;
213 int s;
214
Hans Verkuil94dee762008-04-26 09:26:13 -0300215 if (cur_speed == 0)
216 cur_speed = 1000;
217 if (new_speed < 0)
218 new_speed = -new_speed;
219 if (cur_speed < 0)
220 cur_speed = -cur_speed;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300221
222 if (cur_speed <= new_speed) {
Hans Verkuil94dee762008-04-26 09:26:13 -0300223 if (new_speed > 1500)
224 return fact * 2000;
225 if (new_speed > 1000)
226 return fact * 1500;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300227 }
228 else {
Hans Verkuil94dee762008-04-26 09:26:13 -0300229 if (new_speed >= 2000)
230 return fact * 2000;
231 if (new_speed >= 1500)
232 return fact * 1500;
233 if (new_speed >= 1000)
234 return fact * 1000;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300235 }
Hans Verkuil94dee762008-04-26 09:26:13 -0300236 if (new_speed == 0)
237 return 1000;
238 if (new_speed == 1 || new_speed == 1000)
239 return fact * new_speed;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300240
241 s = new_speed;
242 new_speed = 1000 / new_speed;
243 if (1000 / cur_speed == new_speed)
244 new_speed += (cur_speed < s) ? -1 : 1;
245 if (new_speed > 60) return 1000 / (fact * 60);
246 return 1000 / (fact * new_speed);
247}
248
249static int ivtv_video_command(struct ivtv *itv, struct ivtv_open_id *id,
250 struct video_command *vc, int try)
251{
252 struct ivtv_stream *s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
253
254 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
255 return -EINVAL;
256
257 switch (vc->cmd) {
258 case VIDEO_CMD_PLAY: {
Hans Verkuil25415cf2007-03-10 18:29:48 -0300259 vc->flags = 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300260 vc->play.speed = ivtv_validate_speed(itv->speed, vc->play.speed);
261 if (vc->play.speed < 0)
262 vc->play.format = VIDEO_PLAY_FMT_GOP;
263 if (try) break;
264
265 if (ivtv_set_output_mode(itv, OUT_MPG) != OUT_MPG)
266 return -EBUSY;
Hans Verkuilac425142007-07-22 08:46:38 -0300267 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags)) {
268 /* forces ivtv_set_speed to be called */
269 itv->speed = 0;
270 }
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300271 return ivtv_start_decoding(id, vc->play.speed);
272 }
273
274 case VIDEO_CMD_STOP:
Hans Verkuil018ba852007-04-10 18:59:09 -0300275 vc->flags &= VIDEO_CMD_STOP_IMMEDIATELY|VIDEO_CMD_STOP_TO_BLACK;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300276 if (vc->flags & VIDEO_CMD_STOP_IMMEDIATELY)
277 vc->stop.pts = 0;
278 if (try) break;
279 if (atomic_read(&itv->decoding) == 0)
280 return 0;
281 if (itv->output_mode != OUT_MPG)
282 return -EBUSY;
283
284 itv->output_mode = OUT_NONE;
285 return ivtv_stop_v4l2_decode_stream(s, vc->flags, vc->stop.pts);
286
287 case VIDEO_CMD_FREEZE:
Hans Verkuil018ba852007-04-10 18:59:09 -0300288 vc->flags &= VIDEO_CMD_FREEZE_TO_BLACK;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300289 if (try) break;
290 if (itv->output_mode != OUT_MPG)
291 return -EBUSY;
292 if (atomic_read(&itv->decoding) > 0) {
293 ivtv_vapi(itv, CX2341X_DEC_PAUSE_PLAYBACK, 1,
294 (vc->flags & VIDEO_CMD_FREEZE_TO_BLACK) ? 1 : 0);
Hans Verkuilac425142007-07-22 08:46:38 -0300295 set_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300296 }
297 break;
298
299 case VIDEO_CMD_CONTINUE:
Hans Verkuil25415cf2007-03-10 18:29:48 -0300300 vc->flags = 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300301 if (try) break;
302 if (itv->output_mode != OUT_MPG)
303 return -EBUSY;
Hans Verkuilac425142007-07-22 08:46:38 -0300304 if (test_and_clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags)) {
305 int speed = itv->speed;
306 itv->speed = 0;
307 return ivtv_start_decoding(id, speed);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300308 }
309 break;
310
311 default:
312 return -EINVAL;
313 }
314 return 0;
315}
316
Hans Verkuil3f038d82008-05-29 16:43:54 -0300317static int ivtv_g_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300318{
Hans Verkuil3f038d82008-05-29 16:43:54 -0300319 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
320 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300321
Hans Verkuile88360c2008-06-21 08:00:56 -0300322 vbifmt->reserved[0] = 0;
323 vbifmt->reserved[1] = 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300324 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300325 return -EINVAL;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300326 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
327 if (itv->is_60hz) {
328 vbifmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
329 vbifmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
330 } else {
331 vbifmt->service_lines[0][23] = V4L2_SLICED_WSS_625;
332 vbifmt->service_lines[0][16] = V4L2_SLICED_VPS;
333 }
334 vbifmt->service_set = ivtv_get_service_set(vbifmt);
335 return 0;
336}
337
338static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
339{
340 struct ivtv_open_id *id = fh;
341 struct ivtv *itv = id->itv;
Hans Verkuile88360c2008-06-21 08:00:56 -0300342 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300343
Hans Verkuile88360c2008-06-21 08:00:56 -0300344 pixfmt->width = itv->params.width;
345 pixfmt->height = itv->params.height;
346 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
347 pixfmt->field = V4L2_FIELD_INTERLACED;
348 pixfmt->priv = 0;
349 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
350 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300351 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
Hans Verkuile88360c2008-06-21 08:00:56 -0300352 pixfmt->sizeimage =
353 pixfmt->height * pixfmt->width +
354 pixfmt->height * (pixfmt->width / 2);
355 pixfmt->bytesperline = 720;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300356 } else {
Hans Verkuile88360c2008-06-21 08:00:56 -0300357 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
358 pixfmt->sizeimage = 128 * 1024;
359 pixfmt->bytesperline = 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300360 }
361 return 0;
362}
363
Hans Verkuil3f038d82008-05-29 16:43:54 -0300364static int ivtv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300365{
Hans Verkuil3f038d82008-05-29 16:43:54 -0300366 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
Hans Verkuile88360c2008-06-21 08:00:56 -0300367 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300368
Hans Verkuile88360c2008-06-21 08:00:56 -0300369 vbifmt->sampling_rate = 27000000;
370 vbifmt->offset = 248;
371 vbifmt->samples_per_line = itv->vbi.raw_decoder_line_size - 4;
372 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
373 vbifmt->start[0] = itv->vbi.start[0];
374 vbifmt->start[1] = itv->vbi.start[1];
375 vbifmt->count[0] = vbifmt->count[1] = itv->vbi.count;
376 vbifmt->flags = 0;
377 vbifmt->reserved[0] = 0;
378 vbifmt->reserved[1] = 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300379 return 0;
380}
381
382static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
383{
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300384 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300385 struct ivtv_open_id *id = fh;
386 struct ivtv *itv = id->itv;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300387
Hans Verkuile88360c2008-06-21 08:00:56 -0300388 vbifmt->reserved[0] = 0;
389 vbifmt->reserved[1] = 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300390 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300391
Hans Verkuil3f038d82008-05-29 16:43:54 -0300392 if (id->type == IVTV_DEC_STREAM_TYPE_VBI) {
393 vbifmt->service_set = itv->is_50hz ? V4L2_SLICED_VBI_625 :
394 V4L2_SLICED_VBI_525;
395 ivtv_expand_service_set(vbifmt, itv->is_50hz);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300396 return 0;
397 }
398
Hans Verkuil3f038d82008-05-29 16:43:54 -0300399 itv->video_dec_func(itv, VIDIOC_G_FMT, fmt);
400 vbifmt->service_set = ivtv_get_service_set(vbifmt);
401 return 0;
402}
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300403
Hans Verkuil3f038d82008-05-29 16:43:54 -0300404static int ivtv_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
405{
406 struct ivtv_open_id *id = fh;
407 struct ivtv *itv = id->itv;
Hans Verkuile88360c2008-06-21 08:00:56 -0300408 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300409
Hans Verkuil3f038d82008-05-29 16:43:54 -0300410 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300411 return -EINVAL;
Hans Verkuile88360c2008-06-21 08:00:56 -0300412 pixfmt->width = itv->main_rect.width;
413 pixfmt->height = itv->main_rect.height;
414 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
415 pixfmt->field = V4L2_FIELD_INTERLACED;
416 pixfmt->priv = 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300417 if (id->type == IVTV_DEC_STREAM_TYPE_YUV) {
418 switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) {
419 case IVTV_YUV_MODE_INTERLACED:
Hans Verkuile88360c2008-06-21 08:00:56 -0300420 pixfmt->field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ?
Hans Verkuil3f038d82008-05-29 16:43:54 -0300421 V4L2_FIELD_INTERLACED_BT : V4L2_FIELD_INTERLACED_TB;
422 break;
423 case IVTV_YUV_MODE_PROGRESSIVE:
Hans Verkuile88360c2008-06-21 08:00:56 -0300424 pixfmt->field = V4L2_FIELD_NONE;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300425 break;
426 default:
Hans Verkuile88360c2008-06-21 08:00:56 -0300427 pixfmt->field = V4L2_FIELD_ANY;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300428 break;
429 }
Hans Verkuile88360c2008-06-21 08:00:56 -0300430 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
431 pixfmt->bytesperline = 720;
432 pixfmt->width = itv->yuv_info.v4l2_src_w;
433 pixfmt->height = itv->yuv_info.v4l2_src_h;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300434 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */
Hans Verkuile88360c2008-06-21 08:00:56 -0300435 pixfmt->sizeimage =
436 1080 * ((pixfmt->height + 31) & ~31);
Hans Verkuil3f038d82008-05-29 16:43:54 -0300437 } else {
Hans Verkuile88360c2008-06-21 08:00:56 -0300438 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
439 pixfmt->sizeimage = 128 * 1024;
440 pixfmt->bytesperline = 0;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300441 }
442 return 0;
443}
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300444
Hans Verkuil3f038d82008-05-29 16:43:54 -0300445static int ivtv_g_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
446{
447 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
Hans Verkuile88360c2008-06-21 08:00:56 -0300448 struct v4l2_window *winfmt = &fmt->fmt.win;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300449
450 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
451 return -EINVAL;
Hans Verkuile88360c2008-06-21 08:00:56 -0300452 winfmt->chromakey = itv->osd_chroma_key;
453 winfmt->global_alpha = itv->osd_global_alpha;
454 winfmt->field = V4L2_FIELD_INTERLACED;
455 winfmt->clips = NULL;
456 winfmt->clipcount = 0;
457 winfmt->bitmap = NULL;
458 winfmt->w.top = winfmt->w.left = 0;
459 winfmt->w.width = itv->osd_rect.width;
460 winfmt->w.height = itv->osd_rect.height;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300461 return 0;
462}
463
464static int ivtv_try_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
465{
466 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
467}
468
469static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
470{
471 struct ivtv_open_id *id = fh;
472 struct ivtv *itv = id->itv;
473 int w = fmt->fmt.pix.width;
474 int h = fmt->fmt.pix.height;
475
476 w = min(w, 720);
477 w = max(w, 1);
478 h = min(h, itv->is_50hz ? 576 : 480);
479 h = max(h, 2);
480 ivtv_g_fmt_vid_cap(file, fh, fmt);
481 fmt->fmt.pix.width = w;
482 fmt->fmt.pix.height = h;
483 return 0;
484}
485
486static int ivtv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
487{
488 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
489}
490
491static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
492{
493 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
494 struct ivtv_open_id *id = fh;
495 struct ivtv *itv = id->itv;
496
497 if (id->type == IVTV_DEC_STREAM_TYPE_VBI)
498 return ivtv_g_fmt_sliced_vbi_cap(file, fh, fmt);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300499
500 /* set sliced VBI capture format */
501 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
Hans Verkuile88360c2008-06-21 08:00:56 -0300502 vbifmt->reserved[0] = 0;
503 vbifmt->reserved[1] = 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300504
505 if (vbifmt->service_set)
Hans Verkuilfeb5bce2008-05-01 09:22:13 -0300506 ivtv_expand_service_set(vbifmt, itv->is_50hz);
Hans Verkuil3f038d82008-05-29 16:43:54 -0300507 check_service_set(vbifmt, itv->is_50hz);
Hans Verkuilfeb5bce2008-05-01 09:22:13 -0300508 vbifmt->service_set = ivtv_get_service_set(vbifmt);
Hans Verkuil3f038d82008-05-29 16:43:54 -0300509 return 0;
510}
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300511
Hans Verkuil3f038d82008-05-29 16:43:54 -0300512static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
513{
514 struct ivtv_open_id *id = fh;
Hans Verkuileffc3462008-09-06 08:24:37 -0300515 s32 w = fmt->fmt.pix.width;
516 s32 h = fmt->fmt.pix.height;
517 int field = fmt->fmt.pix.field;
518 int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
Hans Verkuil3f038d82008-05-29 16:43:54 -0300519
Hans Verkuil3f038d82008-05-29 16:43:54 -0300520 if (!ret && id->type == IVTV_DEC_STREAM_TYPE_YUV) {
521 fmt->fmt.pix.field = field;
Hans Verkuileffc3462008-09-06 08:24:37 -0300522 w = min(w, 720);
523 w = max(w, 2);
524 h = min(h, 576);
525 h = max(h, 2);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300526 }
Hans Verkuileffc3462008-09-06 08:24:37 -0300527 fmt->fmt.pix.width = w;
528 fmt->fmt.pix.height = h;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300529 return ret;
530}
531
532static int ivtv_try_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
533{
534 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
Hans Verkuile88360c2008-06-21 08:00:56 -0300535 u32 chromakey = fmt->fmt.win.chromakey;
536 u8 global_alpha = fmt->fmt.win.global_alpha;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300537
538 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
539 return -EINVAL;
Hans Verkuile88360c2008-06-21 08:00:56 -0300540 ivtv_g_fmt_vid_out_overlay(file, fh, fmt);
541 fmt->fmt.win.chromakey = chromakey;
542 fmt->fmt.win.global_alpha = global_alpha;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300543 return 0;
544}
545
546static int ivtv_s_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt)
547{
548 return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt);
549}
550
551static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
552{
553 struct ivtv_open_id *id = fh;
554 struct ivtv *itv = id->itv;
555 struct cx2341x_mpeg_params *p = &itv->params;
Hans Verkuileffc3462008-09-06 08:24:37 -0300556 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
Hans Verkuil3f038d82008-05-29 16:43:54 -0300557 int w = fmt->fmt.pix.width;
558 int h = fmt->fmt.pix.height;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300559
560 if (ret)
561 return ret;
562
563 if (p->width == w && p->height == h)
564 return 0;
565
566 if (atomic_read(&itv->capturing) > 0)
567 return -EBUSY;
568
569 p->width = w;
570 p->height = h;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300571 if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
572 fmt->fmt.pix.width /= 2;
573 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
574 return ivtv_g_fmt_vid_cap(file, fh, fmt);
575}
576
577static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
578{
579 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
580
581 itv->vbi.sliced_in->service_set = 0;
582 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in);
583 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
584}
585
586static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt)
587{
588 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
589 struct ivtv_open_id *id = fh;
590 struct ivtv *itv = id->itv;
591 int ret = ivtv_try_fmt_sliced_vbi_cap(file, fh, fmt);
592
593 if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI)
594 return ret;
595
596 if (check_service_set(vbifmt, itv->is_50hz) == 0)
597 return -EINVAL;
598 if (atomic_read(&itv->capturing) > 0)
599 return -EBUSY;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300600 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
601 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
602 return 0;
603}
604
Hans Verkuil3f038d82008-05-29 16:43:54 -0300605static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300606{
Hans Verkuil3f038d82008-05-29 16:43:54 -0300607 struct ivtv_open_id *id = fh;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300608 struct ivtv *itv = id->itv;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300609 struct yuv_playback_info *yi = &itv->yuv_info;
610 int ret = ivtv_try_fmt_vid_out(file, fh, fmt);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300611
Hans Verkuil3f038d82008-05-29 16:43:54 -0300612 if (ret)
613 return ret;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300614
Hans Verkuil3f038d82008-05-29 16:43:54 -0300615 if (id->type != IVTV_DEC_STREAM_TYPE_YUV)
616 return 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300617
Hans Verkuil3f038d82008-05-29 16:43:54 -0300618 /* Return now if we already have some frame data */
619 if (yi->stream_size)
620 return -EBUSY;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300621
Hans Verkuil3f038d82008-05-29 16:43:54 -0300622 yi->v4l2_src_w = fmt->fmt.pix.width;
623 yi->v4l2_src_h = fmt->fmt.pix.height;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300624
Hans Verkuil3f038d82008-05-29 16:43:54 -0300625 switch (fmt->fmt.pix.field) {
626 case V4L2_FIELD_NONE:
627 yi->lace_mode = IVTV_YUV_MODE_PROGRESSIVE;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300628 break;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300629 case V4L2_FIELD_ANY:
630 yi->lace_mode = IVTV_YUV_MODE_AUTO;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300631 break;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300632 case V4L2_FIELD_INTERLACED_BT:
633 yi->lace_mode =
634 IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD;
635 break;
636 case V4L2_FIELD_INTERLACED_TB:
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300637 default:
Hans Verkuil3f038d82008-05-29 16:43:54 -0300638 yi->lace_mode = IVTV_YUV_MODE_INTERLACED;
639 break;
640 }
641 yi->lace_sync_field = (yi->lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1;
642
643 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
644 itv->dma_data_req_size =
645 1080 * ((yi->v4l2_src_h + 31) & ~31);
646
647 /* Force update of yuv registers */
648 yi->yuv_forced_update = 1;
649 return 0;
650}
651
652static int ivtv_s_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt)
653{
654 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
655 int ret = ivtv_try_fmt_vid_out_overlay(file, fh, fmt);
656
657 if (ret == 0) {
658 itv->osd_chroma_key = fmt->fmt.win.chromakey;
659 itv->osd_global_alpha = fmt->fmt.win.global_alpha;
660 ivtv_set_osd_alpha(itv);
661 }
662 return ret;
663}
664
665static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_chip_ident *chip)
666{
667 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
668
669 chip->ident = V4L2_IDENT_NONE;
670 chip->revision = 0;
671 if (chip->match_type == V4L2_CHIP_MATCH_HOST) {
672 if (v4l2_chip_match_host(chip->match_type, chip->match_chip))
673 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416;
674 return 0;
675 }
676 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
677 return ivtv_i2c_id(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip);
678 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR)
679 return ivtv_call_i2c_client(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip);
680 return -EINVAL;
681}
682
Hans Verkuil36ecd492008-06-25 06:00:17 -0300683#ifdef CONFIG_VIDEO_ADV_DEBUG
684static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg)
685{
686 struct v4l2_register *regs = arg;
687 unsigned long flags;
Hans Verkuiladb65bc2008-06-25 06:32:44 -0300688 volatile u8 __iomem *reg_start;
Hans Verkuil36ecd492008-06-25 06:00:17 -0300689
690 if (!capable(CAP_SYS_ADMIN))
691 return -EPERM;
692 if (regs->reg >= IVTV_REG_OFFSET && regs->reg < IVTV_REG_OFFSET + IVTV_REG_SIZE)
693 reg_start = itv->reg_mem - IVTV_REG_OFFSET;
694 else if (itv->has_cx23415 && regs->reg >= IVTV_DECODER_OFFSET &&
695 regs->reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE)
696 reg_start = itv->dec_mem - IVTV_DECODER_OFFSET;
697 else if (regs->reg >= 0 && regs->reg < IVTV_ENCODER_SIZE)
698 reg_start = itv->enc_mem;
699 else
700 return -EINVAL;
701
702 spin_lock_irqsave(&ivtv_cards_lock, flags);
703 if (cmd == VIDIOC_DBG_G_REGISTER)
704 regs->val = readl(regs->reg + reg_start);
705 else
706 writel(regs->val, regs->reg + reg_start);
707 spin_unlock_irqrestore(&ivtv_cards_lock, flags);
708 return 0;
709}
710
Hans Verkuil3f038d82008-05-29 16:43:54 -0300711static int ivtv_g_register(struct file *file, void *fh, struct v4l2_register *reg)
712{
713 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
714
715 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
716 return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg);
717 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
718 return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg);
719 return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg);
720}
721
722static int ivtv_s_register(struct file *file, void *fh, struct v4l2_register *reg)
723{
724 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
725
726 if (v4l2_chip_match_host(reg->match_type, reg->match_chip))
727 return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg);
728 if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER)
729 return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg);
730 return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg);
731}
Hans Verkuil36ecd492008-06-25 06:00:17 -0300732#endif
Hans Verkuil3f038d82008-05-29 16:43:54 -0300733
734static int ivtv_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
735{
736 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
737
738 *p = v4l2_prio_max(&itv->prio);
739
740 return 0;
741}
742
743static int ivtv_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
744{
745 struct ivtv_open_id *id = fh;
746 struct ivtv *itv = id->itv;
747
748 return v4l2_prio_change(&itv->prio, &id->prio, prio);
749}
750
751static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vcap)
752{
753 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
754
Hans Verkuil3f038d82008-05-29 16:43:54 -0300755 strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
756 strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
757 strlcpy(vcap->bus_info, pci_name(itv->dev), sizeof(vcap->bus_info));
758 vcap->version = IVTV_DRIVER_VERSION; /* version */
759 vcap->capabilities = itv->v4l2_cap; /* capabilities */
Hans Verkuil3f038d82008-05-29 16:43:54 -0300760 return 0;
761}
762
763static int ivtv_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin)
764{
765 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
766
767 return ivtv_get_audio_input(itv, vin->index, vin);
768}
769
770static int ivtv_g_audio(struct file *file, void *fh, struct v4l2_audio *vin)
771{
772 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
773
774 vin->index = itv->audio_input;
775 return ivtv_get_audio_input(itv, vin->index, vin);
776}
777
778static int ivtv_s_audio(struct file *file, void *fh, struct v4l2_audio *vout)
779{
780 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
781
782 if (vout->index >= itv->nof_audio_inputs)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -0300783 return -EINVAL;
Hans Verkuil3f038d82008-05-29 16:43:54 -0300784
785 itv->audio_input = vout->index;
786 ivtv_audio_set_io(itv);
787
788 return 0;
789}
790
791static int ivtv_enumaudout(struct file *file, void *fh, struct v4l2_audioout *vin)
792{
793 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
794
795 /* set it to defaults from our table */
796 return ivtv_get_audio_output(itv, vin->index, vin);
797}
798
799static int ivtv_g_audout(struct file *file, void *fh, struct v4l2_audioout *vin)
800{
801 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
802
803 vin->index = 0;
804 return ivtv_get_audio_output(itv, vin->index, vin);
805}
806
807static int ivtv_s_audout(struct file *file, void *fh, struct v4l2_audioout *vout)
808{
809 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
810
811 return ivtv_get_audio_output(itv, vout->index, vout);
812}
813
814static int ivtv_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
815{
816 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
817
818 /* set it to defaults from our table */
819 return ivtv_get_input(itv, vin->index, vin);
820}
821
822static int ivtv_enum_output(struct file *file, void *fh, struct v4l2_output *vout)
823{
824 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
825
826 return ivtv_get_output(itv, vout->index, vout);
827}
828
829static int ivtv_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap)
830{
831 struct ivtv_open_id *id = fh;
832 struct ivtv *itv = id->itv;
833 struct yuv_playback_info *yi = &itv->yuv_info;
834 int streamtype;
835
836 streamtype = id->type;
837
838 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
839 return -EINVAL;
840 cropcap->bounds.top = cropcap->bounds.left = 0;
841 cropcap->bounds.width = 720;
842 if (cropcap->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
843 cropcap->bounds.height = itv->is_50hz ? 576 : 480;
844 cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10;
845 cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11;
846 } else if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
847 if (yi->track_osd) {
848 cropcap->bounds.width = yi->osd_full_w;
849 cropcap->bounds.height = yi->osd_full_h;
850 } else {
851 cropcap->bounds.width = 720;
852 cropcap->bounds.height =
853 itv->is_out_50hz ? 576 : 480;
854 }
855 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10;
856 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11;
857 } else {
858 cropcap->bounds.height = itv->is_out_50hz ? 576 : 480;
859 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10;
860 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11;
861 }
862 cropcap->defrect = cropcap->bounds;
863 return 0;
864}
865
866static int ivtv_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
867{
868 struct ivtv_open_id *id = fh;
869 struct ivtv *itv = id->itv;
870 struct yuv_playback_info *yi = &itv->yuv_info;
871 int streamtype;
872
873 streamtype = id->type;
874
875 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
876 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
877 /* Should be replaced */
878 /* v4l_printk_ioctl(VIDIOC_S_CROP); */
879 }
880
881 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
882 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
883 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
884 yi->main_rect = crop->c;
885 return 0;
886 } else {
887 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
888 crop->c.width, crop->c.height, crop->c.left, crop->c.top)) {
889 itv->main_rect = crop->c;
890 return 0;
891 }
892 }
893 return -EINVAL;
894 }
895 return -EINVAL;
896}
897
898static int ivtv_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
899{
900 struct ivtv_open_id *id = fh;
901 struct ivtv *itv = id->itv;
902 struct yuv_playback_info *yi = &itv->yuv_info;
903 int streamtype;
904
905 streamtype = id->type;
906
907 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
908 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
909 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV)
910 crop->c = yi->main_rect;
911 else
912 crop->c = itv->main_rect;
913 return 0;
914 }
915 return -EINVAL;
916}
917
918static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
919{
920 static struct v4l2_fmtdesc formats[] = {
921 { 0, 0, 0,
922 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
923 { 0, 0, 0, 0 }
924 },
925 { 1, 0, V4L2_FMT_FLAG_COMPRESSED,
926 "MPEG", V4L2_PIX_FMT_MPEG,
927 { 0, 0, 0, 0 }
928 }
929 };
930 enum v4l2_buf_type type = fmt->type;
931
932 if (fmt->index > 1)
933 return -EINVAL;
934
935 *fmt = formats[fmt->index];
936 fmt->type = type;
937 return 0;
938}
939
940static int ivtv_enum_fmt_vid_out(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
941{
942 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
943
944 static struct v4l2_fmtdesc formats[] = {
945 { 0, 0, 0,
946 "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12,
947 { 0, 0, 0, 0 }
948 },
949 { 1, 0, V4L2_FMT_FLAG_COMPRESSED,
950 "MPEG", V4L2_PIX_FMT_MPEG,
951 { 0, 0, 0, 0 }
952 }
953 };
954 enum v4l2_buf_type type = fmt->type;
955
956 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
957 return -EINVAL;
958
959 if (fmt->index > 1)
960 return -EINVAL;
961
962 *fmt = formats[fmt->index];
963 fmt->type = type;
964
965 return 0;
966}
967
968static int ivtv_g_input(struct file *file, void *fh, unsigned int *i)
969{
970 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
971
972 *i = itv->active_input;
973
974 return 0;
975}
976
977int ivtv_s_input(struct file *file, void *fh, unsigned int inp)
978{
979 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
980
981 if (inp < 0 || inp >= itv->nof_inputs)
982 return -EINVAL;
983
984 if (inp == itv->active_input) {
985 IVTV_DEBUG_INFO("Input unchanged\n");
986 return 0;
987 }
988
989 if (atomic_read(&itv->capturing) > 0) {
990 return -EBUSY;
991 }
992
993 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
994 itv->active_input, inp);
995
996 itv->active_input = inp;
997 /* Set the audio input to whatever is appropriate for the
998 input type. */
999 itv->audio_input = itv->card->video_inputs[inp].audio_index;
1000
1001 /* prevent others from messing with the streams until
1002 we're finished changing inputs. */
1003 ivtv_mute(itv);
1004 ivtv_video_set_io(itv);
1005 ivtv_audio_set_io(itv);
1006 ivtv_unmute(itv);
1007
1008 return 0;
1009}
1010
1011static int ivtv_g_output(struct file *file, void *fh, unsigned int *i)
1012{
1013 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1014
1015 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1016 return -EINVAL;
1017
1018 *i = itv->active_output;
1019
1020 return 0;
1021}
1022
1023static int ivtv_s_output(struct file *file, void *fh, unsigned int outp)
1024{
1025 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1026 struct v4l2_routing route;
1027
1028 if (outp >= itv->card->nof_outputs)
1029 return -EINVAL;
1030
1031 if (outp == itv->active_output) {
1032 IVTV_DEBUG_INFO("Output unchanged\n");
1033 return 0;
1034 }
1035 IVTV_DEBUG_INFO("Changing output from %d to %d\n",
1036 itv->active_output, outp);
1037
1038 itv->active_output = outp;
1039 route.input = SAA7127_INPUT_TYPE_NORMAL;
1040 route.output = itv->card->video_outputs[outp].video_output;
1041 ivtv_saa7127(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
1042
1043 return 0;
1044}
1045
1046static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1047{
1048 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1049
1050 if (vf->tuner != 0)
1051 return -EINVAL;
1052
1053 ivtv_call_i2c_clients(itv, VIDIOC_G_FREQUENCY, vf);
1054 return 0;
1055}
1056
1057int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
1058{
1059 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1060
1061 if (vf->tuner != 0)
1062 return -EINVAL;
1063
1064 ivtv_mute(itv);
1065 IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
1066 ivtv_call_i2c_clients(itv, VIDIOC_S_FREQUENCY, vf);
1067 ivtv_unmute(itv);
1068 return 0;
1069}
1070
1071static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std)
1072{
1073 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1074
1075 *std = itv->std;
1076 return 0;
1077}
1078
1079int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1080{
1081 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1082 struct yuv_playback_info *yi = &itv->yuv_info;
1083
1084 if ((*std & V4L2_STD_ALL) == 0)
1085 return -EINVAL;
1086
1087 if (*std == itv->std)
1088 return 0;
1089
1090 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ||
1091 atomic_read(&itv->capturing) > 0 ||
1092 atomic_read(&itv->decoding) > 0) {
1093 /* Switching standard would turn off the radio or mess
1094 with already running streams, prevent that by
1095 returning EBUSY. */
1096 return -EBUSY;
1097 }
1098
1099 itv->std = *std;
1100 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
1101 itv->params.is_50hz = itv->is_50hz = !itv->is_60hz;
1102 itv->params.width = 720;
1103 itv->params.height = itv->is_50hz ? 576 : 480;
1104 itv->vbi.count = itv->is_50hz ? 18 : 12;
1105 itv->vbi.start[0] = itv->is_50hz ? 6 : 10;
1106 itv->vbi.start[1] = itv->is_50hz ? 318 : 273;
1107
1108 if (itv->hw_flags & IVTV_HW_CX25840)
1109 itv->vbi.sliced_decoder_line_size = itv->is_60hz ? 272 : 284;
1110
1111 IVTV_DEBUG_INFO("Switching standard to %llx.\n", (unsigned long long)itv->std);
1112
1113 /* Tuner */
1114 ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std);
1115
1116 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1117 /* set display standard */
1118 itv->std_out = *std;
1119 itv->is_out_60hz = itv->is_60hz;
1120 itv->is_out_50hz = itv->is_50hz;
1121 ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std_out);
1122 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1123 itv->main_rect.left = itv->main_rect.top = 0;
1124 itv->main_rect.width = 720;
1125 itv->main_rect.height = itv->params.height;
1126 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1127 720, itv->main_rect.height, 0, 0);
1128 yi->main_rect = itv->main_rect;
1129 if (!itv->osd_info) {
1130 yi->osd_full_w = 720;
1131 yi->osd_full_h = itv->is_out_50hz ? 576 : 480;
1132 }
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001133 }
1134 return 0;
1135}
1136
Hans Verkuil3f038d82008-05-29 16:43:54 -03001137static int ivtv_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001138{
Hans Verkuil3f038d82008-05-29 16:43:54 -03001139 struct ivtv_open_id *id = fh;
1140 struct ivtv *itv = id->itv;
1141
1142 if (vt->index != 0)
1143 return -EINVAL;
1144
1145 ivtv_call_i2c_clients(itv, VIDIOC_S_TUNER, vt);
1146
1147 return 0;
1148}
1149
1150static int ivtv_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
1151{
1152 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1153
1154 if (vt->index != 0)
1155 return -EINVAL;
1156
Hans Verkuil3f038d82008-05-29 16:43:54 -03001157 ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, vt);
1158
1159 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
1160 strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name));
1161 vt->type = V4L2_TUNER_RADIO;
1162 } else {
1163 strlcpy(vt->name, "ivtv TV Tuner", sizeof(vt->name));
1164 vt->type = V4L2_TUNER_ANALOG_TV;
1165 }
1166
1167 return 0;
1168}
1169
1170static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced_vbi_cap *cap)
1171{
1172 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1173 int set = itv->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
1174 int f, l;
Hans Verkuil3f038d82008-05-29 16:43:54 -03001175
Hans Verkuil79afcb12008-06-21 09:02:36 -03001176 if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
Hans Verkuil3f038d82008-05-29 16:43:54 -03001177 for (f = 0; f < 2; f++) {
1178 for (l = 0; l < 24; l++) {
1179 if (valid_service_line(f, l, itv->is_50hz))
1180 cap->service_lines[f][l] = set;
1181 }
1182 }
1183 return 0;
1184 }
Hans Verkuil79afcb12008-06-21 09:02:36 -03001185 if (cap->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
Hans Verkuil3f038d82008-05-29 16:43:54 -03001186 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT))
1187 return -EINVAL;
1188 if (itv->is_60hz) {
1189 cap->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
1190 cap->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
1191 } else {
1192 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
1193 cap->service_lines[0][16] = V4L2_SLICED_VPS;
1194 }
1195 return 0;
1196 }
1197 return -EINVAL;
1198}
1199
1200static int ivtv_g_enc_index(struct file *file, void *fh, struct v4l2_enc_idx *idx)
1201{
1202 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1203 struct v4l2_enc_idx_entry *e = idx->entry;
1204 int entries;
1205 int i;
1206
1207 entries = (itv->pgm_info_write_idx + IVTV_MAX_PGM_INDEX - itv->pgm_info_read_idx) %
1208 IVTV_MAX_PGM_INDEX;
1209 if (entries > V4L2_ENC_IDX_ENTRIES)
1210 entries = V4L2_ENC_IDX_ENTRIES;
1211 idx->entries = 0;
1212 for (i = 0; i < entries; i++) {
1213 *e = itv->pgm_info[(itv->pgm_info_read_idx + i) % IVTV_MAX_PGM_INDEX];
1214 if ((e->flags & V4L2_ENC_IDX_FRAME_MASK) <= V4L2_ENC_IDX_FRAME_B) {
1215 idx->entries++;
1216 e++;
1217 }
1218 }
1219 itv->pgm_info_read_idx = (itv->pgm_info_read_idx + idx->entries) % IVTV_MAX_PGM_INDEX;
1220 return 0;
1221}
1222
1223static int ivtv_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1224{
1225 struct ivtv_open_id *id = fh;
1226 struct ivtv *itv = id->itv;
1227
Hans Verkuil3f038d82008-05-29 16:43:54 -03001228
1229 switch (enc->cmd) {
1230 case V4L2_ENC_CMD_START:
1231 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1232 enc->flags = 0;
1233 return ivtv_start_capture(id);
1234
1235 case V4L2_ENC_CMD_STOP:
1236 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1237 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1238 ivtv_stop_capture(id, enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END);
1239 return 0;
1240
1241 case V4L2_ENC_CMD_PAUSE:
1242 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1243 enc->flags = 0;
1244
1245 if (!atomic_read(&itv->capturing))
1246 return -EPERM;
1247 if (test_and_set_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1248 return 0;
1249
1250 ivtv_mute(itv);
1251 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 0);
1252 break;
1253
1254 case V4L2_ENC_CMD_RESUME:
1255 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1256 enc->flags = 0;
1257
1258 if (!atomic_read(&itv->capturing))
1259 return -EPERM;
1260
1261 if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags))
1262 return 0;
1263
1264 ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1);
1265 ivtv_unmute(itv);
1266 break;
1267 default:
1268 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1269 return -EINVAL;
1270 }
1271
1272 return 0;
1273}
1274
1275static int ivtv_try_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc)
1276{
1277 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1278
Hans Verkuil3f038d82008-05-29 16:43:54 -03001279 switch (enc->cmd) {
1280 case V4L2_ENC_CMD_START:
1281 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1282 enc->flags = 0;
1283 return 0;
1284
1285 case V4L2_ENC_CMD_STOP:
1286 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1287 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1288 return 0;
1289
1290 case V4L2_ENC_CMD_PAUSE:
1291 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1292 enc->flags = 0;
1293 return 0;
1294
1295 case V4L2_ENC_CMD_RESUME:
1296 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1297 enc->flags = 0;
1298 return 0;
1299 default:
1300 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1301 return -EINVAL;
1302 }
1303}
1304
1305static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1306{
1307 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
Hans Verkuil2d4d5f12007-08-23 21:15:24 -03001308 u32 data[CX2341X_MBOX_MAX_DATA];
Hans Verkuil3f038d82008-05-29 16:43:54 -03001309 struct yuv_playback_info *yi = &itv->yuv_info;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001310
Hans Verkuil3f038d82008-05-29 16:43:54 -03001311 int pixfmt;
1312 static u32 pixel_format[16] = {
1313 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry RGB colormap */
1314 V4L2_PIX_FMT_RGB565,
1315 V4L2_PIX_FMT_RGB555,
1316 V4L2_PIX_FMT_RGB444,
1317 V4L2_PIX_FMT_RGB32,
1318 0,
1319 0,
1320 0,
1321 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry YUV colormap */
1322 V4L2_PIX_FMT_YUV565,
1323 V4L2_PIX_FMT_YUV555,
1324 V4L2_PIX_FMT_YUV444,
1325 V4L2_PIX_FMT_YUV32,
1326 0,
1327 0,
1328 0,
1329 };
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001330
Hans Verkuil3f038d82008-05-29 16:43:54 -03001331 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1332 return -EINVAL;
Hans Verkuil37f89f92008-06-22 11:57:31 -03001333 if (!itv->osd_video_pbase)
1334 return -EINVAL;
Hans Verkuild46c17d2007-03-10 17:59:15 -03001335
Hans Verkuil3f038d82008-05-29 16:43:54 -03001336 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY |
1337 V4L2_FBUF_CAP_GLOBAL_ALPHA;
Hans Verkuild46c17d2007-03-10 17:59:15 -03001338
Hans Verkuil3f038d82008-05-29 16:43:54 -03001339 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1340 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1341 pixfmt = (data[0] >> 3) & 0xf;
Hans Verkuild46c17d2007-03-10 17:59:15 -03001342
Hans Verkuil3f038d82008-05-29 16:43:54 -03001343 fb->fmt.pixelformat = pixel_format[pixfmt];
1344 fb->fmt.width = itv->osd_rect.width;
1345 fb->fmt.height = itv->osd_rect.height;
Hans Verkuil5cf2cc42008-06-21 09:06:59 -03001346 fb->fmt.field = V4L2_FIELD_INTERLACED;
1347 fb->fmt.bytesperline = fb->fmt.width;
Hans Verkuil37f89f92008-06-22 11:57:31 -03001348 fb->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
1349 fb->fmt.field = V4L2_FIELD_INTERLACED;
1350 fb->fmt.priv = 0;
Hans Verkuil5cf2cc42008-06-21 09:06:59 -03001351 if (fb->fmt.pixelformat != V4L2_PIX_FMT_PAL8)
1352 fb->fmt.bytesperline *= 2;
1353 if (fb->fmt.pixelformat == V4L2_PIX_FMT_RGB32 ||
1354 fb->fmt.pixelformat == V4L2_PIX_FMT_YUV32)
1355 fb->fmt.bytesperline *= 2;
Hans Verkuil37f89f92008-06-22 11:57:31 -03001356 fb->fmt.sizeimage = fb->fmt.bytesperline * fb->fmt.height;
Hans Verkuil3f038d82008-05-29 16:43:54 -03001357 fb->base = (void *)itv->osd_video_pbase;
Hans Verkuil5cf2cc42008-06-21 09:06:59 -03001358 fb->flags = 0;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001359
Hans Verkuil3f038d82008-05-29 16:43:54 -03001360 if (itv->osd_chroma_key_state)
1361 fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001362
Hans Verkuil3f038d82008-05-29 16:43:54 -03001363 if (itv->osd_global_alpha_state)
1364 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001365
Hans Verkuil3f038d82008-05-29 16:43:54 -03001366 pixfmt &= 7;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001367
Hans Verkuil3f038d82008-05-29 16:43:54 -03001368 /* no local alpha for RGB565 or unknown formats */
1369 if (pixfmt == 1 || pixfmt > 4)
Hans Verkuil987e00b2007-05-29 13:03:27 -03001370 return 0;
Hans Verkuil987e00b2007-05-29 13:03:27 -03001371
Hans Verkuil3f038d82008-05-29 16:43:54 -03001372 /* 16-bit formats have inverted local alpha */
1373 if (pixfmt == 2 || pixfmt == 3)
1374 fb->capability |= V4L2_FBUF_CAP_LOCAL_INV_ALPHA;
1375 else
1376 fb->capability |= V4L2_FBUF_CAP_LOCAL_ALPHA;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001377
Hans Verkuil3f038d82008-05-29 16:43:54 -03001378 if (itv->osd_local_alpha_state) {
Hans Verkuil2d4d5f12007-08-23 21:15:24 -03001379 /* 16-bit formats have inverted local alpha */
1380 if (pixfmt == 2 || pixfmt == 3)
Hans Verkuil3f038d82008-05-29 16:43:54 -03001381 fb->flags |= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA;
Hans Verkuil2d4d5f12007-08-23 21:15:24 -03001382 else
Hans Verkuil3f038d82008-05-29 16:43:54 -03001383 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
Hans Verkuild4e7ee32007-03-10 18:19:12 -03001384 }
Hans Verkuil3f038d82008-05-29 16:43:54 -03001385 if (yi->track_osd)
1386 fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
Hans Verkuild4e7ee32007-03-10 18:19:12 -03001387
Hans Verkuil3f038d82008-05-29 16:43:54 -03001388 return 0;
1389}
Hans Verkuild4e7ee32007-03-10 18:19:12 -03001390
Hans Verkuil3f038d82008-05-29 16:43:54 -03001391static int ivtv_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1392{
1393 struct ivtv_open_id *id = fh;
1394 struct ivtv *itv = id->itv;
1395 struct yuv_playback_info *yi = &itv->yuv_info;
Hans Verkuild4e7ee32007-03-10 18:19:12 -03001396
Hans Verkuil3f038d82008-05-29 16:43:54 -03001397 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001398 return -EINVAL;
Hans Verkuil37f89f92008-06-22 11:57:31 -03001399 if (!itv->osd_video_pbase)
1400 return -EINVAL;
Hans Verkuil3f038d82008-05-29 16:43:54 -03001401
1402 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0;
1403 itv->osd_local_alpha_state =
1404 (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0;
1405 itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
1406 ivtv_set_osd_alpha(itv);
1407 yi->track_osd = (fb->flags & V4L2_FBUF_FLAG_OVERLAY) != 0;
Hans Verkuil5cf2cc42008-06-21 09:06:59 -03001408 return ivtv_g_fbuf(file, fh, fb);
Hans Verkuil3f038d82008-05-29 16:43:54 -03001409}
1410
1411static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
1412{
1413 struct ivtv_open_id *id = fh;
1414 struct ivtv *itv = id->itv;
1415
1416 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1417 return -EINVAL;
1418
1419 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, on != 0);
1420
1421 return 0;
1422}
1423
1424static int ivtv_log_status(struct file *file, void *fh)
1425{
1426 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
1427 u32 data[CX2341X_MBOX_MAX_DATA];
1428
1429 int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT;
1430 struct v4l2_input vidin;
1431 struct v4l2_audio audin;
1432 int i;
1433
1434 IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num);
1435 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name);
1436 if (itv->hw_flags & IVTV_HW_TVEEPROM) {
1437 struct tveeprom tv;
1438
1439 ivtv_read_eeprom(itv, &tv);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001440 }
Hans Verkuil3f038d82008-05-29 16:43:54 -03001441 ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL);
1442 ivtv_get_input(itv, itv->active_input, &vidin);
1443 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1444 IVTV_INFO("Video Input: %s\n", vidin.name);
1445 IVTV_INFO("Audio Input: %s%s\n", audin.name,
1446 (itv->dualwatch_stereo_mode & ~0x300) == 0x200 ? " (Bilingual)" : "");
1447 if (has_output) {
1448 struct v4l2_output vidout;
1449 struct v4l2_audioout audout;
1450 int mode = itv->output_mode;
1451 static const char * const output_modes[5] = {
1452 "None",
1453 "MPEG Streaming",
1454 "YUV Streaming",
1455 "YUV Frames",
1456 "Passthrough",
1457 };
1458 static const char * const audio_modes[5] = {
1459 "Stereo",
1460 "Left",
1461 "Right",
1462 "Mono",
1463 "Swapped"
1464 };
1465 static const char * const alpha_mode[4] = {
1466 "None",
1467 "Global",
1468 "Local",
1469 "Global and Local"
1470 };
1471 static const char * const pixel_format[16] = {
1472 "ARGB Indexed",
1473 "RGB 5:6:5",
1474 "ARGB 1:5:5:5",
1475 "ARGB 1:4:4:4",
1476 "ARGB 8:8:8:8",
1477 "5",
1478 "6",
1479 "7",
1480 "AYUV Indexed",
1481 "YUV 5:6:5",
1482 "AYUV 1:5:5:5",
1483 "AYUV 1:4:4:4",
1484 "AYUV 8:8:8:8",
1485 "13",
1486 "14",
1487 "15",
1488 };
1489
1490 ivtv_get_output(itv, itv->active_output, &vidout);
1491 ivtv_get_audio_output(itv, 0, &audout);
1492 IVTV_INFO("Video Output: %s\n", vidout.name);
1493 IVTV_INFO("Audio Output: %s (Stereo/Bilingual: %s/%s)\n", audout.name,
1494 audio_modes[itv->audio_stereo_mode],
1495 audio_modes[itv->audio_bilingual_mode]);
1496 if (mode < 0 || mode > OUT_PASSTHROUGH)
1497 mode = OUT_NONE;
1498 IVTV_INFO("Output Mode: %s\n", output_modes[mode]);
1499 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1500 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1501 IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1502 data[0] & 1 ? "On" : "Off",
1503 alpha_mode[(data[0] >> 1) & 0x3],
1504 pixel_format[(data[0] >> 3) & 0xf]);
1505 }
1506 IVTV_INFO("Tuner: %s\n",
1507 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1508 cx2341x_log_status(&itv->params, itv->name);
1509 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1510 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1511 struct ivtv_stream *s = &itv->streams[i];
1512
1513 if (s->v4l2dev == NULL || s->buffers == 0)
1514 continue;
1515 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags,
1516 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
1517 (s->buffers * s->buf_size) / 1024, s->buffers);
1518 }
1519
1520 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n", (long long)itv->mpg_data_received, (long long)itv->vbi_data_inserted);
1521 IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num);
1522
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001523 return 0;
1524}
1525
Hans Verkuild4e7ee32007-03-10 18:19:12 -03001526static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001527{
1528 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1529 struct ivtv *itv = id->itv;
1530 int nonblocking = filp->f_flags & O_NONBLOCK;
1531 struct ivtv_stream *s = &itv->streams[id->type];
1532
1533 switch (cmd) {
1534 case IVTV_IOC_DMA_FRAME: {
1535 struct ivtv_dma_frame *args = arg;
1536
1537 IVTV_DEBUG_IOCTL("IVTV_IOC_DMA_FRAME\n");
1538 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1539 return -EINVAL;
1540 if (args->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
1541 return -EINVAL;
1542 if (itv->output_mode == OUT_UDMA_YUV && args->y_source == NULL)
1543 return 0;
Ian Armstrong42b03fe2008-06-21 11:09:46 -03001544 if (ivtv_start_decoding(id, id->type)) {
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001545 return -EBUSY;
1546 }
1547 if (ivtv_set_output_mode(itv, OUT_UDMA_YUV) != OUT_UDMA_YUV) {
1548 ivtv_release_stream(s);
1549 return -EBUSY;
1550 }
Hans Verkuilad8ff0f2007-08-20 16:01:58 -03001551 /* Mark that this file handle started the UDMA_YUV mode */
1552 id->yuv_frames = 1;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001553 if (args->y_source == NULL)
1554 return 0;
1555 return ivtv_yuv_prep_frame(itv, args);
1556 }
1557
1558 case VIDEO_GET_PTS: {
1559 u32 data[CX2341X_MBOX_MAX_DATA];
1560 u64 *pts = arg;
1561
1562 IVTV_DEBUG_IOCTL("VIDEO_GET_PTS\n");
1563 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1564 *pts = s->dma_pts;
1565 break;
1566 }
1567 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1568 return -EINVAL;
1569
1570 if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
1571 *pts = (u64) ((u64)itv->last_dec_timing[2] << 32) |
1572 (u64)itv->last_dec_timing[1];
1573 break;
1574 }
1575 *pts = 0;
1576 if (atomic_read(&itv->decoding)) {
1577 if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
1578 IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
1579 return -EIO;
1580 }
1581 memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
1582 set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
1583 *pts = (u64) ((u64) data[2] << 32) | (u64) data[1];
1584 /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/
1585 }
1586 break;
1587 }
1588
1589 case VIDEO_GET_FRAME_COUNT: {
1590 u32 data[CX2341X_MBOX_MAX_DATA];
1591 u64 *frame = arg;
1592
1593 IVTV_DEBUG_IOCTL("VIDEO_GET_FRAME_COUNT\n");
1594 if (s->type < IVTV_DEC_STREAM_TYPE_MPG) {
1595 *frame = 0;
1596 break;
1597 }
1598 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1599 return -EINVAL;
1600
1601 if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) {
1602 *frame = itv->last_dec_timing[0];
1603 break;
1604 }
1605 *frame = 0;
1606 if (atomic_read(&itv->decoding)) {
1607 if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) {
1608 IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n");
1609 return -EIO;
1610 }
1611 memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing));
1612 set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
1613 *frame = data[0];
1614 }
1615 break;
1616 }
1617
1618 case VIDEO_PLAY: {
1619 struct video_command vc;
1620
1621 IVTV_DEBUG_IOCTL("VIDEO_PLAY\n");
1622 memset(&vc, 0, sizeof(vc));
1623 vc.cmd = VIDEO_CMD_PLAY;
1624 return ivtv_video_command(itv, id, &vc, 0);
1625 }
1626
1627 case VIDEO_STOP: {
1628 struct video_command vc;
1629
1630 IVTV_DEBUG_IOCTL("VIDEO_STOP\n");
1631 memset(&vc, 0, sizeof(vc));
1632 vc.cmd = VIDEO_CMD_STOP;
1633 vc.flags = VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY;
1634 return ivtv_video_command(itv, id, &vc, 0);
1635 }
1636
1637 case VIDEO_FREEZE: {
1638 struct video_command vc;
1639
1640 IVTV_DEBUG_IOCTL("VIDEO_FREEZE\n");
1641 memset(&vc, 0, sizeof(vc));
1642 vc.cmd = VIDEO_CMD_FREEZE;
1643 return ivtv_video_command(itv, id, &vc, 0);
1644 }
1645
1646 case VIDEO_CONTINUE: {
1647 struct video_command vc;
1648
1649 IVTV_DEBUG_IOCTL("VIDEO_CONTINUE\n");
1650 memset(&vc, 0, sizeof(vc));
1651 vc.cmd = VIDEO_CMD_CONTINUE;
1652 return ivtv_video_command(itv, id, &vc, 0);
1653 }
1654
1655 case VIDEO_COMMAND:
1656 case VIDEO_TRY_COMMAND: {
1657 struct video_command *vc = arg;
1658 int try = (cmd == VIDEO_TRY_COMMAND);
1659
1660 if (try)
Hans Verkuil1aa32c22007-08-19 06:08:58 -03001661 IVTV_DEBUG_IOCTL("VIDEO_TRY_COMMAND %d\n", vc->cmd);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001662 else
Hans Verkuil1aa32c22007-08-19 06:08:58 -03001663 IVTV_DEBUG_IOCTL("VIDEO_COMMAND %d\n", vc->cmd);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001664 return ivtv_video_command(itv, id, vc, try);
1665 }
1666
1667 case VIDEO_GET_EVENT: {
1668 struct video_event *ev = arg;
1669 DEFINE_WAIT(wait);
1670
1671 IVTV_DEBUG_IOCTL("VIDEO_GET_EVENT\n");
1672 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1673 return -EINVAL;
1674 memset(ev, 0, sizeof(*ev));
1675 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
1676
1677 while (1) {
1678 if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
1679 ev->type = VIDEO_EVENT_DECODER_STOPPED;
1680 else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags)) {
1681 ev->type = VIDEO_EVENT_VSYNC;
Hans Verkuil037c86c2007-03-10 06:30:19 -03001682 ev->u.vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ?
1683 VIDEO_VSYNC_FIELD_ODD : VIDEO_VSYNC_FIELD_EVEN;
1684 if (itv->output_mode == OUT_UDMA_YUV &&
1685 (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) ==
1686 IVTV_YUV_MODE_PROGRESSIVE) {
1687 ev->u.vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE;
1688 }
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001689 }
1690 if (ev->type)
1691 return 0;
1692 if (nonblocking)
1693 return -EAGAIN;
Hans Verkuilbaa40722007-08-19 07:10:55 -03001694 /* Wait for event. Note that serialize_lock is locked,
1695 so to allow other processes to access the driver while
1696 we are waiting unlock first and later lock again. */
1697 mutex_unlock(&itv->serialize_lock);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001698 prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE);
1699 if ((itv->i_flags & (IVTV_F_I_EV_DEC_STOPPED|IVTV_F_I_EV_VSYNC)) == 0)
1700 schedule();
1701 finish_wait(&itv->event_waitq, &wait);
Hans Verkuilbaa40722007-08-19 07:10:55 -03001702 mutex_lock(&itv->serialize_lock);
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001703 if (signal_pending(current)) {
1704 /* return if a signal was received */
1705 IVTV_DEBUG_INFO("User stopped wait for event\n");
1706 return -EINTR;
1707 }
1708 }
1709 break;
1710 }
1711
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001712 default:
1713 return -EINVAL;
1714 }
1715 return 0;
1716}
1717
Hans Verkuil3f038d82008-05-29 16:43:54 -03001718static int ivtv_default(struct file *file, void *fh, int cmd, void *arg)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001719{
Hans Verkuil3f038d82008-05-29 16:43:54 -03001720 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001721
Hans Verkuild46c17d2007-03-10 17:59:15 -03001722 switch (cmd) {
Hans Verkuil3f038d82008-05-29 16:43:54 -03001723 case VIDIOC_INT_S_AUDIO_ROUTING: {
1724 struct v4l2_routing *route = arg;
1725
1726 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, route);
1727 break;
Hans Verkuild46c17d2007-03-10 17:59:15 -03001728 }
1729
Hans Verkuil3f038d82008-05-29 16:43:54 -03001730 case VIDIOC_INT_RESET: {
1731 u32 val = *(u32 *)arg;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001732
Hans Verkuil3f038d82008-05-29 16:43:54 -03001733 if ((val == 0 && itv->options.newi2c) || (val & 0x01))
1734 ivtv_reset_ir_gpio(itv);
1735 if (val & 0x02)
1736 itv->video_dec_func(itv, cmd, NULL);
1737 break;
1738 }
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001739
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001740 default:
Hans Verkuil3f038d82008-05-29 16:43:54 -03001741 return -EINVAL;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001742 }
1743 return 0;
1744}
1745
Hans Verkuilbaa40722007-08-19 07:10:55 -03001746static int ivtv_serialized_ioctl(struct ivtv *itv, struct inode *inode, struct file *filp,
1747 unsigned int cmd, unsigned long arg)
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001748{
Hans Verkuil37f89f92008-06-22 11:57:31 -03001749 struct video_device *vfd = video_devdata(filp);
Hans Verkuil3f038d82008-05-29 16:43:54 -03001750 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1751 int ret;
1752
1753 /* Filter dvb ioctls that cannot be handled by the v4l ioctl framework */
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001754 switch (cmd) {
1755 case VIDEO_SELECT_SOURCE:
1756 IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
1757 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
1758 return -EINVAL;
1759 return ivtv_passthrough_mode(itv, arg == VIDEO_SOURCE_DEMUX);
1760
1761 case AUDIO_SET_MUTE:
1762 IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
1763 itv->speed_mute_audio = arg;
1764 return 0;
1765
1766 case AUDIO_CHANNEL_SELECT:
1767 IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
1768 if (arg > AUDIO_STEREO_SWAPPED)
1769 return -EINVAL;
1770 itv->audio_stereo_mode = arg;
1771 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
1772 return 0;
1773
1774 case AUDIO_BILINGUAL_CHANNEL_SELECT:
1775 IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
1776 if (arg > AUDIO_STEREO_SWAPPED)
1777 return -EINVAL;
1778 itv->audio_bilingual_mode = arg;
1779 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
1780 return 0;
1781
Hans Verkuil3f038d82008-05-29 16:43:54 -03001782 case IVTV_IOC_DMA_FRAME:
1783 case VIDEO_GET_PTS:
1784 case VIDEO_GET_FRAME_COUNT:
1785 case VIDEO_GET_EVENT:
1786 case VIDEO_PLAY:
1787 case VIDEO_STOP:
1788 case VIDEO_FREEZE:
1789 case VIDEO_CONTINUE:
1790 case VIDEO_COMMAND:
1791 case VIDEO_TRY_COMMAND:
1792 return ivtv_decoder_ioctls(filp, cmd, (void *)arg);
1793
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001794 default:
1795 break;
1796 }
Hans Verkuil3f038d82008-05-29 16:43:54 -03001797
1798 /* check priority */
1799 switch (cmd) {
1800 case VIDIOC_S_CTRL:
1801 case VIDIOC_S_STD:
1802 case VIDIOC_S_INPUT:
1803 case VIDIOC_S_OUTPUT:
1804 case VIDIOC_S_TUNER:
1805 case VIDIOC_S_FREQUENCY:
1806 case VIDIOC_S_FMT:
1807 case VIDIOC_S_CROP:
1808 case VIDIOC_S_AUDIO:
1809 case VIDIOC_S_AUDOUT:
1810 case VIDIOC_S_EXT_CTRLS:
1811 case VIDIOC_S_FBUF:
1812 case VIDIOC_OVERLAY:
1813 ret = v4l2_prio_check(&itv->prio, &id->prio);
1814 if (ret)
1815 return ret;
1816 }
1817
Hans Verkuil37f89f92008-06-22 11:57:31 -03001818 if (ivtv_debug & IVTV_DBGFLG_IOCTL)
1819 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
1820 ret = video_ioctl2(inode, filp, cmd, arg);
1821 vfd->debug = 0;
1822 return ret;
Hans Verkuil1a0adaf2007-04-27 12:31:25 -03001823}
Hans Verkuilbaa40722007-08-19 07:10:55 -03001824
1825int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1826 unsigned long arg)
1827{
1828 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1829 struct ivtv *itv = id->itv;
1830 int res;
1831
1832 mutex_lock(&itv->serialize_lock);
1833 res = ivtv_serialized_ioctl(itv, inode, filp, cmd, arg);
1834 mutex_unlock(&itv->serialize_lock);
1835 return res;
1836}
Hans Verkuil3f038d82008-05-29 16:43:54 -03001837
Hans Verkuila3998102008-07-21 02:57:38 -03001838static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1839 .vidioc_querycap = ivtv_querycap,
1840 .vidioc_g_priority = ivtv_g_priority,
1841 .vidioc_s_priority = ivtv_s_priority,
1842 .vidioc_s_audio = ivtv_s_audio,
1843 .vidioc_g_audio = ivtv_g_audio,
1844 .vidioc_enumaudio = ivtv_enumaudio,
1845 .vidioc_s_audout = ivtv_s_audout,
1846 .vidioc_g_audout = ivtv_g_audout,
1847 .vidioc_enum_input = ivtv_enum_input,
1848 .vidioc_enum_output = ivtv_enum_output,
1849 .vidioc_enumaudout = ivtv_enumaudout,
1850 .vidioc_cropcap = ivtv_cropcap,
1851 .vidioc_s_crop = ivtv_s_crop,
1852 .vidioc_g_crop = ivtv_g_crop,
1853 .vidioc_g_input = ivtv_g_input,
1854 .vidioc_s_input = ivtv_s_input,
1855 .vidioc_g_output = ivtv_g_output,
1856 .vidioc_s_output = ivtv_s_output,
1857 .vidioc_g_frequency = ivtv_g_frequency,
1858 .vidioc_s_frequency = ivtv_s_frequency,
1859 .vidioc_s_tuner = ivtv_s_tuner,
1860 .vidioc_g_tuner = ivtv_g_tuner,
1861 .vidioc_g_enc_index = ivtv_g_enc_index,
1862 .vidioc_g_fbuf = ivtv_g_fbuf,
1863 .vidioc_s_fbuf = ivtv_s_fbuf,
1864 .vidioc_g_std = ivtv_g_std,
1865 .vidioc_s_std = ivtv_s_std,
1866 .vidioc_overlay = ivtv_overlay,
1867 .vidioc_log_status = ivtv_log_status,
1868 .vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap,
1869 .vidioc_encoder_cmd = ivtv_encoder_cmd,
1870 .vidioc_try_encoder_cmd = ivtv_try_encoder_cmd,
1871 .vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out,
1872 .vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap,
1873 .vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap,
1874 .vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap,
1875 .vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out,
1876 .vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay,
1877 .vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out,
1878 .vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap,
1879 .vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap,
1880 .vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap,
1881 .vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out,
1882 .vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay,
1883 .vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out,
1884 .vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap,
1885 .vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap,
1886 .vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap,
1887 .vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out,
1888 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay,
1889 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out,
1890 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap,
1891 .vidioc_g_chip_ident = ivtv_g_chip_ident,
1892#ifdef CONFIG_VIDEO_ADV_DEBUG
1893 .vidioc_g_register = ivtv_g_register,
1894 .vidioc_s_register = ivtv_s_register,
1895#endif
1896 .vidioc_default = ivtv_default,
1897 .vidioc_queryctrl = ivtv_queryctrl,
1898 .vidioc_querymenu = ivtv_querymenu,
1899 .vidioc_g_ext_ctrls = ivtv_g_ext_ctrls,
1900 .vidioc_s_ext_ctrls = ivtv_s_ext_ctrls,
1901 .vidioc_try_ext_ctrls = ivtv_try_ext_ctrls,
1902};
1903
Hans Verkuil3f038d82008-05-29 16:43:54 -03001904void ivtv_set_funcs(struct video_device *vdev)
1905{
Hans Verkuila3998102008-07-21 02:57:38 -03001906 vdev->ioctl_ops = &ivtv_ioctl_ops;
Hans Verkuil3f038d82008-05-29 16:43:54 -03001907}