1 /* 2 * Copyright 2022 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 /* FILE POLICY AND INTENDED USAGE: 27 * This file manages link detection states and receiver states by using various 28 * link protocols. It also provides helper functions to interpret certain 29 * capabilities or status based on the states it manages or retrieve them 30 * directly from connected receivers. 31 */ 32 33 #include "link_dpms.h" 34 #include "link_detection.h" 35 #include "link_hwss.h" 36 #include "protocols/link_edp_panel_control.h" 37 #include "protocols/link_ddc.h" 38 #include "protocols/link_hpd.h" 39 #include "protocols/link_dpcd.h" 40 #include "protocols/link_dp_capability.h" 41 #include "protocols/link_dp_dpia.h" 42 #include "protocols/link_dp_phy.h" 43 #include "protocols/link_dp_training.h" 44 #include "accessories/link_dp_trace.h" 45 46 #include "link_enc_cfg.h" 47 #include "dm_helpers.h" 48 #include "clk_mgr.h" 49 50 #define DC_LOGGER_INIT(logger) 51 52 #define LINK_INFO(...) \ 53 DC_LOG_HW_HOTPLUG( \ 54 __VA_ARGS__) 55 /* 56 * Some receivers fail to train on first try and are good 57 * on subsequent tries. 2 retries should be plenty. If we 58 * don't have a successful training then we don't expect to 59 * ever get one. 60 */ 61 #define LINK_TRAINING_MAX_VERIFY_RETRY 2 62 63 static enum ddc_transaction_type get_ddc_transaction_type(enum signal_type sink_signal) 64 { 65 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE; 66 67 switch (sink_signal) { 68 case SIGNAL_TYPE_DVI_SINGLE_LINK: 69 case SIGNAL_TYPE_DVI_DUAL_LINK: 70 case SIGNAL_TYPE_HDMI_TYPE_A: 71 case SIGNAL_TYPE_LVDS: 72 case SIGNAL_TYPE_RGB: 73 transaction_type = DDC_TRANSACTION_TYPE_I2C; 74 break; 75 76 case SIGNAL_TYPE_DISPLAY_PORT: 77 case SIGNAL_TYPE_EDP: 78 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX; 79 break; 80 81 case SIGNAL_TYPE_DISPLAY_PORT_MST: 82 /* MST does not use I2COverAux, but there is the 83 * SPECIAL use case for "immediate dwnstrm device 84 * access" (EPR#370830). 85 */ 86 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX; 87 break; 88 89 default: 90 break; 91 } 92 93 return transaction_type; 94 } 95 96 static enum signal_type get_basic_signal_type(struct graphics_object_id encoder, 97 struct graphics_object_id downstream) 98 { 99 if (downstream.type == OBJECT_TYPE_CONNECTOR) { 100 switch (downstream.id) { 101 case CONNECTOR_ID_SINGLE_LINK_DVII: 102 switch (encoder.id) { 103 case ENCODER_ID_INTERNAL_DAC1: 104 case ENCODER_ID_INTERNAL_KLDSCP_DAC1: 105 case ENCODER_ID_INTERNAL_DAC2: 106 case ENCODER_ID_INTERNAL_KLDSCP_DAC2: 107 return SIGNAL_TYPE_RGB; 108 default: 109 return SIGNAL_TYPE_DVI_SINGLE_LINK; 110 } 111 break; 112 case CONNECTOR_ID_DUAL_LINK_DVII: 113 { 114 switch (encoder.id) { 115 case ENCODER_ID_INTERNAL_DAC1: 116 case ENCODER_ID_INTERNAL_KLDSCP_DAC1: 117 case ENCODER_ID_INTERNAL_DAC2: 118 case ENCODER_ID_INTERNAL_KLDSCP_DAC2: 119 return SIGNAL_TYPE_RGB; 120 default: 121 return SIGNAL_TYPE_DVI_DUAL_LINK; 122 } 123 } 124 break; 125 case CONNECTOR_ID_SINGLE_LINK_DVID: 126 return SIGNAL_TYPE_DVI_SINGLE_LINK; 127 case CONNECTOR_ID_DUAL_LINK_DVID: 128 return SIGNAL_TYPE_DVI_DUAL_LINK; 129 case CONNECTOR_ID_VGA: 130 return SIGNAL_TYPE_RGB; 131 case CONNECTOR_ID_HDMI_TYPE_A: 132 return SIGNAL_TYPE_HDMI_TYPE_A; 133 case CONNECTOR_ID_LVDS: 134 return SIGNAL_TYPE_LVDS; 135 case CONNECTOR_ID_DISPLAY_PORT: 136 case CONNECTOR_ID_USBC: 137 return SIGNAL_TYPE_DISPLAY_PORT; 138 case CONNECTOR_ID_EDP: 139 return SIGNAL_TYPE_EDP; 140 default: 141 return SIGNAL_TYPE_NONE; 142 } 143 } else if (downstream.type == OBJECT_TYPE_ENCODER) { 144 switch (downstream.id) { 145 case ENCODER_ID_EXTERNAL_NUTMEG: 146 case ENCODER_ID_EXTERNAL_TRAVIS: 147 return SIGNAL_TYPE_DISPLAY_PORT; 148 default: 149 return SIGNAL_TYPE_NONE; 150 } 151 } 152 153 return SIGNAL_TYPE_NONE; 154 } 155 156 /* 157 * @brief 158 * Detect output sink type 159 */ 160 static enum signal_type link_detect_sink_signal_type(struct dc_link *link, 161 enum dc_detect_reason reason) 162 { 163 enum signal_type result; 164 struct graphics_object_id enc_id; 165 166 if (link->is_dig_mapping_flexible) 167 enc_id = (struct graphics_object_id){.id = ENCODER_ID_UNKNOWN}; 168 else 169 enc_id = link->link_enc->id; 170 result = get_basic_signal_type(enc_id, link->link_id); 171 172 /* Use basic signal type for link without physical connector. */ 173 if (link->ep_type != DISPLAY_ENDPOINT_PHY) 174 return result; 175 176 /* Internal digital encoder will detect only dongles 177 * that require digital signal 178 */ 179 180 /* Detection mechanism is different 181 * for different native connectors. 182 * LVDS connector supports only LVDS signal; 183 * PCIE is a bus slot, the actual connector needs to be detected first; 184 * eDP connector supports only eDP signal; 185 * HDMI should check straps for audio 186 */ 187 188 /* PCIE detects the actual connector on add-on board */ 189 if (link->link_id.id == CONNECTOR_ID_PCIE) { 190 /* ZAZTODO implement PCIE add-on card detection */ 191 } 192 193 switch (link->link_id.id) { 194 case CONNECTOR_ID_HDMI_TYPE_A: { 195 /* check audio support: 196 * if native HDMI is not supported, switch to DVI 197 */ 198 struct audio_support *aud_support = 199 &link->dc->res_pool->audio_support; 200 201 if (!aud_support->hdmi_audio_native) 202 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A) 203 result = SIGNAL_TYPE_DVI_SINGLE_LINK; 204 } 205 break; 206 case CONNECTOR_ID_DISPLAY_PORT: 207 case CONNECTOR_ID_USBC: { 208 /* DP HPD short pulse. Passive DP dongle will not 209 * have short pulse 210 */ 211 if (reason != DETECT_REASON_HPDRX) { 212 /* Check whether DP signal detected: if not - 213 * we assume signal is DVI; it could be corrected 214 * to HDMI after dongle detection 215 */ 216 if (!dm_helpers_is_dp_sink_present(link)) 217 result = SIGNAL_TYPE_DVI_SINGLE_LINK; 218 } 219 } 220 break; 221 default: 222 break; 223 } 224 225 return result; 226 } 227 228 static enum signal_type decide_signal_from_strap_and_dongle_type(enum display_dongle_type dongle_type, 229 struct audio_support *audio_support) 230 { 231 enum signal_type signal = SIGNAL_TYPE_NONE; 232 233 switch (dongle_type) { 234 case DISPLAY_DONGLE_DP_HDMI_DONGLE: 235 if (audio_support->hdmi_audio_on_dongle) 236 signal = SIGNAL_TYPE_HDMI_TYPE_A; 237 else 238 signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 239 break; 240 case DISPLAY_DONGLE_DP_DVI_DONGLE: 241 signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 242 break; 243 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE: 244 if (audio_support->hdmi_audio_native) 245 signal = SIGNAL_TYPE_HDMI_TYPE_A; 246 else 247 signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 248 break; 249 default: 250 signal = SIGNAL_TYPE_NONE; 251 break; 252 } 253 254 return signal; 255 } 256 257 static void read_scdc_caps(struct ddc_service *ddc_service, 258 struct dc_sink *sink) 259 { 260 uint8_t slave_address = HDMI_SCDC_ADDRESS; 261 uint8_t offset = HDMI_SCDC_MANUFACTURER_OUI; 262 263 link_query_ddc_data(ddc_service, slave_address, &offset, 264 sizeof(offset), sink->scdc_caps.manufacturer_OUI.byte, 265 sizeof(sink->scdc_caps.manufacturer_OUI.byte)); 266 267 offset = HDMI_SCDC_DEVICE_ID; 268 269 link_query_ddc_data(ddc_service, slave_address, &offset, 270 sizeof(offset), &(sink->scdc_caps.device_id.byte), 271 sizeof(sink->scdc_caps.device_id.byte)); 272 } 273 274 static bool i2c_read( 275 struct ddc_service *ddc, 276 uint32_t address, 277 uint8_t *buffer, 278 uint32_t len) 279 { 280 uint8_t offs_data = 0; 281 struct i2c_payload payloads[2] = { 282 { 283 .write = true, 284 .address = address, 285 .length = 1, 286 .data = &offs_data }, 287 { 288 .write = false, 289 .address = address, 290 .length = len, 291 .data = buffer } }; 292 293 struct i2c_command command = { 294 .payloads = payloads, 295 .number_of_payloads = 2, 296 .engine = DDC_I2C_COMMAND_ENGINE, 297 .speed = ddc->ctx->dc->caps.i2c_speed_in_khz }; 298 299 return dm_helpers_submit_i2c( 300 ddc->ctx, 301 ddc->link, 302 &command); 303 } 304 305 enum { 306 DP_SINK_CAP_SIZE = 307 DP_EDP_CONFIGURATION_CAP - DP_DPCD_REV + 1 308 }; 309 310 static void query_dp_dual_mode_adaptor( 311 struct ddc_service *ddc, 312 struct display_sink_capability *sink_cap) 313 { 314 uint8_t i; 315 bool is_valid_hdmi_signature; 316 enum display_dongle_type *dongle = &sink_cap->dongle_type; 317 uint8_t type2_dongle_buf[DP_ADAPTOR_TYPE2_SIZE]; 318 bool is_type2_dongle = false; 319 int retry_count = 2; 320 struct dp_hdmi_dongle_signature_data *dongle_signature; 321 322 /* Assume we have no valid DP passive dongle connected */ 323 *dongle = DISPLAY_DONGLE_NONE; 324 sink_cap->max_hdmi_pixel_clock = DP_ADAPTOR_HDMI_SAFE_MAX_TMDS_CLK; 325 326 /* Read DP-HDMI dongle I2c (no response interpreted as DP-DVI dongle)*/ 327 if (!i2c_read( 328 ddc, 329 DP_HDMI_DONGLE_ADDRESS, 330 type2_dongle_buf, 331 sizeof(type2_dongle_buf))) { 332 /* Passive HDMI dongles can sometimes fail here without retrying*/ 333 while (retry_count > 0) { 334 if (i2c_read(ddc, 335 DP_HDMI_DONGLE_ADDRESS, 336 type2_dongle_buf, 337 sizeof(type2_dongle_buf))) 338 break; 339 retry_count--; 340 } 341 if (retry_count == 0) { 342 *dongle = DISPLAY_DONGLE_DP_DVI_DONGLE; 343 sink_cap->max_hdmi_pixel_clock = DP_ADAPTOR_DVI_MAX_TMDS_CLK; 344 345 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, sizeof(type2_dongle_buf), 346 "DP-DVI passive dongle %dMhz: ", 347 DP_ADAPTOR_DVI_MAX_TMDS_CLK / 1000); 348 return; 349 } 350 } 351 352 /* Check if Type 2 dongle.*/ 353 if (type2_dongle_buf[DP_ADAPTOR_TYPE2_REG_ID] == DP_ADAPTOR_TYPE2_ID) 354 is_type2_dongle = true; 355 356 dongle_signature = 357 (struct dp_hdmi_dongle_signature_data *)type2_dongle_buf; 358 359 is_valid_hdmi_signature = true; 360 361 /* Check EOT */ 362 if (dongle_signature->eot != DP_HDMI_DONGLE_SIGNATURE_EOT) { 363 is_valid_hdmi_signature = false; 364 } 365 366 /* Check signature */ 367 for (i = 0; i < sizeof(dongle_signature->id); ++i) { 368 /* If its not the right signature, 369 * skip mismatch in subversion byte.*/ 370 if (dongle_signature->id[i] != 371 dp_hdmi_dongle_signature_str[i] && i != 3) { 372 373 if (is_type2_dongle) { 374 is_valid_hdmi_signature = false; 375 break; 376 } 377 378 } 379 } 380 381 if (is_type2_dongle) { 382 uint32_t max_tmds_clk = 383 type2_dongle_buf[DP_ADAPTOR_TYPE2_REG_MAX_TMDS_CLK]; 384 385 max_tmds_clk = max_tmds_clk * 2 + max_tmds_clk / 2; 386 387 if (0 == max_tmds_clk || 388 max_tmds_clk < DP_ADAPTOR_TYPE2_MIN_TMDS_CLK || 389 max_tmds_clk > DP_ADAPTOR_TYPE2_MAX_TMDS_CLK) { 390 *dongle = DISPLAY_DONGLE_DP_DVI_DONGLE; 391 392 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, 393 sizeof(type2_dongle_buf), 394 "DP-DVI passive dongle %dMhz: ", 395 DP_ADAPTOR_DVI_MAX_TMDS_CLK / 1000); 396 } else { 397 if (is_valid_hdmi_signature == true) { 398 *dongle = DISPLAY_DONGLE_DP_HDMI_DONGLE; 399 400 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, 401 sizeof(type2_dongle_buf), 402 "Type 2 DP-HDMI passive dongle %dMhz: ", 403 max_tmds_clk); 404 } else { 405 *dongle = DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE; 406 407 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, 408 sizeof(type2_dongle_buf), 409 "Type 2 DP-HDMI passive dongle (no signature) %dMhz: ", 410 max_tmds_clk); 411 412 } 413 414 /* Multiply by 1000 to convert to kHz. */ 415 sink_cap->max_hdmi_pixel_clock = 416 max_tmds_clk * 1000; 417 } 418 sink_cap->is_dongle_type_one = false; 419 420 } else { 421 if (is_valid_hdmi_signature == true) { 422 *dongle = DISPLAY_DONGLE_DP_HDMI_DONGLE; 423 424 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, 425 sizeof(type2_dongle_buf), 426 "Type 1 DP-HDMI passive dongle %dMhz: ", 427 sink_cap->max_hdmi_pixel_clock / 1000); 428 } else { 429 *dongle = DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE; 430 431 CONN_DATA_DETECT(ddc->link, type2_dongle_buf, 432 sizeof(type2_dongle_buf), 433 "Type 1 DP-HDMI passive dongle (no signature) %dMhz: ", 434 sink_cap->max_hdmi_pixel_clock / 1000); 435 } 436 sink_cap->is_dongle_type_one = true; 437 } 438 439 return; 440 } 441 442 static enum signal_type dp_passive_dongle_detection(struct ddc_service *ddc, 443 struct display_sink_capability *sink_cap, 444 struct audio_support *audio_support) 445 { 446 query_dp_dual_mode_adaptor(ddc, sink_cap); 447 448 return decide_signal_from_strap_and_dongle_type(sink_cap->dongle_type, 449 audio_support); 450 } 451 452 static void link_disconnect_sink(struct dc_link *link) 453 { 454 if (link->local_sink) { 455 dc_sink_release(link->local_sink); 456 link->local_sink = NULL; 457 } 458 459 link->dpcd_sink_count = 0; 460 //link->dpcd_caps.dpcd_rev.raw = 0; 461 } 462 463 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link) 464 { 465 dc_sink_release(link->local_sink); 466 link->local_sink = prev_sink; 467 } 468 469 #if defined(CONFIG_DRM_AMD_DC_HDCP) 470 static void query_hdcp_capability(enum signal_type signal, struct dc_link *link) 471 { 472 struct hdcp_protection_message msg22; 473 struct hdcp_protection_message msg14; 474 475 memset(&msg22, 0, sizeof(struct hdcp_protection_message)); 476 memset(&msg14, 0, sizeof(struct hdcp_protection_message)); 477 memset(link->hdcp_caps.rx_caps.raw, 0, 478 sizeof(link->hdcp_caps.rx_caps.raw)); 479 480 if ((link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT && 481 link->ddc->transaction_type == 482 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) || 483 link->connector_signal == SIGNAL_TYPE_EDP) { 484 msg22.data = link->hdcp_caps.rx_caps.raw; 485 msg22.length = sizeof(link->hdcp_caps.rx_caps.raw); 486 msg22.msg_id = HDCP_MESSAGE_ID_RX_CAPS; 487 } else { 488 msg22.data = &link->hdcp_caps.rx_caps.fields.version; 489 msg22.length = sizeof(link->hdcp_caps.rx_caps.fields.version); 490 msg22.msg_id = HDCP_MESSAGE_ID_HDCP2VERSION; 491 } 492 msg22.version = HDCP_VERSION_22; 493 msg22.link = HDCP_LINK_PRIMARY; 494 msg22.max_retries = 5; 495 dc_process_hdcp_msg(signal, link, &msg22); 496 497 if (signal == SIGNAL_TYPE_DISPLAY_PORT || signal == SIGNAL_TYPE_DISPLAY_PORT_MST) { 498 enum hdcp_message_status status = HDCP_MESSAGE_UNSUPPORTED; 499 500 msg14.data = &link->hdcp_caps.bcaps.raw; 501 msg14.length = sizeof(link->hdcp_caps.bcaps.raw); 502 msg14.msg_id = HDCP_MESSAGE_ID_READ_BCAPS; 503 msg14.version = HDCP_VERSION_14; 504 msg14.link = HDCP_LINK_PRIMARY; 505 msg14.max_retries = 5; 506 507 status = dc_process_hdcp_msg(signal, link, &msg14); 508 } 509 510 } 511 #endif // CONFIG_DRM_AMD_DC_HDCP 512 static void read_current_link_settings_on_detect(struct dc_link *link) 513 { 514 union lane_count_set lane_count_set = {0}; 515 uint8_t link_bw_set; 516 uint8_t link_rate_set; 517 uint32_t read_dpcd_retry_cnt = 10; 518 enum dc_status status = DC_ERROR_UNEXPECTED; 519 int i; 520 union max_down_spread max_down_spread = {0}; 521 522 // Read DPCD 00101h to find out the number of lanes currently set 523 for (i = 0; i < read_dpcd_retry_cnt; i++) { 524 status = core_link_read_dpcd(link, 525 DP_LANE_COUNT_SET, 526 &lane_count_set.raw, 527 sizeof(lane_count_set)); 528 /* First DPCD read after VDD ON can fail if the particular board 529 * does not have HPD pin wired correctly. So if DPCD read fails, 530 * which it should never happen, retry a few times. Target worst 531 * case scenario of 80 ms. 532 */ 533 if (status == DC_OK) { 534 link->cur_link_settings.lane_count = 535 lane_count_set.bits.LANE_COUNT_SET; 536 break; 537 } 538 539 msleep(8); 540 } 541 542 // Read DPCD 00100h to find if standard link rates are set 543 core_link_read_dpcd(link, DP_LINK_BW_SET, 544 &link_bw_set, sizeof(link_bw_set)); 545 546 if (link_bw_set == 0) { 547 if (link->connector_signal == SIGNAL_TYPE_EDP) { 548 /* If standard link rates are not being used, 549 * Read DPCD 00115h to find the edp link rate set used 550 */ 551 core_link_read_dpcd(link, DP_LINK_RATE_SET, 552 &link_rate_set, sizeof(link_rate_set)); 553 554 // edp_supported_link_rates_count = 0 for DP 555 if (link_rate_set < link->dpcd_caps.edp_supported_link_rates_count) { 556 link->cur_link_settings.link_rate = 557 link->dpcd_caps.edp_supported_link_rates[link_rate_set]; 558 link->cur_link_settings.link_rate_set = link_rate_set; 559 link->cur_link_settings.use_link_rate_set = true; 560 } 561 } else { 562 // Link Rate not found. Seamless boot may not work. 563 ASSERT(false); 564 } 565 } else { 566 link->cur_link_settings.link_rate = link_bw_set; 567 link->cur_link_settings.use_link_rate_set = false; 568 } 569 // Read DPCD 00003h to find the max down spread. 570 core_link_read_dpcd(link, DP_MAX_DOWNSPREAD, 571 &max_down_spread.raw, sizeof(max_down_spread)); 572 link->cur_link_settings.link_spread = 573 max_down_spread.bits.MAX_DOWN_SPREAD ? 574 LINK_SPREAD_05_DOWNSPREAD_30KHZ : LINK_SPREAD_DISABLED; 575 } 576 577 static bool detect_dp(struct dc_link *link, 578 struct display_sink_capability *sink_caps, 579 enum dc_detect_reason reason) 580 { 581 struct audio_support *audio_support = &link->dc->res_pool->audio_support; 582 583 sink_caps->signal = link_detect_sink_signal_type(link, reason); 584 sink_caps->transaction_type = 585 get_ddc_transaction_type(sink_caps->signal); 586 587 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) { 588 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT; 589 if (!detect_dp_sink_caps(link)) 590 return false; 591 592 if (is_dp_branch_device(link)) 593 /* DP SST branch */ 594 link->type = dc_connection_sst_branch; 595 } else { 596 /* DP passive dongles */ 597 sink_caps->signal = dp_passive_dongle_detection(link->ddc, 598 sink_caps, 599 audio_support); 600 link->dpcd_caps.dongle_type = sink_caps->dongle_type; 601 link->dpcd_caps.is_dongle_type_one = sink_caps->is_dongle_type_one; 602 link->dpcd_caps.dpcd_rev.raw = 0; 603 } 604 605 return true; 606 } 607 608 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid) 609 { 610 if (old_edid->length != new_edid->length) 611 return false; 612 613 if (new_edid->length == 0) 614 return false; 615 616 return (memcmp(old_edid->raw_edid, 617 new_edid->raw_edid, new_edid->length) == 0); 618 } 619 620 static bool wait_for_entering_dp_alt_mode(struct dc_link *link) 621 { 622 623 /** 624 * something is terribly wrong if time out is > 200ms. (5Hz) 625 * 500 microseconds * 400 tries us 200 ms 626 **/ 627 unsigned int sleep_time_in_microseconds = 500; 628 unsigned int tries_allowed = 400; 629 bool is_in_alt_mode; 630 unsigned long long enter_timestamp; 631 unsigned long long finish_timestamp; 632 unsigned long long time_taken_in_ns; 633 int tries_taken; 634 635 DC_LOGGER_INIT(link->ctx->logger); 636 637 /** 638 * this function will only exist if we are on dcn21 (is_in_alt_mode is a 639 * function pointer, so checking to see if it is equal to 0 is the same 640 * as checking to see if it is null 641 **/ 642 if (!link->link_enc->funcs->is_in_alt_mode) 643 return true; 644 645 is_in_alt_mode = link->link_enc->funcs->is_in_alt_mode(link->link_enc); 646 DC_LOG_DC("DP Alt mode state on HPD: %d\n", is_in_alt_mode); 647 648 if (is_in_alt_mode) 649 return true; 650 651 enter_timestamp = dm_get_timestamp(link->ctx); 652 653 for (tries_taken = 0; tries_taken < tries_allowed; tries_taken++) { 654 udelay(sleep_time_in_microseconds); 655 /* ask the link if alt mode is enabled, if so return ok */ 656 if (link->link_enc->funcs->is_in_alt_mode(link->link_enc)) { 657 finish_timestamp = dm_get_timestamp(link->ctx); 658 time_taken_in_ns = 659 dm_get_elapse_time_in_ns(link->ctx, 660 finish_timestamp, 661 enter_timestamp); 662 DC_LOG_WARNING("Alt mode entered finished after %llu ms\n", 663 div_u64(time_taken_in_ns, 1000000)); 664 return true; 665 } 666 } 667 finish_timestamp = dm_get_timestamp(link->ctx); 668 time_taken_in_ns = dm_get_elapse_time_in_ns(link->ctx, finish_timestamp, 669 enter_timestamp); 670 DC_LOG_WARNING("Alt mode has timed out after %llu ms\n", 671 div_u64(time_taken_in_ns, 1000000)); 672 return false; 673 } 674 675 static void apply_dpia_mst_dsc_always_on_wa(struct dc_link *link) 676 { 677 /* Apply work around for tunneled MST on certain USB4 docks. Always use DSC if dock 678 * reports DSC support. 679 */ 680 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA && 681 link->type == dc_connection_mst_branch && 682 link->dpcd_caps.branch_dev_id == DP_BRANCH_DEVICE_ID_90CC24 && 683 link->dpcd_caps.branch_hw_revision == DP_BRANCH_HW_REV_20 && 684 link->dpcd_caps.dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_SUPPORT && 685 !link->dc->debug.dpia_debug.bits.disable_mst_dsc_work_around) 686 link->wa_flags.dpia_mst_dsc_always_on = true; 687 } 688 689 static void revert_dpia_mst_dsc_always_on_wa(struct dc_link *link) 690 { 691 /* Disable work around which keeps DSC on for tunneled MST on certain USB4 docks. */ 692 if (link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) 693 link->wa_flags.dpia_mst_dsc_always_on = false; 694 } 695 696 static bool discover_dp_mst_topology(struct dc_link *link, enum dc_detect_reason reason) 697 { 698 DC_LOGGER_INIT(link->ctx->logger); 699 700 LINK_INFO("link=%d, mst branch is now Connected\n", 701 link->link_index); 702 703 link->type = dc_connection_mst_branch; 704 apply_dpia_mst_dsc_always_on_wa(link); 705 706 dm_helpers_dp_update_branch_info(link->ctx, link); 707 if (dm_helpers_dp_mst_start_top_mgr(link->ctx, 708 link, (reason == DETECT_REASON_BOOT || reason == DETECT_REASON_RESUMEFROMS3S4))) { 709 link_disconnect_sink(link); 710 } else { 711 link->type = dc_connection_sst_branch; 712 } 713 714 return link->type == dc_connection_mst_branch; 715 } 716 717 static bool reset_cur_dp_mst_topology(struct dc_link *link) 718 { 719 DC_LOGGER_INIT(link->ctx->logger); 720 721 LINK_INFO("link=%d, mst branch is now Disconnected\n", 722 link->link_index); 723 724 revert_dpia_mst_dsc_always_on_wa(link); 725 return dm_helpers_dp_mst_stop_top_mgr(link->ctx, link); 726 } 727 728 bool dc_link_reset_cur_dp_mst_topology(struct dc_link *link) 729 { 730 return reset_cur_dp_mst_topology(link); 731 } 732 static bool should_prepare_phy_clocks_for_link_verification(const struct dc *dc, 733 enum dc_detect_reason reason) 734 { 735 int i; 736 bool can_apply_seamless_boot = false; 737 738 for (i = 0; i < dc->current_state->stream_count; i++) { 739 if (dc->current_state->streams[i]->apply_seamless_boot_optimization) { 740 can_apply_seamless_boot = true; 741 break; 742 } 743 } 744 745 return !can_apply_seamless_boot && reason != DETECT_REASON_BOOT; 746 } 747 748 static void prepare_phy_clocks_for_destructive_link_verification(const struct dc *dc) 749 { 750 dc_z10_restore(dc); 751 clk_mgr_exit_optimized_pwr_state(dc, dc->clk_mgr); 752 } 753 754 static void restore_phy_clocks_for_destructive_link_verification(const struct dc *dc) 755 { 756 clk_mgr_optimize_pwr_state(dc, dc->clk_mgr); 757 } 758 759 static void verify_link_capability_destructive(struct dc_link *link, 760 struct dc_sink *sink, 761 enum dc_detect_reason reason) 762 { 763 bool should_prepare_phy_clocks = 764 should_prepare_phy_clocks_for_link_verification(link->dc, reason); 765 766 if (should_prepare_phy_clocks) 767 prepare_phy_clocks_for_destructive_link_verification(link->dc); 768 769 if (dc_is_dp_signal(link->local_sink->sink_signal)) { 770 struct dc_link_settings known_limit_link_setting = 771 dp_get_max_link_cap(link); 772 link_set_all_streams_dpms_off_for_link(link); 773 dp_verify_link_cap_with_retries( 774 link, &known_limit_link_setting, 775 LINK_TRAINING_MAX_VERIFY_RETRY); 776 } else { 777 ASSERT(0); 778 } 779 780 if (should_prepare_phy_clocks) 781 restore_phy_clocks_for_destructive_link_verification(link->dc); 782 } 783 784 static void verify_link_capability_non_destructive(struct dc_link *link) 785 { 786 if (dc_is_dp_signal(link->local_sink->sink_signal)) { 787 if (dc_is_embedded_signal(link->local_sink->sink_signal) || 788 link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) 789 /* TODO - should we check link encoder's max link caps here? 790 * How do we know which link encoder to check from? 791 */ 792 link->verified_link_cap = link->reported_link_cap; 793 else 794 link->verified_link_cap = dp_get_max_link_cap(link); 795 } 796 } 797 798 static bool should_verify_link_capability_destructively(struct dc_link *link, 799 enum dc_detect_reason reason) 800 { 801 bool destrictive = false; 802 struct dc_link_settings max_link_cap; 803 bool is_link_enc_unavailable = link->link_enc && 804 link->dc->res_pool->funcs->link_encs_assign && 805 !link_enc_cfg_is_link_enc_avail( 806 link->ctx->dc, 807 link->link_enc->preferred_engine, 808 link); 809 810 if (dc_is_dp_signal(link->local_sink->sink_signal)) { 811 max_link_cap = dp_get_max_link_cap(link); 812 destrictive = true; 813 814 if (link->dc->debug.skip_detection_link_training || 815 dc_is_embedded_signal(link->local_sink->sink_signal) || 816 link->ep_type == DISPLAY_ENDPOINT_USB4_DPIA) { 817 destrictive = false; 818 } else if (link_dp_get_encoding_format(&max_link_cap) == 819 DP_8b_10b_ENCODING) { 820 if (link->dpcd_caps.is_mst_capable || 821 is_link_enc_unavailable) { 822 destrictive = false; 823 } 824 } 825 } 826 827 return destrictive; 828 } 829 830 static void verify_link_capability(struct dc_link *link, struct dc_sink *sink, 831 enum dc_detect_reason reason) 832 { 833 if (should_verify_link_capability_destructively(link, reason)) 834 verify_link_capability_destructive(link, sink, reason); 835 else 836 verify_link_capability_non_destructive(link); 837 } 838 839 /** 840 * detect_link_and_local_sink() - Detect if a sink is attached to a given link 841 * 842 * link->local_sink is created or destroyed as needed. 843 * 844 * This does not create remote sinks. 845 */ 846 static bool detect_link_and_local_sink(struct dc_link *link, 847 enum dc_detect_reason reason) 848 { 849 struct dc_sink_init_data sink_init_data = { 0 }; 850 struct display_sink_capability sink_caps = { 0 }; 851 uint32_t i; 852 bool converter_disable_audio = false; 853 struct audio_support *aud_support = &link->dc->res_pool->audio_support; 854 bool same_edid = false; 855 enum dc_edid_status edid_status; 856 struct dc_context *dc_ctx = link->ctx; 857 struct dc *dc = dc_ctx->dc; 858 struct dc_sink *sink = NULL; 859 struct dc_sink *prev_sink = NULL; 860 struct dpcd_caps prev_dpcd_caps; 861 enum dc_connection_type new_connection_type = dc_connection_none; 862 const uint32_t post_oui_delay = 30; // 30ms 863 864 DC_LOGGER_INIT(link->ctx->logger); 865 866 if (dc_is_virtual_signal(link->connector_signal)) 867 return false; 868 869 if (((link->connector_signal == SIGNAL_TYPE_LVDS || 870 link->connector_signal == SIGNAL_TYPE_EDP) && 871 (!link->dc->config.allow_edp_hotplug_detection)) && 872 link->local_sink) { 873 // need to re-write OUI and brightness in resume case 874 if (link->connector_signal == SIGNAL_TYPE_EDP && 875 (link->dpcd_sink_ext_caps.bits.oled == 1)) { 876 dpcd_set_source_specific_data(link); 877 msleep(post_oui_delay); 878 set_default_brightness_aux(link); 879 //TODO: use cached 880 } 881 882 return true; 883 } 884 885 if (!dc_link_detect_connection_type(link, &new_connection_type)) { 886 BREAK_TO_DEBUGGER(); 887 return false; 888 } 889 890 prev_sink = link->local_sink; 891 if (prev_sink) { 892 dc_sink_retain(prev_sink); 893 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps)); 894 } 895 896 link_disconnect_sink(link); 897 if (new_connection_type != dc_connection_none) { 898 link->type = new_connection_type; 899 link->link_state_valid = false; 900 901 /* From Disconnected-to-Connected. */ 902 switch (link->connector_signal) { 903 case SIGNAL_TYPE_HDMI_TYPE_A: { 904 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C; 905 if (aud_support->hdmi_audio_native) 906 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A; 907 else 908 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 909 break; 910 } 911 912 case SIGNAL_TYPE_DVI_SINGLE_LINK: { 913 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C; 914 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 915 break; 916 } 917 918 case SIGNAL_TYPE_DVI_DUAL_LINK: { 919 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C; 920 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK; 921 break; 922 } 923 924 case SIGNAL_TYPE_LVDS: { 925 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C; 926 sink_caps.signal = SIGNAL_TYPE_LVDS; 927 break; 928 } 929 930 case SIGNAL_TYPE_EDP: { 931 detect_edp_sink_caps(link); 932 read_current_link_settings_on_detect(link); 933 934 /* Disable power sequence on MIPI panel + converter 935 */ 936 if (dc->config.enable_mipi_converter_optimization && 937 dc_ctx->dce_version == DCN_VERSION_3_01 && 938 link->dpcd_caps.sink_dev_id == DP_BRANCH_DEVICE_ID_0022B9 && 939 memcmp(&link->dpcd_caps.branch_dev_name, DP_SINK_BRANCH_DEV_NAME_7580, 940 sizeof(link->dpcd_caps.branch_dev_name)) == 0) { 941 dc->config.edp_no_power_sequencing = true; 942 943 if (!link->dpcd_caps.set_power_state_capable_edp) 944 link->wa_flags.dp_keep_receiver_powered = true; 945 } 946 947 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX; 948 sink_caps.signal = SIGNAL_TYPE_EDP; 949 break; 950 } 951 952 case SIGNAL_TYPE_DISPLAY_PORT: { 953 954 /* wa HPD high coming too early*/ 955 if (link->ep_type == DISPLAY_ENDPOINT_PHY && 956 link->link_enc->features.flags.bits.DP_IS_USB_C == 1) { 957 958 /* if alt mode times out, return false */ 959 if (!wait_for_entering_dp_alt_mode(link)) 960 return false; 961 } 962 963 if (!detect_dp(link, &sink_caps, reason)) { 964 if (prev_sink) 965 dc_sink_release(prev_sink); 966 return false; 967 } 968 969 /* Active SST downstream branch device unplug*/ 970 if (link->type == dc_connection_sst_branch && 971 link->dpcd_caps.sink_count.bits.SINK_COUNT == 0) { 972 if (prev_sink) 973 /* Downstream unplug */ 974 dc_sink_release(prev_sink); 975 return true; 976 } 977 978 /* disable audio for non DP to HDMI active sst converter */ 979 if (link->type == dc_connection_sst_branch && 980 is_dp_active_dongle(link) && 981 (link->dpcd_caps.dongle_type != 982 DISPLAY_DONGLE_DP_HDMI_CONVERTER)) 983 converter_disable_audio = true; 984 break; 985 } 986 987 default: 988 DC_ERROR("Invalid connector type! signal:%d\n", 989 link->connector_signal); 990 if (prev_sink) 991 dc_sink_release(prev_sink); 992 return false; 993 } /* switch() */ 994 995 if (link->dpcd_caps.sink_count.bits.SINK_COUNT) 996 link->dpcd_sink_count = 997 link->dpcd_caps.sink_count.bits.SINK_COUNT; 998 else 999 link->dpcd_sink_count = 1; 1000 1001 set_ddc_transaction_type(link->ddc, 1002 sink_caps.transaction_type); 1003 1004 link->aux_mode = 1005 link_is_in_aux_transaction_mode(link->ddc); 1006 1007 sink_init_data.link = link; 1008 sink_init_data.sink_signal = sink_caps.signal; 1009 1010 sink = dc_sink_create(&sink_init_data); 1011 if (!sink) { 1012 DC_ERROR("Failed to create sink!\n"); 1013 if (prev_sink) 1014 dc_sink_release(prev_sink); 1015 return false; 1016 } 1017 1018 sink->link->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock; 1019 sink->converter_disable_audio = converter_disable_audio; 1020 1021 /* dc_sink_create returns a new reference */ 1022 link->local_sink = sink; 1023 1024 edid_status = dm_helpers_read_local_edid(link->ctx, 1025 link, sink); 1026 1027 switch (edid_status) { 1028 case EDID_BAD_CHECKSUM: 1029 DC_LOG_ERROR("EDID checksum invalid.\n"); 1030 break; 1031 case EDID_PARTIAL_VALID: 1032 DC_LOG_ERROR("Partial EDID valid, abandon invalid blocks.\n"); 1033 break; 1034 case EDID_NO_RESPONSE: 1035 DC_LOG_ERROR("No EDID read.\n"); 1036 /* 1037 * Abort detection for non-DP connectors if we have 1038 * no EDID 1039 * 1040 * DP needs to report as connected if HDP is high 1041 * even if we have no EDID in order to go to 1042 * fail-safe mode 1043 */ 1044 if (dc_is_hdmi_signal(link->connector_signal) || 1045 dc_is_dvi_signal(link->connector_signal)) { 1046 if (prev_sink) 1047 dc_sink_release(prev_sink); 1048 1049 return false; 1050 } 1051 1052 if (link->type == dc_connection_sst_branch && 1053 link->dpcd_caps.dongle_type == 1054 DISPLAY_DONGLE_DP_VGA_CONVERTER && 1055 reason == DETECT_REASON_HPDRX) { 1056 /* Abort detection for DP-VGA adapters when EDID 1057 * can't be read and detection reason is VGA-side 1058 * hotplug 1059 */ 1060 if (prev_sink) 1061 dc_sink_release(prev_sink); 1062 link_disconnect_sink(link); 1063 1064 return true; 1065 } 1066 1067 break; 1068 default: 1069 break; 1070 } 1071 1072 // Check if edid is the same 1073 if ((prev_sink) && 1074 (edid_status == EDID_THE_SAME || edid_status == EDID_OK)) 1075 same_edid = is_same_edid(&prev_sink->dc_edid, 1076 &sink->dc_edid); 1077 1078 if (sink->edid_caps.panel_patch.skip_scdc_overwrite) 1079 link->ctx->dc->debug.hdmi20_disable = true; 1080 1081 if (dc_is_hdmi_signal(link->connector_signal)) 1082 read_scdc_caps(link->ddc, link->local_sink); 1083 1084 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT && 1085 sink_caps.transaction_type == 1086 DDC_TRANSACTION_TYPE_I2C_OVER_AUX) { 1087 /* 1088 * TODO debug why certain monitors don't like 1089 * two link trainings 1090 */ 1091 #if defined(CONFIG_DRM_AMD_DC_HDCP) 1092 query_hdcp_capability(sink->sink_signal, link); 1093 #endif 1094 } else { 1095 // If edid is the same, then discard new sink and revert back to original sink 1096 if (same_edid) { 1097 link_disconnect_remap(prev_sink, link); 1098 sink = prev_sink; 1099 prev_sink = NULL; 1100 } 1101 #if defined(CONFIG_DRM_AMD_DC_HDCP) 1102 query_hdcp_capability(sink->sink_signal, link); 1103 #endif 1104 } 1105 1106 /* HDMI-DVI Dongle */ 1107 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A && 1108 !sink->edid_caps.edid_hdmi) 1109 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK; 1110 1111 if (link->local_sink && dc_is_dp_signal(sink_caps.signal)) 1112 dp_trace_init(link); 1113 1114 /* Connectivity log: detection */ 1115 for (i = 0; i < sink->dc_edid.length / DC_EDID_BLOCK_SIZE; i++) { 1116 CONN_DATA_DETECT(link, 1117 &sink->dc_edid.raw_edid[i * DC_EDID_BLOCK_SIZE], 1118 DC_EDID_BLOCK_SIZE, 1119 "%s: [Block %d] ", sink->edid_caps.display_name, i); 1120 } 1121 1122 DC_LOG_DETECTION_EDID_PARSER("%s: " 1123 "manufacturer_id = %X, " 1124 "product_id = %X, " 1125 "serial_number = %X, " 1126 "manufacture_week = %d, " 1127 "manufacture_year = %d, " 1128 "display_name = %s, " 1129 "speaker_flag = %d, " 1130 "audio_mode_count = %d\n", 1131 __func__, 1132 sink->edid_caps.manufacturer_id, 1133 sink->edid_caps.product_id, 1134 sink->edid_caps.serial_number, 1135 sink->edid_caps.manufacture_week, 1136 sink->edid_caps.manufacture_year, 1137 sink->edid_caps.display_name, 1138 sink->edid_caps.speaker_flags, 1139 sink->edid_caps.audio_mode_count); 1140 1141 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) { 1142 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, " 1143 "format_code = %d, " 1144 "channel_count = %d, " 1145 "sample_rate = %d, " 1146 "sample_size = %d\n", 1147 __func__, 1148 i, 1149 sink->edid_caps.audio_modes[i].format_code, 1150 sink->edid_caps.audio_modes[i].channel_count, 1151 sink->edid_caps.audio_modes[i].sample_rate, 1152 sink->edid_caps.audio_modes[i].sample_size); 1153 } 1154 1155 if (link->connector_signal == SIGNAL_TYPE_EDP) { 1156 // Init dc_panel_config by HW config 1157 if (dc_ctx->dc->res_pool->funcs->get_panel_config_defaults) 1158 dc_ctx->dc->res_pool->funcs->get_panel_config_defaults(&link->panel_config); 1159 // Pickup base DM settings 1160 dm_helpers_init_panel_settings(dc_ctx, &link->panel_config, sink); 1161 // Override dc_panel_config if system has specific settings 1162 dm_helpers_override_panel_settings(dc_ctx, &link->panel_config); 1163 } 1164 1165 } else { 1166 /* From Connected-to-Disconnected. */ 1167 link->type = dc_connection_none; 1168 sink_caps.signal = SIGNAL_TYPE_NONE; 1169 #if defined(CONFIG_DRM_AMD_DC_HDCP) 1170 memset(&link->hdcp_caps, 0, sizeof(struct hdcp_caps)); 1171 #endif 1172 /* When we unplug a passive DP-HDMI dongle connection, dongle_max_pix_clk 1173 * is not cleared. If we emulate a DP signal on this connection, it thinks 1174 * the dongle is still there and limits the number of modes we can emulate. 1175 * Clear dongle_max_pix_clk on disconnect to fix this 1176 */ 1177 link->dongle_max_pix_clk = 0; 1178 1179 dc_link_clear_dprx_states(link); 1180 dp_trace_reset(link); 1181 } 1182 1183 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p edid same=%d\n", 1184 link->link_index, sink, 1185 (sink_caps.signal == 1186 SIGNAL_TYPE_NONE ? "Disconnected" : "Connected"), 1187 prev_sink, same_edid); 1188 1189 if (prev_sink) 1190 dc_sink_release(prev_sink); 1191 1192 return true; 1193 } 1194 1195 /** 1196 * dc_link_detect_connection_type() - Determine if there is a sink connected 1197 * 1198 * @type: Returned connection type 1199 * Does not detect downstream devices, such as MST sinks 1200 * or display connected through active dongles 1201 */ 1202 bool dc_link_detect_connection_type(struct dc_link *link, enum dc_connection_type *type) 1203 { 1204 uint32_t is_hpd_high = 0; 1205 1206 if (link->connector_signal == SIGNAL_TYPE_LVDS) { 1207 *type = dc_connection_single; 1208 return true; 1209 } 1210 1211 if (link->connector_signal == SIGNAL_TYPE_EDP) { 1212 /*in case it is not on*/ 1213 if (!link->dc->config.edp_no_power_sequencing) 1214 link->dc->hwss.edp_power_control(link, true); 1215 link->dc->hwss.edp_wait_for_hpd_ready(link, true); 1216 } 1217 1218 /* Link may not have physical HPD pin. */ 1219 if (link->ep_type != DISPLAY_ENDPOINT_PHY) { 1220 if (link->is_hpd_pending || !dc_link_dpia_query_hpd_status(link)) 1221 *type = dc_connection_none; 1222 else 1223 *type = dc_connection_single; 1224 1225 return true; 1226 } 1227 1228 1229 if (!query_hpd_status(link, &is_hpd_high)) 1230 goto hpd_gpio_failure; 1231 1232 if (is_hpd_high) { 1233 *type = dc_connection_single; 1234 /* TODO: need to do the actual detection */ 1235 } else { 1236 *type = dc_connection_none; 1237 } 1238 1239 return true; 1240 1241 hpd_gpio_failure: 1242 return false; 1243 } 1244 1245 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason) 1246 { 1247 bool is_local_sink_detect_success; 1248 bool is_delegated_to_mst_top_mgr = false; 1249 enum dc_connection_type pre_link_type = link->type; 1250 1251 is_local_sink_detect_success = detect_link_and_local_sink(link, reason); 1252 1253 if (is_local_sink_detect_success && link->local_sink) 1254 verify_link_capability(link, link->local_sink, reason); 1255 1256 if (is_local_sink_detect_success && link->local_sink && 1257 dc_is_dp_signal(link->local_sink->sink_signal) && 1258 link->dpcd_caps.is_mst_capable) 1259 is_delegated_to_mst_top_mgr = discover_dp_mst_topology(link, reason); 1260 1261 if (is_local_sink_detect_success && 1262 pre_link_type == dc_connection_mst_branch && 1263 link->type != dc_connection_mst_branch) 1264 is_delegated_to_mst_top_mgr = reset_cur_dp_mst_topology(link); 1265 1266 return is_local_sink_detect_success && !is_delegated_to_mst_top_mgr; 1267 } 1268 1269 void dc_link_clear_dprx_states(struct dc_link *link) 1270 { 1271 memset(&link->dprx_states, 0, sizeof(link->dprx_states)); 1272 } 1273 #if defined(CONFIG_DRM_AMD_DC_HDCP) 1274 1275 bool dc_link_is_hdcp14(struct dc_link *link, enum signal_type signal) 1276 { 1277 bool ret = false; 1278 1279 switch (signal) { 1280 case SIGNAL_TYPE_DISPLAY_PORT: 1281 case SIGNAL_TYPE_DISPLAY_PORT_MST: 1282 ret = link->hdcp_caps.bcaps.bits.HDCP_CAPABLE; 1283 break; 1284 case SIGNAL_TYPE_DVI_SINGLE_LINK: 1285 case SIGNAL_TYPE_DVI_DUAL_LINK: 1286 case SIGNAL_TYPE_HDMI_TYPE_A: 1287 /* HDMI doesn't tell us its HDCP(1.4) capability, so assume to always be capable, 1288 * we can poll for bksv but some displays have an issue with this. Since its so rare 1289 * for a display to not be 1.4 capable, this assumtion is ok 1290 */ 1291 ret = true; 1292 break; 1293 default: 1294 break; 1295 } 1296 return ret; 1297 } 1298 1299 bool dc_link_is_hdcp22(struct dc_link *link, enum signal_type signal) 1300 { 1301 bool ret = false; 1302 1303 switch (signal) { 1304 case SIGNAL_TYPE_DISPLAY_PORT: 1305 case SIGNAL_TYPE_DISPLAY_PORT_MST: 1306 ret = (link->hdcp_caps.bcaps.bits.HDCP_CAPABLE && 1307 link->hdcp_caps.rx_caps.fields.byte0.hdcp_capable && 1308 (link->hdcp_caps.rx_caps.fields.version == 0x2)) ? 1 : 0; 1309 break; 1310 case SIGNAL_TYPE_DVI_SINGLE_LINK: 1311 case SIGNAL_TYPE_DVI_DUAL_LINK: 1312 case SIGNAL_TYPE_HDMI_TYPE_A: 1313 ret = (link->hdcp_caps.rx_caps.fields.version == 0x4) ? 1:0; 1314 break; 1315 default: 1316 break; 1317 } 1318 1319 return ret; 1320 } 1321 #endif // CONFIG_DRM_AMD_DC_HDCP 1322 1323 const struct dc_link_status *dc_link_get_status(const struct dc_link *link) 1324 { 1325 return &link->link_status; 1326 } 1327 1328