Lines Matching +full:dual +full:- +full:radio
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
6 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
10 #include "ivtv-driver.h"
11 #include "ivtv-fileops.h"
12 #include "ivtv-i2c.h"
13 #include "ivtv-queue.h"
14 #include "ivtv-udma.h"
15 #include "ivtv-irq.h"
16 #include "ivtv-vbi.h"
17 #include "ivtv-mailbox.h"
18 #include "ivtv-routing.h"
19 #include "ivtv-streams.h"
20 #include "ivtv-yuv.h"
21 #include "ivtv-ioctl.h"
22 #include "ivtv-cards.h"
23 #include "ivtv-firmware.h"
25 #include <media/v4l2-event.h>
31 Possible error returns: -EBUSY if someone else has claimed
35 struct ivtv *itv = id->itv; in ivtv_claim_stream()
36 struct ivtv_stream *s = &itv->streams[type]; in ivtv_claim_stream()
40 if (test_and_set_bit(IVTV_F_S_CLAIMED, &s->s_flags)) { in ivtv_claim_stream()
42 if (s->fh == &id->fh) { in ivtv_claim_stream()
46 if (s->fh == NULL && (type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_claim_stream()
51 s->fh = &id->fh; in ivtv_claim_stream()
57 return -EBUSY; in ivtv_claim_stream()
59 s->fh = &id->fh; in ivtv_claim_stream()
72 itv->vbi.insert_mpeg && !ivtv_raw_vbi(itv)) { in ivtv_claim_stream()
77 s_vbi = &itv->streams[vbi_type]; in ivtv_claim_stream()
79 if (!test_and_set_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags)) { in ivtv_claim_stream()
85 set_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags); in ivtv_claim_stream()
94 struct ivtv *itv = s->itv; in ivtv_release_stream()
97 s->fh = NULL; in ivtv_release_stream()
98 if ((s->type == IVTV_DEC_STREAM_TYPE_VBI || s->type == IVTV_ENC_STREAM_TYPE_VBI) && in ivtv_release_stream()
99 test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { in ivtv_release_stream()
103 if (!test_and_clear_bit(IVTV_F_S_CLAIMED, &s->s_flags)) { in ivtv_release_stream()
104 IVTV_DEBUG_WARN("Release stream %s not in use!\n", s->name); in ivtv_release_stream()
111 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) in ivtv_release_stream()
117 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_release_stream()
118 s_vbi = &itv->streams[IVTV_DEC_STREAM_TYPE_VBI]; in ivtv_release_stream()
119 else if (s->type == IVTV_ENC_STREAM_TYPE_MPG) in ivtv_release_stream()
120 s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_release_stream()
125 if (!test_and_clear_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags)) { in ivtv_release_stream()
129 if (s_vbi->fh) { in ivtv_release_stream()
134 if (s_vbi->type == IVTV_DEC_STREAM_TYPE_VBI) in ivtv_release_stream()
136 clear_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags); in ivtv_release_stream()
145 const u32 dual = 0x02; in ivtv_dualwatch() local
147 new_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode); in ivtv_dualwatch()
151 new_stereo_mode = dual; in ivtv_dualwatch()
153 if (new_stereo_mode == itv->dualwatch_stereo_mode) in ivtv_dualwatch()
157 itv->dualwatch_stereo_mode, new_stereo_mode); in ivtv_dualwatch()
158 if (v4l2_ctrl_s_ctrl(itv->cxhdl.audio_mode, new_stereo_mode)) in ivtv_dualwatch()
164 u32 wr_idx = (read_enc(itv->pgm_info_offset) - itv->pgm_info_offset - 4) / 24; in ivtv_update_pgm_info()
168 if (wr_idx >= itv->pgm_info_num) { in ivtv_update_pgm_info()
169 IVTV_DEBUG_WARN("Invalid PGM index %d (>= %d)\n", wr_idx, itv->pgm_info_num); in ivtv_update_pgm_info()
172 cnt = (wr_idx + itv->pgm_info_num - itv->pgm_info_write_idx) % itv->pgm_info_num; in ivtv_update_pgm_info()
174 int idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num; in ivtv_update_pgm_info()
175 struct v4l2_enc_idx_entry *e = itv->pgm_info + idx; in ivtv_update_pgm_info()
176 u32 addr = itv->pgm_info_offset + 4 + idx * 24; in ivtv_update_pgm_info()
177 const int mapping[8] = { -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P, -1, in ivtv_update_pgm_info()
178 V4L2_ENC_IDX_FRAME_B, -1, -1, -1 }; in ivtv_update_pgm_info()
181 e->offset = read_enc(addr + 4) + ((u64)read_enc(addr + 8) << 32); in ivtv_update_pgm_info()
182 if (e->offset > itv->mpg_data_received) { in ivtv_update_pgm_info()
185 e->offset += itv->vbi_data_inserted; in ivtv_update_pgm_info()
186 e->length = read_enc(addr); in ivtv_update_pgm_info()
187 e->pts = read_enc(addr + 16) + ((u64)(read_enc(addr + 20) & 1) << 32); in ivtv_update_pgm_info()
188 e->flags = mapping[read_enc(addr + 12) & 7]; in ivtv_update_pgm_info()
191 itv->pgm_info_write_idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num; in ivtv_update_pgm_info()
196 struct ivtv *itv = s->itv; in ivtv_schedule()
199 lockdep_assert_held(&itv->serialize_lock); in ivtv_schedule()
201 mutex_unlock(&itv->serialize_lock); in ivtv_schedule()
202 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); in ivtv_schedule()
204 if (!s->q_free.buffers) in ivtv_schedule()
206 finish_wait(&s->waitq, &wait); in ivtv_schedule()
207 mutex_lock(&itv->serialize_lock); in ivtv_schedule()
212 struct ivtv *itv = s->itv; in ivtv_get_buffer()
213 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_get_buffer()
218 if (s->type == IVTV_ENC_STREAM_TYPE_MPG) { in ivtv_get_buffer()
223 itv->dualwatch_jiffies + in ivtv_get_buffer()
225 itv->dualwatch_jiffies = jiffies; in ivtv_get_buffer()
229 if (test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) && in ivtv_get_buffer()
230 !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) { in ivtv_get_buffer()
231 while ((buf = ivtv_dequeue(s_vbi, &s_vbi->q_full))) { in ivtv_get_buffer()
233 ivtv_process_vbi_data(itv, buf, s_vbi->dma_pts, s_vbi->type); in ivtv_get_buffer()
234 ivtv_enqueue(s_vbi, buf, &s_vbi->q_free); in ivtv_get_buffer()
237 buf = &itv->vbi.sliced_mpeg_buf; in ivtv_get_buffer()
238 if (buf->readpos != buf->bytesused) { in ivtv_get_buffer()
244 buf = ivtv_dequeue(s, &s->q_io); in ivtv_get_buffer()
249 buf = ivtv_dequeue(s, &s->q_full); in ivtv_get_buffer()
251 if ((buf->b_flags & IVTV_F_B_NEED_BUF_SWAP) == 0) in ivtv_get_buffer()
253 buf->b_flags &= ~IVTV_F_B_NEED_BUF_SWAP; in ivtv_get_buffer()
254 if (s->type == IVTV_ENC_STREAM_TYPE_MPG) in ivtv_get_buffer()
257 else if (s->type != IVTV_DEC_STREAM_TYPE_VBI) { in ivtv_get_buffer()
259 ivtv_process_vbi_data(itv, buf, s->dma_pts, s->type); in ivtv_get_buffer()
265 if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_get_buffer()
266 IVTV_DEBUG_INFO("EOS %s\n", s->name); in ivtv_get_buffer()
272 *err = -EAGAIN; in ivtv_get_buffer()
280 IVTV_DEBUG_INFO("User stopped %s\n", s->name); in ivtv_get_buffer()
281 *err = -EINTR; in ivtv_get_buffer()
289 int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES; in ivtv_setup_sliced_vbi_buf()
291 itv->vbi.sliced_mpeg_buf.buf = itv->vbi.sliced_mpeg_data[idx]; in ivtv_setup_sliced_vbi_buf()
292 itv->vbi.sliced_mpeg_buf.bytesused = itv->vbi.sliced_mpeg_size[idx]; in ivtv_setup_sliced_vbi_buf()
293 itv->vbi.sliced_mpeg_buf.readpos = 0; in ivtv_setup_sliced_vbi_buf()
299 struct ivtv *itv = s->itv; in ivtv_copy_buf_to_user()
300 size_t len = buf->bytesused - buf->readpos; in ivtv_copy_buf_to_user()
303 if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_copy_buf_to_user()
304 !ivtv_raw_vbi(itv) && buf != &itv->vbi.sliced_mpeg_buf) { in ivtv_copy_buf_to_user()
305 const char *start = buf->buf + buf->readpos; in ivtv_copy_buf_to_user()
308 u8 ch = itv->search_pack_header ? 0xba : 0xe0; in ivtv_copy_buf_to_user()
311 while (start + len > p && (q = memchr(p, 0, start + len - p))) { in ivtv_copy_buf_to_user()
313 if ((char *)q + 15 >= buf->buf + buf->bytesused || in ivtv_copy_buf_to_user()
317 if (!itv->search_pack_header) { in ivtv_copy_buf_to_user()
323 itv->search_pack_header = 1; in ivtv_copy_buf_to_user()
336 itv->search_pack_header = 0; in ivtv_copy_buf_to_user()
337 len = (char *)q - start; in ivtv_copy_buf_to_user()
343 if (copy_to_user(ubuf, (u8 *)buf->buf + buf->readpos, len)) { in ivtv_copy_buf_to_user()
344 IVTV_DEBUG_WARN("copy %zd bytes to user failed for %s\n", len, s->name); in ivtv_copy_buf_to_user()
345 return -EFAULT; in ivtv_copy_buf_to_user()
347 /*IVTV_INFO("copied %lld %d %d %d %d %d vbi %d\n", itv->mpg_data_received, len, ucount, in ivtv_copy_buf_to_user()
348 buf->readpos, buf->bytesused, buf->bytesused - buf->readpos - len, in ivtv_copy_buf_to_user()
349 buf == &itv->vbi.sliced_mpeg_buf); */ in ivtv_copy_buf_to_user()
350 buf->readpos += len; in ivtv_copy_buf_to_user()
351 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && buf != &itv->vbi.sliced_mpeg_buf) in ivtv_copy_buf_to_user()
352 itv->mpg_data_received += len; in ivtv_copy_buf_to_user()
358 struct ivtv *itv = s->itv; in ivtv_read()
362 if (atomic_read(&itv->capturing) == 0 && s->fh == NULL) { in ivtv_read()
364 IVTV_DEBUG_WARN("Stream %s not initialized before read\n", s->name); in ivtv_read()
365 return -EIO; in ivtv_read()
369 arrive one-by-one, so make sure we never output more than one VBI frame at a time */ in ivtv_read()
370 if (s->type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_read()
371 (s->type == IVTV_ENC_STREAM_TYPE_VBI && !ivtv_raw_vbi(itv))) in ivtv_read()
386 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_read()
387 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_read()
393 rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written); in ivtv_read()
394 if (buf != &itv->vbi.sliced_mpeg_buf) { in ivtv_read()
395 ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io); in ivtv_read()
397 else if (buf->readpos == buf->bytesused) { in ivtv_read()
398 int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES; in ivtv_read()
399 itv->vbi.sliced_mpeg_size[idx] = 0; in ivtv_read()
400 itv->vbi.inserted_frame++; in ivtv_read()
401 itv->vbi_data_inserted += buf->bytesused; in ivtv_read()
417 struct ivtv *itv = s->itv; in ivtv_read_pos()
419 IVTV_DEBUG_HI_FILE("read %zd from %s, got %zd\n", count, s->name, rc); in ivtv_read_pos()
427 struct ivtv *itv = id->itv; in ivtv_start_capture()
428 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_start_capture()
431 if (s->type == IVTV_ENC_STREAM_TYPE_RAD || in ivtv_start_capture()
432 s->type == IVTV_DEC_STREAM_TYPE_MPG || in ivtv_start_capture()
433 s->type == IVTV_DEC_STREAM_TYPE_YUV || in ivtv_start_capture()
434 s->type == IVTV_DEC_STREAM_TYPE_VOUT) { in ivtv_start_capture()
436 return -EINVAL; in ivtv_start_capture()
440 if (ivtv_claim_stream(id, s->type)) in ivtv_start_capture()
441 return -EBUSY; in ivtv_start_capture()
444 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) { in ivtv_start_capture()
445 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
451 …if (test_bit(IVTV_F_S_STREAMOFF, &s->s_flags) || test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)… in ivtv_start_capture()
452 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
457 s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_start_capture()
458 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_start_capture()
459 test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) && in ivtv_start_capture()
460 !test_and_set_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) { in ivtv_start_capture()
468 clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags); in ivtv_start_capture()
469 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_start_capture()
472 return -EIO; in ivtv_start_capture()
480 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
482 if (test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags)) in ivtv_start_capture()
488 IVTV_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name); in ivtv_start_capture()
493 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_start_capture()
494 test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) { in ivtv_start_capture()
496 clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags); in ivtv_start_capture()
498 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_start_capture()
500 return -EIO; in ivtv_start_capture()
505 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_read()
506 struct ivtv *itv = id->itv; in ivtv_v4l2_read()
507 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_read()
510 IVTV_DEBUG_HI_FILE("read %zd bytes from %s\n", count, s->name); in ivtv_v4l2_read()
512 if (mutex_lock_interruptible(&itv->serialize_lock)) in ivtv_v4l2_read()
513 return -ERESTARTSYS; in ivtv_v4l2_read()
516 rc = ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK); in ivtv_v4l2_read()
517 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_read()
523 struct ivtv *itv = id->itv; in ivtv_start_decoding()
524 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_start_decoding()
527 if (atomic_read(&itv->decoding) == 0) { in ivtv_start_decoding()
528 if (ivtv_claim_stream(id, s->type)) { in ivtv_start_decoding()
531 return -EBUSY; in ivtv_start_decoding()
535 if (rc == -EAGAIN) in ivtv_start_decoding()
541 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_start_decoding()
548 struct ivtv *itv = s->itv; in ivtv_schedule_dma()
552 lockdep_assert_held(&itv->serialize_lock); in ivtv_schedule_dma()
554 mutex_unlock(&itv->serialize_lock); in ivtv_schedule_dma()
555 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE); in ivtv_schedule_dma()
557 test_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) in ivtv_schedule_dma()
559 finish_wait(&itv->dma_waitq, &wait); in ivtv_schedule_dma()
560 mutex_lock(&itv->serialize_lock); in ivtv_schedule_dma()
567 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_write()
568 struct ivtv *itv = id->itv; in ivtv_write()
569 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_write()
570 struct yuv_playback_info *yi = &itv->yuv_info; in ivtv_write()
577 IVTV_DEBUG_HI_FILE("write %zd bytes to %s\n", count, s->name); in ivtv_write()
579 if (s->type != IVTV_DEC_STREAM_TYPE_MPG && in ivtv_write()
580 s->type != IVTV_DEC_STREAM_TYPE_YUV && in ivtv_write()
581 s->type != IVTV_DEC_STREAM_TYPE_VOUT) in ivtv_write()
583 return -EINVAL; in ivtv_write()
586 if (ivtv_claim_stream(id, s->type)) in ivtv_write()
587 return -EBUSY; in ivtv_write()
590 if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) { in ivtv_write()
593 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
598 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV; in ivtv_write()
602 return -EBUSY; in ivtv_write()
605 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
608 rc = ivtv_start_decoding(id, itv->speed); in ivtv_write()
610 IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name); in ivtv_write()
613 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_write()
614 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
619 /* If possible, just DMA the entire frame - Check the data transfer size in ivtv_write()
620 since we may get here before the stream has been fully set-up */ in ivtv_write()
621 if (mode == OUT_YUV && s->q_full.length == 0 && itv->dma_data_req_size) { in ivtv_write()
622 while (count >= itv->dma_data_req_size) { in ivtv_write()
628 bytes_written += itv->dma_data_req_size; in ivtv_write()
629 user_buf += itv->dma_data_req_size; in ivtv_write()
630 count -= itv->dma_data_req_size; in ivtv_write()
633 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); in ivtv_write()
640 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_io))) in ivtv_write()
642 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_free))) { in ivtv_write()
647 if (filp->f_flags & O_NONBLOCK) in ivtv_write()
648 return -EAGAIN; in ivtv_write()
651 IVTV_DEBUG_INFO("User stopped %s\n", s->name); in ivtv_write()
652 return -EINTR; in ivtv_write()
660 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && in ivtv_write()
661 yi->stream_size + count > itv->dma_data_req_size) in ivtv_write()
663 itv->dma_data_req_size - yi->stream_size); in ivtv_write()
669 ivtv_queue_move(s, &q, NULL, &s->q_free, 0); in ivtv_write()
673 count -= rc; in ivtv_write()
676 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) { in ivtv_write()
677 yi->stream_size += rc; in ivtv_write()
679 if (yi->stream_size == itv->dma_data_req_size) { in ivtv_write()
680 ivtv_enqueue(s, buf, &s->q_full); in ivtv_write()
681 yi->stream_size = 0; in ivtv_write()
686 if (buf->bytesused != s->buf_size) { in ivtv_write()
688 ivtv_enqueue(s, buf, &s->q_io); in ivtv_write()
692 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_write()
694 ivtv_enqueue(s, buf, &s->q_full); in ivtv_write()
697 if (test_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags)) { in ivtv_write()
698 if (s->q_full.length >= itv->dma_data_req_size) { in ivtv_write()
703 IVTV_DEBUG_INFO("User interrupted %s\n", s->name); in ivtv_write()
704 return -EINTR; in ivtv_write()
707 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); in ivtv_write()
708 ivtv_queue_move(s, &s->q_full, NULL, &s->q_predma, itv->dma_data_req_size); in ivtv_write()
709 ivtv_dma_stream_dec_prepare(s, itv->dma_data_req_offset + IVTV_DECODER_OFFSET, 1); in ivtv_write()
714 if (count && !(filp->f_flags & O_NONBLOCK)) in ivtv_write()
716 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); in ivtv_write()
722 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_write()
723 struct ivtv *itv = id->itv; in ivtv_v4l2_write()
726 if (mutex_lock_interruptible(&itv->serialize_lock)) in ivtv_v4l2_write()
727 return -ERESTARTSYS; in ivtv_v4l2_write()
729 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_write()
735 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_dec_poll()
736 struct ivtv *itv = id->itv; in ivtv_v4l2_dec_poll()
737 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_dec_poll()
745 if (!list_empty(&id->fh.subscribed)) { in ivtv_v4l2_dec_poll()
746 poll_wait(filp, &id->fh.wait, wait); in ivtv_v4l2_dec_poll()
747 /* Turn off the old-style vsync events */ in ivtv_v4l2_dec_poll()
748 clear_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); in ivtv_v4l2_dec_poll()
749 if (v4l2_event_pending(&id->fh)) in ivtv_v4l2_dec_poll()
752 /* This is the old-style API which is here only for backwards in ivtv_v4l2_dec_poll()
754 poll_wait(filp, &s->waitq, wait); in ivtv_v4l2_dec_poll()
755 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); in ivtv_v4l2_dec_poll()
756 if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) || in ivtv_v4l2_dec_poll()
757 test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags)) in ivtv_v4l2_dec_poll()
762 if (s->q_free.buffers) in ivtv_v4l2_dec_poll()
770 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_enc_poll()
771 struct ivtv *itv = id->itv; in ivtv_v4l2_enc_poll()
772 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_enc_poll()
773 int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_v4l2_enc_poll()
777 if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags) && in ivtv_v4l2_enc_poll()
778 s->type != IVTV_ENC_STREAM_TYPE_RAD && in ivtv_v4l2_enc_poll()
782 mutex_lock(&itv->serialize_lock); in ivtv_v4l2_enc_poll()
784 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_enc_poll()
787 s->name, rc); in ivtv_v4l2_enc_poll()
795 poll_wait(filp, &s->waitq, wait); in ivtv_v4l2_enc_poll()
796 if (v4l2_event_pending(&id->fh)) in ivtv_v4l2_enc_poll()
799 poll_wait(filp, &id->fh.wait, wait); in ivtv_v4l2_enc_poll()
801 if (s->q_full.length || s->q_io.length) in ivtv_v4l2_enc_poll()
810 struct ivtv *itv = id->itv; in ivtv_stop_capture()
811 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_stop_capture()
813 IVTV_DEBUG_FILE("close() of %s\n", s->name); in ivtv_stop_capture()
818 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_stop_capture()
819 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_stop_capture()
824 if (id->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_stop_capture()
825 test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags) && in ivtv_stop_capture()
826 !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) { in ivtv_stop_capture()
830 if ((id->type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_stop_capture()
831 id->type == IVTV_ENC_STREAM_TYPE_VBI) && in ivtv_stop_capture()
832 test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { in ivtv_stop_capture()
834 s->fh = NULL; in ivtv_stop_capture()
841 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_stop_capture()
842 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_stop_capture()
849 struct ivtv *itv = id->itv; in ivtv_stop_decoding()
850 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_stop_decoding()
852 IVTV_DEBUG_FILE("close() of %s\n", s->name); in ivtv_stop_decoding()
854 if (id->type == IVTV_DEC_STREAM_TYPE_YUV && in ivtv_stop_decoding()
855 test_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags)) { in ivtv_stop_decoding()
861 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_stop_decoding()
865 itv->output_mode = OUT_NONE; in ivtv_stop_decoding()
867 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_stop_decoding()
868 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_stop_decoding()
870 if (itv->output_mode == OUT_UDMA_YUV && id->yuv_frames) in ivtv_stop_decoding()
871 itv->output_mode = OUT_NONE; in ivtv_stop_decoding()
873 itv->speed = 0; in ivtv_stop_decoding()
874 clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags); in ivtv_stop_decoding()
880 struct v4l2_fh *fh = filp->private_data; in ivtv_v4l2_close()
882 struct ivtv *itv = id->itv; in ivtv_v4l2_close()
883 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_close()
885 IVTV_DEBUG_FILE("close %s\n", s->name); in ivtv_v4l2_close()
887 mutex_lock(&itv->serialize_lock); in ivtv_v4l2_close()
889 /* Stop radio */ in ivtv_v4l2_close()
890 if (id->type == IVTV_ENC_STREAM_TYPE_RAD && in ivtv_v4l2_close()
892 /* Closing radio device, return to TV mode */ in ivtv_v4l2_close()
894 /* Mark that the radio is no longer in use */ in ivtv_v4l2_close()
895 clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags); in ivtv_v4l2_close()
897 ivtv_call_all(itv, video, s_std, itv->std); in ivtv_v4l2_close()
900 if (itv->hw_flags & IVTV_HW_SAA711X) { in ivtv_v4l2_close()
904 if (atomic_read(&itv->capturing) > 0) { in ivtv_v4l2_close()
907 v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute) | in ivtv_v4l2_close()
908 (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8)); in ivtv_v4l2_close()
918 if (s->fh != &id->fh) in ivtv_v4l2_close()
923 if (s->type >= IVTV_DEC_STREAM_TYPE_MPG) { in ivtv_v4l2_close()
924 struct ivtv_stream *s_vout = &itv->streams[IVTV_DEC_STREAM_TYPE_VOUT]; in ivtv_v4l2_close()
929 IVTV_DEC_STREAM_TYPE_VOUT open, then disable CC on TV-out. */ in ivtv_v4l2_close()
930 if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) { in ivtv_v4l2_close()
931 /* disable CC on TV-out */ in ivtv_v4l2_close()
939 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_close()
947 struct ivtv *itv = s->itv;
951 IVTV_DEBUG_FILE("open %s\n", s->name);
956 return -ENXIO;
970 if (res == -EAGAIN)
973 return -EIO;
976 if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
977 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
978 return -EBUSY;
980 if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
981 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags))
982 return -EBUSY;
984 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
987 /* return -ENODEV; */
996 return -ENOMEM;
998 v4l2_fh_init(&item->fh, &s->vdev);
999 item->itv = itv;
1000 item->type = s->type;
1002 filp->private_data = &item->fh;
1003 v4l2_fh_add(&item->fh);
1005 if (item->type == IVTV_ENC_STREAM_TYPE_RAD &&
1007 if (!test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
1008 if (atomic_read(&itv->capturing) > 0) {
1009 /* switching to radio while capture is
1011 v4l2_fh_del(&item->fh);
1012 v4l2_fh_exit(&item->fh);
1014 return -EBUSY;
1017 /* Mark that the radio is being used. */
1018 set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
1019 /* We have the radio */
1021 /* Switch tuner to radio */
1023 /* Select the correct audio input (i.e. radio tuner) */
1025 if (itv->hw_flags & IVTV_HW_SAA711X) {
1034 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
1035 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
1036 } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
1037 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
1039 itv->dma_data_req_size =
1040 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
1041 itv->yuv_info.stream_size = 0;
1051 if (mutex_lock_interruptible(vdev->lock))
1052 return -ERESTARTSYS;
1054 mutex_unlock(vdev->lock);
1060 if (atomic_read(&itv->capturing))
1067 if (atomic_read(&itv->capturing)) {