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 <[email protected]> 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/[email protected]?part=2
