[PATCH v2 2/4] media: rcar-isp: ispcore: Update image data flush settings
From: Niklas Söderlund
Date: Sat Nov 14 2026 - 14:56:16 EST
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@xxxxxxxxxxxx>
---
* 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