Skip to contentSkip to conversation

Enable JPEG Encoder on RK3566/RK3568

PATCH Superseded Nicolas Frattaroli 2 participants 7 messages May 11, 2022

Subsystems (5)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Enable JPEG Encoder on RK3566/RK3568

Hello,

the following series adds support for and enables one of the hardware video encoders on the RK3566 and RK3568 line of SoCs by Rockchip, initially just for the JPEG format in line with what the kernel supports.

The encoder block is separate from the Hantro decoder instance, as they are in different power domains and have wildly different memory addresses as well.

The encoder hardware seemingly also supports VP8 and H.264 in addition to just JPEG, as is evident from both the downstream vendor stack and the register listing in the TRM. The hantro driver in Linux, however, does not yet support encoding these formats.

The first patch modifies the bindings with a new compatible, and adds the ability to just have a vepu interrupt without a vdpu interrupt.

The second patch makes the actual driver changes to support this variant.

The third and final patch makes the necessary device tree changes for the rk356x device tree file to add both the node for the encoder and its MMU.

The series has been tested on a PINE64 Quartz64 Model A with an RK3566 SoC using GStreamer.

Below you'll also find an interdiff against V2.

Regards,
Nicolas Frattaroli

Changes in v3:
- bindings: change consts to an enum
- bindings: add check to make sure devices with a -vepu compatible only have the vepu interrupt

Changes in v2:
- rename compatible as it's not JPEG only
- rename device tree nodes as it's not JPEG only
- reword commits as it's not JPEG only
- get rid of a whole bunch of redundant struct definitions, as, you guessed it, it's not JPEG only

Nicolas Frattaroli (3):
dt-bindings: media: rockchip-vpu: Add RK3568 VEPU compatible
media: hantro: Add support for RK356x encoder
arm64: dts: rockchip: Add Hantro encoder node to rk356x

 .../bindings/media/rockchip-vpu.yaml          | 17 ++++++++++++-
 arch/arm64/boot/dts/rockchip/rk356x.dtsi      | 21 ++++++++++++++++
 drivers/staging/media/hantro/hantro_drv.c     |  1 +
 drivers/staging/media/hantro/hantro_hw.h      |  1 +
 .../staging/media/hantro/rockchip_vpu_hw.c    | 25 +++++++++++++++++++
 5 files changed, 64 insertions(+), 1 deletion(-)

Interdiff against v2:

Documentation/devicetree/bindings/media/rockchip-vpu.yaml +15 -2
index 4045f107ca4e..965ca80b5cea 100644
@@ -40,8 +40,9 @@ properties:
 
   interrupt-names:
     oneOf:
-      - const: vdpu
-      - const: vepu
+      - enum:
+          - vdpu
+          - vepu
       - items:
           - const: vepu
           - const: vdpu
@@ -78,6 +79,18 @@ required:
 
 additionalProperties: false
 
+allOf:
+  # compatibles that end in -vepu should only have the vepu interrupt
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: "^[a-zA-Z0-9\\-,_.]+\\-vepu$"
+    then:
+      properties:
+        interrupt-names:
+          const: vepu
+
 examples:
   - |
         #include <dt-bindings/clock/rk3288-cru.h>
Signature · 1 line
2.36.1
#1 lore raw

PATCH v3 1/3 dt-bindings: media: rockchip-vpu: Add RK3568 VEPU compatible

The RK3568 and RK3566 have a Hantro VPU node solely dedicated to encoding. This patch adds a compatible for it, and also allows the bindings to only come with a vepu interrupt.

---
 .../devicetree/bindings/media/rockchip-vpu.yaml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +16 -1
index bacb60a34989..965ca80b5cea 100644
@@ -22,6 +22,7 @@ properties:
           - rockchip,rk3288-vpu
           - rockchip,rk3328-vpu
           - rockchip,rk3399-vpu
+          - rockchip,rk3568-vepu
           - rockchip,px30-vpu
       - items:
           - const: rockchip,rk3188-vpu
@@ -39,7 +40,9 @@ properties:
 
   interrupt-names:
     oneOf:
-      - const: vdpu
+      - enum:
+          - vdpu
+          - vepu
       - items:
           - const: vepu
           - const: vdpu
@@ -76,6 +79,18 @@ required:
 
 additionalProperties: false
 
+allOf:
+  # compatibles that end in -vepu should only have the vepu interrupt
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: "^[a-zA-Z0-9\\-,_.]+\\-vepu$"
+    then:
+      properties:
+        interrupt-names:
+          const: vepu
+
 examples:
   - |
         #include <dt-bindings/clock/rk3288-cru.h>
Signature · 1 line
2.36.1
#5 lore raw

PATCH v3 2/3 media: hantro: Add support for RK356x encoder

In reply to Nicolas Frattaroli

The RK3566 and RK3568 SoCs come with a small Hantro instance which is solely dedicated to encoding. This patch adds the necessary structs to the Hantro driver to allow the JPEG encoder of it to function.

Through some sleuthing through the vendor's MPP source code and after closer inspection of the TRM, it was determined that the hardware likely supports VP8 and H.264 as well.

Tested with the following GStreamer command:

gst-launch-1.0 videotestsrc ! v4l2jpegenc ! matroskamux ! \
filesink location=foo.mkv

---
 drivers/staging/media/hantro/hantro_drv.c     |  1 +
 drivers/staging/media/hantro/hantro_hw.h      |  1 +
 .../staging/media/hantro/rockchip_vpu_hw.c    | 25 +++++++++++++++++++
 3 files changed, 27 insertions(+)
drivers/staging/media/hantro/hantro_drv.c +1 -0
index dc768884cb79..0b38b41136e2 100644
@@ -628,6 +628,7 @@ static const struct of_device_id of_hantro_match[] = {
 	{ .compatible = "rockchip,rk3288-vpu", .data = &rk3288_vpu_variant, },
 	{ .compatible = "rockchip,rk3328-vpu", .data = &rk3328_vpu_variant, },
 	{ .compatible = "rockchip,rk3399-vpu", .data = &rk3399_vpu_variant, },
+	{ .compatible = "rockchip,rk3568-vepu", .data = &rk3568_vepu_variant, },
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
 	{ .compatible = "nxp,imx8mm-vpu-g1", .data = &imx8mm_vpu_g1_variant, },
drivers/staging/media/hantro/hantro_hw.h +1 -0
index ed018e293ba0..b312da654d38 100644
@@ -300,6 +300,7 @@ extern const struct hantro_variant rk3066_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3399_vpu_variant;
+extern const struct hantro_variant rk3568_vepu_variant;
 extern const struct hantro_variant sama5d4_vdec_variant;
 extern const struct hantro_variant sunxi_vpu_variant;
 
drivers/staging/media/hantro/rockchip_vpu_hw.c +25 -0
index 163cf92eafca..a97a4ea8ede4 100644
@@ -417,6 +417,14 @@ static const struct hantro_codec_ops rk3399_vpu_codec_ops[] = {
 	},
 };
 
+static const struct hantro_codec_ops rk3568_jpeg_enc_codec_ops[] = {
+	[HANTRO_MODE_JPEG_ENC] = {
+		.run = rockchip_vpu2_jpeg_enc_run,
+		.reset = rockchip_vpu2_enc_reset,
+		.done = rockchip_vpu2_jpeg_enc_done,
+	},
+};
+
 /*
  * VPU variant.
  */
@@ -439,6 +447,10 @@ static const struct hantro_irq rockchip_vpu2_irqs[] = {
 	{ "vdpu", rockchip_vpu2_vdpu_irq },
 };
 
+static const struct hantro_irq rk3568_vepu_irqs[] = {
+	{ "vepu", rockchip_vpu2_vepu_irq },
+};
+
 static const char * const rk3066_vpu_clk_names[] = {
 	"aclk_vdpu", "hclk_vdpu",
 	"aclk_vepu", "hclk_vepu"
@@ -545,6 +557,19 @@ const struct hantro_variant rk3399_vpu_variant = {
 	.num_clocks = ARRAY_SIZE(rockchip_vpu_clk_names)
 };
 
+const struct hantro_variant rk3568_vepu_variant = {
+	.enc_offset = 0x0,
+	.enc_fmts = rockchip_vpu_enc_fmts,
+	.num_enc_fmts = ARRAY_SIZE(rockchip_vpu_enc_fmts),
+	.codec = HANTRO_JPEG_ENCODER,
+	.codec_ops = rk3568_jpeg_enc_codec_ops,
+	.irqs = rk3568_vepu_irqs,
+	.num_irqs = ARRAY_SIZE(rk3568_vepu_irqs),
+	.init = rockchip_vpu_hw_init,
+	.clk_names = rockchip_vpu_clk_names,
+	.num_clocks = ARRAY_SIZE(rockchip_vpu_clk_names)
+};
+
 const struct hantro_variant px30_vpu_variant = {
 	.enc_offset = 0x0,
 	.enc_fmts = rockchip_vpu_enc_fmts,
Signature · 1 line
2.36.1
#6 lore raw

PATCH v3 3/3 arm64: dts: rockchip: Add Hantro encoder node to rk356x

In reply to Nicolas Frattaroli

The RK3566 and RK3568 come with a dedicated Hantro instance solely for encoding. This patch adds a node for this to the device tree, along with a node for its MMU.

---
 arch/arm64/boot/dts/rockchip/rk356x.dtsi | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm64/boot/dts/rockchip/rk356x.dtsi +21 -0
index 7cdef800cb3c..2e3c9e1887e3 100644
@@ -508,6 +508,27 @@ gpu: gpu@fde60000 {
 		status = "disabled";
 	};
 
+	vepu: video-codec@fdee0000 {
+		compatible = "rockchip,rk3568-vepu";
+		reg = <0x0 0xfdee0000 0x0 0x800>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "vepu";
+		clocks = <&cru ACLK_JENC>, <&cru HCLK_JENC>;
+		clock-names = "aclk", "hclk";
+		iommus = <&vepu_mmu>;
+		power-domains = <&power RK3568_PD_RGA>;
+	};
+
+	vepu_mmu: iommu@fdee0800 {
+		compatible = "rockchip,rk3568-iommu";
+		reg = <0x0 0xfdee0800 0x0 0x40>;
+		interrupts = <GIC_SPI 63 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru ACLK_JENC>, <&cru HCLK_JENC>;
+		clock-names = "aclk", "iface";
+		power-domains = <&power RK3568_PD_RGA>;
+		#iommu-cells = <0>;
+	};
+
 	sdmmc2: mmc@fe000000 {
 		compatible = "rockchip,rk3568-dw-mshc", "rockchip,rk3288-dw-mshc";
 		reg = <0x0 0xfe000000 0x0 0x4000>;
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH v3 1/3] dt-bindings: media: rockchip-vpu: Add RK3568 VEPU compatible

In reply to Nicolas Frattaroli
Quoted 33 lines · Nicolas Frattaroli

The RK3568 and RK3566 have a Hantro VPU node solely dedicated to encoding. This patch adds a compatible for it, and also allows the bindings to only come with a vepu interrupt.

---
 .../devicetree/bindings/media/rockchip-vpu.yaml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +4 -1
index bacb60a34989..965ca80b5cea 100644
@@ -22,6 +22,7 @@ properties:
           - rockchip,rk3288-vpu
           - rockchip,rk3328-vpu
           - rockchip,rk3399-vpu
+          - rockchip,rk3568-vepu
           - rockchip,px30-vpu
       - items:
           - const: rockchip,rk3188-vpu
@@ -39,7 +40,9 @@ properties:
 
   interrupt-names:
     oneOf:
-      - const: vdpu
+      - enum:
+          - vdpu
+          - vepu
       - items:
           - const: vepu
           - const: vdpu

Documentation/devicetree/bindings/media/rockchip-vpu.yaml required: · line 88

Quoted 10 lines
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +7 -0
@@ -76,6 +79,18 @@ required:
 
 additionalProperties: false
 
+allOf:
+  # compatibles that end in -vepu should only have the vepu interrupt
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: "^[a-zA-Z0-9\\-,_.]+\\-vepu$"

Why not listing the compatible how I asked? This is the common way of handling allOf:if:then per variant.

https://lore.kernel.org/all/[email protected]/

Your patches do not apply on next, so the set might not have been tested by Rob's bot.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v3 1/3] dt-bindings: media: rockchip-vpu: Add RK3568 VEPU compatible

Quoted 37 lines · On Mittwoch, 11. Mai 2022 18:00:09 CEST Krzysztof Kozlowski wrote:
Quoted 36 lines · Nicolas Frattaroli

The RK3568 and RK3566 have a Hantro VPU node solely dedicated to encoding. This patch adds a compatible for it, and also allows the bindings to only come with a vepu interrupt.

---
 .../devicetree/bindings/media/rockchip-vpu.yaml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +4 -1
index bacb60a34989..965ca80b5cea 100644
@@ -22,6 +22,7 @@ properties:
           - rockchip,rk3288-vpu
           - rockchip,rk3328-vpu
           - rockchip,rk3399-vpu
+          - rockchip,rk3568-vepu
           - rockchip,px30-vpu
       - items:
           - const: rockchip,rk3188-vpu
@@ -39,7 +40,9 @@ properties:
 
   interrupt-names:
     oneOf:
-      - const: vdpu
+      - enum:
+          - vdpu
+          - vepu
       - items:
           - const: vepu
           - const: vdpu
@@ -76,6 +79,18 @@ required:
 
 additionalProperties: false
 
Quoted 10 lines

Documentation/devicetree/bindings/media/rockchip-vpu.yaml required: · line 88

Quoted 7 lines
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +7 -0
+allOf:
+  # compatibles that end in -vepu should only have the vepu interrupt
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: "^[a-zA-Z0-9\\-,_.]+\\-vepu$"

Why not listing the compatible how I asked? This is the common way of handling allOf:if:then per variant.

Because I was afraid that if this wasn't general enough to apply to all future vepu-only instances of Hantro, then my patch might be bikeshed into requiring a v4. Clearly, my worries had the opposite effect.

Also because I thought it was cool to use a pattern for this to enforce consistent naming in the bindings.

Quoted 5 lines

https://lore.kernel.org/all/[email protected]/

Your patches do not apply on next, so the set might not have been tested by Rob's bot.

Good to know. Once I send out v4 in a few days and maybe after some more opinions so I can stop bombarding the mailing list with tiny revisions of the same patch set, I will base it on linux-next.

I'm happy to report though that this passes dt_binding_check with W=1 without adding any new warnings. I do actually run those checks (and checkpatch) before submitting.

Quoted 4 lines

Best regards,
Krzysztof

Regards,
Nicolas Frattaroli

#4 lore raw

Re: [PATCH v3 1/3] dt-bindings: media: rockchip-vpu: Add RK3568 VEPU compatible

Quoted 49 lines · Nicolas Frattaroli
Quoted 37 lines · On Mittwoch, 11. Mai 2022 18:00:09 CEST Krzysztof Kozlowski wrote:
Quoted 36 lines · Nicolas Frattaroli

The RK3568 and RK3566 have a Hantro VPU node solely dedicated to encoding. This patch adds a compatible for it, and also allows the bindings to only come with a vepu interrupt.

---
 .../devicetree/bindings/media/rockchip-vpu.yaml | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +4 -1
index bacb60a34989..965ca80b5cea 100644
@@ -22,6 +22,7 @@ properties:
           - rockchip,rk3288-vpu
           - rockchip,rk3328-vpu
           - rockchip,rk3399-vpu
+          - rockchip,rk3568-vepu
           - rockchip,px30-vpu
       - items:
           - const: rockchip,rk3188-vpu
@@ -39,7 +40,9 @@ properties:
 
   interrupt-names:
     oneOf:
-      - const: vdpu
+      - enum:
+          - vdpu
+          - vepu
       - items:
           - const: vepu
           - const: vdpu
@@ -76,6 +79,18 @@ required:
 
 additionalProperties: false
 
Quoted 10 lines

Documentation/devicetree/bindings/media/rockchip-vpu.yaml required: · line 88

Quoted 7 lines
Documentation/devicetree/bindings/media/rockchip-vpu.yaml +7 -0
+allOf:
+  # compatibles that end in -vepu should only have the vepu interrupt
+  - if:
+      properties:
+        compatible:
+          contains:
+            pattern: "^[a-zA-Z0-9\\-,_.]+\\-vepu$"

Why not listing the compatible how I asked? This is the common way of handling allOf:if:then per variant.

Quoted 6 lines

Because I was afraid that if this wasn't general enough to apply to all future vepu-only instances of Hantro, then my patch might be bikeshed into requiring a v4. Clearly, my worries had the opposite effect.

Also because I thought it was cool to use a pattern for this to enforce consistent naming in the bindings.

Until it does not match for some reason. :) Just list the compatible under enum and it is expected the list to grow over time (if needed).

Best regards,
Krzysztof

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip