media: sun6i-csi: Improve capture and bridge
cover media: sun6i-csi: Improve capture and bridge
Hi,
I'm resending this series as I haven't received any feedback on the initial submission. This series improves sun6i-csi capture and bridge.
Patch 1 fixes sun6i_csi_capture_format_prepare() to align both width and height to 16 for NV12_16L16, as its 16x16 tiles require.
Patch 2 adds vidioc_enum_framesizes() to sun6i-csi-capture, using the same alignment.
Patch 3 removes duplicated mbus codes from sun6i-csi-bridge. It was posted earlier and carries Paul's Reviewed-by.
Tested on LicheePi Zero Dock (Allwinner V3s) with:
ov5647 -> sun6i-mipi-csi2 -> sun6i-csi-bridge -> sun6i-csi-capture
As ov5647 only outputs Bayer, streaming HM12/NV12 is not possible on this setup, so I did not test real streaming. I checked that v4l2-ctl --try-fmt-video, --set-fmt-video, --get-fmt-video and --list-framesizes report the expected sizes for HM12 (16 aligned) and NV12 (2 aligned).
Arash Golgol (3):
media: sun6i-csi: capture: Align size to 16 for NV12_16L16
media: sun6i-csi: capture: Add enum_framesizes support
media: sun6i-csi: bridge: Remove duplicate mbus format entries
.../sunxi/sun6i-csi/sun6i_csi_bridge.c | 12 ----- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 45 ++++++++++++++++--- 2 files changed, 39 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
PATCH RESEND 1/3 media: sun6i-csi: capture: Align size to 16 for NV12_16L16
The NV12_16L16 format is made of 16x16 tiles, so both the width and the height must be a multiple of 16. The format preparation always aligned dimensions to 2 pixels, whatever the pixel format, which allowed sizes covering partial tiles.
Select the alignment from the pixel format, and do so after the pixel format fallback so that the final format is the one used.
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +14 -6
@@ -41,6 +41,12 @@ void sun6i_csi_capture_format(struct sun6i_csi_device *csi_dev, *field = csi_dev->capture.format.fmt.pix.field; } +static unsigned int sun6i_csi_capture_format_align (u32 pixelformat) +{ +/* Returns log2 of the required alignment. */ +return pixelformat ==V4L2_PIX_FMT_NV12_16L16 ?4 :1 ; +} +/* Format */ static const struct sun6i_csi_capture_format sun6i_csi_capture_formats[] = {
@@ -665,17 +671,19 @@ static void sun6i_csi_capture_format_prepare(struct v4l2_format *format) {struct v4l2_pix_format *pix_format = &format->fmt.pix;const struct v4l2_format_info *info; -unsigned int width, height; - -v4l_bound_align_image (&pix_format->width,SUN6I_CSI_CAPTURE_WIDTH_MIN , -SUN6I_CSI_CAPTURE_WIDTH_MAX ,1 , - &pix_format->height,SUN6I_CSI_CAPTURE_HEIGHT_MIN , -SUN6I_CSI_CAPTURE_HEIGHT_MAX ,1 ,0 ); +unsigned int width, height, align;if (!sun6i_csi_capture_format_find (pix_format->pixelformat)) pix_format->pixelformat = sun6i_csi_capture_formats[0 ].pixelformat; + align =sun6i_csi_capture_format_align (pix_format->pixelformat); + +v4l_bound_align_image (&pix_format->width,SUN6I_CSI_CAPTURE_WIDTH_MIN , +SUN6I_CSI_CAPTURE_WIDTH_MAX , align, + &pix_format->height,SUN6I_CSI_CAPTURE_HEIGHT_MIN , +SUN6I_CSI_CAPTURE_HEIGHT_MAX , align,0 ); + width = pix_format->width; height = pix_format->height;
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 RESEND 1/3] media: sun6i-csi: capture: Align size to 16 for NV12_16L16
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] media: sun6i-csi: NV12_16L16 height alignment leaves partial chroma tiles - [Low] media…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] media: sun6i-csi: NV12_16L16 height alignment leaves partial chroma tiles
- [Low] media: sun6i-csi: missing Fixes trailer for NV12_16L16 alignment fix
--
commit 4b8ff24cde9c84f3080742e2927f26041221e015
Author: Arash Golgol <[email protected]>
Quoted 7 lines
media: sun6i-csi: capture: Align size to 16 for
NV12_16L16The
NV12_16L16format is made of 16x16 tiles, so both the width and the height must be a multiple of 16. The format preparation always aligned dimensions to 2 pixels, whatever the pixel format, which allowed sizes covering partial tiles.
Quoted 5 lines
Select the alignment from the pixel format, and do so after the pixel format fallback so that the final format is the one used.
Assisted-by Claude:claude-sonnet-5-5Signed-off-by Arash Golgol <[email protected]>
[Severity: Low]
This looks like a bug fix for NV12_16L16 format alignment. Should this include:
Quoted 32 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +7
-6@@ -41,6 +41,12 @@ void sun6i_csi_capture_format(struct sun6i_csi_device *csi_dev, *field = csi_dev->capture.format.fmt.pix.field; } +static unsigned int sun6i_csi_capture_format_align (u32 pixelformat) +{ +/* Returns log2 of the required alignment. */ +return pixelformat ==V4L2_PIX_FMT_NV12_16L16 ?4 :1 ; +} +/* Format */ static const struct sun6i_csi_capture_format sun6i_csi_capture_formats[] = {@@ -665,17 +671,19 @@ static void sun6i_csi_capture_format_prepare(struct v4l2_format *format) {struct v4l2_pix_format *pix_format = &format->fmt.pix;const struct v4l2_format_info *info; -unsigned int width, height; - -v4l_bound_align_image (&pix_format->width,SUN6I_CSI_CAPTURE_WIDTH_MIN , -SUN6I_CSI_CAPTURE_WIDTH_MAX ,1 , - &pix_format->height,SUN6I_CSI_CAPTURE_HEIGHT_MIN , -SUN6I_CSI_CAPTURE_HEIGHT_MAX ,1 ,0 ); +unsigned int width, height, align;if (!sun6i_csi_capture_format_find (pix_format->pixelformat)) pix_format->pixelformat = sun6i_csi_capture_formats[0 ].pixelformat;
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static void sun6i_csi_capture_format_prepare(struct v4l2_format *format) · line 688
Quoted 10 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +7
-0+ align =sun6i_csi_capture_format_align (pix_format->pixelformat); + +v4l_bound_align_image (&pix_format->width,SUN6I_CSI_CAPTURE_WIDTH_MIN , +SUN6I_CSI_CAPTURE_WIDTH_MAX , align, + &pix_format->height,SUN6I_CSI_CAPTURE_HEIGHT_MIN , +SUN6I_CSI_CAPTURE_HEIGHT_MAX , align,0 ); + width = pix_format->width; height = pix_format->height;
[Severity: Medium]
Does aligning height to 16 pixels still leave partial chroma tiles for V4L2_PIX_FMT_NV12_16L16?
V4L2_PIX_FMT_NV12_16L16 is a 4:2:0 semi-planar format where both the luma and chroma planes use 16x16 tiles. Because the chroma plane has half as many lines as the luma plane, one row of chroma tiles spans 32 image lines.
With 16-pixel height alignment, an odd multiple of 16 (such as 1280x720) leaves a half-row of chroma tiles, and sun6i_csi_capture_format_prepare() still computes sizeimage as (width * 12 / 8) * height. This leaves the buffer short by width * 8 bytes for consumers expecting full chroma tiles.
Aligning height to 32 pixels (halign = 5), or padding the chroma plane in sizeimage to width * ALIGN(height, 32) / 2 if 16-pixel heights must be kept, would avoid partial chroma tiles.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH RESEND 2/3 media: sun6i-csi: capture: Add enum_framesizes support
In reply to Arash GolgolImplement VIDIOC_ENUM_FRAMESIZES as a stepwise range from the minimum and maximum sizes supported by the hardware. The step follows the alignment enforced by try_fmt: 16 for NV12_16L16 and 2 otherwise.
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +25 -0
@@ -746,6 +746,30 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *priv,return 0 ; } +static int sun6i_csi_capture_enum_framesizes (struct file *file,void *priv, +struct v4l2_frmsizeenum *fsize) +{ +unsigned int step; + +if (fsize->index !=0 ) +return -EINVAL ; + +if (!sun6i_csi_capture_format_find (fsize->pixel_format)) +return -EINVAL ; + + step =1U <<sun6i_csi_capture_format_align (fsize->pixel_format); + + fsize->type =V4L2_FRMSIZE_TYPE_STEPWISE ; + fsize->stepwise.min_width =SUN6I_CSI_CAPTURE_WIDTH_MIN ; + fsize->stepwise.max_width =SUN6I_CSI_CAPTURE_WIDTH_MAX ; + fsize->stepwise.step_width = step; + fsize->stepwise.min_height =SUN6I_CSI_CAPTURE_HEIGHT_MIN ; + fsize->stepwise.max_height =SUN6I_CSI_CAPTURE_HEIGHT_MAX ; + fsize->stepwise.step_height = step; + +return 0 ; +} +static int sun6i_csi_capture_g_fmt (struct file *file,void *priv,struct v4l2_format *format) {
@@ -813,6 +837,7 @@ static const struct v4l2_ioctl_ops sun6i_csi_capture_ioctl_ops = { .vidioc_querycap = sun6i_csi_capture_querycap, .vidioc_enum_fmt_vid_cap = sun6i_csi_capture_enum_fmt, + .vidioc_enum_framesizes = sun6i_csi_capture_enum_framesizes, .vidioc_g_fmt_vid_cap = sun6i_csi_capture_g_fmt, .vidioc_s_fmt_vid_cap = sun6i_csi_capture_s_fmt, .vidioc_try_fmt_vid_cap = sun6i_csi_capture_try_fmt,
Signature · 1 line
2.34.1
PATCH RESEND 3/3 media: sun6i-csi: bridge: Remove duplicate mbus format entries
In reply to Arash GolgolThe driver reports MEDIA_BUS_FMT_UYVY8_2X8 and MEDIA_BUS_FMT_UYVY8_1X16 twice when enumerating supported media bus codes.
Remove the duplicated entries from sun6i_csi_bridge_formats[].
--- .../platform/sunxi/sun6i-csi/sun6i_csi_bridge.c | 12 ------------ 1 file changed, 12 deletions(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c +0 -12
@@ -93,12 +93,6 @@ static const struct sun6i_csi_bridge_format sun6i_csi_bridge_formats[] = { .input_yuv_seq = SUN6I_CSI_INPUT_YUV_SEQ_YVYU, .input_yuv_seq_invert = SUN6I_CSI_INPUT_YUV_SEQ_YUYV, }, - { - .mbus_code = MEDIA_BUS_FMT_UYVY8_2X8, - .input_format = SUN6I_CSI_INPUT_FMT_YUV422, - .input_yuv_seq = SUN6I_CSI_INPUT_YUV_SEQ_UYVY, - .input_yuv_seq_invert = SUN6I_CSI_INPUT_YUV_SEQ_VYUY, - }, { .mbus_code = MEDIA_BUS_FMT_VYUY8_2X8, .input_format = SUN6I_CSI_INPUT_FMT_YUV422,
@@ -123,12 +117,6 @@ static const struct sun6i_csi_bridge_format sun6i_csi_bridge_formats[] = { .input_yuv_seq = SUN6I_CSI_INPUT_YUV_SEQ_YVYU, .input_yuv_seq_invert = SUN6I_CSI_INPUT_YUV_SEQ_YUYV, }, - { - .mbus_code = MEDIA_BUS_FMT_UYVY8_1X16, - .input_format = SUN6I_CSI_INPUT_FMT_YUV422, - .input_yuv_seq = SUN6I_CSI_INPUT_YUV_SEQ_UYVY, - .input_yuv_seq_invert = SUN6I_CSI_INPUT_YUV_SEQ_VYUY, - }, { .mbus_code = MEDIA_BUS_FMT_VYUY8_1X16, .input_format = SUN6I_CSI_INPUT_FMT_YUV422,
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 RESEND 3/3] media: sun6i-csi: bridge: Remove duplicate mbus format entries
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] media: sun6i-csi: missing Fixes trailer for duplicate mbus format fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] media: sun6i-csi: missing Fixes trailer for duplicate mbus format fix
--
commit 850b1e10a5f40c70aa0ec931f64f3f8c9b5c9f03
Author: Arash Golgol <[email protected]>
Quoted 10 lines
media: sun6i-csi: bridge: Remove duplicate mbus format entries
The driver reports
MEDIA_BUS_FMT_UYVY8_2X8andMEDIA_BUS_FMT_UYVY8_1X16twice when enumerating supported media bus codes.Remove the duplicated entries from sun6i_csi_bridge_formats[].
Signed-off-by Arash Golgol <[email protected]>Reviewed-by Paul Kocialkowski <[email protected]>
[Severity: Low]
This fixes a bug where sun6i_csi_bridge_enum_mbus_code() reports duplicate media bus codes to userspace. Those duplicate entries were originally added when the bridge subdev was introduced. Should this include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3