Lines Matching full:vcap

187 	struct dcmipp_bytecap_device *vcap = video_drvdata(file);  in dcmipp_bytecap_g_fmt_vid_cap()  local
189 f->fmt.pix = vcap->format; in dcmipp_bytecap_g_fmt_vid_cap()
197 struct dcmipp_bytecap_device *vcap = video_drvdata(file); in dcmipp_bytecap_try_fmt_vid_cap() local
215 dev_dbg(vcap->dev, "resolution updated: %dx%d -> %dx%d\n", in dcmipp_bytecap_try_fmt_vid_cap()
237 struct dcmipp_bytecap_device *vcap = video_drvdata(file); in dcmipp_bytecap_s_fmt_vid_cap() local
241 if (vb2_is_busy(&vcap->queue)) in dcmipp_bytecap_s_fmt_vid_cap()
248 …dev_dbg(vcap->dev, "%s: format update: old:%ux%u (0x%p4cc, %u, %u, %u, %u) new:%ux%d (0x%p4cc, %u,… in dcmipp_bytecap_s_fmt_vid_cap()
249 vcap->vdev.name, in dcmipp_bytecap_s_fmt_vid_cap()
251 vcap->format.width, vcap->format.height, in dcmipp_bytecap_s_fmt_vid_cap()
252 &vcap->format.pixelformat, vcap->format.colorspace, in dcmipp_bytecap_s_fmt_vid_cap()
253 vcap->format.quantization, vcap->format.xfer_func, in dcmipp_bytecap_s_fmt_vid_cap()
254 vcap->format.ycbcr_enc, in dcmipp_bytecap_s_fmt_vid_cap()
261 vcap->format = f->fmt.pix; in dcmipp_bytecap_s_fmt_vid_cap()
358 static void dcmipp_start_capture(struct dcmipp_bytecap_device *vcap, in dcmipp_start_capture() argument
362 reg_write(vcap, DCMIPP_P0PPM0AR1, buf->addr); in dcmipp_start_capture()
365 reg_write(vcap, DCMIPP_P0DCLMTR, DCMIPP_P0DCLMTR_ENABLE | in dcmipp_start_capture()
369 reg_set(vcap, DCMIPP_P0FCTCR, DCMIPP_P0FCTCR_CPTREQ); in dcmipp_start_capture()
372 static void dcmipp_bytecap_all_buffers_done(struct dcmipp_bytecap_device *vcap, in dcmipp_bytecap_all_buffers_done() argument
377 list_for_each_entry_safe(buf, node, &vcap->buffers, list) { in dcmipp_bytecap_all_buffers_done()
386 struct dcmipp_bytecap_device *vcap = vb2_get_drv_priv(vq); in dcmipp_bytecap_start_streaming() local
387 struct media_entity *entity = &vcap->vdev.entity; in dcmipp_bytecap_start_streaming()
392 vcap->sequence = 0; in dcmipp_bytecap_start_streaming()
393 memset(&vcap->count, 0, sizeof(vcap->count)); in dcmipp_bytecap_start_streaming()
399 if (!vcap->s_subdev) { in dcmipp_bytecap_start_streaming()
400 pad = media_pad_remote_pad_first(&vcap->vdev.entity.pads[0]); in dcmipp_bytecap_start_streaming()
403 vcap->s_subdev = media_entity_to_v4l2_subdev(pad->entity); in dcmipp_bytecap_start_streaming()
404 vcap->s_subdev_pad_nb = pad->index; in dcmipp_bytecap_start_streaming()
407 ret = pm_runtime_resume_and_get(vcap->dev); in dcmipp_bytecap_start_streaming()
409 dev_err(vcap->dev, "%s: Failed to start streaming, cannot get sync (%d)\n", in dcmipp_bytecap_start_streaming()
414 ret = media_pipeline_start(entity->pads, &vcap->pipe); in dcmipp_bytecap_start_streaming()
416 dev_dbg(vcap->dev, "%s: Failed to start streaming, media pipeline start error (%d)\n", in dcmipp_bytecap_start_streaming()
421 ret = v4l2_subdev_enable_streams(vcap->s_subdev, in dcmipp_bytecap_start_streaming()
422 vcap->s_subdev_pad_nb, BIT_ULL(0)); in dcmipp_bytecap_start_streaming()
426 spin_lock_irq(&vcap->irqlock); in dcmipp_bytecap_start_streaming()
429 reg_set(vcap, DCMIPP_P0FSCR, DCMIPP_P0FSCR_PIPEN); in dcmipp_bytecap_start_streaming()
435 vcap->next = list_first_entry(&vcap->buffers, typeof(*buf), list); in dcmipp_bytecap_start_streaming()
436 dev_dbg(vcap->dev, "Start with next [%d] %p phy=%pad\n", in dcmipp_bytecap_start_streaming()
437 vcap->next->vb.vb2_buf.index, vcap->next, &vcap->next->addr); in dcmipp_bytecap_start_streaming()
439 dcmipp_start_capture(vcap, vcap->next); in dcmipp_bytecap_start_streaming()
442 vcap->cmier |= DCMIPP_CMIER_P0ALL; in dcmipp_bytecap_start_streaming()
443 reg_set(vcap, DCMIPP_CMIER, vcap->cmier); in dcmipp_bytecap_start_streaming()
445 vcap->state = DCMIPP_RUNNING; in dcmipp_bytecap_start_streaming()
447 spin_unlock_irq(&vcap->irqlock); in dcmipp_bytecap_start_streaming()
454 pm_runtime_put(vcap->dev); in dcmipp_bytecap_start_streaming()
456 spin_lock_irq(&vcap->irqlock); in dcmipp_bytecap_start_streaming()
461 dcmipp_bytecap_all_buffers_done(vcap, VB2_BUF_STATE_QUEUED); in dcmipp_bytecap_start_streaming()
462 vcap->active = NULL; in dcmipp_bytecap_start_streaming()
463 spin_unlock_irq(&vcap->irqlock); in dcmipp_bytecap_start_streaming()
468 static void dcmipp_dump_status(struct dcmipp_bytecap_device *vcap) in dcmipp_dump_status() argument
470 struct device *dev = vcap->dev; in dcmipp_dump_status()
472 dev_dbg(dev, "[DCMIPP_PRSR] =%#10.8x\n", reg_read(vcap, DCMIPP_PRSR)); in dcmipp_dump_status()
473 dev_dbg(dev, "[DCMIPP_P0SR] =%#10.8x\n", reg_read(vcap, DCMIPP_P0SR)); in dcmipp_dump_status()
475 reg_read(vcap, DCMIPP_P0DCCNTR)); in dcmipp_dump_status()
476 dev_dbg(dev, "[DCMIPP_CMSR1] =%#10.8x\n", reg_read(vcap, DCMIPP_CMSR1)); in dcmipp_dump_status()
477 dev_dbg(dev, "[DCMIPP_CMSR2] =%#10.8x\n", reg_read(vcap, DCMIPP_CMSR2)); in dcmipp_dump_status()
486 struct dcmipp_bytecap_device *vcap = vb2_get_drv_priv(vq); in dcmipp_bytecap_stop_streaming() local
490 ret = v4l2_subdev_disable_streams(vcap->s_subdev, in dcmipp_bytecap_stop_streaming()
491 vcap->s_subdev_pad_nb, BIT_ULL(0)); in dcmipp_bytecap_stop_streaming()
493 dev_warn(vcap->dev, "Failed to disable stream\n"); in dcmipp_bytecap_stop_streaming()
496 media_pipeline_stop(vcap->vdev.entity.pads); in dcmipp_bytecap_stop_streaming()
499 reg_clear(vcap, DCMIPP_CMIER, vcap->cmier); in dcmipp_bytecap_stop_streaming()
502 reg_clear(vcap, DCMIPP_P0FCTCR, DCMIPP_P0FCTCR_CPTREQ); in dcmipp_bytecap_stop_streaming()
505 ret = readl_relaxed_poll_timeout(vcap->regs + DCMIPP_P0SR, status, in dcmipp_bytecap_stop_streaming()
510 dev_warn(vcap->dev, "Timeout when stopping\n"); in dcmipp_bytecap_stop_streaming()
513 reg_clear(vcap, DCMIPP_P0FSCR, DCMIPP_P0FSCR_PIPEN); in dcmipp_bytecap_stop_streaming()
515 spin_lock_irq(&vcap->irqlock); in dcmipp_bytecap_stop_streaming()
518 dcmipp_bytecap_all_buffers_done(vcap, VB2_BUF_STATE_ERROR); in dcmipp_bytecap_stop_streaming()
519 INIT_LIST_HEAD(&vcap->buffers); in dcmipp_bytecap_stop_streaming()
521 vcap->active = NULL; in dcmipp_bytecap_stop_streaming()
522 vcap->state = DCMIPP_STOPPED; in dcmipp_bytecap_stop_streaming()
524 spin_unlock_irq(&vcap->irqlock); in dcmipp_bytecap_stop_streaming()
526 dcmipp_dump_status(vcap); in dcmipp_bytecap_stop_streaming()
528 pm_runtime_put(vcap->dev); in dcmipp_bytecap_stop_streaming()
530 if (vcap->count.errors) in dcmipp_bytecap_stop_streaming()
531 …dev_warn(vcap->dev, "Some errors found while streaming: errors=%d (overrun=%d, limit=%d, nactive=%… in dcmipp_bytecap_stop_streaming()
532 vcap->count.errors, vcap->count.overrun, in dcmipp_bytecap_stop_streaming()
533 vcap->count.limit, vcap->count.nactive, in dcmipp_bytecap_stop_streaming()
534 vcap->count.underrun, vcap->count.buffers); in dcmipp_bytecap_stop_streaming()
539 struct dcmipp_bytecap_device *vcap = vb2_get_drv_priv(vb->vb2_queue); in dcmipp_bytecap_buf_prepare() local
544 size = vcap->format.sizeimage; in dcmipp_bytecap_buf_prepare()
547 dev_err(vcap->dev, "%s data will not fit into plane (%lu < %lu)\n", in dcmipp_bytecap_buf_prepare()
562 dev_dbg(vcap->dev, "Setup [%d] phy=%pad size=%zu\n", in dcmipp_bytecap_buf_prepare()
571 struct dcmipp_bytecap_device *vcap = in dcmipp_bytecap_buf_queue() local
576 dev_dbg(vcap->dev, "Queue [%d] %p phy=%pad\n", buf->vb.vb2_buf.index, in dcmipp_bytecap_buf_queue()
579 spin_lock_irq(&vcap->irqlock); in dcmipp_bytecap_buf_queue()
580 list_add_tail(&buf->list, &vcap->buffers); in dcmipp_bytecap_buf_queue()
582 if (vcap->state == DCMIPP_WAIT_FOR_BUFFER) { in dcmipp_bytecap_buf_queue()
583 vcap->next = buf; in dcmipp_bytecap_buf_queue()
584 dev_dbg(vcap->dev, "Restart with next [%d] %p phy=%pad\n", in dcmipp_bytecap_buf_queue()
587 dcmipp_start_capture(vcap, buf); in dcmipp_bytecap_buf_queue()
589 vcap->state = DCMIPP_RUNNING; in dcmipp_bytecap_buf_queue()
592 spin_unlock_irq(&vcap->irqlock); in dcmipp_bytecap_buf_queue()
601 struct dcmipp_bytecap_device *vcap = vb2_get_drv_priv(vq); in dcmipp_bytecap_queue_setup() local
604 size = vcap->format.sizeimage; in dcmipp_bytecap_queue_setup()
608 return sizes[0] < vcap->format.sizeimage ? -EINVAL : 0; in dcmipp_bytecap_queue_setup()
611 sizes[0] = vcap->format.sizeimage; in dcmipp_bytecap_queue_setup()
613 dev_dbg(vcap->dev, "Setup queue, count=%d, size=%d\n", in dcmipp_bytecap_queue_setup()
640 struct dcmipp_bytecap_device *vcap = in dcmipp_bytecap_release() local
643 dcmipp_pads_cleanup(vcap->ved.pads); in dcmipp_bytecap_release()
644 mutex_destroy(&vcap->lock); in dcmipp_bytecap_release()
646 kfree(vcap); in dcmipp_bytecap_release()
651 struct dcmipp_bytecap_device *vcap = in dcmipp_bytecap_ent_release() local
655 vb2_video_unregister_device(&vcap->vdev); in dcmipp_bytecap_ent_release()
658 static void dcmipp_buffer_done(struct dcmipp_bytecap_device *vcap, in dcmipp_buffer_done() argument
669 vbuf->sequence = vcap->sequence++; in dcmipp_buffer_done()
675 dev_dbg(vcap->dev, "Done [%d] %p phy=%pad\n", buf->vb.vb2_buf.index, in dcmipp_buffer_done()
677 vcap->count.buffers++; in dcmipp_buffer_done()
682 dcmipp_bytecap_set_next_frame_or_stop(struct dcmipp_bytecap_device *vcap) in dcmipp_bytecap_set_next_frame_or_stop() argument
684 if (!vcap->next && list_is_singular(&vcap->buffers)) { in dcmipp_bytecap_set_next_frame_or_stop()
691 reg_clear(vcap, DCMIPP_P0FCTCR, DCMIPP_P0FCTCR_CPTREQ); in dcmipp_bytecap_set_next_frame_or_stop()
693 dev_dbg(vcap->dev, "Capture restart is deferred to next buffer queueing\n"); in dcmipp_bytecap_set_next_frame_or_stop()
694 vcap->next = NULL; in dcmipp_bytecap_set_next_frame_or_stop()
695 vcap->state = DCMIPP_WAIT_FOR_BUFFER; in dcmipp_bytecap_set_next_frame_or_stop()
700 if (!vcap->next) in dcmipp_bytecap_set_next_frame_or_stop()
701 vcap->next = list_next_entry(vcap->active, list); in dcmipp_bytecap_set_next_frame_or_stop()
708 reg_write(vcap, DCMIPP_P0PPM0AR1, vcap->next->addr); in dcmipp_bytecap_set_next_frame_or_stop()
709 dev_dbg(vcap->dev, "Write [%d] %p phy=%pad\n", in dcmipp_bytecap_set_next_frame_or_stop()
710 vcap->next->vb.vb2_buf.index, vcap->next, &vcap->next->addr); in dcmipp_bytecap_set_next_frame_or_stop()
714 static void dcmipp_bytecap_process_frame(struct dcmipp_bytecap_device *vcap, in dcmipp_bytecap_process_frame() argument
718 struct dcmipp_buf *buf = vcap->active; in dcmipp_bytecap_process_frame()
721 vcap->count.nactive++; in dcmipp_bytecap_process_frame()
722 vcap->count.errors++; in dcmipp_bytecap_process_frame()
727 dev_dbg(vcap->dev, "frame larger than expected (%zu > %zu)\n", in dcmipp_bytecap_process_frame()
731 vcap->count.limit++; in dcmipp_bytecap_process_frame()
732 vcap->count.errors++; in dcmipp_bytecap_process_frame()
736 dcmipp_buffer_done(vcap, buf, bytesused, err); in dcmipp_bytecap_process_frame()
737 vcap->active = NULL; in dcmipp_bytecap_process_frame()
742 struct dcmipp_bytecap_device *vcap = in dcmipp_bytecap_irq_thread() local
747 spin_lock_irq(&vcap->irqlock); in dcmipp_bytecap_irq_thread()
749 cmsr2 = vcap->cmsr2 & vcap->cmier; in dcmipp_bytecap_irq_thread()
757 vcap->count.errors++; in dcmipp_bytecap_irq_thread()
758 vcap->count.overrun++; in dcmipp_bytecap_irq_thread()
762 vcap->count.frame++; in dcmipp_bytecap_irq_thread()
765 bytesused = reg_read(vcap, DCMIPP_P0DCCNTR); in dcmipp_bytecap_irq_thread()
766 dcmipp_bytecap_process_frame(vcap, bytesused); in dcmipp_bytecap_irq_thread()
770 vcap->count.vsync++; in dcmipp_bytecap_irq_thread()
771 if (vcap->state == DCMIPP_WAIT_FOR_BUFFER) { in dcmipp_bytecap_irq_thread()
772 vcap->count.underrun++; in dcmipp_bytecap_irq_thread()
785 swap(vcap->active, vcap->next); in dcmipp_bytecap_irq_thread()
786 dcmipp_bytecap_set_next_frame_or_stop(vcap); in dcmipp_bytecap_irq_thread()
790 spin_unlock_irq(&vcap->irqlock); in dcmipp_bytecap_irq_thread()
796 struct dcmipp_bytecap_device *vcap = in dcmipp_bytecap_irq_callback() local
800 vcap->cmsr2 = reg_read(vcap, DCMIPP_CMSR2) & vcap->cmier; in dcmipp_bytecap_irq_callback()
801 vcap->count.it++; in dcmipp_bytecap_irq_callback()
804 reg_write(vcap, DCMIPP_CMFCR, vcap->cmsr2); in dcmipp_bytecap_irq_callback()
813 struct dcmipp_bytecap_device *vcap = container_of(vd, in dcmipp_bytecap_link_validate() local
827 if (source_fmt.format.width != vcap->format.width || in dcmipp_bytecap_link_validate()
828 source_fmt.format.height != vcap->format.height) { in dcmipp_bytecap_link_validate()
829 dev_err(vcap->dev, "Wrong width or height %ux%u (%ux%u expected)\n", in dcmipp_bytecap_link_validate()
830 vcap->format.width, vcap->format.height, in dcmipp_bytecap_link_validate()
837 vcap->format.pixelformat && in dcmipp_bytecap_link_validate()
844 dev_err(vcap->dev, "mbus code 0x%x do not match capture device format (0x%x)\n", in dcmipp_bytecap_link_validate()
845 vcap->format.pixelformat, source_fmt.format.code); in dcmipp_bytecap_link_validate()
861 struct dcmipp_bytecap_device *vcap; in dcmipp_bytecap_ent_init() local
868 vcap = kzalloc(sizeof(*vcap), GFP_KERNEL); in dcmipp_bytecap_ent_init()
869 if (!vcap) in dcmipp_bytecap_ent_init()
873 vcap->ved.pads = dcmipp_pads_init(1, &pad_flag); in dcmipp_bytecap_ent_init()
874 if (IS_ERR(vcap->ved.pads)) { in dcmipp_bytecap_ent_init()
875 ret = PTR_ERR(vcap->ved.pads); in dcmipp_bytecap_ent_init()
880 vcap->vdev.entity.name = entity_name; in dcmipp_bytecap_ent_init()
881 vcap->vdev.entity.function = MEDIA_ENT_F_IO_V4L; in dcmipp_bytecap_ent_init()
882 vcap->vdev.entity.ops = &dcmipp_bytecap_entity_ops; in dcmipp_bytecap_ent_init()
883 ret = media_entity_pads_init(&vcap->vdev.entity, 1, vcap->ved.pads); in dcmipp_bytecap_ent_init()
888 mutex_init(&vcap->lock); in dcmipp_bytecap_ent_init()
891 q = &vcap->queue; in dcmipp_bytecap_ent_init()
894 q->lock = &vcap->lock; in dcmipp_bytecap_ent_init()
895 q->drv_priv = vcap; in dcmipp_bytecap_ent_init()
918 INIT_LIST_HEAD(&vcap->buffers); in dcmipp_bytecap_ent_init()
919 spin_lock_init(&vcap->irqlock); in dcmipp_bytecap_ent_init()
922 vcap->format = fmt_default; in dcmipp_bytecap_ent_init()
925 vcap->ved.ent = &vcap->vdev.entity; in dcmipp_bytecap_ent_init()
926 vcap->ved.handler = dcmipp_bytecap_irq_callback; in dcmipp_bytecap_ent_init()
927 vcap->ved.thread_fn = dcmipp_bytecap_irq_thread; in dcmipp_bytecap_ent_init()
928 vcap->dev = dev; in dcmipp_bytecap_ent_init()
929 vcap->regs = regs; in dcmipp_bytecap_ent_init()
932 vdev = &vcap->vdev; in dcmipp_bytecap_ent_init()
938 vdev->lock = &vcap->lock; in dcmipp_bytecap_ent_init()
942 video_set_drvdata(vdev, &vcap->ved); in dcmipp_bytecap_ent_init()
948 vcap->vdev.name, ret); in dcmipp_bytecap_ent_init()
952 return &vcap->ved; in dcmipp_bytecap_ent_init()
955 media_entity_cleanup(&vcap->vdev.entity); in dcmipp_bytecap_ent_init()
957 mutex_destroy(&vcap->lock); in dcmipp_bytecap_ent_init()
959 dcmipp_pads_cleanup(vcap->ved.pads); in dcmipp_bytecap_ent_init()
961 kfree(vcap); in dcmipp_bytecap_ent_init()