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