]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/gpu/drm/i915/intel_dp.c
drm/i915: Force VDD off on the new power seqeuencer before starting to use it
[mirror_ubuntu-artful-kernel.git] / drivers / gpu / drm / i915 / intel_dp.c
index 9df331b3305bbe83a4f9e81507f7c47a0bf1262f..fb12896bafee7af9683747ab4840045d7fb74c3b 100644 (file)
@@ -156,38 +156,28 @@ static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
        u8 source_max, sink_max;
 
        source_max = intel_dig_port->max_lanes;
-       sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
+       sink_max = intel_dp->max_sink_lane_count;
 
        return min(source_max, sink_max);
 }
 
-/*
- * The units on the numbers in the next two are... bizarre.  Examples will
- * make it clearer; this one parallels an example in the eDP spec.
- *
- * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
- *
- *     270000 * 1 * 8 / 10 == 216000
- *
- * The actual data capacity of that configuration is 2.16Gbit/s, so the
- * units are decakilobits.  ->clock in a drm_display_mode is in kilohertz -
- * or equivalently, kilopixels per second - so for 1680x1050R it'd be
- * 119000.  At 18bpp that's 2142000 kilobits per second.
- *
- * Thus the strange-looking division by 10 in intel_dp_link_required, to
- * get the result in decakilobits instead of kilobits.
- */
-
-static int
+int
 intel_dp_link_required(int pixel_clock, int bpp)
 {
-       return (pixel_clock * bpp + 9) / 10;
+       /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
+       return DIV_ROUND_UP(pixel_clock * bpp, 8);
 }
 
-static int
+int
 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
 {
-       return (max_link_clock * max_lanes * 8) / 10;
+       /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
+        * link rate that is generally expressed in Gbps. Since, 8 bits of data
+        * is transmitted every LS_Clk per lane, there is no need to account for
+        * the channel encoding that is done in the PHY layer here.
+        */
+
+       return max_link_clock * max_lanes;
 }
 
 static int
@@ -223,7 +213,7 @@ intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
 
        *sink_rates = default_rates;
 
-       return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
+       return (intel_dp->max_sink_link_bw >> 3) + 1;
 }
 
 static int
@@ -233,7 +223,7 @@ intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
        struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
        int size;
 
-       if (IS_BROXTON(dev_priv)) {
+       if (IS_GEN9_LP(dev_priv)) {
                *source_rates = bxt_rates;
                size = ARRAY_SIZE(bxt_rates);
        } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
@@ -288,6 +278,44 @@ static int intel_dp_common_rates(struct intel_dp *intel_dp,
                               common_rates);
 }
 
+static int intel_dp_link_rate_index(struct intel_dp *intel_dp,
+                                   int *common_rates, int link_rate)
+{
+       int common_len;
+       int index;
+
+       common_len = intel_dp_common_rates(intel_dp, common_rates);
+       for (index = 0; index < common_len; index++) {
+               if (link_rate == common_rates[common_len - index - 1])
+                       return common_len - index - 1;
+       }
+
+       return -1;
+}
+
+int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
+                                           int link_rate, uint8_t lane_count)
+{
+       int common_rates[DP_MAX_SUPPORTED_RATES];
+       int link_rate_index;
+
+       link_rate_index = intel_dp_link_rate_index(intel_dp,
+                                                  common_rates,
+                                                  link_rate);
+       if (link_rate_index > 0) {
+               intel_dp->max_sink_link_bw = drm_dp_link_rate_to_bw_code(common_rates[link_rate_index - 1]);
+               intel_dp->max_sink_lane_count = lane_count;
+       } else if (lane_count > 1) {
+               intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
+               intel_dp->max_sink_lane_count = lane_count >> 1;
+       } else {
+               DRM_ERROR("Link Training Unsuccessful\n");
+               return -1;
+       }
+
+       return 0;
+}
+
 static enum drm_mode_status
 intel_dp_mode_valid(struct drm_connector *connector,
                    struct drm_display_mode *mode)
@@ -355,7 +383,8 @@ intel_dp_init_panel_power_sequencer(struct drm_device *dev,
                                    struct intel_dp *intel_dp);
 static void
 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
-                                             struct intel_dp *intel_dp);
+                                             struct intel_dp *intel_dp,
+                                             bool force_disable_vdd);
 static void
 intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
 
@@ -464,14 +493,50 @@ vlv_power_sequencer_kick(struct intel_dp *intel_dp)
        }
 }
 
+static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
+{
+       struct intel_encoder *encoder;
+       unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
+
+       /*
+        * We don't have power sequencer currently.
+        * Pick one that's not used by other ports.
+        */
+       for_each_intel_encoder(&dev_priv->drm, encoder) {
+               struct intel_dp *intel_dp;
+
+               if (encoder->type != INTEL_OUTPUT_DP &&
+                   encoder->type != INTEL_OUTPUT_EDP)
+                       continue;
+
+               intel_dp = enc_to_intel_dp(&encoder->base);
+
+               if (encoder->type == INTEL_OUTPUT_EDP) {
+                       WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
+                               intel_dp->active_pipe != intel_dp->pps_pipe);
+
+                       if (intel_dp->pps_pipe != INVALID_PIPE)
+                               pipes &= ~(1 << intel_dp->pps_pipe);
+               } else {
+                       WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
+
+                       if (intel_dp->active_pipe != INVALID_PIPE)
+                               pipes &= ~(1 << intel_dp->active_pipe);
+               }
+       }
+
+       if (pipes == 0)
+               return INVALID_PIPE;
+
+       return ffs(pipes) - 1;
+}
+
 static enum pipe
 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
 {
        struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
        struct drm_device *dev = intel_dig_port->base.base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
-       struct intel_encoder *encoder;
-       unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
        enum pipe pipe;
 
        lockdep_assert_held(&dev_priv->pps_mutex);
@@ -479,33 +544,20 @@ vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
        /* We should never land here with regular DP ports */
        WARN_ON(!is_edp(intel_dp));
 
+       WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
+               intel_dp->active_pipe != intel_dp->pps_pipe);
+
        if (intel_dp->pps_pipe != INVALID_PIPE)
                return intel_dp->pps_pipe;
 
-       /*
-        * We don't have power sequencer currently.
-        * Pick one that's not used by other ports.
-        */
-       for_each_intel_encoder(dev, encoder) {
-               struct intel_dp *tmp;
-
-               if (encoder->type != INTEL_OUTPUT_EDP)
-                       continue;
-
-               tmp = enc_to_intel_dp(&encoder->base);
-
-               if (tmp->pps_pipe != INVALID_PIPE)
-                       pipes &= ~(1 << tmp->pps_pipe);
-       }
+       pipe = vlv_find_free_pps(dev_priv);
 
        /*
         * Didn't find one. This should not happen since there
         * are two power sequencers and up to two eDP ports.
         */
-       if (WARN_ON(pipes == 0))
+       if (WARN_ON(pipe == INVALID_PIPE))
                pipe = PIPE_A;
-       else
-               pipe = ffs(pipes) - 1;
 
        vlv_steal_power_sequencer(dev, pipe);
        intel_dp->pps_pipe = pipe;
@@ -516,7 +568,7 @@ vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
 
        /* init power sequencer on this pipe and port */
        intel_dp_init_panel_power_sequencer(dev, intel_dp);
-       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
+       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
 
        /*
         * Even vdd force doesn't work until we've made
@@ -553,7 +605,7 @@ bxt_power_sequencer_idx(struct intel_dp *intel_dp)
         * Only the HW needs to be reprogrammed, the SW state is fixed and
         * has been setup during connector init.
         */
-       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
+       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
 
        return 0;
 }
@@ -636,7 +688,7 @@ vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
                      port_name(port), pipe_name(intel_dp->pps_pipe));
 
        intel_dp_init_panel_power_sequencer(dev, intel_dp);
-       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
+       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
 }
 
 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
@@ -645,7 +697,7 @@ void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
        struct intel_encoder *encoder;
 
        if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
-                   !IS_BROXTON(dev_priv)))
+                   !IS_GEN9_LP(dev_priv)))
                return;
 
        /*
@@ -661,11 +713,18 @@ void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
        for_each_intel_encoder(dev, encoder) {
                struct intel_dp *intel_dp;
 
-               if (encoder->type != INTEL_OUTPUT_EDP)
+               if (encoder->type != INTEL_OUTPUT_DP &&
+                   encoder->type != INTEL_OUTPUT_EDP)
                        continue;
 
                intel_dp = enc_to_intel_dp(&encoder->base);
-               if (IS_BROXTON(dev_priv))
+
+               WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
+
+               if (encoder->type != INTEL_OUTPUT_EDP)
+                       continue;
+
+               if (IS_GEN9_LP(dev_priv))
                        intel_dp->pps_reset = true;
                else
                        intel_dp->pps_pipe = INVALID_PIPE;
@@ -688,7 +747,7 @@ static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
 
        memset(regs, 0, sizeof(*regs));
 
-       if (IS_BROXTON(dev_priv))
+       if (IS_GEN9_LP(dev_priv))
                pps_idx = bxt_power_sequencer_idx(intel_dp);
        else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
                pps_idx = vlv_power_sequencer_pipe(intel_dp);
@@ -697,7 +756,7 @@ static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
        regs->pp_stat = PP_STATUS(pps_idx);
        regs->pp_on = PP_ON_DELAYS(pps_idx);
        regs->pp_off = PP_OFF_DELAYS(pps_idx);
-       if (!IS_BROXTON(dev_priv))
+       if (!IS_GEN9_LP(dev_priv))
                regs->pp_div = PP_DIVISOR(pps_idx);
 }
 
@@ -942,14 +1001,14 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
                uint8_t *recv, int recv_size)
 {
        struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
-       struct drm_device *dev = intel_dig_port->base.base.dev;
-       struct drm_i915_private *dev_priv = to_i915(dev);
+       struct drm_i915_private *dev_priv =
+                       to_i915(intel_dig_port->base.base.dev);
        i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
        uint32_t aux_clock_divider;
        int i, ret, recv_bytes;
        uint32_t status;
        int try, clock = 0;
-       bool has_aux_irq = HAS_AUX_IRQ(dev);
+       bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
        bool vdd;
 
        pps_lock(intel_dp);
@@ -1542,8 +1601,7 @@ intel_dp_compute_config(struct intel_encoder *encoder,
                        struct intel_crtc_state *pipe_config,
                        struct drm_connector_state *conn_state)
 {
-       struct drm_device *dev = encoder->base.dev;
-       struct drm_i915_private *dev_priv = to_i915(dev);
+       struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
        struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
        struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
        enum port port = dp_to_dig_port(intel_dp)->port;
@@ -1578,7 +1636,7 @@ intel_dp_compute_config(struct intel_encoder *encoder,
                intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
                                       adjusted_mode);
 
-               if (INTEL_INFO(dev)->gen >= 9) {
+               if (INTEL_GEN(dev_priv) >= 9) {
                        int ret;
                        ret = skl_update_scaler_crtc(pipe_config);
                        if (ret)
@@ -1791,9 +1849,7 @@ static void intel_dp_prepare(struct intel_encoder *encoder,
                        trans_dp &= ~TRANS_DP_ENH_FRAMING;
                I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
        } else {
-               if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
-                   !IS_CHERRYVIEW(dev_priv) &&
-                   pipe_config->limited_color_range)
+               if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
                        intel_dp->DP |= DP_COLOR_RANGE_16_235;
 
                if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
@@ -2404,6 +2460,8 @@ void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
                ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
                                         DP_SET_POWER_D3);
        } else {
+               struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
+
                /*
                 * When turning on, we need to retry for 1ms to give the sink
                 * time to wake up.
@@ -2415,6 +2473,9 @@ void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
                                break;
                        msleep(1);
                }
+
+               if (ret == 1 && lspcon->active)
+                       lspcon_wait_pcon_mode(lspcon);
        }
 
        if (ret != 1)
@@ -2515,8 +2576,7 @@ static void intel_dp_get_config(struct intel_encoder *encoder,
 
        pipe_config->base.adjusted_mode.flags |= flags;
 
-       if (!HAS_PCH_SPLIT(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
-           !IS_CHERRYVIEW(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
+       if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
                pipe_config->limited_color_range = true;
 
        pipe_config->lane_count =
@@ -2735,7 +2795,8 @@ static void intel_dp_enable_port(struct intel_dp *intel_dp,
 }
 
 static void intel_enable_dp(struct intel_encoder *encoder,
-                           struct intel_crtc_state *pipe_config)
+                           struct intel_crtc_state *pipe_config,
+                           struct drm_connector_state *conn_state)
 {
        struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
        struct drm_device *dev = encoder->base.dev;
@@ -2777,7 +2838,7 @@ static void intel_enable_dp(struct intel_encoder *encoder,
        if (pipe_config->has_audio) {
                DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
                                 pipe_name(pipe));
-               intel_audio_codec_enable(encoder);
+               intel_audio_codec_enable(encoder, pipe_config, conn_state);
        }
 }
 
@@ -2787,7 +2848,7 @@ static void g4x_enable_dp(struct intel_encoder *encoder,
 {
        struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
 
-       intel_enable_dp(encoder, pipe_config);
+       intel_enable_dp(encoder, pipe_config, conn_state);
        intel_edp_backlight_on(intel_dp);
 }
 
@@ -2822,6 +2883,8 @@ static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
        enum pipe pipe = intel_dp->pps_pipe;
        i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
 
+       WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
+
        edp_panel_vdd_off_sync(intel_dp);
 
        /*
@@ -2856,22 +2919,23 @@ static void vlv_steal_power_sequencer(struct drm_device *dev,
                struct intel_dp *intel_dp;
                enum port port;
 
-               if (encoder->type != INTEL_OUTPUT_EDP)
+               if (encoder->type != INTEL_OUTPUT_DP &&
+                   encoder->type != INTEL_OUTPUT_EDP)
                        continue;
 
                intel_dp = enc_to_intel_dp(&encoder->base);
                port = dp_to_dig_port(intel_dp)->port;
 
+               WARN(intel_dp->active_pipe == pipe,
+                    "stealing pipe %c power sequencer from active (e)DP port %c\n",
+                    pipe_name(pipe), port_name(port));
+
                if (intel_dp->pps_pipe != pipe)
                        continue;
 
                DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
                              pipe_name(pipe), port_name(port));
 
-               WARN(encoder->base.crtc,
-                    "stealing pipe %c power sequencer from active eDP port %c\n",
-                    pipe_name(pipe), port_name(port));
-
                /* make sure vdd is off before we steal it */
                vlv_detach_power_sequencer(intel_dp);
        }
@@ -2887,19 +2951,17 @@ static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
 
        lockdep_assert_held(&dev_priv->pps_mutex);
 
-       if (!is_edp(intel_dp))
-               return;
-
-       if (intel_dp->pps_pipe == crtc->pipe)
-               return;
+       WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
 
-       /*
-        * If another power sequencer was being used on this
-        * port previously make sure to turn off vdd there while
-        * we still have control of it.
-        */
-       if (intel_dp->pps_pipe != INVALID_PIPE)
+       if (intel_dp->pps_pipe != INVALID_PIPE &&
+           intel_dp->pps_pipe != crtc->pipe) {
+               /*
+                * If another power sequencer was being used on this
+                * port previously make sure to turn off vdd there while
+                * we still have control of it.
+                */
                vlv_detach_power_sequencer(intel_dp);
+       }
 
        /*
         * We may be stealing the power
@@ -2907,6 +2969,11 @@ static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
         */
        vlv_steal_power_sequencer(dev, crtc->pipe);
 
+       intel_dp->active_pipe = crtc->pipe;
+
+       if (!is_edp(intel_dp))
+               return;
+
        /* now it's all ours */
        intel_dp->pps_pipe = crtc->pipe;
 
@@ -2915,7 +2982,7 @@ static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
 
        /* init power sequencer on this pipe and port */
        intel_dp_init_panel_power_sequencer(dev, intel_dp);
-       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
+       intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
 }
 
 static void vlv_pre_enable_dp(struct intel_encoder *encoder,
@@ -2924,7 +2991,7 @@ static void vlv_pre_enable_dp(struct intel_encoder *encoder,
 {
        vlv_phy_pre_encoder_enable(encoder);
 
-       intel_enable_dp(encoder, pipe_config);
+       intel_enable_dp(encoder, pipe_config, conn_state);
 }
 
 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
@@ -2942,7 +3009,7 @@ static void chv_pre_enable_dp(struct intel_encoder *encoder,
 {
        chv_phy_pre_encoder_enable(encoder);
 
-       intel_enable_dp(encoder, pipe_config);
+       intel_enable_dp(encoder, pipe_config, conn_state);
 
        /* Second common lane will stay alive on its own now */
        chv_phy_release_cl2_override(encoder);
@@ -2979,13 +3046,12 @@ intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_
 uint8_t
 intel_dp_voltage_max(struct intel_dp *intel_dp)
 {
-       struct drm_device *dev = intel_dp_to_dev(intel_dp);
-       struct drm_i915_private *dev_priv = to_i915(dev);
+       struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
        enum port port = dp_to_dig_port(intel_dp)->port;
 
-       if (IS_BROXTON(dev_priv))
+       if (IS_GEN9_LP(dev_priv))
                return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
-       else if (INTEL_INFO(dev)->gen >= 9) {
+       else if (INTEL_GEN(dev_priv) >= 9) {
                if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
                        return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
                return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
@@ -3494,6 +3560,12 @@ intel_dp_link_down(struct intel_dp *intel_dp)
        msleep(intel_dp->panel_power_down_delay);
 
        intel_dp->DP = DP;
+
+       if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
+               pps_lock(intel_dp);
+               intel_dp->active_pipe = INVALID_PIPE;
+               pps_unlock(intel_dp);
+       }
 }
 
 bool
@@ -3572,7 +3644,12 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
                        if (val == 0)
                                break;
 
-                       /* Value read is in kHz while drm clock is saved in deca-kHz */
+                       /* Value read multiplied by 200kHz gives the per-lane
+                        * link rate in kHz. The source rates are, however,
+                        * stored in terms of LS_Clk kHz. The full conversion
+                        * back to symbols is
+                        * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
+                        */
                        intel_dp->sink_rates[i] = (val * 200) / 10;
                }
                intel_dp->num_sink_rates = i;
@@ -3838,7 +3915,7 @@ static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
                        DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
                                      intel_dp->aux.i2c_nack_count,
                                      intel_dp->aux.i2c_defer_count);
-               intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
+               intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
        } else {
                struct edid *block = intel_connector->detect_edid;
 
@@ -3854,11 +3931,11 @@ static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
                        DRM_DEBUG_KMS("Failed to write EDID checksum\n");
 
                test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
-               intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
+               intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_STANDARD;
        }
 
        /* Set test active flag here so userspace doesn't interrupt things */
-       intel_dp->compliance_test_active = 1;
+       intel_dp->compliance.test_active = 1;
 
        return test_result;
 }
@@ -3884,22 +3961,22 @@ static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
        switch (rxdata) {
        case DP_TEST_LINK_TRAINING:
                DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
-               intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
+               intel_dp->compliance.test_type = DP_TEST_LINK_TRAINING;
                response = intel_dp_autotest_link_training(intel_dp);
                break;
        case DP_TEST_LINK_VIDEO_PATTERN:
                DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
-               intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
+               intel_dp->compliance.test_type = DP_TEST_LINK_VIDEO_PATTERN;
                response = intel_dp_autotest_video_pattern(intel_dp);
                break;
        case DP_TEST_LINK_EDID_READ:
                DRM_DEBUG_KMS("EDID test requested\n");
-               intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
+               intel_dp->compliance.test_type = DP_TEST_LINK_EDID_READ;
                response = intel_dp_autotest_edid(intel_dp);
                break;
        case DP_TEST_LINK_PHY_TEST_PATTERN:
                DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
-               intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
+               intel_dp->compliance.test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
                response = intel_dp_autotest_phy_pattern(intel_dp);
                break;
        default:
@@ -4018,12 +4095,12 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
                return;
 
        /* FIXME: we need to synchronize this sort of stuff with hardware
-        * readout */
-       if (WARN_ON_ONCE(!intel_dp->lane_count))
+        * readout. Currently fast link training doesn't work on boot-up. */
+       if (!intel_dp->lane_count)
                return;
 
        /* if link training is requested we should perform it always */
-       if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
+       if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
            (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
                DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
                              intel_encoder->base.name);
@@ -4057,9 +4134,7 @@ intel_dp_short_pulse(struct intel_dp *intel_dp)
         * Clearing compliance test variables to allow capturing
         * of values for next automated test request.
         */
-       intel_dp->compliance_test_active = 0;
-       intel_dp->compliance_test_type = 0;
-       intel_dp->compliance_test_data = 0;
+       memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
 
        /*
         * Now read the DPCD to see if it's actually running
@@ -4151,9 +4226,10 @@ static enum drm_connector_status
 edp_detect(struct intel_dp *intel_dp)
 {
        struct drm_device *dev = intel_dp_to_dev(intel_dp);
+       struct drm_i915_private *dev_priv = to_i915(dev);
        enum drm_connector_status status;
 
-       status = intel_panel_detect(dev);
+       status = intel_panel_detect(dev_priv);
        if (status == connector_status_unknown)
                status = connector_status_connected;
 
@@ -4299,7 +4375,7 @@ static bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
                return ibx_digital_port_connected(dev_priv, port);
        else if (HAS_PCH_SPLIT(dev_priv))
                return cpt_digital_port_connected(dev_priv, port);
-       else if (IS_BROXTON(dev_priv))
+       else if (IS_GEN9_LP(dev_priv))
                return bxt_digital_port_connected(dev_priv, port);
        else if (IS_GM45(dev_priv))
                return gm45_digital_port_connected(dev_priv, port);
@@ -4376,9 +4452,7 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
                status = connector_status_disconnected;
 
        if (status == connector_status_disconnected) {
-               intel_dp->compliance_test_active = 0;
-               intel_dp->compliance_test_type = 0;
-               intel_dp->compliance_test_data = 0;
+               memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
 
                if (intel_dp->is_mst) {
                        DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
@@ -4399,6 +4473,12 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
                      yesno(intel_dp_source_supports_hbr2(intel_dp)),
                      yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
 
+       /* Set the max lane count for sink */
+       intel_dp->max_sink_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);
+
+       /* Set the max link BW for sink */
+       intel_dp->max_sink_link_bw = intel_dp_max_link_bw(intel_dp);
+
        intel_dp_print_rates(intel_dp);
 
        intel_dp_read_desc(intel_dp);
@@ -4754,27 +4834,41 @@ static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
        edp_panel_vdd_schedule_off(intel_dp);
 }
 
+static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
+{
+       struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
+
+       if ((intel_dp->DP & DP_PORT_EN) == 0)
+               return INVALID_PIPE;
+
+       if (IS_CHERRYVIEW(dev_priv))
+               return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
+       else
+               return PORT_TO_PIPE(intel_dp->DP);
+}
+
 void intel_dp_encoder_reset(struct drm_encoder *encoder)
 {
        struct drm_i915_private *dev_priv = to_i915(encoder->dev);
-       struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
-       struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
-       struct intel_dp *intel_dp = &intel_dig_port->dp;
+       struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+       struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
 
        if (!HAS_DDI(dev_priv))
                intel_dp->DP = I915_READ(intel_dp->output_reg);
 
-       if (IS_GEN9(dev_priv) && lspcon->active)
+       if (lspcon->active)
                lspcon_resume(lspcon);
 
-       if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
-               return;
-
        pps_lock(intel_dp);
 
-       /* Reinit the power sequencer, in case BIOS did something with it. */
-       intel_dp_pps_init(encoder->dev, intel_dp);
-       intel_edp_panel_vdd_sanitize(intel_dp);
+       if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
+               intel_dp->active_pipe = vlv_active_pipe(intel_dp);
+
+       if (is_edp(intel_dp)) {
+               /* Reinit the power sequencer, in case BIOS did something with it. */
+               intel_dp_pps_init(encoder->dev, intel_dp);
+               intel_edp_panel_vdd_sanitize(intel_dp);
+       }
 
        pps_unlock(intel_dp);
 }
@@ -4873,18 +4967,16 @@ put_power:
 }
 
 /* check the VBT to see whether the eDP is on another port */
-bool intel_dp_is_edp(struct drm_device *dev, enum port port)
+bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
 {
-       struct drm_i915_private *dev_priv = to_i915(dev);
-
        /*
         * eDP not supported on g4x. so bail out early just
         * for a bit extra safety in case the VBT is bonkers.
         */
-       if (INTEL_INFO(dev)->gen < 5)
+       if (INTEL_GEN(dev_priv) < 5)
                return false;
 
-       if (port == PORT_A)
+       if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
                return true;
 
        return intel_bios_is_port_edp(dev_priv, port);
@@ -4931,7 +5023,7 @@ intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
 
        pp_on = I915_READ(regs.pp_on);
        pp_off = I915_READ(regs.pp_off);
-       if (!IS_BROXTON(dev_priv)) {
+       if (!IS_GEN9_LP(dev_priv)) {
                I915_WRITE(regs.pp_ctrl, pp_ctl);
                pp_div = I915_READ(regs.pp_div);
        }
@@ -4949,7 +5041,7 @@ intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
        seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
                   PANEL_POWER_DOWN_DELAY_SHIFT;
 
-       if (IS_BROXTON(dev_priv)) {
+       if (IS_GEN9_LP(dev_priv)) {
                u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
                        BXT_POWER_CYCLE_DELAY_SHIFT;
                if (tmp > 0)
@@ -5061,7 +5153,8 @@ intel_dp_init_panel_power_sequencer(struct drm_device *dev,
 
 static void
 intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
-                                             struct intel_dp *intel_dp)
+                                             struct intel_dp *intel_dp,
+                                             bool force_disable_vdd)
 {
        struct drm_i915_private *dev_priv = to_i915(dev);
        u32 pp_on, pp_off, pp_div, port_sel = 0;
@@ -5074,13 +5167,38 @@ intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
 
        intel_pps_get_registers(dev_priv, intel_dp, &regs);
 
+       /*
+        * On some VLV machines the BIOS can leave the VDD
+        * enabled even on power seqeuencers which aren't
+        * hooked up to any port. This would mess up the
+        * power domain tracking the first time we pick
+        * one of these power sequencers for use since
+        * edp_panel_vdd_on() would notice that the VDD was
+        * already on and therefore wouldn't grab the power
+        * domain reference. Disable VDD first to avoid this.
+        * This also avoids spuriously turning the VDD on as
+        * soon as the new power seqeuencer gets initialized.
+        */
+       if (force_disable_vdd) {
+               u32 pp = ironlake_get_pp_control(intel_dp);
+
+               WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
+
+               if (pp & EDP_FORCE_VDD)
+                       DRM_DEBUG_KMS("VDD already on, disabling first\n");
+
+               pp &= ~EDP_FORCE_VDD;
+
+               I915_WRITE(regs.pp_ctrl, pp);
+       }
+
        pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
                (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
        pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
                 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
        /* Compute the divisor for the pp clock, simply match the Bspec
         * formula. */
-       if (IS_BROXTON(dev_priv)) {
+       if (IS_GEN9_LP(dev_priv)) {
                pp_div = I915_READ(regs.pp_ctrl);
                pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
                pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
@@ -5106,7 +5224,7 @@ intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
 
        I915_WRITE(regs.pp_on, pp_on);
        I915_WRITE(regs.pp_off, pp_off);
-       if (IS_BROXTON(dev_priv))
+       if (IS_GEN9_LP(dev_priv))
                I915_WRITE(regs.pp_ctrl, pp_div);
        else
                I915_WRITE(regs.pp_div, pp_div);
@@ -5114,7 +5232,7 @@ intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
        DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
                      I915_READ(regs.pp_on),
                      I915_READ(regs.pp_off),
-                     IS_BROXTON(dev_priv) ?
+                     IS_GEN9_LP(dev_priv) ?
                      (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
                      I915_READ(regs.pp_div));
 }
@@ -5128,7 +5246,7 @@ static void intel_dp_pps_init(struct drm_device *dev,
                vlv_initial_power_sequencer_setup(intel_dp);
        } else {
                intel_dp_init_panel_power_sequencer(dev, intel_dp);
-               intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
+               intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
        }
 }
 
@@ -5483,7 +5601,7 @@ intel_dp_drrs_init(struct intel_connector *intel_connector,
        INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
        mutex_init(&dev_priv->drrs.mutex);
 
-       if (INTEL_INFO(dev)->gen <= 6) {
+       if (INTEL_GEN(dev_priv) <= 6) {
                DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
                return NULL;
        }
@@ -5494,7 +5612,7 @@ intel_dp_drrs_init(struct intel_connector *intel_connector,
        }
 
        downclock_mode = intel_find_panel_downclock
-                                       (dev, fixed_mode, connector);
+                                       (dev_priv, fixed_mode, connector);
 
        if (!downclock_mode) {
                DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
@@ -5603,10 +5721,7 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
                 * If the current pipe isn't valid, try the PPS pipe, and if that
                 * fails just assume pipe A.
                 */
-               if (IS_CHERRYVIEW(dev_priv))
-                       pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
-               else
-                       pipe = PORT_TO_PIPE(intel_dp->DP);
+               pipe = vlv_active_pipe(intel_dp);
 
                if (pipe != PIPE_A && pipe != PIPE_B)
                        pipe = intel_dp->pps_pipe;
@@ -5655,9 +5770,10 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
                return false;
 
        intel_dp->pps_pipe = INVALID_PIPE;
+       intel_dp->active_pipe = INVALID_PIPE;
 
        /* intel_dp vfuncs */
-       if (INTEL_INFO(dev)->gen >= 9)
+       if (INTEL_GEN(dev_priv) >= 9)
                intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
        else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
                intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
@@ -5666,7 +5782,7 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
        else
                intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
 
-       if (INTEL_INFO(dev)->gen >= 9)
+       if (INTEL_GEN(dev_priv) >= 9)
                intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
        else
                intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
@@ -5678,11 +5794,14 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
        intel_dp->DP = I915_READ(intel_dp->output_reg);
        intel_dp->attached_connector = intel_connector;
 
-       if (intel_dp_is_edp(dev, port))
+       if (intel_dp_is_edp(dev_priv, port))
                type = DRM_MODE_CONNECTOR_eDP;
        else
                type = DRM_MODE_CONNECTOR_DisplayPort;
 
+       if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
+               intel_dp->active_pipe = vlv_active_pipe(intel_dp);
+
        /*
         * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
         * for DP the encoder type can be set by the caller to
@@ -5742,7 +5861,7 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
        }
 
        /* init MST on ports that can support it */
-       if (HAS_DP_MST(dev) && !is_edp(intel_dp) &&
+       if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
            (port == PORT_B || port == PORT_C || port == PORT_D))
                intel_dp_mst_encoder_init(intel_dig_port,
                                          intel_connector->base.base.id);
@@ -5772,11 +5891,10 @@ fail:
        return false;
 }
 
-bool intel_dp_init(struct drm_device *dev,
+bool intel_dp_init(struct drm_i915_private *dev_priv,
                   i915_reg_t output_reg,
                   enum port port)
 {
-       struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_digital_port *intel_dig_port;
        struct intel_encoder *intel_encoder;
        struct drm_encoder *encoder;
@@ -5793,8 +5911,9 @@ bool intel_dp_init(struct drm_device *dev,
        intel_encoder = &intel_dig_port->base;
        encoder = &intel_encoder->base;
 
-       if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
-                            DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
+       if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
+                            &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
+                            "DP %c", port_name(port)))
                goto err_encoder_init;
 
        intel_encoder->compute_config = intel_dp_compute_config;
@@ -5816,7 +5935,7 @@ bool intel_dp_init(struct drm_device *dev,
        } else {
                intel_encoder->pre_enable = g4x_pre_enable_dp;
                intel_encoder->enable = g4x_enable_dp;
-               if (INTEL_INFO(dev)->gen >= 5)
+               if (INTEL_GEN(dev_priv) >= 5)
                        intel_encoder->post_disable = ilk_post_disable_dp;
        }