media: sun6i-csi/isp: Implement MC I/O support
Subsystems (5)
cover media: sun6i-csi/isp: Implement MC I/O support
This series is a follow-up to Adam Pigg's "suns6-csi changes to support libcamera" series, with the same purpose.
As discussed in the original thread, it takes a different approach and ensures input/output format matching is maintained without regression.
New v4l2 format info is also added about unusual formats used by the driver so that no specific logic is required to handle them.
The same functionality is also added to the sun6i-isp driver.
Paul Kocialkowski (9):
media: v4l2: Add RGB565X pixel format to v4l2 format info
media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
media: v4l2: Introduce compressed pixel encoding definition and helper
media: v4l2: Add JPEG pixel format to v4l2 format info
media: sun6i-csi: capture: Rework and separate format validation
media: sun6i-csi: capture: Implement MC I/O with extended enum_fmt
media: sun6i-csi: capture: Implement enum_framesizes
media: sun6i-isp: capture: Implement MC I/O with extended enum_fmt
media: sun6i-isp: capture: Implement enum_framesizes
.../sunxi/sun6i-csi/sun6i_csi_capture.c | 157 ++++++++++++------ drivers/media/v4l2-core/v4l2-common.c | 6 + .../media/sunxi/sun6i-isp/sun6i_isp_capture.c | 35 +++- include/media/v4l2-common.h | 7 + 4 files changed, 154 insertions(+), 51 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/9 media: v4l2: Add RGB565X pixel format to v4l2 format info
Represent the RGB565X pixel format in the v4l2 format info table. This is a big-endian variant of the already present RGB565 format, which has the same characteristics.
--- drivers/media/v4l2-core/v4l2-common.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-common.c +1 -0
@@ -250,6 +250,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_ABGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGRA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB565, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_RGB565X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGR666, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
Signature · 1 line
2.39.2
Re: [PATCH 1/9] media: v4l2: Add RGB565X pixel format to v4l2 format info
Dne petek, 24. marec 2023 ob 16:12:20 CET je Paul Kocialkowski napisal(a):
Quoted 5 lines
Represent the RGB565X pixel format in the v4l2 format info table. This is a big-endian variant of the already present RGB565 format, which has the same characteristics.
Signed-off-by Paul Kocialkowski <[email protected]>
Best regards,
Jernej
Re: [PATCH 1/9] media: v4l2: Add RGB565X pixel format to v4l2 format info
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 5 lines · Paul Kocialkowski
Represent the RGB565X pixel format in the v4l2 format info table. This is a big-endian variant of the already present RGB565 format, which has the same characteristics.
Signed-off-by Paul Kocialkowski <[email protected]>
Quoted 16 lines
--- drivers/media/v4l2-core/v4l2-common.c | 1 + 1 file changed, 1 insertion(+)drivers/media/v4l2-core/v4l2-common.c +1
-0@@ -250,6 +250,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_ABGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGRA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB565, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_RGB565X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGR666, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/9 media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
In reply to Paul KocialkowskiRepresent the NV12_16L16 pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.
--- drivers/media/v4l2-core/v4l2-common.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +2 -0
@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } }, /* YUV planar formats, non contiguous variant */ { .format = V4L2_PIX_FMT_YUV420M, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },
Signature · 1 line
2.39.2
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
Dne petek, 24. marec 2023 ob 16:12:21 CET je Paul Kocialkowski napisal(a):
Quoted 4 lines
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.Signed-off-by Paul Kocialkowski <[email protected]>
Best regards,
Jernej
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 13 lines · Paul Kocialkowski
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-common.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/v4l2-core/v4l2-common.c +0
-0
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 284
Quoted 5 lines
drivers/media/v4l2-core/v4l2-common.c +2
-0@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } },
Not necessarily related to this patch, but I'm a bit puzzled by why V4L2_PIX_FMT_NV12_4L4 doesn't list block sizes.
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0/* YUV planar formats, non contiguous variant */ { .format = V4L2_PIX_FMT_YUV420M, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
Le samedi 25 mars 2023 à 23:01 +0200, Laurent Pinchart a écrit :
Quoted 13 lines
Hi Paul,
Thank you for the patch.
Quoted 8 lines · Paul Kocialkowski
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-common.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 13 lines
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 284
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +2
-0@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } },Not necessarily related to this patch, but I'm a bit puzzled by why
V4L2_PIX_FMT_NV12_4L4doesn't list block sizes.
It looks like Ezequiel introduced that initially, but didn't introduce any tiled format, as a side effect, we missed it and no one ever used it.
In practice, its not dramatic, since most of the time, the alignment needed is bigger then the block (specially with only 4x4 tiles), but we should certainly fix that, thanks for spotting.
Quoted 5 lines
Quoted 4 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0/* YUV planar formats, non contiguous variant */ { .format = V4L2_PIX_FMT_YUV420M, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
Hi Nicolas,
Quoted 24 lines · Nicolas Dufresne
Le samedi 25 mars 2023 à 23:01 +0200, Laurent Pinchart a écrit :
Quoted 9 lines · Paul Kocialkowski
Quoted 8 lines
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-common.c | 2 ++ 1 file changed, 2 insertions(+)Quoted 13 lines
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 284
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +2
-0@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } },Not necessarily related to this patch, but I'm a bit puzzled by why
V4L2_PIX_FMT_NV12_4L4doesn't list block sizes.
Quoted 6 lines
It looks like Ezequiel introduced that initially, but didn't introduce any tiled format, as a side effect, we missed it and no one ever used it.
In practice, its not dramatic, since most of the time, the alignment needed is bigger then the block (specially with only 4x4 tiles), but we should certainly fix that, thanks for spotting.
Just to make sure this won't fall through the cracks, will you send a patch ?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0/* YUV planar formats, non contiguous variant */ { .format = V4L2_PIX_FMT_YUV420M, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
Hi Laurent,
Le mer. 5 avr. 2023, 00 h 21, Laurent Pinchart
<[email protected]> a écrit :
Quoted 8 lines
Hi Nicolas,
Quoted 5 lines · Nicolas Dufresne
Le samedi 25 mars 2023 à 23:01 +0200, Laurent Pinchart a écrit :
Quoted 4 lines · Paul Kocialkowski
Quoted 3 lines
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/v4l2-
Quoted 6 lines
Signed-off-by Paul Kocialkowski <[email protected]>---
drivers/media/v4l2-core/v4l2-common.c| 2 ++1 file changed, 2 insertions(+)drivers/media/v4l2- renamed from drivers/media/v4l2-core/v4l2-common.c +0
-0
core/v4l2-common.c
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32
Quoted 4 lines
index
3d044b31caad..5101989716aa100644drivers/media/v4l2-core/v4l2-common.c +0
-0@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32
format)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0/* Tiled YUV formats */{ .format =
V4L2_PIX_FMT_NV12_4L4, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 },
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
{ .format =
V4L2_PIX_FMT_P010_4L4, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 },
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc =
V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2,
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+ .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } },
Not necessarily related to this patch, but I'm a bit puzzled by why
V4L2_PIX_FMT_NV12_4L4doesn't list block sizes.It looks like Ezequiel introduced that initially, but didn't introduce any
tiled
Quoted 3 lines
Quoted 3 lines
format, as a side effect, we missed it and no one ever used it.
In practice, its not dramatic, since most of the time, the alignment needed
is
Quoted 1 line
Quoted 1 line
bigger then the block (specially with only 4x4 tiles), but we should
certainly
Quoted 4 lines
Quoted 1 line
fix that, thanks for spotting.
Just to make sure this won't fall through the cracks, will you send a patch ?
I didn't had any immediate plan to fix it (lack of time, absence of related bugs). Andrzej, do you happen to have some time ? The SUNXI pixel format should have that too, along with some NXP format.
regards,
Nicolas
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
/* YUV planar formats, non contiguous variant */
{ .format =V4L2_PIX_FMT_YUV420M, .pixel_enc =V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/9] media: v4l2: Add NV12_16L16 pixel format to v4l2 format info
In reply to Paul KocialkowskiLe vendredi 24 mars 2023 à 16:12 +0100, Paul Kocialkowski a écrit :
Quoted 4 lines
Represent the
NV12_16L16pixel format in the v4l2 format info table. This is a 16x16 tiled version of NV12.Signed-off-by Paul Kocialkowski <[email protected]>
Quoted 17 lines
--- drivers/media/v4l2-core/v4l2-common.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/v4l2-core/v4l2-common.c +2
-0@@ -280,6 +280,8 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .hdiv = 2, .vdiv = 2 }, + { .format = V4L2_PIX_FMT_NV12_16L16, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2, + .block_w = { 16, 16, 0, 0 }, .block_h = { 16, 16, 0, 0 } }, /* YUV planar formats, non contiguous variant */ { .format = V4L2_PIX_FMT_YUV420M, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 3, .comp_planes = 3, .bpp = { 1, 1, 1, 0 }, .hdiv = 2, .vdiv = 2 },
PATCH 3/9 media: v4l2: Introduce compressed pixel encoding definition and helper
In reply to Paul KocialkowskiSome pixel formats (such as JPEG) have their data compressed and encoded in a specific way, which is not directly YUV, RGB or Bayer.
Add a new definition and helper for compressed pixel encoding to represent this situation.
--- include/media/v4l2-common.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/media/v4l2-common.h +7 -0
@@ -465,12 +465,14 @@ int v4l2_s_parm_cap(struct video_device *vdev,* @V4L2_PIXEL_ENC_YUV: Pixel encoding is YUV * @V4L2_PIXEL_ENC_RGB: Pixel encoding is RGB * @V4L2_PIXEL_ENC_BAYER: Pixel encoding is Bayer +* @V4L2_PIXEL_ENC_COMPRESSED: Pixel encoding is compressed */ enum v4l2_pixel_encoding {V4L2_PIXEL_ENC_UNKNOWN =0 ,V4L2_PIXEL_ENC_YUV =1 ,V4L2_PIXEL_ENC_RGB =2 ,V4L2_PIXEL_ENC_BAYER =3 , +V4L2_PIXEL_ENC_COMPRESSED =4 , };/**
@@ -512,6 +514,11 @@ static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)return f && f->pixel_enc ==V4L2_PIXEL_ENC_BAYER ; } +static inline bool v4l2_is_format_compressed (const struct v4l2_format_info *f) +{ +return f && f->pixel_enc ==V4L2_PIXEL_ENC_COMPRESSED ; +} +const struct v4l2_format_info *v4l2_format_info (u32 format);void v4l2_apply_frmsize_constraints (u32 *width,u32 *height,const struct v4l2_frmsize_stepwise *frmsize);
Signature · 1 line
2.39.2
Re: [PATCH 3/9] media: v4l2: Introduce compressed pixel encoding definition and helper
Dne petek, 24. marec 2023 ob 16:12:22 CET je Paul Kocialkowski napisal(a):
Quoted 7 lines
Some pixel formats (such as JPEG) have their data compressed and encoded in a specific way, which is not directly YUV, RGB or Bayer.
Add a new definition and helper for compressed pixel encoding to represent this situation.
Signed-off-by Paul Kocialkowski <[email protected]>
Best regards,
Jernej
PATCH 4/9 media: v4l2: Add JPEG pixel format to v4l2 format info
In reply to Paul KocialkowskiRepresent the JPEG pixel format in the v4l2 format info table.
Note that the bpp is set to 1 which is not a proper way to estimate the needed buffer size for a given JPEG image. However the compression ratios of JPEG typically allow fitting the image in a smaller size, even though extra metadata could increase the total size by an arbitrary amount. Thus it is not a perfectly safe way to calculate the size of a JPEG buffer for given dimensions but it still provides a reasonable approach.
--- drivers/media/v4l2-core/v4l2-common.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +3 -0
@@ -317,6 +317,9 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_SGBRG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGRBG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SRGGB12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, + + /* Compressed formats */ + { .format = V4L2_PIX_FMT_JPEG, .pixel_enc = V4L2_PIXEL_ENC_COMPRESSED, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, }; unsigned int i;
Signature · 1 line
2.39.2
Re: [PATCH 4/9] media: v4l2: Add JPEG pixel format to v4l2 format info
Dne petek, 24. marec 2023 ob 16:12:23 CET je Paul Kocialkowski napisal(a):
Quoted 11 lines
Represent the JPEG pixel format in the v4l2 format info table.
Note that the bpp is set to 1 which is not a proper way to estimate the needed buffer size for a given JPEG image. However the compression ratios of JPEG typically allow fitting the image in a smaller size, even though extra metadata could increase the total size by an arbitrary amount. Thus it is not a perfectly safe way to calculate the size of a JPEG buffer for given dimensions but it still provides a reasonable approach.
Signed-off-by Paul Kocialkowski <[email protected]>
Best regards,
Jernej
Re: [PATCH 4/9] media: v4l2: Add JPEG pixel format to v4l2 format info
In reply to Paul KocialkowskiLe vendredi 24 mars 2023 à 16:12 +0100, Paul Kocialkowski a écrit :
Quoted 20 lines
Represent the JPEG pixel format in the v4l2 format info table.
Note that the bpp is set to 1 which is not a proper way to estimate the needed buffer size for a given JPEG image. However the compression ratios of JPEG typically allow fitting the image in a smaller size, even though extra metadata could increase the total size by an arbitrary amount. Thus it is not a perfectly safe way to calculate the size of a JPEG buffer for given dimensions but it still provides a reasonable approach.
Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-common.c | 3 +++ 1 file changed, 3 insertions(+)drivers/media/v4l2-core/v4l2-common.c +0
-0
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 322
Quoted 6 lines
drivers/media/v4l2-core/v4l2-common.c +3
-0@@ -317,6 +317,9 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_SGBRG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGRBG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SRGGB12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 }, + + /* Compressed formats */ + { .format = V4L2_PIX_FMT_JPEG, .pixel_enc = V4L2_PIXEL_ENC_COMPRESSED, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
This is ackward, at best. Guesstimating the compressed buffer size is a valid use case, but this table and the related helper function seems badly suited. When I look at the stateless decoders that do that, they take into account the fact that the compression can handle different bit depth, and difference subsampling (choma idc). In this implementation, JPEG is reduce to 4:4:4, 8bit.
I'd like to reject this change, and recommand coming back with a suitable integration, so that it can be special cased and the driver can communicate the required information to narrow down the estimate. And this way, you are actually making it usable for other compressed format like H.264, HEVC, VP8, VP9 AV1 etc.
Nicolas
Nacked in that form.
Quoted 4 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0};unsigned int i;
PATCH 5/9 media: sun6i-csi: capture: Rework and separate format validation
In reply to Paul KocialkowskiIntroduce a new sun6i_csi_capture_format_check helper to indicate whether a set of pixel format and mbus code are compatible. Most of the logic is taken from sun6i_csi_capture_link_validate, with extra checks added along the way.
Note that v4l2_format_info is now used for all pixel formats since they should all be listed in the helper at this point.
The motivation behind this change is to pave the way for supporting the mc-style enum_fmt.
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 95 ++++++++++--------- 1 file changed, 49 insertions(+), 46 deletions(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +49 -46
@@ -327,6 +327,52 @@ static bool sun6i_csi_capture_format_match(u32 pixelformat, u32 mbus_code)return false; } +static bool sun6i_csi_capture_format_check (u32 pixelformat,u32 mbus_code) +{ +const struct sun6i_csi_capture_format *capture_format; +const struct sun6i_csi_bridge_format *bridge_format; +const struct v4l2_format_info *format_info; + + format_info =v4l2_format_info (pixelformat); +if (WARN_ON (!format_info)) +return false; + + capture_format =sun6i_csi_capture_format_find (pixelformat); +if (WARN_ON (!capture_format)) +return false; + + bridge_format =sun6i_csi_bridge_format_find (mbus_code); +if (WARN_ON (!bridge_format)) +return false; + +/* Raw input is required for non-YUV formats. */ +if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW && + (format_info->pixel_enc ==V4L2_PIXEL_ENC_BAYER || + format_info->pixel_enc ==V4L2_PIXEL_ENC_RGB || + format_info->pixel_enc ==V4L2_PIXEL_ENC_COMPRESSED )) +return false; + +if (format_info->pixel_enc ==V4L2_PIXEL_ENC_YUV ) { +/* YUV input is required for YUV pixels. */ +if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV420 && + bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV422 ) +return false; + +/* YUV420 input can't produce (upsampled) YUV422 output. */ +if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_YUV420 && + format_info->vdiv ==1 ) +return false; + } + +/* Raw input requires a 1:1 match between input and output. */ +if ((bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_RAW || + capture_format->input_format_raw) && + !sun6i_csi_capture_format_match (pixelformat, mbus_code)) +return false; + +return true; +} +/* Capture */ static void
@@ -890,28 +936,16 @@ static int sun6i_csi_capture_link_validate(struct media_link *link)media_entity_to_video_device (link->sink->entity);struct sun6i_csi_device *csi_dev =video_get_drvdata (video_dev);struct v4l2_device *v4l2_dev = csi_dev->v4l2_dev; -const struct sun6i_csi_capture_format *capture_format; -const struct sun6i_csi_bridge_format *bridge_format;unsigned int capture_width, capture_height;unsigned int bridge_width, bridge_height; -const struct v4l2_format_info *format_info;u32 pixelformat, capture_field;u32 mbus_code, bridge_field; -bool match;sun6i_csi_capture_dimensions (csi_dev, &capture_width, &capture_height); -sun6i_csi_capture_format (csi_dev, &pixelformat, &capture_field); - capture_format =sun6i_csi_capture_format_find (pixelformat); -if (WARN_ON (!capture_format)) -return -EINVAL ;sun6i_csi_bridge_dimensions (csi_dev, &bridge_width, &bridge_height); -sun6i_csi_bridge_format (csi_dev, &mbus_code, &bridge_field); - bridge_format =sun6i_csi_bridge_format_find (mbus_code); -if (WARN_ON (!bridge_format)) -return -EINVAL ;/* No cropping/scaling is supported. */ if (capture_width != bridge_width || capture_height != bridge_height) {
@@ -922,43 +956,12 @@ static int sun6i_csi_capture_link_validate(struct media_link *link)return -EINVAL ; } - format_info =v4l2_format_info (pixelformat); -/* Some formats are not listed. */ -if (!format_info) -return 0 ; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_BAYER && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW ) - goto invalid; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_RGB && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW ) - goto invalid; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_YUV ) { -if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV420 && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV422 ) - goto invalid; - -/* YUV420 input can't produce YUV422 output. */ -if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_YUV420 && - format_info->vdiv ==1 ) - goto invalid; - } - -/* With raw input mode, we need a 1:1 match between input and output. */ -if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_RAW || - capture_format->input_format_raw) { - match =sun6i_csi_capture_format_match (pixelformat, mbus_code); -if (!match) - goto invalid; +if (!sun6i_csi_capture_format_check (pixelformat, mbus_code)) { +v4l2_err (v4l2_dev,"invalid input/output format combination\n" ); +return -EINVAL ; }return 0 ; - -invalid: -v4l2_err (v4l2_dev,"invalid input/output format combination\n" ); -return -EINVAL ; }static const struct media_entity_operations sun6i_csi_capture_media_ops = {
Signature · 1 line
2.39.2
Re: [PATCH 5/9] media: sun6i-csi: capture: Rework and separate format validation
Dne petek, 24. marec 2023 ob 16:12:24 CET je Paul Kocialkowski napisal(a):
Quoted 5 lines
Introduce a new
sun6i_csi_capture_format_checkhelper to indicate whether a set of pixel format and mbus code are compatible. Most of the logic is taken fromsun6i_csi_capture_link_validate, with extra checks added along the way.
Quoted 7 lines
Note that
v4l2_format_infois now used for all pixel formats since they should all be listed in the helper at this point.The motivation behind this change is to pave the way for supporting the mc-style
enum_fmt.Signed-off-by Paul Kocialkowski <[email protected]>
Best regards,
Jernej
Re: [PATCH 5/9] media: sun6i-csi: capture: Rework and separate format validation
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 21 lines · Paul Kocialkowski
Introduce a new
sun6i_csi_capture_format_checkhelper to indicate whether a set of pixel format and mbus code are compatible. Most of the logic is taken fromsun6i_csi_capture_link_validate, with extra checks added along the way.Note that
v4l2_format_infois now used for all pixel formats since they should all be listed in the helper at this point.The motivation behind this change is to pave the way for supporting the mc-style
enum_fmt.Signed-off-by Paul Kocialkowski <[email protected]>--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 95 ++++++++++--------- 1 file changed, 49 insertions(+), 46 deletions(-)drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +0
-0
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static bool sun6i_csi_capture_format_match(u32 pixelformat, u32 mbus_code) · line 333
Quoted 7 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +4
-0@@ -327,6 +327,52 @@ static bool sun6i_csi_capture_format_match(u32 pixelformat, u32 mbus_code)return false; } +static bool sun6i_csi_capture_format_check (u32 pixelformat,u32 mbus_code) +{ +const struct sun6i_csi_capture_format *capture_format; +const struct sun6i_csi_bridge_format *bridge_format;
I think I would have named those output_format and input_format respectively, as "capture" and "bridge" take a bit more mental processing when reading the code. That may be because I'm not familiar with the driver though, so feel free to ignore this.
Quoted 9 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +9
-0+const struct v4l2_format_info *format_info; + + format_info =v4l2_format_info (pixelformat); +if (WARN_ON (!format_info)) +return false; + + capture_format =sun6i_csi_capture_format_find (pixelformat); +if (WARN_ON (!capture_format)) +return false;
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static bool sun6i_csi_capture_format_match(u32 pixelformat, u32 mbus_code) · line 352
Quoted 10 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +10
-0+ + bridge_format =sun6i_csi_bridge_format_find (mbus_code); +if (WARN_ON (!bridge_format)) +return false; + +/* Raw input is required for non-YUV formats. */ +if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW && + (format_info->pixel_enc ==V4L2_PIXEL_ENC_BAYER || + format_info->pixel_enc ==V4L2_PIXEL_ENC_RGB || + format_info->pixel_enc ==V4L2_PIXEL_ENC_COMPRESSED ))
Unless I'm mistaken, the compressed format check is new. You could split it to a separate patch, or at least mention it in the commit message.
Quoted 9 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +9
-0+return false; + +if (format_info->pixel_enc ==V4L2_PIXEL_ENC_YUV ) { +/* YUV input is required for YUV pixels. */ +if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV420 && + bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV422 ) +return false; + +/* YUV420 input can't produce (upsampled) YUV422 output. */
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static bool sun6i_csi_capture_format_match(u32 pixelformat, u32 mbus_code) · line 371
Quoted 10 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +10
-0+if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_YUV420 && + format_info->vdiv ==1 ) +return false; + } + +/* Raw input requires a 1:1 match between input and output. */ +if ((bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_RAW || + capture_format->input_format_raw) && + !sun6i_csi_capture_format_match (pixelformat, mbus_code)) +return false;
Wrong indentation.
With this fixed,
Quoted 83 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +7
-46+ +return true; +} +/* Capture */ static void@@ -890,28 +936,16 @@ static int sun6i_csi_capture_link_validate(struct media_link *link)media_entity_to_video_device (link->sink->entity);struct sun6i_csi_device *csi_dev =video_get_drvdata (video_dev);struct v4l2_device *v4l2_dev = csi_dev->v4l2_dev; -const struct sun6i_csi_capture_format *capture_format; -const struct sun6i_csi_bridge_format *bridge_format;unsigned int capture_width, capture_height;unsigned int bridge_width, bridge_height; -const struct v4l2_format_info *format_info;u32 pixelformat, capture_field;u32 mbus_code, bridge_field; -bool match;sun6i_csi_capture_dimensions (csi_dev, &capture_width, &capture_height); -sun6i_csi_capture_format (csi_dev, &pixelformat, &capture_field); - capture_format =sun6i_csi_capture_format_find (pixelformat); -if (WARN_ON (!capture_format)) -return -EINVAL ;sun6i_csi_bridge_dimensions (csi_dev, &bridge_width, &bridge_height); -sun6i_csi_bridge_format (csi_dev, &mbus_code, &bridge_field); - bridge_format =sun6i_csi_bridge_format_find (mbus_code); -if (WARN_ON (!bridge_format)) -return -EINVAL ;/* No cropping/scaling is supported. */ if (capture_width != bridge_width || capture_height != bridge_height) {@@ -922,43 +956,12 @@ static int sun6i_csi_capture_link_validate(struct media_link *link)return -EINVAL ; } - format_info =v4l2_format_info (pixelformat); -/* Some formats are not listed. */ -if (!format_info) -return 0 ; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_BAYER && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW ) - goto invalid; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_RGB && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_RAW ) - goto invalid; - -if (format_info->pixel_enc ==V4L2_PIXEL_ENC_YUV ) { -if (bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV420 && - bridge_format->input_format !=SUN6I_CSI_INPUT_FMT_YUV422 ) - goto invalid; - -/* YUV420 input can't produce YUV422 output. */ -if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_YUV420 && - format_info->vdiv ==1 ) - goto invalid; - } - -/* With raw input mode, we need a 1:1 match between input and output. */ -if (bridge_format->input_format ==SUN6I_CSI_INPUT_FMT_RAW || - capture_format->input_format_raw) { - match =sun6i_csi_capture_format_match (pixelformat, mbus_code); -if (!match) - goto invalid; +if (!sun6i_csi_capture_format_check (pixelformat, mbus_code)) { +v4l2_err (v4l2_dev,"invalid input/output format combination\n" ); +return -EINVAL ; }return 0 ; - -invalid: -v4l2_err (v4l2_dev,"invalid input/output format combination\n" ); -return -EINVAL ; }static const struct media_entity_operations sun6i_csi_capture_media_ops = {
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 6/9 media: sun6i-csi: capture: Implement MC I/O with extended enum_fmt
In reply to Paul KocialkowskiThis driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the IO_MC device cap and extend the enum_fmt implementation to support enumeration with an explicit mbus_code.
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +32 -4
@@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code; +unsigned int index_valid =0 ; +unsigned int i; + +if (!mbus_code) { +if (index >=ARRAY_SIZE (sun6i_csi_capture_formats)) +return -EINVAL ; + + fmtdesc->pixelformat = + sun6i_csi_capture_formats[index].pixelformat; + +return 0 ; + } + +/* Check capture pixel format matching with mbus code. */ -if (index >=ARRAY_SIZE (sun6i_csi_capture_formats)) +if (!sun6i_csi_bridge_format_find (mbus_code))return -EINVAL ; - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; +for (i =0 ; i <ARRAY_SIZE (sun6i_csi_capture_formats); i++) { +u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; -return 0 ; +if (!sun6i_csi_capture_format_check (pixelformat, mbus_code)) +continue ; + +if (index == index_valid) { + fmtdesc->pixelformat = pixelformat; +return 0 ; + } + + index_valid++; + } + +return -EINVAL ; } static int sun6i_csi_capture_g_fmt(struct file *file, void *private,
@@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev)strscpy (video_dev->name,SUN6I_CSI_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_csi_capture_fops;
Signature · 1 line
2.39.2
Re: [PATCH 6/9] media: sun6i-csi: capture: Implement MC I/O with extended enum_fmt
Dne petek, 24. marec 2023 ob 16:12:25 CET je Paul Kocialkowski napisal(a):
Quoted 16 lines
This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the
IO_MCdevice cap and extend theenum_fmtimplementation to support enumeration with an explicitmbus_code.Signed-off-by Paul Kocialkowski <[email protected]>--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-)drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +0
-0
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, · line 780
Quoted 4 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +1
-0@@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code;
Nit: reverse christmas tree.
Other than that:
Best regards,
Jernej
Quoted 53 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +31
-4+unsigned int index_valid =0 ; +unsigned int i; + +if (!mbus_code) { +if (index >=ARRAY_SIZE (sun6i_csi_capture_formats)) +return -EINVAL ; + + fmtdesc->pixelformat = + sun6i_csi_capture_formats[index].pixelformat; + +return 0 ; + } + +/* Check capture pixel format matching with mbus code. */ -if (index >=ARRAY_SIZE (sun6i_csi_capture_formats)) +if (!sun6i_csi_bridge_format_find (mbus_code))return -EINVAL ; - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; +for (i =0 ; i <ARRAY_SIZE (sun6i_csi_capture_formats); i++) { +u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; -return 0 ; +if (!sun6i_csi_capture_format_check (pixelformat, mbus_code)) +continue ; + +if (index == index_valid) { + fmtdesc->pixelformat = pixelformat; +return 0 ; + } + + index_valid++; + } + +return -EINVAL ; } static int sun6i_csi_capture_g_fmt(struct file *file, void *private,@@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev)strscpy (video_dev->name,SUN6I_CSI_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_csi_capture_fops;Signature · 1 line
2.39.2
Re: [PATCH 6/9] media: sun6i-csi: capture: Implement MC I/O with extended enum_fmt
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 36 lines · Paul Kocialkowski
This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the
IO_MCdevice cap and extend theenum_fmtimplementation to support enumeration with an explicitmbus_code.Signed-off-by Paul Kocialkowski <[email protected]>--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-)drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +15
-1@@ -777,13 +777,40 @@ static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code; +unsigned int index_valid =0 ; +unsigned int i; + +if (!mbus_code) { +if (index >=ARRAY_SIZE (sun6i_csi_capture_formats)) +return -EINVAL ; + + fmtdesc->pixelformat = + sun6i_csi_capture_formats[index].pixelformat; + +return 0 ; + } + +/* Check capture pixel format matching with mbus code. */ -if (index >=ARRAY_SIZE (sun6i_csi_capture_formats))
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, · line 803
Quoted 10 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +5
-2+if (!sun6i_csi_bridge_format_find (mbus_code))return -EINVAL ; - fmtdesc->pixelformat = sun6i_csi_capture_formats[index].pixelformat; +for (i =0 ; i <ARRAY_SIZE (sun6i_csi_capture_formats); i++) { +u32 pixelformat = sun6i_csi_capture_formats[i].pixelformat; -return 0 ; +if (!sun6i_csi_capture_format_check (pixelformat, mbus_code)) +continue ;
I would probably have added compatible media bus codes to the sun6i_csi_capture_format structure. This should work though, even if it is more CPU-intensive. I'm OK with either option.
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c static int sun6i_csi_capture_enum_fmt(struct file *file, void *private, · line 805
Quoted 2 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +2
-0+ +if (index == index_valid) {
You can replace this with
if (index == 0) {and
index_valid++;
with
index--;
below, and drop the index_valid variable.
Quoted 20 lines
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +10
-1+ fmtdesc->pixelformat = pixelformat; +return 0 ; + } + + index_valid++; + } + +return -EINVAL ; } static int sun6i_csi_capture_g_fmt(struct file *file, void *private,@@ -1039,7 +1066,8 @@ int sun6i_csi_capture_setup(struct sun6i_csi_device *csi_dev)strscpy (video_dev->name,SUN6I_CSI_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 7/9 media: sun6i-csi: capture: Implement enum_framesizes
In reply to Paul KocialkowskiReport available frame sizes as a continuous range between the hardware min/max limits.
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +26 -0
@@ -847,6 +847,30 @@ static int sun6i_csi_capture_try_fmt(struct file *file, void *private,return 0 ; } +static int +sun6i_csi_capture_enum_framesizes (struct file *file,void *fh, +struct v4l2_frmsizeenum *frmsizeenum) +{ +const struct sun6i_csi_capture_format *format; + +if (frmsizeenum->index >0 ) +return -EINVAL ; + + format =sun6i_csi_capture_format_find (frmsizeenum->pixel_format); +if (!format) +return -EINVAL ; + + frmsizeenum->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + frmsizeenum->stepwise.min_width =SUN6I_CSI_CAPTURE_WIDTH_MIN ; + frmsizeenum->stepwise.max_width =SUN6I_CSI_CAPTURE_WIDTH_MAX ; + frmsizeenum->stepwise.min_height =SUN6I_CSI_CAPTURE_HEIGHT_MIN ; + frmsizeenum->stepwise.max_height =SUN6I_CSI_CAPTURE_HEIGHT_MAX ; + frmsizeenum->stepwise.step_width =1 ; + frmsizeenum->stepwise.step_height =1 ; + +return 0 ; +} +static int sun6i_csi_capture_enum_input (struct file *file,void *private,struct v4l2_input *input) {
@@ -884,6 +908,8 @@ static const struct v4l2_ioctl_ops sun6i_csi_capture_ioctl_ops = { .vidioc_s_fmt_vid_cap = sun6i_csi_capture_s_fmt, .vidioc_try_fmt_vid_cap = sun6i_csi_capture_try_fmt, + .vidioc_enum_framesizes = sun6i_csi_capture_enum_framesizes, + .vidioc_enum_input = sun6i_csi_capture_enum_input, .vidioc_g_input = sun6i_csi_capture_g_input, .vidioc_s_input = sun6i_csi_capture_s_input,
Signature · 1 line
2.39.2
Re: [PATCH 7/9] media: sun6i-csi: capture: Implement enum_framesizes
Dne petek, 24. marec 2023 ob 16:12:26 CET je Paul Kocialkowski napisal(a):
Quoted 6 lines
Report available frame sizes as a continuous range between the hardware min/max limits.
Signed-off-by Paul Kocialkowski <[email protected]>Co-authored-by Adam Pigg <[email protected]>Signed-off-by Adam Pigg <[email protected]>
Best regards,
Jernej
Re: [PATCH 7/9] media: sun6i-csi: capture: Implement enum_framesizes
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 6 lines · Paul Kocialkowski
Report available frame sizes as a continuous range between the hardware min/max limits.
Signed-off-by Paul Kocialkowski <[email protected]>Co-authored-by Adam Pigg <[email protected]>Signed-off-by Adam Pigg <[email protected]>
Quoted 48 lines
--- .../sunxi/sun6i-csi/sun6i_csi_capture.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +26
-0@@ -847,6 +847,30 @@ static int sun6i_csi_capture_try_fmt(struct file *file, void *private,return 0 ; } +static int +sun6i_csi_capture_enum_framesizes (struct file *file,void *fh, +struct v4l2_frmsizeenum *frmsizeenum) +{ +const struct sun6i_csi_capture_format *format; + +if (frmsizeenum->index >0 ) +return -EINVAL ; + + format =sun6i_csi_capture_format_find (frmsizeenum->pixel_format); +if (!format) +return -EINVAL ; + + frmsizeenum->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + frmsizeenum->stepwise.min_width =SUN6I_CSI_CAPTURE_WIDTH_MIN ; + frmsizeenum->stepwise.max_width =SUN6I_CSI_CAPTURE_WIDTH_MAX ; + frmsizeenum->stepwise.min_height =SUN6I_CSI_CAPTURE_HEIGHT_MIN ; + frmsizeenum->stepwise.max_height =SUN6I_CSI_CAPTURE_HEIGHT_MAX ; + frmsizeenum->stepwise.step_width =1 ; + frmsizeenum->stepwise.step_height =1 ; + +return 0 ; +} +static int sun6i_csi_capture_enum_input (struct file *file,void *private,struct v4l2_input *input) {@@ -884,6 +908,8 @@ static const struct v4l2_ioctl_ops sun6i_csi_capture_ioctl_ops = { .vidioc_s_fmt_vid_cap = sun6i_csi_capture_s_fmt, .vidioc_try_fmt_vid_cap = sun6i_csi_capture_try_fmt, + .vidioc_enum_framesizes = sun6i_csi_capture_enum_framesizes, + .vidioc_enum_input = sun6i_csi_capture_enum_input, .vidioc_g_input = sun6i_csi_capture_g_input, .vidioc_s_input = sun6i_csi_capture_s_input,
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 8/9 media: sun6i-isp: capture: Implement MC I/O with extended enum_fmt
In reply to Paul KocialkowskiThis driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the IO_MC device cap and extend the enum_fmt implementation to support enumeration with an explicit mbus_code.
--- .../staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +8 -1
@@ -439,6 +439,12 @@ static int sun6i_isp_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code; + +if (mbus_code && !sun6i_isp_proc_format_find (mbus_code)) +return -EINVAL ; + +/* Capture format is independent from proc format. */ if (index >=ARRAY_SIZE (sun6i_isp_capture_formats))return -EINVAL ;
@@ -685,7 +691,8 @@ int sun6i_isp_capture_setup(struct sun6i_isp_device *isp_dev)strscpy (video_dev->name,SUN6I_ISP_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_isp_capture_fops;
Signature · 1 line
2.39.2
Re: [PATCH 8/9] media: sun6i-isp: capture: Implement MC I/O with extended enum_fmt
Dne petek, 24. marec 2023 ob 16:12:27 CET je Paul Kocialkowski napisal(a):
Quoted 16 lines
This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the
IO_MCdevice cap and extend theenum_fmtimplementation to support enumeration with an explicitmbus_code.Signed-off-by Paul Kocialkowski <[email protected]>--- .../staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +0
-0
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c static int sun6i_isp_capture_enum_fmt(struct file *file, void *private, · line 442
Quoted 4 lines
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +1
-0@@ -439,6 +439,12 @@ static int sun6i_isp_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code;
Nit: reverse christmas tree
Other than that:
Best regards,
Jernej
Quoted 22 lines
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +7
-1+ +if (mbus_code && !sun6i_isp_proc_format_find (mbus_code)) +return -EINVAL ; + +/* Capture format is independent from proc format. */ if (index >=ARRAY_SIZE (sun6i_isp_capture_formats))return -EINVAL ;@@ -685,7 +691,8 @@ int sun6i_isp_capture_setup(struct sun6i_isp_device *isp_dev)strscpy (video_dev->name,SUN6I_ISP_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_isp_capture_fops;Signature · 1 line
2.39.2
Re: [PATCH 8/9] media: sun6i-isp: capture: Implement MC I/O with extended enum_fmt
In reply to Paul KocialkowskiHi Paul,
Thank you for the patch.
Quoted 16 lines · Paul Kocialkowski
This driver needs the media-controller API to operate and should not be considered as a video-device-centric implementation.
Properly report the
IO_MCdevice cap and extend theenum_fmtimplementation to support enumeration with an explicitmbus_code.Signed-off-by Paul Kocialkowski <[email protected]>--- .../staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +0
-0
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c static int sun6i_isp_capture_enum_fmt(struct file *file, void *private, · line 446
Quoted 8 lines
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +5
-0@@ -439,6 +439,12 @@ static int sun6i_isp_capture_enum_fmt(struct file *file, void *private, struct v4l2_fmtdesc *fmtdesc) {u32 index = fmtdesc->index; +u32 mbus_code = fmtdesc->mbus_code; + +if (mbus_code && !sun6i_isp_proc_format_find (mbus_code)) +return -EINVAL ; +
This doesn't look right. As far as I understand, sun6i_isp_proc_format_find() looks up media bus codes for the ISP sink pad. Here you enuemrate pixel formats of the ISP output, so the media bus code given by userspace corresponds to the ISP source pad.
I've had a look at sun6i_isp_proc_set_fmt() to see what media bus codes are used on the ISP output, and couldn't figure it out as it seems incorrectly implemented :-) The function doesn't check format->pad.
Quoted 14 lines
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +3
-1+/* Capture format is independent from proc format. */ if (index >=ARRAY_SIZE (sun6i_isp_capture_formats))return -EINVAL ;@@ -685,7 +691,8 @@ int sun6i_isp_capture_setup(struct sun6i_isp_device *isp_dev)strscpy (video_dev->name,SUN6I_ISP_CAPTURE_NAME ,sizeof (video_dev->name)); - video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING ; + video_dev->device_caps =V4L2_CAP_VIDEO_CAPTURE |V4L2_CAP_STREAMING | +V4L2_CAP_IO_MC ; video_dev->vfl_dir =VFL_DIR_RX ; video_dev->release = video_device_release_empty; video_dev->fops = &sun6i_isp_capture_fops;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 9/9 media: sun6i-isp: capture: Implement enum_framesizes
In reply to Paul KocialkowskiReport available frame sizes as a continuous range between the hardware min/max limits.
--- .../media/sunxi/sun6i-isp/sun6i_isp_capture.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/staging/media/sunxi/sun6i-isp/sun6i_isp_capture.c +26 -0
@@ -487,6 +487,30 @@ static int sun6i_isp_capture_try_fmt(struct file *file, void *private,return 0 ; } +static int +sun6i_isp_capture_enum_framesizes (struct file *file,void *fh, +struct v4l2_frmsizeenum *frmsizeenum) +{ +const struct sun6i_isp_capture_format *format; + +if (frmsizeenum->index >0 ) +return -EINVAL ; + + format =sun6i_isp_capture_format_find (frmsizeenum->pixel_format); +if (!format) +return -EINVAL ; + + frmsizeenum->type =V4L2_FRMSIZE_TYPE_CONTINUOUS ; + frmsizeenum->stepwise.min_width =SUN6I_ISP_CAPTURE_WIDTH_MIN ; + frmsizeenum->stepwise.max_width =SUN6I_ISP_CAPTURE_WIDTH_MAX ; + frmsizeenum->stepwise.min_height =SUN6I_ISP_CAPTURE_HEIGHT_MIN ; + frmsizeenum->stepwise.max_height =SUN6I_ISP_CAPTURE_HEIGHT_MAX ; + frmsizeenum->stepwise.step_width =1 ; + frmsizeenum->stepwise.step_height =1 ; + +return 0 ; +} +static int sun6i_isp_capture_enum_input (struct file *file,void *private,struct v4l2_input *input) {
@@ -524,6 +548,8 @@ static const struct v4l2_ioctl_ops sun6i_isp_capture_ioctl_ops = { .vidioc_s_fmt_vid_cap = sun6i_isp_capture_s_fmt, .vidioc_try_fmt_vid_cap = sun6i_isp_capture_try_fmt, + .vidioc_enum_framesizes = sun6i_isp_capture_enum_framesizes, + .vidioc_enum_input = sun6i_isp_capture_enum_input, .vidioc_g_input = sun6i_isp_capture_g_input, .vidioc_s_input = sun6i_isp_capture_s_input,
Signature · 1 line
2.39.2
Re: [PATCH 9/9] media: sun6i-isp: capture: Implement enum_framesizes
Dne petek, 24. marec 2023 ob 16:12:28 CET je Paul Kocialkowski napisal(a):
Quoted 6 lines
Report available frame sizes as a continuous range between the hardware min/max limits.
Signed-off-by Paul Kocialkowski <[email protected]>Co-authored-by Adam Pigg <[email protected]>Signed-off-by Adam Pigg <[email protected]>
Best regards,
Jernej