linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
@ 2022-05-10 11:58 Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 01/50] staging: media: imx: imx7-media-csi: Initialize locks early on Laurent Pinchart
                   ` (52 more replies)
  0 siblings, 53 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Hello,

This patch series prepares the imx7-media-csi for destaging by
decoupling it from the helpers shared with the i.MX6 IPUv3.

The strategy Paul and I have followed is to import copies of helper code
and, refactor it within the imx7-media-csi driver, and repeat until no
more shared helpers are used. There is still room for refactoring and
simplification of the imx7-media-csi driver, but I believe it is now in
a state clean enough to be moved out of staging.

The series also includes a few fixes or improvements in supported
formats that are now made possible thanks to this refactoring. See
patches 45/50 and 46/50 for details.

The code size has grown as a result. This is partly offset by code in
the shared helpers that can be removed or simplified, but I haven't
starting working on that. The helpers are now used for the i.MX6 IPUv3
only, so I will leave this exercise to anyone who would be interested in
destaging that driver as well.

Some of the items in the TODO file related to the imx7-media-csi driver
have been addressed. The two remaining items are frame interval monitor
support and restricting the list of supported formats to the SoC
version. The former isn't a destaging blocker in my opinion, as the
feature can be added later if desired (and frame interval monitoring
should then be moved to the V4L2 core). I believe the latter could also
be addressed after destaging the driver, but in any case, this is a
discussion for a future destaging series (which may come as soon as this
one is accepted).

Alexander, this also could greatly simplify your "[PATCH v3 0/8]
imx7/imx8mm media / csi patches" series.

Laurent Pinchart (48):
  staging: media: imx: imx7-media-csi: Initialize locks early on
  staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  staging: media: imx: imx7-media-csi: Import notifier helpers
  staging: media: imx: imx7-media-csi: Drop duplicate link creation
  staging: media: imx: imx7-media-csi: Drop the imx_media notifier
  staging: media: imx: imx7-media-csi: Don't populate vdev lists
  staging: media: imx: imx7-media-csi: Drop unused frame_interval
  staging: media: imx: imx7-media-csi: Move format init to probe time
  staging: media: imx: imx7-media-csi: Import video device helpers
  staging: media: imx: imx7-media-csi: Drop legacy video device support
  staging: media: imx: imx7-media-csi: Drop unused controls support
  staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure
  staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi
  staging: media: imx: imx7-media-csi: Ensure consistent function prefix
  staging: media: imx: imx7-media-csi: Don't set subdev group id
  staging: media: imx: imx7-media-csi: Import imx_media_dev_init()
    helper
  staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi
  staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device
    call
  staging: media: imx: imx7-media-csi: Don't initialize unused fields
  staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()
  staging: media: imx: imx7-media-csi: Import
    imx_media_pipeline_set_stream()
  staging: media: imx: imx7-media-csi: Avoid unnecessary casts
  staging: media: imx: imx7-media-csi: Inline pipeline start/stop
  staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi
  staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer
  staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into
    imx7_csi
  staging: media: imx: imx7-media-csi: Store imx7_csi in drv data
  staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf
  staging: media: imx: imx7-media-csi: Decouple from shared macros
  staging: media: imx: imx7-media-csi: Drop error message on alloc
    failure
  staging: media: imx: imx7-media-csi: Import format helpers
  staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool
    yuv field
  staging: media: imx: imx7-media-csi: Drop IC support from
    imx7_csi_try_colorimetry()
  staging: media: imx: imx7-media-csi: Drop IPU-only formats
  staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB
    formats
  staging: media: imx: imx7-media-csi: Make default formats consistent
  staging: media: imx: imx7-media-csi: Define macro for default mbus
    code
  staging: media: imx: imx7-media-csi: Simplify default mbus code in
    try_fmt
  staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format
    selectors
  staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt
    fields
  staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()
  staging: media: imx: imx7-media-csi: Simplify default format in
    try_fmt
  staging: media: imx: imx7-media-csi: Fix list of supported formats
  staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support
  staging: media: imx: imx7-media-csi: Drop unneeded pixel format
    validation
  staging: media: imx: imx7-media-csi: Inline
    imx7_csi_enum_pixel_formats()
  staging: media: imx: imx7-media-csi: Drop V4L2 events support
  staging: media: imx: imx7-media-csi: Drop usage of shared helpers

Paul Elder (2):
  staging: media: imx: imx7-media-csi: Move misc init out of probe()
  staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi

 drivers/staging/media/imx/imx7-media-csi.c | 1370 +++++++++++++++++---
 1 file changed, 1172 insertions(+), 198 deletions(-)


base-commit: c5eb0a61238dd6faf37f58c9ce61c9980aaffd7a
-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 69+ messages in thread

* [PATCH 01/50] staging: media: imx: imx7-media-csi: Initialize locks early on
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Laurent Pinchart
                   ` (51 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Group all the direct initialization of imx7_csi fields at the beginning
of the imx7_csi_probe() function instead of spreading them around.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 8467a1491048..893620e8fc03 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1188,27 +1188,32 @@ static int imx7_csi_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	csi->dev = dev;
+	platform_set_drvdata(pdev, &csi->sd);
+
+	spin_lock_init(&csi->irqlock);
+	mutex_init(&csi->lock);
 
 	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
 	if (IS_ERR(csi->mclk)) {
 		ret = PTR_ERR(csi->mclk);
 		dev_err(dev, "Failed to get mclk: %d", ret);
-		return ret;
+		goto destroy_mutex;
 	}
 
 	csi->irq = platform_get_irq(pdev, 0);
-	if (csi->irq < 0)
-		return csi->irq;
+	if (csi->irq < 0) {
+		ret = csi->irq;
+		goto destroy_mutex;
+	}
 
 	csi->regbase = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(csi->regbase))
-		return PTR_ERR(csi->regbase);
+	if (IS_ERR(csi->regbase)) {
+		ret = PTR_ERR(csi->regbase);
+		goto destroy_mutex;
+	}
 
 	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
 
-	spin_lock_init(&csi->irqlock);
-	mutex_init(&csi->lock);
-
 	/* install interrupt handler */
 	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
 			       (void *)csi);
@@ -1223,7 +1228,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 		ret = PTR_ERR(imxmd);
 		goto destroy_mutex;
 	}
-	platform_set_drvdata(pdev, &csi->sd);
 
 	ret = imx_media_of_add_csi(imxmd, node);
 	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 01/50] staging: media: imx: imx7-media-csi: Initialize locks early on Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 14:09   ` Rui Miguel Silva
  2022-05-10 15:25   ` [PATCH v1.1 " Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 03/50] staging: media: imx: imx7-media-csi: Import notifier helpers Laurent Pinchart
                   ` (50 subsequent siblings)
  52 siblings, 2 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Prepare for the decoupling of the imx7-media-csi driver from the
IPUv3-based drivers by moving the imx_media_dev handling from probe()
function to separate functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 71 +++++++++++++---------
 1 file changed, 42 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 893620e8fc03..d7c65b8bb3c9 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1175,11 +1175,45 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 	return v4l2_async_register_subdev(&csi->sd);
 }
 
+static void imx7_csi_media_cleanup(struct imx7_csi *csi)
+{
+	struct imx_media_dev *imxmd = csi->imxmd;
+
+	v4l2_device_unregister(&imxmd->v4l2_dev);
+	media_device_unregister(&imxmd->md);
+	media_device_cleanup(&imxmd->md);
+}
+
+static int imx7_csi_media_init(struct imx7_csi *csi)
+{
+	struct imx_media_dev *imxmd;
+	int ret;
+
+	/* add media device */
+	imxmd = imx_media_dev_init(csi->dev, NULL);
+	if (IS_ERR(imxmd))
+		return PTR_ERR(imxmd);
+
+	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
+	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
+		imx7_csi_media_cleanup(csi);
+		return ret;
+	}
+
+	ret = imx_media_dev_notifier_register(imxmd, NULL);
+	if (ret < 0) {
+		imx7_csi_media_cleanup(csi);
+		return ret;
+	}
+
+	csi->imxmd = imxmd;
+
+	return 0;
+}
+
 static int imx7_csi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *node = dev->of_node;
-	struct imx_media_dev *imxmd;
 	struct imx7_csi *csi;
 	int i, ret;
 
@@ -1193,6 +1227,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	spin_lock_init(&csi->irqlock);
 	mutex_init(&csi->lock);
 
+	/* Acquire resources and install interrupt handler. */
 	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
 	if (IS_ERR(csi->mclk)) {
 		ret = PTR_ERR(csi->mclk);
@@ -1214,7 +1249,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 
 	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
 
-	/* install interrupt handler */
 	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
 			       (void *)csi);
 	if (ret < 0) {
@@ -1222,22 +1256,11 @@ static int imx7_csi_probe(struct platform_device *pdev)
 		goto destroy_mutex;
 	}
 
-	/* add media device */
-	imxmd = imx_media_dev_init(dev, NULL);
-	if (IS_ERR(imxmd)) {
-		ret = PTR_ERR(imxmd);
+	/* Initialize all the media device infrastructure. */
+	ret = imx7_csi_media_init(csi);
+	if (ret)
 		goto destroy_mutex;
-	}
 
-	ret = imx_media_of_add_csi(imxmd, node);
-	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
-		goto cleanup;
-
-	ret = imx_media_dev_notifier_register(imxmd, NULL);
-	if (ret < 0)
-		goto cleanup;
-
-	csi->imxmd = imxmd;
 	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
 	v4l2_set_subdevdata(&csi->sd, csi);
 	csi->sd.internal_ops = &imx7_csi_internal_ops;
@@ -1269,11 +1292,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&csi->notifier);
 
 cleanup:
-	v4l2_async_nf_unregister(&imxmd->notifier);
-	v4l2_async_nf_cleanup(&imxmd->notifier);
-	v4l2_device_unregister(&imxmd->v4l2_dev);
-	media_device_unregister(&imxmd->md);
-	media_device_cleanup(&imxmd->md);
+	imx7_csi_media_cleanup(csi);
 
 destroy_mutex:
 	mutex_destroy(&csi->lock);
@@ -1285,14 +1304,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
 {
 	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct imx_media_dev *imxmd = csi->imxmd;
 
-	v4l2_async_nf_unregister(&imxmd->notifier);
-	v4l2_async_nf_cleanup(&imxmd->notifier);
-
-	media_device_unregister(&imxmd->md);
-	v4l2_device_unregister(&imxmd->v4l2_dev);
-	media_device_cleanup(&imxmd->md);
+	imx7_csi_media_cleanup(csi);
 
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 03/50] staging: media: imx: imx7-media-csi: Import notifier helpers
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 01/50] staging: media: imx: imx7-media-csi: Initialize locks early on Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 04/50] staging: media: imx: imx7-media-csi: Drop duplicate link creation Laurent Pinchart
                   ` (49 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

To prepare for code refactoring, copy the V4L2 async notifier helper
code used by this driver verbatim from imx-media-dev-common.c. Rename
some functions to avoid name clashes. No functional change included.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 210 ++++++++++++++++++++-
 1 file changed, 209 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index d7c65b8bb3c9..708076b7045a 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -717,6 +717,214 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+/* -----------------------------------------------------------------------------
+ * Temporary copy of imx_media_dev helpers
+ */
+
+static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n)
+{
+	return container_of(n, struct imx_media_dev, notifier);
+}
+
+/*
+ * Create the missing media links from the CSI-2 receiver.
+ * Called after all async subdevs have bound.
+ */
+static void imx_media_create_csi2_links(struct imx_media_dev *imxmd)
+{
+	struct v4l2_subdev *sd, *csi2 = NULL;
+
+	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
+		if (sd->grp_id == IMX_MEDIA_GRP_ID_CSI2) {
+			csi2 = sd;
+			break;
+		}
+	}
+	if (!csi2)
+		return;
+
+	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
+		/* skip if not a CSI or a CSI mux */
+		if (!(sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI) &&
+		    !(sd->grp_id & IMX_MEDIA_GRP_ID_CSI) &&
+		    !(sd->grp_id & IMX_MEDIA_GRP_ID_CSI_MUX))
+			continue;
+
+		v4l2_create_fwnode_links(csi2, sd);
+	}
+}
+
+/*
+ * adds given video device to given imx-media source pad vdev list.
+ * Continues upstream from the pad entity's sink pads.
+ */
+static int imx_media_add_vdev_to_pad(struct imx_media_dev *imxmd,
+				     struct imx_media_video_dev *vdev,
+				     struct media_pad *srcpad)
+{
+	struct media_entity *entity = srcpad->entity;
+	struct imx_media_pad_vdev *pad_vdev;
+	struct list_head *pad_vdev_list;
+	struct media_link *link;
+	struct v4l2_subdev *sd;
+	int i, ret;
+
+	/* skip this entity if not a v4l2_subdev */
+	if (!is_media_entity_v4l2_subdev(entity))
+		return 0;
+
+	sd = media_entity_to_v4l2_subdev(entity);
+
+	pad_vdev_list = to_pad_vdev_list(sd, srcpad->index);
+	if (!pad_vdev_list) {
+		v4l2_warn(&imxmd->v4l2_dev, "%s:%u has no vdev list!\n",
+			  entity->name, srcpad->index);
+		/*
+		 * shouldn't happen, but no reason to fail driver load,
+		 * just skip this entity.
+		 */
+		return 0;
+	}
+
+	/* just return if we've been here before */
+	list_for_each_entry(pad_vdev, pad_vdev_list, list) {
+		if (pad_vdev->vdev == vdev)
+			return 0;
+	}
+
+	dev_dbg(imxmd->md.dev, "adding %s to pad %s:%u\n",
+		vdev->vfd->entity.name, entity->name, srcpad->index);
+
+	pad_vdev = devm_kzalloc(imxmd->md.dev, sizeof(*pad_vdev), GFP_KERNEL);
+	if (!pad_vdev)
+		return -ENOMEM;
+
+	/* attach this vdev to this pad */
+	pad_vdev->vdev = vdev;
+	list_add_tail(&pad_vdev->list, pad_vdev_list);
+
+	/* move upstream from this entity's sink pads */
+	for (i = 0; i < entity->num_pads; i++) {
+		struct media_pad *pad = &entity->pads[i];
+
+		if (!(pad->flags & MEDIA_PAD_FL_SINK))
+			continue;
+
+		list_for_each_entry(link, &entity->links, list) {
+			if (link->sink != pad)
+				continue;
+			ret = imx_media_add_vdev_to_pad(imxmd, vdev,
+							link->source);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+/*
+ * For every subdevice, allocate an array of list_head's, one list_head
+ * for each pad, to hold the list of video devices reachable from that
+ * pad.
+ */
+static int imx_media_alloc_pad_vdev_lists(struct imx_media_dev *imxmd)
+{
+	struct list_head *vdev_lists;
+	struct media_entity *entity;
+	struct v4l2_subdev *sd;
+	int i;
+
+	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
+		entity = &sd->entity;
+		vdev_lists = devm_kcalloc(imxmd->md.dev,
+					  entity->num_pads, sizeof(*vdev_lists),
+					  GFP_KERNEL);
+		if (!vdev_lists)
+			return -ENOMEM;
+
+		/* attach to the subdev's host private pointer */
+		sd->host_priv = vdev_lists;
+
+		for (i = 0; i < entity->num_pads; i++)
+			INIT_LIST_HEAD(to_pad_vdev_list(sd, i));
+	}
+
+	return 0;
+}
+
+/* form the vdev lists in all imx-media source pads */
+static int imx_media_create_pad_vdev_lists(struct imx_media_dev *imxmd)
+{
+	struct imx_media_video_dev *vdev;
+	struct media_link *link;
+	int ret;
+
+	ret = imx_media_alloc_pad_vdev_lists(imxmd);
+	if (ret)
+		return ret;
+
+	list_for_each_entry(vdev, &imxmd->vdev_list, list) {
+		link = list_first_entry(&vdev->vfd->entity.links,
+					struct media_link, list);
+		ret = imx_media_add_vdev_to_pad(imxmd, vdev, link->source);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+/* async subdev complete notifier */
+static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier)
+{
+	struct imx_media_dev *imxmd = notifier2dev(notifier);
+	int ret;
+
+	mutex_lock(&imxmd->mutex);
+
+	imx_media_create_csi2_links(imxmd);
+
+	ret = imx_media_create_pad_vdev_lists(imxmd);
+	if (ret)
+		goto unlock;
+
+	ret = v4l2_device_register_subdev_nodes(&imxmd->v4l2_dev);
+unlock:
+	mutex_unlock(&imxmd->mutex);
+	if (ret)
+		return ret;
+
+	return media_device_register(&imxmd->md);
+}
+
+static const struct v4l2_async_notifier_operations imx_media_notifier_ops = {
+	.complete = __imx_media_probe_complete,
+};
+
+static int __imx_media_dev_notifier_register(struct imx_media_dev *imxmd,
+			    const struct v4l2_async_notifier_operations *ops)
+{
+	int ret;
+
+	/* no subdevs? just bail */
+	if (list_empty(&imxmd->notifier.asd_list)) {
+		v4l2_err(&imxmd->v4l2_dev, "no subdevs\n");
+		return -ENODEV;
+	}
+
+	/* prepare the async subdev notifier and register it */
+	imxmd->notifier.ops = ops ? ops : &imx_media_notifier_ops;
+	ret = v4l2_async_nf_register(&imxmd->v4l2_dev, &imxmd->notifier);
+	if (ret) {
+		v4l2_err(&imxmd->v4l2_dev,
+			 "v4l2_async_nf_register failed with %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev Operations
  */
@@ -1200,7 +1408,7 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 		return ret;
 	}
 
-	ret = imx_media_dev_notifier_register(imxmd, NULL);
+	ret = __imx_media_dev_notifier_register(imxmd, NULL);
 	if (ret < 0) {
 		imx7_csi_media_cleanup(csi);
 		return ret;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 04/50] staging: media: imx: imx7-media-csi: Drop duplicate link creation
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (2 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 03/50] staging: media: imx: imx7-media-csi: Import notifier helpers Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 05/50] staging: media: imx: imx7-media-csi: Drop the imx_media notifier Laurent Pinchart
                   ` (48 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx_media_create_csi2_links() creates a media controller link
between the CSI-2 receiver and the next entity in the pipeline, which
can be either a video mux (handled by the video-mux driver) or the CSI
bridge itself. This isn't needed, as the link is already created either
by the video-mux driver or by the imx7-media-csi driver itself (in
imx7_csi_notify_bound()).

Drop imx_media_create_csi2_links(), which allows dropping the CSI bridge
subdev grp_id.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 31 ----------------------
 1 file changed, 31 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 708076b7045a..e2d6dabad007 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -726,34 +726,6 @@ static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n)
 	return container_of(n, struct imx_media_dev, notifier);
 }
 
-/*
- * Create the missing media links from the CSI-2 receiver.
- * Called after all async subdevs have bound.
- */
-static void imx_media_create_csi2_links(struct imx_media_dev *imxmd)
-{
-	struct v4l2_subdev *sd, *csi2 = NULL;
-
-	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
-		if (sd->grp_id == IMX_MEDIA_GRP_ID_CSI2) {
-			csi2 = sd;
-			break;
-		}
-	}
-	if (!csi2)
-		return;
-
-	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
-		/* skip if not a CSI or a CSI mux */
-		if (!(sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI) &&
-		    !(sd->grp_id & IMX_MEDIA_GRP_ID_CSI) &&
-		    !(sd->grp_id & IMX_MEDIA_GRP_ID_CSI_MUX))
-			continue;
-
-		v4l2_create_fwnode_links(csi2, sd);
-	}
-}
-
 /*
  * adds given video device to given imx-media source pad vdev list.
  * Continues upstream from the pad entity's sink pads.
@@ -883,8 +855,6 @@ static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier)
 
 	mutex_lock(&imxmd->mutex);
 
-	imx_media_create_csi2_links(imxmd);
-
 	ret = imx_media_create_pad_vdev_lists(imxmd);
 	if (ret)
 		goto unlock;
@@ -1477,7 +1447,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	csi->sd.dev = &pdev->dev;
 	csi->sd.owner = THIS_MODULE;
 	csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
-	csi->sd.grp_id = IMX_MEDIA_GRP_ID_CSI;
 	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
 
 	for (i = 0; i < IMX7_CSI_PADS_NUM; i++)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 05/50] staging: media: imx: imx7-media-csi: Drop the imx_media notifier
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (3 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 04/50] staging: media: imx: imx7-media-csi: Drop duplicate link creation Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe() Laurent Pinchart
                   ` (47 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The V4L2 async notifier embedded in the imx_media_dev structure is
triggered when the CSI bridge subdev is registered. We don't need an
async notifier for this, as we can call the .complete() handler directly
from the CSI bridge subdev .registered() handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 63 +++++++---------------
 1 file changed, 19 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index e2d6dabad007..984f7bec15af 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -721,11 +721,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
  * Temporary copy of imx_media_dev helpers
  */
 
-static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n)
-{
-	return container_of(n, struct imx_media_dev, notifier);
-}
-
 /*
  * adds given video device to given imx-media source pad vdev list.
  * Continues upstream from the pad entity's sink pads.
@@ -848,9 +843,8 @@ static int imx_media_create_pad_vdev_lists(struct imx_media_dev *imxmd)
 }
 
 /* async subdev complete notifier */
-static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier)
+static int __imx_media_probe_complete(struct imx_media_dev *imxmd)
 {
-	struct imx_media_dev *imxmd = notifier2dev(notifier);
 	int ret;
 
 	mutex_lock(&imxmd->mutex);
@@ -868,33 +862,6 @@ static int __imx_media_probe_complete(struct v4l2_async_notifier *notifier)
 	return media_device_register(&imxmd->md);
 }
 
-static const struct v4l2_async_notifier_operations imx_media_notifier_ops = {
-	.complete = __imx_media_probe_complete,
-};
-
-static int __imx_media_dev_notifier_register(struct imx_media_dev *imxmd,
-			    const struct v4l2_async_notifier_operations *ops)
-{
-	int ret;
-
-	/* no subdevs? just bail */
-	if (list_empty(&imxmd->notifier.asd_list)) {
-		v4l2_err(&imxmd->v4l2_dev, "no subdevs\n");
-		return -ENODEV;
-	}
-
-	/* prepare the async subdev notifier and register it */
-	imxmd->notifier.ops = ops ? ops : &imx_media_notifier_ops;
-	ret = v4l2_async_nf_register(&imxmd->v4l2_dev, &imxmd->notifier);
-	if (ret) {
-		v4l2_err(&imxmd->v4l2_dev,
-			 "v4l2_async_nf_register failed with %d\n", ret);
-		return ret;
-	}
-
-	return 0;
-}
-
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev Operations
  */
@@ -1247,10 +1214,12 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 
 	ret = imx_media_capture_device_register(csi->vdev,
 						MEDIA_LNK_FL_IMMUTABLE);
-	if (ret)
+	if (ret) {
 		imx_media_capture_device_remove(csi->vdev);
+		return ret;
+	}
 
-	return ret;
+	return __imx_media_probe_complete(csi->imxmd);
 }
 
 static void imx7_csi_unregistered(struct v4l2_subdev *sd)
@@ -1316,8 +1285,16 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 					       MEDIA_LNK_FL_IMMUTABLE);
 }
 
+static int imx7_csi_notify_complete(struct v4l2_async_notifier *notifier)
+{
+	struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier);
+
+	return v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev);
+}
+
 static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
 	.bound = imx7_csi_notify_bound,
+	.complete = imx7_csi_notify_complete,
 };
 
 static int imx7_csi_async_register(struct imx7_csi *csi)
@@ -1346,11 +1323,11 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 	csi->notifier.ops = &imx7_csi_notify_ops;
 
-	ret = v4l2_async_subdev_nf_register(&csi->sd, &csi->notifier);
+	ret = v4l2_async_nf_register(&csi->imxmd->v4l2_dev, &csi->notifier);
 	if (ret)
 		return ret;
 
-	return v4l2_async_register_subdev(&csi->sd);
+	return 0;
 }
 
 static void imx7_csi_media_cleanup(struct imx7_csi *csi)
@@ -1378,12 +1355,6 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 		return ret;
 	}
 
-	ret = __imx_media_dev_notifier_register(imxmd, NULL);
-	if (ret < 0) {
-		imx7_csi_media_cleanup(csi);
-		return ret;
-	}
-
 	csi->imxmd = imxmd;
 
 	return 0;
@@ -1458,6 +1429,10 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto cleanup;
 
+	ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
+	if (ret)
+		goto cleanup;
+
 	ret = imx7_csi_async_register(csi);
 	if (ret)
 		goto subdev_notifier_cleanup;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (4 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 05/50] staging: media: imx: imx7-media-csi: Drop the imx_media notifier Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 15:26   ` [PATCH v1.1 " Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 07/50] staging: media: imx: imx7-media-csi: Don't populate vdev lists Laurent Pinchart
                   ` (46 subsequent siblings)
  52 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel,
	Paul Elder

From: Paul Elder <paul.elder@ideasonboard.com>

There is a chunk of miscellaneous initializations related to the CSI
subdev and media pads directly in the probe function. Move them into the
imx7_csi_media_init() function to clean up the probe function.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 49 +++++++++++-----------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 984f7bec15af..042dd4c0cb4d 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1342,7 +1342,7 @@ static void imx7_csi_media_cleanup(struct imx7_csi *csi)
 static int imx7_csi_media_init(struct imx7_csi *csi)
 {
 	struct imx_media_dev *imxmd;
-	int ret;
+	int i, ret;
 
 	/* add media device */
 	imxmd = imx_media_dev_init(csi->dev, NULL);
@@ -1357,14 +1357,33 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 
 	csi->imxmd = imxmd;
 
-	return 0;
+	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
+	v4l2_set_subdevdata(&csi->sd, csi);
+	csi->sd.internal_ops = &imx7_csi_internal_ops;
+	csi->sd.entity.ops = &imx7_csi_entity_ops;
+	csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+	csi->sd.dev = csi->dev;
+	csi->sd.owner = THIS_MODULE;
+	csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
+	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
+
+	for (i = 0; i < IMX7_CSI_PADS_NUM; i++)
+		csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ?
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+
+	ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM,
+				     csi->pad);
+	if (ret < 0)
+		return ret;
+
+	return v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
 }
 
 static int imx7_csi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct imx7_csi *csi;
-	int i, ret;
+	int ret;
 
 	csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL);
 	if (!csi)
@@ -1410,28 +1429,9 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	if (ret)
 		goto destroy_mutex;
 
-	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
-	v4l2_set_subdevdata(&csi->sd, csi);
-	csi->sd.internal_ops = &imx7_csi_internal_ops;
-	csi->sd.entity.ops = &imx7_csi_entity_ops;
-	csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
-	csi->sd.dev = &pdev->dev;
-	csi->sd.owner = THIS_MODULE;
-	csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
-	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
-
-	for (i = 0; i < IMX7_CSI_PADS_NUM; i++)
-		csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ?
-			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
-
-	ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM,
-				     csi->pad);
-	if (ret < 0)
-		goto cleanup;
-
 	ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
 	if (ret)
-		goto cleanup;
+		goto media_cleanup;
 
 	ret = imx7_csi_async_register(csi);
 	if (ret)
@@ -1442,8 +1442,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 subdev_notifier_cleanup:
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
-
-cleanup:
+media_cleanup:
 	imx7_csi_media_cleanup(csi);
 
 destroy_mutex:
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 07/50] staging: media: imx: imx7-media-csi: Don't populate vdev lists
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (5 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 08/50] staging: media: imx: imx7-media-csi: Drop unused frame_interval Laurent Pinchart
                   ` (45 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx_media_dev framework maintains a per-pad list of connected video
devices, created once all subdevs have been bound. This is used for two
purposes, updating V4L2 control inheritance when links change, and
relaying subdev events to video nodes. None of these are used by the
imx7-media-csi driver as it implements the MC-centric approach. Drop
them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 167 +++------------------
 1 file changed, 17 insertions(+), 150 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 042dd4c0cb4d..e0b600580c21 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -717,151 +717,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-/* -----------------------------------------------------------------------------
- * Temporary copy of imx_media_dev helpers
- */
-
-/*
- * adds given video device to given imx-media source pad vdev list.
- * Continues upstream from the pad entity's sink pads.
- */
-static int imx_media_add_vdev_to_pad(struct imx_media_dev *imxmd,
-				     struct imx_media_video_dev *vdev,
-				     struct media_pad *srcpad)
-{
-	struct media_entity *entity = srcpad->entity;
-	struct imx_media_pad_vdev *pad_vdev;
-	struct list_head *pad_vdev_list;
-	struct media_link *link;
-	struct v4l2_subdev *sd;
-	int i, ret;
-
-	/* skip this entity if not a v4l2_subdev */
-	if (!is_media_entity_v4l2_subdev(entity))
-		return 0;
-
-	sd = media_entity_to_v4l2_subdev(entity);
-
-	pad_vdev_list = to_pad_vdev_list(sd, srcpad->index);
-	if (!pad_vdev_list) {
-		v4l2_warn(&imxmd->v4l2_dev, "%s:%u has no vdev list!\n",
-			  entity->name, srcpad->index);
-		/*
-		 * shouldn't happen, but no reason to fail driver load,
-		 * just skip this entity.
-		 */
-		return 0;
-	}
-
-	/* just return if we've been here before */
-	list_for_each_entry(pad_vdev, pad_vdev_list, list) {
-		if (pad_vdev->vdev == vdev)
-			return 0;
-	}
-
-	dev_dbg(imxmd->md.dev, "adding %s to pad %s:%u\n",
-		vdev->vfd->entity.name, entity->name, srcpad->index);
-
-	pad_vdev = devm_kzalloc(imxmd->md.dev, sizeof(*pad_vdev), GFP_KERNEL);
-	if (!pad_vdev)
-		return -ENOMEM;
-
-	/* attach this vdev to this pad */
-	pad_vdev->vdev = vdev;
-	list_add_tail(&pad_vdev->list, pad_vdev_list);
-
-	/* move upstream from this entity's sink pads */
-	for (i = 0; i < entity->num_pads; i++) {
-		struct media_pad *pad = &entity->pads[i];
-
-		if (!(pad->flags & MEDIA_PAD_FL_SINK))
-			continue;
-
-		list_for_each_entry(link, &entity->links, list) {
-			if (link->sink != pad)
-				continue;
-			ret = imx_media_add_vdev_to_pad(imxmd, vdev,
-							link->source);
-			if (ret)
-				return ret;
-		}
-	}
-
-	return 0;
-}
-
-/*
- * For every subdevice, allocate an array of list_head's, one list_head
- * for each pad, to hold the list of video devices reachable from that
- * pad.
- */
-static int imx_media_alloc_pad_vdev_lists(struct imx_media_dev *imxmd)
-{
-	struct list_head *vdev_lists;
-	struct media_entity *entity;
-	struct v4l2_subdev *sd;
-	int i;
-
-	list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
-		entity = &sd->entity;
-		vdev_lists = devm_kcalloc(imxmd->md.dev,
-					  entity->num_pads, sizeof(*vdev_lists),
-					  GFP_KERNEL);
-		if (!vdev_lists)
-			return -ENOMEM;
-
-		/* attach to the subdev's host private pointer */
-		sd->host_priv = vdev_lists;
-
-		for (i = 0; i < entity->num_pads; i++)
-			INIT_LIST_HEAD(to_pad_vdev_list(sd, i));
-	}
-
-	return 0;
-}
-
-/* form the vdev lists in all imx-media source pads */
-static int imx_media_create_pad_vdev_lists(struct imx_media_dev *imxmd)
-{
-	struct imx_media_video_dev *vdev;
-	struct media_link *link;
-	int ret;
-
-	ret = imx_media_alloc_pad_vdev_lists(imxmd);
-	if (ret)
-		return ret;
-
-	list_for_each_entry(vdev, &imxmd->vdev_list, list) {
-		link = list_first_entry(&vdev->vfd->entity.links,
-					struct media_link, list);
-		ret = imx_media_add_vdev_to_pad(imxmd, vdev, link->source);
-		if (ret)
-			return ret;
-	}
-
-	return 0;
-}
-
-/* async subdev complete notifier */
-static int __imx_media_probe_complete(struct imx_media_dev *imxmd)
-{
-	int ret;
-
-	mutex_lock(&imxmd->mutex);
-
-	ret = imx_media_create_pad_vdev_lists(imxmd);
-	if (ret)
-		goto unlock;
-
-	ret = v4l2_device_register_subdev_nodes(&imxmd->v4l2_dev);
-unlock:
-	mutex_unlock(&imxmd->mutex);
-	if (ret)
-		return ret;
-
-	return media_device_register(&imxmd->md);
-}
-
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev Operations
  */
@@ -1214,12 +1069,24 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 
 	ret = imx_media_capture_device_register(csi->vdev,
 						MEDIA_LNK_FL_IMMUTABLE);
-	if (ret) {
-		imx_media_capture_device_remove(csi->vdev);
-		return ret;
-	}
+	if (ret)
+		goto err_remove;
 
-	return __imx_media_probe_complete(csi->imxmd);
+	ret = v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev);
+	if (ret)
+		goto err_unreg;
+
+	ret = media_device_register(&csi->imxmd->md);
+	if (ret)
+		goto err_unreg;
+
+	return 0;
+
+err_unreg:
+	imx_media_capture_device_unregister(csi->vdev);
+err_remove:
+	imx_media_capture_device_remove(csi->vdev);
+	return ret;
 }
 
 static void imx7_csi_unregistered(struct v4l2_subdev *sd)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 08/50] staging: media: imx: imx7-media-csi: Drop unused frame_interval
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (6 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 07/50] staging: media: imx: imx7-media-csi: Don't populate vdev lists Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 09/50] staging: media: imx: imx7-media-csi: Move format init to probe time Laurent Pinchart
                   ` (44 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The frame_interval field of the imx7_csi structure is set but never
used. Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index e0b600580c21..cd063c4f3f40 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -181,7 +181,6 @@ struct imx7_csi {
 
 	struct v4l2_mbus_framefmt format_mbus[IMX7_CSI_PADS_NUM];
 	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
-	struct v4l2_fract frame_interval[IMX7_CSI_PADS_NUM];
 
 	void __iomem *regbase;
 	int irq;
@@ -1056,10 +1055,6 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 					      &csi->cc[i]);
 		if (ret < 0)
 			return ret;
-
-		/* init default frame interval */
-		csi->frame_interval[i].numerator = 1;
-		csi->frame_interval[i].denominator = 30;
 	}
 
 	csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 09/50] staging: media: imx: imx7-media-csi: Move format init to probe time
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (7 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 08/50] staging: media: imx: imx7-media-csi: Drop unused frame_interval Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 10/50] staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi Laurent Pinchart
                   ` (43 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

There's no need to wait until the subdev is registered to initialize the
active pad formats. Do so at probe time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 55 ++++++++++------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index cd063c4f3f40..d85b5ab204df 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -763,26 +763,6 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 	return ret;
 }
 
-static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
-			     struct v4l2_subdev_state *sd_state)
-{
-	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct v4l2_mbus_framefmt *mf;
-	int ret;
-	int i;
-
-	for (i = 0; i < IMX7_CSI_PADS_NUM; i++) {
-		mf = v4l2_subdev_get_try_format(sd, sd_state, i);
-
-		ret = imx_media_init_mbus_fmt(mf, 800, 600, 0, V4L2_FIELD_NONE,
-					      &csi->cc[i]);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
 static struct v4l2_mbus_framefmt *
 imx7_csi_get_format(struct imx7_csi *csi,
 		    struct v4l2_subdev_state *sd_state,
@@ -795,6 +775,28 @@ imx7_csi_get_format(struct imx7_csi *csi,
 	return &csi->format_mbus[pad];
 }
 
+static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
+			     struct v4l2_subdev_state *sd_state)
+{
+	const enum v4l2_subdev_format_whence which =
+		sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
+	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
+	int ret;
+	int i;
+
+	for (i = 0; i < IMX7_CSI_PADS_NUM; i++) {
+		struct v4l2_mbus_framefmt *mf =
+			imx7_csi_get_format(csi, sd_state, i, which);
+
+		ret = imx_media_init_mbus_fmt(mf, 800, 600, 0, V4L2_FIELD_NONE,
+					      &csi->cc[i]);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,
 				   struct v4l2_subdev_state *sd_state,
 				   struct v4l2_subdev_mbus_code_enum *code)
@@ -1046,16 +1048,6 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 	int ret;
-	int i;
-
-	for (i = 0; i < IMX7_CSI_PADS_NUM; i++) {
-		/* set a default mbus format  */
-		ret = imx_media_init_mbus_fmt(&csi->format_mbus[i],
-					      800, 600, 0, V4L2_FIELD_NONE,
-					      &csi->cc[i]);
-		if (ret < 0)
-			return ret;
-	}
 
 	csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
 						  IMX7_CSI_PAD_SRC, false);
@@ -1291,7 +1283,8 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	if (ret)
 		goto destroy_mutex;
 
-	ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
+	/* Set the default mbus formats. */
+	ret = imx7_csi_init_cfg(&csi->sd, NULL);
 	if (ret)
 		goto media_cleanup;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 10/50] staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (8 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 09/50] staging: media: imx: imx7-media-csi: Move format init to probe time Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 11/50] staging: media: imx: imx7-media-csi: Import video device helpers Laurent Pinchart
                   ` (42 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel,
	Paul Elder

From: Paul Elder <paul.elder@ideasonboard.com>

imx_media_of_add_csi() from imx-media-of.c validates that the fwnode for
the CSI bridge is enabled, and adds the fwnode to the async notifier of
the imxmd. The former is redundant, as if the CSI bridge driver probes,
clearly it is enabled in the DT. The latter is not needed as the imxmd
notifier isn't used anymore. The call is thus not needed and can be
dropped. This removes the dependency of imx7-media-csi.c on
imx-media-of.c.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index d85b5ab204df..e7dcb602afae 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1203,12 +1203,6 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 	if (IS_ERR(imxmd))
 		return PTR_ERR(imxmd);
 
-	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
-	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
-		imx7_csi_media_cleanup(csi);
-		return ret;
-	}
-
 	csi->imxmd = imxmd;
 
 	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 11/50] staging: media: imx: imx7-media-csi: Import video device helpers
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (9 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 10/50] staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 12/50] staging: media: imx: imx7-media-csi: Drop legacy video device support Laurent Pinchart
                   ` (41 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

To prepare for code refactoring, copy the video device helper code used
by this driver verbatim from imx-media-capture. Rename some functions to
avoid name clashes, and leave the legacy ioctls out as they're not used
by the imx7-media-csi driver. No functional change included.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 712 ++++++++++++++++++++-
 1 file changed, 702 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index e7dcb602afae..63f291684e79 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -17,11 +17,15 @@
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
 #include <linux/types.h>
 
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-fwnode.h>
+#include <media/v4l2-ioctl.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
 #include <media/videobuf2-dma-contig.h>
@@ -335,6 +339,9 @@ static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 		imx7_csi_reg_write(csi, phys, CSI_CSIDMASA_FB1);
 }
 
+static struct imx_media_buffer *
+imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev);
+
 static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = csi->vdev;
@@ -344,7 +351,7 @@ static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 	int i;
 
 	for (i = 0; i < 2; i++) {
-		buf = imx_media_capture_device_next_buf(vdev);
+		buf = imx7_media_capture_device_next_buf(vdev);
 		if (buf) {
 			csi->active_vb2_buf[i] = buf;
 			vb2_buf = &buf->vbuf.vb2_buf;
@@ -646,7 +653,7 @@ static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 	csi->frame_sequence++;
 
 	/* get next queued buffer */
-	next = imx_media_capture_device_next_buf(vdev);
+	next = imx7_media_capture_device_next_buf(vdev);
 	if (next) {
 		phys = vb2_dma_contig_plane_dma_addr(&next->vbuf.vb2_buf, 0);
 		csi->active_vb2_buf[csi->buf_num] = next;
@@ -716,6 +723,691 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+/* -----------------------------------------------------------------------------
+ * Video Capture Device
+ */
+
+#define IMX_CAPTURE_NAME "imx-capture"
+
+struct capture_priv {
+	struct imx_media_dev *md;		/* Media device */
+	struct device *dev;			/* Physical device */
+
+	struct imx_media_video_dev vdev;	/* Video device */
+	struct media_pad vdev_pad;		/* Video device pad */
+
+	struct v4l2_subdev *src_sd;		/* Source subdev */
+	int src_sd_pad;				/* Source subdev pad */
+
+	struct mutex mutex;			/* Protect vdev operations */
+
+	struct vb2_queue q;			/* The videobuf2 queue */
+	struct list_head ready_q;		/* List of queued buffers */
+	spinlock_t q_lock;			/* Protect ready_q */
+
+	struct v4l2_ctrl_handler ctrl_hdlr;	/* Controls inherited from subdevs */
+
+	bool legacy_api;			/* Use the legacy (pre-MC) API */
+};
+
+#define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
+
+/* In bytes, per queue */
+#define VID_MEM_LIMIT	SZ_64M
+
+/* -----------------------------------------------------------------------------
+ * Video Capture Device - IOCTLs
+ */
+
+static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
+{
+	const struct imx_media_pixfmt *cc;
+
+	cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
+	if (cc) {
+		enum imx_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
+					    ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
+
+		cc = imx_media_find_pixel_format(fourcc, fmt_sel);
+		if (!cc) {
+			imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
+			cc = imx_media_find_pixel_format(fourcc, fmt_sel);
+		}
+
+		return cc;
+	}
+
+	return imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
+}
+
+static int capture_querycap(struct file *file, void *fh,
+			    struct v4l2_capability *cap)
+{
+	struct capture_priv *priv = video_drvdata(file);
+
+	strscpy(cap->driver, IMX_CAPTURE_NAME, sizeof(cap->driver));
+	strscpy(cap->card, IMX_CAPTURE_NAME, sizeof(cap->card));
+	snprintf(cap->bus_info, sizeof(cap->bus_info),
+		 "platform:%s", dev_name(priv->dev));
+
+	return 0;
+}
+
+static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
+				    struct v4l2_fmtdesc *f)
+{
+	return imx_media_enum_pixel_formats(&f->pixelformat, f->index,
+					    PIXFMT_SEL_ANY, f->mbus_code);
+}
+
+static int capture_enum_framesizes(struct file *file, void *fh,
+				   struct v4l2_frmsizeenum *fsize)
+{
+	const struct imx_media_pixfmt *cc;
+
+	if (fsize->index > 0)
+		return -EINVAL;
+
+	cc = imx_media_find_pixel_format(fsize->pixel_format, PIXFMT_SEL_ANY);
+	if (!cc)
+		return -EINVAL;
+
+	/*
+	 * TODO: The constraints are hardware-specific and may depend on the
+	 * pixel format. This should come from the driver using
+	 * imx_media_capture.
+	 */
+	fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
+	fsize->stepwise.min_width = 1;
+	fsize->stepwise.max_width = 65535;
+	fsize->stepwise.min_height = 1;
+	fsize->stepwise.max_height = 65535;
+	fsize->stepwise.step_width = 1;
+	fsize->stepwise.step_height = 1;
+
+	return 0;
+}
+
+static int capture_g_fmt_vid_cap(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct capture_priv *priv = video_drvdata(file);
+
+	f->fmt.pix = priv->vdev.fmt;
+
+	return 0;
+}
+
+static const struct imx_media_pixfmt *
+__capture_try_fmt(struct v4l2_pix_format *pixfmt, struct v4l2_rect *compose)
+{
+	struct v4l2_mbus_framefmt fmt_src;
+	const struct imx_media_pixfmt *cc;
+
+	/*
+	 * Find the pixel format, default to the first supported format if not
+	 * found.
+	 */
+	cc = imx_media_find_pixel_format(pixfmt->pixelformat, PIXFMT_SEL_ANY);
+	if (!cc) {
+		imx_media_enum_pixel_formats(&pixfmt->pixelformat, 0,
+					     PIXFMT_SEL_ANY, 0);
+		cc = imx_media_find_pixel_format(pixfmt->pixelformat,
+						 PIXFMT_SEL_ANY);
+	}
+
+	/* Allow IDMAC interweave but enforce field order from source. */
+	if (V4L2_FIELD_IS_INTERLACED(pixfmt->field)) {
+		switch (pixfmt->field) {
+		case V4L2_FIELD_SEQ_TB:
+			pixfmt->field = V4L2_FIELD_INTERLACED_TB;
+			break;
+		case V4L2_FIELD_SEQ_BT:
+			pixfmt->field = V4L2_FIELD_INTERLACED_BT;
+			break;
+		default:
+			break;
+		}
+	}
+
+	v4l2_fill_mbus_format(&fmt_src, pixfmt, 0);
+	imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
+
+	if (compose) {
+		compose->width = fmt_src.width;
+		compose->height = fmt_src.height;
+	}
+
+	return cc;
+}
+
+static int capture_try_fmt_vid_cap(struct file *file, void *fh,
+				   struct v4l2_format *f)
+{
+	__capture_try_fmt(&f->fmt.pix, NULL);
+	return 0;
+}
+
+static int capture_s_fmt_vid_cap(struct file *file, void *fh,
+				 struct v4l2_format *f)
+{
+	struct capture_priv *priv = video_drvdata(file);
+	const struct imx_media_pixfmt *cc;
+
+	if (vb2_is_busy(&priv->q)) {
+		dev_err(priv->dev, "%s queue busy\n", __func__);
+		return -EBUSY;
+	}
+
+	cc = __capture_try_fmt(&f->fmt.pix, &priv->vdev.compose);
+
+	priv->vdev.cc = cc;
+	priv->vdev.fmt = f->fmt.pix;
+
+	return 0;
+}
+
+static int capture_g_selection(struct file *file, void *fh,
+			       struct v4l2_selection *s)
+{
+	struct capture_priv *priv = video_drvdata(file);
+
+	switch (s->target) {
+	case V4L2_SEL_TGT_COMPOSE:
+	case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+		/* The compose rectangle is fixed to the source format. */
+		s->r = priv->vdev.compose;
+		break;
+	case V4L2_SEL_TGT_COMPOSE_PADDED:
+		/*
+		 * The hardware writes with a configurable but fixed DMA burst
+		 * size. If the source format width is not burst size aligned,
+		 * the written frame contains padding to the right.
+		 */
+		s->r.left = 0;
+		s->r.top = 0;
+		s->r.width = priv->vdev.fmt.width;
+		s->r.height = priv->vdev.fmt.height;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int capture_subscribe_event(struct v4l2_fh *fh,
+				   const struct v4l2_event_subscription *sub)
+{
+	switch (sub->type) {
+	case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR:
+		return v4l2_event_subscribe(fh, sub, 0, NULL);
+	default:
+		return -EINVAL;
+	}
+}
+
+static const struct v4l2_ioctl_ops capture_ioctl_ops = {
+	.vidioc_querycap		= capture_querycap,
+
+	.vidioc_enum_fmt_vid_cap	= capture_enum_fmt_vid_cap,
+	.vidioc_enum_framesizes		= capture_enum_framesizes,
+
+	.vidioc_g_fmt_vid_cap		= capture_g_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap		= capture_try_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap		= capture_s_fmt_vid_cap,
+
+	.vidioc_g_selection		= capture_g_selection,
+
+	.vidioc_reqbufs			= vb2_ioctl_reqbufs,
+	.vidioc_create_bufs		= vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf		= vb2_ioctl_prepare_buf,
+	.vidioc_querybuf		= vb2_ioctl_querybuf,
+	.vidioc_qbuf			= vb2_ioctl_qbuf,
+	.vidioc_dqbuf			= vb2_ioctl_dqbuf,
+	.vidioc_expbuf			= vb2_ioctl_expbuf,
+	.vidioc_streamon		= vb2_ioctl_streamon,
+	.vidioc_streamoff		= vb2_ioctl_streamoff,
+
+	.vidioc_subscribe_event		= capture_subscribe_event,
+	.vidioc_unsubscribe_event	= v4l2_event_unsubscribe,
+};
+
+/* -----------------------------------------------------------------------------
+ * Video Capture Device - Queue Operations
+ */
+
+static int capture_queue_setup(struct vb2_queue *vq,
+			       unsigned int *nbuffers,
+			       unsigned int *nplanes,
+			       unsigned int sizes[],
+			       struct device *alloc_devs[])
+{
+	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct v4l2_pix_format *pix = &priv->vdev.fmt;
+	unsigned int count = *nbuffers;
+
+	if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
+	if (*nplanes) {
+		if (*nplanes != 1 || sizes[0] < pix->sizeimage)
+			return -EINVAL;
+		count += vq->num_buffers;
+	}
+
+	count = min_t(__u32, VID_MEM_LIMIT / pix->sizeimage, count);
+
+	if (*nplanes)
+		*nbuffers = (count < vq->num_buffers) ? 0 :
+			count - vq->num_buffers;
+	else
+		*nbuffers = count;
+
+	*nplanes = 1;
+	sizes[0] = pix->sizeimage;
+
+	return 0;
+}
+
+static int capture_buf_init(struct vb2_buffer *vb)
+{
+	struct imx_media_buffer *buf = to_imx_media_vb(vb);
+
+	INIT_LIST_HEAD(&buf->list);
+
+	return 0;
+}
+
+static int capture_buf_prepare(struct vb2_buffer *vb)
+{
+	struct vb2_queue *vq = vb->vb2_queue;
+	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct v4l2_pix_format *pix = &priv->vdev.fmt;
+
+	if (vb2_plane_size(vb, 0) < pix->sizeimage) {
+		dev_err(priv->dev,
+			"data will not fit into plane (%lu < %lu)\n",
+			vb2_plane_size(vb, 0), (long)pix->sizeimage);
+		return -EINVAL;
+	}
+
+	vb2_set_plane_payload(vb, 0, pix->sizeimage);
+
+	return 0;
+}
+
+static void capture_buf_queue(struct vb2_buffer *vb)
+{
+	struct capture_priv *priv = vb2_get_drv_priv(vb->vb2_queue);
+	struct imx_media_buffer *buf = to_imx_media_vb(vb);
+	unsigned long flags;
+
+	spin_lock_irqsave(&priv->q_lock, flags);
+
+	list_add_tail(&buf->list, &priv->ready_q);
+
+	spin_unlock_irqrestore(&priv->q_lock, flags);
+}
+
+static int capture_validate_fmt(struct capture_priv *priv)
+{
+	struct v4l2_subdev_format fmt_src;
+	const struct imx_media_pixfmt *cc;
+	int ret;
+
+	/* Retrieve the media bus format on the source subdev. */
+	fmt_src.pad = priv->src_sd_pad;
+	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
+	if (ret)
+		return ret;
+
+	/*
+	 * Verify that the media bus size matches the size set on the video
+	 * node. It is sufficient to check the compose rectangle size without
+	 * checking the rounded size from vdev.fmt, as the rounded size is
+	 * derived directly from the compose rectangle size, and will thus
+	 * always match if the compose rectangle matches.
+	 */
+	if (priv->vdev.compose.width != fmt_src.format.width ||
+	    priv->vdev.compose.height != fmt_src.format.height)
+		return -EPIPE;
+
+	/*
+	 * Verify that the media bus code is compatible with the pixel format
+	 * set on the video node.
+	 */
+	cc = capture_find_format(fmt_src.format.code, 0);
+	if (!cc || priv->vdev.cc->cs != cc->cs)
+		return -EPIPE;
+
+	return 0;
+}
+
+static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
+{
+	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct imx_media_buffer *buf, *tmp;
+	unsigned long flags;
+	int ret;
+
+	ret = capture_validate_fmt(priv);
+	if (ret) {
+		dev_err(priv->dev, "capture format not valid\n");
+		goto return_bufs;
+	}
+
+	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
+					    true);
+	if (ret) {
+		dev_err(priv->dev, "pipeline start failed with %d\n", ret);
+		goto return_bufs;
+	}
+
+	return 0;
+
+return_bufs:
+	spin_lock_irqsave(&priv->q_lock, flags);
+	list_for_each_entry_safe(buf, tmp, &priv->ready_q, list) {
+		list_del(&buf->list);
+		vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);
+	}
+	spin_unlock_irqrestore(&priv->q_lock, flags);
+	return ret;
+}
+
+static void capture_stop_streaming(struct vb2_queue *vq)
+{
+	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct imx_media_buffer *frame;
+	struct imx_media_buffer *tmp;
+	unsigned long flags;
+	int ret;
+
+	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
+					    false);
+	if (ret)
+		dev_warn(priv->dev, "pipeline stop failed with %d\n", ret);
+
+	/* release all active buffers */
+	spin_lock_irqsave(&priv->q_lock, flags);
+	list_for_each_entry_safe(frame, tmp, &priv->ready_q, list) {
+		list_del(&frame->list);
+		vb2_buffer_done(&frame->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
+	}
+	spin_unlock_irqrestore(&priv->q_lock, flags);
+}
+
+static const struct vb2_ops capture_qops = {
+	.queue_setup	 = capture_queue_setup,
+	.buf_init        = capture_buf_init,
+	.buf_prepare	 = capture_buf_prepare,
+	.buf_queue	 = capture_buf_queue,
+	.wait_prepare	 = vb2_ops_wait_prepare,
+	.wait_finish	 = vb2_ops_wait_finish,
+	.start_streaming = capture_start_streaming,
+	.stop_streaming  = capture_stop_streaming,
+};
+
+/* -----------------------------------------------------------------------------
+ * Video Capture Device - File Operations
+ */
+
+static int capture_open(struct file *file)
+{
+	struct capture_priv *priv = video_drvdata(file);
+	struct video_device *vfd = priv->vdev.vfd;
+	int ret;
+
+	if (mutex_lock_interruptible(&priv->mutex))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret) {
+		dev_err(priv->dev, "v4l2_fh_open failed\n");
+		goto out;
+	}
+
+	ret = v4l2_pipeline_pm_get(&vfd->entity);
+	if (ret)
+		v4l2_fh_release(file);
+
+out:
+	mutex_unlock(&priv->mutex);
+	return ret;
+}
+
+static int capture_release(struct file *file)
+{
+	struct capture_priv *priv = video_drvdata(file);
+	struct video_device *vfd = priv->vdev.vfd;
+	struct vb2_queue *vq = &priv->q;
+
+	mutex_lock(&priv->mutex);
+
+	if (file->private_data == vq->owner) {
+		vb2_queue_release(vq);
+		vq->owner = NULL;
+	}
+
+	v4l2_pipeline_pm_put(&vfd->entity);
+
+	v4l2_fh_release(file);
+	mutex_unlock(&priv->mutex);
+	return 0;
+}
+
+static const struct v4l2_file_operations capture_fops = {
+	.owner		= THIS_MODULE,
+	.open		= capture_open,
+	.release	= capture_release,
+	.poll		= vb2_fop_poll,
+	.unlocked_ioctl	= video_ioctl2,
+	.mmap		= vb2_fop_mmap,
+};
+
+/* -----------------------------------------------------------------------------
+ * Video Capture Device - Init & Cleanup
+ */
+
+static struct imx_media_buffer *
+imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
+{
+	struct capture_priv *priv = to_capture_priv(vdev);
+	struct imx_media_buffer *buf = NULL;
+	unsigned long flags;
+
+	spin_lock_irqsave(&priv->q_lock, flags);
+
+	/* get next queued buffer */
+	if (!list_empty(&priv->ready_q)) {
+		buf = list_entry(priv->ready_q.next, struct imx_media_buffer,
+				 list);
+		list_del(&buf->list);
+	}
+
+	spin_unlock_irqrestore(&priv->q_lock, flags);
+
+	return buf;
+}
+
+static int capture_init_format(struct capture_priv *priv)
+{
+	struct v4l2_subdev_format fmt_src = {
+		.pad = priv->src_sd_pad,
+		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+	};
+	struct imx_media_video_dev *vdev = &priv->vdev;
+	int ret;
+
+	if (priv->legacy_api) {
+		ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL,
+				       &fmt_src);
+		if (ret) {
+			dev_err(priv->dev, "failed to get source format\n");
+			return ret;
+		}
+	} else {
+		fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
+		fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
+		fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
+	}
+
+	imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt, &fmt_src.format, NULL);
+	vdev->compose.width = fmt_src.format.width;
+	vdev->compose.height = fmt_src.format.height;
+
+	vdev->cc = imx_media_find_pixel_format(vdev->fmt.pixelformat,
+					       PIXFMT_SEL_ANY);
+
+	return 0;
+}
+
+static int imx7_media_capture_device_register(struct imx_media_video_dev *vdev,
+					      u32 link_flags)
+{
+	struct capture_priv *priv = to_capture_priv(vdev);
+	struct v4l2_subdev *sd = priv->src_sd;
+	struct v4l2_device *v4l2_dev = sd->v4l2_dev;
+	struct video_device *vfd = vdev->vfd;
+	int ret;
+
+	/* get media device */
+	priv->md = container_of(v4l2_dev->mdev, struct imx_media_dev, md);
+
+	vfd->v4l2_dev = v4l2_dev;
+
+	/* Initialize the default format and compose rectangle. */
+	ret = capture_init_format(priv);
+	if (ret < 0)
+		return ret;
+
+	/* Register the video device. */
+	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
+	if (ret) {
+		dev_err(priv->dev, "Failed to register video device\n");
+		return ret;
+	}
+
+	dev_info(priv->dev, "Registered %s as /dev/%s\n", vfd->name,
+		 video_device_node_name(vfd));
+
+	/* Create the link from the src_sd devnode pad to device node. */
+	if (link_flags & MEDIA_LNK_FL_IMMUTABLE)
+		link_flags |= MEDIA_LNK_FL_ENABLED;
+	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
+				    &vfd->entity, 0, link_flags);
+	if (ret) {
+		dev_err(priv->dev, "failed to create link to device node\n");
+		video_unregister_device(vfd);
+		return ret;
+	}
+
+	/* Add vdev to the video devices list. */
+	imx_media_add_video_device(priv->md, vdev);
+
+	return 0;
+}
+
+static void imx7_media_capture_device_unregister(struct imx_media_video_dev *vdev)
+{
+	struct capture_priv *priv = to_capture_priv(vdev);
+	struct video_device *vfd = priv->vdev.vfd;
+
+	media_entity_cleanup(&vfd->entity);
+	video_unregister_device(vfd);
+}
+
+static struct imx_media_video_dev *
+imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
+			       int pad, bool legacy_api)
+{
+	struct capture_priv *priv;
+	struct video_device *vfd;
+	struct vb2_queue *vq;
+	int ret;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return ERR_PTR(-ENOMEM);
+
+	priv->src_sd = src_sd;
+	priv->src_sd_pad = pad;
+	priv->dev = dev;
+	priv->legacy_api = legacy_api;
+
+	mutex_init(&priv->mutex);
+	INIT_LIST_HEAD(&priv->ready_q);
+	spin_lock_init(&priv->q_lock);
+
+	/* Allocate and initialize the video device. */
+	vfd = video_device_alloc();
+	if (!vfd)
+		return ERR_PTR(-ENOMEM);
+
+	vfd->fops = &capture_fops;
+	vfd->ioctl_ops = &capture_ioctl_ops;
+	vfd->minor = -1;
+	vfd->release = video_device_release;
+	vfd->vfl_dir = VFL_DIR_RX;
+	vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
+	vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
+			 | (!legacy_api ? V4L2_CAP_IO_MC : 0);
+	vfd->lock = &priv->mutex;
+	vfd->queue = &priv->q;
+
+	snprintf(vfd->name, sizeof(vfd->name), "%s capture", src_sd->name);
+
+	video_set_drvdata(vfd, priv);
+	priv->vdev.vfd = vfd;
+	INIT_LIST_HEAD(&priv->vdev.list);
+
+	/* Initialize the video device pad. */
+	priv->vdev_pad.flags = MEDIA_PAD_FL_SINK;
+	ret = media_entity_pads_init(&vfd->entity, 1, &priv->vdev_pad);
+	if (ret) {
+		video_device_release(vfd);
+		return ERR_PTR(ret);
+	}
+
+	/* Initialize the vb2 queue. */
+	vq = &priv->q;
+	vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	vq->io_modes = VB2_MMAP | VB2_DMABUF;
+	vq->drv_priv = priv;
+	vq->buf_struct_size = sizeof(struct imx_media_buffer);
+	vq->ops = &capture_qops;
+	vq->mem_ops = &vb2_dma_contig_memops;
+	vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+	vq->lock = &priv->mutex;
+	vq->min_buffers_needed = 2;
+	vq->dev = priv->dev;
+
+	ret = vb2_queue_init(vq);
+	if (ret) {
+		dev_err(priv->dev, "vb2_queue_init failed\n");
+		video_device_release(vfd);
+		return ERR_PTR(ret);
+	}
+
+	if (legacy_api) {
+		/* Initialize the control handler. */
+		v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
+		vfd->ctrl_handler = &priv->ctrl_hdlr;
+	}
+
+	return &priv->vdev;
+}
+
+static void imx7_media_capture_device_remove(struct imx_media_video_dev *vdev)
+{
+	struct capture_priv *priv = to_capture_priv(vdev);
+
+	v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
+}
+
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev Operations
  */
@@ -1049,13 +1741,13 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 	int ret;
 
-	csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
-						  IMX7_CSI_PAD_SRC, false);
+	csi->vdev = imx7_media_capture_device_init(csi->sd.dev, &csi->sd,
+						   IMX7_CSI_PAD_SRC, false);
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-	ret = imx_media_capture_device_register(csi->vdev,
-						MEDIA_LNK_FL_IMMUTABLE);
+	ret = imx7_media_capture_device_register(csi->vdev,
+						 MEDIA_LNK_FL_IMMUTABLE);
 	if (ret)
 		goto err_remove;
 
@@ -1070,9 +1762,9 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	return 0;
 
 err_unreg:
-	imx_media_capture_device_unregister(csi->vdev);
+	imx7_media_capture_device_unregister(csi->vdev);
 err_remove:
-	imx_media_capture_device_remove(csi->vdev);
+	imx7_media_capture_device_remove(csi->vdev);
 	return ret;
 }
 
@@ -1080,8 +1772,8 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 
-	imx_media_capture_device_unregister(csi->vdev);
-	imx_media_capture_device_remove(csi->vdev);
+	imx7_media_capture_device_unregister(csi->vdev);
+	imx7_media_capture_device_remove(csi->vdev);
 }
 
 static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 12/50] staging: media: imx: imx7-media-csi: Drop legacy video device support
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (10 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 11/50] staging: media: imx: imx7-media-csi: Import video device helpers Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 13/50] staging: media: imx: imx7-media-csi: Drop unused controls support Laurent Pinchart
                   ` (40 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Drop all the code related to the unused (by this driver) legacy video
device support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 31 +++++-----------------
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 63f291684e79..2e314ce961dc 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -746,8 +746,6 @@ struct capture_priv {
 	spinlock_t q_lock;			/* Protect ready_q */
 
 	struct v4l2_ctrl_handler ctrl_hdlr;	/* Controls inherited from subdevs */
-
-	bool legacy_api;			/* Use the legacy (pre-MC) API */
 };
 
 #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
@@ -1240,20 +1238,10 @@ static int capture_init_format(struct capture_priv *priv)
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
 	struct imx_media_video_dev *vdev = &priv->vdev;
-	int ret;
 
-	if (priv->legacy_api) {
-		ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL,
-				       &fmt_src);
-		if (ret) {
-			dev_err(priv->dev, "failed to get source format\n");
-			return ret;
-		}
-	} else {
-		fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
-		fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
-		fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
-	}
+	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
+	fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
+	fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
 
 	imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt, &fmt_src.format, NULL);
 	vdev->compose.width = fmt_src.format.width;
@@ -1322,7 +1310,7 @@ static void imx7_media_capture_device_unregister(struct imx_media_video_dev *vde
 
 static struct imx_media_video_dev *
 imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
-			       int pad, bool legacy_api)
+			       int pad)
 {
 	struct capture_priv *priv;
 	struct video_device *vfd;
@@ -1336,7 +1324,6 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	priv->src_sd = src_sd;
 	priv->src_sd_pad = pad;
 	priv->dev = dev;
-	priv->legacy_api = legacy_api;
 
 	mutex_init(&priv->mutex);
 	INIT_LIST_HEAD(&priv->ready_q);
@@ -1354,7 +1341,7 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	vfd->vfl_dir = VFL_DIR_RX;
 	vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
 	vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
-			 | (!legacy_api ? V4L2_CAP_IO_MC : 0);
+			 | V4L2_CAP_IO_MC;
 	vfd->lock = &priv->mutex;
 	vfd->queue = &priv->q;
 
@@ -1392,12 +1379,6 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 		return ERR_PTR(ret);
 	}
 
-	if (legacy_api) {
-		/* Initialize the control handler. */
-		v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
-		vfd->ctrl_handler = &priv->ctrl_hdlr;
-	}
-
 	return &priv->vdev;
 }
 
@@ -1742,7 +1723,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	int ret;
 
 	csi->vdev = imx7_media_capture_device_init(csi->sd.dev, &csi->sd,
-						   IMX7_CSI_PAD_SRC, false);
+						   IMX7_CSI_PAD_SRC);
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 13/50] staging: media: imx: imx7-media-csi: Drop unused controls support
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (11 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 12/50] staging: media: imx: imx7-media-csi: Drop legacy video device support Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 14/50] staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure Laurent Pinchart
                   ` (39 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Drop the unused control handler from the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 2e314ce961dc..499bb74ad6f3 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -21,7 +21,6 @@
 #include <linux/spinlock.h>
 #include <linux/types.h>
 
-#include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-fwnode.h>
@@ -744,8 +743,6 @@ struct capture_priv {
 	struct vb2_queue q;			/* The videobuf2 queue */
 	struct list_head ready_q;		/* List of queued buffers */
 	spinlock_t q_lock;			/* Protect ready_q */
-
-	struct v4l2_ctrl_handler ctrl_hdlr;	/* Controls inherited from subdevs */
 };
 
 #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
@@ -1382,13 +1379,6 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	return &priv->vdev;
 }
 
-static void imx7_media_capture_device_remove(struct imx_media_video_dev *vdev)
-{
-	struct capture_priv *priv = to_capture_priv(vdev);
-
-	v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
-}
-
 /* -----------------------------------------------------------------------------
  * V4L2 Subdev Operations
  */
@@ -1730,7 +1720,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	ret = imx7_media_capture_device_register(csi->vdev,
 						 MEDIA_LNK_FL_IMMUTABLE);
 	if (ret)
-		goto err_remove;
+		return ret;
 
 	ret = v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev);
 	if (ret)
@@ -1744,8 +1734,6 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 
 err_unreg:
 	imx7_media_capture_device_unregister(csi->vdev);
-err_remove:
-	imx7_media_capture_device_remove(csi->vdev);
 	return ret;
 }
 
@@ -1754,7 +1742,6 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 
 	imx7_media_capture_device_unregister(csi->vdev);
-	imx7_media_capture_device_remove(csi->vdev);
 }
 
 static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 14/50] staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (12 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 13/50] staging: media: imx: imx7-media-csi: Drop unused controls support Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 15/50] staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi Laurent Pinchart
                   ` (38 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The struct imx7_csi fields are in a random order, reorganize them
logically to prepare for adding new fields.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 36 ++++++++++++----------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 499bb74ad6f3..ad69c2e8dbc2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -169,37 +169,41 @@ enum imx_csi_model {
 
 struct imx7_csi {
 	struct device *dev;
-	struct v4l2_subdev sd;
+
+	/* Resources and locks */
+	void __iomem *regbase;
+	int irq;
+	struct clk *mclk;
+
+	struct mutex lock; /* Protects is_streaming, format_mbus, cc */
+	spinlock_t irqlock; /* Protects last_eof */
+
+	/* Media and V4L2 device */
+	struct imx_media_dev *imxmd;
 	struct v4l2_async_notifier notifier;
-	struct imx_media_video_dev *vdev;
-	struct imx_media_dev *imxmd;
-	struct media_pad pad[IMX7_CSI_PADS_NUM];
-
-	/* lock to protect members below */
-	struct mutex lock;
-	/* lock to protect irq handler when stop streaming */
-	spinlock_t irqlock;
 
 	struct v4l2_subdev *src_sd;
+	bool is_csi2;
+
+	/* V4L2 subdev */
+	struct v4l2_subdev sd;
+	struct media_pad pad[IMX7_CSI_PADS_NUM];
 
 	struct v4l2_mbus_framefmt format_mbus[IMX7_CSI_PADS_NUM];
 	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
 
-	void __iomem *regbase;
-	int irq;
-	struct clk *mclk;
+	/* Video device */
+	struct imx_media_video_dev *vdev;
 
-	/* active vb2 buffers to send to video dev sink */
+	/* Buffers and streaming state */
 	struct imx_media_buffer *active_vb2_buf[2];
 	struct imx_media_dma_buf underrun_buf;
 
+	bool is_streaming;
 	int buf_num;
 	u32 frame_sequence;
 
 	bool last_eof;
-	bool is_streaming;
-	bool is_csi2;
-
 	struct completion last_eof_completion;
 
 	enum imx_csi_model model;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 15/50] staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (13 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 14/50] staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 16/50] staging: media: imx: imx7-media-csi: Ensure consistent function prefix Laurent Pinchart
                   ` (37 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Merge the capture_priv fields in the imx7_csi structure as there's no
more need to have two separate structures. Update all the users
accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 271 +++++++++------------
 1 file changed, 117 insertions(+), 154 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ad69c2e8dbc2..9b4463e456c2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -193,7 +193,14 @@ struct imx7_csi {
 	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
 
 	/* Video device */
-	struct imx_media_video_dev *vdev;
+	struct imx_media_video_dev vdev;	/* Video device */
+	struct media_pad vdev_pad;		/* Video device pad */
+
+	struct mutex vdev_mutex;		/* Protect vdev operations */
+
+	struct vb2_queue q;			/* The videobuf2 queue */
+	struct list_head ready_q;		/* List of queued buffers */
+	spinlock_t q_lock;			/* Protect ready_q */
 
 	/* Buffers and streaming state */
 	struct imx_media_buffer *active_vb2_buf[2];
@@ -343,18 +350,17 @@ static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 }
 
 static struct imx_media_buffer *
-imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev);
+imx7_media_capture_device_next_buf(struct imx7_csi *csi);
 
 static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = csi->vdev;
 	struct imx_media_buffer *buf;
 	struct vb2_buffer *vb2_buf;
 	dma_addr_t phys[2];
 	int i;
 
 	for (i = 0; i < 2; i++) {
-		buf = imx7_media_capture_device_next_buf(vdev);
+		buf = imx7_media_capture_device_next_buf(csi);
 		if (buf) {
 			csi->active_vb2_buf[i] = buf;
 			vb2_buf = &buf->vbuf.vb2_buf;
@@ -389,7 +395,7 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,
 
 static int imx7_csi_dma_setup(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = csi->vdev;
+	struct imx_media_video_dev *vdev = &csi->vdev;
 	int ret;
 
 	ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,
@@ -440,7 +446,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 
 static void imx7_csi_configure(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = csi->vdev;
+	struct imx_media_video_dev *vdev = &csi->vdev;
 	struct v4l2_pix_format *out_pix = &vdev->fmt;
 	int width = out_pix->width;
 	u32 stride = 0;
@@ -640,7 +646,7 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi)
 
 static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = csi->vdev;
+	struct imx_media_video_dev *vdev = &csi->vdev;
 	struct imx_media_buffer *done, *next;
 	struct vb2_buffer *vb;
 	dma_addr_t phys;
@@ -656,7 +662,7 @@ static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 	csi->frame_sequence++;
 
 	/* get next queued buffer */
-	next = imx7_media_capture_device_next_buf(vdev);
+	next = imx7_media_capture_device_next_buf(csi);
 	if (next) {
 		phys = vb2_dma_contig_plane_dma_addr(&next->vbuf.vb2_buf, 0);
 		csi->active_vb2_buf[csi->buf_num] = next;
@@ -732,25 +738,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 
 #define IMX_CAPTURE_NAME "imx-capture"
 
-struct capture_priv {
-	struct imx_media_dev *md;		/* Media device */
-	struct device *dev;			/* Physical device */
-
-	struct imx_media_video_dev vdev;	/* Video device */
-	struct media_pad vdev_pad;		/* Video device pad */
-
-	struct v4l2_subdev *src_sd;		/* Source subdev */
-	int src_sd_pad;				/* Source subdev pad */
-
-	struct mutex mutex;			/* Protect vdev operations */
-
-	struct vb2_queue q;			/* The videobuf2 queue */
-	struct list_head ready_q;		/* List of queued buffers */
-	spinlock_t q_lock;			/* Protect ready_q */
-};
-
-#define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
-
 /* In bytes, per queue */
 #define VID_MEM_LIMIT	SZ_64M
 
@@ -782,12 +769,12 @@ static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
 static int capture_querycap(struct file *file, void *fh,
 			    struct v4l2_capability *cap)
 {
-	struct capture_priv *priv = video_drvdata(file);
+	struct imx7_csi *csi = video_drvdata(file);
 
 	strscpy(cap->driver, IMX_CAPTURE_NAME, sizeof(cap->driver));
 	strscpy(cap->card, IMX_CAPTURE_NAME, sizeof(cap->card));
 	snprintf(cap->bus_info, sizeof(cap->bus_info),
-		 "platform:%s", dev_name(priv->dev));
+		 "platform:%s", dev_name(csi->dev));
 
 	return 0;
 }
@@ -830,9 +817,9 @@ static int capture_enum_framesizes(struct file *file, void *fh,
 static int capture_g_fmt_vid_cap(struct file *file, void *fh,
 				 struct v4l2_format *f)
 {
-	struct capture_priv *priv = video_drvdata(file);
+	struct imx7_csi *csi = video_drvdata(file);
 
-	f->fmt.pix = priv->vdev.fmt;
+	f->fmt.pix = csi->vdev.fmt;
 
 	return 0;
 }
@@ -890,18 +877,18 @@ static int capture_try_fmt_vid_cap(struct file *file, void *fh,
 static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 				 struct v4l2_format *f)
 {
-	struct capture_priv *priv = video_drvdata(file);
+	struct imx7_csi *csi = video_drvdata(file);
 	const struct imx_media_pixfmt *cc;
 
-	if (vb2_is_busy(&priv->q)) {
-		dev_err(priv->dev, "%s queue busy\n", __func__);
+	if (vb2_is_busy(&csi->q)) {
+		dev_err(csi->dev, "%s queue busy\n", __func__);
 		return -EBUSY;
 	}
 
-	cc = __capture_try_fmt(&f->fmt.pix, &priv->vdev.compose);
+	cc = __capture_try_fmt(&f->fmt.pix, &csi->vdev.compose);
 
-	priv->vdev.cc = cc;
-	priv->vdev.fmt = f->fmt.pix;
+	csi->vdev.cc = cc;
+	csi->vdev.fmt = f->fmt.pix;
 
 	return 0;
 }
@@ -909,14 +896,14 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 static int capture_g_selection(struct file *file, void *fh,
 			       struct v4l2_selection *s)
 {
-	struct capture_priv *priv = video_drvdata(file);
+	struct imx7_csi *csi = video_drvdata(file);
 
 	switch (s->target) {
 	case V4L2_SEL_TGT_COMPOSE:
 	case V4L2_SEL_TGT_COMPOSE_DEFAULT:
 	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
 		/* The compose rectangle is fixed to the source format. */
-		s->r = priv->vdev.compose;
+		s->r = csi->vdev.compose;
 		break;
 	case V4L2_SEL_TGT_COMPOSE_PADDED:
 		/*
@@ -926,8 +913,8 @@ static int capture_g_selection(struct file *file, void *fh,
 		 */
 		s->r.left = 0;
 		s->r.top = 0;
-		s->r.width = priv->vdev.fmt.width;
-		s->r.height = priv->vdev.fmt.height;
+		s->r.width = csi->vdev.fmt.width;
+		s->r.height = csi->vdev.fmt.height;
 		break;
 	default:
 		return -EINVAL;
@@ -983,8 +970,8 @@ static int capture_queue_setup(struct vb2_queue *vq,
 			       unsigned int sizes[],
 			       struct device *alloc_devs[])
 {
-	struct capture_priv *priv = vb2_get_drv_priv(vq);
-	struct v4l2_pix_format *pix = &priv->vdev.fmt;
+	struct imx7_csi *csi = vb2_get_drv_priv(vq);
+	struct v4l2_pix_format *pix = &csi->vdev.fmt;
 	unsigned int count = *nbuffers;
 
 	if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -1021,12 +1008,11 @@ static int capture_buf_init(struct vb2_buffer *vb)
 
 static int capture_buf_prepare(struct vb2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
-	struct capture_priv *priv = vb2_get_drv_priv(vq);
-	struct v4l2_pix_format *pix = &priv->vdev.fmt;
+	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
+	struct v4l2_pix_format *pix = &csi->vdev.fmt;
 
 	if (vb2_plane_size(vb, 0) < pix->sizeimage) {
-		dev_err(priv->dev,
+		dev_err(csi->dev,
 			"data will not fit into plane (%lu < %lu)\n",
 			vb2_plane_size(vb, 0), (long)pix->sizeimage);
 		return -EINVAL;
@@ -1039,27 +1025,27 @@ static int capture_buf_prepare(struct vb2_buffer *vb)
 
 static void capture_buf_queue(struct vb2_buffer *vb)
 {
-	struct capture_priv *priv = vb2_get_drv_priv(vb->vb2_queue);
+	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
 	struct imx_media_buffer *buf = to_imx_media_vb(vb);
 	unsigned long flags;
 
-	spin_lock_irqsave(&priv->q_lock, flags);
+	spin_lock_irqsave(&csi->q_lock, flags);
 
-	list_add_tail(&buf->list, &priv->ready_q);
+	list_add_tail(&buf->list, &csi->ready_q);
 
-	spin_unlock_irqrestore(&priv->q_lock, flags);
+	spin_unlock_irqrestore(&csi->q_lock, flags);
 }
 
-static int capture_validate_fmt(struct capture_priv *priv)
+static int capture_validate_fmt(struct imx7_csi *csi)
 {
 	struct v4l2_subdev_format fmt_src;
 	const struct imx_media_pixfmt *cc;
 	int ret;
 
 	/* Retrieve the media bus format on the source subdev. */
-	fmt_src.pad = priv->src_sd_pad;
+	fmt_src.pad = IMX7_CSI_PAD_SRC;
 	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-	ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
+	ret = v4l2_subdev_call(&csi->sd, pad, get_fmt, NULL, &fmt_src);
 	if (ret)
 		return ret;
 
@@ -1070,8 +1056,8 @@ static int capture_validate_fmt(struct capture_priv *priv)
 	 * derived directly from the compose rectangle size, and will thus
 	 * always match if the compose rectangle matches.
 	 */
-	if (priv->vdev.compose.width != fmt_src.format.width ||
-	    priv->vdev.compose.height != fmt_src.format.height)
+	if (csi->vdev.compose.width != fmt_src.format.width ||
+	    csi->vdev.compose.height != fmt_src.format.height)
 		return -EPIPE;
 
 	/*
@@ -1079,7 +1065,7 @@ static int capture_validate_fmt(struct capture_priv *priv)
 	 * set on the video node.
 	 */
 	cc = capture_find_format(fmt_src.format.code, 0);
-	if (!cc || priv->vdev.cc->cs != cc->cs)
+	if (!cc || csi->vdev.cc->cs != cc->cs)
 		return -EPIPE;
 
 	return 0;
@@ -1087,56 +1073,54 @@ static int capture_validate_fmt(struct capture_priv *priv)
 
 static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
-	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct imx7_csi *csi = vb2_get_drv_priv(vq);
 	struct imx_media_buffer *buf, *tmp;
 	unsigned long flags;
 	int ret;
 
-	ret = capture_validate_fmt(priv);
+	ret = capture_validate_fmt(csi);
 	if (ret) {
-		dev_err(priv->dev, "capture format not valid\n");
+		dev_err(csi->dev, "capture format not valid\n");
 		goto return_bufs;
 	}
 
-	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
-					    true);
+	ret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, true);
 	if (ret) {
-		dev_err(priv->dev, "pipeline start failed with %d\n", ret);
+		dev_err(csi->dev, "pipeline start failed with %d\n", ret);
 		goto return_bufs;
 	}
 
 	return 0;
 
 return_bufs:
-	spin_lock_irqsave(&priv->q_lock, flags);
-	list_for_each_entry_safe(buf, tmp, &priv->ready_q, list) {
+	spin_lock_irqsave(&csi->q_lock, flags);
+	list_for_each_entry_safe(buf, tmp, &csi->ready_q, list) {
 		list_del(&buf->list);
 		vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED);
 	}
-	spin_unlock_irqrestore(&priv->q_lock, flags);
+	spin_unlock_irqrestore(&csi->q_lock, flags);
 	return ret;
 }
 
 static void capture_stop_streaming(struct vb2_queue *vq)
 {
-	struct capture_priv *priv = vb2_get_drv_priv(vq);
+	struct imx7_csi *csi = vb2_get_drv_priv(vq);
 	struct imx_media_buffer *frame;
 	struct imx_media_buffer *tmp;
 	unsigned long flags;
 	int ret;
 
-	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
-					    false);
+	ret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, false);
 	if (ret)
-		dev_warn(priv->dev, "pipeline stop failed with %d\n", ret);
+		dev_warn(csi->dev, "pipeline stop failed with %d\n", ret);
 
 	/* release all active buffers */
-	spin_lock_irqsave(&priv->q_lock, flags);
-	list_for_each_entry_safe(frame, tmp, &priv->ready_q, list) {
+	spin_lock_irqsave(&csi->q_lock, flags);
+	list_for_each_entry_safe(frame, tmp, &csi->ready_q, list) {
 		list_del(&frame->list);
 		vb2_buffer_done(&frame->vbuf.vb2_buf, VB2_BUF_STATE_ERROR);
 	}
-	spin_unlock_irqrestore(&priv->q_lock, flags);
+	spin_unlock_irqrestore(&csi->q_lock, flags);
 }
 
 static const struct vb2_ops capture_qops = {
@@ -1156,16 +1140,16 @@ static const struct vb2_ops capture_qops = {
 
 static int capture_open(struct file *file)
 {
-	struct capture_priv *priv = video_drvdata(file);
-	struct video_device *vfd = priv->vdev.vfd;
+	struct imx7_csi *csi = video_drvdata(file);
+	struct video_device *vfd = csi->vdev.vfd;
 	int ret;
 
-	if (mutex_lock_interruptible(&priv->mutex))
+	if (mutex_lock_interruptible(&csi->vdev_mutex))
 		return -ERESTARTSYS;
 
 	ret = v4l2_fh_open(file);
 	if (ret) {
-		dev_err(priv->dev, "v4l2_fh_open failed\n");
+		dev_err(csi->dev, "v4l2_fh_open failed\n");
 		goto out;
 	}
 
@@ -1174,17 +1158,17 @@ static int capture_open(struct file *file)
 		v4l2_fh_release(file);
 
 out:
-	mutex_unlock(&priv->mutex);
+	mutex_unlock(&csi->vdev_mutex);
 	return ret;
 }
 
 static int capture_release(struct file *file)
 {
-	struct capture_priv *priv = video_drvdata(file);
-	struct video_device *vfd = priv->vdev.vfd;
-	struct vb2_queue *vq = &priv->q;
+	struct imx7_csi *csi = video_drvdata(file);
+	struct video_device *vfd = csi->vdev.vfd;
+	struct vb2_queue *vq = &csi->q;
 
-	mutex_lock(&priv->mutex);
+	mutex_lock(&csi->vdev_mutex);
 
 	if (file->private_data == vq->owner) {
 		vb2_queue_release(vq);
@@ -1194,7 +1178,7 @@ static int capture_release(struct file *file)
 	v4l2_pipeline_pm_put(&vfd->entity);
 
 	v4l2_fh_release(file);
-	mutex_unlock(&priv->mutex);
+	mutex_unlock(&csi->vdev_mutex);
 	return 0;
 }
 
@@ -1212,33 +1196,32 @@ static const struct v4l2_file_operations capture_fops = {
  */
 
 static struct imx_media_buffer *
-imx7_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
+imx7_media_capture_device_next_buf(struct imx7_csi *csi)
 {
-	struct capture_priv *priv = to_capture_priv(vdev);
 	struct imx_media_buffer *buf = NULL;
 	unsigned long flags;
 
-	spin_lock_irqsave(&priv->q_lock, flags);
+	spin_lock_irqsave(&csi->q_lock, flags);
 
 	/* get next queued buffer */
-	if (!list_empty(&priv->ready_q)) {
-		buf = list_entry(priv->ready_q.next, struct imx_media_buffer,
+	if (!list_empty(&csi->ready_q)) {
+		buf = list_entry(csi->ready_q.next, struct imx_media_buffer,
 				 list);
 		list_del(&buf->list);
 	}
 
-	spin_unlock_irqrestore(&priv->q_lock, flags);
+	spin_unlock_irqrestore(&csi->q_lock, flags);
 
 	return buf;
 }
 
-static int capture_init_format(struct capture_priv *priv)
+static int capture_init_format(struct imx7_csi *csi)
 {
 	struct v4l2_subdev_format fmt_src = {
-		.pad = priv->src_sd_pad,
+		.pad = IMX7_CSI_PAD_SRC,
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
-	struct imx_media_video_dev *vdev = &priv->vdev;
+	struct imx_media_video_dev *vdev = &csi->vdev;
 
 	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
 	fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
@@ -1254,86 +1237,68 @@ static int capture_init_format(struct capture_priv *priv)
 	return 0;
 }
 
-static int imx7_media_capture_device_register(struct imx_media_video_dev *vdev,
-					      u32 link_flags)
+static int imx7_media_capture_device_register(struct imx7_csi *csi)
 {
-	struct capture_priv *priv = to_capture_priv(vdev);
-	struct v4l2_subdev *sd = priv->src_sd;
+	struct v4l2_subdev *sd = &csi->sd;
 	struct v4l2_device *v4l2_dev = sd->v4l2_dev;
-	struct video_device *vfd = vdev->vfd;
+	struct video_device *vfd = csi->vdev.vfd;
 	int ret;
 
-	/* get media device */
-	priv->md = container_of(v4l2_dev->mdev, struct imx_media_dev, md);
-
 	vfd->v4l2_dev = v4l2_dev;
 
 	/* Initialize the default format and compose rectangle. */
-	ret = capture_init_format(priv);
+	ret = capture_init_format(csi);
 	if (ret < 0)
 		return ret;
 
 	/* Register the video device. */
 	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
 	if (ret) {
-		dev_err(priv->dev, "Failed to register video device\n");
+		dev_err(csi->dev, "Failed to register video device\n");
 		return ret;
 	}
 
-	dev_info(priv->dev, "Registered %s as /dev/%s\n", vfd->name,
+	dev_info(csi->dev, "Registered %s as /dev/%s\n", vfd->name,
 		 video_device_node_name(vfd));
 
-	/* Create the link from the src_sd devnode pad to device node. */
-	if (link_flags & MEDIA_LNK_FL_IMMUTABLE)
-		link_flags |= MEDIA_LNK_FL_ENABLED;
-	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
-				    &vfd->entity, 0, link_flags);
+	/* Create the link from the CSI subdev to the video device. */
+	ret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC, &vfd->entity,
+				    0, MEDIA_LNK_FL_IMMUTABLE |
+				    MEDIA_LNK_FL_ENABLED);
 	if (ret) {
-		dev_err(priv->dev, "failed to create link to device node\n");
+		dev_err(csi->dev, "failed to create link to device node\n");
 		video_unregister_device(vfd);
 		return ret;
 	}
 
 	/* Add vdev to the video devices list. */
-	imx_media_add_video_device(priv->md, vdev);
+	imx_media_add_video_device(csi->imxmd, &csi->vdev);
 
 	return 0;
 }
 
-static void imx7_media_capture_device_unregister(struct imx_media_video_dev *vdev)
+static void imx7_media_capture_device_unregister(struct imx7_csi *csi)
 {
-	struct capture_priv *priv = to_capture_priv(vdev);
-	struct video_device *vfd = priv->vdev.vfd;
+	struct video_device *vfd = csi->vdev.vfd;
 
 	media_entity_cleanup(&vfd->entity);
 	video_unregister_device(vfd);
 }
 
-static struct imx_media_video_dev *
-imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
-			       int pad)
+static int imx7_media_capture_device_init(struct imx7_csi *csi)
 {
-	struct capture_priv *priv;
 	struct video_device *vfd;
 	struct vb2_queue *vq;
 	int ret;
 
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return ERR_PTR(-ENOMEM);
-
-	priv->src_sd = src_sd;
-	priv->src_sd_pad = pad;
-	priv->dev = dev;
-
-	mutex_init(&priv->mutex);
-	INIT_LIST_HEAD(&priv->ready_q);
-	spin_lock_init(&priv->q_lock);
+	mutex_init(&csi->vdev_mutex);
+	INIT_LIST_HEAD(&csi->ready_q);
+	spin_lock_init(&csi->q_lock);
 
 	/* Allocate and initialize the video device. */
 	vfd = video_device_alloc();
 	if (!vfd)
-		return ERR_PTR(-ENOMEM);
+		return -ENOMEM;
 
 	vfd->fops = &capture_fops;
 	vfd->ioctl_ops = &capture_ioctl_ops;
@@ -1343,44 +1308,44 @@ imx7_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
 	vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
 			 | V4L2_CAP_IO_MC;
-	vfd->lock = &priv->mutex;
-	vfd->queue = &priv->q;
+	vfd->lock = &csi->vdev_mutex;
+	vfd->queue = &csi->q;
 
-	snprintf(vfd->name, sizeof(vfd->name), "%s capture", src_sd->name);
+	snprintf(vfd->name, sizeof(vfd->name), "%s capture", csi->sd.name);
 
-	video_set_drvdata(vfd, priv);
-	priv->vdev.vfd = vfd;
-	INIT_LIST_HEAD(&priv->vdev.list);
+	video_set_drvdata(vfd, csi);
+	csi->vdev.vfd = vfd;
+	INIT_LIST_HEAD(&csi->vdev.list);
 
 	/* Initialize the video device pad. */
-	priv->vdev_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_pads_init(&vfd->entity, 1, &priv->vdev_pad);
+	csi->vdev_pad.flags = MEDIA_PAD_FL_SINK;
+	ret = media_entity_pads_init(&vfd->entity, 1, &csi->vdev_pad);
 	if (ret) {
 		video_device_release(vfd);
-		return ERR_PTR(ret);
+		return ret;
 	}
 
 	/* Initialize the vb2 queue. */
-	vq = &priv->q;
+	vq = &csi->q;
 	vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	vq->io_modes = VB2_MMAP | VB2_DMABUF;
-	vq->drv_priv = priv;
+	vq->drv_priv = csi;
 	vq->buf_struct_size = sizeof(struct imx_media_buffer);
 	vq->ops = &capture_qops;
 	vq->mem_ops = &vb2_dma_contig_memops;
 	vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	vq->lock = &priv->mutex;
+	vq->lock = &csi->vdev_mutex;
 	vq->min_buffers_needed = 2;
-	vq->dev = priv->dev;
+	vq->dev = csi->dev;
 
 	ret = vb2_queue_init(vq);
 	if (ret) {
-		dev_err(priv->dev, "vb2_queue_init failed\n");
+		dev_err(csi->dev, "vb2_queue_init failed\n");
 		video_device_release(vfd);
-		return ERR_PTR(ret);
+		return ret;
 	}
 
-	return &priv->vdev;
+	return 0;
 }
 
 /* -----------------------------------------------------------------------------
@@ -1645,7 +1610,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 				      struct v4l2_subdev_format *sink_fmt)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct imx_media_video_dev *vdev = csi->vdev;
+	struct imx_media_video_dev *vdev = &csi->vdev;
 	const struct v4l2_pix_format *out_pix = &vdev->fmt;
 	struct media_pad *pad;
 	int ret;
@@ -1716,13 +1681,11 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 	int ret;
 
-	csi->vdev = imx7_media_capture_device_init(csi->sd.dev, &csi->sd,
-						   IMX7_CSI_PAD_SRC);
-	if (IS_ERR(csi->vdev))
-		return PTR_ERR(csi->vdev);
+	ret = imx7_media_capture_device_init(csi);
+	if (ret)
+		return ret;
 
-	ret = imx7_media_capture_device_register(csi->vdev,
-						 MEDIA_LNK_FL_IMMUTABLE);
+	ret = imx7_media_capture_device_register(csi);
 	if (ret)
 		return ret;
 
@@ -1737,7 +1700,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	return 0;
 
 err_unreg:
-	imx7_media_capture_device_unregister(csi->vdev);
+	imx7_media_capture_device_unregister(csi);
 	return ret;
 }
 
@@ -1745,7 +1708,7 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 
-	imx7_media_capture_device_unregister(csi->vdev);
+	imx7_media_capture_device_unregister(csi);
 }
 
 static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 16/50] staging: media: imx: imx7-media-csi: Ensure consistent function prefix
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (14 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 15/50] staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 17/50] staging: media: imx: imx7-media-csi: Don't set subdev group id Laurent Pinchart
                   ` (36 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Rename all the functions and macros imported from imx-media-capture.c
with a consistent imx7_csi_video_ prefix. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 164 ++++++++++-----------
 1 file changed, 80 insertions(+), 84 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 9b4463e456c2..80d666416d47 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -162,6 +162,10 @@
 #define CSI_CSICR18			0x48
 #define CSI_CSICR19			0x4c
 
+#define IMX7_CSI_VIDEO_NAME		"imx-capture"
+/* In bytes, per queue */
+#define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
+
 enum imx_csi_model {
 	IMX7_CSI_IMX7 = 0,
 	IMX7_CSI_IMX8MQ,
@@ -349,8 +353,7 @@ static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 		imx7_csi_reg_write(csi, phys, CSI_CSIDMASA_FB1);
 }
 
-static struct imx_media_buffer *
-imx7_media_capture_device_next_buf(struct imx7_csi *csi);
+static struct imx_media_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi);
 
 static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 {
@@ -360,7 +363,7 @@ static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 	int i;
 
 	for (i = 0; i < 2; i++) {
-		buf = imx7_media_capture_device_next_buf(csi);
+		buf = imx7_csi_video_next_buf(csi);
 		if (buf) {
 			csi->active_vb2_buf[i] = buf;
 			vb2_buf = &buf->vbuf.vb2_buf;
@@ -662,7 +665,7 @@ static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 	csi->frame_sequence++;
 
 	/* get next queued buffer */
-	next = imx7_media_capture_device_next_buf(csi);
+	next = imx7_csi_video_next_buf(csi);
 	if (next) {
 		phys = vb2_dma_contig_plane_dma_addr(&next->vbuf.vb2_buf, 0);
 		csi->active_vb2_buf[csi->buf_num] = next;
@@ -732,20 +735,12 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-/* -----------------------------------------------------------------------------
- * Video Capture Device
- */
-
-#define IMX_CAPTURE_NAME "imx-capture"
-
-/* In bytes, per queue */
-#define VID_MEM_LIMIT	SZ_64M
-
 /* -----------------------------------------------------------------------------
  * Video Capture Device - IOCTLs
  */
 
-static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
+static const struct imx_media_pixfmt *
+imx7_csi_video_find_format(u32 code, u32 fourcc)
 {
 	const struct imx_media_pixfmt *cc;
 
@@ -766,28 +761,28 @@ static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
 	return imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
 }
 
-static int capture_querycap(struct file *file, void *fh,
-			    struct v4l2_capability *cap)
+static int imx7_csi_video_querycap(struct file *file, void *fh,
+				   struct v4l2_capability *cap)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 
-	strscpy(cap->driver, IMX_CAPTURE_NAME, sizeof(cap->driver));
-	strscpy(cap->card, IMX_CAPTURE_NAME, sizeof(cap->card));
+	strscpy(cap->driver, IMX7_CSI_VIDEO_NAME, sizeof(cap->driver));
+	strscpy(cap->card, IMX7_CSI_VIDEO_NAME, sizeof(cap->card));
 	snprintf(cap->bus_info, sizeof(cap->bus_info),
 		 "platform:%s", dev_name(csi->dev));
 
 	return 0;
 }
 
-static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
-				    struct v4l2_fmtdesc *f)
+static int imx7_csi_video_enum_fmt_vid_cap(struct file *file, void *fh,
+					   struct v4l2_fmtdesc *f)
 {
 	return imx_media_enum_pixel_formats(&f->pixelformat, f->index,
 					    PIXFMT_SEL_ANY, f->mbus_code);
 }
 
-static int capture_enum_framesizes(struct file *file, void *fh,
-				   struct v4l2_frmsizeenum *fsize)
+static int imx7_csi_video_enum_framesizes(struct file *file, void *fh,
+					  struct v4l2_frmsizeenum *fsize)
 {
 	const struct imx_media_pixfmt *cc;
 
@@ -814,8 +809,8 @@ static int capture_enum_framesizes(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_g_fmt_vid_cap(struct file *file, void *fh,
-				 struct v4l2_format *f)
+static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh,
+					struct v4l2_format *f)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 
@@ -825,7 +820,8 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh,
 }
 
 static const struct imx_media_pixfmt *
-__capture_try_fmt(struct v4l2_pix_format *pixfmt, struct v4l2_rect *compose)
+__imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
+			 struct v4l2_rect *compose)
 {
 	struct v4l2_mbus_framefmt fmt_src;
 	const struct imx_media_pixfmt *cc;
@@ -867,15 +863,15 @@ __capture_try_fmt(struct v4l2_pix_format *pixfmt, struct v4l2_rect *compose)
 	return cc;
 }
 
-static int capture_try_fmt_vid_cap(struct file *file, void *fh,
-				   struct v4l2_format *f)
+static int imx7_csi_video_try_fmt_vid_cap(struct file *file, void *fh,
+					  struct v4l2_format *f)
 {
-	__capture_try_fmt(&f->fmt.pix, NULL);
+	__imx7_csi_video_try_fmt(&f->fmt.pix, NULL);
 	return 0;
 }
 
-static int capture_s_fmt_vid_cap(struct file *file, void *fh,
-				 struct v4l2_format *f)
+static int imx7_csi_video_s_fmt_vid_cap(struct file *file, void *fh,
+					struct v4l2_format *f)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 	const struct imx_media_pixfmt *cc;
@@ -885,7 +881,7 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 		return -EBUSY;
 	}
 
-	cc = __capture_try_fmt(&f->fmt.pix, &csi->vdev.compose);
+	cc = __imx7_csi_video_try_fmt(&f->fmt.pix, &csi->vdev.compose);
 
 	csi->vdev.cc = cc;
 	csi->vdev.fmt = f->fmt.pix;
@@ -893,8 +889,8 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_g_selection(struct file *file, void *fh,
-			       struct v4l2_selection *s)
+static int imx7_csi_video_g_selection(struct file *file, void *fh,
+				      struct v4l2_selection *s)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 
@@ -923,8 +919,8 @@ static int capture_g_selection(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_subscribe_event(struct v4l2_fh *fh,
-				   const struct v4l2_event_subscription *sub)
+static int imx7_csi_video_subscribe_event(struct v4l2_fh *fh,
+					  const struct v4l2_event_subscription *sub)
 {
 	switch (sub->type) {
 	case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR:
@@ -934,17 +930,17 @@ static int capture_subscribe_event(struct v4l2_fh *fh,
 	}
 }
 
-static const struct v4l2_ioctl_ops capture_ioctl_ops = {
-	.vidioc_querycap		= capture_querycap,
+static const struct v4l2_ioctl_ops imx7_csi_video_ioctl_ops = {
+	.vidioc_querycap		= imx7_csi_video_querycap,
 
-	.vidioc_enum_fmt_vid_cap	= capture_enum_fmt_vid_cap,
-	.vidioc_enum_framesizes		= capture_enum_framesizes,
+	.vidioc_enum_fmt_vid_cap	= imx7_csi_video_enum_fmt_vid_cap,
+	.vidioc_enum_framesizes		= imx7_csi_video_enum_framesizes,
 
-	.vidioc_g_fmt_vid_cap		= capture_g_fmt_vid_cap,
-	.vidioc_try_fmt_vid_cap		= capture_try_fmt_vid_cap,
-	.vidioc_s_fmt_vid_cap		= capture_s_fmt_vid_cap,
+	.vidioc_g_fmt_vid_cap		= imx7_csi_video_g_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap		= imx7_csi_video_try_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap		= imx7_csi_video_s_fmt_vid_cap,
 
-	.vidioc_g_selection		= capture_g_selection,
+	.vidioc_g_selection		= imx7_csi_video_g_selection,
 
 	.vidioc_reqbufs			= vb2_ioctl_reqbufs,
 	.vidioc_create_bufs		= vb2_ioctl_create_bufs,
@@ -956,7 +952,7 @@ static const struct v4l2_ioctl_ops capture_ioctl_ops = {
 	.vidioc_streamon		= vb2_ioctl_streamon,
 	.vidioc_streamoff		= vb2_ioctl_streamoff,
 
-	.vidioc_subscribe_event		= capture_subscribe_event,
+	.vidioc_subscribe_event		= imx7_csi_video_subscribe_event,
 	.vidioc_unsubscribe_event	= v4l2_event_unsubscribe,
 };
 
@@ -964,11 +960,11 @@ static const struct v4l2_ioctl_ops capture_ioctl_ops = {
  * Video Capture Device - Queue Operations
  */
 
-static int capture_queue_setup(struct vb2_queue *vq,
-			       unsigned int *nbuffers,
-			       unsigned int *nplanes,
-			       unsigned int sizes[],
-			       struct device *alloc_devs[])
+static int imx7_csi_video_queue_setup(struct vb2_queue *vq,
+				      unsigned int *nbuffers,
+				      unsigned int *nplanes,
+				      unsigned int sizes[],
+				      struct device *alloc_devs[])
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
 	struct v4l2_pix_format *pix = &csi->vdev.fmt;
@@ -983,7 +979,7 @@ static int capture_queue_setup(struct vb2_queue *vq,
 		count += vq->num_buffers;
 	}
 
-	count = min_t(__u32, VID_MEM_LIMIT / pix->sizeimage, count);
+	count = min_t(__u32, IMX7_CSI_VIDEO_MEM_LIMIT / pix->sizeimage, count);
 
 	if (*nplanes)
 		*nbuffers = (count < vq->num_buffers) ? 0 :
@@ -997,7 +993,7 @@ static int capture_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int capture_buf_init(struct vb2_buffer *vb)
+static int imx7_csi_video_buf_init(struct vb2_buffer *vb)
 {
 	struct imx_media_buffer *buf = to_imx_media_vb(vb);
 
@@ -1006,7 +1002,7 @@ static int capture_buf_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int capture_buf_prepare(struct vb2_buffer *vb)
+static int imx7_csi_video_buf_prepare(struct vb2_buffer *vb)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
 	struct v4l2_pix_format *pix = &csi->vdev.fmt;
@@ -1023,7 +1019,7 @@ static int capture_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void capture_buf_queue(struct vb2_buffer *vb)
+static void imx7_csi_video_buf_queue(struct vb2_buffer *vb)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
 	struct imx_media_buffer *buf = to_imx_media_vb(vb);
@@ -1036,7 +1032,7 @@ static void capture_buf_queue(struct vb2_buffer *vb)
 	spin_unlock_irqrestore(&csi->q_lock, flags);
 }
 
-static int capture_validate_fmt(struct imx7_csi *csi)
+static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 {
 	struct v4l2_subdev_format fmt_src;
 	const struct imx_media_pixfmt *cc;
@@ -1064,21 +1060,22 @@ static int capture_validate_fmt(struct imx7_csi *csi)
 	 * Verify that the media bus code is compatible with the pixel format
 	 * set on the video node.
 	 */
-	cc = capture_find_format(fmt_src.format.code, 0);
+	cc = imx7_csi_video_find_format(fmt_src.format.code, 0);
 	if (!cc || csi->vdev.cc->cs != cc->cs)
 		return -EPIPE;
 
 	return 0;
 }
 
-static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
+static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
+					  unsigned int count)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
 	struct imx_media_buffer *buf, *tmp;
 	unsigned long flags;
 	int ret;
 
-	ret = capture_validate_fmt(csi);
+	ret = imx7_csi_video_validate_fmt(csi);
 	if (ret) {
 		dev_err(csi->dev, "capture format not valid\n");
 		goto return_bufs;
@@ -1102,7 +1099,7 @@ static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
 	return ret;
 }
 
-static void capture_stop_streaming(struct vb2_queue *vq)
+static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
 	struct imx_media_buffer *frame;
@@ -1123,22 +1120,22 @@ static void capture_stop_streaming(struct vb2_queue *vq)
 	spin_unlock_irqrestore(&csi->q_lock, flags);
 }
 
-static const struct vb2_ops capture_qops = {
-	.queue_setup	 = capture_queue_setup,
-	.buf_init        = capture_buf_init,
-	.buf_prepare	 = capture_buf_prepare,
-	.buf_queue	 = capture_buf_queue,
+static const struct vb2_ops imx7_csi_video_qops = {
+	.queue_setup	 = imx7_csi_video_queue_setup,
+	.buf_init        = imx7_csi_video_buf_init,
+	.buf_prepare	 = imx7_csi_video_buf_prepare,
+	.buf_queue	 = imx7_csi_video_buf_queue,
 	.wait_prepare	 = vb2_ops_wait_prepare,
 	.wait_finish	 = vb2_ops_wait_finish,
-	.start_streaming = capture_start_streaming,
-	.stop_streaming  = capture_stop_streaming,
+	.start_streaming = imx7_csi_video_start_streaming,
+	.stop_streaming  = imx7_csi_video_stop_streaming,
 };
 
 /* -----------------------------------------------------------------------------
  * Video Capture Device - File Operations
  */
 
-static int capture_open(struct file *file)
+static int imx7_csi_video_open(struct file *file)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 	struct video_device *vfd = csi->vdev.vfd;
@@ -1162,7 +1159,7 @@ static int capture_open(struct file *file)
 	return ret;
 }
 
-static int capture_release(struct file *file)
+static int imx7_csi_video_release(struct file *file)
 {
 	struct imx7_csi *csi = video_drvdata(file);
 	struct video_device *vfd = csi->vdev.vfd;
@@ -1182,10 +1179,10 @@ static int capture_release(struct file *file)
 	return 0;
 }
 
-static const struct v4l2_file_operations capture_fops = {
+static const struct v4l2_file_operations imx7_csi_video_fops = {
 	.owner		= THIS_MODULE,
-	.open		= capture_open,
-	.release	= capture_release,
+	.open		= imx7_csi_video_open,
+	.release	= imx7_csi_video_release,
 	.poll		= vb2_fop_poll,
 	.unlocked_ioctl	= video_ioctl2,
 	.mmap		= vb2_fop_mmap,
@@ -1195,8 +1192,7 @@ static const struct v4l2_file_operations capture_fops = {
  * Video Capture Device - Init & Cleanup
  */
 
-static struct imx_media_buffer *
-imx7_media_capture_device_next_buf(struct imx7_csi *csi)
+static struct imx_media_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi)
 {
 	struct imx_media_buffer *buf = NULL;
 	unsigned long flags;
@@ -1215,7 +1211,7 @@ imx7_media_capture_device_next_buf(struct imx7_csi *csi)
 	return buf;
 }
 
-static int capture_init_format(struct imx7_csi *csi)
+static int imx7_csi_video_init_format(struct imx7_csi *csi)
 {
 	struct v4l2_subdev_format fmt_src = {
 		.pad = IMX7_CSI_PAD_SRC,
@@ -1237,7 +1233,7 @@ static int capture_init_format(struct imx7_csi *csi)
 	return 0;
 }
 
-static int imx7_media_capture_device_register(struct imx7_csi *csi)
+static int imx7_csi_video_register(struct imx7_csi *csi)
 {
 	struct v4l2_subdev *sd = &csi->sd;
 	struct v4l2_device *v4l2_dev = sd->v4l2_dev;
@@ -1247,7 +1243,7 @@ static int imx7_media_capture_device_register(struct imx7_csi *csi)
 	vfd->v4l2_dev = v4l2_dev;
 
 	/* Initialize the default format and compose rectangle. */
-	ret = capture_init_format(csi);
+	ret = imx7_csi_video_init_format(csi);
 	if (ret < 0)
 		return ret;
 
@@ -1277,7 +1273,7 @@ static int imx7_media_capture_device_register(struct imx7_csi *csi)
 	return 0;
 }
 
-static void imx7_media_capture_device_unregister(struct imx7_csi *csi)
+static void imx7_csi_video_unregister(struct imx7_csi *csi)
 {
 	struct video_device *vfd = csi->vdev.vfd;
 
@@ -1285,7 +1281,7 @@ static void imx7_media_capture_device_unregister(struct imx7_csi *csi)
 	video_unregister_device(vfd);
 }
 
-static int imx7_media_capture_device_init(struct imx7_csi *csi)
+static int imx7_csi_video_init(struct imx7_csi *csi)
 {
 	struct video_device *vfd;
 	struct vb2_queue *vq;
@@ -1300,8 +1296,8 @@ static int imx7_media_capture_device_init(struct imx7_csi *csi)
 	if (!vfd)
 		return -ENOMEM;
 
-	vfd->fops = &capture_fops;
-	vfd->ioctl_ops = &capture_ioctl_ops;
+	vfd->fops = &imx7_csi_video_fops;
+	vfd->ioctl_ops = &imx7_csi_video_ioctl_ops;
 	vfd->minor = -1;
 	vfd->release = video_device_release;
 	vfd->vfl_dir = VFL_DIR_RX;
@@ -1331,7 +1327,7 @@ static int imx7_media_capture_device_init(struct imx7_csi *csi)
 	vq->io_modes = VB2_MMAP | VB2_DMABUF;
 	vq->drv_priv = csi;
 	vq->buf_struct_size = sizeof(struct imx_media_buffer);
-	vq->ops = &capture_qops;
+	vq->ops = &imx7_csi_video_qops;
 	vq->mem_ops = &vb2_dma_contig_memops;
 	vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	vq->lock = &csi->vdev_mutex;
@@ -1681,11 +1677,11 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 	int ret;
 
-	ret = imx7_media_capture_device_init(csi);
+	ret = imx7_csi_video_init(csi);
 	if (ret)
 		return ret;
 
-	ret = imx7_media_capture_device_register(csi);
+	ret = imx7_csi_video_register(csi);
 	if (ret)
 		return ret;
 
@@ -1700,7 +1696,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	return 0;
 
 err_unreg:
-	imx7_media_capture_device_unregister(csi);
+	imx7_csi_video_unregister(csi);
 	return ret;
 }
 
@@ -1708,7 +1704,7 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 
-	imx7_media_capture_device_unregister(csi);
+	imx7_csi_video_unregister(csi);
 }
 
 static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 17/50] staging: media: imx: imx7-media-csi: Don't set subdev group id
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (15 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 16/50] staging: media: imx: imx7-media-csi: Ensure consistent function prefix Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 18/50] staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper Laurent Pinchart
                   ` (35 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The subdev group id isn't used by any of the remaining helpers used by
this driver, don't set it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 80d666416d47..bd1bdc09e701 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1749,13 +1749,6 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier);
 	struct media_pad *sink = &csi->sd.entity.pads[IMX7_CSI_PAD_SINK];
 
-	/*
-	 * If the subdev is a video mux, it must be one of the CSI
-	 * muxes. Mark it as such via its group id.
-	 */
-	if (sd->entity.function == MEDIA_ENT_F_VID_MUX)
-		sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
-
 	csi->src_sd = sd;
 
 	return v4l2_create_fwnode_links_to_pad(sd, sink, MEDIA_LNK_FL_ENABLED |
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 18/50] staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (16 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 17/50] staging: media: imx: imx7-media-csi: Don't set subdev group id Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 19/50] staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi Laurent Pinchart
                   ` (34 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

To prepare for code refactoring, copy the imx_media_dev_init() helper
used by this driver from imx-media-dev-common.c. Rename the function to
avoid name clashes, and leave the v4l2_device notify handler out as it
only serves to implement control inheritance, which this driver doesn't
use. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 50 +++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index bd1bdc09e701..8b19792adfc6 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1809,13 +1809,61 @@ static void imx7_csi_media_cleanup(struct imx7_csi *csi)
 	media_device_cleanup(&imxmd->md);
 }
 
+static const struct media_device_ops imx7_csi_media_ops = {
+	.link_notify = v4l2_pipeline_link_notify,
+};
+
+static struct imx_media_dev *imx7_csi_media_dev_init(struct device *dev)
+{
+	struct imx_media_dev *imxmd;
+	int ret;
+
+	imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL);
+	if (!imxmd)
+		return ERR_PTR(-ENOMEM);
+
+	dev_set_drvdata(dev, imxmd);
+
+	strscpy(imxmd->md.model, "imx-media", sizeof(imxmd->md.model));
+	imxmd->md.ops = &imx7_csi_media_ops;
+	imxmd->md.dev = dev;
+
+	mutex_init(&imxmd->mutex);
+
+	imxmd->v4l2_dev.mdev = &imxmd->md;
+	strscpy(imxmd->v4l2_dev.name, "imx-media",
+		sizeof(imxmd->v4l2_dev.name));
+	snprintf(imxmd->md.bus_info, sizeof(imxmd->md.bus_info),
+		 "platform:%s", dev_name(imxmd->md.dev));
+
+	media_device_init(&imxmd->md);
+
+	ret = v4l2_device_register(dev, &imxmd->v4l2_dev);
+	if (ret < 0) {
+		v4l2_err(&imxmd->v4l2_dev,
+			 "Failed to register v4l2_device: %d\n", ret);
+		goto cleanup;
+	}
+
+	INIT_LIST_HEAD(&imxmd->vdev_list);
+
+	v4l2_async_nf_init(&imxmd->notifier);
+
+	return imxmd;
+
+cleanup:
+	media_device_cleanup(&imxmd->md);
+
+	return ERR_PTR(ret);
+}
+
 static int imx7_csi_media_init(struct imx7_csi *csi)
 {
 	struct imx_media_dev *imxmd;
 	int i, ret;
 
 	/* add media device */
-	imxmd = imx_media_dev_init(csi->dev, NULL);
+	imxmd = imx7_csi_media_dev_init(csi->dev);
 	if (IS_ERR(imxmd))
 		return PTR_ERR(imxmd);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 19/50] staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (17 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 18/50] staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 20/50] staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call Laurent Pinchart
                   ` (33 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

There's no need anymore to allocate the imx_media_dev structure
separately from imx7_csi. Embed it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 47 +++++++++-------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 8b19792adfc6..891e939d7ea5 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -183,7 +183,7 @@ struct imx7_csi {
 	spinlock_t irqlock; /* Protects last_eof */
 
 	/* Media and V4L2 device */
-	struct imx_media_dev *imxmd;
+	struct imx_media_dev imxmd;
 	struct v4l2_async_notifier notifier;
 
 	struct v4l2_subdev *src_sd;
@@ -1081,7 +1081,7 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 		goto return_bufs;
 	}
 
-	ret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, true);
+	ret = imx_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity, true);
 	if (ret) {
 		dev_err(csi->dev, "pipeline start failed with %d\n", ret);
 		goto return_bufs;
@@ -1107,7 +1107,7 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 	unsigned long flags;
 	int ret;
 
-	ret = imx_media_pipeline_set_stream(csi->imxmd, &csi->sd.entity, false);
+	ret = imx_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity, false);
 	if (ret)
 		dev_warn(csi->dev, "pipeline stop failed with %d\n", ret);
 
@@ -1268,7 +1268,7 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
 	}
 
 	/* Add vdev to the video devices list. */
-	imx_media_add_video_device(csi->imxmd, &csi->vdev);
+	imx_media_add_video_device(&csi->imxmd, &csi->vdev);
 
 	return 0;
 }
@@ -1685,11 +1685,11 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	if (ret)
 		return ret;
 
-	ret = v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev);
+	ret = v4l2_device_register_subdev_nodes(&csi->imxmd.v4l2_dev);
 	if (ret)
 		goto err_unreg;
 
-	ret = media_device_register(&csi->imxmd->md);
+	ret = media_device_register(&csi->imxmd.md);
 	if (ret)
 		goto err_unreg;
 
@@ -1759,7 +1759,7 @@ static int imx7_csi_notify_complete(struct v4l2_async_notifier *notifier)
 {
 	struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier);
 
-	return v4l2_device_register_subdev_nodes(&csi->imxmd->v4l2_dev);
+	return v4l2_device_register_subdev_nodes(&csi->imxmd.v4l2_dev);
 }
 
 static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
@@ -1793,7 +1793,7 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 	csi->notifier.ops = &imx7_csi_notify_ops;
 
-	ret = v4l2_async_nf_register(&csi->imxmd->v4l2_dev, &csi->notifier);
+	ret = v4l2_async_nf_register(&csi->imxmd.v4l2_dev, &csi->notifier);
 	if (ret)
 		return ret;
 
@@ -1802,7 +1802,7 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 static void imx7_csi_media_cleanup(struct imx7_csi *csi)
 {
-	struct imx_media_dev *imxmd = csi->imxmd;
+	struct imx_media_dev *imxmd = &csi->imxmd;
 
 	v4l2_device_unregister(&imxmd->v4l2_dev);
 	media_device_unregister(&imxmd->md);
@@ -1813,20 +1813,16 @@ static const struct media_device_ops imx7_csi_media_ops = {
 	.link_notify = v4l2_pipeline_link_notify,
 };
 
-static struct imx_media_dev *imx7_csi_media_dev_init(struct device *dev)
+static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 {
-	struct imx_media_dev *imxmd;
+	struct imx_media_dev *imxmd = &csi->imxmd;
 	int ret;
 
-	imxmd = devm_kzalloc(dev, sizeof(*imxmd), GFP_KERNEL);
-	if (!imxmd)
-		return ERR_PTR(-ENOMEM);
-
-	dev_set_drvdata(dev, imxmd);
+	dev_set_drvdata(csi->dev, imxmd);
 
 	strscpy(imxmd->md.model, "imx-media", sizeof(imxmd->md.model));
 	imxmd->md.ops = &imx7_csi_media_ops;
-	imxmd->md.dev = dev;
+	imxmd->md.dev = csi->dev;
 
 	mutex_init(&imxmd->mutex);
 
@@ -1838,7 +1834,7 @@ static struct imx_media_dev *imx7_csi_media_dev_init(struct device *dev)
 
 	media_device_init(&imxmd->md);
 
-	ret = v4l2_device_register(dev, &imxmd->v4l2_dev);
+	ret = v4l2_device_register(csi->dev, &imxmd->v4l2_dev);
 	if (ret < 0) {
 		v4l2_err(&imxmd->v4l2_dev,
 			 "Failed to register v4l2_device: %d\n", ret);
@@ -1849,25 +1845,22 @@ static struct imx_media_dev *imx7_csi_media_dev_init(struct device *dev)
 
 	v4l2_async_nf_init(&imxmd->notifier);
 
-	return imxmd;
+	return 0;
 
 cleanup:
 	media_device_cleanup(&imxmd->md);
 
-	return ERR_PTR(ret);
+	return ret;
 }
 
 static int imx7_csi_media_init(struct imx7_csi *csi)
 {
-	struct imx_media_dev *imxmd;
 	int i, ret;
 
 	/* add media device */
-	imxmd = imx7_csi_media_dev_init(csi->dev);
-	if (IS_ERR(imxmd))
-		return PTR_ERR(imxmd);
-
-	csi->imxmd = imxmd;
+	ret = imx7_csi_media_dev_init(csi);
+	if (ret)
+		return ret;
 
 	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
 	v4l2_set_subdevdata(&csi->sd, csi);
@@ -1888,7 +1881,7 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 	if (ret < 0)
 		return ret;
 
-	return v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
+	return v4l2_device_register_subdev(&csi->imxmd.v4l2_dev, &csi->sd);
 }
 
 static int imx7_csi_probe(struct platform_device *pdev)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 20/50] staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (18 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 19/50] staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 21/50] staging: media: imx: imx7-media-csi: Don't initialize unused fields Laurent Pinchart
                   ` (32 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

There's no need to call imx_media_add_video_device() anymore, as the
video devices list it manages is only used by the control inheritance
mechanism in the helpers, which this driver doesn't use.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 891e939d7ea5..b6643952da25 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1267,9 +1267,6 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
 		return ret;
 	}
 
-	/* Add vdev to the video devices list. */
-	imx_media_add_video_device(&csi->imxmd, &csi->vdev);
-
 	return 0;
 }
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 21/50] staging: media: imx: imx7-media-csi: Don't initialize unused fields
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (19 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 20/50] staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 22/50] staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad() Laurent Pinchart
                   ` (31 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx_media_dev structure contains three fields that are not used by
this driver or any helper code that it calls. Don't initialize them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index b6643952da25..7e932884fd02 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1821,8 +1821,6 @@ static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 	imxmd->md.ops = &imx7_csi_media_ops;
 	imxmd->md.dev = csi->dev;
 
-	mutex_init(&imxmd->mutex);
-
 	imxmd->v4l2_dev.mdev = &imxmd->md;
 	strscpy(imxmd->v4l2_dev.name, "imx-media",
 		sizeof(imxmd->v4l2_dev.name));
@@ -1838,10 +1836,6 @@ static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 		goto cleanup;
 	}
 
-	INIT_LIST_HEAD(&imxmd->vdev_list);
-
-	v4l2_async_nf_init(&imxmd->notifier);
-
 	return 0;
 
 cleanup:
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 22/50] staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (20 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 21/50] staging: media: imx: imx7-media-csi: Don't initialize unused fields Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 23/50] staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream() Laurent Pinchart
                   ` (30 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Inline the imx_media_pipeline_pad() helper, dropping all the code unused
by the imx7-media-csi driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 7e932884fd02..e1b494183ebc 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1605,7 +1605,8 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
 	struct imx_media_video_dev *vdev = &csi->vdev;
 	const struct v4l2_pix_format *out_pix = &vdev->fmt;
-	struct media_pad *pad;
+	struct media_pad *pad = NULL;
+	unsigned int i;
 	int ret;
 
 	if (!csi->src_sd)
@@ -1627,7 +1628,17 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 
 	case MEDIA_ENT_F_VID_MUX:
 		/* The input is the mux, check its input. */
-		pad = imx_media_pipeline_pad(&csi->src_sd->entity, 0, 0, true);
+		for (i = 0; i < csi->src_sd->entity.num_pads; i++) {
+			struct media_pad *spad = &csi->src_sd->entity.pads[i];
+
+			if (!(spad->flags & MEDIA_PAD_FL_SINK))
+				continue;
+
+			pad = media_entity_remote_pad(spad);
+			if (pad)
+				break;
+		}
+
 		if (!pad)
 			return -ENODEV;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 23/50] staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (21 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 22/50] staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 24/50] staging: media: imx: imx7-media-csi: Avoid unnecessary casts Laurent Pinchart
                   ` (29 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

To prepare for code refactoring, copy the
imx_media_pipeline_set_stream() helper used by this driver from
imx-media-utils.c. Rename the function to avoid name clashes, no
functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 40 ++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index e1b494183ebc..1c8ee7c88f46 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1067,6 +1067,40 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	return 0;
 }
 
+/*
+ * Turn current pipeline streaming on/off starting from entity.
+ */
+static int imx7_csi_media_pipeline_set_stream(struct imx_media_dev *imxmd,
+					      struct media_entity *entity,
+					      bool on)
+{
+	struct v4l2_subdev *sd;
+	int ret = 0;
+
+	if (!is_media_entity_v4l2_subdev(entity))
+		return -EINVAL;
+	sd = media_entity_to_v4l2_subdev(entity);
+
+	mutex_lock(&imxmd->md.graph_mutex);
+
+	if (on) {
+		ret = __media_pipeline_start(entity, &imxmd->pipe);
+		if (ret)
+			goto out;
+		ret = v4l2_subdev_call(sd, video, s_stream, 1);
+		if (ret)
+			__media_pipeline_stop(entity);
+	} else {
+		v4l2_subdev_call(sd, video, s_stream, 0);
+		if (entity->pipe)
+			__media_pipeline_stop(entity);
+	}
+
+out:
+	mutex_unlock(&imxmd->md.graph_mutex);
+	return ret;
+}
+
 static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 					  unsigned int count)
 {
@@ -1081,7 +1115,8 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 		goto return_bufs;
 	}
 
-	ret = imx_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity, true);
+	ret = imx7_csi_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity,
+						 true);
 	if (ret) {
 		dev_err(csi->dev, "pipeline start failed with %d\n", ret);
 		goto return_bufs;
@@ -1107,7 +1142,8 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 	unsigned long flags;
 	int ret;
 
-	ret = imx_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity, false);
+	ret = imx7_csi_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity,
+						 false);
 	if (ret)
 		dev_warn(csi->dev, "pipeline stop failed with %d\n", ret);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 24/50] staging: media: imx: imx7-media-csi: Avoid unnecessary casts
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (22 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 23/50] staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 25/50] staging: media: imx: imx7-media-csi: Inline pipeline start/stop Laurent Pinchart
                   ` (28 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Simplify the imx7_csi_media_pipeline_set_stream() function by passing it
the imx7_csi pointer, which avoids going from subdev to entity and back
to subdev.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 31 +++++++---------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 1c8ee7c88f46..8600fc4d6be2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1067,33 +1067,24 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	return 0;
 }
 
-/*
- * Turn current pipeline streaming on/off starting from entity.
- */
-static int imx7_csi_media_pipeline_set_stream(struct imx_media_dev *imxmd,
-					      struct media_entity *entity,
-					      bool on)
+static int imx7_csi_media_pipeline_set_stream(struct imx7_csi *csi, bool on)
 {
-	struct v4l2_subdev *sd;
+	struct imx_media_dev *imxmd = &csi->imxmd;
 	int ret = 0;
 
-	if (!is_media_entity_v4l2_subdev(entity))
-		return -EINVAL;
-	sd = media_entity_to_v4l2_subdev(entity);
-
 	mutex_lock(&imxmd->md.graph_mutex);
 
 	if (on) {
-		ret = __media_pipeline_start(entity, &imxmd->pipe);
+		ret = __media_pipeline_start(&csi->sd.entity, &imxmd->pipe);
 		if (ret)
 			goto out;
-		ret = v4l2_subdev_call(sd, video, s_stream, 1);
+		ret = v4l2_subdev_call(&csi->sd, video, s_stream, 1);
 		if (ret)
-			__media_pipeline_stop(entity);
+			__media_pipeline_stop(&csi->sd.entity);
 	} else {
-		v4l2_subdev_call(sd, video, s_stream, 0);
-		if (entity->pipe)
-			__media_pipeline_stop(entity);
+		v4l2_subdev_call(&csi->sd, video, s_stream, 0);
+		if (csi->sd.entity.pipe)
+			__media_pipeline_stop(&csi->sd.entity);
 	}
 
 out:
@@ -1115,8 +1106,7 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 		goto return_bufs;
 	}
 
-	ret = imx7_csi_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity,
-						 true);
+	ret = imx7_csi_media_pipeline_set_stream(csi, true);
 	if (ret) {
 		dev_err(csi->dev, "pipeline start failed with %d\n", ret);
 		goto return_bufs;
@@ -1142,8 +1132,7 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 	unsigned long flags;
 	int ret;
 
-	ret = imx7_csi_media_pipeline_set_stream(&csi->imxmd, &csi->sd.entity,
-						 false);
+	ret = imx7_csi_media_pipeline_set_stream(csi, false);
 	if (ret)
 		dev_warn(csi->dev, "pipeline stop failed with %d\n", ret);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 25/50] staging: media: imx: imx7-media-csi: Inline pipeline start/stop
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (23 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 24/50] staging: media: imx: imx7-media-csi: Avoid unnecessary casts Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 26/50] staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi Laurent Pinchart
                   ` (27 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx7_csi_media_pipeline_set_stream() function has separate branches
for the start and stop paths, surrounded by mutex lock/unlock. That is
very little shared code, inline the locking and corresponding branch in
each of the two callers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 58 ++++++++--------------
 1 file changed, 22 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 8600fc4d6be2..44c19c73da97 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1067,31 +1067,6 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	return 0;
 }
 
-static int imx7_csi_media_pipeline_set_stream(struct imx7_csi *csi, bool on)
-{
-	struct imx_media_dev *imxmd = &csi->imxmd;
-	int ret = 0;
-
-	mutex_lock(&imxmd->md.graph_mutex);
-
-	if (on) {
-		ret = __media_pipeline_start(&csi->sd.entity, &imxmd->pipe);
-		if (ret)
-			goto out;
-		ret = v4l2_subdev_call(&csi->sd, video, s_stream, 1);
-		if (ret)
-			__media_pipeline_stop(&csi->sd.entity);
-	} else {
-		v4l2_subdev_call(&csi->sd, video, s_stream, 0);
-		if (csi->sd.entity.pipe)
-			__media_pipeline_stop(&csi->sd.entity);
-	}
-
-out:
-	mutex_unlock(&imxmd->md.graph_mutex);
-	return ret;
-}
-
 static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 					  unsigned int count)
 {
@@ -1103,18 +1078,29 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 	ret = imx7_csi_video_validate_fmt(csi);
 	if (ret) {
 		dev_err(csi->dev, "capture format not valid\n");
-		goto return_bufs;
+		goto err_buffers;
 	}
 
-	ret = imx7_csi_media_pipeline_set_stream(csi, true);
-	if (ret) {
-		dev_err(csi->dev, "pipeline start failed with %d\n", ret);
-		goto return_bufs;
-	}
+	mutex_lock(&csi->imxmd.md.graph_mutex);
+
+	ret = __media_pipeline_start(&csi->sd.entity, &csi->imxmd.pipe);
+	if (ret)
+		goto err_unlock;
+
+	ret = v4l2_subdev_call(&csi->sd, video, s_stream, 1);
+	if (ret)
+		goto err_stop;
+
+	mutex_unlock(&csi->imxmd.md.graph_mutex);
 
 	return 0;
 
-return_bufs:
+err_stop:
+	__media_pipeline_stop(&csi->sd.entity);
+err_unlock:
+	mutex_unlock(&csi->imxmd.md.graph_mutex);
+	dev_err(csi->dev, "pipeline start failed with %d\n", ret);
+err_buffers:
 	spin_lock_irqsave(&csi->q_lock, flags);
 	list_for_each_entry_safe(buf, tmp, &csi->ready_q, list) {
 		list_del(&buf->list);
@@ -1130,11 +1116,11 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 	struct imx_media_buffer *frame;
 	struct imx_media_buffer *tmp;
 	unsigned long flags;
-	int ret;
 
-	ret = imx7_csi_media_pipeline_set_stream(csi, false);
-	if (ret)
-		dev_warn(csi->dev, "pipeline stop failed with %d\n", ret);
+	mutex_lock(&csi->imxmd.md.graph_mutex);
+	v4l2_subdev_call(&csi->sd, video, s_stream, 0);
+	__media_pipeline_stop(&csi->sd.entity);
+	mutex_unlock(&csi->imxmd.md.graph_mutex);
 
 	/* release all active buffers */
 	spin_lock_irqsave(&csi->q_lock, flags);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 26/50] staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (24 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 25/50] staging: media: imx: imx7-media-csi: Inline pipeline start/stop Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 27/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer Laurent Pinchart
                   ` (26 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Now that the driver doesn't use any helper that relies on the
imx_media_dev structure anymore, merge the three fields of the
imx_media_dev structure directly in the imx7_csi structure. Update all
the users accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 61 +++++++++++-----------
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 44c19c73da97..b116f6ab96f0 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -183,8 +183,10 @@ struct imx7_csi {
 	spinlock_t irqlock; /* Protects last_eof */
 
 	/* Media and V4L2 device */
-	struct imx_media_dev imxmd;
+	struct media_device mdev;
+	struct v4l2_device v4l2_dev;
 	struct v4l2_async_notifier notifier;
+	struct media_pipeline pipe;
 
 	struct v4l2_subdev *src_sd;
 	bool is_csi2;
@@ -1081,9 +1083,9 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 		goto err_buffers;
 	}
 
-	mutex_lock(&csi->imxmd.md.graph_mutex);
+	mutex_lock(&csi->mdev.graph_mutex);
 
-	ret = __media_pipeline_start(&csi->sd.entity, &csi->imxmd.pipe);
+	ret = __media_pipeline_start(&csi->sd.entity, &csi->pipe);
 	if (ret)
 		goto err_unlock;
 
@@ -1091,14 +1093,14 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 	if (ret)
 		goto err_stop;
 
-	mutex_unlock(&csi->imxmd.md.graph_mutex);
+	mutex_unlock(&csi->mdev.graph_mutex);
 
 	return 0;
 
 err_stop:
 	__media_pipeline_stop(&csi->sd.entity);
 err_unlock:
-	mutex_unlock(&csi->imxmd.md.graph_mutex);
+	mutex_unlock(&csi->mdev.graph_mutex);
 	dev_err(csi->dev, "pipeline start failed with %d\n", ret);
 err_buffers:
 	spin_lock_irqsave(&csi->q_lock, flags);
@@ -1117,10 +1119,10 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 	struct imx_media_buffer *tmp;
 	unsigned long flags;
 
-	mutex_lock(&csi->imxmd.md.graph_mutex);
+	mutex_lock(&csi->mdev.graph_mutex);
 	v4l2_subdev_call(&csi->sd, video, s_stream, 0);
 	__media_pipeline_stop(&csi->sd.entity);
-	mutex_unlock(&csi->imxmd.md.graph_mutex);
+	mutex_unlock(&csi->mdev.graph_mutex);
 
 	/* release all active buffers */
 	spin_lock_irqsave(&csi->q_lock, flags);
@@ -1704,11 +1706,11 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	if (ret)
 		return ret;
 
-	ret = v4l2_device_register_subdev_nodes(&csi->imxmd.v4l2_dev);
+	ret = v4l2_device_register_subdev_nodes(&csi->v4l2_dev);
 	if (ret)
 		goto err_unreg;
 
-	ret = media_device_register(&csi->imxmd.md);
+	ret = media_device_register(&csi->mdev);
 	if (ret)
 		goto err_unreg;
 
@@ -1778,7 +1780,7 @@ static int imx7_csi_notify_complete(struct v4l2_async_notifier *notifier)
 {
 	struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier);
 
-	return v4l2_device_register_subdev_nodes(&csi->imxmd.v4l2_dev);
+	return v4l2_device_register_subdev_nodes(&csi->v4l2_dev);
 }
 
 static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
@@ -1812,7 +1814,7 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 	csi->notifier.ops = &imx7_csi_notify_ops;
 
-	ret = v4l2_async_nf_register(&csi->imxmd.v4l2_dev, &csi->notifier);
+	ret = v4l2_async_nf_register(&csi->v4l2_dev, &csi->notifier);
 	if (ret)
 		return ret;
 
@@ -1821,11 +1823,9 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 
 static void imx7_csi_media_cleanup(struct imx7_csi *csi)
 {
-	struct imx_media_dev *imxmd = &csi->imxmd;
-
-	v4l2_device_unregister(&imxmd->v4l2_dev);
-	media_device_unregister(&imxmd->md);
-	media_device_cleanup(&imxmd->md);
+	v4l2_device_unregister(&csi->v4l2_dev);
+	media_device_unregister(&csi->mdev);
+	media_device_cleanup(&csi->mdev);
 }
 
 static const struct media_device_ops imx7_csi_media_ops = {
@@ -1834,26 +1834,25 @@ static const struct media_device_ops imx7_csi_media_ops = {
 
 static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 {
-	struct imx_media_dev *imxmd = &csi->imxmd;
 	int ret;
 
-	dev_set_drvdata(csi->dev, imxmd);
+	dev_set_drvdata(csi->dev, csi);
 
-	strscpy(imxmd->md.model, "imx-media", sizeof(imxmd->md.model));
-	imxmd->md.ops = &imx7_csi_media_ops;
-	imxmd->md.dev = csi->dev;
+	strscpy(csi->mdev.model, "imx-media", sizeof(csi->mdev.model));
+	csi->mdev.ops = &imx7_csi_media_ops;
+	csi->mdev.dev = csi->dev;
 
-	imxmd->v4l2_dev.mdev = &imxmd->md;
-	strscpy(imxmd->v4l2_dev.name, "imx-media",
-		sizeof(imxmd->v4l2_dev.name));
-	snprintf(imxmd->md.bus_info, sizeof(imxmd->md.bus_info),
-		 "platform:%s", dev_name(imxmd->md.dev));
+	csi->v4l2_dev.mdev = &csi->mdev;
+	strscpy(csi->v4l2_dev.name, "imx-media",
+		sizeof(csi->v4l2_dev.name));
+	snprintf(csi->mdev.bus_info, sizeof(csi->mdev.bus_info),
+		 "platform:%s", dev_name(csi->mdev.dev));
 
-	media_device_init(&imxmd->md);
+	media_device_init(&csi->mdev);
 
-	ret = v4l2_device_register(csi->dev, &imxmd->v4l2_dev);
+	ret = v4l2_device_register(csi->dev, &csi->v4l2_dev);
 	if (ret < 0) {
-		v4l2_err(&imxmd->v4l2_dev,
+		v4l2_err(&csi->v4l2_dev,
 			 "Failed to register v4l2_device: %d\n", ret);
 		goto cleanup;
 	}
@@ -1861,7 +1860,7 @@ static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 	return 0;
 
 cleanup:
-	media_device_cleanup(&imxmd->md);
+	media_device_cleanup(&csi->mdev);
 
 	return ret;
 }
@@ -1894,7 +1893,7 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 	if (ret < 0)
 		return ret;
 
-	return v4l2_device_register_subdev(&csi->imxmd.v4l2_dev, &csi->sd);
+	return v4l2_device_register_subdev(&csi->v4l2_dev, &csi->sd);
 }
 
 static int imx7_csi_probe(struct platform_device *pdev)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 27/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (25 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 26/50] staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 28/50] staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi Laurent Pinchart
                   ` (25 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Decouple from the imx_media_buffer structure defined in shared helpers
by duplicating it in the imx7-media-csi driver. No functional change
intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 41 ++++++++++++++--------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index b116f6ab96f0..bd1bc3fada2e 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -171,6 +171,19 @@ enum imx_csi_model {
 	IMX7_CSI_IMX8MQ,
 };
 
+struct imx7_csi_vb2_buffer {
+	struct vb2_v4l2_buffer vbuf;
+	struct list_head list;
+};
+
+static inline struct imx7_csi_vb2_buffer *
+to_imx7_csi_vb2_buffer(struct vb2_buffer *vb)
+{
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
+	return container_of(vbuf, struct imx7_csi_vb2_buffer, vbuf);
+}
+
 struct imx7_csi {
 	struct device *dev;
 
@@ -209,7 +222,7 @@ struct imx7_csi {
 	spinlock_t q_lock;			/* Protect ready_q */
 
 	/* Buffers and streaming state */
-	struct imx_media_buffer *active_vb2_buf[2];
+	struct imx7_csi_vb2_buffer *active_vb2_buf[2];
 	struct imx_media_dma_buf underrun_buf;
 
 	bool is_streaming;
@@ -355,11 +368,11 @@ static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 		imx7_csi_reg_write(csi, phys, CSI_CSIDMASA_FB1);
 }
 
-static struct imx_media_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi);
+static struct imx7_csi_vb2_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi);
 
 static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 {
-	struct imx_media_buffer *buf;
+	struct imx7_csi_vb2_buffer *buf;
 	struct vb2_buffer *vb2_buf;
 	dma_addr_t phys[2];
 	int i;
@@ -382,7 +395,7 @@ static void imx7_csi_setup_vb2_buf(struct imx7_csi *csi)
 static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,
 					 enum vb2_buffer_state return_status)
 {
-	struct imx_media_buffer *buf;
+	struct imx7_csi_vb2_buffer *buf;
 	int i;
 
 	/* return any remaining active frames with return_status */
@@ -652,7 +665,7 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi)
 static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = &csi->vdev;
-	struct imx_media_buffer *done, *next;
+	struct imx7_csi_vb2_buffer *done, *next;
 	struct vb2_buffer *vb;
 	dma_addr_t phys;
 
@@ -997,7 +1010,7 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq,
 
 static int imx7_csi_video_buf_init(struct vb2_buffer *vb)
 {
-	struct imx_media_buffer *buf = to_imx_media_vb(vb);
+	struct imx7_csi_vb2_buffer *buf = to_imx7_csi_vb2_buffer(vb);
 
 	INIT_LIST_HEAD(&buf->list);
 
@@ -1024,7 +1037,7 @@ static int imx7_csi_video_buf_prepare(struct vb2_buffer *vb)
 static void imx7_csi_video_buf_queue(struct vb2_buffer *vb)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
-	struct imx_media_buffer *buf = to_imx_media_vb(vb);
+	struct imx7_csi_vb2_buffer *buf = to_imx7_csi_vb2_buffer(vb);
 	unsigned long flags;
 
 	spin_lock_irqsave(&csi->q_lock, flags);
@@ -1073,7 +1086,7 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 					  unsigned int count)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
-	struct imx_media_buffer *buf, *tmp;
+	struct imx7_csi_vb2_buffer *buf, *tmp;
 	unsigned long flags;
 	int ret;
 
@@ -1115,8 +1128,8 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq,
 static void imx7_csi_video_stop_streaming(struct vb2_queue *vq)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
-	struct imx_media_buffer *frame;
-	struct imx_media_buffer *tmp;
+	struct imx7_csi_vb2_buffer *frame;
+	struct imx7_csi_vb2_buffer *tmp;
 	unsigned long flags;
 
 	mutex_lock(&csi->mdev.graph_mutex);
@@ -1205,16 +1218,16 @@ static const struct v4l2_file_operations imx7_csi_video_fops = {
  * Video Capture Device - Init & Cleanup
  */
 
-static struct imx_media_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi)
+static struct imx7_csi_vb2_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi)
 {
-	struct imx_media_buffer *buf = NULL;
+	struct imx7_csi_vb2_buffer *buf = NULL;
 	unsigned long flags;
 
 	spin_lock_irqsave(&csi->q_lock, flags);
 
 	/* get next queued buffer */
 	if (!list_empty(&csi->ready_q)) {
-		buf = list_entry(csi->ready_q.next, struct imx_media_buffer,
+		buf = list_entry(csi->ready_q.next, struct imx7_csi_vb2_buffer,
 				 list);
 		list_del(&buf->list);
 	}
@@ -1336,7 +1349,7 @@ static int imx7_csi_video_init(struct imx7_csi *csi)
 	vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 	vq->io_modes = VB2_MMAP | VB2_DMABUF;
 	vq->drv_priv = csi;
-	vq->buf_struct_size = sizeof(struct imx_media_buffer);
+	vq->buf_struct_size = sizeof(struct imx7_csi_vb2_buffer);
 	vq->ops = &imx7_csi_video_qops;
 	vq->mem_ops = &vb2_dma_contig_memops;
 	vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 28/50] staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (26 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 27/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 29/50] staging: media: imx: imx7-media-csi: Store imx7_csi in drv data Laurent Pinchart
                   ` (24 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Now that the driver doesn't use any helper that relies on the
imx_media_video_dev structure anymore, merge its fields directly in the
imx7_csi structure. Update all the users accordingly, and drop the list
field that isn't used by the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 121 ++++++++++-----------
 1 file changed, 57 insertions(+), 64 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index bd1bc3fada2e..14683a15e003 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -212,9 +212,13 @@ struct imx7_csi {
 	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
 
 	/* Video device */
-	struct imx_media_video_dev vdev;	/* Video device */
+	struct video_device *vdev;		/* Video device */
 	struct media_pad vdev_pad;		/* Video device pad */
 
+	struct v4l2_pix_format vdev_fmt;	/* The user format */
+	const struct imx_media_pixfmt *vdev_cc;
+	struct v4l2_rect vdev_compose;		/* The compose rectangle */
+
 	struct mutex vdev_mutex;		/* Protect vdev operations */
 
 	struct vb2_queue q;			/* The videobuf2 queue */
@@ -413,11 +417,10 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,
 
 static int imx7_csi_dma_setup(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = &csi->vdev;
 	int ret;
 
 	ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,
-				      vdev->fmt.sizeimage);
+				      csi->vdev_fmt.sizeimage);
 	if (ret < 0) {
 		v4l2_warn(&csi->sd, "consider increasing the CMA area\n");
 		return ret;
@@ -464,8 +467,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 
 static void imx7_csi_configure(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = &csi->vdev;
-	struct v4l2_pix_format *out_pix = &vdev->fmt;
+	struct v4l2_pix_format *out_pix = &csi->vdev_fmt;
 	int width = out_pix->width;
 	u32 stride = 0;
 	u32 cr3 = BIT_FRMCNT_RST;
@@ -664,14 +666,13 @@ static void imx7_csi_error_recovery(struct imx7_csi *csi)
 
 static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 {
-	struct imx_media_video_dev *vdev = &csi->vdev;
 	struct imx7_csi_vb2_buffer *done, *next;
 	struct vb2_buffer *vb;
 	dma_addr_t phys;
 
 	done = csi->active_vb2_buf[csi->buf_num];
 	if (done) {
-		done->vbuf.field = vdev->fmt.field;
+		done->vbuf.field = csi->vdev_fmt.field;
 		done->vbuf.sequence = csi->frame_sequence;
 		vb = &done->vbuf.vb2_buf;
 		vb->timestamp = ktime_get_ns();
@@ -829,7 +830,7 @@ static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh,
 {
 	struct imx7_csi *csi = video_drvdata(file);
 
-	f->fmt.pix = csi->vdev.fmt;
+	f->fmt.pix = csi->vdev_fmt;
 
 	return 0;
 }
@@ -896,10 +897,10 @@ static int imx7_csi_video_s_fmt_vid_cap(struct file *file, void *fh,
 		return -EBUSY;
 	}
 
-	cc = __imx7_csi_video_try_fmt(&f->fmt.pix, &csi->vdev.compose);
+	cc = __imx7_csi_video_try_fmt(&f->fmt.pix, &csi->vdev_compose);
 
-	csi->vdev.cc = cc;
-	csi->vdev.fmt = f->fmt.pix;
+	csi->vdev_cc = cc;
+	csi->vdev_fmt = f->fmt.pix;
 
 	return 0;
 }
@@ -914,7 +915,7 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh,
 	case V4L2_SEL_TGT_COMPOSE_DEFAULT:
 	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
 		/* The compose rectangle is fixed to the source format. */
-		s->r = csi->vdev.compose;
+		s->r = csi->vdev_compose;
 		break;
 	case V4L2_SEL_TGT_COMPOSE_PADDED:
 		/*
@@ -924,8 +925,8 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh,
 		 */
 		s->r.left = 0;
 		s->r.top = 0;
-		s->r.width = csi->vdev.fmt.width;
-		s->r.height = csi->vdev.fmt.height;
+		s->r.width = csi->vdev_fmt.width;
+		s->r.height = csi->vdev_fmt.height;
 		break;
 	default:
 		return -EINVAL;
@@ -982,7 +983,7 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq,
 				      struct device *alloc_devs[])
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vq);
-	struct v4l2_pix_format *pix = &csi->vdev.fmt;
+	struct v4l2_pix_format *pix = &csi->vdev_fmt;
 	unsigned int count = *nbuffers;
 
 	if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -1020,7 +1021,7 @@ static int imx7_csi_video_buf_init(struct vb2_buffer *vb)
 static int imx7_csi_video_buf_prepare(struct vb2_buffer *vb)
 {
 	struct imx7_csi *csi = vb2_get_drv_priv(vb->vb2_queue);
-	struct v4l2_pix_format *pix = &csi->vdev.fmt;
+	struct v4l2_pix_format *pix = &csi->vdev_fmt;
 
 	if (vb2_plane_size(vb, 0) < pix->sizeimage) {
 		dev_err(csi->dev,
@@ -1063,12 +1064,12 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	/*
 	 * Verify that the media bus size matches the size set on the video
 	 * node. It is sufficient to check the compose rectangle size without
-	 * checking the rounded size from vdev.fmt, as the rounded size is
+	 * checking the rounded size from pix_fmt, as the rounded size is
 	 * derived directly from the compose rectangle size, and will thus
 	 * always match if the compose rectangle matches.
 	 */
-	if (csi->vdev.compose.width != fmt_src.format.width ||
-	    csi->vdev.compose.height != fmt_src.format.height)
+	if (csi->vdev_compose.width != fmt_src.format.width ||
+	    csi->vdev_compose.height != fmt_src.format.height)
 		return -EPIPE;
 
 	/*
@@ -1076,7 +1077,7 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	 * set on the video node.
 	 */
 	cc = imx7_csi_video_find_format(fmt_src.format.code, 0);
-	if (!cc || csi->vdev.cc->cs != cc->cs)
+	if (!cc || csi->vdev_cc->cs != cc->cs)
 		return -EPIPE;
 
 	return 0;
@@ -1164,7 +1165,6 @@ static const struct vb2_ops imx7_csi_video_qops = {
 static int imx7_csi_video_open(struct file *file)
 {
 	struct imx7_csi *csi = video_drvdata(file);
-	struct video_device *vfd = csi->vdev.vfd;
 	int ret;
 
 	if (mutex_lock_interruptible(&csi->vdev_mutex))
@@ -1176,7 +1176,7 @@ static int imx7_csi_video_open(struct file *file)
 		goto out;
 	}
 
-	ret = v4l2_pipeline_pm_get(&vfd->entity);
+	ret = v4l2_pipeline_pm_get(&csi->vdev->entity);
 	if (ret)
 		v4l2_fh_release(file);
 
@@ -1188,7 +1188,6 @@ static int imx7_csi_video_open(struct file *file)
 static int imx7_csi_video_release(struct file *file)
 {
 	struct imx7_csi *csi = video_drvdata(file);
-	struct video_device *vfd = csi->vdev.vfd;
 	struct vb2_queue *vq = &csi->q;
 
 	mutex_lock(&csi->vdev_mutex);
@@ -1198,7 +1197,7 @@ static int imx7_csi_video_release(struct file *file)
 		vq->owner = NULL;
 	}
 
-	v4l2_pipeline_pm_put(&vfd->entity);
+	v4l2_pipeline_pm_put(&csi->vdev->entity);
 
 	v4l2_fh_release(file);
 	mutex_unlock(&csi->vdev_mutex);
@@ -1243,18 +1242,16 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 		.pad = IMX7_CSI_PAD_SRC,
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
-	struct imx_media_video_dev *vdev = &csi->vdev;
-
 	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
 	fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
 	fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
 
-	imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt, &fmt_src.format, NULL);
-	vdev->compose.width = fmt_src.format.width;
-	vdev->compose.height = fmt_src.format.height;
+	imx_media_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
+	csi->vdev_compose.width = fmt_src.format.width;
+	csi->vdev_compose.height = fmt_src.format.height;
 
-	vdev->cc = imx_media_find_pixel_format(vdev->fmt.pixelformat,
-					       PIXFMT_SEL_ANY);
+	csi->vdev_cc = imx_media_find_pixel_format(csi->vdev_fmt.pixelformat,
+						   PIXFMT_SEL_ANY);
 
 	return 0;
 }
@@ -1263,10 +1260,10 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
 {
 	struct v4l2_subdev *sd = &csi->sd;
 	struct v4l2_device *v4l2_dev = sd->v4l2_dev;
-	struct video_device *vfd = csi->vdev.vfd;
+	struct video_device *vdev = csi->vdev;
 	int ret;
 
-	vfd->v4l2_dev = v4l2_dev;
+	vdev->v4l2_dev = v4l2_dev;
 
 	/* Initialize the default format and compose rectangle. */
 	ret = imx7_csi_video_init_format(csi);
@@ -1274,22 +1271,22 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
 		return ret;
 
 	/* Register the video device. */
-	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
+	ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
 	if (ret) {
 		dev_err(csi->dev, "Failed to register video device\n");
 		return ret;
 	}
 
-	dev_info(csi->dev, "Registered %s as /dev/%s\n", vfd->name,
-		 video_device_node_name(vfd));
+	dev_info(csi->dev, "Registered %s as /dev/%s\n", vdev->name,
+		 video_device_node_name(vdev));
 
 	/* Create the link from the CSI subdev to the video device. */
-	ret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC, &vfd->entity,
-				    0, MEDIA_LNK_FL_IMMUTABLE |
+	ret = media_create_pad_link(&sd->entity, IMX7_CSI_PAD_SRC,
+				    &vdev->entity, 0, MEDIA_LNK_FL_IMMUTABLE |
 				    MEDIA_LNK_FL_ENABLED);
 	if (ret) {
 		dev_err(csi->dev, "failed to create link to device node\n");
-		video_unregister_device(vfd);
+		video_unregister_device(vdev);
 		return ret;
 	}
 
@@ -1298,15 +1295,13 @@ static int imx7_csi_video_register(struct imx7_csi *csi)
 
 static void imx7_csi_video_unregister(struct imx7_csi *csi)
 {
-	struct video_device *vfd = csi->vdev.vfd;
-
-	media_entity_cleanup(&vfd->entity);
-	video_unregister_device(vfd);
+	media_entity_cleanup(&csi->vdev->entity);
+	video_unregister_device(csi->vdev);
 }
 
 static int imx7_csi_video_init(struct imx7_csi *csi)
 {
-	struct video_device *vfd;
+	struct video_device *vdev;
 	struct vb2_queue *vq;
 	int ret;
 
@@ -1315,32 +1310,31 @@ static int imx7_csi_video_init(struct imx7_csi *csi)
 	spin_lock_init(&csi->q_lock);
 
 	/* Allocate and initialize the video device. */
-	vfd = video_device_alloc();
-	if (!vfd)
+	vdev = video_device_alloc();
+	if (!vdev)
 		return -ENOMEM;
 
-	vfd->fops = &imx7_csi_video_fops;
-	vfd->ioctl_ops = &imx7_csi_video_ioctl_ops;
-	vfd->minor = -1;
-	vfd->release = video_device_release;
-	vfd->vfl_dir = VFL_DIR_RX;
-	vfd->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
-	vfd->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
+	vdev->fops = &imx7_csi_video_fops;
+	vdev->ioctl_ops = &imx7_csi_video_ioctl_ops;
+	vdev->minor = -1;
+	vdev->release = video_device_release;
+	vdev->vfl_dir = VFL_DIR_RX;
+	vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
+	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING
 			 | V4L2_CAP_IO_MC;
-	vfd->lock = &csi->vdev_mutex;
-	vfd->queue = &csi->q;
+	vdev->lock = &csi->vdev_mutex;
+	vdev->queue = &csi->q;
 
-	snprintf(vfd->name, sizeof(vfd->name), "%s capture", csi->sd.name);
+	snprintf(vdev->name, sizeof(vdev->name), "%s capture", csi->sd.name);
 
-	video_set_drvdata(vfd, csi);
-	csi->vdev.vfd = vfd;
-	INIT_LIST_HEAD(&csi->vdev.list);
+	video_set_drvdata(vdev, csi);
+	csi->vdev = vdev;
 
 	/* Initialize the video device pad. */
 	csi->vdev_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_pads_init(&vfd->entity, 1, &csi->vdev_pad);
+	ret = media_entity_pads_init(&vdev->entity, 1, &csi->vdev_pad);
 	if (ret) {
-		video_device_release(vfd);
+		video_device_release(vdev);
 		return ret;
 	}
 
@@ -1360,7 +1354,7 @@ static int imx7_csi_video_init(struct imx7_csi *csi)
 	ret = vb2_queue_init(vq);
 	if (ret) {
 		dev_err(csi->dev, "vb2_queue_init failed\n");
-		video_device_release(vfd);
+		video_device_release(vdev);
 		return ret;
 	}
 
@@ -1629,8 +1623,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 				      struct v4l2_subdev_format *sink_fmt)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct imx_media_video_dev *vdev = &csi->vdev;
-	const struct v4l2_pix_format *out_pix = &vdev->fmt;
+	const struct v4l2_pix_format *out_pix = &csi->vdev_fmt;
 	struct media_pad *pad = NULL;
 	unsigned int i;
 	int ret;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 29/50] staging: media: imx: imx7-media-csi: Store imx7_csi in drv data
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (27 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 28/50] staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 30/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf Laurent Pinchart
                   ` (23 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Replace the subdev pointer stored in platform drv data with the imx7_csi
pointer. Drop a now redundant dev_set_drvdata() call.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 14683a15e003..5a5157d8b27b 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1842,8 +1842,6 @@ static int imx7_csi_media_dev_init(struct imx7_csi *csi)
 {
 	int ret;
 
-	dev_set_drvdata(csi->dev, csi);
-
 	strscpy(csi->mdev.model, "imx-media", sizeof(csi->mdev.model));
 	csi->mdev.ops = &imx7_csi_media_ops;
 	csi->mdev.dev = csi->dev;
@@ -1913,7 +1911,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	csi->dev = dev;
-	platform_set_drvdata(pdev, &csi->sd);
+	platform_set_drvdata(pdev, csi);
 
 	spin_lock_init(&csi->irqlock);
 	mutex_init(&csi->lock);
@@ -1977,14 +1975,13 @@ static int imx7_csi_probe(struct platform_device *pdev)
 
 static int imx7_csi_remove(struct platform_device *pdev)
 {
-	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
-	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
+	struct imx7_csi *csi = platform_get_drvdata(pdev);
 
 	imx7_csi_media_cleanup(csi);
 
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
-	v4l2_async_unregister_subdev(sd);
+	v4l2_async_unregister_subdev(&csi->sd);
 
 	mutex_destroy(&csi->lock);
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 30/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (28 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 29/50] staging: media: imx: imx7-media-csi: Store imx7_csi in drv data Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 31/50] staging: media: imx: imx7-media-csi: Decouple from shared macros Laurent Pinchart
                   ` (22 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

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>
---
 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 5a5157d8b27b..05907d6257a8 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)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 31/50] staging: media: imx: imx7-media-csi: Decouple from shared macros
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (29 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 30/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 32/50] staging: media: imx: imx7-media-csi: Drop error message on alloc failure Laurent Pinchart
                   ` (21 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Decouple from the IMX7_CSI_VIDEO_DEF_PIX_WIDTH,
IMX7_CSI_VIDEO_DEF_PIX_HEIGHT and IMX_MEDIA_EOF_TIMEOUT macros defined
in shared helpers by duplicating them in the imx7-media-csi driver, with
a rename to avoid name clashes. No functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 05907d6257a8..2106a72ebe85 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -165,6 +165,9 @@
 #define IMX7_CSI_VIDEO_NAME		"imx-capture"
 /* In bytes, per queue */
 #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
+#define IMX7_CSI_VIDEO_DEF_PIX_WIDTH	640
+#define IMX7_CSI_VIDEO_DEF_PIX_HEIGHT	480
+#define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
 enum imx_csi_model {
 	IMX7_CSI_IMX7 = 0,
@@ -488,7 +491,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 	/*
 	 * and then wait for interrupt handler to mark completion.
 	 */
-	timeout_jiffies = msecs_to_jiffies(IMX_MEDIA_EOF_TIMEOUT);
+	timeout_jiffies = msecs_to_jiffies(IMX7_CSI_VIDEO_EOF_TIMEOUT);
 	ret = wait_for_completion_timeout(&csi->last_eof_completion,
 					  timeout_jiffies);
 	if (ret == 0)
@@ -1275,8 +1278,8 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
 	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
-	fmt_src.format.width = IMX_MEDIA_DEF_PIX_WIDTH;
-	fmt_src.format.height = IMX_MEDIA_DEF_PIX_HEIGHT;
+	fmt_src.format.width = IMX7_CSI_VIDEO_DEF_PIX_WIDTH;
+	fmt_src.format.height = IMX7_CSI_VIDEO_DEF_PIX_HEIGHT;
 
 	imx_media_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
 	csi->vdev_compose.width = fmt_src.format.width;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 32/50] staging: media: imx: imx7-media-csi: Drop error message on alloc failure
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (30 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 31/50] staging: media: imx: imx7-media-csi: Decouple from shared macros Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 33/50] staging: media: imx: imx7-media-csi: Import format helpers Laurent Pinchart
                   ` (20 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The kernel memory allocators already complain loudly to the log when
allocation fails. There's no need for an additional message.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 2106a72ebe85..e5dc9525fa52 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -442,10 +442,8 @@ static int imx7_csi_alloc_dma_buf(struct imx7_csi *csi,
 	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__);
+	if (!buf->virt)
 		return -ENOMEM;
-	}
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 33/50] staging: media: imx: imx7-media-csi: Import format helpers
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (31 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 32/50] staging: media: imx: imx7-media-csi: Drop error message on alloc failure Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 34/50] staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv field Laurent Pinchart
                   ` (19 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

To prepare for code refactoring, copy the format helpers used by this
driver from imx-media-utils.c. Rename structures and functions to avoid
name clashes, no functional change intended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 660 +++++++++++++++++++--
 1 file changed, 615 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index e5dc9525fa52..42f1485b3550 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -174,6 +174,23 @@ enum imx_csi_model {
 	IMX7_CSI_IMX8MQ,
 };
 
+struct imx7_csi_pixfmt {
+	/* the in-memory FourCC pixel format */
+	u32     fourcc;
+	/*
+	 * the set of equivalent media bus codes for the fourcc.
+	 * NOTE! codes pointer is NULL for in-memory-only formats.
+	 */
+	const u32 *codes;
+	int     bpp;     /* total bpp */
+	/* cycles per pixel for generic (bayer) formats for the parallel bus */
+	int	cycles;
+	enum ipu_color_space cs;
+	bool    planar;  /* is a planar format */
+	bool    bayer;   /* is a raw bayer format */
+	bool    ipufmt;  /* is one of the IPU internal formats */
+};
+
 struct imx7_csi_vb2_buffer {
 	struct vb2_v4l2_buffer vbuf;
 	struct list_head list;
@@ -218,14 +235,14 @@ struct imx7_csi {
 	struct media_pad pad[IMX7_CSI_PADS_NUM];
 
 	struct v4l2_mbus_framefmt format_mbus[IMX7_CSI_PADS_NUM];
-	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
+	const struct imx7_csi_pixfmt *cc[IMX7_CSI_PADS_NUM];
 
 	/* Video device */
 	struct video_device *vdev;		/* Video device */
 	struct media_pad vdev_pad;		/* Video device pad */
 
 	struct v4l2_pix_format vdev_fmt;	/* The user format */
-	const struct imx_media_pixfmt *vdev_cc;
+	const struct imx7_csi_pixfmt *vdev_cc;
 	struct v4l2_rect vdev_compose;		/* The compose rectangle */
 
 	struct mutex vdev_mutex;		/* Protect vdev operations */
@@ -784,30 +801,518 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+/* -----------------------------------------------------------------------------
+ * Format Helpers
+ */
+
+#define IMX_BUS_FMTS(fmt...) (const u32[]) {fmt, 0}
+
+enum imx7_csi_pixfmt_sel {
+	IMX7_CSI_PIXFMT_SEL_YUV   = BIT(0), /* select YUV formats */
+	IMX7_CSI_PIXFMT_SEL_RGB   = BIT(1), /* select RGB formats */
+	IMX7_CSI_PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */
+	IMX7_CSI_PIXFMT_SEL_IPU   = BIT(3), /* select IPU-internal formats */
+	IMX7_CSI_PIXFMT_SEL_YUV_RGB = IMX7_CSI_PIXFMT_SEL_YUV
+				    | IMX7_CSI_PIXFMT_SEL_RGB,
+	IMX7_CSI_PIXFMT_SEL_ANY = IMX7_CSI_PIXFMT_SEL_YUV
+				| IMX7_CSI_PIXFMT_SEL_RGB
+				| IMX7_CSI_PIXFMT_SEL_BAYER,
+};
+
+/*
+ * List of supported pixel formats for the subdevs.
+ */
+static const struct imx7_csi_pixfmt pixel_formats[] = {
+	/*** YUV formats start here ***/
+	{
+		.fourcc	= V4L2_PIX_FMT_UYVY,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_UYVY8_2X8,
+			MEDIA_BUS_FMT_UYVY8_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 16,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_YUYV,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_YUYV8_2X8,
+			MEDIA_BUS_FMT_YUYV8_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 16,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_YUV420,
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 12,
+		.planar = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_YVU420,
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 12,
+		.planar = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_YUV422P,
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 16,
+		.planar = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_NV12,
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 12,
+		.planar = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_NV16,
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 16,
+		.planar = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_YUV32,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32),
+		.cs     = IPUV3_COLORSPACE_YUV,
+		.bpp    = 32,
+		.ipufmt = true,
+	},
+	/*** RGB formats start here ***/
+	{
+		.fourcc	= V4L2_PIX_FMT_RGB565,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.cycles = 2,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_RGB24,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_RGB888_1X24,
+			MEDIA_BUS_FMT_RGB888_2X12_LE
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 24,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_BGR24,
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 24,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_XRGB32,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 32,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_XRGB32,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 32,
+		.ipufmt = true,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_XBGR32,
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 32,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_BGRX32,
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 32,
+	}, {
+		.fourcc	= V4L2_PIX_FMT_RGBX32,
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 32,
+	},
+	/*** raw bayer and grayscale formats start here ***/
+	{
+		.fourcc = V4L2_PIX_FMT_SBGGR8,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG8,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG8,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB8,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SBGGR16,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_SBGGR10_1X10,
+			MEDIA_BUS_FMT_SBGGR12_1X12,
+			MEDIA_BUS_FMT_SBGGR14_1X14,
+			MEDIA_BUS_FMT_SBGGR16_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG16,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_SGBRG10_1X10,
+			MEDIA_BUS_FMT_SGBRG12_1X12,
+			MEDIA_BUS_FMT_SGBRG14_1X14,
+			MEDIA_BUS_FMT_SGBRG16_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG16,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_SGRBG10_1X10,
+			MEDIA_BUS_FMT_SGRBG12_1X12,
+			MEDIA_BUS_FMT_SGRBG14_1X14,
+			MEDIA_BUS_FMT_SGRBG16_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB16,
+		.codes  = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_SRGGB10_1X10,
+			MEDIA_BUS_FMT_SRGGB12_1X12,
+			MEDIA_BUS_FMT_SRGGB14_1X14,
+			MEDIA_BUS_FMT_SRGGB16_1X16
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_GREY,
+		.codes = IMX_BUS_FMTS(
+			MEDIA_BUS_FMT_Y8_1X8,
+			MEDIA_BUS_FMT_Y10_1X10,
+			MEDIA_BUS_FMT_Y12_1X12
+		),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_Y10,
+		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_Y12,
+		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	},
+};
+
+/*
+ * Search in the pixel_formats[] array for an entry with the given fourcc
+ * that matches the requested selection criteria and return it.
+ *
+ * @fourcc: Search for an entry with the given fourcc pixel format.
+ * @fmt_sel: Allow entries only with the given selection criteria.
+ */
+static const struct imx7_csi_pixfmt *
+imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
+{
+	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
+	unsigned int i;
+
+	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
+
+	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
+		enum imx7_csi_pixfmt_sel sel;
+
+		if (sel_ipu != fmt->ipufmt)
+			continue;
+
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
+			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+
+		if ((fmt_sel & sel) && fmt->fourcc == fourcc)
+			return fmt;
+	}
+
+	return NULL;
+}
+
+/*
+ * Search in the pixel_formats[] array for an entry with the given media
+ * bus code that matches the requested selection criteria and return it.
+ *
+ * @code: Search for an entry with the given media-bus code.
+ * @fmt_sel: Allow entries only with the given selection criteria.
+ */
+static const struct imx7_csi_pixfmt *
+imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
+{
+	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
+	unsigned int i;
+
+	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
+
+	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
+		enum imx7_csi_pixfmt_sel sel;
+		unsigned int j;
+
+		if (sel_ipu != fmt->ipufmt)
+			continue;
+
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
+			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+
+		if (!(fmt_sel & sel) || !fmt->codes)
+			continue;
+
+		for (j = 0; fmt->codes[j]; j++) {
+			if (code == fmt->codes[j])
+				return fmt;
+		}
+	}
+
+	return NULL;
+}
+
+static inline const struct imx7_csi_pixfmt *
+imx7_csi_find_ipu_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
+{
+	return imx7_csi_find_mbus_format(code, fmt_sel | IMX7_CSI_PIXFMT_SEL_IPU);
+}
+
+/*
+ * Enumerate entries in the pixel_formats[] array that match the
+ * requested selection criteria. Return the fourcc that matches the
+ * selection criteria at the requested match index.
+ *
+ * @fourcc: The returned fourcc that matches the search criteria at
+ *          the requested match index.
+ * @index: The requested match index.
+ * @fmt_sel: Include in the enumeration entries with the given selection
+ *           criteria.
+ * @code: If non-zero, only include in the enumeration entries matching this
+ *	media bus code.
+ */
+static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
+				       enum imx7_csi_pixfmt_sel fmt_sel,
+				       u32 code)
+{
+	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
+	unsigned int i;
+
+	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
+
+	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
+		enum imx7_csi_pixfmt_sel sel;
+
+		if (sel_ipu != fmt->ipufmt)
+			continue;
+
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
+			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+
+		if (!(fmt_sel & sel))
+			continue;
+
+		/*
+		 * If a media bus code is specified, only consider formats that
+		 * match it.
+		 */
+		if (code) {
+			unsigned int j;
+
+			if (!fmt->codes)
+				continue;
+
+			for (j = 0; fmt->codes[j]; j++) {
+				if (code == fmt->codes[j])
+					break;
+			}
+
+			if (!fmt->codes[j])
+				continue;
+		}
+
+		if (index == 0) {
+			*fourcc = fmt->fourcc;
+			return 0;
+		}
+
+		index--;
+	}
+
+	return -EINVAL;
+}
+
+/*
+ * Enumerate entries in the pixel_formats[] array that match the
+ * requested search criteria. Return the media-bus code that matches
+ * the search criteria at the requested match index.
+ *
+ * @code: The returned media-bus code that matches the search criteria at
+ *        the requested match index.
+ * @index: The requested match index.
+ * @fmt_sel: Include in the enumeration entries with the given selection
+ *           criteria.
+ */
+static int imx7_csi_enum_mbus_formats(u32 *code, u32 index,
+				      enum imx7_csi_pixfmt_sel fmt_sel)
+{
+	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
+	unsigned int i;
+
+	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
+
+	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
+		enum imx7_csi_pixfmt_sel sel;
+		unsigned int j;
+
+		if (sel_ipu != fmt->ipufmt)
+			continue;
+
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
+			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+
+		if (!(fmt_sel & sel) || !fmt->codes)
+			continue;
+
+		for (j = 0; fmt->codes[j]; j++) {
+			if (index == 0) {
+				*code = fmt->codes[j];
+				return 0;
+			}
+
+			index--;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
+				  u32 width, u32 height, u32 code, u32 field,
+				  const struct imx7_csi_pixfmt **cc)
+{
+	const struct imx7_csi_pixfmt *lcc;
+
+	mbus->width = width;
+	mbus->height = height;
+	mbus->field = field;
+
+	if (code == 0)
+		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
+
+	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
+	if (!lcc) {
+		lcc = imx7_csi_find_ipu_format(code, IMX7_CSI_PIXFMT_SEL_YUV_RGB);
+		if (!lcc)
+			return -EINVAL;
+	}
+
+	mbus->code = code;
+
+	mbus->colorspace = V4L2_COLORSPACE_SRGB;
+	mbus->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mbus->colorspace);
+	mbus->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mbus->colorspace);
+	mbus->quantization =
+		V4L2_MAP_QUANTIZATION_DEFAULT(lcc->cs == IPUV3_COLORSPACE_RGB,
+					      mbus->colorspace,
+					      mbus->ycbcr_enc);
+
+	if (cc)
+		*cc = lcc;
+
+	return 0;
+}
+
+static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
+					const struct v4l2_mbus_framefmt *mbus,
+					const struct imx7_csi_pixfmt *cc)
+{
+	u32 width;
+	u32 stride;
+
+	if (!cc) {
+		cc = imx7_csi_find_ipu_format(mbus->code,
+					      IMX7_CSI_PIXFMT_SEL_YUV_RGB);
+		if (!cc)
+			cc = imx7_csi_find_mbus_format(mbus->code,
+						       IMX7_CSI_PIXFMT_SEL_ANY);
+		if (!cc)
+			return -EINVAL;
+	}
+
+	/*
+	 * TODO: the IPU currently does not support the AYUV32 format,
+	 * so until it does convert to a supported YUV format.
+	 */
+	if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) {
+		u32 code;
+
+		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
+		cc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_YUV);
+	}
+
+	/* Round up width for minimum burst size */
+	width = round_up(mbus->width, 8);
+
+	/* Round up stride for IDMAC line start address alignment */
+	if (cc->planar)
+		stride = round_up(width, 16);
+	else
+		stride = round_up((width * cc->bpp) >> 3, 8);
+
+	pix->width = width;
+	pix->height = mbus->height;
+	pix->pixelformat = cc->fourcc;
+	pix->colorspace = mbus->colorspace;
+	pix->xfer_func = mbus->xfer_func;
+	pix->ycbcr_enc = mbus->ycbcr_enc;
+	pix->quantization = mbus->quantization;
+	pix->field = mbus->field;
+	pix->bytesperline = stride;
+	pix->sizeimage = cc->planar ? ((stride * pix->height * cc->bpp) >> 3) :
+			 stride * pix->height;
+
+	return 0;
+}
+
 /* -----------------------------------------------------------------------------
  * Video Capture Device - IOCTLs
  */
 
-static const struct imx_media_pixfmt *
+static const struct imx7_csi_pixfmt *
 imx7_csi_video_find_format(u32 code, u32 fourcc)
 {
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 
-	cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
+	cc = imx7_csi_find_ipu_format(code, IMX7_CSI_PIXFMT_SEL_YUV_RGB);
 	if (cc) {
-		enum imx_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
-					    ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
+		enum imx7_csi_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
+						 ? IMX7_CSI_PIXFMT_SEL_YUV
+						 : IMX7_CSI_PIXFMT_SEL_RGB;
 
-		cc = imx_media_find_pixel_format(fourcc, fmt_sel);
+		cc = imx7_csi_find_pixel_format(fourcc, fmt_sel);
 		if (!cc) {
-			imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
-			cc = imx_media_find_pixel_format(fourcc, fmt_sel);
+			imx7_csi_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
+			cc = imx7_csi_find_pixel_format(fourcc, fmt_sel);
 		}
 
 		return cc;
 	}
 
-	return imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
+	return imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
 }
 
 static int imx7_csi_video_querycap(struct file *file, void *fh,
@@ -826,19 +1331,21 @@ static int imx7_csi_video_querycap(struct file *file, void *fh,
 static int imx7_csi_video_enum_fmt_vid_cap(struct file *file, void *fh,
 					   struct v4l2_fmtdesc *f)
 {
-	return imx_media_enum_pixel_formats(&f->pixelformat, f->index,
-					    PIXFMT_SEL_ANY, f->mbus_code);
+	return imx7_csi_enum_pixel_formats(&f->pixelformat, f->index,
+					   IMX7_CSI_PIXFMT_SEL_ANY,
+					   f->mbus_code);
 }
 
 static int imx7_csi_video_enum_framesizes(struct file *file, void *fh,
 					  struct v4l2_frmsizeenum *fsize)
 {
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 
 	if (fsize->index > 0)
 		return -EINVAL;
 
-	cc = imx_media_find_pixel_format(fsize->pixel_format, PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_pixel_format(fsize->pixel_format,
+					IMX7_CSI_PIXFMT_SEL_ANY);
 	if (!cc)
 		return -EINVAL;
 
@@ -868,23 +1375,24 @@ static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static const struct imx_media_pixfmt *
+static const struct imx7_csi_pixfmt *
 __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 			 struct v4l2_rect *compose)
 {
 	struct v4l2_mbus_framefmt fmt_src;
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 
 	/*
 	 * Find the pixel format, default to the first supported format if not
 	 * found.
 	 */
-	cc = imx_media_find_pixel_format(pixfmt->pixelformat, PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat,
+					IMX7_CSI_PIXFMT_SEL_ANY);
 	if (!cc) {
-		imx_media_enum_pixel_formats(&pixfmt->pixelformat, 0,
-					     PIXFMT_SEL_ANY, 0);
-		cc = imx_media_find_pixel_format(pixfmt->pixelformat,
-						 PIXFMT_SEL_ANY);
+		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0,
+					    IMX7_CSI_PIXFMT_SEL_ANY, 0);
+		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat,
+						IMX7_CSI_PIXFMT_SEL_ANY);
 	}
 
 	/* Allow IDMAC interweave but enforce field order from source. */
@@ -902,7 +1410,7 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	}
 
 	v4l2_fill_mbus_format(&fmt_src, pixfmt, 0);
-	imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
+	imx7_csi_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
 
 	if (compose) {
 		compose->width = fmt_src.width;
@@ -923,7 +1431,7 @@ static int imx7_csi_video_s_fmt_vid_cap(struct file *file, void *fh,
 					struct v4l2_format *f)
 {
 	struct imx7_csi *csi = video_drvdata(file);
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 
 	if (vb2_is_busy(&csi->q)) {
 		dev_err(csi->dev, "%s queue busy\n", __func__);
@@ -1084,7 +1592,7 @@ static void imx7_csi_video_buf_queue(struct vb2_buffer *vb)
 static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 {
 	struct v4l2_subdev_format fmt_src;
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 	int ret;
 
 	/* Retrieve the media bus format on the source subdev. */
@@ -1279,12 +1787,12 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 	fmt_src.format.width = IMX7_CSI_VIDEO_DEF_PIX_WIDTH;
 	fmt_src.format.height = IMX7_CSI_VIDEO_DEF_PIX_HEIGHT;
 
-	imx_media_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
+	imx7_csi_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
 	csi->vdev_compose.width = fmt_src.format.width;
 	csi->vdev_compose.height = fmt_src.format.height;
 
-	csi->vdev_cc = imx_media_find_pixel_format(csi->vdev_fmt.pixelformat,
-						   PIXFMT_SEL_ANY);
+	csi->vdev_cc = imx7_csi_find_pixel_format(csi->vdev_fmt.pixelformat,
+						  IMX7_CSI_PIXFMT_SEL_ANY);
 
 	return 0;
 }
@@ -1466,8 +1974,8 @@ static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
 		struct v4l2_mbus_framefmt *mf =
 			imx7_csi_get_format(csi, sd_state, i, which);
 
-		ret = imx_media_init_mbus_fmt(mf, 800, 600, 0, V4L2_FIELD_NONE,
-					      &csi->cc[i]);
+		ret = imx7_csi_init_mbus_fmt(mf, 800, 600, 0, V4L2_FIELD_NONE,
+					     &csi->cc[i]);
 		if (ret < 0)
 			return ret;
 	}
@@ -1490,8 +1998,8 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,
 
 	switch (code->pad) {
 	case IMX7_CSI_PAD_SINK:
-		ret = imx_media_enum_mbus_formats(&code->code, code->index,
-						  PIXFMT_SEL_ANY);
+		ret = imx7_csi_enum_mbus_formats(&code->code, code->index,
+						 IMX7_CSI_PIXFMT_SEL_ANY);
 		break;
 	case IMX7_CSI_PAD_SRC:
 		if (code->index != 0) {
@@ -1536,12 +2044,74 @@ static int imx7_csi_get_fmt(struct v4l2_subdev *sd,
 	return ret;
 }
 
+/*
+ * Default the colorspace in tryfmt to SRGB if set to an unsupported
+ * colorspace or not initialized. Then set the remaining colorimetry
+ * parameters based on the colorspace if they are uninitialized.
+ *
+ * tryfmt->code must be set on entry.
+ *
+ * If this format is destined to be routed through the Image Converter,
+ * Y`CbCr encoding must be fixed. The IC supports only BT.601 Y`CbCr
+ * or Rec.709 Y`CbCr encoding.
+ */
+static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,
+				     bool ic_route)
+{
+	const struct imx7_csi_pixfmt *cc;
+	bool is_rgb = false;
+
+	cc = imx7_csi_find_mbus_format(tryfmt->code, IMX7_CSI_PIXFMT_SEL_ANY);
+	if (!cc)
+		cc = imx7_csi_find_ipu_format(tryfmt->code,
+					      IMX7_CSI_PIXFMT_SEL_YUV_RGB);
+
+	if (cc && cc->cs == IPUV3_COLORSPACE_RGB)
+		is_rgb = true;
+
+	switch (tryfmt->colorspace) {
+	case V4L2_COLORSPACE_SMPTE170M:
+	case V4L2_COLORSPACE_REC709:
+	case V4L2_COLORSPACE_JPEG:
+	case V4L2_COLORSPACE_SRGB:
+	case V4L2_COLORSPACE_BT2020:
+	case V4L2_COLORSPACE_OPRGB:
+	case V4L2_COLORSPACE_DCI_P3:
+	case V4L2_COLORSPACE_RAW:
+		break;
+	default:
+		tryfmt->colorspace = V4L2_COLORSPACE_SRGB;
+		break;
+	}
+
+	if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
+		tryfmt->xfer_func =
+			V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace);
+
+	if (ic_route) {
+		if (tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_601 &&
+		    tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_709)
+			tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
+	} else {
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			tryfmt->ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
+		}
+	}
+
+	if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
+		tryfmt->quantization =
+			V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb,
+						      tryfmt->colorspace,
+						      tryfmt->ycbcr_enc);
+}
+
 static int imx7_csi_try_fmt(struct imx7_csi *csi,
 			    struct v4l2_subdev_state *sd_state,
 			    struct v4l2_subdev_format *sdformat,
-			    const struct imx_media_pixfmt **cc)
+			    const struct imx7_csi_pixfmt **cc)
 {
-	const struct imx_media_pixfmt *in_cc;
+	const struct imx7_csi_pixfmt *in_cc;
 	struct v4l2_mbus_framefmt *in_fmt;
 	u32 code;
 
@@ -1552,8 +2122,8 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 
 	switch (sdformat->pad) {
 	case IMX7_CSI_PAD_SRC:
-		in_cc = imx_media_find_mbus_format(in_fmt->code,
-						   PIXFMT_SEL_ANY);
+		in_cc = imx7_csi_find_mbus_format(in_fmt->code,
+						  IMX7_CSI_PIXFMT_SEL_ANY);
 
 		sdformat->format.width = in_fmt->width;
 		sdformat->format.height = in_fmt->height;
@@ -1567,13 +2137,13 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		sdformat->format.ycbcr_enc = in_fmt->ycbcr_enc;
 		break;
 	case IMX7_CSI_PAD_SINK:
-		*cc = imx_media_find_mbus_format(sdformat->format.code,
-						 PIXFMT_SEL_ANY);
+		*cc = imx7_csi_find_mbus_format(sdformat->format.code,
+						IMX7_CSI_PIXFMT_SEL_ANY);
 		if (!*cc) {
-			imx_media_enum_mbus_formats(&code, 0,
-						    PIXFMT_SEL_YUV_RGB);
-			*cc = imx_media_find_mbus_format(code,
-							 PIXFMT_SEL_YUV_RGB);
+			imx7_csi_enum_mbus_formats(&code, 0,
+						   IMX7_CSI_PIXFMT_SEL_YUV_RGB);
+			*cc = imx7_csi_find_mbus_format(code,
+							IMX7_CSI_PIXFMT_SEL_YUV_RGB);
 			sdformat->format.code = (*cc)->codes[0];
 		}
 
@@ -1584,7 +2154,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		return -EINVAL;
 	}
 
-	imx_media_try_colorimetry(&sdformat->format, false);
+	imx7_csi_try_colorimetry(&sdformat->format, false);
 
 	return 0;
 }
@@ -1594,9 +2164,9 @@ static int imx7_csi_set_fmt(struct v4l2_subdev *sd,
 			    struct v4l2_subdev_format *sdformat)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	const struct imx_media_pixfmt *outcc;
+	const struct imx7_csi_pixfmt *outcc;
 	struct v4l2_mbus_framefmt *outfmt;
-	const struct imx_media_pixfmt *cc;
+	const struct imx7_csi_pixfmt *cc;
 	struct v4l2_mbus_framefmt *fmt;
 	struct v4l2_subdev_format format;
 	int ret = 0;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 34/50] staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv field
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (32 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 33/50] staging: media: imx: imx7-media-csi: Import format helpers Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 35/50] staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorimetry() Laurent Pinchart
                   ` (18 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Replace the enum ipu_color_space cs field in struct imx7_csi_pixfmt with
a bool yuv field. This decouples the driver from the unrelated IPUv3
headers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 71 ++++++++--------------
 1 file changed, 26 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 42f1485b3550..b8ce4fd7c55d 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -185,7 +185,7 @@ struct imx7_csi_pixfmt {
 	int     bpp;     /* total bpp */
 	/* cycles per pixel for generic (bayer) formats for the parallel bus */
 	int	cycles;
-	enum ipu_color_space cs;
+	bool	yuv;
 	bool    planar;  /* is a planar format */
 	bool    bayer;   /* is a raw bayer format */
 	bool    ipufmt;  /* is one of the IPU internal formats */
@@ -830,7 +830,7 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_UYVY8_2X8,
 			MEDIA_BUS_FMT_UYVY8_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 16,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_YUYV,
@@ -838,37 +838,37 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_YUYV8_2X8,
 			MEDIA_BUS_FMT_YUYV8_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 16,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_YUV420,
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 12,
 		.planar = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_YVU420,
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 12,
 		.planar = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_YUV422P,
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 16,
 		.planar = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_NV12,
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 12,
 		.planar = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_NV16,
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 16,
 		.planar = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_YUV32,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32),
-		.cs     = IPUV3_COLORSPACE_YUV,
+		.yuv	= true,
 		.bpp    = 32,
 		.ipufmt = true,
 	},
@@ -876,7 +876,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 	{
 		.fourcc	= V4L2_PIX_FMT_RGB565,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.cycles = 2,
 	}, {
@@ -885,59 +884,48 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_RGB888_1X24,
 			MEDIA_BUS_FMT_RGB888_2X12_LE
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 24,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_BGR24,
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 24,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_XRGB32,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_XRGB32,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 		.ipufmt = true,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_XBGR32,
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_BGRX32,
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_RGBX32,
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 	},
 	/*** raw bayer and grayscale formats start here ***/
 	{
 		.fourcc = V4L2_PIX_FMT_SBGGR8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGBRG8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGRBG8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SRGGB8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
@@ -948,7 +936,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SBGGR14_1X14,
 			MEDIA_BUS_FMT_SBGGR16_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	}, {
@@ -959,7 +946,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SGBRG14_1X14,
 			MEDIA_BUS_FMT_SGBRG16_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	}, {
@@ -970,7 +956,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SGRBG14_1X14,
 			MEDIA_BUS_FMT_SGRBG16_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	}, {
@@ -981,7 +966,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SRGGB14_1X14,
 			MEDIA_BUS_FMT_SRGGB16_1X16
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	}, {
@@ -991,19 +975,16 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_Y10_1X10,
 			MEDIA_BUS_FMT_Y12_1X12
 		),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y10,
 		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y12,
 		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
-		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
 	},
@@ -1031,9 +1012,9 @@ imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
 		if (sel_ipu != fmt->ipufmt)
 			continue;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
-			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
-			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
+		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
+		       IMX7_CSI_PIXFMT_SEL_RGB);
 
 		if ((fmt_sel & sel) && fmt->fourcc == fourcc)
 			return fmt;
@@ -1065,9 +1046,9 @@ imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
 		if (sel_ipu != fmt->ipufmt)
 			continue;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
-			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
-			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
+		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
+		       IMX7_CSI_PIXFMT_SEL_RGB);
 
 		if (!(fmt_sel & sel) || !fmt->codes)
 			continue;
@@ -1116,9 +1097,9 @@ static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
 		if (sel_ipu != fmt->ipufmt)
 			continue;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
-			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
-			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
+		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
+		       IMX7_CSI_PIXFMT_SEL_RGB);
 
 		if (!(fmt_sel & sel))
 			continue;
@@ -1180,9 +1161,9 @@ static int imx7_csi_enum_mbus_formats(u32 *code, u32 index,
 		if (sel_ipu != fmt->ipufmt)
 			continue;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER :
-			((fmt->cs == IPUV3_COLORSPACE_YUV) ?
-			 IMX7_CSI_PIXFMT_SEL_YUV : IMX7_CSI_PIXFMT_SEL_RGB);
+		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
+		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
+		       IMX7_CSI_PIXFMT_SEL_RGB);
 
 		if (!(fmt_sel & sel) || !fmt->codes)
 			continue;
@@ -1226,7 +1207,7 @@ static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 	mbus->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mbus->colorspace);
 	mbus->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mbus->colorspace);
 	mbus->quantization =
-		V4L2_MAP_QUANTIZATION_DEFAULT(lcc->cs == IPUV3_COLORSPACE_RGB,
+		V4L2_MAP_QUANTIZATION_DEFAULT(!lcc->yuv,
 					      mbus->colorspace,
 					      mbus->ycbcr_enc);
 
@@ -1257,7 +1238,7 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 	 * TODO: the IPU currently does not support the AYUV32 format,
 	 * so until it does convert to a supported YUV format.
 	 */
-	if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) {
+	if (cc->ipufmt && cc->yuv) {
 		u32 code;
 
 		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
@@ -1299,7 +1280,7 @@ imx7_csi_video_find_format(u32 code, u32 fourcc)
 
 	cc = imx7_csi_find_ipu_format(code, IMX7_CSI_PIXFMT_SEL_YUV_RGB);
 	if (cc) {
-		enum imx7_csi_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
+		enum imx7_csi_pixfmt_sel fmt_sel = cc->yuv
 						 ? IMX7_CSI_PIXFMT_SEL_YUV
 						 : IMX7_CSI_PIXFMT_SEL_RGB;
 
@@ -1618,7 +1599,7 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	 * set on the video node.
 	 */
 	cc = imx7_csi_video_find_format(fmt_src.format.code, 0);
-	if (!cc || csi->vdev_cc->cs != cc->cs)
+	if (!cc || csi->vdev_cc->yuv != cc->yuv)
 		return -EPIPE;
 
 	return 0;
@@ -2066,7 +2047,7 @@ static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,
 		cc = imx7_csi_find_ipu_format(tryfmt->code,
 					      IMX7_CSI_PIXFMT_SEL_YUV_RGB);
 
-	if (cc && cc->cs == IPUV3_COLORSPACE_RGB)
+	if (cc && !cc->yuv)
 		is_rgb = true;
 
 	switch (tryfmt->colorspace) {
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 35/50] staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorimetry()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (33 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 34/50] staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv field Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 36/50] staging: media: imx: imx7-media-csi: Drop IPU-only formats Laurent Pinchart
                   ` (17 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx7_csi_try_colorimetry() function supports the unrelated image
converter hardware as it originates from shared helpers. Drop that.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index b8ce4fd7c55d..c8ff259452b1 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -2031,13 +2031,8 @@ static int imx7_csi_get_fmt(struct v4l2_subdev *sd,
  * parameters based on the colorspace if they are uninitialized.
  *
  * tryfmt->code must be set on entry.
- *
- * If this format is destined to be routed through the Image Converter,
- * Y`CbCr encoding must be fixed. The IC supports only BT.601 Y`CbCr
- * or Rec.709 Y`CbCr encoding.
  */
-static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,
-				     bool ic_route)
+static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt)
 {
 	const struct imx7_csi_pixfmt *cc;
 	bool is_rgb = false;
@@ -2069,16 +2064,9 @@ static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,
 		tryfmt->xfer_func =
 			V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace);
 
-	if (ic_route) {
-		if (tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_601 &&
-		    tryfmt->ycbcr_enc != V4L2_YCBCR_ENC_709)
-			tryfmt->ycbcr_enc = V4L2_YCBCR_ENC_601;
-	} else {
-		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
-			tryfmt->ycbcr_enc =
-				V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
-		}
-	}
+	if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+		tryfmt->ycbcr_enc =
+			V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
 
 	if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
 		tryfmt->quantization =
@@ -2135,7 +2123,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		return -EINVAL;
 	}
 
-	imx7_csi_try_colorimetry(&sdformat->format, false);
+	imx7_csi_try_colorimetry(&sdformat->format);
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 36/50] staging: media: imx: imx7-media-csi: Drop IPU-only formats
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (34 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 35/50] staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorimetry() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 37/50] staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats Laurent Pinchart
                   ` (16 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The formats specific to the IPUv3 are not supported by the CSI bridge.
Drop them, along with the related code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 98 ++--------------------
 1 file changed, 6 insertions(+), 92 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index c8ff259452b1..17259922a082 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -188,7 +188,6 @@ struct imx7_csi_pixfmt {
 	bool	yuv;
 	bool    planar;  /* is a planar format */
 	bool    bayer;   /* is a raw bayer format */
-	bool    ipufmt;  /* is one of the IPU internal formats */
 };
 
 struct imx7_csi_vb2_buffer {
@@ -811,7 +810,6 @@ enum imx7_csi_pixfmt_sel {
 	IMX7_CSI_PIXFMT_SEL_YUV   = BIT(0), /* select YUV formats */
 	IMX7_CSI_PIXFMT_SEL_RGB   = BIT(1), /* select RGB formats */
 	IMX7_CSI_PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */
-	IMX7_CSI_PIXFMT_SEL_IPU   = BIT(3), /* select IPU-internal formats */
 	IMX7_CSI_PIXFMT_SEL_YUV_RGB = IMX7_CSI_PIXFMT_SEL_YUV
 				    | IMX7_CSI_PIXFMT_SEL_RGB,
 	IMX7_CSI_PIXFMT_SEL_ANY = IMX7_CSI_PIXFMT_SEL_YUV
@@ -865,12 +863,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		.yuv	= true,
 		.bpp    = 16,
 		.planar = true,
-	}, {
-		.fourcc = V4L2_PIX_FMT_YUV32,
-		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32),
-		.yuv	= true,
-		.bpp    = 32,
-		.ipufmt = true,
 	},
 	/*** RGB formats start here ***/
 	{
@@ -892,11 +884,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		.fourcc	= V4L2_PIX_FMT_XRGB32,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
 		.bpp    = 32,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_XRGB32,
-		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
-		.bpp    = 32,
-		.ipufmt = true,
 	}, {
 		.fourcc	= V4L2_PIX_FMT_XBGR32,
 		.bpp    = 32,
@@ -1000,18 +987,12 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 static const struct imx7_csi_pixfmt *
 imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
 {
-	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
 	unsigned int i;
 
-	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
-
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
 		enum imx7_csi_pixfmt_sel sel;
 
-		if (sel_ipu != fmt->ipufmt)
-			continue;
-
 		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
 		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
 		       IMX7_CSI_PIXFMT_SEL_RGB);
@@ -1033,19 +1014,13 @@ imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
 static const struct imx7_csi_pixfmt *
 imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
 {
-	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
 	unsigned int i;
 
-	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
-
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
 		enum imx7_csi_pixfmt_sel sel;
 		unsigned int j;
 
-		if (sel_ipu != fmt->ipufmt)
-			continue;
-
 		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
 		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
 		       IMX7_CSI_PIXFMT_SEL_RGB);
@@ -1062,12 +1037,6 @@ imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
 	return NULL;
 }
 
-static inline const struct imx7_csi_pixfmt *
-imx7_csi_find_ipu_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
-{
-	return imx7_csi_find_mbus_format(code, fmt_sel | IMX7_CSI_PIXFMT_SEL_IPU);
-}
-
 /*
  * Enumerate entries in the pixel_formats[] array that match the
  * requested selection criteria. Return the fourcc that matches the
@@ -1085,18 +1054,12 @@ static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
 				       enum imx7_csi_pixfmt_sel fmt_sel,
 				       u32 code)
 {
-	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
 	unsigned int i;
 
-	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
-
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
 		enum imx7_csi_pixfmt_sel sel;
 
-		if (sel_ipu != fmt->ipufmt)
-			continue;
-
 		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
 		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
 		       IMX7_CSI_PIXFMT_SEL_RGB);
@@ -1148,19 +1111,13 @@ static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
 static int imx7_csi_enum_mbus_formats(u32 *code, u32 index,
 				      enum imx7_csi_pixfmt_sel fmt_sel)
 {
-	bool sel_ipu = fmt_sel & IMX7_CSI_PIXFMT_SEL_IPU;
 	unsigned int i;
 
-	fmt_sel &= ~IMX7_CSI_PIXFMT_SEL_IPU;
-
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
 		enum imx7_csi_pixfmt_sel sel;
 		unsigned int j;
 
-		if (sel_ipu != fmt->ipufmt)
-			continue;
-
 		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
 		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
 		       IMX7_CSI_PIXFMT_SEL_RGB);
@@ -1195,11 +1152,8 @@ static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
 
 	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
-	if (!lcc) {
-		lcc = imx7_csi_find_ipu_format(code, IMX7_CSI_PIXFMT_SEL_YUV_RGB);
-		if (!lcc)
-			return -EINVAL;
-	}
+	if (!lcc)
+		return -EINVAL;
 
 	mbus->code = code;
 
@@ -1225,26 +1179,12 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 	u32 stride;
 
 	if (!cc) {
-		cc = imx7_csi_find_ipu_format(mbus->code,
-					      IMX7_CSI_PIXFMT_SEL_YUV_RGB);
-		if (!cc)
-			cc = imx7_csi_find_mbus_format(mbus->code,
-						       IMX7_CSI_PIXFMT_SEL_ANY);
+		cc = imx7_csi_find_mbus_format(mbus->code,
+					       IMX7_CSI_PIXFMT_SEL_ANY);
 		if (!cc)
 			return -EINVAL;
 	}
 
-	/*
-	 * TODO: the IPU currently does not support the AYUV32 format,
-	 * so until it does convert to a supported YUV format.
-	 */
-	if (cc->ipufmt && cc->yuv) {
-		u32 code;
-
-		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
-		cc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_YUV);
-	}
-
 	/* Round up width for minimum burst size */
 	width = round_up(mbus->width, 8);
 
@@ -1273,29 +1213,6 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
  * Video Capture Device - IOCTLs
  */
 
-static const struct imx7_csi_pixfmt *
-imx7_csi_video_find_format(u32 code, u32 fourcc)
-{
-	const struct imx7_csi_pixfmt *cc;
-
-	cc = imx7_csi_find_ipu_format(code, IMX7_CSI_PIXFMT_SEL_YUV_RGB);
-	if (cc) {
-		enum imx7_csi_pixfmt_sel fmt_sel = cc->yuv
-						 ? IMX7_CSI_PIXFMT_SEL_YUV
-						 : IMX7_CSI_PIXFMT_SEL_RGB;
-
-		cc = imx7_csi_find_pixel_format(fourcc, fmt_sel);
-		if (!cc) {
-			imx7_csi_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
-			cc = imx7_csi_find_pixel_format(fourcc, fmt_sel);
-		}
-
-		return cc;
-	}
-
-	return imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
-}
-
 static int imx7_csi_video_querycap(struct file *file, void *fh,
 				   struct v4l2_capability *cap)
 {
@@ -1598,7 +1515,8 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	 * Verify that the media bus code is compatible with the pixel format
 	 * set on the video node.
 	 */
-	cc = imx7_csi_video_find_format(fmt_src.format.code, 0);
+	cc = imx7_csi_find_mbus_format(fmt_src.format.code,
+				       IMX7_CSI_PIXFMT_SEL_ANY);
 	if (!cc || csi->vdev_cc->yuv != cc->yuv)
 		return -EPIPE;
 
@@ -2038,10 +1956,6 @@ static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt)
 	bool is_rgb = false;
 
 	cc = imx7_csi_find_mbus_format(tryfmt->code, IMX7_CSI_PIXFMT_SEL_ANY);
-	if (!cc)
-		cc = imx7_csi_find_ipu_format(tryfmt->code,
-					      IMX7_CSI_PIXFMT_SEL_YUV_RGB);
-
 	if (cc && !cc->yuv)
 		is_rgb = true;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 37/50] staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (35 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 36/50] staging: media: imx: imx7-media-csi: Drop IPU-only formats Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 38/50] staging: media: imx: imx7-media-csi: Make default formats consistent Laurent Pinchart
                   ` (15 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

A large number of formats defined in the pixel_formats array are not
supported, as shown by the switch-case check in
imx7_csi_pad_link_validate(). Drop them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 55 ----------------------
 1 file changed, 55 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 17259922a082..6704e5d4d43b 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -838,61 +838,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		),
 		.yuv	= true,
 		.bpp    = 16,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_YUV420,
-		.yuv	= true,
-		.bpp    = 12,
-		.planar = true,
-	}, {
-		.fourcc = V4L2_PIX_FMT_YVU420,
-		.yuv	= true,
-		.bpp    = 12,
-		.planar = true,
-	}, {
-		.fourcc = V4L2_PIX_FMT_YUV422P,
-		.yuv	= true,
-		.bpp    = 16,
-		.planar = true,
-	}, {
-		.fourcc = V4L2_PIX_FMT_NV12,
-		.yuv	= true,
-		.bpp    = 12,
-		.planar = true,
-	}, {
-		.fourcc = V4L2_PIX_FMT_NV16,
-		.yuv	= true,
-		.bpp    = 16,
-		.planar = true,
-	},
-	/*** RGB formats start here ***/
-	{
-		.fourcc	= V4L2_PIX_FMT_RGB565,
-		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE),
-		.bpp    = 16,
-		.cycles = 2,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_RGB24,
-		.codes  = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_RGB888_1X24,
-			MEDIA_BUS_FMT_RGB888_2X12_LE
-		),
-		.bpp    = 24,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_BGR24,
-		.bpp    = 24,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_XRGB32,
-		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
-		.bpp    = 32,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_XBGR32,
-		.bpp    = 32,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_BGRX32,
-		.bpp    = 32,
-	}, {
-		.fourcc	= V4L2_PIX_FMT_RGBX32,
-		.bpp    = 32,
 	},
 	/*** raw bayer and grayscale formats start here ***/
 	{
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 38/50] staging: media: imx: imx7-media-csi: Make default formats consistent
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (36 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 37/50] staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code Laurent Pinchart
                   ` (14 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Use the same default image width and height for both the CSI subdev and
the video node to achieve a consistent default through the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 6704e5d4d43b..bcf57aff3572 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -165,10 +165,11 @@
 #define IMX7_CSI_VIDEO_NAME		"imx-capture"
 /* In bytes, per queue */
 #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
-#define IMX7_CSI_VIDEO_DEF_PIX_WIDTH	640
-#define IMX7_CSI_VIDEO_DEF_PIX_HEIGHT	480
 #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
+#define IMX7_CSI_DEF_PIX_WIDTH		640
+#define IMX7_CSI_DEF_PIX_HEIGHT		480
+
 enum imx_csi_model {
 	IMX7_CSI_IMX7 = 0,
 	IMX7_CSI_IMX8MQ,
@@ -303,7 +304,8 @@ static void imx7_csi_init_default(struct imx7_csi *csi)
 	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
 	imx7_csi_reg_write(csi, BIT_FRMCNT_RST, CSI_CSICR3);
 
-	imx7_csi_reg_write(csi, BIT_IMAGE_WIDTH(800) | BIT_IMAGE_HEIGHT(600),
+	imx7_csi_reg_write(csi, BIT_IMAGE_WIDTH(IMX7_CSI_DEF_PIX_WIDTH) |
+			   BIT_IMAGE_HEIGHT(IMX7_CSI_DEF_PIX_HEIGHT),
 			   CSI_CSIIMAG_PARA);
 
 	imx7_csi_reg_write(csi, BIT_DMA_REFLASH_RFF, CSI_CSICR3);
@@ -1628,8 +1630,8 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
 	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
-	fmt_src.format.width = IMX7_CSI_VIDEO_DEF_PIX_WIDTH;
-	fmt_src.format.height = IMX7_CSI_VIDEO_DEF_PIX_HEIGHT;
+	fmt_src.format.width = IMX7_CSI_DEF_PIX_WIDTH;
+	fmt_src.format.height = IMX7_CSI_DEF_PIX_HEIGHT;
 
 	imx7_csi_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &fmt_src.format, NULL);
 	csi->vdev_compose.width = fmt_src.format.width;
@@ -1818,8 +1820,9 @@ static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
 		struct v4l2_mbus_framefmt *mf =
 			imx7_csi_get_format(csi, sd_state, i, which);
 
-		ret = imx7_csi_init_mbus_fmt(mf, 800, 600, 0, V4L2_FIELD_NONE,
-					     &csi->cc[i]);
+		ret = imx7_csi_init_mbus_fmt(mf, IMX7_CSI_DEF_PIX_WIDTH,
+					     IMX7_CSI_DEF_PIX_HEIGHT, 0,
+					     V4L2_FIELD_NONE, &csi->cc[i]);
 		if (ret < 0)
 			return ret;
 	}
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (37 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 38/50] staging: media: imx: imx7-media-csi: Make default formats consistent Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-11 13:22   ` Alexander Stein
  2022-07-07  0:19   ` [PATCH v1.1 " Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 40/50] staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt Laurent Pinchart
                   ` (13 subsequent siblings)
  52 siblings, 2 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Define a macro for the default media bus code and use it through the
driver to replace a hardcoded value and a dynamic query from the
pixel_formats table.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index bcf57aff3572..f2e85e9851e4 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -167,6 +167,7 @@
 #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
 #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
+#define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
 #define IMX7_CSI_DEF_PIX_WIDTH		640
 #define IMX7_CSI_DEF_PIX_HEIGHT		480
 
@@ -1096,7 +1097,7 @@ static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 	mbus->field = field;
 
 	if (code == 0)
-		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
+		code = IMX7_CSI_DEF_MBUS_CODE;
 
 	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
 	if (!lcc)
@@ -1629,7 +1630,7 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 		.pad = IMX7_CSI_PAD_SRC,
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
-	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
+	fmt_src.format.code = IMX7_CSI_DEF_MBUS_CODE;
 	fmt_src.format.width = IMX7_CSI_DEF_PIX_WIDTH;
 	fmt_src.format.height = IMX7_CSI_DEF_PIX_HEIGHT;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 40/50] staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (38 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 41/50] staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors Laurent Pinchart
                   ` (12 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

When trying a format on the subdev sink pad, if the requested media bus
code isn't supported, fallback to the default with a simpler logic.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index f2e85e9851e4..f3b9ce03318f 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1972,11 +1972,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		*cc = imx7_csi_find_mbus_format(sdformat->format.code,
 						IMX7_CSI_PIXFMT_SEL_ANY);
 		if (!*cc) {
-			imx7_csi_enum_mbus_formats(&code, 0,
-						   IMX7_CSI_PIXFMT_SEL_YUV_RGB);
+			code = IMX7_CSI_DEF_MBUS_CODE;
 			*cc = imx7_csi_find_mbus_format(code,
-							IMX7_CSI_PIXFMT_SEL_YUV_RGB);
-			sdformat->format.code = (*cc)->codes[0];
+							IMX7_CSI_PIXFMT_SEL_ANY);
+			sdformat->format.code = code;
 		}
 
 		if (sdformat->format.field != V4L2_FIELD_INTERLACED)
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 41/50] staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (39 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 40/50] staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 42/50] staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields Laurent Pinchart
                   ` (11 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

All the format lookup functions are called with a ANY selector, drop
selector support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 105 +++++----------------
 1 file changed, 22 insertions(+), 83 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index f3b9ce03318f..ab101d82c253 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -809,17 +809,6 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 
 #define IMX_BUS_FMTS(fmt...) (const u32[]) {fmt, 0}
 
-enum imx7_csi_pixfmt_sel {
-	IMX7_CSI_PIXFMT_SEL_YUV   = BIT(0), /* select YUV formats */
-	IMX7_CSI_PIXFMT_SEL_RGB   = BIT(1), /* select RGB formats */
-	IMX7_CSI_PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */
-	IMX7_CSI_PIXFMT_SEL_YUV_RGB = IMX7_CSI_PIXFMT_SEL_YUV
-				    | IMX7_CSI_PIXFMT_SEL_RGB,
-	IMX7_CSI_PIXFMT_SEL_ANY = IMX7_CSI_PIXFMT_SEL_YUV
-				| IMX7_CSI_PIXFMT_SEL_RGB
-				| IMX7_CSI_PIXFMT_SEL_BAYER,
-};
-
 /*
  * List of supported pixel formats for the subdevs.
  */
@@ -927,25 +916,16 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 
 /*
  * Search in the pixel_formats[] array for an entry with the given fourcc
- * that matches the requested selection criteria and return it.
- *
- * @fourcc: Search for an entry with the given fourcc pixel format.
- * @fmt_sel: Allow entries only with the given selection criteria.
+ * return it.
  */
-static const struct imx7_csi_pixfmt *
-imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
+static const struct imx7_csi_pixfmt *imx7_csi_find_pixel_format(u32 fourcc)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
-		enum imx7_csi_pixfmt_sel sel;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
-		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
-		       IMX7_CSI_PIXFMT_SEL_RGB);
-
-		if ((fmt_sel & sel) && fmt->fourcc == fourcc)
+		if (fmt->fourcc == fourcc)
 			return fmt;
 	}
 
@@ -954,26 +934,17 @@ imx7_csi_find_pixel_format(u32 fourcc, enum imx7_csi_pixfmt_sel fmt_sel)
 
 /*
  * Search in the pixel_formats[] array for an entry with the given media
- * bus code that matches the requested selection criteria and return it.
- *
- * @code: Search for an entry with the given media-bus code.
- * @fmt_sel: Allow entries only with the given selection criteria.
+ * bus code and return it.
  */
-static const struct imx7_csi_pixfmt *
-imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
+static const struct imx7_csi_pixfmt *imx7_csi_find_mbus_format(u32 code)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
-		enum imx7_csi_pixfmt_sel sel;
 		unsigned int j;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
-		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
-		       IMX7_CSI_PIXFMT_SEL_RGB);
-
-		if (!(fmt_sel & sel) || !fmt->codes)
+		if (!fmt->codes)
 			continue;
 
 		for (j = 0; fmt->codes[j]; j++) {
@@ -993,27 +964,15 @@ imx7_csi_find_mbus_format(u32 code, enum imx7_csi_pixfmt_sel fmt_sel)
  * @fourcc: The returned fourcc that matches the search criteria at
  *          the requested match index.
  * @index: The requested match index.
- * @fmt_sel: Include in the enumeration entries with the given selection
- *           criteria.
  * @code: If non-zero, only include in the enumeration entries matching this
  *	media bus code.
  */
-static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
-				       enum imx7_csi_pixfmt_sel fmt_sel,
-				       u32 code)
+static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index, u32 code)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
-		enum imx7_csi_pixfmt_sel sel;
-
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
-		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
-		       IMX7_CSI_PIXFMT_SEL_RGB);
-
-		if (!(fmt_sel & sel))
-			continue;
 
 		/*
 		 * If a media bus code is specified, only consider formats that
@@ -1053,24 +1012,16 @@ static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index,
  * @code: The returned media-bus code that matches the search criteria at
  *        the requested match index.
  * @index: The requested match index.
- * @fmt_sel: Include in the enumeration entries with the given selection
- *           criteria.
  */
-static int imx7_csi_enum_mbus_formats(u32 *code, u32 index,
-				      enum imx7_csi_pixfmt_sel fmt_sel)
+static int imx7_csi_enum_mbus_formats(u32 *code, u32 index)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
 		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
-		enum imx7_csi_pixfmt_sel sel;
 		unsigned int j;
 
-		sel = fmt->bayer ? IMX7_CSI_PIXFMT_SEL_BAYER
-		    : (fmt->yuv ? IMX7_CSI_PIXFMT_SEL_YUV :
-		       IMX7_CSI_PIXFMT_SEL_RGB);
-
-		if (!(fmt_sel & sel) || !fmt->codes)
+		if (!fmt->codes)
 			continue;
 
 		for (j = 0; fmt->codes[j]; j++) {
@@ -1099,7 +1050,7 @@ static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 	if (code == 0)
 		code = IMX7_CSI_DEF_MBUS_CODE;
 
-	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
+	lcc = imx7_csi_find_mbus_format(code);
 	if (!lcc)
 		return -EINVAL;
 
@@ -1127,8 +1078,7 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 	u32 stride;
 
 	if (!cc) {
-		cc = imx7_csi_find_mbus_format(mbus->code,
-					       IMX7_CSI_PIXFMT_SEL_ANY);
+		cc = imx7_csi_find_mbus_format(mbus->code);
 		if (!cc)
 			return -EINVAL;
 	}
@@ -1178,7 +1128,6 @@ static int imx7_csi_video_enum_fmt_vid_cap(struct file *file, void *fh,
 					   struct v4l2_fmtdesc *f)
 {
 	return imx7_csi_enum_pixel_formats(&f->pixelformat, f->index,
-					   IMX7_CSI_PIXFMT_SEL_ANY,
 					   f->mbus_code);
 }
 
@@ -1190,8 +1139,7 @@ static int imx7_csi_video_enum_framesizes(struct file *file, void *fh,
 	if (fsize->index > 0)
 		return -EINVAL;
 
-	cc = imx7_csi_find_pixel_format(fsize->pixel_format,
-					IMX7_CSI_PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_pixel_format(fsize->pixel_format);
 	if (!cc)
 		return -EINVAL;
 
@@ -1232,13 +1180,10 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	 * Find the pixel format, default to the first supported format if not
 	 * found.
 	 */
-	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat,
-					IMX7_CSI_PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	if (!cc) {
-		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0,
-					    IMX7_CSI_PIXFMT_SEL_ANY, 0);
-		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat,
-						IMX7_CSI_PIXFMT_SEL_ANY);
+		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0, 0);
+		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	}
 
 	/* Allow IDMAC interweave but enforce field order from source. */
@@ -1463,8 +1408,7 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi)
 	 * Verify that the media bus code is compatible with the pixel format
 	 * set on the video node.
 	 */
-	cc = imx7_csi_find_mbus_format(fmt_src.format.code,
-				       IMX7_CSI_PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_mbus_format(fmt_src.format.code);
 	if (!cc || csi->vdev_cc->yuv != cc->yuv)
 		return -EPIPE;
 
@@ -1638,8 +1582,7 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 	csi->vdev_compose.width = fmt_src.format.width;
 	csi->vdev_compose.height = fmt_src.format.height;
 
-	csi->vdev_cc = imx7_csi_find_pixel_format(csi->vdev_fmt.pixelformat,
-						  IMX7_CSI_PIXFMT_SEL_ANY);
+	csi->vdev_cc = imx7_csi_find_pixel_format(csi->vdev_fmt.pixelformat);
 
 	return 0;
 }
@@ -1846,8 +1789,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,
 
 	switch (code->pad) {
 	case IMX7_CSI_PAD_SINK:
-		ret = imx7_csi_enum_mbus_formats(&code->code, code->index,
-						 IMX7_CSI_PIXFMT_SEL_ANY);
+		ret = imx7_csi_enum_mbus_formats(&code->code, code->index);
 		break;
 	case IMX7_CSI_PAD_SRC:
 		if (code->index != 0) {
@@ -1904,7 +1846,7 @@ static void imx7_csi_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt)
 	const struct imx7_csi_pixfmt *cc;
 	bool is_rgb = false;
 
-	cc = imx7_csi_find_mbus_format(tryfmt->code, IMX7_CSI_PIXFMT_SEL_ANY);
+	cc = imx7_csi_find_mbus_format(tryfmt->code);
 	if (cc && !cc->yuv)
 		is_rgb = true;
 
@@ -1954,8 +1896,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 
 	switch (sdformat->pad) {
 	case IMX7_CSI_PAD_SRC:
-		in_cc = imx7_csi_find_mbus_format(in_fmt->code,
-						  IMX7_CSI_PIXFMT_SEL_ANY);
+		in_cc = imx7_csi_find_mbus_format(in_fmt->code);
 
 		sdformat->format.width = in_fmt->width;
 		sdformat->format.height = in_fmt->height;
@@ -1969,12 +1910,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		sdformat->format.ycbcr_enc = in_fmt->ycbcr_enc;
 		break;
 	case IMX7_CSI_PAD_SINK:
-		*cc = imx7_csi_find_mbus_format(sdformat->format.code,
-						IMX7_CSI_PIXFMT_SEL_ANY);
+		*cc = imx7_csi_find_mbus_format(sdformat->format.code);
 		if (!*cc) {
 			code = IMX7_CSI_DEF_MBUS_CODE;
-			*cc = imx7_csi_find_mbus_format(code,
-							IMX7_CSI_PIXFMT_SEL_ANY);
+			*cc = imx7_csi_find_mbus_format(code);
 			sdformat->format.code = code;
 		}
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 42/50] staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (40 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 41/50] staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 43/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt() Laurent Pinchart
                   ` (10 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The imx7_csi_pixfmt cycles field is never used nor set, the bayer field
is never used, and the planar field is never set. Drop them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 23 ++--------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ab101d82c253..b3fa3e20873b 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -185,11 +185,7 @@ struct imx7_csi_pixfmt {
 	 */
 	const u32 *codes;
 	int     bpp;     /* total bpp */
-	/* cycles per pixel for generic (bayer) formats for the parallel bus */
-	int	cycles;
 	bool	yuv;
-	bool    planar;  /* is a planar format */
-	bool    bayer;   /* is a raw bayer format */
 };
 
 struct imx7_csi_vb2_buffer {
@@ -836,22 +832,18 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		.fourcc = V4L2_PIX_FMT_SBGGR8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8),
 		.bpp    = 8,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGBRG8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8),
 		.bpp    = 8,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGRBG8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8),
 		.bpp    = 8,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SRGGB8,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8),
 		.bpp    = 8,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SBGGR16,
 		.codes  = IMX_BUS_FMTS(
@@ -861,7 +853,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SBGGR16_1X16
 		),
 		.bpp    = 16,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGBRG16,
 		.codes  = IMX_BUS_FMTS(
@@ -871,7 +862,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SGBRG16_1X16
 		),
 		.bpp    = 16,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SGRBG16,
 		.codes  = IMX_BUS_FMTS(
@@ -881,7 +871,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SGRBG16_1X16
 		),
 		.bpp    = 16,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_SRGGB16,
 		.codes  = IMX_BUS_FMTS(
@@ -891,7 +880,6 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_SRGGB16_1X16
 		),
 		.bpp    = 16,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_GREY,
 		.codes = IMX_BUS_FMTS(
@@ -900,17 +888,14 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 			MEDIA_BUS_FMT_Y12_1X12
 		),
 		.bpp    = 8,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y10,
 		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
 		.bpp    = 16,
-		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y12,
 		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
 		.bpp    = 16,
-		.bayer  = true,
 	},
 };
 
@@ -1087,10 +1072,7 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 	width = round_up(mbus->width, 8);
 
 	/* Round up stride for IDMAC line start address alignment */
-	if (cc->planar)
-		stride = round_up(width, 16);
-	else
-		stride = round_up((width * cc->bpp) >> 3, 8);
+	stride = round_up((width * cc->bpp) >> 3, 8);
 
 	pix->width = width;
 	pix->height = mbus->height;
@@ -1101,8 +1083,7 @@ static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 	pix->quantization = mbus->quantization;
 	pix->field = mbus->field;
 	pix->bytesperline = stride;
-	pix->sizeimage = cc->planar ? ((stride * pix->height * cc->bpp) >> 3) :
-			 stride * pix->height;
+	pix->sizeimage = stride * pix->height;
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 43/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (41 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 42/50] staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt Laurent Pinchart
                   ` (9 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Inline the imx7_csi_init_mbus_fmt() function in its only caller. This
allows simplifying the code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 54 ++++++----------------
 1 file changed, 15 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index b3fa3e20873b..bc3a87656117 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1022,39 +1022,6 @@ static int imx7_csi_enum_mbus_formats(u32 *code, u32 index)
 	return -EINVAL;
 }
 
-static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
-				  u32 width, u32 height, u32 code, u32 field,
-				  const struct imx7_csi_pixfmt **cc)
-{
-	const struct imx7_csi_pixfmt *lcc;
-
-	mbus->width = width;
-	mbus->height = height;
-	mbus->field = field;
-
-	if (code == 0)
-		code = IMX7_CSI_DEF_MBUS_CODE;
-
-	lcc = imx7_csi_find_mbus_format(code);
-	if (!lcc)
-		return -EINVAL;
-
-	mbus->code = code;
-
-	mbus->colorspace = V4L2_COLORSPACE_SRGB;
-	mbus->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mbus->colorspace);
-	mbus->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mbus->colorspace);
-	mbus->quantization =
-		V4L2_MAP_QUANTIZATION_DEFAULT(!lcc->yuv,
-					      mbus->colorspace,
-					      mbus->ycbcr_enc);
-
-	if (cc)
-		*cc = lcc;
-
-	return 0;
-}
-
 static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 					const struct v4l2_mbus_framefmt *mbus,
 					const struct imx7_csi_pixfmt *cc)
@@ -1738,18 +1705,27 @@ static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
 	const enum v4l2_subdev_format_whence which =
 		sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	int ret;
+	const struct imx7_csi_pixfmt *cc;
 	int i;
 
+	cc = imx7_csi_find_mbus_format(IMX7_CSI_DEF_MBUS_CODE);
+
 	for (i = 0; i < IMX7_CSI_PADS_NUM; i++) {
 		struct v4l2_mbus_framefmt *mf =
 			imx7_csi_get_format(csi, sd_state, i, which);
 
-		ret = imx7_csi_init_mbus_fmt(mf, IMX7_CSI_DEF_PIX_WIDTH,
-					     IMX7_CSI_DEF_PIX_HEIGHT, 0,
-					     V4L2_FIELD_NONE, &csi->cc[i]);
-		if (ret < 0)
-			return ret;
+		mf->code = IMX7_CSI_DEF_MBUS_CODE;
+		mf->width = IMX7_CSI_DEF_PIX_WIDTH;
+		mf->height = IMX7_CSI_DEF_PIX_HEIGHT;
+		mf->field = V4L2_FIELD_NONE;
+
+		mf->colorspace = V4L2_COLORSPACE_SRGB;
+		mf->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mf->colorspace);
+		mf->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mf->colorspace);
+		mf->quantization = V4L2_MAP_QUANTIZATION_DEFAULT(!cc->yuv,
+					mf->colorspace, mf->ycbcr_enc);
+
+		csi->cc[i] = cc;
 	}
 
 	return 0;
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (42 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 43/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-11 13:27   ` Alexander Stein
  2022-07-07  0:20   ` [PATCH v1.1 " Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 45/50] staging: media: imx: imx7-media-csi: Fix list of supported formats Laurent Pinchart
                   ` (8 subsequent siblings)
  52 siblings, 2 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

When trying a format on the video node, if the requested pixel format
isn't supported, fallback to the default with a simpler logic.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index bc3a87656117..0fb5e0c03396 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -168,6 +168,7 @@
 #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
 #define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
+#define IMX7_CSI_DEF_PIX_FORMAT		V4L2_PIX_FMT_UYVY
 #define IMX7_CSI_DEF_PIX_WIDTH		640
 #define IMX7_CSI_DEF_PIX_HEIGHT		480
 
@@ -1130,7 +1131,7 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	 */
 	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	if (!cc) {
-		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0, 0);
+		pixfmt->pixelformat = IMX7_CSI_DEF_PIX_FORMAT;
 		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	}
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 45/50] staging: media: imx: imx7-media-csi: Fix list of supported formats
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (43 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 46/50] staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support Laurent Pinchart
                   ` (7 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The list of supported formats comes from helpers shared with the i.MX6
IPUv3 and is incorrect in multiple regards:

- 10-, 12- and 14-bit Bayer formats are stored in memory as SBGGR10,
  SBGGR12 and SBGGR14 respectively (plus components permutations), not
  SBGGR16. Same thing for greyscale formats.
- 16-bit RAW formats are not supported by the hardware.

Fix the supported formats table.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 106 ++++++++++++---------
 1 file changed, 61 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 0fb5e0c03396..1bb60f245861 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -846,56 +846,64 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8),
 		.bpp    = 8,
 	}, {
-		.fourcc = V4L2_PIX_FMT_SBGGR16,
-		.codes  = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_SBGGR10_1X10,
-			MEDIA_BUS_FMT_SBGGR12_1X12,
-			MEDIA_BUS_FMT_SBGGR14_1X14,
-			MEDIA_BUS_FMT_SBGGR16_1X16
-		),
-		.bpp    = 16,
-	}, {
-		.fourcc = V4L2_PIX_FMT_SGBRG16,
-		.codes  = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_SGBRG10_1X10,
-			MEDIA_BUS_FMT_SGBRG12_1X12,
-			MEDIA_BUS_FMT_SGBRG14_1X14,
-			MEDIA_BUS_FMT_SGBRG16_1X16
-		),
-		.bpp    = 16,
-	}, {
-		.fourcc = V4L2_PIX_FMT_SGRBG16,
-		.codes  = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_SGRBG10_1X10,
-			MEDIA_BUS_FMT_SGRBG12_1X12,
-			MEDIA_BUS_FMT_SGRBG14_1X14,
-			MEDIA_BUS_FMT_SGRBG16_1X16
-		),
-		.bpp    = 16,
-	}, {
-		.fourcc = V4L2_PIX_FMT_SRGGB16,
-		.codes  = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_SRGGB10_1X10,
-			MEDIA_BUS_FMT_SRGGB12_1X12,
-			MEDIA_BUS_FMT_SRGGB14_1X14,
-			MEDIA_BUS_FMT_SRGGB16_1X16
-		),
+		.fourcc = V4L2_PIX_FMT_SBGGR10,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR10_1X10),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG10,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG10_1X10),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG10,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG10_1X10),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB10,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB10_1X10),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SBGGR12,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR12_1X12),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG12,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG12_1X12),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG12,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG12_1X12),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB12,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB12_1X12),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SBGGR14,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR14_1X14),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG14,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG14_1X14),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG14,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG14_1X14),
+		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB14,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB14_1X14),
 		.bpp    = 16,
 	}, {
 		.fourcc = V4L2_PIX_FMT_GREY,
-		.codes = IMX_BUS_FMTS(
-			MEDIA_BUS_FMT_Y8_1X8,
-			MEDIA_BUS_FMT_Y10_1X10,
-			MEDIA_BUS_FMT_Y12_1X12
-		),
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y8_1X8),
 		.bpp    = 8,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y10,
-		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
 		.bpp    = 16,
 	}, {
 		.fourcc = V4L2_PIX_FMT_Y12,
-		.codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
 		.bpp    = 16,
 	},
 };
@@ -2015,10 +2023,18 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	case V4L2_PIX_FMT_SGBRG8:
 	case V4L2_PIX_FMT_SGRBG8:
 	case V4L2_PIX_FMT_SRGGB8:
-	case V4L2_PIX_FMT_SBGGR16:
-	case V4L2_PIX_FMT_SGBRG16:
-	case V4L2_PIX_FMT_SGRBG16:
-	case V4L2_PIX_FMT_SRGGB16:
+	case V4L2_PIX_FMT_SBGGR10:
+	case V4L2_PIX_FMT_SGBRG10:
+	case V4L2_PIX_FMT_SGRBG10:
+	case V4L2_PIX_FMT_SRGGB10:
+	case V4L2_PIX_FMT_SBGGR12:
+	case V4L2_PIX_FMT_SGBRG12:
+	case V4L2_PIX_FMT_SGRBG12:
+	case V4L2_PIX_FMT_SRGGB12:
+	case V4L2_PIX_FMT_SBGGR14:
+	case V4L2_PIX_FMT_SGBRG14:
+	case V4L2_PIX_FMT_SGRBG14:
+	case V4L2_PIX_FMT_SRGGB14:
 		break;
 
 	default:
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 46/50] staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (44 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 45/50] staging: media: imx: imx7-media-csi: Fix list of supported formats Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 47/50] staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation Laurent Pinchart
                   ` (6 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The device supports 14-bit greyscale formats the same way it supports
14-bit Bayer formats.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 1bb60f245861..4d8e3c0a3633 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -905,6 +905,10 @@ static const struct imx7_csi_pixfmt pixel_formats[] = {
 		.fourcc = V4L2_PIX_FMT_Y12,
 		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
 		.bpp    = 16,
+	}, {
+		.fourcc = V4L2_PIX_FMT_Y14,
+		.codes  = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y14_1X14),
+		.bpp    = 16,
 	},
 };
 
@@ -2019,6 +2023,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	case V4L2_PIX_FMT_GREY:
 	case V4L2_PIX_FMT_Y10:
 	case V4L2_PIX_FMT_Y12:
+	case V4L2_PIX_FMT_Y14:
 	case V4L2_PIX_FMT_SBGGR8:
 	case V4L2_PIX_FMT_SGBRG8:
 	case V4L2_PIX_FMT_SGRBG8:
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 47/50] staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (45 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 46/50] staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 48/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats() Laurent Pinchart
                   ` (5 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The driver won't accept unsupported pixel formats, there's thus no need
to validate it in imx7_csi_pad_link_validate().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 33 ----------------------
 1 file changed, 33 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 4d8e3c0a3633..8be6f40588af 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1966,7 +1966,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 				      struct v4l2_subdev_format *sink_fmt)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	const struct v4l2_pix_format *out_pix = &csi->vdev_fmt;
 	struct media_pad *pad = NULL;
 	unsigned int i;
 	int ret;
@@ -2016,38 +2015,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 		break;
 	}
 
-	/* Validate the sink link, ensure the pixel format is supported. */
-	switch (out_pix->pixelformat) {
-	case V4L2_PIX_FMT_UYVY:
-	case V4L2_PIX_FMT_YUYV:
-	case V4L2_PIX_FMT_GREY:
-	case V4L2_PIX_FMT_Y10:
-	case V4L2_PIX_FMT_Y12:
-	case V4L2_PIX_FMT_Y14:
-	case V4L2_PIX_FMT_SBGGR8:
-	case V4L2_PIX_FMT_SGBRG8:
-	case V4L2_PIX_FMT_SGRBG8:
-	case V4L2_PIX_FMT_SRGGB8:
-	case V4L2_PIX_FMT_SBGGR10:
-	case V4L2_PIX_FMT_SGBRG10:
-	case V4L2_PIX_FMT_SGRBG10:
-	case V4L2_PIX_FMT_SRGGB10:
-	case V4L2_PIX_FMT_SBGGR12:
-	case V4L2_PIX_FMT_SGBRG12:
-	case V4L2_PIX_FMT_SGRBG12:
-	case V4L2_PIX_FMT_SRGGB12:
-	case V4L2_PIX_FMT_SBGGR14:
-	case V4L2_PIX_FMT_SGBRG14:
-	case V4L2_PIX_FMT_SGRBG14:
-	case V4L2_PIX_FMT_SRGGB14:
-		break;
-
-	default:
-		dev_dbg(csi->dev, "Invalid capture pixel format 0x%08x\n",
-			out_pix->pixelformat);
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 48/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats()
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (46 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 47/50] staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 49/50] staging: media: imx: imx7-media-csi: Drop V4L2 events support Laurent Pinchart
                   ` (4 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Inline the imx7_csi_enum_pixel_formats() function in its only caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 84 +++++++++-------------
 1 file changed, 34 insertions(+), 50 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 8be6f40588af..0bf69933f1bd 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -954,54 +954,6 @@ static const struct imx7_csi_pixfmt *imx7_csi_find_mbus_format(u32 code)
 	return NULL;
 }
 
-/*
- * Enumerate entries in the pixel_formats[] array that match the
- * requested selection criteria. Return the fourcc that matches the
- * selection criteria at the requested match index.
- *
- * @fourcc: The returned fourcc that matches the search criteria at
- *          the requested match index.
- * @index: The requested match index.
- * @code: If non-zero, only include in the enumeration entries matching this
- *	media bus code.
- */
-static int imx7_csi_enum_pixel_formats(u32 *fourcc, u32 index, u32 code)
-{
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
-		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
-
-		/*
-		 * If a media bus code is specified, only consider formats that
-		 * match it.
-		 */
-		if (code) {
-			unsigned int j;
-
-			if (!fmt->codes)
-				continue;
-
-			for (j = 0; fmt->codes[j]; j++) {
-				if (code == fmt->codes[j])
-					break;
-			}
-
-			if (!fmt->codes[j])
-				continue;
-		}
-
-		if (index == 0) {
-			*fourcc = fmt->fourcc;
-			return 0;
-		}
-
-		index--;
-	}
-
-	return -EINVAL;
-}
-
 /*
  * Enumerate entries in the pixel_formats[] array that match the
  * requested search criteria. Return the media-bus code that matches
@@ -1088,8 +1040,40 @@ static int imx7_csi_video_querycap(struct file *file, void *fh,
 static int imx7_csi_video_enum_fmt_vid_cap(struct file *file, void *fh,
 					   struct v4l2_fmtdesc *f)
 {
-	return imx7_csi_enum_pixel_formats(&f->pixelformat, f->index,
-					   f->mbus_code);
+	unsigned int index = f->index;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+		const struct imx7_csi_pixfmt *fmt = &pixel_formats[i];
+
+		/*
+		 * If a media bus code is specified, only consider formats that
+		 * match it.
+		 */
+		if (f->mbus_code) {
+			unsigned int j;
+
+			if (!fmt->codes)
+				continue;
+
+			for (j = 0; fmt->codes[j]; j++) {
+				if (f->mbus_code == fmt->codes[j])
+					break;
+			}
+
+			if (!fmt->codes[j])
+				continue;
+		}
+
+		if (index == 0) {
+			f->pixelformat = fmt->fourcc;
+			return 0;
+		}
+
+		index--;
+	}
+
+	return -EINVAL;
 }
 
 static int imx7_csi_video_enum_framesizes(struct file *file, void *fh,
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 49/50] staging: media: imx: imx7-media-csi: Drop V4L2 events support
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (47 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 48/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats() Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 11:58 ` [PATCH 50/50] staging: media: imx: imx7-media-csi: Drop usage of shared helpers Laurent Pinchart
                   ` (3 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

The only event that the driver allows subscribing to,
V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR, is never generated. Drop events
support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 0bf69933f1bd..ae74256755f4 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -22,14 +22,12 @@
 #include <linux/types.h>
 
 #include <media/v4l2-device.h>
-#include <media/v4l2-event.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
 #include <media/videobuf2-dma-contig.h>
 
-#include <media/imx.h>
 #include "imx-media.h"
 
 #define IMX7_CSI_PAD_SINK		0
@@ -1212,17 +1210,6 @@ static int imx7_csi_video_g_selection(struct file *file, void *fh,
 	return 0;
 }
 
-static int imx7_csi_video_subscribe_event(struct v4l2_fh *fh,
-					  const struct v4l2_event_subscription *sub)
-{
-	switch (sub->type) {
-	case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR:
-		return v4l2_event_subscribe(fh, sub, 0, NULL);
-	default:
-		return -EINVAL;
-	}
-}
-
 static const struct v4l2_ioctl_ops imx7_csi_video_ioctl_ops = {
 	.vidioc_querycap		= imx7_csi_video_querycap,
 
@@ -1244,9 +1231,6 @@ static const struct v4l2_ioctl_ops imx7_csi_video_ioctl_ops = {
 	.vidioc_expbuf			= vb2_ioctl_expbuf,
 	.vidioc_streamon		= vb2_ioctl_streamon,
 	.vidioc_streamoff		= vb2_ioctl_streamoff,
-
-	.vidioc_subscribe_event		= imx7_csi_video_subscribe_event,
-	.vidioc_unsubscribe_event	= v4l2_event_unsubscribe,
 };
 
 /* -----------------------------------------------------------------------------
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH 50/50] staging: media: imx: imx7-media-csi: Drop usage of shared helpers
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (48 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 49/50] staging: media: imx: imx7-media-csi: Drop V4L2 events support Laurent Pinchart
@ 2022-05-10 11:58 ` Laurent Pinchart
  2022-05-10 14:04 ` [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Rui Miguel Silva
                   ` (2 subsequent siblings)
  52 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 11:58 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

None of the shared helpers are used anymore. Make this official by
dropping inclusion of imx-media.h.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ae74256755f4..cf35a2a02d8d 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -28,8 +28,6 @@
 #include <media/v4l2-subdev.h>
 #include <media/videobuf2-dma-contig.h>
 
-#include "imx-media.h"
-
 #define IMX7_CSI_PAD_SINK		0
 #define IMX7_CSI_PAD_SRC		1
 #define IMX7_CSI_PADS_NUM		2
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (49 preceding siblings ...)
  2022-05-10 11:58 ` [PATCH 50/50] staging: media: imx: imx7-media-csi: Drop usage of shared helpers Laurent Pinchart
@ 2022-05-10 14:04 ` Rui Miguel Silva
  2022-05-10 14:18   ` Laurent Pinchart
  2022-05-11 13:36 ` (EXT) " Alexander Stein
  2022-05-16  7:59 ` Alexander Stein
  52 siblings, 1 reply; 69+ messages in thread
From: Rui Miguel Silva @ 2022-05-10 14:04 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Hi Laurent,
Thanks for this small change :).

On Tue, May 10, 2022 at 02:58:09PM +0300, Laurent Pinchart wrote:
> Hello,
> 
> This patch series prepares the imx7-media-csi for destaging by
> decoupling it from the helpers shared with the i.MX6 IPUv3.
> 
> The strategy Paul and I have followed is to import copies of helper code
> and, refactor it within the imx7-media-csi driver, and repeat until no
> more shared helpers are used. There is still room for refactoring and
> simplification of the imx7-media-csi driver, but I believe it is now in
> a state clean enough to be moved out of staging.

I agree.

> 
> The series also includes a few fixes or improvements in supported
> formats that are now made possible thanks to this refactoring. See
> patches 45/50 and 46/50 for details.
> 
> The code size has grown as a result. This is partly offset by code in
> the shared helpers that can be removed or simplified, but I haven't
> starting working on that. The helpers are now used for the i.MX6 IPUv3
> only, so I will leave this exercise to anyone who would be interested in
> destaging that driver as well.
> 
> Some of the items in the TODO file related to the imx7-media-csi driver
> have been addressed. The two remaining items are frame interval monitor
> support and restricting the list of supported formats to the SoC
> version. The former isn't a destaging blocker in my opinion, as the
> feature can be added later if desired (and frame interval monitoring
> should then be moved to the V4L2 core). I believe the latter could also
> be addressed after destaging the driver, but in any case, this is a
> discussion for a future destaging series (which may come as soon as this
> one is accepted).
> 
> Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> imx7/imx8mm media / csi patches" series.

I went over all patches and I have 2 small remarks:

1. Shouldn't we change the connection between imx-media objects and
   imx7-csi also in kconfig? Since at the end of this series they are
   completely independent. Yeah, it can be done in a follow up
   patch on the unstaging, for me that's fine also.

2. Something that caught my eye on patch 2/50. But nothing functional.

Once again many thanks for continuing investing in this code.
for the all series (except patch 2/50):

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>

Cheers,
     Rui
> 
> Laurent Pinchart (48):
>   staging: media: imx: imx7-media-csi: Initialize locks early on
>   staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
>   staging: media: imx: imx7-media-csi: Import notifier helpers
>   staging: media: imx: imx7-media-csi: Drop duplicate link creation
>   staging: media: imx: imx7-media-csi: Drop the imx_media notifier
>   staging: media: imx: imx7-media-csi: Don't populate vdev lists
>   staging: media: imx: imx7-media-csi: Drop unused frame_interval
>   staging: media: imx: imx7-media-csi: Move format init to probe time
>   staging: media: imx: imx7-media-csi: Import video device helpers
>   staging: media: imx: imx7-media-csi: Drop legacy video device support
>   staging: media: imx: imx7-media-csi: Drop unused controls support
>   staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure
>   staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi
>   staging: media: imx: imx7-media-csi: Ensure consistent function prefix
>   staging: media: imx: imx7-media-csi: Don't set subdev group id
>   staging: media: imx: imx7-media-csi: Import imx_media_dev_init()
>     helper
>   staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi
>   staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device
>     call
>   staging: media: imx: imx7-media-csi: Don't initialize unused fields
>   staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()
>   staging: media: imx: imx7-media-csi: Import
>     imx_media_pipeline_set_stream()
>   staging: media: imx: imx7-media-csi: Avoid unnecessary casts
>   staging: media: imx: imx7-media-csi: Inline pipeline start/stop
>   staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi
>   staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer
>   staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into
>     imx7_csi
>   staging: media: imx: imx7-media-csi: Store imx7_csi in drv data
>   staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf
>   staging: media: imx: imx7-media-csi: Decouple from shared macros
>   staging: media: imx: imx7-media-csi: Drop error message on alloc
>     failure
>   staging: media: imx: imx7-media-csi: Import format helpers
>   staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool
>     yuv field
>   staging: media: imx: imx7-media-csi: Drop IC support from
>     imx7_csi_try_colorimetry()
>   staging: media: imx: imx7-media-csi: Drop IPU-only formats
>   staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB
>     formats
>   staging: media: imx: imx7-media-csi: Make default formats consistent
>   staging: media: imx: imx7-media-csi: Define macro for default mbus
>     code
>   staging: media: imx: imx7-media-csi: Simplify default mbus code in
>     try_fmt
>   staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format
>     selectors
>   staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt
>     fields
>   staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()
>   staging: media: imx: imx7-media-csi: Simplify default format in
>     try_fmt
>   staging: media: imx: imx7-media-csi: Fix list of supported formats
>   staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support
>   staging: media: imx: imx7-media-csi: Drop unneeded pixel format
>     validation
>   staging: media: imx: imx7-media-csi: Inline
>     imx7_csi_enum_pixel_formats()
>   staging: media: imx: imx7-media-csi: Drop V4L2 events support
>   staging: media: imx: imx7-media-csi: Drop usage of shared helpers
> 
> Paul Elder (2):
>   staging: media: imx: imx7-media-csi: Move misc init out of probe()
>   staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi
> 
>  drivers/staging/media/imx/imx7-media-csi.c | 1370 +++++++++++++++++---
>  1 file changed, 1172 insertions(+), 198 deletions(-)
> 
> 
> base-commit: c5eb0a61238dd6faf37f58c9ce61c9980aaffd7a
> -- 
> Regards,
> 
> Laurent Pinchart
> 

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  2022-05-10 11:58 ` [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Laurent Pinchart
@ 2022-05-10 14:09   ` Rui Miguel Silva
  2022-05-10 14:42     ` Laurent Pinchart
  2022-05-10 15:25   ` [PATCH v1.1 " Laurent Pinchart
  1 sibling, 1 reply; 69+ messages in thread
From: Rui Miguel Silva @ 2022-05-10 14:09 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Hi Laurent,

On Tue, May 10, 2022 at 02:58:11PM +0300, Laurent Pinchart wrote:
> Prepare for the decoupling of the imx7-media-csi driver from the
> IPUv3-based drivers by moving the imx_media_dev handling from probe()
> function to separate functions.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 71 +++++++++++++---------
>  1 file changed, 42 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> index 893620e8fc03..d7c65b8bb3c9 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -1175,11 +1175,45 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
>  	return v4l2_async_register_subdev(&csi->sd);
>  }
>  
> +static void imx7_csi_media_cleanup(struct imx7_csi *csi)
> +{
> +	struct imx_media_dev *imxmd = csi->imxmd;

I know that later on we embed this media dev in csi, but meanwhile we
can reach here where csi->imxmd is NULL, because...

> +
> +	v4l2_device_unregister(&imxmd->v4l2_dev);
> +	media_device_unregister(&imxmd->md);
> +	media_device_cleanup(&imxmd->md);
> +}
> +
> +static int imx7_csi_media_init(struct imx7_csi *csi)
> +{
> +	struct imx_media_dev *imxmd;
> +	int ret;
> +
> +	/* add media device */
> +	imxmd = imx_media_dev_init(csi->dev, NULL);
> +	if (IS_ERR(imxmd))
> +		return PTR_ERR(imxmd);

here we get out and later remove() is called, or...

> +
> +	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
> +	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
> +		imx7_csi_media_cleanup(csi);

here we only set csi->imxmd = imxmd bellow.

> +		return ret;
> +	}
> +
> +	ret = imx_media_dev_notifier_register(imxmd, NULL);
> +	if (ret < 0) {
> +		imx7_csi_media_cleanup(csi);

ditto

> +		return ret;
> +	}
> +
> +	csi->imxmd = imxmd;
> +
> +	return 0;
> +}
> +
>  static int imx7_csi_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	struct device_node *node = dev->of_node;
> -	struct imx_media_dev *imxmd;
>  	struct imx7_csi *csi;
>  	int i, ret;
>  
> @@ -1193,6 +1227,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  	spin_lock_init(&csi->irqlock);
>  	mutex_init(&csi->lock);
>  
> +	/* Acquire resources and install interrupt handler. */
>  	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
>  	if (IS_ERR(csi->mclk)) {
>  		ret = PTR_ERR(csi->mclk);
> @@ -1214,7 +1249,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  
>  	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
>  
> -	/* install interrupt handler */
>  	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
>  			       (void *)csi);
>  	if (ret < 0) {
> @@ -1222,22 +1256,11 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  		goto destroy_mutex;
>  	}
>  
> -	/* add media device */
> -	imxmd = imx_media_dev_init(dev, NULL);
> -	if (IS_ERR(imxmd)) {
> -		ret = PTR_ERR(imxmd);
> +	/* Initialize all the media device infrastructure. */
> +	ret = imx7_csi_media_init(csi);
> +	if (ret)
>  		goto destroy_mutex;
> -	}
>  
> -	ret = imx_media_of_add_csi(imxmd, node);
> -	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
> -		goto cleanup;
> -
> -	ret = imx_media_dev_notifier_register(imxmd, NULL);
> -	if (ret < 0)
> -		goto cleanup;
> -
> -	csi->imxmd = imxmd;
>  	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
>  	v4l2_set_subdevdata(&csi->sd, csi);
>  	csi->sd.internal_ops = &imx7_csi_internal_ops;
> @@ -1269,11 +1292,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  	v4l2_async_nf_cleanup(&csi->notifier);
>  
>  cleanup:
> -	v4l2_async_nf_unregister(&imxmd->notifier);
> -	v4l2_async_nf_cleanup(&imxmd->notifier);

Didn't this notifier got dropped in cleanup() function? or am I
missing something?

Cheers,
     Rui
> -	v4l2_device_unregister(&imxmd->v4l2_dev);
> -	media_device_unregister(&imxmd->md);
> -	media_device_cleanup(&imxmd->md);
> +	imx7_csi_media_cleanup(csi);
>  
>  destroy_mutex:
>  	mutex_destroy(&csi->lock);
> @@ -1285,14 +1304,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
>  {
>  	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
>  	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
> -	struct imx_media_dev *imxmd = csi->imxmd;
>  
> -	v4l2_async_nf_unregister(&imxmd->notifier);
> -	v4l2_async_nf_cleanup(&imxmd->notifier);
> -
> -	media_device_unregister(&imxmd->md);
> -	v4l2_device_unregister(&imxmd->v4l2_dev);
> -	media_device_cleanup(&imxmd->md);
> +	imx7_csi_media_cleanup(csi);
>  
>  	v4l2_async_nf_unregister(&csi->notifier);
>  	v4l2_async_nf_cleanup(&csi->notifier);
> -- 
> Regards,
> 
> Laurent Pinchart
> 

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-05-10 14:04 ` [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Rui Miguel Silva
@ 2022-05-10 14:18   ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 14:18 UTC (permalink / raw)
  To: Rui Miguel Silva
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Hi Rui,

On Tue, May 10, 2022 at 03:04:16PM +0100, Rui Miguel Silva wrote:
> Hi Laurent,
> Thanks for this small change :).

Thanks for your small review ;-)

> On Tue, May 10, 2022 at 02:58:09PM +0300, Laurent Pinchart wrote:
> > Hello,
> > 
> > This patch series prepares the imx7-media-csi for destaging by
> > decoupling it from the helpers shared with the i.MX6 IPUv3.
> > 
> > The strategy Paul and I have followed is to import copies of helper code
> > and, refactor it within the imx7-media-csi driver, and repeat until no
> > more shared helpers are used. There is still room for refactoring and
> > simplification of the imx7-media-csi driver, but I believe it is now in
> > a state clean enough to be moved out of staging.
> 
> I agree.
> 
> > The series also includes a few fixes or improvements in supported
> > formats that are now made possible thanks to this refactoring. See
> > patches 45/50 and 46/50 for details.
> > 
> > The code size has grown as a result. This is partly offset by code in
> > the shared helpers that can be removed or simplified, but I haven't
> > starting working on that. The helpers are now used for the i.MX6 IPUv3
> > only, so I will leave this exercise to anyone who would be interested in
> > destaging that driver as well.
> > 
> > Some of the items in the TODO file related to the imx7-media-csi driver
> > have been addressed. The two remaining items are frame interval monitor
> > support and restricting the list of supported formats to the SoC
> > version. The former isn't a destaging blocker in my opinion, as the
> > feature can be added later if desired (and frame interval monitoring
> > should then be moved to the V4L2 core). I believe the latter could also
> > be addressed after destaging the driver, but in any case, this is a
> > discussion for a future destaging series (which may come as soon as this
> > one is accepted).
> > 
> > Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> > imx7/imx8mm media / csi patches" series.
> 
> I went over all patches and I have 2 small remarks:
> 
> 1. Shouldn't we change the connection between imx-media objects and
>    imx7-csi also in kconfig? Since at the end of this series they are
>    completely independent. Yeah, it can be done in a follow up
>    patch on the unstaging, for me that's fine also.

I was thinking of doing it while destaging, as I found it a bit
pointless to reorganize Kconfig in staging to then immediately move the
driver out of staging, but I don't mind already handling this in staging
if preferred.

> 2. Something that caught my eye on patch 2/50. But nothing functional.

I'll reply to that patch.

> Once again many thanks for continuing investing in this code.
> for the all series (except patch 2/50):
> 
> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>

Thank you !

> > Laurent Pinchart (48):
> >   staging: media: imx: imx7-media-csi: Initialize locks early on
> >   staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
> >   staging: media: imx: imx7-media-csi: Import notifier helpers
> >   staging: media: imx: imx7-media-csi: Drop duplicate link creation
> >   staging: media: imx: imx7-media-csi: Drop the imx_media notifier
> >   staging: media: imx: imx7-media-csi: Don't populate vdev lists
> >   staging: media: imx: imx7-media-csi: Drop unused frame_interval
> >   staging: media: imx: imx7-media-csi: Move format init to probe time
> >   staging: media: imx: imx7-media-csi: Import video device helpers
> >   staging: media: imx: imx7-media-csi: Drop legacy video device support
> >   staging: media: imx: imx7-media-csi: Drop unused controls support
> >   staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure
> >   staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi
> >   staging: media: imx: imx7-media-csi: Ensure consistent function prefix
> >   staging: media: imx: imx7-media-csi: Don't set subdev group id
> >   staging: media: imx: imx7-media-csi: Import imx_media_dev_init()
> >     helper
> >   staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi
> >   staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device
> >     call
> >   staging: media: imx: imx7-media-csi: Don't initialize unused fields
> >   staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad()
> >   staging: media: imx: imx7-media-csi: Import
> >     imx_media_pipeline_set_stream()
> >   staging: media: imx: imx7-media-csi: Avoid unnecessary casts
> >   staging: media: imx: imx7-media-csi: Inline pipeline start/stop
> >   staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi
> >   staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer
> >   staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into
> >     imx7_csi
> >   staging: media: imx: imx7-media-csi: Store imx7_csi in drv data
> >   staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf
> >   staging: media: imx: imx7-media-csi: Decouple from shared macros
> >   staging: media: imx: imx7-media-csi: Drop error message on alloc
> >     failure
> >   staging: media: imx: imx7-media-csi: Import format helpers
> >   staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool
> >     yuv field
> >   staging: media: imx: imx7-media-csi: Drop IC support from
> >     imx7_csi_try_colorimetry()
> >   staging: media: imx: imx7-media-csi: Drop IPU-only formats
> >   staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB
> >     formats
> >   staging: media: imx: imx7-media-csi: Make default formats consistent
> >   staging: media: imx: imx7-media-csi: Define macro for default mbus
> >     code
> >   staging: media: imx: imx7-media-csi: Simplify default mbus code in
> >     try_fmt
> >   staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format
> >     selectors
> >   staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt
> >     fields
> >   staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt()
> >   staging: media: imx: imx7-media-csi: Simplify default format in
> >     try_fmt
> >   staging: media: imx: imx7-media-csi: Fix list of supported formats
> >   staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support
> >   staging: media: imx: imx7-media-csi: Drop unneeded pixel format
> >     validation
> >   staging: media: imx: imx7-media-csi: Inline
> >     imx7_csi_enum_pixel_formats()
> >   staging: media: imx: imx7-media-csi: Drop V4L2 events support
> >   staging: media: imx: imx7-media-csi: Drop usage of shared helpers
> > 
> > Paul Elder (2):
> >   staging: media: imx: imx7-media-csi: Move misc init out of probe()
> >   staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi
> > 
> >  drivers/staging/media/imx/imx7-media-csi.c | 1370 +++++++++++++++++---
> >  1 file changed, 1172 insertions(+), 198 deletions(-)
> > 
> > 
> > base-commit: c5eb0a61238dd6faf37f58c9ce61c9980aaffd7a

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  2022-05-10 14:09   ` Rui Miguel Silva
@ 2022-05-10 14:42     ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 14:42 UTC (permalink / raw)
  To: Rui Miguel Silva
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Hi Rui,

On Tue, May 10, 2022 at 03:09:02PM +0100, Rui Miguel Silva wrote:
> On Tue, May 10, 2022 at 02:58:11PM +0300, Laurent Pinchart wrote:
> > Prepare for the decoupling of the imx7-media-csi driver from the
> > IPUv3-based drivers by moving the imx_media_dev handling from probe()
> > function to separate functions.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/staging/media/imx/imx7-media-csi.c | 71 +++++++++++++---------
> >  1 file changed, 42 insertions(+), 29 deletions(-)
> > 
> > diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> > index 893620e8fc03..d7c65b8bb3c9 100644
> > --- a/drivers/staging/media/imx/imx7-media-csi.c
> > +++ b/drivers/staging/media/imx/imx7-media-csi.c
> > @@ -1175,11 +1175,45 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
> >  	return v4l2_async_register_subdev(&csi->sd);
> >  }
> >  
> > +static void imx7_csi_media_cleanup(struct imx7_csi *csi)
> > +{
> > +	struct imx_media_dev *imxmd = csi->imxmd;
> 
> I know that later on we embed this media dev in csi, but meanwhile we
> can reach here where csi->imxmd is NULL, because...
> 
> > +
> > +	v4l2_device_unregister(&imxmd->v4l2_dev);
> > +	media_device_unregister(&imxmd->md);
> > +	media_device_cleanup(&imxmd->md);
> > +}
> > +
> > +static int imx7_csi_media_init(struct imx7_csi *csi)
> > +{
> > +	struct imx_media_dev *imxmd;
> > +	int ret;
> > +
> > +	/* add media device */
> > +	imxmd = imx_media_dev_init(csi->dev, NULL);
> > +	if (IS_ERR(imxmd))
> > +		return PTR_ERR(imxmd);
> 
> here we get out and later remove() is called, or...

This can't happen, as if probe() fails, remove() isn't called.

> > +
> > +	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
> > +	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
> > +		imx7_csi_media_cleanup(csi);
> 
> here we only set csi->imxmd = imxmd bellow.
> 
> > +		return ret;
> > +	}
> > +
> > +	ret = imx_media_dev_notifier_register(imxmd, NULL);
> > +	if (ret < 0) {
> > +		imx7_csi_media_cleanup(csi);
> 
> ditto

Those two are valid concerns. I'll fix them.

> > +		return ret;
> > +	}
> > +
> > +	csi->imxmd = imxmd;
> > +
> > +	return 0;
> > +}
> > +
> >  static int imx7_csi_probe(struct platform_device *pdev)
> >  {
> >  	struct device *dev = &pdev->dev;
> > -	struct device_node *node = dev->of_node;
> > -	struct imx_media_dev *imxmd;
> >  	struct imx7_csi *csi;
> >  	int i, ret;
> >  
> > @@ -1193,6 +1227,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
> >  	spin_lock_init(&csi->irqlock);
> >  	mutex_init(&csi->lock);
> >  
> > +	/* Acquire resources and install interrupt handler. */
> >  	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
> >  	if (IS_ERR(csi->mclk)) {
> >  		ret = PTR_ERR(csi->mclk);
> > @@ -1214,7 +1249,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
> >  
> >  	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
> >  
> > -	/* install interrupt handler */
> >  	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
> >  			       (void *)csi);
> >  	if (ret < 0) {
> > @@ -1222,22 +1256,11 @@ static int imx7_csi_probe(struct platform_device *pdev)
> >  		goto destroy_mutex;
> >  	}
> >  
> > -	/* add media device */
> > -	imxmd = imx_media_dev_init(dev, NULL);
> > -	if (IS_ERR(imxmd)) {
> > -		ret = PTR_ERR(imxmd);
> > +	/* Initialize all the media device infrastructure. */
> > +	ret = imx7_csi_media_init(csi);
> > +	if (ret)
> >  		goto destroy_mutex;
> > -	}
> >  
> > -	ret = imx_media_of_add_csi(imxmd, node);
> > -	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
> > -		goto cleanup;
> > -
> > -	ret = imx_media_dev_notifier_register(imxmd, NULL);
> > -	if (ret < 0)
> > -		goto cleanup;
> > -
> > -	csi->imxmd = imxmd;
> >  	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
> >  	v4l2_set_subdevdata(&csi->sd, csi);
> >  	csi->sd.internal_ops = &imx7_csi_internal_ops;
> > @@ -1269,11 +1292,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
> >  	v4l2_async_nf_cleanup(&csi->notifier);
> >  
> >  cleanup:
> > -	v4l2_async_nf_unregister(&imxmd->notifier);
> > -	v4l2_async_nf_cleanup(&imxmd->notifier);
> 
> Didn't this notifier got dropped in cleanup() function? or am I
> missing something?

They should be kept in imx7_csi_media_cleanup() and removed later. I'll
fix it too.

> > -	v4l2_device_unregister(&imxmd->v4l2_dev);
> > -	media_device_unregister(&imxmd->md);
> > -	media_device_cleanup(&imxmd->md);
> > +	imx7_csi_media_cleanup(csi);
> >  
> >  destroy_mutex:
> >  	mutex_destroy(&csi->lock);
> > @@ -1285,14 +1304,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
> >  {
> >  	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
> >  	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
> > -	struct imx_media_dev *imxmd = csi->imxmd;
> >  
> > -	v4l2_async_nf_unregister(&imxmd->notifier);
> > -	v4l2_async_nf_cleanup(&imxmd->notifier);
> > -
> > -	media_device_unregister(&imxmd->md);
> > -	v4l2_device_unregister(&imxmd->v4l2_dev);
> > -	media_device_cleanup(&imxmd->md);
> > +	imx7_csi_media_cleanup(csi);
> >  
> >  	v4l2_async_nf_unregister(&csi->notifier);
> >  	v4l2_async_nf_cleanup(&csi->notifier);

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 69+ messages in thread

* [PATCH v1.1 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  2022-05-10 11:58 ` [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Laurent Pinchart
  2022-05-10 14:09   ` Rui Miguel Silva
@ 2022-05-10 15:25   ` Laurent Pinchart
  2022-05-10 15:49     ` Rui Miguel Silva
  1 sibling, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 15:25 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Prepare for the decoupling of the imx7-media-csi driver from the
IPUv3-based drivers by moving the imx_media_dev handling from probe()
function to separate functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Set csi->imxmd earlier in imx7_csi_media_init()
- Unregister and cleanup notifier in imx7_csi_media_cleanup()
---
 drivers/staging/media/imx/imx7-media-csi.c | 74 +++++++++++++---------
 1 file changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 893620e8fc03..3246a5826cb2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1175,11 +1175,48 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
 	return v4l2_async_register_subdev(&csi->sd);
 }
 
+static void imx7_csi_media_cleanup(struct imx7_csi *csi)
+{
+	struct imx_media_dev *imxmd = csi->imxmd;
+
+	v4l2_async_nf_unregister(&imxmd->notifier);
+	v4l2_async_nf_cleanup(&imxmd->notifier);
+
+	v4l2_device_unregister(&imxmd->v4l2_dev);
+	media_device_unregister(&imxmd->md);
+	media_device_cleanup(&imxmd->md);
+}
+
+static int imx7_csi_media_init(struct imx7_csi *csi)
+{
+	struct imx_media_dev *imxmd;
+	int ret;
+
+	/* add media device */
+	imxmd = imx_media_dev_init(csi->dev, NULL);
+	if (IS_ERR(imxmd))
+		return PTR_ERR(imxmd);
+
+	csi->imxmd = imxmd;
+
+	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
+	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
+		imx7_csi_media_cleanup(csi);
+		return ret;
+	}
+
+	ret = imx_media_dev_notifier_register(imxmd, NULL);
+	if (ret < 0) {
+		imx7_csi_media_cleanup(csi);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int imx7_csi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *node = dev->of_node;
-	struct imx_media_dev *imxmd;
 	struct imx7_csi *csi;
 	int i, ret;
 
@@ -1193,6 +1230,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	spin_lock_init(&csi->irqlock);
 	mutex_init(&csi->lock);
 
+	/* Acquire resources and install interrupt handler. */
 	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
 	if (IS_ERR(csi->mclk)) {
 		ret = PTR_ERR(csi->mclk);
@@ -1214,7 +1252,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 
 	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
 
-	/* install interrupt handler */
 	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
 			       (void *)csi);
 	if (ret < 0) {
@@ -1222,22 +1259,11 @@ static int imx7_csi_probe(struct platform_device *pdev)
 		goto destroy_mutex;
 	}
 
-	/* add media device */
-	imxmd = imx_media_dev_init(dev, NULL);
-	if (IS_ERR(imxmd)) {
-		ret = PTR_ERR(imxmd);
+	/* Initialize all the media device infrastructure. */
+	ret = imx7_csi_media_init(csi);
+	if (ret)
 		goto destroy_mutex;
-	}
 
-	ret = imx_media_of_add_csi(imxmd, node);
-	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
-		goto cleanup;
-
-	ret = imx_media_dev_notifier_register(imxmd, NULL);
-	if (ret < 0)
-		goto cleanup;
-
-	csi->imxmd = imxmd;
 	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
 	v4l2_set_subdevdata(&csi->sd, csi);
 	csi->sd.internal_ops = &imx7_csi_internal_ops;
@@ -1269,11 +1295,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&csi->notifier);
 
 cleanup:
-	v4l2_async_nf_unregister(&imxmd->notifier);
-	v4l2_async_nf_cleanup(&imxmd->notifier);
-	v4l2_device_unregister(&imxmd->v4l2_dev);
-	media_device_unregister(&imxmd->md);
-	media_device_cleanup(&imxmd->md);
+	imx7_csi_media_cleanup(csi);
 
 destroy_mutex:
 	mutex_destroy(&csi->lock);
@@ -1285,14 +1307,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
 {
 	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct imx_media_dev *imxmd = csi->imxmd;
 
-	v4l2_async_nf_unregister(&imxmd->notifier);
-	v4l2_async_nf_cleanup(&imxmd->notifier);
-
-	media_device_unregister(&imxmd->md);
-	v4l2_device_unregister(&imxmd->v4l2_dev);
-	media_device_cleanup(&imxmd->md);
+	imx7_csi_media_cleanup(csi);
 
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH v1.1 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe()
  2022-05-10 11:58 ` [PATCH 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe() Laurent Pinchart
@ 2022-05-10 15:26   ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-10 15:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel,
	Paul Elder

From: Paul Elder <paul.elder@ideasonboard.com>

There is a chunk of miscellaneous initializations related to the CSI
subdev and media pads directly in the probe function. Move them into the
imx7_csi_media_init() function to clean up the probe function.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
Changes since v1:

- Fix error handling in imx7_csi_media_init()
---
 drivers/staging/media/imx/imx7-media-csi.c | 60 ++++++++++++----------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 9551cf37a1a9..1b801f39f568 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1342,6 +1342,7 @@ static void imx7_csi_media_cleanup(struct imx7_csi *csi)
 static int imx7_csi_media_init(struct imx7_csi *csi)
 {
 	struct imx_media_dev *imxmd;
+	unsigned int i;
 	int ret;
 
 	/* add media device */
@@ -1352,19 +1353,44 @@ static int imx7_csi_media_init(struct imx7_csi *csi)
 	csi->imxmd = imxmd;
 
 	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
-	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
-		imx7_csi_media_cleanup(csi);
-		return ret;
-	}
+	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
+		goto error;
+
+	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
+	v4l2_set_subdevdata(&csi->sd, csi);
+	csi->sd.internal_ops = &imx7_csi_internal_ops;
+	csi->sd.entity.ops = &imx7_csi_entity_ops;
+	csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+	csi->sd.dev = csi->dev;
+	csi->sd.owner = THIS_MODULE;
+	csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
+	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
+
+	for (i = 0; i < IMX7_CSI_PADS_NUM; i++)
+		csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ?
+			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
+
+	ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM,
+				     csi->pad);
+	if (ret)
+		goto error;
+
+	ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
+	if (ret)
+		goto error;
 
 	return 0;
+
+error:
+	imx7_csi_media_cleanup(csi);
+	return ret;
 }
 
 static int imx7_csi_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct imx7_csi *csi;
-	int i, ret;
+	int ret;
 
 	csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL);
 	if (!csi)
@@ -1410,28 +1436,9 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	if (ret)
 		goto destroy_mutex;
 
-	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
-	v4l2_set_subdevdata(&csi->sd, csi);
-	csi->sd.internal_ops = &imx7_csi_internal_ops;
-	csi->sd.entity.ops = &imx7_csi_entity_ops;
-	csi->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
-	csi->sd.dev = &pdev->dev;
-	csi->sd.owner = THIS_MODULE;
-	csi->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
-	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
-
-	for (i = 0; i < IMX7_CSI_PADS_NUM; i++)
-		csi->pad[i].flags = (i == IMX7_CSI_PAD_SINK) ?
-			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
-
-	ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM,
-				     csi->pad);
-	if (ret < 0)
-		goto cleanup;
-
 	ret = v4l2_device_register_subdev(&csi->imxmd->v4l2_dev, &csi->sd);
 	if (ret)
-		goto cleanup;
+		goto media_cleanup;
 
 	ret = imx7_csi_async_register(csi);
 	if (ret)
@@ -1442,8 +1449,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 subdev_notifier_cleanup:
 	v4l2_async_nf_unregister(&csi->notifier);
 	v4l2_async_nf_cleanup(&csi->notifier);
-
-cleanup:
+media_cleanup:
 	imx7_csi_media_cleanup(csi);
 
 destroy_mutex:
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* Re: [PATCH v1.1 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe()
  2022-05-10 15:25   ` [PATCH v1.1 " Laurent Pinchart
@ 2022-05-10 15:49     ` Rui Miguel Silva
  0 siblings, 0 replies; 69+ messages in thread
From: Rui Miguel Silva @ 2022-05-10 15:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Thanks Laurent,
On Tue, May 10, 2022 at 06:25:18PM +0300, Laurent Pinchart wrote:
> Prepare for the decoupling of the imx7-media-csi driver from the
> IPUv3-based drivers by moving the imx_media_dev handling from probe()
> function to separate functions.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>

Cheers,
   Rui

> ---
> Changes since v1:
> 
> - Set csi->imxmd earlier in imx7_csi_media_init()
> - Unregister and cleanup notifier in imx7_csi_media_cleanup()
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 74 +++++++++++++---------
>  1 file changed, 45 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> index 893620e8fc03..3246a5826cb2 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -1175,11 +1175,48 @@ static int imx7_csi_async_register(struct imx7_csi *csi)
>  	return v4l2_async_register_subdev(&csi->sd);
>  }
>  
> +static void imx7_csi_media_cleanup(struct imx7_csi *csi)
> +{
> +	struct imx_media_dev *imxmd = csi->imxmd;
> +
> +	v4l2_async_nf_unregister(&imxmd->notifier);
> +	v4l2_async_nf_cleanup(&imxmd->notifier);
> +
> +	v4l2_device_unregister(&imxmd->v4l2_dev);
> +	media_device_unregister(&imxmd->md);
> +	media_device_cleanup(&imxmd->md);
> +}
> +
> +static int imx7_csi_media_init(struct imx7_csi *csi)
> +{
> +	struct imx_media_dev *imxmd;
> +	int ret;
> +
> +	/* add media device */
> +	imxmd = imx_media_dev_init(csi->dev, NULL);
> +	if (IS_ERR(imxmd))
> +		return PTR_ERR(imxmd);
> +
> +	csi->imxmd = imxmd;
> +
> +	ret = imx_media_of_add_csi(imxmd, csi->dev->of_node);
> +	if (ret < 0 && ret != -ENODEV && ret != -EEXIST) {
> +		imx7_csi_media_cleanup(csi);
> +		return ret;
> +	}
> +
> +	ret = imx_media_dev_notifier_register(imxmd, NULL);
> +	if (ret < 0) {
> +		imx7_csi_media_cleanup(csi);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
>  static int imx7_csi_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	struct device_node *node = dev->of_node;
> -	struct imx_media_dev *imxmd;
>  	struct imx7_csi *csi;
>  	int i, ret;
>  
> @@ -1193,6 +1230,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  	spin_lock_init(&csi->irqlock);
>  	mutex_init(&csi->lock);
>  
> +	/* Acquire resources and install interrupt handler. */
>  	csi->mclk = devm_clk_get(&pdev->dev, "mclk");
>  	if (IS_ERR(csi->mclk)) {
>  		ret = PTR_ERR(csi->mclk);
> @@ -1214,7 +1252,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  
>  	csi->model = (enum imx_csi_model)(uintptr_t)of_device_get_match_data(&pdev->dev);
>  
> -	/* install interrupt handler */
>  	ret = devm_request_irq(dev, csi->irq, imx7_csi_irq_handler, 0, "csi",
>  			       (void *)csi);
>  	if (ret < 0) {
> @@ -1222,22 +1259,11 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  		goto destroy_mutex;
>  	}
>  
> -	/* add media device */
> -	imxmd = imx_media_dev_init(dev, NULL);
> -	if (IS_ERR(imxmd)) {
> -		ret = PTR_ERR(imxmd);
> +	/* Initialize all the media device infrastructure. */
> +	ret = imx7_csi_media_init(csi);
> +	if (ret)
>  		goto destroy_mutex;
> -	}
>  
> -	ret = imx_media_of_add_csi(imxmd, node);
> -	if (ret < 0 && ret != -ENODEV && ret != -EEXIST)
> -		goto cleanup;
> -
> -	ret = imx_media_dev_notifier_register(imxmd, NULL);
> -	if (ret < 0)
> -		goto cleanup;
> -
> -	csi->imxmd = imxmd;
>  	v4l2_subdev_init(&csi->sd, &imx7_csi_subdev_ops);
>  	v4l2_set_subdevdata(&csi->sd, csi);
>  	csi->sd.internal_ops = &imx7_csi_internal_ops;
> @@ -1269,11 +1295,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
>  	v4l2_async_nf_cleanup(&csi->notifier);
>  
>  cleanup:
> -	v4l2_async_nf_unregister(&imxmd->notifier);
> -	v4l2_async_nf_cleanup(&imxmd->notifier);
> -	v4l2_device_unregister(&imxmd->v4l2_dev);
> -	media_device_unregister(&imxmd->md);
> -	media_device_cleanup(&imxmd->md);
> +	imx7_csi_media_cleanup(csi);
>  
>  destroy_mutex:
>  	mutex_destroy(&csi->lock);
> @@ -1285,14 +1307,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
>  {
>  	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
>  	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
> -	struct imx_media_dev *imxmd = csi->imxmd;
>  
> -	v4l2_async_nf_unregister(&imxmd->notifier);
> -	v4l2_async_nf_cleanup(&imxmd->notifier);
> -
> -	media_device_unregister(&imxmd->md);
> -	v4l2_device_unregister(&imxmd->v4l2_dev);
> -	media_device_cleanup(&imxmd->md);
> +	imx7_csi_media_cleanup(csi);
>  
>  	v4l2_async_nf_unregister(&csi->notifier);
>  	v4l2_async_nf_cleanup(&csi->notifier);
> -- 
> Regards,
> 
> Laurent Pinchart
> 

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code
  2022-05-10 11:58 ` [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code Laurent Pinchart
@ 2022-05-11 13:22   ` Alexander Stein
  2022-05-11 20:20     ` Laurent Pinchart
  2022-07-07  0:19   ` [PATCH v1.1 " Laurent Pinchart
  1 sibling, 1 reply; 69+ messages in thread
From: Alexander Stein @ 2022-05-11 13:22 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hello Laurent,

Am Dienstag, 10. Mai 2022, 13:58:48 CEST schrieb Laurent Pinchart:
> Define a macro for the default media bus code and use it through the
> driver to replace a hardcoded value and a dynamic query from the
> pixel_formats table.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c
> b/drivers/staging/media/imx/imx7-media-csi.c index
> bcf57aff3572..f2e85e9851e4 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -167,6 +167,7 @@
>  #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
>  #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
> 
> +#define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
>  #define IMX7_CSI_DEF_PIX_WIDTH		640
>  #define IMX7_CSI_DEF_PIX_HEIGHT		480
> 
> @@ -1096,7 +1097,7 @@ static int imx7_csi_init_mbus_fmt(struct
> v4l2_mbus_framefmt *mbus, mbus->field = field;
> 
>  	if (code == 0)
> -		imx7_csi_enum_mbus_formats(&code, 0, 
IMX7_CSI_PIXFMT_SEL_YUV);
> +		code = IMX7_CSI_DEF_MBUS_CODE;
> 
>  	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
>  	if (!lcc)
> @@ -1629,7 +1630,7 @@ static int imx7_csi_video_init_format(struct imx7_csi
> *csi) .pad = IMX7_CSI_PAD_SRC,
>  		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
>  	};
> -	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
> +	fmt_src.format.code = IMX7_CSI_DEF_MBUS_CODE;
>  	fmt_src.format.width = IMX7_CSI_DEF_PIX_WIDTH;
>  	fmt_src.format.height = IMX7_CSI_DEF_PIX_HEIGHT;

This change assumes, like before, that MEDIA_BUS_FMT_UYVY8_2X8 is the 1st code 
in the 1st entry in pixel_formats. Maybe a comment is helpful to indicate 
that.

Regards,
Alexander



^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt
  2022-05-10 11:58 ` [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt Laurent Pinchart
@ 2022-05-11 13:27   ` Alexander Stein
  2022-07-07  0:20   ` [PATCH v1.1 " Laurent Pinchart
  1 sibling, 0 replies; 69+ messages in thread
From: Alexander Stein @ 2022-05-11 13:27 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hello Laurent,

Am Dienstag, 10. Mai 2022, 13:58:53 CEST schrieb Laurent Pinchart:
> When trying a format on the video node, if the requested pixel format
> isn't supported, fallback to the default with a simpler logic.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c
> b/drivers/staging/media/imx/imx7-media-csi.c index
> bc3a87656117..0fb5e0c03396 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -168,6 +168,7 @@
>  #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
> 
>  #define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
> +#define IMX7_CSI_DEF_PIX_FORMAT		V4L2_PIX_FMT_UYVY
>  #define IMX7_CSI_DEF_PIX_WIDTH		640
>  #define IMX7_CSI_DEF_PIX_HEIGHT		480
> 
> @@ -1130,7 +1131,7 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format
> *pixfmt, */
>  	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
>  	if (!cc) {
> -		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0, 0);
> +		pixfmt->pixelformat = IMX7_CSI_DEF_PIX_FORMAT;
>  		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
>  	}

This change now expects that V4L2_PIX_FMT_UYVY is the 1st entry in 
pixel_formats. Maybe a comment is helpful to indicate 
that.

Regards,
Alexander




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: (EXT) [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (50 preceding siblings ...)
  2022-05-10 14:04 ` [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Rui Miguel Silva
@ 2022-05-11 13:36 ` Alexander Stein
  2022-07-07  0:23   ` Laurent Pinchart
  2022-05-16  7:59 ` Alexander Stein
  52 siblings, 1 reply; 69+ messages in thread
From: Alexander Stein @ 2022-05-11 13:36 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hello Laurent,

thanks for pushing out this huge set.

Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> Hello,
> 
> This patch series prepares the imx7-media-csi for destaging by
> decoupling it from the helpers shared with the i.MX6 IPUv3.
> 
> The strategy Paul and I have followed is to import copies of helper code
> and, refactor it within the imx7-media-csi driver, and repeat until no
> more shared helpers are used. There is still room for refactoring and
> simplification of the imx7-media-csi driver, but I believe it is now in
> a state clean enough to be moved out of staging.
> 
> The series also includes a few fixes or improvements in supported
> formats that are now made possible thanks to this refactoring. See
> patches 45/50 and 46/50 for details.
> 
> The code size has grown as a result. This is partly offset by code in
> the shared helpers that can be removed or simplified, but I haven't
> starting working on that. The helpers are now used for the i.MX6 IPUv3
> only, so I will leave this exercise to anyone who would be interested in
> destaging that driver as well.
> 
> Some of the items in the TODO file related to the imx7-media-csi driver
> have been addressed. The two remaining items are frame interval monitor
> support and restricting the list of supported formats to the SoC
> version. The former isn't a destaging blocker in my opinion, as the
> feature can be added later if desired (and frame interval monitoring
> should then be moved to the V4L2 core). I believe the latter could also
> be addressed after destaging the driver, but in any case, this is a
> discussion for a future destaging series (which may come as soon as this
> one is accepted).
> 
> Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> imx7/imx8mm media / csi patches" series.

Thanks for putting me on CC. I'll try to get my system running your patches 
ASAP.

Best regards,
Alexander





^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code
  2022-05-11 13:22   ` Alexander Stein
@ 2022-05-11 20:20     ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-05-11 20:20 UTC (permalink / raw)
  To: Alexander Stein
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hi Alexander,

On Wed, May 11, 2022 at 03:22:02PM +0200, Alexander Stein wrote:
> Am Dienstag, 10. Mai 2022, 13:58:48 CEST schrieb Laurent Pinchart:
> > Define a macro for the default media bus code and use it through the
> > driver to replace a hardcoded value and a dynamic query from the
> > pixel_formats table.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/staging/media/imx/imx7-media-csi.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/staging/media/imx/imx7-media-csi.c
> > b/drivers/staging/media/imx/imx7-media-csi.c index
> > bcf57aff3572..f2e85e9851e4 100644
> > --- a/drivers/staging/media/imx/imx7-media-csi.c
> > +++ b/drivers/staging/media/imx/imx7-media-csi.c
> > @@ -167,6 +167,7 @@
> >  #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
> >  #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
> > 
> > +#define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
> >  #define IMX7_CSI_DEF_PIX_WIDTH		640
> >  #define IMX7_CSI_DEF_PIX_HEIGHT		480
> > 
> > @@ -1096,7 +1097,7 @@ static int imx7_csi_init_mbus_fmt(struct
> > v4l2_mbus_framefmt *mbus, mbus->field = field;
> > 
> >  	if (code == 0)
> > -		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
> > +		code = IMX7_CSI_DEF_MBUS_CODE;
> > 
> >  	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
> >  	if (!lcc)
> > @@ -1629,7 +1630,7 @@ static int imx7_csi_video_init_format(struct imx7_csi
> > *csi) .pad = IMX7_CSI_PAD_SRC,
> >  		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
> >  	};
> > -	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
> > +	fmt_src.format.code = IMX7_CSI_DEF_MBUS_CODE;
> >  	fmt_src.format.width = IMX7_CSI_DEF_PIX_WIDTH;
> >  	fmt_src.format.height = IMX7_CSI_DEF_PIX_HEIGHT;
> 
> This change assumes, like before, that MEDIA_BUS_FMT_UYVY8_2X8 is the 1st code 
> in the 1st entry in pixel_formats. Maybe a comment is helpful to indicate 
> that.

I'll add a comment above the formats array that mentions this. Same for
the comment on had on patch 44/50. I'll refrain from posting a v2 until
I get more review as I don't want to spam the list too often.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
                   ` (51 preceding siblings ...)
  2022-05-11 13:36 ` (EXT) " Alexander Stein
@ 2022-05-16  7:59 ` Alexander Stein
  52 siblings, 0 replies; 69+ messages in thread
From: Alexander Stein @ 2022-05-16  7:59 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hello Laurent,

Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> Hello,
> 
> This patch series prepares the imx7-media-csi for destaging by
> decoupling it from the helpers shared with the i.MX6 IPUv3.
> 
> The strategy Paul and I have followed is to import copies of helper code
> and, refactor it within the imx7-media-csi driver, and repeat until no
> more shared helpers are used. There is still room for refactoring and
> simplification of the imx7-media-csi driver, but I believe it is now in
> a state clean enough to be moved out of staging.
> 
> The series also includes a few fixes or improvements in supported
> formats that are now made possible thanks to this refactoring. See
> patches 45/50 and 46/50 for details.
> 
> The code size has grown as a result. This is partly offset by code in
> the shared helpers that can be removed or simplified, but I haven't
> starting working on that. The helpers are now used for the i.MX6 IPUv3
> only, so I will leave this exercise to anyone who would be interested in
> destaging that driver as well.
> 
> Some of the items in the TODO file related to the imx7-media-csi driver
> have been addressed. The two remaining items are frame interval monitor
> support and restricting the list of supported formats to the SoC
> version. The former isn't a destaging blocker in my opinion, as the
> feature can be added later if desired (and frame interval monitoring
> should then be moved to the V4L2 core). I believe the latter could also
> be addressed after destaging the driver, but in any case, this is a
> discussion for a future destaging series (which may come as soon as this
> one is accepted).
> 
> Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> imx7/imx8mm media / csi patches" series.

Thanks again for this patchset. This does not only simplify my series, it 
pretty much makes it obsolete. Only one change is still valid (rounding up 
width depending on bpp), but I would skip that for now.
Just using my DT is enough. Nice!

If you respin a v2, I'll retest again for a proper Tested-by tag.

Regards,
Alexander




^ permalink raw reply	[flat|nested] 69+ messages in thread

* [PATCH v1.1 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code
  2022-05-10 11:58 ` [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code Laurent Pinchart
  2022-05-11 13:22   ` Alexander Stein
@ 2022-07-07  0:19   ` Laurent Pinchart
  1 sibling, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-07-07  0:19 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

Define a macro for the default media bus code and use it through the
driver to replace a hardcoded value and a dynamic query from the
pixel_formats table.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
Changes since v1:

- Add a comment to tell MEDIA_BUS_FMT_UYVY8_2X8 must be first
---
 drivers/staging/media/imx/imx7-media-csi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index b76e040e45da..f8c21dd00e55 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -167,6 +167,7 @@
 #define IMX7_CSI_VIDEO_MEM_LIMIT	SZ_64M
 #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
+#define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
 #define IMX7_CSI_DEF_PIX_WIDTH		640
 #define IMX7_CSI_DEF_PIX_HEIGHT		480
 
@@ -820,7 +821,8 @@ enum imx7_csi_pixfmt_sel {
 };
 
 /*
- * List of supported pixel formats for the subdevs.
+ * List of supported pixel formats for the subdevs. Keep MEDIA_BUS_FMT_UYVY8_2X8
+ * first to match IMX7_CSI_DEF_MBUS_CODE.
  */
 static const struct imx7_csi_pixfmt pixel_formats[] = {
 	/*** YUV formats start here ***/
@@ -1096,7 +1098,7 @@ static int imx7_csi_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 	mbus->field = field;
 
 	if (code == 0)
-		imx7_csi_enum_mbus_formats(&code, 0, IMX7_CSI_PIXFMT_SEL_YUV);
+		code = IMX7_CSI_DEF_MBUS_CODE;
 
 	lcc = imx7_csi_find_mbus_format(code, IMX7_CSI_PIXFMT_SEL_ANY);
 	if (!lcc)
@@ -1629,7 +1631,7 @@ static int imx7_csi_video_init_format(struct imx7_csi *csi)
 		.pad = IMX7_CSI_PAD_SRC,
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
 	};
-	fmt_src.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
+	fmt_src.format.code = IMX7_CSI_DEF_MBUS_CODE;
 	fmt_src.format.width = IMX7_CSI_DEF_PIX_WIDTH;
 	fmt_src.format.height = IMX7_CSI_DEF_PIX_HEIGHT;
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* [PATCH v1.1 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt
  2022-05-10 11:58 ` [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt Laurent Pinchart
  2022-05-11 13:27   ` Alexander Stein
@ 2022-07-07  0:20   ` Laurent Pinchart
  1 sibling, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2022-07-07  0:20 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Jacopo Mondi,
	Martin Kepplinger, Alexander Stein, Dorota Czaplejewicz, kernel

When trying a format on the video node, if the requested pixel format
isn't supported, fallback to the default with a simpler logic.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
Changes since v1:

- Add a comment to tell V4L2_PIX_FMT_UYVY must be first
---
 drivers/staging/media/imx/imx7-media-csi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 19aa8724f6c1..fd707a49be3f 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -168,6 +168,7 @@
 #define IMX7_CSI_VIDEO_EOF_TIMEOUT	2000
 
 #define IMX7_CSI_DEF_MBUS_CODE		MEDIA_BUS_FMT_UYVY8_2X8
+#define IMX7_CSI_DEF_PIX_FORMAT		V4L2_PIX_FMT_UYVY
 #define IMX7_CSI_DEF_PIX_WIDTH		640
 #define IMX7_CSI_DEF_PIX_HEIGHT		480
 
@@ -806,8 +807,9 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 #define IMX_BUS_FMTS(fmt...) (const u32[]) {fmt, 0}
 
 /*
- * List of supported pixel formats for the subdevs. Keep MEDIA_BUS_FMT_UYVY8_2X8
- * first to match IMX7_CSI_DEF_MBUS_CODE.
+ * List of supported pixel formats for the subdevs. Keep V4L2_PIX_FMT_UYVY and
+ * MEDIA_BUS_FMT_UYVY8_2X8 first to match IMX7_CSI_DEF_PIX_FORMAT and
+ * IMX7_CSI_DEF_MBUS_CODE.
  */
 static const struct imx7_csi_pixfmt pixel_formats[] = {
 	/*** YUV formats start here ***/
@@ -1131,7 +1133,7 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	 */
 	cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	if (!cc) {
-		imx7_csi_enum_pixel_formats(&pixfmt->pixelformat, 0, 0);
+		pixfmt->pixelformat = IMX7_CSI_DEF_PIX_FORMAT;
 		cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
 	}
 
-- 
Regards,

Laurent Pinchart


^ permalink raw reply related	[flat|nested] 69+ messages in thread

* Re: (EXT) [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-05-11 13:36 ` (EXT) " Alexander Stein
@ 2022-07-07  0:23   ` Laurent Pinchart
  2022-07-07 10:45     ` Alexander Stein
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2022-07-07  0:23 UTC (permalink / raw)
  To: Alexander Stein
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hi Alexander,

On Wed, May 11, 2022 at 03:36:14PM +0200, Alexander Stein wrote:
> Hello Laurent,
> 
> thanks for pushing out this huge set.
> 
> Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> > Hello,
> > 
> > This patch series prepares the imx7-media-csi for destaging by
> > decoupling it from the helpers shared with the i.MX6 IPUv3.
> > 
> > The strategy Paul and I have followed is to import copies of helper code
> > and, refactor it within the imx7-media-csi driver, and repeat until no
> > more shared helpers are used. There is still room for refactoring and
> > simplification of the imx7-media-csi driver, but I believe it is now in
> > a state clean enough to be moved out of staging.
> > 
> > The series also includes a few fixes or improvements in supported
> > formats that are now made possible thanks to this refactoring. See
> > patches 45/50 and 46/50 for details.
> > 
> > The code size has grown as a result. This is partly offset by code in
> > the shared helpers that can be removed or simplified, but I haven't
> > starting working on that. The helpers are now used for the i.MX6 IPUv3
> > only, so I will leave this exercise to anyone who would be interested in
> > destaging that driver as well.
> > 
> > Some of the items in the TODO file related to the imx7-media-csi driver
> > have been addressed. The two remaining items are frame interval monitor
> > support and restricting the list of supported formats to the SoC
> > version. The former isn't a destaging blocker in my opinion, as the
> > feature can be added later if desired (and frame interval monitoring
> > should then be moved to the V4L2 core). I believe the latter could also
> > be addressed after destaging the driver, but in any case, this is a
> > discussion for a future destaging series (which may come as soon as this
> > one is accepted).
> > 
> > Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> > imx7/imx8mm media / csi patches" series.
> 
> Thanks for putting me on CC. I'll try to get my system running your patches 
> ASAP.

As only minor changes were needed, I ended up posting v1.1 of the
corresponding patches instead of spamming everybody with a full v2. For
your convenience, I've pushed the result to

	git://linuxtv.org/pinchartl/media.git imx7/destage

I know it's a bit of a short notice, but I'd like to send a pull request
in time for v5.20, when do you think you would be able to test the
series ?

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-07-07  0:23   ` Laurent Pinchart
@ 2022-07-07 10:45     ` Alexander Stein
  2022-07-07 11:34       ` Laurent Pinchart
  0 siblings, 1 reply; 69+ messages in thread
From: Alexander Stein @ 2022-07-07 10:45 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hello Laurent,

Am Donnerstag, 7. Juli 2022, 02:23:55 CEST schrieb Laurent Pinchart:
> Hi Alexander,
> 
> On Wed, May 11, 2022 at 03:36:14PM +0200, Alexander Stein wrote:
> > Hello Laurent,
> > 
> > thanks for pushing out this huge set.
> > 
> > Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> > > Hello,
> > > 
> > > This patch series prepares the imx7-media-csi for destaging by
> > > decoupling it from the helpers shared with the i.MX6 IPUv3.
> > > 
> > > The strategy Paul and I have followed is to import copies of helper code
> > > and, refactor it within the imx7-media-csi driver, and repeat until no
> > > more shared helpers are used. There is still room for refactoring and
> > > simplification of the imx7-media-csi driver, but I believe it is now in
> > > a state clean enough to be moved out of staging.
> > > 
> > > The series also includes a few fixes or improvements in supported
> > > formats that are now made possible thanks to this refactoring. See
> > > patches 45/50 and 46/50 for details.
> > > 
> > > The code size has grown as a result. This is partly offset by code in
> > > the shared helpers that can be removed or simplified, but I haven't
> > > starting working on that. The helpers are now used for the i.MX6 IPUv3
> > > only, so I will leave this exercise to anyone who would be interested in
> > > destaging that driver as well.
> > > 
> > > Some of the items in the TODO file related to the imx7-media-csi driver
> > > have been addressed. The two remaining items are frame interval monitor
> > > support and restricting the list of supported formats to the SoC
> > > version. The former isn't a destaging blocker in my opinion, as the
> > > feature can be added later if desired (and frame interval monitoring
> > > should then be moved to the V4L2 core). I believe the latter could also
> > > be addressed after destaging the driver, but in any case, this is a
> > > discussion for a future destaging series (which may come as soon as this
> > > one is accepted).
> > > 
> > > Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> > > imx7/imx8mm media / csi patches" series.
> > 
> > Thanks for putting me on CC. I'll try to get my system running your
> > patches
> > ASAP.
> 
> As only minor changes were needed, I ended up posting v1.1 of the
> corresponding patches instead of spamming everybody with a full v2. For
> your convenience, I've pushed the result to
> 
> 	git://linuxtv.org/pinchartl/media.git imx7/destage
> 
> I know it's a bit of a short notice, but I'd like to send a pull request
> in time for v5.20, when do you think you would be able to test the
> series ?

I happen to have my setup already available, so I could test your updated 
series pretty fast.
Accessing imx327 still works for WIP config. So
Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>

Best regards,
Alexander




^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-07-07 10:45     ` Alexander Stein
@ 2022-07-07 11:34       ` Laurent Pinchart
  2022-07-07 11:52         ` Alexander Stein
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2022-07-07 11:34 UTC (permalink / raw)
  To: Alexander Stein
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hi Alexander,

On Thu, Jul 07, 2022 at 12:45:01PM +0200, Alexander Stein wrote:
> Am Donnerstag, 7. Juli 2022, 02:23:55 CEST schrieb Laurent Pinchart:
> > On Wed, May 11, 2022 at 03:36:14PM +0200, Alexander Stein wrote:
> > > Hello Laurent,
> > > 
> > > thanks for pushing out this huge set.
> > > 
> > > Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> > > > Hello,
> > > > 
> > > > This patch series prepares the imx7-media-csi for destaging by
> > > > decoupling it from the helpers shared with the i.MX6 IPUv3.
> > > > 
> > > > The strategy Paul and I have followed is to import copies of helper code
> > > > and, refactor it within the imx7-media-csi driver, and repeat until no
> > > > more shared helpers are used. There is still room for refactoring and
> > > > simplification of the imx7-media-csi driver, but I believe it is now in
> > > > a state clean enough to be moved out of staging.
> > > > 
> > > > The series also includes a few fixes or improvements in supported
> > > > formats that are now made possible thanks to this refactoring. See
> > > > patches 45/50 and 46/50 for details.
> > > > 
> > > > The code size has grown as a result. This is partly offset by code in
> > > > the shared helpers that can be removed or simplified, but I haven't
> > > > starting working on that. The helpers are now used for the i.MX6 IPUv3
> > > > only, so I will leave this exercise to anyone who would be interested in
> > > > destaging that driver as well.
> > > > 
> > > > Some of the items in the TODO file related to the imx7-media-csi driver
> > > > have been addressed. The two remaining items are frame interval monitor
> > > > support and restricting the list of supported formats to the SoC
> > > > version. The former isn't a destaging blocker in my opinion, as the
> > > > feature can be added later if desired (and frame interval monitoring
> > > > should then be moved to the V4L2 core). I believe the latter could also
> > > > be addressed after destaging the driver, but in any case, this is a
> > > > discussion for a future destaging series (which may come as soon as this
> > > > one is accepted).
> > > > 
> > > > Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> > > > imx7/imx8mm media / csi patches" series.
> > > 
> > > Thanks for putting me on CC. I'll try to get my system running your
> > > patches
> > > ASAP.
> > 
> > As only minor changes were needed, I ended up posting v1.1 of the
> > corresponding patches instead of spamming everybody with a full v2. For
> > your convenience, I've pushed the result to
> > 
> > 	git://linuxtv.org/pinchartl/media.git imx7/destage
> > 
> > I know it's a bit of a short notice, but I'd like to send a pull request
> > in time for v5.20, when do you think you would be able to test the
> > series ?
> 
> I happen to have my setup already available, so I could test your updated 
> series pretty fast.
> Accessing imx327 still works for WIP config. So
> Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>

Thanks a lot for the quick testing. I've now sent the pull request.

Do you plan to submit a new version of your patches on top of this ?

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 69+ messages in thread

* Re: Re: Re: [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi
  2022-07-07 11:34       ` Laurent Pinchart
@ 2022-07-07 11:52         ` Alexander Stein
  0 siblings, 0 replies; 69+ messages in thread
From: Alexander Stein @ 2022-07-07 11:52 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Jacopo Mondi, Martin Kepplinger, Dorota Czaplejewicz, kernel

Hi Laurent,

Am Donnerstag, 7. Juli 2022, 13:34:50 CEST schrieb Laurent Pinchart:
> Hi Alexander,
> 
> On Thu, Jul 07, 2022 at 12:45:01PM +0200, Alexander Stein wrote:
> > Am Donnerstag, 7. Juli 2022, 02:23:55 CEST schrieb Laurent Pinchart:
> > > On Wed, May 11, 2022 at 03:36:14PM +0200, Alexander Stein wrote:
> > > > Hello Laurent,
> > > > 
> > > > thanks for pushing out this huge set.
> > > > 
> > > > Am Dienstag, 10. Mai 2022, 13:58:09 CEST schrieb Laurent Pinchart:
> > > > > Hello,
> > > > > 
> > > > > This patch series prepares the imx7-media-csi for destaging by
> > > > > decoupling it from the helpers shared with the i.MX6 IPUv3.
> > > > > 
> > > > > The strategy Paul and I have followed is to import copies of helper
> > > > > code
> > > > > and, refactor it within the imx7-media-csi driver, and repeat until
> > > > > no
> > > > > more shared helpers are used. There is still room for refactoring
> > > > > and
> > > > > simplification of the imx7-media-csi driver, but I believe it is now
> > > > > in
> > > > > a state clean enough to be moved out of staging.
> > > > > 
> > > > > The series also includes a few fixes or improvements in supported
> > > > > formats that are now made possible thanks to this refactoring. See
> > > > > patches 45/50 and 46/50 for details.
> > > > > 
> > > > > The code size has grown as a result. This is partly offset by code
> > > > > in
> > > > > the shared helpers that can be removed or simplified, but I haven't
> > > > > starting working on that. The helpers are now used for the i.MX6
> > > > > IPUv3
> > > > > only, so I will leave this exercise to anyone who would be
> > > > > interested in
> > > > > destaging that driver as well.
> > > > > 
> > > > > Some of the items in the TODO file related to the imx7-media-csi
> > > > > driver
> > > > > have been addressed. The two remaining items are frame interval
> > > > > monitor
> > > > > support and restricting the list of supported formats to the SoC
> > > > > version. The former isn't a destaging blocker in my opinion, as the
> > > > > feature can be added later if desired (and frame interval monitoring
> > > > > should then be moved to the V4L2 core). I believe the latter could
> > > > > also
> > > > > be addressed after destaging the driver, but in any case, this is a
> > > > > discussion for a future destaging series (which may come as soon as
> > > > > this
> > > > > one is accepted).
> > > > > 
> > > > > Alexander, this also could greatly simplify your "[PATCH v3 0/8]
> > > > > imx7/imx8mm media / csi patches" series.
> > > > 
> > > > Thanks for putting me on CC. I'll try to get my system running your
> > > > patches
> > > > ASAP.
> > > 
> > > As only minor changes were needed, I ended up posting v1.1 of the
> > > corresponding patches instead of spamming everybody with a full v2. For
> > > your convenience, I've pushed the result to
> > > 
> > > 	git://linuxtv.org/pinchartl/media.git imx7/destage
> > > 
> > > I know it's a bit of a short notice, but I'd like to send a pull request
> > > in time for v5.20, when do you think you would be able to test the
> > > series ?
> > 
> > I happen to have my setup already available, so I could test your updated
> > series pretty fast.
> > Accessing imx327 still works for WIP config. So
> > Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> 
> Thanks a lot for the quick testing. I've now sent the pull request.
> 
> Do you plan to submit a new version of your patches on top of this ?

The patches regarding the imx[,7]-media-* are not needed anymore, they are 
obsolete now. There are only patches regarding DT overlay and the Vision 
Components FPGA and sensors I'm working on right now.

Best regards,
Alexander




^ permalink raw reply	[flat|nested] 69+ messages in thread

end of thread, other threads:[~2022-07-07 11:53 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 11:58 [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 01/50] staging: media: imx: imx7-media-csi: Initialize locks early on Laurent Pinchart
2022-05-10 11:58 ` [PATCH 02/50] staging: media: imx: imx7-media-csi: Split imx_media_dev from probe() Laurent Pinchart
2022-05-10 14:09   ` Rui Miguel Silva
2022-05-10 14:42     ` Laurent Pinchart
2022-05-10 15:25   ` [PATCH v1.1 " Laurent Pinchart
2022-05-10 15:49     ` Rui Miguel Silva
2022-05-10 11:58 ` [PATCH 03/50] staging: media: imx: imx7-media-csi: Import notifier helpers Laurent Pinchart
2022-05-10 11:58 ` [PATCH 04/50] staging: media: imx: imx7-media-csi: Drop duplicate link creation Laurent Pinchart
2022-05-10 11:58 ` [PATCH 05/50] staging: media: imx: imx7-media-csi: Drop the imx_media notifier Laurent Pinchart
2022-05-10 11:58 ` [PATCH 06/50] staging: media: imx: imx7-media-csi: Move misc init out of probe() Laurent Pinchart
2022-05-10 15:26   ` [PATCH v1.1 " Laurent Pinchart
2022-05-10 11:58 ` [PATCH 07/50] staging: media: imx: imx7-media-csi: Don't populate vdev lists Laurent Pinchart
2022-05-10 11:58 ` [PATCH 08/50] staging: media: imx: imx7-media-csi: Drop unused frame_interval Laurent Pinchart
2022-05-10 11:58 ` [PATCH 09/50] staging: media: imx: imx7-media-csi: Move format init to probe time Laurent Pinchart
2022-05-10 11:58 ` [PATCH 10/50] staging: media: imx: imx7-media-csi: Remove imx_media_of_add_csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 11/50] staging: media: imx: imx7-media-csi: Import video device helpers Laurent Pinchart
2022-05-10 11:58 ` [PATCH 12/50] staging: media: imx: imx7-media-csi: Drop legacy video device support Laurent Pinchart
2022-05-10 11:58 ` [PATCH 13/50] staging: media: imx: imx7-media-csi: Drop unused controls support Laurent Pinchart
2022-05-10 11:58 ` [PATCH 14/50] staging: media: imx: imx7-media-csi: Reorganize imx7_csi structure Laurent Pinchart
2022-05-10 11:58 ` [PATCH 15/50] staging: media: imx: imx7-media-csi: Fold capture_priv into imx7_csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 16/50] staging: media: imx: imx7-media-csi: Ensure consistent function prefix Laurent Pinchart
2022-05-10 11:58 ` [PATCH 17/50] staging: media: imx: imx7-media-csi: Don't set subdev group id Laurent Pinchart
2022-05-10 11:58 ` [PATCH 18/50] staging: media: imx: imx7-media-csi: Import imx_media_dev_init() helper Laurent Pinchart
2022-05-10 11:58 ` [PATCH 19/50] staging: media: imx: imx7-media-csi: Embed imx_media_dev in imx7_csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 20/50] staging: media: imx: imx7-media-csi: Drop imx_media_add_video_device call Laurent Pinchart
2022-05-10 11:58 ` [PATCH 21/50] staging: media: imx: imx7-media-csi: Don't initialize unused fields Laurent Pinchart
2022-05-10 11:58 ` [PATCH 22/50] staging: media: imx: imx7-media-csi: Inline imx_media_pipeline_pad() Laurent Pinchart
2022-05-10 11:58 ` [PATCH 23/50] staging: media: imx: imx7-media-csi: Import imx_media_pipeline_set_stream() Laurent Pinchart
2022-05-10 11:58 ` [PATCH 24/50] staging: media: imx: imx7-media-csi: Avoid unnecessary casts Laurent Pinchart
2022-05-10 11:58 ` [PATCH 25/50] staging: media: imx: imx7-media-csi: Inline pipeline start/stop Laurent Pinchart
2022-05-10 11:58 ` [PATCH 26/50] staging: media: imx: imx7-media-csi: Fold imx_media_dev into imx7_csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 27/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_buffer Laurent Pinchart
2022-05-10 11:58 ` [PATCH 28/50] staging: media: imx: imx7-media-csi: Fold imx_media_video_dev into imx7_csi Laurent Pinchart
2022-05-10 11:58 ` [PATCH 29/50] staging: media: imx: imx7-media-csi: Store imx7_csi in drv data Laurent Pinchart
2022-05-10 11:58 ` [PATCH 30/50] staging: media: imx: imx7-media-csi: Decouple from imx_media_dma_buf Laurent Pinchart
2022-05-10 11:58 ` [PATCH 31/50] staging: media: imx: imx7-media-csi: Decouple from shared macros Laurent Pinchart
2022-05-10 11:58 ` [PATCH 32/50] staging: media: imx: imx7-media-csi: Drop error message on alloc failure Laurent Pinchart
2022-05-10 11:58 ` [PATCH 33/50] staging: media: imx: imx7-media-csi: Import format helpers Laurent Pinchart
2022-05-10 11:58 ` [PATCH 34/50] staging: media: imx: imx7-media-csi: Replace ipu_color_space with bool yuv field Laurent Pinchart
2022-05-10 11:58 ` [PATCH 35/50] staging: media: imx: imx7-media-csi: Drop IC support from imx7_csi_try_colorimetry() Laurent Pinchart
2022-05-10 11:58 ` [PATCH 36/50] staging: media: imx: imx7-media-csi: Drop IPU-only formats Laurent Pinchart
2022-05-10 11:58 ` [PATCH 37/50] staging: media: imx: imx7-media-csi: Drop unsupported YUV and RGB formats Laurent Pinchart
2022-05-10 11:58 ` [PATCH 38/50] staging: media: imx: imx7-media-csi: Make default formats consistent Laurent Pinchart
2022-05-10 11:58 ` [PATCH 39/50] staging: media: imx: imx7-media-csi: Define macro for default mbus code Laurent Pinchart
2022-05-11 13:22   ` Alexander Stein
2022-05-11 20:20     ` Laurent Pinchart
2022-07-07  0:19   ` [PATCH v1.1 " Laurent Pinchart
2022-05-10 11:58 ` [PATCH 40/50] staging: media: imx: imx7-media-csi: Simplify default mbus code in try_fmt Laurent Pinchart
2022-05-10 11:58 ` [PATCH 41/50] staging: media: imx: imx7-media-csi: Drop YUV/RGB/BAYER format selectors Laurent Pinchart
2022-05-10 11:58 ` [PATCH 42/50] staging: media: imx: imx7-media-csi: Drop unneeded imx7_csi_pixfmt fields Laurent Pinchart
2022-05-10 11:58 ` [PATCH 43/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_init_mbus_fmt() Laurent Pinchart
2022-05-10 11:58 ` [PATCH 44/50] staging: media: imx: imx7-media-csi: Simplify default format in try_fmt Laurent Pinchart
2022-05-11 13:27   ` Alexander Stein
2022-07-07  0:20   ` [PATCH v1.1 " Laurent Pinchart
2022-05-10 11:58 ` [PATCH 45/50] staging: media: imx: imx7-media-csi: Fix list of supported formats Laurent Pinchart
2022-05-10 11:58 ` [PATCH 46/50] staging: media: imx: imx7-media-csi: Add V4L2_PIX_FMT_Y14 support Laurent Pinchart
2022-05-10 11:58 ` [PATCH 47/50] staging: media: imx: imx7-media-csi: Drop unneeded pixel format validation Laurent Pinchart
2022-05-10 11:58 ` [PATCH 48/50] staging: media: imx: imx7-media-csi: Inline imx7_csi_enum_pixel_formats() Laurent Pinchart
2022-05-10 11:58 ` [PATCH 49/50] staging: media: imx: imx7-media-csi: Drop V4L2 events support Laurent Pinchart
2022-05-10 11:58 ` [PATCH 50/50] staging: media: imx: imx7-media-csi: Drop usage of shared helpers Laurent Pinchart
2022-05-10 14:04 ` [PATCH 00/50] staging: media: imx: Prepare destaging of imx7-media-csi Rui Miguel Silva
2022-05-10 14:18   ` Laurent Pinchart
2022-05-11 13:36 ` (EXT) " Alexander Stein
2022-07-07  0:23   ` Laurent Pinchart
2022-07-07 10:45     ` Alexander Stein
2022-07-07 11:34       ` Laurent Pinchart
2022-07-07 11:52         ` Alexander Stein
2022-05-16  7:59 ` Alexander Stein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).