Skip to contentSkip to conversation

drm/spacemit: add SpacemiT K3 display support

PATCH Applied Cody Kang 5 participants 28 messages Nov 21 – Nov 24

Subsystems (7)
lore
Share & tools
lore

Cody Kang

author
#0 lore raw

v3 cover drm/spacemit: add SpacemiT K3 display support

This series adds display support for the SpacemiT K3 [2], a RISC-V SoC:
a new DRM driver, a new PHY driver and three new bindings.

The display path is three blocks deep:

Saturn DPU -> Innosilicon DP/eDP controller -> Innosilicon DP PHY

New readers will find an introduction to this hardware in the v2 cover letter [3].

In v3, two major changes, thanks to Thomas Zimmermann for the review that led to these:

- The DPU driver lost its internal layers: the callback tables, the tracepoints and the command-list grouping are gone.
- Page-flip events go through the vblank machinery, and the DPU is powered through runtime PM.

The rest of the v3 changes please see below, with details in each patch's changelog.

v2 ships in the Ubuntu 26.10 RISC-V kernel [4]. Thanks to Sarah Emery for two fixes found there.

Thanks to Ze Huang for testing v2 on the K3 Pico-ITX. The Tested-by is not carried, because the DRM driver changed too much in v3.

Ze, Sarah: if you have time to run v3, a retest would be very welcome.

Sashiko AI review contributed total review comments: 51 items, which I
accepted: 19 items.

v3 repeated the full v1 test matrix on both boards, in built-in and modular configurations, with the module load/unload rounds of v2, plus page-flip and DPMS rounds and unloading the modules while a client is running.

About the series:

The DPU driver arrives as five staged patches (7 to 11) to keep each one a reasonable size. It becomes buildable with patch 11. Bisect safe.

This series supports a single primary plane per CRTC and linear RGB scanout (no plane scaling, rotation, YUV or writeback). It does not support DSI, DSC or DP audio, and link rates are capped at HBR2.

Based on v7.4-rc1.

Testing this series needs a SpacemiT u-boot carrying display support:
the branch at [1], or a later official release.

Tested on two K3 boards:

- Pico-ITX: an eDP panel and an external DisplayPort monitor.
- CoM260-IFX: DisplayPort only, no eDP.

Note: The eDP panel DTS enablement is not part of this series; a separate
series will follow showing how eDP can be verified.

[1] https://github.com/spacemit-com/uboot-for-k3-display-verify/tree/k3-br-v1.0.y
[2] https://www.spacemit.com/community/document/info?lang=en&nodepath=hardware/key_stone/k3
[3] https://lore.kernel.org/r/[email protected]
[4] https://launchpad.net/ubuntu/+source/linux-riscv/7.2.0-5.5.2

Changes in v3:
- drop the tracepoints, the hardware callback tables and the constant-fill path; the Saturn register code is called directly (Thomas Zimmermann)
- one command list per channel, allocated once and submitted by its owner; the grouping, sorting and chaining of lists is gone (Thomas Zimmermann)
- deliver the commit's event through the vblank machinery, armed from the CFG_RDY interrupt (Thomas Zimmermann)
- power the DPU through runtime PM, and stop the boot loader's pipeline at probe instead of at the first modeset (Thomas Zimmermann)
- add prepare_fb: the display MMU table is built once per GEM object
and the buffer's fences are waited for (Thomas Zimmermann)
- program the plane from the clipped rectangles, and size its line buffer in atomic_check (Thomas Zimmermann)
- wrap only the hardware access in drm_dev_enter() (Thomas Zimmermann); release the drm_device when the aggregate unbinds
- map scanout buffers write-combining; fail AUX transfers fast when HPD is low (Sarah Emery)
- reject modes above 3840x2160, and bound framebuffers by what the RDMA registers can address (Icenowy Zheng)
- let the panel supply the modes on eDP (Guodong Xu)
- leave the DPU's pixel clock at the rate it has; on DP and eDP the PHY PLL is the pixel clock (Guodong Xu)
- do not advertise a gamma table (Guodong Xu)
- DT: order the display nodes by unit address; the Pico-ITX message names the Type-C receptacle's DP alternate mode (Icenowy Zheng)
- clk: the commit message names the binding that documents the two
clock inputs (Jerome Brunet)
- MAINTAINERS: add Guodong Xu as maintainer; list Cody Kang with the vsit.ai address
- rebased onto v7.4-rc1: atomic_create_state replaces .reset
- commit messages of patches 5, 7, 8, 9, 11, 12, 14 and 16 reworded
- picked up Rob Herring's Reviewed-by on patch 4
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- unbind: keep the online IRQ alive until the teardown commits have drained; module unload no longer rides two watchdog timeouts
- bridge teardown on devres: reset via devm_reset_control_get_exclusive_deasserted(), pxclk disable as a
devm action ordered against the PHY child (Philipp Zabel, Yao Zi)
- all five DPU reset lines behind one reset_control_bulk_* pair
(Philipp Zabel, Guodong Xu)
- bindings: port@1 is now required; the CoM260 board describes its DP receptacle with a dp-connector node; redundant minItems dropped
(Rob Herring)
- possible_crtcs derived from the input endpoint only
- EDID reads through the AUX I2C adapter; write-1-to-clear interrupt
acks by plain write; assorted dead code dropped
- picked up Rob Herring's Reviewed-by on patches 1-3
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Cody Kang (17):
dt-bindings: display: spacemit: add K3 Saturn DPU controller
dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
phy: spacemit: add Innosilicon DP TX PHY driver
clk: spacemit: k3: parent eDP/DP pixel clock to the PHY PLL drm/spacemit: add Saturn DPU register model
drm/spacemit: add Saturn DPU core types, cmdlist and display MMU drm/spacemit: add Saturn DPU hardware backend
drm/spacemit: add Saturn DPU KMS pipeline
drm/spacemit: add Saturn DPU DRM device driver drm/spacemit: add Innosilicon DP/eDP controller bridge driver
MAINTAINERS: add SpacemiT K3 display driver entry
riscv: dts: spacemit: k3: add display nodes
riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output
riscv: defconfig: spacemit: k3: enable display driver

 .../display/spacemit/spacemit,k3-inno-dp.yaml      |  141 ++
 .../display/spacemit/spacemit,k3-saturn-dpu.yaml   |  132 ++
 .../bindings/phy/spacemit,k3-inno-dp-phy.yaml      |   48 +
 .../bindings/soc/spacemit/spacemit,k1-syscon.yaml  |   21 +-
 MAINTAINERS                                        |   11 +
 arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts     |   27 +
 arch/riscv/boot/dts/spacemit/k3-display.dtsi       |  166 ++
 arch/riscv/boot/dts/spacemit/k3-pico-itx.dts       |   11 +
 arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi       |   22 +
 arch/riscv/configs/defconfig                       |    2 +
 drivers/clk/spacemit/ccu-k3.c                      |    4 +-
 drivers/gpu/drm/Kconfig                            |    1 +
 drivers/gpu/drm/Makefile                           |    1 +
 drivers/gpu/drm/spacemit/Kconfig                   |   37 +
 drivers/gpu/drm/spacemit/Makefile                  |   15 +
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.c          |  353 ++++
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.h          |   36 +
 drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c      |  670 ++++++
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c       |   66 +
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h       |   16 +
 drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h |   25 +
 drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h |   47 +
 .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h |   65 +
 .../drm/spacemit/dpu/saturn_regs/saturn_fields.h   |  312 +++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.c        |  198 ++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.h        |  133 ++
 drivers/gpu/drm/spacemit/spacemit_crtc.c           |  589 ++++++
 drivers/gpu/drm/spacemit/spacemit_crtc.h           |  133 ++
 drivers/gpu/drm/spacemit/spacemit_dmmu.c           |  119 ++
 drivers/gpu/drm/spacemit/spacemit_dmmu.h           |   80 +
 drivers/gpu/drm/spacemit/spacemit_dpu_ids.h        |   26 +
 drivers/gpu/drm/spacemit/spacemit_dpu_reg.h        |   99 +
 drivers/gpu/drm/spacemit/spacemit_drm.c            |  204 ++
 drivers/gpu/drm/spacemit/spacemit_drm.h            |   62 +
 drivers/gpu/drm/spacemit/spacemit_inno_dp.c        | 2186 ++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_inno_dp.h        |  328 +++
 drivers/gpu/drm/spacemit/spacemit_planes.c         |  332 +++
 drivers/phy/spacemit/Kconfig                       |   13 +
 drivers/phy/spacemit/Makefile                      |    1 +
 drivers/phy/spacemit/phy-k3-inno-dp.c              |  951 +++++++++
 40 files changed, 7680 insertions(+), 3 deletions(-)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260713-k3-display-e8ffed67e936

Best regards,

Signature · 1 line
Cody Kang <[email protected]>
author
#1 lore raw

PATCH v3 1/17 dt-bindings: display: spacemit: add K3 Saturn DPU controller

From: Cody Kang <[email protected]>

Document the Saturn display processing unit found on the SpacemiT K3 SoC. The K3 instantiates two of them, one per display path. They share a
compatible: an instance differs only in which register window, interrupt, clock and reset lines it takes.

---
v3:
- no change
v2:
- add Reviewed-by: Rob Herring (Arm)

---
 .../display/spacemit/spacemit,k3-saturn-dpu.yaml   | 132 +++++++++++++++++++++
 1 file changed, 132 insertions(+)
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +132 -0
new file mode 100644
index 0000000000000..97ea9da4b68e4
@@ -0,0 +1,132 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-saturn-dpu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 Saturn Display Processing Unit
+
+maintainers:
+  - Cody Kang <[email protected]>
+
+description:
+  The Saturn DPU is the display processing unit of the SpacemiT K3 SoC. It
+  composes the display planes and drives the timing for one display path. Its
+  output goes to a DisplayPort or embedded DisplayPort controller. The K3 has
+  two instances.
+
+properties:
+  compatible:
+    const: spacemit,k3-saturn-dpu
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Online (live display) compose path.
+      - description: Offline (writeback) compose path.
+
+  interrupt-names:
+    items:
+      - const: online
+      - const: offline
+
+  clocks:
+    items:
+      - description: Pixel clock.
+      - description: Memory clock for the compose pipeline.
+      - description: AXI bus clock.
+      - description: DSI escape clock.
+      - description: DSC clock.
+
+  clock-names:
+    items:
+      - const: pxclk
+      - const: mclk
+      - const: aclk
+      - const: escclk
+      - const: dscclk
+
+  resets:
+    items:
+      - description: Memory clock domain.
+      - description: LCD domain, shared with the downstream controller.
+      - description: DSI escape clock domain.
+      - description: AXI clock domain.
+      - description: DSC domain.
+
+  reset-names:
+    items:
+      - const: mclk
+      - const: lcd
+      - const: esc
+      - const: aclk
+      - const: dsc
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Video output to the DisplayPort or eDP controller.
+
+    required:
+      - port@0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/spacemit,k3-clocks.h>
+    #include <dt-bindings/reset/spacemit,k3-resets.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        dpu@c0340000 {
+            compatible = "spacemit,k3-saturn-dpu";
+            reg = <0x0 0xc0340000 0x0 0x54000>;
+            interrupts = <90 IRQ_TYPE_LEVEL_HIGH>,
+                         <89 IRQ_TYPE_LEVEL_HIGH>;
+            interrupt-names = "online", "offline";
+            clocks = <&syscon_apmu CLK_APMU_LCD_PXCLK>,
+                     <&syscon_apmu CLK_APMU_LCD_MCLK>,
+                     <&syscon_apmu CLK_APMU_DPU_ACLK>,
+                     <&syscon_apmu CLK_APMU_DSI_ESC>,
+                     <&syscon_apmu CLK_APMU_LCD_DSC>;
+            clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk";
+            resets = <&syscon_apmu RESET_APMU_LCD_MCLK>,
+                     <&syscon_apmu RESET_APMU_LCD>,
+                     <&syscon_apmu RESET_APMU_DSI_ESC>,
+                     <&syscon_apmu RESET_APMU_DPU_ACLK>,
+                     <&syscon_apmu RESET_APMU_LCD_DSCCLK>;
+            reset-names = "mclk", "lcd", "esc", "aclk", "dsc";
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                    reg = <0>;
+                    endpoint {
+                        remote-endpoint = <&edp0_in>;
+                    };
+                };
+            };
+        };
+    };
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v3 01/17] dt-bindings: display: spacemit: add K3 Saturn DPU controller

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dt-bindings: display: spacemit: interrupts ordered before clocks in K3 DPU --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dt-bindings: display: spacemit: interrupts ordered before clocks in K3 DPU
--

commit 5cacd6c3de4c42a0a1e84fc0f0f6938c6990b78e
Author: Cody Kang <[email protected]>

dt-bindings: display: spacemit: add K3 Saturn DPU controller

This commit adds the Device Tree binding schema for the Saturn display processing unit found on the SpacemiT K3 SoC.

Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +0 -0
new file mode 100644
index 0000000000000..97ea9da4b68e4
@@ -0,0 +1,132 @@

[ ... ]

Quoted 32 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +32 -0
+properties:
+  compatible:
+    const: spacemit,k3-saturn-dpu
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: Online (live display) compose path.
+      - description: Offline (writeback) compose path.
+
+  interrupt-names:
+    items:
+      - const: online
+      - const: offline
+
+  clocks:
+    items:
+      - description: Pixel clock.
+      - description: Memory clock for the compose pipeline.
+      - description: AXI bus clock.
+      - description: DSI escape clock.
+      - description: DSC clock.
+
+  clock-names:
+    items:
+      - const: pxclk
+      - const: mclk
+      - const: aclk
+      - const: escclk
+      - const: dscclk

[ ... ]

Quoted 10 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +10 -0
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - ports

[ ... ]

Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml line 112

Quoted 12 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +12 -0
+        dpu@c0340000 {
+            compatible = "spacemit,k3-saturn-dpu";
+            reg = <0x0 0xc0340000 0x0 0x54000>;
+            interrupts = <90 IRQ_TYPE_LEVEL_HIGH>,
+                         <89 IRQ_TYPE_LEVEL_HIGH>;
+            interrupt-names = "online", "offline";
+            clocks = <&syscon_apmu CLK_APMU_LCD_PXCLK>,
+                     <&syscon_apmu CLK_APMU_LCD_MCLK>,
+                     <&syscon_apmu CLK_APMU_DPU_ACLK>,
+                     <&syscon_apmu CLK_APMU_DSI_ESC>,
+                     <&syscon_apmu CLK_APMU_LCD_DSC>;
+            clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk";

[Severity: Low]
This isn't a bug, but in Device Tree binding schemas, clocks and clock-names should be listed before interrupts and interrupt-names in the properties, required, and examples sections to follow the canonical property order (compatible, reg, clocks, clock-names, interrupts, interrupt-names).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#3 lore raw

PATCH v3 2/17 dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY

In reply to Cody Kang

From: Cody Kang <[email protected]>

The SpacemiT K3 DisplayPort controller drives its four transmit lanes through an integrated Innosilicon DP PHY, one PHY per controller. Add a binding so the controller can reference its transmit PHY and the pixel clock the PHY's PLL sources.

The PHY's registers are interleaved with its parent controller's inside one MMIO window, so it owns neither a reg nor a reset and is modelled as a child of the controller.

It exposes its PLL-generated pixel clock through #clock-cells, so the APMU pixel-clock mux can select it as a parent through the clock framework.

---
v3:
- no change
v2:
- add Reviewed-by: Rob Herring (Arm)

---
 .../bindings/phy/spacemit,k3-inno-dp-phy.yaml      | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)
Documentation/devicetree/bindings/phy/spacemit,k3-inno-dp-phy.yaml new file +48 -0
new file mode 100644
index 0000000000000..f8f1ef3729511
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/spacemit,k3-inno-dp-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 Innosilicon DisplayPort PHY
+
+maintainers:
+  - Cody Kang <[email protected]>
+
+description:
+  Innosilicon four-lane DisplayPort transmit PHY integrated in the SpacemiT
+  K3 SoC, one per DisplayPort controller. Its registers are interleaved with
+  the controller's own inside a single register window, so it is described as
+  a child of the controller and owns neither a reg nor a reset.
+
+  The PHY provides the pixel clock its PLL generates, which the APMU
+  pixel-clock mux takes as one of its inputs.
+
+properties:
+  compatible:
+    const: spacemit,k3-inno-dp-phy
+
+  "#phy-cells":
+    const: 0
+
+  "#clock-cells":
+    const: 0
+
+  clock-output-names:
+    maxItems: 1
+
+required:
+  - compatible
+  - "#phy-cells"
+  - "#clock-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    phy {
+        compatible = "spacemit,k3-inno-dp-phy";
+        #phy-cells = <0>;
+        #clock-cells = <0>;
+        clock-output-names = "edp0_pll_pxclk";
+    };
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v3 3/17 dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller

In reply to Cody Kang

From: Cody Kang <[email protected]>

Both K3 instances are the same IP and share one compatible; which one behaves as eDP is decided by what its downstream port is wired to, not by which register window it sits in, so the binding does not distinguish them.

---
v3:
- no change
v2:
- make port@1 required (Rob Herring)
- add Reviewed-by: Rob Herring (Arm)

---
 .../display/spacemit/spacemit,k3-inno-dp.yaml      | 141 +++++++++++++++++++++
 1 file changed, 141 insertions(+)
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +141 -0
new file mode 100644
index 0000000000000..491d25730da9f
@@ -0,0 +1,141 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/spacemit/spacemit,k3-inno-dp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 Innosilicon DisplayPort / embedded DisplayPort Controller
+
+maintainers:
+  - Cody Kang <[email protected]>
+
+description:
+  Innosilicon DisplayPort transmit controller integrated in the SpacemiT K3
+  SoC. The K3 has two instances of the same block sharing one compatible;
+  each acts as embedded or external DisplayPort depending on whether its
+  output port drives a panel or a connector.
+
+properties:
+  compatible:
+    const: spacemit,k3-inno-dp
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+    description: Link and hot-plug events.
+
+  clocks:
+    items:
+      - description: Pixel clock for the controller.
+      - description:
+          Pixel clock generated by the DP PHY PLL; the pixel clock above is
+          parented onto it in use.
+
+  clock-names:
+    items:
+      - const: pxclk
+      - const: pll
+
+  resets:
+    maxItems: 1
+    description: Controller-wide reset signal.
+
+  phys:
+    maxItems: 1
+    description: Phandle to the K3 Innosilicon DP PHY.
+
+  phy-names:
+    items:
+      - const: dp
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Video input from the DPU.
+
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port
+        description: Output to the panel or to the DisplayPort connector.
+
+    required:
+      - port@0
+      - port@1
+
+  aux-bus:
+    $ref: /schemas/display/dp-aux-bus.yaml#
+    description:
+      The DisplayPort AUX bus. Present when the output drives an embedded
+      panel, which is described as a child of this node and identifies itself
+      over AUX. Absent when the output is a connector.
+
+  phy:
+    $ref: /schemas/phy/spacemit,k3-inno-dp-phy.yaml#
+    description:
+      The DisplayPort PHY. Its registers live inside this controller's
+      register window, so it is described here as a child node.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - phys
+  - phy-names
+  - ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/spacemit,k3-clocks.h>
+    #include <dt-bindings/reset/spacemit,k3-resets.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        edp@cac84000 {
+            compatible = "spacemit,k3-inno-dp";
+            reg = <0x0 0xcac84000 0x0 0x4000>;
+            interrupts = <132 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon_apmu CLK_APMU_EDP0_PXCLK>, <&edp0_phy>;
+            clock-names = "pxclk", "pll";
+            resets = <&syscon_apmu RESET_APMU_EDP0>;
+            phys = <&edp0_phy>;
+            phy-names = "dp";
+
+            edp0_phy: phy {
+                compatible = "spacemit,k3-inno-dp-phy";
+                #phy-cells = <0>;
+                #clock-cells = <0>;
+                clock-output-names = "edp0_pll_pxclk";
+            };
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                    reg = <0>;
+                    endpoint {
+                        remote-endpoint = <&dpu0_out>;
+                    };
+                };
+
+                port@1 {
+                    reg = <1>;
+                    endpoint {
+                        remote-endpoint = <&panel_in>;
+                    };
+                };
+            };
+        };
+    };
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v3 03/17] dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] dt-bindings: display: spacemit: interrupts listed before clocks in k3-inno-dp --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] dt-bindings: display: spacemit: interrupts listed before clocks in k3-inno-dp
--

commit ec123ddd0dcb86d2168d07ef0954ffae1dd9d9aa
Author: Cody Kang <[email protected]>

dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller

This commit adds the Device Tree binding schema for the SpacemiT K3 Innosilicon DisplayPort and embedded DisplayPort controller.

Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +0 -0
new file mode 100644
index 0000000000000..491d25730da9f
@@ -0,0 +1,141 @@

[ ... ]

Quoted 22 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +22 -0
+properties:
+  compatible:
+    const: spacemit,k3-inno-dp
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+    description: Link and hot-plug events.
+
+  clocks:
+    items:
+      - description: Pixel clock for the controller.
+      - description:
+          Pixel clock generated by the DP PHY PLL; the pixel clock above is
+          parented onto it in use.
+
+  clock-names:
+    items:
+      - const: pxclk
+      - const: pll

[ ... ]

Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +6 -0
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names

[ ... ]

Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml line 110

Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +6 -0
+        edp@cac84000 {
+            compatible = "spacemit,k3-inno-dp";
+            reg = <0x0 0xcac84000 0x0 0x4000>;
+            interrupts = <132 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&syscon_apmu CLK_APMU_EDP0_PXCLK>, <&edp0_phy>;
+            clock-names = "pxclk", "pll";

[Severity: Low]
This isn't a bug, but DT binding schemas and example nodes follow the canonical property ordering where clocks and clock-names appear before interrupts. Could interrupts be moved after clock-names in properties, required, and the edp@cac84000 example node?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author
#6 lore raw

PATCH v3 4/17 dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU

In reply to Cody Kang

From: Cody Kang <[email protected]>

The APMU's eDP pixel-clock muxes select the DP PHY PLLs as parents, so the K3 syscon takes two clock inputs the other variants do not have.

Gate them behind the K3 compatible instead of widening the shared clock list, so a non-K3 syscon cannot silently accept clocks it has no mux for.

---
v3:
- add Reviewed-by: Rob Herring (Arm)
v2:
- drop the redundant minItems: 4; four is already the minimum (Rob Herring)

---
 .../bindings/soc/spacemit/spacemit,k1-syscon.yaml   | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml +20 -1
index d3a7c93c3c54f..a6ef456fe14be 100644
@@ -31,14 +31,18 @@ properties:
     maxItems: 1
 
   clocks:
-    maxItems: 4
+    minItems: 4
+    maxItems: 6
 
   clock-names:
+    minItems: 4
     items:
       - const: osc
       - const: vctcxo_1m
       - const: vctcxo_3m
       - const: vctcxo_24m
+      - const: edp0_pll_pxclk
+      - const: edp1_pll_pxclk
 
   "#clock-cells":
     const: 1
@@ -95,6 +99,21 @@ allOf:
         - clocks
         - clock-names
         - "#clock-cells"
+  # Only the K3 APMU exposes the two eDP/DP PHY PLL pixel clocks as extra
+  # inputs (parents of its eDP pixel-clock muxes); every other variant has
+  # the four base oscillator inputs only.
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              const: spacemit,k3-syscon-apmu
+    then:
+      properties:
+        clocks:
+          maxItems: 4
+        clock-names:
+          maxItems: 4
 
 additionalProperties: false
 
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v3 5/17 phy: spacemit: add Innosilicon DP TX PHY driver

In reply to Cody Kang

From: Cody Kang <[email protected]>

The PHY's registers are interleaved into its parent DP controller's MMIO window rather than a window of its own, so it probes as a child of the controller, carries no reg or reset, and reaches its registers through the controller's regmap.

It registers its pixel PLL as a clock provider. That lets the display controller ask for a mode's pixel rate through clk_set_rate(), and it lets the APMU pixel-clock mux parent to the PHY through the clock framework. Without it the controller would have to program the PHY's pixel PLL itself.

---
v3:
- park the pixel PLL when the lane enable write fails
- share one pixel PLL lookup between determine_rate and set_rate
- describe the lane trim fields with GENMASK() and FIELD_PREP()
- drop redundant checks and initialisers
- commit message: reword why the PHY is a clock provider v2:
- drop the mod_devicetable.h include (Uwe Kleine-Koenig)
- unwind the lanes and pixel PLL on the power_on lock-timeout paths (Sashiko)
- document why power_off keeps the MPLL up: it feeds the 16 MHz AUX reference, and AUX must survive link drops (Sashiko)
- register the PHY and clock providers last in probe (Sashiko)

---
 drivers/phy/spacemit/Kconfig          |  13 +
 drivers/phy/spacemit/Makefile         |   1 +
 drivers/phy/spacemit/phy-k3-inno-dp.c | 951 ++++++++++++++++++++++++++++++++++
 3 files changed, 965 insertions(+)
drivers/phy/spacemit/Kconfig +13 -0
index b5f36621b2075..6b6071c965d9e 100644
@@ -42,3 +42,16 @@ config PHY_SPACEMIT_K3_COMBO_PHY
 	  driver takes care of enabling and clock setup and will be used
 	  by K3 dwc3 driver.
 	  If unsure, say N.
+
+config PHY_SPACEMIT_K3_INNO_DP
+	tristate "SpacemiT K3 Innosilicon DisplayPort PHY driver"
+	depends on (ARCH_SPACEMIT || COMPILE_TEST) && OF
+	depends on COMMON_CLK
+	select GENERIC_PHY
+	select REGMAP
+	help
+	  Enable support for the Innosilicon DisplayPort transmit PHY
+	  integrated in the SpacemiT K3 SoC. The PHY shares its MMIO window
+	  with its parent DP/eDP controller (drivers/gpu/drm/spacemit/) and
+	  exposes lane / rate / vswing / pre-emphasis control through the
+	  generic PHY framework.
drivers/phy/spacemit/Makefile +1 -0
index f679c1851b4f0..cdd88d9cc18bc 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_PHY_SPACEMIT_K1_PCIE)		+= phy-k1-pcie.o
 obj-$(CONFIG_PHY_SPACEMIT_K1_USB2)		+= phy-k1-usb2.o
 obj-$(CONFIG_PHY_SPACEMIT_K3_COMBO_PHY)		+= phy-k3-combo.o
 obj-$(CONFIG_PHY_SPACEMIT_K3_COMMON_OPS)	+= phy-k3-common.o
+obj-$(CONFIG_PHY_SPACEMIT_K3_INNO_DP)		+= phy-k3-inno-dp.o
drivers/phy/spacemit/phy-k3-inno-dp.c new file +951 -0

951 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#8 lore raw

PATCH v3 6/17 clk: spacemit: k3: parent eDP/DP pixel clock to the PHY PLL

In reply to Cody Kang

From: Cody Kang <[email protected]>

The APMU eDP/DP pixel-clock muxes took their second parent from an input named external_clk, which no binding documents and no device tree supplies. Their real parents are the DP PHY PLLs, which now exist as clocks, and the K3 APMU binding lists them as the inputs edp0_pll_pxclk and edp1_pll_pxclk. Point each mux at its PLL input and let the pixel clock reach the controller through the clock framework.

---
v3:
- commit message: name the binding that documents the two clock inputs (Jerome Brunet)
v2:
- no change

---
 drivers/clk/spacemit/ccu-k3.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/spacemit/ccu-k3.c +2 -2
index 39df15c8a3e6d..8782e55926d99 100644
@@ -1038,13 +1038,13 @@ CCU_FACTOR_DEFINE(ufs_refclk, CCU_PARENT_HW(pll1_d64_38p4), 2, 1);
 
 static const struct clk_parent_data edp0_pclk_parents[] = {
 	CCU_PARENT_HW(lcd_pxclk),
-	CCU_PARENT_NAME(external_clk),
+	CCU_PARENT_NAME(edp0_pll_pxclk),
 };
 CCU_MUX_GATE_DEFINE(edp0_pxclk, edp0_pclk_parents, APMU_LCD_EDP_CTRL, 2, 1, BIT(1), 0);
 
 static const struct clk_parent_data edp1_pclk_parents[] = {
 	CCU_PARENT_HW(dsi4ln2_lcd_pxclk),
-	CCU_PARENT_NAME(external_clk),
+	CCU_PARENT_NAME(edp1_pll_pxclk),
 };
 CCU_MUX_GATE_DEFINE(edp1_pxclk, edp1_pclk_parents, APMU_LCD_EDP_CTRL, 18, 1, BIT(17), 0);
 
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH v3 7/17 drm/spacemit: add Saturn DPU register model

In reply to Cody Kang

From: Cody Kang <[email protected]>

The Saturn display processing unit is programmed through a set of register blocks (composer, RDMA, timing generator, cmdlist engine, display MMU) laid out identically in both DPU instances of the K3. Add the block address map, the per-field word offset and mask tables consumed by the field accessors, the interrupt bit layout and the compositor and output-format ID encodings. The address map describes the whole IP block on purpose, including blocks the driver does not touch; the field tables carry the fields the driver programs, with each block's full word count kept as its NWORDS extent.

---
v3:
- write single-bit register fields as BIT()
- name the include guards after their files
- commit message: reworded
v2:
- no change

---
 drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h |  25 ++
 .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h |  65 +++++
 .../drm/spacemit/dpu/saturn_regs/saturn_fields.h   | 312 +++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_dpu_ids.h        |  26 ++
 4 files changed, 428 insertions(+)
drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h new file +25 -0
new file mode 100644
index 0000000000000..24a22538f47b1
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2025-2026 SpacemiT Co., Ltd.
+ *
+ */
+
+#ifndef DPU_INT_H
+#define DPU_INT_H
+
+#include <linux/bits.h>
+
+#define DPU_INT_CMDLIST_CH_FRM_CFG_DONE_MASK	(0xff)
+#define DPU_INT_CMDLIST_CH_FRM_CFG_DONE		(DPU_INT_CMDLIST_CH_FRM_CFG_DONE_MASK << 11)
+#define DPU_INT_FRM_TIMING_UNFLOW		BIT(8)
+#define DPU_INT_CFG_RDY_CLR			BIT(5)
+#define DPU_INT_FRM_TIMING_CFG_LINE		BIT(4)
+#define DPU_INT_FRM_TIMING_CFG_EOF		(BIT(2) | BIT(3))
+#define DPU_INT_FRM_TIMING_EOF			BIT(1)
+#define DPU_INT_FRM_TIMING_VSYNC		BIT(0)
+#define DPU_REST_INT_BITS			(DPU_INT_FRM_TIMING_CFG_EOF | \
+						 DPU_INT_FRM_TIMING_CFG_LINE | \
+						 DPU_INT_FRM_TIMING_EOF | \
+						 DPU_INT_CMDLIST_CH_FRM_CFG_DONE)
+
+#endif /* DPU_INT_H */
drivers/gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h new file +65 -0

65 lines not on this page · raw message

drivers/gpu/drm/spacemit/dpu/saturn_regs/saturn_fields.h new file +312 -0

312 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_dpu_ids.h new file +26 -0
new file mode 100644
index 0000000000000..d5ec7d51ca3a4
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2025-2026 SpacemiT Co., Ltd.
+ */
+
+#ifndef _SPACEMIT_DPU_IDS_H_
+#define _SPACEMIT_DPU_IDS_H_
+
+/*
+ * Saturn online compositor ids. Both K3 DPU instances are wired as COMPOSER1,
+ * which selects the composer registers, the scene control block and the
+ * composer's command-list enable and CFG_RDY bits.
+ */
+#define COMPOSER0	0
+#define COMPOSER1	1
+#define COMPOSER2	2
+#define COMPOSER3	3
+
+/* Output-format encoding of the timing generator's user field. */
+#define OUTFMT_RGB121212	0
+#define OUTFMT_RGB101010	1
+#define OUTFMT_RGB888		2
+#define OUTFMT_RGB666		12
+#define OUTFMT_RGB565		13
+
+#endif /* _SPACEMIT_DPU_IDS_H_ */
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH v3 8/17 drm/spacemit: add Saturn DPU core types, cmdlist and display MMU

In reply to Cody Kang

From: Cody Kang <[email protected]>

Register programming of the Saturn DPU is batched: the driver builds per-module register lists in memory and the hardware command-list engine replays them once the driver raises config-ready (CFG_RDY), while scanout buffers are mapped through the DPU's private address translation unit (DMMU) rather than scanned out by physical address.

Add the shared driver types, the MMIO field accessors, the command-list builder and the DMMU table code. Some DPU configuration registers are write-only, so a read-modify-write would corrupt neighbouring fields; byte- and halfword-aligned fields are therefore written at their native width instead.

---
v3:
- drop the tracepoints and dpu_trace.h (Thomas Zimmermann)
- drop the hardware callback table; the Saturn register code is called directly (Thomas Zimmermann)
- one command list per channel, allocated once; the grouping, sorting and chaining of lists is gone (Thomas Zimmermann)
- build the display MMU table once per GEM object (Thomas Zimmermann)
- use drm_WARN_ON_ONCE() in the DMMU table fill (Thomas Zimmermann)
- keep the clock handles and the power state in the device data
- commit message: the engine replays the lists on config-ready, not at frame boundaries
v2:
- hold the DPU reset lines as one reset_control_bulk_data pipe_resets[5] array in spacemit_drm_private and drop the pointers duplicated into struct spacemit_crtc (Philipp Zabel)
- drop the INT_VSYNC_UPDATE enum member; it never had an irq_list[] mapping and the register model has no such status bit (Sashiko)
- drop the unreachable multi-planar arms in spacemit_dmmu_map(); every advertised format is single-planar (Sashiko)
- drop the unused cmdlist parameter from the crtc_cmdlist op (Sashiko)

---
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.h   |  36 +++++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 198 ++++++++++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 133 +++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_crtc.h    | 133 +++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_dmmu.c    | 119 +++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_dmmu.h    |  80 +++++++++++
 drivers/gpu/drm/spacemit/spacemit_dpu_reg.h |  99 ++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_drm.h     |  62 +++++++++
 8 files changed, 860 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.h new file +36 -0
new file mode 100644
index 0000000000000..9f3c58166273c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2025-2026 SpacemiT Co., Ltd.
+ *
+ */
+
+#ifndef _DPU_SATURN_H_
+#define _DPU_SATURN_H_
+
+#include "../spacemit_crtc.h"
+
+struct dpu_format_id {
+	u32 format;		/* DRM fourcc */
+	u8 id;
+	u8 bpp;			/* bits per pixel */
+};
+
+#define SPACEMIT_DPU_INVALID_FORMAT_ID	0xff
+
+int spacemit_dpu_parse_clocks(struct device *dev, struct dpu_clk_context *clk_ctx);
+int spacemit_dpu_enable_clocks(struct spacemit_drm_private *priv);
+void spacemit_dpu_disable_clocks(struct spacemit_drm_private *priv);
+void spacemit_dpu_init(struct spacemit_crtc *a_crtc,
+		       const struct drm_display_mode *mode);
+void spacemit_dpu_uninit(struct spacemit_crtc *a_crtc);
+void spacemit_dpu_run(struct drm_crtc *crtc, struct drm_atomic_commit *state);
+bool spacemit_dpu_online_isr(struct spacemit_crtc *a_crtc);
+u8 spacemit_plane_hw_get_format_id(u32 format);
+u32 saturn_conf_dpuctrl_rdma(struct drm_atomic_commit *state,
+			     const struct drm_crtc_state *crtc_state);
+extern const struct spacemit_hw_device spacemit_k3_saturn_dpu;
+void saturn_enable_irq_mask(struct spacemit_crtc *a_crtc, bool enable,
+			    u32 offset, u32 mask);
+void spacemit_cfg_rdy_timer_handler(struct timer_list *t);
+void spacemit_dpu_complete_event(struct spacemit_crtc *a_crtc);
+#endif
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +198 -0

198 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_cmdlist.h new file +133 -0

133 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_crtc.h new file +133 -0

133 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +119 -0

119 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_dmmu.h new file +80 -0

80 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_dpu_reg.h new file +99 -0

99 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_drm.h new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#11 lore raw

PATCH v3 9/17 drm/spacemit: add Saturn DPU hardware backend

In reply to Cody Kang

From: Cody Kang <[email protected]>

Add the register-level programming of one Saturn instance: clock and reset bring-up, scene control and timing generator setup, RDMA channel and composer layer programming, RDMA line-buffer sizing, interrupt dispatch and the CFG_RDY/vsync handshake that paces commits. The KMS layer calls the backend directly.

---
v3:
- drop the tracepoints (Thomas Zimmermann)
- drop the ops table and inline the forwarding helpers (Thomas Zimmermann)
- drop the constant-fill path; the plane always uses RDMA channel 0 (Thomas Zimmermann)
- size the RDMA line buffer per plane instead of arbitrating between channels (Thomas Zimmermann)
- submit only the compose list from the CRTC flush; the planes' lists are no longer sorted and submitted there (Thomas Zimmermann)
- arm the commit's event from the CFG_RDY interrupt and deliver it through the vblank machinery (Thomas Zimmermann)
- leave the DPU's pixel clock at the rate it has; on DP and eDP the PHY PLL is the pixel clock (Guodong Xu)
- return IRQ_NONE when no status bit was pending, disable the clocks in reverse enable order, drop a stray dma_rmb() and definitions nothing reads
- commit message: drop the reference to an upcoming patch v2:
- drop the dead INT_VSYNC_UPDATE clear; the enum member goes away in patch 08 (Sashiko)
- drop the cmdlist parameter from saturn_hee_crtc_cmdlist(), matching the crtc_cmdlist op change in patch 08

---
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.c          | 353 +++++++++++
 drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c      | 670 +++++++++++++++++++++
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c       |  66 ++
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h       |  16 +
 drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h |  47 ++
 5 files changed, 1152 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +353 -0
new file mode 100644
index 0000000000000..704e64fb9ec7e
@@ -0,0 +1,353 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 SpacemiT Co., Ltd.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/iopoll.h>
+#include <linux/regmap.h>
+#include <linux/timer.h>
+#include <linux/types.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_print.h>
+#include <drm/drm_vblank.h>
+
+#include "../spacemit_cmdlist.h"
+#include "../spacemit_dmmu.h"
+#include "../spacemit_dpu_ids.h"
+#include "../spacemit_dpu_reg.h"
+#include "../spacemit_drm.h"
+#include "dpu_saturn.h"
+#include "saturn_regs/ops_hee.h"
+
+static const struct dpu_format_id primary_fmts[] = {
+	{ DRM_FORMAT_XRGB8888, 8, 32 },
+	{ DRM_FORMAT_ARGB8888, 4, 32 },
+	{ DRM_FORMAT_XBGR8888, 9, 32 },
+	{ DRM_FORMAT_ABGR8888, 5, 32 },
+	{ DRM_FORMAT_RGBX8888, 10, 32 },
+	{ DRM_FORMAT_RGBA8888, 6, 32 },
+	{ DRM_FORMAT_BGRX8888, 11, 32 },
+	{ DRM_FORMAT_BGRA8888, 7, 32 },
+	{ DRM_FORMAT_ABGR2101010, 1, 32 },
+	{ DRM_FORMAT_RGB888, 12, 24 },
+	{ DRM_FORMAT_BGR888, 13, 24 },
+	{ DRM_FORMAT_RGB565, 22, 16 },
+	{ DRM_FORMAT_BGR565, 23, 16 },
+};
+
+/* Read channels per instance. */
+#define SATURN_HEE_RDMA_NUM	4
+
+/* A commit whose CFG_RDY is not taken within this time is reported. */
+#define SATURN_CFG_RDY_TIMEOUT_MS	3000
+
+/* Wait for the previous CFG_RDY to be consumed before the block is set up. */
+#define SATURN_CFG_IDLE_POLL_US		100
+#define SATURN_CFG_IDLE_TIMEOUT_US	(200 * USEC_PER_MSEC)
+
+static const u32 saturn_hee_fbcmem_sizes[] = {
+	89600, /* 87.5 KiB */
+	15360, /* 15 KiB */
+};
+
+const struct spacemit_hw_device spacemit_k3_saturn_dpu = {
+	.rdma_nums = SATURN_HEE_RDMA_NUM,
+	.n_formats = ARRAY_SIZE(primary_fmts),
+	.formats = primary_fmts,
+	.n_fbcmems = ARRAY_SIZE(saturn_hee_fbcmem_sizes),
+	.fbcmem_sizes = saturn_hee_fbcmem_sizes,
+};
+
+void saturn_enable_irq_mask(struct spacemit_crtc *a_crtc, bool enable,
+			    u32 offset, u32 mask)
+{
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+
+	if (!priv->clocks_on)
+		return;
+
+	regmap_update_bits(hwdev->regmap, offset, mask, enable ? mask : 0);
+}
+
+int spacemit_dpu_parse_clocks(struct device *dev, struct dpu_clk_context *clk_ctx)
+{
+	clk_ctx->pxclk = devm_clk_get(dev, "pxclk");
+	if (IS_ERR(clk_ctx->pxclk))
+		return dev_err_probe(dev, PTR_ERR(clk_ctx->pxclk),
+				     "failed to get pxclk\n");
+
+	clk_ctx->mclk = devm_clk_get(dev, "mclk");
+	if (IS_ERR(clk_ctx->mclk))
+		return dev_err_probe(dev, PTR_ERR(clk_ctx->mclk),
+				     "failed to get mclk\n");
+
+	clk_ctx->escclk = devm_clk_get(dev, "escclk");
+	if (IS_ERR(clk_ctx->escclk))
+		return dev_err_probe(dev, PTR_ERR(clk_ctx->escclk),
+				     "failed to get escclk\n");
+
+	clk_ctx->aclk = devm_clk_get(dev, "aclk");
+	if (IS_ERR(clk_ctx->aclk))
+		return dev_err_probe(dev, PTR_ERR(clk_ctx->aclk),
+				     "failed to get aclk\n");
+
+	clk_ctx->dscclk = devm_clk_get(dev, "dscclk");
+	if (IS_ERR(clk_ctx->dscclk))
+		return dev_err_probe(dev, PTR_ERR(clk_ctx->dscclk),
+				     "failed to get dscclk\n");
+
+	return 0;
+}
+
+/*
+ * Bring @clk to the rate nearest @rate. A clock that refuses is reported and
+ * left as it is: the rates are targets, not requirements.
+ */
+static void spacemit_dpu_clk_set_rate(struct device *dev, struct clk *clk,
+				      unsigned long rate, const char *name)
+{
+	long rounded = clk_round_rate(clk, rate);
+	int ret;
+
+	if (rounded < 0) {
+		dev_warn_ratelimited(dev, "%s: no rate near %lu Hz: %ld\n",
+				     name, rate, rounded);
+		return;
+	}
+
+	ret = clk_set_rate(clk, rounded);
+	if (ret)
+		dev_warn_ratelimited(dev, "%s: failed to set %ld Hz: %d\n",
+				     name, rounded, ret);
+}
+
+int spacemit_dpu_enable_clocks(struct spacemit_drm_private *priv)
+{
+	struct dpu_clk_context *clk_ctx = &priv->clk_ctx;
+	int ret;
+
+	/*
+	 * Rate left alone: the mode's pixel clock is the DP PHY's PLL. This
+	 * input only has to run for the "lcd" reset to reach the DPU.
+	 */
+	ret = clk_prepare_enable(clk_ctx->pxclk);
+	if (ret)
+		goto err;
+
+	ret = clk_prepare_enable(clk_ctx->mclk);
+	if (ret)
+		goto err_pxclk;
+	spacemit_dpu_clk_set_rate(priv->dev, clk_ctx->mclk, DPU_MCLK_DEFAULT,
+				  "mclk");
+
+	/* The escape clock only has to run for the "esc" reset to propagate. */
+	ret = clk_prepare_enable(clk_ctx->escclk);
+	if (ret)
+		goto err_mclk;
+
+	ret = clk_prepare_enable(clk_ctx->aclk);
+	if (ret)
+		goto err_escclk;
+	spacemit_dpu_clk_set_rate(priv->dev, clk_ctx->aclk, DPU_AXICLK_DEFAULT,
+				  "aclk");
+
+	ret = clk_prepare_enable(clk_ctx->dscclk);
+	if (ret)
+		goto err_aclk;
+
+	return 0;
+
+err_aclk:
+	clk_disable_unprepare(clk_ctx->aclk);
+err_escclk:
+	clk_disable_unprepare(clk_ctx->escclk);
+err_mclk:
+	clk_disable_unprepare(clk_ctx->mclk);
+err_pxclk:
+	clk_disable_unprepare(clk_ctx->pxclk);
+err:
+	dev_err(priv->dev, "failed to enable DPU clocks: %d\n", ret);
+	return ret;
+}
+
+void spacemit_dpu_disable_clocks(struct spacemit_drm_private *priv)
+{
+	struct dpu_clk_context *clk_ctx = &priv->clk_ctx;
+
+	clk_disable_unprepare(clk_ctx->dscclk);
+	clk_disable_unprepare(clk_ctx->aclk);
+	clk_disable_unprepare(clk_ctx->escclk);
+	clk_disable_unprepare(clk_ctx->mclk);
+	clk_disable_unprepare(clk_ctx->pxclk);
+}
+
+u8 spacemit_plane_hw_get_format_id(u32 format)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(primary_fmts); i++) {
+		if (primary_fmts[i].format == format)
+			return primary_fmts[i].id;
+	}
+
+	return SPACEMIT_DPU_INVALID_FORMAT_ID;
+}
+
+/* Complete a commit whose lists the engine will not confirm any more. */
+void spacemit_dpu_complete_event(struct spacemit_crtc *a_crtc)
+{
+	struct drm_crtc *crtc = &a_crtc->crtc;
+	struct drm_pending_vblank_event *event;
+	unsigned long flags;
+
+	spin_lock_irqsave(&crtc->dev->event_lock, flags);
+	event = a_crtc->event;
+	a_crtc->event = NULL;
+	if (event)
+		drm_crtc_send_vblank_event(crtc, event);
+	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+
+	if (event)
+		drm_crtc_vblank_put(crtc);
+}
+
+void spacemit_cfg_rdy_timer_handler(struct timer_list *t)
+{
+	struct spacemit_crtc *a_crtc = timer_container_of(a_crtc, t,
+							  cfg_rdy_timer);
+
+	drm_err_ratelimited(a_crtc->crtc.dev, "CFG_RDY handshake timeout\n");
+	/* A CFG_RDY that still comes belongs to no commit any more. */
+	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
+	spacemit_dpu_complete_event(a_crtc);
+}
+
+void spacemit_dpu_init(struct spacemit_crtc *a_crtc,
+		       const struct drm_display_mode *mode)
+{
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+	u32 val;
+
+	if (!priv->clocks_on)
+		return;
+
+	if (read_poll_timeout(saturn_hee_get_cfg_rdy, val, val == 0,
+			      SATURN_CFG_IDLE_POLL_US,
+			      SATURN_CFG_IDLE_TIMEOUT_US, false, a_crtc, hwdev))
+		drm_err(a_crtc->crtc.dev, "wait for cfg ready timed out\n");
+
+	saturn_hee_dpu_init(a_crtc, mode);
+}
+
+void spacemit_dpu_uninit(struct spacemit_crtc *a_crtc)
+{
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+
+	if (!priv->clocks_on)
+		return;
+
+	saturn_hee_irq_enable(a_crtc, false);
+}
+
+/* The read channels of the planes this CRTC scans out after the commit. */
+u32 saturn_conf_dpuctrl_rdma(struct drm_atomic_commit *state,
+			     const struct drm_crtc_state *crtc_state)
+{
+	struct drm_plane *plane;
+	u32 rdma_en = 0;
+
+	drm_for_each_plane_mask(plane, crtc_state->crtc->dev,
+				crtc_state->plane_mask) {
+		const struct drm_plane_state *plane_state =
+				drm_atomic_get_new_plane_state(state, plane);
+
+		/* A plane the commit does not touch keeps its current state. */
+		if (!plane_state)
+			plane_state = plane->state;
+		if (plane_state->visible)
+			rdma_en |= BIT(to_spacemit_plane(plane)->rdma_id);
+	}
+
+	return rdma_en;
+}
+
+/* Returns false when none of the pending status bits was this CRTC's. */
+bool spacemit_dpu_online_isr(struct spacemit_crtc *a_crtc)
+{
+	u32 irq_raw, irq_bit, irq_ur_bit, handled;
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+
+	irq_raw = saturn_hee_get_int_sts(hwdev);
+	irq_bit = saturn_hee_get_irq_bit(INT_UNDERRUN);
+	irq_ur_bit = irq_raw & irq_bit;
+	handled = irq_ur_bit;
+	if (irq_ur_bit && !a_crtc->ur_reported) {
+		saturn_hee_clr_int_sts(a_crtc, irq_ur_bit);
+		drm_err_ratelimited(a_crtc->crtc.dev, "underrun\n");
+		a_crtc->ur_reported = true;
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_CFG_RDY);
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		timer_delete(&a_crtc->cfg_rdy_timer);
+		a_crtc->ur_reported = false;
+		saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
+		handled |= irq_bit;
+
+		/* The lists are taken: the next vblank completes the commit. */
+		spin_lock(&a_crtc->crtc.dev->event_lock);
+		if (a_crtc->event) {
+			drm_crtc_arm_vblank_event(&a_crtc->crtc, a_crtc->event);
+			a_crtc->event = NULL;
+		}
+		spin_unlock(&a_crtc->crtc.dev->event_lock);
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_VSYNC);
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		drm_crtc_handle_vblank(&a_crtc->crtc);
+		handled |= irq_bit;
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_REST) | irq_ur_bit;
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		handled |= irq_raw & irq_bit;
+	}
+
+	return handled;
+}
+
+void spacemit_dpu_run(struct drm_crtc *crtc, struct drm_atomic_commit *state)
+{
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+
+	saturn_hee_conf_dpuctrl(crtc, state);
+
+	/* flush all config register writes before CFG_RDY is raised */
+	mb();
+
+	/* Ack first: one left by a commit that timed out is not this one's. */
+	saturn_hee_clr_int_sts(a_crtc, saturn_hee_get_irq_bit(INT_CFG_RDY));
+	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, true);
+
+	mod_timer(&a_crtc->cfg_rdy_timer,
+		  jiffies + msecs_to_jiffies(SATURN_CFG_RDY_TIMEOUT_MS));
+	saturn_hee_cfg_ready(a_crtc, hwdev);
+
+	if (unlikely(a_crtc->is_1st_f)) {
+		drm_dbg(a_crtc->crtc.dev, "DPU start\n");
+		a_crtc->is_1st_f = false;
+		saturn_hee_sw_start(a_crtc, hwdev);
+	}
+}
+
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +670 -0

670 lines not on this page · raw message

drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +66 -0

66 lines not on this page · raw message

drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h new file +16 -0
new file mode 100644
index 0000000000000..ea9189ea738d5
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SATURN_FBCMEM_H_
+#define _SATURN_FBCMEM_H_
+
+#include <drm/drm_plane.h>
+
+#include "../spacemit_crtc.h"
+#include "../spacemit_dpu_reg.h"
+#include "dpu_saturn.h"
+
+#define FBCMEM_UNIT	(32) /* fbcmem is 32 bytes per unit */
+
+int saturn_cal_layer_fbcmem_size(struct drm_plane *plane,
+				 struct drm_plane_state *state);
+
+#endif
drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH v3 09/17] drm/spacemit: add Saturn DPU hardware backend

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/spacemit: vfp underflow in saturn_init_tmg() when front porch < 7 - [High] drm/spacemit…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/spacemit: vfp underflow in saturn_init_tmg() when front porch < 7
- [High] drm/spacemit: unmasked IRQ dispatch and premature vblank event in ISR
- [Medium] drm/spacemit: stale underrun IRQ and ur_mask_armed race on CFG_RDY
- [Medium] drm/spacemit: race on cfg_rdy_timer and INT_CFG_RDY in spacemit_dpu_run()
--

commit feb91f776850387e06b93738a2a9ed3971674069
Author: Cody Kang <[email protected]>

drm/spacemit: add Saturn DPU hardware backend

This commit adds the Saturn DPU hardware backend, covering clock setup, scene control and timing generator programming, RDMA channel and composer configuration, line-buffer sizing, and interrupt handling.

Quoted 6 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +0 -0
new file mode 100644
index 0000000000000..704e64fb9ec7e
@@ -0,0 +1,353 @@

[ ... ]

Quoted 28 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +28 -0
+/* Complete a commit whose lists the engine will not confirm any more. */
+void spacemit_dpu_complete_event(struct spacemit_crtc *a_crtc)
+{
+	struct drm_crtc *crtc = &a_crtc->crtc;
+	struct drm_pending_vblank_event *event;
+	unsigned long flags;
+
+	spin_lock_irqsave(&crtc->dev->event_lock, flags);
+	event = a_crtc->event;
+	a_crtc->event = NULL;
+	if (event)
+		drm_crtc_send_vblank_event(crtc, event);
+	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+
+	if (event)
+		drm_crtc_vblank_put(crtc);
+}
+
+void spacemit_cfg_rdy_timer_handler(struct timer_list *t)
+{
+	struct spacemit_crtc *a_crtc = timer_container_of(a_crtc, t,
+							  cfg_rdy_timer);
+
+	drm_err_ratelimited(a_crtc->crtc.dev, "CFG_RDY handshake timeout\n");
+	/* A CFG_RDY that still comes belongs to no commit any more. */
+	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
+	spacemit_dpu_complete_event(a_crtc);
+}

[ ... ]

Quoted 36 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +36 -0
+/* Returns false when none of the pending status bits was this CRTC's. */
+bool spacemit_dpu_online_isr(struct spacemit_crtc *a_crtc)
+{
+	u32 irq_raw, irq_bit, irq_ur_bit, handled;
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+
+	irq_raw = saturn_hee_get_int_sts(hwdev);
+	irq_bit = saturn_hee_get_irq_bit(INT_UNDERRUN);
+	irq_ur_bit = irq_raw & irq_bit;
+	handled = irq_ur_bit;
+	if (irq_ur_bit && !a_crtc->ur_reported) {
+		saturn_hee_clr_int_sts(a_crtc, irq_ur_bit);
+		drm_err_ratelimited(a_crtc->crtc.dev, "underrun\n");
+		a_crtc->ur_reported = true;
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_CFG_RDY);
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		timer_delete(&a_crtc->cfg_rdy_timer);
+		a_crtc->ur_reported = false;
+		saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, false);
+		handled |= irq_bit;
+
+		/* The lists are taken: the next vblank completes the commit. */
+		spin_lock(&a_crtc->crtc.dev->event_lock);
+		if (a_crtc->event) {
+			drm_crtc_arm_vblank_event(&a_crtc->crtc, a_crtc->event);
+			a_crtc->event = NULL;
+		}
+		spin_unlock(&a_crtc->crtc.dev->event_lock);
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_VSYNC);
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		drm_crtc_handle_vblank(&a_crtc->crtc);

drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 326

Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10 -0
+		handled |= irq_bit;
+	}
+	irq_bit = saturn_hee_get_irq_bit(INT_REST) | irq_ur_bit;
+	if (irq_raw & irq_bit) {
+		saturn_hee_clr_int_sts(a_crtc, irq_bit);
+		handled |= irq_raw & irq_bit;
+	}
+
+	return handled;
+}

[Severity: High]
Can spacemit_dpu_online_isr() complete a commit's vblank event a frame early when INT_CFG_RDY and INT_VSYNC are both set in irq_raw?

As noted in saturn_hee_irq_enable() and spacemit_dpu_run(), DPU_ONLINE_IRQ_STS latches status bits even while their mask bits in DPU_ONLINE_IRQ_MSK are cleared, yet saturn_hee_enable_irq() unmasks interrupts without clearing DPU_ONLINE_IRQ_STS first and spacemit_dpu_online_isr() does not mask irq_raw against DPU_ONLINE_IRQ_MSK. When INT_CFG_RDY fires while INT_VSYNC is also set (either from a frame boundary or latched while vblank was masked), the INT_CFG_RDY branch calls drm_crtc_arm_vblank_event() and the following INT_VSYNC branch immediately calls drm_crtc_handle_vblank() in the same ISR invocation. That delivers the flip event before the next vblank and unblocks drm_atomic_helper_wait_for_flip_done() early, allowing the next commit to overwrite the active command list slot.

Quoted 16 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +16 -0
+
+void spacemit_dpu_run(struct drm_crtc *crtc, struct drm_atomic_commit *state)
+{
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+
+	saturn_hee_conf_dpuctrl(crtc, state);
+
+	/* flush all config register writes before CFG_RDY is raised */
+	mb();
+
+	/* Ack first: one left by a commit that timed out is not this one's. */
+	saturn_hee_clr_int_sts(a_crtc, saturn_hee_get_irq_bit(INT_CFG_RDY));
+	saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, true);
+

drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 352

Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10 -0
+	mod_timer(&a_crtc->cfg_rdy_timer,
+		  jiffies + msecs_to_jiffies(SATURN_CFG_RDY_TIMEOUT_MS));
+	saturn_hee_cfg_ready(a_crtc, hwdev);
+
+	if (unlikely(a_crtc->is_1st_f)) {
+		drm_dbg(a_crtc->crtc.dev, "DPU start\n");
+		a_crtc->is_1st_f = false;
+		saturn_hee_sw_start(a_crtc, hwdev);
+	}
+}

[Severity: Medium]
Can spacemit_cfg_rdy_timer_handler() race with spacemit_dpu_online_isr() and spacemit_dpu_run() to complete the next commit's vblank event early or leave INT_CFG_RDY masked?

CPU0 (<softirq>) CPU1
spacemit_cfg_rdy_timer_handler()
drm_err_ratelimited(...)

                                  <hardirq>
                                  spacemit_dpu_online_isr()
                                    timer_delete(&a_crtc->cfg_rdy_timer)
                                    drm_crtc_arm_vblank_event(...)
                                    drm_crtc_handle_vblank(...)
                                  spacemit_crtc_atomic_flush()
                                    a_crtc->event = new_event
                                    spacemit_dpu_run()
                                      saturn_hee_enable_irq(..., true)

saturn_hee_enable_irq(..., false) spacemit_dpu_complete_event()
drm_crtc_send_vblank_event() <-- completes new commit early

timer_delete() in spacemit_dpu_online_isr() does not wait for an in-flight spacemit_cfg_rdy_timer_handler(), so the timer callback can mask the next commit's INT_CFG_RDY and complete its a_crtc->event before the hardware consumes its command lists.

In addition, spacemit_dpu_run() unmasks INT_CFG_RDY before mod_timer() and saturn_hee_cfg_ready(). If a late CFG_RDY from a previously timed-out commit arrives right after saturn_hee_enable_irq(a_crtc, INT_CFG_RDY, true), spacemit_dpu_online_isr() runs timer_delete() before the timer is armed, masks INT_CFG_RDY, and arms a_crtc->event before both_cfg_rdy is written for the new commit.

Quoted 6 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +0 -0
new file mode 100644
index 0000000000000..1a194fe7cc7ba
@@ -0,0 +1,670 @@

[ ... ]

Quoted 7 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +7 -0
+void saturn_hee_enable_irq(struct spacemit_crtc *a_crtc,
+			   enum spacemit_dpu_irq irq_id, bool enable)
+{
+	saturn_enable_irq_mask(a_crtc, enable,
+			       DPU_INT_BASE_ADDR + DPU_ONLINE_IRQ_MSK,
+			       saturn_hee_get_irq_bit(irq_id));
+}

drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 74

Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +10 -0
+
+void saturn_hee_cfg_ready(struct spacemit_crtc *a_crtc,
+			  struct spacemit_hw_device *hwdev)
+{
+	u32 base = DPU_SCENE_CTL_ADDR(COMPOSER1);
+
+	saturn_hee_enable_irq(a_crtc, INT_UNDERRUN, true);
+	a_crtc->ur_mask_armed = true;
+	dpu_write(hwdev, DPU_CTL_REG, base, both_cfg_rdy, 1);
+}

[Severity: Medium]
Does enabling INT_UNDERRUN in saturn_hee_cfg_ready() before setting a_crtc->ur_mask_armed and without clearing DPU_ONLINE_IRQ_STS race with spacemit_dpu_online_isr()?

saturn_hee_cfg_ready()
saturn_hee_enable_irq(a_crtc, INT_UNDERRUN, true) <hardirq>

    spacemit_dpu_online_isr()
      saturn_hee_clr_int_sts(a_crtc, ...)
        if (... && a_crtc->ur_mask_armed)  <-- still false; stays unmasked

a_crtc->ur_mask_armed = true

After an underrun, INT_UNDERRUN is masked for the rest of the frame while the hardware continues latching DPU_INT_FRM_TIMING_UNFLOW in DPU_ONLINE_IRQ_STS. When the next commit calls saturn_hee_cfg_ready(), unmasking INT_UNDERRUN without clearing DPU_ONLINE_IRQ_STS immediately triggers spacemit_dpu_online_isr(). If the interrupt arrives before a_crtc->ur_mask_armed = true (which also happens in saturn_hee_irq_enable()), saturn_hee_clr_int_sts() sees ur_mask_armed == false and leaves INT_UNDERRUN unmasked; if it arrives after ur_mask_armed = true but before INT_CFG_RDY clears ur_reported, the bottom saturn_hee_clr_int_sts() call in spacemit_dpu_online_isr() immediately masks INT_UNDERRUN again before the new commit takes effect.

Quoted 49 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +49 -0
+
+void saturn_hee_sw_start(struct spacemit_crtc *a_crtc,
+			 struct spacemit_hw_device *hwdev)
+{
+	u32 base;
+
+	base = DPU_SCENE_CTL_ADDR(COMPOSER1);
+	dpu_write_reg(hwdev, DPU_CTL_REG, base, sw_start, 1);
+}
+
+static void saturn_init_tmg(struct spacemit_crtc *a_crtc,
+			    const struct drm_display_mode *mode)
+{
+	u32 base = TMG0_BASE_ADDR;
+	struct spacemit_drm_private *priv = a_crtc->crtc.dev->dev_private;
+	struct spacemit_hw_device *hwdev = priv->hwdev;
+	u16 vfp, vbp, vsync, hfp, hbp, hsync;
+	void __iomem *tmg_addr;
+	u32 value;
+
+	tmg_addr = hwdev->base + TMG0_BASE_ADDR;
+
+	hsync = mode->hsync_end - mode->hsync_start;
+	hbp = mode->htotal - mode->hsync_end;
+	hfp = mode->hsync_start - mode->hdisplay;
+	vsync = mode->vsync_end - mode->vsync_start;
+	vbp = mode->vtotal - mode->vsync_end;
+	vfp = mode->vsync_start - mode->vdisplay;
+	drm_dbg(a_crtc->crtc.dev, "timing " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
+
+	dpu_write(hwdev, TMG_REG, base, disp_ready_man_en, 0);
+	dpu_write(hwdev, TMG_REG, base, background_r, 0);
+	dpu_write(hwdev, TMG_REG, base, background_g, 0x0);
+	dpu_write(hwdev, TMG_REG, base, background_b, 0xff);
+	dpu_write(hwdev, TMG_REG, base, eof_1st_ln_dly_num, vfp - 7);
+	dpu_write(hwdev, TMG_REG, base, eof_2nd_ln_dly_num, vfp - 6);
+	dpu_write(hwdev, TMG_REG, base, split_en, 0);
+	dpu_write(hwdev, TMG_REG, base, cmd_screen, 0);
+	dpu_write(hwdev, TMG_REG, base, cmd_wait_en, 0);
+	dpu_write(hwdev, TMG_REG, base, cmd_wait_te, 0);
+	dpu_write(hwdev, TMG_REG, base, sof_pre_ln_num, 0);
+	dpu_write(hwdev, TMG_REG, base, hfp, hfp);
+	dpu_write(hwdev, TMG_REG, base, hbp, hbp);
+	dpu_write(hwdev, TMG_REG, base, vfp, vfp);
+	dpu_write(hwdev, TMG_REG, base, vbp, vbp);
+	dpu_write(hwdev, TMG_REG, base, hsync_width, hsync);
+	dpu_write(hwdev, TMG_REG, base, vsync_width, vsync);
+	dpu_write(hwdev, TMG_REG, base, hsp, 1);
+	dpu_write(hwdev, TMG_REG, base, vsp, 1);

drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 133

Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +10 -0
+	dpu_write(hwdev, TMG_REG, base, h_active, mode->hdisplay);
+	dpu_write(hwdev, TMG_REG, base, v_active, mode->vdisplay);
+	dpu_write(hwdev, TMG_REG, base, fm_timing_en, 1);
+	/* The pipeline always hands RGB888 to the DP/eDP encoder. */
+	dpu_write(hwdev, TMG_REG, base, user, OUTFMT_RGB888);
+
+	value = readl(tmg_addr + 4 * dpu_field_word(TMG_REG, vfp));
+	value &= ~dpu_field_mask(TMG_REG, vfp);
+	value |= vfp;
+	writel(value, tmg_addr + 4 * dpu_field_word(TMG_REG, vfp));

[Severity: High]
Does vfp - 7 and vfp - 6 underflow when the display mode's vertical front porch is smaller than 7 lines?

Standard modes such as 1920x1080@60Hz (vdisplay = 1080, vsync_start = 1084, so vfp = 4) have vfp < 7, which wraps the 16-bit eof_1st_ln_dly_num and eof_2nd_ln_dly_num fields to 0xfff9..0xffff, exceeding vtotal so the EOF line-delay counters cannot fire within the frame. Also, the raw readl()/writel() sequence at the end of saturn_init_tmg() redundantly rewrites the same vfp field that dpu_write(hwdev, TMG_REG, base, vfp, vfp) just programmed above.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
author
#13 lore raw

PATCH v3 10/17 drm/spacemit: add Saturn DPU KMS pipeline

In reply to Cody Kang

From: Cody Kang <[email protected]>

Add the atomic KMS implementation on top of the hardware backend: one CRTC and one primary plane per DPU instance. The plane's atomic_check sizes its share of the RDMA line buffer and prepare_fb builds the framebuffer's DMMU table; atomic commit fills the per-channel command lists and arms the CFG_RDY handshake, and the commit's event is delivered at the vblank after the engine has taken the lists. The DPU is powered through runtime PM.

---
v3:
- use atomic_create_state; .reset is gone from the CRTC and plane funcs in v7.4-rc1
- drop the ops table between the KMS code and the DPU backend (Thomas Zimmermann)
- drop the tracepoints; use drm_dbg() and drm_WARN_ON() (Thomas Zimmermann)
- wrap only the hardware access in drm_dev_enter() (Thomas Zimmermann)
- enable vblank after programming the mode, and initialise vblank after drm_mode_config_reset() (Thomas Zimmermann)
- program the plane from the clipped rectangles; drop the 1:1 and zero-size source checks (Thomas Zimmermann)
- submit the plane's command list from its atomic_update, and turn its channel off when the plane is disabled (Thomas Zimmermann)
- size the line buffer in the plane's atomic_check; no allocation in atomic_check (Thomas Zimmermann)
- add prepare_fb: build the display MMU table there and wait for the buffer's fences (Thomas Zimmermann)
- stop the boot loader's pipeline at probe instead of at the first modeset, and request the interrupt after it (Thomas Zimmermann)
- power the DPU through runtime PM instead of from atomic_disable (Thomas Zimmermann)
- release the drm_device when the aggregate unbinds, and stop output polling before its components unbind; take the mode and the plane state from the commit
- reject a framebuffer with an offset, a src_x beyond the DMMU table padding, or a buffer larger than one TBU can map
- reject modes above 3840x2160 in the CRTC's mode_valid (Icenowy Zheng)
- do not advertise a gamma table (Guodong Xu)
v2:
- put all five DPU reset lines behind one reset_control_bulk_* pair (Philipp Zabel, Guodong Xu)
- keep the online IRQ alive across drm_dev_unregister() and drm_atomic_helper_shutdown() in unbind (Sashiko)
- free the per-state DMA buffers in the plane .reset path instead of bypassing the custom state destructor (Sashiko)
- release the duplicated state's references on the rdmas allocation failure path in crtc duplicate_state (Sashiko)
- set clocks_on only after dpu_pm_resume() has enabled the clocks (Sashiko)

---
 drivers/gpu/drm/spacemit/spacemit_crtc.c   | 589 +++++++++++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_planes.c | 332 ++++++++++++++++
 2 files changed, 921 insertions(+)
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +589 -0
new file mode 100644
index 0000000000000..c1257444dd150
@@ -0,0 +1,589 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025-2026 SpacemiT Co., Ltd.
+ *
+ */
+
+#include <linux/aperture.h>
+#include <linux/component.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/timer.h>
+
+#include <drm/clients/drm_client_setup.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+
+#include "dpu/dpu_saturn.h"
+#include "dpu/saturn_regs/ops_hee.h"
+#include "dpu/saturn_regs/saturn_fields.h"
+#include "spacemit_cmdlist.h"
+#include "spacemit_crtc.h"
+#include "spacemit_dmmu.h"
+#include "spacemit_drm.h"
+
+static void spacemit_crtc_atomic_enable(struct drm_crtc *crtc,
+					struct drm_atomic_commit *state)
+{
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, crtc);
+	const struct drm_display_mode *mode = &crtc_state->adjusted_mode;
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct spacemit_drm_private *priv = crtc->dev->dev_private;
+	int idx;
+	int ret;
+
+	/*
+	 * Not pm_runtime_resume_and_get(): atomic_disable runs and drops this
+	 * reference even when the power-up failed.
+	 */
+	ret = pm_runtime_get_sync(priv->dev);
+	if (ret < 0) {
+		/* The resume callback has said what failed. */
+		drm_dbg(crtc->dev, "DPU power-up failed: %d\n", ret);
+		return;
+	}
+
+	if (drm_dev_enter(crtc->dev, &idx)) {
+		spacemit_dpu_init(a_crtc, mode);
+		a_crtc->is_1st_f = true;
+		drm_dev_exit(idx);
+	}
+
+	drm_crtc_vblank_on(&a_crtc->crtc);
+}
+
+static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc,
+					 struct drm_atomic_commit *state)
+{
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, crtc);
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct drm_device *drm = a_crtc->crtc.dev;
+	struct spacemit_drm_private *priv = drm->dev_private;
+	int idx;
+
+	if (drm_dev_enter(drm, &idx)) {
+		spacemit_dpu_uninit(a_crtc);
+		drm_dev_exit(idx);
+	}
+
+	drm_crtc_vblank_off(&a_crtc->crtc);
+
+	/* A commit may still be waiting for CFG_RDY: stop its watchdog. */
+	timer_delete_sync(&a_crtc->cfg_rdy_timer);
+
+	pm_runtime_put_sync(priv->dev);
+
+	/* No further vblank will come; complete the disable event here. */
+	spacemit_dpu_complete_event(a_crtc);
+	spin_lock_irq(&drm->event_lock);
+	if (crtc_state->event) {
+		drm_crtc_send_vblank_event(crtc, crtc_state->event);
+		crtc_state->event = NULL;
+	}
+	spin_unlock_irq(&drm->event_lock);
+}
+
+/* Planes write composer rows into the CRTC list, so open it before them. */
+static void spacemit_crtc_atomic_begin(struct drm_crtc *crtc,
+				       struct drm_atomic_commit *state)
+{
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+
+	spacemit_cmdlist_ring_next(a_crtc->cl, &a_crtc->cl_cur);
+}
+
+static void spacemit_crtc_atomic_flush(struct drm_crtc *crtc,
+				       struct drm_atomic_commit *state)
+{
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, crtc);
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct spacemit_drm_private *priv = crtc->dev->dev_private;
+	int idx;
+
+	/*
+	 * The event releases the next commit, which rewrites the other
+	 * command list and points the engine at it. Hold the event until
+	 * CFG_RDY says the engine has taken this commit's lists; the
+	 * interrupt then arms it for the following vblank.
+	 */
+	spin_lock_irq(&crtc->dev->event_lock);
+	if (crtc_state->event) {
+		if (drm_crtc_vblank_get(crtc) == 0)
+			a_crtc->event = crtc_state->event;
+		else
+			drm_crtc_send_vblank_event(crtc, crtc_state->event);
+		crtc_state->event = NULL;
+	}
+	spin_unlock_irq(&crtc->dev->event_lock);
+
+	/* clocks_on is false here only after a failed power-up. */
+	if (priv->clocks_on && drm_dev_enter(crtc->dev, &idx)) {
+		spacemit_dpu_run(crtc, state);
+		drm_dev_exit(idx);
+	} else {
+		spacemit_dpu_complete_event(a_crtc);
+	}
+}
+
+static int spacemit_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	saturn_hee_enable_irq(to_spacemit_crtc(crtc), INT_VSYNC, true);
+
+	return 0;
+}
+
+static void spacemit_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+	saturn_hee_enable_irq(to_spacemit_crtc(crtc), INT_VSYNC, false);
+}
+
+static enum drm_mode_status
+spacemit_crtc_mode_valid(struct drm_crtc *crtc,
+			 const struct drm_display_mode *mode)
+{
+	if (mode->hdisplay > SPACEMIT_DPU_MAX_HDISPLAY)
+		return MODE_BAD_HVALUE;
+	if (mode->vdisplay > SPACEMIT_DPU_MAX_VDISPLAY)
+		return MODE_BAD_VVALUE;
+
+	return MODE_OK;
+}
+
+static const struct drm_crtc_helper_funcs spacemit_crtc_helper_funcs = {
+	.mode_valid = spacemit_crtc_mode_valid,
+	.atomic_begin = spacemit_crtc_atomic_begin,
+	.atomic_flush = spacemit_crtc_atomic_flush,
+	.atomic_enable = spacemit_crtc_atomic_enable,
+	.atomic_disable = spacemit_crtc_atomic_disable,
+};
+
+static const struct drm_crtc_funcs spacemit_crtc_funcs = {
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_create_state = drm_atomic_helper_crtc_create_state,
+	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+	.enable_vblank = spacemit_crtc_enable_vblank,
+	.disable_vblank = spacemit_crtc_disable_vblank,
+};
+
+static void spacemit_crtc_put_port(struct drm_device *drm, void *port)
+{
+	of_node_put(port);
+}
+
+static struct spacemit_crtc *spacemit_crtc_create(struct drm_device *drm,
+						  struct drm_plane *primary,
+						  struct device_node *port)
+{
+	struct spacemit_crtc *a_crtc;
+	int err;
+
+	a_crtc = drmm_crtc_alloc_with_planes(drm, struct spacemit_crtc, crtc,
+					     primary, NULL,
+					     &spacemit_crtc_funcs, NULL);
+	if (IS_ERR(a_crtc)) {
+		drm_err(drm, "failed to init crtc\n");
+		return a_crtc;
+	}
+
+	/*
+	 * drm_of_find_possible_crtcs() walks crtc->port for the life of the
+	 * drm_device.
+	 */
+	a_crtc->crtc.port = of_node_get(port);
+	err = drmm_add_action_or_reset(drm, spacemit_crtc_put_port, port);
+	if (err)
+		return ERR_PTR(err);
+
+	drm_crtc_helper_add(&a_crtc->crtc, &spacemit_crtc_helper_funcs);
+
+	err = spacemit_cmdlist_ring_init(drm, a_crtc->cl, CMDLIST_CRTC, NULL,
+					 &a_crtc->crtc);
+	if (err)
+		return ERR_PTR(err);
+
+	a_crtc->cl_cmp = spacemit_cmdlist_regs_alloc(drm, CMPS_X_REG__NWORDS);
+	a_crtc->cl_pp = spacemit_cmdlist_regs_alloc(drm, POSTPIPE_REG__NWORDS);
+	if (!a_crtc->cl_cmp || !a_crtc->cl_pp)
+		return ERR_PTR(-ENOMEM);
+
+	return a_crtc;
+}
+
+/* The one plane and the one CRTC of a DPU instance. */
+static struct spacemit_crtc *spacemit_drm_pipeline_init(struct drm_device *drm)
+{
+	struct spacemit_crtc *a_crtc;
+	struct device_node *port;
+	struct drm_plane *plane;
+
+	plane = spacemit_plane_init(drm);
+	if (IS_ERR(plane))
+		return ERR_CAST(plane);
+
+	port = of_graph_get_port_by_id(drm->dev->of_node, 0);
+	if (!port)
+		return ERR_PTR(dev_err_probe(drm->dev, -EINVAL,
+					     "no output port\n"));
+
+	a_crtc = spacemit_crtc_create(drm, plane, port);
+	of_node_put(port);
+	if (IS_ERR(a_crtc))
+		return a_crtc;
+
+	timer_setup(&a_crtc->cfg_rdy_timer, spacemit_cfg_rdy_timer_handler, 0);
+
+	return a_crtc;
+}
+
+static irqreturn_t spacemit_dpu_isr(int irq, void *data)
+{
+	struct spacemit_drm_private *priv = data;
+	struct spacemit_crtc *a_crtc = priv->a_crtc;
+
+	if (!a_crtc)
+		return IRQ_NONE;
+
+	/* Reading a clock-gated DPU's status registers stalls the bus. */
+	if (unlikely(!READ_ONCE(priv->clocks_on)))
+		return IRQ_NONE;
+
+	/*
+	 * Not under drm_dev_enter(): an unplugged device raises interrupts
+	 * until its CRTC is off, and they still have to be acked.
+	 */
+	return spacemit_dpu_online_isr(a_crtc) ? IRQ_HANDLED : IRQ_NONE;
+}
+
+/*
+ * Acquire at probe, not at bind: the aggregate can rebind without this device
+ * detaching, and the exclusive resets would not be handed out a second time.
+ */
+static int spacemit_dpu_hw_resources_init(struct spacemit_drm_private *priv,
+					  struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int n_rstc;
+	int ret;
+
+	ret = spacemit_dpu_parse_clocks(dev, &priv->clk_ctx);
+	if (ret)
+		return ret;
+
+	priv->pipe_resets[0].id = "lcd";
+	priv->pipe_resets[1].id = "esc";
+	priv->pipe_resets[2].id = "mclk";
+	priv->pipe_resets[3].id = "aclk";
+	priv->pipe_resets[4].id = "dsc";
+	n_rstc = ARRAY_SIZE(priv->pipe_resets);
+	ret = devm_reset_control_bulk_get_exclusive(dev, n_rstc,
+						    priv->pipe_resets);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to get resets\n");
+
+	/*
+	 * The boot loader may leave its boot-logo pipeline running. Stop it
+	 * here with the resets alone (the clocks are not ours to gate yet)
+	 * and hold them until the first enable brings the block up.
+	 */
+	ret = reset_control_bulk_assert(n_rstc, priv->pipe_resets);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to assert resets\n");
+	usleep_range(10000, 20000);
+
+	priv->irq_online = platform_get_irq_byname(pdev, "online");
+	if (priv->irq_online < 0)
+		return priv->irq_online;
+
+	/* Keep the line disabled until bind: the handler needs bind state. */
+	return devm_request_irq(dev, priv->irq_online, spacemit_dpu_isr,
+				IRQF_NO_AUTOEN, "DPU_ONLINE", priv);
+}
+
+static const struct regmap_config spacemit_dpu_regmap_config = {
+	.name		= "dpu",
+	.reg_bits	= 32,
+	.val_bits	= 32,
+	.reg_stride	= 4,
+	.max_register	= 0x53ffc,	/* 0x54000-byte DPU register window */
+};
+
+static int spacemit_drm_master_bind(struct device *dev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(dev);
+	struct spacemit_crtc *a_crtc;
+	struct drm_device *drm;
+	int ret;
+
+	ret = aperture_remove_all_conflicting_devices(spacemit_drm_drv.name);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to remove existing framebuffers\n");
+
+	/*
+	 * Bind-scoped, not devm: the aggregate can rebind without this
+	 * device being re-probed, and each bind must release its own
+	 * drm_device.
+	 */
+	drm = drm_dev_alloc(&spacemit_drm_drv, dev);
+	if (IS_ERR(drm))
+		return PTR_ERR(drm);
+	priv->ddev = drm;
+	drm->dev_private = priv;
+
+	ret = spacemit_drm_mode_config_init(drm);
+	if (ret)
+		goto err_dc;
+
+	a_crtc = spacemit_drm_pipeline_init(drm);
+	if (IS_ERR(a_crtc)) {
+		ret = PTR_ERR(a_crtc);
+		goto err_dc;
+	}
+	priv->a_crtc = a_crtc;
+
+	/*
+	 * component_bind_all() unbinds what it bound before returning an error.
+	 */
+	ret = component_bind_all(dev, drm);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to bind all components\n");
+		goto err_dc;
+	}
+
+	drm_mode_config_reset(drm);
+
+	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to initialize vblank\n");
+		goto err_unbind_all;
+	}
+
+	drmm_kms_helper_poll_init(drm);
+	drm_helper_hpd_irq_event(drm);
+
+	enable_irq(priv->irq_online);
+
+	ret = drm_dev_register(drm, 0);
+	if (ret < 0)
+		goto err_disable_irq;
+	drm_client_setup(drm, NULL);
+
+	return 0;
+
+err_disable_irq:
+	disable_irq(priv->irq_online);
+
+err_unbind_all:
+	component_unbind_all(dev, drm);
+err_dc:
+	/*
+	 * .shutdown tests priv->ddev; never leave it on a half-initialised
+	 * device.
+	 */
+	priv->ddev = NULL;
+	priv->a_crtc = NULL;
+	drm_dev_put(drm);
+	return ret;
+}
+
+static void spacemit_drm_master_unbind(struct device *dev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(dev);
+	struct drm_device *drm = priv->ddev;
+
+	/*
+	 * A process may keep the card open past this point. Unplug, so that
+	 * its ioctls fail and the drm_dev_enter() sections keep off the
+	 * registers. The commits that follow still turn the outputs off: the
+	 * CRTC drops its runtime PM reference, and the suspend resets the DPU.
+	 * The interrupt stays alive until then, for a commit that was already
+	 * waiting on it.
+	 */
+	drm_dev_unplug(drm);
+	/* An open file keeps the drm_device, and its poll worker, alive. */
+	drm_kms_helper_poll_fini(drm);
+	drm_atomic_helper_shutdown(drm);
+
+	disable_irq(priv->irq_online);
+
+	component_unbind_all(dev, drm);
+
+	/* .shutdown and a later re-bind must not touch the stale instance. */
+	priv->ddev = NULL;
+	priv->a_crtc = NULL;
+
+	drm_dev_put(drm);
+}
+
+const struct component_master_ops spacemit_drm_master_ops = {
+	.bind = spacemit_drm_master_bind,
+	.unbind = spacemit_drm_master_unbind,
+};
+
+static int spacemit_dpu_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const struct spacemit_hw_device *hwdev_template;
+	struct spacemit_drm_private *priv;
+	int ret;
+
+	/* A display MMU entry holds a 26-bit page frame number. */
+	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(38));
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to set DMA mask\n");
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+	priv->dev = dev;
+	dev_set_drvdata(dev, priv);
+
+	/* The match data is shared const; the MMIO mapping is per-instance. */
+	hwdev_template = device_get_match_data(dev);
+	if (!hwdev_template)
+		return -ENODEV;
+	priv->hwdev = devm_kmemdup(dev, hwdev_template,
+				   sizeof(*hwdev_template), GFP_KERNEL);
+	if (!priv->hwdev)
+		return -ENOMEM;
+
+	priv->hwdev->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->hwdev->base))
+		return PTR_ERR(priv->hwdev->base);
+
+	priv->hwdev->regmap = devm_regmap_init_mmio(dev, priv->hwdev->base,
+						    &spacemit_dpu_regmap_config);
+	if (IS_ERR(priv->hwdev->regmap))
+		return dev_err_probe(dev, PTR_ERR(priv->hwdev->regmap),
+				     "failed to init DPU regmap\n");
+
+	ret = spacemit_dpu_hw_resources_init(priv, pdev);
+	if (ret)
+		return ret;
+
+	/* Held in reset with the clocks off: the suspended state. */
+	ret = devm_pm_runtime_enable(dev);
+	if (ret)
+		return ret;
+
+	return spacemit_drm_of_component_probe(dev);
+}
+
+static void spacemit_dpu_remove(struct platform_device *pdev)
+{
+	component_master_del(&pdev->dev, &spacemit_drm_master_ops);
+}
+
+static void spacemit_dpu_shutdown(struct platform_device *pdev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(&pdev->dev);
+	struct drm_device *drm = priv->ddev;
+
+	/* Not bound: nothing was ever enabled. */
+	if (!drm)
+		return;
+
+	drm_atomic_helper_shutdown(drm);
+}
+
+static int spacemit_dpu_runtime_suspend(struct device *dev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(dev);
+	int ret;
+
+	/*
+	 * Close the ISR's MMIO gate, then let a handler that is already past
+	 * it finish before the clocks stop.
+	 */
+	WRITE_ONCE(priv->clocks_on, false);
+	synchronize_irq(priv->irq_online);
+
+	/*
+	 * Assert before gating: a reset asserted into an already-gated block
+	 * has no clock edges to propagate on and leaves the register file
+	 * untouched.
+	 */
+	ret = reset_control_bulk_assert(ARRAY_SIZE(priv->pipe_resets),
+					priv->pipe_resets);
+	if (ret)
+		dev_warn(dev, "failed to assert resets: %d\n", ret);
+	usleep_range(10000, 20000);
+
+	spacemit_dpu_disable_clocks(priv);
+
+	return 0;
+}
+
+static int spacemit_dpu_runtime_resume(struct device *dev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(dev);
+	int ret;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(priv->pipe_resets),
+					  priv->pipe_resets);
+	if (ret) {
+		dev_err(dev, "failed to deassert resets: %d\n", ret);
+		return ret;
+	}
+
+	ret = spacemit_dpu_enable_clocks(priv);
+	if (ret) {
+		reset_control_bulk_assert(ARRAY_SIZE(priv->pipe_resets),
+					  priv->pipe_resets);
+		return ret;
+	}
+
+	/* The DPU must settle after reset deassert or CFG_RDY races the flush. */
+	usleep_range(10000, 20000);
+	WRITE_ONCE(priv->clocks_on, true);
+
+	return 0;
+}
+
+static const struct dev_pm_ops spacemit_dpu_pm_ops = {
+	RUNTIME_PM_OPS(spacemit_dpu_runtime_suspend, spacemit_dpu_runtime_resume,
+		       NULL)
+};
+
+static const struct of_device_id spacemit_dpu_match_table[] = {
+	{
+		.compatible = "spacemit,k3-saturn-dpu",
+		.data = &spacemit_k3_saturn_dpu,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, spacemit_dpu_match_table);
+
+static struct platform_driver spacemit_dpu_driver = {
+	.probe = spacemit_dpu_probe,
+	.remove = spacemit_dpu_remove,
+	.shutdown = spacemit_dpu_shutdown,
+	.driver = {
+		.name = "spacemit-dpu-drv",
+		.of_match_table = spacemit_dpu_match_table,
+		.pm = pm_ptr(&spacemit_dpu_pm_ops),
+		.suppress_bind_attrs = true,
+	},
+};
+module_platform_driver(spacemit_dpu_driver);
+
+MODULE_DESCRIPTION("SpacemiT DRM KMS master driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/spacemit/spacemit_planes.c new file +332 -0

332 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH v3 10/17] drm/spacemit: add Saturn DPU KMS pipeline

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] drm/spacemit: premature event send in spacemit_crtc_atomic_disable() - [High] drm/spacemit…

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [High] drm/spacemit: premature event send in spacemit_crtc_atomic_disable()
- [High] drm/spacemit: premature event arming in spacemit_crtc_atomic_flush() and ISR
- [High] drm/spacemit: stale INT_VSYNC not cleared in spacemit_crtc_enable_vblank()
- [Medium] drm/spacemit: unbind before poll_fini in spacemit_drm_master_bind()
- [Medium] drm/spacemit: composer dst_w and dst_h left at 0 when no plane is visible
- [Medium] drm/spacemit: vblank not reset due to drm_vblank_init() ordering
--

commit c4c8906d170c5bfb4e5c852ca468ddf4805b4d47
Author: Cody Kang <[email protected]>

drm/spacemit: add Saturn DPU KMS pipeline

This commit adds the atomic KMS CRTC and primary plane implementation, runtime PM hooks, and component master bind/unbind logic for the Saturn DPU.

Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0 -0
new file mode 100644
index 0000000000000..c1257444dd150
@@ -0,0 +1,589 @@

[ ... ]

Quoted 21 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +21 -0
+static void spacemit_crtc_atomic_disable(struct drm_crtc *crtc,
+					 struct drm_atomic_commit *state)
+{
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, crtc);
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct drm_device *drm = a_crtc->crtc.dev;
+	struct spacemit_drm_private *priv = drm->dev_private;
+	int idx;
+
+	if (drm_dev_enter(drm, &idx)) {
+		spacemit_dpu_uninit(a_crtc);
+		drm_dev_exit(idx);
+	}
+
+	drm_crtc_vblank_off(&a_crtc->crtc);
+
+	/* A commit may still be waiting for CFG_RDY: stop its watchdog. */
+	timer_delete_sync(&a_crtc->cfg_rdy_timer);
+
+	pm_runtime_put_sync(priv->dev);

drivers/gpu/drm/spacemit/spacemit_crtc.c line 99

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10 -0
+
+	/* No further vblank will come; complete the disable event here. */
+	spacemit_dpu_complete_event(a_crtc);
+	spin_lock_irq(&drm->event_lock);
+	if (crtc_state->event) {
+		drm_crtc_send_vblank_event(crtc, crtc_state->event);
+		crtc_state->event = NULL;
+	}
+	spin_unlock_irq(&drm->event_lock);
+}

[Severity: High]
Does sending crtc_state->event without checking !crtc_state->active complete the vblank event prematurely during an active-to-active modeset?

When changing modes on an active CRTC, drm_atomic_helper_commit_modeset_disables() calls spacemit_crtc_atomic_disable() before spacemit_crtc_atomic_enable() and spacemit_crtc_atomic_flush() run. Consuming crtc_state->event here delivers the event and signals commit->flip_done before the new mode is programmed, allowing a subsequent non-blocking commit to overwrite the 2-slot command-list ring before the engine takes the modeset lists.

[ ... ]

Quoted 23 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +23 -0
+static void spacemit_crtc_atomic_flush(struct drm_crtc *crtc,
+				       struct drm_atomic_commit *state)
+{
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, crtc);
+	struct spacemit_crtc *a_crtc = to_spacemit_crtc(crtc);
+	struct spacemit_drm_private *priv = crtc->dev->dev_private;
+	int idx;
+
+	/*
+	 * The event releases the next commit, which rewrites the other
+	 * command list and points the engine at it. Hold the event until
+	 * CFG_RDY says the engine has taken this commit's lists; the
+	 * interrupt then arms it for the following vblank.
+	 */
+	spin_lock_irq(&crtc->dev->event_lock);
+	if (crtc_state->event) {
+		if (drm_crtc_vblank_get(crtc) == 0)
+			a_crtc->event = crtc_state->event;
+		else
+			drm_crtc_send_vblank_event(crtc, crtc_state->event);
+		crtc_state->event = NULL;
+	}

drivers/gpu/drm/spacemit/spacemit_crtc.c line 142

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10 -0
+	spin_unlock_irq(&crtc->dev->event_lock);
+
+	/* clocks_on is false here only after a failed power-up. */
+	if (priv->clocks_on && drm_dev_enter(crtc->dev, &idx)) {
+		spacemit_dpu_run(crtc, state);
+		drm_dev_exit(idx);
+	} else {
+		spacemit_dpu_complete_event(a_crtc);
+	}
+}

[Severity: High]
Can a_crtc->event be armed and delivered before the hardware takes the new command lists?

spacemit_crtc_atomic_flush()
spin_lock_irq(&crtc->dev->event_lock) drm_crtc_vblank_get(crtc)
a_crtc->event = crtc_state->event spin_unlock_irq(&crtc->dev->event_lock)
<hardirq>
spacemit_dpu_online_isr()
if (irq_raw & INT_CFG_RDY)
drm_crtc_arm_vblank_event(..., a_crtc->event) <-- armed early
if (irq_raw & INT_VSYNC)
drm_crtc_handle_vblank(...) <-- sent early
spacemit_dpu_run()

    saturn_hee_conf_dpuctrl()
    saturn_hee_clr_int_sts(..., INT_CFG_RDY)
    saturn_hee_cfg_ready()

spacemit_dpu_online_isr() inspects the unmasked DPU_ONLINE_IRQ_STS register. If an enabled interrupt (such as INT_VSYNC) fires after event_lock is dropped and before spacemit_dpu_run() clears a leftover INT_CFG_RDY status bit and raises both_cfg_rdy, the ISR sees INT_CFG_RDY and arms a_crtc->event before the CRTC command list is even submitted.

In addition, because spacemit_dpu_online_isr() handles INT_CFG_RDY before INT_VSYNC and there is no get_vblank_counter hook, when both bits are set in irq_raw, drm_crtc_arm_vblank_event() arms the event for vblank->count + 1 and the immediately following drm_crtc_handle_vblank() increments vblank->count and delivers it in the same interrupt instead of at the next vblank, releasing flip_done while the command list is still in use.

drivers/gpu/drm/spacemit/spacemit_crtc.c line 149

Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +7 -0
+
+static int spacemit_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	saturn_hee_enable_irq(to_spacemit_crtc(crtc), INT_VSYNC, true);
+
+	return 0;
+}

[Severity: High]
Does unmasking INT_VSYNC without clearing DPU_ONLINE_IRQ_STS first fire a spurious mid-frame vblank interrupt?

As noted in saturn_hee_irq_enable(), DPU_ONLINE_IRQ_STS latches status bits while masked and fires as soon as the mask opens, but saturn_hee_irq_enable() only clears INT_UNDERRUN | INT_CFG_RDY:

drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c:saturn_hee_irq_enable() {
	mask = saturn_hee_get_irq_bit(INT_UNDERRUN) |
	       saturn_hee_get_irq_bit(INT_CFG_RDY);
	if (enable) {
		...
		regmap_write(priv->hwdev->regmap,
			     DPU_INT_BASE_ADDR + DPU_ONLINE_IRQ_STS, mask);
	}
}

Whenever vblank has been disabled while the CRTC is running, the next frame latches INT_VSYNC in DPU_ONLINE_IRQ_STS. Re-enabling vblank then immediately raises an interrupt mid-frame, incrementing the software vblank counter with a mid-frame timestamp or completing an event armed by INT_CFG_RDY in the same ISR call before the actual vblank.

[ ... ]

Quoted 25 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +25 -0
+	drm_mode_config_reset(drm);
+
+	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to initialize vblank\n");
+		goto err_unbind_all;
+	}
+
+	drmm_kms_helper_poll_init(drm);
+	drm_helper_hpd_irq_event(drm);
+
+	enable_irq(priv->irq_online);
+
+	ret = drm_dev_register(drm, 0);
+	if (ret < 0)
+		goto err_disable_irq;
+	drm_client_setup(drm, NULL);
+
+	return 0;
+
+err_disable_irq:
+	disable_irq(priv->irq_online);
+
+err_unbind_all:
+	component_unbind_all(dev, drm);

drivers/gpu/drm/spacemit/spacemit_crtc.c line 405

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10 -0
+err_dc:
+	/*
+	 * .shutdown tests priv->ddev; never leave it on a half-initialised
+	 * device.
+	 */
+	priv->ddev = NULL;
+	priv->a_crtc = NULL;
+	drm_dev_put(drm);
+	return ret;
+}

[Severity: Medium]
Does calling drm_mode_config_reset() before drm_vblank_init() leave vblank->inmodeset unset while the CRTC is initially disabled?

drm_mode_config_crtc_create_state() only calls drm_crtc_vblank_reset() when drm_dev_has_vblank() is true, which requires dev->num_crtcs to have been set by drm_vblank_init(). With the current order, drm_vblank_get() on the disabled CRTC succeeds instead of returning -EINVAL and enables vblank while the DPU is powered off. Calling drm_vblank_init() before drm_mode_config_reset() avoids this.

[Severity: Medium]
If drm_dev_register() fails, does err_disable_irq unbind the components while output polling is still active?

drmm_kms_helper_poll_init() and drm_helper_hpd_irq_event() start output polling before drm_dev_register(), but the error path runs component_unbind_all() before drm_dev_put() invokes the drmm poll release action, unlike spacemit_drm_master_unbind() which calls drm_kms_helper_poll_fini() before component_unbind_all().

[ ... ]

Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +0 -0
new file mode 100644
index 0000000000000..c49a2e1572771
@@ -0,0 +1,332 @@

[ ... ]

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +10 -0
+static void spacemit_plane_atomic_update(struct drm_plane *plane,
+					 struct drm_atomic_commit *state)
+{
+	struct drm_plane_state *new_state =
+			drm_atomic_get_new_plane_state(state, plane);
+	struct drm_crtc_state *crtc_state =
+			drm_atomic_get_new_crtc_state(state, new_state->crtc);
+	struct spacemit_drm_private *priv = plane->dev->dev_private;
+	int idx;
+

drivers/gpu/drm/spacemit/spacemit_planes.c line 151

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_planes.c new file +10 -0
+	if (priv->clocks_on && drm_dev_enter(plane->dev, &idx)) {
+		/* A plane moved off the screen has no rectangle to program. */
+		if (new_state->visible)
+			spacemit_plane_program(plane, new_state,
+					       &crtc_state->adjusted_mode);
+		else
+			spacemit_plane_off(plane, new_state->crtc);
+		drm_dev_exit(idx);
+	}
+}

[Severity: Medium]
When a CRTC is enabled with no visible plane (disabled or clipped off-screen), do the composer output dimensions CMPS_X_REG dst_w and dst_h remain at 0?

saturn_init_regs() enables CMPS_X_REG (module_enable = 1) and saturn_hee_conf_dpuctrl() sets POSTPIPE_REG m_inwidth and m_inheight to mode->hdisplay and mode->vdisplay, but CMPS_X_REG dst_w and dst_h are only written in saturn_hee_plane_update_hw_channel():

drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c:saturn_hee_plane_update_hw_channel() {
	...
	base = CMP1_BASE_ADDR;
	dpu_write(hwdev, CMPS_X_REG, base, dst_w, mode->hdisplay, cl_cmp);
	dpu_write(hwdev, CMPS_X_REG, base, dst_h, mode->vdisplay, cl_cmp);
	...
}

Skipping spacemit_plane_program() when new_state->visible is false leaves the composer configured for a 0x0 output feeding a full-mode postpipe and timing generator, causing a pipeline dimension mismatch and display underrun.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
maintainer
#15 lore raw

Re: [PATCH v3 10/17] drm/spacemit: add Saturn DPU KMS pipeline

In reply to Cody Kang

Hi,

Quoted 34 lines · On Sat, Nov 21, 2026 at 03:40:49PM +0800, Cody Kang via B4 Relay wrote:
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +34 -0
+static int spacemit_drm_master_bind(struct device *dev)
+{
+	struct spacemit_drm_private *priv = dev_get_drvdata(dev);
+	struct spacemit_crtc *a_crtc;
+	struct drm_device *drm;
+	int ret;
+
+	ret = aperture_remove_all_conflicting_devices(spacemit_drm_drv.name);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to remove existing framebuffers\n");
+
+	/*
+	 * Bind-scoped, not devm: the aggregate can rebind without this
+	 * device being re-probed, and each bind must release its own
+	 * drm_device.
+	 */
+	drm = drm_dev_alloc(&spacemit_drm_drv, dev);
+	if (IS_ERR(drm))
+		return PTR_ERR(drm);
+	priv->ddev = drm;
+	drm->dev_private = priv;
+
+	ret = spacemit_drm_mode_config_init(drm);
+	if (ret)
+		goto err_dc;
+
+	a_crtc = spacemit_drm_pipeline_init(drm);
+	if (IS_ERR(a_crtc)) {
+		ret = PTR_ERR(a_crtc);
+		goto err_dc;
+	}
+	priv->a_crtc = a_crtc;
+

drivers/gpu/drm/spacemit/spacemit_crtc.c line 371

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10 -0
+	/*
+	 * component_bind_all() unbinds what it bound before returning an error.
+	 */
+	ret = component_bind_all(dev, drm);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to bind all components\n");
+		goto err_dc;
+	}
+
+	drm_mode_config_reset(drm);

You need to use drm_mode_config_create_initial_state().

Maxime

author
#16 lore raw

Re: [PATCH v3 10/17] drm/spacemit: add Saturn DPU KMS pipeline

Hi Maxime,

Quoted 2 lines · Maxime Ripard
Quoted 1 line · On Sat, Nov 21, 2026 at 03:40:49PM +0800, Cody Kang via B4 Relay wrote:

+static int spacemit_drm_master_bind(struct device *dev)

[...]

Quoted 3 lines

drivers/gpu/drm/spacemit/spacemit_crtc.c line 371

Quoted 1 line
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +1 -0
+	drm_mode_config_reset(drm);

You need to use drm_mode_config_create_initial_state().

Thanks for the review. Will fix in v4.

Cody

author
#17 lore raw

PATCH v3 11/17 drm/spacemit: add Saturn DPU DRM device driver

In reply to Cody Kang

From: Cody Kang <[email protected]>

Add the DRM device for the SpacemiT K3 Saturn display processing unit and hook the driver up to the build. The SoC has two DPU instances; each drives one CRTC that scans out a single primary plane in linear RGB at up to 3840x2160@60 and feeds a downstream DP/eDP controller over an OF-graph endpoint. Buffers use drm_gem_shmem_helper. The AFBC/compressed decode path is not exposed and writeback is not implemented.

The write-combining mapping of the scanout buffers is from Sarah Emery <[email protected]>.

---
v3:
- map scanout buffers write-combining (Sarah Emery); build the sg table when a dumb buffer is created, so the zeroes it was cleared with are written back before anything is drawn
- bound framebuffers by what the RDMA registers can address instead of by the largest mode (Icenowy Zheng)
- stop the component match loop on the first error; depend on PM
- add a GEM object wrapper carrying the display MMU table (Thomas Zimmermann)
v2:
- check for an ERR_PTR component match before component_master_add_with_match() (Sashiko)
- add a comment explaining why commit_tail waits for flip_done before commit_hw_done (Sashiko)

---
 drivers/gpu/drm/Kconfig                 |   1 +
 drivers/gpu/drm/Makefile                |   1 +
 drivers/gpu/drm/spacemit/Kconfig        |  18 +++
 drivers/gpu/drm/spacemit/Makefile       |  12 ++
 drivers/gpu/drm/spacemit/spacemit_drm.c | 204 ++++++++++++++++++++++++++++++++
 5 files changed, 236 insertions(+)
drivers/gpu/drm/Kconfig +1 -0
index 61111d50b1c65..76abdfb25dc44 100644
@@ -345,6 +345,7 @@ source "drivers/gpu/drm/renesas/Kconfig"
 source "drivers/gpu/drm/rockchip/Kconfig"
 source "drivers/gpu/drm/sitronix/Kconfig"
 source "drivers/gpu/drm/solomon/Kconfig"
+source "drivers/gpu/drm/spacemit/Kconfig"
 source "drivers/gpu/drm/sprd/Kconfig"
 source "drivers/gpu/drm/sti/Kconfig"
 source "drivers/gpu/drm/stm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 2c6bc093a923a..d0ef32d224382 100644
@@ -204,6 +204,7 @@ obj-$(CONFIG_DRM_MSM) += msm/
 obj-$(CONFIG_DRM_TEGRA) += tegra/
 obj-$(CONFIG_DRM_STM) += stm/
 obj-$(CONFIG_DRM_STI) += sti/
+obj-$(CONFIG_DRM_SPACEMIT) += spacemit/
 obj-y 			+= imx/
 obj-$(CONFIG_DRM_INGENIC) += ingenic/
 obj-$(CONFIG_DRM_LOGICVC) += logicvc/
drivers/gpu/drm/spacemit/Kconfig new file +18 -0
new file mode 100644
index 0000000000000..8326a7b98151a
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config DRM_SPACEMIT
+	tristate "DRM support for SpacemiT display controllers"
+	depends on DRM && OF && MMU
+	depends on PM
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	select DRM_CLIENT_SELECTION
+	select DRM_KMS_HELPER
+	select DRM_GEM_SHMEM_HELPER
+	select REGMAP_MMIO
+	help
+	  Choose this option if you have a SpacemiT SoC with the Saturn
+	  display processing unit, such as the K3. The DPU scans out
+	  framebuffers through its private display MMU and feeds a
+	  DisplayPort or embedded DisplayPort controller.
+
+	  If M is selected the module will be called spacemit-drm.
drivers/gpu/drm/spacemit/Makefile new file +12 -0
new file mode 100644
index 0000000000000..b3b148000cf7b
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+spacemit-drm-y := spacemit_drm.o \
+		  spacemit_crtc.o \
+		  spacemit_cmdlist.o \
+		  spacemit_planes.o \
+		  spacemit_dmmu.o \
+		  dpu/dpu_saturn.o \
+		  dpu/dpu_saturn_hee.o \
+		  dpu/saturn_fbcmem.o
+
+obj-$(CONFIG_DRM_SPACEMIT) += spacemit-drm.o
drivers/gpu/drm/spacemit/spacemit_drm.c new file +204 -0

204 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#18 lore raw

PATCH v3 12/17 drm/spacemit: add Innosilicon DP/eDP controller bridge driver

In reply to Cody Kang

From: Cody Kang <[email protected]>

Add the DP/eDP controller that sits downstream of the Saturn DPU. Two identical instances share one compatible; the eDP-vs-DP role is board wiring, so it is taken from the devicetree: an eDP panel always sits under an aux-bus child node, an external DP connector never does.

The link rate is set through the generic PHY framework and the pixel rate through the clock the PHY registers, so the controller programs no PLL. It only sets the power-down bits of the two PLLs when it shuts the link down or resets the block.

The controller's HPD interrupt is gated by the DP pixel clock, which can be off exactly when a plug has to be caught, so the connector is also polled and the interrupt path re-reads the live level when it does fire.

The check that fails AUX transfers fast while HPD is low is from Sarah Emery <[email protected]>.

---
v3:
- fail AUX transfers fast when HPD is low (Sarah Emery)
- narrow the link after a failed training and read the EDID with drm_edid_read_ddc(); clear a stale AUX reply before a transfer and hold the AUX mutex across the AUX resets; drop the mode_config.mutex wrap, the external pixel clock path and the unused stream formats
- join the DRM device only once the eDP panel has probed
- let the panel supply the modes on eDP (Guodong Xu)
- use drm_dbg() (Thomas Zimmermann)
- commit message: the controller does set the PLL power-down bits v2:
- use devm_reset_control_get_exclusive_deasserted(), dropping the manual deassert/assert paths and the reset field (Philipp Zabel)
- hand the pxclk disable to a devm action registered after the PHY child is populated (Yao Zi)
- drop the dead NULL-clk guards (Yao Zi)
- drop the error message duplicated by devm_request_threaded_irq() (Yao Zi)
- ack the W1C DP_GENERAL_INTERRUPT bits with plain writes (Sashiko)
- return IRQ_HANDLED when the ISR consumed an HPD latch instead of IRQ_NONE (Sashiko)
- read EDID blocks through the aux I2C adapter (Sashiko)
- drop DRM_BRIDGE_OP_MODES from the DP branch (Sashiko)
- respond to Rob Herring's suggestion, port@1 required, compute possible_crtcs from the input endpoint only

---
 drivers/gpu/drm/spacemit/Kconfig            |   19 +
 drivers/gpu/drm/spacemit/Makefile           |    3 +
 drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2186 +++++++++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_inno_dp.h |  328 ++++
 4 files changed, 2536 insertions(+)
drivers/gpu/drm/spacemit/Kconfig +19 -0
index 8326a7b98151a..4667cb624401a 100644
@@ -16,3 +16,22 @@ config DRM_SPACEMIT
 	  DisplayPort or embedded DisplayPort controller.
 
 	  If M is selected the module will be called spacemit-drm.
+
+config SPACEMIT_INNO_DP
+	tristate "SpacemiT Innosilicon DP/eDP controller support"
+	depends on DRM_SPACEMIT
+	imply PHY_SPACEMIT_K3_INNO_DP
+	select GENERIC_PHY
+	select DRM_PANEL_BRIDGE
+	select DRM_BRIDGE_CONNECTOR
+	select DRM_DISPLAY_HELPER
+	select DRM_DISPLAY_DP_HELPER
+	select DRM_DISPLAY_DP_AUX_BUS
+	help
+	  Choose this option to enable the Innosilicon DisplayPort /
+	  embedded DisplayPort transmitter integrated in SpacemiT SoCs.
+	  The controller sits downstream of the Saturn DPU and drives an
+	  eDP panel (discovered over the DP AUX bus) or an external
+	  DisplayPort connector.
+
+	  If M is selected the module will be called spacemit-inno-dp.
drivers/gpu/drm/spacemit/Makefile +3 -0
index b3b148000cf7b..260d316a271b5 100644
@@ -9,4 +9,7 @@ spacemit-drm-y := spacemit_drm.o \
 		  dpu/dpu_saturn_hee.o \
 		  dpu/saturn_fbcmem.o
 
+spacemit-inno-dp-y := spacemit_inno_dp.o
+
 obj-$(CONFIG_DRM_SPACEMIT) += spacemit-drm.o
+obj-$(CONFIG_SPACEMIT_INNO_DP) += spacemit-inno-dp.o
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2186 -0

2,186 lines not on this page · raw message

drivers/gpu/drm/spacemit/spacemit_inno_dp.h new file +328 -0

328 lines not on this page · raw message

Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH v3 12/17] drm/spacemit: add Innosilicon DP/eDP controller bridge driver

Thank you for your contribution! Sashiko AI review found 13 potential issues to consider: - [High] drm/spacemit: missing pre-emphasis shift in spacemit_dp_link_apply_adjust() - [High] drm/spacemit…

Thank you for your contribution! Sashiko AI review found 13 potential issues to consider:
- [High] drm/spacemit: missing pre-emphasis shift in spacemit_dp_link_apply_adjust()
- [High] drm/spacemit: reset in spacemit_dp_dev_init() desyncs cached PREPLL clk rate
- [Medium] drm/spacemit: broken HPD IRQ notify in spacemit_dp_hotplug_event_handler()
- [Medium] drm/spacemit: fallback caps in spacemit_dp_hw_read_sink_caps() block retry
- [Medium] drm/spacemit: missing hw disable in spacemit_dp_unregister() and bind()
- [Medium] drm/spacemit: missing spacemit_dp_hw_disable() on bind init failure
- [Medium] drm/spacemit: pixel clock truncation to MHz in TU and HBLANK calculation
- [Medium] drm/spacemit: unacknowledged level-high HPD IRQ in spacemit_dp_irq_handler()
- [Medium] drm/spacemit: unlocked dp->link and dp->dpcd reads in mode_valid and check
- [Medium] drm/spacemit: AUX registered before init and MPLL reset without hw_mutex
- [Medium] drm/spacemit: pixel PLL left powered down on untrained link in atomic_enable
- [Medium] drm/spacemit: nested AUX retries and fallback in spacemit_dp_aux_transfer()
- [Medium] drm/spacemit: spacemit_dp_remove() runs before devm AUX bus depopulation
--

commit a1a5915e82d2de32d9e2fe7095172a35686df3b2
Author: Cody Kang <[email protected]>

drm/spacemit: add Innosilicon DP/eDP controller bridge driver

This commit adds the DRM bridge driver for the Innosilicon DisplayPort and embedded DisplayPort controller downstream of the SpacemiT Saturn DPU.

Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0 -0
new file mode 100644
index 0000000000000..436e5f15b4039

[ ... ]

Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +9 -0
+	ret = regmap_read_poll_timeout(dp->regs, DP_GENERAL_INTERRUPT, val,
+				       val & DP_AUX_REPLY_EVENT_INT_STA,
+				       SPACEMIT_DP_AUX_POLL_US,
+				       SPACEMIT_DP_AUX_TIMEOUT_US);
+	if (ret) {
+		if (retries < SPACEMIT_DP_AUX_MAX_RETRIES) {
+			retries++;
+			spacemit_dp_aux_hw_reset(dp);
+			dev_dbg(dp->dev,

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 354

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+				"AUX timeout, cmd=0x%x addr=0x%x size=%zu retry %d/%d\n",
+				cmd, msg->address, msg->size, retries, SPACEMIT_DP_AUX_MAX_RETRIES);
+			goto retry_eio;
+		}
+
+		dev_err_ratelimited(dp->dev,
+				    "AUX transfer timeout, req: 0x%x, cmd: 0x%x, addr: 0x%x, size %zu\n",
+				    msg->request, cmd, msg->address, msg->size);
+		return ret;
+	}

[Severity: Medium]
Does retrying timed-out transfers inside spacemit_dp_aux_transfer() compound with the DRM DP helpers and spacemit_dp_hw_read_sink_caps() to stall for over two minutes under dp->mode_lock?

Each timed-out spacemit_dp_aux_transfer() call waits 4 * 200 ms (~813 ms). drm_dp_dpcd_access() retries negative errors 32 times, drm_dp_dpcd_read_data() falls back to a second 32-retry probe via drm_dp_dpcd_readb(), and spacemit_dp_hw_read_sink_caps() loops SPACEMIT_DP_SINK_READY_RETRIES (3) times, multiplying a single unresponsive sink into 768 consecutive 200 ms timeouts (~156 seconds) while holding dp->mode_lock or component bind locks.

This is also reachable on eDP during spacemit_dp_bind(), which checks spacemit_dp_hw_detect_hpd() and calls spacemit_dp_hw_read_sink_caps() even though DP_HPD_IN_STATUS is not meaningful on eDP and the panel is powered off until atomic_pre_enable; when that read fails, the non-zero fallback limits set by spacemit_dp_hw_read_sink_caps() prevent spacemit_dp_bridge_atomic_enable() from re-reading DPCD once the panel is powered.

[ ... ]

Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2 -0
+static void spacemit_dp_hw_read_sink_caps(struct spacemit_dp_dev *dp)
+{

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 484

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+	if (ret < 0) {
+		drm_warn_ratelimited(dp->drm,
+				     "failed to read DPCD after %d retries: %zd\n",
+				     SPACEMIT_DP_SINK_READY_RETRIES, ret);
+		dp->link.revision = DP_DPCD_REV_14;
+		dp->link.max_rate = SPACEMIT_DP_LINK_RATE_5_40;
+		dp->link.max_num_lanes = SPACEMIT_DP_LANE_2;
+		dp->link.enhanced_framing = 1;
+		return;
+	}

[Severity: Medium]
Does populating non-zero fallback values in dp->link.max_rate and dp->link.max_num_lanes when spacemit_dp_hw_read_sink_caps() fails prevent spacemit_dp_bridge_atomic_enable() from retrying the DPCD read?

spacemit_dp_bridge_atomic_enable() only retries spacemit_dp_hw_read_sink_caps() when !dp->link.max_rate || !dp->link.max_num_lanes. If an earlier DPCD read at bind or detect time fails (for example, on eDP during spacemit_dp_bind() when noisy DP_HPD_IN_STATUS reads high before the panel is powered, or on a slow-waking monitor), max_rate and max_num_lanes are set to 5.4 Gbps and 2 lanes while dp->dpcd remains zeroed or stale. The enable-time retry is then skipped, clamping 4-lane panels or monitors to 2 lanes and running link training without valid dp->dpcd capability bytes (such as TPS3 support).

[ ... ]

Quoted 24 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +24 -0
+static int spacemit_dp_link_apply_adjust(struct spacemit_dp_dev *dp,
+					 const u8 *link_status,
+				    enum spacemit_dp_lane_count lanes,
+				    u8 *training_set)
+{
+	union phy_configure_opts opts = {
+		.dp = {
+			.lanes = lanes,
+			.set_voltages = true,
+		},
+	};
+	int i, ret;
+
+	for (i = 0; i < lanes; i++) {
+		u8 v = drm_dp_get_adjust_request_voltage(link_status, i);
+		u8 p = drm_dp_get_adjust_request_pre_emphasis(link_status, i);
+		u8 v_bits;
+
+		if (v >= SPACEMIT_DP_SWING_MAX)
+			v = SPACEMIT_DP_SWING_MAX;
+		if (p >= SPACEMIT_DP_PREEMP_MAX)
+			p = SPACEMIT_DP_PREEMP_MAX;
+
+		opts.dp.voltage[i] = v;

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 735

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+		opts.dp.pre[i] = p;
+
+		v_bits = v;
+		if (v == SPACEMIT_DP_SWING_MAX)
+			v_bits |= DP_TRAIN_MAX_SWING_REACHED;
+		if (p == SPACEMIT_DP_PREEMP_MAX)
+			v_bits |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
+
+		training_set[i] = v_bits | (p << DP_TRAIN_PRE_EMPHASIS_SHIFT);
+	}

[Severity: High]
Isn't the return value of drm_dp_get_adjust_request_pre_emphasis() already shifted left by DP_TRAIN_PRE_EMPHASIS_SHIFT (3)?

For pre-emphasis levels 1, 2 and 3, drm_dp_get_adjust_request_pre_emphasis() returns 8, 16 and 24. Comparing p >= SPACEMIT_DP_PREEMP_MAX (2) without shifting right by DP_TRAIN_PRE_EMPHASIS_SHIFT first causes any request for pre-emphasis level 1 to be clamped to level 2, marked with DP_TRAIN_MAX_PRE_EMPHASIS_REACHED, and shifted a second time when building training_set[i].

[ ... ]

Quoted 21 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +21 -0
+static void spacemit_dp_hw_set_msa_and_enable_video(struct spacemit_dp_dev *dp,
+						    const struct drm_display_mode *mode,
+						    enum spacemit_dp_link_rate rate,
+						    enum spacemit_dp_lane_count lanes)
+{
+	u64 hb_num;
+	u32 link_rate;
+	u32 fp; /* Pixel clock in MHz */
+	u32 tu, tu_frac, tu_int, rd_thres;
+	u32 hsync_len, hstart, vstart;
+
+	/* mode->clock unit is kHz, fp unit is MHz */
+	fp = mode->clock / 1000;
+
+	if (fp == 0)
+		fp = 1; /* Prevent division by zero */
+
+	/*
+	 * HBlank interval = (htotal - hactive) * (LinkSymbolClock / 4) /
+	 * PixelClock, where LinkSymbolClock = LinkRate * 100 (1.62G -> 162MHz).
+	 * rate is in kbit/s, so link_rate = rate / 10000 gives the 162, 270,

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 906

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+	 * 540 form used below.
+	 */
+	link_rate = rate / 10000;
+
+	/* Multiply before dividing: hb_num = hblank * (link_rate / 4) / fp */
+	hb_num = (u64)(mode->htotal - mode->hdisplay) * link_rate;
+	do_div(hb_num, 4 * fp);
+
+	/* Transfer unit: tu = fp * bpp * 640 / (8 * lanes * link_rate) */
+	tu = div_u64((u64)fp * SPACEMIT_DP_BPP * 640, 8 * lanes * link_rate);

[Severity: Medium]
Does truncating mode->clock to integer MHz in fp underestimate the transfer unit size for fractional-MHz pixel clocks?

spacemit_dp_set_plls() programs dp->pll_clk to mode->clock * 1000 Hz, so a 1080p60 mode runs at 148.5 MHz (and 720p60 at 74.25 MHz), whereas fp = mode->clock / 1000 truncates those clocks to 148 MHz and 74 MHz. For 1080p60 on 2 lanes at 2.7 Gbps, this programs a TU of 52.6 instead of 52.8, packing fewer bytes per TU than the pixel clock delivers into the video FIFO. Using mode->clock in kHz and rate / 10 directly avoids the truncation.

[ ... ]

Quoted 15 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +15 -0
+static enum drm_mode_status
+spacemit_dp_bridge_mode_valid(struct drm_bridge *bridge,
+			      const struct drm_display_info *info,
+			 const struct drm_display_mode *mode)
+{
+	struct spacemit_dp_dev *dp = container_of(bridge,
+						  struct spacemit_dp_dev,
+						  bridge);
+	unsigned int max_link_rate, max_lanes;
+	u64 max_bw, req_bw;
+
+	/*
+	 * Prefer the link limits the driver maintains: they start as the
+	 * sink's capabilities clamped to the PHY and are narrowed after a
+	 * failed training. drm_dp_max_link_rate() is in 10 kbit/s.

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1194

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+	 */
+	if (dp->link.max_rate && dp->link.max_num_lanes) {
+		max_link_rate = dp->link.max_rate / 10;
+		max_lanes = dp->link.max_num_lanes;
+	} else {
+		max_link_rate = min_t(unsigned int,
+				      drm_dp_max_link_rate(dp->dpcd),
+				      SPACEMIT_DP_SOURCE_MAX_RATE / 10);
+		max_lanes = drm_dp_max_lane_count(dp->dpcd);
+	}

[Severity: Medium]
Can spacemit_dp_bridge_mode_valid() and spacemit_dp_bridge_atomic_check() race with concurrent updates to dp->link and dp->dpcd?

spacemit_dp_hw_read_sink_caps() and spacemit_dp_link_narrow() update dp->dpcd, dp->link.max_rate and dp->link.max_num_lanes under dp->mode_lock from the hotplug IRQ thread (spacemit_dp_hotplug_event_handler()) and from non-blocking atomic commits (spacemit_dp_bridge_atomic_enable()), neither of which holds the DRM modeset locks. Reading those fields in spacemit_dp_bridge_mode_valid() and spacemit_dp_bridge_atomic_check() without dp->mode_lock can observe a torn rate/lane pair or partially read dp->dpcd bytes.

[ ... ]

Quoted 30 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +30 -0
+	for (trained = false, i = start;
+	     i < ARRAY_SIZE(spacemit_dp_link_priority_table); i++) {
+		u32 capacity;
+
+		cfg = &spacemit_dp_link_priority_table[i];
+
+		/* Source and sink limits */
+		if (cfg->rate > dp->link.max_rate || cfg->lanes > dp->link.max_num_lanes)
+			continue;
+
+		/* Bandwidth requirement */
+		capacity = spacemit_dp_calc_link_capacity(cfg->rate,
+							  cfg->lanes);
+		if (capacity < req_bw)
+			continue;
+
+		drm_dbg(dp->drm, "trying link config: rate %d lanes %d (capacity %d, required %d)\n",
+			cfg->rate, cfg->lanes, capacity, req_bw);
+
+		spacemit_dp_link_disable(dp);
+
+		/* Apply Hardware Settings */
+		if (spacemit_dp_set_plls(dp, cfg->rate, adjusted_mode->clock))
+			continue;
+
+		if (spacemit_dp_phy_set_lanes(dp, cfg->lanes))
+			continue;
+
+		if (spacemit_dp_phy_on(dp))
+			continue;

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1346

Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6 -0
+	/*
+	 * The DPU's pixel clock comes from the PHY PLL, so scanning out into an
+	 * untrained link never reaches CFG_RDY and wedges the CRTC on
+	 * flip_done.
+	 */
+	if (!trained) {

[Severity: Medium]
Can the !trained path in spacemit_dp_bridge_atomic_enable() return with the PHY pixel PLL powered down and stall the DPU commit?

When dp->link.max_rate or dp->link.max_num_lanes was 0 during atomic_check() and the enable-time DPCD read yields limits below req_bw, every entry in spacemit_dp_link_priority_table is skipped before spacemit_dp_set_plls() or spacemit_dp_phy_on() is called, leaving the PHY powered off from spacemit_dp_bind() or spacemit_dp_bridge_atomic_disable(). The same happens if spacemit_dp_set_plls(), spacemit_dp_phy_set_lanes() or spacemit_dp_phy_on() fails after spacemit_dp_link_disable(). Because the DPU gets its pixel clock from dp->pll_clk, returning with PREPLL powered down prevents the DPU from latching CFG_RDY and stalls drm_atomic_helper_wait_for_flip_done() until the 3000 ms SATURN_CFG_RDY_TIMEOUT_MS timeout expires.

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1527

Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +8 -0
+static irqreturn_t spacemit_dp_irq_handler(int irq, void *data)
+{
+	struct spacemit_dp_dev *dp = data;
+	irqreturn_t ret = IRQ_NONE;
+	int idx;
+
+	if (!drm_dev_enter(dp->drm, &idx))
+		return IRQ_NONE;

[Severity: Medium]
What happens if a level-high HPD interrupt fires after drm_dev_unplug() during master unbind?

In spacemit_drm_master_unbind(), drm_dev_unplug() runs before drm_kms_helper_poll_fini(), drm_atomic_helper_shutdown() and component_unbind_all(). Once drm_dev_unplug() marks the device unplugged, drm_dev_enter() in spacemit_dp_irq_handler() returns false and the handler exits with IRQ_NONE without calling spacemit_dp_hw_clean_hpd() to clear the level-triggered interrupt latch, causing a hardirq storm until spacemit_dp_unbind() calls disable_irq().

[ ... ]

Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +8 -0
+static irqreturn_t spacemit_dp_hotplug_event_handler(int irq, void *data)
+{
+	struct spacemit_dp_dev *dp = data;
+	enum drm_connector_status status;
+	int idx;
+
+	if (!drm_dev_enter(dp->drm, &idx))
+		return IRQ_HANDLED;

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1569

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+
+	/*
+	 * .detect() owns mode_lock and re-reads the sink caps on a fresh plug
+	 */
+	status = spacemit_dp_bridge_detect(&dp->bridge, dp->connector);
+	drm_bridge_hpd_notify(&dp->bridge, status);
+
+	drm_dev_exit(idx);
+	return IRQ_HANDLED;
+}

[Severity: Medium]
Does drm_bridge_hpd_notify() ever notify DRM on external DisplayPort hotplug interrupts?

In spacemit_dp_probe(), external DP sets dp->bridge.ops to DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID without DRM_BRIDGE_OP_HPD. Because drm_bridge_connector_init() only registers an HPD callback on a bridge with DRM_BRIDGE_OP_HPD set, dp->bridge.hpd_cb is NULL and drm_bridge_hpd_notify() is a no-op. Moreover, calling spacemit_dp_bridge_detect() here updates dp->connector_status without updating dp->connector->status, so an unplug-and-replug while the pixel clock is running between 10-second poll intervals leaves both statuses as connector_status_connected and drops the hotplug event and EDID re-read.

[ ... ]

Quoted 2 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2 -0
+static int spacemit_dp_dev_init(struct spacemit_dp_dev *dp)
+{

[ ... ]

Quoted 12 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +12 -0
+	/* Reset Controller and PHY */
+	regmap_write_bits(dp->regs, DP_SOFT_RESET, DP_CONTROLLER_RESET,
+			  FIELD_PREP(DP_CONTROLLER_RESET, 0x1));
+	regmap_write_bits(dp->regs, DP_SOFT_RESET, DP_PHY_RESET,
+			  FIELD_PREP(DP_PHY_RESET, 0x1));
+	regmap_write_bits(dp->regs, DP_SOFT_RESET, DP_HDCP_RESET,
+			  FIELD_PREP(DP_HDCP_RESET, 0x1));
+	regmap_write_bits(dp->regs, DP_SOFT_RESET, DP_AUX_RESET,
+			  FIELD_PREP(DP_AUX_RESET, 0x1));
+	regmap_write_bits(dp->regs, DP_SOFT_RESET, DP_VIDEO_RESET,
+			  FIELD_PREP(DP_VIDEO_RESET, 0x1));
+	usleep_range(5000, 8000);

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1726

Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +11 -0
+	ret = spacemit_dp_set_plls(dp, SPACEMIT_DP_LINK_RATE_2_70, 148500);
+	if (ret)
+		return ret;
+
+	ret = spacemit_dp_phy_set_lanes(dp, SPACEMIT_DP_LANE_2);
+	if (ret)
+		return ret;
+
+	ret = spacemit_dp_phy_on(dp);
+	if (ret)
+		return ret;

[Severity: High]
When spacemit_dp_dev_init() runs a second time in spacemit_dp_bind() on eDP (or on component rebind), does pulsing DP_PHY_RESET wipe the PREPLL registers while clk_set_rate(dp->pll_clk, 148500000) short-circuits in the clock framework?

On eDP, spacemit_dp_probe() calls spacemit_dp_dev_init(), which programs dp->pll_clk to 148.5 MHz, and the PHY clock provider caches that rate. When spacemit_dp_bind() calls spacemit_dp_dev_init() again, asserting DP_PHY_RESET resets the shared PHY PREPLL registers back to hardware defaults, but clk_set_rate(dp->pll_clk, 148500000) sees that the requested rate matches the cached rate and returns without calling the PHY clock's .set_rate callback. spacemit_dp_phy_on() (and later atomic_enable() for any 148.5 MHz mode) then tries to lock an unprogrammed PREPLL.

[ ... ]

Quoted 15 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +15 -0
+static int spacemit_dp_bind(struct device *dev, struct device *master,
+			    void *data)
+{
+	struct spacemit_dp_dev *dp = dev_get_drvdata(dev);
+	struct drm_device *drm = data;
+	struct device_node *ep;
+	int ret;
+
+	dp->drm = drm;
+	dp->aux.drm_dev = drm;
+	ret = drm_dp_aux_register(&dp->aux);
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to register DP AUX\n");
+		goto err_drm;
+	}

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1877

Quoted 3 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +3 -0
+	ret = spacemit_dp_dev_init(dp);
+	if (ret)
+		goto err_encoder;

[Severity: Medium]
Can userspace AUX or DDC transactions race with spacemit_dp_dev_init() and spacemit_dp_set_plls()?

spacemit_dp_bind() calls drm_dp_aux_register(&dp->aux) before spacemit_dp_dev_init(dp), exposing /dev/drm_dp_aux* and the I2C adapter before the controller is initialized on external DP and while spacemit_dp_dev_init() powers down MPLL and asserts DP_CONTROLLER_RESET, DP_PHY_RESET and DP_AUX_RESET without holding dp->aux.hw_mutex. Similarly, in spacemit_dp_bridge_atomic_enable(), spacemit_dp_link_disable() releases dp->aux.hw_mutex before spacemit_dp_set_plls() power-cycles the MPLL that supplies the 16 MHz AUX reference clock.

[Severity: Medium]
If spacemit_dp_dev_init() fails here in spacemit_dp_bind(), should the error path call spacemit_dp_hw_disable(dp) the way spacemit_dp_probe() does?

spacemit_dp_dev_init() enables interrupt masks and powers up the MPLL and PREPLL in spacemit_dp_set_plls() before calling spacemit_dp_phy_set_lanes() and spacemit_dp_phy_on(). Jumping to err_encoder on failure leaves the PLLs powered on, and because dp->component_added is true while bind failed, a later spacemit_dp_remove() will not run spacemit_dp_unbind() or spacemit_dp_hw_disable() either.

[ ... ]

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1973

Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +8 -0
+/* Leave the DRM device, or power down a controller that never joined one. */
+static void spacemit_dp_unregister(struct spacemit_dp_dev *dp)
+{
+	if (dp->component_added)
+		component_del(dp->dev, &spacemit_dp_ops);
+	else
+		spacemit_dp_hw_disable(dp);
+}

[Severity: Medium]
Does spacemit_dp_unregister() leave the hardware powered on when dp->component_added is true but the component master was never bound?

On eDP, spacemit_dp_probe() powers up the MPLL and analog TX blocks via spacemit_dp_dev_init() and spacemit_dp_edp_link_panel() sets dp->component_added = true. If the driver is removed while the aggregate DRM device is unbound (or if spacemit_dp_dev_init() failed during spacemit_dp_bind()), component_del() does not invoke spacemit_dp_unbind(), and the if (dp->component_added) branch skips spacemit_dp_hw_disable(dp). Calling spacemit_dp_hw_disable(dp) unconditionally after component_del() would ensure the PLLs and TX blocks are always powered down.

[ ... ]

Quoted 8 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +8 -0
+	ret = devm_of_dp_aux_populate_bus(&dp->aux, spacemit_dp_edp_link_panel);
+	if (ret) {
+		spacemit_dp_unregister(dp);
+		return dev_err_probe(dev, ret,
+				     "eDP: failed to populate aux-bus panel\n");
+	}
+
+	return 0;

drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2159

Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10 -0
+
+err_disable_pxclk:
+	clk_disable_unprepare(dp->pxclk);
+	return ret;
+}
+
+static void spacemit_dp_remove(struct platform_device *pdev)
+{
+	spacemit_dp_unregister(platform_get_drvdata(pdev));
+}

[Severity: Medium]
On eDP, does spacemit_dp_remove() tear down the component and power down the controller before devres depopulates the AUX bus?

devm_of_dp_aux_populate_bus() registers of_dp_aux_depopulate_bus_void() as a devres action, which runs during devres_release_all() after spacemit_dp_remove() returns. During driver unbind, spacemit_dp_remove() powers down the controller while the AUX-bus child panel device is still registered, and a deferred panel probe completing in that window can still invoke spacemit_dp_edp_link_panel() -> component_add() after spacemit_dp_unregister() has already run:

CPU0 CPU1 (deferred_probe_work_func)
__device_release_driver()
spacemit_dp_remove()

    spacemit_dp_unregister()
      /* dp->component_added is false */
      spacemit_dp_hw_disable()
                                      panel_edp_probe()
                                        spacemit_dp_edp_link_panel()
                                          component_add(dp->dev, ...)
  devres_release_all()
    of_dp_aux_depopulate_bus_void()
    /* dp freed while component remains registered */

Depopulating the AUX bus in spacemit_dp_remove() before spacemit_dp_unregister() (or registering spacemit_dp_unregister() as a devm action prior to devm_of_dp_aux_populate_bus()) avoids this ordering inversion.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
author
#20 lore raw

PATCH v3 13/17 MAINTAINERS: add SpacemiT K3 display driver entry

In reply to Cody Kang

From: Cody Kang <[email protected]>

Cover the Saturn DPU, the Innosilicon DP/eDP controller, the DP PHY and their bindings.

---
v3:
- add Guodong Xu as maintainer
- list Cody Kang with the vsit.ai address
v2:
- no change

---
 MAINTAINERS | 11 +++++++++++
 1 file changed, 11 insertions(+)
MAINTAINERS +11 -0
index 93abbb315065d..7bba82e8cc810 100644
@@ -26364,6 +26364,17 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/sound/spacemit,k1-i2s.yaml
 F:	sound/soc/spacemit/k1_i2s.c
 
+SPACEMIT K3 DISPLAY DRIVER
+M:	Cody Kang <[email protected]>
+M:	Guodong Xu <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/display/spacemit/
+F:	Documentation/devicetree/bindings/phy/spacemit,k3-inno-dp-phy.yaml
+F:	drivers/gpu/drm/spacemit/
+F:	drivers/phy/spacemit/phy-k3-inno-dp.c
+
 SPACEMIT RESET CONTROLLER DRIVER
 M:	Guodong Xu <[email protected]>
 L:	[email protected]
Signature · 1 line
2.43.0
author
#21 lore raw

PATCH v3 14/17 riscv: dts: spacemit: k3: add display nodes

In reply to Cody Kang

From: Cody Kang <[email protected]>

Add the SoC-level display nodes: the two Saturn DPUs, the two DP/eDP controllers with their PHY children.

The PHY PLLs feed back into the APMU as pixel-clock mux parents, so list them as clock inputs of the APMU node.

---
v3:
- order the display nodes by unit address
- commit message: reword the sentence about the APMU node v2:
- edp0/dp1: add port@1 with a board-completable endpoint, needed once the binding requires port@1 (Rob Herring, on patch 03)

---
 arch/riscv/boot/dts/spacemit/k3-display.dtsi | 166 +++++++++++++++++++++++++++
 1 file changed, 166 insertions(+)
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +166 -0
new file mode 100644
index 0000000000000..694c6d3c660f7
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * SpacemiT K3 display subsystem (DPU0/eDP0 + DPU1/DP1) shared
+ * device-tree definitions for inclusion alongside k3.dtsi.
+ *
+ * Copyright (C) 2026 SpacemiT Co., Ltd.
+ */
+
+#include <dt-bindings/clock/spacemit,k3-clocks.h>
+#include <dt-bindings/reset/spacemit,k3-resets.h>
+#include <dt-bindings/interrupt-controller/irq.h>
+
+&soc {
+	dpu0_crtc0: dpu@c0340000 {
+		compatible = "spacemit,k3-saturn-dpu";
+		reg = <0x0 0xc0340000 0x0 0x54000>;
+		interrupts = <90 IRQ_TYPE_LEVEL_HIGH>,
+			     <89 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "online", "offline";
+		clocks = <&syscon_apmu CLK_APMU_LCD_PXCLK>,
+			 <&syscon_apmu CLK_APMU_LCD_MCLK>,
+			 <&syscon_apmu CLK_APMU_DPU_ACLK>,
+			 <&syscon_apmu CLK_APMU_DSI_ESC>,
+			 <&syscon_apmu CLK_APMU_LCD_DSC>;
+		clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk";
+		resets = <&syscon_apmu RESET_APMU_LCD_MCLK>,
+			 <&syscon_apmu RESET_APMU_LCD>,
+			 <&syscon_apmu RESET_APMU_DSI_ESC>,
+			 <&syscon_apmu RESET_APMU_DPU_ACLK>,
+			 <&syscon_apmu RESET_APMU_LCD_DSCCLK>;
+		reset-names = "mclk", "lcd", "esc",
+			      "aclk", "dsc";
+		status = "disabled";
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				dpu0_out: endpoint {
+					remote-endpoint = <&edp0_in>;
+				};
+			};
+		};
+	};
+
+	dpu1_crtc0: dpu@c0440000 {
+		compatible = "spacemit,k3-saturn-dpu";
+		reg = <0x0 0xc0440000 0x0 0x54000>;
+		interrupts = <139 IRQ_TYPE_LEVEL_HIGH>,
+			     <138 IRQ_TYPE_LEVEL_HIGH>;
+		interrupt-names = "online", "offline";
+		clocks = <&syscon_apmu CLK_APMU_DSI4LN2_LCD_PXCLK>,
+			 <&syscon_apmu CLK_APMU_DSI4LN2_LCD_MCLK>,
+			 <&syscon_apmu CLK_APMU_DSI4LN2_DPU_ACLK>,
+			 <&syscon_apmu CLK_APMU_DSI4LN2_DSI_ESC>,
+			 <&syscon_apmu CLK_APMU_DSI4LN2_LCD_DSC>;
+		clock-names = "pxclk", "mclk", "aclk", "escclk", "dscclk";
+		resets = <&syscon_apmu RESET_APMU_DSI4LN2_LCD_MCLK>,
+			 <&syscon_apmu RESET_APMU_DSI4LN2_LCD_SW>,
+			 <&syscon_apmu RESET_APMU_DSI4LN2_ESCCLK>,
+			 <&syscon_apmu RESET_APMU_DSI4LN2_DPU_ACLK>,
+			 <&syscon_apmu RESET_APMU_DSI4LN2_LCD_DSCCLK>;
+		reset-names = "mclk", "lcd", "esc",
+			      "aclk", "dsc";
+		status = "disabled";
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				dpu1_out: endpoint {
+					remote-endpoint = <&dp1_in>;
+				};
+			};
+		};
+	};
+
+	edp0: edp@cac84000 {
+		compatible = "spacemit,k3-inno-dp";
+		reg = <0x0 0xcac84000 0x0 0x4000>;
+		interrupts = <132 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&syscon_apmu CLK_APMU_EDP0_PXCLK>, <&edp0_phy>;
+		clock-names = "pxclk", "pll";
+		resets = <&syscon_apmu RESET_APMU_EDP0>;
+		phys = <&edp0_phy>;
+		phy-names = "dp";
+		status = "disabled";
+
+		edp0_phy: phy {
+			compatible = "spacemit,k3-inno-dp-phy";
+			#phy-cells = <0>;
+			#clock-cells = <0>;
+			clock-output-names = "edp0_pll_pxclk";
+		};
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				edp0_in: endpoint {
+					remote-endpoint = <&dpu0_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				edp0_out: endpoint {
+				};
+			};
+		};
+	};
+
+	dp1: dp@cac88000 {
+		compatible = "spacemit,k3-inno-dp";
+		reg = <0x0 0xcac88000 0x0 0x4000>;
+		interrupts = <140 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&syscon_apmu CLK_APMU_EDP1_PXCLK>, <&dp1_phy>;
+		clock-names = "pxclk", "pll";
+		resets = <&syscon_apmu RESET_APMU_EDP1>;
+		phys = <&dp1_phy>;
+		phy-names = "dp";
+		status = "disabled";
+
+		dp1_phy: phy {
+			compatible = "spacemit,k3-inno-dp-phy";
+			#phy-cells = <0>;
+			#clock-cells = <0>;
+			clock-output-names = "edp1_pll_pxclk";
+		};
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				dp1_in: endpoint {
+					remote-endpoint = <&dpu1_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				dp1_out: endpoint {
+				};
+			};
+		};
+	};
+};
+
+/*
+ * Feed the PHY PLL pixel clocks back in as the APMU mux parents. This lives
+ * here, not in k3.dtsi: the PHYs only exist where this file is included.
+ */
+&syscon_apmu {
+	clocks = <&osc_32k>, <&vctcxo_1m>, <&vctcxo_3m>, <&vctcxo_24m>,
+		 <&edp0_phy>, <&dp1_phy>;
+	clock-names = "osc", "vctcxo_1m", "vctcxo_3m", "vctcxo_24m",
+		      "edp0_pll_pxclk", "edp1_pll_pxclk";
+};
Signature · 1 line
2.43.0
author
#22 lore raw

PATCH v3 15/17 riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output

In reply to Cody Kang

From: Cody Kang <[email protected]>

Pico-ITX brings the second DPU's output to a USB Type-C receptacle, as DisplayPort alternate mode. The mux and the PD controller in front of the receptacle are run by the on-board EC and the SoC only gets the HPD line back, so there is no connector node to link the output to. Enable that DPU and the DisplayPort controller it feeds.

---
v3:
- commit message: the output is the Type-C receptacle's DP alternate mode, not a DisplayPort connector (Icenowy Zheng)
v2:
- no change

---
 arch/riscv/boot/dts/spacemit/k3-pico-itx.dts | 11 +++++++++++
 arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 11 +++++++++++
 2 files changed, 22 insertions(+)
arch/riscv/boot/dts/spacemit/k3-pico-itx.dts +11 -0
index dda420900aa2c..da042d7c30328 100644
@@ -6,6 +6,7 @@
 #include <dt-bindings/gpio/gpio.h>
 
 #include "k3.dtsi"
+#include "k3-display.dtsi"
 #include "k3-pinctrl.dtsi"
 
 / {
@@ -368,3 +369,13 @@ &usb3d {
 	phy-names = "usb2-phy", "usb3-phy";
 	status = "okay";
 };
+
+&dpu1_crtc0 {
+	status = "okay";
+};
+
+&dp1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&dp1_1_cfg>;
+	status = "okay";
+};
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
index cb4f4f4e33aff..a3188ca0ceb36 100644
@@ -11,6 +11,17 @@
 #define K3_GPIO(x)	(x / 32) (x % 32)
 
 &pinctrl {
+	/omit-if-no-ref/
+	dp1_1_cfg: dp1-1-cfg {
+		dp1-pins {
+			pinmux = <K3_PADCONF(24, 6)>;	/* dp1 hpd */
+
+			bias-disable;
+			drive-strength = <25>;
+			power-source = <3300>;
+		};
+	};
+
 	gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg {
 		gmac0-rgmii-0-pins {
 			pinmux = <K3_PADCONF(0, 1)>,	/* gmac0_rxdv */
Signature · 1 line
2.43.0
author
#23 lore raw

PATCH v3 16/17 riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output

In reply to Cody Kang

From: Cody Kang <[email protected]>

CoM260-IFX carries a single DisplayPort output. Enable the second DPU and the DisplayPort controller it feeds.

---
v3:
- describe the HPD pad at the 1.8 V it runs at
- commit message: reworded
v2:
- describe the DP receptacle (dp-connector) and link it to dp1 port@1 (Rob Herring, on patch 03)

---
 arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts | 27 ++++++++++++++++++++++++++
 arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi   | 11 +++++++++++
 2 files changed, 38 insertions(+)
arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts +27 -0
index fadcf28389be9..321715d455865 100644
@@ -6,6 +6,7 @@
 #include <dt-bindings/phy/phy.h>
 
 #include "k3-com260.dtsi"
+#include "k3-display.dtsi"
 
 / {
 	model = "SpacemiT K3 CoM260 IFX";
@@ -20,6 +21,18 @@ chosen {
 		stdout-path = "serial0:115200n8";
 	};
 
+	connector {
+		compatible = "dp-connector";
+		label = "DP1";
+		type = "full-size";
+
+		port {
+			dp1_connector_in: endpoint {
+				remote-endpoint = <&dp1_out>;
+			};
+		};
+	};
+
 	reg_hub_5v: regulator-usb3-hub-5v {
 		compatible = "regulator-fixed";
 		regulator-name = "USB30_HUB";
@@ -129,3 +142,17 @@ &sdhci0 {
 	sd-uhs-sdr104;
 	status = "okay";
 };
+
+&dpu1_crtc0 {
+	status = "okay";
+};
+
+&dp1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&dp1_3_cfg>;
+	status = "okay";
+};
+
+&dp1_out {
+	remote-endpoint = <&dp1_connector_in>;
+};
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
index a3188ca0ceb36..ea88ec95b9136 100644
@@ -22,6 +22,17 @@ dp1-pins {
 		};
 	};
 
+	/omit-if-no-ref/
+	dp1_3_cfg: dp1-3-cfg {
+		dp1-pins {
+			pinmux = <K3_PADCONF(72, 4)>;	/* dp1 hpd */
+
+			bias-disable;
+			drive-strength = <25>;
+			power-source = <1800>;
+		};
+	};
+
 	gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg {
 		gmac0-rgmii-0-pins {
 			pinmux = <K3_PADCONF(0, 1)>,	/* gmac0_rxdv */
Signature · 1 line
2.43.0
author
#24 lore raw

PATCH v3 17/17 riscv: defconfig: spacemit: k3: enable display driver

In reply to Cody Kang

From: Cody Kang <[email protected]>

Enable the Saturn DPU and the DP/eDP controller as modules, matching the other DRM drivers in this defconfig; the DP PHY follows through the controller's imply.

---
v3:
- no change
v2:
- no change

---
 arch/riscv/configs/defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/configs/defconfig +2 -0
index 04ae305d5511b..7db411d385582 100644
@@ -194,6 +194,8 @@ CONFIG_VIDEO_CADENCE_CSI2RX=m
 CONFIG_DRM=m
 CONFIG_DRM_RADEON=m
 CONFIG_DRM_NOUVEAU=m
+CONFIG_DRM_SPACEMIT=m
+CONFIG_SPACEMIT_INNO_DP=m
 CONFIG_DRM_SUN4I=m
 CONFIG_DRM_VIRTIO_GPU=m
 CONFIG_FB=y
Signature · 1 line
2.43.0
Tested-by on the v3 series
#26 lore raw
In reply to Cody Kang
Quoted 21 lines · On Sat Nov 21, 2026 at 3:40 PM CST, Cody Kang via B4 Relay wrote:

This series adds display support for the SpacemiT K3 [2], a RISC-V SoC:
a new DRM driver, a new PHY driver and three new bindings.

The display path is three blocks deep:

Saturn DPU -> Innosilicon DP/eDP controller -> Innosilicon DP PHY

New readers will find an introduction to this hardware in the v2 cover letter [3].

In v3, two major changes, thanks to Thomas Zimmermann for the review that led to these:

- The DPU driver lost its internal layers: the callback tables, the tracepoints and the command-list grouping are gone.
- Page-flip events go through the vblank machinery, and the DPU is powered through runtime PM.

The rest of the v3 changes please see below, with details in each patch's changelog.

Quoted 7 lines

v2 ships in the Ubuntu 26.10 RISC-V kernel [4]. Thanks to Sarah Emery for two fixes found there.

Thanks to Ze Huang for testing v2 on the K3 Pico-ITX. The Tested-by is not carried, because the DRM driver changed too much in v3.

Ze, Sarah: if you have time to run v3, a retest would be very welcome.

Thanks for v3. I tested the series based on v7.4-rc1 on the K3 Pico-ITX with an external DisplayPort monitor.

Modesetting and page flipping with modetest work at 1920x1080@144Hz, and kmscube renders correctly using Mesa softpipe.

Quoted 158 lines

Sashiko AI review contributed total review comments: 51 items, which I
accepted: 19 items.

v3 repeated the full v1 test matrix on both boards, in built-in and modular configurations, with the module load/unload rounds of v2, plus page-flip and DPMS rounds and unloading the modules while a client is running.

About the series:

The DPU driver arrives as five staged patches (7 to 11) to keep each one a reasonable size. It becomes buildable with patch 11. Bisect safe.

This series supports a single primary plane per CRTC and linear RGB scanout (no plane scaling, rotation, YUV or writeback). It does not support DSI, DSC or DP audio, and link rates are capped at HBR2.

Based on v7.4-rc1.

Testing this series needs a SpacemiT u-boot carrying display support:
the branch at [1], or a later official release.

Tested on two K3 boards:

- Pico-ITX: an eDP panel and an external DisplayPort monitor.
- CoM260-IFX: DisplayPort only, no eDP.

Note: The eDP panel DTS enablement is not part of this series; a separate
series will follow showing how eDP can be verified.

[1] https://github.com/spacemit-com/uboot-for-k3-display-verify/tree/k3-br-v1.0.y
[2] https://www.spacemit.com/community/document/info?lang=en&nodepath=hardware/key_stone/k3
[3] https://lore.kernel.org/r/[email protected]
[4] https://launchpad.net/ubuntu/+source/linux-riscv/7.2.0-5.5.2

Changes in v3:
- drop the tracepoints, the hardware callback tables and the constant-fill path; the Saturn register code is called directly (Thomas Zimmermann)
- one command list per channel, allocated once and submitted by its owner; the grouping, sorting and chaining of lists is gone (Thomas Zimmermann)
- deliver the commit's event through the vblank machinery, armed from the CFG_RDY interrupt (Thomas Zimmermann)
- power the DPU through runtime PM, and stop the boot loader's pipeline at probe instead of at the first modeset (Thomas Zimmermann)
- add prepare_fb: the display MMU table is built once per GEM object
and the buffer's fences are waited for (Thomas Zimmermann)
- program the plane from the clipped rectangles, and size its line buffer in atomic_check (Thomas Zimmermann)
- wrap only the hardware access in drm_dev_enter() (Thomas Zimmermann); release the drm_device when the aggregate unbinds
- map scanout buffers write-combining; fail AUX transfers fast when HPD is low (Sarah Emery)
- reject modes above 3840x2160, and bound framebuffers by what the RDMA registers can address (Icenowy Zheng)
- let the panel supply the modes on eDP (Guodong Xu)
- leave the DPU's pixel clock at the rate it has; on DP and eDP the PHY PLL is the pixel clock (Guodong Xu)
- do not advertise a gamma table (Guodong Xu)
- DT: order the display nodes by unit address; the Pico-ITX message names the Type-C receptacle's DP alternate mode (Icenowy Zheng)
- clk: the commit message names the binding that documents the two
clock inputs (Jerome Brunet)
- MAINTAINERS: add Guodong Xu as maintainer; list Cody Kang with the vsit.ai address
- rebased onto v7.4-rc1: atomic_create_state replaces .reset
- commit messages of patches 5, 7, 8, 9, 11, 12, 14 and 16 reworded
- picked up Rob Herring's Reviewed-by on patch 4
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- unbind: keep the online IRQ alive until the teardown commits have drained; module unload no longer rides two watchdog timeouts
- bridge teardown on devres: reset via devm_reset_control_get_exclusive_deasserted(), pxclk disable as a
devm action ordered against the PHY child (Philipp Zabel, Yao Zi)
- all five DPU reset lines behind one reset_control_bulk_* pair
(Philipp Zabel, Guodong Xu)
- bindings: port@1 is now required; the CoM260 board describes its DP receptacle with a dp-connector node; redundant minItems dropped
(Rob Herring)
- possible_crtcs derived from the input endpoint only
- EDID reads through the AUX I2C adapter; write-1-to-clear interrupt
acks by plain write; assorted dead code dropped
- picked up Rob Herring's Reviewed-by on patches 1-3
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Cody Kang (17):
dt-bindings: display: spacemit: add K3 Saturn DPU controller
dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
phy: spacemit: add Innosilicon DP TX PHY driver
clk: spacemit: k3: parent eDP/DP pixel clock to the PHY PLL drm/spacemit: add Saturn DPU register model
drm/spacemit: add Saturn DPU core types, cmdlist and display MMU drm/spacemit: add Saturn DPU hardware backend
drm/spacemit: add Saturn DPU KMS pipeline
drm/spacemit: add Saturn DPU DRM device driver drm/spacemit: add Innosilicon DP/eDP controller bridge driver
MAINTAINERS: add SpacemiT K3 display driver entry
riscv: dts: spacemit: k3: add display nodes
riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output
riscv: defconfig: spacemit: k3: enable display driver

 .../display/spacemit/spacemit,k3-inno-dp.yaml      |  141 ++
 .../display/spacemit/spacemit,k3-saturn-dpu.yaml   |  132 ++
 .../bindings/phy/spacemit,k3-inno-dp-phy.yaml      |   48 +
 .../bindings/soc/spacemit/spacemit,k1-syscon.yaml  |   21 +-
 MAINTAINERS                                        |   11 +
 arch/riscv/boot/dts/spacemit/k3-com260-ifx.dts     |   27 +
 arch/riscv/boot/dts/spacemit/k3-display.dtsi       |  166 ++
 arch/riscv/boot/dts/spacemit/k3-pico-itx.dts       |   11 +
 arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi       |   22 +
 arch/riscv/configs/defconfig                       |    2 +
 drivers/clk/spacemit/ccu-k3.c                      |    4 +-
 drivers/gpu/drm/Kconfig                            |    1 +
 drivers/gpu/drm/Makefile                           |    1 +
 drivers/gpu/drm/spacemit/Kconfig                   |   37 +
 drivers/gpu/drm/spacemit/Makefile                  |   15 +
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.c          |  353 ++++
 drivers/gpu/drm/spacemit/dpu/dpu_saturn.h          |   36 +
 drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c      |  670 ++++++
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c       |   66 +
 drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h       |   16 +
 drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h |   25 +
 drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h |   47 +
 .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h |   65 +
 .../drm/spacemit/dpu/saturn_regs/saturn_fields.h   |  312 +++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.c        |  198 ++
 drivers/gpu/drm/spacemit/spacemit_cmdlist.h        |  133 ++
 drivers/gpu/drm/spacemit/spacemit_crtc.c           |  589 ++++++
 drivers/gpu/drm/spacemit/spacemit_crtc.h           |  133 ++
 drivers/gpu/drm/spacemit/spacemit_dmmu.c           |  119 ++
 drivers/gpu/drm/spacemit/spacemit_dmmu.h           |   80 +
 drivers/gpu/drm/spacemit/spacemit_dpu_ids.h        |   26 +
 drivers/gpu/drm/spacemit/spacemit_dpu_reg.h        |   99 +
 drivers/gpu/drm/spacemit/spacemit_drm.c            |  204 ++
 drivers/gpu/drm/spacemit/spacemit_drm.h            |   62 +
 drivers/gpu/drm/spacemit/spacemit_inno_dp.c        | 2186 ++++++++++++++++++++
 drivers/gpu/drm/spacemit/spacemit_inno_dp.h        |  328 +++
 drivers/gpu/drm/spacemit/spacemit_planes.c         |  332 +++
 drivers/phy/spacemit/Kconfig                       |   13 +
 drivers/phy/spacemit/Makefile                      |    1 +
 drivers/phy/spacemit/phy-k3-inno-dp.c              |  951 +++++++++
 40 files changed, 7680 insertions(+), 3 deletions(-)

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260713-k3-display-e8ffed67e936

Best regards,

Signature · 1 line
Cody Kang <[email protected]>
author
#27 lore raw

Hi Ze,

Quoted 7 lines · Ze Huang

Thanks for v3. I tested the series based on v7.4-rc1 on the K3 Pico-ITX with an external DisplayPort monitor.

Modesetting and page flipping with modetest work at 1920x1080@144Hz, and kmscube renders correctly using Mesa softpipe.

Thanks for testing v3.

Cody