Lines Matching +full:port +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
15 * This is a dummy non-zero value for the sizeimage field of v4l2_pix_format.
28 .name = "NTSC-M",
29 .id = V4L2_STD_NTSC_M,
31 .name = "NTSC-JP",
32 .id = V4L2_STD_NTSC_M_JP,
36 /* Take the encoder configuration form the port struct and
39 static void saa7164_encoder_configure(struct saa7164_port *port) in saa7164_encoder_configure() argument
41 struct saa7164_dev *dev = port->dev; in saa7164_encoder_configure()
44 port->encoder_params.width = port->width; in saa7164_encoder_configure()
45 port->encoder_params.height = port->height; in saa7164_encoder_configure()
46 port->encoder_params.is_50hz = in saa7164_encoder_configure()
47 (port->encodernorm.id & V4L2_STD_625_50) != 0; in saa7164_encoder_configure()
50 saa7164_api_initialize_dif(port); in saa7164_encoder_configure()
53 saa7164_api_configure_dif(port, port->encodernorm.id); in saa7164_encoder_configure()
56 saa7164_api_set_audio_std(port); in saa7164_encoder_configure()
59 static int saa7164_encoder_buffers_dealloc(struct saa7164_port *port) in saa7164_encoder_buffers_dealloc() argument
62 struct saa7164_dev *dev = port->dev; in saa7164_encoder_buffers_dealloc()
67 mutex_lock(&port->dmaqueue_lock); in saa7164_encoder_buffers_dealloc()
69 dprintk(DBGLVL_ENC, "%s(port=%d) dmaqueue\n", __func__, port->nr); in saa7164_encoder_buffers_dealloc()
70 list_for_each_safe(c, n, &port->dmaqueue.list) { in saa7164_encoder_buffers_dealloc()
76 dprintk(DBGLVL_ENC, "%s(port=%d) used\n", __func__, port->nr); in saa7164_encoder_buffers_dealloc()
77 list_for_each_safe(p, q, &port->list_buf_used.list) { in saa7164_encoder_buffers_dealloc()
83 dprintk(DBGLVL_ENC, "%s(port=%d) free\n", __func__, port->nr); in saa7164_encoder_buffers_dealloc()
84 list_for_each_safe(l, v, &port->list_buf_free.list) { in saa7164_encoder_buffers_dealloc()
90 mutex_unlock(&port->dmaqueue_lock); in saa7164_encoder_buffers_dealloc()
91 dprintk(DBGLVL_ENC, "%s(port=%d) done\n", __func__, port->nr); in saa7164_encoder_buffers_dealloc()
97 static int saa7164_encoder_buffers_alloc(struct saa7164_port *port) in saa7164_encoder_buffers_alloc() argument
99 struct saa7164_dev *dev = port->dev; in saa7164_encoder_buffers_alloc()
102 struct tmHWStreamParameters *params = &port->hw_streamingparams; in saa7164_encoder_buffers_alloc()
103 int result = -ENODEV, i; in saa7164_encoder_buffers_alloc()
108 if (port->encoder_params.stream_type == in saa7164_encoder_buffers_alloc()
113 params->samplesperline = 128; in saa7164_encoder_buffers_alloc()
114 params->numberoflines = 256; in saa7164_encoder_buffers_alloc()
115 params->pitch = 128; in saa7164_encoder_buffers_alloc()
116 params->numpagetables = 2 + in saa7164_encoder_buffers_alloc()
119 if (port->encoder_params.stream_type == in saa7164_encoder_buffers_alloc()
124 params->samplesperline = 188; in saa7164_encoder_buffers_alloc()
125 params->numberoflines = 312; in saa7164_encoder_buffers_alloc()
126 params->pitch = 188; in saa7164_encoder_buffers_alloc()
127 params->numpagetables = 2 + in saa7164_encoder_buffers_alloc()
133 params->bitspersample = 8; in saa7164_encoder_buffers_alloc()
134 params->linethreshold = 0; in saa7164_encoder_buffers_alloc()
135 params->pagetablelistvirt = NULL; in saa7164_encoder_buffers_alloc()
136 params->pagetablelistphys = NULL; in saa7164_encoder_buffers_alloc()
137 params->numpagetableentries = port->hwcfg.buffercount; in saa7164_encoder_buffers_alloc()
140 for (i = 0; i < port->hwcfg.buffercount; i++) { in saa7164_encoder_buffers_alloc()
141 buf = saa7164_buffer_alloc(port, in saa7164_encoder_buffers_alloc()
142 params->numberoflines * in saa7164_encoder_buffers_alloc()
143 params->pitch); in saa7164_encoder_buffers_alloc()
148 result = -ENOMEM; in saa7164_encoder_buffers_alloc()
152 mutex_lock(&port->dmaqueue_lock); in saa7164_encoder_buffers_alloc()
153 list_add_tail(&buf->list, &port->dmaqueue.list); in saa7164_encoder_buffers_alloc()
154 mutex_unlock(&port->dmaqueue_lock); in saa7164_encoder_buffers_alloc()
162 len = params->numberoflines * params->pitch; in saa7164_encoder_buffers_alloc()
173 mutex_lock(&port->dmaqueue_lock); in saa7164_encoder_buffers_alloc()
174 list_add_tail(&ubuf->list, &port->list_buf_free.list); in saa7164_encoder_buffers_alloc()
175 mutex_unlock(&port->dmaqueue_lock); in saa7164_encoder_buffers_alloc()
186 static int saa7164_encoder_initialize(struct saa7164_port *port) in saa7164_encoder_initialize() argument
188 saa7164_encoder_configure(port); in saa7164_encoder_initialize()
192 /* -- V4L2 --------------------------------------------------------- */
193 int saa7164_s_std(struct saa7164_port *port, v4l2_std_id id) in saa7164_s_std() argument
195 struct saa7164_dev *dev = port->dev; in saa7164_s_std()
198 dprintk(DBGLVL_ENC, "%s(id=0x%x)\n", __func__, (u32)id); in saa7164_s_std()
201 if (id & saa7164_tvnorms[i].id) in saa7164_s_std()
205 return -EINVAL; in saa7164_s_std()
207 port->encodernorm = saa7164_tvnorms[i]; in saa7164_s_std()
208 port->std = id; in saa7164_s_std()
213 saa7164_api_set_audio_std(port); in saa7164_s_std()
215 dprintk(DBGLVL_ENC, "%s(id=0x%x) OK\n", __func__, (u32)id); in saa7164_s_std()
220 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id) in vidioc_s_std() argument
222 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_s_std()
224 return saa7164_s_std(fh->port, id); in vidioc_s_std()
227 int saa7164_g_std(struct saa7164_port *port, v4l2_std_id *id) in saa7164_g_std() argument
229 *id = port->std; in saa7164_g_std()
233 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) in vidioc_g_std() argument
235 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_g_std()
237 return saa7164_g_std(fh->port, id); in vidioc_g_std()
248 if (i->index >= 7) in saa7164_enum_input()
249 return -EINVAL; in saa7164_enum_input()
251 strscpy(i->name, inputs[i->index], sizeof(i->name)); in saa7164_enum_input()
253 if (i->index == 0) in saa7164_enum_input()
254 i->type = V4L2_INPUT_TYPE_TUNER; in saa7164_enum_input()
256 i->type = V4L2_INPUT_TYPE_CAMERA; in saa7164_enum_input()
259 i->std |= saa7164_tvnorms[n].id; in saa7164_enum_input()
264 int saa7164_g_input(struct saa7164_port *port, unsigned int *i) in saa7164_g_input() argument
266 struct saa7164_dev *dev = port->dev; in saa7164_g_input()
268 if (saa7164_api_get_videomux(port) != SAA_OK) in saa7164_g_input()
269 return -EIO; in saa7164_g_input()
271 *i = (port->mux_input - 1); in saa7164_g_input()
280 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_g_input()
282 return saa7164_g_input(fh->port, i); in vidioc_g_input()
285 int saa7164_s_input(struct saa7164_port *port, unsigned int i) in saa7164_s_input() argument
287 struct saa7164_dev *dev = port->dev; in saa7164_s_input()
292 return -EINVAL; in saa7164_s_input()
294 port->mux_input = i + 1; in saa7164_s_input()
296 if (saa7164_api_set_videomux(port) != SAA_OK) in saa7164_s_input()
297 return -EIO; in saa7164_s_input()
304 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_s_input()
306 return saa7164_s_input(fh->port, i); in vidioc_s_input()
311 struct saa7164_encoder_fh *fh = file->private_data; in saa7164_g_tuner()
312 struct saa7164_port *port = fh->port; in saa7164_g_tuner() local
313 struct saa7164_dev *dev = port->dev; in saa7164_g_tuner()
315 if (0 != t->index) in saa7164_g_tuner()
316 return -EINVAL; in saa7164_g_tuner()
318 strscpy(t->name, "tuner", sizeof(t->name)); in saa7164_g_tuner()
319 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO; in saa7164_g_tuner()
320 t->rangelow = SAA7164_TV_MIN_FREQ; in saa7164_g_tuner()
321 t->rangehigh = SAA7164_TV_MAX_FREQ; in saa7164_g_tuner()
323 dprintk(DBGLVL_ENC, "VIDIOC_G_TUNER: tuner type %d\n", t->type); in saa7164_g_tuner()
331 if (0 != t->index) in saa7164_s_tuner()
332 return -EINVAL; in saa7164_s_tuner()
338 int saa7164_g_frequency(struct saa7164_port *port, struct v4l2_frequency *f) in saa7164_g_frequency() argument
340 if (f->tuner) in saa7164_g_frequency()
341 return -EINVAL; in saa7164_g_frequency()
343 f->frequency = port->freq; in saa7164_g_frequency()
350 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_g_frequency()
352 return saa7164_g_frequency(fh->port, f); in vidioc_g_frequency()
355 int saa7164_s_frequency(struct saa7164_port *port, in saa7164_s_frequency() argument
358 struct saa7164_dev *dev = port->dev; in saa7164_s_frequency()
366 .std = port->encodernorm.id, in saa7164_s_frequency()
367 .frequency = f->frequency in saa7164_s_frequency()
372 f->frequency, f->tuner); in saa7164_s_frequency()
374 if (f->tuner != 0) in saa7164_s_frequency()
375 return -EINVAL; in saa7164_s_frequency()
377 port->freq = clamp(f->frequency, in saa7164_s_frequency()
381 if (port->nr == SAA7164_PORT_ENC1) in saa7164_s_frequency()
382 tsport = &dev->ports[SAA7164_PORT_TS1]; in saa7164_s_frequency()
383 else if (port->nr == SAA7164_PORT_ENC2) in saa7164_s_frequency()
384 tsport = &dev->ports[SAA7164_PORT_TS2]; in saa7164_s_frequency()
386 return -EINVAL; /* should not happen */ in saa7164_s_frequency()
388 fe = tsport->dvb.frontend; in saa7164_s_frequency()
390 if (fe && fe->ops.tuner_ops.set_analog_params) in saa7164_s_frequency()
391 fe->ops.tuner_ops.set_analog_params(fe, ¶ms); in saa7164_s_frequency()
395 saa7164_encoder_initialize(port); in saa7164_s_frequency()
403 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_s_frequency()
405 return saa7164_s_frequency(fh->port, f); in vidioc_s_frequency()
410 struct saa7164_port *port = in saa7164_s_ctrl() local
411 container_of(ctrl->handler, struct saa7164_port, ctrl_handler); in saa7164_s_ctrl()
412 struct saa7164_encoder_params *params = &port->encoder_params; in saa7164_s_ctrl()
415 switch (ctrl->id) { in saa7164_s_ctrl()
417 port->ctl_brightness = ctrl->val; in saa7164_s_ctrl()
418 saa7164_api_set_usercontrol(port, PU_BRIGHTNESS_CONTROL); in saa7164_s_ctrl()
421 port->ctl_contrast = ctrl->val; in saa7164_s_ctrl()
422 saa7164_api_set_usercontrol(port, PU_CONTRAST_CONTROL); in saa7164_s_ctrl()
425 port->ctl_saturation = ctrl->val; in saa7164_s_ctrl()
426 saa7164_api_set_usercontrol(port, PU_SATURATION_CONTROL); in saa7164_s_ctrl()
429 port->ctl_hue = ctrl->val; in saa7164_s_ctrl()
430 saa7164_api_set_usercontrol(port, PU_HUE_CONTROL); in saa7164_s_ctrl()
433 port->ctl_sharpness = ctrl->val; in saa7164_s_ctrl()
434 saa7164_api_set_usercontrol(port, PU_SHARPNESS_CONTROL); in saa7164_s_ctrl()
437 port->ctl_volume = ctrl->val; in saa7164_s_ctrl()
438 saa7164_api_set_audio_volume(port, port->ctl_volume); in saa7164_s_ctrl()
441 params->bitrate = ctrl->val; in saa7164_s_ctrl()
444 params->stream_type = ctrl->val; in saa7164_s_ctrl()
447 params->ctl_mute = ctrl->val; in saa7164_s_ctrl()
448 ret = saa7164_api_audio_mute(port, params->ctl_mute); in saa7164_s_ctrl()
452 ret = -EIO; in saa7164_s_ctrl()
456 params->ctl_aspect = ctrl->val; in saa7164_s_ctrl()
457 ret = saa7164_api_set_aspect_ratio(port); in saa7164_s_ctrl()
461 ret = -EIO; in saa7164_s_ctrl()
465 params->bitrate_mode = ctrl->val; in saa7164_s_ctrl()
468 params->refdist = ctrl->val; in saa7164_s_ctrl()
471 params->bitrate_peak = ctrl->val; in saa7164_s_ctrl()
474 params->gop_size = ctrl->val; in saa7164_s_ctrl()
477 ret = -EINVAL; in saa7164_s_ctrl()
486 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_querycap()
487 struct saa7164_port *port = fh->port; in vidioc_querycap() local
488 struct saa7164_dev *dev = port->dev; in vidioc_querycap()
490 strscpy(cap->driver, dev->name, sizeof(cap->driver)); in vidioc_querycap()
491 strscpy(cap->card, saa7164_boards[dev->board].name, in vidioc_querycap()
492 sizeof(cap->card)); in vidioc_querycap()
493 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in vidioc_querycap()
502 if (f->index != 0) in vidioc_enum_fmt_vid_cap()
503 return -EINVAL; in vidioc_enum_fmt_vid_cap()
505 f->pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_enum_fmt_vid_cap()
513 struct saa7164_encoder_fh *fh = file->private_data; in vidioc_fmt_vid_cap()
514 struct saa7164_port *port = fh->port; in vidioc_fmt_vid_cap() local
516 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_fmt_vid_cap()
517 f->fmt.pix.bytesperline = 0; in vidioc_fmt_vid_cap()
518 f->fmt.pix.sizeimage = SAA7164_SIZEIMAGE; in vidioc_fmt_vid_cap()
519 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in vidioc_fmt_vid_cap()
520 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in vidioc_fmt_vid_cap()
521 f->fmt.pix.width = port->width; in vidioc_fmt_vid_cap()
522 f->fmt.pix.height = port->height; in vidioc_fmt_vid_cap()
526 static int saa7164_encoder_stop_port(struct saa7164_port *port) in saa7164_encoder_stop_port() argument
528 struct saa7164_dev *dev = port->dev; in saa7164_encoder_stop_port()
531 ret = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); in saa7164_encoder_stop_port()
535 ret = -EIO; in saa7164_encoder_stop_port()
544 static int saa7164_encoder_acquire_port(struct saa7164_port *port) in saa7164_encoder_acquire_port() argument
546 struct saa7164_dev *dev = port->dev; in saa7164_encoder_acquire_port()
549 ret = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); in saa7164_encoder_acquire_port()
553 ret = -EIO; in saa7164_encoder_acquire_port()
562 static int saa7164_encoder_pause_port(struct saa7164_port *port) in saa7164_encoder_pause_port() argument
564 struct saa7164_dev *dev = port->dev; in saa7164_encoder_pause_port()
567 ret = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); in saa7164_encoder_pause_port()
571 ret = -EIO; in saa7164_encoder_pause_port()
586 static int saa7164_encoder_stop_streaming(struct saa7164_port *port) in saa7164_encoder_stop_streaming() argument
588 struct saa7164_dev *dev = port->dev; in saa7164_encoder_stop_streaming()
594 dprintk(DBGLVL_ENC, "%s(port=%d)\n", __func__, port->nr); in saa7164_encoder_stop_streaming()
596 ret = saa7164_encoder_pause_port(port); in saa7164_encoder_stop_streaming()
597 ret = saa7164_encoder_acquire_port(port); in saa7164_encoder_stop_streaming()
598 ret = saa7164_encoder_stop_port(port); in saa7164_encoder_stop_streaming()
600 dprintk(DBGLVL_ENC, "%s(port=%d) Hardware stopped\n", __func__, in saa7164_encoder_stop_streaming()
601 port->nr); in saa7164_encoder_stop_streaming()
604 mutex_lock(&port->dmaqueue_lock); in saa7164_encoder_stop_streaming()
607 list_for_each_safe(c, n, &port->dmaqueue.list) { in saa7164_encoder_stop_streaming()
609 buf->flags = SAA7164_BUFFER_FREE; in saa7164_encoder_stop_streaming()
610 buf->pos = 0; in saa7164_encoder_stop_streaming()
613 list_for_each_safe(c, n, &port->list_buf_used.list) { in saa7164_encoder_stop_streaming()
615 ubuf->pos = 0; in saa7164_encoder_stop_streaming()
616 list_move_tail(&ubuf->list, &port->list_buf_free.list); in saa7164_encoder_stop_streaming()
619 mutex_unlock(&port->dmaqueue_lock); in saa7164_encoder_stop_streaming()
622 saa7164_encoder_buffers_dealloc(port); in saa7164_encoder_stop_streaming()
624 dprintk(DBGLVL_ENC, "%s(port=%d) Released\n", __func__, port->nr); in saa7164_encoder_stop_streaming()
629 static int saa7164_encoder_start_streaming(struct saa7164_port *port) in saa7164_encoder_start_streaming() argument
631 struct saa7164_dev *dev = port->dev; in saa7164_encoder_start_streaming()
634 dprintk(DBGLVL_ENC, "%s(port=%d)\n", __func__, port->nr); in saa7164_encoder_start_streaming()
636 port->done_first_interrupt = 0; in saa7164_encoder_start_streaming()
642 saa7164_encoder_buffers_alloc(port); in saa7164_encoder_start_streaming()
645 saa7164_api_set_encoder(port); in saa7164_encoder_start_streaming()
646 saa7164_api_get_encoder(port); in saa7164_encoder_start_streaming()
649 saa7164_buffer_cfg_port(port); in saa7164_encoder_start_streaming()
652 result = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); in saa7164_encoder_start_streaming()
658 result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); in saa7164_encoder_start_streaming()
663 ret = -EIO; in saa7164_encoder_start_streaming()
669 result = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); in saa7164_encoder_start_streaming()
675 result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); in saa7164_encoder_start_streaming()
681 ret = -EIO; in saa7164_encoder_start_streaming()
687 result = saa7164_api_transition_port(port, SAA_DMASTATE_RUN); in saa7164_encoder_start_streaming()
693 result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); in saa7164_encoder_start_streaming()
699 ret = -EIO; in saa7164_encoder_start_streaming()
710 struct saa7164_port *port; in fops_open() local
713 port = (struct saa7164_port *)video_get_drvdata(video_devdata(file)); in fops_open()
714 if (!port) in fops_open()
715 return -ENODEV; in fops_open()
717 dev = port->dev; in fops_open()
724 return -ENOMEM; in fops_open()
726 fh->port = port; in fops_open()
727 v4l2_fh_init(&fh->fh, video_devdata(file)); in fops_open()
728 v4l2_fh_add(&fh->fh); in fops_open()
729 file->private_data = fh; in fops_open()
736 struct saa7164_encoder_fh *fh = file->private_data; in fops_release()
737 struct saa7164_port *port = fh->port; in fops_release() local
738 struct saa7164_dev *dev = port->dev; in fops_release()
743 if (atomic_cmpxchg(&fh->v4l_reading, 1, 0) == 1) { in fops_release()
744 if (atomic_dec_return(&port->v4l_reader_count) == 0) { in fops_release()
746 saa7164_encoder_stop_streaming(port); in fops_release()
750 v4l2_fh_del(&fh->fh); in fops_release()
751 v4l2_fh_exit(&fh->fh); in fops_release()
758 saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port) in saa7164_enc_next_buf() argument
761 struct saa7164_dev *dev = port->dev; in saa7164_enc_next_buf()
764 mutex_lock(&port->dmaqueue_lock); in saa7164_enc_next_buf()
765 if (!list_empty(&port->list_buf_used.list)) { in saa7164_enc_next_buf()
766 ubuf = list_first_entry(&port->list_buf_used.list, in saa7164_enc_next_buf()
770 crc = crc32(0, ubuf->data, ubuf->actual_size); in saa7164_enc_next_buf()
771 if (crc != ubuf->crc) { in saa7164_enc_next_buf()
775 ubuf, ubuf->crc, crc); in saa7164_enc_next_buf()
780 mutex_unlock(&port->dmaqueue_lock); in saa7164_enc_next_buf()
790 struct saa7164_encoder_fh *fh = file->private_data; in fops_read()
791 struct saa7164_port *port = fh->port; in fops_read() local
793 struct saa7164_dev *dev = port->dev; in fops_read()
798 port->last_read_msecs_diff = port->last_read_msecs; in fops_read()
799 port->last_read_msecs = jiffies_to_msecs(jiffies); in fops_read()
800 port->last_read_msecs_diff = port->last_read_msecs - in fops_read()
801 port->last_read_msecs_diff; in fops_read()
803 saa7164_histogram_update(&port->read_interval, in fops_read()
804 port->last_read_msecs_diff); in fops_read()
808 return -ESPIPE; in fops_read()
811 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) { in fops_read()
812 if (atomic_inc_return(&port->v4l_reader_count) == 1) { in fops_read()
814 if (saa7164_encoder_initialize(port) < 0) { in fops_read()
816 return -EINVAL; in fops_read()
819 saa7164_encoder_start_streaming(port); in fops_read()
825 if ((file->f_flags & O_NONBLOCK) == 0) { in fops_read()
826 if (wait_event_interruptible(port->wait_read, in fops_read()
827 saa7164_enc_next_buf(port))) { in fops_read()
829 return -ERESTARTSYS; in fops_read()
834 ubuf = saa7164_enc_next_buf(port); in fops_read()
839 rem = ubuf->actual_size - ubuf->pos; in fops_read()
842 p = ubuf->data + ubuf->pos; in fops_read()
845 "%s() count=%d cnt=%d rem=%d buf=%p buf->pos=%d\n", in fops_read()
846 __func__, (int)count, cnt, rem, ubuf, ubuf->pos); in fops_read()
852 ret = -EFAULT; in fops_read()
857 ubuf->pos += cnt; in fops_read()
858 count -= cnt; in fops_read()
862 if (ubuf->pos > ubuf->actual_size) in fops_read()
865 if (ubuf->pos == ubuf->actual_size) { in fops_read()
870 ubuf->pos = 0; in fops_read()
872 mutex_lock(&port->dmaqueue_lock); in fops_read()
873 list_move_tail(&ubuf->list, &port->list_buf_free.list); in fops_read()
874 mutex_unlock(&port->dmaqueue_lock); in fops_read()
877 if ((file->f_flags & O_NONBLOCK) == 0) { in fops_read()
878 if (wait_event_interruptible(port->wait_read, in fops_read()
879 saa7164_enc_next_buf(port))) { in fops_read()
883 ubuf = saa7164_enc_next_buf(port); in fops_read()
888 ret = -EAGAIN; in fops_read()
897 (struct saa7164_encoder_fh *)file->private_data; in fops_poll()
898 struct saa7164_port *port = fh->port; in fops_poll() local
901 port->last_poll_msecs_diff = port->last_poll_msecs; in fops_poll()
902 port->last_poll_msecs = jiffies_to_msecs(jiffies); in fops_poll()
903 port->last_poll_msecs_diff = port->last_poll_msecs - in fops_poll()
904 port->last_poll_msecs_diff; in fops_poll()
906 saa7164_histogram_update(&port->poll_interval, in fops_poll()
907 port->last_poll_msecs_diff); in fops_poll()
912 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) { in fops_poll()
913 if (atomic_inc_return(&port->v4l_reader_count) == 1) { in fops_poll()
914 if (saa7164_encoder_initialize(port) < 0) in fops_poll()
916 saa7164_encoder_start_streaming(port); in fops_poll()
922 if (!list_empty(&port->list_buf_used.list)) in fops_poll()
965 .minor = -1,
972 struct saa7164_port *port, in saa7164_encoder_alloc() argument
978 struct saa7164_dev *dev = port->dev; in saa7164_encoder_alloc()
987 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, in saa7164_encoder_alloc()
988 type, saa7164_boards[dev->board].name); in saa7164_encoder_alloc()
990 vfd->v4l2_dev = &dev->v4l2_dev; in saa7164_encoder_alloc()
991 vfd->release = video_device_release; in saa7164_encoder_alloc()
995 int saa7164_encoder_register(struct saa7164_port *port) in saa7164_encoder_register() argument
997 struct saa7164_dev *dev = port->dev; in saa7164_encoder_register()
998 struct v4l2_ctrl_handler *hdl = &port->ctrl_handler; in saa7164_encoder_register()
999 int result = -ENODEV; in saa7164_encoder_register()
1003 BUG_ON(port->type != SAA7164_MPEG_ENCODER); in saa7164_encoder_register()
1006 if (port->hwcfg.BARLocation == 0) { in saa7164_encoder_register()
1009 result = -ENOMEM; in saa7164_encoder_register()
1015 port->encodernorm = saa7164_tvnorms[0]; in saa7164_encoder_register()
1016 port->width = 720; in saa7164_encoder_register()
1017 port->mux_input = 1; /* Composite */ in saa7164_encoder_register()
1018 port->video_format = EU_VIDEO_FORMAT_MPEG_2; in saa7164_encoder_register()
1019 port->audio_format = 0; in saa7164_encoder_register()
1020 port->video_resolution = 0; in saa7164_encoder_register()
1021 port->freq = SAA7164_TV_MIN_FREQ; in saa7164_encoder_register()
1037 V4L2_CID_AUDIO_VOLUME, -83, 24, 1, 20); in saa7164_encoder_register()
1062 if (hdl->error) { in saa7164_encoder_register()
1063 result = hdl->error; in saa7164_encoder_register()
1067 port->std = V4L2_STD_NTSC_M; in saa7164_encoder_register()
1069 if (port->encodernorm.id & V4L2_STD_525_60) in saa7164_encoder_register()
1070 port->height = 480; in saa7164_encoder_register()
1072 port->height = 576; in saa7164_encoder_register()
1075 port->v4l_device = saa7164_encoder_alloc(port, in saa7164_encoder_register()
1076 dev->pci, &saa7164_mpeg_template, "mpeg"); in saa7164_encoder_register()
1078 if (!port->v4l_device) { in saa7164_encoder_register()
1080 dev->name); in saa7164_encoder_register()
1081 result = -ENOMEM; in saa7164_encoder_register()
1085 port->v4l_device->ctrl_handler = hdl; in saa7164_encoder_register()
1087 video_set_drvdata(port->v4l_device, port); in saa7164_encoder_register()
1088 result = video_register_device(port->v4l_device, in saa7164_encoder_register()
1089 VFL_TYPE_VIDEO, -1); in saa7164_encoder_register()
1092 dev->name); in saa7164_encoder_register()
1097 dev->name, port->v4l_device->num); in saa7164_encoder_register()
1100 saa7164_api_set_videomux(port); in saa7164_encoder_register()
1101 saa7164_api_set_usercontrol(port, PU_BRIGHTNESS_CONTROL); in saa7164_encoder_register()
1102 saa7164_api_set_usercontrol(port, PU_CONTRAST_CONTROL); in saa7164_encoder_register()
1103 saa7164_api_set_usercontrol(port, PU_HUE_CONTROL); in saa7164_encoder_register()
1104 saa7164_api_set_usercontrol(port, PU_SATURATION_CONTROL); in saa7164_encoder_register()
1105 saa7164_api_set_usercontrol(port, PU_SHARPNESS_CONTROL); in saa7164_encoder_register()
1106 saa7164_api_audio_mute(port, 0); in saa7164_encoder_register()
1107 saa7164_api_set_audio_volume(port, 20); in saa7164_encoder_register()
1108 saa7164_api_set_aspect_ratio(port); in saa7164_encoder_register()
1111 saa7164_api_set_audio_detection(port, 0); in saa7164_encoder_register()
1113 saa7164_api_set_encoder(port); in saa7164_encoder_register()
1114 saa7164_api_get_encoder(port); in saa7164_encoder_register()
1118 video_device_release(port->v4l_device); in saa7164_encoder_register()
1119 port->v4l_device = NULL; in saa7164_encoder_register()
1126 void saa7164_encoder_unregister(struct saa7164_port *port) in saa7164_encoder_unregister() argument
1128 struct saa7164_dev *dev = port->dev; in saa7164_encoder_unregister()
1130 dprintk(DBGLVL_ENC, "%s(port=%d)\n", __func__, port->nr); in saa7164_encoder_unregister()
1132 BUG_ON(port->type != SAA7164_MPEG_ENCODER); in saa7164_encoder_unregister()
1134 if (port->v4l_device) { in saa7164_encoder_unregister()
1135 if (port->v4l_device->minor != -1) in saa7164_encoder_unregister()
1136 video_unregister_device(port->v4l_device); in saa7164_encoder_unregister()
1138 video_device_release(port->v4l_device); in saa7164_encoder_unregister()
1140 port->v4l_device = NULL; in saa7164_encoder_unregister()
1142 v4l2_ctrl_handler_free(&port->ctrl_handler); in saa7164_encoder_unregister()
1144 dprintk(DBGLVL_ENC, "%s(port=%d) done\n", __func__, port->nr); in saa7164_encoder_unregister()