All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
@ 2021-02-15  4:26 Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 01/77] media: imx: Drop dependency on I2C Laurent Pinchart
                   ` (78 more replies)
  0 siblings, 79 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Hello,

This large patch series is a collection of miscellaneous fixes, cleanups
and enhancements for the i.MX7 camera support. Most notably, it
implements support for the Media Controller API in the driver.

Compared to v1, review comments have been taken into account, and the
patches have been rebased on top of the DT bindings and latest imx
changes as present in the linux-media tree. Patches 38/77, 39/77, 60/77
and 61/77 are new. For additional information, please see individual
patches.

I have successfully tested the code on an i.MX6ULL board (with an
MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an i.MX8MM
board (with an OV5640 sensor, and additional patches for i.MX8MM
support).

Laurent Pinchart (77):
  media: imx: Drop dependency on I2C
  media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol
  media: imx: Drop manual dependency on VIDEO_IMX_MEDIA
  media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  media: imx: Set default sizes through macros in all drivers
  media: imx: utils: Add ability to filter pixel formats by mbus code
  media: imx: capture: Use dev_* instead of v4l2_* to log messages
  media: imx: capture: Use device name to construct bus_info
  media: imx: capture: Remove forward declaration of capture_qops
  media: imx: capture: Handle errors from v4l2_fh_open()
  media: imx: capture: Clean up capture_priv structure
  media: imx: capture: Remove capture_priv stop field
  media: imx: capture: Move queue and ctrl handler init to init function
  media: imx: capture: Initialize video_device programmatically
  media: imx: capture: Register the video device after completing init
  media: imx: capture: Store v4l2_pix_format in imx_media_video_dev
  media: imx: capture: Move default format init to a separate function
  media: imx: capture: Rename querycap handler to capture_querycap
  media: imx: capture: Rename ioctl operations with legacy prefix
  media: imx: capture: Add a mechanism to disable control inheritance
  media: imx: capture: Remove unneeded variable in
    __capture_legacy_try_fmt
  media: imx: capture: Pass v4l2_pix_format to
    __capture_legacy_try_fmt()
  media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt()
  media: imx: capture: Extract format lookup from
    __capture_legacy_try_fmt
  media: imx: capture: Simplify capture_validate_fmt() implementation
  media: imx: capture: Simplify __capture_legacy_try_fmt()
  media: imx: capture: Decouple video node from source with MC-centric
    API
  media: imx: capture: Expose V4L2_CAP_IO_MC for the MC-centric API
  media: imx: imx7-media-csi: Disable legacy video node API
  media: imx: capture: Support creating immutable link to capture device
  media: imx: imx7-media-csi: Remove control handler
  media: imx: imx7-media-csi: Move (de)init from link setup to
    .s_stream()
  media: imx: imx7-media-csi: Create immutable link to capture device
  media: imx: imx7-media-csi: Replace CSICR*_RESET_VAL with values
  media: imx: imx7-media-csi: Tidy up register fields macros
  media: imx: imx7-media-csi: Reorganize code in sections
  media: imx: imx7-media-csi: Validate capture format in
    .link_validate()
  media: imx: imx7-media-csi: Fix source type identification
  media: imx: imx7-media-csi: Don't lock access to is_csi2
  media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup()
  media: imx: imx7-media-csi: Split imx7_csi_dma_stop()
  media: imx: imx7-media-csi: Move CSI configuration before source start
  media: imx: imx7-media-csi: Merge streaming_start() with csi_enable()
  media: imx: imx7-media-csi: Merge hw_reset() with init_interface()
  media: imx: imx7-media-csi: Set the MIPI data type based on the bus
    code
  media: imx: imx7-media-csi: Don't set the buffer stride when disabling
  media: imx: imx7-media-csi: Merge all config in imx7_csi_configure()
  media: imx: imx7-media-csi: Clear all configurable CSICR18 fields
  media: imx: imx7-media-csi: Set RFF burst type in imx7_csi_configure()
  media: imx: imx7-media-csi: Simplify imx7_csi_rx_fifo_clear()
  media: imx: imx7-media-csi: Don't double-enable the CSI
  media: imx: imx7-media-csi: Don't double-enable the RxFIFO
  media: imx: imx7-media-csi: Remove double reflash of DMA controller
  media: imx: imx7-media-csi: Don't enable SOF and EOF interrupts
  media: imx: imx7_media-csi: Add support for additional Bayer patterns
  media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad()
  media: imx: imx7_media-csi: Create immutable link to source device
  dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property
  dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle
    property
  dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces
  dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions
  media: imx: imx7_mipi_csis: Acquire reset control without naming it
  media: imx: imx7_mipi_csis: Fix input size alignment
  media: imx: imx7_mipi_csis: Make source .s_power() optional
  media: imx: imx7_mipi_csis: Avoid double get of wrap clock
  media: imx: imx7_mipi_csis: Drop 10-bit YUV support
  media: imx: imx7_mipi_csis: Fix UYVY8 media bus format
  media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle()
  media: imx: imx7_mipi_csis: Move link setup check out of locked
    section
  media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate
  media: imx: imx7_mipi_csis: Turn register access macros into functions
  media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL
    register
  media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields
  media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID
  media: imx: imx7_mipi_csis: Rename register macros to match datasheet
  media: imx: imx7_mipi_csis: Use register macros in
    mipi_csis_dump_regs()
  media: imx: imx7_mipi_csis: Print shadow registers in
    mipi_csis_dump_regs()

 .../bindings/media/nxp,imx7-mipi-csi2.yaml    |   94 +-
 drivers/media/v4l2-core/v4l2-mc.c             |    6 +-
 drivers/staging/media/imx/Kconfig             |    9 +-
 drivers/staging/media/imx/Makefile            |    6 +-
 drivers/staging/media/imx/TODO                |    9 +-
 drivers/staging/media/imx/imx-ic-prp.c        |    4 +-
 drivers/staging/media/imx/imx-ic-prpencvf.c   |   24 +-
 drivers/staging/media/imx/imx-media-capture.c |  685 +++++++----
 .../staging/media/imx/imx-media-csc-scaler.c  |    2 +-
 drivers/staging/media/imx/imx-media-csi.c     |   33 +-
 .../staging/media/imx/imx-media-dev-common.c  |    4 +
 drivers/staging/media/imx/imx-media-utils.c   |   23 +-
 drivers/staging/media/imx/imx-media-vdic.c    |    7 +-
 drivers/staging/media/imx/imx-media.h         |   12 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c    |    6 +-
 drivers/staging/media/imx/imx7-media-csi.c    | 1042 ++++++++---------
 drivers/staging/media/imx/imx7-mipi-csis.c    |  399 ++++---
 include/media/v4l2-mc.h                       |    8 +-
 18 files changed, 1275 insertions(+), 1098 deletions(-)

-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 01/77] media: imx: Drop dependency on I2C
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 02/77] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
                   ` (77 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The i.MX staging media drivers don't depend on I2C. Drop the dependency
from Kconfig.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
index 15322dc3124a..743e43742211 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -18,7 +18,7 @@ menu "i.MX5/6/7/8 Media Sub devices"
 
 config VIDEO_IMX_CSI
 	tristate "i.MX5/6 Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C
+	depends on VIDEO_IMX_MEDIA && VIDEO_DEV
 	depends on IMX_IPUV3_CORE
 	default y
 	help
@@ -26,7 +26,7 @@ config VIDEO_IMX_CSI
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 / i.MX8M Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C
+	depends on VIDEO_IMX_MEDIA && VIDEO_DEV
 	default y
 	help
 	  Enable support for video4linux camera sensor interface driver for
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 02/77] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 01/77] media: imx: Drop dependency on I2C Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 03/77] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
                   ` (76 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

All the i.MX staging media drivers depend on VIDEO_DEV. Move the
dependency to the common VIDEO_IMX_MEDIA symbol to avoid repeating it.

While at it, sort the dependencies and selections alphabetically.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/Kconfig | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
index 743e43742211..e3ca3c9d5d22 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -2,13 +2,14 @@
 config VIDEO_IMX_MEDIA
 	tristate "i.MX5/6 V4L2 media core driver"
 	depends on ARCH_MXC || COMPILE_TEST
+	depends on HAS_DMA
+	depends on VIDEO_DEV
 	depends on VIDEO_V4L2
 	select MEDIA_CONTROLLER
-	select VIDEO_V4L2_SUBDEV_API
-	depends on HAS_DMA
-	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_FWNODE
 	select V4L2_MEM2MEM_DEV
+	select VIDEOBUF2_DMA_CONTIG
+	select VIDEO_V4L2_SUBDEV_API
 	help
 	  Say yes here to enable support for video4linux media controller
 	  driver for the i.MX5/6 SOC.
@@ -18,7 +19,7 @@ menu "i.MX5/6/7/8 Media Sub devices"
 
 config VIDEO_IMX_CSI
 	tristate "i.MX5/6 Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA && VIDEO_DEV
+	depends on VIDEO_IMX_MEDIA
 	depends on IMX_IPUV3_CORE
 	default y
 	help
@@ -26,7 +27,7 @@ config VIDEO_IMX_CSI
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 / i.MX8M Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA && VIDEO_DEV
+	depends on VIDEO_IMX_MEDIA
 	default y
 	help
 	  Enable support for video4linux camera sensor interface driver for
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 03/77] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 01/77] media: imx: Drop dependency on I2C Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 02/77] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
                   ` (75 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The VIDEO_IMX_CSI and VIDEO_IMX7_CSI symbols are defined in a section
guarded by VIDEO_IMX_MEDIA. There's no need to duplicate that with a
"depends on" statement. Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/Kconfig | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
index e3ca3c9d5d22..c3bf433ba3e3 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -19,7 +19,6 @@ menu "i.MX5/6/7/8 Media Sub devices"
 
 config VIDEO_IMX_CSI
 	tristate "i.MX5/6 Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA
 	depends on IMX_IPUV3_CORE
 	default y
 	help
@@ -27,7 +26,6 @@ config VIDEO_IMX_CSI
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 / i.MX8M Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA
 	default y
 	help
 	  Enable support for video4linux camera sensor interface driver for
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (2 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 03/77] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-26 15:45   ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 05/77] media: imx: Set default sizes through macros in all drivers Laurent Pinchart
                   ` (74 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

imx6-media-objs contains a set of objects that are specific to the i.MX6
IPU-based media subsystem. They're not needed for the i.MX7 CSI. Only
compile them if CONFIG_VIDEO_IMX_CSI is selected.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/imx/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
index 69cc5da04a2e..6ac33275cc97 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1,11 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
+imx-media-common-objs := imx-media-capture.o imx-media-dev-common.o \
+	imx-media-of.o imx-media-utils.o
+
 imx6-media-objs := imx-media-dev.o imx-media-internal-sd.o \
 	imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o imx-media-vdic.o \
 	imx-media-csc-scaler.o
 
-imx-media-common-objs := imx-media-capture.o imx-media-dev-common.o \
-	imx-media-of.o imx-media-utils.o
-
 imx6-media-csi-objs := imx-media-csi.o imx-media-fim.o
 
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 05/77] media: imx: Set default sizes through macros in all drivers
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (3 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 06/77] media: imx: utils: Add ability to filter pixel formats by mbus code Laurent Pinchart
                   ` (73 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

All drivers use 640x480 as the default size, but they all hardcode those
values. Create two global macros named IMX_MEDIA_DEF_PIX_WIDTH and
IMX_MEDIA_DEF_PIX_HEIGHT to store the default size, and use them through
the code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-ic-prp.c      |  4 +++-
 drivers/staging/media/imx/imx-ic-prpencvf.c |  5 +++--
 drivers/staging/media/imx/imx-media-csi.c   | 13 +++++++------
 drivers/staging/media/imx/imx-media-vdic.c  |  5 +++--
 drivers/staging/media/imx/imx-media.h       |  3 +++
 drivers/staging/media/imx/imx6-mipi-csi2.c  |  4 +++-
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c
index 5b09e11b1a0e..f21ed881295f 100644
--- a/drivers/staging/media/imx/imx-ic-prp.c
+++ b/drivers/staging/media/imx/imx-ic-prp.c
@@ -442,7 +442,9 @@ static int prp_registered(struct v4l2_subdev *sd)
 	/* set a default mbus format  */
 	imx_media_enum_ipu_formats(&code, 0, PIXFMT_SEL_YUV);
 
-	return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
+	return imx_media_init_mbus_fmt(&priv->format_mbus,
+				       IMX_MEDIA_DEF_PIX_WIDTH,
+				       IMX_MEDIA_DEF_PIX_HEIGHT, code,
 				       V4L2_FIELD_NONE, NULL);
 }
 
diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c
index 74f5de466d5d..47df1a5a1ae8 100644
--- a/drivers/staging/media/imx/imx-ic-prpencvf.c
+++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
@@ -1255,8 +1255,9 @@ static int prp_registered(struct v4l2_subdev *sd)
 
 	for (i = 0; i < PRPENCVF_NUM_PADS; i++) {
 		ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
-					      640, 480, code, V4L2_FIELD_NONE,
-					      &priv->cc[i]);
+					      IMX_MEDIA_DEF_PIX_WIDTH,
+					      IMX_MEDIA_DEF_PIX_HEIGHT, code,
+					      V4L2_FIELD_NONE, &priv->cc[i]);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index ef5add079774..b9d3f98a2c8f 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1758,8 +1758,9 @@ static int csi_registered(struct v4l2_subdev *sd)
 
 		/* set a default mbus format  */
 		ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
-					      640, 480, code, V4L2_FIELD_NONE,
-					      &priv->cc[i]);
+					      IMX_MEDIA_DEF_PIX_WIDTH,
+					      IMX_MEDIA_DEF_PIX_HEIGHT, code,
+					      V4L2_FIELD_NONE, &priv->cc[i]);
 		if (ret)
 			goto put_csi;
 
@@ -1772,10 +1773,10 @@ static int csi_registered(struct v4l2_subdev *sd)
 	priv->skip = &csi_skip[0];
 
 	/* init default crop and compose rectangle sizes */
-	priv->crop.width = 640;
-	priv->crop.height = 480;
-	priv->compose.width = 640;
-	priv->compose.height = 480;
+	priv->crop.width = IMX_MEDIA_DEF_PIX_WIDTH;
+	priv->crop.height = IMX_MEDIA_DEF_PIX_HEIGHT;
+	priv->compose.width = IMX_MEDIA_DEF_PIX_WIDTH;
+	priv->compose.height = IMX_MEDIA_DEF_PIX_HEIGHT;
 
 	priv->fim = imx_media_fim_init(&priv->sd);
 	if (IS_ERR(priv->fim)) {
diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c
index 879329f81f79..395b850736fa 100644
--- a/drivers/staging/media/imx/imx-media-vdic.c
+++ b/drivers/staging/media/imx/imx-media-vdic.c
@@ -856,8 +856,9 @@ static int vdic_registered(struct v4l2_subdev *sd)
 
 		/* set a default mbus format  */
 		ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
-					      640, 480, code, V4L2_FIELD_NONE,
-					      &priv->cc[i]);
+					      IMX_MEDIA_DEF_PIX_WIDTH,
+					      IMX_MEDIA_DEF_PIX_HEIGHT, code,
+					      V4L2_FIELD_NONE, &priv->cc[i]);
 		if (ret)
 			return ret;
 
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index c8b6a43d0d7c..1abb9bb88c12 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -15,6 +15,9 @@
 #include <media/videobuf2-dma-contig.h>
 #include <video/imx-ipu-v3.h>
 
+#define IMX_MEDIA_DEF_PIX_WIDTH		640
+#define IMX_MEDIA_DEF_PIX_HEIGHT	480
+
 /*
  * Enumeration of the IPU internal sub-devices
  */
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 4f8fcc91aaae..9020541edb89 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -571,7 +571,9 @@ static int csi2_registered(struct v4l2_subdev *sd)
 
 	/* set a default mbus format  */
 	return imx_media_init_mbus_fmt(&csi2->format_mbus,
-				      640, 480, 0, V4L2_FIELD_NONE, NULL);
+				      IMX_MEDIA_DEF_PIX_WIDTH,
+				      IMX_MEDIA_DEF_PIX_HEIGHT, 0,
+				      V4L2_FIELD_NONE, NULL);
 }
 
 static const struct media_entity_operations csi2_entity_ops = {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 06/77] media: imx: utils: Add ability to filter pixel formats by mbus code
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (4 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 05/77] media: imx: Set default sizes through macros in all drivers Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 07/77] media: imx: capture: Use dev_* instead of v4l2_* to log messages Laurent Pinchart
                   ` (72 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Add a media bus code argument to the imx_media_enum_pixel_formats(). If
set to a non-zero value, the function will only consider pixel formats
that match the given media bus code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c |  5 ++--
 .../staging/media/imx/imx-media-csc-scaler.c  |  2 +-
 drivers/staging/media/imx/imx-media-utils.c   | 23 ++++++++++++++++++-
 drivers/staging/media/imx/imx-media.h         |  2 +-
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index e10ce103a5b4..bea3467e017c 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -174,7 +174,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
 			(cc_src->cs == IPUV3_COLORSPACE_YUV) ?
 			PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
 
-		ret = imx_media_enum_pixel_formats(&fourcc, f->index, fmt_sel);
+		ret = imx_media_enum_pixel_formats(&fourcc, f->index, fmt_sel,
+						   0);
 		if (ret)
 			return ret;
 	} else {
@@ -223,7 +224,7 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
 
 		cc = imx_media_find_pixel_format(fourcc, fmt_sel);
 		if (!cc) {
-			imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel);
+			imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
 			cc = imx_media_find_pixel_format(fourcc, fmt_sel);
 		}
 	} else {
diff --git a/drivers/staging/media/imx/imx-media-csc-scaler.c b/drivers/staging/media/imx/imx-media-csc-scaler.c
index 63a0204502a8..eb6da9b9d8ba 100644
--- a/drivers/staging/media/imx/imx-media-csc-scaler.c
+++ b/drivers/staging/media/imx/imx-media-csc-scaler.c
@@ -167,7 +167,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,
 	int ret;
 
 	ret = imx_media_enum_pixel_formats(&fourcc, f->index,
-					   PIXFMT_SEL_YUV_RGB);
+					   PIXFMT_SEL_YUV_RGB, 0);
 	if (ret)
 		return ret;
 
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c
index c2088f7ceef5..5128915a5d6f 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -283,9 +283,11 @@ EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
  * @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.
  */
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-				 enum imx_pixfmt_sel fmt_sel)
+				 enum imx_pixfmt_sel fmt_sel, u32 code)
 {
 	bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;
 	unsigned int i;
@@ -306,6 +308,25 @@ int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
 		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;
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index 1abb9bb88c12..085110eec87e 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -170,7 +170,7 @@ struct imx_media_dev {
 const struct imx_media_pixfmt *
 imx_media_find_pixel_format(u32 fourcc, enum imx_pixfmt_sel sel);
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-				 enum imx_pixfmt_sel sel);
+				 enum imx_pixfmt_sel sel, u32 code);
 const struct imx_media_pixfmt *
 imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel sel);
 int imx_media_enum_mbus_formats(u32 *code, u32 index,
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 07/77] media: imx: capture: Use dev_* instead of v4l2_* to log messages
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (5 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 06/77] media: imx: utils: Add ability to filter pixel formats by mbus code Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 08/77] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
                   ` (71 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx-media-capture helpers operate a video device node, but abuse the
v4l2_* subdev print functions to log messages. We have a struct device
pointer available, use it instead with the dev_* functions. This reduces
dependencies from imx-media-capture to the connected subdev.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index bea3467e017c..5fcf731ed450 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -163,7 +163,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
 	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 	ret = v4l2_subdev_call(priv->src_sd, pad, get_fmt, NULL, &fmt_src);
 	if (ret) {
-		v4l2_err(priv->src_sd, "failed to get src_sd format\n");
+		dev_err(priv->dev, "failed to get src_sd format\n");
 		return ret;
 	}
 
@@ -289,7 +289,7 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 	int ret;
 
 	if (vb2_is_busy(&priv->q)) {
-		v4l2_err(priv->src_sd, "%s queue busy\n", __func__);
+		dev_err(priv->dev, "%s queue busy\n", __func__);
 		return -EBUSY;
 	}
 
@@ -510,9 +510,9 @@ static int capture_buf_prepare(struct vb2_buffer *vb)
 	struct v4l2_pix_format *pix = &priv->vdev.fmt.fmt.pix;
 
 	if (vb2_plane_size(vb, 0) < pix->sizeimage) {
-		v4l2_err(priv->src_sd,
-			 "data will not fit into plane (%lu < %lu)\n",
-			 vb2_plane_size(vb, 0), (long)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;
 	}
 
@@ -570,14 +570,14 @@ static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 	ret = capture_validate_fmt(priv);
 	if (ret) {
-		v4l2_err(priv->src_sd, "capture format not valid\n");
+		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) {
-		v4l2_err(priv->src_sd, "pipeline start failed with %d\n", ret);
+		dev_err(priv->dev, "pipeline start failed with %d\n", ret);
 		goto return_bufs;
 	}
 
@@ -610,7 +610,7 @@ static void capture_stop_streaming(struct vb2_queue *vq)
 	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
 					    false);
 	if (ret)
-		v4l2_warn(priv->src_sd, "pipeline stop failed with %d\n", ret);
+		dev_warn(priv->dev, "pipeline stop failed with %d\n", ret);
 
 	/* release all active buffers */
 	spin_lock_irqsave(&priv->q_lock, flags);
@@ -646,7 +646,7 @@ static int capture_open(struct file *file)
 
 	ret = v4l2_fh_open(file);
 	if (ret)
-		v4l2_err(priv->src_sd, "v4l2_fh_open failed\n");
+		dev_err(priv->dev, "v4l2_fh_open failed\n");
 
 	ret = v4l2_pipeline_pm_get(&vfd->entity);
 	if (ret)
@@ -749,7 +749,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 
 	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
 	if (ret) {
-		v4l2_err(sd, "Failed to register video device\n");
+		dev_err(priv->dev, "Failed to register video device\n");
 		return ret;
 	}
 
@@ -766,7 +766,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 
 	ret = vb2_queue_init(vq);
 	if (ret) {
-		v4l2_err(sd, "vb2_queue_init failed\n");
+		dev_err(priv->dev, "vb2_queue_init failed\n");
 		goto unreg;
 	}
 
@@ -776,7 +776,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
 				    &vfd->entity, 0, 0);
 	if (ret) {
-		v4l2_err(sd, "failed to create link to device node\n");
+		dev_err(priv->dev, "failed to create link to device node\n");
 		goto unreg;
 	}
 
@@ -785,7 +785,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 	ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt_src);
 	if (ret) {
-		v4l2_err(sd, "failed to get src_sd format\n");
+		dev_err(priv->dev, "failed to get src_sd format\n");
 		goto unreg;
 	}
 
@@ -797,8 +797,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	vdev->cc = imx_media_find_pixel_format(vdev->fmt.fmt.pix.pixelformat,
 					       PIXFMT_SEL_ANY);
 
-	v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name,
-		  video_device_node_name(vfd));
+	dev_info(priv->dev, "Registered %s as /dev/%s\n", vfd->name,
+		 video_device_node_name(vfd));
 
 	vfd->ctrl_handler = &priv->ctrl_hdlr;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 08/77] media: imx: capture: Use device name to construct bus_info
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (6 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 07/77] media: imx: capture: Use dev_* instead of v4l2_* to log messages Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 09/77] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
                   ` (70 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The v4l2_capability bus_info field is meant to locate the device in the
system. Using a subdev name isn't a good fit, the device name is a much
better option. Use it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 5fcf731ed450..4c9ae3a7c37d 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -74,7 +74,7 @@ static int vidioc_querycap(struct file *file, void *fh,
 	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", priv->src_sd->name);
+		 "platform:%s", dev_name(priv->dev));
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 09/77] media: imx: capture: Remove forward declaration of capture_qops
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (7 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 08/77] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 10/77] media: imx: capture: Handle errors from v4l2_fh_open() Laurent Pinchart
                   ` (69 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The forward declaration of capture_qops isn't needed, remove it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 4c9ae3a7c37d..50bbcb1217e3 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -60,8 +60,6 @@ struct capture_priv {
 /* In bytes, per queue */
 #define VID_MEM_LIMIT	SZ_64M
 
-static const struct vb2_ops capture_qops;
-
 /*
  * Video ioctls follow
  */
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 10/77] media: imx: capture: Handle errors from v4l2_fh_open()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (8 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 09/77] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 11/77] media: imx: capture: Clean up capture_priv structure Laurent Pinchart
                   ` (68 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

If the call to v4l2_fh_open() fails, return the error code instead of
proceeding normally as if nothing happened.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 50bbcb1217e3..101ad562c2eb 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -643,13 +643,16 @@ static int capture_open(struct file *file)
 		return -ERESTARTSYS;
 
 	ret = v4l2_fh_open(file);
-	if (ret)
+	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;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 11/77] media: imx: capture: Clean up capture_priv structure
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (9 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 10/77] media: imx: capture: Handle errors from v4l2_fh_open() Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 12/77] media: imx: capture: Remove capture_priv stop field Laurent Pinchart
                   ` (67 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Document all the fields of the capture_priv structure and group them by
purpose.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 30 ++++++++-----------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 101ad562c2eb..933ebc69e16d 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -29,30 +29,24 @@
 #define IMX_CAPTURE_NAME "imx-capture"
 
 struct capture_priv {
-	struct imx_media_video_dev vdev;
+	struct imx_media_dev *md;		/* Media device */
+	struct device *dev;			/* Physical device */
 
-	struct v4l2_subdev    *src_sd;
-	int                   src_sd_pad;
-	struct device         *dev;
+	struct imx_media_video_dev vdev;	/* Video device */
+	struct media_pad vdev_pad;		/* Video device pad */
 
-	struct imx_media_dev  *md;
+	struct v4l2_subdev *src_sd;		/* Source subdev */
+	int src_sd_pad;				/* Source subdev pad */
 
-	struct media_pad      vdev_pad;
+	struct mutex mutex;			/* Protect vdev operations */
 
-	struct mutex          mutex;       /* capture device mutex */
+	struct vb2_queue q;			/* The videobuf2 queue */
+	struct list_head ready_q;		/* List of queued buffers */
+	spinlock_t q_lock;			/* Protect ready_q */
 
-	/* the videobuf2 queue */
-	struct vb2_queue       q;
-	/* list of ready imx_media_buffer's from q */
-	struct list_head       ready_q;
-	/* protect ready_q */
-	spinlock_t             q_lock;
+	struct v4l2_ctrl_handler ctrl_hdlr;	/* Controls inherited from subdevs */
 
-	/* controls inherited from subdevs */
-	struct v4l2_ctrl_handler ctrl_hdlr;
-
-	/* misc status */
-	bool                  stop;          /* streaming is stopping */
+	bool stop;				/* streaming is stopping */
 };
 
 #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 12/77] media: imx: capture: Remove capture_priv stop field
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (10 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 11/77] media: imx: capture: Clean up capture_priv structure Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 13/77] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
                   ` (66 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The stop field in the capture_priv structure is only set, never read.
Drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 933ebc69e16d..4cee7ba55311 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -45,8 +45,6 @@ struct capture_priv {
 	spinlock_t q_lock;			/* Protect ready_q */
 
 	struct v4l2_ctrl_handler ctrl_hdlr;	/* Controls inherited from subdevs */
-
-	bool stop;				/* streaming is stopping */
 };
 
 #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
@@ -573,8 +571,6 @@ static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto return_bufs;
 	}
 
-	priv->stop = false;
-
 	return 0;
 
 return_bufs:
@@ -595,10 +591,6 @@ static void capture_stop_streaming(struct vb2_queue *vq)
 	unsigned long flags;
 	int ret;
 
-	spin_lock_irqsave(&priv->q_lock, flags);
-	priv->stop = true;
-	spin_unlock_irqrestore(&priv->q_lock, flags);
-
 	ret = imx_media_pipeline_set_stream(priv->md, &priv->src_sd->entity,
 					    false);
 	if (ret)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 13/77] media: imx: capture: Move queue and ctrl handler init to init function
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (11 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 12/77] media: imx: capture: Remove capture_priv stop field Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 14/77] media: imx: capture: Initialize video_device programmatically Laurent Pinchart
                   ` (65 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Move the initialization of the vb2 queue and the control handler to the
imx_media_capture_device_init() function. There's no need to delay them
until the registration time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 51 ++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 4cee7ba55311..88de2eef74d2 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -725,7 +725,6 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	struct v4l2_subdev *sd = priv->src_sd;
 	struct v4l2_device *v4l2_dev = sd->v4l2_dev;
 	struct video_device *vfd = vdev->vfd;
-	struct vb2_queue *vq = &priv->q;
 	struct v4l2_subdev_format fmt_src;
 	int ret;
 
@@ -740,25 +739,6 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 		return ret;
 	}
 
-	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");
-		goto unreg;
-	}
-
-	INIT_LIST_HEAD(&priv->ready_q);
-
 	/* create the link from the src_sd devnode pad to device node */
 	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
 				    &vfd->entity, 0, 0);
@@ -787,8 +767,6 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	dev_info(priv->dev, "Registered %s as /dev/%s\n", vfd->name,
 		 video_device_node_name(vfd));
 
-	vfd->ctrl_handler = &priv->ctrl_hdlr;
-
 	/* add vdev to the video device list */
 	imx_media_add_video_device(priv->md, vdev);
 
@@ -815,6 +793,7 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 {
 	struct capture_priv *priv;
 	struct video_device *vfd;
+	struct vb2_queue *vq;
 	int ret;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -826,8 +805,10 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	priv->dev = dev;
 
 	mutex_init(&priv->mutex);
+	INIT_LIST_HEAD(&priv->ready_q);
 	spin_lock_init(&priv->q_lock);
 
+	/* Allocate and initialize the video device. */
 	snprintf(capture_videodev.name, sizeof(capture_videodev.name),
 		 "%s capture", src_sd->name);
 
@@ -838,8 +819,12 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	*vfd = capture_videodev;
 	vfd->lock = &priv->mutex;
 	vfd->queue = &priv->q;
+
+	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) {
@@ -847,11 +832,29 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 		return ERR_PTR(ret);
 	}
 
-	INIT_LIST_HEAD(&priv->vdev.list);
+	/* 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;
 
-	video_set_drvdata(vfd, priv);
+	ret = vb2_queue_init(vq);
+	if (ret) {
+		dev_err(priv->dev, "vb2_queue_init failed\n");
+		video_device_release(vfd);
+		return ERR_PTR(ret);
+	}
 
+	/* Initialize the control handler. */
 	v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
+	vfd->ctrl_handler = &priv->ctrl_hdlr;
 
 	return &priv->vdev;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 14/77] media: imx: capture: Initialize video_device programmatically
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (12 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 13/77] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 15/77] media: imx: capture: Register the video device after completing init Laurent Pinchart
                   ` (64 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Overwriting the whole video_device isn't future-proof as it would
overwrite any field initialized by video_device_alloc(). Furthermore,
the current implementation modifies the global template video_device as
if it were a per-instance structure, which is bad practice. To fix all
this, initialize the video device programmatically in
imx_media_capture_device_init().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-media-capture.c | 23 ++++++++-----------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 88de2eef74d2..78b6e592692f 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -672,16 +672,6 @@ static const struct v4l2_file_operations capture_fops = {
 	.mmap		= vb2_fop_mmap,
 };
 
-static struct video_device capture_videodev = {
-	.fops		= &capture_fops,
-	.ioctl_ops	= &capture_ioctl_ops,
-	.minor		= -1,
-	.release	= video_device_release,
-	.vfl_dir	= VFL_DIR_RX,
-	.tvnorms	= V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
-	.device_caps	= V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING,
-};
-
 struct imx_media_buffer *
 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
 {
@@ -809,17 +799,22 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	spin_lock_init(&priv->q_lock);
 
 	/* Allocate and initialize the video device. */
-	snprintf(capture_videodev.name, sizeof(capture_videodev.name),
-		 "%s capture", src_sd->name);
-
 	vfd = video_device_alloc();
 	if (!vfd)
 		return ERR_PTR(-ENOMEM);
 
-	*vfd = capture_videodev;
+	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;
 	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);
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 15/77] media: imx: capture: Register the video device after completing init
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (13 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 14/77] media: imx: capture: Initialize video_device programmatically Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 16/77] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev Laurent Pinchart
                   ` (63 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

When the video device is registered, it can get used by userspace
immediately. Its initialization must thus be fully complete. Ensure this
by registering the video device after all initialization steps.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 37 +++++++++----------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 78b6e592692f..cd0ad2b32bbf 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -723,27 +723,13 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 
 	vfd->v4l2_dev = v4l2_dev;
 
-	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
-	if (ret) {
-		dev_err(priv->dev, "Failed to register video device\n");
-		return ret;
-	}
-
-	/* create the link from the src_sd devnode pad to device node */
-	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
-				    &vfd->entity, 0, 0);
-	if (ret) {
-		dev_err(priv->dev, "failed to create link to device node\n");
-		goto unreg;
-	}
-
 	/* setup default format */
 	fmt_src.pad = priv->src_sd_pad;
 	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
 	ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt_src);
 	if (ret) {
 		dev_err(priv->dev, "failed to get src_sd format\n");
-		goto unreg;
+		return ret;
 	}
 
 	vdev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -754,16 +740,29 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 	vdev->cc = imx_media_find_pixel_format(vdev->fmt.fmt.pix.pixelformat,
 					       PIXFMT_SEL_ANY);
 
+	/* 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));
 
-	/* add vdev to the video device list */
+	/* Create the link from the src_sd devnode pad to device node. */
+	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
+				    &vfd->entity, 0, 0);
+	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;
-unreg:
-	video_unregister_device(vfd);
-	return ret;
 }
 EXPORT_SYMBOL_GPL(imx_media_capture_device_register);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 16/77] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (14 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 15/77] media: imx: capture: Register the video device after completing init Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 17/77] media: imx: capture: Move default format init to a separate function Laurent Pinchart
                   ` (62 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx_media_video_dev structure stores the active format on the video
node in an instance of v4l2_format. This wastes memory when all we need
is the information contained in the smaller v4l2_pix_format
sub-structure. Replace v4l2_format by v4l2_pix_format to save memory.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/staging/media/imx/imx-ic-prpencvf.c   | 15 +++++--------
 drivers/staging/media/imx/imx-media-capture.c | 22 +++++++++----------
 drivers/staging/media/imx/imx-media-csi.c     | 11 ++++------
 drivers/staging/media/imx/imx-media-vdic.c    |  2 +-
 drivers/staging/media/imx/imx-media.h         |  2 +-
 drivers/staging/media/imx/imx7-media-csi.c    |  7 +++---
 6 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c
index 47df1a5a1ae8..adb1a09e59d2 100644
--- a/drivers/staging/media/imx/imx-ic-prpencvf.c
+++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
@@ -204,7 +204,7 @@ static void prp_vb2_buf_done(struct prp_priv *priv, struct ipuv3_channel *ch)
 
 	done = priv->active_vb2_buf[priv->ipu_buf_num];
 	if (done) {
-		done->vbuf.field = vdev->fmt.fmt.pix.field;
+		done->vbuf.field = vdev->fmt.field;
 		done->vbuf.sequence = priv->frame_sequence;
 		vb = &done->vbuf.vb2_buf;
 		vb->timestamp = ktime_get_ns();
@@ -229,7 +229,7 @@ static void prp_vb2_buf_done(struct prp_priv *priv, struct ipuv3_channel *ch)
 		ipu_idmac_clear_buffer(ch, priv->ipu_buf_num);
 
 	if (priv->interweave_swap && ch == priv->out_ch)
-		phys += vdev->fmt.fmt.pix.bytesperline;
+		phys += vdev->fmt.bytesperline;
 
 	ipu_cpmem_set_buffer(ch, priv->ipu_buf_num, phys);
 }
@@ -362,7 +362,7 @@ static int prp_setup_channel(struct prp_priv *priv,
 	ipu_cpmem_zero(channel);
 
 	memset(&image, 0, sizeof(image));
-	image.pix = vdev->fmt.fmt.pix;
+	image.pix = vdev->fmt;
 	image.rect = vdev->compose;
 
 	/*
@@ -457,7 +457,7 @@ static int prp_setup_rotation(struct prp_priv *priv)
 	int ret;
 
 	infmt = &priv->format_mbus[PRPENCVF_SINK_PAD];
-	outfmt = &vdev->fmt.fmt.pix;
+	outfmt = &vdev->fmt;
 	incc = priv->cc[PRPENCVF_SINK_PAD];
 	outcc = vdev->cc;
 
@@ -586,7 +586,7 @@ static int prp_setup_norotation(struct prp_priv *priv)
 	int ret;
 
 	infmt = &priv->format_mbus[PRPENCVF_SINK_PAD];
-	outfmt = &vdev->fmt.fmt.pix;
+	outfmt = &vdev->fmt;
 	incc = priv->cc[PRPENCVF_SINK_PAD];
 	outcc = vdev->cc;
 
@@ -665,17 +665,14 @@ static int prp_start(struct prp_priv *priv)
 {
 	struct imx_ic_priv *ic_priv = priv->ic_priv;
 	struct imx_media_video_dev *vdev = priv->vdev;
-	struct v4l2_pix_format *outfmt;
 	int ret;
 
 	ret = prp_get_ipu_resources(priv);
 	if (ret)
 		return ret;
 
-	outfmt = &vdev->fmt.fmt.pix;
-
 	ret = imx_media_alloc_dma_buf(ic_priv->ipu_dev, &priv->underrun_buf,
-				      outfmt->sizeimage);
+				      vdev->fmt.sizeimage);
 	if (ret)
 		goto out_put_ipu;
 
diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index cd0ad2b32bbf..0d00eb1f1026 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -189,7 +189,7 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh,
 {
 	struct capture_priv *priv = video_drvdata(file);
 
-	*f = priv->vdev.fmt;
+	f->fmt.pix = priv->vdev.fmt;
 
 	return 0;
 }
@@ -294,7 +294,7 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	priv->vdev.fmt.fmt.pix = f->fmt.pix;
+	priv->vdev.fmt = f->fmt.pix;
 
 	return 0;
 }
@@ -343,8 +343,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.fmt.pix.width;
-		s->r.height = priv->vdev.fmt.fmt.pix.height;
+		s->r.width = priv->vdev.fmt.width;
+		s->r.height = priv->vdev.fmt.height;
 		break;
 	default:
 		return -EINVAL;
@@ -458,7 +458,7 @@ static int capture_queue_setup(struct vb2_queue *vq,
 			       struct device *alloc_devs[])
 {
 	struct capture_priv *priv = vb2_get_drv_priv(vq);
-	struct v4l2_pix_format *pix = &priv->vdev.fmt.fmt.pix;
+	struct v4l2_pix_format *pix = &priv->vdev.fmt;
 	unsigned int count = *nbuffers;
 
 	if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -497,7 +497,7 @@ 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.fmt.pix;
+	struct v4l2_pix_format *pix = &priv->vdev.fmt;
 
 	if (vb2_plane_size(vb, 0) < pix->sizeimage) {
 		dev_err(priv->dev,
@@ -544,8 +544,8 @@ static int capture_validate_fmt(struct capture_priv *priv)
 	if (ret)
 		return ret;
 
-	return (priv->vdev.fmt.fmt.pix.width != f.fmt.pix.width ||
-		priv->vdev.fmt.fmt.pix.height != f.fmt.pix.height ||
+	return (priv->vdev.fmt.width != f.fmt.pix.width ||
+		priv->vdev.fmt.height != f.fmt.pix.height ||
 		priv->vdev.cc->cs != cc->cs ||
 		priv->vdev.compose.width != compose.width ||
 		priv->vdev.compose.height != compose.height) ? -EINVAL : 0;
@@ -732,12 +732,10 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 		return ret;
 	}
 
-	vdev->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-	imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-				      &fmt_src.format, NULL);
+	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.fmt.pix.pixelformat,
+	vdev->cc = imx_media_find_pixel_format(vdev->fmt.pixelformat,
 					       PIXFMT_SEL_ANY);
 
 	/* Register the video device. */
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index b9d3f98a2c8f..c062fa481d76 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -267,7 +267,7 @@ static void csi_vb2_buf_done(struct csi_priv *priv)
 
 	done = priv->active_vb2_buf[priv->ipu_buf_num];
 	if (done) {
-		done->vbuf.field = vdev->fmt.fmt.pix.field;
+		done->vbuf.field = vdev->fmt.field;
 		done->vbuf.sequence = priv->frame_sequence;
 		vb = &done->vbuf.vb2_buf;
 		vb->timestamp = ktime_get_ns();
@@ -292,7 +292,7 @@ static void csi_vb2_buf_done(struct csi_priv *priv)
 		ipu_idmac_clear_buffer(priv->idmac_ch, priv->ipu_buf_num);
 
 	if (priv->interweave_swap)
-		phys += vdev->fmt.fmt.pix.bytesperline;
+		phys += vdev->fmt.bytesperline;
 
 	ipu_cpmem_set_buffer(priv->idmac_ch, priv->ipu_buf_num, phys);
 }
@@ -422,7 +422,7 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
 	ipu_cpmem_zero(priv->idmac_ch);
 
 	memset(&image, 0, sizeof(image));
-	image.pix = vdev->fmt.fmt.pix;
+	image.pix = vdev->fmt;
 	image.rect = vdev->compose;
 
 	csi_idmac_setup_vb2_buf(priv, phys);
@@ -596,7 +596,6 @@ static int csi_idmac_setup(struct csi_priv *priv)
 static int csi_idmac_start(struct csi_priv *priv)
 {
 	struct imx_media_video_dev *vdev = priv->vdev;
-	struct v4l2_pix_format *outfmt;
 	int ret;
 
 	ret = csi_idmac_get_ipu_resources(priv);
@@ -605,10 +604,8 @@ static int csi_idmac_start(struct csi_priv *priv)
 
 	ipu_smfc_map_channel(priv->smfc, priv->csi_id, priv->vc_num);
 
-	outfmt = &vdev->fmt.fmt.pix;
-
 	ret = imx_media_alloc_dma_buf(priv->dev, &priv->underrun_buf,
-				      outfmt->sizeimage);
+				      vdev->fmt.sizeimage);
 	if (ret)
 		goto out_put_ipu;
 
diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c
index 395b850736fa..abf290bda98d 100644
--- a/drivers/staging/media/imx/imx-media-vdic.c
+++ b/drivers/staging/media/imx/imx-media-vdic.c
@@ -246,7 +246,7 @@ static int setup_vdi_channel(struct vdic_priv *priv,
 	ipu_cpmem_zero(channel);
 
 	memset(&image, 0, sizeof(image));
-	image.pix = vdev->fmt.fmt.pix;
+	image.pix = vdev->fmt;
 	image.rect = vdev->compose;
 	/* one field to VDIC channels */
 	image.pix.height /= 2;
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index 085110eec87e..01a80eb4304a 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -105,7 +105,7 @@ struct imx_media_video_dev {
 	struct video_device *vfd;
 
 	/* the user format */
-	struct v4l2_format fmt;
+	struct v4l2_pix_format fmt;
 	/* the compose rectangle */
 	struct v4l2_rect compose;
 	const struct imx_media_pixfmt *cc;
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 3046f880c014..a93ff3d98613 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -596,7 +596,7 @@ static void imx7_csi_vb2_buf_done(struct imx7_csi *csi)
 
 	done = csi->active_vb2_buf[csi->buf_num];
 	if (done) {
-		done->vbuf.field = vdev->fmt.fmt.pix.field;
+		done->vbuf.field = vdev->fmt.field;
 		done->vbuf.sequence = csi->frame_sequence;
 		vb = &done->vbuf.vb2_buf;
 		vb->timestamp = ktime_get_ns();
@@ -678,11 +678,10 @@ static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
 static int imx7_csi_dma_start(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = csi->vdev;
-	struct v4l2_pix_format *out_pix = &vdev->fmt.fmt.pix;
 	int ret;
 
 	ret = imx_media_alloc_dma_buf(csi->dev, &csi->underrun_buf,
-				      out_pix->sizeimage);
+				      vdev->fmt.sizeimage);
 	if (ret < 0) {
 		v4l2_warn(&csi->sd, "consider increasing the CMA area\n");
 		return ret;
@@ -727,7 +726,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 static int imx7_csi_configure(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = csi->vdev;
-	struct v4l2_pix_format *out_pix = &vdev->fmt.fmt.pix;
+	struct v4l2_pix_format *out_pix = &vdev->fmt;
 	__u32 in_code = csi->format_mbus[IMX7_CSI_PAD_SINK].code;
 	u32 cr1, cr18;
 	int width = out_pix->width;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 17/77] media: imx: capture: Move default format init to a separate function
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (15 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 16/77] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 18/77] media: imx: capture: Rename querycap handler to capture_querycap Laurent Pinchart
                   ` (61 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

To prepare for more complex default format initialization and keep
imx_media_capture_device_register() simple, extract the format
initialization code to a separate function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 42 ++++++++++++-------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 0d00eb1f1026..4eb0f7b43f4a 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -709,13 +709,37 @@ void imx_media_capture_device_error(struct imx_media_video_dev *vdev)
 }
 EXPORT_SYMBOL_GPL(imx_media_capture_device_error);
 
+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;
+
+	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;
+	}
+
+	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;
+}
+
 int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 {
 	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;
-	struct v4l2_subdev_format fmt_src;
 	int ret;
 
 	/* get media device */
@@ -723,20 +747,10 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 
 	vfd->v4l2_dev = v4l2_dev;
 
-	/* setup default format */
-	fmt_src.pad = priv->src_sd_pad;
-	fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-	ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt_src);
-	if (ret) {
-		dev_err(priv->dev, "failed to get src_sd format\n");
+	/* Initialize the default format and compose rectangle. */
+	ret = capture_init_format(priv);
+	if (ret < 0)
 		return ret;
-	}
-
-	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);
 
 	/* Register the video device. */
 	ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1);
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 18/77] media: imx: capture: Rename querycap handler to capture_querycap
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (16 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 17/77] media: imx: capture: Move default format init to a separate function Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 19/77] media: imx: capture: Rename ioctl operations with legacy prefix Laurent Pinchart
                   ` (60 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

For consistency with all the other ioctl handlers, rename
vidioc_querycap() to capture_querycap().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 4eb0f7b43f4a..ed36c28a8b52 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -56,8 +56,8 @@ struct capture_priv {
  * Video ioctls follow
  */
 
-static int vidioc_querycap(struct file *file, void *fh,
-			   struct v4l2_capability *cap)
+static int capture_querycap(struct file *file, void *fh,
+			    struct v4l2_capability *cap)
 {
 	struct capture_priv *priv = video_drvdata(file);
 
@@ -414,7 +414,7 @@ static int capture_subscribe_event(struct v4l2_fh *fh,
 }
 
 static const struct v4l2_ioctl_ops capture_ioctl_ops = {
-	.vidioc_querycap	= vidioc_querycap,
+	.vidioc_querycap	= capture_querycap,
 
 	.vidioc_enum_framesizes = capture_enum_framesizes,
 	.vidioc_enum_frameintervals = capture_enum_frameintervals,
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 19/77] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (17 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 18/77] media: imx: capture: Rename querycap handler to capture_querycap Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 20/77] media: imx: capture: Add a mechanism to disable control inheritance Laurent Pinchart
                   ` (59 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The i.MX media drivers implement a legacy video node API, where the
format of the video node is influenced by the active format of the
connected subdev (both for enumeration and for the get, set and try
format ioctls), and where controls exposed by the subdevs in the
pipeline are inherited by the video node.

At the same time, the drivers implement the media controller API and
expose subdev video nodes to userspace. Those two modes of operation are
incompatible and should not be exposed together. Furthermore, the legacy
API gets in the way of proper enumeration of pixel formats on the video
node, as it prevents compliance with the V4L2 specification.

As a first step towards fixing this, rename all V4L2 video node ioctl
handlers with a legacy prefix. This will allow implementing a new set of
ioctls in parallel and gradually switching drivers. Add a task to the
TODO file for the removal of the legacy API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/TODO                |   9 +-
 drivers/staging/media/imx/imx-media-capture.c | 210 +++++++++---------
 2 files changed, 116 insertions(+), 103 deletions(-)

diff --git a/drivers/staging/media/imx/TODO b/drivers/staging/media/imx/TODO
index 9cfc1c1e78dc..2384f4c6b09d 100644
--- a/drivers/staging/media/imx/TODO
+++ b/drivers/staging/media/imx/TODO
@@ -17,9 +17,12 @@
 - This media driver supports inheriting V4L2 controls to the
   video capture devices, from the subdevices in the capture device's
   pipeline. The controls for each capture device are updated in the
-  link_notify callback when the pipeline is modified. It should be
-  decided whether this feature is useful enough to make it generally
-  available by exporting to v4l2-core.
+  link_notify callback when the pipeline is modified. This feature should be
+  removed, userspace should use the subdev-based userspace API instead.
+
+- Similarly to the legacy control handling, legacy format handling where
+  formats on the video nodes are influenced by the active format of the
+  connected subdev should be removed.
 
 - i.MX7: all of the above, since it uses the imx media core
 
diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index ed36c28a8b52..483198a5da96 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -52,8 +52,8 @@ struct capture_priv {
 /* In bytes, per queue */
 #define VID_MEM_LIMIT	SZ_64M
 
-/*
- * Video ioctls follow
+/* -----------------------------------------------------------------------------
+ * Common Video IOCTLs
  */
 
 static int capture_querycap(struct file *file, void *fh,
@@ -69,8 +69,52 @@ static int capture_querycap(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_enum_framesizes(struct file *file, void *fh,
-				   struct v4l2_frmsizeenum *fsize)
+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 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;
+}
+
+/* -----------------------------------------------------------------------------
+ * Legacy Video IOCTLs
+ */
+
+static int capture_legacy_enum_framesizes(struct file *file, void *fh,
+					  struct v4l2_frmsizeenum *fsize)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	const struct imx_media_pixfmt *cc;
@@ -109,8 +153,8 @@ static int capture_enum_framesizes(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_enum_frameintervals(struct file *file, void *fh,
-				       struct v4l2_frmivalenum *fival)
+static int capture_legacy_enum_frameintervals(struct file *file, void *fh,
+					      struct v4l2_frmivalenum *fival)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	const struct imx_media_pixfmt *cc;
@@ -140,8 +184,8 @@ static int capture_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
-				    struct v4l2_fmtdesc *f)
+static int capture_legacy_enum_fmt_vid_cap(struct file *file, void *fh,
+					   struct v4l2_fmtdesc *f)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	const struct imx_media_pixfmt *cc_src;
@@ -184,21 +228,11 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
 	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 int __capture_try_fmt_vid_cap(struct capture_priv *priv,
-				     struct v4l2_subdev_format *fmt_src,
-				     struct v4l2_format *f,
-				     const struct imx_media_pixfmt **retcc,
-				     struct v4l2_rect *compose)
+static int __capture_legacy_try_fmt(struct capture_priv *priv,
+				    struct v4l2_subdev_format *fmt_src,
+				    struct v4l2_format *f,
+				    const struct imx_media_pixfmt **retcc,
+				    struct v4l2_rect *compose)
 {
 	const struct imx_media_pixfmt *cc, *cc_src;
 
@@ -255,8 +289,8 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
 	return 0;
 }
 
-static int capture_try_fmt_vid_cap(struct file *file, void *fh,
-				   struct v4l2_format *f)
+static int capture_legacy_try_fmt_vid_cap(struct file *file, void *fh,
+					  struct v4l2_format *f)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	struct v4l2_subdev_format fmt_src;
@@ -268,11 +302,11 @@ static int capture_try_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	return __capture_try_fmt_vid_cap(priv, &fmt_src, f, NULL, NULL);
+	return __capture_legacy_try_fmt(priv, &fmt_src, f, NULL, NULL);
 }
 
-static int capture_s_fmt_vid_cap(struct file *file, void *fh,
-				 struct v4l2_format *f)
+static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
+					struct v4l2_format *f)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	struct v4l2_subdev_format fmt_src;
@@ -289,8 +323,8 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	ret = __capture_try_fmt_vid_cap(priv, &fmt_src, f, &priv->vdev.cc,
-					&priv->vdev.compose);
+	ret = __capture_legacy_try_fmt(priv, &fmt_src, f, &priv->vdev.cc,
+				       &priv->vdev.compose);
 	if (ret)
 		return ret;
 
@@ -299,21 +333,22 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_querystd(struct file *file, void *fh, v4l2_std_id *std)
+static int capture_legacy_querystd(struct file *file, void *fh,
+				   v4l2_std_id *std)
 {
 	struct capture_priv *priv = video_drvdata(file);
 
 	return v4l2_subdev_call(priv->src_sd, video, querystd, std);
 }
 
-static int capture_g_std(struct file *file, void *fh, v4l2_std_id *std)
+static int capture_legacy_g_std(struct file *file, void *fh, v4l2_std_id *std)
 {
 	struct capture_priv *priv = video_drvdata(file);
 
 	return v4l2_subdev_call(priv->src_sd, video, g_std, std);
 }
 
-static int capture_s_std(struct file *file, void *fh, v4l2_std_id std)
+static int capture_legacy_s_std(struct file *file, void *fh, v4l2_std_id std)
 {
 	struct capture_priv *priv = video_drvdata(file);
 
@@ -323,38 +358,8 @@ static int capture_s_std(struct file *file, void *fh, v4l2_std_id std)
 	return v4l2_subdev_call(priv->src_sd, video, s_std, std);
 }
 
-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_g_parm(struct file *file, void *fh,
-			  struct v4l2_streamparm *a)
+static int capture_legacy_g_parm(struct file *file, void *fh,
+				 struct v4l2_streamparm *a)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	struct v4l2_subdev_frame_interval fi;
@@ -375,8 +380,8 @@ static int capture_g_parm(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_s_parm(struct file *file, void *fh,
-			  struct v4l2_streamparm *a)
+static int capture_legacy_s_parm(struct file *file, void *fh,
+				 struct v4l2_streamparm *a)
 {
 	struct capture_priv *priv = video_drvdata(file);
 	struct v4l2_subdev_frame_interval fi;
@@ -398,8 +403,8 @@ static int capture_s_parm(struct file *file, void *fh,
 	return 0;
 }
 
-static int capture_subscribe_event(struct v4l2_fh *fh,
-				   const struct v4l2_event_subscription *sub)
+static int capture_legacy_subscribe_event(struct v4l2_fh *fh,
+					  const struct v4l2_event_subscription *sub)
 {
 	switch (sub->type) {
 	case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR:
@@ -413,42 +418,42 @@ 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 capture_legacy_ioctl_ops = {
+	.vidioc_querycap		= capture_querycap,
 
-	.vidioc_enum_framesizes = capture_enum_framesizes,
-	.vidioc_enum_frameintervals = capture_enum_frameintervals,
+	.vidioc_enum_framesizes		= capture_legacy_enum_framesizes,
+	.vidioc_enum_frameintervals	= capture_legacy_enum_frameintervals,
 
-	.vidioc_enum_fmt_vid_cap        = capture_enum_fmt_vid_cap,
-	.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_enum_fmt_vid_cap	= capture_legacy_enum_fmt_vid_cap,
+	.vidioc_g_fmt_vid_cap		= capture_g_fmt_vid_cap,
+	.vidioc_try_fmt_vid_cap		= capture_legacy_try_fmt_vid_cap,
+	.vidioc_s_fmt_vid_cap		= capture_legacy_s_fmt_vid_cap,
 
-	.vidioc_querystd        = capture_querystd,
-	.vidioc_g_std           = capture_g_std,
-	.vidioc_s_std           = capture_s_std,
+	.vidioc_querystd		= capture_legacy_querystd,
+	.vidioc_g_std			= capture_legacy_g_std,
+	.vidioc_s_std			= capture_legacy_s_std,
 
-	.vidioc_g_selection	= capture_g_selection,
+	.vidioc_g_selection		= capture_g_selection,
 
-	.vidioc_g_parm          = capture_g_parm,
-	.vidioc_s_parm          = capture_s_parm,
+	.vidioc_g_parm			= capture_legacy_g_parm,
+	.vidioc_s_parm			= capture_legacy_s_parm,
 
-	.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_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,
+	.vidioc_subscribe_event		= capture_legacy_subscribe_event,
+	.vidioc_unsubscribe_event	= v4l2_event_unsubscribe,
 };
 
-/*
- * Queue operations
+/* -----------------------------------------------------------------------------
+ * Queue Operations
  */
 
 static int capture_queue_setup(struct vb2_queue *vq,
@@ -540,7 +545,7 @@ static int capture_validate_fmt(struct capture_priv *priv)
 
 	v4l2_fill_pix_format(&f.fmt.pix, &fmt_src.format);
 
-	ret = __capture_try_fmt_vid_cap(priv, &fmt_src, &f, &cc, &compose);
+	ret = __capture_legacy_try_fmt(priv, &fmt_src, &f, &cc, &compose);
 	if (ret)
 		return ret;
 
@@ -616,9 +621,10 @@ static const struct vb2_ops capture_qops = {
 	.stop_streaming  = capture_stop_streaming,
 };
 
-/*
- * File operations
+/* -----------------------------------------------------------------------------
+ * File Operations
  */
+
 static int capture_open(struct file *file)
 {
 	struct capture_priv *priv = video_drvdata(file);
@@ -672,6 +678,10 @@ static const struct v4l2_file_operations capture_fops = {
 	.mmap		= vb2_fop_mmap,
 };
 
+/* -----------------------------------------------------------------------------
+ * Public API
+ */
+
 struct imx_media_buffer *
 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
 {
@@ -815,7 +825,7 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 		return ERR_PTR(-ENOMEM);
 
 	vfd->fops = &capture_fops;
-	vfd->ioctl_ops = &capture_ioctl_ops;
+	vfd->ioctl_ops = &capture_legacy_ioctl_ops;
 	vfd->minor = -1;
 	vfd->release = video_device_release;
 	vfd->vfl_dir = VFL_DIR_RX;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 20/77] media: imx: capture: Add a mechanism to disable control inheritance
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (18 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 19/77] media: imx: capture: Rename ioctl operations with legacy prefix Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 21/77] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt Laurent Pinchart
                   ` (58 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Add a parameter to the imx_media_capture_device_init() function to
select between the legacy and MC-centric API. When selecting the
MC-centric API, the video node doesn't inherit controls from subdevs
anymore. All callers are updated to use the legacy API for now,
preserving the existing behaviour.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-ic-prpencvf.c      |  2 +-
 drivers/staging/media/imx/imx-media-capture.c    | 13 +++++++++----
 drivers/staging/media/imx/imx-media-csi.c        |  5 ++---
 drivers/staging/media/imx/imx-media-dev-common.c |  4 ++++
 drivers/staging/media/imx/imx-media.h            |  2 +-
 drivers/staging/media/imx/imx7-media-csi.c       |  2 +-
 6 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c
index adb1a09e59d2..88d69425e1b3 100644
--- a/drivers/staging/media/imx/imx-ic-prpencvf.c
+++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
@@ -1265,7 +1265,7 @@ static int prp_registered(struct v4l2_subdev *sd)
 
 	priv->vdev = imx_media_capture_device_init(ic_priv->ipu_dev,
 						   &ic_priv->sd,
-						   PRPENCVF_SRC_PAD);
+						   PRPENCVF_SRC_PAD, true);
 	if (IS_ERR(priv->vdev))
 		return PTR_ERR(priv->vdev);
 
diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 483198a5da96..d782394f6cd1 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -45,6 +45,8 @@ 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)
@@ -800,7 +802,7 @@ EXPORT_SYMBOL_GPL(imx_media_capture_device_unregister);
 
 struct imx_media_video_dev *
 imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
-			      int pad)
+			      int pad, bool legacy_api)
 {
 	struct capture_priv *priv;
 	struct video_device *vfd;
@@ -814,6 +816,7 @@ imx_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);
@@ -868,9 +871,11 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 		return ERR_PTR(ret);
 	}
 
-	/* Initialize the control handler. */
-	v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
-	vfd->ctrl_handler = &priv->ctrl_hdlr;
+	if (legacy_api) {
+		/* Initialize the control handler. */
+		v4l2_ctrl_handler_init(&priv->ctrl_hdlr, 0);
+		vfd->ctrl_handler = &priv->ctrl_hdlr;
+	}
 
 	return &priv->vdev;
 }
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index c062fa481d76..45c92816facc 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1781,9 +1781,8 @@ static int csi_registered(struct v4l2_subdev *sd)
 		goto put_csi;
 	}
 
-	priv->vdev = imx_media_capture_device_init(priv->sd.dev,
-						   &priv->sd,
-						   CSI_SRC_PAD_IDMAC);
+	priv->vdev = imx_media_capture_device_init(priv->sd.dev, &priv->sd,
+						   CSI_SRC_PAD_IDMAC, true);
 	if (IS_ERR(priv->vdev)) {
 		ret = PTR_ERR(priv->vdev);
 		goto free_fim;
diff --git a/drivers/staging/media/imx/imx-media-dev-common.c b/drivers/staging/media/imx/imx-media-dev-common.c
index 5fe4b22ab847..d186179388d0 100644
--- a/drivers/staging/media/imx/imx-media-dev-common.c
+++ b/drivers/staging/media/imx/imx-media-dev-common.c
@@ -287,6 +287,8 @@ static int imx_media_link_notify(struct media_link *link, u32 flags,
 	    !(flags & MEDIA_LNK_FL_ENABLED)) {
 		list_for_each_entry(pad_vdev, pad_vdev_list, list) {
 			vfd = pad_vdev->vdev->vfd;
+			if (!vfd->ctrl_handler)
+				continue;
 			dev_dbg(imxmd->md.dev,
 				"reset controls for %s\n",
 				vfd->entity.name);
@@ -297,6 +299,8 @@ static int imx_media_link_notify(struct media_link *link, u32 flags,
 		   (link->flags & MEDIA_LNK_FL_ENABLED)) {
 		list_for_each_entry(pad_vdev, pad_vdev_list, list) {
 			vfd = pad_vdev->vdev->vfd;
+			if (!vfd->ctrl_handler)
+				continue;
 			dev_dbg(imxmd->md.dev,
 				"refresh controls for %s\n",
 				vfd->entity.name);
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index 01a80eb4304a..2ea2e62ddf86 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -286,7 +286,7 @@ int imx_media_ic_unregister(struct v4l2_subdev *sd);
 /* imx-media-capture.c */
 struct imx_media_video_dev *
 imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
-			      int pad);
+			      int pad, bool legacy_api);
 void imx_media_capture_device_remove(struct imx_media_video_dev *vdev);
 int imx_media_capture_device_register(struct imx_media_video_dev *vdev);
 void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev);
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index a93ff3d98613..a032d785746d 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1100,7 +1100,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	}
 
 	csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
-						  IMX7_CSI_PAD_SRC);
+						  IMX7_CSI_PAD_SRC, true);
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 21/77] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (19 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 20/77] media: imx: capture: Add a mechanism to disable control inheritance Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 22/77] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
                   ` (57 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The __capture_legacy_try_fmt() function doesn't need two
imx_media_pixfmt pointer variables. Remove one of them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 20 +++++++++----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index d782394f6cd1..1ef358eb3bd8 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -236,16 +236,16 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 				    const struct imx_media_pixfmt **retcc,
 				    struct v4l2_rect *compose)
 {
-	const struct imx_media_pixfmt *cc, *cc_src;
+	const struct imx_media_pixfmt *cc;
 
-	cc_src = imx_media_find_ipu_format(fmt_src->format.code,
-					   PIXFMT_SEL_YUV_RGB);
-	if (cc_src) {
+	cc = imx_media_find_ipu_format(fmt_src->format.code,
+				       PIXFMT_SEL_YUV_RGB);
+	if (cc) {
 		enum imx_pixfmt_sel fmt_sel;
 		u32 fourcc;
 
-		fmt_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
-			PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
+		fmt_sel = (cc->cs == IPUV3_COLORSPACE_YUV)
+			? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
 		fourcc = f->fmt.pix.pixelformat;
 
 		cc = imx_media_find_pixel_format(fourcc, fmt_sel);
@@ -254,12 +254,10 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 			cc = imx_media_find_pixel_format(fourcc, fmt_sel);
 		}
 	} else {
-		cc_src = imx_media_find_mbus_format(fmt_src->format.code,
-						    PIXFMT_SEL_ANY);
-		if (WARN_ON(!cc_src))
+		cc = imx_media_find_mbus_format(fmt_src->format.code,
+						PIXFMT_SEL_ANY);
+		if (WARN_ON(!cc))
 			return -EINVAL;
-
-		cc = cc_src;
 	}
 
 	/* allow IDMAC interweave but enforce field order from source */
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 22/77] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (20 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 21/77] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 23/77] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt() Laurent Pinchart
                   ` (56 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The __capture_legacy_try_fmt() function only needs the v4l2_pix_format
embedded in the v4l2_format argument it receives. Pass it the
v4l2_pix_format directly, allowing on caller to allocate a smaller
structure on the stack.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 25 ++++++++++---------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 1ef358eb3bd8..954f053497f9 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -232,7 +232,7 @@ static int capture_legacy_enum_fmt_vid_cap(struct file *file, void *fh,
 
 static int __capture_legacy_try_fmt(struct capture_priv *priv,
 				    struct v4l2_subdev_format *fmt_src,
-				    struct v4l2_format *f,
+				    struct v4l2_pix_format *pixfmt,
 				    const struct imx_media_pixfmt **retcc,
 				    struct v4l2_rect *compose)
 {
@@ -246,7 +246,7 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 
 		fmt_sel = (cc->cs == IPUV3_COLORSPACE_YUV)
 			? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
-		fourcc = f->fmt.pix.pixelformat;
+		fourcc = pixfmt->pixelformat;
 
 		cc = imx_media_find_pixel_format(fourcc, fmt_sel);
 		if (!cc) {
@@ -261,7 +261,7 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 	}
 
 	/* allow IDMAC interweave but enforce field order from source */
-	if (V4L2_FIELD_IS_INTERLACED(f->fmt.pix.field)) {
+	if (V4L2_FIELD_IS_INTERLACED(pixfmt->field)) {
 		switch (fmt_src->format.field) {
 		case V4L2_FIELD_SEQ_TB:
 			fmt_src->format.field = V4L2_FIELD_INTERLACED_TB;
@@ -274,7 +274,7 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 		}
 	}
 
-	imx_media_mbus_fmt_to_pix_fmt(&f->fmt.pix, &fmt_src->format, cc);
+	imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src->format, cc);
 
 	if (retcc)
 		*retcc = cc;
@@ -302,7 +302,8 @@ static int capture_legacy_try_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	return __capture_legacy_try_fmt(priv, &fmt_src, f, NULL, NULL);
+	return __capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix, NULL,
+					NULL);
 }
 
 static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
@@ -323,8 +324,8 @@ static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	ret = __capture_legacy_try_fmt(priv, &fmt_src, f, &priv->vdev.cc,
-				       &priv->vdev.compose);
+	ret = __capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix,
+				       &priv->vdev.cc, &priv->vdev.compose);
 	if (ret)
 		return ret;
 
@@ -534,7 +535,7 @@ static int capture_validate_fmt(struct capture_priv *priv)
 	struct v4l2_subdev_format fmt_src;
 	const struct imx_media_pixfmt *cc;
 	struct v4l2_rect compose;
-	struct v4l2_format f;
+	struct v4l2_pix_format pixfmt;
 	int ret;
 
 	fmt_src.pad = priv->src_sd_pad;
@@ -543,14 +544,14 @@ static int capture_validate_fmt(struct capture_priv *priv)
 	if (ret)
 		return ret;
 
-	v4l2_fill_pix_format(&f.fmt.pix, &fmt_src.format);
+	v4l2_fill_pix_format(&pixfmt, &fmt_src.format);
 
-	ret = __capture_legacy_try_fmt(priv, &fmt_src, &f, &cc, &compose);
+	ret = __capture_legacy_try_fmt(priv, &fmt_src, &pixfmt, &cc, &compose);
 	if (ret)
 		return ret;
 
-	return (priv->vdev.fmt.width != f.fmt.pix.width ||
-		priv->vdev.fmt.height != f.fmt.pix.height ||
+	return (priv->vdev.fmt.width != pixfmt.width ||
+		priv->vdev.fmt.height != pixfmt.height ||
 		priv->vdev.cc->cs != cc->cs ||
 		priv->vdev.compose.width != compose.width ||
 		priv->vdev.compose.height != compose.height) ? -EINVAL : 0;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 23/77] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (21 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 22/77] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 24/77] media: imx: capture: Extract format lookup from __capture_legacy_try_fmt Laurent Pinchart
                   ` (55 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The correct return code to report an invalid pipeline configuration is
-EPIPE. Return it instead of -EINVAL from __capture_legacy_try_fmt()
when the capture format doesn't match the media bus format of the
connected subdev.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 954f053497f9..43bf3ac9076a 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -554,7 +554,7 @@ static int capture_validate_fmt(struct capture_priv *priv)
 		priv->vdev.fmt.height != pixfmt.height ||
 		priv->vdev.cc->cs != cc->cs ||
 		priv->vdev.compose.width != compose.width ||
-		priv->vdev.compose.height != compose.height) ? -EINVAL : 0;
+		priv->vdev.compose.height != compose.height) ? -EPIPE : 0;
 }
 
 static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 24/77] media: imx: capture: Extract format lookup from __capture_legacy_try_fmt
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (22 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 23/77] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 25/77] media: imx: capture: Simplify capture_validate_fmt() implementation Laurent Pinchart
                   ` (54 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Extract the format lookup code from __capture_legacy_try_fmt() to a
separate function, it will be reused when validating the video node
format at stream start time.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 45 ++++++++++---------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 43bf3ac9076a..6350acd0dba9 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -58,6 +58,27 @@ struct capture_priv {
  * Common Video 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)
 {
@@ -238,27 +259,9 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 {
 	const struct imx_media_pixfmt *cc;
 
-	cc = imx_media_find_ipu_format(fmt_src->format.code,
-				       PIXFMT_SEL_YUV_RGB);
-	if (cc) {
-		enum imx_pixfmt_sel fmt_sel;
-		u32 fourcc;
-
-		fmt_sel = (cc->cs == IPUV3_COLORSPACE_YUV)
-			? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
-		fourcc = pixfmt->pixelformat;
-
-		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);
-		}
-	} else {
-		cc = imx_media_find_mbus_format(fmt_src->format.code,
-						PIXFMT_SEL_ANY);
-		if (WARN_ON(!cc))
-			return -EINVAL;
-	}
+	cc = capture_find_format(fmt_src->format.code, pixfmt->pixelformat);
+	if (WARN_ON(!cc))
+		return -EINVAL;
 
 	/* allow IDMAC interweave but enforce field order from source */
 	if (V4L2_FIELD_IS_INTERLACED(pixfmt->field)) {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 25/77] media: imx: capture: Simplify capture_validate_fmt() implementation
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (23 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 24/77] media: imx: capture: Extract format lookup from __capture_legacy_try_fmt Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 26/77] media: imx: capture: Simplify __capture_legacy_try_fmt() Laurent Pinchart
                   ` (53 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

capture_validate_fmt() delegates the media bus format to pixel format
conversion to __capture_legacy_try_fmt(). It turns out that this can be
simplified quite a lot:

- The format lookup from media bus code can be performed by the recently
  added capture_find_format() function instead of receiving the
  information from a side effect of __capture_legacy_try_fmt().

- The validation of the pixel format size isn't needed, as they
  duplicate the validation of the compose rectangle. The pixel format
  size is directly derived from the size of the incoming stream, which
  is stored in the compose rectangle. If the compose rectangle is valid,
  the pixel format size will be valid too.

By removing the validation of the pixel format size and using
capture_find_format() to lookup the format, we can stop using
__capture_legacy_try_fmt() and simplify capture_validate_fmt().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 30 ++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 6350acd0dba9..ed4e51b93dc5 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -537,27 +537,35 @@ static int capture_validate_fmt(struct capture_priv *priv)
 {
 	struct v4l2_subdev_format fmt_src;
 	const struct imx_media_pixfmt *cc;
-	struct v4l2_rect compose;
-	struct v4l2_pix_format pixfmt;
 	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;
 
-	v4l2_fill_pix_format(&pixfmt, &fmt_src.format);
+	/*
+	 * 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;
 
-	ret = __capture_legacy_try_fmt(priv, &fmt_src, &pixfmt, &cc, &compose);
-	if (ret)
-		return ret;
+	/*
+	 * 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 (priv->vdev.fmt.width != pixfmt.width ||
-		priv->vdev.fmt.height != pixfmt.height ||
-		priv->vdev.cc->cs != cc->cs ||
-		priv->vdev.compose.width != compose.width ||
-		priv->vdev.compose.height != compose.height) ? -EPIPE : 0;
+	return 0;
 }
 
 static int capture_start_streaming(struct vb2_queue *vq, unsigned int count)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 26/77] media: imx: capture: Simplify __capture_legacy_try_fmt()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (24 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 25/77] media: imx: capture: Simplify capture_validate_fmt() implementation Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 27/77] media: imx: capture: Decouple video node from source with MC-centric API Laurent Pinchart
                   ` (52 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The __capture_legacy_try_fmt() function returns two values through
pointer arguments. One is a compose rectangle, which duplicates
informationr returned through the subdev format argument, and can thus
be removed. The other is the imx_media_pixfmt, which can be returned
by value instead.

Simplify the implementation of __capture_legacy_try_fmt() by dropping
the retcc and compose arguments, and returning the imx_media_pixfmt by
value.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 40 ++++++++-----------
 1 file changed, 17 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index ed4e51b93dc5..700e99d02523 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -251,17 +251,16 @@ static int capture_legacy_enum_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
-static int __capture_legacy_try_fmt(struct capture_priv *priv,
-				    struct v4l2_subdev_format *fmt_src,
-				    struct v4l2_pix_format *pixfmt,
-				    const struct imx_media_pixfmt **retcc,
-				    struct v4l2_rect *compose)
+static const struct imx_media_pixfmt *
+__capture_legacy_try_fmt(struct capture_priv *priv,
+			 struct v4l2_subdev_format *fmt_src,
+			 struct v4l2_pix_format *pixfmt)
 {
 	const struct imx_media_pixfmt *cc;
 
 	cc = capture_find_format(fmt_src->format.code, pixfmt->pixelformat);
 	if (WARN_ON(!cc))
-		return -EINVAL;
+		return NULL;
 
 	/* allow IDMAC interweave but enforce field order from source */
 	if (V4L2_FIELD_IS_INTERLACED(pixfmt->field)) {
@@ -279,17 +278,7 @@ static int __capture_legacy_try_fmt(struct capture_priv *priv,
 
 	imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src->format, cc);
 
-	if (retcc)
-		*retcc = cc;
-
-	if (compose) {
-		compose->left = 0;
-		compose->top = 0;
-		compose->width = fmt_src->format.width;
-		compose->height = fmt_src->format.height;
-	}
-
-	return 0;
+	return cc;
 }
 
 static int capture_legacy_try_fmt_vid_cap(struct file *file, void *fh,
@@ -305,8 +294,10 @@ static int capture_legacy_try_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	return __capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix, NULL,
-					NULL);
+	if (!__capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix))
+		return -EINVAL;
+
+	return 0;
 }
 
 static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
@@ -314,6 +305,7 @@ static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
 {
 	struct capture_priv *priv = video_drvdata(file);
 	struct v4l2_subdev_format fmt_src;
+	const struct imx_media_pixfmt *cc;
 	int ret;
 
 	if (vb2_is_busy(&priv->q)) {
@@ -327,12 +319,14 @@ static int capture_legacy_s_fmt_vid_cap(struct file *file, void *fh,
 	if (ret)
 		return ret;
 
-	ret = __capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix,
-				       &priv->vdev.cc, &priv->vdev.compose);
-	if (ret)
-		return ret;
+	cc = __capture_legacy_try_fmt(priv, &fmt_src, &f->fmt.pix);
+	if (!cc)
+		return -EINVAL;
 
+	priv->vdev.cc = cc;
 	priv->vdev.fmt = f->fmt.pix;
+	priv->vdev.compose.width = fmt_src.format.width;
+	priv->vdev.compose.height = fmt_src.format.height;
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 27/77] media: imx: capture: Decouple video node from source with MC-centric API
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (25 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 26/77] media: imx: capture: Simplify __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 28/77] media: imx: capture: Expose V4L2_CAP_IO_MC for the " Laurent Pinchart
                   ` (51 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

When operating in MC-centric mode, the behaviour of video nodes shall
not be influenced by the active configuration of the source subdev. Add
a set of ioctl handlers that implement this mode, and select them when
support for the legacy API is not requested.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 161 +++++++++++++++++-
 1 file changed, 155 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 700e99d02523..99133b7ffa5f 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -55,7 +55,7 @@ struct capture_priv {
 #define VID_MEM_LIMIT	SZ_64M
 
 /* -----------------------------------------------------------------------------
- * Common Video IOCTLs
+ * MC-Centric Video IOCTLs
  */
 
 static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
@@ -92,6 +92,41 @@ static int capture_querycap(struct file *file, void *fh,
 	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, 0);
+}
+
+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)
 {
@@ -102,6 +137,75 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh,
 	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)
 {
@@ -132,6 +236,43 @@ 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)
+{
+	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,
+};
+
 /* -----------------------------------------------------------------------------
  * Legacy Video IOCTLs
  */
@@ -734,10 +875,17 @@ static int capture_init_format(struct capture_priv *priv)
 	struct imx_media_video_dev *vdev = &priv->vdev;
 	int ret;
 
-	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;
+	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);
@@ -832,7 +980,8 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 		return ERR_PTR(-ENOMEM);
 
 	vfd->fops = &capture_fops;
-	vfd->ioctl_ops = &capture_legacy_ioctl_ops;
+	vfd->ioctl_ops = legacy_api ? &capture_legacy_ioctl_ops
+		       : &capture_ioctl_ops;
 	vfd->minor = -1;
 	vfd->release = video_device_release;
 	vfd->vfl_dir = VFL_DIR_RX;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 28/77] media: imx: capture: Expose V4L2_CAP_IO_MC for the MC-centric API
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (26 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 27/77] media: imx: capture: Decouple video node from source with MC-centric API Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 29/77] media: imx: imx7-media-csi: Disable legacy video node API Laurent Pinchart
                   ` (50 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Report to userspace that the MC-centric API is MC-centric by exposing
the V4L2_CAP_IO_MC. This requires adding support for mbus code filtering
in format enumeration, as required by V4L2_CAP_IO_MC.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx-media-capture.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 99133b7ffa5f..c4360866f7f6 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -96,7 +96,7 @@ 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, 0);
+					    PIXFMT_SEL_ANY, f->mbus_code);
 }
 
 static int capture_enum_framesizes(struct file *file, void *fh,
@@ -986,7 +986,8 @@ imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 	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;
+	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;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 29/77] media: imx: imx7-media-csi: Disable legacy video node API
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (27 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 28/77] media: imx: capture: Expose V4L2_CAP_IO_MC for the " Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 30/77] media: imx: capture: Support creating immutable link to capture device Laurent Pinchart
                   ` (49 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Support for the MC-centric API has been tested on the i.MX7. Enable it
for that platform. i.MX6 should be converted next.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index a032d785746d..3bf2505de6a2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1100,7 +1100,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	}
 
 	csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
-						  IMX7_CSI_PAD_SRC, true);
+						  IMX7_CSI_PAD_SRC, false);
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 30/77] media: imx: capture: Support creating immutable link to capture device
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (28 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 29/77] media: imx: imx7-media-csi: Disable legacy video node API Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 31/77] media: imx: imx7-media-csi: Remove control handler Laurent Pinchart
                   ` (48 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

When the subdevice connected to the capture device has a single possible
sink, there's no point in making the link mutable. Support creating
immutable links.

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

- Pass link flags to imx_media_capture_device_register()
---
 drivers/staging/media/imx/imx-ic-prpencvf.c   | 2 +-
 drivers/staging/media/imx/imx-media-capture.c | 7 +++++--
 drivers/staging/media/imx/imx-media-csi.c     | 2 +-
 drivers/staging/media/imx/imx-media.h         | 3 ++-
 drivers/staging/media/imx/imx7-media-csi.c    | 2 +-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c
index 88d69425e1b3..d990553de87b 100644
--- a/drivers/staging/media/imx/imx-ic-prpencvf.c
+++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
@@ -1269,7 +1269,7 @@ static int prp_registered(struct v4l2_subdev *sd)
 	if (IS_ERR(priv->vdev))
 		return PTR_ERR(priv->vdev);
 
-	ret = imx_media_capture_device_register(priv->vdev);
+	ret = imx_media_capture_device_register(priv->vdev, 0);
 	if (ret)
 		goto remove_vdev;
 
diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index c4360866f7f6..93ba09236010 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -898,7 +898,8 @@ static int capture_init_format(struct capture_priv *priv)
 	return 0;
 }
 
-int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
+int imx_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;
@@ -927,8 +928,10 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
 		 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, 0);
+				    &vfd->entity, 0, link_flags);
 	if (ret) {
 		dev_err(priv->dev, "failed to create link to device node\n");
 		video_unregister_device(vfd);
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 45c92816facc..8d02939aaa23 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1788,7 +1788,7 @@ static int csi_registered(struct v4l2_subdev *sd)
 		goto free_fim;
 	}
 
-	ret = imx_media_capture_device_register(priv->vdev);
+	ret = imx_media_capture_device_register(priv->vdev, 0);
 	if (ret)
 		goto remove_vdev;
 
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index 2ea2e62ddf86..492d9a64e704 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -288,7 +288,8 @@ struct imx_media_video_dev *
 imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
 			      int pad, bool legacy_api);
 void imx_media_capture_device_remove(struct imx_media_video_dev *vdev);
-int imx_media_capture_device_register(struct imx_media_video_dev *vdev);
+int imx_media_capture_device_register(struct imx_media_video_dev *vdev,
+				      u32 link_flags);
 void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev);
 struct imx_media_buffer *
 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev);
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 3bf2505de6a2..90cf4b889e23 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1104,7 +1104,7 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-	ret = imx_media_capture_device_register(csi->vdev);
+	ret = imx_media_capture_device_register(csi->vdev, 0);
 	if (ret)
 		imx_media_capture_device_remove(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 31/77] media: imx: imx7-media-csi: Remove control handler
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (29 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 30/77] media: imx: capture: Support creating immutable link to capture device Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 32/77] media: imx: imx7-media-csi: Move (de)init from link setup to .s_stream() Laurent Pinchart
                   ` (47 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The control handler isn't used, drop it.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 90cf4b889e23..c64c5196939b 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -18,7 +18,6 @@
 #include <linux/regmap.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>
@@ -173,8 +172,6 @@ struct imx7_csi {
 	const struct imx_media_pixfmt *cc[IMX7_CSI_PADS_NUM];
 	struct v4l2_fract frame_interval[IMX7_CSI_PADS_NUM];
 
-	struct v4l2_ctrl_handler ctrl_hdlr;
-
 	void __iomem *regbase;
 	int irq;
 	struct clk *mclk;
@@ -476,8 +473,6 @@ static int imx7_csi_link_setup(struct media_entity *entity,
 		}
 		csi->sink = remote->entity;
 	} else {
-		v4l2_ctrl_handler_free(&csi->ctrl_hdlr);
-		v4l2_ctrl_handler_init(&csi->ctrl_hdlr, 0);
 		csi->sink = NULL;
 	}
 
@@ -1289,9 +1284,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	csi->sd.grp_id = IMX_MEDIA_GRP_ID_CSI;
 	snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
 
-	v4l2_ctrl_handler_init(&csi->ctrl_hdlr, 0);
-	csi->sd.ctrl_handler = &csi->ctrl_hdlr;
-
 	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;
@@ -1299,7 +1291,7 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	ret = media_entity_pads_init(&csi->sd.entity, IMX7_CSI_PADS_NUM,
 				     csi->pad);
 	if (ret < 0)
-		goto free;
+		goto cleanup;
 
 	ret = imx7_csi_async_register(csi);
 	if (ret)
@@ -1311,9 +1303,6 @@ static int imx7_csi_probe(struct platform_device *pdev)
 	v4l2_async_notifier_unregister(&csi->notifier);
 	v4l2_async_notifier_cleanup(&csi->notifier);
 
-free:
-	v4l2_ctrl_handler_free(&csi->ctrl_hdlr);
-
 cleanup:
 	v4l2_async_notifier_unregister(&imxmd->notifier);
 	v4l2_async_notifier_cleanup(&imxmd->notifier);
@@ -1343,7 +1332,6 @@ static int imx7_csi_remove(struct platform_device *pdev)
 	v4l2_async_notifier_unregister(&csi->notifier);
 	v4l2_async_notifier_cleanup(&csi->notifier);
 	v4l2_async_unregister_subdev(sd);
-	v4l2_ctrl_handler_free(&csi->ctrl_hdlr);
 
 	mutex_destroy(&csi->lock);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 32/77] media: imx: imx7-media-csi: Move (de)init from link setup to .s_stream()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (30 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 31/77] media: imx: imx7-media-csi: Remove control handler Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 33/77] media: imx: imx7-media-csi: Create immutable link to capture device Laurent Pinchart
                   ` (46 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

There's no need to initialize the CSI every time a link is enabled (and
de-initialize it when a link is disabled). Move initialization to
.s_stream() instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 30 ++++++++--------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index c64c5196939b..bc3324a30824 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -184,7 +184,6 @@ struct imx7_csi {
 	u32 frame_sequence;
 
 	bool last_eof;
-	bool is_init;
 	bool is_streaming;
 	bool is_csi2;
 
@@ -402,9 +401,6 @@ static int imx7_csi_init(struct imx7_csi *csi)
 {
 	int ret;
 
-	if (csi->is_init)
-		return 0;
-
 	ret = clk_prepare_enable(csi->mclk);
 	if (ret < 0)
 		return ret;
@@ -412,22 +408,15 @@ static int imx7_csi_init(struct imx7_csi *csi)
 	imx7_csi_init_interface(csi);
 	imx7_csi_dmareq_rff_enable(csi);
 
-	csi->is_init = true;
-
 	return 0;
 }
 
 static void imx7_csi_deinit(struct imx7_csi *csi)
 {
-	if (!csi->is_init)
-		return;
-
 	imx7_csi_hw_reset(csi);
 	imx7_csi_init_interface(csi);
 	imx7_csi_dmareq_rff_disable(csi);
 	clk_disable_unprepare(csi->mclk);
-
-	csi->is_init = false;
 }
 
 static int imx7_csi_link_setup(struct media_entity *entity,
@@ -462,7 +451,7 @@ static int imx7_csi_link_setup(struct media_entity *entity,
 			csi->src_sd = NULL;
 		}
 
-		goto init;
+		goto unlock;
 	}
 
 	/* source pad */
@@ -476,12 +465,6 @@ static int imx7_csi_link_setup(struct media_entity *entity,
 		csi->sink = NULL;
 	}
 
-init:
-	if (csi->sink || csi->src_sd)
-		ret = imx7_csi_init(csi);
-	else
-		imx7_csi_deinit(csi);
-
 unlock:
 	mutex_unlock(&csi->lock);
 
@@ -868,19 +851,28 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 		goto out_unlock;
 
 	if (enable) {
+		ret = imx7_csi_init(csi);
+		if (ret < 0)
+			goto out_unlock;
+
 		ret = v4l2_subdev_call(csi->src_sd, video, s_stream, 1);
-		if (ret < 0)
+		if (ret < 0) {
+			imx7_csi_deinit(csi);
 			goto out_unlock;
+		}
 
 		ret = imx7_csi_streaming_start(csi);
 		if (ret < 0) {
 			v4l2_subdev_call(csi->src_sd, video, s_stream, 0);
+			imx7_csi_deinit(csi);
 			goto out_unlock;
 		}
 	} else {
 		imx7_csi_streaming_stop(csi);
 
 		v4l2_subdev_call(csi->src_sd, video, s_stream, 0);
+
+		imx7_csi_deinit(csi);
 	}
 
 	csi->is_streaming = !!enable;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 33/77] media: imx: imx7-media-csi: Create immutable link to capture device
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (31 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 32/77] media: imx: imx7-media-csi: Move (de)init from link setup to .s_stream() Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 34/77] media: imx: imx7-media-csi: Replace CSICR*_RESET_VAL with values Laurent Pinchart
                   ` (45 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The i.MX7 camera pipeline is simple, with the CSI connected directly to
the capture device without any other option. There's thus no need to
allow link configurable by userspace. Make it immutable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index bc3324a30824..174e608ededa 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -166,8 +166,6 @@ struct imx7_csi {
 
 	struct v4l2_subdev *src_sd;
 
-	struct media_entity *sink;
-
 	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];
@@ -450,19 +448,6 @@ static int imx7_csi_link_setup(struct media_entity *entity,
 		} else {
 			csi->src_sd = NULL;
 		}
-
-		goto unlock;
-	}
-
-	/* source pad */
-	if (flags & MEDIA_LNK_FL_ENABLED) {
-		if (csi->sink) {
-			ret = -EBUSY;
-			goto unlock;
-		}
-		csi->sink = remote->entity;
-	} else {
-		csi->sink = NULL;
 	}
 
 unlock:
@@ -842,7 +827,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&csi->lock);
 
-	if (!csi->src_sd || !csi->sink) {
+	if (!csi->src_sd) {
 		ret = -EPIPE;
 		goto out_unlock;
 	}
@@ -1091,7 +1076,8 @@ static int imx7_csi_registered(struct v4l2_subdev *sd)
 	if (IS_ERR(csi->vdev))
 		return PTR_ERR(csi->vdev);
 
-	ret = imx_media_capture_device_register(csi->vdev, 0);
+	ret = imx_media_capture_device_register(csi->vdev,
+						MEDIA_LNK_FL_IMMUTABLE);
 	if (ret)
 		imx_media_capture_device_remove(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 34/77] media: imx: imx7-media-csi: Replace CSICR*_RESET_VAL with values
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (32 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 33/77] media: imx: imx7-media-csi: Create immutable link to capture device Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:26 ` [PATCH v2 35/77] media: imx: imx7-media-csi: Tidy up register fields macros Laurent Pinchart
                   ` (44 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The CSICR*_RESET_VAL macros only obfuscate code. Use their value
directly, replacing the numerical value with the macros that describe
register bits.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 174e608ededa..072047e059ef 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -32,11 +32,6 @@
 #define IMX7_CSI_PAD_SRC	1
 #define IMX7_CSI_PADS_NUM	2
 
-/* reset values */
-#define CSICR1_RESET_VAL	0x40000800
-#define CSICR2_RESET_VAL	0x0
-#define CSICR3_RESET_VAL	0x0
-
 /* csi control reg 1 */
 #define BIT_SWAP16_EN		BIT(31)
 #define BIT_EXT_VSYNC		BIT(30)
@@ -211,9 +206,9 @@ static void imx7_csi_hw_reset(struct imx7_csi *csi)
 			   imx7_csi_reg_read(csi, CSI_CSICR3) | BIT_FRMCNT_RST,
 			   CSI_CSICR3);
 
-	imx7_csi_reg_write(csi, CSICR1_RESET_VAL, CSI_CSICR1);
-	imx7_csi_reg_write(csi, CSICR2_RESET_VAL, CSI_CSICR2);
-	imx7_csi_reg_write(csi, CSICR3_RESET_VAL, CSI_CSICR3);
+	imx7_csi_reg_write(csi, BIT_EXT_VSYNC | BIT_HSYNC_POL, CSI_CSICR1);
+	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
+	imx7_csi_reg_write(csi, 0, CSI_CSICR3);
 }
 
 static u32 imx7_csi_irq_clear(struct imx7_csi *csi)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 35/77] media: imx: imx7-media-csi: Tidy up register fields macros
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (33 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 34/77] media: imx: imx7-media-csi: Replace CSICR*_RESET_VAL with values Laurent Pinchart
@ 2021-02-15  4:26 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 36/77] media: imx: imx7-media-csi: Reorganize code in sections Laurent Pinchart
                   ` (43 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:26 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Describe multi-bit fields with parameterized macros where applicable,
and use them to replace manual shifts and hardcoded numerical values.
Add macros for the CSICR2 fields used in the driver.

While at it, align the indentation for all macros, and use lower-case
hex numbers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 196 +++++++++++----------
 1 file changed, 102 insertions(+), 94 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 072047e059ef..a5971b958b64 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -28,79 +28,88 @@
 #include <media/imx.h>
 #include "imx-media.h"
 
-#define IMX7_CSI_PAD_SINK	0
-#define IMX7_CSI_PAD_SRC	1
-#define IMX7_CSI_PADS_NUM	2
+#define IMX7_CSI_PAD_SINK		0
+#define IMX7_CSI_PAD_SRC		1
+#define IMX7_CSI_PADS_NUM		2
 
 /* csi control reg 1 */
-#define BIT_SWAP16_EN		BIT(31)
-#define BIT_EXT_VSYNC		BIT(30)
-#define BIT_EOF_INT_EN		BIT(29)
-#define BIT_PRP_IF_EN		BIT(28)
-#define BIT_CCIR_MODE		BIT(27)
-#define BIT_COF_INT_EN		BIT(26)
-#define BIT_SF_OR_INTEN		BIT(25)
-#define BIT_RF_OR_INTEN		BIT(24)
-#define BIT_SFF_DMA_DONE_INTEN  BIT(22)
-#define BIT_STATFF_INTEN	BIT(21)
-#define BIT_FB2_DMA_DONE_INTEN  BIT(20)
-#define BIT_FB1_DMA_DONE_INTEN  BIT(19)
-#define BIT_RXFF_INTEN		BIT(18)
-#define BIT_SOF_POL		BIT(17)
-#define BIT_SOF_INTEN		BIT(16)
-#define BIT_MCLKDIV		(0xF << 12)
-#define BIT_HSYNC_POL		BIT(11)
-#define BIT_CCIR_EN		BIT(10)
-#define BIT_MCLKEN		BIT(9)
-#define BIT_FCC			BIT(8)
-#define BIT_PACK_DIR		BIT(7)
-#define BIT_CLR_STATFIFO	BIT(6)
-#define BIT_CLR_RXFIFO		BIT(5)
-#define BIT_GCLK_MODE		BIT(4)
-#define BIT_INV_DATA		BIT(3)
-#define BIT_INV_PCLK		BIT(2)
-#define BIT_REDGE		BIT(1)
-#define BIT_PIXEL_BIT		BIT(0)
+#define BIT_SWAP16_EN			BIT(31)
+#define BIT_EXT_VSYNC			BIT(30)
+#define BIT_EOF_INT_EN			BIT(29)
+#define BIT_PRP_IF_EN			BIT(28)
+#define BIT_CCIR_MODE			BIT(27)
+#define BIT_COF_INT_EN			BIT(26)
+#define BIT_SF_OR_INTEN			BIT(25)
+#define BIT_RF_OR_INTEN			BIT(24)
+#define BIT_SFF_DMA_DONE_INTEN		BIT(22)
+#define BIT_STATFF_INTEN		BIT(21)
+#define BIT_FB2_DMA_DONE_INTEN		BIT(20)
+#define BIT_FB1_DMA_DONE_INTEN		BIT(19)
+#define BIT_RXFF_INTEN			BIT(18)
+#define BIT_SOF_POL			BIT(17)
+#define BIT_SOF_INTEN			BIT(16)
+#define BIT_MCLKDIV(n)			((n) << 12)
+#define BIT_MCLKDIV_MASK		(0xf << 12)
+#define BIT_HSYNC_POL			BIT(11)
+#define BIT_CCIR_EN			BIT(10)
+#define BIT_MCLKEN			BIT(9)
+#define BIT_FCC				BIT(8)
+#define BIT_PACK_DIR			BIT(7)
+#define BIT_CLR_STATFIFO		BIT(6)
+#define BIT_CLR_RXFIFO			BIT(5)
+#define BIT_GCLK_MODE			BIT(4)
+#define BIT_INV_DATA			BIT(3)
+#define BIT_INV_PCLK			BIT(2)
+#define BIT_REDGE			BIT(1)
+#define BIT_PIXEL_BIT			BIT(0)
 
-#define SHIFT_MCLKDIV		12
+/* control reg 2 */
+#define BIT_DMA_BURST_TYPE_RFF_INCR4	(1 << 30)
+#define BIT_DMA_BURST_TYPE_RFF_INCR8	(2 << 30)
+#define BIT_DMA_BURST_TYPE_RFF_INCR16	(3 << 30)
+#define BIT_DMA_BURST_TYPE_RFF_MASK	(3 << 30)
 
 /* control reg 3 */
-#define BIT_FRMCNT		(0xFFFF << 16)
-#define BIT_FRMCNT_RST		BIT(15)
-#define BIT_DMA_REFLASH_RFF	BIT(14)
-#define BIT_DMA_REFLASH_SFF	BIT(13)
-#define BIT_DMA_REQ_EN_RFF	BIT(12)
-#define BIT_DMA_REQ_EN_SFF	BIT(11)
-#define BIT_STATFF_LEVEL	(0x7 << 8)
-#define BIT_HRESP_ERR_EN	BIT(7)
-#define BIT_RXFF_LEVEL		(0x7 << 4)
-#define BIT_TWO_8BIT_SENSOR	BIT(3)
-#define BIT_ZERO_PACK_EN	BIT(2)
-#define BIT_ECC_INT_EN		BIT(1)
-#define BIT_ECC_AUTO_EN		BIT(0)
-
-#define SHIFT_FRMCNT		16
-#define SHIFT_RXFIFO_LEVEL	4
+#define BIT_FRMCNT(n)			((n) << 16)
+#define BIT_FRMCNT_MASK			(0xffff << 16)
+#define BIT_FRMCNT_RST			BIT(15)
+#define BIT_DMA_REFLASH_RFF		BIT(14)
+#define BIT_DMA_REFLASH_SFF		BIT(13)
+#define BIT_DMA_REQ_EN_RFF		BIT(12)
+#define BIT_DMA_REQ_EN_SFF		BIT(11)
+#define BIT_STATFF_LEVEL(n)		((n) << 8)
+#define BIT_STATFF_LEVEL_MASK		(0x7 << 8)
+#define BIT_HRESP_ERR_EN		BIT(7)
+#define BIT_RXFF_LEVEL(n)		((n) << 4)
+#define BIT_RXFF_LEVEL_MASK		(0x7 << 4)
+#define BIT_TWO_8BIT_SENSOR		BIT(3)
+#define BIT_ZERO_PACK_EN		BIT(2)
+#define BIT_ECC_INT_EN			BIT(1)
+#define BIT_ECC_AUTO_EN			BIT(0)
 
 /* csi status reg */
-#define BIT_ADDR_CH_ERR_INT	BIT(28)
-#define BIT_FIELD0_INT		BIT(27)
-#define BIT_FIELD1_INT		BIT(26)
-#define BIT_SFF_OR_INT		BIT(25)
-#define BIT_RFF_OR_INT		BIT(24)
-#define BIT_DMA_TSF_DONE_SFF	BIT(22)
-#define BIT_STATFF_INT		BIT(21)
-#define BIT_DMA_TSF_DONE_FB2	BIT(20)
-#define BIT_DMA_TSF_DONE_FB1	BIT(19)
-#define BIT_RXFF_INT		BIT(18)
-#define BIT_EOF_INT		BIT(17)
-#define BIT_SOF_INT		BIT(16)
-#define BIT_F2_INT		BIT(15)
-#define BIT_F1_INT		BIT(14)
-#define BIT_COF_INT		BIT(13)
-#define BIT_HRESP_ERR_INT	BIT(7)
-#define BIT_ECC_INT		BIT(1)
-#define BIT_DRDY		BIT(0)
+#define BIT_ADDR_CH_ERR_INT		BIT(28)
+#define BIT_FIELD0_INT			BIT(27)
+#define BIT_FIELD1_INT			BIT(26)
+#define BIT_SFF_OR_INT			BIT(25)
+#define BIT_RFF_OR_INT			BIT(24)
+#define BIT_DMA_TSF_DONE_SFF		BIT(22)
+#define BIT_STATFF_INT			BIT(21)
+#define BIT_DMA_TSF_DONE_FB2		BIT(20)
+#define BIT_DMA_TSF_DONE_FB1		BIT(19)
+#define BIT_RXFF_INT			BIT(18)
+#define BIT_EOF_INT			BIT(17)
+#define BIT_SOF_INT			BIT(16)
+#define BIT_F2_INT			BIT(15)
+#define BIT_F1_INT			BIT(14)
+#define BIT_COF_INT			BIT(13)
+#define BIT_HRESP_ERR_INT		BIT(7)
+#define BIT_ECC_INT			BIT(1)
+#define BIT_DRDY			BIT(0)
+
+/* csi image parameter reg */
+#define BIT_IMAGE_WIDTH(n)		((n) << 16)
+#define BIT_IMAGE_HEIGHT(n)		(n)
 
 /* csi control reg 18 */
 #define BIT_CSI_HW_ENABLE		BIT(31)
@@ -109,8 +118,7 @@
 #define BIT_MIPI_DATA_FORMAT_RAW12	(0x2c << 25)
 #define BIT_MIPI_DATA_FORMAT_RAW14	(0x2d << 25)
 #define BIT_MIPI_DATA_FORMAT_YUV422_8B	(0x1e << 25)
-#define BIT_MIPI_DATA_FORMAT_MASK	(0x3F << 25)
-#define BIT_MIPI_DATA_FORMAT_OFFSET	25
+#define BIT_MIPI_DATA_FORMAT_MASK	(0x3f << 25)
 #define BIT_DATA_FROM_MIPI		BIT(22)
 #define BIT_MIPI_YU_SWAP		BIT(21)
 #define BIT_MIPI_DOUBLE_CMPNT		BIT(20)
@@ -122,29 +130,29 @@
 #define BIT_TVDECODER_IN_EN		BIT(1)
 #define BIT_NTSC_EN			BIT(0)
 
-#define CSI_MCLK_VF		1
-#define CSI_MCLK_ENC		2
-#define CSI_MCLK_RAW		4
-#define CSI_MCLK_I2C		8
+#define CSI_MCLK_VF			1
+#define CSI_MCLK_ENC			2
+#define CSI_MCLK_RAW			4
+#define CSI_MCLK_I2C			8
 
-#define CSI_CSICR1		0x0
-#define CSI_CSICR2		0x4
-#define CSI_CSICR3		0x8
-#define CSI_STATFIFO		0xC
-#define CSI_CSIRXFIFO		0x10
-#define CSI_CSIRXCNT		0x14
-#define CSI_CSISR		0x18
+#define CSI_CSICR1			0x00
+#define CSI_CSICR2			0x04
+#define CSI_CSICR3			0x08
+#define CSI_STATFIFO			0x0c
+#define CSI_CSIRXFIFO			0x10
+#define CSI_CSIRXCNT			0x14
+#define CSI_CSISR			0x18
 
-#define CSI_CSIDBG		0x1C
-#define CSI_CSIDMASA_STATFIFO	0x20
-#define CSI_CSIDMATS_STATFIFO	0x24
-#define CSI_CSIDMASA_FB1	0x28
-#define CSI_CSIDMASA_FB2	0x2C
-#define CSI_CSIFBUF_PARA	0x30
-#define CSI_CSIIMAG_PARA	0x34
+#define CSI_CSIDBG			0x1c
+#define CSI_CSIDMASA_STATFIFO		0x20
+#define CSI_CSIDMATS_STATFIFO		0x24
+#define CSI_CSIDMASA_FB1		0x28
+#define CSI_CSIDMASA_FB2		0x2c
+#define CSI_CSIFBUF_PARA		0x30
+#define CSI_CSIIMAG_PARA		0x34
 
-#define CSI_CSICR18		0x48
-#define CSI_CSICR19		0x4c
+#define CSI_CSICR18			0x48
+#define CSI_CSICR19			0x4c
 
 struct imx7_csi {
 	struct device *dev;
@@ -227,10 +235,10 @@ static void imx7_csi_init_interface(struct imx7_csi *csi)
 	unsigned int imag_para;
 
 	val = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL |
-		BIT_FCC | 1 << SHIFT_MCLKDIV | BIT_MCLKEN;
+		BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
 	imx7_csi_reg_write(csi, val, CSI_CSICR1);
 
-	imag_para = (800 << 16) | 600;
+	imag_para = BIT_IMAGE_WIDTH(800) | BIT_IMAGE_HEIGHT(600);
 	imx7_csi_reg_write(csi, imag_para, CSI_CSIIMAG_PARA);
 
 	val = BIT_DMA_REFLASH_RFF;
@@ -329,12 +337,12 @@ static void imx7_csi_dmareq_rff_enable(struct imx7_csi *csi)
 	u32 cr2 = imx7_csi_reg_read(csi, CSI_CSICR2);
 
 	/* Burst Type of DMA Transfer from RxFIFO. INCR16 */
-	cr2 |= 0xC0000000;
+	cr2 |= BIT_DMA_BURST_TYPE_RFF_INCR16;
 
 	cr3 |= BIT_DMA_REQ_EN_RFF;
 	cr3 |= BIT_HRESP_ERR_EN;
-	cr3 &= ~BIT_RXFF_LEVEL;
-	cr3 |= 0x2 << 4;
+	cr3 &= ~BIT_RXFF_LEVEL_MASK;
+	cr3 |= BIT_RXFF_LEVEL(2);
 
 	imx7_csi_reg_write(csi, cr3, CSI_CSICR3);
 	imx7_csi_reg_write(csi, cr2, CSI_CSICR2);
@@ -357,7 +365,7 @@ static void imx7_csi_set_imagpara(struct imx7_csi *csi, int width, int height)
 	rx_count = (width * height) >> 2;
 	imx7_csi_reg_write(csi, rx_count, CSI_CSIRXCNT);
 
-	imag_para = (width << 16) | height;
+	imag_para = BIT_IMAGE_WIDTH(width) | BIT_IMAGE_HEIGHT(height);
 	imx7_csi_reg_write(csi, imag_para, CSI_CSIIMAG_PARA);
 
 	/* reflash the embedded DMA controller */
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 36/77] media: imx: imx7-media-csi: Reorganize code in sections
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (34 preceding siblings ...)
  2021-02-15  4:26 ` [PATCH v2 35/77] media: imx: imx7-media-csi: Tidy up register fields macros Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 37/77] media: imx: imx7-media-csi: Validate capture format in .link_validate() Laurent Pinchart
                   ` (42 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

To prepare for a major rework of the hardware initialization, and make
the code easier to read, reorder functions to group them in sections. No
functional change is included.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 496 +++++++++++----------
 1 file changed, 258 insertions(+), 238 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index a5971b958b64..158b235476eb 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -197,6 +197,10 @@ imx7_csi_notifier_to_dev(struct v4l2_async_notifier *n)
 	return container_of(n, struct imx7_csi, notifier);
 }
 
+/* -----------------------------------------------------------------------------
+ * Hardware Configuration
+ */
+
 static u32 imx7_csi_reg_read(struct imx7_csi *csi, unsigned int offset)
 {
 	return readl(csi->regbase + offset);
@@ -387,122 +391,6 @@ static void imx7_csi_sw_reset(struct imx7_csi *csi)
 	imx7_csi_hw_enable(csi);
 }
 
-static void imx7_csi_error_recovery(struct imx7_csi *csi)
-{
-	imx7_csi_hw_disable(csi);
-
-	imx7_csi_rx_fifo_clear(csi);
-
-	imx7_csi_dma_reflash(csi);
-
-	imx7_csi_hw_enable(csi);
-}
-
-static int imx7_csi_init(struct imx7_csi *csi)
-{
-	int ret;
-
-	ret = clk_prepare_enable(csi->mclk);
-	if (ret < 0)
-		return ret;
-	imx7_csi_hw_reset(csi);
-	imx7_csi_init_interface(csi);
-	imx7_csi_dmareq_rff_enable(csi);
-
-	return 0;
-}
-
-static void imx7_csi_deinit(struct imx7_csi *csi)
-{
-	imx7_csi_hw_reset(csi);
-	imx7_csi_init_interface(csi);
-	imx7_csi_dmareq_rff_disable(csi);
-	clk_disable_unprepare(csi->mclk);
-}
-
-static int imx7_csi_link_setup(struct media_entity *entity,
-			       const struct media_pad *local,
-			       const struct media_pad *remote, u32 flags)
-{
-	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
-	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct v4l2_subdev *remote_sd;
-	int ret = 0;
-
-	dev_dbg(csi->dev, "link setup %s -> %s\n", remote->entity->name,
-		local->entity->name);
-
-	mutex_lock(&csi->lock);
-
-	if (local->flags & MEDIA_PAD_FL_SINK) {
-		if (!is_media_entity_v4l2_subdev(remote->entity)) {
-			ret = -EINVAL;
-			goto unlock;
-		}
-
-		remote_sd = media_entity_to_v4l2_subdev(remote->entity);
-
-		if (flags & MEDIA_LNK_FL_ENABLED) {
-			if (csi->src_sd) {
-				ret = -EBUSY;
-				goto unlock;
-			}
-			csi->src_sd = remote_sd;
-		} else {
-			csi->src_sd = NULL;
-		}
-	}
-
-unlock:
-	mutex_unlock(&csi->lock);
-
-	return ret;
-}
-
-static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
-				      struct media_link *link,
-				      struct v4l2_subdev_format *source_fmt,
-				      struct v4l2_subdev_format *sink_fmt)
-{
-	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct media_entity *src;
-	struct media_pad *pad;
-	int ret;
-
-	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
-	if (ret)
-		return ret;
-
-	if (!csi->src_sd)
-		return -EPIPE;
-
-	src = &csi->src_sd->entity;
-
-	/*
-	 * if the source is neither a CSI MUX or CSI-2 get the one directly
-	 * upstream from this CSI
-	 */
-	if (src->function != MEDIA_ENT_F_VID_IF_BRIDGE &&
-	    src->function != MEDIA_ENT_F_VID_MUX)
-		src = &csi->sd.entity;
-
-	/*
-	 * find the entity that is selected by the source. This is needed
-	 * to distinguish between a parallel or CSI-2 pipeline.
-	 */
-	pad = imx_media_pipeline_pad(src, 0, 0, true);
-	if (!pad)
-		return -ENODEV;
-
-	mutex_lock(&csi->lock);
-
-	csi->is_csi2 = (pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE);
-
-	mutex_unlock(&csi->lock);
-
-	return 0;
-}
-
 static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 				int buf_num)
 {
@@ -553,94 +441,6 @@ static void imx7_csi_dma_unsetup_vb2_buf(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 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.sequence = csi->frame_sequence;
-		vb = &done->vbuf.vb2_buf;
-		vb->timestamp = ktime_get_ns();
-		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
-	}
-	csi->frame_sequence++;
-
-	/* get next queued buffer */
-	next = imx_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;
-	} else {
-		phys = csi->underrun_buf.phys;
-		csi->active_vb2_buf[csi->buf_num] = NULL;
-	}
-
-	imx7_csi_update_buf(csi, phys, csi->buf_num);
-}
-
-static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
-{
-	struct imx7_csi *csi =  data;
-	u32 status;
-
-	spin_lock(&csi->irqlock);
-
-	status = imx7_csi_irq_clear(csi);
-
-	if (status & BIT_RFF_OR_INT) {
-		dev_warn(csi->dev, "Rx fifo overflow\n");
-		imx7_csi_error_recovery(csi);
-	}
-
-	if (status & BIT_HRESP_ERR_INT) {
-		dev_warn(csi->dev, "Hresponse error detected\n");
-		imx7_csi_error_recovery(csi);
-	}
-
-	if (status & BIT_ADDR_CH_ERR_INT) {
-		imx7_csi_hw_disable(csi);
-
-		imx7_csi_dma_reflash(csi);
-
-		imx7_csi_hw_enable(csi);
-	}
-
-	if ((status & BIT_DMA_TSF_DONE_FB1) &&
-	    (status & BIT_DMA_TSF_DONE_FB2)) {
-		/*
-		 * For both FB1 and FB2 interrupter bits set case,
-		 * CSI DMA is work in one of FB1 and FB2 buffer,
-		 * but software can not know the state.
-		 * Skip it to avoid base address updated
-		 * when csi work in field0 and field1 will write to
-		 * new base address.
-		 */
-	} else if (status & BIT_DMA_TSF_DONE_FB1) {
-		csi->buf_num = 0;
-	} else if (status & BIT_DMA_TSF_DONE_FB2) {
-		csi->buf_num = 1;
-	}
-
-	if ((status & BIT_DMA_TSF_DONE_FB1) ||
-	    (status & BIT_DMA_TSF_DONE_FB2)) {
-		imx7_csi_vb2_buf_done(csi);
-
-		if (csi->last_eof) {
-			complete(&csi->last_eof_completion);
-			csi->last_eof = false;
-		}
-	}
-
-	spin_unlock(&csi->irqlock);
-
-	return IRQ_HANDLED;
-}
-
 static int imx7_csi_dma_start(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = csi->vdev;
@@ -772,6 +572,28 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 	return 0;
 }
 
+static int imx7_csi_init(struct imx7_csi *csi)
+{
+	int ret;
+
+	ret = clk_prepare_enable(csi->mclk);
+	if (ret < 0)
+		return ret;
+	imx7_csi_hw_reset(csi);
+	imx7_csi_init_interface(csi);
+	imx7_csi_dmareq_rff_enable(csi);
+
+	return 0;
+}
+
+static void imx7_csi_deinit(struct imx7_csi *csi)
+{
+	imx7_csi_hw_reset(csi);
+	imx7_csi_init_interface(csi);
+	imx7_csi_dmareq_rff_disable(csi);
+	clk_disable_unprepare(csi->mclk);
+}
+
 static void imx7_csi_enable(struct imx7_csi *csi)
 {
 	imx7_csi_sw_reset(csi);
@@ -823,6 +645,113 @@ static int imx7_csi_streaming_stop(struct imx7_csi *csi)
 	return 0;
 }
 
+/* -----------------------------------------------------------------------------
+ * Interrupt Handling
+ */
+
+static void imx7_csi_error_recovery(struct imx7_csi *csi)
+{
+	imx7_csi_hw_disable(csi);
+
+	imx7_csi_rx_fifo_clear(csi);
+
+	imx7_csi_dma_reflash(csi);
+
+	imx7_csi_hw_enable(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 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.sequence = csi->frame_sequence;
+		vb = &done->vbuf.vb2_buf;
+		vb->timestamp = ktime_get_ns();
+		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+	}
+	csi->frame_sequence++;
+
+	/* get next queued buffer */
+	next = imx_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;
+	} else {
+		phys = csi->underrun_buf.phys;
+		csi->active_vb2_buf[csi->buf_num] = NULL;
+	}
+
+	imx7_csi_update_buf(csi, phys, csi->buf_num);
+}
+
+static irqreturn_t imx7_csi_irq_handler(int irq, void *data)
+{
+	struct imx7_csi *csi =  data;
+	u32 status;
+
+	spin_lock(&csi->irqlock);
+
+	status = imx7_csi_irq_clear(csi);
+
+	if (status & BIT_RFF_OR_INT) {
+		dev_warn(csi->dev, "Rx fifo overflow\n");
+		imx7_csi_error_recovery(csi);
+	}
+
+	if (status & BIT_HRESP_ERR_INT) {
+		dev_warn(csi->dev, "Hresponse error detected\n");
+		imx7_csi_error_recovery(csi);
+	}
+
+	if (status & BIT_ADDR_CH_ERR_INT) {
+		imx7_csi_hw_disable(csi);
+
+		imx7_csi_dma_reflash(csi);
+
+		imx7_csi_hw_enable(csi);
+	}
+
+	if ((status & BIT_DMA_TSF_DONE_FB1) &&
+	    (status & BIT_DMA_TSF_DONE_FB2)) {
+		/*
+		 * For both FB1 and FB2 interrupter bits set case,
+		 * CSI DMA is work in one of FB1 and FB2 buffer,
+		 * but software can not know the state.
+		 * Skip it to avoid base address updated
+		 * when csi work in field0 and field1 will write to
+		 * new base address.
+		 */
+	} else if (status & BIT_DMA_TSF_DONE_FB1) {
+		csi->buf_num = 0;
+	} else if (status & BIT_DMA_TSF_DONE_FB2) {
+		csi->buf_num = 1;
+	}
+
+	if ((status & BIT_DMA_TSF_DONE_FB1) ||
+	    (status & BIT_DMA_TSF_DONE_FB2)) {
+		imx7_csi_vb2_buf_done(csi);
+
+		if (csi->last_eof) {
+			complete(&csi->last_eof_completion);
+			csi->last_eof = false;
+		}
+	}
+
+	spin_unlock(&csi->irqlock);
+
+	return IRQ_HANDLED;
+}
+
+/* -----------------------------------------------------------------------------
+ * V4L2 Subdev Operations
+ */
+
 static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
@@ -871,6 +800,26 @@ 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_pad_config *cfg)
+{
+	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, cfg, 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_pad_config *cfg,
@@ -1055,6 +1004,50 @@ static int imx7_csi_set_fmt(struct v4l2_subdev *sd,
 	return ret;
 }
 
+static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
+				      struct media_link *link,
+				      struct v4l2_subdev_format *source_fmt,
+				      struct v4l2_subdev_format *sink_fmt)
+{
+	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
+	struct media_entity *src;
+	struct media_pad *pad;
+	int ret;
+
+	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
+	if (ret)
+		return ret;
+
+	if (!csi->src_sd)
+		return -EPIPE;
+
+	src = &csi->src_sd->entity;
+
+	/*
+	 * if the source is neither a CSI MUX or CSI-2 get the one directly
+	 * upstream from this CSI
+	 */
+	if (src->function != MEDIA_ENT_F_VID_IF_BRIDGE &&
+	    src->function != MEDIA_ENT_F_VID_MUX)
+		src = &csi->sd.entity;
+
+	/*
+	 * find the entity that is selected by the source. This is needed
+	 * to distinguish between a parallel or CSI-2 pipeline.
+	 */
+	pad = imx_media_pipeline_pad(src, 0, 0, true);
+	if (!pad)
+		return -ENODEV;
+
+	mutex_lock(&csi->lock);
+
+	csi->is_csi2 = (pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE);
+
+	mutex_unlock(&csi->lock);
+
+	return 0;
+}
+
 static int imx7_csi_registered(struct v4l2_subdev *sd)
 {
 	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
@@ -1095,47 +1088,21 @@ static void imx7_csi_unregistered(struct v4l2_subdev *sd)
 	imx_media_capture_device_remove(csi->vdev);
 }
 
-static int imx7_csi_init_cfg(struct v4l2_subdev *sd,
-			     struct v4l2_subdev_pad_config *cfg)
-{
-	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, cfg, 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 const struct media_entity_operations imx7_csi_entity_ops = {
-	.link_setup	= imx7_csi_link_setup,
-	.link_validate	= v4l2_subdev_link_validate,
-	.get_fwnode_pad = v4l2_subdev_get_fwnode_pad_1_to_1,
-};
-
 static const struct v4l2_subdev_video_ops imx7_csi_video_ops = {
-	.s_stream		= imx7_csi_s_stream,
+	.s_stream	= imx7_csi_s_stream,
 };
 
 static const struct v4l2_subdev_pad_ops imx7_csi_pad_ops = {
-	.init_cfg =		imx7_csi_init_cfg,
-	.enum_mbus_code =	imx7_csi_enum_mbus_code,
-	.get_fmt =		imx7_csi_get_fmt,
-	.set_fmt =		imx7_csi_set_fmt,
-	.link_validate =	imx7_csi_pad_link_validate,
+	.init_cfg	= imx7_csi_init_cfg,
+	.enum_mbus_code	= imx7_csi_enum_mbus_code,
+	.get_fmt	= imx7_csi_get_fmt,
+	.set_fmt	= imx7_csi_set_fmt,
+	.link_validate	= imx7_csi_pad_link_validate,
 };
 
 static const struct v4l2_subdev_ops imx7_csi_subdev_ops = {
-	.video =	&imx7_csi_video_ops,
-	.pad =		&imx7_csi_pad_ops,
+	.video		= &imx7_csi_video_ops,
+	.pad		= &imx7_csi_pad_ops,
 };
 
 static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = {
@@ -1143,6 +1110,59 @@ static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = {
 	.unregistered	= imx7_csi_unregistered,
 };
 
+/* -----------------------------------------------------------------------------
+ * Media Entity Operations
+ */
+
+static int imx7_csi_link_setup(struct media_entity *entity,
+			       const struct media_pad *local,
+			       const struct media_pad *remote, u32 flags)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
+	struct v4l2_subdev *remote_sd;
+	int ret = 0;
+
+	dev_dbg(csi->dev, "link setup %s -> %s\n", remote->entity->name,
+		local->entity->name);
+
+	mutex_lock(&csi->lock);
+
+	if (local->flags & MEDIA_PAD_FL_SINK) {
+		if (!is_media_entity_v4l2_subdev(remote->entity)) {
+			ret = -EINVAL;
+			goto unlock;
+		}
+
+		remote_sd = media_entity_to_v4l2_subdev(remote->entity);
+
+		if (flags & MEDIA_LNK_FL_ENABLED) {
+			if (csi->src_sd) {
+				ret = -EBUSY;
+				goto unlock;
+			}
+			csi->src_sd = remote_sd;
+		} else {
+			csi->src_sd = NULL;
+		}
+	}
+
+unlock:
+	mutex_unlock(&csi->lock);
+
+	return ret;
+}
+
+static const struct media_entity_operations imx7_csi_entity_ops = {
+	.link_setup	= imx7_csi_link_setup,
+	.link_validate	= v4l2_subdev_link_validate,
+	.get_fwnode_pad = v4l2_subdev_get_fwnode_pad_1_to_1,
+};
+
+/* -----------------------------------------------------------------------------
+ * Probe & Remove
+ */
+
 static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 				 struct v4l2_subdev *sd,
 				 struct v4l2_async_subdev *asd)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 37/77] media: imx: imx7-media-csi: Validate capture format in .link_validate()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (35 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 36/77] media: imx: imx7-media-csi: Reorganize code in sections Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification Laurent Pinchart
                   ` (41 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Move capture format validation from imx7_csi_configure() to
.link_validate(). This simplifies error handling at stream on time, as
imx7_csi_configure) now becomes a void function.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 158b235476eb..de7b93317a47 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -489,7 +489,7 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 	imx_media_free_dma_buf(csi->dev, &csi->underrun_buf);
 }
 
-static int imx7_csi_configure(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;
@@ -518,7 +518,7 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 			BIT_BASEADDR_CHG_ERR_EN);
 		imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
 
-		return 0;
+		return;
 	}
 
 	imx7_csi_set_imagpara(csi, width, out_pix->height);
@@ -562,14 +562,10 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 			cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
 		cr1 |= BIT_PIXEL_BIT;
 		break;
-	default:
-		return -EINVAL;
 	}
 
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
 	imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
-
-	return 0;
 }
 
 static int imx7_csi_init(struct imx7_csi *csi)
@@ -622,18 +618,10 @@ static int imx7_csi_streaming_start(struct imx7_csi *csi)
 	if (ret < 0)
 		return ret;
 
-	ret = imx7_csi_configure(csi);
-	if (ret < 0)
-		goto dma_stop;
-
+	imx7_csi_configure(csi);
 	imx7_csi_enable(csi);
 
 	return 0;
-
-dma_stop:
-	imx7_csi_dma_stop(csi);
-
-	return ret;
 }
 
 static int imx7_csi_streaming_stop(struct imx7_csi *csi)
@@ -1010,10 +998,16 @@ 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;
 	struct media_entity *src;
 	struct media_pad *pad;
 	int ret;
 
+	/*
+	 * Validate the source link, and record whether the CSI mux selects the
+	 * parallel input or the CSI-2 receiver.
+	 */
 	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
 	if (ret)
 		return ret;
@@ -1031,10 +1025,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	    src->function != MEDIA_ENT_F_VID_MUX)
 		src = &csi->sd.entity;
 
-	/*
-	 * find the entity that is selected by the source. This is needed
-	 * to distinguish between a parallel or CSI-2 pipeline.
-	 */
 	pad = imx_media_pipeline_pad(src, 0, 0, true);
 	if (!pad)
 		return -ENODEV;
@@ -1045,6 +1035,23 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 
 	mutex_unlock(&csi->lock);
 
+	/* 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_SBGGR8:
+	case V4L2_PIX_FMT_SBGGR16:
+		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] 100+ messages in thread

* [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (36 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 37/77] media: imx: imx7-media-csi: Validate capture format in .link_validate() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01  9:30   ` Rui Miguel Silva
  2021-02-15  4:27 ` [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2 Laurent Pinchart
                   ` (40 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The code in imx7_csi_pad_link_validate() that checks the type of the
source incorrectly handles devices that have no parallel input. In that
case, the source entity of the CSI is the CSI-2 receiver, not the video
mux, and the driver will proceed to check the type of the source of the
CSI-2 receiver.

Make the code more explicit to fix this, by handling the three cases
(parallel input only, CSI-2 receiver only, and video mux) separately.

Note that the driver will not correctly handle the case where only a
parallel input is present, and the external entity connected to the
parallel input reports a MEDIA_ENT_F_VID_IF_BRIDGE or
MEDIA_ENT_F_VID_MUX function. This was broken already, and should be
fixed separately.

Fixes: f168e796bf40 ("media: imx7: csi: Fix pad link validation")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 52 +++++++++++++---------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index de7b93317a47..2a4b69cc0178 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1000,39 +1000,47 @@ 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_entity *src;
 	struct media_pad *pad;
+	bool is_csi2;
 	int ret;
 
-	/*
-	 * Validate the source link, and record whether the CSI mux selects the
-	 * parallel input or the CSI-2 receiver.
-	 */
-	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
-	if (ret)
-		return ret;
-
 	if (!csi->src_sd)
 		return -EPIPE;
 
-	src = &csi->src_sd->entity;
-
 	/*
-	 * if the source is neither a CSI MUX or CSI-2 get the one directly
-	 * upstream from this CSI
+	 * Validate the source link, and record whether the source uses the
+	 * parallel input or the CSI-2 receiver.
 	 */
-	if (src->function != MEDIA_ENT_F_VID_IF_BRIDGE &&
-	    src->function != MEDIA_ENT_F_VID_MUX)
-		src = &csi->sd.entity;
+	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
+	if (ret)
+		return ret;
 
-	pad = imx_media_pipeline_pad(src, 0, 0, true);
-	if (!pad)
-		return -ENODEV;
+	switch (csi->src_sd->entity.function) {
+	case MEDIA_ENT_F_VID_IF_BRIDGE:
+		/* The input is the CSI-2 receiver. */
+		is_csi2 = true;
+		break;
+
+	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);
+		if (!pad)
+			return -ENODEV;
+
+		is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
+		break;
+
+	default:
+		/*
+		 * The input is an external entity, it must use the parallel
+		 * bus.
+		 */
+		is_csi2 = false;
+		break;
+	}
 
 	mutex_lock(&csi->lock);
-
-	csi->is_csi2 = (pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE);
-
+	csi->is_csi2 = is_csi2;
 	mutex_unlock(&csi->lock);
 
 	/* Validate the sink link, ensure the pixel format is supported. */
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (37 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01  9:31   ` Rui Miguel Silva
  2021-02-15  4:27 ` [PATCH v2 40/77] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup() Laurent Pinchart
                   ` (39 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The is_csi2 field can't be accessed concurrently by
imx7_csi_pad_link_validate() and imx7_csi_configure(), as the latter is
called from imx7_csi_s_stream(), which is called after link validation.
Drop the lock.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 2a4b69cc0178..dc25b593eaeb 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1001,7 +1001,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	struct imx_media_video_dev *vdev = csi->vdev;
 	const struct v4l2_pix_format *out_pix = &vdev->fmt;
 	struct media_pad *pad;
-	bool is_csi2;
 	int ret;
 
 	if (!csi->src_sd)
@@ -1018,7 +1017,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	switch (csi->src_sd->entity.function) {
 	case MEDIA_ENT_F_VID_IF_BRIDGE:
 		/* The input is the CSI-2 receiver. */
-		is_csi2 = true;
+		csi->is_csi2 = true;
 		break;
 
 	case MEDIA_ENT_F_VID_MUX:
@@ -1027,7 +1026,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 		if (!pad)
 			return -ENODEV;
 
-		is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
+		csi->is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
 		break;
 
 	default:
@@ -1035,14 +1034,10 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 		 * The input is an external entity, it must use the parallel
 		 * bus.
 		 */
-		is_csi2 = false;
+		csi->is_csi2 = false;
 		break;
 	}
 
-	mutex_lock(&csi->lock);
-	csi->is_csi2 = is_csi2;
-	mutex_unlock(&csi->lock);
-
 	/* Validate the sink link, ensure the pixel format is supported. */
 	switch (out_pix->pixelformat) {
 	case V4L2_PIX_FMT_UYVY:
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 40/77] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (38 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2 Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 41/77] media: imx: imx7-media-csi: Split imx7_csi_dma_stop() Laurent Pinchart
                   ` (38 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx7_csi_dma_start() doesn't start DMA. Rename it to
imx7_csi_dma_setup() to avoid confusion.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index dc25b593eaeb..af4119dc8fd6 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -441,7 +441,7 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi,
 	}
 }
 
-static int imx7_csi_dma_start(struct imx7_csi *csi)
+static int imx7_csi_dma_setup(struct imx7_csi *csi)
 {
 	struct imx_media_video_dev *vdev = csi->vdev;
 	int ret;
@@ -614,7 +614,7 @@ static int imx7_csi_streaming_start(struct imx7_csi *csi)
 {
 	int ret;
 
-	ret = imx7_csi_dma_start(csi);
+	ret = imx7_csi_dma_setup(csi);
 	if (ret < 0)
 		return ret;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 41/77] media: imx: imx7-media-csi: Split imx7_csi_dma_stop()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (39 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 40/77] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 42/77] media: imx: imx7-media-csi: Move CSI configuration before source start Laurent Pinchart
                   ` (37 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx7_csi_dma_stop() function performs two operations, it waits for
DMA to be complete, and then cleans up and frees buffers. Split the
second part out to a new imx7_csi_dma_cleanup() function to match
imx7_csi_dma_setup(), in preparation for a stream start refactoring.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index af4119dc8fd6..9cb04fa31b5a 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -462,6 +462,12 @@ static int imx7_csi_dma_setup(struct imx7_csi *csi)
 	return 0;
 }
 
+static void imx7_csi_dma_cleanup(struct imx7_csi *csi)
+{
+	imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR);
+	imx_media_free_dma_buf(csi->dev, &csi->underrun_buf);
+}
+
 static void imx7_csi_dma_stop(struct imx7_csi *csi)
 {
 	unsigned long timeout_jiffies;
@@ -483,10 +489,6 @@ static void imx7_csi_dma_stop(struct imx7_csi *csi)
 		v4l2_warn(&csi->sd, "wait last EOF timeout\n");
 
 	imx7_csi_hw_disable_irq(csi);
-
-	imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR);
-
-	imx_media_free_dma_buf(csi->dev, &csi->underrun_buf);
 }
 
 static void imx7_csi_configure(struct imx7_csi *csi)
@@ -627,6 +629,7 @@ static int imx7_csi_streaming_start(struct imx7_csi *csi)
 static int imx7_csi_streaming_stop(struct imx7_csi *csi)
 {
 	imx7_csi_dma_stop(csi);
+	imx7_csi_dma_cleanup(csi);
 
 	imx7_csi_disable(csi);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 42/77] media: imx: imx7-media-csi: Move CSI configuration before source start
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (40 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 41/77] media: imx: imx7-media-csi: Split imx7_csi_dma_stop() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 43/77] media: imx: imx7-media-csi: Merge streaming_start() with csi_enable() Laurent Pinchart
                   ` (36 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

There's no reason to delay the CSI configuration and the DMA setup after
starting the source. Move it before, simplifying error handling at
stream start.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 9cb04fa31b5a..f6a26dff8541 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -577,15 +577,23 @@ static int imx7_csi_init(struct imx7_csi *csi)
 	ret = clk_prepare_enable(csi->mclk);
 	if (ret < 0)
 		return ret;
+
 	imx7_csi_hw_reset(csi);
 	imx7_csi_init_interface(csi);
 	imx7_csi_dmareq_rff_enable(csi);
 
+	ret = imx7_csi_dma_setup(csi);
+	if (ret < 0)
+		return ret;
+
+	imx7_csi_configure(csi);
+
 	return 0;
 }
 
 static void imx7_csi_deinit(struct imx7_csi *csi)
 {
+	imx7_csi_dma_cleanup(csi);
 	imx7_csi_hw_reset(csi);
 	imx7_csi_init_interface(csi);
 	imx7_csi_dmareq_rff_disable(csi);
@@ -612,24 +620,14 @@ static void imx7_csi_disable(struct imx7_csi *csi)
 	imx7_csi_hw_disable(csi);
 }
 
-static int imx7_csi_streaming_start(struct imx7_csi *csi)
+static void imx7_csi_streaming_start(struct imx7_csi *csi)
 {
-	int ret;
-
-	ret = imx7_csi_dma_setup(csi);
-	if (ret < 0)
-		return ret;
-
-	imx7_csi_configure(csi);
 	imx7_csi_enable(csi);
-
-	return 0;
 }
 
 static int imx7_csi_streaming_stop(struct imx7_csi *csi)
 {
 	imx7_csi_dma_stop(csi);
-	imx7_csi_dma_cleanup(csi);
 
 	imx7_csi_disable(csi);
 
@@ -769,12 +767,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 			goto out_unlock;
 		}
 
-		ret = imx7_csi_streaming_start(csi);
-		if (ret < 0) {
-			v4l2_subdev_call(csi->src_sd, video, s_stream, 0);
-			imx7_csi_deinit(csi);
-			goto out_unlock;
-		}
+		imx7_csi_streaming_start(csi);
 	} else {
 		imx7_csi_streaming_stop(csi);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 43/77] media: imx: imx7-media-csi: Merge streaming_start() with csi_enable()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (41 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 42/77] media: imx: imx7-media-csi: Move CSI configuration before source start Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 44/77] media: imx: imx7-media-csi: Merge hw_reset() with init_interface() Laurent Pinchart
                   ` (35 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx7_csi_streaming_start() function just wraps imx7_csi_enable().
Call the latter directly.

Similarly, merge imx7_csi_streaming_stop() and imx7_csi_disable() as
they're both called from a single location only.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 28 +++++++---------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index f6a26dff8541..53bab0a0a878 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -610,28 +610,16 @@ static void imx7_csi_enable(struct imx7_csi *csi)
 }
 
 static void imx7_csi_disable(struct imx7_csi *csi)
-{
-	imx7_csi_dmareq_rff_disable(csi);
-
-	imx7_csi_hw_disable_irq(csi);
-
-	imx7_csi_buf_stride_set(csi, 0);
-
-	imx7_csi_hw_disable(csi);
-}
-
-static void imx7_csi_streaming_start(struct imx7_csi *csi)
-{
-	imx7_csi_enable(csi);
-}
-
-static int imx7_csi_streaming_stop(struct imx7_csi *csi)
 {
 	imx7_csi_dma_stop(csi);
 
-	imx7_csi_disable(csi);
+	imx7_csi_dmareq_rff_disable(csi);
 
-	return 0;
+	imx7_csi_hw_disable_irq(csi);
+
+	imx7_csi_buf_stride_set(csi, 0);
+
+	imx7_csi_hw_disable(csi);
 }
 
 /* -----------------------------------------------------------------------------
@@ -767,9 +755,9 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable)
 			goto out_unlock;
 		}
 
-		imx7_csi_streaming_start(csi);
+		imx7_csi_enable(csi);
 	} else {
-		imx7_csi_streaming_stop(csi);
+		imx7_csi_disable(csi);
 
 		v4l2_subdev_call(csi->src_sd, video, s_stream, 0);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 44/77] media: imx: imx7-media-csi: Merge hw_reset() with init_interface()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (42 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 43/77] media: imx: imx7-media-csi: Merge streaming_start() with csi_enable() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 45/77] media: imx: imx7-media-csi: Set the MIPI data type based on the bus code Laurent Pinchart
                   ` (34 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The imx7_csi_hw_reset() and imx7_csi_init_interface() functions are
always called together. Merge them. This allows simplifying the code by
avoiding duplicated register writes.

As the imx7_csi_hw_reset() function didn't perform a hardware reset by
initialized the registers to reset defaults (in addition to resetting
the frame counter), name the resulting function imx7_csi_init_default()
as it sets default values.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 37 +++++++---------------
 1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 53bab0a0a878..0ad18885542b 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -212,17 +212,6 @@ static void imx7_csi_reg_write(struct imx7_csi *csi, unsigned int value,
 	writel(value, csi->regbase + offset);
 }
 
-static void imx7_csi_hw_reset(struct imx7_csi *csi)
-{
-	imx7_csi_reg_write(csi,
-			   imx7_csi_reg_read(csi, CSI_CSICR3) | BIT_FRMCNT_RST,
-			   CSI_CSICR3);
-
-	imx7_csi_reg_write(csi, BIT_EXT_VSYNC | BIT_HSYNC_POL, CSI_CSICR1);
-	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
-	imx7_csi_reg_write(csi, 0, CSI_CSICR3);
-}
-
 static u32 imx7_csi_irq_clear(struct imx7_csi *csi)
 {
 	u32 isr;
@@ -233,20 +222,18 @@ static u32 imx7_csi_irq_clear(struct imx7_csi *csi)
 	return isr;
 }
 
-static void imx7_csi_init_interface(struct imx7_csi *csi)
+static void imx7_csi_init_default(struct imx7_csi *csi)
 {
-	unsigned int val = 0;
-	unsigned int imag_para;
+	imx7_csi_reg_write(csi, BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE |
+			   BIT_HSYNC_POL | BIT_FCC | BIT_MCLKDIV(1) |
+			   BIT_MCLKEN, CSI_CSICR1);
+	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
+	imx7_csi_reg_write(csi, BIT_FRMCNT_RST, CSI_CSICR3);
 
-	val = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL |
-		BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
-	imx7_csi_reg_write(csi, val, CSI_CSICR1);
+	imx7_csi_reg_write(csi, BIT_IMAGE_WIDTH(800) | BIT_IMAGE_HEIGHT(600),
+			   CSI_CSIIMAG_PARA);
 
-	imag_para = BIT_IMAGE_WIDTH(800) | BIT_IMAGE_HEIGHT(600);
-	imx7_csi_reg_write(csi, imag_para, CSI_CSIIMAG_PARA);
-
-	val = BIT_DMA_REFLASH_RFF;
-	imx7_csi_reg_write(csi, val, CSI_CSICR3);
+	imx7_csi_reg_write(csi, BIT_DMA_REFLASH_RFF, CSI_CSICR3);
 }
 
 static void imx7_csi_hw_enable_irq(struct imx7_csi *csi)
@@ -578,8 +565,7 @@ static int imx7_csi_init(struct imx7_csi *csi)
 	if (ret < 0)
 		return ret;
 
-	imx7_csi_hw_reset(csi);
-	imx7_csi_init_interface(csi);
+	imx7_csi_init_default(csi);
 	imx7_csi_dmareq_rff_enable(csi);
 
 	ret = imx7_csi_dma_setup(csi);
@@ -594,8 +580,7 @@ static int imx7_csi_init(struct imx7_csi *csi)
 static void imx7_csi_deinit(struct imx7_csi *csi)
 {
 	imx7_csi_dma_cleanup(csi);
-	imx7_csi_hw_reset(csi);
-	imx7_csi_init_interface(csi);
+	imx7_csi_init_default(csi);
 	imx7_csi_dmareq_rff_disable(csi);
 	clk_disable_unprepare(csi->mclk);
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 45/77] media: imx: imx7-media-csi: Set the MIPI data type based on the bus code
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (43 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 44/77] media: imx: imx7-media-csi: Merge hw_reset() with init_interface() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 46/77] media: imx: imx7-media-csi: Don't set the buffer stride when disabling Laurent Pinchart
                   ` (33 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The MIPI CSI-2 data type depends solely on the media bus code on the
sink pad. Deriving it from the pixel format is confusing. Simplify the
code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 64 +++++++++++++---------
 1 file changed, 39 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 0ad18885542b..b4bd161bec40 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -482,7 +482,6 @@ 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;
-	__u32 in_code = csi->format_mbus[IMX7_CSI_PAD_SINK].code;
 	u32 cr1, cr18;
 	int width = out_pix->width;
 
@@ -518,37 +517,52 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 	cr18 &= BIT_MIPI_DATA_FORMAT_MASK;
 	cr18 |= BIT_DATA_FROM_MIPI;
 
-	switch (out_pix->pixelformat) {
-	case V4L2_PIX_FMT_UYVY:
-	case V4L2_PIX_FMT_YUYV:
-		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
+	switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
+	case MEDIA_BUS_FMT_Y8_1X8:
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+	case MEDIA_BUS_FMT_SGBRG8_1X8:
+	case MEDIA_BUS_FMT_SGRBG8_1X8:
+	case MEDIA_BUS_FMT_SRGGB8_1X8:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
 		break;
-	case V4L2_PIX_FMT_GREY:
-		if (in_code == MEDIA_BUS_FMT_Y8_1X8)
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
-		else if (in_code == MEDIA_BUS_FMT_Y10_1X10)
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
-		else
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
-		break;
-	case V4L2_PIX_FMT_Y10:
+	case MEDIA_BUS_FMT_Y10_1X10:
+	case MEDIA_BUS_FMT_SBGGR10_1X10:
+	case MEDIA_BUS_FMT_SGBRG10_1X10:
+	case MEDIA_BUS_FMT_SGRBG10_1X10:
+	case MEDIA_BUS_FMT_SRGGB10_1X10:
 		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
-		cr1 |= BIT_PIXEL_BIT;
 		break;
-	case V4L2_PIX_FMT_Y12:
+	case MEDIA_BUS_FMT_Y12_1X12:
+	case MEDIA_BUS_FMT_SBGGR12_1X12:
+	case MEDIA_BUS_FMT_SGBRG12_1X12:
+	case MEDIA_BUS_FMT_SGRBG12_1X12:
+	case MEDIA_BUS_FMT_SRGGB12_1X12:
 		cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
-		cr1 |= BIT_PIXEL_BIT;
 		break;
+	case MEDIA_BUS_FMT_Y14_1X14:
+	case MEDIA_BUS_FMT_SBGGR14_1X14:
+	case MEDIA_BUS_FMT_SGBRG14_1X14:
+	case MEDIA_BUS_FMT_SGRBG14_1X14:
+	case MEDIA_BUS_FMT_SRGGB14_1X14:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
+		break;
+	/*
+	 * CSI-2 sources are supposed to use the 1X16 formats, but not all of
+	 * them comply. Support both variants.
+	 */
+	case MEDIA_BUS_FMT_UYVY8_2X8:
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_2X8:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
+		break;
+	}
+
+	switch (out_pix->pixelformat) {
+	case V4L2_PIX_FMT_Y10:
+	case V4L2_PIX_FMT_Y12:
 	case V4L2_PIX_FMT_SBGGR8:
-		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
-		break;
 	case V4L2_PIX_FMT_SBGGR16:
-		if (in_code == MEDIA_BUS_FMT_SBGGR10_1X10)
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
-		else if (in_code == MEDIA_BUS_FMT_SBGGR12_1X12)
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
-		else if (in_code == MEDIA_BUS_FMT_SBGGR14_1X14)
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
 		cr1 |= BIT_PIXEL_BIT;
 		break;
 	}
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 46/77] media: imx: imx7-media-csi: Don't set the buffer stride when disabling
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (44 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 45/77] media: imx: imx7-media-csi: Set the MIPI data type based on the bus code Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 47/77] media: imx: imx7-media-csi: Merge all config in imx7_csi_configure() Laurent Pinchart
                   ` (32 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

There's no need to set the buffer stride to 0 when disabling the CSI.
Remove the extraneous register write.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.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 b4bd161bec40..ac6763f8810d 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -616,8 +616,6 @@ static void imx7_csi_disable(struct imx7_csi *csi)
 
 	imx7_csi_hw_disable_irq(csi);
 
-	imx7_csi_buf_stride_set(csi, 0);
-
 	imx7_csi_hw_disable(csi);
 }
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 47/77] media: imx: imx7-media-csi: Merge all config in imx7_csi_configure()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (45 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 46/77] media: imx: imx7-media-csi: Don't set the buffer stride when disabling Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 48/77] media: imx: imx7-media-csi: Clear all configurable CSICR18 fields Laurent Pinchart
                   ` (31 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Merge all the configuration steps (imx7_csi_buf_stride_set(),
imx7_csi_deinterlace_enable(), imx7_csi_set_imagpara() and
imx7_csi_init_default()) in the imx7_csi_configure() function. This
simplifies the configuration procedure by removing most
read-update-write cycles, and makes the code generally more readable.

imx7_csi_init_default() is kept as it is also called from
imx7_csi_deinit(). This will be addressed separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 202 +++++++++------------
 1 file changed, 88 insertions(+), 114 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ac6763f8810d..9c1e4c8754e2 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -305,23 +305,6 @@ static void imx7_csi_rx_fifo_clear(struct imx7_csi *csi)
 	imx7_csi_reg_write(csi, cr1 | BIT_FCC, CSI_CSICR1);
 }
 
-static void imx7_csi_buf_stride_set(struct imx7_csi *csi, u32 stride)
-{
-	imx7_csi_reg_write(csi, stride, CSI_CSIFBUF_PARA);
-}
-
-static void imx7_csi_deinterlace_enable(struct imx7_csi *csi, bool enable)
-{
-	u32 cr18 = imx7_csi_reg_read(csi, CSI_CSICR18);
-
-	if (enable)
-		cr18 |= BIT_DEINTERLACE_EN;
-	else
-		cr18 &= ~BIT_DEINTERLACE_EN;
-
-	imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
-}
-
 static void imx7_csi_dmareq_rff_enable(struct imx7_csi *csi)
 {
 	u32 cr3 = imx7_csi_reg_read(csi, CSI_CSICR3);
@@ -348,21 +331,6 @@ static void imx7_csi_dmareq_rff_disable(struct imx7_csi *csi)
 	imx7_csi_reg_write(csi, cr3, CSI_CSICR3);
 }
 
-static void imx7_csi_set_imagpara(struct imx7_csi *csi, int width, int height)
-{
-	int imag_para;
-	int rx_count;
-
-	rx_count = (width * height) >> 2;
-	imx7_csi_reg_write(csi, rx_count, CSI_CSIRXCNT);
-
-	imag_para = BIT_IMAGE_WIDTH(width) | BIT_IMAGE_HEIGHT(height);
-	imx7_csi_reg_write(csi, imag_para, CSI_CSIIMAG_PARA);
-
-	/* reflash the embedded DMA controller */
-	imx7_csi_dma_reflash(csi);
-}
-
 static void imx7_csi_sw_reset(struct imx7_csi *csi)
 {
 	imx7_csi_hw_disable(csi);
@@ -482,93 +450,101 @@ 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;
-	u32 cr1, cr18;
 	int width = out_pix->width;
-
-	if (out_pix->field == V4L2_FIELD_INTERLACED) {
-		imx7_csi_deinterlace_enable(csi, true);
-		imx7_csi_buf_stride_set(csi, out_pix->width);
-	} else {
-		imx7_csi_deinterlace_enable(csi, false);
-		imx7_csi_buf_stride_set(csi, 0);
-	}
+	u32 cr1, cr18;
+	u32 stride;
 
 	cr18 = imx7_csi_reg_read(csi, CSI_CSICR18);
 
+	if (out_pix->field == V4L2_FIELD_INTERLACED) {
+		cr18 |= BIT_DEINTERLACE_EN;
+		stride = out_pix->width;
+	} else {
+		cr18 &= ~BIT_DEINTERLACE_EN;
+		stride = 0;
+	}
+
 	if (!csi->is_csi2) {
+		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
+		    | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
+
+		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+			BIT_BASEADDR_CHG_ERR_EN;
+
 		if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY ||
 		    out_pix->pixelformat == V4L2_PIX_FMT_YUYV)
 			width *= 2;
-
-		imx7_csi_set_imagpara(csi, width, out_pix->height);
-
-		cr18 |= (BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
-			BIT_BASEADDR_CHG_ERR_EN);
-		imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
-
-		return;
-	}
-
-	imx7_csi_set_imagpara(csi, width, out_pix->height);
-
-	cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
-	cr1 &= ~BIT_GCLK_MODE;
-
-	cr18 &= BIT_MIPI_DATA_FORMAT_MASK;
-	cr18 |= BIT_DATA_FROM_MIPI;
-
-	switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
-	case MEDIA_BUS_FMT_Y8_1X8:
-	case MEDIA_BUS_FMT_SBGGR8_1X8:
-	case MEDIA_BUS_FMT_SGBRG8_1X8:
-	case MEDIA_BUS_FMT_SGRBG8_1X8:
-	case MEDIA_BUS_FMT_SRGGB8_1X8:
-		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
-		break;
-	case MEDIA_BUS_FMT_Y10_1X10:
-	case MEDIA_BUS_FMT_SBGGR10_1X10:
-	case MEDIA_BUS_FMT_SGBRG10_1X10:
-	case MEDIA_BUS_FMT_SGRBG10_1X10:
-	case MEDIA_BUS_FMT_SRGGB10_1X10:
-		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
-		break;
-	case MEDIA_BUS_FMT_Y12_1X12:
-	case MEDIA_BUS_FMT_SBGGR12_1X12:
-	case MEDIA_BUS_FMT_SGBRG12_1X12:
-	case MEDIA_BUS_FMT_SGRBG12_1X12:
-	case MEDIA_BUS_FMT_SRGGB12_1X12:
-		cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
-		break;
-	case MEDIA_BUS_FMT_Y14_1X14:
-	case MEDIA_BUS_FMT_SBGGR14_1X14:
-	case MEDIA_BUS_FMT_SGBRG14_1X14:
-	case MEDIA_BUS_FMT_SGRBG14_1X14:
-	case MEDIA_BUS_FMT_SRGGB14_1X14:
-		cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
-		break;
-	/*
-	 * CSI-2 sources are supposed to use the 1X16 formats, but not all of
-	 * them comply. Support both variants.
-	 */
-	case MEDIA_BUS_FMT_UYVY8_2X8:
-	case MEDIA_BUS_FMT_UYVY8_1X16:
-	case MEDIA_BUS_FMT_YUYV8_2X8:
-	case MEDIA_BUS_FMT_YUYV8_1X16:
-		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
-		break;
-	}
-
-	switch (out_pix->pixelformat) {
-	case V4L2_PIX_FMT_Y10:
-	case V4L2_PIX_FMT_Y12:
-	case V4L2_PIX_FMT_SBGGR8:
-	case V4L2_PIX_FMT_SBGGR16:
-		cr1 |= BIT_PIXEL_BIT;
-		break;
+	} else {
+		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
+		    | BIT_MCLKDIV(1) | BIT_MCLKEN;
+
+		cr18 &= BIT_MIPI_DATA_FORMAT_MASK;
+		cr18 |= BIT_DATA_FROM_MIPI;
+
+		switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
+		case MEDIA_BUS_FMT_Y8_1X8:
+		case MEDIA_BUS_FMT_SBGGR8_1X8:
+		case MEDIA_BUS_FMT_SGBRG8_1X8:
+		case MEDIA_BUS_FMT_SGRBG8_1X8:
+		case MEDIA_BUS_FMT_SRGGB8_1X8:
+			cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
+			break;
+		case MEDIA_BUS_FMT_Y10_1X10:
+		case MEDIA_BUS_FMT_SBGGR10_1X10:
+		case MEDIA_BUS_FMT_SGBRG10_1X10:
+		case MEDIA_BUS_FMT_SGRBG10_1X10:
+		case MEDIA_BUS_FMT_SRGGB10_1X10:
+			cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
+			break;
+		case MEDIA_BUS_FMT_Y12_1X12:
+		case MEDIA_BUS_FMT_SBGGR12_1X12:
+		case MEDIA_BUS_FMT_SGBRG12_1X12:
+		case MEDIA_BUS_FMT_SGRBG12_1X12:
+		case MEDIA_BUS_FMT_SRGGB12_1X12:
+			cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
+			break;
+		case MEDIA_BUS_FMT_Y14_1X14:
+		case MEDIA_BUS_FMT_SBGGR14_1X14:
+		case MEDIA_BUS_FMT_SGBRG14_1X14:
+		case MEDIA_BUS_FMT_SGRBG14_1X14:
+		case MEDIA_BUS_FMT_SRGGB14_1X14:
+			cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
+			break;
+		/*
+		 * CSI-2 sources are supposed to use the 1X16 formats, but not
+		 * all of them comply. Support both variants.
+		 */
+		case MEDIA_BUS_FMT_UYVY8_2X8:
+		case MEDIA_BUS_FMT_UYVY8_1X16:
+		case MEDIA_BUS_FMT_YUYV8_2X8:
+		case MEDIA_BUS_FMT_YUYV8_1X16:
+			cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
+			break;
+		}
+
+		switch (out_pix->pixelformat) {
+		case V4L2_PIX_FMT_Y10:
+		case V4L2_PIX_FMT_Y12:
+		case V4L2_PIX_FMT_SBGGR8:
+		case V4L2_PIX_FMT_SBGGR16:
+			cr1 |= BIT_PIXEL_BIT;
+			break;
+		}
 	}
 
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
+	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
+	imx7_csi_reg_write(csi, BIT_FRMCNT_RST, CSI_CSICR3);
 	imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
+
+	imx7_csi_reg_write(csi, (width * out_pix->height) >> 2, CSI_CSIRXCNT);
+	imx7_csi_reg_write(csi, BIT_IMAGE_WIDTH(width) |
+			   BIT_IMAGE_HEIGHT(out_pix->height),
+			   CSI_CSIIMAG_PARA);
+	imx7_csi_reg_write(csi, stride, CSI_CSIFBUF_PARA);
+
+	/* reflash the embedded DMA controller */
+	imx7_csi_dma_reflash(csi);
 }
 
 static int imx7_csi_init(struct imx7_csi *csi)
@@ -579,14 +555,12 @@ static int imx7_csi_init(struct imx7_csi *csi)
 	if (ret < 0)
 		return ret;
 
-	imx7_csi_init_default(csi);
-	imx7_csi_dmareq_rff_enable(csi);
-
-	ret = imx7_csi_dma_setup(csi);
-	if (ret < 0)
-		return ret;
-
 	imx7_csi_configure(csi);
+	imx7_csi_dmareq_rff_enable(csi);
+
+	ret = imx7_csi_dma_setup(csi);
+	if (ret < 0)
+		return ret;
 
 	return 0;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 48/77] media: imx: imx7-media-csi: Clear all configurable CSICR18 fields
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (46 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 47/77] media: imx: imx7-media-csi: Merge all config in imx7_csi_configure() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 49/77] media: imx: imx7-media-csi: Set RFF burst type in imx7_csi_configure() Laurent Pinchart
                   ` (30 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

When configuring the CSI in imx7_csi_configure(), the CSICR18 is set
through a read-modify-write cycle to avoid affecting fields whose usage
isn't clear. The function then sets fields depending on whether the
input is interlaced or progressive, and from the parallel input or the
CSI-2 receiver.

Those bits are only set and never cleared. For instance, when switching
from a CSI-2 source to the parallel input, the BIT_DATA_FROM_MIPI will
stay set. Fix this issue by first clearing all the fields we need to
configure.

Add BIT_CSI_HW_ENABLE to the set of fields being cleared, as the CSI
needs to start in the disabled state. This allows dropping the call to
imx7_csi_hw_disable() in imx7_csi_sw_reset().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 9c1e4c8754e2..ea14195e6c7f 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -333,8 +333,6 @@ static void imx7_csi_dmareq_rff_disable(struct imx7_csi *csi)
 
 static void imx7_csi_sw_reset(struct imx7_csi *csi)
 {
-	imx7_csi_hw_disable(csi);
-
 	imx7_csi_rx_fifo_clear(csi);
 
 	imx7_csi_dma_reflash(csi);
@@ -451,17 +449,19 @@ 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;
 	int width = out_pix->width;
+	u32 stride = 0;
 	u32 cr1, cr18;
-	u32 stride;
 
 	cr18 = imx7_csi_reg_read(csi, CSI_CSICR18);
 
+	cr18 &= ~(BIT_CSI_HW_ENABLE | BIT_MIPI_DATA_FORMAT_MASK |
+		  BIT_DATA_FROM_MIPI | BIT_BASEADDR_CHG_ERR_EN |
+		  BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+		  BIT_DEINTERLACE_EN);
+
 	if (out_pix->field == V4L2_FIELD_INTERLACED) {
 		cr18 |= BIT_DEINTERLACE_EN;
 		stride = out_pix->width;
-	} else {
-		cr18 &= ~BIT_DEINTERLACE_EN;
-		stride = 0;
 	}
 
 	if (!csi->is_csi2) {
@@ -478,7 +478,6 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
 		    | BIT_MCLKDIV(1) | BIT_MCLKEN;
 
-		cr18 &= BIT_MIPI_DATA_FORMAT_MASK;
 		cr18 |= BIT_DATA_FROM_MIPI;
 
 		switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 49/77] media: imx: imx7-media-csi: Set RFF burst type in imx7_csi_configure()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (47 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 48/77] media: imx: imx7-media-csi: Clear all configurable CSICR18 fields Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 50/77] media: imx: imx7-media-csi: Simplify imx7_csi_rx_fifo_clear() Laurent Pinchart
                   ` (29 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The RFF burst type is set in imx7_csi_dmareq_rff_enable(), which doesn't
match the function name. Move it to imx7_csi_configure().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ea14195e6c7f..3d1dd8ef9d87 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -308,10 +308,6 @@ static void imx7_csi_rx_fifo_clear(struct imx7_csi *csi)
 static void imx7_csi_dmareq_rff_enable(struct imx7_csi *csi)
 {
 	u32 cr3 = imx7_csi_reg_read(csi, CSI_CSICR3);
-	u32 cr2 = imx7_csi_reg_read(csi, CSI_CSICR2);
-
-	/* Burst Type of DMA Transfer from RxFIFO. INCR16 */
-	cr2 |= BIT_DMA_BURST_TYPE_RFF_INCR16;
 
 	cr3 |= BIT_DMA_REQ_EN_RFF;
 	cr3 |= BIT_HRESP_ERR_EN;
@@ -319,7 +315,6 @@ static void imx7_csi_dmareq_rff_enable(struct imx7_csi *csi)
 	cr3 |= BIT_RXFF_LEVEL(2);
 
 	imx7_csi_reg_write(csi, cr3, CSI_CSICR3);
-	imx7_csi_reg_write(csi, cr2, CSI_CSICR2);
 }
 
 static void imx7_csi_dmareq_rff_disable(struct imx7_csi *csi)
@@ -532,7 +527,7 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 	}
 
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
-	imx7_csi_reg_write(csi, 0, CSI_CSICR2);
+	imx7_csi_reg_write(csi, BIT_DMA_BURST_TYPE_RFF_INCR16, CSI_CSICR2);
 	imx7_csi_reg_write(csi, BIT_FRMCNT_RST, CSI_CSICR3);
 	imx7_csi_reg_write(csi, cr18, CSI_CSICR18);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 50/77] media: imx: imx7-media-csi: Simplify imx7_csi_rx_fifo_clear()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (48 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 49/77] media: imx: imx7-media-csi: Set RFF burst type in imx7_csi_configure() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 51/77] media: imx: imx7-media-csi: Don't double-enable the CSI Laurent Pinchart
                   ` (28 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

There's no need to read the CSICR1 register before each write in
imx7_csi_rx_fifo_clear(). Simplify the function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 3d1dd8ef9d87..fb09af335edf 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -294,14 +294,10 @@ static void imx7_csi_dma_reflash(struct imx7_csi *csi)
 
 static void imx7_csi_rx_fifo_clear(struct imx7_csi *csi)
 {
-	u32 cr1;
+	u32 cr1 = imx7_csi_reg_read(csi, CSI_CSICR1) & ~BIT_FCC;
 
-	cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
-	imx7_csi_reg_write(csi, cr1 & ~BIT_FCC, CSI_CSICR1);
-	cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
+	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
 	imx7_csi_reg_write(csi, cr1 | BIT_CLR_RXFIFO, CSI_CSICR1);
-
-	cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
 	imx7_csi_reg_write(csi, cr1 | BIT_FCC, CSI_CSICR1);
 }
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 51/77] media: imx: imx7-media-csi: Don't double-enable the CSI
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (49 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 50/77] media: imx: imx7-media-csi: Simplify imx7_csi_rx_fifo_clear() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 52/77] media: imx: imx7-media-csi: Don't double-enable the RxFIFO Laurent Pinchart
                   ` (27 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The CSI is enabled at the end of imx7_csi_sw_reset(), called from
imx7_csi_enable(), as well as at the end of imx7_csi_enable(). The
latter is enough, remove the former.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.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 fb09af335edf..ed389928fa4e 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -331,8 +331,6 @@ static void imx7_csi_sw_reset(struct imx7_csi *csi)
 	usleep_range(2000, 3000);
 
 	imx7_csi_irq_clear(csi);
-
-	imx7_csi_hw_enable(csi);
 }
 
 static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 52/77] media: imx: imx7-media-csi: Don't double-enable the RxFIFO
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (50 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 51/77] media: imx: imx7-media-csi: Don't double-enable the CSI Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 53/77] media: imx: imx7-media-csi: Remove double reflash of DMA controller Laurent Pinchart
                   ` (26 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The RxFIFO is enabled by imx7_csi_dmareq_rff_enable() in both
imx7_csi_init() and imx7_csi_enable(). Enabling it once is enough,
remove the former.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index ed389928fa4e..439e4ed8ed10 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -544,7 +544,6 @@ static int imx7_csi_init(struct imx7_csi *csi)
 		return ret;
 
 	imx7_csi_configure(csi);
-	imx7_csi_dmareq_rff_enable(csi);
 
 	ret = imx7_csi_dma_setup(csi);
 	if (ret < 0)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 53/77] media: imx: imx7-media-csi: Remove double reflash of DMA controller
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (51 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 52/77] media: imx: imx7-media-csi: Don't double-enable the RxFIFO Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 54/77] media: imx: imx7-media-csi: Don't enable SOF and EOF interrupts Laurent Pinchart
                   ` (25 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The DMA controller needs to be reflashed after being configured. There
is however no need to do it twice, once in imx7_csi_configure() and once
in imx7_csi_sw_reset(), called from imx7_csi_enable(). Remove the
former.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.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 439e4ed8ed10..4a8d48495701 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -530,9 +530,6 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 			   BIT_IMAGE_HEIGHT(out_pix->height),
 			   CSI_CSIIMAG_PARA);
 	imx7_csi_reg_write(csi, stride, CSI_CSIFBUF_PARA);
-
-	/* reflash the embedded DMA controller */
-	imx7_csi_dma_reflash(csi);
 }
 
 static int imx7_csi_init(struct imx7_csi *csi)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 54/77] media: imx: imx7-media-csi: Don't enable SOF and EOF interrupts
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (52 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 53/77] media: imx: imx7-media-csi: Remove double reflash of DMA controller Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 55/77] media: imx: imx7_media-csi: Add support for additional Bayer patterns Laurent Pinchart
                   ` (24 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The SOF and EOF interrupts are not used. Don't enable them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 30 ++++++++--------------
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 4a8d48495701..475c39b05f9a 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -240,15 +240,10 @@ static void imx7_csi_hw_enable_irq(struct imx7_csi *csi)
 {
 	u32 cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
 
-	cr1 |= BIT_SOF_INTEN;
 	cr1 |= BIT_RFF_OR_INT;
-
-	/* still capture needs DMA interrupt */
 	cr1 |= BIT_FB1_DMA_DONE_INTEN;
 	cr1 |= BIT_FB2_DMA_DONE_INTEN;
 
-	cr1 |= BIT_EOF_INT_EN;
-
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
 }
 
@@ -256,11 +251,9 @@ static void imx7_csi_hw_disable_irq(struct imx7_csi *csi)
 {
 	u32 cr1 = imx7_csi_reg_read(csi, CSI_CSICR1);
 
-	cr1 &= ~BIT_SOF_INTEN;
 	cr1 &= ~BIT_RFF_OR_INT;
 	cr1 &= ~BIT_FB1_DMA_DONE_INTEN;
 	cr1 &= ~BIT_FB2_DMA_DONE_INTEN;
-	cr1 &= ~BIT_EOF_INT_EN;
 
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
 }
@@ -322,17 +315,6 @@ static void imx7_csi_dmareq_rff_disable(struct imx7_csi *csi)
 	imx7_csi_reg_write(csi, cr3, CSI_CSICR3);
 }
 
-static void imx7_csi_sw_reset(struct imx7_csi *csi)
-{
-	imx7_csi_rx_fifo_clear(csi);
-
-	imx7_csi_dma_reflash(csi);
-
-	usleep_range(2000, 3000);
-
-	imx7_csi_irq_clear(csi);
-}
-
 static void imx7_csi_update_buf(struct imx7_csi *csi, dma_addr_t phys,
 				int buf_num)
 {
@@ -559,10 +541,18 @@ static void imx7_csi_deinit(struct imx7_csi *csi)
 
 static void imx7_csi_enable(struct imx7_csi *csi)
 {
-	imx7_csi_sw_reset(csi);
+	/* Clear the Rx FIFO and reflash the DMA controller. */
+	imx7_csi_rx_fifo_clear(csi);
+	imx7_csi_dma_reflash(csi);
 
-	imx7_csi_dmareq_rff_enable(csi);
+	usleep_range(2000, 3000);
+
+	/* Clear and enable the interrupts. */
+	imx7_csi_irq_clear(csi);
 	imx7_csi_hw_enable_irq(csi);
+
+	/* Enable the RxFIFO DMA and the CSI. */
+	imx7_csi_dmareq_rff_enable(csi);
 	imx7_csi_hw_enable(csi);
 }
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 55/77] media: imx: imx7_media-csi: Add support for additional Bayer patterns
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (53 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 54/77] media: imx: imx7-media-csi: Don't enable SOF and EOF interrupts Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 56/77] media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad() Laurent Pinchart
                   ` (23 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The CSI driver only supports the BGGR Bayer patterns currently. The
hardware supports all patterns (the only pattern-dependent hardware
operation is statistics calculation, as de-bayering isn't supported),
enable them in the driver too.

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

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 475c39b05f9a..763235447422 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -496,7 +496,13 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 		case V4L2_PIX_FMT_Y10:
 		case V4L2_PIX_FMT_Y12:
 		case V4L2_PIX_FMT_SBGGR8:
+		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:
 			cr1 |= BIT_PIXEL_BIT;
 			break;
 		}
@@ -975,7 +981,13 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	case V4L2_PIX_FMT_Y10:
 	case V4L2_PIX_FMT_Y12:
 	case V4L2_PIX_FMT_SBGGR8:
+	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:
 		break;
 
 	default:
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 56/77] media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (54 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 55/77] media: imx: imx7_media-csi: Add support for additional Bayer patterns Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 57/77] media: imx: imx7_media-csi: Create immutable link to source device Laurent Pinchart
                   ` (22 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Add a flags argument to the v4l2_create_fwnode_links_to_pad() function
to specify the link flags. This allows drivers to create immutable links
for instance.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/media/v4l2-core/v4l2-mc.c          | 6 +++---
 drivers/staging/media/imx/imx-media-csi.c  | 2 +-
 drivers/staging/media/imx/imx6-mipi-csi2.c | 2 +-
 drivers/staging/media/imx/imx7-media-csi.c | 2 +-
 drivers/staging/media/imx/imx7-mipi-csis.c | 2 +-
 include/media/v4l2-mc.h                    | 8 +++++++-
 6 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
index ba2f2b8dcc8c..cba3d8e0bc4a 100644
--- a/drivers/media/v4l2-core/v4l2-mc.c
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -310,7 +310,7 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
 int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
-				    struct media_pad *sink)
+				    struct media_pad *sink, u32 flags)
 {
 	struct fwnode_handle *endpoint;
 	struct v4l2_subdev *sink_sd;
@@ -367,7 +367,7 @@ int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
 			sink_sd->entity.name, sink_idx);
 
 		ret = media_create_pad_link(&src_sd->entity, src_idx,
-					    &sink_sd->entity, sink_idx, 0);
+					    &sink_sd->entity, sink_idx, flags);
 		if (ret) {
 			dev_err(sink_sd->dev,
 				"link %s:%d -> %s:%d failed with %d\n",
@@ -395,7 +395,7 @@ int v4l2_create_fwnode_links(struct v4l2_subdev *src_sd,
 		if (!(pad->flags & MEDIA_PAD_FL_SINK))
 			continue;
 
-		ret = v4l2_create_fwnode_links_to_pad(src_sd, pad);
+		ret = v4l2_create_fwnode_links_to_pad(src_sd, pad, 0);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c
index 8d02939aaa23..e3bfd635a89a 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1894,7 +1894,7 @@ static int imx_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	if (sd->entity.function == MEDIA_ENT_F_VID_MUX)
 		sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
 
-	return v4l2_create_fwnode_links_to_pad(sd, sink);
+	return v4l2_create_fwnode_links_to_pad(sd, sink, 0);
 }
 
 static const struct v4l2_async_notifier_operations csi_notify_ops = {
diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c
index 9020541edb89..fc2378ac04b7 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -621,7 +621,7 @@ static int csi2_notify_bound(struct v4l2_async_notifier *notifier,
 
 	dev_dbg(csi2->dev, "Bound %s pad: %d\n", sd->name, pad);
 
-	return v4l2_create_fwnode_links_to_pad(sd, sink);
+	return v4l2_create_fwnode_links_to_pad(sd, sink, 0);
 }
 
 static void csi2_notify_unbind(struct v4l2_async_notifier *notifier,
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 763235447422..69eac1cb4599 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1128,7 +1128,7 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	if (sd->entity.function == MEDIA_ENT_F_VID_MUX)
 		sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
 
-	return v4l2_create_fwnode_links_to_pad(sd, sink);
+	return v4l2_create_fwnode_links_to_pad(sd, sink, 0);
 }
 
 static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index a01a7364b4b9..8cf860544b0a 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -962,7 +962,7 @@ static int mipi_csis_notify_bound(struct v4l2_async_notifier *notifier,
 	struct csi_state *state = mipi_notifier_to_csis_state(notifier);
 	struct media_pad *sink = &state->mipi_sd.entity.pads[CSIS_PAD_SINK];
 
-	return v4l2_create_fwnode_links_to_pad(sd, sink);
+	return v4l2_create_fwnode_links_to_pad(sd, sink, 0);
 }
 
 static const struct v4l2_async_notifier_operations mipi_csis_notify_ops = {
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index bdaa5f2f8ca2..c181685923d5 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -91,6 +91,7 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q);
  *
  * @src_sd: pointer to a source subdev
  * @sink:  pointer to a subdev sink pad
+ * @flags: the link flags
  *
  * This function searches for fwnode endpoint connections from a source
  * subdevice to a single sink pad, and if suitable connections are found,
@@ -98,6 +99,11 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q);
  * called by the sink subdevice, in its v4l2-async notifier subdev bound
  * callback, to create links from a bound source subdevice.
  *
+ * The @flags argument specifies the link flags. The caller shall ensure that
+ * the flags are valid regardless of the number of links that may be created.
+ * For instance, setting the MEDIA_LNK_FL_ENABLED flag will cause all created
+ * links to be enabled, which isn't valid if more than one link is created.
+ *
  * .. note::
  *
  *    Any sink subdevice that calls this function must implement the
@@ -107,7 +113,7 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q);
  * Return 0 on success or a negative error code on failure.
  */
 int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
-				    struct media_pad *sink);
+				    struct media_pad *sink, u32 flags);
 
 /**
  * v4l2_create_fwnode_links - Create fwnode-based links from a source
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 57/77] media: imx: imx7_media-csi: Create immutable link to source device
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (55 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 56/77] media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
                   ` (21 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The CSI subdev has a single source, the input video mux. There's thus a
single link between the source and the CSI, which can be made immutable
and enabled to simplify configuration.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-media-csi.c | 45 ++--------------------
 1 file changed, 4 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 69eac1cb4599..f85a2f5f1413 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1065,47 +1065,7 @@ static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = {
  * Media Entity Operations
  */
 
-static int imx7_csi_link_setup(struct media_entity *entity,
-			       const struct media_pad *local,
-			       const struct media_pad *remote, u32 flags)
-{
-	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
-	struct imx7_csi *csi = v4l2_get_subdevdata(sd);
-	struct v4l2_subdev *remote_sd;
-	int ret = 0;
-
-	dev_dbg(csi->dev, "link setup %s -> %s\n", remote->entity->name,
-		local->entity->name);
-
-	mutex_lock(&csi->lock);
-
-	if (local->flags & MEDIA_PAD_FL_SINK) {
-		if (!is_media_entity_v4l2_subdev(remote->entity)) {
-			ret = -EINVAL;
-			goto unlock;
-		}
-
-		remote_sd = media_entity_to_v4l2_subdev(remote->entity);
-
-		if (flags & MEDIA_LNK_FL_ENABLED) {
-			if (csi->src_sd) {
-				ret = -EBUSY;
-				goto unlock;
-			}
-			csi->src_sd = remote_sd;
-		} else {
-			csi->src_sd = NULL;
-		}
-	}
-
-unlock:
-	mutex_unlock(&csi->lock);
-
-	return ret;
-}
-
 static const struct media_entity_operations imx7_csi_entity_ops = {
-	.link_setup	= imx7_csi_link_setup,
 	.link_validate	= v4l2_subdev_link_validate,
 	.get_fwnode_pad = v4l2_subdev_get_fwnode_pad_1_to_1,
 };
@@ -1128,7 +1088,10 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	if (sd->entity.function == MEDIA_ENT_F_VID_MUX)
 		sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
 
-	return v4l2_create_fwnode_links_to_pad(sd, sink, 0);
+	csi->src_sd = sd;
+
+	return v4l2_create_fwnode_links_to_pad(sd, sink, MEDIA_LNK_FL_ENABLED |
+					       MEDIA_LNK_FL_IMMUTABLE);
 }
 
 static const struct v4l2_async_notifier_operations imx7_csi_notify_ops = {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (56 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 57/77] media: imx: imx7_media-csi: Create immutable link to source device Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-05 21:41   ` Rob Herring
  2021-02-15  4:27 ` [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
                   ` (20 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam, Rob Herring, devicetree

The reset-names property is incorrect, as it references the reset of the
MIPI D-PHY master, which is used by the DSI controller. Fixing the
property name would create backward-compatibility issues. As the device
has a single reset, we can instead drop reset-names completely, which
also simplifies the binding.

Fix the example accordingly to use the correct reset.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 .../devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml        | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
index 0668332959e7..8d4007caa210 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
@@ -44,9 +44,6 @@ properties:
   resets:
     maxItems: 1
 
-  reset-names:
-    const: mrst
-
   clock-frequency:
     description:
       The IP main (system bus) clock frequency in Hertz
@@ -118,7 +115,6 @@ required:
   - power-domains
   - phy-supply
   - resets
-  - reset-names
   - ports
 
 additionalProperties: false
@@ -144,7 +140,6 @@ examples:
             power-domains = <&pgc_mipi_phy>;
             phy-supply = <&reg_1p0d>;
             resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
-            reset-names = "mrst";
             fsl,csis-hs-settle = <3>;
 
             ports {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (57 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-05 21:42   ` Rob Herring
  2021-02-15  4:27 ` [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces Laurent Pinchart
                   ` (19 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam, Rob Herring, devicetree

The fsl,csis-hs-settle property isn't used by the driver anymore. Drop
it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 .../devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml       | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
index 8d4007caa210..74ff92b5baa3 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
@@ -49,11 +49,6 @@ properties:
       The IP main (system bus) clock frequency in Hertz
     default: 166000000
 
-  fsl,csis-hs-settle:
-    $ref: /schemas/types.yaml#/definitions/uint32
-    description:
-      Differential receiver (HS-RX) settle time
-
   ports:
     type: object
     description:
@@ -140,7 +135,6 @@ examples:
             power-domains = <&pgc_mipi_phy>;
             phy-supply = <&reg_1p0d>;
             resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
-            fsl,csis-hs-settle = <3>;
 
             ports {
                     #address-cells = <1>;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (58 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01  9:33   ` Rui Miguel Silva
  2021-03-05 21:42   ` Rob Herring
  2021-02-15  4:27 ` [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions Laurent Pinchart
                   ` (18 subsequent siblings)
  78 siblings, 2 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam, Rob Herring, devicetree

DT bindings examples are customarily indented with 4 spaces.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
index 74ff92b5baa3..76fcc8d80ee3 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
@@ -122,41 +122,41 @@ examples:
     #include <dt-bindings/reset/imx7-reset.h>
 
     mipi_csi: mipi-csi@30750000 {
-            compatible = "fsl,imx7-mipi-csi2";
-            reg = <0x30750000 0x10000>;
-            interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
+        compatible = "fsl,imx7-mipi-csi2";
+        reg = <0x30750000 0x10000>;
+        interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
 
-            clocks = <&clks IMX7D_IPG_ROOT_CLK>,
-                     <&clks IMX7D_MIPI_CSI_ROOT_CLK>,
-                     <&clks IMX7D_MIPI_DPHY_ROOT_CLK>;
-            clock-names = "pclk", "wrap", "phy";
-            clock-frequency = <166000000>;
+        clocks = <&clks IMX7D_IPG_ROOT_CLK>,
+                 <&clks IMX7D_MIPI_CSI_ROOT_CLK>,
+                 <&clks IMX7D_MIPI_DPHY_ROOT_CLK>;
+        clock-names = "pclk", "wrap", "phy";
+        clock-frequency = <166000000>;
 
-            power-domains = <&pgc_mipi_phy>;
-            phy-supply = <&reg_1p0d>;
-            resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
+        power-domains = <&pgc_mipi_phy>;
+        phy-supply = <&reg_1p0d>;
+        resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
 
-            ports {
-                    #address-cells = <1>;
-                    #size-cells = <0>;
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
 
-                    port@0 {
-                            reg = <0>;
+            port@0 {
+                reg = <0>;
 
-                            mipi_from_sensor: endpoint {
-                                    remote-endpoint = <&ov2680_to_mipi>;
-                                    data-lanes = <1>;
-                            };
-                    };
+                mipi_from_sensor: endpoint {
+                    remote-endpoint = <&ov2680_to_mipi>;
+                    data-lanes = <1>;
+                };
+            };
 
-                    port@1 {
-                            reg = <1>;
+            port@1 {
+                reg = <1>;
 
-                            mipi_vc0_to_csi_mux: endpoint {
-                                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
-                            };
-                    };
+                mipi_vc0_to_csi_mux: endpoint {
+                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
+                };
             };
+        };
     };
 
 ...
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (59 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01  9:35   ` Rui Miguel Silva
  2021-03-05 21:43   ` Rob Herring
  2021-02-15  4:27 ` [PATCH v2 62/77] media: imx: imx7_mipi_csis: Acquire reset control without naming it Laurent Pinchart
                   ` (17 subsequent siblings)
  78 siblings, 2 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam, Rob Herring, devicetree

Expand the description of the binding itself and of individual
properties to include additional information that may not be immediately
appartent from reading the reference manual. Drop the last sentence of
the phy-supply description that refers to the driver's implementation.

While at it, fix the capitalization of MIPI CSI-2 in the title.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 29 +++++++++++--------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
index 76fcc8d80ee3..471a5bf7eb76 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
@@ -4,14 +4,19 @@
 $id: http://devicetree.org/schemas/media/nxp,imx7-mipi-csi2.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: NXP i.MX7 Mipi CSI2
+title: NXP i.MX7 MIPI CSI-2 receiver
 
 maintainers:
   - Rui Miguel Silva <rmfrfs@gmail.com>
 
-description: |
-  This is the device node for the MIPI CSI-2 receiver core in i.MX7 soc. It is
-  compatible with previous version of samsung d-phy.
+description: |-
+  The NXP i.MX7 SoC family includes a MIPI CSI-2 receiver IP core, documented
+  as "CSIS V3.3". The IP core seems to originate from Samsung, and may be
+  compatible with some of the Exynos4 ad S5P SoCs.
+
+  While the CSI-2 receiver is separate from the MIPI D-PHY IP core, the PHY is
+  completely wrapped by the CSIS and doesn't expose a control interface of its
+  own. This binding thus covers both IP cores.
 
 properties:
   compatible:
@@ -24,8 +29,10 @@ properties:
     maxItems: 1
 
   clocks:
-    minItems: 3
-    maxItems: 3
+    items:
+      - description: The peripheral clock (a.k.a. APB clock)
+      - description: The external clock (optionally used as the pixel clock)
+      - description: The MIPI D-PHY clock
 
   clock-names:
     items:
@@ -37,16 +44,14 @@ properties:
     maxItems: 1
 
   phy-supply:
-    description:
-      Phandle to a regulator that provides power to the PHY. This
-      regulator will be managed during the PHY power on/off sequence.
+    description: The MIPI D-PHY digital power supply
 
   resets:
-    maxItems: 1
+    items:
+      - description: MIPI D-PHY slave reset
 
   clock-frequency:
-    description:
-      The IP main (system bus) clock frequency in Hertz
+    description: The desired external clock ("wrap") frequency, in Hz
     default: 166000000
 
   ports:
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 62/77] media: imx: imx7_mipi_csis: Acquire reset control without naming it
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (60 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 63/77] media: imx: imx7_mipi_csis: Fix input size alignment Laurent Pinchart
                   ` (16 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The device has a single reset line, there's thus no need to name it
explicitly when calling devm_reset_control_get_exclusive(). Drop the
name in preparation for the removal of the reset-names property in the
DT binding.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 8cf860544b0a..36eabab22bfb 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -943,7 +943,7 @@ static int mipi_csis_parse_dt(struct platform_device *pdev,
 		state->clk_frequency = DEFAULT_SCLK_CSIS_FREQ;
 
 	/* Get MIPI PHY resets */
-	state->mrst = devm_reset_control_get_exclusive(&pdev->dev, "mrst");
+	state->mrst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
 	if (IS_ERR(state->mrst))
 		return PTR_ERR(state->mrst);
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 63/77] media: imx: imx7_mipi_csis: Fix input size alignment
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (61 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 62/77] media: imx: imx7_mipi_csis: Acquire reset control without naming it Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 64/77] media: imx: imx7_mipi_csis: Make source .s_power() optional Laurent Pinchart
                   ` (15 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The alignments given to the v4l_bound_align_image() are expressed in
bytes, while the function expects them to be expressed as a power of
two. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 36eabab22bfb..381eda94398a 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -831,25 +831,25 @@ static int mipi_csis_set_fmt(struct v4l2_subdev *mipi_sd,
 	 */
 	switch (csis_fmt->width % 8) {
 	case 0:
-		align = 1;
+		align = 0;
 		break;
 	case 4:
-		align = 2;
+		align = 1;
 		break;
 	case 2:
 	case 6:
-		align = 4;
+		align = 2;
 		break;
 	case 1:
 	case 3:
 	case 5:
 	case 7:
-		align = 8;
+		align = 3;
 		break;
 	}
 
 	v4l_bound_align_image(&fmt->width, 1, CSIS_MAX_PIX_WIDTH, align,
-			      &fmt->height, 1, CSIS_MAX_PIX_HEIGHT, 1, 0);
+			      &fmt->height, 1, CSIS_MAX_PIX_HEIGHT, 0, 0);
 
 	sdformat->format = *fmt;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 64/77] media: imx: imx7_mipi_csis: Make source .s_power() optional
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (62 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 63/77] media: imx: imx7_mipi_csis: Fix input size alignment Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 65/77] media: imx: imx7_mipi_csis: Avoid double get of wrap clock Laurent Pinchart
                   ` (14 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The .s_power() subdev operation is optional, don't error out when the
source doesn't implement it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 381eda94398a..c153a77c3784 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -627,7 +627,7 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 			return ret;
 		}
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
-		if (ret < 0)
+		if (ret < 0 && ret != -ENOIOCTLCMD)
 			return ret;
 	}
 
@@ -649,6 +649,8 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 	} else {
 		v4l2_subdev_call(state->src_sd, video, s_stream, 0);
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 0);
+		if (ret == -ENOIOCTLCMD)
+			ret = 0;
 		mipi_csis_stop_stream(state);
 		state->flags &= ~ST_STREAMING;
 		if (state->debug)
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 65/77] media: imx: imx7_mipi_csis: Avoid double get of wrap clock
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (63 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 64/77] media: imx: imx7_mipi_csis: Make source .s_power() optional Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 66/77] media: imx: imx7_mipi_csis: Drop 10-bit YUV support Laurent Pinchart
                   ` (13 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The wrap clock is retrieved with the other clocks using
devm_clk_bulk_get(), and retrieved independently with a specific
devm_clk_get() call. The latter isn't needed, replace it with usage of
the wrap clock from the bulk array.

As the wrap clock is mandatory, simplify its usage further by removing
conditionals.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 31 +++++++++++-----------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index c153a77c3784..816650c438aa 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -206,7 +206,17 @@ static const struct mipi_csis_event mipi_csis_events[] = {
 
 #define MIPI_CSIS_NUM_EVENTS ARRAY_SIZE(mipi_csis_events)
 
-static const char * const mipi_csis_clk_id[] = {"pclk", "wrap", "phy"};
+enum mipi_csis_clk {
+	MIPI_CSIS_CLK_PCLK,
+	MIPI_CSIS_CLK_WRAP,
+	MIPI_CSIS_CLK_PHY,
+};
+
+static const char * const mipi_csis_clk_id[] = {
+	"pclk",
+	"wrap",
+	"phy",
+};
 
 struct csis_hw_reset {
 	struct regmap *src;
@@ -229,7 +239,6 @@ struct csi_state {
 	struct platform_device *pdev;
 	struct phy *phy;
 	void __iomem *regs;
-	struct clk *wrap_clk;
 	int irq;
 	u32 flags;
 
@@ -507,12 +516,7 @@ static void mipi_csis_set_params(struct csi_state *state)
 	mipi_csis_write(state, MIPI_CSIS_ISPSYNC_CH0, val);
 
 	val = mipi_csis_read(state, MIPI_CSIS_CLK_CTRL);
-	val &= ~MIPI_CSIS_CLK_CTRL_WCLK_SRC;
-	if (state->wrap_clk)
-		val |= MIPI_CSIS_CLK_CTRL_WCLK_SRC;
-	else
-		val &= ~MIPI_CSIS_CLK_CTRL_WCLK_SRC;
-
+	val |= MIPI_CSIS_CLK_CTRL_WCLK_SRC;
 	val |= MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL_CH0(15);
 	val &= ~MIPI_CSIS_CLK_CTRL_CLKGATE_EN_MSK;
 	mipi_csis_write(state, MIPI_CSIS_CLK_CTRL, val);
@@ -557,12 +561,9 @@ static int mipi_csis_clk_get(struct csi_state *state)
 	if (ret < 0)
 		return ret;
 
-	state->wrap_clk = devm_clk_get(dev, "wrap");
-	if (IS_ERR(state->wrap_clk))
-		return PTR_ERR(state->wrap_clk);
-
 	/* Set clock rate */
-	ret = clk_set_rate(state->wrap_clk, state->clk_frequency);
+	ret = clk_set_rate(state->clks[MIPI_CSIS_CLK_WRAP].clk,
+			   state->clk_frequency);
 	if (ret < 0)
 		dev_err(dev, "set rate=%d failed: %d\n", state->clk_frequency,
 			ret);
@@ -1149,9 +1150,9 @@ static int mipi_csis_probe(struct platform_device *pdev)
 			goto unregister_all;
 	}
 
-	dev_info(&pdev->dev, "lanes: %d, hs_settle: %d, wclk: %d, freq: %u\n",
+	dev_info(&pdev->dev, "lanes: %d, hs_settle: %d, freq: %u\n",
 		 state->bus.num_data_lanes, state->hs_settle,
-		 state->wrap_clk ? 1 : 0, state->clk_frequency);
+		 state->clk_frequency);
 
 	return 0;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 66/77] media: imx: imx7_mipi_csis: Drop 10-bit YUV support
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (64 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 65/77] media: imx: imx7_mipi_csis: Avoid double get of wrap clock Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 67/77] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format Laurent Pinchart
                   ` (12 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The data type specified for 10-bit YUV is the same as 8-bit YUV. This is
wrong, and has thus clearly not been tested. Instead of fixing data type
without being able to test it, drop it. It can be added back later when
someone will have access to a 10-bit YUV source to this it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 816650c438aa..e73efc7e99f9 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -276,10 +276,6 @@ static const struct csis_pix_format mipi_csis_formats[] = {
 		.code = MEDIA_BUS_FMT_UYVY8_2X8,
 		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
 		.width = 8,
-	}, {
-		.code = MEDIA_BUS_FMT_UYVY10_2X10,
-		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
-		.width = 10,
 	},
 	/* RAW (Bayer and greyscale) formats. */
 	{
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 67/77] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (65 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 66/77] media: imx: imx7_mipi_csis: Drop 10-bit YUV support Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 68/77] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle() Laurent Pinchart
                   ` (11 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

CSI-2 uses, as a convention, 1Xn media bus formats. Replace
MEDIA_BUS_FMT_UYVY8_2X8 with MEDIA_BUS_FMT_UYVY8_1X16, and set the width
value accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index e73efc7e99f9..a705797559dd 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -273,9 +273,9 @@ struct csis_pix_format {
 static const struct csis_pix_format mipi_csis_formats[] = {
 	/* YUV formats. */
 	{
-		.code = MEDIA_BUS_FMT_UYVY8_2X8,
+		.code = MEDIA_BUS_FMT_UYVY8_1X16,
 		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
-		.width = 8,
+		.width = 16,
 	},
 	/* RAW (Bayer and greyscale) formats. */
 	{
@@ -718,7 +718,7 @@ static int mipi_csis_init_cfg(struct v4l2_subdev *mipi_sd,
 	which = cfg ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
 	fmt_sink = mipi_csis_get_format(state, cfg, which, CSIS_PAD_SINK);
 
-	fmt_sink->code = MEDIA_BUS_FMT_UYVY8_2X8;
+	fmt_sink->code = MEDIA_BUS_FMT_UYVY8_1X16;
 	fmt_sink->width = MIPI_CSIS_DEF_PIX_WIDTH;
 	fmt_sink->height = MIPI_CSIS_DEF_PIX_HEIGHT;
 	fmt_sink->field = V4L2_FIELD_NONE;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 68/77] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (66 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 67/77] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 69/77] media: imx: imx7_mipi_csis: Move link setup check out of locked section Laurent Pinchart
                   ` (10 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The mipi_csis_set_hsync_settle() is small, called from a single place,
and misnamed (HS stands for high speed, not horizontal sync). Inline it
in its only caller, and refactor the HSSETTLE register field macros
while at it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index a705797559dd..a5f00983bd92 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -108,8 +108,8 @@
 
 /* D-PHY common control */
 #define MIPI_CSIS_DPHYCTRL			0x24
-#define MIPI_CSIS_DPHYCTRL_HSS_MASK		(0xff << 24)
-#define MIPI_CSIS_DPHYCTRL_HSS_OFFSET		24
+#define MIPI_CSIS_DPHYCTRL_HSSETTLE(n)		((n) << 24)
+#define MIPI_CSIS_DPHYCTRL_HSSETTLE_MASK	GENMASK(31, 24)
 #define MIPI_CSIS_DPHYCTRL_SCLKS_MASK		(0x3 << 22)
 #define MIPI_CSIS_DPHYCTRL_SCLKS_OFFSET		22
 #define MIPI_CSIS_DPHYCTRL_DPDN_SWAP_CLK	BIT(6)
@@ -482,15 +482,6 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH0, val);
 }
 
-static void mipi_csis_set_hsync_settle(struct csi_state *state, int hs_settle)
-{
-	u32 val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL);
-
-	val = (val & ~MIPI_CSIS_DPHYCTRL_HSS_MASK) | (hs_settle << 24);
-
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val);
-}
-
 static void mipi_csis_set_params(struct csi_state *state)
 {
 	int lanes = state->bus.num_data_lanes;
@@ -504,7 +495,10 @@ static void mipi_csis_set_params(struct csi_state *state)
 
 	__mipi_csis_set_format(state);
 
-	mipi_csis_set_hsync_settle(state, state->hs_settle);
+	val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL);
+	val = (val & ~MIPI_CSIS_DPHYCTRL_HSSETTLE_MASK)
+	    | MIPI_CSIS_DPHYCTRL_HSSETTLE(state->hs_settle);
+	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val);
 
 	val = (0 << MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET) |
 		(0 << MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET) |
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 69/77] media: imx: imx7_mipi_csis: Move link setup check out of locked section
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (67 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 68/77] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate Laurent Pinchart
                   ` (9 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Checking if the link setup operation is called for the sink or source
pad doesn't require any locking. Move it out of the section protected by
the mutex.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index a5f00983bd92..333ab3966b5b 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -668,20 +668,23 @@ static int mipi_csis_link_setup(struct media_entity *entity,
 	dev_dbg(state->dev, "link setup %s -> %s", remote_pad->entity->name,
 		local_pad->entity->name);
 
+	/* We only care about the link to the source. */
+	if (!(local_pad->flags & MEDIA_PAD_FL_SINK))
+		return 0;
+
 	remote_sd = media_entity_to_v4l2_subdev(remote_pad->entity);
 
 	mutex_lock(&state->lock);
 
-	if (local_pad->flags & MEDIA_PAD_FL_SINK) {
-		if (flags & MEDIA_LNK_FL_ENABLED) {
-			if (state->src_sd) {
-				ret = -EBUSY;
-				goto out;
-			}
-			state->src_sd = remote_sd;
-		} else {
-			state->src_sd = NULL;
+	if (flags & MEDIA_LNK_FL_ENABLED) {
+		if (state->src_sd) {
+			ret = -EBUSY;
+			goto out;
 		}
+
+		state->src_sd = remote_sd;
+	} else {
+		state->src_sd = NULL;
 	}
 
 out:
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (68 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 69/77] media: imx: imx7_mipi_csis: Move link setup check out of locked section Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01 16:40   ` [PATCH v2.1 " Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 71/77] media: imx: imx7_mipi_csis: Turn register access macros into functions Laurent Pinchart
                   ` (8 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The Ths_settle timing parameter depends solely on the lane data rate of
the source. Calculate it at runtime instead of requiring it to be
specified in the device tree.

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

- Unlock mutex in mipi_csis_link_setup() error path
- Use v4l2_get_link_freq()
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 43 ++++++++++++++++++++--
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 333ab3966b5b..4a51d2440b64 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -24,6 +24,7 @@
 #include <linux/reset.h>
 #include <linux/spinlock.h>
 
+#include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-mc.h>
@@ -482,6 +483,39 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH0, val);
 }
 
+static int mipi_csis_calculate_params(struct csi_state *state)
+{
+	s64 link_freq;
+	u32 lane_rate;
+
+	/* Calculate the line rate from the pixel rate. */
+	link_freq = v4l2_get_link_freq(state->src_sd->ctrl_handler,
+				       state->csis_fmt->width,
+				       state->bus.num_data_lanes * 2);
+	if (link_freq < 0) {
+		dev_err(state->dev, "Unable to obtain link frequency: %d\n",
+			(int)link_freq);
+		return link_freq;
+	}
+
+	lane_rate = link_freq * 2;
+
+	if (lane_rate < 80000000 || lane_rate > 1500000000) {
+		dev_dbg(state->dev, "Out-of-bound lane rate %u\n", lane_rate);
+		return -EINVAL;
+	}
+
+	/*
+	 * The HSSETTLE counter value is document in a table, but can also
+	 * easily be calculated.
+	 */
+	state->hs_settle = (lane_rate - 5000000) / 45000000;
+	dev_dbg(state->dev, "lane rate %u, Ths_settle %u\n",
+		lane_rate, state->hs_settle);
+
+	return 0;
+}
+
 static void mipi_csis_set_params(struct csi_state *state)
 {
 	int lanes = state->bus.num_data_lanes;
@@ -608,9 +642,13 @@ static void mipi_csis_log_counters(struct csi_state *state, bool non_errors)
 static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 {
 	struct csi_state *state = mipi_sd_to_csis_state(mipi_sd);
-	int ret = 0;
+	int ret;
 
 	if (enable) {
+		ret = mipi_csis_calculate_params(state);
+		if (ret < 0)
+			return ret;
+
 		mipi_csis_clear_counters(state);
 		ret = pm_runtime_get_sync(&state->pdev->dev);
 		if (ret < 0) {
@@ -943,9 +981,6 @@ static int mipi_csis_parse_dt(struct platform_device *pdev,
 	if (IS_ERR(state->mrst))
 		return PTR_ERR(state->mrst);
 
-	/* Get MIPI CSI-2 bus configuration from the endpoint node. */
-	of_property_read_u32(node, "fsl,csis-hs-settle", &state->hs_settle);
-
 	return 0;
 }
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 71/77] media: imx: imx7_mipi_csis: Turn register access macros into functions
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (69 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 72/77] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register Laurent Pinchart
                   ` (7 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Make it easier to instrument register access (for instance with
printk-based logging) by turning the macros into inline functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 4a51d2440b64..5e907ea46743 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -358,8 +358,15 @@ static const struct csis_pix_format mipi_csis_formats[] = {
 	}
 };
 
-#define mipi_csis_write(__csis, __r, __v) writel(__v, (__csis)->regs + (__r))
-#define mipi_csis_read(__csis, __r) readl((__csis)->regs + (__r))
+static inline void mipi_csis_write(struct csi_state *state, u32 reg, u32 val)
+{
+	writel(val, state->regs + reg);
+}
+
+static inline u32 mipi_csis_read(struct csi_state *state, u32 reg)
+{
+	return readl(state->regs + reg);
+}
 
 static int mipi_csis_dump_regs(struct csi_state *state)
 {
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 72/77] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (70 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 71/77] media: imx: imx7_mipi_csis: Turn register access macros into functions Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 73/77] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields Laurent Pinchart
                   ` (6 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

When setting the CSIS parameters, write the MIPI_CSIS_DPHYCTRL register
fully instead of modifying selected fields, as the register doesn't
contain any reserved fields that need to be preserved. This simplifies
initialization slightly, and ensures that the register value doesn't
depend on its previous state (before a warm reboot for instance).

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 5e907ea46743..26f323bff498 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -536,10 +536,8 @@ static void mipi_csis_set_params(struct csi_state *state)
 
 	__mipi_csis_set_format(state);
 
-	val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL);
-	val = (val & ~MIPI_CSIS_DPHYCTRL_HSSETTLE_MASK)
-	    | MIPI_CSIS_DPHYCTRL_HSSETTLE(state->hs_settle);
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val);
+	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL,
+			MIPI_CSIS_DPHYCTRL_HSSETTLE(state->hs_settle));
 
 	val = (0 << MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET) |
 		(0 << MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET) |
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 73/77] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (71 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 72/77] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 74/77] media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID Laurent Pinchart
                   ` (5 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Define macros for the fields of the MIPI_CSIS_DPHY_BCTRL_L register,
based on the i.MX8MM datasheet. The numerical value written to the
register, taken from the i.MX7D code, is unchanged, and corresponds to a
20.0MHz Tx escape clock frequency according to the documentation of the
register from the i.MX8MM. Whether the other fields are applicable to
the i.MX7D is unknown.

While at it, rename the DPHY[BS]CTRL register names to DPHY_[BS]CTRL to
match the datasheet.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 53 +++++++++++++++++++---
 1 file changed, 47 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 26f323bff498..f7dcadb4fab4 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -120,13 +120,47 @@
 #define MIPI_CSIS_DPHYCTRL_ENABLE		(0x1f << 0)
 
 /* D-PHY Master and Slave Control register Low */
-#define MIPI_CSIS_DPHYBCTRL_L			0x30
+#define MIPI_CSIS_DPHY_BCTRL_L			0x30
+#define MIPI_CSIS_DPHY_BCTRL_L_USER_DATA_PATTERN_LOW(n)		(((n) & 3U) << 30)
+#define MIPI_CSIS_DPHY_BCTRL_L_BIAS_REF_VOLT_715MV		(0 << 28)
+#define MIPI_CSIS_DPHY_BCTRL_L_BIAS_REF_VOLT_724MV		(1 << 28)
+#define MIPI_CSIS_DPHY_BCTRL_L_BIAS_REF_VOLT_733MV		(2 << 28)
+#define MIPI_CSIS_DPHY_BCTRL_L_BIAS_REF_VOLT_706MV		(3 << 28)
+#define MIPI_CSIS_DPHY_BCTRL_L_BGR_CHOPPER_FREQ_3MHZ		(0 << 27)
+#define MIPI_CSIS_DPHY_BCTRL_L_BGR_CHOPPER_FREQ_1_5MHZ		(1 << 27)
+#define MIPI_CSIS_DPHY_BCTRL_L_VREG12_EXTPWR_EN_CTL		BIT(26)
+#define MIPI_CSIS_DPHY_BCTRL_L_REG_12P_LVL_CTL_1_2V		(0 << 24)
+#define MIPI_CSIS_DPHY_BCTRL_L_REG_12P_LVL_CTL_1_23V		(1 << 24)
+#define MIPI_CSIS_DPHY_BCTRL_L_REG_12P_LVL_CTL_1_17V		(2 << 24)
+#define MIPI_CSIS_DPHY_BCTRL_L_REG_12P_LVL_CTL_1_26V		(3 << 24)
+#define MIPI_CSIS_DPHY_BCTRL_L_REG_1P2_LVL_SEL			BIT(23)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_HYS_LVL_80MV		(0 << 21)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_HYS_LVL_100MV		(1 << 21)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_HYS_LVL_120MV		(2 << 21)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_HYS_LVL_140MV		(3 << 21)
+#define MIPI_CSIS_DPHY_BCTRL_L_VREF_SRC_SEL			BIT(20)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_VREF_LVL_715MV		(0 << 18)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_VREF_LVL_743MV		(1 << 18)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_VREF_LVL_650MV		(2 << 18)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_VREF_LVL_682MV		(3 << 18)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_RX_PULSE_REJECT		BIT(17)
+#define MIPI_CSIS_DPHY_BCTRL_L_MSTRCLK_LP_SLEW_RATE_DOWN_0	(0 << 15)
+#define MIPI_CSIS_DPHY_BCTRL_L_MSTRCLK_LP_SLEW_RATE_DOWN_15P	(1 << 15)
+#define MIPI_CSIS_DPHY_BCTRL_L_MSTRCLK_LP_SLEW_RATE_DOWN_30P	(3 << 15)
+#define MIPI_CSIS_DPHY_BCTRL_L_MSTRCLK_LP_SLEW_RATE_UP		BIT(14)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_CD_HYS_60MV			(0 << 13)
+#define MIPI_CSIS_DPHY_BCTRL_L_LP_CD_HYS_70MV			(1 << 13)
+#define MIPI_CSIS_DPHY_BCTRL_L_BGR_CHOPPER_EN			BIT(12)
+#define MIPI_CSIS_DPHY_BCTRL_L_ERRCONTENTION_LP_EN		BIT(11)
+#define MIPI_CSIS_DPHY_BCTRL_L_TXTRIGGER_CLK_EN			BIT(10)
+#define MIPI_CSIS_DPHY_BCTRL_L_B_DPHYCTRL(n)			(((n) * 25 / 1000000) << 0)
+
 /* D-PHY Master and Slave Control register High */
-#define MIPI_CSIS_DPHYBCTRL_H			0x34
+#define MIPI_CSIS_DPHY_BCTRL_H			0x34
 /* D-PHY Slave Control register Low */
-#define MIPI_CSIS_DPHYSCTRL_L			0x38
+#define MIPI_CSIS_DPHY_SCTRL_L			0x38
 /* D-PHY Slave Control register High */
-#define MIPI_CSIS_DPHYSCTRL_H			0x3c
+#define MIPI_CSIS_DPHY_SCTRL_H			0x3c
 
 /* ISP Configuration register */
 #define MIPI_CSIS_ISPCONFIG_CH0			0x40
@@ -550,8 +584,15 @@ static void mipi_csis_set_params(struct csi_state *state)
 	val &= ~MIPI_CSIS_CLK_CTRL_CLKGATE_EN_MSK;
 	mipi_csis_write(state, MIPI_CSIS_CLK_CTRL, val);
 
-	mipi_csis_write(state, MIPI_CSIS_DPHYBCTRL_L, 0x1f4);
-	mipi_csis_write(state, MIPI_CSIS_DPHYBCTRL_H, 0);
+	mipi_csis_write(state, MIPI_CSIS_DPHY_BCTRL_L,
+			MIPI_CSIS_DPHY_BCTRL_L_BIAS_REF_VOLT_715MV |
+			MIPI_CSIS_DPHY_BCTRL_L_BGR_CHOPPER_FREQ_3MHZ |
+			MIPI_CSIS_DPHY_BCTRL_L_REG_12P_LVL_CTL_1_2V |
+			MIPI_CSIS_DPHY_BCTRL_L_LP_RX_HYS_LVL_80MV |
+			MIPI_CSIS_DPHY_BCTRL_L_LP_RX_VREF_LVL_715MV |
+			MIPI_CSIS_DPHY_BCTRL_L_LP_CD_HYS_60MV |
+			MIPI_CSIS_DPHY_BCTRL_L_B_DPHYCTRL(20000000));
+	mipi_csis_write(state, MIPI_CSIS_DPHY_BCTRL_H, 0);
 
 	/* Update the shadow register. */
 	val = mipi_csis_read(state, MIPI_CSIS_CMN_CTRL);
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 74/77] media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (72 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 73/77] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet Laurent Pinchart
                   ` (4 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Replace the per-channel ISP registers macros with a single one that take
the channel as a parameter. Only channel 0 is supported for now, but
this will make support for multiple channels easier.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 26 ++++++----------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index f7dcadb4fab4..b93a176aa007 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -163,11 +163,7 @@
 #define MIPI_CSIS_DPHY_SCTRL_H			0x3c
 
 /* ISP Configuration register */
-#define MIPI_CSIS_ISPCONFIG_CH0			0x40
-#define MIPI_CSIS_ISPCONFIG_CH1			0x50
-#define MIPI_CSIS_ISPCONFIG_CH2			0x60
-#define MIPI_CSIS_ISPCONFIG_CH3			0x70
-
+#define MIPI_CSIS_ISPCONFIG_CH(n)		(0x40 + (n) * 0x10)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP_MSK	(0xff << 24)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP(x)	((x) << 24)
 #define MIPI_CSIS_ISPCFG_DOUBLE_CMPNT		BIT(12)
@@ -177,25 +173,17 @@
 #define MIPI_CSIS_ISPCFG_FMT_RAW10		(0x2b << 2)
 #define MIPI_CSIS_ISPCFG_FMT_RAW12		(0x2c << 2)
 #define MIPI_CSIS_ISPCFG_FMT_RAW14		(0x2d << 2)
-
 /* User defined formats, x = 1...4 */
 #define MIPI_CSIS_ISPCFG_FMT_USER(x)		((0x30 + (x) - 1) << 2)
 #define MIPI_CSIS_ISPCFG_FMT_MASK		(0x3f << 2)
 
 /* ISP Image Resolution register */
-#define MIPI_CSIS_ISPRESOL_CH0			0x44
-#define MIPI_CSIS_ISPRESOL_CH1			0x54
-#define MIPI_CSIS_ISPRESOL_CH2			0x64
-#define MIPI_CSIS_ISPRESOL_CH3			0x74
+#define MIPI_CSIS_ISPRESOL_CH(n)		(0x44 + (n) * 0x10)
 #define CSIS_MAX_PIX_WIDTH			0xffff
 #define CSIS_MAX_PIX_HEIGHT			0xffff
 
 /* ISP SYNC register */
-#define MIPI_CSIS_ISPSYNC_CH0			0x48
-#define MIPI_CSIS_ISPSYNC_CH1			0x58
-#define MIPI_CSIS_ISPSYNC_CH2			0x68
-#define MIPI_CSIS_ISPSYNC_CH3			0x78
-
+#define MIPI_CSIS_ISPSYNC_CH(n)			(0x48 + (n) * 0x10)
 #define MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET	18
 #define MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET	12
 #define MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET	0
@@ -514,14 +502,14 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	u32 val;
 
 	/* Color format */
-	val = mipi_csis_read(state, MIPI_CSIS_ISPCONFIG_CH0);
+	val = mipi_csis_read(state, MIPI_CSIS_ISPCONFIG_CH(0));
 	val &= ~(MIPI_CSIS_ISPCFG_ALIGN_32BIT | MIPI_CSIS_ISPCFG_FMT_MASK);
 	val |= state->csis_fmt->fmt_reg;
-	mipi_csis_write(state, MIPI_CSIS_ISPCONFIG_CH0, val);
+	mipi_csis_write(state, MIPI_CSIS_ISPCONFIG_CH(0), val);
 
 	/* Pixel resolution */
 	val = mf->width | (mf->height << 16);
-	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH0, val);
+	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH(0), val);
 }
 
 static int mipi_csis_calculate_params(struct csi_state *state)
@@ -576,7 +564,7 @@ static void mipi_csis_set_params(struct csi_state *state)
 	val = (0 << MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET) |
 		(0 << MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET) |
 		(0 << MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET);
-	mipi_csis_write(state, MIPI_CSIS_ISPSYNC_CH0, val);
+	mipi_csis_write(state, MIPI_CSIS_ISPSYNC_CH(0), val);
 
 	val = mipi_csis_read(state, MIPI_CSIS_CLK_CTRL);
 	val |= MIPI_CSIS_CLK_CTRL_WCLK_SRC;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (73 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 74/77] media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-01 16:41   ` [PATCH v2.1 " Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 76/77] media: imx: imx7_mipi_csis: Use register macros in mipi_csis_dump_regs() Laurent Pinchart
                   ` (3 subsequent siblings)
  78 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Rename several register macros to match the names from the
documentation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 172 ++++++++++-----------
 1 file changed, 86 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index b93a176aa007..aaf66ec630eb 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -63,61 +63,61 @@
 #define MIPI_CSIS_CLK_CTRL_WCLK_SRC		BIT(0)
 
 /* CSIS Interrupt mask */
-#define MIPI_CSIS_INTMSK			0x10
-#define MIPI_CSIS_INTMSK_EVEN_BEFORE		BIT(31)
-#define MIPI_CSIS_INTMSK_EVEN_AFTER		BIT(30)
-#define MIPI_CSIS_INTMSK_ODD_BEFORE		BIT(29)
-#define MIPI_CSIS_INTMSK_ODD_AFTER		BIT(28)
-#define MIPI_CSIS_INTMSK_FRAME_START		BIT(24)
-#define MIPI_CSIS_INTMSK_FRAME_END		BIT(20)
-#define MIPI_CSIS_INTMSK_ERR_SOT_HS		BIT(16)
-#define MIPI_CSIS_INTMSK_ERR_LOST_FS		BIT(12)
-#define MIPI_CSIS_INTMSK_ERR_LOST_FE		BIT(8)
-#define MIPI_CSIS_INTMSK_ERR_OVER		BIT(4)
-#define MIPI_CSIS_INTMSK_ERR_WRONG_CFG		BIT(3)
-#define MIPI_CSIS_INTMSK_ERR_ECC		BIT(2)
-#define MIPI_CSIS_INTMSK_ERR_CRC		BIT(1)
-#define MIPI_CSIS_INTMSK_ERR_UNKNOWN		BIT(0)
+#define MIPI_CSIS_INT_MSK			0x10
+#define MIPI_CSIS_INT_MSK_EVEN_BEFORE		BIT(31)
+#define MIPI_CSIS_INT_MSK_EVEN_AFTER		BIT(30)
+#define MIPI_CSIS_INT_MSK_ODD_BEFORE		BIT(29)
+#define MIPI_CSIS_INT_MSK_ODD_AFTER		BIT(28)
+#define MIPI_CSIS_INT_MSK_FRAME_START		BIT(24)
+#define MIPI_CSIS_INT_MSK_FRAME_END		BIT(20)
+#define MIPI_CSIS_INT_MSK_ERR_SOT_HS		BIT(16)
+#define MIPI_CSIS_INT_MSK_ERR_LOST_FS		BIT(12)
+#define MIPI_CSIS_INT_MSK_ERR_LOST_FE		BIT(8)
+#define MIPI_CSIS_INT_MSK_ERR_OVER		BIT(4)
+#define MIPI_CSIS_INT_MSK_ERR_WRONG_CFG		BIT(3)
+#define MIPI_CSIS_INT_MSK_ERR_ECC		BIT(2)
+#define MIPI_CSIS_INT_MSK_ERR_CRC		BIT(1)
+#define MIPI_CSIS_INT_MSK_ERR_UNKNOWN		BIT(0)
 
 /* CSIS Interrupt source */
-#define MIPI_CSIS_INTSRC			0x14
-#define MIPI_CSIS_INTSRC_EVEN_BEFORE		BIT(31)
-#define MIPI_CSIS_INTSRC_EVEN_AFTER		BIT(30)
-#define MIPI_CSIS_INTSRC_EVEN			BIT(30)
-#define MIPI_CSIS_INTSRC_ODD_BEFORE		BIT(29)
-#define MIPI_CSIS_INTSRC_ODD_AFTER		BIT(28)
-#define MIPI_CSIS_INTSRC_ODD			(0x3 << 28)
-#define MIPI_CSIS_INTSRC_NON_IMAGE_DATA		(0xf << 28)
-#define MIPI_CSIS_INTSRC_FRAME_START		BIT(24)
-#define MIPI_CSIS_INTSRC_FRAME_END		BIT(20)
-#define MIPI_CSIS_INTSRC_ERR_SOT_HS		BIT(16)
-#define MIPI_CSIS_INTSRC_ERR_LOST_FS		BIT(12)
-#define MIPI_CSIS_INTSRC_ERR_LOST_FE		BIT(8)
-#define MIPI_CSIS_INTSRC_ERR_OVER		BIT(4)
-#define MIPI_CSIS_INTSRC_ERR_WRONG_CFG		BIT(3)
-#define MIPI_CSIS_INTSRC_ERR_ECC		BIT(2)
-#define MIPI_CSIS_INTSRC_ERR_CRC		BIT(1)
-#define MIPI_CSIS_INTSRC_ERR_UNKNOWN		BIT(0)
-#define MIPI_CSIS_INTSRC_ERRORS			0xfffff
+#define MIPI_CSIS_INT_SRC			0x14
+#define MIPI_CSIS_INT_SRC_EVEN_BEFORE		BIT(31)
+#define MIPI_CSIS_INT_SRC_EVEN_AFTER		BIT(30)
+#define MIPI_CSIS_INT_SRC_EVEN			BIT(30)
+#define MIPI_CSIS_INT_SRC_ODD_BEFORE		BIT(29)
+#define MIPI_CSIS_INT_SRC_ODD_AFTER		BIT(28)
+#define MIPI_CSIS_INT_SRC_ODD			(0x3 << 28)
+#define MIPI_CSIS_INT_SRC_NON_IMAGE_DATA		(0xf << 28)
+#define MIPI_CSIS_INT_SRC_FRAME_START		BIT(24)
+#define MIPI_CSIS_INT_SRC_FRAME_END		BIT(20)
+#define MIPI_CSIS_INT_SRC_ERR_SOT_HS		BIT(16)
+#define MIPI_CSIS_INT_SRC_ERR_LOST_FS		BIT(12)
+#define MIPI_CSIS_INT_SRC_ERR_LOST_FE		BIT(8)
+#define MIPI_CSIS_INT_SRC_ERR_OVER		BIT(4)
+#define MIPI_CSIS_INT_SRC_ERR_WRONG_CFG		BIT(3)
+#define MIPI_CSIS_INT_SRC_ERR_ECC		BIT(2)
+#define MIPI_CSIS_INT_SRC_ERR_CRC		BIT(1)
+#define MIPI_CSIS_INT_SRC_ERR_UNKNOWN		BIT(0)
+#define MIPI_CSIS_INT_SRC_ERRORS		0xfffff
 
 /* D-PHY status control */
-#define MIPI_CSIS_DPHYSTATUS			0x20
-#define MIPI_CSIS_DPHYSTATUS_ULPS_DAT		BIT(8)
-#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_DAT	BIT(4)
-#define MIPI_CSIS_DPHYSTATUS_ULPS_CLK		BIT(1)
-#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_CLK	BIT(0)
+#define MIPI_CSIS_DPHY_STATUS			0x20
+#define MIPI_CSIS_DPHY_STATUS_ULPS_DAT		BIT(8)
+#define MIPI_CSIS_DPHY_STATUS_STOPSTATE_DAT	BIT(4)
+#define MIPI_CSIS_DPHY_STATUS_ULPS_CLK		BIT(1)
+#define MIPI_CSIS_DPHY_STATUS_STOPSTATE_CLK	BIT(0)
 
 /* D-PHY common control */
-#define MIPI_CSIS_DPHYCTRL			0x24
-#define MIPI_CSIS_DPHYCTRL_HSSETTLE(n)		((n) << 24)
-#define MIPI_CSIS_DPHYCTRL_HSSETTLE_MASK	GENMASK(31, 24)
-#define MIPI_CSIS_DPHYCTRL_SCLKS_MASK		(0x3 << 22)
-#define MIPI_CSIS_DPHYCTRL_SCLKS_OFFSET		22
-#define MIPI_CSIS_DPHYCTRL_DPDN_SWAP_CLK	BIT(6)
-#define MIPI_CSIS_DPHYCTRL_DPDN_SWAP_DAT	BIT(5)
-#define MIPI_CSIS_DPHYCTRL_ENABLE_DAT		BIT(1)
-#define MIPI_CSIS_DPHYCTRL_ENABLE_CLK		BIT(0)
-#define MIPI_CSIS_DPHYCTRL_ENABLE		(0x1f << 0)
+#define MIPI_CSIS_DPHY_CMN_CTRL			0x24
+#define MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE(n)	((n) << 24)
+#define MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE_MASK	GENMASK(31, 24)
+#define MIPI_CSIS_DPHY_CMN_CTRL_SCLKS_MASK	(0x3 << 22)
+#define MIPI_CSIS_DPHY_CMN_CTRL_SCLKS_OFFSET	22
+#define MIPI_CSIS_DPHY_CMN_CTRL_DPDN_SWAP_CLK	BIT(6)
+#define MIPI_CSIS_DPHY_CMN_CTRL_DPDN_SWAP_DAT	BIT(5)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE_DAT	BIT(1)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE_CLK	BIT(0)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE		(0x1f << 0)
 
 /* D-PHY Master and Slave Control register Low */
 #define MIPI_CSIS_DPHY_BCTRL_L			0x30
@@ -163,7 +163,7 @@
 #define MIPI_CSIS_DPHY_SCTRL_H			0x3c
 
 /* ISP Configuration register */
-#define MIPI_CSIS_ISPCONFIG_CH(n)		(0x40 + (n) * 0x10)
+#define MIPI_CSIS_ISP_CONFIG_CH(n)		(0x40 + (n) * 0x10)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP_MSK	(0xff << 24)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP(x)	((x) << 24)
 #define MIPI_CSIS_ISPCFG_DOUBLE_CMPNT		BIT(12)
@@ -178,15 +178,15 @@
 #define MIPI_CSIS_ISPCFG_FMT_MASK		(0x3f << 2)
 
 /* ISP Image Resolution register */
-#define MIPI_CSIS_ISPRESOL_CH(n)		(0x44 + (n) * 0x10)
+#define MIPI_CSIS_ISP_RESOL_CH(n)		(0x44 + (n) * 0x10)
 #define CSIS_MAX_PIX_WIDTH			0xffff
 #define CSIS_MAX_PIX_HEIGHT			0xffff
 
 /* ISP SYNC register */
-#define MIPI_CSIS_ISPSYNC_CH(n)			(0x48 + (n) * 0x10)
-#define MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET	18
-#define MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET	12
-#define MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET	0
+#define MIPI_CSIS_ISP_SYNC_CH(n)		(0x48 + (n) * 0x10)
+#define MIPI_CSIS_ISP_SYNC_HSYNC_LINTV_OFFSET	18
+#define MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET	12
+#define MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET	0
 
 /* Non-image packet data buffers */
 #define MIPI_CSIS_PKTDATA_ODD			0x2000
@@ -209,22 +209,22 @@ struct mipi_csis_event {
 
 static const struct mipi_csis_event mipi_csis_events[] = {
 	/* Errors */
-	{ MIPI_CSIS_INTSRC_ERR_SOT_HS,	"SOT Error" },
-	{ MIPI_CSIS_INTSRC_ERR_LOST_FS,	"Lost Frame Start Error" },
-	{ MIPI_CSIS_INTSRC_ERR_LOST_FE,	"Lost Frame End Error" },
-	{ MIPI_CSIS_INTSRC_ERR_OVER,	"FIFO Overflow Error" },
-	{ MIPI_CSIS_INTSRC_ERR_WRONG_CFG, "Wrong Configuration Error" },
-	{ MIPI_CSIS_INTSRC_ERR_ECC,	"ECC Error" },
-	{ MIPI_CSIS_INTSRC_ERR_CRC,	"CRC Error" },
-	{ MIPI_CSIS_INTSRC_ERR_UNKNOWN,	"Unknown Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_SOT_HS,		"SOT Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_LOST_FS,	"Lost Frame Start Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_LOST_FE,	"Lost Frame End Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_OVER,		"FIFO Overflow Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_WRONG_CFG,	"Wrong Configuration Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_ECC,		"ECC Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_CRC,		"CRC Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_UNKNOWN,	"Unknown Error" },
 	/* Non-image data receive events */
-	{ MIPI_CSIS_INTSRC_EVEN_BEFORE,	"Non-image data before even frame" },
-	{ MIPI_CSIS_INTSRC_EVEN_AFTER,	"Non-image data after even frame" },
-	{ MIPI_CSIS_INTSRC_ODD_BEFORE,	"Non-image data before odd frame" },
-	{ MIPI_CSIS_INTSRC_ODD_AFTER,	"Non-image data after odd frame" },
+	{ MIPI_CSIS_INT_SRC_EVEN_BEFORE,	"Non-image data before even frame" },
+	{ MIPI_CSIS_INT_SRC_EVEN_AFTER,		"Non-image data after even frame" },
+	{ MIPI_CSIS_INT_SRC_ODD_BEFORE,		"Non-image data before odd frame" },
+	{ MIPI_CSIS_INT_SRC_ODD_AFTER,		"Non-image data after odd frame" },
 	/* Frame start/end */
-	{ MIPI_CSIS_INTSRC_FRAME_START,	"Frame Start" },
-	{ MIPI_CSIS_INTSRC_FRAME_END,	"Frame End" },
+	{ MIPI_CSIS_INT_SRC_FRAME_START,	"Frame Start" },
+	{ MIPI_CSIS_INT_SRC_FRAME_END,		"Frame End" },
 };
 
 #define MIPI_CSIS_NUM_EVENTS ARRAY_SIZE(mipi_csis_events)
@@ -444,7 +444,7 @@ static const struct csis_pix_format *find_csis_format(u32 code)
 
 static void mipi_csis_enable_interrupts(struct csi_state *state, bool on)
 {
-	mipi_csis_write(state, MIPI_CSIS_INTMSK, on ? 0xffffffff : 0);
+	mipi_csis_write(state, MIPI_CSIS_INT_MSK, on ? 0xffffffff : 0);
 }
 
 static void mipi_csis_sw_reset(struct csi_state *state)
@@ -486,13 +486,13 @@ static void mipi_csis_system_enable(struct csi_state *state, int on)
 		val &= ~MIPI_CSIS_CMN_CTRL_ENABLE;
 	mipi_csis_write(state, MIPI_CSIS_CMN_CTRL, val);
 
-	val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL);
-	val &= ~MIPI_CSIS_DPHYCTRL_ENABLE;
+	val = mipi_csis_read(state, MIPI_CSIS_DPHY_CMN_CTRL);
+	val &= ~MIPI_CSIS_DPHY_CMN_CTRL_ENABLE;
 	if (on) {
 		mask = (1 << (state->bus.num_data_lanes + 1)) - 1;
-		val |= (mask & MIPI_CSIS_DPHYCTRL_ENABLE);
+		val |= (mask & MIPI_CSIS_DPHY_CMN_CTRL_ENABLE);
 	}
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val);
+	mipi_csis_write(state, MIPI_CSIS_DPHY_CMN_CTRL, val);
 }
 
 /* Called with the state.lock mutex held */
@@ -502,14 +502,14 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	u32 val;
 
 	/* Color format */
-	val = mipi_csis_read(state, MIPI_CSIS_ISPCONFIG_CH(0));
+	val = mipi_csis_read(state, MIPI_CSIS_ISP_CONFIG_CH(0));
 	val &= ~(MIPI_CSIS_ISPCFG_ALIGN_32BIT | MIPI_CSIS_ISPCFG_FMT_MASK);
 	val |= state->csis_fmt->fmt_reg;
-	mipi_csis_write(state, MIPI_CSIS_ISPCONFIG_CH(0), val);
+	mipi_csis_write(state, MIPI_CSIS_ISP_CONFIG_CH(0), val);
 
 	/* Pixel resolution */
 	val = mf->width | (mf->height << 16);
-	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH(0), val);
+	mipi_csis_write(state, MIPI_CSIS_ISP_RESOL_CH(0), val);
 }
 
 static int mipi_csis_calculate_params(struct csi_state *state)
@@ -558,13 +558,13 @@ static void mipi_csis_set_params(struct csi_state *state)
 
 	__mipi_csis_set_format(state);
 
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL,
-			MIPI_CSIS_DPHYCTRL_HSSETTLE(state->hs_settle));
+	mipi_csis_write(state, MIPI_CSIS_DPHY_CMN_CTRL,
+			MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE(state->hs_settle));
 
-	val = (0 << MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET) |
-		(0 << MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET) |
-		(0 << MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET);
-	mipi_csis_write(state, MIPI_CSIS_ISPSYNC_CH(0), val);
+	val = (0 << MIPI_CSIS_ISP_SYNC_HSYNC_LINTV_OFFSET)
+	    | (0 << MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET)
+	    | (0 << MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET);
+	mipi_csis_write(state, MIPI_CSIS_ISP_SYNC_CH(0), val);
 
 	val = mipi_csis_read(state, MIPI_CSIS_CLK_CTRL);
 	val |= MIPI_CSIS_CLK_CTRL_WCLK_SRC;
@@ -955,12 +955,12 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id)
 	unsigned int i;
 	u32 status;
 
-	status = mipi_csis_read(state, MIPI_CSIS_INTSRC);
+	status = mipi_csis_read(state, MIPI_CSIS_INT_SRC);
 
 	spin_lock_irqsave(&state->slock, flags);
 
 	/* Update the event/error counters */
-	if ((status & MIPI_CSIS_INTSRC_ERRORS) || state->debug) {
+	if ((status & MIPI_CSIS_INT_SRC_ERRORS) || state->debug) {
 		for (i = 0; i < MIPI_CSIS_NUM_EVENTS; i++) {
 			if (!(status & state->events[i].mask))
 				continue;
@@ -969,7 +969,7 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id)
 	}
 	spin_unlock_irqrestore(&state->slock, flags);
 
-	mipi_csis_write(state, MIPI_CSIS_INTSRC, status);
+	mipi_csis_write(state, MIPI_CSIS_INT_SRC, status);
 
 	return IRQ_HANDLED;
 }
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 76/77] media: imx: imx7_mipi_csis: Use register macros in mipi_csis_dump_regs()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (74 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-02-15  4:27 ` [PATCH v2 77/77] media: imx: imx7_mipi_csis: Print shadow registers " Laurent Pinchart
                   ` (2 subsequent siblings)
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Replace hardcoded register addresses in the MIPI_CSIS_DBG_CTRL()
function with macros. While at it, update the printed name of the
registers to match the datasheet, and short them by address.

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

- Define MIPI_CSIS_DBG_CTRL
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 25 ++++++++++++----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index aaf66ec630eb..6bf8f0daae94 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -188,6 +188,9 @@
 #define MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET	12
 #define MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET	0
 
+/* Debug control register */
+#define MIPI_CSIS_DBG_CTRL			0xc0
+
 /* Non-image packet data buffers */
 #define MIPI_CSIS_PKTDATA_ODD			0x2000
 #define MIPI_CSIS_PKTDATA_EVEN			0x3000
@@ -399,23 +402,23 @@ static int mipi_csis_dump_regs(struct csi_state *state)
 		u32 offset;
 		const char * const name;
 	} registers[] = {
-		{ 0x04, "CTRL" },
-		{ 0x24, "DPHYCTRL" },
-		{ 0x08, "CLKCTRL" },
-		{ 0x20, "DPHYSTS" },
-		{ 0x10, "INTMSK" },
-		{ 0x40, "CONFIG_CH0" },
-		{ 0x44, "RESOL_CH0" },
-		{ 0xC0, "DBG_CONFIG" },
-		{ 0x38, "DPHYSLAVE_L" },
-		{ 0x3C, "DPHYSLAVE_H" },
+		{ MIPI_CSIS_CMN_CTRL, "CMN_CTRL" },
+		{ MIPI_CSIS_CLK_CTRL, "CLK_CTRL" },
+		{ MIPI_CSIS_INT_MSK, "INT_MSK" },
+		{ MIPI_CSIS_DPHY_STATUS, "DPHY_STATUS" },
+		{ MIPI_CSIS_DPHY_CMN_CTRL, "DPHY_CMN_CTRL" },
+		{ MIPI_CSIS_DPHY_SCTRL_L, "DPHY_SCTRL_L" },
+		{ MIPI_CSIS_DPHY_SCTRL_H, "DPHY_SCTRL_H" },
+		{ MIPI_CSIS_ISP_CONFIG_CH(0), "ISP_CONFIG_CH0" },
+		{ MIPI_CSIS_ISP_RESOL_CH(0), "ISP_RESOL_CH0" },
+		{ MIPI_CSIS_DBG_CTRL, "DBG_CTRL" },
 	};
 
 	dev_info(dev, "--- REGISTERS ---\n");
 
 	for (i = 0; i < ARRAY_SIZE(registers); i++) {
 		cfg = mipi_csis_read(state, registers[i].offset);
-		dev_info(dev, "%12s: 0x%08x\n", registers[i].name, cfg);
+		dev_info(dev, "%14s: 0x%08x\n", registers[i].name, cfg);
 	}
 
 	return 0;
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2 77/77] media: imx: imx7_mipi_csis: Print shadow registers in mipi_csis_dump_regs()
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (75 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 76/77] media: imx: imx7_mipi_csis: Use register macros in mipi_csis_dump_regs() Laurent Pinchart
@ 2021-02-15  4:27 ` Laurent Pinchart
  2021-03-16 11:56 ` [PATCH] imx7-media-csi: csi2 only Martin Kepplinger
  2021-03-17 18:04 ` [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Frieder Schrempf
  78 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-15  4:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Print the value of the ISP shadow registers in mipi_csis_dump_regs() as
this can help debugging.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 6bf8f0daae94..ea84698f4718 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -188,6 +188,11 @@
 #define MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET	12
 #define MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET	0
 
+/* ISP shadow registers */
+#define MIPI_CSIS_SDW_CONFIG_CH(n)		(0x80 + (n) * 0x10)
+#define MIPI_CSIS_SDW_RESOL_CH(n)		(0x84 + (n) * 0x10)
+#define MIPI_CSIS_SDW_SYNC_CH(n)		(0x88 + (n) * 0x10)
+
 /* Debug control register */
 #define MIPI_CSIS_DBG_CTRL			0xc0
 
@@ -411,6 +416,8 @@ static int mipi_csis_dump_regs(struct csi_state *state)
 		{ MIPI_CSIS_DPHY_SCTRL_H, "DPHY_SCTRL_H" },
 		{ MIPI_CSIS_ISP_CONFIG_CH(0), "ISP_CONFIG_CH0" },
 		{ MIPI_CSIS_ISP_RESOL_CH(0), "ISP_RESOL_CH0" },
+		{ MIPI_CSIS_SDW_CONFIG_CH(0), "SDW_CONFIG_CH0" },
+		{ MIPI_CSIS_SDW_RESOL_CH(0), "SDW_RESOL_CH0" },
 		{ MIPI_CSIS_DBG_CTRL, "DBG_CTRL" },
 	};
 
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-02-15  4:26 ` [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
@ 2021-02-26 15:45   ` Laurent Pinchart
  0 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-02-26 15:45 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Please ignore this patch, it's a rebase leftover and isn't useful.

Reviews for the rest of the series, however, would be nice ;-)

On Mon, Feb 15, 2021 at 06:26:28AM +0200, Laurent Pinchart wrote:
> imx6-media-objs contains a set of objects that are specific to the i.MX6
> IPU-based media subsystem. They're not needed for the i.MX7 CSI. Only
> compile them if CONFIG_VIDEO_IMX_CSI is selected.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> ---
>  drivers/staging/media/imx/Makefile | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
> index 69cc5da04a2e..6ac33275cc97 100644
> --- a/drivers/staging/media/imx/Makefile
> +++ b/drivers/staging/media/imx/Makefile
> @@ -1,11 +1,11 @@
>  # SPDX-License-Identifier: GPL-2.0
> +imx-media-common-objs := imx-media-capture.o imx-media-dev-common.o \
> +	imx-media-of.o imx-media-utils.o
> +
>  imx6-media-objs := imx-media-dev.o imx-media-internal-sd.o \
>  	imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o imx-media-vdic.o \
>  	imx-media-csc-scaler.o
>  
> -imx-media-common-objs := imx-media-capture.o imx-media-dev-common.o \
> -	imx-media-of.o imx-media-utils.o
> -
>  imx6-media-csi-objs := imx-media-csi.o imx-media-fim.o
>  
>  obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification
  2021-02-15  4:27 ` [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification Laurent Pinchart
@ 2021-03-01  9:30   ` Rui Miguel Silva
  0 siblings, 0 replies; 100+ messages in thread
From: Rui Miguel Silva @ 2021-03-01  9:30 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia,
	Fabio Estevam

Hi Laurent,
Thanks for the patch.

On Mon, Feb 15, 2021 at 06:27:02AM +0200, Laurent Pinchart wrote:
> The code in imx7_csi_pad_link_validate() that checks the type of the
> source incorrectly handles devices that have no parallel input. In that
> case, the source entity of the CSI is the CSI-2 receiver, not the video
> mux, and the driver will proceed to check the type of the source of the
> CSI-2 receiver.
> 
> Make the code more explicit to fix this, by handling the three cases
> (parallel input only, CSI-2 receiver only, and video mux) separately.
> 
> Note that the driver will not correctly handle the case where only a
> parallel input is present, and the external entity connected to the
> parallel input reports a MEDIA_ENT_F_VID_IF_BRIDGE or
> MEDIA_ENT_F_VID_MUX function. This was broken already, and should be
> fixed separately.
> 
> Fixes: f168e796bf40 ("media: imx7: csi: Fix pad link validation")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

------
Cheers,
     Rui
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 52 +++++++++++++---------
>  1 file changed, 30 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> index de7b93317a47..2a4b69cc0178 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -1000,39 +1000,47 @@ 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_entity *src;
>  	struct media_pad *pad;
> +	bool is_csi2;
>  	int ret;
>  
> -	/*
> -	 * Validate the source link, and record whether the CSI mux selects the
> -	 * parallel input or the CSI-2 receiver.
> -	 */
> -	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
> -	if (ret)
> -		return ret;
> -
>  	if (!csi->src_sd)
>  		return -EPIPE;
>  
> -	src = &csi->src_sd->entity;
> -
>  	/*
> -	 * if the source is neither a CSI MUX or CSI-2 get the one directly
> -	 * upstream from this CSI
> +	 * Validate the source link, and record whether the source uses the
> +	 * parallel input or the CSI-2 receiver.
>  	 */
> -	if (src->function != MEDIA_ENT_F_VID_IF_BRIDGE &&
> -	    src->function != MEDIA_ENT_F_VID_MUX)
> -		src = &csi->sd.entity;
> +	ret = v4l2_subdev_link_validate_default(sd, link, source_fmt, sink_fmt);
> +	if (ret)
> +		return ret;
>  
> -	pad = imx_media_pipeline_pad(src, 0, 0, true);
> -	if (!pad)
> -		return -ENODEV;
> +	switch (csi->src_sd->entity.function) {
> +	case MEDIA_ENT_F_VID_IF_BRIDGE:
> +		/* The input is the CSI-2 receiver. */
> +		is_csi2 = true;
> +		break;
> +
> +	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);
> +		if (!pad)
> +			return -ENODEV;
> +
> +		is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
> +		break;
> +
> +	default:
> +		/*
> +		 * The input is an external entity, it must use the parallel
> +		 * bus.
> +		 */
> +		is_csi2 = false;
> +		break;
> +	}
>  
>  	mutex_lock(&csi->lock);
> -
> -	csi->is_csi2 = (pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE);
> -
> +	csi->is_csi2 = is_csi2;
>  	mutex_unlock(&csi->lock);
>  
>  	/* Validate the sink link, ensure the pixel format is supported. */
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* Re: [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2
  2021-02-15  4:27 ` [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2 Laurent Pinchart
@ 2021-03-01  9:31   ` Rui Miguel Silva
  0 siblings, 0 replies; 100+ messages in thread
From: Rui Miguel Silva @ 2021-03-01  9:31 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia,
	Fabio Estevam

Hi Laurent,
On Mon, Feb 15, 2021 at 06:27:03AM +0200, Laurent Pinchart wrote:
> The is_csi2 field can't be accessed concurrently by
> imx7_csi_pad_link_validate() and imx7_csi_configure(), as the latter is
> called from imx7_csi_s_stream(), which is called after link validation.
> Drop the lock.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

------
Cheers,
     Rui
> ---
>  drivers/staging/media/imx/imx7-media-csi.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> index 2a4b69cc0178..dc25b593eaeb 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -1001,7 +1001,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
>  	struct imx_media_video_dev *vdev = csi->vdev;
>  	const struct v4l2_pix_format *out_pix = &vdev->fmt;
>  	struct media_pad *pad;
> -	bool is_csi2;
>  	int ret;
>  
>  	if (!csi->src_sd)
> @@ -1018,7 +1017,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
>  	switch (csi->src_sd->entity.function) {
>  	case MEDIA_ENT_F_VID_IF_BRIDGE:
>  		/* The input is the CSI-2 receiver. */
> -		is_csi2 = true;
> +		csi->is_csi2 = true;
>  		break;
>  
>  	case MEDIA_ENT_F_VID_MUX:
> @@ -1027,7 +1026,7 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
>  		if (!pad)
>  			return -ENODEV;
>  
> -		is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
> +		csi->is_csi2 = pad->entity->function == MEDIA_ENT_F_VID_IF_BRIDGE;
>  		break;
>  
>  	default:
> @@ -1035,14 +1034,10 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
>  		 * The input is an external entity, it must use the parallel
>  		 * bus.
>  		 */
> -		is_csi2 = false;
> +		csi->is_csi2 = false;
>  		break;
>  	}
>  
> -	mutex_lock(&csi->lock);
> -	csi->is_csi2 = is_csi2;
> -	mutex_unlock(&csi->lock);
> -
>  	/* Validate the sink link, ensure the pixel format is supported. */
>  	switch (out_pix->pixelformat) {
>  	case V4L2_PIX_FMT_UYVY:
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* Re: [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces
  2021-02-15  4:27 ` [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces Laurent Pinchart
@ 2021-03-01  9:33   ` Rui Miguel Silva
  2021-03-05 21:42   ` Rob Herring
  1 sibling, 0 replies; 100+ messages in thread
From: Rui Miguel Silva @ 2021-03-01  9:33 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia,
	Fabio Estevam, Rob Herring, devicetree

Hi Laurent,
Thanks.

On Mon, Feb 15, 2021 at 06:27:24AM +0200, Laurent Pinchart wrote:
> DT bindings examples are customarily indented with 4 spaces.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

------
Cheers,
     Rui
> ---
>  .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 54 +++++++++----------
>  1 file changed, 27 insertions(+), 27 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> index 74ff92b5baa3..76fcc8d80ee3 100644
> --- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> +++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> @@ -122,41 +122,41 @@ examples:
>      #include <dt-bindings/reset/imx7-reset.h>
>  
>      mipi_csi: mipi-csi@30750000 {
> -            compatible = "fsl,imx7-mipi-csi2";
> -            reg = <0x30750000 0x10000>;
> -            interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
> +        compatible = "fsl,imx7-mipi-csi2";
> +        reg = <0x30750000 0x10000>;
> +        interrupts = <GIC_SPI 25 IRQ_TYPE_LEVEL_HIGH>;
>  
> -            clocks = <&clks IMX7D_IPG_ROOT_CLK>,
> -                     <&clks IMX7D_MIPI_CSI_ROOT_CLK>,
> -                     <&clks IMX7D_MIPI_DPHY_ROOT_CLK>;
> -            clock-names = "pclk", "wrap", "phy";
> -            clock-frequency = <166000000>;
> +        clocks = <&clks IMX7D_IPG_ROOT_CLK>,
> +                 <&clks IMX7D_MIPI_CSI_ROOT_CLK>,
> +                 <&clks IMX7D_MIPI_DPHY_ROOT_CLK>;
> +        clock-names = "pclk", "wrap", "phy";
> +        clock-frequency = <166000000>;
>  
> -            power-domains = <&pgc_mipi_phy>;
> -            phy-supply = <&reg_1p0d>;
> -            resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
> +        power-domains = <&pgc_mipi_phy>;
> +        phy-supply = <&reg_1p0d>;
> +        resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
>  
> -            ports {
> -                    #address-cells = <1>;
> -                    #size-cells = <0>;
> +        ports {
> +            #address-cells = <1>;
> +            #size-cells = <0>;
>  
> -                    port@0 {
> -                            reg = <0>;
> +            port@0 {
> +                reg = <0>;
>  
> -                            mipi_from_sensor: endpoint {
> -                                    remote-endpoint = <&ov2680_to_mipi>;
> -                                    data-lanes = <1>;
> -                            };
> -                    };
> +                mipi_from_sensor: endpoint {
> +                    remote-endpoint = <&ov2680_to_mipi>;
> +                    data-lanes = <1>;
> +                };
> +            };
>  
> -                    port@1 {
> -                            reg = <1>;
> +            port@1 {
> +                reg = <1>;
>  
> -                            mipi_vc0_to_csi_mux: endpoint {
> -                                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
> -                            };
> -                    };
> +                mipi_vc0_to_csi_mux: endpoint {
> +                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
> +                };
>              };
> +        };
>      };
>  
>  ...
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* Re: [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions
  2021-02-15  4:27 ` [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions Laurent Pinchart
@ 2021-03-01  9:35   ` Rui Miguel Silva
  2021-03-05 21:43   ` Rob Herring
  1 sibling, 0 replies; 100+ messages in thread
From: Rui Miguel Silva @ 2021-03-01  9:35 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia,
	Fabio Estevam, Rob Herring, devicetree

Hi Laurent,
On Mon, Feb 15, 2021 at 06:27:25AM +0200, Laurent Pinchart wrote:
> Expand the description of the binding itself and of individual
> properties to include additional information that may not be immediately
> appartent from reading the reference manual. Drop the last sentence of
> the phy-supply description that refers to the driver's implementation.
> 
> While at it, fix the capitalization of MIPI CSI-2 in the title.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

For the descriptions changes, LGTM.

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

------
Cheers,
     Rui
> ---
>  .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 29 +++++++++++--------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> index 76fcc8d80ee3..471a5bf7eb76 100644
> --- a/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> +++ b/Documentation/devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml
> @@ -4,14 +4,19 @@
>  $id: http://devicetree.org/schemas/media/nxp,imx7-mipi-csi2.yaml#
>  $schema: http://devicetree.org/meta-schemas/core.yaml#
>  
> -title: NXP i.MX7 Mipi CSI2
> +title: NXP i.MX7 MIPI CSI-2 receiver
>  
>  maintainers:
>    - Rui Miguel Silva <rmfrfs@gmail.com>
>  
> -description: |
> -  This is the device node for the MIPI CSI-2 receiver core in i.MX7 soc. It is
> -  compatible with previous version of samsung d-phy.
> +description: |-
> +  The NXP i.MX7 SoC family includes a MIPI CSI-2 receiver IP core, documented
> +  as "CSIS V3.3". The IP core seems to originate from Samsung, and may be
> +  compatible with some of the Exynos4 ad S5P SoCs.
> +
> +  While the CSI-2 receiver is separate from the MIPI D-PHY IP core, the PHY is
> +  completely wrapped by the CSIS and doesn't expose a control interface of its
> +  own. This binding thus covers both IP cores.
>  
>  properties:
>    compatible:
> @@ -24,8 +29,10 @@ properties:
>      maxItems: 1
>  
>    clocks:
> -    minItems: 3
> -    maxItems: 3
> +    items:
> +      - description: The peripheral clock (a.k.a. APB clock)
> +      - description: The external clock (optionally used as the pixel clock)
> +      - description: The MIPI D-PHY clock
>  
>    clock-names:
>      items:
> @@ -37,16 +44,14 @@ properties:
>      maxItems: 1
>  
>    phy-supply:
> -    description:
> -      Phandle to a regulator that provides power to the PHY. This
> -      regulator will be managed during the PHY power on/off sequence.
> +    description: The MIPI D-PHY digital power supply
>  
>    resets:
> -    maxItems: 1
> +    items:
> +      - description: MIPI D-PHY slave reset
>  
>    clock-frequency:
> -    description:
> -      The IP main (system bus) clock frequency in Hertz
> +    description: The desired external clock ("wrap") frequency, in Hz
>      default: 166000000
>  
>    ports:
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* [PATCH v2.1 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate
  2021-02-15  4:27 ` [PATCH v2 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate Laurent Pinchart
@ 2021-03-01 16:40   ` Laurent Pinchart
  0 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-01 16:40 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

The Ths_settle timing parameter depends solely on the lane data rate of
the source. Calculate it at runtime instead of requiring it to be
specified in the device tree.

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

- Don't print hs_settle at probe time
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 48 ++++++++++++++++++----
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 333ab3966b5b..e1728240b494 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -24,6 +24,7 @@
 #include <linux/reset.h>
 #include <linux/spinlock.h>
 
+#include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-mc.h>
@@ -482,6 +483,39 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH0, val);
 }
 
+static int mipi_csis_calculate_params(struct csi_state *state)
+{
+	s64 link_freq;
+	u32 lane_rate;
+
+	/* Calculate the line rate from the pixel rate. */
+	link_freq = v4l2_get_link_freq(state->src_sd->ctrl_handler,
+				       state->csis_fmt->width,
+				       state->bus.num_data_lanes * 2);
+	if (link_freq < 0) {
+		dev_err(state->dev, "Unable to obtain link frequency: %d\n",
+			(int)link_freq);
+		return link_freq;
+	}
+
+	lane_rate = link_freq * 2;
+
+	if (lane_rate < 80000000 || lane_rate > 1500000000) {
+		dev_dbg(state->dev, "Out-of-bound lane rate %u\n", lane_rate);
+		return -EINVAL;
+	}
+
+	/*
+	 * The HSSETTLE counter value is document in a table, but can also
+	 * easily be calculated.
+	 */
+	state->hs_settle = (lane_rate - 5000000) / 45000000;
+	dev_dbg(state->dev, "lane rate %u, Ths_settle %u\n",
+		lane_rate, state->hs_settle);
+
+	return 0;
+}
+
 static void mipi_csis_set_params(struct csi_state *state)
 {
 	int lanes = state->bus.num_data_lanes;
@@ -608,9 +642,13 @@ static void mipi_csis_log_counters(struct csi_state *state, bool non_errors)
 static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 {
 	struct csi_state *state = mipi_sd_to_csis_state(mipi_sd);
-	int ret = 0;
+	int ret;
 
 	if (enable) {
+		ret = mipi_csis_calculate_params(state);
+		if (ret < 0)
+			return ret;
+
 		mipi_csis_clear_counters(state);
 		ret = pm_runtime_get_sync(&state->pdev->dev);
 		if (ret < 0) {
@@ -943,9 +981,6 @@ static int mipi_csis_parse_dt(struct platform_device *pdev,
 	if (IS_ERR(state->mrst))
 		return PTR_ERR(state->mrst);
 
-	/* Get MIPI CSI-2 bus configuration from the endpoint node. */
-	of_property_read_u32(node, "fsl,csis-hs-settle", &state->hs_settle);
-
 	return 0;
 }
 
@@ -1143,9 +1178,8 @@ static int mipi_csis_probe(struct platform_device *pdev)
 			goto unregister_all;
 	}
 
-	dev_info(&pdev->dev, "lanes: %d, hs_settle: %d, freq: %u\n",
-		 state->bus.num_data_lanes, state->hs_settle,
-		 state->clk_frequency);
+	dev_info(&pdev->dev, "lanes: %d, freq: %u\n",
+		 state->bus.num_data_lanes, state->clk_frequency);
 
 	return 0;
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH v2.1 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet
  2021-02-15  4:27 ` [PATCH v2 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet Laurent Pinchart
@ 2021-03-01 16:41   ` Laurent Pinchart
  0 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-01 16:41 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Rename several register macros to match the names from the
documentation.

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

- Fix indentation
- Address SCLKS_MASK and SCLKS_OFFSET
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 172 ++++++++++-----------
 1 file changed, 86 insertions(+), 86 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index de1bc0146e59..f57268fad99c 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -63,61 +63,61 @@
 #define MIPI_CSIS_CLK_CTRL_WCLK_SRC		BIT(0)
 
 /* CSIS Interrupt mask */
-#define MIPI_CSIS_INTMSK			0x10
-#define MIPI_CSIS_INTMSK_EVEN_BEFORE		BIT(31)
-#define MIPI_CSIS_INTMSK_EVEN_AFTER		BIT(30)
-#define MIPI_CSIS_INTMSK_ODD_BEFORE		BIT(29)
-#define MIPI_CSIS_INTMSK_ODD_AFTER		BIT(28)
-#define MIPI_CSIS_INTMSK_FRAME_START		BIT(24)
-#define MIPI_CSIS_INTMSK_FRAME_END		BIT(20)
-#define MIPI_CSIS_INTMSK_ERR_SOT_HS		BIT(16)
-#define MIPI_CSIS_INTMSK_ERR_LOST_FS		BIT(12)
-#define MIPI_CSIS_INTMSK_ERR_LOST_FE		BIT(8)
-#define MIPI_CSIS_INTMSK_ERR_OVER		BIT(4)
-#define MIPI_CSIS_INTMSK_ERR_WRONG_CFG		BIT(3)
-#define MIPI_CSIS_INTMSK_ERR_ECC		BIT(2)
-#define MIPI_CSIS_INTMSK_ERR_CRC		BIT(1)
-#define MIPI_CSIS_INTMSK_ERR_UNKNOWN		BIT(0)
+#define MIPI_CSIS_INT_MSK			0x10
+#define MIPI_CSIS_INT_MSK_EVEN_BEFORE		BIT(31)
+#define MIPI_CSIS_INT_MSK_EVEN_AFTER		BIT(30)
+#define MIPI_CSIS_INT_MSK_ODD_BEFORE		BIT(29)
+#define MIPI_CSIS_INT_MSK_ODD_AFTER		BIT(28)
+#define MIPI_CSIS_INT_MSK_FRAME_START		BIT(24)
+#define MIPI_CSIS_INT_MSK_FRAME_END		BIT(20)
+#define MIPI_CSIS_INT_MSK_ERR_SOT_HS		BIT(16)
+#define MIPI_CSIS_INT_MSK_ERR_LOST_FS		BIT(12)
+#define MIPI_CSIS_INT_MSK_ERR_LOST_FE		BIT(8)
+#define MIPI_CSIS_INT_MSK_ERR_OVER		BIT(4)
+#define MIPI_CSIS_INT_MSK_ERR_WRONG_CFG		BIT(3)
+#define MIPI_CSIS_INT_MSK_ERR_ECC		BIT(2)
+#define MIPI_CSIS_INT_MSK_ERR_CRC		BIT(1)
+#define MIPI_CSIS_INT_MSK_ERR_UNKNOWN		BIT(0)
 
 /* CSIS Interrupt source */
-#define MIPI_CSIS_INTSRC			0x14
-#define MIPI_CSIS_INTSRC_EVEN_BEFORE		BIT(31)
-#define MIPI_CSIS_INTSRC_EVEN_AFTER		BIT(30)
-#define MIPI_CSIS_INTSRC_EVEN			BIT(30)
-#define MIPI_CSIS_INTSRC_ODD_BEFORE		BIT(29)
-#define MIPI_CSIS_INTSRC_ODD_AFTER		BIT(28)
-#define MIPI_CSIS_INTSRC_ODD			(0x3 << 28)
-#define MIPI_CSIS_INTSRC_NON_IMAGE_DATA		(0xf << 28)
-#define MIPI_CSIS_INTSRC_FRAME_START		BIT(24)
-#define MIPI_CSIS_INTSRC_FRAME_END		BIT(20)
-#define MIPI_CSIS_INTSRC_ERR_SOT_HS		BIT(16)
-#define MIPI_CSIS_INTSRC_ERR_LOST_FS		BIT(12)
-#define MIPI_CSIS_INTSRC_ERR_LOST_FE		BIT(8)
-#define MIPI_CSIS_INTSRC_ERR_OVER		BIT(4)
-#define MIPI_CSIS_INTSRC_ERR_WRONG_CFG		BIT(3)
-#define MIPI_CSIS_INTSRC_ERR_ECC		BIT(2)
-#define MIPI_CSIS_INTSRC_ERR_CRC		BIT(1)
-#define MIPI_CSIS_INTSRC_ERR_UNKNOWN		BIT(0)
-#define MIPI_CSIS_INTSRC_ERRORS			0xfffff
+#define MIPI_CSIS_INT_SRC			0x14
+#define MIPI_CSIS_INT_SRC_EVEN_BEFORE		BIT(31)
+#define MIPI_CSIS_INT_SRC_EVEN_AFTER		BIT(30)
+#define MIPI_CSIS_INT_SRC_EVEN			BIT(30)
+#define MIPI_CSIS_INT_SRC_ODD_BEFORE		BIT(29)
+#define MIPI_CSIS_INT_SRC_ODD_AFTER		BIT(28)
+#define MIPI_CSIS_INT_SRC_ODD			(0x3 << 28)
+#define MIPI_CSIS_INT_SRC_NON_IMAGE_DATA	(0xf << 28)
+#define MIPI_CSIS_INT_SRC_FRAME_START		BIT(24)
+#define MIPI_CSIS_INT_SRC_FRAME_END		BIT(20)
+#define MIPI_CSIS_INT_SRC_ERR_SOT_HS		BIT(16)
+#define MIPI_CSIS_INT_SRC_ERR_LOST_FS		BIT(12)
+#define MIPI_CSIS_INT_SRC_ERR_LOST_FE		BIT(8)
+#define MIPI_CSIS_INT_SRC_ERR_OVER		BIT(4)
+#define MIPI_CSIS_INT_SRC_ERR_WRONG_CFG		BIT(3)
+#define MIPI_CSIS_INT_SRC_ERR_ECC		BIT(2)
+#define MIPI_CSIS_INT_SRC_ERR_CRC		BIT(1)
+#define MIPI_CSIS_INT_SRC_ERR_UNKNOWN		BIT(0)
+#define MIPI_CSIS_INT_SRC_ERRORS		0xfffff
 
 /* D-PHY status control */
-#define MIPI_CSIS_DPHYSTATUS			0x20
-#define MIPI_CSIS_DPHYSTATUS_ULPS_DAT		BIT(8)
-#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_DAT	BIT(4)
-#define MIPI_CSIS_DPHYSTATUS_ULPS_CLK		BIT(1)
-#define MIPI_CSIS_DPHYSTATUS_STOPSTATE_CLK	BIT(0)
+#define MIPI_CSIS_DPHY_STATUS			0x20
+#define MIPI_CSIS_DPHY_STATUS_ULPS_DAT		BIT(8)
+#define MIPI_CSIS_DPHY_STATUS_STOPSTATE_DAT	BIT(4)
+#define MIPI_CSIS_DPHY_STATUS_ULPS_CLK		BIT(1)
+#define MIPI_CSIS_DPHY_STATUS_STOPSTATE_CLK	BIT(0)
 
 /* D-PHY common control */
-#define MIPI_CSIS_DPHYCTRL			0x24
-#define MIPI_CSIS_DPHYCTRL_HSSETTLE(n)		((n) << 24)
-#define MIPI_CSIS_DPHYCTRL_HSSETTLE_MASK	GENMASK(31, 24)
-#define MIPI_CSIS_DPHYCTRL_SCLKS_MASK		(0x3 << 22)
-#define MIPI_CSIS_DPHYCTRL_SCLKS_OFFSET		22
-#define MIPI_CSIS_DPHYCTRL_DPDN_SWAP_CLK	BIT(6)
-#define MIPI_CSIS_DPHYCTRL_DPDN_SWAP_DAT	BIT(5)
-#define MIPI_CSIS_DPHYCTRL_ENABLE_DAT		BIT(1)
-#define MIPI_CSIS_DPHYCTRL_ENABLE_CLK		BIT(0)
-#define MIPI_CSIS_DPHYCTRL_ENABLE		(0x1f << 0)
+#define MIPI_CSIS_DPHY_CMN_CTRL			0x24
+#define MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE(n)	((n) << 24)
+#define MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE_MASK	GENMASK(31, 24)
+#define MIPI_CSIS_DPHY_CMN_CTRL_CLKSETTLE(n)	((n) << 22)
+#define MIPI_CSIS_DPHY_CMN_CTRL_CLKSETTLE_MASK	GENMASK(23, 22)
+#define MIPI_CSIS_DPHY_CMN_CTRL_DPDN_SWAP_CLK	BIT(6)
+#define MIPI_CSIS_DPHY_CMN_CTRL_DPDN_SWAP_DAT	BIT(5)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE_DAT	BIT(1)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE_CLK	BIT(0)
+#define MIPI_CSIS_DPHY_CMN_CTRL_ENABLE		(0x1f << 0)
 
 /* D-PHY Master and Slave Control register Low */
 #define MIPI_CSIS_DPHY_BCTRL_L			0x30
@@ -163,7 +163,7 @@
 #define MIPI_CSIS_DPHY_SCTRL_H			0x3c
 
 /* ISP Configuration register */
-#define MIPI_CSIS_ISPCONFIG_CH(n)		(0x40 + (n) * 0x10)
+#define MIPI_CSIS_ISP_CONFIG_CH(n)		(0x40 + (n) * 0x10)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP_MSK	(0xff << 24)
 #define MIPI_CSIS_ISPCFG_MEM_FULL_GAP(x)	((x) << 24)
 #define MIPI_CSIS_ISPCFG_DOUBLE_CMPNT		BIT(12)
@@ -178,15 +178,15 @@
 #define MIPI_CSIS_ISPCFG_FMT_MASK		(0x3f << 2)
 
 /* ISP Image Resolution register */
-#define MIPI_CSIS_ISPRESOL_CH(n)		(0x44 + (n) * 0x10)
+#define MIPI_CSIS_ISP_RESOL_CH(n)		(0x44 + (n) * 0x10)
 #define CSIS_MAX_PIX_WIDTH			0xffff
 #define CSIS_MAX_PIX_HEIGHT			0xffff
 
 /* ISP SYNC register */
-#define MIPI_CSIS_ISPSYNC_CH(n)			(0x48 + (n) * 0x10)
-#define MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET	18
-#define MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET	12
-#define MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET	0
+#define MIPI_CSIS_ISP_SYNC_CH(n)		(0x48 + (n) * 0x10)
+#define MIPI_CSIS_ISP_SYNC_HSYNC_LINTV_OFFSET	18
+#define MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET	12
+#define MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET	0
 
 /* Non-image packet data buffers */
 #define MIPI_CSIS_PKTDATA_ODD			0x2000
@@ -209,22 +209,22 @@ struct mipi_csis_event {
 
 static const struct mipi_csis_event mipi_csis_events[] = {
 	/* Errors */
-	{ MIPI_CSIS_INTSRC_ERR_SOT_HS,	"SOT Error" },
-	{ MIPI_CSIS_INTSRC_ERR_LOST_FS,	"Lost Frame Start Error" },
-	{ MIPI_CSIS_INTSRC_ERR_LOST_FE,	"Lost Frame End Error" },
-	{ MIPI_CSIS_INTSRC_ERR_OVER,	"FIFO Overflow Error" },
-	{ MIPI_CSIS_INTSRC_ERR_WRONG_CFG, "Wrong Configuration Error" },
-	{ MIPI_CSIS_INTSRC_ERR_ECC,	"ECC Error" },
-	{ MIPI_CSIS_INTSRC_ERR_CRC,	"CRC Error" },
-	{ MIPI_CSIS_INTSRC_ERR_UNKNOWN,	"Unknown Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_SOT_HS,		"SOT Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_LOST_FS,	"Lost Frame Start Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_LOST_FE,	"Lost Frame End Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_OVER,		"FIFO Overflow Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_WRONG_CFG,	"Wrong Configuration Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_ECC,		"ECC Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_CRC,		"CRC Error" },
+	{ MIPI_CSIS_INT_SRC_ERR_UNKNOWN,	"Unknown Error" },
 	/* Non-image data receive events */
-	{ MIPI_CSIS_INTSRC_EVEN_BEFORE,	"Non-image data before even frame" },
-	{ MIPI_CSIS_INTSRC_EVEN_AFTER,	"Non-image data after even frame" },
-	{ MIPI_CSIS_INTSRC_ODD_BEFORE,	"Non-image data before odd frame" },
-	{ MIPI_CSIS_INTSRC_ODD_AFTER,	"Non-image data after odd frame" },
+	{ MIPI_CSIS_INT_SRC_EVEN_BEFORE,	"Non-image data before even frame" },
+	{ MIPI_CSIS_INT_SRC_EVEN_AFTER,		"Non-image data after even frame" },
+	{ MIPI_CSIS_INT_SRC_ODD_BEFORE,		"Non-image data before odd frame" },
+	{ MIPI_CSIS_INT_SRC_ODD_AFTER,		"Non-image data after odd frame" },
 	/* Frame start/end */
-	{ MIPI_CSIS_INTSRC_FRAME_START,	"Frame Start" },
-	{ MIPI_CSIS_INTSRC_FRAME_END,	"Frame End" },
+	{ MIPI_CSIS_INT_SRC_FRAME_START,	"Frame Start" },
+	{ MIPI_CSIS_INT_SRC_FRAME_END,		"Frame End" },
 };
 
 #define MIPI_CSIS_NUM_EVENTS ARRAY_SIZE(mipi_csis_events)
@@ -444,7 +444,7 @@ static const struct csis_pix_format *find_csis_format(u32 code)
 
 static void mipi_csis_enable_interrupts(struct csi_state *state, bool on)
 {
-	mipi_csis_write(state, MIPI_CSIS_INTMSK, on ? 0xffffffff : 0);
+	mipi_csis_write(state, MIPI_CSIS_INT_MSK, on ? 0xffffffff : 0);
 }
 
 static void mipi_csis_sw_reset(struct csi_state *state)
@@ -486,13 +486,13 @@ static void mipi_csis_system_enable(struct csi_state *state, int on)
 		val &= ~MIPI_CSIS_CMN_CTRL_ENABLE;
 	mipi_csis_write(state, MIPI_CSIS_CMN_CTRL, val);
 
-	val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL);
-	val &= ~MIPI_CSIS_DPHYCTRL_ENABLE;
+	val = mipi_csis_read(state, MIPI_CSIS_DPHY_CMN_CTRL);
+	val &= ~MIPI_CSIS_DPHY_CMN_CTRL_ENABLE;
 	if (on) {
 		mask = (1 << (state->bus.num_data_lanes + 1)) - 1;
-		val |= (mask & MIPI_CSIS_DPHYCTRL_ENABLE);
+		val |= (mask & MIPI_CSIS_DPHY_CMN_CTRL_ENABLE);
 	}
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val);
+	mipi_csis_write(state, MIPI_CSIS_DPHY_CMN_CTRL, val);
 }
 
 /* Called with the state.lock mutex held */
@@ -502,14 +502,14 @@ static void __mipi_csis_set_format(struct csi_state *state)
 	u32 val;
 
 	/* Color format */
-	val = mipi_csis_read(state, MIPI_CSIS_ISPCONFIG_CH(0));
+	val = mipi_csis_read(state, MIPI_CSIS_ISP_CONFIG_CH(0));
 	val &= ~(MIPI_CSIS_ISPCFG_ALIGN_32BIT | MIPI_CSIS_ISPCFG_FMT_MASK);
 	val |= state->csis_fmt->fmt_reg;
-	mipi_csis_write(state, MIPI_CSIS_ISPCONFIG_CH(0), val);
+	mipi_csis_write(state, MIPI_CSIS_ISP_CONFIG_CH(0), val);
 
 	/* Pixel resolution */
 	val = mf->width | (mf->height << 16);
-	mipi_csis_write(state, MIPI_CSIS_ISPRESOL_CH(0), val);
+	mipi_csis_write(state, MIPI_CSIS_ISP_RESOL_CH(0), val);
 }
 
 static int mipi_csis_calculate_params(struct csi_state *state)
@@ -558,13 +558,13 @@ static void mipi_csis_set_params(struct csi_state *state)
 
 	__mipi_csis_set_format(state);
 
-	mipi_csis_write(state, MIPI_CSIS_DPHYCTRL,
-			MIPI_CSIS_DPHYCTRL_HSSETTLE(state->hs_settle));
+	mipi_csis_write(state, MIPI_CSIS_DPHY_CMN_CTRL,
+			MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE(state->hs_settle));
 
-	val = (0 << MIPI_CSIS_ISPSYNC_HSYNC_LINTV_OFFSET) |
-		(0 << MIPI_CSIS_ISPSYNC_VSYNC_SINTV_OFFSET) |
-		(0 << MIPI_CSIS_ISPSYNC_VSYNC_EINTV_OFFSET);
-	mipi_csis_write(state, MIPI_CSIS_ISPSYNC_CH(0), val);
+	val = (0 << MIPI_CSIS_ISP_SYNC_HSYNC_LINTV_OFFSET)
+	    | (0 << MIPI_CSIS_ISP_SYNC_VSYNC_SINTV_OFFSET)
+	    | (0 << MIPI_CSIS_ISP_SYNC_VSYNC_EINTV_OFFSET);
+	mipi_csis_write(state, MIPI_CSIS_ISP_SYNC_CH(0), val);
 
 	val = mipi_csis_read(state, MIPI_CSIS_CLK_CTRL);
 	val |= MIPI_CSIS_CLK_CTRL_WCLK_SRC;
@@ -955,12 +955,12 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id)
 	unsigned int i;
 	u32 status;
 
-	status = mipi_csis_read(state, MIPI_CSIS_INTSRC);
+	status = mipi_csis_read(state, MIPI_CSIS_INT_SRC);
 
 	spin_lock_irqsave(&state->slock, flags);
 
 	/* Update the event/error counters */
-	if ((status & MIPI_CSIS_INTSRC_ERRORS) || state->debug) {
+	if ((status & MIPI_CSIS_INT_SRC_ERRORS) || state->debug) {
 		for (i = 0; i < MIPI_CSIS_NUM_EVENTS; i++) {
 			if (!(status & state->events[i].mask))
 				continue;
@@ -969,7 +969,7 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id)
 	}
 	spin_unlock_irqrestore(&state->slock, flags);
 
-	mipi_csis_write(state, MIPI_CSIS_INTSRC, status);
+	mipi_csis_write(state, MIPI_CSIS_INT_SRC, status);
 
 	return IRQ_HANDLED;
 }
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property
  2021-02-15  4:27 ` [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
@ 2021-03-05 21:41   ` Rob Herring
  0 siblings, 0 replies; 100+ messages in thread
From: Rob Herring @ 2021-03-05 21:41 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Fabio Estevam, linux-media, Rui Miguel Silva, Rob Herring,
	Philipp Zabel, devicetree, Steve Longerbeam, Ezequiel Garcia

On Mon, 15 Feb 2021 06:27:22 +0200, Laurent Pinchart wrote:
> The reset-names property is incorrect, as it references the reset of the
> MIPI D-PHY master, which is used by the DSI controller. Fixing the
> property name would create backward-compatibility issues. As the device
> has a single reset, we can instead drop reset-names completely, which
> also simplifies the binding.
> 
> Fix the example accordingly to use the correct reset.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
> ---
>  .../devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml        | 5 -----
>  1 file changed, 5 deletions(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property
  2021-02-15  4:27 ` [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
@ 2021-03-05 21:42   ` Rob Herring
  0 siblings, 0 replies; 100+ messages in thread
From: Rob Herring @ 2021-03-05 21:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Philipp Zabel, Rob Herring, Ezequiel Garcia, Fabio Estevam,
	Rui Miguel Silva, devicetree, Steve Longerbeam, linux-media

On Mon, 15 Feb 2021 06:27:23 +0200, Laurent Pinchart wrote:
> The fsl,csis-hs-settle property isn't used by the driver anymore. Drop
> it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
> ---
>  .../devicetree/bindings/media/nxp,imx7-mipi-csi2.yaml       | 6 ------
>  1 file changed, 6 deletions(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces
  2021-02-15  4:27 ` [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces Laurent Pinchart
  2021-03-01  9:33   ` Rui Miguel Silva
@ 2021-03-05 21:42   ` Rob Herring
  1 sibling, 0 replies; 100+ messages in thread
From: Rob Herring @ 2021-03-05 21:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Rui Miguel Silva, Steve Longerbeam, Fabio Estevam, Rob Herring,
	devicetree, linux-media, Ezequiel Garcia, Philipp Zabel

On Mon, 15 Feb 2021 06:27:24 +0200, Laurent Pinchart wrote:
> DT bindings examples are customarily indented with 4 spaces.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 54 +++++++++----------
>  1 file changed, 27 insertions(+), 27 deletions(-)
> 

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions
  2021-02-15  4:27 ` [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions Laurent Pinchart
  2021-03-01  9:35   ` Rui Miguel Silva
@ 2021-03-05 21:43   ` Rob Herring
  1 sibling, 0 replies; 100+ messages in thread
From: Rob Herring @ 2021-03-05 21:43 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Rob Herring, devicetree, Steve Longerbeam, Philipp Zabel,
	linux-media, Fabio Estevam, Rui Miguel Silva, Ezequiel Garcia

On Mon, 15 Feb 2021 06:27:25 +0200, Laurent Pinchart wrote:
> Expand the description of the binding itself and of individual
> properties to include additional information that may not be immediately
> appartent from reading the reference manual. Drop the last sentence of
> the phy-supply description that refers to the driver's implementation.
> 
> While at it, fix the capitalization of MIPI CSI-2 in the title.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  .../bindings/media/nxp,imx7-mipi-csi2.yaml    | 29 +++++++++++--------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

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

* [PATCH] imx7-media-csi: csi2 only
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (76 preceding siblings ...)
  2021-02-15  4:27 ` [PATCH v2 77/77] media: imx: imx7_mipi_csis: Print shadow registers " Laurent Pinchart
@ 2021-03-16 11:56 ` Martin Kepplinger
  2021-03-16 18:05   ` Laurent Pinchart
  2021-03-17 18:04 ` [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Frieder Schrempf
  78 siblings, 1 reply; 100+ messages in thread
From: Martin Kepplinger @ 2021-03-16 11:56 UTC (permalink / raw)
  To: laurent.pinchart
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam,
	Martin Kepplinger

---

hi Laurent,

thanks a lot for posting this series!

First: I only test imx7-media-csi (csi bridge) because I run it on imx8mq.
overall, I'm very happy with all of this and I get the same image out
of it as I get with the mx6s_capture nxp driver.

one issue I have is with is_csi2, so I post this patch that I need in
order to test. It's obviously no solution, just to describe the issue:

I'm not sure why but imx7_csi_pad_link_validate() isn't called in my case
and is_csi2 doesn't get set, so I force it. Would it make sense to make
a dts property for this?

The other thing is that
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=0
doesn't call the sensor drivers' set_fmt() pad function. That means that
only the one mode I hard-code as default will work. instead I just see this:

[  742.977677] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
[  742.977702] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
[  742.977709] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
[  742.977714] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
[  742.977720] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
[  742.977985] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
[  742.977992] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
[  742.977997] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
[  742.978002] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
[  742.978008] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
[  742.978025] mc: media_release: Media Release

Does anything come to your mind that would prevent the set_fmt call here?
That's what the (nxp) mipi driver looks like I'm running here:
https://source.puri.sm/martin.kepplinger/linux-next/-/blob/5.12-rc3/librem5__integration_byzantium/drivers/media/platform/imx8/mxc-mipi-csi2_yav.c

                             martin


 drivers/staging/media/imx/imx7-media-csi.c | 135 +++++++++------------
 1 file changed, 60 insertions(+), 75 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 56b92ba97d25..95c359019725 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -435,82 +435,67 @@ static void imx7_csi_configure(struct imx7_csi *csi)
 		stride = out_pix->width;
 	}
 
-	if (!csi->is_csi2) {
-		dev_dbg(csi->dev, "%s: NOT is_csi2\n", __func__);
-		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
-		    | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
-
-		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
-			BIT_BASEADDR_CHG_ERR_EN;
-
-		if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY ||
-		    out_pix->pixelformat == V4L2_PIX_FMT_YUYV)
-			width *= 2;
-	} else {
-		dev_dbg(csi->dev, "%s: is_csi2\n", __func__);
-
-		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
-		    | BIT_MCLKDIV(1) | BIT_MCLKEN;
-
-		cr18 |= BIT_DATA_FROM_MIPI;
-
-		switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
-		case MEDIA_BUS_FMT_Y8_1X8:
-		case MEDIA_BUS_FMT_SBGGR8_1X8:
-		case MEDIA_BUS_FMT_SGBRG8_1X8:
-		case MEDIA_BUS_FMT_SGRBG8_1X8:
-		case MEDIA_BUS_FMT_SRGGB8_1X8:
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
-			break;
-		case MEDIA_BUS_FMT_Y10_1X10:
-		case MEDIA_BUS_FMT_SBGGR10_1X10:
-		case MEDIA_BUS_FMT_SGBRG10_1X10:
-		case MEDIA_BUS_FMT_SGRBG10_1X10:
-		case MEDIA_BUS_FMT_SRGGB10_1X10:
-			dev_dbg(csi->dev, "%s: RAW10\n", __func__);
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
-			break;
-		case MEDIA_BUS_FMT_Y12_1X12:
-		case MEDIA_BUS_FMT_SBGGR12_1X12:
-		case MEDIA_BUS_FMT_SGBRG12_1X12:
-		case MEDIA_BUS_FMT_SGRBG12_1X12:
-		case MEDIA_BUS_FMT_SRGGB12_1X12:
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
-			break;
-		case MEDIA_BUS_FMT_Y14_1X14:
-		case MEDIA_BUS_FMT_SBGGR14_1X14:
-		case MEDIA_BUS_FMT_SGBRG14_1X14:
-		case MEDIA_BUS_FMT_SGRBG14_1X14:
-		case MEDIA_BUS_FMT_SRGGB14_1X14:
-			cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
-			break;
-		/*
-		 * CSI-2 sources are supposed to use the 1X16 formats, but not
-		 * all of them comply. Support both variants.
-		 */
-		case MEDIA_BUS_FMT_UYVY8_2X8:
-		case MEDIA_BUS_FMT_UYVY8_1X16:
-		case MEDIA_BUS_FMT_YUYV8_2X8:
-		case MEDIA_BUS_FMT_YUYV8_1X16:
-			cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
-			break;
-		}
+	cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
+	    | BIT_MCLKDIV(1) | BIT_MCLKEN;
+
+	cr18 |= BIT_DATA_FROM_MIPI;
+
+	switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
+	case MEDIA_BUS_FMT_Y8_1X8:
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+	case MEDIA_BUS_FMT_SGBRG8_1X8:
+	case MEDIA_BUS_FMT_SGRBG8_1X8:
+	case MEDIA_BUS_FMT_SRGGB8_1X8:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
+		break;
+	case MEDIA_BUS_FMT_Y10_1X10:
+	case MEDIA_BUS_FMT_SBGGR10_1X10:
+	case MEDIA_BUS_FMT_SGBRG10_1X10:
+	case MEDIA_BUS_FMT_SGRBG10_1X10:
+	case MEDIA_BUS_FMT_SRGGB10_1X10:
+		dev_dbg(csi->dev, "%s: RAW10\n", __func__);
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
+		break;
+	case MEDIA_BUS_FMT_Y12_1X12:
+	case MEDIA_BUS_FMT_SBGGR12_1X12:
+	case MEDIA_BUS_FMT_SGBRG12_1X12:
+	case MEDIA_BUS_FMT_SGRBG12_1X12:
+	case MEDIA_BUS_FMT_SRGGB12_1X12:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
+		break;
+	case MEDIA_BUS_FMT_Y14_1X14:
+	case MEDIA_BUS_FMT_SBGGR14_1X14:
+	case MEDIA_BUS_FMT_SGBRG14_1X14:
+	case MEDIA_BUS_FMT_SGRBG14_1X14:
+	case MEDIA_BUS_FMT_SRGGB14_1X14:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
+		break;
+	/*
+	 * CSI-2 sources are supposed to use the 1X16 formats, but not
+	 * all of them comply. Support both variants.
+	 */
+	case MEDIA_BUS_FMT_UYVY8_2X8:
+	case MEDIA_BUS_FMT_UYVY8_1X16:
+	case MEDIA_BUS_FMT_YUYV8_2X8:
+	case MEDIA_BUS_FMT_YUYV8_1X16:
+		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
+		break;
+	}
 
-		switch (out_pix->pixelformat) {
-		case V4L2_PIX_FMT_Y10:
-		case V4L2_PIX_FMT_Y12:
-		case V4L2_PIX_FMT_SBGGR8:
-		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:
-			dev_dbg(csi->dev, "%s: PIXEL_BIT\n", __func__);
-			cr1 |= BIT_PIXEL_BIT;
-			break;
-		}
+	switch (out_pix->pixelformat) {
+	case V4L2_PIX_FMT_Y10:
+	case V4L2_PIX_FMT_Y12:
+	case V4L2_PIX_FMT_SBGGR8:
+	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:
+		dev_dbg(csi->dev, "%s: PIXEL_BIT\n", __func__);
+		cr1 |= BIT_PIXEL_BIT;
+		break;
 	}
 
 	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);
-- 
2.30.1


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

* Re: [PATCH] imx7-media-csi: csi2 only
  2021-03-16 11:56 ` [PATCH] imx7-media-csi: csi2 only Martin Kepplinger
@ 2021-03-16 18:05   ` Laurent Pinchart
  2021-03-17 10:08     ` Martin Kepplinger
  0 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-16 18:05 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam

Hi Martin,

On Tue, Mar 16, 2021 at 12:56:35PM +0100, Martin Kepplinger wrote:
> ---
> 
> hi Laurent,
> 
> thanks a lot for posting this series!
> 
> First: I only test imx7-media-csi (csi bridge) because I run it on imx8mq.
> overall, I'm very happy with all of this and I get the same image out
> of it as I get with the mx6s_capture nxp driver.

That's good news :-)

> one issue I have is with is_csi2, so I post this patch that I need in
> order to test. It's obviously no solution, just to describe the issue:
> 
> I'm not sure why but imx7_csi_pad_link_validate() isn't called in my case
> and is_csi2 doesn't get set, so I force it. Would it make sense to make
> a dts property for this?

Some platforms support both parallel and CSI-2 inputs, so we can't
hardcode which one is used in DT. I'd advise trying to debug why the
function is never called in your case, it's meant to be called with the
following call stack

- imx7_csi_pad_link_validate() (through v4l2_subdev_pad_ops.link_validate)
- v4l2_subdev_link_validate() (through media_entity_operations.link_validate)
- __media_pipeline_start()
- imx_media_pipeline_set_stream()
- capture_start_streaming()
- ...

> The other thing is that
> v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=0
> doesn't call the sensor drivers' set_fmt() pad function. That means that
> only the one mode I hard-code as default will work. instead I just see this:

That's expected. With a driver based on the media controller API, you
have to configure the format on each subdev manually. You can use the
media-ctl utility for that. The video node is only used to control the
DMA engine, the kernel driver doesn't propagate the configuration to
subdevices.

> [  742.977677] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
> [  742.977702] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
> [  742.977709] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
> [  742.977714] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
> [  742.977720] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
> [  742.977985] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
> [  742.977992] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
> [  742.977997] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
> [  742.978002] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
> [  742.978008] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
> [  742.978025] mc: media_release: Media Release
> 
> Does anything come to your mind that would prevent the set_fmt call here?
> That's what the (nxp) mipi driver looks like I'm running here:
> https://source.puri.sm/martin.kepplinger/linux-next/-/blob/5.12-rc3/librem5__integration_byzantium/drivers/media/platform/imx8/mxc-mipi-csi2_yav.c
> 
>  drivers/staging/media/imx/imx7-media-csi.c | 135 +++++++++------------
>  1 file changed, 60 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
> index 56b92ba97d25..95c359019725 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -435,82 +435,67 @@ static void imx7_csi_configure(struct imx7_csi *csi)
>  		stride = out_pix->width;
>  	}
>  
> -	if (!csi->is_csi2) {
> -		dev_dbg(csi->dev, "%s: NOT is_csi2\n", __func__);
> -		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
> -		    | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
> -
> -		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
> -			BIT_BASEADDR_CHG_ERR_EN;
> -
> -		if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY ||
> -		    out_pix->pixelformat == V4L2_PIX_FMT_YUYV)
> -			width *= 2;
> -	} else {
> -		dev_dbg(csi->dev, "%s: is_csi2\n", __func__);
> -
> -		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
> -		    | BIT_MCLKDIV(1) | BIT_MCLKEN;
> -
> -		cr18 |= BIT_DATA_FROM_MIPI;
> -
> -		switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
> -		case MEDIA_BUS_FMT_Y8_1X8:
> -		case MEDIA_BUS_FMT_SBGGR8_1X8:
> -		case MEDIA_BUS_FMT_SGBRG8_1X8:
> -		case MEDIA_BUS_FMT_SGRBG8_1X8:
> -		case MEDIA_BUS_FMT_SRGGB8_1X8:
> -			cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
> -			break;
> -		case MEDIA_BUS_FMT_Y10_1X10:
> -		case MEDIA_BUS_FMT_SBGGR10_1X10:
> -		case MEDIA_BUS_FMT_SGBRG10_1X10:
> -		case MEDIA_BUS_FMT_SGRBG10_1X10:
> -		case MEDIA_BUS_FMT_SRGGB10_1X10:
> -			dev_dbg(csi->dev, "%s: RAW10\n", __func__);
> -			cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
> -			break;
> -		case MEDIA_BUS_FMT_Y12_1X12:
> -		case MEDIA_BUS_FMT_SBGGR12_1X12:
> -		case MEDIA_BUS_FMT_SGBRG12_1X12:
> -		case MEDIA_BUS_FMT_SGRBG12_1X12:
> -		case MEDIA_BUS_FMT_SRGGB12_1X12:
> -			cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
> -			break;
> -		case MEDIA_BUS_FMT_Y14_1X14:
> -		case MEDIA_BUS_FMT_SBGGR14_1X14:
> -		case MEDIA_BUS_FMT_SGBRG14_1X14:
> -		case MEDIA_BUS_FMT_SGRBG14_1X14:
> -		case MEDIA_BUS_FMT_SRGGB14_1X14:
> -			cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
> -			break;
> -		/*
> -		 * CSI-2 sources are supposed to use the 1X16 formats, but not
> -		 * all of them comply. Support both variants.
> -		 */
> -		case MEDIA_BUS_FMT_UYVY8_2X8:
> -		case MEDIA_BUS_FMT_UYVY8_1X16:
> -		case MEDIA_BUS_FMT_YUYV8_2X8:
> -		case MEDIA_BUS_FMT_YUYV8_1X16:
> -			cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
> -			break;
> -		}
> +	cr1 = BIT_SOF_POL | BIT_REDGE | BIT_HSYNC_POL | BIT_FCC
> +	    | BIT_MCLKDIV(1) | BIT_MCLKEN;
> +
> +	cr18 |= BIT_DATA_FROM_MIPI;
> +
> +	switch (csi->format_mbus[IMX7_CSI_PAD_SINK].code) {
> +	case MEDIA_BUS_FMT_Y8_1X8:
> +	case MEDIA_BUS_FMT_SBGGR8_1X8:
> +	case MEDIA_BUS_FMT_SGBRG8_1X8:
> +	case MEDIA_BUS_FMT_SGRBG8_1X8:
> +	case MEDIA_BUS_FMT_SRGGB8_1X8:
> +		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
> +		break;
> +	case MEDIA_BUS_FMT_Y10_1X10:
> +	case MEDIA_BUS_FMT_SBGGR10_1X10:
> +	case MEDIA_BUS_FMT_SGBRG10_1X10:
> +	case MEDIA_BUS_FMT_SGRBG10_1X10:
> +	case MEDIA_BUS_FMT_SRGGB10_1X10:
> +		dev_dbg(csi->dev, "%s: RAW10\n", __func__);
> +		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
> +		break;
> +	case MEDIA_BUS_FMT_Y12_1X12:
> +	case MEDIA_BUS_FMT_SBGGR12_1X12:
> +	case MEDIA_BUS_FMT_SGBRG12_1X12:
> +	case MEDIA_BUS_FMT_SGRBG12_1X12:
> +	case MEDIA_BUS_FMT_SRGGB12_1X12:
> +		cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
> +		break;
> +	case MEDIA_BUS_FMT_Y14_1X14:
> +	case MEDIA_BUS_FMT_SBGGR14_1X14:
> +	case MEDIA_BUS_FMT_SGBRG14_1X14:
> +	case MEDIA_BUS_FMT_SGRBG14_1X14:
> +	case MEDIA_BUS_FMT_SRGGB14_1X14:
> +		cr18 |= BIT_MIPI_DATA_FORMAT_RAW14;
> +		break;
> +	/*
> +	 * CSI-2 sources are supposed to use the 1X16 formats, but not
> +	 * all of them comply. Support both variants.
> +	 */
> +	case MEDIA_BUS_FMT_UYVY8_2X8:
> +	case MEDIA_BUS_FMT_UYVY8_1X16:
> +	case MEDIA_BUS_FMT_YUYV8_2X8:
> +	case MEDIA_BUS_FMT_YUYV8_1X16:
> +		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
> +		break;
> +	}
>  
> -		switch (out_pix->pixelformat) {
> -		case V4L2_PIX_FMT_Y10:
> -		case V4L2_PIX_FMT_Y12:
> -		case V4L2_PIX_FMT_SBGGR8:
> -		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:
> -			dev_dbg(csi->dev, "%s: PIXEL_BIT\n", __func__);
> -			cr1 |= BIT_PIXEL_BIT;
> -			break;
> -		}
> +	switch (out_pix->pixelformat) {
> +	case V4L2_PIX_FMT_Y10:
> +	case V4L2_PIX_FMT_Y12:
> +	case V4L2_PIX_FMT_SBGGR8:
> +	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:
> +		dev_dbg(csi->dev, "%s: PIXEL_BIT\n", __func__);
> +		cr1 |= BIT_PIXEL_BIT;
> +		break;
>  	}
>  
>  	imx7_csi_reg_write(csi, cr1, CSI_CSICR1);

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH] imx7-media-csi: csi2 only
  2021-03-16 18:05   ` Laurent Pinchart
@ 2021-03-17 10:08     ` Martin Kepplinger
  2021-03-17 10:19       ` Laurent Pinchart
  0 siblings, 1 reply; 100+ messages in thread
From: Martin Kepplinger @ 2021-03-17 10:08 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam

Am Dienstag, dem 16.03.2021 um 20:05 +0200 schrieb Laurent Pinchart:
> Hi Martin,
> 
> On Tue, Mar 16, 2021 at 12:56:35PM +0100, Martin Kepplinger wrote:
> > ---
> > 
> > hi Laurent,
> > 
> > thanks a lot for posting this series!
> > 
> > First: I only test imx7-media-csi (csi bridge) because I run it on
> > imx8mq.
> > overall, I'm very happy with all of this and I get the same image
> > out
> > of it as I get with the mx6s_capture nxp driver.
> 
> That's good news :-)
> 
> > one issue I have is with is_csi2, so I post this patch that I need
> > in
> > order to test. It's obviously no solution, just to describe the
> > issue:
> > 
> > I'm not sure why but imx7_csi_pad_link_validate() isn't called in
> > my case
> > and is_csi2 doesn't get set, so I force it. Would it make sense to
> > make
> > a dts property for this?
> 
> Some platforms support both parallel and CSI-2 inputs, so we can't
> hardcode which one is used in DT. I'd advise trying to debug why the
> function is never called in your case, it's meant to be called with
> the
> following call stack
> 
> - imx7_csi_pad_link_validate() (through
> v4l2_subdev_pad_ops.link_validate)
> - v4l2_subdev_link_validate() (through
> media_entity_operations.link_validate)
> - __media_pipeline_start()
> - imx_media_pipeline_set_stream()
> - capture_start_streaming()
> - ...

possible the 2 issues are related. I have to say that media-ctl (and
the api) is kind of new to me and this is not strictly related to the
patchset anymore. The patchset is certainly required for us to have.
this is just me trying to test it properly...


I tried to set what I know that my sensor driver sends to mipi:

media-ctl -V "'csi':0 [fmt:SBGGR10/640x480 colorspace:raw]"


Device topology
- entity 1: csi (2 pads, 1 link)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
	pad0: Sink
		[fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
xfer:none ycbcr:601 quantization:full-range]
	pad1: Source
		[fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
xfer:none ycbcr:601 quantization:full-range]
		-> "csi capture":0 [ENABLED,IMMUTABLE]

- entity 4: csi capture (1 pad, 1 link)
            type Node subtype V4L flags 0
            device node name /dev/video0
	pad0: Sink
		<- "csi":1 [ENABLED,IMMUTABLE]

- entity 10: mxc-mipi-csi2.0 (0 pad, 0 link)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev1


now the mipi and camera drivers don't seem to be a "media" drivers, but
is that strictly necessary?

anyways, capture_start_streaming() calls capture_validate_fmt() which
fails due to the colorspace 0 it finds:

[   77.754721] capture_start_streaming: starting
[   77.759758] imx7-csi 30a90000.csi1_bridge: capture_validate_fmt:
capture_find_format err
[   77.768150] imx7-csi 30a90000.csi1_bridge: capture_validate_fmt:
capture_find_format found colorspace 0x0 != 0x1
[   77.778372] imx7-csi 30a90000.csi1_bridge: capture format not valid

thanks so far,
                                   martin

> 
> > The other thing is that
> > v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=0
> > doesn't call the sensor drivers' set_fmt() pad function. That means
> > that
> > only the one mode I hard-code as default will work. instead I just
> > see this:
> 
> That's expected. With a driver based on the media controller API, you
> have to configure the format on each subdev manually. You can use the
> media-ctl utility for that. The video node is only used to control
> the
> DMA engine, the kernel driver doesn't propagate the configuration to
> subdevices.
> 
> > [  742.977677] imx7-csi 30a90000.csi1_bridge: begin graph walk at
> > 'csi capture'
> > [  742.977702] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi'
> > on stack
> > [  742.977709] imx7-csi 30a90000.csi1_bridge: walk: skipping entity
> > 'csi capture' (already seen)
> > [  742.977714] imx7-csi 30a90000.csi1_bridge: walk: returning
> > entity 'csi'
> > [  742.977720] imx7-csi 30a90000.csi1_bridge: walk: returning
> > entity 'csi capture'
> > [  742.977985] imx7-csi 30a90000.csi1_bridge: begin graph walk at
> > 'csi capture'
> > [  742.977992] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi'
> > on stack
> > [  742.977997] imx7-csi 30a90000.csi1_bridge: walk: skipping entity
> > 'csi capture' (already seen)
> > [  742.978002] imx7-csi 30a90000.csi1_bridge: walk: returning
> > entity 'csi'
> > [  742.978008] imx7-csi 30a90000.csi1_bridge: walk: returning
> > entity 'csi capture'
> > [  742.978025] mc: media_release: Media Release
> > 
> > Does anything come to your mind that would prevent the set_fmt call
> > here?
> > That's what the (nxp) mipi driver looks like I'm running here:
> > https://source.puri.sm/martin.kepplinger/linux-next/-/blob/5.12-rc3/librem5__integration_byzantium/drivers/media/platform/imx8/mxc-mipi-csi2_yav.c
> > 



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

* Re: [PATCH] imx7-media-csi: csi2 only
  2021-03-17 10:08     ` Martin Kepplinger
@ 2021-03-17 10:19       ` Laurent Pinchart
  2021-03-28 14:25         ` Martin Kepplinger
  0 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-17 10:19 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam

Hi Martin,

On Wed, Mar 17, 2021 at 11:08:57AM +0100, Martin Kepplinger wrote:
> Am Dienstag, dem 16.03.2021 um 20:05 +0200 schrieb Laurent Pinchart:
> > On Tue, Mar 16, 2021 at 12:56:35PM +0100, Martin Kepplinger wrote:
> > > ---
> > > 
> > > hi Laurent,
> > > 
> > > thanks a lot for posting this series!
> > > 
> > > First: I only test imx7-media-csi (csi bridge) because I run it on imx8mq.
> > > overall, I'm very happy with all of this and I get the same image out
> > > of it as I get with the mx6s_capture nxp driver.
> > 
> > That's good news :-)
> > 
> > > one issue I have is with is_csi2, so I post this patch that I need in
> > > order to test. It's obviously no solution, just to describe the issue:
> > > 
> > > I'm not sure why but imx7_csi_pad_link_validate() isn't called in my case
> > > and is_csi2 doesn't get set, so I force it. Would it make sense to> make
> > > a dts property for this?
> > 
> > Some platforms support both parallel and CSI-2 inputs, so we can't
> > hardcode which one is used in DT. I'd advise trying to debug why the
> > function is never called in your case, it's meant to be called with the
> > following call stack
> > 
> > - imx7_csi_pad_link_validate() (through
> > v4l2_subdev_pad_ops.link_validate)
> > - v4l2_subdev_link_validate() (through
> > media_entity_operations.link_validate)
> > - __media_pipeline_start()
> > - imx_media_pipeline_set_stream()
> > - capture_start_streaming()
> > - ...
> 
> possible the 2 issues are related. I have to say that media-ctl (and
> the api) is kind of new to me and this is not strictly related to the
> patchset anymore. The patchset is certainly required for us to have.
> this is just me trying to test it properly...
> 
> 
> I tried to set what I know that my sensor driver sends to mipi:
> 
> media-ctl -V "'csi':0 [fmt:SBGGR10/640x480 colorspace:raw]"
> 
> 
> Device topology
> - entity 1: csi (2 pads, 1 link)
>             type V4L2 subdev subtype Unknown flags 0
>             device node name /dev/v4l-subdev0
> 	pad0: Sink
> 		[fmt:SBGGR10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range]
> 	pad1: Source
> 		[fmt:SBGGR10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range]
> 		-> "csi capture":0 [ENABLED,IMMUTABLE]
> 
> - entity 4: csi capture (1 pad, 1 link)
>             type Node subtype V4L flags 0
>             device node name /dev/video0
> 	pad0: Sink
> 		<- "csi":1 [ENABLED,IMMUTABLE]
> 
> - entity 10: mxc-mipi-csi2.0 (0 pad, 0 link)
>              type V4L2 subdev subtype Unknown flags 0
>              device node name /dev/v4l-subdev1

The sensor is missing from the media graph, so that's not very likely to
work :-) Has the sensor driver probed correctly ? Also, the
mxc-mipi-csi2.0 entity doesn't have pads, that's not right.

> now the mipi and camera drivers don't seem to be a "media" drivers, but
> is that strictly necessary?
>
> anyways, capture_start_streaming() calls capture_validate_fmt() which
> fails due to the colorspace 0 it finds:
> 
> [   77.754721] capture_start_streaming: starting
> [   77.759758] imx7-csi 30a90000.csi1_bridge: capture_validate_fmt: capture_find_format err
> [   77.768150] imx7-csi 30a90000.csi1_bridge: capture_validate_fmt: capture_find_format found colorspace 0x0 != 0x1
> [   77.778372] imx7-csi 30a90000.csi1_bridge: capture format not valid
> 
> > > The other thing is that
> > > v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=0
> > > doesn't call the sensor drivers' set_fmt() pad function. That means that
> > > only the one mode I hard-code as default will work. instead I just
> > > see this:
> > 
> > That's expected. With a driver based on the media controller API, you
> > have to configure the format on each subdev manually. You can use the
> > media-ctl utility for that. The video node is only used to control the
> > DMA engine, the kernel driver doesn't propagate the configuration to
> > subdevices.
> > 
> > > [  742.977677] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
> > > [  742.977702] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
> > > [  742.977709] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
> > > [  742.977714] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
> > > [  742.977720] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
> > > [  742.977985] imx7-csi 30a90000.csi1_bridge: begin graph walk at 'csi capture'
> > > [  742.977992] imx7-csi 30a90000.csi1_bridge: walk: pushing 'csi' on stack
> > > [  742.977997] imx7-csi 30a90000.csi1_bridge: walk: skipping entity 'csi capture' (already seen)
> > > [  742.978002] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi'
> > > [  742.978008] imx7-csi 30a90000.csi1_bridge: walk: returning entity 'csi capture'
> > > [  742.978025] mc: media_release: Media Release
> > > 
> > > Does anything come to your mind that would prevent the set_fmt call here?
> > > That's what the (nxp) mipi driver looks like I'm running here:
> > > https://source.puri.sm/martin.kepplinger/linux-next/-/blob/5.12-rc3/librem5__integration_byzantium/drivers/media/platform/imx8/mxc-mipi-csi2_yav.c

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (77 preceding siblings ...)
  2021-03-16 11:56 ` [PATCH] imx7-media-csi: csi2 only Martin Kepplinger
@ 2021-03-17 18:04 ` Frieder Schrempf
  2021-03-19  1:27   ` Laurent Pinchart
  78 siblings, 1 reply; 100+ messages in thread
From: Frieder Schrempf @ 2021-03-17 18:04 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Hi Laurent,

On 15.02.21 05:26, Laurent Pinchart wrote:
> Hello,
> 
> This large patch series is a collection of miscellaneous fixes, cleanups
> and enhancements for the i.MX7 camera support. Most notably, it
> implements support for the Media Controller API in the driver.
> 
> Compared to v1, review comments have been taken into account, and the
> patches have been rebased on top of the DT bindings and latest imx
> changes as present in the linux-media tree. Patches 38/77, 39/77, 60/77
> and 61/77 are new. For additional information, please see individual
> patches.
> 
> I have successfully tested the code on an i.MX6ULL board (with an
> MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an i.MX8MM
> board (with an OV5640 sensor, and additional patches for i.MX8MM
> support).

First of all, thanks for the great work!

I'm currently trying to get a setup with CSI + MIPI + ADV7280 working on 
an i.MX8MM system. Would you mind sharing the additional patches I need 
for this?

I guess you are referring to patches for the MIPI CSIS PHY and the 
devicetree. Anything else, that I'm missing?

Thanks
Frieder

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

* Re: [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-03-17 18:04 ` [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Frieder Schrempf
@ 2021-03-19  1:27   ` Laurent Pinchart
  2021-04-15  9:00     ` Frieder Schrempf
  0 siblings, 1 reply; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-19  1:27 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Hi Frieder,

On Wed, Mar 17, 2021 at 07:04:19PM +0100, Frieder Schrempf wrote:
> On 15.02.21 05:26, Laurent Pinchart wrote:
> > Hello,
> > 
> > This large patch series is a collection of miscellaneous fixes, cleanups
> > and enhancements for the i.MX7 camera support. Most notably, it
> > implements support for the Media Controller API in the driver.
> > 
> > Compared to v1, review comments have been taken into account, and the
> > patches have been rebased on top of the DT bindings and latest imx
> > changes as present in the linux-media tree. Patches 38/77, 39/77, 60/77
> > and 61/77 are new. For additional information, please see individual
> > patches.
> > 
> > I have successfully tested the code on an i.MX6ULL board (with an
> > MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an i.MX8MM
> > board (with an OV5640 sensor, and additional patches for i.MX8MM
> > support).
> 
> First of all, thanks for the great work!

You're welcome.

> I'm currently trying to get a setup with CSI + MIPI + ADV7280 working on 
> an i.MX8MM system. Would you mind sharing the additional patches I need 
> for this?
> 
> I guess you are referring to patches for the MIPI CSIS PHY and the 
> devicetree. Anything else, that I'm missing?

I've pushed my work in progress patches to

	git://linuxtv.org/pinchartl/media.git imx/next

I haven't tested this on mainline though, as the i.MX8MM board I'm using
currently requires an NXP BSP.

For the DT integration, here's what I have in imx8mm.dtsi:

			csi1_bridge: csi1_bridge@32e20000 {
				compatible = "fsl,imx8mm-csi", "fsl,imx7-csi";
				reg = <0x32e20000 0x1000>;
				interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
				clocks = <&clk IMX8MM_CLK_DISP_AXI_ROOT>,
					 <&clk IMX8MM_CLK_CSI1_ROOT>,
					 <&clk IMX8MM_CLK_DISP_APB_ROOT>;
				clock-names = "axi", "mclk", "dcic";
				power-domains = <&dispmix_pd>;
				status = "disabled";

				port {
					csi_in: endpoint {
						remote-endpoint = <&mipi_csi_out>;
					};
				};
			};

			mipi_csi: mipi_csi@32e30000 {
				compatible = "fsl,imx8mm-mipi-csi2", "fsl,imx7-mipi-csi2";
				reg = <0x32e30000 0x1000>;
				interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
				clock-frequency = <333000000>;
				clocks = <&clk IMX8MM_CLK_DISP_APB_ROOT>,
					 <&clk IMX8MM_CLK_CSI1_ROOT>,
					 <&clk IMX8MM_CLK_CSI1_PHY_REF>,
					 <&clk IMX8MM_CLK_DISP_AXI_ROOT>;
				clock-names = "pclk", "wrap", "phy", "axi";
				power-domains = <&mipi_pd>;

				status = "disabled";

				ports {
					#address-cells = <1>;
					#size-cells = <0>;

					port@0 {
						reg = <0>;
					};

					port@1 {
						reg = <1>;

						mipi_csi_out: endpoint {
							remote-endpoint = <&csi_in>;
						};
					};
				};
			};

Mainline seems to be missing the power domains, so you'll likely have to
sort this out.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH] imx7-media-csi: csi2 only
  2021-03-17 10:19       ` Laurent Pinchart
@ 2021-03-28 14:25         ` Martin Kepplinger
  2021-03-28 16:43           ` Laurent Pinchart
  0 siblings, 1 reply; 100+ messages in thread
From: Martin Kepplinger @ 2021-03-28 14:25 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam

Am Mittwoch, dem 17.03.2021 um 12:19 +0200 schrieb Laurent Pinchart:
> Hi Martin,
> 
> On Wed, Mar 17, 2021 at 11:08:57AM +0100, Martin Kepplinger wrote:
> > Am Dienstag, dem 16.03.2021 um 20:05 +0200 schrieb Laurent
> > Pinchart:
> > > On Tue, Mar 16, 2021 at 12:56:35PM +0100, Martin Kepplinger
> > > wrote:
> > > > ---
> > > > 
> > > > hi Laurent,
> > > > 
> > > > thanks a lot for posting this series!
> > > > 
> > > > First: I only test imx7-media-csi (csi bridge) because I run it
> > > > on imx8mq.
> > > > overall, I'm very happy with all of this and I get the same
> > > > image out
> > > > of it as I get with the mx6s_capture nxp driver.
> > > 
> > > That's good news :-)
> > > 
> > > > one issue I have is with is_csi2, so I post this patch that I
> > > > need in
> > > > order to test. It's obviously no solution, just to describe the
> > > > issue:
> > > > 
> > > > I'm not sure why but imx7_csi_pad_link_validate() isn't called
> > > > in my case
> > > > and is_csi2 doesn't get set, so I force it. Would it make sense
> > > > to> make
> > > > a dts property for this?
> > > 
> > > Some platforms support both parallel and CSI-2 inputs, so we
> > > can't
> > > hardcode which one is used in DT. I'd advise trying to debug why
> > > the
> > > function is never called in your case, it's meant to be called
> > > with the
> > > following call stack
> > > 
> > > - imx7_csi_pad_link_validate() (through
> > > v4l2_subdev_pad_ops.link_validate)
> > > - v4l2_subdev_link_validate() (through
> > > media_entity_operations.link_validate)
> > > - __media_pipeline_start()
> > > - imx_media_pipeline_set_stream()
> > > - capture_start_streaming()
> > > - ...
> > 
> > possible the 2 issues are related. I have to say that media-ctl
> > (and
> > the api) is kind of new to me and this is not strictly related to
> > the
> > patchset anymore. The patchset is certainly required for us to
> > have.
> > this is just me trying to test it properly...
> > 
> > 
> > I tried to set what I know that my sensor driver sends to mipi:
> > 
> > media-ctl -V "'csi':0 [fmt:SBGGR10/640x480 colorspace:raw]"
> > 
> > 
> > Device topology
> > - entity 1: csi (2 pads, 1 link)
> >             type V4L2 subdev subtype Unknown flags 0
> >             device node name /dev/v4l-subdev0
> >         pad0: Sink
> >                 [fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
> > xfer:none ycbcr:601 quantization:full-range]
> >         pad1: Source
> >                 [fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
> > xfer:none ycbcr:601 quantization:full-range]
> >                 -> "csi capture":0 [ENABLED,IMMUTABLE]
> > 
> > - entity 4: csi capture (1 pad, 1 link)
> >             type Node subtype V4L flags 0
> >             device node name /dev/video0
> >         pad0: Sink
> >                 <- "csi":1 [ENABLED,IMMUTABLE]
> > 
> > - entity 10: mxc-mipi-csi2.0 (0 pad, 0 link)
> >              type V4L2 subdev subtype Unknown flags 0
> >              device node name /dev/v4l-subdev1
> 
> The sensor is missing from the media graph, so that's not very likely
> to
> work :-) Has the sensor driver probed correctly ? Also, the
> mxc-mipi-csi2.0 entity doesn't have pads, that's not right.
> 
> 

ok. what I try is adding a mipi driver (based on nxps') to the staging
drivers and what media-ctl -p says so far is below. Despite no sensor
being shown (not sure what's missing there), the sensors' get_format()
and get_frame_interval() are being called during "media-ctl -p" and
hence the "mxc-mipi-csi2.0" sink format is correct.

somehow commands like these just don't change anything:

media-ctl -l "'mxc-mipi-csi2.0':4" -> "'csi':0[1]"
or setting already set up links to active [1] or inactive [0] doesn't
change anything either:
media-ctl -l "'csi':1" -> "'csi capture':0" "[1]"

does anything come to mind what's missing here by chance? thanks a lot
for all your help!


Media device information
------------------------
driver          imx7-csi
model           imx-media
serial          
bus info        
hw revision     0x0
driver version  5.12.0

Device topology
- entity 1: csi (2 pads, 1 link)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
	pad0: Sink
		[fmt:UYVY8_2X8/640x480 field:none colorspace:srgb
xfer:srgb ycbcr:601 quantization:lim-range]
	pad1: Source
		[fmt:UYVY8_2X8/640x480 field:none colorspace:srgb
xfer:srgb ycbcr:601 quantization:lim-range]
		-> "csi capture":0 [ENABLED,IMMUTABLE]

- entity 4: csi capture (1 pad, 1 link)
            type Node subtype V4L flags 0
            device node name /dev/video1
	pad0: Sink
		<- "csi":1 [ENABLED,IMMUTABLE]

- entity 10: mxc-mipi-csi2.0 (8 pads, 0 link)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev1
	pad0: Sink
		[fmt:SBGGR10_1X10/640x480@1/30 field:none
colorspace:unknown]
	pad1: Unknown
	pad2: Unknown
	pad3: Unknown
	pad4: Source
	pad5: Unknown
	pad6: Unknown
	pad7: Unknown




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

* Re: [PATCH] imx7-media-csi: csi2 only
  2021-03-28 14:25         ` Martin Kepplinger
@ 2021-03-28 16:43           ` Laurent Pinchart
  0 siblings, 0 replies; 100+ messages in thread
From: Laurent Pinchart @ 2021-03-28 16:43 UTC (permalink / raw)
  To: Martin Kepplinger
  Cc: ezequiel, festevam, linux-media, p.zabel, rmfrfs, slongerbeam

Hi Martin,

On Sun, Mar 28, 2021 at 04:25:26PM +0200, Martin Kepplinger wrote:
> Am Mittwoch, dem 17.03.2021 um 12:19 +0200 schrieb Laurent Pinchart:
> > On Wed, Mar 17, 2021 at 11:08:57AM +0100, Martin Kepplinger wrote:
> > > Am Dienstag, dem 16.03.2021 um 20:05 +0200 schrieb Laurent Pinchart:
> > > > On Tue, Mar 16, 2021 at 12:56:35PM +0100, Martin Kepplinger wrote:
> > > > > ---
> > > > > 
> > > > > hi Laurent,
> > > > > 
> > > > > thanks a lot for posting this series!
> > > > > 
> > > > > First: I only test imx7-media-csi (csi bridge) because I run it on imx8mq.
> > > > > overall, I'm very happy with all of this and I get the same image out
> > > > > of it as I get with the mx6s_capture nxp driver.
> > > > 
> > > > That's good news :-)
> > > > 
> > > > > one issue I have is with is_csi2, so I post this patch that I need in
> > > > > order to test. It's obviously no solution, just to describe the issue:
> > > > > 
> > > > > I'm not sure why but imx7_csi_pad_link_validate() isn't called in my case
> > > > > and is_csi2 doesn't get set, so I force it. Would it make sense to make
> > > > > a dts property for this?
> > > > 
> > > > Some platforms support both parallel and CSI-2 inputs, so we can't
> > > > hardcode which one is used in DT. I'd advise trying to debug why the
> > > > function is never called in your case, it's meant to be called with the
> > > > following call stack
> > > > 
> > > > - imx7_csi_pad_link_validate() (through
> > > > v4l2_subdev_pad_ops.link_validate)
> > > > - v4l2_subdev_link_validate() (through
> > > > media_entity_operations.link_validate)
> > > > - __media_pipeline_start()
> > > > - imx_media_pipeline_set_stream()
> > > > - capture_start_streaming()
> > > > - ...
> > > 
> > > possible the 2 issues are related. I have to say that media-ctl (and
> > > the api) is kind of new to me and this is not strictly related to the
> > > patchset anymore. The patchset is certainly required for us to have.
> > > this is just me trying to test it properly...
> > > 
> > > 
> > > I tried to set what I know that my sensor driver sends to mipi:
> > > 
> > > media-ctl -V "'csi':0 [fmt:SBGGR10/640x480 colorspace:raw]"
> > > 
> > > 
> > > Device topology
> > > - entity 1: csi (2 pads, 1 link)
> > >             type V4L2 subdev subtype Unknown flags 0
> > >             device node name /dev/v4l-subdev0
> > >         pad0: Sink
> > >                 [fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
> > > xfer:none ycbcr:601 quantization:full-range]
> > >         pad1: Source
> > >                 [fmt:SBGGR10_1X10/640x480 field:none colorspace:raw
> > > xfer:none ycbcr:601 quantization:full-range]
> > >                 -> "csi capture":0 [ENABLED,IMMUTABLE]
> > > 
> > > - entity 4: csi capture (1 pad, 1 link)
> > >             type Node subtype V4L flags 0
> > >             device node name /dev/video0
> > >         pad0: Sink
> > >                 <- "csi":1 [ENABLED,IMMUTABLE]
> > > 
> > > - entity 10: mxc-mipi-csi2.0 (0 pad, 0 link)
> > >              type V4L2 subdev subtype Unknown flags 0
> > >              device node name /dev/v4l-subdev1
> > 
> > The sensor is missing from the media graph, so that's not very likely to
> > work :-) Has the sensor driver probed correctly ? Also, the
> > mxc-mipi-csi2.0 entity doesn't have pads, that's not right.
> 
> ok. what I try is adding a mipi driver (based on nxps') to the staging
> drivers and what media-ctl -p says so far is below. Despite no sensor
> being shown (not sure what's missing there), the sensors' get_format()
> and get_frame_interval() are being called during "media-ctl -p" and
> hence the "mxc-mipi-csi2.0" sink format is correct.
> 
> somehow commands like these just don't change anything:
> 
> media-ctl -l "'mxc-mipi-csi2.0':4" -> "'csi':0[1]"
> or setting already set up links to active [1] or inactive [0] doesn't
> change anything either:
> media-ctl -l "'csi':1" -> "'csi capture':0" "[1]"
> 
> does anything come to mind what's missing here by chance? thanks a lot
> for all your help!
> 
> 
> Media device information
> ------------------------
> driver          imx7-csi
> model           imx-media
> serial          
> bus info        
> hw revision     0x0
> driver version  5.12.0
> 
> Device topology
> - entity 1: csi (2 pads, 1 link)
>             type V4L2 subdev subtype Unknown flags 0
>             device node name /dev/v4l-subdev0
> 	pad0: Sink
> 		[fmt:UYVY8_2X8/640x480 field:none colorspace:srgb
> xfer:srgb ycbcr:601 quantization:lim-range]
> 	pad1: Source
> 		[fmt:UYVY8_2X8/640x480 field:none colorspace:srgb
> xfer:srgb ycbcr:601 quantization:lim-range]
> 		-> "csi capture":0 [ENABLED,IMMUTABLE]
> 
> - entity 4: csi capture (1 pad, 1 link)
>             type Node subtype V4L flags 0
>             device node name /dev/video1
> 	pad0: Sink
> 		<- "csi":1 [ENABLED,IMMUTABLE]
> 
> - entity 10: mxc-mipi-csi2.0 (8 pads, 0 link)
>              type V4L2 subdev subtype Unknown flags 0
>              device node name /dev/v4l-subdev1
> 	pad0: Sink
> 		[fmt:SBGGR10_1X10/640x480@1/30 field:none colorspace:unknown]
> 	pad1: Unknown
> 	pad2: Unknown
> 	pad3: Unknown
> 	pad4: Source
> 	pad5: Unknown
> 	pad6: Unknown
> 	pad7: Unknown

I can't tell what wrong without looking at the code, but for instance
the 8 pads above also look fishy.

I'd recommend extending the existing imx7-mipi-csis driver instead of
creating a new driver. The CSI-2 receivers in i.MX7 and i.MX8 are very
similar, the latter having a more recent version of the same IP core
(originating from Samsung, and actually also supported in one separate
driver for Exynos which should ideally be merged with imx7-mipi-csis
into a single implementation, but that's a separate matter). A new
i.MX8-specific driver will have little chance of being accepted upstream
given the above.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-03-19  1:27   ` Laurent Pinchart
@ 2021-04-15  9:00     ` Frieder Schrempf
  2021-04-15 16:04       ` Frieder Schrempf
  0 siblings, 1 reply; 100+ messages in thread
From: Frieder Schrempf @ 2021-04-15  9:00 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

Hi Laurent,

On 19.03.21 02:27, Laurent Pinchart wrote:
> Hi Frieder,
> 
> On Wed, Mar 17, 2021 at 07:04:19PM +0100, Frieder Schrempf wrote:
>> On 15.02.21 05:26, Laurent Pinchart wrote:
>>> Hello,
>>>
>>> This large patch series is a collection of miscellaneous fixes, cleanups
>>> and enhancements for the i.MX7 camera support. Most notably, it
>>> implements support for the Media Controller API in the driver.
>>>
>>> Compared to v1, review comments have been taken into account, and the
>>> patches have been rebased on top of the DT bindings and latest imx
>>> changes as present in the linux-media tree. Patches 38/77, 39/77, 60/77
>>> and 61/77 are new. For additional information, please see individual
>>> patches.
>>>
>>> I have successfully tested the code on an i.MX6ULL board (with an
>>> MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an i.MX8MM
>>> board (with an OV5640 sensor, and additional patches for i.MX8MM
>>> support).
>>
>> First of all, thanks for the great work!
> 
> You're welcome.
> 
>> I'm currently trying to get a setup with CSI + MIPI + ADV7280 working on
>> an i.MX8MM system. Would you mind sharing the additional patches I need
>> for this?
>>
>> I guess you are referring to patches for the MIPI CSIS PHY and the
>> devicetree. Anything else, that I'm missing?
> 
> I've pushed my work in progress patches to
> 
> 	git://linuxtv.org/pinchartl/media.git imx/next
> 
> I haven't tested this on mainline though, as the i.MX8MM board I'm using
> currently requires an NXP BSP.
> 
> For the DT integration, here's what I have in imx8mm.dtsi:
> 
[...]
> 
> Mainline seems to be missing the power domains, so you'll likely have to
> sort this out.
> 

Thanks a lot for the patches. I finally found some time to test this 
with our hardware. I'm working on v5.10 mainline and applied pending 
support for the power-domains from Lucas [1].

It doesn't look bad and I can bring up the media devices, etc. but up to 
now I couldn't get any image from the ADV7280A-M.

This is the first time I'm working with the media/v4l subsystem, so I 
might be missing some trivial things. Also I'm not quite sure if the 
adv7180 driver is currently fully compatible.

Anyway here are some things I noticed. Maybe you could have a quick look 
and see if you can gather something from that, which helps me to get 
this running?

After enabling the link to the adv7180 with:

media-ctl -l "'adv7180 1-0021':0 -> 'imx7-mipi-csis.0':0[1]"

all the links look ok, but not all the parameters seem to be propagated 
up to the subdevs (see [2]). But I don't even know if this should happen 
automatically.

After setting up the format like this, the subdev setup looks ok as far 
as I can judge (see [3]):

media-ctl -V "'adv7180 1-0021':0 [fmt:UYVY2X8/720x240 field:alternate]"
media-ctl -V "'imx7-mipi-csis.0':1 [fmt:UYVY2X8/720x240 field:alternate]"

Also there is one small issue with the adv7180 not implementing neither 
V4L2_CID_LINK_FREQ nor V4L2_CID_PIXEL_RATE. So v4l2_get_link_rate() 
fails, but as this seems to be only used to calculate hs_settle, I just 
hardcoded the hs_settle value for now.

Finally I don't get any image from the analog converter. The stream 
seems to be setup correctly, but I don't receive any frames. Though I 
can see that there is data on the MIPI CSI lanes.

I'm also not quite sure which value to use for the CSI clock-frequency. 
On the clock lane of the CSI interface I can measure something around 
106 MHz coming from the ADV7280.

Maybe you got some pointers for me to look at?

Thanks
Frieder

[1] 
https://patchwork.kernel.org/project/linux-arm-kernel/cover/20201105174434.1817539-1-l.stach@pengutronix.de/
[2] https://paste.ee/p/HuIfu
[3] https://paste.ee/p/os6dU

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

* Re: [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-04-15  9:00     ` Frieder Schrempf
@ 2021-04-15 16:04       ` Frieder Schrempf
  2021-04-26  8:06         ` Frieder Schrempf
  0 siblings, 1 reply; 100+ messages in thread
From: Frieder Schrempf @ 2021-04-15 16:04 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

On 15.04.21 11:00, Frieder Schrempf wrote:
> Hi Laurent,
> 
> On 19.03.21 02:27, Laurent Pinchart wrote:
>> Hi Frieder,
>>
>> On Wed, Mar 17, 2021 at 07:04:19PM +0100, Frieder Schrempf wrote:
>>> On 15.02.21 05:26, Laurent Pinchart wrote:
>>>> Hello,
>>>>
>>>> This large patch series is a collection of miscellaneous fixes, 
>>>> cleanups
>>>> and enhancements for the i.MX7 camera support. Most notably, it
>>>> implements support for the Media Controller API in the driver.
>>>>
>>>> Compared to v1, review comments have been taken into account, and the
>>>> patches have been rebased on top of the DT bindings and latest imx
>>>> changes as present in the linux-media tree. Patches 38/77, 39/77, 60/77
>>>> and 61/77 are new. For additional information, please see individual
>>>> patches.
>>>>
>>>> I have successfully tested the code on an i.MX6ULL board (with an
>>>> MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an 
>>>> i.MX8MM
>>>> board (with an OV5640 sensor, and additional patches for i.MX8MM
>>>> support).
>>>
>>> First of all, thanks for the great work!
>>
>> You're welcome.
>>
>>> I'm currently trying to get a setup with CSI + MIPI + ADV7280 working on
>>> an i.MX8MM system. Would you mind sharing the additional patches I need
>>> for this?
>>>
>>> I guess you are referring to patches for the MIPI CSIS PHY and the
>>> devicetree. Anything else, that I'm missing?
>>
>> I've pushed my work in progress patches to
>>
>>     git://linuxtv.org/pinchartl/media.git imx/next
>>
>> I haven't tested this on mainline though, as the i.MX8MM board I'm using
>> currently requires an NXP BSP.
>>
>> For the DT integration, here's what I have in imx8mm.dtsi:
>>
> [...]
>>
>> Mainline seems to be missing the power domains, so you'll likely have to
>> sort this out.
>>
> 
> Thanks a lot for the patches. I finally found some time to test this 
> with our hardware. I'm working on v5.10 mainline and applied pending 
> support for the power-domains from Lucas [1].
> 
> It doesn't look bad and I can bring up the media devices, etc. but up to 
> now I couldn't get any image from the ADV7280A-M.
> 
> This is the first time I'm working with the media/v4l subsystem, so I 
> might be missing some trivial things. Also I'm not quite sure if the 
> adv7180 driver is currently fully compatible.
> 
> Anyway here are some things I noticed. Maybe you could have a quick look 
> and see if you can gather something from that, which helps me to get 
> this running?
> 
> After enabling the link to the adv7180 with:
> 
> media-ctl -l "'adv7180 1-0021':0 -> 'imx7-mipi-csis.0':0[1]"
> 
> all the links look ok, but not all the parameters seem to be propagated 
> up to the subdevs (see [2]). But I don't even know if this should happen 
> automatically.
> 
> After setting up the format like this, the subdev setup looks ok as far 
> as I can judge (see [3]):
> 
> media-ctl -V "'adv7180 1-0021':0 [fmt:UYVY2X8/720x240 field:alternate]"
> media-ctl -V "'imx7-mipi-csis.0':1 [fmt:UYVY2X8/720x240 field:alternate]"
> 
> Also there is one small issue with the adv7180 not implementing neither 
> V4L2_CID_LINK_FREQ nor V4L2_CID_PIXEL_RATE. So v4l2_get_link_rate() 
> fails, but as this seems to be only used to calculate hs_settle, I just 
> hardcoded the hs_settle value for now.
> 
> Finally I don't get any image from the analog converter. The stream 
> seems to be setup correctly, but I don't receive any frames. Though I 
> can see that there is data on the MIPI CSI lanes.

I discovered, that when the stream is running and I toggle the 
CSITX_PWRDN bit in the ADV7280 (disable and the enable again the MIPI 
CSI TX), I receive a single frame from the camera, but nothing more 
until I restart the streaming and toggle the CSITX_PWRDN again.

Also I'm not able to get any frame data if I try to get progressive 
frames from the ADV (setting field = none and fmt = UYVY2X8/720x480), or 
if I try to use PAL instead of NTSC.

So at least I know now that my hardware seems to work in general. But I 
still hope to get this setup fully working...

> 
> I'm also not quite sure which value to use for the CSI clock-frequency. 
> On the clock lane of the CSI interface I can measure something around 
> 106 MHz coming from the ADV7280.
> 
> Maybe you got some pointers for me to look at?
> 
> Thanks
> Frieder
> 
> [1] 
> https://patchwork.kernel.org/project/linux-arm-kernel/cover/20201105174434.1817539-1-l.stach@pengutronix.de/ 
> 
> [2] https://paste.ee/p/HuIfu
> [3] https://paste.ee/p/os6dU

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

* Re: [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-04-15 16:04       ` Frieder Schrempf
@ 2021-04-26  8:06         ` Frieder Schrempf
  0 siblings, 0 replies; 100+ messages in thread
From: Frieder Schrempf @ 2021-04-26  8:06 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Fabio Estevam

On 15.04.21 18:04, Frieder Schrempf wrote:
> On 15.04.21 11:00, Frieder Schrempf wrote:
>> Hi Laurent,
>>
>> On 19.03.21 02:27, Laurent Pinchart wrote:
>>> Hi Frieder,
>>>
>>> On Wed, Mar 17, 2021 at 07:04:19PM +0100, Frieder Schrempf wrote:
>>>> On 15.02.21 05:26, Laurent Pinchart wrote:
>>>>> Hello,
>>>>>
>>>>> This large patch series is a collection of miscellaneous fixes, 
>>>>> cleanups
>>>>> and enhancements for the i.MX7 camera support. Most notably, it
>>>>> implements support for the Media Controller API in the driver.
>>>>>
>>>>> Compared to v1, review comments have been taken into account, and the
>>>>> patches have been rebased on top of the DT bindings and latest imx
>>>>> changes as present in the linux-media tree. Patches 38/77, 39/77, 
>>>>> 60/77
>>>>> and 61/77 are new. For additional information, please see individual
>>>>> patches.
>>>>>
>>>>> I have successfully tested the code on an i.MX6ULL board (with an
>>>>> MT9M114 sensor), an I.MX7D board (with an IMX296 sensor), and an 
>>>>> i.MX8MM
>>>>> board (with an OV5640 sensor, and additional patches for i.MX8MM
>>>>> support).
>>>>
>>>> First of all, thanks for the great work!
>>>
>>> You're welcome.
>>>
>>>> I'm currently trying to get a setup with CSI + MIPI + ADV7280 
>>>> working on
>>>> an i.MX8MM system. Would you mind sharing the additional patches I need
>>>> for this?
>>>>
>>>> I guess you are referring to patches for the MIPI CSIS PHY and the
>>>> devicetree. Anything else, that I'm missing?
>>>
>>> I've pushed my work in progress patches to
>>>
>>>     git://linuxtv.org/pinchartl/media.git imx/next
>>>
>>> I haven't tested this on mainline though, as the i.MX8MM board I'm using
>>> currently requires an NXP BSP.
>>>
>>> For the DT integration, here's what I have in imx8mm.dtsi:
>>>
>> [...]
>>>
>>> Mainline seems to be missing the power domains, so you'll likely have to
>>> sort this out.
>>>
>>
>> Thanks a lot for the patches. I finally found some time to test this 
>> with our hardware. I'm working on v5.10 mainline and applied pending 
>> support for the power-domains from Lucas [1].
>>
>> It doesn't look bad and I can bring up the media devices, etc. but up 
>> to now I couldn't get any image from the ADV7280A-M.
>>
>> This is the first time I'm working with the media/v4l subsystem, so I 
>> might be missing some trivial things. Also I'm not quite sure if the 
>> adv7180 driver is currently fully compatible.
>>
>> Anyway here are some things I noticed. Maybe you could have a quick 
>> look and see if you can gather something from that, which helps me to 
>> get this running?
>>
>> After enabling the link to the adv7180 with:
>>
>> media-ctl -l "'adv7180 1-0021':0 -> 'imx7-mipi-csis.0':0[1]"
>>
>> all the links look ok, but not all the parameters seem to be 
>> propagated up to the subdevs (see [2]). But I don't even know if this 
>> should happen automatically.
>>
>> After setting up the format like this, the subdev setup looks ok as 
>> far as I can judge (see [3]):
>>
>> media-ctl -V "'adv7180 1-0021':0 [fmt:UYVY2X8/720x240 field:alternate]"
>> media-ctl -V "'imx7-mipi-csis.0':1 [fmt:UYVY2X8/720x240 field:alternate]"
>>
>> Also there is one small issue with the adv7180 not implementing 
>> neither V4L2_CID_LINK_FREQ nor V4L2_CID_PIXEL_RATE. So 
>> v4l2_get_link_rate() fails, but as this seems to be only used to 
>> calculate hs_settle, I just hardcoded the hs_settle value for now.
>>
>> Finally I don't get any image from the analog converter. The stream 
>> seems to be setup correctly, but I don't receive any frames. Though I 
>> can see that there is data on the MIPI CSI lanes.
> 
> I discovered, that when the stream is running and I toggle the 
> CSITX_PWRDN bit in the ADV7280 (disable and the enable again the MIPI 
> CSI TX), I receive a single frame from the camera, but nothing more 
> until I restart the streaming and toggle the CSITX_PWRDN again.
> 
> Also I'm not able to get any frame data if I try to get progressive 
> frames from the ADV (setting field = none and fmt = UYVY2X8/720x480), or 
> if I try to use PAL instead of NTSC.
> 
> So at least I know now that my hardware seems to work in general. But I 
> still hope to get this setup fully working...
> 

Just to wrap this up: It seems like for YUV422 you need some "special" 
settings.

First of all, just as with the RGB formats I needed to set 
MIPI_CSIS_ISPCFG_PIXEL_MODE_DUAL in the MIPI CSIS driver and 
BIT_TWO_8BIT_SENSOR in the CR3 register in the CSI driver.

Without this the MIPI CSIS hardware will always run into an overflow 
condition as soon as some data has been received.

Further I needed to set BIT_MIPI_DOUBLE_CMPNT in CR18 to get the colors 
right. No idea what it really does, but the RM mentions YUV422 in the 
description for this bit.

With this setup (and some changes on the adv7180 driver) I can get 
proper images from the camera. Though there's one problem remaining 
related to synchronization. It looks like the ADV outputs some invalid 
data at the beginning of the stream which results in an arbitrary 
horizontal and vertical offset of the image.

I guess that this could maybe be solved by implementing g_skip_frames() 
for the CSI driver, but I haven't tried that.

If anyone is interested, here is my WIP branch: 
https://git.kontron-electronics.de/linux/linux/-/commits/v5.10-mx8mm-csi.

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

end of thread, other threads:[~2021-04-26  8:06 UTC | newest]

Thread overview: 100+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15  4:26 [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 01/77] media: imx: Drop dependency on I2C Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 02/77] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 03/77] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 04/77] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
2021-02-26 15:45   ` Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 05/77] media: imx: Set default sizes through macros in all drivers Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 06/77] media: imx: utils: Add ability to filter pixel formats by mbus code Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 07/77] media: imx: capture: Use dev_* instead of v4l2_* to log messages Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 08/77] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 09/77] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 10/77] media: imx: capture: Handle errors from v4l2_fh_open() Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 11/77] media: imx: capture: Clean up capture_priv structure Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 12/77] media: imx: capture: Remove capture_priv stop field Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 13/77] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 14/77] media: imx: capture: Initialize video_device programmatically Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 15/77] media: imx: capture: Register the video device after completing init Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 16/77] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 17/77] media: imx: capture: Move default format init to a separate function Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 18/77] media: imx: capture: Rename querycap handler to capture_querycap Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 19/77] media: imx: capture: Rename ioctl operations with legacy prefix Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 20/77] media: imx: capture: Add a mechanism to disable control inheritance Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 21/77] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 22/77] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 23/77] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt() Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 24/77] media: imx: capture: Extract format lookup from __capture_legacy_try_fmt Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 25/77] media: imx: capture: Simplify capture_validate_fmt() implementation Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 26/77] media: imx: capture: Simplify __capture_legacy_try_fmt() Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 27/77] media: imx: capture: Decouple video node from source with MC-centric API Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 28/77] media: imx: capture: Expose V4L2_CAP_IO_MC for the " Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 29/77] media: imx: imx7-media-csi: Disable legacy video node API Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 30/77] media: imx: capture: Support creating immutable link to capture device Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 31/77] media: imx: imx7-media-csi: Remove control handler Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 32/77] media: imx: imx7-media-csi: Move (de)init from link setup to .s_stream() Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 33/77] media: imx: imx7-media-csi: Create immutable link to capture device Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 34/77] media: imx: imx7-media-csi: Replace CSICR*_RESET_VAL with values Laurent Pinchart
2021-02-15  4:26 ` [PATCH v2 35/77] media: imx: imx7-media-csi: Tidy up register fields macros Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 36/77] media: imx: imx7-media-csi: Reorganize code in sections Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 37/77] media: imx: imx7-media-csi: Validate capture format in .link_validate() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 38/77] media: imx: imx7-media-csi: Fix source type identification Laurent Pinchart
2021-03-01  9:30   ` Rui Miguel Silva
2021-02-15  4:27 ` [PATCH v2 39/77] media: imx: imx7-media-csi: Don't lock access to is_csi2 Laurent Pinchart
2021-03-01  9:31   ` Rui Miguel Silva
2021-02-15  4:27 ` [PATCH v2 40/77] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 41/77] media: imx: imx7-media-csi: Split imx7_csi_dma_stop() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 42/77] media: imx: imx7-media-csi: Move CSI configuration before source start Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 43/77] media: imx: imx7-media-csi: Merge streaming_start() with csi_enable() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 44/77] media: imx: imx7-media-csi: Merge hw_reset() with init_interface() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 45/77] media: imx: imx7-media-csi: Set the MIPI data type based on the bus code Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 46/77] media: imx: imx7-media-csi: Don't set the buffer stride when disabling Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 47/77] media: imx: imx7-media-csi: Merge all config in imx7_csi_configure() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 48/77] media: imx: imx7-media-csi: Clear all configurable CSICR18 fields Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 49/77] media: imx: imx7-media-csi: Set RFF burst type in imx7_csi_configure() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 50/77] media: imx: imx7-media-csi: Simplify imx7_csi_rx_fifo_clear() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 51/77] media: imx: imx7-media-csi: Don't double-enable the CSI Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 52/77] media: imx: imx7-media-csi: Don't double-enable the RxFIFO Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 53/77] media: imx: imx7-media-csi: Remove double reflash of DMA controller Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 54/77] media: imx: imx7-media-csi: Don't enable SOF and EOF interrupts Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 55/77] media: imx: imx7_media-csi: Add support for additional Bayer patterns Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 56/77] media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 57/77] media: imx: imx7_media-csi: Create immutable link to source device Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 58/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
2021-03-05 21:41   ` Rob Herring
2021-02-15  4:27 ` [PATCH v2 59/77] dt-bindings: media: nxp,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
2021-03-05 21:42   ` Rob Herring
2021-02-15  4:27 ` [PATCH v2 60/77] dt-bindings: media: nxp,imx7-mipi-csi2: Indent example with 4 spaces Laurent Pinchart
2021-03-01  9:33   ` Rui Miguel Silva
2021-03-05 21:42   ` Rob Herring
2021-02-15  4:27 ` [PATCH v2 61/77] dt-bindings: media: nxp,imx7-mipi-csi2: Expand descriptions Laurent Pinchart
2021-03-01  9:35   ` Rui Miguel Silva
2021-03-05 21:43   ` Rob Herring
2021-02-15  4:27 ` [PATCH v2 62/77] media: imx: imx7_mipi_csis: Acquire reset control without naming it Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 63/77] media: imx: imx7_mipi_csis: Fix input size alignment Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 64/77] media: imx: imx7_mipi_csis: Make source .s_power() optional Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 65/77] media: imx: imx7_mipi_csis: Avoid double get of wrap clock Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 66/77] media: imx: imx7_mipi_csis: Drop 10-bit YUV support Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 67/77] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 68/77] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 69/77] media: imx: imx7_mipi_csis: Move link setup check out of locked section Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 70/77] media: imx: imx7_mipi_csis: Calculate Ths_settle from source lane rate Laurent Pinchart
2021-03-01 16:40   ` [PATCH v2.1 " Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 71/77] media: imx: imx7_mipi_csis: Turn register access macros into functions Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 72/77] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 73/77] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 74/77] media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 75/77] media: imx: imx7_mipi_csis: Rename register macros to match datasheet Laurent Pinchart
2021-03-01 16:41   ` [PATCH v2.1 " Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 76/77] media: imx: imx7_mipi_csis: Use register macros in mipi_csis_dump_regs() Laurent Pinchart
2021-02-15  4:27 ` [PATCH v2 77/77] media: imx: imx7_mipi_csis: Print shadow registers " Laurent Pinchart
2021-03-16 11:56 ` [PATCH] imx7-media-csi: csi2 only Martin Kepplinger
2021-03-16 18:05   ` Laurent Pinchart
2021-03-17 10:08     ` Martin Kepplinger
2021-03-17 10:19       ` Laurent Pinchart
2021-03-28 14:25         ` Martin Kepplinger
2021-03-28 16:43           ` Laurent Pinchart
2021-03-17 18:04 ` [PATCH v2 00/77] media: imx: Miscellaneous fixes and cleanups for i.MX7 Frieder Schrempf
2021-03-19  1:27   ` Laurent Pinchart
2021-04-15  9:00     ` Frieder Schrempf
2021-04-15 16:04       ` Frieder Schrempf
2021-04-26  8:06         ` Frieder Schrempf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.