Lines Matching refs:vp
47 static void camif_cfg_video_path(struct camif_vp *vp) in camif_cfg_video_path() argument
49 WARN_ON(s3c_camif_get_scaler_config(vp, &vp->scaler)); in camif_cfg_video_path()
50 camif_hw_set_scaler(vp); in camif_cfg_video_path()
51 camif_hw_set_flip(vp); in camif_cfg_video_path()
52 camif_hw_set_target_format(vp); in camif_cfg_video_path()
53 camif_hw_set_output_dma(vp); in camif_cfg_video_path()
56 static void camif_prepare_dma_offset(struct camif_vp *vp) in camif_prepare_dma_offset() argument
58 struct camif_frame *f = &vp->out_frame; in camif_prepare_dma_offset()
68 static int s3c_camif_hw_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_init() argument
72 if (camif->sensor.sd == NULL || vp->out_fmt == NULL) in s3c_camif_hw_init()
76 camif_hw_clear_fifo_overflow(vp); in s3c_camif_hw_init()
85 camif_hw_set_input_path(vp); in s3c_camif_hw_init()
86 camif_cfg_video_path(vp); in s3c_camif_hw_init()
87 vp->state &= ~ST_VP_CONFIG; in s3c_camif_hw_init()
98 static int s3c_camif_hw_vp_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_vp_init() argument
102 if (vp->out_fmt == NULL) in s3c_camif_hw_vp_init()
105 camif_prepare_dma_offset(vp); in s3c_camif_hw_vp_init()
107 camif_hw_clear_fifo_overflow(vp); in s3c_camif_hw_vp_init()
108 camif_cfg_video_path(vp); in s3c_camif_hw_vp_init()
109 vp->state &= ~ST_VP_CONFIG; in s3c_camif_hw_vp_init()
150 static int camif_reinitialize(struct camif_vp *vp) in camif_reinitialize() argument
152 struct camif_dev *camif = vp->camif; in camif_reinitialize()
158 streaming = vp->state & ST_VP_SENSOR_STREAMING; in camif_reinitialize()
160 vp->state &= ~(ST_VP_PENDING | ST_VP_RUNNING | ST_VP_OFF | in camif_reinitialize()
165 while (!list_empty(&vp->pending_buf_q)) { in camif_reinitialize()
166 buf = camif_pending_queue_pop(vp); in camif_reinitialize()
170 while (!list_empty(&vp->active_buf_q)) { in camif_reinitialize()
171 buf = camif_active_queue_pop(vp); in camif_reinitialize()
183 static bool s3c_vp_active(struct camif_vp *vp) in s3c_vp_active() argument
185 struct camif_dev *camif = vp->camif; in s3c_vp_active()
190 ret = (vp->state & ST_VP_RUNNING) || (vp->state & ST_VP_PENDING); in s3c_vp_active()
208 static int camif_stop_capture(struct camif_vp *vp) in camif_stop_capture() argument
210 struct camif_dev *camif = vp->camif; in camif_stop_capture()
214 if (!s3c_vp_active(vp)) in camif_stop_capture()
218 vp->state &= ~(ST_VP_OFF | ST_VP_LASTIRQ); in camif_stop_capture()
219 vp->state |= ST_VP_ABORTING; in camif_stop_capture()
222 ret = wait_event_timeout(vp->irq_queue, in camif_stop_capture()
223 !(vp->state & ST_VP_ABORTING), in camif_stop_capture()
228 if (ret == 0 && !(vp->state & ST_VP_OFF)) { in camif_stop_capture()
230 vp->state &= ~(ST_VP_OFF | ST_VP_ABORTING | in camif_stop_capture()
233 camif_hw_disable_capture(vp); in camif_stop_capture()
234 camif_hw_enable_scaler(vp, false); in camif_stop_capture()
239 return camif_reinitialize(vp); in camif_stop_capture()
242 static int camif_prepare_addr(struct camif_vp *vp, struct vb2_buffer *vb, in camif_prepare_addr() argument
245 struct camif_frame *frame = &vp->out_frame; in camif_prepare_addr()
254 vp->out_fmt->colplanes, pix_size); in camif_prepare_addr()
258 switch (vp->out_fmt->colplanes) { in camif_prepare_addr()
271 if (vp->out_fmt->color == IMG_FMT_YCBCR422P) in camif_prepare_addr()
276 if (vp->out_fmt->color == IMG_FMT_YCRCB420) in camif_prepare_addr()
291 struct camif_vp *vp = priv; in s3c_camif_irq_handler() local
292 struct camif_dev *camif = vp->camif; in s3c_camif_irq_handler()
299 camif_hw_clear_pending_irq(vp); in s3c_camif_irq_handler()
301 status = camif_hw_get_status(vp); in s3c_camif_irq_handler()
304 camif_hw_clear_fifo_overflow(vp); in s3c_camif_irq_handler()
308 if (vp->state & ST_VP_ABORTING) { in s3c_camif_irq_handler()
309 if (vp->state & ST_VP_OFF) { in s3c_camif_irq_handler()
311 vp->state &= ~(ST_VP_OFF | ST_VP_ABORTING | in s3c_camif_irq_handler()
313 wake_up(&vp->irq_queue); in s3c_camif_irq_handler()
315 } else if (vp->state & ST_VP_LASTIRQ) { in s3c_camif_irq_handler()
316 camif_hw_disable_capture(vp); in s3c_camif_irq_handler()
317 camif_hw_enable_scaler(vp, false); in s3c_camif_irq_handler()
318 camif_hw_set_lastirq(vp, false); in s3c_camif_irq_handler()
319 vp->state |= ST_VP_OFF; in s3c_camif_irq_handler()
322 camif_hw_set_lastirq(vp, true); in s3c_camif_irq_handler()
323 vp->state |= ST_VP_LASTIRQ; in s3c_camif_irq_handler()
327 if (!list_empty(&vp->pending_buf_q) && (vp->state & ST_VP_RUNNING) && in s3c_camif_irq_handler()
328 !list_empty(&vp->active_buf_q)) { in s3c_camif_irq_handler()
341 vbuf = camif_active_queue_peek(vp, index); in s3c_camif_irq_handler()
348 vbuf->vb.v4l2_buf.sequence = vp->frame_sequence++; in s3c_camif_irq_handler()
352 vbuf = camif_pending_queue_pop(vp); in s3c_camif_irq_handler()
354 camif_hw_set_output_addr(vp, &vbuf->paddr, index); in s3c_camif_irq_handler()
355 camif_hw_set_output_addr(vp, &vbuf->paddr, index + 2); in s3c_camif_irq_handler()
358 camif_active_queue_add(vp, vbuf); in s3c_camif_irq_handler()
360 } else if (!(vp->state & ST_VP_ABORTING) && in s3c_camif_irq_handler()
361 (vp->state & ST_VP_PENDING)) { in s3c_camif_irq_handler()
362 vp->state |= ST_VP_RUNNING; in s3c_camif_irq_handler()
365 if (vp->state & ST_VP_CONFIG) { in s3c_camif_irq_handler()
366 camif_prepare_dma_offset(vp); in s3c_camif_irq_handler()
368 camif_hw_set_scaler(vp); in s3c_camif_irq_handler()
369 camif_hw_set_flip(vp); in s3c_camif_irq_handler()
374 vp->state &= ~ST_VP_CONFIG; in s3c_camif_irq_handler()
383 struct camif_vp *vp = vb2_get_drv_priv(vq); in start_streaming() local
384 struct camif_dev *camif = vp->camif; in start_streaming()
398 ret = s3c_camif_hw_init(camif, vp); in start_streaming()
400 ret = s3c_camif_hw_vp_init(camif, vp); in start_streaming()
405 camif_reinitialize(vp); in start_streaming()
410 vp->frame_sequence = 0; in start_streaming()
411 vp->state |= ST_VP_PENDING; in start_streaming()
413 if (!list_empty(&vp->pending_buf_q) && in start_streaming()
414 (!(vp->state & ST_VP_STREAMING) || in start_streaming()
415 !(vp->state & ST_VP_SENSOR_STREAMING))) { in start_streaming()
417 camif_hw_enable_scaler(vp, vp->scaler.enable); in start_streaming()
418 camif_hw_enable_capture(vp); in start_streaming()
419 vp->state |= ST_VP_STREAMING; in start_streaming()
421 if (!(vp->state & ST_VP_SENSOR_STREAMING)) { in start_streaming()
422 vp->state |= ST_VP_SENSOR_STREAMING; in start_streaming()
426 v4l2_err(&vp->vdev, "Sensor s_stream failed\n"); in start_streaming()
440 struct camif_vp *vp = vb2_get_drv_priv(vq); in stop_streaming() local
441 camif_stop_capture(vp); in stop_streaming()
449 struct camif_vp *vp = vb2_get_drv_priv(vq); in queue_setup() local
450 struct camif_dev *camif = vp->camif; in queue_setup()
451 struct camif_frame *frame = &vp->out_frame; in queue_setup()
452 const struct camif_fmt *fmt = vp->out_fmt; in queue_setup()
457 fmt = s3c_camif_find_format(vp, &pix->pixelformat, -1); in queue_setup()
479 struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
481 if (vp->out_fmt == NULL) in buffer_prepare()
484 if (vb2_plane_size(vb, 0) < vp->payload) { in buffer_prepare()
485 v4l2_err(&vp->vdev, "buffer too small: %lu, required: %u\n", in buffer_prepare()
486 vb2_plane_size(vb, 0), vp->payload); in buffer_prepare()
489 vb2_set_plane_payload(vb, 0, vp->payload); in buffer_prepare()
497 struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
498 struct camif_dev *camif = vp->camif; in buffer_queue()
502 WARN_ON(camif_prepare_addr(vp, &buf->vb, &buf->paddr)); in buffer_queue()
504 if (!(vp->state & ST_VP_STREAMING) && vp->active_buffers < 2) { in buffer_queue()
506 buf->index = vp->buf_index; in buffer_queue()
508 camif_hw_set_output_addr(vp, &buf->paddr, buf->index); in buffer_queue()
509 camif_hw_set_output_addr(vp, &buf->paddr, buf->index + 2); in buffer_queue()
511 camif_active_queue_add(vp, buf); in buffer_queue()
512 vp->buf_index = !vp->buf_index; in buffer_queue()
514 camif_pending_queue_add(vp, buf); in buffer_queue()
517 if (vb2_is_streaming(&vp->vb_queue) && !list_empty(&vp->pending_buf_q) in buffer_queue()
518 && !(vp->state & ST_VP_STREAMING)) { in buffer_queue()
520 vp->state |= ST_VP_STREAMING; in buffer_queue()
521 camif_hw_enable_scaler(vp, vp->scaler.enable); in buffer_queue()
522 camif_hw_enable_capture(vp); in buffer_queue()
525 if (!(vp->state & ST_VP_SENSOR_STREAMING)) { in buffer_queue()
527 vp->state |= ST_VP_SENSOR_STREAMING; in buffer_queue()
529 v4l2_err(&vp->vdev, "Sensor s_stream failed\n"); in buffer_queue()
551 struct camif_vp *vp = video_drvdata(file); in s3c_camif_open() local
552 struct camif_dev *camif = vp->camif; in s3c_camif_open()
555 pr_debug("[vp%d] state: %#x, owner: %p, pid: %d\n", vp->id, in s3c_camif_open()
556 vp->state, vp->owner, task_pid_nr(current)); in s3c_camif_open()
583 struct camif_vp *vp = video_drvdata(file); in s3c_camif_close() local
584 struct camif_dev *camif = vp->camif; in s3c_camif_close()
587 pr_debug("[vp%d] state: %#x, owner: %p, pid: %d\n", vp->id, in s3c_camif_close()
588 vp->state, vp->owner, task_pid_nr(current)); in s3c_camif_close()
592 if (vp->owner == file->private_data) { in s3c_camif_close()
593 camif_stop_capture(vp); in s3c_camif_close()
594 vb2_queue_release(&vp->vb_queue); in s3c_camif_close()
595 vp->owner = NULL; in s3c_camif_close()
610 struct camif_vp *vp = video_drvdata(file); in s3c_camif_poll() local
611 struct camif_dev *camif = vp->camif; in s3c_camif_poll()
615 if (vp->owner && vp->owner != file->private_data) in s3c_camif_poll()
618 ret = vb2_poll(&vp->vb_queue, file, wait); in s3c_camif_poll()
626 struct camif_vp *vp = video_drvdata(file); in s3c_camif_mmap() local
629 if (vp->owner && vp->owner != file->private_data) in s3c_camif_mmap()
632 ret = vb2_mmap(&vp->vb_queue, vma); in s3c_camif_mmap()
653 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_querycap() local
658 dev_name(vp->camif->dev), vp->id); in s3c_camif_vidioc_querycap()
669 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_enum_input() local
670 struct v4l2_subdev *sensor = vp->camif->sensor.sd; in s3c_camif_vidioc_enum_input()
696 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_enum_fmt() local
699 fmt = s3c_camif_find_format(vp, NULL, f->index); in s3c_camif_vidioc_enum_fmt()
713 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_g_fmt() local
715 struct camif_frame *frame = &vp->out_frame; in s3c_camif_vidioc_g_fmt()
716 const struct camif_fmt *fmt = vp->out_fmt; in s3c_camif_vidioc_g_fmt()
719 pix->sizeimage = vp->payload; in s3c_camif_vidioc_g_fmt()
730 static int __camif_video_try_format(struct camif_vp *vp, in __camif_video_try_format() argument
734 struct camif_dev *camif = vp->camif; in __camif_video_try_format()
740 fmt = s3c_camif_find_format(vp, &pix->pixelformat, 0); in __camif_video_try_format()
748 pix_lim = &camif->variant->vp_pix_limits[vp->id]; in __camif_video_try_format()
784 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_try_fmt() local
785 return __camif_video_try_format(vp, &f->fmt.pix, NULL); in s3c_camif_vidioc_try_fmt()
792 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_s_fmt() local
793 struct camif_frame *out_frame = &vp->out_frame; in s3c_camif_vidioc_s_fmt()
797 pr_debug("[vp%d]\n", vp->id); in s3c_camif_vidioc_s_fmt()
799 if (vb2_is_busy(&vp->vb_queue)) in s3c_camif_vidioc_s_fmt()
802 ret = __camif_video_try_format(vp, &f->fmt.pix, &fmt); in s3c_camif_vidioc_s_fmt()
806 vp->out_fmt = fmt; in s3c_camif_vidioc_s_fmt()
807 vp->payload = pix->sizeimage; in s3c_camif_vidioc_s_fmt()
817 if (vp->owner == NULL) in s3c_camif_vidioc_s_fmt()
818 vp->owner = priv; in s3c_camif_vidioc_s_fmt()
821 out_frame->f_width, out_frame->f_height, vp->payload, fmt->name, in s3c_camif_vidioc_s_fmt()
857 struct camif_vp *vp = video_drvdata(file); in s3c_camif_streamon() local
858 struct camif_dev *camif = vp->camif; in s3c_camif_streamon()
862 pr_debug("[vp%d]\n", vp->id); in s3c_camif_streamon()
867 if (vp->owner && vp->owner != priv) in s3c_camif_streamon()
870 if (s3c_vp_active(vp)) in s3c_camif_streamon()
883 return vb2_streamon(&vp->vb_queue, type); in s3c_camif_streamon()
889 struct camif_vp *vp = video_drvdata(file); in s3c_camif_streamoff() local
890 struct camif_dev *camif = vp->camif; in s3c_camif_streamoff()
893 pr_debug("[vp%d]\n", vp->id); in s3c_camif_streamoff()
898 if (vp->owner && vp->owner != priv) in s3c_camif_streamoff()
901 ret = vb2_streamoff(&vp->vb_queue, type); in s3c_camif_streamoff()
910 struct camif_vp *vp = video_drvdata(file); in s3c_camif_reqbufs() local
914 vp->id, rb->count, vp->owner, priv); in s3c_camif_reqbufs()
916 if (vp->owner && vp->owner != priv) in s3c_camif_reqbufs()
922 vp->owner = NULL; in s3c_camif_reqbufs()
924 ret = vb2_reqbufs(&vp->vb_queue, rb); in s3c_camif_reqbufs()
930 vb2_reqbufs(&vp->vb_queue, rb); in s3c_camif_reqbufs()
934 vp->reqbufs_count = rb->count; in s3c_camif_reqbufs()
935 if (vp->owner == NULL && rb->count > 0) in s3c_camif_reqbufs()
936 vp->owner = priv; in s3c_camif_reqbufs()
944 struct camif_vp *vp = video_drvdata(file); in s3c_camif_querybuf() local
945 return vb2_querybuf(&vp->vb_queue, buf); in s3c_camif_querybuf()
951 struct camif_vp *vp = video_drvdata(file); in s3c_camif_qbuf() local
953 pr_debug("[vp%d]\n", vp->id); in s3c_camif_qbuf()
955 if (vp->owner && vp->owner != priv) in s3c_camif_qbuf()
958 return vb2_qbuf(&vp->vb_queue, buf); in s3c_camif_qbuf()
964 struct camif_vp *vp = video_drvdata(file); in s3c_camif_dqbuf() local
966 pr_debug("[vp%d] sequence: %d\n", vp->id, vp->frame_sequence); in s3c_camif_dqbuf()
968 if (vp->owner && vp->owner != priv) in s3c_camif_dqbuf()
971 return vb2_dqbuf(&vp->vb_queue, buf, file->f_flags & O_NONBLOCK); in s3c_camif_dqbuf()
977 struct camif_vp *vp = video_drvdata(file); in s3c_camif_create_bufs() local
980 if (vp->owner && vp->owner != priv) in s3c_camif_create_bufs()
984 ret = vb2_create_bufs(&vp->vb_queue, create); in s3c_camif_create_bufs()
986 if (!ret && vp->owner == NULL) in s3c_camif_create_bufs()
987 vp->owner = priv; in s3c_camif_create_bufs()
995 struct camif_vp *vp = video_drvdata(file); in s3c_camif_prepare_buf() local
996 return vb2_prepare_buf(&vp->vb_queue, b); in s3c_camif_prepare_buf()
1002 struct camif_vp *vp = video_drvdata(file); in s3c_camif_g_selection() local
1012 sel->r.width = vp->out_frame.f_width; in s3c_camif_g_selection()
1013 sel->r.height = vp->out_frame.f_height; in s3c_camif_g_selection()
1017 sel->r = vp->out_frame.rect; in s3c_camif_g_selection()
1024 static void __camif_try_compose(struct camif_dev *camif, struct camif_vp *vp, in __camif_try_compose() argument
1029 *r = vp->out_frame.rect; in __camif_try_compose()
1039 struct camif_vp *vp = video_drvdata(file); in s3c_camif_s_selection() local
1040 struct camif_dev *camif = vp->camif; in s3c_camif_s_selection()
1048 __camif_try_compose(camif, vp, &rect); in s3c_camif_s_selection()
1052 vp->out_frame.rect = rect; in s3c_camif_s_selection()
1053 vp->state |= ST_VP_CONFIG; in s3c_camif_s_selection()
1092 struct camif_vp *vp = ctrl->priv; in s3c_camif_video_s_ctrl() local
1093 struct camif_dev *camif = vp->camif; in s3c_camif_video_s_ctrl()
1096 pr_debug("[vp%d] ctrl: %s, value: %d\n", vp->id, in s3c_camif_video_s_ctrl()
1103 vp->hflip = ctrl->val; in s3c_camif_video_s_ctrl()
1107 vp->vflip = ctrl->val; in s3c_camif_video_s_ctrl()
1111 vp->state |= ST_VP_CONFIG; in s3c_camif_video_s_ctrl()
1123 struct camif_vp *vp = &camif->vp[idx]; in s3c_camif_register_video_node() local
1124 struct vb2_queue *q = &vp->vb_queue; in s3c_camif_register_video_node()
1125 struct video_device *vfd = &vp->vdev; in s3c_camif_register_video_node()
1131 vp->id == 0 ? "codec" : "preview"); in s3c_camif_register_video_node()
1139 vp->reqbufs_count = 0; in s3c_camif_register_video_node()
1141 INIT_LIST_HEAD(&vp->pending_buf_q); in s3c_camif_register_video_node()
1142 INIT_LIST_HEAD(&vp->active_buf_q); in s3c_camif_register_video_node()
1150 q->drv_priv = vp; in s3c_camif_register_video_node()
1152 q->lock = &vp->camif->lock; in s3c_camif_register_video_node()
1158 vp->pad.flags = MEDIA_PAD_FL_SINK; in s3c_camif_register_video_node()
1159 ret = media_entity_init(&vfd->entity, 1, &vp->pad, 0); in s3c_camif_register_video_node()
1163 video_set_drvdata(vfd, vp); in s3c_camif_register_video_node()
1165 v4l2_ctrl_handler_init(&vp->ctrl_handler, 1); in s3c_camif_register_video_node()
1166 ctrl = v4l2_ctrl_new_std(&vp->ctrl_handler, &s3c_camif_video_ctrl_ops, in s3c_camif_register_video_node()
1169 ctrl->priv = vp; in s3c_camif_register_video_node()
1170 ctrl = v4l2_ctrl_new_std(&vp->ctrl_handler, &s3c_camif_video_ctrl_ops, in s3c_camif_register_video_node()
1173 ctrl->priv = vp; in s3c_camif_register_video_node()
1175 ret = vp->ctrl_handler.error; in s3c_camif_register_video_node()
1179 vfd->ctrl_handler = &vp->ctrl_handler; in s3c_camif_register_video_node()
1190 v4l2_ctrl_handler_free(&vp->ctrl_handler); in s3c_camif_register_video_node()
1200 struct video_device *vfd = &camif->vp[idx].vdev; in s3c_camif_unregister_video_node()
1319 if (vb2_is_busy(&camif->vp[VP_CODEC].vb_queue) || in s3c_camif_subdev_set_fmt()
1320 vb2_is_busy(&camif->vp[VP_PREVIEW].vb_queue)) { in s3c_camif_subdev_set_fmt()
1347 struct camif_frame *frame = &camif->vp[i].out_frame; in s3c_camif_subdev_set_fmt()
1440 struct v4l2_rect *or = &camif->vp[i].out_frame.rect; in __camif_try_crop()
1477 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_subdev_set_selection() local
1478 scaler = vp->scaler; in s3c_camif_subdev_set_selection()
1479 if (s3c_camif_get_scaler_config(vp, &scaler)) in s3c_camif_subdev_set_selection()
1481 vp->scaler = scaler; in s3c_camif_subdev_set_selection()
1482 vp->state |= ST_VP_CONFIG; in s3c_camif_subdev_set_selection()
1542 camif->vp[VP_CODEC].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1543 camif->vp[VP_PREVIEW].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1632 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_set_defaults() local
1633 struct camif_frame *f = &vp->out_frame; in s3c_camif_set_defaults()
1635 vp->camif = camif; in s3c_camif_set_defaults()
1636 vp->id = i; in s3c_camif_set_defaults()
1637 vp->offset = camif->variant->vp_offset; in s3c_camif_set_defaults()
1640 vp->fmt_flags = i ? FMT_FL_S3C24XX_PREVIEW : in s3c_camif_set_defaults()
1643 vp->fmt_flags = FMT_FL_S3C64XX; in s3c_camif_set_defaults()
1645 vp->out_fmt = s3c_camif_find_format(vp, NULL, 0); in s3c_camif_set_defaults()
1646 BUG_ON(vp->out_fmt == NULL); in s3c_camif_set_defaults()
1655 vp->scaler.enable = 1; in s3c_camif_set_defaults()
1657 vp->payload = (f->f_width * f->f_height * in s3c_camif_set_defaults()
1658 vp->out_fmt->depth) / 8; in s3c_camif_set_defaults()