1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2020 Intel Corporation 4 * 5 * HDMI support for G4x,ILK,SNB,IVB,VLV,CHV (HSW+ handled by the DDI code). 6 */ 7 8 #include "g4x_hdmi.h" 9 #include "i915_drv.h" 10 #include "i915_reg.h" 11 #include "intel_atomic.h" 12 #include "intel_audio.h" 13 #include "intel_connector.h" 14 #include "intel_crtc.h" 15 #include "intel_de.h" 16 #include "intel_display_power.h" 17 #include "intel_display_types.h" 18 #include "intel_dp_aux.h" 19 #include "intel_dpio_phy.h" 20 #include "intel_fdi.h" 21 #include "intel_fifo_underrun.h" 22 #include "intel_hdmi.h" 23 #include "intel_hotplug.h" 24 #include "intel_sdvo.h" 25 #include "vlv_sideband.h" 26 27 static void intel_hdmi_prepare(struct intel_encoder *encoder, 28 const struct intel_crtc_state *crtc_state) 29 { 30 struct drm_device *dev = encoder->base.dev; 31 struct drm_i915_private *dev_priv = to_i915(dev); 32 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 33 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 34 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 35 u32 hdmi_val; 36 37 intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); 38 39 hdmi_val = SDVO_ENCODING_HDMI; 40 if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range) 41 hdmi_val |= HDMI_COLOR_RANGE_16_235; 42 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) 43 hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH; 44 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) 45 hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH; 46 47 if (crtc_state->pipe_bpp > 24) 48 hdmi_val |= HDMI_COLOR_FORMAT_12bpc; 49 else 50 hdmi_val |= SDVO_COLOR_FORMAT_8bpc; 51 52 if (crtc_state->has_hdmi_sink) 53 hdmi_val |= HDMI_MODE_SELECT_HDMI; 54 55 if (HAS_PCH_CPT(dev_priv)) 56 hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe); 57 else if (IS_CHERRYVIEW(dev_priv)) 58 hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe); 59 else 60 hdmi_val |= SDVO_PIPE_SEL(crtc->pipe); 61 62 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, hdmi_val); 63 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 64 } 65 66 static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder, 67 enum pipe *pipe) 68 { 69 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 70 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 71 intel_wakeref_t wakeref; 72 bool ret; 73 74 wakeref = intel_display_power_get_if_enabled(dev_priv, 75 encoder->power_domain); 76 if (!wakeref) 77 return false; 78 79 ret = intel_sdvo_port_enabled(dev_priv, intel_hdmi->hdmi_reg, pipe); 80 81 intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 82 83 return ret; 84 } 85 86 static bool connector_is_hdmi(struct drm_connector *connector) 87 { 88 struct intel_encoder *encoder = 89 intel_attached_encoder(to_intel_connector(connector)); 90 91 return encoder && encoder->type == INTEL_OUTPUT_HDMI; 92 } 93 94 static bool g4x_compute_has_hdmi_sink(struct intel_atomic_state *state, 95 struct intel_crtc *this_crtc) 96 { 97 const struct drm_connector_state *conn_state; 98 struct drm_connector *connector; 99 int i; 100 101 /* 102 * On g4x only one HDMI port can transmit infoframes/audio at 103 * any given time. Select the first suitable port for this duty. 104 * 105 * See also g4x_hdmi_connector_atomic_check(). 106 */ 107 for_each_new_connector_in_state(&state->base, connector, conn_state, i) { 108 struct intel_encoder *encoder = to_intel_encoder(conn_state->best_encoder); 109 const struct intel_crtc_state *crtc_state; 110 struct intel_crtc *crtc; 111 112 if (!connector_is_hdmi(connector)) 113 continue; 114 115 crtc = to_intel_crtc(conn_state->crtc); 116 if (!crtc) 117 continue; 118 119 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 120 121 if (!intel_hdmi_compute_has_hdmi_sink(encoder, crtc_state, conn_state)) 122 continue; 123 124 return crtc == this_crtc; 125 } 126 127 return false; 128 } 129 130 static int g4x_hdmi_compute_config(struct intel_encoder *encoder, 131 struct intel_crtc_state *crtc_state, 132 struct drm_connector_state *conn_state) 133 { 134 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state); 135 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 136 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 137 138 if (HAS_PCH_SPLIT(i915)) { 139 crtc_state->has_pch_encoder = true; 140 if (!intel_fdi_compute_pipe_bpp(crtc_state)) 141 return -EINVAL; 142 } 143 144 if (IS_G4X(i915)) 145 crtc_state->has_hdmi_sink = g4x_compute_has_hdmi_sink(state, crtc); 146 else 147 crtc_state->has_hdmi_sink = 148 intel_hdmi_compute_has_hdmi_sink(encoder, crtc_state, conn_state); 149 150 return intel_hdmi_compute_config(encoder, crtc_state, conn_state); 151 } 152 153 static void intel_hdmi_get_config(struct intel_encoder *encoder, 154 struct intel_crtc_state *pipe_config) 155 { 156 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 157 struct drm_device *dev = encoder->base.dev; 158 struct drm_i915_private *dev_priv = to_i915(dev); 159 u32 tmp, flags = 0; 160 int dotclock; 161 162 pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI); 163 164 tmp = intel_de_read(dev_priv, intel_hdmi->hdmi_reg); 165 166 if (tmp & SDVO_HSYNC_ACTIVE_HIGH) 167 flags |= DRM_MODE_FLAG_PHSYNC; 168 else 169 flags |= DRM_MODE_FLAG_NHSYNC; 170 171 if (tmp & SDVO_VSYNC_ACTIVE_HIGH) 172 flags |= DRM_MODE_FLAG_PVSYNC; 173 else 174 flags |= DRM_MODE_FLAG_NVSYNC; 175 176 if (tmp & HDMI_MODE_SELECT_HDMI) 177 pipe_config->has_hdmi_sink = true; 178 179 pipe_config->infoframes.enable |= 180 intel_hdmi_infoframes_enabled(encoder, pipe_config); 181 182 if (pipe_config->infoframes.enable) 183 pipe_config->has_infoframe = true; 184 185 if (tmp & HDMI_AUDIO_ENABLE) 186 pipe_config->has_audio = true; 187 188 if (!HAS_PCH_SPLIT(dev_priv) && 189 tmp & HDMI_COLOR_RANGE_16_235) 190 pipe_config->limited_color_range = true; 191 192 pipe_config->hw.adjusted_mode.flags |= flags; 193 194 if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc) 195 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 2, 3); 196 else 197 dotclock = pipe_config->port_clock; 198 199 if (pipe_config->pixel_multiplier) 200 dotclock /= pipe_config->pixel_multiplier; 201 202 pipe_config->hw.adjusted_mode.crtc_clock = dotclock; 203 204 pipe_config->lane_count = 4; 205 206 intel_hdmi_read_gcp_infoframe(encoder, pipe_config); 207 208 intel_read_infoframe(encoder, pipe_config, 209 HDMI_INFOFRAME_TYPE_AVI, 210 &pipe_config->infoframes.avi); 211 intel_read_infoframe(encoder, pipe_config, 212 HDMI_INFOFRAME_TYPE_SPD, 213 &pipe_config->infoframes.spd); 214 intel_read_infoframe(encoder, pipe_config, 215 HDMI_INFOFRAME_TYPE_VENDOR, 216 &pipe_config->infoframes.hdmi); 217 218 intel_audio_codec_get_config(encoder, pipe_config); 219 } 220 221 static void g4x_hdmi_enable_port(struct intel_encoder *encoder, 222 const struct intel_crtc_state *pipe_config) 223 { 224 struct drm_device *dev = encoder->base.dev; 225 struct drm_i915_private *dev_priv = to_i915(dev); 226 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 227 u32 temp; 228 229 temp = intel_de_read(dev_priv, intel_hdmi->hdmi_reg); 230 231 temp |= SDVO_ENABLE; 232 233 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 234 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 235 } 236 237 static void g4x_hdmi_audio_enable(struct intel_encoder *encoder, 238 const struct intel_crtc_state *crtc_state, 239 const struct drm_connector_state *conn_state) 240 { 241 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 242 struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 243 244 if (!crtc_state->has_audio) 245 return; 246 247 drm_WARN_ON(&i915->drm, !crtc_state->has_hdmi_sink); 248 249 /* Enable audio presence detect */ 250 intel_de_rmw(i915, hdmi->hdmi_reg, 0, HDMI_AUDIO_ENABLE); 251 252 intel_audio_codec_enable(encoder, crtc_state, conn_state); 253 } 254 255 static void g4x_hdmi_audio_disable(struct intel_encoder *encoder, 256 const struct intel_crtc_state *old_crtc_state, 257 const struct drm_connector_state *old_conn_state) 258 { 259 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 260 struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 261 262 if (!old_crtc_state->has_audio) 263 return; 264 265 intel_audio_codec_disable(encoder, old_crtc_state, old_conn_state); 266 267 /* Disable audio presence detect */ 268 intel_de_rmw(i915, hdmi->hdmi_reg, HDMI_AUDIO_ENABLE, 0); 269 } 270 271 static void g4x_enable_hdmi(struct intel_atomic_state *state, 272 struct intel_encoder *encoder, 273 const struct intel_crtc_state *pipe_config, 274 const struct drm_connector_state *conn_state) 275 { 276 g4x_hdmi_enable_port(encoder, pipe_config); 277 } 278 279 static void ibx_enable_hdmi(struct intel_atomic_state *state, 280 struct intel_encoder *encoder, 281 const struct intel_crtc_state *pipe_config, 282 const struct drm_connector_state *conn_state) 283 { 284 struct drm_device *dev = encoder->base.dev; 285 struct drm_i915_private *dev_priv = to_i915(dev); 286 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 287 u32 temp; 288 289 temp = intel_de_read(dev_priv, intel_hdmi->hdmi_reg); 290 291 temp |= SDVO_ENABLE; 292 293 /* 294 * HW workaround, need to write this twice for issue 295 * that may result in first write getting masked. 296 */ 297 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 298 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 299 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 300 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 301 302 /* 303 * HW workaround, need to toggle enable bit off and on 304 * for 12bpc with pixel repeat. 305 * 306 * FIXME: BSpec says this should be done at the end of 307 * the modeset sequence, so not sure if this isn't too soon. 308 */ 309 if (pipe_config->pipe_bpp > 24 && 310 pipe_config->pixel_multiplier > 1) { 311 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, 312 temp & ~SDVO_ENABLE); 313 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 314 315 /* 316 * HW workaround, need to write this twice for issue 317 * that may result in first write getting masked. 318 */ 319 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 320 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 321 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 322 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 323 } 324 } 325 326 static void cpt_enable_hdmi(struct intel_atomic_state *state, 327 struct intel_encoder *encoder, 328 const struct intel_crtc_state *pipe_config, 329 const struct drm_connector_state *conn_state) 330 { 331 struct drm_device *dev = encoder->base.dev; 332 struct drm_i915_private *dev_priv = to_i915(dev); 333 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 334 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 335 enum pipe pipe = crtc->pipe; 336 u32 temp; 337 338 temp = intel_de_read(dev_priv, intel_hdmi->hdmi_reg); 339 340 temp |= SDVO_ENABLE; 341 342 /* 343 * WaEnableHDMI8bpcBefore12bpc:snb,ivb 344 * 345 * The procedure for 12bpc is as follows: 346 * 1. disable HDMI clock gating 347 * 2. enable HDMI with 8bpc 348 * 3. enable HDMI with 12bpc 349 * 4. enable HDMI clock gating 350 */ 351 352 if (pipe_config->pipe_bpp > 24) { 353 intel_de_rmw(dev_priv, TRANS_CHICKEN1(pipe), 354 0, TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE); 355 356 temp &= ~SDVO_COLOR_FORMAT_MASK; 357 temp |= SDVO_COLOR_FORMAT_8bpc; 358 } 359 360 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 361 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 362 363 if (pipe_config->pipe_bpp > 24) { 364 temp &= ~SDVO_COLOR_FORMAT_MASK; 365 temp |= HDMI_COLOR_FORMAT_12bpc; 366 367 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 368 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 369 370 intel_de_rmw(dev_priv, TRANS_CHICKEN1(pipe), 371 TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE, 0); 372 } 373 } 374 375 static void vlv_enable_hdmi(struct intel_atomic_state *state, 376 struct intel_encoder *encoder, 377 const struct intel_crtc_state *pipe_config, 378 const struct drm_connector_state *conn_state) 379 { 380 } 381 382 static void intel_disable_hdmi(struct intel_atomic_state *state, 383 struct intel_encoder *encoder, 384 const struct intel_crtc_state *old_crtc_state, 385 const struct drm_connector_state *old_conn_state) 386 { 387 struct drm_device *dev = encoder->base.dev; 388 struct drm_i915_private *dev_priv = to_i915(dev); 389 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 390 struct intel_digital_port *dig_port = 391 hdmi_to_dig_port(intel_hdmi); 392 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 393 u32 temp; 394 395 temp = intel_de_read(dev_priv, intel_hdmi->hdmi_reg); 396 397 temp &= ~SDVO_ENABLE; 398 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 399 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 400 401 /* 402 * HW workaround for IBX, we need to move the port 403 * to transcoder A after disabling it to allow the 404 * matching DP port to be enabled on transcoder A. 405 */ 406 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) { 407 /* 408 * We get CPU/PCH FIFO underruns on the other pipe when 409 * doing the workaround. Sweep them under the rug. 410 */ 411 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false); 412 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false); 413 414 temp &= ~SDVO_PIPE_SEL_MASK; 415 temp |= SDVO_ENABLE | SDVO_PIPE_SEL(PIPE_A); 416 /* 417 * HW workaround, need to write this twice for issue 418 * that may result in first write getting masked. 419 */ 420 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 421 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 422 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 423 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 424 425 temp &= ~SDVO_ENABLE; 426 intel_de_write(dev_priv, intel_hdmi->hdmi_reg, temp); 427 intel_de_posting_read(dev_priv, intel_hdmi->hdmi_reg); 428 429 intel_wait_for_vblank_if_active(dev_priv, PIPE_A); 430 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true); 431 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true); 432 } 433 434 dig_port->set_infoframes(encoder, 435 false, 436 old_crtc_state, old_conn_state); 437 438 intel_dp_dual_mode_set_tmds_output(intel_hdmi, false); 439 } 440 441 static void g4x_disable_hdmi(struct intel_atomic_state *state, 442 struct intel_encoder *encoder, 443 const struct intel_crtc_state *old_crtc_state, 444 const struct drm_connector_state *old_conn_state) 445 { 446 intel_disable_hdmi(state, encoder, old_crtc_state, old_conn_state); 447 } 448 449 static void pch_disable_hdmi(struct intel_atomic_state *state, 450 struct intel_encoder *encoder, 451 const struct intel_crtc_state *old_crtc_state, 452 const struct drm_connector_state *old_conn_state) 453 { 454 } 455 456 static void pch_post_disable_hdmi(struct intel_atomic_state *state, 457 struct intel_encoder *encoder, 458 const struct intel_crtc_state *old_crtc_state, 459 const struct drm_connector_state *old_conn_state) 460 { 461 intel_disable_hdmi(state, encoder, old_crtc_state, old_conn_state); 462 } 463 464 static void intel_hdmi_pre_enable(struct intel_atomic_state *state, 465 struct intel_encoder *encoder, 466 const struct intel_crtc_state *pipe_config, 467 const struct drm_connector_state *conn_state) 468 { 469 struct intel_digital_port *dig_port = 470 enc_to_dig_port(encoder); 471 472 intel_hdmi_prepare(encoder, pipe_config); 473 474 dig_port->set_infoframes(encoder, 475 pipe_config->has_infoframe, 476 pipe_config, conn_state); 477 } 478 479 static void vlv_hdmi_pre_enable(struct intel_atomic_state *state, 480 struct intel_encoder *encoder, 481 const struct intel_crtc_state *pipe_config, 482 const struct drm_connector_state *conn_state) 483 { 484 struct intel_display *display = to_intel_display(encoder); 485 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 486 487 vlv_phy_pre_encoder_enable(encoder, pipe_config); 488 489 /* HDMI 1.0V-2dB */ 490 vlv_set_phy_signal_level(encoder, pipe_config, 491 0x2b245f5f, 0x00002000, 492 0x5578b83a, 0x2b247878); 493 494 dig_port->set_infoframes(encoder, 495 pipe_config->has_infoframe, 496 pipe_config, conn_state); 497 498 g4x_hdmi_enable_port(encoder, pipe_config); 499 500 vlv_wait_port_ready(display, dig_port, 0x0); 501 } 502 503 static void vlv_hdmi_pre_pll_enable(struct intel_atomic_state *state, 504 struct intel_encoder *encoder, 505 const struct intel_crtc_state *pipe_config, 506 const struct drm_connector_state *conn_state) 507 { 508 intel_hdmi_prepare(encoder, pipe_config); 509 510 vlv_phy_pre_pll_enable(encoder, pipe_config); 511 } 512 513 static void chv_hdmi_pre_pll_enable(struct intel_atomic_state *state, 514 struct intel_encoder *encoder, 515 const struct intel_crtc_state *pipe_config, 516 const struct drm_connector_state *conn_state) 517 { 518 intel_hdmi_prepare(encoder, pipe_config); 519 520 chv_phy_pre_pll_enable(encoder, pipe_config); 521 } 522 523 static void chv_hdmi_post_pll_disable(struct intel_atomic_state *state, 524 struct intel_encoder *encoder, 525 const struct intel_crtc_state *old_crtc_state, 526 const struct drm_connector_state *old_conn_state) 527 { 528 chv_phy_post_pll_disable(encoder, old_crtc_state); 529 } 530 531 static void vlv_hdmi_post_disable(struct intel_atomic_state *state, 532 struct intel_encoder *encoder, 533 const struct intel_crtc_state *old_crtc_state, 534 const struct drm_connector_state *old_conn_state) 535 { 536 /* Reset lanes to avoid HDMI flicker (VLV w/a) */ 537 vlv_phy_reset_lanes(encoder, old_crtc_state); 538 } 539 540 static void chv_hdmi_post_disable(struct intel_atomic_state *state, 541 struct intel_encoder *encoder, 542 const struct intel_crtc_state *old_crtc_state, 543 const struct drm_connector_state *old_conn_state) 544 { 545 struct drm_device *dev = encoder->base.dev; 546 struct drm_i915_private *dev_priv = to_i915(dev); 547 548 vlv_dpio_get(dev_priv); 549 550 /* Assert data lane reset */ 551 chv_data_lane_soft_reset(encoder, old_crtc_state, true); 552 553 vlv_dpio_put(dev_priv); 554 } 555 556 static void chv_hdmi_pre_enable(struct intel_atomic_state *state, 557 struct intel_encoder *encoder, 558 const struct intel_crtc_state *pipe_config, 559 const struct drm_connector_state *conn_state) 560 { 561 struct intel_display *display = to_intel_display(encoder); 562 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 563 564 chv_phy_pre_encoder_enable(encoder, pipe_config); 565 566 /* FIXME: Program the support xxx V-dB */ 567 /* Use 800mV-0dB */ 568 chv_set_phy_signal_level(encoder, pipe_config, 128, 102, false); 569 570 dig_port->set_infoframes(encoder, 571 pipe_config->has_infoframe, 572 pipe_config, conn_state); 573 574 g4x_hdmi_enable_port(encoder, pipe_config); 575 576 vlv_wait_port_ready(display, dig_port, 0x0); 577 578 /* Second common lane will stay alive on its own now */ 579 chv_phy_release_cl2_override(encoder); 580 } 581 582 static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { 583 .destroy = intel_encoder_destroy, 584 }; 585 586 static enum intel_hotplug_state 587 intel_hdmi_hotplug(struct intel_encoder *encoder, 588 struct intel_connector *connector) 589 { 590 enum intel_hotplug_state state; 591 592 state = intel_encoder_hotplug(encoder, connector); 593 594 /* 595 * On many platforms the HDMI live state signal is known to be 596 * unreliable, so we can't use it to detect if a sink is connected or 597 * not. Instead we detect if it's connected based on whether we can 598 * read the EDID or not. That in turn has a problem during disconnect, 599 * since the HPD interrupt may be raised before the DDC lines get 600 * disconnected (due to how the required length of DDC vs. HPD 601 * connector pins are specified) and so we'll still be able to get a 602 * valid EDID. To solve this schedule another detection cycle if this 603 * time around we didn't detect any change in the sink's connection 604 * status. 605 */ 606 if (state == INTEL_HOTPLUG_UNCHANGED && !connector->hotplug_retries) 607 state = INTEL_HOTPLUG_RETRY; 608 609 return state; 610 } 611 612 int g4x_hdmi_connector_atomic_check(struct drm_connector *connector, 613 struct drm_atomic_state *state) 614 { 615 struct drm_i915_private *i915 = to_i915(state->dev); 616 struct drm_connector_list_iter conn_iter; 617 struct drm_connector *conn; 618 int ret; 619 620 ret = intel_digital_connector_atomic_check(connector, state); 621 if (ret) 622 return ret; 623 624 if (!IS_G4X(i915)) 625 return 0; 626 627 if (!intel_connector_needs_modeset(to_intel_atomic_state(state), connector)) 628 return 0; 629 630 /* 631 * On g4x only one HDMI port can transmit infoframes/audio 632 * at any given time. Make sure all enabled HDMI ports are 633 * included in the state so that it's possible to select 634 * one of them for this duty. 635 * 636 * See also g4x_compute_has_hdmi_sink(). 637 */ 638 drm_connector_list_iter_begin(&i915->drm, &conn_iter); 639 drm_for_each_connector_iter(conn, &conn_iter) { 640 struct drm_connector_state *conn_state; 641 struct drm_crtc_state *crtc_state; 642 struct drm_crtc *crtc; 643 644 if (!connector_is_hdmi(conn)) 645 continue; 646 647 drm_dbg_kms(&i915->drm, "Adding [CONNECTOR:%d:%s]\n", 648 conn->base.id, conn->name); 649 650 conn_state = drm_atomic_get_connector_state(state, conn); 651 if (IS_ERR(conn_state)) { 652 ret = PTR_ERR(conn_state); 653 break; 654 } 655 656 crtc = conn_state->crtc; 657 if (!crtc) 658 continue; 659 660 crtc_state = drm_atomic_get_new_crtc_state(state, crtc); 661 crtc_state->mode_changed = true; 662 663 ret = drm_atomic_add_affected_planes(state, crtc); 664 if (ret) 665 break; 666 } 667 drm_connector_list_iter_end(&conn_iter); 668 669 return ret; 670 } 671 672 static bool is_hdmi_port_valid(struct drm_i915_private *i915, enum port port) 673 { 674 if (IS_G4X(i915) || IS_VALLEYVIEW(i915)) 675 return port == PORT_B || port == PORT_C; 676 else 677 return port == PORT_B || port == PORT_C || port == PORT_D; 678 } 679 680 static bool assert_hdmi_port_valid(struct drm_i915_private *i915, enum port port) 681 { 682 return !drm_WARN(&i915->drm, !is_hdmi_port_valid(i915, port), 683 "Platform does not support HDMI %c\n", port_name(port)); 684 } 685 686 bool g4x_hdmi_init(struct drm_i915_private *dev_priv, 687 i915_reg_t hdmi_reg, enum port port) 688 { 689 struct intel_display *display = &dev_priv->display; 690 const struct intel_bios_encoder_data *devdata; 691 struct intel_digital_port *dig_port; 692 struct intel_encoder *intel_encoder; 693 struct intel_connector *intel_connector; 694 695 if (!assert_port_valid(dev_priv, port)) 696 return false; 697 698 if (!assert_hdmi_port_valid(dev_priv, port)) 699 return false; 700 701 devdata = intel_bios_encoder_data_lookup(display, port); 702 703 /* FIXME bail? */ 704 if (!devdata) 705 drm_dbg_kms(&dev_priv->drm, "No VBT child device for HDMI-%c\n", 706 port_name(port)); 707 708 dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL); 709 if (!dig_port) 710 return false; 711 712 dig_port->aux_ch = AUX_CH_NONE; 713 714 intel_connector = intel_connector_alloc(); 715 if (!intel_connector) 716 goto err_connector_alloc; 717 718 intel_encoder = &dig_port->base; 719 720 intel_encoder->devdata = devdata; 721 722 mutex_init(&dig_port->hdcp_mutex); 723 724 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base, 725 &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS, 726 "HDMI %c", port_name(port))) 727 goto err_encoder_init; 728 729 intel_encoder->hotplug = intel_hdmi_hotplug; 730 intel_encoder->compute_config = g4x_hdmi_compute_config; 731 if (HAS_PCH_SPLIT(dev_priv)) { 732 intel_encoder->disable = pch_disable_hdmi; 733 intel_encoder->post_disable = pch_post_disable_hdmi; 734 } else { 735 intel_encoder->disable = g4x_disable_hdmi; 736 } 737 intel_encoder->get_hw_state = intel_hdmi_get_hw_state; 738 intel_encoder->get_config = intel_hdmi_get_config; 739 if (IS_CHERRYVIEW(dev_priv)) { 740 intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable; 741 intel_encoder->pre_enable = chv_hdmi_pre_enable; 742 intel_encoder->enable = vlv_enable_hdmi; 743 intel_encoder->post_disable = chv_hdmi_post_disable; 744 intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable; 745 } else if (IS_VALLEYVIEW(dev_priv)) { 746 intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable; 747 intel_encoder->pre_enable = vlv_hdmi_pre_enable; 748 intel_encoder->enable = vlv_enable_hdmi; 749 intel_encoder->post_disable = vlv_hdmi_post_disable; 750 } else { 751 intel_encoder->pre_enable = intel_hdmi_pre_enable; 752 if (HAS_PCH_CPT(dev_priv)) 753 intel_encoder->enable = cpt_enable_hdmi; 754 else if (HAS_PCH_IBX(dev_priv)) 755 intel_encoder->enable = ibx_enable_hdmi; 756 else 757 intel_encoder->enable = g4x_enable_hdmi; 758 } 759 intel_encoder->audio_enable = g4x_hdmi_audio_enable; 760 intel_encoder->audio_disable = g4x_hdmi_audio_disable; 761 intel_encoder->shutdown = intel_hdmi_encoder_shutdown; 762 763 intel_encoder->type = INTEL_OUTPUT_HDMI; 764 intel_encoder->power_domain = intel_display_power_ddi_lanes_domain(dev_priv, port); 765 intel_encoder->port = port; 766 if (IS_CHERRYVIEW(dev_priv)) { 767 if (port == PORT_D) 768 intel_encoder->pipe_mask = BIT(PIPE_C); 769 else 770 intel_encoder->pipe_mask = BIT(PIPE_A) | BIT(PIPE_B); 771 } else { 772 intel_encoder->pipe_mask = ~0; 773 } 774 intel_encoder->cloneable = BIT(INTEL_OUTPUT_ANALOG); 775 intel_encoder->hpd_pin = intel_hpd_pin_default(dev_priv, port); 776 /* 777 * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems 778 * to work on real hardware. And since g4x can send infoframes to 779 * only one port anyway, nothing is lost by allowing it. 780 */ 781 if (IS_G4X(dev_priv)) 782 intel_encoder->cloneable |= BIT(INTEL_OUTPUT_HDMI); 783 784 dig_port->hdmi.hdmi_reg = hdmi_reg; 785 dig_port->dp.output_reg = INVALID_MMIO_REG; 786 dig_port->max_lanes = 4; 787 788 intel_infoframe_init(dig_port); 789 790 if (!intel_hdmi_init_connector(dig_port, intel_connector)) 791 goto err_init_connector; 792 793 return true; 794 795 err_init_connector: 796 drm_encoder_cleanup(&intel_encoder->base); 797 err_encoder_init: 798 kfree(intel_connector); 799 err_connector_alloc: 800 kfree(dig_port); 801 802 return false; 803 } 804