Skip to contentSkip to conversation

media: imx8-isi: Add i.MX952 ISI support

PATCH Superseded Guoniu Zhou 3 participants 21 messages Nov 16 – Dec 1

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover media: imx8-isi: Add i.MX952 ISI support

The series adds support for the i.MX952 Image Sensing Interface (ISI), which is a minor silicon revision of the i.MX95 ISI.

The i.MX952 ISI reuses the i.MX95 ISI core with the same 8-channel pipeline and 4 pixel link inputs. The key hardware improvement is the addition of RAW10/12/14 output LSB alignment, which allows the ISI to output right-aligned RAW data directly, matching the V4L2 format requirement without the RAW16 workaround needed on earlier platforms.

The series is organized as follows:

1. Reorder mxc_imx95_data definition to follow mxc_imx93_data, matching the order in the of_match array.
2. Extend output format mask to 7 bits unconditionally since bit 30 is unused on older platforms.
3. Support mbus_code filtering in mxc_isi_format_enum().
4. Reuse mxc_isi_format_enum() in capture format enumeration.
5. Apply RAW output format workaround at runtime, storing the actual hardware format in the format table.
6. Add RAW14 output format support (available from i.MX8ULP).
7. Select MSB-aligned RAW input from pixel link on i.MX95.
8. Exclude RAW10/12/14 output formats on i.MX95.
9. Add the i.MX952 compatible string to the DT binding.
10. Add the i.MX952 platform data and of_match entry.
11. Enable RAW10/12/14 output LSB alignment on i.MX952.

Review status
==============

Most review comments received on previous revisions have been addressed and several patches have already collected Reviewed-by/Acked-by tags.

The only remaining open topic in this series is the RAW alignment handling discussed at:

https://lore.kernel.org/all/ar028ZyZg56Mk60M@lizhi-Precision-Tower-5810/
https://lore.kernel.org/all/ar00qevdwDHYAEy9@SMW015318/

The discussion affects the final patch:

media: imx8-isi: Enable RAW10/12/14 output LSB alignment on i.MX952
media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95

I would especially appreciate Laurent Pinchart's feedback on the proposed approach, as this is the last unresolved topic before the series is ready for merging.

---
Changes in v5:
- Rebase to latest media/next(7969a6f407cf)
- [3/11] Clarify that this preparatory patch introduces no functional change (Laurent)
- Collect Reviewed-by tags
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Rebase to latest media/next(2dcdfb625c3b)
- Split the original patch 5/5 into multiple focused patches:
patches 3-8 are new, each addressing a specific aspect
- [3/11] New: Support mbus_code filtering in mxc_isi_format_enum()
- [4/11] New: Reuse mxc_isi_format_enum() in capture format enumeration
- [5/11] New: Apply RAW output format workaround at runtime
- [6/11] New: Add RAW14 output format support
- [7/11] New: Select MSB-aligned RAW input from pixel link on i.MX95
- [8/11] New: Exclude RAW10/12/14 output formats on i.MX95
- [11/11] Split RAW_IN_MSB_ALIGN into a separate preceding patch
- [11/11] Split RAW format table and RAW14 changes into separate preceding patches
- [11/11] Move isi_out_raw_shifted() to regs.h in the preceding workaround patch
- [11/11] Rewrite commit message
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- [1/5] Add Reviewed-by tag from Laurent
- [2/5] Use unconditional 7-bit mask instead of per-platform approach (Laurent)
- [2/5] Drop Reviewed-by from Frank Li due to significant change and request to review again
- [3/5] Add Reviewed-by/Acked-by tag from Frank, Laurent and Dooley
- [4/5] Extend mask globally instead of per-platform (Laurent)
- [4/5] Add Reviewed-by tag from Frank
- [5/5] Use CHNL_IMG_CTRL_FORMAT_MASK instead of the removed per-platform format_mask (Laurent)
- [5/5] Derive raw_out_lsb from the model field instead of dedicated platform data (Laurent)
- [5/5] Clarify the CHNL_IMG_CTRL_FORMAT_RAW14 comment: the format is documented on i.MX{8ULP,91,93,95,952} but only used on i.MX952
- [5/5] Rewrite commit message to explain why the RAW16 workaround fails on i.MX95+ (Laurent)
- [5/5] Add Reviewed-by tag from Frank
- Drop "Remove unused model field" patch; model field is now used to derive raw_out_lsb capability (Laurent)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Use fallback compatible fsl,imx95-isi for imx952 (Frank)
- Remove unused model field from platform data (Frank)
- Add Reviewed-by tag from Frank Li for patch 1/6 and 2/6
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Guoniu Zhou (11):
media: imx8-isi: Reorder mxc_imx95_data to follow mxc_imx93_data
media: imx8-isi: Extend output format mask to 7 bits
media: imx8-isi: Support mbus_code filtering in format enumeration
media: imx8-isi: Reuse mxc_isi_format_enum() in capture format enumeration
media: imx8-isi: Apply RAW output format workaround at runtime
media: imx8-isi: Add RAW14 output format support
media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95
media: imx8-isi: Exclude RAW10/12/14 output formats on i.MX95
media: dt-bindings: nxp,imx8-isi: Add i.MX952 ISI compatible string
media: imx8-isi: Add i.MX952 ISI support
media: imx8-isi: Enable RAW10/12/14 output LSB alignment on i.MX952

 .../devicetree/bindings/media/nxp,imx8-isi.yaml    |  18 ++--
 .../media/platform/nxp/imx8-isi/imx8-isi-core.c    |  37 ++++---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.h    |   7 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c  |  56 ++++++++++-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |   2 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    |  22 ++++-
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 110 ++++++++++-----------
 7 files changed, 171 insertions(+), 81 deletions(-)

---
base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
change-id: 20260817-isi_imx952-66ca65f9b638

Best regards,

Signature · 1 line
Guoniu Zhou <[email protected]>
#1 lore raw

PATCH v5 1/11 media: imx8-isi: Reorder mxc_imx95_data to follow mxc_imx93_data

Move mxc_imx95_data definition after mxc_imx93_data to match the order defined in the of_match array.

---
Changes in v3:
- Add Reviewed-by tag from Laurent

Changes in v2:
- Add Reviewed-by tag from Frank Li

---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.c    | 24 +++++++++++-----------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +12 -12
index 0ae5f35e017c..f2a8eb82fbfd 100644
@@ -314,18 +314,6 @@ static const struct mxc_isi_plat_data mxc_imx8mp_data = {
 	.has_36bit_dma		= true,
 };
 
-static const struct mxc_isi_plat_data mxc_imx95_data = {
-	.model			= MXC_ISI_IMX95,
-	.num_ports		= 4,
-	.num_channels		= 8,
-	.num_vc			= 8,
-	.reg_offset		= 0x10000,
-	.ier_reg		= &mxc_imx8_isi_ier_v2,
-	.set_thd		= &mxc_imx8_isi_thd_v1,
-	.buf_active_reverse	= true,
-	.has_36bit_dma		= true,
-};
-
 static const struct mxc_isi_plat_data mxc_imx8qm_data = {
 	.model			= MXC_ISI_IMX8QM,
 	.num_ports		= 5,
@@ -384,6 +372,18 @@ static const struct mxc_isi_plat_data mxc_imx93_data = {
 	.has_36bit_dma		= false,
 };
 
+static const struct mxc_isi_plat_data mxc_imx95_data = {
+	.model			= MXC_ISI_IMX95,
+	.num_ports		= 4,
+	.num_channels		= 8,
+	.num_vc			= 8,
+	.reg_offset		= 0x10000,
+	.ier_reg		= &mxc_imx8_isi_ier_v2,
+	.set_thd		= &mxc_imx8_isi_thd_v1,
+	.buf_active_reverse	= true,
+	.has_36bit_dma		= true,
+};
+
 /* -----------------------------------------------------------------------------
  * Power management
  */
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/11 media: imx8-isi: Extend output format mask to 7 bits

In reply to Guoniu Zhou

The ISI output format field width differs across SoC generations:
i.MX8 series (MN/MP/QM/QXP) use a 6-bit field (bits 29:24), while from i.MX8ULP onwards (including i.MX91/93/95/952) the field is extended to 7 bits (bits 30:24) to support RAW32 and RAW14 formats.

Extend CHNL_IMG_CTRL_FORMAT_MASK to 7 bits unconditionally since bit 30 is unused on older platforms.

---
Changes in v3:
- Use unconditional 7-bit mask instead of per-platform approach (Laurent)
- Drop Reviewed-by from Frank Li due to significant change

Changes in v2:
- Add Reviewed-by tag from Frank Li

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -1
index e795f4daf3ff..c704be882705 100644
@@ -39,7 +39,7 @@
 /* Channel Image Control Register */
 #define CHNL_IMG_CTRL						0x0004
 #define CHNL_IMG_CTRL_FORMAT(n)					((n) << 24)
-#define CHNL_IMG_CTRL_FORMAT_MASK				GENMASK(29, 24)
+#define CHNL_IMG_CTRL_FORMAT_MASK				GENMASK(30, 24)
 #define CHNL_IMG_CTRL_FORMAT_RGBA8888				0x00
 #define CHNL_IMG_CTRL_FORMAT_ABGR8888				0x01
 #define CHNL_IMG_CTRL_FORMAT_ARGB8888				0x02
Signature · 1 line
2.34.1
#3 lore raw

PATCH v5 3/11 media: imx8-isi: Support mbus_code filtering in format enumeration

In reply to Guoniu Zhou

Extend mxc_isi_format_enum() to accept a v4l2_fmtdesc pointer instead of a plain index, allowing callers to filter formats by mbus_code.

This is a preparatory change for capture format enumeration. No functional change is introduced by this patch. For the M2M device, mbus_code is always cleared by the V4L2 framework for devices without V4L2_CAP_IO_MC (v4l2-ioctl.c), so format enumeration remains unchanged.

---
Changes in v5:
- Clarify that this preparatory patch introduces no functional change (Laurent).

Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h  | 2 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c   | 2 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 6 +++++-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -1
index 58b47335afc7..a30633a7e2e9 100644
@@ -322,7 +322,7 @@ mxc_isi_bus_format_by_index(unsigned int index, unsigned int pad);
 const struct mxc_isi_format_info *
 mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(unsigned int index, enum mxc_isi_video_type type);
+mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
 mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix,
 		   enum mxc_isi_video_type type);
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +1 -1
index b729eecad0fe..1178947bb548 100644
@@ -492,7 +492,7 @@ static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh,
 		MXC_ISI_VIDEO_M2M_OUT : MXC_ISI_VIDEO_M2M_CAP;
 	const struct mxc_isi_format_info *info;
 
-	info = mxc_isi_format_enum(f->index, type);
+	info = mxc_isi_format_enum(f, type);
 	if (!info)
 		return -EINVAL;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +5 -1
index fc907d357149..a904cd2739ea 100644
@@ -482,13 +482,17 @@ mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
 }
 
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(unsigned int index, enum mxc_isi_video_type type)
+mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 {
+	unsigned int index = f->index;
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		if (f->mbus_code && fmt->mbus_code != f->mbus_code)
+			continue;
+
 		if (!(fmt->type & type))
 			continue;
 
Signature · 1 line
2.34.1
maintainer Reviewed-by on v5 3/11
#4 lore raw

Re: [PATCH v5 03/11] media: imx8-isi: Support mbus_code filtering in format enumeration

Quoted 10 lines · Guoniu Zhou

Extend mxc_isi_format_enum() to accept a v4l2_fmtdesc pointer instead of a plain index, allowing callers to filter formats by mbus_code.

This is a preparatory change for capture format enumeration. No functional change is introduced by this patch. For the M2M device, mbus_code is always cleared by the V4L2 framework for devices without V4L2_CAP_IO_MC (v4l2-ioctl.c), so format enumeration remains unchanged.

Quoted 61 lines

---
Changes in v5:
- Clarify that this preparatory patch introduces no functional change (Laurent).

Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h  | 2 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c   | 2 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 6 +++++-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -1
index 58b47335afc7..a30633a7e2e9 100644
@@ -322,7 +322,7 @@ mxc_isi_bus_format_by_index(unsigned int index, unsigned int pad);
 const struct mxc_isi_format_info *
 mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(unsigned int index, enum mxc_isi_video_type type);
+mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
 mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix,
 		   enum mxc_isi_video_type type);
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +1 -1
index b729eecad0fe..1178947bb548 100644
@@ -492,7 +492,7 @@ static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh,
 		MXC_ISI_VIDEO_M2M_OUT : MXC_ISI_VIDEO_M2M_CAP;
 	const struct mxc_isi_format_info *info;
 
-	info = mxc_isi_format_enum(f->index, type);
+	info = mxc_isi_format_enum(f, type);
 	if (!info)
 		return -EINVAL;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +5 -1
index fc907d357149..a904cd2739ea 100644
@@ -482,13 +482,17 @@ mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
 }
 
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(unsigned int index, enum mxc_isi_video_type type)
+mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 {
+	unsigned int index = f->index;
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		if (f->mbus_code && fmt->mbus_code != f->mbus_code)
+			continue;
+
 		if (!(fmt->type & type))
 			continue;
 
Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw

PATCH v5 4/11 media: imx8-isi: Reuse mxc_isi_format_enum() in capture format enumeration

In reply to Guoniu Zhou

Simplify mxc_isi_video_enum_fmt() by reusing mxc_isi_format_enum() instead of open-coding the same format table traversal.

---
Changes in v4:
- New patch

---
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 30 +++-------------------
 1 file changed, 3 insertions(+), 27 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +3 -27
index a904cd2739ea..af91bd65b2c1 100644
@@ -1231,34 +1231,10 @@ static int mxc_isi_video_enum_fmt(struct file *file, void *priv,
 				  struct v4l2_fmtdesc *f)
 {
 	const struct mxc_isi_format_info *fmt;
-	unsigned int index = f->index;
-	unsigned int i;
-
-	if (f->mbus_code) {
-		/*
-		 * If a media bus code is specified, only enumerate formats
-		 * compatible with it.
-		 */
-		for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
-			fmt = &mxc_isi_formats[i];
-			if (fmt->mbus_code != f->mbus_code)
-				continue;
-
-			if (index == 0)
-				break;
-
-			index--;
-		}
 
-		if (i == ARRAY_SIZE(mxc_isi_formats))
-			return -EINVAL;
-	} else {
-		/* Otherwise, enumerate all formatS. */
-		if (f->index >= ARRAY_SIZE(mxc_isi_formats))
-			return -EINVAL;
-
-		fmt = &mxc_isi_formats[f->index];
-	}
+	fmt = mxc_isi_format_enum(f, MXC_ISI_VIDEO_CAP);
+	if (!fmt)
+		return -EINVAL;
 
 	f->pixelformat = fmt->fourcc;
 	f->flags |= V4L2_FMT_FLAG_CSC_COLORSPACE | V4L2_FMT_FLAG_CSC_YCBCR_ENC
Signature · 1 line
2.34.1
#6 lore raw

PATCH v5 5/11 media: imx8-isi: Apply RAW output format workaround at runtime

In reply to Guoniu Zhou

Refactor the RAW format handling by storing the actual hardware output format (RAW10/RAW12) in the format table instead of the workaround value RAW16. The RAW16 workaround is now applied at runtime in mxc_isi_channel_set_output_format() via the new isi_out_raw_shifted() helper in imx8-isi-regs.h.

This makes the format table accurately reflect the real hardware capability.

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c  |  7 ++++-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    | 13 ++++++++++
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 30 ++++++++--------------
 3 files changed, 30 insertions(+), 20 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +6 -1
index 6aa760ce3605..cc52a90c2477 100644
@@ -411,13 +411,18 @@ void mxc_isi_channel_set_output_format(struct mxc_isi_pipe *pipe,
 				       struct v4l2_pix_format_mplane *format)
 {
 	u32 val;
+	u32 fmt;
 
 	/* set outbuf format */
 	dev_dbg(pipe->isi->dev, "output format %p4cc", &format->pixelformat);
 
+	fmt = isi_out_raw_shifted(info->isi_out_format)
+	    ? CHNL_IMG_CTRL_FORMAT_RAW16
+	    : info->isi_out_format;
+
 	val = mxc_isi_read(pipe, CHNL_IMG_CTRL);
 	val &= ~CHNL_IMG_CTRL_FORMAT_MASK;
-	val |= CHNL_IMG_CTRL_FORMAT(info->isi_out_format);
+	val |= CHNL_IMG_CTRL_FORMAT(fmt);
 	mxc_isi_write(pipe, CHNL_IMG_CTRL, val);
 
 	/* line pitch */
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +13 -0
index c704be882705..0f3ada30e71e 100644
@@ -421,4 +421,17 @@
 /* Channel Input Buffer Extended Address Bits */
 #define CHNL_IN_BUF_XTND_ADDR					0x00b8
 
+/*
+ * The ISI shifts the 10-bit and 12-bit RAW formats left by 6 and 4 bits when
+ * using CHNL_IMG_CTRL_FORMAT_RAW10 or CHNL_IMG_CTRL_FORMAT_RAW12 respectively,
+ * to align the bits to the left and pad with zeros in the LSBs. The
+ * corresponding V4L2 formats are however right-aligned, so
+ * CHNL_IMG_CTRL_FORMAT_RAW16 must be used to avoid the left shift.
+ */
+static inline bool isi_out_raw_shifted(u32 format)
+{
+	return format == CHNL_IMG_CTRL_FORMAT_RAW10 ||
+	       format == CHNL_IMG_CTRL_FORMAT_RAW12;
+}
+
 #endif /* __IMX8_ISI_REGS_H__ */
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +11 -19
index af91bd65b2c1..978a637f539d 100644
@@ -218,15 +218,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.depth		= { 32 },
 		.encoding	= MXC_ISI_ENC_RGB,
 	},
-	/*
-	 * RAW formats
-	 *
-	 * The ISI shifts the 10-bit and 12-bit formats left by 6 and 4 bits
-	 * when using CHNL_IMG_CTRL_FORMAT_RAW10 or MXC_ISI_OUT_FMT_RAW12
-	 * respectively, to align the bits to the left and pad with zeros in
-	 * the LSBs. The corresponding V4L2 formats are however right-aligned,
-	 * we have to use CHNL_IMG_CTRL_FORMAT_RAW16 to avoid the left shift.
-	 */
+	/* RAW formats */
 	{
 		.mbus_code	= MEDIA_BUS_FMT_Y8_1X8,
 		.fourcc		= V4L2_PIX_FMT_GREY,
@@ -240,7 +232,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y10_1X10,
 		.fourcc		= V4L2_PIX_FMT_Y10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -249,7 +241,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y12_1X12,
 		.fourcc		= V4L2_PIX_FMT_Y12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -312,7 +304,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SBGGR10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -321,7 +313,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SGBRG10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -330,7 +322,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SGRBG10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -339,7 +331,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SRGGB10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -348,7 +340,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SBGGR12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -357,7 +349,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SGBRG12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -366,7 +358,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SGRBG12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -375,7 +367,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SRGGB12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH v5 05/11] media: imx8-isi: Apply RAW output format workaround at runtime

Hi Zhou,

Quoted 2 lines · Guoniu Zhou

Refactor the RAW format handling by storing the actual hardware output format (RAW10/RAW12) in the format table instead of the workaround value

It's not a workaround, it's just the correct way for all platforms supported so far to produce the RAW10/12/14 formats that V4L2 expect.

Quoted 6 lines

RAW16. The RAW16 workaround is now applied at runtime in mxc_isi_channel_set_output_format() via the new isi_out_raw_shifted() helper in imx8-isi-regs.h.

This makes the format table accurately reflect the real hardware capability.

The commit message should explain why.

Quoted 41 lines

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c  |  7 ++++-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    | 13 ++++++++++
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 30 ++++++++--------------
 3 files changed, 30 insertions(+), 20 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +6 -1
index 6aa760ce3605..cc52a90c2477 100644
@@ -411,13 +411,18 @@ void mxc_isi_channel_set_output_format(struct mxc_isi_pipe *pipe,
 				       struct v4l2_pix_format_mplane *format)
 {
 	u32 val;
+	u32 fmt;
 
 	/* set outbuf format */
 	dev_dbg(pipe->isi->dev, "output format %p4cc", &format->pixelformat);
 
+	fmt = isi_out_raw_shifted(info->isi_out_format)
+	    ? CHNL_IMG_CTRL_FORMAT_RAW16
+	    : info->isi_out_format;
+
 	val = mxc_isi_read(pipe, CHNL_IMG_CTRL);
 	val &= ~CHNL_IMG_CTRL_FORMAT_MASK;
-	val |= CHNL_IMG_CTRL_FORMAT(info->isi_out_format);
+	val |= CHNL_IMG_CTRL_FORMAT(fmt);
 	mxc_isi_write(pipe, CHNL_IMG_CTRL, val);
 
 	/* line pitch */
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +0 -0
index c704be882705..0f3ada30e71e 100644
@@ -421,4 +421,17 @@
 /* Channel Input Buffer Extended Address Bits */

drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h line 431

Quoted 10 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +8 -0
 #define CHNL_IN_BUF_XTND_ADDR					0x00b8
 
+/*
+ * The ISI shifts the 10-bit and 12-bit RAW formats left by 6 and 4 bits when
+ * using CHNL_IMG_CTRL_FORMAT_RAW10 or CHNL_IMG_CTRL_FORMAT_RAW12 respectively,
+ * to align the bits to the left and pad with zeros in the LSBs. The
+ * corresponding V4L2 formats are however right-aligned, so
+ * CHNL_IMG_CTRL_FORMAT_RAW16 must be used to avoid the left shift.
+ */
+static inline bool isi_out_raw_shifted(u32 format)

Reading this function, and other similar helpers in subsequent patches, I think the APIs need to be improved. This series makes the code complicated to follow, with functions whose names are confusing. It gives me a feeling of LLM-generated code, that is not completely wrong, but also not quite right.

Quoted 117 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +5 -0
+{
+	return format == CHNL_IMG_CTRL_FORMAT_RAW10 ||
+	       format == CHNL_IMG_CTRL_FORMAT_RAW12;
+}
+
 #endif /* __IMX8_ISI_REGS_H__ */
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +11 -19
index af91bd65b2c1..978a637f539d 100644
@@ -218,15 +218,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.depth		= { 32 },
 		.encoding	= MXC_ISI_ENC_RGB,
 	},
-	/*
-	 * RAW formats
-	 *
-	 * The ISI shifts the 10-bit and 12-bit formats left by 6 and 4 bits
-	 * when using CHNL_IMG_CTRL_FORMAT_RAW10 or MXC_ISI_OUT_FMT_RAW12
-	 * respectively, to align the bits to the left and pad with zeros in
-	 * the LSBs. The corresponding V4L2 formats are however right-aligned,
-	 * we have to use CHNL_IMG_CTRL_FORMAT_RAW16 to avoid the left shift.
-	 */
+	/* RAW formats */
 	{
 		.mbus_code	= MEDIA_BUS_FMT_Y8_1X8,
 		.fourcc		= V4L2_PIX_FMT_GREY,
@@ -240,7 +232,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y10_1X10,
 		.fourcc		= V4L2_PIX_FMT_Y10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -249,7 +241,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y12_1X12,
 		.fourcc		= V4L2_PIX_FMT_Y12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -312,7 +304,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SBGGR10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -321,7 +313,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SGBRG10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -330,7 +322,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SGRBG10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -339,7 +331,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB10_1X10,
 		.fourcc		= V4L2_PIX_FMT_SRGGB10,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW10,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -348,7 +340,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SBGGR12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -357,7 +349,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SGBRG12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -366,7 +358,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SGRBG12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -375,7 +367,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB12_1X12,
 		.fourcc		= V4L2_PIX_FMT_SRGGB12,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW12,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
Signature · 3 lines
Regards,

Laurent Pinchart
#8 lore raw

PATCH v5 6/11 media: imx8-isi: Add RAW14 output format support

In reply to Guoniu Zhou

From i.MX8ULP onwards, the ISI added RAW14 output format. Add its register definition and use it for all 14-bit RAW formats in the format table instead of RAW16.

Include RAW14 in isi_out_raw_shifted() so the RAW16 workaround covers it on platforms that lack LSB-aligned RAW output.

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h  |  5 ++++-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 10 +++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +4 -1
index 0f3ada30e71e..5f66b7c9cd1c 100644
@@ -89,6 +89,8 @@
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P10P			0x3a
 #define CHNL_IMG_CTRL_FORMAT_YUV420_2P12			0x3d
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P12			0x3e
+#define CHNL_IMG_CTRL_FORMAT_RAW14				0x41	/* i.MX{8ULP,91,93,95} */
+
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL(n)				((n) << 16)
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL_MASK			GENMASK(23, 16)
 #define CHNL_IMG_CTRL_GBL_ALPHA_EN				BIT(15)
@@ -431,7 +433,8 @@
 static inline bool isi_out_raw_shifted(u32 format)
 {
 	return format == CHNL_IMG_CTRL_FORMAT_RAW10 ||
-	       format == CHNL_IMG_CTRL_FORMAT_RAW12;
+	       format == CHNL_IMG_CTRL_FORMAT_RAW12 ||
+	       format == CHNL_IMG_CTRL_FORMAT_RAW14;
 }
 
 #endif /* __IMX8_ISI_REGS_H__ */
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +5 -5
index 978a637f539d..ca8fe8782af8 100644
@@ -250,7 +250,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y14_1X14,
 		.fourcc		= V4L2_PIX_FMT_Y14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -376,7 +376,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SBGGR14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -385,7 +385,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SGBRG14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -394,7 +394,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SGRBG14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -403,7 +403,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SRGGB14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
Signature · 1 line
2.34.1
maintainer
#9 lore raw

Re: [PATCH v5 06/11] media: imx8-isi: Add RAW14 output format support

Hi Zhou,

Quoted 22 lines · Guoniu Zhou

From i.MX8ULP onwards, the ISI added RAW14 output format. Add its register definition and use it for all 14-bit RAW formats in the format table instead of RAW16.

Include RAW14 in isi_out_raw_shifted() so the RAW16 workaround covers it on platforms that lack LSB-aligned RAW output.

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h  |  5 ++++-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c | 10 +++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +0 -0
index 0f3ada30e71e..5f66b7c9cd1c 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h line 92

Quoted 4 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -0
@@ -89,6 +89,8 @@
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P10P			0x3a
 #define CHNL_IMG_CTRL_FORMAT_YUV420_2P12			0x3d
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P12			0x3e
+#define CHNL_IMG_CTRL_FORMAT_RAW14				0x41	/* i.MX{8ULP,91,93,95} */

This patch can be squashed with 05/11, adding this macro doesn't call for making it a separate patch.

Quoted 63 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +3 -1
+
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL(n)				((n) << 16)
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL_MASK			GENMASK(23, 16)
 #define CHNL_IMG_CTRL_GBL_ALPHA_EN				BIT(15)
@@ -431,7 +433,8 @@
 static inline bool isi_out_raw_shifted(u32 format)
 {
 	return format == CHNL_IMG_CTRL_FORMAT_RAW10 ||
-	       format == CHNL_IMG_CTRL_FORMAT_RAW12;
+	       format == CHNL_IMG_CTRL_FORMAT_RAW12 ||
+	       format == CHNL_IMG_CTRL_FORMAT_RAW14;
 }
 
 #endif /* __IMX8_ISI_REGS_H__ */
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +5 -5
index 978a637f539d..ca8fe8782af8 100644
@@ -250,7 +250,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_Y14_1X14,
 		.fourcc		= V4L2_PIX_FMT_Y14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -376,7 +376,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SBGGR14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SBGGR14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -385,7 +385,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGBRG14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SGBRG14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -394,7 +394,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SGRBG14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SGRBG14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
@@ -403,7 +403,7 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 		.mbus_code	= MEDIA_BUS_FMT_SRGGB14_1X14,
 		.fourcc		= V4L2_PIX_FMT_SRGGB14,
 		.type		= MXC_ISI_VIDEO_CAP,
-		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW16,
+		.isi_out_format	= CHNL_IMG_CTRL_FORMAT_RAW14,
 		.mem_planes	= 1,
 		.color_planes	= 1,
 		.depth		= { 16 },
Signature · 3 lines
Regards,

Laurent Pinchart
#10 lore raw

PATCH v5 7/11 media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95

In reply to Guoniu Zhou

The ISI receives RAW data from the Pixel Link, whose alignment is determined by the SoC integration. Before i.MX93, the Pixel Link provides LSB-aligned RAW data to the ISI. Starting with i.MX93, both LSB and MSB alignment are supported and can be selected via CHNL_CTRL_RAW_IN_MSB_ALIGN, with the default keeping LSB alignment for backward compatibility. From i.MX95 onwards, the CSI formatter replaces the gasket and only provides MSB-aligned RAW data.

Set CHNL_CTRL_RAW_IN_MSB_ALIGN on i.MX95 so the ISI selects RAW samples from the high bits of the Pixel Link bus.

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c   | 20 ++++++++++++++++++++
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h |  1 +
 2 files changed, 21 insertions(+)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +20 -0
index cc52a90c2477..b3f32b9796d5 100644
@@ -303,6 +303,22 @@ static void mxc_isi_channel_set_panic_threshold(struct mxc_isi_pipe *pipe)
 	mxc_isi_write(pipe, CHNL_OUT_BUF_CTRL, val);
 }
 
+/*
+ * The ISI receives RAW data from the Pixel Link, whose alignment is
+ * determined by the SoC integration. It originally selected RAW samples
+ * from the low bits of the Pixel Link bus. Starting with i.MX93,
+ * CHNL_CTRL_RAW_IN_MSB_ALIGN was introduced to allow the ISI to select
+ * RAW samples from either the high or low bits, as both LSB and MSB
+ * alignment can be selected in the gasket.
+ *
+ * On i.MX95, the CSI formatter provides MSB-aligned RAW data, so the ISI
+ * must select RAW samples from the high bits of the Pixel Link bus.
+ */
+static bool isi_raw_in_msb(const struct mxc_isi_plat_data *pdata)
+{
+	return pdata->model == MXC_ISI_IMX95;
+}
+
 static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 					enum mxc_isi_input_id input,
 					unsigned int vc,
@@ -357,6 +373,10 @@ static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 			val |= CHNL_CTRL_VC_ID_1(vc >> 2);
 	}
 
+	/* Select MSB-aligned RAW data from the Pixel Link when needed. */
+	if (isi_raw_in_msb(pipe->isi->pdata))
+		val |= CHNL_CTRL_RAW_IN_MSB_ALIGN;
+
 	mxc_isi_write(pipe, CHNL_CTRL, val);
 
 	mutex_unlock(&pipe->lock);
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -0
index 5f66b7c9cd1c..35438abf3172 100644
@@ -20,6 +20,7 @@
 #define CHNL_CTRL_CHAIN_BUF_NO_CHAIN				0
 #define CHNL_CTRL_CHAIN_BUF_2_CHAIN				1
 #define CHNL_CTRL_SW_RST					BIT(24)
+#define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
  * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX95 only
Signature · 1 line
2.34.1
Reviewed-by on v5 7/11
#11 lore raw

Re: [PATCH v5 07/11] media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95

Quoted 8 lines · Guoniu Zhou

The ISI receives RAW data from the Pixel Link, whose alignment is determined by the SoC integration. Before i.MX93, the Pixel Link provides LSB-aligned RAW data to the ISI. Starting with i.MX93, both LSB and MSB alignment are supported and can be selected via CHNL_CTRL_RAW_IN_MSB_ALIGN, with the default keeping LSB alignment for backward compatibility. From i.MX95 onwards, the CSI formatter replaces the gasket and only provides MSB-aligned RAW data.

Quoted 5 lines

Set CHNL_CTRL_RAW_IN_MSB_ALIGN on i.MX95 so the ISI selects RAW samples from the high bits of the Pixel Link bus.

---

Quoted 62 lines

Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c   | 20 ++++++++++++++++++++
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h |  1 +
 2 files changed, 21 insertions(+)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +20 -0
index cc52a90c2477..b3f32b9796d5 100644
@@ -303,6 +303,22 @@ static void mxc_isi_channel_set_panic_threshold(struct mxc_isi_pipe *pipe)
 	mxc_isi_write(pipe, CHNL_OUT_BUF_CTRL, val);
 }
 
+/*
+ * The ISI receives RAW data from the Pixel Link, whose alignment is
+ * determined by the SoC integration. It originally selected RAW samples
+ * from the low bits of the Pixel Link bus. Starting with i.MX93,
+ * CHNL_CTRL_RAW_IN_MSB_ALIGN was introduced to allow the ISI to select
+ * RAW samples from either the high or low bits, as both LSB and MSB
+ * alignment can be selected in the gasket.
+ *
+ * On i.MX95, the CSI formatter provides MSB-aligned RAW data, so the ISI
+ * must select RAW samples from the high bits of the Pixel Link bus.
+ */
+static bool isi_raw_in_msb(const struct mxc_isi_plat_data *pdata)
+{
+	return pdata->model == MXC_ISI_IMX95;
+}
+
 static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 					enum mxc_isi_input_id input,
 					unsigned int vc,
@@ -357,6 +373,10 @@ static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 			val |= CHNL_CTRL_VC_ID_1(vc >> 2);
 	}
 
+	/* Select MSB-aligned RAW data from the Pixel Link when needed. */
+	if (isi_raw_in_msb(pipe->isi->pdata))
+		val |= CHNL_CTRL_RAW_IN_MSB_ALIGN;
+
 	mxc_isi_write(pipe, CHNL_CTRL, val);
 
 	mutex_unlock(&pipe->lock);
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -1
index 5f66b7c9cd1c..35438abf3172 100644
@@ -20,6 +20,7 @@
 #define CHNL_CTRL_CHAIN_BUF_NO_CHAIN				0
 #define CHNL_CTRL_CHAIN_BUF_2_CHAIN				1
 #define CHNL_CTRL_SW_RST					BIT(24)
+#define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
  * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX95 only
 
--

2.34.1

maintainer
#12 lore raw

Re: [PATCH v5 07/11] media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95

In reply to Guoniu Zhou
Quoted 8 lines · Guoniu Zhou

The ISI receives RAW data from the Pixel Link, whose alignment is determined by the SoC integration. Before i.MX93, the Pixel Link provides LSB-aligned RAW data to the ISI. Starting with i.MX93, both LSB and MSB alignment are supported and can be selected via CHNL_CTRL_RAW_IN_MSB_ALIGN, with the default keeping LSB alignment for backward compatibility. From i.MX95 onwards, the CSI formatter replaces the gasket and only provides MSB-aligned RAW data.

Quoted 4 lines

Set CHNL_CTRL_RAW_IN_MSB_ALIGN on i.MX95 so the ISI selects RAW samples from the high bits of the Pixel Link bus.

I think this patch should go after 08/11.

Quoted 16 lines

---
Changes in v4:
- New patch

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c   | 20 ++++++++++++++++++++
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h |  1 +
 2 files changed, 21 insertions(+)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +0 -0
index cc52a90c2477..b3f32b9796d5 100644
@@ -303,6 +303,22 @@ static void mxc_isi_channel_set_panic_threshold(struct mxc_isi_pipe *pipe)
 	mxc_isi_write(pipe, CHNL_OUT_BUF_CTRL, val);
 }
 

drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c static void mxc_isi_channel_set_panic_threshold(struct mxc_isi_pipe *pipe) · line 315

Quoted 10 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +10 -0
+/*
+ * The ISI receives RAW data from the Pixel Link, whose alignment is
+ * determined by the SoC integration. It originally selected RAW samples
+ * from the low bits of the Pixel Link bus. Starting with i.MX93,
+ * CHNL_CTRL_RAW_IN_MSB_ALIGN was introduced to allow the ISI to select
+ * RAW samples from either the high or low bits, as both LSB and MSB
+ * alignment can be selected in the gasket.
+ *
+ * On i.MX95, the CSI formatter provides MSB-aligned RAW data, so the ISI
+ * must select RAW samples from the high bits of the Pixel Link bus.

This comment is too verbose. It copies most of the information from the commit messages while that's not useful for the reader here. See below for a shortened message.

Quoted 10 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +6 -0
+ */
+static bool isi_raw_in_msb(const struct mxc_isi_plat_data *pdata)
+{
+	return pdata->model == MXC_ISI_IMX95;
+}
+
 static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 					enum mxc_isi_input_id input,
 					unsigned int vc,

drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe, · line 378

Quoted 6 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +3 -0
@@ -357,6 +373,10 @@ static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 			val |= CHNL_CTRL_VC_ID_1(vc >> 2);
 	}
 
+	/* Select MSB-aligned RAW data from the Pixel Link when needed. */
+	if (isi_raw_in_msb(pipe->isi->pdata))
+		val |= CHNL_CTRL_RAW_IN_MSB_ALIGN;

The helper function is used here only, you can just inline it.

	/*
	 * Starting on i.MX95, the ISI gasket is replaced by a Pixel Formatter
	 * that unconditionally aligns data to the MSB. Configure the ISI to
	 * select MSB-aligned data.
	 */
	if (isi->pdata->model == MXC_ISI_IMX95)
		val |= CHNL_CTRL_RAW_IN_MSB_ALIGN;
Quoted 16 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +1 -0
+
 	mxc_isi_write(pipe, CHNL_CTRL, val);
 
 	mutex_unlock(&pipe->lock);
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -0
index 5f66b7c9cd1c..35438abf3172 100644
@@ -20,6 +20,7 @@
 #define CHNL_CTRL_CHAIN_BUF_NO_CHAIN				0
 #define CHNL_CTRL_CHAIN_BUF_2_CHAIN				1
 #define CHNL_CTRL_SW_RST					BIT(24)
+#define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
  * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX95 only
Signature · 3 lines
Regards,

Laurent Pinchart
#13 lore raw

PATCH v5 8/11 media: imx8-isi: Exclude RAW10/12/14 output formats on i.MX95

In reply to Guoniu Zhou

On i.MX95, the CSI formatter provides MSB-aligned RAW data to the ISI via the Pixel Link. The RAW16 passthrough that older platforms use to produce LSB-aligned output now passes through MSB-aligned data instead, so it no longer produces correct V4L2-compatible output. Exclude RAW10/12/14 from format enumeration on i.MX95.

---
Changes in v4:
- New patch

---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.h    |  6 ++--
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |  2 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    | 10 +++---
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 38 ++++++++++++++++++----
 4 files changed, 42 insertions(+), 14 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +4 -2
index a30633a7e2e9..ba0d6df98fd4 100644
@@ -320,9 +320,11 @@ mxc_isi_bus_format_by_code(u32 code, unsigned int pad);
 const struct mxc_isi_bus_format_info *
 mxc_isi_bus_format_by_index(unsigned int index, unsigned int pad);
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type);
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,
+			 enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
 mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix,
 		   enum mxc_isi_video_type type);
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +1 -1
index 1178947bb548..1ad0fd1af3b1 100644
@@ -492,7 +492,7 @@ static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh,
 		MXC_ISI_VIDEO_M2M_OUT : MXC_ISI_VIDEO_M2M_CAP;
 	const struct mxc_isi_format_info *info;
 
-	info = mxc_isi_format_enum(f, type);
+	info = mxc_isi_format_enum(NULL, f, type);
 	if (!info)
 		return -EINVAL;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +5 -5
index 35438abf3172..b83a25a58ebe 100644
@@ -425,11 +425,11 @@
 #define CHNL_IN_BUF_XTND_ADDR					0x00b8
 
 /*
- * The ISI shifts the 10-bit and 12-bit RAW formats left by 6 and 4 bits when
- * using CHNL_IMG_CTRL_FORMAT_RAW10 or CHNL_IMG_CTRL_FORMAT_RAW12 respectively,
- * to align the bits to the left and pad with zeros in the LSBs. The
- * corresponding V4L2 formats are however right-aligned, so
- * CHNL_IMG_CTRL_FORMAT_RAW16 must be used to avoid the left shift.
+ * The ISI shifts the 10/12/14-bit RAW formats left to MSB-align the output.
+ * On platforms where the Pixel Link provides LSB-aligned data, the RAW16
+ * passthrough must be used instead to preserve LSB alignment. On platforms
+ * where the Pixel Link provides MSB-aligned data (i.MX95), these formats
+ * cannot produce correct V4L2-compatible output and must be excluded.
  */
 static inline bool isi_out_raw_shifted(u32 format)
 {
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +32 -6
index ca8fe8782af8..708aa4c775c7 100644
@@ -458,14 +458,32 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 	}
 };
 
+/*
+ * On i.MX95, the Pixel Link provides MSB-aligned RAW data, so neither the
+ * RAW16 passthrough nor the native RAW10/12/14 output formats can produce
+ * correct V4L2-compatible LSB-aligned output. Exclude these formats.
+ */
+static bool
+mxc_isi_format_is_raw_unsupported(const struct mxc_isi_plat_data *pdata,
+				  const struct mxc_isi_format_info *fmt)
+{
+	return pdata && pdata->model == MXC_ISI_IMX95 &&
+	       isi_out_raw_shifted(fmt->isi_out_format);
+}
+
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,
+			 enum mxc_isi_video_type type)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (fmt->fourcc == fourcc && fmt->type & type)
 			return fmt;
 	}
@@ -474,7 +492,8 @@ mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
 }
 
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 {
 	unsigned int index = f->index;
 	unsigned int i;
@@ -482,6 +501,10 @@ mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (f->mbus_code && fmt->mbus_code != f->mbus_code)
 			continue;
 
@@ -509,7 +532,7 @@ mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix
 		  ? MXC_ISI_MAX_WIDTH_UNCHAINED
 		  : MXC_ISI_MAX_WIDTH_CHAINED;
 
-	fmt = mxc_isi_format_by_fourcc(pix->pixelformat, type);
+	fmt = mxc_isi_format_by_fourcc(pipe->isi->pdata, pix->pixelformat, type);
 	if (!fmt)
 		fmt = &mxc_isi_formats[0];
 
@@ -803,7 +826,8 @@ static int mxc_isi_video_validate_format(struct mxc_isi_video *video)
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
 
-	info = mxc_isi_format_by_fourcc(video->pix.pixelformat,
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					video->pix.pixelformat,
 					MXC_ISI_VIDEO_CAP);
 	format = v4l2_subdev_state_get_format(state, MXC_ISI_PIPE_PAD_SOURCE);
 
@@ -1222,9 +1246,10 @@ static int mxc_isi_video_querycap(struct file *file, void *priv,
 static int mxc_isi_video_enum_fmt(struct file *file, void *priv,
 				  struct v4l2_fmtdesc *f)
 {
+	struct mxc_isi_video *video = video_drvdata(file);
 	const struct mxc_isi_format_info *fmt;
 
-	fmt = mxc_isi_format_enum(f, MXC_ISI_VIDEO_CAP);
+	fmt = mxc_isi_format_enum(video->pipe->isi->pdata, f, MXC_ISI_VIDEO_CAP);
 	if (!fmt)
 		return -EINVAL;
 
@@ -1281,7 +1306,8 @@ static int mxc_isi_video_enum_framesizes(struct file *file, void *priv,
 	if (fsize->index)
 		return -EINVAL;
 
-	info = mxc_isi_format_by_fourcc(fsize->pixel_format, MXC_ISI_VIDEO_CAP);
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					fsize->pixel_format, MXC_ISI_VIDEO_CAP);
 	if (!info)
 		return -EINVAL;
 
Signature · 1 line
2.34.1
Reviewed-by on v5 8/11
#14 lore raw

Re: [PATCH v5 08/11] media: imx8-isi: Exclude RAW10/12/14 output formats on i.MX95

Quoted 8 lines · Guoniu Zhou

On i.MX95, the CSI formatter provides MSB-aligned RAW data to the ISI via the Pixel Link. The RAW16 passthrough that older platforms use to produce LSB-aligned output now passes through MSB-aligned data instead, so it no longer produces correct V4L2-compatible output. Exclude RAW10/12/14 from format enumeration on i.MX95.

---

Quoted 166 lines

Changes in v4:
- New patch

---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.h    |  6 ++--
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |  2 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    | 10 +++---
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 38 ++++++++++++++++++----
 4 files changed, 42 insertions(+), 14 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +4 -2
index a30633a7e2e9..ba0d6df98fd4 100644
@@ -320,9 +320,11 @@ mxc_isi_bus_format_by_code(u32 code, unsigned int pad);
 const struct mxc_isi_bus_format_info *
 mxc_isi_bus_format_by_index(unsigned int index, unsigned int pad);
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type);
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,
+			 enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
 mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix,
 		   enum mxc_isi_video_type type);
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +1 -1
index 1178947bb548..1ad0fd1af3b1 100644
@@ -492,7 +492,7 @@ static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh,
 		MXC_ISI_VIDEO_M2M_OUT : MXC_ISI_VIDEO_M2M_CAP;
 	const struct mxc_isi_format_info *info;
 
-	info = mxc_isi_format_enum(f, type);
+	info = mxc_isi_format_enum(NULL, f, type);
 	if (!info)
 		return -EINVAL;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +5 -5
index 35438abf3172..b83a25a58ebe 100644
@@ -425,11 +425,11 @@
 #define CHNL_IN_BUF_XTND_ADDR					0x00b8
 
 /*
- * The ISI shifts the 10-bit and 12-bit RAW formats left by 6 and 4 bits when
- * using CHNL_IMG_CTRL_FORMAT_RAW10 or CHNL_IMG_CTRL_FORMAT_RAW12 respectively,
- * to align the bits to the left and pad with zeros in the LSBs. The
- * corresponding V4L2 formats are however right-aligned, so
- * CHNL_IMG_CTRL_FORMAT_RAW16 must be used to avoid the left shift.
+ * The ISI shifts the 10/12/14-bit RAW formats left to MSB-align the output.
+ * On platforms where the Pixel Link provides LSB-aligned data, the RAW16
+ * passthrough must be used instead to preserve LSB alignment. On platforms
+ * where the Pixel Link provides MSB-aligned data (i.MX95), these formats
+ * cannot produce correct V4L2-compatible output and must be excluded.
  */
 static inline bool isi_out_raw_shifted(u32 format)
 {
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +32 -7
index ca8fe8782af8..708aa4c775c7 100644
@@ -458,14 +458,32 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 	}
 };
 
+/*
+ * On i.MX95, the Pixel Link provides MSB-aligned RAW data, so neither the
+ * RAW16 passthrough nor the native RAW10/12/14 output formats can produce
+ * correct V4L2-compatible LSB-aligned output. Exclude these formats.
+ */
+static bool
+mxc_isi_format_is_raw_unsupported(const struct mxc_isi_plat_data *pdata,
+				  const struct mxc_isi_format_info *fmt)
+{
+	return pdata && pdata->model == MXC_ISI_IMX95 &&
+	       isi_out_raw_shifted(fmt->isi_out_format);
+}
+
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,
+			 enum mxc_isi_video_type type)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (fmt->fourcc == fourcc && fmt->type & type)
 			return fmt;
 	}
@@ -474,7 +492,8 @@ mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
 }
 
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 {
 	unsigned int index = f->index;
 	unsigned int i;
@@ -482,6 +501,10 @@ mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (f->mbus_code && fmt->mbus_code != f->mbus_code)
 			continue;
 
@@ -509,7 +532,7 @@ mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix
 		  ? MXC_ISI_MAX_WIDTH_UNCHAINED
 		  : MXC_ISI_MAX_WIDTH_CHAINED;
 
-	fmt = mxc_isi_format_by_fourcc(pix->pixelformat, type);
+	fmt = mxc_isi_format_by_fourcc(pipe->isi->pdata, pix->pixelformat, type);
 	if (!fmt)
 		fmt = &mxc_isi_formats[0];
 
@@ -803,7 +826,8 @@ static int mxc_isi_video_validate_format(struct mxc_isi_video *video)
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
 
-	info = mxc_isi_format_by_fourcc(video->pix.pixelformat,
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					video->pix.pixelformat,
 					MXC_ISI_VIDEO_CAP);
 	format = v4l2_subdev_state_get_format(state, MXC_ISI_PIPE_PAD_SOURCE);
 
@@ -1222,9 +1246,10 @@ static int mxc_isi_video_querycap(struct file *file, void *priv,
 static int mxc_isi_video_enum_fmt(struct file *file, void *priv,
 				  struct v4l2_fmtdesc *f)
 {
+	struct mxc_isi_video *video = video_drvdata(file);
 	const struct mxc_isi_format_info *fmt;
 
-	fmt = mxc_isi_format_enum(f, MXC_ISI_VIDEO_CAP);
+	fmt = mxc_isi_format_enum(video->pipe->isi->pdata, f, MXC_ISI_VIDEO_CAP);
 	if (!fmt)
 		return -EINVAL;
 
@@ -1281,7 +1306,8 @@ static int mxc_isi_video_enum_framesizes(struct file *file, void *priv,
 	if (fsize->index)
 		return -EINVAL;
 
-	info = mxc_isi_format_by_fourcc(fsize->pixel_format, MXC_ISI_VIDEO_CAP);
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					fsize->pixel_format, MXC_ISI_VIDEO_CAP);
 	if (!info)
 		return -EINVAL;
 
 
--

2.34.1

maintainer
#15 lore raw

Re: [PATCH v5 08/11] media: imx8-isi: Exclude RAW10/12/14 output formats on i.MX95

In reply to Guoniu Zhou
Quoted 5 lines · Guoniu Zhou

On i.MX95, the CSI formatter provides MSB-aligned RAW data to the ISI via the Pixel Link. The RAW16 passthrough that older platforms use to produce LSB-aligned output now passes through MSB-aligned data instead, so it no longer produces correct V4L2-compatible output. Exclude RAW10/12/14 from format enumeration on i.MX95.

The important part is that the hardware is not able to shift the data right, unlike on the i.MX952. Please explain clearly here that producing the V4L2 RAW 10/12/14 formats is not possible.

Quoted 16 lines

---
Changes in v4:
- New patch

---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.h    |  6 ++--
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |  2 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    | 10 +++---
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 38 ++++++++++++++++++----
 4 files changed, 42 insertions(+), 14 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +0 -0
index a30633a7e2e9..ba0d6df98fd4 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h mxc_isi_bus_format_by_code(u32 code, unsigned int pad); · line 323

Quoted 5 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -1
@@ -320,9 +320,11 @@ mxc_isi_bus_format_by_code(u32 code, unsigned int pad);
 const struct mxc_isi_bus_format_info *
 mxc_isi_bus_format_by_index(unsigned int index, unsigned int pad);
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type);
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,

Let's pass the mxc_isi_pipe pointer to this function, to match mxc_isi_format_try().

drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h mxc_isi_bus_format_by_code(u32 code, unsigned int pad); · line 326

Quoted 4 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +2 -1
+			 enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,

Same here.

Quoted 9 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -0
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type);
 const struct mxc_isi_format_info *
 mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix,
 		   enum mxc_isi_video_type type);
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +0 -0
index 1178947bb548..1ad0fd1af3b1 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh, · line 495

Quoted 5 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +1 -1
@@ -492,7 +492,7 @@ static int mxc_isi_m2m_enum_fmt_vid(struct file *file, void *fh,
 		MXC_ISI_VIDEO_M2M_OUT : MXC_ISI_VIDEO_M2M_CAP;
 	const struct mxc_isi_format_info *info;
 
-	info = mxc_isi_format_enum(f, type);
+	info = mxc_isi_format_enum(NULL, f, type);

I'd rather not allow passing NULL to mxc_isi_format_enum() (and down to mxc_isi_format_is_raw_unsupported()), as that's fragile. You can access the pipe pointer here from struct file.

If the goal is to not disallow raw formats in M2M mode on i.MX95, using NULL as a magic value is even worse. The code should be explicit.

Quoted 30 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c +0 -0
 	if (!info)
 		return -EINVAL;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +5 -5
index 35438abf3172..b83a25a58ebe 100644
@@ -425,11 +425,11 @@
 #define CHNL_IN_BUF_XTND_ADDR					0x00b8
 
 /*
- * The ISI shifts the 10-bit and 12-bit RAW formats left by 6 and 4 bits when
- * using CHNL_IMG_CTRL_FORMAT_RAW10 or CHNL_IMG_CTRL_FORMAT_RAW12 respectively,
- * to align the bits to the left and pad with zeros in the LSBs. The
- * corresponding V4L2 formats are however right-aligned, so
- * CHNL_IMG_CTRL_FORMAT_RAW16 must be used to avoid the left shift.
+ * The ISI shifts the 10/12/14-bit RAW formats left to MSB-align the output.
+ * On platforms where the Pixel Link provides LSB-aligned data, the RAW16
+ * passthrough must be used instead to preserve LSB alignment. On platforms
+ * where the Pixel Link provides MSB-aligned data (i.MX95), these formats
+ * cannot produce correct V4L2-compatible output and must be excluded.
  */
 static inline bool isi_out_raw_shifted(u32 format)
 {
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +0 -0
index ca8fe8782af8..708aa4c775c7 100644
@@ -458,14 +458,32 @@ static const struct mxc_isi_format_info mxc_isi_formats[] = {
 	}

drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c static const struct mxc_isi_format_info mxc_isi_formats[] = { · line 468

Quoted 10 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +8 -0
 };
 
+/*
+ * On i.MX95, the Pixel Link provides MSB-aligned RAW data, so neither the
+ * RAW16 passthrough nor the native RAW10/12/14 output formats can produce
+ * correct V4L2-compatible LSB-aligned output. Exclude these formats.
+ */
+static bool
+mxc_isi_format_is_raw_unsupported(const struct mxc_isi_plat_data *pdata,
+				  const struct mxc_isi_format_info *fmt)

As explained in the review of a previous patch, the function naming makes the code harder to understand.

Quoted 84 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-video.c +24 -6
+{
+	return pdata && pdata->model == MXC_ISI_IMX95 &&
+	       isi_out_raw_shifted(fmt->isi_out_format);
+}
+
 const struct mxc_isi_format_info *
-mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
+mxc_isi_format_by_fourcc(const struct mxc_isi_plat_data *pdata, u32 fourcc,
+			 enum mxc_isi_video_type type)
 {
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (fmt->fourcc == fourcc && fmt->type & type)
 			return fmt;
 	}
@@ -474,7 +492,8 @@ mxc_isi_format_by_fourcc(u32 fourcc, enum mxc_isi_video_type type)
 }
 
 const struct mxc_isi_format_info *
-mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
+mxc_isi_format_enum(const struct mxc_isi_plat_data *pdata,
+		    const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 {
 	unsigned int index = f->index;
 	unsigned int i;
@@ -482,6 +501,10 @@ mxc_isi_format_enum(const struct v4l2_fmtdesc *f, enum mxc_isi_video_type type)
 	for (i = 0; i < ARRAY_SIZE(mxc_isi_formats); i++) {
 		const struct mxc_isi_format_info *fmt = &mxc_isi_formats[i];
 
+		/* Skip formats unsupported by the platform. */
+		if (mxc_isi_format_is_raw_unsupported(pdata, fmt))
+			continue;
+
 		if (f->mbus_code && fmt->mbus_code != f->mbus_code)
 			continue;
 
@@ -509,7 +532,7 @@ mxc_isi_format_try(struct mxc_isi_pipe *pipe, struct v4l2_pix_format_mplane *pix
 		  ? MXC_ISI_MAX_WIDTH_UNCHAINED
 		  : MXC_ISI_MAX_WIDTH_CHAINED;
 
-	fmt = mxc_isi_format_by_fourcc(pix->pixelformat, type);
+	fmt = mxc_isi_format_by_fourcc(pipe->isi->pdata, pix->pixelformat, type);
 	if (!fmt)
 		fmt = &mxc_isi_formats[0];
 
@@ -803,7 +826,8 @@ static int mxc_isi_video_validate_format(struct mxc_isi_video *video)
 
 	state = v4l2_subdev_lock_and_get_active_state(sd);
 
-	info = mxc_isi_format_by_fourcc(video->pix.pixelformat,
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					video->pix.pixelformat,
 					MXC_ISI_VIDEO_CAP);
 	format = v4l2_subdev_state_get_format(state, MXC_ISI_PIPE_PAD_SOURCE);
 
@@ -1222,9 +1246,10 @@ static int mxc_isi_video_querycap(struct file *file, void *priv,
 static int mxc_isi_video_enum_fmt(struct file *file, void *priv,
 				  struct v4l2_fmtdesc *f)
 {
+	struct mxc_isi_video *video = video_drvdata(file);
 	const struct mxc_isi_format_info *fmt;
 
-	fmt = mxc_isi_format_enum(f, MXC_ISI_VIDEO_CAP);
+	fmt = mxc_isi_format_enum(video->pipe->isi->pdata, f, MXC_ISI_VIDEO_CAP);
 	if (!fmt)
 		return -EINVAL;
 
@@ -1281,7 +1306,8 @@ static int mxc_isi_video_enum_framesizes(struct file *file, void *priv,
 	if (fsize->index)
 		return -EINVAL;
 
-	info = mxc_isi_format_by_fourcc(fsize->pixel_format, MXC_ISI_VIDEO_CAP);
+	info = mxc_isi_format_by_fourcc(video->pipe->isi->pdata,
+					fsize->pixel_format, MXC_ISI_VIDEO_CAP);
 	if (!info)
 		return -EINVAL;
 
Signature · 3 lines
Regards,

Laurent Pinchart
#16 lore raw

PATCH v5 9/11 media: dt-bindings: nxp,imx8-isi: Add i.MX952 ISI compatible string

In reply to Guoniu Zhou

The i.MX952 ISI is a minor silicon revision of the i.MX95 ISI, primarily addressing RAW data alignment. The core functionality remains identical, so the i.MX952 ISI uses a fallback compatible string to fsl,imx95-isi.

---
Changes in v3:
- Add Reviewed-by/Acked-by tag from Frank, Laurent and Dooley

Changes in v2:
- Use fallback compatible fsl,imx95-isi for imx952 (Frank, Conor Dooley)

---
 .../devicetree/bindings/media/nxp,imx8-isi.yaml        | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/media/nxp,imx8-isi.yaml +11 -7
index 279c9cd3034a..d0a99f00a45e 100644
@@ -18,13 +18,17 @@ description: |
 
 properties:
   compatible:
-    enum:
-      - fsl,imx8mn-isi
-      - fsl,imx8mp-isi
-      - fsl,imx8ulp-isi
-      - fsl,imx91-isi
-      - fsl,imx93-isi
-      - fsl,imx95-isi
+    oneOf:
+      - enum:
+          - fsl,imx8mn-isi
+          - fsl,imx8mp-isi
+          - fsl,imx8ulp-isi
+          - fsl,imx91-isi
+          - fsl,imx93-isi
+          - fsl,imx95-isi
+      - items:
+          - const: fsl,imx952-isi
+          - const: fsl,imx95-isi
 
   reg:
     maxItems: 1
Signature · 1 line
2.34.1
#17 lore raw

PATCH v5 10/11 media: imx8-isi: Add i.MX952 ISI support

In reply to Guoniu Zhou

The i.MX952 ISI is reused from the i.MX95 ISI with a minor silicon revision. It can process up to 8 image sources simultaneously and obtain image data from up to 4 pixel link sources.

---
Changes in v3:
- Extend mask globally instead of per-platform (Laurent)
- Add Reviewed-by tag from Frank

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 13 +++++++++++++
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h |  1 +
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +13 -0
index f2a8eb82fbfd..bedf8515b1e7 100644
@@ -384,6 +384,18 @@ static const struct mxc_isi_plat_data mxc_imx95_data = {
 	.has_36bit_dma		= true,
 };
 
+static const struct mxc_isi_plat_data mxc_imx952_data = {
+	.model			= MXC_ISI_IMX952,
+	.num_ports		= 4,
+	.num_channels		= 8,
+	.num_vc			= 8,
+	.reg_offset		= 0x10000,
+	.ier_reg		= &mxc_imx8_isi_ier_v2,
+	.set_thd		= &mxc_imx8_isi_thd_v1,
+	.buf_active_reverse	= true,
+	.has_36bit_dma		= true,
+};
+
 /* -----------------------------------------------------------------------------
  * Power management
  */
@@ -574,6 +586,7 @@ static const struct of_device_id mxc_isi_of_match[] = {
 	{ .compatible = "fsl,imx91-isi", .data = &mxc_imx91_data },
 	{ .compatible = "fsl,imx93-isi", .data = &mxc_imx93_data },
 	{ .compatible = "fsl,imx95-isi", .data = &mxc_imx95_data },
+	{ .compatible = "fsl,imx952-isi", .data = &mxc_imx952_data },
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, mxc_isi_of_match);
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -0
index ba0d6df98fd4..64e6961a4ea4 100644
@@ -164,6 +164,7 @@ enum model {
 	MXC_ISI_IMX91,
 	MXC_ISI_IMX93,
 	MXC_ISI_IMX95,
+	MXC_ISI_IMX952,
 };
 
 struct mxc_isi_plat_data {
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -1
index b83a25a58ebe..d2b8a26b7c21 100644
@@ -23,7 +23,7 @@
 #define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
- * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX95 only
+ * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX{95,952} only
  */
 #define CHNL_CTRL_BLANK_PXL(n)					FIELD_PREP(GENMASK(23, 16), (n))
 #define CHNL_CTRL_VC_ID_1(n)					FIELD_PREP(BIT(16), (n))
Signature · 1 line
2.34.1
maintainer Reviewed-by on v5 10/11
#18 lore raw
Quoted 64 lines · Guoniu Zhou

The i.MX952 ISI is reused from the i.MX95 ISI with a minor silicon revision. It can process up to 8 image sources simultaneously and obtain image data from up to 4 pixel link sources.

---
Changes in v3:
- Extend mask globally instead of per-platform (Laurent)
- Add Reviewed-by tag from Frank

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c | 13 +++++++++++++
 drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h |  1 +
 drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.c +13 -0
index f2a8eb82fbfd..bedf8515b1e7 100644
@@ -384,6 +384,18 @@ static const struct mxc_isi_plat_data mxc_imx95_data = {
 	.has_36bit_dma		= true,
 };
 
+static const struct mxc_isi_plat_data mxc_imx952_data = {
+	.model			= MXC_ISI_IMX952,
+	.num_ports		= 4,
+	.num_channels		= 8,
+	.num_vc			= 8,
+	.reg_offset		= 0x10000,
+	.ier_reg		= &mxc_imx8_isi_ier_v2,
+	.set_thd		= &mxc_imx8_isi_thd_v1,
+	.buf_active_reverse	= true,
+	.has_36bit_dma		= true,
+};
+
 /* -----------------------------------------------------------------------------
  * Power management
  */
@@ -574,6 +586,7 @@ static const struct of_device_id mxc_isi_of_match[] = {
 	{ .compatible = "fsl,imx91-isi", .data = &mxc_imx91_data },
 	{ .compatible = "fsl,imx93-isi", .data = &mxc_imx93_data },
 	{ .compatible = "fsl,imx95-isi", .data = &mxc_imx95_data },
+	{ .compatible = "fsl,imx952-isi", .data = &mxc_imx952_data },
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, mxc_isi_of_match);
drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h +1 -0
index ba0d6df98fd4..64e6961a4ea4 100644
@@ -164,6 +164,7 @@ enum model {
 	MXC_ISI_IMX91,
 	MXC_ISI_IMX93,
 	MXC_ISI_IMX95,
+	MXC_ISI_IMX952,
 };
 
 struct mxc_isi_plat_data {
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +0 -0
index b83a25a58ebe..d2b8a26b7c21 100644

drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h line 26

Quoted 5 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +1 -1
@@ -23,7 +23,7 @@
 #define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
- * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX95 only
+ * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX{95,952} only

You should also update the comments for CHNL_CTRL_RAW_IN_MSB_ALIGN and CHNL_IMG_CTRL_FORMAT_RAW14. With that,

Quoted 3 lines
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +0 -0
  */
 #define CHNL_CTRL_BLANK_PXL(n)					FIELD_PREP(GENMASK(23, 16), (n))
 #define CHNL_CTRL_VC_ID_1(n)					FIELD_PREP(BIT(16), (n))
Signature · 3 lines
Regards,

Laurent Pinchart
#19 lore raw

PATCH v5 11/11 media: imx8-isi: Enable RAW10/12/14 output LSB alignment on i.MX952

In reply to Guoniu Zhou

Before i.MX952, the ISI RAW10/12/14 output formats are always MSB-aligned, which is not compatible with the V4L2 RAW format definition that requires LSB alignment.

From i.MX952 onwards, the ISI introduces CHNL_CTRL_RAW_OUT_LSB_ALIGN to select whether RAW10/12/14 outputs are MSB or LSB aligned. Enable it so the driver produces correct V4L2-compatible LSB-aligned output.

---
Changes in v4:
- Split RAW_IN_MSB_ALIGN into a separate preceding patch
- Split RAW format table and RAW14 changes into separate preceding patches
- Move isi_out_raw_shifted() to regs.h in the preceding workaround patch
- Rewrite commit message

Changes in v3:
- Use CHNL_IMG_CTRL_FORMAT_MASK instead of the removed per-platform format_mask (Laurent)
- Derive raw_out_lsb from the model field instead of dedicated platform data (Laurent)
- Clarify the CHNL_IMG_CTRL_FORMAT_RAW14 comment: the format is
documented on i.MX{8ULP,91,93,95,952} but only used on i.MX952
- Update the mxc_isi_channel_set_output_format() comment wording
- Rewrite commit message
- Add Reviewed-by tag from Frank

---
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c  | 37 +++++++++++++++++++---
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    |  5 +--
 2 files changed, 36 insertions(+), 6 deletions(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c +33 -4
index b3f32b9796d5..6733776e72aa 100644
@@ -311,12 +311,24 @@ static void mxc_isi_channel_set_panic_threshold(struct mxc_isi_pipe *pipe)
  * RAW samples from either the high or low bits, as both LSB and MSB
  * alignment can be selected in the gasket.
  *
- * On i.MX95, the CSI formatter provides MSB-aligned RAW data, so the ISI
- * must select RAW samples from the high bits of the Pixel Link bus.
+ * Starting with i.MX95, the CSI formatter provides MSB-aligned RAW data,
+ * so the ISI must select RAW samples from the high bits of the Pixel Link
+ * bus.
  */
 static bool isi_raw_in_msb(const struct mxc_isi_plat_data *pdata)
 {
-	return pdata->model == MXC_ISI_IMX95;
+	return pdata->model == MXC_ISI_IMX95 ||
+	       pdata->model == MXC_ISI_IMX952;
+}
+
+/*
+ * Starting with i.MX952, the ISI can output RAW10/12/14 formats with LSB
+ * alignment, matching the V4L2 requirement. Older platforms lack this
+ * capability and need the RAW16 workaround.
+ */
+static bool isi_raw_out_lsb(const struct mxc_isi_plat_data *pdata)
+{
+	return pdata->model == MXC_ISI_IMX952;
 }
 
 static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
@@ -377,6 +389,13 @@ static void mxc_isi_channel_set_control(struct mxc_isi_pipe *pipe,
 	if (isi_raw_in_msb(pipe->isi->pdata))
 		val |= CHNL_CTRL_RAW_IN_MSB_ALIGN;
 
+	/*
+	 * Enable RAW10/12/14 output LSB alignment to match the
+	 * V4L2 requirement that RAW formats are LSB-aligned.
+	 */
+	if (isi_raw_out_lsb(pipe->isi->pdata))
+		val |= CHNL_CTRL_RAW_OUT_LSB_ALIGN;
+
 	mxc_isi_write(pipe, CHNL_CTRL, val);
 
 	mutex_unlock(&pipe->lock);
@@ -430,13 +449,23 @@ void mxc_isi_channel_set_output_format(struct mxc_isi_pipe *pipe,
 				       const struct mxc_isi_format_info *info,
 				       struct v4l2_pix_format_mplane *format)
 {
+	const struct mxc_isi_plat_data *pdata = pipe->isi->pdata;
 	u32 val;
 	u32 fmt;
 
 	/* set outbuf format */
 	dev_dbg(pipe->isi->dev, "output format %p4cc", &format->pixelformat);
 
-	fmt = isi_out_raw_shifted(info->isi_out_format)
+	/*
+	 * Before i.MX952, the ISI shifts the 10/12/14-bit formats left
+	 * by 6, 4 and 2 bits when using CHNL_IMG_CTRL_FORMAT_RAW10/12/14
+	 * respectively, to align the bits to the left and pad with zeros in
+	 * the LSBs. The corresponding V4L2 formats are however right-aligned,
+	 * we have to use CHNL_IMG_CTRL_FORMAT_RAW16 to avoid the left shift.
+	 * Starting with i.MX952, the ISI supports RAW10/12/14 LSB output
+	 * alignment, so skip the above workaround.
+	 */
+	fmt = !isi_raw_out_lsb(pdata) && isi_out_raw_shifted(info->isi_out_format)
 	    ? CHNL_IMG_CTRL_FORMAT_RAW16
 	    : info->isi_out_format;
 
drivers/media/platform/nxp/imx8-isi/imx8-isi-regs.h +3 -2
index d2b8a26b7c21..075fc6848213 100644
@@ -20,7 +20,8 @@
 #define CHNL_CTRL_CHAIN_BUF_NO_CHAIN				0
 #define CHNL_CTRL_CHAIN_BUF_2_CHAIN				1
 #define CHNL_CTRL_SW_RST					BIT(24)
-#define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95} */
+#define CHNL_CTRL_RAW_OUT_LSB_ALIGN				BIT(23)	/* i.MX952 only */
+#define CHNL_CTRL_RAW_IN_MSB_ALIGN				BIT(22)	/* i.MX{91,93,95,952} */
 /*
  * CHNL_CTRL_BLANK_PXL: i.MX8{QM,QXP} only
  * CHNL_CTRL_VC_ID_1, CHNL_CTRL_VC_ID_1_MASK: i.MX{95,952} only
@@ -90,7 +91,7 @@
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P10P			0x3a
 #define CHNL_IMG_CTRL_FORMAT_YUV420_2P12			0x3d
 #define CHNL_IMG_CTRL_FORMAT_YUV420_3P12			0x3e
-#define CHNL_IMG_CTRL_FORMAT_RAW14				0x41	/* i.MX{8ULP,91,93,95} */
+#define CHNL_IMG_CTRL_FORMAT_RAW14				0x41	/* i.MX{8ULP,91,93,95,952}, used on i.MX952 only */
 
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL(n)				((n) << 16)
 #define CHNL_IMG_CTRL_GBL_ALPHA_VAL_MASK			GENMASK(23, 16)
Signature · 1 line
2.34.1
maintainer
#20 lore raw
In reply to Guoniu Zhou
Quoted 9 lines · Guoniu Zhou

The series adds support for the i.MX952 Image Sensing Interface (ISI), which is a minor silicon revision of the i.MX95 ISI.

The i.MX952 ISI reuses the i.MX95 ISI core with the same 8-channel pipeline and 4 pixel link inputs. The key hardware improvement is the addition of RAW10/12/14 output LSB alignment, which allows the ISI to output right-aligned RAW data directly, matching the V4L2 format requirement without the RAW16 workaround needed on earlier platforms.

Quoted 8 lines

The series is organized as follows:

1. Reorder mxc_imx95_data definition to follow mxc_imx93_data, matching the order in the of_match array.
2. Extend output format mask to 7 bits unconditionally since bit 30 is unused on older platforms.
3. Support mbus_code filtering in mxc_isi_format_enum().
4. Reuse mxc_isi_format_enum() in capture format enumeration.

I have sent a pull request for v7.5 with patches 1 to 4.

Quoted 102 lines

5. Apply RAW output format workaround at runtime, storing the actual hardware format in the format table.
6. Add RAW14 output format support (available from i.MX8ULP).
7. Select MSB-aligned RAW input from pixel link on i.MX95.
8. Exclude RAW10/12/14 output formats on i.MX95.
9. Add the i.MX952 compatible string to the DT binding.
10. Add the i.MX952 platform data and of_match entry.
11. Enable RAW10/12/14 output LSB alignment on i.MX952.

Review status
==============

Most review comments received on previous revisions have been addressed and several patches have already collected Reviewed-by/Acked-by tags.

The only remaining open topic in this series is the RAW alignment handling discussed at:

https://lore.kernel.org/all/ar028ZyZg56Mk60M@lizhi-Precision-Tower-5810/
https://lore.kernel.org/all/ar00qevdwDHYAEy9@SMW015318/

The discussion affects the final patch:

media: imx8-isi: Enable RAW10/12/14 output LSB alignment on i.MX952
media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95

I would especially appreciate Laurent Pinchart's feedback on the proposed approach, as this is the last unresolved topic before the series is ready for merging.

---
Changes in v5:
- Rebase to latest media/next(7969a6f407cf)
- [3/11] Clarify that this preparatory patch introduces no functional change (Laurent)
- Collect Reviewed-by tags
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Rebase to latest media/next(2dcdfb625c3b)
- Split the original patch 5/5 into multiple focused patches:
patches 3-8 are new, each addressing a specific aspect
- [3/11] New: Support mbus_code filtering in mxc_isi_format_enum()
- [4/11] New: Reuse mxc_isi_format_enum() in capture format enumeration
- [5/11] New: Apply RAW output format workaround at runtime
- [6/11] New: Add RAW14 output format support
- [7/11] New: Select MSB-aligned RAW input from pixel link on i.MX95
- [8/11] New: Exclude RAW10/12/14 output formats on i.MX95
- [11/11] Split RAW_IN_MSB_ALIGN into a separate preceding patch
- [11/11] Split RAW format table and RAW14 changes into separate preceding patches
- [11/11] Move isi_out_raw_shifted() to regs.h in the preceding workaround patch
- [11/11] Rewrite commit message
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- [1/5] Add Reviewed-by tag from Laurent
- [2/5] Use unconditional 7-bit mask instead of per-platform approach (Laurent)
- [2/5] Drop Reviewed-by from Frank Li due to significant change and request to review again
- [3/5] Add Reviewed-by/Acked-by tag from Frank, Laurent and Dooley
- [4/5] Extend mask globally instead of per-platform (Laurent)
- [4/5] Add Reviewed-by tag from Frank
- [5/5] Use CHNL_IMG_CTRL_FORMAT_MASK instead of the removed per-platform format_mask (Laurent)
- [5/5] Derive raw_out_lsb from the model field instead of dedicated platform data (Laurent)
- [5/5] Clarify the CHNL_IMG_CTRL_FORMAT_RAW14 comment: the format is documented on i.MX{8ULP,91,93,95,952} but only used on i.MX952
- [5/5] Rewrite commit message to explain why the RAW16 workaround fails on i.MX95+ (Laurent)
- [5/5] Add Reviewed-by tag from Frank
- Drop "Remove unused model field" patch; model field is now used to derive raw_out_lsb capability (Laurent)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Use fallback compatible fsl,imx95-isi for imx952 (Frank)
- Remove unused model field from platform data (Frank)
- Add Reviewed-by tag from Frank Li for patch 1/6 and 2/6
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Guoniu Zhou (11):
media: imx8-isi: Reorder mxc_imx95_data to follow mxc_imx93_data
media: imx8-isi: Extend output format mask to 7 bits
media: imx8-isi: Support mbus_code filtering in format enumeration
media: imx8-isi: Reuse mxc_isi_format_enum() in capture format enumeration
media: imx8-isi: Apply RAW output format workaround at runtime
media: imx8-isi: Add RAW14 output format support
media: imx8-isi: Select MSB-aligned RAW input from pixel link on i.MX95
media: imx8-isi: Exclude RAW10/12/14 output formats on i.MX95
media: dt-bindings: nxp,imx8-isi: Add i.MX952 ISI compatible string
media: imx8-isi: Add i.MX952 ISI support
media: imx8-isi: Enable RAW10/12/14 output LSB alignment on i.MX952

 .../devicetree/bindings/media/nxp,imx8-isi.yaml    |  18 ++--
 .../media/platform/nxp/imx8-isi/imx8-isi-core.c    |  37 ++++---
 .../media/platform/nxp/imx8-isi/imx8-isi-core.h    |   7 +-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c  |  56 ++++++++++-
 drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c |   2 +-
 .../media/platform/nxp/imx8-isi/imx8-isi-regs.h    |  22 ++++-
 .../media/platform/nxp/imx8-isi/imx8-isi-video.c   | 110 ++++++++++-----------
 7 files changed, 171 insertions(+), 81 deletions(-)

---
base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
change-id: 20260817-isi_imx952-66ca65f9b638

Signature · 3 lines
Regards,

Laurent Pinchart