linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride
@ 2026-11-14 19:55 Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Niklas Söderlund @ 2026-11-14 19:55 UTC (permalink / raw)
  To: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi
  Cc: linux-media, linux-kernel, linux-renesas-soc,
	Niklas Söderlund

Hello,

The main part of this series aims to add NV12M output format support and 
there is a small drive-by fix to honor the image stride from input 
images in patch 1/4.

Patch 2/4 address a confusion around how much data was needed to flush 
out all pixels to the output buffer. Later versions of the datasheet 
makes it use clear and how it relates to image strides. This is needed 
for NV12M support as we need to tightly control it to generate valid 
NV12M frames.

Patch 3/4 is a quality of life fix where the current driver looks at the 
pixelformat to figure out how many planes are used. As it only supports 
RGB (1 plane) and NV16M (2 plane) this worked, but before adding NV12M 
(2 plane) look at the correct field so we don't have to maintain a list 
of pixelformats that have two planes ourself.

Finally patch 4/4 adds NV12M support. Enabling support for it is 
straightforward but one snag around how the DMA-engine works.

When the DMA-engine is configured to only output CbCr data from odd or
even lines it still outputs blanks pixels to the buffer for the line
where no data is taken.

To work around this and still produce valid NV12 frames the device needs
to be configured so all blank pixels written to the buffer are part of
the line padding. In addition to also keeping the same number of padding
bytes as the Y plane.

The DMA-engine is able to do this as we can set different strides for
the two planes and haw two DMA-engine lines (one with data + some
padding and one with only padding) make up a single correctly formatted
NV12 CbCr line.

For readers comparing the DMA configuration with the datasheet this
driver takes the CbCr data from even lines, compared to odd lines in the
datasheet example. The reason for this is that if odd lines are used the
first even line adds half a NV12 line of padding at the start of the
CbCr plane. To counter this the CbCr plane would need a padding line at
the start of the plane which is not supported, or we would need to set
the plane start address half a line before the buffer actually starts
and potentially corrupt memory as we write blank bytes outside our
buffer.

Tested on V4H SparrowHawk without any regressions and the output frames 
looks good.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
Changes in v2:
- See each patch.
- Link to v1: https://patch.msgid.link/20261019-v4l2-add-nv12-v1-0-4a84736803b6@ragnatech.se

---
Niklas Söderlund (3):
      media: rcar-isp: ispcore: Update image data flush settings
      media: rcar-isp: ispcore: Look at number of planes when programming
      media: rcar-isp: ispcore: Add NV12M support

Yuya Hamamachi (1):
      media: rcar-isp: ispcore: Honour requested bytesperline on RAW input

 drivers/media/platform/renesas/rcar-isp/core-io.c | 82 +++++++++++++++++++++--
 drivers/media/platform/renesas/rcar-isp/core.c    | 45 ++++++++++++-
 2 files changed, 117 insertions(+), 10 deletions(-)
---
base-commit: bf6c63ecc20a54aaac7a2fcbd6adaf6498388825
change-id: 20261015-v4l2-add-nv12-9358df2bf649

Best regards,
--  
Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>


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

* [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input
  2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
@ 2026-11-14 19:55 ` Niklas Söderlund
  2026-11-16 11:21   ` Jacopo Mondi
  2026-11-14 19:55 ` [PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings Niklas Söderlund
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Niklas Söderlund @ 2026-11-14 19:55 UTC (permalink / raw)
  To: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi
  Cc: linux-media, linux-kernel, linux-renesas-soc,
	Niklas Söderlund

From: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>

The RAW input video device always overwrote the bytesperline requested
by userspace with width * bpp. The input buffers are however shared with
the VIN, which may use a larger line stride (for example 3296 instead of
3280 bytes for a 1640 pixel wide 10 bit image). The dmabuf exported by
the ISP was then smaller than the VIN buffer size, and queueing it to
the VIN failed with -EINVAL:

  __prepare_dmabuf: invalid dmabuf length 4042752 for plane 0,
  minimum length 4060672

Use the requested bytesperline if it is larger than the minimum.

Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
[Niklas: Use clamp(..) instead of if statements]
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
* Changes since v1
- Use clamp() instead of max(min()).
- Upper limit at SZ_64K - 1, not SZ_64K.
---
 drivers/media/platform/renesas/rcar-isp/core-io.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
index b60b91f43d42..cc538e984aa1 100644
--- a/drivers/media/platform/renesas/rcar-isp/core-io.c
+++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
@@ -5,6 +5,8 @@
  * Copyright (C) 2026 Ragnatech AB
  */
 
+#include <linux/sizes.h>
+
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
@@ -335,6 +337,7 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
 				     struct v4l2_pix_format_mplane *pix)
 {
 	unsigned int bpp = 0;
+	unsigned int bpl;
 
 	v4l_bound_align_image(&pix->width, RISP_MIN_WIDTH, RISP_MAX_WIDTH, RISP_SIZE_ALIGNMENT,
 			      &pix->height, RISP_MIN_HEIGHT, RISP_MAX_HEIGHT, RISP_SIZE_ALIGNMENT,
@@ -352,11 +355,17 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
 		bpp = risp_io_input_formats[0].bpp;
 	}
 
+	/*
+	 * Honour the line stride requested by userspace, the buffers are
+	 * shared with the VIN which may use a larger stride than the minimum.
+	 */
+	bpl = clamp(pix->plane_fmt[0].bytesperline, pix->width * bpp, SZ_64K - 1);
+
 	pix->field = V4L2_FIELD_NONE;
 	pix->colorspace = V4L2_COLORSPACE_RAW;
 
 	pix->num_planes = 1;
-	pix->plane_fmt[0].bytesperline = pix->width * bpp;
+	pix->plane_fmt[0].bytesperline = bpl;
 	pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
 }
 

-- 
2.55.0


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

* [PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings
  2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
@ 2026-11-14 19:55 ` Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 3/4] media: rcar-isp: ispcore: Look at number of planes when programming Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 4/4] media: rcar-isp: ispcore: Add NV12M support Niklas Söderlund
  3 siblings, 0 replies; 6+ messages in thread
From: Niklas Söderlund @ 2026-11-14 19:55 UTC (permalink / raw)
  To: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi
  Cc: linux-media, linux-kernel, linux-renesas-soc,
	Niklas Söderlund

Later versions of the datasheet have an updated chapter on how the image
out flush settings depends on proper stride settings. Update the bytes
per line calculation and flush out settings to match the datasheet
clarification.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
* Changes since v1
- Fix spelling of capture.
---
 drivers/media/platform/renesas/rcar-isp/core-io.c | 32 +++++++++++++++++++----
 drivers/media/platform/renesas/rcar-isp/core.c    |  2 +-
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
index cc538e984aa1..1c63194f6455 100644
--- a/drivers/media/platform/renesas/rcar-isp/core-io.c
+++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
@@ -727,12 +727,34 @@ static const struct v4l2_pix_format_mplane risp_io_capture_default_format = {
 	.num_planes = 1,
 	.plane_fmt = {
 		[0] = {
-			.bytesperline = ALIGN(1920 * 4, 256),
-			.sizeimage = ALIGN(1920 * 4, 256) * 1080,
+			.bytesperline = 15872, /* See risp_io_capture_bytesperline() */
+			.sizeimage = 15872 * 1080,
 		},
 	},
 };
 
+static unsigned int risp_io_capture_bytesperline(unsigned int width, unsigned int bpp)
+{
+	/*
+	 * The datasheet specifies strict alignment and padding rules to be able
+	 * to flush out all the pixels. Each line must be 256 byte aligned and
+	 * at the end of the frame at least one extra line of space must be
+	 * available.
+	 *
+	 * As we can't extend the buffer with one extra line we need to work
+	 * with stride setting to satisfy both constraints. Fortunately the
+	 * datasheet gives us a calculation for this.
+	 *
+	 *   FLUSH[pixels] = ALIGN(WIDTH[pixels], 256)
+	 *
+	 *   PADDING[bytes] = ALIGN(BPP[bytes] * WIDTH[pixels], 256) - BPP[bytes] * WIDTH[pixels] + BPP[bytes] * FLUSH[pixels]
+	 */
+	unsigned int data = bpp * width;
+	unsigned int padding = ALIGN(data, 256) - data + bpp * ALIGN(width, 256);
+
+	return ALIGN(data + padding, 256);
+}
+
 static void risp_io_capture_try_format(struct rcar_isp_core_io *io,
 				       struct v4l2_pix_format_mplane *pix)
 {
@@ -749,16 +771,16 @@ static void risp_io_capture_try_format(struct rcar_isp_core_io *io,
 	case V4L2_PIX_FMT_NV16M:
 		pix->quantization = V4L2_QUANTIZATION_LIM_RANGE;
 		pix->num_planes = 2;
-		pix->plane_fmt[0].bytesperline = ALIGN(pix->width, 256);
+		pix->plane_fmt[0].bytesperline = risp_io_capture_bytesperline(pix->width, 1);
 		pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
-		pix->plane_fmt[1].bytesperline = ALIGN(pix->width, 256);
+		pix->plane_fmt[1].bytesperline = pix->plane_fmt[0].bytesperline;
 		pix->plane_fmt[1].sizeimage = pix->plane_fmt[1].bytesperline * pix->height;
 		break;
 	default:
 		pix->pixelformat = V4L2_PIX_FMT_XBGR32;
 		pix->quantization = V4L2_QUANTIZATION_FULL_RANGE;
 		pix->num_planes = 1;
-		pix->plane_fmt[0].bytesperline = ALIGN(pix->width * 4, 256);
+		pix->plane_fmt[0].bytesperline = risp_io_capture_bytesperline(pix->width, 4);
 		pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
 		break;
 	}
diff --git a/drivers/media/platform/renesas/rcar-isp/core.c b/drivers/media/platform/renesas/rcar-isp/core.c
index 586a5adbedfa..8908496c734e 100644
--- a/drivers/media/platform/renesas/rcar-isp/core.c
+++ b/drivers/media/platform/renesas/rcar-isp/core.c
@@ -398,7 +398,7 @@ static int risp_core_config_output(struct rcar_isp_core *core,
 
 	/* Set image out flush EOF. */
 	risp_core_write(core, ISPCORE_DMA_IMAGE_FLUSH_OUT_REG(index),
-			pix->plane_fmt[0].bytesperline <<
+			ALIGN(pix->width, 256) <<
 			ISPCORE_DMA_IMAGE_FLUSH_OUT_PADDING_PIXEL_EOF_SHIFT);
 
 	/* Enable DMA and set burst length. */

-- 
2.55.0


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

* [PATCH v2 3/4] media: rcar-isp: ispcore: Look at number of planes when programming
  2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings Niklas Söderlund
@ 2026-11-14 19:55 ` Niklas Söderlund
  2026-11-14 19:55 ` [PATCH v2 4/4] media: rcar-isp: ispcore: Add NV12M support Niklas Söderlund
  3 siblings, 0 replies; 6+ messages in thread
From: Niklas Söderlund @ 2026-11-14 19:55 UTC (permalink / raw)
  To: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi
  Cc: linux-media, linux-kernel, linux-renesas-soc,
	Niklas Söderlund

Instead of expanding a list of formats that uses two planes look at the
format information directly.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Barnabás Pőcze <barnabas.pocze+renesas@ideasonboard.com>
---
* Changes since v1
- Use '< 2' instead of '!= 2' to be more future proof if we ever add 3
  planes support.
---
 drivers/media/platform/renesas/rcar-isp/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/renesas/rcar-isp/core.c b/drivers/media/platform/renesas/rcar-isp/core.c
index 8908496c734e..5cd21134a2d7 100644
--- a/drivers/media/platform/renesas/rcar-isp/core.c
+++ b/drivers/media/platform/renesas/rcar-isp/core.c
@@ -126,8 +126,7 @@ static void risp_core_job_run_output(struct rcar_isp_core *core,
 		mem = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
 		risp_core_write(core, reg, mem);
 
-		/* Only NV16 uses 2 planes. */
-		if (fmt->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_NV16M)
+		if (fmt->fmt.pix_mp.num_planes < 2)
 			continue;
 
 		reg = ISPCORE_DMA_IMAGE_FRAME_BASE_ADDRESS_COMP1(0, frame);

-- 
2.55.0


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

* [PATCH v2 4/4] media: rcar-isp: ispcore: Add NV12M support
  2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
                   ` (2 preceding siblings ...)
  2026-11-14 19:55 ` [PATCH v2 3/4] media: rcar-isp: ispcore: Look at number of planes when programming Niklas Söderlund
@ 2026-11-14 19:55 ` Niklas Söderlund
  3 siblings, 0 replies; 6+ messages in thread
From: Niklas Söderlund @ 2026-11-14 19:55 UTC (permalink / raw)
  To: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi
  Cc: linux-media, linux-kernel, linux-renesas-soc,
	Niklas Söderlund

It is possible to support NV12M output by only outputting the CbCr plane
from even or odd lines. Enabling support for it is straightforward but
one snag around how the DMA-engine works.

When the DMA-engine is configured to only output CbCr data from odd or
even lines it still outputs blanks pixels to the buffer for the line
where no data is taken.

To work around this and still produce valid NV12 frames the device needs
to be configured so all blank pixels written to the buffer are part of
the line padding. In addition to also keeping the same number of padding
bytes as the Y plane.

The DMA-engine is able to do this as we can set different strides for
the two planes and haw two DMA-engine lines (one with data + some
padding and one with only padding) make up a single correctly formatted
NV12 CbCr line.

For readers comparing the DMA configuration with the datasheet this
driver takes the CbCr data from even lines, compared to odd lines in the
datasheet example. The reason for this is that if odd lines are used the
first even line adds half a NV12 line of padding at the start of the
CbCr plane. To counter this the CbCr plane would need a padding line at
the start of the plane which is not supported, or we would need to set
the plane start address half a line before the buffer actually starts
and potentially corrupt memory as we write blank bytes outside our
buffer.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/renesas/rcar-isp/core-io.c | 39 +++++++++++++++++++++-
 drivers/media/platform/renesas/rcar-isp/core.c    | 40 +++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
index 1c63194f6455..d3b302c5b66e 100644
--- a/drivers/media/platform/renesas/rcar-isp/core-io.c
+++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
@@ -768,6 +768,39 @@ static void risp_io_capture_try_format(struct rcar_isp_core_io *io,
 	pix->xfer_func = V4L2_XFER_FUNC_SRGB;
 
 	switch (pix->pixelformat) {
+	case V4L2_PIX_FMT_NV12M:
+		pix->quantization = V4L2_QUANTIZATION_LIM_RANGE;
+		pix->num_planes = 2;
+		/*
+		 * The DMA-engine still outputs pixels for the height lines of
+		 * the CrCb plane. To produce a NV12 frame we must ensure all
+		 * these blank pixels are in the padding area of the frame.
+		 *
+		 * To do this the stride of the CrCb plane need to be half that
+		 * of the Y plane. The first "DMA-engine line" will write the
+		 * CrCb data + some blank padding, while the second "DMA-engine
+		 * line" will only write blank padding bytes. Two "DMA-engine
+		 * lines" will then create one correct NV12 line in the CrCb
+		 * plane.
+		 *
+		 * All frame data also needs to fits in the first half of the
+		 * line. The strict DMA flush settings used already ensures
+		 * this is always the case.
+		 *
+		 * Finally the NV12 stride of the Y and CrCb plane must be the
+		 * same and the R-Car ISP needs the hardware stride to be 256
+		 * byte aligned. By align the Y plane lines to 512 bytes the
+		 * CrCb planes hardware stride is always aligned with 256 when
+		 * cut in half.
+		 */
+		pix->plane_fmt[0].bytesperline =
+			ALIGN(risp_io_capture_bytesperline(pix->width, 1), 512);
+		pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
+		/* Both planes must have the same length. */
+		pix->plane_fmt[1].bytesperline = pix->plane_fmt[0].bytesperline;
+		/* The CrCb plane is half height of the Y plane. */
+		pix->plane_fmt[1].sizeimage = pix->plane_fmt[1].bytesperline * pix->height / 2;
+		break;
 	case V4L2_PIX_FMT_NV16M:
 		pix->quantization = V4L2_QUANTIZATION_LIM_RANGE;
 		pix->num_planes = 2;
@@ -794,9 +827,12 @@ static int risp_io_capture_enum_fmt(struct file *file, void *priv,
 
 	switch (f->index) {
 	case 0:
-		f->pixelformat = V4L2_PIX_FMT_NV16M;
+		f->pixelformat = V4L2_PIX_FMT_NV12M;
 		break;
 	case 1:
+		f->pixelformat = V4L2_PIX_FMT_NV16M;
+		break;
+	case 2:
 		f->pixelformat = V4L2_PIX_FMT_XBGR32;
 		break;
 	default:
@@ -854,6 +890,7 @@ static int risp_io_capture_enum_framesizes(struct file *file, void *fh,
 		return -EINVAL;
 
 	switch (fsize->pixel_format) {
+	case V4L2_PIX_FMT_NV12M:
 	case V4L2_PIX_FMT_NV16M:
 	case V4L2_PIX_FMT_XBGR32:
 		break;
diff --git a/drivers/media/platform/renesas/rcar-isp/core.c b/drivers/media/platform/renesas/rcar-isp/core.c
index 5cd21134a2d7..76be90e78420 100644
--- a/drivers/media/platform/renesas/rcar-isp/core.c
+++ b/drivers/media/platform/renesas/rcar-isp/core.c
@@ -341,6 +341,45 @@ static int risp_core_config_output(struct rcar_isp_core *core,
 	/* For all frame capture slots. */
 	for (unsigned int frame = 0; frame < 4; frame++) {
 		switch (pix->pixelformat) {
+		case V4L2_PIX_FMT_NV12M:
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_MODE(index, frame),
+					1);
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_PIXEL_POSITION(index, frame),
+					0 << 24 | 0 << 16 | 4 << 8 | 16 << 0);
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_PIXEL_BITWIDTH_MINUS1(index, frame),
+					0 << 24 | 0 << 16 | 7 << 8 | 7 << 0);
+			/*
+			 * Pick CrCb data from even lines.
+			 *
+			 * The datasheet suggest taking the odd lines but that
+			 * would require padding at the start of the buffer to
+			 * create valid NV12 frame, or start writing outside the
+			 * buffer potentially corrupting memory.
+			 */
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_PIXEL_BPP(index, frame),
+					0 << 28 | 0 << 24 |
+					0 << 20 | 0 << 16 |
+					1 << 12 | 0 << 8 |
+					3 << 4  | 0 << 0);
+
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_STRIDE_COMP0(index, frame),
+					pix->plane_fmt[0].bytesperline);
+			/*
+			 * Stride of CrCb plane needs be cut in half as the
+			 * DMA-engine writes blank pixels for the lines not
+			 * processed.
+			 *
+			 * See risp_io_capture_try_format() for details.
+			 */
+			risp_core_write(core,
+					ISPCORE_DMA_IMAGE_FRAME_STRIDE_COMP1(index, frame),
+					pix->plane_fmt[1].bytesperline / 2);
+			break;
 		case V4L2_PIX_FMT_NV16M:
 			risp_core_write(core,
 					ISPCORE_DMA_IMAGE_FRAME_MODE(index, frame),
@@ -436,6 +475,7 @@ static u32 risp_core_pix2bus(const struct rcar_isp_core_io *io)
 		return MEDIA_BUS_FMT_SRGGB12_1X12;
 	case V4L2_PIX_FMT_XBGR32:
 		return MEDIA_BUS_FMT_RGB888_1X24;
+	case V4L2_PIX_FMT_NV12M:
 	case V4L2_PIX_FMT_NV16M:
 		return MEDIA_BUS_FMT_YUYV12_1X24;
 	default:

-- 
2.55.0


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

* Re: [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input
  2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
@ 2026-11-16 11:21   ` Jacopo Mondi
  0 siblings, 0 replies; 6+ messages in thread
From: Jacopo Mondi @ 2026-11-16 11:21 UTC (permalink / raw)
  To: Niklas Söderlund, Laurent Pinchart
  Cc: Jacopo Mondi, Jai Luthra, Niklas Söderlund,
	Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
	Barnabás Pőcze, Yusuke Goda, Yuya Hamamachi,
	linux-media, linux-kernel, linux-renesas-soc

Hi Niklas,

On Sat, Nov 14, 2026 at 08:55:16PM +0100, Niklas Söderlund wrote:
> From: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
>
> The RAW input video device always overwrote the bytesperline requested
> by userspace with width * bpp. The input buffers are however shared with
> the VIN, which may use a larger line stride (for example 3296 instead of
> 3280 bytes for a 1640 pixel wide 10 bit image). The dmabuf exported by
> the ISP was then smaller than the VIN buffer size, and queueing it to
> the VIN failed with -EINVAL:
>
>   __prepare_dmabuf: invalid dmabuf length 4042752 for plane 0,
>   minimum length 4060672
>
> Use the requested bytesperline if it is larger than the minimum.
>

This is worth a fixes imo

> Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
> [Niklas: Use clamp(..) instead of if statements]
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> * Changes since v1
> - Use clamp() instead of max(min()).
> - Upper limit at SZ_64K - 1, not SZ_64K.
> ---
>  drivers/media/platform/renesas/rcar-isp/core-io.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
> index b60b91f43d42..cc538e984aa1 100644
> --- a/drivers/media/platform/renesas/rcar-isp/core-io.c
> +++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
> @@ -5,6 +5,8 @@
>   * Copyright (C) 2026 Ragnatech AB
>   */
>
> +#include <linux/sizes.h>
> +
>  #include <media/v4l2-ctrls.h>
>  #include <media/v4l2-event.h>
>  #include <media/v4l2-ioctl.h>
> @@ -335,6 +337,7 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
>  				     struct v4l2_pix_format_mplane *pix)
>  {
>  	unsigned int bpp = 0;
> +	unsigned int bpl;
>
>  	v4l_bound_align_image(&pix->width, RISP_MIN_WIDTH, RISP_MAX_WIDTH, RISP_SIZE_ALIGNMENT,
>  			      &pix->height, RISP_MIN_HEIGHT, RISP_MAX_HEIGHT, RISP_SIZE_ALIGNMENT,
> @@ -352,11 +355,17 @@ static void risp_io_input_try_format(struct rcar_isp_core_io *io,
>  		bpp = risp_io_input_formats[0].bpp;
>  	}
>
> +	/*
> +	 * Honour the line stride requested by userspace, the buffers are
> +	 * shared with the VIN which may use a larger stride than the minimum.
> +	 */
> +	bpl = clamp(pix->plane_fmt[0].bytesperline, pix->width * bpp, SZ_64K - 1);
> +

There is a (quite long) anlysis of this bug in our forge:
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14

and while the commit message of this patch correctly identify the issue
it doesn't take into account any requirement (stride alignment and max
stride length) of the VSP-X unit which actually does the transfer on
behalf of the ISP.

We didn't get to the bottom of VSP-X stride alignment constraints, but
the RPF unit documentation specifies a max size for the source picture
stride (which is the SZ_64K - 1 value that is used by this patch).
https://git.ideasonboard.com/renesas-v4h-isp/libcamera/issues/14#issuecomment-40317

Laurent suggested to get the VSP-X stride alignment and max size by
adding a function (possibily a try format) in the ISP/VSP-X interface.

I'm more of the opinion that as the ISP-core, VSP-X and VIN are part
of the same SoC it is not too crazy to use (SZ_64K - 1) here directly
(maybe adding a comment on where the limits comes from).

What do you think ?


>  	pix->field = V4L2_FIELD_NONE;
>  	pix->colorspace = V4L2_COLORSPACE_RAW;
>
>  	pix->num_planes = 1;
> -	pix->plane_fmt[0].bytesperline = pix->width * bpp;
> +	pix->plane_fmt[0].bytesperline = bpl;
>  	pix->plane_fmt[0].sizeimage = pix->plane_fmt[0].bytesperline * pix->height;
>  }
>
>
> --
> 2.55.0
>
>

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

end of thread, other threads:[~2026-11-16 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 19:55 [PATCH v2 0/4] media: rcar-isp: Add NV12M support and fix stride Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 1/4] media: rcar-isp: ispcore: Honour requested bytesperline on RAW input Niklas Söderlund
2026-11-16 11:21   ` Jacopo Mondi
2026-11-14 19:55 ` [PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 3/4] media: rcar-isp: ispcore: Look at number of planes when programming Niklas Söderlund
2026-11-14 19:55 ` [PATCH v2 4/4] media: rcar-isp: ispcore: Add NV12M support Niklas Söderlund

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