From 57327b0824052b474aee0f2088ce2bbb6689fe6e Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 9 May 2022 23:32:33 +0100 Subject: [PATCH] media: staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf Decouple from the imx_media_dma_buf structure defined in shared helpers by duplicating it in the imx7-media-csi driver, along with the two small alloc and free functions. No functional change intended. Signed-off-by: Laurent Pinchart Acked-by: Rui Miguel Silva Tested-by: Alexander Stein Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/imx/imx7-media-csi.c | 40 +++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index aa66fd8e..834195f 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -184,6 +184,12 @@ to_imx7_csi_vb2_buffer(struct vb2_buffer *vb) return container_of(vbuf, struct imx7_csi_vb2_buffer, vbuf); } +struct imx7_csi_dma_buf { + void *virt; + dma_addr_t phys; + unsigned long len; +}; + struct imx7_csi { struct device *dev; @@ -227,7 +233,7 @@ struct imx7_csi { /* Buffers and streaming state */ struct imx7_csi_vb2_buffer *active_vb2_buf[2]; - struct imx_media_dma_buf underrun_buf; + struct imx7_csi_dma_buf underrun_buf; bool is_streaming; int buf_num; @@ -415,12 +421,38 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi, } } +static void imx7_csi_free_dma_buf(struct imx7_csi *csi, + struct imx7_csi_dma_buf *buf) +{ + if (buf->virt) + dma_free_coherent(csi->dev, buf->len, buf->virt, buf->phys); + + buf->virt = NULL; + buf->phys = 0; +} + +static int imx7_csi_alloc_dma_buf(struct imx7_csi *csi, + struct imx7_csi_dma_buf *buf, int size) +{ + imx7_csi_free_dma_buf(csi, buf); + + buf->len = PAGE_ALIGN(size); + buf->virt = dma_alloc_coherent(csi->dev, buf->len, &buf->phys, + GFP_DMA | GFP_KERNEL); + if (!buf->virt) { + dev_err(csi->dev, "%s: failed\n", __func__); + return -ENOMEM; + } + + return 0; +} + static int imx7_csi_dma_setup(struct imx7_csi *csi) { int ret; - ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf, - csi->vdev_fmt.sizeimage); + ret = imx7_csi_alloc_dma_buf(csi, &csi->underrun_buf, + csi->vdev_fmt.sizeimage); if (ret < 0) { v4l2_warn(&csi->sd, "consider increasing the CMA area\n"); return ret; @@ -439,7 +471,7 @@ static void imx7_csi_dma_cleanup(struct imx7_csi *csi, enum vb2_buffer_state return_status) { imx7_csi_dma_unsetup_vb2_buf(csi, return_status); - imx_media_free_dma_buf(csi->dev, &csi->underrun_buf); + imx7_csi_free_dma_buf(csi, &csi->underrun_buf); } static void imx7_csi_dma_stop(struct imx7_csi *csi) -- 2.7.4