Lines Matching full:csi
58 u32 csi_dt; /* CSI Data type. */
67 struct ti_csi2rx_dev *csi; member
215 static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi,
305 struct ti_csi2rx_dev *csi = video_drvdata(file); in ti_csi2rx_g_fmt_vid_cap() local
307 *f = csi->v_fmt; in ti_csi2rx_g_fmt_vid_cap()
336 struct ti_csi2rx_dev *csi = video_drvdata(file); in ti_csi2rx_s_fmt_vid_cap() local
337 struct vb2_queue *q = &csi->vidq; in ti_csi2rx_s_fmt_vid_cap()
347 csi->v_fmt = *f; in ti_csi2rx_s_fmt_vid_cap()
412 struct ti_csi2rx_dev *csi = dev_get_drvdata(notifier->v4l2_dev->dev); in csi_async_notifier_bound() local
414 csi->source = subdev; in csi_async_notifier_bound()
421 struct ti_csi2rx_dev *csi = dev_get_drvdata(notifier->v4l2_dev->dev); in csi_async_notifier_complete() local
422 struct video_device *vdev = &csi->vdev; in csi_async_notifier_complete()
429 ret = v4l2_create_fwnode_links_to_pad(csi->source, &csi->pad, in csi_async_notifier_complete()
437 ret = v4l2_device_register_subdev_nodes(&csi->v4l2_dev); in csi_async_notifier_complete()
449 static int ti_csi2rx_notifier_register(struct ti_csi2rx_dev *csi) in ti_csi2rx_notifier_register() argument
456 node = of_get_child_by_name(csi->dev->of_node, "csi-bridge"); in ti_csi2rx_notifier_register()
466 v4l2_async_nf_init(&csi->notifier, &csi->v4l2_dev); in ti_csi2rx_notifier_register()
467 csi->notifier.ops = &csi_async_notifier_ops; in ti_csi2rx_notifier_register()
469 asc = v4l2_async_nf_add_fwnode(&csi->notifier, fwnode, in ti_csi2rx_notifier_register()
473 v4l2_async_nf_cleanup(&csi->notifier); in ti_csi2rx_notifier_register()
477 ret = v4l2_async_nf_register(&csi->notifier); in ti_csi2rx_notifier_register()
479 v4l2_async_nf_cleanup(&csi->notifier); in ti_csi2rx_notifier_register()
486 static void ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi) in ti_csi2rx_setup_shim() argument
491 fmt = find_format_by_fourcc(csi->v_fmt.fmt.pix.pixelformat); in ti_csi2rx_setup_shim()
495 writel(reg, csi->shim + SHIM_CNTL); in ti_csi2rx_setup_shim()
533 writel(reg, csi->shim + SHIM_DMACNTX); in ti_csi2rx_setup_shim()
537 writel(reg, csi->shim + SHIM_PSI_CFG0); in ti_csi2rx_setup_shim()
558 static int ti_csi2rx_drain_dma(struct ti_csi2rx_dev *csi) in ti_csi2rx_drain_dma() argument
567 desc = dmaengine_prep_slave_single(csi->dma.chan, csi->dma.drain.paddr, in ti_csi2rx_drain_dma()
568 csi->dma.drain.len, DMA_DEV_TO_MEM, in ti_csi2rx_drain_dma()
583 dma_async_issue_pending(csi->dma.chan); in ti_csi2rx_drain_dma()
587 dmaengine_terminate_sync(csi->dma.chan); in ti_csi2rx_drain_dma()
588 dev_dbg(csi->dev, "DMA transfer timed out for drain buffer\n"); in ti_csi2rx_drain_dma()
599 struct ti_csi2rx_dev *csi = buf->csi; in ti_csi2rx_dma_callback() local
600 struct ti_csi2rx_dma *dma = &csi->dma; in ti_csi2rx_dma_callback()
608 buf->vb.sequence = csi->sequence++; in ti_csi2rx_dma_callback()
620 if (ti_csi2rx_start_dma(csi, buf)) { in ti_csi2rx_dma_callback()
621 dev_err(csi->dev, "Failed to queue the next buffer for DMA\n"); in ti_csi2rx_dma_callback()
634 static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi, in ti_csi2rx_start_dma() argument
639 size_t len = csi->v_fmt.fmt.pix.sizeimage; in ti_csi2rx_start_dma()
644 desc = dmaengine_prep_slave_single(csi->dma.chan, addr, len, in ti_csi2rx_start_dma()
658 dma_async_issue_pending(csi->dma.chan); in ti_csi2rx_start_dma()
663 static void ti_csi2rx_stop_dma(struct ti_csi2rx_dev *csi) in ti_csi2rx_stop_dma() argument
665 struct ti_csi2rx_dma *dma = &csi->dma; in ti_csi2rx_stop_dma()
671 state = csi->dma.state; in ti_csi2rx_stop_dma()
682 ret = ti_csi2rx_drain_dma(csi); in ti_csi2rx_stop_dma()
684 dev_warn(csi->dev, in ti_csi2rx_stop_dma()
688 ret = dmaengine_terminate_sync(csi->dma.chan); in ti_csi2rx_stop_dma()
690 dev_err(csi->dev, "Failed to stop DMA: %d\n", ret); in ti_csi2rx_stop_dma()
693 static void ti_csi2rx_cleanup_buffers(struct ti_csi2rx_dev *csi, in ti_csi2rx_cleanup_buffers() argument
696 struct ti_csi2rx_dma *dma = &csi->dma; in ti_csi2rx_cleanup_buffers()
701 list_for_each_entry_safe(buf, tmp, &csi->dma.queue, list) { in ti_csi2rx_cleanup_buffers()
705 list_for_each_entry_safe(buf, tmp, &csi->dma.submitted, list) { in ti_csi2rx_cleanup_buffers()
716 struct ti_csi2rx_dev *csi = vb2_get_drv_priv(q); in ti_csi2rx_queue_setup() local
717 unsigned int size = csi->v_fmt.fmt.pix.sizeimage; in ti_csi2rx_queue_setup()
733 struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue); in ti_csi2rx_buffer_prepare() local
734 unsigned long size = csi->v_fmt.fmt.pix.sizeimage; in ti_csi2rx_buffer_prepare()
737 dev_err(csi->dev, "Data will not fit into plane\n"); in ti_csi2rx_buffer_prepare()
747 struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue); in ti_csi2rx_buffer_queue() local
749 struct ti_csi2rx_dma *dma = &csi->dma; in ti_csi2rx_buffer_queue()
755 buf->csi = csi; in ti_csi2rx_buffer_queue()
784 ret = ti_csi2rx_drain_dma(csi); in ti_csi2rx_buffer_queue()
786 dev_warn(csi->dev, in ti_csi2rx_buffer_queue()
790 ret = ti_csi2rx_start_dma(csi, buf); in ti_csi2rx_buffer_queue()
795 dev_err(csi->dev, "Failed to start DMA: %d\n", ret); in ti_csi2rx_buffer_queue()
805 struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vq); in ti_csi2rx_start_streaming() local
806 struct ti_csi2rx_dma *dma = &csi->dma; in ti_csi2rx_start_streaming()
818 ret = video_device_pipeline_start(&csi->vdev, &csi->pipe); in ti_csi2rx_start_streaming()
822 ti_csi2rx_setup_shim(csi); in ti_csi2rx_start_streaming()
824 csi->sequence = 0; in ti_csi2rx_start_streaming()
829 ret = ti_csi2rx_start_dma(csi, buf); in ti_csi2rx_start_streaming()
831 dev_err(csi->dev, "Failed to start DMA: %d\n", ret); in ti_csi2rx_start_streaming()
840 ret = v4l2_subdev_call(csi->source, video, s_stream, 1); in ti_csi2rx_start_streaming()
847 ti_csi2rx_stop_dma(csi); in ti_csi2rx_start_streaming()
849 video_device_pipeline_stop(&csi->vdev); in ti_csi2rx_start_streaming()
850 writel(0, csi->shim + SHIM_CNTL); in ti_csi2rx_start_streaming()
851 writel(0, csi->shim + SHIM_DMACNTX); in ti_csi2rx_start_streaming()
853 ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_QUEUED); in ti_csi2rx_start_streaming()
859 struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vq); in ti_csi2rx_stop_streaming() local
862 video_device_pipeline_stop(&csi->vdev); in ti_csi2rx_stop_streaming()
864 writel(0, csi->shim + SHIM_CNTL); in ti_csi2rx_stop_streaming()
865 writel(0, csi->shim + SHIM_DMACNTX); in ti_csi2rx_stop_streaming()
867 ret = v4l2_subdev_call(csi->source, video, s_stream, 0); in ti_csi2rx_stop_streaming()
869 dev_err(csi->dev, "Failed to stop subdev stream\n"); in ti_csi2rx_stop_streaming()
871 ti_csi2rx_stop_dma(csi); in ti_csi2rx_stop_streaming()
872 ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_ERROR); in ti_csi2rx_stop_streaming()
885 static int ti_csi2rx_init_vb2q(struct ti_csi2rx_dev *csi) in ti_csi2rx_init_vb2q() argument
887 struct vb2_queue *q = &csi->vidq; in ti_csi2rx_init_vb2q()
892 q->drv_priv = csi; in ti_csi2rx_init_vb2q()
897 q->dev = dmaengine_get_dma_device(csi->dma.chan); in ti_csi2rx_init_vb2q()
898 q->lock = &csi->mutex; in ti_csi2rx_init_vb2q()
905 csi->vdev.queue = q; in ti_csi2rx_init_vb2q()
914 struct ti_csi2rx_dev *csi = container_of(vdev, struct ti_csi2rx_dev, vdev); in ti_csi2rx_link_validate() local
915 struct v4l2_pix_format *csi_fmt = &csi->v_fmt.fmt.pix; in ti_csi2rx_link_validate()
923 ret = v4l2_subdev_call_state_active(csi->source, pad, in ti_csi2rx_link_validate()
929 dev_dbg(csi->dev, "Width does not match (source %u, sink %u)\n", in ti_csi2rx_link_validate()
935 dev_dbg(csi->dev, "Height does not match (source %u, sink %u)\n", in ti_csi2rx_link_validate()
942 dev_dbg(csi->dev, "Field does not match (source %u, sink %u)\n", in ti_csi2rx_link_validate()
949 dev_dbg(csi->dev, "Media bus format 0x%x not supported\n", in ti_csi2rx_link_validate()
955 dev_dbg(csi->dev, in ti_csi2rx_link_validate()
968 static int ti_csi2rx_init_dma(struct ti_csi2rx_dev *csi) in ti_csi2rx_init_dma() argument
975 INIT_LIST_HEAD(&csi->dma.queue); in ti_csi2rx_init_dma()
976 INIT_LIST_HEAD(&csi->dma.submitted); in ti_csi2rx_init_dma()
977 spin_lock_init(&csi->dma.lock); in ti_csi2rx_init_dma()
979 csi->dma.state = TI_CSI2RX_DMA_STOPPED; in ti_csi2rx_init_dma()
981 csi->dma.chan = dma_request_chan(csi->dev, "rx0"); in ti_csi2rx_init_dma()
982 if (IS_ERR(csi->dma.chan)) in ti_csi2rx_init_dma()
983 return PTR_ERR(csi->dma.chan); in ti_csi2rx_init_dma()
985 ret = dmaengine_slave_config(csi->dma.chan, &cfg); in ti_csi2rx_init_dma()
987 dma_release_channel(csi->dma.chan); in ti_csi2rx_init_dma()
991 csi->dma.drain.len = DRAIN_BUFFER_SIZE; in ti_csi2rx_init_dma()
992 csi->dma.drain.vaddr = dma_alloc_coherent(csi->dev, csi->dma.drain.len, in ti_csi2rx_init_dma()
993 &csi->dma.drain.paddr, in ti_csi2rx_init_dma()
995 if (!csi->dma.drain.vaddr) in ti_csi2rx_init_dma()
1001 static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi) in ti_csi2rx_v4l2_init() argument
1003 struct media_device *mdev = &csi->mdev; in ti_csi2rx_v4l2_init()
1004 struct video_device *vdev = &csi->vdev; in ti_csi2rx_v4l2_init()
1006 struct v4l2_pix_format *pix_fmt = &csi->v_fmt.fmt.pix; in ti_csi2rx_v4l2_init()
1021 ti_csi2rx_fill_fmt(fmt, &csi->v_fmt); in ti_csi2rx_v4l2_init()
1023 mdev->dev = csi->dev; in ti_csi2rx_v4l2_init()
1030 vdev->v4l2_dev = &csi->v4l2_dev; in ti_csi2rx_v4l2_init()
1037 vdev->lock = &csi->mutex; in ti_csi2rx_v4l2_init()
1038 video_set_drvdata(vdev, csi); in ti_csi2rx_v4l2_init()
1040 csi->pad.flags = MEDIA_PAD_FL_SINK; in ti_csi2rx_v4l2_init()
1042 ret = media_entity_pads_init(&csi->vdev.entity, 1, &csi->pad); in ti_csi2rx_v4l2_init()
1046 csi->v4l2_dev.mdev = mdev; in ti_csi2rx_v4l2_init()
1048 ret = v4l2_device_register(csi->dev, &csi->v4l2_dev); in ti_csi2rx_v4l2_init()
1054 v4l2_device_unregister(&csi->v4l2_dev); in ti_csi2rx_v4l2_init()
1062 static void ti_csi2rx_cleanup_dma(struct ti_csi2rx_dev *csi) in ti_csi2rx_cleanup_dma() argument
1064 dma_free_coherent(csi->dev, csi->dma.drain.len, in ti_csi2rx_cleanup_dma()
1065 csi->dma.drain.vaddr, csi->dma.drain.paddr); in ti_csi2rx_cleanup_dma()
1066 csi->dma.drain.vaddr = NULL; in ti_csi2rx_cleanup_dma()
1067 dma_release_channel(csi->dma.chan); in ti_csi2rx_cleanup_dma()
1070 static void ti_csi2rx_cleanup_v4l2(struct ti_csi2rx_dev *csi) in ti_csi2rx_cleanup_v4l2() argument
1072 media_device_unregister(&csi->mdev); in ti_csi2rx_cleanup_v4l2()
1073 v4l2_device_unregister(&csi->v4l2_dev); in ti_csi2rx_cleanup_v4l2()
1074 media_device_cleanup(&csi->mdev); in ti_csi2rx_cleanup_v4l2()
1077 static void ti_csi2rx_cleanup_subdev(struct ti_csi2rx_dev *csi) in ti_csi2rx_cleanup_subdev() argument
1079 v4l2_async_nf_unregister(&csi->notifier); in ti_csi2rx_cleanup_subdev()
1080 v4l2_async_nf_cleanup(&csi->notifier); in ti_csi2rx_cleanup_subdev()
1083 static void ti_csi2rx_cleanup_vb2q(struct ti_csi2rx_dev *csi) in ti_csi2rx_cleanup_vb2q() argument
1085 vb2_queue_release(&csi->vidq); in ti_csi2rx_cleanup_vb2q()
1090 struct ti_csi2rx_dev *csi; in ti_csi2rx_probe() local
1093 csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); in ti_csi2rx_probe()
1094 if (!csi) in ti_csi2rx_probe()
1097 csi->dev = &pdev->dev; in ti_csi2rx_probe()
1098 platform_set_drvdata(pdev, csi); in ti_csi2rx_probe()
1100 mutex_init(&csi->mutex); in ti_csi2rx_probe()
1101 csi->shim = devm_platform_ioremap_resource(pdev, 0); in ti_csi2rx_probe()
1102 if (IS_ERR(csi->shim)) { in ti_csi2rx_probe()
1103 ret = PTR_ERR(csi->shim); in ti_csi2rx_probe()
1107 ret = ti_csi2rx_init_dma(csi); in ti_csi2rx_probe()
1111 ret = ti_csi2rx_v4l2_init(csi); in ti_csi2rx_probe()
1115 ret = ti_csi2rx_init_vb2q(csi); in ti_csi2rx_probe()
1119 ret = ti_csi2rx_notifier_register(csi); in ti_csi2rx_probe()
1123 ret = of_platform_populate(csi->dev->of_node, NULL, NULL, csi->dev); in ti_csi2rx_probe()
1125 dev_err(csi->dev, "Failed to create children: %d\n", ret); in ti_csi2rx_probe()
1132 ti_csi2rx_cleanup_subdev(csi); in ti_csi2rx_probe()
1134 ti_csi2rx_cleanup_vb2q(csi); in ti_csi2rx_probe()
1136 ti_csi2rx_cleanup_v4l2(csi); in ti_csi2rx_probe()
1138 ti_csi2rx_cleanup_dma(csi); in ti_csi2rx_probe()
1140 mutex_destroy(&csi->mutex); in ti_csi2rx_probe()
1146 struct ti_csi2rx_dev *csi = platform_get_drvdata(pdev); in ti_csi2rx_remove() local
1148 video_unregister_device(&csi->vdev); in ti_csi2rx_remove()
1150 ti_csi2rx_cleanup_vb2q(csi); in ti_csi2rx_remove()
1151 ti_csi2rx_cleanup_subdev(csi); in ti_csi2rx_remove()
1152 ti_csi2rx_cleanup_v4l2(csi); in ti_csi2rx_remove()
1153 ti_csi2rx_cleanup_dma(csi); in ti_csi2rx_remove()
1155 mutex_destroy(&csi->mutex); in ti_csi2rx_remove()