Skip to contentSkip to conversation

drm/verisilicon : support DC8200 and inno hdmi

PATCH NAK keith zhao 8 participants 33 messages Nov 20, 2024 – Jun 17, 2025

Subsystems (12)
lore
Share & tools
lore

keith zhao

author
#0 lore raw

v5 cover drm/verisilicon : support DC8200 and inno hdmi

Verisilicon/DC8200 display controller IP has 2 display pipes and each pipe support a primary plane and a cursor plane .
In addition, there are 4 overlay planes as 2 display pipes common resources.

The first display pipe is bound to the inno HDMI encoder. The second display pipe is bound to Internal custom encoder, which is used to find dsi bridge by dts node.

This patchset should be applied on next branch.

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop vs_crtc_funcs&vs_plane_funcs, subdivide the plane's help interface.
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module

V3:
Changes since v3:
- Delete the custom plane property.
- Delete the custom fourcc modifiers.
- Adjust the calculation mode of hdmi pixclock.
- Add match data for dc8200 driver.
- Adjust some magic values.
- Add a simple encoder for dsi output.

V4:
Changes since v4:
- Delete the display subsystem module as all crtcs and planes are a driver.
- Delete the custom struct, directly use the drm struct data.
- Tidy up the inno hdmi public interface.
- Add a simple encoder for dsi output.

V5:
Changes since v5:
- Refine the Innosilicon HDMI by quoting bridge abstracting.
- Delete the encoder driver, which is created directly by internal functions.
- Adapt to the changes in kernel upgrade APIs, such as drm_client_setup.

keith zhao (9):
dt-bindings: display: bindings for starfive,JH7110 display pipeline
riscv: dts: Add display property
drm: bridge: inno-hdmi: add inno bridge driver.
drm/vs: Add Hardware Functions for VS DC8200
drm/vs: Add Base API for VS Mode Configuration
drm/vs: Add CRTC Functions
drm/vs: Add VS Plane API
drm/vs: Add Innosilicon HDMI Support
drm/vs: Add VS DRM Master Driver for JH7110 SoC

 .../display/bridge/innosilicon,inno-hdmi.yaml |   45 +
 .../display/rockchip/rockchip,inno-hdmi.yaml  |   27 +-
 .../starfive/starfive,jh7110-dc8200.yaml      |  176 +++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |   91 ++
 .../soc/starfive/starfive,jh7110-syscon.yaml  |    1 +
 MAINTAINERS                                   |   11 +
 .../boot/dts/starfive/jh7110-common.dtsi      |  125 ++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |   41 +
 drivers/gpu/drm/Kconfig                       |    2 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/bridge/Kconfig                |    2 +
 drivers/gpu/drm/bridge/Makefile               |    1 +
 drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
 drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
 .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
 .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
 drivers/gpu/drm/rockchip/Kconfig              |    1 +
 drivers/gpu/drm/rockchip/Makefile             |    2 +-
 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
 .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
 drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 ---------------
 drivers/gpu/drm/verisilicon/Kconfig           |   32 +
 drivers/gpu/drm/verisilicon/Makefile          |   10 +
 .../gpu/drm/verisilicon/inno_hdmi-starfive.c  |  553 +++++++++
 .../gpu/drm/verisilicon/inno_hdmi-starfive.h  |  194 +++
 drivers/gpu/drm/verisilicon/vs_crtc.c         |  241 ++++
 drivers/gpu/drm/verisilicon/vs_crtc.h         |   42 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c        | 1104 +++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_dc_hw.h        |  492 ++++++++
 drivers/gpu/drm/verisilicon/vs_drv.c          |  777 ++++++++++++
 drivers/gpu/drm/verisilicon/vs_drv.h          |   41 +
 drivers/gpu/drm/verisilicon/vs_modeset.c      |   31 +
 drivers/gpu/drm/verisilicon/vs_modeset.h      |   10 +
 drivers/gpu/drm/verisilicon/vs_plane.c        |  358 ++++++
 drivers/gpu/drm/verisilicon/vs_plane.h        |   27 +
 drivers/gpu/drm/verisilicon/vs_type.h         |   54 +
 include/drm/bridge/inno_hdmi.h                |   56 +
 37 files changed, 5630 insertions(+), 1051 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
 create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
 rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
 delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
 create mode 100644 include/drm/bridge/inno_hdmi.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/9 dt-bindings: display: bindings for starfive,JH7110 display pipeline

- Added bindings to support the display subsystem on the JH7110 SoC.

- Included the DC8200 display controller and Inno HDMI controller.

- Created innosilicon,inno-hdmi.yaml schema containing common properties for the Inno DesignWare HDMI TX controller.
This isn't a full device tree binding specification,
but is intended to be referenced by platform-specific bindings for the IP core.

---
 .../display/bridge/innosilicon,inno-hdmi.yaml |  45 +++++
 .../display/rockchip/rockchip,inno-hdmi.yaml  |  27 +--
 .../starfive/starfive,jh7110-dc8200.yaml      | 176 ++++++++++++++++++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  91 +++++++++
 .../soc/starfive/starfive,jh7110-syscon.yaml  |   1 +
 MAINTAINERS                                   |   8 +
 6 files changed, 323 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +45 -0
new file mode 100644
index 000000000000..f2543aebc312
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/bridge/innosilicon,inno-hdmi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Common Properties for Innosilicon HDMI TX IP
+
+maintainers:
+  - keith zhao <[email protected]>
+
+description: |
+  Innosilicon HDMI TX is an HDMI transmission device integrated into the zap SoC.
+  This document specifies the device tree properties for the INNO HDMI IP core.
+  It is intended to be referenced by platform-specific device tree bindings,
+  which will determine the necessity of each property.
+
+properties:
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description:
+          Port node with one endpoint connected to a display controller node.
+
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description:
+          Port node with one endpoint connected to a hdmi-connector node.
+
+    required:
+      - port@0
+      - port@1
+
+additionalProperties: true
+
+...
Documentation/devicetree/bindings/display/rockchip/rockchip,inno-hdmi.yaml +2 -25
index 5b87b0f1963e..589dedfcbee0 100644
@@ -16,12 +16,6 @@ properties:
       - rockchip,rk3036-inno-hdmi
       - rockchip,rk3128-inno-hdmi
 
-  reg:
-    maxItems: 1
-
-  interrupts:
-    maxItems: 1
-
   clocks:
     minItems: 1
     items:
@@ -40,24 +34,6 @@ properties:
   "#sound-dai-cells":
     const: 0
 
-  ports:
-    $ref: /schemas/graph.yaml#/properties/ports
-
-    properties:
-      port@0:
-        $ref: /schemas/graph.yaml#/properties/port
-        description:
-          Port node with one endpoint connected to a vop node.
-
-      port@1:
-        $ref: /schemas/graph.yaml#/properties/port
-        description:
-          Port node with one endpoint connected to a hdmi-connector node.
-
-    required:
-      - port@0
-      - port@1
-
 required:
   - compatible
   - reg
@@ -69,6 +45,7 @@ required:
   - ports
 
 allOf:
+  - $ref: ../bridge/innosilicon,inno-hdmi.yaml#
   - $ref: /schemas/sound/dai-common.yaml#
   - if:
       properties:
@@ -95,7 +72,7 @@ allOf:
       required:
         - power-domains
 
-additionalProperties: false
+unevaluatedProperties: false
 
 examples:
   - |
Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml new file +176 -0

176 lines not on this page · raw message

Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml new file +91 -0

91 lines not on this page · raw message

Documentation/devicetree/bindings/soc/starfive/starfive,jh7110-syscon.yaml +1 -0
index 0039319e91fe..cf9b657d0e8a 100644
@@ -24,6 +24,7 @@ properties:
           - enum:
               - starfive,jh7110-aon-syscon
               - starfive,jh7110-stg-syscon
+              - starfive,jh7110-vout-syscon
           - const: syscon
 
   reg:
MAINTAINERS +8 -0
index 84086d47db69..f787dd625497 100644
@@ -7432,6 +7432,14 @@ T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/ste,mcde.yaml
 F:	drivers/gpu/drm/mcde/
 
+DRM DRIVERS FOR STARFIVE
+M:	Keith Zhao <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
+F:	Documentation/devicetree/bindings/display/starfive/
+
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
 M:	Michael Trimarchi <[email protected]>
 S:	Maintained
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/9] dt-bindings: display: bindings for starfive,JH7110 display pipeline

Quoted 1 line · keith zhao

- Added bindings to support the display subsystem on the JH7110 SoC.

Please do not use "This commit/patch/change" (implied) and past tense, but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitting-patches.rst#L95

Quoted 9 lines

- Included the DC8200 display controller and Inno HDMI controller.

- Created innosilicon,inno-hdmi.yaml schema containing common properties for the Inno DesignWare HDMI TX controller.
This isn't a full device tree binding specification,
but is intended to be referenced by platform-specific bindings for the IP core.

Quoted 7 lines
---
 .../display/bridge/innosilicon,inno-hdmi.yaml |  45 +++++
 .../display/rockchip/rockchip,inno-hdmi.yaml  |  27 +--
 .../starfive/starfive,jh7110-dc8200.yaml      | 176 ++++++++++++++++++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  91 +++++++++
 .../soc/starfive/starfive,jh7110-syscon.yaml  |   1 +

I do not see how you addressed my feedback. I asked you to split the patch. Where is the split?

Your answer to my request to split was "Background is ...", yeah, so what? You are not going to split?

Quoted 14 lines
 MAINTAINERS                                   |   8 +
 6 files changed, 323 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml
 create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +2 -0
new file mode 100644
index 000000000000..f2543aebc312
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2

Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml line 12

Quoted 10 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +10 -0
+---
+$id: http://devicetree.org/schemas/display/bridge/innosilicon,inno-hdmi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Common Properties for Innosilicon HDMI TX IP
+
+maintainers:
+  - keith zhao <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml line 13

Quoted 1 line
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +1 -0
+  Innosilicon HDMI TX is an HDMI transmission device integrated into the zap SoC.

Keep and extend.

Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml line 14

Quoted 1 line
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +1 -0
+  This document specifies the device tree properties for the INNO HDMI IP core.

Keep... but what is INNO HDMI IP core? Another name? Different block?

Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml line 16

Quoted 2 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +2 -0
+  It is intended to be referenced by platform-specific device tree bindings,
+  which will determine the necessity of each property.

Not much improved here. Last two sentences are almost useless. Again - document the hardware. Drop this sentence.

I already complained about this. I already complained that you keep ignoring my comments and this does not improve much.

Since you did not implement my main feedback I am going to NAK the rest except one more thing:

...

Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml line 20

Quoted 4 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml new file +4 -0
+
+properties:
+  compatible:
+    const: "starfive,jh7110-inno-hdmi"

I could not be more specific in my previous feedback. Improvements? No. Stop wasting our time.

NAK.

Best regards,
Krzysztof

author
#3 lore raw

RE: [PATCH v5 1/9] dt-bindings: display: bindings for starfive,JH7110 display pipeline

Quoted 46 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: 2024年11月21日 16:23
To: Keith Zhao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; William Qiu <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Changhuang Liang <[email protected]>; Jack Zhu <[email protected]>; [email protected]
Subject: Re: [PATCH v5 1/9] dt-bindings: display: bindings for starfive,JH7110 display pipeline

Quoted 1 line · keith zhao

- Added bindings to support the display subsystem on the JH7110 SoC.

Please do not use "This commit/patch/change" (implied) and past tense, but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v5.17.1/source/Documentation/process/submitti
ng-patches.rst#L95

Quoted 9 lines

- Included the DC8200 display controller and Inno HDMI controller.

- Created innosilicon,inno-hdmi.yaml schema containing common properties for the Inno DesignWare HDMI TX controller.
This isn't a full device tree binding specification,
but is intended to be referenced by platform-specific bindings for the IP core.

Quoted 7 lines
---
 .../display/bridge/innosilicon,inno-hdmi.yaml |  45 +++++
.../display/rockchip/rockchip,inno-hdmi.yaml  |  27 +--
 .../starfive/starfive,jh7110-dc8200.yaml      | 176 ++++++++++++++++++
 .../starfive/starfive,jh7110-inno-hdmi.yaml   |  91 +++++++++
 .../soc/starfive/starfive,jh7110-syscon.yaml  |   1 +
Quoted 2 lines

I do not see how you addressed my feedback. I asked you to split the patch. Where is the split?

Oh sorry, I had a bit of a misunderstanding here before.
"Your patch is difficult to review. Split changing existing bindings (and defining common part) to a separate patch."
......
Split changing existing bindings (and defining common part) to a separate "bindings".
.......

Quoted 4 lines

Your answer to my request to split was "Background is ...", yeah, so what? You are not going to split?

Based on the misunderstanding of this idea, it led to not splitting the patch this time. Now I understand. Will split it .

Quoted 29 lines
Quoted 29 lines
 MAINTAINERS                                   |   8 +
 6 files changed, 323 insertions(+), 25 deletions(-)  create mode

100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi .yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8 200.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inn o-hdmi.yaml

diff --git a/Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hd mi.yaml b/Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hd mi.yaml
new file mode 100644
index 000000000000..f2543aebc312

Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +8 -0
+++ o-hdmi.yaml
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) %YAML 1.2
+---
+$id:
+http://devicetree.org/schemas/display/bridge/innosilicon,inno-hdmi.ya
+ml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
Quoted 9 lines

Documentation/devicetree/bindings/display/bridge/innosilicon,inn line 13

Quoted 6 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +6 -0
+title: Common Properties for Innosilicon HDMI TX IP
+
+maintainers:
+  - keith zhao <[email protected]>
+
+description: |

Do not need '|' unless you need to preserve formatting.

I will remove the '|' since it's not necessary for preserving formatting. And here is the reason why add '|' before.
https://elixir.bootlin.com/linux/v6.12/source/Documentation/devicetree/bindings/display/bridge/synopsys,dw-hdmi.yaml#L12

Quoted 6 lines

Documentation/devicetree/bindings/display/bridge/innosilicon,inn line 14

Quoted 3 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +1 -0
+  Innosilicon HDMI TX is an HDMI transmission device integrated into the

zap SoC.

Keep and extend.

Ok

Quoted 10 lines

Documentation/devicetree/bindings/display/bridge/innosilicon,inn line 15

Quoted 2 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +1 -0
+  This document specifies the device tree properties for the INNO HDMI IP

core.

Keep... but what is INNO HDMI IP core? Another name? Different block?

Documentation/devicetree/bindings/display/bridge/innosilicon,inn line 17

Quoted 2 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +2 -0
+  It is intended to be referenced by platform-specific device tree
+ bindings,  which will determine the necessity of each property.
Quoted 8 lines

Not much improved here. Last two sentences are almost useless. Again - document the hardware. Drop this sentence.

I already complained about this. I already complained that you keep ignoring my comments and this does not improve much.

Since you did not implement my main feedback I am going to NAK the rest except one more thing:

I appreciate your patience,
I will not refer to the existing YAML files in the main branch for writing anymore; I will only follow your suggestions
https://elixir.bootlin.com/linux/v6.12/source/Documentation/devicetree/bindings/display/bridge/synopsys,dw-hdmi.yaml#L18

Quoted 4 lines

...

Quoted 8 lines

Documentation/devicetree/bindings/display/bridge/innosilicon,inn

Quoted 4 lines
Documentation/devicetree/bindings/display/bridge/innosilicon,inn new file +4 -0
+
+properties:
+  compatible:
+    const: "starfive,jh7110-inno-hdmi"

I could not be more specific in my previous feedback. Improvements? No. Stop wasting our time.

This modification was overlooked when merging, sorry again. Thank you for your feedback.

Quoted 4 lines

NAK.

Best regards,
Krzysztof

author
#4 lore raw

PATCH v5 2/9 riscv: dts: Add display property

In reply to keith zhao

Add the display DT nodes in Starfive JH7110 soc-specific DT file.

---
 .../boot/dts/starfive/jh7110-common.dtsi      | 125 ++++++++++++++++++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  41 ++++++
 2 files changed, 166 insertions(+)
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +125 -0
index 9d77713f5361..301b56f2ef0c 100644
@@ -30,6 +30,25 @@ memory@40000000 {
 		reg = <0x0 0x40000000 0x1 0x0>;
 	};
 
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		/* vout applies for space from this CMA
+		 * Without this CMA reservation,
+		 * vout may not work properly.
+		 */
+		linux,cma {
+			compatible = "shared-dma-pool";
+			reusable;
+			size = <0x0 0x20000000>;
+			alignment = <0x0 0x1000>;
+			alloc-ranges = <0x0 0x70000000 0x0 0x20000000>;
+			linux,cma-default;
+		};
+	};
+
 	gpio-restart {
 		compatible = "gpio-restart";
 		gpios = <&sysgpio 35 GPIO_ACTIVE_HIGH>;
@@ -62,12 +81,55 @@ codec {
 			};
 		};
 	};
+
+	hdmi_con: hdmi-con {
+		compatible = "hdmi-connector";
+		type = "a";
+
+		port {
+			hdmi_con_in: endpoint {
+				remote-endpoint = <&hdmi_out_con>;
+			};
+		};
+	};
 };
 
 &cpus {
 	timebase-frequency = <4000000>;
 };
 
+&dc8200 {
+	status = "okay";
+	crtc_out: ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dc_out0: port@0 {
+			reg = <0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			dc_out_dpi0: endpoint@0 {
+				reg = <0>;
+				remote-endpoint = <&hdmi_enc>;
+			};
+
+		};
+
+		dc_out1: port@1 {
+			reg = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			dc_out_dpi1: endpoint@1 {
+				reg = <1>;
+				//remote-endpoint = <&dsi_enc>;
+			};
+
+		};
+	};
+};
+
 &dvp_clk {
 	clock-frequency = <74250000>;
 };
@@ -88,6 +150,31 @@ &gmac1_rmii_refin {
 	clock-frequency = <50000000>;
 };
 
+&hdmi {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&hdmi_pins>;
+
+	ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		hdmi_in: port@0 {
+			reg = <0>;
+			hdmi_enc: endpoint {
+				remote-endpoint = <&dc_out_dpi0>;
+			};
+		};
+
+		hdmi_out: port@1 {
+			reg = <1>;
+			hdmi_out_con: endpoint {
+				remote-endpoint = <&hdmi_con_in>;
+			};
+		};
+	};
+};
+
 &hdmitx0_pixelclk {
 	clock-frequency = <297000000>;
 };
@@ -366,6 +453,40 @@ &syscrg {
 };
 
 &sysgpio {
+	hdmi_pins: hdmi-0 {
+		hdmi-cec-pins {
+			pinmux = <GPIOMUX(14, GPOUT_SYS_HDMI_CEC_SDA,
+					      GPOEN_SYS_HDMI_CEC_SDA,
+					      GPI_SYS_HDMI_CEC_SDA)>;
+			input-enable;
+			bias-pull-up;
+		};
+
+		hdmi-hpd-pins {
+			pinmux = <GPIOMUX(15, GPOUT_HIGH,
+					      GPOEN_ENABLE,
+					      GPI_SYS_HDMI_HPD)>;
+			input-enable;
+			bias-disable; /* external pull-up */
+		};
+
+		hdmi-scl-pins {
+			pinmux = <GPIOMUX(0, GPOUT_SYS_HDMI_DDC_SCL,
+					     GPOEN_SYS_HDMI_DDC_SCL,
+					     GPI_SYS_HDMI_DDC_SCL)>;
+			input-enable;
+			bias-pull-up;
+		};
+
+		hdmi-sda-pins {
+			pinmux = <GPIOMUX(1, GPOUT_SYS_HDMI_DDC_SDA,
+					     GPOEN_SYS_HDMI_DDC_SDA,
+					     GPI_SYS_HDMI_DDC_SDA)>;
+			input-enable;
+			bias-pull-up;
+		};
+	};
+
 	i2c0_pins: i2c0-0 {
 		i2c-pins {
 			pinmux = <GPIOMUX(57, GPOUT_LOW,
@@ -656,3 +777,7 @@ &U74_3 {
 &U74_4 {
 	cpu-supply = <&vdd_cpu>;
 };
+
+&voutcrg {
+	status = "okay";
+};
arch/riscv/boot/dts/starfive/jh7110.dtsi +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#5 lore raw

Re: [PATCH v5 2/9] riscv: dts: Add display property

Quoted 3 lines · keith zhao

Add the display DT nodes in Starfive JH7110 soc-specific DT file.

$subject: "riscv: dts: Add display property"

a) this is jh7110 exclusive, not for all riscv devicetrees
b) you are adding more than a property

Quoted 10 lines
---
 .../boot/dts/starfive/jh7110-common.dtsi      | 125 ++++++++++++++++++
 arch/riscv/boot/dts/starfive/jh7110.dtsi      |  41 ++++++
 2 files changed, 166 insertions(+)
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +0 -0
index 9d77713f5361..301b56f2ef0c 100644

arch/riscv/boot/dts/starfive/jh7110-common.dtsi memory@40000000 { · line 38

Quoted 9 lines
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +6 -0
@@ -30,6 +30,25 @@ memory@40000000 {
 		reg = <0x0 0x40000000 0x1 0x0>;
 	};
 
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		/* vout applies for space from this CMA

"vout" could be a voltage, please be more specific. Comments should be wrapped at at least 80 chars. Linux coding style puts /* on a line of its own.

Quoted 30 lines
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +23 -0
+		 * Without this CMA reservation,
+		 * vout may not work properly.
+		 */
+		linux,cma {
+			compatible = "shared-dma-pool";
+			reusable;
+			size = <0x0 0x20000000>;
+			alignment = <0x0 0x1000>;
+			alloc-ranges = <0x0 0x70000000 0x0 0x20000000>;
+			linux,cma-default;
+		};
+	};
+
 	gpio-restart {
 		compatible = "gpio-restart";
 		gpios = <&sysgpio 35 GPIO_ACTIVE_HIGH>;
@@ -62,12 +81,55 @@ codec {
 			};
 		};
 	};
+
+	hdmi_con: hdmi-con {
+		compatible = "hdmi-connector";
+		type = "a";
+
+		port {
+			hdmi_con_in: endpoint {
+				remote-endpoint = <&hdmi_out_con>;
+			};
+		};

arch/riscv/boot/dts/starfive/jh7110-common.dtsi codec { · line 103

Quoted 10 lines
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +4 -0
+	};
 };
 
 &cpus {
 	timebase-frequency = <4000000>;
 };
 
+&dc8200 {
+	status = "okay";
+	crtc_out: ports {

blank line between properties and child nodes please.

arch/riscv/boot/dts/starfive/jh7110-common.dtsi codec { · line 107

Quoted 4 lines
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +4 -0
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		dc_out0: port@0 {

Cheers,
Conor.

author
#6 lore raw

PATCH v5 3/9 drm: bridge: inno-hdmi: add inno bridge driver.

In reply to keith zhao

move rochchip inno hdmi connector to a newly created directory named inno-hdmi.c, and rename rockchip/inno_hdmi.c to rockchip/inno_hdmi-rockchip.c

This patch refines the Innosilicon HDMI architecture by abstracting the existing connector into a bridge architecture.
The drm_bridge_connector_init function is used to create the connector.

---
 MAINTAINERS                                   |    2 +
 drivers/gpu/drm/bridge/Kconfig                |    2 +
 drivers/gpu/drm/bridge/Makefile               |    1 +
 drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
 drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
 .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
 .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
 drivers/gpu/drm/rockchip/Kconfig              |    1 +
 drivers/gpu/drm/rockchip/Makefile             |    2 +-
 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
 .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
 drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 -----------------
 include/drm/bridge/inno_hdmi.h                |   56 +
 13 files changed, 1171 insertions(+), 1026 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
 create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
 rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
 delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
 create mode 100644 include/drm/bridge/inno_hdmi.h
MAINTAINERS +2 -0
index f787dd625497..7766ee0bdd74 100644
@@ -7439,6 +7439,8 @@ S:	Maintained
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 F:	Documentation/devicetree/bindings/display/starfive/
+F:	drivers/gpu/drm/bridge/innosilicon/
+F:	include/drm/bridge/inno_hdmi.h
 
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
 M:	Michael Trimarchi <[email protected]>
drivers/gpu/drm/bridge/Kconfig +2 -0
index 683cb33805b2..37be5dd5213f 100644
@@ -423,6 +423,8 @@ source "drivers/gpu/drm/bridge/cadence/Kconfig"
 
 source "drivers/gpu/drm/bridge/imx/Kconfig"
 
+source "drivers/gpu/drm/bridge/innosilicon/Kconfig"
+
 source "drivers/gpu/drm/bridge/synopsys/Kconfig"
 
 endmenu
drivers/gpu/drm/bridge/Makefile +1 -0
index 3daf803ce80b..866d1e0fd8aa 100644
@@ -41,4 +41,5 @@ obj-$(CONFIG_DRM_ITE_IT66121) += ite-it66121.o
 obj-y += analogix/
 obj-y += cadence/
 obj-y += imx/
+obj-y += innosilicon/
 obj-y += synopsys/
drivers/gpu/drm/bridge/innosilicon/Kconfig new file +6 -0
new file mode 100644
index 000000000000..73dbed3b1c4d
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config DRM_INNO_HDMI
+	tristate
+	help
+	  Support the common interface which is part of the INNO
+	  Designware HDMI block.
drivers/gpu/drm/bridge/innosilicon/Makefile new file +2 -0
new file mode 100644
index 000000000000..3b3a961ab9fb
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_DRM_INNO_HDMI) += inno-hdmi.o
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +376 -0

376 lines not on this page · raw message

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h new file +34 -0
new file mode 100644
index 000000000000..75e3e002947f
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *    Zheng Yang <[email protected]>
+ *    Yakir Yang <[email protected]>
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#ifndef __INNO_H__
+#define __INNO_H__
+
+#define DDC_SEGMENT_ADDR		0x30
+
+#define HDMI_SCL_RATE			(100 * 1000)
+#define DDC_BUS_FREQ_L			0x4b
+#define DDC_BUS_FREQ_H			0x4c
+
+#define HDMI_EDID_SEGMENT_POINTER	0x4d
+#define HDMI_EDID_WORD_ADDR		0x4e
+#define HDMI_EDID_FIFO_OFFSET		0x4f
+#define HDMI_EDID_FIFO_ADDR		0x50
+
+#define HDMI_INTERRUPT_MASK1		0xc0
+#define HDMI_INTERRUPT_STATUS1		0xc1
+#define	m_INT_ACTIVE_VSYNC		(1 << 5)
+#define m_INT_EDID_READY		(1 << 2)
+
+#define HDMI_STATUS			0xc8
+#define m_HOTPLUG			(1 << 7)
+#define m_MASK_INT_HOTPLUG		(1 << 5)
+#define m_INT_HOTPLUG			(1 << 1)
+#define v_MASK_INT_HOTPLUG(n)		(((n) & 0x1) << 5)
+
+#endif /* __INNO_H__ */
drivers/gpu/drm/rockchip/Kconfig +1 -0
index 258dd38e1a8e..e728b5ee2219 100644
@@ -78,6 +78,7 @@ config ROCKCHIP_INNO_HDMI
 	select DRM_DISPLAY_HDMI_HELPER
 	select DRM_DISPLAY_HDMI_STATE_HELPER
 	select DRM_DISPLAY_HELPER
+	select DRM_INNO_HDMI
 	help
 	  This selects support for Rockchip SoC specific extensions
 	  for the Innosilicon HDMI driver. If you want to enable
drivers/gpu/drm/rockchip/Makefile +1 -1
index 3ff7b21c0414..4b2d0cba8db3 100644
@@ -12,7 +12,7 @@ rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_CDN_DP) += cdn-dp-core.o cdn-dp-reg.o
 rockchipdrm-$(CONFIG_ROCKCHIP_DW_HDMI) += dw_hdmi-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI) += dw-mipi-dsi-rockchip.o
-rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi.o
+rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_LVDS) += rockchip_lvds.o
 rockchipdrm-$(CONFIG_ROCKCHIP_RGB) += rockchip_rgb.o
 rockchipdrm-$(CONFIG_ROCKCHIP_RK3066_HDMI) += rk3066_hdmi.o
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +690 -0

690 lines not on this page · raw message

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.h renamed from drivers/gpu/drm/rockchip/inno_hdmi.h +0 -0
similarity index 100%
rename from drivers/gpu/drm/rockchip/inno_hdmi.h
rename to drivers/gpu/drm/rockchip/inno_hdmi-rockchip.h
drivers/gpu/drm/rockchip/inno_hdmi.c deleted +0 -1025

1,025 lines not on this page · raw message

include/drm/bridge/inno_hdmi.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 4 lines · keith zhao
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +4 -0
+	/* Unmute hotplug interrupt */
+	hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG, v_MASK_INT_HOTPLUG(1));
+
+	ret = devm_request_threaded_irq(hdmi->dev, irq, inno_hdmi_hardirq,

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 376

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+					inno_hdmi_irq, IRQF_SHARED,
+					dev_name(hdmi->dev), hdmi);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(inno_hdmi_bind);
+
+MODULE_AUTHOR("Keith Zhao <[email protected]>");
+MODULE_DESCRIPTION("INNO HDMI transmitter driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:inno-hdmi");

You should not need MODULE_ALIAS() in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute for incomplete ID table.

Best regards,
Krzysztof

author
#8 lore raw

RE: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 32 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: 2024年11月20日 15:38
To: Keith Zhao <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; William Qiu <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Changhuang Liang <[email protected]>; Jack Zhu <[email protected]>; [email protected]
Subject: Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 11 lines · keith zhao
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +11 -0
+	/* Unmute hotplug interrupt */
+	hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG,
+v_MASK_INT_HOTPLUG(1));
+
+	ret = devm_request_threaded_irq(hdmi->dev, irq, inno_hdmi_hardirq,
+					inno_hdmi_irq, IRQF_SHARED,
+					dev_name(hdmi->dev), hdmi);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(inno_hdmi_bind);
+
Quoted 9 lines

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c

Quoted 3 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +3 -0
+MODULE_AUTHOR("Keith Zhao <[email protected]>");
+MODULE_DESCRIPTION("INNO HDMI transmitter driver");
+MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:inno-hdmi");

You should not need MODULE_ALIAS() in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute for incomplete ID table.

Thank you for your suggestion!
I will review the device ID table to ensure its completeness and avoid using MODULE_ALIAS().

Quoted 3 lines

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 41 lines · Keith Zhao
Quoted 32 lines

-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: 2024年11月20日 15:38
To: Keith Zhao <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; William Qiu <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Changhuang Liang <[email protected]>; Jack Zhu <[email protected]>; [email protected]
Subject: Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 11 lines · keith zhao
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +11 -0
+	/* Unmute hotplug interrupt */
+	hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG,
+v_MASK_INT_HOTPLUG(1));
+
+	ret = devm_request_threaded_irq(hdmi->dev, irq, inno_hdmi_hardirq,
+					inno_hdmi_irq, IRQF_SHARED,
+					dev_name(hdmi->dev), hdmi);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(inno_hdmi_bind);
+
Quoted 9 lines

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c

Quoted 3 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +3 -0
+MODULE_AUTHOR("Keith Zhao <[email protected]>");
+MODULE_DESCRIPTION("INNO HDMI transmitter driver");
+MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:inno-hdmi");

You should not need MODULE_ALIAS() in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute for incomplete ID table.

Quoted 3 lines

Thank you for your suggestion!
I will review the device ID table to ensure its completeness and avoid using MODULE_ALIAS().

In this context neither MODULE_ALIAS nor ID table are suitable/needed. If you need them, means your driver does not build in all setups :/ Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

In reply to keith zhao

Hello,

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 685

Quoted 3 lines · keith zhao
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +3 -0
+struct platform_driver inno_hdmi_driver = {
+	.probe  = inno_hdmi_rockchip_probe,
+	.remove_new = inno_hdmi_rockchip_remove,

Please use .remove instead of .remove_new.

Best regards
Uwe

author
#11 lore raw

RE: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 20 lines

-----Original Message-----
From: Uwe Kleine-König <[email protected]>
Sent: 2024年11月20日 22:56
To: Keith Zhao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; William Qiu <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Changhuang Liang <[email protected]>; Jack Zhu <[email protected]>; [email protected]
Subject: Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 9 lines

Hello,

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 685

Quoted 3 lines · keith zhao
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +3 -0
+struct platform_driver inno_hdmi_driver = {
+	.probe  = inno_hdmi_rockchip_probe,
+	.remove_new = inno_hdmi_rockchip_remove,

Please use .remove instead of .remove_new.

Thank you for the clarification regarding .remove_new.
I understand that it's a relic and that new drivers should implement .remove().

I have a question. One of the changes in this patch is to rename some function interfaces. The original code is like this.

struct platform_driver inno_hdmi_driver = {
.probe = inno_hdmi_probe, .remove_new = inno_hdmi_remove, .driver = {
.name = "innohdmi-rockchip", .of_match_table = inno_hdmi_dt_ids,
},
};

Rename inno_hdmi_probe and inno_hdmi_remove struct platform_driver inno_hdmi_driver = {
.probe = inno_hdmi_rockchip_probe, .remove_new = inno_hdmi_rockchip_remove, .driver = {
.name = "innohdmi-rockchip", .of_match_table = inno_hdmi_dt_ids,
},
};
Based on the principle of maintaining consistency, does it(remove_new) need to be changed?

Thanks

Quoted 2 lines

Best regards
Uwe

#12 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 44 lines · Keith Zhao
Quoted 20 lines

-----Original Message-----
From: Uwe Kleine-König <[email protected]>
Sent: 2024年11月20日 22:56
To: Keith Zhao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; William Qiu <[email protected]>; Xingyu Wu <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Changhuang Liang <[email protected]>; Jack Zhu <[email protected]>; [email protected]
Subject: Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

Quoted 9 lines

Hello,

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 685

Quoted 3 lines · keith zhao
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +3 -0
+struct platform_driver inno_hdmi_driver = {
+	.probe  = inno_hdmi_rockchip_probe,
+	.remove_new = inno_hdmi_rockchip_remove,

Please use .remove instead of .remove_new.

Thank you for the clarification regarding .remove_new.
I understand that it's a relic and that new drivers should implement .remove().

I have a question. One of the changes in this patch is to rename some function interfaces. The original code is like this.

struct platform_driver inno_hdmi_driver = {
.probe = inno_hdmi_probe, .remove_new = inno_hdmi_remove, .driver = {
.name = "innohdmi-rockchip", .of_match_table = inno_hdmi_dt_ids,
},
};

Quoted 11 lines

Rename inno_hdmi_probe and inno_hdmi_remove struct platform_driver inno_hdmi_driver = {
.probe = inno_hdmi_rockchip_probe, .remove_new = inno_hdmi_rockchip_remove, .driver = {
.name = "innohdmi-rockchip", .of_match_table = inno_hdmi_dt_ids,
},
};
Based on the principle of maintaining consistency, does it(remove_new) need to be changed?

If this isn't new code but moving from somewhere, don't change .remove_new into .remove in the same patch. If you want, fix that in a separate patch then.

Best regards
Uwe

#13 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

In reply to keith zhao
Quoted 7 lines · keith zhao

move rochchip inno hdmi connector to a newly created directory named inno-hdmi.c, and rename rockchip/inno_hdmi.c to rockchip/inno_hdmi-rockchip.c

This patch refines the Innosilicon HDMI architecture by abstracting the existing connector into a bridge architecture.
The drm_bridge_connector_init function is used to create the connector.

Please describe your design decisions. What is common to all Innosilicon HDMI bridges and what bits are specific to the Rockchip implementation.

Quoted 127 lines
---
 MAINTAINERS                                   |    2 +
 drivers/gpu/drm/bridge/Kconfig                |    2 +
 drivers/gpu/drm/bridge/Makefile               |    1 +
 drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
 drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
 .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
 .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
 drivers/gpu/drm/rockchip/Kconfig              |    1 +
 drivers/gpu/drm/rockchip/Makefile             |    2 +-
 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
 .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
 drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 -----------------
 include/drm/bridge/inno_hdmi.h                |   56 +
 13 files changed, 1171 insertions(+), 1026 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
 create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
 rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
 delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
 create mode 100644 include/drm/bridge/inno_hdmi.h
MAINTAINERS +2 -0
index f787dd625497..7766ee0bdd74 100644
@@ -7439,6 +7439,8 @@ S:	Maintained
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 F:	Documentation/devicetree/bindings/display/starfive/
+F:	drivers/gpu/drm/bridge/innosilicon/
+F:	include/drm/bridge/inno_hdmi.h
 
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
 M:	Michael Trimarchi <[email protected]>
drivers/gpu/drm/bridge/Kconfig +2 -0
index 683cb33805b2..37be5dd5213f 100644
@@ -423,6 +423,8 @@ source "drivers/gpu/drm/bridge/cadence/Kconfig"
 
 source "drivers/gpu/drm/bridge/imx/Kconfig"
 
+source "drivers/gpu/drm/bridge/innosilicon/Kconfig"
+
 source "drivers/gpu/drm/bridge/synopsys/Kconfig"
 
 endmenu
drivers/gpu/drm/bridge/Makefile +1 -0
index 3daf803ce80b..866d1e0fd8aa 100644
@@ -41,4 +41,5 @@ obj-$(CONFIG_DRM_ITE_IT66121) += ite-it66121.o
 obj-y += analogix/
 obj-y += cadence/
 obj-y += imx/
+obj-y += innosilicon/
 obj-y += synopsys/
drivers/gpu/drm/bridge/innosilicon/Kconfig new file +6 -0
new file mode 100644
index 000000000000..73dbed3b1c4d
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config DRM_INNO_HDMI
+	tristate
+	help
+	  Support the common interface which is part of the INNO
+	  Designware HDMI block.
drivers/gpu/drm/bridge/innosilicon/Makefile new file +2 -0
new file mode 100644
index 000000000000..3b3a961ab9fb
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_DRM_INNO_HDMI) += inno-hdmi.o
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +39 -0
new file mode 100644
index 000000000000..c26132b41bdf
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *    Zheng Yang <[email protected]>
+ *    Yakir Yang <[email protected]>
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#include <drm/bridge/inno_hdmi.h>
+#include <drm/display/drm_hdmi_state_helper.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_of.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_bridge.h>
+#include <drm/drm_bridge_connector.h>
+
+#include "inno-hdmi.h"
+
+u8 hdmi_readb(struct inno_hdmi *hdmi, u16 offset)
+{
+	return readl_relaxed(hdmi->regs + (offset) * 0x04);
+}
+EXPORT_SYMBOL_GPL(hdmi_readb);
+
+void hdmi_writeb(struct inno_hdmi *hdmi, u16 offset, u32 val)
+{
+	writel_relaxed(val, hdmi->regs + (offset) * 0x04);
+}

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 49

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+EXPORT_SYMBOL_GPL(hdmi_writeb);
+
+void hdmi_modb(struct inno_hdmi *hdmi, u16 offset, u32 msk, u32 val)
+{
+	u8 temp = hdmi_readb(hdmi, offset) & ~msk;
+
+	temp |= val & msk;
+	hdmi_writeb(hdmi, offset, temp);
+}
+EXPORT_SYMBOL_GPL(hdmi_modb);

So, you are exporting the low-level register accessory functions, including the unprotected RMW function (which makes almost impossible to track users if something goes wrong). May I ask, why?

Quoted 46 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +46 -0
+
+void inno_hdmi_i2c_init(struct inno_hdmi *hdmi, unsigned long long rate)
+{
+	unsigned long long ddc_bus_freq = rate >> 2;
+
+	do_div(ddc_bus_freq, HDMI_SCL_RATE);
+
+	hdmi_writeb(hdmi, DDC_BUS_FREQ_L, ddc_bus_freq & 0xFF);
+	hdmi_writeb(hdmi, DDC_BUS_FREQ_H, (ddc_bus_freq >> 8) & 0xFF);
+
+	/* Clear the EDID interrupt flag and mute the interrupt */
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, 0);
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
+}
+EXPORT_SYMBOL_GPL(inno_hdmi_i2c_init);
+
+static irqreturn_t inno_hdmi_i2c_irq(struct inno_hdmi *hdmi)
+{
+	struct inno_hdmi_i2c *i2c = hdmi->i2c;
+	u8 stat;
+
+	stat = hdmi_readb(hdmi, HDMI_INTERRUPT_STATUS1);
+	if (!(stat & m_INT_EDID_READY))
+		return IRQ_NONE;
+
+	/* Clear HDMI EDID interrupt flag */
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
+
+	complete(&i2c->cmp);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t inno_hdmi_hardirq(int irq, void *dev_id)
+{
+	struct inno_hdmi *hdmi = dev_id;
+	irqreturn_t ret = IRQ_NONE;
+	u8 interrupt;
+
+	if (hdmi->i2c)
+		ret = inno_hdmi_i2c_irq(hdmi);
+
+	interrupt = hdmi_readb(hdmi, HDMI_STATUS);
+	if (interrupt & m_INT_HOTPLUG) {
+		hdmi_modb(hdmi, HDMI_STATUS, m_INT_HOTPLUG, m_INT_HOTPLUG);
+		ret = IRQ_WAKE_THREAD;

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 105

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+	}
+
+	return ret;
+}
+
+static irqreturn_t inno_hdmi_irq(int irq, void *dev_id)
+{
+	struct inno_hdmi *hdmi = dev_id;
+
+	drm_helper_hpd_irq_event(hdmi->bridge.dev);

I understand that you are mostly moving existing code around. I just hope to see that this gets rewored in the next patches to use drm_bridge_hpd_notify() instead.

Quoted 126 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +126 -0
+
+	return IRQ_HANDLED;
+}
+
+static int inno_hdmi_i2c_read(struct inno_hdmi *hdmi, struct i2c_msg *msgs)
+{
+	int length = msgs->len;
+	u8 *buf = msgs->buf;
+	int ret;
+
+	ret = wait_for_completion_timeout(&hdmi->i2c->cmp, HZ / 10);
+	if (!ret)
+		return -EAGAIN;
+
+	while (length--)
+		*buf++ = hdmi_readb(hdmi, HDMI_EDID_FIFO_ADDR);
+
+	return 0;
+}
+
+static int inno_hdmi_i2c_write(struct inno_hdmi *hdmi, struct i2c_msg *msgs)
+{
+	/*
+	 * The DDC module only support read EDID message, so
+	 * we assume that each word write to this i2c adapter
+	 * should be the offset of EDID word address.
+	 */
+	if (msgs->len != 1 || (msgs->addr != DDC_ADDR && msgs->addr != DDC_SEGMENT_ADDR))
+		return -EINVAL;
+
+	reinit_completion(&hdmi->i2c->cmp);
+
+	if (msgs->addr == DDC_SEGMENT_ADDR)
+		hdmi->i2c->segment_addr = msgs->buf[0];
+	if (msgs->addr == DDC_ADDR)
+		hdmi->i2c->ddc_addr = msgs->buf[0];
+
+	/* Set edid fifo first addr */
+	hdmi_writeb(hdmi, HDMI_EDID_FIFO_OFFSET, 0x00);
+
+	/* Set edid word address 0x00/0x80 */
+	hdmi_writeb(hdmi, HDMI_EDID_WORD_ADDR, hdmi->i2c->ddc_addr);
+
+	/* Set edid segment pointer */
+	hdmi_writeb(hdmi, HDMI_EDID_SEGMENT_POINTER, hdmi->i2c->segment_addr);
+
+	return 0;
+}
+
+static int inno_hdmi_i2c_xfer(struct i2c_adapter *adap,
+			      struct i2c_msg *msgs, int num)
+{
+	struct inno_hdmi *hdmi = i2c_get_adapdata(adap);
+	struct inno_hdmi_i2c *i2c = hdmi->i2c;
+	int i, ret = 0;
+
+	guard(mutex)(&i2c->lock);
+	/* Clear the EDID interrupt flag and unmute the interrupt */
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, m_INT_EDID_READY);
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
+
+	for (i = 0; i < num; i++) {
+		DRM_DEV_DEBUG(hdmi->dev,
+			      "xfer: num: %d/%d, len: %d, flags: %#x\n",
+			      i + 1, num, msgs[i].len, msgs[i].flags);
+
+		if (msgs[i].flags & I2C_M_RD)
+			ret = inno_hdmi_i2c_read(hdmi, &msgs[i]);
+		else
+			ret = inno_hdmi_i2c_write(hdmi, &msgs[i]);
+
+		if (ret < 0)
+			break;
+	}
+
+	if (!ret)
+		ret = num;
+
+	/* Mute HDMI EDID interrupt */
+	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, 0);
+
+	return ret;
+}
+
+static u32 inno_hdmi_i2c_func(struct i2c_adapter *adapter)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+static const struct i2c_algorithm inno_hdmi_algorithm = {
+	.master_xfer	= inno_hdmi_i2c_xfer,
+	.functionality	= inno_hdmi_i2c_func,
+};
+
+static struct i2c_adapter *inno_hdmi_i2c_adapter(struct inno_hdmi *hdmi)
+{
+	struct i2c_adapter *adap;
+	struct inno_hdmi_i2c *i2c;
+	int ret;
+
+	i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL);
+	if (!i2c)
+		return ERR_PTR(-ENOMEM);
+
+	mutex_init(&i2c->lock);
+	init_completion(&i2c->cmp);
+
+	adap = &i2c->adap;
+	adap->owner = THIS_MODULE;
+	adap->dev.parent = hdmi->dev;
+	adap->dev.of_node = hdmi->dev->of_node;
+	adap->algo = &inno_hdmi_algorithm;
+	strscpy(adap->name, "Inno HDMI", sizeof(adap->name));
+	i2c_set_adapdata(adap, hdmi);
+
+	ret = devm_i2c_add_adapter(hdmi->dev, adap);
+	if (ret) {
+		dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name);
+		return ERR_PTR(ret);
+	}
+
+	hdmi->i2c = i2c;
+
+	DRM_DEV_DEBUG(hdmi->dev, "registered %s I2C bus driver\n", adap->name);
+
+	return adap;

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 241

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+}
+
+static int inno_bridge_attach(struct drm_bridge *bridge,
+			      enum drm_bridge_attach_flags flags)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+
+	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
+		return drm_bridge_attach(bridge->encoder, hdmi->next_bridge,
+					 bridge, flags);

No. You are not handling the case of flags == 0, so return -EINVAL if there is no DRM_BRIDGE_ATTACH_NO_CONNECTOR flag and then drm_bridge_attach the next bridge.

Quoted 22 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +22 -0
+
+	return 0;
+}
+
+static enum drm_connector_status
+inno_hdmi_bridge_detect(struct drm_bridge *bridge)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+
+	return (hdmi_readb(hdmi, HDMI_STATUS) & m_HOTPLUG) ?
+		connector_status_connected : connector_status_disconnected;
+}
+
+static const struct drm_edid *inno_bridge_edid_read(struct drm_bridge *bridge,
+						    struct drm_connector *connector)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+
+	return drm_edid_read_ddc(connector, hdmi->bridge.ddc);
+}
+
+static enum drm_mode_status

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 273

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+inno_bridge_mode_valid(struct drm_bridge *bridge,
+		       const struct drm_display_info *info,
+		       const struct drm_display_mode *mode)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+
+	enum drm_mode_status mode_status = MODE_OK;
+
+	if (hdmi->plat_data->mode_valid)
+		mode_status = hdmi->plat_data->mode_valid(hdmi, mode);

TMDS char rate validation should be handled in the generic code so that I can replace it later on. Fix the driver first and then perform code split.

Quoted 15 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +15 -0
+
+	return mode_status;
+}
+
+static int inno_hdmi_clear_infoframe(struct drm_bridge *bridge,
+				     enum hdmi_infoframe_type type)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+	int ret = 0;
+
+	if (hdmi->plat_data->hdmi_clear_infoframe)
+		ret = hdmi->plat_data->hdmi_clear_infoframe(hdmi, type);
+
+	return ret;
+}

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 298

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+
+static int inno_write_infoframe(struct drm_bridge *bridge,
+				enum hdmi_infoframe_type type,
+				const u8 *buffer, size_t len)
+{
+	struct inno_hdmi *hdmi = bridge->driver_private;
+	int ret = 0;
+
+	if (hdmi->plat_data->hdmi_write_infoframe)
+		ret = hdmi->plat_data->hdmi_write_infoframe(hdmi, type, buffer, len);

Are these two ops really platform-specific?

Quoted 43 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +43 -0
+
+	return ret;
+}
+
+static int inno_bridge_atomic_check(struct drm_bridge *bridge,
+					   struct drm_bridge_state *bridge_state,
+					   struct drm_crtc_state *crtc_state,
+					   struct drm_connector_state *conn_state)
+{
+	return drm_atomic_helper_connector_hdmi_check(conn_state->connector,
+							  bridge_state->base.state);
+}
+
+static const struct drm_bridge_funcs inno_bridge_funcs = {
+	.atomic_check	  = inno_bridge_atomic_check,
+	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
+	.atomic_reset = drm_atomic_helper_bridge_reset,
+	.attach = inno_bridge_attach,
+	.detect = inno_hdmi_bridge_detect,
+	.edid_read = inno_bridge_edid_read,
+	.mode_valid = inno_bridge_mode_valid,
+	.hdmi_clear_infoframe = inno_hdmi_clear_infoframe,
+	.hdmi_write_infoframe = inno_write_infoframe,
+};
+
+int inno_hdmi_bind(struct drm_device *drm, struct inno_hdmi *hdmi, struct drm_encoder	*encoder)
+{
+	int ret, irq;
+	struct platform_device *pdev = to_platform_device(hdmi->dev);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		ret = irq;
+		return ret;
+	}
+
+	hdmi->ddc = inno_hdmi_i2c_adapter(hdmi);
+	if (IS_ERR(hdmi->ddc)) {
+		ret = PTR_ERR(hdmi->ddc);
+		hdmi->ddc = NULL;
+		return ret;
+	}

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 351

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+
+	hdmi->next_bridge = devm_drm_of_get_bridge(hdmi->dev, hdmi->dev->of_node, 1, 0);
+	if (IS_ERR(hdmi->next_bridge))
+		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->next_bridge),
+				     "failed to acquire drm_bridge\n");
+
+	hdmi->bridge.driver_private = hdmi;
+	hdmi->bridge.funcs = &inno_bridge_funcs;
+	hdmi->bridge.ddc = hdmi->ddc;
+#ifdef CONFIG_OF

Drop #ifdef, it is always present.

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 364

Quoted 13 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +13 -0
+	hdmi->bridge.of_node = hdmi->dev->of_node;
+#endif
+	hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID |
+					 DRM_BRIDGE_OP_HPD | DRM_BRIDGE_OP_HDMI;
+	hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
+
+	hdmi->bridge.vendor = hdmi->plat_data->vendor;
+	hdmi->bridge.product = hdmi->plat_data->product;
+
+	devm_drm_bridge_add(hdmi->dev, &hdmi->bridge);
+
+	/* Unmute hotplug interrupt */
+	hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG, v_MASK_INT_HOTPLUG(1));

This should be handled by .hpd_enable() / .hpd_disable().

Quoted 40 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +12 -0
+
+	ret = devm_request_threaded_irq(hdmi->dev, irq, inno_hdmi_hardirq,
+					inno_hdmi_irq, IRQF_SHARED,
+					dev_name(hdmi->dev), hdmi);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(inno_hdmi_bind);
+
+MODULE_AUTHOR("Keith Zhao <[email protected]>");
+MODULE_DESCRIPTION("INNO HDMI transmitter driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:inno-hdmi");
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h new file +22 -0
new file mode 100644
index 000000000000..75e3e002947f
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *    Zheng Yang <[email protected]>
+ *    Yakir Yang <[email protected]>
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#ifndef __INNO_H__
+#define __INNO_H__
+
+#define DDC_SEGMENT_ADDR		0x30
+
+#define HDMI_SCL_RATE			(100 * 1000)
+#define DDC_BUS_FREQ_L			0x4b
+#define DDC_BUS_FREQ_H			0x4c
+
+#define HDMI_EDID_SEGMENT_POINTER	0x4d
+#define HDMI_EDID_WORD_ADDR		0x4e
+#define HDMI_EDID_FIFO_OFFSET		0x4f
+#define HDMI_EDID_FIFO_ADDR		0x50
+

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h line 32

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h new file +10 -0
+#define HDMI_INTERRUPT_MASK1		0xc0
+#define HDMI_INTERRUPT_STATUS1		0xc1
+#define	m_INT_ACTIVE_VSYNC		(1 << 5)
+#define m_INT_EDID_READY		(1 << 2)
+
+#define HDMI_STATUS			0xc8
+#define m_HOTPLUG			(1 << 7)
+#define m_MASK_INT_HOTPLUG		(1 << 5)
+#define m_INT_HOTPLUG			(1 << 1)
+#define v_MASK_INT_HOTPLUG(n)		(((n) & 0x1) << 5)

No need for a separate header. Who else is going to use it?

Quoted 175 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h new file +2 -0
+
+#endif /* __INNO_H__ */
drivers/gpu/drm/rockchip/Kconfig +1 -0
index 258dd38e1a8e..e728b5ee2219 100644
@@ -78,6 +78,7 @@ config ROCKCHIP_INNO_HDMI
 	select DRM_DISPLAY_HDMI_HELPER
 	select DRM_DISPLAY_HDMI_STATE_HELPER
 	select DRM_DISPLAY_HELPER
+	select DRM_INNO_HDMI
 	help
 	  This selects support for Rockchip SoC specific extensions
 	  for the Innosilicon HDMI driver. If you want to enable
drivers/gpu/drm/rockchip/Makefile +1 -1
index 3ff7b21c0414..4b2d0cba8db3 100644
@@ -12,7 +12,7 @@ rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_CDN_DP) += cdn-dp-core.o cdn-dp-reg.o
 rockchipdrm-$(CONFIG_ROCKCHIP_DW_HDMI) += dw_hdmi-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_DW_MIPI_DSI) += dw-mipi-dsi-rockchip.o
-rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi.o
+rockchipdrm-$(CONFIG_ROCKCHIP_INNO_HDMI) += inno_hdmi-rockchip.o
 rockchipdrm-$(CONFIG_ROCKCHIP_LVDS) += rockchip_lvds.o
 rockchipdrm-$(CONFIG_ROCKCHIP_RGB) += rockchip_rgb.o
 rockchipdrm-$(CONFIG_ROCKCHIP_RK3066_HDMI) += rk3066_hdmi.o
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +142 -0
new file mode 100644
index 000000000000..2bde9d539e9e
@@ -0,0 +1,690 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *    Zheng Yang <[email protected]>
+ *    Yakir Yang <[email protected]>
+ */
+
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/hdmi.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#include <drm/bridge/inno_hdmi.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_bridge_connector.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_of.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>
+
+#include <drm/display/drm_hdmi_helper.h>
+#include <drm/display/drm_hdmi_state_helper.h>
+
+#include "rockchip_drm_drv.h"
+
+#include "inno_hdmi-rockchip.h"
+
+#define INNO_HDMI_MIN_TMDS_CLOCK  25000000U
+
+struct inno_hdmi_rockchip_phy_config {
+	unsigned long pixelclock;
+	u8 pre_emphasis;
+	u8 voltage_level_control;
+};
+
+struct inno_hdmi_rockchip_variant {
+	struct inno_hdmi_rockchip_phy_config *phy_configs;
+	struct inno_hdmi_rockchip_phy_config *default_phy_config;
+	const struct inno_hdmi_plat_data *plat_data;
+};
+
+struct rockchip_inno_hdmi {
+	struct device *dev;
+
+	struct clk *pclk;
+	struct clk *refclk;
+
+	struct inno_hdmi inno_hdmi;
+	struct drm_connector	*connector;
+	struct rockchip_encoder	encoder;
+
+	const struct inno_hdmi_rockchip_variant *variant;
+	unsigned int			colorimetry;
+};
+
+static struct rockchip_inno_hdmi *encoder_to_rk_hdmi(struct drm_encoder *encoder)
+{
+	struct rockchip_encoder *rkencoder = to_rockchip_encoder(encoder);
+
+	return container_of(rkencoder, struct rockchip_inno_hdmi, encoder);
+}
+
+static struct rockchip_inno_hdmi *inno_hdmi_to_rk_hdmi(struct inno_hdmi *inno_hdmi)
+{
+	return container_of(inno_hdmi, struct rockchip_inno_hdmi, inno_hdmi);
+}
+
+enum {
+	CSC_RGB_0_255_TO_ITU601_16_235_8BIT,
+	CSC_RGB_0_255_TO_ITU709_16_235_8BIT,
+	CSC_RGB_0_255_TO_RGB_16_235_8BIT,
+};
+
+static const char coeff_csc[][24] = {
+	/*
+	 * RGB2YUV:601 SD mode:
+	 *   Cb = -0.291G - 0.148R + 0.439B + 128
+	 *   Y  = 0.504G  + 0.257R + 0.098B + 16
+	 *   Cr = -0.368G + 0.439R - 0.071B + 128
+	 */
+	{
+		0x11, 0x5f, 0x01, 0x82, 0x10, 0x23, 0x00, 0x80,
+		0x02, 0x1c, 0x00, 0xa1, 0x00, 0x36, 0x00, 0x1e,
+		0x11, 0x29, 0x10, 0x59, 0x01, 0x82, 0x00, 0x80
+	},
+	/*
+	 * RGB2YUV:709 HD mode:
+	 *   Cb = - 0.338G - 0.101R + 0.439B + 128
+	 *   Y  = 0.614G   + 0.183R + 0.062B + 16
+	 *   Cr = - 0.399G + 0.439R - 0.040B + 128
+	 */
+	{
+		0x11, 0x98, 0x01, 0xc1, 0x10, 0x28, 0x00, 0x80,
+		0x02, 0x74, 0x00, 0xbb, 0x00, 0x3f, 0x00, 0x10,
+		0x11, 0x5a, 0x10, 0x67, 0x01, 0xc1, 0x00, 0x80
+	},
+	/*
+	 * RGB[0:255]2RGB[16:235]:
+	 *   R' = R x (235-16)/255 + 16;
+	 *   G' = G x (235-16)/255 + 16;
+	 *   B' = B x (235-16)/255 + 16;
+	 */
+	{
+		0x00, 0x00, 0x03, 0x6F, 0x00, 0x00, 0x00, 0x10,
+		0x03, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+		0x00, 0x00, 0x00, 0x00, 0x03, 0x6F, 0x00, 0x10
+	},
+};
+
+static struct inno_hdmi_rockchip_phy_config rk3036_hdmi_phy_configs[] = {
+	{  74250000, 0x3f, 0xbb },
+	{ 165000000, 0x6f, 0xbb },
+	{      ~0UL, 0x00, 0x00 }
+};
+
+static struct inno_hdmi_rockchip_phy_config rk3128_hdmi_phy_configs[] = {
+	{  74250000, 0x3f, 0xaa },
+	{ 165000000, 0x5f, 0xaa },
+	{      ~0UL, 0x00, 0x00 }
+};
+
+static int inno_hdmi_rockchip_find_phy_config(struct rockchip_inno_hdmi *rk_hdmi,
+					      unsigned long pixelclk)
+{
+	const struct inno_hdmi_rockchip_phy_config *phy_configs =
+						rk_hdmi->variant->phy_configs;
+	int i;
+
+	for (i = 0; phy_configs[i].pixelclock != ~0UL; i++) {
+		if (pixelclk <= phy_configs[i].pixelclock)
+			return i;
+	}
+
+	DRM_DEV_DEBUG(rk_hdmi->dev, "No phy configuration for pixelclock %lu\n",
+		      pixelclk);
+

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 152

Quoted 10 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +10 -0
+	return -EINVAL;
+}
+
+static void inno_hdmi_rockchip_sys_power(struct inno_hdmi *hdmi, bool enable)
+{
+	if (enable)
+		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_ON);
+	else
+		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_OFF);
+}

This looks exactly like SF code

Quoted 27 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +27 -0
+
+static void inno_hdmi_rockchip_standby(struct inno_hdmi *hdmi)
+{
+	inno_hdmi_rockchip_sys_power(hdmi, false);
+
+	hdmi_writeb(hdmi, HDMI_PHY_DRIVER, 0x00);
+	hdmi_writeb(hdmi, HDMI_PHY_PRE_EMPHASIS, 0x00);
+	hdmi_writeb(hdmi, HDMI_PHY_CHG_PWR, 0x00);
+	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x15);
+};
+
+static void inno_hdmi_rockchip_power_up(struct rockchip_inno_hdmi *rk_hdmi,
+					unsigned long mpixelclock)
+{
+	struct inno_hdmi_rockchip_phy_config *phy_config;
+	struct inno_hdmi *hdmi = &rk_hdmi->inno_hdmi;
+	int ret = inno_hdmi_rockchip_find_phy_config(rk_hdmi, mpixelclock);
+
+	if (ret < 0) {
+		phy_config = rk_hdmi->variant->default_phy_config;
+		DRM_DEV_ERROR(rk_hdmi->dev,
+			      "Using default phy configuration for TMDS rate %lu",
+			      mpixelclock);
+	} else {
+		phy_config = &rk_hdmi->variant->phy_configs[ret];
+	}
+

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 189

Quoted 10 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +10 -0
+	inno_hdmi_rockchip_sys_power(hdmi, false);
+
+	hdmi_writeb(hdmi, HDMI_PHY_PRE_EMPHASIS, phy_config->pre_emphasis);
+	hdmi_writeb(hdmi, HDMI_PHY_DRIVER, phy_config->voltage_level_control);
+	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x15);
+	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x14);
+	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x10);
+	hdmi_writeb(hdmi, HDMI_PHY_CHG_PWR, 0x0f);
+	hdmi_writeb(hdmi, HDMI_PHY_SYNC, 0x00);
+	hdmi_writeb(hdmi, HDMI_PHY_SYNC, 0x01);

Are these registers platform-specific too?

Quoted 89 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +89 -0
+
+	inno_hdmi_rockchip_sys_power(hdmi, true);
+};
+
+static void inno_hdmi_rockchip_reset(struct inno_hdmi *hdmi)
+{
+	u32 val;
+	u32 msk;
+
+	hdmi_modb(hdmi, HDMI_SYS_CTRL, m_RST_DIGITAL, v_NOT_RST_DIGITAL);
+	udelay(100);
+
+	hdmi_modb(hdmi, HDMI_SYS_CTRL, m_RST_ANALOG, v_NOT_RST_ANALOG);
+	udelay(100);
+
+	msk = m_REG_CLK_INV | m_REG_CLK_SOURCE | m_POWER | m_INT_POL;
+	val = v_REG_CLK_INV | v_REG_CLK_SOURCE_SYS | v_PWR_ON | v_INT_POL_HIGH;
+	hdmi_modb(hdmi, HDMI_SYS_CTRL, msk, val);
+
+	inno_hdmi_rockchip_standby(hdmi);
+}
+
+static int inno_hdmi_rockchip_disable_frame(struct inno_hdmi *hdmi,
+					    enum hdmi_infoframe_type type)
+{
+	if (type != HDMI_INFOFRAME_TYPE_AVI) {
+		drm_err(hdmi->bridge.dev,
+			"Unsupported infoframe type: %u\n", type);
+		return 0;
+	}
+
+	hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_BUF_INDEX, INFOFRAME_AVI);
+
+	return 0;
+}
+
+static int inno_hdmi_rockchip_upload_frame(struct inno_hdmi *hdmi,
+					   enum hdmi_infoframe_type type,
+					   const u8 *buffer, size_t len)
+{
+	ssize_t i;
+
+	if (type != HDMI_INFOFRAME_TYPE_AVI) {
+		drm_err(hdmi->bridge.dev,
+			"Unsupported infoframe type: %u\n", type);
+		return 0;
+	}
+
+	inno_hdmi_rockchip_disable_frame(hdmi, type);
+
+	for (i = 0; i < len; i++)
+		hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_ADDR + i, buffer[i]);
+
+	return 0;
+}
+
+static int inno_hdmi_rockchip_config_video_csc(struct rockchip_inno_hdmi *rk_hdmi)
+{
+	struct drm_connector *connector = rk_hdmi->connector;
+	struct drm_connector_state *conn_state = connector->state;
+	struct inno_hdmi *hdmi = &rk_hdmi->inno_hdmi;
+
+	int c0_c2_change = 0;
+	int csc_enable = 0;
+	int csc_mode = 0;
+	int auto_csc = 0;
+	int value;
+	int i;
+
+	/* Input video mode is SDR RGB24bit, data enable signal from external */
+	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL1, v_DE_EXTERNAL |
+		    v_VIDEO_INPUT_FORMAT(VIDEO_INPUT_SDR_RGB444));
+
+	/* Input color hardcode to RGB, and output color hardcode to RGB888 */
+	value = v_VIDEO_INPUT_BITS(VIDEO_INPUT_8BITS) |
+		v_VIDEO_OUTPUT_COLOR(0) |
+		v_VIDEO_INPUT_CSP(0);
+	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL2, value);
+
+	if (conn_state->hdmi.output_format == HDMI_COLORSPACE_RGB) {
+		if (conn_state->hdmi.is_limited_range) {
+			csc_mode = CSC_RGB_0_255_TO_RGB_16_235_8BIT;
+			auto_csc = AUTO_CSC_DISABLE;
+			c0_c2_change = C0_C2_CHANGE_DISABLE;
+			csc_enable = v_CSC_ENABLE;
+
+		} else {
+			value = v_SOF_DISABLE | v_COLOR_DEPTH_NOT_INDICATED(1);
+			hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 288

Quoted 10 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +10 -0
+
+			hdmi_modb(hdmi, HDMI_VIDEO_CONTRL,
+				  m_VIDEO_AUTO_CSC | m_VIDEO_C0_C2_SWAP,
+				  v_VIDEO_AUTO_CSC(AUTO_CSC_DISABLE) |
+				  v_VIDEO_C0_C2_SWAP(C0_C2_CHANGE_DISABLE));
+			return 0;
+		}
+	} else {
+		if (rk_hdmi->colorimetry == HDMI_COLORIMETRY_ITU_601) {
+			if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {

This is not your fault, but I don't see HDMI_COLORSPACE_YUV444 in supported_formats being passed to drmm_connector_hdmi_init(). Probably this needs to be fixed.

Quoted 17 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +17 -0
+				csc_mode = CSC_RGB_0_255_TO_ITU601_16_235_8BIT;
+				auto_csc = AUTO_CSC_DISABLE;
+				c0_c2_change = C0_C2_CHANGE_DISABLE;
+				csc_enable = v_CSC_ENABLE;
+			}
+		} else {
+			if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {
+				csc_mode = CSC_RGB_0_255_TO_ITU709_16_235_8BIT;
+				auto_csc = AUTO_CSC_DISABLE;
+				c0_c2_change = C0_C2_CHANGE_DISABLE;
+				csc_enable = v_CSC_ENABLE;
+			}
+		}
+	}
+
+	for (i = 0; i < 24; i++)
+		hdmi_writeb(hdmi, HDMI_VIDEO_CSC_COEF + i,

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 315

Quoted 10 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +10 -0
+			    coeff_csc[csc_mode][i]);
+
+	value = v_SOF_DISABLE | csc_enable | v_COLOR_DEPTH_NOT_INDICATED(1);
+	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);
+	hdmi_modb(hdmi, HDMI_VIDEO_CONTRL, m_VIDEO_AUTO_CSC |
+		  m_VIDEO_C0_C2_SWAP, v_VIDEO_AUTO_CSC(auto_csc) |
+		  v_VIDEO_C0_C2_SWAP(c0_c2_change));
+
+	return 0;
+}

Is CSC also optional?

Quoted 35 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +35 -0
+
+static int inno_hdmi_rockchip_config_video_timing(struct inno_hdmi *hdmi,
+						  struct drm_display_mode *mode)
+{
+	int value;
+
+	/* Set detail external video timing polarity and interlace mode */
+	value = v_EXTERANL_VIDEO(1);
+	value |= mode->flags & DRM_MODE_FLAG_PHSYNC ?
+		 v_HSYNC_POLARITY(1) : v_HSYNC_POLARITY(0);
+	value |= mode->flags & DRM_MODE_FLAG_PVSYNC ?
+		 v_VSYNC_POLARITY(1) : v_VSYNC_POLARITY(0);
+	value |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
+		 v_INETLACE(1) : v_INETLACE(0);
+	hdmi_writeb(hdmi, HDMI_VIDEO_TIMING_CTL, value);
+
+	/* Set detail external video timing */
+	value = mode->htotal;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_H, (value >> 8) & 0xFF);
+
+	value = mode->htotal - mode->hdisplay;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_H, (value >> 8) & 0xFF);
+
+	value = mode->htotal - mode->hsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_H, (value >> 8) & 0xFF);
+
+	value = mode->hsync_end - mode->hsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_H, (value >> 8) & 0xFF);
+
+	value = mode->vtotal;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_L, value & 0xFF);

drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c line 360

Quoted 10 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +10 -0
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_H, (value >> 8) & 0xFF);
+
+	value = mode->vtotal - mode->vdisplay;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VBLANK, value & 0xFF);
+
+	value = mode->vtotal - mode->vsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDELAY, value & 0xFF);
+
+	value = mode->vsync_end - mode->vsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDURATION, value & 0xFF);

This code has a lot in common with your SF driver implementation. Please don't duplicate it.

Quoted 1,430 lines
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c new file +330 -0
+
+	hdmi_writeb(hdmi, HDMI_PHY_PRE_DIV_RATIO, 0x1e);
+	hdmi_writeb(hdmi, HDMI_PHY_FEEDBACK_DIV_RATIO_LOW, 0x2c);
+	hdmi_writeb(hdmi, HDMI_PHY_FEEDBACK_DIV_RATIO_HIGH, 0x01);
+
+	return 0;
+}
+
+static int inno_hdmi_rockchip_setup(struct rockchip_inno_hdmi *rk_hdmi,
+				    struct drm_atomic_state *state)
+{
+	struct inno_hdmi *hdmi = &rk_hdmi->inno_hdmi;
+	struct drm_connector *connector = rk_hdmi->connector;
+	struct drm_display_info *display = &connector->display_info;
+	struct drm_connector_state *new_conn_state;
+	struct drm_crtc_state *new_crtc_state;
+
+	new_conn_state = drm_atomic_get_new_connector_state(state, connector);
+	if (WARN_ON(!new_conn_state))
+		return -EINVAL;
+
+	new_crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
+	if (WARN_ON(!new_crtc_state))
+		return -EINVAL;
+
+	/* Mute video and audio output */
+	hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
+		  v_AUDIO_MUTE(1) | v_VIDEO_MUTE(1));
+
+	/* Set HDMI Mode */
+	hdmi_writeb(hdmi, HDMI_HDCP_CTRL,
+		    v_HDMI_DVI(display->is_hdmi));
+
+	inno_hdmi_rockchip_config_video_timing(hdmi, &new_crtc_state->adjusted_mode);
+
+	inno_hdmi_rockchip_config_video_csc(rk_hdmi);
+
+	drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
+
+	/*
+	 * When IP controller have configured to an accurate video
+	 * timing, then the TMDS clock source would be switched to
+	 * DCLK_LCDC, so we need to init the TMDS rate to mode pixel
+	 * clock rate, and reconfigure the DDC clock.
+	 */
+	inno_hdmi_i2c_init(hdmi, new_conn_state->hdmi.tmds_char_rate);
+
+	/* Unmute video and audio output */
+	hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
+		  v_AUDIO_MUTE(0) | v_VIDEO_MUTE(0));
+
+	inno_hdmi_rockchip_power_up(rk_hdmi, new_conn_state->hdmi.tmds_char_rate);
+
+	return 0;
+}
+
+static enum drm_mode_status inno_hdmi_rockchip_mode_valid(struct inno_hdmi *hdmi,
+							  const struct drm_display_mode *mode)
+{
+	unsigned long mpixelclk, max_tolerance;
+	long rounded_refclk;
+	struct rockchip_inno_hdmi *rk_hdmi = inno_hdmi_to_rk_hdmi(hdmi);
+
+	/* No support for double-clock modes */
+	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
+		return MODE_BAD;
+
+	mpixelclk = mode->clock * 1000;
+
+	if (mpixelclk < INNO_HDMI_MIN_TMDS_CLOCK)
+		return MODE_CLOCK_LOW;
+
+	if (inno_hdmi_rockchip_find_phy_config(rk_hdmi, mpixelclk) < 0)
+		return MODE_CLOCK_HIGH;
+
+	if (rk_hdmi->refclk) {
+		rounded_refclk = clk_round_rate(rk_hdmi->refclk, mpixelclk);
+		if (rounded_refclk < 0)
+			return MODE_BAD;
+
+		/* Vesa DMT standard mentions +/- 0.5% max tolerance */
+		max_tolerance = mpixelclk / 200;
+		if (abs_diff((unsigned long)rounded_refclk, mpixelclk) > max_tolerance)
+			return MODE_NOCLOCK;
+	}
+
+	return MODE_OK;
+}
+
+static void inno_hdmi_rockchip_encoder_enable(struct drm_encoder *encoder,
+					      struct drm_atomic_state *state)
+{
+	struct rockchip_inno_hdmi *rk_hdmi = encoder_to_rk_hdmi(encoder);
+
+	inno_hdmi_rockchip_setup(rk_hdmi, state);
+}
+
+static void inno_hdmi_rockchip_encoder_disable(struct drm_encoder *encoder,
+					       struct drm_atomic_state *state)
+{
+	struct rockchip_inno_hdmi *rk_hdmi = encoder_to_rk_hdmi(encoder);
+
+	inno_hdmi_rockchip_standby(&rk_hdmi->inno_hdmi);
+}
+
+static int
+inno_hdmi_rockchip_encoder_atomic_check(struct drm_encoder *encoder,
+					struct drm_crtc_state *crtc_state,
+					struct drm_connector_state *conn_state)
+{
+	struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
+	struct drm_display_mode *mode = &crtc_state->adjusted_mode;
+	u8 vic = drm_match_cea_mode(mode);
+	struct rockchip_inno_hdmi *rk_hdmi = encoder_to_rk_hdmi(encoder);
+
+	s->output_mode = ROCKCHIP_OUT_MODE_P888;
+	s->output_type = DRM_MODE_CONNECTOR_HDMIA;
+
+	if (vic == 6 || vic == 7 ||
+	    vic == 21 || vic == 22 ||
+	    vic == 2 || vic == 3 ||
+	    vic == 17 || vic == 18)
+		rk_hdmi->colorimetry = HDMI_COLORIMETRY_ITU_601;
+	else
+		rk_hdmi->colorimetry = HDMI_COLORIMETRY_ITU_709;
+
+	return 0;
+}
+
+static const struct drm_encoder_helper_funcs inno_hdmi_rockchip_encoder_helper_funcs = {
+	.atomic_check	= inno_hdmi_rockchip_encoder_atomic_check,
+	.atomic_enable	= inno_hdmi_rockchip_encoder_enable,
+	.atomic_disable	= inno_hdmi_rockchip_encoder_disable,
+};
+
+static int inno_hdmi_rockchip_register(struct drm_device *drm, struct inno_hdmi *hdmi)
+{
+	struct rockchip_inno_hdmi *rk_hdmi = inno_hdmi_to_rk_hdmi(hdmi);
+	struct drm_encoder *encoder = &rk_hdmi->encoder.encoder;
+	struct device *dev = hdmi->dev;
+	int ret;
+
+	encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
+
+	/*
+	 * If we failed to find the CRTC(s) which this encoder is
+	 * supposed to be connected to, it's because the CRTC has
+	 * not been registered yet.  Defer probing, and hope that
+	 * the required CRTC is added later.
+	 */
+	if (encoder->possible_crtcs == 0)
+		return -EPROBE_DEFER;
+
+	drm_encoder_helper_add(encoder, &inno_hdmi_rockchip_encoder_helper_funcs);
+	drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_TMDS);
+
+	ret = inno_hdmi_bind(drm, hdmi, encoder);
+	if (ret)
+		goto err_cleanup_encoder;
+
+	ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+	if (ret)
+		goto err_cleanup_encoder;
+
+	rk_hdmi->connector = drm_bridge_connector_init(drm, encoder);
+	if (IS_ERR(rk_hdmi->connector)) {
+		dev_err(dev, "Unable to create bridge connector\n");
+		ret = PTR_ERR(rk_hdmi->connector);
+		return ret;
+	}
+
+	drm_connector_attach_encoder(rk_hdmi->connector, encoder);
+
+	return 0;
+
+err_cleanup_encoder:
+	drm_encoder_cleanup(encoder);
+	return ret;
+}
+
+static int inno_hdmi_rockchip_bind(struct device *dev, struct device *master, void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct drm_device *drm = data;
+	struct rockchip_inno_hdmi *rk_hdmi;
+	struct inno_hdmi *hdmi;
+	const struct inno_hdmi_rockchip_variant *variant;
+	int ret;
+
+	rk_hdmi = devm_kzalloc(dev, sizeof(*rk_hdmi), GFP_KERNEL);
+	if (!rk_hdmi)
+		return -ENOMEM;
+
+	rk_hdmi->dev = dev;
+	hdmi = &rk_hdmi->inno_hdmi;
+	hdmi->dev = dev;
+
+	variant = of_device_get_match_data(hdmi->dev);
+	if (!variant)
+		return -EINVAL;
+
+	rk_hdmi->variant = variant;
+	hdmi->plat_data = variant->plat_data;
+
+	hdmi->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(hdmi->regs))
+		return PTR_ERR(hdmi->regs);
+
+	rk_hdmi->pclk = devm_clk_get(hdmi->dev, "pclk");
+	if (IS_ERR(rk_hdmi->pclk)) {
+		DRM_DEV_ERROR(rk_hdmi->dev, "Unable to get HDMI pclk clk\n");
+		return PTR_ERR(rk_hdmi->pclk);
+	}
+
+	ret = clk_prepare_enable(rk_hdmi->pclk);
+	if (ret) {
+		DRM_DEV_ERROR(rk_hdmi->dev,
+			      "Cannot enable HDMI pclk clock: %d\n", ret);
+		return ret;
+	}
+
+	rk_hdmi->refclk = devm_clk_get_optional(rk_hdmi->dev, "ref");
+	if (IS_ERR(rk_hdmi->refclk)) {
+		DRM_DEV_ERROR(rk_hdmi->dev, "Unable to get HDMI reference clock\n");
+		ret = PTR_ERR(rk_hdmi->refclk);
+		goto err_disable_pclk;
+	}
+
+	ret = clk_prepare_enable(rk_hdmi->refclk);
+	if (ret) {
+		DRM_DEV_ERROR(rk_hdmi->dev,
+			      "Cannot enable HDMI reference clock: %d\n", ret);
+		goto err_disable_pclk;
+	}
+
+	inno_hdmi_rockchip_reset(hdmi);
+
+	/*
+	 * When the controller isn't configured to an accurate
+	 * video timing and there is no reference clock available,
+	 * then the TMDS clock source would be switched to PCLK_HDMI,
+	 * so we need to init the TMDS rate to PCLK rate, and
+	 * reconfigure the DDC clock.
+	 */
+	if (rk_hdmi->refclk)
+		inno_hdmi_i2c_init(hdmi, clk_get_rate(rk_hdmi->refclk));
+	else
+		inno_hdmi_i2c_init(hdmi, clk_get_rate(rk_hdmi->pclk));
+
+	ret = inno_hdmi_rockchip_register(drm, hdmi);
+	if (ret)
+		goto err_disable_clk;
+
+	dev_set_drvdata(dev, hdmi);
+
+	return 0;
+
+err_disable_clk:
+	clk_disable_unprepare(rk_hdmi->refclk);
+err_disable_pclk:
+	clk_disable_unprepare(rk_hdmi->pclk);
+	return ret;
+}
+
+static void inno_hdmi_rockchip_unbind(struct device *dev, struct device *master,
+			     void *data)
+{
+	struct inno_hdmi *hdmi = dev_get_drvdata(dev);
+	struct rockchip_inno_hdmi *rk_hdmi = inno_hdmi_to_rk_hdmi(hdmi);
+
+	rk_hdmi->encoder.encoder.funcs->destroy(&rk_hdmi->encoder.encoder);
+
+	clk_disable_unprepare(rk_hdmi->refclk);
+	clk_disable_unprepare(rk_hdmi->pclk);
+}
+
+static const struct component_ops inno_hdmi_rockchip_ops = {
+	.bind	= inno_hdmi_rockchip_bind,
+	.unbind	= inno_hdmi_rockchip_unbind,
+};
+
+static int inno_hdmi_rockchip_probe(struct platform_device *pdev)
+{
+	return component_add(&pdev->dev, &inno_hdmi_rockchip_ops);
+}
+
+static void inno_hdmi_rockchip_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &inno_hdmi_rockchip_ops);
+}
+
+const struct inno_hdmi_plat_data data_inno = {
+	.vendor = "Rockchip",
+	.product = "Inno HDMI",
+	.mode_valid = inno_hdmi_rockchip_mode_valid,
+	.hdmi_clear_infoframe = inno_hdmi_rockchip_disable_frame,
+	.hdmi_write_infoframe = inno_hdmi_rockchip_upload_frame,
+};
+
+static const struct inno_hdmi_rockchip_variant rk3036_inno_hdmi_variant = {
+	.phy_configs = rk3036_hdmi_phy_configs,
+	.default_phy_config = &rk3036_hdmi_phy_configs[1],
+	.plat_data = &data_inno,
+};
+
+static const struct inno_hdmi_rockchip_variant rk3128_inno_hdmi_variant = {
+	.phy_configs = rk3128_hdmi_phy_configs,
+	.default_phy_config = &rk3128_hdmi_phy_configs[1],
+	.plat_data = &data_inno,
+};
+
+static const struct of_device_id inno_hdmi_dt_ids[] = {
+	{ .compatible = "rockchip,rk3036-inno-hdmi",
+	  .data = &rk3036_inno_hdmi_variant,
+	},
+	{ .compatible = "rockchip,rk3128-inno-hdmi",
+	  .data = &rk3128_inno_hdmi_variant,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, inno_hdmi_dt_ids);
+
+struct platform_driver inno_hdmi_driver = {
+	.probe  = inno_hdmi_rockchip_probe,
+	.remove_new = inno_hdmi_rockchip_remove,
+	.driver = {
+		.name = "innohdmi-rockchip",
+		.of_match_table = inno_hdmi_dt_ids,
+	},
+};
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.h renamed from drivers/gpu/drm/rockchip/inno_hdmi.h +0 -0
similarity index 100%
rename from drivers/gpu/drm/rockchip/inno_hdmi.h
rename to drivers/gpu/drm/rockchip/inno_hdmi-rockchip.h
drivers/gpu/drm/rockchip/inno_hdmi.c deleted +0 -1025
deleted file mode 100644
index 42ef62aa0a1e..000000000000
@@ -1,1025 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
- *    Zheng Yang <[email protected]>
- *    Yakir Yang <[email protected]>
- */
-
-#include <linux/irq.h>
-#include <linux/clk.h>
-#include <linux/delay.h>
-#include <linux/err.h>
-#include <linux/hdmi.h>
-#include <linux/mod_devicetable.h>
-#include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/platform_device.h>
-
-#include <drm/drm_atomic.h>
-#include <drm/drm_atomic_helper.h>
-#include <drm/drm_edid.h>
-#include <drm/drm_of.h>
-#include <drm/drm_probe_helper.h>
-#include <drm/drm_simple_kms_helper.h>
-
-#include <drm/display/drm_hdmi_helper.h>
-#include <drm/display/drm_hdmi_state_helper.h>
-
-#include "rockchip_drm_drv.h"
-
-#include "inno_hdmi.h"
-
-#define INNO_HDMI_MIN_TMDS_CLOCK  25000000U
-
-struct inno_hdmi_phy_config {
-	unsigned long pixelclock;
-	u8 pre_emphasis;
-	u8 voltage_level_control;
-};
-
-struct inno_hdmi_variant {
-	struct inno_hdmi_phy_config *phy_configs;
-	struct inno_hdmi_phy_config *default_phy_config;
-};
-
-struct inno_hdmi_i2c {
-	struct i2c_adapter adap;
-
-	u8 ddc_addr;
-	u8 segment_addr;
-
-	struct mutex lock;
-	struct completion cmp;
-};
-
-struct inno_hdmi {
-	struct device *dev;
-
-	struct clk *pclk;
-	struct clk *refclk;
-	void __iomem *regs;
-
-	struct drm_connector	connector;
-	struct rockchip_encoder	encoder;
-
-	struct inno_hdmi_i2c *i2c;
-	struct i2c_adapter *ddc;
-
-	const struct inno_hdmi_variant *variant;
-};
-
-struct inno_hdmi_connector_state {
-	struct drm_connector_state	base;
-	unsigned int			colorimetry;
-};
-
-static struct inno_hdmi *encoder_to_inno_hdmi(struct drm_encoder *encoder)
-{
-	struct rockchip_encoder *rkencoder = to_rockchip_encoder(encoder);
-
-	return container_of(rkencoder, struct inno_hdmi, encoder);
-}
-
-static struct inno_hdmi *connector_to_inno_hdmi(struct drm_connector *connector)
-{
-	return container_of(connector, struct inno_hdmi, connector);
-}
-
-#define to_inno_hdmi_conn_state(conn_state) \
-	container_of_const(conn_state, struct inno_hdmi_connector_state, base)
-
-enum {
-	CSC_RGB_0_255_TO_ITU601_16_235_8BIT,
-	CSC_RGB_0_255_TO_ITU709_16_235_8BIT,
-	CSC_RGB_0_255_TO_RGB_16_235_8BIT,
-};
-
-static const char coeff_csc[][24] = {
-	/*
-	 * RGB2YUV:601 SD mode:
-	 *   Cb = -0.291G - 0.148R + 0.439B + 128
-	 *   Y  = 0.504G  + 0.257R + 0.098B + 16
-	 *   Cr = -0.368G + 0.439R - 0.071B + 128
-	 */
-	{
-		0x11, 0x5f, 0x01, 0x82, 0x10, 0x23, 0x00, 0x80,
-		0x02, 0x1c, 0x00, 0xa1, 0x00, 0x36, 0x00, 0x1e,
-		0x11, 0x29, 0x10, 0x59, 0x01, 0x82, 0x00, 0x80
-	},
-	/*
-	 * RGB2YUV:709 HD mode:
-	 *   Cb = - 0.338G - 0.101R + 0.439B + 128
-	 *   Y  = 0.614G   + 0.183R + 0.062B + 16
-	 *   Cr = - 0.399G + 0.439R - 0.040B + 128
-	 */
-	{
-		0x11, 0x98, 0x01, 0xc1, 0x10, 0x28, 0x00, 0x80,
-		0x02, 0x74, 0x00, 0xbb, 0x00, 0x3f, 0x00, 0x10,
-		0x11, 0x5a, 0x10, 0x67, 0x01, 0xc1, 0x00, 0x80
-	},
-	/*
-	 * RGB[0:255]2RGB[16:235]:
-	 *   R' = R x (235-16)/255 + 16;
-	 *   G' = G x (235-16)/255 + 16;
-	 *   B' = B x (235-16)/255 + 16;
-	 */
-	{
-		0x00, 0x00, 0x03, 0x6F, 0x00, 0x00, 0x00, 0x10,
-		0x03, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
-		0x00, 0x00, 0x00, 0x00, 0x03, 0x6F, 0x00, 0x10
-	},
-};
-
-static struct inno_hdmi_phy_config rk3036_hdmi_phy_configs[] = {
-	{  74250000, 0x3f, 0xbb },
-	{ 165000000, 0x6f, 0xbb },
-	{      ~0UL, 0x00, 0x00 }
-};
-
-static struct inno_hdmi_phy_config rk3128_hdmi_phy_configs[] = {
-	{  74250000, 0x3f, 0xaa },
-	{ 165000000, 0x5f, 0xaa },
-	{      ~0UL, 0x00, 0x00 }
-};
-
-static int inno_hdmi_find_phy_config(struct inno_hdmi *hdmi,
-				     unsigned long pixelclk)
-{
-	const struct inno_hdmi_phy_config *phy_configs =
-						hdmi->variant->phy_configs;
-	int i;
-
-	for (i = 0; phy_configs[i].pixelclock != ~0UL; i++) {
-		if (pixelclk <= phy_configs[i].pixelclock)
-			return i;
-	}
-
-	DRM_DEV_DEBUG(hdmi->dev, "No phy configuration for pixelclock %lu\n",
-		      pixelclk);
-
-	return -EINVAL;
-}
-
-static inline u8 hdmi_readb(struct inno_hdmi *hdmi, u16 offset)
-{
-	return readl_relaxed(hdmi->regs + (offset) * 0x04);
-}
-
-static inline void hdmi_writeb(struct inno_hdmi *hdmi, u16 offset, u32 val)
-{
-	writel_relaxed(val, hdmi->regs + (offset) * 0x04);
-}
-
-static inline void hdmi_modb(struct inno_hdmi *hdmi, u16 offset,
-			     u32 msk, u32 val)
-{
-	u8 temp = hdmi_readb(hdmi, offset) & ~msk;
-
-	temp |= val & msk;
-	hdmi_writeb(hdmi, offset, temp);
-}
-
-static void inno_hdmi_i2c_init(struct inno_hdmi *hdmi, unsigned long long rate)
-{
-	unsigned long long ddc_bus_freq = rate >> 2;
-
-	do_div(ddc_bus_freq, HDMI_SCL_RATE);
-
-	hdmi_writeb(hdmi, DDC_BUS_FREQ_L, ddc_bus_freq & 0xFF);
-	hdmi_writeb(hdmi, DDC_BUS_FREQ_H, (ddc_bus_freq >> 8) & 0xFF);
-
-	/* Clear the EDID interrupt flag and mute the interrupt */
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, 0);
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
-}
-
-static void inno_hdmi_sys_power(struct inno_hdmi *hdmi, bool enable)
-{
-	if (enable)
-		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_ON);
-	else
-		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_OFF);
-}
-
-static void inno_hdmi_standby(struct inno_hdmi *hdmi)
-{
-	inno_hdmi_sys_power(hdmi, false);
-
-	hdmi_writeb(hdmi, HDMI_PHY_DRIVER, 0x00);
-	hdmi_writeb(hdmi, HDMI_PHY_PRE_EMPHASIS, 0x00);
-	hdmi_writeb(hdmi, HDMI_PHY_CHG_PWR, 0x00);
-	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x15);
-};
-
-static void inno_hdmi_power_up(struct inno_hdmi *hdmi,
-			       unsigned long mpixelclock)
-{
-	struct inno_hdmi_phy_config *phy_config;
-	int ret = inno_hdmi_find_phy_config(hdmi, mpixelclock);
-
-	if (ret < 0) {
-		phy_config = hdmi->variant->default_phy_config;
-		DRM_DEV_ERROR(hdmi->dev,
-			      "Using default phy configuration for TMDS rate %lu",
-			      mpixelclock);
-	} else {
-		phy_config = &hdmi->variant->phy_configs[ret];
-	}
-
-	inno_hdmi_sys_power(hdmi, false);
-
-	hdmi_writeb(hdmi, HDMI_PHY_PRE_EMPHASIS, phy_config->pre_emphasis);
-	hdmi_writeb(hdmi, HDMI_PHY_DRIVER, phy_config->voltage_level_control);
-	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x15);
-	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x14);
-	hdmi_writeb(hdmi, HDMI_PHY_SYS_CTL, 0x10);
-	hdmi_writeb(hdmi, HDMI_PHY_CHG_PWR, 0x0f);
-	hdmi_writeb(hdmi, HDMI_PHY_SYNC, 0x00);
-	hdmi_writeb(hdmi, HDMI_PHY_SYNC, 0x01);
-
-	inno_hdmi_sys_power(hdmi, true);
-};
-
-static void inno_hdmi_reset(struct inno_hdmi *hdmi)
-{
-	u32 val;
-	u32 msk;
-
-	hdmi_modb(hdmi, HDMI_SYS_CTRL, m_RST_DIGITAL, v_NOT_RST_DIGITAL);
-	udelay(100);
-
-	hdmi_modb(hdmi, HDMI_SYS_CTRL, m_RST_ANALOG, v_NOT_RST_ANALOG);
-	udelay(100);
-
-	msk = m_REG_CLK_INV | m_REG_CLK_SOURCE | m_POWER | m_INT_POL;
-	val = v_REG_CLK_INV | v_REG_CLK_SOURCE_SYS | v_PWR_ON | v_INT_POL_HIGH;
-	hdmi_modb(hdmi, HDMI_SYS_CTRL, msk, val);
-
-	inno_hdmi_standby(hdmi);
-}
-
-static int inno_hdmi_disable_frame(struct drm_connector *connector,
-				   enum hdmi_infoframe_type type)
-{
-	struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
-
-	if (type != HDMI_INFOFRAME_TYPE_AVI) {
-		drm_err(connector->dev,
-			"Unsupported infoframe type: %u\n", type);
-		return 0;
-	}
-
-	hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_BUF_INDEX, INFOFRAME_AVI);
-
-	return 0;
-}
-
-static int inno_hdmi_upload_frame(struct drm_connector *connector,
-				  enum hdmi_infoframe_type type,
-				  const u8 *buffer, size_t len)
-{
-	struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
-	ssize_t i;
-
-	if (type != HDMI_INFOFRAME_TYPE_AVI) {
-		drm_err(connector->dev,
-			"Unsupported infoframe type: %u\n", type);
-		return 0;
-	}
-
-	inno_hdmi_disable_frame(connector, type);
-
-	for (i = 0; i < len; i++)
-		hdmi_writeb(hdmi, HDMI_CONTROL_PACKET_ADDR + i, buffer[i]);
-
-	return 0;
-}
-
-static const struct drm_connector_hdmi_funcs inno_hdmi_hdmi_connector_funcs = {
-	.clear_infoframe	= inno_hdmi_disable_frame,
-	.write_infoframe	= inno_hdmi_upload_frame,
-};
-
-static int inno_hdmi_config_video_csc(struct inno_hdmi *hdmi)
-{
-	struct drm_connector *connector = &hdmi->connector;
-	struct drm_connector_state *conn_state = connector->state;
-	struct inno_hdmi_connector_state *inno_conn_state =
-					to_inno_hdmi_conn_state(conn_state);
-	int c0_c2_change = 0;
-	int csc_enable = 0;
-	int csc_mode = 0;
-	int auto_csc = 0;
-	int value;
-	int i;
-
-	/* Input video mode is SDR RGB24bit, data enable signal from external */
-	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL1, v_DE_EXTERNAL |
-		    v_VIDEO_INPUT_FORMAT(VIDEO_INPUT_SDR_RGB444));
-
-	/* Input color hardcode to RGB, and output color hardcode to RGB888 */
-	value = v_VIDEO_INPUT_BITS(VIDEO_INPUT_8BITS) |
-		v_VIDEO_OUTPUT_COLOR(0) |
-		v_VIDEO_INPUT_CSP(0);
-	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL2, value);
-
-	if (conn_state->hdmi.output_format == HDMI_COLORSPACE_RGB) {
-		if (conn_state->hdmi.is_limited_range) {
-			csc_mode = CSC_RGB_0_255_TO_RGB_16_235_8BIT;
-			auto_csc = AUTO_CSC_DISABLE;
-			c0_c2_change = C0_C2_CHANGE_DISABLE;
-			csc_enable = v_CSC_ENABLE;
-
-		} else {
-			value = v_SOF_DISABLE | v_COLOR_DEPTH_NOT_INDICATED(1);
-			hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);
-
-			hdmi_modb(hdmi, HDMI_VIDEO_CONTRL,
-				  m_VIDEO_AUTO_CSC | m_VIDEO_C0_C2_SWAP,
-				  v_VIDEO_AUTO_CSC(AUTO_CSC_DISABLE) |
-				  v_VIDEO_C0_C2_SWAP(C0_C2_CHANGE_DISABLE));
-			return 0;
-		}
-	} else {
-		if (inno_conn_state->colorimetry == HDMI_COLORIMETRY_ITU_601) {
-			if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {
-				csc_mode = CSC_RGB_0_255_TO_ITU601_16_235_8BIT;
-				auto_csc = AUTO_CSC_DISABLE;
-				c0_c2_change = C0_C2_CHANGE_DISABLE;
-				csc_enable = v_CSC_ENABLE;
-			}
-		} else {
-			if (conn_state->hdmi.output_format == HDMI_COLORSPACE_YUV444) {
-				csc_mode = CSC_RGB_0_255_TO_ITU709_16_235_8BIT;
-				auto_csc = AUTO_CSC_DISABLE;
-				c0_c2_change = C0_C2_CHANGE_DISABLE;
-				csc_enable = v_CSC_ENABLE;
-			}
-		}
-	}
-
-	for (i = 0; i < 24; i++)
-		hdmi_writeb(hdmi, HDMI_VIDEO_CSC_COEF + i,
-			    coeff_csc[csc_mode][i]);
-
-	value = v_SOF_DISABLE | csc_enable | v_COLOR_DEPTH_NOT_INDICATED(1);
-	hdmi_writeb(hdmi, HDMI_VIDEO_CONTRL3, value);
-	hdmi_modb(hdmi, HDMI_VIDEO_CONTRL, m_VIDEO_AUTO_CSC |
-		  m_VIDEO_C0_C2_SWAP, v_VIDEO_AUTO_CSC(auto_csc) |
-		  v_VIDEO_C0_C2_SWAP(c0_c2_change));
-
-	return 0;
-}
-
-static int inno_hdmi_config_video_timing(struct inno_hdmi *hdmi,
-					 struct drm_display_mode *mode)
-{
-	int value;
-
-	/* Set detail external video timing polarity and interlace mode */
-	value = v_EXTERANL_VIDEO(1);
-	value |= mode->flags & DRM_MODE_FLAG_PHSYNC ?
-		 v_HSYNC_POLARITY(1) : v_HSYNC_POLARITY(0);
-	value |= mode->flags & DRM_MODE_FLAG_PVSYNC ?
-		 v_VSYNC_POLARITY(1) : v_VSYNC_POLARITY(0);
-	value |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
-		 v_INETLACE(1) : v_INETLACE(0);
-	hdmi_writeb(hdmi, HDMI_VIDEO_TIMING_CTL, value);
-
-	/* Set detail external video timing */
-	value = mode->htotal;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_L, value & 0xFF);
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_H, (value >> 8) & 0xFF);
-
-	value = mode->htotal - mode->hdisplay;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_L, value & 0xFF);
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_H, (value >> 8) & 0xFF);
-
-	value = mode->htotal - mode->hsync_start;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_L, value & 0xFF);
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_H, (value >> 8) & 0xFF);
-
-	value = mode->hsync_end - mode->hsync_start;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_L, value & 0xFF);
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_H, (value >> 8) & 0xFF);
-
-	value = mode->vtotal;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_L, value & 0xFF);
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_H, (value >> 8) & 0xFF);
-
-	value = mode->vtotal - mode->vdisplay;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VBLANK, value & 0xFF);
-
-	value = mode->vtotal - mode->vsync_start;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDELAY, value & 0xFF);
-
-	value = mode->vsync_end - mode->vsync_start;
-	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDURATION, value & 0xFF);
-
-	hdmi_writeb(hdmi, HDMI_PHY_PRE_DIV_RATIO, 0x1e);
-	hdmi_writeb(hdmi, HDMI_PHY_FEEDBACK_DIV_RATIO_LOW, 0x2c);
-	hdmi_writeb(hdmi, HDMI_PHY_FEEDBACK_DIV_RATIO_HIGH, 0x01);
-
-	return 0;
-}
-
-static int inno_hdmi_setup(struct inno_hdmi *hdmi,
-			   struct drm_atomic_state *state)
-{
-	struct drm_connector *connector = &hdmi->connector;
-	struct drm_display_info *display = &connector->display_info;
-	struct drm_connector_state *new_conn_state;
-	struct drm_crtc_state *new_crtc_state;
-
-	new_conn_state = drm_atomic_get_new_connector_state(state, connector);
-	if (WARN_ON(!new_conn_state))
-		return -EINVAL;
-
-	new_crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
-	if (WARN_ON(!new_crtc_state))
-		return -EINVAL;
-
-	/* Mute video and audio output */
-	hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
-		  v_AUDIO_MUTE(1) | v_VIDEO_MUTE(1));
-
-	/* Set HDMI Mode */
-	hdmi_writeb(hdmi, HDMI_HDCP_CTRL,
-		    v_HDMI_DVI(display->is_hdmi));
-
-	inno_hdmi_config_video_timing(hdmi, &new_crtc_state->adjusted_mode);
-
-	inno_hdmi_config_video_csc(hdmi);
-
-	drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
-
-	/*
-	 * When IP controller have configured to an accurate video
-	 * timing, then the TMDS clock source would be switched to
-	 * DCLK_LCDC, so we need to init the TMDS rate to mode pixel
-	 * clock rate, and reconfigure the DDC clock.
-	 */
-	inno_hdmi_i2c_init(hdmi, new_conn_state->hdmi.tmds_char_rate);
-
-	/* Unmute video and audio output */
-	hdmi_modb(hdmi, HDMI_AV_MUTE, m_AUDIO_MUTE | m_VIDEO_BLACK,
-		  v_AUDIO_MUTE(0) | v_VIDEO_MUTE(0));
-
-	inno_hdmi_power_up(hdmi, new_conn_state->hdmi.tmds_char_rate);
-
-	return 0;
-}
-
-static enum drm_mode_status inno_hdmi_display_mode_valid(struct inno_hdmi *hdmi,
-							 struct drm_display_mode *mode)
-{
-	unsigned long mpixelclk, max_tolerance;
-	long rounded_refclk;
-
-	/* No support for double-clock modes */
-	if (mode->flags & DRM_MODE_FLAG_DBLCLK)
-		return MODE_BAD;
-
-	mpixelclk = mode->clock * 1000;
-
-	if (mpixelclk < INNO_HDMI_MIN_TMDS_CLOCK)
-		return MODE_CLOCK_LOW;
-
-	if (inno_hdmi_find_phy_config(hdmi, mpixelclk) < 0)
-		return MODE_CLOCK_HIGH;
-
-	if (hdmi->refclk) {
-		rounded_refclk = clk_round_rate(hdmi->refclk, mpixelclk);
-		if (rounded_refclk < 0)
-			return MODE_BAD;
-
-		/* Vesa DMT standard mentions +/- 0.5% max tolerance */
-		max_tolerance = mpixelclk / 200;
-		if (abs_diff((unsigned long)rounded_refclk, mpixelclk) > max_tolerance)
-			return MODE_NOCLOCK;
-	}
-
-	return MODE_OK;
-}
-
-static void inno_hdmi_encoder_enable(struct drm_encoder *encoder,
-				     struct drm_atomic_state *state)
-{
-	struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder);
-
-	inno_hdmi_setup(hdmi, state);
-}
-
-static void inno_hdmi_encoder_disable(struct drm_encoder *encoder,
-				      struct drm_atomic_state *state)
-{
-	struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder);
-
-	inno_hdmi_standby(hdmi);
-}
-
-static int
-inno_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
-			       struct drm_crtc_state *crtc_state,
-			       struct drm_connector_state *conn_state)
-{
-	struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
-	struct drm_display_mode *mode = &crtc_state->adjusted_mode;
-	u8 vic = drm_match_cea_mode(mode);
-	struct inno_hdmi_connector_state *inno_conn_state =
-					to_inno_hdmi_conn_state(conn_state);
-
-	s->output_mode = ROCKCHIP_OUT_MODE_P888;
-	s->output_type = DRM_MODE_CONNECTOR_HDMIA;
-
-	if (vic == 6 || vic == 7 ||
-	    vic == 21 || vic == 22 ||
-	    vic == 2 || vic == 3 ||
-	    vic == 17 || vic == 18)
-		inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_601;
-	else
-		inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_709;
-
-	return 0;
-}
-
-static const struct drm_encoder_helper_funcs inno_hdmi_encoder_helper_funcs = {
-	.atomic_check	= inno_hdmi_encoder_atomic_check,
-	.atomic_enable	= inno_hdmi_encoder_enable,
-	.atomic_disable	= inno_hdmi_encoder_disable,
-};
-
-static enum drm_connector_status
-inno_hdmi_connector_detect(struct drm_connector *connector, bool force)
-{
-	struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
-
-	return (hdmi_readb(hdmi, HDMI_STATUS) & m_HOTPLUG) ?
-		connector_status_connected : connector_status_disconnected;
-}
-
-static int inno_hdmi_connector_get_modes(struct drm_connector *connector)
-{
-	struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
-	const struct drm_edid *drm_edid;
-	int ret = 0;
-
-	if (!hdmi->ddc)
-		return 0;
-
-	drm_edid = drm_edid_read_ddc(connector, hdmi->ddc);
-	drm_edid_connector_update(connector, drm_edid);
-	ret = drm_edid_connector_add_modes(connector);
-	drm_edid_free(drm_edid);
-
-	return ret;
-}
-
-static enum drm_mode_status
-inno_hdmi_connector_mode_valid(struct drm_connector *connector,
-			       struct drm_display_mode *mode)
-{
-	struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector);
-
-	return  inno_hdmi_display_mode_valid(hdmi, mode);
-}
-
-static void
-inno_hdmi_connector_destroy_state(struct drm_connector *connector,
-				  struct drm_connector_state *state)
-{
-	struct inno_hdmi_connector_state *inno_conn_state =
-						to_inno_hdmi_conn_state(state);
-
-	__drm_atomic_helper_connector_destroy_state(&inno_conn_state->base);
-	kfree(inno_conn_state);
-}
-
-static void inno_hdmi_connector_reset(struct drm_connector *connector)
-{
-	struct inno_hdmi_connector_state *inno_conn_state;
-
-	if (connector->state) {
-		inno_hdmi_connector_destroy_state(connector, connector->state);
-		connector->state = NULL;
-	}
-
-	inno_conn_state = kzalloc(sizeof(*inno_conn_state), GFP_KERNEL);
-	if (!inno_conn_state)
-		return;
-
-	__drm_atomic_helper_connector_reset(connector, &inno_conn_state->base);
-	__drm_atomic_helper_connector_hdmi_reset(connector, connector->state);
-
-	inno_conn_state->colorimetry = HDMI_COLORIMETRY_ITU_709;
-}
-
-static struct drm_connector_state *
-inno_hdmi_connector_duplicate_state(struct drm_connector *connector)
-{
-	struct inno_hdmi_connector_state *inno_conn_state;
-
-	if (WARN_ON(!connector->state))
-		return NULL;
-
-	inno_conn_state = kmemdup(to_inno_hdmi_conn_state(connector->state),
-				  sizeof(*inno_conn_state), GFP_KERNEL);
-
-	if (!inno_conn_state)
-		return NULL;
-
-	__drm_atomic_helper_connector_duplicate_state(connector,
-						      &inno_conn_state->base);
-
-	return &inno_conn_state->base;
-}
-
-static const struct drm_connector_funcs inno_hdmi_connector_funcs = {
-	.fill_modes = drm_helper_probe_single_connector_modes,
-	.detect = inno_hdmi_connector_detect,
-	.reset = inno_hdmi_connector_reset,
-	.atomic_duplicate_state = inno_hdmi_connector_duplicate_state,
-	.atomic_destroy_state = inno_hdmi_connector_destroy_state,
-};
-
-static struct drm_connector_helper_funcs inno_hdmi_connector_helper_funcs = {
-	.atomic_check = drm_atomic_helper_connector_hdmi_check,
-	.get_modes = inno_hdmi_connector_get_modes,
-	.mode_valid = inno_hdmi_connector_mode_valid,
-};
-
-static int inno_hdmi_register(struct drm_device *drm, struct inno_hdmi *hdmi)
-{
-	struct drm_encoder *encoder = &hdmi->encoder.encoder;
-	struct device *dev = hdmi->dev;
-
-	encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
-
-	/*
-	 * If we failed to find the CRTC(s) which this encoder is
-	 * supposed to be connected to, it's because the CRTC has
-	 * not been registered yet.  Defer probing, and hope that
-	 * the required CRTC is added later.
-	 */
-	if (encoder->possible_crtcs == 0)
-		return -EPROBE_DEFER;
-
-	drm_encoder_helper_add(encoder, &inno_hdmi_encoder_helper_funcs);
-	drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_TMDS);
-
-	hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
-
-	drm_connector_helper_add(&hdmi->connector,
-				 &inno_hdmi_connector_helper_funcs);
-	drmm_connector_hdmi_init(drm, &hdmi->connector,
-				 "Rockchip", "Inno HDMI",
-				 &inno_hdmi_connector_funcs,
-				 &inno_hdmi_hdmi_connector_funcs,
-				 DRM_MODE_CONNECTOR_HDMIA,
-				 hdmi->ddc,
-				 BIT(HDMI_COLORSPACE_RGB),
-				 8);
-
-	drm_connector_attach_encoder(&hdmi->connector, encoder);
-
-	return 0;
-}
-
-static irqreturn_t inno_hdmi_i2c_irq(struct inno_hdmi *hdmi)
-{
-	struct inno_hdmi_i2c *i2c = hdmi->i2c;
-	u8 stat;
-
-	stat = hdmi_readb(hdmi, HDMI_INTERRUPT_STATUS1);
-	if (!(stat & m_INT_EDID_READY))
-		return IRQ_NONE;
-
-	/* Clear HDMI EDID interrupt flag */
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
-
-	complete(&i2c->cmp);
-
-	return IRQ_HANDLED;
-}
-
-static irqreturn_t inno_hdmi_hardirq(int irq, void *dev_id)
-{
-	struct inno_hdmi *hdmi = dev_id;
-	irqreturn_t ret = IRQ_NONE;
-	u8 interrupt;
-
-	if (hdmi->i2c)
-		ret = inno_hdmi_i2c_irq(hdmi);
-
-	interrupt = hdmi_readb(hdmi, HDMI_STATUS);
-	if (interrupt & m_INT_HOTPLUG) {
-		hdmi_modb(hdmi, HDMI_STATUS, m_INT_HOTPLUG, m_INT_HOTPLUG);
-		ret = IRQ_WAKE_THREAD;
-	}
-
-	return ret;
-}
-
-static irqreturn_t inno_hdmi_irq(int irq, void *dev_id)
-{
-	struct inno_hdmi *hdmi = dev_id;
-
-	drm_helper_hpd_irq_event(hdmi->connector.dev);
-
-	return IRQ_HANDLED;
-}
-
-static int inno_hdmi_i2c_read(struct inno_hdmi *hdmi, struct i2c_msg *msgs)
-{
-	int length = msgs->len;
-	u8 *buf = msgs->buf;
-	int ret;
-
-	ret = wait_for_completion_timeout(&hdmi->i2c->cmp, HZ / 10);
-	if (!ret)
-		return -EAGAIN;
-
-	while (length--)
-		*buf++ = hdmi_readb(hdmi, HDMI_EDID_FIFO_ADDR);
-
-	return 0;
-}
-
-static int inno_hdmi_i2c_write(struct inno_hdmi *hdmi, struct i2c_msg *msgs)
-{
-	/*
-	 * The DDC module only support read EDID message, so
-	 * we assume that each word write to this i2c adapter
-	 * should be the offset of EDID word address.
-	 */
-	if ((msgs->len != 1) ||
-	    ((msgs->addr != DDC_ADDR) && (msgs->addr != DDC_SEGMENT_ADDR)))
-		return -EINVAL;
-
-	reinit_completion(&hdmi->i2c->cmp);
-
-	if (msgs->addr == DDC_SEGMENT_ADDR)
-		hdmi->i2c->segment_addr = msgs->buf[0];
-	if (msgs->addr == DDC_ADDR)
-		hdmi->i2c->ddc_addr = msgs->buf[0];
-
-	/* Set edid fifo first addr */
-	hdmi_writeb(hdmi, HDMI_EDID_FIFO_OFFSET, 0x00);
-
-	/* Set edid word address 0x00/0x80 */
-	hdmi_writeb(hdmi, HDMI_EDID_WORD_ADDR, hdmi->i2c->ddc_addr);
-
-	/* Set edid segment pointer */
-	hdmi_writeb(hdmi, HDMI_EDID_SEGMENT_POINTER, hdmi->i2c->segment_addr);
-
-	return 0;
-}
-
-static int inno_hdmi_i2c_xfer(struct i2c_adapter *adap,
-			      struct i2c_msg *msgs, int num)
-{
-	struct inno_hdmi *hdmi = i2c_get_adapdata(adap);
-	struct inno_hdmi_i2c *i2c = hdmi->i2c;
-	int i, ret = 0;
-
-	mutex_lock(&i2c->lock);
-
-	/* Clear the EDID interrupt flag and unmute the interrupt */
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, m_INT_EDID_READY);
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_STATUS1, m_INT_EDID_READY);
-
-	for (i = 0; i < num; i++) {
-		DRM_DEV_DEBUG(hdmi->dev,
-			      "xfer: num: %d/%d, len: %d, flags: %#x\n",
-			      i + 1, num, msgs[i].len, msgs[i].flags);
-
-		if (msgs[i].flags & I2C_M_RD)
-			ret = inno_hdmi_i2c_read(hdmi, &msgs[i]);
-		else
-			ret = inno_hdmi_i2c_write(hdmi, &msgs[i]);
-
-		if (ret < 0)
-			break;
-	}
-
-	if (!ret)
-		ret = num;
-
-	/* Mute HDMI EDID interrupt */
-	hdmi_writeb(hdmi, HDMI_INTERRUPT_MASK1, 0);
-
-	mutex_unlock(&i2c->lock);
-
-	return ret;
-}
-
-static u32 inno_hdmi_i2c_func(struct i2c_adapter *adapter)
-{
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
-}
-
-static const struct i2c_algorithm inno_hdmi_algorithm = {
-	.master_xfer	= inno_hdmi_i2c_xfer,
-	.functionality	= inno_hdmi_i2c_func,
-};
-
-static struct i2c_adapter *inno_hdmi_i2c_adapter(struct inno_hdmi *hdmi)
-{
-	struct i2c_adapter *adap;
-	struct inno_hdmi_i2c *i2c;
-	int ret;
-
-	i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL);
-	if (!i2c)
-		return ERR_PTR(-ENOMEM);
-
-	mutex_init(&i2c->lock);
-	init_completion(&i2c->cmp);
-
-	adap = &i2c->adap;
-	adap->owner = THIS_MODULE;
-	adap->dev.parent = hdmi->dev;
-	adap->dev.of_node = hdmi->dev->of_node;
-	adap->algo = &inno_hdmi_algorithm;
-	strscpy(adap->name, "Inno HDMI", sizeof(adap->name));
-	i2c_set_adapdata(adap, hdmi);
-
-	ret = i2c_add_adapter(adap);
-	if (ret) {
-		dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name);
-		devm_kfree(hdmi->dev, i2c);
-		return ERR_PTR(ret);
-	}
-
-	hdmi->i2c = i2c;
-
-	DRM_DEV_INFO(hdmi->dev, "registered %s I2C bus driver\n", adap->name);
-
-	return adap;
-}
-
-static int inno_hdmi_bind(struct device *dev, struct device *master,
-				 void *data)
-{
-	struct platform_device *pdev = to_platform_device(dev);
-	struct drm_device *drm = data;
-	struct inno_hdmi *hdmi;
-	const struct inno_hdmi_variant *variant;
-	int irq;
-	int ret;
-
-	hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
-	if (!hdmi)
-		return -ENOMEM;
-
-	hdmi->dev = dev;
-
-	variant = of_device_get_match_data(hdmi->dev);
-	if (!variant)
-		return -EINVAL;
-
-	hdmi->variant = variant;
-
-	hdmi->regs = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(hdmi->regs))
-		return PTR_ERR(hdmi->regs);
-
-	hdmi->pclk = devm_clk_get(hdmi->dev, "pclk");
-	if (IS_ERR(hdmi->pclk)) {
-		DRM_DEV_ERROR(hdmi->dev, "Unable to get HDMI pclk clk\n");
-		return PTR_ERR(hdmi->pclk);
-	}
-
-	ret = clk_prepare_enable(hdmi->pclk);
-	if (ret) {
-		DRM_DEV_ERROR(hdmi->dev,
-			      "Cannot enable HDMI pclk clock: %d\n", ret);
-		return ret;
-	}
-
-	hdmi->refclk = devm_clk_get_optional(hdmi->dev, "ref");
-	if (IS_ERR(hdmi->refclk)) {
-		DRM_DEV_ERROR(hdmi->dev, "Unable to get HDMI reference clock\n");
-		ret = PTR_ERR(hdmi->refclk);
-		goto err_disable_pclk;
-	}
-
-	ret = clk_prepare_enable(hdmi->refclk);
-	if (ret) {
-		DRM_DEV_ERROR(hdmi->dev,
-			      "Cannot enable HDMI reference clock: %d\n", ret);
-		goto err_disable_pclk;
-	}
-
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		ret = irq;
-		goto err_disable_clk;
-	}
-
-	inno_hdmi_reset(hdmi);
-
-	hdmi->ddc = inno_hdmi_i2c_adapter(hdmi);
-	if (IS_ERR(hdmi->ddc)) {
-		ret = PTR_ERR(hdmi->ddc);
-		hdmi->ddc = NULL;
-		goto err_disable_clk;
-	}
-
-	/*
-	 * When the controller isn't configured to an accurate
-	 * video timing and there is no reference clock available,
-	 * then the TMDS clock source would be switched to PCLK_HDMI,
-	 * so we need to init the TMDS rate to PCLK rate, and
-	 * reconfigure the DDC clock.
-	 */
-	if (hdmi->refclk)
-		inno_hdmi_i2c_init(hdmi, clk_get_rate(hdmi->refclk));
-	else
-		inno_hdmi_i2c_init(hdmi, clk_get_rate(hdmi->pclk));
-
-	ret = inno_hdmi_register(drm, hdmi);
-	if (ret)
-		goto err_put_adapter;
-
-	dev_set_drvdata(dev, hdmi);
-
-	/* Unmute hotplug interrupt */
-	hdmi_modb(hdmi, HDMI_STATUS, m_MASK_INT_HOTPLUG, v_MASK_INT_HOTPLUG(1));
-
-	ret = devm_request_threaded_irq(dev, irq, inno_hdmi_hardirq,
-					inno_hdmi_irq, IRQF_SHARED,
-					dev_name(dev), hdmi);
-	if (ret < 0)
-		goto err_cleanup_hdmi;
-
-	return 0;
-err_cleanup_hdmi:
-	hdmi->connector.funcs->destroy(&hdmi->connector);
-	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
-err_put_adapter:
-	i2c_put_adapter(hdmi->ddc);
-err_disable_clk:
-	clk_disable_unprepare(hdmi->refclk);
-err_disable_pclk:
-	clk_disable_unprepare(hdmi->pclk);
-	return ret;
-}
-
-static void inno_hdmi_unbind(struct device *dev, struct device *master,
-			     void *data)
-{
-	struct inno_hdmi *hdmi = dev_get_drvdata(dev);
-
-	hdmi->connector.funcs->destroy(&hdmi->connector);
-	hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
-
-	i2c_put_adapter(hdmi->ddc);
-	clk_disable_unprepare(hdmi->refclk);
-	clk_disable_unprepare(hdmi->pclk);
-}
-
-static const struct component_ops inno_hdmi_ops = {
-	.bind	= inno_hdmi_bind,
-	.unbind	= inno_hdmi_unbind,
-};
-
-static int inno_hdmi_probe(struct platform_device *pdev)
-{
-	return component_add(&pdev->dev, &inno_hdmi_ops);
-}
-
-static void inno_hdmi_remove(struct platform_device *pdev)
-{
-	component_del(&pdev->dev, &inno_hdmi_ops);
-}
-
-static const struct inno_hdmi_variant rk3036_inno_hdmi_variant = {
-	.phy_configs = rk3036_hdmi_phy_configs,
-	.default_phy_config = &rk3036_hdmi_phy_configs[1],
-};
-
-static const struct inno_hdmi_variant rk3128_inno_hdmi_variant = {
-	.phy_configs = rk3128_hdmi_phy_configs,
-	.default_phy_config = &rk3128_hdmi_phy_configs[1],
-};
-
-static const struct of_device_id inno_hdmi_dt_ids[] = {
-	{ .compatible = "rockchip,rk3036-inno-hdmi",
-	  .data = &rk3036_inno_hdmi_variant,
-	},
-	{ .compatible = "rockchip,rk3128-inno-hdmi",
-	  .data = &rk3128_inno_hdmi_variant,
-	},
-	{},
-};
-MODULE_DEVICE_TABLE(of, inno_hdmi_dt_ids);
-
-struct platform_driver inno_hdmi_driver = {
-	.probe  = inno_hdmi_probe,
-	.remove_new = inno_hdmi_remove,
-	.driver = {
-		.name = "innohdmi-rockchip",
-		.of_match_table = inno_hdmi_dt_ids,
-	},
-};
include/drm/bridge/inno_hdmi.h new file +56 -0
new file mode 100644
index 000000000000..bfd22f180153
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#ifndef __INNO_COMMON_HDMI__
+#define __INNO_COMMON_HDMI__
+
+#include <drm/drm_connector.h>
+#include <drm/drm_encoder.h>
+#include <drm/drm_bridge.h>
+#include <linux/i2c.h>
+
+struct inno_hdmi;
+
+struct inno_hdmi_i2c {
+	u8 ddc_addr;
+	u8 segment_addr;
+
+	struct i2c_adapter adap;
+	struct mutex lock; /* For i2c operation. */
+	struct completion cmp;
+};
+
+struct inno_hdmi_plat_data {
+	const char *vendor;
+	const char *product;
+
+	/* Platform-specific mode validation*/
+	enum drm_mode_status (*mode_valid)(struct inno_hdmi *hdmi,
+					   const struct drm_display_mode *mode);
+	int (*hdmi_clear_infoframe)(struct inno_hdmi *hdmi, enum hdmi_infoframe_type type);
+	int (*hdmi_write_infoframe)(struct inno_hdmi *hdmi, enum hdmi_infoframe_type type,
+				    const u8 *buffer, size_t len);
+};
+
+struct inno_hdmi {
+	struct device *dev;
+	void __iomem *regs;
+
+	struct i2c_adapter *ddc;
+	struct drm_bridge bridge;
+	struct drm_bridge *next_bridge;
+	struct inno_hdmi_i2c *i2c;
+
+	const struct inno_hdmi_plat_data *plat_data;
+};
+
+u8 hdmi_readb(struct inno_hdmi *hdmi, u16 offset);
+void hdmi_writeb(struct inno_hdmi *hdmi, u16 offset, u32 val);
+void hdmi_modb(struct inno_hdmi *hdmi, u16 offset, u32 msk, u32 val);
+
+void inno_hdmi_i2c_init(struct inno_hdmi *hdmi, unsigned long long rate);
+int inno_hdmi_bind(struct drm_device *drm, struct inno_hdmi *hdmi, struct drm_encoder *encoder);
+
+#endif /* __INNO_COMMON_HDMI__ */
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
#14 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

In reply to keith zhao
Quoted 119 lines · keith zhao

move rochchip inno hdmi connector to a newly created directory named inno-hdmi.c, and rename rockchip/inno_hdmi.c to rockchip/inno_hdmi-rockchip.c

This patch refines the Innosilicon HDMI architecture by abstracting the existing connector into a bridge architecture.
The drm_bridge_connector_init function is used to create the connector.

---
 MAINTAINERS                                   |    2 +
 drivers/gpu/drm/bridge/Kconfig                |    2 +
 drivers/gpu/drm/bridge/Makefile               |    1 +
 drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
 drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
 .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
 .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
 drivers/gpu/drm/rockchip/Kconfig              |    1 +
 drivers/gpu/drm/rockchip/Makefile             |    2 +-
 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
 .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
 drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 -----------------
 include/drm/bridge/inno_hdmi.h                |   56 +
 13 files changed, 1171 insertions(+), 1026 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
 create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
 rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
 delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
 create mode 100644 include/drm/bridge/inno_hdmi.h
MAINTAINERS +2 -0
index f787dd625497..7766ee0bdd74 100644
@@ -7439,6 +7439,8 @@ S:	Maintained
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 F:	Documentation/devicetree/bindings/display/starfive/
+F:	drivers/gpu/drm/bridge/innosilicon/
+F:	include/drm/bridge/inno_hdmi.h
 
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
 M:	Michael Trimarchi <[email protected]>
drivers/gpu/drm/bridge/Kconfig +2 -0
index 683cb33805b2..37be5dd5213f 100644
@@ -423,6 +423,8 @@ source "drivers/gpu/drm/bridge/cadence/Kconfig"
 
 source "drivers/gpu/drm/bridge/imx/Kconfig"
 
+source "drivers/gpu/drm/bridge/innosilicon/Kconfig"
+
 source "drivers/gpu/drm/bridge/synopsys/Kconfig"
 
 endmenu
drivers/gpu/drm/bridge/Makefile +1 -0
index 3daf803ce80b..866d1e0fd8aa 100644
@@ -41,4 +41,5 @@ obj-$(CONFIG_DRM_ITE_IT66121) += ite-it66121.o
 obj-y += analogix/
 obj-y += cadence/
 obj-y += imx/
+obj-y += innosilicon/
 obj-y += synopsys/
drivers/gpu/drm/bridge/innosilicon/Kconfig new file +6 -0
new file mode 100644
index 000000000000..73dbed3b1c4d
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config DRM_INNO_HDMI
+	tristate
+	help
+	  Support the common interface which is part of the INNO
+	  Designware HDMI block.
drivers/gpu/drm/bridge/innosilicon/Makefile new file +2 -0
new file mode 100644
index 000000000000..3b3a961ab9fb
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_DRM_INNO_HDMI) += inno-hdmi.o
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +24 -0
new file mode 100644
index 000000000000..c26132b41bdf
@@ -0,0 +1,376 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *    Zheng Yang <[email protected]>
+ *    Yakir Yang <[email protected]>
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#include <drm/bridge/inno_hdmi.h>
+#include <drm/display/drm_hdmi_state_helper.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_of.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>

drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c line 34

Quoted 10 lines
drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c new file +10 -0
+#include <drm/drm_bridge.h>
+#include <drm/drm_bridge_connector.h>
+
+#include "inno-hdmi.h"
+
+u8 hdmi_readb(struct inno_hdmi *hdmi, u16 offset)
+{
+	return readl_relaxed(hdmi->regs + (offset) * 0x04);
+}
+EXPORT_SYMBOL_GPL(hdmi_readb);

Not to mention that hdmi_foo() is too generic. Please use some common prefix through the file. At least inno_hdmi_foo() will be much better.

Signature · 2 lines
With best wishes
Dmitry
#15 lore raw

Re: [PATCH v5 3/9] drm: bridge: inno-hdmi: add inno bridge driver.

In reply to keith zhao
Quoted 38 lines · keith zhao

move rochchip inno hdmi connector to a newly created directory named inno-hdmi.c, and rename rockchip/inno_hdmi.c to rockchip/inno_hdmi-rockchip.c

This patch refines the Innosilicon HDMI architecture by abstracting the existing connector into a bridge architecture.
The drm_bridge_connector_init function is used to create the connector.

---
 MAINTAINERS                                   |    2 +
 drivers/gpu/drm/bridge/Kconfig                |    2 +
 drivers/gpu/drm/bridge/Makefile               |    1 +
 drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
 drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
 .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
 .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
 drivers/gpu/drm/rockchip/Kconfig              |    1 +
 drivers/gpu/drm/rockchip/Makefile             |    2 +-
 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
 .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
 drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 -----------------
 include/drm/bridge/inno_hdmi.h                |   56 +
 13 files changed, 1171 insertions(+), 1026 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
 create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
 create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
 rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
 delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
 create mode 100644 include/drm/bridge/inno_hdmi.h
MAINTAINERS +0 -0
index f787dd625497..7766ee0bdd74 100644

MAINTAINERS S: Maintained · line 7443

Quoted 5 lines
MAINTAINERS +2 -0
@@ -7439,6 +7439,8 @@ S:	Maintained
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 F:	Documentation/devicetree/bindings/display/starfive/
+F:	drivers/gpu/drm/bridge/innosilicon/
+F:	include/drm/bridge/inno_hdmi.h

Separate entry, please. This is not specific to StarFive.

Quoted 3 lines
MAINTAINERS +0 -0
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
 M:	Michael Trimarchi <[email protected]>
Signature · 2 lines
With best wishes
Dmitry
author
#16 lore raw

PATCH v5 4/9 drm/vs: Add Hardware Functions for VS DC8200

In reply to keith zhao

This commit introduces hardware-based APIs for
the VS DRM related to the DC8200

---
 MAINTAINERS                            |    1 +
 drivers/gpu/drm/Kconfig                |    2 +
 drivers/gpu/drm/Makefile               |    1 +
 drivers/gpu/drm/verisilicon/Kconfig    |   13 +
 drivers/gpu/drm/verisilicon/Makefile   |    5 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1104 ++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 +++++++++++
 drivers/gpu/drm/verisilicon/vs_type.h  |   54 ++
 8 files changed, 1672 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h
MAINTAINERS +1 -0
index 7766ee0bdd74..55d6bccdd036 100644
@@ -7440,6 +7440,7 @@ T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml
 F:	Documentation/devicetree/bindings/display/starfive/
 F:	drivers/gpu/drm/bridge/innosilicon/
+F:	drivers/gpu/drm/verisilicon
 F:	include/drm/bridge/inno_hdmi.h
 
 DRM DRIVER FOR SYNAPTICS R63353 PANELS
drivers/gpu/drm/Kconfig +2 -0
index 1df4e627e3d3..0abd0ecbe1e5 100644
@@ -481,6 +481,8 @@ source "drivers/gpu/drm/sprd/Kconfig"
 
 source "drivers/gpu/drm/imagination/Kconfig"
 
+source "drivers/gpu/drm/verisilicon/Kconfig"
+
 config DRM_HYPERV
 	tristate "DRM Support for Hyper-V synthetic video device"
 	depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
index 3894f43f6d47..9450b90d5df1 100644
@@ -223,3 +223,4 @@ obj-y			+= solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
 obj-$(CONFIG_DRM_LOONGSON) += loongson/
 obj-$(CONFIG_DRM_POWERVR) += imagination/
+obj-$(CONFIG_DRM_VERISILICON_DC8200) += verisilicon/
drivers/gpu/drm/verisilicon/Kconfig new file +13 -0
new file mode 100644
index 000000000000..874e8bcde5d5
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+config DRM_VERISILICON_DC8200
+	tristate "DRM Support for VeriSilicon DC8200"
+	depends on DRM
+	select DRM_KMS_HELPER
+	select DRM_GEM_DMA_HELPER
+	select DMA_CMA if HAVE_DMA_CONTIGUOUS
+	select CMA if HAVE_DMA_CONTIGUOUS
+	help
+	  Choose this option if you have a VeriSilicon DC8200 chipset.
+	  This driver provides VeriSilicon kernel mode
+	  setting and buffer management. It does not
+	  provide 2D or 3D acceleration.
drivers/gpu/drm/verisilicon/Makefile new file +5 -0
new file mode 100644
index 000000000000..7da54b259940
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+vs_drm-objs := vs_dc_hw.o
+
+obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_dc_hw.c new file +1104 -0

1,104 lines not on this page · raw message

drivers/gpu/drm/verisilicon/vs_dc_hw.h new file +492 -0

492 lines not on this page · raw message

drivers/gpu/drm/verisilicon/vs_type.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.34.1
#17 lore raw

Re: [PATCH v5 4/9] drm/vs: Add Hardware Functions for VS DC8200

Quoted 2 lines · keith zhao

This commit introduces hardware-based APIs for
the VS DRM related to the DC8200

This doesn't describe anything. I've asked to describe the hardware. Also please don't use phrases as "This commit does this and this". See Documentation/process/submitting-patches.rst

Quoted 18 lines
---
 MAINTAINERS                            |    1 +
 drivers/gpu/drm/Kconfig                |    2 +
 drivers/gpu/drm/Makefile               |    1 +
 drivers/gpu/drm/verisilicon/Kconfig    |   13 +
 drivers/gpu/drm/verisilicon/Makefile   |    5 +
 drivers/gpu/drm/verisilicon/vs_dc_hw.c | 1104 ++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_dc_hw.h |  492 +++++++++++
 drivers/gpu/drm/verisilicon/vs_type.h  |   54 ++
 8 files changed, 1672 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
 create mode 100644 drivers/gpu/drm/verisilicon/Makefile
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h

[...]

Quoted 8 lines
drivers/gpu/drm/verisilicon/vs_dc_hw.h new file +8 -0
+
+struct dc_hw {
+	enum dc_hw_out		out[DC_DISPLAY_NUM];
+	void __iomem		*hi_base;
+	void __iomem		*reg_base;
+	struct dc_hw_plane_reg	reg[DC_LAYER_NUM];
+
+	struct dc_hw_gamma	gamma[DC_DISPLAY_NUM];

drivers/gpu/drm/verisilicon/vs_dc_hw.h line 456

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_dc_hw.h new file +10 -0
+	struct vs_dc_info	*info;
+};
+
+struct vs_dc_plane {
+	enum dc_hw_plane_id id;
+	u32 offset;
+};
+
+struct vs_dc {
+	struct vs_crtc		*crtc[DC_DISPLAY_NUM];

"Not defined here. Please drop and add when it is actually defined.", this was in v4.

Quoted 58 lines
drivers/gpu/drm/verisilicon/vs_dc_hw.h new file +36 -0
+	struct dc_hw		hw;
+
+	struct vs_dc_plane	planes[PLANE_NUM];
+};
+
+int dc_hw_init(struct vs_dc *dc);
+void dc_hw_disable_plane(struct vs_dc *dc, u8 id);
+void dc_hw_update_cursor(struct dc_hw *hw, u8 id, dma_addr_t dma_addr,
+			 u32 crtc_w, u32 crtc_x, u32 crtc_y,
+			 s32 hotspot_x, int32_t hotspot_y);
+void dc_hw_disable_cursor(struct dc_hw *hw, u8 id);
+void dc_hw_update_gamma(struct dc_hw *hw, u8 id, u16 index,
+			u16 r, u16 g, u16 b);
+void dc_hw_enable_gamma(struct dc_hw *hw, u8 id, bool enable);
+void dc_hw_enable(struct dc_hw *hw, int id, struct drm_display_mode *mode,
+		  u8 encoder_type, u32 output_fmt);
+void dc_hw_disable(struct dc_hw *hw, int id);
+void dc_hw_enable_interrupt(struct dc_hw *hw);
+void dc_hw_disable_interrupt(struct dc_hw *hw);
+void dc_hw_get_interrupt(struct dc_hw *hw, u8 *status);
+void dc_hw_enable_shadow_register(struct vs_dc *dc, bool enable);
+void dc_hw_set_out(struct dc_hw *hw, enum dc_hw_out out, u8 id);
+void dc_hw_commit(struct dc_hw *hw);
+void dc_plane_hw_update_format_colorspace(struct vs_dc *dc, u32 format,
+					  enum drm_color_encoding encoding, u8 id, bool is_yuv);
+void dc_plane_hw_update_address(struct vs_dc *dc, u8 id, u32 format, dma_addr_t *dma_addr,
+				struct drm_framebuffer *drm_fb, struct drm_rect *src);
+void dc_plane_hw_update_format(struct vs_dc *dc, u32 format, enum drm_color_encoding encoding,
+			       unsigned int rotation, bool visible, unsigned int zpos,
+			       u8 id, u8 display_id);
+void dc_plane_hw_update_scale(struct vs_dc *dc, struct drm_rect *src, struct drm_rect *dst,
+			      u8 id, u8 display_id, unsigned int rotation);
+void dc_plane_hw_update_blend(struct vs_dc *dc, u16 alpha, u16 pixel_blend_mode,
+			      u8 id, u8 display_id);
+
+#endif /* __VS_DC_HW_H__ */
drivers/gpu/drm/verisilicon/vs_type.h new file +16 -0
new file mode 100644
index 000000000000..e9c4ef3cacd6
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_TYPE_H__
+#define __VS_TYPE_H__
+
+enum drm_plane_type;
+
+struct vs_plane_data {
+	unsigned int num_formats;
+	const u32 *formats;
+	u8 num_modifiers;
+	const u64 *modifiers;
+	unsigned int min_width;

drivers/gpu/drm/verisilicon/vs_type.h line 26

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_type.h new file +10 -0
+	unsigned int min_height;
+	unsigned int max_width;
+	unsigned int max_height;
+	unsigned int rotation;
+	unsigned int blend_mode;
+	unsigned int color_encoding;
+	int min_scale; /* 16.16 fixed point */
+	int max_scale; /* 16.16 fixed point */
+	u8   zpos;
+};

Doesn't seem to be used in this patch. I think in v4 I've already asked to drop everything (data types, fields, defines) that are not used by _this_ patch. Readd them later, as required.

Quoted 31 lines
drivers/gpu/drm/verisilicon/vs_type.h new file +28 -0
+
+struct vs_plane_info {
+	u32 id;
+	const struct vs_plane_data *data;
+	enum drm_plane_type type;
+};
+
+struct vs_dc_info {
+	const char *name;
+
+	u8 panel_num;
+
+	/* planes */
+	u8 plane_num;
+
+	u8 layer_num;
+	u8 primary_num;
+	u8 overlay_num;
+	u8 cursor_num;
+	const struct vs_plane_info *info;
+	/* 0 means no gamma LUT */
+	u16 gamma_size;
+	u8 gamma_bits;
+
+	u16 pitch_alignment;
+};
+
+#endif /* __VS_TYPE_H__ */
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
#18 lore raw

Re: [PATCH v5 4/9] drm/vs: Add Hardware Functions for VS DC8200

In reply to keith zhao
kernel test robot noticed the following build warnings:

Hi keith,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.12 next-20241121]
[cannot apply to drm-misc/drm-misc-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/keith-zhao/dt-bindings-display-bindings-for-starfive-JH7110-display-pipeline/20241121-145710
base:   linus/master
patch link:    https://lore.kernel.org/r/20241120061848.196754-5-keith.zhao%40starfivetech.com
patch subject: [PATCH v5 4/9] drm/vs: Add Hardware Functions for VS DC8200
config: xtensa-kismet-CONFIG_CMA-CONFIG_DRM_VERISILICON_DC8200-0-0 (https://download.01.org/0day-ci/archive/20241122/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20241122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for CMA when selected by DRM_VERISILICON_DC8200

WARNING: unmet direct dependencies detected for CMA
Depends on [n]: MMU [=n]
Selected by [y]:
- DRM_VERISILICON_DC8200 [=y] && HAS_IOMEM [=y] && DRM [=y] && HAVE_DMA_CONTIGUOUS [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#19 lore raw

Re: [PATCH v5 4/9] drm/vs: Add Hardware Functions for VS DC8200

In reply to keith zhao
kernel test robot noticed the following build warnings:

Hi keith,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.12 next-20241127]
[cannot apply to drm-misc/drm-misc-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/keith-zhao/dt-bindings-display-bindings-for-starfive-JH7110-display-pipeline/20241121-145710
base:   linus/master
patch link:    https://lore.kernel.org/r/20241120061848.196754-5-keith.zhao%40starfivetech.com
patch subject: [PATCH v5 4/9] drm/vs: Add Hardware Functions for VS DC8200
config: xtensa-kismet-CONFIG_CMA-CONFIG_DRM_VERISILICON_DC8200-0-0 (https://download.01.org/0day-ci/archive/20241128/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20241128/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for CMA when selected by DRM_VERISILICON_DC8200

WARNING: unmet direct dependencies detected for CMA
Depends on [n]: MMU [=n]
Selected by [y]:
- DRM_VERISILICON_DC8200 [=y] && HAS_IOMEM [=y] && DRM [=y] && HAVE_DMA_CONTIGUOUS [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#20 lore raw

PATCH v5 5/9 drm/vs: Add Base API for VS Mode Configuration

In reply to keith zhao

This commit adds a base API for configuring VS modes, which will streamline the setup and management of display modes in the VS DRM subsystem.

In this implementation, we are using drm_atomic_helper_commit_tail_rpm() instead of drm_atomic_helper_commit_tail() to ensure that
we skip planes related to inactive CRTCs.

This helps to optimize the commit process and reduces unnecessary overhead when dealing with inactive display resources.

---
 drivers/gpu/drm/verisilicon/Makefile     |  3 ++-
 drivers/gpu/drm/verisilicon/vs_modeset.c | 31 ++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_modeset.h | 10 ++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 7da54b259940..842867dad4cb 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_dc_hw.o
+vs_drm-objs := vs_dc_hw.o \
+	       vs_modeset.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_modeset.c new file +31 -0
new file mode 100644
index 000000000000..0873a3465143
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+
+#include "vs_modeset.h"
+
+static const struct drm_mode_config_funcs vs_mode_config_funcs = {
+	.fb_create			 = drm_gem_fb_create,
+	.atomic_check		 = drm_atomic_helper_check,
+	.atomic_commit		 = drm_atomic_helper_commit,
+};
+
+static struct drm_mode_config_helper_funcs vs_mode_config_helpers = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+void vs_mode_config_init(struct drm_device *dev)
+{
+	int ret;
+
+	ret = drmm_mode_config_init(dev);
+	if (ret)
+		return;
+
+	dev->mode_config.funcs = &vs_mode_config_funcs;
+	dev->mode_config.helper_private = &vs_mode_config_helpers;
+}
drivers/gpu/drm/verisilicon/vs_modeset.h new file +10 -0
new file mode 100644
index 000000000000..bd04f81d2ad2
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_MODESET_H__
+#define __VS_MODESET_H__
+
+void vs_mode_config_init(struct drm_device *dev);
+#endif /* __VS_FB_H__ */
Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH v5 5/9] drm/vs: Add Base API for VS Mode Configuration

Quoted 10 lines · keith zhao

This commit adds a base API for configuring VS modes, which will streamline the setup and management of display modes in the VS DRM subsystem.

In this implementation, we are using drm_atomic_helper_commit_tail_rpm() instead of drm_atomic_helper_commit_tail() to ensure that
we skip planes related to inactive CRTCs.

This helps to optimize the commit process and reduces unnecessary overhead when dealing with inactive display resources.

* This is an alternative implementation for the
* &drm_mode_config_helper_funcs.atomic_commit_tail hook, for drivers
* that support runtime_pm or need the CRTC to be enabled to perform a
* commit. Otherwise, one should use the default implementation
* drm_atomic_helper_commit_tail().

Neither of the cases seem to apply here. Please use drm_atomic_helper_commit_tail().

Quoted 64 lines
---
 drivers/gpu/drm/verisilicon/Makefile     |  3 ++-
 drivers/gpu/drm/verisilicon/vs_modeset.c | 31 ++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_modeset.h | 10 ++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 7da54b259940..842867dad4cb 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-vs_drm-objs := vs_dc_hw.o
+vs_drm-objs := vs_dc_hw.o \
+	       vs_modeset.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_modeset.c new file +31 -0
new file mode 100644
index 000000000000..0873a3465143
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+
+#include "vs_modeset.h"
+
+static const struct drm_mode_config_funcs vs_mode_config_funcs = {
+	.fb_create			 = drm_gem_fb_create,
+	.atomic_check		 = drm_atomic_helper_check,
+	.atomic_commit		 = drm_atomic_helper_commit,
+};
+
+static struct drm_mode_config_helper_funcs vs_mode_config_helpers = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
+};
+
+void vs_mode_config_init(struct drm_device *dev)
+{
+	int ret;
+
+	ret = drmm_mode_config_init(dev);
+	if (ret)
+		return;
+
+	dev->mode_config.funcs = &vs_mode_config_funcs;
+	dev->mode_config.helper_private = &vs_mode_config_helpers;
+}
drivers/gpu/drm/verisilicon/vs_modeset.h new file +0 -0
new file mode 100644
index 000000000000..bd04f81d2ad2

drivers/gpu/drm/verisilicon/vs_modeset.h line 10

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_modeset.h new file +10 -0
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_MODESET_H__
+#define __VS_MODESET_H__
+
+void vs_mode_config_init(struct drm_device *dev);
+#endif /* __VS_FB_H__ */

There is no point in having single-function headers, please find something more global.

Quoted 3 lines
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
author
#22 lore raw

PATCH v5 6/9 drm/vs: Add CRTC Functions

In reply to keith zhao

This commit adds CRTC functions and helper functions to the VS DRM subsystem,
enhancing support for display management and configurations.

---
 drivers/gpu/drm/verisilicon/Makefile  |   3 +-
 drivers/gpu/drm/verisilicon/vs_crtc.c | 241 ++++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_crtc.h |  42 +++++
 drivers/gpu/drm/verisilicon/vs_drv.h  |  41 +++++
 4 files changed, 326 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 842867dad4cb..37f6a4db2a12 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 vs_drm-objs := vs_dc_hw.o \
-	       vs_modeset.o
+	       vs_modeset.o \
+	       vs_crtc.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_crtc.c new file +241 -0

241 lines not on this page · raw message

drivers/gpu/drm/verisilicon/vs_crtc.h new file +42 -0

42 lines not on this page · raw message

drivers/gpu/drm/verisilicon/vs_drv.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.34.1
#23 lore raw

Re: [PATCH v5 6/9] drm/vs: Add CRTC Functions

Quoted 125 lines · keith zhao

This commit adds CRTC functions and helper functions to the VS DRM subsystem,
enhancing support for display management and configurations.

---
 drivers/gpu/drm/verisilicon/Makefile  |   3 +-
 drivers/gpu/drm/verisilicon/vs_crtc.c | 241 ++++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_crtc.h |  42 +++++
 drivers/gpu/drm/verisilicon/vs_drv.h  |  41 +++++
 4 files changed, 326 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 842867dad4cb..37f6a4db2a12 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 vs_drm-objs := vs_dc_hw.o \
-	       vs_modeset.o
+	       vs_modeset.o \
+	       vs_crtc.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_crtc.c new file +91 -0
new file mode 100644
index 000000000000..45ce28960e27
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ *
+ */
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_vblank.h>
+#include <drm/drm_print.h>
+
+#include "vs_crtc.h"
+#include "vs_drv.h"
+
+static void vs_crtc_atomic_destroy_state(struct drm_crtc *crtc,
+					 struct drm_crtc_state *state)
+{
+	__drm_atomic_helper_crtc_destroy_state(state);
+	kfree(to_vs_crtc_state(state));
+}
+
+static void vs_crtc_reset(struct drm_crtc *crtc)
+{
+	struct vs_crtc_state *state;
+
+	if (crtc->state)
+		vs_crtc_atomic_destroy_state(crtc, crtc->state);
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return;
+
+	__drm_atomic_helper_crtc_reset(crtc, &state->base);
+}
+
+static struct drm_crtc_state *
+vs_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+	struct vs_crtc_state *old_state;
+	struct vs_crtc_state *state;
+
+	if (!crtc->state)
+		return NULL;
+
+	old_state = to_vs_crtc_state(crtc->state);
+
+	state = kmemdup(old_state, sizeof(*old_state), GFP_KERNEL);
+		if (!state)
+			return NULL;
+
+	__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
+
+	return &state->base;
+}
+
+static int vs_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	dc_hw_enable_interrupt(&dc->hw);
+
+	return 0;
+}
+
+static void vs_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	dc_hw_disable_interrupt(&dc->hw);
+}
+
+static const struct drm_crtc_funcs vs_crtc_funcs = {
+	.set_config		= drm_atomic_helper_set_config,
+	.page_flip		= drm_atomic_helper_page_flip,
+	.reset			= vs_crtc_reset,
+	.atomic_duplicate_state = vs_crtc_atomic_duplicate_state,
+	.atomic_destroy_state	= vs_crtc_atomic_destroy_state,
+	.enable_vblank		= vs_crtc_enable_vblank,
+	.disable_vblank		= vs_crtc_disable_vblank,
+};
+
+static void vs_crtc_atomic_enable(struct drm_crtc *crtc,
+				  struct drm_atomic_state *state)
+{
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	struct vs_crtc_state *crtc_state = to_vs_crtc_state(crtc->state);
+	struct drm_display_mode *mode = &crtc->state->adjusted_mode;
+	int id;

drivers/gpu/drm/verisilicon/vs_crtc.c line 101

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_crtc.c new file +10 -0
+
+	id = to_vs_display_id(crtc);
+	if (crtc_state->encoder_type == DRM_MODE_ENCODER_DSI) {
+		dc_hw_set_out(&dc->hw, OUT_DPI, id);
+		clk_set_rate(priv->clks[7].clk, mode->clock * 1000);
+		clk_set_parent(priv->clks[5].clk, priv->clks[7].clk);
+	} else {
+		dc_hw_set_out(&dc->hw, OUT_DP, id);
+		clk_set_parent(priv->clks[4].clk, priv->clks[6].clk);
+	}

Can this go to the encoder's atomic_enable() instead? Also it would be nice to have a less magic code here. What are the clocks 4-7?

Quoted 146 lines
drivers/gpu/drm/verisilicon/vs_crtc.c new file +140 -0
+
+	dc_hw_enable(&dc->hw, id, mode, crtc_state->encoder_type, crtc_state->output_fmt);
+
+	enable_irq(priv->irq);
+
+	drm_crtc_vblank_on(crtc);
+}
+
+static void vs_crtc_atomic_disable(struct drm_crtc *crtc,
+				   struct drm_atomic_state *state)
+{
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+	int id;
+
+	drm_crtc_vblank_off(crtc);
+
+	disable_irq(priv->irq);
+
+	id = to_vs_display_id(crtc);
+	dc_hw_disable(&dc->hw, id);
+
+	if (crtc->state->event && !crtc->state->active) {
+		spin_lock_irq(&crtc->dev->event_lock);
+		drm_crtc_send_vblank_event(crtc, crtc->state->event);
+		crtc->state->event = NULL;
+		spin_unlock_irq(&crtc->dev->event_lock);
+	}
+}
+
+static void vs_dc_set_gamma(struct vs_dc *dc, struct drm_crtc *crtc,
+			    struct drm_color_lut *lut, unsigned int size)
+{
+	u16 i, r, g, b;
+	u8 bits, id;
+
+	if (size != dc->hw.info->gamma_size) {
+		drm_err(crtc->dev, "gamma size does not match!\n");
+		return;
+	}
+
+	id = to_vs_display_id(crtc);
+
+	bits = dc->hw.info->gamma_bits;
+	for (i = 0; i < size; i++) {
+		r = drm_color_lut_extract(lut[i].red, bits);
+		g = drm_color_lut_extract(lut[i].green, bits);
+		b = drm_color_lut_extract(lut[i].blue, bits);
+		dc_hw_update_gamma(&dc->hw, id, i, r, g, b);
+
+		if (i >= dc->hw.info->gamma_size)
+			return;
+
+		dc->hw.gamma[id].gamma[i][0] = r;
+		dc->hw.gamma[id].gamma[i][1] = g;
+		dc->hw.gamma[id].gamma[i][2] = b;
+	}
+}
+
+static void vs_crtc_atomic_begin(struct drm_crtc *crtc,
+				 struct drm_atomic_state *state)
+{
+	struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state,
+									  crtc);
+
+	struct drm_property_blob *blob = new_state->gamma_lut;
+	struct drm_color_lut *lut;
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+	u8 id;
+
+	dc_hw_enable_shadow_register(dc, false);
+
+	id = to_vs_display_id(crtc);
+	if (new_state->color_mgmt_changed) {
+		if (blob && blob->length) {
+			lut = blob->data;
+			vs_dc_set_gamma(dc, crtc, lut,
+					blob->length / sizeof(*lut));
+			dc_hw_enable_gamma(&dc->hw, id, true);
+		} else {
+			dc_hw_enable_gamma(&dc->hw, id, false);
+		}
+	}
+}
+
+static void vs_crtc_atomic_flush(struct drm_crtc *crtc,
+				 struct drm_atomic_state *state)
+{
+	struct drm_pending_vblank_event *event = crtc->state->event;
+	struct vs_drm_device *priv = to_vs_drm_private(crtc->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	if (event) {
+		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
+
+		spin_lock_irq(&crtc->dev->event_lock);
+		drm_crtc_arm_vblank_event(crtc, event);
+		crtc->state->event = NULL;
+		spin_unlock_irq(&crtc->dev->event_lock);
+	}
+
+	dc_hw_enable_shadow_register(dc, true);
+}
+
+static const struct drm_crtc_helper_funcs vs_crtc_helper_funcs = {
+	.atomic_check = drm_crtc_helper_atomic_check,
+	.atomic_enable	= vs_crtc_atomic_enable,
+	.atomic_disable = vs_crtc_atomic_disable,
+	.atomic_begin	= vs_crtc_atomic_begin,
+	.atomic_flush	= vs_crtc_atomic_flush,
+};
+
+struct vs_crtc *vs_crtc_create(struct drm_device *drm_dev,
+			       struct vs_dc_info *info)
+{
+	struct vs_crtc *crtc;
+	int ret;
+
+	if (!info)
+		return NULL;
+
+	crtc = drmm_crtc_alloc_with_planes(drm_dev, struct vs_crtc, base, NULL,
+					   NULL, &vs_crtc_funcs,
+					   info->name ? info->name : NULL);
+
+	drm_crtc_helper_add(&crtc->base, &vs_crtc_helper_funcs);
+
+	if (info->gamma_size) {
+		ret = drm_mode_crtc_set_gamma_size(&crtc->base,
+						   info->gamma_size);
+		if (ret)
+			return NULL;
+
+		drm_crtc_enable_color_mgmt(&crtc->base, 0, false,
+					   info->gamma_size);
+	}
+
+	return crtc;
+}
drivers/gpu/drm/verisilicon/vs_crtc.h new file +0 -0
new file mode 100644
index 000000000000..58aa7a77d94e

drivers/gpu/drm/verisilicon/vs_crtc.h line 10

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_crtc.h new file +10 -0
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_CRTC_H__
+#define __VS_CRTC_H__
+
+#include <drm/drm_crtc.h>
+#include <drm/drm_crtc_helper.h>

I thought you've commented about removing them.

Quoted 6 lines
drivers/gpu/drm/verisilicon/vs_crtc.h new file +6 -0
+
+#include "vs_type.h"
+
+struct vs_crtc_state {
+	struct drm_crtc_state base;
+

drivers/gpu/drm/verisilicon/vs_crtc.h line 26

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_crtc.h new file +10 -0
+	u32 output_fmt;
+	u8 encoder_type;
+	u8 bpp;
+};
+
+struct vs_crtc {
+	struct drm_crtc base;
+	struct device *dev;
+	u8 index;
+};

Which modules do need to look into CRTC and CRTC state?

Quoted 33 lines
drivers/gpu/drm/verisilicon/vs_crtc.h new file +16 -0
+
+static inline u8 to_vs_display_id(struct drm_crtc *crtc)
+{
+	return container_of(crtc, struct vs_crtc, base)->index;
+}
+
+struct vs_crtc *vs_crtc_create(struct drm_device *drm_dev,
+			       struct vs_dc_info *info);
+
+static inline struct vs_crtc_state *
+to_vs_crtc_state(struct drm_crtc_state *state)
+{
+	return container_of(state, struct vs_crtc_state, base);
+}
+
+#endif /* __VS_CRTC_H__ */
drivers/gpu/drm/verisilicon/vs_drv.h new file +11 -0
new file mode 100644
index 000000000000..dc6efb093205
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_DRV_H__
+#define __VS_DRV_H__
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>

drivers/gpu/drm/verisilicon/vs_drv.h line 21

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.h new file +10 -0
+#include <linux/reset.h>
+
+#include <drm/drm_fourcc.h>
+
+#include "vs_dc_hw.h"
+
+/*@pitch_alignment: buffer pitch alignment required by sub-devices.*/
+struct vs_drm_device {
+	struct drm_device base;
+	unsigned int pitch_alignment;

Unused

drivers/gpu/drm/verisilicon/vs_drv.h line 23

Quoted 2 lines
drivers/gpu/drm/verisilicon/vs_drv.h new file +2 -0
+	/* clocks */
+	unsigned int clk_count;

unused

drivers/gpu/drm/verisilicon/vs_drv.h line 25

Quoted 2 lines
drivers/gpu/drm/verisilicon/vs_drv.h new file +2 -0
+	struct clk_bulk_data	*clks;
+	struct reset_control	*rsts;

You guess, unused

drivers/gpu/drm/verisilicon/vs_drv.h line 28

Quoted 3 lines
drivers/gpu/drm/verisilicon/vs_drv.h new file +3 -0
+	struct vs_dc dc;
+	int irq;
+	struct regmap *dc_syscon_regmap;

and this one too

Quoted 16 lines
drivers/gpu/drm/verisilicon/vs_drv.h new file +13 -0
+};
+
+static inline struct vs_drm_device *
+to_vs_drm_private(const struct drm_device *dev)
+{
+	return container_of(dev, struct vs_drm_device, base);
+}
+
+#ifdef CONFIG_DRM_INNO_STARFIVE_HDMI
+extern struct platform_driver starfive_hdmi_driver;
+#endif
+
+#endif /* __VS_DRV_H__ */
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
author
#24 lore raw

PATCH v5 7/9 drm/vs: Add VS Plane API

In reply to keith zhao

This commit introduces plane functions and helper functions for the VS DRM subsystem, enhancing support for managing display planes and their configurations.

---
 drivers/gpu/drm/verisilicon/Makefile   |   3 +-
 drivers/gpu/drm/verisilicon/vs_plane.c | 358 +++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_plane.h |  27 ++
 3 files changed, 387 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 37f6a4db2a12..1a0e46f38ae8 100644
@@ -2,6 +2,7 @@
 
 vs_drm-objs := vs_dc_hw.o \
 	       vs_modeset.o \
-	       vs_crtc.o
+	       vs_crtc.o \
+	       vs_plane.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_plane.c new file +358 -0

358 lines not on this page · raw message

drivers/gpu/drm/verisilicon/vs_plane.h new file +27 -0
new file mode 100644
index 000000000000..60d45b69e30a
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_PLANE_H__
+#define __VS_PLANE_H__
+
+#include <drm/drm_plane.h>
+
+struct vs_plane_info;
+
+struct vs_plane_state {
+	struct drm_plane_state base;
+	dma_addr_t dma_addr[DRM_FORMAT_MAX_PLANES];
+};
+
+struct vs_plane {
+	struct drm_plane base;
+	u8 id;
+};
+
+struct vs_plane *vs_plane_create(struct drm_device *drm_dev,
+				 struct vs_plane_info *info,
+				 unsigned int layer_num,
+				 unsigned int possible_crtcs);
+#endif /* __VS_PLANE_H__ */
Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH v5 7/9] drm/vs: Add VS Plane API

Quoted 121 lines · keith zhao

This commit introduces plane functions and helper functions for the VS DRM subsystem, enhancing support for managing display planes and their configurations.

---
 drivers/gpu/drm/verisilicon/Makefile   |   3 +-
 drivers/gpu/drm/verisilicon/vs_plane.c | 358 +++++++++++++++++++++++++
 drivers/gpu/drm/verisilicon/vs_plane.h |  27 ++
 3 files changed, 387 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c
 create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h
drivers/gpu/drm/verisilicon/Makefile +2 -1
index 37f6a4db2a12..1a0e46f38ae8 100644
@@ -2,6 +2,7 @@
 
 vs_drm-objs := vs_dc_hw.o \
 	       vs_modeset.o \
-	       vs_crtc.o
+	       vs_crtc.o \
+	       vs_plane.o
 
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_plane.c new file +89 -0
new file mode 100644
index 000000000000..ba47d0185fc6
@@ -0,0 +1,358 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_blend.h>
+#include <drm/drm_gem_dma_helper.h>
+#include <drm/drm_fb_dma_helper.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_plane_helper.h>
+
+#include "vs_plane.h"
+#include "vs_drv.h"
+#include "vs_crtc.h"
+
+static inline struct vs_plane_state *
+to_vs_plane_state(struct drm_plane_state *state)
+{
+	return container_of(state, struct vs_plane_state, base);
+}
+
+static inline struct vs_plane *to_vs_plane(struct drm_plane *plane)
+{
+	return container_of(plane, struct vs_plane, base);
+}
+
+static void vs_plane_atomic_destroy_state(struct drm_plane *plane,
+					  struct drm_plane_state *state)
+{
+	struct vs_plane_state *vs_plane_state = to_vs_plane_state(state);
+
+	__drm_atomic_helper_plane_destroy_state(state);
+	kfree(vs_plane_state);
+}
+
+static void vs_plane_reset(struct drm_plane *plane)
+{
+	struct vs_plane_state *state;
+
+	if (plane->state)
+		vs_plane_atomic_destroy_state(plane, plane->state);
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return;
+
+	__drm_atomic_helper_plane_reset(plane, &state->base);
+}
+
+static struct drm_plane_state *
+vs_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+	struct vs_plane_state *state;
+
+	if (WARN_ON(!plane->state))
+		return NULL;
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return NULL;
+
+	__drm_atomic_helper_plane_duplicate_state(plane, &state->base);
+
+	return &state->base;
+}
+
+static bool vs_format_mod_supported(struct drm_plane *plane,
+				    u32 format,
+				    u64 modifier)
+{
+	int i;
+
+	/* We always have to allow these modifiers:
+	 * 1. Core DRM checks for LINEAR support if userspace does not provide modifiers.
+	 * 2. Not passing any modifiers is the same as explicitly passing INVALID.
+	 */
+	if (modifier == DRM_FORMAT_MOD_LINEAR)
+		return true;
+
+	/* Check that the modifier is on the list of the plane's supported modifiers. */
+	for (i = 0; i < plane->modifier_count; i++) {
+		if (modifier == plane->modifiers[i])
+			break;
+	}
+
+	if (i == plane->modifier_count)
+		return false;
+

drivers/gpu/drm/verisilicon/vs_plane.c line 99

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +10 -0
+	return true;
+}
+
+static const struct drm_plane_funcs vs_plane_funcs = {
+	.update_plane		= drm_atomic_helper_update_plane,
+	.disable_plane		= drm_atomic_helper_disable_plane,
+	.reset			= vs_plane_reset,
+	.atomic_duplicate_state = vs_plane_atomic_duplicate_state,
+	.atomic_destroy_state	= vs_plane_atomic_destroy_state,
+	.format_mod_supported	= vs_format_mod_supported,

* If not present, then any modifier in the plane's modifier
* list is allowed with any of the plane's formats.

How is your implementation different from the default behaviour?

drivers/gpu/drm/verisilicon/vs_plane.c line 102

Quoted 3 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +3 -0
+};
+
+static unsigned char vs_get_plane_number(struct drm_framebuffer *fb)

Inline at the calling site.

Quoted 41 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +41 -0
+{
+	const struct drm_format_info *info;
+
+	if (!fb)
+		return 0;
+
+	info = drm_format_info(fb->format->format);
+	if (!info || info->num_planes > DRM_FORMAT_MAX_PLANES)
+		return 0;
+
+	return info->num_planes;
+}
+
+static bool vs_dc_mod_supported(const struct vs_plane_info *vs_info, u64 modifier)
+{
+	const u64 *mods;
+
+	if (vs_info->type == DRM_PLANE_TYPE_CURSOR)
+		return 0;
+
+	if (!vs_info->data->modifiers)
+		return false;
+
+	for (mods = vs_info->data->modifiers; *mods != DRM_FORMAT_MOD_INVALID; mods++) {
+		if (*mods == modifier)
+			return true;
+	}
+
+	return false;
+}
+
+static int vs_common_plane_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
+	struct vs_drm_device *priv = to_vs_drm_private(plane->dev);
+	struct vs_dc *dc = &priv->dc;
+	struct drm_framebuffer *fb = new_state->fb;
+	const struct vs_plane_info *plane_info;
+	struct drm_crtc_state *crtc_state;
+
+	if (!new_state->crtc || !new_state->fb)

drivers/gpu/drm/verisilicon/vs_plane.c line 153

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +10 -0
+		return 0;
+
+	plane_info = (struct vs_plane_info *)&dc->hw.info->info[to_vs_plane(plane)->id];
+
+	if (fb->width < plane_info->data->min_width ||
+	    fb->width > plane_info->data->max_width ||
+	    fb->height < plane_info->data->min_height ||
+	    fb->height > plane_info->data->max_height)
+		drm_err_once(plane->dev, "buffer size may not support on plane%d.\n",
+			     to_vs_plane(plane)->id);

Don't allow users spam console. Use drm_dbg_kms(), drm_dbg_atomic() or drm_dbg_driver(), whichever fits better.

drivers/gpu/drm/verisilicon/vs_plane.c line 155

Quoted 2 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +2 -0
+
+	if (!vs_dc_mod_supported(plane_info, fb->modifier)) {

Should not be necessary, it matches default drm behaviour, see drm_plane_has_format() called from drm_atomic_plane_check().

drivers/gpu/drm/verisilicon/vs_plane.c line 160

Quoted 5 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +5 -0
+		drm_err(plane->dev, "unsupported modifier on plane%d.\n", to_vs_plane(plane)->id);
+		return -EINVAL;
+	}
+
+	crtc_state = drm_atomic_get_existing_crtc_state(new_state->state, new_state->crtc);

drm_atomic_get_new_crtc_state(). Don't call deprecated functions.

Quoted 147 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +147 -0
+	return drm_atomic_helper_check_plane_state(new_state, crtc_state,
+						   plane_info->data->min_scale,
+						   plane_info->data->max_scale,
+						   true, true);
+}
+
+static void vs_plane_atomic_update(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, plane);
+
+	unsigned char i, num_planes, display_id, id;
+	u32 format;
+	bool is_yuv;
+	struct vs_plane *vs_plane = to_vs_plane(plane);
+	struct vs_plane_state *plane_state = to_vs_plane_state(new_state);
+	struct vs_drm_device *priv = to_vs_drm_private(plane->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	if (!new_state->fb || !new_state->crtc)
+		return;
+
+	drm_fb_dma_sync_non_coherent(plane->dev, old_state, new_state);
+
+	num_planes = vs_get_plane_number(new_state->fb);
+
+	for (i = 0; i < num_planes; i++) {
+		dma_addr_t dma_addr;
+
+		dma_addr = drm_fb_dma_get_gem_addr(new_state->fb, new_state, i);
+		plane_state->dma_addr[i] = dma_addr;
+	}
+
+	display_id = to_vs_display_id(new_state->crtc);
+	format = new_state->fb->format->format;
+	is_yuv = new_state->fb->format->is_yuv;
+	id = vs_plane->id;
+
+	dc_plane_hw_update_format_colorspace(dc, format, new_state->color_encoding, id, is_yuv);
+	if (new_state->visible)
+		dc_plane_hw_update_address(dc, id, format, plane_state->dma_addr,
+					   new_state->fb, &new_state->src);
+	dc_plane_hw_update_format(dc, format, new_state->color_encoding, new_state->rotation,
+				  new_state->visible, new_state->zpos, id, display_id);
+	dc_plane_hw_update_scale(dc, &new_state->src, &new_state->dst, id,
+				 display_id, new_state->rotation);
+	dc_plane_hw_update_blend(dc, new_state->alpha, new_state->pixel_blend_mode,
+				 id, display_id);
+}
+
+static void vs_cursor_plane_atomic_update(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
+									   plane);
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
+									   plane);
+	struct vs_drm_device *priv = to_vs_drm_private(plane->dev);
+	struct vs_dc *dc = &priv->dc;
+	unsigned char display_id;
+	u32 crtc_w, crtc_x, crtc_y;
+	s32 hotspot_x, hotspot_y;
+	dma_addr_t dma_addr;
+
+	display_id = to_vs_display_id(new_state->crtc);
+
+	if (!new_state->fb || !new_state->crtc)
+		return;
+
+	drm_fb_dma_sync_non_coherent(new_state->fb->dev, old_state, new_state);
+	dma_addr = drm_fb_dma_get_gem_addr(new_state->fb, new_state, 0);
+	crtc_w = new_state->crtc_w;
+
+	if (new_state->crtc_x > 0) {
+		crtc_x = new_state->crtc_x;
+		hotspot_x = 0;
+	} else {
+		hotspot_x = -new_state->crtc_x;
+		crtc_x = 0;
+	}
+	if (new_state->crtc_y > 0) {
+		crtc_y = new_state->crtc_y;
+		hotspot_y = 0;
+	} else {
+		hotspot_y = -new_state->crtc_y;
+		crtc_y = 0;
+	}
+	dc_hw_update_cursor(&dc->hw, display_id, dma_addr, crtc_w, crtc_x,
+			    crtc_y, hotspot_x, hotspot_y);
+}
+
+static void vs_plane_atomic_disable(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct vs_plane *vs_plane = to_vs_plane(plane);
+	struct vs_drm_device *priv = to_vs_drm_private(plane->dev);
+	struct vs_dc *dc = &priv->dc;
+
+	dc_hw_disable_plane(dc, vs_plane->id);
+}
+
+static void vs_cursor_plane_atomic_disable(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, plane);
+	struct vs_drm_device *priv = to_vs_drm_private(plane->dev);
+	struct vs_dc *dc = &priv->dc;
+	unsigned char display_id;
+
+	display_id = to_vs_display_id(old_state->crtc);
+	dc_hw_disable_cursor(&dc->hw, display_id);
+}
+
+static const struct drm_plane_helper_funcs vs_primary_plane_helpers = {
+	.atomic_check	= vs_common_plane_atomic_check,
+	.atomic_update	= vs_plane_atomic_update,
+	.atomic_disable = vs_plane_atomic_disable,
+};
+
+static const struct drm_plane_helper_funcs vs_overlay_plane_helpers = {
+	.atomic_check	= vs_common_plane_atomic_check,
+	.atomic_update	= vs_plane_atomic_update,
+	.atomic_disable = vs_plane_atomic_disable,
+};
+
+static const struct drm_plane_helper_funcs vs_cursor_plane_helpers = {
+	.atomic_check	= vs_common_plane_atomic_check,
+	.atomic_update	= vs_cursor_plane_atomic_update,
+	.atomic_disable = vs_cursor_plane_atomic_disable,
+};
+
+struct vs_plane *vs_plane_create(struct drm_device *drm_dev,
+				 struct vs_plane_info *info,
+				 unsigned int layer_num,
+				 unsigned int possible_crtcs)
+{
+	struct vs_plane *plane;
+	const struct vs_plane_data *data = info->data;
+	int ret;
+
+	if (!info)
+		return NULL;
+
+	plane = drmm_universal_plane_alloc(drm_dev, struct vs_plane, base,
+					   possible_crtcs,
+					   &vs_plane_funcs,
+					   data->formats, data->num_formats,
+					   data->modifiers, info->type,
+					   NULL);
+	if (IS_ERR(plane))

drivers/gpu/drm/verisilicon/vs_plane.c line 317

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +10 -0
+		return ERR_CAST(plane);
+
+	if (info->type == DRM_PLANE_TYPE_PRIMARY)
+		drm_plane_helper_add(&plane->base, &vs_primary_plane_helpers);
+	else if (info->type == DRM_PLANE_TYPE_OVERLAY)
+		drm_plane_helper_add(&plane->base, &vs_overlay_plane_helpers);
+	else
+		drm_plane_helper_add(&plane->base, &vs_cursor_plane_helpers);
+
+	if (data->blend_mode) {

Which of the planes sets .blend_mode ?

Quoted 58 lines
drivers/gpu/drm/verisilicon/vs_plane.c new file +41 -0
+		ret = drm_plane_create_alpha_property(&plane->base);
+		if (ret)
+			return NULL;
+
+		ret = drm_plane_create_blend_mode_property(&plane->base,
+							   BIT(DRM_MODE_BLEND_PIXEL_NONE) |
+							   BIT(DRM_MODE_BLEND_PREMULTI) |
+							   BIT(DRM_MODE_BLEND_COVERAGE));
+		if (ret)
+			return NULL;
+	}
+
+	if (data->color_encoding) {
+		ret = drm_plane_create_color_properties(&plane->base, data->color_encoding,
+							BIT(DRM_COLOR_YCBCR_LIMITED_RANGE),
+							DRM_COLOR_YCBCR_BT709,
+							DRM_COLOR_YCBCR_LIMITED_RANGE);
+		if (ret)
+			return NULL;
+	}
+
+	if (data->rotation) {
+		ret = drm_plane_create_rotation_property(&plane->base,
+							 DRM_MODE_ROTATE_0,
+							 data->rotation);
+		if (ret)
+			return NULL;
+	}
+
+	if (data->zpos != 255) {
+		ret = drm_plane_create_zpos_property(&plane->base, data->zpos, 0, layer_num - 1);
+		if (ret)
+			return NULL;
+	} else {
+		ret = drm_plane_create_zpos_immutable_property(&plane->base, data->zpos);
+		if (ret)
+			return NULL;
+	}
+
+	return plane;
+}
drivers/gpu/drm/verisilicon/vs_plane.h new file +11 -0
new file mode 100644
index 000000000000..60d45b69e30a
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_PLANE_H__
+#define __VS_PLANE_H__
+
+#include <drm/drm_plane.h>
+
+struct vs_plane_info;

drivers/gpu/drm/verisilicon/vs_plane.h line 21

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_plane.h new file +10 -0
+
+struct vs_plane_state {
+	struct drm_plane_state base;
+	dma_addr_t dma_addr[DRM_FORMAT_MAX_PLANES];
+};
+
+struct vs_plane {
+	struct drm_plane base;
+	u8 id;
+};

Why do you need to export them?

Quoted 9 lines
drivers/gpu/drm/verisilicon/vs_plane.h new file +6 -0
+
+struct vs_plane *vs_plane_create(struct drm_device *drm_dev,
+				 struct vs_plane_info *info,
+				 unsigned int layer_num,
+				 unsigned int possible_crtcs);
+#endif /* __VS_PLANE_H__ */
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
author
#26 lore raw

PATCH v5 8/9 drm/vs: Add Innosilicon HDMI Support

In reply to keith zhao

This commit adds the Innosilicon HDMI driver, designed to interface with the VS display controller.

The driver leverages the APIs provided by the Innosilicon HDMI bridge.

---
 drivers/gpu/drm/verisilicon/Kconfig           |  19 +
 drivers/gpu/drm/verisilicon/Makefile          |   1 +
 .../gpu/drm/verisilicon/inno_hdmi-starfive.c  | 553 ++++++++++++++++++
 .../gpu/drm/verisilicon/inno_hdmi-starfive.h  | 194 ++++++
 4 files changed, 767 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
drivers/gpu/drm/verisilicon/Kconfig +19 -0
index 874e8bcde5d5..49648a3a6deb 100644
@@ -11,3 +11,22 @@ config DRM_VERISILICON_DC8200
 	  This driver provides VeriSilicon kernel mode
 	  setting and buffer management. It does not
 	  provide 2D or 3D acceleration.
+
+config DRM_INNO_STARFIVE_HDMI
+	bool "Starfive JH7110 specific extensions for Innosilicon HDMI"
+	depends on DRM_VERISILICON_DC8200
+	select DRM_INNO_HDMI
+	select DRM_DISPLAY_HELPER
+	select DRM_BRIDGE_CONNECTOR
+	help
+          This configuration option enables support for StarFive SoC
+          specific extensions for the Innosilicon HDMI driver.
+
+          Enabling this option is essential for proper functionality
+          of HDMI on JH7110 based SoCs. If you are using a StarFive
+          JH7110 SoC and require HDMI output functionalities,
+          you should select this option to ensure that the driver is
+          compiled with the necessary extensions and dependencies.
+
+          This option may enable additional features and capabilities
+          specific to StarFive's implementation of the HDMI technology.
drivers/gpu/drm/verisilicon/Makefile +1 -0
index 1a0e46f38ae8..a602630c2416 100644
@@ -5,4 +5,5 @@ vs_drm-objs := vs_dc_hw.o \
 	       vs_crtc.o \
 	       vs_plane.o
 
+vs_drm-$(CONFIG_DRM_INNO_STARFIVE_HDMI) += inno_hdmi-starfive.o
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +553 -0

553 lines not on this page · raw message

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.34.1
#27 lore raw

Re: [PATCH v5 8/9] drm/vs: Add Innosilicon HDMI Support

Quoted 1 line · keith zhao

This commit adds the Innosilicon HDMI driver,

Documentation/process/submitting-patches.rst, look for "This patch..."

Quoted 3 lines

designed to interface with the VS display controller.

The driver leverages the APIs provided by the Innosilicon HDMI bridge.

Please describe design decisions, features supported by HW but not yet implemented (to give you an idea: CSC, YUV, infoframes, etc).

Quoted 184 lines
---
 drivers/gpu/drm/verisilicon/Kconfig           |  19 +
 drivers/gpu/drm/verisilicon/Makefile          |   1 +
 .../gpu/drm/verisilicon/inno_hdmi-starfive.c  | 553 ++++++++++++++++++
 .../gpu/drm/verisilicon/inno_hdmi-starfive.h  | 194 ++++++
 4 files changed, 767 insertions(+)
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
 create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
drivers/gpu/drm/verisilicon/Kconfig +19 -0
index 874e8bcde5d5..49648a3a6deb 100644
@@ -11,3 +11,22 @@ config DRM_VERISILICON_DC8200
 	  This driver provides VeriSilicon kernel mode
 	  setting and buffer management. It does not
 	  provide 2D or 3D acceleration.
+
+config DRM_INNO_STARFIVE_HDMI
+	bool "Starfive JH7110 specific extensions for Innosilicon HDMI"
+	depends on DRM_VERISILICON_DC8200
+	select DRM_INNO_HDMI
+	select DRM_DISPLAY_HELPER
+	select DRM_BRIDGE_CONNECTOR
+	help
+          This configuration option enables support for StarFive SoC
+          specific extensions for the Innosilicon HDMI driver.
+
+          Enabling this option is essential for proper functionality
+          of HDMI on JH7110 based SoCs. If you are using a StarFive
+          JH7110 SoC and require HDMI output functionalities,
+          you should select this option to ensure that the driver is
+          compiled with the necessary extensions and dependencies.
+
+          This option may enable additional features and capabilities
+          specific to StarFive's implementation of the HDMI technology.
drivers/gpu/drm/verisilicon/Makefile +1 -0
index 1a0e46f38ae8..a602630c2416 100644
@@ -5,4 +5,5 @@ vs_drm-objs := vs_dc_hw.o \
 	       vs_crtc.o \
 	       vs_plane.o
 
+vs_drm-$(CONFIG_DRM_INNO_STARFIVE_HDMI) += inno_hdmi-starfive.o
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +130 -0
new file mode 100644
index 000000000000..6923f789bcc0
@@ -0,0 +1,553 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */
+
+#include <linux/component.h>
+#include <linux/clk.h>
+#include <linux/i2c.h>
+#include <linux/media-bus-format.h>
+#include <linux/module.h>
+#include <linux/reset.h>
+
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_of.h>
+#include <drm/drm_simple_kms_helper.h>
+#include <drm/bridge/inno_hdmi.h>
+#include <drm/drm_bridge_connector.h>
+#include <drm/drm_bridge.h>
+
+#include <sound/hdmi-codec.h>
+
+#include "inno_hdmi-starfive.h"
+#include "vs_crtc.h"
+
+enum hdmi_clk {
+	CLK_SYS = 0,
+	CLK_M,
+	CLK_B,
+	CLK_HDMI_NUM
+};
+
+struct pre_pll_config {
+	unsigned long pixclock;
+	unsigned long tmdsclock;
+	u8 prediv;
+	u16 fbdiv;
+	u8 tmds_div_a;
+	u8 tmds_div_b;
+	u8 tmds_div_c;
+	u8 pclk_div_a;
+	u8 pclk_div_b;
+	u8 pclk_div_c;
+	u8 pclk_div_d;
+	u8 vco_div_5_en;
+	u32 fracdiv;
+};
+
+struct post_pll_config {
+	unsigned long tmdsclock;
+	u8 prediv;
+	u16 fbdiv;
+	u8 postdiv;
+	u8 post_div_en;
+	u8 version;
+};
+
+struct stf_inno_hdmi {
+	struct drm_encoder	encoder;
+	struct drm_connector	*connector;
+	struct inno_hdmi inno_hdmi;
+	struct clk_bulk_data clk_hdmi[CLK_HDMI_NUM];
+	struct reset_control *tx_rst;
+	int	nclks;
+	unsigned long tmds_rate;
+	struct pre_pll_config pre_cfg;
+	const struct post_pll_config *post_cfg;
+};
+
+static inline struct stf_inno_hdmi *to_starfive_inno_hdmi(struct drm_encoder *encoder)
+{
+	return container_of(encoder, struct stf_inno_hdmi, encoder);
+}
+
+static struct inno_hdmi *encoder_to_inno_hdmi(struct drm_encoder *encoder)
+{
+	struct stf_inno_hdmi *stf_hdmi = to_starfive_inno_hdmi(encoder);
+
+	return &stf_hdmi->inno_hdmi;
+}
+
+static const struct post_pll_config post_pll_cfg_table[] = {
+	{25200000, 1, 80, 13, 3, 1},
+	{27000000, 1, 40, 11, 3, 1},
+	{33750000, 1, 40, 11, 3, 1},
+	{49000000, 1, 20, 1, 3, 3},
+	{241700000, 1, 20, 1, 3, 3},
+	{297000000, 4, 20, 0, 0, 3},
+	{ /* sentinel */ }
+};
+
+static int inno_hdmi_starfive_enable_clk_rst(struct device *dev,
+					     struct stf_inno_hdmi *stf_inno_hdmi)
+{
+	int ret;
+
+	ret = clk_bulk_prepare_enable(stf_inno_hdmi->nclks, stf_inno_hdmi->clk_hdmi);
+	if (ret) {
+		dev_err(dev, "failed to enable clocks\n");
+		return ret;
+	}
+
+	ret = reset_control_deassert(stf_inno_hdmi->tx_rst);
+	if (ret < 0) {
+		dev_err(dev, "failed to deassert tx_rst\n");
+		return ret;
+	}
+	return 0;
+}
+
+static void inno_hdmi_starfive_disable_clk_rst(struct device *dev,
+					       struct stf_inno_hdmi *stf_inno_hdmi)
+{
+	int ret;
+
+	ret = reset_control_assert(stf_inno_hdmi->tx_rst);
+	if (ret < 0)
+		dev_err(dev, "failed to assert tx_rst\n");
+
+	clk_bulk_disable_unprepare(stf_inno_hdmi->nclks, stf_inno_hdmi->clk_hdmi);
+}
+
+static void inno_hdmi_starfive_config_pll(struct stf_inno_hdmi *stf_inno_hdmi)
+{
+	u32 val;
+	struct inno_hdmi *hdmi;
+
+	hdmi = &stf_inno_hdmi->inno_hdmi;

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 140

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+	u8 reg_1ad_value = stf_inno_hdmi->post_cfg->post_div_en ?
+			   stf_inno_hdmi->post_cfg->postdiv : 0x00;
+	u8 reg_1aa_value = stf_inno_hdmi->post_cfg->post_div_en ?
+			   0x0e : 0x02;
+
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_CONTROL, STF_INNO_PRE_PLL_POWER_DOWN);
+	hdmi_writeb(hdmi, STF_INNO_POST_PLL_DIV_1,
+		    STF_INNO_POST_PLL_POST_DIV_ENABLE |
+		    STF_INNO_POST_PLL_REFCLK_SEL_TMDS |
+		    STF_INNO_POST_PLL_POWER_DOWN);

This kind of code begs to be reimplemented using regmap. Then the base driver can also use regmap instead of exporting hdmi_writeb() / _readb().

Quoted 115 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +115 -0
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_1,
+		    STF_INNO_PRE_PLL_PRE_DIV(stf_inno_hdmi->pre_cfg.prediv));
+
+	val = STF_INNO_SPREAD_SPECTRUM_MOD_DISABLE | STF_INNO_SPREAD_SPECTRUM_MOD_DOWN;
+	if (!stf_inno_hdmi->pre_cfg.fracdiv)
+		val |= STF_INNO_PRE_PLL_FRAC_DIV_DISABLE;
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_2,
+		    STF_INNO_PRE_PLL_FB_DIV_11_8(stf_inno_hdmi->pre_cfg.fbdiv) | val);
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_3,
+		    STF_INNO_PRE_PLL_FB_DIV_7_0(stf_inno_hdmi->pre_cfg.fbdiv));
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_4,
+		    STF_INNO_PRE_PLL_TMDSCLK_DIV_C(stf_inno_hdmi->pre_cfg.tmds_div_c) |
+		    STF_INNO_PRE_PLL_TMDSCLK_DIV_A(stf_inno_hdmi->pre_cfg.tmds_div_a) |
+		    STF_INNO_PRE_PLL_TMDSCLK_DIV_B(stf_inno_hdmi->pre_cfg.tmds_div_b));
+
+	if (stf_inno_hdmi->pre_cfg.fracdiv) {
+		hdmi_writeb(hdmi, STF_INNO_PRE_PLL_FRAC_DIV_L,
+			    STF_INNO_PRE_PLL_FRAC_DIV_7_0(stf_inno_hdmi->pre_cfg.fracdiv));
+		hdmi_writeb(hdmi, STF_INNO_PRE_PLL_FRAC_DIV_M,
+			    STF_INNO_PRE_PLL_FRAC_DIV_15_8(stf_inno_hdmi->pre_cfg.fracdiv));
+		hdmi_writeb(hdmi, STF_INNO_PRE_PLL_FRAC_DIV_H,
+			    STF_INNO_PRE_PLL_FRAC_DIV_23_16(stf_inno_hdmi->pre_cfg.fracdiv));
+	}
+
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_5,
+		    STF_INNO_PRE_PLL_PCLK_DIV_A(stf_inno_hdmi->pre_cfg.pclk_div_a) |
+		    STF_INNO_PRE_PLL_PCLK_DIV_B(stf_inno_hdmi->pre_cfg.pclk_div_b));
+	hdmi_writeb(hdmi, STF_INNO_PRE_PLL_DIV_6,
+		    STF_INNO_PRE_PLL_PCLK_DIV_C(stf_inno_hdmi->pre_cfg.pclk_div_c) |
+		    STF_INNO_PRE_PLL_PCLK_DIV_D(stf_inno_hdmi->pre_cfg.pclk_div_d));
+
+	/*pre-pll power down*/
+	hdmi_modb(hdmi, STF_INNO_PRE_PLL_CONTROL, STF_INNO_PRE_PLL_POWER_DOWN, 0);
+
+	hdmi_modb(hdmi, STF_INNO_POST_PLL_DIV_2, STF_INNO_POST_PLL_Pre_DIV_MASK,
+		  STF_INNO_POST_PLL_PRE_DIV(stf_inno_hdmi->post_cfg->prediv));
+	hdmi_writeb(hdmi, STF_INNO_POST_PLL_DIV_3, stf_inno_hdmi->post_cfg->fbdiv & 0xff);
+	hdmi_writeb(hdmi, STF_INNO_POST_PLL_DIV_4, reg_1ad_value);
+	hdmi_writeb(hdmi, STF_INNO_POST_PLL_DIV_1, reg_1aa_value);
+}
+
+static void inno_hdmi_starfive_tmds_driver_on(struct inno_hdmi *hdmi)
+{
+	hdmi_modb(hdmi, STF_INNO_TMDS_CONTROL,
+		  STF_INNO_TMDS_DRIVER_ENABLE, STF_INNO_TMDS_DRIVER_ENABLE);
+}
+
+static void inno_hdmi_starfive_sync_tmds(struct inno_hdmi *hdmi)
+{
+	/*first send 0 to this bit, then send 1 and keep 1 into this bit*/
+	hdmi_writeb(hdmi, HDMI_SYNC, 0x0);
+	hdmi_writeb(hdmi, HDMI_SYNC, 0x1);
+}
+
+static void inno_hdmi_starfive_phy_get_pre_pll_cfg(struct stf_inno_hdmi *hdmi)
+{
+	if (hdmi->tmds_rate > 30000000) {
+		hdmi->pre_cfg.pixclock = hdmi->tmds_rate;
+		hdmi->pre_cfg.tmdsclock = hdmi->tmds_rate;
+		hdmi->pre_cfg.prediv = 1;
+		hdmi->pre_cfg.fbdiv = hdmi->tmds_rate / 3000000;
+		hdmi->pre_cfg.tmds_div_a = 0;
+		hdmi->pre_cfg.tmds_div_b = 1;
+		hdmi->pre_cfg.tmds_div_c = 1;
+		hdmi->pre_cfg.pclk_div_a = 1;
+		hdmi->pre_cfg.pclk_div_b = 0;
+		hdmi->pre_cfg.pclk_div_c = 2;
+		hdmi->pre_cfg.pclk_div_d = 2;
+		hdmi->pre_cfg.vco_div_5_en = hdmi->tmds_rate % 3000000 ? 1 : 0;
+
+		if (hdmi->pre_cfg.vco_div_5_en) {
+			hdmi->pre_cfg.fracdiv = (hdmi->tmds_rate % 3000000) *
+						 0xffffff / 1000000;
+		}
+	} else {
+		hdmi->pre_cfg.pixclock = hdmi->tmds_rate;
+		hdmi->pre_cfg.tmdsclock = hdmi->tmds_rate;
+		hdmi->pre_cfg.prediv = 1;
+		hdmi->pre_cfg.fbdiv = hdmi->tmds_rate / 1000000;
+		hdmi->pre_cfg.tmds_div_a = 2;
+		hdmi->pre_cfg.tmds_div_b = 1;
+		hdmi->pre_cfg.tmds_div_c = 1;
+		hdmi->pre_cfg.pclk_div_a = 3;
+		hdmi->pre_cfg.pclk_div_b = 0;
+		hdmi->pre_cfg.pclk_div_c = 3;
+		hdmi->pre_cfg.pclk_div_d = 4;
+		hdmi->pre_cfg.vco_div_5_en = hdmi->tmds_rate % 1000000 ? 1 : 0;
+
+		if (hdmi->pre_cfg.vco_div_5_en) {
+			hdmi->pre_cfg.fracdiv = (hdmi->tmds_rate % 1000000) *
+						 0xffffff / 1000000;
+		}
+	}
+}
+
+static int inno_hdmi_starfive_phy_clk_set_rate(struct stf_inno_hdmi *stf_inno_hdmi)
+{
+	stf_inno_hdmi->post_cfg = post_pll_cfg_table;
+
+	inno_hdmi_starfive_phy_get_pre_pll_cfg(stf_inno_hdmi);
+
+	for (; stf_inno_hdmi->post_cfg->tmdsclock != 0; stf_inno_hdmi->post_cfg++)
+		if (stf_inno_hdmi->tmds_rate <= stf_inno_hdmi->post_cfg->tmdsclock)
+			break;
+
+	inno_hdmi_starfive_config_pll(stf_inno_hdmi);
+
+	return 0;
+}
+
+static int inno_hdmi_starfive_config_video_timing(struct inno_hdmi *hdmi,
+						  struct drm_display_mode *mode)
+{
+	int value;
+

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 265

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+	/* Set detail external video timing polarity and interlace mode */
+	value = v_EXTERANL_VIDEO(1);
+
+	value |= mode->flags & DRM_MODE_FLAG_PHSYNC ?
+		 v_HSYNC_POLARITY_SF(1) : v_HSYNC_POLARITY_SF(0);
+	value |= mode->flags & DRM_MODE_FLAG_PVSYNC ?
+		 v_VSYNC_POLARITY_SF(1) : v_VSYNC_POLARITY_SF(0);
+
+	value |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
+		 v_INETLACE(1) : v_INETLACE(0);

I don't see .interlace_allowed = true

Quoted 24 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +24 -0
+	hdmi_writeb(hdmi, HDMI_VIDEO_TIMING_CTL, value);
+
+	/* Set detail external video timing */
+	value = mode->htotal;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HTOTAL_H, (value >> 8) & 0xFF);
+
+	value = mode->htotal - mode->hdisplay;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HBLANK_H, (value >> 8) & 0xFF);
+
+	value = mode->htotal - mode->hsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDELAY_H, (value >> 8) & 0xFF);
+
+	value = mode->hsync_end - mode->hsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_HDURATION_H, (value >> 8) & 0xFF);
+
+	value = mode->vtotal;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_L, value & 0xFF);
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VTOTAL_H, (value >> 8) & 0xFF);
+
+	value = mode->vtotal - mode->vdisplay;

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 299

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VBLANK, value & 0xFF);
+
+	value = mode->vtotal - mode->vsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDELAY, value & 0xFF);
+
+	value = mode->vsync_end - mode->vsync_start;
+	hdmi_writeb(hdmi, HDMI_VIDEO_EXT_VDURATION, value & 0xFF);
+
+	return 0;
+}

This is mostly the same as Rockchip's implementation. Please use common code instead.

Quoted 9 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +9 -0
+
+static void inno_hdmi_starfive_sys_power(struct inno_hdmi *hdmi, bool enable)
+{
+	if (enable)
+		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_ON);
+	else
+		hdmi_modb(hdmi, HDMI_SYS_CTRL, m_POWER, v_PWR_OFF);
+}
+

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 318

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+static int inno_hdmi_starfive_setup(struct inno_hdmi *hdmi, struct drm_display_mode *mode)
+{
+	struct stf_inno_hdmi *stf_inno_hdmi = dev_get_drvdata(hdmi->dev);
+	int ret;
+	u32 val;
+
+	hdmi_modb(hdmi, STF_INNO_BIAS_CONTROL, STF_INNO_BIAS_ENABLE, STF_INNO_BIAS_ENABLE);
+	hdmi_writeb(hdmi, STF_INNO_RX_CONTROL, STF_INNO_RX_ENABLE);
+
+	stf_inno_hdmi->tmds_rate = mode->clock * 1000;

Should not be necessary, use drm_connector_hdmi_state::tmds_char_rate which is already set for you.

Quoted 27 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +27 -0
+	inno_hdmi_starfive_phy_clk_set_rate(stf_inno_hdmi);
+
+	ret = readx_poll_timeout(readl_relaxed,
+				 hdmi->regs + (STF_INNO_PRE_PLL_LOCK_STATUS) * 0x04,
+				 val, val & 0x1, 1000, 100000);
+	if (ret < 0) {
+		dev_err(hdmi->dev, "failed to wait pre-pll lock\n");
+		return ret;
+	}
+
+	ret = readx_poll_timeout(readl_relaxed,
+				 hdmi->regs + (STF_INNO_POST_PLL_LOCK_STATUS) * 0x04,
+				 val, val & 0x1, 1000, 100000);
+	if (ret < 0) {
+		dev_err(hdmi->dev, "failed to wait post-pll lock\n");
+		return ret;
+	}
+
+	/*turn on LDO*/
+	hdmi_writeb(hdmi, STF_INNO_LDO_CONTROL, STF_INNO_LDO_ENABLE);
+	/*turn on serializer*/
+	hdmi_writeb(hdmi, STF_INNO_SERIALIER_CONTROL, STF_INNO_SERIALIER_ENABLE);
+
+	inno_hdmi_starfive_sys_power(hdmi, false);
+	inno_hdmi_starfive_config_video_timing(hdmi, mode);
+	inno_hdmi_starfive_sys_power(hdmi, true);
+

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 355

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+	inno_hdmi_starfive_tmds_driver_on(hdmi);
+	inno_hdmi_starfive_sync_tmds(hdmi);
+
+	return 0;
+}
+
+static enum drm_mode_status
+inno_hdmi_starfive_mode_valid(struct inno_hdmi *hdmi, const struct drm_display_mode *mode)
+{
+	int pclk = mode->clock * 1000;

This is drm_hdmi_compute_mode_clock().

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 359

Quoted 4 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +4 -0
+	bool valid = false;
+
+	if (pclk <= PIXCLOCK_4K_30FPS)
+		valid = true;

This looks like .tmds_char_rate_valid()

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 371

Quoted 12 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +12 -0
+
+	return (valid) ? MODE_OK : MODE_BAD;
+}
+
+static void inno_hdmi_starfive_encoder_enable(struct drm_encoder *encoder,
+					      struct drm_atomic_state *state)
+{
+	struct stf_inno_hdmi *sft_hdmi = to_starfive_inno_hdmi(encoder);
+	struct drm_connector_state *conn_state;
+	struct drm_crtc_state *crtc_state;
+
+	conn_state = drm_atomic_get_new_connector_state(state, sft_hdmi->connector);

Use drm_atomic_get_new_connector_for_encoder() to get connector.

Quoted 117 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +117 -0
+	if (WARN_ON(!conn_state))
+		return;
+
+	crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
+	if (WARN_ON(!crtc_state))
+		return;
+
+	inno_hdmi_starfive_setup(&sft_hdmi->inno_hdmi, &crtc_state->adjusted_mode);
+}
+
+static void inno_hdmi_starfive_encoder_disable(struct drm_encoder *encoder,
+					       struct drm_atomic_state *state)
+{
+	struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder);
+
+	inno_hdmi_starfive_sys_power(hdmi, false);
+}
+
+static int
+inno_hdmi_starfive_encoder_atomic_check(struct drm_encoder *encoder,
+					struct drm_crtc_state *crtc_state,
+					struct drm_connector_state *conn_state)
+{
+	struct vs_crtc_state *vs_crtc_state = to_vs_crtc_state(crtc_state);
+
+	vs_crtc_state->encoder_type = encoder->encoder_type;
+	vs_crtc_state->output_fmt = MEDIA_BUS_FMT_RGB888_1X24;
+
+	return 0;
+}
+
+static const struct drm_encoder_helper_funcs stf_inno_encoder_helper_funcs = {
+	.atomic_check   = inno_hdmi_starfive_encoder_atomic_check,
+	.atomic_enable  = inno_hdmi_starfive_encoder_enable,
+	.atomic_disable = inno_hdmi_starfive_encoder_disable,
+};
+
+static int inno_hdmi_starfive_get_clk_rst(struct device *dev, struct stf_inno_hdmi *stf_hdmi)
+{
+	int ret;
+
+	stf_hdmi->nclks = ARRAY_SIZE(stf_hdmi->clk_hdmi);
+
+	ret = devm_clk_bulk_get(dev, stf_hdmi->nclks, stf_hdmi->clk_hdmi);
+	if (ret) {
+		dev_err(dev, "Failed to get clk controls\n");
+		return ret;
+	}
+
+	stf_hdmi->tx_rst = devm_reset_control_get_by_index(dev, 0);
+	if (IS_ERR(stf_hdmi->tx_rst)) {
+		dev_err(dev, "failed to get tx_rst reset\n");
+		return PTR_ERR(stf_hdmi->tx_rst);
+	}
+
+	return 0;
+}
+
+static int inno_hdmi_starfive_bind(struct device *dev, struct device *master, void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct drm_device *drm = dev_get_drvdata(master);
+	struct stf_inno_hdmi *stf_hdmi;
+	struct inno_hdmi *hdmi;
+	struct drm_encoder *encoder;
+
+	int ret;
+	unsigned long long rate;
+
+	stf_hdmi = drmm_simple_encoder_alloc(drm, struct stf_inno_hdmi,
+					     encoder, DRM_MODE_ENCODER_TMDS);
+	if (IS_ERR(stf_hdmi))
+		return PTR_ERR(stf_hdmi);
+
+	hdmi = &stf_hdmi->inno_hdmi;
+	hdmi->dev = dev;
+
+	hdmi->plat_data = (struct inno_hdmi_plat_data *)of_device_get_match_data(dev);
+	if (!hdmi->plat_data)
+		return -ENODEV;
+
+	hdmi->regs = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(hdmi->regs))
+		return PTR_ERR(hdmi->regs);
+
+	ret = inno_hdmi_starfive_get_clk_rst(dev, stf_hdmi);
+	if (ret < 0)
+		return ret;
+
+	ret = inno_hdmi_starfive_enable_clk_rst(dev, stf_hdmi);
+	if (ret)
+		return ret;
+
+	rate = clk_get_rate(stf_hdmi->clk_hdmi[CLK_SYS].clk);
+	inno_hdmi_i2c_init(hdmi, rate);
+
+	ret = inno_hdmi_bind(drm, hdmi, &stf_hdmi->encoder);
+	if (ret)
+		goto err_disable_clk;
+
+	encoder = &stf_hdmi->encoder;
+
+	encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
+
+	/*
+	 * If we failed to find the CRTC(s) which this encoder is
+	 * supposed to be connected to, it's because the CRTC has
+	 * not been registered yet.  Defer probing, and hope that
+	 * the required CRTC is added later.
+	 */
+	if (encoder->possible_crtcs == 0)
+		return -EPROBE_DEFER;
+
+	drm_encoder_helper_add(encoder, &stf_inno_encoder_helper_funcs);
+
+	ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+	if (ret)

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 498

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+		return ret;
+
+	stf_hdmi->connector = drm_bridge_connector_init(drm, encoder);
+	if (IS_ERR(stf_hdmi->connector)) {
+		dev_err(dev, "Unable to create bridge connector\n");
+		ret = PTR_ERR(stf_hdmi->connector);
+		return ret;
+	}
+
+	drm_connector_attach_encoder(stf_hdmi->connector, encoder);

Please, don't store connector in your data.

Quoted 26 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +26 -0
+
+	dev_set_drvdata(dev, stf_hdmi);
+
+	return 0;
+
+err_disable_clk:
+	inno_hdmi_starfive_disable_clk_rst(dev, stf_hdmi);
+	return ret;
+}
+
+static void inno_hdmi_starfive_unbind(struct device *dev, struct device *master, void *data)
+{
+	struct stf_inno_hdmi *stf_hdmi = dev_get_drvdata(dev);
+
+	inno_hdmi_starfive_disable_clk_rst(dev, stf_hdmi);
+}
+
+static const struct component_ops inno_hdmi_starfive_ops = {
+	.bind	= inno_hdmi_starfive_bind,
+	.unbind	= inno_hdmi_starfive_unbind,
+};
+
+static int inno_hdmi_starfive_probe(struct platform_device *pdev)
+{
+	return component_add(&pdev->dev, &inno_hdmi_starfive_ops);
+}

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c line 534

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +10 -0
+
+static void inno_hdmi_starfive_remove(struct platform_device *pdev)
+{
+	component_del(&pdev->dev, &inno_hdmi_starfive_ops);
+}
+
+static const struct inno_hdmi_plat_data stf_inno_info = {
+	.vendor = "STARFIVE",
+	.product = "INNO HDMI",
+	.mode_valid = inno_hdmi_starfive_mode_valid,

No infoframes support, really?

Quoted 29 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c new file +19 -0
+};
+
+static const struct of_device_id starfive_hdmi_dt_ids[] = {
+	{ .compatible = "starfive,jh7110-inno-hdmi", .data = &stf_inno_info,},
+	{},
+};
+MODULE_DEVICE_TABLE(of, starfive_hdmi_dt_ids);
+
+struct platform_driver starfive_hdmi_driver = {
+	.probe  = inno_hdmi_starfive_probe,
+	.remove = inno_hdmi_starfive_remove,
+	.driver = {
+		.name = "starfive-hdmi",
+		.of_match_table = starfive_hdmi_dt_ids,
+	},
+};
+
+MODULE_AUTHOR("StarFive Corporation");
+MODULE_DESCRIPTION("Starfive Specific INNO-HDMI Driver");
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +4 -0
new file mode 100644
index 000000000000..db4d4578490d
@@ -0,0 +1,194 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) StarFive Technology Co., Ltd.
+ */

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h line 14

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +10 -0
+
+#ifndef __STARFIVE_HDMI_H__
+#define __STARFIVE_HDMI_H__
+
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+
+#define HDMI_SYNC			0xce
+
+#define UPDATE(x, h, l)			FIELD_PREP(GENMASK(h, l), x)

No extra wrappers

Quoted 32 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +32 -0
+#define HDMI_SYS_CTRL			0x00
+#define m_RST_ANALOG			(1 << 6)
+#define v_RST_ANALOG			(0 << 6)
+#define v_NOT_RST_ANALOG		(1 << 6)
+#define m_RST_DIGITAL			(1 << 5)
+#define v_RST_DIGITAL			(0 << 5)
+#define v_NOT_RST_DIGITAL		(1 << 5)
+#define m_REG_CLK_INV			(1 << 4)
+#define v_REG_CLK_NOT_INV		(0 << 4)
+#define v_REG_CLK_INV			(1 << 4)
+#define m_VCLK_INV			(1 << 3)
+#define v_VCLK_NOT_INV			(0 << 3)
+#define v_VCLK_INV			(1 << 3)
+#define m_REG_CLK_SOURCE		(1 << 2)
+#define v_REG_CLK_SOURCE_TMDS		(0 << 2)
+#define v_REG_CLK_SOURCE_SYS		(1 << 2)
+#define m_POWER				(1 << 1)
+#define v_PWR_ON			(0 << 1)
+#define v_PWR_OFF			(1 << 1)
+#define m_INT_POL			(1 << 0)
+#define v_INT_POL_HIGH			1
+#define v_INT_POL_LOW			0
+
+#define HDMI_VIDEO_TIMING_CTL		0x08
+#define v_VSYNC_POLARITY_SF(n)		((n) << 3)
+#define v_HSYNC_POLARITY_SF(n)		((n) << 2)
+#define v_INETLACE(n)			((n) << 1)
+#define v_EXTERANL_VIDEO(n)		((n) << 0)
+
+#define HDMI_VIDEO_EXT_HTOTAL_L		0x09
+#define HDMI_VIDEO_EXT_HTOTAL_H		0x0a
+#define HDMI_VIDEO_EXT_HBLANK_L		0x0b

drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h line 56

Quoted 10 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +10 -0
+#define HDMI_VIDEO_EXT_HBLANK_H		0x0c
+#define HDMI_VIDEO_EXT_HDELAY_L		0x0d
+#define HDMI_VIDEO_EXT_HDELAY_H		0x0e
+#define HDMI_VIDEO_EXT_HDURATION_L	0x0f
+#define HDMI_VIDEO_EXT_HDURATION_H	0x10
+#define HDMI_VIDEO_EXT_VTOTAL_L		0x11
+#define HDMI_VIDEO_EXT_VTOTAL_H		0x12
+#define HDMI_VIDEO_EXT_VBLANK		0x13
+#define HDMI_VIDEO_EXT_VDELAY		0x14
+#define HDMI_VIDEO_EXT_VDURATION	0x15

Which of these registers are common? Defined them in a single header file that can be used by all the drivers.

Quoted 141 lines
drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h new file +138 -0
+
+/* REG: 0x1a0 */
+#define STF_INNO_PRE_PLL_CONTROL			0x1a0
+#define STF_INNO_PCLK_VCO_DIV_5_MASK			BIT(1)
+#define STF_INNO_PCLK_VCO_DIV_5(x)			UPDATE(x, 1, 1)
+#define STF_INNO_PRE_PLL_POWER_DOWN			BIT(0)
+
+/* REG: 0x1a1 */
+#define STF_INNO_PRE_PLL_DIV_1				0x1a1
+#define STF_INNO_PRE_PLL_PRE_DIV_MASK			GENMASK(5, 0)
+#define STF_INNO_PRE_PLL_PRE_DIV(x)			UPDATE(x, 5, 0)
+
+/* REG: 0x1a2 */
+#define STF_INNO_PRE_PLL_DIV_2					0x1a2
+#define STF_INNO_SPREAD_SPECTRUM_MOD_DOWN		BIT(7)
+#define STF_INNO_SPREAD_SPECTRUM_MOD_DISABLE		BIT(6)
+#define STF_INNO_PRE_PLL_FRAC_DIV_DISABLE		UPDATE(3, 5, 4)
+#define STF_INNO_PRE_PLL_FB_DIV_11_8_MASK		GENMASK(3, 0)
+#define STF_INNO_PRE_PLL_FB_DIV_11_8(x)			UPDATE((x) >> 8, 3, 0)
+
+/* REG: 0x1a3 */
+#define STF_INNO_PRE_PLL_DIV_3				0x1a3
+#define STF_INNO_PRE_PLL_FB_DIV_7_0(x)			UPDATE(x, 7, 0)
+
+/* REG: 0x1a4*/
+#define STF_INNO_PRE_PLL_DIV_4				0x1a4
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_C_MASK		GENMASK(1, 0)
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_C(x)		UPDATE(x, 1, 0)
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_B_MASK		GENMASK(3, 2)
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_B(x)		UPDATE(x, 3, 2)
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_A_MASK		GENMASK(5, 4)
+#define STF_INNO_PRE_PLL_TMDSCLK_DIV_A(x)		UPDATE(x, 5, 4)
+
+/* REG: 0x1a5 */
+#define STF_INNO_PRE_PLL_DIV_5				0x1a5
+#define STF_INNO_PRE_PLL_PCLK_DIV_B_SHIFT		5
+#define STF_INNO_PRE_PLL_PCLK_DIV_B_MASK		GENMASK(6, 5)
+#define STF_INNO_PRE_PLL_PCLK_DIV_B(x)			UPDATE(x, 6, 5)
+#define STF_INNO_PRE_PLL_PCLK_DIV_A_MASK		GENMASK(4, 0)
+#define STF_INNO_PRE_PLL_PCLK_DIV_A(x)			UPDATE(x, 4, 0)
+
+/* REG: 0x1a6 */
+#define STF_INNO_PRE_PLL_DIV_6				0x1a6
+#define STF_INNO_PRE_PLL_PCLK_DIV_C_SHIFT		5
+#define STF_INNO_PRE_PLL_PCLK_DIV_C_MASK		GENMASK(6, 5)
+#define STF_INNO_PRE_PLL_PCLK_DIV_C(x)			UPDATE(x, 6, 5)
+#define STF_INNO_PRE_PLL_PCLK_DIV_D_MASK		GENMASK(4, 0)
+#define STF_INNO_PRE_PLL_PCLK_DIV_D(x)			UPDATE(x, 4, 0)
+
+/* REG: 0x1a9 */
+#define STF_INNO_PRE_PLL_LOCK_STATUS			0x1a9
+
+/* REG: 0x1aa */
+#define STF_INNO_POST_PLL_DIV_1				0x1aa
+#define STF_INNO_POST_PLL_POST_DIV_ENABLE		GENMASK(3, 2)
+#define STF_INNO_POST_PLL_REFCLK_SEL_TMDS		BIT(1)
+#define STF_INNO_POST_PLL_POWER_DOWN			BIT(0)
+#define STF_INNO_POST_PLL_FB_DIV_8(x)			UPDATE(((x) >> 8) << 4, 4, 4)
+
+/* REG:0x1ab */
+#define STF_INNO_POST_PLL_DIV_2				0x1ab
+#define STF_INNO_POST_PLL_Pre_DIV_MASK			GENMASK(5, 0)
+#define STF_INNO_POST_PLL_PRE_DIV(x)			UPDATE(x, 5, 0)
+
+/* REG: 0x1ac */
+#define STF_INNO_POST_PLL_DIV_3				0x1ac
+#define STF_INNO_POST_PLL_FB_DIV_7_0(x)			UPDATE(x, 7, 0)
+
+/* REG: 0x1ad */
+#define STF_INNO_POST_PLL_DIV_4				0x1ad
+#define STF_INNO_POST_PLL_POST_DIV_MASK			GENMASK(2, 0)
+#define STF_INNO_POST_PLL_POST_DIV_2			0x0
+#define STF_INNO_POST_PLL_POST_DIV_4			0x1
+#define STF_INNO_POST_PLL_POST_DIV_8			0x3
+
+/* REG: 0x1af */
+#define STF_INNO_POST_PLL_LOCK_STATUS			0x1af
+
+/* REG: 0x1b0 */
+#define STF_INNO_BIAS_CONTROL				0x1b0
+#define STF_INNO_BIAS_ENABLE				BIT(2)
+
+/* REG: 0x1b2 */
+#define STF_INNO_TMDS_CONTROL				0x1b2
+#define STF_INNO_TMDS_CLK_DRIVER_EN			BIT(3)
+#define STF_INNO_TMDS_D2_DRIVER_EN			BIT(2)
+#define STF_INNO_TMDS_D1_DRIVER_EN			BIT(1)
+#define STF_INNO_TMDS_D0_DRIVER_EN			BIT(0)
+#define STF_INNO_TMDS_DRIVER_ENABLE			(STF_INNO_TMDS_CLK_DRIVER_EN | \
+							 STF_INNO_TMDS_D2_DRIVER_EN | \
+							 STF_INNO_TMDS_D1_DRIVER_EN | \
+							 STF_INNO_TMDS_D0_DRIVER_EN)
+
+/* REG: 0x1b4 */
+#define STF_INNO_LDO_CONTROL				0x1b4
+#define STF_INNO_LDO_D2_EN				BIT(2)
+#define STF_INNO_LDO_D1_EN				BIT(1)
+#define STF_INNO_LDO_D0_EN				BIT(0)
+#define STF_INNO_LDO_ENABLE				(STF_INNO_LDO_D2_EN | \
+							 STF_INNO_LDO_D1_EN | \
+							 STF_INNO_LDO_D0_EN)
+
+/* REG: 0x1be */
+#define STF_INNO_SERIALIER_CONTROL			0x1be
+#define STF_INNO_SERIALIER_D2_EN			BIT(6)
+#define STF_INNO_SERIALIER_D1_EN			BIT(5)
+#define STF_INNO_SERIALIER_D0_EN			BIT(4)
+#define STF_INNO_SERIALIER_EN				BIT(0)
+
+#define STF_INNO_SERIALIER_ENABLE			(STF_INNO_SERIALIER_D2_EN | \
+							 STF_INNO_SERIALIER_D1_EN | \
+							 STF_INNO_SERIALIER_D0_EN | \
+							 STF_INNO_SERIALIER_EN)
+
+/* REG: 0x1cc */
+#define STF_INNO_RX_CONTROL				0x1cc
+#define STF_INNO_RX_EN					BIT(3)
+#define STF_INNO_RX_CHANNEL_2_EN			BIT(2)
+#define STF_INNO_RX_CHANNEL_1_EN			BIT(1)
+#define STF_INNO_RX_CHANNEL_0_EN			BIT(0)
+#define STF_INNO_RX_ENABLE				(STF_INNO_RX_EN | \
+							 STF_INNO_RX_CHANNEL_2_EN | \
+							 STF_INNO_RX_CHANNEL_1_EN | \
+							 STF_INNO_RX_CHANNEL_0_EN)
+
+/* REG: 0x1d1 */
+#define STF_INNO_PRE_PLL_FRAC_DIV_H			0x1d1
+#define STF_INNO_PRE_PLL_FRAC_DIV_23_16(x)		UPDATE((x) >> 16, 7, 0)
+/* REG: 0x1d2 */
+#define STF_INNO_PRE_PLL_FRAC_DIV_M			0x1d2
+#define STF_INNO_PRE_PLL_FRAC_DIV_15_8(x)		UPDATE((x) >> 8, 7, 0)
+/* REG: 0x1d3 */
+#define STF_INNO_PRE_PLL_FRAC_DIV_L			0x1d3
+#define STF_INNO_PRE_PLL_FRAC_DIV_7_0(x)		UPDATE(x, 7, 0)
+
+#define PIXCLOCK_4K_30FPS				297000000
+
+#endif /* __STARFIVE_HDMI_H__ */
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
author
#28 lore raw

PATCH v5 9/9 drm/vs: Add VS DRM Master Driver for JH7110 SoC

In reply to keith zhao

The VS DRM master driver for the JH7110 System on Chip (SoC), along with the addition of a DMA GEM (Graphics Execution Manager) driver

---
 drivers/gpu/drm/verisilicon/Makefile |   3 +-
 drivers/gpu/drm/verisilicon/vs_drv.c | 777 +++++++++++++++++++++++++++
 2 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
drivers/gpu/drm/verisilicon/Makefile +2 -1
index a602630c2416..67c94518d810 100644
@@ -3,7 +3,8 @@
 vs_drm-objs := vs_dc_hw.o \
 	       vs_modeset.o \
 	       vs_crtc.o \
-	       vs_plane.o
+	       vs_plane.o \
+	       vs_drv.o
 
 vs_drm-$(CONFIG_DRM_INNO_STARFIVE_HDMI) += inno_hdmi-starfive.o
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_drv.c new file +777 -0

777 lines not on this page · raw message

Signature · 1 line
2.34.1
#29 lore raw

Re: [PATCH v5 9/9] drm/vs: Add VS DRM Master Driver for JH7110 SoC

Quoted 116 lines · keith zhao

The VS DRM master driver for the JH7110 System on Chip (SoC), along with the addition of a DMA GEM (Graphics Execution Manager) driver

---
 drivers/gpu/drm/verisilicon/Makefile |   3 +-
 drivers/gpu/drm/verisilicon/vs_drv.c | 777 +++++++++++++++++++++++++++
 2 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c
drivers/gpu/drm/verisilicon/Makefile +2 -1
index a602630c2416..67c94518d810 100644
@@ -3,7 +3,8 @@
 vs_drm-objs := vs_dc_hw.o \
 	       vs_modeset.o \
 	       vs_crtc.o \
-	       vs_plane.o
+	       vs_plane.o \
+	       vs_drv.o
 
 vs_drm-$(CONFIG_DRM_INNO_STARFIVE_HDMI) += inno_hdmi-starfive.o
 obj-$(CONFIG_DRM_VERISILICON_DC8200) += vs_drm.o
drivers/gpu/drm/verisilicon/vs_drv.c new file +86 -0
new file mode 100644
index 000000000000..830dd0b1e9a0
@@ -0,0 +1,777 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) VeriSilicon Holdings Co., Ltd.
+ */
+#include <linux/clk.h>
+#include <linux/component.h>
+#include <linux/mfd/syscon.h>
+#include <linux/of_clk.h>
+#include <linux/of_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+
+#include <drm/drm_aperture.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_client_setup.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_file.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem_dma_helper.h>
+#include <drm/drm_module.h>
+#include <drm/drm_of.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "vs_drv.h"
+#include "vs_crtc.h"
+#include "vs_plane.h"
+#include "vs_modeset.h"
+
+#define DRV_NAME	"verisilicon"
+#define DRV_DESC	"Verisilicon DRM driver"
+#define DRV_DATE	"20230516"
+#define DRV_MAJOR	1
+#define DRV_MINOR	0
+
+#define FRAC_16_16(mult, div)	 (((mult) << 16) / (div))
+
+static const u32 primary_overlay_format[] = {
+	DRM_FORMAT_RGB565,
+	DRM_FORMAT_BGR565,
+	DRM_FORMAT_XRGB8888,
+	DRM_FORMAT_XBGR8888,
+	DRM_FORMAT_RGBX8888,
+	DRM_FORMAT_BGRX8888,
+	DRM_FORMAT_ARGB8888,
+	DRM_FORMAT_ABGR8888,
+	DRM_FORMAT_RGBA8888,
+	DRM_FORMAT_BGRA8888,
+	DRM_FORMAT_XRGB4444,
+	DRM_FORMAT_XBGR4444,
+	DRM_FORMAT_RGBX4444,
+	DRM_FORMAT_BGRX4444,
+	DRM_FORMAT_ARGB4444,
+	DRM_FORMAT_ABGR4444,
+	DRM_FORMAT_RGBA4444,
+	DRM_FORMAT_BGRA4444,
+	DRM_FORMAT_XRGB1555,
+	DRM_FORMAT_XBGR1555,
+	DRM_FORMAT_RGBX5551,
+	DRM_FORMAT_BGRX5551,
+	DRM_FORMAT_ARGB1555,
+	DRM_FORMAT_ABGR1555,
+	DRM_FORMAT_RGBA5551,
+	DRM_FORMAT_BGRA5551,
+	DRM_FORMAT_ARGB2101010,
+	DRM_FORMAT_ABGR2101010,
+	DRM_FORMAT_RGBA1010102,
+	DRM_FORMAT_BGRA1010102,
+	DRM_FORMAT_YUYV,
+	DRM_FORMAT_YVYU,
+	DRM_FORMAT_UYVY,
+	DRM_FORMAT_VYUY,
+	DRM_FORMAT_YVU420,
+	DRM_FORMAT_YUV420,
+	DRM_FORMAT_NV12,
+	DRM_FORMAT_NV21,
+	DRM_FORMAT_NV16,
+	DRM_FORMAT_NV61,
+	DRM_FORMAT_P010,
+};
+
+static const u32 cursor_formats[] = {
+	DRM_FORMAT_ARGB8888
+};

drivers/gpu/drm/verisilicon/vs_drv.c line 96

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +10 -0
+
+static const u64 format_modifier[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID
+};
+
+static const u64 secondary_format_modifiers[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID
+};

Same as primary

Quoted 320 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +320 -0
+
+static const struct vs_plane_data vs_plane_pri0 = {
+		.num_formats	= ARRAY_SIZE(primary_overlay_format),
+		.formats		= primary_overlay_format,
+		.num_modifiers	= ARRAY_SIZE(format_modifier),
+		.modifiers		= format_modifier,
+		.min_width		= 0,
+		.min_height		= 0,
+		.max_width		= 4096,
+		.max_height		= 4096,
+		.min_scale		= FRAC_16_16(1, 3),
+		.max_scale		= FRAC_16_16(10, 1),
+		.rotation		= DRM_MODE_ROTATE_0 |
+					  DRM_MODE_ROTATE_90 |
+					  DRM_MODE_ROTATE_180 |
+					  DRM_MODE_ROTATE_270 |
+					  DRM_MODE_REFLECT_X |
+					  DRM_MODE_REFLECT_Y,
+		.color_encoding	= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+		.zpos			= 0,
+};
+
+static const struct vs_plane_data vs_plane_pri1 = {
+		.num_formats		= ARRAY_SIZE(primary_overlay_format),
+		.formats		= primary_overlay_format,
+		.num_modifiers		= ARRAY_SIZE(format_modifier),
+		.modifiers		= format_modifier,
+		.min_width		= 0,
+		.min_height		= 0,
+		.max_width		= 4096,
+		.max_height		= 4096,
+		.min_scale		= FRAC_16_16(1, 3),
+		.max_scale		= FRAC_16_16(10, 1),
+		.rotation		= DRM_MODE_ROTATE_0 |
+					  DRM_MODE_ROTATE_90 |
+					  DRM_MODE_ROTATE_180 |
+					  DRM_MODE_ROTATE_270 |
+					  DRM_MODE_REFLECT_X |
+					  DRM_MODE_REFLECT_Y,
+		.color_encoding		= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+		.zpos			= 3,
+};
+
+static const struct vs_plane_data vs_plane_over0 = {
+		.num_formats		= ARRAY_SIZE(primary_overlay_format),
+		.formats		= primary_overlay_format,
+		.num_modifiers		= ARRAY_SIZE(format_modifier),
+		.modifiers		= format_modifier,
+		.min_width		= 0,
+		.min_height		= 0,
+		.max_width		= 4096,
+		.max_height		= 4096,
+		.min_scale		= FRAC_16_16(1, 3),
+		.max_scale		= FRAC_16_16(10, 1),
+		.rotation		= DRM_MODE_ROTATE_0 |
+					  DRM_MODE_ROTATE_90 |
+					  DRM_MODE_ROTATE_180 |
+					  DRM_MODE_ROTATE_270 |
+					  DRM_MODE_REFLECT_X |
+					  DRM_MODE_REFLECT_Y,
+		.color_encoding		= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+		.zpos			= 1,
+};
+
+static const struct vs_plane_data vs_plane_over1 = {
+		.num_formats		= ARRAY_SIZE(primary_overlay_format),
+		.formats		= primary_overlay_format,
+		.num_modifiers		= ARRAY_SIZE(secondary_format_modifiers),
+		.modifiers		= secondary_format_modifiers,
+		.min_width		= 0,
+		.min_height		= 0,
+		.max_width		= 4096,
+		.max_height		= 4096,
+		.min_scale		= DRM_PLANE_NO_SCALING,
+		.max_scale		= DRM_PLANE_NO_SCALING,
+		.rotation		= 0,
+		.color_encoding		= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+		.zpos			= 2,
+};
+
+static const struct vs_plane_data vs_plane_over2 = {
+	.num_formats		= ARRAY_SIZE(primary_overlay_format),
+	.formats		= primary_overlay_format,
+	.num_modifiers		= ARRAY_SIZE(format_modifier),
+	.modifiers		= format_modifier,
+	.min_width		= 0,
+	.min_height		= 0,
+	.max_width		= 4096,
+	.max_height		= 4096,
+	.min_scale		= FRAC_16_16(1, 3),
+	.max_scale		= FRAC_16_16(10, 1),
+	.rotation		= DRM_MODE_ROTATE_0 |
+				  DRM_MODE_ROTATE_90 |
+				  DRM_MODE_ROTATE_180 |
+				  DRM_MODE_ROTATE_270 |
+				  DRM_MODE_REFLECT_X |
+				  DRM_MODE_REFLECT_Y,
+	.color_encoding		= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+	.zpos			= 4,
+};
+
+static const struct vs_plane_data vs_plane_over3 = {
+		.num_formats	= ARRAY_SIZE(primary_overlay_format),
+		.formats		= primary_overlay_format,
+		.num_modifiers	= ARRAY_SIZE(format_modifier),
+		.modifiers		= format_modifier,
+		.min_width		= 0,
+		.min_height		= 0,
+		.max_width		= 4096,
+		.max_height		= 4096,
+		.min_scale		= FRAC_16_16(1, 3),
+		.max_scale		= FRAC_16_16(10, 1),
+		.rotation		= DRM_MODE_ROTATE_0 |
+					  DRM_MODE_ROTATE_90 |
+					  DRM_MODE_ROTATE_180 |
+					  DRM_MODE_ROTATE_270 |
+					  DRM_MODE_REFLECT_X |
+					  DRM_MODE_REFLECT_Y,
+		.color_encoding	= BIT(DRM_COLOR_YCBCR_BT709) | BIT(DRM_COLOR_YCBCR_BT2020),
+		.zpos			= 5,
+};
+
+static const struct vs_plane_data vs_plane_cur0 = {
+	.num_formats		= ARRAY_SIZE(cursor_formats),
+	.formats		= cursor_formats,
+	.min_width		= 32,
+	.min_height		= 32,
+	.max_width		= 64,
+	.max_height		= 64,
+	.min_scale		= DRM_PLANE_NO_SCALING,
+	.max_scale		= DRM_PLANE_NO_SCALING,
+	.zpos			= 255,
+};
+
+static const struct vs_plane_data vs_plane_cur1 = {
+	.num_formats		= ARRAY_SIZE(cursor_formats),
+	.formats		= cursor_formats,
+	.min_width		= 32,
+	.min_height		= 32,
+	.max_width		= 64,
+	.max_height		= 64,
+	.zpos			= 255,
+};
+
+static const struct vs_plane_info info[] = {
+	{.id = PRIMARY_PLANE_0, .data = &vs_plane_pri0,
+	 .type = DRM_PLANE_TYPE_PRIMARY},
+	{.id = OVERLAY_PLANE_0, .data = &vs_plane_over0,
+	 .type = DRM_PLANE_TYPE_OVERLAY},
+	{.id = OVERLAY_PLANE_1, .data = &vs_plane_over1,
+	 .type = DRM_PLANE_TYPE_OVERLAY},
+	{.id = PRIMARY_PLANE_1, .data = &vs_plane_pri1,
+	 .type = DRM_PLANE_TYPE_PRIMARY},
+	{.id = OVERLAY_PLANE_2, .data = &vs_plane_over2,
+	 .type = DRM_PLANE_TYPE_OVERLAY},
+	{.id = OVERLAY_PLANE_3, .data = &vs_plane_over3,
+	 .type = DRM_PLANE_TYPE_OVERLAY},
+	{.id = CURSOR_PLANE_0, .data = &vs_plane_cur0,
+	 .type = DRM_PLANE_TYPE_CURSOR},
+	{.id = CURSOR_PLANE_1, .data = &vs_plane_cur1,
+	 .type = DRM_PLANE_TYPE_CURSOR},
+};
+
+static const struct vs_dc_info dc8200_info = {
+	.name			= "DC8200",
+	.plane_num      = ARRAY_SIZE(info),
+	.panel_num		= 2,
+	.info		= info,
+	.layer_num		= 6,
+	.gamma_size		= GAMMA_EX_SIZE,
+	.gamma_bits		= 12,
+	.pitch_alignment	= 128,
+};
+
+#define STARFIVE_SOC_CON8		0x08
+# define STARFIVE_MIPI_SEL		BIT(3)
+
+static int vs_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
+			      struct drm_mode_create_dumb *args)
+{
+	struct vs_drm_device *priv = to_vs_drm_private(dev);
+	unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+
+	args->pitch = ALIGN(pitch, priv->pitch_alignment);
+	return drm_gem_dma_dumb_create_internal(file, dev, args);
+}
+
+DEFINE_DRM_GEM_FOPS(vs_drm_fops);
+
+static struct drm_driver vs_drm_driver = {
+	.driver_features	= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
+
+	DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vs_gem_dumb_create),
+
+	.fops			= &vs_drm_fops,
+	.name			= DRV_NAME,
+	.desc			= DRV_DESC,
+	.date			= DRV_DATE,
+	.major			= DRV_MAJOR,
+	.minor			= DRV_MINOR,
+};
+
+static irqreturn_t vs_dc_isr(int irq, void *data)
+{
+	struct vs_drm_device *priv = data;
+	struct vs_dc *dc = &priv->dc;
+	u8 status = 0;
+
+	dc_hw_get_interrupt(&dc->hw, &status);
+
+	if (status & BIT(0))
+		drm_crtc_handle_vblank(&dc->crtc[0]->base);
+
+	if (status & BIT(1))
+		drm_crtc_handle_vblank(&dc->crtc[1]->base);
+
+	return IRQ_HANDLED;
+}
+
+static int vs_drm_device_init_res(struct vs_drm_device *priv)
+{
+	struct device *dev = priv->base.dev;
+	struct platform_device *pdev = to_platform_device(dev);
+	int ret;
+	struct vs_dc *dc;
+
+	dc = &priv->dc;
+	dc->hw.hi_base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(dc->hw.hi_base))
+		return PTR_ERR(dc->hw.hi_base);
+
+	dc->hw.reg_base = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(dc->hw.reg_base))
+		return PTR_ERR(dc->hw.reg_base);
+
+	dc->hw.info = (struct vs_dc_info *)of_device_get_match_data(dev);
+
+	ret = devm_clk_bulk_get_all(dev, &priv->clks);
+	if (ret < 0) {
+		dev_err(dev, "can't get vout clock, ret=%d\n", ret);
+		return ret;
+	}
+	priv->clk_count = ret;
+
+	priv->rsts = devm_reset_control_array_get_shared(dev);
+	if (IS_ERR(priv->rsts))
+		return PTR_ERR(priv->rsts);
+
+	priv->irq = platform_get_irq(pdev, 0);
+
+	/* do not autoenable, will be enabled later */
+	ret = devm_request_irq(dev, priv->irq, vs_dc_isr, IRQF_NO_AUTOEN, dev_name(dev), priv);
+	if (ret < 0) {
+		dev_err(dev, "Failed to install irq:%u.\n", priv->irq);
+		return ret;
+	}
+
+	priv->dc_syscon_regmap = syscon_regmap_lookup_by_phandle(dev->of_node,
+						"starfive,syscon");
+	if (IS_ERR(priv->dc_syscon_regmap)) {
+		dev_err(dev, "failed to get starfive,syscon property\n");
+		return PTR_ERR(priv->dc_syscon_regmap);
+	}
+
+	return ret;
+}
+
+static u32 vs_get_addr_offset(u32 id)
+{
+	u32 offset = 0;
+
+	switch (id) {
+	case PRIMARY_PLANE_1:
+	case OVERLAY_PLANE_1:
+		offset = 0x04;
+		break;
+	case OVERLAY_PLANE_2:
+		offset = 0x08;
+		break;
+	case OVERLAY_PLANE_3:
+		offset = 0x0C;
+		break;
+	default:
+		break;
+	}
+
+	return offset;
+}
+
+static u32 vs_map_possible_crtc(u32 id)
+{
+	switch (id) {
+	case PRIMARY_PLANE_0:
+	case CURSOR_PLANE_0:
+		return 0x01;//crtc0
+	case PRIMARY_PLANE_1:
+	case CURSOR_PLANE_1:
+		return 0x02;//crtc1
+	default:
+		return 0x03;//crtc0&crtc1
+	}
+}
+
+static int vs_kms_init(struct vs_drm_device *priv)
+{
+	struct vs_dc *dc;
+	struct drm_device *drm_dev;
+	int i, ret;
+	struct device_node *port;
+	struct vs_crtc *crtc;
+	struct vs_dc_info *dc_info;
+	struct vs_plane_info *plane_info;
+	struct vs_plane *plane;
+
+	u32 max_width = 0, max_height = 0;
+	u32 min_width = 0xffff, min_heigth = 0xffff;
+
+	dc = &priv->dc;
+	dc_info = dc->hw.info;
+	drm_dev = &priv->base;

drivers/gpu/drm/verisilicon/vs_drv.c line 426

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +10 -0
+
+	for (i = 0; i < dc_info->panel_num; i++) {
+		crtc = vs_crtc_create(drm_dev, dc_info);
+		if (!crtc) {
+			drm_err(drm_dev, "Failed to create CRTC.\n");
+			ret = -ENOMEM;
+			return ret;
+		}
+		crtc->dev = drm_dev->dev;
+		crtc->index = i;

Do you actually need .index? Can you pass panel data directly to CRTC functions?

drivers/gpu/drm/verisilicon/vs_drv.c line 434

Quoted 8 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +8 -0
+
+		port = of_graph_get_port_by_id(crtc->dev->of_node, i);
+		if (!port) {
+			drm_err(drm_dev, "no port node found for crtc_port%d\n", i);
+			return -ENOENT;
+		}
+
+		crtc->base.port = port;

Set those fields from vs_crtc_create(), removing the need to export the structure.

drivers/gpu/drm/verisilicon/vs_drv.c line 437

Quoted 3 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +3 -0
+		dc->crtc[i] = crtc;
+
+		of_node_put(port);

I have mixed feelings towards freeing the node here. Please move it to the driver cleanup.

Quoted 6 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +6 -0
+	}
+
+	if (!dc->crtc[0]->base.port || !dc->crtc[1]->base.port) {
+		drm_err(drm_dev, "no port no crtc mask, fail to create plane\n");
+		return -ENOENT;
+	}

drivers/gpu/drm/verisilicon/vs_drv.c line 453

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +10 -0
+
+	for (i = 0; i < dc_info->plane_num; i++) {
+		plane_info = (struct vs_plane_info *)&dc_info->info[i];
+
+		plane = vs_plane_create(drm_dev, plane_info, dc_info->layer_num,
+					vs_map_possible_crtc(plane_info->id));
+
+		plane->id = i;
+		dc->planes[i].id = plane_info->id;
+		dc->planes[i].offset = vs_get_addr_offset(plane_info->id);

Same comment. Ideally please pass all data to vs_plane_craete().

Quoted 230 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +230 -0
+
+		if (plane_info->type == DRM_PLANE_TYPE_PRIMARY) {
+			if (plane_info->id == PRIMARY_PLANE_0)
+				dc->crtc[0]->base.primary = &plane->base;
+			else
+				dc->crtc[1]->base.primary = &plane->base;
+			min_width = min_t(u32, min_width, plane_info->data->min_width);
+			min_heigth = min_t(u32, min_heigth, plane_info->data->min_height);
+			/*
+			 * Note: these values are used for multiple independent things:
+			 * hw display mode filtering, plane buffer sizes ...
+			 * Use the combined maximum values here to cover all use cases,
+			 * and do more specific checking in the respective code paths.
+			 */
+			max_width = max_t(u32, max_width, plane_info->data->max_width);
+			max_height = max_t(u32, max_height, plane_info->data->max_height);
+		}
+
+		if (plane_info->type == DRM_PLANE_TYPE_CURSOR) {
+			if (plane_info->id == CURSOR_PLANE_0)
+				dc->crtc[0]->base.cursor = &plane->base;
+			else
+				dc->crtc[1]->base.cursor = &plane->base;
+			drm_dev->mode_config.cursor_width = plane_info->data->max_width;
+			drm_dev->mode_config.cursor_height = plane_info->data->max_height;
+		}
+	}
+
+	drm_dev->mode_config.min_width = min_width;
+	drm_dev->mode_config.min_height = min_heigth;
+	drm_dev->mode_config.max_width = max_width;
+	drm_dev->mode_config.max_height = max_height;
+
+	if (dc_info->pitch_alignment > priv->pitch_alignment)
+		priv->pitch_alignment = dc_info->pitch_alignment;
+
+	return 0;
+}
+
+static int vs_load(struct vs_drm_device *priv)
+{
+	int ret;
+
+	ret = clk_bulk_prepare_enable(priv->clk_count, priv->clks);
+	if (ret)
+		return ret;
+
+	reset_control_deassert(priv->rsts);
+
+	ret = dc_hw_init(&priv->dc);
+	if (ret) {
+		DRM_ERROR("failed to init DC HW\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void vs_mipi_encoder_disable(struct drm_encoder *encoder)
+{
+	struct drm_device *dev = encoder->dev;
+	struct vs_drm_device *priv = to_vs_drm_private(dev);
+	int idx;
+
+	if (!drm_dev_enter(dev, &idx))
+		return;
+
+	regmap_update_bits(priv->dc_syscon_regmap, STARFIVE_SOC_CON8, STARFIVE_MIPI_SEL, 0);
+
+	drm_dev_exit(idx);
+}
+
+static void vs_mipi_encoder_enable(struct drm_encoder *encoder)
+{
+	struct drm_device *dev = encoder->dev;
+	struct vs_drm_device *priv = to_vs_drm_private(dev);
+	int idx;
+
+	if (!drm_dev_enter(dev, &idx))
+		return;
+
+	regmap_update_bits(priv->dc_syscon_regmap, STARFIVE_SOC_CON8, STARFIVE_MIPI_SEL, BIT(3));
+
+	drm_dev_exit(idx);
+}
+
+static const struct drm_encoder_helper_funcs vs_mipi_encoder_helper_funcs = {
+	.disable = vs_mipi_encoder_disable,
+	.enable = vs_mipi_encoder_enable,
+};
+
+static int vs_attach_mipi_bridge(struct vs_drm_device *priv)
+{
+	struct device *dev = priv->base.dev;
+	struct drm_bridge *bridge;
+	struct drm_encoder *encoder;
+	int ret;
+
+	bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 1);
+	if (IS_ERR(bridge)) {
+		if (PTR_ERR(bridge) == -ENODEV) {
+			bridge = NULL;
+			return 0;
+		}
+
+		return PTR_ERR(bridge);
+	}
+
+	/* Create the encoder and attach the bridge. */
+	encoder = devm_kzalloc(dev, sizeof(*encoder), GFP_KERNEL);
+	if (!encoder)
+		return -ENOMEM;
+
+	encoder->possible_crtcs = drm_crtc_mask(&priv->dc.crtc[1]->base);
+
+	ret = drmm_encoder_init(&priv->base, encoder, NULL, DRM_MODE_ENCODER_DSI, NULL);
+	if (ret) {
+		dev_err(dev, "Failed to initialize encoder\n");
+		return ret;
+	}
+
+	drm_encoder_helper_add(encoder, &vs_mipi_encoder_helper_funcs);
+
+	ret = drm_bridge_attach(encoder, bridge, NULL, 0);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to attach bridge\n");
+
+	return 0;
+}
+
+static int vs_drm_bind(struct device *dev)
+{
+	struct vs_drm_device *priv;
+	int ret;
+	struct drm_device *drm_dev;
+
+	priv = devm_drm_dev_alloc(dev, &vs_drm_driver, struct vs_drm_device, base);
+	if (IS_ERR(priv))
+		return PTR_ERR(priv);
+
+	priv->pitch_alignment = 64;
+	drm_dev = &priv->base;
+	dev_set_drvdata(dev, drm_dev);
+
+	ret = dma_set_coherent_mask(drm_dev->dev, DMA_BIT_MASK(40));
+	if (ret)
+		return ret;
+
+	ret = vs_drm_device_init_res(priv);
+	if (ret)
+		return ret;
+
+	vs_mode_config_init(drm_dev);
+
+	/* Remove existing drivers that may own the framebuffer memory. */
+	ret = drm_aperture_remove_framebuffers(&vs_drm_driver);
+	if (ret)
+		return ret;
+
+	ret = vs_kms_init(priv);
+	if (ret) {
+		DRM_ERROR("Failed to initialize KMS pipeline\n");
+		return ret;
+	}
+
+	ret = vs_load(priv);
+	if (ret)
+		return ret;
+
+	/* Now try and bind all our sub-components */
+	ret = component_bind_all(dev, drm_dev);
+	if (ret) {
+		ret = -EPROBE_DEFER;
+		goto unload;
+	}
+
+	ret = vs_attach_mipi_bridge(priv);
+	if (ret)
+		goto err_unbind_all;
+
+	ret = drm_vblank_init(drm_dev, drm_dev->mode_config.num_crtc);
+	if (ret)
+		goto err_unbind_all;
+
+	drm_mode_config_reset(drm_dev);
+
+	ret = drmm_kms_helper_poll_init(drm_dev);
+	if (ret)
+		goto err_unbind_all;
+
+	ret = drm_dev_register(drm_dev, 0);
+	if (ret)
+		goto err_unbind_all;
+
+	drm_client_setup(drm_dev, NULL);
+
+	return 0;
+
+err_unbind_all:
+	component_unbind_all(drm_dev->dev, drm_dev);
+unload:
+	reset_control_assert(priv->rsts);
+	clk_bulk_disable_unprepare(priv->clk_count, priv->clks);
+	return ret;
+}
+
+static void vs_drm_unbind(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct vs_drm_device *priv = to_vs_drm_private(drm_dev);
+
+	reset_control_assert(priv->rsts);
+	clk_bulk_disable_unprepare(priv->clk_count, priv->clks);
+
+	drm_dev_unregister(drm_dev);
+	drm_atomic_helper_shutdown(drm_dev);
+	component_unbind_all(drm_dev->dev, drm_dev);
+}
+
+static const struct component_master_ops vs_drm_ops = {
+	.bind = vs_drm_bind,
+	.unbind = vs_drm_unbind,
+};
+
+static struct platform_driver *drm_sub_drivers[] = {
+#ifdef CONFIG_DRM_INNO_STARFIVE_HDMI
+	&starfive_hdmi_driver,
+#endif
+};
+

drivers/gpu/drm/verisilicon/vs_drv.c line 693

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +10 -0
+static struct component_match *vs_add_external_components(struct device *dev)
+{
+	struct component_match *match = NULL;
+	struct device_node *node;
+
+#ifdef CONFIG_DRM_INNO_STARFIVE_HDMI
+	node = of_graph_get_remote_node(dev->of_node, 0, 0);
+	drm_of_component_match_add(dev, &match, component_compare_of, node);
+	of_node_put(node);
+#endif

Having #ifndef in the function body is a frowned upon practice.

Quoted 49 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +49 -0
+
+	return match ? match : ERR_PTR(-ENODEV);
+}
+
+static int vs_drm_platform_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct component_match *match;
+
+	/* all the planes and CRTC would be created in this platform device,
+	 * so external components are encoder + connector
+	 */
+	match = vs_add_external_components(dev);
+	if (IS_ERR(match))
+		return PTR_ERR(match);
+
+	return component_master_add_with_match(dev, &vs_drm_ops, match);
+}
+
+static void vs_drm_platform_remove(struct platform_device *pdev)
+{
+	component_master_del(&pdev->dev, &vs_drm_ops);
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int vs_drm_suspend(struct device *dev)
+{
+	return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
+}
+
+static int vs_drm_resume(struct device *dev)
+{
+	drm_mode_config_helper_resume(dev_get_drvdata(dev));
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(vs_drm_pm_ops, vs_drm_suspend, vs_drm_resume);
+
+static const struct of_device_id vs_drm_dt_ids[] = {
+	{ .compatible = "starfive,jh7110-dc8200", .data = &dc8200_info,},
+	{ },
+};
+
+MODULE_DEVICE_TABLE(of, vs_drm_dt_ids);
+
+static struct platform_driver vs_drm_platform_driver = {
+	.probe = vs_drm_platform_probe,

drivers/gpu/drm/verisilicon/vs_drv.c line 752

Quoted 10 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +10 -0
+	.remove = vs_drm_platform_remove,
+
+	.driver = {
+		.name = DRV_NAME,
+		.of_match_table = vs_drm_dt_ids,
+		.pm = &vs_drm_pm_ops,
+	},
+};
+
+static int __init vs_drm_init(void)

Generic comment: Please settle on some common prefix for all your functions and data structures. vs_dc_nnnnn() sounds good enough from my POV.

Quoted 28 lines
drivers/gpu/drm/verisilicon/vs_drv.c new file +25 -0
+{
+	int ret;
+
+	ret = platform_register_drivers(drm_sub_drivers, ARRAY_SIZE(drm_sub_drivers));
+	if (ret)
+		return ret;
+
+	ret = drm_platform_driver_register(&vs_drm_platform_driver);
+	if (ret)
+		platform_unregister_drivers(drm_sub_drivers, ARRAY_SIZE(drm_sub_drivers));
+
+	return ret;
+}
+
+static void __exit vs_drm_fini(void)
+{
+	platform_driver_unregister(&vs_drm_platform_driver);
+	platform_unregister_drivers(drm_sub_drivers, ARRAY_SIZE(drm_sub_drivers));
+}
+
+module_init(vs_drm_init);
+module_exit(vs_drm_fini);
+
+MODULE_DESCRIPTION("VeriSilicon DRM Driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry
#30 lore raw
In reply to keith zhao
Quoted 118 lines · keith zhao

Verisilicon/DC8200 display controller IP has 2 display pipes and each pipe support a primary plane and a cursor plane .
In addition, there are 4 overlay planes as 2 display pipes common resources.

The first display pipe is bound to the inno HDMI encoder. The second display pipe is bound to Internal custom encoder, which is used to find dsi bridge by dts node.

This patchset should be applied on next branch.

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop vs_crtc_funcs&vs_plane_funcs, subdivide the plane's help interface.
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module

V3:
Changes since v3:
- Delete the custom plane property.
- Delete the custom fourcc modifiers.
- Adjust the calculation mode of hdmi pixclock.
- Add match data for dc8200 driver.
- Adjust some magic values.
- Add a simple encoder for dsi output.

V4:
Changes since v4:
- Delete the display subsystem module as all crtcs and planes are a driver.
- Delete the custom struct, directly use the drm struct data.
- Tidy up the inno hdmi public interface.
- Add a simple encoder for dsi output.

V5:
Changes since v5:
- Refine the Innosilicon HDMI by quoting bridge abstracting.
- Delete the encoder driver, which is created directly by internal functions.
- Adapt to the changes in kernel upgrade APIs, such as drm_client_setup.

keith zhao (9):
dt-bindings: display: bindings for starfive,JH7110 display pipeline
riscv: dts: Add display property
drm: bridge: inno-hdmi: add inno bridge driver.
drm/vs: Add Hardware Functions for VS DC8200
drm/vs: Add Base API for VS Mode Configuration
drm/vs: Add CRTC Functions
drm/vs: Add VS Plane API
drm/vs: Add Innosilicon HDMI Support
drm/vs: Add VS DRM Master Driver for JH7110 SoC

  .../display/bridge/innosilicon,inno-hdmi.yaml |   45 +
  .../display/rockchip/rockchip,inno-hdmi.yaml  |   27 +-
  .../starfive/starfive,jh7110-dc8200.yaml      |  176 +++
  .../starfive/starfive,jh7110-inno-hdmi.yaml   |   91 ++
  .../soc/starfive/starfive,jh7110-syscon.yaml  |    1 +
  MAINTAINERS                                   |   11 +
  .../boot/dts/starfive/jh7110-common.dtsi      |  125 ++
  arch/riscv/boot/dts/starfive/jh7110.dtsi      |   41 +
  drivers/gpu/drm/Kconfig                       |    2 +
  drivers/gpu/drm/Makefile                      |    1 +
  drivers/gpu/drm/bridge/Kconfig                |    2 +
  drivers/gpu/drm/bridge/Makefile               |    1 +
  drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
  drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
  .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
  .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
  drivers/gpu/drm/rockchip/Kconfig              |    1 +
  drivers/gpu/drm/rockchip/Makefile             |    2 +-
  drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
  .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
  drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 ---------------
  drivers/gpu/drm/verisilicon/Kconfig           |   32 +
  drivers/gpu/drm/verisilicon/Makefile          |   10 +
  .../gpu/drm/verisilicon/inno_hdmi-starfive.c  |  553 +++++++++
  .../gpu/drm/verisilicon/inno_hdmi-starfive.h  |  194 +++
  drivers/gpu/drm/verisilicon/vs_crtc.c         |  241 ++++
  drivers/gpu/drm/verisilicon/vs_crtc.h         |   42 +
  drivers/gpu/drm/verisilicon/vs_dc_hw.c        | 1104 +++++++++++++++++
  drivers/gpu/drm/verisilicon/vs_dc_hw.h        |  492 ++++++++
  drivers/gpu/drm/verisilicon/vs_drv.c          |  777 ++++++++++++
  drivers/gpu/drm/verisilicon/vs_drv.h          |   41 +
  drivers/gpu/drm/verisilicon/vs_modeset.c      |   31 +
  drivers/gpu/drm/verisilicon/vs_modeset.h      |   10 +
  drivers/gpu/drm/verisilicon/vs_plane.c        |  358 ++++++
  drivers/gpu/drm/verisilicon/vs_plane.h        |   27 +
  drivers/gpu/drm/verisilicon/vs_type.h         |   54 +
  include/drm/bridge/inno_hdmi.h                |   56 +
  37 files changed, 5630 insertions(+), 1051 deletions(-)

create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
create mode 100644 drivers/gpu/drm/verisilicon/Makefile
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h

Quoted 9 lines

create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h create mode 100644 include/drm/bridge/inno_hdmi.h

Is this patch series still being worked on? If not I would like to give it a try to fix it up and get it merged.

Would like to get it working on my deepcomputing fml13v01 board, there is also a gpu driver for the thead th1520 being worked on by Michal Wilczynski that depends on this. Would be nice if that could get merged when it is ready.

Kind regards,
Maud

#31 lore raw
Quoted 129 lines · Maud Spierings
Quoted 118 lines · keith zhao

Verisilicon/DC8200 display controller IP has 2 display pipes and each pipe support a primary plane and a cursor plane .
In addition, there are 4 overlay planes as 2 display pipes common resources.

The first display pipe is bound to the inno HDMI encoder. The second display pipe is bound to Internal custom encoder, which is used to find dsi bridge by dts node.

This patchset should be applied on next branch.

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop vs_crtc_funcs&vs_plane_funcs, subdivide the plane's help interface.
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module

V3:
Changes since v3:
- Delete the custom plane property.
- Delete the custom fourcc modifiers.
- Adjust the calculation mode of hdmi pixclock.
- Add match data for dc8200 driver.
- Adjust some magic values.
- Add a simple encoder for dsi output.

V4:
Changes since v4:
- Delete the display subsystem module as all crtcs and planes are a driver.
- Delete the custom struct, directly use the drm struct data.
- Tidy up the inno hdmi public interface.
- Add a simple encoder for dsi output.

V5:
Changes since v5:
- Refine the Innosilicon HDMI by quoting bridge abstracting.
- Delete the encoder driver, which is created directly by internal functions.
- Adapt to the changes in kernel upgrade APIs, such as drm_client_setup.

keith zhao (9):
dt-bindings: display: bindings for starfive,JH7110 display pipeline
riscv: dts: Add display property
drm: bridge: inno-hdmi: add inno bridge driver.
drm/vs: Add Hardware Functions for VS DC8200
drm/vs: Add Base API for VS Mode Configuration
drm/vs: Add CRTC Functions
drm/vs: Add VS Plane API
drm/vs: Add Innosilicon HDMI Support
drm/vs: Add VS DRM Master Driver for JH7110 SoC

  .../display/bridge/innosilicon,inno-hdmi.yaml |   45 +
  .../display/rockchip/rockchip,inno-hdmi.yaml  |   27 +-
  .../starfive/starfive,jh7110-dc8200.yaml      |  176 +++
  .../starfive/starfive,jh7110-inno-hdmi.yaml   |   91 ++
  .../soc/starfive/starfive,jh7110-syscon.yaml  |    1 +
  MAINTAINERS                                   |   11 +
  .../boot/dts/starfive/jh7110-common.dtsi      |  125 ++
  arch/riscv/boot/dts/starfive/jh7110.dtsi      |   41 +
  drivers/gpu/drm/Kconfig                       |    2 +
  drivers/gpu/drm/Makefile                      |    1 +
  drivers/gpu/drm/bridge/Kconfig                |    2 +
  drivers/gpu/drm/bridge/Makefile               |    1 +
  drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
  drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
  .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
  .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
  drivers/gpu/drm/rockchip/Kconfig              |    1 +
  drivers/gpu/drm/rockchip/Makefile             |    2 +-
  drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
  .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
  drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 ---------------
  drivers/gpu/drm/verisilicon/Kconfig           |   32 +
  drivers/gpu/drm/verisilicon/Makefile          |   10 +
  .../gpu/drm/verisilicon/inno_hdmi-starfive.c  |  553 +++++++++
  .../gpu/drm/verisilicon/inno_hdmi-starfive.h  |  194 +++
  drivers/gpu/drm/verisilicon/vs_crtc.c         |  241 ++++
  drivers/gpu/drm/verisilicon/vs_crtc.h         |   42 +
  drivers/gpu/drm/verisilicon/vs_dc_hw.c        | 1104 +++++++++++++++++
  drivers/gpu/drm/verisilicon/vs_dc_hw.h        |  492 ++++++++
  drivers/gpu/drm/verisilicon/vs_drv.c          |  777 ++++++++++++
  drivers/gpu/drm/verisilicon/vs_drv.h          |   41 +
  drivers/gpu/drm/verisilicon/vs_modeset.c      |   31 +
  drivers/gpu/drm/verisilicon/vs_modeset.h      |   10 +
  drivers/gpu/drm/verisilicon/vs_plane.c        |  358 ++++++
  drivers/gpu/drm/verisilicon/vs_plane.h        |   27 +
  drivers/gpu/drm/verisilicon/vs_type.h         |   54 +
  include/drm/bridge/inno_hdmi.h                |   56 +
  37 files changed, 5630 insertions(+), 1051 deletions(-)

create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
create mode 100644 drivers/gpu/drm/verisilicon/Makefile
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h

Quoted 9 lines

create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h create mode 100644 include/drm/bridge/inno_hdmi.h

Quoted 3 lines

Is this patch series still being worked on? If not I would like to give it a try to fix it up and get it merged.

Would like to get it working on my deepcomputing fml13v01 board, there is also a gpu driver for the thead th1520 being worked on by Michal Wilczynski that depends on this. Would be nice if that could get merged when it is ready.

Hi Maud,

Thanks for your interest in this patch series. I'm also keen to see it merged, as the GPU support on the TH1520 Soc depends on it. I just sent v4 of my series [1] with the last missing pieces to enable the GPU driver to probe correctly.

I'm not aware of any recent progress on this particular set from Keith. I would be happy to collaborate with you or take over the work of getting it ready for merging.

I also have a StarFive Vision Five 2 board, and my plan was to get the driver working for the JH7110 first. The only thing different for the TH1520 SoC is the HDMI driver, which could be added later.

However, the main blocker is the lack of public documentation for the Verisilicon DC8200 controller. The official StarFive documentation portal [2] mentions two essential documents: "DC8200 Dual Display Controller DPU IP Exposed Accessible Registers" and "DC8200 Dual Display Controller IP Hardware Features."

Pinging the StarFive developers on this thread: would it be possible to make these documents available? Access to them is critical for us to successfully move this driver forward.

[1] - https://lore.kernel.org/all/[email protected]/
[2] - https://doc-en.rvspace.org/JH7110/TRM/JH7110_TRM/detail_info_display.html

Quoted 4 lines

Kind regards,
Maud

Best regards,

Signature · 1 line
Michal Wilczynski <[email protected]>
#32 lore raw
Quoted 138 lines · Michal Wilczynski
Quoted 129 lines · Maud Spierings
Quoted 118 lines · keith zhao

Verisilicon/DC8200 display controller IP has 2 display pipes and each pipe support a primary plane and a cursor plane .
In addition, there are 4 overlay planes as 2 display pipes common resources.

The first display pipe is bound to the inno HDMI encoder. The second display pipe is bound to Internal custom encoder, which is used to find dsi bridge by dts node.

This patchset should be applied on next branch.

V1:
Changes since v1:
- Further standardize the yaml file.
- Dts naming convention improved.
- Fix the problem of compiling and loading ko files.
- Use drm new api to automatically manage resources.
- Drop vs_crtc_funcs&vs_plane_funcs, subdivide the plane's help interface.
- Reduce the modifiers unused.
- Optimize the hdmi driver code

V2:
Changes since v2:
- fix the error about checking the yaml file.
- match drm driver GEM DMA API.
- Delete the custom crtc property .
- hdmi use drmm_ new api to automatically manage resources.
- update the modifiers comments.
- enabling KASAN, fix the error during removing module

V3:
Changes since v3:
- Delete the custom plane property.
- Delete the custom fourcc modifiers.
- Adjust the calculation mode of hdmi pixclock.
- Add match data for dc8200 driver.
- Adjust some magic values.
- Add a simple encoder for dsi output.

V4:
Changes since v4:
- Delete the display subsystem module as all crtcs and planes are a driver.
- Delete the custom struct, directly use the drm struct data.
- Tidy up the inno hdmi public interface.
- Add a simple encoder for dsi output.

V5:
Changes since v5:
- Refine the Innosilicon HDMI by quoting bridge abstracting.
- Delete the encoder driver, which is created directly by internal functions.
- Adapt to the changes in kernel upgrade APIs, such as drm_client_setup.

keith zhao (9):
dt-bindings: display: bindings for starfive,JH7110 display pipeline
riscv: dts: Add display property
drm: bridge: inno-hdmi: add inno bridge driver.
drm/vs: Add Hardware Functions for VS DC8200
drm/vs: Add Base API for VS Mode Configuration
drm/vs: Add CRTC Functions
drm/vs: Add VS Plane API
drm/vs: Add Innosilicon HDMI Support
drm/vs: Add VS DRM Master Driver for JH7110 SoC

   .../display/bridge/innosilicon,inno-hdmi.yaml |   45 +
   .../display/rockchip/rockchip,inno-hdmi.yaml  |   27 +-
   .../starfive/starfive,jh7110-dc8200.yaml      |  176 +++
   .../starfive/starfive,jh7110-inno-hdmi.yaml   |   91 ++
   .../soc/starfive/starfive,jh7110-syscon.yaml  |    1 +
   MAINTAINERS                                   |   11 +
   .../boot/dts/starfive/jh7110-common.dtsi      |  125 ++
   arch/riscv/boot/dts/starfive/jh7110.dtsi      |   41 +
   drivers/gpu/drm/Kconfig                       |    2 +
   drivers/gpu/drm/Makefile                      |    1 +
   drivers/gpu/drm/bridge/Kconfig                |    2 +
   drivers/gpu/drm/bridge/Makefile               |    1 +
   drivers/gpu/drm/bridge/innosilicon/Kconfig    |    6 +
   drivers/gpu/drm/bridge/innosilicon/Makefile   |    2 +
   .../gpu/drm/bridge/innosilicon/inno-hdmi.c    |  376 ++++++
   .../gpu/drm/bridge/innosilicon/inno-hdmi.h    |   34 +
   drivers/gpu/drm/rockchip/Kconfig              |    1 +
   drivers/gpu/drm/rockchip/Makefile             |    2 +-
   drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c |  690 +++++++++++
   .../{inno_hdmi.h => inno_hdmi-rockchip.h}     |    0
   drivers/gpu/drm/rockchip/inno_hdmi.c          | 1025 ---------------
   drivers/gpu/drm/verisilicon/Kconfig           |   32 +
   drivers/gpu/drm/verisilicon/Makefile          |   10 +
   .../gpu/drm/verisilicon/inno_hdmi-starfive.c  |  553 +++++++++
   .../gpu/drm/verisilicon/inno_hdmi-starfive.h  |  194 +++
   drivers/gpu/drm/verisilicon/vs_crtc.c         |  241 ++++
   drivers/gpu/drm/verisilicon/vs_crtc.h         |   42 +
   drivers/gpu/drm/verisilicon/vs_dc_hw.c        | 1104 +++++++++++++++++
   drivers/gpu/drm/verisilicon/vs_dc_hw.h        |  492 ++++++++
   drivers/gpu/drm/verisilicon/vs_drv.c          |  777 ++++++++++++
   drivers/gpu/drm/verisilicon/vs_drv.h          |   41 +
   drivers/gpu/drm/verisilicon/vs_modeset.c      |   31 +
   drivers/gpu/drm/verisilicon/vs_modeset.h      |   10 +
   drivers/gpu/drm/verisilicon/vs_plane.c        |  358 ++++++
   drivers/gpu/drm/verisilicon/vs_plane.h        |   27 +
   drivers/gpu/drm/verisilicon/vs_type.h         |   54 +
   include/drm/bridge/inno_hdmi.h                |   56 +
   37 files changed, 5630 insertions(+), 1051 deletions(-)

create mode 100644 Documentation/devicetree/bindings/display/bridge/innosilicon,inno-hdmi.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-dc8200.yaml create mode 100644 Documentation/devicetree/bindings/display/starfive/starfive,jh7110-inno-hdmi.yaml create mode 100644 drivers/gpu/drm/bridge/innosilicon/Kconfig
create mode 100644 drivers/gpu/drm/bridge/innosilicon/Makefile
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.c
create mode 100644 drivers/gpu/drm/bridge/innosilicon/inno-hdmi.h
create mode 100644 drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c
rename drivers/gpu/drm/rockchip/{inno_hdmi.h => inno_hdmi-rockchip.h} (100%)
delete mode 100644 drivers/gpu/drm/rockchip/inno_hdmi.c
create mode 100644 drivers/gpu/drm/verisilicon/Kconfig
create mode 100644 drivers/gpu/drm/verisilicon/Makefile
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.c
create mode 100644 drivers/gpu/drm/verisilicon/inno_hdmi-starfive.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_crtc.h
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.c
create mode 100644 drivers/gpu/drm/verisilicon/vs_dc_hw.h

Quoted 9 lines

create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.c create mode 100644 drivers/gpu/drm/verisilicon/vs_drv.h create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.c create mode 100644 drivers/gpu/drm/verisilicon/vs_modeset.h create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.c create mode 100644 drivers/gpu/drm/verisilicon/vs_plane.h create mode 100644 drivers/gpu/drm/verisilicon/vs_type.h create mode 100644 include/drm/bridge/inno_hdmi.h

Quoted 3 lines

Is this patch series still being worked on? If not I would like to give it a try to fix it up and get it merged.

Would like to get it working on my deepcomputing fml13v01 board, there is also a gpu driver for the thead th1520 being worked on by Michal Wilczynski that depends on this. Would be nice if that could get merged when it is ready.

Hi Maud,

Quoted 8 lines

Thanks for your interest in this patch series. I'm also keen to see it merged, as the GPU support on the TH1520 Soc depends on it. I just sent v4 of my series [1] with the last missing pieces to enable the GPU driver to probe correctly.

I'm not aware of any recent progress on this particular set from Keith. I would be happy to collaborate with you or take over the work of getting it ready for merging.

I've tried rebasing it ontop of a new -next, but it got quite complicated fast unfortunately. Especially the hdmi part, as there have been changes inbetween there. I have not managed yet to create a working rebase, though I feel like I also didn't try hard enough yet.

Quoted 10 lines

I also have a StarFive Vision Five 2 board, and my plan was to get the driver working for the JH7110 first. The only thing different for the TH1520 SoC is the HDMI driver, which could be added later.

However, the main blocker is the lack of public documentation for the Verisilicon DC8200 controller. The official StarFive documentation portal [2] mentions two essential documents: "DC8200 Dual Display Controller DPU IP Exposed Accessible Registers" and "DC8200 Dual Display Controller IP Hardware Features."

Quoted 3 lines

Pinging the StarFive developers on this thread: would it be possible to make these documents available? Access to them is critical for us to successfully move this driver forward.

Those would indeed be very nice to have.

Quoted 3 lines

[1] - https://lore.kernel.org/all/[email protected]/
[2] - https://doc-en.rvspace.org/JH7110/TRM/JH7110_TRM/detail_info_display.html

Kind regards,
Maud