drm/spacemit: add SpacemiT K3 display support
Subsystems (7)
v4 cover drm/spacemit: add SpacemiT K3 display support
This series adds display support for the SpacemiT K3 [1], 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 [2].
v4 keeps the structure of v3. After v3 I went through the whole driver again, against the comments that new DRM and PHY drivers usually get on the lists, and tested more on the boards. I also went through every Sashiko report on v3 and those of a local run on an earlier state of
v4: the real bugs are fixed, and false positives are left as they are.
The largest change (measured in lines of code) moves the PHY's analog set-up from the DP controller driver into the PHY driver. The rest is removal (a PLL table, register fields and stores that nothing used, the HPD interrupt handlers) and fixes, most of them in the KMS and DP controller patches (9 and 11).
A note for those who are reviewing v3: patches 1, 4 and 12 are identical in v4, and patches 2, 3, 10 and 13 to 16 differ by a few lines, so comments on those still apply. Patches 5 to 9 and 11 changed; please look at them in v4. Each patch's changelog lists the changes.
One binding changed since Rob Herring's review. Patch 2 adds a "clocks" property to the Innosilicon DP PHY, to accurately reflect hardware. Patch 3's example includes this PHY, so it changed accordingly. I kept his Reviewed-by; please say if it should go.
The clock patch of v3 (patch 6 there) was applied by Jerome Brunet to the clk-spacemit branch of clk/linux.git. It is no longer part of this series, and the patches after it have moved up by one. The display needs that patch at run time, but nothing in this series needs it to build.
v2 ships in the Ubuntu 26.10 RISC-V kernel [3]. Thanks to Sarah Emery for two fixes found there.
Thanks to Ze Huang for testing v3 on the K3 Pico-ITX with an external DisplayPort monitor, and to James Morris for testing v3 on the K3 CoM260-IFX with a DisplayPort monitor.
Their Tested-by tags were given on v3. Because v4 changes this much, I have not carried them over: no patch of v4 has a Tested-by. A retest of v4 would be very welcome.
About the series:
The DPU driver arrives as five staged patches (6 to 10) to keep each one a reasonable size. It becomes buildable with patch 10. 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 drm-misc-next.
Testing this series needs a SpacemiT u-boot carrying display support.
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.
Testing of v4:
The series was tested on both boards on drm-misc-next plus the clock patch, as modules and built in: mode switching, kmscube on each head and on both, DPMS, page flips, module load and unload, DisplayPort hot-plug, and all eleven plane formats on the eDP panel and on a DisplayPort monitor.
IGT 2.4 was also run on both boards. Of the kms tests that apply to this driver, all pass.
[1] https://www.spacemit.com/community/document/info?lang=en&nodepath=hardware/key_stone/k3
[2] https://lore.kernel.org/r/[email protected]
[3] https://launchpad.net/ubuntu/+source/linux-riscv/7.2.0-5.5.2
Changes in v4:
- drop the clk patch, applied by Jerome Brunet; rebased onto drm-misc-next
- create the initial state with drm_mode_config_create_initial_state() (Maxime Ripard)
- build the DP controller into spacemit-drm; use devm_drm_dev_alloc() and the clk bulk API (Guodong Xu)
- set the sink to D0 before link training (James Morris)
- PHY: move the analog set-up here from the DP controller driver, and take the reference clock from the device tree (new "clocks" property in the binding)
- drop the RGB888 and BGR888 plane formats, which make the DPU
underrun, and the HPD interrupt handlers, whose interrupt never fires on the boards
- other fixes: see each patch's changelog
- Link to v3: https://patch.msgid.link/[email protected]
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 (16):
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 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 | 142 ++ .../display/spacemit/spacemit,k3-saturn-dpu.yaml | 132 ++ .../bindings/phy/spacemit,k3-inno-dp-phy.yaml | 54 + .../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 | 168 ++ arch/riscv/boot/dts/spacemit/k3-pico-itx.dts | 11 + arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 22 + arch/riscv/configs/defconfig | 3 + drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/spacemit/Kconfig | 36 + drivers/gpu/drm/spacemit/Makefile | 14 + drivers/gpu/drm/spacemit/dpu/dpu_saturn.c | 276 +++ drivers/gpu/drm/spacemit/dpu/dpu_saturn.h | 34 + drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c | 677 +++++++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c | 57 + drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h | 16 + drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h | 24 + drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h | 42 + .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h | 64 + .../drm/spacemit/dpu/saturn_regs/saturn_fields.h | 286 +++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 188 ++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 133 ++ drivers/gpu/drm/spacemit/spacemit_crtc.c | 667 +++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 125 ++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 127 ++ drivers/gpu/drm/spacemit/spacemit_dmmu.h | 79 + 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 | 203 ++ drivers/gpu/drm/spacemit/spacemit_drm.h | 84 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2046 ++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 ++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 303 +++ drivers/phy/spacemit/Kconfig | 13 + drivers/phy/spacemit/Makefile | 1 + drivers/phy/spacemit/phy-k3-inno-dp.c | 1115 +++++++++++ 39 files changed, 7655 insertions(+), 1 deletion(-)
---
base-commit: 5ce32a0c94a827ff44ee60898c28060714dcff75
change-id: 20260713-k3-display-e8ffed67e936
Best regards,
Signature · 1 line
Cody Kang <[email protected]>
PATCH v4 1/16 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.
---
v4:
- no change
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
@@ -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
[email protected]
AI reviewRe: [PATCH v4 01/16] 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 1d1a07223b3c8334a3622cd2d38585f26ba9223d
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 on the SpacemiT K3 SoC.
Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +0
-0@@ -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 25 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +25
-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";
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml line 112
Quoted 10 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-saturn-dpu.yaml new file +10
-0+ 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 clocks and clock-names are normally listed before interrupts and interrupt-names in the properties, required, and examples sections to match the canonical property order across DT bindings.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v4 2/16 dt-bindings: phy: add SpacemiT K3 Innosilicon DP PHY
In reply to Cody KangFrom: 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. The reference of its two PLLs is a clock input.
---
v4:
- add the reference clock input and require it
v3:
- no change
v2:
- add Reviewed-by: Rob Herring (Arm)
--- .../bindings/phy/spacemit,k3-inno-dp-phy.yaml | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+)
Documentation/devicetree/bindings/phy/spacemit,k3-inno-dp-phy.yaml new file +54 -0
@@ -0,0 +1,54 @@ +# 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 + + clocks: + items: + - description: 24 MHz reference clock of the link and pixel PLLs. + + "#phy-cells": + const: 0 + + "#clock-cells": + const: 0 + + clock-output-names: + maxItems: 1 + +required: + - compatible + - clocks + - "#phy-cells" + - "#clock-cells" + +additionalProperties: false + +examples: + - | + phy { + compatible = "spacemit,k3-inno-dp-phy"; + clocks = <&vctcxo_24m>; + #phy-cells = <0>; + #clock-cells = <0>; + clock-output-names = "edp0_pll_pxclk"; + };
Signature · 1 line
2.43.0
PATCH v4 3/16 dt-bindings: display: spacemit: add K3 Innosilicon DP/eDP controller
In reply to Cody KangFrom: 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.
---
v4:
- give the example PHY its reference clock
v3:
- no change
v2:
- make port@1 required (Rob Herring)
- add Reviewed-by: Rob Herring (Arm)
--- .../display/spacemit/spacemit,k3-inno-dp.yaml | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+)
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +142 -0
@@ -0,0 +1,142 @@ +# 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"; + clocks = <&vctcxo_24m>; + #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
[email protected]
AI reviewRe: [PATCH v4 03/16] 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 d5bd080e6be4156a5fe8cd3106910175a25a16f4
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 Innosilicon DisplayPort / eDP controller integrated in the SpacemiT K3 SoC.
Quoted 6 lines
Documentation/devicetree/bindings/display/spacemit/spacemit,k3-inno-dp.yaml new file +0
-0@@ -0,0 +1,142 @@
[ ... ]
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 place clocks and clock-names before interrupts, following the canonical property order (compatible, reg, clocks, clock-names, interrupts). Could interrupts be moved after clock-names in properties, required, and the example node?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v4 4/16 dt-bindings: soc: spacemit: allow eDP/DP PHY PLL pixel clocks on K3 APMU
In reply to Cody KangFrom: 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.
---
v4:
- no change
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
@@ -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
PATCH v4 5/16 phy: spacemit: add Innosilicon DP TX PHY driver
In reply to Cody KangFrom: 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 takes the 24 MHz reference of both PLLs from a clock.
It registers its pixel PLL as a clock provider. That lets the DP 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.
---
v4:
- take the reference clock from the device tree instead of assuming 24 MHz
- add init, exit, reset and calibrate callbacks: the analog set-up the controller driver used to write is done here
- drop the pixel PLL table; the solver returns the same settings for every row
- wait for the link PLL to lock before starting the pixel PLL
- no sysfs unbind: the controller holds the PHY for its whole life 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 | 1115 +++++++++++++++++++++++++++++++++ 3 files changed, 1129 insertions(+)
drivers/phy/spacemit/Kconfig +13 -0
@@ -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
@@ -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 +1115 -0
1,115 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 05/16] phy: spacemit: add Innosilicon DP TX PHY driver
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] phy: spacemit: restore DPTX_ANA_BG_EN_RCAL after k3_inno_dp_phy_exit() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] phy: spacemit: restore DPTX_ANA_BG_EN_RCAL after k3_inno_dp_phy_exit()
--
commit db47538992daf82cf49bc60c2552401b3362a0b7
Author: Cody Kang <[email protected]>
phy: spacemit: add Innosilicon DP TX PHY driver
This commit adds a PHY and pixel-clock provider driver for the Innosilicon DisplayPort transmit PHY on the SpacemiT K3 SoC.
Quoted 5 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +0
-0
[ ... ]
Quoted 29 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +29
-0+/* Bandgap and lane supplies back on after exit. */ +static int k3_inno_dp_phy_init (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy); +struct regmap *rm = p->regmap; +int ret; + + ret =regmap_set_bits (rm,DPTX_ANA_TX_CTRL6 ,DPTX_ANA_BG_EN ); +if (ret) +return ret; + + ret =regmap_set_bits (rm,DPTX_ANA_TX_ENABLE , +DPTX_ANA_TX_EN_LDO_D3 |DPTX_ANA_TX_EN_LDO_D2 | +DPTX_ANA_TX_EN_LDO_D1 |DPTX_ANA_TX_EN_LDO_D0 | +DPTX_ANA_TX_EN_DRV_D3 |DPTX_ANA_TX_EN_DRV_D2 | +DPTX_ANA_TX_EN_DRV_D1 |DPTX_ANA_TX_EN_DRV_D0 ); +if (ret) +return ret; + +return regmap_set_bits (rm,DPTX_ANA_TX_CTRL3 , +DPTX_ANA_TX_EN_P2S_D3 |DPTX_ANA_TX_EN_P2S_D2 | +DPTX_ANA_TX_EN_P2S_D1 |DPTX_ANA_TX_EN_P2S_D0 ); +} + +static int k3_inno_dp_phy_exit (struct phy *phy) +{ +struct k3_inno_dp_phy *p =phy_get_drvdata (phy); +struct regmap *rm = p->regmap; +
[ ... ]
drivers/phy/spacemit/phy-k3-inno-dp.c line 334
Quoted 4 lines
drivers/phy/spacemit/phy-k3-inno-dp.c new file +4
-0+regmap_write_bits (rm,DPTX_ANA_TX_CTRL6 ,DPTX_ANA_BG_EN , +FIELD_PREP (DPTX_ANA_BG_EN ,0 )); +regmap_write_bits (rm,DPTX_ANA_TX_CTRL7 ,DPTX_ANA_BG_EN_RCAL , +FIELD_PREP (DPTX_ANA_BG_EN_RCAL ,0 ));
[Severity: Medium]
Should k3_inno_dp_phy_init() (or k3_inno_dp_phy_calibrate()) re-enable DPTX_ANA_BG_EN_RCAL in DPTX_ANA_TX_CTRL7? k3_inno_dp_phy_exit() clears it, and neither k3_inno_dp_phy_init() nor k3_inno_dp_phy_calibrate() sets it back, leaving the resistor-calibration reference disabled if the PHY is re-initialized after phy_exit().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v4 6/16 drm/spacemit: add Saturn DPU register model
In reply to Cody KangFrom: 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 covers the whole IP block, including blocks the driver does not touch; the field tables carry only the fields the driver programs.
---
v4:
- drop an offset that nothing uses
- drop fields that nothing programs
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 | 24 ++ .../gpu/drm/spacemit/dpu/saturn_regs/reg_map_hee.h | 64 +++++ .../drm/spacemit/dpu/saturn_regs/saturn_fields.h | 286 +++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dpu_ids.h | 26 ++ 4 files changed, 400 insertions(+)
drivers/gpu/drm/spacemit/dpu/saturn_regs/dpu_int.h new file +24 -0
@@ -0,0 +1,24 @@ +/* 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 GENMASK(18, 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 +64 -0
64 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_regs/saturn_fields.h new file +286 -0
286 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dpu_ids.h new file +26 -0
@@ -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
PATCH v4 7/16 drm/spacemit: add Saturn DPU core types, cmdlist and display MMU
In reply to Cody KangFrom: 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. A field is written by a 32-bit read-modify-write of its word; the register file does not take 8- or 16-bit stores.
---
v4:
- write register fields with 32-bit accesses only: narrower stores do not reach the registers
- make the register accessors inline functions; type the DMMU table entries as little-endian
- commit message: the registers are not write-only
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 | 34 ++++ drivers/gpu/drm/spacemit/dpu/saturn_regs/ops_hee.h | 42 +++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.c | 188 +++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_cmdlist.h | 133 +++++++++++++++ drivers/gpu/drm/spacemit/spacemit_crtc.h | 125 ++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.c | 127 ++++++++++++++ drivers/gpu/drm/spacemit/spacemit_dmmu.h | 79 +++++++++ drivers/gpu/drm/spacemit/spacemit_dpu_reg.h | 99 +++++++++++ drivers/gpu/drm/spacemit/spacemit_drm.h | 83 +++++++++ 9 files changed, 910 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.h new file +34 -0
@@ -0,0 +1,34 @@ +/* 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; +}; + +#define SPACEMIT_DPU_INVALID_FORMAT_ID 0xff + +int spacemit_dpu_enable_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 (const struct spacemit_hw_device *hwdev, +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/dpu/saturn_regs/ops_hee.h new file +42 -0
42 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_cmdlist.c new file +188 -0
188 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 +125 -0
125 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dmmu.c new file +127 -0
127 lines not on this page · raw message
drivers/gpu/drm/spacemit/spacemit_dmmu.h new file +79 -0
79 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 +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 8/16 drm/spacemit: add Saturn DPU hardware backend
In reply to Cody KangFrom: 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.
---
v4:
- pan by moving the read address instead of the read window; a window reaching column 4096 of the framebuffer made the DPU underrun
- write the composer size on every commit, from the CRTC, not with a plane update
- handle the DPU clocks with the clk bulk API (Guodong Xu)
- build the command-list header and rows from masks instead of bitfields
- drop the register stores that never reached the hardware
- look up the format id in the plane's own table; write 0 to the stride of the plane that does not exist
- drop the RGB888 and BGR888 plane formats: the DPU underruns with them at most framebuffer widths
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 | 276 +++++++++++ drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c | 677 ++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c | 57 +++ drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h | 16 + 4 files changed, 1026 insertions(+)
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +276 -0
@@ -0,0 +1,276 @@ +// 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_fourcc.h> +#include <drm/drm_print.h> +#include <drm/drm_vblank.h> + +#include "../spacemit_drm.h" +#include "dpu_saturn.h" +#include "saturn_regs/ops_hee.h" + +/* +* RGB888 and BGR888 are not listed: the read channel underruns with them at +* most widths. +*/ +static const struct dpu_format_id primary_fmts[] = { + {DRM_FORMAT_XRGB8888 ,8 }, + {DRM_FORMAT_ARGB8888 ,4 }, + {DRM_FORMAT_XBGR8888 ,9 }, + {DRM_FORMAT_ABGR8888 ,5 }, + {DRM_FORMAT_RGBX8888 ,10 }, + {DRM_FORMAT_RGBA8888 ,6 }, + {DRM_FORMAT_BGRX8888 ,11 }, + {DRM_FORMAT_BGRA8888 ,7 }, + {DRM_FORMAT_ABGR2101010 ,1 }, + {DRM_FORMAT_RGB565 ,22 }, + {DRM_FORMAT_BGR565 ,23 }, +}; + +/* 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 = { + .n_formats =ARRAY_SIZE (primary_fmts), + .formats = primary_fmts, + .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 =spacemit_drm_priv (a_crtc->crtc.dev); +struct spacemit_hw_device *hwdev = priv->hwdev; + +/* Also called from the interrupt handler and the vblank hooks. */ +if (!READ_ONCE (priv->clocks_on)) +return ; + +regmap_update_bits (hwdev->regmap, offset, mask, enable ? mask :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) +{ +int ret; + +/* +* pxclk keeps its rate: the mode's pixel clock is the DP PHY's PLL. +* pxclk and escclk only have to run for the "lcd" and "esc" resets +* to reach the DPU. +*/ + ret =clk_bulk_prepare_enable (ARRAY_SIZE (priv->clks), priv->clks); +if (ret) +return ret; + +spacemit_dpu_clk_set_rate (priv->dev, priv->clks[DPU_MCLK ].clk, +DPU_MCLK_DEFAULT ,"mclk" ); +spacemit_dpu_clk_set_rate (priv->dev, priv->clks[DPU_ACLK ].clk, +DPU_AXICLK_DEFAULT ,"aclk" ); + +return 0 ; +} + +u8 spacemit_plane_hw_get_format_id (const struct spacemit_hw_device *hwdev, +u32 format) +{ +unsigned int i; + +for (i =0 ; i < hwdev->n_formats; i++) { +if (hwdev->formats[i].format == format) +return hwdev->formats[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 =spacemit_drm_priv (a_crtc->crtc.dev); +struct spacemit_hw_device *hwdev = priv->hwdev; +u32 val; + +if (read_poll_timeout (saturn_hee_get_cfg_rdy, val, val ==0 , +SATURN_CFG_IDLE_POLL_US , +SATURN_CFG_IDLE_TIMEOUT_US , false, 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 =spacemit_drm_priv (a_crtc->crtc.dev); + +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 =spacemit_drm_priv (a_crtc->crtc.dev); +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 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 =spacemit_drm_priv (a_crtc->crtc.dev); +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); + +/* The first frame after atomic_enable is started by software. */ +if (drm_atomic_crtc_needs_modeset (crtc_state)) { +drm_dbg (a_crtc->crtc.dev,"DPU start\n" ); +saturn_hee_sw_start (hwdev); + } +}
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +677 -0
677 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.c new file +57 -0
57 lines not on this page · raw message
drivers/gpu/drm/spacemit/dpu/saturn_fbcmem.h new file +16 -0
@@ -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
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 08/16] drm/spacemit: add Saturn DPU hardware backend
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/spacemit: unmasked IRQ dispatch and early flip event in spacemit_dpu_online_isr() - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm/spacemit: unmasked IRQ dispatch and early flip event in spacemit_dpu_online_isr()
- [Medium] drm/spacemit: stale underrun IRQ and ur_mask_armed race in saturn_hee_cfg_ready()
- [Medium] drm/spacemit: race on cfg_rdy_timer and INT_CFG_RDY in spacemit_dpu_run()
--
commit 6da7eab6a7dc744a64994fe44a0926021ae9c800
Author: Cody Kang <[email protected]>
drm/spacemit: add Saturn DPU hardware backend
This commit adds register-level programming for the SpacemiT Saturn DPU hardware backend, covering clock setup, timing generator and composer programming, RDMA line-buffer sizing, and interrupt handling.
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +0
-0
[ ... ]
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+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 28 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +28
-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 =spacemit_drm_priv (a_crtc->crtc.dev); +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);
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 240
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+ 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; + }
[Severity: High]
Can spacemit_dpu_online_isr() complete a_crtc->event one frame early and dispatch masked interrupts?
saturn_hee_get_int_sts() reads raw DPU_ONLINE_IRQ_STS bits without masking against DPU_ONLINE_IRQ_MSK, even though status bits latch while masked. Because INT_CFG_RDY is handled before INT_VSYNC in the same ISR pass, when both bits are set in irq_raw, the INT_CFG_RDY branch calls drm_crtc_arm_vblank_event() for current_vblank + 1 and the INT_VSYNC branch immediately calls drm_crtc_handle_vblank(), firing the flip event on the same interrupt instead of the next vblank. This unblocks drm_atomic_helper_wait_for_flip_done() early, allowing the next commit to overwrite the active command-list slot and unmap the old framebuffer while it is still scanning out.
Quoted 19 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +19
-0+ 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 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 =spacemit_drm_priv (a_crtc->crtc.dev); +struct spacemit_hw_device *hwdev = priv->hwdev; + +saturn_hee_conf_dpuctrl (crtc, state); +
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c line 269
Quoted 10 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c new file +10
-0+/* 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);
[Severity: Medium]
Can an in-flight spacemit_cfg_rdy_timer_handler() or a late INT_CFG_RDY from a timed-out commit race with spacemit_dpu_run()?
CPU0 (<softirq>) CPU1spacemit_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 = ...
spacemit_dpu_run()
saturn_hee_enable_irq(..., true) saturn_hee_enable_irq(..., false) spacemit_dpu_complete_event(a_crtc) <-- completes new commit's event
timer_delete() in spacemit_dpu_online_isr() does not wait for a running timer callback, so spacemit_cfg_rdy_timer_handler() can mask the next commit's INT_CFG_RDY and complete its a_crtc->event before hardware consumes its command lists. In addition, spacemit_dpu_run() unmasks INT_CFG_RDY before mod_timer() and saturn_hee_cfg_ready(), so a late CFG_RDY from a prior timed-out commit firing in that window deletes the timer before it is armed, masks INT_CFG_RDY, and leaves cfg_rdy_timer running with INT_CFG_RDY disabled.
Quoted 5 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +0
-0
[ ... ]
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c line 57
Quoted 9 lines
drivers/gpu/drm/spacemit/dpu/dpu_saturn_hee.c new file +9
-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 saturn_hee_cfg_ready() immediately fire on a stale underrun bit and race on a_crtc->ur_mask_armed?
After an underrun is logged and INT_UNDERRUN is masked by saturn_hee_clr_int_sts(), further underrunning scanlines re-latch DPU_INT_FRM_TIMING_UNFLOW in DPU_ONLINE_IRQ_STS. On the next commit, saturn_hee_cfg_ready() unmasks INT_UNDERRUN without clearing DPU_ONLINE_IRQ_STS first and before setting a_crtc->ur_mask_armed = true (as does saturn_hee_irq_enable()):
saturn_hee_cfg_ready()
saturn_hee_enable_irq(a_crtc, INT_UNDERRUN, true) <hardirq>
spacemit_dpu_online_isr()
saturn_hee_clr_int_sts(..., irq_ur_bit)
if (... && a_crtc->ur_mask_armed) <-- still false; stays unmasked a_crtc->ur_mask_armed = true
Even if a_crtc->ur_mask_armed = true is written before the interrupt is taken, a_crtc->ur_reported is still true until INT_CFG_RDY fires, so the stale underrun triggers spacemit_dpu_online_isr(), skips logging, and is cleared at the end of the ISR via saturn_hee_clr_int_sts(), which masks INT_UNDERRUN and disarms ur_mask_armed before the new commit takes effect.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
PATCH v4 9/16 drm/spacemit: add Saturn DPU KMS pipeline
In reply to Cody KangFrom: 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.
---
v4:
- create the initial state with drm_mode_config_create_initial_state() at bind (Maxime Ripard)
- let the primary plane keep its framebuffer on a disabled CRTC
- reject modes whose porches or sync widths do not fit the timing generator fields, vscan above 1, and interlaced or doublescan modes
- ack a latched VSYNC before vblank is enabled; keep the commit's event for atomic_flush when a modeset turns the CRTC off and on; stop connector polling before a failed bind unbinds its components; shut the CFG_RDY watchdog down in unbind
- allocate the DRM device with devm_drm_dev_alloc() and stop using dev_private (Guodong Xu)
- fail enable_vblank while the DPU is off
- remove firmware framebuffers before the probe-time reset, and run the clocks for that reset
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 | 647 +++++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_planes.c | 303 ++++++++++++++ 2 files changed, 950 insertions(+)
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +647 -0
@@ -0,0 +1,647 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2025-2026 SpacemiT Co., Ltd. +* +*/ + +#include <linux/aperture.h> +#include <linux/bitfield.h> +#include <linux/clk.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_dpu_reg.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 =spacemit_drm_priv (crtc->dev); +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 ) { +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); +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 =spacemit_drm_priv (drm); +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. On +* a modeset the CRTC comes back on and atomic_flush owns the event. +*/ +spacemit_dpu_complete_event (a_crtc); +spin_lock_irq (&drm->event_lock); +if (crtc_state->event && !crtc_state->active) { +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 =spacemit_drm_priv (crtc->dev); +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) +{ +struct spacemit_drm_private *priv =spacemit_drm_priv (crtc->dev); +struct spacemit_crtc *a_crtc =to_spacemit_crtc (crtc); + +/* Not powered: the mask cannot be opened and no VSYNC will come. */ +if (!READ_ONCE (priv->clocks_on)) +return -EINVAL ; + +/* +* A VSYNC that latched while masked would interrupt as the mask +* opens and count a vblank that is already over. +*/ +saturn_hee_clr_int_sts (a_crtc,saturn_hee_get_irq_bit (INT_VSYNC )); +saturn_hee_enable_irq (a_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) +{ +unsigned int hfp = mode->hsync_start - mode->hdisplay; +unsigned int hsync = mode->hsync_end - mode->hsync_start; +unsigned int hbp = mode->htotal - mode->hsync_end; +unsigned int vfp = mode->vsync_start - mode->vdisplay; +unsigned int vsync = mode->vsync_end - mode->vsync_start; +unsigned int vbp = mode->vtotal - mode->vsync_end; + +if (mode->hdisplay >SPACEMIT_DPU_MAX_HDISPLAY ) +return MODE_BAD_HVALUE ; +if (mode->vdisplay >SPACEMIT_DPU_MAX_VDISPLAY ) +return MODE_BAD_VVALUE ; + +/* Progressive scan only; the timing generator cannot repeat lines. */ +if (mode->flags &DRM_MODE_FLAG_INTERLACE ) +return MODE_NO_INTERLACE ; +if (mode->flags &DRM_MODE_FLAG_DBLSCAN ) +return MODE_NO_DBLESCAN ; +if (mode->vscan >1 ) +return MODE_NO_VSCAN ; + +/* Porches and sync widths must fit their timing generator fields. */ +if (hfp >FIELD_MAX (dpu_field_mask (TMG_REG , hfp)) || + hbp >FIELD_MAX (dpu_field_mask (TMG_REG , hbp))) +return MODE_HBLANK_WIDE ; +if (hsync >FIELD_MAX (dpu_field_mask (TMG_REG , hsync_width))) +return MODE_HSYNC_WIDE ; +if (vfp >FIELD_MAX (dpu_field_mask (TMG_REG , vfp)) || + vbp >FIELD_MAX (dpu_field_mask (TMG_REG , vbp))) +return MODE_VBLANK_WIDE ; +if (vsync >FIELD_MAX (dpu_field_mask (TMG_REG , vsync_width))) +return MODE_VSYNC_WIDE ; + +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 ; +} + +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; + + priv->clks[DPU_PXCLK ].id ="pxclk" ; + priv->clks[DPU_MCLK ].id ="mclk" ; + priv->clks[DPU_ESCCLK ].id ="escclk" ; + priv->clks[DPU_ACLK ].id ="aclk" ; + priv->clks[DPU_DSCCLK ].id ="dscclk" ; + ret =devm_clk_bulk_get (dev,ARRAY_SIZE (priv->clks), priv->clks); +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" ); + + ret =aperture_remove_all_conflicting_devices (spacemit_drm_drv.name); +if (ret) +return dev_err_probe (dev, ret, +"failed to remove existing framebuffers\n" ); + +/* +* The boot loader may leave its boot-logo pipeline running. Stop it +* here and hold the resets until the first enable brings the block +* up. The clocks may have been gated as unused by now, and the resets +* only reach a clocked block. +*/ + ret =clk_bulk_prepare_enable (ARRAY_SIZE (priv->clks), priv->clks); +if (ret) +return dev_err_probe (dev, ret,"failed to enable clocks\n" ); + ret =reset_control_bulk_assert (n_rstc, priv->pipe_resets); +usleep_range (10000 ,20000 ); +clk_bulk_disable_unprepare (ARRAY_SIZE (priv->clks), priv->clks); +if (ret) +return dev_err_probe (dev, ret,"failed to assert resets\n" ); + + 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_drm_device *sdrm; +struct spacemit_crtc *a_crtc; +struct drm_device *drm; +int ret; + +/* +* devres taken in bind is scoped to the bind: the component core +* releases it when the aggregate unbinds, which puts the drm_device. +*/ + sdrm =devm_drm_dev_alloc (dev, &spacemit_drm_drv, + struct spacemit_drm_device, base); +if (IS_ERR (sdrm)) +return PTR_ERR (sdrm); + sdrm->priv = priv; + drm = &sdrm->base; + priv->ddev = drm; + + 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; + } + + ret =drm_mode_config_create_initial_state (drm); +if (ret) { +dev_err_probe (dev, ret,"failed to create the initial state\n" ); + goto err_unbind_all; + } + + 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); + +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: +/* The poll worker must not find the connectors half torn down. */ +drm_kms_helper_poll_fini (drm); +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 ; +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); +/* +* A shutdown commit that failed has not stopped the watchdog of a +* commit still waiting for CFG_RDY, and the CRTC is freed once unbind +* returns. +*/ +timer_shutdown_sync (&priv->a_crtc->cfg_rdy_timer); + +component_unbind_all (dev, drm); + +/* .shutdown and a later re-bind must not touch the stale instance. */ + priv->ddev =NULL ; + priv->a_crtc =NULL ; +} + +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_obj (dev, *priv); +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 ); + +clk_bulk_disable_unprepare (ARRAY_SIZE (priv->clks), priv->clks); + +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 +303 -0
303 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 09/16] drm/spacemit: add Saturn DPU KMS pipeline
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/spacemit: incomplete teardown in spacemit_drm_master_unbind() - [High] drm/spacemit: UAF of…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/spacemit: incomplete teardown in spacemit_drm_master_unbind()
- [High] drm/spacemit: UAF of devm-allocated priv when drm_device outlives remove
- [High] drm/spacemit: vblank init ordering in spacemit_drm_master_bind() and race
- [High] drm/spacemit: premature event arming in spacemit_crtc_atomic_flush() and ISR
--
commit e124be165ca1d42bc693534742294e9b826976ad
Author: Cody Kang <[email protected]>
drm/spacemit: add Saturn DPU KMS pipeline
This commit adds the atomic KMS CRTC and primary plane implementation, component master bind/unbind, and runtime PM callbacks for the SpacemiT Saturn DPU.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +0
-0
[ ... ]
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 =spacemit_drm_priv (crtc->dev); +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 145
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 spacemit_dpu_online_isr() arm and complete a_crtc->event before the DPU has taken and scanned out the new command lists?
spacemit_crtc_atomic_flush() publishes a_crtc->event and drops event_lock before spacemit_dpu_run() clears stale INT_CFG_RDY status and raises both_cfg_rdy:
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c:spacemit_dpu_run() {
...
saturn_hee_conf_dpuctrl(crtc, state);
/* 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);
...
saturn_hee_cfg_ready(a_crtc, hwdev);
}Because spacemit_dpu_online_isr() reads unmasked status from DPU_ONLINE_IRQ_STS and handles INT_CFG_RDY before INT_VSYNC, an interrupt that fires with a leftover INT_CFG_RDY bit set (or at the frame boundary when INT_CFG_RDY and INT_VSYNC are both pending) arms a_crtc->event for vblank->count + 1 and immediately delivers it via drm_crtc_handle_vblank() in the same ISR call:
drivers/gpu/drm/spacemit/dpu/dpu_saturn.c:spacemit_dpu_online_isr() {
...
irq_bit = saturn_hee_get_irq_bit(INT_CFG_RDY);
if (irq_raw & irq_bit) {
...
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;
}
...
}Completing the event early signals flip_done before the hardware finishes with the previous buffers, allowing the next commit to overwrite the in-use slot in the two-entry command-list ring and clean up the active framebuffer.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_crtc.c line 431
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +11
-0+ ret =drm_mode_config_create_initial_state (drm); +if (ret) { +dev_err_probe (dev, ret,"failed to create the initial state\n" ); + goto err_unbind_all; + } + + 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; + }
[Severity: High]
Does calling drm_mode_config_create_initial_state() before drm_vblank_init() leave vblank enabled on the initially disabled CRTC and allow spacemit_crtc_enable_vblank() to race with runtime PM?
drm_mode_config_create_initial_state() only calls drm_crtc_vblank_reset() when drm_dev_has_vblank(drm) is already true. Because drm_vblank_init() has not run yet, the disabled CRTC is left with vblank->inmodeset == 0 instead of 1, so DRM_IOCTL_WAIT_VBLANK can invoke spacemit_crtc_enable_vblank() before drm_crtc_vblank_on() is called.
Furthermore, spacemit_crtc_enable_vblank() only checks READ_ONCE(priv->clocks_on) without synchronization against spacemit_dpu_runtime_suspend() (which only waits on synchronize_irq(priv->irq_online)):
CPU0 CPU1spacemit_crtc_enable_vblank() spacemit_dpu_runtime_suspend()
if (!READ_ONCE(priv->clocks_on))
WRITE_ONCE(priv->clocks_on, false);
synchronize_irq(priv->irq_online);
reset_control_bulk_assert(...);
clk_bulk_disable_unprepare(...); saturn_hee_clr_int_sts(...) <-- MMIO write to clock-gated DPU stalls bus
During spacemit_crtc_atomic_enable(), spacemit_dpu_runtime_resume() also sets priv->clocks_on = true before spacemit_dpu_init() and drm_crtc_vblank_on(), allowing a concurrent drm_vblank_get() to unmask INT_VSYNC before the timing generator is initialized.
[ ... ]
Quoted 22 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +22
-0+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); +/* +* A shutdown commit that failed has not stopped the watchdog of a +* commit still waiting for CFG_RDY, and the CRTC is freed once unbind
drivers/gpu/drm/spacemit/spacemit_crtc.c line 492
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+* returns. +*/ +timer_shutdown_sync (&priv->a_crtc->cfg_rdy_timer); + +component_unbind_all (dev, drm); + +/* .shutdown and a later re-bind must not touch the stale instance. */ + priv->ddev =NULL ; + priv->a_crtc =NULL ; +}
[Severity: High]
What completes priv->a_crtc->event and stops DPU DMA when spacemit_drm_master_unbind() runs?
If a commit is waiting for CFG_RDY when drm_atomic_helper_shutdown() fails, disable_irq() and timer_shutdown_sync() stop both paths that call spacemit_dpu_complete_event(), leaking priv->a_crtc->event and its vblank reference and leaving flip_done unsignaled (along with the CRTC's runtime PM reference).
Even when drm_atomic_helper_shutdown() succeeds, calling drm_dev_unplug() first makes drm_dev_enter() in spacemit_crtc_atomic_disable() and spacemit_plane_atomic_disable() return false, skipping spacemit_dpu_uninit() and spacemit_plane_off(). Hardware shutdown then relies entirely on spacemit_dpu_runtime_suspend(), so if runtime suspend does not run (for example when power/control is set to "on" or shutdown failed), the DPU remains clocked and out of reset while component unbind releases the drm_device and frees the command-list rings via dma_free_coherent().
[ ... ]
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +14
-0+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_obj (dev, *priv); +if (!priv)
drivers/gpu/drm/spacemit/spacemit_crtc.c line 522
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_crtc.c new file +10
-0+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 );
[Severity: High]
Can sdrm->priv be dereferenced after it is freed if an open DRM file outlives spacemit_dpu_remove()?
priv and priv->hwdev are allocated with devm on the platform device, so they are freed as soon as spacemit_dpu_remove() finishes, whereas sdrm->base (the drm_device) stays alive until the last open file descriptor is closed. KMS and vblank callbacks on that drm_device still dereference sdrm->priv via spacemit_drm_priv() before or without drm_dev_enter() — for example in spacemit_crtc_atomic_flush() (priv->clocks_on), spacemit_plane_atomic_check() (priv->hwdev), and spacemit_crtc_disable_vblank() from the vblank disable timer — causing a use-after-free.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
PATCH v4 10/16 drm/spacemit: add Saturn DPU DRM device driver
In reply to Cody KangFrom: 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 display MMU reads each table entry as one 4 KiB page, hence the dependency on PAGE_SIZE_4KB. 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]>.
---
v4:
- depend on PAGE_SIZE_4KB
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 | 19 +++ drivers/gpu/drm/spacemit/Makefile | 12 ++ drivers/gpu/drm/spacemit/spacemit_drm.c | 203 ++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+)
drivers/gpu/drm/Kconfig +1 -0
@@ -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
@@ -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 +19 -0
@@ -0,0 +1,19 @@ +# 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 PAGE_SIZE_4KB + 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
@@ -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 +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v4 11/16 drm/spacemit: add Innosilicon DP/eDP controller bridge driver
In reply to Cody KangFrom: 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.
On DisplayPort the bridge behind the output port is attached when the devicetree has one (a dp-connector node).
The link rate is set through the generic PHY framework and the pixel rate through the clock the PHY registers. The PHY's own registers are left to the PHY driver.
The external DP connector is polled for hot-plug: the controller's HPD interrupt does not fire on the K3 boards, while the HPD level can be read at any time. A sink that is swapped within one poll interval of 10 s is not noticed.
The driver is built into spacemit-drm. Otherwise the bridge module can be unloaded while the DRM device is open, and the DRM device then calls bridge ops that are gone, which triggers an oops.
The PHY is a child device that has to bind while the controller probes, and a PHY driver that registers later does not retry a deferred controller, so the module asks for the PHY module first (MODULE_SOFTDEP).
The check that fails AUX transfers fast while HPD is low is from Sarah Emery <[email protected]>.
---
v4:
- keep the DP block powered across unbind, so that a bind without a re-probe finds a working AUX channel; power it down when the device goes away
- never install assumed sink limits: after a failed capability read the limits stay empty and the next enable reads again
- set the sink to D0 before link training (James Morris)
- build the driver into spacemit-drm; as a module of its own it could be unloaded while the DRM device was still open (Guodong Xu)
- take the pre-emphasis request as the shifted level it is, and keep swing plus pre-emphasis within 3; park the link when the bring-up fails in bind; keep the pixel PLL running when no link configuration is tried
- leave the PHY's analog registers to the PHY driver
- take the AUX reply code from the upper nibble of the status byte; leave AUX and EDID retries to the DP helpers
- read the eDP 1.4 link rate table; compute the transfer unit and the HBLANK interval in kHz
- attach the bridge behind the DisplayPort output; use of_drm_get_bridge_by_endpoint()
- declare no detect and HPD ops on eDP and leave its HPD interrupt off; do not report a branch device without a sink as connected
- stop the capability read and link training when AUX times out; bound the retries of a failed eDP enable; stop the retry work at shutdown
- drop the HPD interrupt handlers: the interrupt never fires on the boards and the connector is polled
- select the PHY driver instead of implying it: a built-in controller with a modular or missing PHY driver stays deferred
- commit message: say why external DP hot-plug is polled
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 | 17 + drivers/gpu/drm/spacemit/Makefile | 2 + drivers/gpu/drm/spacemit/spacemit_crtc.c | 22 +- drivers/gpu/drm/spacemit/spacemit_drm.h | 1 + drivers/gpu/drm/spacemit/spacemit_inno_dp.c | 2046 +++++++++++++++++++++++++++ drivers/gpu/drm/spacemit/spacemit_inno_dp.h | 328 +++++ 6 files changed, 2415 insertions(+), 1 deletion(-)
drivers/gpu/drm/spacemit/Kconfig +17 -0
@@ -17,3 +17,20 @@ config DRM_SPACEMIT DisplayPort or embedded DisplayPort controller. If M is selected the module will be called spacemit-drm. + +config SPACEMIT_INNO_DP + bool "SpacemiT Innosilicon DP/eDP controller support" + depends on DRM_SPACEMIT + depends on COMMON_CLK + select PHY_SPACEMIT_K3_INNO_DP + select GENERIC_PHY + 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.
drivers/gpu/drm/spacemit/Makefile +2 -0
@@ -9,4 +9,6 @@ spacemit-drm-y := spacemit_drm.o \ dpu/dpu_saturn_hee.o \ dpu/saturn_fbcmem.o +spacemit-drm-$(CONFIG_SPACEMIT_INNO_DP) += spacemit_inno_dp.o + obj-$(CONFIG_DRM_SPACEMIT) += spacemit-drm.o
drivers/gpu/drm/spacemit/spacemit_crtc.c +21 -1
@@ -641,7 +641,27 @@ static struct platform_driver spacemit_dpu_driver = { .suppress_bind_attrs = true, }, }; -module_platform_driver (spacemit_dpu_driver); + +static struct platform_driver *const spacemit_drm_drivers[] = { +#ifdef CONFIG_SPACEMIT_INNO_DP + &spacemit_dp_driver, +#endif + &spacemit_dpu_driver, +}; + +static int __init spacemit_drm_init (void ) +{ +return platform_register_drivers (spacemit_drm_drivers, +ARRAY_SIZE (spacemit_drm_drivers)); +} +module_init (spacemit_drm_init); + +static void __exit spacemit_drm_exit(void) +{ +platform_unregister_drivers (spacemit_drm_drivers, +ARRAY_SIZE (spacemit_drm_drivers)); +} +module_exit (spacemit_drm_exit);MODULE_DESCRIPTION ("SpacemiT DRM KMS master driver" );MODULE_LICENSE ("GPL" );
drivers/gpu/drm/spacemit/spacemit_drm.h +1 -0
@@ -76,6 +76,7 @@ spacemit_drm_priv(struct drm_device *drm)extern const struct drm_driver spacemit_drm_drv;extern const struct component_master_ops spacemit_drm_master_ops; +extern struct platform_driver spacemit_dp_driver;int spacemit_drm_mode_config_init (struct drm_device *drm);int spacemit_drm_of_component_probe (struct device *dev);
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +2046 -0
2,046 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
[email protected]
AI reviewRe: [PATCH v4 11/16] drm/spacemit: add Innosilicon DP/eDP controller bridge driver
Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] drm/spacemit: clk_set_parent() fails in spacemit_dp_probe() due to ccu-k3 mux - [High]…
Thank you for your contribution! Sashiko AI review found 11 potential issues to consider:
- [High] drm/spacemit: clk_set_parent() fails in spacemit_dp_probe() due to ccu-k3 mux
- [High] drm/spacemit: DP_PHY_RESET in spacemit_dp_dev_init() desyncs PREPLL clk rate
- [Medium] drm/spacemit: sink count and cap retry bugs in spacemit_dp_bridge_detect()
- [Medium] drm/spacemit: missing 1-lane HBR2 config and eDP sink_rates filter
- [Medium] drm/spacemit: skipped PLL check and stale DPCD in mode_valid()
- [Medium] drm/spacemit: phy_exit() in spacemit_dp_shutdown() while DRM device is active
- [Medium] drm/spacemit: spacemit_dp_remove() runs before devm DP AUX bus depopulation
- [Medium] drm/spacemit: AUX registered before init and MPLL reset without hw_mutex
- [Medium] drm/spacemit: unlocked dp->link and dp->dpcd reads in mode_valid() and check
- [Medium] drm/spacemit: multi-second AUX timeout stalls and ignored D0 timeout
- [Medium] drm/spacemit: redundant init and unguarded eDP HPD check in spacemit_dp_bind()
--
commit 35a58c12d01e7fe94c01dcd449a9206872d617e4
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 Saturn DPU on SpacemiT SoCs.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +0
-0
[ ... ]
Quoted 6 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +6
-0+static const struct spacemit_dp_link_config { +enum spacemit_dp_link_rate rate; +enum spacemit_dp_lane_count lanes; +} spacemit_dp_link_priority_table[] = { + {SPACEMIT_DP_LINK_RATE_1_62 ,SPACEMIT_DP_LANE_1 },/* 1.62 Gbps */ + {SPACEMIT_DP_LINK_RATE_2_70 ,SPACEMIT_DP_LANE_1 },/* 2.70 Gbps */
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 107
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+ {SPACEMIT_DP_LINK_RATE_1_62, SPACEMIT_DP_LANE_2}, /* 3.24 Gbps */ + + {SPACEMIT_DP_LINK_RATE_2_70, SPACEMIT_DP_LANE_2}, /* 5.40 Gbps */ + {SPACEMIT_DP_LINK_RATE_1_62, SPACEMIT_DP_LANE_4}, /* 6.48 Gbps */ + + {SPACEMIT_DP_LINK_RATE_2_70, SPACEMIT_DP_LANE_4}, /* 10.8 Gbps */ + {SPACEMIT_DP_LINK_RATE_5_40, SPACEMIT_DP_LANE_2}, /* 10.8 Gbps */ + + {SPACEMIT_DP_LINK_RATE_5_40, SPACEMIT_DP_LANE_4}, /* 21.6 Gbps */ +};
[Severity: Medium]
Should spacemit_dp_link_priority_table[] also include {SPACEMIT_DP_LINK_RATE_5_40, SPACEMIT_DP_LANE_1}?
Both the DisplayPort specification and phy-k3-inno-dp support 1-lane HBR2 (4.32 Gbps usable capacity), and spacemit_dp_bridge_mode_valid() accepts 1-lane HBR2 modes up to 4.32 Gbps, but spacemit_dp_bridge_atomic_check() and spacemit_dp_bridge_atomic_enable() reject any 1-lane mode above 2.16 Gbps because that entry is missing from the table.
In addition, when dp->link.use_rate_select is true on eDP 1.4, neither spacemit_dp_bridge_atomic_check() nor the loop filter in spacemit_dp_bridge_atomic_enable() verifies that cfg->rate is listed in dp->link.sink_rates[]. If a panel lists 2.70 Gbps in DP_SUPPORTED_LINK_RATES without 1.62 Gbps, atomic_check() picks 1.62 Gbps and atomic_enable() power-cycles the link, programs the PLLs, powers on the PHY, and writes DP_EDP_CONFIGURATION_SET before spacemit_dp_link_train() rejects the rate with -EINVAL.
[ ... ]
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +11
-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) { +spacemit_dp_aux_hw_reset (dp); +dev_dbg_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; + }
[ ... ]
Quoted 7 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +7
-0+/* A sink left in D3 need not answer the training writes. */ +if (drm_dp_link_power_up (&dp->aux, dp->link.revision) <0 ) +drm_dbg (dp->drm,"failed to set the sink to D0\n" ); + +/* +* A sink may act on the DP_LINK_BW_SET write, so set the lane count +* first.
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 887
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+*/ + link_config[0 ] = lanes; +if (dp->link.enhanced_framing) + link_config[0 ] |=DP_LANE_COUNT_ENHANCED_FRAME_EN ; +regmap_write_bits (dp->regs,DP_CORE_CONTROL ,DP_ENHANCE_FRAMING_EN , +FIELD_PREP (DP_ENHANCE_FRAMING_EN , + dp->link.enhanced_framing)); + + ret =drm_dp_dpcd_write_byte (&dp->aux,DP_LANE_COUNT_SET , + link_config[0 ]);
[Severity: Medium]
Does a single timed-out DPCD access stall for 6.5 seconds, and does spacemit_dp_link_train() double that stall by ignoring -ETIMEDOUT from drm_dp_link_power_up()?
SPACEMIT_DP_AUX_TIMEOUT_US is 200 ms plus 4-5 ms in spacemit_dp_aux_hw_reset(), and drm_dp_dpcd_access() retries all 32 times even on -ETIMEDOUT, so each unresponsive DPCD access blocks for 6.54 seconds while holding aux.hw_mutex and dp->mode_lock. Because spacemit_dp_link_train() only logs a failure from drm_dp_link_power_up() and proceeds to drm_dp_dpcd_write_byte(DP_LANE_COUNT_SET), an unresponsive sink stalls for 13.1 seconds before returning -ETIMEDOUT to spacemit_dp_bridge_atomic_enable().
[ ... ]
Quoted 19 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +19
-0+static enum drm_connector_status +spacemit_dp_bridge_detect (struct drm_bridge *bridge,struct drm_connector *connector) +{ +struct spacemit_dp_dev *dp =container_of_const (bridge, + struct spacemit_dp_dev, + bridge); +enum drm_connector_status status; + +guard (mutex)(&dp->mode_lock); + status =spacemit_dp_hw_detect_hpd (dp); + +/* +* The bind-time cap read only covers a sink that was already there. +* Without a re-read here, link.max_rate stays 0 and every link config +* is filtered out. +*/ +if (status == connector_status_connected && + dp->connector_status != connector_status_connected) +spacemit_dp_hw_read_sink_caps (dp);
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1127
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+ +/* A branch device holds HPD up with no sink behind it. */ +if (status == connector_status_connected && +drm_dp_is_branch (dp->dpcd) && !drm_dp_read_sink_count (&dp->aux)) + status = connector_status_disconnected; + + dp->connector_status = status; + +return status; +}
[Severity: Medium]
Does !drm_dp_read_sink_count(&dp->aux) treat negative error returns as a connected sink?
drm_dp_read_sink_count() returns a negative errno when reading DP_SINK_COUNT fails, so !drm_dp_read_sink_count(&dp->aux) evaluates to false on error and reports the branch device as connected; checking drm_dp_read_sink_count(&dp->aux) <= 0 would avoid that.
Also, if spacemit_dp_hw_read_sink_caps() fails (or if spacemit_dp_bridge_atomic_enable() clears dp->link.max_rate and dp->link.max_num_lanes after sink_lost), dp->dpcd is zeroed while dp->connector_status is still latched to connector_status_connected. Later detect polls while HPD stays high see dp->connector_status == connector_status_connected and never retry spacemit_dp_hw_read_sink_caps() even though dp->link.max_rate is 0.
[ ... ]
Quoted 43 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +43
-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_const (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. +*/ +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); + } +if (!max_link_rate || !max_lanes) { +/* Sink not enumerated yet: accept and re-check at modeset. */ +return MODE_OK ; + } + +/* +* max_link_rate is per lane in 10 kbit/s. The x10 to reach kbit/s and +* the 8b/10b coding overhead cancel down to a plain "* 8". +*/ + max_bw = (u64 )max_link_rate * max_lanes *8 ; + +/* Required bandwidth: pixel clock (kHz) * bits per pixel. */ + req_bw = (u64 )mode->clock *SPACEMIT_DP_BPP ; + +if (req_bw > max_bw) { + drm_dbg(bridge->dev, + "rejecting %dx%d@%d: %llu > %llu kbit/s (%u kbit/s x%u lanes)\n", + mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode),
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1198
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+ req_bw, max_bw, max_link_rate * 10, max_lanes); +return MODE_CLOCK_HIGH ; + } + +/* The pixel clock is made by the PHY PLL, which cannot hit every rate. */ +if (clk_round_rate (dp->pll_clk, mode->clock *1000UL ) <=0 ) +return MODE_NOCLOCK ; + +return MODE_OK ; +}
[Severity: Medium]
Does returning MODE_OK when !max_link_rate || !max_lanes bypass the clk_round_rate(dp->pll_clk, ...) check, and does the else branch fall back to un-narrowed dp->dpcd values?
Before an eDP panel is enabled for the first time, its DPCD limits are 0, so spacemit_dp_bridge_mode_valid() returns early before checking whether dp->pll_clk can synthesize mode->clock. If the PHY PLL rejects the rate, spacemit_dp_set_plls() later fails in spacemit_dp_bridge_atomic_enable() (including in the !dp->phy_powered fallback), leaving the pixel clock off and wedging the CRTC commit.
Also, when spacemit_dp_bridge_atomic_enable() zeroes dp->link.max_rate and dp->link.max_num_lanes after link narrowing is exhausted or the sink is lost, dp->dpcd is not cleared, so the else branch here reverts to the full un-narrowed capabilities from dp->dpcd.
[ ... ]
Quoted 32 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +32
-0+static int spacemit_dp_bridge_atomic_check (struct drm_bridge *bridge, +struct drm_bridge_state *bridge_state, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) +{ +struct spacemit_dp_dev *dp =container_of_const (bridge, + struct spacemit_dp_dev, + bridge); +struct spacemit_dp_bridge_state *st = +to_spacemit_dp_bridge_state (bridge_state); +const struct drm_display_mode *mode = &crtc_state->adjusted_mode; +u32 req_bw; +int i; + + req_bw =spacemit_dp_calc_required_bw (mode,SPACEMIT_DP_BPP ); + +/* No caps yet: leave idx unset and let ->atomic_enable() retry. */ +if (!dp->link.max_rate || !dp->link.max_num_lanes) { + st->link_cfg_idx =-1 ; +return 0 ; + } + +for (i =0 ; i <ARRAY_SIZE (spacemit_dp_link_priority_table); i++) { +const struct spacemit_dp_link_config *cfg = + &spacemit_dp_link_priority_table[i]; + +if (cfg->rate > dp->link.max_rate || + cfg->lanes > dp->link.max_num_lanes) +continue ; +if (spacemit_dp_calc_link_capacity (cfg->rate, cfg->lanes) < req_bw) +continue ; +
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1451
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+ st->link_cfg_idx = i; +return 0 ; + } + +drm_dbg (bridge->dev, +"no DP link cfg fits %dx%d@%d (need %u kbit/s; sink %u kbit/s x %u lanes)\n" , + mode->hdisplay, mode->vdisplay,drm_mode_vrefresh (mode), + req_bw, dp->link.max_rate, dp->link.max_num_lanes); +return -EINVAL ; +}
[Severity: Medium]
Can spacemit_dp_bridge_atomic_check() and spacemit_dp_bridge_mode_valid() race with concurrent updates to dp->link and dp->dpcd because neither acquires dp->mode_lock?
output_poll_execute() runs spacemit_dp_bridge_detect() under mode_config.mutex (without connection_mutex), and non-blocking commits run spacemit_dp_bridge_atomic_enable() on a workqueue without modeset locks:
CPU0 CPU1 (kworker)spacemit_dp_bridge_atomic_check() spacemit_dp_bridge_atomic_enable()
if (!dp->link.max_rate || ...)
guard(mutex)(&dp->mode_lock);
dp->link.max_rate = 0;
dp->link.max_num_lanes = 0;
for (i = 0; ...; i++)
if (cfg->rate > dp->link.max_rate)
continue; return -EINVAL; <-- commit fails instead of returning 0 with idx = -1
If dp->link.max_rate or dp->link.max_num_lanes is cleared after the initial check in spacemit_dp_bridge_atomic_check(), the loop filters out every table entry and fails the atomic check with -EINVAL.
[ ... ]
Quoted 14 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +14
-0+static int spacemit_dp_dev_init (struct spacemit_dp_dev *dp) +{ +int ret; + +/* The PHY parks its lanes and PLLs for the reset below. */ + ret =phy_reset (dp->phy); +if (ret) +return ret; + +/* 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 ));
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +4
-0+ ret =spacemit_dp_set_plls (dp,SPACEMIT_DP_LINK_RATE_2_70 ,148500 ); +if (ret) +return ret; +
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1681
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+ 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; + +return phy_calibrate (dp->phy); +}
[Severity: High]
Does pulsing DP_PHY_RESET in spacemit_dp_dev_init() wipe the PHY PREPLL registers while the clock framework still caches 148500000 Hz?
On eDP, spacemit_dp_probe() calls spacemit_dp_dev_init(), which calls clk_set_rate(dp->pll_clk, 148500000) to program the PREPLL registers and cache p->pxclk_rate = 148500000 in phy-k3-inno-dp. When spacemit_dp_bind() calls spacemit_dp_dev_init() a second time (or on a component rebind), DP_PHY_RESET resets the PREPLL registers to their hardware defaults, but clk_set_rate(dp->pll_clk, 148500000) sees the rate unchanged and returns 0 without calling k3_inno_dp_pxclk_set_rate(). spacemit_dp_phy_on() and any subsequent 148.5 MHz modeset then power on PREPLL with its post-reset register defaults.
Quoted 5 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +5
-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;
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1697
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+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; + }
[Severity: Medium]
Does registering dp->aux before spacemit_dp_dev_init() expose the AUX device and I2C adapter while the controller and MPLL are uninitialized or being reset without dp->aux.hw_mutex?
drm_dp_aux_register() publishes /dev/drm_dp_aux* and the I2C-over-AUX adapter before spacemit_dp_dev_init() runs below. Neither spacemit_dp_dev_init() (which powers down MPLL via phy_reset() and asserts DP_CONTROLLER_RESET and DP_AUX_RESET) nor spacemit_dp_set_plls() in spacemit_dp_bridge_atomic_enable() (which power-cycles the MPLL supplying the 16 MHz AUX clock after spacemit_dp_link_disable() releases dp->aux.hw_mutex) holds dp->aux.hw_mutex, racing with concurrent userspace AUX or DDC transfers.
[ ... ]
Quoted 4 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +4
-0+ ret =spacemit_dp_dev_init (dp); + +/* +* Also after a failed bring-up, which may have left the PHY on. Not
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1742
Quoted 10 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +10
-0+* spacemit_dp_hw_disable(): see spacemit_dp_unbind(). +*/ +spacemit_dp_link_disable (dp); +if (ret) + goto err_encoder; + + dp->connector_status =spacemit_dp_hw_detect_hpd (dp); + +if (dp->connector_status == connector_status_connected) +spacemit_dp_hw_read_sink_caps (dp);
[Severity: Medium]
Should spacemit_dp_bind() skip spacemit_dp_hw_detect_hpd() and the second spacemit_dp_dev_init() on eDP?
On eDP, spacemit_dp_probe() has just run spacemit_dp_dev_init() and spacemit_dp_link_disable() before populating the AUX bus, so repeating them in spacemit_dp_bind() adds another ~150 ms of synchronous reset and PHY calibration delay. spacemit_dp_bind() then checks spacemit_dp_hw_detect_hpd() and calls spacemit_dp_hw_read_sink_caps() without checking !dp->edp_mode, even though DP_HPD_IN_STATUS is noisy on eDP and an unpowered panel with a non-AUX backlight can time out on those DPCD reads.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1829
Quoted 9 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +9
-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); + +/* The device is going away; its next probe resets the block. */ +spacemit_dp_hw_disable (dp); +}
[Severity: Medium]
During driver unbind on eDP, does spacemit_dp_remove() -> spacemit_dp_unregister() tear down the component and PHY before devres depopulates the DP AUX bus?
spacemit_dp_probe() registers AUX bus depopulation via devm_of_dp_aux_populate_bus(), which runs during devres_release_all() after spacemit_dp_remove() returns:
CPU0 CPU1 (deferred probe work)spacemit_dp_remove()
spacemit_dp_unregister()
if (dp->component_added)
spacemit_dp_hw_disable()
phy_exit(dp->phy)
dp_aux_ep_probe()
spacemit_dp_edp_link_panel()
component_add(dp->dev, ...)
dp->component_added = true;devres_release_all()
of_dp_aux_depopulate_bus_void()
/* dp is freed with component still on component_list */
Even without a racing deferred panel probe, spacemit_dp_hw_disable() exits the PHY and stops the MPLL AUX clock while the AUX child panel device is still bound.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 1948
Quoted 13 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +13
-0+/* +* The PHY exposes its PLL as the APMU pixel-clock mux's external +* parent. +*/ + dp->pll_clk =devm_clk_get (dev,"pll" ); +if (IS_ERR (dp->pll_clk)) +return dev_err_probe (dev,PTR_ERR (dp->pll_clk), +"failed to get PHY pixel clock\n" ); + + ret =clk_set_parent (dp->pxclk, dp->pll_clk); +if (ret) +return dev_err_probe (dev, ret, +"failed to route the pixel mux to the PHY PLL\n" );
[Severity: High]
Does clk_set_parent(dp->pxclk, dp->pll_clk) always fail with -EINVAL on K3?
In drivers/clk/spacemit/ccu-k3.c, both edp0_pclk_parents[] and edp1_pclk_parents[] declare their second parent with CCU_PARENT_NAME(external_clk) (.fw_name = "external_clk"), whereas the spacemit,k3-syscon-apmu binding and DT node name those clock inputs "edp0_pll_pxclk" and "edp1_pll_pxclk":
drivers/clk/spacemit/ccu-k3.c:
static const struct clk_parent_data edp0_pclk_parents[] = {
CCU_PARENT_HW(lcd_pxclk), CCU_PARENT_NAME(external_clk),
};
When clk_set_parent() resolves edp0_pxclk or edp1_pxclk's external parent via clk_core_get(), of_parse_clkspec() looks up "external_clk" in the APMU node's clock-names, fails to match dp->pll_clk, and aborts spacemit_dp_probe() with -EINVAL.
[ ... ]
drivers/gpu/drm/spacemit/spacemit_inno_dp.c line 2028
Quoted 11 lines
drivers/gpu/drm/spacemit/spacemit_inno_dp.c new file +11
-0+static void spacemit_dp_shutdown (struct platform_device *pdev) +{ +struct spacemit_dp_dev *dp =platform_get_drvdata (pdev); + +/* Not under mode_lock: the modeset that the work starts takes it. */ +disable_work_sync (&dp->modeset_retry_work); + +/* The DRM device may still be there and enabling the output. */ +guard (mutex)(&dp->mode_lock); +spacemit_dp_hw_disable (dp); +}
[Severity: Medium]
Can calling spacemit_dp_hw_disable() in spacemit_dp_shutdown() run phy_exit() before the DPU master device shuts down its KMS pipeline?
Because the DP/eDP platform devices are registered after the DPU devices, device_shutdown() runs spacemit_dp_shutdown() before spacemit_dpu_shutdown() runs drm_atomic_helper_shutdown(). spacemit_dp_hw_disable() calls phy_exit(dp->phy), which powers down the PHY bandgap, LDOs, and MPLL (stopping the 16 MHz AUX clock) and drops phy->init_count to 0. Any subsequent AUX transfer during panel disable in drm_atomic_helper_shutdown() will time out, and any in-flight spacemit_dp_bridge_atomic_enable() that acquires dp->mode_lock after spacemit_dp_shutdown() will call phy_power_on() with phy->init_count == 0.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH v4 12/16 MAINTAINERS: add SpacemiT K3 display driver entry
In reply to Cody KangFrom: Cody Kang <[email protected]>
Cover the Saturn DPU, the Innosilicon DP/eDP controller, the DP PHY and their bindings.
---
v4:
- no change
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
@@ -26453,6 +26453,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
PATCH v4 13/16 riscv: dts: spacemit: k3: add display nodes
In reply to Cody KangFrom: 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. The PHYs take the 24 MHz oscillator as their reference.
---
v4:
- give the PHYs their reference clock
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 | 168 +++++++++++++++++++++++++++ 1 file changed, 168 insertions(+)
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +168 -0
@@ -0,0 +1,168 @@ +// 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"; + clocks = <&vctcxo_24m>; + #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"; + clocks = <&vctcxo_24m>; + #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
[email protected]
AI reviewRe: [PATCH v4 13/16] riscv: dts: spacemit: k3: add display nodes
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] riscv: dts: spacemit: k3: syscon_apmu clock-names mismatch with ccu-k3.c --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] riscv: dts: spacemit: k3: syscon_apmu clock-names mismatch with ccu-k3.c
--
commit ae676ef5f4ab9bc45c70f9e62a3c06fdadbd5d6b
Author: Cody Kang <[email protected]>
riscv: dts: spacemit: k3: add display nodes
This commit adds k3-display.dtsi defining the two Saturn DPU nodes, the two DP/eDP controller nodes with their PHY children, and an override on syscon_apmu to supply the PHY PLL pixel clocks.
Quoted 5 lines
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +0
-0
[ ... ]
arch/riscv/boot/dts/spacemit/k3-display.dtsi line 168
Quoted 10 lines
arch/riscv/boot/dts/spacemit/k3-display.dtsi new file +10
-0+/* + * 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"; +};
[Severity: High]
Do the clock-names "edp0_pll_pxclk" and "edp1_pll_pxclk" match what the K3 APMU clock driver looks up for the eDP pixel clock mux parents?
In drivers/clk/spacemit/ccu-k3.c, both edp0_pclk_parents and edp1_pclk_parents specify CCU_PARENT_NAME(external_clk), which sets .fw_name = "external_clk":
drivers/clk/spacemit/ccu-k3.c {
...static const struct clk_parent_data edp0_pclk_parents[] = {
CCU_PARENT_HW(lcd_pxclk),
CCU_PARENT_NAME(external_clk),
};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),
};
...
}Because syscon_apmu does not have a clock named "external_clk", the clock core cannot resolve the PHY PLL parent for edp0_pxclk or edp1_pxclk, and spacemit_dp_probe() -> clk_set_parent(dp->pxclk, dp->pll_clk) will fail with -EINVAL when edp0 or dp1 is enabled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
PATCH v4 14/16 riscv: dts: spacemit: k3-pico-itx: enable the DisplayPort output
In reply to Cody KangFrom: 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.
---
v4:
- sort the DisplayPort overrides into the file; name the pin group child after its group
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
@@ -6,6 +6,7 @@ #include <dt-bindings/gpio/gpio.h> #include "k3.dtsi" +#include "k3-display.dtsi" #include "k3-pinctrl.dtsi" / {
@@ -239,6 +240,16 @@ &combophy { status = "okay"; }; +&dp1 { + pinctrl-names = "default"; + pinctrl-0 = <&dp1_1_cfg>; + status = "okay"; +}; + +&dpu1_crtc0 { + status = "okay"; +}; + ð0 { pinctrl-names = "default"; pinctrl-0 = <&gmac0_rgmii_0_cfg>, <&gmac0_phy_0_cfg>;
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
@@ -11,6 +11,17 @@ #define K3_GPIO(x) (x / 32) (x % 32) &pinctrl { + /omit-if-no-ref/ + dp1_1_cfg: dp1-1-cfg { + dp1-1-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
PATCH v4 15/16 riscv: dts: spacemit: k3-com260-ifx: enable the DisplayPort output
In reply to Cody KangFrom: Cody Kang <[email protected]>
CoM260-IFX carries a single DisplayPort output. Enable the second DPU and the DisplayPort controller it feeds.
---
v4:
- sort the DisplayPort overrides into the file; name the pin group child after its group
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
@@ -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";
@@ -60,6 +73,20 @@ &combophy { status = "okay"; }; +&dp1 { + pinctrl-names = "default"; + pinctrl-0 = <&dp1_3_cfg>; + status = "okay"; +}; + +&dp1_out { + remote-endpoint = <&dp1_connector_in>; +}; + +&dpu1_crtc0 { + status = "okay"; +}; + &i2c1 { pinctrl-names = "default"; pinctrl-0 = <&i2c1_1_cfg>;
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi +11 -0
@@ -22,6 +22,17 @@ dp1-1-pins { }; }; + /omit-if-no-ref/ + dp1_3_cfg: dp1-3-cfg { + dp1-3-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
PATCH v4 16/16 riscv: defconfig: spacemit: k3: enable display driver
In reply to Cody KangFrom: Cody Kang <[email protected]>
Enable the Saturn DPU as a module, matching the other DRM drivers in this defconfig, and the DP/eDP controller, which is built into that module; the DP PHY follows through the controller's select. Enable the display connector driver as well: the CoM260-IFX ends its DisplayPort output in a dp-connector node.
---
v4:
- SPACEMIT_INNO_DP is a bool now (Guodong Xu)
- enable DRM_DISPLAY_CONNECTOR, which the CoM260-IFX DisplayPort output needs
v3:
- no change
v2:
- no change
--- arch/riscv/configs/defconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/riscv/configs/defconfig +3 -0
@@ -192,8 +192,11 @@ CONFIG_MEDIA_SUPPORT=m CONFIG_MEDIA_PLATFORM_SUPPORT=y CONFIG_VIDEO_CADENCE_CSI2RX=m CONFIG_DRM=m +CONFIG_DRM_DISPLAY_CONNECTOR=m CONFIG_DRM_RADEON=m CONFIG_DRM_NOUVEAU=m +CONFIG_DRM_SPACEMIT=m +CONFIG_SPACEMIT_INNO_DP=y CONFIG_DRM_SUN4I=m CONFIG_DRM_VIRTIO_GPU=m CONFIG_FB=y
Signature · 1 line
2.43.0