Extend RAW format support for rzg2l-cru driver
Subsystems (2)
v4 cover Extend RAW format support for rzg2l-cru driver
Hi All
This series adds new pixel formats representing the 64-bit packed format that's used by the Camera Receiver Unit in RZ/G2L and V2H SoCs. Support for capturing those formats is then added to the rzg2l-cru driver itself.
Thanks
Dan
v3: https://lore.kernel.org/linux-media/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/T/
v1: https://lore.kernel.org/all/[email protected]/T/
Daniel Scally (6):
media: v4l2: Add Renesas Camera Receiver Unit pixel formats
media: rzg2l-cru: Add vidioc_enum_framesizes()
media: platform: rzg2l-cru: Use v4l2_get_link_freq()
media: platform: rzg2l-cru: Use v4l2_fill_pixfmt()
media: rzg2l-cru: Support multiple mbus codes per pixel format
media: platform: rzg2l-cru: Add support for RAW10/12/14 data
.../userspace-api/media/v4l/pixfmt-bayer.rst | 1 + .../media/v4l/pixfmt-rawnn-cru.rst | 143 ++++++++++++++++++ .../platform/renesas/rzg2l-cru/rzg2l-cru.h | 10 +- .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 39 +++-- .../platform/renesas/rzg2l-cru/rzg2l-ip.c | 108 ++++++++++--- .../platform/renesas/rzg2l-cru/rzg2l-video.c | 40 +++-- drivers/media/v4l2-core/v4l2-common.c | 4 + drivers/media/v4l2-core/v4l2-ioctl.c | 4 + include/uapi/linux/videodev2.h | 6 + 9 files changed, 308 insertions(+), 47 deletions(-) create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
Signature · 1 line
2.34.1
PATCH v4 1/6 media: v4l2: Add Renesas Camera Receiver Unit pixel formats
From: Daniel Scally <[email protected]>
The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW data captured from an image sensor without conversion to an RGB/YUV format. In that case the data are packed into 64-bit blocks, with a variable amount of padding in the most significant bits depending on the bitdepth of the data. Add new V4L2 pixel format codes for the new formats, along with documentation to describe them.
---
Changes in v4:
- Removed references to "Bayer" or "srgb"
Changes in v3:
- Switched from bayer-order specific formats to generic RAWnn
Changes in v2:
- Added labels to the new formats in the documentation file
- Added 20-bit formats
.../userspace-api/media/v4l/pixfmt-bayer.rst | 1 + .../media/v4l/pixfmt-rawnn-cru.rst | 143 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-common.c | 4 + drivers/media/v4l2-core/v4l2-ioctl.c | 4 + include/uapi/linux/videodev2.h | 6 + 5 files changed, 158 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
Documentation/userspace-api/media/v4l/pixfmt-bayer.rst +1 -0
@@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter pixfmt-srggb14 pixfmt-srggb14p pixfmt-srggb16 + pixfmt-rawnn-cru
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +143 -0
143 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-common.c +4 -0
@@ -332,10 +332,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_SGBRG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGRBG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SRGGB10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW10, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SBGGR12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGBRG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW14, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW20, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, }; unsigned int i;
drivers/media/v4l2-core/v4l2-ioctl.c +4 -0
@@ -1413,6 +1413,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG10DPCM8 : descr ="8-bit Bayer GBGB/RGRG (DPCM)" ;break ;case V4L2_PIX_FMT_SGRBG10DPCM8 : descr ="8-bit Bayer GRGR/BGBG (DPCM)" ;break ;case V4L2_PIX_FMT_SRGGB10DPCM8 : descr ="8-bit Bayer RGRG/GBGB (DPCM)" ;break ; +case V4L2_PIX_FMT_CRU_RAW10 : descr ="10-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR12 : descr ="12-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG12 : descr ="12-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG12 : descr ="12-bit Bayer GRGR/BGBG" ;break ;
@@ -1421,6 +1422,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG12P : descr ="12-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG12P : descr ="12-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB12P : descr ="12-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW12 : descr ="12-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR14 : descr ="14-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG14 : descr ="14-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG14 : descr ="14-bit Bayer GRGR/BGBG" ;break ;
@@ -1429,10 +1431,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG14P : descr ="14-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG14P : descr ="14-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB14P : descr ="14-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW14 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR16 : descr ="16-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG16 : descr ="16-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG16 : descr ="16-bit Bayer GRGR/BGBG" ;break ;case V4L2_PIX_FMT_SRGGB16 : descr ="16-bit Bayer RGRG/GBGB" ;break ; +case V4L2_PIX_FMT_CRU_RAW20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;case V4L2_PIX_FMT_SPCA505 : descr ="GSPCA SPCA505" ;break ;
include/uapi/linux/videodev2.h +6 -0
@@ -840,6 +840,12 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B')/* PiSP 8-bit mode 2 compressed BGGR bayer */ #define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M')/* PiSP 8-bit mode 2 compressed monochrome */ +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */ +#define V4L2_PIX_FMT_CRU_RAW10 v4l2_fourcc('C', 'R', '1', '0') +#define V4L2_PIX_FMT_CRU_RAW12 v4l2_fourcc('C', 'R', '1', '2') +#define V4L2_PIX_FMT_CRU_RAW14 v4l2_fourcc('C', 'R', '1', '4') +#define V4L2_PIX_FMT_CRU_RAW20 v4l2_fourcc('C', 'R', '2', '0') +/* SDR formats - used only for Software Defined Radio devices */ #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8')/* IQ u8 */ #define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6')/* IQ u16le */
Signature · 1 line
2.34.1
Re: [PATCH v4 1/6] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
Hi Daniel,
Thanks for the set.
Quoted 59 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW data captured from an image sensor without conversion to an RGB/YUV format. In that case the data are packed into 64-bit blocks, with a variable amount of padding in the most significant bits depending on the bitdepth of the data. Add new V4L2 pixel format codes for the new formats, along with documentation to describe them.
Reviewed-by Lad Prabhakar <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Removed references to "Bayer" or "srgb"
Changes in v3:
- Switched from bayer-order specific formats to generic RAWnn
Changes in v2:
- Added labels to the new formats in the documentation file
- Added 20-bit formats.../userspace-api/media/v4l/pixfmt-bayer.rst | 1 + .../media/v4l/pixfmt-rawnn-cru.rst | 143 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-common.c | 4 + drivers/media/v4l2-core/v4l2-ioctl.c | 4 + include/uapi/linux/videodev2.h | 6 + 5 files changed, 158 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rstDocumentation/userspace-api/media/v4l/pixfmt-bayer.rst +1
-0@@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter pixfmt-srggb14 pixfmt-srggb14p pixfmt-srggb16 + pixfmt-rawnn-cruDocumentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +9
-0@@ -0,0 +1,143 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _v4l2-pix-fmt-cru-raw10: +.. _v4l2-pix-fmt-cru-raw12: +.. _v4l2-pix-fmt-cru-raw14: +.. _v4l2-pix-fmt-cru-raw20: + +********************************************************************************************************************************** +V4L2_PIX_FMT_CRU_RAW10 ('CR10'), V4L2_PIX_FMT_CRU_RAW12 ('CR12'), V4L2_PIX_FMT_CRU_RAW14 ('CR14'), V4L2_PIX_FMT_CRU_RAW20 ('CR20')
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst line 19
Quoted 10 lines
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +10
-0+********************************************************************************************************************************** + +=============================================================== +Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats +=============================================================== + +| V4L2_PIX_FMT_CRU_RAW10 (CR10) +| V4L2_PIX_FMT_CRU_RAW12 (CR12) +| V4L2_PIX_FMT_CRU_RAW14 (CR14) +| V4L2_PIX_FMT_CRU_RAW20 (CR20)
Could these be called V4L2_PIX_FMT_GENERIC_CRU_RAW*, to align with V4L2_PIX_FMT_GENERIC_CSI2_RAW*?
Quoted 130 lines
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +124
-0+ +Description +=========== + +These pixel formats are some of the RAW outputs for the Camera Receiver Unit in +the Renesas RZ/V2H SoC. They are raw formats which pack pixels contiguously into +64-bit units, with the 4 or 8 most significant bits padded. + +**Byte Order** + +.. flat-table:: RAW formats + :header-rows: 2 + :stub-columns: 0 + :widths: 36 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + :fill-cells: + + * - :rspan:`1` Pixel Format Code + - :cspan:`63` Data organization + * - 63 + - 62 + - 61 + - 60 + - 59 + - 58 + - 57 + - 56 + - 55 + - 54 + - 53 + - 52 + - 51 + - 50 + - 49 + - 48 + - 47 + - 46 + - 45 + - 44 + - 43 + - 42 + - 41 + - 40 + - 39 + - 38 + - 37 + - 36 + - 35 + - 34 + - 33 + - 32 + - 31 + - 30 + - 29 + - 28 + - 27 + - 26 + - 25 + - 24 + - 23 + - 22 + - 21 + - 20 + - 19 + - 18 + - 17 + - 16 + - 15 + - 14 + - 13 + - 12 + - 11 + - 10 + - 9 + - 8 + - 7 + - 6 + - 5 + - 4 + - 3 + - 2 + - 1 + - 0 + * - V4L2_PIX_FMT_CRU_RAW10 + - 0 + - 0 + - 0 + - 0 + - :cspan:`9` P5 + - :cspan:`9` P4 + - :cspan:`9` P3 + - :cspan:`9` P2 + - :cspan:`9` P1 + - :cspan:`9` P0 + * - V4L2_PIX_FMT_CRU_RAW12 + - 0 + - 0 + - 0 + - 0 + - :cspan:`11` P4 + - :cspan:`11` P3 + - :cspan:`11` P2 + - :cspan:`11` P1 + - :cspan:`11` P0 + * - V4L2_PIX_FMT_CRU_RAW14 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - :cspan:`13` P3 + - :cspan:`13` P2 + - :cspan:`13` P1 + - :cspan:`13` P0 + * - V4L2_PIX_FMT_CRU_RAW20 + - 0 + - 0 + - 0 + - 0 + - :cspan:`19` P2 + - :cspan:`19` P1 + - :cspan:`19` P0drivers/media/v4l2-core/v4l2-common.c +0
-0@@ -332,10 +332,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_SGBRG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 342
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +4
-0{ .format = V4L2_PIX_FMT_SGRBG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SRGGB10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW10, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SBGGR12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGBRG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW14, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW20, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
I'd add a new section for these. The generic CSI-2 formats are actually missing there, it'd be nice to add them first. I can post a patch.
Quoted 53 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0};unsigned int i;drivers/media/v4l2-core/v4l2-ioctl.c +4
-0@@ -1413,6 +1413,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG10DPCM8 : descr ="8-bit Bayer GBGB/RGRG (DPCM)" ;break ;case V4L2_PIX_FMT_SGRBG10DPCM8 : descr ="8-bit Bayer GRGR/BGBG (DPCM)" ;break ;case V4L2_PIX_FMT_SRGGB10DPCM8 : descr ="8-bit Bayer RGRG/GBGB (DPCM)" ;break ; +case V4L2_PIX_FMT_CRU_RAW10 : descr ="10-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR12 : descr ="12-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG12 : descr ="12-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG12 : descr ="12-bit Bayer GRGR/BGBG" ;break ;@@ -1421,6 +1422,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG12P : descr ="12-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG12P : descr ="12-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB12P : descr ="12-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW12 : descr ="12-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR14 : descr ="14-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG14 : descr ="14-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG14 : descr ="14-bit Bayer GRGR/BGBG" ;break ;@@ -1429,10 +1431,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG14P : descr ="14-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG14P : descr ="14-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB14P : descr ="14-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW14 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR16 : descr ="16-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG16 : descr ="16-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG16 : descr ="16-bit Bayer GRGR/BGBG" ;break ;case V4L2_PIX_FMT_SRGGB16 : descr ="16-bit Bayer RGRG/GBGB" ;break ; +case V4L2_PIX_FMT_CRU_RAW20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;case V4L2_PIX_FMT_SPCA505 : descr ="GSPCA SPCA505" ;break ;include/uapi/linux/videodev2.h +6
-0@@ -840,6 +840,12 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B')/* PiSP 8-bit mode 2 compressed BGGR bayer */ #define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M')/* PiSP 8-bit mode 2 compressed monochrome */ +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */ +#define V4L2_PIX_FMT_CRU_RAW10 v4l2_fourcc('C', 'R', '1', '0') +#define V4L2_PIX_FMT_CRU_RAW12 v4l2_fourcc('C', 'R', '1', '2') +#define V4L2_PIX_FMT_CRU_RAW14 v4l2_fourcc('C', 'R', '1', '4') +#define V4L2_PIX_FMT_CRU_RAW20 v4l2_fourcc('C', 'R', '2', '0') +/* SDR formats - used only for Software Defined Radio devices */ #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8')/* IQ u8 */ #define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6')/* IQ u16le */
Signature · 3 lines
Regards, Sakari Ailus
Jacopo Mondi
maintainerRe: [PATCH v4 1/6] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
Hi Sakari
Quoted 69 lines · Sakari Ailus
Hi Daniel,
Thanks for the set.
Quoted 64 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW data captured from an image sensor without conversion to an RGB/YUV format. In that case the data are packed into 64-bit blocks, with a variable amount of padding in the most significant bits depending on the bitdepth of the data. Add new V4L2 pixel format codes for the new formats, along with documentation to describe them.
Reviewed-by Lad Prabhakar <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Jacopo Mondi <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Removed references to "Bayer" or "srgb"
Changes in v3:
- Switched from bayer-order specific formats to generic RAWnn
Changes in v2:
- Added labels to the new formats in the documentation file
- Added 20-bit formats.../userspace-api/media/v4l/pixfmt-bayer.rst | 1 + .../media/v4l/pixfmt-rawnn-cru.rst | 143 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-common.c | 4 + drivers/media/v4l2-core/v4l2-ioctl.c | 4 + include/uapi/linux/videodev2.h | 6 + 5 files changed, 158 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rstDocumentation/userspace-api/media/v4l/pixfmt-bayer.rst +1
-0@@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter pixfmt-srggb14 pixfmt-srggb14p pixfmt-srggb16 + pixfmt-rawnn-cruDocumentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +14
-0@@ -0,0 +1,143 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _v4l2-pix-fmt-cru-raw10: +.. _v4l2-pix-fmt-cru-raw12: +.. _v4l2-pix-fmt-cru-raw14: +.. _v4l2-pix-fmt-cru-raw20: + +********************************************************************************************************************************** +V4L2_PIX_FMT_CRU_RAW10 ('CR10'), V4L2_PIX_FMT_CRU_RAW12 ('CR12'), V4L2_PIX_FMT_CRU_RAW14 ('CR14'), V4L2_PIX_FMT_CRU_RAW20 ('CR20') +********************************************************************************************************************************** + +=============================================================== +Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats +===============================================================
Quoted 8 lines
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst line 19
Quoted 5 lines
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +5
-0+ +| V4L2_PIX_FMT_CRU_RAW10 (CR10) +| V4L2_PIX_FMT_CRU_RAW12 (CR12) +| V4L2_PIX_FMT_CRU_RAW14 (CR14) +| V4L2_PIX_FMT_CRU_RAW20 (CR20)Could these be called V4L2_PIX_FMT_GENERIC_CRU_RAW*, to align with V4L2_PIX_FMT_GENERIC_CSI2_RAW*?
Is this a good idea ? I understand the CSI2 ones are "generic" when it comes to both the Bayer pattern ordering and the platform.
The CRU codes are platforms specific, and while they're Bayer order agnostic, calling them generic feels a bit of an overstretch ?
Quoted 203 lines
Quoted 131 lines
Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst new file +124
-0+ +Description +=========== + +These pixel formats are some of the RAW outputs for the Camera Receiver Unit in +the Renesas RZ/V2H SoC. They are raw formats which pack pixels contiguously into +64-bit units, with the 4 or 8 most significant bits padded. + +**Byte Order** + +.. flat-table:: RAW formats + :header-rows: 2 + :stub-columns: 0 + :widths: 36 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 + :fill-cells: + + * - :rspan:`1` Pixel Format Code + - :cspan:`63` Data organization + * - 63 + - 62 + - 61 + - 60 + - 59 + - 58 + - 57 + - 56 + - 55 + - 54 + - 53 + - 52 + - 51 + - 50 + - 49 + - 48 + - 47 + - 46 + - 45 + - 44 + - 43 + - 42 + - 41 + - 40 + - 39 + - 38 + - 37 + - 36 + - 35 + - 34 + - 33 + - 32 + - 31 + - 30 + - 29 + - 28 + - 27 + - 26 + - 25 + - 24 + - 23 + - 22 + - 21 + - 20 + - 19 + - 18 + - 17 + - 16 + - 15 + - 14 + - 13 + - 12 + - 11 + - 10 + - 9 + - 8 + - 7 + - 6 + - 5 + - 4 + - 3 + - 2 + - 1 + - 0 + * - V4L2_PIX_FMT_CRU_RAW10 + - 0 + - 0 + - 0 + - 0 + - :cspan:`9` P5 + - :cspan:`9` P4 + - :cspan:`9` P3 + - :cspan:`9` P2 + - :cspan:`9` P1 + - :cspan:`9` P0 + * - V4L2_PIX_FMT_CRU_RAW12 + - 0 + - 0 + - 0 + - 0 + - :cspan:`11` P4 + - :cspan:`11` P3 + - :cspan:`11` P2 + - :cspan:`11` P1 + - :cspan:`11` P0 + * - V4L2_PIX_FMT_CRU_RAW14 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + - :cspan:`13` P3 + - :cspan:`13` P2 + - :cspan:`13` P1 + - :cspan:`13` P0 + * - V4L2_PIX_FMT_CRU_RAW20 + - 0 + - 0 + - 0 + - 0 + - :cspan:`19` P2 + - :cspan:`19` P1 + - :cspan:`19` P0drivers/media/v4l2-core/v4l2-common.c +0
-0@@ -332,10 +332,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_SGBRG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },drivers/media/v4l2-core/v4l2-common.c const struct v4l2_format_info *v4l2_format_info(u32 format) · line 342
Quoted 10 lines
drivers/media/v4l2-core/v4l2-common.c +4
-0{ .format = V4L2_PIX_FMT_SGRBG10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SRGGB10DPCM8, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW10, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SBGGR12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_SGBRG12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .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 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW12, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW14, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_CRU_RAW20, .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },I'd add a new section for these. The generic CSI-2 formats are actually missing there, it'd be nice to add them first. I can post a patch.
Quoted 43 lines
drivers/media/v4l2-core/v4l2-common.c +0
-0};unsigned int i;drivers/media/v4l2-core/v4l2-ioctl.c +4
-0@@ -1413,6 +1413,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG10DPCM8 : descr ="8-bit Bayer GBGB/RGRG (DPCM)" ;break ;case V4L2_PIX_FMT_SGRBG10DPCM8 : descr ="8-bit Bayer GRGR/BGBG (DPCM)" ;break ;case V4L2_PIX_FMT_SRGGB10DPCM8 : descr ="8-bit Bayer RGRG/GBGB (DPCM)" ;break ; +case V4L2_PIX_FMT_CRU_RAW10 : descr ="10-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR12 : descr ="12-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG12 : descr ="12-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG12 : descr ="12-bit Bayer GRGR/BGBG" ;break ;@@ -1421,6 +1422,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG12P : descr ="12-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG12P : descr ="12-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB12P : descr ="12-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW12 : descr ="12-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR14 : descr ="14-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG14 : descr ="14-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG14 : descr ="14-bit Bayer GRGR/BGBG" ;break ;@@ -1429,10 +1431,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_SGBRG14P : descr ="14-bit Bayer GBGB/RGRG Packed" ;break ;case V4L2_PIX_FMT_SGRBG14P : descr ="14-bit Bayer GRGR/BGBG Packed" ;break ;case V4L2_PIX_FMT_SRGGB14P : descr ="14-bit Bayer RGRG/GBGB Packed" ;break ; +case V4L2_PIX_FMT_CRU_RAW14 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SBGGR16 : descr ="16-bit Bayer BGBG/GRGR" ;break ;case V4L2_PIX_FMT_SGBRG16 : descr ="16-bit Bayer GBGB/RGRG" ;break ;case V4L2_PIX_FMT_SGRBG16 : descr ="16-bit Bayer GRGR/BGBG" ;break ;case V4L2_PIX_FMT_SRGGB16 : descr ="16-bit Bayer RGRG/GBGB" ;break ; +case V4L2_PIX_FMT_CRU_RAW20 : descr ="14-bit Raw CRU Packed" ;break ;case V4L2_PIX_FMT_SN9C20X_I420 : descr ="GSPCA SN9C20X I420" ;break ;case V4L2_PIX_FMT_SPCA501 : descr ="GSPCA SPCA501" ;break ;case V4L2_PIX_FMT_SPCA505 : descr ="GSPCA SPCA505" ;break ;include/uapi/linux/videodev2.h +0
-0@@ -840,6 +840,12 @@ struct v4l2_pix_format {#define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B')/* PiSP 8-bit mode 2 compressed BGGR bayer */ #define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M')/* PiSP 8-bit mode 2 compressed monochrome */ include/uapi/linux/videodev2.h struct v4l2_pix_format { · line 851
Quoted 10 lines
include/uapi/linux/videodev2.h +6
-0+/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */ +#define V4L2_PIX_FMT_CRU_RAW10 v4l2_fourcc('C', 'R', '1', '0') +#define V4L2_PIX_FMT_CRU_RAW12 v4l2_fourcc('C', 'R', '1', '2') +#define V4L2_PIX_FMT_CRU_RAW14 v4l2_fourcc('C', 'R', '1', '4') +#define V4L2_PIX_FMT_CRU_RAW20 v4l2_fourcc('C', 'R', '2', '0') +/* SDR formats - used only for Software Defined Radio devices */ #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8')/* IQ u8 */ #define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6')/* IQ u16le */ --
Regards,Sakari Ailus
Re: [PATCH v4 1/6] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
Hi Jacopo,
Quoted 5 lines · Jacopo Mondi
Quoted 5 lines
Quoted 4 lines
+| V4L2_PIX_FMT_CRU_RAW10 (CR10) +| V4L2_PIX_FMT_CRU_RAW12 (CR12) +| V4L2_PIX_FMT_CRU_RAW14 (CR14) +| V4L2_PIX_FMT_CRU_RAW20 (CR20)
Quoted 8 lines
Quoted 2 lines
Could these be called V4L2_PIX_FMT_GENERIC_CRU_RAW*, to align with V4L2_PIX_FMT_GENERIC_CSI2_RAW*?
Is this a good idea ? I understand the CSI2 ones are "generic" when it comes to both the Bayer pattern ordering and the platform.
The CRU codes are platforms specific, and while they're Bayer order agnostic, calling them generic feels a bit of an overstretch ?
I think I checked outdated patches -- in fact in the latest patchset such formats are called V4L2_PIX_FMT_RAW_CSI2_X, where X is the bit depth. So this question doesn't need to be answered. :-)
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH v4 1/6] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
Hi Sakari, thanks for the comments
Quoted 9 lines · Sakari Ailus
Hi Jacopo,
Quoted 6 lines · Jacopo Mondi
Quoted 6 lines
Quoted 4 lines
+| V4L2_PIX_FMT_CRU_RAW10 (CR10) +| V4L2_PIX_FMT_CRU_RAW12 (CR12) +| V4L2_PIX_FMT_CRU_RAW14 (CR14) +| V4L2_PIX_FMT_CRU_RAW20 (CR20)Could these be called V4L2_PIX_FMT_GENERIC_CRU_RAW*, to align with V4L2_PIX_FMT_GENERIC_CSI2_RAW*?
Quoted 9 lines
Quoted 5 lines
Is this a good idea ? I understand the CSI2 ones are "generic" when it comes to both the Bayer pattern ordering and the platform.
The CRU codes are platforms specific, and while they're Bayer order agnostic, calling them generic feels a bit of an overstretch ?
I think I checked outdated patches -- in fact in the latest patchset such formats are called
V4L2_PIX_FMT_RAW_CSI2_X, where X is the bit depth. So this question doesn't need to be answered. :-)
Done :) But I'll move the formats to a new section in v4l2_format_info() indeed.
PATCH v4 2/6 media: rzg2l-cru: Add vidioc_enum_framesizes()
In reply to Daniel ScallyFrom: Daniel Scally <[email protected]>
Add a callback to fill VIDIOC_ENUM_FRAMESIZES ioctl for the CRU
---
Changes in v4:
- New patch
.../platform/renesas/rzg2l-cru/rzg2l-video.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +28 -0
@@ -1031,7 +1031,33 @@ static int rzg2l_cru_enum_fmt_vid_cap(struct file *file, void *priv,return 0 ; } +static int rzg2l_cru_enum_framesizes (struct file *file,void *fh, +struct v4l2_frmsizeenum *fsize) +{ +struct rzg2l_cru_dev *cru =video_drvdata (file); +const struct rzg2l_cru_info *info = cru->info; +const struct rzg2l_cru_ip_format *fmt; + +if (fsize->index) +return -EINVAL ; + + fmt =rzg2l_cru_ip_format_to_fmt (fsize->pixel_format); +if (!fmt) +return -EINVAL ; + + fsize->type =V4L2_FRMIVAL_TYPE_CONTINUOUS ; + fsize->stepwise.min_width =RZG2L_CRU_MIN_INPUT_WIDTH ; + fsize->stepwise.max_width = info->max_width; + fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height =RZG2L_CRU_MIN_INPUT_HEIGHT ; + fsize->stepwise.max_height = info->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} +static const struct v4l2_ioctl_ops rzg2l_cru_ioctl_ops = { + .vidioc_querycap = rzg2l_cru_querycap, .vidioc_try_fmt_vid_cap = rzg2l_cru_try_fmt_vid_cap, .vidioc_g_fmt_vid_cap = rzg2l_cru_g_fmt_vid_cap,
@@ -1047,6 +1073,8 @@ static const struct v4l2_ioctl_ops rzg2l_cru_ioctl_ops = { .vidioc_prepare_buf = vb2_ioctl_prepare_buf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, + + .vidioc_enum_framesizes = rzg2l_cru_enum_framesizes, };/* -----------------------------------------------------------------------------
Signature · 1 line
2.34.1
Re: [PATCH v4 2/6] media: rzg2l-cru: Add vidioc_enum_framesizes()
Hi Dan,
Thank you for the patch.
Quoted 3 lines · Daniel Scally
From: Daniel Scally <[email protected]>
Add a callback to fill
VIDIOC_ENUM_FRAMESIZESioctl for the CRU
s/CRU/CRU./
And did you mean "implement the" instead of "fill" ?
Quoted 34 lines
Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- New patch
.../platform/renesas/rzg2l-cru/rzg2l-video.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +17
-0@@ -1031,7 +1031,33 @@ static int rzg2l_cru_enum_fmt_vid_cap(struct file *file, void *priv,return 0 ; } +static int rzg2l_cru_enum_framesizes (struct file *file,void *fh, +struct v4l2_frmsizeenum *fsize) +{ +struct rzg2l_cru_dev *cru =video_drvdata (file); +const struct rzg2l_cru_info *info = cru->info; +const struct rzg2l_cru_ip_format *fmt; + +if (fsize->index) +return -EINVAL ; + + fmt =rzg2l_cru_ip_format_to_fmt (fsize->pixel_format); +if (!fmt) +return -EINVAL ; + + fsize->type =V4L2_FRMIVAL_TYPE_CONTINUOUS ; + fsize->stepwise.min_width =RZG2L_CRU_MIN_INPUT_WIDTH ; + fsize->stepwise.max_width = info->max_width;
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c static int rzg2l_cru_enum_fmt_vid_cap(struct file *file, void *priv, · line 1060
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +9
-0+ fsize->stepwise.step_width =1 ; + fsize->stepwise.min_height =RZG2L_CRU_MIN_INPUT_HEIGHT ; + fsize->stepwise.max_height = info->max_height; + fsize->stepwise.step_height =1 ; + +return 0 ; +} +static const struct v4l2_ioctl_ops rzg2l_cru_ioctl_ops = { +
Stray blank line.
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c static const struct v4l2_ioctl_ops rzg2l_cru_ioctl_ops = { · line 1076
Quoted 8 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +1
-0.vidioc_querycap = rzg2l_cru_querycap, .vidioc_try_fmt_vid_cap = rzg2l_cru_try_fmt_vid_cap, .vidioc_g_fmt_vid_cap = rzg2l_cru_g_fmt_vid_cap,@@ -1047,6 +1073,8 @@ static const struct v4l2_ioctl_ops rzg2l_cru_ioctl_ops = { .vidioc_prepare_buf = vb2_ioctl_prepare_buf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, +
And here too. With that addressed,
Quoted 4 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +1
-0+ .vidioc_enum_framesizes = rzg2l_cru_enum_framesizes, };/* -----------------------------------------------------------------------------
Signature · 3 lines
Regards, Laurent Pinchart
PATCH v4 3/6 media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Daniel ScallyFrom: Daniel Scally <[email protected]>
The rzg2l_csi2_calc_mbps() function currently tries to calculate the link frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control of the remote subdevice. Switch the function to v4l2_get_link_freq() which correctly targets V4L2_CID_LINK_FREQ before falling back on V4L2_CID_PIXEL_RATE if the former is unavailable.
---
Changes in v4:
- Used separate s64 variable as return value for v4l2_get_link_freq() and as the mbps variable for do_div() to avoid compilation warnings.
Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +12 -15
@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }
Signature · 1 line
2.34.1
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Daniel,
Thanks for your patch.
Quoted 65 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +5
-15@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) {
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +7
-0+dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }
I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Some notes:
- pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample
- hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
Then hsfreq should be:
- hsfreq = link_freq * 2
Please correct me if I'm wrong.
After applying this series. I'm getting the following issue testing the imx219 sensor with SRGGB8_1X8 and SGRBG10_1X10 color format.
[ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range)
I'm suspecting that this could be related to this formula. Let me know what do you think.
Thanks in advance!
Tested using:
root@smarc-rzg3e:~# media-ctl -p Media controller API version 6.15.0
Media device information
------------------------
driver rzg2l_cru
model renesas,r9a09g047-cru
serial
bus info platform:16000000.video hw revision 0x0 driver version 6.15.0
Device topology
- entity 1: csi-16000400.csi2 (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0
device node name /dev/v4l-subdev0
pad0: Sink
[stream:0 fmt:SGRBG10_1X10/640x480 field:none]
<- "imx219 0-0010":0 [ENABLED,IMMUTABLE]
pad1: Source
[stream:0 fmt:SGRBG10_1X10/640x480 field:none]
-> "cru-ip-16000000.video":0 [ENABLED,IMMUTABLE]- entity 4: cru-ip-16000000.video (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0
device node name /dev/v4l-subdev1
pad0: Sink
[stream:0 fmt:SGRBG10_1X10/640x480 field:none]
<- "csi-16000400.csi2":1 [ENABLED,IMMUTABLE]
pad1: Source
[stream:0 fmt:SGRBG10_1X10/640x480 field:none]
-> "CRU output":0 [ENABLED,IMMUTABLE]- entity 7: imx219 0-0010 (1 pad, 1 link, 0 routes)
type V4L2 subdev subtype Sensor flags 0
device node name /dev/v4l-subdev2
pad0: Source
[stream:0 fmt:SGRBG10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range
crop.bounds:(8,8)/3280x2464
crop:(1008,760)/1280x960]
-> "csi-16000400.csi2":0 [ENABLED,IMMUTABLE]- entity 17: CRU output (1 pad, 1 link)
type Node subtype V4L flags 0
device node name /dev/video0
pad0: Sink
<- "cru-ip-16000000.video":1 [ENABLED,IMMUTABLE]
# IMX219 TESTING SGRBG10_1X10
v4l2-ctl -c horizontal_flip=1 -d /dev/v4l-subdev2
media-ctl -d /dev/media0 --set-v4l2 '"imx219 0-0010":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d /dev/media0 --set-v4l2 '"csi-16000400.csi2":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d /dev/media0 --set-v4l2 '"cru-ip-16000000.video":0[fmt:SGRBG10_1X10/640x480]'
v4l2-ctl -d0 --set-fmt-video pixelformat=CR10,width=640,height=480 v4l2-ctl -d0 --stream-mmap --stream-count=100
# IMX219 TESTING SRGGB8_1X8
media-ctl -d /dev/media0 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d /dev/media0 --set-v4l2 '"csi-16000400.csi2":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d /dev/media0 --set-v4l2 '"cru-ip-16000000.video":0[fmt:SRGGB8_1X8/1920x1080]'
v4l2-ctl -d0 --set-fmt-video pixelformat=RGGB,width=1920,height=1080 v4l2-ctl -d0 --stream-mmap --stream-count=32
Thanks & Regards,
Tommaso
Quoted 3 lines
Signature · 1 line
2.34.1
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
+cc linux-renesas-soc
Quoted 187 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 65 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +5
-15@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) {drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +7
-0+dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
- hsfreq =
link_freq* 2Please correct me if I'm wrong.
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.[ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range)I'm suspecting that this could be related to this formula. Let me know what do you think.
Thanks in advance!
Tested using:
root@smarc-rzg3e:~# media-ctl -p Media controller API version 6.15.0Media device information
------------------------
driverrzg2l_cru
model renesas,r9a09g047-cru
serialbus info platform:16000000.video hw revision 0x0 driver version 6.15.0Device topology
- entity 1: csi-16000400.csi2 (2 pads, 2 links, 0 routes)type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev0 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "imx219 0-0010":0 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "cru-ip-16000000.video":0 [ENABLED,IMMUTABLE]- entity 4: cru-ip-16000000.video (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev1 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "csi-16000400.csi2":1 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "CRU output":0 [ENABLED,IMMUTABLE]- entity 7: imx219 0-0010 (1 pad, 1 link, 0 routes)
type V4L2 subdev subtype Sensor flags 0 device node name /dev/v4l-subdev2 pad0: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range crop.bounds:(8,8)/3280x2464 crop:(1008,760)/1280x960] -> "csi-16000400.csi2":0 [ENABLED,IMMUTABLE]- entity 17: CRU output (1 pad, 1 link)
type Node subtype V4L flags 0
device node name/dev/video0
pad0: Sink
<- "cru-ip-16000000.video":1 [ENABLED,IMMUTABLE]# IMX219 TESTING
SGRBG10_1X10
v4l2-ctl -c horizontal_flip=1 -d/dev/v4l-subdev2media-ctl -d
/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SGRBG10_1X10/640x480]'v4l2-ctl -d0 --set-fmt-video pixelformat=CR10,width=640,height=480 v4l2-ctl -d0 --stream-mmap --stream-count=100
# IMX219 TESTING
SRGGB8_1X8
media-ctl -d/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SRGGB8_1X8/1920x1080]'v4l2-ctl -d0 --set-fmt-video pixelformat=RGGB,width=1920,height=1080 v4l2-ctl -d0 --stream-mmap --stream-count=32
Thanks & Regards,
TommasoQuoted 3 lines
Signature · 1 line
2.34.1
Jacopo Mondi
maintainerRe: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Tommaso MerciaiHi Tommaso
Quoted 83 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 65 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +5
-15@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) {drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +7
-0+dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
And not the per-lane frequency as the variable name and the commit message suggest
Quoted 2 lines
- hsfreq =
link_freq* 2
if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
Dan, did you ever notice issues during your testing ?
Also, with the introduction of 15f0035bfd0a ("media: v4l: Support passing media pad argument to v4l2_get_link_freq()") it's probably now better to pass the source's pad to v4l2_get_link_freq() ?
Quoted 6 lines
Please correct me if I'm wrong.
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.
Does the error go away if you multiply the link_freq by 2 ?
Thanks
j
Quoted 89 lines
[ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range)I'm suspecting that this could be related to this formula. Let me know what do you think.
Thanks in advance!
Tested using:
root@smarc-rzg3e:~# media-ctl -p Media controller API version 6.15.0Media device information
------------------------
driverrzg2l_cru
model renesas,r9a09g047-cru
serialbus info platform:16000000.video hw revision 0x0 driver version 6.15.0Device topology
- entity 1: csi-16000400.csi2 (2 pads, 2 links, 0 routes)type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev0 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "imx219 0-0010":0 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "cru-ip-16000000.video":0 [ENABLED,IMMUTABLE]- entity 4: cru-ip-16000000.video (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev1 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "csi-16000400.csi2":1 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "CRU output":0 [ENABLED,IMMUTABLE]- entity 7: imx219 0-0010 (1 pad, 1 link, 0 routes)
type V4L2 subdev subtype Sensor flags 0 device node name /dev/v4l-subdev2 pad0: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range crop.bounds:(8,8)/3280x2464 crop:(1008,760)/1280x960] -> "csi-16000400.csi2":0 [ENABLED,IMMUTABLE]- entity 17: CRU output (1 pad, 1 link)
type Node subtype V4L flags 0
device node name/dev/video0
pad0: Sink
<- "cru-ip-16000000.video":1 [ENABLED,IMMUTABLE]# IMX219 TESTING
SGRBG10_1X10
v4l2-ctl -c horizontal_flip=1 -d/dev/v4l-subdev2media-ctl -d
/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SGRBG10_1X10/640x480]'v4l2-ctl -d0 --set-fmt-video pixelformat=CR10,width=640,height=480 v4l2-ctl -d0 --stream-mmap --stream-count=100
# IMX219 TESTING
SRGGB8_1X8
media-ctl -d/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SRGGB8_1X8/1920x1080]'v4l2-ctl -d0 --set-fmt-video pixelformat=RGGB,width=1920,height=1080 v4l2-ctl -d0 --stream-mmap --stream-count=32
Thanks & Regards,
TommasoQuoted 3 lines
--
2.34.1
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Jacopo,
Thanks for your comment.
Quoted 116 lines · Jacopo Mondi
Hi Tommaso
Quoted 83 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 65 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +5
-15@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) {drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +7
-0+dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +0
-1-* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes And not the per-lane frequency as the variable name and the commit message suggest
Quoted 2 lines
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Please correct me if I'm wrong.
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?
Yes the error goes away on my side using:
mbps = ret * 2;
Tested with imx219 image sensor: SRGGB8_1X8 and SGRBG10_1X10 color format.
Thanks & Regards,
Tommaso
Quoted 93 lines
Thanks
jQuoted 89 lines
[ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range)I'm suspecting that this could be related to this formula. Let me know what do you think.
Thanks in advance!
Tested using:
root@smarc-rzg3e:~# media-ctl -p Media controller API version 6.15.0Media device information
------------------------
driverrzg2l_cru
model renesas,r9a09g047-cru
serialbus info platform:16000000.video hw revision 0x0 driver version 6.15.0Device topology
- entity 1: csi-16000400.csi2 (2 pads, 2 links, 0 routes)type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev0 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "imx219 0-0010":0 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "cru-ip-16000000.video":0 [ENABLED,IMMUTABLE]- entity 4: cru-ip-16000000.video (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev1 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "csi-16000400.csi2":1 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "CRU output":0 [ENABLED,IMMUTABLE]- entity 7: imx219 0-0010 (1 pad, 1 link, 0 routes)
type V4L2 subdev subtype Sensor flags 0 device node name /dev/v4l-subdev2 pad0: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range crop.bounds:(8,8)/3280x2464 crop:(1008,760)/1280x960] -> "csi-16000400.csi2":0 [ENABLED,IMMUTABLE]- entity 17: CRU output (1 pad, 1 link)
type Node subtype V4L flags 0
device node name/dev/video0
pad0: Sink
<- "cru-ip-16000000.video":1 [ENABLED,IMMUTABLE]# IMX219 TESTING
SGRBG10_1X10
v4l2-ctl -c horizontal_flip=1 -d/dev/v4l-subdev2media-ctl -d
/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SGRBG10_1X10/640x480]'v4l2-ctl -d0 --set-fmt-video pixelformat=CR10,width=640,height=480 v4l2-ctl -d0 --stream-mmap --stream-count=100
# IMX219 TESTING
SRGGB8_1X8
media-ctl -d/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SRGGB8_1X8/1920x1080]'v4l2-ctl -d0 --set-fmt-video pixelformat=RGGB,width=1920,height=1080 v4l2-ctl -d0 --stream-mmap --stream-count=32
Thanks & Regards,
TommasoQuoted 3 lines
--
2.34.1
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Tommaso,
Quoted 67 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);
div needs to be updated in v4l2_get_link_freq() as below so that when subdev has only V4L2_CID_PIXEL_RATE we get the correct value.
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
- csi2->lanes);
+ csi2->lanes * 2);
Quoted 30 lines
Quoted 30 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 11 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use v4l2_get_link_freq().
Quoted 11 lines
Quoted 11 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 4 lines
Please correct me if I'm wrong.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi all - sorry for the late response, I was away last week.
Quoted 83 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
Review
Quoted 2 lines
(quoted diff) +1
-1- csi2->lanes); + csi2->lanes * 2);
Ack
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 12 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 1 line
- hsfreq =
link_freq* 2
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().
I'll send a new version with that extra patch, plus the change you mention above and Jacopo's point about passing the pad to v4l2_get_link_freq()
Good spot Tommaso!
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Lad, PrabhakarHi again
Quoted 132 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,(quoted diff) +1
-1- csi2->lanes); + csi2->lanes * 2);Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 12 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Actually, I'm missing something here. Tommaso, you're using an imx219? So V4L2_CID_LINK_FREQ should be 456000000 and V4L2_CID_PIXEL_RATE should be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Jacopo Mondi
maintainerRe: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Dan
Quoted 145 lines · Dan Scally
Hi again
Quoted 132 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,(quoted diff) +1
-1- csi2->lanes); + csi2->lanes * 2);Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 12 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Quoted 8 lines
Actually, I'm missing something here. Tommaso, you're using an imx219? So
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?
It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
- */
- mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp;
- do_div(mbps, csi2->lanes * 1000000);
The new code returns the link frequency instead
+ /* Read the link frequency from remote subdevice. */
+ ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
+ csi2->lanes);
+
+ mbps = ret;
+ do_div(mbps, 1000000);
Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
mbps = ret * 2;
if it uses
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);
Does it make sense ?
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 8 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Jacopo
Quoted 184 lines · Jacopo Mondi
Hi Dan
Quoted 144 lines · Dan Scally
Hi again
Quoted 132 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,(quoted diff) +1
-1- csi2->lanes); + csi2->lanes * 2);Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 12 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Quoted 8 lines
Actually, I'm missing something here. Tommaso, you're using an imx219? So
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
(quoted diff) +0
-6- /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000);The new code returns the link frequency instead
(quoted diff) +6
-0+ /* Read the link frequency from remote subdevice. */ + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes); + + mbps = ret; + do_div(mbps, 1000000);Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
Quoted 8 lines
mbps = ret * 2;if it uses
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);Does it make sense ?
That part makes sense - thank you - but then do we actually want a separate patch that "fixes" the original function to add the / 2, if the existing behaviour is what we want?
Quoted 15 lines
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 7 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Jacopo MondiHi Jacopo, Dan,
Thanks for your comments! :)
Quoted 149 lines · Jacopo Mondi
Hi Dan
Quoted 146 lines · Dan Scally
Hi again
Quoted 132 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None .../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,(quoted diff) +1
-1- csi2->lanes); + csi2->lanes * 2);Quoted 28 lines
Quoted 28 lines
Quoted 15 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 12 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Actually, I'm missing something here. Tommaso, you're using an imx219? So
Yes, tested with an imx219 image sensor.
Quoted 37 lines
Quoted 7 lines
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
(quoted diff) +0
-6- /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000);The new code returns the link frequency instead
(quoted diff) +6
-0+ /* Read the link frequency from remote subdevice. */ + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes); + + mbps = ret; + do_div(mbps, 1000000);Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
Quoted 8 lines
mbps = ret * 2;if it uses
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);Does it make sense ?
Thanks Jacopo. Agree.
Some formulas:
(please correct me if I'm wrong :) )
We have the following formula:
vclk * bpp = hsclk * 8 * lanes
hsclk(bit) = hsclk(byte) * 8 = hsfreq
Then:
- hsfreq = (vclk * bpp) / lanes
- hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
Formula for link_freq:
hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample
Rewriting the pixel_rate formula as:
(pixel_rate * bits_per_sample) / nr_of_lanes = link_freq * 2
Then:
hsfreq = link_freq * 2
---
Old code:
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
- */
- mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp;
- do_div(mbps, csi2->lanes * 1000000);
mbps = (182400000 * 10) / 2 = 912000000 --> 912000000 / 1000000 = 912
---
New code:
+ /* Read the link frequency from remote subdevice. */
+ ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
+ csi2->lanes);
+
+ mbps = ret;
+ do_div(mbps, 1000000);
mbps = (456000000 / 1000000) = 456 (I think is wrong missing *2 based on the formula)
Please let me know if I'm missing somenthing.
Thanks in advance.
Thanks & Regards,
Tommaso
Quoted 16 lines
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 8 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Quoted 252 lines · Tommaso Merciai
Hi Jacopo, Dan,
Thanks for your comments! :)Quoted 149 lines · Jacopo Mondi
Hi Dan
Quoted 146 lines · Dan Scally
Hi again
Quoted 132 lines · Prabhakar
Hi Tommaso,
Quoted 66 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 62 lines · Jacopo Mondi
Hi Tommaso
Quoted 59 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 55 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++----------
1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) const struct rzg2l_csi2_format *format; const struct v4l2_mbus_framefmt *fmt; struct v4l2_subdev_state *state; - struct v4l2_ctrl *ctrl; u64 mbps; - - /* Read the pixel rate control from remote. */ - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", - source->name); - return -EINVAL; - } + s64 ret; state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); format = rzg2l_csi2_code_to_fmt(fmt->code); v4l2_subdev_unlock_state(state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6- /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000); + /* Read the link frequency from remote subdevice. */ + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler,
format->bpp, -csi2->lanes);
+csi2->lanes* 2);Quoted 27 lines
Quoted 27 lines
Quoted 14 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 11 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+ if (ret < 0) { + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", + source->name); + return -EINVAL; + } + + mbps = ret; + do_div(mbps, 1000000); return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Actually, I'm missing something here. Tommaso, you're using an imx219? So
Yes, tested with an imx219 image sensor.
Quoted 37 lines
Quoted 7 lines
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);The new code returns the link frequency instead
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
Quoted 8 lines
mbps = ret * 2;
if it uses
ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);Does it make sense ?
Thanks Jacopo. Agree.
Some formulas:
(please correct me if I'm wrong :) )We have the following formula:
vclk * bpp = hsclk * 8 * lanes
hsclk(bit) = hsclk(byte) * 8 = hsfreqThen:
- hsfreq = (vclk * bpp) / lanes
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesFormula for
link_freq:hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanespixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sampleRewriting the
pixel_rateformula as:(
pixel_rate*bits_per_sample) /nr_of_lanes=link_freq* 2Then:
hsfreq =link_freq* 2
---Old code:
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);mbps = (182400000 * 10) / 2 = 912000000 --> 912000000 / 1000000 = 912
---New code:
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);
Quoted 3 lines
mbps = (456000000 / 1000000) = 456 (I think is wrong missing *2 based on the formula)
Please let me know if I'm missing somenthing.
That all makes sense to me yes. Perhaps I'm misunderstanding, but I thought one conclusion of the discussion was that we wanted a separate patch adding the missing / 2 so that it could be backported as a fix...is that not the case? If we just need to make sure the new behaviour matches the old then adding the * 2 to a v5 is fine.
Thanks
Dan
Quoted 22 lines
Thanks in advance.
Thanks & Regards,
TommasoQuoted 16 lines
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 8 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Jacopo Mondi
maintainerRe: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Dan
Quoted 258 lines · Dan Scally
Quoted 256 lines · Tommaso Merciai
Hi Jacopo, Dan,
Thanks for your comments! :)Quoted 151 lines · Jacopo Mondi
Hi Dan
Quoted 148 lines · Dan Scally
Hi again
Quoted 134 lines · Prabhakar
Hi Tommaso,
Quoted 68 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 64 lines · Jacopo Mondi
Hi Tommaso
Quoted 61 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 57 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++----------
1 file changed, 12 insertions(+), 15 deletions(-)diff --git
a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.cb/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.cindex9243306e2aa9..8870c2cb8104100644drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) const struct rzg2l_csi2_format *format; const struct v4l2_mbus_framefmt *fmt; struct v4l2_subdev_state *state; - struct v4l2_ctrl *ctrl; u64 mbps; - - /* Read the pixel rate control from remote. */ - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", - source->name); - return -EINVAL; - } + s64 ret; state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); format = rzg2l_csi2_code_to_fmt(fmt->code); v4l2_subdev_unlock_state(state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6- /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000); + /* Read the link frequency from remote subdevice. */ + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler,
format->bpp, -csi2->lanes);
+csi2->lanes* 2);Quoted 27 lines
Quoted 27 lines
Quoted 14 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 11 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+ if (ret < 0) { + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", + source->name); + return -EINVAL; + } + + mbps = ret; + do_div(mbps, 1000000); return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Actually, I'm missing something here. Tommaso, you're using an imx219? So
Yes, tested with an imx219 image sensor.
Quoted 37 lines
Quoted 7 lines
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);The new code returns the link frequency instead
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
Quoted 8 lines
mbps = ret * 2;
if it uses
ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);Does it make sense ?
Thanks Jacopo. Agree.
Some formulas:
(please correct me if I'm wrong :) )We have the following formula:
vclk * bpp = hsclk * 8 * lanes
hsclk(bit) = hsclk(byte) * 8 = hsfreqThen:
- hsfreq = (vclk * bpp) / lanes
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesFormula for
link_freq:hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanespixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sampleRewriting the
pixel_rateformula as:(
pixel_rate*bits_per_sample) /nr_of_lanes=link_freq* 2Then:
hsfreq =link_freq* 2
---Old code:
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);mbps = (182400000 * 10) / 2 = 912000000 --> 912000000 / 1000000 = 912
---New code:
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);mbps = (456000000 / 1000000) = 456 (I think is wrong missing *2 based on the formula)
Quoted 9 lines
Quoted 1 line
Please let me know if I'm missing somenthing.
That all makes sense to me yes. Perhaps I'm misunderstanding, but I thought one conclusion of the discussion was that we wanted a separate patch adding the missing / 2 so that it could be backported as a fix...is that not the case? If we just need to make sure the new behaviour matches the old then adding the * 2 to a v5 is fine.
I don't think we need to fix the existing code which seems correct to me the way it is.
I've now found in the thread the following from Prabhakar
-------------------------------------------------------------------------------
Quoted 2 lines
Quoted 2 lines
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use v4l2_get_link_freq().
-------------------------------------------------------------------------------
I think I've confused everyone with "original code didn't have a / 2", but as explained what I meant is that the original code should have had a "/ 2" for the new code to match it.
I don't think we need to do anything, if not use
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
csi2->lanes * 2);
mbps = ret * 2;
do_div(mbps, 1000000);in v5.
Feel free to make the above look nicer, I think we could spare a few variables, what matters to me is that:
1) Use csi2->lane * 2 as suggested by Prabhakar so that the behaviour is the same for remotes that use LINK_FREQ and remotes that use PIXEL_RATE
2) Use mbps = v4l2_get_link_freq() * 2
3) Use the pad version of v4l2_get_link_freq() if possible
Quoted 28 lines
Thanks
Dan
Quoted 22 lines
Thanks in advance.
Thanks & Regards,
TommasoQuoted 16 lines
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 8 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
Hi Jacopo
Quoted 290 lines · Jacopo Mondi
Hi Dan
Quoted 253 lines · Dan Scally
Quoted 252 lines · Tommaso Merciai
Hi Jacopo, Dan,
Thanks for your comments! :)Quoted 150 lines · Jacopo Mondi
Hi Dan
Quoted 147 lines · Dan Scally
Hi again
Quoted 134 lines · Prabhakar
Hi Tommaso,
Quoted 68 lines · Tommaso Merciai
Hi Jacopo,
Thanks for your comment.Quoted 64 lines · Jacopo Mondi
Hi Tommaso
Quoted 61 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 57 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)diff --git
a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.cb/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.cindex9243306e2aa9..8870c2cb8104100644drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) const struct rzg2l_csi2_format *format; const struct v4l2_mbus_framefmt *fmt; struct v4l2_subdev_state *state; - struct v4l2_ctrl *ctrl; u64 mbps; - - /* Read the pixel rate control from remote. */ - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE); - if (!ctrl) { - dev_err(csi2->dev, "no pixel rate control in subdev %s\n", - source->name); - return -EINVAL; - } + s64 ret; state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev); fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK); format = rzg2l_csi2_code_to_fmt(fmt->code); v4l2_subdev_unlock_state(state);Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 9 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6- /* - * Calculate hsfreq in Mbps - * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes - */ - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp; - do_div(mbps, csi2->lanes * 1000000); + /* Read the link frequency from remote subdevice. */ + ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);div needs to be updated in
v4l2_get_link_freq()as below so that when subdev has onlyV4L2_CID_PIXEL_RATEwe get the correct value.ret = v4l2_get_link_freq(source->ctrl_handler,
format->bpp,
-csi2->lanes);
+csi2->lanes* 2);Quoted 27 lines
Quoted 27 lines
Quoted 14 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 11 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+ if (ret < 0) { + dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n", + source->name); + return -EINVAL; + } + + mbps = ret; + do_div(mbps, 1000000); return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
- * hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanesAnd not the per-lane frequency as the variable name and the commit message suggest
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().Quoted 9 lines
Quoted 9 lines
Dan, did you ever notice issues during your testing ?
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?Quoted 3 lines
Please correct me if I'm wrong.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Yes the error goes away on my side using:
mbps = ret * 2;
I tested the above with an OV5645 sensor and see no issues.
Actually, I'm missing something here. Tommaso, you're using an imx219? So
Yes, tested with an imx219 image sensor.
Quoted 36 lines
Quoted 7 lines
V4L2_CID_LINK_FREQshould be 456000000 andV4L2_CID_PIXEL_RATEshould be 182400000. The original calculation (assuming a 10-bit format and 2 lanes) is 182400000 * 10 / (2 * 1000000) = 912. That's double the link frequency in Mbps (456) so I understand that the / 2 was missing...but the function with this patch applied should return 456 already...so if that's the correct value then I'm confused as to why you'd be seeing errors and why multiplying the return by 2 would fix them. What am I missing?It's the other way around actually.
The function needs to calculate the lane bandwidth not the linke frequency (*), and as you confirmed the original code returned 912 Mbps.
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);The new code returns the link frequency instead
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);Maybe I confused you when I've said "the original code didn't have a / 2" but what I meant is that the original code should have had a / 2 to behave like the new version (but what we actually want is the new code to behave like the old one, not the other way around :)
so the new code should do
Quoted 8 lines
mbps = ret * 2;
if it uses
ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2);Does it make sense ?
Thanks Jacopo. Agree.
Some formulas:
(please correct me if I'm wrong :) )We have the following formula:
vclk * bpp = hsclk * 8 * lanes
hsclk(bit) = hsclk(byte) * 8 = hsfreqThen:
- hsfreq = (vclk * bpp) / lanes
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesFormula for
link_freq:hsfreq = (
pixel_rate*bits_per_sample) /number_of_lanespixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sampleRewriting the
pixel_rateformula as:(
pixel_rate*bits_per_sample) /nr_of_lanes=link_freq* 2Then:
hsfreq =link_freq* 2
---Old code:
- /*
- * Calculate hsfreq in Mbps
- * hsfreq = (pixel_rate*bits_per_sample) /number_of_lanes- */
- mbps =v4l2_ctrl_g_ctrl_int64(ctrl)*format->bpp; -do_div(mbps, csi2->lanes * 1000000);mbps = (182400000 * 10) / 2 = 912000000 --> 912000000 / 1000000 = 912
---New code:
+ /* Read the link frequency from remote subdevice. */ + ret =
v4l2_get_link_freq(source->ctrl_handler, format->bpp, + csi2->lanes);
+
+ mbps = ret;
+do_div(mbps, 1000000);mbps = (456000000 / 1000000) = 456 (I think is wrong missing *2 based on the formula)
Quoted 8 lines
Quoted 1 line
Please let me know if I'm missing somenthing.
That all makes sense to me yes. Perhaps I'm misunderstanding, but I thought one conclusion of the discussion was that we wanted a separate patch adding the missing / 2 so that it could be backported as a fix...is that not the case? If we just need to make sure the new behaviour matches the old then adding the * 2 to a v5 is fine.
I don't think we need to fix the existing code which seems correct to me the way it is.
I've now found in the thread the following from Prabhakar
-------------------------------------------------------------------------------
Quoted 2 lines
Quoted 2 lines
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
I agree the orignal code missed a / 2. I think we need a fixup patch (so that this can be backported) and then this change to use
v4l2_get_link_freq().
-------------------------------------------------------------------------------I think I've confused everyone with "original code didn't have a / 2", but as explained what I meant is that the original code should have had a "/ 2" for the new code to match it.
I don't think we need to do anything, if not use
ret = v4l2_get_link_freq(source->ctrl_handler, format->bpp, csi2->lanes * 2); mbps = ret * 2; do_div(mbps, 1000000);in v5.
Quoted 7 lines
Feel free to make the above look nicer, I think we could spare a few variables, what matters to me is that:
1) Use
csi2->lane* 2 as suggested by Prabhakar so that the behaviour is the same for remotes that useLINK_FREQand remotes that usePIXEL_RATE
2) Use mbps =v4l2_get_link_freq()* 2
3) Use the pad version ofv4l2_get_link_freq()if possible
Got it - thanks very much, and sorry for the confusion!
Quoted 26 lines
Quoted 26 lines
Thanks
Dan
Quoted 19 lines
Thanks in advance.
Thanks & Regards,
TommasoQuoted 14 lines
(*) Table 35.7 of the RZ/G2LC datasheet doesn't actually specify that, but given that all values are in Mbps and not in MHz, and the old code calculaates the bandwidth and not link frequency, it's fair to assume this I guess...
Quoted 7 lines
Thanks
Dan
Quoted 2 lines
Cheers,
Prabhakar
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Jacopo MondiHi Jacopo
Quoted 98 lines · Jacopo Mondi
Hi Tommaso
Quoted 82 lines · Tommaso Merciai
Hi Daniel,
Thanks for your patch.Quoted 65 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +5
-15@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state); -/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes); +if (ret <0 ) {drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 306
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +7
-0+dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }I tested this series with an imx219 image sensor connected to the CSI-2 RX IP of RZ/G3E:
Quoted 6 lines
Some notes:
-
pixel_rate=link_freq* 2 *nr_of_lanes/bits_per_sample
- hsfreq = (pixel_rate*bits_per_sample) /number_of_lanesThen hsfreq should be:
The old code seems to call 'hsfreq' the per-lane bandwidth
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +0
-1-* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes And not the per-lane frequency as the variable name and the commit message suggest
Quoted 8 lines
Quoted 1 line
- hsfreq =
link_freq* 2if that's the intention, due to CSI-2 DDR, then you're correct I think ?
Seeing that also Laurent has reviewed it, and Prabhakar tested it, I wonder if we all have missed that the original code didn't have a / 2
Dan, did you ever notice issues during your testing ?
I don't recall any, but this patch has been in my tree for a long time, so possibly hidden by it.
Quoted 4 lines
Also, with the introduction of
15f0035bfd0a("media: v4l: Support passing media pad argument tov4l2_get_link_freq()") it's probably now better to pass the source's pad tov4l2_get_link_freq()?
Ah thanks for pointing that out - the _Generic() magic had hidden it so I hadn't noticed that it had changed.
Quoted 99 lines
Quoted 6 lines
Please correct me if I'm wrong.
After applying this series. I'm getting the following issue testing the imx219 sensor with
SRGGB8_1X8andSGRBG10_1X10color format.Does the error go away if you multiply the
link_freqby 2 ?Thanks
jQuoted 88 lines
[ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.305876] rzg2l-cru 16000000.video: Invalid MB address 0xe8bf8300 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range) [ 947.339165] rzg2l-cru 16000000.video: Invalid MB address 0xe8c9e900 (out of range)I'm suspecting that this could be related to this formula. Let me know what do you think.
Thanks in advance!
Tested using:
root@smarc-rzg3e:~# media-ctl -p Media controller API version 6.15.0Media device information
------------------------
driverrzg2l_cru
model renesas,r9a09g047-cru
serialbus info platform:16000000.video hw revision 0x0 driver version 6.15.0Device topology
- entity 1: csi-16000400.csi2 (2 pads, 2 links, 0 routes)type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev0 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "imx219 0-0010":0 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "cru-ip-16000000.video":0 [ENABLED,IMMUTABLE]- entity 4: cru-ip-16000000.video (2 pads, 2 links, 0 routes)
type V4L2 subdev subtype Unknown flags 0 device node name /dev/v4l-subdev1 pad0: Sink [stream:0 fmt:SGRBG10_1X10/640x480 field:none] <- "csi-16000400.csi2":1 [ENABLED,IMMUTABLE] pad1: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none] -> "CRU output":0 [ENABLED,IMMUTABLE]- entity 7: imx219 0-0010 (1 pad, 1 link, 0 routes)
type V4L2 subdev subtype Sensor flags 0 device node name /dev/v4l-subdev2 pad0: Source [stream:0 fmt:SGRBG10_1X10/640x480 field:none colorspace:raw xfer:none ycbcr:601 quantization:full-range crop.bounds:(8,8)/3280x2464 crop:(1008,760)/1280x960] -> "csi-16000400.csi2":0 [ENABLED,IMMUTABLE]- entity 17: CRU output (1 pad, 1 link)
type Node subtype V4L flags 0
device node name/dev/video0
pad0: Sink
<- "cru-ip-16000000.video":1 [ENABLED,IMMUTABLE]# IMX219 TESTING
SGRBG10_1X10
v4l2-ctl -c horizontal_flip=1 -d/dev/v4l-subdev2media-ctl -d
/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SGRBG10_1X10/640x480]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SGRBG10_1X10/640x480]'v4l2-ctl -d0 --set-fmt-video pixelformat=CR10,width=640,height=480 v4l2-ctl -d0 --stream-mmap --stream-count=100
# IMX219 TESTING
SRGGB8_1X8
media-ctl -d/dev/media0--set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"csi-16000400.csi2":0[fmt:SRGGB8_1X8/1920x1080]' media-ctl -d/dev/media0--set-v4l2 '"cru-ip-16000000.video":0[fmt:SRGGB8_1X8/1920x1080]'v4l2-ctl -d0 --set-fmt-video pixelformat=RGGB,width=1920,height=1080 v4l2-ctl -d0 --stream-mmap --stream-count=32
Thanks & Regards,
TommasoQuoted 3 lines
--
2.34.1
Re: [PATCH v4 3/6] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
In reply to Daniel ScallyHi Daniel,
Quoted 54 lines · Daniel Scally
From: Daniel Scally <[email protected]>
The
rzg2l_csi2_calc_mbps()function currently tries to calculate the link frequency for a CSI2 bus using theV4L2_CID_PIXEL_RATEcontrol of the remote subdevice. Switch the function tov4l2_get_link_freq()which correctly targetsV4L2_CID_LINK_FREQbefore falling back onV4L2_CID_PIXEL_RATEif the former is unavailable.Reviewed-by Jacopo Mondi <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>Reviewed-by Lad Prabhakar <[email protected]>Tested-by Lad Prabhakar <[email protected]>Signed-off-by Daniel Scally <[email protected]>---
Changes in v4:- Used separate s64 variable as return value for
v4l2_get_link_freq()and as the mbps variable fordo_div()to avoid compilation warnings.Changes in v3:
- Fixed mbps sign
Changes in v2:
- None
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-)drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +1
-9@@ -282,28 +282,25 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)const struct rzg2l_csi2_format *format;const struct v4l2_mbus_framefmt *fmt;struct v4l2_subdev_state *state; -struct v4l2_ctrl *ctrl;u64 mbps; - -/* Read the pixel rate control from remote. */ - ctrl =v4l2_ctrl_find (source->ctrl_handler,V4L2_CID_PIXEL_RATE ); -if (!ctrl) { -dev_err (csi2->dev,"no pixel rate control in subdev %s\n" , - source->name); -return -EINVAL ; - } +s64 ret; state =v4l2_subdev_lock_and_get_active_state (&csi2->subdev); fmt =v4l2_subdev_state_get_format (state,RZG2L_CSI2_SINK ); format =rzg2l_csi2_code_to_fmt (fmt->code);v4l2_subdev_unlock_state (state);
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2) · line 295
Quoted 10 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +3
-6-/* -* Calculate hsfreq in Mbps -* hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes -*/ - mbps =v4l2_ctrl_g_ctrl_int64 (ctrl) * format->bpp; -do_div (mbps, csi2->lanes *1000000 ); +/* Read the link frequency from remote subdevice. */ + ret =v4l2_get_link_freq (source->ctrl_handler, format->bpp, + csi2->lanes);
Please call v4l2_get_link_freq() on the pad, not the control handler.
Quoted 11 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +8
-0+if (ret <0 ) { +dev_err (csi2->dev,"can't retrieve link freq from subdev %s\n" , + source->name); +return -EINVAL ; + } + + mbps = ret; +do_div (mbps,1000000 );return mbps; }
Signature · 3 lines
Regards, Sakari Ailus
PATCH v4 4/6 media: platform: rzg2l-cru: Use v4l2_fill_pixfmt()
In reply to Daniel ScallyFrom: Daniel Scally <[email protected]>
Rather than open-code a calculation of the format's bytesperline and sizeimage, use the v4l2_fill_pixfmt() helper. This makes it easier to support the CRU packed pixel formats without over complicating the driver.
This change makes the .bpp member of struct rzg2l_cru_ip_format superfluous - remove them.
---
Changes in v4:
- None
Changes in v3:
- None
Changes in v2:
- Minor changes due to rebase
drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h | 2 -- drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c | 5 ----- drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 10 +--------- 3 files changed, 1 insertion(+), 16 deletions(-)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h +0 -2
@@ -68,7 +68,6 @@ struct rzg2l_cru_ip {* @datatype: MIPI CSI2 data type * @format: 4CC format identifier (V4L2_PIX_FMT_*) * @icndmr: ICnDMR register value -* @bpp: bytes per pixel * @yuv: Flag to indicate whether the format is YUV-based. */ struct rzg2l_cru_ip_format {
@@ -76,7 +75,6 @@ struct rzg2l_cru_ip_format {u32 datatype;u32 format;u32 icndmr; -u8 bpp;bool yuv; };
drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c +0 -5
@@ -16,7 +16,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .code = MEDIA_BUS_FMT_UYVY8_1X16, .datatype = MIPI_CSI2_DT_YUV422_8B, .format = V4L2_PIX_FMT_UYVY, - .bpp = 2, .icndmr = ICnDMR_YCMODE_UYVY, .yuv = true, },
@@ -24,7 +23,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .code = MEDIA_BUS_FMT_SBGGR8_1X8, .format = V4L2_PIX_FMT_SBGGR8, .datatype = MIPI_CSI2_DT_RAW8, - .bpp = 1, .icndmr = 0, .yuv = false, },
@@ -32,7 +30,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .code = MEDIA_BUS_FMT_SGBRG8_1X8, .format = V4L2_PIX_FMT_SGBRG8, .datatype = MIPI_CSI2_DT_RAW8, - .bpp = 1, .icndmr = 0, .yuv = false, },
@@ -40,7 +37,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .code = MEDIA_BUS_FMT_SGRBG8_1X8, .format = V4L2_PIX_FMT_SGRBG8, .datatype = MIPI_CSI2_DT_RAW8, - .bpp = 1, .icndmr = 0, .yuv = false, },
@@ -48,7 +44,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .code = MEDIA_BUS_FMT_SRGGB8_1X8, .format = V4L2_PIX_FMT_SRGGB8, .datatype = MIPI_CSI2_DT_RAW8, - .bpp = 1, .icndmr = 0, .yuv = false, },
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +1 -9
@@ -941,15 +941,7 @@ static void rzg2l_cru_format_align(struct rzg2l_cru_dev *cru,v4l_bound_align_image (&pix->width,320 , info->max_width,1 , &pix->height,240 , info->max_height,2 ,0 ); -if (info->has_stride) { -u32 stride =clamp (pix->bytesperline, pix->width * fmt->bpp, -RZG2L_CRU_STRIDE_MAX ); - pix->bytesperline =round_up (stride,RZG2L_CRU_STRIDE_ALIGN ); - }else { - pix->bytesperline = pix->width * fmt->bpp; - } - - pix->sizeimage = pix->bytesperline * pix->height; +v4l2_fill_pixfmt (pix, pix->pixelformat, pix->width, pix->height);dev_dbg (cru->dev,"Format %ux%u bpl: %u size: %u\n" , pix->width, pix->height, pix->bytesperline, pix->sizeimage);
Signature · 1 line
2.34.1
PATCH v4 5/6 media: rzg2l-cru: Support multiple mbus codes per pixel format
In reply to Daniel ScallyFrom: Daniel Scally <[email protected]>
As a preliminary step for supporting the CRU pixel formats, extend the driver such that multiple media bus codes can support each of the output pixel formats.
---
Changes in v4:
- None
Changes in v3:
- New patch due to changes to patch 1
.../platform/renesas/rzg2l-cru/rzg2l-cru.h | 8 ++- .../platform/renesas/rzg2l-cru/rzg2l-ip.c | 67 +++++++++++++++---- .../platform/renesas/rzg2l-cru/rzg2l-video.c | 2 +- 3 files changed, 61 insertions(+), 16 deletions(-)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h +7 -1
@@ -71,7 +71,11 @@ struct rzg2l_cru_ip {* @yuv: Flag to indicate whether the format is YUV-based. */ struct rzg2l_cru_ip_format { -u32 code; +/* +* RAW output formats might be produced by RAW media codes with any one +* of the 4 common bayer patterns. +*/ +u32 codes[4 ];u32 datatype;u32 format;u32 icndmr;
@@ -190,6 +194,8 @@ struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru);const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt (unsigned int code);const struct rzg2l_cru_ip_format *rzg2l_cru_ip_format_to_fmt (u32 format);const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt (u32 index); +bool rzg2l_cru_ip_fmt_supports_mbus_code (const struct rzg2l_cru_ip_format *fmt, +unsigned int code);void rzg2l_cru_enable_interrupts (struct rzg2l_cru_dev *cru);void rzg2l_cru_disable_interrupts (struct rzg2l_cru_dev *cru);
drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c +53 -14
123 lines not on this page · raw message
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c +1 -1
@@ -1149,7 +1149,7 @@ static int rzg2l_cru_video_link_validate(struct media_link *link)if (fmt.format.width != cru->format.width || fmt.format.height != cru->format.height || fmt.format.field != cru->format.field || - video_fmt->code != fmt.format.code) + !rzg2l_cru_ip_fmt_supports_mbus_code (video_fmt, fmt.format.code))return -EPIPE ;return 0 ;
Signature · 1 line
2.34.1
PATCH v4 6/6 media: platform: rzg2l-cru: Add support for RAW10/12/14 data
In reply to Daniel ScallyFrom: Daniel Scally <[email protected]>
Add support to the rzg2l-cru driver to capture 10/12/14 bit bayer data and output it into the CRU's 64-bit packed pixel format.
---
Changes in v4:
- None
Changes in v3:
- Fewer new entries as the RAWnn pixel formats support multiple mbus codes
Changes in v2:
- Minor updates accounting for rebase
.../platform/renesas/rzg2l-cru/rzg2l-csi2.c | 12 +++++++ .../platform/renesas/rzg2l-cru/rzg2l-ip.c | 36 +++++++++++++++++++ 2 files changed, 48 insertions(+)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c +12 -0
@@ -232,6 +232,18 @@ static const struct rzg2l_csi2_format rzg2l_csi2_formats[] = { { .code = MEDIA_BUS_FMT_SGBRG8_1X8, .bpp = 8, }, { .code = MEDIA_BUS_FMT_SGRBG8_1X8, .bpp = 8, }, { .code = MEDIA_BUS_FMT_SRGGB8_1X8, .bpp = 8, }, + { .code = MEDIA_BUS_FMT_SBGGR10_1X10, .bpp = 10, }, + { .code = MEDIA_BUS_FMT_SGBRG10_1X10, .bpp = 10, }, + { .code = MEDIA_BUS_FMT_SGRBG10_1X10, .bpp = 10, }, + { .code = MEDIA_BUS_FMT_SRGGB10_1X10, .bpp = 10, }, + { .code = MEDIA_BUS_FMT_SBGGR12_1X12, .bpp = 12, }, + { .code = MEDIA_BUS_FMT_SGBRG12_1X12, .bpp = 12, }, + { .code = MEDIA_BUS_FMT_SGRBG12_1X12, .bpp = 12, }, + { .code = MEDIA_BUS_FMT_SRGGB12_1X12, .bpp = 12, }, + { .code = MEDIA_BUS_FMT_SBGGR14_1X14, .bpp = 14, }, + { .code = MEDIA_BUS_FMT_SGBRG14_1X14, .bpp = 14, }, + { .code = MEDIA_BUS_FMT_SGRBG14_1X14, .bpp = 14, }, + { .code = MEDIA_BUS_FMT_SRGGB14_1X14, .bpp = 14, }, }; static inline struct rzg2l_csi2 *sd_to_csi2(struct v4l2_subdev *sd)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c +36 -0
@@ -57,6 +57,42 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = { .icndmr = 0, .yuv = false, }, + { + .codes = { + MEDIA_BUS_FMT_SBGGR10_1X10, + MEDIA_BUS_FMT_SGBRG10_1X10, + MEDIA_BUS_FMT_SGRBG10_1X10, + MEDIA_BUS_FMT_SRGGB10_1X10 + }, + .format = V4L2_PIX_FMT_CRU_RAW10, + .datatype = MIPI_CSI2_DT_RAW10, + .icndmr = 0, + .yuv = false, + }, + { + .codes = { + MEDIA_BUS_FMT_SBGGR12_1X12, + MEDIA_BUS_FMT_SGBRG12_1X12, + MEDIA_BUS_FMT_SGRBG12_1X12, + MEDIA_BUS_FMT_SRGGB12_1X12 + }, + .format = V4L2_PIX_FMT_CRU_RAW12, + .datatype = MIPI_CSI2_DT_RAW12, + .icndmr = 0, + .yuv = false, + }, + { + .codes = { + MEDIA_BUS_FMT_SBGGR14_1X14, + MEDIA_BUS_FMT_SGBRG14_1X14, + MEDIA_BUS_FMT_SGRBG14_1X14, + MEDIA_BUS_FMT_SRGGB14_1X14 + }, + .format = V4L2_PIX_FMT_CRU_RAW14, + .datatype = MIPI_CSI2_DT_RAW14, + .icndmr = 0, + .yuv = false, + }, }; const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code)
Signature · 1 line
2.34.1