Lines Matching refs:dma
58 static int xvip_dma_verify_format(struct xvip_dma *dma) in xvip_dma_verify_format() argument
64 subdev = xvip_dma_remote_subdev(&dma->pad, &fmt.pad); in xvip_dma_verify_format()
73 if (dma->fmtinfo->code != fmt.format.code || in xvip_dma_verify_format()
74 dma->format.height != fmt.format.height || in xvip_dma_verify_format()
75 dma->format.width != fmt.format.width || in xvip_dma_verify_format()
76 dma->format.colorspace != fmt.format.colorspace) in xvip_dma_verify_format()
99 struct xvip_dma *dma = pipe->output; in xvip_pipeline_start_stop() local
105 entity = &dma->video.entity; in xvip_pipeline_start_stop()
196 struct xvip_dma *dma; in xvip_pipeline_validate() local
201 dma = to_xvip_dma(media_entity_to_video_device(entity)); in xvip_pipeline_validate()
203 if (dma->pad.flags & MEDIA_PAD_FL_SINK) { in xvip_pipeline_validate()
204 pipe->output = dma; in xvip_pipeline_validate()
258 struct xvip_dma *dma) in xvip_pipeline_prepare() argument
266 ret = xvip_pipeline_validate(pipe, dma); in xvip_pipeline_prepare()
294 struct xvip_dma *dma; member
302 struct xvip_dma *dma = buf->dma; in xvip_dma_complete() local
304 spin_lock(&dma->queued_lock); in xvip_dma_complete()
306 spin_unlock(&dma->queued_lock); in xvip_dma_complete()
309 buf->buf.sequence = dma->sequence++; in xvip_dma_complete()
311 vb2_set_plane_payload(&buf->buf.vb2_buf, 0, dma->format.sizeimage); in xvip_dma_complete()
320 struct xvip_dma *dma = vb2_get_drv_priv(vq); in xvip_dma_queue_setup() local
324 return sizes[0] < dma->format.sizeimage ? -EINVAL : 0; in xvip_dma_queue_setup()
327 sizes[0] = dma->format.sizeimage; in xvip_dma_queue_setup()
335 struct xvip_dma *dma = vb2_get_drv_priv(vb->vb2_queue); in xvip_dma_buffer_prepare() local
338 buf->dma = dma; in xvip_dma_buffer_prepare()
346 struct xvip_dma *dma = vb2_get_drv_priv(vb->vb2_queue); in xvip_dma_buffer_queue() local
352 if (dma->queue.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { in xvip_dma_buffer_queue()
354 dma->xt.dir = DMA_DEV_TO_MEM; in xvip_dma_buffer_queue()
355 dma->xt.src_sgl = false; in xvip_dma_buffer_queue()
356 dma->xt.dst_sgl = true; in xvip_dma_buffer_queue()
357 dma->xt.dst_start = addr; in xvip_dma_buffer_queue()
360 dma->xt.dir = DMA_MEM_TO_DEV; in xvip_dma_buffer_queue()
361 dma->xt.src_sgl = true; in xvip_dma_buffer_queue()
362 dma->xt.dst_sgl = false; in xvip_dma_buffer_queue()
363 dma->xt.src_start = addr; in xvip_dma_buffer_queue()
366 dma->xt.frame_size = 1; in xvip_dma_buffer_queue()
367 dma->sgl[0].size = dma->format.width * dma->fmtinfo->bpp; in xvip_dma_buffer_queue()
368 dma->sgl[0].icg = dma->format.bytesperline - dma->sgl[0].size; in xvip_dma_buffer_queue()
369 dma->xt.numf = dma->format.height; in xvip_dma_buffer_queue()
371 desc = dmaengine_prep_interleaved_dma(dma->dma, &dma->xt, flags); in xvip_dma_buffer_queue()
373 dev_err(dma->xdev->dev, "Failed to prepare DMA transfer\n"); in xvip_dma_buffer_queue()
380 spin_lock_irq(&dma->queued_lock); in xvip_dma_buffer_queue()
381 list_add_tail(&buf->queue, &dma->queued_bufs); in xvip_dma_buffer_queue()
382 spin_unlock_irq(&dma->queued_lock); in xvip_dma_buffer_queue()
386 if (vb2_is_streaming(&dma->queue)) in xvip_dma_buffer_queue()
387 dma_async_issue_pending(dma->dma); in xvip_dma_buffer_queue()
392 struct xvip_dma *dma = vb2_get_drv_priv(vq); in xvip_dma_start_streaming() local
397 dma->sequence = 0; in xvip_dma_start_streaming()
406 pipe = dma->video.entity.pipe in xvip_dma_start_streaming()
407 ? to_xvip_pipeline(&dma->video.entity) : &dma->pipe; in xvip_dma_start_streaming()
409 ret = media_pipeline_start(&dma->video.entity, &pipe->pipe); in xvip_dma_start_streaming()
416 ret = xvip_dma_verify_format(dma); in xvip_dma_start_streaming()
420 ret = xvip_pipeline_prepare(pipe, dma); in xvip_dma_start_streaming()
427 dma_async_issue_pending(dma->dma); in xvip_dma_start_streaming()
435 media_pipeline_stop(&dma->video.entity); in xvip_dma_start_streaming()
439 spin_lock_irq(&dma->queued_lock); in xvip_dma_start_streaming()
440 list_for_each_entry_safe(buf, nbuf, &dma->queued_bufs, queue) { in xvip_dma_start_streaming()
444 spin_unlock_irq(&dma->queued_lock); in xvip_dma_start_streaming()
451 struct xvip_dma *dma = vb2_get_drv_priv(vq); in xvip_dma_stop_streaming() local
452 struct xvip_pipeline *pipe = to_xvip_pipeline(&dma->video.entity); in xvip_dma_stop_streaming()
459 dmaengine_terminate_all(dma->dma); in xvip_dma_stop_streaming()
463 media_pipeline_stop(&dma->video.entity); in xvip_dma_stop_streaming()
466 spin_lock_irq(&dma->queued_lock); in xvip_dma_stop_streaming()
467 list_for_each_entry_safe(buf, nbuf, &dma->queued_bufs, queue) { in xvip_dma_stop_streaming()
471 spin_unlock_irq(&dma->queued_lock); in xvip_dma_stop_streaming()
492 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); in xvip_dma_querycap() local
494 cap->capabilities = dma->xdev->v4l2_caps | V4L2_CAP_STREAMING | in xvip_dma_querycap()
498 strscpy(cap->card, dma->video.name, sizeof(cap->card)); in xvip_dma_querycap()
500 dma->xdev->dev->of_node, dma->port); in xvip_dma_querycap()
514 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); in xvip_dma_enum_format() local
519 f->pixelformat = dma->format.pixelformat; in xvip_dma_enum_format()
528 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); in xvip_dma_get_format() local
530 format->fmt.pix = dma->format; in xvip_dma_get_format()
536 __xvip_dma_try_format(struct xvip_dma *dma, struct v4l2_pix_format *pix, in __xvip_dma_try_format() argument
562 align = lcm(dma->align, info->bpp); in __xvip_dma_try_format()
576 max_bpl = rounddown(XVIP_DMA_MAX_WIDTH, dma->align); in __xvip_dma_try_format()
577 bpl = rounddown(pix->bytesperline, dma->align); in __xvip_dma_try_format()
590 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); in xvip_dma_try_format() local
592 __xvip_dma_try_format(dma, &format->fmt.pix, NULL); in xvip_dma_try_format()
600 struct xvip_dma *dma = to_xvip_dma(vfh->vdev); in xvip_dma_set_format() local
603 __xvip_dma_try_format(dma, &format->fmt.pix, &info); in xvip_dma_set_format()
605 if (vb2_is_busy(&dma->queue)) in xvip_dma_set_format()
608 dma->format = format->fmt.pix; in xvip_dma_set_format()
609 dma->fmtinfo = info; in xvip_dma_set_format()
650 int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma, in xvip_dma_init() argument
656 dma->xdev = xdev; in xvip_dma_init()
657 dma->port = port; in xvip_dma_init()
658 mutex_init(&dma->lock); in xvip_dma_init()
659 mutex_init(&dma->pipe.lock); in xvip_dma_init()
660 INIT_LIST_HEAD(&dma->queued_bufs); in xvip_dma_init()
661 spin_lock_init(&dma->queued_lock); in xvip_dma_init()
663 dma->fmtinfo = xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT); in xvip_dma_init()
664 dma->format.pixelformat = dma->fmtinfo->fourcc; in xvip_dma_init()
665 dma->format.colorspace = V4L2_COLORSPACE_SRGB; in xvip_dma_init()
666 dma->format.field = V4L2_FIELD_NONE; in xvip_dma_init()
667 dma->format.width = XVIP_DMA_DEF_WIDTH; in xvip_dma_init()
668 dma->format.height = XVIP_DMA_DEF_HEIGHT; in xvip_dma_init()
669 dma->format.bytesperline = dma->format.width * dma->fmtinfo->bpp; in xvip_dma_init()
670 dma->format.sizeimage = dma->format.bytesperline * dma->format.height; in xvip_dma_init()
673 dma->pad.flags = type == V4L2_BUF_TYPE_VIDEO_CAPTURE in xvip_dma_init()
676 ret = media_entity_pads_init(&dma->video.entity, 1, &dma->pad); in xvip_dma_init()
681 dma->video.fops = &xvip_dma_fops; in xvip_dma_init()
682 dma->video.v4l2_dev = &xdev->v4l2_dev; in xvip_dma_init()
683 dma->video.queue = &dma->queue; in xvip_dma_init()
684 snprintf(dma->video.name, sizeof(dma->video.name), "%pOFn %s %u", in xvip_dma_init()
688 dma->video.vfl_type = VFL_TYPE_VIDEO; in xvip_dma_init()
689 dma->video.vfl_dir = type == V4L2_BUF_TYPE_VIDEO_CAPTURE in xvip_dma_init()
691 dma->video.release = video_device_release_empty; in xvip_dma_init()
692 dma->video.ioctl_ops = &xvip_dma_ioctl_ops; in xvip_dma_init()
693 dma->video.lock = &dma->lock; in xvip_dma_init()
694 dma->video.device_caps = V4L2_CAP_STREAMING; in xvip_dma_init()
696 dma->video.device_caps |= V4L2_CAP_VIDEO_CAPTURE; in xvip_dma_init()
698 dma->video.device_caps |= V4L2_CAP_VIDEO_OUTPUT; in xvip_dma_init()
700 video_set_drvdata(&dma->video, dma); in xvip_dma_init()
710 dma->queue.type = type; in xvip_dma_init()
711 dma->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; in xvip_dma_init()
712 dma->queue.lock = &dma->lock; in xvip_dma_init()
713 dma->queue.drv_priv = dma; in xvip_dma_init()
714 dma->queue.buf_struct_size = sizeof(struct xvip_dma_buffer); in xvip_dma_init()
715 dma->queue.ops = &xvip_dma_queue_qops; in xvip_dma_init()
716 dma->queue.mem_ops = &vb2_dma_contig_memops; in xvip_dma_init()
717 dma->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC in xvip_dma_init()
719 dma->queue.dev = dma->xdev->dev; in xvip_dma_init()
720 ret = vb2_queue_init(&dma->queue); in xvip_dma_init()
722 dev_err(dma->xdev->dev, "failed to initialize VB2 queue\n"); in xvip_dma_init()
728 dma->dma = dma_request_chan(dma->xdev->dev, name); in xvip_dma_init()
729 if (IS_ERR(dma->dma)) { in xvip_dma_init()
730 ret = PTR_ERR(dma->dma); in xvip_dma_init()
732 dev_err(dma->xdev->dev, "no VDMA channel found\n"); in xvip_dma_init()
736 dma->align = 1 << dma->dma->device->copy_align; in xvip_dma_init()
738 ret = video_register_device(&dma->video, VFL_TYPE_VIDEO, -1); in xvip_dma_init()
740 dev_err(dma->xdev->dev, "failed to register video device\n"); in xvip_dma_init()
747 xvip_dma_cleanup(dma); in xvip_dma_init()
751 void xvip_dma_cleanup(struct xvip_dma *dma) in xvip_dma_cleanup() argument
753 if (video_is_registered(&dma->video)) in xvip_dma_cleanup()
754 video_unregister_device(&dma->video); in xvip_dma_cleanup()
756 if (!IS_ERR_OR_NULL(dma->dma)) in xvip_dma_cleanup()
757 dma_release_channel(dma->dma); in xvip_dma_cleanup()
759 media_entity_cleanup(&dma->video.entity); in xvip_dma_cleanup()
761 mutex_destroy(&dma->lock); in xvip_dma_cleanup()
762 mutex_destroy(&dma->pipe.lock); in xvip_dma_cleanup()