1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2020 Intel Corporation 4 * 5 * DisplayPort support for G4x,ILK,SNB,IVB,VLV,CHV (HSW+ handled by the DDI code). 6 */ 7 8 #include <linux/string_helpers.h> 9 10 #include <drm/drm_print.h> 11 12 #include "g4x_dp.h" 13 #include "i915_reg.h" 14 #include "intel_audio.h" 15 #include "intel_backlight.h" 16 #include "intel_connector.h" 17 #include "intel_crtc.h" 18 #include "intel_de.h" 19 #include "intel_display_power.h" 20 #include "intel_display_regs.h" 21 #include "intel_display_types.h" 22 #include "intel_display_utils.h" 23 #include "intel_dp.h" 24 #include "intel_dp_aux.h" 25 #include "intel_dp_link_training.h" 26 #include "intel_dp_test.h" 27 #include "intel_dpio_phy.h" 28 #include "intel_encoder.h" 29 #include "intel_fifo_underrun.h" 30 #include "intel_hdmi.h" 31 #include "intel_hotplug.h" 32 #include "intel_pch_display.h" 33 #include "intel_pps.h" 34 35 static const struct dpll g4x_dpll[] = { 36 { .dot = 162000, .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8, }, 37 { .dot = 270000, .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2, }, 38 }; 39 40 static const struct dpll pch_dpll[] = { 41 { .dot = 162000, .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9, }, 42 { .dot = 270000, .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8, }, 43 }; 44 45 static const struct dpll vlv_dpll[] = { 46 { .dot = 162000, .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81, }, 47 { .dot = 270000, .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27, }, 48 }; 49 50 static const struct dpll chv_dpll[] = { 51 /* m2 is .22 binary fixed point */ 52 { .dot = 162000, .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a /* 32.4 */ }, 53 { .dot = 270000, .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 /* 27.0 */ }, 54 }; 55 56 const struct dpll *vlv_get_dpll(struct intel_display *display) 57 { 58 return display->platform.cherryview ? &chv_dpll[0] : &vlv_dpll[0]; 59 } 60 61 static void g4x_dp_set_clock(struct intel_encoder *encoder, 62 struct intel_crtc_state *pipe_config) 63 { 64 struct intel_display *display = to_intel_display(encoder); 65 const struct dpll *divisor = NULL; 66 int i, count = 0; 67 68 if (display->platform.g4x) { 69 divisor = g4x_dpll; 70 count = ARRAY_SIZE(g4x_dpll); 71 } else if (HAS_PCH_SPLIT(display)) { 72 divisor = pch_dpll; 73 count = ARRAY_SIZE(pch_dpll); 74 } else if (display->platform.cherryview) { 75 divisor = chv_dpll; 76 count = ARRAY_SIZE(chv_dpll); 77 } else if (display->platform.valleyview) { 78 divisor = vlv_dpll; 79 count = ARRAY_SIZE(vlv_dpll); 80 } 81 82 if (divisor && count) { 83 for (i = 0; i < count; i++) { 84 if (pipe_config->port_clock == divisor[i].dot) { 85 pipe_config->dpll = divisor[i]; 86 pipe_config->clock_set = true; 87 break; 88 } 89 } 90 } 91 } 92 93 static void intel_dp_prepare(struct intel_encoder *encoder, 94 const struct intel_crtc_state *pipe_config) 95 { 96 struct intel_display *display = to_intel_display(encoder); 97 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 98 enum port port = encoder->port; 99 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 100 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 101 102 intel_dp_set_link_params(intel_dp, 103 pipe_config->port_clock, 104 pipe_config->lane_count); 105 106 /* 107 * There are four kinds of DP registers: 108 * IBX PCH 109 * SNB CPU 110 * IVB CPU 111 * CPT PCH 112 * 113 * IBX PCH and CPU are the same for almost everything, 114 * except that the CPU DP PLL is configured in this 115 * register 116 * 117 * CPT PCH is quite different, having many bits moved 118 * to the TRANS_DP_CTL register instead. That 119 * configuration happens (oddly) in ilk_pch_enable 120 */ 121 122 /* Preserve the BIOS-computed detected bit. This is 123 * supposed to be read-only. 124 */ 125 intel_dp->DP = intel_de_read(display, intel_dp->output_reg) & DP_DETECTED; 126 127 /* Handle DP bits in common between all three register formats */ 128 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; 129 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count); 130 131 /* Split out the IBX/CPU vs CPT settings */ 132 133 if (display->platform.ivybridge && port == PORT_A) { 134 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 135 intel_dp->DP |= DP_SYNC_HS_HIGH; 136 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 137 intel_dp->DP |= DP_SYNC_VS_HIGH; 138 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; 139 140 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) 141 intel_dp->DP |= DP_ENHANCED_FRAMING; 142 143 intel_dp->DP |= DP_PIPE_SEL_IVB(crtc->pipe); 144 } else if (HAS_PCH_CPT(display) && port != PORT_A) { 145 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; 146 147 intel_de_rmw(display, TRANS_DP_CTL(crtc->pipe), 148 TRANS_DP_ENH_FRAMING, 149 pipe_config->enhanced_framing ? 150 TRANS_DP_ENH_FRAMING : 0); 151 } else { 152 if (display->platform.g4x && pipe_config->limited_color_range) 153 intel_dp->DP |= DP_COLOR_RANGE_16_235; 154 155 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 156 intel_dp->DP |= DP_SYNC_HS_HIGH; 157 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 158 intel_dp->DP |= DP_SYNC_VS_HIGH; 159 intel_dp->DP |= DP_LINK_TRAIN_OFF; 160 161 if (pipe_config->enhanced_framing) 162 intel_dp->DP |= DP_ENHANCED_FRAMING; 163 164 if (display->platform.cherryview) 165 intel_dp->DP |= DP_PIPE_SEL_CHV(crtc->pipe); 166 else 167 intel_dp->DP |= DP_PIPE_SEL(crtc->pipe); 168 } 169 } 170 171 static void assert_dp_port(struct intel_dp *intel_dp, bool state) 172 { 173 struct intel_display *display = to_intel_display(intel_dp); 174 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 175 bool cur_state = intel_de_read(display, intel_dp->output_reg) & DP_PORT_EN; 176 177 INTEL_DISPLAY_STATE_WARN(display, cur_state != state, 178 "[ENCODER:%d:%s] state assertion failure (expected %s, current %s)\n", 179 dig_port->base.base.base.id, dig_port->base.base.name, 180 str_on_off(state), str_on_off(cur_state)); 181 } 182 #define assert_dp_port_disabled(d) assert_dp_port((d), false) 183 184 static void assert_edp_pll(struct intel_display *display, bool state) 185 { 186 bool cur_state = intel_de_read(display, DP_A) & EDP_PLL_ENABLE; 187 188 INTEL_DISPLAY_STATE_WARN(display, cur_state != state, 189 "eDP PLL state assertion failure (expected %s, current %s)\n", 190 str_on_off(state), str_on_off(cur_state)); 191 } 192 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true) 193 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false) 194 195 static void ilk_edp_pll_on(struct intel_dp *intel_dp, 196 const struct intel_crtc_state *pipe_config) 197 { 198 struct intel_display *display = to_intel_display(intel_dp); 199 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 200 201 assert_transcoder_disabled(display, pipe_config->cpu_transcoder); 202 assert_dp_port_disabled(intel_dp); 203 assert_edp_pll_disabled(display); 204 205 drm_dbg_kms(display->drm, "enabling eDP PLL for clock %d\n", 206 pipe_config->port_clock); 207 208 intel_dp->DP &= ~EDP_PLL_FREQ_MASK; 209 210 if (pipe_config->port_clock == 162000) 211 intel_dp->DP |= EDP_PLL_FREQ_162MHZ; 212 else 213 intel_dp->DP |= EDP_PLL_FREQ_270MHZ; 214 215 intel_de_write(display, DP_A, intel_dp->DP); 216 intel_de_posting_read(display, DP_A); 217 udelay(500); 218 219 /* 220 * [DevILK] Work around required when enabling DP PLL 221 * while a pipe is enabled going to FDI: 222 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI 223 * 2. Program DP PLL enable 224 */ 225 if (display->platform.ironlake) 226 intel_wait_for_vblank_if_active(display, !crtc->pipe); 227 228 intel_dp->DP |= EDP_PLL_ENABLE; 229 230 intel_de_write(display, DP_A, intel_dp->DP); 231 intel_de_posting_read(display, DP_A); 232 udelay(200); 233 } 234 235 static void ilk_edp_pll_off(struct intel_dp *intel_dp, 236 const struct intel_crtc_state *old_crtc_state) 237 { 238 struct intel_display *display = to_intel_display(intel_dp); 239 240 assert_transcoder_disabled(display, old_crtc_state->cpu_transcoder); 241 assert_dp_port_disabled(intel_dp); 242 assert_edp_pll_enabled(display); 243 244 drm_dbg_kms(display->drm, "disabling eDP PLL\n"); 245 246 intel_dp->DP &= ~EDP_PLL_ENABLE; 247 248 intel_de_write(display, DP_A, intel_dp->DP); 249 intel_de_posting_read(display, DP_A); 250 udelay(200); 251 } 252 253 static bool cpt_dp_port_selected(struct intel_display *display, 254 enum port port, enum pipe *pipe) 255 { 256 enum pipe p; 257 258 for_each_pipe(display, p) { 259 u32 val = intel_de_read(display, TRANS_DP_CTL(p)); 260 261 if ((val & TRANS_DP_PORT_SEL_MASK) == TRANS_DP_PORT_SEL(port)) { 262 *pipe = p; 263 return true; 264 } 265 } 266 267 drm_dbg_kms(display->drm, "No pipe for DP port %c found\n", 268 port_name(port)); 269 270 /* must initialize pipe to something for the asserts */ 271 *pipe = PIPE_A; 272 273 return false; 274 } 275 276 bool g4x_dp_port_enabled(struct intel_display *display, 277 i915_reg_t dp_reg, enum port port, 278 enum pipe *pipe) 279 { 280 bool ret; 281 u32 val; 282 283 val = intel_de_read(display, dp_reg); 284 285 ret = val & DP_PORT_EN; 286 287 /* asserts want to know the pipe even if the port is disabled */ 288 if (display->platform.ivybridge && port == PORT_A) 289 *pipe = REG_FIELD_GET(DP_PIPE_SEL_MASK_IVB, val); 290 else if (HAS_PCH_CPT(display) && port != PORT_A) 291 ret &= cpt_dp_port_selected(display, port, pipe); 292 else if (display->platform.cherryview) 293 *pipe = REG_FIELD_GET(DP_PIPE_SEL_MASK_CHV, val); 294 else 295 *pipe = REG_FIELD_GET(DP_PIPE_SEL_MASK, val); 296 297 return ret; 298 } 299 300 static bool intel_dp_get_hw_state(struct intel_encoder *encoder, 301 enum pipe *pipe) 302 { 303 struct intel_display *display = to_intel_display(encoder); 304 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 305 struct ref_tracker *wakeref; 306 bool ret; 307 308 wakeref = intel_display_power_get_if_enabled(display, 309 encoder->power_domain); 310 if (!wakeref) 311 return false; 312 313 ret = g4x_dp_port_enabled(display, intel_dp->output_reg, 314 encoder->port, pipe); 315 316 intel_display_power_put(display, encoder->power_domain, wakeref); 317 318 return ret; 319 } 320 321 static void g4x_dp_get_m_n(struct intel_crtc_state *crtc_state) 322 { 323 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 324 325 if (crtc_state->has_pch_encoder) { 326 intel_pch_transcoder_get_m1_n1(crtc, &crtc_state->dp_m_n); 327 intel_pch_transcoder_get_m2_n2(crtc, &crtc_state->dp_m2_n2); 328 } else { 329 intel_cpu_transcoder_get_m1_n1(crtc, crtc_state->cpu_transcoder, 330 &crtc_state->dp_m_n); 331 intel_cpu_transcoder_get_m2_n2(crtc, crtc_state->cpu_transcoder, 332 &crtc_state->dp_m2_n2); 333 } 334 } 335 336 static void intel_dp_get_config(struct intel_encoder *encoder, 337 struct intel_crtc_state *pipe_config) 338 { 339 struct intel_display *display = to_intel_display(encoder); 340 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 341 u32 tmp, flags = 0; 342 enum port port = encoder->port; 343 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 344 345 if (encoder->type == INTEL_OUTPUT_EDP) 346 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); 347 else 348 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); 349 350 tmp = intel_de_read(display, intel_dp->output_reg); 351 352 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A; 353 354 if (HAS_PCH_CPT(display) && port != PORT_A) { 355 u32 trans_dp = intel_de_read(display, 356 TRANS_DP_CTL(crtc->pipe)); 357 358 if (trans_dp & TRANS_DP_ENH_FRAMING) 359 pipe_config->enhanced_framing = true; 360 361 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH) 362 flags |= DRM_MODE_FLAG_PHSYNC; 363 else 364 flags |= DRM_MODE_FLAG_NHSYNC; 365 366 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH) 367 flags |= DRM_MODE_FLAG_PVSYNC; 368 else 369 flags |= DRM_MODE_FLAG_NVSYNC; 370 } else { 371 if (tmp & DP_ENHANCED_FRAMING) 372 pipe_config->enhanced_framing = true; 373 374 if (tmp & DP_SYNC_HS_HIGH) 375 flags |= DRM_MODE_FLAG_PHSYNC; 376 else 377 flags |= DRM_MODE_FLAG_NHSYNC; 378 379 if (tmp & DP_SYNC_VS_HIGH) 380 flags |= DRM_MODE_FLAG_PVSYNC; 381 else 382 flags |= DRM_MODE_FLAG_NVSYNC; 383 } 384 385 pipe_config->hw.adjusted_mode.flags |= flags; 386 387 if (display->platform.g4x && tmp & DP_COLOR_RANGE_16_235) 388 pipe_config->limited_color_range = true; 389 390 pipe_config->lane_count = REG_FIELD_GET(DP_PORT_WIDTH_MASK, tmp) + 1; 391 392 g4x_dp_get_m_n(pipe_config); 393 394 if (port == PORT_A) { 395 if ((intel_de_read(display, DP_A) & EDP_PLL_FREQ_MASK) == EDP_PLL_FREQ_162MHZ) 396 pipe_config->port_clock = 162000; 397 else 398 pipe_config->port_clock = 270000; 399 } 400 401 pipe_config->hw.adjusted_mode.crtc_clock = 402 intel_dotclock_calculate(pipe_config->port_clock, 403 &pipe_config->dp_m_n); 404 405 if (intel_dp_is_edp(intel_dp)) 406 intel_edp_fixup_vbt_bpp(encoder, pipe_config->pipe_bpp); 407 408 intel_audio_codec_get_config(encoder, pipe_config); 409 } 410 411 static void 412 intel_dp_link_down(struct intel_encoder *encoder, 413 const struct intel_crtc_state *old_crtc_state) 414 { 415 struct intel_display *display = to_intel_display(encoder); 416 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 417 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 418 enum port port = encoder->port; 419 420 if (drm_WARN_ON(display->drm, 421 (intel_de_read(display, intel_dp->output_reg) & 422 DP_PORT_EN) == 0)) 423 return; 424 425 drm_dbg_kms(display->drm, "\n"); 426 427 intel_dp->DP &= ~DP_PORT_EN; 428 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 429 intel_de_posting_read(display, intel_dp->output_reg); 430 431 /* 432 * HW workaround for IBX, we need to move the port 433 * to transcoder A after disabling it to allow the 434 * matching HDMI port to be enabled on transcoder A. 435 */ 436 if (HAS_PCH_IBX(display) && crtc->pipe == PIPE_B && port != PORT_A) { 437 /* 438 * We get CPU/PCH FIFO underruns on the other pipe when 439 * doing the workaround. Sweep them under the rug. 440 */ 441 intel_set_cpu_fifo_underrun_reporting(display, PIPE_A, false); 442 intel_set_pch_fifo_underrun_reporting(display, PIPE_A, false); 443 444 /* always enable with pattern 1 (as per spec) */ 445 intel_dp->DP &= ~(DP_PIPE_SEL_MASK | DP_LINK_TRAIN_MASK); 446 intel_dp->DP |= DP_PORT_EN | DP_PIPE_SEL(PIPE_A) | 447 DP_LINK_TRAIN_PAT_1; 448 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 449 intel_de_posting_read(display, intel_dp->output_reg); 450 451 intel_dp->DP &= ~DP_PORT_EN; 452 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 453 intel_de_posting_read(display, intel_dp->output_reg); 454 455 intel_wait_for_vblank_if_active(display, PIPE_A); 456 intel_set_cpu_fifo_underrun_reporting(display, PIPE_A, true); 457 intel_set_pch_fifo_underrun_reporting(display, PIPE_A, true); 458 } 459 460 msleep(intel_dp->pps.panel_power_down_delay); 461 462 if (display->platform.valleyview || display->platform.cherryview) 463 vlv_pps_port_disable(encoder, old_crtc_state); 464 } 465 466 static void g4x_dp_audio_enable(struct intel_encoder *encoder, 467 const struct intel_crtc_state *crtc_state, 468 const struct drm_connector_state *conn_state) 469 { 470 struct intel_display *display = to_intel_display(encoder); 471 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 472 473 if (!crtc_state->has_audio) 474 return; 475 476 /* Enable audio presence detect */ 477 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE; 478 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 479 480 intel_audio_codec_enable(encoder, crtc_state, conn_state); 481 } 482 483 static void g4x_dp_audio_disable(struct intel_encoder *encoder, 484 const struct intel_crtc_state *old_crtc_state, 485 const struct drm_connector_state *old_conn_state) 486 { 487 struct intel_display *display = to_intel_display(encoder); 488 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 489 490 if (!old_crtc_state->has_audio) 491 return; 492 493 intel_audio_codec_disable(encoder, old_crtc_state, old_conn_state); 494 495 /* Disable audio presence detect */ 496 intel_dp->DP &= ~DP_AUDIO_OUTPUT_ENABLE; 497 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 498 } 499 500 static void intel_disable_dp(struct intel_atomic_state *state, 501 struct intel_encoder *encoder, 502 const struct intel_crtc_state *old_crtc_state, 503 const struct drm_connector_state *old_conn_state) 504 { 505 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 506 507 intel_dp->link.active = false; 508 509 /* 510 * Make sure the panel is off before trying to change the mode. 511 * But also ensure that we have vdd while we switch off the panel. 512 */ 513 intel_pps_vdd_on(intel_dp); 514 intel_edp_backlight_off(old_conn_state); 515 intel_dp_set_power(intel_dp, DP_SET_POWER_D3); 516 intel_pps_off(intel_dp); 517 } 518 519 static void g4x_disable_dp(struct intel_atomic_state *state, 520 struct intel_encoder *encoder, 521 const struct intel_crtc_state *old_crtc_state, 522 const struct drm_connector_state *old_conn_state) 523 { 524 intel_disable_dp(state, encoder, old_crtc_state, old_conn_state); 525 } 526 527 static void vlv_disable_dp(struct intel_atomic_state *state, 528 struct intel_encoder *encoder, 529 const struct intel_crtc_state *old_crtc_state, 530 const struct drm_connector_state *old_conn_state) 531 { 532 intel_disable_dp(state, encoder, old_crtc_state, old_conn_state); 533 } 534 535 static void g4x_post_disable_dp(struct intel_atomic_state *state, 536 struct intel_encoder *encoder, 537 const struct intel_crtc_state *old_crtc_state, 538 const struct drm_connector_state *old_conn_state) 539 { 540 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 541 enum port port = encoder->port; 542 543 /* 544 * Bspec does not list a specific disable sequence for g4x DP. 545 * Follow the ilk+ sequence (disable pipe before the port) for 546 * g4x DP as it does not suffer from underruns like the normal 547 * g4x modeset sequence (disable pipe after the port). 548 */ 549 intel_dp_link_down(encoder, old_crtc_state); 550 551 /* Only ilk+ has port A */ 552 if (port == PORT_A) 553 ilk_edp_pll_off(intel_dp, old_crtc_state); 554 } 555 556 static void vlv_post_disable_dp(struct intel_atomic_state *state, 557 struct intel_encoder *encoder, 558 const struct intel_crtc_state *old_crtc_state, 559 const struct drm_connector_state *old_conn_state) 560 { 561 intel_dp_link_down(encoder, old_crtc_state); 562 } 563 564 static void chv_post_disable_dp(struct intel_atomic_state *state, 565 struct intel_encoder *encoder, 566 const struct intel_crtc_state *old_crtc_state, 567 const struct drm_connector_state *old_conn_state) 568 { 569 intel_dp_link_down(encoder, old_crtc_state); 570 571 /* Assert data lane reset */ 572 chv_data_lane_soft_reset(encoder, old_crtc_state, true); 573 } 574 575 static void 576 cpt_set_link_train(struct intel_dp *intel_dp, 577 const struct intel_crtc_state *crtc_state, 578 u8 dp_train_pat) 579 { 580 struct intel_display *display = to_intel_display(intel_dp); 581 582 intel_dp->DP &= ~DP_LINK_TRAIN_MASK_CPT; 583 584 switch (intel_dp_training_pattern_symbol(dp_train_pat)) { 585 case DP_TRAINING_PATTERN_DISABLE: 586 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT; 587 break; 588 case DP_TRAINING_PATTERN_1: 589 intel_dp->DP |= DP_LINK_TRAIN_PAT_1_CPT; 590 break; 591 case DP_TRAINING_PATTERN_2: 592 intel_dp->DP |= DP_LINK_TRAIN_PAT_2_CPT; 593 break; 594 default: 595 MISSING_CASE(intel_dp_training_pattern_symbol(dp_train_pat)); 596 return; 597 } 598 599 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 600 intel_de_posting_read(display, intel_dp->output_reg); 601 } 602 603 static void 604 cpt_set_idle_link_train(struct intel_dp *intel_dp, 605 const struct intel_crtc_state *crtc_state) 606 { 607 struct intel_display *display = to_intel_display(intel_dp); 608 609 intel_dp->DP &= ~DP_LINK_TRAIN_MASK_CPT; 610 intel_dp->DP |= DP_LINK_TRAIN_PAT_IDLE_CPT; 611 612 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 613 intel_de_posting_read(display, intel_dp->output_reg); 614 } 615 616 static void 617 g4x_set_link_train(struct intel_dp *intel_dp, 618 const struct intel_crtc_state *crtc_state, 619 u8 dp_train_pat) 620 { 621 struct intel_display *display = to_intel_display(intel_dp); 622 623 intel_dp->DP &= ~DP_LINK_TRAIN_MASK; 624 625 switch (intel_dp_training_pattern_symbol(dp_train_pat)) { 626 case DP_TRAINING_PATTERN_DISABLE: 627 intel_dp->DP |= DP_LINK_TRAIN_OFF; 628 break; 629 case DP_TRAINING_PATTERN_1: 630 intel_dp->DP |= DP_LINK_TRAIN_PAT_1; 631 break; 632 case DP_TRAINING_PATTERN_2: 633 intel_dp->DP |= DP_LINK_TRAIN_PAT_2; 634 break; 635 default: 636 MISSING_CASE(intel_dp_training_pattern_symbol(dp_train_pat)); 637 return; 638 } 639 640 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 641 intel_de_posting_read(display, intel_dp->output_reg); 642 } 643 644 static void 645 g4x_set_idle_link_train(struct intel_dp *intel_dp, 646 const struct intel_crtc_state *crtc_state) 647 { 648 struct intel_display *display = to_intel_display(intel_dp); 649 650 intel_dp->DP &= ~DP_LINK_TRAIN_MASK; 651 intel_dp->DP |= DP_LINK_TRAIN_PAT_IDLE; 652 653 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 654 intel_de_posting_read(display, intel_dp->output_reg); 655 } 656 657 static void intel_dp_enable_port(struct intel_dp *intel_dp, 658 const struct intel_crtc_state *crtc_state) 659 { 660 struct intel_display *display = to_intel_display(intel_dp); 661 662 /* enable with pattern 1 (as per spec) */ 663 664 intel_dp_program_link_training_pattern(intel_dp, crtc_state, 665 DP_PHY_DPRX, DP_TRAINING_PATTERN_1); 666 667 /* 668 * Magic for VLV/CHV. We _must_ first set up the register 669 * without actually enabling the port, and then do another 670 * write to enable the port. Otherwise link training will 671 * fail when the power sequencer is freshly used for this port. 672 */ 673 intel_dp->DP |= DP_PORT_EN; 674 675 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 676 intel_de_posting_read(display, intel_dp->output_reg); 677 } 678 679 static void intel_enable_dp(struct intel_atomic_state *state, 680 struct intel_encoder *encoder, 681 const struct intel_crtc_state *pipe_config, 682 const struct drm_connector_state *conn_state) 683 { 684 struct intel_display *display = to_intel_display(state); 685 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 686 u32 dp_reg = intel_de_read(display, intel_dp->output_reg); 687 688 if (drm_WARN_ON(display->drm, dp_reg & DP_PORT_EN)) 689 return; 690 691 with_intel_pps_lock(intel_dp) { 692 if (display->platform.valleyview || display->platform.cherryview) 693 vlv_pps_port_enable_unlocked(encoder, pipe_config); 694 695 intel_dp_enable_port(intel_dp, pipe_config); 696 697 intel_pps_vdd_on_unlocked(intel_dp); 698 intel_pps_on_unlocked(intel_dp); 699 intel_pps_vdd_off_unlocked(intel_dp, true); 700 } 701 702 if (display->platform.valleyview || display->platform.cherryview) { 703 unsigned int lane_mask = 0x0; 704 705 if (display->platform.cherryview) 706 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count); 707 708 vlv_wait_port_ready(encoder, lane_mask); 709 } 710 711 intel_dp_set_power(intel_dp, DP_SET_POWER_D0); 712 intel_dp_configure_protocol_converter(intel_dp, pipe_config); 713 intel_dp_check_frl_training(intel_dp); 714 intel_dp_pcon_dsc_configure(intel_dp, pipe_config); 715 intel_dp_start_link_train(state, intel_dp, pipe_config); 716 intel_dp_stop_link_train(intel_dp, pipe_config); 717 } 718 719 static void g4x_enable_dp(struct intel_atomic_state *state, 720 struct intel_encoder *encoder, 721 const struct intel_crtc_state *pipe_config, 722 const struct drm_connector_state *conn_state) 723 { 724 intel_enable_dp(state, encoder, pipe_config, conn_state); 725 intel_edp_backlight_on(pipe_config, conn_state); 726 } 727 728 static void vlv_enable_dp(struct intel_atomic_state *state, 729 struct intel_encoder *encoder, 730 const struct intel_crtc_state *pipe_config, 731 const struct drm_connector_state *conn_state) 732 { 733 intel_edp_backlight_on(pipe_config, conn_state); 734 } 735 736 static void g4x_pre_enable_dp(struct intel_atomic_state *state, 737 struct intel_encoder *encoder, 738 const struct intel_crtc_state *pipe_config, 739 const struct drm_connector_state *conn_state) 740 { 741 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 742 enum port port = encoder->port; 743 744 intel_dp_prepare(encoder, pipe_config); 745 746 /* Only ilk+ has port A */ 747 if (port == PORT_A) 748 ilk_edp_pll_on(intel_dp, pipe_config); 749 } 750 751 static void vlv_pre_enable_dp(struct intel_atomic_state *state, 752 struct intel_encoder *encoder, 753 const struct intel_crtc_state *pipe_config, 754 const struct drm_connector_state *conn_state) 755 { 756 vlv_phy_pre_encoder_enable(encoder, pipe_config); 757 758 intel_enable_dp(state, encoder, pipe_config, conn_state); 759 } 760 761 static void vlv_dp_pre_pll_enable(struct intel_atomic_state *state, 762 struct intel_encoder *encoder, 763 const struct intel_crtc_state *pipe_config, 764 const struct drm_connector_state *conn_state) 765 { 766 intel_dp_prepare(encoder, pipe_config); 767 768 vlv_phy_pre_pll_enable(encoder, pipe_config); 769 } 770 771 static void chv_pre_enable_dp(struct intel_atomic_state *state, 772 struct intel_encoder *encoder, 773 const struct intel_crtc_state *pipe_config, 774 const struct drm_connector_state *conn_state) 775 { 776 chv_phy_pre_encoder_enable(encoder, pipe_config); 777 778 intel_enable_dp(state, encoder, pipe_config, conn_state); 779 780 /* Second common lane will stay alive on its own now */ 781 chv_phy_release_cl2_override(encoder); 782 } 783 784 static void chv_dp_pre_pll_enable(struct intel_atomic_state *state, 785 struct intel_encoder *encoder, 786 const struct intel_crtc_state *pipe_config, 787 const struct drm_connector_state *conn_state) 788 { 789 intel_dp_prepare(encoder, pipe_config); 790 791 chv_phy_pre_pll_enable(encoder, pipe_config); 792 } 793 794 static void chv_dp_post_pll_disable(struct intel_atomic_state *state, 795 struct intel_encoder *encoder, 796 const struct intel_crtc_state *old_crtc_state, 797 const struct drm_connector_state *old_conn_state) 798 { 799 chv_phy_post_pll_disable(encoder, old_crtc_state); 800 } 801 802 static u8 intel_dp_voltage_max_2(struct intel_dp *intel_dp, 803 const struct intel_crtc_state *crtc_state) 804 { 805 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2; 806 } 807 808 static u8 intel_dp_voltage_max_3(struct intel_dp *intel_dp, 809 const struct intel_crtc_state *crtc_state) 810 { 811 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3; 812 } 813 814 static u8 intel_dp_preemph_max_2(struct intel_dp *intel_dp) 815 { 816 return DP_TRAIN_PRE_EMPH_LEVEL_2; 817 } 818 819 static u8 intel_dp_preemph_max_3(struct intel_dp *intel_dp) 820 { 821 return DP_TRAIN_PRE_EMPH_LEVEL_3; 822 } 823 824 static void vlv_set_signal_levels(struct intel_encoder *encoder, 825 const struct intel_crtc_state *crtc_state) 826 { 827 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 828 unsigned long demph_reg_value, preemph_reg_value, 829 uniqtranscale_reg_value; 830 u8 train_set = intel_dp->train_set[0]; 831 832 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { 833 case DP_TRAIN_PRE_EMPH_LEVEL_0: 834 preemph_reg_value = 0x0004000; 835 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 836 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 837 demph_reg_value = 0x2B405555; 838 uniqtranscale_reg_value = 0x552AB83A; 839 break; 840 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 841 demph_reg_value = 0x2B404040; 842 uniqtranscale_reg_value = 0x5548B83A; 843 break; 844 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 845 demph_reg_value = 0x2B245555; 846 uniqtranscale_reg_value = 0x5560B83A; 847 break; 848 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: 849 demph_reg_value = 0x2B405555; 850 uniqtranscale_reg_value = 0x5598DA3A; 851 break; 852 default: 853 return; 854 } 855 break; 856 case DP_TRAIN_PRE_EMPH_LEVEL_1: 857 preemph_reg_value = 0x0002000; 858 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 859 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 860 demph_reg_value = 0x2B404040; 861 uniqtranscale_reg_value = 0x5552B83A; 862 break; 863 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 864 demph_reg_value = 0x2B404848; 865 uniqtranscale_reg_value = 0x5580B83A; 866 break; 867 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 868 demph_reg_value = 0x2B404040; 869 uniqtranscale_reg_value = 0x55ADDA3A; 870 break; 871 default: 872 return; 873 } 874 break; 875 case DP_TRAIN_PRE_EMPH_LEVEL_2: 876 preemph_reg_value = 0x0000000; 877 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 878 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 879 demph_reg_value = 0x2B305555; 880 uniqtranscale_reg_value = 0x5570B83A; 881 break; 882 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 883 demph_reg_value = 0x2B2B4040; 884 uniqtranscale_reg_value = 0x55ADDA3A; 885 break; 886 default: 887 return; 888 } 889 break; 890 case DP_TRAIN_PRE_EMPH_LEVEL_3: 891 preemph_reg_value = 0x0006000; 892 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 893 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 894 demph_reg_value = 0x1B405555; 895 uniqtranscale_reg_value = 0x55ADDA3A; 896 break; 897 default: 898 return; 899 } 900 break; 901 default: 902 return; 903 } 904 905 vlv_set_phy_signal_level(encoder, crtc_state, 906 demph_reg_value, preemph_reg_value, 907 uniqtranscale_reg_value, 0); 908 } 909 910 static void chv_set_signal_levels(struct intel_encoder *encoder, 911 const struct intel_crtc_state *crtc_state) 912 { 913 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 914 u32 deemph_reg_value, margin_reg_value; 915 bool uniq_trans_scale = false; 916 u8 train_set = intel_dp->train_set[0]; 917 918 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { 919 case DP_TRAIN_PRE_EMPH_LEVEL_0: 920 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 921 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 922 deemph_reg_value = 128; 923 margin_reg_value = 52; 924 break; 925 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 926 deemph_reg_value = 128; 927 margin_reg_value = 77; 928 break; 929 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 930 deemph_reg_value = 128; 931 margin_reg_value = 102; 932 break; 933 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: 934 deemph_reg_value = 128; 935 margin_reg_value = 154; 936 uniq_trans_scale = true; 937 break; 938 default: 939 return; 940 } 941 break; 942 case DP_TRAIN_PRE_EMPH_LEVEL_1: 943 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 944 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 945 deemph_reg_value = 85; 946 margin_reg_value = 78; 947 break; 948 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 949 deemph_reg_value = 85; 950 margin_reg_value = 116; 951 break; 952 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 953 deemph_reg_value = 85; 954 margin_reg_value = 154; 955 break; 956 default: 957 return; 958 } 959 break; 960 case DP_TRAIN_PRE_EMPH_LEVEL_2: 961 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 962 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 963 deemph_reg_value = 64; 964 margin_reg_value = 104; 965 break; 966 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 967 deemph_reg_value = 64; 968 margin_reg_value = 154; 969 break; 970 default: 971 return; 972 } 973 break; 974 case DP_TRAIN_PRE_EMPH_LEVEL_3: 975 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 976 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 977 deemph_reg_value = 43; 978 margin_reg_value = 154; 979 break; 980 default: 981 return; 982 } 983 break; 984 default: 985 return; 986 } 987 988 chv_set_phy_signal_level(encoder, crtc_state, 989 deemph_reg_value, margin_reg_value, 990 uniq_trans_scale); 991 } 992 993 static u32 g4x_signal_levels(u8 train_set) 994 { 995 u32 signal_levels = 0; 996 997 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) { 998 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 999 default: 1000 signal_levels |= DP_VOLTAGE_0_4; 1001 break; 1002 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 1003 signal_levels |= DP_VOLTAGE_0_6; 1004 break; 1005 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 1006 signal_levels |= DP_VOLTAGE_0_8; 1007 break; 1008 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: 1009 signal_levels |= DP_VOLTAGE_1_2; 1010 break; 1011 } 1012 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) { 1013 case DP_TRAIN_PRE_EMPH_LEVEL_0: 1014 default: 1015 signal_levels |= DP_PRE_EMPHASIS_0; 1016 break; 1017 case DP_TRAIN_PRE_EMPH_LEVEL_1: 1018 signal_levels |= DP_PRE_EMPHASIS_3_5; 1019 break; 1020 case DP_TRAIN_PRE_EMPH_LEVEL_2: 1021 signal_levels |= DP_PRE_EMPHASIS_6; 1022 break; 1023 case DP_TRAIN_PRE_EMPH_LEVEL_3: 1024 signal_levels |= DP_PRE_EMPHASIS_9_5; 1025 break; 1026 } 1027 return signal_levels; 1028 } 1029 1030 static void 1031 g4x_set_signal_levels(struct intel_encoder *encoder, 1032 const struct intel_crtc_state *crtc_state) 1033 { 1034 struct intel_display *display = to_intel_display(encoder); 1035 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1036 u8 train_set = intel_dp->train_set[0]; 1037 u32 signal_levels; 1038 1039 signal_levels = g4x_signal_levels(train_set); 1040 1041 drm_dbg_kms(display->drm, "Using signal levels %08x\n", 1042 signal_levels); 1043 1044 intel_dp->DP &= ~(DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK); 1045 intel_dp->DP |= signal_levels; 1046 1047 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 1048 intel_de_posting_read(display, intel_dp->output_reg); 1049 } 1050 1051 /* SNB CPU eDP voltage swing and pre-emphasis control */ 1052 static u32 snb_cpu_edp_signal_levels(u8 train_set) 1053 { 1054 u8 signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | 1055 DP_TRAIN_PRE_EMPHASIS_MASK); 1056 1057 switch (signal_levels) { 1058 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1059 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1060 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; 1061 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1062 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B; 1063 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: 1064 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2: 1065 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B; 1066 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1067 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1068 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B; 1069 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1070 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1071 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B; 1072 default: 1073 MISSING_CASE(signal_levels); 1074 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B; 1075 } 1076 } 1077 1078 static void 1079 snb_cpu_edp_set_signal_levels(struct intel_encoder *encoder, 1080 const struct intel_crtc_state *crtc_state) 1081 { 1082 struct intel_display *display = to_intel_display(encoder); 1083 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1084 u8 train_set = intel_dp->train_set[0]; 1085 u32 signal_levels; 1086 1087 signal_levels = snb_cpu_edp_signal_levels(train_set); 1088 1089 drm_dbg_kms(display->drm, "Using signal levels %08x\n", 1090 signal_levels); 1091 1092 intel_dp->DP &= ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB; 1093 intel_dp->DP |= signal_levels; 1094 1095 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 1096 intel_de_posting_read(display, intel_dp->output_reg); 1097 } 1098 1099 /* IVB CPU eDP voltage swing and pre-emphasis control */ 1100 static u32 ivb_cpu_edp_signal_levels(u8 train_set) 1101 { 1102 u8 signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | 1103 DP_TRAIN_PRE_EMPHASIS_MASK); 1104 1105 switch (signal_levels) { 1106 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1107 return EDP_LINK_TRAIN_400MV_0DB_IVB; 1108 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1109 return EDP_LINK_TRAIN_400MV_3_5DB_IVB; 1110 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2: 1111 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2: 1112 return EDP_LINK_TRAIN_400MV_6DB_IVB; 1113 1114 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1115 return EDP_LINK_TRAIN_600MV_0DB_IVB; 1116 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1117 return EDP_LINK_TRAIN_600MV_3_5DB_IVB; 1118 1119 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0: 1120 return EDP_LINK_TRAIN_800MV_0DB_IVB; 1121 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1: 1122 return EDP_LINK_TRAIN_800MV_3_5DB_IVB; 1123 1124 default: 1125 MISSING_CASE(signal_levels); 1126 return EDP_LINK_TRAIN_500MV_0DB_IVB; 1127 } 1128 } 1129 1130 static void 1131 ivb_cpu_edp_set_signal_levels(struct intel_encoder *encoder, 1132 const struct intel_crtc_state *crtc_state) 1133 { 1134 struct intel_display *display = to_intel_display(encoder); 1135 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1136 u8 train_set = intel_dp->train_set[0]; 1137 u32 signal_levels; 1138 1139 signal_levels = ivb_cpu_edp_signal_levels(train_set); 1140 1141 drm_dbg_kms(display->drm, "Using signal levels %08x\n", 1142 signal_levels); 1143 1144 intel_dp->DP &= ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB; 1145 intel_dp->DP |= signal_levels; 1146 1147 intel_de_write(display, intel_dp->output_reg, intel_dp->DP); 1148 intel_de_posting_read(display, intel_dp->output_reg); 1149 } 1150 1151 /* 1152 * If display is now connected check links status, 1153 * there has been known issues of link loss triggering 1154 * long pulse. 1155 * 1156 * Some sinks (eg. ASUS PB287Q) seem to perform some 1157 * weird HPD ping pong during modesets. So we can apparently 1158 * end up with HPD going low during a modeset, and then 1159 * going back up soon after. And once that happens we must 1160 * retrain the link to get a picture. That's in case no 1161 * userspace component reacted to intermittent HPD dip. 1162 */ 1163 static enum intel_hotplug_state 1164 intel_dp_hotplug(struct intel_encoder *encoder, 1165 struct intel_connector *connector) 1166 { 1167 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1168 enum intel_hotplug_state state; 1169 1170 if (intel_dp_test_phy(intel_dp)) 1171 return INTEL_HOTPLUG_UNCHANGED; 1172 1173 state = intel_encoder_hotplug(encoder, connector); 1174 1175 intel_dp_check_link_state(intel_dp); 1176 1177 /* 1178 * Keeping it consistent with intel_ddi_hotplug() and 1179 * intel_hdmi_hotplug(). 1180 */ 1181 if (state == INTEL_HOTPLUG_UNCHANGED && !connector->hotplug_retries) 1182 state = INTEL_HOTPLUG_RETRY; 1183 1184 return state; 1185 } 1186 1187 static bool ibx_digital_port_connected(struct intel_encoder *encoder) 1188 { 1189 struct intel_display *display = to_intel_display(encoder); 1190 u32 bit = display->hotplug.pch_hpd[encoder->hpd_pin]; 1191 1192 return intel_de_read(display, SDEISR) & bit; 1193 } 1194 1195 static bool g4x_digital_port_connected(struct intel_encoder *encoder) 1196 { 1197 struct intel_display *display = to_intel_display(encoder); 1198 u32 bit; 1199 1200 switch (encoder->hpd_pin) { 1201 case HPD_PORT_B: 1202 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X; 1203 break; 1204 case HPD_PORT_C: 1205 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X; 1206 break; 1207 case HPD_PORT_D: 1208 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X; 1209 break; 1210 default: 1211 MISSING_CASE(encoder->hpd_pin); 1212 return false; 1213 } 1214 1215 return intel_de_read(display, PORT_HOTPLUG_STAT(display)) & bit; 1216 } 1217 1218 static bool ilk_digital_port_connected(struct intel_encoder *encoder) 1219 { 1220 struct intel_display *display = to_intel_display(encoder); 1221 u32 bit = display->hotplug.hpd[encoder->hpd_pin]; 1222 1223 return intel_de_read(display, DEISR) & bit; 1224 } 1225 1226 static int g4x_dp_compute_config(struct intel_encoder *encoder, 1227 struct intel_crtc_state *crtc_state, 1228 struct drm_connector_state *conn_state) 1229 { 1230 struct intel_display *display = to_intel_display(encoder); 1231 int ret; 1232 1233 if (HAS_PCH_SPLIT(display) && encoder->port != PORT_A) 1234 crtc_state->has_pch_encoder = true; 1235 1236 ret = intel_dp_compute_config(encoder, crtc_state, conn_state); 1237 if (ret) 1238 return ret; 1239 1240 g4x_dp_set_clock(encoder, crtc_state); 1241 1242 return 0; 1243 } 1244 1245 static void g4x_dp_suspend_complete(struct intel_encoder *encoder) 1246 { 1247 /* 1248 * TODO: Move this to intel_dp_encoder_suspend(), 1249 * once modeset locking around that is removed. 1250 */ 1251 intel_encoder_link_check_flush_work(encoder); 1252 } 1253 1254 static void intel_dp_encoder_destroy(struct drm_encoder *encoder) 1255 { 1256 intel_dp_encoder_flush_work(encoder); 1257 1258 drm_encoder_cleanup(encoder); 1259 kfree(enc_to_dig_port(to_intel_encoder(encoder))); 1260 } 1261 1262 static void intel_dp_encoder_reset(struct drm_encoder *encoder) 1263 { 1264 struct intel_display *display = to_intel_display(encoder->dev); 1265 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(encoder)); 1266 1267 intel_dp->DP = intel_de_read(display, intel_dp->output_reg); 1268 1269 intel_dp->reset_link_params = true; 1270 intel_dp_invalidate_source_oui(intel_dp); 1271 1272 if (display->platform.valleyview || display->platform.cherryview) 1273 vlv_pps_pipe_reset(intel_dp); 1274 1275 intel_pps_encoder_reset(intel_dp); 1276 } 1277 1278 static const struct drm_encoder_funcs intel_dp_enc_funcs = { 1279 .reset = intel_dp_encoder_reset, 1280 .destroy = intel_dp_encoder_destroy, 1281 }; 1282 1283 bool g4x_dp_init(struct intel_display *display, 1284 i915_reg_t output_reg, enum port port) 1285 { 1286 const struct intel_bios_encoder_data *devdata; 1287 struct intel_digital_port *dig_port; 1288 struct intel_encoder *intel_encoder; 1289 struct drm_encoder *encoder; 1290 struct intel_connector *intel_connector; 1291 1292 if (!assert_port_valid(display, port)) 1293 return false; 1294 1295 devdata = intel_bios_encoder_data_lookup(display, port); 1296 1297 /* FIXME bail? */ 1298 if (!devdata) 1299 drm_dbg_kms(display->drm, "No VBT child device for DP-%c\n", 1300 port_name(port)); 1301 1302 dig_port = intel_dig_port_alloc(); 1303 if (!dig_port) 1304 return false; 1305 1306 intel_connector = intel_connector_alloc(); 1307 if (!intel_connector) 1308 goto err_connector_alloc; 1309 1310 intel_encoder = &dig_port->base; 1311 encoder = &intel_encoder->base; 1312 1313 intel_encoder->devdata = devdata; 1314 1315 if (drm_encoder_init(display->drm, &intel_encoder->base, 1316 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS, 1317 "DP %c", port_name(port))) 1318 goto err_encoder_init; 1319 1320 intel_encoder_link_check_init(intel_encoder, intel_dp_link_check); 1321 1322 intel_encoder->hotplug = intel_dp_hotplug; 1323 intel_encoder->compute_config = g4x_dp_compute_config; 1324 intel_encoder->get_hw_state = intel_dp_get_hw_state; 1325 intel_encoder->get_config = intel_dp_get_config; 1326 intel_encoder->sync_state = intel_dp_sync_state; 1327 intel_encoder->initial_fastset_check = intel_dp_initial_fastset_check; 1328 intel_encoder->update_pipe = intel_backlight_update; 1329 intel_encoder->suspend = intel_dp_encoder_suspend; 1330 intel_encoder->suspend_complete = g4x_dp_suspend_complete; 1331 intel_encoder->shutdown = intel_dp_encoder_shutdown; 1332 if (display->platform.cherryview) { 1333 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable; 1334 intel_encoder->pre_enable = chv_pre_enable_dp; 1335 intel_encoder->enable = vlv_enable_dp; 1336 intel_encoder->disable = vlv_disable_dp; 1337 intel_encoder->post_disable = chv_post_disable_dp; 1338 intel_encoder->post_pll_disable = chv_dp_post_pll_disable; 1339 } else if (display->platform.valleyview) { 1340 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable; 1341 intel_encoder->pre_enable = vlv_pre_enable_dp; 1342 intel_encoder->enable = vlv_enable_dp; 1343 intel_encoder->disable = vlv_disable_dp; 1344 intel_encoder->post_disable = vlv_post_disable_dp; 1345 } else { 1346 intel_encoder->pre_enable = g4x_pre_enable_dp; 1347 intel_encoder->enable = g4x_enable_dp; 1348 intel_encoder->disable = g4x_disable_dp; 1349 intel_encoder->post_disable = g4x_post_disable_dp; 1350 } 1351 intel_encoder->audio_enable = g4x_dp_audio_enable; 1352 intel_encoder->audio_disable = g4x_dp_audio_disable; 1353 1354 if ((display->platform.ivybridge && port == PORT_A) || 1355 (HAS_PCH_CPT(display) && port != PORT_A)) { 1356 dig_port->dp.set_link_train = cpt_set_link_train; 1357 dig_port->dp.set_idle_link_train = cpt_set_idle_link_train; 1358 } else { 1359 dig_port->dp.set_link_train = g4x_set_link_train; 1360 dig_port->dp.set_idle_link_train = g4x_set_idle_link_train; 1361 } 1362 1363 if (display->platform.cherryview) 1364 intel_encoder->set_signal_levels = chv_set_signal_levels; 1365 else if (display->platform.valleyview) 1366 intel_encoder->set_signal_levels = vlv_set_signal_levels; 1367 else if (display->platform.ivybridge && port == PORT_A) 1368 intel_encoder->set_signal_levels = ivb_cpu_edp_set_signal_levels; 1369 else if (display->platform.sandybridge && port == PORT_A) 1370 intel_encoder->set_signal_levels = snb_cpu_edp_set_signal_levels; 1371 else 1372 intel_encoder->set_signal_levels = g4x_set_signal_levels; 1373 1374 if (display->platform.valleyview || display->platform.cherryview || 1375 (HAS_PCH_SPLIT(display) && port != PORT_A)) { 1376 dig_port->dp.preemph_max = intel_dp_preemph_max_3; 1377 dig_port->dp.voltage_max = intel_dp_voltage_max_3; 1378 } else { 1379 dig_port->dp.preemph_max = intel_dp_preemph_max_2; 1380 dig_port->dp.voltage_max = intel_dp_voltage_max_2; 1381 } 1382 1383 dig_port->dp.output_reg = output_reg; 1384 1385 intel_encoder->type = INTEL_OUTPUT_DP; 1386 intel_encoder->power_domain = intel_display_power_ddi_lanes_domain(display, port); 1387 if (display->platform.cherryview) { 1388 if (port == PORT_D) 1389 intel_encoder->pipe_mask = BIT(PIPE_C); 1390 else 1391 intel_encoder->pipe_mask = BIT(PIPE_A) | BIT(PIPE_B); 1392 } else { 1393 intel_encoder->pipe_mask = ~0; 1394 } 1395 intel_encoder->cloneable = 0; 1396 intel_encoder->port = port; 1397 intel_encoder->hpd_pin = intel_hpd_pin_default(port); 1398 1399 dig_port->hpd_pulse = intel_dp_hpd_pulse; 1400 1401 if (HAS_GMCH(display)) { 1402 dig_port->connected = g4x_digital_port_connected; 1403 } else { 1404 if (port == PORT_A) 1405 dig_port->connected = ilk_digital_port_connected; 1406 else 1407 dig_port->connected = ibx_digital_port_connected; 1408 } 1409 1410 if (port != PORT_A) 1411 intel_infoframe_init(dig_port); 1412 1413 dig_port->aux_ch = intel_dp_aux_ch(intel_encoder); 1414 if (dig_port->aux_ch == AUX_CH_NONE) 1415 goto err_init_connector; 1416 1417 if (!intel_dp_init_connector(dig_port, intel_connector)) 1418 goto err_init_connector; 1419 1420 return true; 1421 1422 err_init_connector: 1423 drm_encoder_cleanup(encoder); 1424 err_encoder_init: 1425 kfree(intel_connector); 1426 err_connector_alloc: 1427 kfree(dig_port); 1428 return false; 1429 } 1430