aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_dp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/i915/intel_dp.c')
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c401
1 files changed, 194 insertions, 207 deletions
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index f1bd4f4cd667..6c8746c030c7 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -35,42 +35,10 @@
35#include "intel_drv.h" 35#include "intel_drv.h"
36#include <drm/i915_drm.h> 36#include <drm/i915_drm.h>
37#include "i915_drv.h" 37#include "i915_drv.h"
38#include <drm/drm_dp_helper.h>
39 38
40#define DP_RECEIVER_CAP_SIZE 0xf
41#define DP_LINK_STATUS_SIZE 6 39#define DP_LINK_STATUS_SIZE 6
42#define DP_LINK_CHECK_TIMEOUT (10 * 1000) 40#define DP_LINK_CHECK_TIMEOUT (10 * 1000)
43 41
44#define DP_LINK_CONFIGURATION_SIZE 9
45
46struct intel_dp {
47 struct intel_encoder base;
48 uint32_t output_reg;
49 uint32_t DP;
50 uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
51 bool has_audio;
52 enum hdmi_force_audio force_audio;
53 uint32_t color_range;
54 int dpms_mode;
55 uint8_t link_bw;
56 uint8_t lane_count;
57 uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
58 struct i2c_adapter adapter;
59 struct i2c_algo_dp_aux_data algo;
60 bool is_pch_edp;
61 uint8_t train_set[4];
62 int panel_power_up_delay;
63 int panel_power_down_delay;
64 int panel_power_cycle_delay;
65 int backlight_on_delay;
66 int backlight_off_delay;
67 struct drm_display_mode *panel_fixed_mode; /* for eDP */
68 struct delayed_work panel_vdd_work;
69 bool want_panel_vdd;
70 struct edid *edid; /* cached EDID for eDP */
71 int edid_mode_count;
72};
73
74/** 42/**
75 * is_edp - is the given port attached to an eDP panel (either CPU or PCH) 43 * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
76 * @intel_dp: DP struct 44 * @intel_dp: DP struct
@@ -839,9 +807,6 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
839 } 807 }
840} 808}
841 809
842static void ironlake_edp_pll_on(struct drm_encoder *encoder);
843static void ironlake_edp_pll_off(struct drm_encoder *encoder);
844
845static void 810static void
846intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, 811intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
847 struct drm_display_mode *adjusted_mode) 812 struct drm_display_mode *adjusted_mode)
@@ -852,14 +817,6 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
852 struct drm_crtc *crtc = intel_dp->base.base.crtc; 817 struct drm_crtc *crtc = intel_dp->base.base.crtc;
853 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 818 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
854 819
855 /* Turn on the eDP PLL if needed */
856 if (is_edp(intel_dp)) {
857 if (!is_pch_edp(intel_dp))
858 ironlake_edp_pll_on(encoder);
859 else
860 ironlake_edp_pll_off(encoder);
861 }
862
863 /* 820 /*
864 * There are four kinds of DP registers: 821 * There are four kinds of DP registers:
865 * 822 *
@@ -881,10 +838,8 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
881 * supposed to be read-only. 838 * supposed to be read-only.
882 */ 839 */
883 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED; 840 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
884 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
885 841
886 /* Handle DP bits in common between all three register formats */ 842 /* Handle DP bits in common between all three register formats */
887
888 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; 843 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
889 844
890 switch (intel_dp->lane_count) { 845 switch (intel_dp->lane_count) {
@@ -931,7 +886,6 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
931 intel_dp->DP |= intel_crtc->pipe << 29; 886 intel_dp->DP |= intel_crtc->pipe << 29;
932 887
933 /* don't miss out required setting for eDP */ 888 /* don't miss out required setting for eDP */
934 intel_dp->DP |= DP_PLL_ENABLE;
935 if (adjusted_mode->clock < 200000) 889 if (adjusted_mode->clock < 200000)
936 intel_dp->DP |= DP_PLL_FREQ_160MHZ; 890 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
937 else 891 else
@@ -953,7 +907,6 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
953 907
954 if (is_cpu_edp(intel_dp)) { 908 if (is_cpu_edp(intel_dp)) {
955 /* don't miss out required setting for eDP */ 909 /* don't miss out required setting for eDP */
956 intel_dp->DP |= DP_PLL_ENABLE;
957 if (adjusted_mode->clock < 200000) 910 if (adjusted_mode->clock < 200000)
958 intel_dp->DP |= DP_PLL_FREQ_160MHZ; 911 intel_dp->DP |= DP_PLL_FREQ_160MHZ;
959 else 912 else
@@ -1224,27 +1177,49 @@ static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
1224 msleep(intel_dp->backlight_off_delay); 1177 msleep(intel_dp->backlight_off_delay);
1225} 1178}
1226 1179
1227static void ironlake_edp_pll_on(struct drm_encoder *encoder) 1180static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
1228{ 1181{
1229 struct drm_device *dev = encoder->dev; 1182 struct drm_device *dev = intel_dp->base.base.dev;
1183 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1230 struct drm_i915_private *dev_priv = dev->dev_private; 1184 struct drm_i915_private *dev_priv = dev->dev_private;
1231 u32 dpa_ctl; 1185 u32 dpa_ctl;
1232 1186
1187 assert_pipe_disabled(dev_priv,
1188 to_intel_crtc(crtc)->pipe);
1189
1233 DRM_DEBUG_KMS("\n"); 1190 DRM_DEBUG_KMS("\n");
1234 dpa_ctl = I915_READ(DP_A); 1191 dpa_ctl = I915_READ(DP_A);
1235 dpa_ctl |= DP_PLL_ENABLE; 1192 WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
1236 I915_WRITE(DP_A, dpa_ctl); 1193 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1194
1195 /* We don't adjust intel_dp->DP while tearing down the link, to
1196 * facilitate link retraining (e.g. after hotplug). Hence clear all
1197 * enable bits here to ensure that we don't enable too much. */
1198 intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
1199 intel_dp->DP |= DP_PLL_ENABLE;
1200 I915_WRITE(DP_A, intel_dp->DP);
1237 POSTING_READ(DP_A); 1201 POSTING_READ(DP_A);
1238 udelay(200); 1202 udelay(200);
1239} 1203}
1240 1204
1241static void ironlake_edp_pll_off(struct drm_encoder *encoder) 1205static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
1242{ 1206{
1243 struct drm_device *dev = encoder->dev; 1207 struct drm_device *dev = intel_dp->base.base.dev;
1208 struct drm_crtc *crtc = intel_dp->base.base.crtc;
1244 struct drm_i915_private *dev_priv = dev->dev_private; 1209 struct drm_i915_private *dev_priv = dev->dev_private;
1245 u32 dpa_ctl; 1210 u32 dpa_ctl;
1246 1211
1212 assert_pipe_disabled(dev_priv,
1213 to_intel_crtc(crtc)->pipe);
1214
1247 dpa_ctl = I915_READ(DP_A); 1215 dpa_ctl = I915_READ(DP_A);
1216 WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
1217 "dp pll off, should be on\n");
1218 WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
1219
1220 /* We can't rely on the value tracked for the DP register in
1221 * intel_dp->DP because link_down must not change that (otherwise link
1222 * re-training will fail. */
1248 dpa_ctl &= ~DP_PLL_ENABLE; 1223 dpa_ctl &= ~DP_PLL_ENABLE;
1249 I915_WRITE(DP_A, dpa_ctl); 1224 I915_WRITE(DP_A, dpa_ctl);
1250 POSTING_READ(DP_A); 1225 POSTING_READ(DP_A);
@@ -1281,10 +1256,57 @@ static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
1281 } 1256 }
1282} 1257}
1283 1258
1284static void intel_dp_prepare(struct drm_encoder *encoder) 1259static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
1260 enum pipe *pipe)
1285{ 1261{
1286 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1262 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1263 struct drm_device *dev = encoder->base.dev;
1264 struct drm_i915_private *dev_priv = dev->dev_private;
1265 u32 tmp = I915_READ(intel_dp->output_reg);
1287 1266
1267 if (!(tmp & DP_PORT_EN))
1268 return false;
1269
1270 if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
1271 *pipe = PORT_TO_PIPE_CPT(tmp);
1272 } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
1273 *pipe = PORT_TO_PIPE(tmp);
1274 } else {
1275 u32 trans_sel;
1276 u32 trans_dp;
1277 int i;
1278
1279 switch (intel_dp->output_reg) {
1280 case PCH_DP_B:
1281 trans_sel = TRANS_DP_PORT_SEL_B;
1282 break;
1283 case PCH_DP_C:
1284 trans_sel = TRANS_DP_PORT_SEL_C;
1285 break;
1286 case PCH_DP_D:
1287 trans_sel = TRANS_DP_PORT_SEL_D;
1288 break;
1289 default:
1290 return true;
1291 }
1292
1293 for_each_pipe(i) {
1294 trans_dp = I915_READ(TRANS_DP_CTL(i));
1295 if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
1296 *pipe = i;
1297 return true;
1298 }
1299 }
1300 }
1301
1302 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", intel_dp->output_reg);
1303
1304 return true;
1305}
1306
1307static void intel_disable_dp(struct intel_encoder *encoder)
1308{
1309 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1288 1310
1289 /* Make sure the panel is off before trying to change the mode. But also 1311 /* Make sure the panel is off before trying to change the mode. But also
1290 * ensure that we have vdd while we switch off the panel. */ 1312 * ensure that we have vdd while we switch off the panel. */
@@ -1292,14 +1314,31 @@ static void intel_dp_prepare(struct drm_encoder *encoder)
1292 ironlake_edp_backlight_off(intel_dp); 1314 ironlake_edp_backlight_off(intel_dp);
1293 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 1315 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1294 ironlake_edp_panel_off(intel_dp); 1316 ironlake_edp_panel_off(intel_dp);
1295 intel_dp_link_down(intel_dp); 1317
1318 /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
1319 if (!is_cpu_edp(intel_dp))
1320 intel_dp_link_down(intel_dp);
1296} 1321}
1297 1322
1298static void intel_dp_commit(struct drm_encoder *encoder) 1323static void intel_post_disable_dp(struct intel_encoder *encoder)
1299{ 1324{
1300 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1325 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1301 struct drm_device *dev = encoder->dev; 1326
1302 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc); 1327 if (is_cpu_edp(intel_dp)) {
1328 intel_dp_link_down(intel_dp);
1329 ironlake_edp_pll_off(intel_dp);
1330 }
1331}
1332
1333static void intel_enable_dp(struct intel_encoder *encoder)
1334{
1335 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1336 struct drm_device *dev = encoder->base.dev;
1337 struct drm_i915_private *dev_priv = dev->dev_private;
1338 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1339
1340 if (WARN_ON(dp_reg & DP_PORT_EN))
1341 return;
1303 1342
1304 ironlake_edp_panel_vdd_on(intel_dp); 1343 ironlake_edp_panel_vdd_on(intel_dp);
1305 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 1344 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
@@ -1308,47 +1347,14 @@ static void intel_dp_commit(struct drm_encoder *encoder)
1308 ironlake_edp_panel_vdd_off(intel_dp, true); 1347 ironlake_edp_panel_vdd_off(intel_dp, true);
1309 intel_dp_complete_link_train(intel_dp); 1348 intel_dp_complete_link_train(intel_dp);
1310 ironlake_edp_backlight_on(intel_dp); 1349 ironlake_edp_backlight_on(intel_dp);
1311
1312 intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
1313
1314 if (HAS_PCH_CPT(dev))
1315 intel_cpt_verify_modeset(dev, intel_crtc->pipe);
1316} 1350}
1317 1351
1318static void 1352static void intel_pre_enable_dp(struct intel_encoder *encoder)
1319intel_dp_dpms(struct drm_encoder *encoder, int mode)
1320{ 1353{
1321 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1354 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1322 struct drm_device *dev = encoder->dev;
1323 struct drm_i915_private *dev_priv = dev->dev_private;
1324 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
1325 1355
1326 if (mode != DRM_MODE_DPMS_ON) { 1356 if (is_cpu_edp(intel_dp))
1327 /* Switching the panel off requires vdd. */ 1357 ironlake_edp_pll_on(intel_dp);
1328 ironlake_edp_panel_vdd_on(intel_dp);
1329 ironlake_edp_backlight_off(intel_dp);
1330 intel_dp_sink_dpms(intel_dp, mode);
1331 ironlake_edp_panel_off(intel_dp);
1332 intel_dp_link_down(intel_dp);
1333
1334 if (is_cpu_edp(intel_dp))
1335 ironlake_edp_pll_off(encoder);
1336 } else {
1337 if (is_cpu_edp(intel_dp))
1338 ironlake_edp_pll_on(encoder);
1339
1340 ironlake_edp_panel_vdd_on(intel_dp);
1341 intel_dp_sink_dpms(intel_dp, mode);
1342 if (!(dp_reg & DP_PORT_EN)) {
1343 intel_dp_start_link_train(intel_dp);
1344 ironlake_edp_panel_on(intel_dp);
1345 ironlake_edp_panel_vdd_off(intel_dp, true);
1346 intel_dp_complete_link_train(intel_dp);
1347 } else
1348 ironlake_edp_panel_vdd_off(intel_dp, false);
1349 ironlake_edp_backlight_on(intel_dp);
1350 }
1351 intel_dp->dpms_mode = mode;
1352} 1358}
1353 1359
1354/* 1360/*
@@ -1667,6 +1673,45 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
1667 struct drm_i915_private *dev_priv = dev->dev_private; 1673 struct drm_i915_private *dev_priv = dev->dev_private;
1668 int ret; 1674 int ret;
1669 1675
1676 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
1677 dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
1678
1679 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1680 case DP_TRAINING_PATTERN_DISABLE:
1681 dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
1682 break;
1683 case DP_TRAINING_PATTERN_1:
1684 dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
1685 break;
1686 case DP_TRAINING_PATTERN_2:
1687 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1688 break;
1689 case DP_TRAINING_PATTERN_3:
1690 DRM_ERROR("DP training pattern 3 not supported\n");
1691 dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
1692 break;
1693 }
1694
1695 } else {
1696 dp_reg_value &= ~DP_LINK_TRAIN_MASK;
1697
1698 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
1699 case DP_TRAINING_PATTERN_DISABLE:
1700 dp_reg_value |= DP_LINK_TRAIN_OFF;
1701 break;
1702 case DP_TRAINING_PATTERN_1:
1703 dp_reg_value |= DP_LINK_TRAIN_PAT_1;
1704 break;
1705 case DP_TRAINING_PATTERN_2:
1706 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1707 break;
1708 case DP_TRAINING_PATTERN_3:
1709 DRM_ERROR("DP training pattern 3 not supported\n");
1710 dp_reg_value |= DP_LINK_TRAIN_PAT_2;
1711 break;
1712 }
1713 }
1714
1670 I915_WRITE(intel_dp->output_reg, dp_reg_value); 1715 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1671 POSTING_READ(intel_dp->output_reg); 1716 POSTING_READ(intel_dp->output_reg);
1672 1717
@@ -1674,12 +1719,15 @@ intel_dp_set_link_train(struct intel_dp *intel_dp,
1674 DP_TRAINING_PATTERN_SET, 1719 DP_TRAINING_PATTERN_SET,
1675 dp_train_pat); 1720 dp_train_pat);
1676 1721
1677 ret = intel_dp_aux_native_write(intel_dp, 1722 if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
1678 DP_TRAINING_LANE0_SET, 1723 DP_TRAINING_PATTERN_DISABLE) {
1679 intel_dp->train_set, 1724 ret = intel_dp_aux_native_write(intel_dp,
1680 intel_dp->lane_count); 1725 DP_TRAINING_LANE0_SET,
1681 if (ret != intel_dp->lane_count) 1726 intel_dp->train_set,
1682 return false; 1727 intel_dp->lane_count);
1728 if (ret != intel_dp->lane_count)
1729 return false;
1730 }
1683 1731
1684 return true; 1732 return true;
1685} 1733}
@@ -1689,26 +1737,12 @@ static void
1689intel_dp_start_link_train(struct intel_dp *intel_dp) 1737intel_dp_start_link_train(struct intel_dp *intel_dp)
1690{ 1738{
1691 struct drm_device *dev = intel_dp->base.base.dev; 1739 struct drm_device *dev = intel_dp->base.base.dev;
1692 struct drm_i915_private *dev_priv = dev->dev_private;
1693 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
1694 int i; 1740 int i;
1695 uint8_t voltage; 1741 uint8_t voltage;
1696 bool clock_recovery = false; 1742 bool clock_recovery = false;
1697 int voltage_tries, loop_tries; 1743 int voltage_tries, loop_tries;
1698 u32 reg;
1699 uint32_t DP = intel_dp->DP; 1744 uint32_t DP = intel_dp->DP;
1700 1745
1701 /*
1702 * On CPT we have to enable the port in training pattern 1, which
1703 * will happen below in intel_dp_set_link_train. Otherwise, enable
1704 * the port and wait for it to become active.
1705 */
1706 if (!HAS_PCH_CPT(dev)) {
1707 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1708 POSTING_READ(intel_dp->output_reg);
1709 intel_wait_for_vblank(dev, intel_crtc->pipe);
1710 }
1711
1712 /* Write the link configuration data */ 1746 /* Write the link configuration data */
1713 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, 1747 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
1714 intel_dp->link_configuration, 1748 intel_dp->link_configuration,
@@ -1716,10 +1750,6 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1716 1750
1717 DP |= DP_PORT_EN; 1751 DP |= DP_PORT_EN;
1718 1752
1719 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp)))
1720 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1721 else
1722 DP &= ~DP_LINK_TRAIN_MASK;
1723 memset(intel_dp->train_set, 0, 4); 1753 memset(intel_dp->train_set, 0, 4);
1724 voltage = 0xff; 1754 voltage = 0xff;
1725 voltage_tries = 0; 1755 voltage_tries = 0;
@@ -1743,12 +1773,7 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1743 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1773 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1744 } 1774 }
1745 1775
1746 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) 1776 if (!intel_dp_set_link_train(intel_dp, DP,
1747 reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
1748 else
1749 reg = DP | DP_LINK_TRAIN_PAT_1;
1750
1751 if (!intel_dp_set_link_train(intel_dp, reg,
1752 DP_TRAINING_PATTERN_1 | 1777 DP_TRAINING_PATTERN_1 |
1753 DP_LINK_SCRAMBLING_DISABLE)) 1778 DP_LINK_SCRAMBLING_DISABLE))
1754 break; 1779 break;
@@ -1803,10 +1828,8 @@ static void
1803intel_dp_complete_link_train(struct intel_dp *intel_dp) 1828intel_dp_complete_link_train(struct intel_dp *intel_dp)
1804{ 1829{
1805 struct drm_device *dev = intel_dp->base.base.dev; 1830 struct drm_device *dev = intel_dp->base.base.dev;
1806 struct drm_i915_private *dev_priv = dev->dev_private;
1807 bool channel_eq = false; 1831 bool channel_eq = false;
1808 int tries, cr_tries; 1832 int tries, cr_tries;
1809 u32 reg;
1810 uint32_t DP = intel_dp->DP; 1833 uint32_t DP = intel_dp->DP;
1811 1834
1812 /* channel equalization */ 1835 /* channel equalization */
@@ -1835,13 +1858,8 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1835 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; 1858 DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
1836 } 1859 }
1837 1860
1838 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp)))
1839 reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
1840 else
1841 reg = DP | DP_LINK_TRAIN_PAT_2;
1842
1843 /* channel eq pattern */ 1861 /* channel eq pattern */
1844 if (!intel_dp_set_link_train(intel_dp, reg, 1862 if (!intel_dp_set_link_train(intel_dp, DP,
1845 DP_TRAINING_PATTERN_2 | 1863 DP_TRAINING_PATTERN_2 |
1846 DP_LINK_SCRAMBLING_DISABLE)) 1864 DP_LINK_SCRAMBLING_DISABLE))
1847 break; 1865 break;
@@ -1876,15 +1894,7 @@ intel_dp_complete_link_train(struct intel_dp *intel_dp)
1876 ++tries; 1894 ++tries;
1877 } 1895 }
1878 1896
1879 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) 1897 intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
1880 reg = DP | DP_LINK_TRAIN_OFF_CPT;
1881 else
1882 reg = DP | DP_LINK_TRAIN_OFF;
1883
1884 I915_WRITE(intel_dp->output_reg, reg);
1885 POSTING_READ(intel_dp->output_reg);
1886 intel_dp_aux_native_write_1(intel_dp,
1887 DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
1888} 1898}
1889 1899
1890static void 1900static void
@@ -1894,18 +1904,11 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1894 struct drm_i915_private *dev_priv = dev->dev_private; 1904 struct drm_i915_private *dev_priv = dev->dev_private;
1895 uint32_t DP = intel_dp->DP; 1905 uint32_t DP = intel_dp->DP;
1896 1906
1897 if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0) 1907 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
1898 return; 1908 return;
1899 1909
1900 DRM_DEBUG_KMS("\n"); 1910 DRM_DEBUG_KMS("\n");
1901 1911
1902 if (is_edp(intel_dp)) {
1903 DP &= ~DP_PLL_ENABLE;
1904 I915_WRITE(intel_dp->output_reg, DP);
1905 POSTING_READ(intel_dp->output_reg);
1906 udelay(100);
1907 }
1908
1909 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) { 1912 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
1910 DP &= ~DP_LINK_TRAIN_MASK_CPT; 1913 DP &= ~DP_LINK_TRAIN_MASK_CPT;
1911 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); 1914 I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
@@ -1917,13 +1920,6 @@ intel_dp_link_down(struct intel_dp *intel_dp)
1917 1920
1918 msleep(17); 1921 msleep(17);
1919 1922
1920 if (is_edp(intel_dp)) {
1921 if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp)))
1922 DP |= DP_LINK_TRAIN_OFF_CPT;
1923 else
1924 DP |= DP_LINK_TRAIN_OFF;
1925 }
1926
1927 if (HAS_PCH_IBX(dev) && 1923 if (HAS_PCH_IBX(dev) &&
1928 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) { 1924 I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
1929 struct drm_crtc *crtc = intel_dp->base.base.crtc; 1925 struct drm_crtc *crtc = intel_dp->base.base.crtc;
@@ -2032,10 +2028,10 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
2032 u8 sink_irq_vector; 2028 u8 sink_irq_vector;
2033 u8 link_status[DP_LINK_STATUS_SIZE]; 2029 u8 link_status[DP_LINK_STATUS_SIZE];
2034 2030
2035 if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON) 2031 if (!intel_dp->base.connectors_active)
2036 return; 2032 return;
2037 2033
2038 if (!intel_dp->base.base.crtc) 2034 if (WARN_ON(!intel_dp->base.base.crtc))
2039 return; 2035 return;
2040 2036
2041 /* Try to read receiver status if the link appears to be up */ 2037 /* Try to read receiver status if the link appears to be up */
@@ -2159,7 +2155,6 @@ intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *ada
2159 ret = drm_add_edid_modes(connector, intel_dp->edid); 2155 ret = drm_add_edid_modes(connector, intel_dp->edid);
2160 drm_edid_to_eld(connector, 2156 drm_edid_to_eld(connector,
2161 intel_dp->edid); 2157 intel_dp->edid);
2162 connector->display_info.raw_edid = NULL;
2163 return intel_dp->edid_mode_count; 2158 return intel_dp->edid_mode_count;
2164 } 2159 }
2165 2160
@@ -2205,7 +2200,6 @@ intel_dp_detect(struct drm_connector *connector, bool force)
2205 edid = intel_dp_get_edid(connector, &intel_dp->adapter); 2200 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
2206 if (edid) { 2201 if (edid) {
2207 intel_dp->has_audio = drm_detect_monitor_audio(edid); 2202 intel_dp->has_audio = drm_detect_monitor_audio(edid);
2208 connector->display_info.raw_edid = NULL;
2209 kfree(edid); 2203 kfree(edid);
2210 } 2204 }
2211 } 2205 }
@@ -2270,8 +2264,6 @@ intel_dp_detect_audio(struct drm_connector *connector)
2270 edid = intel_dp_get_edid(connector, &intel_dp->adapter); 2264 edid = intel_dp_get_edid(connector, &intel_dp->adapter);
2271 if (edid) { 2265 if (edid) {
2272 has_audio = drm_detect_monitor_audio(edid); 2266 has_audio = drm_detect_monitor_audio(edid);
2273
2274 connector->display_info.raw_edid = NULL;
2275 kfree(edid); 2267 kfree(edid);
2276 } 2268 }
2277 2269
@@ -2325,9 +2317,8 @@ intel_dp_set_property(struct drm_connector *connector,
2325done: 2317done:
2326 if (intel_dp->base.base.crtc) { 2318 if (intel_dp->base.base.crtc) {
2327 struct drm_crtc *crtc = intel_dp->base.base.crtc; 2319 struct drm_crtc *crtc = intel_dp->base.base.crtc;
2328 drm_crtc_helper_set_mode(crtc, &crtc->mode, 2320 intel_set_mode(crtc, &crtc->mode,
2329 crtc->x, crtc->y, 2321 crtc->x, crtc->y, crtc->fb);
2330 crtc->fb);
2331 } 2322 }
2332 2323
2333 return 0; 2324 return 0;
@@ -2361,15 +2352,13 @@ static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
2361} 2352}
2362 2353
2363static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { 2354static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
2364 .dpms = intel_dp_dpms,
2365 .mode_fixup = intel_dp_mode_fixup, 2355 .mode_fixup = intel_dp_mode_fixup,
2366 .prepare = intel_dp_prepare,
2367 .mode_set = intel_dp_mode_set, 2356 .mode_set = intel_dp_mode_set,
2368 .commit = intel_dp_commit, 2357 .disable = intel_encoder_noop,
2369}; 2358};
2370 2359
2371static const struct drm_connector_funcs intel_dp_connector_funcs = { 2360static const struct drm_connector_funcs intel_dp_connector_funcs = {
2372 .dpms = drm_helper_connector_dpms, 2361 .dpms = intel_connector_dpms,
2373 .detect = intel_dp_detect, 2362 .detect = intel_dp_detect,
2374 .fill_modes = drm_helper_probe_single_connector_modes, 2363 .fill_modes = drm_helper_probe_single_connector_modes,
2375 .set_property = intel_dp_set_property, 2364 .set_property = intel_dp_set_property,
@@ -2440,7 +2429,7 @@ intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connect
2440} 2429}
2441 2430
2442void 2431void
2443intel_dp_init(struct drm_device *dev, int output_reg) 2432intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
2444{ 2433{
2445 struct drm_i915_private *dev_priv = dev->dev_private; 2434 struct drm_i915_private *dev_priv = dev->dev_private;
2446 struct drm_connector *connector; 2435 struct drm_connector *connector;
@@ -2455,7 +2444,9 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2455 return; 2444 return;
2456 2445
2457 intel_dp->output_reg = output_reg; 2446 intel_dp->output_reg = output_reg;
2458 intel_dp->dpms_mode = -1; 2447 intel_dp->port = port;
2448 /* Preserve the current hw state. */
2449 intel_dp->DP = I915_READ(intel_dp->output_reg);
2459 2450
2460 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); 2451 intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
2461 if (!intel_connector) { 2452 if (!intel_connector) {
@@ -2482,18 +2473,10 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2482 2473
2483 connector->polled = DRM_CONNECTOR_POLL_HPD; 2474 connector->polled = DRM_CONNECTOR_POLL_HPD;
2484 2475
2485 if (output_reg == DP_B || output_reg == PCH_DP_B) 2476 intel_encoder->cloneable = false;
2486 intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
2487 else if (output_reg == DP_C || output_reg == PCH_DP_C)
2488 intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
2489 else if (output_reg == DP_D || output_reg == PCH_DP_D)
2490 intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
2491 2477
2492 if (is_edp(intel_dp)) { 2478 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2493 intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); 2479 ironlake_panel_vdd_work);
2494 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
2495 ironlake_panel_vdd_work);
2496 }
2497 2480
2498 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); 2481 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
2499 2482
@@ -2507,29 +2490,33 @@ intel_dp_init(struct drm_device *dev, int output_reg)
2507 intel_connector_attach_encoder(intel_connector, intel_encoder); 2490 intel_connector_attach_encoder(intel_connector, intel_encoder);
2508 drm_sysfs_connector_add(connector); 2491 drm_sysfs_connector_add(connector);
2509 2492
2493 intel_encoder->enable = intel_enable_dp;
2494 intel_encoder->pre_enable = intel_pre_enable_dp;
2495 intel_encoder->disable = intel_disable_dp;
2496 intel_encoder->post_disable = intel_post_disable_dp;
2497 intel_encoder->get_hw_state = intel_dp_get_hw_state;
2498 intel_connector->get_hw_state = intel_connector_get_hw_state;
2499
2510 /* Set up the DDC bus. */ 2500 /* Set up the DDC bus. */
2511 switch (output_reg) { 2501 switch (port) {
2512 case DP_A: 2502 case PORT_A:
2513 name = "DPDDC-A"; 2503 name = "DPDDC-A";
2514 break; 2504 break;
2515 case DP_B: 2505 case PORT_B:
2516 case PCH_DP_B: 2506 dev_priv->hotplug_supported_mask |= DPB_HOTPLUG_INT_STATUS;
2517 dev_priv->hotplug_supported_mask |= 2507 name = "DPDDC-B";
2518 DPB_HOTPLUG_INT_STATUS; 2508 break;
2519 name = "DPDDC-B"; 2509 case PORT_C:
2520 break; 2510 dev_priv->hotplug_supported_mask |= DPC_HOTPLUG_INT_STATUS;
2521 case DP_C: 2511 name = "DPDDC-C";
2522 case PCH_DP_C: 2512 break;
2523 dev_priv->hotplug_supported_mask |= 2513 case PORT_D:
2524 DPC_HOTPLUG_INT_STATUS; 2514 dev_priv->hotplug_supported_mask |= DPD_HOTPLUG_INT_STATUS;
2525 name = "DPDDC-C"; 2515 name = "DPDDC-D";
2526 break; 2516 break;
2527 case DP_D: 2517 default:
2528 case PCH_DP_D: 2518 WARN(1, "Invalid port %c\n", port_name(port));
2529 dev_priv->hotplug_supported_mask |= 2519 break;
2530 DPD_HOTPLUG_INT_STATUS;
2531 name = "DPDDC-D";
2532 break;
2533 } 2520 }
2534 2521
2535 /* Cache some DPCD data in the eDP case */ 2522 /* Cache some DPCD data in the eDP case */