Skip to contentSkip to conversation

drm/cix: add Sky1 DisplayPort transmitter

PATCH Superseded Luo Liu 3 participants 7 messages Nov 17 – Nov 18

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luo Liu

author
#0 lore raw

v2 cover drm/cix: add Sky1 DisplayPort transmitter

Add the CIX Sky1 DisplayPort transmitter as a DRM bridge. The USB-C transmitters and the native DP/eDP transmitter use separate compatibles because their RCSU video-adapter layouts differ. The Sky1 devicetree nodes are not included in this posting.

Scope: DPTX hardware and bindings only. Komeda (the Sky1 display controller that feeds these bridges) and the board DTS are separate series. Nothing in this posting wires a full display stack.

Connector handling in this driver:

The Komeda display pipeline (ARM Mali DPU on Sky1, posted separately) calls drm_bridge_attach() with attach flags 0 and does not register a connector for these DP outputs. This driver therefore registers a DisplayPort drm_connector from bridge .attach(). Detect, EDID read, mode enumeration and validation run through drm_connector_funcs and helper hooks on that connector.

v1 -> v2:
- Split the compatible into "cix,sky1-usbdp" and "cix,sky1-dp", and rename the binding to cix,sky1-dp.yaml.
- Drop cix,adapter-port, cix,stream-id and cix,dp-max-rate. Every transmitter uses stream 0, and the maximum link rate is HBR2.
- Require phys and port in the binding; example follows Sky1-Orion graph (DPU pipeline@0 to DPTX, USB-C dp-port PHY).
- Keep only the documented DPTX node in the binding example; reference the DPU and USB-C PHY through phandles instead of copying their nodes.
- Allow COMPILE_TEST.
- Serialize mode selection with link retraining, and roll back the PHY and the IRQ disable depth when enable or resume fails.
- Pair phy_init/phy_exit with host_init/deinit; use phy_power_on/off only from core_on/off.
- Stop active streams before host teardown on remove and shutdown.
- Match YCbCr 4:2:0 against the original CEA mode, and avoid a 64-bit division in the pixel-clock adjustment.
- Initialize train_done before the clock-recovery and channel-equalization loops.
- Serialize sessions with a plain mutex and AUX with a separate lock instead of a hand-written recursive lock; use ops->session_lock in DRM paths and _locked helpers for the internal steps. Document the session_lock -> aux_lock order.
- Roll back the bridge enable path with an explicit unprepare step when mode selection or stream enable fails.
- Poll the PHY ready status with readl_poll_timeout(), check only the AUX reply field that matches the request type, and drop the redundant DPCD power-up retry loop.
- Wait for AUX reply with readl_poll_timeout(); register devm teardown via devm_add_action_or_reset().
- Document INTERRUPT_CAUSE read-to-clear (Sky1 TRM).
- Use GENMASK()/FIELD_PREP() for adapter format fields; drop unused link-training parameters.

Luo Liu (2):
dt-bindings: display: add CIX Sky1 DisplayPort transmitter drm/cix: add Sky1 DisplayPort transmitter driver

 .../bindings/display/cix,sky1-dp.yaml         |   99 +
 MAINTAINERS                                   |    9 +
 drivers/gpu/drm/Kconfig                       |    1 +
 drivers/gpu/drm/Makefile                      |    1 +
 drivers/gpu/drm/cix/Kconfig                   |    3 +
 drivers/gpu/drm/cix/Makefile                  |    3 +
 drivers/gpu/drm/cix/dptx/Kconfig              |   17 +
 drivers/gpu/drm/cix/dptx/Makefile             |    4 +
 drivers/gpu/drm/cix/dptx/cix_dptx.c           | 2434 +++++++++++++++++
 drivers/gpu/drm/cix/dptx/cix_dptx.h           |  408 +++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c       |  771 ++++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h       |   16 +
 12 files changed, 3766 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
 create mode 100644 drivers/gpu/drm/cix/Kconfig
 create mode 100644 drivers/gpu/drm/cix/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/Kconfig
 create mode 100644 drivers/gpu/drm/cix/dptx/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.h
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

author
#1 lore raw

PATCH v2 1/2 dt-bindings: display: add CIX Sky1 DisplayPort transmitter

Document the CIX Sky1 DisplayPort transmitter. Each instance sits between one of the SoC display pipelines and a DisplayPort PHY, and exposes the DP register block together with the RCSU block used for the link setup.

The USB-C transmitters and the native DP/eDP transmitter use different RCSU layouts, described by "cix,sky1-usbdp" and "cix,sky1-dp". The controller is a DRM bridge. Its video input is linked through the OF graph, and the DisplayPort PHY is referenced through the generic PHY framework.

---
 .../bindings/display/cix,sky1-dp.yaml         | 99 +++++++++++++++++++
 MAINTAINERS                                   |  8 ++
 2 files changed, 107 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
Documentation/devicetree/bindings/display/cix,sky1-dp.yaml new file +99 -0
new file mode 100644
index 000000000000..ec6d02989b58
@@ -0,0 +1,99 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/cix,sky1-dp.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CIX Sky1 Trilinear DisplayPort Transmitter
+
+maintainers:
+  - Luo Liu <[email protected]>
+
+description:
+  Trilinear DisplayPort transmitter on CIX Sky1. The USB-C transmitters
+  and the native DP/eDP transmitter use different RCSU video-adapter
+  register offsets and bit layouts, so each has its own compatible.
+
+properties:
+  compatible:
+    oneOf:
+      - description: USB-C DisplayPort transmitter
+        const: cix,sky1-usbdp
+      - description: Native DP/eDP transmitter
+        const: cix,sky1-dp
+
+  reg:
+    items:
+      - description: DisplayPort transmitter registers.
+      - description: RCSU video adapter registers used for link setup.
+
+  reg-names:
+    items:
+      - const: dp
+      - const: rcsu
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: APB clock of the controller.
+      - description: Video clock of stream 0.
+      - description: Video clock of stream 1.
+
+  clock-names:
+    items:
+      - const: apb
+      - const: vid0
+      - const: vid1
+
+  resets:
+    maxItems: 1
+    description: DisplayPort controller reset.
+
+  phys:
+    maxItems: 1
+    description: DisplayPort PHY the controller transmits through.
+
+  port:
+    $ref: /schemas/graph.yaml#/properties/port
+    description:
+      Video input from the Mali D71 display pipeline (Komeda) that drives
+      this controller. The link to the sink is through phys (USB-C combo PHY
+      or the native DP PHY), not a second OF graph port on the DPTX.
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - phys
+  - port
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    dp0: dp@14064000 {
+        compatible = "cix,sky1-usbdp";
+        reg = <0x14064000 0x4000>,
+              <0x14050000 0x400>;
+        reg-names = "dp", "rcsu";
+        interrupts = <GIC_SPI 332 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&dpc0_apb>, <&dpc0_vid0>, <&dpc0_vid1>;
+        clock-names = "apb", "vid0", "vid1";
+        resets = <&dpc0_rst>;
+        phys = <&usbc0_dp_phy>;
+
+        port {
+            dp0_0_in: endpoint {
+                remote-endpoint = <&dpu0_pipe0_out>;
+            };
+        };
+    };
MAINTAINERS +8 -0
index 93abbb315065..e3557e931c94 100644
@@ -6522,6 +6522,14 @@ M:	Satish Kharat <[email protected]>
 S:	Supported
 F:	drivers/infiniband/hw/usnic/
 
+CIX SKY1 DISPLAYPORT TRANSMITTER DRIVER
+M:	Luo Liu <[email protected]>
+M:	Wuyi Shen <[email protected]>
+R:	CIX Linux Kernel Upstream Group <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+
 CLANG CONTEXT ANALYSIS
 M:	Marco Elver <[email protected]>
 R:	Bart Van Assche <[email protected]>
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: display: add CIX Sky1 DisplayPort transmitter

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] dt-bindings: display: cix,sky1-dp: missing output port in OF graph schema - [Low] dt-bindings…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] dt-bindings: display: cix,sky1-dp: missing output port in OF graph schema
- [Low] dt-bindings: display: cix,sky1-dp: unused labels in DTS example --

commit d98f4d4238cf91c13498054d6c8b154975a5d02b
Author: Luo Liu <[email protected]>

dt-bindings: display: add CIX Sky1 DisplayPort transmitter

This commit adds the Devicetree binding schema and MAINTAINERS entry for the CIX Sky1 DisplayPort and USB-C DisplayPort transmitters.

Quoted 5 lines
Documentation/devicetree/bindings/display/cix,sky1-dp.yaml new file +0 -0
new file mode 100644
index 0000000000000..ec6d02989b580

[ ... ]

Documentation/devicetree/bindings/display/cix,sky1-dp.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/display/cix,sky1-dp.yaml new file +10 -0
+  phys:
+    maxItems: 1
+    description: DisplayPort PHY the controller transmits through.
+
+  port:
+    $ref: /schemas/graph.yaml#/properties/port
+    description:
+      Video input from the Mali D71 display pipeline (Komeda) that drives
+      this controller. The link to the sink is through phys (USB-C combo PHY
+      or the native DP PHY), not a second OF graph port on the DPTX.

[Severity: Medium]
Should this binding use ports with port@0 for the video input and port@1 for the DisplayPort or eDP output instead of a single port property?

The phys property only references the local SoC PHY block, whereas downstream display sinks such as dp-connector, eDP panels, and USB-C connectors or muxes link to the transmitter output endpoint via the OF graph (and eDP panels may also sit under an aux-bus child node). With only a single port defined and additionalProperties set to false, board devicetrees cannot describe the connection to the downstream sink without failing dtbs_check.

[ ... ]

Quoted 11 lines
Documentation/devicetree/bindings/display/cix,sky1-dp.yaml new file +11 -0
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    dp0: dp@14064000 {
+        compatible = "cix,sky1-usbdp";
+        reg = <0x14064000 0x4000>,
+              <0x14050000 0x400>;
+        reg-names = "dp", "rcsu";
+        interrupts = <GIC_SPI 332 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&dpc0_apb>, <&dpc0_vid0>, <&dpc0_vid1>;

Documentation/devicetree/bindings/display/cix,sky1-dp.yaml line 99

Quoted 10 lines
Documentation/devicetree/bindings/display/cix,sky1-dp.yaml new file +10 -0
+        clock-names = "apb", "vid0", "vid1";
+        resets = <&dpc0_rst>;
+        phys = <&usbc0_dp_phy>;
+
+        port {
+            dp0_0_in: endpoint {
+                remote-endpoint = <&dpu0_pipe0_out>;
+            };
+        };
+    };

[Severity: Low]
Can the unused labels dp0 and dp0_0_in be dropped from the example? Unreferenced labels in binding examples trigger warnings from scripts/dtc/dt-check-style in strict mode.

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

PATCH v2 2/2 drm/cix: add Sky1 DisplayPort transmitter driver

In reply to Luo Liu

Add a DRM bridge driver for the CIX Sky1 DisplayPort transmitter. The controller implements the DP link training and the source side of the DisplayPort protocol, and is fed by one of the SoC display pipelines.

The transmitter is exposed as a DRM bridge. The Komeda display pipeline (ARM Mali DPU on Sky1) that feeds these outputs is not part of this series. Komeda calls drm_bridge_attach() with attach flags 0 and does not register a connector, so this driver registers a DisplayPort drm_connector from .attach(). That matches how Sky1 is integrated today and gives userspace a connector on the encoder.

The connector reads EDID, validates modes against link bandwidth, supports YCbCr 4:2:0 and signals hotplug through drm_helper_hpd_irq_event().

The DisplayPort PHY is driven through the generic PHY API: link-rate and voltage-swing updates are forwarded to the PHY and the link is retrained when the sink requests it. Audio and DSC are not supported yet.

---
 MAINTAINERS                             |    1 +
 drivers/gpu/drm/Kconfig                 |    1 +
 drivers/gpu/drm/Makefile                |    1 +
 drivers/gpu/drm/cix/Kconfig             |    3 +
 drivers/gpu/drm/cix/Makefile            |    3 +
 drivers/gpu/drm/cix/dptx/Kconfig        |   17 +
 drivers/gpu/drm/cix/dptx/Makefile       |    4 +
 drivers/gpu/drm/cix/dptx/cix_dptx.c     | 2434 +++++++++++++++++++++++
 drivers/gpu/drm/cix/dptx/cix_dptx.h     |  408 ++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c |  771 +++++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h |   16 +
 11 files changed, 3659 insertions(+)
 create mode 100644 drivers/gpu/drm/cix/Kconfig
 create mode 100644 drivers/gpu/drm/cix/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/Kconfig
 create mode 100644 drivers/gpu/drm/cix/dptx/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.h
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h
MAINTAINERS +1 -0
index e3557e931c94..3cc8c8865793 100644
@@ -6529,6 +6529,7 @@ R:	CIX Linux Kernel Upstream Group <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+F:	drivers/gpu/drm/cix/dptx/
 
 CLANG CONTEXT ANALYSIS
 M:	Marco Elver <[email protected]>
drivers/gpu/drm/Kconfig +1 -0
index 61111d50b1c6..a1808db8b9c8 100644
@@ -311,6 +311,7 @@ source "drivers/gpu/drm/aspeed/Kconfig"
 source "drivers/gpu/drm/ast/Kconfig"
 source "drivers/gpu/drm/atmel-hlcdc/Kconfig"
 source "drivers/gpu/drm/bridge/Kconfig"
+source "drivers/gpu/drm/cix/Kconfig"
 source "drivers/gpu/drm/etnaviv/Kconfig"
 source "drivers/gpu/drm/exynos/Kconfig"
 source "drivers/gpu/drm/fsl-dcu/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 2c6bc093a923..6ed7456bb993 100644
@@ -169,6 +169,7 @@ obj-y			+= tests/
 obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
 obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o
 obj-y			+= arm/
+obj-y			+= cix/
 obj-y			+= clients/
 obj-y			+= display/
 obj-$(CONFIG_DRM_TTM)	+= ttm/
drivers/gpu/drm/cix/Kconfig new file +3 -0
new file mode 100644
index 000000000000..6cbaa5bf9fe9
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+source "drivers/gpu/drm/cix/dptx/Kconfig"
drivers/gpu/drm/cix/Makefile new file +3 -0
new file mode 100644
index 000000000000..a93591fc49e8
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_DRM_CIX_DP) += dptx/
drivers/gpu/drm/cix/dptx/Kconfig new file +17 -0
new file mode 100644
index 000000000000..547d50209612
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DRM_CIX_DP
+	tristate "Cix DisplayPort Controller Driver"
+	depends on ARCH_CIX || COMPILE_TEST
+	depends on COMMON_CLK && DRM && OF
+	depends on GENERIC_PHY
+	select DRM_KMS_HELPER
+	select DRM_DISPLAY_HELPER
+	select DRM_DISPLAY_DP_HELPER
+	help
+	  DRM/KMS driver for the Cix DisplayPort controller. It implements
+	  the standard DRM bridge interface and drives an external
+	  DisplayPort PHY through the generic PHY framework.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called cix-dptx.
drivers/gpu/drm/cix/dptx/Makefile new file +4 -0
new file mode 100644
index 000000000000..d156178d9a34
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+cix-dptx-y := cix_dptx.o cix_dptx_drm.o
+obj-$(CONFIG_DRM_CIX_DP) += cix-dptx.o
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +2434 -0

2,434 lines not on this page · raw message

drivers/gpu/drm/cix/dptx/cix_dptx.h new file +408 -0

408 lines not on this page · raw message

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +771 -0

110 lines not on this page · raw message

drivers/gpu/drm/cix/dptx/cix_dptx_drm.h new file +16 -0
new file mode 100644
index 000000000000..3ac57faa349e

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#4 lore raw

Re: [PATCH v2 2/2] drm/cix: add Sky1 DisplayPort transmitter driver

Thank you for your contribution! Sashiko AI review found 22 potential issues to consider: - [High] drm/cix/dptx: wrong callback signature for cix_dptx_dev_release() - [High] drm/cix/dptx: unlocked…

Thank you for your contribution! Sashiko AI review found 22 potential issues to consider:
- [High] drm/cix/dptx: wrong callback signature for cix_dptx_dev_release()
- [High] drm/cix/dptx: unlocked crtc->state access in cix_dp_get_mode() on HPD IRQ
- [High] drm/cix/dptx: __cix_dp_detect() ignores connect error and skips disconnect
- [High] drm/cix/dptx: suspend race in cix_dp_pm_prepare() and lost OOB HPD
- [High] drm/cix: uninitialized connector->fwnode breaks USB-C OOB hotplug events
- [High] drm/cix: premature drm_connector_cleanup() in cix_dp_bridge_detach()
- [High] drm/cix: use-after-free and destroyed mutex lock after device unbind
- [Medium] drm/cix/dptx: broken VSC SDP colorimetry in cix_dp_needs_vsc_sdp()
- [Medium] drm/cix/dptx: bridge PM callbacks toggle drm_device polling
- [Medium] drm/cix/dptx: DPTX_STATE_SUSPENDED blocks cix_dpcd_power_down() on suspend
- [Medium] drm/cix/dptx: CIX_DPTX_ENHANCED_FRAMING_ENABLE not cleared in cix_dp_link_configure()
- [Medium] drm/cix/dptx: hpd_event_work queued on multiple workqueues
- [Medium] drm/cix: unhandled DRM_BRIDGE_ATTACH_NO_CONNECTOR in cix_dp_bridge_attach()
- [Medium] drm/cix: force_hpd overwritten during suspend in cix_dp_oob_hotplug_event()
- [Medium] drm/cix: overly strict minbpp in cix_dp_connector_mode_valid() for fallback formats
- [Medium] drm/cix: late crtc_state->mode_changed assignment in cix_dp_bridge_atomic_check()
- [Medium] drm/cix: unlocked sink cap reads in atomic_check/mode_valid and HPD status race
- [Medium] drm/cix: unchecked connector->state allocation in cix_dp_connector_create()
- [Medium] drm/cix: broken sync polarity flags and pixel clock check in cix_dp_adjust_mode()
- [Medium] drm/cix: unlocked drm_helper_probe_detect() in cix_dp_hpd_event_work_func()
- [Low] drm/cix: missing error on RBR downshift in cix_dp_mode_configure()
- [Low] drm/cix: missing content_type check in cix_dp_bridge_atomic_check()
--

commit 91969ec67c0ae274ce458c0bfa9354271adf193d
Author: Luo Liu <[email protected]>

drm/cix: add Sky1 DisplayPort transmitter driver

This commit adds a DRM bridge driver for the CIX Sky1 DisplayPort transmitter, handling DP link training, EDID probing, mode validation, YCbCr 4:2:0 output, and hotplug events.

Quoted 5 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +0 -0
new file mode 100644
index 0000000000000..882c4a92f5118

[ ... ]

Quoted 14 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +14 -0
+static int cix_dp_mode_configure(struct cix_dp *dp, int pclk, u8 bw, u8 bpp,
+				 bool downshift)
+{
+	int max_rate = dp->link_config.max_rate;
+	int lane_cnt;
+	int bw_code;
+	int link_rate;
+
+	if (!downshift)
+		bw_code = bw;
+	else
+		switch (bw) {
+		case DP_LINK_BW_8_1:
+			bw_code = DP_LINK_BW_5_4;

drivers/gpu/drm/cix/dptx/cix_dptx.c line 198

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+			break;
+		case DP_LINK_BW_5_4:
+			bw_code = DP_LINK_BW_2_7;
+			break;
+		case DP_LINK_BW_2_7:
+			bw_code = DP_LINK_BW_1_62;
+			break;
+		case DP_LINK_BW_1_62:
+			bw_code = DP_LINK_BW_1_62;
+			break;

[Severity: Low]
Should downshifting from DP_LINK_BW_1_62 return -EINVAL instead of keeping DP_LINK_BW_1_62 and returning 0?

cix_dp_train_loop() only breaks out of its inner downshift loop when cix_dp_mode_configure() returns a negative error, so returning 0 causes it to repeat training at 1.62 Gbps up to four times per outer loop iteration.

[ ... ]

drivers/gpu/drm/cix/dptx/cix_dptx.c line 296

Quoted 12 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +12 -0
+static int cix_dp_link_configure(struct cix_dp *dp)
+{
+	u8 bw_code = dp->mode.bw_code;
+	u8 lane_cnt = dp->mode.lane_cnt;
+	int ret;
+
+	cix_dp_write(dp, CIX_DPTX_LANE_COUNT_SET, lane_cnt);
+
+	if (dp->caps.enhanced_framing) {
+		cix_dp_write(dp, CIX_DPTX_ENHANCED_FRAMING_ENABLE, 1);
+		lane_cnt |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
+	}

[Severity: Medium]
Does cix_dp_link_configure() leave CIX_DPTX_ENHANCED_FRAMING_ENABLE set to 1 when switching to a sink that does not support enhanced framing?

cix_dp_core_off() does not reset the transmitter when a stream is disabled, so if a sink without enhanced framing is connected after one that enabled it, the transmitter keeps sending enhanced framing while DP_LANE_COUNT_ENHANCED_FRAME_EN is cleared in the sink's DPCD.

[ ... ]

Quoted 44 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +44 -0
+	value = (mode->htotal - mode->hdisplay) *
+		(dp->mode.link_rate / 40) * 9 / mode->clock;
+
+	cix_dp_write(dp, CIX_DPTX_SECONDARY_DATA_WINDOW(stream_id), value);
+	cix_dp_write(dp, CIX_DPTX_DATA_CONTROL(stream_id), data_control);
+	cix_dp_write(dp, CIX_DPTX_USER_PIXEL_COUNT(stream_id),
+		     dp->pixel_per_cycle);
+}
+
+static struct drm_display_mode *cix_dp_get_mode(struct cix_dp *dp,
+						int stream_id)
+{
+	struct drm_crtc *crtc;
+
+	if (stream_id < 0 || stream_id >= dp->max_streams)
+		return NULL;
+
+	if (!dp->active_panels[stream_id] || !dp->bridge.encoder)
+		return NULL;
+
+	crtc = dp->bridge.encoder->crtc;
+	if (!crtc || !crtc->state)
+		return NULL;
+
+	return &crtc->state->adjusted_mode;
+}
+
+/*
+ * Link retraining can lower the bandwidth or the lane count while a stream
+ * is already enabled. TU and timing were programmed for the previous link,
+ * so write them again from the trained mode.
+ */
+static void cix_dp_update_active_streams(struct cix_dp *dp)
+{
+	struct cix_dp_panel *panel;
+	struct drm_display_mode *mode;
+	int bpp;
+	int i;
+
+	for (i = 0; i < dp->max_streams; i++) {
+		panel = dp->active_panels[i];
+		if (!panel || !panel->connector)
+			continue;
+

drivers/gpu/drm/cix/dptx/cix_dptx.c line 573

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+		mode = cix_dp_get_mode(dp, i);
+		if (!mode)
+			continue;
+
+		bpp = panel->connector->config.bpp;
+		cix_dp_mode_set_transfer_unit(dp, panel->source_id, mode,
+					      bpp);
+		cix_dp_mode_set_timing(dp, panel->source_id, mode, bpp);
+	}
+}

[Severity: High]
Can cix_dp_get_mode() cause a use-after-free on crtc->state or a divide-by-zero in cix_dp_mode_set_timing() when called from cix_dp_hpd_irq_work_func()?

cix_dp_hpd_irq_work_func() runs under dp->session_lock without holding crtc->mutex, while a concurrent atomic commit (such as a page flip or CRTC disable) swaps and frees crtc->state without taking dp->session_lock:

CPU0 (atomic commit) CPU1 (hpd_irq_work)
drm_atomic_helper_commit() cix_dp_hpd_irq_work_func()

                                    cix_dp_train_loop()
                                      cix_dp_update_active_streams()
                                        mode = cix_dp_get_mode()
                                          return &crtc->state->adjusted_mode
  drm_atomic_helper_swap_state()
  drm_atomic_commit_put()
    kfree(old_crtc_state)
                                        cix_dp_mode_set_timing(..., mode, ...)
                                          ... / mode->clock  <-- UAF

If a CRTC disable commit has just swapped in a disabled crtc->state before cix_dp_bridge_atomic_disable() acquires dp->session_lock, mode->clock is 0 and cix_dp_mode_set_timing() also divides by zero. Caching adjusted_mode in struct cix_dp under dp->session_lock during cix_dp_bridge_mode_set() would avoid touching crtc->state from the HPD worker.

[ ... ]

Quoted 16 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +16 -0
+static ssize_t cix_dp_aux_transfer(struct drm_dp_aux *aux,
+				   struct drm_dp_aux_msg *msg)
+{
+	struct cix_dp *dp = container_of(aux, struct cix_dp, aux);
+	size_t to_access = 0;
+	size_t accessed_bytes = 0;
+	u32 reply_mask;
+	u32 reply_ack;
+	u32 state;
+	ssize_t ret;
+
+	/*
+	 * AUX has its own lock instead of session_lock: the driver calls
+	 * drm_dp_*() helpers while holding session_lock, and those helpers
+	 * re-enter aux->transfer. host_init() and host_deinit() take this
+	 * lock while they enable or gate the APB clock.

drivers/gpu/drm/cix/dptx/cix_dptx.c line 698

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+	 */
+	mutex_lock(&dp->aux_lock);
+
+	state = READ_ONCE(dp->state);
+	if (!(state & DPTX_STATE_INITIALIZED) ||
+	    (state & DPTX_STATE_SUSPENDED) ||
+	    (!cix_dp_get_hpd_state(dp) && !READ_ONCE(dp->aux_ignore_hpd))) {
+		ret = -ENODEV;
+		goto out;
+	}

[Severity: Medium]
Does rejecting AUX transfers when DPTX_STATE_SUSPENDED is set prevent cix_dpcd_power_down() from putting the sink into D3 during suspend and shutdown?

cix_dp_pm_prepare() sets DPTX_STATE_SUSPENDED before cix_dp_host_deinit() or the KMS atomic disable path calls cix_dp_core_off() -> cix_dpcd_power_down(). Because DPTX_STATE_INITIALIZED remains set while apb_clk is enabled, checking only !(state & DPTX_STATE_INITIALIZED) here would allow the D3 write to complete before cix_dp_host_deinit() gates the clock.

[ ... ]

Quoted 9 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +9 -0
+static bool cix_dp_needs_vsc_sdp(enum cix_dp_format output_format,
+				 int colorspace)
+{
+	if (output_format == CIX_DP_FORMAT_YCBCR420)
+		return true;
+
+	switch (colorspace) {
+	case DRM_MODE_COLORIMETRY_SYCC_601:
+	case DRM_MODE_COLORIMETRY_OPYCC_601:

drivers/gpu/drm/cix/dptx/cix_dptx.c line 863

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+	case DRM_MODE_COLORIMETRY_BT2020_YCC:
+	case DRM_MODE_COLORIMETRY_BT2020_RGB:
+	case DRM_MODE_COLORIMETRY_BT2020_CYCC:
+		return true;
+	default:
+		break;
+	}
+
+	return false;
+}

[Severity: Medium]
Why does cix_dp_needs_vsc_sdp() omit the DCI-P3 and xvYCC colorimetries that cix_dp_vsc_colorimetry() handles?

Because the non-VSC path in cix_dp_set_misc() never writes colorimetry bits to MISC0, selecting DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, DRM_MODE_COLORIMETRY_XVYCC_601, or DRM_MODE_COLORIMETRY_XVYCC_709 on an RGB, YCbCr 4:4:4, or YCbCr 4:2:2 stream leaves VSC SDP disabled and makes the DCI-P3 cases in cix_dp_vsc_colorimetry() unreachable for RGB.

In addition, cix_dp_vsc_colorimetry() maps colorspace without checking whether it matches the active pixel format, so YCbCr 4:2:0 with DCI-P3 emits 0x4 (which encodes sYCC601 in a YCbCr VSC SDP), RGB with BT2020_YCC emits 0x7 (Reserved for RGB), and a YCbCr fallback with BT2020_RGB emits 0x6 (BT2020_CYCC instead of BT2020_YCC).

[ ... ]

Quoted 21 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +21 -0
+static int __cix_dp_detect(struct cix_dp *dp)
+{
+	int ret;
+
+	lockdep_assert_held(&dp->session_lock);
+
+	/*
+	 * This task is the HPD worker and suspend is already published.
+	 * Leave the IRQ and the host down. A modeset on another task still
+	 * goes through cix_dp_resume_locked().
+	 */
+	if ((dp->state & DPTX_STATE_SUSPENDED) &&
+	    READ_ONCE(dp->hpd_worker) == current)
+		return -EBUSY;
+
+	ret = cix_dp_resume_locked(dp);
+	if (ret)
+		return ret;
+
+	if (!(dp->state & DPTX_STATE_INITIALIZED)) {
+		dev_warn_once(dp->dev, "detect with uninitialized host\n");

drivers/gpu/drm/cix/dptx/cix_dptx.c line 1643

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+		return -ENODEV;
+	}
+
+	if (!cix_dp_get_hpd_state(dp))
+		return -ENODEV;
+
+	cix_dp_handle_connect_locked(dp);
+
+	return 0;
+}

[Severity: High]
Does __cix_dp_detect() report a connected sink even when cix_dp_handle_connect_locked() fails to read the DPCD, and leave DPTX_STATE_CONNECTED set when HPD is deasserted?

If cix_dp_panel_read_sink_caps() fails over AUX, __cix_dp_detect() still returns 0, so cix_dp_connector_detect() reports connector_status_connected with zeroed dp->caps and stale dp->dpcd, and the next modeset fails with -ENODEV in cix_dp_prepare(). Conversely, when !cix_dp_get_hpd_state(dp), returning -ENODEV without calling cix_dp_handle_disconnect_locked(dp) leaves DPTX_STATE_CONNECTED set across an unplug/replug if a poll runs before hpd_event_work, causing cix_dp_handle_connect_locked() to skip reading the new sink's DPCD.

[ ... ]

Quoted 7 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +7 -0
+	drm_helper_probe_detect(&dp->connector.base, NULL, false);
+
+	cix_dp_session_lock(dp);
+	status = dp->status;
+	if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+	    !cix_dp_regs_accessible(dp)) {
+		cix_dp_session_unlock(dp);

drivers/gpu/drm/cix/dptx/cix_dptx.c line 1812

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+		goto out;
+	}
+	if (status == connector_status_connected)
+		cix_dp_handle_connect_locked(dp);
+	else
+		cix_dp_handle_disconnect_locked(dp);
+	cix_dp_session_unlock(dp);
+
+	if (old_status != status && dp->drm)
+		drm_helper_hpd_irq_event(dp->drm);

[Severity: Medium]
Why does cix_dp_hpd_event_work_func() call drm_helper_probe_detect() without holding dp->drm->mode_config.mutex before calling drm_helper_hpd_irq_event()?

When ctx is NULL, drm_helper_probe_detect() only takes mode_config.connection_mutex while reading connector->status and incrementing connector->epoch_counter, which are protected by mode_config.mutex, and then drm_helper_hpd_irq_event() immediately runs detection a second time under mode_config.mutex. Moreover, if cix_dp_replay_deferred_hotplug() schedules hpd_event_work during cix_dp_bridge_attach() before the KMS driver calls drm_kms_helper_poll_init(), the first drm_helper_probe_detect() updates dp->status while drm_helper_hpd_irq_event() bails out because !poll_enabled, leaving connector->status unknown and suppressing subsequent hotplug events because old_status == status.

[ ... ]

drivers/gpu/drm/cix/dptx/cix_dptx.c line 1878

Quoted 5 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +5 -0
+	if (value & CIX_DPTX_INTERRUPT_HPD_EVENT)
+		queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
+
+	if (value & CIX_DPTX_INTERRUPT_HPD_IRQ)
+		queue_delayed_work(system_freezable_wq, &dp->hpd_irq_work, 0);

[Severity: Medium]
Can queuing dp->hpd_event_work onto system_freezable_wq here while cix_dp_replay_deferred_hotplug(), cix_dp_pm_complete(), and cix_dp_oob_hotplug_event() use schedule_delayed_work() allow cix_dp_hpd_event_work_func() to run concurrently on two CPUs?

schedule_delayed_work() queues onto system_wq, and workqueue non-reentrancy only prevents concurrent execution when a work item is queued onto the same workqueue it is currently running on. Two instances of cix_dp_hpd_event_work_func() can therefore run simultaneously and race on dp->hpd_worker (and cix_dp_oob_hotplug_event() also queues dp->sw_hpd_irq_work onto system_wq instead of system_freezable_wq).

[ ... ]

drivers/gpu/drm/cix/dptx/cix_dptx.c line 1927

Quoted 4 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +4 -0
+static int cix_dp_pm_prepare(struct cix_dp *dp)
+{
+	if (dp->drm && dp->drm->mode_config.poll_enabled)
+		drm_kms_helper_poll_disable(dp->drm);

[Severity: Medium]
Should a bridge driver's PM callbacks call drm_kms_helper_poll_disable() and drm_kms_helper_poll_enable() on the shared struct drm_device?

Connector polling is device-wide state managed by the KMS master driver; calling drm_kms_helper_poll_enable(dp->drm) in cix_dp_pm_complete() re-enables polling across the whole drm_device as soon as the first cix-dptx bridge instance resumes, while the display controller and sibling bridges may still be suspended.

Quoted 12 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +12 -0
+
+	cix_dp_irq_off(dp);
+
+	/*
+	 * Publish SUSPENDED before the cancel. oob and a running HPD
+	 * worker then leave the IRQ and the host down.
+	 */
+	cix_dp_session_lock(dp);
+	dp->state |= DPTX_STATE_SUSPENDED;
+	cix_dp_session_unlock(dp);
+
+	cix_dp_cancel_hpd_works(dp);

drivers/gpu/drm/cix/dptx/cix_dptx.c line 1949

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+
+	cix_dp_session_lock(dp);
+	if (!dp->active_stream_cnt)
+		cix_dp_host_deinit(dp);
+	dp->status = connector_status_unknown;
+	dp->state &= ~DPTX_STATE_CONNECTED;
+	cix_dp_session_unlock(dp);
+
+	return 0;
+}

[Severity: High]
Can a concurrent detect or modeset between cix_dp_session_unlock() and the second cix_dp_session_lock() undo suspend and leave dp->irq enabled with apb_clk gated?

CPU0 (suspend) CPU1 (other task or hpd_worker)
cix_dp_pm_prepare()
cix_dp_irq_off(dp)
dp->state |= DPTX_STATE_SUSPENDED
cix_dp_session_unlock(dp)
cix_dp_cancel_hpd_works(dp)

                                  cix_dp_detect() / cix_dp_prepare()
                                    cix_dp_resume_locked(dp)
                                      cix_dp_host_init(dp)
                                      enable_irq(dp->irq)
                                      dp->state &= ~DPTX_STATE_SUSPENDED
  cix_dp_session_lock(dp)
  cix_dp_host_deinit(dp)
    clk_disable_unprepare(dp->apb_clk)  <-- IRQ left enabled with clock off

Any task other than dp->hpd_worker calling __cix_dp_detect() (such as userspace probing or a sibling port's hpd_event_work running drm_helper_hpd_irq_event()), or dp->hpd_worker itself calling cix_dp_prepare() via drm_helper_hpd_irq_event() -> drm_client_dev_hotplug(), will call cix_dp_resume_locked(dp) while cix_dp_pm_prepare() has dropped session_lock. In addition, cix_dp_oob_hotplug_event() overwrites dp->force_hpd with connector_status_disconnected when DPTX_STATE_SUSPENDED is set, losing any USB-C connect event that arrives during suspend.

[ ... ]

Quoted 11 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +11 -0
+static void cix_dp_deinit(struct cix_dp *dp)
+{
+	if (!(dp->state & DPTX_STATE_CONFIGURED))
+		return;
+
+	cix_dp_session_lock(dp);
+	WRITE_ONCE(dp->hpd_stopped, true);
+	cix_dp_session_unlock(dp);
+
+	cix_dp_irq_off(dp);
+	cix_dp_cancel_hpd_works(dp);

drivers/gpu/drm/cix/dptx/cix_dptx.c line 2237

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +10 -0
+
+	cix_dp_session_lock(dp);
+	cix_dp_stop_streams_locked(dp);
+	cix_dp_host_deinit(dp);
+	dp->state &= ~(DPTX_STATE_CONFIGURED);
+	cix_dp_session_unlock(dp);
+
+	mutex_destroy(&dp->session_lock);
+	mutex_destroy(&dp->aux_lock);
+}

[Severity: High]
Can unbinding the platform device while dp->bridge is still attached to an encoder cause use of destroyed mutexes and freed devm resources?

Because dp is allocated with devm_drm_bridge_alloc(), struct cix_dp outlives platform device unbind until the encoder detaches the bridge. However, devres runs cix_dp_deinit() on unbind, destroying dp->session_lock and dp->aux_lock while dp->aux is still registered and before cix_dp_bridge_detach() -> cix_dp_quiesce_hpd() locks dp->session_lock; and if cix_dp_prepare() runs in the meantime, it sees !(dp->state & DPTX_STATE_INITIALIZED) without checking DPTX_STATE_CONFIGURED and calls cix_dp_host_init(), accessing freed devm clocks, reset, PHY, and unmapped dp_iomem.

Quoted 7 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +7 -0
+
+static void cix_dptx_dev_release(struct device *dev, void *res)
+{
+	struct cix_dp *dp = res;
+
+	cix_dp_deinit(dp);
+}

[ ... ]

drivers/gpu/drm/cix/dptx/cix_dptx.c line 2347

Quoted 7 lines
drivers/gpu/drm/cix/dptx/cix_dptx.c new file +7 -0
+	ret = cix_dp_init(dp);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, cix_dptx_dev_release, dp);
+	if (ret)
+		return ret;

[Severity: High]
Does cix_dptx_dev_release() have the wrong function signature for devm_add_action_or_reset()?

devm_add_action_or_reset() expects void (*action)(void *), so this fails to build with -Werror=incompatible-pointer-types, and when invoked by devres with a single argument (dp), cix_dptx_dev_release() reads the second parameter (res) and passes an uninitialized register value to cix_dp_deinit().

Quoted 5 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +0 -0
new file mode 100644
index 0000000000000..5fc350daebfdd

[ ... ]

Quoted 9 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +9 -0
+static enum drm_connector_status
+cix_dp_connector_detect(struct drm_connector *connector, bool force)
+{
+	struct cix_dp *dp = connector_to_dp(connector);
+	enum drm_connector_status status;
+
+	if (dp->ops->detect(dp))
+		status = connector_status_disconnected;
+	else

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 67

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+		status = connector_status_connected;
+
+	dp->ops->session_lock(dp);
+	dp->status = status;
+	dp->ops->session_unlock(dp);
+	drm_dp_set_subconnector_property(connector, status, dp->dpcd,
+					 dp->downstream_ports);
+
+	return status;
+}

[Severity: Medium]
Can updating dp->status in cix_dp_connector_detect() suppress hotplug uevents in cix_dp_hpd_event_work_func(), and what protects dp->caps and dp->link_config in cix_dp_bridge_atomic_check() and cix_dp_connector_mode_valid()?

If userspace probes the connector after hpd_event_work is queued but before cix_dp_hpd_event_work_func() samples old_status = dp->status, old_status will already equal status and drm_helper_hpd_irq_event() will be skipped (and because __cix_dp_detect() does not clear DPTX_STATE_CONNECTED on disconnect, a subsequent reconnect will also skip reading the new sink's DPCD). Additionally, cix_dp_bridge_atomic_check() and cix_dp_connector_mode_valid() read dp->caps and dp->link_config without holding dp->session_lock, racing with cix_dp_panel_read_sink_caps() zeroing dp->caps before AUX reads complete.

Quoted 7 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +7 -0
+
+static void cix_dp_oob_hotplug_event(struct drm_connector *connector,
+				     enum drm_connector_status hpd_state)
+{
+	struct cix_dp *dp = connector_to_dp(connector);
+
+	dp->ops->session_lock(dp);

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 84

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+	if (READ_ONCE(dp->hpd_stopped)) {
+		dp->ops->session_unlock(dp);
+		return;
+	}
+
+	if (dp->state & DPTX_STATE_SUSPENDED) {
+		dp->force_hpd = connector_status_disconnected;
+		dp->ops->session_unlock(dp);
+		return;
+	}

[Severity: Medium]
If an out-of-band Type-C connect event arrives while DPTX_STATE_SUSPENDED is set, doesn't setting dp->force_hpd = connector_status_disconnected lose the hotplug event across resume?

On cix,sky1-usbdp where the hardware HPD pin is unwired, cix_dp_get_hpd_state() relies on dp->force_hpd; clobbering it with connector_status_disconnected instead of recording hpd_state causes the hpd_event_work scheduled by cix_dp_pm_complete() to see the connected USB-C monitor as disconnected after resume.

[ ... ]

Quoted 22 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +22 -0
+static enum drm_mode_status
+cix_dp_connector_mode_valid(struct drm_connector *connector,
+			    const struct drm_display_mode *mode)
+{
+	const struct drm_display_info *info = &connector->display_info;
+	struct cix_dp *dp = connector_to_dp(connector);
+	int max_lanes = dp->link_config.max_lanes;
+	int max_rate = dp->link_config.max_rate;
+	int clock = mode->clock;
+	u32 pixel_per_cycle = cix_dp_pick_ppc(mode, CIX_DP_FORMAT_RGB);
+	int minbpp = CIX_DP_MIN_BPP;
+
+	if (drm_mode_is_420_only(info, mode)) {
+		if (!connector->ycbcr_420_allowed || !dp->caps.vsc_supported)
+			return MODE_NO_420;
+
+		minbpp = 8 * 3 / 2;
+		pixel_per_cycle = 1;
+	}
+
+	if (pixel_per_cycle == 1 && clock > CIX_DP_MAX_FREQ) {
+		drm_mode_debug_printmodeline(mode);

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 173

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+		return MODE_CLOCK_HIGH;
+	}
+
+	if (clock > CIX_DP_MAX_RATE(max_rate, max_lanes, minbpp)) {
+		drm_mode_debug_printmodeline(mode);
+		return MODE_CLOCK_HIGH;
+	}
+
+	return MODE_OK;
+}

[Severity: Medium]
Does cix_dp_connector_mode_valid() reject modes that would fit on the link via the 8-bpc YCbCr 4:2:0 (420-also) or 8-bpc YCbCr 4:2:2 fallbacks in fmt_prio[]?

minbpp defaults to CIX_DP_MIN_BPP (18) and is only lowered to 12 for drm_mode_is_420_only(), so any 420-also mode (12 bpp) or YCbCr 4:2:2 mode (16 bpp) whose clock exceeds the 18-bpp link rate limit is rejected with MODE_CLOCK_HIGH before cix_dp_pick_format_bpc() can select those fallback formats.

[ ... ]

Quoted 22 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +22 -0
+static void cix_dp_adjust_mode(struct drm_display_mode *mode,
+			       struct drm_display_mode *adjusted_mode)
+{
+	int diff = mode->htotal - mode->hsync_end;
+
+	/*
+	 * Cix DP requires horizontal backporch to be greater than 12.
+	 * This limitation may not be compatible with the sink device.
+	 *
+	 * Everything below is derived from @mode instead of accumulating on
+	 * @adjusted_mode, so that repeated atomic checks of the same state
+	 * produce the same result.
+	 */
+	if (diff < CIX_DPTX_MIN_H_BACKPORCH) {
+		adjusted_mode->htotal = mode->htotal +
+					CIX_DPTX_MIN_H_BACKPORCH - diff;
+		adjusted_mode->clock =
+			div_u64(mul_u32_u32(mode->clock, adjusted_mode->htotal),
+				mode->htotal);
+	}
+
+	/* The sync polarities are inverted with respect to the source mode. */

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 255

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+	if (mode->flags & DRM_MODE_FLAG_PVSYNC)
+		adjusted_mode->flags &= ~DRM_MODE_FLAG_PVSYNC;
+	else
+		adjusted_mode->flags |= DRM_MODE_FLAG_PVSYNC;
+
+	if (mode->flags & DRM_MODE_FLAG_PHSYNC)
+		adjusted_mode->flags &= ~DRM_MODE_FLAG_PHSYNC;
+	else
+		adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC;
+}

[Severity: Medium]
Doesn't toggling only DRM_MODE_FLAG_PVSYNC and DRM_MODE_FLAG_PHSYNC leave adjusted_mode->flags with either both positive and negative sync flags set or neither set?

DRM_MODE_FLAG_NVSYNC and DRM_MODE_FLAG_NHSYNC need to be updated alongside PVSYNC and PHSYNC. Also, when cix_dp_adjust_mode() increases adjusted_mode->clock (or when a mode has clock >= CIX_DP_MAX_FREQ * 2 so cix_dp_pick_ppc() returns 1), cix_dp_format_ok() only checks adjusted_mode->clock against CIX_DP_MAX_FREQ for YCbCr 4:2:0 and never validates the increased pixel clock for RGB or YCbCr 4:4:4/4:2:2.

[ ... ]

Quoted 5 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +5 -0
+static int cix_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)
+{

[ ... ]

Quoted 7 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +7 -0
+	/*
+	 * The colour space is programmed through a VSC SDP, so a change of
+	 * the requested colour space requires a full modeset.
+	 */
+	if (dp->caps.vsc_supported) {
+		const struct drm_connector_state *old_conn_state;
+

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 560

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+		old_conn_state =
+			drm_atomic_get_old_connector_state(bridge_state->base.state,
+							   conn_state->connector);
+		if (old_conn_state &&
+		    old_conn_state->colorspace != conn_state->colorspace)
+			crtc_state->mode_changed = true;
+	}
+
+	return 0;
+}

[Severity: Low]
Should this also check old_conn_state->content_type != conn_state->content_type (and enable VSC SDP in cix_dp_needs_vsc_sdp() when content_type is non-zero)?

content_type is packed into the VSC SDP in dptx_setup_vsc_sdp() during cix_dp_bridge_atomic_enable(), so changing the connector content type property alone on an active stream will not update the hardware VSC SDP unless a modeset is triggered.

[ ... ]

Quoted 4 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +4 -0
+static int cix_dp_connector_atomic_check(struct drm_connector *conn,
+					 struct drm_atomic_commit *state)
+{
+	struct drm_connector_state *new_con_state =

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 633

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+		drm_atomic_get_new_connector_state(state, conn);
+
+	if (!new_con_state)
+		return 0;
+
+	/* PSR is not implemented, so never advertise self refresh support. */
+	new_con_state->self_refresh_aware = false;
+
+	return 0;
+}

[Severity: Medium]
Should the colorspace modeset check in cix_dp_bridge_atomic_check() live in cix_dp_connector_atomic_check() instead?

cix_dp_bridge_atomic_check() runs from mode_fixup() at the end of drm_atomic_helper_check_modeset(), after drm_atomic_crtc_needs_modeset() has already decided whether to add affected connectors and planes, run mode_valid(), and reset adjusted_mode from mode. Setting crtc_state->mode_changed or connectors_changed here in cix_dp_connector_atomic_check() ensures those modeset preparation steps are not skipped when colorspace changes.

[ ... ]

Quoted 8 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +8 -0
+static int cix_dp_connector_create(struct cix_dp *dp,
+				   struct drm_encoder *encoder)
+{
+	struct cix_connector *conn = &dp->connector;
+	struct drm_connector *connector = &conn->base;
+	int ret;
+
+	conn->dp = dp;

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 680

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+	connector->ycbcr_420_allowed = true;
+
+	ret = drm_connector_init_with_ddc(encoder->dev, connector,
+					  &cix_dp_connector_funcs,
+					  DRM_MODE_CONNECTOR_DisplayPort,
+					  &dp->aux.ddc);
+	if (ret)
+		return ret;

[Severity: High]
Does cix_dp_connector_create() need to set connector->fwnode so drm_connector_oob_hotplug_event() can find this connector?

drm_connector_oob_hotplug_event() looks up the target connector with drm_connector_find_by_fwnode(connector_fwnode). Because connector->fwnode is left NULL here, out-of-band hotplug notifications on cix,sky1-usbdp ports always fail with -ENODEV and never reach cix_dp_oob_hotplug_event().

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 690

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+
+	drm_connector_helper_add(connector, &cix_dp_connector_helper_funcs);
+
+	drm_atomic_helper_connector_reset(connector);
+
+	ret = drm_connector_attach_encoder(connector, encoder);
+	if (ret)
+		goto err_cleanup;
+
+	cix_dp_add_properties(connector);

[Severity: Medium]
Can cix_dp_add_properties() dereference a NULL connector->state if the allocation inside drm_atomic_helper_connector_reset() fails?

drm_connector_attach_max_bpc_property() unconditionally writes to connector->state->max_requested_bpc and connector->state->max_bpc.

[ ... ]

Quoted 11 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +11 -0
+static int cix_dp_bridge_attach(struct drm_bridge *bridge,
+				struct drm_encoder *encoder,
+				enum drm_bridge_attach_flags flags)
+{
+	struct cix_dp *dp = bridge_to_dp(bridge);
+	int ret;
+
+	dp->drm = bridge->dev;
+	WRITE_ONCE(dp->hpd_stopped, false);
+
+	ret = dp->ops->aux_register(dp);

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 721

Quoted 10 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +10 -0
+	if (ret)
+		goto err_clear_drm;
+
+	/*
+	 * Komeda (ARM Mali DPU on Sky1, not in this series) calls
+	 * drm_bridge_attach() with attach flags 0 and does not register a
+	 * connector; create one here so userspace gets a DP output.
+	 */
+	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
+		return 0;

[Severity: Medium]
Should cix_dp_bridge_attach() reject DRM_BRIDGE_ATTACH_NO_CONNECTOR with -EINVAL before registering AUX?

The bridge does not implement drm_bridge_connector callbacks (.detect, .edid_read, .get_modes, .hpd_enable/.hpd_disable), and returning 0 here leaves dp->dp_panel.connector NULL, which causes cix_dp_set_misc() to fail every stream enable with -EINVAL and cix_dp_hpd_event_work_func() to ignore hotplug events.

[ ... ]

drivers/gpu/drm/cix/dptx/cix_dptx_drm.c line 749

Quoted 11 lines
drivers/gpu/drm/cix/dptx/cix_dptx_drm.c new file +11 -0
+static void cix_dp_bridge_detach(struct drm_bridge *bridge)
+{
+	struct cix_dp *dp = bridge_to_dp(bridge);
+
+	/* Stop workers before the connector goes away. */
+	dp->ops->quiesce_hpd(dp);
+
+	dp->dp_panel.connector = NULL;
+
+	if (dp->connector.base.dev)
+		drm_connector_cleanup(&dp->connector.base);

[Severity: High]
Doesn't calling drm_connector_cleanup(&dp->connector.base) here while cix_dp_connector_funcs.destroy is also set to drm_connector_cleanup() corrupt connector refcounting during teardown?

In drm_mode_config_cleanup(), encoders (and their attached bridges) are cleaned up before the connector list and CRTC states. Calling drm_connector_cleanup() directly in cix_dp_bridge_detach() zeroes the embedded struct drm_connector while references are still held, so the subsequent drm_connector_put() underflows the zeroed refcount and dereferences a NULL connector->funcs->destroy in drm_connector_free().

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

Re: [PATCH v2 2/2] drm/cix: add Sky1 DisplayPort transmitter driver

In reply to Luo Liu

Hi,

Quoted 33 lines · Luo Liu

Add a DRM bridge driver for the CIX Sky1 DisplayPort transmitter. The controller implements the DP link training and the source side of the DisplayPort protocol, and is fed by one of the SoC display pipelines.

The transmitter is exposed as a DRM bridge. The Komeda display pipeline (ARM Mali DPU on Sky1) that feeds these outputs is not part of this series. Komeda calls drm_bridge_attach() with attach flags 0 and does not register a connector, so this driver registers a DisplayPort drm_connector from .attach(). That matches how Sky1 is integrated today and gives userspace a connector on the encoder.

The connector reads EDID, validates modes against link bandwidth, supports YCbCr 4:2:0 and signals hotplug through drm_helper_hpd_irq_event().

The DisplayPort PHY is driven through the generic PHY API: link-rate and voltage-swing updates are forwarded to the PHY and the link is retrained when the sink requests it. Audio and DSC are not supported yet.

---
 MAINTAINERS                             |    1 +
 drivers/gpu/drm/Kconfig                 |    1 +
 drivers/gpu/drm/Makefile                |    1 +
 drivers/gpu/drm/cix/Kconfig             |    3 +
 drivers/gpu/drm/cix/Makefile            |    3 +
 drivers/gpu/drm/cix/dptx/Kconfig        |   17 +
 drivers/gpu/drm/cix/dptx/Makefile       |    4 +
 drivers/gpu/drm/cix/dptx/cix_dptx.c     | 2434 +++++++++++++++++++++++
 drivers/gpu/drm/cix/dptx/cix_dptx.h     |  408 ++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c |  771 +++++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h |   16 +
 11 files changed, 3659 insertions(+)
Quoted 8 lines
 create mode 100644 drivers/gpu/drm/cix/Kconfig
 create mode 100644 drivers/gpu/drm/cix/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/Kconfig
 create mode 100644 drivers/gpu/drm/cix/dptx/Makefile
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.h
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h

This patch is too large. At least consider splitting it into two parts:
cix_dptx_drm.c and cix_dptx.c.

Quoted 12 lines
MAINTAINERS +3 -0
index e3557e931c94..3cc8c8865793 100644
@@ -6529,6 +6529,7 @@ R:	CIX Linux Kernel Upstream Group <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+F:	drivers/gpu/drm/cix/dptx/
+
+/*

[...]

Quoted 104 lines
MAINTAINERS +104 -0
+/*
+ * USB-C combo PHY only. Its HPD pin is not wired to this controller, so a
+ * sink that was plugged in before the connector existed never raises
+ * HPD_EVENT. Replay that plug once the PHY is already in DP mode and AUX
+ * answers.
+ *
+ * A native DP port wires HPD to the controller and leaves the PHY mode at
+ * PHY_MODE_INVALID, so the checks below skip it. That port is reported by
+ * the HPD interrupt instead.
+ */
+static void cix_dp_replay_deferred_hotplug(struct cix_dp *dp)
+{
+	struct phy *phy = dp->phy;
+	union phy_configure_opts opts = { 0 };
+	u8 dpcd_rev;
+	ssize_t ret;
+	bool hpd;
+
+	cix_dp_session_lock(dp);
+	if (!cix_dp_regs_accessible(dp) ||
+	    dp->force_hpd != connector_status_unknown) {
+		cix_dp_session_unlock(dp);
+		return;
+	}
+	hpd = cix_dp_get_hpd_state(dp);
+	cix_dp_session_unlock(dp);
+	if (hpd) {
+		/*
+		 * Native HPD may have fired before the connector existed.
+		 * Read the DPCD from the work now that it does.
+		 */
+		schedule_delayed_work(&dp->hpd_event_work, 0);
+		return;
+	}
+
+	phy_validate(phy, PHY_MODE_DP, 0, &opts);
+	if (phy_get_mode(phy) != PHY_MODE_DP)
+		return;
+
+	/*
+	 * The combo PHY is already muxed to DP, so the sink may have been
+	 * plugged in before the connector existed. HPD is unwired here, so
+	 * admit this one AUX transaction before force_hpd is set.
+	 */
+	cix_dp_session_lock(dp);
+	if (!cix_dp_regs_accessible(dp) ||
+	    dp->force_hpd != connector_status_unknown) {
+		cix_dp_session_unlock(dp);
+		return;
+	}
+	dp->aux_ignore_hpd = true;
+	cix_dp_session_unlock(dp);
+
+	ret = drm_dp_dpcd_readb(&dp->aux, DP_DPCD_REV, &dpcd_rev);
+
+	cix_dp_session_lock(dp);
+	dp->aux_ignore_hpd = false;
+	if (ret < 0 || !cix_dp_regs_accessible(dp)) {
+		cix_dp_session_unlock(dp);
+		return;
+	}
+	dp->force_hpd = connector_status_connected;
+	dp->status = connector_status_unknown;
+	cix_dp_session_unlock(dp);
+
+	schedule_delayed_work(&dp->hpd_event_work, 0);
+}
+
+static void cix_dp_hpd_event_work_func(struct work_struct *work)
+{
+	struct cix_dp *dp = container_of(work, struct cix_dp,
+					 hpd_event_work.work);
+	struct phy *phy = dp->phy;
+	union phy_configure_opts opts = { 0 };
+	enum drm_connector_status old_status;
+	enum drm_connector_status status;
+	enum phy_mode mode;
+	bool hpd;
+	int i;
+
+	WRITE_ONCE(dp->hpd_worker, current);
+
+	if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector)
+		goto out;
+
+	/*
+	 * Sample before the PHY wait. A probe during that wait updates
+	 * dp->status, and reading it afterwards drops the hotplug uevent.
+	 */
+	cix_dp_session_lock(dp);
+	old_status = dp->status;
+	if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+	    !cix_dp_regs_accessible(dp)) {
+		cix_dp_session_unlock(dp);
+		goto out;
+	}
+	hpd = cix_dp_get_hpd_state(dp);
+	cix_dp_session_unlock(dp);
+
+	/*
+	 * On a USB-C DP alt-mode PHY the hotplug only becomes valid once the
+	 * PHY has been switched to DP mode, so wait for the mode change.
+	 * A native DP PHY has no ->set_mode() operation, which leaves the
+	 * mode at PHY_MODE_INVALID forever; there is nothing to wait for.

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+	 */
+	if (hpd && phy_get_mode(phy) != PHY_MODE_INVALID) {
+		for (i = 0; i < DP_HPD_MAX_TRIES; i++) {
+			phy_validate(phy, PHY_MODE_DP, 0, &opts);
+			mode = phy_get_mode(phy);
+			if (mode == PHY_MODE_DP)
+				break;
+			msleep(100);
+		}
+	}

It seems you've used quite a few tricks for USB-C Alt-mode. Both the deferred_hotplug above and the polling here to wait for the PHY status to become ready.

Given that, why not consider using DRM's native bridge notifications to accomplish this? Please take a look at aux-hpd-bridge.c.

Quoted 60 lines
MAINTAINERS +60 -0
+
+	cix_dp_session_lock(dp);
+	if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+	    !cix_dp_regs_accessible(dp)) {
+		cix_dp_session_unlock(dp);
+		goto out;
+	}
+	cix_dp_session_unlock(dp);
+
+	drm_helper_probe_detect(&dp->connector.base, NULL, false);
+
+	cix_dp_session_lock(dp);
+	status = dp->status;
+	if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+	    !cix_dp_regs_accessible(dp)) {
+		cix_dp_session_unlock(dp);
+		goto out;
+	}
+	if (status == connector_status_connected)
+		cix_dp_handle_connect_locked(dp);
+	else
+		cix_dp_handle_disconnect_locked(dp);
+	cix_dp_session_unlock(dp);
+
+	if (old_status != status && dp->drm)
+		drm_helper_hpd_irq_event(dp->drm);
+out:
+	WRITE_ONCE(dp->hpd_worker, NULL);
+}
+
+static void cix_dp_hpd_irq_work_func(struct work_struct *work)
+{
+	struct cix_dp *dp = container_of(work, struct cix_dp,
+					 hpd_irq_work.work);
+	u8 status[DP_LINK_STATUS_SIZE + 2];
+	int ret;
+
+	cix_dp_session_lock(dp);
+
+	if (READ_ONCE(dp->hpd_stopped) ||
+	    !cix_dp_regs_accessible(dp) ||
+	    !(dp->state & DPTX_STATE_ENABLED) ||
+	    !cix_dp_get_hpd_state(dp))
+		goto end;
+
+	ret = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
+			       DP_LINK_STATUS_SIZE + 2);
+	if (ret < 0)
+		goto end;
+
+	if (drm_dp_clock_recovery_ok(&status[2], dp->mode.lane_cnt) &&
+	    drm_dp_channel_eq_ok(&status[2], dp->mode.lane_cnt))
+		goto end;
+
+	cix_dp_train_loop(dp);
+
+end:
+	cix_dp_session_unlock(dp);
+}
+

[...]

Quoted 41 lines
MAINTAINERS +41 -0
+
+static int cix_dptx_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const struct cix_dp_soc_data *soc_data;
+	struct cix_dp *dp;
+	int ret;
+
+	soc_data = of_device_get_match_data(dev);
+	if (!soc_data)
+		return -ENODEV;
+
+	dp = cix_dp_bridge_alloc(dev);
+	if (IS_ERR(dp))
+		return PTR_ERR(dp);
+
+	dp->dev = dev;
+	dp->native_dp = soc_data->native_dp;
+	dp->ops = &cix_dp_hw_ops;
+	dp->status = connector_status_unknown;
+	dp->force_hpd = connector_status_unknown;
+	dp->num_lanes = CIX_DPTX_MAX_LANES;
+	dp->max_rate = CIX_DP_LINK_RATE_HBR2;
+	dp->max_streams = DPTX_MST_SOURCE_NUMBER;
+	dp->dp_panel.source_id = 0;
+	dp->state = DPTX_STATE_DISCONNECTED;
+	dp->pixel_per_cycle = 1;
+
+	ret = cix_dp_parse_dt(dp);
+	if (ret)
+		return ret;
+
+	dp->link_config.max_lanes = dp->num_lanes;
+	dp->link_config.max_rate = dp->max_rate;
+
+	ret = cix_dp_init(dp);
+	if (ret)
+		return ret;
+
+	ret = devm_add_action_or_reset(dev, cix_dptx_dev_release, dp);
+	if (ret)

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+		return ret;
+
+	dev_set_drvdata(dev, dp);
+
+	dp->bridge.of_node = dev->of_node;
+
+	drm_bridge_add(&dp->bridge);
+
+	return 0;
+}

It looks like this part is platform-specific, so I think Andy's suggestion to split it out into a bridge from the beginning is reasonable.

https://lore.kernel.org/all/[email protected]/

Quoted 11 lines
MAINTAINERS +11 -0
+
+static void cix_dptx_remove(struct platform_device *pdev)
+{
+	struct cix_dp *dp = dev_get_drvdata(&pdev->dev);
+
+	if (!dp)
+		return;
+
+	drm_bridge_remove(&dp->bridge);
+}
+

[...]

Quoted 10 lines
MAINTAINERS +10 -0
+
+static int cix_dp_bridge_attach(struct drm_bridge *bridge,
+				struct drm_encoder *encoder,
+				enum drm_bridge_attach_flags flags)
+{
+	struct cix_dp *dp = bridge_to_dp(bridge);
+	int ret;
+
+	dp->drm = bridge->dev;
+	WRITE_ONCE(dp->hpd_stopped, false);

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+
+	ret = dp->ops->aux_register(dp);
+	if (ret)
+		goto err_clear_drm;
+
+	/*
+	 * Komeda (ARM Mali DPU on Sky1, not in this series) calls
+	 * drm_bridge_attach() with attach flags 0 and does not register a
+	 * connector; create one here so userspace gets a DP output.
+	 */

Please drop this comment.

Signature · 2 lines
Best, 
Chaoyi
author
#6 lore raw

回复: [PATCH v2 2/2] drm/cix: add Sky1 DisplayPort transmitter driver

Hi Chaoyi,
Thank you very much for your reply and suggestions.

Quoted 63 lines

-----邮件原件-----
发件人: Chaoyi Chen <[email protected]>
发送时间: 2026年11月18日 11:53
收件人: Luo Liu <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wuyi Shen (沈武义) <[email protected]>; cix-kernel-upstream <[email protected]>
主题: Re: [PATCH v2 2/2] drm/cix: add Sky1 DisplayPort transmitter driver

[Some people who received this message don't often get email from [email protected]. Learn why this is important at
https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL

Hi,

Quoted 20 lines · Luo Liu

Add a DRM bridge driver for the CIX Sky1 DisplayPort transmitter. The controller implements the DP link training and the source side of the DisplayPort protocol, and is fed by one of the SoC display pipelines.

The transmitter is exposed as a DRM bridge. The Komeda display pipeline (ARM Mali DPU on Sky1) that feeds these outputs is not part of this series. Komeda calls drm_bridge_attach() with attach flags 0 and does not register a connector, so this driver registers a DisplayPort drm_connector from .attach(). That matches how Sky1 is integrated today and gives userspace a connector on the encoder.

The connector reads EDID, validates modes against link bandwidth, supports YCbCr 4:2:0 and signals hotplug through drm_helper_hpd_irq_event().

The DisplayPort PHY is driven through the generic PHY API: link-rate and voltage-swing updates are forwarded to the PHY and the link is retrained when the sink requests it. Audio and DSC are not supported yet.

Quoted 9 lines
---
 MAINTAINERS                             |    1 +
 drivers/gpu/drm/Kconfig                 |    1 +
 drivers/gpu/drm/Makefile                |    1 +
 drivers/gpu/drm/cix/Kconfig             |    3 +
 drivers/gpu/drm/cix/Makefile            |    3 +
 drivers/gpu/drm/cix/dptx/Kconfig        |   17 +
 drivers/gpu/drm/cix/dptx/Makefile       |    4 +
 drivers/gpu/drm/cix/dptx/cix_dptx.c     | 2434

+++++++++++++++++++++++

Quoted 5 lines
 drivers/gpu/drm/cix/dptx/cix_dptx.h     |  408 ++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c |  771 +++++++
 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h |   16 +
 11 files changed, 3659 insertions(+)
 create mode 100644 drivers/gpu/drm/cix/Kconfig  create mode 100644
Quoted 7 lines

drivers/gpu/drm/cix/Makefile create mode 100644 drivers/gpu/drm/cix/dptx/Kconfig create mode 100644 drivers/gpu/drm/cix/dptx/Makefile create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.c

 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx.h
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.c
 create mode 100644 drivers/gpu/drm/cix/dptx/cix_dptx_drm.h
Quoted 2 lines

This patch is too large. At least consider splitting it into two parts:
cix_dptx_drm.c and cix_dptx.c.

OK,I will splitting it to 2 patchs

Quoted 133 lines

MAINTAINERS R: CIX Linux Kernel Upstream Group

Quoted 6 lines
MAINTAINERS index renamed from MAINTAINERS +0 -0

e3557e931c94..3cc8c8865793 100644

MAINTAINERS +0 -0
@@ -6529,6 +6529,7 @@ R:      CIX Linux Kernel Upstream Group

<[email protected]>

Quoted 6 lines
MAINTAINERS +3 -0
 L:   [email protected]
 S:   Maintained
 F:   Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+F:   drivers/gpu/drm/cix/dptx/
+
+/*

[...]

Quoted 92 lines
MAINTAINERS +92 -0
+/*
+ * USB-C combo PHY only. Its HPD pin is not wired to this controller,
+so a
+ * sink that was plugged in before the connector existed never raises
+ * HPD_EVENT. Replay that plug once the PHY is already in DP mode and
+AUX
+ * answers.
+ *
+ * A native DP port wires HPD to the controller and leaves the PHY
+mode at
+ * PHY_MODE_INVALID, so the checks below skip it. That port is
+reported by
+ * the HPD interrupt instead.
+ */
+static void cix_dp_replay_deferred_hotplug(struct cix_dp *dp) {
+     struct phy *phy = dp->phy;
+     union phy_configure_opts opts = { 0 };
+     u8 dpcd_rev;
+     ssize_t ret;
+     bool hpd;
+
+     cix_dp_session_lock(dp);
+     if (!cix_dp_regs_accessible(dp) ||
+         dp->force_hpd != connector_status_unknown) {
+             cix_dp_session_unlock(dp);
+             return;
+     }
+     hpd = cix_dp_get_hpd_state(dp);
+     cix_dp_session_unlock(dp);
+     if (hpd) {
+             /*
+              * Native HPD may have fired before the connector existed.
+              * Read the DPCD from the work now that it does.
+              */
+             schedule_delayed_work(&dp->hpd_event_work, 0);
+             return;
+     }
+
+     phy_validate(phy, PHY_MODE_DP, 0, &opts);
+     if (phy_get_mode(phy) != PHY_MODE_DP)
+             return;
+
+     /*
+      * The combo PHY is already muxed to DP, so the sink may have been
+      * plugged in before the connector existed. HPD is unwired here, so
+      * admit this one AUX transaction before force_hpd is set.
+      */
+     cix_dp_session_lock(dp);
+     if (!cix_dp_regs_accessible(dp) ||
+         dp->force_hpd != connector_status_unknown) {
+             cix_dp_session_unlock(dp);
+             return;
+     }
+     dp->aux_ignore_hpd = true;
+     cix_dp_session_unlock(dp);
+
+     ret = drm_dp_dpcd_readb(&dp->aux, DP_DPCD_REV, &dpcd_rev);
+
+     cix_dp_session_lock(dp);
+     dp->aux_ignore_hpd = false;
+     if (ret < 0 || !cix_dp_regs_accessible(dp)) {
+             cix_dp_session_unlock(dp);
+             return;
+     }
+     dp->force_hpd = connector_status_connected;
+     dp->status = connector_status_unknown;
+     cix_dp_session_unlock(dp);
+
+     schedule_delayed_work(&dp->hpd_event_work, 0); }
+
+static void cix_dp_hpd_event_work_func(struct work_struct *work) {
+     struct cix_dp *dp = container_of(work, struct cix_dp,
+                                      hpd_event_work.work);
+     struct phy *phy = dp->phy;
+     union phy_configure_opts opts = { 0 };
+     enum drm_connector_status old_status;
+     enum drm_connector_status status;
+     enum phy_mode mode;
+     bool hpd;
+     int i;
+
+     WRITE_ONCE(dp->hpd_worker, current);
+
+     if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector)
+             goto out;
+
+     /*
+      * Sample before the PHY wait. A probe during that wait updates
+      * dp->status, and reading it afterwards drops the hotplug uevent.
+      */
+     cix_dp_session_lock(dp);
+     old_status = dp->status;

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+     if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+         !cix_dp_regs_accessible(dp)) {
+             cix_dp_session_unlock(dp);
+             goto out;
+     }
+     hpd = cix_dp_get_hpd_state(dp);
+     cix_dp_session_unlock(dp);
+
+     /*
+      * On a USB-C DP alt-mode PHY the hotplug only becomes valid once

the

MAINTAINERS

Quoted 13 lines
MAINTAINERS +13 -0
+      * PHY has been switched to DP mode, so wait for the mode change.
+      * A native DP PHY has no ->set_mode() operation, which leaves the
+      * mode at PHY_MODE_INVALID forever; there is nothing to wait for.
+      */
+     if (hpd && phy_get_mode(phy) != PHY_MODE_INVALID) {
+             for (i = 0; i < DP_HPD_MAX_TRIES; i++) {
+                     phy_validate(phy, PHY_MODE_DP, 0, &opts);
+                     mode = phy_get_mode(phy);
+                     if (mode == PHY_MODE_DP)
+                             break;
+                     msleep(100);
+             }
+     }
Quoted 6 lines

It seems you've used quite a few tricks for USB-C Alt-mode. Both the deferred_hotplug above and the polling here to wait for the PHY status to become ready.

Given that, why not consider using DRM's native bridge notifications to accomplish this? Please take a look at aux-hpd-bridge.c.

Great advice, thanks. I'll try making the changes and test them on my local Radax O6 board.

Quoted 107 lines
Quoted 59 lines
MAINTAINERS +58 -0
+
+     cix_dp_session_lock(dp);
+     if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+         !cix_dp_regs_accessible(dp)) {
+             cix_dp_session_unlock(dp);
+             goto out;
+     }
+     cix_dp_session_unlock(dp);
+
+     drm_helper_probe_detect(&dp->connector.base, NULL, false);
+
+     cix_dp_session_lock(dp);
+     status = dp->status;
+     if (READ_ONCE(dp->hpd_stopped) || !dp->dp_panel.connector ||
+         !cix_dp_regs_accessible(dp)) {
+             cix_dp_session_unlock(dp);
+             goto out;
+     }
+     if (status == connector_status_connected)
+             cix_dp_handle_connect_locked(dp);
+     else
+             cix_dp_handle_disconnect_locked(dp);
+     cix_dp_session_unlock(dp);
+
+     if (old_status != status && dp->drm)
+             drm_helper_hpd_irq_event(dp->drm);
+out:
+     WRITE_ONCE(dp->hpd_worker, NULL); }
+
+static void cix_dp_hpd_irq_work_func(struct work_struct *work) {
+     struct cix_dp *dp = container_of(work, struct cix_dp,
+                                      hpd_irq_work.work);
+     u8 status[DP_LINK_STATUS_SIZE + 2];
+     int ret;
+
+     cix_dp_session_lock(dp);
+
+     if (READ_ONCE(dp->hpd_stopped) ||
+         !cix_dp_regs_accessible(dp) ||
+         !(dp->state & DPTX_STATE_ENABLED) ||
+         !cix_dp_get_hpd_state(dp))
+             goto end;
+
+     ret = drm_dp_dpcd_read(&dp->aux, DP_SINK_COUNT, status,
+                            DP_LINK_STATUS_SIZE + 2);
+     if (ret < 0)
+             goto end;
+
+     if (drm_dp_clock_recovery_ok(&status[2], dp->mode.lane_cnt) &&
+         drm_dp_channel_eq_ok(&status[2], dp->mode.lane_cnt))
+             goto end;
+
+     cix_dp_train_loop(dp);
+
+end:
+     cix_dp_session_unlock(dp);
+}
+

[...]

Quoted 45 lines
MAINTAINERS +45 -0
+
+static int cix_dptx_probe(struct platform_device *pdev) {
+     struct device *dev = &pdev->dev;
+     const struct cix_dp_soc_data *soc_data;
+     struct cix_dp *dp;
+     int ret;
+
+     soc_data = of_device_get_match_data(dev);
+     if (!soc_data)
+             return -ENODEV;
+
+     dp = cix_dp_bridge_alloc(dev);
+     if (IS_ERR(dp))
+             return PTR_ERR(dp);
+
+     dp->dev = dev;
+     dp->native_dp = soc_data->native_dp;
+     dp->ops = &cix_dp_hw_ops;
+     dp->status = connector_status_unknown;
+     dp->force_hpd = connector_status_unknown;
+     dp->num_lanes = CIX_DPTX_MAX_LANES;
+     dp->max_rate = CIX_DP_LINK_RATE_HBR2;
+     dp->max_streams = DPTX_MST_SOURCE_NUMBER;
+     dp->dp_panel.source_id = 0;
+     dp->state = DPTX_STATE_DISCONNECTED;
+     dp->pixel_per_cycle = 1;
+
+     ret = cix_dp_parse_dt(dp);
+     if (ret)
+             return ret;
+
+     dp->link_config.max_lanes = dp->num_lanes;
+     dp->link_config.max_rate = dp->max_rate;
+
+     ret = cix_dp_init(dp);
+     if (ret)
+             return ret;
+
+     ret = devm_add_action_or_reset(dev, cix_dptx_dev_release, dp);
+     if (ret)
+             return ret;
+
+     dev_set_drvdata(dev, dp);
+
+     dp->bridge.of_node = dev->of_node;
Quoted 8 lines

MAINTAINERS

Quoted 5 lines
MAINTAINERS +5 -0
+
+     drm_bridge_add(&dp->bridge);
+
+     return 0;
+}

It looks like this part is platform-specific, so I think Andy's suggestion to split it out into a bridge from the beginning is reasonable.

Thanks, that sounds reasonable. It would involve a fair amount of rework, so I'll take my time and try to abstract out the hardware-generic interfaces.

Quoted 30 lines

https://lore.kernel.org/all/15d12979.26c5.1a1d9c981a5.Coremail.andyshrk@1
63.com/

Quoted 10 lines
MAINTAINERS +10 -0
+
+static void cix_dptx_remove(struct platform_device *pdev) {
+     struct cix_dp *dp = dev_get_drvdata(&pdev->dev);
+
+     if (!dp)
+             return;
+
+     drm_bridge_remove(&dp->bridge);
+}
+

[...]

Quoted 13 lines
MAINTAINERS +13 -0
+
+static int cix_dp_bridge_attach(struct drm_bridge *bridge,
+                             struct drm_encoder *encoder,
+                             enum drm_bridge_attach_flags flags) {
+     struct cix_dp *dp = bridge_to_dp(bridge);
+     int ret;
+
+     dp->drm = bridge->dev;
+     WRITE_ONCE(dp->hpd_stopped, false);
+
+     ret = dp->ops->aux_register(dp);
+     if (ret)
+             goto err_clear_drm;
Quoted 8 lines

MAINTAINERS

Quoted 6 lines
MAINTAINERS +6 -0
+
+     /*
+      * Komeda (ARM Mali DPU on Sky1, not in this series) calls
+      * drm_bridge_attach() with attach flags 0 and does not register a
+      * connector; create one here so userspace gets a DP output.
+      */

Please drop this comment.

OK , I will drop it

Quoted 4 lines

--
Best,
Chaoyi