Skip to contentSkip to conversation

media: imx: Miscellaneous fixes for i.MX7

PATCH In review Laurent Pinchart 3 participants 14 messages Mar 10, 2020 – Mar 12, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover media: imx: Miscellaneous fixes for i.MX7

Hello,

This patch series contains miscellaneous fixes I developed while trying to capture from a CSI-2 sensor on the i.MX7.

Patches 01/10, 02/10 and 05/10 are small fixes or enhancements, please see individual commit messages. Patch 06/10 fixes a recent issue with video field handling. Patches 03/10, 04/10 and 07/10 to 10/10 add support for 10- and 12-bit greyscale formats (both on the i.MX7 CSI-2 receiver side and the CSI side), including the ability to clamp Y10 and Y12 to Y8.

Steve, Philipp, Rui, once you get to review this series, will you submit a pull request or should I do so ?

Laurent Pinchart (10):
media: imx: imx7_mipi_csis: Power off the source when stopping
streaming
media: imx: imx7_mipi_csis: Print the RESOL_CH0 register
media: imx: imx7_mipi_csis: Add greyscale formats support
media: imx: imx7-mipi-csis: Filter on CSI-2 data type
media: imx: imx7-media-csi: Remove unneeded register read
media: imx: imx7-media-csi: Fix video field handling
media: imx: imx6-media-csi: Replace Y16 with Y10 and Y12
media: imx: imx6-media-csi: Support clamping Y10 and Y12 to Y8
media: imx: imx7-media-csi: Add Y10 and Y12 formats support
media: imx: imx7-media-csi: Support clamping Y10 and Y12 to Y8

 drivers/staging/media/imx/imx-media-csi.c   |  3 ++-
 drivers/staging/media/imx/imx-media-utils.c | 19 ++++++++++++------
 drivers/staging/media/imx/imx7-media-csi.c  | 22 ++++++++++++++++++++-
 drivers/staging/media/imx/imx7-mipi-csis.c  | 16 ++++++++++++++-
 4 files changed, 51 insertions(+), 9 deletions(-)
Signature · 3 lines
Regards,

Laurent Pinchart
#1 lore raw

PATCH v2 1/10 media: imx: imx7_mipi_csis: Power off the source when stopping streaming

The .s_stream() implementation incorrectly powers on the source when stopping the stream. Power it off instead.

Fixes 7807063b862b ("media: staging/imx7: add MIPI CSI-2 receiver subdev for i.MX7")

---
Changes since v1:

- Added Fixes: tag

---
 drivers/staging/media/imx/imx7-mipi-csis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/imx/imx7-mipi-csis.c +1 -1
index 383abecb3bec..0053e8b0b88e 100644
@@ -577,7 +577,7 @@ 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, 1);
+		ret = v4l2_subdev_call(state->src_sd, core, s_power, 0);
 		mipi_csis_stop_stream(state);
 		state->flags &= ~ST_STREAMING;
 		if (state->debug)
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

PATCH v2 2/10 media: imx: imx7_mipi_csis: Print the RESOL_CH0 register

In reply to Laurent Pinchart

Add the RESOL_CH0 register to the list of registers printed through the debugfs debug infrastructure for the driver, as it can be useful to verify proper configuration of the CSI-2 receiver.

---
 drivers/staging/media/imx/imx7-mipi-csis.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/media/imx/imx7-mipi-csis.c +1 -0
index 0053e8b0b88e..f96e32549381 100644
@@ -301,6 +301,7 @@ static int mipi_csis_dump_regs(struct csi_state *state)
 		{ 0x20, "DPHYSTS" },
 		{ 0x10, "INTMSK" },
 		{ 0x40, "CONFIG_CH0" },
+		{ 0x44, "RESOL_CH0" },
 		{ 0xC0, "DBG_CONFIG" },
 		{ 0x38, "DPHYSLAVE_L" },
 		{ 0x3C, "DPHYSLAVE_H" },
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

PATCH v2 3/10 media: imx: imx7_mipi_csis: Add greyscale formats support

In reply to Laurent Pinchart

Add support for the 8-, 10- and 12-bit greyscale media bus formats, and map them to the CSI-2 RAW8, RAW10 and RAW12 formats respectively.

---
 drivers/staging/media/imx/imx7-mipi-csis.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/staging/media/imx/imx7-mipi-csis.c +12 -0
index f96e32549381..2dd0b02e98b7 100644
@@ -280,6 +280,18 @@ static const struct csis_pix_format mipi_csis_formats[] = {
 		.code = MEDIA_BUS_FMT_YUYV8_2X8,
 		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
 		.data_alignment = 16,
+	}, {
+		.code = MEDIA_BUS_FMT_Y8_1X8,
+		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RAW8,
+		.data_alignment = 8,
+	}, {
+		.code = MEDIA_BUS_FMT_Y10_1X10,
+		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RAW10,
+		.data_alignment = 16,
+	}, {
+		.code = MEDIA_BUS_FMT_Y12_1X12,
+		.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RAW12,
+		.data_alignment = 16,
 	}
 };
 
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

PATCH v2 4/10 media: imx: imx7-mipi-csis: Filter on CSI-2 data type

In reply to Laurent Pinchart

Enable filtering based on CSI-2 data type. Otherwise sources that send multiple data types (such as sensors that send embedded data) will not be properly supported. They will both result in additional non-image lines being captured, and in the receiver being confused as it doesn't resynchronise on vsync.

---
 drivers/staging/media/imx/imx7-mipi-csis.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/media/imx/imx7-mipi-csis.c +1 -0
index 2dd0b02e98b7..de17a1d22873 100644
@@ -430,6 +430,7 @@ static void mipi_csis_set_params(struct csi_state *state)
 	val = mipi_csis_read(state, MIPI_CSIS_CMN_CTRL);
 	val &= ~MIPI_CSIS_CMN_CTRL_LANE_NR_MASK;
 	val |= (lanes - 1) << MIPI_CSIS_CMN_CTRL_LANE_NR_OFFSET;
+	val |= MIPI_CSIS_CMN_CTRL_INTER_MODE;
 	mipi_csis_write(state, MIPI_CSIS_CMN_CTRL, val);
 
 	__mipi_csis_set_format(state);
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

PATCH v2 5/10 media: imx: imx7-media-csi: Remove unneeded register read

In reply to Laurent Pinchart

The imx7_csi_dma_reflash() function starts by reading the unrelated register CSI_CSICR18 to then overwrite the read value with a read from register CSI_CSICR3. This is likely due to a bad copy&paste, and is not needed. Remove the extraneous read from register CSI_CSICR18.

Fixes 9e5fa4e1e5b5b ("media: imx7-media-csi: Use u32 for storing register reads")

---
Changes since v1:

- Add Fixes: tag

---
 drivers/staging/media/imx/imx7-media-csi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/imx/imx7-media-csi.c +1 -1
index db30e2c70f2f..2f665e4b8c40 100644
@@ -292,7 +292,7 @@ static void imx7_csi_hw_disable(struct imx7_csi *csi)
 
 static void imx7_csi_dma_reflash(struct imx7_csi *csi)
 {
-	u32 cr3 = imx7_csi_reg_read(csi, CSI_CSICR18);
+	u32 cr3;
 
 	cr3 = imx7_csi_reg_read(csi, CSI_CSICR3);
 	cr3 |= BIT_DMA_REFLASH_RFF;
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

PATCH v2 6/10 media: imx: imx7-media-csi: Fix video field handling

In reply to Laurent Pinchart

Commit 4791bd7d6adc ("media: imx: Try colorimetry at both sink and source pads") reworked the way that formats are set on the sink pad of the CSI subdevice, and accidentally removed video field handling. Restore it by defaulting to V4L2_FIELD_NONE if the field value isn't supported, with the only two supported value being V4L2_FIELD_NONE and V4L2_FIELD_INTERLACED.

Fixes 4791bd7d6adc ("media: imx: Try colorimetry at both sink and source pads")

---
Changes since v1:

- Fix commit message to mention V4L2_FIELD_INTERLACED instead of V4L2_FIELD_ALTERNATE

---
 drivers/staging/media/imx/imx7-media-csi.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/staging/media/imx/imx7-media-csi.c +4 -0
index 2f665e4b8c40..706c47741a3c 100644
@@ -1009,6 +1009,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 		sdformat->format.width = in_fmt->width;
 		sdformat->format.height = in_fmt->height;
 		sdformat->format.code = in_fmt->code;
+		sdformat->format.field = in_fmt->field;
 		*cc = in_cc;
 
 		sdformat->format.colorspace = in_fmt->colorspace;
@@ -1023,6 +1024,9 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
 							 false);
 			sdformat->format.code = (*cc)->codes[0];
 		}
+
+		if (sdformat->format.field != V4L2_FIELD_INTERLACED)
+			sdformat->format.field = V4L2_FIELD_NONE;
 		break;
 	default:
 		return -EINVAL;
Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

PATCH v2 7/10 media: imx: imx6-media-csi: Replace Y16 with Y10 and Y12

In reply to Laurent Pinchart

The driver doesn't really support V4L2_PIX_FMT_Y16, as there's no 16-bit greyscale media bus code defined by the kernel. It (ab)uses the format to capture 10-bit and 12-bit greyscale formats. Fix it to properly support MEDIA_BUS_FMT_Y10_1X10 and MEDIA_BUS_FMT_Y12_1X12 instead.

---
 drivers/staging/media/imx/imx-media-csi.c   |  3 ++-
 drivers/staging/media/imx/imx-media-utils.c | 13 ++++++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +2 -1
index b60ed4f22f6d..f4abac93c0e4 100644
@@ -457,7 +457,8 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
 	case V4L2_PIX_FMT_SGBRG16:
 	case V4L2_PIX_FMT_SGRBG16:
 	case V4L2_PIX_FMT_SRGGB16:
-	case V4L2_PIX_FMT_Y16:
+	case V4L2_PIX_FMT_Y10:
+	case V4L2_PIX_FMT_Y12:
 		burst_size = 8;
 		passthrough_bits = 16;
 		break;
drivers/staging/media/imx/imx-media-utils.c +8 -5
index 0788a1874557..bc20fcc88267 100644
@@ -166,11 +166,14 @@ static const struct imx_media_pixfmt rgb_formats[] = {
 		.bpp    = 8,
 		.bayer  = true,
 	}, {
-		.fourcc = V4L2_PIX_FMT_Y16,
-		.codes = {
-			MEDIA_BUS_FMT_Y10_1X10,
-			MEDIA_BUS_FMT_Y12_1X12,
-		},
+		.fourcc = V4L2_PIX_FMT_Y10,
+		.codes = {MEDIA_BUS_FMT_Y10_1X10},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_Y12,
+		.codes = {MEDIA_BUS_FMT_Y12_1X12},
 		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 16,
 		.bayer  = true,
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer Acked-by on v2 7/10
#8 lore raw

Re: [PATCH v2 07/10] media: imx: imx6-media-csi: Replace Y16 with Y10 and Y12

Quoted 4 lines · Laurent Pinchart

The driver doesn't really support V4L2_PIX_FMT_Y16, as there's no 16-bit greyscale media bus code defined by the kernel. It (ab)uses the format to capture 10-bit and 12-bit greyscale formats. Fix it to properly support MEDIA_BUS_FMT_Y10_1X10 and MEDIA_BUS_FMT_Y12_1X12 instead.

I thought this might need a Fixes: e30681bc19bf ("media: imx: add 16-bit grayscale support"), but on closer look, V4L2_PIX_FMT_Y10 and V4L2_PIX_FMT_Y12 were not added until after. In any case,

Quoted 46 lines
---
  drivers/staging/media/imx/imx-media-csi.c   |  3 ++-
  drivers/staging/media/imx/imx-media-utils.c | 13 ++++++++-----
  2 files changed, 10 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +2 -1
index b60ed4f22f6d..f4abac93c0e4 100644
@@ -457,7 +457,8 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
  	case V4L2_PIX_FMT_SGBRG16:
  	case V4L2_PIX_FMT_SGRBG16:
  	case V4L2_PIX_FMT_SRGGB16:
-	case V4L2_PIX_FMT_Y16:
+	case V4L2_PIX_FMT_Y10:
+	case V4L2_PIX_FMT_Y12:
  		burst_size = 8;
  		passthrough_bits = 16;
  		break;
drivers/staging/media/imx/imx-media-utils.c +8 -5
index 0788a1874557..bc20fcc88267 100644
@@ -166,11 +166,14 @@ static const struct imx_media_pixfmt rgb_formats[] = {
  		.bpp    = 8,
  		.bayer  = true,
  	}, {
-		.fourcc = V4L2_PIX_FMT_Y16,
-		.codes = {
-			MEDIA_BUS_FMT_Y10_1X10,
-			MEDIA_BUS_FMT_Y12_1X12,
-		},
+		.fourcc = V4L2_PIX_FMT_Y10,
+		.codes = {MEDIA_BUS_FMT_Y10_1X10},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_Y12,
+		.codes = {MEDIA_BUS_FMT_Y12_1X12},
  		.cs     = IPUV3_COLORSPACE_RGB,
  		.bpp    = 16,
  		.bayer  = true,
#9 lore raw

PATCH v2 8/10 media: imx: imx6-media-csi: Support clamping Y10 and Y12 to Y8

In reply to Laurent Pinchart

10-bit and 12-bit greyscale input data to the CSI can be written as 8-bit data to memory. Support this.

---
 drivers/staging/media/imx/imx-media-utils.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/media/imx/imx-media-utils.c +5 -1
index bc20fcc88267..fae981698c49 100644
@@ -161,7 +161,11 @@ static const struct imx_media_pixfmt rgb_formats[] = {
 		.bayer  = true,
 	}, {
 		.fourcc = V4L2_PIX_FMT_GREY,
-		.codes = {MEDIA_BUS_FMT_Y8_1X8},
+		.codes = {
+			MEDIA_BUS_FMT_Y8_1X8,
+			MEDIA_BUS_FMT_Y10_1X10,
+			MEDIA_BUS_FMT_Y12_1X12,
+		},
 		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 8,
 		.bayer  = true,
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer Acked-by on v2 8/10
#10 lore raw

Re: [PATCH v2 08/10] media: imx: imx6-media-csi: Support clamping Y10 and Y12 to Y8

Quoted 4 lines · Laurent Pinchart

10-bit and 12-bit greyscale input data to the CSI can be written as 8-bit data to memory. Support this.

Quoted 21 lines
---
  drivers/staging/media/imx/imx-media-utils.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/media/imx/imx-media-utils.c +5 -1
index bc20fcc88267..fae981698c49 100644
@@ -161,7 +161,11 @@ static const struct imx_media_pixfmt rgb_formats[] = {
  		.bayer  = true,
  	}, {
  		.fourcc = V4L2_PIX_FMT_GREY,
-		.codes = {MEDIA_BUS_FMT_Y8_1X8},
+		.codes = {
+			MEDIA_BUS_FMT_Y8_1X8,
+			MEDIA_BUS_FMT_Y10_1X10,
+			MEDIA_BUS_FMT_Y12_1X12,
+		},
  		.cs     = IPUV3_COLORSPACE_RGB,
  		.bpp    = 8,
  		.bayer  = true,
#11 lore raw

PATCH v2 9/10 media: imx: imx7-media-csi: Add Y10 and Y12 formats support

In reply to Laurent Pinchart

Support capturing the 10- and 12-bit greyscale formats.

---
 drivers/staging/media/imx/imx7-media-csi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/staging/media/imx/imx7-media-csi.c +8 -0
index 706c47741a3c..e85202255168 100644
@@ -804,6 +804,14 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 	case V4L2_PIX_FMT_YUYV:
 		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
 		break;
+	case V4L2_PIX_FMT_Y10:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
+		cr1 |= BIT_PIXEL_BIT;
+		break;
+	case V4L2_PIX_FMT_Y12:
+		cr18 |= BIT_MIPI_DATA_FORMAT_RAW12;
+		cr1 |= BIT_PIXEL_BIT;
+		break;
 	case V4L2_PIX_FMT_SBGGR8:
 		cr18 |= BIT_MIPI_DATA_FORMAT_RAW8;
 		break;
Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

PATCH v2 10/10 media: imx: imx7-media-csi: Support clamping Y10 and Y12 to Y8

In reply to Laurent Pinchart

10-bit and 12-bit greyscale input data to the CSI can be written as 8-bit data to memory. Support this.

---
 drivers/staging/media/imx/imx7-media-csi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/staging/media/imx/imx7-media-csi.c +8 -0
index e85202255168..3225082ce58d 100644
@@ -804,6 +804,14 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 	case V4L2_PIX_FMT_YUYV:
 		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
 		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:
 		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
 		cr1 |= BIT_PIXEL_BIT;
Signature · 3 lines
Regards,

Laurent Pinchart
Reviewed-by on v2 10/10
#13 lore raw

Re: [PATCH v2 10/10] media: imx: imx7-media-csi: Support clamping Y10 and Y12 to Y8

Hi Laurent,
Thanks for this, I think this is the only one I did not acked.

Quoted 4 lines · Laurent Pinchart

10-bit and 12-bit greyscale input data to the CSI can be written as 8-bit data to memory. Support this.

------
Cheers,
Rui

Quoted 28 lines
---
 drivers/staging/media/imx/imx7-media-csi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/staging/media/imx/imx7-media-csi.c +8 -0
index e85202255168..3225082ce58d 100644
@@ -804,6 +804,14 @@ static int imx7_csi_configure(struct imx7_csi *csi)
 	case V4L2_PIX_FMT_YUYV:
 		cr18 |= BIT_MIPI_DATA_FORMAT_YUV422_8B;
 		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:
 		cr18 |= BIT_MIPI_DATA_FORMAT_RAW10;
 		cr1 |= BIT_PIXEL_BIT;
Signature · 3 lines
Regards,

Laurent Pinchart