drm: zynqmp_dp: Retrain link after HPD if necessary
Subsystems (4)
v3 cover drm: zynqmp_dp: Retrain link after HPD if necessary
I noticed that after reconnecting a mini-displayport cable, the sink would not display an image. But if I forced the link to re-train, the image would come back.
Some digging revealed that the DP spec requires retraining after a HPD event if the sink syas the link has gone down. So implement that since it fixes my problem and it's required by spec.
Changes in v3:
- Simplify HPD retrain condition
Changes in v2:
- needs_retain -> needs_retrain
- Actually retrain the loop (accidentally removed while rebasing)
Sean Anderson (3):
drm: zynqmp_dp: Update connector state before AUX transfers
drm: zynqmp_dp: Use smp_load/store for status
drm: zynqmp_dp: Retrain link after HPD if necessary
drivers/gpu/drm/xlnx/zynqmp_dp.c | 42 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v3 1/3 drm: zynqmp_dp: Update connector state before AUX transfers
We still want to retry AUX transfers even when the connector is first plugged in. Update the connector state before reading the DPDC to ensure the AUX bus sees the most-recent state.
---
(no changes since v1)
drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
@@ -1697,6 +1697,7 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp) }if (state &ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_HPD ) { + dp->status = connector_status_connected; ret =drm_dp_dpcd_read (&dp->aux,0x0 , dp->dpcd,sizeof (dp->dpcd));if (ret <0 ) {
@@ -1711,7 +1712,6 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp)drm_dp_max_lane_count (dp->dpcd), dp->num_lanes); - dp->status = connector_status_connected;return connector_status_connected; }
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v3 2/3 drm: zynqmp_dp: Use smp_load/store for status
In reply to Sean Andersondp->status is read asynchronously by the AUX bus. Therefore, all reads outside of dp->lock must be atomic. Similarly, writes must be atomic as well. Reads with dp->lock held do not need to be atomic.
---
(no changes since v1)
drivers/gpu/drm/xlnx/zynqmp_dp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +3 -3
@@ -1111,7 +1111,7 @@ zynqmp_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)return msg->size; } -if (dp->status == connector_status_disconnected) { +if (READ_ONCE (dp->status) == connector_status_disconnected) {dev_dbg (dp->dev,"no connected aux device\n" );if (dp->ignore_aux_errors) goto fake_response;
@@ -1697,7 +1697,7 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp) }if (state &ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_HPD ) { - dp->status = connector_status_connected; +WRITE_ONCE (dp->status, connector_status_connected); ret =drm_dp_dpcd_read (&dp->aux,0x0 , dp->dpcd,sizeof (dp->dpcd));if (ret <0 ) {
@@ -1716,7 +1716,7 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp) } disconnected: - dp->status = connector_status_disconnected; +WRITE_ONCE (dp->status, connector_status_disconnected);return connector_status_disconnected; }
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v3 3/3 drm: zynqmp_dp: Retrain link after HPD if necessary
In reply to Sean AndersonSection 5.1.4 of the v1.2 DisplayPort standard says
Quoted 6 lines
The Source device shall respond to Hot Plug event/Hot Re-plug event by first reading DPCD Link/Sink Device Status registers at DPCD 00200h through 00205h.... If the link is unstable or lost, the Source device then reads the DPCD Receiver Capabilities registers at DPCD 00000h through 0000Fh to determine the appropriate information needed to train the link. The Source device shall then initiate link training.
However, zynqmp_dp_hpd_work_func does not check the link status. This may prevent the sink from detecting the source if, for example, the user disconnects the cable and then reconnects it. I encountered this problem when testing a mini DP connector (although I had no problem when using a full-size connector with the existing driver).
Follow the spec by checking the link status after a HPD event and retraining if necessary. Simplify the condition a bit since drm_dp_channel_eq_ok checks a superset of drm_dp_clock_recovery_ok.
---
Changes in v3:
- Simplify HPD retrain condition
Changes in v2:
- needs_retain -> needs_retrain
- Actually retrain the loop (accidentally removed while rebasing)
drivers/gpu/drm/xlnx/zynqmp_dp.c | 36 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +22 -14
@@ -1677,6 +1677,22 @@ static int zynqmp_dp_bridge_atomic_check(struct drm_bridge *bridge,return 0 ; } +static bool zynqmp_hpd_needs_retrain (struct zynqmp_dp *dp) +{ +u8 status[DP_LINK_STATUS_SIZE +2 ]; +int err; + + err =drm_dp_dpcd_read (&dp->aux,DP_SINK_COUNT , status, +DP_LINK_STATUS_SIZE +2 ); +if (err <0 ) { +dev_dbg_ratelimited (dp->dev, +"could not read sink status: %d\n" , err); +return false; + } + +return !drm_dp_channel_eq_ok (&status[2 ], dp->mode.lane_cnt); +} +static enum drm_connector_status __zynqmp_dp_bridge_detect (struct zynqmp_dp *dp) {struct zynqmp_dp_link_config *link_config = &dp->link_config;
@@ -1698,6 +1714,9 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp)if (state &ZYNQMP_DP_INTERRUPT_SIGNAL_STATE_HPD ) {WRITE_ONCE (dp->status, connector_status_connected); +if (!zynqmp_hpd_needs_retrain (dp)) +return connector_status_connected; + ret =drm_dp_dpcd_read (&dp->aux,0x0 , dp->dpcd,sizeof (dp->dpcd));if (ret <0 ) {
@@ -1712,6 +1731,7 @@ static enum drm_connector_status __zynqmp_dp_bridge_detect(struct zynqmp_dp *dp)drm_dp_max_lane_count (dp->dpcd), dp->num_lanes); +zynqmp_dp_train_loop (dp);return connector_status_connected; }
@@ -2335,25 +2355,13 @@ static void zynqmp_dp_hpd_irq_work_func(struct work_struct *work) { struct zynqmp_dp *dp = container_of(work, struct zynqmp_dp, hpd_irq_work); -u8 status[DP_LINK_STATUS_SIZE +2 ]; -int err;guard (mutex)(&dp->lock);if (dp->ignore_hpd)return ; - err =drm_dp_dpcd_read (&dp->aux,DP_SINK_COUNT , status, -DP_LINK_STATUS_SIZE +2 ); -if (err <0 ) { -dev_dbg_ratelimited (dp->dev, -"could not read sink status: %d\n" , err); - }else { -if (status[4 ] &DP_LINK_STATUS_UPDATED || - !drm_dp_clock_recovery_ok (&status[2 ], dp->mode.lane_cnt) || - !drm_dp_channel_eq_ok (&status[2 ], dp->mode.lane_cnt)) { -zynqmp_dp_train_loop (dp); - } - } +if (zynqmp_hpd_needs_retrain (dp)) +zynqmp_dp_train_loop (dp); }static irqreturn_t zynqmp_dp_irq_handler (int irq,void *data)
Signature · 1 line
2.35.1.1320.gc452695387.dirty