media: platform: rga: Add RGA3 support
Subsystems (4)
v4 cover media: platform: rga: Add RGA3 support
This series adds support for the Raster Graphic Acceleration 3 (RGA3) peripheral, which is included in the RK3588 SoC. The RK3588 contains one RGA2-Enhanced core (which is already implemented by the rockchip rga driver) and two independent RGA3 cores. They feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are:
- supports 10bit YUV output formats
- supports 8x8 tiles and FBCD as inputs and outputs
- supports BT2020 color space conversion
- max output resolution of (8192-64)x(8192-64)
- MMU can map up to 32G DDR RAM
- fully planar formats (3 planes) are not supported
- max scale up/down factor of 8 (RGA2 allows up to 16)
This patch set adds support for one RGA3 core in the existing rga m2m driver. The feature set of the PR is limited to scaling, format and color space conversions between common 8bit RGB/YUV formats. This already allows a practical usage of the RGA3.
During testing it has been noted that the scaling of the hardware is slightly incorrect. A test conversion of 128x128 RGBA to 256x256 RGBA causes a slight shift to the bottom right. The shift is suddle, as it seems that the image is shifted by about 2px down and right and then cropped to it's final size (probably caused by the source sampling).
The same behavior has been observed when using the vendor driver with the librga library.
Furthermore comparing the RGA3 conversion with the GStreamer videoconvertscale element, the chroma-site is different. A quick testing didn't reveal a chroma-site that creates the same image with the GStreamer Element. Also when converting from YUV to RGB the RGB values differ by 1 or 2. This doesn't seem to be a colorspace conversion issue but rather a slightly different precision on the calculation.
This was tested on a Radxa Rock 5T. Around 80 fps were measured when scaling and converting from RGBA 480x360 to NV12 3840x2160 in a single gstreamer pipeline. Format conversions were tested with a single gstreamer pipeline converting a fixed input to a given input format. Afterwards it's piped through the RGA3 and the result is converted back to rgba and compared against a given hash value (generated after comparing the output manually to the input).
The patchset also fixes the failing v4l2-compliance tests due to the missing colorimetry propagation from output to capture:
v4l2-compliance 1.32.0, 64 bits, 64-bit time_t
...
Card type : rga2
...
Total for rockchip-rga device /dev/video0: 48, Succeeded: 48, Failed: 0, Warnings: 0
v4l2-compliance 1.32.0, 64 bits, 64-bit time_t
...
Card type : rga3
...
Total for rockchip-rga device /dev/video1: 48, Succeeded: 48, Failed: 0, Warnings: 0
To distinguish the RGA2 core from the RGA3 cores the Card type is set accordingly. Scheduling operations between both RGA3 cores to double the possible frame rate might be a future improvement. Until then additional RGA3 cores are disabled to only provide one video device to the user space. This prevents a potential ABI breakage when multi core support is implemented.
The DTS change at the end is just as a preview, as this series targets media/next. After it's merged the DTS change will be sent as a new patch not targeting media.
Patch 1 updates the dtb bindings doc to support the RGA3 Patch 2-5 extend v4l2 common functionality Patch 6-9 are general cleanups
Patch 10-25 prepare the rga driver for the RGA3 Patch 26 adds RGA3 support to the rga driver Patch 27 dtsi additions for the RGA3
---
Changes in v4:
- Add Nicolas to Cc for potential reviews and Sebastian for the nice
RK3588 mainline status table
- Improved single memory plane y stride alignment adjustments
- Adjusted scaling inaccuracy description
- Dropped required iommu property from the binding yaml
- Fixed binding yaml indentation
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add iommus property to the dtb bindings documentation
- Drop interrupt name from the dtsi
- Added v4l2_format_info for missing 2 byte RGB formats
- Fixed incorrect dt node reference in the binding patch commit message
- Removed now unused depth member of rga_frame
- Replaced RGA3 semi planar bool with v4l2_format_info check
- Calculated x_div/y_div variables instead of storing them
- Limited width/height to even values for YUV formats
- Support all 4 CSC modes: BT601L, BT601F, BT709L, BT2020L
- Note slightly incorrect scaling by the hardware
- Fix stride alignment to bytes
- Use early returns in rga-buf init/cleanup
- Fix incorrect devm_clk_bulk_get with devm_clk_bulk_get_all
- Don't enforce max scaling factor in try_fmt (only in s_fmt)
- Merge single register editing RGA3 functions into the other functions
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Removed overclocking (assigning higher clock speeds in the dts)
- Disable the second RGA3 core
- Improved RGA3 feature documentation and code comments
- Don't write the whole command buffer in each frame
- Don't announce CIDs for the RGA3 and error out on s_selection
- Check the max scaling factor of 16 (RGA2) and 8 (RGA3)
- Move stride alignment and alpha checking to v4l2 common
- Register the interrupt as shared for an external IOMMU
- Add IOMMU patch as dependency to fix sporadic hangups
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Michael Olbrich (1):
media: rockchip: rga: share the interrupt when an external iommu is used
Sven Püschel (26):
media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3
media: v4l2-common: sort RGB formats in v4l2_format_info
media: v4l2-common: add missing 1 and 2 byte RGB formats to v4l2_format_info
media: v4l2-common: add has_alpha to v4l2_format_info
media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper
media: rockchip: rga: use clk_bulk api
media: rockchip: rga: use stride for offset calculation
media: rockchip: rga: remove redundant rga_frame variables
media: rockchip: rga: announce and sync colorimetry
media: rockchip: rga: move hw specific parts to a dedicated struct
media: rockchip: rga: avoid odd frame sizes for YUV formats
media: rockchip: rga: calculate x_div/y_div using v4l2_format_info
media: rockchip: rga: move cmdbuf to rga_ctx
media: rockchip: rga: align stride to 4 bytes
media: rockchip: rga: prepare cmdbuf on streamon
media: rockchip: rga: check scaling factor
media: rockchip: rga: use card type to specify rga type
media: rockchip: rga: change offset to dma_addresses
media: rockchip: rga: support external iommus
media: rockchip: rga: remove size from rga_frame
media: rockchip: rga: remove stride from rga_frame
media: rockchip: rga: move rga_fmt to rga-hw.h
media: rockchip: rga: add feature flags
media: rockchip: rga: disable multi-core support
media: rockchip: rga: add rga3 support
arm64: dts: rockchip: add rga3 dt nodes
.../devicetree/bindings/media/rockchip-rga.yaml | 10 +- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 44 ++ drivers/media/platform/rockchip/rga/Makefile | 2 +- drivers/media/platform/rockchip/rga/rga-buf.c | 61 ++- drivers/media/platform/rockchip/rga/rga-hw.c | 358 +++++++++---- drivers/media/platform/rockchip/rga/rga-hw.h | 14 +- drivers/media/platform/rockchip/rga/rga.c | 577 ++++++++++----------- drivers/media/platform/rockchip/rga/rga.h | 85 +-- drivers/media/platform/rockchip/rga/rga3-hw.c | 507 ++++++++++++++++++ drivers/media/platform/rockchip/rga/rga3-hw.h | 192 +++++++ drivers/media/v4l2-core/v4l2-common.c | 128 +++-- include/media/v4l2-common.h | 6 + 12 files changed, 1480 insertions(+), 504 deletions(-)
---
base-commit: 0e2c4117c3512cf6b8f54c2c3d37564bfa3ccd67
change-id: 20251001-spu-rga3-8a00e018b120
prerequisite-change-id: 20251126-spu-iommudtefix-cd0c5244c74a:v1
prerequisite-patch-id: 10c6c977c0f71400931941b42da73adcaf63e810
Best regards,
Signature · 1 line
Sven Püschel <[email protected]>
PATCH v4 1/27 media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3
Add a new compatible for the RGA3 (Raster Graphic Acceleration 3) peripheral found on the RK3588 SoC. Also specify an iommu property, as the RGA3 contains the generic rockchip iommu. While other versions also have an iommu, it's usually specific to them.
The RK3588 contains one RGA2-Enhance core (also contained on the RK3399) and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are:
- supports 10bit YUV output formats
- supports 8x8 tiles and FBCD as inputs and outputs
- supports BT2020 color space conversion
- max output resolution of (8192-64)x(8192-64)
- MMU can map up to 32G DDR RAM
- fully planar formats (3 planes) are not supported
- max scale up/down factor of 8 (RGA2 allows up to 16)
---
Changed in v3/v4:
- Dropped Acked-by: Krzysztof Kozlowski due to the added iommus property and description adjustments.
--- Documentation/devicetree/bindings/media/rockchip-rga.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/rockchip-rga.yaml +9 -1
@@ -9,7 +9,11 @@ title: Rockchip 2D raster graphic acceleration controller (RGA) description: RGA is a standalone 2D raster graphic acceleration unit. It accelerates 2D graphics operations, such as point/line drawing, image scaling, rotation, - BitBLT, alpha blending and image blur/sharpness. + BitBLT, alpha blending and image blur/sharpness. There exist many versions + of this unit that differ in the supported inputs/output formats, + the attached IOMMU and the supported operations on the input. As some SoCs + include multiple RGA units with different versions, a more specific + compatible name to differentiate the concrete unit is used for them. maintainers: - Jacob Chen <[email protected]>
@@ -20,6 +24,7 @@ properties: oneOf: - const: rockchip,rk3288-rga - const: rockchip,rk3399-rga + - const: rockchip,rk3588-rga3 - items: - enum: - rockchip,rk3228-rga
@@ -45,6 +50,9 @@ properties: power-domains: maxItems: 1 + iommus: + maxItems: 1 + resets: maxItems: 3
Signature · 1 line
2.53.0
Re: [PATCH v4 01/27] media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3
Quoted 20 lines · Sven Püschel
Add a new compatible for the RGA3 (Raster Graphic Acceleration 3) peripheral found on the RK3588 SoC. Also specify an iommu property, as the RGA3 contains the generic rockchip iommu. While other versions also have an iommu, it's usually specific to them.
The RK3588 contains one RGA2-Enhance core (also contained on the RK3399) and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are:
- supports 10bit YUV output formats
- supports 8x8 tiles and FBCD as inputs and outputs
- supports BT2020 color space conversion
- max output resolution of (8192-64)x(8192-64)
- MMU can map up to 32G DDR RAM
- fully planar formats (3 planes) are not supported
- max scale up/down factor of 8 (RGA2 allows up to 16)Signed-off-by Sven Püschel <[email protected]>
Quoted 9 lines
---
Changed in v3/v4:
- Dropped Acked-by: Krzysztof Kozlowski due to the added iommus property and description adjustments.--- Documentation/devicetree/bindings/media/rockchip-rga.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
PATCH v4 2/27 media: v4l2-common: sort RGB formats in v4l2_format_info
In reply to Sven PüschelSort the RGB formats in v4l2_format_info to match the format definitions in include/uapi/linux/videodev2.h . Also introduce the same sections to partition the list of formats and align the format info in each section.
The alignment of the 1 or 2 bytes RGB formats contains an additional space in preparation of adding the missing formats to the list, as for V4L2_PIX_FMT_ARGB555X an additional space is necessary.
--- drivers/media/v4l2-core/v4l2-common.c | 54 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 24 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +30 -24
@@ -245,33 +245,39 @@ EXPORT_SYMBOL_GPL(v4l2_s_parm_cap);const struct v4l2_format_info *v4l2_format_info (u32 format) {static const struct v4l2_format_info formats[] = { -/* RGB formats */ - { .format =V4L2_PIX_FMT_BGR24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_HSV24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_XBGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGRX32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_XRGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGBX32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_HSV32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_ARGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGBA32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_ABGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGRA32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB565 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB565X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGR666 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGR48_12 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_BGR48 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGB48 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_ABGR64_12 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {8 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, - { .format =V4L2_PIX_FMT_RGBA1010102 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, +/* RGB formats (1 or 2 bytes per pixel) */ + { .format =V4L2_PIX_FMT_RGB555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB565 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB565X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + +/* RGB formats (3 or 4 bytes per pixel) */ + { .format =V4L2_PIX_FMT_BGR666 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_BGR24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGB24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_BGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_ABGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_XBGR32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_BGRA32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_BGRX32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGBA32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGBX32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_ARGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_XRGB32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, { .format =V4L2_PIX_FMT_RGBX1010102 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGBA1010102 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, { .format =V4L2_PIX_FMT_ARGB2101010 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, +/* RGB formats (6 or 8 bytes per pixel) */ + { .format =V4L2_PIX_FMT_BGR48_12 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_BGR48 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_RGB48 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {6 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_ABGR64_12 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {8 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + +/* HSV formats */ + { .format =V4L2_PIX_FMT_HSV24 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {3 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, + { .format =V4L2_PIX_FMT_HSV32 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {4 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 }, +/* YUV packed formats */ { .format =V4L2_PIX_FMT_YUYV , .pixel_enc =V4L2_PIXEL_ENC_YUV , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =2 , .vdiv =1 }, { .format =V4L2_PIX_FMT_YVYU , .pixel_enc =V4L2_PIXEL_ENC_YUV , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =2 , .vdiv =1 },
Signature · 1 line
2.53.0
PATCH v4 3/27 media: v4l2-common: add missing 1 and 2 byte RGB formats to v4l2_format_info
In reply to Sven PüschelAdd all missing one and two byte RGB formats to v4l2_format_info. This allows drivers to more consistently use v4l2_format_info, as it now covers all currently defined RGB formats.
--- drivers/media/v4l2-core/v4l2-common.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/media/v4l2-core/v4l2-common.c +21 -0
@@ -246,8 +246,29 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) {static const struct v4l2_format_info formats[] = {/* RGB formats (1 or 2 bytes per pixel) */ + { .format =V4L2_PIX_FMT_RGB332 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_ARGB444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_XRGB444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGBA444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGBX444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_ABGR444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_XBGR444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_BGRA444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_BGRX444 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_ARGB555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_XRGB555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGBA555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGBX555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_ABGR555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_XBGR555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_BGRA555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_BGRX555 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB565 , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB555X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_ARGB555X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_XRGB555X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .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_RGB565X , .pixel_enc =V4L2_PIXEL_ENC_RGB , .mem_planes =1 , .comp_planes =1 , .bpp = {2 ,0 ,0 ,0 }, .bpp_div = {1 ,1 ,1 ,1 }, .hdiv =1 , .vdiv =1 },/* RGB formats (3 or 4 bytes per pixel) */
Signature · 1 line
2.53.0
PATCH v4 4/27 media: v4l2-common: add has_alpha to v4l2_format_info
In reply to Sven PüschelAdd a has_alpha value to the v4l2_format_info struct to indicate if the format contains an alpha component. This information can currently not be queried in a generic way, but might be useful for potential drivers to properly setup alpha blending to copy or set the alpha value. The implementation is based on the drm_format_info implementation.
--- drivers/media/v4l2-core/v4l2-common.c | 32 ++++++++++++++++---------------- include/media/v4l2-common.h | 2 ++ 2 files changed, 18 insertions(+), 16 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +16 -16
@@ -248,26 +248,26 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)/* RGB formats (1 or 2 bytes per pixel) */ { .format = V4L2_PIX_FMT_RGB332, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGB444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XRGB444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGBA444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGBA444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_RGBX444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ABGR444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ABGR444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XBGR444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_BGRA444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_BGRA444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_BGRX444, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XRGB555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGBA555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGBA555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_RGBX555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ABGR555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ABGR555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XBGR555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_BGRA555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_BGRA555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_BGRX555, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGB565, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGB555X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB555X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_ARGB555X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XRGB555X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .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_RGB565X, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
@@ -276,24 +276,24 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) { .format = V4L2_PIX_FMT_BGR24, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB24, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_ABGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_ABGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XBGR32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_BGRA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_BGRA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_BGRX32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_RGBA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_RGBA32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_RGBX32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_ARGB32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_ARGB32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, { .format = V4L2_PIX_FMT_XRGB32, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGBX1010102, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_RGBA1010102, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_ARGB2101010, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_RGBA1010102, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, + { .format = V4L2_PIX_FMT_ARGB2101010, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, /* RGB formats (6 or 8 bytes per pixel) */ { .format = V4L2_PIX_FMT_BGR48_12, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_BGR48, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, { .format = V4L2_PIX_FMT_RGB48, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, - { .format = V4L2_PIX_FMT_ABGR64_12, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 }, + { .format = V4L2_PIX_FMT_ABGR64_12, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1, .has_alpha = true }, /* HSV formats */ { .format = V4L2_PIX_FMT_HSV24, .pixel_enc = V4L2_PIXEL_ENC_RGB, .mem_planes = 1, .comp_planes = 1, .bpp = { 3, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
include/media/v4l2-common.h +2 -0
@@ -520,6 +520,7 @@ enum v4l2_pixel_encoding {* @vdiv: Vertical chroma subsampling factor * @block_w: Per-plane macroblock pixel width (optional) * @block_h: Per-plane macroblock pixel height (optional) +* @has_alpha: Does the format embeds an alpha component? */ struct v4l2_format_info {u32 format;
@@ -532,6 +533,7 @@ struct v4l2_format_info {u8 vdiv;u8 block_w[4 ];u8 block_h[4 ]; +bool has_alpha; };static inline bool v4l2_is_format_rgb (const struct v4l2_format_info *f)
Signature · 1 line
2.53.0
PATCH v4 5/27 media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper
In reply to Sven PüschelAdd a v4l2_fill_pixfmt_mp_aligned helper which allows the user to specify a custom stride alignment in bytes. This is necessary for hardware like the Rockchip RGA3, which requires the stride value to be aligned to a 16 bytes boundary.
The code makes some assumptions about the v4l2 format to simplify the calculation. They currently hold for all known v4l2 formats.
--- drivers/media/v4l2-core/v4l2-common.c | 51 ++++++++++++++++++++++++++--------- include/media/v4l2-common.h | 4 +++ 2 files changed, 43 insertions(+), 12 deletions(-)
drivers/media/v4l2-core/v4l2-common.c +39 -12
@@ -431,14 +431,28 @@ static inline unsigned int v4l2_format_block_height(const struct v4l2_format_inf }static inline unsigned int v4l2_format_plane_stride (const struct v4l2_format_info *info,int plane, -unsigned int width) +unsigned int width,u8 byte_alignment) {unsigned int hdiv = plane ? info->hdiv :1 ;unsigned int aligned_width =ALIGN (width,v4l2_format_block_width (info, plane)); -return DIV_ROUND_UP (aligned_width, hdiv) * - info->bpp[plane] / info->bpp_div[plane]; +/* +* Formats with a single memory plane derive the stride of the +* other planes from the y stride. Due to chroma subsampling this +* may cause the other plane strides to break the byte_alignment. +* Increase the alignment if necessary to prevent this. +* +* It assumes the following format properties: +* - bpp_div[0] == bpp_div[1] +* - The multiplication factor doesn't differ between the non y planes +*/ +if (info->mem_planes ==1 && info->comp_planes >1 && plane ==0 ) + byte_alignment *= info->hdiv * info->bpp[0 ] / info->bpp[1 ]; + +return ALIGN (DIV_ROUND_UP (aligned_width, hdiv) * info->bpp[plane] / + info->bpp_div[plane], + byte_alignment); } static inline unsigned int v4l2_format_plane_height(const struct v4l2_format_info *info, int plane,
@@ -452,9 +466,10 @@ static inline unsigned int v4l2_format_plane_height(const struct v4l2_format_inf }static inline unsigned int v4l2_format_plane_size (const struct v4l2_format_info *info,int plane, -unsigned int width,unsigned int height) +unsigned int width,unsigned int height, +u8 stride_alignment) { -return v4l2_format_plane_stride (info, plane, width) * +return v4l2_format_plane_stride (info, plane, width, stride_alignment) *v4l2_format_plane_height (info, plane, height); }
@@ -475,8 +490,9 @@ void v4l2_apply_frmsize_constraints(u32 *width, u32 *height, }EXPORT_SYMBOL_GPL (v4l2_apply_frmsize_constraints); -int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt, -u32 pixelformat,u32 width,u32 height) +int v4l2_fill_pixfmt_mp_aligned (struct v4l2_pix_format_mplane *pixfmt, +u32 pixelformat,u32 width,u32 height, +u8 stride_alignment) {const struct v4l2_format_info *info;struct v4l2_plane_pix_format *plane;
@@ -493,23 +509,34 @@ int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt,if (info->mem_planes ==1 ) { plane = &pixfmt->plane_fmt[0 ]; - plane->bytesperline =v4l2_format_plane_stride (info,0 , width); + plane->bytesperline =v4l2_format_plane_stride (info,0 , width, + stride_alignment); plane->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) plane->sizeimage += -v4l2_format_plane_size (info, i, width, height); +v4l2_format_plane_size (info, i, width, height, + stride_alignment); }else {for (i =0 ; i < info->comp_planes; i++) { plane = &pixfmt->plane_fmt[i]; plane->bytesperline = -v4l2_format_plane_stride (info, i, width); +v4l2_format_plane_stride (info, i, width, + stride_alignment); plane->sizeimage = plane->bytesperline *v4l2_format_plane_height (info, i, height); } }return 0 ; } +EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt_mp_aligned); + +int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt, +u32 pixelformat,u32 width,u32 height) +{ +return v4l2_fill_pixfmt_mp_aligned (pixfmt, pixelformat, + width, height,1 ); +}EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt_mp); int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
@@ -529,12 +556,12 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, pixfmt->width = width; pixfmt->height = height; pixfmt->pixelformat = pixelformat; - pixfmt->bytesperline =v4l2_format_plane_stride (info,0 , width); + pixfmt->bytesperline =v4l2_format_plane_stride (info,0 , width,1 ); pixfmt->sizeimage =0 ;for (i =0 ; i < info->comp_planes; i++) pixfmt->sizeimage += -v4l2_format_plane_size (info, i, width, height); +v4l2_format_plane_size (info, i, width, height,1 );return 0 ; }EXPORT_SYMBOL_GPL (v4l2_fill_pixfmt);
include/media/v4l2-common.h +4 -0
@@ -558,6 +558,10 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, u32 width, u32 height);int v4l2_fill_pixfmt_mp (struct v4l2_pix_format_mplane *pixfmt,u32 pixelformat,u32 width,u32 height); +/* @stride_alignment is a power of 2 value in bytes */ +int v4l2_fill_pixfmt_mp_aligned (struct v4l2_pix_format_mplane *pixfmt, +u32 pixelformat,u32 width,u32 height, +u8 stride_alignment);/** * v4l2_get_link_freq - Get link rate from transmitter
Signature · 1 line
2.53.0
PATCH v4 6/27 media: rockchip: rga: use clk_bulk api
In reply to Sven PüschelUse the clk_bulk API to avoid code duplication for each of the three clocks.
--- drivers/media/platform/rockchip/rga/rga.c | 65 ++++--------------------------- drivers/media/platform/rockchip/rga/rga.h | 6 +-- 2 files changed, 11 insertions(+), 60 deletions(-)
drivers/media/platform/rockchip/rga/rga.c +8 -57
@@ -698,48 +698,10 @@ static const struct video_device rga_videodev = { .device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; -static int rga_enable_clocks (struct rockchip_rga *rga) -{ -int ret; - - ret =clk_prepare_enable (rga->sclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga sclk: %d\n" , ret); -return ret; - } - - ret =clk_prepare_enable (rga->aclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga aclk: %d\n" , ret); - goto err_disable_sclk; - } - - ret =clk_prepare_enable (rga->hclk); -if (ret) { -dev_err (rga->dev,"Cannot enable rga hclk: %d\n" , ret); - goto err_disable_aclk; - } - -return 0 ; - -err_disable_aclk: -clk_disable_unprepare (rga->aclk); -err_disable_sclk: -clk_disable_unprepare (rga->sclk); - -return ret; -} - -static void rga_disable_clocks (struct rockchip_rga *rga) -{ -clk_disable_unprepare (rga->sclk); -clk_disable_unprepare (rga->hclk); -clk_disable_unprepare (rga->aclk); -} -static int rga_parse_dt (struct rockchip_rga *rga) {struct reset_control *core_rst, *axi_rst, *ahb_rst; +int ret; core_rst =devm_reset_control_get (rga->dev,"core" );if (IS_ERR (core_rst)) {
@@ -771,23 +733,12 @@ static int rga_parse_dt(struct rockchip_rga *rga)udelay (1 );reset_control_deassert (ahb_rst); - rga->sclk =devm_clk_get (rga->dev,"sclk" ); -if (IS_ERR (rga->sclk)) { -dev_err (rga->dev,"failed to get sclk clock\n" ); -return PTR_ERR (rga->sclk); - } - - rga->aclk =devm_clk_get (rga->dev,"aclk" ); -if (IS_ERR (rga->aclk)) { -dev_err (rga->dev,"failed to get aclk clock\n" ); -return PTR_ERR (rga->aclk); - } - - rga->hclk =devm_clk_get (rga->dev,"hclk" ); -if (IS_ERR (rga->hclk)) { -dev_err (rga->dev,"failed to get hclk clock\n" ); -return PTR_ERR (rga->hclk); + ret =devm_clk_bulk_get_all (rga->dev, &rga->clks); +if (ret <0 ) { +dev_err (rga->dev,"failed to get clocks\n" ); +return ret; } + rga->num_clks = ret;return 0 ; }
@@ -935,7 +886,7 @@ static int __maybe_unused rga_runtime_suspend(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -rga_disable_clocks (rga); +clk_bulk_disable_unprepare (rga->num_clks, rga->clks);return 0 ; }
@@ -944,7 +895,7 @@ static int __maybe_unused rga_runtime_resume(struct device *dev) {struct rockchip_rga *rga =dev_get_drvdata (dev); -return rga_enable_clocks (rga); +return clk_bulk_prepare_enable (rga->num_clks, rga->clks); }static const struct dev_pm_ops rga_pm = {
drivers/media/platform/rockchip/rga/rga.h +3 -3
@@ -6,6 +6,7 @@#ifndef __RGA_H__#define __RGA_H__ +#include <linux/clk.h> #include <linux/platform_device.h> #include <media/videobuf2-v4l2.h> #include <media/v4l2-ctrls.h>
@@ -81,9 +82,8 @@ struct rockchip_rga {struct device *dev;struct regmap *grf;void __iomem *regs; -struct clk *sclk; -struct clk *aclk; -struct clk *hclk; +struct clk_bulk_data *clks; +int num_clks;struct rockchip_rga_version version;/* vfd lock */
Signature · 1 line
2.53.0
PATCH v4 7/27 media: rockchip: rga: use stride for offset calculation
In reply to Sven PüschelUse the stride instead of the width for the offset calculation. This ensures that the bytesperline value doesn't need to match the width value of the image.
Furthermore this patch removes the dependency on the uv_factor property and instead reuses the v4l2_format_info to determine the correct division factor.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 14 +++++++++----- drivers/media/platform/rockchip/rga/rga.c | 16 ---------------- drivers/media/platform/rockchip/rga/rga.h | 1 - 3 files changed, 9 insertions(+), 22 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +9 -5
@@ -14,7 +14,6 @@#include <media/videobuf2-dma-sg.h> #include <media/videobuf2-v4l2.h> -#include "rga-hw.h" #include "rga.h" static ssize_t fill_descriptors(struct rga_dma_desc *desc, size_t max_desc,
@@ -95,14 +94,19 @@ static int rga_buf_init(struct vb2_buffer *vb)return 0 ; } -static int get_plane_offset (struct rga_frame *f,int plane) +static int get_plane_offset (struct rga_frame *f, +const struct v4l2_format_info *info, +int plane) { +u32 stride = f->pix.plane_fmt[0 ].bytesperline; +if (plane ==0 )return 0 ;if (plane ==1 ) -return f->width * f->height; +return stride * f->height;if (plane ==2 ) -return f->width * f->height + (f->width * f->height / f->fmt->uv_factor); +return stride * f->height + + (stride * f->height / info->hdiv / info->vdiv);return -EINVAL ; }
@@ -148,7 +152,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb)/* Fill the remaining planes */ info =v4l2_format_info (f->fmt->fourcc);for (i = info->mem_planes; i < info->comp_planes; i++) - offsets[i] =get_plane_offset (f, i); + offsets[i] =get_plane_offset (f, info, i); rbuf->offset.y_off = offsets[0 ]; rbuf->offset.u_off = offsets[1 ];
drivers/media/platform/rockchip/rga/rga.c +0 -16
@@ -190,7 +190,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_ALPHA_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, .depth = 32, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -199,7 +198,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, .depth = 32, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -208,7 +206,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_XBGR8888, .depth = 32, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -217,7 +214,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, .depth = 24, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -226,7 +222,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, .depth = 24, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -235,7 +230,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR4444, .depth = 16, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -244,7 +238,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR1555, .depth = 16, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -253,7 +246,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_BGR565, .depth = 16, - .uv_factor = 1, .y_div = 1, .x_div = 1, },
@@ -262,7 +254,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .uv_factor = 4, .y_div = 2, .x_div = 1, },
@@ -271,7 +262,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, .depth = 16, - .uv_factor = 2, .y_div = 1, .x_div = 1, },
@@ -280,7 +270,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .uv_factor = 4, .y_div = 2, .x_div = 1, },
@@ -289,7 +278,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .uv_factor = 4, .y_div = 2, .x_div = 1, },
@@ -298,7 +286,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, .depth = 16, - .uv_factor = 2, .y_div = 1, .x_div = 1, },
@@ -307,7 +294,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, .depth = 12, - .uv_factor = 4, .y_div = 2, .x_div = 2, },
@@ -316,7 +302,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422P, .depth = 16, - .uv_factor = 2, .y_div = 1, .x_div = 2, },
@@ -325,7 +310,6 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, .depth = 12, - .uv_factor = 4, .y_div = 2, .x_div = 2, },
drivers/media/platform/rockchip/rga/rga.h +0 -1
@@ -17,7 +17,6 @@struct rga_fmt {u32 fourcc;int depth; -u8 uv_factor;u8 y_div;u8 x_div;u8 color_swap;
Signature · 1 line
2.53.0
PATCH v4 8/27 media: rockchip: rga: remove redundant rga_frame variables
In reply to Sven PüschelRemove the redundant rga_frame variables width, height and color space. The value of these variables is already contained in the pix member of rga_frame. The code also keeps these values in sync. Therefore drop them in favor of the existing pix member.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 6 ++--- drivers/media/platform/rockchip/rga/rga-hw.c | 6 ++--- drivers/media/platform/rockchip/rga/rga.c | 32 ++++++++++----------------- drivers/media/platform/rockchip/rga/rga.h | 5 ----- 4 files changed, 18 insertions(+), 31 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +3 -3
@@ -103,10 +103,10 @@ static int get_plane_offset(struct rga_frame *f,if (plane ==0 )return 0 ;if (plane ==1 ) -return stride * f->height; +return stride * f->pix.height;if (plane ==2 ) -return stride * f->height + - (stride * f->height / info->hdiv / info->vdiv); +return stride * f->pix.height + + (stride * f->pix.height / info->hdiv / info->vdiv);return -EINVAL ; }
drivers/media/platform/rockchip/rga/rga-hw.c +3 -3
@@ -53,7 +53,7 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_addr_offset *offset, x_div = frm->fmt->x_div; y_div = frm->fmt->y_div; uv_stride = frm->stride / x_div; - pixel_width = frm->stride / frm->width; + pixel_width = frm->stride / frm->pix.width; lt->y_off = offset->y_off + y * frm->stride + x * pixel_width; lt->u_off = offset->u_off + (y / y_div) * uv_stride + x / x_div;
@@ -191,7 +191,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx)if (RGA_COLOR_FMT_IS_YUV (ctx->in.fmt->hw_format) &&RGA_COLOR_FMT_IS_RGB (ctx->out.fmt->hw_format)) { -switch (ctx->in.colorspace) { +switch (ctx->in.pix.colorspace) {case V4L2_COLORSPACE_REC709 : src_info.data.csc_mode =RGA_SRC_CSC_MODE_BT709_R0 ;break ;
@@ -203,7 +203,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx)if (RGA_COLOR_FMT_IS_RGB (ctx->in.fmt->hw_format) &&RGA_COLOR_FMT_IS_YUV (ctx->out.fmt->hw_format)) { -switch (ctx->out.colorspace) { +switch (ctx->out.pix.colorspace) {case V4L2_COLORSPACE_REC709 : dst_info.data.csc_mode =RGA_SRC_CSC_MODE_BT709_R0 ;break ;
drivers/media/platform/rockchip/rga/rga.c +12 -20
@@ -329,9 +329,6 @@ static struct rga_fmt *rga_fmt_find(u32 pixelformat) }static struct rga_frame def_frame = { - .width =DEFAULT_WIDTH , - .height =DEFAULT_HEIGHT , - .colorspace =V4L2_COLORSPACE_DEFAULT , .crop.left =0 , .crop.top =0 , .crop.width =DEFAULT_WIDTH ,
@@ -363,9 +360,9 @@ static int rga_open(struct file *file) ctx->out = def_frame;v4l2_fill_pixfmt_mp (&ctx->in.pix, - ctx->in.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->in.fmt->fourcc,DEFAULT_WIDTH ,DEFAULT_HEIGHT );v4l2_fill_pixfmt_mp (&ctx->out.pix, - ctx->out.fmt->fourcc, ctx->out.width, ctx->out.height); + ctx->out.fmt->fourcc,DEFAULT_WIDTH ,DEFAULT_HEIGHT );if (mutex_lock_interruptible (&rga->mutex)) {kfree (ctx);
@@ -453,10 +450,8 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)if (IS_ERR (frm))return PTR_ERR (frm); -v4l2_fill_pixfmt_mp (pix_fmt, frm->fmt->fourcc, frm->width, frm->height); - + *pix_fmt = frm->pix; pix_fmt->field =V4L2_FIELD_NONE ; - pix_fmt->colorspace = frm->colorspace;return 0 ; }
@@ -505,27 +500,24 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) frm =rga_get_frame (ctx, f->type);if (IS_ERR (frm))return PTR_ERR (frm); - frm->width = pix_fmt->width; - frm->height = pix_fmt->height; frm->size =0 ;for (i =0 ; i < pix_fmt->num_planes; i++) frm->size += pix_fmt->plane_fmt[i].sizeimage; frm->fmt =rga_fmt_find (pix_fmt->pixelformat); frm->stride = pix_fmt->plane_fmt[0 ].bytesperline; - frm->colorspace = pix_fmt->colorspace;/* Reset crop settings */ frm->crop.left =0 ; frm->crop.top =0 ; - frm->crop.width = frm->width; - frm->crop.height = frm->height; + frm->crop.width = pix_fmt->width; + frm->crop.height = pix_fmt->height; frm->pix = *pix_fmt;v4l2_dbg (debug,1 , &rga->v4l2_dev,"[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n" ,V4L2_TYPE_IS_OUTPUT (f->type) ?"OUTPUT" :"CAPTURE" , - &frm->fmt->fourcc, frm->width, frm->height, + &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, frm->stride, frm->size);for (i =0 ; i < pix_fmt->num_planes; i++) {
@@ -579,8 +571,8 @@ static int vidioc_g_selection(struct file *file, void *priv, }else { s->r.left =0 ; s->r.top =0 ; - s->r.width = f->width; - s->r.height = f->height; + s->r.width = f->pix.width; + s->r.height = f->pix.height; }return 0 ;
@@ -629,8 +621,8 @@ static int vidioc_s_selection(struct file *file, void *priv,return -EINVAL ; } -if (s->r.left + s->r.width > f->width || - s->r.top + s->r.height > f->height || +if (s->r.left + s->r.width > f->pix.width || + s->r.top + s->r.height > f->pix.height || s->r.width <MIN_WIDTH || s->r.height <MIN_HEIGHT ) {v4l2_dbg (debug,1 , &rga->v4l2_dev,"unsupported crop value.\n" );return -EINVAL ;
@@ -821,8 +813,8 @@ static int rga_probe(struct platform_device *pdev) goto rel_m2m; } - def_frame.stride = (def_frame.width * def_frame.fmt->depth) >>3 ; - def_frame.size = def_frame.stride * def_frame.height; + def_frame.stride = (DEFAULT_WIDTH * def_frame.fmt->depth) >>3 ; + def_frame.size = def_frame.stride *DEFAULT_HEIGHT ; ret =video_register_device (vfd,VFL_TYPE_VIDEO ,-1 );if (ret) {
drivers/media/platform/rockchip/rga/rga.h +0 -5
@@ -24,11 +24,6 @@ struct rga_fmt { };struct rga_frame { -/* Original dimensions */ -u32 width; -u32 height; -u32 colorspace; -/* Crop */ struct v4l2_rect crop;
Signature · 1 line
2.53.0
PATCH v4 9/27 media: rockchip: rga: announce and sync colorimetry
In reply to Sven PüschelAnnounce the capability to adjust the quantization and ycbcr_enc on the capture side and check if the SET_CSC flag is set when the colorimetry is changed. Furthermore copy the colorimetry from the output to the capture side to fix the currently failing v4l2-compliance tests, which expect exactly this behavior.
--- drivers/media/platform/rockchip/rga/rga.c | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/media/platform/rockchip/rga/rga.c +37 -0
@@ -437,6 +437,15 @@ static int vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtdesc *f fmt = &formats[f->index]; f->pixelformat = fmt->fourcc; +if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE && + f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ) +return 0 ; + +/* allow changing the quantization and xfer func for YUV formats */ +if (v4l2_is_format_yuv (v4l2_format_info (f->pixelformat))) + f->flags |=V4L2_FMT_FLAG_CSC_QUANTIZATION | +V4L2_FMT_FLAG_CSC_YCBCR_ENC ; +return 0 ; }
@@ -459,8 +468,25 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)static int vidioc_try_fmt (struct file *file,void *priv,struct v4l2_format *f) {struct v4l2_pix_format_mplane *pix_fmt = &f->fmt.pix_mp; +struct rga_ctx *ctx =file_to_rga_ctx (file);struct rga_fmt *fmt; +if (V4L2_TYPE_IS_CAPTURE (f->type)) { +const struct rga_frame *frm; + + frm =rga_get_frame (ctx, f->type); +if (IS_ERR (frm)) +return PTR_ERR (frm); + +if (!(pix_fmt->flags &V4L2_PIX_FMT_FLAG_SET_CSC )) { + pix_fmt->quantization = frm->pix.quantization; + pix_fmt->ycbcr_enc = frm->pix.ycbcr_enc; + } +/* disallow values not announced in vidioc_enum_fmt */ + pix_fmt->colorspace = frm->pix.colorspace; + pix_fmt->xfer_func = frm->pix.xfer_func; + } + fmt =rga_fmt_find (pix_fmt->pixelformat);if (!fmt) fmt = &formats[0 ];
@@ -506,6 +532,17 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) frm->fmt =rga_fmt_find (pix_fmt->pixelformat); frm->stride = pix_fmt->plane_fmt[0 ].bytesperline; +/* +* Copy colorimetry from output to capture as required by the +* v4l2-compliance tests +*/ +if (V4L2_TYPE_IS_OUTPUT (f->type)) { + ctx->out.pix.colorspace = pix_fmt->colorspace; + ctx->out.pix.ycbcr_enc = pix_fmt->ycbcr_enc; + ctx->out.pix.quantization = pix_fmt->quantization; + ctx->out.pix.xfer_func = pix_fmt->xfer_func; + } +/* Reset crop settings */ frm->crop.left =0 ; frm->crop.top =0 ;
Signature · 1 line
2.53.0
PATCH v4 10/27 media: rockchip: rga: move hw specific parts to a dedicated struct
In reply to Sven PüschelIn preparation for the RGA3 unit, move RGA2 specific parts from rga.c to rga-hw.c and create a struct to reference the RGA2 specific functions and formats. This also allows to remove the rga-hw.h reference from the include list of the rga driver.
Also document the command finish interrupt with a dedicated define.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 166 ++++++++++++++++++++- drivers/media/platform/rockchip/rga/rga-hw.h | 5 +- drivers/media/platform/rockchip/rga/rga.c | 211 +++++---------------------- drivers/media/platform/rockchip/rga/rga.h | 23 ++- 4 files changed, 227 insertions(+), 178 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +164 -2
@@ -437,8 +437,8 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } -void rga_hw_start (struct rockchip_rga *rga, -struct rga_vb_buffer *src,struct rga_vb_buffer *dst) +static void rga_hw_start (struct rockchip_rga *rga, +struct rga_vb_buffer *src,struct rga_vb_buffer *dst) {struct rga_ctx *ctx = rga->curr;
@@ -452,3 +452,165 @@ void rga_hw_start(struct rockchip_rga *rga,rga_write (rga,RGA_CMD_CTRL ,0x1 ); } + +static bool rga_handle_irq (struct rockchip_rga *rga) +{ +int intr; + + intr =rga_read (rga,RGA_INT ) &0xf ; + +rga_mod (rga,RGA_INT , intr <<4 ,0xf <<4 ); + +return intr &RGA_INT_COMMAND_FINISHED ; +} + +static void rga_get_version (struct rockchip_rga *rga) +{ + rga->version.major = (rga_read (rga,RGA_VERSION_INFO ) >>24 ) &0xFF ; + rga->version.minor = (rga_read (rga,RGA_VERSION_INFO ) >>20 ) &0x0F ; +} + +static struct rga_fmt formats[] = { + { + .fourcc =V4L2_PIX_FMT_ARGB32 , + .color_swap =RGA_COLOR_ALPHA_SWAP , + .hw_format =RGA_COLOR_FMT_ABGR8888 , + .depth =32 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_ABGR32 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_ABGR8888 , + .depth =32 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_XBGR32 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_XBGR8888 , + .depth =32 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_RGB24 , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_RGB888 , + .depth =24 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_BGR24 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_RGB888 , + .depth =24 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_ARGB444 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_ABGR4444 , + .depth =16 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_ARGB555 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_ABGR1555 , + .depth =16 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_RGB565 , + .color_swap =RGA_COLOR_RB_SWAP , + .hw_format =RGA_COLOR_FMT_BGR565 , + .depth =16 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_NV21 , + .color_swap =RGA_COLOR_UV_SWAP , + .hw_format =RGA_COLOR_FMT_YUV420SP , + .depth =12 , + .y_div =2 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_NV61 , + .color_swap =RGA_COLOR_UV_SWAP , + .hw_format =RGA_COLOR_FMT_YUV422SP , + .depth =16 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_NV12 , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_YUV420SP , + .depth =12 , + .y_div =2 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_NV12M , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_YUV420SP , + .depth =12 , + .y_div =2 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_NV16 , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_YUV422SP , + .depth =16 , + .y_div =1 , + .x_div =1 , + }, + { + .fourcc =V4L2_PIX_FMT_YUV420 , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_YUV420P , + .depth =12 , + .y_div =2 , + .x_div =2 , + }, + { + .fourcc =V4L2_PIX_FMT_YUV422P , + .color_swap =RGA_COLOR_NONE_SWAP , + .hw_format =RGA_COLOR_FMT_YUV422P , + .depth =16 , + .y_div =1 , + .x_div =2 , + }, + { + .fourcc =V4L2_PIX_FMT_YVU420 , + .color_swap =RGA_COLOR_UV_SWAP , + .hw_format =RGA_COLOR_FMT_YUV420P , + .depth =12 , + .y_div =2 , + .x_div =2 , + }, +}; + +const struct rga_hw rga2_hw = { + .formats = formats, + .num_formats =ARRAY_SIZE (formats), + .cmdbuf_size =RGA_CMDBUF_SIZE , + .min_width =MIN_WIDTH , + .max_width =MAX_WIDTH , + .min_height =MIN_HEIGHT , + .max_height =MAX_HEIGHT , + + .start = rga_hw_start, + .handle_irq = rga_handle_irq, + .get_version = rga_get_version, +};
drivers/media/platform/rockchip/rga/rga-hw.h +2 -3
@@ -15,9 +15,6 @@#define MIN_WIDTH 34#define MIN_HEIGHT 34 -#define DEFAULT_WIDTH 100 -#define DEFAULT_HEIGHT 100 -#define RGA_TIMEOUT 500/* Registers address */
@@ -178,6 +175,8 @@#define RGA_ALPHA_COLOR_NORMAL 0#define RGA_ALPHA_COLOR_MULTIPLY_CAL 1 +#define RGA_INT_COMMAND_FINISHED 4 +/* Registers union */ union rga_mode_ctrl {unsigned int val;
drivers/media/platform/rockchip/rga/rga.c +40 -171
339 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga.h +21 -2
@@ -14,6 +14,9 @@#define RGA_NAME "rockchip-rga" +#define DEFAULT_WIDTH 100 +#define DEFAULT_HEIGHT 100 +struct rga_fmt {u32 fourcc;int depth;
@@ -68,6 +71,8 @@ static inline struct rga_ctx *file_to_rga_ctx(struct file *filp) return container_of(file_to_v4l2_fh(filp), struct rga_ctx, fh); } +struct rga_hw ; +struct rockchip_rga {struct v4l2_device v4l2_dev;struct v4l2_m2m_dev *m2m_dev;
@@ -88,6 +93,8 @@ struct rockchip_rga {struct rga_ctx *curr;dma_addr_t cmdbuf_phy;void *cmdbuf_virt; + +const struct rga_hw *hw; };struct rga_addr_offset {
@@ -138,7 +145,19 @@ static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask) rga_write(rga, reg, temp); }; -void rga_hw_start (struct rockchip_rga *rga, -struct rga_vb_buffer *src,struct rga_vb_buffer *dst); +struct rga_hw { +struct rga_fmt *formats; +u32 num_formats; +size_t cmdbuf_size; +u32 min_width, min_height; +u32 max_width, max_height; + +void (*start)(struct rockchip_rga *rga, +struct rga_vb_buffer *src,struct rga_vb_buffer *dst); +bool (*handle_irq)(struct rockchip_rga *rga); +void (*get_version)(struct rockchip_rga *rga); +}; + +extern const struct rga_hw rga2_hw;#endif
Signature · 1 line
2.53.0
PATCH v4 11/27 media: rockchip: rga: avoid odd frame sizes for YUV formats
In reply to Sven PüschelAvoid odd frame sizes for YUV formats, as they may cause undefined behavior. This is done in preparation for the RGA3, which hangs when the output format is set to 129x129 pixel YUV420 SP (NV12).
This requirement is documented explicitly for the RGA3 in section 5.6.3 of the RK3588 TRM Part 2. For the RGA2 the RK3588 TRM Part 2 (section 6.1.2) and RK3568 TRM Part 2 (section 14.2) only mentions the x/y offsets and stride aligning requirements. But the vendor driver for the RGA2 also contains checks for the width and height to be aligned to 2 bytes.
--- drivers/media/platform/rockchip/rga/rga.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/media/platform/rockchip/rga/rga.c +14 -5
@@ -337,6 +337,19 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)struct rga_ctx *ctx =file_to_rga_ctx (file);const struct rga_hw *hw = ctx->rga->hw;struct rga_fmt *fmt; +struct v4l2_frmsize_stepwise frmsize = { + .min_width = hw->min_width, + .max_width = hw->max_width, + .min_height = hw->min_height, + .max_height = hw->max_height, + .step_width =1 , + .step_height =1 , + }; + +if (v4l2_is_format_yuv (v4l2_format_info (pix_fmt->pixelformat))) { + frmsize.step_width =2 ; + frmsize.step_height =2 ; + }if (V4L2_TYPE_IS_CAPTURE (f->type)) {const struct rga_frame *frm;
@@ -358,11 +371,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)if (!fmt) fmt = &hw->formats[0 ]; - pix_fmt->width =clamp (pix_fmt->width, - hw->min_width, hw->max_width); - pix_fmt->height =clamp (pix_fmt->height, - hw->min_height, hw->max_height); - +v4l2_apply_frmsize_constraints (&pix_fmt->width, &pix_fmt->height, &frmsize);v4l2_fill_pixfmt_mp (pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height); pix_fmt->field =V4L2_FIELD_NONE ;
Signature · 1 line
2.53.0
PATCH v4 12/27 media: rockchip: rga: calculate x_div/y_div using v4l2_format_info
In reply to Sven PüschelCalculate the x_div and y_div variables with the information from v4l2_format_info instead of storing these in the rga_fmt struct.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 45 +++++++--------------------- drivers/media/platform/rockchip/rga/rga.h | 2 -- 2 files changed, 11 insertions(+), 36 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +11 -34
@@ -42,6 +42,7 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_addr_offset *offset, {struct rga_corners_addr_offset offsets;struct rga_addr_offset *lt, *lb, *rt, *rb; +const struct v4l2_format_info *format_info;unsigned int x_div =0 , y_div =0 , uv_stride =0 , pixel_width =0 ;
@@ -50,8 +51,16 @@ rga_get_addr_offset(struct rga_frame *frm, struct rga_addr_offset *offset, rt = &offsets.right_top; rb = &offsets.right_bottom; - x_div = frm->fmt->x_div; - y_div = frm->fmt->y_div; + format_info =v4l2_format_info (frm->pix.pixelformat); +/* x_div is only used for the u/v planes. +* When the format doesn't have these, use 1 to avoid a division by zero. +*/ +if (format_info->bpp[1 ]) + x_div = format_info->hdiv * format_info->bpp_div[1 ] / + format_info->bpp[1 ]; +else + x_div =1 ; + y_div = format_info->vdiv; uv_stride = frm->stride / x_div; pixel_width = frm->stride / frm->pix.width;
@@ -476,128 +485,96 @@ static struct rga_fmt formats[] = { .color_swap = RGA_COLOR_ALPHA_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, .depth = 32, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_ABGR32, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, .depth = 32, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_XBGR32, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_XBGR8888, .depth = 32, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_RGB24, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, .depth = 24, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_BGR24, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, .depth = 24, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_ARGB444, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR4444, .depth = 16, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_ARGB555, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR1555, .depth = 16, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_RGB565, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_BGR565, .depth = 16, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_NV21, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .y_div = 2, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_NV61, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, .depth = 16, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_NV12, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .y_div = 2, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_NV12M, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, .depth = 12, - .y_div = 2, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_NV16, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, .depth = 16, - .y_div = 1, - .x_div = 1, }, { .fourcc = V4L2_PIX_FMT_YUV420, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, .depth = 12, - .y_div = 2, - .x_div = 2, }, { .fourcc = V4L2_PIX_FMT_YUV422P, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422P, .depth = 16, - .y_div = 1, - .x_div = 2, }, { .fourcc = V4L2_PIX_FMT_YVU420, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, .depth = 12, - .y_div = 2, - .x_div = 2, }, };
drivers/media/platform/rockchip/rga/rga.h +0 -2
@@ -20,8 +20,6 @@struct rga_fmt {u32 fourcc;int depth; -u8 y_div; -u8 x_div;u8 color_swap;u8 hw_format; };
Signature · 1 line
2.53.0
PATCH v4 13/27 media: rockchip: rga: move cmdbuf to rga_ctx
In reply to Sven PüschelMove the command buffer to the rga_ctx struct in preparation to reuse an already prepared command buffer. This allows to split the command buffer setup in a further commit to setup a template for the command buffer at streamon and only update the buffer addresses in device_run and trigger the command stream. No sync point is added, as one command buffer should only be used for one conversion at a time.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 28 +++++++--------- drivers/media/platform/rockchip/rga/rga.c | 48 ++++++++++++++++------------ drivers/media/platform/rockchip/rga/rga.h | 5 +-- 3 files changed, 41 insertions(+), 40 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +11 -17
@@ -122,8 +122,7 @@ static struct rga_addr_offset *rga_lookup_draw_pos(structstatic void rga_cmd_set_src_addr (struct rga_ctx *ctx,dma_addr_t dma_addr) { -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int reg; reg =RGA_MMU_SRC_BASE -RGA_MODE_BASE_REG ;
@@ -135,8 +134,7 @@ static void rga_cmd_set_src_addr(struct rga_ctx *ctx, dma_addr_t dma_addr)static void rga_cmd_set_src1_addr (struct rga_ctx *ctx,dma_addr_t dma_addr) { -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int reg; reg =RGA_MMU_SRC1_BASE -RGA_MODE_BASE_REG ;
@@ -148,8 +146,7 @@ static void rga_cmd_set_src1_addr(struct rga_ctx *ctx, dma_addr_t dma_addr)static void rga_cmd_set_dst_addr (struct rga_ctx *ctx,dma_addr_t dma_addr) { -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int reg; reg =RGA_MMU_DST_BASE -RGA_MODE_BASE_REG ;
@@ -162,7 +159,7 @@ static void rga_cmd_set_dst_addr(struct rga_ctx *ctx, dma_addr_t dma_addr)static void rga_cmd_set_trans_info (struct rga_ctx *ctx) {struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int scale_dst_w, scale_dst_h;unsigned int src_h, src_w, dst_h, dst_w;union rga_src_info src_info;
@@ -322,8 +319,7 @@ static void rga_cmd_set_src_info(struct rga_ctx *ctx, struct rga_addr_offset *offset) {struct rga_corners_addr_offset src_offsets; -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int src_h, src_w, src_x, src_y; src_h = ctx->in.crop.height;
@@ -350,8 +346,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx, {struct rga_addr_offset *dst_offset;struct rga_corners_addr_offset offsets; -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;unsigned int dst_h, dst_w, dst_x, dst_y;unsigned int mir_mode =0 ;unsigned int rot_mode =0 ;
@@ -397,8 +392,7 @@ static void rga_cmd_set_dst_info(struct rga_ctx *ctx,static void rga_cmd_set_mode (struct rga_ctx *ctx) { -struct rockchip_rga *rga = ctx->rga; -u32 *dest = rga->cmdbuf_virt; +u32 *dest = ctx->cmdbuf_virt;union rga_mode_ctrl mode;union rga_alpha_ctrl0 alpha_ctrl0;union rga_alpha_ctrl1 alpha_ctrl1;
@@ -423,7 +417,7 @@ static void rga_cmd_set(struct rga_ctx *ctx, {struct rockchip_rga *rga = ctx->rga; -memset (rga->cmdbuf_virt,0 ,RGA_CMDBUF_SIZE *4 ); +memset (ctx->cmdbuf_virt,0 ,RGA_CMDBUF_SIZE *4 );rga_cmd_set_src_addr (ctx, src->dma_desc_pa);/*
@@ -439,11 +433,11 @@ static void rga_cmd_set(struct rga_ctx *ctx,rga_cmd_set_dst_info (ctx, &dst->offset);rga_cmd_set_trans_info (ctx); -rga_write (rga,RGA_CMD_BASE , rga->cmdbuf_phy); +rga_write (rga,RGA_CMD_BASE , ctx->cmdbuf_phy);/* sync CMD buf for RGA */ -dma_sync_single_for_device (rga->dev, rga->cmdbuf_phy, -PAGE_SIZE ,DMA_BIDIRECTIONAL ); +dma_sync_single_for_device (rga->dev, ctx->cmdbuf_phy, +PAGE_SIZE ,DMA_BIDIRECTIONAL ); } static void rga_hw_start(struct rockchip_rga *rga,
drivers/media/platform/rockchip/rga/rga.c +27 -21
97 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga.h +3 -2
@@ -53,6 +53,9 @@ struct rga_ctx {struct rga_frame out;struct v4l2_ctrl_handler ctrl_handler; +void *cmdbuf_virt; +dma_addr_t cmdbuf_phy; +int osequence;int csequence;
@@ -89,8 +92,6 @@ struct rockchip_rga {spinlock_t ctrl_lock;struct rga_ctx *curr; -dma_addr_t cmdbuf_phy; -void *cmdbuf_virt;const struct rga_hw *hw; };
Signature · 1 line
2.53.0
PATCH v4 14/27 media: rockchip: rga: align stride to 4 bytes
In reply to Sven PüschelAdd an alignment setting to rga_hw to set the desired stride alignment. As the RGA2 register for the stride counts in word units, the code already divides the bytesperline value by 4 when writing it into the register. Therefore fix the alignment to a multiple of 4 to avoid potential off by one errors due from the division.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 ++++++----- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +1 -0
@@ -580,6 +580,7 @@ const struct rga_hw rga2_hw = { .max_width = MAX_WIDTH, .min_height = MIN_HEIGHT, .max_height = MAX_HEIGHT, + .stride_alignment = 4, .start = rga_hw_start, .handle_irq = rga_handle_irq,
drivers/media/platform/rockchip/rga/rga.c +6 -5
@@ -234,10 +234,10 @@ static int rga_open(struct file *file) ctx->in = def_frame; ctx->out = def_frame; -v4l2_fill_pixfmt_mp (&ctx->in.pix, - ctx->in.fmt->fourcc, def_width, def_height); -v4l2_fill_pixfmt_mp (&ctx->out.pix, - ctx->out.fmt->fourcc, def_width, def_height); +v4l2_fill_pixfmt_mp_aligned (&ctx->in.pix, ctx->in.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment); +v4l2_fill_pixfmt_mp_aligned (&ctx->out.pix, ctx->out.fmt->fourcc, + def_width, def_height, rga->hw->stride_alignment);if (mutex_lock_interruptible (&rga->mutex)) { ret = -ERESTARTSYS ;
@@ -393,7 +393,8 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) fmt = &hw->formats[0 ];v4l2_apply_frmsize_constraints (&pix_fmt->width, &pix_fmt->height, &frmsize); -v4l2_fill_pixfmt_mp (pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt->height); +v4l2_fill_pixfmt_mp_aligned (pix_fmt, pix_fmt->pixelformat, + pix_fmt->width, pix_fmt->height, hw->stride_alignment); pix_fmt->field =V4L2_FIELD_NONE ;return 0 ;
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -150,6 +150,7 @@ struct rga_hw {size_t cmdbuf_size;u32 min_width, min_height;u32 max_width, max_height; +u8 stride_alignment;void (*start)(struct rockchip_rga *rga,struct rga_vb_buffer *src,struct rga_vb_buffer *dst);
Signature · 1 line
2.53.0
PATCH v4 15/27 media: rockchip: rga: prepare cmdbuf on streamon
In reply to Sven PüschelPrepare the command buffer on streamon to reuse it's contents instead of completely writing it for every frame. Due to the stream settings being fixed after a streamon we only need to replace the source and destination addresses for each frame. This reduces the amount of CPU and memory operations done in each frame.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 13 +++++++++---- drivers/media/platform/rockchip/rga/rga.c | 13 ++++++++++++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +9 -4
@@ -417,8 +417,6 @@ static void rga_cmd_set(struct rga_ctx *ctx, {struct rockchip_rga *rga = ctx->rga; -memset (ctx->cmdbuf_virt,0 ,RGA_CMDBUF_SIZE *4 ); -rga_cmd_set_src_addr (ctx, src->dma_desc_pa);/* * Due to hardware bug,
@@ -427,11 +425,9 @@ static void rga_cmd_set(struct rga_ctx *ctx,rga_cmd_set_src1_addr (ctx, dst->dma_desc_pa);rga_cmd_set_dst_addr (ctx, dst->dma_desc_pa); -rga_cmd_set_mode (ctx);rga_cmd_set_src_info (ctx, &src->offset);rga_cmd_set_dst_info (ctx, &dst->offset); -rga_cmd_set_trans_info (ctx);rga_write (rga,RGA_CMD_BASE , ctx->cmdbuf_phy);
@@ -440,6 +436,14 @@ static void rga_cmd_set(struct rga_ctx *ctx, PAGE_SIZE, DMA_BIDIRECTIONAL); } +static void rga_hw_setup_cmdbuf (struct rga_ctx *ctx) +{ +memset (ctx->cmdbuf_virt,0 ,RGA_CMDBUF_SIZE *4 ); + +rga_cmd_set_mode (ctx); +rga_cmd_set_trans_info (ctx); +} +static void rga_hw_start (struct rockchip_rga *rga,struct rga_vb_buffer *src,struct rga_vb_buffer *dst) {
@@ -582,6 +586,7 @@ const struct rga_hw rga2_hw = { .max_height = MAX_HEIGHT, .stride_alignment = 4, + .setup_cmdbuf = rga_hw_setup_cmdbuf, .start = rga_hw_start, .handle_irq = rga_handle_irq, .get_version = rga_get_version,
drivers/media/platform/rockchip/rga/rga.c +12 -1
@@ -568,6 +568,17 @@ static int vidioc_s_selection(struct file *file, void *priv,return ret; } +static int vidioc_streamon (struct file *file,void *priv, +enum v4l2_buf_type type) +{ +struct rga_ctx *ctx =file_to_rga_ctx (file); +const struct rga_hw *hw = ctx->rga->hw; + + hw->setup_cmdbuf (ctx); + +return v4l2_m2m_streamon (file, ctx->fh.m2m_ctx, type); +} +static const struct v4l2_ioctl_ops rga_ioctl_ops = { .vidioc_querycap = vidioc_querycap,
@@ -592,7 +603,7 @@ static const struct v4l2_ioctl_ops rga_ioctl_ops = { .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, - .vidioc_streamon = v4l2_m2m_ioctl_streamon, + .vidioc_streamon = vidioc_streamon, .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, .vidioc_g_selection = vidioc_g_selection,
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -152,6 +152,7 @@ struct rga_hw {u32 max_width, max_height;u8 stride_alignment; +void (*setup_cmdbuf)(struct rga_ctx *ctx);void (*start)(struct rockchip_rga *rga,struct rga_vb_buffer *src,struct rga_vb_buffer *dst);bool (*handle_irq)(struct rockchip_rga *rga);
Signature · 1 line
2.53.0
PATCH v4 16/27 media: rockchip: rga: check scaling factor
In reply to Sven PüschelCheck the scaling factor to avoid potential problems. This is relevant for the upcoming RGA3 support, as it can hang when the scaling factor is exceeded.
There are two relevant scenarios that have to be considered to protect against invalid scaling values:
When the output or capture is already streaming, setting the format on the other side should consider the max scaling factor and clamp it accordingly. This is only done in the streaming case, as it otherwise may unintentionally clamp the value when the application sets the first format (due to a default format on the other side).
When the format is set on both sides first, then the format won't be corrected by above means. Therefore the second streamon call has to check the scaling factor and fail otherwise.
As try functions should only be state aware if specified, the scaling limitation is only done in s_fmt.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga-hw.h | 1 + drivers/media/platform/rockchip/rga/rga.c | 47 ++++++++++++++++++++++++++++ drivers/media/platform/rockchip/rga/rga.h | 1 + 4 files changed, 50 insertions(+)
drivers/media/platform/rockchip/rga/rga-hw.c +1 -0
@@ -584,6 +584,7 @@ const struct rga_hw rga2_hw = { .max_width = MAX_WIDTH, .min_height = MIN_HEIGHT, .max_height = MAX_HEIGHT, + .max_scaling_factor = MAX_SCALING_FACTOR, .stride_alignment = 4, .setup_cmdbuf = rga_hw_setup_cmdbuf,
drivers/media/platform/rockchip/rga/rga-hw.h +1 -0
@@ -14,6 +14,7 @@#define MIN_WIDTH 34#define MIN_HEIGHT 34 +#define MAX_SCALING_FACTOR 16#define RGA_TIMEOUT 500
drivers/media/platform/rockchip/rga/rga.c +47 -0
69 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -150,6 +150,7 @@ struct rga_hw {size_t cmdbuf_size;u32 min_width, min_height;u32 max_width, max_height; +u8 max_scaling_factor;u8 stride_alignment;void (*setup_cmdbuf)(struct rga_ctx *ctx);
Signature · 1 line
2.53.0
PATCH v4 17/27 media: rockchip: rga: use card type to specify rga type
In reply to Sven PüschelIn preparation of the RGA3 support add a filed to the rga_hw struct to specify the desired card type value. This allows the user to differentiate the RGA2 and RGA3 video device nodes.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 4 +++- drivers/media/platform/rockchip/rga/rga.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/rga-hw.c +1 -0
@@ -577,6 +577,7 @@ static struct rga_fmt formats[] = { };const struct rga_hw rga2_hw = { + .card_type ="rga2" , .formats = formats, .num_formats =ARRAY_SIZE (formats), .cmdbuf_size =RGA_CMDBUF_SIZE ,
drivers/media/platform/rockchip/rga/rga.c +3 -1
@@ -306,8 +306,10 @@ static const struct v4l2_file_operations rga_fops = {static int vidioc_querycap (struct file *file,void *priv,struct v4l2_capability *cap) { +struct rockchip_rga *rga =video_drvdata (file); +strscpy (cap->driver,RGA_NAME ,sizeof (cap->driver)); -strscpy (cap->card,"rockchip-rga" ,sizeof (cap->card)); +strscpy (cap->card, rga->hw->card_type,sizeof (cap->card));strscpy (cap->bus_info,"platform:rga" ,sizeof (cap->bus_info));return 0 ;
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -145,6 +145,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask) };struct rga_hw { +const char *card_type;struct rga_fmt *formats;u32 num_formats;size_t cmdbuf_size;
Signature · 1 line
2.53.0
PATCH v4 18/27 media: rockchip: rga: change offset to dma_addresses
In reply to Sven PüschelChange the offset to dma_addresses, as the current naming is misleading. The offset naming comes from the fact that it references the offset in the mapped iommu address space. But from the hardware point of view this is an address, as also pointed out by the register naming (e.g. RGA_DST_Y_RGB_BASE_ADDR). Therefore also change the type to dma_addr_t, as with an external iommu driver this would also be the correct type.
This change is a preparation for the RGA3 support, which uses an external iommu and therefore just gets an dma_addr_t for each buffer. The field renaming allows to reuse the existing fields of rga_vb_buffer to store these values.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 12 +-- drivers/media/platform/rockchip/rga/rga-hw.c | 105 +++++++++++++------------- drivers/media/platform/rockchip/rga/rga.h | 12 +-- 3 files changed, 64 insertions(+), 65 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +6 -6
@@ -121,7 +121,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb)size_t curr_desc =0 ;int i;const struct v4l2_format_info *info; -unsigned int offsets[VIDEO_MAX_PLANES ]; +unsigned int dma_addrs[VIDEO_MAX_PLANES ];if (IS_ERR (f))return PTR_ERR (f);
@@ -145,18 +145,18 @@ static int rga_buf_prepare(struct vb2_buffer *vb) "Failed to map video buffer to RGA\n");return n_desc; } - offsets[i] = curr_desc <<PAGE_SHIFT ; + dma_addrs[i] = curr_desc <<PAGE_SHIFT ; curr_desc += n_desc; }/* Fill the remaining planes */ info =v4l2_format_info (f->fmt->fourcc);for (i = info->mem_planes; i < info->comp_planes; i++) - offsets[i] =get_plane_offset (f, info, i); + dma_addrs[i] = dma_addrs[0 ] +get_plane_offset (f, info, i); - rbuf->offset.y_off = offsets[0 ]; - rbuf->offset.u_off = offsets[1 ]; - rbuf->offset.v_off = offsets[2 ]; + rbuf->dma_addrs.y_addr = dma_addrs[0 ]; + rbuf->dma_addrs.u_addr = dma_addrs[1 ]; + rbuf->dma_addrs.v_addr = dma_addrs[2 ];return 0 ; }
drivers/media/platform/rockchip/rga/rga-hw.c +52 -53
184 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga.h +6 -6
@@ -96,10 +96,10 @@ struct rockchip_rga {const struct rga_hw *hw; }; -struct rga_addr_offset { -unsigned int y_off; -unsigned int u_off; -unsigned int v_off; +struct rga_addrs { +dma_addr_t y_addr; +dma_addr_t u_addr; +dma_addr_t v_addr; };struct rga_vb_buffer {
@@ -111,8 +111,8 @@ struct rga_vb_buffer {dma_addr_t dma_desc_pa;size_t n_desc; -/* Plane offsets of this buffer into the mapping */ -struct rga_addr_offset offset; +/* Plane DMA addresses after the MMU mapping of the buffer */ +struct rga_addrs dma_addrs; };static inline struct rga_vb_buffer *vb_to_rga (struct vb2_v4l2_buffer *vb)
Signature · 1 line
2.53.0
PATCH v4 19/27 media: rockchip: rga: support external iommus
In reply to Sven PüschelIn preparation for the RGA3 add support for external iommus. This is a transition step to just disable the RGA2 specific mmu table setup code.
Currently a simple rga_hw struct field is used to set the internal iommu. But to handle the case of more sophisticated detection mechanisms (e.g. check for an iommu property in the device tree), it is abstracted by an inline function.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 31 ++++++++++++++++++--------- drivers/media/platform/rockchip/rga/rga-hw.c | 1 + drivers/media/platform/rockchip/rga/rga.c | 11 ++++++++-- drivers/media/platform/rockchip/rga/rga.h | 6 ++++++ 4 files changed, 37 insertions(+), 12 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +21 -10
@@ -12,6 +12,7 @@#include <media/v4l2-ioctl.h> #include <media/v4l2-mem2mem.h> #include <media/videobuf2-dma-sg.h> +#include <media/videobuf2-dma-contig.h> #include <media/videobuf2-v4l2.h> #include "rga.h"
@@ -82,6 +83,9 @@ static int rga_buf_init(struct vb2_buffer *vb)if (IS_ERR (f))return PTR_ERR (f); +if (!rga_has_internal_iommu (rga)) +return 0 ; + n_desc =DIV_ROUND_UP (f->size,PAGE_SIZE ); rbuf->n_desc = n_desc;
@@ -136,17 +140,21 @@ static int rga_buf_prepare(struct vb2_buffer *vb)for (i =0 ; i < vb->num_planes; i++) {vb2_set_plane_payload (vb, i, f->pix.plane_fmt[i].sizeimage); -/* Create local MMU table for RGA */ - n_desc =fill_descriptors (&rbuf->dma_desc[curr_desc], - rbuf->n_desc - curr_desc, -vb2_dma_sg_plane_desc (vb, i)); -if (n_desc <0 ) { -v4l2_err (&ctx->rga->v4l2_dev, -"Failed to map video buffer to RGA\n" ); -return n_desc; +if (rga_has_internal_iommu (ctx->rga)) { +/* Create local MMU table for RGA */ + n_desc =fill_descriptors (&rbuf->dma_desc[curr_desc], + rbuf->n_desc - curr_desc, +vb2_dma_sg_plane_desc (vb, i)); +if (n_desc <0 ) { +v4l2_err (&ctx->rga->v4l2_dev, +"Failed to map video buffer to RGA\n" ); +return n_desc; + } + dma_addrs[i] = curr_desc <<PAGE_SHIFT ; + curr_desc += n_desc; + }else { + dma_addrs[i] =vb2_dma_contig_plane_dma_addr (vb, i); } - dma_addrs[i] = curr_desc <<PAGE_SHIFT ; - curr_desc += n_desc; }/* Fill the remaining planes */
@@ -176,6 +184,9 @@ static void rga_buf_cleanup(struct vb2_buffer *vb)struct rga_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue);struct rockchip_rga *rga = ctx->rga; +if (!rga_has_internal_iommu (rga)) +return ; +dma_free_coherent (rga->dev, rbuf->n_desc *sizeof (*rbuf->dma_desc), rbuf->dma_desc, rbuf->dma_desc_pa); }
drivers/media/platform/rockchip/rga/rga-hw.c +1 -0
@@ -577,6 +577,7 @@ static struct rga_fmt formats[] = {const struct rga_hw rga2_hw = { .card_type ="rga2" , + .has_internal_iommu = true, .formats = formats, .num_formats =ARRAY_SIZE (formats), .cmdbuf_size =RGA_CMDBUF_SIZE ,
drivers/media/platform/rockchip/rga/rga.c +9 -2
@@ -23,6 +23,7 @@#include <media/v4l2-ioctl.h> #include <media/v4l2-mem2mem.h> #include <media/videobuf2-dma-sg.h> +#include <media/videobuf2-dma-contig.h> #include <media/videobuf2-v4l2.h> #include "rga.h"
@@ -95,7 +96,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) src_vq->io_modes =VB2_MMAP |VB2_DMABUF ; src_vq->drv_priv = ctx; src_vq->ops = &rga_qops; - src_vq->mem_ops = &vb2_dma_sg_memops; +if (rga_has_internal_iommu (ctx->rga)) + src_vq->mem_ops = &vb2_dma_sg_memops; +else + src_vq->mem_ops = &vb2_dma_contig_memops; src_vq->gfp_flags = __GFP_DMA32; src_vq->buf_struct_size =sizeof (struct rga_vb_buffer ); src_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ;
@@ -110,7 +114,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) dst_vq->io_modes =VB2_MMAP |VB2_DMABUF ; dst_vq->drv_priv = ctx; dst_vq->ops = &rga_qops; - dst_vq->mem_ops = &vb2_dma_sg_memops; +if (rga_has_internal_iommu (ctx->rga)) + dst_vq->mem_ops = &vb2_dma_sg_memops; +else + dst_vq->mem_ops = &vb2_dma_contig_memops; dst_vq->gfp_flags = __GFP_DMA32; dst_vq->buf_struct_size =sizeof (struct rga_vb_buffer ); dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ;
drivers/media/platform/rockchip/rga/rga.h +6 -0
@@ -146,6 +146,7 @@ static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)struct rga_hw {const char *card_type; +bool has_internal_iommu;struct rga_fmt *formats;u32 num_formats;size_t cmdbuf_size;
@@ -161,6 +162,11 @@ struct rga_hw { void (*get_version)(struct rockchip_rga *rga); }; +static inline bool rga_has_internal_iommu (const struct rockchip_rga *rga) +{ +return rga->hw->has_internal_iommu; +} +extern const struct rga_hw rga2_hw;#endif
Signature · 1 line
2.53.0
PATCH v4 20/27 media: rockchip: rga: share the interrupt when an external iommu is used
In reply to Sven PüschelFrom: Michael Olbrich <[email protected]>
The RGA3 and the corresponding iommu share the interrupt. So in that case, request a shared interrupt so that the iommu driver can request it as well.
--- drivers/media/platform/rockchip/rga/rga.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/rga.c +2 -1
@@ -761,7 +761,8 @@ static int rga_probe(struct platform_device *pdev) goto err_put_clk; } - ret =devm_request_irq (rga->dev, irq, rga_isr,0 , + ret =devm_request_irq (rga->dev, irq, rga_isr, +rga_has_internal_iommu (rga) ?0 :IRQF_SHARED ,dev_name (rga->dev), rga);if (ret <0 ) {dev_err (rga->dev,"failed to request irq\n" );
Signature · 1 line
2.53.0
PATCH v4 21/27 media: rockchip: rga: remove size from rga_frame
In reply to Sven PüschelThe size member is only used for the mmu page table mapping. Therefore avoid storing the value and instead only calculate it in place. This also avoids the calculation entirely when an external iommu is used.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 6 +++++- drivers/media/platform/rockchip/rga/rga.c | 8 ++------ drivers/media/platform/rockchip/rga/rga.h | 1 - 3 files changed, 7 insertions(+), 8 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +5 -1
@@ -79,6 +79,8 @@ static int rga_buf_init(struct vb2_buffer *vb)struct rockchip_rga *rga = ctx->rga;struct rga_frame *f =rga_get_frame (ctx, vb->vb2_queue->type);size_t n_desc =0 ; +u32 size =0 ; +u8 i;if (IS_ERR (f))return PTR_ERR (f);
@@ -86,7 +88,9 @@ static int rga_buf_init(struct vb2_buffer *vb)if (!rga_has_internal_iommu (rga))return 0 ; - n_desc =DIV_ROUND_UP (f->size,PAGE_SIZE ); +for (i =0 ; i < f->pix.num_planes; i++) + size += f->pix.plane_fmt[i].sizeimage; + n_desc =DIV_ROUND_UP (size,PAGE_SIZE ); rbuf->n_desc = n_desc; rbuf->dma_desc = dma_alloc_coherent(rga->dev,
drivers/media/platform/rockchip/rga/rga.c +2 -6
@@ -221,7 +221,6 @@ static int rga_open(struct file *file) }; def_frame.stride = (def_width * def_frame.fmt->depth) >>3 ; - def_frame.size = def_frame.stride * def_height; ctx =kzalloc_obj (*ctx);if (!ctx)
@@ -459,9 +458,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) frm =rga_get_frame (ctx, f->type);if (IS_ERR (frm))return PTR_ERR (frm); - frm->size =0 ; -for (i =0 ; i < pix_fmt->num_planes; i++) - frm->size += pix_fmt->plane_fmt[i].sizeimage; frm->fmt =rga_fmt_find (rga, pix_fmt->pixelformat); frm->stride = pix_fmt->plane_fmt[0 ].bytesperline;
@@ -485,10 +481,10 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) frm->pix = *pix_fmt;v4l2_dbg (debug,1 , &rga->v4l2_dev, -"[%s] fmt - %p4cc %dx%d (stride %d, sizeimage %d)\n" , +"[%s] fmt - %p4cc %dx%d (stride %d)\n" ,V4L2_TYPE_IS_OUTPUT (f->type) ?"OUTPUT" :"CAPTURE" , &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride, frm->size); + frm->stride);for (i =0 ; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev,
drivers/media/platform/rockchip/rga/rga.h +0 -1
@@ -34,7 +34,6 @@ struct rga_frame {/* Variables that can calculated once and reused */ u32 stride; -u32 size; };struct rga_dma_desc {
Signature · 1 line
2.53.0
PATCH v4 22/27 media: rockchip: rga: remove stride from rga_frame
In reply to Sven PüschelRemove the stride variable from rga_frame. Despite the comment it didn't involve any calculation and is just a copy of the plane_fmt[0].bytesperline value. Therefore avoid this struct member and use the bytesperline value directly in the places where it is required.
Also drop the dependency on the depth format member, which was only used to calculate the stride of the default format. This is already done by the v4l2_fill_pixfmt_mp_aligned helper and used as stride in try_fmt. Therefore using it's value also for the default format stride is just more consistent.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 36 ++++++++++------------------ drivers/media/platform/rockchip/rga/rga.c | 5 +--- drivers/media/platform/rockchip/rga/rga.h | 4 ---- 3 files changed, 13 insertions(+), 32 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +12 -24
@@ -44,7 +44,7 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_addrs *addrs,struct rga_addrs *lt, *lb, *rt, *rb;const struct v4l2_format_info *format_info;unsigned int x_div =0 , - y_div =0 , uv_stride =0 , pixel_width =0 ; + y_div =0 , y_stride =0 , uv_stride =0 , pixel_width =0 ; lt = &corner_addrs.left_top; lb = &corner_addrs.left_bottom;
@@ -61,14 +61,15 @@ rga_get_corner_addrs(struct rga_frame *frm, struct rga_addrs *addrs,else x_div =1 ; y_div = format_info->vdiv; - uv_stride = frm->stride / x_div; - pixel_width = frm->stride / frm->pix.width; + y_stride = frm->pix.plane_fmt[0 ].bytesperline; + uv_stride = y_stride / x_div; + pixel_width = y_stride / frm->pix.width; - lt->y_addr = addrs->y_addr + y * frm->stride + x * pixel_width; + lt->y_addr = addrs->y_addr + y * y_stride + x * pixel_width; lt->u_addr = addrs->u_addr + (y / y_div) * uv_stride + x / x_div; lt->v_addr = addrs->v_addr + (y / y_div) * uv_stride + x / x_div; - lb->y_addr = lt->y_addr + (h -1 ) * frm->stride; + lb->y_addr = lt->y_addr + (h -1 ) * y_stride; lb->u_addr = lt->u_addr + (h / y_div -1 ) * uv_stride; lb->v_addr = lt->v_addr + (h / y_div -1 ) * uv_stride;
@@ -169,6 +170,7 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx)union rga_src_act_info src_act_info;union rga_dst_vir_info dst_vir_info;union rga_dst_act_info dst_act_info; +u32 in_stride, out_stride; src_h = ctx->in.crop.height; src_w = ctx->in.crop.width;
@@ -291,13 +293,15 @@ static void rga_cmd_set_trans_info(struct rga_ctx *ctx)* Calculate the framebuffer virtual strides and active size, * note that the step of vir_stride / vir_width is 4 byte words */ - src_vir_info.data.vir_stride = ctx->in.stride >>2 ; - src_vir_info.data.vir_width = ctx->in.stride >>2 ; + in_stride = ctx->in.pix.plane_fmt[0 ].bytesperline; + src_vir_info.data.vir_stride = in_stride >>2 ; + src_vir_info.data.vir_width = in_stride >>2 ; src_act_info.data.act_height = src_h -1 ; src_act_info.data.act_width = src_w -1 ; - dst_vir_info.data.vir_stride = ctx->out.stride >>2 ; + out_stride = ctx->out.pix.plane_fmt[0 ].bytesperline; + dst_vir_info.data.vir_stride = out_stride >>2 ; dst_act_info.data.act_height = dst_h -1 ; dst_act_info.data.act_width = dst_w -1 ;
@@ -481,97 +485,81 @@ static struct rga_fmt formats[] = { .fourcc = V4L2_PIX_FMT_ARGB32, .color_swap = RGA_COLOR_ALPHA_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, - .depth = 32, }, { .fourcc = V4L2_PIX_FMT_ABGR32, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR8888, - .depth = 32, }, { .fourcc = V4L2_PIX_FMT_XBGR32, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_XBGR8888, - .depth = 32, }, { .fourcc = V4L2_PIX_FMT_RGB24, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, - .depth = 24, }, { .fourcc = V4L2_PIX_FMT_BGR24, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_RGB888, - .depth = 24, }, { .fourcc = V4L2_PIX_FMT_ARGB444, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR4444, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_ARGB555, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_ABGR1555, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_RGB565, .color_swap = RGA_COLOR_RB_SWAP, .hw_format = RGA_COLOR_FMT_BGR565, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_NV21, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, - .depth = 12, }, { .fourcc = V4L2_PIX_FMT_NV61, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_NV12, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, - .depth = 12, }, { .fourcc = V4L2_PIX_FMT_NV12M, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420SP, - .depth = 12, }, { .fourcc = V4L2_PIX_FMT_NV16, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422SP, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_YUV420, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, - .depth = 12, }, { .fourcc = V4L2_PIX_FMT_YUV422P, .color_swap = RGA_COLOR_NONE_SWAP, .hw_format = RGA_COLOR_FMT_YUV422P, - .depth = 16, }, { .fourcc = V4L2_PIX_FMT_YVU420, .color_swap = RGA_COLOR_UV_SWAP, .hw_format = RGA_COLOR_FMT_YUV420P, - .depth = 12, }, };
drivers/media/platform/rockchip/rga/rga.c +1 -4
@@ -220,8 +220,6 @@ static int rga_open(struct file *file) .fmt = &rga->hw->formats[0], }; - def_frame.stride = (def_width * def_frame.fmt->depth) >>3 ; - ctx =kzalloc_obj (*ctx);if (!ctx)return -ENOMEM ;
@@ -459,7 +457,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)if (IS_ERR (frm))return PTR_ERR (frm); frm->fmt =rga_fmt_find (rga, pix_fmt->pixelformat); - frm->stride = pix_fmt->plane_fmt[0 ].bytesperline;/* * Copy colorimetry from output to capture as required by the
@@ -484,7 +481,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)"[%s] fmt - %p4cc %dx%d (stride %d)\n" ,V4L2_TYPE_IS_OUTPUT (f->type) ?"OUTPUT" :"CAPTURE" , &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, - frm->stride); + pix_fmt->plane_fmt[0].bytesperline);for (i =0 ; i < pix_fmt->num_planes; i++) { v4l2_dbg(debug, 1, &rga->v4l2_dev,
drivers/media/platform/rockchip/rga/rga.h +0 -4
@@ -19,7 +19,6 @@struct rga_fmt {u32 fourcc; -int depth;u8 color_swap;u8 hw_format; };
@@ -31,9 +30,6 @@ struct rga_frame {/* Image format */ struct rga_fmt *fmt;struct v4l2_pix_format_mplane pix; - -/* Variables that can calculated once and reused */ -u32 stride; };struct rga_dma_desc {
Signature · 1 line
2.53.0
PATCH v4 23/27 media: rockchip: rga: move rga_fmt to rga-hw.h
In reply to Sven PüschelMove rga_fmt to rga-hw in preparation of the RGA3 addition, as the struct contains many RGA2 specific values. They are used to write the correct register values quickly based on the chosen format. Therefore the pointer to the rga_fmt struct is kept but changed to an opaque void pointer outside of the rga-hw.h.
To enumerate and set the correct formats, two helper functions need to be exposed in the rga_hw struct:
enum_format just get's the vidioc_enum_fmt format and it's return value is also returned from vidioc_enum_fmt. This is a simple pass-through, as the implementation is very simple.
adjust_and_map_format is a simple abstraction around the previous rga_find_format. But unlike rga_find_format, it always returns a valid format. Therefore the passed format value is also a pointer to update it in case the values are not supported by the hardware. Due to the RGA3 supporting different formats on the capture and output side, an additional parameter is_capture has been added to support this use-case. The additional ctx parameter is also added to allow the RGA3 to limit the colorimetry only if an RGB<->YCrCb transformation happens.
--- drivers/media/platform/rockchip/rga/rga-buf.c | 2 +- drivers/media/platform/rockchip/rga/rga-hw.c | 49 +++++++++++++++++++++------ drivers/media/platform/rockchip/rga/rga-hw.h | 8 +++++ drivers/media/platform/rockchip/rga/rga.c | 39 +++++++-------------- drivers/media/platform/rockchip/rga/rga.h | 14 +++----- 5 files changed, 66 insertions(+), 46 deletions(-)
drivers/media/platform/rockchip/rga/rga-buf.c +1 -1
@@ -162,7 +162,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb) }/* Fill the remaining planes */ - info =v4l2_format_info (f->fmt->fourcc); + info =v4l2_format_info (f->pix.pixelformat);for (i = info->mem_planes; i < info->comp_planes; i++) dma_addrs[i] = dma_addrs[0 ] +get_plane_offset (f, info, i);
drivers/media/platform/rockchip/rga/rga-hw.c +39 -10
86 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga-hw.h +8 -0
@@ -6,6 +6,8 @@#ifndef __RGA_HW_H__#define __RGA_HW_H__ +#include <linux/types.h> +#define RGA_CMDBUF_SIZE 0x20/* Hardware limits */
@@ -431,4 +433,10 @@ union rga_pat_con { } data; }; +struct rga_fmt { +u32 fourcc; +u8 color_swap; +u8 hw_format; +}; +#endif
drivers/media/platform/rockchip/rga/rga.c +13 -26
@@ -185,17 +185,6 @@ static int rga_setup_ctrls(struct rga_ctx *ctx)return 0 ; } -static struct rga_fmt *rga_fmt_find (struct rockchip_rga *rga,u32 pixelformat) -{ -unsigned int i; - -for (i =0 ; i < rga->hw->num_formats; i++) { -if (rga->hw->formats[i].fourcc == pixelformat) -return &rga->hw->formats[i]; - } -return NULL ; -} -struct rga_frame *rga_get_frame (struct rga_ctx *ctx,enum v4l2_buf_type type) {if (V4L2_TYPE_IS_OUTPUT (type))
@@ -217,7 +206,6 @@ static int rga_open(struct file *file) .crop.top = 0, .crop.width = def_width, .crop.height = def_height, - .fmt = &rga->hw->formats[0], }; ctx =kzalloc_obj (*ctx);
@@ -238,9 +226,12 @@ static int rga_open(struct file *file) ctx->in = def_frame; ctx->out = def_frame; -v4l2_fill_pixfmt_mp_aligned (&ctx->in.pix, ctx->in.fmt->fourcc, + ctx->in.fmt = rga->hw->adjust_and_map_format (ctx, &ctx->in.pix, true); +v4l2_fill_pixfmt_mp_aligned (&ctx->in.pix, ctx->in.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment); -v4l2_fill_pixfmt_mp_aligned (&ctx->out.pix, ctx->out.fmt->fourcc, + ctx->out.fmt = + rga->hw->adjust_and_map_format (ctx, &ctx->out.pix, false); +v4l2_fill_pixfmt_mp_aligned (&ctx->out.pix, ctx->out.pix.pixelformat, def_width, def_height, rga->hw->stride_alignment);if (mutex_lock_interruptible (&rga->mutex)) {
@@ -322,13 +313,11 @@ vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)static int vidioc_enum_fmt (struct file *file,void *priv,struct v4l2_fmtdesc *f) {struct rockchip_rga *rga =video_drvdata (file); -struct rga_fmt *fmt; - -if (f->index >= rga->hw->num_formats) -return -EINVAL ; +int ret; - fmt = &rga->hw->formats[f->index]; - f->pixelformat = fmt->fourcc; + ret = rga->hw->enum_format (f); +if (ret !=0 ) +return ret;if (f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE && f->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE )
@@ -363,7 +352,6 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f)struct v4l2_pix_format_mplane *pix_fmt = &f->fmt.pix_mp;struct rga_ctx *ctx =file_to_rga_ctx (file);const struct rga_hw *hw = ctx->rga->hw; -struct rga_fmt *fmt;struct v4l2_frmsize_stepwise frmsize = { .min_width = hw->min_width, .max_width = hw->max_width,
@@ -394,9 +382,7 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_fmt->xfer_func = frm->pix.xfer_func; } - fmt =rga_fmt_find (ctx->rga, pix_fmt->pixelformat); -if (!fmt) - fmt = &hw->formats[0 ]; + hw->adjust_and_map_format (ctx, pix_fmt,V4L2_TYPE_IS_OUTPUT (f->type));v4l2_apply_frmsize_constraints (&pix_fmt->width, &pix_fmt->height, &frmsize); v4l2_fill_pixfmt_mp_aligned(pix_fmt, pix_fmt->pixelformat,
@@ -456,7 +442,8 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) frm =rga_get_frame (ctx, f->type);if (IS_ERR (frm))return PTR_ERR (frm); - frm->fmt =rga_fmt_find (rga, pix_fmt->pixelformat); + frm->fmt = rga->hw->adjust_and_map_format (ctx, pix_fmt, +V4L2_TYPE_IS_OUTPUT (f->type));/* * Copy colorimetry from output to capture as required by the
@@ -480,7 +467,7 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f)v4l2_dbg (debug,1 , &rga->v4l2_dev,"[%s] fmt - %p4cc %dx%d (stride %d)\n" ,V4L2_TYPE_IS_OUTPUT (f->type) ?"OUTPUT" :"CAPTURE" , - &frm->fmt->fourcc, pix_fmt->width, pix_fmt->height, + &pix_fmt->pixelformat, pix_fmt->width, pix_fmt->height, pix_fmt->plane_fmt[0 ].bytesperline);for (i =0 ; i < pix_fmt->num_planes; i++) {
drivers/media/platform/rockchip/rga/rga.h +5 -9
@@ -17,18 +17,12 @@#define DEFAULT_WIDTH 100#define DEFAULT_HEIGHT 100 -struct rga_fmt { -u32 fourcc; -u8 color_swap; -u8 hw_format; -}; -struct rga_frame {/* Crop */ struct v4l2_rect crop;/* Image format */ -struct rga_fmt *fmt; +void *fmt;struct v4l2_pix_format_mplane pix; };
@@ -142,8 +136,6 @@ static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)struct rga_hw {const char *card_type;bool has_internal_iommu; -struct rga_fmt *formats; -u32 num_formats;size_t cmdbuf_size;u32 min_width, min_height;u32 max_width, max_height;
@@ -155,6 +147,10 @@ struct rga_hw { struct rga_vb_buffer *src, struct rga_vb_buffer *dst);bool (*handle_irq)(struct rockchip_rga *rga);void (*get_version)(struct rockchip_rga *rga); +void *(*adjust_and_map_format)(struct rga_ctx *ctx, +struct v4l2_pix_format_mplane *format, +bool is_output); +int (*enum_format)(struct v4l2_fmtdesc *f); };static inline bool rga_has_internal_iommu (const struct rockchip_rga *rga)
Signature · 1 line
2.53.0
PATCH v4 24/27 media: rockchip: rga: add feature flags
In reply to Sven PüschelIn preparation to the RGA3 addition add feature flags, which can limit the exposed feature set of the video device, like rotating or selection support. This is necessary as the RGA3 doesn't initially implement the full feature set currently exposed by the driver.
--- drivers/media/platform/rockchip/rga/rga-hw.c | 4 ++++ drivers/media/platform/rockchip/rga/rga.c | 23 +++++++++++++++-------- drivers/media/platform/rockchip/rga/rga.h | 7 +++++++ 3 files changed, 26 insertions(+), 8 deletions(-)
drivers/media/platform/rockchip/rga/rga-hw.c +4 -0
@@ -602,6 +602,10 @@ const struct rga_hw rga2_hw = { .max_height = MAX_HEIGHT, .max_scaling_factor = MAX_SCALING_FACTOR, .stride_alignment = 4, + .features =RGA_FEATURE_FLIP + |RGA_FEATURE_ROTATE + |RGA_FEATURE_BG_COLOR + | RGA_FEATURE_SELECTION, .setup_cmdbuf = rga_hw_setup_cmdbuf, .start = rga_hw_start,
drivers/media/platform/rockchip/rga/rga.c +15 -8
@@ -162,17 +162,21 @@ static int rga_setup_ctrls(struct rga_ctx *ctx)v4l2_ctrl_handler_init (&ctx->ctrl_handler,4 ); -v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, -V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +if (rga->hw->features &RGA_FEATURE_FLIP ) { +v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, +V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); -v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, -V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, +V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); + } -v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, -V4L2_CID_ROTATE ,0 ,270 ,90 ,0 ); +if (rga->hw->features &RGA_FEATURE_ROTATE ) +v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, +V4L2_CID_ROTATE ,0 ,270 ,90 ,0 ); -v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, -V4L2_CID_BG_COLOR ,0 ,0xffffffff ,1 ,0 ); +if (rga->hw->features &RGA_FEATURE_BG_COLOR ) +v4l2_ctrl_new_std (&ctx->ctrl_handler, &rga_ctrl_ops, +V4L2_CID_BG_COLOR ,0 ,0xffffffff ,1 ,0 );if (ctx->ctrl_handler.error) {int err = ctx->ctrl_handler.error;
@@ -536,6 +540,9 @@ static int vidioc_s_selection(struct file *file, void *priv,struct rga_frame *f;int ret =0 ; +if (!(rga->hw->features &RGA_FEATURE_SELECTION )) +return -EINVAL ; + f =rga_get_frame (ctx, s->type);if (IS_ERR (f))return PTR_ERR (f);
drivers/media/platform/rockchip/rga/rga.h +7 -0
@@ -6,6 +6,7 @@#ifndef __RGA_H__#define __RGA_H__ +#include <linux/bits.h> #include <linux/clk.h> #include <linux/platform_device.h> #include <media/videobuf2-v4l2.h>
@@ -133,6 +134,11 @@ static inline void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32 mask)rga_write (rga, reg, temp); }; +#define RGA_FEATURE_FLIP BIT(0) +#define RGA_FEATURE_ROTATE BIT(1) +#define RGA_FEATURE_BG_COLOR BIT(2) +#define RGA_FEATURE_SELECTION BIT(3) +struct rga_hw {const char *card_type;bool has_internal_iommu;
@@ -141,6 +147,7 @@ struct rga_hw {u32 max_width, max_height;u8 max_scaling_factor;u8 stride_alignment; +u8 features;void (*setup_cmdbuf)(struct rga_ctx *ctx); void (*start)(struct rockchip_rga *rga,
Signature · 1 line
2.53.0
PATCH v4 25/27 media: rockchip: rga: disable multi-core support
In reply to Sven PüschelDisable multi-core support in preparation of the RGA3 addition. The RK3588 SoC features two equal RGA3 cores. This allows scheduling of the work between both cores, which is not yet implemented. Until it is implemented avoid exposing both cores as independent video devices to prevent an ABI breakage when multi-core support is added.
This patch is copied from the Hantro driver patch to disable multi core support by Sebastian Reichel. See
commit ccdeb8d57f7f ("media: hantro: Disable multicore support")
--- drivers/media/platform/rockchip/rga/rga.c | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/media/platform/rockchip/rga/rga.c +47 -0
@@ -708,6 +708,49 @@ static int rga_parse_dt(struct rockchip_rga *rga)return 0 ; } +/* +* Some SoCs, like RK3588 have multiple identical RGA3 cores, but the +* kernel is currently missing support for multi-core handling. Exposing +* separate devices for each core to userspace is bad, since that does +* not allow scheduling tasks properly (and creates ABI). With this workaround +* the driver will only probe for the first core and early exit for the other +* cores. Once the driver gains multi-core support, the same technique +* for detecting the main core can be used to cluster all cores together. +*/ +static int rga_disable_multicore (struct device *dev) +{ +struct device_node *node =NULL ; +const char *compatible; +bool is_main_core; +int ret; + +/* Intentionally ignores the fallback strings */ + ret =of_property_read_string (dev->of_node,"compatible" , &compatible); +if (ret) +return ret; + +/* The first compatible and available node found is considered the main core */ +do { + node =of_find_compatible_node (node,NULL , compatible); +if (of_device_is_available (node)) +break ; + }while (node); + +if (!node) +return -EINVAL ; + + is_main_core = (dev->of_node == node); + +of_node_put (node); + +if (!is_main_core) { +dev_info (dev,"missing multi-core support, ignoring this instance\n" ); +return -ENODEV ; + } + +return 0 ; +} +static int rga_probe (struct platform_device *pdev) {struct rockchip_rga *rga;
@@ -718,6 +761,10 @@ static int rga_probe(struct platform_device *pdev)if (!pdev->dev.of_node)return -ENODEV ; + ret =rga_disable_multicore (&pdev->dev); +if (ret) +return ret; + rga =devm_kzalloc (&pdev->dev,sizeof (*rga),GFP_KERNEL );if (!rga)return -ENOMEM ;
Signature · 1 line
2.53.0
PATCH v4 26/27 media: rockchip: rga: add rga3 support
In reply to Sven PüschelAdd support for the RGA3 unit contained in the RK3588.
Only a basic feature set consisting of scaling and color conversion is implemented. Currently unimplemented features include:
- Advanced formats like 10bit YUV, FBCE mode and Tile8x8 mode
- Background color (V4L2_CID_BG_COLOR)
- Configurable alpha value (V4L2_CID_ALPHA_COMPONENT)
- Image flipping (V4L2_CID_HFLIP and V4L2_CID_VFLIP)
- Image rotation (V4L2_CID_ROTATE)
- Image cropping/composing (VIDIOC_S_SELECTION)
- Only very basic output cropping for 1088 -> 1080 cases is implemented
The register address defines were copied from the
vendor Rockchip kernel sources and slightly adjusted to not start at 0 again for the cmd registers.
During testing it has been noted that the scaling of the hardware is slightly incorrect. A test conversion of 128x128 RGBA to 256x256 RGBA causes a slightly larger scaling. The scaling is suddle, as it seems that the image is scaled to a 2px larger version and then cropped to it's final size. Trying to use the RGA2 scaling factor calculation didn't work. As the calculation matches the vendor kernel driver, no further research has been utilized to check if there may be some kind of better scaling factor calculation.
Furthermore comparing the RGA3 conversion with the GStreamer videoconvertscale element, the chroma-site is different. A quick testing didn't reveal a chroma-site that creates the same image with the GStreamer Element. Also when converting from YUV to RGB the RGB values differ by 1 or 2. This doesn't seem to be a colorspace conversion issue but rather a slightly different precision on the calculation.
--- drivers/media/platform/rockchip/rga/Makefile | 2 +- drivers/media/platform/rockchip/rga/rga.c | 4 + drivers/media/platform/rockchip/rga/rga.h | 1 + drivers/media/platform/rockchip/rga/rga3-hw.c | 507 ++++++++++++++++++++++++++ drivers/media/platform/rockchip/rga/rga3-hw.h | 192 ++++++++++ 5 files changed, 705 insertions(+), 1 deletion(-)
drivers/media/platform/rockchip/rga/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only -rockchip-rga-objs := rga.o rga-hw.o rga-buf.o +rockchip-rga-objs := rga.o rga-hw.o rga3-hw.o rga-buf.o obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
drivers/media/platform/rockchip/rga/rga.c +4 -0
@@ -910,6 +910,10 @@ static const struct of_device_id rockchip_rga_match[] = { .compatible = "rockchip,rk3399-rga", .data = &rga2_hw, }, + { + .compatible = "rockchip,rk3588-rga3", + .data = &rga3_hw, + }, {}, };
drivers/media/platform/rockchip/rga/rga.h +1 -0
@@ -166,5 +166,6 @@ static inline bool rga_has_internal_iommu(const struct rockchip_rga *rga) }extern const struct rga_hw rga2_hw; +extern const struct rga_hw rga3_hw;#endif
drivers/media/platform/rockchip/rga/rga3-hw.c new file +507 -0
507 lines not on this page · raw message
drivers/media/platform/rockchip/rga/rga3-hw.h new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 27/27 arm64: dts: rockchip: add rga3 dt nodes
In reply to Sven PüschelAdd devicetree nodes for the RGA3 (Raster Graphics Acceleration 3) peripheral in the RK3588.
The existing rga node refers to the RGA2-Enhanced peripheral. The RK3588 contains one RGA2-Enhanced core and two RGA3 cores. Both feature a similar functionality of scaling, cropping and rotating of up to two input images into one output image. Key differences of the RGA3 are:
- supports 10bit YUV output formats
- supports 8x8 tiles and FBCD as inputs and outputs
- supports BT2020 color space conversion
- max output resolution of (8192-64)x(8192-64)
- MMU can map up to 32G DDR RAM
- fully planar formats (3 planes) are not supported
- max scale up/down factor of 8 (RGA2 allows up to 16)
--- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +44 -0
@@ -1273,6 +1273,50 @@ rga: rga@fdb80000 { power-domains = <&power RK3588_PD_VDPU>; }; + rga3_core0: rga@fdb60000 { + compatible = "rockchip,rk3588-rga3"; + reg = <0x0 0xfdb60000 0x0 0x200>; + interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>, <&cru CLK_RGA3_0_CORE>; + clock-names = "aclk", "hclk", "sclk"; + resets = <&cru SRST_RGA3_0_CORE>, <&cru SRST_A_RGA3_0>, <&cru SRST_H_RGA3_0>; + reset-names = "core", "axi", "ahb"; + power-domains = <&power RK3588_PD_RGA30>; + iommus = <&rga3_0_mmu>; + }; + + rga3_0_mmu: iommu@fdb60f00 { + compatible = "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0xfdb60f00 0x0 0x100>; + interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RGA3_0>, <&cru HCLK_RGA3_0>; + clock-names = "aclk", "iface"; + #iommu-cells = <0>; + power-domains = <&power RK3588_PD_RGA30>; + }; + + rga3_core1: rga@fdb70000 { + compatible = "rockchip,rk3588-rga3"; + reg = <0x0 0xfdb70000 0x0 0x200>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>, <&cru CLK_RGA3_1_CORE>; + clock-names = "aclk", "hclk", "sclk"; + resets = <&cru SRST_RGA3_1_CORE>, <&cru SRST_A_RGA3_1>, <&cru SRST_H_RGA3_1>; + reset-names = "core", "axi", "ahb"; + power-domains = <&power RK3588_PD_RGA31>; + iommus = <&rga3_1_mmu>; + }; + + rga3_1_mmu: iommu@fdb70f00 { + compatible = "rockchip,rk3588-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0xfdb70f00 0x0 0x100>; + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_HIGH 0>; + clocks = <&cru ACLK_RGA3_1>, <&cru HCLK_RGA3_1>; + clock-names = "aclk", "iface"; + #iommu-cells = <0>; + power-domains = <&power RK3588_PD_RGA31>; + }; + vepu121_0: video-codec@fdba0000 { compatible = "rockchip,rk3588-vepu121"; reg = <0x0 0xfdba0000 0x0 0x800>;
Signature · 1 line
2.53.0