mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] media: rockchip: rkcif: ENUM_FMT and bytesperline fixes
@ 2026-11-05 23:23 Faizel K B
  2026-11-05 23:23 ` [PATCH 1/2] media: rockchip: rkcif: Filter enumerated formats by media bus code Faizel K B
  2026-11-05 23:23 ` [PATCH 2/2] media: rockchip: rkcif: Honour the requested bytesperline on MIPI Faizel K B
  0 siblings, 2 replies; 3+ messages in thread
From: Faizel K B @ 2026-11-05 23:23 UTC (permalink / raw)
  To: Mehdi Djait, Michael Riesch
  Cc: Mauro Carvalho Chehab, Heiko Stuebner, linux-media,
	linux-rockchip, linux-arm-kernel, linux-kernel, libcamera-devel,
	Robert Mader, Faizel K B

This series fixes two issues in the rkcif MIPI capture path, found while
using the libcamera simple pipeline handler with a Sony IMX415 on a
Radxa ROCK 5B+ (RK3588).

Patch 1 makes VIDIOC_ENUM_FMT honour the mbus_code field, as required
for V4L2_CAP_IO_MC devices. Without it, userspace can select a pixel
format that doesn't match the media bus format, e.g. a different Bayer
order, and the captured images have wrong colours.

Patch 2 aligns bytesperline to 8 bytes, as required by the MIPI DMA,
and honours a larger value requested by userspace. This allows the
capture buffers to be imported as DMA-BUFs by the libcamera GPU
software ISP on Panfrost, which needs a 64-byte stride alignment,
instead of copying every frame.

Tested on ROCK 5B+ with IMX415 (SGBRG10, 3864x2192): correct colours
without any userspace workaround, and a stride of 7936 bytes accepted
and used for zero-copy import. The corresponding libcamera change is
under review at:
https://patchwork.libcamera.org/patch/28662/

Faizel K B (2):
  media: rockchip: rkcif: Filter enumerated formats by media bus code
  media: rockchip: rkcif: Honour the requested bytesperline on MIPI

 .../platform/rockchip/rkcif/rkcif-stream.c    | 37 ++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)


base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
-- 
2.43.0


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

* [PATCH 1/2] media: rockchip: rkcif: Filter enumerated formats by media bus code
  2026-11-05 23:23 [PATCH 0/2] media: rockchip: rkcif: ENUM_FMT and bytesperline fixes Faizel K B
@ 2026-11-05 23:23 ` Faizel K B
  2026-11-05 23:23 ` [PATCH 2/2] media: rockchip: rkcif: Honour the requested bytesperline on MIPI Faizel K B
  1 sibling, 0 replies; 3+ messages in thread
From: Faizel K B @ 2026-11-05 23:23 UTC (permalink / raw)
  To: Mehdi Djait, Michael Riesch
  Cc: Mauro Carvalho Chehab, Heiko Stuebner, linux-media,
	linux-rockchip, linux-arm-kernel, linux-kernel, libcamera-devel,
	Robert Mader, Faizel K B

VIDIOC_ENUM_FMT ignores the mbus_code field and returns all formats,
although the video devices set V4L2_CAP_IO_MC. Return only the formats
that match the requested media bus code.

Otherwise userspace can pick a pixel format that doesn't match the
media bus format, and then interprets the captured data in the wrong
format.

Signed-off-by: Faizel K B <faizel.kb@gmail.com>
---
 .../media/platform/rockchip/rkcif/rkcif-stream.c  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
index 3130d420ad55..f2a24832a8cf 100644
--- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
+++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
@@ -395,13 +395,20 @@ static int rkcif_stream_enum_formats(struct file *file, void *priv,
 				     struct v4l2_fmtdesc *f)
 {
 	struct rkcif_stream *stream = video_drvdata(file);
+	unsigned int i, n = 0;
 
-	if (f->index >= stream->out_fmts_num)
-		return -EINVAL;
+	for (i = 0; i < stream->out_fmts_num; i++) {
+		if (f->mbus_code &&
+		    stream->out_fmts[i].mbus_code != f->mbus_code)
+			continue;
 
-	f->pixelformat = stream->out_fmts[f->index].fourcc;
+		if (n++ == f->index) {
+			f->pixelformat = stream->out_fmts[i].fourcc;
+			return 0;
+		}
+	}
 
-	return 0;
+	return -EINVAL;
 }
 
 static int rkcif_stream_enum_framesizes(struct file *file, void *fh,
-- 
2.43.0


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

* [PATCH 2/2] media: rockchip: rkcif: Honour the requested bytesperline on MIPI
  2026-11-05 23:23 [PATCH 0/2] media: rockchip: rkcif: ENUM_FMT and bytesperline fixes Faizel K B
  2026-11-05 23:23 ` [PATCH 1/2] media: rockchip: rkcif: Filter enumerated formats by media bus code Faizel K B
@ 2026-11-05 23:23 ` Faizel K B
  1 sibling, 0 replies; 3+ messages in thread
From: Faizel K B @ 2026-11-05 23:23 UTC (permalink / raw)
  To: Mehdi Djait, Michael Riesch
  Cc: Mauro Carvalho Chehab, Heiko Stuebner, linux-media,
	linux-rockchip, linux-arm-kernel, linux-kernel, libcamera-devel,
	Robert Mader, Faizel K B

The MIPI DMA uses bytesperline as the line stride, which must be a
multiple of 8 bytes, but v4l2_fill_pixfmt_mp() doesn't align it.
Any larger bytesperline requested by userspace is also replaced with
the minimum.

Align bytesperline to 8 bytes and honour a larger requested value, up
to the limit of the line width register. This allows DMA-BUF importers
that need a larger stride alignment to use the buffers directly.

Signed-off-by: Faizel K B <faizel.kb@gmail.com>
---
 .../platform/rockchip/rkcif/rkcif-stream.c    | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
index f2a24832a8cf..e50f20e40f7a 100644
--- a/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
+++ b/drivers/media/platform/rockchip/rkcif/rkcif-stream.c
@@ -23,6 +23,7 @@
 #define CIF_MIN_HEIGHT	 64
 #define CIF_MAX_WIDTH	 8192
 #define CIF_MAX_HEIGHT	 8192
+#define CIF_MAX_BYTESPERLINE 0xffff8 /* VLW: 20 bits, 8-byte aligned */
 
 static inline struct rkcif_buffer *to_rkcif_buffer(struct vb2_v4l2_buffer *vb)
 {
@@ -334,20 +335,39 @@ static const struct vb2_ops rkcif_stream_vb2_ops = {
 	.stop_streaming = rkcif_stream_stop_streaming,
 };
 
+static void rkcif_stream_set_bytesperline(struct v4l2_pix_format_mplane *pix,
+					  u32 req_bpl)
+{
+	u32 min_bpl = ALIGN(pix->plane_fmt[0].bytesperline, 8);
+	u32 max_bpl = min_t(u32, CIF_MAX_BYTESPERLINE,
+			    ALIGN_DOWN(U32_MAX / pix->height, 8));
+	u32 bpl = min_bpl;
+
+	if (req_bpl > min_bpl && req_bpl <= max_bpl)
+		bpl = ALIGN(req_bpl, 8);
+
+	pix->plane_fmt[0].bytesperline = bpl;
+	pix->plane_fmt[0].sizeimage = bpl * pix->height;
+}
+
 static int rkcif_stream_fill_format(struct rkcif_stream *stream,
 				    struct v4l2_pix_format_mplane *pix)
 {
 	const struct rkcif_output_fmt *fmt;
-	u32 height, width;
+	u32 height, width, req_bpl;
 	int ret;
 
 	fmt = rkcif_stream_find_output_fmt(stream, true, pix->pixelformat);
 	height = clamp_t(u32, pix->height, CIF_MIN_HEIGHT, CIF_MAX_HEIGHT);
 	width = clamp_t(u32, pix->width, CIF_MIN_WIDTH, CIF_MAX_WIDTH);
+	req_bpl = pix->plane_fmt[0].bytesperline;
 	ret = v4l2_fill_pixfmt_mp(pix, fmt->fourcc, width, height);
 	if (ret)
 		return ret;
 
+	if (stream->interface->type == RKCIF_IF_MIPI)
+		rkcif_stream_set_bytesperline(pix, req_bpl);
+
 	pix->field = V4L2_FIELD_NONE;
 
 	return 0;
-- 
2.43.0


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 23:23 [PATCH 0/2] media: rockchip: rkcif: ENUM_FMT and bytesperline fixes Faizel K B
2026-11-05 23:23 ` [PATCH 1/2] media: rockchip: rkcif: Filter enumerated formats by media bus code Faizel K B
2026-11-05 23:23 ` [PATCH 2/2] media: rockchip: rkcif: Honour the requested bytesperline on MIPI Faizel K B

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®