Skip to contentSkip to conversation

Add HANTRO G2/HEVC decoder support for IMX8MQ

PATCH Superseded Benjamin Gaignard 5 participants 30 messages Apr 7, 2021 – Nov 30, 2021

Subsystems (9)

v9 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Benjamin Gaignard

author maintainer
#0 lore raw

v9 cover Add HANTRO G2/HEVC decoder support for IMX8MQ

The IMX8MQ got two VPUs but until now only G1 has been enabled. This series aim to add the second VPU (aka G2) and provide basic HEVC decoding support.

To be able to decode HEVC it is needed to add/update some of the structures in the uapi. In addition of them one HANTRO dedicated control is required to inform the driver of the numbre of bits to skip at the beginning of the slice header.
The hardware require to allocate few auxiliary buffers to store the references frame or tile size data.

The driver has been tested with fluster test suite stream.
For example with this command: ./fluster.py run -ts JCT-VC-HEVC_V1 -d GStreamer-H.265-V4L2SL-Gst1.0

Finally the both VPUs will have a node the device-tree and be independent from v4l2 point of view.

A branch with all the dev is available here:
https://gitlab.collabora.com/benjamin.gaignard/for-upstream/-/commits/upstream_g2_v9

version 9:
- Corrections in commits messages.
- Define the dedicated control in hevc-controls.h
- Add note in documentation.
- Change max value of the dedicated control.
- Rebased on media_tree/master branch.

version 8:
- Add reviewed-by and ack-by tags
- Fix the warnings reported by kernel test robot
- Only patch 9 (adding dedicated control), patch 11 (HEVC support) and patch 13 (DT changes) are still missing of review/ack tag.

version 7:
- Remove 'q' from syscon phandle name to make usable for iMX8MM too. Update the bindings documentation.
- Add review/ack tags.
- Rebase on top of media_tree/master
- Be more accurate when computing the size of the memory needed motion vectors.
- Explain why the all clocks need to set in the both DT node.

version 6:
- fix the errors reported by kernel test robot

version 5:
- use syscon instead of VPU reset driver.
- Do not break kernel/DT backward compatibility.
- Add documentation for dedicated Hantro control.
- Fix the remarks done by Ezequeil (typo, comments, unused function)
- Run v4l2-compliance without errors (see below).
- Do not add field to distinguish version, check postproc reg instead

version 4:
- Split the changes in hevc controls in 2 commits to make them easier to review.
- Change hantro_codec_ops run() prototype to return errors
- Hantro v4l2 dedicated control is now only an integer
- rebase on top of VPU reset changes posted here:
https://www.spinics.net/lists/arm-kernel/msg878440.html
- Various fix from previous remarks
- Limit the modifications in API to what the driver needs

version 3:
- Fix typo in Hantro v4l2 dedicated control
- Add documentation for the new structures and fields
- Rebased on top of media_tree for-linus-5.12-rc1 tag

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.
- be more verbose about why I change the bindings
- remove all sign-off expect mime since it is confusing
- remove useless clocks in VPUs nodes

./v4l2-compliance -m 1
v4l2-compliance 1.21.0-4705, 64 bits, 64-bit time_t v4l2-compliance SHA: 733f7a54f79d 2021-02-03 08:25:49

Compliance test for hantro-vpu device /dev/media1:

Media Driver Info:

	Driver name      : hantro-vpu
	Model            : hantro-vpu
	Serial           : 
	Bus info         : platform: hantro-vpu
	Media version    : 5.11.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 5.11.0

Required ioctls:
test MEDIA_IOC_DEVICE_INFO: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/media1 open: OK
test MEDIA_IOC_DEVICE_INFO: OK
test for unlimited opens: OK

Media Controller ioctls:
test MEDIA_IOC_G_TOPOLOGY: OK
Entities: 3 Interfaces: 1 Pads: 4 Links: 4 test MEDIA_IOC_ENUM_ENTITIES/LINKS: OK test MEDIA_IOC_SETUP_LINK: OK

Total for hantro-vpu device /dev/media1: 8, Succeeded: 8, Failed: 0, Warnings: 0
--------------------------------------------------------------------------------
Compliance test for hantro-vpu device /dev/video1:

Driver Info:

	Driver name      : hantro-vpu
	Card type        : nxp,imx8mq-vpu-g2-dec
	Bus info         : platform: hantro-vpu
	Driver version   : 5.11.0
	Capabilities     : 0x84204000

Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Media Driver Info:

	Driver name      : hantro-vpu
	Model            : hantro-vpu
	Serial           : 
	Bus info         : platform: hantro-vpu
	Media version    : 5.11.0
	Hardware revision: 0x00000000 (0)
	Driver version   : 5.11.0
Interface Info:
	ID               : 0x0300000c
	Type             : V4L Video
Entity Info:
	ID               : 0x00000001 (1)
	Name             : nxp,imx8mq-vpu-g2-dec-source
	Function         : V4L2 I/O
	Pad 0x01000002   : 0: Source
	  Link 0x02000008: to remote pad 0x1000004 of entity 'nxp,imx8mq-vpu-g2-dec-proc': Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video1 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, Warnings: 0

Benjamin

Benjamin Gaignard (13):
dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
media: hantro: Use syscon instead of 'ctrl' register
media: hevc: Add fields and flags for hevc PPS
media: hevc: Add decode params control
media: hantro: change hantro_codec_ops run prototype to return errors
media: hantro: Define HEVC codec profiles and supported features
media: hantro: Only use postproc when post processed formats are
defined
media: uapi: Add a control for HANTRO driver
media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
media: hantro: Introduce G2/HEVC decoder
media: hantro: IMX8M: add variant for G2/HEVC codec
arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml        |  53 +-
 .../devicetree/bindings/mfd/syscon.yaml       |   1 +
 .../userspace-api/media/drivers/hantro.rst    |  19 +
 .../userspace-api/media/drivers/index.rst     |   1 +
 .../media/v4l/ext-ctrls-codec.rst             | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst            |   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi     |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c          |  28 +-
 drivers/staging/media/hantro/Makefile         |   2 +
 drivers/staging/media/hantro/hantro.h         |  18 +-
 drivers/staging/media/hantro/hantro_drv.c     |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c        |   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c    | 327 ++++++++++
 drivers/staging/media/hantro/hantro_hw.h      |  69 +-
 .../staging/media/hantro/hantro_postproc.c    |  14 +
 drivers/staging/media/hantro/hantro_v4l2.c    |   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   | 128 +++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c     |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c    |   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c      |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |  12 +-
 include/media/hevc-ctrls.h                    |  46 +-
 30 files changed, 1690 insertions(+), 121 deletions(-)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v9 1/13 dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

Add 'nxp,imx8mq-vpu-ctrl' to the list of possible syscon. It will used to access the VPU control registers.

---
version 9:
- corrections in commit message

version 8:
- Add Lee ack

version 7:
- Add Rob ack

 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/mfd/syscon.yaml +1 -0
index f14ae6da0068..ae22c4730613 100644
@@ -44,6 +44,7 @@ properties:
               - hisilicon,peri-subctrl
               - microchip,sparx5-cpu-syscon
               - mstar,msc313-pmsleep
+              - nxp,imx8mq-vpu-ctrl
               - rockchip,px30-qos
               - rockchip,rk3066-qos
               - rockchip,rk3288-qos
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH v9 2/13 dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

In reply to Benjamin Gaignard

Introducing the G2 hevc video decoder requires modifications of the bindings to allow one node per VPU.

VPUs share one hardware control block which is provided as a phandle on a syscon.
Each node has now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use the 'ctrl' reg-name even if it is deprecated now.

---
version 9:
- Corrections in commit message

version 7:
- Add Rob and Philipp reviewed-by tag
- Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml        | 53 ++++++++++++-------
 1 file changed, 34 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml +34 -19
index 762be3f96ce9..18e7d40a5f24 100644
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-    const: nxp,imx8mq-vpu
+    oneOf:
+      - const: nxp,imx8mq-vpu
+      - const: nxp,imx8mq-vpu-g2
 
   reg:
-    maxItems: 3
-
-  reg-names:
-    items:
-      - const: g1
-      - const: g2
-      - const: ctrl
+    maxItems: 1
 
   interrupts:
-    maxItems: 2
+    maxItems: 1
 
   interrupt-names:
-    items:
+    oneOf:
       - const: g1
       - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
     maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+    description: Specifies a phandle to syscon VPU hardware control block
+    $ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8m-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
         #include <dt-bindings/clock/imx8mq-clock.h>
         #include <dt-bindings/interrupt-controller/arm-gic.h>
 
-        vpu: video-codec@38300000 {
+        vpu_ctrl: syscon@38320000 {
+                 compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+                 reg = <0x38320000 0x10000>;
+        };
+
+        vpu_g1: video-codec@38300000 {
                 compatible = "nxp,imx8mq-vpu";
-                reg = <0x38300000 0x10000>,
-                      <0x38310000 0x10000>,
-                      <0x38320000 0x10000>;
-                reg-names = "g1", "g2", "ctrl";
-                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-                             <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-                interrupt-names = "g1", "g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g1";
+                clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+                clock-names = "g1", "g2", "bus";
+                power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
+        };
+
+        vpu_g2: video-codec@38310000 {
+                compatible = "nxp,imx8mq-vpu-g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g2";
                 clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
                 clock-names = "g1", "g2", "bus";
                 power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
         };
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v9 02/13] dt-bindings: media: nxp, imx8mq-vpu: Update the bindings for G2 support

Quoted 9 lines · Benjamin Gaignard

Introducing the G2 hevc video decoder requires modifications of the bindings to allow one node per VPU.

VPUs share one hardware control block which is provided as a phandle on a syscon.
Each node has now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

Quoted 6 lines

To be compatible with older DT the driver is still capable to use the 'ctrl' reg-name even if it is deprecated now.

I need to edit the yaml file to add support the imx8mm, but it doesn't appear that this series has gone anywhere. I know there is still some waiting on the vpu-blk-ctrl driver, but it seems like the 8mq could split the codecs out using syscon in place of the blk-ctrl until that driver is available. If that doesn't work, I might have to introduce a separate yaml file for mini which could be somehow merged with the 8mq in the future. I am just not sure which way to go right now.

adam

Quoted 115 lines

---
version 9:
- Corrections in commit message

version 7:
- Add Rob and Philipp reviewed-by tag
- Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml        | 53 ++++++++++++-------
 1 file changed, 34 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml +34 -20
index 762be3f96ce9..18e7d40a5f24 100644
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-    const: nxp,imx8mq-vpu
+    oneOf:
+      - const: nxp,imx8mq-vpu
+      - const: nxp,imx8mq-vpu-g2
 
   reg:
-    maxItems: 3
-
-  reg-names:
-    items:
-      - const: g1
-      - const: g2
-      - const: ctrl
+    maxItems: 1
 
   interrupts:
-    maxItems: 2
+    maxItems: 1
 
   interrupt-names:
-    items:
+    oneOf:
       - const: g1
       - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
     maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+    description: Specifies a phandle to syscon VPU hardware control block
+    $ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8m-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
         #include <dt-bindings/clock/imx8mq-clock.h>
         #include <dt-bindings/interrupt-controller/arm-gic.h>
 
-        vpu: video-codec@38300000 {
+        vpu_ctrl: syscon@38320000 {
+                 compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+                 reg = <0x38320000 0x10000>;
+        };
+
+        vpu_g1: video-codec@38300000 {
                 compatible = "nxp,imx8mq-vpu";
-                reg = <0x38300000 0x10000>,
-                      <0x38310000 0x10000>,
-                      <0x38320000 0x10000>;
-                reg-names = "g1", "g2", "ctrl";
-                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-                             <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-                interrupt-names = "g1", "g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g1";
+                clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+                clock-names = "g1", "g2", "bus";
+                power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
+        };
+
+        vpu_g2: video-codec@38310000 {
+                compatible = "nxp,imx8mq-vpu-g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g2";
                 clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
                 clock-names = "g1", "g2", "bus";
                 power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
         };
--

2.25.1

Quoted 4 lines

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

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

author maintainer
#4 lore raw

Re: [PATCH v9 02/13] dt-bindings: media: nxp, imx8mq-vpu: Update the bindings for G2 support

Le 29/11/2021 à 21:13, Adam Ford a écrit :

Quoted 16 lines
Quoted 8 lines · Benjamin Gaignard

Introducing the G2 hevc video decoder requires modifications of the bindings to allow one node per VPU.

VPUs share one hardware control block which is provided as a phandle on a syscon.
Each node has now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

Quoted 6 lines

To be compatible with older DT the driver is still capable to use the 'ctrl' reg-name even if it is deprecated now.

Quoted 7 lines

I need to edit the yaml file to add support the imx8mm, but it doesn't appear that this series has gone anywhere. I know there is still some waiting on the vpu-blk-ctrl driver, but it seems like the 8mq could split the codecs out using syscon in place of the blk-ctrl until that driver is available. If that doesn't work, I might have to introduce a separate yaml file for mini which could be somehow merged with the 8mq in the future. I am just not sure which way to go right now.

To summarize Lucas a have a branch here: https://git.pengutronix.de/cgit/lst/linux/log/?h=imx8mq-vpu-blk-ctrl
where he try to enable blk-ctrl for imx6mq, it is working for G1 but not for G2.

You can find the thread about that here:
https://www.spinics.net/lists/devicetree/msg450831.html

Regards,
Benjamin

Quoted 121 lines

adam

Quoted 119 lines

---
version 9:
- Corrections in commit message

version 7:
- Add Rob and Philipp reviewed-by tag
- Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel and DT.

  .../bindings/media/nxp,imx8mq-vpu.yaml        | 53 ++++++++++++-------
  1 file changed, 34 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml +34 -20
index 762be3f96ce9..18e7d40a5f24 100644
@@ -15,22 +15,18 @@ description:
 
  properties:
    compatible:
-    const: nxp,imx8mq-vpu
+    oneOf:
+      - const: nxp,imx8mq-vpu
+      - const: nxp,imx8mq-vpu-g2
 
    reg:
-    maxItems: 3
-
-  reg-names:
-    items:
-      - const: g1
-      - const: g2
-      - const: ctrl
+    maxItems: 1
 
    interrupts:
-    maxItems: 2
+    maxItems: 1
 
    interrupt-names:
-    items:
+    oneOf:
        - const: g1
        - const: g2
 
@@ -46,14 +42,18 @@ properties:
    power-domains:
      maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+    description: Specifies a phandle to syscon VPU hardware control block
+    $ref: "/schemas/types.yaml#/definitions/phandle"
+
  required:
    - compatible
    - reg
-  - reg-names
    - interrupts
    - interrupt-names
    - clocks
    - clock-names
+  - nxp,imx8m-vpu-ctrl
 
  additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
          #include <dt-bindings/clock/imx8mq-clock.h>
          #include <dt-bindings/interrupt-controller/arm-gic.h>
 
-        vpu: video-codec@38300000 {
+        vpu_ctrl: syscon@38320000 {
+                 compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+                 reg = <0x38320000 0x10000>;
+        };
+
+        vpu_g1: video-codec@38300000 {
                  compatible = "nxp,imx8mq-vpu";
-                reg = <0x38300000 0x10000>,
-                      <0x38310000 0x10000>,
-                      <0x38320000 0x10000>;
-                reg-names = "g1", "g2", "ctrl";
-                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-                             <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-                interrupt-names = "g1", "g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g1";
+                clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+                clock-names = "g1", "g2", "bus";
+                power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
+        };
+
+        vpu_g2: video-codec@38310000 {
+                compatible = "nxp,imx8mq-vpu-g2";
+                reg = <0x38300000 0x10000>;
+                interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g2";
                  clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
                           <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
                           <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
                  clock-names = "g1", "g2", "bus";
                  power-domains = <&pgc_vpu>;
+                nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
          };
--

2.25.1

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

author maintainer
#5 lore raw

PATCH v9 3/13 media: hantro: Use syscon instead of 'ctrl' register

In reply to Benjamin Gaignard

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

---
version 9:
- Corrections in commit message

version 7:
- Add Philipp reviewed-by tag.
- Change syscon phandle name.

version 5:
- use syscon instead of VPU reset driver.
- if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h       |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------
 2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +3 -2
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/videodev2.h>
 #include <linux/wait.h>
 #include <linux/clk.h>
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases:		Mapped addresses of VPU registers.
  * @enc_base:		Mapped address of VPU encoder register for convenience.
  * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
  * @vpu_mutex:		Mutex to synchronize V4L2 calls.
  * @irqlock:		Spinlock to synchronize access to data structures
  *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
 	void __iomem **reg_bases;
 	void __iomem *enc_base;
 	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;
 
 	struct mutex vpu_mutex;	/* video_device lock */
 	spinlock_t irqlock;
drivers/staging/media/hantro/imx8m_vpu_hw.c +31 -21

97 lines not on this page · raw message

Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Regards,
Lucas

Quoted 207 lines

---
version 9:
 - Corrections in commit message

version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.

version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h | 5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------

 2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +0 -0
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
  #define HANTRO_H_

 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/videodev2.h>
 #include <linux/wait.h>
 #include <linux/clk.h>

drivers/staging/media/hantro/hantro.h +2 -2
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
   * @reg_bases:		Mapped addresses of VPU registers.
   * @enc_base:		Mapped address of VPU encoder register for convenience.
   * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
   * @vpu_mutex:		Mutex to synchronize V4L2 calls.
   * @irqlock:		Spinlock to synchronize access to data structures
   *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
  	void __iomem **reg_bases;
  	void __iomem *enc_base;
  	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;

  struct mutex vpu_mutex; /* video_device lock */
  spinlock_t irqlock;

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
index c222de075ef4..8d0c3425234b 100644
@@ -7,6 +7,7 @@

 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/mfd/syscon.h>

 #include "hantro.h"
 #include "hantro_jpeg.h"

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -24,30 +25,28 @@
  #define CTRL_G1_PP_FUSE		0x0c
  #define CTRL_G2_DEC_FUSE	0x10

drivers/staging/media/hantro/imx8m_vpu_hw.c +6 -0
+static const struct regmap_config ctrl_regmap_ctrl = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 0x14,
+};
+

 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
-	u32 val;
-

  /* Assert */

drivers/staging/media/hantro/imx8m_vpu_hw.c +1 -3
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val &= ~reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);

  udelay(2);

  /* Release */

drivers/staging/media/hantro/imx8m_vpu_hw.c +2 -3
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val |= reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+			   reset_bits, reset_bits);

 }

 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +2 -5
-	u32 val;
-
-	val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-	val |= clock_bits;
-	writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+	regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+			   clock_bits, clock_bits);

 }

 static int imx8mq_runtime_resume(struct hantro_dev *vpu)

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
  	imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);

  /* Set values of the fuse registers */

drivers/staging/media/hantro/imx8m_vpu_hw.c +3 -3
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+	regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0xffffffff);

  clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)

 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +16 -2
-	vpu->dec_base = vpu->reg_bases[0];
-	vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+	struct device_node *np = vpu->dev->of_node;
+
+	vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, "nxp,imx8m-vpu-ctrl");
+	if (IS_ERR(vpu->ctrl_base)) {
+		struct resource *res;
+		void __iomem *ctrl;
+
+		res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, "ctrl");
+		ctrl = devm_ioremap_resource(vpu->dev, res);
+		if (IS_ERR(ctrl))
+			return PTR_ERR(ctrl);
+
+		vpu->ctrl_base = devm_regmap_init_mmio(vpu->dev, ctrl, &ctrl_regmap_ctrl);
+		if (IS_ERR(vpu->ctrl_base))
+			return PTR_ERR(vpu->ctrl_base);
+	}

  return 0;
 }

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -198,7 +211,6 @@ static const struct hantro_irq imx8mq_irqs[] = {
  };

 static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" }; -static const char * const imx8mq_reg_names[] = { "g1", "g2", "ctrl" };

 const struct hantro_variant imx8mq_vpu_variant = { .dec_fmts = imx8m_vpu_dec_fmts,

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
@@ -215,6 +227,4 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_irqs = ARRAY_SIZE(imx8mq_irqs),
  	.clk_names = imx8mq_clk_names,
  	.num_clocks = ARRAY_SIZE(imx8mq_clk_names),
-	.reg_names = imx8mq_reg_names,
-	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };
author maintainer
#7 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 18 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 2 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

Regards,
Benjamin

Quoted 213 lines

Regards,
Lucas

Quoted 207 lines

---
version 9:
 - Corrections in commit message

version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.

version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

  drivers/staging/media/hantro/hantro.h       |  5 +-
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------
  2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +1 -0
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
  #define HANTRO_H_
 
 
 
 
  #include <linux/platform_device.h>
+#include <linux/regmap.h>

 #include <linux/videodev2.h>
 #include <linux/wait.h>
 #include <linux/clk.h>

drivers/staging/media/hantro/hantro.h +2 -2
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
   * @reg_bases:		Mapped addresses of VPU registers.
   * @enc_base:		Mapped address of VPU encoder register for convenience.
   * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
   * @vpu_mutex:		Mutex to synchronize V4L2 calls.
   * @irqlock:		Spinlock to synchronize access to data structures
   *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
  	void __iomem **reg_bases;
  	void __iomem *enc_base;
  	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;
 
 
 

  struct mutex vpu_mutex; /* video_device lock */
  spinlock_t irqlock;

drivers/staging/media/hantro/imx8m_vpu_hw.c +1 -0
index c222de075ef4..8d0c3425234b 100644
@@ -7,6 +7,7 @@
 
 
 
 
  #include <linux/clk.h>
  #include <linux/delay.h>
+#include <linux/mfd/syscon.h>

 #include "hantro.h"
 #include "hantro_jpeg.h"

drivers/staging/media/hantro/imx8m_vpu_hw.c +14 -16
@@ -24,30 +25,28 @@
  #define CTRL_G1_PP_FUSE		0x0c
  #define CTRL_G2_DEC_FUSE	0x10
 
 
 
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 0x14,
+};
+
  static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
  {
-	u32 val;
-
  	/* Assert */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val &= ~reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
 
 
 
  	udelay(2);
 
 
 
 
  	/* Release */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val |= reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+			   reset_bits, reset_bits);
  }
 
 
 
 
  static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
  {
-	u32 val;
-
-	val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-	val |= clock_bits;
-	writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+	regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+			   clock_bits, clock_bits);
  }
 
 
 
 
  static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
  	imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
 
 
 
  	/* Set values of the fuse registers */
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+	regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0xffffffff);

  clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);

drivers/staging/media/hantro/imx8m_vpu_hw.c +16 -2
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 
 
 
  static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
  {
-	vpu->dec_base = vpu->reg_bases[0];
-	vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+	struct device_node *np = vpu->dev->of_node;
+
+	vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, "nxp,imx8m-vpu-ctrl");
+	if (IS_ERR(vpu->ctrl_base)) {
+		struct resource *res;
+		void __iomem *ctrl;
+
+		res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, "ctrl");
+		ctrl = devm_ioremap_resource(vpu->dev, res);
+		if (IS_ERR(ctrl))
+			return PTR_ERR(ctrl);
+
+		vpu->ctrl_base = devm_regmap_init_mmio(vpu->dev, ctrl, &ctrl_regmap_ctrl);
+		if (IS_ERR(vpu->ctrl_base))
+			return PTR_ERR(vpu->ctrl_base);
+	}

  return 0;
 }

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -1
@@ -198,7 +211,6 @@ static const struct hantro_irq imx8mq_irqs[] = {
  };
 
 
 
 
  static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
-static const char * const imx8mq_reg_names[] = { "g1", "g2", "ctrl" };

 const struct hantro_variant imx8mq_vpu_variant = { .dec_fmts = imx8m_vpu_dec_fmts,

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
@@ -215,6 +227,4 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_irqs = ARRAY_SIZE(imx8mq_irqs),
  	.clk_names = imx8mq_clk_names,
  	.num_clocks = ARRAY_SIZE(imx8mq_clk_names),
-	.reg_names = imx8mq_reg_names,
-	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };
#8 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Quoted 19 lines

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 18 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 7 lines
Quoted 2 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that hvec patches, as I only skimmed them, but I don't see any reason to delay patches 04-11 from this series until the i.MX8M platform issues are sorted. AFAICS those things are totally orthogonal.

Regards,
Lucas

Quoted 253 lines
Quoted 253 lines

Regards,
Lucas

Quoted 249 lines

---
version 9:
  - Corrections in commit message

version 7:
  - Add Philipp reviewed-by tag.
  - Change syscon phandle name.

version 5:
  - use syscon instead of VPU reset driver.
  - if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

  drivers/staging/media/hantro/hantro.h | 5 +-
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------

  2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +0 -0
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
   #define HANTRO_H_

  #include <linux/platform_device.h>
+#include <linux/regmap.h>
  #include <linux/videodev2.h>
  #include <linux/wait.h>
  #include <linux/clk.h>

drivers/staging/media/hantro/hantro.h +2 -2
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
    * @reg_bases:		Mapped addresses of VPU registers.
    * @enc_base:		Mapped address of VPU encoder register for convenience.
    * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
    * @vpu_mutex:		Mutex to synchronize V4L2 calls.
    * @irqlock:		Spinlock to synchronize access to data structures
    *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
   	void __iomem **reg_bases;
   	void __iomem *enc_base;
   	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;

   struct mutex vpu_mutex; /* video_device lock */
   spinlock_t irqlock;

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
index c222de075ef4..8d0c3425234b 100644
@@ -7,6 +7,7 @@

  #include <linux/clk.h>
  #include <linux/delay.h>
+#include <linux/mfd/syscon.h>

  #include "hantro.h"
  #include "hantro_jpeg.h"

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -24,30 +25,28 @@
   #define CTRL_G1_PP_FUSE		0x0c
   #define CTRL_G2_DEC_FUSE	0x10

drivers/staging/media/hantro/imx8m_vpu_hw.c +6 -0
+static const struct regmap_config ctrl_regmap_ctrl = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 0x14,
+};
+

  static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
-	u32 val;
-

   /* Assert */

drivers/staging/media/hantro/imx8m_vpu_hw.c +1 -3
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val &= ~reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);

   udelay(2);

   /* Release */

drivers/staging/media/hantro/imx8m_vpu_hw.c +2 -3
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val |= reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+			   reset_bits, reset_bits);

  }

  static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +2 -5
-	u32 val;
-
-	val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-	val |= clock_bits;
-	writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+	regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+			   clock_bits, clock_bits);

  }

  static int imx8mq_runtime_resume(struct hantro_dev *vpu)

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
   	imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);

   /* Set values of the fuse registers */

drivers/staging/media/hantro/imx8m_vpu_hw.c +3 -3
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+	regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0xffffffff);

   clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)

  static int imx8mq_vpu_hw_init(struct hantro_dev *vpu) {

drivers/staging/media/hantro/imx8m_vpu_hw.c +16 -2
-	vpu->dec_base = vpu->reg_bases[0];
-	vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+	struct device_node *np = vpu->dev->of_node;
+
+	vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, "nxp,imx8m-vpu-ctrl");
+	if (IS_ERR(vpu->ctrl_base)) {
+		struct resource *res;
+		void __iomem *ctrl;
+
+		res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, "ctrl");
+		ctrl = devm_ioremap_resource(vpu->dev, res);
+		if (IS_ERR(ctrl))
+			return PTR_ERR(ctrl);
+
+		vpu->ctrl_base = devm_regmap_init_mmio(vpu->dev, ctrl, &ctrl_regmap_ctrl);
+		if (IS_ERR(vpu->ctrl_base))
+			return PTR_ERR(vpu->ctrl_base);
+	}

   return 0;
  }

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -0
@@ -198,7 +211,6 @@ static const struct hantro_irq imx8mq_irqs[] = {
   };

  static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" }; -static const char * const imx8mq_reg_names[] = { "g1", "g2", "ctrl" };

Quoted 12 lines
Quoted 11 lines

drivers/staging/media/hantro/imx8m_vpu_hw.c const struct hantro_variant imx8mq_vpu_variant = { · line 230

Quoted 9 lines

  const struct hantro_variant imx8mq_vpu_variant = { .dec_fmts = imx8m_vpu_dec_fmts,

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
@@ -215,6 +227,4 @@ const struct hantro_variant imx8mq_vpu_variant = {
   	.num_irqs = ARRAY_SIZE(imx8mq_irqs),
   	.clk_names = imx8mq_clk_names,
   	.num_clocks = ARRAY_SIZE(imx8mq_clk_names),
-	.reg_names = imx8mq_reg_names,
-	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
   };

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

author maintainer
#9 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Quoted 22 lines

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Quoted 21 lines

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 20 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines
Quoted 4 lines

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that hvec patches, as I only skimmed them, but I don't see any reason to delay patches 04-11 from this series until the i.MX8M platform issues are sorted. AFAICS those things are totally orthogonal.

Hi Hans,
What do you think about this proposal to split this series ? Get hevc part merged could allow me to continue to add features like scaling lists, compressed reference buffers and 10-bit supports.

Regards,
Benjamin

Quoted 268 lines

Regards,
Lucas

Quoted 262 lines
Quoted 262 lines

Regards,
Lucas

Quoted 258 lines

---
version 9:
  - Corrections in commit message

version 7:
  - Add Philipp reviewed-by tag.
  - Change syscon phandle name.

version 5:
  - use syscon instead of VPU reset driver.
  - if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

   drivers/staging/media/hantro/hantro.h       |  5 +-
   drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------
   2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +3 -2
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
   #define HANTRO_H_
 
 
 
 
 
 
 
   #include <linux/platform_device.h>
+#include <linux/regmap.h>
   #include <linux/videodev2.h>
   #include <linux/wait.h>
   #include <linux/clk.h>
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
    * @reg_bases:		Mapped addresses of VPU registers.
    * @enc_base:		Mapped address of VPU encoder register for convenience.
    * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
    * @vpu_mutex:		Mutex to synchronize V4L2 calls.
    * @irqlock:		Spinlock to synchronize access to data structures
    *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
   	void __iomem **reg_bases;
   	void __iomem *enc_base;
   	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;
 
 
 

   struct mutex vpu_mutex; /* video_device lock */
   spinlock_t irqlock;

drivers/staging/media/hantro/imx8m_vpu_hw.c +31 -21
index c222de075ef4..8d0c3425234b 100644
@@ -7,6 +7,7 @@
 
 
 
 
 
 
 
   #include <linux/clk.h>
   #include <linux/delay.h>
+#include <linux/mfd/syscon.h>
 
 
 
 
 
 
 
   #include "hantro.h"
   #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
   #define CTRL_G1_PP_FUSE		0x0c
   #define CTRL_G2_DEC_FUSE	0x10
 
 
 
 
 
 
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 0x14,
+};
+
   static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
   {
-	u32 val;
-
   	/* Assert */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val &= ~reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
 
 
 
 
 
 
   	udelay(2);
 
 
 
 
 
 
 
   	/* Release */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val |= reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+			   reset_bits, reset_bits);
   }
 
 
 
 
 
 
 
   static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
   {
-	u32 val;
-
-	val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-	val |= clock_bits;
-	writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+	regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+			   clock_bits, clock_bits);
   }
 
 
 
 
 
 
 
   static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
   	imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
 
 
 
 
 
 
   	/* Set values of the fuse registers */
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+	regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0xffffffff);
 
 
 
 
 
 
 
   	clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 
 
 
 
 
 
   static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
   {
-	vpu->dec_base = vpu->reg_bases[0];
-	vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+	struct device_node *np = vpu->dev->of_node;
+
+	vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, "nxp,imx8m-vpu-ctrl");
+	if (IS_ERR(vpu->ctrl_base)) {
+		struct resource *res;
+		void __iomem *ctrl;
+
+		res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, "ctrl");
+		ctrl = devm_ioremap_resource(vpu->dev, res);
+		if (IS_ERR(ctrl))
+			return PTR_ERR(ctrl);
+
+		vpu->ctrl_base = devm_regmap_init_mmio(vpu->dev, ctrl, &ctrl_regmap_ctrl);
+		if (IS_ERR(vpu->ctrl_base))
+			return PTR_ERR(vpu->ctrl_base);
+	}
 
 
 
 
 
 
 
   	return 0;
   }
@@ -198,7 +211,6 @@ static const struct hantro_irq imx8mq_irqs[] = {
   };
 
 
 
 
 
 
 
   static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
-static const char * const imx8mq_reg_names[] = { "g1", "g2", "ctrl" };
 
 
 
 
 
 
 
   const struct hantro_variant imx8mq_vpu_variant = {
   	.dec_fmts = imx8m_vpu_dec_fmts,
@@ -215,6 +227,4 @@ const struct hantro_variant imx8mq_vpu_variant = {
   	.num_irqs = ARRAY_SIZE(imx8mq_irqs),
   	.clk_names = imx8mq_clk_names,
   	.num_clocks = ARRAY_SIZE(imx8mq_clk_names),
-	.reg_names = imx8mq_reg_names,
-	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
   };
#10 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Quoted 33 lines · Benjamin Gaignard

Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Quoted 22 lines

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Quoted 21 lines

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 20 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines
Quoted 4 lines

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that hvec patches, as I only skimmed them, but I don't see any reason to delay patches 04-11 from this series until the i.MX8M platform issues are sorted. AFAICS those things are totally orthogonal.

Quoted 4 lines

Hi Hans,
What do you think about this proposal to split this series ? Get hevc part merged could allow me to continue to add features like scaling lists, compressed reference buffers and 10-bit supports.

Makes sense to me!

Regards,

Hans

author maintainer
#11 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Le 20/04/2021 à 11:16, Hans Verkuil a écrit :

Quoted 32 lines · Benjamin Gaignard
Quoted 31 lines

Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Quoted 30 lines

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Quoted 19 lines

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 18 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 6 lines
Quoted 2 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that hvec patches, as I only skimmed them, but I don't see any reason to delay patches 04-11 from this series until the i.MX8M platform issues are sorted. AFAICS those things are totally orthogonal.

Quoted 5 lines
Quoted 4 lines

Hi Hans,
What do you think about this proposal to split this series ? Get hevc part merged could allow me to continue to add features like scaling lists, compressed reference buffers and 10-bit supports.

Makes sense to me!

Great !
If the latest version match your expectations how would you like to processed ? Can you merged patches 4 to 12 ? or should I resend them in a new shorted series ?

Regards,
Benjamin

Quoted 5 lines

Regards,

Hans

#12 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Quoted 38 lines · Benjamin Gaignard

Le 20/04/2021 à 11:16, Hans Verkuil a écrit :

Quoted 36 lines · Benjamin Gaignard
Quoted 35 lines

Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Quoted 22 lines

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Quoted 21 lines

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 20 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines
Quoted 4 lines

That could replace the 3 first patches and Dt patche of this series but that will not impact the hevc part, so I wonder if pure hevc patches could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that hvec patches, as I only skimmed them, but I don't see any reason to delay patches 04-11 from this series until the i.MX8M platform issues are sorted. AFAICS those things are totally orthogonal.

Hi Hans,
What do you think about this proposal to split this series ? Get hevc part merged could allow me to continue to add features like scaling lists, compressed reference buffers and 10-bit supports.

Quoted 5 lines
Quoted 1 line

Makes sense to me!

Great !
If the latest version match your expectations how would you like to processed ? Can you merged patches 4 to 12 ? or should I resend them in a new shorted series ?

A separate patch series would be easier for me.

Regards,

Hans

Quoted 9 lines

Regards,
Benjamin

Quoted 5 lines

Regards,

Hans

#13 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

In reply to Lucas Stach

Hi Lucas,

Quoted 19 lines · Lucas Stach

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 3 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

It seems the i.MX8MM BLK-CTL series are moving forward:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=479175

... but I'm unable to wrap my head around how this affects the devicetree VPU modelling for i.MX8MQ (and also i.MX8MM, i.MX8MP, ...).

Can you clarify that?

Thanks,
Ezequiel

#14 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Hi Ezequiel,

Am Sonntag, dem 16.05.2021 um 19:40 -0300 schrieb Ezequiel Garcia:

Quoted 26 lines

Hi Lucas,

Quoted 19 lines · Lucas Stach

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 3 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines

It seems the i.MX8MM BLK-CTL series are moving forward:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=479175

... but I'm unable to wrap my head around how this affects the devicetree VPU modelling for i.MX8MQ (and also i.MX8MM, i.MX8MP, ...).

For the i.MX8MQ we want to have the same virtual power-domains provided by a BLK-CTRL driver for the VPUs, as on i.MX8MM. This way we should be able to use the same DT bindings for the VPUs on i.MX8MQ and i.MX8MM, even though the SoC integration with the blk-ctrl is a little different.

Quoted 2 lines

Can you clarify that?

I'm planning on sending some patches adding i.MX8MQ VPU support to the BLK-CTRL driver in the next few days. I guess that should clarify things. :)

Regards,
Lucas

#15 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Quoted 37 lines · Lucas Stach

Hi Ezequiel,

Am Sonntag, dem 16.05.2021 um 19:40 -0300 schrieb Ezequiel Garcia:

Quoted 26 lines

Hi Lucas,

Quoted 19 lines · Lucas Stach

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 3 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines

It seems the i.MX8MM BLK-CTL series are moving forward:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=479175

... but I'm unable to wrap my head around how this affects the devicetree VPU modelling for i.MX8MQ (and also i.MX8MM, i.MX8MP, ...).

Quoted 6 lines

For the i.MX8MQ we want to have the same virtual power-domains provided by a BLK-CTRL driver for the VPUs, as on i.MX8MM. This way we should be able to use the same DT bindings for the VPUs on i.MX8MQ and i.MX8MM, even though the SoC integration with the blk-ctrl is a little different.

AFAICS, there's not support for i.MX8MP VPU power domains. I suppose we should make sure we'll be able to cover those as well.

Will i.MX8MP need its own driver as well?

Quoted 6 lines
Quoted 2 lines

Can you clarify that?

I'm planning on sending some patches adding i.MX8MQ VPU support to the BLK-CTRL driver in the next few days. I guess that should clarify things. :)

Great.

Thanks a lot,
Ezequiel

#16 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Am Montag, dem 17.05.2021 um 10:23 -0300 schrieb Ezequiel Garcia:

Quoted 45 lines · Lucas Stach
Quoted 37 lines

Hi Ezequiel,

Am Sonntag, dem 16.05.2021 um 19:40 -0300 schrieb Ezequiel Garcia:

Quoted 26 lines

Hi Lucas,

Quoted 19 lines · Lucas Stach

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 3 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines

It seems the i.MX8MM BLK-CTL series are moving forward:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=479175

... but I'm unable to wrap my head around how this affects the devicetree VPU modelling for i.MX8MQ (and also i.MX8MM, i.MX8MP, ...).

Quoted 6 lines

For the i.MX8MQ we want to have the same virtual power-domains provided by a BLK-CTRL driver for the VPUs, as on i.MX8MM. This way we should be able to use the same DT bindings for the VPUs on i.MX8MQ and i.MX8MM, even though the SoC integration with the blk-ctrl is a little different.

Quoted 5 lines

AFAICS, there's not support for i.MX8MP VPU power domains. I suppose we should make sure we'll be able to cover those as well.

Will i.MX8MP need its own driver as well?

Quoted 1 line

I haven't looked too closely at the 8MP VPU subsystem yet, but I expect it to be slightly different again so it will need changes to the blk- ctrl driver. But that's the whole point of this virtual power domain
exercise: abstract away the SoC specific things in the blk-ctrl driver, so the VPU driver doesn't need to care about them.

Regards,
Lucas

#17 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

In reply to Lucas Stach

Hi Lucas,

Quoted 43 lines · Lucas Stach

Hi Ezequiel,

Am Sonntag, dem 16.05.2021 um 19:40 -0300 schrieb Ezequiel Garcia:

Quoted 26 lines

Hi Lucas,

Quoted 19 lines · Lucas Stach

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 3 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 8 lines

It seems the i.MX8MM BLK-CTL series are moving forward:

https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=479175

... but I'm unable to wrap my head around how this affects the devicetree VPU modelling for i.MX8MQ (and also i.MX8MM, i.MX8MP, ...).

For the i.MX8MQ we want to have the same virtual power-domains provided by a BLK-CTRL driver for the VPUs, as on i.MX8MM. This way we should be able to use the same DT bindings for the VPUs on i.MX8MQ and i.MX8MM, even though the SoC integration with the blk-ctrl is a little different.

Quoted 6 lines
Quoted 2 lines

Can you clarify that?

I'm planning on sending some patches adding i.MX8MQ VPU support to the BLK-CTRL driver in the next few days. I guess that should clarify things. :)

As a gentle reminder, Hans sent the i.MX8MQ G2 HEVC support pull request and Benjamin just posted a series adding support for more features.

Do you think we could have the blk-ctrl support landing in v5.14?

If you work on the patches, and you happen to test the G1 and G2 on i.MX8MM it would be great to add that too.

Meanwhile, our next steps would be to improve the HEVC V4L2 uAPI itself.

Thanks a lot!
Ezequiel

author maintainer
#18 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

In reply to Lucas Stach

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 18 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 2 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Hey guys,

I may I have miss them but I haven't see patches about power domain for IMX8MQ VPU control block ?
Is it something that you still plan to do ?
If not, I can resend my patches where I use syscon.

Regards,
Benjamin

Quoted 202 lines

Regards,
Lucas

Quoted 198 lines

---
version 9:
 - Corrections in commit message

version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.

version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using 'ctrl' reg-name.

  drivers/staging/media/hantro/hantro.h       |  5 +-
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 ++++++++++++---------
  2 files changed, 34 insertions(+), 23 deletions(-)
drivers/staging/media/hantro/hantro.h +1 -0
index 6c1b888abe75..37b9ce04bd4e 100644
@@ -13,6 +13,7 @@
  #define HANTRO_H_
 
 
 
 
  #include <linux/platform_device.h>
+#include <linux/regmap.h>

 #include <linux/videodev2.h>
 #include <linux/wait.h>
 #include <linux/clk.h>

drivers/staging/media/hantro/hantro.h +2 -2
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
   * @reg_bases:		Mapped addresses of VPU registers.
   * @enc_base:		Mapped address of VPU encoder register for convenience.
   * @dec_base:		Mapped address of VPU decoder register for convenience.
- * @ctrl_base:		Mapped address of VPU control block.
+ * @ctrl_base:		Regmap of VPU control block.
   * @vpu_mutex:		Mutex to synchronize V4L2 calls.
   * @irqlock:		Spinlock to synchronize access to data structures
   *			shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
  	void __iomem **reg_bases;
  	void __iomem *enc_base;
  	void __iomem *dec_base;
-	void __iomem *ctrl_base;
+	struct regmap *ctrl_base;
 
 
 

  struct mutex vpu_mutex; /* video_device lock */
  spinlock_t irqlock;

drivers/staging/media/hantro/imx8m_vpu_hw.c +1 -0
index c222de075ef4..8d0c3425234b 100644
@@ -7,6 +7,7 @@
 
 
 
 
  #include <linux/clk.h>
  #include <linux/delay.h>
+#include <linux/mfd/syscon.h>

 #include "hantro.h"
 #include "hantro_jpeg.h"

drivers/staging/media/hantro/imx8m_vpu_hw.c +14 -16
@@ -24,30 +25,28 @@
  #define CTRL_G1_PP_FUSE		0x0c
  #define CTRL_G2_DEC_FUSE	0x10
 
 
 
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 0x14,
+};
+
  static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
  {
-	u32 val;
-
  	/* Assert */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val &= ~reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
 
 
 
  	udelay(2);
 
 
 
 
  	/* Release */
-	val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-	val |= reset_bits;
-	writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+	regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+			   reset_bits, reset_bits);
  }
 
 
 
 
  static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
  {
-	u32 val;
-
-	val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-	val |= clock_bits;
-	writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+	regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+			   clock_bits, clock_bits);
  }
 
 
 
 
  static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
  	imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
 
 
 
  	/* Set values of the fuse registers */
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-	writel(0xffffffff, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+	regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0xffffffff);
+	regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0xffffffff);

  clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);

drivers/staging/media/hantro/imx8m_vpu_hw.c +16 -2
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 
 
 
  static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
  {
-	vpu->dec_base = vpu->reg_bases[0];
-	vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+	struct device_node *np = vpu->dev->of_node;
+
+	vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, "nxp,imx8m-vpu-ctrl");
+	if (IS_ERR(vpu->ctrl_base)) {
+		struct resource *res;
+		void __iomem *ctrl;
+
+		res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, "ctrl");
+		ctrl = devm_ioremap_resource(vpu->dev, res);
+		if (IS_ERR(ctrl))
+			return PTR_ERR(ctrl);
+
+		vpu->ctrl_base = devm_regmap_init_mmio(vpu->dev, ctrl, &ctrl_regmap_ctrl);
+		if (IS_ERR(vpu->ctrl_base))
+			return PTR_ERR(vpu->ctrl_base);
+	}

  return 0;
 }

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -1
@@ -198,7 +211,6 @@ static const struct hantro_irq imx8mq_irqs[] = {
  };
 
 
 
 
  static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
-static const char * const imx8mq_reg_names[] = { "g1", "g2", "ctrl" };
Quoted 11 lines

drivers/staging/media/hantro/imx8m_vpu_hw.c const struct hantro_variant imx8mq_vpu_variant = { · line 230

Quoted 9 lines

 const struct hantro_variant imx8mq_vpu_variant = { .dec_fmts = imx8m_vpu_dec_fmts,

drivers/staging/media/hantro/imx8m_vpu_hw.c +0 -2
@@ -215,6 +227,4 @@ const struct hantro_variant imx8mq_vpu_variant = {
  	.num_irqs = ARRAY_SIZE(imx8mq_irqs),
  	.clk_names = imx8mq_clk_names,
  	.num_clocks = ARRAY_SIZE(imx8mq_clk_names),
-	.reg_names = imx8mq_reg_names,
-	.num_regs = ARRAY_SIZE(imx8mq_reg_names)
  };

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

#19 lore raw

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

Hi Benjamin,

Quoted 23 lines · Benjamin Gaignard

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Quoted 18 lines

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

Quoted 6 lines

In order to be able to share the control hardware block between VPUs use a syscon instead a ioremap it in the driver. To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl' phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the series.

We just discussed a way forward on how to handle the clocks and resets provided by the blkctl block on i.MX8MM and later and it seems there is a consensus on trying to provide virtual power domains from a blkctl driver, controlling clocks and resets for the devices in the power domain. I would like to avoid introducing yet another way of handling the blkctl and thus would like to align the i.MX8MQ VPU blkctl with what we are planning to do on the later chip generations.

Quoted 2 lines

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this virtual power domain thing a shot.

Quoted 7 lines

Hey guys,

I may I have miss them but I haven't see patches about power domain for IMX8MQ VPU control block ?
Is it something that you still plan to do ?
If not, I can resend my patches where I use syscon.

Please see "soc: imx: add i.MX BLK-CTL support" [1] sent by Peng a couple weeks ago. It adds the VPUMIX for i.MX8MM, so it seems the best way forward is to follow that design, extending it for i.MX8MQ.

That's still under discussion, but hopefully it will be sorted out for v5.15.

Speaking of i.MX8MM, I got a report that the Hantro G1 block mostly work, but needs to be restricted to 1920x1080. If you could add a new compatible and variant for that, maybe we can find someone to test it.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#mf73fe4a13aec0a8e633a14a5d9c2d5609799acb4

Kindly,
Ezequiel

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

author maintainer
#20 lore raw

PATCH v9 4/13 media: hevc: Add fields and flags for hevc PPS

In reply to Benjamin Gaignard

Add fields and flags as they are defined in 7.4.3.3.1 "General picture parameter set RBSP semantics of the H.265 ITU specification.

---
version 8:
- add Ezequiel review tag

 .../userspace-api/media/v4l/ext-ctrls-codec.rst    | 14 ++++++++++++++
 include/media/hevc-ctrls.h                         |  4 ++++
 2 files changed, 18 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +14 -0
index b0de4e6e7ebd..aabcb0e63a5e 100644
@@ -3000,6 +3000,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -
@@ -3110,6 +3116,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000
       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+      - 0x00080000
+      - Specifies the presence of deblocking filter control syntax elements in
+        the PPS
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      - Specifies that tile column boundaries and likewise tile row boundaries
+        are distributed uniformly across the picture
 
 .. raw:: latex
 
include/media/hevc-ctrls.h +4 -0
index b4cb2ef02f17..003f819ecb26 100644
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER	(1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT		(1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT	(1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING			(1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
 	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
 	__u8	num_extra_slice_header_bits;
+	__u8	num_ref_idx_l0_default_active_minus1;
+	__u8	num_ref_idx_l1_default_active_minus1;
 	__s8	init_qp_minus26;
 	__u8	diff_cu_qp_delta_depth;
 	__s8	pps_cb_qp_offset;
Signature · 1 line
2.25.1
author maintainer
#21 lore raw

PATCH v9 5/13 media: hevc: Add decode params control

In reply to Benjamin Gaignard

Add decode params control and the associated structure to group all the information that are needed to decode a reference frame as is described in ITU-T Rec. H.265 section "8.3.2 Decoding process for reference picture set".

Adapt Cedrus driver to these changes.

---
version 9:
- Corrections in commit message

version 8:
- add Ezequiel review tag

version 7:
- rebased on top of media_tree/master branch

version 6:
- fix compilation errors

 .../media/v4l/ext-ctrls-codec.rst             | 94 +++++++++++++++----
 .../media/v4l/vidioc-queryctrl.rst            |  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c          | 28 ++++--
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h                    | 29 ++++--
 8 files changed, 138 insertions(+), 40 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +76 -18
index aabcb0e63a5e..7b90cb939e9d 100644
@@ -3214,9 +3214,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
@@ -3224,22 +3221,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB.
     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come before
-        the current frame.
-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come after
-        the current frame.
-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.
-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
-    * - struct :c:type:`v4l2_hevc_dpb_entry`
-      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-      - The decoded picture buffer, for meta-data about reference frames.
     * - struct :c:type:`v4l2_hevc_pred_weight_table`
       - ``pred_weight_table``
       - The prediction weight coefficients for inter-picture prediction.
@@ -3492,3 +3475,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     encoding the next frame queued after setting this control.
     This provides a bitmask which consists of bits [0, LTR_COUNT-1].
     This is applicable to the H264 and HEVC encoders.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture order
+    count (POC) for all the lists (short, long, before, current, after) and the
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      - PicOrderCntVal as described in section 8.3.1 "Decoding process
+        for picture order count" of the specification.
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.
+    * - __u8
+      - ``num_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come before
+        the current frame.
+    * - __u8
+      - ``num_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come after
+        the current frame.
+    * - __u8
+      - ``num_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - PocStCurrBefore as described in section 8.3.2 "Decoding process for reference
+        picture set.
+    * - __u8
+      - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - PocStCurrAfter as described in section 8.3.2 "Decoding process for reference
+        picture set.
+    * - __u8
+      - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+        picture set.
+    * - __u64
+      - ``flags``
+      - See :ref:`Decode Parameters Flags <hevc_decode_params_flags>`
+
+.. _hevc_decode_params_flags:
+
+``Decode Parameters Flags``
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC``
+      - 0x00000001
+      -
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC``
+      - 0x00000002
+      -
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR``
+      - 0x00000004
+      -
Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +6 -0
index 8a285daedc6a..cf8f94693c39 100644
@@ -495,6 +495,12 @@ See also the examples in :ref:`control`.
       - n/a
       - A struct :c:type:`v4l2_ctrl_vp8_frame`, containing VP8
 	frame parameters for stateless video decoders.
+    * - ``V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS``
+      - n/a
+      - n/a
+      - n/a
+      - A struct :c:type:`v4l2_ctrl_hevc_decode_params`, containing HEVC
+	decoding parameters for stateless video decoders.
 
 .. raw:: latex
 
drivers/media/v4l2-core/v4l2-ctrls.c +20 -8
index c7bcc5c25771..9c918766e2c8 100644
@@ -1041,6 +1041,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_MPEG_VIDEO_HEVC_SPS:			return "HEVC Sequence Parameter Set";
 	case V4L2_CID_MPEG_VIDEO_HEVC_PPS:			return "HEVC Picture Parameter Set";
 	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:		return "HEVC Slice Parameters";
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS:		return "HEVC Decode Parameters";
 	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:		return "HEVC Decode Mode";
 	case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:		return "HEVC Start Code";
 
@@ -1526,6 +1527,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:
 		*type = V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS;
 		break;
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS:
+		*type = V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS;
+		break;
 	case V4L2_CID_UNIT_CELL_SIZE:
 		*type = V4L2_CTRL_TYPE_AREA;
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
@@ -1895,6 +1899,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 	struct v4l2_ctrl_hevc_pps *p_hevc_pps;
 	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
+	struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
 	struct v4l2_area *area;
 	void *p = ptr.p + idx * ctrl->elem_size;
 	unsigned int i;
@@ -2170,24 +2175,21 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 		zero_padding(*p_hevc_pps);
 		break;
 
-	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
-		p_hevc_slice_params = p;
+	case V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS:
+		p_hevc_decode_params = p;
 
-		if (p_hevc_slice_params->num_active_dpb_entries >
+		if (p_hevc_decode_params->num_active_dpb_entries >
 		    V4L2_HEVC_DPB_ENTRIES_NUM_MAX)
 			return -EINVAL;
 
-		zero_padding(p_hevc_slice_params->pred_weight_table);
-
-		for (i = 0; i < p_hevc_slice_params->num_active_dpb_entries;
+		for (i = 0; i < p_hevc_decode_params->num_active_dpb_entries;
 		     i++) {
 			struct v4l2_hevc_dpb_entry *dpb_entry =
-				&p_hevc_slice_params->dpb[i];
+				&p_hevc_decode_params->dpb[i];
 
 			zero_padding(*dpb_entry);
 		}
 
-		zero_padding(*p_hevc_slice_params);
 		break;
 
 	case V4L2_CTRL_TYPE_HDR10_CLL_INFO:
@@ -2237,6 +2239,13 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 
 		break;
 
+	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
+		p_hevc_slice_params = p;
+
+		zero_padding(p_hevc_slice_params->pred_weight_table);
+		zero_padding(*p_hevc_slice_params);
+		break;
+
 	case V4L2_CTRL_TYPE_AREA:
 		area = p;
 		if (!area->width || !area->height)
@@ -2938,6 +2947,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
 		elem_size = sizeof(struct v4l2_ctrl_hevc_slice_params);
 		break;
+	case V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS:
+		elem_size = sizeof(struct v4l2_ctrl_hevc_decode_params);
+		break;
 	case V4L2_CTRL_TYPE_HDR10_CLL_INFO:
 		elem_size = sizeof(struct v4l2_ctrl_hdr10_cll_info);
 		break;
drivers/staging/media/sunxi/cedrus/cedrus.c +6 -0
index 92812d1a39d4..6f095ae53818 100644
@@ -151,6 +151,12 @@ static const struct cedrus_control cedrus_controls[] = {
 		},
 		.codec		= CEDRUS_CODEC_VP8,
 	},
+	{
+		.cfg = {
+			.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+		},
+		.codec		= CEDRUS_CODEC_H265,
+	},
 };
 
 #define CEDRUS_CONTROLS_COUNT	ARRAY_SIZE(cedrus_controls)
drivers/staging/media/sunxi/cedrus/cedrus.h +1 -0
index 15f147dad4cb..930922bd4e46 100644
@@ -76,6 +76,7 @@ struct cedrus_h265_run {
 	const struct v4l2_ctrl_hevc_sps			*sps;
 	const struct v4l2_ctrl_hevc_pps			*pps;
 	const struct v4l2_ctrl_hevc_slice_params	*slice_params;
+	const struct v4l2_ctrl_hevc_decode_params	*decode_params;
 };
 
 struct cedrus_vp8_run {
drivers/staging/media/sunxi/cedrus/cedrus_dec.c +2 -0
index d696b3ec70c0..8a7e44f92812 100644
@@ -68,6 +68,8 @@ void cedrus_device_run(void *priv)
 			V4L2_CID_MPEG_VIDEO_HEVC_PPS);
 		run.h265.slice_params = cedrus_find_control_data(ctx,
 			V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS);
+		run.h265.decode_params = cedrus_find_control_data(ctx,
+			V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS);
 		break;
 
 	case V4L2_PIX_FMT_VP8_FRAME:
drivers/staging/media/sunxi/cedrus/cedrus_h265.c +7 -5
index ce497d0197df..397a4ba5df4c 100644
@@ -245,6 +245,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	const struct v4l2_ctrl_hevc_sps *sps;
 	const struct v4l2_ctrl_hevc_pps *pps;
 	const struct v4l2_ctrl_hevc_slice_params *slice_params;
+	const struct v4l2_ctrl_hevc_decode_params *decode_params;
 	const struct v4l2_hevc_pred_weight_table *pred_weight_table;
 	dma_addr_t src_buf_addr;
 	dma_addr_t src_buf_end_addr;
@@ -256,6 +257,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	sps = run->h265.sps;
 	pps = run->h265.pps;
 	slice_params = run->h265.slice_params;
+	decode_params = run->h265.decode_params;
 	pred_weight_table = &slice_params->pred_weight_table;
 
 	/* MV column buffer size and allocation. */
@@ -487,7 +489,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 
 	reg = VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_TC_OFFSET_DIV2(slice_params->slice_tc_offset_div2) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_BETA_OFFSET_DIV2(slice_params->slice_beta_offset_div2) |
-	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_POC_BIGEST_IN_RPS_ST(slice_params->num_rps_poc_st_curr_after == 0) |
+	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_POC_BIGEST_IN_RPS_ST(decode_params->num_poc_st_curr_after == 0) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_CR_QP_OFFSET(slice_params->slice_cr_qp_offset) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_CB_QP_OFFSET(slice_params->slice_cb_qp_offset) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_QP_DELTA(slice_params->slice_qp_delta);
@@ -527,8 +529,8 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	cedrus_write(dev, VE_DEC_H265_NEIGHBOR_INFO_ADDR, reg);
 
 	/* Write decoded picture buffer in pic list. */
-	cedrus_h265_frame_info_write_dpb(ctx, slice_params->dpb,
-					 slice_params->num_active_dpb_entries);
+	cedrus_h265_frame_info_write_dpb(ctx, decode_params->dpb,
+					 decode_params->num_active_dpb_entries);
 
 	/* Output frame. */
 
@@ -545,7 +547,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 
 	/* Reference picture list 0 (for P/B frames). */
 	if (slice_params->slice_type != V4L2_HEVC_SLICE_TYPE_I) {
-		cedrus_h265_ref_pic_list_write(dev, slice_params->dpb,
+		cedrus_h265_ref_pic_list_write(dev, decode_params->dpb,
 					       slice_params->ref_idx_l0,
 					       slice_params->num_ref_idx_l0_active_minus1 + 1,
 					       VE_DEC_H265_SRAM_OFFSET_REF_PIC_LIST0);
@@ -564,7 +566,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 
 	/* Reference picture list 1 (for B frames). */
 	if (slice_params->slice_type == V4L2_HEVC_SLICE_TYPE_B) {
-		cedrus_h265_ref_pic_list_write(dev, slice_params->dpb,
+		cedrus_h265_ref_pic_list_write(dev, decode_params->dpb,
 					       slice_params->ref_idx_l1,
 					       slice_params->num_ref_idx_l1_active_minus1 + 1,
 					       VE_DEC_H265_SRAM_OFFSET_REF_PIC_LIST1);
include/media/hevc-ctrls.h +20 -9
index 003f819ecb26..8e0109eea454 100644
@@ -19,6 +19,7 @@
 #define V4L2_CID_MPEG_VIDEO_HEVC_SPS		(V4L2_CID_CODEC_BASE + 1008)
 #define V4L2_CID_MPEG_VIDEO_HEVC_PPS		(V4L2_CID_CODEC_BASE + 1009)
 #define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS	(V4L2_CID_CODEC_BASE + 1010)
+#define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS	(V4L2_CID_CODEC_BASE + 1012)
 #define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE	(V4L2_CID_CODEC_BASE + 1015)
 #define V4L2_CID_MPEG_VIDEO_HEVC_START_CODE	(V4L2_CID_CODEC_BASE + 1016)
 
@@ -26,6 +27,7 @@
 #define V4L2_CTRL_TYPE_HEVC_SPS 0x0120
 #define V4L2_CTRL_TYPE_HEVC_PPS 0x0121
 #define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122
+#define V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS 0x0124
 
 enum v4l2_mpeg_video_hevc_decode_mode {
 	V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED,
@@ -194,18 +196,10 @@ struct v4l2_ctrl_hevc_slice_params {
 	__u8	pic_struct;
 
 	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
-	__u8	num_active_dpb_entries;
 	__u8	ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
 	__u8	ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
 
-	__u8	num_rps_poc_st_curr_before;
-	__u8	num_rps_poc_st_curr_after;
-	__u8	num_rps_poc_lt_curr;
-
-	__u8	padding;
-
-	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
-	struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u8	padding[5];
 
 	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
 	struct v4l2_hevc_pred_weight_table pred_weight_table;
@@ -213,4 +207,21 @@ struct v4l2_ctrl_hevc_slice_params {
 	__u64	flags;
 };
 
+#define V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC		0x1
+#define V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC		0x2
+#define V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR  0x4
+
+struct v4l2_ctrl_hevc_decode_params {
+	__s32	pic_order_cnt_val;
+	__u8	num_active_dpb_entries;
+	struct	v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u8	num_poc_st_curr_before;
+	__u8	num_poc_st_curr_after;
+	__u8	num_poc_lt_curr;
+	__u8	poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u8	poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u8	poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u64	flags;
+};
+
 #endif
Signature · 1 line
2.25.1
author maintainer
#22 lore raw

PATCH v9 6/13 media: hantro: change hantro_codec_ops run prototype to return errors

In reply to Benjamin Gaignard

Change hantro_codec_ops run prototype from 'void' to 'int'.
This allows the driver to cancel the job if an error occurs while configuring the hardware.

---
version 9:
- Corrections in commit message

version 8:
- add Ezequiel review tag

version 5:
- forward hantro_h264_dec_prepare_run() return value in case of error

 drivers/staging/media/hantro/hantro_drv.c     |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++++++---
 .../media/hantro/hantro_g1_mpeg2_dec.c        |  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 ++++--
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h      | 19 ++++++++++---------
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c     |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c    |  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c      |  6 ++++--
 9 files changed, 40 insertions(+), 21 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +3 -1
index 595e82a82728..02c5c2f1a88b 100644
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-	ctx->codec_ops->run(ctx);
+	if (ctx->codec_ops->run(ctx))
+		goto err_cancel_job;
+
 	return;
 
 err_cancel_job:
drivers/staging/media/hantro/hantro_g1_h264_dec.c +7 -3
index 845bef73d218..5c792b7bcb79 100644
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
 	vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
+	int ret;
 
 	/* Prepare the H264 decoder context. */
-	if (hantro_h264_dec_prepare_run(ctx))
-		return;
+	ret = hantro_h264_dec_prepare_run(ctx);
+	if (ret)
+		return ret;
 
 	/* Configure hardware registers. */
 	set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 			   G1_REG_CONFIG_DEC_CLK_GATE_E,
 			   G1_REG_CONFIG);
 	vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+	return 0;
 }
drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c +3 -1
index 6386a3989bfe..5e8943d31dc5 100644
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, struct hantro_ctx *ctx,
 	vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
 	reg = G1_REG_DEC_E(1);
 	vdpu_write(vpu, reg, G1_SWREG(1));
+
+	return 0;
 }
drivers/staging/media/hantro/hantro_g1_vp8_dec.c +4 -2
index 57002ba70176..96622a7f8279 100644
@@ -425,7 +425,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
 	vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
 	const struct v4l2_ctrl_vp8_frame *hdr;
 	struct hantro_dev *vpu = ctx->dev;
@@ -438,7 +438,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
 	hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
 	if (WARN_ON(!hdr))
-		return;
+		return -EINVAL;
 
 	/* Reset segment_map buffer in keyframe */
 	if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -498,4 +498,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 	hantro_end_prepare_run(ctx);
 
 	vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+	return 0;
 }
drivers/staging/media/hantro/hantro_h1_jpeg_enc.c +3 -1
index b88dc4ed06db..56cf261a8e95 100644
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
 	}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -136,6 +136,8 @@ void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 	hantro_end_prepare_run(ctx);
 
 	vepu_write(vpu, reg, H1_REG_ENC_CTRL);
+
+	return 0;
 }
 
 void hantro_jpeg_enc_done(struct hantro_ctx *ctx)
drivers/staging/media/hantro/hantro_hw.h +10 -9
index 83b3e42b63a3..6a34ddfa34b7 100644
@@ -133,14 +133,15 @@ struct hantro_postproc_ctx {
  *		Optional and called from process context.
  * @run:	Start single {en,de)coding job. Called from atomic context
  *		to indicate that a pair of buffers is ready and the hardware
- *		should be programmed and started.
+ *		should be programmed and started. Returns zero if OK, a
+ *		negative value in error cases.
  * @done:	Read back processing results and additional data from hardware.
  * @reset:	Reset the hardware in case of a timeout.
  */
 struct hantro_codec_ops {
 	int (*init)(struct hantro_ctx *ctx);
 	void (*exit)(struct hantro_ctx *ctx);
-	void (*run)(struct hantro_ctx *ctx);
+	int (*run)(struct hantro_ctx *ctx);
 	void (*done)(struct hantro_ctx *ctx);
 	void (*reset)(struct hantro_ctx *ctx);
 };
@@ -176,8 +177,8 @@ void hantro_irq_done(struct hantro_dev *vpu,
 void hantro_start_prepare_run(struct hantro_ctx *ctx);
 void hantro_end_prepare_run(struct hantro_ctx *ctx);
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
-void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx);
+int rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx);
 int hantro_jpeg_enc_init(struct hantro_ctx *ctx);
 void hantro_jpeg_enc_exit(struct hantro_ctx *ctx);
 void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
@@ -185,7 +186,7 @@ void hantro_jpeg_enc_done(struct hantro_ctx *ctx);
 dma_addr_t hantro_h264_get_ref_buf(struct hantro_ctx *ctx,
 				   unsigned int dpb_idx);
 int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx);
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx);
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx);
 int hantro_h264_dec_init(struct hantro_ctx *ctx);
 void hantro_h264_dec_exit(struct hantro_ctx *ctx);
 
@@ -216,15 +217,15 @@ hantro_h264_mv_size(unsigned int width, unsigned int height)
 	return 64 * MB_WIDTH(width) * MB_WIDTH(height) + 32;
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
-void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx);
+int rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx);
 void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
 	const struct v4l2_ctrl_mpeg2_quantization *ctrl);
 int hantro_mpeg2_dec_init(struct hantro_ctx *ctx);
 void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx);
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
-void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx);
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx);
+int rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx);
 int hantro_vp8_dec_init(struct hantro_ctx *ctx);
 void hantro_vp8_dec_exit(struct hantro_ctx *ctx);
 void hantro_vp8_prob_update(struct hantro_ctx *ctx,
drivers/staging/media/hantro/rk3399_vpu_hw_jpeg_enc.c +3 -1
index 3498e6124acd..3a27ebef4f38 100644
@@ -118,7 +118,7 @@ rk3399_vpu_jpeg_enc_set_qtable(struct hantro_dev *vpu,
 	}
 }
 
-void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx)
+int rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -168,4 +168,6 @@ void rk3399_vpu_jpeg_enc_run(struct hantro_ctx *ctx)
 	/* Kick the watchdog and start encoding */
 	hantro_end_prepare_run(ctx);
 	vepu_write(vpu, reg, VEPU_REG_ENCODE_START);
+
+	return 0;
 }
drivers/staging/media/hantro/rk3399_vpu_hw_mpeg2_dec.c +3 -1
index f610fa5b4335..4bd3080abbc1 100644
@@ -157,7 +157,7 @@ rk3399_vpu_mpeg2_dec_set_buffers(struct hantro_dev *vpu,
 	vdpu_write_relaxed(vpu, backward_addr, VDPU_REG_REFER3_BASE);
 }
 
-void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx)
+int rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
 	struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -254,4 +254,6 @@ void rk3399_vpu_mpeg2_dec_run(struct hantro_ctx *ctx)
 
 	reg = vdpu_read(vpu, VDPU_SWREG(57)) | VDPU_REG_DEC_E(1);
 	vdpu_write(vpu, reg, VDPU_SWREG(57));
+
+	return 0;
 }
drivers/staging/media/hantro/rk3399_vpu_hw_vp8_dec.c +4 -2
index 8661a3cc1e6b..e5d20fe5b007 100644
@@ -503,7 +503,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
 	vdpu_write_relaxed(vpu, dst_dma, VDPU_REG_ADDR_DST);
 }
 
-void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx)
+int rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx)
 {
 	const struct v4l2_ctrl_vp8_frame *hdr;
 	struct hantro_dev *vpu = ctx->dev;
@@ -516,7 +516,7 @@ void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx)
 
 	hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
 	if (WARN_ON(!hdr))
-		return;
+		return -EINVAL;
 
 	/* Reset segment_map buffer in keyframe */
 	if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -589,4 +589,6 @@ void rk3399_vpu_vp8_dec_run(struct hantro_ctx *ctx)
 	hantro_end_prepare_run(ctx);
 
 	hantro_reg_write(vpu, &vp8_dec_start_dec, 1);
+
+	return 0;
 }
Signature · 1 line
2.25.1
author maintainer
#23 lore raw

PATCH v9 7/13 media: hantro: Define HEVC codec profiles and supported features

In reply to Benjamin Gaignard

Define which HEVC profiles (up to level 5.1) and features (no scaling, no 10 bits) are supported by the driver.

---
version 8:
- add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h     |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++++++++++++++++++++++
 2 files changed, 61 insertions(+)
drivers/staging/media/hantro/hantro.h +3 -0
index 37b9ce04bd4e..edb4561a6887 100644
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER	BIT(16)
 #define HANTRO_VP8_DECODER	BIT(17)
 #define HANTRO_H264_DECODER	BIT(18)
+#define HANTRO_HEVC_DECODER	BIT(19)
 #define HANTRO_DECODERS		0xffff0000
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
 	HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
 	HANTRO_MODE_H264_DEC,
 	HANTRO_MODE_MPEG2_DEC,
 	HANTRO_MODE_VP8_DEC,
+	HANTRO_MODE_HEVC_DEC,
 };
 
 /*
drivers/staging/media/hantro/hantro_drv.c +58 -0

70 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#24 lore raw

PATCH v9 8/13 media: hantro: Only use postproc when post processed formats are defined

In reply to Benjamin Gaignard

If the variant doesn't support postprocessed formats make sure it will be ok.

---
version 9:
- Corrections in commit message

version 8:
- add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h          |  8 ++------
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++++++++++++++
 drivers/staging/media/hantro/hantro_v4l2.c     |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/staging/media/hantro/hantro.h +2 -6
index edb4561a6887..7a5ad93466c8 100644
@@ -414,12 +414,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
 	return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
-		      const struct hantro_fmt *fmt)
-{
-	return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+			   const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
drivers/staging/media/hantro/hantro_postproc.c +14 -0
index 6d2a8f2a8f0b..ed8916c950a4 100644
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
 	.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+			   const struct hantro_fmt *fmt)
+{
+	struct hantro_dev *vpu = ctx->dev;
+
+	if (ctx->is_encoder)
+		return false;
+
+	if (!vpu->variant->postproc_fmts)
+		return false;
+
+	return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
drivers/staging/media/hantro/hantro_v4l2.c +3 -1
index 1bc118e375a1..77d7fe62ce81 100644
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
 			    unsigned int *num_fmts)
 {
-	if (ctx->is_encoder) {
+	struct hantro_dev *vpu = ctx->dev;
+
+	if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
 		*num_fmts = 0;
 		return NULL;
 	}
Signature · 1 line
2.25.1
author maintainer
#25 lore raw

PATCH v9 9/13 media: uapi: Add a control for HANTRO driver

In reply to Benjamin Gaignard

The HEVC HANTRO driver needs to know the number of bits to skip at the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control for this purpose.

---
version 9:
- Corrections in commit message.
- Move control definition in hevc-ctrls.h
- Add note in documentation to explain that this control may change in the futur

version 5:
- Be even more verbose in control documentation.
- Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst    | 19 +++++++++++++++++++
 .../userspace-api/media/drivers/index.rst     |  1 +
 include/media/hevc-ctrls.h                    | 13 +++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst
Documentation/userspace-api/media/drivers/hantro.rst new file +19 -0
new file mode 100644
index 000000000000..cd9754b4e005
@@ -0,0 +1,19 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===========================
+
+The Hantro video decoder driver implements the following driver-specific controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+    Specifies to Hantro HEVC video decoder driver the number of data (in bits) to
+    skip in the slice segment header.
+    If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+    to before syntax element "slice_temporal_mvp_enabled_flag".
+    If IDR, the skipped bits are just "pic_output_flag"
+    (separate_colour_plane_flag is not supported).
+
+.. note::
+
+        This control is not yet part of the public kernel API and
+        it is expected to change.
Documentation/userspace-api/media/drivers/index.rst +1 -0
index 1a9038f5f9fa..12e3c512d718 100644
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source distribution of Linux.
 
 	ccs
 	cx2341x-uapi
+        hantro
 	imx-uapi
 	max2175
 	meye-uapi
include/media/hevc-ctrls.h +13 -0
index 8e0109eea454..b713eeed1915 100644
@@ -224,4 +224,17 @@ struct v4l2_ctrl_hevc_decode_params {
 	__u64	flags;
 };
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE				(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP	(V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 #endif
Signature · 1 line
2.25.1
author maintainer
#26 lore raw

PATCH v9 10/13 media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

In reply to Benjamin Gaignard

Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handled by the driver.

---
version 9:
- Corrections in commit message

version 8:
- Add Ezequiel review tag

 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/media/hantro/hantro_v4l2.c +1 -0
index 77d7fe62ce81..0655324fd0d4 100644
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 fourcc)
 	case V4L2_PIX_FMT_MPEG2_SLICE:
 	case V4L2_PIX_FMT_VP8_FRAME:
 	case V4L2_PIX_FMT_H264_SLICE:
+	case V4L2_PIX_FMT_HEVC_SLICE:
 		ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
 		break;
 	default:
Signature · 1 line
2.25.1
author maintainer
#27 lore raw

PATCH v9 11/13 media: hantro: Introduce G2/HEVC decoder

In reply to Benjamin Gaignard

Implement all the logic to get G2 hardware decoding HEVC frames. It supports up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or the scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning of the slice header. That is very specific to this hardware so can't go into uapi structures. Computing the needed value is complex and requires information from the stream that only the userland knows so let it provide the correct value to the driver.

---
version 9:
- Corrections in commit message
- Change V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP control's max value

version 8:
- Fix compilation warnings

version 7:
- Improve motion vectors requested memory size computation.

 drivers/staging/media/hantro/Makefile         |   2 +
 drivers/staging/media/hantro/hantro.h         |   2 +
 drivers/staging/media/hantro/hantro_drv.c     |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++
 drivers/staging/media/hantro/hantro_hevc.c    | 327 ++++++++++
 drivers/staging/media/hantro/hantro_hw.h      |  49 ++
 7 files changed, 1201 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c
drivers/staging/media/hantro/Makefile +2 -0
index 743ce08eb184..0357f1772267 100644
@@ -9,12 +9,14 @@ hantro-vpu-y += \
 		hantro_h1_jpeg_enc.o \
 		hantro_g1_h264_dec.o \
 		hantro_g1_mpeg2_dec.o \
+		hantro_g2_hevc_dec.o \
 		hantro_g1_vp8_dec.o \
 		rk3399_vpu_hw_jpeg_enc.o \
 		rk3399_vpu_hw_mpeg2_dec.o \
 		rk3399_vpu_hw_vp8_dec.o \
 		hantro_jpeg.o \
 		hantro_h264.o \
+		hantro_hevc.o \
 		hantro_mpeg2.o \
 		hantro_vp8.o
 
drivers/staging/media/hantro/hantro.h +2 -0
index 7a5ad93466c8..6a21d1e95b34 100644
@@ -222,6 +222,7 @@ struct hantro_dev {
  * @jpeg_enc:		JPEG-encoding context.
  * @mpeg2_dec:		MPEG-2-decoding context.
  * @vp8_dec:		VP8-decoding context.
+ * @hevc_dec:		HEVC-decoding context.
  */
 struct hantro_ctx {
 	struct hantro_dev *dev;
@@ -248,6 +249,7 @@ struct hantro_ctx {
 		struct hantro_jpeg_enc_hw_ctx jpeg_enc;
 		struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
 		struct hantro_vp8_dec_hw_ctx vp8_dec;
+		struct hantro_hevc_dec_hw_ctx hevc_dec;
 	};
 };
 
drivers/staging/media/hantro/hantro_drv.c +36 -0
index d9a3a5ef9330..905a69758b37 100644
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
 	return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct hantro_ctx *ctx;
+
+	ctx = container_of(ctrl->handler,
+			   struct hantro_ctx, ctrl_handler);
+
+	vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+	switch (ctrl->id) {
+	case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+		ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
 	.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
 	.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+	.s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
 	{
 		.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
 		.cfg = {
 			.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
 		},
+	}, {
+		.codec = HANTRO_HEVC_DECODER,
+		.cfg = {
+			.id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+			.name = "Hantro HEVC slice header skip bytes",
+			.type = V4L2_CTRL_TYPE_INTEGER,
+			.min = 0,
+			.def = 0,
+			.max = 0x100,
+			.step = 1,
+			.ops = &hantro_hevc_ctrl_ops,
+		},
 	},
 };
 
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +587 -0

587 lines not on this page · raw message

drivers/staging/media/hantro/hantro_g2_regs.h new file +198 -0

198 lines not on this page · raw message

drivers/staging/media/hantro/hantro_hevc.c new file +327 -0

327 lines not on this page · raw message

drivers/staging/media/hantro/hantro_hw.h +49 -0

67 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#28 lore raw

PATCH v9 12/13 media: hantro: IMX8M: add variant for G2/HEVC codec

In reply to Benjamin Gaignard

Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160. G2 doesn't have a postprocessor, uses the same clocks and has it own interrupt.

---
version 9:
- Corrections in commit message

version 8:
- Add Ezequiel Reviewed-by tag.

version 7:
- Add Philipp Reviewed-by tag.

version 5:
- remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h    |  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 ++++++++++++++++++++-
 3 files changed, 76 insertions(+), 2 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +1 -0
index 905a69758b37..d6f4958f6292 100644
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
 	{ .compatible = "nxp,imx8mq-vpu", .data = &imx8mq_vpu_variant, },
+	{ .compatible = "nxp,imx8mq-vpu-g2", .data = &imx8mq_vpu_g2_variant },
 #endif
 	{ /* sentinel */ }
 };
drivers/staging/media/hantro/hantro_hw.h +1 -0
index 41f3d5b92357..682fea1fe914 100644
@@ -205,6 +205,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
drivers/staging/media/hantro/imx8m_vpu_hw.c +74 -2

117 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#29 lore raw

PATCH v9 13/13 arm64: dts: imx8mq: Add node to G2 hardware

In reply to Benjamin Gaignard

Split the VPU node in two: one for G1 and one for G2 since they are different hardware blocks.
Add syscon for the hardware control block.
Remove the reg-names property that is useless.
Each VPU node only needs one interrupt.
Change G2 assigned clock to match the specification.
In both nodes all the clocks need to be assigned to make sure that the control block will be correctly clocked even if only one device node is enabled.

---
version 9:
- Corrections in commit message

version 7:
- use nxp,imx8m-vpu-ctrl as phandle syscon property name

version 5:
- use syscon instead of VPU reset

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++++++++++++++++++-----
 1 file changed, 34 insertions(+), 9 deletions(-)
arch/arm64/boot/dts/freescale/imx8mq.dtsi +34 -9
index 17c449e12c2e..65158414d255 100644
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
 			status = "disabled";
 		};
 
-		vpu: video-codec@38300000 {
+		vpu_ctrl: syscon@38320000 {
+			compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+			reg = <0x38320000 0x10000>;
+		};
+
+		vpu_g1: video-codec@38300000 {
 			compatible = "nxp,imx8mq-vpu";
-			reg = <0x38300000 0x10000>,
-			      <0x38310000 0x10000>,
-			      <0x38320000 0x10000>;
-			reg-names = "g1", "g2", "ctrl";
-			interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-				     <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-			interrupt-names = "g1", "g2";
+			reg = <0x38300000 0x10000>;
+			interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "g1";
 			clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
 				 <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
 				 <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@38300000 {
 						 <&clk IMX8MQ_VPU_PLL_OUT>,
 						 <&clk IMX8MQ_SYS1_PLL_800M>,
 						 <&clk IMX8MQ_VPU_PLL>;
-			assigned-clock-rates = <600000000>, <600000000>,
+			assigned-clock-rates = <600000000>, <300000000>,
+					       <800000000>, <0>;
+			power-domains = <&pgc_vpu>;
+			nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
+		};
+
+		vpu_g2: video-codec@38310000 {
+			compatible = "nxp,imx8mq-vpu-g2";
+			reg = <0x38310000 0x10000>;
+			interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "g2";
+			clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
+				 <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+				 <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+			clock-names = "g1", "g2",  "bus";
+			assigned-clocks = <&clk IMX8MQ_CLK_VPU_G1>,
+					  <&clk IMX8MQ_CLK_VPU_G2>,
+					  <&clk IMX8MQ_CLK_VPU_BUS>,
+					  <&clk IMX8MQ_VPU_PLL_BYPASS>;
+			assigned-clock-parents = <&clk IMX8MQ_VPU_PLL_OUT>,
+						 <&clk IMX8MQ_VPU_PLL_OUT>,
+						 <&clk IMX8MQ_SYS1_PLL_800M>,
+						 <&clk IMX8MQ_VPU_PLL>;
+			assigned-clock-rates = <600000000>, <300000000>,
 					       <800000000>, <0>;
 			power-domains = <&pgc_vpu>;
+			nxp,imx8m-vpu-ctrl = <&vpu_ctrl>;
 		};
 
 		pcie0: pcie@33800000 {
Signature · 1 line
2.25.1