drm/i915/tc: Factor out a function querying active links on a TC port
authorImre Deak <imre.deak@intel.com>
Tue, 21 Mar 2023 22:01:00 +0000 (00:01 +0200)
committerImre Deak <imre.deak@intel.com>
Wed, 22 Mar 2023 18:31:22 +0000 (20:31 +0200)
For clarity factor out the function to determine if there are active
links on a TC port. This prepares for the next patch also checking the
port's PLL type.

While at it pass crtc_state to intel_tc_port_sanitize_mode(), and check
hw.active in that, instead of the deprecated crtc->active flag.

v2: Check crtc_state->hw.active instead of crtc->active. (Ville)

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230321220101.983366-2-imre.deak@intel.com
drivers/gpu/drm/i915/display/intel_ddi.c
drivers/gpu/drm/i915/display/intel_tc.c
drivers/gpu/drm/i915/display/intel_tc.h

index 6f48a7b8dcffaae2051f13b0a89466a15efa1a23..73240cf78c8bf3b7298c5762b21275bdea93a6c8 100644 (file)
@@ -3642,7 +3642,8 @@ static void intel_ddi_sync_state(struct intel_encoder *encoder,
        enum phy phy = intel_port_to_phy(i915, encoder->port);
 
        if (intel_phy_is_tc(i915, phy))
-               intel_tc_port_sanitize_mode(enc_to_dig_port(encoder));
+               intel_tc_port_sanitize_mode(enc_to_dig_port(encoder),
+                                           crtc_state);
 
        if (crtc_state && intel_crtc_has_dp_encoder(crtc_state))
                intel_dp_sync_state(encoder, crtc_state);
index 5d040f0c5f6305a3dee38af7ce08d739334a3cf9..c5bfd9f11d7de9f5233a7219022dfbf0f1d02cab 100644 (file)
@@ -872,36 +872,47 @@ void intel_tc_port_init_mode(struct intel_digital_port *dig_port)
        mutex_unlock(&dig_port->tc_lock);
 }
 
+static bool tc_port_has_active_links(struct intel_digital_port *dig_port,
+                                    const struct intel_crtc_state *crtc_state)
+{
+       struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
+       int active_links = 0;
+
+       if (dig_port->dp.is_mst) {
+               active_links = intel_dp_mst_encoder_active_links(dig_port);
+       } else if (crtc_state && crtc_state->hw.active) {
+               active_links = 1;
+       }
+
+       if (active_links && !icl_tc_phy_is_connected(dig_port))
+               drm_err(&i915->drm,
+                       "Port %s: PHY disconnected with %d active link(s)\n",
+                       dig_port->tc_port_name, active_links);
+
+       return active_links;
+}
+
 /**
  * intel_tc_port_sanitize_mode: Sanitize the given port's TypeC mode
  * @dig_port: digital port
+ * @crtc_state: atomic state of CRTC connected to @dig_port
  *
  * Sanitize @dig_port's TypeC mode wrt. the encoder's state right after driver
  * loading and system resume:
  * If the encoder is enabled keep the TypeC mode/PHY connected state locked until
  * the encoder is disabled.
  * If the encoder is disabled make sure the PHY is disconnected.
+ * @crtc_state is valid if @dig_port is enabled, NULL otherwise.
  */
-void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port)
+void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port,
+                                const struct intel_crtc_state *crtc_state)
 {
        struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
-       struct intel_encoder *encoder = &dig_port->base;
-       int active_links = 0;
 
        mutex_lock(&dig_port->tc_lock);
 
-       if (dig_port->dp.is_mst)
-               active_links = intel_dp_mst_encoder_active_links(dig_port);
-       else if (encoder->base.crtc)
-               active_links = to_intel_crtc(encoder->base.crtc)->active;
-
        drm_WARN_ON(&i915->drm, dig_port->tc_link_refcount != 1);
-       if (active_links) {
-               if (!icl_tc_phy_is_connected(dig_port))
-                       drm_dbg_kms(&i915->drm,
-                                   "Port %s: PHY disconnected with %d active link(s)\n",
-                                   dig_port->tc_port_name, active_links);
-       } else {
+       if (!tc_port_has_active_links(dig_port, crtc_state)) {
                /*
                 * TBT-alt is the default mode in any case the PHY ownership is not
                 * held (regardless of the sink's connected live state), so
index 93813056043a54489a6b5ecb3265906c9f792d36..79667d977508cfb99438586e87283113408d0ce3 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/mutex.h>
 #include <linux/types.h>
 
+struct intel_crtc_state;
 struct intel_digital_port;
 struct intel_encoder;
 
@@ -26,7 +27,8 @@ void intel_tc_port_set_fia_lane_count(struct intel_digital_port *dig_port,
                                      int required_lanes);
 
 void intel_tc_port_init_mode(struct intel_digital_port *dig_port);
-void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port);
+void intel_tc_port_sanitize_mode(struct intel_digital_port *dig_port,
+                                const struct intel_crtc_state *crtc_state);
 void intel_tc_port_lock(struct intel_digital_port *dig_port);
 void intel_tc_port_unlock(struct intel_digital_port *dig_port);
 void intel_tc_port_flush_work(struct intel_digital_port *dig_port);