Patch Detail
Show a patch.
GET /api/patches/15855/?format=api
{ "id": 15855, "url": "https://patchwork.libcamera.org/api/patches/15855/?format=api", "web_url": "https://patchwork.libcamera.org/patch/15855/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20220510115147.19360-16-laurent.pinchart@ideasonboard.com>", "date": "2022-05-10T11:51:12", "name": "[libcamera-devel,15/50] staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi", "commit_ref": null, "pull_url": null, "state": "not-applicable", "archived": false, "hash": "8d6b8a5e59726c7b0d6c36b2cb620e7e2fb8d447", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/15855/mbox/", "series": [ { "id": 3106, "url": "https://patchwork.libcamera.org/api/series/3106/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3106", "date": "2022-05-10T11:50:57", "name": "staging: media: imx: Prepare destaging of imx7-media-csi", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3106/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/15855/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/15855/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6E2D9C326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 May 2022 11:52:17 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1050465671;\n\tTue, 10 May 2022 13:52:17 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0CBC96565D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 May 2022 13:52:10 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 23E5CB9A;\n\tTue, 10 May 2022 13:52:09 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1652183537;\n\tbh=8VldD6m7V1ArQbM/CUQB5R4nyIPDmBlDaODt8kryyMA=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=LO2Mn7w5vSAoc+O8OCM0gw3naZWMPxNI3IVQq7luaFblkdrcyZpQLyv7kNvchTkqX\n\tkqpA0zfL/XEDYj1jiFmmVRbNx8NVbXGTiIs9Vy+OMuks30hgxjxIRS9pb5U90t1Ii9\n\tswLBmBxpQFsukcN9IAlc2D6yhfOL0vBMFJN7JBPESgAYQvQX2xzxY8Cex7Gl1+a5Cq\n\tdAQf2VOjrcvDIRXaLitXHH1NiwNtZ46kFxsk7GUdgDJ0s+YY5scOa0GIXde+IOdAub\n\tcUlOYmnkJnAp5TIRVUmmLxebHm/LJT2tprEzfzp3sBlCIj82EXQvjoVT2cP51f5co+\n\tBAOFAh4RS3scw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1652183529;\n\tbh=8VldD6m7V1ArQbM/CUQB5R4nyIPDmBlDaODt8kryyMA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=GnQkg5jNjp9ViBvKzwa1Ipd2eNvoK3kwj0omg4uWZFfchKArHK2WeYBIzjL5QHL9E\n\tHK8uu2q5g0xb3UNFpWhbzVrxqX7dNWl9j7wBKzLprXtpjZLGGJLVa6ledB5oS3pliL\n\tnJnXVOJsV9U0xTgpBrZD0U3aak0a7WfIjd2Ey2Vg=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"GnQkg5jN\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 10 May 2022 14:51:12 +0300", "Message-Id": "<20220510115147.19360-16-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.35.1", "In-Reply-To": "<20220510115147.19360-1-laurent.pinchart@ideasonboard.com>", "References": "<20220510115147.19360-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 15/50] staging: media: imx:\n\timx7-media-csi: Fold capture_priv into imx7_csi", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Cc": "Martin Kepplinger <martin.kepplinger@puri.sm>, kernel@pengutronix.de,\n\tDorota Czaplejewicz <dorota.czaplejewicz@puri.sm>,\n\tAlexander Stein <alexander.stein@ew.tq-group.com>,\n\tRui Miguel Silva <rmfrfs@gmail.com>,\n\tPhilipp Zabel <p.zabel@pengutronix.de>, \n\tSteve Longerbeam <slongerbeam@gmail.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Merge the capture_priv fields in the imx7_csi structure as there's no\nmore need to have two separate structures. Update all the users\naccordingly.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n drivers/staging/media/imx/imx7-media-csi.c | 271 +++++++++------------\n 1 file changed, 117 insertions(+), 154 deletions(-)", "diff": "diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c\nindex ad69c2e8dbc2..9b4463e456c2 100644\n--- a/drivers/staging/media/imx/imx7-media-csi.c\n+++ b/drivers/staging/media/imx/imx7-media-csi.c\n@@ -193,7 +193,14 @@ struct imx7_csi {\n \tconst struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];\n \n \t/* Video device */\n-\tstruct imx_media_video_dev *vdev;\n+\tstruct imx_media_video_dev vdev;\t/* Video device */\n+\tstruct media_pad vdev_pad;\t\t/* Video device pad */\n+\n+\tstruct mutex vdev_mutex;\t\t/* Protect vdev operations */\n+\n+\tstruct vb2_queue q;\t\t\t/* The videobuf2 queue */\n+\tstruct list_head ready_q;\t\t/* List of queued buffers */\n+\tspinlock_t q_lock;\t\t\t/* Protect ready_q */\n \n \t/* Buffers and streaming state */\n \tstruct imx_media_buffer *active_vb2_buf[2];\n@@ -343,18 +350,17 @@ static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,\n }\n \n static struct imx_media_buffer *\n-imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev);\n+imx7_media_capture_device_next_buf(struct imx7_csi *csi);\n \n static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)\n {\n-\tstruct imx_media_video_dev *vdev = csi->vdev;\n \tstruct imx_media_buffer *buf;\n \tstruct vb2_buffer *vb2_buf;\n \tdma_addr_t phys[2];\n \tint i;\n \n \tfor (i = 0; i < 2; i++) {\n-\t\tbuf = imx7_media_capture_device_next_buf(vdev);\n+\t\tbuf = imx7_media_capture_device_next_buf(csi);\n \t\tif (buf) {\n \t\t\tcsi->active_vb2_buf[i] = buf;\n \t\t\tvb2_buf = &buf->vbuf.vb2_buf;\n@@ -389,7 +395,7 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,\n \n static int imx7_csi_dma_setup(struct imx7_csi *csi)\n {\n-\tstruct imx_media_video_dev *vdev = csi->vdev;\n+\tstruct imx_media_video_dev *vdev = &csi->vdev;\n \tint ret;\n \n \tret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,\n@@ -440,7 +446,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)\n \n static void imx7_csi_configure(struct imx7_csi *csi)\n {\n-\tstruct imx_media_video_dev *vdev = csi->vdev;\n+\tstruct imx_media_video_dev *vdev = &csi->vdev;\n \tstruct v4l2_pix_format *out_pix = &vdev->fmt;\n \tint width = out_pix->width;\n \tu32 stride = 0;\n@@ -640,7 +646,7 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi)\n \n static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)\n {\n-\tstruct imx_media_video_dev *vdev = csi->vdev;\n+\tstruct imx_media_video_dev *vdev = &csi->vdev;\n \tstruct imx_media_buffer *done, *next;\n \tstruct vb2_buffer *vb;\n \tdma_addr_t phys;\n@@ -656,7 +662,7 @@ static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)\n \tcsi->frame_sequence++;\n \n \t/* get next queued buffer */\n-\tnext = imx7_media_capture_device_next_buf(vdev);\n+\tnext = imx7_media_capture_device_next_buf(csi);\n \tif (next) {\n \t\tphys = vb2_dma_contig_plane_dma_addr(&next->vbuf.vb2_buf, 0);\n \t\tcsi->active_vb2_buf[csi->buf_num] = next;\n@@ -732,25 +738,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)\n \n #define IMX_CAPTURE_NAME \"imx-capture\"\n \n-struct capture_priv {\n-\tstruct imx_media_dev *md;\t\t/* Media device */\n-\tstruct device *dev;\t\t\t/* Physical device */\n-\n-\tstruct imx_media_video_dev vdev;\t/* Video device */\n-\tstruct media_pad vdev_pad;\t\t/* Video device pad */\n-\n-\tstruct v4l2_subdev *src_sd;\t\t/* Source subdev */\n-\tint src_sd_pad;\t\t\t\t/* Source subdev pad */\n-\n-\tstruct mutex mutex;\t\t\t/* Protect vdev operations */\n-\n-\tstruct vb2_queue q;\t\t\t/* The videobuf2 queue */\n-\tstruct list_head ready_q;\t\t/* List of queued buffers */\n-\tspinlock_t q_lock;\t\t\t/* Protect ready_q */\n-};\n-\n-#define to_capture_priv(v) container_of(v, struct capture_priv, vdev)\n-\n /* In bytes, per queue */\n #define VID_MEM_LIMIT\tSZ_64M\n \n@@ -782,12 +769,12 @@ static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)\n static int capture_querycap(struct file *file, void *fh,\n \t\t\t struct v4l2_capability *cap)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n+\tstruct imx7_csi *csi = video_drvdata(file);\n \n \tstrscpy(cap->driver, IMX_CAPTURE_NAME, sizeof(cap->driver));\n \tstrscpy(cap->card, IMX_CAPTURE_NAME, sizeof(cap->card));\n \tsnprintf(cap->bus_info, sizeof(cap->bus_info),\n-\t\t \"platform:%s\", dev_name(priv->dev));\n+\t\t \"platform:%s\", dev_name(csi->dev));\n \n \treturn 0;\n }\n@@ -830,9 +817,9 @@ static int capture_enum_framesizes(struct file *file, void *fh,\n static int capture_g_fmt_vid_cap(struct file *file, void *fh,\n \t\t\t\t struct v4l2_format *f)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n+\tstruct imx7_csi *csi = video_drvdata(file);\n \n-\tf->fmt.pix = priv->vdev.fmt;\n+\tf->fmt.pix = csi->vdev.fmt;\n \n \treturn 0;\n }\n@@ -890,18 +877,18 @@ static int capture_try_fmt_vid_cap(struct file *file, void *fh,\n static int capture_s_fmt_vid_cap(struct file *file, void *fh,\n \t\t\t\t struct v4l2_format *f)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n+\tstruct imx7_csi *csi = video_drvdata(file);\n \tconst struct imx_media_pixfmt *cc;\n \n-\tif (vb2_is_busy(&priv->q)) {\n-\t\tdev_err(priv->dev, \"%s queue busy\\n\", __func__);\n+\tif (vb2_is_busy(&csi->q)) {\n+\t\tdev_err(csi->dev, \"%s queue busy\\n\", __func__);\n \t\treturn -EBUSY;\n \t}\n \n-\tcc = __capture_try_fmt(&f->fmt.pix, &priv->vdev.compose);\n+\tcc = __capture_try_fmt(&f->fmt.pix, &csi->vdev.compose);\n \n-\tpriv->vdev.cc = cc;\n-\tpriv->vdev.fmt = f->fmt.pix;\n+\tcsi->vdev.cc = cc;\n+\tcsi->vdev.fmt = f->fmt.pix;\n \n \treturn 0;\n }\n@@ -909,14 +896,14 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,\n static int capture_g_selection(struct file *file, void *fh,\n \t\t\t struct v4l2_selection *s)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n+\tstruct imx7_csi *csi = video_drvdata(file);\n \n \tswitch (s->target) {\n \tcase V4L2_SEL_TGT_COMPOSE:\n \tcase V4L2_SEL_TGT_COMPOSE_DEFAULT:\n \tcase V4L2_SEL_TGT_COMPOSE_BOUNDS:\n \t\t/* The compose rectangle is fixed to the source format. */\n-\t\ts->r = priv->vdev.compose;\n+\t\ts->r = csi->vdev.compose;\n \t\tbreak;\n \tcase V4L2_SEL_TGT_COMPOSE_PADDED:\n \t\t/*\n@@ -926,8 +913,8 @@ static int capture_g_selection(struct file *file, void *fh,\n \t\t */\n \t\ts->r.left = 0;\n \t\ts->r.top = 0;\n-\t\ts->r.width = priv->vdev.fmt.width;\n-\t\ts->r.height = priv->vdev.fmt.height;\n+\t\ts->r.width = csi->vdev.fmt.width;\n+\t\ts->r.height = csi->vdev.fmt.height;\n \t\tbreak;\n \tdefault:\n \t\treturn -EINVAL;\n@@ -983,8 +970,8 @@ static int capture_queue_setup(struct vb2_queue *vq,\n \t\t\t unsigned int sizes[],\n \t\t\t struct device *alloc_devs[])\n {\n-\tstruct capture_priv *priv = vb2_get_drv_priv(vq);\n-\tstruct v4l2_pix_format *pix = &priv->vdev.fmt;\n+\tstruct imx7_csi *csi = vb2_get_drv_priv(vq);\n+\tstruct v4l2_pix_format *pix = &csi->vdev.fmt;\n \tunsigned int count = *nbuffers;\n \n \tif (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)\n@@ -1021,12 +1008,11 @@ static int capture_buf_init(struct vb2_buffer *vb)\n \n static int capture_buf_prepare(struct vb2_buffer *vb)\n {\n-\tstruct vb2_queue *vq = vb->vb2_queue;\n-\tstruct capture_priv *priv = vb2_get_drv_priv(vq);\n-\tstruct v4l2_pix_format *pix = &priv->vdev.fmt;\n+\tstruct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);\n+\tstruct v4l2_pix_format *pix = &csi->vdev.fmt;\n \n \tif (vb2_plane_size(vb, 0) < pix->sizeimage) {\n-\t\tdev_err(priv->dev,\n+\t\tdev_err(csi->dev,\n \t\t\t\"data will not fit into plane (%lu < %lu)\\n\",\n \t\t\tvb2_plane_size(vb, 0), (long)pix->sizeimage);\n \t\treturn -EINVAL;\n@@ -1039,27 +1025,27 @@ static int capture_buf_prepare(struct vb2_buffer *vb)\n \n static void capture_buf_queue(struct vb2_buffer *vb)\n {\n-\tstruct capture_priv *priv = vb2_get_drv_priv(vb->vb2_queue);\n+\tstruct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);\n \tstruct imx_media_buffer *buf = to_imx_media_vb(vb);\n \tunsigned long flags;\n \n-\tspin_lock_irqsave(&priv->q_lock, flags);\n+\tspin_lock_irqsave(&csi->q_lock, flags);\n \n-\tlist_add_tail(&buf->list, &priv->ready_q);\n+\tlist_add_tail(&buf->list, &csi->ready_q);\n \n-\tspin_unlock_irqrestore(&priv->q_lock, flags);\n+\tspin_unlock_irqrestore(&csi->q_lock, flags);\n }\n \n-static int capture_validate_fmt(struct capture_priv *priv)\n+static int capture_validate_fmt(struct imx7_csi *csi)\n {\n \tstruct v4l2_subdev_format fmt_src;\n \tconst struct imx_media_pixfmt *cc;\n \tint ret;\n \n \t/* Retrieve the media bus format on the source subdev. */\n-\tfmt_src.pad = priv->src_sd_pad;\n+\tfmt_src.pad = IMX7_CSI_PAD_SRC;\n \tfmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n-\tret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);\n+\tret = v4l2_subdev_call(&csi->sd, pad, get_fmt, NULL, &fmt_src);\n \tif (ret)\n \t\treturn ret;\n \n@@ -1070,8 +1056,8 @@ static int capture_validate_fmt(struct capture_priv *priv)\n \t * derived directly from the compose rectangle size, and will thus\n \t * always match if the compose rectangle matches.\n \t */\n-\tif (priv->vdev.compose.width != fmt_src.format.width ||\n-\t priv->vdev.compose.height != fmt_src.format.height)\n+\tif (csi->vdev.compose.width != fmt_src.format.width ||\n+\t csi->vdev.compose.height != fmt_src.format.height)\n \t\treturn -EPIPE;\n \n \t/*\n@@ -1079,7 +1065,7 @@ static int capture_validate_fmt(struct capture_priv *priv)\n \t * set on the video node.\n \t */\n \tcc = capture_find_format(fmt_src.format.code, 0);\n-\tif (!cc || priv->vdev.cc->cs != cc->cs)\n+\tif (!cc || csi->vdev.cc->cs != cc->cs)\n \t\treturn -EPIPE;\n \n \treturn 0;\n@@ -1087,56 +1073,54 @@ static int capture_validate_fmt(struct capture_priv *priv)\n \n static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)\n {\n-\tstruct capture_priv *priv = vb2_get_drv_priv(vq);\n+\tstruct imx7_csi *csi = vb2_get_drv_priv(vq);\n \tstruct imx_media_buffer *buf, *tmp;\n \tunsigned long flags;\n \tint ret;\n \n-\tret = capture_validate_fmt(priv);\n+\tret = capture_validate_fmt(csi);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"capture format not valid\\n\");\n+\t\tdev_err(csi->dev, \"capture format not valid\\n\");\n \t\tgoto return_bufs;\n \t}\n \n-\tret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,\n-\t\t\t\t\t true);\n+\tret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, true);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"pipeline start failed with %d\\n\", ret);\n+\t\tdev_err(csi->dev, \"pipeline start failed with %d\\n\", ret);\n \t\tgoto return_bufs;\n \t}\n \n \treturn 0;\n \n return_bufs:\n-\tspin_lock_irqsave(&priv->q_lock, flags);\n-\tlist_for_each_entry_safe(buf, tmp, &priv->ready_q, list) {\n+\tspin_lock_irqsave(&csi->q_lock, flags);\n+\tlist_for_each_entry_safe(buf, tmp, &csi->ready_q, list) {\n \t\tlist_del(&buf->list);\n \t\tvb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);\n \t}\n-\tspin_unlock_irqrestore(&priv->q_lock, flags);\n+\tspin_unlock_irqrestore(&csi->q_lock, flags);\n \treturn ret;\n }\n \n static void capture_stop_streaming(struct vb2_queue *vq)\n {\n-\tstruct capture_priv *priv = vb2_get_drv_priv(vq);\n+\tstruct imx7_csi *csi = vb2_get_drv_priv(vq);\n \tstruct imx_media_buffer *frame;\n \tstruct imx_media_buffer *tmp;\n \tunsigned long flags;\n \tint ret;\n \n-\tret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,\n-\t\t\t\t\t false);\n+\tret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, false);\n \tif (ret)\n-\t\tdev_warn(priv->dev, \"pipeline stop failed with %d\\n\", ret);\n+\t\tdev_warn(csi->dev, \"pipeline stop failed with %d\\n\", ret);\n \n \t/* release all active buffers */\n-\tspin_lock_irqsave(&priv->q_lock, flags);\n-\tlist_for_each_entry_safe(frame, tmp, &priv->ready_q, list) {\n+\tspin_lock_irqsave(&csi->q_lock, flags);\n+\tlist_for_each_entry_safe(frame, tmp, &csi->ready_q, list) {\n \t\tlist_del(&frame->list);\n \t\tvb2_buffer_done(&frame->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);\n \t}\n-\tspin_unlock_irqrestore(&priv->q_lock, flags);\n+\tspin_unlock_irqrestore(&csi->q_lock, flags);\n }\n \n static const struct vb2_ops capture_qops = {\n@@ -1156,16 +1140,16 @@ static const struct vb2_ops capture_qops = {\n \n static int capture_open(struct file *file)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n-\tstruct video_device *vfd = priv->vdev.vfd;\n+\tstruct imx7_csi *csi = video_drvdata(file);\n+\tstruct video_device *vfd = csi->vdev.vfd;\n \tint ret;\n \n-\tif (mutex_lock_interruptible(&priv->mutex))\n+\tif (mutex_lock_interruptible(&csi->vdev_mutex))\n \t\treturn -ERESTARTSYS;\n \n \tret = v4l2_fh_open(file);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"v4l2_fh_open failed\\n\");\n+\t\tdev_err(csi->dev, \"v4l2_fh_open failed\\n\");\n \t\tgoto out;\n \t}\n \n@@ -1174,17 +1158,17 @@ static int capture_open(struct file *file)\n \t\tv4l2_fh_release(file);\n \n out:\n-\tmutex_unlock(&priv->mutex);\n+\tmutex_unlock(&csi->vdev_mutex);\n \treturn ret;\n }\n \n static int capture_release(struct file *file)\n {\n-\tstruct capture_priv *priv = video_drvdata(file);\n-\tstruct video_device *vfd = priv->vdev.vfd;\n-\tstruct vb2_queue *vq = &priv->q;\n+\tstruct imx7_csi *csi = video_drvdata(file);\n+\tstruct video_device *vfd = csi->vdev.vfd;\n+\tstruct vb2_queue *vq = &csi->q;\n \n-\tmutex_lock(&priv->mutex);\n+\tmutex_lock(&csi->vdev_mutex);\n \n \tif (file->private_data == vq->owner) {\n \t\tvb2_queue_release(vq);\n@@ -1194,7 +1178,7 @@ static int capture_release(struct file *file)\n \tv4l2_pipeline_pm_put(&vfd->entity);\n \n \tv4l2_fh_release(file);\n-\tmutex_unlock(&priv->mutex);\n+\tmutex_unlock(&csi->vdev_mutex);\n \treturn 0;\n }\n \n@@ -1212,33 +1196,32 @@ static const struct v4l2_file_operations capture_fops = {\n */\n \n static struct imx_media_buffer *\n-imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev)\n+imx7_media_capture_device_next_buf(struct imx7_csi *csi)\n {\n-\tstruct capture_priv *priv = to_capture_priv(vdev);\n \tstruct imx_media_buffer *buf = NULL;\n \tunsigned long flags;\n \n-\tspin_lock_irqsave(&priv->q_lock, flags);\n+\tspin_lock_irqsave(&csi->q_lock, flags);\n \n \t/* get next queued buffer */\n-\tif (!list_empty(&priv->ready_q)) {\n-\t\tbuf = list_entry(priv->ready_q.next, struct imx_media_buffer,\n+\tif (!list_empty(&csi->ready_q)) {\n+\t\tbuf = list_entry(csi->ready_q.next, struct imx_media_buffer,\n \t\t\t\t list);\n \t\tlist_del(&buf->list);\n \t}\n \n-\tspin_unlock_irqrestore(&priv->q_lock, flags);\n+\tspin_unlock_irqrestore(&csi->q_lock, flags);\n \n \treturn buf;\n }\n \n-static int capture_init_format(struct capture_priv *priv)\n+static int capture_init_format(struct imx7_csi *csi)\n {\n \tstruct v4l2_subdev_format fmt_src = {\n-\t\t.pad = priv->src_sd_pad,\n+\t\t.pad = IMX7_CSI_PAD_SRC,\n \t\t.which = V4L2_SUBDEV_FORMAT_ACTIVE,\n \t};\n-\tstruct imx_media_video_dev *vdev = &priv->vdev;\n+\tstruct imx_media_video_dev *vdev = &csi->vdev;\n \n \tfmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;\n \tfmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;\n@@ -1254,86 +1237,68 @@ static int capture_init_format(struct capture_priv *priv)\n \treturn 0;\n }\n \n-static int imx7_media_capture_device_register(struct imx_media_video_dev *vdev,\n-\t\t\t\t\t u32 link_flags)\n+static int imx7_media_capture_device_register(struct imx7_csi *csi)\n {\n-\tstruct capture_priv *priv = to_capture_priv(vdev);\n-\tstruct v4l2_subdev *sd = priv->src_sd;\n+\tstruct v4l2_subdev *sd = &csi->sd;\n \tstruct v4l2_device *v4l2_dev = sd->v4l2_dev;\n-\tstruct video_device *vfd = vdev->vfd;\n+\tstruct video_device *vfd = csi->vdev.vfd;\n \tint ret;\n \n-\t/* get media device */\n-\tpriv->md = container_of(v4l2_dev->mdev, struct imx_media_dev, md);\n-\n \tvfd->v4l2_dev = v4l2_dev;\n \n \t/* Initialize the default format and compose rectangle. */\n-\tret = capture_init_format(priv);\n+\tret = capture_init_format(csi);\n \tif (ret < 0)\n \t\treturn ret;\n \n \t/* Register the video device. */\n \tret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"Failed to register video device\\n\");\n+\t\tdev_err(csi->dev, \"Failed to register video device\\n\");\n \t\treturn ret;\n \t}\n \n-\tdev_info(priv->dev, \"Registered %s as /dev/%s\\n\", vfd->name,\n+\tdev_info(csi->dev, \"Registered %s as /dev/%s\\n\", vfd->name,\n \t\t video_device_node_name(vfd));\n \n-\t/* Create the link from the src_sd devnode pad to device node. */\n-\tif (link_flags & MEDIA_LNK_FL_IMMUTABLE)\n-\t\tlink_flags |= MEDIA_LNK_FL_ENABLED;\n-\tret = media_create_pad_link(&sd->entity, priv->src_sd_pad,\n-\t\t\t\t &vfd->entity, 0, link_flags);\n+\t/* Create the link from the CSI subdev to the video device. */\n+\tret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC, &vfd->entity,\n+\t\t\t\t 0, MEDIA_LNK_FL_IMMUTABLE |\n+\t\t\t\t MEDIA_LNK_FL_ENABLED);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"failed to create link to device node\\n\");\n+\t\tdev_err(csi->dev, \"failed to create link to device node\\n\");\n \t\tvideo_unregister_device(vfd);\n \t\treturn ret;\n \t}\n \n \t/* Add vdev to the video devices list. */\n-\timx_media_add_video_device(priv->md, vdev);\n+\timx_media_add_video_device(csi->imxmd, &csi->vdev);\n \n \treturn 0;\n }\n \n-static void imx7_media_capture_device_unregister(struct imx_media_video_dev *vdev)\n+static void imx7_media_capture_device_unregister(struct imx7_csi *csi)\n {\n-\tstruct capture_priv *priv = to_capture_priv(vdev);\n-\tstruct video_device *vfd = priv->vdev.vfd;\n+\tstruct video_device *vfd = csi->vdev.vfd;\n \n \tmedia_entity_cleanup(&vfd->entity);\n \tvideo_unregister_device(vfd);\n }\n \n-static struct imx_media_video_dev *\n-imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,\n-\t\t\t int pad)\n+static int imx7_media_capture_device_init(struct imx7_csi *csi)\n {\n-\tstruct capture_priv *priv;\n \tstruct video_device *vfd;\n \tstruct vb2_queue *vq;\n \tint ret;\n \n-\tpriv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);\n-\tif (!priv)\n-\t\treturn ERR_PTR(-ENOMEM);\n-\n-\tpriv->src_sd = src_sd;\n-\tpriv->src_sd_pad = pad;\n-\tpriv->dev = dev;\n-\n-\tmutex_init(&priv->mutex);\n-\tINIT_LIST_HEAD(&priv->ready_q);\n-\tspin_lock_init(&priv->q_lock);\n+\tmutex_init(&csi->vdev_mutex);\n+\tINIT_LIST_HEAD(&csi->ready_q);\n+\tspin_lock_init(&csi->q_lock);\n \n \t/* Allocate and initialize the video device. */\n \tvfd = video_device_alloc();\n \tif (!vfd)\n-\t\treturn ERR_PTR(-ENOMEM);\n+\t\treturn -ENOMEM;\n \n \tvfd->fops = &capture_fops;\n \tvfd->ioctl_ops = &capture_ioctl_ops;\n@@ -1343,44 +1308,44 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,\n \tvfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;\n \tvfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING\n \t\t\t | V4L2_CAP_IO_MC;\n-\tvfd->lock = &priv->mutex;\n-\tvfd->queue = &priv->q;\n+\tvfd->lock = &csi->vdev_mutex;\n+\tvfd->queue = &csi->q;\n \n-\tsnprintf(vfd->name, sizeof(vfd->name), \"%s capture\", src_sd->name);\n+\tsnprintf(vfd->name, sizeof(vfd->name), \"%s capture\", csi->sd.name);\n \n-\tvideo_set_drvdata(vfd, priv);\n-\tpriv->vdev.vfd = vfd;\n-\tINIT_LIST_HEAD(&priv->vdev.list);\n+\tvideo_set_drvdata(vfd, csi);\n+\tcsi->vdev.vfd = vfd;\n+\tINIT_LIST_HEAD(&csi->vdev.list);\n \n \t/* Initialize the video device pad. */\n-\tpriv->vdev_pad.flags = MEDIA_PAD_FL_SINK;\n-\tret = media_entity_pads_init(&vfd->entity, 1, &priv->vdev_pad);\n+\tcsi->vdev_pad.flags = MEDIA_PAD_FL_SINK;\n+\tret = media_entity_pads_init(&vfd->entity, 1, &csi->vdev_pad);\n \tif (ret) {\n \t\tvideo_device_release(vfd);\n-\t\treturn ERR_PTR(ret);\n+\t\treturn ret;\n \t}\n \n \t/* Initialize the vb2 queue. */\n-\tvq = &priv->q;\n+\tvq = &csi->q;\n \tvq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;\n \tvq->io_modes = VB2_MMAP | VB2_DMABUF;\n-\tvq->drv_priv = priv;\n+\tvq->drv_priv = csi;\n \tvq->buf_struct_size = sizeof(struct imx_media_buffer);\n \tvq->ops = &capture_qops;\n \tvq->mem_ops = &vb2_dma_contig_memops;\n \tvq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;\n-\tvq->lock = &priv->mutex;\n+\tvq->lock = &csi->vdev_mutex;\n \tvq->min_buffers_needed = 2;\n-\tvq->dev = priv->dev;\n+\tvq->dev = csi->dev;\n \n \tret = vb2_queue_init(vq);\n \tif (ret) {\n-\t\tdev_err(priv->dev, \"vb2_queue_init failed\\n\");\n+\t\tdev_err(csi->dev, \"vb2_queue_init failed\\n\");\n \t\tvideo_device_release(vfd);\n-\t\treturn ERR_PTR(ret);\n+\t\treturn ret;\n \t}\n \n-\treturn &priv->vdev;\n+\treturn 0;\n }\n \n /* -----------------------------------------------------------------------------\n@@ -1645,7 +1610,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,\n \t\t\t\t struct v4l2_subdev_format *sink_fmt)\n {\n \tstruct imx7_csi *csi = v4l2_get_subdevdata(sd);\n-\tstruct imx_media_video_dev *vdev = csi->vdev;\n+\tstruct imx_media_video_dev *vdev = &csi->vdev;\n \tconst struct v4l2_pix_format *out_pix = &vdev->fmt;\n \tstruct media_pad *pad;\n \tint ret;\n@@ -1716,13 +1681,11 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)\n \tstruct imx7_csi *csi = v4l2_get_subdevdata(sd);\n \tint ret;\n \n-\tcsi->vdev = imx7_media_capture_device_init(csi->sd.dev, &csi->sd,\n-\t\t\t\t\t\t IMX7_CSI_PAD_SRC);\n-\tif (IS_ERR(csi->vdev))\n-\t\treturn PTR_ERR(csi->vdev);\n+\tret = imx7_media_capture_device_init(csi);\n+\tif (ret)\n+\t\treturn ret;\n \n-\tret = imx7_media_capture_device_register(csi->vdev,\n-\t\t\t\t\t\t MEDIA_LNK_FL_IMMUTABLE);\n+\tret = imx7_media_capture_device_register(csi);\n \tif (ret)\n \t\treturn ret;\n \n@@ -1737,7 +1700,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)\n \treturn 0;\n \n err_unreg:\n-\timx7_media_capture_device_unregister(csi->vdev);\n+\timx7_media_capture_device_unregister(csi);\n \treturn ret;\n }\n \n@@ -1745,7 +1708,7 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)\n {\n \tstruct imx7_csi *csi = v4l2_get_subdevdata(sd);\n \n-\timx7_media_capture_device_unregister(csi->vdev);\n+\timx7_media_capture_device_unregister(csi);\n }\n \n static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {\n", "prefixes": [ "libcamera-devel", "15/50" ] }