* [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter
@ 2026-12-04 11:43 Luo Liu
2026-12-04 11:43 ` [PATCH v10 1/5] dt-bindings: display: add CIX " Luo Liu
` (4 more replies)
0 siblings, 5 replies; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add the Trilinear DisplayPort transmitter as a DRM bridge, with the CIX
Sky1 platform glue behind a platform data structure.
The hardware layer, the DRM bridge and the core state machine live in
drivers/gpu/drm/bridge/trilinear/, so other SoCs using the same
transmitter can share them; the platform registers its own dptx_plat_data
through include/drm/bridge/trilinear_dp.h. The transmitter drives up to
four lanes at HBR3 and has two SST sources. MST is not implemented and
stays disabled.
The USB-C transmitters and the native DP/eDP transmitter use different
RCSU video-adapter register offsets and bit layouts, so the binding has
one compatible for each. The Sky1 devicetree nodes are not included in
this posting.
Scope: DPTX hardware, bridge 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.
Tested on a Radxa Orion O6 board; the USB-C DisplayPort output works
with the connector created by drm_bridge_connector_init().
Connector handling in this driver:
The bridge is meant to be attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR
and drm_bridge_connector_init() creates the connector from the bridge
operations. The driver implements the bridge side only and never
registers a connector of its own. A bridge wired in front of the
connector is chained from port@1.
Changes in v10:
- port@1 is resolved at probe: a remote endpoint means a converter
bridge ahead of the connector, which the bridge chains and releases on
destroy; without one the port feeds the native DP PHY.
- Link training gives up when HPD drops, propagates failures other than
-EIO, programs the PHY swing and pre-emphasis before the DPCD request,
and clamps the pre-emphasis so swing plus pre-emphasis stays within
3.5 dB.
- The PHY is configured with the lane count being trained, and the
enhanced-frame flag no longer leaks into the caller's lane count.
- The hotplug replay waits for the common PHY from the event work with a
bounded retry instead of polling in interrupt context, and only the
HPD interrupt sources are left unmasked.
- The stream clock is divided by the pixel-per-cycle factor.
- RGB tries 10 bpc first when BT.2020 or a deeper mode is requested, and
the bpc is rounded down to a supported value.
- VSC is refused for 4:2:0 when the sink lacks support, its dynamic
range follows the pixel format, and BT.709/XVYCC/DCI-P3 colorspaces
are mapped.
- The secondary data window is computed in 64-bit arithmetic.
- atomic_check returns early when the CRTC is off.
- The platform glue stores the dptx_dev in drvdata.
Luo Liu (5):
dt-bindings: display: add CIX Sky1 DisplayPort transmitter
drm/bridge: trilinear: add the DPTX hardware layer
drm/bridge: trilinear: add the DPTX DRM bridge
drm/bridge: trilinear: add the DPTX core and build glue
drm/cix: add the Sky1 DisplayPort platform glue
.../bindings/display/cix,sky1-dp.yaml | 133 ++
MAINTAINERS | 11 +
drivers/gpu/drm/Kconfig | 1 +
drivers/gpu/drm/Makefile | 1 +
drivers/gpu/drm/bridge/Kconfig | 2 +
drivers/gpu/drm/bridge/Makefile | 1 +
drivers/gpu/drm/bridge/trilinear/Kconfig | 9 +
drivers/gpu/drm/bridge/trilinear/Makefile | 4 +
drivers/gpu/drm/bridge/trilinear/dptx.h | 114 ++
drivers/gpu/drm/bridge/trilinear/dptx_core.c | 1077 +++++++++++++
drivers/gpu/drm/bridge/trilinear/dptx_drm.c | 769 +++++++++
drivers/gpu/drm/bridge/trilinear/dptx_drm.h | 17 +
drivers/gpu/drm/bridge/trilinear/dptx_hw.c | 1418 +++++++++++++++++
drivers/gpu/drm/bridge/trilinear/dptx_hw.h | 103 ++
drivers/gpu/drm/cix/Kconfig | 3 +
drivers/gpu/drm/cix/Makefile | 3 +
drivers/gpu/drm/cix/dptx/Kconfig | 15 +
drivers/gpu/drm/cix/dptx/Makefile | 4 +
drivers/gpu/drm/cix/dptx/cix_dptx.c | 181 +++
include/drm/bridge/trilinear_dp.h | 84 +
20 files changed, 3950 insertions(+)
create mode 100644 Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
create mode 100644 drivers/gpu/drm/bridge/trilinear/Kconfig
create mode 100644 drivers/gpu/drm/bridge/trilinear/Makefile
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx.h
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_core.c
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_drm.c
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_drm.h
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_hw.c
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_hw.h
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 include/drm/bridge/trilinear_dp.h
--
2.25.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v10 1/5] dt-bindings: display: add CIX Sky1 DisplayPort transmitter
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
@ 2026-12-04 11:43 ` Luo Liu
2026-12-04 11:43 ` [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add a binding for the Trilinear DisplayPort transmitter integrated on
CIX Sky1. The USB-C and the native DP/eDP transmitters use different
RCSU video-adapter register offsets and bit layouts, so each has its own
compatible.
The binding describes the full video link: port@0 is the input from the
display pipeline, and port@1 is the output towards the display
connector, a bridge in front of it, or the USB-C combo PHY that carries
the DP lanes to the receptacle. The driver drives the link through phys,
gets its connector from drm_bridge_connector_init(), and chains a
downstream bridge from port@1 when one is wired.
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Luo Liu <Luo.Liu@cixtech.com>
---
.../bindings/display/cix,sky1-dp.yaml | 133 ++++++++++++++++++
MAINTAINERS | 8 ++
2 files changed, 141 insertions(+)
create mode 100644 Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
diff --git a/Documentation/devicetree/bindings/display/cix,sky1-dp.yaml b/Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
new file mode 100644
index 000000000000..d382e38637b9
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
@@ -0,0 +1,133 @@
+# 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 <Luo.Liu@cixtech.com>
+
+description: |
+ Trilinear DisplayPort transmitter on CIX Sky1. The transmitter takes its
+ video stream from the display pipeline through its input port and drives
+ the link through a generic PHY. Its output port describes where the DP
+ lanes go on the board: a display connector, a bridge, or the USB-C combo
+ PHY that carries them to the receptacle.
+
+ 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: "cix,sky1-usbdp" for the USB-C transmitters and "cix,sky1-dp"
+ for the native DP/eDP one.
+
+properties:
+ compatible:
+ enum:
+ - cix,sky1-usbdp
+ - 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
+
+ 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
+
+ interrupts:
+ maxItems: 1
+
+ resets:
+ maxItems: 1
+ description: DisplayPort controller reset.
+
+ phys:
+ maxItems: 1
+ description: DisplayPort PHY the controller transmits through.
+
+ ports:
+ $ref: /schemas/graph.yaml#/properties/ports
+
+ properties:
+ port@0:
+ $ref: /schemas/graph.yaml#/properties/port
+ description:
+ Video input from the Mali D71 display pipeline (Komeda) that feeds
+ this controller.
+
+ port@1:
+ $ref: /schemas/graph.yaml#/properties/port
+ description:
+ Output of the controller. It connects to the display connector, to
+ a bridge in front of one, or to the USB-C combo PHY that carries
+ the DP lanes to the receptacle.
+
+ required:
+ - port@0
+ - port@1
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - clocks
+ - clock-names
+ - interrupts
+ - resets
+ - phys
+ - ports
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+ dp@14064000 {
+ compatible = "cix,sky1-usbdp";
+ reg = <0x14064000 0x4000>,
+ <0x14050000 0x400>;
+ reg-names = "dp", "rcsu";
+ clocks = <&dpc0_apb>, <&dpc0_vid0>, <&dpc0_vid1>;
+ clock-names = "apb", "vid0", "vid1";
+ interrupts = <GIC_SPI 332 IRQ_TYPE_LEVEL_HIGH>;
+ resets = <&dpc0_rst>;
+ phys = <&usbc0_dp_phy>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+
+ endpoint {
+ remote-endpoint = <&dpu0_pipe0_out>;
+ };
+ };
+
+ port@1 {
+ reg = <1>;
+
+ endpoint {
+ remote-endpoint = <&dp0_connector_in>;
+ };
+ };
+ };
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315065..e3557e931c94 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6522,6 +6522,14 @@ M: Satish Kharat <satishkh@cisco.com>
S: Supported
F: drivers/infiniband/hw/usnic/
+CIX SKY1 DISPLAYPORT TRANSMITTER DRIVER
+M: Luo Liu <Luo.Liu@cixtech.com>
+M: Wuyi Shen <wuyi.shen@cixtech.com>
+R: CIX Linux Kernel Upstream Group <cix-kernel-upstream@cixtech.com>
+L: dri-devel@lists.freedesktop.org
+S: Maintained
+F: Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+
CLANG CONTEXT ANALYSIS
M: Marco Elver <elver@google.com>
R: Bart Van Assche <bvanassche@acm.org>
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
2026-12-04 11:43 ` [PATCH v10 1/5] dt-bindings: display: add CIX " Luo Liu
@ 2026-12-04 11:43 ` Luo Liu
2026-12-04 12:06 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add the register and PHY programming for the Trilinear DisplayPort
transmitter: controller reset, host and core enable, AUX transfers
through the controller's AUX channel, sink capability parsing from the
DPCD, and link training with clock recovery and channel equalization.
The transmitter drives up to four lanes at HBR3 and has two SST
sources. The stream setup programs the main stream attributes, the
pixel format and the optional VSC SDP per stream. MST is not
implemented and is left disabled.
DP_SET_POWER is only accessed on sinks whose DPCD revision implements
the register, so a v1.0 sink is not sent a request it cannot answer.
Signed-off-by: Luo Liu <Luo.Liu@cixtech.com>
---
MAINTAINERS | 1 +
drivers/gpu/drm/bridge/trilinear/dptx_hw.c | 1418 ++++++++++++++++++++
drivers/gpu/drm/bridge/trilinear/dptx_hw.h | 103 ++
3 files changed, 1522 insertions(+)
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_hw.c
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_hw.h
diff --git a/MAINTAINERS b/MAINTAINERS
index e3557e931c94..01ff0666f63b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6529,6 +6529,7 @@ R: CIX Linux Kernel Upstream Group <cix-kernel-upstream@cixtech.com>
L: dri-devel@lists.freedesktop.org
S: Maintained
F: Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
+F: drivers/gpu/drm/bridge/trilinear/
CLANG CONTEXT ANALYSIS
M: Marco Elver <elver@google.com>
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_hw.c b/drivers/gpu/drm/bridge/trilinear/dptx_hw.c
new file mode 100644
index 000000000000..bdf24e464b94
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx_hw.c
@@ -0,0 +1,1418 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * DisplayPort transmitter hardware interface
+ *
+ * Copyright (C) 2026 Trilinear Technologies
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/iopoll.h>
+#include <linux/math64.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/slab.h>
+#include <linux/sprintf.h>
+
+#include <drm/display/drm_dp_helper.h>
+
+#include "dptx_hw.h"
+
+#define DPTX_SDP_DB_MAX 32
+#define DP_MAX_TRAINING_TRIES 5
+#define DP_APB_CLK_RATE 200000000UL
+
+/* ------------------------------------------------------------------------ */
+/* Register offsets */
+/* ------------------------------------------------------------------------ */
+/* link configuration */
+#define DPTX_LINK_BW_SET 0x000ul
+#define DPTX_LANE_COUNT_SET 0x004ul
+#define DPTX_ENHANCED_FRAMING_ENABLE 0x008ul
+#define DPTX_TRAINING_PATTERN_SET 0x00cul
+#define DPTX_DISABLE_SCRAMBLING 0x014ul
+#define DPTX_DOWNSPREAD_CONTROL 0x018ul
+
+/* core enables */
+#define DPTX_TRANSMITTER_ENABLE 0x080ul
+#define DPTX_SOFT_RESET 0x090ul
+#define DPTX_SOURCE_ENABLE 0x094ul
+
+/* misc control */
+#define DPTX_FORCE_SCRAMBLER_RESET 0x0c0ul
+
+/* AUX channel */
+#define DPTX_AUX_COMMAND 0x100ul
+#define DPTX_AUX_WRITE_FIFO 0x104ul
+#define DPTX_AUX_ADDRESS 0x108ul
+#define DPTX_AUX_CLOCK_DIVIDER 0x10cul
+#define DPTX_HPD_INPUT_STATE 0x128ul
+#define DPTX_AUX_REPLY_DATA 0x134ul
+#define DPTX_AUX_REPLY_CODE 0x138ul
+#define DPTX_INTERRUPT_CAUSE 0x140ul
+#define DPTX_INTERRUPT_MASK 0x144ul
+#define DPTX_AUX_REPLY_DATA_COUNT 0x148ul
+#define DPTX_AUX_STATUS 0x14cul
+
+/* PHY status */
+#define DPTX_PHY_STATUS 0x280ul
+
+/* MST / SST control */
+#define DPTX_MST_ENABLE 0x500ul
+#define DPTX_SST_SOURCE_SELECT 0x50cul
+
+/* main stream control, virtual source 0 (bases for per-stream helpers) */
+#define DPTX_SRC0_VIDEO_STREAM_ENABLE 0x800ul
+#define DPTX_SRC0_SECONDARY_STREAM_ENABLE 0x804ul
+#define DPTX_SRC0_SECONDARY_DATA_WINDOW 0x808ul
+#define DPTX_SRC0_DATA_CONTROL 0x810ul
+#define DPTX_SRC0_MAIN_STREAM_OVERRIDE 0x814ul
+#define DPTX_SRC0_MAIN_STREAM_HTOTAL 0x820ul
+#define DPTX_SRC0_MAIN_STREAM_VTOTAL 0x824ul
+#define DPTX_SRC0_MAIN_STREAM_POLARITY 0x828ul
+#define DPTX_SRC0_MAIN_STREAM_HSWIDTH 0x82cul
+#define DPTX_SRC0_MAIN_STREAM_VSWIDTH 0x830ul
+#define DPTX_SRC0_MAIN_STREAM_HRES 0x834ul
+#define DPTX_SRC0_MAIN_STREAM_VRES 0x838ul
+#define DPTX_SRC0_MAIN_STREAM_HSTART 0x83cul
+#define DPTX_SRC0_MAIN_STREAM_VSTART 0x840ul
+#define DPTX_SRC0_MAIN_STREAM_MISC0 0x844ul
+#define DPTX_SRC0_MAIN_STREAM_MISC1 0x848ul
+#define DPTX_SRC0_TU_CONFIG 0x850ul
+#define DPTX_SRC0_USER_PIXEL_COUNT 0x858ul
+#define DPTX_SRC0_USER_DATA_COUNT 0x85cul
+#define DPTX_SRC0_USER_SYNC_POLARITY 0x864ul
+
+/* secondary channel, source 0 */
+#define DPTX_SEC0_INFOFRAME_ENABLE 0x910ul
+#define DPTX_SEC0_INFOFRAME_RATE 0x914ul
+#define DPTX_SEC0_INFOFRAME_SELECT 0x934ul
+#define DPTX_SEC0_INFOFRAME_DATA 0x938ul
+
+/* spacing between consecutive virtual source register blocks */
+#define DPTX_SOURCE_OFFSET 0x200ul
+
+/* per-stream helpers, indexed by source/stream id */
+#define DPTX_INFOFRAME_ENABLE(stream_id) \
+ (DPTX_SEC0_INFOFRAME_ENABLE + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_INFOFRAME_SELECT(stream_id) \
+ (DPTX_SEC0_INFOFRAME_SELECT + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_INFOFRAME_RATE(stream_id) \
+ (DPTX_SEC0_INFOFRAME_RATE + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_INFOFRAME_DATA(stream_id) \
+ (DPTX_SEC0_INFOFRAME_DATA + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_VIDEO_STREAM_ENABLE(stream_id) \
+ (DPTX_SRC0_VIDEO_STREAM_ENABLE + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_SECONDARY_STREAM_ENABLE(stream_id) \
+ (DPTX_SRC0_SECONDARY_STREAM_ENABLE + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_MISC0(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_MISC0 + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_MISC1(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_MISC1 + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_OVERRIDE(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_OVERRIDE + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_HTOTAL(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_HTOTAL + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_VTOTAL(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_VTOTAL + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_POLARITY(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_POLARITY + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_HSWIDTH(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_HSWIDTH + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_VSWIDTH(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_VSWIDTH + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_HRES(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_HRES + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_VRES(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_VRES + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_HSTART(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_HSTART + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_MAIN_STREAM_VSTART(stream_id) \
+ (DPTX_SRC0_MAIN_STREAM_VSTART + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_TU_CONFIG(stream_id) \
+ (DPTX_SRC0_TU_CONFIG + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_USER_DATA_COUNT(stream_id) \
+ (DPTX_SRC0_USER_DATA_COUNT + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_SECONDARY_DATA_WINDOW(stream_id) \
+ (DPTX_SRC0_SECONDARY_DATA_WINDOW + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_DATA_CONTROL(stream_id) \
+ (DPTX_SRC0_DATA_CONTROL + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_USER_PIXEL_COUNT(stream_id) \
+ (DPTX_SRC0_USER_PIXEL_COUNT + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+#define DPTX_USER_SYNC_POLARITY(stream_id) \
+ (DPTX_SRC0_USER_SYNC_POLARITY + \
+ DPTX_SOURCE_OFFSET * (stream_id))
+
+/* ------------------------------------------------------------------------ */
+/* Register DPTX_MAIN_STREAM_MISC0 bits */
+/* ------------------------------------------------------------------------ */
+#define DPTX_STREAM_MISC0_COMP_FORMAT_RGB (0 << 1)
+#define DPTX_STREAM_MISC0_COMP_FORMAT_YCRCB_422 (5 << 1)
+#define DPTX_STREAM_MISC0_COMP_FORMAT_YCRCB_444 (6 << 1)
+#define DPTX_STREAM_MISC0_BPC_6 (0 << 5)
+#define DPTX_STREAM_MISC0_BPC_8 BIT(5)
+#define DPTX_STREAM_MISC0_BPC_10 (2 << 5)
+#define DPTX_STREAM_MISC0_BPC_12 (3 << 5)
+#define DPTX_STREAM_MISC0_BPC_16 (4 << 5)
+
+/* ------------------------------------------------------------------------ */
+/* Register DPTX_MAIN_STREAM_MISC1 bits */
+/* ------------------------------------------------------------------------ */
+#define DPTX_STREAM_MISC1_Y_ONLY_EN BIT(7)
+#define DPTX_VSC_COLORIMETRY_EN BIT(6)
+
+/* ------------------------------------------------------------------------ */
+/* Register DPTX_MAIN_STREAM_OVERRIDE bits */
+/* ------------------------------------------------------------------------ */
+#define DPTX_STREAM_OVERRIDE_ENABLE BIT(6)
+/*
+ * Pixel format in bits [5:3]. 0 is RGB. 4:2:2 and 4:4:4 use the same
+ * component-format codes as MISC0 bits [2:1]. 4:2:0 cannot be carried
+ * in MISC0, so it has its own value.
+ */
+#define DPTX_STREAM_OVERRIDE_YCbCR_422 BIT(3)
+#define DPTX_STREAM_OVERRIDE_YCbCR_444 (2 << 3)
+#define DPTX_STREAM_OVERRIDE_YCbCR_420 (4 << 3)
+#define DPTX_STREAM_OVERRIDE_BPC_6 (0)
+#define DPTX_STREAM_OVERRIDE_BPC_8 (1)
+#define DPTX_STREAM_OVERRIDE_BPC_10 (2)
+#define DPTX_STREAM_OVERRIDE_BPC_12 (3)
+#define DPTX_STREAM_OVERRIDE_BPC_16 (4)
+
+/* ------------------------------------------------------------------------ */
+/* Register DPTX_AUX_COMMAND bits */
+/* ------------------------------------------------------------------------ */
+#define DPTX_AUX_COMMAND_CMD_SHIFT 8
+#define DPTX_AUX_COMMAND_ADDRESS_ONLY BIT(12)
+#define DPTX_AUX_COMMAND_BYTES_SHIFT 0
+#define DPTX_AUX_STATUS_REPLY_ERROR BIT(3)
+#define DPTX_AUX_STATUS_REQUEST_IN_PROGRESS BIT(2)
+#define DPTX_AUX_STATUS_REPLY_IN_PROGRESS BIT(1)
+#define DPTX_AUX_STATUS_REPLY_RECEIVED BIT(0)
+
+#define DPTX_AUX_READ BIT(0)
+
+/* ------------------------------------------------------------------------ */
+/* Register DPTX_REPLY_DATA_COUNT bits */
+/* ------------------------------------------------------------------------ */
+#define DPTX_REPLY_DATA_COUNT_MASK 0xff
+
+#define DPTX_MSA_TRANSFER_UNIT_SIZE_TU_SIZE_DEF 64
+#define DPTX_MAIN_STREAM_POLARITY_HSYNC_SHIFT 0
+#define DPTX_MAIN_STREAM_POLARITY_VSYNC_SHIFT 1
+#define DPTX_MAIN_STREAM_POLARITY_DATAENABLE_HIGH 0xc
+
+#define DPTX_DATA_CONTROL_DEFAULT (BIT(13) | BIT(2))
+#define DPTX_DATA_CONTROL_2PPC_4LANE_HBR3 BIT(2)
+
+#define DPTX_INTERRUPT_GP_TIMER_IRQ BIT(4)
+#define DPTX_INTERRUPT_REPLY_TIMEOUT BIT(3)
+#define DPTX_INTERRUPT_REPLY_RECEIVED BIT(2)
+#define DPTX_INTERRUPT_HPD_IRQ BIT(1)
+#define DPTX_INTERRUPT_HPD_EVENT BIT(0)
+
+#define DPTX_INTERRUPT_MASK_ALL 0x3f
+#define DPTX_INTERRUPT_CFG \
+ (DPTX_INTERRUPT_MASK_ALL & \
+ ~(DPTX_INTERRUPT_HPD_EVENT | DPTX_INTERRUPT_HPD_IRQ))
+
+static const char * const stream_clk_names[] = {
+ "vid0", "vid1",
+};
+
+static u32 dptx_hw_read(struct dp_hw *hw, int offset)
+{
+ return readl(hw->base + offset);
+}
+
+static void dptx_hw_write(struct dp_hw *hw, int offset, u32 val)
+{
+ writel(val, hw->base + offset);
+}
+
+static bool dptx_hw_hpd_state(struct dp_hw *hw)
+{
+ return dptx_hw_read(hw, DPTX_HPD_INPUT_STATE) & BIT(0);
+}
+
+static bool dptx_hw_sink_present(struct dp_hw *hw)
+{
+ u8 dpcd_rev;
+
+ return drm_dp_dpcd_readb(&hw->aux, DP_DPCD_REV, &dpcd_rev) >= 0;
+}
+
+static int dptx_hw_phy_vs_emph_set(struct dp_hw *hw, struct phy *phy,
+ u8 lane_cnt, const u8 *train_set)
+{
+ union phy_configure_opts opts = { 0 };
+ u8 train;
+ int i;
+
+ opts.dp.lanes = lane_cnt;
+ for (i = 0; i < lane_cnt; i++) {
+ train = train_set[i];
+ opts.dp.voltage[i] = (train & DP_TRAIN_VOLTAGE_SWING_MASK) >>
+ DP_TRAIN_VOLTAGE_SWING_SHIFT;
+ opts.dp.pre[i] = (train & DP_TRAIN_PRE_EMPHASIS_MASK) >>
+ DP_TRAIN_PRE_EMPHASIS_SHIFT;
+ }
+
+ opts.dp.set_voltages = 1;
+ return phy_configure(phy, &opts);
+}
+
+static void dptx_hw_aux_clock_divider(struct dp_hw *hw)
+{
+ unsigned int rate;
+
+ rate = clk_get_rate(hw->apb_clk) / (1000 * 1000);
+ if (!rate)
+ rate = 25;
+
+ dptx_hw_write(hw, DPTX_AUX_CLOCK_DIVIDER, rate);
+}
+
+static int dptx_hw_apb_clock(struct dp_hw *hw, bool enable)
+{
+ int ret;
+
+ if (IS_ERR_OR_NULL(hw->apb_clk))
+ return 0;
+
+ if (!enable) {
+ clk_disable_unprepare(hw->apb_clk);
+ return 0;
+ }
+
+ if (!clk_get_rate(hw->apb_clk)) {
+ ret = clk_set_rate(hw->apb_clk, DP_APB_CLK_RATE);
+ if (ret) {
+ dev_err(hw->dev, "failed to set apb clock rate: %d\n",
+ ret);
+ return ret;
+ }
+ }
+
+ return clk_prepare_enable(hw->apb_clk);
+}
+
+static void dptx_hw_reset(struct dp_hw *hw, bool assert)
+{
+ if (assert)
+ reset_control_assert(hw->reset);
+ else
+ reset_control_deassert(hw->reset);
+}
+
+static void dptx_hw_host_enable(struct dp_hw *hw, bool enable)
+{
+ if (enable) {
+ dptx_hw_write(hw, DPTX_TRANSMITTER_ENABLE, 1);
+ dptx_hw_write(hw, DPTX_INTERRUPT_MASK,
+ DPTX_INTERRUPT_CFG);
+ dptx_hw_aux_clock_divider(hw);
+ return;
+ }
+
+ dptx_hw_write(hw, DPTX_TRANSMITTER_ENABLE, 0);
+ dptx_hw_write(hw, DPTX_INTERRUPT_MASK,
+ DPTX_INTERRUPT_MASK_ALL);
+}
+
+static void dptx_hw_core_enable(struct dp_hw *hw, int source_id,
+ bool enable)
+{
+ u32 sources = BIT(source_id);
+ u32 value;
+
+ if (enable) {
+ dptx_hw_write(hw, DPTX_SOFT_RESET, sources);
+ dptx_hw_write(hw, DPTX_SOURCE_ENABLE, sources);
+ dptx_hw_write(hw, DPTX_FORCE_SCRAMBLER_RESET, sources);
+ dptx_hw_write(hw, DPTX_MST_ENABLE, 0);
+ dptx_hw_write(hw, DPTX_SST_SOURCE_SELECT, source_id);
+ return;
+ }
+
+ dptx_hw_write(hw, DPTX_MST_ENABLE, 0);
+
+ value = dptx_hw_read(hw, DPTX_SOURCE_ENABLE);
+ dptx_hw_write(hw, DPTX_SOURCE_ENABLE, value & ~sources);
+
+ value = dptx_hw_read(hw, DPTX_SOFT_RESET);
+ dptx_hw_write(hw, DPTX_SOFT_RESET, value & ~sources);
+
+ value = dptx_hw_read(hw, DPTX_FORCE_SCRAMBLER_RESET);
+ dptx_hw_write(hw, DPTX_FORCE_SCRAMBLER_RESET, value & ~sources);
+}
+
+static void dptx_hw_link_setup(struct dp_hw *hw, u8 lane_cnt,
+ bool enhanced, bool downspread)
+{
+ dptx_hw_write(hw, DPTX_LANE_COUNT_SET, lane_cnt);
+ dptx_hw_write(hw, DPTX_ENHANCED_FRAMING_ENABLE, enhanced ? 1 : 0);
+ dptx_hw_write(hw, DPTX_DOWNSPREAD_CONTROL, downspread);
+}
+
+static int dptx_hw_link_rate(struct dp_hw *hw, struct phy *phy,
+ u8 bw_code, u8 lane_cnt, bool downspread)
+{
+ union phy_configure_opts opts = { 0 };
+ u32 ready = (1 << lane_cnt) - 1;
+ u32 value;
+ int ret;
+
+ dptx_hw_write(hw, DPTX_LINK_BW_SET, bw_code);
+
+ opts.dp.link_rate = drm_dp_bw_code_to_link_rate(bw_code) / 100;
+ opts.dp.lanes = lane_cnt;
+ opts.dp.ssc = downspread;
+ opts.dp.set_rate = 1;
+ opts.dp.set_lanes = 1;
+ ret = phy_configure(phy, &opts);
+ if (ret)
+ return ret;
+
+ return readl_poll_timeout(hw->base + DPTX_PHY_STATUS, value,
+ (value & ready) == ready, 1000, 100 * 1000);
+}
+
+static int dptx_hw_link_configure(struct dp_hw *hw, struct phy *phy,
+ u8 bw_code, u8 lane_cnt, bool enhanced)
+{
+ u8 lane_cnt_set = lane_cnt;
+ bool downspread;
+ int ret;
+
+ downspread = hw->dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;
+
+ dptx_hw_link_setup(hw, lane_cnt, enhanced, downspread);
+
+ if (enhanced)
+ lane_cnt_set |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_DOWNSPREAD_CTRL,
+ downspread ? DP_SPREAD_AMP_0_5 : 0);
+ if (ret < 0)
+ return ret;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_LANE_COUNT_SET, lane_cnt_set);
+ if (ret < 0)
+ return ret;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_MAIN_LINK_CHANNEL_CODING_SET,
+ DP_SET_ANSI_8B10B);
+ if (ret < 0)
+ return ret;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_LINK_BW_SET, bw_code);
+ if (ret < 0)
+ return ret;
+
+ return dptx_hw_link_rate(hw, phy, bw_code, lane_cnt, downspread);
+}
+
+static int dptx_hw_link_set_pattern(struct dp_hw *hw, u32 pattern)
+{
+ if (pattern == DP_TRAINING_PATTERN_4) {
+ dptx_hw_write(hw, DPTX_TRAINING_PATTERN_SET, 0x4);
+ dptx_hw_write(hw, DPTX_DISABLE_SCRAMBLING, 0);
+ } else {
+ dptx_hw_write(hw, DPTX_TRAINING_PATTERN_SET, pattern);
+ pattern |= DP_LINK_SCRAMBLING_DISABLE;
+ }
+
+ return drm_dp_dpcd_writeb(&hw->aux, DP_TRAINING_PATTERN_SET, pattern);
+}
+
+static int dptx_hw_link_vs_emph(struct dp_hw *hw, struct phy *phy,
+ u8 lane_cnt)
+{
+ int ret;
+
+ ret = dptx_hw_phy_vs_emph_set(hw, phy, lane_cnt, hw->train_setting);
+ if (ret)
+ return ret;
+
+ return drm_dp_dpcd_write(&hw->aux, DP_TRAINING_LANE0_SET,
+ hw->train_setting, lane_cnt);
+}
+
+static void dptx_hw_link_adjust_train(struct dp_hw *hw, u8 lane_cnt,
+ const u8 *link_status)
+{
+ u8 voltage;
+ u8 preemphasis;
+ u8 pre_level;
+ int i;
+
+ for (i = 0; i < lane_cnt; i++) {
+ voltage = drm_dp_get_adjust_request_voltage(link_status, i);
+ preemphasis =
+ drm_dp_get_adjust_request_pre_emphasis(link_status, i);
+ pre_level = preemphasis >> DP_TRAIN_PRE_EMPHASIS_SHIFT;
+
+ if (voltage + pre_level > 3) {
+ pre_level = 3 - voltage;
+ preemphasis = pre_level << DP_TRAIN_PRE_EMPHASIS_SHIFT;
+ }
+
+ if (voltage >= DP_TRAIN_VOLTAGE_SWING_LEVEL_3)
+ voltage |= DP_TRAIN_MAX_SWING_REACHED;
+
+ if (preemphasis >= DP_TRAIN_PRE_EMPH_LEVEL_3)
+ preemphasis |= DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
+
+ hw->train_setting[i] = voltage | preemphasis;
+ }
+}
+
+static int dptx_hw_link_clock_recovery(struct dp_hw *hw, struct phy *phy,
+ u8 lane_cnt)
+{
+ u8 link_status[DP_LINK_STATUS_SIZE];
+ u8 prev[DPTX_MAX_LANES];
+ bool train_done = false;
+ int tries = 0;
+ int i;
+ int ret;
+
+ ret = dptx_hw_link_set_pattern(hw, DP_TRAINING_PATTERN_1);
+ if (ret < 0)
+ return ret;
+
+ memset(prev, 0, lane_cnt);
+
+ for (i = 0; i < 512; i++) {
+ ret = dptx_hw_link_vs_emph(hw, phy, lane_cnt);
+ if (ret)
+ return ret;
+
+ drm_dp_link_train_clock_recovery_delay(&hw->aux, hw->dpcd);
+ ret = drm_dp_dpcd_read_link_status(&hw->aux, link_status);
+ if (ret < 0)
+ return ret;
+
+ train_done = drm_dp_clock_recovery_ok(link_status, lane_cnt);
+ if (train_done)
+ break;
+
+ memcpy(prev, hw->train_setting, lane_cnt);
+ dptx_hw_link_adjust_train(hw, lane_cnt, link_status);
+
+ if (!memcmp(hw->train_setting, prev, lane_cnt))
+ tries++;
+ else
+ tries = 0;
+
+ if (tries == DP_MAX_TRAINING_TRIES)
+ break;
+ }
+
+ if (train_done)
+ return 0;
+
+ return -EIO;
+}
+
+static int dptx_hw_link_channel_equalization(struct dp_hw *hw, struct phy *phy,
+ u8 lane_cnt, bool tps3,
+ bool tps4)
+{
+ u8 link_status[DP_LINK_STATUS_SIZE];
+ bool train_done = false;
+ u32 pattern;
+ int i;
+ int ret;
+
+ if (tps4)
+ pattern = DP_TRAINING_PATTERN_4;
+ else if (tps3)
+ pattern = DP_TRAINING_PATTERN_3;
+ else
+ pattern = DP_TRAINING_PATTERN_2;
+
+ ret = dptx_hw_link_set_pattern(hw, pattern);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < DP_MAX_TRAINING_TRIES; i++) {
+ ret = dptx_hw_link_vs_emph(hw, phy, lane_cnt);
+ if (ret)
+ return ret;
+
+ drm_dp_link_train_channel_eq_delay(&hw->aux, hw->dpcd);
+ ret = drm_dp_dpcd_read_link_status(&hw->aux, link_status);
+ if (ret < 0)
+ return ret;
+
+ train_done = drm_dp_channel_eq_ok(link_status, lane_cnt);
+ if (train_done)
+ break;
+
+ if (!drm_dp_clock_recovery_ok(link_status, lane_cnt))
+ break;
+
+ dptx_hw_link_adjust_train(hw, lane_cnt, link_status);
+ }
+
+ if (train_done)
+ return 0;
+
+ return -EIO;
+}
+
+static void dptx_hw_link_train_start(struct dp_hw *hw)
+{
+ dptx_hw_write(hw, DPTX_DISABLE_SCRAMBLING, 1);
+ memset(hw->train_setting, 0, sizeof(hw->train_setting));
+}
+
+static int dptx_hw_link_train_end(struct dp_hw *hw)
+{
+ int ret;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_TRAINING_PATTERN_SET, 0);
+ dptx_hw_write(hw, DPTX_TRAINING_PATTERN_SET, 0);
+ dptx_hw_write(hw, DPTX_DISABLE_SCRAMBLING, 0);
+
+ return ret < 0 ? ret : 0;
+}
+
+static int dptx_hw_link_train(struct dp_hw *hw, struct phy *phy, u8 bw_code,
+ u8 lane_cnt)
+{
+ int end_ret;
+ int ret;
+
+ ret = dptx_hw_link_configure(hw, phy, bw_code, lane_cnt,
+ hw->caps.enhanced_framing);
+ if (ret < 0)
+ return ret;
+
+ dptx_hw_link_train_start(hw);
+
+ ret = dptx_hw_link_clock_recovery(hw, phy, lane_cnt);
+ if (!ret)
+ ret = dptx_hw_link_channel_equalization(hw, phy, lane_cnt,
+ hw->caps.tps3_supported,
+ hw->caps.tps4_supported);
+
+ end_ret = dptx_hw_link_train_end(hw);
+ if (!ret)
+ ret = end_ret;
+
+ return ret;
+}
+
+static int dptx_hw_link_status(struct dp_hw *hw, u8 lane_cnt)
+{
+ u8 status[DP_LINK_STATUS_SIZE + 2];
+ ssize_t ret;
+
+ ret = drm_dp_dpcd_read(&hw->aux, DP_SINK_COUNT, status,
+ sizeof(status));
+ if (ret != (ssize_t)sizeof(status))
+ return ret < 0 ? ret : -EIO;
+
+ if (drm_dp_clock_recovery_ok(&status[2], lane_cnt) &&
+ drm_dp_channel_eq_ok(&status[2], lane_cnt))
+ return 0;
+
+ return 1;
+}
+
+static int dptx_hw_aux_submit(struct dp_hw *hw, u32 cmd, u32 addr,
+ const u8 *buf, u32 len)
+{
+ bool is_read = cmd & DPTX_AUX_READ;
+ u32 value;
+ int i;
+ int ret;
+
+ value = dptx_hw_read(hw, DPTX_AUX_STATUS);
+ if (value & (DPTX_AUX_STATUS_REQUEST_IN_PROGRESS |
+ DPTX_AUX_STATUS_REPLY_IN_PROGRESS))
+ return -EBUSY;
+
+ dptx_hw_write(hw, DPTX_AUX_ADDRESS, addr);
+
+ if (!is_read)
+ for (i = 0; i < len; i++)
+ dptx_hw_write(hw, DPTX_AUX_WRITE_FIFO,
+ buf[i]);
+
+ value = cmd << DPTX_AUX_COMMAND_CMD_SHIFT;
+ if (!buf || !len)
+ value |= DPTX_AUX_COMMAND_ADDRESS_ONLY;
+ else
+ value |= (len - 1) << DPTX_AUX_COMMAND_BYTES_SHIFT;
+
+ dptx_hw_write(hw, DPTX_AUX_COMMAND, value);
+
+ ret = readl_poll_timeout(hw->base + DPTX_AUX_STATUS, value,
+ value & (DPTX_AUX_STATUS_REPLY_RECEIVED |
+ DPTX_AUX_STATUS_REPLY_ERROR),
+ 100, 4000);
+ if (ret)
+ return -ETIMEDOUT;
+
+ /*
+ * REPLY_ERROR is the block's reply timeout. NACK and DEFER come back
+ * as a reply with a non-zero reply code, which the caller reads.
+ */
+ if (value & DPTX_AUX_STATUS_REPLY_ERROR)
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
+static void dptx_hw_aux_reply_data(struct dp_hw *hw, u8 *buf, u32 len)
+{
+ int i;
+
+ for (i = 0; i < len; i++)
+ buf[i] = dptx_hw_read(hw, DPTX_AUX_REPLY_DATA);
+}
+
+static int dptx_hw_aux_cmd_submit(struct dp_hw *hw, u32 cmd, u32 addr,
+ u8 *buf, u32 bytes, u32 reply_mask,
+ u32 reply_ack, u8 *reply)
+{
+ bool is_read = cmd & DPTX_AUX_READ;
+ u32 reply_code;
+ u32 count;
+ int ret;
+
+ ret = dptx_hw_aux_submit(hw, cmd, addr, buf, bytes);
+ if (ret)
+ return ret;
+
+ reply_code = dptx_hw_read(hw, DPTX_AUX_REPLY_CODE);
+ if (reply)
+ *reply = reply_code;
+
+ if ((reply_code & reply_mask) != reply_ack)
+ return 0;
+
+ if (!is_read)
+ return bytes;
+
+ if (!bytes)
+ return 0;
+
+ count = dptx_hw_read(hw, DPTX_AUX_REPLY_DATA_COUNT) &
+ DPTX_REPLY_DATA_COUNT_MASK;
+ if (count > bytes)
+ return -EIO;
+
+ dptx_hw_aux_reply_data(hw, buf, count);
+
+ return count;
+}
+
+static ssize_t dptx_hw_aux_transfer(struct drm_dp_aux *aux,
+ struct drm_dp_aux_msg *msg)
+{
+ struct dp_hw *hw = container_of(aux, struct dp_hw, aux);
+ size_t to_access = 0;
+ size_t accessed_bytes = 0;
+ u32 reply_mask;
+ u32 reply_ack;
+ u32 addr;
+ bool is_native;
+ u8 *buf;
+ ssize_t ret;
+
+ switch (msg->request) {
+ case DP_AUX_NATIVE_WRITE:
+ case DP_AUX_NATIVE_READ:
+ is_native = true;
+ reply_mask = DP_AUX_NATIVE_REPLY_MASK;
+ reply_ack = DP_AUX_NATIVE_REPLY_ACK;
+ break;
+ default:
+ is_native = false;
+ reply_mask = DP_AUX_NATIVE_REPLY_MASK | DP_AUX_I2C_REPLY_MASK;
+ reply_ack = DP_AUX_NATIVE_REPLY_ACK | DP_AUX_I2C_REPLY_ACK;
+ break;
+ }
+
+ do {
+ to_access = min_t(size_t, DP_AUX_MAX_PAYLOAD_BYTES,
+ msg->size - accessed_bytes);
+ buf = accessed_bytes ? msg->buffer + accessed_bytes : msg->buffer;
+ addr = is_native ? msg->address + accessed_bytes : msg->address;
+ ret = dptx_hw_aux_cmd_submit(hw, msg->request, addr, buf,
+ to_access, reply_mask, reply_ack,
+ &msg->reply);
+ if (ret < 0) {
+ if (!accessed_bytes)
+ return ret;
+ break;
+ }
+
+ if ((msg->reply & reply_mask) != reply_ack)
+ break;
+
+ accessed_bytes += ret;
+ if ((size_t)ret < to_access)
+ break;
+ } while (accessed_bytes < msg->size);
+
+ return accessed_bytes;
+}
+
+static int dptx_hw_stream_clock_enable(struct dp_hw *hw, unsigned int stream_id,
+ bool enable)
+{
+ struct clk *clk;
+ int ret;
+
+ if (stream_id >= DP_STREAM_MAX)
+ return -EINVAL;
+
+ clk = hw->stream_clk[stream_id];
+ if (IS_ERR_OR_NULL(clk))
+ return -EINVAL;
+
+ if (enable) {
+ ret = clk_prepare_enable(clk);
+ if (ret)
+ return ret;
+ } else {
+ clk_disable_unprepare(clk);
+ }
+
+ return 0;
+}
+
+static int dptx_hw_stream_clock_rate_set(struct dp_hw *hw, unsigned int stream_id,
+ unsigned long rate)
+{
+ struct clk *clk;
+
+ if (stream_id >= DP_STREAM_MAX)
+ return -EINVAL;
+
+ clk = hw->stream_clk[stream_id];
+ if (IS_ERR_OR_NULL(clk) || clk_get_rate(clk) == rate)
+ return 0;
+
+ return clk_set_rate(clk, rate);
+}
+
+static int dptx_hw_dpcd_power_up(struct dp_hw *hw,
+ unsigned int delay_ms)
+{
+ u8 value;
+ int ret;
+
+ if (hw->dpcd[DP_DPCD_REV] < DP_DPCD_REV_11)
+ return 0;
+
+ ret = drm_dp_dpcd_readb(&hw->aux, DP_SET_POWER, &value);
+ if (ret < 0)
+ return ret;
+
+ value = (value & ~DP_SET_POWER_MASK) | DP_SET_POWER_D0;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_SET_POWER, value);
+ if (ret < 0)
+ return ret;
+
+ msleep(delay_ms);
+
+ return 0;
+}
+
+static int dptx_hw_dpcd_power_down(struct dp_hw *hw, bool hpd)
+{
+ u8 value;
+ int ret;
+
+ if (!hpd)
+ return 0;
+
+ if (hw->dpcd[DP_DPCD_REV] < DP_DPCD_REV_11)
+ return 0;
+
+ ret = drm_dp_dpcd_readb(&hw->aux, DP_SET_POWER, &value);
+ if (ret < 0)
+ return ret;
+
+ value = (value & ~DP_SET_POWER_MASK) | DP_SET_POWER_D3;
+
+ ret = drm_dp_dpcd_writeb(&hw->aux, DP_SET_POWER, value);
+ if (ret < 0)
+ return ret;
+
+ usleep_range(200, 205);
+
+ return 0;
+}
+
+static int dptx_hw_dpcd_sink_caps(struct dp_hw *hw)
+{
+ u8 dpcd[DP_RECEIVER_CAP_SIZE];
+ u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
+ int ret;
+
+ ret = drm_dp_read_dpcd_caps(&hw->aux, dpcd);
+ if (ret)
+ return ret;
+
+ ret = drm_dp_read_downstream_info(&hw->aux, dpcd, downstream_ports);
+ if (ret)
+ return ret;
+
+ memcpy(hw->dpcd, dpcd, sizeof(dpcd));
+ memcpy(hw->downstream_ports, downstream_ports, sizeof(downstream_ports));
+
+ hw->caps.enhanced_framing = drm_dp_enhanced_frame_cap(hw->dpcd);
+ hw->caps.tps3_supported = drm_dp_tps3_supported(hw->dpcd);
+ hw->caps.tps4_supported = drm_dp_tps4_supported(hw->dpcd);
+ hw->caps.vsc_supported = drm_dp_vsc_sdp_supported(&hw->aux, hw->dpcd);
+
+ hw->caps.max_lanes = drm_dp_max_lane_count(hw->dpcd);
+ hw->caps.max_rate = drm_dp_max_link_rate(hw->dpcd);
+
+ return 0;
+}
+
+static bool dptx_hw_vsc_supported(struct dp_hw *hw)
+{
+ return hw->caps.vsc_supported;
+}
+
+static void dptx_hw_stream_misc(struct dp_hw *hw, unsigned int stream_id,
+ enum dp_pixelformat format, u8 bpc,
+ bool vsc)
+{
+ u8 override_bpc;
+ u8 override = 0;
+ u8 misc1 = 0;
+ u8 misc0;
+
+ switch (format) {
+ case DP_PIXELFORMAT_YUV444:
+ misc0 = DPTX_STREAM_MISC0_COMP_FORMAT_YCRCB_444;
+ break;
+ case DP_PIXELFORMAT_YUV422:
+ misc0 = DPTX_STREAM_MISC0_COMP_FORMAT_YCRCB_422;
+ break;
+ default:
+ misc0 = DPTX_STREAM_MISC0_COMP_FORMAT_RGB;
+ break;
+ }
+
+ switch (bpc) {
+ case 6:
+ misc0 |= DPTX_STREAM_MISC0_BPC_6;
+ override_bpc = DPTX_STREAM_OVERRIDE_BPC_6;
+ break;
+ case 10:
+ misc0 |= DPTX_STREAM_MISC0_BPC_10;
+ override_bpc = DPTX_STREAM_OVERRIDE_BPC_10;
+ break;
+ case 12:
+ misc0 |= DPTX_STREAM_MISC0_BPC_12;
+ override_bpc = DPTX_STREAM_OVERRIDE_BPC_12;
+ break;
+ case 16:
+ misc0 |= DPTX_STREAM_MISC0_BPC_16;
+ override_bpc = DPTX_STREAM_OVERRIDE_BPC_16;
+ break;
+ default:
+ misc0 |= DPTX_STREAM_MISC0_BPC_8;
+ override_bpc = DPTX_STREAM_OVERRIDE_BPC_8;
+ break;
+ }
+
+ if (!vsc && format == DP_PIXELFORMAT_Y_ONLY)
+ misc1 |= DPTX_STREAM_MISC1_Y_ONLY_EN;
+
+ if (vsc) {
+ misc1 |= DPTX_VSC_COLORIMETRY_EN;
+ override = override_bpc | DPTX_STREAM_OVERRIDE_ENABLE;
+
+ switch (format) {
+ case DP_PIXELFORMAT_YUV444:
+ override |= DPTX_STREAM_OVERRIDE_YCbCR_444;
+ break;
+ case DP_PIXELFORMAT_YUV422:
+ override |= DPTX_STREAM_OVERRIDE_YCbCR_422;
+ break;
+ case DP_PIXELFORMAT_YUV420:
+ override |= DPTX_STREAM_OVERRIDE_YCbCR_420;
+ break;
+ default:
+ break;
+ }
+ }
+
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_MISC0(stream_id), misc0);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_MISC1(stream_id), misc1);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_OVERRIDE(stream_id),
+ override);
+}
+
+static void dptx_hw_stream_tu(struct dp_hw *hw, unsigned int stream_id,
+ u32 video_kbytes, u32 link_rate,
+ u8 lane_cnt)
+{
+ u32 bytes_per_tu_scaled;
+ u32 symbols_per_tu;
+ u32 frac_symbols_per_tu;
+ u32 tu;
+
+ /*
+ * Scaled by 1000 (fixed point) so the fraction below can be split
+ * into integer symbols + 1/16 fractional symbols without floating
+ * point.
+ */
+ bytes_per_tu_scaled = video_kbytes *
+ DPTX_MSA_TRANSFER_UNIT_SIZE_TU_SIZE_DEF /
+ (lane_cnt * link_rate / 1000);
+
+ symbols_per_tu = (bytes_per_tu_scaled / 1000) & 0xff;
+
+ /*
+ * Fractional number of valid symbols per TU in units of 1/16th. An
+ * accumulator is used to increase the number of data per transaction
+ * unit by 1 every 1/N TUs.
+ */
+ frac_symbols_per_tu = ((bytes_per_tu_scaled % 1000) * 16 / 1000) & 0x0f;
+
+ tu = DPTX_MSA_TRANSFER_UNIT_SIZE_TU_SIZE_DEF;
+ tu |= FIELD_PREP(GENMASK(23, 16), symbols_per_tu);
+ tu |= FIELD_PREP(GENMASK(27, 24), frac_symbols_per_tu);
+
+ dptx_hw_write(hw, DPTX_TU_CONFIG(stream_id), tu);
+}
+
+static void dptx_hw_stream_timing_set(struct dp_hw *hw, unsigned int stream_id,
+ const struct drm_display_mode *mode,
+ u8 bpp, u8 lane_cnt, u32 link_rate,
+ u32 pixel_per_cycle)
+{
+ u32 data_control = DPTX_DATA_CONTROL_DEFAULT;
+ u32 polarity;
+ u32 user_data_count;
+ u32 secondary_window;
+
+ if (pixel_per_cycle == 2 && lane_cnt == 4 &&
+ link_rate == drm_dp_bw_code_to_link_rate(DP_LINK_BW_8_1))
+ data_control = DPTX_DATA_CONTROL_2PPC_4LANE_HBR3;
+
+ polarity = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ?
+ BIT(DPTX_MAIN_STREAM_POLARITY_VSYNC_SHIFT) : 0) |
+ ((mode->flags & DRM_MODE_FLAG_PHSYNC) ?
+ BIT(DPTX_MAIN_STREAM_POLARITY_HSYNC_SHIFT) : 0);
+
+ user_data_count = ((mode->hdisplay * bpp + 7) / 8 + lane_cnt - 1) /
+ lane_cnt;
+
+ secondary_window = div_u64((u64)(mode->htotal - mode->hdisplay) *
+ (link_rate / 40) * 9, mode->clock);
+
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_HTOTAL(stream_id),
+ mode->htotal);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_VTOTAL(stream_id),
+ mode->vtotal);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_POLARITY(stream_id),
+ polarity);
+ dptx_hw_write(hw, DPTX_USER_SYNC_POLARITY(stream_id),
+ DPTX_MAIN_STREAM_POLARITY_DATAENABLE_HIGH |
+ polarity);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_HSWIDTH(stream_id),
+ mode->hsync_end - mode->hsync_start);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_VSWIDTH(stream_id),
+ mode->vsync_end - mode->vsync_start);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_HRES(stream_id),
+ mode->hdisplay);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_VRES(stream_id),
+ mode->vdisplay);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_HSTART(stream_id),
+ mode->htotal - mode->hsync_start);
+ dptx_hw_write(hw, DPTX_MAIN_STREAM_VSTART(stream_id),
+ mode->vtotal - mode->vsync_start);
+ dptx_hw_write(hw, DPTX_USER_DATA_COUNT(stream_id),
+ user_data_count);
+ dptx_hw_write(hw, DPTX_SECONDARY_DATA_WINDOW(stream_id),
+ secondary_window);
+ dptx_hw_write(hw, DPTX_DATA_CONTROL(stream_id), data_control);
+ dptx_hw_write(hw, DPTX_USER_PIXEL_COUNT(stream_id),
+ pixel_per_cycle);
+}
+
+static void dptx_hw_stream_timing(struct dp_hw *hw, unsigned int stream_id,
+ const struct drm_display_mode *mode,
+ u8 bpp, u8 lane_cnt, u32 link_rate,
+ u32 pixel_per_cycle)
+{
+ dptx_hw_stream_tu(hw, stream_id, mode->clock * bpp / 8, link_rate,
+ lane_cnt);
+ dptx_hw_stream_timing_set(hw, stream_id, mode, bpp, lane_cnt,
+ link_rate, pixel_per_cycle);
+}
+
+static void dptx_hw_stream_enable(struct dp_hw *hw, unsigned int stream_id,
+ bool enable)
+{
+ if (enable) {
+ dptx_hw_write(hw, DPTX_VIDEO_STREAM_ENABLE(stream_id), 1);
+ dptx_hw_write(hw, DPTX_SECONDARY_STREAM_ENABLE(stream_id), 1);
+ return;
+ }
+
+ dptx_hw_write(hw, DPTX_INFOFRAME_ENABLE(stream_id), 0);
+ dptx_hw_write(hw, DPTX_INFOFRAME_SELECT(stream_id), 0);
+ dptx_hw_write(hw, DPTX_INFOFRAME_RATE(stream_id), 0);
+ dptx_hw_write(hw, DPTX_SECONDARY_STREAM_ENABLE(stream_id), 0);
+ dptx_hw_write(hw, DPTX_VIDEO_STREAM_ENABLE(stream_id), 0);
+}
+
+static void dptx_hw_stream_infoframe_write(struct dp_hw *hw,
+ unsigned int stream_id, u32 select,
+ const struct dp_sdp *sdp,
+ bool repeat)
+{
+ u32 value;
+ int i;
+
+ if (stream_id >= DPTX_MST_SOURCE_NUMBER ||
+ select >= DPTX_MAX_SDP)
+ return;
+
+ value = dptx_hw_read(hw, DPTX_INFOFRAME_ENABLE(stream_id));
+ dptx_hw_write(hw, DPTX_INFOFRAME_ENABLE(stream_id),
+ value & ~BIT(select));
+ dptx_hw_write(hw, DPTX_INFOFRAME_SELECT(stream_id), select);
+
+ dptx_hw_write(hw, DPTX_INFOFRAME_DATA(stream_id),
+ sdp->sdp_header.HB0);
+ dptx_hw_write(hw, DPTX_INFOFRAME_DATA(stream_id),
+ sdp->sdp_header.HB1);
+ dptx_hw_write(hw, DPTX_INFOFRAME_DATA(stream_id),
+ sdp->sdp_header.HB2);
+ dptx_hw_write(hw, DPTX_INFOFRAME_DATA(stream_id),
+ sdp->sdp_header.HB3);
+
+ for (i = 0; i < DPTX_SDP_DB_MAX; i++)
+ dptx_hw_write(hw, DPTX_INFOFRAME_DATA(stream_id),
+ sdp->db[i]);
+
+ value = dptx_hw_read(hw, DPTX_INFOFRAME_RATE(stream_id));
+ if (repeat)
+ value |= BIT(select);
+ else
+ value &= ~BIT(select);
+ dptx_hw_write(hw, DPTX_INFOFRAME_RATE(stream_id), value);
+
+ value = dptx_hw_read(hw, DPTX_INFOFRAME_ENABLE(stream_id));
+ dptx_hw_write(hw, DPTX_INFOFRAME_ENABLE(stream_id),
+ value | BIT(select));
+}
+
+static bool dptx_hw_needs_vsc_sdp(enum dp_pixelformat format,
+ u32 colorspace)
+{
+ if (format == DP_PIXELFORMAT_YUV420)
+ return true;
+
+ switch (colorspace) {
+ case DRM_MODE_COLORIMETRY_BT709_YCC:
+ case DRM_MODE_COLORIMETRY_XVYCC_601:
+ case DRM_MODE_COLORIMETRY_XVYCC_709:
+ case DRM_MODE_COLORIMETRY_SYCC_601:
+ case DRM_MODE_COLORIMETRY_OPYCC_601:
+ case DRM_MODE_COLORIMETRY_BT2020_CYCC:
+ case DRM_MODE_COLORIMETRY_BT2020_RGB:
+ case DRM_MODE_COLORIMETRY_BT2020_YCC:
+ case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
+ case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+static enum dp_colorimetry
+dptx_hw_vsc_colorimetry(enum dp_pixelformat format, u32 colorspace)
+{
+ switch (colorspace) {
+ case DRM_MODE_COLORIMETRY_BT709_YCC:
+ return DP_COLORIMETRY_BT709_YCC;
+ case DRM_MODE_COLORIMETRY_XVYCC_601:
+ return DP_COLORIMETRY_XVYCC_601;
+ case DRM_MODE_COLORIMETRY_XVYCC_709:
+ return DP_COLORIMETRY_XVYCC_709;
+ case DRM_MODE_COLORIMETRY_SYCC_601:
+ return DP_COLORIMETRY_SYCC_601;
+ case DRM_MODE_COLORIMETRY_OPYCC_601:
+ return DP_COLORIMETRY_OPYCC_601;
+ case DRM_MODE_COLORIMETRY_BT2020_CYCC:
+ return DP_COLORIMETRY_BT2020_CYCC;
+ case DRM_MODE_COLORIMETRY_BT2020_RGB:
+ return DP_COLORIMETRY_BT2020_RGB;
+ case DRM_MODE_COLORIMETRY_BT2020_YCC:
+ return DP_COLORIMETRY_BT2020_YCC;
+ case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
+ case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
+ return DP_COLORIMETRY_DCI_P3_RGB;
+ default:
+ break;
+ }
+
+ /* Unspecified RGB is sRGB. Unspecified YCbCr is BT.709. */
+ if (format == DP_PIXELFORMAT_RGB)
+ return DP_COLORIMETRY_DEFAULT;
+
+ return DP_COLORIMETRY_BT709_YCC;
+}
+
+static int dptx_hw_stream_format_set(struct dp_hw *hw, unsigned int stream_id,
+ enum dp_pixelformat format, u32 colorspace,
+ u8 bpc, u8 content_type)
+{
+ struct drm_dp_vsc_sdp vsc = {};
+ struct dp_sdp sdp;
+ bool enable;
+ ssize_t len;
+
+ if (format == DP_PIXELFORMAT_YUV420 && !hw->caps.vsc_supported)
+ return -EINVAL;
+
+ enable = hw->caps.vsc_supported &&
+ dptx_hw_needs_vsc_sdp(format, colorspace);
+
+ if (enable) {
+ vsc.sdp_type = DP_SDP_VSC;
+ vsc.revision = 0x5;
+ vsc.length = 0x13;
+ vsc.pixelformat = format;
+ vsc.colorimetry = dptx_hw_vsc_colorimetry(format, colorspace);
+
+ switch (bpc) {
+ case 6:
+ case 8:
+ case 10:
+ case 12:
+ case 16:
+ vsc.bpc = bpc;
+ break;
+ default:
+ vsc.bpc = 8;
+ break;
+ }
+
+ vsc.dynamic_range = format == DP_PIXELFORMAT_RGB ?
+ DP_DYNAMIC_RANGE_VESA :
+ DP_DYNAMIC_RANGE_CTA;
+ vsc.content_type = content_type;
+
+ len = drm_dp_vsc_sdp_pack(&vsc, &sdp);
+ if (len < 0)
+ return len;
+ }
+
+ dptx_hw_stream_misc(hw, stream_id, format, bpc, enable);
+
+ if (enable)
+ dptx_hw_stream_infoframe_write(hw, stream_id, DPTX_VSC_SDP,
+ &sdp, true);
+ return 0;
+}
+
+static irqreturn_t dptx_hw_irq(struct dp_hw *hw)
+{
+ u32 value;
+ u32 mask;
+
+ /*
+ * DPTX_INTERRUPT_CAUSE is read-to-clear, so this read also
+ * acknowledges the pending interrupts.
+ */
+ value = dptx_hw_read(hw, DPTX_INTERRUPT_CAUSE);
+ mask = dptx_hw_read(hw, DPTX_INTERRUPT_MASK);
+ value &= ~mask;
+ if (!value)
+ return IRQ_NONE;
+
+ if (value & DPTX_INTERRUPT_GP_TIMER_IRQ)
+ dev_dbg_ratelimited(hw->dev, "gp tmr\n");
+
+ if (value & DPTX_INTERRUPT_REPLY_TIMEOUT)
+ dev_dbg_ratelimited(hw->dev, "reply timeout\n");
+
+ if (value & DPTX_INTERRUPT_REPLY_RECEIVED)
+ dev_dbg_ratelimited(hw->dev, "reply received\n");
+
+ if (value & DPTX_INTERRUPT_HPD_EVENT)
+ hw->hpd_event_callback(hw->data);
+
+ if (value & DPTX_INTERRUPT_HPD_IRQ)
+ hw->hpd_irq_callback(hw->data);
+
+ return IRQ_HANDLED;
+}
+
+static int dptx_hw_aux_register(struct dp_hw *hw,
+ struct drm_device *drm)
+{
+ int ret;
+
+ hw->aux.drm_dev = drm;
+
+ ret = drm_dp_aux_register(&hw->aux);
+ if (ret) {
+ hw->aux.drm_dev = NULL;
+ return ret;
+ }
+
+ hw->aux_registered = true;
+
+ return 0;
+}
+
+static void dptx_hw_aux_unregister(struct dp_hw *hw)
+{
+ if (!hw->aux_registered)
+ return;
+
+ drm_dp_aux_unregister(&hw->aux);
+ hw->aux.drm_dev = NULL;
+ hw->aux_registered = false;
+}
+
+static const struct dptx_hw_ops dptx_hw_ops = {
+ .hpd_state = dptx_hw_hpd_state,
+ .sink_present = dptx_hw_sink_present,
+
+ .host_enable = dptx_hw_host_enable,
+ .core_enable = dptx_hw_core_enable,
+
+ .apb_clock = dptx_hw_apb_clock,
+ .reset = dptx_hw_reset,
+
+ .link_train = dptx_hw_link_train,
+ .link_status = dptx_hw_link_status,
+
+ .aux_register = dptx_hw_aux_register,
+ .aux_unregister = dptx_hw_aux_unregister,
+
+ .dpcd_power_up = dptx_hw_dpcd_power_up,
+ .dpcd_power_down = dptx_hw_dpcd_power_down,
+ .dpcd_sink_caps = dptx_hw_dpcd_sink_caps,
+ .vsc_supported = dptx_hw_vsc_supported,
+
+ .stream_clock_enable = dptx_hw_stream_clock_enable,
+ .stream_clock_rate_set = dptx_hw_stream_clock_rate_set,
+ .stream_timing = dptx_hw_stream_timing,
+ .stream_enable = dptx_hw_stream_enable,
+ .stream_format_set = dptx_hw_stream_format_set,
+
+ .irq = dptx_hw_irq,
+};
+
+static int dptx_hw_parse_dt(struct dp_hw *hw)
+{
+ struct platform_device *pdev = to_platform_device(hw->dev);
+ struct device *dev = hw->dev;
+ int i;
+
+ hw->base = devm_platform_ioremap_resource_byname(pdev, "dp");
+ if (IS_ERR(hw->base))
+ return dev_err_probe(dev, PTR_ERR(hw->base),
+ "failed to map dp registers\n");
+
+ hw->reset = devm_reset_control_get(dev, NULL);
+ if (IS_ERR(hw->reset))
+ return dev_err_probe(dev, PTR_ERR(hw->reset),
+ "failed to get reset\n");
+
+ hw->apb_clk = devm_clk_get(dev, "apb");
+ if (IS_ERR(hw->apb_clk))
+ return dev_err_probe(dev, PTR_ERR(hw->apb_clk),
+ "failed to get apb clock\n");
+
+ for (i = 0; i < DPTX_MST_SOURCE_NUMBER &&
+ i < ARRAY_SIZE(stream_clk_names); i++) {
+ hw->stream_clk[i] = devm_clk_get(dev, stream_clk_names[i]);
+ if (IS_ERR(hw->stream_clk[i]))
+ return dev_err_probe(dev, PTR_ERR(hw->stream_clk[i]),
+ "failed to get %s\n",
+ stream_clk_names[i]);
+ }
+
+ return 0;
+}
+
+struct dp_hw *dptx_hw_init(struct device *dev, void *data,
+ void (*hpd_event_callback)(void *data),
+ void (*hpd_irq_callback)(void *data))
+{
+ struct dp_hw *hw;
+ int ret;
+
+ hw = kzalloc_obj(*hw);
+ if (!hw)
+ return ERR_PTR(-ENOMEM);
+
+ hw->dev = dev;
+ hw->data = data;
+ hw->hpd_event_callback = hpd_event_callback;
+ hw->hpd_irq_callback = hpd_irq_callback;
+ hw->ops = &dptx_hw_ops;
+
+ ret = dptx_hw_parse_dt(hw);
+ if (ret) {
+ kfree(hw);
+ return ERR_PTR(ret);
+ }
+
+ hw->aux.name = kasprintf(GFP_KERNEL, "%s AUX", dev_name(dev));
+ if (!hw->aux.name) {
+ kfree(hw);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ hw->aux.dev = dev;
+ hw->aux.transfer = dptx_hw_aux_transfer;
+
+ drm_dp_aux_init(&hw->aux);
+
+ return hw;
+}
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_hw.h b/drivers/gpu/drm/bridge/trilinear/dptx_hw.h
new file mode 100644
index 000000000000..420ef242a4f6
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx_hw.h
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * DisplayPort transmitter hardware interface
+ *
+ * Copyright (C) 2026 Trilinear Technologies
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#ifndef DPTX_HW_H
+#define DPTX_HW_H
+
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+
+#include <drm/display/drm_dp_helper.h>
+#include <drm/drm_modes.h>
+
+#define DPTX_MST_SOURCE_NUMBER 2
+#define DP_STREAM_MAX 4
+#define DPTX_MAX_LANES 4
+
+#define DPTX_MAX_SDP 7
+#define DPTX_VSC_SDP 1
+
+struct dptx_hw_ops;
+struct phy;
+struct reset_control;
+struct drm_device;
+
+struct dp_sink_caps {
+ bool enhanced_framing;
+ bool tps3_supported;
+ bool tps4_supported;
+ bool vsc_supported;
+ u8 max_lanes;
+ int max_rate;
+};
+
+struct dp_hw {
+ struct device *dev;
+ void __iomem *base;
+ struct clk *apb_clk;
+ struct clk *stream_clk[DP_STREAM_MAX];
+ struct reset_control *reset;
+ struct drm_dp_aux aux;
+ bool aux_registered;
+ u8 dpcd[DP_RECEIVER_CAP_SIZE];
+ u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
+ u8 train_setting[DPTX_MAX_LANES];
+ struct dp_sink_caps caps;
+ void (*hpd_event_callback)(void *data);
+ void (*hpd_irq_callback)(void *data);
+ const struct dptx_hw_ops *ops;
+ void *data;
+};
+
+struct dptx_hw_ops {
+ bool (*hpd_state)(struct dp_hw *hw);
+ bool (*sink_present)(struct dp_hw *hw);
+
+ void (*host_enable)(struct dp_hw *hw, bool enable);
+ void (*reset)(struct dp_hw *hw, bool assert);
+ void (*core_enable)(struct dp_hw *hw, int source_id, bool enable);
+
+ int (*apb_clock)(struct dp_hw *hw, bool enable);
+
+ int (*link_train)(struct dp_hw *hw, struct phy *phy, u8 bw_code,
+ u8 lane_cnt);
+
+ int (*link_status)(struct dp_hw *hw, u8 lane_cnt);
+
+ int (*aux_register)(struct dp_hw *hw, struct drm_device *drm);
+ void (*aux_unregister)(struct dp_hw *hw);
+
+ int (*dpcd_power_up)(struct dp_hw *hw, unsigned int delay_ms);
+ int (*dpcd_power_down)(struct dp_hw *hw, bool hpd);
+ int (*dpcd_sink_caps)(struct dp_hw *hw);
+ bool (*vsc_supported)(struct dp_hw *hw);
+
+ int (*stream_clock_enable)(struct dp_hw *hw, unsigned int stream_id,
+ bool enable);
+ int (*stream_clock_rate_set)(struct dp_hw *hw, unsigned int stream_id,
+ unsigned long rate);
+ void (*stream_timing)(struct dp_hw *hw, unsigned int stream_id,
+ const struct drm_display_mode *mode, u8 bpp,
+ u8 lane_cnt, u32 link_rate,
+ u32 pixel_per_cycle);
+ void (*stream_enable)(struct dp_hw *hw, unsigned int stream_id,
+ bool enable);
+
+ int (*stream_format_set)(struct dp_hw *hw, unsigned int stream_id,
+ enum dp_pixelformat format, u32 colorspace,
+ u8 bpc, u8 content_type);
+
+ irqreturn_t (*irq)(struct dp_hw *hw);
+};
+
+struct dp_hw *dptx_hw_init(struct device *dev, void *data,
+ void (*hpd_event_callback)(void *data),
+ void (*hpd_irq_callback)(void *data));
+
+#endif /* DPTX_HW_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
2026-12-04 11:43 ` [PATCH v10 1/5] dt-bindings: display: add CIX " Luo Liu
2026-12-04 11:43 ` [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
@ 2026-12-04 11:43 ` Luo Liu
2026-12-04 12:16 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
2026-12-04 11:43 ` [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu
4 siblings, 1 reply; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add the DRM bridge that exposes the transmitter to KMS: connector
detection, EDID mode enumeration with a downstream timing fallback,
validation of a mode against the sink link capabilities, and the atomic
enable and disable paths.
The bridge is meant to be attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR;
the connector is created by drm_bridge_connector_init() from the bridge
operations, so the driver only implements the bridge side and never
creates a connector of its own.
A mode whose horizontal backporch has to be widened is rejected when
the adjusted timings no longer fit the mode fields, so malformed
timings supplied from userspace cannot wrap around and reach the
hardware.
The bridge adds a device link to the controller on attach, so the
transmitter resumes before the controller's resume commit and is
suspended after the controller has stopped issuing commits. The link is
created only if the transmitter has not been released, and is dropped
on detach.
Signed-off-by: Luo Liu <Luo.Liu@cixtech.com>
---
MAINTAINERS | 1 +
drivers/gpu/drm/bridge/trilinear/dptx.h | 114 +++
drivers/gpu/drm/bridge/trilinear/dptx_drm.c | 769 ++++++++++++++++++++
drivers/gpu/drm/bridge/trilinear/dptx_drm.h | 17 +
include/drm/bridge/trilinear_dp.h | 74 ++
5 files changed, 975 insertions(+)
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx.h
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_drm.c
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_drm.h
create mode 100644 include/drm/bridge/trilinear_dp.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 01ff0666f63b..6ebb17dd18e9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6530,6 +6530,7 @@ L: dri-devel@lists.freedesktop.org
S: Maintained
F: Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
F: drivers/gpu/drm/bridge/trilinear/
+F: include/drm/bridge/trilinear_dp.h
CLANG CONTEXT ANALYSIS
M: Marco Elver <elver@google.com>
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx.h b/drivers/gpu/drm/bridge/trilinear/dptx.h
new file mode 100644
index 000000000000..3e3b8aee5ac4
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx.h
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * DisplayPort transmitter driver
+ *
+ * Copyright (C) 2026 Trilinear Technologies
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#ifndef DPTX_H
+#define DPTX_H
+
+#include <linux/bits.h>
+#include <linux/mutex.h>
+
+#include <drm/bridge/trilinear_dp.h>
+#include <drm/display/drm_dp_helper.h>
+#include <drm/drm_bridge.h>
+#include <drm/drm_connector.h>
+
+#include "dptx_hw.h"
+
+#define DPTX_MAX_RATE(rate, lanes, bpp) ((rate) * (lanes) * 8 / (bpp))
+
+#define bridge_to_dp(_bridge) \
+ container_of(_bridge, struct dptx_dev, bridge)
+
+#define DPTX_MAX_FREQ 600000
+#define DP_MAX_TRAINING_LOOP 3
+
+enum dptx_state {
+ DPTX_STATE_DISCONNECTED = 0,
+ DPTX_STATE_CONFIGURED = BIT(0),
+ DPTX_STATE_INITIALIZED = BIT(1),
+ DPTX_STATE_READY = BIT(2),
+ DPTX_STATE_CONNECTED = BIT(3),
+ DPTX_STATE_ENABLED = BIT(6),
+ DPTX_STATE_SUSPENDED = BIT(7),
+ DPTX_STATE_SHUTDOWN = BIT(9),
+};
+
+struct dptx_mode {
+ u8 bw_code;
+ u8 lane_cnt;
+ int pclock;
+ int link_rate;
+};
+
+struct dptx_config {
+ int bpp;
+ int bpc;
+ enum dp_pixelformat format;
+ u32 colorspace;
+ u8 content_type;
+};
+
+struct dptx_dev;
+struct dp_hw;
+struct phy;
+struct task_struct;
+
+struct dptx_ops {
+ int (*detect)(struct dptx_dev *dp);
+ enum drm_connector_status (*detect_status)(struct dptx_dev *dp);
+ int (*prepare)(struct dptx_dev *dp);
+ int (*unprepare)(struct dptx_dev *dp);
+ int (*encoder_enable)(struct dptx_dev *dp, unsigned int stream_id,
+ int enable);
+ int (*mode_configure)(struct dptx_dev *dp, int pclk, u8 bw, u8 bpp,
+ bool downshift);
+ void (*replay_deferred_hotplug)(struct dptx_dev *dp);
+ void (*quiesce_hpd)(struct dptx_dev *dp);
+};
+
+struct dptx_dev {
+ struct drm_bridge bridge;
+ struct drm_bridge *next_bridge;
+ struct device *dev;
+ struct phy *phy;
+ int irq;
+ bool irq_suspended;
+ bool hpd_stopped;
+ bool attached;
+ struct device *link_consumer;
+ /* Set when the platform device is gone; the bridge may still be in use. */
+ bool released;
+ /* Link limits of the current sink, clamped to the controller ones. */
+ int link_max_rate;
+ int link_max_lanes;
+
+ struct delayed_work hpd_event_work;
+ struct delayed_work hpd_irq_work;
+ u32 phy_dp_tries;
+ enum drm_connector_status force_hpd;
+ /* Tasks whose detect or hpd_notify result is currently echoing back. */
+ struct task_struct *detect_task;
+ struct task_struct *notify_task;
+ struct dptx_mode mode;
+ /* Adjusted mode of the enabled stream, cached for the hotplug workers. */
+ struct drm_display_mode adjusted_mode;
+ enum dptx_state state;
+ u32 pixel_per_cycle;
+ u32 active_stream_cnt;
+ /* Serializes the DP state against the hotplug workers. */
+ struct mutex lock;
+ u32 active_streams;
+ struct dptx_config config;
+ const struct dptx_ops *ops;
+ struct dp_hw *hw;
+ const struct dptx_plat_data *soc_data;
+ bool oob_hpd;
+ void *soc_priv;
+};
+
+#endif /* DPTX_H */
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_drm.c b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c
new file mode 100644
index 000000000000..02be7923528f
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c
@@ -0,0 +1,769 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * DisplayPort DRM bridge helpers
+ *
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/math64.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_bridge.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_print.h>
+
+#include "dptx.h"
+#include "dptx_drm.h"
+
+#define DPTX_MIN_H_BACKPORCH 12
+#define DPTX_MIN_BPP (6 * 3)
+
+struct fmt_prio_entry {
+ int format;
+ int bpc;
+};
+
+/* SST: RGB -> YUV422 10 -> YUV422 8 -> RGB 6 -> YUV420 8 */
+static const struct fmt_prio_entry fmt_prio[] = {
+ { DRM_OUTPUT_COLOR_FORMAT_RGB444, 0 },
+ { DRM_OUTPUT_COLOR_FORMAT_YCBCR422, 10 },
+ { DRM_OUTPUT_COLOR_FORMAT_YCBCR422, 8 },
+ { DRM_OUTPUT_COLOR_FORMAT_RGB444, 6 },
+ { DRM_OUTPUT_COLOR_FORMAT_YCBCR420, 8 },
+};
+
+static const u8 dp_common_link_bw[] = {
+ DP_LINK_BW_1_62,
+ DP_LINK_BW_2_7,
+ DP_LINK_BW_5_4,
+ DP_LINK_BW_8_1,
+};
+
+static enum drm_connector_status dptx_bridge_detect(struct drm_bridge *bridge,
+ struct drm_connector *connector)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ enum drm_connector_status status;
+
+ status = dp->ops->detect_status(dp);
+ WRITE_ONCE(dp->detect_task, current);
+
+ return status;
+}
+
+static void dptx_hpd_notify(struct dptx_dev *dp,
+ enum drm_connector_status hpd_state)
+{
+ if (READ_ONCE(dp->detect_task) == current) {
+ WRITE_ONCE(dp->detect_task, NULL);
+ return;
+ }
+
+ if (READ_ONCE(dp->notify_task) == current) {
+ WRITE_ONCE(dp->notify_task, NULL);
+ return;
+ }
+
+ if (!dp->oob_hpd)
+ return;
+
+ guard(mutex)(&dp->lock);
+
+ if (dp->hpd_stopped ||
+ hpd_state == connector_status_unknown)
+ return;
+
+ dp->force_hpd = hpd_state;
+
+ if (!(dp->state & DPTX_STATE_SUSPENDED)) {
+ queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
+ if (hpd_state == connector_status_connected)
+ queue_delayed_work(system_freezable_wq,
+ &dp->hpd_irq_work,
+ msecs_to_jiffies(20));
+ }
+}
+
+static void dptx_bridge_hpd_notify(struct drm_bridge *bridge,
+ struct drm_connector *connector,
+ enum drm_connector_status status)
+{
+ dptx_hpd_notify(bridge_to_dp(bridge), status);
+}
+
+static int dptx_bridge_get_modes(struct drm_bridge *bridge,
+ struct drm_connector *connector)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ const struct drm_edid *edid;
+ struct drm_display_mode *mode;
+ int ret;
+
+ scoped_guard(mutex, &dp->lock) {
+ if (dp->released ||
+ (dp->state & DPTX_STATE_SUSPENDED) ||
+ !(dp->state & DPTX_STATE_INITIALIZED) ||
+ !(dp->state & DPTX_STATE_CONNECTED))
+ return 0;
+
+ edid = drm_edid_read(connector);
+ }
+
+ if (edid) {
+ drm_edid_connector_update(connector, edid);
+ ret = drm_edid_connector_add_modes(connector);
+ drm_edid_free(edid);
+
+ return ret;
+ }
+
+ drm_edid_connector_update(connector, NULL);
+
+ scoped_guard(mutex, &dp->lock) {
+ if (dp->released || !(dp->state & DPTX_STATE_CONNECTED))
+ return 0;
+
+ mode = drm_dp_downstream_mode(connector->dev, dp->hw->dpcd,
+ dp->hw->downstream_ports);
+ }
+ if (!mode)
+ return 0;
+
+ drm_mode_probed_add(connector, mode);
+
+ return 1;
+}
+
+static u32 dptx_pick_ppc(const struct drm_display_mode *mode,
+ enum dp_pixelformat format)
+{
+ if (mode->clock > DPTX_MAX_FREQ &&
+ mode->clock < DPTX_MAX_FREQ * 2 &&
+ format != DP_PIXELFORMAT_YUV420)
+ return 2;
+
+ return 1;
+}
+
+static bool dptx_adjust_mode(const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode)
+{
+ u64 clock;
+ u32 htotal;
+ int diff = mode->htotal - mode->hsync_end;
+
+ if (diff < DPTX_MIN_H_BACKPORCH) {
+ htotal = mode->htotal + DPTX_MIN_H_BACKPORCH - diff;
+ if (htotal > U16_MAX)
+ return false;
+
+ clock = div_u64(mul_u32_u32(mode->clock, htotal),
+ mode->htotal);
+ if (clock > INT_MAX)
+ return false;
+
+ adjusted_mode->htotal = htotal;
+ adjusted_mode->clock = clock;
+ }
+
+ adjusted_mode->flags &= ~(DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC);
+ if (mode->flags & DRM_MODE_FLAG_PVSYNC)
+ adjusted_mode->flags |= DRM_MODE_FLAG_NVSYNC;
+ else
+ adjusted_mode->flags |= DRM_MODE_FLAG_PVSYNC;
+
+ adjusted_mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC);
+ if (mode->flags & DRM_MODE_FLAG_PHSYNC)
+ adjusted_mode->flags |= DRM_MODE_FLAG_NHSYNC;
+ else
+ adjusted_mode->flags |= DRM_MODE_FLAG_PHSYNC;
+
+ return true;
+}
+
+static enum drm_mode_status
+dptx_bridge_mode_valid(struct drm_bridge *bridge,
+ const struct drm_display_info *info,
+ const struct drm_display_mode *mode)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ struct drm_display_mode adjusted;
+ int max_lanes;
+ int max_rate;
+ u32 pixel_per_cycle;
+ int bpc = info->bpc ? info->bpc : 8;
+ int minbpp = DPTX_MIN_BPP;
+ bool vsc_supported;
+ bool can_420;
+
+ adjusted = *mode;
+ if (!dptx_adjust_mode(mode, &adjusted))
+ return MODE_H_ILLEGAL;
+
+ scoped_guard(mutex, &dp->lock) {
+ max_lanes = dp->link_max_lanes;
+ max_rate = dp->link_max_rate;
+ vsc_supported = dp->hw->ops->vsc_supported(dp->hw);
+ }
+
+ pixel_per_cycle = dptx_pick_ppc(&adjusted, DP_PIXELFORMAT_RGB);
+
+ can_420 = drm_mode_is_420(info, mode) && bridge->ycbcr_420_allowed &&
+ vsc_supported;
+
+ if (drm_mode_is_420_only(info, mode)) {
+ if (!can_420 || bpc < 8)
+ return MODE_NO_420;
+
+ minbpp = 8 * 3 / 2;
+ pixel_per_cycle = 1;
+ } else if (bpc >= 8 && can_420 && adjusted.clock <= DPTX_MAX_FREQ) {
+ minbpp = 8 * 3 / 2;
+ } else if (bpc >= 8 &&
+ info->color_formats &
+ BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422)) {
+ minbpp = 8 * 2;
+ }
+
+ if (pixel_per_cycle == 1 && adjusted.clock > DPTX_MAX_FREQ) {
+ drm_mode_debug_printmodeline(mode);
+ return MODE_CLOCK_HIGH;
+ }
+
+ if (adjusted.clock > DPTX_MAX_RATE(max_rate, max_lanes, minbpp)) {
+ drm_mode_debug_printmodeline(mode);
+ return MODE_CLOCK_HIGH;
+ }
+
+ return MODE_OK;
+}
+
+static bool dptx_bt2020_colorspace(const struct drm_connector_state *state)
+{
+ return state->colorspace >= DRM_MODE_COLORIMETRY_BT2020_CYCC &&
+ state->colorspace <= DRM_MODE_COLORIMETRY_BT2020_YCC;
+}
+
+static int dptx_cal_bpc(struct drm_connector_state *connector_state,
+ int format, int bpc)
+{
+ int max_bpc = connector_state->max_bpc;
+
+ if (dptx_bt2020_colorspace(connector_state))
+ max_bpc = min(max_bpc, 10);
+
+ bpc = min(bpc, max_bpc);
+
+ if (bpc >= 16)
+ bpc = 16;
+ else if (bpc >= 12)
+ bpc = 12;
+ else if (bpc >= 10)
+ bpc = 10;
+ else if (bpc >= 8)
+ bpc = 8;
+ else if (bpc >= 6)
+ bpc = 6;
+ else
+ return -EINVAL;
+
+ if (bpc < 8 && format != DRM_OUTPUT_COLOR_FORMAT_RGB444)
+ return -EINVAL;
+
+ return bpc;
+}
+
+static int dptx_cal_bpp(struct dptx_dev *dp, int bpc, int format)
+{
+ int bpp = bpc * 3;
+
+ switch (format) {
+ case DRM_OUTPUT_COLOR_FORMAT_RGB444:
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR444:
+ bpp = bpc * 3;
+ break;
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR422:
+ bpp = bpc * 2;
+ break;
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR420:
+ bpp = bpc * 3 / 2;
+ break;
+ default:
+ dev_warn(dp->dev, "invalid color format %d\n", format);
+ }
+ return bpp;
+}
+
+static int compute_available_clock_rate(struct dptx_dev *dp,
+ struct drm_connector_state *conn_state,
+ int suggest_bpc, int clock,
+ int color_format, int *rt_bpc,
+ int *rt_bpp)
+{
+ int max_lanes = dp->link_max_lanes;
+ int max_rate = dp->link_max_rate;
+ int rate;
+ int bpc;
+ int bpp;
+
+ bpc = dptx_cal_bpc(conn_state, color_format, suggest_bpc);
+ if (bpc < 0)
+ return bpc;
+ bpp = dptx_cal_bpp(dp, bpc, color_format);
+ rate = DPTX_MAX_RATE(max_rate, max_lanes, bpp);
+
+ if (clock <= rate) {
+ *rt_bpc = bpc;
+ *rt_bpp = bpp;
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+/*
+ * @mode still has the CEA timings and sync flags. adjusted_mode has had
+ * its polarities inverted, so it no longer matches a VIC.
+ */
+static bool dptx_format_ok(struct dptx_dev *dp,
+ const struct drm_display_info *info,
+ const struct drm_display_mode *mode,
+ const struct drm_display_mode *adjusted_mode,
+ int info_formats, int format)
+{
+ if (format == DRM_OUTPUT_COLOR_FORMAT_YCBCR420) {
+ if (!dp->hw->ops->vsc_supported(dp->hw))
+ return false;
+
+ /*
+ * Y420VDB sets the sink-wide 420 bit for every mode. This
+ * VIC has to be 420-only or 420-also. 420 is one pixel
+ * per cycle.
+ */
+ if (!drm_mode_is_420(info, mode))
+ return false;
+
+ return adjusted_mode->clock <= DPTX_MAX_FREQ;
+ }
+
+ if (drm_mode_is_420_only(info, mode))
+ return false;
+
+ if (adjusted_mode->clock >= DPTX_MAX_FREQ * 2)
+ return false;
+
+ return info_formats & BIT(format);
+}
+
+static int dptx_pick_format_bpc(struct dptx_dev *dp,
+ struct drm_connector_state *conn_state,
+ const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode,
+ int info_formats, int suggest_bpc,
+ int *color_format, int *bpc, int *bpp)
+{
+ struct drm_display_info *info =
+ &conn_state->connector->display_info;
+ int curr_bpc;
+ int format;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(fmt_prio); i++) {
+ format = fmt_prio[i].format;
+ curr_bpc = fmt_prio[i].bpc ? fmt_prio[i].bpc : suggest_bpc;
+
+ if (!dptx_format_ok(dp, info, mode, adjusted_mode,
+ info_formats, format))
+ continue;
+
+ /*
+ * First entry (RGB): prefer 10bit before falling back to
+ * suggest_bpc, and step down to 8bit before giving up on RGB.
+ * BT.2020 also tries 10 first when suggest_bpc is lower.
+ * The DPU always outputs RGB, so a lower RGB depth is still
+ * preferable to a converted YUV format.
+ */
+ if (i == 0) {
+ bool try_10 = suggest_bpc > 10 ||
+ (dptx_bt2020_colorspace(conn_state) &&
+ suggest_bpc < 10);
+
+ if (try_10 &&
+ !compute_available_clock_rate(dp, conn_state, 10,
+ adjusted_mode->clock,
+ format, bpc, bpp)) {
+ if (color_format)
+ *color_format = format;
+ return 0;
+ }
+
+ if (suggest_bpc <= 10 &&
+ !compute_available_clock_rate(dp, conn_state,
+ suggest_bpc,
+ adjusted_mode->clock,
+ format, bpc, bpp)) {
+ if (color_format)
+ *color_format = format;
+ return 0;
+ }
+
+ if (suggest_bpc > 8 &&
+ !compute_available_clock_rate(dp, conn_state, 8,
+ adjusted_mode->clock,
+ format, bpc, bpp)) {
+ if (color_format)
+ *color_format = format;
+ return 0;
+ }
+
+ continue;
+ }
+
+ if (!compute_available_clock_rate(dp, conn_state, curr_bpc,
+ adjusted_mode->clock,
+ format, bpc, bpp)) {
+ if (color_format)
+ *color_format = format;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+static enum dp_pixelformat dptx_drm_format_to_dp(int color_format)
+{
+ switch (color_format) {
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR444:
+ return DP_PIXELFORMAT_YUV444;
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR422:
+ return DP_PIXELFORMAT_YUV422;
+ case DRM_OUTPUT_COLOR_FORMAT_YCBCR420:
+ return DP_PIXELFORMAT_YUV420;
+ default:
+ return DP_PIXELFORMAT_RGB;
+ }
+}
+
+static int dptx_pick_link_rate(struct dptx_dev *dp,
+ struct drm_display_mode *adjusted_mode,
+ int bpp)
+{
+ int max_rate = dp->link_max_rate;
+ int max_lanes = dp->link_max_lanes;
+ int link_rate = max_rate;
+ int rate;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(dp_common_link_bw); i++) {
+ rate = drm_dp_bw_code_to_link_rate(dp_common_link_bw[i]);
+ if (rate > max_rate)
+ break;
+ if (adjusted_mode->clock <= DPTX_MAX_RATE(rate, max_lanes, bpp)) {
+ link_rate = rate;
+ break;
+ }
+ }
+
+ return link_rate;
+}
+
+static int dptx_pick_config(struct dptx_dev *dp,
+ struct drm_connector_state *conn_state,
+ const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode,
+ int *color_format, int *bpc, int *bpp)
+{
+ struct drm_display_info *info = &conn_state->connector->display_info;
+ u32 color_formats = info->color_formats;
+ int suggest_bpc;
+
+ color_formats |= BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444);
+
+ /* bpc 0 is unspecified. Start at 8, and never below 6. */
+ suggest_bpc = info->bpc ? info->bpc : 8;
+ if (suggest_bpc < 6)
+ suggest_bpc = 6;
+
+ return dptx_pick_format_bpc(dp, conn_state, mode, adjusted_mode,
+ color_formats, suggest_bpc,
+ color_format, bpc, bpp);
+}
+
+static int dptx_bridge_mode_set(struct dptx_dev *dp,
+ struct drm_crtc_state *crtc_state,
+ struct drm_connector_state *conn_state)
+{
+ struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
+ int color_format;
+ int link_rate;
+ int bw_code;
+ int bpc;
+ int bpp;
+ int ret;
+
+ ret = dp->ops->detect(dp);
+ if (ret)
+ return ret;
+
+ guard(mutex)(&dp->lock);
+
+ ret = dptx_pick_config(dp, conn_state, &crtc_state->mode,
+ adjusted_mode, &color_format, &bpc, &bpp);
+ if (ret)
+ return ret;
+
+ dp->config.format = dptx_drm_format_to_dp(color_format);
+ dp->config.colorspace = conn_state->colorspace;
+ dp->config.content_type = conn_state->content_type;
+ dp->config.bpc = bpc;
+ dp->config.bpp = bpp;
+ drm_mode_copy(&dp->adjusted_mode, adjusted_mode);
+ dp->pixel_per_cycle = dptx_pick_ppc(adjusted_mode, dp->config.format);
+
+ link_rate = dptx_pick_link_rate(dp, adjusted_mode, bpp);
+ bw_code = drm_dp_link_rate_to_bw_code(link_rate);
+
+ ret = dp->ops->mode_configure(dp, adjusted_mode->clock, bw_code,
+ bpp, false);
+ if (ret)
+ return ret;
+
+ dev_dbg(dp->dev,
+ "%dx%d@%d fmt=%d bpc=%d bpp=%d link=%u lanes=%u ppc=%u\n",
+ adjusted_mode->hdisplay, adjusted_mode->vdisplay,
+ drm_mode_vrefresh(adjusted_mode), dp->config.format,
+ bpc, bpp, bw_code, dp->mode.lane_cnt,
+ dp->pixel_per_cycle);
+
+ return 0;
+}
+
+static int dptx_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 dptx_dev *dp = bridge_to_dp(bridge);
+ int bpc;
+ int bpp;
+ int ret;
+ bool vsc_supported;
+
+ if (!conn_state->crtc)
+ return 0;
+
+ if (!crtc_state->active)
+ return 0;
+
+ if (!dptx_adjust_mode(&crtc_state->mode, &crtc_state->adjusted_mode))
+ return -EINVAL;
+
+ scoped_guard(mutex, &dp->lock) {
+ ret = dptx_pick_config(dp, conn_state, &crtc_state->mode,
+ &crtc_state->adjusted_mode,
+ NULL, &bpc, &bpp);
+ vsc_supported = dp->hw->ops->vsc_supported(dp->hw);
+ }
+ if (ret)
+ return ret;
+
+ if (vsc_supported) {
+ const struct drm_connector_state *old_conn_state;
+
+ 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;
+
+ ret = drm_atomic_add_affected_planes(bridge_state->base.state,
+ crtc_state->crtc);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static void
+dptx_bridge_atomic_enable(struct drm_bridge *bridge,
+ struct drm_atomic_commit *state)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ struct drm_connector_state *conn_state;
+ struct drm_crtc_state *crtc_state;
+ struct drm_connector *connector;
+ int ret;
+
+ connector = drm_atomic_get_new_connector_for_encoder(state,
+ bridge->encoder);
+ if (!connector)
+ return;
+
+ conn_state = drm_atomic_get_new_connector_state(state, connector);
+ if (!conn_state || !conn_state->crtc)
+ return;
+
+ crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
+ if (!crtc_state)
+ return;
+
+ ret = dp->ops->prepare(dp);
+ if (ret) {
+ if (ret != -ENODEV)
+ drm_err(bridge->dev, "failed to prepare DP output: %d\n",
+ ret);
+ return;
+ }
+
+ ret = dptx_bridge_mode_set(dp, crtc_state, conn_state);
+ if (ret) {
+ drm_err(bridge->dev, "failed to set DP mode: %d\n", ret);
+ goto err_unprepare;
+ }
+
+ ret = dp->ops->encoder_enable(dp, 0, true);
+ if (ret) {
+ drm_err(bridge->dev, "failed to enable DP output: %d\n", ret);
+ goto err_unprepare;
+ }
+
+ return;
+
+err_unprepare:
+ mutex_lock(&dp->lock);
+ dp->ops->unprepare(dp);
+ mutex_unlock(&dp->lock);
+}
+
+static void
+dptx_bridge_atomic_disable(struct drm_bridge *bridge,
+ struct drm_atomic_commit *state)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+
+ dp->ops->encoder_enable(dp, 0, false);
+}
+
+static void dptx_bridge_detach(struct drm_bridge *bridge);
+
+static int dptx_bridge_attach(struct drm_bridge *bridge,
+ struct drm_encoder *encoder,
+ enum drm_bridge_attach_flags flags)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ struct device_link *link;
+ int ret;
+
+ if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
+ return -EINVAL;
+
+ scoped_guard(mutex, &dp->lock) {
+ if (dp->released) {
+ ret = -ENODEV;
+ } else {
+ ret = dp->hw->ops->aux_register(dp->hw, bridge->dev);
+ if (!ret) {
+ link = device_link_add(bridge->dev->dev,
+ dp->dev,
+ DL_FLAG_STATELESS);
+ if (link) {
+ dp->link_consumer = bridge->dev->dev;
+ WRITE_ONCE(dp->hpd_stopped, false);
+ dp->attached = true;
+ } else {
+ dp->hw->ops->aux_unregister(dp->hw);
+ ret = -EINVAL;
+ }
+ }
+ }
+ }
+ if (ret)
+ return ret;
+
+ if (!dp->next_bridge)
+ return 0;
+
+ ret = drm_bridge_attach(encoder, dp->next_bridge, bridge, flags);
+ if (ret)
+ dptx_bridge_detach(bridge);
+
+ return ret;
+}
+
+static void dptx_bridge_hpd_enable(struct drm_bridge *bridge)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+
+ dp->ops->replay_deferred_hotplug(dp);
+}
+
+static void dptx_bridge_detach(struct drm_bridge *bridge)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+ struct device *consumer;
+
+ /* Stop workers before the connector goes away. */
+ dp->ops->quiesce_hpd(dp);
+
+ scoped_guard(mutex, &dp->lock) {
+ dp->attached = false;
+
+ if (!dp->released)
+ dp->hw->ops->aux_unregister(dp->hw);
+
+ consumer = dp->link_consumer;
+ dp->link_consumer = NULL;
+ }
+
+ if (consumer)
+ device_link_remove(consumer, dp->dev);
+}
+
+static void dptx_bridge_destroy(struct drm_bridge *bridge)
+{
+ struct dptx_dev *dp = bridge_to_dp(bridge);
+
+ if (dp->next_bridge)
+ drm_bridge_put(dp->next_bridge);
+
+ mutex_destroy(&dp->lock);
+
+ if (!dp->hw)
+ return;
+
+ kfree(dp->hw->aux.name);
+ kfree(dp->hw);
+}
+
+static const struct drm_bridge_funcs dptx_bridge_funcs = {
+ .attach = dptx_bridge_attach,
+ .detach = dptx_bridge_detach,
+ .destroy = dptx_bridge_destroy,
+ .detect = dptx_bridge_detect,
+ .get_modes = dptx_bridge_get_modes,
+ .mode_valid = dptx_bridge_mode_valid,
+ .hpd_notify = dptx_bridge_hpd_notify,
+ .hpd_enable = dptx_bridge_hpd_enable,
+ .atomic_check = dptx_bridge_atomic_check,
+ .atomic_enable = dptx_bridge_atomic_enable,
+ .atomic_disable = dptx_bridge_atomic_disable,
+ .atomic_create_state = drm_atomic_helper_bridge_create_state,
+ .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
+ .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
+};
+
+struct dptx_dev *dptx_bridge_alloc(struct device *dev)
+{
+ return devm_drm_bridge_alloc(dev, struct dptx_dev, bridge,
+ &dptx_bridge_funcs);
+}
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_drm.h b/drivers/gpu/drm/bridge/trilinear/dptx_drm.h
new file mode 100644
index 000000000000..fc30a7ce6e99
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx_drm.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * DisplayPort DRM helpers
+ *
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#ifndef DPTX_DRM_H
+#define DPTX_DRM_H
+
+#include <linux/device.h>
+
+#include "dptx.h"
+
+struct dptx_dev *dptx_bridge_alloc(struct device *dev);
+
+#endif /* DPTX_DRM_H */
diff --git a/include/drm/bridge/trilinear_dp.h b/include/drm/bridge/trilinear_dp.h
new file mode 100644
index 000000000000..c65ebd103f47
--- /dev/null
+++ b/include/drm/bridge/trilinear_dp.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * DisplayPort transmitter bridge driver
+ *
+ * Copyright (C) 2026 Trilinear Technologies
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#ifndef DRM_BRIDGE_TRILINEAR_DP_H
+#define DRM_BRIDGE_TRILINEAR_DP_H
+
+#include <linux/types.h>
+
+#include <drm/display/drm_dp.h>
+
+struct device;
+struct dptx_dev;
+
+/**
+ * struct dptx_plat_data - platform glue for the DPTX bridge
+ * @adapter_config: programs the SoC side pixel format and pixel-per-clock
+ * mode for a stream; @stream_id is the SST stream index,
+ * @format the pixel format carried on the link and @ppc2
+ * whether the stream runs at two pixels per clock
+ * @oob_hpd: HPD is reported out of band, for example through a USB-C port
+ * controller, instead of being wired to the transmitter
+ * @max_bw_code: highest DP link bandwidth code (DP_LINK_BW_*) the platform's
+ * DP output supports
+ *
+ * The bridge driver owns the DP protocol and the DRM bridge; the platform
+ * integration fills in the parts that are wired differently between SoCs.
+ */
+struct dptx_plat_data {
+ void (*adapter_config)(void *priv, unsigned int stream_id,
+ enum dp_pixelformat format, bool ppc2);
+ bool oob_hpd;
+ u8 max_bw_code;
+};
+
+/**
+ * trilinear_dptx_probe - allocate and register a DPTX bridge
+ * @dev: device backing the transmitter
+ * @soc_data: platform glue for this transmitter
+ * @priv: opaque context passed back to &dptx_plat_data.adapter_config
+ *
+ * Return: the DPTX device on success, or an ERR_PTR() on failure.
+ */
+struct dptx_dev *trilinear_dptx_probe(struct device *dev,
+ const struct dptx_plat_data *soc_data,
+ void *priv);
+
+/**
+ * trilinear_dptx_suspend - prepare a DPTX bridge for system sleep
+ * @dp: DPTX device returned by trilinear_dptx_probe()
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int trilinear_dptx_suspend(struct dptx_dev *dp);
+
+/**
+ * trilinear_dptx_resume - restore a DPTX bridge after system sleep
+ * @dp: DPTX device returned by trilinear_dptx_probe()
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+int trilinear_dptx_resume(struct dptx_dev *dp);
+
+/**
+ * trilinear_dptx_shutdown - stop a DPTX bridge on system shutdown
+ * @dp: DPTX device returned by trilinear_dptx_probe()
+ */
+void trilinear_dptx_shutdown(struct dptx_dev *dp);
+
+#endif /* DRM_BRIDGE_TRILINEAR_DP_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
` (2 preceding siblings ...)
2026-12-04 11:43 ` [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
@ 2026-12-04 11:43 ` Luo Liu
2026-12-04 12:15 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu
4 siblings, 1 reply; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add the probe path, system sleep handling, hotplug workers and the
stream state machine that tie the hardware layer to the DRM bridge, and
hook the driver into the DRM bridge Kconfig and Makefile.
A port@1 with a remote endpoint points at a converter bridge in front
of the connector, so the probe resolves it for the bridge to chain; a
port@1 without one feeds the native DP PHY directly.
Detection is driven by the controller's HPD interrupt. The USB-C
transmitters do not route HPD to the controller, so a sink that was
plugged in before the bridge was attached raises no event; replay that
plug once the common PHY is in DP mode and the AUX channel answers. The
native DP port wires HPD and is reported by the interrupt.
An atomic enable that arrives while the transmitter is suspended is
refused instead of powering the host back up behind the sleep callbacks;
the host is left for the resume path to bring up again.
The transmitter is torn down from the platform remove callback as well
as from devres, so the device link is dropped while the device is still
registered; device links are purged during device removal and must not
be released afterwards.
Signed-off-by: Luo Liu <Luo.Liu@cixtech.com>
---
drivers/gpu/drm/bridge/Kconfig | 2 +
drivers/gpu/drm/bridge/Makefile | 1 +
drivers/gpu/drm/bridge/trilinear/Kconfig | 9 +
drivers/gpu/drm/bridge/trilinear/Makefile | 4 +
drivers/gpu/drm/bridge/trilinear/dptx_core.c | 1077 ++++++++++++++++++
include/drm/bridge/trilinear_dp.h | 10 +
6 files changed, 1103 insertions(+)
create mode 100644 drivers/gpu/drm/bridge/trilinear/Kconfig
create mode 100644 drivers/gpu/drm/bridge/trilinear/Makefile
create mode 100644 drivers/gpu/drm/bridge/trilinear/dptx_core.c
diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index c7da6b02d7b6..d328d5f84dc7 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -510,4 +510,6 @@ source "drivers/gpu/drm/bridge/imx/Kconfig"
source "drivers/gpu/drm/bridge/synopsys/Kconfig"
+source "drivers/gpu/drm/bridge/trilinear/Kconfig"
+
endmenu
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 15cc821d85b7..9fe6bec55c51 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -53,3 +53,4 @@ obj-y += analogix/
obj-y += cadence/
obj-y += imx/
obj-y += synopsys/
+obj-y += trilinear/
diff --git a/drivers/gpu/drm/bridge/trilinear/Kconfig b/drivers/gpu/drm/bridge/trilinear/Kconfig
new file mode 100644
index 000000000000..7e2bf1f27035
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/Kconfig
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DRM_TRILINEAR_DPTX
+ tristate
+ depends on COMMON_CLK && DRM && OF
+ depends on GENERIC_PHY
+ select DRM_KMS_HELPER
+ select DRM_DISPLAY_HELPER
+ select DRM_DISPLAY_DP_HELPER
diff --git a/drivers/gpu/drm/bridge/trilinear/Makefile b/drivers/gpu/drm/bridge/trilinear/Makefile
new file mode 100644
index 000000000000..415842b8465d
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+trilinear-dptx-y := dptx_core.o dptx_drm.o dptx_hw.o
+obj-$(CONFIG_DRM_TRILINEAR_DPTX) += trilinear-dptx.o
diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_core.c b/drivers/gpu/drm/bridge/trilinear/dptx_core.c
new file mode 100644
index 000000000000..5ca90acfb981
--- /dev/null
+++ b/drivers/gpu/drm/bridge/trilinear/dptx_core.c
@@ -0,0 +1,1077 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 Trilinear Technologies
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/of_irq.h>
+#include <linux/phy/phy.h>
+#include <linux/sched.h>
+#include <linux/workqueue.h>
+
+#include <drm/drm_bridge.h>
+
+#include "dptx.h"
+#include "dptx_drm.h"
+#include "dptx_hw.h"
+
+#define DEFAULT_DP_POWER_ON_DELAY_MS 4
+#define DP_HPD_MAX_TRIES 100
+
+static unsigned int dptx_power_on_delay_ms = DEFAULT_DP_POWER_ON_DELAY_MS;
+module_param_named(power_on_delay_ms, dptx_power_on_delay_ms, uint, 0444);
+MODULE_PARM_DESC(power_on_delay_ms,
+ "Delay after powering the sink up, in msec (default: 4)");
+
+static bool dptx_regs_accessible(struct dptx_dev *dp)
+{
+ return !(dp->state & DPTX_STATE_SUSPENDED) &&
+ (dp->state & DPTX_STATE_INITIALIZED);
+}
+
+static bool dptx_get_hpd_state(struct dptx_dev *dp)
+{
+ return dp->hw->ops->hpd_state(dp->hw) ||
+ dp->force_hpd == connector_status_connected;
+}
+
+static int dptx_get_lanes(struct dptx_dev *dp, int link_rate, int pclk, u8 bpp)
+{
+ int max_lanes = dp->link_max_lanes;
+ int i;
+
+ for (i = 1; i <= max_lanes; i <<= 1) {
+ if (pclk <= DPTX_MAX_RATE(link_rate, i, bpp ? bpp : 24))
+ return i;
+ }
+
+ return 0;
+}
+
+static int dptx_mode_configure(struct dptx_dev *dp, int pclk, u8 bw, u8 bpp,
+ bool downshift)
+{
+ int lane_cnt;
+ int bw_code;
+ int link_rate;
+
+ if (!downshift) {
+ bw_code = bw;
+ } else {
+ link_rate = drm_dp_bw_code_to_link_rate(bw);
+ if (link_rate > 540000)
+ bw_code = DP_LINK_BW_5_4;
+ else if (link_rate > 270000)
+ bw_code = DP_LINK_BW_2_7;
+ else if (link_rate > 162000)
+ bw_code = DP_LINK_BW_1_62;
+ else
+ return -EINVAL;
+ }
+
+ link_rate = drm_dp_bw_code_to_link_rate(bw_code);
+ lane_cnt = dptx_get_lanes(dp, link_rate, pclk, bpp);
+ if (!lane_cnt)
+ return -EINVAL;
+
+ dp->mode.bw_code = bw_code;
+ dp->mode.link_rate = link_rate;
+ dp->mode.lane_cnt = lane_cnt;
+ dp->mode.pclock = pclk;
+
+ return 0;
+}
+
+static struct drm_display_mode *dptx_get_mode(struct dptx_dev *dp,
+ unsigned int stream_id)
+{
+ if (stream_id >= DPTX_MST_SOURCE_NUMBER)
+ return NULL;
+
+ if (!(dp->active_streams & BIT(stream_id)))
+ return NULL;
+
+ return &dp->adjusted_mode;
+}
+
+static void dptx_active_streams(struct dptx_dev *dp)
+{
+ struct drm_display_mode *mode;
+ int i;
+
+ if (!dp->attached)
+ return;
+
+ for (i = 0; i < DPTX_MST_SOURCE_NUMBER; i++) {
+ if (!(dp->active_streams & BIT(i)))
+ continue;
+
+ mode = dptx_get_mode(dp, i);
+ if (!mode)
+ continue;
+
+ dp->hw->ops->stream_timing(dp->hw, i, mode,
+ dp->config.bpp,
+ dp->mode.lane_cnt, dp->mode.link_rate,
+ dp->pixel_per_cycle);
+ }
+}
+
+static int dptx_stream_hw_cfg(struct dptx_dev *dp, unsigned int stream_id)
+{
+ const struct dptx_config *config = &dp->config;
+ struct drm_display_mode *mode = dptx_get_mode(dp, stream_id);
+ int ret;
+
+ if (!mode)
+ return -EINVAL;
+
+ ret = dp->hw->ops->stream_format_set(dp->hw, stream_id, config->format,
+ config->colorspace, config->bpc,
+ config->content_type);
+ if (ret)
+ return ret;
+
+ dp->hw->ops->stream_timing(dp->hw, stream_id, mode,
+ dp->config.bpp, dp->mode.lane_cnt,
+ dp->mode.link_rate, dp->pixel_per_cycle);
+
+ dp->soc_data->adapter_config(dp->soc_priv, stream_id,
+ config->format, dp->pixel_per_cycle == 2);
+
+ return 0;
+}
+
+static int dptx_ctrl_stream_on(struct dptx_dev *dp, unsigned int stream_id)
+{
+ struct drm_display_mode *mode;
+ unsigned long pixel_clock;
+ int ret;
+
+ if (stream_id >= DPTX_MST_SOURCE_NUMBER)
+ return -EINVAL;
+
+ mode = dptx_get_mode(dp, stream_id);
+ if (!mode)
+ return -EINVAL;
+
+ pixel_clock = (unsigned long)mode->clock * 1000 / dp->pixel_per_cycle;
+ ret = dp->hw->ops->stream_clock_rate_set(dp->hw, stream_id, pixel_clock);
+ if (ret)
+ return ret;
+
+ ret = dp->hw->ops->stream_clock_enable(dp->hw, stream_id, true);
+ if (ret)
+ return ret;
+
+ ret = dptx_stream_hw_cfg(dp, stream_id);
+ if (ret) {
+ dp->hw->ops->stream_clock_enable(dp->hw, stream_id, false);
+ return ret;
+ }
+
+ dp->hw->ops->stream_enable(dp->hw, stream_id, true);
+
+ dp->active_stream_cnt++;
+ return 0;
+}
+
+static void dptx_ctrl_stream_off(struct dptx_dev *dp, unsigned int stream_id)
+{
+ dp->hw->ops->stream_enable(dp->hw, stream_id, false);
+ dp->hw->ops->stream_clock_enable(dp->hw, stream_id, false);
+
+ dp->active_stream_cnt--;
+}
+
+static void dptx_stop_streams(struct dptx_dev *dp)
+{
+ int i;
+
+ if (!(dp->state & DPTX_STATE_INITIALIZED))
+ return;
+
+ for (i = 0; i < DPTX_MST_SOURCE_NUMBER; i++) {
+ if (!(dp->active_streams & BIT(i)))
+ continue;
+
+ dptx_ctrl_stream_off(dp, i);
+ dp->active_streams &= ~BIT(i);
+ }
+
+ if (!dp->active_stream_cnt)
+ dp->state &= ~DPTX_STATE_ENABLED;
+}
+
+static int dptx_enable(struct dptx_dev *dp, unsigned int stream_id)
+{
+ int ret;
+
+ if (stream_id >= DPTX_MST_SOURCE_NUMBER)
+ return -EINVAL;
+
+ if (dp->active_streams & BIT(stream_id))
+ return 0;
+
+ if (!(dp->state & DPTX_STATE_INITIALIZED) ||
+ !(dp->state & DPTX_STATE_READY)) {
+ dev_dbg(dp->dev, "enable skipped, state=0x%x\n", dp->state);
+ return 0;
+ }
+
+ dp->active_streams |= BIT(stream_id);
+ ret = dptx_ctrl_stream_on(dp, stream_id);
+ if (ret) {
+ dp->active_streams &= ~BIT(stream_id);
+ return ret;
+ }
+
+ dp->state |= DPTX_STATE_ENABLED;
+
+ return 0;
+}
+
+static int dptx_disable(struct dptx_dev *dp, unsigned int stream_id)
+{
+ if (stream_id >= DPTX_MST_SOURCE_NUMBER)
+ return -EINVAL;
+
+ if (!(dp->state & DPTX_STATE_ENABLED) ||
+ !(dp->state & DPTX_STATE_INITIALIZED))
+ return 0;
+
+ if (dp->active_stream_cnt && (dp->active_streams & BIT(stream_id))) {
+ dptx_ctrl_stream_off(dp, stream_id);
+ dp->active_streams &= ~BIT(stream_id);
+ }
+
+ return 0;
+}
+
+static int dptx_train_loop(struct dptx_dev *dp)
+{
+ struct dptx_mode *mode = &dp->mode;
+ struct dptx_mode orig = dp->mode;
+ u8 bpp = dp->config.bpp;
+ u8 prev_bw = mode->bw_code;
+ u8 prev_lanes = mode->lane_cnt;
+ u8 bw_code = mode->bw_code;
+ int i;
+ int j;
+ int ret;
+
+ for (i = 0; i < DP_MAX_TRAINING_LOOP; i++) {
+ for (j = 0; j <= 3; j++) {
+ if (!(dp->state & DPTX_STATE_READY) ||
+ !dptx_get_hpd_state(dp)) {
+ ret = -ENODEV;
+ goto err_restore;
+ }
+
+ ret = dp->hw->ops->link_train(dp->hw, dp->phy,
+ mode->bw_code,
+ mode->lane_cnt);
+ if (!ret) {
+ if (dp->active_stream_cnt &&
+ (mode->bw_code != prev_bw ||
+ mode->lane_cnt != prev_lanes))
+ dptx_active_streams(dp);
+ return 0;
+ }
+
+ if (ret != -EIO)
+ goto err_restore;
+
+ ret = dptx_mode_configure(dp, mode->pclock, bw_code,
+ bpp, true);
+ if (ret < 0)
+ break;
+
+ bw_code = dp->mode.bw_code;
+ }
+
+ ret = dptx_mode_configure(dp, mode->pclock,
+ drm_dp_link_rate_to_bw_code(dp->link_max_rate),
+ bpp, false);
+ if (ret < 0)
+ goto err_restore;
+
+ bw_code = dp->mode.bw_code;
+ }
+
+ ret = -EIO;
+err_restore:
+ dp->mode = orig;
+
+ return ret;
+}
+
+static int dptx_read_sink_caps(struct dptx_dev *dp)
+{
+ int max_rate;
+ int ret;
+
+ ret = dp->hw->ops->dpcd_sink_caps(dp->hw);
+ if (ret)
+ return ret;
+
+ if (!dp->hw->caps.max_lanes || !dp->hw->caps.max_rate)
+ return -EINVAL;
+
+ max_rate = drm_dp_bw_code_to_link_rate(dp->soc_data->max_bw_code);
+
+ dp->link_max_lanes = min_t(u8, dp->hw->caps.max_lanes, DPTX_MAX_LANES);
+ dp->link_max_rate = min_t(int, dp->hw->caps.max_rate, max_rate);
+
+ return 0;
+}
+
+static int dptx_core_on(struct dptx_dev *dp)
+{
+ int i, ret;
+
+ if (dp->state & DPTX_STATE_READY)
+ return 0;
+
+ dp->state |= DPTX_STATE_READY;
+
+ for (i = 0; i < DPTX_MST_SOURCE_NUMBER; i++)
+ dp->hw->ops->stream_enable(dp->hw, i, false);
+
+ ret = phy_power_on(dp->phy);
+ if (ret)
+ goto err;
+
+ ret = dp->hw->ops->dpcd_power_up(dp->hw, dptx_power_on_delay_ms);
+ if (ret)
+ goto err_power;
+
+ ret = dptx_read_sink_caps(dp);
+ if (ret)
+ goto err_power;
+
+ ret = dptx_train_loop(dp);
+ if (ret)
+ goto err_power;
+
+ dp->hw->ops->core_enable(dp->hw, 0, true);
+
+ return 0;
+
+err_power:
+ dp->hw->ops->dpcd_power_down(dp->hw, dptx_get_hpd_state(dp));
+ phy_power_off(dp->phy);
+err:
+ dp->state &= ~DPTX_STATE_READY;
+ return ret;
+}
+
+static int dptx_core_off(struct dptx_dev *dp)
+{
+ if (!(dp->state & DPTX_STATE_READY))
+ return 0;
+
+ dp->hw->ops->dpcd_power_down(dp->hw, dptx_get_hpd_state(dp));
+
+ phy_power_off(dp->phy);
+ dp->hw->ops->core_enable(dp->hw, 0, false);
+
+ dp->state &= ~DPTX_STATE_READY;
+
+ return 0;
+}
+
+static int dptx_host_reset(struct dptx_dev *dp)
+{
+ int ret;
+
+ dp->hw->ops->reset(dp->hw, true);
+ usleep_range(10, 20);
+ dp->hw->ops->reset(dp->hw, false);
+
+ ret = phy_reset(dp->phy);
+ if (ret)
+ return ret;
+
+ usleep_range(100, 200);
+ dp->hw->ops->host_enable(dp->hw, true);
+
+ ret = phy_init(dp->phy);
+ if (ret) {
+ dp->hw->ops->host_enable(dp->hw, false);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int dptx_host_init(struct dptx_dev *dp)
+{
+ int ret;
+
+ if (dp->state & DPTX_STATE_INITIALIZED)
+ return 0;
+
+ ret = dp->hw->ops->apb_clock(dp->hw, true);
+ if (ret)
+ return ret;
+
+ ret = dptx_host_reset(dp);
+ if (ret) {
+ dp->hw->ops->apb_clock(dp->hw, false);
+ return ret;
+ }
+
+ drm_dp_dpcd_set_powered(&dp->hw->aux, true);
+ dp->state |= DPTX_STATE_INITIALIZED;
+
+ return 0;
+}
+
+static void dptx_host_deinit(struct dptx_dev *dp)
+{
+ if (dp->state & DPTX_STATE_READY)
+ dptx_core_off(dp);
+
+ dp->force_hpd = connector_status_unknown;
+
+ if (!(dp->state & DPTX_STATE_INITIALIZED))
+ return;
+
+ drm_dp_dpcd_set_powered(&dp->hw->aux, false);
+
+ dp->hw->ops->host_enable(dp->hw, false);
+ phy_exit(dp->phy);
+ dp->hw->ops->apb_clock(dp->hw, false);
+
+ dp->state &= ~DPTX_STATE_INITIALIZED;
+}
+
+static int dptx_host_resume(struct dptx_dev *dp)
+{
+ int ret;
+
+ if (!(dp->state & DPTX_STATE_SUSPENDED))
+ return 0;
+
+ ret = dptx_host_init(dp);
+ if (ret)
+ return ret;
+
+ if (dp->irq_suspended) {
+ enable_irq(dp->irq);
+ dp->irq_suspended = false;
+ }
+
+ dp->state &= ~DPTX_STATE_SUSPENDED;
+ return 0;
+}
+
+static int dptx_handle_connect(struct dptx_dev *dp)
+{
+ int ret;
+
+ if (dp->state & DPTX_STATE_SUSPENDED)
+ return 0;
+
+ ret = dptx_read_sink_caps(dp);
+ if (ret) {
+ dp->state &= ~DPTX_STATE_CONNECTED;
+ return ret;
+ }
+
+ dp->state |= DPTX_STATE_CONNECTED;
+
+ return 0;
+}
+
+static int dptx_handle_disconnect(struct dptx_dev *dp)
+{
+ dp->state &= ~DPTX_STATE_CONNECTED;
+
+ /*
+ * The typec state can lag behind the PHY. Keep the forced state
+ * unless the PHY is in DP mode, where an AUX probe can correct a
+ * stale report.
+ */
+ if (!dp->oob_hpd ||
+ phy_get_mode(dp->phy) == PHY_MODE_DP)
+ dp->force_hpd = connector_status_unknown;
+
+ return 0;
+}
+
+static enum drm_connector_status dptx_ret_to_status(int ret)
+{
+ if (ret == -EBUSY)
+ return connector_status_unknown;
+ if (ret)
+ return connector_status_disconnected;
+
+ return connector_status_connected;
+}
+
+static int dptx_detect_locked(struct dptx_dev *dp)
+{
+ if (dp->released)
+ return -ENODEV;
+
+ if (dp->state & DPTX_STATE_SUSPENDED)
+ return -EBUSY;
+
+ if (!(dp->state & DPTX_STATE_INITIALIZED)) {
+ dev_warn_once(dp->dev, "detect with uninitialized host\n");
+ return -ENODEV;
+ }
+
+ if (!dptx_get_hpd_state(dp)) {
+ dptx_handle_disconnect(dp);
+ return -ENODEV;
+ }
+
+ return dptx_handle_connect(dp);
+}
+
+static int dptx_detect(struct dptx_dev *dp)
+{
+ guard(mutex)(&dp->lock);
+
+ return dptx_detect_locked(dp);
+}
+
+static enum drm_connector_status dptx_detect_status(struct dptx_dev *dp)
+{
+ return dptx_ret_to_status(dptx_detect(dp));
+}
+
+static void dptx_notify_hpd(struct dptx_dev *dp,
+ enum drm_connector_status status)
+{
+ WRITE_ONCE(dp->notify_task, current);
+ drm_bridge_hpd_notify(&dp->bridge, status);
+ WRITE_ONCE(dp->notify_task, NULL);
+}
+
+static bool dptx_hpd_work_aborted(struct dptx_dev *dp)
+{
+ return dp->hpd_stopped ||
+ !dp->attached ||
+ !dptx_regs_accessible(dp);
+}
+
+static bool dptx_hpd_wait_aborted(struct dptx_dev *dp)
+{
+ guard(mutex)(&dp->lock);
+
+ return dptx_hpd_work_aborted(dp) || !dptx_get_hpd_state(dp);
+}
+
+static bool dptx_phy_dp_mode_ready(struct dptx_dev *dp)
+{
+ if (phy_get_mode(dp->phy) == PHY_MODE_DP) {
+ dp->phy_dp_tries = 0;
+ return true;
+ }
+
+ if (dptx_hpd_wait_aborted(dp) ||
+ ++dp->phy_dp_tries > DP_HPD_MAX_TRIES) {
+ dp->phy_dp_tries = 0;
+ dev_dbg(dp->dev, "PHY did not enter DP mode\n");
+ return false;
+ }
+
+ queue_delayed_work(system_freezable_wq, &dp->hpd_event_work,
+ msecs_to_jiffies(100));
+
+ return false;
+}
+
+static void dptx_hpd_event_work_func(struct work_struct *work)
+{
+ struct dptx_dev *dp = container_of(work, struct dptx_dev,
+ hpd_event_work.work);
+ enum drm_connector_status status;
+ bool hpd;
+
+ scoped_guard(mutex, &dp->lock) {
+ if (dptx_hpd_work_aborted(dp))
+ return;
+
+ hpd = dptx_get_hpd_state(dp);
+ }
+
+ if (hpd && dp->oob_hpd && !dptx_phy_dp_mode_ready(dp))
+ return;
+
+ scoped_guard(mutex, &dp->lock) {
+ if (dptx_hpd_work_aborted(dp))
+ return;
+
+ status = dptx_ret_to_status(dptx_detect_locked(dp));
+ }
+
+ if (dp->bridge.dev)
+ dptx_notify_hpd(dp, status);
+}
+
+static void dptx_hpd_irq_work_func(struct work_struct *work)
+{
+ struct dptx_dev *dp = container_of(work, struct dptx_dev,
+ hpd_irq_work.work);
+
+ guard(mutex)(&dp->lock);
+
+ if (dp->hpd_stopped ||
+ !dptx_regs_accessible(dp) ||
+ !(dp->state & DPTX_STATE_ENABLED) ||
+ !dptx_get_hpd_state(dp))
+ return;
+
+ if (dp->hw->ops->link_status(dp->hw, dp->mode.lane_cnt) > 0)
+ dptx_train_loop(dp);
+}
+
+static bool dptx_deferred_hotplug_pending(struct dptx_dev *dp)
+{
+ return !dptx_hpd_work_aborted(dp) &&
+ !dp->released &&
+ dp->force_hpd == connector_status_unknown;
+}
+
+/*
+ * Replay a plug that happened before the connector existed. A USB-C combo
+ * PHY does not wire HPD to this controller, so a sink plugged in early
+ * never raises HPD_EVENT; replay it once the PHY is in DP mode and AUX
+ * answers. A native DP port whose HPD pin is already asserted is caught by
+ * the state check below and detected the same way; the rest of that port's
+ * hotplugs come from the HPD interrupt.
+ */
+static void dptx_replay_deferred_hotplug(struct dptx_dev *dp)
+{
+ guard(mutex)(&dp->lock);
+
+ if (!dptx_deferred_hotplug_pending(dp))
+ return;
+
+ if (dptx_get_hpd_state(dp)) {
+ queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
+ return;
+ }
+
+ if (!dp->oob_hpd || phy_get_mode(dp->phy) != PHY_MODE_DP)
+ return;
+
+ if (!dp->hw->ops->sink_present(dp->hw))
+ return;
+
+ dp->force_hpd = connector_status_connected;
+
+ queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
+}
+
+static irqreturn_t dptx_irq_handler(int irq, void *data)
+{
+ struct dptx_dev *dp = data;
+
+ return dp->hw->ops->irq(dp->hw);
+}
+
+static void dptx_queue_hpd_event(void *data)
+{
+ struct dptx_dev *dp = data;
+
+ if (!READ_ONCE(dp->hpd_stopped))
+ queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
+}
+
+static void dptx_queue_hpd_irq(void *data)
+{
+ struct dptx_dev *dp = data;
+
+ if (!READ_ONCE(dp->hpd_stopped))
+ queue_delayed_work(system_freezable_wq, &dp->hpd_irq_work, 0);
+}
+
+static void dptx_irq_off(struct dptx_dev *dp)
+{
+ if (dp->irq_suspended)
+ return;
+
+ disable_irq(dp->irq);
+ dp->irq_suspended = true;
+}
+
+static void dptx_cancel_hpd_works(struct dptx_dev *dp)
+{
+ cancel_delayed_work_sync(&dp->hpd_irq_work);
+ cancel_delayed_work_sync(&dp->hpd_event_work);
+}
+
+static void dptx_quiesce_hpd(struct dptx_dev *dp)
+{
+ scoped_guard(mutex, &dp->lock) {
+ WRITE_ONCE(dp->hpd_stopped, true);
+
+ if (!dp->released)
+ synchronize_irq(dp->irq);
+ }
+
+ dptx_cancel_hpd_works(dp);
+}
+
+static int dptx_pm_prepare(struct dptx_dev *dp, bool shutdown)
+{
+ scoped_guard(mutex, &dp->lock) {
+ dptx_irq_off(dp);
+ dp->state |= DPTX_STATE_SUSPENDED;
+ if (shutdown)
+ dp->state |= DPTX_STATE_SHUTDOWN;
+ }
+
+ dptx_cancel_hpd_works(dp);
+
+ scoped_guard(mutex, &dp->lock) {
+ if (shutdown)
+ dptx_stop_streams(dp);
+ if (!dp->active_stream_cnt)
+ dptx_host_deinit(dp);
+ dp->state &= ~DPTX_STATE_CONNECTED;
+ }
+
+ return 0;
+}
+
+static int dptx_pm_complete(struct dptx_dev *dp)
+{
+ bool replay = false;
+ int ret;
+
+ scoped_guard(mutex, &dp->lock) {
+ ret = dptx_host_resume(dp);
+ if (!ret)
+ replay = !dp->hpd_stopped && dp->attached;
+ }
+
+ if (ret)
+ return ret;
+
+ if (replay) {
+ dp->ops->replay_deferred_hotplug(dp);
+
+ scoped_guard(mutex, &dp->lock) {
+ if (!dptx_hpd_work_aborted(dp))
+ queue_delayed_work(system_freezable_wq,
+ &dp->hpd_event_work, 0);
+ }
+ }
+
+ return 0;
+}
+
+static int dptx_prepare(struct dptx_dev *dp)
+{
+ int ret;
+
+ guard(mutex)(&dp->lock);
+
+ if (dp->released ||
+ (dp->state & (DPTX_STATE_SUSPENDED | DPTX_STATE_SHUTDOWN)))
+ return -ENODEV;
+
+ if (dp->state & DPTX_STATE_ENABLED)
+ return 0;
+
+ if (!(dp->state & DPTX_STATE_INITIALIZED)) {
+ ret = dptx_host_init(dp);
+ if (ret)
+ return ret;
+ } else if (dp->state & DPTX_STATE_READY) {
+ /* core_on() finished, but the stream never became ENABLED. */
+ dptx_core_off(dp);
+ }
+
+ if (!dptx_get_hpd_state(dp)) {
+ if (!dp->oob_hpd ||
+ dp->force_hpd != connector_status_unknown ||
+ phy_get_mode(dp->phy) != PHY_MODE_DP ||
+ !dp->hw->ops->sink_present(dp->hw))
+ return -ENODEV;
+
+ dp->force_hpd = connector_status_connected;
+ }
+
+ return dptx_handle_connect(dp);
+}
+
+static int dptx_unprepare(struct dptx_dev *dp)
+{
+ if (dp->active_stream_cnt)
+ return 0;
+
+ if (!(dp->state & (DPTX_STATE_ENABLED | DPTX_STATE_READY)))
+ return 0;
+
+ dptx_core_off(dp);
+
+ /* dptx_pm_prepare() may have run before this suspend-time commit. */
+ if (dp->state & DPTX_STATE_SUSPENDED)
+ dptx_host_deinit(dp);
+
+ dp->state &= ~DPTX_STATE_ENABLED;
+
+ return 0;
+}
+
+static int dptx_encoder_enable(struct dptx_dev *dp, unsigned int stream_id,
+ int enable)
+{
+ int ret;
+
+ guard(mutex)(&dp->lock);
+
+ if (enable) {
+ if (!dptx_regs_accessible(dp) ||
+ !(dp->state & DPTX_STATE_CONNECTED))
+ return -ENODEV;
+
+ ret = dptx_core_on(dp);
+ if (ret)
+ return ret;
+
+ ret = dptx_enable(dp, stream_id);
+ if (ret)
+ dptx_unprepare(dp);
+ } else {
+ if (!(dp->state & DPTX_STATE_INITIALIZED))
+ return 0;
+
+ ret = dptx_disable(dp, stream_id);
+ if (ret)
+ return ret;
+
+ ret = dptx_unprepare(dp);
+ }
+
+ return ret;
+}
+
+static int dptx_init(struct dptx_dev *dp)
+{
+ int ret;
+
+ INIT_DELAYED_WORK(&dp->hpd_event_work, dptx_hpd_event_work_func);
+ INIT_DELAYED_WORK(&dp->hpd_irq_work, dptx_hpd_irq_work_func);
+
+ dp->state |= (DPTX_STATE_CONFIGURED);
+
+ ret = dptx_host_init(dp);
+ if (ret)
+ goto err_configured;
+
+ irq_set_status_flags(dp->irq, IRQ_DISABLE_UNLAZY);
+ ret = devm_request_threaded_irq(dp->dev, dp->irq, NULL,
+ dptx_irq_handler, IRQF_ONESHOT,
+ dev_name(dp->dev), dp);
+ if (ret < 0)
+ goto err_deinit;
+
+ return 0;
+
+err_deinit:
+ dptx_host_deinit(dp);
+err_configured:
+ dp->state &= ~DPTX_STATE_CONFIGURED;
+ return ret;
+}
+
+static void dptx_deinit(struct dptx_dev *dp)
+{
+ struct device *consumer = NULL;
+
+ scoped_guard(mutex, &dp->lock) {
+ if (!(dp->state & DPTX_STATE_CONFIGURED))
+ return;
+
+ WRITE_ONCE(dp->hpd_stopped, true);
+ dp->released = true;
+ dptx_irq_off(dp);
+ }
+
+ dptx_cancel_hpd_works(dp);
+
+ scoped_guard(mutex, &dp->lock) {
+ dptx_stop_streams(dp);
+ dptx_host_deinit(dp);
+ dp->hw->ops->aux_unregister(dp->hw);
+ dp->state &= ~(DPTX_STATE_CONFIGURED);
+ consumer = dp->link_consumer;
+ dp->link_consumer = NULL;
+ }
+
+ if (consumer)
+ device_link_remove(consumer, dp->dev);
+}
+
+static void dptx_dev_release(void *res)
+{
+ struct dptx_dev *dp = res;
+
+ dptx_deinit(dp);
+}
+
+static int dptx_get_irq(struct dptx_dev *dp)
+{
+ int ret;
+
+ ret = of_irq_get(dp->dev->of_node, 0);
+ if (ret <= 0)
+ return dev_err_probe(dp->dev, ret ?: -EINVAL,
+ "failed to get irq\n");
+
+ dp->irq = ret;
+
+ return 0;
+}
+
+static const struct dptx_ops dptx_impl_ops = {
+ .detect = dptx_detect,
+ .detect_status = dptx_detect_status,
+ .prepare = dptx_prepare,
+ .unprepare = dptx_unprepare,
+ .encoder_enable = dptx_encoder_enable,
+ .mode_configure = dptx_mode_configure,
+ .replay_deferred_hotplug = dptx_replay_deferred_hotplug,
+ .quiesce_hpd = dptx_quiesce_hpd,
+};
+
+struct dptx_dev *trilinear_dptx_probe(struct device *dev,
+ const struct dptx_plat_data *soc_data,
+ void *priv)
+{
+ struct device_node *remote __free(device_node) = NULL;
+ struct dptx_dev *dp;
+ struct dp_hw *hw;
+ int ret;
+
+ if (!soc_data || !soc_data->adapter_config || !soc_data->max_bw_code)
+ return ERR_PTR(-EINVAL);
+
+ dp = dptx_bridge_alloc(dev);
+ if (IS_ERR(dp))
+ return dp;
+
+ mutex_init(&dp->lock);
+
+ dp->dev = dev;
+
+ dp->phy = devm_phy_get(dev, NULL);
+ if (IS_ERR(dp->phy))
+ return ERR_PTR(dev_err_probe(dev, PTR_ERR(dp->phy),
+ "failed to get dp phy\n"));
+
+ hw = dptx_hw_init(dev, dp, dptx_queue_hpd_event, dptx_queue_hpd_irq);
+ if (IS_ERR(hw))
+ return ERR_CAST(hw);
+
+ dp->hw = hw;
+
+ dp->soc_data = soc_data;
+ dp->oob_hpd = soc_data->oob_hpd;
+ dp->soc_priv = priv;
+ dp->ops = &dptx_impl_ops;
+ dp->force_hpd = connector_status_unknown;
+ dp->state = DPTX_STATE_DISCONNECTED;
+ dp->pixel_per_cycle = 1;
+
+ ret = dptx_get_irq(dp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ dp->link_max_lanes = DPTX_MAX_LANES;
+ dp->link_max_rate =
+ drm_dp_bw_code_to_link_rate(soc_data->max_bw_code);
+
+ ret = dptx_init(dp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ dp->bridge.of_node = dev->of_node;
+ dp->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_MODES |
+ DRM_BRIDGE_OP_HPD;
+ dp->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
+ dp->bridge.ddc = &dp->hw->aux.ddc;
+ dp->bridge.ycbcr_420_allowed = true;
+
+ remote = of_graph_get_remote_node(dev->of_node, 1, 0);
+ if (remote) {
+ dp->next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node,
+ 1, 0);
+ if (IS_ERR(dp->next_bridge)) {
+ ret = PTR_ERR(dp->next_bridge);
+ dp->next_bridge = NULL;
+ dptx_deinit(dp);
+ return ERR_PTR(ret);
+ }
+ }
+
+ ret = devm_drm_bridge_add(dev, &dp->bridge);
+ if (ret) {
+ dptx_deinit(dp);
+ return ERR_PTR(ret);
+ }
+
+ ret = devm_add_action_or_reset(dev, dptx_dev_release, dp);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return dp;
+}
+EXPORT_SYMBOL_GPL(trilinear_dptx_probe);
+
+int trilinear_dptx_suspend(struct dptx_dev *dp)
+{
+ if (!dp)
+ return 0;
+
+ return dptx_pm_prepare(dp, false);
+}
+EXPORT_SYMBOL_GPL(trilinear_dptx_suspend);
+
+int trilinear_dptx_resume(struct dptx_dev *dp)
+{
+ if (!dp)
+ return 0;
+
+ return dptx_pm_complete(dp);
+}
+EXPORT_SYMBOL_GPL(trilinear_dptx_resume);
+
+void trilinear_dptx_remove(struct dptx_dev *dp)
+{
+ if (!dp)
+ return;
+
+ dptx_deinit(dp);
+}
+EXPORT_SYMBOL_GPL(trilinear_dptx_remove);
+
+void trilinear_dptx_shutdown(struct dptx_dev *dp)
+{
+ if (!dp)
+ return;
+
+ dptx_pm_prepare(dp, true);
+}
+EXPORT_SYMBOL_GPL(trilinear_dptx_shutdown);
+
+MODULE_AUTHOR("Luo Liu <Luo.Liu@cixtech.com>");
+MODULE_AUTHOR("Wuyi Shen <wuyi.shen@cixtech.com>");
+MODULE_DESCRIPTION("DisplayPort transmitter bridge driver");
+MODULE_LICENSE("GPL");
diff --git a/include/drm/bridge/trilinear_dp.h b/include/drm/bridge/trilinear_dp.h
index c65ebd103f47..06e5458f04ae 100644
--- a/include/drm/bridge/trilinear_dp.h
+++ b/include/drm/bridge/trilinear_dp.h
@@ -65,6 +65,16 @@ int trilinear_dptx_suspend(struct dptx_dev *dp);
*/
int trilinear_dptx_resume(struct dptx_dev *dp);
+/**
+ * trilinear_dptx_remove - tear down a DPTX bridge on driver removal
+ * @dp: DPTX device returned by trilinear_dptx_probe()
+ *
+ * Called from the platform remove callback, before the device is deleted.
+ * The device link to the display controller is dropped here, since device
+ * links are purged on removal and cannot be released afterwards.
+ */
+void trilinear_dptx_remove(struct dptx_dev *dp);
+
/**
* trilinear_dptx_shutdown - stop a DPTX bridge on system shutdown
* @dp: DPTX device returned by trilinear_dptx_probe()
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
` (3 preceding siblings ...)
2026-12-04 11:43 ` [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
@ 2026-12-04 11:43 ` Luo Liu
2026-12-04 12:01 ` sashiko-bot
4 siblings, 1 reply; 11+ messages in thread
From: Luo Liu @ 2026-12-04 11:43 UTC (permalink / raw)
To: maarten.lankhorst, mripard, tzimmermann, andrzej.hajda,
neil.armstrong, rfoss, robh, krzk+dt, conor+dt
Cc: dri-devel, devicetree, laurent.pinchart, jonas, jernej.skrabec,
luca.ceresoli, wuyi.shen, cix-kernel-upstream
Add the platform driver that maps the Sky1 RCSU video adapter registers
and programs the pixel format and pixel-per-clock mode for the
Trilinear DisplayPort transmitter.
The DP protocol, link training and the DRM bridge live in the shared
Trilinear bridge driver. This glue only fills in the SoC-specific parts
through dptx_plat_data, declared in include/drm/bridge/trilinear_dp.h.
The remove callback tears the transmitter down before the device is
deleted.
Signed-off-by: Luo Liu <Luo.Liu@cixtech.com>
---
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 | 15 +++
drivers/gpu/drm/cix/dptx/Makefile | 4 +
drivers/gpu/drm/cix/dptx/cix_dptx.c | 181 ++++++++++++++++++++++++++++
8 files changed, 209 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
diff --git a/MAINTAINERS b/MAINTAINERS
index 6ebb17dd18e9..b63870a11a5b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6530,6 +6530,7 @@ L: dri-devel@lists.freedesktop.org
S: Maintained
F: Documentation/devicetree/bindings/display/cix,sky1-dp.yaml
F: drivers/gpu/drm/bridge/trilinear/
+F: drivers/gpu/drm/cix/
F: include/drm/bridge/trilinear_dp.h
CLANG CONTEXT ANALYSIS
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 61111d50b1c6..a1808db8b9c8 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -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"
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 2c6bc093a923..6ed7456bb993 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -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/
diff --git a/drivers/gpu/drm/cix/Kconfig b/drivers/gpu/drm/cix/Kconfig
new file mode 100644
index 000000000000..6cbaa5bf9fe9
--- /dev/null
+++ b/drivers/gpu/drm/cix/Kconfig
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+source "drivers/gpu/drm/cix/dptx/Kconfig"
diff --git a/drivers/gpu/drm/cix/Makefile b/drivers/gpu/drm/cix/Makefile
new file mode 100644
index 000000000000..2cc5cba67848
--- /dev/null
+++ b/drivers/gpu/drm/cix/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_DRM_CIX_DP) += dptx/
diff --git a/drivers/gpu/drm/cix/dptx/Kconfig b/drivers/gpu/drm/cix/dptx/Kconfig
new file mode 100644
index 000000000000..f5d3afe5699f
--- /dev/null
+++ b/drivers/gpu/drm/cix/dptx/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DRM_CIX_DP
+ tristate "Cix Sky1 DisplayPort platform glue"
+ depends on ARCH_CIX || COMPILE_TEST
+ depends on COMMON_CLK && DRM && OF
+ depends on GENERIC_PHY
+ select DRM_TRILINEAR_DPTX
+ help
+ Platform glue for the Cix Sky1 DisplayPort output. It maps the
+ SoC video adapter registers and binds the shared Trilinear DPTX
+ bridge driver.
+
+ To compile this driver as a module, choose M here: the module will
+ be called cix-dptx.
diff --git a/drivers/gpu/drm/cix/dptx/Makefile b/drivers/gpu/drm/cix/dptx/Makefile
new file mode 100644
index 000000000000..64226bbd7c49
--- /dev/null
+++ b/drivers/gpu/drm/cix/dptx/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+cix-dptx-y := cix_dptx.o
+obj-$(CONFIG_DRM_CIX_DP) += cix-dptx.o
diff --git a/drivers/gpu/drm/cix/dptx/cix_dptx.c b/drivers/gpu/drm/cix/dptx/cix_dptx.c
new file mode 100644
index 000000000000..e25b3b365d7b
--- /dev/null
+++ b/drivers/gpu/drm/cix/dptx/cix_dptx.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * CIX Sky1 DisplayPort platform glue
+ *
+ * Copyright 2026 Cix Technology Group Co., Ltd.
+ */
+
+#include <linux/bits.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+
+#include <drm/bridge/trilinear_dp.h>
+
+#define CFG_ADAPTER_VIDEO0_OFFSET 0x300
+#define CFG_ADAPTER_VIDEO1_OFFSET 0x304
+#define CFG_ADAPTER_VIDEO_OFFSET_DP2 0x320
+
+struct cix_dp_adapter_fmt {
+ int offset;
+ u32 shift;
+};
+
+struct cix_dptx {
+ void __iomem *rcsu;
+};
+
+static const struct cix_dp_adapter_fmt usbc_adapter_fmt[] = {
+ { CFG_ADAPTER_VIDEO0_OFFSET, 30 },
+ { CFG_ADAPTER_VIDEO1_OFFSET, 19 },
+};
+
+static const struct cix_dp_adapter_fmt dp2_adapter_fmt[] = {
+ { CFG_ADAPTER_VIDEO_OFFSET_DP2, 17 },
+ { CFG_ADAPTER_VIDEO_OFFSET_DP2, 20 },
+};
+
+static void cix_dp_adapter_fmt_set(void __iomem *rcsu,
+ const struct cix_dp_adapter_fmt *adapter,
+ enum dp_pixelformat format, bool ppc2)
+{
+ u32 fmt_mask;
+ u32 ppc_bit;
+ u32 value;
+
+ /* The PPC control bit sits directly below the pixel format field. */
+ fmt_mask = GENMASK(adapter->shift + 1, adapter->shift);
+ ppc_bit = BIT(adapter->shift - 1);
+
+ value = readl(rcsu + adapter->offset);
+
+ value &= ~fmt_mask;
+ if (format == DP_PIXELFORMAT_YUV422)
+ value |= 2U << adapter->shift;
+ else if (format == DP_PIXELFORMAT_YUV420)
+ value |= 3U << adapter->shift;
+
+ if (ppc2)
+ value |= ppc_bit;
+ else
+ value &= ~ppc_bit;
+
+ writel(value, rcsu + adapter->offset);
+}
+
+static void cix_dp_usbc_adapter_config(void *data, unsigned int pipe_id,
+ enum dp_pixelformat format, bool ppc2)
+{
+ struct cix_dptx *priv = data;
+
+ if (pipe_id >= ARRAY_SIZE(usbc_adapter_fmt))
+ return;
+
+ cix_dp_adapter_fmt_set(priv->rcsu, &usbc_adapter_fmt[pipe_id], format,
+ ppc2);
+}
+
+static void cix_dp_native_adapter_config(void *data, unsigned int pipe_id,
+ enum dp_pixelformat format, bool ppc2)
+{
+ struct cix_dptx *priv = data;
+
+ if (pipe_id >= ARRAY_SIZE(dp2_adapter_fmt))
+ return;
+
+ cix_dp_adapter_fmt_set(priv->rcsu, &dp2_adapter_fmt[pipe_id], format,
+ ppc2);
+}
+
+static int cix_dptx_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ const struct dptx_plat_data *soc_data;
+ struct cix_dptx *priv;
+ struct dptx_dev *dp;
+ void __iomem *rcsu;
+
+ soc_data = of_device_get_match_data(dev);
+ if (!soc_data)
+ return -ENODEV;
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ rcsu = devm_platform_ioremap_resource_byname(pdev, "rcsu");
+ if (IS_ERR(rcsu))
+ return dev_err_probe(dev, PTR_ERR(rcsu),
+ "failed to map rcsu registers\n");
+
+ priv->rcsu = rcsu;
+
+ dp = trilinear_dptx_probe(dev, soc_data, priv);
+ if (IS_ERR(dp))
+ return PTR_ERR(dp);
+
+ platform_set_drvdata(pdev, dp);
+
+ return 0;
+}
+
+static void cix_dptx_remove(struct platform_device *pdev)
+{
+ trilinear_dptx_remove(platform_get_drvdata(pdev));
+}
+
+static int cix_dptx_pm_suspend(struct device *dev)
+{
+ return trilinear_dptx_suspend(dev_get_drvdata(dev));
+}
+
+static int cix_dptx_pm_resume(struct device *dev)
+{
+ return trilinear_dptx_resume(dev_get_drvdata(dev));
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(cix_dptx_pm_ops, cix_dptx_pm_suspend,
+ cix_dptx_pm_resume);
+
+static void cix_dptx_shutdown(struct platform_device *pdev)
+{
+ trilinear_dptx_shutdown(platform_get_drvdata(pdev));
+}
+
+static const struct dptx_plat_data sky1_usbdp_data = {
+ .adapter_config = cix_dp_usbc_adapter_config,
+ .oob_hpd = true,
+ .max_bw_code = DP_LINK_BW_5_4,
+};
+
+static const struct dptx_plat_data sky1_dp_data = {
+ .adapter_config = cix_dp_native_adapter_config,
+ .max_bw_code = DP_LINK_BW_5_4,
+};
+
+static const struct of_device_id cix_dptx_dt_ids[] = {
+ { .compatible = "cix,sky1-usbdp", .data = &sky1_usbdp_data },
+ { .compatible = "cix,sky1-dp", .data = &sky1_dp_data },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, cix_dptx_dt_ids);
+
+static struct platform_driver cix_dp_driver = {
+ .probe = cix_dptx_probe,
+ .remove = cix_dptx_remove,
+ .shutdown = cix_dptx_shutdown,
+ .driver = {
+ .name = "cix-dptx",
+ .of_match_table = cix_dptx_dt_ids,
+ .pm = pm_sleep_ptr(&cix_dptx_pm_ops),
+ },
+};
+
+module_platform_driver(cix_dp_driver);
+
+MODULE_AUTHOR("Luo Liu <Luo.Liu@cixtech.com>");
+MODULE_AUTHOR("Wuyi Shen <wuyi.shen@cixtech.com>");
+MODULE_DESCRIPTION("Cix Sky1 DisplayPort platform glue");
+MODULE_LICENSE("GPL");
--
2.25.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue
2026-12-04 11:43 ` [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu
@ 2026-12-04 12:01 ` sashiko-bot
2026-12-04 12:11 ` 回复: " Luo Liu
0 siblings, 1 reply; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 12:01 UTC (permalink / raw)
To: Luo Liu; +Cc: dri-devel, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/bridge: trilinear: unlocked device_link_remove() UAF on
dp->dev
- [Medium] drm/bridge: trilinear: missing dp->released check in
dptx_bridge_mode_set()
- [Low] drm/cix: bridge glue placed in top-level drm/cix/ instead of
drm/bridge/
--
commit 1e4145188b36c3532088673583ce49d4b100b5b9
Author: Luo Liu <Luo.Liu@cixtech.com>
drm/cix: add the Sky1 DisplayPort platform glue
This commit adds the Cix Sky1 platform glue driver that maps the RCSU video
adapter registers and binds the shared Trilinear DisplayPort bridge driver.
[ ... ]
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 61111d50b1c65..a1808db8b9c8a 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -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"
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 2c6bc093a923a..6ed7456bb993a 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -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/
[Severity: Low]
Should this bridge platform glue live under drivers/gpu/drm/bridge/ (or
drivers/gpu/drm/bridge/trilinear/) rather than a new top-level
drivers/gpu/drm/cix/ directory?
drivers/gpu/drm/cix/ contains no drm_driver, only a single 181-line wrapper
for the Trilinear bridge driver. Putting it at the top level exposes
DRM_CIX_DP outside the Display Interface Bridges menu and adds four extra
Kconfig/Makefile files, whereas comparable SoC bridge wrappers such as
drivers/gpu/drm/bridge/th1520-dw-hdmi.c and
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-j721e.c sit under
drivers/gpu/drm/bridge/.
[ ... ]
> diff --git a/drivers/gpu/drm/cix/dptx/cix_dptx.c b/drivers/gpu/drm/cix/dptx/cix_dptx.c
> new file mode 100644
> index 0000000000000..e25b3b365d7b8
> --- /dev/null
> +++ b/drivers/gpu/drm/cix/dptx/cix_dptx.c
[ ... ]
> +static void cix_dptx_remove(struct platform_device *pdev)
> +{
> + trilinear_dptx_remove(platform_get_drvdata(pdev));
> +}
[Severity: Medium]
Can cix_dptx_remove() allow dp->dev to be freed while dptx_bridge_detach()
is still about to pass it to device_link_remove()?
CPU0 (bridge detach) CPU1 (platform device delete)
dptx_bridge_detach()
lock(&dp->lock)
consumer = dp->link_consumer
dp->link_consumer = NULL
unlock(&dp->lock)
device_unregister(dp->dev)
device_del(dp->dev)
cix_dptx_remove()
dptx_deinit()
lock(&dp->lock)
/* link_consumer == NULL */
unlock(&dp->lock)
device_links_purge(dp->dev)
put_device(dp->dev) /* freed */
device_link_remove(consumer,
dp->dev) <-- use-after-free
trilinear_dptx_probe() stores dp->dev without taking a device reference, and
dptx_bridge_attach() adds a DL_FLAG_STATELESS link, so removing the supplier
device does not unbind the consumer first. Because dptx_bridge_detach()
clears dp->link_consumer and drops dp->lock before calling
device_link_remove(), dptx_deinit() returns immediately and device_del()
purges the link and frees dp->dev before device_link_remove() walks
supplier->links.consumers.
Calling device_link_remove() while still holding dp->lock in
dptx_bridge_detach() (matching the dp->lock -> device_links_write_lock
ordering already used in dptx_bridge_attach()) would serialize link removal
with dptx_deinit().
[Severity: Medium]
Can dptx_bridge_mode_set() dereference a freed dp->dev if cix_dptx_remove()
runs between dp->ops->detect() and reacquiring dp->lock?
CPU0 (modeset) CPU1 (platform device delete)
dptx_bridge_mode_set()
dp->ops->detect(dp)
/* locks, checks released,
unlocks */
device_unregister(dp->dev)
cix_dptx_remove()
dptx_deinit()
dp->released = true
device_link_remove(...)
put_device(dp->dev) /* freed */
guard(mutex)(&dp->lock)
/* no dp->released check */
dev_dbg(dp->dev, ...) <-- use-after-free
dptx_bridge_mode_set() releases dp->lock when dp->ops->detect() returns and
does not re-check dp->released after reacquiring it. Because dp->bridge
keeps dp alive after dp->dev is freed, dptx_bridge_mode_set() mutates state
on a released bridge and dereferences freed dp->dev in dev_dbg() when
dynamic debug is enabled.
Checking dp->released and returning -ENODEV immediately after acquiring
dp->lock in dptx_bridge_mode_set() would close this window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@cixtech.com?part=5
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer
2026-12-04 11:43 ` [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
@ 2026-12-04 12:06 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 12:06 UTC (permalink / raw)
To: Luo Liu; +Cc: dri-devel, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/bridge: trilinear: dptx_hw_link_vs_emph() returns positive
byte count
- [Medium] drm/bridge: dptx_hw_link_adjust_train() clamps pre-emphasis
instead of swing
- [Medium] drm/bridge: trilinear: missing CR limits in
dptx_hw_link_clock_recovery()
- [Low] drm/bridge: trilinear: duplicate DPCD power helpers in dptx_hw.c
- [Low] drm/bridge: trilinear: unnecessary single-implementation
dptx_hw_ops vtable
--
commit f4828b3f444687387aa09825f7746b0c5c9153bf
Author: Luo Liu <Luo.Liu@cixtech.com>
drm/bridge: trilinear: add the DPTX hardware layer
This commit adds the register, AUX channel, DPCD capability, link training,
and main stream programming layer for the Trilinear DisplayPort transmitter.
> diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_hw.c b/drivers/gpu/drm/bridge/trilinear/dptx_hw.c
> new file mode 100644
> index 0000000000000..bdf24e464b942
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_hw.c
[ ... ]
> +static int dptx_hw_link_vs_emph(struct dp_hw *hw, struct phy *phy,
> + u8 lane_cnt)
> +{
> + int ret;
> +
> + ret = dptx_hw_phy_vs_emph_set(hw, phy, lane_cnt, hw->train_setting);
> + if (ret)
> + return ret;
> +
> + return drm_dp_dpcd_write(&hw->aux, DP_TRAINING_LANE0_SET,
> + hw->train_setting, lane_cnt);
> +}
[Severity: High]
Does dptx_hw_link_vs_emph() return a positive byte count on success?
drm_dp_dpcd_write() returns the number of bytes written (lane_cnt) rather
than 0. Both dptx_hw_link_clock_recovery() and
dptx_hw_link_channel_equalization() treat any non-zero return as an error,
so link training aborts on the first clock-recovery iteration, skips
channel equalization, and fails modeset enable.
Using drm_dp_dpcd_write_data() here returns 0 on a full write and a
negative error code on failure or a short write.
> +
> +static void dptx_hw_link_adjust_train(struct dp_hw *hw, u8 lane_cnt,
> + const u8 *link_status)
> +{
> + u8 voltage;
> + u8 preemphasis;
> + u8 pre_level;
> + int i;
> +
> + for (i = 0; i < lane_cnt; i++) {
> + voltage = drm_dp_get_adjust_request_voltage(link_status, i);
> + preemphasis =
> + drm_dp_get_adjust_request_pre_emphasis(link_status, i);
> + pre_level = preemphasis >> DP_TRAIN_PRE_EMPHASIS_SHIFT;
> +
> + if (voltage + pre_level > 3) {
> + pre_level = 3 - voltage;
> + preemphasis = pre_level << DP_TRAIN_PRE_EMPHASIS_SHIFT;
> + }
[Severity: Medium]
Should this clamp voltage swing instead of pre-emphasis when
voltage + pre_level > 3?
Per the DisplayPort specification, when a requested combination exceeds 3,
the transmitter keeps the requested pre-emphasis and clamps voltage to
3 - pre_level. Clamping pre-emphasis instead drops requested pre-emphasis
during link training and fails DisplayPort compliance tests.
[ ... ]
> +static int dptx_hw_link_clock_recovery(struct dp_hw *hw, struct phy *phy,
> + u8 lane_cnt)
> +{
[ ... ]
> + for (i = 0; i < 512; i++) {
> + ret = dptx_hw_link_vs_emph(hw, phy, lane_cnt);
> + if (ret)
> + return ret;
> +
> + drm_dp_link_train_clock_recovery_delay(&hw->aux, hw->dpcd);
> + ret = drm_dp_dpcd_read_link_status(&hw->aux, link_status);
> + if (ret < 0)
> + return ret;
> +
> + train_done = drm_dp_clock_recovery_ok(link_status, lane_cnt);
> + if (train_done)
> + break;
> +
> + memcpy(prev, hw->train_setting, lane_cnt);
> + dptx_hw_link_adjust_train(hw, lane_cnt, link_status);
> +
> + if (!memcmp(hw->train_setting, prev, lane_cnt))
> + tries++;
> + else
> + tries = 0;
> +
> + if (tries == DP_MAX_TRAINING_TRIES)
> + break;
> + }
[Severity: Medium]
Can this 512-iteration clock-recovery loop stall link training for seconds
on a marginal or oscillating sink?
The loop never stops when DP_TRAIN_MAX_SWING_REACHED is set and does not
enforce the DP 1.4 10-iteration limit (or a bounded cap such as 80
iterations for pre-DP 1.4 sinks).
On an oscillating pre-DP 1.4 sink with DP_TRAINING_AUX_RD_INTERVAL == 4,
drm_dp_link_train_clock_recovery_delay() sleeps 16 to 32 ms per iteration,
turning 512 iterations into an 8 to 16 second stall per training attempt.
[ ... ]
> +static int dptx_hw_dpcd_power_up(struct dp_hw *hw,
> + unsigned int delay_ms)
> +{
> + u8 value;
> + int ret;
> +
> + if (hw->dpcd[DP_DPCD_REV] < DP_DPCD_REV_11)
> + return 0;
> +
> + ret = drm_dp_dpcd_readb(&hw->aux, DP_SET_POWER, &value);
> + if (ret < 0)
> + return ret;
> +
> + value = (value & ~DP_SET_POWER_MASK) | DP_SET_POWER_D0;
> +
> + ret = drm_dp_dpcd_writeb(&hw->aux, DP_SET_POWER, value);
> + if (ret < 0)
> + return ret;
> +
> + msleep(delay_ms);
> +
> + return 0;
> +}
> +
> +static int dptx_hw_dpcd_power_down(struct dp_hw *hw, bool hpd)
> +{
> + u8 value;
> + int ret;
> +
> + if (!hpd)
> + return 0;
> +
> + if (hw->dpcd[DP_DPCD_REV] < DP_DPCD_REV_11)
> + return 0;
> +
> + ret = drm_dp_dpcd_readb(&hw->aux, DP_SET_POWER, &value);
> + if (ret < 0)
> + return ret;
> +
> + value = (value & ~DP_SET_POWER_MASK) | DP_SET_POWER_D3;
> +
> + ret = drm_dp_dpcd_writeb(&hw->aux, DP_SET_POWER, value);
> + if (ret < 0)
> + return ret;
> +
> + usleep_range(200, 205);
> +
> + return 0;
> +}
[Severity: Low]
Can dptx_hw_dpcd_power_up() and dptx_hw_dpcd_power_down() reuse
drm_dp_link_power_up() and drm_dp_link_power_down()?
Those core helpers already check DP_DPCD_REV_11 and perform the
DP_SET_POWER read-modify-write, avoiding duplicate DPCD power-state code.
[ ... ]
> diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_hw.h b/drivers/gpu/drm/bridge/trilinear/dptx_hw.h
> new file mode 100644
> index 0000000000000..420ef242a4f61
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_hw.h
[ ... ]
> +struct dptx_hw_ops {
> + bool (*hpd_state)(struct dp_hw *hw);
> + bool (*sink_present)(struct dp_hw *hw);
> +
> + void (*host_enable)(struct dp_hw *hw, bool enable);
> + void (*reset)(struct dp_hw *hw, bool assert);
> + void (*core_enable)(struct dp_hw *hw, int source_id, bool enable);
[Severity: Low]
Is the 20-method struct dptx_hw_ops vtable needed?
There is only one implementation (dptx_hw_ops in dptx_hw.c), assigned
unconditionally in dptx_hw_init(). Declaring direct dptx_hw_*() functions
in dptx_hw.h would avoid the boilerplate and indirect calls.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@cixtech.com?part=2
^ permalink raw reply [flat|nested] 11+ messages in thread
* 回复: [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue
2026-12-04 12:01 ` sashiko-bot
@ 2026-12-04 12:11 ` Luo Liu
0 siblings, 0 replies; 11+ messages in thread
From: Luo Liu @ 2026-12-04 12:11 UTC (permalink / raw)
To: sashiko-reviews@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
> -----邮件原件-----
> 发件人: sashiko-bot@kernel.org <sashiko-bot@kernel.org>
> 发送时间: 2026年12月4日 20:02
> 收件人: Luo Liu <Luo.Liu@cixtech.com>
> 抄送: dri-devel@lists.freedesktop.org; devicetree@vger.kernel.org;
> robh@kernel.org; conor+dt@kernel.org
> 主题: Re: [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue
>
> EXTERNAL EMAIL
>
> Thank you for your contribution! Sashiko AI review found 3 potential issues to
> consider:
> - [Medium] drm/bridge: trilinear: unlocked device_link_remove() UAF on
> dp->dev
> - [Medium] drm/bridge: trilinear: missing dp->released check in
> dptx_bridge_mode_set()
> - [Low] drm/cix: bridge glue placed in top-level drm/cix/ instead of
> drm/bridge/
> --
>
> commit 1e4145188b36c3532088673583ce49d4b100b5b9
> Author: Luo Liu <Luo.Liu@cixtech.com>
>
> drm/cix: add the Sky1 DisplayPort platform glue
>
> This commit adds the Cix Sky1 platform glue driver that maps the RCSU video
> adapter registers and binds the shared Trilinear DisplayPort bridge driver.
>
> [ ... ]
>
> > diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index
> > 61111d50b1c65..a1808db8b9c8a 100644
> > --- a/drivers/gpu/drm/Kconfig
> > +++ b/drivers/gpu/drm/Kconfig
> > @@ -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"
> > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index
> > 2c6bc093a923a..6ed7456bb993a 100644
> > --- a/drivers/gpu/drm/Makefile
> > +++ b/drivers/gpu/drm/Makefile
> > @@ -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/
>
> [Severity: Low]
> Should this bridge platform glue live under drivers/gpu/drm/bridge/ (or
> drivers/gpu/drm/bridge/trilinear/) rather than a new top-level
> drivers/gpu/drm/cix/ directory?
>
> drivers/gpu/drm/cix/ contains no drm_driver, only a single 181-line wrapper for
> the Trilinear bridge driver. Putting it at the top level exposes DRM_CIX_DP
> outside the Display Interface Bridges menu and adds four extra Kconfig/Makefile
> files, whereas comparable SoC bridge wrappers such as
> drivers/gpu/drm/bridge/th1520-dw-hdmi.c and
> drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-j721e.c sit under
> drivers/gpu/drm/bridge/.
The CIX directory is intentional. It is not a wrapper around the
Trilinear bridge: it implements the CIX-specific side, namely the RCSU
video-adapter format and pixel-per-cycle programming, and it supplies
the per-compatible platform data (USB-C versus native DP, out-of-band
HPD, link limits) that the shared code in drivers/gpu/drm/bridge/
trilinear/ must not know about.
That code will keep growing as more CIX SoCs and output variants (eDP,
HDMI through a converter) are supported, each with its own register
layout and quirks. Keeping it in a private vendor directory keeps the
Trilinear code SoC-agnostic and gives the CIX code a stable home instead
of moving it later. If the Kconfig menu placement is the concern rather
than the directory, I can source the CIX Kconfig from the bridge menu.
>
> [ ... ]
>
> > diff --git a/drivers/gpu/drm/cix/dptx/cix_dptx.c
> > b/drivers/gpu/drm/cix/dptx/cix_dptx.c
> > new file mode 100644
> > index 0000000000000..e25b3b365d7b8
> > --- /dev/null
> > +++ b/drivers/gpu/drm/cix/dptx/cix_dptx.c
>
> [ ... ]
>
> > +static void cix_dptx_remove(struct platform_device *pdev) {
> > + trilinear_dptx_remove(platform_get_drvdata(pdev));
> > +}
>
> [Severity: Medium]
> Can cix_dptx_remove() allow dp->dev to be freed while dptx_bridge_detach() is
> still about to pass it to device_link_remove()?
>
> CPU0 (bridge detach) CPU1 (platform device delete)
> dptx_bridge_detach()
> lock(&dp->lock)
> consumer = dp->link_consumer
> dp->link_consumer = NULL
> unlock(&dp->lock)
> device_unregister(dp->dev)
> device_del(dp->dev)
> cix_dptx_remove()
> dptx_deinit()
> lock(&dp->lock)
> /* link_consumer == NULL
> */
> unlock(&dp->lock)
> device_links_purge(dp->dev)
> put_device(dp->dev) /* freed */
> device_link_remove(consumer,
> dp->dev) <-- use-after-free
>
> trilinear_dptx_probe() stores dp->dev without taking a device reference, and
> dptx_bridge_attach() adds a DL_FLAG_STATELESS link, so removing the supplier
> device does not unbind the consumer first. Because dptx_bridge_detach()
> clears dp->link_consumer and drops dp->lock before calling
> device_link_remove(), dptx_deinit() returns immediately and device_del()
> purges the link and frees dp->dev before device_link_remove() walks
> supplier->links.consumers.
>
> Calling device_link_remove() while still holding dp->lock in
> dptx_bridge_detach() (matching the dp->lock -> device_links_write_lock
> ordering already used in dptx_bridge_attach()) would serialize link removal with
> dptx_deinit().
>
> [Severity: Medium]
> Can dptx_bridge_mode_set() dereference a freed dp->dev if cix_dptx_remove()
> runs between dp->ops->detect() and reacquiring dp->lock?
>
> CPU0 (modeset) CPU1 (platform device delete)
> dptx_bridge_mode_set()
> dp->ops->detect(dp)
> /* locks, checks released,
> unlocks */
> device_unregister(dp->dev)
> cix_dptx_remove()
> dptx_deinit()
> dp->released = true
> device_link_remove(...)
> put_device(dp->dev) /* freed */
> guard(mutex)(&dp->lock)
> /* no dp->released check */
> dev_dbg(dp->dev, ...) <-- use-after-free
>
> dptx_bridge_mode_set() releases dp->lock when dp->ops->detect() returns and
> does not re-check dp->released after reacquiring it. Because dp->bridge keeps
> dp alive after dp->dev is freed, dptx_bridge_mode_set() mutates state on a
> released bridge and dereferences freed dp->dev in dev_dbg() when dynamic
> debug is enabled.
>
> Checking dp->released and returning -ENODEV immediately after acquiring
> dp->lock in dptx_bridge_mode_set() would close this window.
>
> --
> Sashiko AI
> review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@c
> ixtech.com?part=5
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue
2026-12-04 11:43 ` [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
@ 2026-12-04 12:15 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 12:15 UTC (permalink / raw)
To: Luo Liu; +Cc: dri-devel, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] drm/bridge: trilinear: dptx_hw_link_vs_emph() returns byte
count as error
- [Medium] drm/bridge: trilinear: UAF on dp->dev calling
device_link_remove() unlocked
- [Medium] drm/bridge: trilinear: dptx_deinit() lets detach skip
aux_unregister()
- [Medium] drm/bridge: trilinear: UAF of dp->dev in
dptx_bridge_mode_set()
- [Medium] drm/bridge: trilinear: port@1 chaining breaks OOB HPD replay
and notify
- [Low] drm/bridge: trilinear: dptx_init() leaks IRQ_DISABLE_UNLAZY on
error
- [Low] drm/bridge: trilinear: redundant OF lookup and __free() style in
probe
--
commit 73b96bebc6d815be1eb22b178ab9b6dfb9d2585a
Author: Luo Liu <Luo.Liu@cixtech.com>
drm/bridge: trilinear: add the DPTX core and build glue
This commit adds the Trilinear DisplayPort transmitter core driver
(probe, PM callbacks, hotplug workers, and stream/link state machine),
exports trilinear_dptx_remove(), and hooks the driver into the DRM bridge
Kconfig and Makefile.
> diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_core.c b/drivers/gpu/drm/bridge/trilinear/dptx_core.c
> new file mode 100644
> index 0000000000000..5ca90acfb981f
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_core.c
[ ... ]
> +static int dptx_train_loop(struct dptx_dev *dp)
> +{
[ ... ]
> + ret = dp->hw->ops->link_train(dp->hw, dp->phy,
> + mode->bw_code,
> + mode->lane_cnt);
> + if (!ret) {
> + if (dp->active_stream_cnt &&
> + (mode->bw_code != prev_bw ||
> + mode->lane_cnt != prev_lanes))
> + dptx_active_streams(dp);
> + return 0;
> + }
> +
> + if (ret != -EIO)
> + goto err_restore;
[Severity: High]
Will link training always fail here when the first DPCD write succeeds?
In drivers/gpu/drm/bridge/trilinear/dptx_hw.c, dptx_hw_link_vs_emph()
returns the result of drm_dp_dpcd_write() directly, which is the positive
byte count (lane_cnt) on success rather than 0:
drivers/gpu/drm/bridge/trilinear/dptx_hw.c:dptx_hw_link_vs_emph() {
...
return drm_dp_dpcd_write(&hw->aux, DP_TRAINING_LANE0_SET,
hw->train_setting, lane_cnt);
}
Both dptx_hw_link_clock_recovery() and dptx_hw_link_channel_equalization()
treat any non-zero return as an error (if (ret) return ret;), so positive
lane_cnt propagates back to dptx_train_loop(), hits the ret != -EIO branch,
and causes dptx_core_on() to power down the link on every enable.
Using drm_dp_dpcd_write_data() in dptx_hw_link_vs_emph() (or normalizing a
non-negative return to 0) would fix this.
[ ... ]
> +static int dptx_init(struct dptx_dev *dp)
> +{
[ ... ]
> + irq_set_status_flags(dp->irq, IRQ_DISABLE_UNLAZY);
> + ret = devm_request_threaded_irq(dp->dev, dp->irq, NULL,
> + dptx_irq_handler, IRQF_ONESHOT,
> + dev_name(dp->dev), dp);
> + if (ret < 0)
> + goto err_deinit;
> +
> + return 0;
> +
> +err_deinit:
> + dptx_host_deinit(dp);
> +err_configured:
> + dp->state &= ~DPTX_STATE_CONFIGURED;
> + return ret;
> +}
[Severity: Low]
Does the err_deinit path leave IRQ_DISABLE_UNLAZY set on dp->irq if
devm_request_threaded_irq() fails?
__free_irq() only clears IRQ_DISABLE_UNLAZY when freeing a registered
action, so a failed request leaks the flag on the IRQ descriptor. Setting
IRQ_DISABLE_UNLAZY after devm_request_threaded_irq() succeeds (or clearing
it on err_deinit) avoids that.
> +
> +static void dptx_deinit(struct dptx_dev *dp)
> +{
> + struct device *consumer = NULL;
> +
> + scoped_guard(mutex, &dp->lock) {
> + if (!(dp->state & DPTX_STATE_CONFIGURED))
> + return;
> +
> + WRITE_ONCE(dp->hpd_stopped, true);
> + dp->released = true;
> + dptx_irq_off(dp);
> + }
[Severity: Medium]
Can dptx_bridge_mode_set() hit a use-after-free on dp->dev if platform
removal runs between dp->ops->detect() and acquiring dp->lock?
Because dp->dev is not refcounted and the DL_FLAG_STATELESS device link
does not unbind the display controller when the DPTX device is removed,
trilinear_dptx_remove() can run concurrently with a modeset:
CPU0 CPU1
dptx_bridge_mode_set()
dp->ops->detect(dp)
mutex_lock(&dp->lock)
...
mutex_unlock(&dp->lock)
trilinear_dptx_remove()
dptx_deinit()
dp->released = true
device_del(dp->dev)
put_device(dp->dev) (freed)
mutex_lock(&dp->lock)
...
dev_dbg(dp->dev, ...) <-- use-after-free
dptx_bridge_mode_set() in dptx_drm.c does not recheck dp->released after
acquiring dp->lock before calling dev_dbg(dp->dev, ...). Rechecking
dp->released under dp->lock (or logging with drm_dbg_kms(dp->bridge.dev,
...)) avoids dereferencing a freed dp->dev.
> +
> + dptx_cancel_hpd_works(dp);
> +
> + scoped_guard(mutex, &dp->lock) {
> + dptx_stop_streams(dp);
> + dptx_host_deinit(dp);
> + dp->hw->ops->aux_unregister(dp->hw);
[Severity: Medium]
Can setting dp->released before dptx_cancel_hpd_works() cause
dptx_bridge_detach() to skip aux_unregister() and leave aux->drm_dev
dangling?
In dptx_drm.c, dptx_bridge_detach() only calls aux_unregister() when
!dp->released:
CPU0 CPU1
dptx_deinit()
mutex_lock(&dp->lock)
dp->released = true
mutex_unlock(&dp->lock)
dptx_cancel_hpd_works()
dptx_bridge_detach()
mutex_lock(&dp->lock)
/* dp->released is true: skips
aux_unregister() */
mutex_unlock(&dp->lock)
drm_dev_release(bridge->dev) (freed)
mutex_lock(&dp->lock)
dptx_host_deinit()
dptx_hw_dpcd_power_down()
drm_dp_dpcd_readb(&hw->aux) <-- use-after-free
aux_unregister(dp->hw)
While /dev/drm_dp_auxN and the I2C adapter stay registered, both
dptx_hw_dpcd_power_down() (via drm_dp_dump_access() -> drm_dbg_dp()) and
concurrent userspace AUX transfers can dereference the freed
struct drm_device. Since dptx_hw_aux_unregister() is idempotent,
dptx_bridge_detach() can unregister AUX unconditionally under dp->lock,
and dptx_deinit() should avoid DPCD transfers with a stale aux->drm_dev.
> + dp->state &= ~(DPTX_STATE_CONFIGURED);
> + consumer = dp->link_consumer;
> + dp->link_consumer = NULL;
> + }
> +
> + if (consumer)
> + device_link_remove(consumer, dp->dev);
> +}
[Severity: Medium]
Can calling device_link_remove() outside dp->lock race with platform device
removal and cause a use-after-free on dp->dev?
Both dptx_deinit() and dptx_bridge_detach() clear dp->link_consumer under
dp->lock and drop the lock before calling device_link_remove(). Because
the link is DL_FLAG_STATELESS, supplier removal does not unbind the
consumer first:
CPU0 CPU1
dptx_bridge_detach()
mutex_lock(&dp->lock)
consumer = dp->link_consumer
dp->link_consumer = NULL
mutex_unlock(&dp->lock)
trilinear_dptx_remove()
dptx_deinit()
/* sees link_consumer == NULL */
device_del(dp->dev)
put_device(dp->dev) (freed)
device_link_remove(consumer, dp->dev)
list_for_each_entry(..., &dp->dev->links.consumers, ...)
<-- use-after-free
Calling device_link_remove() while holding dp->lock in both
dptx_bridge_detach() and dptx_deinit() (matching device_link_add() in
dptx_bridge_attach()) serializes link removal against supplier teardown.
[ ... ]
> +struct dptx_dev *trilinear_dptx_probe(struct device *dev,
> + const struct dptx_plat_data *soc_data,
> + void *priv)
> +{
> + struct device_node *remote __free(device_node) = NULL;
[Severity: Low]
This isn't a bug, but remote is declared with __free(device_node) = NULL at
the top of the function and assigned much later, whereas the cleanup API
convention is to initialize __free() variables at acquisition.
In addition, of_drm_get_bridge_by_endpoint() already calls
of_graph_get_remote_node() internally and returns ERR_PTR(-ENODEV) when no
remote endpoint is present, so calling of_drm_get_bridge_by_endpoint()
directly and ignoring -ENODEV drops both the redundant OF lookup and the
remote variable.
[ ... ]
> + remote = of_graph_get_remote_node(dev->of_node, 1, 0);
> + if (remote) {
> + dp->next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node,
> + 1, 0);
> + if (IS_ERR(dp->next_bridge)) {
> + ret = PTR_ERR(dp->next_bridge);
> + dp->next_bridge = NULL;
> + dptx_deinit(dp);
> + return ERR_PTR(ret);
> + }
> + }
[Severity: Medium]
Does chaining a downstream bridge on port@1 break out-of-band HPD replay
and notifications on USB-C DisplayPort?
In upstream USB-C DP Alt Mode topologies, the chain ends at a
drm_aux_hpd_bridge (which sets DRM_BRIDGE_OP_HPD), and a dp-connector with
hpd-gpios also sets DRM_BRIDGE_OP_HPD. drm_bridge_connector_init() picks
the last bridge with DRM_BRIDGE_OP_HPD as bridge_connector->bridge_hpd, so
drm_bridge_connector_enable_hpd() never calls dptx_bridge_hpd_enable() on
&dp->bridge and dp->bridge.hpd_cb stays NULL.
As a result, boot-time dptx_replay_deferred_hotplug() never runs for an
already-plugged USB-C sink, and dptx_notify_hpd() becomes a silent no-op,
dropping notifications from delayed PHY DP-mode polling and system resume
in dptx_pm_complete(). Conversely, wiring port@1 directly to a USB-C combo
PHY that does not register a struct drm_bridge (as documented in
cix,sky1-dp.yaml) makes of_drm_get_bridge_by_endpoint() return
-EPROBE_DEFER indefinitely.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@cixtech.com?part=4
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge
2026-12-04 11:43 ` [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
@ 2026-12-04 12:16 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-04 12:16 UTC (permalink / raw)
To: Luo Liu; +Cc: dri-devel, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] drm/bridge: trilinear: dptx_bridge_hpd_enable() skipped with
downstream HPD
- [Medium] drm/bridge: trilinear: dptx_bridge_atomic_check() gates on
crtc active
- [Medium] drm/bridge: trilinear: UAF of dp->dev in dptx_bridge_detach()
- [Medium] drm/bridge: trilinear: UAF of dp->dev in
dptx_bridge_mode_set()
- [Medium] drm/bridge: trilinear: stale connector_state->max_bpc in
dptx_cal_bpc()
- [Medium] drm/bridge: trilinear: detect_task echo filter bypassed with
next_bridge
- [Low] drm/bridge: trilinear: dptx_format_ok() ignores connector
ycbcr_420_allowed
- [Low] drm/bridge: trilinear: dptx_bridge_get_modes() skips clearing
stale EDID
--
commit c57f0845c508835bad4ad01db002a262ef2f01b3
Author: Luo Liu <Luo.Liu@cixtech.com>
drm/bridge: trilinear: add the DPTX DRM bridge
This patch adds the DRM bridge implementation for the Trilinear DisplayPort
transmitter, including connector detection, EDID mode reading, mode
validation, atomic check/enable/disable, and bridge attach/detach helpers.
> diff --git a/drivers/gpu/drm/bridge/trilinear/dptx_drm.c b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c
> new file mode 100644
> index 0000000000000..02be7923528ff
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/trilinear/dptx_drm.c
[ ... ]
> +static enum drm_connector_status dptx_bridge_detect(struct drm_bridge *bridge,
> + struct drm_connector *connector)
> +{
> + struct dptx_dev *dp = bridge_to_dp(bridge);
> + enum drm_connector_status status;
> +
> + status = dp->ops->detect_status(dp);
> + WRITE_ONCE(dp->detect_task, current);
> +
> + return status;
> +}
> +
> +static void dptx_hpd_notify(struct dptx_dev *dp,
> + enum drm_connector_status hpd_state)
> +{
> + if (READ_ONCE(dp->detect_task) == current) {
> + WRITE_ONCE(dp->detect_task, NULL);
> + return;
> + }
> +
> + if (READ_ONCE(dp->notify_task) == current) {
> + WRITE_ONCE(dp->notify_task, NULL);
> + return;
> + }
> +
> + if (!dp->oob_hpd)
> + return;
> +
> + guard(mutex)(&dp->lock);
> +
> + if (dp->hpd_stopped ||
> + hpd_state == connector_status_unknown)
> + return;
> +
> + dp->force_hpd = hpd_state;
> +
> + if (!(dp->state & DPTX_STATE_SUSPENDED)) {
> + queue_delayed_work(system_freezable_wq, &dp->hpd_event_work, 0);
> + if (hpd_state == connector_status_connected)
> + queue_delayed_work(system_freezable_wq,
> + &dp->hpd_irq_work,
> + msecs_to_jiffies(20));
> + }
> +}
[Severity: Medium]
Can chaining a downstream bridge that advertises DRM_BRIDGE_OP_DETECT bypass
the detect_task echo filter?
drm_bridge_connector_init() selects the last bridge in the chain advertising
DRM_BRIDGE_OP_DETECT as bridge_detect. When dp->oob_hpd is true and
dp->next_bridge sets DRM_BRIDGE_OP_DETECT, drm_bridge_connector_detect_ctx()
calls detect on dp->next_bridge instead of dptx_bridge_detect(), and then
broadcasts hpd_notify to every bridge in the chain.
Because dp->detect_task is never set, dptx_hpd_notify() treats every
connector probe as a new out-of-band hotplug event and queues hpd_event_work
and hpd_irq_work. If dp->next_bridge does not also set DRM_BRIDGE_OP_HPD
(leaving dp->bridge as bridge_hpd), hpd_event_work triggers
drm_bridge_connector_handle_hpd(), which clears dp->notify_task before
drm_kms_helper_connector_hotplug_event() reprobes the connector, creating an
infinite hotplug and workqueue loop.
[ ... ]
> +static int dptx_bridge_get_modes(struct drm_bridge *bridge,
> + struct drm_connector *connector)
> +{
> + struct dptx_dev *dp = bridge_to_dp(bridge);
> + const struct drm_edid *edid;
> + struct drm_display_mode *mode;
> + int ret;
> +
> + scoped_guard(mutex, &dp->lock) {
> + if (dp->released ||
> + (dp->state & DPTX_STATE_SUSPENDED) ||
> + !(dp->state & DPTX_STATE_INITIALIZED) ||
> + !(dp->state & DPTX_STATE_CONNECTED))
> + return 0;
> +
> + edid = drm_edid_read(connector);
> + }
[Severity: Low]
Should this early return clear the connector's EDID with
drm_edid_connector_update(connector, NULL)?
drm_helper_probe_single_connector_modes() only clears the EDID property when
connector->status is connector_status_disconnected. When a connector is
forced on (DRM_FORCE_ON) after unplugging a sink, or probed while suspended
(connector_status_unknown), returning 0 here skips the later
drm_edid_connector_update(connector, NULL) call and leaves stale
connector->edid_blob_ptr and connector->display_info from the previous sink
while connector->modes is replaced with fallback modes.
Clearing the EDID outside dp->lock on this early-return path would match
drm_bridge_connector_get_modes_edid().
[ ... ]
> +static int dptx_cal_bpc(struct drm_connector_state *connector_state,
> + int format, int bpc)
> +{
> + int max_bpc = connector_state->max_bpc;
> +
> + if (dptx_bt2020_colorspace(connector_state))
> + max_bpc = min(max_bpc, 10);
> +
> + bpc = min(bpc, max_bpc);
[Severity: Medium]
Can connector_state->max_bpc be stale here after hotplugging a different
sink?
drm_atomic_check_only() runs drm_atomic_connector_check() (which refreshes
connector_state->max_bpc from display_info.bpc) only for connectors already
in the atomic state before driver atomic_check(). On a CRTC-only modeset
(for example changing MODE_ID without modifying connector properties), the
connector is added later by drm_atomic_add_affected_connectors() with its
previous max_bpc intact.
After swapping a 6-bpc sink for an 8-bpc or 10-bpc sink, a stale max_bpc of
6 causes dptx_cal_bpc() to reject valid YCbCr 4:2:0/4:2:2 modes and clamp
RGB to 6 bpc; swapping from 10-bpc to 8-bpc allows 10-bpc YCbCr 4:2:2 to be
selected for an 8-bpc sink. Computing max_bpc directly from
connector->display_info.bpc (defaulting to 8 when 0) and clamping by
connector_state->max_requested_bpc avoids stale values.
[ ... ]
> +static bool dptx_format_ok(struct dptx_dev *dp,
> + const struct drm_display_info *info,
> + const struct drm_display_mode *mode,
> + const struct drm_display_mode *adjusted_mode,
> + int info_formats, int format)
> +{
> + if (format == DRM_OUTPUT_COLOR_FORMAT_YCBCR420) {
> + if (!dp->hw->ops->vsc_supported(dp->hw))
> + return false;
> +
> + /*
> + * Y420VDB sets the sink-wide 420 bit for every mode. This
> + * VIC has to be 420-only or 420-also. 420 is one pixel
> + * per cycle.
> + */
> + if (!drm_mode_is_420(info, mode))
> + return false;
> +
> + return adjusted_mode->clock <= DPTX_MAX_FREQ;
> + }
[Severity: Low]
Does dptx_format_ok() need to check conn_state->connector->ycbcr_420_allowed
before allowing YCbCr 4:2:0?
drm_bridge_connector_init() clears connector->ycbcr_420_allowed when any
bridge in the encoder's chain (such as a downstream bridge attached at
dp->next_bridge) does not support YCbCr 4:2:0. Because dptx_format_ok()
does not check connector->ycbcr_420_allowed, a 420-also mode whose clock
exceeds RGB/4:2:2 link bandwidth can still be accepted and programmed as
DP_PIXELFORMAT_YUV420, producing broken or blank output.
[ ... ]
> +static int dptx_bridge_mode_set(struct dptx_dev *dp,
> + struct drm_crtc_state *crtc_state,
> + struct drm_connector_state *conn_state)
> +{
> + struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
> + int color_format;
> + int link_rate;
> + int bw_code;
> + int bpc;
> + int bpp;
> + int ret;
> +
> + ret = dp->ops->detect(dp);
> + if (ret)
> + return ret;
> +
> + guard(mutex)(&dp->lock);
> +
> + ret = dptx_pick_config(dp, conn_state, &crtc_state->mode,
> + adjusted_mode, &color_format, &bpc, &bpp);
> + if (ret)
> + return ret;
> +
> + dp->config.format = dptx_drm_format_to_dp(color_format);
> + dp->config.colorspace = conn_state->colorspace;
> + dp->config.content_type = conn_state->content_type;
> + dp->config.bpc = bpc;
> + dp->config.bpp = bpp;
> + drm_mode_copy(&dp->adjusted_mode, adjusted_mode);
> + dp->pixel_per_cycle = dptx_pick_ppc(adjusted_mode, dp->config.format);
> +
> + link_rate = dptx_pick_link_rate(dp, adjusted_mode, bpp);
> + bw_code = drm_dp_link_rate_to_bw_code(link_rate);
> +
> + ret = dp->ops->mode_configure(dp, adjusted_mode->clock, bw_code,
> + bpp, false);
> + if (ret)
> + return ret;
> +
> + dev_dbg(dp->dev,
> + "%dx%d@%d fmt=%d bpc=%d bpp=%d link=%u lanes=%u ppc=%u\n",
> + adjusted_mode->hdisplay, adjusted_mode->vdisplay,
> + drm_mode_vrefresh(adjusted_mode), dp->config.format,
> + bpc, bpp, bw_code, dp->mode.lane_cnt,
> + dp->pixel_per_cycle);
> +
> + return 0;
> +}
[Severity: Medium]
Can concurrent platform device removal free dp->dev before dev_dbg(dp->dev,
...) runs?
struct dptx_dev stores dp->dev without taking a get_device() reference, and
dptx_bridge_mode_set() does not re-check dp->released after reacquiring
dp->lock:
CPU0 CPU1
dptx_bridge_mode_set()
dp->ops->detect(dp)
/* drops dp->lock */
platform_device_unregister()
dptx_deinit()
dp->released = true
device_del(dp->dev)
put_device(dp->dev) /* freed */
guard(mutex)(&dp->lock)
...
dev_dbg(dp->dev, ...) <-- use-after-free
Checking dp->released right after acquiring dp->lock (or pinning dp->dev
with get_device()/put_device() for the lifetime of the bridge) would close
this window.
> +
> +static int dptx_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 dptx_dev *dp = bridge_to_dp(bridge);
> + int bpc;
> + int bpp;
> + int ret;
> + bool vsc_supported;
> +
> + if (!conn_state->crtc)
> + return 0;
> +
> + if (!crtc_state->active)
> + return 0;
> +
> + if (!dptx_adjust_mode(&crtc_state->mode, &crtc_state->adjusted_mode))
> + return -EINVAL;
[Severity: Medium]
Returning early on !crtc_state->active looks like it violates the DRM atomic
DPMS contract -- shouldn't this gate on crtc_state->enable instead?
include/drm/drm_crtc.h specifies that drivers must not consult
crtc_state->active in atomic_check to reject commits, because DPMS ON on an
already-enabled CRTC is expected to succeed. When userspace commits a
modeset with enable=true and active=false, returning early here skips
dptx_adjust_mode() and dptx_pick_config(), so mode_fixup() in
drm_atomic_helper.c runs the CRTC's mode_fixup() on the unadjusted timings.
On the subsequent DPMS ON commit (active=true, mode_changed=false),
dptx_bridge_atomic_check() then runs and can reject DPMS ON with -EINVAL
(for an unsupported mode or after a sink swap during DPMS OFF), or mutate
adjusted_mode->htotal/clock/flags while the CRTC's mode_fixup() is skipped,
leaving CRTC and DPTX programmed with mismatched timings. Adjusting and
validating when crtc_state->enable is true (and gating link revalidation on
mode_changed || connectors_changed) avoids both problems.
[ ... ]
> +static void dptx_bridge_hpd_enable(struct drm_bridge *bridge)
> +{
> + struct dptx_dev *dp = bridge_to_dp(bridge);
> +
> + dp->ops->replay_deferred_hotplug(dp);
> +}
[Severity: High]
Will dptx_bridge_hpd_enable() ever be called when a downstream bridge
advertises DRM_BRIDGE_OP_HPD?
When dp->next_bridge is a USB-C HPD bridge such as drm_aux_hpd_bridge
(which sets DRM_BRIDGE_OP_HPD with no .hpd_enable hook),
drm_bridge_connector_init() overwrites bridge_connector->bridge_hpd with
dp->next_bridge because it sits later in encoder->bridge_chain.
drm_bridge_connector_enable_hpd() then only calls drm_bridge_hpd_enable() on
bridge_connector->bridge_hpd, so dptx_bridge_hpd_enable() never runs at
boot.
With dp->oob_hpd set, any early HPD notification before connector HPD is
enabled is dropped while the controller's own HPD pin is unwired, leaving an
already-connected USB-C DisplayPort sink reported as disconnected until it
is unplugged and replugged.
> +
> +static void dptx_bridge_detach(struct drm_bridge *bridge)
> +{
> + struct dptx_dev *dp = bridge_to_dp(bridge);
> + struct device *consumer;
> +
> + /* Stop workers before the connector goes away. */
> + dp->ops->quiesce_hpd(dp);
> +
> + scoped_guard(mutex, &dp->lock) {
> + dp->attached = false;
> +
> + if (!dp->released)
> + dp->hw->ops->aux_unregister(dp->hw);
> +
> + consumer = dp->link_consumer;
> + dp->link_consumer = NULL;
> + }
> +
> + if (consumer)
> + device_link_remove(consumer, dp->dev);
> +}
[Severity: Medium]
Can device_link_remove(consumer, dp->dev) dereference a freed dp->dev once
dp->lock is dropped?
dp->link_consumer is cleared unconditionally without checking !dp->released,
and struct dptx_dev holds no get_device() reference on dp->dev:
CPU0 CPU1
dptx_bridge_detach()
lock(&dp->lock)
consumer = dp->link_consumer
dp->link_consumer = NULL
unlock(&dp->lock)
platform_device_unregister()
dptx_deinit()
/* dp->link_consumer is NULL */
device_del(dp->dev)
device_links_purge(dp->dev)
put_device(dp->dev) /* freed */
device_link_remove(consumer,
dp->dev) <-- use-after-free
Guarding the link removal with !dp->released while holding dp->lock
(matching device_link_add() in dptx_bridge_attach()), or taking a
get_device()/put_device() reference on dp->dev, would prevent this
use-after-free.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114332.280808-1-Luo.Liu@cixtech.com?part=3
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-04 12:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:43 [PATCH v10 0/5] drm/bridge: trilinear: add the Sky1 DisplayPort transmitter Luo Liu
2026-12-04 11:43 ` [PATCH v10 1/5] dt-bindings: display: add CIX " Luo Liu
2026-12-04 11:43 ` [PATCH v10 2/5] drm/bridge: trilinear: add the DPTX hardware layer Luo Liu
2026-12-04 12:06 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 3/5] drm/bridge: trilinear: add the DPTX DRM bridge Luo Liu
2026-12-04 12:16 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 4/5] drm/bridge: trilinear: add the DPTX core and build glue Luo Liu
2026-12-04 12:15 ` sashiko-bot
2026-12-04 11:43 ` [PATCH v10 5/5] drm/cix: add the Sky1 DisplayPort platform glue Luo Liu
2026-12-04 12:01 ` sashiko-bot
2026-12-04 12:11 ` 回复: " Luo Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox