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

Hello,

This large patch series has been sitting in my tree for way too long. I
haven't posted it yet as I'm running into an issue on my test hardware
that I can't prove is not a regression from this series, but the
pressure has grown and the patches are better on the list for review.

There's really not much to detail in the cover letter as there are
"just" fixes and cleanups I developed while bringing up camera support
for an i.MX7D platform, and later on an i.MX8MM that shares the same
MIPI-CSI2 and CSI IP cores (with some differences).

The issue I've noticed is that the CSI writes two images consecutively
to the same buffer, overwritting memory after the end of the buffer. I
believe this bug to already be present in mainline, but I can't prove it
as my sensor won't work without some of the patches in this series. The
problem could also be sensor-specific.

Rui, would you be able to test this on your i.MX7 hardware to make sure
there's no regression ?

Laurent Pinchart (75):
  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: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
  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: 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: Convert i.MX7 MIPI CSI-2 receiver binding to YAML
  dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property
  dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle
    property
  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 pixel
    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/fsl,imx7-mipi-csi2.yaml    |  194 ++++
 .../bindings/media/imx7-mipi-csi2.txt         |   90 --
 MAINTAINERS                                   |    2 +-
 drivers/media/v4l2-core/v4l2-mc.c             |    6 +-
 drivers/staging/media/imx/Kconfig             |   12 +-
 drivers/staging/media/imx/Makefile            |    8 +-
 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    | 1016 ++++++++---------
 drivers/staging/media/imx/imx7-mipi-csis.c    |  412 ++++---
 include/media/v4l2-mc.h                       |    8 +-
 20 files changed, 1422 insertions(+), 1135 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
 delete mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt

-- 
Regards,

Laurent Pinchart


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

* [PATCH 01/75] media: imx: Drop dependency on I2C
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:21   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 02/75] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
                   ` (76 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 f555aac8a9d5..4782f7cfb709 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -18,14 +18,14 @@ menu "i.MX5/6/7 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
 	default y
 	help
 	  A video4linux camera sensor interface driver for i.MX5/6.
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 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] 121+ messages in thread

* [PATCH 02/75] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
  2021-01-05 15:27 ` [PATCH 01/75] media: imx: Drop dependency on I2C Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:21   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 03/75] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
                   ` (75 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 4782f7cfb709..76a9111c189c 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 && IMX_IPUV3_CORE
 	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,14 +19,14 @@ menu "i.MX5/6/7 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
 	default y
 	help
 	  A video4linux camera sensor interface driver for i.MX5/6.
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 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] 121+ messages in thread

* [PATCH 03/75] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
  2021-01-05 15:27 ` [PATCH 01/75] media: imx: Drop dependency on I2C Laurent Pinchart
  2021-01-05 15:27 ` [PATCH 02/75] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:22   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI Laurent Pinchart
                   ` (74 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 76a9111c189c..ce270627a7c4 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -19,14 +19,12 @@ menu "i.MX5/6/7 Media Sub devices"
 
 config VIDEO_IMX_CSI
 	tristate "i.MX5/6 Camera Sensor Interface driver"
-	depends on VIDEO_IMX_MEDIA
 	default y
 	help
 	  A video4linux camera sensor interface driver for i.MX5/6.
 
 config VIDEO_IMX7_CSI
 	tristate "i.MX6UL/L / i.MX7 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] 121+ messages in thread

* [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (2 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 03/75] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:24   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
                   ` (73 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

The i.MX7 camera drivers, selected by VIDEO_IMX7_CSI, don't depend on
IMX_IPUV3_CORE. Move the dependency from the common VIDEO_IMX_MEDIA
symbol to VIDEO_IMX_CSI.

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

diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
index ce270627a7c4..0f1277a58d3c 100644
--- a/drivers/staging/media/imx/Kconfig
+++ b/drivers/staging/media/imx/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_IMX_MEDIA
 	depends on ARCH_MXC || COMPILE_TEST
 	depends on HAS_DMA
 	depends on VIDEO_DEV
-	depends on VIDEO_V4L2 && IMX_IPUV3_CORE
+	depends on VIDEO_V4L2
 	select MEDIA_CONTROLLER
 	select V4L2_FWNODE
 	select V4L2_MEM2MEM_DEV
@@ -19,6 +19,7 @@ menu "i.MX5/6/7 Media Sub devices"
 
 config VIDEO_IMX_CSI
 	tristate "i.MX5/6 Camera Sensor Interface driver"
+	depends on IMX_IPUV3_CORE
 	default y
 	help
 	  A video4linux camera sensor interface driver for i.MX5/6.
-- 
Regards,

Laurent Pinchart


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

* [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (3 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-08 17:42   ` Ezequiel Garcia
  2021-01-05 15:27 ` [PATCH 06/75] media: imx: Set default sizes through macros in all drivers Laurent Pinchart
                   ` (72 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 drivers/staging/media/imx/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
index 9bd9e873ba7c..6ac33275cc97 100644
--- a/drivers/staging/media/imx/Makefile
+++ b/drivers/staging/media/imx/Makefile
@@ -1,16 +1,16 @@
 # 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) += imx6-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
 
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media.o
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media-csi.o
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
 
-- 
Regards,

Laurent Pinchart


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

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

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>
---
 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 21ebf7769696..434866d28bfd 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1766,8 +1766,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;
 
@@ -1780,10 +1781,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 f17135158029..5b904c3448a0 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 94d87d27d389..d12b57a5d222 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -510,7 +510,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] 121+ messages in thread

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

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>
---
 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 c1931eb2540e..eb1453ade571 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 fab1155a5958..fb2ce2128c24 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 5b904c3448a0..1761451d3003 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] 121+ messages in thread

* [PATCH 08/75] media: imx: capture: Use dev_* instead of v4l2_* to log messages
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (6 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 07/75] media: imx: utils: Add ability to filter pixel formats by mbus code Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:25   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 09/75] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
                   ` (69 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 eb1453ade571..21f01ec56bd5 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] 121+ messages in thread

* [PATCH 09/75] media: imx: capture: Use device name to construct bus_info
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (7 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 08/75] media: imx: capture: Use dev_* instead of v4l2_* to log messages Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:26   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 10/75] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
                   ` (68 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 21f01ec56bd5..8efe3d753967 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] 121+ messages in thread

* [PATCH 10/75] media: imx: capture: Remove forward declaration of capture_qops
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (8 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 09/75] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:26   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 11/75] media: imx: capture: Handle errors from v4l2_fh_open() Laurent Pinchart
                   ` (67 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 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 8efe3d753967..0b1dbff198a2 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] 121+ messages in thread

* [PATCH 11/75] media: imx: capture: Handle errors from v4l2_fh_open()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (9 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 10/75] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:27   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 12/75] media: imx: capture: Clean up capture_priv structure Laurent Pinchart
                   ` (66 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 0b1dbff198a2..b599e30df338 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] 121+ messages in thread

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

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 b599e30df338..dd3861a96cb8 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] 121+ messages in thread

* [PATCH 13/75] media: imx: capture: Remove capture_priv stop field
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (11 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 12/75] media: imx: capture: Clean up capture_priv structure Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:29   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 14/75] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
                   ` (64 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 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 dd3861a96cb8..4f9cff62eb1f 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] 121+ messages in thread

* [PATCH 14/75] media: imx: capture: Move queue and ctrl handler init to init function
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (12 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 13/75] media: imx: capture: Remove capture_priv stop field Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:30   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 15/75] media: imx: capture: Initialize video_device programmatically Laurent Pinchart
                   ` (63 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 4f9cff62eb1f..d7cc1423b71e 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);
 
@@ -821,6 +799,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);
@@ -832,8 +811,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);
 
@@ -844,8 +825,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) {
@@ -853,11 +838,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] 121+ messages in thread

* [PATCH 15/75] media: imx: capture: Initialize video_device programmatically
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (13 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 14/75] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:31   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 16/75] media: imx: capture: Register the video device after completing init Laurent Pinchart
                   ` (62 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 d7cc1423b71e..e22d98ce5d1e 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)
 {
@@ -815,17 +805,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] 121+ messages in thread

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

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>
---
 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 e22d98ce5d1e..335cb74baa4c 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] 121+ messages in thread

* [PATCH 17/75] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (15 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 16/75] media: imx: capture: Register the video device after completing init Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 14:33   ` Philipp Zabel
  2021-01-05 15:27 ` [PATCH 18/75] media: imx: capture: Move default format init to a separate function Laurent Pinchart
                   ` (60 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 335cb74baa4c..f778d9588eb3 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 434866d28bfd..3a1501434288 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 1761451d3003..483fda2f13d9 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 a3f3df901704..98eb41f6496c 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -585,7 +585,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();
@@ -667,11 +667,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;
@@ -716,7 +715,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] 121+ messages in thread

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

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>
---
 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 f778d9588eb3..009dd8733813 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] 121+ messages in thread

* [PATCH 19/75] media: imx: capture: Rename querycap handler to capture_querycap
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (17 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 18/75] media: imx: capture: Move default format init to a separate function Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 17:45   ` Steve Longerbeam
  2021-01-05 15:27 ` [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix Laurent Pinchart
                   ` (58 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 009dd8733813..db1f551b86ea 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] 121+ messages in thread

* [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (18 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 19/75] media: imx: capture: Rename querycap handler to capture_querycap Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 17:51   ` Steve Longerbeam
  2021-01-05 15:27 ` [PATCH 21/75] media: imx: capture: Add a mechanism to disable control inheritance Laurent Pinchart
                   ` (57 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 db1f551b86ea..0775e60ad894 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)
 {
@@ -821,7 +831,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] 121+ messages in thread

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

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>
---
 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 0775e60ad894..70b3d187bbc3 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)
@@ -806,7 +808,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;
@@ -820,6 +822,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);
@@ -874,9 +877,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 3a1501434288..436f3d7160fa 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1789,9 +1789,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 483fda2f13d9..16ab879e0084 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 98eb41f6496c..466e7e3567aa 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1089,7 +1089,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] 121+ messages in thread

* [PATCH 22/75] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (20 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 21/75] media: imx: capture: Add a mechanism to disable control inheritance Laurent Pinchart
@ 2021-01-05 15:27 ` Laurent Pinchart
  2021-01-06 17:55   ` Steve Longerbeam
  2021-01-05 15:28 ` [PATCH 23/75] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
                   ` (55 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:27 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 70b3d187bbc3..7932b7f0f4f2 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] 121+ messages in thread

* [PATCH 23/75] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (21 preceding siblings ...)
  2021-01-05 15:27 ` [PATCH 22/75] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-06 17:57   ` Steve Longerbeam
  2021-01-05 15:28 ` [PATCH 24/75] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt() Laurent Pinchart
                   ` (54 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 7932b7f0f4f2..d34cbf0a0fa1 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] 121+ messages in thread

* [PATCH 24/75] media: imx: capture: Return -EPIPE from __capture_legacy_try_fmt()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (22 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 23/75] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 25/75] media: imx: capture: Extract format lookup from __capture_legacy_try_fmt Laurent Pinchart
                   ` (53 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 d34cbf0a0fa1..7d23a0e7ee3a 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] 121+ messages in thread

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

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>
---
 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 7d23a0e7ee3a..775ebce92c94 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] 121+ messages in thread

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

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>
---
 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 775ebce92c94..8f3c0da371d3 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] 121+ messages in thread

* [PATCH 27/75] media: imx: capture: Simplify __capture_legacy_try_fmt()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (25 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 26/75] media: imx: capture: Simplify capture_validate_fmt() implementation Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-06 17:59   ` Steve Longerbeam
  2021-01-05 15:28 ` [PATCH 28/75] media: imx: capture: Decouple video node from source with MC-centric API Laurent Pinchart
                   ` (50 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 8f3c0da371d3..9a8e1a1400a2 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] 121+ messages in thread

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

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>
---
 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 9a8e1a1400a2..f8c1f48d5d4c 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);
@@ -838,7 +986,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] 121+ messages in thread

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

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>
---
 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 f8c1f48d5d4c..04eb612ff1fa 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,
@@ -992,7 +992,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] 121+ messages in thread

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

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>
---
 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 466e7e3567aa..afd1a7e35bfe 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1089,7 +1089,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] 121+ messages in thread

* [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (29 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 30/75] media: imx: imx7-media-csi: Disable legacy video node API Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-06 17:44   ` Steve Longerbeam
  2021-01-08 17:37   ` Ezequiel Garcia
  2021-01-05 15:28 ` [PATCH 32/75] media: imx: imx7-media-csi: Remove control handler Laurent Pinchart
                   ` (46 subsequent siblings)
  77 siblings, 2 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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..6c9c75ffb30c 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, false);
 	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 04eb612ff1fa..c6991e8f151c 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -898,12 +898,14 @@ 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,
+				      bool immutable)
 {
 	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;
+	u32 flags;
 	int ret;
 
 	/* get media device */
@@ -927,8 +929,9 @@ 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. */
+	flags = immutable ? MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE : 0;
 	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
-				    &vfd->entity, 0, 0);
+				    &vfd->entity, 0, 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 436f3d7160fa..d54d2a3789c0 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1796,7 +1796,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, false);
 	if (ret)
 		goto remove_vdev;
 
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index 16ab879e0084..4efc4d186c0a 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,
+				      bool immutable);
 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 afd1a7e35bfe..c087a212efdd 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1093,7 +1093,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, false);
 	if (ret)
 		imx_media_capture_device_remove(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

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

The control handler isn't used, drop it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 c087a212efdd..69ff491671a3 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;
 	}
 
@@ -1284,9 +1279,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;
@@ -1294,7 +1286,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)
@@ -1306,9 +1298,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);
@@ -1338,7 +1327,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] 121+ messages in thread

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

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>
---
 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 69ff491671a3..60202f56343e 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);
 
@@ -857,19 +840,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] 121+ messages in thread

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

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>
---
 drivers/staging/media/imx/imx7-media-csi.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 60202f56343e..6f39f81274b5 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:
@@ -831,7 +816,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;
 	}
@@ -1080,7 +1065,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, false);
+	ret = imx_media_capture_device_register(csi->vdev, true);
 	if (ret)
 		imx_media_capture_device_remove(csi->vdev);
 
-- 
Regards,

Laurent Pinchart


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

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

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>
---
 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 6f39f81274b5..e3dfca630d4c 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] 121+ messages in thread

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

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>
---
 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 e3dfca630d4c..3748430f993b 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] 121+ messages in thread

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

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>
---
 drivers/staging/media/imx/imx7-media-csi.c | 474 +++++++++++----------
 1 file changed, 247 insertions(+), 227 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index 3748430f993b..26ac4bf95e85 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,111 +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_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;
-
-	/*
-	 * find the entity that is selected by the CSI mux. This is needed
-	 * to distinguish between a parallel or CSI-2 pipeline.
-	 */
-	pad = imx_media_pipeline_pad(&csi->src_sd->entity, 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)
 {
@@ -542,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;
@@ -761,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);
@@ -812,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);
@@ -860,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,
@@ -1044,6 +1004,39 @@ 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_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;
+
+	/*
+	 * find the entity that is selected by the CSI mux. This is needed
+	 * to distinguish between a parallel or CSI-2 pipeline.
+	 */
+	pad = imx_media_pipeline_pad(&csi->src_sd->entity, 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);
@@ -1083,47 +1076,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 = {
@@ -1131,6 +1098,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] 121+ messages in thread

* [PATCH 38/75] media: imx: imx7-media-csi: Validate capture format in .link_validate()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (36 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 37/75] media: imx: imx7-media-csi: Reorganize code in sections Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 39/75] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup() Laurent Pinchart
                   ` (39 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 26ac4bf95e85..bc45dc5d0275 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,9 +998,15 @@ 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_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;
@@ -1020,10 +1014,6 @@ static int imx7_csi_pad_link_validate(struct v4l2_subdev *sd,
 	if (!csi->src_sd)
 		return -EPIPE;
 
-	/*
-	 * find the entity that is selected by the CSI mux. This is needed
-	 * to distinguish between a parallel or CSI-2 pipeline.
-	 */
 	pad = imx_media_pipeline_pad(&csi->src_sd->entity, 0, 0, true);
 	if (!pad)
 		return -ENODEV;
@@ -1034,6 +1024,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] 121+ messages in thread

* [PATCH 39/75] media: imx: imx7-media-csi: Rename imx7_csi_dma_start() to *_setup()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (37 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 38/75] media: imx: imx7-media-csi: Validate capture format in .link_validate() Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 40/75] media: imx: imx7-media-csi: Split imx7_csi_dma_stop() Laurent Pinchart
                   ` (38 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 bc45dc5d0275..eb13dfd82def 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] 121+ messages in thread

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

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>
---
 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 eb13dfd82def..b7e4d83bbbfc 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] 121+ messages in thread

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

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>
---
 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 b7e4d83bbbfc..7ff100e895df 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] 121+ messages in thread

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

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>
---
 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 7ff100e895df..8680f5d9ff71 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] 121+ messages in thread

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

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>
---
 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 8680f5d9ff71..0bdd169c3801 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] 121+ messages in thread

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

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>
---
 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 0bdd169c3801..6bc430ea1263 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] 121+ messages in thread

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

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>
---
 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 6bc430ea1263..f639ca5d5b2f 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] 121+ messages in thread

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

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>
---
 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 f639ca5d5b2f..bb6e2dac54a6 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] 121+ messages in thread

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

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>
---
 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 bb6e2dac54a6..17fce3b42d87 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] 121+ messages in thread

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

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>
---
 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 17fce3b42d87..7871ad55060a 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] 121+ messages in thread

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

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>
---
 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 7871ad55060a..85ab733a2c4f 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] 121+ messages in thread

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

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>
---
 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 85ab733a2c4f..31d26d7c3cfb 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] 121+ messages in thread

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

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>
---
 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 31d26d7c3cfb..d826ac45f52d 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] 121+ messages in thread

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

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>
---
 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 d826ac45f52d..7aec88b27915 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] 121+ messages in thread

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

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 7aec88b27915..b13c4c17382c 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] 121+ messages in thread

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

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>
---
 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 b13c4c17382c..a0397dd06b95 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;
 		}
@@ -961,7 +967,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] 121+ messages in thread

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

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>
---
 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 d54d2a3789c0..df48f990203a 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1902,7 +1902,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 d12b57a5d222..a82f77316c95 100644
--- a/drivers/staging/media/imx/imx6-mipi-csi2.c
+++ b/drivers/staging/media/imx/imx6-mipi-csi2.c
@@ -547,7 +547,7 @@ static int csi2_notify_bound(struct v4l2_async_notifier *notifier,
 	struct csi2_dev *csi2 = notifier_to_dev(notifier);
 	struct media_pad *sink = &csi2->sd.entity.pads[CSI2_SINK_PAD];
 
-	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 csi2_notify_ops = {
diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
index a0397dd06b95..ed11d405c98c 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1113,7 +1113,7 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	/* Mark it as such via its group id */
 	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 7612993cc1d6..d8d1556cb526 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] 121+ messages in thread

* [PATCH 56/75] media: imx: imx7_media-csi: Create immutable link to source device
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (54 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 55/75] media: v4l2-mc: Add link flags to v4l2_create_fwnode_links_to_pad() Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 57/75] dt-bindings: media: Convert i.MX7 MIPI CSI-2 receiver binding to YAML Laurent Pinchart
                   ` (21 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 ed11d405c98c..b82275af0d3e 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1050,47 +1050,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,
 };
@@ -1113,7 +1073,10 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
 	/* Mark it as such via its group id */
 	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] 121+ messages in thread

* [PATCH 57/75] dt-bindings: media: Convert i.MX7 MIPI CSI-2 receiver binding to YAML
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (55 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 56/75] media: imx: imx7_media-csi: Create immutable link to source device Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:43   ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 58/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
                   ` (20 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Rob Herring, devicetree

Convert the DT binding for the i.MX7 MIPI CSI-2 receiver to YAML. Add
Rui to the maintainers list as he's the original author of the binding.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../bindings/media/fsl,imx7-mipi-csi2.yaml    | 204 ++++++++++++++++++
 .../bindings/media/imx7-mipi-csi2.txt         |  90 --------
 MAINTAINERS                                   |   2 +-
 3 files changed, 205 insertions(+), 91 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
 delete mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt

diff --git a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
new file mode 100644
index 000000000000..2df997293780
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
@@ -0,0 +1,204 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/fsl,imx7-mipi-csi2.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP i.MX7 MIPI CSI-2 receiver
+
+maintainers:
+  - Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+  - Rui Miguel Silva <rui.silva@linaro.org>
+
+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:
+    const: fsl,imx7-mipi-csi2
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    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:
+      - const: pclk
+      - const: wrap
+      - const: phy
+
+  resets:
+    items:
+      - description: MIPI D-PHY slave reset
+
+  reset-names:
+    items:
+      - const: mrst
+
+  power-domains: true
+
+  phy-supply:
+    description: The MIPI D-PHY digital power supply
+
+  clock-frequency:
+    description: The desired external clock ("wrap") frequency, in Hz
+    default: 166000000
+
+  fsl,csis-hs-settle:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: HS-SETTLE time (unit unknown)
+
+  ports:
+    # See ./video-interfaces.txt for details
+    type: object
+
+    properties:
+      "#address-cells":
+        $ref: /schemas/types.yaml#/definitions/uint32
+        const: 1
+
+      "#size-cells":
+        $ref: /schemas/types.yaml#/definitions/uint32
+        const: 0
+
+      port@0:
+        type: object
+        description: The input port, connected to the CSI-2 source
+
+        properties:
+          reg:
+            const: 0
+
+          endpoint:
+            type: object
+
+            properties:
+              data-lanes:
+                $ref: /schemas/types.yaml#/definitions/uint32-array
+                items:
+                  minItems: 1
+                  maxItems: 2
+                  items:
+                    - const: 1
+                    - const: 2
+
+              remote-endpoint:
+                $ref: /schemas/types.yaml#/definitions/phandle
+
+            required:
+              - data-lanes
+              - remote-endpoint
+
+            additionalProperties: false
+
+        required:
+          - reg
+
+        additionalProperties: false
+
+      port@1:
+        type: object
+        description: The output port
+
+        properties:
+          reg:
+            const: 1
+
+          endpoint:
+            type: object
+
+            properties:
+              remote-endpoint:
+                $ref: /schemas/types.yaml#/definitions/phandle
+
+            required:
+              - remote-endpoint
+
+            additionalProperties: false
+
+        required:
+          - reg
+
+        additionalProperties: false
+
+    required:
+      - "#address-cells"
+      - "#size-cells"
+      - port@0
+      - port@1
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - power-domains
+  - phy-supply
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/imx7d-clock.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #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>;
+        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>;
+        reset-names = "mrst";
+        fsl,csis-hs-settle = <3>;
+
+        ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            port@0 {
+                reg = <0>;
+
+                mipi_csi_in: endpoint {
+                    remote-endpoint = <&ov2680_out>;
+                    data-lanes = <1>;
+                };
+            };
+
+            port@1 {
+                reg = <1>;
+
+                mipi_csi_out: endpoint {
+                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
+                };
+            };
+        };
+    };
+
+...
diff --git a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
deleted file mode 100644
index 71fd74ed3ec8..000000000000
--- a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
+++ /dev/null
@@ -1,90 +0,0 @@
-Freescale i.MX7 Mipi CSI2
-=========================
-
-mipi_csi2 node
---------------
-
-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.
-
-Required properties:
-
-- compatible    : "fsl,imx7-mipi-csi2";
-- reg           : base address and length of the register set for the device;
-- interrupts    : should contain MIPI CSIS interrupt;
-- clocks        : list of clock specifiers, see
-        Documentation/devicetree/bindings/clock/clock-bindings.txt for details;
-- clock-names   : must contain "pclk", "wrap" and "phy" entries, matching
-                  entries in the clock property;
-- power-domains : a phandle to the power domain, see
-          Documentation/devicetree/bindings/power/power_domain.txt for details.
-- reset-names   : should include following entry "mrst";
-- resets        : a list of phandle, should contain reset entry of
-                  reset-names;
-- phy-supply    : from the generic phy bindings, a phandle to a regulator that
-	          provides power to MIPI CSIS core;
-
-Optional properties:
-
-- clock-frequency : The IP's main (system bus) clock frequency in Hz, default
-		    value when this property is not specified is 166 MHz;
-- fsl,csis-hs-settle : differential receiver (HS-RX) settle time;
-
-The device node should contain two 'port' child nodes with one child 'endpoint'
-node, according to the bindings defined in:
- Documentation/devicetree/bindings/ media/video-interfaces.txt.
- The following are properties specific to those nodes.
-
-port node
----------
-
-- reg		  : (required) can take the values 0 or 1, where 0 shall be
-                     related to the sink port and port 1 shall be the source
-                     one;
-
-endpoint node
--------------
-
-- data-lanes    : (required) an array specifying active physical MIPI-CSI2
-		    data input lanes and their mapping to logical lanes; this
-                    shall only be applied to port 0 (sink port), the array's
-                    content is unused only its length is meaningful,
-                    in this case the maximum length supported is 2;
-
-example:
-
-        mipi_csi: mipi-csi@30750000 {
-                #address-cells = <1>;
-                #size-cells = <0>;
-
-                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>;
-                power-domains = <&pgc_mipi_phy>;
-                phy-supply = <&reg_1p0d>;
-                resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
-                reset-names = "mrst";
-                fsl,csis-hs-settle = <3>;
-
-                port@0 {
-                        reg = <0>;
-
-                        mipi_from_sensor: endpoint {
-                                remote-endpoint = <&ov2680_to_mipi>;
-                                data-lanes = <1>;
-                        };
-                };
-
-                port@1 {
-                        reg = <1>;
-
-                        mipi_vc0_to_csi_mux: endpoint {
-                                remote-endpoint = <&csi_mux_from_mipi_vc0>;
-                        };
-                };
-        };
diff --git a/MAINTAINERS b/MAINTAINERS
index 970d9cee509d..584ea2116c38 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10842,8 +10842,8 @@ L:	linux-media@vger.kernel.org
 S:	Maintained
 T:	git git://linuxtv.org/media_tree.git
 F:	Documentation/admin-guide/media/imx7.rst
+F:	Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
 F:	Documentation/devicetree/bindings/media/imx7-csi.txt
-F:	Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
 F:	drivers/staging/media/imx/imx7-media-csi.c
 F:	drivers/staging/media/imx/imx7-mipi-csis.c
 
-- 
Regards,

Laurent Pinchart


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

* [PATCH 58/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (56 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 57/75] dt-bindings: media: Convert i.MX7 MIPI CSI-2 receiver binding to YAML Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
                   ` (19 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, 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>
---
 .../devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml     | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
index 2df997293780..d8918ba3b06c 100644
--- a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
@@ -45,10 +45,6 @@ properties:
     items:
       - description: MIPI D-PHY slave reset
 
-  reset-names:
-    items:
-      - const: mrst
-
   power-domains: true
 
   phy-supply:
@@ -150,7 +146,6 @@ required:
   - clocks
   - clock-names
   - resets
-  - reset-names
   - power-domains
   - phy-supply
   - ports
@@ -174,8 +169,7 @@ examples:
         clock-frequency = <166000000>;
         power-domains = <&pgc_mipi_phy>;
         phy-supply = <&reg_1p0d>;
-        resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
-        reset-names = "mrst";
+        resets = <&src IMX7_RESET_MIPI_PHY_SRST>;
         fsl,csis-hs-settle = <3>;
 
         ports {
-- 
Regards,

Laurent Pinchart


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

* [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (57 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 58/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-06 22:49   ` Sakari Ailus
  2021-01-05 15:28 ` [PATCH 60/75] media: imx: imx7_mipi_csis: Acquire reset control without naming it Laurent Pinchart
                   ` (18 subsequent siblings)
  77 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, 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>
---
 .../devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml         | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
index d8918ba3b06c..656aac67470d 100644
--- a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
+++ b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
@@ -54,10 +54,6 @@ properties:
     description: The desired external clock ("wrap") frequency, in Hz
     default: 166000000
 
-  fsl,csis-hs-settle:
-    $ref: /schemas/types.yaml#/definitions/uint32
-    description: HS-SETTLE time (unit unknown)
-
   ports:
     # See ./video-interfaces.txt for details
     type: object
-- 
Regards,

Laurent Pinchart


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

* [PATCH 60/75] media: imx: imx7_mipi_csis: Acquire reset control without naming it
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (58 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 61/75] media: imx: imx7_mipi_csis: Fix input size alignment Laurent Pinchart
                   ` (17 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 d8d1556cb526..b6a808cddb37 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] 121+ messages in thread

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

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>
---
 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 b6a808cddb37..fe8f3fdab832 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] 121+ messages in thread

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

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>
---
 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 fe8f3fdab832..75facfc85dde 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] 121+ messages in thread

* [PATCH 63/75] media: imx: imx7_mipi_csis: Avoid double get of wrap clock
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (61 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 62/75] media: imx: imx7_mipi_csis: Make source .s_power() optional Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 64/75] media: imx: imx7_mipi_csis: Drop 10-bit YUV support Laurent Pinchart
                   ` (14 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 75facfc85dde..7994b3f54933 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);
@@ -1154,9 +1155,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] 121+ messages in thread

* [PATCH 64/75] media: imx: imx7_mipi_csis: Drop 10-bit YUV support
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (62 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 63/75] media: imx: imx7_mipi_csis: Avoid double get of wrap clock Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 65/75] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format Laurent Pinchart
                   ` (13 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 7994b3f54933..5a5b3723f0a8 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] 121+ messages in thread

* [PATCH 65/75] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (63 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 64/75] media: imx: imx7_mipi_csis: Drop 10-bit YUV support Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 66/75] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle() Laurent Pinchart
                   ` (12 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 5a5b3723f0a8..938503601c60 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] 121+ messages in thread

* [PATCH 66/75] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (64 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 65/75] media: imx: imx7_mipi_csis: Fix UYVY8 media bus format Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 67/75] media: imx: imx7_mipi_csis: Move link setup check out of locked section Laurent Pinchart
                   ` (11 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 938503601c60..4e85611fcdc6 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] 121+ messages in thread

* [PATCH 67/75] media: imx: imx7_mipi_csis: Move link setup check out of locked section
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (65 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 66/75] media: imx: imx7_mipi_csis: Inline mipi_csis_set_hsync_settle() Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate Laurent Pinchart
                   ` (10 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 4e85611fcdc6..3c68ee8b2a59 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] 121+ messages in thread

* [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (66 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 67/75] media: imx: imx7_mipi_csis: Move link setup check out of locked section Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-06 22:59   ` Sakari Ailus
  2021-01-11  9:39   ` Rui Miguel Silva
  2021-01-05 15:28 ` [PATCH 69/75] media: imx: imx7_mipi_csis: Turn register access macros into functions Laurent Pinchart
                   ` (9 subsequent siblings)
  77 siblings, 2 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

The Ths_settle timing parameter depends solely on the pixel 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>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 65 ++++++++++++++++++----
 1 file changed, 53 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 3c68ee8b2a59..c83450ac37fa 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-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-mc.h>
@@ -233,7 +234,11 @@ struct csi_state {
 	struct media_pad pads[CSIS_PADS_NUM];
 	struct v4l2_subdev mipi_sd;
 	struct v4l2_async_notifier notifier;
-	struct v4l2_subdev *src_sd;
+
+	struct {
+		struct v4l2_subdev *sd;
+		struct v4l2_ctrl *pixel_rate;
+	} src;
 
 	u8 index;
 	struct platform_device *pdev;
@@ -482,6 +487,31 @@ 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)
+{
+	u64 pixel_rate;
+	u32 lane_rate;
+
+	/* Calculate the line rate from the pixel rate. */
+	pixel_rate = v4l2_ctrl_g_ctrl_int64(state->src.pixel_rate);
+	lane_rate = div_u64(pixel_rate, state->bus.num_data_lanes)
+		  * state->csis_fmt->width;
+	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, "pixel rate %llu, lane rate %u, Ths_settle %u\n",
+		pixel_rate, 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,16 +638,20 @@ 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) {
 			pm_runtime_put_noidle(&state->pdev->dev);
 			return ret;
 		}
-		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
+		ret = v4l2_subdev_call(state->src.sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			return ret;
 	}
@@ -630,7 +664,7 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 		}
 
 		mipi_csis_start_stream(state);
-		ret = v4l2_subdev_call(state->src_sd, video, s_stream, 1);
+		ret = v4l2_subdev_call(state->src.sd, video, s_stream, 1);
 		if (ret < 0)
 			goto unlock;
 
@@ -638,8 +672,8 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		state->flags |= ST_STREAMING;
 	} else {
-		v4l2_subdev_call(state->src_sd, video, s_stream, 0);
-		ret = v4l2_subdev_call(state->src_sd, core, s_power, 0);
+		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);
@@ -677,14 +711,24 @@ static int mipi_csis_link_setup(struct media_entity *entity,
 	mutex_lock(&state->lock);
 
 	if (flags & MEDIA_LNK_FL_ENABLED) {
-		if (state->src_sd) {
+		if (state->src.sd) {
 			ret = -EBUSY;
 			goto out;
 		}
 
-		state->src_sd = remote_sd;
+		state->src.pixel_rate = v4l2_ctrl_find(remote_sd->ctrl_handler,
+						       V4L2_CID_PIXEL_RATE);
+		if (!state->src.pixel_rate) {
+			dev_err(state->dev,
+				"source %s has no pixel rate control\n",
+				remote_sd->name);
+			return -EINVAL;
+		}
+
+		state->src.sd = remote_sd;
 	} else {
-		state->src_sd = NULL;
+		state->src.pixel_rate = NULL;
+		state->src.sd = NULL;
 	}
 
 out:
@@ -943,9 +987,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] 121+ messages in thread

* [PATCH 69/75] media: imx: imx7_mipi_csis: Turn register access macros into functions
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (67 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 70/75] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register Laurent Pinchart
                   ` (8 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 c83450ac37fa..63424a81c800 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -362,8 +362,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] 121+ messages in thread

* [PATCH 70/75] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (68 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 69/75] media: imx: imx7_mipi_csis: Turn register access macros into functions Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 71/75] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields Laurent Pinchart
                   ` (7 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 63424a81c800..14496c6cbc09 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -532,10 +532,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] 121+ messages in thread

* [PATCH 71/75] media: imx: imx7_mipi_csis: Define macros for DPHY_BCTRL_L fields
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (69 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 70/75] media: imx: imx7_mipi_csis: Fully initialize MIPI_CSIS_DPHYCTRL register Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 15:28 ` [PATCH 72/75] media: imx: imx7_mipi_csis: Make ISP registers macros take channel ID Laurent Pinchart
                   ` (6 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 14496c6cbc09..75df91527dbd 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
@@ -546,8 +580,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] 121+ messages in thread

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

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>
---
 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 75df91527dbd..7c298a295cef 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
@@ -518,14 +506,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)
@@ -572,7 +560,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] 121+ messages in thread

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

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

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 7c298a295cef..5bbb26993597 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)
@@ -448,7 +448,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)
@@ -490,13 +490,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 */
@@ -506,14 +506,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)
@@ -554,13 +554,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;
@@ -961,12 +961,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;
@@ -975,7 +975,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] 121+ messages in thread

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

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>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 5bbb26993597..63a150be3bd6 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -403,23 +403,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] 121+ messages in thread

* [PATCH 75/75] media: imx: imx7_mipi_csis: Print shadow registers in mipi_csis_dump_regs()
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (73 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 74/75] media: imx: imx7_mipi_csis: Use register macros in mipi_csis_dump_regs() Laurent Pinchart
@ 2021-01-05 15:28 ` Laurent Pinchart
  2021-01-05 17:45 ` [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Fabio Estevam
                   ` (2 subsequent siblings)
  77 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:28 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

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>
---
 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 63a150be3bd6..944518a9fd58 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)
+
 /* Non-image packet data buffers */
 #define MIPI_CSIS_PKTDATA_ODD			0x2000
 #define MIPI_CSIS_PKTDATA_EVEN			0x3000
@@ -412,6 +417,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] 121+ messages in thread

* Re: [PATCH 57/75] dt-bindings: media: Convert i.MX7 MIPI CSI-2 receiver binding to YAML
  2021-01-05 15:28 ` [PATCH 57/75] dt-bindings: media: Convert i.MX7 MIPI CSI-2 receiver binding to YAML Laurent Pinchart
@ 2021-01-05 15:43   ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-05 15:43 UTC (permalink / raw)
  To: linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Rob Herring, devicetree

This isn't applicable anymore as Rui had already converted the DT
bindings. Sorry for the noise.

(I may however send additional patches, for instance to add descriptions
for the clocks).

On Tue, Jan 05, 2021 at 05:28:34PM +0200, Laurent Pinchart wrote:
> Convert the DT binding for the i.MX7 MIPI CSI-2 receiver to YAML. Add
> Rui to the maintainers list as he's the original author of the binding.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  .../bindings/media/fsl,imx7-mipi-csi2.yaml    | 204 ++++++++++++++++++
>  .../bindings/media/imx7-mipi-csi2.txt         |  90 --------
>  MAINTAINERS                                   |   2 +-
>  3 files changed, 205 insertions(+), 91 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
>  delete mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> 
> diff --git a/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
> new file mode 100644
> index 000000000000..2df997293780
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
> @@ -0,0 +1,204 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/media/fsl,imx7-mipi-csi2.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: NXP i.MX7 MIPI CSI-2 receiver
> +
> +maintainers:
> +  - Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> +  - Rui Miguel Silva <rui.silva@linaro.org>
> +
> +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:
> +    const: fsl,imx7-mipi-csi2
> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  clocks:
> +    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:
> +      - const: pclk
> +      - const: wrap
> +      - const: phy
> +
> +  resets:
> +    items:
> +      - description: MIPI D-PHY slave reset
> +
> +  reset-names:
> +    items:
> +      - const: mrst
> +
> +  power-domains: true
> +
> +  phy-supply:
> +    description: The MIPI D-PHY digital power supply
> +
> +  clock-frequency:
> +    description: The desired external clock ("wrap") frequency, in Hz
> +    default: 166000000
> +
> +  fsl,csis-hs-settle:
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    description: HS-SETTLE time (unit unknown)
> +
> +  ports:
> +    # See ./video-interfaces.txt for details
> +    type: object
> +
> +    properties:
> +      "#address-cells":
> +        $ref: /schemas/types.yaml#/definitions/uint32
> +        const: 1
> +
> +      "#size-cells":
> +        $ref: /schemas/types.yaml#/definitions/uint32
> +        const: 0
> +
> +      port@0:
> +        type: object
> +        description: The input port, connected to the CSI-2 source
> +
> +        properties:
> +          reg:
> +            const: 0
> +
> +          endpoint:
> +            type: object
> +
> +            properties:
> +              data-lanes:
> +                $ref: /schemas/types.yaml#/definitions/uint32-array
> +                items:
> +                  minItems: 1
> +                  maxItems: 2
> +                  items:
> +                    - const: 1
> +                    - const: 2
> +
> +              remote-endpoint:
> +                $ref: /schemas/types.yaml#/definitions/phandle
> +
> +            required:
> +              - data-lanes
> +              - remote-endpoint
> +
> +            additionalProperties: false
> +
> +        required:
> +          - reg
> +
> +        additionalProperties: false
> +
> +      port@1:
> +        type: object
> +        description: The output port
> +
> +        properties:
> +          reg:
> +            const: 1
> +
> +          endpoint:
> +            type: object
> +
> +            properties:
> +              remote-endpoint:
> +                $ref: /schemas/types.yaml#/definitions/phandle
> +
> +            required:
> +              - remote-endpoint
> +
> +            additionalProperties: false
> +
> +        required:
> +          - reg
> +
> +        additionalProperties: false
> +
> +    required:
> +      - "#address-cells"
> +      - "#size-cells"
> +      - port@0
> +      - port@1
> +
> +    additionalProperties: false
> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +  - clocks
> +  - clock-names
> +  - resets
> +  - reset-names
> +  - power-domains
> +  - phy-supply
> +  - ports
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/clock/imx7d-clock.h>
> +    #include <dt-bindings/interrupt-controller/arm-gic.h>
> +    #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>;
> +        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>;
> +        reset-names = "mrst";
> +        fsl,csis-hs-settle = <3>;
> +
> +        ports {
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            port@0 {
> +                reg = <0>;
> +
> +                mipi_csi_in: endpoint {
> +                    remote-endpoint = <&ov2680_out>;
> +                    data-lanes = <1>;
> +                };
> +            };
> +
> +            port@1 {
> +                reg = <1>;
> +
> +                mipi_csi_out: endpoint {
> +                    remote-endpoint = <&csi_mux_from_mipi_vc0>;
> +                };
> +            };
> +        };
> +    };
> +
> +...
> diff --git a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt b/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> deleted file mode 100644
> index 71fd74ed3ec8..000000000000
> --- a/Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> +++ /dev/null
> @@ -1,90 +0,0 @@
> -Freescale i.MX7 Mipi CSI2
> -=========================
> -
> -mipi_csi2 node
> ---------------
> -
> -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.
> -
> -Required properties:
> -
> -- compatible    : "fsl,imx7-mipi-csi2";
> -- reg           : base address and length of the register set for the device;
> -- interrupts    : should contain MIPI CSIS interrupt;
> -- clocks        : list of clock specifiers, see
> -        Documentation/devicetree/bindings/clock/clock-bindings.txt for details;
> -- clock-names   : must contain "pclk", "wrap" and "phy" entries, matching
> -                  entries in the clock property;
> -- power-domains : a phandle to the power domain, see
> -          Documentation/devicetree/bindings/power/power_domain.txt for details.
> -- reset-names   : should include following entry "mrst";
> -- resets        : a list of phandle, should contain reset entry of
> -                  reset-names;
> -- phy-supply    : from the generic phy bindings, a phandle to a regulator that
> -	          provides power to MIPI CSIS core;
> -
> -Optional properties:
> -
> -- clock-frequency : The IP's main (system bus) clock frequency in Hz, default
> -		    value when this property is not specified is 166 MHz;
> -- fsl,csis-hs-settle : differential receiver (HS-RX) settle time;
> -
> -The device node should contain two 'port' child nodes with one child 'endpoint'
> -node, according to the bindings defined in:
> - Documentation/devicetree/bindings/ media/video-interfaces.txt.
> - The following are properties specific to those nodes.
> -
> -port node
> ----------
> -
> -- reg		  : (required) can take the values 0 or 1, where 0 shall be
> -                     related to the sink port and port 1 shall be the source
> -                     one;
> -
> -endpoint node
> --------------
> -
> -- data-lanes    : (required) an array specifying active physical MIPI-CSI2
> -		    data input lanes and their mapping to logical lanes; this
> -                    shall only be applied to port 0 (sink port), the array's
> -                    content is unused only its length is meaningful,
> -                    in this case the maximum length supported is 2;
> -
> -example:
> -
> -        mipi_csi: mipi-csi@30750000 {
> -                #address-cells = <1>;
> -                #size-cells = <0>;
> -
> -                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>;
> -                power-domains = <&pgc_mipi_phy>;
> -                phy-supply = <&reg_1p0d>;
> -                resets = <&src IMX7_RESET_MIPI_PHY_MRST>;
> -                reset-names = "mrst";
> -                fsl,csis-hs-settle = <3>;
> -
> -                port@0 {
> -                        reg = <0>;
> -
> -                        mipi_from_sensor: endpoint {
> -                                remote-endpoint = <&ov2680_to_mipi>;
> -                                data-lanes = <1>;
> -                        };
> -                };
> -
> -                port@1 {
> -                        reg = <1>;
> -
> -                        mipi_vc0_to_csi_mux: endpoint {
> -                                remote-endpoint = <&csi_mux_from_mipi_vc0>;
> -                        };
> -                };
> -        };
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 970d9cee509d..584ea2116c38 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -10842,8 +10842,8 @@ L:	linux-media@vger.kernel.org
>  S:	Maintained
>  T:	git git://linuxtv.org/media_tree.git
>  F:	Documentation/admin-guide/media/imx7.rst
> +F:	Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
>  F:	Documentation/devicetree/bindings/media/imx7-csi.txt
> -F:	Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
>  F:	drivers/staging/media/imx/imx7-media-csi.c
>  F:	drivers/staging/media/imx/imx7-mipi-csis.c
>  

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (74 preceding siblings ...)
  2021-01-05 15:28 ` [PATCH 75/75] media: imx: imx7_mipi_csis: Print shadow registers " Laurent Pinchart
@ 2021-01-05 17:45 ` Fabio Estevam
  2021-01-05 19:00   ` Fabio Estevam
  2021-01-06 15:41   ` Laurent Pinchart
  2021-01-05 19:29 ` Rui Miguel Silva
  2021-01-11  9:53 ` Rui Miguel Silva
  77 siblings, 2 replies; 121+ messages in thread
From: Fabio Estevam @ 2021-01-05 17:45 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Laurent,

On Tue, Jan 5, 2021 at 12:31 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hello,
>
> This large patch series has been sitting in my tree for way too long. I
> haven't posted it yet as I'm running into an issue on my test hardware
> that I can't prove is not a regression from this series, but the
> pressure has grown and the patches are better on the list for review.
>
> There's really not much to detail in the cover letter as there are
> "just" fixes and cleanups I developed while bringing up camera support
> for an i.MX7D platform, and later on an i.MX8MM that shares the same
> MIPI-CSI2 and CSI IP cores (with some differences).
>
> The issue I've noticed is that the CSI writes two images consecutively
> to the same buffer, overwritting memory after the end of the buffer. I
> believe this bug to already be present in mainline, but I can't prove it
> as my sensor won't work without some of the patches in this series. The
> problem could also be sensor-specific.
>
> Rui, would you be able to test this on your i.MX7 hardware to make sure
> there's no regression ?

Thanks for your series.

I tested it on a imx6ul-evk board.

There is a build error introduced by patch 74/75. I fixed it like this:

--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -193,6 +193,8 @@
 #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                     0x20
 /* Non-image packet data buffers */
 #define MIPI_CSIS_PKTDATA_ODD                  0x2000
 #define MIPI_CSIS_PKTDATA_EVEN                 0x3000

Then I applied my patch and Rui's to fix the imx6ul regression as per
the other thread we have been discussing, but I was not able to
capture:

# gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps =
video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
framerate=(fraction)120/1, interlace-mode=(string)progressive,
colorimetr
y=(string)1:1:5:1
/GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:src: caps =
video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
framerate=(fraction)120/1, interlace-mode=(string)progressive, color
imetry=(string)1:1:5:1
/GstPipeline:pipeline0/GstFBDEVSink:fbdevsink0.GstPad:sink: caps =
video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
framerate=(fraction)120/1, interlace-mode=(string)progressive, color
imetry=(string)1:1:5:1
/GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:sink: caps =
video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
framerate=(fraction)120/1, interlace-mode=(string)progressive, colo
rimetry=(string)1:1:5:1
[   32.783736] cma: cma_alloc: alloc failed, req-size: 8100 pages, ret: -12
[   32.791332] imx7-csi 21c4000.csi: dma_alloc_coherent of size 33177600 failed
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed
to allocate required memory.
Additional debug info:
../sys/v4l2/gstv4l2src.c(659): gst_v4l2src_decide_allocation ():
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Buffer pool activation failed
Execution ended after 0:00:00.214658125
Setting pipeline to NULL ...
Freeing pipeline ...

As shown above the dimensions and framerate are incorrectly reported
as: width=(int)3840, height=(int)2160, framerate=(fraction)120/1

Previously it was:

# gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps =
video/x-raw, format=(string)UYVY, width=(int)320, height=(int)240,
framerate=(fraction)30000/1001, interlace-mode=(string)progressive,
colorim
etry=(string)1:4:7:1
/GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:src: caps =
video/x-raw, format=(string)BGRx, width=(int)320, height=(int)240,
framerate=(fraction)30000/1001, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstFBDEVSink:fbdevsink0.GstPad:sink: caps =
video/x-raw, format=(string)BGRx, width=(int)320, height=(int)240,
framerate=(fraction)30000/1001, interlace-mode=(string)progressive
/GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:sink: caps =
video/x-raw, format=(string)UYVY, width=(int)320, height=(int)240,
framerate=(fraction)30000/1001, interlace-mode=(string)progressive, c
olorimetry=(string)1:4:7:1

Thanks

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-05 17:45 ` [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Fabio Estevam
@ 2021-01-05 19:00   ` Fabio Estevam
  2021-01-06 15:41   ` Laurent Pinchart
  1 sibling, 0 replies; 121+ messages in thread
From: Fabio Estevam @ 2021-01-05 19:00 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

On Tue, Jan 5, 2021 at 2:45 PM Fabio Estevam <festevam@gmail.com> wrote:

> There is a build error introduced by patch 74/75. I fixed it like this:
>
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -193,6 +193,8 @@
>  #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                     0x20

I meant 0xc0 here, sorry.

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (75 preceding siblings ...)
  2021-01-05 17:45 ` [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Fabio Estevam
@ 2021-01-05 19:29 ` Rui Miguel Silva
  2021-01-11  9:53 ` Rui Miguel Silva
  77 siblings, 0 replies; 121+ messages in thread
From: Rui Miguel Silva @ 2021-01-05 19:29 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

Hey Laurent,
On Tue, Jan 05, 2021 at 05:27:37PM +0200, Laurent Pinchart wrote:
> Hello,
> 
> This large patch series has been sitting in my tree for way too long. I
> haven't posted it yet as I'm running into an issue on my test hardware
> that I can't prove is not a regression from this series, but the
> pressure has grown and the patches are better on the list for review.
> 
> There's really not much to detail in the cover letter as there are
> "just" fixes and cleanups I developed while bringing up camera support
> for an i.MX7D platform, and later on an i.MX8MM that shares the same
> MIPI-CSI2 and CSI IP cores (with some differences).
> 
> The issue I've noticed is that the CSI writes two images consecutively
> to the same buffer, overwritting memory after the end of the buffer. I
> believe this bug to already be present in mainline, but I can't prove it
> as my sensor won't work without some of the patches in this series. The
> problem could also be sensor-specific.
> 
> Rui, would you be able to test this on your i.MX7 hardware to make sure
> there's no regression ?

Thanks for these small improvements, ehehh.

Well, we already have a regression reported by Fabio in imx6ull, but
just give a couple of days to go over this and restore my setup with
the warp7 board.

------
Cheers,
     Rui
> 
> Laurent Pinchart (75):
>   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: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
>   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: 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: Convert i.MX7 MIPI CSI-2 receiver binding to YAML
>   dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property
>   dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle
>     property
>   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 pixel
>     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/fsl,imx7-mipi-csi2.yaml    |  194 ++++
>  .../bindings/media/imx7-mipi-csi2.txt         |   90 --
>  MAINTAINERS                                   |    2 +-
>  drivers/media/v4l2-core/v4l2-mc.c             |    6 +-
>  drivers/staging/media/imx/Kconfig             |   12 +-
>  drivers/staging/media/imx/Makefile            |    8 +-
>  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    | 1016 ++++++++---------
>  drivers/staging/media/imx/imx7-mipi-csis.c    |  412 ++++---
>  include/media/v4l2-mc.h                       |    8 +-
>  20 files changed, 1422 insertions(+), 1135 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
>  delete mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> 
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* Re: [PATCH 01/75] media: imx: Drop dependency on I2C
  2021-01-05 15:27 ` [PATCH 01/75] media: imx: Drop dependency on I2C Laurent Pinchart
@ 2021-01-06 14:21   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:21 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 f555aac8a9d5..4782f7cfb709 100644
> --- a/drivers/staging/media/imx/Kconfig
> +++ b/drivers/staging/media/imx/Kconfig
> @@ -18,14 +18,14 @@ menu "i.MX5/6/7 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
>  	default y
>  	help
>  	  A video4linux camera sensor interface driver for i.MX5/6.
>  
>  config VIDEO_IMX7_CSI
>  	tristate "i.MX6UL/L / i.MX7 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

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 02/75] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol
  2021-01-05 15:27 ` [PATCH 02/75] media: imx: Move dependency on VIDEO_DEV to common Kconfig symbol Laurent Pinchart
@ 2021-01-06 14:21   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:21 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 4782f7cfb709..76a9111c189c 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 && IMX_IPUV3_CORE
>  	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,14 +19,14 @@ menu "i.MX5/6/7 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
>  	default y
>  	help
>  	  A video4linux camera sensor interface driver for i.MX5/6.
>  
>  config VIDEO_IMX7_CSI
>  	tristate "i.MX6UL/L / i.MX7 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

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 03/75] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA
  2021-01-05 15:27 ` [PATCH 03/75] media: imx: Drop manual dependency on VIDEO_IMX_MEDIA Laurent Pinchart
@ 2021-01-06 14:22   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:22 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 76a9111c189c..ce270627a7c4 100644
> --- a/drivers/staging/media/imx/Kconfig
> +++ b/drivers/staging/media/imx/Kconfig
> @@ -19,14 +19,12 @@ menu "i.MX5/6/7 Media Sub devices"
>  
>  config VIDEO_IMX_CSI
>  	tristate "i.MX5/6 Camera Sensor Interface driver"
> -	depends on VIDEO_IMX_MEDIA
>  	default y
>  	help
>  	  A video4linux camera sensor interface driver for i.MX5/6.
>  
>  config VIDEO_IMX7_CSI
>  	tristate "i.MX6UL/L / i.MX7 Camera Sensor Interface driver"
> -	depends on VIDEO_IMX_MEDIA
>  	default y
>  	help
>  	  Enable support for video4linux camera sensor interface driver for

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
  2021-01-05 15:27 ` [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI Laurent Pinchart
@ 2021-01-06 14:24   ` Philipp Zabel
  2021-01-06 15:42     ` Laurent Pinchart
  0 siblings, 1 reply; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:24 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

Hi Laurent,

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> The i.MX7 camera drivers, selected by VIDEO_IMX7_CSI, don't depend on
> IMX_IPUV3_CORE. Move the dependency from the common VIDEO_IMX_MEDIA
> symbol to VIDEO_IMX_CSI.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/staging/media/imx/Kconfig | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
> index ce270627a7c4..0f1277a58d3c 100644
> --- a/drivers/staging/media/imx/Kconfig
> +++ b/drivers/staging/media/imx/Kconfig
> @@ -4,7 +4,7 @@ config VIDEO_IMX_MEDIA
>  	depends on ARCH_MXC || COMPILE_TEST
>  	depends on HAS_DMA
>  	depends on VIDEO_DEV
> -	depends on VIDEO_V4L2 && IMX_IPUV3_CORE
> +	depends on VIDEO_V4L2
>  	select MEDIA_CONTROLLER
>  	select V4L2_FWNODE
>  	select V4L2_MEM2MEM_DEV
> @@ -19,6 +19,7 @@ menu "i.MX5/6/7 Media Sub devices"
>  
>  config VIDEO_IMX_CSI
>  	tristate "i.MX5/6 Camera Sensor Interface driver"
> +	depends on IMX_IPUV3_CORE
>  	default y
>  	help
>  	  A video4linux camera sensor interface driver for i.MX5/6.

This patch drops the IMX_IPUV3_CORE dependency from VIDEO_IMX_MEDIA,
which still tries to build imx6-media.ko (and will fail if
IMX_IPUV3_CORE is disabled) until the following patch.

Would it make sense to squash this with the following patch for better
bisectability?

regards
Philipp

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

* Re: [PATCH 08/75] media: imx: capture: Use dev_* instead of v4l2_* to log messages
  2021-01-05 15:27 ` [PATCH 08/75] media: imx: capture: Use dev_* instead of v4l2_* to log messages Laurent Pinchart
@ 2021-01-06 14:25   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:25 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 eb1453ade571..21f01ec56bd5 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;
>  

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 09/75] media: imx: capture: Use device name to construct bus_info
  2021-01-05 15:27 ` [PATCH 09/75] media: imx: capture: Use device name to construct bus_info Laurent Pinchart
@ 2021-01-06 14:26   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:26 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 21f01ec56bd5..8efe3d753967 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;
>  }

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 10/75] media: imx: capture: Remove forward declaration of capture_qops
  2021-01-05 15:27 ` [PATCH 10/75] media: imx: capture: Remove forward declaration of capture_qops Laurent Pinchart
@ 2021-01-06 14:26   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:26 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> The forward declaration of capture_qops isn't needed, remove it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  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 8efe3d753967..0b1dbff198a2 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
>   */

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 11/75] media: imx: capture: Handle errors from v4l2_fh_open()
  2021-01-05 15:27 ` [PATCH 11/75] media: imx: capture: Handle errors from v4l2_fh_open() Laurent Pinchart
@ 2021-01-06 14:27   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:27 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 0b1dbff198a2..b599e30df338 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;
>  }

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 13/75] media: imx: capture: Remove capture_priv stop field
  2021-01-05 15:27 ` [PATCH 13/75] media: imx: capture: Remove capture_priv stop field Laurent Pinchart
@ 2021-01-06 14:29   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:29 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> The stop field in the capture_priv structure is only set, never read.
> Drop it.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  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 dd3861a96cb8..4f9cff62eb1f 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)

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 14/75] media: imx: capture: Move queue and ctrl handler init to init function
  2021-01-05 15:27 ` [PATCH 14/75] media: imx: capture: Move queue and ctrl handler init to init function Laurent Pinchart
@ 2021-01-06 14:30   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:30 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 4f9cff62eb1f..d7cc1423b71e 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);
>  
> @@ -821,6 +799,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);
> @@ -832,8 +811,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);
>  
> @@ -844,8 +825,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) {
> @@ -853,11 +838,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;
>  }

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 15/75] media: imx: capture: Initialize video_device programmatically
  2021-01-05 15:27 ` [PATCH 15/75] media: imx: capture: Initialize video_device programmatically Laurent Pinchart
@ 2021-01-06 14:31   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:31 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 d7cc1423b71e..e22d98ce5d1e 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)
>  {
> @@ -815,17 +805,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);

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 17/75] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev
  2021-01-05 15:27 ` [PATCH 17/75] media: imx: capture: Store v4l2_pix_format in imx_media_video_dev Laurent Pinchart
@ 2021-01-06 14:33   ` Philipp Zabel
  0 siblings, 0 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-06 14:33 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> 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>
> ---
>  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 335cb74baa4c..f778d9588eb3 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 434866d28bfd..3a1501434288 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 1761451d3003..483fda2f13d9 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 a3f3df901704..98eb41f6496c 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -585,7 +585,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();
> @@ -667,11 +667,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;
> @@ -716,7 +715,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;

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

regards
Philipp

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-05 17:45 ` [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Fabio Estevam
  2021-01-05 19:00   ` Fabio Estevam
@ 2021-01-06 15:41   ` Laurent Pinchart
  2021-01-06 21:10     ` Fabio Estevam
  1 sibling, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-06 15:41 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Fabio,

On Tue, Jan 05, 2021 at 02:45:40PM -0300, Fabio Estevam wrote:
> On Tue, Jan 5, 2021 at 12:31 PM Laurent Pinchart wrote:
> >
> > Hello,
> >
> > This large patch series has been sitting in my tree for way too long. I
> > haven't posted it yet as I'm running into an issue on my test hardware
> > that I can't prove is not a regression from this series, but the
> > pressure has grown and the patches are better on the list for review.
> >
> > There's really not much to detail in the cover letter as there are
> > "just" fixes and cleanups I developed while bringing up camera support
> > for an i.MX7D platform, and later on an i.MX8MM that shares the same
> > MIPI-CSI2 and CSI IP cores (with some differences).
> >
> > The issue I've noticed is that the CSI writes two images consecutively
> > to the same buffer, overwritting memory after the end of the buffer. I
> > believe this bug to already be present in mainline, but I can't prove it
> > as my sensor won't work without some of the patches in this series. The
> > problem could also be sensor-specific.
> >
> > Rui, would you be able to test this on your i.MX7 hardware to make sure
> > there's no regression ?
> 
> Thanks for your series.
> 
> I tested it on a imx6ul-evk board.

Thank you.

> There is a build error introduced by patch 74/75. I fixed it like this:
> 
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -193,6 +193,8 @@
>  #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                     0x20
>  /* Non-image packet data buffers */
>  #define MIPI_CSIS_PKTDATA_ODD                  0x2000
>  #define MIPI_CSIS_PKTDATA_EVEN                 0x3000

Oops. I have a debug patch in my branch on top of the series that adds
the macro, that's why I haven't noticed compilation broke. Sorry about
that.

> Then I applied my patch and Rui's to fix the imx6ul regression as per
> the other thread we have been discussing, but I was not able to
> capture:

Would you be able to bisect this ?

> # gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink
> Setting pipeline to PAUSED ...
> Pipeline is live and does not need PREROLL ...
> Pipeline is PREROLLED ...
> Setting pipeline to PLAYING ...
> New clock: GstSystemClock
> /GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps =
> video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
> framerate=(fraction)120/1, interlace-mode=(string)progressive,
> colorimetr
> y=(string)1:1:5:1
> /GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:src: caps =
> video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
> framerate=(fraction)120/1, interlace-mode=(string)progressive, color
> imetry=(string)1:1:5:1
> /GstPipeline:pipeline0/GstFBDEVSink:fbdevsink0.GstPad:sink: caps =
> video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
> framerate=(fraction)120/1, interlace-mode=(string)progressive, color
> imetry=(string)1:1:5:1
> /GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:sink: caps =
> video/x-raw, format=(string)BGRx, width=(int)3840, height=(int)2160,
> framerate=(fraction)120/1, interlace-mode=(string)progressive, colo
> rimetry=(string)1:1:5:1
> [   32.783736] cma: cma_alloc: alloc failed, req-size: 8100 pages, ret: -12
> [   32.791332] imx7-csi 21c4000.csi: dma_alloc_coherent of size 33177600 failed
> ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Failed
> to allocate required memory.
> Additional debug info:
> ../sys/v4l2/gstv4l2src.c(659): gst_v4l2src_decide_allocation ():
> /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
> Buffer pool activation failed
> Execution ended after 0:00:00.214658125
> Setting pipeline to NULL ...
> Freeing pipeline ...
> 
> As shown above the dimensions and framerate are incorrectly reported
> as: width=(int)3840, height=(int)2160, framerate=(fraction)120/1
> 
> Previously it was:
> 
> # gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink
> Setting pipeline to PAUSED ...
> Pipeline is live and does not need PREROLL ...
> Pipeline is PREROLLED ...
> Setting pipeline to PLAYING ...
> New clock: GstSystemClock
> /GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps =
> video/x-raw, format=(string)UYVY, width=(int)320, height=(int)240,
> framerate=(fraction)30000/1001, interlace-mode=(string)progressive,
> colorim
> etry=(string)1:4:7:1
> /GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:src: caps =
> video/x-raw, format=(string)BGRx, width=(int)320, height=(int)240,
> framerate=(fraction)30000/1001, interlace-mode=(string)progressive
> /GstPipeline:pipeline0/GstFBDEVSink:fbdevsink0.GstPad:sink: caps =
> video/x-raw, format=(string)BGRx, width=(int)320, height=(int)240,
> framerate=(fraction)30000/1001, interlace-mode=(string)progressive
> /GstPipeline:pipeline0/v4l2convert:v4l2convert0.GstPad:sink: caps =
> video/x-raw, format=(string)UYVY, width=(int)320, height=(int)240,
> framerate=(fraction)30000/1001, interlace-mode=(string)progressive, c
> olorimetry=(string)1:4:7:1

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 04/75] media: imx: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
  2021-01-06 14:24   ` Philipp Zabel
@ 2021-01-06 15:42     ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-06 15:42 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Ezequiel Garcia

Hi Philipp,

On Wed, Jan 06, 2021 at 03:24:58PM +0100, Philipp Zabel wrote:
> On Tue, 2021-01-05 at 17:27 +0200, Laurent Pinchart wrote:
> > The i.MX7 camera drivers, selected by VIDEO_IMX7_CSI, don't depend on
> > IMX_IPUV3_CORE. Move the dependency from the common VIDEO_IMX_MEDIA
> > symbol to VIDEO_IMX_CSI.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/staging/media/imx/Kconfig | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/media/imx/Kconfig b/drivers/staging/media/imx/Kconfig
> > index ce270627a7c4..0f1277a58d3c 100644
> > --- a/drivers/staging/media/imx/Kconfig
> > +++ b/drivers/staging/media/imx/Kconfig
> > @@ -4,7 +4,7 @@ config VIDEO_IMX_MEDIA
> >  	depends on ARCH_MXC || COMPILE_TEST
> >  	depends on HAS_DMA
> >  	depends on VIDEO_DEV
> > -	depends on VIDEO_V4L2 && IMX_IPUV3_CORE
> > +	depends on VIDEO_V4L2
> >  	select MEDIA_CONTROLLER
> >  	select V4L2_FWNODE
> >  	select V4L2_MEM2MEM_DEV
> > @@ -19,6 +19,7 @@ menu "i.MX5/6/7 Media Sub devices"
> >  
> >  config VIDEO_IMX_CSI
> >  	tristate "i.MX5/6 Camera Sensor Interface driver"
> > +	depends on IMX_IPUV3_CORE
> >  	default y
> >  	help
> >  	  A video4linux camera sensor interface driver for i.MX5/6.
> 
> This patch drops the IMX_IPUV3_CORE dependency from VIDEO_IMX_MEDIA,
> which still tries to build imx6-media.ko (and will fail if
> IMX_IPUV3_CORE is disabled) until the following patch.
> 
> Would it make sense to squash this with the following patch for better
> bisectability?

Yes it does, I'll do so in v2.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device
  2021-01-05 15:28 ` [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device Laurent Pinchart
@ 2021-01-06 17:44   ` Steve Longerbeam
  2021-01-09  0:41     ` Laurent Pinchart
  2021-01-08 17:37   ` Ezequiel Garcia
  1 sibling, 1 reply; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:44 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia

Hi Laurent,

On 1/5/21 7:28 AM, Laurent Pinchart wrote:
> 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>
> ---
>   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..6c9c75ffb30c 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, false);

Might as well go ahead and pass true here now, to make the prpenc and 
prpvf links to the capture device immutable, since there is only one 
source and sink in this case.

Steve

>   	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 04eb612ff1fa..c6991e8f151c 100644
> --- a/drivers/staging/media/imx/imx-media-capture.c
> +++ b/drivers/staging/media/imx/imx-media-capture.c
> @@ -898,12 +898,14 @@ 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,
> +				      bool immutable)
>   {
>   	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;
> +	u32 flags;
>   	int ret;
>   
>   	/* get media device */
> @@ -927,8 +929,9 @@ 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. */
> +	flags = immutable ? MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE : 0;
>   	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
> -				    &vfd->entity, 0, 0);
> +				    &vfd->entity, 0, 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 436f3d7160fa..d54d2a3789c0 100644
> --- a/drivers/staging/media/imx/imx-media-csi.c
> +++ b/drivers/staging/media/imx/imx-media-csi.c
> @@ -1796,7 +1796,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, false);
>   	if (ret)
>   		goto remove_vdev;
>   
> diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
> index 16ab879e0084..4efc4d186c0a 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,
> +				      bool immutable);
>   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 afd1a7e35bfe..c087a212efdd 100644
> --- a/drivers/staging/media/imx/imx7-media-csi.c
> +++ b/drivers/staging/media/imx/imx7-media-csi.c
> @@ -1093,7 +1093,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, false);
>   	if (ret)
>   		imx_media_capture_device_remove(csi->vdev);
>   


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

* Re: [PATCH 19/75] media: imx: capture: Rename querycap handler to capture_querycap
  2021-01-05 15:27 ` [PATCH 19/75] media: imx: capture: Rename querycap handler to capture_querycap Laurent Pinchart
@ 2021-01-06 17:45   ` Steve Longerbeam
  0 siblings, 0 replies; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:45 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia



On 1/5/21 7:27 AM, Laurent Pinchart wrote:
> For consistency with all the other ioctl handlers, rename
> vidioc_querycap() to capture_querycap().
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.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 009dd8733813..db1f551b86ea 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,

Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-05 15:27 ` [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix Laurent Pinchart
@ 2021-01-06 17:51   ` Steve Longerbeam
  2021-01-07 10:52     ` Philipp Zabel
  0 siblings, 1 reply; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:51 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia

Hi Laurent,

I guess I have fallen behind the times with v4l2, but I wasn't aware 
that the /dev/video nodes and VIDIOC_* APIs are now considered legacy!

Steve

On 1/5/21 7:27 AM, Laurent Pinchart wrote:
> 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>
> ---
>   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 db1f551b86ea..0775e60ad894 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)
>   {
> @@ -821,7 +831,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;


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

* Re: [PATCH 22/75] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt
  2021-01-05 15:27 ` [PATCH 22/75] media: imx: capture: Remove unneeded variable in __capture_legacy_try_fmt Laurent Pinchart
@ 2021-01-06 17:55   ` Steve Longerbeam
  0 siblings, 0 replies; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:55 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia



On 1/5/21 7:27 AM, Laurent Pinchart wrote:
> 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>
> ---
>   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 70b3d187bbc3..7932b7f0f4f2 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 */

Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>

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

* Re: [PATCH 23/75] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt()
  2021-01-05 15:28 ` [PATCH 23/75] media: imx: capture: Pass v4l2_pix_format to __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-01-06 17:57   ` Steve Longerbeam
  0 siblings, 0 replies; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:57 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia



On 1/5/21 7:28 AM, Laurent Pinchart wrote:
> 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>
> ---
>   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 7932b7f0f4f2..d34cbf0a0fa1 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;

Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>

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

* Re: [PATCH 27/75] media: imx: capture: Simplify __capture_legacy_try_fmt()
  2021-01-05 15:28 ` [PATCH 27/75] media: imx: capture: Simplify __capture_legacy_try_fmt() Laurent Pinchart
@ 2021-01-06 17:59   ` Steve Longerbeam
  0 siblings, 0 replies; 121+ messages in thread
From: Steve Longerbeam @ 2021-01-06 17:59 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia



On 1/5/21 7:28 AM, Laurent Pinchart wrote:
> 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>
> ---
>   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 8f3c0da371d3..9a8e1a1400a2 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;
>   }

Reviewed-by: Steve Longerbeam <slongerbeam@gmail.com>


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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-06 15:41   ` Laurent Pinchart
@ 2021-01-06 21:10     ` Fabio Estevam
  2021-01-09  1:10       ` Laurent Pinchart
  0 siblings, 1 reply; 121+ messages in thread
From: Fabio Estevam @ 2021-01-06 21:10 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Laurent,

On Wed, Jan 6, 2021 at 12:41 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:

> Would you be able to bisect this ?

Sure, the commit the broke camera capture on a imx6ul-evk board was:

commit d2c66a98046a42ccb7d8a7b761a5dd6867815171
Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date:   Tue Mar 10 16:04:01 2020 +0200

    media: imx: imx7-media-csi: Disable legacy video node API

    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>

If I use your imx/csi/imx7 branch, and then revert the above commit,
camera capture works for me (with the additional patch from me and Rui
as discussed in the other thread).

Regards,

Fabio Estevam

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

* Re: [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property
  2021-01-05 15:28 ` [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property Laurent Pinchart
@ 2021-01-06 22:49   ` Sakari Ailus
  2021-01-06 22:53     ` Sakari Ailus
  0 siblings, 1 reply; 121+ messages in thread
From: Sakari Ailus @ 2021-01-06 22:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Rob Herring, devicetree

Hi Laurent,

On Tue, Jan 05, 2021 at 05:28:36PM +0200, Laurent Pinchart wrote:
> The fsl,csis-hs-settle property isn't used by the driver anymore. Drop
> it.

How does it configure the hardware now without this?

-- 
Sakari Ailus

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

* Re: [PATCH 59/75] dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle property
  2021-01-06 22:49   ` Sakari Ailus
@ 2021-01-06 22:53     ` Sakari Ailus
  0 siblings, 0 replies; 121+ messages in thread
From: Sakari Ailus @ 2021-01-06 22:53 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia, Rob Herring, devicetree

On Thu, Jan 07, 2021 at 12:49:59AM +0200, Sakari Ailus wrote:
> Hi Laurent,
> 
> On Tue, Jan 05, 2021 at 05:28:36PM +0200, Laurent Pinchart wrote:
> > The fsl,csis-hs-settle property isn't used by the driver anymore. Drop
> > it.
> 
> How does it configure the hardware now without this?

Please ignore, I found patch 68. :-)

-- 
Sakari Ailus

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

* Re: [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate
  2021-01-05 15:28 ` [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate Laurent Pinchart
@ 2021-01-06 22:59   ` Sakari Ailus
  2021-01-09  0:52     ` Laurent Pinchart
  2021-01-11  9:39   ` Rui Miguel Silva
  1 sibling, 1 reply; 121+ messages in thread
From: Sakari Ailus @ 2021-01-06 22:59 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Laurent,

Thanks for the patchset.

On Tue, Jan 05, 2021 at 05:28:45PM +0200, Laurent Pinchart wrote:
> The Ths_settle timing parameter depends solely on the pixel 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>
> ---
>  drivers/staging/media/imx/imx7-mipi-csis.c | 65 ++++++++++++++++++----
>  1 file changed, 53 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index 3c68ee8b2a59..c83450ac37fa 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-ctrls.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-fwnode.h>
>  #include <media/v4l2-mc.h>
> @@ -233,7 +234,11 @@ struct csi_state {
>  	struct media_pad pads[CSIS_PADS_NUM];
>  	struct v4l2_subdev mipi_sd;
>  	struct v4l2_async_notifier notifier;
> -	struct v4l2_subdev *src_sd;
> +
> +	struct {
> +		struct v4l2_subdev *sd;
> +		struct v4l2_ctrl *pixel_rate;
> +	} src;
>  
>  	u8 index;
>  	struct platform_device *pdev;
> @@ -482,6 +487,31 @@ 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)
> +{
> +	u64 pixel_rate;
> +	u32 lane_rate;
> +
> +	/* Calculate the line rate from the pixel rate. */
> +	pixel_rate = v4l2_ctrl_g_ctrl_int64(state->src.pixel_rate);

Could you instead use v4l2_get_link_freq()?

I guess we're also moving to the LINK_FREQ control to tell this.

> +	lane_rate = div_u64(pixel_rate, state->bus.num_data_lanes)
> +		  * state->csis_fmt->width;
> +	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;

Much better, thank you!

-- 
Regards,

Sakari Ailus

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-06 17:51   ` Steve Longerbeam
@ 2021-01-07 10:52     ` Philipp Zabel
  2021-01-08  0:03       ` Fabio Estevam
  2021-01-09  1:09       ` Laurent Pinchart
  0 siblings, 2 replies; 121+ messages in thread
From: Philipp Zabel @ 2021-01-07 10:52 UTC (permalink / raw)
  To: Steve Longerbeam, Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Ezequiel Garcia

Hi Steve, Laurent,

On Wed, 2021-01-06 at 09:51 -0800, Steve Longerbeam wrote:
> Hi Laurent,
> 
> I guess I have fallen behind the times with v4l2, but I wasn't aware 
> that the /dev/video nodes and VIDIOC_* APIs are now considered legacy!

I don't think Laurent considers the video node legacy, just the fact
that the current implementation looks at the subdev source pad's active
format in ENUM_FRAMESIZES and ENUM_/G/S/TRY_FMT.

I see the behavior of VIDIOC_ENUM_FMT was extended/defined for MC-
centric devices last year, to allow enumerating all pixel formats or
filter pixel formats for a given mbus format:

e5b6b07a1b45 ("media: v4l2: Extend VIDIOC_ENUM_FMT to support MC-centric devices")
cfe9e707c564 ("media: open.rst: document mc-centric and video-node-centric")

> Steve
> 
> On 1/5/21 7:27 AM, Laurent Pinchart wrote:
> > 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.

But I don't quite understand why G/S/TRY_FMT should not respect the
connected subdev source pad's active format. Should MC-centric devices
allow to set non-working configurations and only error out on stream
start? Is this documented?

The current "legacy" vb2_ops check the subdev in ENUM_FRAMESIZES and
ENUM_FRAMEINTERVALS, and in TRY_FMT/S_FMT to determine format and
possible interlacing options. If the MC-centric ops just drop that,
there is no way to determine which interlacing combinations are actually
supported.

regards
Philipp

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-07 10:52     ` Philipp Zabel
@ 2021-01-08  0:03       ` Fabio Estevam
  2021-01-09  1:09       ` Laurent Pinchart
  1 sibling, 0 replies; 121+ messages in thread
From: Fabio Estevam @ 2021-01-08  0:03 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Steve Longerbeam, Laurent Pinchart, linux-media,
	Rui Miguel Silva, Ezequiel Garcia

Hi Philipp,

On Thu, Jan 7, 2021 at 7:53 AM Philipp Zabel <p.zabel@pengutronix.de> wrote:

> But I don't quite understand why G/S/TRY_FMT should not respect the
> connected subdev source pad's active format. Should MC-centric devices
> allow to set non-working configurations and only error out on stream
> start? Is this documented?
>
> The current "legacy" vb2_ops check the subdev in ENUM_FRAMESIZES and
> ENUM_FRAMEINTERVALS, and in TRY_FMT/S_FMT to determine format and
> possible interlacing options. If the MC-centric ops just drop that,
> there is no way to determine which interlacing combinations are actually
> supported.

You make a good point and it is aligned with what I am seeing here too.

When I tested this series, I noticed a regression on imx6ul-evk
capture and doing a bisect it points to:
media: imx: imx7-media-csi: Disable legacy video node API

Reverting it back to using the legacy API fixed things for me.

When the MC-centric API is used the camera dimensions reported by
Gstreamer are no longer correct.

Regards,

Fabio Estevam

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

* Re: [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device
  2021-01-05 15:28 ` [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device Laurent Pinchart
  2021-01-06 17:44   ` Steve Longerbeam
@ 2021-01-08 17:37   ` Ezequiel Garcia
  2021-01-09  0:48     ` Laurent Pinchart
  1 sibling, 1 reply; 121+ messages in thread
From: Ezequiel Garcia @ 2021-01-08 17:37 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel

Hi Laurent,

On Tue, 2021-01-05 at 17:28 +0200, Laurent Pinchart wrote:
> 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.
> 

Does this apply to csi2_notify_bound as welll
that is, is there any point in making the sensor link mutable?
 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  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..6c9c75ffb30c 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, false);

Maybe it's just me, but I dislike this boolean parameter pattern,
as opposed to passing the flags directly, or some other MUTABLE/IMMUTABLE
enum value.

Cheers,
Ezequiel


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

* Re: [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-01-05 15:27 ` [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI Laurent Pinchart
@ 2021-01-08 17:42   ` Ezequiel Garcia
  2021-01-08 17:47     ` Laurent Pinchart
  0 siblings, 1 reply; 121+ messages in thread
From: Ezequiel Garcia @ 2021-01-08 17:42 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Rui Miguel Silva, Steve Longerbeam, Philipp Zabel

On Tue, 2021-01-05 at 17:27 +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>
> ---
>  drivers/staging/media/imx/Makefile | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
> index 9bd9e873ba7c..6ac33275cc97 100644
> --- a/drivers/staging/media/imx/Makefile
> +++ b/drivers/staging/media/imx/Makefile
> @@ -1,16 +1,16 @@
>  # 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) += imx6-media.o
>  obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
>  
> +obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media.o
>  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media-csi.o
>  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
>  

Nice change. This shows more clearly what's shared and what not.

Would it be too hard to walk the extra kilometer (not necesarily now,
not necesarily looking at you do it) split imx6 and imx7 better,
so we can start thinking what's needed to destage imx6?

I don't think the imx6 support is all that bad that it has
to live in staging.

Thanks,
Ezequiel



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

* Re: [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-01-08 17:42   ` Ezequiel Garcia
@ 2021-01-08 17:47     ` Laurent Pinchart
  2021-01-08 18:05       ` Ezequiel Garcia
  0 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-08 17:47 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel

Hi Ezequiel,

On Fri, Jan 08, 2021 at 02:42:32PM -0300, Ezequiel Garcia wrote:
> On Tue, 2021-01-05 at 17:27 +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>
> > ---
> >  drivers/staging/media/imx/Makefile | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
> > index 9bd9e873ba7c..6ac33275cc97 100644
> > --- a/drivers/staging/media/imx/Makefile
> > +++ b/drivers/staging/media/imx/Makefile
> > @@ -1,16 +1,16 @@
> >  # 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) += imx6-media.o
> >  obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
> >  
> > +obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media.o
> >  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media-csi.o
> >  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
> 
> Nice change. This shows more clearly what's shared and what not.
> 
> Would it be too hard to walk the extra kilometer (not necesarily now,
> not necesarily looking at you do it) split imx6 and imx7 better,
> so we can start thinking what's needed to destage imx6?

I'd really welcome that, but I'd like to get this series merged first.
Unless you want a v2 with twice the number of patches ;-)

> I don't think the imx6 support is all that bad that it has
> to live in staging.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 05/75] media: imx: Compile imx6-media-objs only for CONFIG_VIDEO_IMX_CSI
  2021-01-08 17:47     ` Laurent Pinchart
@ 2021-01-08 18:05       ` Ezequiel Garcia
  0 siblings, 0 replies; 121+ messages in thread
From: Ezequiel Garcia @ 2021-01-08 18:05 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel

On Fri, 2021-01-08 at 19:47 +0200, Laurent Pinchart wrote:
> Hi Ezequiel,
> 
> On Fri, Jan 08, 2021 at 02:42:32PM -0300, Ezequiel Garcia wrote:
> > On Tue, 2021-01-05 at 17:27 +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>
> > > ---
> > >  drivers/staging/media/imx/Makefile | 8 ++++----
> > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/staging/media/imx/Makefile b/drivers/staging/media/imx/Makefile
> > > index 9bd9e873ba7c..6ac33275cc97 100644
> > > --- a/drivers/staging/media/imx/Makefile
> > > +++ b/drivers/staging/media/imx/Makefile
> > > @@ -1,16 +1,16 @@
> > >  # 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) += imx6-media.o
> > >  obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
> > >  
> > > +obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media.o
> > >  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-media-csi.o
> > >  obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
> > 
> > Nice change. This shows more clearly what's shared and what not.
> > 
> > Would it be too hard to walk the extra kilometer (not necesarily now,
> > not necesarily looking at you do it) split imx6 and imx7 better,
> > so we can start thinking what's needed to destage imx6?
> 
> I'd really welcome that, but I'd like to get this series merged first.
> Unless you want a v2 with twice the number of patches ;-)
> 

Well, maybe that'd make you set a new record :)

Feel free to add:

Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,
Ezequiel 


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

* Re: [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device
  2021-01-06 17:44   ` Steve Longerbeam
@ 2021-01-09  0:41     ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-09  0:41 UTC (permalink / raw)
  To: Steve Longerbeam
  Cc: linux-media, Rui Miguel Silva, Philipp Zabel, Ezequiel Garcia

Hi Steve,

On Wed, Jan 06, 2021 at 09:44:37AM -0800, Steve Longerbeam wrote:
> On 1/5/21 7:28 AM, Laurent Pinchart wrote:
> > 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>
> > ---
> >   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..6c9c75ffb30c 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, false);
> 
> Might as well go ahead and pass true here now, to make the prpenc and 
> prpvf links to the capture device immutable, since there is only one 
> source and sink in this case.

This patch only adds the infrastructure to create immutable links, but
doesn't make use of it. Subsequent patches change that. I can add
another patch for the prpenc and prpvf.

> >   	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 04eb612ff1fa..c6991e8f151c 100644
> > --- a/drivers/staging/media/imx/imx-media-capture.c
> > +++ b/drivers/staging/media/imx/imx-media-capture.c
> > @@ -898,12 +898,14 @@ 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,
> > +				      bool immutable)
> >   {
> >   	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;
> > +	u32 flags;
> >   	int ret;
> >   
> >   	/* get media device */
> > @@ -927,8 +929,9 @@ 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. */
> > +	flags = immutable ? MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE : 0;
> >   	ret = media_create_pad_link(&sd->entity, priv->src_sd_pad,
> > -				    &vfd->entity, 0, 0);
> > +				    &vfd->entity, 0, 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 436f3d7160fa..d54d2a3789c0 100644
> > --- a/drivers/staging/media/imx/imx-media-csi.c
> > +++ b/drivers/staging/media/imx/imx-media-csi.c
> > @@ -1796,7 +1796,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, false);
> >   	if (ret)
> >   		goto remove_vdev;
> >   
> > diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
> > index 16ab879e0084..4efc4d186c0a 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,
> > +				      bool immutable);
> >   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 afd1a7e35bfe..c087a212efdd 100644
> > --- a/drivers/staging/media/imx/imx7-media-csi.c
> > +++ b/drivers/staging/media/imx/imx7-media-csi.c
> > @@ -1093,7 +1093,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, false);
> >   	if (ret)
> >   		imx_media_capture_device_remove(csi->vdev);
> >   

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 31/75] media: imx: capture: Support creating immutable link to capture device
  2021-01-08 17:37   ` Ezequiel Garcia
@ 2021-01-09  0:48     ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-09  0:48 UTC (permalink / raw)
  To: Ezequiel Garcia
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel

Hi Ezequiel,

On Fri, Jan 08, 2021 at 02:37:54PM -0300, Ezequiel Garcia wrote:
> Hi Laurent,
> 
> On Tue, 2021-01-05 at 17:28 +0200, Laurent Pinchart wrote:
> > 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.
> 
> Does this apply to csi2_notify_bound as welll
> that is, is there any point in making the sensor link mutable?

We could have multiple sensors connected to the same CSI-2 receiver,
with all but one always in reset (not a recommended hardware design, but
it has been done and can work in some cases).

> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  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..6c9c75ffb30c 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, false);
> 
> Maybe it's just me, but I dislike this boolean parameter pattern,
> as opposed to passing the flags directly, or some other MUTABLE/IMMUTABLE
> enum value.

Something along these lines ?

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 04eb612ff1fa..a17e087a0d02 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -898,7 +898,9 @@ 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)
+				      bool immutable)
 {
 	struct capture_priv *priv = to_capture_priv(vdev);
 	struct v4l2_subdev *sd = priv->src_sd;
@@ -927,8 +929,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 cfad000d9352..ce64f3da81f7 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 afd1a7e35bfe..1b13347bd0a0 100644
--- a/drivers/staging/media/imx/imx7-media-csi.c
+++ b/drivers/staging/media/imx/imx7-media-csi.c
@@ -1093,7 +1093,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] 121+ messages in thread

* Re: [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate
  2021-01-06 22:59   ` Sakari Ailus
@ 2021-01-09  0:52     ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-09  0:52 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Sakari,

On Thu, Jan 07, 2021 at 12:59:24AM +0200, Sakari Ailus wrote:
> On Tue, Jan 05, 2021 at 05:28:45PM +0200, Laurent Pinchart wrote:
> > The Ths_settle timing parameter depends solely on the pixel 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>
> > ---
> >  drivers/staging/media/imx/imx7-mipi-csis.c | 65 ++++++++++++++++++----
> >  1 file changed, 53 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> > index 3c68ee8b2a59..c83450ac37fa 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-ctrls.h>
> >  #include <media/v4l2-device.h>
> >  #include <media/v4l2-fwnode.h>
> >  #include <media/v4l2-mc.h>
> > @@ -233,7 +234,11 @@ struct csi_state {
> >  	struct media_pad pads[CSIS_PADS_NUM];
> >  	struct v4l2_subdev mipi_sd;
> >  	struct v4l2_async_notifier notifier;
> > -	struct v4l2_subdev *src_sd;
> > +
> > +	struct {
> > +		struct v4l2_subdev *sd;
> > +		struct v4l2_ctrl *pixel_rate;
> > +	} src;
> >  
> >  	u8 index;
> >  	struct platform_device *pdev;
> > @@ -482,6 +487,31 @@ 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)
> > +{
> > +	u64 pixel_rate;
> > +	u32 lane_rate;
> > +
> > +	/* Calculate the line rate from the pixel rate. */
> > +	pixel_rate = v4l2_ctrl_g_ctrl_int64(state->src.pixel_rate);
> 
> Could you instead use v4l2_get_link_freq()?
> 
> I guess we're also moving to the LINK_FREQ control to tell this.

I've developed this patch before we discussed moving to LINQ_FREQ :-)
I'll fix this in v2.

> > +	lane_rate = div_u64(pixel_rate, state->bus.num_data_lanes)
> > +		  * state->csis_fmt->width;
> > +	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;
> 
> Much better, thank you!

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-07 10:52     ` Philipp Zabel
  2021-01-08  0:03       ` Fabio Estevam
@ 2021-01-09  1:09       ` Laurent Pinchart
  2021-01-11  8:40         ` Philipp Zabel
  1 sibling, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-09  1:09 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Steve Longerbeam, linux-media, Rui Miguel Silva, Ezequiel Garcia

Hi Philipp,

On Thu, Jan 07, 2021 at 11:52:33AM +0100, Philipp Zabel wrote:
> On Wed, 2021-01-06 at 09:51 -0800, Steve Longerbeam wrote:
> > Hi Laurent,
> > 
> > I guess I have fallen behind the times with v4l2, but I wasn't aware 
> > that the /dev/video nodes and VIDIOC_* APIs are now considered legacy!
> 
> I don't think Laurent considers the video node legacy, just the fact
> that the current implementation looks at the subdev source pad's active
> format in ENUM_FRAMESIZES and ENUM_/G/S/TRY_FMT.

Correct. The legacy part here is control of the source subdev through
the video node. It should instead be handled with the media controller
API. The DMA engine side is still handled through the video node, and
that's totally fine.

> I see the behavior of VIDIOC_ENUM_FMT was extended/defined for MC-
> centric devices last year, to allow enumerating all pixel formats or
> filter pixel formats for a given mbus format:
> 
> e5b6b07a1b45 ("media: v4l2: Extend VIDIOC_ENUM_FMT to support MC-centric devices")
> cfe9e707c564 ("media: open.rst: document mc-centric and video-node-centric")
> 
> > On 1/5/21 7:27 AM, Laurent Pinchart wrote:
> > > 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.
> 
> But I don't quite understand why G/S/TRY_FMT should not respect the
> connected subdev source pad's active format. Should MC-centric devices
> allow to set non-working configurations and only error out on stream
> start? Is this documented?

It's the currently recommended practice, but I'm not sure it's
documented.

There are multiple issues here. One of them is that we could limit
VIDIOC_S_FMT to formats compatible with the connected source subdev with
minimum complexity in the implementation, but the source subdev could
then see its configuration being changed by userspace, and updating the
format on the video node automatically would be not only more difficult,
but potentially confusing for userspace as formats are not supposed to
change automatically. For this reason, we need to validate the full
pipeline at stream on time in any case, and restricting the format
ioctls on the video node to the active configuration of the connected
subdev would thus not be that useful.

Another issue is that we've had cases in the past where it was useful
for userspace to configure the video node with a format not matching the
connected subdev, with the subdev configuration later being changed to
match the video node, before starting the stream. I'm not sure if this
use case is still valid today though.

> The current "legacy" vb2_ops check the subdev in ENUM_FRAMESIZES and
> ENUM_FRAMEINTERVALS, and in TRY_FMT/S_FMT to determine format and
> possible interlacing options. If the MC-centric ops just drop that,
> there is no way to determine which interlacing combinations are actually
> supported.

Could you elaborate a little bit here ? We don't have an API to
explicitly enumerate supported interlacing types. This can be done by
calling VIDIOC_TRY_FMT with all field types and see which ones are
supported. You can still do so with the MC-based API, the video node
will return from VIDIOC_TRY_FMT the interlacing types intrinsicly
supported by the video node, and you can query from the source subdev
the interlacing types supported by the source. Userspace can then
combine the information to find what is supported. In this case, with a
source producing V4L2_FIELD_SEQ_TB, and the video node not reporting
V4L2_FIELD_SEQ_TB but reporting V4L2_FIELD_INTERLACED_TB, wouldn't the
application be able to know that V4L2_FIELD_INTERLACED_TB will work ?

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-06 21:10     ` Fabio Estevam
@ 2021-01-09  1:10       ` Laurent Pinchart
  2021-01-09  1:47         ` Fabio Estevam
  0 siblings, 1 reply; 121+ messages in thread
From: Laurent Pinchart @ 2021-01-09  1:10 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Fabio,

On Wed, Jan 06, 2021 at 06:10:44PM -0300, Fabio Estevam wrote:
> On Wed, Jan 6, 2021 at 12:41 PM Laurent Pinchart wrote:
> 
> > Would you be able to bisect this ?
> 
> Sure, the commit the broke camera capture on a imx6ul-evk board was:
> 
> commit d2c66a98046a42ccb7d8a7b761a5dd6867815171
> Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Date:   Tue Mar 10 16:04:01 2020 +0200
> 
>     media: imx: imx7-media-csi: Disable legacy video node API
> 
>     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>
> 
> If I use your imx/csi/imx7 branch, and then revert the above commit,
> camera capture works for me (with the additional patch from me and Rui
> as discussed in the other thread).

Ah of course, I should have mentioned that, sorry. Without the legacy
video node API, the pipeline has to be configured with the MC API and
the V4L2 subdev userspace API before starting the stream.

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-09  1:10       ` Laurent Pinchart
@ 2021-01-09  1:47         ` Fabio Estevam
  2021-02-15  0:23           ` Laurent Pinchart
  0 siblings, 1 reply; 121+ messages in thread
From: Fabio Estevam @ 2021-01-09  1:47 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Laurent,

On Fri, Jan 8, 2021 at 10:11 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:

> Ah of course, I should have mentioned that, sorry. Without the legacy
> video node API, the pipeline has to be configured with the MC API and
> the V4L2 subdev userspace API before starting the stream.

The current method I use is:

media-ctl -l "'ov5640 1-003c':0 -> 'csi':0[1]"
media-ctl -l "'csi':1 -> 'csi capture':0[1]"
media-ctl -v -V "'ov5640 1-003c':0 [fmt:UYVY8_2X8/320x240 field:none]"

# gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink

Could you please let me know what is the correct way I should do with
the MC API?

Thanks

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-09  1:09       ` Laurent Pinchart
@ 2021-01-11  8:40         ` Philipp Zabel
  2021-02-14 21:33           ` Laurent Pinchart
  0 siblings, 1 reply; 121+ messages in thread
From: Philipp Zabel @ 2021-01-11  8:40 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Steve Longerbeam, linux-media, Rui Miguel Silva, Ezequiel Garcia

Hi Laurent,

On Sat, 2021-01-09 at 03:09 +0200, Laurent Pinchart wrote:
> Could you elaborate a little bit here ? We don't have an API to
> explicitly enumerate supported interlacing types. This can be done by
> calling VIDIOC_TRY_FMT with all field types and see which ones are
> supported. You can still do so with the MC-based API, the video node
> will return from VIDIOC_TRY_FMT the interlacing types intrinsicly
> supported by the video node, and you can query from the source subdev
> the interlacing types supported by the source. Userspace can then
> combine the information to find what is supported.

The i.MX6 CSI always captures whole frames, so SEQ_TB or SEQ_BT at its
source pad.
The IDMAC supports "interlaced scan" of SEQ_TB into INTERLACED_TB and
SEQ_BT into INTERLACED_BT when writing to memory. It can't change the
field timing order (BT <-> TB) as that was already decided at the CSI.

So for capture of interlaced material, the video device currently allows
either SEQ_TB and INTERLACED_TB or SEQ_BT and INTERLACED_BT, depending
on which field order is configured at the CSI source pad.

See d969291d8479 ("media: imx: Fix field negotiation") for details.

regards
Philipp

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

* Re: [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate
  2021-01-05 15:28 ` [PATCH 68/75] media: imx: imx7_mipi_csis: Calculate Ths_settle from source pixel rate Laurent Pinchart
  2021-01-06 22:59   ` Sakari Ailus
@ 2021-01-11  9:39   ` Rui Miguel Silva
  1 sibling, 0 replies; 121+ messages in thread
From: Rui Miguel Silva @ 2021-01-11  9:39 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

On Tue, Jan 05, 2021 at 05:28:45PM +0200, Laurent Pinchart wrote:
> The Ths_settle timing parameter depends solely on the pixel 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>
> ---
>  drivers/staging/media/imx/imx7-mipi-csis.c | 65 ++++++++++++++++++----
>  1 file changed, 53 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index 3c68ee8b2a59..c83450ac37fa 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-ctrls.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-fwnode.h>
>  #include <media/v4l2-mc.h>
> @@ -233,7 +234,11 @@ struct csi_state {
>  	struct media_pad pads[CSIS_PADS_NUM];
>  	struct v4l2_subdev mipi_sd;
>  	struct v4l2_async_notifier notifier;
> -	struct v4l2_subdev *src_sd;
> +
> +	struct {
> +		struct v4l2_subdev *sd;
> +		struct v4l2_ctrl *pixel_rate;
> +	} src;
>  
>  	u8 index;
>  	struct platform_device *pdev;
> @@ -482,6 +487,31 @@ 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)
> +{
> +	u64 pixel_rate;
> +	u32 lane_rate;
> +
> +	/* Calculate the line rate from the pixel rate. */
> +	pixel_rate = v4l2_ctrl_g_ctrl_int64(state->src.pixel_rate);
> +	lane_rate = div_u64(pixel_rate, state->bus.num_data_lanes)
> +		  * state->csis_fmt->width;
> +	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, "pixel rate %llu, lane rate %u, Ths_settle %u\n",
> +		pixel_rate, 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,16 +638,20 @@ 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) {
>  			pm_runtime_put_noidle(&state->pdev->dev);
>  			return ret;
>  		}
> -		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
> +		ret = v4l2_subdev_call(state->src.sd, core, s_power, 1);
>  		if (ret < 0 && ret != -ENOIOCTLCMD)
>  			return ret;
>  	}
> @@ -630,7 +664,7 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
>  		}
>  
>  		mipi_csis_start_stream(state);
> -		ret = v4l2_subdev_call(state->src_sd, video, s_stream, 1);
> +		ret = v4l2_subdev_call(state->src.sd, video, s_stream, 1);
>  		if (ret < 0)
>  			goto unlock;
>  
> @@ -638,8 +672,8 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
>  
>  		state->flags |= ST_STREAMING;
>  	} else {
> -		v4l2_subdev_call(state->src_sd, video, s_stream, 0);
> -		ret = v4l2_subdev_call(state->src_sd, core, s_power, 0);
> +		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);
> @@ -677,14 +711,24 @@ static int mipi_csis_link_setup(struct media_entity *entity,
>  	mutex_lock(&state->lock);
>  
>  	if (flags & MEDIA_LNK_FL_ENABLED) {
> -		if (state->src_sd) {
> +		if (state->src.sd) {
>  			ret = -EBUSY;
>  			goto out;
>  		}
>  
> -		state->src_sd = remote_sd;
> +		state->src.pixel_rate = v4l2_ctrl_find(remote_sd->ctrl_handler,
> +						       V4L2_CID_PIXEL_RATE);
> +		if (!state->src.pixel_rate) {
> +			dev_err(state->dev,
> +				"source %s has no pixel rate control\n",
> +				remote_sd->name);
> +			return -EINVAL;

This needs to goto out to release lock.

------
Cheers,
     Rui
> +		}
> +
> +		state->src.sd = remote_sd;
>  	} else {
> -		state->src_sd = NULL;
> +		state->src.pixel_rate = NULL;
> +		state->src.sd = NULL;
>  	}
>  
>  out:
> @@ -943,9 +987,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	[flat|nested] 121+ messages in thread

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-05 15:27 [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7 Laurent Pinchart
                   ` (76 preceding siblings ...)
  2021-01-05 19:29 ` Rui Miguel Silva
@ 2021-01-11  9:53 ` Rui Miguel Silva
  77 siblings, 0 replies; 121+ messages in thread
From: Rui Miguel Silva @ 2021-01-11  9:53 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Steve Longerbeam, Philipp Zabel, Ezequiel Garcia

Hi Laurent,
again many thanks for this series.

On Tue, Jan 05, 2021 at 05:27:37PM +0200, Laurent Pinchart wrote:
> Hello,
> 
> This large patch series has been sitting in my tree for way too long. I
> haven't posted it yet as I'm running into an issue on my test hardware
> that I can't prove is not a regression from this series, but the
> pressure has grown and the patches are better on the list for review.
> 
> There's really not much to detail in the cover letter as there are
> "just" fixes and cleanups I developed while bringing up camera support
> for an i.MX7D platform, and later on an i.MX8MM that shares the same
> MIPI-CSI2 and CSI IP cores (with some differences).
> 
> The issue I've noticed is that the CSI writes two images consecutively
> to the same buffer, overwritting memory after the end of the buffer. I
> believe this bug to already be present in mainline, but I can't prove it
> as my sensor won't work without some of the patches in this series. The
> problem could also be sensor-specific.
> 
> Rui, would you be able to test this on your i.MX7 hardware to make sure
> there's no regression ?

Only yesterday had the time to setup and test this. In general it
looks very good to me, I only catched one issue and the other was that
my sensor did not implemented the pixel rate control (will send a
follow up patch on that).

I think a lot of the changes are at capture level, so maybe others
need to go over that.

So, when you address:
  - the comments for others that I agree
  - the error path in patch 68
  - rebase the dt-bindings yaml changes, 
  - rebase on top of fabio and my patch regarding parallel setup in
    imx6ull

You can add my:
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>

to the all series.

Bellow goes my use case setup and outputs with your changes:

root@imx7s-warp-mbl:~# uname -a
Linux imx7s-warp-mbl 5.11.0-rc1-00119-gf546a57674cb-dirty #109 SMP Mon Jan 11 00:28:24 WET 2021 armv7l GNU/Linux

oot@imx7s-warp-mbl:~# media-ctl --version
media-ctl 1.21.0-4690

# Setup links
media-ctl -l "'ov2680 1-0036':0 -> 'imx7-mipi-csis.0':0[1]"
media-ctl -l "'imx7-mipi-csis.0':1 -> 'csi_mux':1[1]"
media-ctl -l "'csi_mux':2 -> 'csi':0[1]"
media-ctl -l "'csi':1 -> 'csi capture':0[1]"

# Configure pads for pipeline
media-ctl -V "'ov2680 1-0036':0 [fmt:SBGGR10_1X10/1600x1200 field:none]"
media-ctl -V "'csi_mux':1 [fmt:SBGGR10_1X10/1600x1200 field:none]"
media-ctl -V "'csi_mux':2 [fmt:SBGGR10_1X10/1600x1200 field:none]"
media-ctl -V "'imx7-mipi-csis.0':0 [fmt:SBGGR10_1X10/1600x1200 field:none]"
media-ctl -V "'csi':0 [fmt:SBGGR10_1X10/1600x1200 field:none]"

root@imx7s-warp-mbl:~# media-ctl -p
Media controller API version 5.11.0

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

Device topology
- entity 1: csi (2 pads, 2 links)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
        pad0: Sink
                [fmt:SBGGR10_1X10/1600x1200 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range]
                <- "csi_mux":2 [ENABLED,IMMUTABLE]
        pad1: Source
                [fmt:SBGGR10_1X10/1600x1200 field:none colorspace:srgb xfer:srgb 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: csi_mux (3 pads, 2 links)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev1
        pad0: Sink
                [fmt:Y8_1X8/1x1 field:none]
        pad1: Sink
                [fmt:SBGGR10_1X10/1600x1200 field:none]
                <- "imx7-mipi-csis.0":1 [ENABLED]
        pad2: Source
                [fmt:SBGGR10_1X10/1600x1200 field:none]
                -> "csi":0 [ENABLED,IMMUTABLE]

- entity 16: imx7-mipi-csis.0 (2 pads, 2 links)
             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev2
        pad0: Sink
                [fmt:SBGGR10_1X10/1600x1200 field:none colorspace:smpte170m xfer:709 ycbcr:601 quantization:lim-range]
                <- "ov2680 1-0036":0 [ENABLED]
        pad1: Source
                [fmt:SBGGR10_1X10/1600x1200 field:none colorspace:smpte170m xfer:709 ycbcr:601 quantization:lim-range]
                -> "csi_mux":1 [ENABLED]

- entity 21: ov2680 1-0036 (1 pad, 1 link)
             type V4L2 subdev subtype Sensor flags 0
             device node name /dev/v4l-subdev3
        pad0: Source
                [fmt:SBGGR10_1X10/1600x1200@1/30 field:none colorspace:srgb]
                -> "imx7-mipi-csis.0":0 [ENABLED]

root@imx7s-warp-mbl:~# v4l2-ctl --set-fmt-video=width=1600,height=1200,pixelformat=RG16 --stream-mmap --stream-count=1 -d /dev/video0 --stream-to=picture_
1600_1200.raw
<

------
Cheers,
     Rui

> 
> Laurent Pinchart (75):
>   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: Move IMX_IPUV3_CORE dependency to VIDEO_IMX_CSI
>   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: 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: Convert i.MX7 MIPI CSI-2 receiver binding to YAML
>   dt-bindings: media: fsl,imx7-mipi-csi2: Drop the reset-names property
>   dt-bindings: media: fsl,imx7-mipi-csi2: Drop fsl,csis-hs-settle
>     property
>   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 pixel
>     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/fsl,imx7-mipi-csi2.yaml    |  194 ++++
>  .../bindings/media/imx7-mipi-csi2.txt         |   90 --
>  MAINTAINERS                                   |    2 +-
>  drivers/media/v4l2-core/v4l2-mc.c             |    6 +-
>  drivers/staging/media/imx/Kconfig             |   12 +-
>  drivers/staging/media/imx/Makefile            |    8 +-
>  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    | 1016 ++++++++---------
>  drivers/staging/media/imx/imx7-mipi-csis.c    |  412 ++++---
>  include/media/v4l2-mc.h                       |    8 +-
>  20 files changed, 1422 insertions(+), 1135 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/media/fsl,imx7-mipi-csi2.yaml
>  delete mode 100644 Documentation/devicetree/bindings/media/imx7-mipi-csi2.txt
> 
> -- 
> Regards,
> 
> Laurent Pinchart
> 

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

* Re: [PATCH 20/75] media: imx: capture: Rename ioctl operations with legacy prefix
  2021-01-11  8:40         ` Philipp Zabel
@ 2021-02-14 21:33           ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-02-14 21:33 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Steve Longerbeam, linux-media, Rui Miguel Silva, Ezequiel Garcia,
	Sakari Ailus

Hi Philipp,

(CC'ing Sakari)

On Mon, Jan 11, 2021 at 09:40:17AM +0100, Philipp Zabel wrote:
> On Sat, 2021-01-09 at 03:09 +0200, Laurent Pinchart wrote:
> > Could you elaborate a little bit here ? We don't have an API to
> > explicitly enumerate supported interlacing types. This can be done by
> > calling VIDIOC_TRY_FMT with all field types and see which ones are
> > supported. You can still do so with the MC-based API, the video node
> > will return from VIDIOC_TRY_FMT the interlacing types intrinsicly
> > supported by the video node, and you can query from the source subdev
> > the interlacing types supported by the source. Userspace can then
> > combine the information to find what is supported.
> 
> The i.MX6 CSI always captures whole frames, so SEQ_TB or SEQ_BT at its
> source pad.
> The IDMAC supports "interlaced scan" of SEQ_TB into INTERLACED_TB and
> SEQ_BT into INTERLACED_BT when writing to memory. It can't change the
> field timing order (BT <-> TB) as that was already decided at the CSI.
> 
> So for capture of interlaced material, the video device currently allows
> either SEQ_TB and INTERLACED_TB or SEQ_BT and INTERLACED_BT, depending
> on which field order is configured at the CSI source pad.
> 
> See d969291d8479 ("media: imx: Fix field negotiation") for details.

Thanks for the explanation.

With the MC-based API, and unless I'm mistaken, userspace can determine
what interlacing options are supported as follows. Sakari, please feel
free to confirm, or infirm.

- The video node would report support for V4L2_FIELD_NONE,
  V4L2_FIELD_SEQ_(TB|BT) and V4L2_FIELD_INTERLACED_(TB|BT).

- The CSI subdev's source pad would report V4L2_FIELD_NONE for
  progressive sources, and V4L2_FIELD_ALTERNATE for interlaced sources.
  At the bus level top and bottom frames alternate, so
  V4L2_FIELD_SEQ_(TB|BT) isn't valid as it's defined based on buffers.
  V4L2_FIELD_INTERLACED_(TB|BT) isn't valid either in this case when
  frames alternate between top and bottom (they're not interleaved on
  the bus).

- When starting the video stream, the driver would reject a mismatch
  between the source pad and the video node (V4L2_FIELD_NONE on the
  source pad and V4L2_FIELD_SEQ_* or V4L2_FIELD_INTERLACED_* on the
  video node, or the other way around).

- From a userspace point of view, the fact that both V4L2_FIELD_SEQ_*
  and V4L2_FIELD_INTERLACED_* are supported on the video node (which can
  be queried using VIDIOC_S_FMT or VIDIOC_TRY_FMT) means that the DMA
  engine can interleave interlaced content. If the IDMAC wasn't able to
  interleave lines, but was only able to capture the two fields
  sequentially in the same buffer, it would only report
  V4L2_FIELD_SEQ_*, not V4L2_FIELD_INTERLACED_*.

Does this make sense ?

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH 00/75] media: imx: Miscellaneous fixes and cleanups for i.MX7
  2021-01-09  1:47         ` Fabio Estevam
@ 2021-02-15  0:23           ` Laurent Pinchart
  0 siblings, 0 replies; 121+ messages in thread
From: Laurent Pinchart @ 2021-02-15  0:23 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: linux-media, Rui Miguel Silva, Steve Longerbeam, Philipp Zabel,
	Ezequiel Garcia

Hi Fabio,

Sorry for the late reply.

On Fri, Jan 08, 2021 at 10:47:15PM -0300, Fabio Estevam wrote:
> On Fri, Jan 8, 2021 at 10:11 PM Laurent Pinchart wrote:
> >
> > Ah of course, I should have mentioned that, sorry. Without the legacy
> > video node API, the pipeline has to be configured with the MC API and
> > the V4L2 subdev userspace API before starting the stream.
> 
> The current method I use is:
> 
> media-ctl -l "'ov5640 1-003c':0 -> 'csi':0[1]"
> media-ctl -l "'csi':1 -> 'csi capture':0[1]"
> media-ctl -v -V "'ov5640 1-003c':0 [fmt:UYVY8_2X8/320x240 field:none]"

I think this is good. The output of 'media-ctl -p' would help
double-checking.

> # gst-launch-1.0 -v  v4l2src device=/dev/video1 ! v4l2convert ! fbdevsink

Here you need to specify the format and size for the V4L2 device. I
think the following should do (I haven't tested it though and I'm no
gstreamer expert).

gst-launch-1.0 -v \
	v4l2src device=/dev/video1 ! \
	video/x-raw,format=UYVY,width=320,height=240 ! \
	v4l2convert ! \
	fbdevsink

> Could you please let me know what is the correct way I should do with
> the MC API?

-- 
Regards,

Laurent Pinchart

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

end of thread, other threads:[~2021-02-15  0:24 UTC | newest]

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

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.