Commit | Line | Data |
---|---|---|
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" | |
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 | ||
feb5bce2 | 41 | u16 ivtv_service2vbi(int type) |
1a0adaf3 HV |
42 | { |
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 | ||
57 | static 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 | ||
63 | static 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 | ||
feb5bce2 | 91 | void ivtv_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) |
1a0adaf3 HV |
92 | { |
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 | ||
104 | static 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 | ||
feb5bce2 | 118 | u16 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 |
131 | void 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 | ||
138 | int 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 | ||
210 | static int ivtv_validate_speed(int cur_speed, int new_speed) | |
211 | { | |
212 | int fact = new_speed < 0 ? -1 : 1; | |
213 | int s; | |
214 | ||
94dee760 HV |
215 | 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; | |
1a0adaf3 HV |
221 | |
222 | if (cur_speed <= new_speed) { | |
94dee760 HV |
223 | if (new_speed > 1500) |
224 | return fact * 2000; | |
225 | if (new_speed > 1000) | |
226 | return fact * 1500; | |
1a0adaf3 HV |
227 | } |
228 | else { | |
94dee760 HV |
229 | 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; | |
1a0adaf3 | 235 | } |
94dee760 HV |
236 | if (new_speed == 0) |
237 | return 1000; | |
238 | if (new_speed == 1 || new_speed == 1000) | |
239 | return fact * new_speed; | |
1a0adaf3 HV |
240 | |
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 | ||
249 | static 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: { | |
25415cf3 | 259 | vc->flags = 0; |
1a0adaf3 HV |
260 | 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; | |
ac425144 HV |
267 | 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 | } | |
1a0adaf3 HV |
271 | return ivtv_start_decoding(id, vc->play.speed); |
272 | } | |
273 | ||
274 | case VIDEO_CMD_STOP: | |
018ba85b | 275 | vc->flags &= VIDEO_CMD_STOP_IMMEDIATELY|VIDEO_CMD_STOP_TO_BLACK; |
1a0adaf3 HV |
276 | 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: | |
018ba85b | 288 | vc->flags &= VIDEO_CMD_FREEZE_TO_BLACK; |
1a0adaf3 HV |
289 | 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); | |
ac425144 | 295 | set_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags); |
1a0adaf3 HV |
296 | } |
297 | break; | |
298 | ||
299 | case VIDEO_CMD_CONTINUE: | |
25415cf3 | 300 | vc->flags = 0; |
1a0adaf3 HV |
301 | if (try) break; |
302 | if (itv->output_mode != OUT_MPG) | |
303 | return -EBUSY; | |
ac425144 HV |
304 | 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); | |
1a0adaf3 HV |
308 | } |
309 | break; | |
310 | ||
311 | default: | |
312 | return -EINVAL; | |
313 | } | |
314 | return 0; | |
315 | } | |
316 | ||
317 | static int ivtv_itvc(struct ivtv *itv, unsigned int cmd, void *arg) | |
318 | { | |
319 | struct v4l2_register *regs = arg; | |
320 | unsigned long flags; | |
321 | volatile u8 __iomem *reg_start; | |
322 | ||
323 | if (!capable(CAP_SYS_ADMIN)) | |
324 | return -EPERM; | |
325 | if (regs->reg >= IVTV_REG_OFFSET && regs->reg < IVTV_REG_OFFSET + IVTV_REG_SIZE) | |
326 | reg_start = itv->reg_mem - IVTV_REG_OFFSET; | |
327 | else if (itv->has_cx23415 && regs->reg >= IVTV_DECODER_OFFSET && | |
328 | regs->reg < IVTV_DECODER_OFFSET + IVTV_DECODER_SIZE) | |
329 | reg_start = itv->dec_mem - IVTV_DECODER_OFFSET; | |
330 | else if (regs->reg >= 0 && regs->reg < IVTV_ENCODER_SIZE) | |
331 | reg_start = itv->enc_mem; | |
332 | else | |
333 | return -EINVAL; | |
334 | ||
335 | spin_lock_irqsave(&ivtv_cards_lock, flags); | |
336 | if (cmd == VIDIOC_DBG_G_REGISTER) { | |
337 | regs->val = readl(regs->reg + reg_start); | |
338 | } else { | |
339 | writel(regs->val, regs->reg + reg_start); | |
340 | } | |
341 | spin_unlock_irqrestore(&ivtv_cards_lock, flags); | |
342 | return 0; | |
343 | } | |
344 | ||
3f038d80 | 345 | static int ivtv_g_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt) |
1a0adaf3 | 346 | { |
3f038d80 HV |
347 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; |
348 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; | |
1a0adaf3 | 349 | |
e88360c0 HV |
350 | vbifmt->reserved[0] = 0; |
351 | vbifmt->reserved[1] = 0; | |
3f038d80 HV |
352 | if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT)) |
353 | return -EINVAL; | |
354 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; | |
355 | if (itv->is_60hz) { | |
356 | vbifmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525; | |
357 | vbifmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525; | |
358 | } else { | |
359 | vbifmt->service_lines[0][23] = V4L2_SLICED_WSS_625; | |
360 | vbifmt->service_lines[0][16] = V4L2_SLICED_VPS; | |
1a0adaf3 | 361 | } |
3f038d80 HV |
362 | vbifmt->service_set = ivtv_get_service_set(vbifmt); |
363 | return 0; | |
364 | } | |
1a0adaf3 | 365 | |
3f038d80 HV |
366 | static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
367 | { | |
368 | struct ivtv_open_id *id = fh; | |
369 | struct ivtv *itv = id->itv; | |
e88360c0 HV |
370 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
371 | ||
372 | pixfmt->width = itv->params.width; | |
373 | pixfmt->height = itv->params.height; | |
374 | pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; | |
375 | pixfmt->field = V4L2_FIELD_INTERLACED; | |
376 | pixfmt->priv = 0; | |
377 | if (id->type == IVTV_ENC_STREAM_TYPE_YUV) { | |
378 | pixfmt->pixelformat = V4L2_PIX_FMT_HM12; | |
3f038d80 | 379 | /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ |
e88360c0 HV |
380 | pixfmt->sizeimage = |
381 | pixfmt->height * pixfmt->width + | |
382 | pixfmt->height * (pixfmt->width / 2); | |
383 | pixfmt->bytesperline = 720; | |
3f038d80 | 384 | } else { |
e88360c0 HV |
385 | pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; |
386 | pixfmt->sizeimage = 128 * 1024; | |
387 | pixfmt->bytesperline = 0; | |
1a0adaf3 HV |
388 | } |
389 | return 0; | |
390 | } | |
391 | ||
3f038d80 | 392 | static int ivtv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
1a0adaf3 | 393 | { |
3f038d80 | 394 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; |
e88360c0 HV |
395 | struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi; |
396 | ||
397 | vbifmt->sampling_rate = 27000000; | |
398 | vbifmt->offset = 248; | |
399 | vbifmt->samples_per_line = itv->vbi.raw_decoder_line_size - 4; | |
400 | vbifmt->sample_format = V4L2_PIX_FMT_GREY; | |
401 | vbifmt->start[0] = itv->vbi.start[0]; | |
402 | vbifmt->start[1] = itv->vbi.start[1]; | |
403 | vbifmt->count[0] = vbifmt->count[1] = itv->vbi.count; | |
404 | vbifmt->flags = 0; | |
405 | vbifmt->reserved[0] = 0; | |
406 | vbifmt->reserved[1] = 0; | |
3f038d80 HV |
407 | return 0; |
408 | } | |
1a0adaf3 | 409 | |
3f038d80 HV |
410 | static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
411 | { | |
412 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; | |
413 | struct ivtv_open_id *id = fh; | |
414 | struct ivtv *itv = id->itv; | |
1a0adaf3 | 415 | |
e88360c0 HV |
416 | vbifmt->reserved[0] = 0; |
417 | vbifmt->reserved[1] = 0; | |
3f038d80 | 418 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; |
1a0adaf3 | 419 | |
3f038d80 HV |
420 | if (id->type == IVTV_DEC_STREAM_TYPE_VBI) { |
421 | vbifmt->service_set = itv->is_50hz ? V4L2_SLICED_VBI_625 : | |
422 | V4L2_SLICED_VBI_525; | |
423 | ivtv_expand_service_set(vbifmt, itv->is_50hz); | |
424 | return 0; | |
425 | } | |
77aded6b | 426 | |
3f038d80 HV |
427 | itv->video_dec_func(itv, VIDIOC_G_FMT, fmt); |
428 | vbifmt->service_set = ivtv_get_service_set(vbifmt); | |
429 | return 0; | |
430 | } | |
77aded6b | 431 | |
3f038d80 HV |
432 | static int ivtv_g_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt) |
433 | { | |
434 | struct ivtv_open_id *id = fh; | |
435 | struct ivtv *itv = id->itv; | |
e88360c0 | 436 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; |
77aded6b | 437 | |
3f038d80 HV |
438 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) |
439 | return -EINVAL; | |
e88360c0 HV |
440 | pixfmt->width = itv->main_rect.width; |
441 | pixfmt->height = itv->main_rect.height; | |
442 | pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; | |
443 | pixfmt->field = V4L2_FIELD_INTERLACED; | |
444 | pixfmt->priv = 0; | |
3f038d80 HV |
445 | if (id->type == IVTV_DEC_STREAM_TYPE_YUV) { |
446 | switch (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) { | |
447 | case IVTV_YUV_MODE_INTERLACED: | |
e88360c0 | 448 | pixfmt->field = (itv->yuv_info.lace_mode & IVTV_YUV_SYNC_MASK) ? |
3f038d80 HV |
449 | V4L2_FIELD_INTERLACED_BT : V4L2_FIELD_INTERLACED_TB; |
450 | break; | |
451 | case IVTV_YUV_MODE_PROGRESSIVE: | |
e88360c0 | 452 | pixfmt->field = V4L2_FIELD_NONE; |
3f038d80 HV |
453 | break; |
454 | default: | |
e88360c0 | 455 | pixfmt->field = V4L2_FIELD_ANY; |
3f038d80 | 456 | break; |
1a0adaf3 | 457 | } |
e88360c0 HV |
458 | pixfmt->pixelformat = V4L2_PIX_FMT_HM12; |
459 | pixfmt->bytesperline = 720; | |
460 | pixfmt->width = itv->yuv_info.v4l2_src_w; | |
461 | pixfmt->height = itv->yuv_info.v4l2_src_h; | |
3f038d80 | 462 | /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ |
e88360c0 HV |
463 | pixfmt->sizeimage = |
464 | 1080 * ((pixfmt->height + 31) & ~31); | |
3f038d80 | 465 | } else { |
e88360c0 HV |
466 | pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; |
467 | pixfmt->sizeimage = 128 * 1024; | |
468 | pixfmt->bytesperline = 0; | |
1a0adaf3 | 469 | } |
3f038d80 HV |
470 | return 0; |
471 | } | |
1a0adaf3 | 472 | |
3f038d80 HV |
473 | static int ivtv_g_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt) |
474 | { | |
475 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
e88360c0 | 476 | struct v4l2_window *winfmt = &fmt->fmt.win; |
1a0adaf3 | 477 | |
3f038d80 HV |
478 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) |
479 | return -EINVAL; | |
e88360c0 HV |
480 | winfmt->chromakey = itv->osd_chroma_key; |
481 | winfmt->global_alpha = itv->osd_global_alpha; | |
482 | winfmt->field = V4L2_FIELD_INTERLACED; | |
483 | winfmt->clips = NULL; | |
484 | winfmt->clipcount = 0; | |
485 | winfmt->bitmap = NULL; | |
486 | winfmt->w.top = winfmt->w.left = 0; | |
487 | winfmt->w.width = itv->osd_rect.width; | |
488 | winfmt->w.height = itv->osd_rect.height; | |
3f038d80 HV |
489 | return 0; |
490 | } | |
1a0adaf3 | 491 | |
3f038d80 HV |
492 | static int ivtv_try_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt) |
493 | { | |
494 | return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt); | |
495 | } | |
1a0adaf3 | 496 | |
3f038d80 HV |
497 | static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
498 | { | |
499 | struct ivtv_open_id *id = fh; | |
500 | struct ivtv *itv = id->itv; | |
501 | int w = fmt->fmt.pix.width; | |
502 | int h = fmt->fmt.pix.height; | |
503 | ||
504 | w = min(w, 720); | |
505 | w = max(w, 1); | |
506 | h = min(h, itv->is_50hz ? 576 : 480); | |
507 | h = max(h, 2); | |
508 | ivtv_g_fmt_vid_cap(file, fh, fmt); | |
509 | fmt->fmt.pix.width = w; | |
510 | fmt->fmt.pix.height = h; | |
511 | return 0; | |
512 | } | |
1a0adaf3 | 513 | |
3f038d80 HV |
514 | static int ivtv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
515 | { | |
516 | return ivtv_g_fmt_vbi_cap(file, fh, fmt); | |
517 | } | |
1a0adaf3 | 518 | |
3f038d80 HV |
519 | static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) |
520 | { | |
521 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; | |
522 | struct ivtv_open_id *id = fh; | |
523 | struct ivtv *itv = id->itv; | |
1a0adaf3 | 524 | |
3f038d80 HV |
525 | if (id->type == IVTV_DEC_STREAM_TYPE_VBI) |
526 | return ivtv_g_fmt_sliced_vbi_cap(file, fh, fmt); | |
1a0adaf3 HV |
527 | |
528 | /* set sliced VBI capture format */ | |
529 | vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36; | |
e88360c0 HV |
530 | vbifmt->reserved[0] = 0; |
531 | vbifmt->reserved[1] = 0; | |
1a0adaf3 HV |
532 | |
533 | if (vbifmt->service_set) | |
feb5bce2 | 534 | ivtv_expand_service_set(vbifmt, itv->is_50hz); |
3f038d80 | 535 | check_service_set(vbifmt, itv->is_50hz); |
feb5bce2 | 536 | vbifmt->service_set = ivtv_get_service_set(vbifmt); |
3f038d80 HV |
537 | return 0; |
538 | } | |
539 | ||
540 | static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt) | |
541 | { | |
542 | struct ivtv_open_id *id = fh; | |
543 | s32 w, h; | |
544 | int field; | |
545 | int ret; | |
546 | ||
547 | w = fmt->fmt.pix.width; | |
548 | h = fmt->fmt.pix.height; | |
549 | field = fmt->fmt.pix.field; | |
550 | ret = ivtv_g_fmt_vid_out(file, fh, fmt); | |
551 | fmt->fmt.pix.width = w; | |
552 | fmt->fmt.pix.height = h; | |
553 | if (!ret && id->type == IVTV_DEC_STREAM_TYPE_YUV) { | |
554 | fmt->fmt.pix.field = field; | |
555 | if (fmt->fmt.pix.width < 2) | |
556 | fmt->fmt.pix.width = 2; | |
557 | if (fmt->fmt.pix.width > 720) | |
558 | fmt->fmt.pix.width = 720; | |
559 | if (fmt->fmt.pix.height < 2) | |
560 | fmt->fmt.pix.height = 2; | |
561 | if (fmt->fmt.pix.height > 576) | |
562 | fmt->fmt.pix.height = 576; | |
563 | } | |
564 | return ret; | |
565 | } | |
566 | ||
567 | static int ivtv_try_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt) | |
568 | { | |
569 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
e88360c0 HV |
570 | u32 chromakey = fmt->fmt.win.chromakey; |
571 | u8 global_alpha = fmt->fmt.win.global_alpha; | |
1a0adaf3 | 572 | |
3f038d80 HV |
573 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) |
574 | return -EINVAL; | |
e88360c0 HV |
575 | ivtv_g_fmt_vid_out_overlay(file, fh, fmt); |
576 | fmt->fmt.win.chromakey = chromakey; | |
577 | fmt->fmt.win.global_alpha = global_alpha; | |
3f038d80 HV |
578 | return 0; |
579 | } | |
580 | ||
581 | static int ivtv_s_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format *fmt) | |
582 | { | |
583 | return ivtv_g_fmt_sliced_vbi_out(file, fh, fmt); | |
584 | } | |
585 | ||
586 | static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt) | |
587 | { | |
588 | struct ivtv_open_id *id = fh; | |
589 | struct ivtv *itv = id->itv; | |
590 | struct cx2341x_mpeg_params *p = &itv->params; | |
591 | int w = fmt->fmt.pix.width; | |
592 | int h = fmt->fmt.pix.height; | |
593 | int ret = ivtv_try_fmt_vid_cap(file, fh, fmt); | |
594 | ||
595 | if (ret) | |
596 | return ret; | |
597 | ||
598 | if (p->width == w && p->height == h) | |
1a0adaf3 | 599 | return 0; |
3f038d80 HV |
600 | |
601 | if (atomic_read(&itv->capturing) > 0) | |
602 | return -EBUSY; | |
603 | ||
604 | p->width = w; | |
605 | p->height = h; | |
606 | if (w != 720 || h != (itv->is_50hz ? 576 : 480)) | |
607 | p->video_temporal_filter = 0; | |
608 | else | |
609 | p->video_temporal_filter = 8; | |
610 | if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) | |
611 | fmt->fmt.pix.width /= 2; | |
612 | itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); | |
613 | return ivtv_g_fmt_vid_cap(file, fh, fmt); | |
614 | } | |
615 | ||
616 | static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) | |
617 | { | |
618 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
619 | ||
620 | itv->vbi.sliced_in->service_set = 0; | |
621 | itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in); | |
622 | return ivtv_g_fmt_vbi_cap(file, fh, fmt); | |
623 | } | |
624 | ||
625 | static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_format *fmt) | |
626 | { | |
627 | struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced; | |
628 | struct ivtv_open_id *id = fh; | |
629 | struct ivtv *itv = id->itv; | |
630 | int ret = ivtv_try_fmt_sliced_vbi_cap(file, fh, fmt); | |
631 | ||
632 | if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI) | |
633 | return ret; | |
634 | ||
635 | if (check_service_set(vbifmt, itv->is_50hz) == 0) | |
1a0adaf3 | 636 | return -EINVAL; |
3f038d80 | 637 | if (atomic_read(&itv->capturing) > 0) |
1a0adaf3 | 638 | return -EBUSY; |
1a0adaf3 HV |
639 | itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); |
640 | memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in)); | |
641 | return 0; | |
642 | } | |
643 | ||
3f038d80 | 644 | static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt) |
1a0adaf3 | 645 | { |
3f038d80 | 646 | struct ivtv_open_id *id = fh; |
1a0adaf3 | 647 | struct ivtv *itv = id->itv; |
3f038d80 HV |
648 | struct yuv_playback_info *yi = &itv->yuv_info; |
649 | int ret = ivtv_try_fmt_vid_out(file, fh, fmt); | |
1a0adaf3 | 650 | |
3f038d80 HV |
651 | if (ret) |
652 | return ret; | |
1a0adaf3 | 653 | |
3f038d80 HV |
654 | if (id->type != IVTV_DEC_STREAM_TYPE_YUV) |
655 | return 0; | |
1a0adaf3 | 656 | |
3f038d80 HV |
657 | /* Return now if we already have some frame data */ |
658 | if (yi->stream_size) | |
659 | return -EBUSY; | |
1a0adaf3 | 660 | |
3f038d80 HV |
661 | yi->v4l2_src_w = fmt->fmt.pix.width; |
662 | yi->v4l2_src_h = fmt->fmt.pix.height; | |
2cc72095 | 663 | |
3f038d80 HV |
664 | switch (fmt->fmt.pix.field) { |
665 | case V4L2_FIELD_NONE: | |
666 | yi->lace_mode = IVTV_YUV_MODE_PROGRESSIVE; | |
1a0adaf3 | 667 | break; |
3f038d80 HV |
668 | case V4L2_FIELD_ANY: |
669 | yi->lace_mode = IVTV_YUV_MODE_AUTO; | |
670 | break; | |
671 | case V4L2_FIELD_INTERLACED_BT: | |
672 | yi->lace_mode = | |
673 | IVTV_YUV_MODE_INTERLACED|IVTV_YUV_SYNC_ODD; | |
674 | break; | |
675 | case V4L2_FIELD_INTERLACED_TB: | |
1a0adaf3 | 676 | default: |
3f038d80 HV |
677 | yi->lace_mode = IVTV_YUV_MODE_INTERLACED; |
678 | break; | |
1a0adaf3 | 679 | } |
3f038d80 HV |
680 | yi->lace_sync_field = (yi->lace_mode & IVTV_YUV_SYNC_MASK) == IVTV_YUV_SYNC_EVEN ? 0 : 1; |
681 | ||
682 | if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) | |
683 | itv->dma_data_req_size = | |
684 | 1080 * ((yi->v4l2_src_h + 31) & ~31); | |
685 | ||
686 | /* Force update of yuv registers */ | |
687 | yi->yuv_forced_update = 1; | |
1a0adaf3 HV |
688 | return 0; |
689 | } | |
690 | ||
3f038d80 | 691 | static int ivtv_s_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_format *fmt) |
1a0adaf3 | 692 | { |
3f038d80 HV |
693 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; |
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 | |
3f038d80 HV |
704 | static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_chip_ident *chip) |
705 | { | |
706 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
d46c17d7 | 707 | |
3f038d80 HV |
708 | chip->ident = V4L2_IDENT_NONE; |
709 | chip->revision = 0; | |
710 | if (chip->match_type == V4L2_CHIP_MATCH_HOST) { | |
711 | if (v4l2_chip_match_host(chip->match_type, chip->match_chip)) | |
712 | chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416; | |
713 | return 0; | |
d46c17d7 | 714 | } |
3f038d80 HV |
715 | if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) |
716 | return ivtv_i2c_id(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip); | |
717 | if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR) | |
718 | return ivtv_call_i2c_client(itv, chip->match_chip, VIDIOC_G_CHIP_IDENT, chip); | |
719 | return -EINVAL; | |
720 | } | |
d46c17d7 | 721 | |
3f038d80 HV |
722 | static int ivtv_g_register(struct file *file, void *fh, struct v4l2_register *reg) |
723 | { | |
724 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
d46c17d7 | 725 | |
3f038d80 HV |
726 | if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) |
727 | return ivtv_itvc(itv, VIDIOC_DBG_G_REGISTER, reg); | |
728 | if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) | |
729 | return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg); | |
730 | return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_G_REGISTER, reg); | |
731 | } | |
732 | ||
733 | static int ivtv_s_register(struct file *file, void *fh, struct v4l2_register *reg) | |
734 | { | |
735 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
d46c17d7 | 736 | |
3f038d80 HV |
737 | if (v4l2_chip_match_host(reg->match_type, reg->match_chip)) |
738 | return ivtv_itvc(itv, VIDIOC_DBG_S_REGISTER, reg); | |
739 | if (reg->match_type == V4L2_CHIP_MATCH_I2C_DRIVER) | |
740 | return ivtv_i2c_id(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg); | |
741 | return ivtv_call_i2c_client(itv, reg->match_chip, VIDIOC_DBG_S_REGISTER, reg); | |
742 | } | |
1a0adaf3 | 743 | |
3f038d80 HV |
744 | static int ivtv_g_priority(struct file *file, void *fh, enum v4l2_priority *p) |
745 | { | |
746 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 747 | |
3f038d80 | 748 | *p = v4l2_prio_max(&itv->prio); |
1a0adaf3 | 749 | |
3f038d80 HV |
750 | return 0; |
751 | } | |
1a0adaf3 | 752 | |
3f038d80 HV |
753 | static int ivtv_s_priority(struct file *file, void *fh, enum v4l2_priority prio) |
754 | { | |
755 | struct ivtv_open_id *id = fh; | |
756 | struct ivtv *itv = id->itv; | |
1a0adaf3 | 757 | |
3f038d80 HV |
758 | return v4l2_prio_change(&itv->prio, &id->prio, prio); |
759 | } | |
1a0adaf3 | 760 | |
3f038d80 HV |
761 | static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vcap) |
762 | { | |
763 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
764 | ||
765 | memset(vcap, 0, sizeof(*vcap)); | |
766 | strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver)); | |
767 | strlcpy(vcap->card, itv->card_name, sizeof(vcap->card)); | |
768 | strlcpy(vcap->bus_info, pci_name(itv->dev), sizeof(vcap->bus_info)); | |
769 | vcap->version = IVTV_DRIVER_VERSION; /* version */ | |
770 | vcap->capabilities = itv->v4l2_cap; /* capabilities */ | |
771 | /* reserved.. must set to 0! */ | |
772 | vcap->reserved[0] = vcap->reserved[1] = | |
773 | vcap->reserved[2] = vcap->reserved[3] = 0; | |
774 | return 0; | |
775 | } | |
1a0adaf3 | 776 | |
3f038d80 HV |
777 | static int ivtv_enumaudio(struct file *file, void *fh, struct v4l2_audio *vin) |
778 | { | |
779 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 780 | |
3f038d80 HV |
781 | return ivtv_get_audio_input(itv, vin->index, vin); |
782 | } | |
783 | ||
784 | static int ivtv_g_audio(struct file *file, void *fh, struct v4l2_audio *vin) | |
785 | { | |
786 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 787 | |
3f038d80 HV |
788 | vin->index = itv->audio_input; |
789 | return ivtv_get_audio_input(itv, vin->index, vin); | |
790 | } | |
1a0adaf3 | 791 | |
3f038d80 HV |
792 | static int ivtv_s_audio(struct file *file, void *fh, struct v4l2_audio *vout) |
793 | { | |
794 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 795 | |
3f038d80 HV |
796 | if (vout->index >= itv->nof_audio_inputs) |
797 | return -EINVAL; | |
1a0adaf3 | 798 | |
3f038d80 HV |
799 | itv->audio_input = vout->index; |
800 | ivtv_audio_set_io(itv); | |
1a0adaf3 | 801 | |
3f038d80 HV |
802 | return 0; |
803 | } | |
1a0adaf3 | 804 | |
3f038d80 HV |
805 | static int ivtv_enumaudout(struct file *file, void *fh, struct v4l2_audioout *vin) |
806 | { | |
807 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 808 | |
3f038d80 HV |
809 | /* set it to defaults from our table */ |
810 | return ivtv_get_audio_output(itv, vin->index, vin); | |
811 | } | |
1a0adaf3 | 812 | |
3f038d80 HV |
813 | static int ivtv_g_audout(struct file *file, void *fh, struct v4l2_audioout *vin) |
814 | { | |
815 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 816 | |
3f038d80 HV |
817 | vin->index = 0; |
818 | return ivtv_get_audio_output(itv, vin->index, vin); | |
819 | } | |
1a0adaf3 | 820 | |
3f038d80 HV |
821 | static int ivtv_s_audout(struct file *file, void *fh, struct v4l2_audioout *vout) |
822 | { | |
823 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 824 | |
3f038d80 HV |
825 | return ivtv_get_audio_output(itv, vout->index, vout); |
826 | } | |
1a0adaf3 | 827 | |
3f038d80 HV |
828 | static int ivtv_enum_input(struct file *file, void *fh, struct v4l2_input *vin) |
829 | { | |
830 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 831 | |
3f038d80 HV |
832 | /* set it to defaults from our table */ |
833 | return ivtv_get_input(itv, vin->index, vin); | |
834 | } | |
1a0adaf3 | 835 | |
3f038d80 HV |
836 | static int ivtv_enum_output(struct file *file, void *fh, struct v4l2_output *vout) |
837 | { | |
838 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 839 | |
3f038d80 HV |
840 | return ivtv_get_output(itv, vout->index, vout); |
841 | } | |
987e00ba | 842 | |
3f038d80 HV |
843 | static int ivtv_cropcap(struct file *file, void *fh, struct v4l2_cropcap *cropcap) |
844 | { | |
845 | struct ivtv_open_id *id = fh; | |
846 | struct ivtv *itv = id->itv; | |
847 | struct yuv_playback_info *yi = &itv->yuv_info; | |
848 | int streamtype; | |
849 | ||
850 | streamtype = id->type; | |
851 | ||
852 | if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) | |
853 | return -EINVAL; | |
854 | cropcap->bounds.top = cropcap->bounds.left = 0; | |
855 | cropcap->bounds.width = 720; | |
856 | if (cropcap->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { | |
857 | cropcap->bounds.height = itv->is_50hz ? 576 : 480; | |
858 | cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10; | |
859 | cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11; | |
860 | } else if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) { | |
861 | if (yi->track_osd) { | |
862 | cropcap->bounds.width = yi->osd_full_w; | |
863 | cropcap->bounds.height = yi->osd_full_h; | |
987e00ba | 864 | } else { |
3f038d80 HV |
865 | cropcap->bounds.width = 720; |
866 | cropcap->bounds.height = | |
867 | itv->is_out_50hz ? 576 : 480; | |
987e00ba | 868 | } |
3f038d80 HV |
869 | cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10; |
870 | cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11; | |
871 | } else { | |
872 | cropcap->bounds.height = itv->is_out_50hz ? 576 : 480; | |
873 | cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10; | |
874 | cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11; | |
987e00ba | 875 | } |
3f038d80 HV |
876 | cropcap->defrect = cropcap->bounds; |
877 | return 0; | |
878 | } | |
879 | ||
880 | static int ivtv_s_crop(struct file *file, void *fh, struct v4l2_crop *crop) | |
881 | { | |
882 | struct ivtv_open_id *id = fh; | |
883 | struct ivtv *itv = id->itv; | |
884 | struct yuv_playback_info *yi = &itv->yuv_info; | |
885 | int streamtype; | |
987e00ba | 886 | |
3f038d80 | 887 | streamtype = id->type; |
1a0adaf3 | 888 | |
3f038d80 HV |
889 | if (ivtv_debug & IVTV_DBGFLG_IOCTL) { |
890 | printk(KERN_INFO "ivtv%d ioctl: ", itv->num); | |
891 | /* Should be replaced */ | |
892 | /* v4l_printk_ioctl(VIDIOC_S_CROP); */ | |
893 | } | |
894 | ||
895 | if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && | |
896 | (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { | |
897 | if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) { | |
898 | yi->main_rect = crop->c; | |
899 | return 0; | |
900 | } else { | |
901 | if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, | |
902 | crop->c.width, crop->c.height, crop->c.left, crop->c.top)) { | |
903 | itv->main_rect = crop->c; | |
987e00ba HV |
904 | return 0; |
905 | } | |
987e00ba | 906 | } |
c9aec06f | 907 | return -EINVAL; |
1a0adaf3 | 908 | } |
3f038d80 HV |
909 | return -EINVAL; |
910 | } | |
1a0adaf3 | 911 | |
3f038d80 HV |
912 | static int ivtv_g_crop(struct file *file, void *fh, struct v4l2_crop *crop) |
913 | { | |
914 | struct ivtv_open_id *id = fh; | |
915 | struct ivtv *itv = id->itv; | |
916 | struct yuv_playback_info *yi = &itv->yuv_info; | |
917 | int streamtype; | |
1a0adaf3 | 918 | |
3f038d80 HV |
919 | streamtype = id->type; |
920 | ||
921 | if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && | |
922 | (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { | |
923 | if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) | |
924 | crop->c = yi->main_rect; | |
925 | else | |
926 | crop->c = itv->main_rect; | |
927 | return 0; | |
928 | } | |
929 | return -EINVAL; | |
930 | } | |
931 | ||
932 | static int ivtv_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt) | |
933 | { | |
934 | static struct v4l2_fmtdesc formats[] = { | |
935 | { 0, 0, 0, | |
936 | "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12, | |
937 | { 0, 0, 0, 0 } | |
938 | }, | |
939 | { 1, 0, V4L2_FMT_FLAG_COMPRESSED, | |
940 | "MPEG", V4L2_PIX_FMT_MPEG, | |
941 | { 0, 0, 0, 0 } | |
987e00ba | 942 | } |
3f038d80 HV |
943 | }; |
944 | enum v4l2_buf_type type = fmt->type; | |
945 | ||
946 | if (fmt->index > 1) | |
c9aec06f | 947 | return -EINVAL; |
1a0adaf3 | 948 | |
3f038d80 HV |
949 | *fmt = formats[fmt->index]; |
950 | fmt->type = type; | |
951 | return 0; | |
952 | } | |
1a0adaf3 | 953 | |
3f038d80 HV |
954 | static int ivtv_enum_fmt_vid_out(struct file *file, void *fh, struct v4l2_fmtdesc *fmt) |
955 | { | |
956 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
957 | ||
958 | static struct v4l2_fmtdesc formats[] = { | |
959 | { 0, 0, 0, | |
960 | "HM12 (YUV 4:2:0)", V4L2_PIX_FMT_HM12, | |
961 | { 0, 0, 0, 0 } | |
962 | }, | |
963 | { 1, 0, V4L2_FMT_FLAG_COMPRESSED, | |
964 | "MPEG", V4L2_PIX_FMT_MPEG, | |
965 | { 0, 0, 0, 0 } | |
1a0adaf3 | 966 | } |
3f038d80 HV |
967 | }; |
968 | enum v4l2_buf_type type = fmt->type; | |
969 | ||
970 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
971 | return -EINVAL; | |
972 | ||
973 | if (fmt->index > 1) | |
974 | return -EINVAL; | |
975 | ||
976 | *fmt = formats[fmt->index]; | |
977 | fmt->type = type; | |
978 | ||
979 | return 0; | |
980 | } | |
981 | ||
982 | static int ivtv_g_input(struct file *file, void *fh, unsigned int *i) | |
983 | { | |
984 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
985 | ||
986 | *i = itv->active_input; | |
987 | ||
988 | return 0; | |
989 | } | |
990 | ||
991 | int ivtv_s_input(struct file *file, void *fh, unsigned int inp) | |
992 | { | |
993 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
994 | ||
995 | if (inp < 0 || inp >= itv->nof_inputs) | |
996 | return -EINVAL; | |
997 | ||
998 | if (inp == itv->active_input) { | |
999 | IVTV_DEBUG_INFO("Input unchanged\n"); | |
1a0adaf3 HV |
1000 | return 0; |
1001 | } | |
1002 | ||
3f038d80 HV |
1003 | if (atomic_read(&itv->capturing) > 0) { |
1004 | return -EBUSY; | |
1a0adaf3 HV |
1005 | } |
1006 | ||
3f038d80 HV |
1007 | IVTV_DEBUG_INFO("Changing input from %d to %d\n", |
1008 | itv->active_input, inp); | |
1a0adaf3 | 1009 | |
3f038d80 HV |
1010 | itv->active_input = inp; |
1011 | /* Set the audio input to whatever is appropriate for the | |
1012 | input type. */ | |
1013 | itv->audio_input = itv->card->video_inputs[inp].audio_index; | |
1a0adaf3 | 1014 | |
3f038d80 HV |
1015 | /* prevent others from messing with the streams until |
1016 | we're finished changing inputs. */ | |
1017 | ivtv_mute(itv); | |
1018 | ivtv_video_set_io(itv); | |
1019 | ivtv_audio_set_io(itv); | |
1020 | ivtv_unmute(itv); | |
1021 | ||
1022 | return 0; | |
1023 | } | |
1a0adaf3 | 1024 | |
3f038d80 HV |
1025 | static int ivtv_g_output(struct file *file, void *fh, unsigned int *i) |
1026 | { | |
1027 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 1028 | |
3f038d80 HV |
1029 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) |
1030 | return -EINVAL; | |
1031 | ||
1032 | *i = itv->active_output; | |
1033 | ||
1034 | return 0; | |
1035 | } | |
1036 | ||
1037 | static int ivtv_s_output(struct file *file, void *fh, unsigned int outp) | |
1038 | { | |
1039 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1040 | struct v4l2_routing route; | |
1041 | ||
1042 | if (outp >= itv->card->nof_outputs) | |
1043 | return -EINVAL; | |
1044 | ||
1045 | if (outp == itv->active_output) { | |
1046 | IVTV_DEBUG_INFO("Output unchanged\n"); | |
1047 | return 0; | |
1a0adaf3 | 1048 | } |
3f038d80 HV |
1049 | IVTV_DEBUG_INFO("Changing output from %d to %d\n", |
1050 | itv->active_output, outp); | |
1a0adaf3 | 1051 | |
3f038d80 HV |
1052 | itv->active_output = outp; |
1053 | route.input = SAA7127_INPUT_TYPE_NORMAL; | |
1054 | route.output = itv->card->video_outputs[outp].video_output; | |
1055 | ivtv_saa7127(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route); | |
1056 | ||
1057 | return 0; | |
1058 | } | |
1059 | ||
1060 | static int ivtv_g_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) | |
1061 | { | |
1062 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1063 | ||
1064 | if (vf->tuner != 0) | |
1065 | return -EINVAL; | |
1066 | ||
1067 | ivtv_call_i2c_clients(itv, VIDIOC_G_FREQUENCY, vf); | |
1068 | return 0; | |
1069 | } | |
1070 | ||
1071 | int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf) | |
1072 | { | |
1073 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1074 | ||
1075 | if (vf->tuner != 0) | |
1076 | return -EINVAL; | |
1077 | ||
1078 | ivtv_mute(itv); | |
1079 | IVTV_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency); | |
1080 | ivtv_call_i2c_clients(itv, VIDIOC_S_FREQUENCY, vf); | |
1081 | ivtv_unmute(itv); | |
1082 | return 0; | |
1083 | } | |
1084 | ||
1085 | static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std) | |
1086 | { | |
1087 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1088 | ||
1089 | *std = itv->std; | |
1090 | return 0; | |
1091 | } | |
1092 | ||
1093 | int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std) | |
1094 | { | |
1095 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1096 | struct yuv_playback_info *yi = &itv->yuv_info; | |
1097 | ||
1098 | if ((*std & V4L2_STD_ALL) == 0) | |
1099 | return -EINVAL; | |
1100 | ||
1101 | if (*std == itv->std) | |
1102 | return 0; | |
1103 | ||
1104 | if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) || | |
1105 | atomic_read(&itv->capturing) > 0 || | |
1106 | atomic_read(&itv->decoding) > 0) { | |
1107 | /* Switching standard would turn off the radio or mess | |
1108 | with already running streams, prevent that by | |
1109 | returning EBUSY. */ | |
1110 | return -EBUSY; | |
1111 | } | |
1112 | ||
1113 | itv->std = *std; | |
1114 | itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; | |
1115 | itv->params.is_50hz = itv->is_50hz = !itv->is_60hz; | |
1116 | itv->params.width = 720; | |
1117 | itv->params.height = itv->is_50hz ? 576 : 480; | |
1118 | itv->vbi.count = itv->is_50hz ? 18 : 12; | |
1119 | itv->vbi.start[0] = itv->is_50hz ? 6 : 10; | |
1120 | itv->vbi.start[1] = itv->is_50hz ? 318 : 273; | |
1121 | ||
1122 | if (itv->hw_flags & IVTV_HW_CX25840) | |
1123 | itv->vbi.sliced_decoder_line_size = itv->is_60hz ? 272 : 284; | |
1124 | ||
1125 | IVTV_DEBUG_INFO("Switching standard to %llx.\n", (unsigned long long)itv->std); | |
1126 | ||
1127 | /* Tuner */ | |
1128 | ivtv_call_i2c_clients(itv, VIDIOC_S_STD, &itv->std); | |
1129 | ||
1130 | if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { | |
1131 | /* set display standard */ | |
1132 | itv->std_out = *std; | |
1133 | itv->is_out_60hz = itv->is_60hz; | |
1134 | itv->is_out_50hz = itv->is_50hz; | |
1135 | ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std_out); | |
1136 | ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz); | |
1137 | itv->main_rect.left = itv->main_rect.top = 0; | |
1138 | itv->main_rect.width = 720; | |
1139 | itv->main_rect.height = itv->params.height; | |
1140 | ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, | |
1141 | 720, itv->main_rect.height, 0, 0); | |
1142 | yi->main_rect = itv->main_rect; | |
1143 | if (!itv->osd_info) { | |
1144 | yi->osd_full_w = 720; | |
1145 | yi->osd_full_h = itv->is_out_50hz ? 576 : 480; | |
1146 | } | |
1147 | } | |
1148 | return 0; | |
1149 | } | |
1150 | ||
1151 | static int ivtv_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) | |
1152 | { | |
1153 | struct ivtv_open_id *id = fh; | |
1154 | struct ivtv *itv = id->itv; | |
1155 | ||
1156 | if (vt->index != 0) | |
1157 | return -EINVAL; | |
1158 | ||
1159 | ivtv_call_i2c_clients(itv, VIDIOC_S_TUNER, vt); | |
1160 | ||
1161 | return 0; | |
1162 | } | |
1163 | ||
1164 | static int ivtv_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt) | |
1165 | { | |
1166 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1167 | ||
1168 | if (vt->index != 0) | |
1169 | return -EINVAL; | |
1170 | ||
1171 | memset(vt, 0, sizeof(*vt)); | |
1172 | ivtv_call_i2c_clients(itv, VIDIOC_G_TUNER, vt); | |
1173 | ||
1174 | if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) { | |
1175 | strlcpy(vt->name, "ivtv Radio Tuner", sizeof(vt->name)); | |
1176 | vt->type = V4L2_TUNER_RADIO; | |
1177 | } else { | |
1178 | strlcpy(vt->name, "ivtv TV Tuner", sizeof(vt->name)); | |
1179 | vt->type = V4L2_TUNER_ANALOG_TV; | |
1a0adaf3 HV |
1180 | } |
1181 | ||
3f038d80 HV |
1182 | return 0; |
1183 | } | |
1a0adaf3 | 1184 | |
3f038d80 HV |
1185 | static int ivtv_g_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_sliced_vbi_cap *cap) |
1186 | { | |
1187 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1188 | int set = itv->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525; | |
1189 | int f, l; | |
1190 | enum v4l2_buf_type type = cap->type; | |
1191 | ||
1192 | memset(cap, 0, sizeof(*cap)); | |
1193 | cap->type = type; | |
1194 | if (type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { | |
1195 | for (f = 0; f < 2; f++) { | |
1196 | for (l = 0; l < 24; l++) { | |
1197 | if (valid_service_line(f, l, itv->is_50hz)) | |
1198 | cap->service_lines[f][l] = set; | |
1199 | } | |
1200 | } | |
1201 | return 0; | |
1202 | } | |
1203 | if (type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) { | |
1204 | if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_OUTPUT)) | |
1a0adaf3 | 1205 | return -EINVAL; |
3f038d80 HV |
1206 | if (itv->is_60hz) { |
1207 | cap->service_lines[0][21] = V4L2_SLICED_CAPTION_525; | |
1208 | cap->service_lines[1][21] = V4L2_SLICED_CAPTION_525; | |
1209 | } else { | |
1210 | cap->service_lines[0][23] = V4L2_SLICED_WSS_625; | |
1211 | cap->service_lines[0][16] = V4L2_SLICED_VPS; | |
1a0adaf3 | 1212 | } |
3f038d80 | 1213 | return 0; |
1a0adaf3 | 1214 | } |
3f038d80 HV |
1215 | return -EINVAL; |
1216 | } | |
1a0adaf3 | 1217 | |
3f038d80 HV |
1218 | static int ivtv_g_enc_index(struct file *file, void *fh, struct v4l2_enc_idx *idx) |
1219 | { | |
1220 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1221 | struct v4l2_enc_idx_entry *e = idx->entry; | |
1222 | int entries; | |
1223 | int i; | |
1a0adaf3 | 1224 | |
3f038d80 HV |
1225 | entries = (itv->pgm_info_write_idx + IVTV_MAX_PGM_INDEX - itv->pgm_info_read_idx) % |
1226 | IVTV_MAX_PGM_INDEX; | |
1227 | if (entries > V4L2_ENC_IDX_ENTRIES) | |
1228 | entries = V4L2_ENC_IDX_ENTRIES; | |
1229 | idx->entries = 0; | |
1230 | for (i = 0; i < entries; i++) { | |
1231 | *e = itv->pgm_info[(itv->pgm_info_read_idx + i) % IVTV_MAX_PGM_INDEX]; | |
1232 | if ((e->flags & V4L2_ENC_IDX_FRAME_MASK) <= V4L2_ENC_IDX_FRAME_B) { | |
1233 | idx->entries++; | |
1234 | e++; | |
1235 | } | |
1a0adaf3 | 1236 | } |
3f038d80 HV |
1237 | itv->pgm_info_read_idx = (itv->pgm_info_read_idx + idx->entries) % IVTV_MAX_PGM_INDEX; |
1238 | return 0; | |
1239 | } | |
1a0adaf3 | 1240 | |
3f038d80 HV |
1241 | static int ivtv_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc) |
1242 | { | |
1243 | struct ivtv_open_id *id = fh; | |
1244 | struct ivtv *itv = id->itv; | |
1a0adaf3 | 1245 | |
3f038d80 | 1246 | memset(&enc->raw, 0, sizeof(enc->raw)); |
1a0adaf3 | 1247 | |
3f038d80 HV |
1248 | switch (enc->cmd) { |
1249 | case V4L2_ENC_CMD_START: | |
1250 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); | |
1251 | enc->flags = 0; | |
1252 | return ivtv_start_capture(id); | |
1a0adaf3 | 1253 | |
3f038d80 HV |
1254 | case V4L2_ENC_CMD_STOP: |
1255 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); | |
1256 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; | |
1257 | ivtv_stop_capture(id, enc->flags & V4L2_ENC_CMD_STOP_AT_GOP_END); | |
1258 | return 0; | |
1a0adaf3 | 1259 | |
3f038d80 HV |
1260 | case V4L2_ENC_CMD_PAUSE: |
1261 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); | |
1262 | enc->flags = 0; | |
1a0adaf3 | 1263 | |
3f038d80 HV |
1264 | if (!atomic_read(&itv->capturing)) |
1265 | return -EPERM; | |
1266 | if (test_and_set_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags)) | |
1267 | return 0; | |
1a0adaf3 | 1268 | |
3f038d80 HV |
1269 | ivtv_mute(itv); |
1270 | ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 0); | |
1a0adaf3 | 1271 | break; |
1a0adaf3 | 1272 | |
3f038d80 HV |
1273 | case V4L2_ENC_CMD_RESUME: |
1274 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); | |
1275 | enc->flags = 0; | |
1a0adaf3 | 1276 | |
3f038d80 HV |
1277 | if (!atomic_read(&itv->capturing)) |
1278 | return -EPERM; | |
1a0adaf3 | 1279 | |
3f038d80 HV |
1280 | if (!test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags)) |
1281 | return 0; | |
1a0adaf3 | 1282 | |
3f038d80 HV |
1283 | ivtv_vapi(itv, CX2341X_ENC_PAUSE_ENCODER, 1, 1); |
1284 | ivtv_unmute(itv); | |
1a0adaf3 | 1285 | break; |
3f038d80 HV |
1286 | default: |
1287 | IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); | |
1288 | return -EINVAL; | |
1a0adaf3 HV |
1289 | } |
1290 | ||
3f038d80 HV |
1291 | return 0; |
1292 | } | |
1a0adaf3 | 1293 | |
3f038d80 HV |
1294 | static int ivtv_try_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *enc) |
1295 | { | |
1296 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1a0adaf3 | 1297 | |
3f038d80 | 1298 | memset(&enc->raw, 0, sizeof(enc->raw)); |
1a0adaf3 | 1299 | |
3f038d80 HV |
1300 | switch (enc->cmd) { |
1301 | case V4L2_ENC_CMD_START: | |
1302 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n"); | |
1303 | enc->flags = 0; | |
1304 | return 0; | |
1a0adaf3 | 1305 | |
3f038d80 HV |
1306 | case V4L2_ENC_CMD_STOP: |
1307 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n"); | |
1308 | enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; | |
1309 | return 0; | |
1a0adaf3 | 1310 | |
3f038d80 HV |
1311 | case V4L2_ENC_CMD_PAUSE: |
1312 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n"); | |
1313 | enc->flags = 0; | |
1314 | return 0; | |
1a0adaf3 | 1315 | |
3f038d80 HV |
1316 | case V4L2_ENC_CMD_RESUME: |
1317 | IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n"); | |
1318 | enc->flags = 0; | |
1319 | return 0; | |
1320 | default: | |
1321 | IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd); | |
1322 | return -EINVAL; | |
1a0adaf3 | 1323 | } |
3f038d80 | 1324 | } |
1a0adaf3 | 1325 | |
3f038d80 HV |
1326 | static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb) |
1327 | { | |
1328 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1329 | u32 data[CX2341X_MBOX_MAX_DATA]; | |
1330 | struct yuv_playback_info *yi = &itv->yuv_info; | |
1331 | ||
1332 | int pixfmt; | |
1333 | static u32 pixel_format[16] = { | |
1334 | V4L2_PIX_FMT_PAL8, /* Uses a 256-entry RGB colormap */ | |
1335 | V4L2_PIX_FMT_RGB565, | |
1336 | V4L2_PIX_FMT_RGB555, | |
1337 | V4L2_PIX_FMT_RGB444, | |
1338 | V4L2_PIX_FMT_RGB32, | |
1339 | 0, | |
1340 | 0, | |
1341 | 0, | |
1342 | V4L2_PIX_FMT_PAL8, /* Uses a 256-entry YUV colormap */ | |
1343 | V4L2_PIX_FMT_YUV565, | |
1344 | V4L2_PIX_FMT_YUV555, | |
1345 | V4L2_PIX_FMT_YUV444, | |
1346 | V4L2_PIX_FMT_YUV32, | |
1347 | 0, | |
1348 | 0, | |
1349 | 0, | |
1350 | }; | |
1351 | ||
1352 | memset(fb, 0, sizeof(*fb)); | |
1353 | ||
1354 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) | |
1a0adaf3 | 1355 | return -EINVAL; |
1a0adaf3 | 1356 | |
3f038d80 HV |
1357 | fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY | |
1358 | V4L2_FBUF_CAP_GLOBAL_ALPHA; | |
d4e7ee36 | 1359 | |
3f038d80 HV |
1360 | ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0); |
1361 | data[0] |= (read_reg(0x2a00) >> 7) & 0x40; | |
1362 | pixfmt = (data[0] >> 3) & 0xf; | |
d4e7ee36 | 1363 | |
3f038d80 HV |
1364 | fb->fmt.pixelformat = pixel_format[pixfmt]; |
1365 | fb->fmt.width = itv->osd_rect.width; | |
1366 | fb->fmt.height = itv->osd_rect.height; | |
1367 | fb->base = (void *)itv->osd_video_pbase; | |
d4e7ee36 | 1368 | |
3f038d80 HV |
1369 | if (itv->osd_chroma_key_state) |
1370 | fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY; | |
d4e7ee36 | 1371 | |
3f038d80 HV |
1372 | if (itv->osd_global_alpha_state) |
1373 | fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA; | |
d4e7ee36 | 1374 | |
3f038d80 | 1375 | pixfmt &= 7; |
d4e7ee36 | 1376 | |
3f038d80 HV |
1377 | /* no local alpha for RGB565 or unknown formats */ |
1378 | if (pixfmt == 1 || pixfmt > 4) | |
1379 | return 0; | |
1380 | ||
1381 | /* 16-bit formats have inverted local alpha */ | |
1382 | if (pixfmt == 2 || pixfmt == 3) | |
1383 | fb->capability |= V4L2_FBUF_CAP_LOCAL_INV_ALPHA; | |
1384 | else | |
1385 | fb->capability |= V4L2_FBUF_CAP_LOCAL_ALPHA; | |
1386 | ||
1387 | if (itv->osd_local_alpha_state) { | |
2d4d5f11 HV |
1388 | /* 16-bit formats have inverted local alpha */ |
1389 | if (pixfmt == 2 || pixfmt == 3) | |
3f038d80 | 1390 | fb->flags |= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA; |
2d4d5f11 | 1391 | else |
3f038d80 | 1392 | fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; |
d4e7ee36 | 1393 | } |
3f038d80 HV |
1394 | if (yi->track_osd) |
1395 | fb->flags |= V4L2_FBUF_FLAG_OVERLAY; | |
1396 | ||
1397 | return 0; | |
1398 | } | |
d4e7ee36 | 1399 | |
3f038d80 HV |
1400 | static int ivtv_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb) |
1401 | { | |
1402 | struct ivtv_open_id *id = fh; | |
1403 | struct ivtv *itv = id->itv; | |
1404 | struct yuv_playback_info *yi = &itv->yuv_info; | |
d4e7ee36 | 1405 | |
3f038d80 HV |
1406 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) |
1407 | return -EINVAL; | |
d4e7ee36 | 1408 | |
3f038d80 HV |
1409 | itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0; |
1410 | itv->osd_local_alpha_state = | |
1411 | (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0; | |
1412 | itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0; | |
1413 | ivtv_set_osd_alpha(itv); | |
1414 | yi->track_osd = (fb->flags & V4L2_FBUF_FLAG_OVERLAY) != 0; | |
7c03a448 | 1415 | |
3f038d80 HV |
1416 | return 0; |
1417 | } | |
1418 | ||
1419 | static int ivtv_overlay(struct file *file, void *fh, unsigned int on) | |
1420 | { | |
1421 | struct ivtv_open_id *id = fh; | |
1422 | struct ivtv *itv = id->itv; | |
7c03a448 | 1423 | |
3f038d80 HV |
1424 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) |
1425 | return -EINVAL; | |
1a0adaf3 | 1426 | |
3f038d80 | 1427 | ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, on != 0); |
1a0adaf3 | 1428 | |
3f038d80 HV |
1429 | return 0; |
1430 | } | |
1431 | ||
1432 | static int ivtv_log_status(struct file *file, void *fh) | |
1433 | { | |
1434 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; | |
1435 | u32 data[CX2341X_MBOX_MAX_DATA]; | |
1436 | ||
1437 | int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT; | |
1438 | struct v4l2_input vidin; | |
1439 | struct v4l2_audio audin; | |
1440 | int i; | |
1441 | ||
1442 | IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num); | |
1443 | IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name); | |
1444 | if (itv->hw_flags & IVTV_HW_TVEEPROM) { | |
1445 | struct tveeprom tv; | |
1446 | ||
1447 | ivtv_read_eeprom(itv, &tv); | |
1448 | } | |
1449 | ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL); | |
1450 | ivtv_get_input(itv, itv->active_input, &vidin); | |
1451 | ivtv_get_audio_input(itv, itv->audio_input, &audin); | |
1452 | IVTV_INFO("Video Input: %s\n", vidin.name); | |
1453 | IVTV_INFO("Audio Input: %s%s\n", audin.name, | |
1454 | (itv->dualwatch_stereo_mode & ~0x300) == 0x200 ? " (Bilingual)" : ""); | |
1455 | if (has_output) { | |
1456 | struct v4l2_output vidout; | |
1457 | struct v4l2_audioout audout; | |
1458 | int mode = itv->output_mode; | |
1459 | static const char * const output_modes[5] = { | |
1460 | "None", | |
1461 | "MPEG Streaming", | |
1462 | "YUV Streaming", | |
1463 | "YUV Frames", | |
1464 | "Passthrough", | |
1465 | }; | |
1466 | static const char * const audio_modes[5] = { | |
1467 | "Stereo", | |
1468 | "Left", | |
1469 | "Right", | |
1470 | "Mono", | |
1471 | "Swapped" | |
1472 | }; | |
1473 | static const char * const alpha_mode[4] = { | |
1474 | "None", | |
1475 | "Global", | |
1476 | "Local", | |
1477 | "Global and Local" | |
1478 | }; | |
1479 | static const char * const pixel_format[16] = { | |
1480 | "ARGB Indexed", | |
1481 | "RGB 5:6:5", | |
1482 | "ARGB 1:5:5:5", | |
1483 | "ARGB 1:4:4:4", | |
1484 | "ARGB 8:8:8:8", | |
1485 | "5", | |
1486 | "6", | |
1487 | "7", | |
1488 | "AYUV Indexed", | |
1489 | "YUV 5:6:5", | |
1490 | "AYUV 1:5:5:5", | |
1491 | "AYUV 1:4:4:4", | |
1492 | "AYUV 8:8:8:8", | |
1493 | "13", | |
1494 | "14", | |
1495 | "15", | |
1496 | }; | |
1497 | ||
1498 | ivtv_get_output(itv, itv->active_output, &vidout); | |
1499 | ivtv_get_audio_output(itv, 0, &audout); | |
1500 | IVTV_INFO("Video Output: %s\n", vidout.name); | |
1501 | IVTV_INFO("Audio Output: %s (Stereo/Bilingual: %s/%s)\n", audout.name, | |
1502 | audio_modes[itv->audio_stereo_mode], | |
1503 | audio_modes[itv->audio_bilingual_mode]); | |
1504 | if (mode < 0 || mode > OUT_PASSTHROUGH) | |
1505 | mode = OUT_NONE; | |
1506 | IVTV_INFO("Output Mode: %s\n", output_modes[mode]); | |
1507 | ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0); | |
1508 | data[0] |= (read_reg(0x2a00) >> 7) & 0x40; | |
1509 | IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n", | |
1510 | data[0] & 1 ? "On" : "Off", | |
1511 | alpha_mode[(data[0] >> 1) & 0x3], | |
1512 | pixel_format[(data[0] >> 3) & 0xf]); | |
1a0adaf3 | 1513 | } |
3f038d80 HV |
1514 | IVTV_INFO("Tuner: %s\n", |
1515 | test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); | |
1516 | cx2341x_log_status(&itv->params, itv->name); | |
1517 | IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags); | |
1518 | for (i = 0; i < IVTV_MAX_STREAMS; i++) { | |
1519 | struct ivtv_stream *s = &itv->streams[i]; | |
1a0adaf3 | 1520 | |
3f038d80 HV |
1521 | if (s->v4l2dev == NULL || s->buffers == 0) |
1522 | continue; | |
1523 | IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags, | |
1524 | (s->buffers - s->q_free.buffers) * 100 / s->buffers, | |
1525 | (s->buffers * s->buf_size) / 1024, s->buffers); | |
1a0adaf3 | 1526 | } |
3f038d80 HV |
1527 | |
1528 | IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n", (long long)itv->mpg_data_received, (long long)itv->vbi_data_inserted); | |
1529 | IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num); | |
1530 | ||
1a0adaf3 HV |
1531 | return 0; |
1532 | } | |
1533 | ||
d4e7ee36 | 1534 | static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg) |
1a0adaf3 HV |
1535 | { |
1536 | struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; | |
1537 | struct ivtv *itv = id->itv; | |
1538 | int nonblocking = filp->f_flags & O_NONBLOCK; | |
1539 | struct ivtv_stream *s = &itv->streams[id->type]; | |
1540 | ||
1541 | switch (cmd) { | |
1542 | case IVTV_IOC_DMA_FRAME: { | |
1543 | struct ivtv_dma_frame *args = arg; | |
1544 | ||
1545 | IVTV_DEBUG_IOCTL("IVTV_IOC_DMA_FRAME\n"); | |
1546 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
1547 | return -EINVAL; | |
1548 | if (args->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) | |
1549 | return -EINVAL; | |
1550 | if (itv->output_mode == OUT_UDMA_YUV && args->y_source == NULL) | |
1551 | return 0; | |
1552 | if (ivtv_claim_stream(id, id->type)) { | |
1553 | return -EBUSY; | |
1554 | } | |
1555 | if (ivtv_set_output_mode(itv, OUT_UDMA_YUV) != OUT_UDMA_YUV) { | |
1556 | ivtv_release_stream(s); | |
1557 | return -EBUSY; | |
1558 | } | |
ad8ff0f1 HV |
1559 | /* Mark that this file handle started the UDMA_YUV mode */ |
1560 | id->yuv_frames = 1; | |
1a0adaf3 HV |
1561 | if (args->y_source == NULL) |
1562 | return 0; | |
1563 | return ivtv_yuv_prep_frame(itv, args); | |
1564 | } | |
1565 | ||
1566 | case VIDEO_GET_PTS: { | |
1567 | u32 data[CX2341X_MBOX_MAX_DATA]; | |
1568 | u64 *pts = arg; | |
1569 | ||
1570 | IVTV_DEBUG_IOCTL("VIDEO_GET_PTS\n"); | |
1571 | if (s->type < IVTV_DEC_STREAM_TYPE_MPG) { | |
1572 | *pts = s->dma_pts; | |
1573 | break; | |
1574 | } | |
1575 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
1576 | return -EINVAL; | |
1577 | ||
1578 | if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) { | |
1579 | *pts = (u64) ((u64)itv->last_dec_timing[2] << 32) | | |
1580 | (u64)itv->last_dec_timing[1]; | |
1581 | break; | |
1582 | } | |
1583 | *pts = 0; | |
1584 | if (atomic_read(&itv->decoding)) { | |
1585 | if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) { | |
1586 | IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n"); | |
1587 | return -EIO; | |
1588 | } | |
1589 | memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing)); | |
1590 | set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags); | |
1591 | *pts = (u64) ((u64) data[2] << 32) | (u64) data[1]; | |
1592 | /*timing->scr = (u64) (((u64) data[4] << 32) | (u64) (data[3]));*/ | |
1593 | } | |
1594 | break; | |
1595 | } | |
1596 | ||
1597 | case VIDEO_GET_FRAME_COUNT: { | |
1598 | u32 data[CX2341X_MBOX_MAX_DATA]; | |
1599 | u64 *frame = arg; | |
1600 | ||
1601 | IVTV_DEBUG_IOCTL("VIDEO_GET_FRAME_COUNT\n"); | |
1602 | if (s->type < IVTV_DEC_STREAM_TYPE_MPG) { | |
1603 | *frame = 0; | |
1604 | break; | |
1605 | } | |
1606 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
1607 | return -EINVAL; | |
1608 | ||
1609 | if (test_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags)) { | |
1610 | *frame = itv->last_dec_timing[0]; | |
1611 | break; | |
1612 | } | |
1613 | *frame = 0; | |
1614 | if (atomic_read(&itv->decoding)) { | |
1615 | if (ivtv_api(itv, CX2341X_DEC_GET_TIMING_INFO, 5, data)) { | |
1616 | IVTV_DEBUG_WARN("GET_TIMING: couldn't read clock\n"); | |
1617 | return -EIO; | |
1618 | } | |
1619 | memcpy(itv->last_dec_timing, data, sizeof(itv->last_dec_timing)); | |
1620 | set_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags); | |
1621 | *frame = data[0]; | |
1622 | } | |
1623 | break; | |
1624 | } | |
1625 | ||
1626 | case VIDEO_PLAY: { | |
1627 | struct video_command vc; | |
1628 | ||
1629 | IVTV_DEBUG_IOCTL("VIDEO_PLAY\n"); | |
1630 | memset(&vc, 0, sizeof(vc)); | |
1631 | vc.cmd = VIDEO_CMD_PLAY; | |
1632 | return ivtv_video_command(itv, id, &vc, 0); | |
1633 | } | |
1634 | ||
1635 | case VIDEO_STOP: { | |
1636 | struct video_command vc; | |
1637 | ||
1638 | IVTV_DEBUG_IOCTL("VIDEO_STOP\n"); | |
1639 | memset(&vc, 0, sizeof(vc)); | |
1640 | vc.cmd = VIDEO_CMD_STOP; | |
1641 | vc.flags = VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY; | |
1642 | return ivtv_video_command(itv, id, &vc, 0); | |
1643 | } | |
1644 | ||
1645 | case VIDEO_FREEZE: { | |
1646 | struct video_command vc; | |
1647 | ||
1648 | IVTV_DEBUG_IOCTL("VIDEO_FREEZE\n"); | |
1649 | memset(&vc, 0, sizeof(vc)); | |
1650 | vc.cmd = VIDEO_CMD_FREEZE; | |
1651 | return ivtv_video_command(itv, id, &vc, 0); | |
1652 | } | |
1653 | ||
1654 | case VIDEO_CONTINUE: { | |
1655 | struct video_command vc; | |
1656 | ||
1657 | IVTV_DEBUG_IOCTL("VIDEO_CONTINUE\n"); | |
1658 | memset(&vc, 0, sizeof(vc)); | |
1659 | vc.cmd = VIDEO_CMD_CONTINUE; | |
1660 | return ivtv_video_command(itv, id, &vc, 0); | |
1661 | } | |
1662 | ||
1663 | case VIDEO_COMMAND: | |
1664 | case VIDEO_TRY_COMMAND: { | |
1665 | struct video_command *vc = arg; | |
1666 | int try = (cmd == VIDEO_TRY_COMMAND); | |
1667 | ||
1668 | if (try) | |
1aa32c2f | 1669 | IVTV_DEBUG_IOCTL("VIDEO_TRY_COMMAND %d\n", vc->cmd); |
1a0adaf3 | 1670 | else |
1aa32c2f | 1671 | IVTV_DEBUG_IOCTL("VIDEO_COMMAND %d\n", vc->cmd); |
1a0adaf3 HV |
1672 | return ivtv_video_command(itv, id, vc, try); |
1673 | } | |
1674 | ||
1675 | case VIDEO_GET_EVENT: { | |
1676 | struct video_event *ev = arg; | |
1677 | DEFINE_WAIT(wait); | |
1678 | ||
1679 | IVTV_DEBUG_IOCTL("VIDEO_GET_EVENT\n"); | |
1680 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
1681 | return -EINVAL; | |
1682 | memset(ev, 0, sizeof(*ev)); | |
1683 | set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); | |
1684 | ||
1685 | while (1) { | |
1686 | if (test_and_clear_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags)) | |
1687 | ev->type = VIDEO_EVENT_DECODER_STOPPED; | |
1688 | else if (test_and_clear_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags)) { | |
1689 | ev->type = VIDEO_EVENT_VSYNC; | |
037c86c5 HV |
1690 | ev->u.vsync_field = test_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags) ? |
1691 | VIDEO_VSYNC_FIELD_ODD : VIDEO_VSYNC_FIELD_EVEN; | |
1692 | if (itv->output_mode == OUT_UDMA_YUV && | |
1693 | (itv->yuv_info.lace_mode & IVTV_YUV_MODE_MASK) == | |
1694 | IVTV_YUV_MODE_PROGRESSIVE) { | |
1695 | ev->u.vsync_field = VIDEO_VSYNC_FIELD_PROGRESSIVE; | |
1696 | } | |
1a0adaf3 HV |
1697 | } |
1698 | if (ev->type) | |
1699 | return 0; | |
1700 | if (nonblocking) | |
1701 | return -EAGAIN; | |
baa4072d HV |
1702 | /* Wait for event. Note that serialize_lock is locked, |
1703 | so to allow other processes to access the driver while | |
1704 | we are waiting unlock first and later lock again. */ | |
1705 | mutex_unlock(&itv->serialize_lock); | |
1a0adaf3 HV |
1706 | prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE); |
1707 | if ((itv->i_flags & (IVTV_F_I_EV_DEC_STOPPED|IVTV_F_I_EV_VSYNC)) == 0) | |
1708 | schedule(); | |
1709 | finish_wait(&itv->event_waitq, &wait); | |
baa4072d | 1710 | mutex_lock(&itv->serialize_lock); |
1a0adaf3 HV |
1711 | if (signal_pending(current)) { |
1712 | /* return if a signal was received */ | |
1713 | IVTV_DEBUG_INFO("User stopped wait for event\n"); | |
1714 | return -EINTR; | |
1715 | } | |
1716 | } | |
1717 | break; | |
1718 | } | |
1719 | ||
1a0adaf3 HV |
1720 | default: |
1721 | return -EINVAL; | |
1722 | } | |
1723 | return 0; | |
1724 | } | |
1725 | ||
3f038d80 | 1726 | static int ivtv_default(struct file *file, void *fh, int cmd, void *arg) |
1a0adaf3 | 1727 | { |
3f038d80 | 1728 | struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; |
d46c17d7 | 1729 | |
1a0adaf3 | 1730 | switch (cmd) { |
3f038d80 HV |
1731 | case VIDIOC_INT_S_AUDIO_ROUTING: { |
1732 | struct v4l2_routing *route = arg; | |
1a0adaf3 | 1733 | |
3f038d80 HV |
1734 | ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, route); |
1735 | break; | |
1736 | } | |
1a0adaf3 | 1737 | |
3f038d80 HV |
1738 | case VIDIOC_INT_RESET: { |
1739 | u32 val = *(u32 *)arg; | |
1a0adaf3 | 1740 | |
3f038d80 HV |
1741 | if ((val == 0 && itv->options.newi2c) || (val & 0x01)) |
1742 | ivtv_reset_ir_gpio(itv); | |
1743 | if (val & 0x02) | |
1744 | itv->video_dec_func(itv, cmd, NULL); | |
1745 | break; | |
1746 | } | |
1a0adaf3 | 1747 | |
1a0adaf3 | 1748 | default: |
3f038d80 | 1749 | return -EINVAL; |
1a0adaf3 HV |
1750 | } |
1751 | return 0; | |
1752 | } | |
1753 | ||
baa4072d HV |
1754 | static int ivtv_serialized_ioctl(struct ivtv *itv, struct inode *inode, struct file *filp, |
1755 | unsigned int cmd, unsigned long arg) | |
1a0adaf3 | 1756 | { |
3f038d80 HV |
1757 | struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; |
1758 | int ret; | |
1759 | ||
1760 | /* Filter dvb ioctls that cannot be handled by the v4l ioctl framework */ | |
1a0adaf3 HV |
1761 | switch (cmd) { |
1762 | case VIDEO_SELECT_SOURCE: | |
1763 | IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n"); | |
1764 | if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) | |
1765 | return -EINVAL; | |
1766 | return ivtv_passthrough_mode(itv, arg == VIDEO_SOURCE_DEMUX); | |
1767 | ||
1768 | case AUDIO_SET_MUTE: | |
1769 | IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n"); | |
1770 | itv->speed_mute_audio = arg; | |
1771 | return 0; | |
1772 | ||
1773 | case AUDIO_CHANNEL_SELECT: | |
1774 | IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n"); | |
1775 | if (arg > AUDIO_STEREO_SWAPPED) | |
1776 | return -EINVAL; | |
1777 | itv->audio_stereo_mode = arg; | |
1778 | ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode); | |
1779 | return 0; | |
1780 | ||
1781 | case AUDIO_BILINGUAL_CHANNEL_SELECT: | |
1782 | IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n"); | |
1783 | if (arg > AUDIO_STEREO_SWAPPED) | |
1784 | return -EINVAL; | |
1785 | itv->audio_bilingual_mode = arg; | |
1786 | ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode); | |
1787 | return 0; | |
1788 | ||
3f038d80 HV |
1789 | case IVTV_IOC_DMA_FRAME: |
1790 | case VIDEO_GET_PTS: | |
1791 | case VIDEO_GET_FRAME_COUNT: | |
1792 | case VIDEO_GET_EVENT: | |
1793 | case VIDEO_PLAY: | |
1794 | case VIDEO_STOP: | |
1795 | case VIDEO_FREEZE: | |
1796 | case VIDEO_CONTINUE: | |
1797 | case VIDEO_COMMAND: | |
1798 | case VIDEO_TRY_COMMAND: | |
1799 | return ivtv_decoder_ioctls(filp, cmd, (void *)arg); | |
1800 | ||
1a0adaf3 HV |
1801 | default: |
1802 | break; | |
1803 | } | |
3f038d80 HV |
1804 | |
1805 | /* check priority */ | |
1806 | switch (cmd) { | |
1807 | case VIDIOC_S_CTRL: | |
1808 | case VIDIOC_S_STD: | |
1809 | case VIDIOC_S_INPUT: | |
1810 | case VIDIOC_S_OUTPUT: | |
1811 | case VIDIOC_S_TUNER: | |
1812 | case VIDIOC_S_FREQUENCY: | |
1813 | case VIDIOC_S_FMT: | |
1814 | case VIDIOC_S_CROP: | |
1815 | case VIDIOC_S_AUDIO: | |
1816 | case VIDIOC_S_AUDOUT: | |
1817 | case VIDIOC_S_EXT_CTRLS: | |
1818 | case VIDIOC_S_FBUF: | |
1819 | case VIDIOC_OVERLAY: | |
1820 | ret = v4l2_prio_check(&itv->prio, &id->prio); | |
1821 | if (ret) | |
1822 | return ret; | |
1823 | } | |
1824 | ||
1825 | if (ivtv_debug & IVTV_DBGFLG_IOCTL) { | |
1826 | printk(KERN_INFO "ivtv%d ioctl: ", itv->num); | |
1827 | v4l_printk_ioctl(cmd); | |
1828 | printk("\n"); | |
1829 | } | |
1830 | ||
1831 | return video_ioctl2(inode, filp, cmd, arg); | |
1a0adaf3 | 1832 | } |
baa4072d HV |
1833 | |
1834 | int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, | |
1835 | unsigned long arg) | |
1836 | { | |
1837 | struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; | |
1838 | struct ivtv *itv = id->itv; | |
1839 | int res; | |
1840 | ||
1841 | mutex_lock(&itv->serialize_lock); | |
1842 | res = ivtv_serialized_ioctl(itv, inode, filp, cmd, arg); | |
1843 | mutex_unlock(&itv->serialize_lock); | |
1844 | return res; | |
1845 | } | |
3f038d80 HV |
1846 | |
1847 | void ivtv_set_funcs(struct video_device *vdev) | |
1848 | { | |
1849 | vdev->vidioc_querycap = ivtv_querycap; | |
1850 | vdev->vidioc_g_priority = ivtv_g_priority; | |
1851 | vdev->vidioc_s_priority = ivtv_s_priority; | |
1852 | vdev->vidioc_s_audio = ivtv_s_audio; | |
1853 | vdev->vidioc_g_audio = ivtv_g_audio; | |
1854 | vdev->vidioc_enumaudio = ivtv_enumaudio; | |
1855 | vdev->vidioc_s_audout = ivtv_s_audout; | |
1856 | vdev->vidioc_g_audout = ivtv_g_audout; | |
1857 | vdev->vidioc_enum_input = ivtv_enum_input; | |
1858 | vdev->vidioc_enum_output = ivtv_enum_output; | |
1859 | vdev->vidioc_enumaudout = ivtv_enumaudout; | |
1860 | vdev->vidioc_cropcap = ivtv_cropcap; | |
1861 | vdev->vidioc_s_crop = ivtv_s_crop; | |
1862 | vdev->vidioc_g_crop = ivtv_g_crop; | |
1863 | vdev->vidioc_g_input = ivtv_g_input; | |
1864 | vdev->vidioc_s_input = ivtv_s_input; | |
1865 | vdev->vidioc_g_output = ivtv_g_output; | |
1866 | vdev->vidioc_s_output = ivtv_s_output; | |
1867 | vdev->vidioc_g_frequency = ivtv_g_frequency; | |
1868 | vdev->vidioc_s_frequency = ivtv_s_frequency; | |
1869 | vdev->vidioc_s_tuner = ivtv_s_tuner; | |
1870 | vdev->vidioc_g_tuner = ivtv_g_tuner; | |
1871 | vdev->vidioc_g_enc_index = ivtv_g_enc_index; | |
1872 | vdev->vidioc_g_fbuf = ivtv_g_fbuf; | |
1873 | vdev->vidioc_s_fbuf = ivtv_s_fbuf; | |
1874 | vdev->vidioc_g_std = ivtv_g_std; | |
1875 | vdev->vidioc_s_std = ivtv_s_std; | |
1876 | vdev->vidioc_overlay = ivtv_overlay; | |
1877 | vdev->vidioc_log_status = ivtv_log_status; | |
1878 | vdev->vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap; | |
1879 | vdev->vidioc_encoder_cmd = ivtv_encoder_cmd; | |
1880 | vdev->vidioc_try_encoder_cmd = ivtv_try_encoder_cmd; | |
1881 | vdev->vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out; | |
1882 | vdev->vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap; | |
1883 | vdev->vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap; | |
1884 | vdev->vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap; | |
1885 | vdev->vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out; | |
1886 | vdev->vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay; | |
1887 | vdev->vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out; | |
1888 | vdev->vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap; | |
1889 | vdev->vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap; | |
1890 | vdev->vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap; | |
1891 | vdev->vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out; | |
1892 | vdev->vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay; | |
1893 | vdev->vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out; | |
1894 | vdev->vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap; | |
1895 | vdev->vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap; | |
1896 | vdev->vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap; | |
1897 | vdev->vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out; | |
1898 | vdev->vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay; | |
1899 | vdev->vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out; | |
1900 | vdev->vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap; | |
1901 | vdev->vidioc_g_chip_ident = ivtv_g_chip_ident; | |
1902 | vdev->vidioc_g_register = ivtv_g_register; | |
1903 | vdev->vidioc_s_register = ivtv_s_register; | |
1904 | vdev->vidioc_default = ivtv_default; | |
1905 | vdev->vidioc_queryctrl = ivtv_queryctrl; | |
1906 | vdev->vidioc_querymenu = ivtv_querymenu; | |
1907 | vdev->vidioc_g_ctrl = ivtv_g_ctrl; | |
1908 | vdev->vidioc_s_ctrl = ivtv_s_ctrl; | |
1909 | vdev->vidioc_g_ext_ctrls = ivtv_g_ext_ctrls; | |
1910 | vdev->vidioc_s_ext_ctrls = ivtv_s_ext_ctrls; | |
1911 | vdev->vidioc_try_ext_ctrls = ivtv_try_ext_ctrls; | |
1912 | } |