summaryrefslogtreecommitdiff
path: root/drivers/staging/media/imx/imx7-media-csi.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-09 23:32:33 +0100
committerMauro Carvalho Chehab <mchehab@kernel.org>2022-07-08 18:02:52 +0100
commit57327b0824052b474aee0f2088ce2bbb6689fe6e (patch)
treed2bb40e49abd5b9c5efd54bf01fdd60d0b8408b6 /drivers/staging/media/imx/imx7-media-csi.c
parent0cc432b7412a783d4bf82dedebcca776792519ed (diff)
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 <laurent.pinchart@ideasonboard.com> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com> Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'drivers/staging/media/imx/imx7-media-csi.c')
-rw-r--r--drivers/staging/media/imx/imx7-media-csi.c40
1 files 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 aa66fd8ef8e8..834195f24c1f 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)