drm: extract dp link bw helpers
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_dp.c
index d1e8ddb2d6c0801e42a25c30e1eb66c29fb80150..f7b7bfc455e2b33143651e40da32128585e1a8df 100644 (file)
@@ -36,8 +36,6 @@
 #include <drm/i915_drm.h>
 #include "i915_drv.h"
 
-#define DP_RECEIVER_CAP_SIZE   0xf
-#define DP_LINK_STATUS_SIZE    6
 #define DP_LINK_CHECK_TIMEOUT  (10 * 1000)
 
 /**
@@ -76,11 +74,6 @@ static bool is_cpu_edp(struct intel_dp *intel_dp)
        return is_edp(intel_dp) && !is_pch_edp(intel_dp);
 }
 
-static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
-{
-       return container_of(encoder, struct intel_dp, base.base);
-}
-
 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
 {
        return container_of(intel_attached_encoder(connector),
@@ -106,8 +99,6 @@ bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
        return is_pch_edp(intel_dp);
 }
 
-static void intel_dp_start_link_train(struct intel_dp *intel_dp);
-static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
 static void intel_dp_link_down(struct intel_dp *intel_dp);
 
 void
@@ -117,10 +108,7 @@ intel_edp_link_config(struct intel_encoder *intel_encoder,
        struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
 
        *lane_num = intel_dp->lane_count;
-       if (intel_dp->link_bw == DP_LINK_BW_1_62)
-               *link_bw = 162000;
-       else if (intel_dp->link_bw == DP_LINK_BW_2_7)
-               *link_bw = 270000;
+       *link_bw = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
 }
 
 int
@@ -128,9 +116,10 @@ intel_edp_target_clock(struct intel_encoder *intel_encoder,
                       struct drm_display_mode *mode)
 {
        struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
+       struct intel_connector *intel_connector = intel_dp->attached_connector;
 
-       if (intel_dp->panel_fixed_mode)
-               return intel_dp->panel_fixed_mode->clock;
+       if (intel_connector->panel.fixed_mode)
+               return intel_connector->panel.fixed_mode->clock;
        else
                return mode->clock;
 }
@@ -234,12 +223,14 @@ intel_dp_mode_valid(struct drm_connector *connector,
                    struct drm_display_mode *mode)
 {
        struct intel_dp *intel_dp = intel_attached_dp(connector);
+       struct intel_connector *intel_connector = to_intel_connector(connector);
+       struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
 
-       if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
-               if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
+       if (is_edp(intel_dp) && fixed_mode) {
+               if (mode->hdisplay > fixed_mode->hdisplay)
                        return MODE_PANEL;
 
-               if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay)
+               if (mode->vdisplay > fixed_mode->vdisplay)
                        return MODE_PANEL;
        }
 
@@ -285,6 +276,10 @@ intel_hrawclk(struct drm_device *dev)
        struct drm_i915_private *dev_priv = dev->dev_private;
        uint32_t clkcfg;
 
+       /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
+       if (IS_VALLEYVIEW(dev))
+               return 200;
+
        clkcfg = I915_READ(CLKCFG);
        switch (clkcfg & CLKCFG_FSB_MASK) {
        case CLKCFG_FSB_400:
@@ -356,6 +351,29 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
        uint32_t aux_clock_divider;
        int try, precharge;
 
+       if (IS_HASWELL(dev)) {
+               switch (intel_dp->port) {
+               case PORT_A:
+                       ch_ctl = DPA_AUX_CH_CTL;
+                       ch_data = DPA_AUX_CH_DATA1;
+                       break;
+               case PORT_B:
+                       ch_ctl = PCH_DPB_AUX_CH_CTL;
+                       ch_data = PCH_DPB_AUX_CH_DATA1;
+                       break;
+               case PORT_C:
+                       ch_ctl = PCH_DPC_AUX_CH_CTL;
+                       ch_data = PCH_DPC_AUX_CH_DATA1;
+                       break;
+               case PORT_D:
+                       ch_ctl = PCH_DPD_AUX_CH_CTL;
+                       ch_data = PCH_DPD_AUX_CH_DATA1;
+                       break;
+               default:
+                       BUG();
+               }
+       }
+
        intel_dp_check_edp(intel_dp);
        /* The clock divider is based off the hrawclk,
         * and would like to run at 2MHz. So, take the
@@ -365,7 +383,9 @@ intel_dp_aux_ch(struct intel_dp *intel_dp,
         * clock divider.
         */
        if (is_cpu_edp(intel_dp)) {
-               if (IS_GEN6(dev) || IS_GEN7(dev))
+               if (IS_VALLEYVIEW(dev))
+                       aux_clock_divider = 100;
+               else if (IS_GEN6(dev) || IS_GEN7(dev))
                        aux_clock_divider = 200; /* SNB & IVB eDP input clock at 400Mhz */
                else
                        aux_clock_divider = 225; /* eDP input clock at 450Mhz */
@@ -677,14 +697,16 @@ intel_dp_mode_fixup(struct drm_encoder *encoder,
 {
        struct drm_device *dev = encoder->dev;
        struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
+       struct intel_connector *intel_connector = intel_dp->attached_connector;
        int lane_count, clock;
        int max_lane_count = intel_dp_max_lane_count(intel_dp);
        int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
        int bpp, mode_rate;
        static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
 
-       if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
-               intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode);
+       if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
+               intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
+                                      adjusted_mode);
                intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
                                        mode, adjusted_mode);
        }
@@ -791,23 +813,45 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
        intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
                             mode->clock, adjusted_mode->clock, &m_n);
 
-       if (HAS_PCH_SPLIT(dev)) {
-               I915_WRITE(TRANSDATA_M1(pipe),
-                          ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
-                          m_n.gmch_m);
+       if (IS_HASWELL(dev)) {
+               I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
+               I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
+               I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
+               I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
+       } else if (HAS_PCH_SPLIT(dev)) {
+               I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
                I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
                I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
                I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
+       } else if (IS_VALLEYVIEW(dev)) {
+               I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
+               I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
+               I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
+               I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
        } else {
                I915_WRITE(PIPE_GMCH_DATA_M(pipe),
-                          ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
-                          m_n.gmch_m);
+                          TU_SIZE(m_n.tu) | m_n.gmch_m);
                I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
                I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
                I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
        }
 }
 
+void intel_dp_init_link_config(struct intel_dp *intel_dp)
+{
+       memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
+       intel_dp->link_configuration[0] = intel_dp->link_bw;
+       intel_dp->link_configuration[1] = intel_dp->lane_count;
+       intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
+       /*
+        * Check for DPCD version > 1.1 and enhanced framing support
+        */
+       if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
+           (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
+               intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
+       }
+}
+
 static void
 intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
                  struct drm_display_mode *adjusted_mode)
@@ -860,21 +904,12 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
                intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
                intel_write_eld(encoder, adjusted_mode);
        }
-       memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
-       intel_dp->link_configuration[0] = intel_dp->link_bw;
-       intel_dp->link_configuration[1] = intel_dp->lane_count;
-       intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
-       /*
-        * Check for DPCD version > 1.1 and enhanced framing support
-        */
-       if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
-           (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
-               intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
-       }
+
+       intel_dp_init_link_config(intel_dp);
 
        /* Split out the IBX/CPU vs CPT settings */
 
-       if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
+       if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
                if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
                        intel_dp->DP |= DP_SYNC_HS_HIGH;
                if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
@@ -1228,7 +1263,7 @@ static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
 }
 
 /* If the sink supports it, try to set the power state appropriately */
-static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
+void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
 {
        int ret, i;
 
@@ -1396,38 +1431,6 @@ intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_
                                              DP_LINK_STATUS_SIZE);
 }
 
-static uint8_t
-intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
-                    int r)
-{
-       return link_status[r - DP_LANE0_1_STATUS];
-}
-
-static uint8_t
-intel_get_adjust_request_voltage(uint8_t adjust_request[2],
-                                int lane)
-{
-       int         s = ((lane & 1) ?
-                        DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
-                        DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
-       uint8_t l = adjust_request[lane>>1];
-
-       return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
-}
-
-static uint8_t
-intel_get_adjust_request_pre_emphasis(uint8_t adjust_request[2],
-                                     int lane)
-{
-       int         s = ((lane & 1) ?
-                        DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
-                        DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
-       uint8_t l = adjust_request[lane>>1];
-
-       return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
-}
-
-
 #if 0
 static char    *voltage_names[] = {
        "0.4V", "0.6V", "0.8V", "1.2V"
@@ -1463,7 +1466,19 @@ intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
 {
        struct drm_device *dev = intel_dp->base.base.dev;
 
-       if (IS_GEN7(dev) && is_cpu_edp(intel_dp)) {
+       if (IS_HASWELL(dev)) {
+               switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
+               case DP_TRAIN_VOLTAGE_SWING_400:
+                       return DP_TRAIN_PRE_EMPHASIS_9_5;
+               case DP_TRAIN_VOLTAGE_SWING_600:
+                       return DP_TRAIN_PRE_EMPHASIS_6;
+               case DP_TRAIN_VOLTAGE_SWING_800:
+                       return DP_TRAIN_PRE_EMPHASIS_3_5;
+               case DP_TRAIN_VOLTAGE_SWING_1200:
+               default:
+                       return DP_TRAIN_PRE_EMPHASIS_0;
+               }
+       } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
                switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
                case DP_TRAIN_VOLTAGE_SWING_400:
                        return DP_TRAIN_PRE_EMPHASIS_6;
@@ -1494,13 +1509,12 @@ intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_ST
        uint8_t v = 0;
        uint8_t p = 0;
        int lane;
-       uint8_t *adjust_request = link_status + (DP_ADJUST_REQUEST_LANE0_1 - DP_LANE0_1_STATUS);
        uint8_t voltage_max;
        uint8_t preemph_max;
 
        for (lane = 0; lane < intel_dp->lane_count; lane++) {
-               uint8_t this_v = intel_get_adjust_request_voltage(adjust_request, lane);
-               uint8_t this_p = intel_get_adjust_request_pre_emphasis(adjust_request, lane);
+               uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
+               uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
 
                if (this_v > v)
                        v = this_v;
@@ -1617,52 +1631,38 @@ intel_gen7_edp_signal_levels(uint8_t train_set)
        }
 }
 
-static uint8_t
-intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
-                     int lane)
-{
-       int s = (lane & 1) * 4;
-       uint8_t l = link_status[lane>>1];
-
-       return (l >> s) & 0xf;
-}
-
-/* Check for clock recovery is done on all channels */
-static bool
-intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
+/* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
+static uint32_t
+intel_dp_signal_levels_hsw(uint8_t train_set)
 {
-       int lane;
-       uint8_t lane_status;
-
-       for (lane = 0; lane < lane_count; lane++) {
-               lane_status = intel_get_lane_status(link_status, lane);
-               if ((lane_status & DP_LANE_CR_DONE) == 0)
-                       return false;
-       }
-       return true;
-}
+       int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
+                                        DP_TRAIN_PRE_EMPHASIS_MASK);
+       switch (signal_levels) {
+       case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
+               return DDI_BUF_EMP_400MV_0DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
+               return DDI_BUF_EMP_400MV_3_5DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
+               return DDI_BUF_EMP_400MV_6DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
+               return DDI_BUF_EMP_400MV_9_5DB_HSW;
 
-/* Check to see if channel eq is done on all channels */
-#define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
-                        DP_LANE_CHANNEL_EQ_DONE|\
-                        DP_LANE_SYMBOL_LOCKED)
-static bool
-intel_channel_eq_ok(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
-{
-       uint8_t lane_align;
-       uint8_t lane_status;
-       int lane;
+       case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
+               return DDI_BUF_EMP_600MV_0DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
+               return DDI_BUF_EMP_600MV_3_5DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
+               return DDI_BUF_EMP_600MV_6DB_HSW;
 
-       lane_align = intel_dp_link_status(link_status,
-                                         DP_LANE_ALIGN_STATUS_UPDATED);
-       if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
-               return false;
-       for (lane = 0; lane < intel_dp->lane_count; lane++) {
-               lane_status = intel_get_lane_status(link_status, lane);
-               if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
-                       return false;
+       case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
+               return DDI_BUF_EMP_800MV_0DB_HSW;
+       case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
+               return DDI_BUF_EMP_800MV_3_5DB_HSW;
+       default:
+               DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
+                             "0x%x\n", signal_levels);
+               return DDI_BUF_EMP_400MV_0DB_HSW;
        }
-       return true;
 }
 
 static bool
@@ -1673,8 +1673,44 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
        struct drm_device *dev = intel_dp->base.base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        int ret;
+       uint32_t temp;
 
-       if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
+       if (IS_HASWELL(dev)) {
+               temp = I915_READ(DP_TP_CTL(intel_dp->port));
+
+               if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
+                       temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
+               else
+                       temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
+
+               temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
+               switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
+               case DP_TRAINING_PATTERN_DISABLE:
+                       temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
+                       I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
+
+                       if (wait_for((I915_READ(DP_TP_STATUS(intel_dp->port)) &
+                                     DP_TP_STATUS_IDLE_DONE), 1))
+                               DRM_ERROR("Timed out waiting for DP idle patterns\n");
+
+                       temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
+                       temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
+
+                       break;
+               case DP_TRAINING_PATTERN_1:
+                       temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
+                       break;
+               case DP_TRAINING_PATTERN_2:
+                       temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
+                       break;
+               case DP_TRAINING_PATTERN_3:
+                       temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
+                       break;
+               }
+               I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
+
+       } else if (HAS_PCH_CPT(dev) &&
+                  (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
                dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
 
                switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
@@ -1734,16 +1770,20 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
 }
 
 /* Enable corresponding port and start training pattern 1 */
-static void
+void
 intel_dp_start_link_train(struct intel_dp *intel_dp)
 {
-       struct drm_device *dev = intel_dp->base.base.dev;
+       struct drm_encoder *encoder = &intel_dp->base.base;
+       struct drm_device *dev = encoder->dev;
        int i;
        uint8_t voltage;
        bool clock_recovery = false;
        int voltage_tries, loop_tries;
        uint32_t DP = intel_dp->DP;
 
+       if (IS_HASWELL(dev))
+               intel_ddi_prepare_link_retrain(encoder);
+
        /* Write the link configuration data */
        intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
                                  intel_dp->link_configuration,
@@ -1761,8 +1801,11 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
                uint8_t     link_status[DP_LINK_STATUS_SIZE];
                uint32_t    signal_levels;
 
-
-               if (IS_GEN7(dev) && is_cpu_edp(intel_dp)) {
+               if (IS_HASWELL(dev)) {
+                       signal_levels = intel_dp_signal_levels_hsw(
+                                                       intel_dp->train_set[0]);
+                       DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
+               } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
                        signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
                        DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
                } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
@@ -1770,23 +1813,24 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
                        DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
                } else {
                        signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
-                       DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n", signal_levels);
                        DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
                }
+               DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n",
+                             signal_levels);
 
+               /* Set training pattern 1 */
                if (!intel_dp_set_link_train(intel_dp, DP,
                                             DP_TRAINING_PATTERN_1 |
                                             DP_LINK_SCRAMBLING_DISABLE))
                        break;
-               /* Set training pattern 1 */
 
-               udelay(100);
+               drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
                if (!intel_dp_get_link_status(intel_dp, link_status)) {
                        DRM_ERROR("failed to get link status\n");
                        break;
                }
 
-               if (intel_clock_recovery_ok(link_status, intel_dp->lane_count)) {
+               if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
                        DRM_DEBUG_KMS("clock recovery OK\n");
                        clock_recovery = true;
                        break;
@@ -1820,7 +1864,7 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
        intel_dp->DP = DP;
 }
 
-static void
+void
 intel_dp_complete_link_train(struct intel_dp *intel_dp)
 {
        struct drm_device *dev = intel_dp->base.base.dev;
@@ -1843,7 +1887,10 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
                        break;
                }
 
-               if (IS_GEN7(dev) && is_cpu_edp(intel_dp)) {
+               if (IS_HASWELL(dev)) {
+                       signal_levels = intel_dp_signal_levels_hsw(intel_dp->train_set[0]);
+                       DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
+               } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
                        signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
                        DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
                } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
@@ -1860,18 +1907,18 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
                                             DP_LINK_SCRAMBLING_DISABLE))
                        break;
 
-               udelay(400);
+               drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
                if (!intel_dp_get_link_status(intel_dp, link_status))
                        break;
 
                /* Make sure clock is still ok */
-               if (!intel_clock_recovery_ok(link_status, intel_dp->lane_count)) {
+               if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
                        intel_dp_start_link_train(intel_dp);
                        cr_tries++;
                        continue;
                }
 
-               if (intel_channel_eq_ok(intel_dp, link_status)) {
+               if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
                        channel_eq = true;
                        break;
                }
@@ -1890,6 +1937,9 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
                ++tries;
        }
 
+       if (channel_eq)
+               DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
+
        intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
 }
 
@@ -1900,6 +1950,24 @@ intel_dp_link_down(struct intel_dp *intel_dp)
        struct drm_i915_private *dev_priv = dev->dev_private;
        uint32_t DP = intel_dp->DP;
 
+       /*
+        * DDI code has a strict mode set sequence and we should try to respect
+        * it, otherwise we might hang the machine in many different ways. So we
+        * really should be disabling the port only on a complete crtc_disable
+        * sequence. This function is just called under two conditions on DDI
+        * code:
+        * - Link train failed while doing crtc_enable, and on this case we
+        *   really should respect the mode set sequence and wait for a
+        *   crtc_disable.
+        * - Someone turned the monitor off and intel_dp_check_link_status
+        *   called us. We don't need to disable the whole port on this case, so
+        *   when someone turns the monitor on again,
+        *   intel_ddi_prepare_link_retrain will take care of redoing the link
+        *   train.
+        */
+       if (IS_HASWELL(dev))
+               return;
+
        if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
                return;
 
@@ -2069,7 +2137,7 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
                        DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
        }
 
-       if (!intel_channel_eq_ok(intel_dp, link_status)) {
+       if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
                DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
                              drm_get_encoder_name(&intel_dp->base.base));
                intel_dp_start_link_train(intel_dp);
@@ -2163,44 +2231,45 @@ g4x_dp_detect(struct intel_dp *intel_dp)
 static struct edid *
 intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 {
-       struct intel_dp *intel_dp = intel_attached_dp(connector);
-       struct edid     *edid;
-       int size;
+       struct intel_connector *intel_connector = to_intel_connector(connector);
 
-       if (is_edp(intel_dp)) {
-               if (!intel_dp->edid)
+       /* use cached edid if we have one */
+       if (intel_connector->edid) {
+               struct edid *edid;
+               int size;
+
+               /* invalid edid */
+               if (IS_ERR(intel_connector->edid))
                        return NULL;
 
-               size = (intel_dp->edid->extensions + 1) * EDID_LENGTH;
+               size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
                edid = kmalloc(size, GFP_KERNEL);
                if (!edid)
                        return NULL;
 
-               memcpy(edid, intel_dp->edid, size);
+               memcpy(edid, intel_connector->edid, size);
                return edid;
        }
 
-       edid = drm_get_edid(connector, adapter);
-       return edid;
+       return drm_get_edid(connector, adapter);
 }
 
 static int
 intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
 {
-       struct intel_dp *intel_dp = intel_attached_dp(connector);
-       int     ret;
+       struct intel_connector *intel_connector = to_intel_connector(connector);
 
-       if (is_edp(intel_dp)) {
-               drm_mode_connector_update_edid_property(connector,
-                                                       intel_dp->edid);
-               ret = drm_add_edid_modes(connector, intel_dp->edid);
-               drm_edid_to_eld(connector,
-                               intel_dp->edid);
-               return intel_dp->edid_mode_count;
+       /* use cached edid if we have one */
+       if (intel_connector->edid) {
+               /* invalid edid */
+               if (IS_ERR(intel_connector->edid))
+                       return 0;
+
+               return intel_connector_update_modes(connector,
+                                                   intel_connector->edid);
        }
 
-       ret = intel_ddc_get_modes(connector, adapter);
-       return ret;
+       return intel_ddc_get_modes(connector, adapter);
 }
 
 
@@ -2251,43 +2320,23 @@ intel_dp_detect(struct drm_connector *connector, bool force)
 static int intel_dp_get_modes(struct drm_connector *connector)
 {
        struct intel_dp *intel_dp = intel_attached_dp(connector);
+       struct intel_connector *intel_connector = to_intel_connector(connector);
        struct drm_device *dev = intel_dp->base.base.dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
        int ret;
 
        /* We should parse the EDID data and find out if it has an audio sink
         */
 
        ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
-       if (ret) {
-               if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) {
-                       struct drm_display_mode *newmode;
-                       list_for_each_entry(newmode, &connector->probed_modes,
-                                           head) {
-                               if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) {
-                                       intel_dp->panel_fixed_mode =
-                                               drm_mode_duplicate(dev, newmode);
-                                       break;
-                               }
-                       }
-               }
+       if (ret)
                return ret;
-       }
 
-       /* if eDP has no EDID, try to use fixed panel mode from VBT */
-       if (is_edp(intel_dp)) {
-               /* initialize panel mode from VBT if available for eDP */
-               if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) {
-                       intel_dp->panel_fixed_mode =
-                               drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
-                       if (intel_dp->panel_fixed_mode) {
-                               intel_dp->panel_fixed_mode->type |=
-                                       DRM_MODE_TYPE_PREFERRED;
-                       }
-               }
-               if (intel_dp->panel_fixed_mode) {
-                       struct drm_display_mode *mode;
-                       mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode);
+       /* if eDP has no EDID, fall back to fixed mode */
+       if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
+               struct drm_display_mode *mode;
+               mode = drm_mode_duplicate(dev,
+                                         intel_connector->panel.fixed_mode);
+               if (mode) {
                        drm_mode_probed_add(connector, mode);
                        return 1;
                }
@@ -2369,9 +2418,16 @@ static void
 intel_dp_destroy(struct drm_connector *connector)
 {
        struct drm_device *dev = connector->dev;
+       struct intel_dp *intel_dp = intel_attached_dp(connector);
+       struct intel_connector *intel_connector = to_intel_connector(connector);
+
+       if (!IS_ERR_OR_NULL(intel_connector->edid))
+               kfree(intel_connector->edid);
 
-       if (intel_dpd_is_edp(dev))
+       if (is_edp(intel_dp)) {
                intel_panel_destroy_backlight(dev);
+               intel_panel_fini(&intel_connector->panel);
+       }
 
        drm_sysfs_connector_remove(connector);
        drm_connector_cleanup(connector);
@@ -2385,7 +2441,6 @@ static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
        i2c_del_adapter(&intel_dp->adapter);
        drm_encoder_cleanup(encoder);
        if (is_edp(intel_dp)) {
-               kfree(intel_dp->edid);
                cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
                ironlake_panel_vdd_off_sync(intel_dp);
        }
@@ -2398,6 +2453,12 @@ static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
        .disable = intel_encoder_noop,
 };
 
+static const struct drm_encoder_helper_funcs intel_dp_helper_funcs_hsw = {
+       .mode_fixup = intel_dp_mode_fixup,
+       .mode_set = intel_ddi_mode_set,
+       .disable = intel_encoder_noop,
+};
+
 static const struct drm_connector_funcs intel_dp_connector_funcs = {
        .dpms = intel_connector_dpms,
        .detect = intel_dp_detect,
@@ -2477,6 +2538,7 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
        struct intel_dp *intel_dp;
        struct intel_encoder *intel_encoder;
        struct intel_connector *intel_connector;
+       struct drm_display_mode *fixed_mode = NULL;
        const char *name = NULL;
        int type;
 
@@ -2495,12 +2557,20 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
                return;
        }
        intel_encoder = &intel_dp->base;
+       intel_dp->attached_connector = intel_connector;
 
        if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
                if (intel_dpd_is_edp(dev))
                        intel_dp->is_pch_edp = true;
 
-       if (output_reg == DP_A || is_pch_edp(intel_dp)) {
+       /*
+        * FIXME : We need to initialize built-in panels before external panels.
+        * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
+        */
+       if (IS_VALLEYVIEW(dev) && output_reg == DP_C) {
+               type = DRM_MODE_CONNECTOR_eDP;
+               intel_encoder->type = INTEL_OUTPUT_EDP;
+       } else if (output_reg == DP_A || is_pch_edp(intel_dp)) {
                type = DRM_MODE_CONNECTOR_eDP;
                intel_encoder->type = INTEL_OUTPUT_EDP;
        } else {
@@ -2526,16 +2596,30 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
 
        drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
                         DRM_MODE_ENCODER_TMDS);
-       drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
+
+       if (IS_HASWELL(dev))
+               drm_encoder_helper_add(&intel_encoder->base,
+                                      &intel_dp_helper_funcs_hsw);
+       else
+               drm_encoder_helper_add(&intel_encoder->base,
+                                      &intel_dp_helper_funcs);
 
        intel_connector_attach_encoder(intel_connector, intel_encoder);
        drm_sysfs_connector_add(connector);
 
-       intel_encoder->enable = intel_enable_dp;
-       intel_encoder->pre_enable = intel_pre_enable_dp;
-       intel_encoder->disable = intel_disable_dp;
-       intel_encoder->post_disable = intel_post_disable_dp;
-       intel_encoder->get_hw_state = intel_dp_get_hw_state;
+       if (IS_HASWELL(dev)) {
+               intel_encoder->enable = intel_enable_ddi;
+               intel_encoder->pre_enable = intel_ddi_pre_enable;
+               intel_encoder->disable = intel_disable_ddi;
+               intel_encoder->post_disable = intel_ddi_post_disable;
+               intel_encoder->get_hw_state = intel_ddi_get_hw_state;
+       } else {
+               intel_encoder->enable = intel_enable_dp;
+               intel_encoder->pre_enable = intel_pre_enable_dp;
+               intel_encoder->disable = intel_disable_dp;
+               intel_encoder->post_disable = intel_post_disable_dp;
+               intel_encoder->get_hw_state = intel_dp_get_hw_state;
+       }
        intel_connector->get_hw_state = intel_connector_get_hw_state;
 
        /* Set up the DDC bus. */
@@ -2620,6 +2704,7 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
 
        if (is_edp(intel_dp)) {
                bool ret;
+               struct drm_display_mode *scan;
                struct edid *edid;
 
                ironlake_edp_panel_vdd_on(intel_dp);
@@ -2642,21 +2727,41 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
                ironlake_edp_panel_vdd_on(intel_dp);
                edid = drm_get_edid(connector, &intel_dp->adapter);
                if (edid) {
-                       drm_mode_connector_update_edid_property(connector,
-                                                               edid);
-                       intel_dp->edid_mode_count =
-                               drm_add_edid_modes(connector, edid);
-                       drm_edid_to_eld(connector, edid);
-                       intel_dp->edid = edid;
+                       if (drm_add_edid_modes(connector, edid)) {
+                               drm_mode_connector_update_edid_property(connector, edid);
+                               drm_edid_to_eld(connector, edid);
+                       } else {
+                               kfree(edid);
+                               edid = ERR_PTR(-EINVAL);
+                       }
+               } else {
+                       edid = ERR_PTR(-ENOENT);
+               }
+               intel_connector->edid = edid;
+
+               /* prefer fixed mode from EDID if available */
+               list_for_each_entry(scan, &connector->probed_modes, head) {
+                       if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
+                               fixed_mode = drm_mode_duplicate(dev, scan);
+                               break;
+                       }
                }
+
+               /* fallback to VBT if available for eDP */
+               if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
+                       fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
+                       if (fixed_mode)
+                               fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
+               }
+
                ironlake_edp_panel_vdd_off(intel_dp, false);
        }
 
        intel_encoder->hot_plug = intel_dp_hot_plug;
 
        if (is_edp(intel_dp)) {
-               dev_priv->int_edp_connector = connector;
-               intel_panel_setup_backlight(dev);
+               intel_panel_init(&intel_connector->panel, fixed_mode);
+               intel_panel_setup_backlight(connector);
        }
 
        intel_dp_add_properties(intel_dp, connector);
This page took 0.041038 seconds and 5 git commands to generate.