Skip to contentSkip to conversation

Add Rockchip RGA V4l2 support

PATCH Superseded Jacob Chen 2 participants 8 messages Aug 2, 2017 – Aug 10, 2017

Subsystems (4)

v5 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Jacob Chen

author
#0 lore raw

v5 cover Add Rockchip RGA V4l2 support

This patch series add a v4l2 m2m drvier for rockchip RGA direct rendering based 2d graphics acceleration module.

Before, my colleague yakir have write a drm RGA drvier and send it to the lists.
http://lists.infradead.org/pipermail/linux-arm-kernel/2016-March/416769.html
I have been asked to find a userspace user("compositor") for it, but after some studys, my conclusion is that unlike exynos g2d, rockchip rga are not suitable for compositor. Rockchip RGA have a limited MMU, which means it can only hold several buffers in the same time. When it was used in compositor, it will waste a lot of time to import/export/flush buffer, resulting in a bad performance.

A few months ago, i saw a discussion in dri-devel at lists.freedesktop.org.
It remind that we could write a v4l2 m2m RGA driver, since we usually use RGA for streaming purpose.
https://patches.linaro.org/cover/97727/

I have test this driver with gstreamer v4l2transform plugin and it work well.

change in V5:
- v4l2-compliance: handle invalid pxielformat
- v4l2-compliance: add subscribe_event
- add colorspace support

change in V4:
- document the controls.
- change according to Hans's comments

change in V3:
- rename the controls.
- add pm_runtime support.
- enable node by default.
- correct spelling in documents.

change in V2:
- generalize the controls.
- map buffers (10-50 us) in every cmd-run rather than in buffer-import to avoid get_free_pages failed on actively used systems.
- remove status in dt-bindings examples.

Jacob Chen (6):
v4l: add portduff blend modes extended-controls.rst: add PorterDuff mode control rockchip/rga: v4l2 m2m support
ARM: dts: rockchip: add RGA device node for RK3288
ARM: dts: rockchip: add RGA device node for RK3399
dt-bindings: Document the Rockchip RGA bindings

 .../devicetree/bindings/media/rockchip-rga.txt     |   33 +
 Documentation/media/uapi/v4l/extended-controls.rst |    5 +
 arch/arm/boot/dts/rk3288.dtsi                      |   11 +
 arch/arm64/boot/dts/rockchip/rk3399.dtsi           |   11 +
 drivers/media/platform/Kconfig                     |   11 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/rockchip-rga/Makefile       |    3 +
 drivers/media/platform/rockchip-rga/rga-buf.c      |  155 +++
 drivers/media/platform/rockchip-rga/rga-hw.c       |  671 +++++++++++++
 drivers/media/platform/rockchip-rga/rga-hw.h       |  437 +++++++++
 drivers/media/platform/rockchip-rga/rga.c          | 1024 ++++++++++++++++++++
 drivers/media/platform/rockchip-rga/rga.h          |  110 +++
 drivers/media/v4l2-core/v4l2-ctrls.c               |   20 +-
 include/uapi/linux/v4l2-controls.h                 |   20 +-
 14 files changed, 2511 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-rga.txt
 create mode 100644 drivers/media/platform/rockchip-rga/Makefile
 create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
 create mode 100644 drivers/media/platform/rockchip-rga/rga.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v5 1/6 v4l: add portduff blend modes

At peresent, we don't have a control for Compositing and Blend. All drivers are just doing copies while actually many hardwares supports more functions.

So Adding V4L2 controls for Compositing and Blend, used for for composting streams.

The values are based on porter duff operations.
Defined in below links.
https://developer.xamarin.com/api/type/Android.Graphics.PorterDuff+Mode/

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 include/uapi/linux/v4l2-controls.h   | 20 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +19 -1
index b9e08e3..561d7d5 100644
@@ -478,7 +478,21 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
 		"Region Grid",
 		NULL,
 	};
-
+	static const char * const porter_duff_modes[] = {
+		"Source",
+		"Source Top",
+		"Source In",
+		"Source Out",
+		"Source Over",
+		"Destination",
+		"Destination Top",
+		"Destination In",
+		"Destination Out",
+		"Destination Over",
+		"Add",
+		"Clear",
+		NULL
+	};
 
 	switch (id) {
 	case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
@@ -564,6 +578,8 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
 		return vpx_golden_frame_sel;
 	case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
 		return jpeg_chroma_subsampling;
+	case V4L2_CID_PORTER_DUFF_MODE:
+		return porter_duff_modes;
 	case V4L2_CID_DV_TX_MODE:
 		return dv_tx_mode;
 	case V4L2_CID_DV_TX_RGB_RANGE:
@@ -886,6 +902,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_PIXEL_RATE:		return "Pixel Rate";
 	case V4L2_CID_TEST_PATTERN:		return "Test Pattern";
 	case V4L2_CID_DEINTERLACING_MODE:	return "Deinterlacing Mode";
+	case V4L2_CID_PORTER_DUFF_MODE:		return "PorterDuff Blend Modes";
 
 	/* DV controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1060,6 +1077,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DV_RX_IT_CONTENT_TYPE:
 	case V4L2_CID_TEST_PATTERN:
 	case V4L2_CID_DEINTERLACING_MODE:
+	case V4L2_CID_PORTER_DUFF_MODE:
 	case V4L2_CID_TUNE_DEEMPHASIS:
 	case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
 	case V4L2_CID_DETECT_MD_MODE:
include/uapi/linux/v4l2-controls.h +19 -1
index 0d2e1e0..986a02b6 100644
@@ -893,7 +893,25 @@ enum v4l2_jpeg_chroma_subsampling {
 #define V4L2_CID_PIXEL_RATE			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
 #define V4L2_CID_TEST_PATTERN			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
 #define V4L2_CID_DEINTERLACING_MODE		(V4L2_CID_IMAGE_PROC_CLASS_BASE + 4)
-
+#define V4L2_CID_PORTER_DUFF_MODE		(V4L2_CID_IMAGE_PROC_CLASS_BASE + 5)
+/*
+ * For details: see
+ * https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html
+ */
+enum v4l2_porter_duff_mode {
+	V4L2_PORTER_DUFF_SRC			= 0,
+	V4L2_PORTER_DUFF_SRCATOP		= 1,
+	V4L2_PORTER_DUFF_SRCIN			= 2,
+	V4L2_PORTER_DUFF_SRCOUT			= 3,
+	V4L2_PORTER_DUFF_SRCOVER		= 4,
+	V4L2_PORTER_DUFF_DST			= 5,
+	V4L2_PORTER_DUFF_DSTATOP		= 6,
+	V4L2_PORTER_DUFF_DSTIN			= 7,
+	V4L2_PORTER_DUFF_DSTOUT			= 8,
+	V4L2_PORTER_DUFF_DSTOVER		= 9,
+	V4L2_PORTER_DUFF_ADD			= 10,
+	V4L2_PORTER_DUFF_CLEAR			= 11,
+};
 
 /*  DV-class control IDs defined by V4L2 */
 #define V4L2_CID_DV_CLASS_BASE			(V4L2_CTRL_CLASS_DV | 0x900)
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v5 2/6 extended-controls.rst: add PorterDuff mode control

In reply to Jacob Chen

PorterDuff mode control are used to determine
how two images are combined.

---
 Documentation/media/uapi/v4l/extended-controls.rst | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
index abb1057..b713581 100644
@@ -3021,6 +3021,11 @@ Image Process Control IDs
     The video deinterlacing mode (such as Bob, Weave, ...). The menu items are
     driver specific and are documented in :ref:`v4l-drivers`.
 
+``V4L2_CID_PORTER_DUFF_MODE (menu)``
+    The PorterDuff blend modes. PorterDuff is a method to overlay, combine and
+    trim images as if they were pieces of cardboard. The device uses this to
+    determine how two images are combined. For more information see
+    `PorterDuff.Mode <https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html>`__.
 
 .. _dv-controls:
 
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v5 3/6 rockchip/rga: v4l2 m2m support

In reply to Jacob Chen

Rockchip RGA is a separate 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

The drvier is mostly based on s5p-g2d v4l2 m2m driver And supports various operations from the rendering pipeline.
- copy
- fast solid color fill
- rotation
- flip
- alpha blending

The code in rga-hw.c is used to configure regs according to operations The code in rga-buf.c is used to create private mmu table for RGA.

---
 drivers/media/platform/Kconfig                |   11 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/rockchip-rga/Makefile  |    3 +
 drivers/media/platform/rockchip-rga/rga-buf.c |  155 ++++
 drivers/media/platform/rockchip-rga/rga-hw.c  |  671 ++++++++++++++++
 drivers/media/platform/rockchip-rga/rga-hw.h  |  437 +++++++++++
 drivers/media/platform/rockchip-rga/rga.c     | 1024 +++++++++++++++++++++++++
 drivers/media/platform/rockchip-rga/rga.h     |  110 +++
 8 files changed, 2413 insertions(+)
 create mode 100644 drivers/media/platform/rockchip-rga/Makefile
 create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
 create mode 100644 drivers/media/platform/rockchip-rga/rga.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga.h
drivers/media/platform/Kconfig +11 -0
index c9106e1..8199bcf 100644
@@ -411,6 +411,17 @@ config VIDEO_RENESAS_VSP1
 	  To compile this driver as a module, choose M here: the module
 	  will be called vsp1.
 
+config VIDEO_ROCKCHIP_RGA
+	tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
+	depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
+	depends on ARCH_ROCKCHIP || COMPILE_TEST
+	select VIDEOBUF2_DMA_SG
+	select V4L2_MEM2MEM_DEV
+	default n
+	---help---
+	  This is a v4l2 driver for Rockchip SOC RGA2
+	  2d graphics accelerator.
+
 config VIDEO_TI_VPE
 	tristate "TI VPE (Video Processing Engine) driver"
 	depends on VIDEO_DEV && VIDEO_V4L2
drivers/media/platform/Makefile +2 -0
index 349ddf6..3bf096f 100644
@@ -54,6 +54,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)	+= rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU) 	+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)	+= vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)	+= rockchip-rga/
+
 obj-y	+= omap/
 
 obj-$(CONFIG_VIDEO_AM437X_VPFE)		+= am437x/
drivers/media/platform/rockchip-rga/Makefile new file +3 -0
new file mode 100644
index 0000000..92fe254
@@ -0,0 +1,3 @@
+rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
+
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
drivers/media/platform/rockchip-rga/rga-buf.c new file +155 -0

155 lines not on this page · raw message

drivers/media/platform/rockchip-rga/rga-hw.c new file +671 -0

671 lines not on this page · raw message

drivers/media/platform/rockchip-rga/rga-hw.h new file +437 -0

437 lines not on this page · raw message

drivers/media/platform/rockchip-rga/rga.c new file +1024 -0

1,024 lines not on this page · raw message

drivers/media/platform/rockchip-rga/rga.h new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v5 4/6 ARM: dts: rockchip: add RGA device node for RK3288

In reply to Jacob Chen

This patch add the RGA dt config of rk3288 SoC.

---
 arch/arm/boot/dts/rk3288.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +11 -0
index 1efc2f2..cea41b7 100644
@@ -945,6 +945,17 @@
 		status = "okay";
 	};
 
+	rga: rga at ff920000 {
+		compatible = "rockchip,rk3288-rga";
+		reg = <0xff920000 0x180>;
+		interrupts = <GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru ACLK_RGA>, <&cru HCLK_RGA>, <&cru SCLK_RGA>;
+		clock-names = "aclk", "hclk", "sclk";
+		power-domains = <&power RK3288_PD_VIO>;
+		resets = <&cru SRST_RGA_CORE>, <&cru SRST_RGA_AXI>, <&cru SRST_RGA_AHB>;
+		reset-names = "core", "axi", "ahb";
+	};
+
 	vopb: vop at ff930000 {
 		compatible = "rockchip,rk3288-vop";
 		reg = <0xff930000 0x19c>;
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v5 5/6 ARM: dts: rockchip: add RGA device node for RK3399

In reply to Jacob Chen

This patch add the RGA dt config of RK3399 SoC.

---
 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +11 -0
index 8e6d1bd..0133a5f 100644
@@ -1056,6 +1056,17 @@
 		status = "disabled";
 	};
 
+	rga: rga at ff680000 {
+		compatible = "rockchip,rk3399-rga";
+		reg = <0x0 0xff680000 0x0 0x10000>;
+		interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH 0>;
+		clocks = <&cru ACLK_RGA>, <&cru HCLK_RGA>, <&cru SCLK_RGA_CORE>;
+		clock-names = "aclk", "hclk", "sclk";
+		resets = <&cru SRST_RGA_CORE>, <&cru SRST_A_RGA>, <&cru SRST_H_RGA>;
+		reset-names = "core", "axi", "ahb";
+		power-domains = <&power RK3399_PD_RGA>;
+	};
+
 	efuse0: efuse at ff690000 {
 		compatible = "rockchip,rk3399-efuse";
 		reg = <0x0 0xff690000 0x0 0x80>;
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v5 6/6 dt-bindings: Document the Rockchip RGA bindings

In reply to Jacob Chen

Add DT bindings documentation for Rockchip RGA

---
 .../devicetree/bindings/media/rockchip-rga.txt     | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-rga.txt
Documentation/devicetree/bindings/media/rockchip-rga.txt new file +33 -0
new file mode 100644
index 0000000..fd5276a
@@ -0,0 +1,33 @@
+device-tree bindings for rockchip 2D raster graphic acceleration controller (RGA)
+
+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.
+
+Required properties:
+- compatible: value should be one of the following
+		"rockchip,rk3288-rga";
+		"rockchip,rk3399-rga";
+
+- interrupts: RGA interrupt specifier.
+
+- clocks: phandle to RGA sclk/hclk/aclk clocks
+
+- clock-names: should be "aclk", "hclk" and "sclk"
+
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: should be "core", "axi" and "ahb"
+
+Example:
+SoC-specific DT entry:
+	rga: rga at ff680000 {
+		compatible = "rockchip,rk3399-rga";
+		reg = <0xff680000 0x10000>;
+		interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru ACLK_RGA>, <&cru HCLK_RGA>, <&cru SCLK_RGA_CORE>;
+		clock-names = "aclk", "hclk", "sclk";
+
+		resets = <&cru SRST_RGA_CORE>, <&cru SRST_A_RGA>, <&cru SRST_H_RGA>;
+		reset-names = "core, "axi", "ahb";
+	};
Signature · 1 line
2.7.4
maintainer Acked-by on v5 6/6
#7 lore raw

Re: [PATCH v5 6/6] dt-bindings: Document the Rockchip RGA bindings

Quoted 8 lines · Jacob Chen

Add DT bindings documentation for Rockchip RGA

---
 .../devicetree/bindings/media/rockchip-rga.txt     | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/rockchip-rga.txt