Lines Matching +full:poll +full:- +full:retry +full:- +full:count
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"
24 #include <media/v4l2-event.h>
30 Possible error returns: -EBUSY if someone else has claimed
34 struct ivtv *itv = id->itv; in ivtv_claim_stream()
35 struct ivtv_stream *s = &itv->streams[type]; in ivtv_claim_stream()
39 if (test_and_set_bit(IVTV_F_S_CLAIMED, &s->s_flags)) { in ivtv_claim_stream()
41 if (s->fh == &id->fh) { in ivtv_claim_stream()
45 if (s->fh == NULL && (type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_claim_stream()
50 s->fh = &id->fh; in ivtv_claim_stream()
56 return -EBUSY; in ivtv_claim_stream()
58 s->fh = &id->fh; in ivtv_claim_stream()
71 itv->vbi.insert_mpeg && !ivtv_raw_vbi(itv)) { in ivtv_claim_stream()
76 s_vbi = &itv->streams[vbi_type]; in ivtv_claim_stream()
78 if (!test_and_set_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags)) { in ivtv_claim_stream()
84 set_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags); in ivtv_claim_stream()
93 struct ivtv *itv = s->itv; in ivtv_release_stream()
96 s->fh = NULL; in ivtv_release_stream()
97 if ((s->type == IVTV_DEC_STREAM_TYPE_VBI || s->type == IVTV_ENC_STREAM_TYPE_VBI) && in ivtv_release_stream()
98 test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { in ivtv_release_stream()
102 if (!test_and_clear_bit(IVTV_F_S_CLAIMED, &s->s_flags)) { in ivtv_release_stream()
103 IVTV_DEBUG_WARN("Release stream %s not in use!\n", s->name); in ivtv_release_stream()
110 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) in ivtv_release_stream()
116 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_release_stream()
117 s_vbi = &itv->streams[IVTV_DEC_STREAM_TYPE_VBI]; in ivtv_release_stream()
118 else if (s->type == IVTV_ENC_STREAM_TYPE_MPG) in ivtv_release_stream()
119 s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_release_stream()
124 if (!test_and_clear_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags)) { in ivtv_release_stream()
128 if (s_vbi->fh) { in ivtv_release_stream()
133 if (s_vbi->type == IVTV_DEC_STREAM_TYPE_VBI) in ivtv_release_stream()
135 clear_bit(IVTV_F_S_CLAIMED, &s_vbi->s_flags); in ivtv_release_stream()
146 new_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode); in ivtv_dualwatch()
152 if (new_stereo_mode == itv->dualwatch_stereo_mode) in ivtv_dualwatch()
156 itv->dualwatch_stereo_mode, new_stereo_mode); in ivtv_dualwatch()
157 if (v4l2_ctrl_s_ctrl(itv->cxhdl.audio_mode, new_stereo_mode)) in ivtv_dualwatch()
163 u32 wr_idx = (read_enc(itv->pgm_info_offset) - itv->pgm_info_offset - 4) / 24; in ivtv_update_pgm_info()
167 if (wr_idx >= itv->pgm_info_num) { in ivtv_update_pgm_info()
168 IVTV_DEBUG_WARN("Invalid PGM index %d (>= %d)\n", wr_idx, itv->pgm_info_num); in ivtv_update_pgm_info()
171 cnt = (wr_idx + itv->pgm_info_num - itv->pgm_info_write_idx) % itv->pgm_info_num; in ivtv_update_pgm_info()
173 int idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num; in ivtv_update_pgm_info()
174 struct v4l2_enc_idx_entry *e = itv->pgm_info + idx; in ivtv_update_pgm_info()
175 u32 addr = itv->pgm_info_offset + 4 + idx * 24; in ivtv_update_pgm_info()
176 const int mapping[8] = { -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P, -1, in ivtv_update_pgm_info()
177 V4L2_ENC_IDX_FRAME_B, -1, -1, -1 }; in ivtv_update_pgm_info()
180 e->offset = read_enc(addr + 4) + ((u64)read_enc(addr + 8) << 32); in ivtv_update_pgm_info()
181 if (e->offset > itv->mpg_data_received) { in ivtv_update_pgm_info()
184 e->offset += itv->vbi_data_inserted; in ivtv_update_pgm_info()
185 e->length = read_enc(addr); in ivtv_update_pgm_info()
186 e->pts = read_enc(addr + 16) + ((u64)(read_enc(addr + 20) & 1) << 32); in ivtv_update_pgm_info()
187 e->flags = mapping[read_enc(addr + 12) & 7]; in ivtv_update_pgm_info()
190 itv->pgm_info_write_idx = (itv->pgm_info_write_idx + i) % itv->pgm_info_num; in ivtv_update_pgm_info()
195 struct ivtv *itv = s->itv; in ivtv_get_buffer()
196 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_get_buffer()
202 if (s->type == IVTV_ENC_STREAM_TYPE_MPG) { in ivtv_get_buffer()
207 itv->dualwatch_jiffies + in ivtv_get_buffer()
209 itv->dualwatch_jiffies = jiffies; in ivtv_get_buffer()
213 if (test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) && in ivtv_get_buffer()
214 !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) { in ivtv_get_buffer()
215 while ((buf = ivtv_dequeue(s_vbi, &s_vbi->q_full))) { in ivtv_get_buffer()
217 ivtv_process_vbi_data(itv, buf, s_vbi->dma_pts, s_vbi->type); in ivtv_get_buffer()
218 ivtv_enqueue(s_vbi, buf, &s_vbi->q_free); in ivtv_get_buffer()
221 buf = &itv->vbi.sliced_mpeg_buf; in ivtv_get_buffer()
222 if (buf->readpos != buf->bytesused) { in ivtv_get_buffer()
228 buf = ivtv_dequeue(s, &s->q_io); in ivtv_get_buffer()
233 buf = ivtv_dequeue(s, &s->q_full); in ivtv_get_buffer()
235 if ((buf->b_flags & IVTV_F_B_NEED_BUF_SWAP) == 0) in ivtv_get_buffer()
237 buf->b_flags &= ~IVTV_F_B_NEED_BUF_SWAP; in ivtv_get_buffer()
238 if (s->type == IVTV_ENC_STREAM_TYPE_MPG) in ivtv_get_buffer()
241 else if (s->type != IVTV_DEC_STREAM_TYPE_VBI) { in ivtv_get_buffer()
243 ivtv_process_vbi_data(itv, buf, s->dma_pts, s->type); in ivtv_get_buffer()
249 if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_get_buffer()
250 IVTV_DEBUG_INFO("EOS %s\n", s->name); in ivtv_get_buffer()
256 *err = -EAGAIN; in ivtv_get_buffer()
261 mutex_unlock(&itv->serialize_lock); in ivtv_get_buffer()
262 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); in ivtv_get_buffer()
264 if (!s->q_full.buffers) in ivtv_get_buffer()
266 finish_wait(&s->waitq, &wait); in ivtv_get_buffer()
267 mutex_lock(&itv->serialize_lock); in ivtv_get_buffer()
270 IVTV_DEBUG_INFO("User stopped %s\n", s->name); in ivtv_get_buffer()
271 *err = -EINTR; in ivtv_get_buffer()
279 int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES; in ivtv_setup_sliced_vbi_buf()
281 itv->vbi.sliced_mpeg_buf.buf = itv->vbi.sliced_mpeg_data[idx]; in ivtv_setup_sliced_vbi_buf()
282 itv->vbi.sliced_mpeg_buf.bytesused = itv->vbi.sliced_mpeg_size[idx]; in ivtv_setup_sliced_vbi_buf()
283 itv->vbi.sliced_mpeg_buf.readpos = 0; in ivtv_setup_sliced_vbi_buf()
289 struct ivtv *itv = s->itv; in ivtv_copy_buf_to_user()
290 size_t len = buf->bytesused - buf->readpos; in ivtv_copy_buf_to_user()
293 if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_copy_buf_to_user()
294 !ivtv_raw_vbi(itv) && buf != &itv->vbi.sliced_mpeg_buf) { in ivtv_copy_buf_to_user()
295 const char *start = buf->buf + buf->readpos; in ivtv_copy_buf_to_user()
298 u8 ch = itv->search_pack_header ? 0xba : 0xe0; in ivtv_copy_buf_to_user()
301 while (start + len > p && (q = memchr(p, 0, start + len - p))) { in ivtv_copy_buf_to_user()
303 if ((char *)q + 15 >= buf->buf + buf->bytesused || in ivtv_copy_buf_to_user()
307 if (!itv->search_pack_header) { in ivtv_copy_buf_to_user()
313 itv->search_pack_header = 1; in ivtv_copy_buf_to_user()
326 itv->search_pack_header = 0; in ivtv_copy_buf_to_user()
327 len = (char *)q - start; in ivtv_copy_buf_to_user()
333 if (copy_to_user(ubuf, (u8 *)buf->buf + buf->readpos, len)) { in ivtv_copy_buf_to_user()
334 IVTV_DEBUG_WARN("copy %zd bytes to user failed for %s\n", len, s->name); in ivtv_copy_buf_to_user()
335 return -EFAULT; in ivtv_copy_buf_to_user()
337 /*IVTV_INFO("copied %lld %d %d %d %d %d vbi %d\n", itv->mpg_data_received, len, ucount, in ivtv_copy_buf_to_user()
338 buf->readpos, buf->bytesused, buf->bytesused - buf->readpos - len, in ivtv_copy_buf_to_user()
339 buf == &itv->vbi.sliced_mpeg_buf); */ in ivtv_copy_buf_to_user()
340 buf->readpos += len; in ivtv_copy_buf_to_user()
341 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && buf != &itv->vbi.sliced_mpeg_buf) in ivtv_copy_buf_to_user()
342 itv->mpg_data_received += len; in ivtv_copy_buf_to_user()
348 struct ivtv *itv = s->itv; in ivtv_read()
352 if (atomic_read(&itv->capturing) == 0 && s->fh == NULL) { in ivtv_read()
354 IVTV_DEBUG_WARN("Stream %s not initialized before read\n", s->name); in ivtv_read()
355 return -EIO; in ivtv_read()
359 arrive one-by-one, so make sure we never output more than one VBI frame at a time */ in ivtv_read()
360 if (s->type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_read()
361 (s->type == IVTV_ENC_STREAM_TYPE_VBI && !ivtv_raw_vbi(itv))) in ivtv_read()
376 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_read()
377 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_read()
383 rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written); in ivtv_read()
384 if (buf != &itv->vbi.sliced_mpeg_buf) { in ivtv_read()
385 ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io); in ivtv_read()
387 else if (buf->readpos == buf->bytesused) { in ivtv_read()
388 int idx = itv->vbi.inserted_frame % IVTV_VBI_FRAMES; in ivtv_read()
389 itv->vbi.sliced_mpeg_size[idx] = 0; in ivtv_read()
390 itv->vbi.inserted_frame++; in ivtv_read()
391 itv->vbi_data_inserted += buf->bytesused; in ivtv_read()
403 static ssize_t ivtv_read_pos(struct ivtv_stream *s, char __user *ubuf, size_t count, in ivtv_read_pos() argument
406 ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0; in ivtv_read_pos()
407 struct ivtv *itv = s->itv; in ivtv_read_pos()
409 IVTV_DEBUG_HI_FILE("read %zd from %s, got %zd\n", count, s->name, rc); in ivtv_read_pos()
417 struct ivtv *itv = id->itv; in ivtv_start_capture()
418 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_start_capture()
421 if (s->type == IVTV_ENC_STREAM_TYPE_RAD || in ivtv_start_capture()
422 s->type == IVTV_DEC_STREAM_TYPE_MPG || in ivtv_start_capture()
423 s->type == IVTV_DEC_STREAM_TYPE_YUV || in ivtv_start_capture()
424 s->type == IVTV_DEC_STREAM_TYPE_VOUT) { in ivtv_start_capture()
426 return -EINVAL; in ivtv_start_capture()
430 if (ivtv_claim_stream(id, s->type)) in ivtv_start_capture()
431 return -EBUSY; in ivtv_start_capture()
434 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) { in ivtv_start_capture()
435 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
441 …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()
442 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
447 s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_start_capture()
448 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_start_capture()
449 test_bit(IVTV_F_S_INTERNAL_USE, &s_vbi->s_flags) && in ivtv_start_capture()
450 !test_and_set_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) { in ivtv_start_capture()
458 clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags); in ivtv_start_capture()
459 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_start_capture()
462 return -EIO; in ivtv_start_capture()
470 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_start_capture()
472 if (test_and_clear_bit(IVTV_F_I_ENC_PAUSED, &itv->i_flags)) in ivtv_start_capture()
478 IVTV_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name); in ivtv_start_capture()
483 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_start_capture()
484 test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags)) { in ivtv_start_capture()
486 clear_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags); in ivtv_start_capture()
488 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_start_capture()
490 return -EIO; in ivtv_start_capture()
493 ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos) in ivtv_v4l2_read() argument
495 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_read()
496 struct ivtv *itv = id->itv; in ivtv_v4l2_read()
497 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_read()
500 IVTV_DEBUG_HI_FILE("read %zd bytes from %s\n", count, s->name); in ivtv_v4l2_read()
502 if (mutex_lock_interruptible(&itv->serialize_lock)) in ivtv_v4l2_read()
503 return -ERESTARTSYS; in ivtv_v4l2_read()
506 rc = ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK); in ivtv_v4l2_read()
507 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_read()
513 struct ivtv *itv = id->itv; in ivtv_start_decoding()
514 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_start_decoding()
517 if (atomic_read(&itv->decoding) == 0) { in ivtv_start_decoding()
518 if (ivtv_claim_stream(id, s->type)) { in ivtv_start_decoding()
521 return -EBUSY; in ivtv_start_decoding()
525 if (rc == -EAGAIN) in ivtv_start_decoding()
531 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_start_decoding()
536 static ssize_t ivtv_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos) in ivtv_write() argument
538 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_write()
539 struct ivtv *itv = id->itv; in ivtv_write()
540 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_write()
541 struct yuv_playback_info *yi = &itv->yuv_info; in ivtv_write()
549 IVTV_DEBUG_HI_FILE("write %zd bytes to %s\n", count, s->name); in ivtv_write()
551 if (s->type != IVTV_DEC_STREAM_TYPE_MPG && in ivtv_write()
552 s->type != IVTV_DEC_STREAM_TYPE_YUV && in ivtv_write()
553 s->type != IVTV_DEC_STREAM_TYPE_VOUT) in ivtv_write()
555 return -EINVAL; in ivtv_write()
558 if (ivtv_claim_stream(id, s->type)) in ivtv_write()
559 return -EBUSY; in ivtv_write()
562 if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) { in ivtv_write()
563 int elems = count / sizeof(struct v4l2_sliced_vbi_data); in ivtv_write()
565 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
570 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV; in ivtv_write()
574 return -EBUSY; in ivtv_write()
577 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
580 rc = ivtv_start_decoding(id, itv->speed); in ivtv_write()
582 IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name); in ivtv_write()
585 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); in ivtv_write()
586 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_write()
590 retry: in ivtv_write()
591 /* If possible, just DMA the entire frame - Check the data transfer size in ivtv_write()
592 since we may get here before the stream has been fully set-up */ in ivtv_write()
593 if (mode == OUT_YUV && s->q_full.length == 0 && itv->dma_data_req_size) { in ivtv_write()
594 while (count >= itv->dma_data_req_size) { in ivtv_write()
600 bytes_written += itv->dma_data_req_size; in ivtv_write()
601 user_buf += itv->dma_data_req_size; in ivtv_write()
602 count -= itv->dma_data_req_size; in ivtv_write()
604 if (count == 0) { in ivtv_write()
605 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); in ivtv_write()
612 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_io))) in ivtv_write()
614 while (q.length - q.bytesused < count && (buf = ivtv_dequeue(s, &s->q_free))) { in ivtv_write()
619 if (filp->f_flags & O_NONBLOCK) in ivtv_write()
620 return -EAGAIN; in ivtv_write()
621 mutex_unlock(&itv->serialize_lock); in ivtv_write()
622 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); in ivtv_write()
624 if (!s->q_free.buffers) in ivtv_write()
626 finish_wait(&s->waitq, &wait); in ivtv_write()
627 mutex_lock(&itv->serialize_lock); in ivtv_write()
629 IVTV_DEBUG_INFO("User stopped %s\n", s->name); in ivtv_write()
630 return -EINTR; in ivtv_write()
638 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && in ivtv_write()
639 yi->stream_size + count > itv->dma_data_req_size) in ivtv_write()
641 itv->dma_data_req_size - yi->stream_size); in ivtv_write()
643 rc = ivtv_buf_copy_from_user(s, buf, user_buf, count); in ivtv_write()
647 ivtv_queue_move(s, &q, NULL, &s->q_free, 0); in ivtv_write()
651 count -= rc; in ivtv_write()
654 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) { in ivtv_write()
655 yi->stream_size += rc; in ivtv_write()
657 if (yi->stream_size == itv->dma_data_req_size) { in ivtv_write()
658 ivtv_enqueue(s, buf, &s->q_full); in ivtv_write()
659 yi->stream_size = 0; in ivtv_write()
664 if (buf->bytesused != s->buf_size) { in ivtv_write()
666 ivtv_enqueue(s, buf, &s->q_io); in ivtv_write()
670 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) in ivtv_write()
672 ivtv_enqueue(s, buf, &s->q_full); in ivtv_write()
675 if (test_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags)) { in ivtv_write()
676 if (s->q_full.length >= itv->dma_data_req_size) { in ivtv_write()
682 mutex_unlock(&itv->serialize_lock); in ivtv_write()
683 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE); in ivtv_write()
685 test_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) { in ivtv_write()
688 finish_wait(&itv->dma_waitq, &wait); in ivtv_write()
689 mutex_lock(&itv->serialize_lock); in ivtv_write()
691 IVTV_DEBUG_INFO("User interrupted %s\n", s->name); in ivtv_write()
692 return -EINTR; in ivtv_write()
695 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); in ivtv_write()
696 ivtv_queue_move(s, &s->q_full, NULL, &s->q_predma, itv->dma_data_req_size); in ivtv_write()
697 ivtv_dma_stream_dec_prepare(s, itv->dma_data_req_offset + IVTV_DECODER_OFFSET, 1); in ivtv_write()
702 if (count && !(filp->f_flags & O_NONBLOCK)) in ivtv_write()
703 goto retry; in ivtv_write()
704 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); in ivtv_write()
708 ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos) in ivtv_v4l2_write() argument
710 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_write()
711 struct ivtv *itv = id->itv; in ivtv_v4l2_write()
714 if (mutex_lock_interruptible(&itv->serialize_lock)) in ivtv_v4l2_write()
715 return -ERESTARTSYS; in ivtv_v4l2_write()
716 res = ivtv_write(filp, user_buf, count, pos); in ivtv_v4l2_write()
717 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_write()
723 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_dec_poll()
724 struct ivtv *itv = id->itv; in ivtv_v4l2_dec_poll()
725 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_dec_poll()
728 /* add stream's waitq to the poll list */ in ivtv_v4l2_dec_poll()
729 IVTV_DEBUG_HI_FILE("Decoder poll\n"); in ivtv_v4l2_dec_poll()
733 if (!list_empty(&id->fh.subscribed)) { in ivtv_v4l2_dec_poll()
734 poll_wait(filp, &id->fh.wait, wait); in ivtv_v4l2_dec_poll()
735 /* Turn off the old-style vsync events */ in ivtv_v4l2_dec_poll()
736 clear_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); in ivtv_v4l2_dec_poll()
737 if (v4l2_event_pending(&id->fh)) in ivtv_v4l2_dec_poll()
740 /* This is the old-style API which is here only for backwards in ivtv_v4l2_dec_poll()
742 poll_wait(filp, &s->waitq, wait); in ivtv_v4l2_dec_poll()
743 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); in ivtv_v4l2_dec_poll()
744 if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) || in ivtv_v4l2_dec_poll()
745 test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags)) in ivtv_v4l2_dec_poll()
750 if (s->q_free.buffers) in ivtv_v4l2_dec_poll()
758 struct ivtv_open_id *id = fh2id(filp->private_data); in ivtv_v4l2_enc_poll()
759 struct ivtv *itv = id->itv; in ivtv_v4l2_enc_poll()
760 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_enc_poll()
761 int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_v4l2_enc_poll()
765 if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags) && in ivtv_v4l2_enc_poll()
766 s->type != IVTV_ENC_STREAM_TYPE_RAD && in ivtv_v4l2_enc_poll()
770 mutex_lock(&itv->serialize_lock); in ivtv_v4l2_enc_poll()
772 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_enc_poll()
775 s->name, rc); in ivtv_v4l2_enc_poll()
778 IVTV_DEBUG_FILE("Encoder poll started capture\n"); in ivtv_v4l2_enc_poll()
781 /* add stream's waitq to the poll list */ in ivtv_v4l2_enc_poll()
782 IVTV_DEBUG_HI_FILE("Encoder poll\n"); in ivtv_v4l2_enc_poll()
783 poll_wait(filp, &s->waitq, wait); in ivtv_v4l2_enc_poll()
784 if (v4l2_event_pending(&id->fh)) in ivtv_v4l2_enc_poll()
787 poll_wait(filp, &id->fh.wait, wait); in ivtv_v4l2_enc_poll()
789 if (s->q_full.length || s->q_io.length) in ivtv_v4l2_enc_poll()
798 struct ivtv *itv = id->itv; in ivtv_stop_capture()
799 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_stop_capture()
801 IVTV_DEBUG_FILE("close() of %s\n", s->name); in ivtv_stop_capture()
806 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_stop_capture()
807 struct ivtv_stream *s_vbi = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; in ivtv_stop_capture()
812 if (id->type == IVTV_ENC_STREAM_TYPE_MPG && in ivtv_stop_capture()
813 test_bit(IVTV_F_S_STREAMING, &s_vbi->s_flags) && in ivtv_stop_capture()
814 !test_bit(IVTV_F_S_APPL_IO, &s_vbi->s_flags)) { in ivtv_stop_capture()
818 if ((id->type == IVTV_DEC_STREAM_TYPE_VBI || in ivtv_stop_capture()
819 id->type == IVTV_ENC_STREAM_TYPE_VBI) && in ivtv_stop_capture()
820 test_bit(IVTV_F_S_INTERNAL_USE, &s->s_flags)) { in ivtv_stop_capture()
822 s->fh = NULL; in ivtv_stop_capture()
829 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_stop_capture()
830 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_stop_capture()
837 struct ivtv *itv = id->itv; in ivtv_stop_decoding()
838 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_stop_decoding()
840 IVTV_DEBUG_FILE("close() of %s\n", s->name); in ivtv_stop_decoding()
842 if (id->type == IVTV_DEC_STREAM_TYPE_YUV && in ivtv_stop_decoding()
843 test_bit(IVTV_F_I_DECODING_YUV, &itv->i_flags)) { in ivtv_stop_decoding()
849 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { in ivtv_stop_decoding()
853 itv->output_mode = OUT_NONE; in ivtv_stop_decoding()
855 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); in ivtv_stop_decoding()
856 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); in ivtv_stop_decoding()
858 if (itv->output_mode == OUT_UDMA_YUV && id->yuv_frames) in ivtv_stop_decoding()
859 itv->output_mode = OUT_NONE; in ivtv_stop_decoding()
861 itv->speed = 0; in ivtv_stop_decoding()
862 clear_bit(IVTV_F_I_DEC_PAUSED, &itv->i_flags); in ivtv_stop_decoding()
868 struct v4l2_fh *fh = filp->private_data; in ivtv_v4l2_close()
870 struct ivtv *itv = id->itv; in ivtv_v4l2_close()
871 struct ivtv_stream *s = &itv->streams[id->type]; in ivtv_v4l2_close()
873 IVTV_DEBUG_FILE("close %s\n", s->name); in ivtv_v4l2_close()
875 mutex_lock(&itv->serialize_lock); in ivtv_v4l2_close()
878 if (id->type == IVTV_ENC_STREAM_TYPE_RAD && in ivtv_v4l2_close()
883 clear_bit(IVTV_F_I_RADIO_USER, &itv->i_flags); in ivtv_v4l2_close()
885 ivtv_call_all(itv, video, s_std, itv->std); in ivtv_v4l2_close()
888 if (itv->hw_flags & IVTV_HW_SAA711X) { in ivtv_v4l2_close()
892 if (atomic_read(&itv->capturing) > 0) { in ivtv_v4l2_close()
895 v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute) | in ivtv_v4l2_close()
896 (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8)); in ivtv_v4l2_close()
906 if (s->fh != &id->fh) in ivtv_v4l2_close()
911 if (s->type >= IVTV_DEC_STREAM_TYPE_MPG) { in ivtv_v4l2_close()
912 struct ivtv_stream *s_vout = &itv->streams[IVTV_DEC_STREAM_TYPE_VOUT]; in ivtv_v4l2_close()
917 IVTV_DEC_STREAM_TYPE_VOUT open, then disable CC on TV-out. */ in ivtv_v4l2_close()
918 if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) { in ivtv_v4l2_close()
919 /* disable CC on TV-out */ in ivtv_v4l2_close()
927 mutex_unlock(&itv->serialize_lock); in ivtv_v4l2_close()
935 struct ivtv *itv = s->itv;
939 IVTV_DEBUG_FILE("open %s\n", s->name);
944 return -ENXIO;
958 if (res == -EAGAIN)
961 return -EIO;
964 if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
965 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
966 return -EBUSY;
968 if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
969 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags))
970 return -EBUSY;
972 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
975 /* return -ENODEV; */
984 return -ENOMEM;
986 v4l2_fh_init(&item->fh, &s->vdev);
987 item->itv = itv;
988 item->type = s->type;
990 filp->private_data = &item->fh;
991 v4l2_fh_add(&item->fh);
993 if (item->type == IVTV_ENC_STREAM_TYPE_RAD &&
995 if (!test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
996 if (atomic_read(&itv->capturing) > 0) {
999 v4l2_fh_del(&item->fh);
1000 v4l2_fh_exit(&item->fh);
1002 return -EBUSY;
1006 set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
1013 if (itv->hw_flags & IVTV_HW_SAA711X) {
1022 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) {
1023 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
1024 } else if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
1025 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
1027 itv->dma_data_req_size =
1028 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
1029 itv->yuv_info.stream_size = 0;
1039 if (mutex_lock_interruptible(vdev->lock))
1040 return -ERESTARTSYS;
1042 mutex_unlock(vdev->lock);
1048 if (atomic_read(&itv->capturing))
1055 if (atomic_read(&itv->capturing)) {