When DisplayPort HPD is handled by a downstream bridge (such as USB
Type-C AltMode or display-connector with hpd-gpios, including behind a
QMP combo PHY drm_aux_bridge), msm_dp_bridge_hpd_enable() is never
called and REG_DP_DP_HPD_CTRL remains disabled. As a result,
msm_dp_aux_is_link_connected() unconditionally reads 0
(ISR_DISCONNECTED) even while a sink is physically connected:

- In msm_dp_ctrl_on_link(), failing DP_TRAINING_1 or DP_TRAINING_2
  immediately breaks out of the training loop instead of downshifting
  the link rate or lane count; in addition, the return value of
  drm_dp_dpcd_read_link_status() was unchecked, leaving link_status
  uninitialized on AUX errors.
- In msm_dp_display_process_hpd_high(), a failed EDID read falsely
  treats the link as unplugged and aborts with -ETIMEDOUT.
- In msm_dp_aux_transfer(), AUX timeouts skip msm_dp_aux_reset().

Track whether the controller's internal HPD block is enabled via
msm_dp_aux_is_hpd_enabled(), gate those internal HPD state checks on it
(also returning false immediately in msm_dp_display_is_dongle_plugged()
when internal HPD is enabled and reports ISR_DISCONNECTED), and check
drm_dp_dpcd_read_link_status() <= 0 in msm_dp_ctrl_on_link(). Keep the
!priv->plugged && !ret guard in msm_dp_bridge_detect() unconditional so
USB Type-C connectors using drm_aux_hpd_bridge stay disconnected until
AltMode mux and orientation setup notify HPD.

Fixes: a8e981ac2d0e ("drm/msm/dp: enable HDP plugin/unplugged interrupts at 
hpd_enable/disable")
Fixes: 5043357e75ba ("drm/msm/dp: rework HPD handling")
Signed-off-by: Gianfranco Mariotti <[email protected]>
---
 drivers/gpu/drm/msm/dp/dp_aux.c     | 13 ++++++++++++-
 drivers/gpu/drm/msm/dp/dp_aux.h     |  1 +
 drivers/gpu/drm/msm/dp/dp_ctrl.c    | 14 ++++++++++----
 drivers/gpu/drm/msm/dp/dp_display.c |  7 ++++++-
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c
index 3825a2fb48e2..74a90d8de167 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.c
+++ b/drivers/gpu/drm/msm/dp/dp_aux.c
@@ -40,6 +40,7 @@ struct msm_dp_aux_private {
        bool initted;
        bool is_edp;
        bool enable_xfers;
+       bool hpd_enabled;
        u32 offset;
        u32 segment;
 
@@ -412,7 +413,7 @@ static ssize_t msm_dp_aux_transfer(struct drm_dp_aux 
*msm_dp_aux,
                                phy_calibrate(aux->phy);
                }
                /* reset aux if link is in connected state */
-               if (msm_dp_aux_is_link_connected(msm_dp_aux))
+               if (!aux->hpd_enabled || 
msm_dp_aux_is_link_connected(msm_dp_aux))
                        msm_dp_aux_reset(aux);
        } else {
                aux->retry_cnt = 0;
@@ -606,6 +607,7 @@ void msm_dp_aux_hpd_enable(struct drm_dp_aux *msm_dp_aux)
 
        /* Enable HPD */
        msm_dp_write_aux(aux, REG_DP_DP_HPD_CTRL, DP_DP_HPD_CTRL_HPD_EN);
+       aux->hpd_enabled = true;
 }
 
 void msm_dp_aux_hpd_disable(struct drm_dp_aux *msm_dp_aux)
@@ -614,6 +616,7 @@ void msm_dp_aux_hpd_disable(struct drm_dp_aux *msm_dp_aux)
                container_of(msm_dp_aux, struct msm_dp_aux_private, msm_dp_aux);
        u32 reg;
 
+       aux->hpd_enabled = false;
        reg = msm_dp_read_aux(aux, REG_DP_DP_HPD_REFTIMER);
        reg &= ~DP_DP_HPD_REFTIMER_ENABLE;
        msm_dp_write_aux(aux, REG_DP_DP_HPD_REFTIMER, reg);
@@ -679,6 +682,14 @@ u32 msm_dp_aux_is_link_connected(struct drm_dp_aux 
*msm_dp_aux)
        return status;
 }
 
+bool msm_dp_aux_is_hpd_enabled(struct drm_dp_aux *msm_dp_aux)
+{
+       struct msm_dp_aux_private *aux =
+               container_of(msm_dp_aux, struct msm_dp_aux_private, msm_dp_aux);
+
+       return aux->hpd_enabled;
+}
+
 struct drm_dp_aux *msm_dp_aux_get(struct device *dev,
                              struct phy *phy,
                              bool is_edp,
diff --git a/drivers/gpu/drm/msm/dp/dp_aux.h b/drivers/gpu/drm/msm/dp/dp_aux.h
index 4be02e8b4d0b..d3cf281f159a 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.h
+++ b/drivers/gpu/drm/msm/dp/dp_aux.h
@@ -22,6 +22,7 @@ void msm_dp_aux_hpd_intr_enable(struct drm_dp_aux 
*msm_dp_aux);
 void msm_dp_aux_hpd_intr_disable(struct drm_dp_aux *msm_dp_aux);
 u32 msm_dp_aux_get_hpd_intr_status(struct drm_dp_aux *msm_dp_aux);
 u32 msm_dp_aux_is_link_connected(struct drm_dp_aux *msm_dp_aux);
+bool msm_dp_aux_is_hpd_enabled(struct drm_dp_aux *msm_dp_aux);
 
 struct phy;
 struct drm_dp_aux *msm_dp_aux_get(struct device *dev,
diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index ceff9a99147f..36fc9c6bd9f4 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -2435,10 +2435,13 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl,
                        break;
                } else if (training_step == DP_TRAINING_1) {
                        /* link train_1 failed */
-                       if (!msm_dp_aux_is_link_connected(ctrl->aux))
+                       if (msm_dp_aux_is_hpd_enabled(ctrl->aux) &&
+                           !msm_dp_aux_is_link_connected(ctrl->aux))
                                break;
 
-                       drm_dp_dpcd_read_link_status(ctrl->aux, link_status);
+                       if (drm_dp_dpcd_read_link_status(ctrl->aux,
+                                                        link_status) <= 0)
+                               break;
 
                        rc = msm_dp_ctrl_link_rate_down_shift(ctrl);
                        if (rc < 0) { /* already in RBR = 1.6G */
@@ -2460,10 +2463,13 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl,
                        }
                } else if (training_step == DP_TRAINING_2) {
                        /* link train_2 failed */
-                       if (!msm_dp_aux_is_link_connected(ctrl->aux))
+                       if (msm_dp_aux_is_hpd_enabled(ctrl->aux) &&
+                           !msm_dp_aux_is_link_connected(ctrl->aux))
                                break;
 
-                       drm_dp_dpcd_read_link_status(ctrl->aux, link_status);
+                       if (drm_dp_dpcd_read_link_status(ctrl->aux,
+                                                        link_status) <= 0)
+                               break;
 
                        if (!drm_dp_clock_recovery_ok(link_status,
                                        ctrl->link->link_params.num_lanes))
diff --git a/drivers/gpu/drm/msm/dp/dp_display.c 
b/drivers/gpu/drm/msm/dp/dp_display.c
index b83de4c3d234..b4ea61a88d68 100644
--- a/drivers/gpu/drm/msm/dp/dp_display.c
+++ b/drivers/gpu/drm/msm/dp/dp_display.c
@@ -294,7 +294,8 @@ static int msm_dp_display_process_hpd_high(struct 
msm_dp_display_private *dp)
                if (connector->force != DRM_FORCE_OFF)
                        DRM_ERROR("panel edid read failed\n");
                /* check edid read fail is due to unplug */
-               if (!msm_dp_aux_is_link_connected(dp->aux)) {
+               if (msm_dp_aux_is_hpd_enabled(dp->aux) &&
+                   !msm_dp_aux_is_link_connected(dp->aux)) {
                        rc = -ETIMEDOUT;
                        goto end;
                }
@@ -1693,6 +1694,10 @@ static bool msm_dp_display_is_dongle_plugged(struct 
msm_dp_display_private *dp,
        if (!dp->plugged || !dp->link->has_sink_count)
                return false;
 
+       if (msm_dp_aux_is_hpd_enabled(dp->aux) &&
+           hpd_link_status == ISR_DISCONNECTED)
+               return false;
+
        if (!dp->link->sink_count && hpd_link_status != ISR_DISCONNECTED)
                return true;
 
-- 
2.25.1

Reply via email to