Lines Matching full:vp
43 /* Locking: called with vp->camif->slock spinlock held */
44 static void camif_cfg_video_path(struct camif_vp *vp) in camif_cfg_video_path() argument
46 WARN_ON(s3c_camif_get_scaler_config(vp, &vp->scaler)); in camif_cfg_video_path()
47 camif_hw_set_scaler(vp); in camif_cfg_video_path()
48 camif_hw_set_flip(vp); in camif_cfg_video_path()
49 camif_hw_set_target_format(vp); in camif_cfg_video_path()
50 camif_hw_set_output_dma(vp); in camif_cfg_video_path()
53 static void camif_prepare_dma_offset(struct camif_vp *vp) in camif_prepare_dma_offset() argument
55 struct camif_frame *f = &vp->out_frame; in camif_prepare_dma_offset()
65 static int s3c_camif_hw_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_init() argument
69 if (camif->sensor.sd == NULL || vp->out_fmt == NULL) in s3c_camif_hw_init()
73 camif_hw_clear_fifo_overflow(vp); in s3c_camif_hw_init()
82 camif_hw_set_input_path(vp); in s3c_camif_hw_init()
83 camif_cfg_video_path(vp); in s3c_camif_hw_init()
84 vp->state &= ~ST_VP_CONFIG; in s3c_camif_hw_init()
95 static int s3c_camif_hw_vp_init(struct camif_dev *camif, struct camif_vp *vp) in s3c_camif_hw_vp_init() argument
99 if (vp->out_fmt == NULL) in s3c_camif_hw_vp_init()
102 camif_prepare_dma_offset(vp); in s3c_camif_hw_vp_init()
104 camif_hw_clear_fifo_overflow(vp); in s3c_camif_hw_vp_init()
105 camif_cfg_video_path(vp); in s3c_camif_hw_vp_init()
106 vp->state &= ~ST_VP_CONFIG; in s3c_camif_hw_vp_init()
149 static int camif_reinitialize(struct camif_vp *vp) in camif_reinitialize() argument
151 struct camif_dev *camif = vp->camif; in camif_reinitialize()
157 streaming = vp->state & ST_VP_SENSOR_STREAMING; in camif_reinitialize()
159 vp->state &= ~(ST_VP_PENDING | ST_VP_RUNNING | ST_VP_OFF | in camif_reinitialize()
164 while (!list_empty(&vp->pending_buf_q)) { in camif_reinitialize()
165 buf = camif_pending_queue_pop(vp); in camif_reinitialize()
169 while (!list_empty(&vp->active_buf_q)) { in camif_reinitialize()
170 buf = camif_active_queue_pop(vp); in camif_reinitialize()
182 static bool s3c_vp_active(struct camif_vp *vp) in s3c_vp_active() argument
184 struct camif_dev *camif = vp->camif; in s3c_vp_active()
189 ret = (vp->state & ST_VP_RUNNING) || (vp->state & ST_VP_PENDING); in s3c_vp_active()
207 static int camif_stop_capture(struct camif_vp *vp) in camif_stop_capture() argument
209 struct camif_dev *camif = vp->camif; in camif_stop_capture()
213 if (!s3c_vp_active(vp)) in camif_stop_capture()
217 vp->state &= ~(ST_VP_OFF | ST_VP_LASTIRQ); in camif_stop_capture()
218 vp->state |= ST_VP_ABORTING; in camif_stop_capture()
221 ret = wait_event_timeout(vp->irq_queue, in camif_stop_capture()
222 !(vp->state & ST_VP_ABORTING), in camif_stop_capture()
227 if (ret == 0 && !(vp->state & ST_VP_OFF)) { in camif_stop_capture()
229 vp->state &= ~(ST_VP_OFF | ST_VP_ABORTING | in camif_stop_capture()
232 camif_hw_disable_capture(vp); in camif_stop_capture()
233 camif_hw_enable_scaler(vp, false); in camif_stop_capture()
238 return camif_reinitialize(vp); in camif_stop_capture()
241 static int camif_prepare_addr(struct camif_vp *vp, struct vb2_buffer *vb, in camif_prepare_addr() argument
244 struct camif_frame *frame = &vp->out_frame; in camif_prepare_addr()
253 vp->out_fmt->colplanes, pix_size); in camif_prepare_addr()
257 switch (vp->out_fmt->colplanes) { in camif_prepare_addr()
270 if (vp->out_fmt->color == IMG_FMT_YCBCR422P) in camif_prepare_addr()
275 if (vp->out_fmt->color == IMG_FMT_YCRCB420) in camif_prepare_addr()
290 struct camif_vp *vp = priv; in s3c_camif_irq_handler() local
291 struct camif_dev *camif = vp->camif; in s3c_camif_irq_handler()
298 camif_hw_clear_pending_irq(vp); in s3c_camif_irq_handler()
300 status = camif_hw_get_status(vp); in s3c_camif_irq_handler()
303 camif_hw_clear_fifo_overflow(vp); in s3c_camif_irq_handler()
307 if (vp->state & ST_VP_ABORTING) { in s3c_camif_irq_handler()
308 if (vp->state & ST_VP_OFF) { in s3c_camif_irq_handler()
310 vp->state &= ~(ST_VP_OFF | ST_VP_ABORTING | in s3c_camif_irq_handler()
312 wake_up(&vp->irq_queue); in s3c_camif_irq_handler()
314 } else if (vp->state & ST_VP_LASTIRQ) { in s3c_camif_irq_handler()
315 camif_hw_disable_capture(vp); in s3c_camif_irq_handler()
316 camif_hw_enable_scaler(vp, false); in s3c_camif_irq_handler()
317 camif_hw_set_lastirq(vp, false); in s3c_camif_irq_handler()
318 vp->state |= ST_VP_OFF; in s3c_camif_irq_handler()
321 camif_hw_set_lastirq(vp, true); in s3c_camif_irq_handler()
322 vp->state |= ST_VP_LASTIRQ; in s3c_camif_irq_handler()
326 if (!list_empty(&vp->pending_buf_q) && (vp->state & ST_VP_RUNNING) && in s3c_camif_irq_handler()
327 !list_empty(&vp->active_buf_q)) { in s3c_camif_irq_handler()
336 vbuf = camif_active_queue_peek(vp, index); in s3c_camif_irq_handler()
341 vbuf->vb.sequence = vp->frame_sequence++; in s3c_camif_irq_handler()
345 vbuf = camif_pending_queue_pop(vp); in s3c_camif_irq_handler()
347 camif_hw_set_output_addr(vp, &vbuf->paddr, index); in s3c_camif_irq_handler()
348 camif_hw_set_output_addr(vp, &vbuf->paddr, index + 2); in s3c_camif_irq_handler()
351 camif_active_queue_add(vp, vbuf); in s3c_camif_irq_handler()
353 } else if (!(vp->state & ST_VP_ABORTING) && in s3c_camif_irq_handler()
354 (vp->state & ST_VP_PENDING)) { in s3c_camif_irq_handler()
355 vp->state |= ST_VP_RUNNING; in s3c_camif_irq_handler()
358 if (vp->state & ST_VP_CONFIG) { in s3c_camif_irq_handler()
359 camif_prepare_dma_offset(vp); in s3c_camif_irq_handler()
361 camif_hw_set_scaler(vp); in s3c_camif_irq_handler()
362 camif_hw_set_flip(vp); in s3c_camif_irq_handler()
367 vp->state &= ~ST_VP_CONFIG; in s3c_camif_irq_handler()
376 struct camif_vp *vp = vb2_get_drv_priv(vq); in start_streaming() local
377 struct camif_dev *camif = vp->camif; in start_streaming()
391 ret = s3c_camif_hw_init(camif, vp); in start_streaming()
393 ret = s3c_camif_hw_vp_init(camif, vp); in start_streaming()
398 camif_reinitialize(vp); in start_streaming()
403 vp->frame_sequence = 0; in start_streaming()
404 vp->state |= ST_VP_PENDING; in start_streaming()
406 if (!list_empty(&vp->pending_buf_q) && in start_streaming()
407 (!(vp->state & ST_VP_STREAMING) || in start_streaming()
408 !(vp->state & ST_VP_SENSOR_STREAMING))) { in start_streaming()
410 camif_hw_enable_scaler(vp, vp->scaler.enable); in start_streaming()
411 camif_hw_enable_capture(vp); in start_streaming()
412 vp->state |= ST_VP_STREAMING; in start_streaming()
414 if (!(vp->state & ST_VP_SENSOR_STREAMING)) { in start_streaming()
415 vp->state |= ST_VP_SENSOR_STREAMING; in start_streaming()
419 v4l2_err(&vp->vdev, "Sensor s_stream failed\n"); in start_streaming()
433 struct camif_vp *vp = vb2_get_drv_priv(vq); in stop_streaming() local
434 camif_stop_capture(vp); in stop_streaming()
441 struct camif_vp *vp = vb2_get_drv_priv(vq); in queue_setup() local
442 struct camif_frame *frame = &vp->out_frame; in queue_setup()
443 const struct camif_fmt *fmt = vp->out_fmt; in queue_setup()
463 struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue); in buffer_prepare() local
465 if (vp->out_fmt == NULL) in buffer_prepare()
468 if (vb2_plane_size(vb, 0) < vp->payload) { in buffer_prepare()
469 v4l2_err(&vp->vdev, "buffer too small: %lu, required: %u\n", in buffer_prepare()
470 vb2_plane_size(vb, 0), vp->payload); in buffer_prepare()
473 vb2_set_plane_payload(vb, 0, vp->payload); in buffer_prepare()
482 struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue); in buffer_queue() local
483 struct camif_dev *camif = vp->camif; in buffer_queue()
487 WARN_ON(camif_prepare_addr(vp, &buf->vb.vb2_buf, &buf->paddr)); in buffer_queue()
489 if (!(vp->state & ST_VP_STREAMING) && vp->active_buffers < 2) { in buffer_queue()
491 buf->index = vp->buf_index; in buffer_queue()
493 camif_hw_set_output_addr(vp, &buf->paddr, buf->index); in buffer_queue()
494 camif_hw_set_output_addr(vp, &buf->paddr, buf->index + 2); in buffer_queue()
496 camif_active_queue_add(vp, buf); in buffer_queue()
497 vp->buf_index = !vp->buf_index; in buffer_queue()
499 camif_pending_queue_add(vp, buf); in buffer_queue()
502 if (vb2_is_streaming(&vp->vb_queue) && !list_empty(&vp->pending_buf_q) in buffer_queue()
503 && !(vp->state & ST_VP_STREAMING)) { in buffer_queue()
505 vp->state |= ST_VP_STREAMING; in buffer_queue()
506 camif_hw_enable_scaler(vp, vp->scaler.enable); in buffer_queue()
507 camif_hw_enable_capture(vp); in buffer_queue()
510 if (!(vp->state & ST_VP_SENSOR_STREAMING)) { in buffer_queue()
512 vp->state |= ST_VP_SENSOR_STREAMING; in buffer_queue()
514 v4l2_err(&vp->vdev, "Sensor s_stream failed\n"); in buffer_queue()
536 struct camif_vp *vp = video_drvdata(file); in s3c_camif_open() local
537 struct camif_dev *camif = vp->camif; in s3c_camif_open()
540 pr_debug("[vp%d] state: %#x, owner: %p, pid: %d\n", vp->id, in s3c_camif_open()
541 vp->state, vp->owner, task_pid_nr(current)); in s3c_camif_open()
568 struct camif_vp *vp = video_drvdata(file); in s3c_camif_close() local
569 struct camif_dev *camif = vp->camif; in s3c_camif_close()
572 pr_debug("[vp%d] state: %#x, owner: %p, pid: %d\n", vp->id, in s3c_camif_close()
573 vp->state, vp->owner, task_pid_nr(current)); in s3c_camif_close()
577 if (vp->owner == file->private_data) { in s3c_camif_close()
578 camif_stop_capture(vp); in s3c_camif_close()
579 vb2_queue_release(&vp->vb_queue); in s3c_camif_close()
580 vp->owner = NULL; in s3c_camif_close()
595 struct camif_vp *vp = video_drvdata(file); in s3c_camif_poll() local
596 struct camif_dev *camif = vp->camif; in s3c_camif_poll()
600 if (vp->owner && vp->owner != file->private_data) in s3c_camif_poll()
603 ret = vb2_poll(&vp->vb_queue, file, wait); in s3c_camif_poll()
611 struct camif_vp *vp = video_drvdata(file); in s3c_camif_mmap() local
614 if (vp->owner && vp->owner != file->private_data) in s3c_camif_mmap()
617 ret = vb2_mmap(&vp->vb_queue, vma); in s3c_camif_mmap()
638 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_querycap() local
643 dev_name(vp->camif->dev), vp->id); in s3c_camif_vidioc_querycap()
650 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_enum_input() local
651 struct v4l2_subdev *sensor = vp->camif->sensor.sd; in s3c_camif_vidioc_enum_input()
677 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_enum_fmt() local
680 fmt = s3c_camif_find_format(vp, NULL, f->index); in s3c_camif_vidioc_enum_fmt()
691 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_g_fmt() local
693 struct camif_frame *frame = &vp->out_frame; in s3c_camif_vidioc_g_fmt()
694 const struct camif_fmt *fmt = vp->out_fmt; in s3c_camif_vidioc_g_fmt()
697 pix->sizeimage = vp->payload; in s3c_camif_vidioc_g_fmt()
708 static int __camif_video_try_format(struct camif_vp *vp, in __camif_video_try_format() argument
712 struct camif_dev *camif = vp->camif; in __camif_video_try_format()
718 fmt = s3c_camif_find_format(vp, &pix->pixelformat, 0); in __camif_video_try_format()
726 pix_lim = &camif->variant->vp_pix_limits[vp->id]; in __camif_video_try_format()
762 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_try_fmt() local
763 return __camif_video_try_format(vp, &f->fmt.pix, NULL); in s3c_camif_vidioc_try_fmt()
770 struct camif_vp *vp = video_drvdata(file); in s3c_camif_vidioc_s_fmt() local
771 struct camif_frame *out_frame = &vp->out_frame; in s3c_camif_vidioc_s_fmt()
775 pr_debug("[vp%d]\n", vp->id); in s3c_camif_vidioc_s_fmt()
777 if (vb2_is_busy(&vp->vb_queue)) in s3c_camif_vidioc_s_fmt()
780 ret = __camif_video_try_format(vp, &f->fmt.pix, &fmt); in s3c_camif_vidioc_s_fmt()
784 vp->out_fmt = fmt; in s3c_camif_vidioc_s_fmt()
785 vp->payload = pix->sizeimage; in s3c_camif_vidioc_s_fmt()
795 if (vp->owner == NULL) in s3c_camif_vidioc_s_fmt()
796 vp->owner = priv; in s3c_camif_vidioc_s_fmt()
799 out_frame->f_width, out_frame->f_height, vp->payload, in s3c_camif_vidioc_s_fmt()
836 struct camif_vp *vp = video_drvdata(file); in s3c_camif_streamon() local
837 struct camif_dev *camif = vp->camif; in s3c_camif_streamon()
841 pr_debug("[vp%d]\n", vp->id); in s3c_camif_streamon()
846 if (vp->owner && vp->owner != priv) in s3c_camif_streamon()
849 if (s3c_vp_active(vp)) in s3c_camif_streamon()
862 return vb2_streamon(&vp->vb_queue, type); in s3c_camif_streamon()
868 struct camif_vp *vp = video_drvdata(file); in s3c_camif_streamoff() local
869 struct camif_dev *camif = vp->camif; in s3c_camif_streamoff()
872 pr_debug("[vp%d]\n", vp->id); in s3c_camif_streamoff()
877 if (vp->owner && vp->owner != priv) in s3c_camif_streamoff()
880 ret = vb2_streamoff(&vp->vb_queue, type); in s3c_camif_streamoff()
889 struct camif_vp *vp = video_drvdata(file); in s3c_camif_reqbufs() local
892 pr_debug("[vp%d] rb count: %d, owner: %p, priv: %p\n", in s3c_camif_reqbufs()
893 vp->id, rb->count, vp->owner, priv); in s3c_camif_reqbufs()
895 if (vp->owner && vp->owner != priv) in s3c_camif_reqbufs()
901 vp->owner = NULL; in s3c_camif_reqbufs()
903 ret = vb2_reqbufs(&vp->vb_queue, rb); in s3c_camif_reqbufs()
909 vb2_reqbufs(&vp->vb_queue, rb); in s3c_camif_reqbufs()
913 vp->reqbufs_count = rb->count; in s3c_camif_reqbufs()
914 if (vp->owner == NULL && rb->count > 0) in s3c_camif_reqbufs()
915 vp->owner = priv; in s3c_camif_reqbufs()
923 struct camif_vp *vp = video_drvdata(file); in s3c_camif_querybuf() local
924 return vb2_querybuf(&vp->vb_queue, buf); in s3c_camif_querybuf()
930 struct camif_vp *vp = video_drvdata(file); in s3c_camif_qbuf() local
932 pr_debug("[vp%d]\n", vp->id); in s3c_camif_qbuf()
934 if (vp->owner && vp->owner != priv) in s3c_camif_qbuf()
937 return vb2_qbuf(&vp->vb_queue, vp->vdev.v4l2_dev->mdev, buf); in s3c_camif_qbuf()
943 struct camif_vp *vp = video_drvdata(file); in s3c_camif_dqbuf() local
945 pr_debug("[vp%d] sequence: %d\n", vp->id, vp->frame_sequence); in s3c_camif_dqbuf()
947 if (vp->owner && vp->owner != priv) in s3c_camif_dqbuf()
950 return vb2_dqbuf(&vp->vb_queue, buf, file->f_flags & O_NONBLOCK); in s3c_camif_dqbuf()
956 struct camif_vp *vp = video_drvdata(file); in s3c_camif_create_bufs() local
959 if (vp->owner && vp->owner != priv) in s3c_camif_create_bufs()
963 ret = vb2_create_bufs(&vp->vb_queue, create); in s3c_camif_create_bufs()
965 if (!ret && vp->owner == NULL) in s3c_camif_create_bufs()
966 vp->owner = priv; in s3c_camif_create_bufs()
974 struct camif_vp *vp = video_drvdata(file); in s3c_camif_prepare_buf() local
975 return vb2_prepare_buf(&vp->vb_queue, vp->vdev.v4l2_dev->mdev, b); in s3c_camif_prepare_buf()
981 struct camif_vp *vp = video_drvdata(file); in s3c_camif_g_selection() local
991 sel->r.width = vp->out_frame.f_width; in s3c_camif_g_selection()
992 sel->r.height = vp->out_frame.f_height; in s3c_camif_g_selection()
996 sel->r = vp->out_frame.rect; in s3c_camif_g_selection()
1003 static void __camif_try_compose(struct camif_dev *camif, struct camif_vp *vp, in __camif_try_compose() argument
1008 *r = vp->out_frame.rect; in __camif_try_compose()
1018 struct camif_vp *vp = video_drvdata(file); in s3c_camif_s_selection() local
1019 struct camif_dev *camif = vp->camif; in s3c_camif_s_selection()
1027 __camif_try_compose(camif, vp, &rect); in s3c_camif_s_selection()
1031 vp->out_frame.rect = rect; in s3c_camif_s_selection()
1032 vp->state |= ST_VP_CONFIG; in s3c_camif_s_selection()
1071 struct camif_vp *vp = ctrl->priv; in s3c_camif_video_s_ctrl() local
1072 struct camif_dev *camif = vp->camif; in s3c_camif_video_s_ctrl()
1075 pr_debug("[vp%d] ctrl: %s, value: %d\n", vp->id, in s3c_camif_video_s_ctrl()
1082 vp->hflip = ctrl->val; in s3c_camif_video_s_ctrl()
1086 vp->vflip = ctrl->val; in s3c_camif_video_s_ctrl()
1090 vp->state |= ST_VP_CONFIG; in s3c_camif_video_s_ctrl()
1102 struct camif_vp *vp = &camif->vp[idx]; in s3c_camif_register_video_node() local
1103 struct vb2_queue *q = &vp->vb_queue; in s3c_camif_register_video_node()
1104 struct video_device *vfd = &vp->vdev; in s3c_camif_register_video_node()
1110 vp->id == 0 ? "codec" : "preview"); in s3c_camif_register_video_node()
1118 vp->reqbufs_count = 0; in s3c_camif_register_video_node()
1120 INIT_LIST_HEAD(&vp->pending_buf_q); in s3c_camif_register_video_node()
1121 INIT_LIST_HEAD(&vp->active_buf_q); in s3c_camif_register_video_node()
1129 q->drv_priv = vp; in s3c_camif_register_video_node()
1131 q->lock = &vp->camif->lock; in s3c_camif_register_video_node()
1138 vp->pad.flags = MEDIA_PAD_FL_SINK; in s3c_camif_register_video_node()
1139 ret = media_entity_pads_init(&vfd->entity, 1, &vp->pad); in s3c_camif_register_video_node()
1143 video_set_drvdata(vfd, vp); in s3c_camif_register_video_node()
1145 v4l2_ctrl_handler_init(&vp->ctrl_handler, 1); in s3c_camif_register_video_node()
1146 ctrl = v4l2_ctrl_new_std(&vp->ctrl_handler, &s3c_camif_video_ctrl_ops, in s3c_camif_register_video_node()
1149 ctrl->priv = vp; in s3c_camif_register_video_node()
1150 ctrl = v4l2_ctrl_new_std(&vp->ctrl_handler, &s3c_camif_video_ctrl_ops, in s3c_camif_register_video_node()
1153 ctrl->priv = vp; in s3c_camif_register_video_node()
1155 ret = vp->ctrl_handler.error; in s3c_camif_register_video_node()
1159 vfd->ctrl_handler = &vp->ctrl_handler; in s3c_camif_register_video_node()
1171 v4l2_ctrl_handler_free(&vp->ctrl_handler); in s3c_camif_register_video_node()
1179 struct video_device *vfd = &camif->vp[idx].vdev; in s3c_camif_unregister_video_node()
1299 if (vb2_is_busy(&camif->vp[VP_CODEC].vb_queue) || in s3c_camif_subdev_set_fmt()
1300 vb2_is_busy(&camif->vp[VP_PREVIEW].vb_queue)) { in s3c_camif_subdev_set_fmt()
1327 struct camif_frame *frame = &camif->vp[i].out_frame; in s3c_camif_subdev_set_fmt()
1420 struct v4l2_rect *or = &camif->vp[i].out_frame.rect; in __camif_try_crop()
1457 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_subdev_set_selection() local
1458 scaler = vp->scaler; in s3c_camif_subdev_set_selection()
1459 if (s3c_camif_get_scaler_config(vp, &scaler)) in s3c_camif_subdev_set_selection()
1461 vp->scaler = scaler; in s3c_camif_subdev_set_selection()
1462 vp->state |= ST_VP_CONFIG; in s3c_camif_subdev_set_selection()
1522 camif->vp[VP_CODEC].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1523 camif->vp[VP_PREVIEW].state |= ST_VP_CONFIG; in s3c_camif_subdev_s_ctrl()
1612 struct camif_vp *vp = &camif->vp[i]; in s3c_camif_set_defaults() local
1613 struct camif_frame *f = &vp->out_frame; in s3c_camif_set_defaults()
1615 vp->camif = camif; in s3c_camif_set_defaults()
1616 vp->id = i; in s3c_camif_set_defaults()
1617 vp->offset = camif->variant->vp_offset; in s3c_camif_set_defaults()
1620 vp->fmt_flags = i ? FMT_FL_S3C24XX_PREVIEW : in s3c_camif_set_defaults()
1623 vp->fmt_flags = FMT_FL_S3C64XX; in s3c_camif_set_defaults()
1625 vp->out_fmt = s3c_camif_find_format(vp, NULL, 0); in s3c_camif_set_defaults()
1626 BUG_ON(vp->out_fmt == NULL); in s3c_camif_set_defaults()
1635 vp->scaler.enable = 1; in s3c_camif_set_defaults()
1637 vp->payload = (f->f_width * f->f_height * in s3c_camif_set_defaults()
1638 vp->out_fmt->depth) / 8; in s3c_camif_set_defaults()