Skip to contentSkip to conversation

Add MT8195 HDMI support

PATCH Superseded Guillaume Ranquet 5 participants 32 messages Nov 4, 2022 – Jan 3, 2023

Subsystems (7)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add MT8195 HDMI support

Add support for HDMI Tx on MT8195.

This includes a split of the current "legacy" hdmi driver into a common library of functions and a two dedicated compilation units with specific code for mt8167 and another for the "new" mt8195 SoC.

Support for the new mt8195 hdmi phy and the dpi/drm_drv adjustments to support hdmi.

Based on next-20221104

test branch with dts and various "in flight" patches available here:
https://gitlab.com/granquet/linux/-/tree/granquet/linux-next_HDMI

I haven't updated the vdosys/mmsys/ethdr and mutex patches in a while in that test branch, they might be outdated..

To: Chunfeng Yun <[email protected]>
To: Kishon Vijay Abraham I <[email protected]>
To: Vinod Koul <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Matthias Brugger <[email protected]>
To: Chun-Kuang Hu <[email protected]>
To: Philipp Zabel <[email protected]>
To: David Airlie <[email protected]>
To: Daniel Vetter <[email protected]>
To: CK Hu <[email protected]>
To: Jitao shi <[email protected]>

---
Changes in v3:
- phy: Grouped register and bit definition together to add clarity
- dt-bindings: Addressed comments
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Removed syscon requirement from the hdmi node
- Use as much as possible bit FIELD_PREP/FIELD_GET macros across all the patches
- Make cec optional dynamically instead of hardcoded with a flag
- Renamed hdmi variants to v1 (legacy) and v2 (mt8195) while waiting for a better name
- Rework hdmi v2 code to use a connector (same as v1)
- Remove "magic" 0x43 addr special handling in hdmi ddc code
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Guillaume Ranquet (12):
dt-bindings: phy: mediatek: hdmi-phy: Add mt8195 compatible
dt-bindings: display: mediatek: add MT8195 hdmi bindings drm/mediatek: hdmi: use a regmap instead of iomem drm/mediatek: extract common functions from the mtk hdmi driver drm/mediatek: hdmi: make the cec dev optional
drm/mediatek: hdmi: add frame_colorimetry flag drm/mediatek: hdmi: add v2 support
drm/mediatek: hdmi: v2: add audio support
phy: phy-mtk-hdmi: Add generic phy configure callback
phy: mediatek: add support for phy-mtk-hdmi-mt8195
dt-bindings: display: mediatek: dpi: Add compatible for MediaTek MT8195 drm/mediatek: dpi: Add mt8195 hdmi to DPI driver

 .../bindings/display/mediatek/mediatek,dpi.yaml    |    1 +
 .../bindings/display/mediatek/mediatek,hdmi.yaml   |   61 +-
 .../display/mediatek/mediatek,mt8195-hdmi-ddc.yaml |   51 +
 .../devicetree/bindings/phy/mediatek,hdmi-phy.yaml |    1 +
 drivers/gpu/drm/mediatek/Makefile                  |    5 +-
 drivers/gpu/drm/mediatek/mtk_dpi.c                 |  143 +-
 drivers/gpu/drm/mediatek/mtk_dpi_regs.h            |    5 +
 drivers/gpu/drm/mediatek/mtk_hdmi.c                |  655 +-------
 drivers/gpu/drm/mediatek/mtk_hdmi.h                |   16 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c         |  477 ++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h         |  224 +++
 drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c         |  367 +++++
 drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h        |  309 ++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.c             | 1592 ++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.h             |   31 +
 drivers/phy/mediatek/Makefile                      |    1 +
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c         |  543 +++++++
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h         |  109 ++
 drivers/phy/mediatek/phy-mtk-hdmi.c                |   15 +
 drivers/phy/mediatek/phy-mtk-hdmi.h                |    2 +
 20 files changed, 3976 insertions(+), 632 deletions(-)

---
base-commit: 8d9826217c539e9dbc3472823dc536cff1d517a2
change-id: 20220919-hdmi_mtk

Best regards,

Signature · 1 line
Guillaume Ranquet <[email protected]>
#1 lore raw

PATCH v3 1/12 dt-bindings: phy: mediatek: hdmi-phy: Add mt8195 compatible

Add a compatible for the HDMI PHY on MT8195

---
 Documentation/devicetree/bindings/phy/mediatek,hdmi-phy.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/phy/mediatek,hdmi-phy.yaml +1 -0
index 0d94950b84ca..71c75a11e189 100644
@@ -28,6 +28,7 @@ properties:
           - const: mediatek,mt2701-hdmi-phy
       - const: mediatek,mt2701-hdmi-phy
       - const: mediatek,mt8173-hdmi-phy
+      - const: mediatek,mt8195-hdmi-phy
 
   reg:
     maxItems: 1
Signature · 1 line
b4 0.11.0-dev
#3 lore raw

Re: [PATCH v3 01/12] dt-bindings: phy: mediatek: hdmi-phy: Add mt8195 compatible

Quoted 14 lines · AngeloGioacchino Del Regno

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 4 lines

Add a compatible for the HDMI PHY on MT8195

Ack and R-b tags go after your S-o-b.

Apart from that:

Hi Angelo,

Thx for your review.
I'm not exactly sure what to do here as I'm using b4 trailers to collect Acked-by and Reviewed-by

And there's an ongoing discussion about that topic on the tools mailing list [1], it seems there's
no agreement on what to do with trailers ordering.
I'll keep using b4 trailers for now as for me this is the sane thing to do. I'll update the ordering if I see concensus on that discussion.

Thx,
Guillaume.

---

[1] https://lore.kernel.org/tools/[email protected]

#4 lore raw

PATCH v3 2/12 dt-bindings: display: mediatek: add MT8195 hdmi bindings

In reply to Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---
 .../bindings/display/mediatek/mediatek,hdmi.yaml   | 61 ++++++++++++++++++----
 .../display/mediatek/mediatek,mt8195-hdmi-ddc.yaml | 51 ++++++++++++++++++
 2 files changed, 101 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +50 -11
index bdaf0b51e68c..9710b7b6e9bf 100644
@@ -21,6 +21,7 @@ properties:
       - mediatek,mt7623-hdmi
       - mediatek,mt8167-hdmi
       - mediatek,mt8173-hdmi
+      - mediatek,mt8195-hdmi
 
   reg:
     maxItems: 1
@@ -29,18 +30,12 @@ properties:
     maxItems: 1
 
   clocks:
-    items:
-      - description: Pixel Clock
-      - description: HDMI PLL
-      - description: Bit Clock
-      - description: S/PDIF Clock
+    minItems: 4
+    maxItems: 4
 
   clock-names:
-    items:
-      - const: pixel
-      - const: pll
-      - const: bclk
-      - const: spdif
+    minItems: 4
+    maxItems: 4
 
   phys:
     maxItems: 1
@@ -58,6 +53,9 @@ properties:
     description: |
       phandle link and register offset to the system configuration registers.
 
+  power-domains:
+    maxItems: 1
+
   ports:
     $ref: /schemas/graph.yaml#/properties/ports
 
@@ -86,9 +84,50 @@ required:
   - clock-names
   - phys
   - phy-names
-  - mediatek,syscon-hdmi
   - ports
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: mediatek,mt8195-hdmi
+    then:
+      properties:
+        clocks:
+          items:
+            - description: APB
+            - description: HDCP
+            - description: HDCP 24M
+            - description: Split HDMI
+        clock-names:
+          items:
+            - const: hdmi_apb_sel
+            - const: hdcp_sel
+            - const: hdcp24_sel
+            - const: split_hdmi
+
+      required:
+        - power-domains
+    else:
+      properties:
+        clocks:
+          items:
+            - description: Pixel Clock
+            - description: HDMI PLL
+            - description: Bit Clock
+            - description: S/PDIF Clock
+
+        clock-names:
+          items:
+            - const: pixel
+            - const: pll
+            - const: bclk
+            - const: spdif
+
+      required:
+        - mediatek,syscon-hdmi
+
 additionalProperties: false
 
 examples:
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
b4 0.11.0-dev
#5 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Quoted 25 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---
 .../bindings/display/mediatek/mediatek,hdmi.yaml   | 61 ++++++++++++++++++----
 .../display/mediatek/mediatek,mt8195-hdmi-ddc.yaml | 51 ++++++++++++++++++
 2 files changed, 101 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +1 -0
index bdaf0b51e68c..9710b7b6e9bf 100644
@@ -21,6 +21,7 @@ properties:
       - mediatek,mt7623-hdmi
       - mediatek,mt8167-hdmi
       - mediatek,mt8173-hdmi
+      - mediatek,mt8195-hdmi
 
   reg:
     maxItems: 1

Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml properties: · line 33

Quoted 9 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +1 -5
@@ -29,18 +30,12 @@ properties:
     maxItems: 1
 
   clocks:
-    items:
-      - description: Pixel Clock
-      - description: HDMI PLL
-      - description: Bit Clock
-      - description: S/PDIF Clock
+    minItems: 4

Drop minItems, it's not needed when equal to maxItems.

Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml properties: · line 37

Quoted 9 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +2 -5
+    maxItems: 4
 
   clock-names:
-    items:
-      - const: pixel
-      - const: pll
-      - const: bclk
-      - const: spdif
+    minItems: 4

Drop minItems, it's not needed when equal to maxItems.

Quoted 88 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +46 -1
+    maxItems: 4
 
   phys:
     maxItems: 1
@@ -58,6 +53,9 @@ properties:
     description: |
       phandle link and register offset to the system configuration registers.
 
+  power-domains:
+    maxItems: 1
+
   ports:
     $ref: /schemas/graph.yaml#/properties/ports
 
@@ -86,9 +84,50 @@ required:
   - clock-names
   - phys
   - phy-names
-  - mediatek,syscon-hdmi
   - ports
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: mediatek,mt8195-hdmi
+    then:
+      properties:
+        clocks:
+          items:
+            - description: APB
+            - description: HDCP
+            - description: HDCP 24M
+            - description: Split HDMI
+        clock-names:
+          items:
+            - const: hdmi_apb_sel
+            - const: hdcp_sel
+            - const: hdcp24_sel
+            - const: split_hdmi
+
+      required:
+        - power-domains
+    else:
+      properties:
+        clocks:
+          items:
+            - description: Pixel Clock
+            - description: HDMI PLL
+            - description: Bit Clock
+            - description: S/PDIF Clock
+
+        clock-names:
+          items:
+            - const: pixel
+            - const: pll
+            - const: bclk
+            - const: spdif
+
+      required:
+        - mediatek,syscon-hdmi
+
 additionalProperties: false
 
 examples:
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +16 -0
new file mode 100644
index 000000000000..2dc273689584
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC pins.
+
+properties:

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc

Unless you expect it to grow, I propose to drop clock-names. It's not useful when the name is the same as name of hardware.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Quoted 153 lines · Krzysztof Kozlowski
Quoted 25 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---
 .../bindings/display/mediatek/mediatek,hdmi.yaml   | 61 ++++++++++++++++++----
 .../display/mediatek/mediatek,mt8195-hdmi-ddc.yaml | 51 ++++++++++++++++++
 2 files changed, 101 insertions(+), 11 deletions(-)
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +1 -0
index bdaf0b51e68c..9710b7b6e9bf 100644
@@ -21,6 +21,7 @@ properties:
       - mediatek,mt7623-hdmi
       - mediatek,mt8167-hdmi
       - mediatek,mt8173-hdmi
+      - mediatek,mt8195-hdmi
 
   reg:
     maxItems: 1

Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml properties: · line 33

Quoted 9 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +1 -5
@@ -29,18 +30,12 @@ properties:
     maxItems: 1
 
   clocks:
-    items:
-      - description: Pixel Clock
-      - description: HDMI PLL
-      - description: Bit Clock
-      - description: S/PDIF Clock
+    minItems: 4

Drop minItems, it's not needed when equal to maxItems.

Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml properties: · line 37

Quoted 9 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +2 -5
+    maxItems: 4
 
   clock-names:
-    items:
-      - const: pixel
-      - const: pll
-      - const: bclk
-      - const: spdif
+    minItems: 4

Drop minItems, it's not needed when equal to maxItems.

Quoted 88 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,hdmi.yaml +46 -1
+    maxItems: 4
 
   phys:
     maxItems: 1
@@ -58,6 +53,9 @@ properties:
     description: |
       phandle link and register offset to the system configuration registers.
 
+  power-domains:
+    maxItems: 1
+
   ports:
     $ref: /schemas/graph.yaml#/properties/ports
 
@@ -86,9 +84,50 @@ required:
   - clock-names
   - phys
   - phy-names
-  - mediatek,syscon-hdmi
   - ports
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: mediatek,mt8195-hdmi
+    then:
+      properties:
+        clocks:
+          items:
+            - description: APB
+            - description: HDCP
+            - description: HDCP 24M
+            - description: Split HDMI
+        clock-names:
+          items:
+            - const: hdmi_apb_sel
+            - const: hdcp_sel
+            - const: hdcp24_sel
+            - const: split_hdmi
+
+      required:
+        - power-domains
+    else:
+      properties:
+        clocks:
+          items:
+            - description: Pixel Clock
+            - description: HDMI PLL
+            - description: Bit Clock
+            - description: S/PDIF Clock
+
+        clock-names:
+          items:
+            - const: pixel
+            - const: pll
+            - const: bclk
+            - const: spdif
+
+      required:
+        - mediatek,syscon-hdmi
+
 additionalProperties: false
 
 examples:
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +16 -0
new file mode 100644
index 000000000000..2dc273689584
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC pins.
+
+properties:

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc

Unless you expect it to grow, I propose to drop clock-names. It's not useful when the name is the same as name of hardware.

Quoted 3 lines

Best regards,
Krzysztof

Thx for your suggestions, I'll apply them in v4.

Thx,
Guillaume.

#7 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

In reply to Guillaume Ranquet

Hi, Guillaume:

Quoted 10 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no
specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---

[snip]

Quoted 55 lines

a/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml
new file mode 100644
index 000000000000..2dc273689584
--- /dev/null
+++
b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +4 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: 

https://urldefense.com/v3/__http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WfpOlq57w$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WdSGOSxzw$

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +9 -0
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC

pins.

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +25 -0
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc
+
+  mediatek,hdmi:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      A phandle to the mt8195 hdmi controller
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+
+additionalProperties: false
+

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hdmiddc0: i2c {
+      compatible = "mediatek,mt8195-hdmi-ddc";
+      mediatek,hdmi = <&hdmi0>;
+      clocks = <&clk26m>;
+      clock-names = "ddc";
+    };

I think we should not have a virtual device. This ddc is part of mt8195-hdmi device, so just keep mt8195-hdmi, and let mt8195-hdmi driver to probe the sub driver of ddc driver.

Regards,
CK

Quoted 3 lines

+
+...

#8 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Quoted 86 lines · CK Hu (胡俊光)

Hi, Guillaume:

Quoted 10 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no
specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---

[snip]

Quoted 55 lines

a/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml
new file mode 100644
index 000000000000..2dc273689584
--- /dev/null
+++
b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +4 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id:

https://urldefense.com/v3/__http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WfpOlq57w$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WdSGOSxzw$

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +9 -0
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC

pins.

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +25 -0
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc
+
+  mediatek,hdmi:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      A phandle to the mt8195 hdmi controller
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+
+additionalProperties: false
+

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hdmiddc0: i2c {
+      compatible = "mediatek,mt8195-hdmi-ddc";
+      mediatek,hdmi = <&hdmi0>;
+      clocks = <&clk26m>;
+      clock-names = "ddc";
+    };

I think we should not have a virtual device. This ddc is part of mt8195-hdmi device, so just keep mt8195-hdmi, and let mt8195-hdmi driver to probe the sub driver of ddc driver.

Quoted 2 lines

Regards,
CK

Hi CK,

Thx for your input.
Though I would strongly prefer to keep the ddc as a separate "virtual device".

It aligns better with the goal of reusing as much code as possible from the HDMI V1 IP,
which is something you have been advocating since V1 of this patch quite some time ago
and has shaped this patch.

To me we are in a state that is clean and avoids branching in the hdmi common code.
Would you reconsider and allow the use of that virtual device?

Thx,
Guillaume.

Quoted 4 lines
Quoted 4 lines

+
+...

#9 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Il 02/01/23 14:38, Guillaume Ranquet ha scritto:

Quoted 101 lines · CK Hu (胡俊光)
Quoted 86 lines

Hi, Guillaume:

Quoted 10 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no
specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---

[snip]

Quoted 55 lines

a/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml
new file mode 100644
index 000000000000..2dc273689584
--- /dev/null
+++
b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +4 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id:

https://urldefense.com/v3/__http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WfpOlq57w$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WdSGOSxzw$

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +9 -0
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC

pins.

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +25 -0
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc
+
+  mediatek,hdmi:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      A phandle to the mt8195 hdmi controller
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+
+additionalProperties: false
+

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hdmiddc0: i2c {
+      compatible = "mediatek,mt8195-hdmi-ddc";
+      mediatek,hdmi = <&hdmi0>;
+      clocks = <&clk26m>;
+      clock-names = "ddc";
+    };

I think we should not have a virtual device. This ddc is part of mt8195-hdmi device, so just keep mt8195-hdmi, and let mt8195-hdmi driver to probe the sub driver of ddc driver.

Quoted 2 lines

Regards,
CK

Hi CK,

Thx for your input.
Though I would strongly prefer to keep the ddc as a separate "virtual device".

It aligns better with the goal of reusing as much code as possible from the HDMI V1 IP,
which is something you have been advocating since V1 of this patch quite some time ago
and has shaped this patch.

Quoted 7 lines

To me we are in a state that is clean and avoids branching in the hdmi common code.
Would you reconsider and allow the use of that virtual device?

Thx,
Guillaume.

You can as well keep the DDC as a separated driver, but register in the HDMI v1 and v2 driver at probe time.

Doing that, you won't need any devicetree node specific to any virtual device :-)

Cheers,
Angelo

#10 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Quoted 110 lines · AngeloGioacchino Del Regno

Il 02/01/23 14:38, Guillaume Ranquet ha scritto:

Quoted 101 lines · CK Hu (胡俊光)
Quoted 86 lines

Hi, Guillaume:

Quoted 10 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no
specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---

[snip]

Quoted 55 lines

a/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml
new file mode 100644
index 000000000000..2dc273689584
--- /dev/null
+++
b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +4 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id:

https://urldefense.com/v3/__http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WfpOlq57w$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WdSGOSxzw$

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +9 -0
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC

pins.

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +25 -0
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc
+
+  mediatek,hdmi:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      A phandle to the mt8195 hdmi controller
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+
+additionalProperties: false
+

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hdmiddc0: i2c {
+      compatible = "mediatek,mt8195-hdmi-ddc";
+      mediatek,hdmi = <&hdmi0>;
+      clocks = <&clk26m>;
+      clock-names = "ddc";
+    };

I think we should not have a virtual device. This ddc is part of mt8195-hdmi device, so just keep mt8195-hdmi, and let mt8195-hdmi driver to probe the sub driver of ddc driver.

Quoted 2 lines

Regards,
CK

Hi CK,

Thx for your input.
Though I would strongly prefer to keep the ddc as a separate "virtual device".

It aligns better with the goal of reusing as much code as possible from the HDMI V1 IP,
which is something you have been advocating since V1 of this patch quite some time ago
and has shaped this patch.

Quoted 7 lines

To me we are in a state that is clean and avoids branching in the hdmi common code.
Would you reconsider and allow the use of that virtual device?

Thx,
Guillaume.

Quoted 9 lines

You can as well keep the DDC as a separated driver, but register in the HDMI v1 and v2 driver at probe time.

Doing that, you won't need any devicetree node specific to any virtual device :-)

Cheers,
Angelo

Sure, but does it make any sense for HDMI v1?
As the ddc in v1 is a real device which (in theory) can be reused by other IPs.

I would see either v1 and v2 ddc exposed as a devicetree node (which is what I favor).
Or v1 as a devicetree node and v2 probed directly from the hdmi code base.

Thx,
Guillaume.

#11 lore raw

Re: [PATCH v3 02/12] dt-bindings: display: mediatek: add MT8195 hdmi bindings

Il 02/01/23 16:19, Guillaume Ranquet ha scritto:

Quoted 122 lines
Quoted 110 lines · AngeloGioacchino Del Regno

Il 02/01/23 14:38, Guillaume Ranquet ha scritto:

Quoted 101 lines · CK Hu (胡俊光)
Quoted 86 lines

Hi, Guillaume:

Quoted 10 lines · Guillaume Ranquet

Add mt8195 SoC bindings for hdmi and hdmi-ddc

On mt8195 the ddc i2c controller is part of the hdmi IP block and thus has no
specific register range, power domain or interrupt, making it simpler than its the legacy "mediatek,hdmi-ddc" binding.

---

[snip]

Quoted 55 lines

a/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml
new file mode 100644
index 000000000000..2dc273689584
--- /dev/null
+++
b/Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195- hdmi-ddc.yaml

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +4 -0
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id:

https://urldefense.com/v3/__http://devicetree.org/schemas/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WfpOlq57w$

+$schema:
https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.yaml*__;Iw!!CTRNKA9wMg0ARbw!wwVQuq5lzW0lvUFUkVXPWT8cIu96xdkn4tMams1E55qyxEZmgV1i0WdSGOSxzw$

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +9 -0
+
+title: Mediatek HDMI DDC for mt8195
+
+maintainers:
+  - CK Hu <[email protected]>
+  - Jitao shi <[email protected]>
+
+description: |
+  The HDMI DDC i2c controller is used to interface with the HDMI DDC

pins.

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +25 -0
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt8195-hdmi-ddc
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ddc
+
+  mediatek,hdmi:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      A phandle to the mt8195 hdmi controller
+
+required:
+  - compatible
+  - clocks
+  - clock-names
+
+additionalProperties: false
+

Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/display/mediatek/mediatek,mt8195-hdmi-ddc.yaml new file +10 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    hdmiddc0: i2c {
+      compatible = "mediatek,mt8195-hdmi-ddc";
+      mediatek,hdmi = <&hdmi0>;
+      clocks = <&clk26m>;
+      clock-names = "ddc";
+    };

I think we should not have a virtual device. This ddc is part of mt8195-hdmi device, so just keep mt8195-hdmi, and let mt8195-hdmi driver to probe the sub driver of ddc driver.

Quoted 2 lines

Regards,
CK

Hi CK,

Thx for your input.
Though I would strongly prefer to keep the ddc as a separate "virtual device".

It aligns better with the goal of reusing as much code as possible from the HDMI V1 IP,
which is something you have been advocating since V1 of this patch quite some time ago
and has shaped this patch.

Quoted 7 lines

To me we are in a state that is clean and avoids branching in the hdmi common code.
Would you reconsider and allow the use of that virtual device?

Thx,
Guillaume.

Quoted 9 lines

You can as well keep the DDC as a separated driver, but register in the HDMI v1 and v2 driver at probe time.

Doing that, you won't need any devicetree node specific to any virtual device :-)

Cheers,
Angelo

Quoted 7 lines

Sure, but does it make any sense for HDMI v1?
As the ddc in v1 is a real device which (in theory) can be reused by other IPs.

I would see either v1 and v2 ddc exposed as a devicetree node (which is what I favor).
Or v1 as a devicetree node and v2 probed directly from the hdmi code base.

The last option looks sensible, since v1 has an external ddc, but on v2 it's integrated.

v1 -> dt probe
v2 -> driver probe

Quoted 2 lines

Thx,
Guillaume.

#12 lore raw

PATCH v3 3/12 drm/mediatek: hdmi: use a regmap instead of iomem

In reply to Guillaume Ranquet

To prepare support for newer chips that need to share their address range with a dedicated ddc driver, use a regmap.

---
 drivers/gpu/drm/mediatek/mtk_hdmi.c | 43 +++++++++++--------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +13 -30
index 4c80b6896dc3..9b02b30a193a 100644
@@ -171,7 +171,7 @@ struct mtk_hdmi {
 	u32 ibias_up;
 	struct regmap *sys_regmap;
 	unsigned int sys_offset;
-	void __iomem *regs;
+	struct regmap *regs;
 	enum hdmi_colorspace csp;
 	struct hdmi_audio_param aud_param;
 	bool audio_enable;
@@ -187,44 +187,29 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
 	return container_of(b, struct mtk_hdmi, bridge);
 }
 
-static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset)
+static int mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset, u32 *val)
 {
-	return readl(hdmi->regs + offset);
+	return regmap_read(hdmi->regs, offset, val);
 }
 
 static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val)
 {
-	writel(val, hdmi->regs + offset);
+	regmap_write(hdmi->regs, offset, val);
 }
 
 static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)
 {
-	void __iomem *reg = hdmi->regs + offset;
-	u32 tmp;
-
-	tmp = readl(reg);
-	tmp &= ~bits;
-	writel(tmp, reg);
+	regmap_clear_bits(hdmi->regs, offset, bits);
 }
 
 static void mtk_hdmi_set_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)
 {
-	void __iomem *reg = hdmi->regs + offset;
-	u32 tmp;
-
-	tmp = readl(reg);
-	tmp |= bits;
-	writel(tmp, reg);
+	regmap_set_bits(hdmi->regs, offset, bits);
 }
 
 static void mtk_hdmi_mask(struct mtk_hdmi *hdmi, u32 offset, u32 val, u32 mask)
 {
-	void __iomem *reg = hdmi->regs + offset;
-	u32 tmp;
-
-	tmp = readl(reg);
-	tmp = (tmp & ~mask) | (val & mask);
-	writel(tmp, reg);
+	regmap_update_bits(hdmi->regs, offset, mask, val);
 }
 
 static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black)
@@ -473,7 +458,7 @@ static void mtk_hdmi_hw_aud_set_i2s_fmt(struct mtk_hdmi *hdmi,
 {
 	u32 val;
 
-	val = mtk_hdmi_read(hdmi, GRL_CFG0);
+	mtk_hdmi_read(hdmi, GRL_CFG0, &val);
 	val &= ~(CFG0_W_LENGTH_MASK | CFG0_I2S_MODE_MASK);
 
 	switch (i2s_fmt) {
@@ -565,7 +550,7 @@ static void mtk_hdmi_hw_aud_set_input_type(struct mtk_hdmi *hdmi,
 {
 	u32 val;
 
-	val = mtk_hdmi_read(hdmi, GRL_CFG1);
+	mtk_hdmi_read(hdmi, GRL_CFG1, &val);
 	if (input_type == HDMI_AUD_INPUT_I2S &&
 	    (val & CFG1_SPDIF) == CFG1_SPDIF) {
 		val &= ~CFG1_SPDIF;
@@ -596,7 +581,7 @@ static void mtk_hdmi_hw_aud_src_reenable(struct mtk_hdmi *hdmi)
 {
 	u32 val;
 
-	val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL);
+	mtk_hdmi_read(hdmi, GRL_MIX_CTRL, &val);
 	if (val & MIX_CTRL_SRC_EN) {
 		val &= ~MIX_CTRL_SRC_EN;
 		mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val);
@@ -610,7 +595,7 @@ static void mtk_hdmi_hw_aud_src_disable(struct mtk_hdmi *hdmi)
 {
 	u32 val;
 
-	val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL);
+	mtk_hdmi_read(hdmi, GRL_MIX_CTRL, &val);
 	val &= ~MIX_CTRL_SRC_EN;
 	mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val);
 	mtk_hdmi_write(hdmi, GRL_SHIFT_L1, 0x00);
@@ -621,7 +606,7 @@ static void mtk_hdmi_hw_aud_set_mclk(struct mtk_hdmi *hdmi,
 {
 	u32 val;
 
-	val = mtk_hdmi_read(hdmi, GRL_CFG5);
+	mtk_hdmi_read(hdmi, GRL_CFG5, &val);
 	val &= CFG5_CD_RATIO_MASK;
 
 	switch (mclk) {
@@ -1427,7 +1412,6 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
 	struct device_node *cec_np, *remote, *i2c_np;
 	struct platform_device *cec_pdev;
 	struct regmap *regmap;
-	struct resource *mem;
 	int ret;
 
 	ret = mtk_hdmi_get_all_clk(hdmi, np);
@@ -1473,8 +1457,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
 	}
 	hdmi->sys_regmap = regmap;
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	hdmi->regs = devm_ioremap_resource(dev, mem);
+	hdmi->regs = device_node_to_regmap(dev->of_node);
 	if (IS_ERR(hdmi->regs)) {
 		ret = PTR_ERR(hdmi->regs);
 		goto put_device;
Signature · 1 line
b4 0.11.0-dev
#13 lore raw

Re: [PATCH v3 03/12] drm/mediatek: hdmi: use a regmap instead of iomem

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 29 lines

To prepare support for newer chips that need to share their address range with a dedicated ddc driver, use a regmap.

---
  drivers/gpu/drm/mediatek/mtk_hdmi.c | 43 +++++++++++--------------------------
  1 file changed, 13 insertions(+), 30 deletions(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -3
index 4c80b6896dc3..9b02b30a193a 100644
@@ -171,7 +171,7 @@ struct mtk_hdmi {
  	u32 ibias_up;
  	struct regmap *sys_regmap;
  	unsigned int sys_offset;
-	void __iomem *regs;
+	struct regmap *regs;
  	enum hdmi_colorspace csp;
  	struct hdmi_audio_param aud_param;
  	bool audio_enable;
@@ -187,44 +187,29 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
  	return container_of(b, struct mtk_hdmi, bridge);
  }
 
-static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset)
+static int mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset, u32 *val)
  {
-	return readl(hdmi->regs + offset);

drivers/gpu/drm/mediatek/mtk_hdmi.c static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b) · line 200

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
+	return regmap_read(hdmi->regs, offset, val);
  }
 
  static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val)
  {
-	writel(val, hdmi->regs + offset);
+	regmap_write(hdmi->regs, offset, val);
  }
 
  static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)

You don't need these functions anymore, as these are now simply wrapping regmap calls, hence these don't contain any "real" logic anymore.

Please remove them and use the regmap API directly.

Thanks,
Angelo

#14 lore raw

Re: [PATCH v3 03/12] drm/mediatek: hdmi: use a regmap instead of iomem

Quoted 44 lines · AngeloGioacchino Del Regno

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 29 lines

To prepare support for newer chips that need to share their address range with a dedicated ddc driver, use a regmap.

---
  drivers/gpu/drm/mediatek/mtk_hdmi.c | 43 +++++++++++--------------------------
  1 file changed, 13 insertions(+), 30 deletions(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -3
index 4c80b6896dc3..9b02b30a193a 100644
@@ -171,7 +171,7 @@ struct mtk_hdmi {
  	u32 ibias_up;
  	struct regmap *sys_regmap;
  	unsigned int sys_offset;
-	void __iomem *regs;
+	struct regmap *regs;
  	enum hdmi_colorspace csp;
  	struct hdmi_audio_param aud_param;
  	bool audio_enable;
@@ -187,44 +187,29 @@ static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b)
  	return container_of(b, struct mtk_hdmi, bridge);
  }
 
-static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset)
+static int mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset, u32 *val)
  {
-	return readl(hdmi->regs + offset);

drivers/gpu/drm/mediatek/mtk_hdmi.c static inline struct mtk_hdmi *hdmi_ctx_from_bridge(struct drm_bridge *b) · line 200

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
+	return regmap_read(hdmi->regs, offset, val);
  }
 
  static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val)
  {
-	writel(val, hdmi->regs + offset);
+	regmap_write(hdmi->regs, offset, val);
  }
 
  static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)

You don't need these functions anymore, as these are now simply wrapping regmap calls, hence these don't contain any "real" logic anymore.

Quoted 5 lines

Please remove them and use the regmap API directly.

Thanks,
Angelo

Agree with that, my intent was to minimize the change size so that it would be easy to review.

My mistake, I'll remove the wrappers.

Thx,
Guillaume.

#15 lore raw

PATCH v3 4/12 drm/mediatek: extract common functions from the mtk hdmi driver

In reply to Guillaume Ranquet

Create a common "framework" that can be used to add support for different hdmi IPs within the mediatek range of products.

---
 drivers/gpu/drm/mediatek/Makefile          |   3 +-
 drivers/gpu/drm/mediatek/mtk_hdmi.c        | 620 ++---------------------------
 drivers/gpu/drm/mediatek/mtk_hdmi.h        |  16 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 433 ++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h | 221 ++++++++++
 5 files changed, 704 insertions(+), 589 deletions(-)
drivers/gpu/drm/mediatek/Makefile +2 -1
index d4d193f60271..79bbaa58893e 100644
@@ -22,7 +22,8 @@ obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
 
 mediatek-drm-hdmi-objs := mtk_cec.o \
 			  mtk_hdmi.o \
-			  mtk_hdmi_ddc.o
+			  mtk_hdmi_common.o \
+			  mtk_hdmi_ddc.o \
 
 obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
 
drivers/gpu/drm/mediatek/mtk_hdmi.c +32 -588

746 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi.h +16 -0
index 472bf141c92b..eef42030e036 100644
@@ -6,9 +6,25 @@
 #ifndef _MTK_HDMI_CTRL_H
 #define _MTK_HDMI_CTRL_H
 
+struct mtk_hdmi;
 struct platform_driver;
 
 extern struct platform_driver mtk_cec_driver;
 extern struct platform_driver mtk_hdmi_ddc_driver;
+extern const struct drm_bridge_funcs mtk_mt8183_hdmi_bridge_funcs;
 
+void mtk_hdmi_output_init_mt8183(struct mtk_hdmi *hdmi);
+void mtk_hdmi_clk_disable_audio_mt8183(struct mtk_hdmi *hdmi);
+int mtk_hdmi_clk_enable_audio_mt8183(struct mtk_hdmi *hdmi);
+void set_hdmi_codec_pdata_mt8183(struct hdmi_codec_pdata *codec_data);
+
+enum mtk_hdmi_clk_id_mt8183 {
+	MTK_HDMIV1_CLK_HDMI_PIXEL,
+	MTK_HDMIV1_CLK_HDMI_PLL,
+	MTK_HDMIV1_CLK_AUD_BCLK,
+	MTK_HDMIV1_CLK_AUD_SPDIF,
+	MTK_HDMIV1_CLK_COUNT,
+};
+
+extern const char * const mtk_hdmi_clk_names_v1[MTK_HDMIV1_CLK_COUNT];
 #endif /* _MTK_HDMI_CTRL_H */
drivers/gpu/drm/mediatek/mtk_hdmi_common.c new file +433 -0

433 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_common.h new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
b4 0.11.0-dev
#16 lore raw

Re: [PATCH v3 04/12] drm/mediatek: extract common functions from the mtk hdmi driver

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 12 lines

Create a common "framework" that can be used to add support for different hdmi IPs within the mediatek range of products.

---
  drivers/gpu/drm/mediatek/Makefile          |   3 +-
  drivers/gpu/drm/mediatek/mtk_hdmi.c        | 620 ++---------------------------
  drivers/gpu/drm/mediatek/mtk_hdmi.h        |  16 +
  drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 433 ++++++++++++++++++++
  drivers/gpu/drm/mediatek/mtk_hdmi_common.h | 221 ++++++++++
  5 files changed, 704 insertions(+), 589 deletions(-)

..snip..

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c new file +0 -0
new file mode 100644
index 000000000000..3f08d37b1af0

..snip..

drivers/gpu/drm/mediatek/mtk_hdmi_common.c line 109

Quoted 3 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c new file +3 -0
+
+int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz,
+				 struct drm_display_mode *mode)

warning: no previous prototype for ‘mtk_hdmi_setup_avi_infoframe’ [-Wmissing-prototypes]

Please fix.

Thanks,
Angelo

#17 lore raw

PATCH v3 5/12 drm/mediatek: hdmi: make the cec dev optional

In reply to Guillaume Ranquet

Make cec device optional in order to support newer versions of the hdmi IP which doesn't require it

---
 drivers/gpu/drm/mediatek/mtk_hdmi.c        |  8 +++--
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 54 ++++++++++++++++++++----------
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h |  1 +
 3 files changed, 42 insertions(+), 21 deletions(-)
drivers/gpu/drm/mediatek/mtk_hdmi.c +5 -3
index 73bda2849196..85c6ebca36dd 100644
@@ -927,10 +927,11 @@ void mtk_hdmi_clk_disable_audio_mt8183(struct mtk_hdmi *hdmi)
 static enum drm_connector_status
 mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
 {
-	bool connected;
+	bool connected = true;
 
 	mutex_lock(&hdmi->update_plugged_status_lock);
-	connected = mtk_cec_hpd_high(hdmi->cec_dev);
+	if (hdmi->cec_dev)
+		connected = mtk_cec_hpd_high(hdmi->cec_dev);
 	if (hdmi->plugged_cb && hdmi->codec_dev)
 		hdmi->plugged_cb(hdmi->codec_dev, connected);
 	mutex_unlock(&hdmi->update_plugged_status_lock);
@@ -1025,7 +1026,8 @@ static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge,
 			return ret;
 	}
 
-	mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev);
+	if (hdmi->cec_dev)
+		mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev);
 
 	return 0;
 }
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +36 -18

83 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_common.h +1 -0
index 7452bea91f9e..921bde150e11 100644
@@ -31,6 +31,7 @@
 struct mtk_hdmi_conf {
 	bool tz_disabled;
 	bool cea_modes_only;
+	bool has_cec;
 	unsigned long max_mode_clock;
 	const struct drm_bridge_funcs *bridge_funcs;
 	void (*mtk_hdmi_output_init)(struct mtk_hdmi *hdmi);
Signature · 1 line
b4 0.11.0-dev
#18 lore raw

PATCH v3 6/12 drm/mediatek: hdmi: add frame_colorimetry flag

In reply to Guillaume Ranquet

Add a flag to indicate support for frame colorimetry.

---
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 11 +++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h |  1 +
 2 files changed, 12 insertions(+)
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +11 -0
index 3635ca66817b..933c51b5f6d7 100644
@@ -120,6 +120,17 @@ int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz
 		return err;
 	}
 
+	if (hdmi->conf->has_frame_colorimetry) {
+		frame.colorimetry = hdmi->colorimtery;
+		if (frame.colorimetry == HDMI_COLORIMETRY_EXTENDED)
+			frame.extended_colorimetry = hdmi->extended_colorimetry;
+
+		/* quantiation range:limited or full */
+		if (frame.colorspace == HDMI_COLORSPACE_RGB)
+			frame.quantization_range = hdmi->quantization_range;
+		else
+			frame.ycc_quantization_range = hdmi->ycc_quantization_range;
+	}
 	err = hdmi_avi_infoframe_pack(&frame, buffer, bufsz);
 
 	if (err < 0) {
drivers/gpu/drm/mediatek/mtk_hdmi_common.h +1 -0
index 921bde150e11..2e8e5feec377 100644
@@ -32,6 +32,7 @@ struct mtk_hdmi_conf {
 	bool tz_disabled;
 	bool cea_modes_only;
 	bool has_cec;
+	bool has_frame_colorimetry;
 	unsigned long max_mode_clock;
 	const struct drm_bridge_funcs *bridge_funcs;
 	void (*mtk_hdmi_output_init)(struct mtk_hdmi *hdmi);
Signature · 1 line
b4 0.11.0-dev
#19 lore raw

Re: [PATCH v3 06/12] drm/mediatek: hdmi: add frame_colorimetry flag

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 13 lines

Add a flag to indicate support for frame colorimetry.

---
  drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 11 +++++++++++
  drivers/gpu/drm/mediatek/mtk_hdmi_common.h |  1 +
  2 files changed, 12 insertions(+)
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +0 -0
index 3635ca66817b..933c51b5f6d7 100644

drivers/gpu/drm/mediatek/mtk_hdmi_common.c int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz · line 124

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +2 -0
@@ -120,6 +120,17 @@ int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz
  		return err;
  	}
 
+	if (hdmi->conf->has_frame_colorimetry) {
+		frame.colorimetry = hdmi->colorimtery;

Typo: s/colorimtery/colorimetry/g

...also, I don't see this being really used? In hdmi-v2 you're setting this param to HDMI_COLORIMETRY_NONE and quantization ranges to always the same default value.

I wonder if this is really needed at this point.

Regards,
Angelo

#20 lore raw

Re: [PATCH v3 06/12] drm/mediatek: hdmi: add frame_colorimetry flag

Quoted 22 lines · AngeloGioacchino Del Regno

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 13 lines

Add a flag to indicate support for frame colorimetry.

---
  drivers/gpu/drm/mediatek/mtk_hdmi_common.c | 11 +++++++++++
  drivers/gpu/drm/mediatek/mtk_hdmi_common.h |  1 +
  2 files changed, 12 insertions(+)
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +0 -0
index 3635ca66817b..933c51b5f6d7 100644

drivers/gpu/drm/mediatek/mtk_hdmi_common.c int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz · line 124

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +2 -0
@@ -120,6 +120,17 @@ int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, u8 *buffer, size_t bufsz
  		return err;
  	}
 
+	if (hdmi->conf->has_frame_colorimetry) {
+		frame.colorimetry = hdmi->colorimtery;

Typo: s/colorimtery/colorimetry/g

Quoted 7 lines

...also, I don't see this being really used? In hdmi-v2 you're setting this param to HDMI_COLORIMETRY_NONE and quantization ranges to always the same default value.

I wonder if this is really needed at this point.

Regards,
Angelo

I'll see if I can make something work without this boolean.

Thx,
Guillaume.

#21 lore raw

PATCH v3 7/12 drm/mediatek: hdmi: add v2 support

In reply to Guillaume Ranquet

Adds hdmi and hdmi-ddc support for v2 IP.

---
 drivers/gpu/drm/mediatek/Makefile           |    2 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c  |   14 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h  |    1 +
 drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c  |  367 +++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h |  309 ++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.c      | 1379 +++++++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.h      |   29 +
 7 files changed, 2101 insertions(+)
drivers/gpu/drm/mediatek/Makefile +2 -0
index 79bbaa58893e..bb60856b629e 100644
@@ -24,6 +24,8 @@ mediatek-drm-hdmi-objs := mtk_cec.o \
 			  mtk_hdmi.o \
 			  mtk_hdmi_common.o \
 			  mtk_hdmi_ddc.o \
+			  mtk_hdmi_ddc_v2.o \
+			  mtk_hdmi_v2.o \
 
 obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
 
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +14 -0
index 933c51b5f6d7..e43c938a9aa5 100644
@@ -380,6 +380,16 @@ static const struct mtk_hdmi_conf mtk_hdmi_conf_mt8173 = {
 	.num_clocks = MTK_HDMIV1_CLK_COUNT,
 };
 
+static const struct mtk_hdmi_conf mtk_hdmi_conf_v2 = {
+	.has_frame_colorimetry = true,
+	.bridge_funcs = &mtk_v2_hdmi_bridge_funcs,
+	.mtk_hdmi_output_init = mtk_hdmi_output_init_v2,
+	.mtk_hdmi_clk_disable = mtk_hdmi_clk_disable_v2,
+	.mtk_hdmi_clk_enable = mtk_hdmi_clk_enable_v2,
+	.mtk_hdmi_clock_names = mtk_hdmi_clk_names_v2,
+	.num_clocks = MTK_HDMIV2_CLK_COUNT,
+};
+
 static const struct of_device_id mtk_drm_hdmi_of_ids[] = {
 	{ .compatible = "mediatek,mt2701-hdmi",
 	  .data = &mtk_hdmi_conf_mt2701,
@@ -390,6 +400,9 @@ static const struct of_device_id mtk_drm_hdmi_of_ids[] = {
 	{ .compatible = "mediatek,mt8173-hdmi",
 	  .data = &mtk_hdmi_conf_mt8173,
 	},
+	{ .compatible = "mediatek,mt8195-hdmi",
+	  .data = &mtk_hdmi_conf_v2,
+	},
 	{}
 };
 MODULE_DEVICE_TABLE(of, mtk_drm_hdmi_of_ids);
@@ -438,6 +451,7 @@ static struct platform_driver mtk_hdmi_driver = {
 static struct platform_driver * const mtk_hdmi_drivers[] = {
 	&mtk_hdmi_ddc_driver,
 	&mtk_cec_driver,
+	&mtk_hdmi_ddc_v2_driver,
 	&mtk_hdmi_driver,
 };
 
drivers/gpu/drm/mediatek/mtk_hdmi_common.h +1 -0
index 2e8e5feec377..d030b71b5231 100644
@@ -27,6 +27,7 @@
 
 #include "mtk_cec.h"
 #include "mtk_hdmi.h"
+#include "mtk_hdmi_v2.h"
 
 struct mtk_hdmi_conf {
 	bool tz_disabled;
drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c new file +367 -0

367 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +309 -0

309 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c new file +1379 -0

1,379 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_v2.h new file +29 -0
new file mode 100644
index 000000000000..53cb62e4389d
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ * Copyright (c) 2022 BayLibre, SAS
+ */
+
+#ifndef _MTK_HDMI_V2_CTRL_H
+#define _MTK_HDMI_V2_CTRL_H
+
+#include <linux/hdmi.h>
+#include <drm/drm_bridge.h>
+
+struct mtk_hdmi;
+
+extern struct platform_driver mtk_hdmi_ddc_v2_driver;
+extern const struct drm_bridge_funcs mtk_v2_hdmi_bridge_funcs;
+void mtk_hdmi_output_init_v2(struct mtk_hdmi *hdmi);
+int mtk_hdmi_clk_enable_v2(struct mtk_hdmi *hdmi);
+void mtk_hdmi_clk_disable_v2(struct mtk_hdmi *hdmi);
+
+enum mtk_hdmi_clk_id_v2 {
+	MTK_HDMIV2_HDCP_SEL,
+	MTK_HDMIV2_HDCP_24M_SEL,
+	MTK_HDMIV2_VPP_SPLIT_HDMI,
+	MTK_HDMIV2_CLK_COUNT,
+};
+
+extern const char *const mtk_hdmi_clk_names_v2[MTK_HDMIV2_CLK_COUNT];
+#endif /* _MTK_HDMI_V2_CTRL_H */
Signature · 1 line
b4 0.11.0-dev
#22 lore raw

Re: [PATCH v3 07/12] drm/mediatek: hdmi: add v2 support

Hi, Guillaume:

Quoted 15 lines · Guillaume Ranquet

Adds hdmi and hdmi-ddc support for v2 IP.

---
 drivers/gpu/drm/mediatek/Makefile           |    2 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c  |   14 +
 drivers/gpu/drm/mediatek/mtk_hdmi_common.h  |    1 +
 drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c  |  367 +++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h |  309 ++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.c      | 1379
+++++++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.h      |   29 +
 7 files changed, 2101 insertions(+)

[snip]

Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +4 -0
new file mode 100644
index 000000000000..f4c3652f4eab
@@ -0,0 +1,309 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2021 MediaTek Inc.
+ * Copyright (c) 2021 BayLibre, SAS

drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h line 14

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +10 -0
+ */
+
+#ifndef _MTK_HDMI_REGS_H
+#define _MTK_HDMI_REGS_H
+
+#define AIF_HEADER GENMASK(19, 0)
+#define AIF_PKT00 GENMASK(31, 0)
+#define AIF_PKT01 (23, 0)
+#define AIF_PKT02 (31, 0)
+#define AIF_PKT03 (23, 0)

Useless, drop it.

drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h line 16

Quoted 2 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +2 -0
+
+#define AIP_CTRL BIT(10)

I think this is

#define AIP_CTRL 0x400

Quoted 12 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +12 -0
+#define AIP_CTS_SVAL 0x408
+#define AIP_DOWNSAMPLE_CTRL 0x41C
+#define AIP_I2S_CHST0 0x414
+#define AIP_I2S_CHST1 0x418
+#define AIP_I2S_CTRL 0x410
+#define AIP_N_VAL 0x404
+#define AIP_SPDIF_CTRL 0x40C
+#define AIP_TPI_CTRL 0x428
+#define AIP_TXCTRL 0x424
+
+#define AUD_DIS (0x0)
+#define AUD_DIS_WR (0x0)

drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h line 38

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +10 -0
+#define AUD_EN BIT(2)
+#define AUD_EN_WR BIT(18)
+#define AUD_ERR_THRESH GENMASK(29, 24)
+#define AUD_IN_EN BIT(8)
+#define AUD_MUTE_DIS (0x0)
+#define AUD_MUTE_FIFO_EN BIT(5)
+#define AUD_PACKET_DROP BIT(6)
+#define AUD_RPT_DIS (0x0)
+#define AUD_RPT_EN BIT(2)
+#define AUD_SEL_OWRT BIT(9)

I would like to put the bitwise definition with double word definition together. You could reference [1].

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/mediatek/mtk_disp_rdma.c?h=v6.2-rc1

Regards,
CK

Quoted 43 lines
drivers/gpu/drm/mediatek/mtk_hdmi_regs_v2.h new file +42 -0
+
+#define AVI_DIS (0)
+#define AVI_DIS_WR (0)
+#define AVI_EN (0x1)
+#define AVI_EN_WR BIT(16)
+#define AVI_HEADER GENMASK(23, 0)
+#define AVI_PKT00 GENMASK(31, 0)
+#define AVI_PKT01 GENMASK(23, 0)
+#define AVI_PKT02 GENMASK(31, 0)
+#define AVI_PKT03 GENMASK(23, 0)
+#define AVI_PKT04 GENMASK(31, 0)
+#define AVI_PKT05 GENMASK(23, 0)
+#define AVI_RPT_DIS (0x0)
+#define AVI_RPT_EN (0x1)
+
+#define C422_C420_CONFIG_BYPASS BIT(5)
+#define C422_C420_CONFIG_ENABLE BIT(4)
+#define C422_C420_CONFIG_OUT_CB_OR_CR BIT(6)
+#define C444_C422_CONFIG_ENABLE (0x1)
+
+#define CBIT_ORDER_SAME BIT(13)
+
+#define CEA_AUD_EN BIT(9)
+#define CEA_AVI_EN BIT(11)
+#define CEA_CP_EN BIT(6)
+#define CEA_SPD_EN BIT(10)
+
+#define CLEAR_FIFO 0x9
+
+#define CLOCK_SCL 0xA
+
+#define CP_CLR_MUTE_EN BIT(1)
+#define CP_EN BIT(5)
+#define CP_EN_WR BIT(21)
+#define CP_RPT_EN BIT(5)
+#define CP_SET_MUTE_DIS (0)
+#define CP_SET_MUTE_EN (1)
+
+#define CTS_CAL_N4 BIT(23)
+#define CTS_REQ_EN BIT(1)
+#define CTS_SW_SEL (1)
+
#23 lore raw

PATCH v3 8/12 drm/mediatek: hdmi: v2: add audio support

In reply to Guillaume Ranquet

Add HDMI audio support for v2

---
 drivers/gpu/drm/mediatek/mtk_hdmi_common.c |   1 +
 drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c |   2 +-
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.c     | 213 +++++++++++++++++++++++++++++
 drivers/gpu/drm/mediatek/mtk_hdmi_v2.h     |   2 +
 4 files changed, 217 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +1 -0
index e43c938a9aa5..1ea91f8bb6c7 100644
@@ -386,6 +386,7 @@ static const struct mtk_hdmi_conf mtk_hdmi_conf_v2 = {
 	.mtk_hdmi_output_init = mtk_hdmi_output_init_v2,
 	.mtk_hdmi_clk_disable = mtk_hdmi_clk_disable_v2,
 	.mtk_hdmi_clk_enable = mtk_hdmi_clk_enable_v2,
+	.set_hdmi_codec_pdata = set_hdmi_codec_pdata_v2,
 	.mtk_hdmi_clock_names = mtk_hdmi_clk_names_v2,
 	.num_clocks = MTK_HDMIV2_CLK_COUNT,
 };
drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c +1 -1
index 61696d255e51..26456802a5c4 100644
@@ -309,7 +309,7 @@ static int mtk_hdmi_ddc_probe(struct platform_device *pdev)
 	ddc->regs = device_node_to_regmap(hdmi);
 	of_node_put(hdmi);
 	if (IS_ERR(ddc->regs))
-		return dev_err_probe(dev, PTR_ERR(ddc->regs), "Unable to get mt8195-hdmi syscon");
+		return dev_err_probe(dev, PTR_ERR(ddc->regs), "Unable to get hdmi syscon");
 
 	ddc->clk = devm_clk_get_enabled(dev, "ddc");
 	if (IS_ERR(ddc->clk))
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +213 -0

270 lines not on this page · raw message

drivers/gpu/drm/mediatek/mtk_hdmi_v2.h +2 -0
index 53cb62e4389d..8a397f2ad2c6 100644
@@ -9,6 +9,7 @@
 
 #include <linux/hdmi.h>
 #include <drm/drm_bridge.h>
+#include <sound/hdmi-codec.h>
 
 struct mtk_hdmi;
 
@@ -17,6 +18,7 @@ extern const struct drm_bridge_funcs mtk_v2_hdmi_bridge_funcs;
 void mtk_hdmi_output_init_v2(struct mtk_hdmi *hdmi);
 int mtk_hdmi_clk_enable_v2(struct mtk_hdmi *hdmi);
 void mtk_hdmi_clk_disable_v2(struct mtk_hdmi *hdmi);
+void set_hdmi_codec_pdata_v2(struct hdmi_codec_pdata *codec_data);
 
 enum mtk_hdmi_clk_id_v2 {
 	MTK_HDMIV2_HDCP_SEL,
Signature · 1 line
b4 0.11.0-dev
#24 lore raw

Re: [PATCH v3 08/12] drm/mediatek: hdmi: v2: add audio support

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 15 lines

Add HDMI audio support for v2

---
  drivers/gpu/drm/mediatek/mtk_hdmi_common.c |   1 +
  drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c |   2 +-
  drivers/gpu/drm/mediatek/mtk_hdmi_v2.c     | 213 +++++++++++++++++++++++++++++
  drivers/gpu/drm/mediatek/mtk_hdmi_v2.h     |   2 +
  4 files changed, 217 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +0 -0
index e43c938a9aa5..1ea91f8bb6c7 100644

drivers/gpu/drm/mediatek/mtk_hdmi_common.c static const struct mtk_hdmi_conf mtk_hdmi_conf_v2 = { · line 389

Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +1 -0
@@ -386,6 +386,7 @@ static const struct mtk_hdmi_conf mtk_hdmi_conf_v2 = {
  	.mtk_hdmi_output_init = mtk_hdmi_output_init_v2,
  	.mtk_hdmi_clk_disable = mtk_hdmi_clk_disable_v2,
  	.mtk_hdmi_clk_enable = mtk_hdmi_clk_enable_v2,
+	.set_hdmi_codec_pdata = set_hdmi_codec_pdata_v2,

Keep naming consistent please:

.mtk_hdmi_set_codec_pdata = mtk_hdmi_set_codec_pdata_v2,

drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c static int mtk_hdmi_ddc_probe(struct platform_device *pdev) · line 312

Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_hdmi_common.c +0 -0
  	.mtk_hdmi_clock_names = mtk_hdmi_clk_names_v2,
  	.num_clocks = MTK_HDMIV2_CLK_COUNT,
  };
drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c +1 -1
index 61696d255e51..26456802a5c4 100644
@@ -309,7 +309,7 @@ static int mtk_hdmi_ddc_probe(struct platform_device *pdev)
  	ddc->regs = device_node_to_regmap(hdmi);
  	of_node_put(hdmi);
  	if (IS_ERR(ddc->regs))
-		return dev_err_probe(dev, PTR_ERR(ddc->regs), "Unable to get mt8195-hdmi syscon");
+		return dev_err_probe(dev, PTR_ERR(ddc->regs), "Unable to get hdmi syscon");

You might as well do the rename in the commit that actually introduces this file, since you're doing that in the same series.

Please do so.

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_ddc_v2.c +0 -0
  	ddc->clk = devm_clk_get_enabled(dev, "ddc");
  	if (IS_ERR(ddc->clk))
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +0 -0
index e8457429964d..b391b22fa9f5 100644
@@ -211,6 +211,26 @@ static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black)
  		mtk_hdmi_mask(hdmi, TOP_VMUTE_CFG1, 0, REG_VMUTE_EN);
  }

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black) · line 222

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +9 -0
 
+static void mtk_hdmi_hw_aud_mute(struct mtk_hdmi *hdmi)
+{
+	u32 val;
+
+	val = mtk_hdmi_read(hdmi, AIP_CTRL, &val);
+
+	if (val & DSD_EN)
+		mtk_hdmi_mask(hdmi, AIP_TXCTRL,
+			      DSD_MUTE_DATA | AUD_MUTE_FIFO_EN,

I think I already gave you some advice to shorten this in an earlier series version.

Besides, you can also use the FIELD_PREP() macro here, and please use it.

P.S.:
val = FIELD_PREP(... something AUD_MUTE_FIFO_EN);
if (val & DSD_EN)

	val |= FIELD_PREP( ... something DSD_MUTE_DATA)

mtk_hdmi_mask(hdmi, AIP_TXCTRL, val, val);

Quoted 15 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +11 -0
+			      DSD_MUTE_DATA | AUD_MUTE_FIFO_EN);
+	else
+		mtk_hdmi_mask(hdmi, AIP_TXCTRL, AUD_MUTE_FIFO_EN,
+			      AUD_MUTE_FIFO_EN);
+}
+
+static void mtk_hdmi_hw_aud_unmute(struct mtk_hdmi *hdmi)
+{
+	mtk_hdmi_mask(hdmi, AIP_TXCTRL, AUD_MUTE_DIS, AUD_MUTE_FIFO_EN);
+}
+
  static void mtk_hdmi_hw_reset(struct mtk_hdmi *hdmi)
  {
  	mtk_hdmi_mask(hdmi, HDMITX_CONFIG, 0x0, HDMITX_SW_RSTB);
@@ -889,6 +909,7 @@ static void mtk_hdmi_audio_reset(struct mtk_hdmi *hdmi, bool rst)

..snip..

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c static void mtk_hdmi_reset_colorspace_setting(struct mtk_hdmi *hdmi) · line 960

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +1 -0
@@ -935,6 +957,28 @@ static void mtk_hdmi_reset_colorspace_setting(struct mtk_hdmi *hdmi)
  	hdmi->ycc_quantization_range = HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
  }
 
+static void mtk_hdmi_audio_enable(struct mtk_hdmi *hdmi)

These two functions are used only in one function (each)... so you don't need them. Just move the two lines in mtk_hdmi_audio_startup() ...

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c static void mtk_hdmi_reset_colorspace_setting(struct mtk_hdmi *hdmi) · line 967

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +7 -0
+{
+	mtk_hdmi_aud_enable_packet(hdmi, true);
+	hdmi->audio_enable = true;
+}
+
+static void mtk_hdmi_audio_disable(struct mtk_hdmi *hdmi)
+{

... and in mtk_hdmi_audio_shutdown().

Quoted 17 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +14 -0
+	mtk_hdmi_aud_enable_packet(hdmi, false);
+	hdmi->audio_enable = false;
+}
+
+static void mtk_hdmi_audio_set_param(struct mtk_hdmi *hdmi,
+				     struct hdmi_audio_param *param)
+{
+	if (!hdmi->audio_enable)
+		return;
+
+	memcpy(&hdmi->aud_param, param, sizeof(*param));
+	mtk_hdmi_aud_output_config(hdmi, &hdmi->mode);
+}
+
  static void mtk_hdmi_change_video_resolution(struct mtk_hdmi *hdmi)
  {
  	bool is_over_340M = false;

..snip..

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c const struct drm_bridge_funcs mtk_v2_hdmi_bridge_funcs = { · line 1555

Quoted 7 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +7 -0
+
+static int mtk_hdmi_audio_mute(struct device *dev, void *data, bool enable,
+			       int direction)
+{
+	struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
+
+	if (direction != SNDRV_PCM_STREAM_PLAYBACK)

Why aren't you returning an error here?

If this is really supposed to be like that, please add a comment in the code explaining the reason, so that the next person reading this won't mistakenly change that.

drivers/gpu/drm/mediatek/mtk_hdmi_v2.c const struct drm_bridge_funcs mtk_v2_hdmi_bridge_funcs = { · line 1565

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_hdmi_v2.c +10 -0
+		return 0;
+
+	if (enable)
+		mtk_hdmi_hw_aud_mute(hdmi);
+	else
+		mtk_hdmi_hw_aud_unmute(hdmi);
+
+	return 0;
+}
+

Regards,
Angelo

#25 lore raw

PATCH v3 9/12 phy: phy-mtk-hdmi: Add generic phy configure callback

In reply to Guillaume Ranquet

Some phys, such as mt8195, needs to have a configure callback defined.

---
 drivers/phy/mediatek/phy-mtk-hdmi.c | 12 ++++++++++++
 drivers/phy/mediatek/phy-mtk-hdmi.h |  1 +
 2 files changed, 13 insertions(+)
drivers/phy/mediatek/phy-mtk-hdmi.c +12 -0
index b16d437d6721..32f713301768 100644
@@ -8,10 +8,12 @@
 
 static int mtk_hdmi_phy_power_on(struct phy *phy);
 static int mtk_hdmi_phy_power_off(struct phy *phy);
+static int mtk_hdmi_phy_configure(struct phy *phy, union phy_configure_opts *opts);
 
 static const struct phy_ops mtk_hdmi_phy_dev_ops = {
 	.power_on = mtk_hdmi_phy_power_on,
 	.power_off = mtk_hdmi_phy_power_off,
+	.configure = mtk_hdmi_phy_configure,
 	.owner = THIS_MODULE,
 };
 
@@ -43,6 +45,16 @@ static int mtk_hdmi_phy_power_off(struct phy *phy)
 	return 0;
 }
 
+static int mtk_hdmi_phy_configure(struct phy *phy, union phy_configure_opts *opts)
+{
+	struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
+
+	if (hdmi_phy->conf->hdmi_phy_configure)
+		return hdmi_phy->conf->hdmi_phy_configure(phy, opts);
+
+	return 0;
+}
+
 static const struct phy_ops *
 mtk_hdmi_phy_dev_get_ops(const struct mtk_hdmi_phy *hdmi_phy)
 {
drivers/phy/mediatek/phy-mtk-hdmi.h +1 -0
index c7fa65cff989..f5aac9d352d8 100644
@@ -24,6 +24,7 @@ struct mtk_hdmi_phy_conf {
 	const struct clk_ops *hdmi_phy_clk_ops;
 	void (*hdmi_phy_enable_tmds)(struct mtk_hdmi_phy *hdmi_phy);
 	void (*hdmi_phy_disable_tmds)(struct mtk_hdmi_phy *hdmi_phy);
+	int (*hdmi_phy_configure)(struct phy *phy, union phy_configure_opts *opts);
 };
 
 struct mtk_hdmi_phy {
Signature · 1 line
b4 0.11.0-dev
#26 lore raw

PATCH v3 10/12 phy: mediatek: add support for phy-mtk-hdmi-mt8195

In reply to Guillaume Ranquet

Add basic support for the mediatek hdmi phy on MT8195 SoC

---
 drivers/phy/mediatek/Makefile              |   1 +
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 543 +++++++++++++++++++++++++++++
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h | 109 ++++++
 drivers/phy/mediatek/phy-mtk-hdmi.c        |   3 +
 drivers/phy/mediatek/phy-mtk-hdmi.h        |   1 +
 5 files changed, 657 insertions(+)
drivers/phy/mediatek/Makefile +1 -0
index fb1f8edaffa7..c9a50395533e 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_PHY_MTK_XSPHY)		+= phy-mtk-xsphy.o
 phy-mtk-hdmi-drv-y			:= phy-mtk-hdmi.o
 phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt2701.o
 phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt8173.o
+phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt8195.o
 obj-$(CONFIG_PHY_MTK_HDMI)		+= phy-mtk-hdmi-drv.o
 
 phy-mtk-mipi-dsi-drv-y			:= phy-mtk-mipi-dsi.o
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +543 -0

543 lines not on this page · raw message

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h new file +109 -0

109 lines not on this page · raw message

drivers/phy/mediatek/phy-mtk-hdmi.c +3 -0
index 32f713301768..d2e824771f9d 100644
@@ -161,6 +161,9 @@ static const struct of_device_id mtk_hdmi_phy_match[] = {
 	{ .compatible = "mediatek,mt8173-hdmi-phy",
 	  .data = &mtk_hdmi_phy_8173_conf,
 	},
+	{ .compatible = "mediatek,mt8195-hdmi-phy",
+	  .data = &mtk_hdmi_phy_8195_conf,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, mtk_hdmi_phy_match);
drivers/phy/mediatek/phy-mtk-hdmi.h +1 -0
index f5aac9d352d8..9dfb725fc57f 100644
@@ -44,6 +44,7 @@ struct mtk_hdmi_phy {
 
 struct mtk_hdmi_phy *to_mtk_hdmi_phy(struct clk_hw *hw);
 
+extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_8195_conf;
 extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_8173_conf;
 extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_2701_conf;
 
Signature · 1 line
b4 0.11.0-dev
maintainer
#27 lore raw

Re: [PATCH v3 10/12] phy: mediatek: add support for phy-mtk-hdmi-mt8195

Quoted 1 line · Guillaume Ranquet

Add basic support for the mediatek hdmi phy on MT8195 SoC

Are phy patches in this series dependent upon changes in drm/, if not consider splitting them up!

Quoted 131 lines
---
 drivers/phy/mediatek/Makefile              |   1 +
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c | 543 +++++++++++++++++++++++++++++
 drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h | 109 ++++++
 drivers/phy/mediatek/phy-mtk-hdmi.c        |   3 +
 drivers/phy/mediatek/phy-mtk-hdmi.h        |   1 +
 5 files changed, 657 insertions(+)
drivers/phy/mediatek/Makefile +1 -0
index fb1f8edaffa7..c9a50395533e 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_PHY_MTK_XSPHY)		+= phy-mtk-xsphy.o
 phy-mtk-hdmi-drv-y			:= phy-mtk-hdmi.o
 phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt2701.o
 phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt8173.o
+phy-mtk-hdmi-drv-y			+= phy-mtk-hdmi-mt8195.o
 obj-$(CONFIG_PHY_MTK_HDMI)		+= phy-mtk-hdmi-drv.o
 
 phy-mtk-mipi-dsi-drv-y			:= phy-mtk-mipi-dsi.o
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +103 -0
new file mode 100644
index 000000000000..48efd3936f29
@@ -0,0 +1,543 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ * Copyright (c) 2022 BayLibre, SAS
+ */
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+#include <linux/nvmem-consumer.h>
+
+#include "phy-mtk-io.h"
+#include "phy-mtk-hdmi.h"
+#include "phy-mtk-hdmi-mt8195.h"
+
+static void mtk_hdmi_ana_fifo_en(struct mtk_hdmi_phy *hdmi_phy)
+{
+	/* make data fifo writable for hdmi2.0 */
+	mtk_phy_set_bits(hdmi_phy->regs + HDMI_ANA_CTL, REG_ANA_HDMI20_FIFO_EN);
+}
+
+static void
+mtk_mt8195_phy_tmds_high_bit_clk_ratio(struct mtk_hdmi_phy *hdmi_phy,
+				       bool enable)
+{
+	void __iomem *regs = hdmi_phy->regs;
+
+	mtk_hdmi_ana_fifo_en(hdmi_phy);
+
+	/* HDMI 2.0 specification, 3.4Gbps <= TMDS Bit Rate <= 6G,
+	 * clock bit ratio 1:40, under 3.4Gbps, clock bit ratio 1:10
+	 */
+	if (enable)
+		mtk_phy_update_field(regs + HDMI20_CLK_CFG, REG_TXC_DIV, REG_TXC_DIV);
+	else
+		mtk_phy_clear_bits(regs + HDMI20_CLK_CFG, REG_TXC_DIV);
+}
+
+static void mtk_hdmi_pll_select_source(struct clk_hw *hw)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	void __iomem *regs = hdmi_phy->regs;
+
+	mtk_phy_clear_bits(regs + HDMI_CTL_3, REG_HDMITX_REF_XTAL_SEL);
+	mtk_phy_clear_bits(regs + HDMI_CTL_3, REG_HDMITX_REF_RESPLL_SEL);
+
+	/* DA_HDMITX21_REF_CK for TXPLL input source */
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_10, RG_HDMITXPLL_REF_CK_SEL);
+}
+
+static int mtk_hdmi_pll_performance_setting(struct clk_hw *hw)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	void __iomem *regs = hdmi_phy->regs;
+
+	/* BP2 */
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_0, RG_HDMITXPLL_BP2);
+
+	/* BC */
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_BC);
+
+	/* IC */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_IC, 0x1);
+
+	/* BR */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_BR, 0x2);
+
+	/* IR */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_IR, 0x2);
+
+	/* BP */
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_BP);
+
+	/* IBAND_FIX_EN, RESERVE[14] */
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_0, RG_HDMITXPLL_IBAND_FIX_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT14);
+
+	/* HIKVCO */
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_HIKVCO);
+
+	/* HREN */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_0, RG_HDMITXPLL_HREN, 0x1);
+
+	/* LVR_SEL */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_0, RG_HDMITXPLL_LVR_SEL, 0x1);
+
+	/* RG_HDMITXPLL_RESERVE[12:11] */
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT12_11);
+
+	/* TCL_EN */
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_0, RG_HDMITXPLL_TCL_EN);
+
+	return 0;
+}
+
+static int mtk_hdmi_pll_set_hw(struct clk_hw *hw, unsigned char prediv,
+			       unsigned char fbkdiv_high,
+			       unsigned long fbkdiv_low,
+			       unsigned char fbkdiv_hs3, unsigned char posdiv1,
+			       unsigned char posdiv2, unsigned char txprediv,

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c line 113

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +10 -0
+			       unsigned char txposdiv,
+			       unsigned char digital_div)
+{
+	unsigned char txposdiv_value = 0;
+	unsigned char div3_ctrl_value = 0;
+	unsigned char posdiv_vallue = 0;
+	unsigned char div_ctrl_value = 0;
+	unsigned char reserve_3_2_value = 0;
+	unsigned char prediv_value = 0;
+	unsigned char reserve13_value = 0;

few of these initialization are superfluous, pls remove

Quoted 112 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +112 -0
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	void __iomem *regs = hdmi_phy->regs;
+
+	mtk_hdmi_pll_select_source(hw);
+
+	mtk_hdmi_pll_performance_setting(hw);
+
+	mtk_phy_update_field(regs + HDMI_1_CFG_10, RG_HDMITX21_BIAS_PE_BG_VREF_SEL, 0x2);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_10, RG_HDMITX21_VREF_SEL);
+	mtk_phy_update_field(regs + HDMI_1_CFG_9, RG_HDMITX21_SLDO_VREF_SEL, 0x2);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_10, RG_HDMITX21_BIAS_PE_VREF_SELB);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_3, RG_HDMITX21_SLDOLPF_EN);
+	mtk_phy_update_field(regs + HDMI_1_CFG_6, RG_HDMITX21_INTR_CAL, 0x11);
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_PWD);
+
+	/* TXPOSDIV */
+	txposdiv_value = ilog2(txposdiv);
+
+	mtk_phy_update_field(regs + HDMI_1_CFG_6, RG_HDMITX21_TX_POSDIV, txposdiv_value);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_TX_POSDIV_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_FRL_EN);
+
+	/* TXPREDIV */
+	switch (txprediv) {
+	case 2:
+		div3_ctrl_value = 0x0;
+		posdiv_vallue = 0x0;
+		break;
+	case 4:
+		div3_ctrl_value = 0x0;
+		posdiv_vallue = 0x1;
+		break;
+	case 6:
+		div3_ctrl_value = 0x1;
+		posdiv_vallue = 0x0;
+		break;
+	case 12:
+		div3_ctrl_value = 0x1;
+		posdiv_vallue = 0x1;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_4, RG_HDMITXPLL_POSDIV_DIV3_CTRL, div3_ctrl_value);
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_4, RG_HDMITXPLL_POSDIV, posdiv_vallue );
+
+	/* POSDIV1 */
+	switch (posdiv1) {
+	case 5:
+		div_ctrl_value = 0x0;
+		break;
+	case 10:
+		div_ctrl_value = 0x1;
+		break;
+	case 12:
+		div_ctrl_value = 0x2;
+		break;
+	case 15:
+		div_ctrl_value = 0x3;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_4, RG_HDMITXPLL_DIV_CTRL, div_ctrl_value);
+
+	/* DE add new setting */
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT14);
+
+	/* POSDIV2 */
+	switch (posdiv2) {
+		case 1:
+			reserve_3_2_value = 0x0;
+			break;
+		case 2:
+			reserve_3_2_value = 0x1;
+			break;
+		case 4:
+			reserve_3_2_value = 0x2;
+			break;
+		case 6:
+			reserve_3_2_value = 0x3;
+			break;
+		default:
+			return -EINVAL;
+	}
+
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT3_2, reserve_3_2_value);
+
+	/* DE add new setting */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT1_0, 0x2);
+
+	/* PREDIV */
+	prediv_value = ilog2(prediv);
+
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_4, RG_HDMITXPLL_PREDIV, prediv_value);
+
+	/* FBKDIV_HS3 */
+	reserve13_value = ilog2(fbkdiv_hs3);
+
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_1, RG_HDMITXPLL_RESERVE_BIT13, reserve13_value);
+
+	/* FBDIV */
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_4, RG_HDMITXPLL_FBKDIV_HIGH, fbkdiv_high);
+	mtk_phy_update_field(regs + HDMI_1_PLL_CFG_3, RG_HDMITXPLL_FBKDIV_LOW, fbkdiv_low);
+
+
+	/* Digital DIVIDER */
+	mtk_phy_clear_bits(regs + HDMI_CTL_3, REG_PIXEL_CLOCK_SEL);
+
+	if (digital_div == 1) {

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c line 235

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +10 -0
+		mtk_phy_clear_bits(regs + HDMI_CTL_3, REG_HDMITX_PIXEL_CLOCK);
+	} else {
+		mtk_phy_set_bits(regs + HDMI_CTL_3, REG_HDMITX_PIXEL_CLOCK);
+		mtk_phy_update_field(regs + HDMI_CTL_3, REG_HDMITXPLL_DIV, digital_div - 1);
+	}
+
+	return 0;
+}
+
+#define PCW_DECIMAL_WIDTH 24

can we have defines at top of the file please, grouped together

Quoted 15 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +15 -0
+static int mtk_hdmi_pll_calculate_params(struct clk_hw *hw, unsigned long rate,
+					 unsigned long parent_rate)
+{
+	int ret;
+	unsigned long long tmds_clk = 0;
+	unsigned long long pixel_clk = 0;
+	/* pll input source frequency */
+	unsigned long long da_hdmitx21_ref_ck = 0;
+	/* ICO output clk */
+	unsigned long long ns_hdmipll_ck = 0;
+	/* source clk for Display digital */
+	unsigned long long ad_hdmipll_pixel_ck = 0;
+	unsigned char digital_div = 0;
+	unsigned long long pcw = 0;
+	unsigned char txprediv = 0;

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c line 261

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +10 -0
+	unsigned char txposdiv = 0;
+	unsigned char fbkdiv_high = 0;
+	unsigned long fbkdiv_low = 0;
+	unsigned char posdiv1 = 0;
+	unsigned char posdiv2 = 0;
+	/* prediv is always 1 */
+	unsigned char prediv = 1;
+	/* fbkdiv_hs3 is always 1 */
+	unsigned char fbkdiv_hs3 = 1;
+	int i = 0;

here as well...

Quoted 250 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +250 -0
+	unsigned char txpredivs[4] = { 2, 4, 6, 12 };
+
+	pixel_clk = rate;
+	tmds_clk = pixel_clk;
+
+	if (tmds_clk < 25000000 || tmds_clk > 594000000)
+		return -EINVAL;
+
+	/* in Hz */
+	da_hdmitx21_ref_ck = 26000000UL;
+
+	/*  TXPOSDIV stage treatment:
+	 *	0M  <  TMDS clk  < 54M		  /8
+	 *	54M <= TMDS clk  < 148.35M    /4
+	 *	148.35M <=TMDS clk < 296.7M   /2
+	 *	296.7 <=TMDS clk <= 594M	  /1
+	 */
+	if (tmds_clk < 54000000UL)
+		txposdiv = 8;
+	else if (tmds_clk >= 54000000UL && tmds_clk < 148350000UL)
+		txposdiv = 4;
+	else if (tmds_clk >= 148350000UL && tmds_clk < 296700000UL)
+		txposdiv = 2;
+	else if (tmds_clk >= 296700000UL && tmds_clk <= 594000000UL)
+		txposdiv = 1;
+	else
+		return -EINVAL;
+
+	/* calculate txprediv: can be 2, 4, 6, 12
+	 * ICO clk = 5*TMDS_CLK*TXPOSDIV*TXPREDIV
+	 * ICO clk constraint: 5G =< ICO clk <= 12G
+	 */
+	for (i = 0; i < ARRAY_SIZE(txpredivs); i++) {
+		ns_hdmipll_ck = 5 * tmds_clk * txposdiv * txpredivs[i];
+		if (ns_hdmipll_ck >= 5000000000UL &&
+		    ns_hdmipll_ck <= 12000000000UL)
+			break;
+	}
+	if (i == (ARRAY_SIZE(txpredivs) - 1) &&
+	    (ns_hdmipll_ck < 5000000000UL || ns_hdmipll_ck > 12000000000UL)) {
+		return -EINVAL;
+	}
+	if (i == ARRAY_SIZE(txpredivs))
+		return -EINVAL;
+
+	txprediv = txpredivs[i];
+
+	/* PCW calculation: FBKDIV
+	 * formula: pcw=(frequency_out*2^pcw_bit) / frequency_in / FBKDIV_HS3;
+	 * RG_HDMITXPLL_FBKDIV[32:0]:
+	 * [32,24] 9bit integer, [23,0]:24bit fraction
+	 */
+	pcw = ns_hdmipll_ck;
+	pcw = pcw << PCW_DECIMAL_WIDTH;
+	pcw = pcw / da_hdmitx21_ref_ck;
+	pcw = pcw / fbkdiv_hs3;
+
+	if ((pcw / BIT(32)) > 1) {
+		return -EINVAL;
+	} else if ((pcw / BIT(32)) == 1) {
+		fbkdiv_high = 1;
+		fbkdiv_low = pcw % BIT(32);
+	} else {
+		fbkdiv_high = 0;
+		fbkdiv_low = pcw;
+	}
+
+	/* posdiv1:
+	 * posdiv1 stage treatment according to color_depth:
+	 * 24bit -> posdiv1 /10, 30bit -> posdiv1 /12.5,
+	 * 36bit -> posdiv1 /15, 48bit -> posdiv1 /10
+	 */
+	posdiv1 = 10;
+	posdiv2 = 1;
+	ad_hdmipll_pixel_ck = (ns_hdmipll_ck / 10) / 1;
+
+	/* Digital clk divider, max /32 */
+	digital_div = ad_hdmipll_pixel_ck / pixel_clk;
+	if (!(digital_div <= 32 && digital_div >= 1))
+		return -EINVAL;
+
+	ret = mtk_hdmi_pll_set_hw(hw, prediv, fbkdiv_high, fbkdiv_low,
+				  fbkdiv_hs3, posdiv1, posdiv2, txprediv,
+				  txposdiv, digital_div);
+	if (ret)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int mtk_hdmi_pll_drv_setting(struct clk_hw *hw)
+{
+	unsigned char data_channel_bias, clk_channel_bias;
+	unsigned char impedance, impedance_en;
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	unsigned long tmds_clk;
+	unsigned long pixel_clk = hdmi_phy->pll_rate;
+	void __iomem *regs = hdmi_phy->regs;
+
+	tmds_clk = pixel_clk;
+
+	/* bias & impedance setting:
+	 * 3G < data rate <= 6G: enable impedance 100ohm,
+	 *      data channel bias 24mA, clock channel bias 20mA
+	 * pixel clk >= HD,  74.175MHZ <= pixel clk <= 300MHZ:
+	 *      enalbe impedance 100ohm
+	 *      data channel 20mA, clock channel 16mA
+	 * 27M =< pixel clk < 74.175: disable impedance
+	 *      data channel & clock channel bias 10mA
+	 */
+
+	/* 3G < data rate <= 6G, 300M < tmds rate <= 594M */
+	if (tmds_clk > 300000000UL && tmds_clk <= 594000000UL) {
+		data_channel_bias = 0x3c; /* 24mA */
+		clk_channel_bias = 0x34; /* 20mA */
+		impedance_en = 0xf;
+		impedance = 0x36; /* 100ohm */
+	} else if (pixel_clk >= 74175000UL && pixel_clk <= 300000000UL) {
+		data_channel_bias = 0x34; /* 20mA */
+		clk_channel_bias = 0x2c; /* 16mA */
+		impedance_en = 0xf;
+		impedance = 0x36; /* 100ohm */
+	} else if (pixel_clk >= 27000000UL && pixel_clk < 74175000UL) {
+		data_channel_bias = 0x14; /* 10mA */
+		clk_channel_bias = 0x14; /* 10mA */
+		impedance_en = 0x0;
+		impedance = 0x0;
+	} else {
+		return -EINVAL;
+	}
+
+	/* bias */
+	mtk_phy_update_field(regs + HDMI_1_CFG_1, RG_HDMITX21_DRV_IBIAS_D0, data_channel_bias);
+	mtk_phy_update_field(regs + HDMI_1_CFG_1, RG_HDMITX21_DRV_IBIAS_D1, data_channel_bias);
+	mtk_phy_update_field(regs + HDMI_1_CFG_1, RG_HDMITX21_DRV_IBIAS_D2, data_channel_bias);
+	mtk_phy_update_field(regs + HDMI_1_CFG_0, RG_HDMITX21_DRV_IBIAS_CLK, clk_channel_bias);
+
+	/* impedance */
+	mtk_phy_update_field(regs + HDMI_1_CFG_0, RG_HDMITX21_DRV_IMP_EN, impedance_en);
+	mtk_phy_update_field(regs + HDMI_1_CFG_2, RG_HDMITX21_DRV_IMP_D0_EN1, impedance);
+	mtk_phy_update_field(regs + HDMI_1_CFG_2, RG_HDMITX21_DRV_IMP_D1_EN1, impedance);
+	mtk_phy_update_field(regs + HDMI_1_CFG_2, RG_HDMITX21_DRV_IMP_D2_EN1, impedance);
+	mtk_phy_update_field(regs + HDMI_1_CFG_2, RG_HDMITX21_DRV_IMP_CLK_EN1, impedance);
+
+	return 0;
+}
+
+static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	void __iomem *regs = hdmi_phy->regs;
+
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_TX_POSDIV_EN);
+
+	mtk_phy_set_bits(regs + HDMI_1_CFG_0, RG_HDMITX21_SER_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_D0_DRV_OP_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_D1_DRV_OP_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_D2_DRV_OP_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_CK_DRV_OP_EN);
+
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_FRL_D0_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_FRL_D1_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_FRL_D2_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_FRL_CK_EN);
+
+	mtk_hdmi_pll_drv_setting(hw);
+
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_10, RG_HDMITX21_BG_PWD);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_BIAS_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_3, RG_HDMITX21_CKLDO_EN);
+	mtk_phy_set_bits(regs + HDMI_1_CFG_3, RG_HDMITX21_SLDO_EN);
+
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_4, DA_HDMITXPLL_PWR_ON);
+	usleep_range(5, 10);
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_4, DA_HDMITXPLL_ISO_EN);
+	usleep_range(5, 10);
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_PWD);
+	usleep_range(30, 50);
+	return 0;
+}
+
+static void mtk_hdmi_pll_unprepare(struct clk_hw *hw)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+	void __iomem *regs = hdmi_phy->regs;
+
+	mtk_phy_set_bits(regs + HDMI_1_CFG_10, RG_HDMITX21_BG_PWD);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_6, RG_HDMITX21_BIAS_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_3, RG_HDMITX21_CKLDO_EN);
+	mtk_phy_clear_bits(regs + HDMI_1_CFG_3, RG_HDMITX21_SLDO_EN);
+
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_2, RG_HDMITXPLL_PWD);
+	usleep_range(10, 20);
+	mtk_phy_set_bits(regs + HDMI_1_PLL_CFG_4, DA_HDMITXPLL_ISO_EN);
+	usleep_range(10, 20);
+	mtk_phy_clear_bits(regs + HDMI_1_PLL_CFG_4, DA_HDMITXPLL_PWR_ON);
+}
+
+static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
+				 unsigned long parent_rate)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+
+	dev_dbg(hdmi_phy->dev, "%s: %lu Hz, parent: %lu Hz\n", __func__, rate,
+		parent_rate);
+
+	return mtk_hdmi_pll_calculate_params(hw, rate, parent_rate);
+}
+
+static long mtk_hdmi_pll_round_rate(struct clk_hw *hw, unsigned long rate,
+				    unsigned long *parent_rate)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+
+	hdmi_phy->pll_rate = rate;
+	return rate;
+}
+
+static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
+					      unsigned long parent_rate)
+{
+	struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
+
+	return hdmi_phy->pll_rate;
+}
+
+static const struct clk_ops mtk_hdmi_pll_ops = {
+	.prepare = mtk_hdmi_pll_prepare,
+	.unprepare = mtk_hdmi_pll_unprepare,
+	.set_rate = mtk_hdmi_pll_set_rate,
+	.round_rate = mtk_hdmi_pll_round_rate,
+	.recalc_rate = mtk_hdmi_pll_recalc_rate,
+};
+
+static void vtx_signal_en(struct mtk_hdmi_phy *hdmi_phy, bool on)
+{
+	void __iomem *regs = hdmi_phy->regs;
+
+	if (on)
+		mtk_phy_set_bits(regs + HDMI_1_CFG_0, RG_HDMITX21_DRV_EN);
+	else
+		mtk_phy_clear_bits(regs + HDMI_1_CFG_0, RG_HDMITX21_DRV_EN);
+}
+
+static void mtk_hdmi_phy_enable_tmds(struct mtk_hdmi_phy *hdmi_phy)
+{
+	vtx_signal_en(hdmi_phy, true);
+	usleep_range(100, 150);
+}
+

drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c line 521

Quoted 10 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +10 -0
+static void mtk_hdmi_phy_disable_tmds(struct mtk_hdmi_phy *hdmi_phy)
+{
+	vtx_signal_en(hdmi_phy, false);
+}
+
+static int mtk_hdmi_phy_configure(struct phy *phy, union phy_configure_opts *opts)
+{
+	struct phy_configure_opts_dp *dp_opts = &opts->dp;
+	struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
+	int ret = 0;

again!

Quoted 166 lines
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.c new file +22 -0
+
+	ret = clk_set_rate(hdmi_phy->pll, dp_opts->link_rate);
+
+	if (ret)
+		return ret;
+
+	mtk_mt8195_phy_tmds_high_bit_clk_ratio(hdmi_phy, false);
+
+	return ret;
+}
+
+struct mtk_hdmi_phy_conf mtk_hdmi_phy_8195_conf = {
+	.flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE,
+	.hdmi_phy_clk_ops = &mtk_hdmi_pll_ops,
+	.hdmi_phy_enable_tmds = mtk_hdmi_phy_enable_tmds,
+	.hdmi_phy_disable_tmds = mtk_hdmi_phy_disable_tmds,
+	.hdmi_phy_configure = mtk_hdmi_phy_configure,
+};
+
+MODULE_AUTHOR("Can Zeng <[email protected]>");
+MODULE_DESCRIPTION("MediaTek MT8195 HDMI PHY Driver");
+MODULE_LICENSE("GPL v2");
drivers/phy/mediatek/phy-mtk-hdmi-mt8195.h new file +109 -0
new file mode 100644
index 000000000000..2c139f57ab91
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ * Copyright (c) 2022 BayLibre, SAS
+ */
+
+#ifndef _MTK_HDMI_PHY_8195_H
+#define _MTK_HDMI_PHY_8195_H
+
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/types.h>
+
+#define HDMI20_CLK_CFG 0x70
+#define REG_TXC_DIV GENMASK(31, 30)
+
+#define HDMI_1_CFG_0 0x00
+#define RG_HDMITX21_DRV_IBIAS_CLK GENMASK(10, 5)
+#define RG_HDMITX21_DRV_IMP_EN GENMASK(23, 20)
+#define RG_HDMITX21_DRV_EN GENMASK(27, 24)
+#define RG_HDMITX21_SER_EN GENMASK(31, 28)
+
+#define HDMI_1_CFG_1 0x04
+#define RG_HDMITX21_DRV_IBIAS_D0 GENMASK(19, 14)
+#define RG_HDMITX21_DRV_IBIAS_D1 GENMASK(25, 20)
+#define RG_HDMITX21_DRV_IBIAS_D2 GENMASK(31, 26)
+
+#define HDMI_1_CFG_10 0x40
+#define RG_HDMITXPLL_REF_CK_SEL GENMASK(2, 1)
+#define RG_HDMITX21_VREF_SEL BIT(4)
+#define RG_HDMITX21_BIAS_PE_VREF_SELB BIT(10)
+#define RG_HDMITX21_BIAS_PE_BG_VREF_SEL GENMASK(16, 15)
+#define RG_HDMITX21_BG_PWD BIT(20)
+
+#define HDMI_1_CFG_2 0x08
+#define RG_HDMITX21_DRV_IMP_D0_EN1 GENMASK(13, 8)
+#define RG_HDMITX21_DRV_IMP_D1_EN1 GENMASK(19, 14)
+#define RG_HDMITX21_DRV_IMP_D2_EN1 GENMASK(25, 20)
+#define RG_HDMITX21_DRV_IMP_CLK_EN1 GENMASK(31, 26)
+
+#define HDMI_1_CFG_3 0x0c
+#define RG_HDMITX21_CKLDO_EN BIT(3)
+#define RG_HDMITX21_SLDOLPF_EN BIT(7)
+#define RG_HDMITX21_SLDO_EN GENMASK(11, 8)
+
+#define HDMI_1_CFG_6 0x18
+#define RG_HDMITX21_D2_DRV_OP_EN BIT(8)
+#define RG_HDMITX21_D1_DRV_OP_EN BIT(9)
+#define RG_HDMITX21_D0_DRV_OP_EN BIT(10)
+#define RG_HDMITX21_CK_DRV_OP_EN BIT(11)
+#define RG_HDMITX21_FRL_EN BIT(12)
+#define RG_HDMITX21_FRL_CK_EN BIT(13)
+#define RG_HDMITX21_FRL_D0_EN BIT(14)
+#define RG_HDMITX21_FRL_D1_EN BIT(15)
+#define RG_HDMITX21_FRL_D2_EN BIT(16)
+#define RG_HDMITX21_INTR_CAL GENMASK(22, 18)
+#define RG_HDMITX21_TX_POSDIV GENMASK(27, 26)
+#define RG_HDMITX21_TX_POSDIV_EN BIT(28)
+#define RG_HDMITX21_BIAS_EN BIT(29)
+
+#define HDMI_1_CFG_9 0x24
+#define RG_HDMITX21_SLDO_VREF_SEL GENMASK(5, 4)
+
+#define HDMI_1_PLL_CFG_0 0x44
+#define RG_HDMITXPLL_HREN GENMASK(13, 12)
+#define RG_HDMITXPLL_IBAND_FIX_EN BIT(24)
+#define RG_HDMITXPLL_LVR_SEL GENMASK(27, 26)
+#define RG_HDMITXPLL_BP2 BIT(30)
+#define RG_HDMITXPLL_TCL_EN BIT(31)
+
+#define HDMI_1_PLL_CFG_1 0x48
+#define RG_HDMITXPLL_RESERVE_BIT1_0 GENMASK(1, 0)
+#define RG_HDMITXPLL_RESERVE_BIT3_2 GENMASK(3, 2)
+#define RG_HDMITXPLL_RESERVE_BIT12_11 GENMASK(12, 11)
+#define RG_HDMITXPLL_RESERVE_BIT13 BIT(13)
+#define RG_HDMITXPLL_RESERVE_BIT14 BIT(14)
+
+#define HDMI_1_PLL_CFG_2 0x4c
+#define RG_HDMITXPLL_BC GENMASK(28, 27)
+#define RG_HDMITXPLL_IC GENMASK(26, 22)
+#define RG_HDMITXPLL_BR GENMASK(21, 19)
+#define RG_HDMITXPLL_IR GENMASK(18, 14)
+#define RG_HDMITXPLL_BP GENMASK(13, 10)
+#define RG_HDMITXPLL_HIKVCO BIT(29)
+#define RG_HDMITXPLL_PWD BIT(31)
+
+#define HDMI_1_PLL_CFG_3 0x50
+#define RG_HDMITXPLL_FBKDIV_LOW GENMASK(31, 0)
+
+#define HDMI_1_PLL_CFG_4 0x54
+#define DA_HDMITXPLL_ISO_EN BIT(1)
+#define DA_HDMITXPLL_PWR_ON BIT(2)
+#define RG_HDMITXPLL_POSDIV_DIV3_CTRL BIT(21)
+#define RG_HDMITXPLL_POSDIV GENMASK(23, 22)
+#define RG_HDMITXPLL_DIV_CTRL GENMASK(25, 24)
+#define RG_HDMITXPLL_PREDIV GENMASK(29, 28)
+#define RG_HDMITXPLL_FBKDIV_HIGH BIT(31)
+
+#define HDMI_ANA_CTL 0x7c
+#define REG_ANA_HDMI20_FIFO_EN BIT(16)
+
+#define HDMI_CTL_3 0xcc
+#define REG_HDMITXPLL_DIV GENMASK(4, 0)
+#define REG_HDMITX_REF_XTAL_SEL BIT(7)
+#define REG_HDMITX_REF_RESPLL_SEL BIT(9)
+#define REG_PIXEL_CLOCK_SEL BIT(10)
+#define REG_HDMITX_PIXEL_CLOCK BIT(23)
+
+#endif /* MTK_HDMI_PHY_8195_H */
drivers/phy/mediatek/phy-mtk-hdmi.c +3 -0
index 32f713301768..d2e824771f9d 100644
@@ -161,6 +161,9 @@ static const struct of_device_id mtk_hdmi_phy_match[] = {
 	{ .compatible = "mediatek,mt8173-hdmi-phy",
 	  .data = &mtk_hdmi_phy_8173_conf,
 	},
+	{ .compatible = "mediatek,mt8195-hdmi-phy",
+	  .data = &mtk_hdmi_phy_8195_conf,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, mtk_hdmi_phy_match);
drivers/phy/mediatek/phy-mtk-hdmi.h +1 -0
index f5aac9d352d8..9dfb725fc57f 100644
@@ -44,6 +44,7 @@ struct mtk_hdmi_phy {
 
 struct mtk_hdmi_phy *to_mtk_hdmi_phy(struct clk_hw *hw);
 
+extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_8195_conf;
 extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_8173_conf;
 extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_2701_conf;
 
Signature · 2 lines
-- 
b4 0.11.0-dev
Signature · 1 line
~Vinod
#28 lore raw

PATCH v3 11/12 dt-bindings: display: mediatek: dpi: Add compatible for MediaTek MT8195

In reply to Guillaume Ranquet

Add dt-binding documentation of dpi for MediaTek MT8195 SoC.

---
 Documentation/devicetree/bindings/display/mediatek/mediatek,dpi.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/display/mediatek/mediatek,dpi.yaml +1 -0
index 5bb23e97cf33..2c7ecef54986 100644
@@ -24,6 +24,7 @@ properties:
       - mediatek,mt8183-dpi
       - mediatek,mt8186-dpi
       - mediatek,mt8192-dpi
+      - mediatek,mt8195-dpi
       - mediatek,mt8195-dp-intf
 
   reg:
Signature · 1 line
b4 0.11.0-dev
#29 lore raw

PATCH v3 12/12 drm/mediatek: dpi: Add mt8195 hdmi to DPI driver

In reply to Guillaume Ranquet

Add the DPI1 hdmi path support in mtk dpi driver

---
 drivers/gpu/drm/mediatek/mtk_dpi.c      | 143 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/mediatek/mtk_dpi_regs.h |   5 ++
 2 files changed, 141 insertions(+), 7 deletions(-)
drivers/gpu/drm/mediatek/mtk_dpi.c +136 -7
index 508a6d994e83..8052b47042b8 100644
@@ -14,7 +14,10 @@
 #include <linux/of_graph.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
+#include <linux/reset.h>
 #include <linux/types.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #include <video/videomode.h>
 
@@ -65,10 +68,14 @@ struct mtk_dpi {
 	struct drm_bridge *next_bridge;
 	struct drm_connector *connector;
 	void __iomem *regs;
+	struct reset_control *reset_ctl;
 	struct device *dev;
 	struct clk *engine_clk;
+	struct clk *dpi_ck_cg;
 	struct clk *pixel_clk;
+	struct clk *dpi_sel_clk;
 	struct clk *tvd_clk;
+	struct clk *hdmi_cg;
 	int irq;
 	struct drm_display_mode mode;
 	const struct mtk_dpi_conf *conf;
@@ -134,6 +141,7 @@ struct mtk_dpi_yc_limit {
  * @yuv422_en_bit: Enable bit of yuv422.
  * @csc_enable_bit: Enable bit of CSC.
  * @pixels_per_iter: Quantity of transferred pixels per iteration.
+ * @is_internal_hdmi: True if this DPI block is directly connected to SoC internal HDMI block
  */
 struct mtk_dpi_conf {
 	unsigned int (*cal_factor)(int clock);
@@ -152,6 +160,7 @@ struct mtk_dpi_conf {
 	u32 yuv422_en_bit;
 	u32 csc_enable_bit;
 	u32 pixels_per_iter;
+	bool is_internal_hdmi;
 };
 
 static void mtk_dpi_mask(struct mtk_dpi *dpi, u32 offset, u32 val, u32 mask)
@@ -465,8 +474,15 @@ static void mtk_dpi_power_off(struct mtk_dpi *dpi)
 		pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio);
 
 	mtk_dpi_disable(dpi);
+
+	reset_control_rearm(dpi->reset_ctl);
+
 	clk_disable_unprepare(dpi->pixel_clk);
 	clk_disable_unprepare(dpi->engine_clk);
+	clk_disable_unprepare(dpi->dpi_sel_clk);
+	clk_disable_unprepare(dpi->dpi_ck_cg);
+	clk_disable_unprepare(dpi->hdmi_cg);
+	clk_disable_unprepare(dpi->tvd_clk);
 }
 
 static int mtk_dpi_power_on(struct mtk_dpi *dpi)
@@ -482,12 +498,44 @@ static int mtk_dpi_power_on(struct mtk_dpi *dpi)
 		goto err_refcount;
 	}
 
+	ret = clk_prepare_enable(dpi->dpi_sel_clk);
+	if (ret) {
+		dev_err(dpi->dev, "failed to enable dpi_sel clock: %d\n", ret);
+		goto err_refcount;
+	}
+
+	ret = clk_prepare_enable(dpi->tvd_clk);
+	if (ret) {
+		dev_err(dpi->dev, "Failed to enable tvd pll: %d\n", ret);
+		goto err_tvd;
+	}
+
+	ret = clk_prepare_enable(dpi->engine_clk);
+	if (ret) {
+		dev_err(dpi->dev, "Failed to enable engine clock: %d\n", ret);
+		goto err_engine;
+	}
+
+	ret = clk_prepare_enable(dpi->hdmi_cg);
+	if (ret) {
+		dev_err(dpi->dev, "Failed to enable hdmi_cg clock: %d\n", ret);
+		goto err_hdmi_cg;
+	}
+
+	ret = clk_prepare_enable(dpi->dpi_ck_cg);
+	if (ret) {
+		dev_err(dpi->dev, "Failed to enable dpi_ck_cg clock: %d\n", ret);
+		goto err_ck_cg;
+	}
+
 	ret = clk_prepare_enable(dpi->pixel_clk);
 	if (ret) {
 		dev_err(dpi->dev, "Failed to enable pixel clock: %d\n", ret);
 		goto err_pixel;
 	}
 
+	reset_control_reset(dpi->reset_ctl);
+
 	if (dpi->pinctrl && dpi->pins_dpi)
 		pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi);
 
@@ -495,6 +543,15 @@ static int mtk_dpi_power_on(struct mtk_dpi *dpi)
 
 err_pixel:
 	clk_disable_unprepare(dpi->engine_clk);
+	clk_disable_unprepare(dpi->dpi_ck_cg);
+err_ck_cg:
+	clk_disable_unprepare(dpi->hdmi_cg);
+err_hdmi_cg:
+	clk_disable_unprepare(dpi->engine_clk);
+err_engine:
+	clk_disable_unprepare(dpi->tvd_clk);
+err_tvd:
+	clk_disable_unprepare(dpi->dpi_sel_clk);
 err_refcount:
 	dpi->refcount--;
 	return ret;
@@ -538,7 +595,6 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
 	else
 		clk_set_rate(dpi->pixel_clk, vm.pixelclock);
 
-
 	vm.pixelclock = clk_get_rate(dpi->pixel_clk);
 
 	dev_dbg(dpi->dev, "Got  PLL %lu Hz, pixel clock %lu Hz\n",
@@ -605,7 +661,16 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
 	if (dpi->conf->support_direct_pin) {
 		mtk_dpi_config_yc_map(dpi, dpi->yc_map);
 		mtk_dpi_config_2n_h_fre(dpi);
-		mtk_dpi_dual_edge(dpi);
+		/* DPI could be connecting to external bridge
+		 * or internal HDMI encoder. */
+		if (dpi->conf->is_internal_hdmi) {
+			mtk_dpi_mask(dpi, DPI_CON, DPI_OUTPUT_1T1P_EN,
+				     DPI_OUTPUT_1T1P_EN);
+			mtk_dpi_mask(dpi, DPI_CON, DPI_INPUT_2P_EN,
+				     DPI_INPUT_2P_EN);
+		} else {
+			mtk_dpi_dual_edge(dpi);
+		}
 		mtk_dpi_config_disable_edge(dpi);
 	}
 	if (dpi->conf->input_2pixel) {
@@ -720,7 +785,10 @@ static void mtk_dpi_bridge_disable(struct drm_bridge *bridge)
 {
 	struct mtk_dpi *dpi = bridge_to_dpi(bridge);
 
-	mtk_dpi_power_off(dpi);
+	if (dpi->conf->is_internal_hdmi)
+		mtk_dpi_power_off(dpi);
+	else
+		mtk_dpi_disable(dpi);
 }
 
 static void mtk_dpi_bridge_enable(struct drm_bridge *bridge)
@@ -763,14 +831,16 @@ void mtk_dpi_start(struct device *dev)
 {
 	struct mtk_dpi *dpi = dev_get_drvdata(dev);
 
-	mtk_dpi_power_on(dpi);
+	if (!dpi->conf->is_internal_hdmi)
+		mtk_dpi_power_on(dpi);
 }
 
 void mtk_dpi_stop(struct device *dev)
 {
 	struct mtk_dpi *dpi = dev_get_drvdata(dev);
 
-	mtk_dpi_power_off(dpi);
+	if (!dpi->conf->is_internal_hdmi)
+		mtk_dpi_power_off(dpi);
 }
 
 static int mtk_dpi_bind(struct device *dev, struct device *master, void *data)
@@ -853,6 +923,11 @@ static unsigned int mt8183_calculate_factor(int clock)
 		return 2;
 }
 
+static unsigned int mt8195_calculate_factor(int clock)
+{
+	return 1;
+}
+
 static unsigned int mt8195_dpintf_calculate_factor(int clock)
 {
 	if (clock < 70000)
@@ -946,6 +1021,24 @@ static const struct mtk_dpi_conf mt8192_conf = {
 	.csc_enable_bit = CSC_ENABLE,
 };
 
+static const struct mtk_dpi_conf mt8195_conf = {
+	.cal_factor = mt8195_calculate_factor,
+	.max_clock_khz = 594000,
+	.reg_h_fre_con = 0xe0,
+	.output_fmts = mt8183_output_fmts,
+	.num_output_fmts = ARRAY_SIZE(mt8183_output_fmts),
+	.pixels_per_iter = 1,
+	.is_ck_de_pol = true,
+	.swap_input_support = true,
+	.dimension_mask = HPW_MASK,
+	.hvsize_mask = HSIZE_MASK,
+	.channel_swap_shift = CH_SWAP,
+	.yuv422_en_bit = YUV422_EN,
+	.csc_enable_bit = CSC_ENABLE,
+	.is_internal_hdmi = true,
+	.support_direct_pin = true,
+};
+
 static const struct mtk_dpi_conf mt8195_dpintf_conf = {
 	.cal_factor = mt8195_dpintf_calculate_factor,
 	.max_clock_khz = 600000,
@@ -1003,6 +1096,12 @@ static int mtk_dpi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	dpi->reset_ctl = devm_reset_control_get_optional_exclusive(dev, "dpi_on");
+	if (IS_ERR(dpi->reset_ctl)) {
+		dev_err(dev, "Failed to get reset_ctl: %ld\n", PTR_ERR(dpi->reset_ctl));
+		return PTR_ERR(dpi->reset_ctl);
+	}
+
 	dpi->engine_clk = devm_clk_get(dev, "engine");
 	if (IS_ERR(dpi->engine_clk)) {
 		ret = PTR_ERR(dpi->engine_clk);
@@ -1012,7 +1111,26 @@ static int mtk_dpi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	dpi->pixel_clk = devm_clk_get(dev, "pixel");
+	dpi->hdmi_cg = devm_clk_get_optional(dev, "hdmi_cg");
+	if (IS_ERR(dpi->hdmi_cg)) {
+		ret = PTR_ERR(dpi->hdmi_cg);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get hdmi_cg clock: %d\n", ret);
+
+		return ret;
+	}
+
+	dpi->dpi_ck_cg = devm_clk_get_optional(dev, "ck_cg");
+	if (IS_ERR(dpi->dpi_ck_cg)) {
+		ret = PTR_ERR(dpi->dpi_ck_cg);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get dpi ck cg clock: %d\n",
+				ret);
+
+		return ret;
+	}
+
+	dpi->pixel_clk = devm_clk_get_optional(dev, "pixel");
 	if (IS_ERR(dpi->pixel_clk)) {
 		ret = PTR_ERR(dpi->pixel_clk);
 		if (ret != -EPROBE_DEFER)
@@ -1021,7 +1139,7 @@ static int mtk_dpi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	dpi->tvd_clk = devm_clk_get(dev, "pll");
+	dpi->tvd_clk = devm_clk_get_optional(dev, "pll");
 	if (IS_ERR(dpi->tvd_clk)) {
 		ret = PTR_ERR(dpi->tvd_clk);
 		if (ret != -EPROBE_DEFER)
@@ -1030,6 +1148,14 @@ static int mtk_dpi_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	dpi->dpi_sel_clk = devm_clk_get_optional(dev, "dpi_sel");
+	if (IS_ERR(dpi->dpi_sel_clk)) {
+		ret = PTR_ERR(dpi->dpi_sel_clk);
+		dev_err_probe(dev, ret, "Failed to get dpi_Sel_clk clock: %d\n", ret);
+
+		return ret;
+	}
+
 	dpi->irq = platform_get_irq(pdev, 0);
 	if (dpi->irq <= 0)
 		return -EINVAL;
@@ -1085,6 +1211,9 @@ static const struct of_device_id mtk_dpi_of_ids[] = {
 	{ .compatible = "mediatek,mt8195-dp-intf",
 	  .data = &mt8195_dpintf_conf,
 	},
+	{ .compatible = "mediatek,mt8195-dpi",
+	  .data = &mt8195_conf,
+	},
 	{ },
 };
 MODULE_DEVICE_TABLE(of, mtk_dpi_of_ids);
drivers/gpu/drm/mediatek/mtk_dpi_regs.h +5 -0
index 62bd4931b344..653ef4b93a97 100644
@@ -43,6 +43,11 @@
 #define DPINTF_YUV422_EN		BIT(24)
 #define DPINTF_CSC_ENABLE		BIT(26)
 #define DPINTF_INPUT_2P_EN		BIT(29)
+#define DPI_OUTPUT_1T1P_EN		BIT(24)
+#define DPI_INPUT_2P_EN			BIT(25)
+#define DPI_EXT_VSYNC_EN		BIT(26)
+#define DPI_RGB565_EN			BIT(27)
+#define DPI_RGB880_EN			BIT(28)
 
 #define DPI_OUTPUT_SETTING	0x14
 #define CH_SWAP				0
Signature · 1 line
b4 0.11.0-dev
#30 lore raw

Re: [PATCH v3 12/12] drm/mediatek: dpi: Add mt8195 hdmi to DPI driver

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 25 lines

Add the DPI1 hdmi path support in mtk dpi driver

---
  drivers/gpu/drm/mediatek/mtk_dpi.c      | 143 ++++++++++++++++++++++++++++++--
  drivers/gpu/drm/mediatek/mtk_dpi_regs.h |   5 ++
  2 files changed, 141 insertions(+), 7 deletions(-)
drivers/gpu/drm/mediatek/mtk_dpi.c +3 -0
index 508a6d994e83..8052b47042b8 100644
@@ -14,7 +14,10 @@
  #include <linux/of_graph.h>
  #include <linux/pinctrl/consumer.h>
  #include <linux/platform_device.h>
+#include <linux/reset.h>
  #include <linux/types.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
  #include <video/videomode.h>
 
@@ -65,10 +68,14 @@ struct mtk_dpi {
  	struct drm_bridge *next_bridge;

drivers/gpu/drm/mediatek/mtk_dpi.c struct mtk_dpi { · line 78

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dpi.c +4 -0
  	struct drm_connector *connector;
  	void __iomem *regs;
+	struct reset_control *reset_ctl;
  	struct device *dev;
  	struct clk *engine_clk;
+	struct clk *dpi_ck_cg;
  	struct clk *pixel_clk;
+	struct clk *dpi_sel_clk;
  	struct clk *tvd_clk;
+	struct clk *hdmi_cg;

I admit that I didn't really check these clocks, but judging by the names, it is highly possible that one (or more) of them are supposed to be parents of some others.

The first suspicious ones are dpi_ck_cg and dpi_sel_clk: please check.

I'm also not sure about the hdmi_cg, shouldn't the DPI have a HDMI port in the graph that you'd declare in devicetree?

Besides... you're doing a lot of work to check if (is_internal_hdmi) for power up/down paths, but seeing that you're introducing this change after adding the HDMI driver makes me mostly sure that the internal hdmi that we're talking about here is the one that is managed by the HDMIV2 driver... and this means that you should really, really, really rely on connecting inputs and outputs the right way in the devicetree, as that will most probably make you able to write practically 0 code to manage power for the DPI... and may also remove the need of adding the hdmi_cg clock here...

Regards,
Angelo

#31 lore raw

Re: [PATCH v3 12/12] drm/mediatek: dpi: Add mt8195 hdmi to DPI driver

Quoted 55 lines · AngeloGioacchino Del Regno

Il 04/11/22 15:09, Guillaume Ranquet ha scritto:

Quoted 25 lines

Add the DPI1 hdmi path support in mtk dpi driver

---
  drivers/gpu/drm/mediatek/mtk_dpi.c      | 143 ++++++++++++++++++++++++++++++--
  drivers/gpu/drm/mediatek/mtk_dpi_regs.h |   5 ++
  2 files changed, 141 insertions(+), 7 deletions(-)
drivers/gpu/drm/mediatek/mtk_dpi.c +3 -0
index 508a6d994e83..8052b47042b8 100644
@@ -14,7 +14,10 @@
  #include <linux/of_graph.h>
  #include <linux/pinctrl/consumer.h>
  #include <linux/platform_device.h>
+#include <linux/reset.h>
  #include <linux/types.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
  #include <video/videomode.h>
 
@@ -65,10 +68,14 @@ struct mtk_dpi {
  	struct drm_bridge *next_bridge;

drivers/gpu/drm/mediatek/mtk_dpi.c struct mtk_dpi { · line 78

Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_dpi.c +4 -0
  	struct drm_connector *connector;
  	void __iomem *regs;
+	struct reset_control *reset_ctl;
  	struct device *dev;
  	struct clk *engine_clk;
+	struct clk *dpi_ck_cg;
  	struct clk *pixel_clk;
+	struct clk *dpi_sel_clk;
  	struct clk *tvd_clk;
+	struct clk *hdmi_cg;

I admit that I didn't really check these clocks, but judging by the names, it is highly possible that one (or more) of them are supposed to be parents of some others.

The first suspicious ones are dpi_ck_cg and dpi_sel_clk: please check.

I'm also not sure about the hdmi_cg, shouldn't the DPI have a HDMI port in the graph that you'd declare in devicetree?

Besides... you're doing a lot of work to check if (is_internal_hdmi) for power up/down paths, but seeing that you're introducing this change after adding the HDMI driver makes me mostly sure that the internal hdmi that we're talking about here is the one that is managed by the HDMIV2 driver... and this means that you should really, really, really rely on connecting inputs and outputs the right way in the devicetree, as that will most probably make you able to write practically 0 code to manage power for the DPI... and may also remove the need of adding the hdmi_cg clock here...

Quoted 4 lines

Regards,
Angelo

I don't have access to a clock tree documentation or anything that permits me to answer those questions with confidence. I'll ask mediatek for some input and I'll also check how those clocks are declared in the clock framework.

You are right in assuming that the "is_internal_hdmi" is in fact the V2 IP. I like the idea of removing code, I'll try to make sense of your suggestion and see if there's anything I can do better for v4.

Thx,
Guillaume.