1 /* 2 * Copyright © 2008 Intel Corporation 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 (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * Authors: 24 * Keith Packard <keithp@keithp.com> 25 * 26 */ 27 28 #include <linux/export.h> 29 #include <linux/i2c.h> 30 #include <linux/iopoll.h> 31 #include <linux/log2.h> 32 #include <linux/math.h> 33 #include <linux/notifier.h> 34 #include <linux/seq_buf.h> 35 #include <linux/slab.h> 36 #include <linux/sort.h> 37 #include <linux/string_helpers.h> 38 #include <linux/timekeeping.h> 39 #include <linux/types.h> 40 #include <asm/byteorder.h> 41 42 #include <drm/display/drm_dp_helper.h> 43 #include <drm/display/drm_dp_tunnel.h> 44 #include <drm/display/drm_dsc_helper.h> 45 #include <drm/display/drm_hdmi_helper.h> 46 #include <drm/drm_atomic_helper.h> 47 #include <drm/drm_crtc.h> 48 #include <drm/drm_edid.h> 49 #include <drm/drm_fixed.h> 50 #include <drm/drm_print.h> 51 #include <drm/drm_probe_helper.h> 52 53 #include "g4x_dp.h" 54 #include "intel_alpm.h" 55 #include "intel_atomic.h" 56 #include "intel_audio.h" 57 #include "intel_backlight.h" 58 #include "intel_combo_phy_regs.h" 59 #include "intel_connector.h" 60 #include "intel_crtc.h" 61 #include "intel_crtc_state_dump.h" 62 #include "intel_cx0_phy.h" 63 #include "intel_ddi.h" 64 #include "intel_de.h" 65 #include "intel_display_driver.h" 66 #include "intel_display_jiffies.h" 67 #include "intel_display_utils.h" 68 #include "intel_display_regs.h" 69 #include "intel_display_rpm.h" 70 #include "intel_display_types.h" 71 #include "intel_dp.h" 72 #include "intel_dp_aux.h" 73 #include "intel_dp_hdcp.h" 74 #include "intel_dp_link_training.h" 75 #include "intel_dp_mst.h" 76 #include "intel_dp_test.h" 77 #include "intel_dp_tunnel.h" 78 #include "intel_dpio_phy.h" 79 #include "intel_dpll.h" 80 #include "intel_drrs.h" 81 #include "intel_encoder.h" 82 #include "intel_fifo_underrun.h" 83 #include "intel_hdcp.h" 84 #include "intel_hdmi.h" 85 #include "intel_hotplug.h" 86 #include "intel_hotplug_irq.h" 87 #include "intel_lspcon.h" 88 #include "intel_lvds.h" 89 #include "intel_modeset_lock.h" 90 #include "intel_panel.h" 91 #include "intel_pch_display.h" 92 #include "intel_pfit.h" 93 #include "intel_pps.h" 94 #include "intel_psr.h" 95 #include "intel_quirks.h" 96 #include "intel_tc.h" 97 #include "intel_vblank.h" 98 #include "intel_vdsc.h" 99 #include "intel_vrr.h" 100 101 /* Max DSC line buffer depth supported by HW. */ 102 #define INTEL_DP_DSC_MAX_LINE_BUF_DEPTH 13 103 104 /* DP DSC FEC Overhead factor in ppm = 1/(0.972261) = 1.028530 */ 105 #define DP_DSC_FEC_OVERHEAD_FACTOR 1028530 106 107 /* Constants for DP DSC configurations */ 108 static const u8 valid_dsc_bpp[] = {6, 8, 10, 12, 15}; 109 110 /** 111 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH) 112 * @intel_dp: DP struct 113 * 114 * If a CPU or PCH DP output is attached to an eDP panel, this function 115 * will return true, and false otherwise. 116 * 117 * This function is not safe to use prior to encoder type being set. 118 */ 119 bool intel_dp_is_edp(struct intel_dp *intel_dp) 120 { 121 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 122 123 return dig_port->base.type == INTEL_OUTPUT_EDP; 124 } 125 126 static void intel_dp_unset_edid(struct intel_dp *intel_dp); 127 128 /* Is link rate UHBR and thus 128b/132b? */ 129 bool intel_dp_is_uhbr(const struct intel_crtc_state *crtc_state) 130 { 131 return drm_dp_is_uhbr_rate(crtc_state->port_clock); 132 } 133 134 /** 135 * intel_dp_link_symbol_size - get the link symbol size for a given link rate 136 * @rate: link rate in 10kbit/s units 137 * 138 * Returns the link symbol size in bits/symbol units depending on the link 139 * rate -> channel coding. 140 */ 141 int intel_dp_link_symbol_size(int rate) 142 { 143 return drm_dp_is_uhbr_rate(rate) ? 32 : 10; 144 } 145 146 /** 147 * intel_dp_link_symbol_clock - convert link rate to link symbol clock 148 * @rate: link rate in 10kbit/s units 149 * 150 * Returns the link symbol clock frequency in kHz units depending on the 151 * link rate and channel coding. 152 */ 153 int intel_dp_link_symbol_clock(int rate) 154 { 155 return DIV_ROUND_CLOSEST(rate * 10, intel_dp_link_symbol_size(rate)); 156 } 157 158 static int max_dprx_rate(struct intel_dp *intel_dp) 159 { 160 struct intel_display *display = to_intel_display(intel_dp); 161 int max_rate; 162 163 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 164 max_rate = drm_dp_tunnel_max_dprx_rate(intel_dp->tunnel); 165 else 166 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]); 167 168 /* 169 * Some platforms + eDP panels may not reliably support HBR3 170 * due to signal integrity limitations, despite advertising it. 171 * Cap the link rate to HBR2 to avoid unstable configurations for the 172 * known machines. 173 */ 174 if (intel_dp_is_edp(intel_dp) && intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2)) 175 max_rate = min(max_rate, 540000); 176 177 return max_rate; 178 } 179 180 static int max_dprx_lane_count(struct intel_dp *intel_dp) 181 { 182 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 183 return drm_dp_tunnel_max_dprx_lane_count(intel_dp->tunnel); 184 185 return drm_dp_max_lane_count(intel_dp->dpcd); 186 } 187 188 static void intel_dp_set_default_sink_rates(struct intel_dp *intel_dp) 189 { 190 intel_dp->sink_rates[0] = 162000; 191 intel_dp->num_sink_rates = 1; 192 } 193 194 /* update sink rates from dpcd */ 195 static void intel_dp_set_dpcd_sink_rates(struct intel_dp *intel_dp) 196 { 197 static const int dp_rates[] = { 198 162000, 270000, 540000, 810000 199 }; 200 int i, max_rate; 201 int max_lttpr_rate; 202 203 if (drm_dp_has_quirk(&intel_dp->desc, DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS)) { 204 /* Needed, e.g., for Apple MBP 2017, 15 inch eDP Retina panel */ 205 static const int quirk_rates[] = { 162000, 270000, 324000 }; 206 207 memcpy(intel_dp->sink_rates, quirk_rates, sizeof(quirk_rates)); 208 intel_dp->num_sink_rates = ARRAY_SIZE(quirk_rates); 209 210 return; 211 } 212 213 /* 214 * Sink rates for 8b/10b. 215 */ 216 max_rate = max_dprx_rate(intel_dp); 217 max_lttpr_rate = drm_dp_lttpr_max_link_rate(intel_dp->lttpr_common_caps); 218 if (max_lttpr_rate) 219 max_rate = min(max_rate, max_lttpr_rate); 220 221 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) { 222 if (dp_rates[i] > max_rate) 223 break; 224 intel_dp->sink_rates[i] = dp_rates[i]; 225 } 226 227 /* 228 * Sink rates for 128b/132b. If set, sink should support all 8b/10b 229 * rates and 10 Gbps. 230 */ 231 if (drm_dp_128b132b_supported(intel_dp->dpcd)) { 232 u8 uhbr_rates = 0; 233 234 BUILD_BUG_ON(ARRAY_SIZE(intel_dp->sink_rates) < ARRAY_SIZE(dp_rates) + 3); 235 236 drm_dp_dpcd_readb(&intel_dp->aux, 237 DP_128B132B_SUPPORTED_LINK_RATES, &uhbr_rates); 238 239 if (drm_dp_lttpr_count(intel_dp->lttpr_common_caps)) { 240 /* We have a repeater */ 241 if (intel_dp->lttpr_common_caps[0] >= 0x20 && 242 intel_dp->lttpr_common_caps[DP_MAIN_LINK_CHANNEL_CODING_PHY_REPEATER - 243 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV] & 244 DP_PHY_REPEATER_128B132B_SUPPORTED) { 245 /* Repeater supports 128b/132b, valid UHBR rates */ 246 uhbr_rates &= intel_dp->lttpr_common_caps[DP_PHY_REPEATER_128B132B_RATES - 247 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV]; 248 } else { 249 /* Does not support 128b/132b */ 250 uhbr_rates = 0; 251 } 252 } 253 254 if (uhbr_rates & DP_UHBR10) 255 intel_dp->sink_rates[i++] = 1000000; 256 if (uhbr_rates & DP_UHBR13_5) 257 intel_dp->sink_rates[i++] = 1350000; 258 if (uhbr_rates & DP_UHBR20) 259 intel_dp->sink_rates[i++] = 2000000; 260 } 261 262 intel_dp->num_sink_rates = i; 263 } 264 265 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) 266 { 267 struct intel_display *display = to_intel_display(intel_dp); 268 struct intel_connector *connector = intel_dp->attached_connector; 269 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 270 struct intel_encoder *encoder = &intel_dig_port->base; 271 272 intel_dp_set_dpcd_sink_rates(intel_dp); 273 274 if (intel_dp->num_sink_rates) 275 return; 276 277 drm_err(display->drm, 278 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Invalid DPCD with no link rates, using defaults\n", 279 connector->base.base.id, connector->base.name, 280 encoder->base.base.id, encoder->base.name); 281 282 intel_dp_set_default_sink_rates(intel_dp); 283 } 284 285 static void intel_dp_set_default_max_sink_lane_count(struct intel_dp *intel_dp) 286 { 287 intel_dp->max_sink_lane_count = 1; 288 } 289 290 static void intel_dp_set_max_sink_lane_count(struct intel_dp *intel_dp) 291 { 292 struct intel_display *display = to_intel_display(intel_dp); 293 struct intel_connector *connector = intel_dp->attached_connector; 294 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 295 struct intel_encoder *encoder = &intel_dig_port->base; 296 297 intel_dp->max_sink_lane_count = max_dprx_lane_count(intel_dp); 298 299 switch (intel_dp->max_sink_lane_count) { 300 case 1: 301 case 2: 302 case 4: 303 return; 304 } 305 306 drm_err(display->drm, 307 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Invalid DPCD max lane count (%d), using default\n", 308 connector->base.base.id, connector->base.name, 309 encoder->base.base.id, encoder->base.name, 310 intel_dp->max_sink_lane_count); 311 312 intel_dp_set_default_max_sink_lane_count(intel_dp); 313 } 314 315 /* Get length of rates array potentially limited by max_rate. */ 316 static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate) 317 { 318 int i; 319 320 /* Limit results by potentially reduced max rate */ 321 for (i = 0; i < len; i++) { 322 if (rates[len - i - 1] <= max_rate) 323 return len - i; 324 } 325 326 return 0; 327 } 328 329 /* Get length of common rates array potentially limited by max_rate. */ 330 static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp, 331 int max_rate) 332 { 333 return intel_dp_rate_limit_len(intel_dp->common_rates, 334 intel_dp->num_common_rates, max_rate); 335 } 336 337 int intel_dp_common_rate(struct intel_dp *intel_dp, int index) 338 { 339 struct intel_display *display = to_intel_display(intel_dp); 340 341 if (drm_WARN_ON(display->drm, 342 index < 0 || index >= intel_dp->num_common_rates)) 343 return 162000; 344 345 return intel_dp->common_rates[index]; 346 } 347 348 /* Theoretical max between source and sink */ 349 int intel_dp_max_common_rate(struct intel_dp *intel_dp) 350 { 351 return intel_dp_common_rate(intel_dp, intel_dp->num_common_rates - 1); 352 } 353 354 int intel_dp_max_source_lane_count(struct intel_digital_port *dig_port) 355 { 356 int vbt_max_lanes = intel_bios_dp_max_lane_count(dig_port->base.devdata); 357 int max_lanes = dig_port->max_lanes; 358 359 if (vbt_max_lanes) 360 max_lanes = min(max_lanes, vbt_max_lanes); 361 362 return max_lanes; 363 } 364 365 /* Theoretical max between source and sink */ 366 int intel_dp_max_common_lane_count(struct intel_dp *intel_dp) 367 { 368 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 369 int source_max = intel_dp_max_source_lane_count(dig_port); 370 int sink_max = intel_dp->max_sink_lane_count; 371 int lane_max = intel_tc_port_max_lane_count(dig_port); 372 int lttpr_max = drm_dp_lttpr_max_lane_count(intel_dp->lttpr_common_caps); 373 374 if (lttpr_max) 375 sink_max = min(sink_max, lttpr_max); 376 377 return min3(source_max, sink_max, lane_max); 378 } 379 380 static int forced_lane_count(struct intel_dp *intel_dp) 381 { 382 return clamp(intel_dp->link.force_lane_count, 1, intel_dp_max_common_lane_count(intel_dp)); 383 } 384 385 int intel_dp_max_lane_count(struct intel_dp *intel_dp) 386 { 387 int lane_count; 388 389 if (intel_dp->link.force_lane_count) 390 lane_count = forced_lane_count(intel_dp); 391 else 392 lane_count = intel_dp->link.max_lane_count; 393 394 switch (lane_count) { 395 case 1: 396 case 2: 397 case 4: 398 return lane_count; 399 default: 400 MISSING_CASE(lane_count); 401 return 1; 402 } 403 } 404 405 static int intel_dp_min_lane_count(struct intel_dp *intel_dp) 406 { 407 if (intel_dp->link.force_lane_count) 408 return forced_lane_count(intel_dp); 409 410 return 1; 411 } 412 413 int intel_dp_link_bw_overhead(int link_clock, int lane_count, int hdisplay, 414 int dsc_slice_count, int bpp_x16, unsigned long flags) 415 { 416 int overhead; 417 418 WARN_ON(flags & ~(DRM_DP_BW_OVERHEAD_MST | DRM_DP_BW_OVERHEAD_SSC_REF_CLK | 419 DRM_DP_BW_OVERHEAD_FEC)); 420 421 if (drm_dp_is_uhbr_rate(link_clock)) 422 flags |= DRM_DP_BW_OVERHEAD_UHBR; 423 424 if (dsc_slice_count) 425 flags |= DRM_DP_BW_OVERHEAD_DSC; 426 427 overhead = drm_dp_bw_overhead(lane_count, hdisplay, 428 dsc_slice_count, 429 bpp_x16, 430 flags); 431 432 /* 433 * TODO: clarify whether a minimum required by the fixed FEC overhead 434 * in the bspec audio programming sequence is required here. 435 */ 436 return max(overhead, intel_dp_bw_fec_overhead(flags & DRM_DP_BW_OVERHEAD_FEC)); 437 } 438 439 /* 440 * The required data bandwidth for a mode with given pixel clock and bpp. This 441 * is the required net bandwidth independent of the data bandwidth efficiency. 442 */ 443 int intel_dp_link_required(int link_clock, int lane_count, 444 int mode_clock, int mode_hdisplay, 445 int link_bpp_x16, unsigned long bw_overhead_flags) 446 { 447 int bw_overhead = intel_dp_link_bw_overhead(link_clock, lane_count, mode_hdisplay, 448 0, link_bpp_x16, bw_overhead_flags); 449 450 return intel_dp_effective_data_rate(mode_clock, link_bpp_x16, bw_overhead); 451 } 452 453 /** 454 * intel_dp_effective_data_rate - Return the pixel data rate accounting for BW allocation overhead 455 * @pixel_clock: pixel clock in kHz 456 * @bpp_x16: bits per pixel .4 fixed point format 457 * @bw_overhead: BW allocation overhead in 1ppm units 458 * 459 * Return the effective pixel data rate in kB/sec units taking into account 460 * the provided SSC, FEC, DSC BW allocation overhead. 461 */ 462 int intel_dp_effective_data_rate(int pixel_clock, int bpp_x16, 463 int bw_overhead) 464 { 465 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_clock * bpp_x16, bw_overhead), 466 1000000 * 16 * 8); 467 } 468 469 /** 470 * intel_dp_max_link_data_rate: Calculate the maximum rate for the given link params 471 * @intel_dp: Intel DP object 472 * @max_dprx_rate: Maximum data rate of the DPRX 473 * @max_dprx_lanes: Maximum lane count of the DPRX 474 * 475 * Calculate the maximum data rate for the provided link parameters taking into 476 * account any BW limitations by a DP tunnel attached to @intel_dp. 477 * 478 * Returns the maximum data rate in kBps units. 479 */ 480 int intel_dp_max_link_data_rate(struct intel_dp *intel_dp, 481 int max_dprx_rate, int max_dprx_lanes) 482 { 483 int max_rate = drm_dp_max_dprx_data_rate(max_dprx_rate, max_dprx_lanes); 484 485 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 486 max_rate = min(max_rate, 487 drm_dp_tunnel_available_bw(intel_dp->tunnel)); 488 489 return max_rate; 490 } 491 492 bool intel_dp_has_joiner(struct intel_dp *intel_dp) 493 { 494 struct intel_display *display = to_intel_display(intel_dp); 495 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 496 struct intel_encoder *encoder = &intel_dig_port->base; 497 struct intel_connector *connector = intel_dp->attached_connector; 498 499 /* eDP MSO is not compatible with joiner */ 500 if (intel_dp->mso_link_count) 501 return false; 502 503 if (intel_dp_is_edp(intel_dp) && 504 !connector->panel.vbt.edp.pipe_joiner_enable) 505 return false; 506 507 return DISPLAY_VER(display) >= 12 || 508 (DISPLAY_VER(display) == 11 && 509 encoder->port != PORT_A); 510 } 511 512 static int dg2_max_source_rate(struct intel_dp *intel_dp) 513 { 514 return intel_dp_is_edp(intel_dp) ? 810000 : 1350000; 515 } 516 517 static int icl_max_source_rate(struct intel_dp *intel_dp) 518 { 519 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 520 521 if (intel_encoder_is_combo(encoder) && !intel_dp_is_edp(intel_dp)) 522 return 540000; 523 524 return 810000; 525 } 526 527 static int ehl_max_source_rate(struct intel_dp *intel_dp) 528 { 529 if (intel_dp_is_edp(intel_dp)) 530 return 540000; 531 532 return 810000; 533 } 534 535 static int mtl_max_source_rate(struct intel_dp *intel_dp) 536 { 537 struct intel_display *display = to_intel_display(intel_dp); 538 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 539 540 if (intel_encoder_is_c10phy(encoder) || 541 display->platform.pantherlake_wildcatlake) 542 return 810000; 543 544 if (DISPLAY_VERx100(display) == 1401) 545 return 1350000; 546 547 return 2000000; 548 } 549 550 static int vbt_max_link_rate(struct intel_dp *intel_dp) 551 { 552 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 553 int max_rate; 554 555 max_rate = intel_bios_dp_max_link_rate(encoder->devdata); 556 557 if (intel_dp_is_edp(intel_dp)) { 558 struct intel_connector *connector = intel_dp->attached_connector; 559 int edp_max_rate = connector->panel.vbt.edp.max_link_rate; 560 561 if (max_rate && edp_max_rate) 562 max_rate = min(max_rate, edp_max_rate); 563 else if (edp_max_rate) 564 max_rate = edp_max_rate; 565 } 566 567 return max_rate; 568 } 569 570 static void 571 intel_dp_set_source_rates(struct intel_dp *intel_dp) 572 { 573 /* The values must be in increasing order */ 574 static const int bmg_rates[] = { 575 162000, 216000, 243000, 270000, 324000, 432000, 540000, 675000, 576 810000, 1000000, 1350000, 577 }; 578 static const int mtl_rates[] = { 579 162000, 216000, 243000, 270000, 324000, 432000, 540000, 675000, 580 810000, 1000000, 2000000, 581 }; 582 static const int icl_rates[] = { 583 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000, 584 1000000, 1350000, 585 }; 586 static const int bxt_rates[] = { 587 162000, 216000, 243000, 270000, 324000, 432000, 540000 588 }; 589 static const int skl_rates[] = { 590 162000, 216000, 270000, 324000, 432000, 540000 591 }; 592 static const int hsw_rates[] = { 593 162000, 270000, 540000 594 }; 595 static const int g4x_rates[] = { 596 162000, 270000 597 }; 598 struct intel_display *display = to_intel_display(intel_dp); 599 const int *source_rates; 600 int size, max_rate = 0, vbt_max_rate; 601 602 /* This should only be done once */ 603 drm_WARN_ON(display->drm, 604 intel_dp->source_rates || intel_dp->num_source_rates); 605 606 if (DISPLAY_VER(display) >= 14) { 607 if (display->platform.battlemage) { 608 source_rates = bmg_rates; 609 size = ARRAY_SIZE(bmg_rates); 610 } else { 611 source_rates = mtl_rates; 612 size = ARRAY_SIZE(mtl_rates); 613 } 614 max_rate = mtl_max_source_rate(intel_dp); 615 } else if (DISPLAY_VER(display) >= 11) { 616 source_rates = icl_rates; 617 size = ARRAY_SIZE(icl_rates); 618 if (display->platform.dg2) 619 max_rate = dg2_max_source_rate(intel_dp); 620 else if (display->platform.alderlake_p || display->platform.alderlake_s || 621 display->platform.dg1 || display->platform.rocketlake) 622 max_rate = 810000; 623 else if (display->platform.jasperlake || display->platform.elkhartlake) 624 max_rate = ehl_max_source_rate(intel_dp); 625 else 626 max_rate = icl_max_source_rate(intel_dp); 627 } else if (display->platform.geminilake || display->platform.broxton) { 628 source_rates = bxt_rates; 629 size = ARRAY_SIZE(bxt_rates); 630 } else if (DISPLAY_VER(display) == 9) { 631 source_rates = skl_rates; 632 size = ARRAY_SIZE(skl_rates); 633 } else if ((display->platform.haswell && !display->platform.haswell_ulx) || 634 display->platform.broadwell) { 635 source_rates = hsw_rates; 636 size = ARRAY_SIZE(hsw_rates); 637 } else { 638 source_rates = g4x_rates; 639 size = ARRAY_SIZE(g4x_rates); 640 } 641 642 vbt_max_rate = vbt_max_link_rate(intel_dp); 643 if (max_rate && vbt_max_rate) 644 max_rate = min(max_rate, vbt_max_rate); 645 else if (vbt_max_rate) 646 max_rate = vbt_max_rate; 647 648 if (max_rate) 649 size = intel_dp_rate_limit_len(source_rates, size, max_rate); 650 651 intel_dp->source_rates = source_rates; 652 intel_dp->num_source_rates = size; 653 } 654 655 static int intersect_rates(const int *source_rates, int source_len, 656 const int *sink_rates, int sink_len, 657 int *common_rates) 658 { 659 int i = 0, j = 0, k = 0; 660 661 while (i < source_len && j < sink_len) { 662 if (source_rates[i] == sink_rates[j]) { 663 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) 664 return k; 665 common_rates[k] = source_rates[i]; 666 ++k; 667 ++i; 668 ++j; 669 } else if (source_rates[i] < sink_rates[j]) { 670 ++i; 671 } else { 672 ++j; 673 } 674 } 675 return k; 676 } 677 678 /* return index of rate in rates array, or -1 if not found */ 679 int intel_dp_rate_index(const int *rates, int len, int rate) 680 { 681 int i; 682 683 for (i = 0; i < len; i++) 684 if (rate == rates[i]) 685 return i; 686 687 return -1; 688 } 689 690 static int intel_dp_link_config_rate(struct intel_dp *intel_dp, 691 const struct intel_dp_link_config *lc) 692 { 693 return intel_dp_common_rate(intel_dp, lc->link_rate_idx); 694 } 695 696 static int intel_dp_link_config_lane_count(const struct intel_dp_link_config *lc) 697 { 698 return 1 << lc->lane_count_exp; 699 } 700 701 static int intel_dp_link_config_bw(struct intel_dp *intel_dp, 702 const struct intel_dp_link_config *lc) 703 { 704 return drm_dp_max_dprx_data_rate(intel_dp_link_config_rate(intel_dp, lc), 705 intel_dp_link_config_lane_count(lc)); 706 } 707 708 static int link_config_cmp_by_bw(const void *a, const void *b, const void *p) 709 { 710 struct intel_dp *intel_dp = (struct intel_dp *)p; /* remove const */ 711 const struct intel_dp_link_config *lc_a = a; 712 const struct intel_dp_link_config *lc_b = b; 713 int bw_a = intel_dp_link_config_bw(intel_dp, lc_a); 714 int bw_b = intel_dp_link_config_bw(intel_dp, lc_b); 715 716 if (bw_a != bw_b) 717 return bw_a - bw_b; 718 719 return intel_dp_link_config_rate(intel_dp, lc_a) - 720 intel_dp_link_config_rate(intel_dp, lc_b); 721 } 722 723 static void intel_dp_link_config_init(struct intel_dp *intel_dp) 724 { 725 struct intel_display *display = to_intel_display(intel_dp); 726 struct intel_dp_link_config *lc; 727 int num_common_lane_configs; 728 int i; 729 int j; 730 731 if (drm_WARN_ON(display->drm, !is_power_of_2(intel_dp_max_common_lane_count(intel_dp)))) 732 return; 733 734 num_common_lane_configs = ilog2(intel_dp_max_common_lane_count(intel_dp)) + 1; 735 736 if (drm_WARN_ON(display->drm, intel_dp->num_common_rates * num_common_lane_configs > 737 ARRAY_SIZE(intel_dp->link.configs))) 738 return; 739 740 intel_dp->link.num_configs = intel_dp->num_common_rates * num_common_lane_configs; 741 742 lc = &intel_dp->link.configs[0]; 743 for (i = 0; i < intel_dp->num_common_rates; i++) { 744 for (j = 0; j < num_common_lane_configs; j++) { 745 lc->lane_count_exp = j; 746 lc->link_rate_idx = i; 747 748 lc++; 749 } 750 } 751 752 sort_r(intel_dp->link.configs, intel_dp->link.num_configs, 753 sizeof(intel_dp->link.configs[0]), 754 link_config_cmp_by_bw, NULL, 755 intel_dp); 756 } 757 758 void intel_dp_link_config_get(struct intel_dp *intel_dp, int idx, int *link_rate, int *lane_count) 759 { 760 struct intel_display *display = to_intel_display(intel_dp); 761 const struct intel_dp_link_config *lc; 762 763 if (drm_WARN_ON(display->drm, idx < 0 || idx >= intel_dp->link.num_configs)) 764 idx = 0; 765 766 lc = &intel_dp->link.configs[idx]; 767 768 *link_rate = intel_dp_link_config_rate(intel_dp, lc); 769 *lane_count = intel_dp_link_config_lane_count(lc); 770 } 771 772 int intel_dp_link_config_index(struct intel_dp *intel_dp, int link_rate, int lane_count) 773 { 774 int link_rate_idx = intel_dp_rate_index(intel_dp->common_rates, intel_dp->num_common_rates, 775 link_rate); 776 int lane_count_exp = ilog2(lane_count); 777 int i; 778 779 for (i = 0; i < intel_dp->link.num_configs; i++) { 780 const struct intel_dp_link_config *lc = &intel_dp->link.configs[i]; 781 782 if (lc->lane_count_exp == lane_count_exp && 783 lc->link_rate_idx == link_rate_idx) 784 return i; 785 } 786 787 return -1; 788 } 789 790 static void intel_dp_set_common_rates(struct intel_dp *intel_dp) 791 { 792 struct intel_display *display = to_intel_display(intel_dp); 793 794 drm_WARN_ON(display->drm, 795 !intel_dp->num_source_rates || !intel_dp->num_sink_rates); 796 797 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates, 798 intel_dp->num_source_rates, 799 intel_dp->sink_rates, 800 intel_dp->num_sink_rates, 801 intel_dp->common_rates); 802 803 /* Paranoia, there should always be something in common. */ 804 if (drm_WARN_ON(display->drm, intel_dp->num_common_rates == 0)) { 805 intel_dp->common_rates[0] = 162000; 806 intel_dp->num_common_rates = 1; 807 } 808 809 intel_dp_link_config_init(intel_dp); 810 } 811 812 bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate, 813 u8 lane_count) 814 { 815 /* 816 * FIXME: we need to synchronize the current link parameters with 817 * hardware readout. Currently fast link training doesn't work on 818 * boot-up. 819 */ 820 if (link_rate == 0 || 821 link_rate > intel_dp->link.max_rate) 822 return false; 823 824 if (lane_count == 0 || 825 lane_count > intel_dp_max_lane_count(intel_dp)) 826 return false; 827 828 return true; 829 } 830 831 u32 intel_dp_mode_to_fec_clock(u32 mode_clock) 832 { 833 return div_u64(mul_u32_u32(mode_clock, DP_DSC_FEC_OVERHEAD_FACTOR), 834 1000000U); 835 } 836 837 int intel_dp_bw_fec_overhead(bool fec_enabled) 838 { 839 /* 840 * TODO: Calculate the actual overhead for a given mode. 841 * The hard-coded 1/0.972261=2.853% overhead factor 842 * corresponds (for instance) to the 8b/10b DP FEC 2.4% + 843 * 0.453% DSC overhead. This is enough for a 3840 width mode, 844 * which has a DSC overhead of up to ~0.2%, but may not be 845 * enough for a 1024 width mode where this is ~0.8% (on a 4 846 * lane DP link, with 2 DSC slices and 8 bpp color depth). 847 */ 848 return fec_enabled ? DP_DSC_FEC_OVERHEAD_FACTOR : 1000000; 849 } 850 851 static int 852 small_joiner_ram_size_bits(struct intel_display *display) 853 { 854 if (DISPLAY_VER(display) >= 13) 855 return 17280 * 8; 856 else if (DISPLAY_VER(display) >= 11) 857 return 7680 * 8; 858 else 859 return 6144 * 8; 860 } 861 862 static int align_min_vesa_compressed_bpp_x16(int min_link_bpp_x16) 863 { 864 int i; 865 866 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp); i++) { 867 int vesa_bpp_x16 = fxp_q4_from_int(valid_dsc_bpp[i]); 868 869 if (vesa_bpp_x16 >= min_link_bpp_x16) 870 return vesa_bpp_x16; 871 } 872 873 return 0; 874 } 875 876 static int align_max_vesa_compressed_bpp_x16(int max_link_bpp_x16) 877 { 878 int i; 879 880 for (i = ARRAY_SIZE(valid_dsc_bpp) - 1; i >= 0; i--) { 881 int vesa_bpp_x16 = fxp_q4_from_int(valid_dsc_bpp[i]); 882 883 if (vesa_bpp_x16 <= max_link_bpp_x16) 884 return vesa_bpp_x16; 885 } 886 887 return 0; 888 } 889 890 static int bigjoiner_interface_bits(struct intel_display *display) 891 { 892 return DISPLAY_VER(display) >= 14 ? 36 : 24; 893 } 894 895 static u32 bigjoiner_bw_max_bpp(struct intel_display *display, u32 mode_clock, 896 int num_joined_pipes) 897 { 898 u32 max_bpp; 899 /* With bigjoiner multiple dsc engines are used in parallel so PPC is 2 */ 900 int ppc = 2; 901 int num_big_joiners = num_joined_pipes / 2; 902 903 max_bpp = display->cdclk.max_cdclk_freq * ppc * bigjoiner_interface_bits(display) / 904 intel_dp_mode_to_fec_clock(mode_clock); 905 906 max_bpp *= num_big_joiners; 907 908 return max_bpp; 909 910 } 911 912 static u32 small_joiner_ram_max_bpp(struct intel_display *display, 913 u32 mode_hdisplay, 914 int num_joined_pipes) 915 { 916 u32 max_bpp; 917 918 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */ 919 max_bpp = small_joiner_ram_size_bits(display) / mode_hdisplay; 920 921 max_bpp *= num_joined_pipes; 922 923 return max_bpp; 924 } 925 926 static int ultrajoiner_ram_bits(void) 927 { 928 return 4 * 72 * 512; 929 } 930 931 static u32 ultrajoiner_ram_max_bpp(u32 mode_hdisplay) 932 { 933 return ultrajoiner_ram_bits() / mode_hdisplay; 934 } 935 936 /* TODO: return a bpp_x16 value */ 937 static 938 u32 get_max_compressed_bpp_with_joiner(struct intel_display *display, 939 u32 mode_clock, u32 mode_hdisplay, 940 int num_joined_pipes) 941 { 942 u32 max_bpp = small_joiner_ram_max_bpp(display, mode_hdisplay, num_joined_pipes); 943 944 if (num_joined_pipes > 1) 945 max_bpp = min(max_bpp, bigjoiner_bw_max_bpp(display, mode_clock, 946 num_joined_pipes)); 947 if (num_joined_pipes == 4) 948 max_bpp = min(max_bpp, ultrajoiner_ram_max_bpp(mode_hdisplay)); 949 950 return max_bpp; 951 } 952 953 static int intel_dp_dsc_min_slice_count(const struct intel_connector *connector, 954 int mode_clock, int mode_hdisplay) 955 { 956 struct intel_display *display = to_intel_display(connector); 957 bool is_edp = 958 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP; 959 int min_slice_count; 960 int max_slice_width; 961 int tp_rgb_yuv444; 962 int tp_yuv422_420; 963 964 /* 965 * TODO: allow using less than the maximum number of slices 966 * supported by the eDP sink, to allow using fewer DSC engines. 967 */ 968 if (is_edp) 969 return drm_dp_dsc_sink_max_slice_count(connector->dp.dsc_dpcd, true); 970 971 /* 972 * TODO: Use the throughput value specific to the actual RGB/YUV 973 * format of the output. 974 * The RGB/YUV444 throughput value should be always either equal 975 * or smaller than the YUV422/420 value, but let's not depend on 976 * this assumption. 977 */ 978 if (mode_clock > max(connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444, 979 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420)) 980 return 0; 981 982 if (mode_hdisplay > connector->dp.dsc_branch_caps.max_line_width) 983 return 0; 984 985 /* 986 * TODO: Pass the total pixel rate of all the streams transferred to 987 * an MST tiled display, calculate the total slice count for all tiles 988 * from this and the per-tile slice count from the total slice count. 989 */ 990 tp_rgb_yuv444 = drm_dp_dsc_sink_max_slice_throughput(connector->dp.dsc_dpcd, 991 mode_clock, true); 992 tp_yuv422_420 = drm_dp_dsc_sink_max_slice_throughput(connector->dp.dsc_dpcd, 993 mode_clock, false); 994 995 /* 996 * TODO: Use the throughput value specific to the actual RGB/YUV 997 * format of the output. 998 * For now use the smaller of these, which is ok, potentially 999 * resulting in a higher than required minimum slice count. 1000 * The RGB/YUV444 throughput value should be always either equal 1001 * or smaller than the YUV422/420 value, but let's not depend on 1002 * this assumption. 1003 */ 1004 min_slice_count = DIV_ROUND_UP(mode_clock, min(tp_rgb_yuv444, tp_yuv422_420)); 1005 1006 /* 1007 * Due to some DSC engine BW limitations, we need to enable second 1008 * slice and VDSC engine, whenever we approach close enough to max CDCLK 1009 */ 1010 if (mode_clock >= ((display->cdclk.max_cdclk_freq * 85) / 100)) 1011 min_slice_count = max(min_slice_count, 2); 1012 1013 max_slice_width = drm_dp_dsc_sink_max_slice_width(connector->dp.dsc_dpcd); 1014 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) { 1015 drm_dbg_kms(display->drm, 1016 "Unsupported slice width %d by DP DSC Sink device\n", 1017 max_slice_width); 1018 return 0; 1019 } 1020 /* Also take into account max slice width */ 1021 min_slice_count = max(min_slice_count, 1022 DIV_ROUND_UP(mode_hdisplay, max_slice_width)); 1023 1024 return min_slice_count; 1025 } 1026 1027 static bool 1028 intel_dp_dsc_get_slice_config(const struct intel_connector *connector, 1029 int mode_clock, int mode_hdisplay, 1030 int num_joined_pipes, 1031 struct intel_dsc_slice_config *config_ret) 1032 { 1033 struct intel_display *display = to_intel_display(connector); 1034 int min_slice_count = 1035 intel_dp_dsc_min_slice_count(connector, mode_clock, mode_hdisplay); 1036 bool is_edp = 1037 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP; 1038 u32 sink_slice_count_mask = 1039 drm_dp_dsc_sink_slice_count_mask(connector->dp.dsc_dpcd, is_edp); 1040 int slices_per_pipe; 1041 1042 /* 1043 * Find the closest match to the valid slice count values 1044 * 1045 * Max HW DSC-per-pipe x slice-per-DSC (= slice-per-pipe) capability: 1046 * ICL: 2x2 1047 * BMG: 2x2, or for ultrajoined 4 pipes: 3x1 1048 * TGL+: 2x4 (TODO: Add support for this) 1049 * 1050 * TODO: Explore if it's worth increasing the number of slices (from 1 1051 * to 2 or 3), so that multiple VDSC engines can be used, thus 1052 * reducing the minimum CDCLK requirement, which in turn is determined 1053 * by the 1 pixel per clock VDSC engine throughput in 1054 * intel_vdsc_min_cdclk(). 1055 */ 1056 for (slices_per_pipe = 1; slices_per_pipe <= 4; slices_per_pipe++) { 1057 struct intel_dsc_slice_config config; 1058 int slices_per_line; 1059 1060 if (!intel_dsc_get_slice_config(display, 1061 num_joined_pipes, slices_per_pipe, 1062 &config)) 1063 continue; 1064 1065 slices_per_line = intel_dsc_line_slice_count(&config); 1066 1067 if (!(drm_dp_dsc_slice_count_to_mask(slices_per_line) & 1068 sink_slice_count_mask)) 1069 continue; 1070 1071 if (mode_hdisplay % slices_per_line) 1072 continue; 1073 1074 if (min_slice_count <= slices_per_line) { 1075 *config_ret = config; 1076 1077 return true; 1078 } 1079 } 1080 1081 /* Print slice count 1,2,4,..24 if bit#0,1,3,..23 is set in the mask. */ 1082 sink_slice_count_mask <<= 1; 1083 drm_dbg_kms(display->drm, 1084 "[CONNECTOR:%d:%s] Unsupported slice count (min: %d, sink supported: %*pbl)\n", 1085 connector->base.base.id, connector->base.name, 1086 min_slice_count, 1087 (int)BITS_PER_TYPE(sink_slice_count_mask), &sink_slice_count_mask); 1088 1089 return false; 1090 } 1091 1092 u8 intel_dp_dsc_get_slice_count(const struct intel_connector *connector, 1093 int mode_clock, int mode_hdisplay, 1094 int num_joined_pipes) 1095 { 1096 struct intel_dsc_slice_config config; 1097 1098 if (!intel_dp_dsc_get_slice_config(connector, 1099 mode_clock, mode_hdisplay, 1100 num_joined_pipes, &config)) 1101 return 0; 1102 1103 return intel_dsc_line_slice_count(&config); 1104 } 1105 1106 static bool source_can_output(struct intel_dp *intel_dp, 1107 enum intel_output_format format) 1108 { 1109 struct intel_display *display = to_intel_display(intel_dp); 1110 1111 switch (format) { 1112 case INTEL_OUTPUT_FORMAT_RGB: 1113 return true; 1114 1115 case INTEL_OUTPUT_FORMAT_YCBCR444: 1116 /* 1117 * No YCbCr output support on gmch platforms. 1118 * Also, ILK doesn't seem capable of DP YCbCr output. 1119 * The displayed image is severely corrupted. SNB+ is fine. 1120 */ 1121 return !HAS_GMCH(display) && !display->platform.ironlake; 1122 1123 case INTEL_OUTPUT_FORMAT_YCBCR420: 1124 /* Platform < Gen 11 cannot output YCbCr420 format */ 1125 return DISPLAY_VER(display) >= 11; 1126 1127 default: 1128 MISSING_CASE(format); 1129 return false; 1130 } 1131 } 1132 1133 static bool 1134 dfp_can_convert_from_rgb(struct intel_dp *intel_dp, 1135 enum intel_output_format sink_format) 1136 { 1137 if (!drm_dp_is_branch(intel_dp->dpcd)) 1138 return false; 1139 1140 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR444) 1141 return intel_dp->dfp.rgb_to_ycbcr; 1142 1143 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1144 return intel_dp->dfp.rgb_to_ycbcr && 1145 intel_dp->dfp.ycbcr_444_to_420; 1146 1147 return false; 1148 } 1149 1150 static bool 1151 dfp_can_convert_from_ycbcr444(struct intel_dp *intel_dp, 1152 enum intel_output_format sink_format) 1153 { 1154 if (!drm_dp_is_branch(intel_dp->dpcd)) 1155 return false; 1156 1157 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1158 return intel_dp->dfp.ycbcr_444_to_420; 1159 1160 return false; 1161 } 1162 1163 static bool 1164 dfp_can_convert(struct intel_dp *intel_dp, 1165 enum intel_output_format output_format, 1166 enum intel_output_format sink_format) 1167 { 1168 switch (output_format) { 1169 case INTEL_OUTPUT_FORMAT_RGB: 1170 return dfp_can_convert_from_rgb(intel_dp, sink_format); 1171 case INTEL_OUTPUT_FORMAT_YCBCR444: 1172 return dfp_can_convert_from_ycbcr444(intel_dp, sink_format); 1173 default: 1174 MISSING_CASE(output_format); 1175 return false; 1176 } 1177 1178 return false; 1179 } 1180 1181 static enum intel_output_format 1182 intel_dp_output_format(struct intel_connector *connector, 1183 enum intel_output_format sink_format) 1184 { 1185 struct intel_display *display = to_intel_display(connector); 1186 struct intel_dp *intel_dp = intel_attached_dp(connector); 1187 enum intel_output_format force_dsc_output_format = 1188 intel_dp->force_dsc_output_format; 1189 enum intel_output_format output_format; 1190 if (force_dsc_output_format) { 1191 if (source_can_output(intel_dp, force_dsc_output_format) && 1192 (!drm_dp_is_branch(intel_dp->dpcd) || 1193 sink_format != force_dsc_output_format || 1194 dfp_can_convert(intel_dp, force_dsc_output_format, sink_format))) 1195 return force_dsc_output_format; 1196 1197 drm_dbg_kms(display->drm, "Cannot force DSC output format\n"); 1198 } 1199 1200 if (sink_format == INTEL_OUTPUT_FORMAT_RGB || 1201 dfp_can_convert_from_rgb(intel_dp, sink_format)) 1202 output_format = INTEL_OUTPUT_FORMAT_RGB; 1203 1204 else if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR444 || 1205 dfp_can_convert_from_ycbcr444(intel_dp, sink_format)) 1206 output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 1207 1208 else 1209 output_format = INTEL_OUTPUT_FORMAT_YCBCR420; 1210 1211 drm_WARN_ON(display->drm, !source_can_output(intel_dp, output_format)); 1212 1213 return output_format; 1214 } 1215 1216 int intel_dp_min_bpp(enum intel_output_format output_format) 1217 { 1218 if (output_format == INTEL_OUTPUT_FORMAT_RGB) 1219 return intel_display_min_pipe_bpp(); 1220 else 1221 return 8 * 3; 1222 } 1223 1224 int intel_dp_output_format_link_bpp_x16(enum intel_output_format output_format, int pipe_bpp) 1225 { 1226 /* 1227 * bpp value was assumed to RGB format. And YCbCr 4:2:0 output 1228 * format of the number of bytes per pixel will be half the number 1229 * of bytes of RGB pixel. 1230 */ 1231 if (output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1232 pipe_bpp /= 2; 1233 1234 return fxp_q4_from_int(pipe_bpp); 1235 } 1236 1237 static enum intel_output_format 1238 intel_dp_sink_format(struct intel_connector *connector, 1239 const struct drm_display_mode *mode) 1240 { 1241 const struct drm_display_info *info = &connector->base.display_info; 1242 1243 if (drm_mode_is_420_only(info, mode)) 1244 return INTEL_OUTPUT_FORMAT_YCBCR420; 1245 1246 return INTEL_OUTPUT_FORMAT_RGB; 1247 } 1248 1249 static int 1250 intel_dp_mode_min_link_bpp_x16(struct intel_connector *connector, 1251 const struct drm_display_mode *mode) 1252 { 1253 enum intel_output_format output_format, sink_format; 1254 1255 sink_format = intel_dp_sink_format(connector, mode); 1256 1257 output_format = intel_dp_output_format(connector, sink_format); 1258 1259 return intel_dp_output_format_link_bpp_x16(output_format, 1260 intel_dp_min_bpp(output_format)); 1261 } 1262 1263 static bool intel_dp_hdisplay_bad(struct intel_display *display, 1264 int hdisplay) 1265 { 1266 /* 1267 * Older platforms don't like hdisplay==4096 with DP. 1268 * 1269 * On ILK/SNB/IVB the pipe seems to be somewhat running (scanline 1270 * and frame counter increment), but we don't get vblank interrupts, 1271 * and the pipe underruns immediately. The link also doesn't seem 1272 * to get trained properly. 1273 * 1274 * On CHV the vblank interrupts don't seem to disappear but 1275 * otherwise the symptoms are similar. 1276 * 1277 * TODO: confirm the behaviour on HSW+ 1278 */ 1279 return hdisplay == 4096 && !HAS_DDI(display); 1280 } 1281 1282 static int intel_dp_max_tmds_clock(struct intel_dp *intel_dp) 1283 { 1284 struct intel_connector *connector = intel_dp->attached_connector; 1285 const struct drm_display_info *info = &connector->base.display_info; 1286 int max_tmds_clock = intel_dp->dfp.max_tmds_clock; 1287 1288 /* Only consider the sink's max TMDS clock if we know this is a HDMI DFP */ 1289 if (max_tmds_clock && info->max_tmds_clock) 1290 max_tmds_clock = min(max_tmds_clock, info->max_tmds_clock); 1291 1292 return max_tmds_clock; 1293 } 1294 1295 static enum drm_mode_status 1296 intel_dp_tmds_clock_valid(struct intel_dp *intel_dp, 1297 int clock, int bpc, 1298 enum intel_output_format sink_format, 1299 bool respect_downstream_limits) 1300 { 1301 int tmds_clock, min_tmds_clock, max_tmds_clock; 1302 1303 if (!respect_downstream_limits) 1304 return MODE_OK; 1305 1306 tmds_clock = intel_hdmi_tmds_clock(clock, bpc, sink_format); 1307 1308 min_tmds_clock = intel_dp->dfp.min_tmds_clock; 1309 max_tmds_clock = intel_dp_max_tmds_clock(intel_dp); 1310 1311 if (min_tmds_clock && tmds_clock < min_tmds_clock) 1312 return MODE_CLOCK_LOW; 1313 1314 if (max_tmds_clock && tmds_clock > max_tmds_clock) 1315 return MODE_CLOCK_HIGH; 1316 1317 return MODE_OK; 1318 } 1319 1320 static enum drm_mode_status 1321 intel_dp_mode_valid_downstream(struct intel_connector *connector, 1322 const struct drm_display_mode *mode, 1323 int target_clock) 1324 { 1325 struct intel_dp *intel_dp = intel_attached_dp(connector); 1326 const struct drm_display_info *info = &connector->base.display_info; 1327 enum drm_mode_status status; 1328 enum intel_output_format sink_format; 1329 1330 /* If PCON supports FRL MODE, check FRL bandwidth constraints */ 1331 if (intel_dp->dfp.pcon_max_frl_bw) { 1332 int link_bpp_x16 = intel_dp_mode_min_link_bpp_x16(connector, mode); 1333 int target_bw; 1334 int max_frl_bw; 1335 1336 target_bw = fxp_q4_to_int_roundup(link_bpp_x16) * target_clock; 1337 1338 max_frl_bw = intel_dp->dfp.pcon_max_frl_bw; 1339 1340 /* converting bw from Gbps to Kbps*/ 1341 max_frl_bw = max_frl_bw * 1000000; 1342 1343 if (target_bw > max_frl_bw) 1344 return MODE_CLOCK_HIGH; 1345 1346 return MODE_OK; 1347 } 1348 1349 if (intel_dp->dfp.max_dotclock && 1350 target_clock > intel_dp->dfp.max_dotclock) 1351 return MODE_CLOCK_HIGH; 1352 1353 sink_format = intel_dp_sink_format(connector, mode); 1354 1355 /* Assume 8bpc for the DP++/HDMI/DVI TMDS clock check */ 1356 status = intel_dp_tmds_clock_valid(intel_dp, target_clock, 1357 8, sink_format, true); 1358 1359 if (status != MODE_OK) { 1360 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420 || 1361 !connector->base.ycbcr_420_allowed || 1362 !drm_mode_is_420_also(info, mode)) 1363 return status; 1364 sink_format = INTEL_OUTPUT_FORMAT_YCBCR420; 1365 status = intel_dp_tmds_clock_valid(intel_dp, target_clock, 1366 8, sink_format, true); 1367 if (status != MODE_OK) 1368 return status; 1369 } 1370 1371 return MODE_OK; 1372 } 1373 1374 int intel_dp_max_hdisplay_per_pipe(struct intel_display *display) 1375 { 1376 return DISPLAY_VER(display) >= 30 ? 6144 : 5120; 1377 } 1378 1379 bool intel_dp_has_dsc(const struct intel_connector *connector) 1380 { 1381 struct intel_display *display = to_intel_display(connector); 1382 1383 if (!HAS_DSC(display)) 1384 return false; 1385 1386 if (connector->mst.dp && !HAS_DSC_MST(display)) 1387 return false; 1388 1389 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP && 1390 connector->panel.vbt.edp.dsc_disable) 1391 return false; 1392 1393 if (!drm_dp_sink_supports_dsc(connector->dp.dsc_dpcd)) 1394 return false; 1395 1396 return true; 1397 } 1398 1399 static 1400 bool intel_dp_can_join(struct intel_dp *intel_dp, 1401 int num_joined_pipes) 1402 { 1403 struct intel_display *display = to_intel_display(intel_dp); 1404 1405 if (num_joined_pipes > 1 && !intel_dp_has_joiner(intel_dp)) 1406 return false; 1407 1408 switch (num_joined_pipes) { 1409 case 1: 1410 return true; 1411 case 2: 1412 return HAS_BIGJOINER(display) || 1413 HAS_UNCOMPRESSED_JOINER(display); 1414 case 4: 1415 return HAS_ULTRAJOINER(display); 1416 default: 1417 return false; 1418 } 1419 } 1420 1421 bool intel_dp_dotclk_valid(struct intel_display *display, 1422 int target_clock, 1423 int htotal, 1424 int dsc_slice_count, 1425 int num_joined_pipes) 1426 { 1427 int max_dotclk = display->cdclk.max_dotclk_freq; 1428 int effective_dotclk_limit; 1429 1430 effective_dotclk_limit = max_dotclk * num_joined_pipes; 1431 1432 if (dsc_slice_count) 1433 target_clock = intel_dsc_get_pixel_rate_with_dsc_bubbles(display, 1434 target_clock, 1435 htotal, 1436 dsc_slice_count); 1437 else 1438 effective_dotclk_limit = 1439 intel_max_uncompressed_dotclock(display) * num_joined_pipes; 1440 1441 return target_clock <= effective_dotclk_limit; 1442 } 1443 1444 static enum drm_mode_status 1445 intel_dp_mode_valid(struct drm_connector *_connector, 1446 const struct drm_display_mode *mode) 1447 { 1448 struct intel_display *display = to_intel_display(_connector->dev); 1449 struct intel_connector *connector = to_intel_connector(_connector); 1450 struct intel_dp *intel_dp = intel_attached_dp(connector); 1451 enum intel_output_format sink_format, output_format; 1452 const struct drm_display_mode *fixed_mode; 1453 int target_clock = mode->clock; 1454 int max_rate, mode_rate, max_lanes, max_link_clock; 1455 u16 dsc_max_compressed_bpp = 0; 1456 enum drm_mode_status status; 1457 bool dsc = false; 1458 int num_joined_pipes; 1459 int link_bpp_x16; 1460 1461 status = intel_cpu_transcoder_mode_valid(display, mode); 1462 if (status != MODE_OK) 1463 return status; 1464 1465 if (mode->flags & DRM_MODE_FLAG_DBLCLK) 1466 return MODE_H_ILLEGAL; 1467 1468 if (mode->clock < 10000) 1469 return MODE_CLOCK_LOW; 1470 1471 if (intel_dp_hdisplay_bad(display, mode->hdisplay)) 1472 return MODE_H_ILLEGAL; 1473 1474 fixed_mode = intel_panel_fixed_mode(connector, mode); 1475 if (intel_dp_is_edp(intel_dp) && fixed_mode) { 1476 status = intel_panel_mode_valid(connector, mode); 1477 if (status != MODE_OK) 1478 return status; 1479 1480 target_clock = fixed_mode->clock; 1481 } 1482 1483 sink_format = intel_dp_sink_format(connector, mode); 1484 output_format = intel_dp_output_format(connector, sink_format); 1485 1486 max_link_clock = intel_dp_max_link_rate(intel_dp); 1487 max_lanes = intel_dp_max_lane_count(intel_dp); 1488 1489 max_rate = intel_dp_max_link_data_rate(intel_dp, max_link_clock, max_lanes); 1490 1491 link_bpp_x16 = intel_dp_mode_min_link_bpp_x16(connector, mode); 1492 mode_rate = intel_dp_link_required(max_link_clock, max_lanes, 1493 target_clock, mode->hdisplay, 1494 link_bpp_x16, 0); 1495 1496 /* 1497 * We cannot determine the required pipe‑join count before knowing whether 1498 * DSC is needed, nor can we determine DSC need without knowing the pipe 1499 * count. 1500 * Because of this dependency cycle, the only correct approach is to iterate 1501 * over candidate pipe counts and evaluate each combination. 1502 */ 1503 status = MODE_CLOCK_HIGH; 1504 for_each_joiner_candidate(connector, mode, num_joined_pipes) { 1505 int dsc_slice_count = 0; 1506 1507 status = intel_pfit_mode_valid(display, mode, output_format, num_joined_pipes); 1508 if (status != MODE_OK) 1509 continue; 1510 1511 if (intel_dp_has_dsc(connector)) { 1512 int pipe_bpp; 1513 1514 dsc_slice_count = intel_dp_dsc_get_slice_count(connector, 1515 target_clock, 1516 mode->hdisplay, 1517 num_joined_pipes); 1518 1519 /* 1520 * TBD pass the connector BPC, 1521 * for now U8_MAX so that max BPC on that platform would be picked 1522 */ 1523 pipe_bpp = intel_dp_dsc_compute_max_bpp(connector, U8_MAX); 1524 1525 /* 1526 * Output bpp is stored in 6.4 format so right shift by 4 to get the 1527 * integer value since we support only integer values of bpp. 1528 */ 1529 if (intel_dp_is_edp(intel_dp)) { 1530 dsc_max_compressed_bpp = 1531 drm_edp_dsc_sink_output_bpp(connector->dp.dsc_dpcd) >> 4; 1532 1533 dsc = dsc_max_compressed_bpp && dsc_slice_count; 1534 } else if (drm_dp_sink_supports_fec(connector->dp.fec_capability)) { 1535 unsigned long bw_overhead_flags = 0; 1536 1537 if (!drm_dp_is_uhbr_rate(max_link_clock)) 1538 bw_overhead_flags |= DRM_DP_BW_OVERHEAD_FEC; 1539 1540 dsc = intel_dp_mode_valid_with_dsc(connector, 1541 max_link_clock, max_lanes, 1542 target_clock, mode->hdisplay, 1543 num_joined_pipes, 1544 output_format, pipe_bpp, 1545 bw_overhead_flags); 1546 } 1547 } 1548 1549 if (intel_dp_joiner_needs_dsc(display, num_joined_pipes) && !dsc) { 1550 status = MODE_CLOCK_HIGH; 1551 continue; 1552 } 1553 1554 if (mode_rate > max_rate && !dsc) { 1555 status = MODE_CLOCK_HIGH; 1556 continue; 1557 } 1558 1559 status = intel_mode_valid_max_plane_size(display, mode, num_joined_pipes); 1560 if (status != MODE_OK) 1561 continue; 1562 1563 if (!dsc) 1564 dsc_slice_count = 0; 1565 1566 if (!intel_dp_dotclk_valid(display, 1567 target_clock, 1568 mode->htotal, 1569 dsc_slice_count, 1570 num_joined_pipes)) { 1571 status = MODE_CLOCK_HIGH; 1572 continue; 1573 } 1574 1575 break; 1576 } 1577 1578 if (status != MODE_OK) 1579 return status; 1580 1581 return intel_dp_mode_valid_downstream(connector, mode, target_clock); 1582 } 1583 1584 bool intel_dp_source_supports_tps3(struct intel_display *display) 1585 { 1586 return DISPLAY_VER(display) >= 9 || 1587 display->platform.broadwell || display->platform.haswell; 1588 } 1589 1590 bool intel_dp_source_supports_tps4(struct intel_display *display) 1591 { 1592 return DISPLAY_VER(display) >= 10; 1593 } 1594 1595 static void seq_buf_print_array(struct seq_buf *s, const int *array, int nelem) 1596 { 1597 int i; 1598 1599 for (i = 0; i < nelem; i++) 1600 seq_buf_printf(s, "%s%d", i ? ", " : "", array[i]); 1601 } 1602 1603 static void intel_dp_print_rates(struct intel_dp *intel_dp) 1604 { 1605 struct intel_display *display = to_intel_display(intel_dp); 1606 DECLARE_SEQ_BUF(s, 128); /* FIXME: too big for stack? */ 1607 1608 if (!drm_debug_enabled(DRM_UT_KMS)) 1609 return; 1610 1611 seq_buf_print_array(&s, intel_dp->source_rates, intel_dp->num_source_rates); 1612 drm_dbg_kms(display->drm, "source rates: %s\n", seq_buf_str(&s)); 1613 1614 seq_buf_clear(&s); 1615 seq_buf_print_array(&s, intel_dp->sink_rates, intel_dp->num_sink_rates); 1616 drm_dbg_kms(display->drm, "sink rates: %s\n", seq_buf_str(&s)); 1617 1618 seq_buf_clear(&s); 1619 seq_buf_print_array(&s, intel_dp->common_rates, intel_dp->num_common_rates); 1620 drm_dbg_kms(display->drm, "common rates: %s\n", seq_buf_str(&s)); 1621 } 1622 1623 static int forced_link_rate(struct intel_dp *intel_dp) 1624 { 1625 int len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->link.force_rate); 1626 1627 if (len == 0) 1628 return intel_dp_common_rate(intel_dp, 0); 1629 1630 return intel_dp_common_rate(intel_dp, len - 1); 1631 } 1632 1633 int 1634 intel_dp_max_link_rate(struct intel_dp *intel_dp) 1635 { 1636 int len; 1637 1638 if (intel_dp->link.force_rate) 1639 return forced_link_rate(intel_dp); 1640 1641 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->link.max_rate); 1642 1643 return intel_dp_common_rate(intel_dp, len - 1); 1644 } 1645 1646 static int 1647 intel_dp_min_link_rate(struct intel_dp *intel_dp) 1648 { 1649 if (intel_dp->link.force_rate) 1650 return forced_link_rate(intel_dp); 1651 1652 return intel_dp_common_rate(intel_dp, 0); 1653 } 1654 1655 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) 1656 { 1657 struct intel_display *display = to_intel_display(intel_dp); 1658 int i = intel_dp_rate_index(intel_dp->sink_rates, 1659 intel_dp->num_sink_rates, rate); 1660 1661 if (drm_WARN_ON(display->drm, i < 0)) 1662 i = 0; 1663 1664 return i; 1665 } 1666 1667 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, 1668 u8 *link_bw, u8 *rate_select) 1669 { 1670 struct intel_display *display = to_intel_display(intel_dp); 1671 1672 /* FIXME g4x can't generate an exact 2.7GHz with the 96MHz non-SSC refclk */ 1673 if (display->platform.g4x && port_clock == 268800) 1674 port_clock = 270000; 1675 1676 /* eDP 1.4 rate select method. */ 1677 if (intel_dp->use_rate_select) { 1678 *link_bw = 0; 1679 *rate_select = 1680 intel_dp_rate_select(intel_dp, port_clock); 1681 } else { 1682 *link_bw = drm_dp_link_rate_to_bw_code(port_clock); 1683 *rate_select = 0; 1684 } 1685 } 1686 1687 bool intel_dp_has_hdmi_sink(struct intel_dp *intel_dp) 1688 { 1689 struct intel_connector *connector = intel_dp->attached_connector; 1690 1691 return connector->base.display_info.is_hdmi; 1692 } 1693 1694 static bool intel_dp_source_supports_fec(struct intel_dp *intel_dp, 1695 const struct intel_crtc_state *pipe_config) 1696 { 1697 struct intel_display *display = to_intel_display(intel_dp); 1698 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 1699 1700 if (DISPLAY_VER(display) >= 12) 1701 return true; 1702 1703 if (DISPLAY_VER(display) == 11 && encoder->port != PORT_A && 1704 !intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) 1705 return true; 1706 1707 return false; 1708 } 1709 1710 bool intel_dp_supports_fec(struct intel_dp *intel_dp, 1711 const struct intel_connector *connector, 1712 const struct intel_crtc_state *pipe_config) 1713 { 1714 return intel_dp_source_supports_fec(intel_dp, pipe_config) && 1715 drm_dp_sink_supports_fec(connector->dp.fec_capability); 1716 } 1717 1718 bool intel_dp_supports_dsc(struct intel_dp *intel_dp, 1719 const struct intel_connector *connector, 1720 const struct intel_crtc_state *crtc_state) 1721 { 1722 if (!intel_dp_has_dsc(connector)) 1723 return false; 1724 1725 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP) && 1726 !intel_dp_supports_fec(intel_dp, connector, crtc_state)) 1727 return false; 1728 1729 return intel_dsc_source_support(crtc_state); 1730 } 1731 1732 static int intel_dp_hdmi_compute_bpc(struct intel_dp *intel_dp, 1733 const struct intel_crtc_state *crtc_state, 1734 int bpc, bool respect_downstream_limits) 1735 { 1736 int clock = crtc_state->hw.adjusted_mode.crtc_clock; 1737 1738 /* 1739 * Current bpc could already be below 8bpc due to 1740 * FDI bandwidth constraints or other limits. 1741 * HDMI minimum is 8bpc however. 1742 */ 1743 bpc = max(bpc, 8); 1744 1745 /* 1746 * We will never exceed downstream TMDS clock limits while 1747 * attempting deep color. If the user insists on forcing an 1748 * out of spec mode they will have to be satisfied with 8bpc. 1749 */ 1750 if (!respect_downstream_limits) 1751 bpc = 8; 1752 1753 for (; bpc >= 8; bpc -= 2) { 1754 if (intel_hdmi_bpc_possible(crtc_state, bpc, 1755 intel_dp_has_hdmi_sink(intel_dp)) && 1756 intel_dp_tmds_clock_valid(intel_dp, clock, bpc, crtc_state->sink_format, 1757 respect_downstream_limits) == MODE_OK) 1758 return bpc; 1759 } 1760 1761 return -EINVAL; 1762 } 1763 1764 static int intel_dp_max_bpp(struct intel_dp *intel_dp, 1765 const struct intel_crtc_state *crtc_state, 1766 bool respect_downstream_limits) 1767 { 1768 struct intel_display *display = to_intel_display(intel_dp); 1769 struct intel_connector *connector = intel_dp->attached_connector; 1770 int bpp, bpc; 1771 1772 bpc = crtc_state->max_pipe_bpp / 3; 1773 1774 if (intel_dp->dfp.max_bpc) 1775 bpc = min_t(int, bpc, intel_dp->dfp.max_bpc); 1776 1777 if (intel_dp->dfp.min_tmds_clock) { 1778 int max_hdmi_bpc; 1779 1780 max_hdmi_bpc = intel_dp_hdmi_compute_bpc(intel_dp, crtc_state, bpc, 1781 respect_downstream_limits); 1782 if (max_hdmi_bpc < 0) 1783 return 0; 1784 1785 bpc = min(bpc, max_hdmi_bpc); 1786 } 1787 1788 bpp = bpc * 3; 1789 if (intel_dp_is_edp(intel_dp)) { 1790 /* Get bpp from vbt only for panels that dont have bpp in edid */ 1791 if (connector->base.display_info.bpc == 0 && 1792 connector->panel.vbt.edp.bpp && 1793 connector->panel.vbt.edp.bpp < bpp) { 1794 drm_dbg_kms(display->drm, 1795 "clamping bpp for eDP panel to BIOS-provided %i\n", 1796 connector->panel.vbt.edp.bpp); 1797 bpp = connector->panel.vbt.edp.bpp; 1798 } 1799 } 1800 1801 return bpp; 1802 } 1803 1804 static bool has_seamless_m_n(struct intel_connector *connector) 1805 { 1806 struct intel_display *display = to_intel_display(connector); 1807 1808 /* 1809 * Seamless M/N reprogramming only implemented 1810 * for BDW+ double buffered M/N registers so far. 1811 */ 1812 return HAS_DOUBLE_BUFFERED_M_N(display) && 1813 intel_panel_drrs_type(connector) == DRRS_TYPE_SEAMLESS; 1814 } 1815 1816 static int intel_dp_mode_clock(const struct intel_crtc_state *crtc_state, 1817 const struct drm_connector_state *conn_state) 1818 { 1819 struct intel_connector *connector = to_intel_connector(conn_state->connector); 1820 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 1821 1822 /* FIXME a bit of a mess wrt clock vs. crtc_clock */ 1823 if (has_seamless_m_n(connector)) 1824 return intel_panel_highest_mode(connector, adjusted_mode)->clock; 1825 else 1826 return adjusted_mode->crtc_clock; 1827 } 1828 1829 /* Optimize link config in order: max bpp, min clock, min lanes */ 1830 static int 1831 intel_dp_compute_link_config_wide(struct intel_dp *intel_dp, 1832 struct intel_crtc_state *pipe_config, 1833 const struct drm_connector_state *conn_state, 1834 const struct link_config_limits *limits) 1835 { 1836 int bpp, i, lane_count, clock = intel_dp_mode_clock(pipe_config, conn_state); 1837 int link_rate, link_avail; 1838 1839 for (bpp = fxp_q4_to_int(limits->link.max_bpp_x16); 1840 bpp >= fxp_q4_to_int(limits->link.min_bpp_x16); 1841 bpp -= 2 * 3) { 1842 int link_bpp_x16 = 1843 intel_dp_output_format_link_bpp_x16(pipe_config->output_format, bpp); 1844 1845 for (i = 0; i < intel_dp->num_common_rates; i++) { 1846 link_rate = intel_dp_common_rate(intel_dp, i); 1847 if (link_rate < limits->min_rate || 1848 link_rate > limits->max_rate) 1849 continue; 1850 1851 for (lane_count = limits->min_lane_count; 1852 lane_count <= limits->max_lane_count; 1853 lane_count <<= 1) { 1854 const struct drm_display_mode *adjusted_mode = 1855 &pipe_config->hw.adjusted_mode; 1856 int mode_rate = 1857 intel_dp_link_required(link_rate, lane_count, 1858 clock, adjusted_mode->hdisplay, 1859 link_bpp_x16, 0); 1860 1861 link_avail = intel_dp_max_link_data_rate(intel_dp, 1862 link_rate, 1863 lane_count); 1864 1865 if (mode_rate <= link_avail) { 1866 pipe_config->lane_count = lane_count; 1867 pipe_config->pipe_bpp = bpp; 1868 pipe_config->port_clock = link_rate; 1869 1870 return 0; 1871 } 1872 } 1873 } 1874 } 1875 1876 return -EINVAL; 1877 } 1878 1879 int intel_dp_dsc_max_src_input_bpc(struct intel_display *display) 1880 { 1881 /* Max DSC Input BPC for ICL is 10 and for TGL+ is 12 */ 1882 if (DISPLAY_VER(display) >= 12) 1883 return 12; 1884 if (DISPLAY_VER(display) == 11) 1885 return 10; 1886 1887 return intel_dp_dsc_min_src_input_bpc(); 1888 } 1889 1890 static int align_min_sink_dsc_input_bpp(const struct intel_connector *connector, 1891 int min_pipe_bpp) 1892 { 1893 u8 dsc_bpc[3]; 1894 int num_bpc; 1895 int i; 1896 1897 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(connector->dp.dsc_dpcd, 1898 dsc_bpc); 1899 for (i = num_bpc - 1; i >= 0; i--) { 1900 if (dsc_bpc[i] * 3 >= min_pipe_bpp) 1901 return dsc_bpc[i] * 3; 1902 } 1903 1904 return 0; 1905 } 1906 1907 static int align_max_sink_dsc_input_bpp(const struct intel_connector *connector, 1908 int max_pipe_bpp) 1909 { 1910 u8 dsc_bpc[3]; 1911 int num_bpc; 1912 int i; 1913 1914 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(connector->dp.dsc_dpcd, 1915 dsc_bpc); 1916 for (i = 0; i < num_bpc; i++) { 1917 if (dsc_bpc[i] * 3 <= max_pipe_bpp) 1918 return dsc_bpc[i] * 3; 1919 } 1920 1921 return 0; 1922 } 1923 1924 int intel_dp_dsc_compute_max_bpp(const struct intel_connector *connector, 1925 u8 max_req_bpc) 1926 { 1927 struct intel_display *display = to_intel_display(connector); 1928 int dsc_max_bpc; 1929 1930 dsc_max_bpc = intel_dp_dsc_max_src_input_bpc(display); 1931 1932 if (!dsc_max_bpc) 1933 return dsc_max_bpc; 1934 1935 dsc_max_bpc = min(dsc_max_bpc, max_req_bpc); 1936 1937 return align_max_sink_dsc_input_bpp(connector, dsc_max_bpc * 3); 1938 } 1939 1940 static int intel_dp_source_dsc_version_minor(struct intel_display *display) 1941 { 1942 return DISPLAY_VER(display) >= 14 ? 2 : 1; 1943 } 1944 1945 static int intel_dp_sink_dsc_version_minor(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]) 1946 { 1947 return (dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] & DP_DSC_MINOR_MASK) >> 1948 DP_DSC_MINOR_SHIFT; 1949 } 1950 1951 static int intel_dp_get_slice_height(int vactive) 1952 { 1953 int slice_height; 1954 1955 /* 1956 * VDSC 1.2a spec in Section 3.8 Options for Slices implies that 108 1957 * lines is an optimal slice height, but any size can be used as long as 1958 * vertical active integer multiple and maximum vertical slice count 1959 * requirements are met. 1960 */ 1961 for (slice_height = 108; slice_height <= vactive; slice_height += 2) 1962 if (vactive % slice_height == 0) 1963 return slice_height; 1964 1965 /* 1966 * Highly unlikely we reach here as most of the resolutions will end up 1967 * finding appropriate slice_height in above loop but returning 1968 * slice_height as 2 here as it should work with all resolutions. 1969 */ 1970 return 2; 1971 } 1972 1973 static int intel_dp_dsc_compute_params(const struct intel_connector *connector, 1974 struct intel_crtc_state *crtc_state) 1975 { 1976 struct intel_display *display = to_intel_display(connector); 1977 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 1978 int ret; 1979 1980 /* 1981 * RC_MODEL_SIZE is currently a constant across all configurations. 1982 * 1983 * FIXME: Look into using sink defined DPCD DP_DSC_RC_BUF_BLK_SIZE and 1984 * DP_DSC_RC_BUF_SIZE for this. 1985 */ 1986 vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST; 1987 vdsc_cfg->pic_height = crtc_state->hw.adjusted_mode.crtc_vdisplay; 1988 1989 vdsc_cfg->slice_height = intel_dp_get_slice_height(vdsc_cfg->pic_height); 1990 1991 ret = intel_dsc_compute_params(crtc_state); 1992 if (ret) 1993 return ret; 1994 1995 vdsc_cfg->dsc_version_major = 1996 (connector->dp.dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] & 1997 DP_DSC_MAJOR_MASK) >> DP_DSC_MAJOR_SHIFT; 1998 vdsc_cfg->dsc_version_minor = 1999 min(intel_dp_source_dsc_version_minor(display), 2000 intel_dp_sink_dsc_version_minor(connector->dp.dsc_dpcd)); 2001 if (vdsc_cfg->convert_rgb) 2002 vdsc_cfg->convert_rgb = 2003 connector->dp.dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & 2004 DP_DSC_RGB; 2005 2006 vdsc_cfg->line_buf_depth = min(INTEL_DP_DSC_MAX_LINE_BUF_DEPTH, 2007 drm_dp_dsc_sink_line_buf_depth(connector->dp.dsc_dpcd)); 2008 if (!vdsc_cfg->line_buf_depth) { 2009 drm_dbg_kms(display->drm, 2010 "DSC Sink Line Buffer Depth invalid\n"); 2011 return -EINVAL; 2012 } 2013 2014 vdsc_cfg->block_pred_enable = 2015 connector->dp.dsc_dpcd[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] & 2016 DP_DSC_BLK_PREDICTION_IS_SUPPORTED; 2017 2018 return drm_dsc_compute_rc_parameters(vdsc_cfg); 2019 } 2020 2021 static bool intel_dp_dsc_supports_format(const struct intel_connector *connector, 2022 enum intel_output_format output_format) 2023 { 2024 struct intel_display *display = to_intel_display(connector); 2025 u8 sink_dsc_format; 2026 2027 switch (output_format) { 2028 case INTEL_OUTPUT_FORMAT_RGB: 2029 sink_dsc_format = DP_DSC_RGB; 2030 break; 2031 case INTEL_OUTPUT_FORMAT_YCBCR444: 2032 sink_dsc_format = DP_DSC_YCbCr444; 2033 break; 2034 case INTEL_OUTPUT_FORMAT_YCBCR420: 2035 if (min(intel_dp_source_dsc_version_minor(display), 2036 intel_dp_sink_dsc_version_minor(connector->dp.dsc_dpcd)) < 2) 2037 return false; 2038 sink_dsc_format = DP_DSC_YCbCr420_Native; 2039 break; 2040 default: 2041 return false; 2042 } 2043 2044 return drm_dp_dsc_sink_supports_format(connector->dp.dsc_dpcd, sink_dsc_format); 2045 } 2046 2047 static bool is_bw_sufficient_for_dsc_config(struct intel_dp *intel_dp, 2048 int link_clock, int lane_count, 2049 int mode_clock, int mode_hdisplay, 2050 int dsc_slice_count, int link_bpp_x16, 2051 unsigned long bw_overhead_flags) 2052 { 2053 int available_bw; 2054 int required_bw; 2055 2056 available_bw = intel_dp_max_link_data_rate(intel_dp, link_clock, lane_count); 2057 required_bw = intel_dp_link_required(link_clock, lane_count, 2058 mode_clock, mode_hdisplay, 2059 link_bpp_x16, bw_overhead_flags); 2060 2061 return available_bw >= required_bw; 2062 } 2063 2064 static int dsc_compute_link_config(struct intel_dp *intel_dp, 2065 struct intel_crtc_state *pipe_config, 2066 struct drm_connector_state *conn_state, 2067 const struct link_config_limits *limits, 2068 int dsc_bpp_x16) 2069 { 2070 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 2071 int link_rate, lane_count; 2072 int i; 2073 2074 for (i = 0; i < intel_dp->num_common_rates; i++) { 2075 link_rate = intel_dp_common_rate(intel_dp, i); 2076 if (link_rate < limits->min_rate || link_rate > limits->max_rate) 2077 continue; 2078 2079 for (lane_count = limits->min_lane_count; 2080 lane_count <= limits->max_lane_count; 2081 lane_count <<= 1) { 2082 2083 /* 2084 * FIXME: intel_dp_mtp_tu_compute_config() requires 2085 * ->lane_count and ->port_clock set before we know 2086 * they'll work. If we end up failing altogether, 2087 * they'll remain in crtc state. This shouldn't matter, 2088 * as we'd then bail out from compute config, but it's 2089 * just ugly. 2090 */ 2091 pipe_config->lane_count = lane_count; 2092 pipe_config->port_clock = link_rate; 2093 2094 if (drm_dp_is_uhbr_rate(link_rate)) { 2095 int ret; 2096 2097 ret = intel_dp_mtp_tu_compute_config(intel_dp, 2098 pipe_config, 2099 conn_state, 2100 dsc_bpp_x16, 2101 dsc_bpp_x16, 2102 0, true); 2103 if (ret) 2104 continue; 2105 } else { 2106 unsigned long bw_overhead_flags = 2107 pipe_config->fec_enable ? DRM_DP_BW_OVERHEAD_FEC : 0; 2108 int line_slice_count = 2109 intel_dsc_line_slice_count(&pipe_config->dsc.slice_config); 2110 2111 if (!is_bw_sufficient_for_dsc_config(intel_dp, 2112 link_rate, lane_count, 2113 adjusted_mode->crtc_clock, 2114 adjusted_mode->hdisplay, 2115 line_slice_count, 2116 dsc_bpp_x16, 2117 bw_overhead_flags)) 2118 continue; 2119 } 2120 2121 return 0; 2122 } 2123 } 2124 2125 return -EINVAL; 2126 } 2127 2128 static 2129 u16 intel_dp_dsc_max_sink_compressed_bppx16(const struct intel_connector *connector, 2130 enum intel_output_format output_format, 2131 int bpc) 2132 { 2133 u16 max_bppx16 = drm_edp_dsc_sink_output_bpp(connector->dp.dsc_dpcd); 2134 2135 if (max_bppx16) 2136 return max_bppx16; 2137 /* 2138 * If support not given in DPCD 67h, 68h use the Maximum Allowed bit rate 2139 * values as given in spec Table 2-157 DP v2.0 2140 */ 2141 switch (output_format) { 2142 case INTEL_OUTPUT_FORMAT_RGB: 2143 case INTEL_OUTPUT_FORMAT_YCBCR444: 2144 return (3 * bpc) << 4; 2145 case INTEL_OUTPUT_FORMAT_YCBCR420: 2146 return (3 * (bpc / 2)) << 4; 2147 default: 2148 MISSING_CASE(output_format); 2149 break; 2150 } 2151 2152 return 0; 2153 } 2154 2155 static int intel_dp_dsc_sink_min_compressed_bpp(enum intel_output_format output_format) 2156 { 2157 /* From Mandatory bit rate range Support Table 2-157 (DP v2.0) */ 2158 switch (output_format) { 2159 case INTEL_OUTPUT_FORMAT_RGB: 2160 case INTEL_OUTPUT_FORMAT_YCBCR444: 2161 return 8; 2162 case INTEL_OUTPUT_FORMAT_YCBCR420: 2163 return 6; 2164 default: 2165 MISSING_CASE(output_format); 2166 break; 2167 } 2168 2169 return 0; 2170 } 2171 2172 static int intel_dp_dsc_sink_max_compressed_bpp(const struct intel_connector *connector, 2173 enum intel_output_format output_format, 2174 int bpc) 2175 { 2176 return intel_dp_dsc_max_sink_compressed_bppx16(connector, 2177 output_format, bpc) >> 4; 2178 } 2179 2180 int intel_dp_dsc_min_src_compressed_bpp(void) 2181 { 2182 /* Min Compressed bpp supported by source is 8 */ 2183 return 8; 2184 } 2185 2186 static int dsc_src_max_compressed_bpp(struct intel_dp *intel_dp) 2187 { 2188 struct intel_display *display = to_intel_display(intel_dp); 2189 2190 /* 2191 * Forcing DSC and using the platform's max compressed bpp is seen to cause 2192 * underruns. Since DSC isn't needed in these cases, limit the 2193 * max compressed bpp to 18, which is a safe value across platforms with different 2194 * pipe bpps. 2195 */ 2196 if (intel_dp->force_dsc_en) 2197 return 18; 2198 2199 /* 2200 * Max Compressed bpp for Gen 13+ is 27bpp. 2201 * For earlier platform is 23bpp. (Bspec:49259). 2202 */ 2203 if (DISPLAY_VER(display) < 13) 2204 return 23; 2205 else 2206 return 27; 2207 } 2208 2209 /* 2210 * Note: for pre-13 display you still need to check the validity of each step. 2211 */ 2212 int intel_dp_dsc_bpp_step_x16(const struct intel_connector *connector) 2213 { 2214 struct intel_display *display = to_intel_display(connector); 2215 u8 incr = drm_dp_dsc_sink_bpp_incr(connector->dp.dsc_dpcd); 2216 2217 if (DISPLAY_VER(display) < 14 || !incr) 2218 return fxp_q4_from_int(1); 2219 2220 if (connector->mst.dp && 2221 !connector->link.force_bpp_x16 && !connector->mst.dp->force_dsc_fractional_bpp_en) 2222 return fxp_q4_from_int(1); 2223 2224 /* fxp q4 */ 2225 return fxp_q4_from_int(1) / incr; 2226 } 2227 2228 /* 2229 * Note: for bpp_x16 to be valid it must be also within the source/sink's 2230 * min..max bpp capability range. 2231 */ 2232 bool intel_dp_dsc_valid_compressed_bpp(struct intel_dp *intel_dp, int bpp_x16) 2233 { 2234 struct intel_display *display = to_intel_display(intel_dp); 2235 2236 if (DISPLAY_VER(display) >= 13) { 2237 if (intel_dp->force_dsc_fractional_bpp_en && !fxp_q4_to_frac(bpp_x16)) 2238 return false; 2239 2240 return true; 2241 } 2242 2243 if (fxp_q4_to_frac(bpp_x16)) 2244 return false; 2245 2246 return align_max_vesa_compressed_bpp_x16(bpp_x16) == bpp_x16; 2247 } 2248 2249 static int align_min_compressed_bpp_x16(const struct intel_connector *connector, int min_bpp_x16) 2250 { 2251 struct intel_display *display = to_intel_display(connector); 2252 2253 if (DISPLAY_VER(display) >= 13) { 2254 int bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2255 2256 drm_WARN_ON(display->drm, !is_power_of_2(bpp_step_x16)); 2257 2258 return round_up(min_bpp_x16, bpp_step_x16); 2259 } else { 2260 return align_min_vesa_compressed_bpp_x16(min_bpp_x16); 2261 } 2262 } 2263 2264 static int align_max_compressed_bpp_x16(const struct intel_connector *connector, 2265 enum intel_output_format output_format, 2266 int pipe_bpp, int max_bpp_x16) 2267 { 2268 struct intel_display *display = to_intel_display(connector); 2269 int link_bpp_x16 = intel_dp_output_format_link_bpp_x16(output_format, pipe_bpp); 2270 int bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2271 2272 max_bpp_x16 = min(max_bpp_x16, link_bpp_x16 - bpp_step_x16); 2273 2274 if (DISPLAY_VER(display) >= 13) { 2275 drm_WARN_ON(display->drm, !is_power_of_2(bpp_step_x16)); 2276 2277 return round_down(max_bpp_x16, bpp_step_x16); 2278 } else { 2279 return align_max_vesa_compressed_bpp_x16(max_bpp_x16); 2280 } 2281 } 2282 2283 /* 2284 * Find the max compressed BPP we can find a link configuration for. The BPPs to 2285 * try depend on the source (platform) and sink. 2286 */ 2287 static int dsc_compute_compressed_bpp(struct intel_dp *intel_dp, 2288 struct intel_crtc_state *pipe_config, 2289 struct drm_connector_state *conn_state, 2290 const struct link_config_limits *limits, 2291 int pipe_bpp) 2292 { 2293 struct intel_display *display = to_intel_display(intel_dp); 2294 const struct intel_connector *connector = to_intel_connector(conn_state->connector); 2295 int min_bpp_x16, max_bpp_x16, bpp_step_x16; 2296 int bpp_x16; 2297 int ret; 2298 2299 min_bpp_x16 = limits->link.min_bpp_x16; 2300 max_bpp_x16 = limits->link.max_bpp_x16; 2301 bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2302 2303 max_bpp_x16 = align_max_compressed_bpp_x16(connector, pipe_config->output_format, 2304 pipe_bpp, max_bpp_x16); 2305 if (intel_dp_is_edp(intel_dp)) { 2306 pipe_config->port_clock = limits->max_rate; 2307 pipe_config->lane_count = limits->max_lane_count; 2308 2309 pipe_config->dsc.compressed_bpp_x16 = max_bpp_x16; 2310 2311 return 0; 2312 } 2313 2314 for (bpp_x16 = max_bpp_x16; bpp_x16 >= min_bpp_x16; bpp_x16 -= bpp_step_x16) { 2315 if (!intel_dp_dsc_valid_compressed_bpp(intel_dp, bpp_x16)) 2316 continue; 2317 2318 ret = dsc_compute_link_config(intel_dp, 2319 pipe_config, 2320 conn_state, 2321 limits, 2322 bpp_x16); 2323 if (ret == 0) { 2324 pipe_config->dsc.compressed_bpp_x16 = bpp_x16; 2325 if (intel_dp->force_dsc_fractional_bpp_en && 2326 fxp_q4_to_frac(bpp_x16)) 2327 drm_dbg_kms(display->drm, 2328 "Forcing DSC fractional bpp\n"); 2329 2330 return 0; 2331 } 2332 } 2333 2334 return -EINVAL; 2335 } 2336 2337 int intel_dp_dsc_min_src_input_bpc(void) 2338 { 2339 /* Min DSC Input BPC for ICL+ is 8 */ 2340 return 8; 2341 } 2342 2343 static 2344 bool is_dsc_pipe_bpp_sufficient(const struct link_config_limits *limits, 2345 int pipe_bpp) 2346 { 2347 return pipe_bpp >= limits->pipe.min_bpp && 2348 pipe_bpp <= limits->pipe.max_bpp; 2349 } 2350 2351 static 2352 int intel_dp_force_dsc_pipe_bpp(struct intel_dp *intel_dp, 2353 const struct link_config_limits *limits) 2354 { 2355 struct intel_display *display = to_intel_display(intel_dp); 2356 int forced_bpp; 2357 2358 if (!intel_dp->force_dsc_bpc) 2359 return 0; 2360 2361 forced_bpp = intel_dp->force_dsc_bpc * 3; 2362 2363 if (is_dsc_pipe_bpp_sufficient(limits, forced_bpp)) { 2364 drm_dbg_kms(display->drm, "Input DSC BPC forced to %d\n", 2365 intel_dp->force_dsc_bpc); 2366 return forced_bpp; 2367 } 2368 2369 drm_dbg_kms(display->drm, 2370 "Cannot force DSC BPC:%d, due to DSC BPC limits\n", 2371 intel_dp->force_dsc_bpc); 2372 2373 return 0; 2374 } 2375 2376 static int intel_dp_dsc_compute_pipe_bpp(struct intel_dp *intel_dp, 2377 struct intel_crtc_state *pipe_config, 2378 struct drm_connector_state *conn_state, 2379 const struct link_config_limits *limits) 2380 { 2381 int forced_bpp, pipe_bpp; 2382 int ret; 2383 2384 forced_bpp = intel_dp_force_dsc_pipe_bpp(intel_dp, limits); 2385 if (forced_bpp) 2386 pipe_bpp = forced_bpp; 2387 else 2388 pipe_bpp = limits->pipe.max_bpp; 2389 2390 ret = dsc_compute_compressed_bpp(intel_dp, pipe_config, conn_state, 2391 limits, pipe_bpp); 2392 if (ret) 2393 return -EINVAL; 2394 2395 pipe_config->pipe_bpp = pipe_bpp; 2396 2397 return 0; 2398 } 2399 2400 /* 2401 * Return whether FEC must be enabled for 8b10b SST or MST links. On 128b132b 2402 * links FEC is always enabled implicitly by the HW, so this function returns 2403 * false for that case. 2404 */ 2405 bool intel_dp_needs_8b10b_fec(const struct intel_crtc_state *crtc_state, 2406 bool dsc_enabled_on_crtc) 2407 { 2408 if (intel_dp_is_uhbr(crtc_state)) 2409 return false; 2410 2411 /* 2412 * Though eDP v1.5 supports FEC with DSC, unlike DP, it is optional. 2413 * Since, FEC is a bandwidth overhead, continue to not enable it for 2414 * eDP. Until, there is a good reason to do so. 2415 */ 2416 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) 2417 return false; 2418 2419 return dsc_enabled_on_crtc || intel_dsc_enabled_on_link(crtc_state); 2420 } 2421 2422 void intel_dp_dsc_reset_config(struct intel_crtc_state *crtc_state) 2423 { 2424 crtc_state->fec_enable = false; 2425 2426 crtc_state->dsc.compression_enable = false; 2427 crtc_state->dsc.compressed_bpp_x16 = 0; 2428 2429 memset(&crtc_state->dsc.slice_config, 0, sizeof(crtc_state->dsc.slice_config)); 2430 memset(&crtc_state->dsc.config, 0, sizeof(crtc_state->dsc.config)); 2431 } 2432 2433 int intel_dp_dsc_compute_config(struct intel_dp *intel_dp, 2434 struct intel_crtc_state *pipe_config, 2435 struct drm_connector_state *conn_state, 2436 const struct link_config_limits *limits, 2437 int timeslots) 2438 { 2439 struct intel_display *display = to_intel_display(intel_dp); 2440 const struct intel_connector *connector = 2441 to_intel_connector(conn_state->connector); 2442 const struct drm_display_mode *adjusted_mode = 2443 &pipe_config->hw.adjusted_mode; 2444 int num_joined_pipes = intel_crtc_num_joined_pipes(pipe_config); 2445 bool is_mst = intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST); 2446 int ret; 2447 2448 /* 2449 * FIXME: set the FEC enabled state once pipe_config->port_clock is 2450 * already known, so the UHBR/non-UHBR mode can be determined. 2451 */ 2452 pipe_config->fec_enable = intel_dp_needs_8b10b_fec(pipe_config, true); 2453 2454 if (!intel_dp_dsc_supports_format(connector, pipe_config->output_format)) 2455 return -EINVAL; 2456 2457 /* 2458 * Link parameters, pipe bpp and compressed bpp have already been 2459 * figured out for DP MST DSC. 2460 */ 2461 if (!is_mst) { 2462 ret = intel_dp_dsc_compute_pipe_bpp(intel_dp, pipe_config, 2463 conn_state, limits); 2464 if (ret) { 2465 drm_dbg_kms(display->drm, 2466 "No Valid pipe bpp for given mode ret = %d\n", ret); 2467 return ret; 2468 } 2469 } 2470 2471 if (!intel_dp_dsc_get_slice_config(connector, adjusted_mode->crtc_clock, 2472 adjusted_mode->crtc_hdisplay, num_joined_pipes, 2473 &pipe_config->dsc.slice_config)) 2474 return -EINVAL; 2475 2476 ret = intel_dp_dsc_compute_params(connector, pipe_config); 2477 if (ret < 0) { 2478 drm_dbg_kms(display->drm, 2479 "Cannot compute valid DSC parameters for Input Bpp = %d" 2480 "Compressed BPP = " FXP_Q4_FMT "\n", 2481 pipe_config->pipe_bpp, 2482 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16)); 2483 return ret; 2484 } 2485 2486 intel_dsc_enable_on_crtc(pipe_config); 2487 2488 drm_dbg_kms(display->drm, "DP DSC computed with Input Bpp = %d " 2489 "Compressed Bpp = " FXP_Q4_FMT " Slice Count = %d\n", 2490 pipe_config->pipe_bpp, 2491 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16), 2492 intel_dsc_line_slice_count(&pipe_config->dsc.slice_config)); 2493 2494 return 0; 2495 } 2496 2497 static int 2498 dsc_throughput_quirk_max_bpp_x16(const struct intel_connector *connector, 2499 int mode_clock) 2500 { 2501 if (!connector->dp.dsc_throughput_quirk) 2502 return INT_MAX; 2503 2504 /* 2505 * Synaptics Panamera branch devices have a problem decompressing a 2506 * stream with a compressed link-bpp higher than 12, if the pixel 2507 * clock is higher than ~50 % of the maximum overall throughput 2508 * reported by the branch device. Work around this by limiting the 2509 * maximum link bpp for such pixel clocks. 2510 * 2511 * TODO: Use the throughput value specific to the actual RGB/YUV 2512 * format of the output, after determining the pixel clock limit for 2513 * YUV modes. For now use the smaller of the throughput values, which 2514 * may result in limiting the link-bpp value already at a lower than 2515 * required mode clock in case of native YUV422/420 output formats. 2516 * The RGB/YUV444 throughput value should be always either equal or 2517 * smaller than the YUV422/420 value, but let's not depend on this 2518 * assumption. 2519 */ 2520 if (mode_clock < 2521 min(connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444, 2522 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420) / 2) 2523 return INT_MAX; 2524 2525 return fxp_q4_from_int(12); 2526 } 2527 2528 int intel_dp_compute_min_compressed_bpp_x16(struct intel_connector *connector, 2529 enum intel_output_format output_format) 2530 { 2531 int dsc_src_min_bpp, dsc_sink_min_bpp, dsc_min_bpp; 2532 int min_bpp_x16; 2533 2534 dsc_src_min_bpp = intel_dp_dsc_min_src_compressed_bpp(); 2535 dsc_sink_min_bpp = intel_dp_dsc_sink_min_compressed_bpp(output_format); 2536 dsc_min_bpp = max(dsc_src_min_bpp, dsc_sink_min_bpp); 2537 2538 min_bpp_x16 = fxp_q4_from_int(dsc_min_bpp); 2539 2540 min_bpp_x16 = align_min_compressed_bpp_x16(connector, min_bpp_x16); 2541 2542 return min_bpp_x16; 2543 } 2544 2545 static int compute_max_compressed_bpp_x16(struct intel_connector *connector, 2546 int mode_clock, int mode_hdisplay, 2547 int num_joined_pipes, 2548 enum intel_output_format output_format, 2549 int pipe_max_bpp, int max_link_bpp_x16) 2550 { 2551 struct intel_display *display = to_intel_display(connector); 2552 struct intel_dp *intel_dp = intel_attached_dp(connector); 2553 int dsc_src_max_bpp, dsc_sink_max_bpp, dsc_max_bpp; 2554 int throughput_max_bpp_x16; 2555 int joiner_max_bpp; 2556 2557 dsc_src_max_bpp = dsc_src_max_compressed_bpp(intel_dp); 2558 joiner_max_bpp = get_max_compressed_bpp_with_joiner(display, 2559 mode_clock, 2560 mode_hdisplay, 2561 num_joined_pipes); 2562 dsc_sink_max_bpp = intel_dp_dsc_sink_max_compressed_bpp(connector, 2563 output_format, 2564 pipe_max_bpp / 3); 2565 dsc_max_bpp = min(dsc_sink_max_bpp, dsc_src_max_bpp); 2566 dsc_max_bpp = min(dsc_max_bpp, joiner_max_bpp); 2567 2568 max_link_bpp_x16 = min(max_link_bpp_x16, fxp_q4_from_int(dsc_max_bpp)); 2569 2570 throughput_max_bpp_x16 = dsc_throughput_quirk_max_bpp_x16(connector, 2571 mode_clock); 2572 if (throughput_max_bpp_x16 < max_link_bpp_x16) { 2573 max_link_bpp_x16 = throughput_max_bpp_x16; 2574 2575 drm_dbg_kms(display->drm, 2576 "[CONNECTOR:%d:%s] Decreasing link max bpp to " FXP_Q4_FMT " due to DSC throughput quirk\n", 2577 connector->base.base.id, connector->base.name, 2578 FXP_Q4_ARGS(max_link_bpp_x16)); 2579 } 2580 2581 max_link_bpp_x16 = align_max_compressed_bpp_x16(connector, output_format, 2582 pipe_max_bpp, max_link_bpp_x16); 2583 2584 return max_link_bpp_x16; 2585 } 2586 2587 bool intel_dp_mode_valid_with_dsc(struct intel_connector *connector, 2588 int link_clock, int lane_count, 2589 int mode_clock, int mode_hdisplay, 2590 int num_joined_pipes, 2591 enum intel_output_format output_format, 2592 int pipe_bpp, unsigned long bw_overhead_flags) 2593 { 2594 struct intel_dp *intel_dp = intel_attached_dp(connector); 2595 int min_bpp_x16 = intel_dp_compute_min_compressed_bpp_x16(connector, 2596 output_format); 2597 int max_bpp_x16 = compute_max_compressed_bpp_x16(connector, 2598 mode_clock, mode_hdisplay, 2599 num_joined_pipes, 2600 output_format, 2601 pipe_bpp, INT_MAX); 2602 int dsc_slice_count = intel_dp_dsc_get_slice_count(connector, 2603 mode_clock, 2604 mode_hdisplay, 2605 num_joined_pipes); 2606 2607 if (min_bpp_x16 <= 0 || min_bpp_x16 > max_bpp_x16) 2608 return false; 2609 2610 if (dsc_slice_count == 0) 2611 return false; 2612 2613 return is_bw_sufficient_for_dsc_config(intel_dp, 2614 link_clock, lane_count, 2615 mode_clock, mode_hdisplay, 2616 dsc_slice_count, min_bpp_x16, 2617 bw_overhead_flags); 2618 } 2619 2620 /* 2621 * Calculate the output link min, max bpp values in limits based on the pipe bpp 2622 * range, crtc_state and dsc mode. Return true on success. 2623 */ 2624 static bool 2625 intel_dp_compute_config_link_bpp_limits(struct intel_connector *connector, 2626 const struct intel_crtc_state *crtc_state, 2627 bool dsc, 2628 struct link_config_limits *limits) 2629 { 2630 struct intel_display *display = to_intel_display(connector); 2631 struct intel_dp *intel_dp = intel_attached_dp(connector); 2632 const struct drm_display_mode *adjusted_mode = 2633 &crtc_state->hw.adjusted_mode; 2634 const struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2635 const struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2636 int max_link_bpp_x16; 2637 2638 max_link_bpp_x16 = min(crtc_state->max_link_bpp_x16, 2639 fxp_q4_from_int(limits->pipe.max_bpp)); 2640 2641 if (!dsc) { 2642 max_link_bpp_x16 = rounddown(max_link_bpp_x16, fxp_q4_from_int(2 * 3)); 2643 2644 if (max_link_bpp_x16 < fxp_q4_from_int(limits->pipe.min_bpp)) 2645 return false; 2646 2647 limits->link.min_bpp_x16 = fxp_q4_from_int(limits->pipe.min_bpp); 2648 } else { 2649 limits->link.min_bpp_x16 = 2650 intel_dp_compute_min_compressed_bpp_x16(connector, 2651 crtc_state->output_format); 2652 2653 max_link_bpp_x16 = 2654 compute_max_compressed_bpp_x16(connector, 2655 adjusted_mode->crtc_clock, 2656 adjusted_mode->hdisplay, 2657 intel_crtc_num_joined_pipes(crtc_state), 2658 crtc_state->output_format, 2659 limits->pipe.max_bpp, 2660 max_link_bpp_x16); 2661 } 2662 2663 limits->link.max_bpp_x16 = max_link_bpp_x16; 2664 2665 drm_dbg_kms(display->drm, 2666 "[ENCODER:%d:%s][CRTC:%d:%s] DP link limits: pixel clock %d kHz DSC %s max lanes %d max rate %d max pipe_bpp %d min link_bpp " FXP_Q4_FMT " max link_bpp " FXP_Q4_FMT "\n", 2667 encoder->base.base.id, encoder->base.name, 2668 crtc->base.base.id, crtc->base.name, 2669 adjusted_mode->crtc_clock, 2670 str_on_off(dsc), 2671 limits->max_lane_count, 2672 limits->max_rate, 2673 limits->pipe.max_bpp, 2674 FXP_Q4_ARGS(limits->link.min_bpp_x16), 2675 FXP_Q4_ARGS(limits->link.max_bpp_x16)); 2676 2677 if (limits->link.min_bpp_x16 <= 0 || 2678 limits->link.min_bpp_x16 > limits->link.max_bpp_x16) 2679 return false; 2680 2681 return true; 2682 } 2683 2684 static bool 2685 intel_dp_dsc_compute_pipe_bpp_limits(struct intel_connector *connector, 2686 struct link_config_limits *limits) 2687 { 2688 struct intel_display *display = to_intel_display(connector); 2689 const struct link_config_limits orig_limits = *limits; 2690 int dsc_min_bpc = intel_dp_dsc_min_src_input_bpc(); 2691 int dsc_max_bpc = intel_dp_dsc_max_src_input_bpc(display); 2692 2693 limits->pipe.min_bpp = max(limits->pipe.min_bpp, dsc_min_bpc * 3); 2694 limits->pipe.min_bpp = align_min_sink_dsc_input_bpp(connector, limits->pipe.min_bpp); 2695 2696 limits->pipe.max_bpp = min(limits->pipe.max_bpp, dsc_max_bpc * 3); 2697 limits->pipe.max_bpp = align_max_sink_dsc_input_bpp(connector, limits->pipe.max_bpp); 2698 2699 if (limits->pipe.min_bpp <= 0 || 2700 limits->pipe.min_bpp > limits->pipe.max_bpp) { 2701 drm_dbg_kms(display->drm, 2702 "[CONNECTOR:%d:%s] Invalid DSC src/sink input BPP (src:%d-%d pipe:%d-%d sink-align:%d-%d)\n", 2703 connector->base.base.id, connector->base.name, 2704 dsc_min_bpc * 3, dsc_max_bpc * 3, 2705 orig_limits.pipe.min_bpp, orig_limits.pipe.max_bpp, 2706 limits->pipe.min_bpp, limits->pipe.max_bpp); 2707 2708 return false; 2709 } 2710 2711 return true; 2712 } 2713 2714 bool 2715 intel_dp_compute_config_limits(struct intel_dp *intel_dp, 2716 struct drm_connector_state *conn_state, 2717 struct intel_crtc_state *crtc_state, 2718 bool respect_downstream_limits, 2719 bool dsc, 2720 struct link_config_limits *limits) 2721 { 2722 struct intel_display *display = to_intel_display(intel_dp); 2723 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 2724 struct intel_connector *connector = 2725 to_intel_connector(conn_state->connector); 2726 2727 limits->min_rate = intel_dp_min_link_rate(intel_dp); 2728 limits->max_rate = intel_dp_max_link_rate(intel_dp); 2729 2730 limits->min_rate = min(limits->min_rate, limits->max_rate); 2731 2732 limits->min_lane_count = intel_dp_min_lane_count(intel_dp); 2733 limits->max_lane_count = intel_dp_max_lane_count(intel_dp); 2734 2735 limits->pipe.min_bpp = intel_dp_min_bpp(crtc_state->output_format); 2736 if (is_mst) { 2737 /* 2738 * FIXME: If all the streams can't fit into the link with their 2739 * current pipe_bpp we should reduce pipe_bpp across the board 2740 * until things start to fit. Until then we limit to <= 8bpc 2741 * since that's what was hardcoded for all MST streams 2742 * previously. This hack should be removed once we have the 2743 * proper retry logic in place. 2744 */ 2745 limits->pipe.max_bpp = min(crtc_state->max_pipe_bpp, 24); 2746 } else { 2747 limits->pipe.max_bpp = intel_dp_max_bpp(intel_dp, crtc_state, 2748 respect_downstream_limits); 2749 } 2750 2751 if (!dsc && intel_dp_in_hdr_mode(conn_state)) { 2752 if (intel_dp_supports_dsc(intel_dp, connector, crtc_state) && 2753 limits->pipe.max_bpp >= 30) 2754 limits->pipe.min_bpp = max(limits->pipe.min_bpp, 30); 2755 else 2756 drm_dbg_kms(display->drm, 2757 "[CONNECTOR:%d:%s] Can't force 30 bpp for HDR (pipe bpp: %d-%d DSC-support: %s)\n", 2758 connector->base.base.id, connector->base.name, 2759 limits->pipe.min_bpp, limits->pipe.max_bpp, 2760 str_yes_no(intel_dp_supports_dsc(intel_dp, connector, 2761 crtc_state))); 2762 } 2763 2764 if (limits->pipe.min_bpp <= 0 || 2765 limits->pipe.min_bpp > limits->pipe.max_bpp) { 2766 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s] Invalid pipe bpp range: %d-%d\n", 2767 connector->base.base.id, connector->base.name, 2768 limits->pipe.min_bpp, limits->pipe.max_bpp); 2769 2770 return false; 2771 } 2772 2773 if (dsc && !intel_dp_dsc_compute_pipe_bpp_limits(connector, limits)) 2774 return false; 2775 2776 /* 2777 * crtc_state->pipe_bpp is the non-DP specific baseline (platform / 2778 * EDID) maximum pipe BPP limited by the max-BPC connector property 2779 * request. Since by now pipe.max_bpp is <= the above baseline 2780 * maximum BPP, the only remaining reason for adjusting pipe.max_bpp 2781 * is the max-BPC connector property request. Adjust pipe.max_bpp to 2782 * this request within the current valid pipe.min_bpp .. pipe.max_bpp 2783 * range. 2784 */ 2785 limits->pipe.max_bpp = clamp(crtc_state->pipe_bpp, limits->pipe.min_bpp, 2786 limits->pipe.max_bpp); 2787 if (dsc) 2788 limits->pipe.max_bpp = align_max_sink_dsc_input_bpp(connector, 2789 limits->pipe.max_bpp); 2790 2791 if (limits->pipe.max_bpp != crtc_state->pipe_bpp) 2792 drm_dbg_kms(display->drm, 2793 "[CONNECTOR:%d:%s] Adjusting requested max pipe bpp %d -> %d\n", 2794 connector->base.base.id, connector->base.name, 2795 crtc_state->pipe_bpp, limits->pipe.max_bpp); 2796 2797 if (is_mst || intel_dp->use_max_params) { 2798 /* 2799 * For MST we always configure max link bw - the spec doesn't 2800 * seem to suggest we should do otherwise. 2801 * 2802 * Use the maximum clock and number of lanes the eDP panel 2803 * advertizes being capable of in case the initial fast 2804 * optimal params failed us. The panels are generally 2805 * designed to support only a single clock and lane 2806 * configuration, and typically on older panels these 2807 * values correspond to the native resolution of the panel. 2808 */ 2809 limits->min_lane_count = limits->max_lane_count; 2810 limits->min_rate = limits->max_rate; 2811 } 2812 2813 intel_dp_test_compute_config(intel_dp, crtc_state, limits); 2814 2815 return intel_dp_compute_config_link_bpp_limits(connector, 2816 crtc_state, 2817 dsc, 2818 limits); 2819 } 2820 2821 int intel_dp_config_required_rate(const struct intel_crtc_state *crtc_state) 2822 { 2823 const struct drm_display_mode *adjusted_mode = 2824 &crtc_state->hw.adjusted_mode; 2825 int link_bpp_x16 = crtc_state->dsc.compression_enable ? 2826 crtc_state->dsc.compressed_bpp_x16 : 2827 fxp_q4_from_int(crtc_state->pipe_bpp); 2828 2829 return intel_dp_link_required(crtc_state->port_clock, crtc_state->lane_count, 2830 adjusted_mode->crtc_clock, adjusted_mode->hdisplay, 2831 link_bpp_x16, 0); 2832 } 2833 2834 bool intel_dp_joiner_needs_dsc(struct intel_display *display, 2835 int num_joined_pipes) 2836 { 2837 /* 2838 * Pipe joiner needs compression up to display 12 due to bandwidth 2839 * limitation. DG2 onwards pipe joiner can be enabled without 2840 * compression. 2841 * Ultrajoiner always needs compression. 2842 */ 2843 return (!HAS_UNCOMPRESSED_JOINER(display) && num_joined_pipes == 2) || 2844 num_joined_pipes == 4; 2845 } 2846 2847 static int 2848 intel_dp_compute_link_for_joined_pipes(struct intel_encoder *encoder, 2849 struct intel_crtc_state *pipe_config, 2850 struct drm_connector_state *conn_state, 2851 bool respect_downstream_limits) 2852 { 2853 struct intel_display *display = to_intel_display(encoder); 2854 int num_joined_pipes = intel_crtc_num_joined_pipes(pipe_config); 2855 struct intel_connector *connector = 2856 to_intel_connector(conn_state->connector); 2857 const struct drm_display_mode *adjusted_mode = 2858 &pipe_config->hw.adjusted_mode; 2859 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2860 struct link_config_limits limits; 2861 bool dsc_needed, joiner_needs_dsc; 2862 int ret = 0; 2863 2864 intel_dp_dsc_reset_config(pipe_config); 2865 2866 joiner_needs_dsc = intel_dp_joiner_needs_dsc(display, num_joined_pipes); 2867 2868 dsc_needed = joiner_needs_dsc || intel_dp->force_dsc_en || 2869 !intel_dp_compute_config_limits(intel_dp, conn_state, pipe_config, 2870 respect_downstream_limits, 2871 false, 2872 &limits); 2873 2874 if (!dsc_needed) { 2875 /* 2876 * Optimize for slow and wide for everything, because there are some 2877 * eDP 1.3 and 1.4 panels don't work well with fast and narrow. 2878 */ 2879 ret = intel_dp_compute_link_config_wide(intel_dp, pipe_config, 2880 conn_state, &limits); 2881 if (!ret && intel_dp_is_uhbr(pipe_config)) 2882 ret = intel_dp_mtp_tu_compute_config(intel_dp, 2883 pipe_config, 2884 conn_state, 2885 fxp_q4_from_int(pipe_config->pipe_bpp), 2886 fxp_q4_from_int(pipe_config->pipe_bpp), 2887 0, false); 2888 2889 if (ret || 2890 !intel_dp_dotclk_valid(display, 2891 adjusted_mode->crtc_clock, 2892 adjusted_mode->crtc_htotal, 2893 0, 2894 num_joined_pipes)) 2895 dsc_needed = true; 2896 } 2897 2898 if (dsc_needed && !intel_dp_supports_dsc(intel_dp, connector, pipe_config)) { 2899 drm_dbg_kms(display->drm, "DSC required but not available\n"); 2900 return -EINVAL; 2901 } 2902 2903 if (dsc_needed) { 2904 int dsc_slice_count; 2905 2906 drm_dbg_kms(display->drm, 2907 "Try DSC (fallback=%s, joiner=%s, force=%s)\n", 2908 str_yes_no(ret), str_yes_no(joiner_needs_dsc), 2909 str_yes_no(intel_dp->force_dsc_en)); 2910 2911 if (!intel_dp_compute_config_limits(intel_dp, conn_state, pipe_config, 2912 respect_downstream_limits, 2913 true, 2914 &limits)) 2915 return -EINVAL; 2916 2917 ret = intel_dp_dsc_compute_config(intel_dp, pipe_config, 2918 conn_state, &limits, 64); 2919 if (ret < 0) 2920 return ret; 2921 2922 dsc_slice_count = intel_dsc_line_slice_count(&pipe_config->dsc.slice_config); 2923 2924 if (!intel_dp_dotclk_valid(display, 2925 adjusted_mode->crtc_clock, 2926 adjusted_mode->crtc_htotal, 2927 dsc_slice_count, 2928 num_joined_pipes)) 2929 return -EINVAL; 2930 } 2931 2932 drm_dbg_kms(display->drm, 2933 "DP lane count %d clock %d bpp input %d compressed " FXP_Q4_FMT " HDR %s link rate required %d available %d\n", 2934 pipe_config->lane_count, pipe_config->port_clock, 2935 pipe_config->pipe_bpp, 2936 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16), 2937 str_yes_no(intel_dp_in_hdr_mode(conn_state)), 2938 intel_dp_config_required_rate(pipe_config), 2939 intel_dp_max_link_data_rate(intel_dp, 2940 pipe_config->port_clock, 2941 pipe_config->lane_count)); 2942 2943 return 0; 2944 } 2945 2946 static int 2947 intel_dp_compute_link_config(struct intel_encoder *encoder, 2948 struct intel_crtc_state *crtc_state, 2949 struct drm_connector_state *conn_state, 2950 bool respect_downstream_limits) 2951 { 2952 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2953 struct intel_connector *connector = 2954 to_intel_connector(conn_state->connector); 2955 const struct drm_display_mode *adjusted_mode = 2956 &crtc_state->hw.adjusted_mode; 2957 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2958 int num_joined_pipes; 2959 int ret = -EINVAL; 2960 2961 if (crtc_state->fec_enable && 2962 !intel_dp_supports_fec(intel_dp, connector, crtc_state)) 2963 return -EINVAL; 2964 2965 for_each_joiner_candidate(connector, adjusted_mode, num_joined_pipes) { 2966 /* 2967 * NOTE: 2968 * The crtc_state->joiner_pipes should have been set at the end 2969 * only if all the conditions are met. However that would mean 2970 * that num_joined_pipes is passed around to all helpers and 2971 * make them use it instead of using crtc_state->joiner_pipes 2972 * directly or indirectly (via intel_crtc_num_joined_pipes()). 2973 * 2974 * For now, setting crtc_state->joiner_pipes to the candidate 2975 * value to avoid the above churn and resetting it to 0, in case 2976 * no joiner candidate is found to be suitable for the given 2977 * configuration. 2978 */ 2979 if (num_joined_pipes > 1) 2980 crtc_state->joiner_pipes = GENMASK(crtc->pipe + num_joined_pipes - 1, 2981 crtc->pipe); 2982 2983 ret = intel_dp_compute_link_for_joined_pipes(encoder, crtc_state, conn_state, 2984 respect_downstream_limits); 2985 if (ret == 0 || ret == -EDEADLK) 2986 break; 2987 } 2988 2989 if (ret < 0) 2990 crtc_state->joiner_pipes = 0; 2991 2992 return ret; 2993 } 2994 2995 bool intel_dp_limited_color_range(const struct intel_crtc_state *crtc_state, 2996 const struct drm_connector_state *conn_state) 2997 { 2998 const struct intel_digital_connector_state *intel_conn_state = 2999 to_intel_digital_connector_state(conn_state); 3000 const struct drm_display_mode *adjusted_mode = 3001 &crtc_state->hw.adjusted_mode; 3002 3003 /* 3004 * Our YCbCr output is always limited range. 3005 * crtc_state->limited_color_range only applies to RGB, 3006 * and it must never be set for YCbCr or we risk setting 3007 * some conflicting bits in TRANSCONF which will mess up 3008 * the colors on the monitor. 3009 */ 3010 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 3011 return false; 3012 3013 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) { 3014 /* 3015 * See: 3016 * CEA-861-E - 5.1 Default Encoding Parameters 3017 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry 3018 */ 3019 return crtc_state->pipe_bpp != 18 && 3020 drm_default_rgb_quant_range(adjusted_mode) == 3021 HDMI_QUANTIZATION_RANGE_LIMITED; 3022 } else { 3023 return intel_conn_state->broadcast_rgb == 3024 INTEL_BROADCAST_RGB_LIMITED; 3025 } 3026 } 3027 3028 static bool intel_dp_port_has_audio(struct intel_display *display, enum port port) 3029 { 3030 if (display->platform.g4x) 3031 return false; 3032 if (DISPLAY_VER(display) < 12 && port == PORT_A) 3033 return false; 3034 3035 return true; 3036 } 3037 3038 static void intel_dp_compute_vsc_colorimetry(const struct intel_crtc_state *crtc_state, 3039 const struct drm_connector_state *conn_state, 3040 struct drm_dp_vsc_sdp *vsc) 3041 { 3042 struct intel_display *display = to_intel_display(crtc_state); 3043 3044 if (crtc_state->has_panel_replay) { 3045 /* 3046 * Prepare VSC Header for SU as per DP 2.0 spec, Table 2-223 3047 * VSC SDP supporting 3D stereo, Panel Replay, and Pixel 3048 * Encoding/Colorimetry Format indication. 3049 */ 3050 vsc->revision = 0x7; 3051 } else { 3052 /* 3053 * Prepare VSC Header for SU as per DP 1.4 spec, Table 2-118 3054 * VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/ 3055 * Colorimetry Format indication. 3056 */ 3057 vsc->revision = 0x5; 3058 } 3059 3060 vsc->length = 0x13; 3061 3062 /* DP 1.4a spec, Table 2-120 */ 3063 switch (crtc_state->output_format) { 3064 case INTEL_OUTPUT_FORMAT_YCBCR444: 3065 vsc->pixelformat = DP_PIXELFORMAT_YUV444; 3066 break; 3067 case INTEL_OUTPUT_FORMAT_YCBCR420: 3068 vsc->pixelformat = DP_PIXELFORMAT_YUV420; 3069 break; 3070 case INTEL_OUTPUT_FORMAT_RGB: 3071 default: 3072 vsc->pixelformat = DP_PIXELFORMAT_RGB; 3073 } 3074 3075 switch (conn_state->colorspace) { 3076 case DRM_MODE_COLORIMETRY_BT709_YCC: 3077 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC; 3078 break; 3079 case DRM_MODE_COLORIMETRY_XVYCC_601: 3080 vsc->colorimetry = DP_COLORIMETRY_XVYCC_601; 3081 break; 3082 case DRM_MODE_COLORIMETRY_XVYCC_709: 3083 vsc->colorimetry = DP_COLORIMETRY_XVYCC_709; 3084 break; 3085 case DRM_MODE_COLORIMETRY_SYCC_601: 3086 vsc->colorimetry = DP_COLORIMETRY_SYCC_601; 3087 break; 3088 case DRM_MODE_COLORIMETRY_OPYCC_601: 3089 vsc->colorimetry = DP_COLORIMETRY_OPYCC_601; 3090 break; 3091 case DRM_MODE_COLORIMETRY_BT2020_CYCC: 3092 vsc->colorimetry = DP_COLORIMETRY_BT2020_CYCC; 3093 break; 3094 case DRM_MODE_COLORIMETRY_BT2020_RGB: 3095 vsc->colorimetry = DP_COLORIMETRY_BT2020_RGB; 3096 break; 3097 case DRM_MODE_COLORIMETRY_BT2020_YCC: 3098 vsc->colorimetry = DP_COLORIMETRY_BT2020_YCC; 3099 break; 3100 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65: 3101 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER: 3102 vsc->colorimetry = DP_COLORIMETRY_DCI_P3_RGB; 3103 break; 3104 default: 3105 /* 3106 * RGB->YCBCR color conversion uses the BT.709 3107 * color space. 3108 */ 3109 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 3110 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC; 3111 else 3112 vsc->colorimetry = DP_COLORIMETRY_DEFAULT; 3113 break; 3114 } 3115 3116 vsc->bpc = crtc_state->pipe_bpp / 3; 3117 3118 /* only RGB pixelformat supports 6 bpc */ 3119 drm_WARN_ON(display->drm, 3120 vsc->bpc == 6 && vsc->pixelformat != DP_PIXELFORMAT_RGB); 3121 3122 /* All YCbCr formats are always limited range. */ 3123 if (vsc->pixelformat == DP_PIXELFORMAT_RGB) 3124 vsc->dynamic_range = crtc_state->limited_color_range ? 3125 DP_DYNAMIC_RANGE_CTA : DP_DYNAMIC_RANGE_VESA; 3126 else 3127 vsc->dynamic_range = DP_DYNAMIC_RANGE_CTA; 3128 3129 vsc->content_type = DP_CONTENT_TYPE_NOT_DEFINED; 3130 } 3131 3132 static void intel_dp_compute_as_sdp(struct intel_dp *intel_dp, 3133 struct intel_crtc_state *crtc_state) 3134 { 3135 struct drm_dp_as_sdp *as_sdp = &crtc_state->infoframes.as_sdp; 3136 const struct drm_display_mode *adjusted_mode = 3137 &crtc_state->hw.adjusted_mode; 3138 3139 if (!crtc_state->vrr.enable || !intel_dp->as_sdp_supported) 3140 return; 3141 3142 crtc_state->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC); 3143 3144 as_sdp->sdp_type = DP_SDP_ADAPTIVE_SYNC; 3145 as_sdp->length = 0x9; 3146 as_sdp->duration_incr_ms = 0; 3147 as_sdp->vtotal = intel_vrr_vmin_vtotal(crtc_state); 3148 3149 if (crtc_state->cmrr.enable) { 3150 as_sdp->mode = DP_AS_SDP_FAVT_TRR_REACHED; 3151 as_sdp->target_rr = drm_mode_vrefresh(adjusted_mode); 3152 as_sdp->target_rr_divider = true; 3153 } else { 3154 as_sdp->mode = DP_AS_SDP_AVT_DYNAMIC_VTOTAL; 3155 as_sdp->target_rr = 0; 3156 } 3157 } 3158 3159 static void intel_dp_compute_vsc_sdp(struct intel_dp *intel_dp, 3160 struct intel_crtc_state *crtc_state, 3161 const struct drm_connector_state *conn_state) 3162 { 3163 struct drm_dp_vsc_sdp *vsc; 3164 3165 if ((!intel_dp->colorimetry_support || 3166 !intel_dp_needs_vsc_sdp(crtc_state, conn_state)) && 3167 !crtc_state->has_psr) 3168 return; 3169 3170 vsc = &crtc_state->infoframes.vsc; 3171 3172 crtc_state->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_VSC); 3173 vsc->sdp_type = DP_SDP_VSC; 3174 3175 /* Needs colorimetry */ 3176 if (intel_dp_needs_vsc_sdp(crtc_state, conn_state)) { 3177 intel_dp_compute_vsc_colorimetry(crtc_state, conn_state, 3178 vsc); 3179 } else if (crtc_state->has_panel_replay) { 3180 /* 3181 * [Panel Replay without colorimetry info] 3182 * Prepare VSC Header for SU as per DP 2.0 spec, Table 2-223 3183 * VSC SDP supporting 3D stereo + Panel Replay. 3184 */ 3185 vsc->revision = 0x6; 3186 vsc->length = 0x10; 3187 } else if (crtc_state->has_sel_update) { 3188 /* 3189 * [PSR2 without colorimetry] 3190 * Prepare VSC Header for SU as per eDP 1.4 spec, Table 6-11 3191 * 3D stereo + PSR/PSR2 + Y-coordinate. 3192 */ 3193 vsc->revision = 0x4; 3194 vsc->length = 0xe; 3195 } else { 3196 /* 3197 * [PSR1] 3198 * Prepare VSC Header for SU as per DP 1.4 spec, Table 2-118 3199 * VSC SDP supporting 3D stereo + PSR (applies to eDP v1.3 or 3200 * higher). 3201 */ 3202 vsc->revision = 0x2; 3203 vsc->length = 0x8; 3204 } 3205 } 3206 3207 bool 3208 intel_dp_in_hdr_mode(const struct drm_connector_state *conn_state) 3209 { 3210 struct hdr_output_metadata *hdr_metadata; 3211 3212 if (!conn_state->hdr_output_metadata) 3213 return false; 3214 3215 hdr_metadata = conn_state->hdr_output_metadata->data; 3216 3217 return hdr_metadata->hdmi_metadata_type1.eotf == HDMI_EOTF_SMPTE_ST2084; 3218 } 3219 3220 static void 3221 intel_dp_compute_hdr_metadata_infoframe_sdp(struct intel_dp *intel_dp, 3222 struct intel_crtc_state *crtc_state, 3223 const struct drm_connector_state *conn_state) 3224 { 3225 struct intel_display *display = to_intel_display(intel_dp); 3226 int ret; 3227 struct hdmi_drm_infoframe *drm_infoframe = &crtc_state->infoframes.drm.drm; 3228 3229 if (!conn_state->hdr_output_metadata) 3230 return; 3231 3232 ret = drm_hdmi_infoframe_set_hdr_metadata(drm_infoframe, conn_state); 3233 3234 if (ret) { 3235 drm_dbg_kms(display->drm, 3236 "couldn't set HDR metadata in infoframe\n"); 3237 return; 3238 } 3239 3240 crtc_state->infoframes.enable |= 3241 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA); 3242 } 3243 3244 static bool can_enable_drrs(struct intel_connector *connector, 3245 const struct intel_crtc_state *pipe_config, 3246 const struct drm_display_mode *downclock_mode) 3247 { 3248 struct intel_display *display = to_intel_display(connector); 3249 3250 if (pipe_config->vrr.enable) 3251 return false; 3252 3253 /* 3254 * DRRS and PSR can't be enable together, so giving preference to PSR 3255 * as it allows more power-savings by complete shutting down display, 3256 * so to guarantee this, intel_drrs_compute_config() must be called 3257 * after intel_psr_compute_config(). 3258 */ 3259 if (pipe_config->has_psr) 3260 return false; 3261 3262 /* FIXME missing FDI M2/N2 etc. */ 3263 if (pipe_config->has_pch_encoder) 3264 return false; 3265 3266 if (!intel_cpu_transcoder_has_drrs(display, pipe_config->cpu_transcoder)) 3267 return false; 3268 3269 return downclock_mode && 3270 intel_panel_drrs_type(connector) == DRRS_TYPE_SEAMLESS; 3271 } 3272 3273 static void 3274 intel_dp_drrs_compute_config(struct intel_connector *connector, 3275 struct intel_crtc_state *pipe_config, 3276 int link_bpp_x16) 3277 { 3278 struct intel_display *display = to_intel_display(connector); 3279 const struct drm_display_mode *downclock_mode = 3280 intel_panel_downclock_mode(connector, &pipe_config->hw.adjusted_mode); 3281 int pixel_clock; 3282 3283 /* 3284 * FIXME all joined pipes share the same transcoder. 3285 * Need to account for that when updating M/N live. 3286 */ 3287 if (has_seamless_m_n(connector) && !pipe_config->joiner_pipes) 3288 pipe_config->update_m_n = true; 3289 3290 if (!can_enable_drrs(connector, pipe_config, downclock_mode)) { 3291 if (intel_cpu_transcoder_has_m2_n2(display, pipe_config->cpu_transcoder)) 3292 intel_zero_m_n(&pipe_config->dp_m2_n2); 3293 return; 3294 } 3295 3296 if (display->platform.ironlake || display->platform.sandybridge || 3297 display->platform.ivybridge) 3298 pipe_config->msa_timing_delay = connector->panel.vbt.edp.drrs_msa_timing_delay; 3299 3300 pipe_config->has_drrs = true; 3301 3302 pixel_clock = downclock_mode->clock; 3303 if (pipe_config->splitter.enable) 3304 pixel_clock /= pipe_config->splitter.link_count; 3305 3306 intel_link_compute_m_n(link_bpp_x16, pipe_config->lane_count, pixel_clock, 3307 pipe_config->port_clock, 3308 intel_dp_bw_fec_overhead(pipe_config->fec_enable), 3309 &pipe_config->dp_m2_n2); 3310 3311 /* FIXME: abstract this better */ 3312 if (pipe_config->splitter.enable) 3313 pipe_config->dp_m2_n2.data_m *= pipe_config->splitter.link_count; 3314 } 3315 3316 static bool intel_dp_has_audio(struct intel_encoder *encoder, 3317 const struct drm_connector_state *conn_state) 3318 { 3319 struct intel_display *display = to_intel_display(encoder); 3320 const struct intel_digital_connector_state *intel_conn_state = 3321 to_intel_digital_connector_state(conn_state); 3322 struct intel_connector *connector = 3323 to_intel_connector(conn_state->connector); 3324 3325 if (!intel_dp_port_has_audio(display, encoder->port)) 3326 return false; 3327 3328 if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO) 3329 return connector->base.display_info.has_audio; 3330 else 3331 return intel_conn_state->force_audio == HDMI_AUDIO_ON; 3332 } 3333 3334 static int 3335 intel_dp_compute_output_format(struct intel_encoder *encoder, 3336 struct intel_crtc_state *crtc_state, 3337 struct drm_connector_state *conn_state, 3338 bool respect_downstream_limits) 3339 { 3340 struct intel_display *display = to_intel_display(encoder); 3341 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3342 struct intel_connector *connector = intel_dp->attached_connector; 3343 const struct drm_display_info *info = &connector->base.display_info; 3344 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 3345 bool ycbcr_420_only; 3346 int ret; 3347 3348 ycbcr_420_only = drm_mode_is_420_only(info, adjusted_mode); 3349 3350 if (ycbcr_420_only && !connector->base.ycbcr_420_allowed) { 3351 drm_dbg_kms(display->drm, 3352 "YCbCr 4:2:0 mode but YCbCr 4:2:0 output not possible. Falling back to RGB.\n"); 3353 crtc_state->sink_format = INTEL_OUTPUT_FORMAT_RGB; 3354 } else { 3355 crtc_state->sink_format = intel_dp_sink_format(connector, adjusted_mode); 3356 } 3357 3358 crtc_state->output_format = intel_dp_output_format(connector, crtc_state->sink_format); 3359 3360 ret = intel_dp_compute_link_config(encoder, crtc_state, conn_state, 3361 respect_downstream_limits); 3362 if (ret) { 3363 if (crtc_state->sink_format == INTEL_OUTPUT_FORMAT_YCBCR420 || 3364 !connector->base.ycbcr_420_allowed || 3365 !drm_mode_is_420_also(info, adjusted_mode)) 3366 return ret; 3367 3368 crtc_state->sink_format = INTEL_OUTPUT_FORMAT_YCBCR420; 3369 crtc_state->output_format = intel_dp_output_format(connector, 3370 crtc_state->sink_format); 3371 ret = intel_dp_compute_link_config(encoder, crtc_state, conn_state, 3372 respect_downstream_limits); 3373 } 3374 3375 return ret; 3376 } 3377 3378 void 3379 intel_dp_audio_compute_config(struct intel_encoder *encoder, 3380 struct intel_crtc_state *pipe_config, 3381 struct drm_connector_state *conn_state) 3382 { 3383 pipe_config->has_audio = 3384 intel_dp_has_audio(encoder, conn_state) && 3385 intel_audio_compute_config(encoder, pipe_config, conn_state); 3386 3387 pipe_config->sdp_split_enable = pipe_config->has_audio && 3388 intel_dp_is_uhbr(pipe_config); 3389 } 3390 3391 void 3392 intel_dp_queue_modeset_retry_for_link(struct intel_atomic_state *state, 3393 struct intel_encoder *encoder, 3394 const struct intel_crtc_state *crtc_state) 3395 { 3396 struct intel_connector *connector; 3397 struct intel_digital_connector_state *conn_state; 3398 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3399 int i; 3400 3401 if (intel_dp->needs_modeset_retry) 3402 return; 3403 3404 intel_dp->needs_modeset_retry = true; 3405 3406 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 3407 intel_connector_queue_modeset_retry_work(intel_dp->attached_connector); 3408 3409 return; 3410 } 3411 3412 for_each_new_intel_connector_in_state(state, connector, conn_state, i) { 3413 if (!conn_state->base.crtc) 3414 continue; 3415 3416 if (connector->mst.dp == intel_dp) 3417 intel_connector_queue_modeset_retry_work(connector); 3418 } 3419 } 3420 3421 int intel_dp_compute_min_hblank(struct intel_crtc_state *crtc_state, 3422 const struct drm_connector_state *conn_state) 3423 { 3424 struct intel_display *display = to_intel_display(crtc_state); 3425 const struct drm_display_mode *adjusted_mode = 3426 &crtc_state->hw.adjusted_mode; 3427 struct intel_connector *connector = to_intel_connector(conn_state->connector); 3428 int symbol_size = intel_dp_is_uhbr(crtc_state) ? 32 : 8; 3429 /* 3430 * min symbol cycles is 3(BS,VBID, BE) for 128b/132b and 3431 * 5(BS, VBID, MVID, MAUD, BE) for 8b/10b 3432 */ 3433 int min_sym_cycles = intel_dp_is_uhbr(crtc_state) ? 3 : 5; 3434 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3435 int num_joined_pipes = intel_crtc_num_joined_pipes(crtc_state); 3436 int min_hblank; 3437 int max_lane_count = 4; 3438 int hactive_sym_cycles, htotal_sym_cycles; 3439 int dsc_slices = 0; 3440 int link_bpp_x16; 3441 3442 if (DISPLAY_VER(display) < 30) 3443 return 0; 3444 3445 /* MIN_HBLANK should be set only for 8b/10b MST or for 128b/132b SST/MST */ 3446 if (!is_mst && !intel_dp_is_uhbr(crtc_state)) 3447 return 0; 3448 3449 if (crtc_state->dsc.compression_enable) { 3450 dsc_slices = intel_dp_dsc_get_slice_count(connector, 3451 adjusted_mode->crtc_clock, 3452 adjusted_mode->crtc_hdisplay, 3453 num_joined_pipes); 3454 if (!dsc_slices) { 3455 drm_dbg(display->drm, "failed to calculate dsc slice count\n"); 3456 return -EINVAL; 3457 } 3458 } 3459 3460 if (crtc_state->dsc.compression_enable) 3461 link_bpp_x16 = crtc_state->dsc.compressed_bpp_x16; 3462 else 3463 link_bpp_x16 = intel_dp_output_format_link_bpp_x16(crtc_state->output_format, 3464 crtc_state->pipe_bpp); 3465 3466 /* Calculate min Hblank Link Layer Symbol Cycle Count for 8b/10b MST & 128b/132b */ 3467 hactive_sym_cycles = drm_dp_link_symbol_cycles(max_lane_count, 3468 adjusted_mode->hdisplay, 3469 dsc_slices, 3470 link_bpp_x16, 3471 symbol_size, is_mst); 3472 htotal_sym_cycles = adjusted_mode->htotal * hactive_sym_cycles / 3473 adjusted_mode->hdisplay; 3474 3475 min_hblank = htotal_sym_cycles - hactive_sym_cycles; 3476 /* minimum Hblank calculation: https://groups.vesa.org/wg/DP/document/20494 */ 3477 min_hblank = max(min_hblank, min_sym_cycles); 3478 3479 /* 3480 * adjust the BlankingStart/BlankingEnd framing control from 3481 * the calculated value 3482 */ 3483 min_hblank = min_hblank - 2; 3484 3485 /* 3486 * min_hblank formula is undergoing a change, to avoid underrun use the 3487 * recomended value in spec to compare with the calculated one and use the 3488 * minimum value 3489 */ 3490 if (intel_dp_is_uhbr(crtc_state)) { 3491 /* 3492 * Note: Bspec requires a min_hblank of 2 for YCBCR420 3493 * with compressed bpp 6, but the minimum compressed bpp 3494 * supported by the driver is 8. 3495 */ 3496 drm_WARN_ON(display->drm, 3497 (crtc_state->dsc.compression_enable && 3498 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 3499 crtc_state->dsc.compressed_bpp_x16 < fxp_q4_from_int(8))); 3500 min_hblank = min(3, min_hblank); 3501 } else { 3502 min_hblank = min(10, min_hblank); 3503 } 3504 3505 crtc_state->min_hblank = min_hblank; 3506 3507 return 0; 3508 } 3509 3510 int 3511 intel_dp_compute_config(struct intel_encoder *encoder, 3512 struct intel_crtc_state *pipe_config, 3513 struct drm_connector_state *conn_state) 3514 { 3515 struct intel_display *display = to_intel_display(encoder); 3516 struct intel_atomic_state *state = to_intel_atomic_state(conn_state->state); 3517 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 3518 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3519 const struct drm_display_mode *fixed_mode; 3520 struct intel_connector *connector = intel_dp->attached_connector; 3521 int ret = 0, link_bpp_x16; 3522 3523 fixed_mode = intel_panel_fixed_mode(connector, adjusted_mode); 3524 if (intel_dp_is_edp(intel_dp) && fixed_mode) { 3525 ret = intel_panel_compute_config(connector, adjusted_mode); 3526 if (ret) 3527 return ret; 3528 } 3529 3530 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 3531 return -EINVAL; 3532 3533 if (!connector->base.interlace_allowed && 3534 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) 3535 return -EINVAL; 3536 3537 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) 3538 return -EINVAL; 3539 3540 if (intel_dp_hdisplay_bad(display, adjusted_mode->crtc_hdisplay)) 3541 return -EINVAL; 3542 3543 /* 3544 * Try to respect downstream TMDS clock limits first, if 3545 * that fails assume the user might know something we don't. 3546 */ 3547 ret = intel_dp_compute_output_format(encoder, pipe_config, conn_state, true); 3548 if (ret) 3549 ret = intel_dp_compute_output_format(encoder, pipe_config, conn_state, false); 3550 if (ret) 3551 return ret; 3552 3553 if ((intel_dp_is_edp(intel_dp) && fixed_mode) || 3554 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) { 3555 ret = intel_pfit_compute_config(pipe_config, conn_state); 3556 if (ret) 3557 return ret; 3558 } 3559 3560 pipe_config->limited_color_range = 3561 intel_dp_limited_color_range(pipe_config, conn_state); 3562 3563 if (intel_dp_is_uhbr(pipe_config)) { 3564 /* 128b/132b SST also needs this */ 3565 pipe_config->mst_master_transcoder = pipe_config->cpu_transcoder; 3566 } else { 3567 pipe_config->enhanced_framing = 3568 drm_dp_enhanced_frame_cap(intel_dp->dpcd); 3569 } 3570 3571 if (pipe_config->dsc.compression_enable) 3572 link_bpp_x16 = pipe_config->dsc.compressed_bpp_x16; 3573 else 3574 link_bpp_x16 = intel_dp_output_format_link_bpp_x16(pipe_config->output_format, 3575 pipe_config->pipe_bpp); 3576 3577 if (intel_dp->mso_link_count) { 3578 int n = intel_dp->mso_link_count; 3579 int overlap = intel_dp->mso_pixel_overlap; 3580 3581 pipe_config->splitter.enable = true; 3582 pipe_config->splitter.link_count = n; 3583 pipe_config->splitter.pixel_overlap = overlap; 3584 3585 drm_dbg_kms(display->drm, 3586 "MSO link count %d, pixel overlap %d\n", 3587 n, overlap); 3588 3589 adjusted_mode->crtc_hdisplay = adjusted_mode->crtc_hdisplay / n + overlap; 3590 adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hblank_start / n + overlap; 3591 adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_end / n + overlap; 3592 adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hsync_start / n + overlap; 3593 adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_end / n + overlap; 3594 adjusted_mode->crtc_htotal = adjusted_mode->crtc_htotal / n + overlap; 3595 adjusted_mode->crtc_clock /= n; 3596 } 3597 3598 intel_dp_audio_compute_config(encoder, pipe_config, conn_state); 3599 3600 if (!intel_dp_is_uhbr(pipe_config)) { 3601 intel_link_compute_m_n(link_bpp_x16, 3602 pipe_config->lane_count, 3603 adjusted_mode->crtc_clock, 3604 pipe_config->port_clock, 3605 intel_dp_bw_fec_overhead(pipe_config->fec_enable), 3606 &pipe_config->dp_m_n); 3607 } 3608 3609 ret = intel_dp_compute_min_hblank(pipe_config, conn_state); 3610 if (ret) 3611 return ret; 3612 3613 /* FIXME: abstract this better */ 3614 if (pipe_config->splitter.enable) 3615 pipe_config->dp_m_n.data_m *= pipe_config->splitter.link_count; 3616 3617 intel_vrr_compute_config(pipe_config, conn_state); 3618 intel_dp_compute_as_sdp(intel_dp, pipe_config); 3619 intel_psr_compute_config(intel_dp, pipe_config, conn_state); 3620 intel_alpm_lobf_compute_config(intel_dp, pipe_config, conn_state); 3621 intel_dp_drrs_compute_config(connector, pipe_config, link_bpp_x16); 3622 intel_dp_compute_vsc_sdp(intel_dp, pipe_config, conn_state); 3623 intel_dp_compute_hdr_metadata_infoframe_sdp(intel_dp, pipe_config, conn_state); 3624 3625 return intel_dp_tunnel_atomic_compute_stream_bw(state, intel_dp, connector, 3626 pipe_config); 3627 } 3628 3629 void intel_dp_set_link_params(struct intel_dp *intel_dp, 3630 int link_rate, int lane_count) 3631 { 3632 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set)); 3633 intel_dp->link.active = false; 3634 intel_dp->needs_modeset_retry = false; 3635 intel_dp->link_rate = link_rate; 3636 intel_dp->lane_count = lane_count; 3637 } 3638 3639 void intel_dp_reset_link_params(struct intel_dp *intel_dp) 3640 { 3641 intel_dp->link.max_lane_count = intel_dp_max_common_lane_count(intel_dp); 3642 intel_dp->link.max_rate = intel_dp_max_common_rate(intel_dp); 3643 intel_dp->link.mst_probed_lane_count = 0; 3644 intel_dp->link.mst_probed_rate = 0; 3645 intel_dp->link.retrain_disabled = false; 3646 intel_dp->link.seq_train_failures = 0; 3647 } 3648 3649 /* Enable backlight PWM and backlight PP control. */ 3650 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state, 3651 const struct drm_connector_state *conn_state) 3652 { 3653 struct intel_display *display = to_intel_display(crtc_state); 3654 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(conn_state->best_encoder)); 3655 3656 if (!intel_dp_is_edp(intel_dp)) 3657 return; 3658 3659 drm_dbg_kms(display->drm, "\n"); 3660 3661 intel_backlight_enable(crtc_state, conn_state); 3662 intel_pps_backlight_on(intel_dp); 3663 } 3664 3665 /* Disable backlight PP control and backlight PWM. */ 3666 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state) 3667 { 3668 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(old_conn_state->best_encoder)); 3669 struct intel_display *display = to_intel_display(intel_dp); 3670 3671 if (!intel_dp_is_edp(intel_dp)) 3672 return; 3673 3674 drm_dbg_kms(display->drm, "\n"); 3675 3676 intel_pps_backlight_off(intel_dp); 3677 intel_backlight_disable(old_conn_state); 3678 } 3679 3680 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp) 3681 { 3682 /* 3683 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus 3684 * be capable of signalling downstream hpd with a long pulse. 3685 * Whether or not that means D3 is safe to use is not clear, 3686 * but let's assume so until proven otherwise. 3687 * 3688 * FIXME should really check all downstream ports... 3689 */ 3690 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 && 3691 drm_dp_is_branch(intel_dp->dpcd) && 3692 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD; 3693 } 3694 3695 static int 3696 write_dsc_decompression_flag(struct drm_dp_aux *aux, u8 flag, bool set) 3697 { 3698 int err; 3699 u8 val; 3700 3701 err = drm_dp_dpcd_readb(aux, DP_DSC_ENABLE, &val); 3702 if (err < 0) 3703 return err; 3704 3705 if (set) 3706 val |= flag; 3707 else 3708 val &= ~flag; 3709 3710 return drm_dp_dpcd_writeb(aux, DP_DSC_ENABLE, val); 3711 } 3712 3713 static void 3714 intel_dp_sink_set_dsc_decompression(struct intel_connector *connector, 3715 bool enable) 3716 { 3717 struct intel_display *display = to_intel_display(connector); 3718 3719 if (write_dsc_decompression_flag(connector->dp.dsc_decompression_aux, 3720 DP_DECOMPRESSION_EN, enable) < 0) 3721 drm_dbg_kms(display->drm, 3722 "Failed to %s sink decompression state\n", 3723 str_enable_disable(enable)); 3724 } 3725 3726 static void 3727 intel_dp_sink_set_dsc_passthrough(const struct intel_connector *connector, 3728 bool enable) 3729 { 3730 struct intel_display *display = to_intel_display(connector); 3731 struct drm_dp_aux *aux = connector->mst.port ? 3732 connector->mst.port->passthrough_aux : NULL; 3733 3734 if (!aux) 3735 return; 3736 3737 if (write_dsc_decompression_flag(aux, 3738 DP_DSC_PASSTHROUGH_EN, enable) < 0) 3739 drm_dbg_kms(display->drm, 3740 "Failed to %s sink compression passthrough state\n", 3741 str_enable_disable(enable)); 3742 } 3743 3744 static int intel_dp_dsc_aux_ref_count(struct intel_atomic_state *state, 3745 const struct intel_connector *connector, 3746 bool for_get_ref) 3747 { 3748 struct intel_display *display = to_intel_display(state); 3749 struct drm_connector *_connector_iter; 3750 struct drm_connector_state *old_conn_state; 3751 struct drm_connector_state *new_conn_state; 3752 int ref_count = 0; 3753 int i; 3754 3755 /* 3756 * On SST the decompression AUX device won't be shared, each connector 3757 * uses for this its own AUX targeting the sink device. 3758 */ 3759 if (!connector->mst.dp) 3760 return connector->dp.dsc_decompression_enabled ? 1 : 0; 3761 3762 for_each_oldnew_connector_in_state(&state->base, _connector_iter, 3763 old_conn_state, new_conn_state, i) { 3764 const struct intel_connector * 3765 connector_iter = to_intel_connector(_connector_iter); 3766 3767 if (connector_iter->mst.dp != connector->mst.dp) 3768 continue; 3769 3770 if (!connector_iter->dp.dsc_decompression_enabled) 3771 continue; 3772 3773 drm_WARN_ON(display->drm, 3774 (for_get_ref && !new_conn_state->crtc) || 3775 (!for_get_ref && !old_conn_state->crtc)); 3776 3777 if (connector_iter->dp.dsc_decompression_aux == 3778 connector->dp.dsc_decompression_aux) 3779 ref_count++; 3780 } 3781 3782 return ref_count; 3783 } 3784 3785 static bool intel_dp_dsc_aux_get_ref(struct intel_atomic_state *state, 3786 struct intel_connector *connector) 3787 { 3788 bool ret = intel_dp_dsc_aux_ref_count(state, connector, true) == 0; 3789 3790 connector->dp.dsc_decompression_enabled = true; 3791 3792 return ret; 3793 } 3794 3795 static bool intel_dp_dsc_aux_put_ref(struct intel_atomic_state *state, 3796 struct intel_connector *connector) 3797 { 3798 connector->dp.dsc_decompression_enabled = false; 3799 3800 return intel_dp_dsc_aux_ref_count(state, connector, false) == 0; 3801 } 3802 3803 /** 3804 * intel_dp_sink_enable_decompression - Enable DSC decompression in sink/last branch device 3805 * @state: atomic state 3806 * @connector: connector to enable the decompression for 3807 * @new_crtc_state: new state for the CRTC driving @connector 3808 * 3809 * Enable the DSC decompression if required in the %DP_DSC_ENABLE DPCD 3810 * register of the appropriate sink/branch device. On SST this is always the 3811 * sink device, whereas on MST based on each device's DSC capabilities it's 3812 * either the last branch device (enabling decompression in it) or both the 3813 * last branch device (enabling passthrough in it) and the sink device 3814 * (enabling decompression in it). 3815 */ 3816 void intel_dp_sink_enable_decompression(struct intel_atomic_state *state, 3817 struct intel_connector *connector, 3818 const struct intel_crtc_state *new_crtc_state) 3819 { 3820 struct intel_display *display = to_intel_display(state); 3821 3822 if (!new_crtc_state->dsc.compression_enable) 3823 return; 3824 3825 if (drm_WARN_ON(display->drm, 3826 !connector->dp.dsc_decompression_aux || 3827 connector->dp.dsc_decompression_enabled)) 3828 return; 3829 3830 if (!intel_dp_dsc_aux_get_ref(state, connector)) 3831 return; 3832 3833 intel_dp_sink_set_dsc_passthrough(connector, true); 3834 intel_dp_sink_set_dsc_decompression(connector, true); 3835 } 3836 3837 /** 3838 * intel_dp_sink_disable_decompression - Disable DSC decompression in sink/last branch device 3839 * @state: atomic state 3840 * @connector: connector to disable the decompression for 3841 * @old_crtc_state: old state for the CRTC driving @connector 3842 * 3843 * Disable the DSC decompression if required in the %DP_DSC_ENABLE DPCD 3844 * register of the appropriate sink/branch device, corresponding to the 3845 * sequence in intel_dp_sink_enable_decompression(). 3846 */ 3847 void intel_dp_sink_disable_decompression(struct intel_atomic_state *state, 3848 struct intel_connector *connector, 3849 const struct intel_crtc_state *old_crtc_state) 3850 { 3851 struct intel_display *display = to_intel_display(state); 3852 3853 if (!old_crtc_state->dsc.compression_enable) 3854 return; 3855 3856 if (drm_WARN_ON(display->drm, 3857 !connector->dp.dsc_decompression_aux || 3858 !connector->dp.dsc_decompression_enabled)) 3859 return; 3860 3861 if (!intel_dp_dsc_aux_put_ref(state, connector)) 3862 return; 3863 3864 intel_dp_sink_set_dsc_decompression(connector, false); 3865 intel_dp_sink_set_dsc_passthrough(connector, false); 3866 } 3867 3868 static void 3869 intel_dp_init_source_oui(struct intel_dp *intel_dp) 3870 { 3871 struct intel_display *display = to_intel_display(intel_dp); 3872 u8 oui[] = { 0x00, 0xaa, 0x01 }; 3873 u8 buf[3] = {}; 3874 3875 if (READ_ONCE(intel_dp->oui_valid)) 3876 return; 3877 3878 WRITE_ONCE(intel_dp->oui_valid, true); 3879 3880 /* 3881 * During driver init, we want to be careful and avoid changing the source OUI if it's 3882 * already set to what we want, so as to avoid clearing any state by accident 3883 */ 3884 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SOURCE_OUI, buf, sizeof(buf)) < 0) 3885 drm_dbg_kms(display->drm, "Failed to read source OUI\n"); 3886 3887 if (memcmp(oui, buf, sizeof(oui)) == 0) { 3888 /* Assume the OUI was written now. */ 3889 intel_dp->last_oui_write = jiffies; 3890 return; 3891 } 3892 3893 if (drm_dp_dpcd_write(&intel_dp->aux, DP_SOURCE_OUI, oui, sizeof(oui)) < 0) { 3894 drm_dbg_kms(display->drm, "Failed to write source OUI\n"); 3895 WRITE_ONCE(intel_dp->oui_valid, false); 3896 } 3897 3898 intel_dp->last_oui_write = jiffies; 3899 } 3900 3901 void intel_dp_invalidate_source_oui(struct intel_dp *intel_dp) 3902 { 3903 WRITE_ONCE(intel_dp->oui_valid, false); 3904 } 3905 3906 void intel_dp_wait_source_oui(struct intel_dp *intel_dp) 3907 { 3908 struct intel_display *display = to_intel_display(intel_dp); 3909 struct intel_connector *connector = intel_dp->attached_connector; 3910 3911 drm_dbg_kms(display->drm, 3912 "[CONNECTOR:%d:%s] Performing OUI wait (%u ms)\n", 3913 connector->base.base.id, connector->base.name, 3914 connector->panel.vbt.backlight.hdr_dpcd_refresh_timeout); 3915 3916 wait_remaining_ms_from_jiffies(intel_dp->last_oui_write, 3917 connector->panel.vbt.backlight.hdr_dpcd_refresh_timeout); 3918 } 3919 3920 /* If the device supports it, try to set the power state appropriately */ 3921 void intel_dp_set_power(struct intel_dp *intel_dp, u8 mode) 3922 { 3923 struct intel_display *display = to_intel_display(intel_dp); 3924 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 3925 int ret, i; 3926 3927 /* Should have a valid DPCD by this point */ 3928 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) 3929 return; 3930 3931 if (mode != DP_SET_POWER_D0) { 3932 if (downstream_hpd_needs_d0(intel_dp)) 3933 return; 3934 3935 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, mode); 3936 } else { 3937 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 3938 3939 intel_lspcon_resume(dig_port); 3940 3941 /* Write the source OUI as early as possible */ 3942 intel_dp_init_source_oui(intel_dp); 3943 3944 /* 3945 * When turning on, we need to retry for 1ms to give the sink 3946 * time to wake up. 3947 */ 3948 for (i = 0; i < 3; i++) { 3949 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, mode); 3950 if (ret == 1) 3951 break; 3952 msleep(1); 3953 } 3954 3955 if (ret == 1 && intel_lspcon_active(dig_port)) 3956 intel_lspcon_wait_pcon_mode(dig_port); 3957 } 3958 3959 if (ret != 1) 3960 drm_dbg_kms(display->drm, 3961 "[ENCODER:%d:%s] Set power to %s failed\n", 3962 encoder->base.base.id, encoder->base.name, 3963 mode == DP_SET_POWER_D0 ? "D0" : "D3"); 3964 } 3965 3966 static bool 3967 intel_dp_get_dpcd(struct intel_dp *intel_dp); 3968 3969 /** 3970 * intel_dp_sync_state - sync the encoder state during init/resume 3971 * @encoder: intel encoder to sync 3972 * @crtc_state: state for the CRTC connected to the encoder 3973 * 3974 * Sync any state stored in the encoder wrt. HW state during driver init 3975 * and system resume. 3976 */ 3977 void intel_dp_sync_state(struct intel_encoder *encoder, 3978 const struct intel_crtc_state *crtc_state) 3979 { 3980 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3981 bool dpcd_updated = false; 3982 3983 /* 3984 * Don't clobber DPCD if it's been already read out during output 3985 * setup (eDP) or detect. 3986 */ 3987 if (crtc_state && intel_dp->dpcd[DP_DPCD_REV] == 0) { 3988 intel_dp_get_dpcd(intel_dp); 3989 dpcd_updated = true; 3990 } 3991 3992 intel_dp_tunnel_resume(intel_dp, crtc_state, dpcd_updated); 3993 3994 if (crtc_state) { 3995 intel_dp_reset_link_params(intel_dp); 3996 intel_dp_set_link_params(intel_dp, crtc_state->port_clock, crtc_state->lane_count); 3997 intel_dp->link.active = true; 3998 } 3999 } 4000 4001 bool intel_dp_initial_fastset_check(struct intel_encoder *encoder, 4002 struct intel_crtc_state *crtc_state) 4003 { 4004 struct intel_display *display = to_intel_display(encoder); 4005 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4006 bool fastset = true; 4007 4008 /* 4009 * If BIOS has set an unsupported or non-standard link rate for some 4010 * reason force an encoder recompute and full modeset. 4011 */ 4012 if (intel_dp_rate_index(intel_dp->source_rates, intel_dp->num_source_rates, 4013 crtc_state->port_clock) < 0) { 4014 drm_dbg_kms(display->drm, 4015 "[ENCODER:%d:%s] Forcing full modeset due to unsupported link rate\n", 4016 encoder->base.base.id, encoder->base.name); 4017 crtc_state->uapi.connectors_changed = true; 4018 fastset = false; 4019 } 4020 4021 /* 4022 * FIXME hack to force full modeset when DSC is being used. 4023 * 4024 * As long as we do not have full state readout and config comparison 4025 * of crtc_state->dsc, we have no way to ensure reliable fastset. 4026 * Remove once we have readout for DSC. 4027 */ 4028 if (crtc_state->dsc.compression_enable) { 4029 drm_dbg_kms(display->drm, 4030 "[ENCODER:%d:%s] Forcing full modeset due to DSC being enabled\n", 4031 encoder->base.base.id, encoder->base.name); 4032 crtc_state->uapi.mode_changed = true; 4033 fastset = false; 4034 } 4035 4036 if (CAN_PANEL_REPLAY(intel_dp)) { 4037 drm_dbg_kms(display->drm, 4038 "[ENCODER:%d:%s] Forcing full modeset to compute panel replay state\n", 4039 encoder->base.base.id, encoder->base.name); 4040 crtc_state->uapi.mode_changed = true; 4041 fastset = false; 4042 } 4043 4044 return fastset; 4045 } 4046 4047 static void intel_dp_get_pcon_dsc_cap(struct intel_dp *intel_dp) 4048 { 4049 struct intel_display *display = to_intel_display(intel_dp); 4050 4051 /* Clear the cached register set to avoid using stale values */ 4052 4053 memset(intel_dp->pcon_dsc_dpcd, 0, sizeof(intel_dp->pcon_dsc_dpcd)); 4054 4055 if (!drm_dp_is_branch(intel_dp->dpcd)) 4056 return; 4057 4058 if (drm_dp_dpcd_read(&intel_dp->aux, DP_PCON_DSC_ENCODER, 4059 intel_dp->pcon_dsc_dpcd, 4060 sizeof(intel_dp->pcon_dsc_dpcd)) < 0) 4061 drm_err(display->drm, "Failed to read DPCD register 0x%x\n", 4062 DP_PCON_DSC_ENCODER); 4063 4064 drm_dbg_kms(display->drm, "PCON ENCODER DSC DPCD: %*ph\n", 4065 (int)sizeof(intel_dp->pcon_dsc_dpcd), intel_dp->pcon_dsc_dpcd); 4066 } 4067 4068 static int intel_dp_pcon_get_frl_mask(u8 frl_bw_mask) 4069 { 4070 static const int bw_gbps[] = {9, 18, 24, 32, 40, 48}; 4071 int i; 4072 4073 for (i = ARRAY_SIZE(bw_gbps) - 1; i >= 0; i--) { 4074 if (frl_bw_mask & (1 << i)) 4075 return bw_gbps[i]; 4076 } 4077 return 0; 4078 } 4079 4080 static int intel_dp_pcon_set_frl_mask(int max_frl) 4081 { 4082 switch (max_frl) { 4083 case 48: 4084 return DP_PCON_FRL_BW_MASK_48GBPS; 4085 case 40: 4086 return DP_PCON_FRL_BW_MASK_40GBPS; 4087 case 32: 4088 return DP_PCON_FRL_BW_MASK_32GBPS; 4089 case 24: 4090 return DP_PCON_FRL_BW_MASK_24GBPS; 4091 case 18: 4092 return DP_PCON_FRL_BW_MASK_18GBPS; 4093 case 9: 4094 return DP_PCON_FRL_BW_MASK_9GBPS; 4095 } 4096 4097 return 0; 4098 } 4099 4100 static int intel_dp_hdmi_sink_max_frl(struct intel_dp *intel_dp) 4101 { 4102 struct intel_connector *connector = intel_dp->attached_connector; 4103 const struct drm_display_info *info = &connector->base.display_info; 4104 int max_frl_rate; 4105 int max_lanes, rate_per_lane; 4106 int max_dsc_lanes, dsc_rate_per_lane; 4107 4108 max_lanes = info->hdmi.max_lanes; 4109 rate_per_lane = info->hdmi.max_frl_rate_per_lane; 4110 max_frl_rate = max_lanes * rate_per_lane; 4111 4112 if (info->hdmi.dsc_cap.v_1p2) { 4113 max_dsc_lanes = info->hdmi.dsc_cap.max_lanes; 4114 dsc_rate_per_lane = info->hdmi.dsc_cap.max_frl_rate_per_lane; 4115 if (max_dsc_lanes && dsc_rate_per_lane) 4116 max_frl_rate = min(max_frl_rate, max_dsc_lanes * dsc_rate_per_lane); 4117 } 4118 4119 return max_frl_rate; 4120 } 4121 4122 static bool 4123 intel_dp_pcon_is_frl_trained(struct intel_dp *intel_dp, 4124 u8 max_frl_bw_mask, u8 *frl_trained_mask) 4125 { 4126 if (drm_dp_pcon_hdmi_link_active(&intel_dp->aux) && 4127 drm_dp_pcon_hdmi_link_mode(&intel_dp->aux, frl_trained_mask) == DP_PCON_HDMI_MODE_FRL && 4128 *frl_trained_mask >= max_frl_bw_mask) 4129 return true; 4130 4131 return false; 4132 } 4133 4134 static int intel_dp_pcon_start_frl_training(struct intel_dp *intel_dp) 4135 { 4136 struct intel_display *display = to_intel_display(intel_dp); 4137 #define TIMEOUT_FRL_READY_MS 500 4138 #define TIMEOUT_HDMI_LINK_ACTIVE_MS 1000 4139 int max_frl_bw, max_pcon_frl_bw, max_edid_frl_bw, ret; 4140 u8 max_frl_bw_mask = 0, frl_trained_mask; 4141 bool is_active; 4142 4143 max_pcon_frl_bw = intel_dp->dfp.pcon_max_frl_bw; 4144 drm_dbg(display->drm, "PCON max rate = %d Gbps\n", max_pcon_frl_bw); 4145 4146 max_edid_frl_bw = intel_dp_hdmi_sink_max_frl(intel_dp); 4147 drm_dbg(display->drm, "Sink max rate from EDID = %d Gbps\n", 4148 max_edid_frl_bw); 4149 4150 max_frl_bw = min(max_edid_frl_bw, max_pcon_frl_bw); 4151 4152 if (max_frl_bw <= 0) 4153 return -EINVAL; 4154 4155 max_frl_bw_mask = intel_dp_pcon_set_frl_mask(max_frl_bw); 4156 drm_dbg(display->drm, "MAX_FRL_BW_MASK = %u\n", max_frl_bw_mask); 4157 4158 if (intel_dp_pcon_is_frl_trained(intel_dp, max_frl_bw_mask, &frl_trained_mask)) 4159 goto frl_trained; 4160 4161 ret = drm_dp_pcon_frl_prepare(&intel_dp->aux, false); 4162 if (ret < 0) 4163 return ret; 4164 /* Wait for PCON to be FRL Ready */ 4165 ret = poll_timeout_us(is_active = drm_dp_pcon_is_frl_ready(&intel_dp->aux), 4166 is_active, 4167 1000, TIMEOUT_FRL_READY_MS * 1000, false); 4168 if (ret) 4169 return ret; 4170 4171 ret = drm_dp_pcon_frl_configure_1(&intel_dp->aux, max_frl_bw, 4172 DP_PCON_ENABLE_SEQUENTIAL_LINK); 4173 if (ret < 0) 4174 return ret; 4175 ret = drm_dp_pcon_frl_configure_2(&intel_dp->aux, max_frl_bw_mask, 4176 DP_PCON_FRL_LINK_TRAIN_NORMAL); 4177 if (ret < 0) 4178 return ret; 4179 ret = drm_dp_pcon_frl_enable(&intel_dp->aux); 4180 if (ret < 0) 4181 return ret; 4182 /* 4183 * Wait for FRL to be completed 4184 * Check if the HDMI Link is up and active. 4185 */ 4186 ret = poll_timeout_us(is_active = intel_dp_pcon_is_frl_trained(intel_dp, max_frl_bw_mask, &frl_trained_mask), 4187 is_active, 4188 1000, TIMEOUT_HDMI_LINK_ACTIVE_MS * 1000, false); 4189 if (ret) 4190 return ret; 4191 4192 frl_trained: 4193 drm_dbg(display->drm, "FRL_TRAINED_MASK = %u\n", frl_trained_mask); 4194 intel_dp->frl.trained_rate_gbps = intel_dp_pcon_get_frl_mask(frl_trained_mask); 4195 intel_dp->frl.is_trained = true; 4196 drm_dbg(display->drm, "FRL trained with : %d Gbps\n", 4197 intel_dp->frl.trained_rate_gbps); 4198 4199 return 0; 4200 } 4201 4202 static bool intel_dp_is_hdmi_2_1_sink(struct intel_dp *intel_dp) 4203 { 4204 if (drm_dp_is_branch(intel_dp->dpcd) && 4205 intel_dp_has_hdmi_sink(intel_dp) && 4206 intel_dp_hdmi_sink_max_frl(intel_dp) > 0) 4207 return true; 4208 4209 return false; 4210 } 4211 4212 static 4213 int intel_dp_pcon_set_tmds_mode(struct intel_dp *intel_dp) 4214 { 4215 int ret; 4216 u8 buf = 0; 4217 4218 /* Set PCON source control mode */ 4219 buf |= DP_PCON_ENABLE_SOURCE_CTL_MODE; 4220 4221 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf); 4222 if (ret < 0) 4223 return ret; 4224 4225 /* Set HDMI LINK ENABLE */ 4226 buf |= DP_PCON_ENABLE_HDMI_LINK; 4227 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf); 4228 if (ret < 0) 4229 return ret; 4230 4231 return 0; 4232 } 4233 4234 void intel_dp_check_frl_training(struct intel_dp *intel_dp) 4235 { 4236 struct intel_display *display = to_intel_display(intel_dp); 4237 4238 /* 4239 * Always go for FRL training if: 4240 * -PCON supports SRC_CTL_MODE (VESA DP2.0-HDMI2.1 PCON Spec Draft-1 Sec-7) 4241 * -sink is HDMI2.1 4242 */ 4243 if (!(intel_dp->downstream_ports[2] & DP_PCON_SOURCE_CTL_MODE) || 4244 !intel_dp_is_hdmi_2_1_sink(intel_dp) || 4245 intel_dp->frl.is_trained) 4246 return; 4247 4248 if (intel_dp_pcon_start_frl_training(intel_dp) < 0) { 4249 int ret, mode; 4250 4251 drm_dbg(display->drm, 4252 "Couldn't set FRL mode, continuing with TMDS mode\n"); 4253 ret = intel_dp_pcon_set_tmds_mode(intel_dp); 4254 mode = drm_dp_pcon_hdmi_link_mode(&intel_dp->aux, NULL); 4255 4256 if (ret < 0 || mode != DP_PCON_HDMI_MODE_TMDS) 4257 drm_dbg(display->drm, 4258 "Issue with PCON, cannot set TMDS mode\n"); 4259 } else { 4260 drm_dbg(display->drm, "FRL training Completed\n"); 4261 } 4262 } 4263 4264 static int 4265 intel_dp_pcon_dsc_enc_slice_height(const struct intel_crtc_state *crtc_state) 4266 { 4267 int vactive = crtc_state->hw.adjusted_mode.vdisplay; 4268 4269 return intel_hdmi_dsc_get_slice_height(vactive); 4270 } 4271 4272 static int 4273 intel_dp_pcon_dsc_enc_slices(struct intel_dp *intel_dp, 4274 const struct intel_crtc_state *crtc_state) 4275 { 4276 struct intel_connector *connector = intel_dp->attached_connector; 4277 const struct drm_display_info *info = &connector->base.display_info; 4278 int hdmi_throughput = info->hdmi.dsc_cap.clk_per_slice; 4279 int hdmi_max_slices = info->hdmi.dsc_cap.max_slices; 4280 int pcon_max_slices = drm_dp_pcon_dsc_max_slices(intel_dp->pcon_dsc_dpcd); 4281 int pcon_max_slice_width = drm_dp_pcon_dsc_max_slice_width(intel_dp->pcon_dsc_dpcd); 4282 4283 return intel_hdmi_dsc_get_num_slices(crtc_state, pcon_max_slices, 4284 pcon_max_slice_width, 4285 hdmi_max_slices, hdmi_throughput); 4286 } 4287 4288 static int 4289 intel_dp_pcon_dsc_enc_bpp(struct intel_dp *intel_dp, 4290 const struct intel_crtc_state *crtc_state, 4291 int num_slices, int slice_width) 4292 { 4293 struct intel_connector *connector = intel_dp->attached_connector; 4294 const struct drm_display_info *info = &connector->base.display_info; 4295 int output_format = crtc_state->output_format; 4296 bool hdmi_all_bpp = info->hdmi.dsc_cap.all_bpp; 4297 int pcon_fractional_bpp = drm_dp_pcon_dsc_bpp_incr(intel_dp->pcon_dsc_dpcd); 4298 int hdmi_max_chunk_bytes = 4299 info->hdmi.dsc_cap.total_chunk_kbytes * 1024; 4300 4301 return intel_hdmi_dsc_get_bpp(pcon_fractional_bpp, slice_width, 4302 num_slices, output_format, hdmi_all_bpp, 4303 hdmi_max_chunk_bytes); 4304 } 4305 4306 void 4307 intel_dp_pcon_dsc_configure(struct intel_dp *intel_dp, 4308 const struct intel_crtc_state *crtc_state) 4309 { 4310 struct intel_display *display = to_intel_display(intel_dp); 4311 struct intel_connector *connector = intel_dp->attached_connector; 4312 const struct drm_display_info *info; 4313 u8 pps_param[6]; 4314 int slice_height; 4315 int slice_width; 4316 int num_slices; 4317 int bits_per_pixel; 4318 int ret; 4319 bool hdmi_is_dsc_1_2; 4320 4321 if (!intel_dp_is_hdmi_2_1_sink(intel_dp)) 4322 return; 4323 4324 if (!connector) 4325 return; 4326 4327 info = &connector->base.display_info; 4328 4329 hdmi_is_dsc_1_2 = info->hdmi.dsc_cap.v_1p2; 4330 4331 if (!drm_dp_pcon_enc_is_dsc_1_2(intel_dp->pcon_dsc_dpcd) || 4332 !hdmi_is_dsc_1_2) 4333 return; 4334 4335 slice_height = intel_dp_pcon_dsc_enc_slice_height(crtc_state); 4336 if (!slice_height) 4337 return; 4338 4339 num_slices = intel_dp_pcon_dsc_enc_slices(intel_dp, crtc_state); 4340 if (!num_slices) 4341 return; 4342 4343 slice_width = DIV_ROUND_UP(crtc_state->hw.adjusted_mode.hdisplay, 4344 num_slices); 4345 4346 bits_per_pixel = intel_dp_pcon_dsc_enc_bpp(intel_dp, crtc_state, 4347 num_slices, slice_width); 4348 if (!bits_per_pixel) 4349 return; 4350 4351 pps_param[0] = slice_height & 0xFF; 4352 pps_param[1] = slice_height >> 8; 4353 pps_param[2] = slice_width & 0xFF; 4354 pps_param[3] = slice_width >> 8; 4355 pps_param[4] = bits_per_pixel & 0xFF; 4356 pps_param[5] = (bits_per_pixel >> 8) & 0x3; 4357 4358 ret = drm_dp_pcon_pps_override_param(&intel_dp->aux, pps_param); 4359 if (ret < 0) 4360 drm_dbg_kms(display->drm, "Failed to set pcon DSC\n"); 4361 } 4362 4363 void intel_dp_configure_protocol_converter(struct intel_dp *intel_dp, 4364 const struct intel_crtc_state *crtc_state) 4365 { 4366 struct intel_display *display = to_intel_display(intel_dp); 4367 bool ycbcr444_to_420 = false; 4368 bool rgb_to_ycbcr = false; 4369 u8 tmp; 4370 4371 if (intel_dp->dpcd[DP_DPCD_REV] < 0x13) 4372 return; 4373 4374 if (!drm_dp_is_branch(intel_dp->dpcd)) 4375 return; 4376 4377 tmp = intel_dp_has_hdmi_sink(intel_dp) ? DP_HDMI_DVI_OUTPUT_CONFIG : 0; 4378 4379 if (drm_dp_dpcd_writeb(&intel_dp->aux, 4380 DP_PROTOCOL_CONVERTER_CONTROL_0, tmp) != 1) 4381 drm_dbg_kms(display->drm, 4382 "Failed to %s protocol converter HDMI mode\n", 4383 str_enable_disable(intel_dp_has_hdmi_sink(intel_dp))); 4384 4385 if (crtc_state->sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) { 4386 switch (crtc_state->output_format) { 4387 case INTEL_OUTPUT_FORMAT_YCBCR420: 4388 break; 4389 case INTEL_OUTPUT_FORMAT_YCBCR444: 4390 ycbcr444_to_420 = true; 4391 break; 4392 case INTEL_OUTPUT_FORMAT_RGB: 4393 rgb_to_ycbcr = true; 4394 ycbcr444_to_420 = true; 4395 break; 4396 default: 4397 MISSING_CASE(crtc_state->output_format); 4398 break; 4399 } 4400 } else if (crtc_state->sink_format == INTEL_OUTPUT_FORMAT_YCBCR444) { 4401 switch (crtc_state->output_format) { 4402 case INTEL_OUTPUT_FORMAT_YCBCR444: 4403 break; 4404 case INTEL_OUTPUT_FORMAT_RGB: 4405 rgb_to_ycbcr = true; 4406 break; 4407 default: 4408 MISSING_CASE(crtc_state->output_format); 4409 break; 4410 } 4411 } 4412 4413 tmp = ycbcr444_to_420 ? DP_CONVERSION_TO_YCBCR420_ENABLE : 0; 4414 4415 if (drm_dp_dpcd_writeb(&intel_dp->aux, 4416 DP_PROTOCOL_CONVERTER_CONTROL_1, tmp) != 1) 4417 drm_dbg_kms(display->drm, 4418 "Failed to %s protocol converter YCbCr 4:2:0 conversion mode\n", 4419 str_enable_disable(intel_dp->dfp.ycbcr_444_to_420)); 4420 4421 tmp = rgb_to_ycbcr ? DP_CONVERSION_BT709_RGB_YCBCR_ENABLE : 0; 4422 4423 if (drm_dp_pcon_convert_rgb_to_ycbcr(&intel_dp->aux, tmp) < 0) 4424 drm_dbg_kms(display->drm, 4425 "Failed to %s protocol converter RGB->YCbCr conversion mode\n", 4426 str_enable_disable(tmp)); 4427 } 4428 4429 static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp) 4430 { 4431 u8 dprx = 0; 4432 4433 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST, 4434 &dprx) != 1) 4435 return false; 4436 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; 4437 } 4438 4439 static int intel_dp_read_dsc_dpcd(struct drm_dp_aux *aux, 4440 u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]) 4441 { 4442 int ret; 4443 4444 ret = drm_dp_dpcd_read_data(aux, DP_DSC_SUPPORT, dsc_dpcd, 4445 DP_DSC_RECEIVER_CAP_SIZE); 4446 if (ret) { 4447 drm_dbg_kms(aux->drm_dev, 4448 "Could not read DSC DPCD register 0x%x Error: %pe\n", 4449 DP_DSC_SUPPORT, ERR_PTR(ret)); 4450 return ret; 4451 } 4452 4453 drm_dbg_kms(aux->drm_dev, "DSC DPCD: %*ph\n", 4454 DP_DSC_RECEIVER_CAP_SIZE, 4455 dsc_dpcd); 4456 return 0; 4457 } 4458 4459 static void init_dsc_overall_throughput_limits(struct intel_connector *connector, bool is_branch) 4460 { 4461 u8 branch_caps[DP_DSC_BRANCH_CAP_SIZE]; 4462 int line_width; 4463 4464 connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444 = INT_MAX; 4465 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420 = INT_MAX; 4466 connector->dp.dsc_branch_caps.max_line_width = INT_MAX; 4467 4468 if (!is_branch) 4469 return; 4470 4471 if (drm_dp_dpcd_read_data(connector->dp.dsc_decompression_aux, 4472 DP_DSC_BRANCH_OVERALL_THROUGHPUT_0, branch_caps, 4473 sizeof(branch_caps)) != 0) 4474 return; 4475 4476 connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444 = 4477 drm_dp_dsc_branch_max_overall_throughput(branch_caps, true) ? : INT_MAX; 4478 4479 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420 = 4480 drm_dp_dsc_branch_max_overall_throughput(branch_caps, false) ? : INT_MAX; 4481 4482 line_width = drm_dp_dsc_branch_max_line_width(branch_caps); 4483 connector->dp.dsc_branch_caps.max_line_width = line_width > 0 ? line_width : INT_MAX; 4484 } 4485 4486 void intel_dp_get_dsc_sink_cap(u8 dpcd_rev, 4487 const struct drm_dp_desc *desc, bool is_branch, 4488 struct intel_connector *connector) 4489 { 4490 struct intel_display *display = to_intel_display(connector); 4491 4492 /* 4493 * Clear the cached register set to avoid using stale values 4494 * for the sinks that do not support DSC. 4495 */ 4496 memset(connector->dp.dsc_dpcd, 0, sizeof(connector->dp.dsc_dpcd)); 4497 4498 /* Clear fec_capable to avoid using stale values */ 4499 connector->dp.fec_capability = 0; 4500 4501 memset(&connector->dp.dsc_branch_caps, 0, sizeof(connector->dp.dsc_branch_caps)); 4502 connector->dp.dsc_throughput_quirk = false; 4503 4504 if (dpcd_rev < DP_DPCD_REV_14) 4505 return; 4506 4507 if (intel_dp_read_dsc_dpcd(connector->dp.dsc_decompression_aux, 4508 connector->dp.dsc_dpcd) < 0) 4509 return; 4510 4511 if (drm_dp_dpcd_readb(connector->dp.dsc_decompression_aux, DP_FEC_CAPABILITY, 4512 &connector->dp.fec_capability) < 0) { 4513 drm_err(display->drm, "Failed to read FEC DPCD register\n"); 4514 return; 4515 } 4516 4517 drm_dbg_kms(display->drm, "FEC CAPABILITY: %x\n", 4518 connector->dp.fec_capability); 4519 4520 if (!(connector->dp.dsc_dpcd[0] & DP_DSC_DECOMPRESSION_IS_SUPPORTED)) 4521 return; 4522 4523 init_dsc_overall_throughput_limits(connector, is_branch); 4524 4525 /* 4526 * TODO: Move the HW rev check as well to the DRM core quirk table if 4527 * that's required after clarifying the list of affected devices. 4528 */ 4529 if (drm_dp_has_quirk(desc, DP_DPCD_QUIRK_DSC_THROUGHPUT_BPP_LIMIT) && 4530 desc->ident.hw_rev == 0x10) 4531 connector->dp.dsc_throughput_quirk = true; 4532 } 4533 4534 static void intel_edp_get_dsc_sink_cap(u8 edp_dpcd_rev, struct intel_connector *connector) 4535 { 4536 if (edp_dpcd_rev < DP_EDP_14) 4537 return; 4538 4539 if (intel_dp_read_dsc_dpcd(connector->dp.dsc_decompression_aux, 4540 connector->dp.dsc_dpcd) < 0) 4541 return; 4542 4543 if (connector->dp.dsc_dpcd[0] & DP_DSC_DECOMPRESSION_IS_SUPPORTED) 4544 init_dsc_overall_throughput_limits(connector, false); 4545 } 4546 4547 static void 4548 intel_dp_detect_dsc_caps(struct intel_dp *intel_dp, struct intel_connector *connector) 4549 { 4550 struct intel_display *display = to_intel_display(intel_dp); 4551 4552 /* Read DP Sink DSC Cap DPCD regs for DP v1.4 */ 4553 if (!HAS_DSC(display)) 4554 return; 4555 4556 if (intel_dp_is_edp(intel_dp)) 4557 intel_edp_get_dsc_sink_cap(intel_dp->edp_dpcd[0], 4558 connector); 4559 else 4560 intel_dp_get_dsc_sink_cap(intel_dp->dpcd[DP_DPCD_REV], 4561 &intel_dp->desc, drm_dp_is_branch(intel_dp->dpcd), 4562 connector); 4563 } 4564 4565 static void intel_edp_mso_mode_fixup(struct intel_connector *connector, 4566 struct drm_display_mode *mode) 4567 { 4568 struct intel_display *display = to_intel_display(connector); 4569 struct intel_dp *intel_dp = intel_attached_dp(connector); 4570 int n = intel_dp->mso_link_count; 4571 int overlap = intel_dp->mso_pixel_overlap; 4572 4573 if (!mode || !n) 4574 return; 4575 4576 mode->hdisplay = (mode->hdisplay - overlap) * n; 4577 mode->hsync_start = (mode->hsync_start - overlap) * n; 4578 mode->hsync_end = (mode->hsync_end - overlap) * n; 4579 mode->htotal = (mode->htotal - overlap) * n; 4580 mode->clock *= n; 4581 4582 drm_mode_set_name(mode); 4583 4584 drm_dbg_kms(display->drm, 4585 "[CONNECTOR:%d:%s] using generated MSO mode: " DRM_MODE_FMT "\n", 4586 connector->base.base.id, connector->base.name, 4587 DRM_MODE_ARG(mode)); 4588 } 4589 4590 void intel_edp_fixup_vbt_bpp(struct intel_encoder *encoder, int pipe_bpp) 4591 { 4592 struct intel_display *display = to_intel_display(encoder); 4593 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4594 struct intel_connector *connector = intel_dp->attached_connector; 4595 4596 if (connector->panel.vbt.edp.bpp && pipe_bpp > connector->panel.vbt.edp.bpp) { 4597 /* 4598 * This is a big fat ugly hack. 4599 * 4600 * Some machines in UEFI boot mode provide us a VBT that has 18 4601 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons 4602 * unknown we fail to light up. Yet the same BIOS boots up with 4603 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as 4604 * max, not what it tells us to use. 4605 * 4606 * Note: This will still be broken if the eDP panel is not lit 4607 * up by the BIOS, and thus we can't get the mode at module 4608 * load. 4609 */ 4610 drm_dbg_kms(display->drm, 4611 "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", 4612 pipe_bpp, connector->panel.vbt.edp.bpp); 4613 connector->panel.vbt.edp.bpp = pipe_bpp; 4614 } 4615 } 4616 4617 static void intel_edp_mso_init(struct intel_dp *intel_dp) 4618 { 4619 struct intel_display *display = to_intel_display(intel_dp); 4620 struct intel_connector *connector = intel_dp->attached_connector; 4621 struct drm_display_info *info = &connector->base.display_info; 4622 u8 mso; 4623 4624 if (intel_dp->edp_dpcd[0] < DP_EDP_14) 4625 return; 4626 4627 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_MSO_LINK_CAPABILITIES, &mso) != 1) { 4628 drm_err(display->drm, "Failed to read MSO cap\n"); 4629 return; 4630 } 4631 4632 /* Valid configurations are SST or MSO 2x1, 2x2, 4x1 */ 4633 mso &= DP_EDP_MSO_NUMBER_OF_LINKS_MASK; 4634 if (mso % 2 || mso > drm_dp_max_lane_count(intel_dp->dpcd)) { 4635 drm_err(display->drm, "Invalid MSO link count cap %u\n", mso); 4636 mso = 0; 4637 } 4638 4639 if (mso) { 4640 drm_dbg_kms(display->drm, 4641 "Sink MSO %ux%u configuration, pixel overlap %u\n", 4642 mso, drm_dp_max_lane_count(intel_dp->dpcd) / mso, 4643 info->mso_pixel_overlap); 4644 if (!HAS_MSO(display)) { 4645 drm_err(display->drm, 4646 "No source MSO support, disabling\n"); 4647 mso = 0; 4648 } 4649 } 4650 4651 intel_dp->mso_link_count = mso; 4652 intel_dp->mso_pixel_overlap = mso ? info->mso_pixel_overlap : 0; 4653 } 4654 4655 static void 4656 intel_edp_set_data_override_rates(struct intel_dp *intel_dp) 4657 { 4658 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 4659 int *sink_rates = intel_dp->sink_rates; 4660 int i, count = 0; 4661 4662 for (i = 0; i < intel_dp->num_sink_rates; i++) { 4663 if (intel_bios_encoder_reject_edp_rate(encoder->devdata, 4664 intel_dp->sink_rates[i])) 4665 continue; 4666 4667 sink_rates[count++] = intel_dp->sink_rates[i]; 4668 } 4669 intel_dp->num_sink_rates = count; 4670 } 4671 4672 static void 4673 intel_edp_set_sink_rates(struct intel_dp *intel_dp) 4674 { 4675 struct intel_display *display = to_intel_display(intel_dp); 4676 4677 intel_dp->num_sink_rates = 0; 4678 4679 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) { 4680 __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; 4681 int ret; 4682 int i; 4683 4684 ret = drm_dp_dpcd_read_data(&intel_dp->aux, 4685 DP_SUPPORTED_LINK_RATES, 4686 sink_rates, sizeof(sink_rates)); 4687 if (ret < 0) { 4688 drm_dbg_kms(display->drm, 4689 "Unable to read eDP supported link rates, using default rates\n"); 4690 memset(sink_rates, 0, sizeof(sink_rates)); 4691 } 4692 4693 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { 4694 int rate; 4695 4696 /* Value read multiplied by 200kHz gives the per-lane 4697 * link rate in kHz. The source rates are, however, 4698 * stored in terms of LS_Clk kHz. The full conversion 4699 * back to symbols is 4700 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) 4701 */ 4702 rate = le16_to_cpu(sink_rates[i]) * 200 / 10; 4703 4704 if (rate == 0) 4705 break; 4706 4707 /* 4708 * Some platforms cannot reliably drive HBR3 rates due to PHY limitations, 4709 * even if the sink advertises support. Reject any sink rates above HBR2 on 4710 * the known machines for stable output. 4711 */ 4712 if (rate > 540000 && 4713 intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2)) 4714 break; 4715 4716 intel_dp->sink_rates[i] = rate; 4717 } 4718 intel_dp->num_sink_rates = i; 4719 } 4720 4721 /* 4722 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available, 4723 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise. 4724 */ 4725 if (intel_dp->num_sink_rates) 4726 intel_dp->use_rate_select = true; 4727 else 4728 intel_dp_set_sink_rates(intel_dp); 4729 4730 intel_edp_set_data_override_rates(intel_dp); 4731 } 4732 4733 static bool 4734 intel_edp_init_dpcd(struct intel_dp *intel_dp, struct intel_connector *connector) 4735 { 4736 struct intel_display *display = to_intel_display(intel_dp); 4737 int ret; 4738 4739 /* this function is meant to be called only once */ 4740 drm_WARN_ON(display->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); 4741 4742 if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) 4743 return false; 4744 4745 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, 4746 drm_dp_is_branch(intel_dp->dpcd)); 4747 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident); 4748 4749 intel_dp->colorimetry_support = 4750 intel_dp_get_colorimetry_status(intel_dp); 4751 4752 /* 4753 * Read the eDP display control registers. 4754 * 4755 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in 4756 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it 4757 * set, but require eDP 1.4+ detection (e.g. for supported link rates 4758 * method). The display control registers should read zero if they're 4759 * not supported anyway. 4760 */ 4761 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, 4762 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == 4763 sizeof(intel_dp->edp_dpcd)) { 4764 drm_dbg_kms(display->drm, "eDP DPCD: %*ph\n", 4765 (int)sizeof(intel_dp->edp_dpcd), 4766 intel_dp->edp_dpcd); 4767 4768 intel_dp->use_max_params = intel_dp->edp_dpcd[0] < DP_EDP_14; 4769 } 4770 4771 /* 4772 * If needed, program our source OUI so we can make various Intel-specific AUX services 4773 * available (such as HDR backlight controls) 4774 */ 4775 intel_dp_init_source_oui(intel_dp); 4776 4777 /* Read the ALPM DPCD caps */ 4778 ret = drm_dp_dpcd_read_byte(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, 4779 &intel_dp->alpm_dpcd); 4780 if (ret < 0) 4781 return false; 4782 4783 /* 4784 * This has to be called after intel_dp->edp_dpcd is filled, PSR checks 4785 * for SET_POWER_CAPABLE bit in intel_dp->edp_dpcd[1] 4786 */ 4787 intel_psr_init_dpcd(intel_dp, connector); 4788 4789 intel_edp_set_sink_rates(intel_dp); 4790 intel_dp_set_max_sink_lane_count(intel_dp); 4791 4792 /* Read the eDP DSC DPCD registers */ 4793 intel_dp_detect_dsc_caps(intel_dp, connector); 4794 4795 return true; 4796 } 4797 4798 static bool 4799 intel_dp_has_sink_count(struct intel_dp *intel_dp) 4800 { 4801 if (!intel_dp->attached_connector) 4802 return false; 4803 4804 return drm_dp_read_sink_count_cap(&intel_dp->attached_connector->base, 4805 intel_dp->dpcd, 4806 &intel_dp->desc); 4807 } 4808 4809 void intel_dp_update_sink_caps(struct intel_dp *intel_dp) 4810 { 4811 intel_dp_set_sink_rates(intel_dp); 4812 intel_dp_set_max_sink_lane_count(intel_dp); 4813 intel_dp_set_common_rates(intel_dp); 4814 } 4815 4816 static bool 4817 intel_dp_get_dpcd(struct intel_dp *intel_dp) 4818 { 4819 int ret; 4820 4821 if (intel_dp_init_lttpr_and_dprx_caps(intel_dp) < 0) 4822 return false; 4823 4824 /* 4825 * Don't clobber cached eDP rates. Also skip re-reading 4826 * the OUI/ID since we know it won't change. 4827 */ 4828 if (!intel_dp_is_edp(intel_dp)) { 4829 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, 4830 drm_dp_is_branch(intel_dp->dpcd)); 4831 4832 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident); 4833 4834 intel_dp->colorimetry_support = 4835 intel_dp_get_colorimetry_status(intel_dp); 4836 4837 intel_dp_update_sink_caps(intel_dp); 4838 } 4839 4840 if (intel_dp_has_sink_count(intel_dp)) { 4841 ret = drm_dp_read_sink_count(&intel_dp->aux); 4842 if (ret < 0) 4843 return false; 4844 4845 /* 4846 * Sink count can change between short pulse hpd hence 4847 * a member variable in intel_dp will track any changes 4848 * between short pulse interrupts. 4849 */ 4850 intel_dp->sink_count = ret; 4851 4852 /* 4853 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that 4854 * a dongle is present but no display. Unless we require to know 4855 * if a dongle is present or not, we don't need to update 4856 * downstream port information. So, an early return here saves 4857 * time from performing other operations which are not required. 4858 */ 4859 if (!intel_dp->sink_count) 4860 return false; 4861 } 4862 4863 return drm_dp_read_downstream_info(&intel_dp->aux, intel_dp->dpcd, 4864 intel_dp->downstream_ports) == 0; 4865 } 4866 4867 static const char *intel_dp_mst_mode_str(enum drm_dp_mst_mode mst_mode) 4868 { 4869 if (mst_mode == DRM_DP_MST) 4870 return "MST"; 4871 else if (mst_mode == DRM_DP_SST_SIDEBAND_MSG) 4872 return "SST w/ sideband messaging"; 4873 else 4874 return "SST"; 4875 } 4876 4877 static enum drm_dp_mst_mode 4878 intel_dp_mst_mode_choose(struct intel_dp *intel_dp, 4879 enum drm_dp_mst_mode sink_mst_mode) 4880 { 4881 struct intel_display *display = to_intel_display(intel_dp); 4882 4883 if (!display->params.enable_dp_mst) 4884 return DRM_DP_SST; 4885 4886 if (!intel_dp_mst_source_support(intel_dp)) 4887 return DRM_DP_SST; 4888 4889 if (sink_mst_mode == DRM_DP_SST_SIDEBAND_MSG && 4890 !(intel_dp->dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_128B132B)) 4891 return DRM_DP_SST; 4892 4893 return sink_mst_mode; 4894 } 4895 4896 static enum drm_dp_mst_mode 4897 intel_dp_mst_detect(struct intel_dp *intel_dp) 4898 { 4899 struct intel_display *display = to_intel_display(intel_dp); 4900 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 4901 enum drm_dp_mst_mode sink_mst_mode; 4902 enum drm_dp_mst_mode mst_detect; 4903 4904 sink_mst_mode = drm_dp_read_mst_cap(&intel_dp->aux, intel_dp->dpcd); 4905 4906 mst_detect = intel_dp_mst_mode_choose(intel_dp, sink_mst_mode); 4907 4908 drm_dbg_kms(display->drm, 4909 "[ENCODER:%d:%s] MST support: port: %s, sink: %s, modparam: %s -> enable: %s\n", 4910 encoder->base.base.id, encoder->base.name, 4911 str_yes_no(intel_dp_mst_source_support(intel_dp)), 4912 intel_dp_mst_mode_str(sink_mst_mode), 4913 str_yes_no(display->params.enable_dp_mst), 4914 intel_dp_mst_mode_str(mst_detect)); 4915 4916 return mst_detect; 4917 } 4918 4919 static void 4920 intel_dp_mst_configure(struct intel_dp *intel_dp) 4921 { 4922 if (!intel_dp_mst_source_support(intel_dp)) 4923 return; 4924 4925 intel_dp->is_mst = intel_dp->mst_detect != DRM_DP_SST; 4926 4927 if (intel_dp->is_mst) 4928 intel_dp_mst_prepare_probe(intel_dp); 4929 4930 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, intel_dp->is_mst); 4931 4932 /* Avoid stale info on the next detect cycle. */ 4933 intel_dp->mst_detect = DRM_DP_SST; 4934 } 4935 4936 static void 4937 intel_dp_mst_disconnect(struct intel_dp *intel_dp) 4938 { 4939 struct intel_display *display = to_intel_display(intel_dp); 4940 4941 if (!intel_dp->is_mst) 4942 return; 4943 4944 drm_dbg_kms(display->drm, 4945 "MST device may have disappeared %d vs %d\n", 4946 intel_dp->is_mst, intel_dp->mst.mgr.mst_state); 4947 intel_dp->is_mst = false; 4948 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, intel_dp->is_mst); 4949 } 4950 4951 #define INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST (DP_AUTOMATED_TEST_REQUEST | \ 4952 DP_CP_IRQ | \ 4953 DP_SINK_SPECIFIC_IRQ) 4954 4955 #define INTEL_DP_DEVICE_SERVICE_IRQ_MASK_MST (DP_CP_IRQ | \ 4956 DP_DOWN_REP_MSG_RDY | \ 4957 DP_UP_REQ_MSG_RDY) 4958 4959 #define INTEL_DP_LINK_SERVICE_IRQ_MASK_SST (RX_CAP_CHANGED | \ 4960 LINK_STATUS_CHANGED | \ 4961 HDMI_LINK_STATUS_CHANGED | \ 4962 CONNECTED_OFF_ENTRY_REQUESTED | \ 4963 DP_TUNNELING_IRQ) 4964 4965 #define INTEL_DP_LINK_SERVICE_IRQ_MASK_MST (RX_CAP_CHANGED | \ 4966 LINK_STATUS_CHANGED | \ 4967 DP_TUNNELING_IRQ) 4968 4969 static bool 4970 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *esi) 4971 { 4972 struct intel_display *display = to_intel_display(intel_dp); 4973 4974 /* 4975 * Display WA for HSD #13013007775: mtl/arl/lnl 4976 * Read the sink count and link service IRQ registers in separate 4977 * transactions to prevent disconnecting the sink on a TBT link 4978 * inadvertently. 4979 */ 4980 if (IS_DISPLAY_VER(display, 14, 20) && !display->platform.battlemage) { 4981 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, esi, 3) != 3) 4982 return false; 4983 4984 /* DP_SINK_COUNT_ESI + 3 == DP_LINK_SERVICE_IRQ_VECTOR_ESI0 */ 4985 return drm_dp_dpcd_readb(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, 4986 &esi[3]) == 1; 4987 } 4988 4989 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, esi, 4) == 4; 4990 } 4991 4992 static bool intel_dp_ack_sink_irq_esi(struct intel_dp *intel_dp, u8 esi[4]) 4993 { 4994 int retry; 4995 4996 for (retry = 0; retry < 3; retry++) { 4997 if (drm_dp_dpcd_write(&intel_dp->aux, DP_SINK_COUNT_ESI + 1, 4998 &esi[1], 3) == 3) 4999 return true; 5000 } 5001 5002 return false; 5003 } 5004 5005 /* Return %true if reading the ESI vector succeeded, %false otherwise. */ 5006 static bool intel_dp_get_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5007 { 5008 memset(esi, 0, 4); 5009 5010 /* 5011 * TODO: For DP_DPCD_REV >= 0x12 read 5012 * DP_SINK_COUNT_ESI and DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0. 5013 */ 5014 if (drm_dp_dpcd_read_data(&intel_dp->aux, DP_SINK_COUNT, esi, 2) != 0) 5015 return false; 5016 5017 if (intel_dp->dpcd[DP_DPCD_REV] < DP_DPCD_REV_12) 5018 return true; 5019 5020 /* TODO: Read DP_DEVICE_SERVICE_IRQ_VECTOR_ESI1 as well */ 5021 if (drm_dp_dpcd_read_byte(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, &esi[3]) != 0) 5022 return false; 5023 5024 return true; 5025 } 5026 5027 /* Return %true if acking the ESI vector IRQ events succeeded, %false otherwise. */ 5028 static bool intel_dp_ack_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5029 { 5030 /* 5031 * TODO: For DP_DPCD_REV >= 0x12 write 5032 * DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0 5033 */ 5034 if (drm_dp_dpcd_write_byte(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, esi[1]) != 0) 5035 return false; 5036 5037 if (intel_dp->dpcd[DP_DPCD_REV] < DP_DPCD_REV_12) 5038 return true; 5039 5040 /* TODO: Read DP_DEVICE_SERVICE_IRQ_VECTOR_ESI1 as well */ 5041 if (drm_dp_dpcd_write_byte(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, esi[3]) != 0) 5042 return false; 5043 5044 return true; 5045 } 5046 5047 /* 5048 * Return %true if reading the ESI vector and acking the ESI IRQ events succeeded, 5049 * %false otherwise. 5050 */ 5051 static bool intel_dp_get_and_ack_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5052 { 5053 struct intel_display *display = to_intel_display(intel_dp); 5054 struct intel_connector *connector = intel_dp->attached_connector; 5055 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 5056 5057 if (!intel_dp_get_sink_irq_esi_sst(intel_dp, esi)) 5058 return false; 5059 5060 drm_dbg_kms(display->drm, 5061 "[CONNECTOR:%d:%s][ENCODER:%d:%s] DPRX ESI: %4ph\n", 5062 connector->base.base.id, connector->base.name, 5063 encoder->base.base.id, encoder->base.name, 5064 esi); 5065 5066 esi[1] &= INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST; 5067 esi[3] &= INTEL_DP_LINK_SERVICE_IRQ_MASK_SST; 5068 5069 if (mem_is_zero(&esi[1], 3)) 5070 return true; 5071 5072 if (!intel_dp_ack_sink_irq_esi_sst(intel_dp, esi)) 5073 return false; 5074 5075 return true; 5076 } 5077 5078 bool 5079 intel_dp_needs_vsc_sdp(const struct intel_crtc_state *crtc_state, 5080 const struct drm_connector_state *conn_state) 5081 { 5082 /* 5083 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication 5084 * of Color Encoding Format and Content Color Gamut], in order to 5085 * sending YCBCR 420 or HDR BT.2020 signals we should use DP VSC SDP. 5086 */ 5087 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 5088 return true; 5089 5090 switch (conn_state->colorspace) { 5091 case DRM_MODE_COLORIMETRY_SYCC_601: 5092 case DRM_MODE_COLORIMETRY_OPYCC_601: 5093 case DRM_MODE_COLORIMETRY_BT2020_YCC: 5094 case DRM_MODE_COLORIMETRY_BT2020_RGB: 5095 case DRM_MODE_COLORIMETRY_BT2020_CYCC: 5096 return true; 5097 default: 5098 break; 5099 } 5100 5101 return false; 5102 } 5103 5104 static ssize_t intel_dp_as_sdp_pack(const struct drm_dp_as_sdp *as_sdp, 5105 struct dp_sdp *sdp, size_t size) 5106 { 5107 size_t length = sizeof(struct dp_sdp); 5108 5109 if (size < length) 5110 return -ENOSPC; 5111 5112 memset(sdp, 0, size); 5113 5114 /* Prepare AS (Adaptive Sync) SDP Header */ 5115 sdp->sdp_header.HB0 = 0; 5116 sdp->sdp_header.HB1 = as_sdp->sdp_type; 5117 sdp->sdp_header.HB2 = 0x02; 5118 sdp->sdp_header.HB3 = as_sdp->length; 5119 5120 /* Fill AS (Adaptive Sync) SDP Payload */ 5121 sdp->db[0] = as_sdp->mode; 5122 sdp->db[1] = as_sdp->vtotal & 0xFF; 5123 sdp->db[2] = (as_sdp->vtotal >> 8) & 0xFF; 5124 sdp->db[3] = as_sdp->target_rr & 0xFF; 5125 sdp->db[4] = (as_sdp->target_rr >> 8) & 0x3; 5126 5127 if (as_sdp->target_rr_divider) 5128 sdp->db[4] |= 0x20; 5129 5130 return length; 5131 } 5132 5133 static ssize_t 5134 intel_dp_hdr_metadata_infoframe_sdp_pack(struct intel_display *display, 5135 const struct hdmi_drm_infoframe *drm_infoframe, 5136 struct dp_sdp *sdp, 5137 size_t size) 5138 { 5139 size_t length = sizeof(struct dp_sdp); 5140 const int infoframe_size = HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE; 5141 unsigned char buf[HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE]; 5142 ssize_t len; 5143 5144 if (size < length) 5145 return -ENOSPC; 5146 5147 memset(sdp, 0, size); 5148 5149 len = hdmi_drm_infoframe_pack_only(drm_infoframe, buf, sizeof(buf)); 5150 if (len < 0) { 5151 drm_dbg_kms(display->drm, 5152 "buffer size is smaller than hdr metadata infoframe\n"); 5153 return -ENOSPC; 5154 } 5155 5156 if (len != infoframe_size) { 5157 drm_dbg_kms(display->drm, "wrong static hdr metadata size\n"); 5158 return -ENOSPC; 5159 } 5160 5161 /* 5162 * Set up the infoframe sdp packet for HDR static metadata. 5163 * Prepare VSC Header for SU as per DP 1.4a spec, 5164 * Table 2-100 and Table 2-101 5165 */ 5166 5167 /* Secondary-Data Packet ID, 00h for non-Audio INFOFRAME */ 5168 sdp->sdp_header.HB0 = 0; 5169 /* 5170 * Packet Type 80h + Non-audio INFOFRAME Type value 5171 * HDMI_INFOFRAME_TYPE_DRM: 0x87 5172 * - 80h + Non-audio INFOFRAME Type value 5173 * - InfoFrame Type: 0x07 5174 * [CTA-861-G Table-42 Dynamic Range and Mastering InfoFrame] 5175 */ 5176 sdp->sdp_header.HB1 = drm_infoframe->type; 5177 /* 5178 * Least Significant Eight Bits of (Data Byte Count – 1) 5179 * infoframe_size - 1 5180 */ 5181 sdp->sdp_header.HB2 = 0x1D; 5182 /* INFOFRAME SDP Version Number */ 5183 sdp->sdp_header.HB3 = (0x13 << 2); 5184 /* CTA Header Byte 2 (INFOFRAME Version Number) */ 5185 sdp->db[0] = drm_infoframe->version; 5186 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */ 5187 sdp->db[1] = drm_infoframe->length; 5188 /* 5189 * Copy HDMI_DRM_INFOFRAME_SIZE size from a buffer after 5190 * HDMI_INFOFRAME_HEADER_SIZE 5191 */ 5192 BUILD_BUG_ON(sizeof(sdp->db) < HDMI_DRM_INFOFRAME_SIZE + 2); 5193 memcpy(&sdp->db[2], &buf[HDMI_INFOFRAME_HEADER_SIZE], 5194 HDMI_DRM_INFOFRAME_SIZE); 5195 5196 /* 5197 * Size of DP infoframe sdp packet for HDR static metadata consists of 5198 * - DP SDP Header(struct dp_sdp_header): 4 bytes 5199 * - Two Data Blocks: 2 bytes 5200 * CTA Header Byte2 (INFOFRAME Version Number) 5201 * CTA Header Byte3 (Length of INFOFRAME) 5202 * - HDMI_DRM_INFOFRAME_SIZE: 26 bytes 5203 * 5204 * Prior to GEN11's GMP register size is identical to DP HDR static metadata 5205 * infoframe size. But GEN11+ has larger than that size, write_infoframe 5206 * will pad rest of the size. 5207 */ 5208 return sizeof(struct dp_sdp_header) + 2 + HDMI_DRM_INFOFRAME_SIZE; 5209 } 5210 5211 static void intel_write_dp_sdp(struct intel_encoder *encoder, 5212 const struct intel_crtc_state *crtc_state, 5213 unsigned int type) 5214 { 5215 struct intel_display *display = to_intel_display(encoder); 5216 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5217 struct dp_sdp sdp = {}; 5218 ssize_t len; 5219 5220 if ((crtc_state->infoframes.enable & 5221 intel_hdmi_infoframe_enable(type)) == 0) 5222 return; 5223 5224 switch (type) { 5225 case DP_SDP_VSC: 5226 len = drm_dp_vsc_sdp_pack(&crtc_state->infoframes.vsc, &sdp); 5227 break; 5228 case HDMI_PACKET_TYPE_GAMUT_METADATA: 5229 len = intel_dp_hdr_metadata_infoframe_sdp_pack(display, 5230 &crtc_state->infoframes.drm.drm, 5231 &sdp, sizeof(sdp)); 5232 break; 5233 case DP_SDP_ADAPTIVE_SYNC: 5234 len = intel_dp_as_sdp_pack(&crtc_state->infoframes.as_sdp, &sdp, 5235 sizeof(sdp)); 5236 break; 5237 default: 5238 MISSING_CASE(type); 5239 return; 5240 } 5241 5242 if (drm_WARN_ON(display->drm, len < 0)) 5243 return; 5244 5245 dig_port->write_infoframe(encoder, crtc_state, type, &sdp, len); 5246 } 5247 5248 void intel_dp_set_infoframes(struct intel_encoder *encoder, 5249 bool enable, 5250 const struct intel_crtc_state *crtc_state, 5251 const struct drm_connector_state *conn_state) 5252 { 5253 struct intel_display *display = to_intel_display(encoder); 5254 i915_reg_t reg = HSW_TVIDEO_DIP_CTL(display, crtc_state->cpu_transcoder); 5255 u32 dip_enable = VIDEO_DIP_ENABLE_AVI_HSW | VIDEO_DIP_ENABLE_GCP_HSW | 5256 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW | 5257 VIDEO_DIP_ENABLE_SPD_HSW | VIDEO_DIP_ENABLE_DRM_GLK; 5258 5259 if (HAS_AS_SDP(display)) 5260 dip_enable |= VIDEO_DIP_ENABLE_AS_ADL; 5261 5262 u32 val = intel_de_read(display, reg) & ~dip_enable; 5263 5264 /* TODO: Sanitize DSC enabling wrt. intel_dsc_dp_pps_write(). */ 5265 if (!enable && HAS_DSC(display)) 5266 val &= ~VDIP_ENABLE_PPS; 5267 5268 /* 5269 * This routine disables VSC DIP if the function is called 5270 * to disable SDP or if it does not have PSR 5271 */ 5272 if (!enable || !crtc_state->has_psr) 5273 val &= ~VIDEO_DIP_ENABLE_VSC_HSW; 5274 5275 intel_de_write(display, reg, val); 5276 intel_de_posting_read(display, reg); 5277 5278 if (!enable) 5279 return; 5280 5281 intel_write_dp_sdp(encoder, crtc_state, DP_SDP_VSC); 5282 intel_write_dp_sdp(encoder, crtc_state, DP_SDP_ADAPTIVE_SYNC); 5283 5284 intel_write_dp_sdp(encoder, crtc_state, HDMI_PACKET_TYPE_GAMUT_METADATA); 5285 } 5286 5287 static 5288 int intel_dp_as_sdp_unpack(struct drm_dp_as_sdp *as_sdp, 5289 const void *buffer, size_t size) 5290 { 5291 const struct dp_sdp *sdp = buffer; 5292 5293 if (size < sizeof(struct dp_sdp)) 5294 return -EINVAL; 5295 5296 memset(as_sdp, 0, sizeof(*as_sdp)); 5297 5298 if (sdp->sdp_header.HB0 != 0) 5299 return -EINVAL; 5300 5301 if (sdp->sdp_header.HB1 != DP_SDP_ADAPTIVE_SYNC) 5302 return -EINVAL; 5303 5304 if (sdp->sdp_header.HB2 != 0x02) 5305 return -EINVAL; 5306 5307 if ((sdp->sdp_header.HB3 & 0x3F) != 9) 5308 return -EINVAL; 5309 5310 as_sdp->length = sdp->sdp_header.HB3 & DP_ADAPTIVE_SYNC_SDP_LENGTH; 5311 as_sdp->mode = sdp->db[0] & DP_ADAPTIVE_SYNC_SDP_OPERATION_MODE; 5312 as_sdp->vtotal = (sdp->db[2] << 8) | sdp->db[1]; 5313 as_sdp->target_rr = ((sdp->db[4] & 0x3) << 8) | sdp->db[3]; 5314 as_sdp->target_rr_divider = sdp->db[4] & 0x20 ? true : false; 5315 5316 return 0; 5317 } 5318 5319 static int intel_dp_vsc_sdp_unpack(struct drm_dp_vsc_sdp *vsc, 5320 const void *buffer, size_t size) 5321 { 5322 const struct dp_sdp *sdp = buffer; 5323 5324 if (size < sizeof(struct dp_sdp)) 5325 return -EINVAL; 5326 5327 memset(vsc, 0, sizeof(*vsc)); 5328 5329 if (sdp->sdp_header.HB0 != 0) 5330 return -EINVAL; 5331 5332 if (sdp->sdp_header.HB1 != DP_SDP_VSC) 5333 return -EINVAL; 5334 5335 vsc->sdp_type = sdp->sdp_header.HB1; 5336 vsc->revision = sdp->sdp_header.HB2; 5337 vsc->length = sdp->sdp_header.HB3; 5338 5339 if ((sdp->sdp_header.HB2 == 0x2 && sdp->sdp_header.HB3 == 0x8) || 5340 (sdp->sdp_header.HB2 == 0x4 && sdp->sdp_header.HB3 == 0xe) || 5341 (sdp->sdp_header.HB2 == 0x6 && sdp->sdp_header.HB3 == 0x10)) { 5342 /* 5343 * - HB2 = 0x2, HB3 = 0x8 5344 * VSC SDP supporting 3D stereo + PSR 5345 * - HB2 = 0x4, HB3 = 0xe 5346 * VSC SDP supporting 3D stereo + PSR2 with Y-coordinate of 5347 * first scan line of the SU region (applies to eDP v1.4b 5348 * and higher). 5349 * - HB2 = 0x6, HB3 = 0x10 5350 * VSC SDP supporting 3D stereo + Panel Replay. 5351 */ 5352 return 0; 5353 } else if (sdp->sdp_header.HB2 == 0x5 && sdp->sdp_header.HB3 == 0x13) { 5354 /* 5355 * - HB2 = 0x5, HB3 = 0x13 5356 * VSC SDP supporting 3D stereo + PSR2 + Pixel Encoding/Colorimetry 5357 * Format. 5358 */ 5359 vsc->pixelformat = (sdp->db[16] >> 4) & 0xf; 5360 vsc->colorimetry = sdp->db[16] & 0xf; 5361 vsc->dynamic_range = (sdp->db[17] >> 7) & 0x1; 5362 5363 switch (sdp->db[17] & 0x7) { 5364 case 0x0: 5365 vsc->bpc = 6; 5366 break; 5367 case 0x1: 5368 vsc->bpc = 8; 5369 break; 5370 case 0x2: 5371 vsc->bpc = 10; 5372 break; 5373 case 0x3: 5374 vsc->bpc = 12; 5375 break; 5376 case 0x4: 5377 vsc->bpc = 16; 5378 break; 5379 default: 5380 MISSING_CASE(sdp->db[17] & 0x7); 5381 return -EINVAL; 5382 } 5383 5384 vsc->content_type = sdp->db[18] & 0x7; 5385 } else { 5386 return -EINVAL; 5387 } 5388 5389 return 0; 5390 } 5391 5392 static void 5393 intel_read_dp_as_sdp(struct intel_encoder *encoder, 5394 struct intel_crtc_state *crtc_state, 5395 struct drm_dp_as_sdp *as_sdp) 5396 { 5397 struct intel_display *display = to_intel_display(encoder); 5398 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5399 unsigned int type = DP_SDP_ADAPTIVE_SYNC; 5400 struct dp_sdp sdp = {}; 5401 int ret; 5402 5403 if ((crtc_state->infoframes.enable & 5404 intel_hdmi_infoframe_enable(type)) == 0) 5405 return; 5406 5407 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, 5408 sizeof(sdp)); 5409 5410 ret = intel_dp_as_sdp_unpack(as_sdp, &sdp, sizeof(sdp)); 5411 if (ret) 5412 drm_dbg_kms(display->drm, "Failed to unpack DP AS SDP\n"); 5413 } 5414 5415 static int 5416 intel_dp_hdr_metadata_infoframe_sdp_unpack(struct hdmi_drm_infoframe *drm_infoframe, 5417 const void *buffer, size_t size) 5418 { 5419 int ret; 5420 5421 const struct dp_sdp *sdp = buffer; 5422 5423 if (size < sizeof(struct dp_sdp)) 5424 return -EINVAL; 5425 5426 if (sdp->sdp_header.HB0 != 0) 5427 return -EINVAL; 5428 5429 if (sdp->sdp_header.HB1 != HDMI_INFOFRAME_TYPE_DRM) 5430 return -EINVAL; 5431 5432 /* 5433 * Least Significant Eight Bits of (Data Byte Count – 1) 5434 * 1Dh (i.e., Data Byte Count = 30 bytes). 5435 */ 5436 if (sdp->sdp_header.HB2 != 0x1D) 5437 return -EINVAL; 5438 5439 /* Most Significant Two Bits of (Data Byte Count – 1), Clear to 00b. */ 5440 if ((sdp->sdp_header.HB3 & 0x3) != 0) 5441 return -EINVAL; 5442 5443 /* INFOFRAME SDP Version Number */ 5444 if (((sdp->sdp_header.HB3 >> 2) & 0x3f) != 0x13) 5445 return -EINVAL; 5446 5447 /* CTA Header Byte 2 (INFOFRAME Version Number) */ 5448 if (sdp->db[0] != 1) 5449 return -EINVAL; 5450 5451 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */ 5452 if (sdp->db[1] != HDMI_DRM_INFOFRAME_SIZE) 5453 return -EINVAL; 5454 5455 ret = hdmi_drm_infoframe_unpack_only(drm_infoframe, &sdp->db[2], 5456 HDMI_DRM_INFOFRAME_SIZE); 5457 5458 return ret; 5459 } 5460 5461 static void intel_read_dp_vsc_sdp(struct intel_encoder *encoder, 5462 struct intel_crtc_state *crtc_state, 5463 struct drm_dp_vsc_sdp *vsc) 5464 { 5465 struct intel_display *display = to_intel_display(encoder); 5466 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5467 unsigned int type = DP_SDP_VSC; 5468 struct dp_sdp sdp = {}; 5469 int ret; 5470 5471 if ((crtc_state->infoframes.enable & 5472 intel_hdmi_infoframe_enable(type)) == 0) 5473 return; 5474 5475 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, sizeof(sdp)); 5476 5477 ret = intel_dp_vsc_sdp_unpack(vsc, &sdp, sizeof(sdp)); 5478 5479 if (ret) 5480 drm_dbg_kms(display->drm, "Failed to unpack DP VSC SDP\n"); 5481 } 5482 5483 static void intel_read_dp_hdr_metadata_infoframe_sdp(struct intel_encoder *encoder, 5484 struct intel_crtc_state *crtc_state, 5485 struct hdmi_drm_infoframe *drm_infoframe) 5486 { 5487 struct intel_display *display = to_intel_display(encoder); 5488 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5489 unsigned int type = HDMI_PACKET_TYPE_GAMUT_METADATA; 5490 struct dp_sdp sdp = {}; 5491 int ret; 5492 5493 if ((crtc_state->infoframes.enable & 5494 intel_hdmi_infoframe_enable(type)) == 0) 5495 return; 5496 5497 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, 5498 sizeof(sdp)); 5499 5500 ret = intel_dp_hdr_metadata_infoframe_sdp_unpack(drm_infoframe, &sdp, 5501 sizeof(sdp)); 5502 5503 if (ret) 5504 drm_dbg_kms(display->drm, 5505 "Failed to unpack DP HDR Metadata Infoframe SDP\n"); 5506 } 5507 5508 void intel_read_dp_sdp(struct intel_encoder *encoder, 5509 struct intel_crtc_state *crtc_state, 5510 unsigned int type) 5511 { 5512 switch (type) { 5513 case DP_SDP_VSC: 5514 intel_read_dp_vsc_sdp(encoder, crtc_state, 5515 &crtc_state->infoframes.vsc); 5516 break; 5517 case HDMI_PACKET_TYPE_GAMUT_METADATA: 5518 intel_read_dp_hdr_metadata_infoframe_sdp(encoder, crtc_state, 5519 &crtc_state->infoframes.drm.drm); 5520 break; 5521 case DP_SDP_ADAPTIVE_SYNC: 5522 intel_read_dp_as_sdp(encoder, crtc_state, 5523 &crtc_state->infoframes.as_sdp); 5524 break; 5525 default: 5526 MISSING_CASE(type); 5527 break; 5528 } 5529 } 5530 5531 static bool intel_dp_link_ok(struct intel_dp *intel_dp, 5532 u8 link_status[DP_LINK_STATUS_SIZE]) 5533 { 5534 struct intel_display *display = to_intel_display(intel_dp); 5535 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 5536 bool uhbr = intel_dp->link_rate >= 1000000; 5537 bool ok; 5538 5539 if (uhbr) 5540 ok = drm_dp_128b132b_lane_channel_eq_done(link_status, 5541 intel_dp->lane_count); 5542 else 5543 ok = drm_dp_channel_eq_ok(link_status, intel_dp->lane_count); 5544 5545 if (ok) 5546 return true; 5547 5548 intel_dp_dump_link_status(intel_dp, DP_PHY_DPRX, link_status); 5549 drm_dbg_kms(display->drm, 5550 "[ENCODER:%d:%s] %s link not ok, retraining\n", 5551 encoder->base.base.id, encoder->base.name, 5552 uhbr ? "128b/132b" : "8b/10b"); 5553 5554 return false; 5555 } 5556 5557 static void 5558 intel_dp_mst_hpd_irq(struct intel_dp *intel_dp, u8 *esi, u8 *ack) 5559 { 5560 bool handled = false; 5561 5562 drm_dp_mst_hpd_irq_handle_event(&intel_dp->mst.mgr, esi, ack, &handled); 5563 5564 if (esi[1] & DP_CP_IRQ) { 5565 intel_hdcp_handle_cp_irq(intel_dp->attached_connector); 5566 ack[1] |= DP_CP_IRQ; 5567 } 5568 } 5569 5570 static bool intel_dp_handle_link_service_irq(struct intel_dp *intel_dp, u8 irq_mask); 5571 5572 /** 5573 * intel_dp_check_mst_status - service any pending MST interrupts, check link status 5574 * @intel_dp: Intel DP struct 5575 * 5576 * Read any pending MST interrupts, call MST core to handle these and ack the 5577 * interrupts. Check if the main and AUX link state is ok. 5578 * 5579 * Returns: 5580 * - %true if pending interrupts were serviced (or no interrupts were 5581 * pending) w/o detecting an error condition. 5582 * - %false if an error condition - like AUX failure or a loss of link - is 5583 * detected, or another condition - like a DP tunnel BW state change - needs 5584 * servicing from the hotplug work. 5585 */ 5586 static bool 5587 intel_dp_check_mst_status(struct intel_dp *intel_dp) 5588 { 5589 struct intel_display *display = to_intel_display(intel_dp); 5590 bool force_retrain = intel_dp->link.force_retrain; 5591 bool reprobe_needed = false; 5592 5593 for (;;) { 5594 u8 esi[4] = {}; 5595 u8 ack[4] = {}; 5596 bool new_irqs; 5597 5598 if (!intel_dp_get_sink_irq_esi(intel_dp, esi)) { 5599 drm_dbg_kms(display->drm, 5600 "failed to get ESI - device may have failed\n"); 5601 reprobe_needed = true; 5602 5603 break; 5604 } 5605 5606 drm_dbg_kms(display->drm, "DPRX ESI: %4ph\n", esi); 5607 5608 ack[3] |= esi[3] & INTEL_DP_LINK_SERVICE_IRQ_MASK_MST; 5609 5610 intel_dp_mst_hpd_irq(intel_dp, esi, ack); 5611 5612 new_irqs = !mem_is_zero(ack, sizeof(ack)); 5613 5614 drm_WARN_ON(display->drm, ack[1] & ~INTEL_DP_DEVICE_SERVICE_IRQ_MASK_MST); 5615 drm_WARN_ON(display->drm, ack[3] & ~INTEL_DP_LINK_SERVICE_IRQ_MASK_MST); 5616 5617 if (new_irqs && !intel_dp_ack_sink_irq_esi(intel_dp, ack)) 5618 drm_dbg_kms(display->drm, "Failed to ack ESI\n"); 5619 5620 if (ack[1] & (DP_DOWN_REP_MSG_RDY | DP_UP_REQ_MSG_RDY)) 5621 drm_dp_mst_hpd_irq_send_new_request(&intel_dp->mst.mgr); 5622 5623 if (force_retrain) { 5624 /* Defer forced retraining to the regular link status check. */ 5625 ack[3] |= LINK_STATUS_CHANGED; 5626 force_retrain = false; 5627 } 5628 5629 if (intel_dp_handle_link_service_irq(intel_dp, ack[3])) 5630 reprobe_needed = true; 5631 5632 if (!new_irqs) 5633 break; 5634 } 5635 5636 return !reprobe_needed; 5637 } 5638 5639 static void 5640 intel_dp_handle_hdmi_link_status_change(struct intel_dp *intel_dp) 5641 { 5642 bool is_active; 5643 u8 buf = 0; 5644 5645 is_active = drm_dp_pcon_hdmi_link_active(&intel_dp->aux); 5646 if (intel_dp->frl.is_trained && !is_active) { 5647 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, &buf) < 0) 5648 return; 5649 5650 buf &= ~DP_PCON_ENABLE_HDMI_LINK; 5651 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf) < 0) 5652 return; 5653 5654 drm_dp_pcon_hdmi_frl_link_error_count(&intel_dp->aux, &intel_dp->attached_connector->base); 5655 5656 intel_dp->frl.is_trained = false; 5657 5658 /* Restart FRL training or fall back to TMDS mode */ 5659 intel_dp_check_frl_training(intel_dp); 5660 } 5661 } 5662 5663 static int 5664 intel_dp_read_link_status(struct intel_dp *intel_dp, u8 link_status[DP_LINK_STATUS_SIZE]) 5665 { 5666 int err; 5667 5668 memset(link_status, 0, DP_LINK_STATUS_SIZE); 5669 5670 if (intel_dp_mst_active_streams(intel_dp) > 0) 5671 err = drm_dp_dpcd_read_data(&intel_dp->aux, DP_LANE0_1_STATUS_ESI, 5672 link_status, DP_LINK_STATUS_SIZE - 2); 5673 else 5674 err = drm_dp_dpcd_read_phy_link_status(&intel_dp->aux, DP_PHY_DPRX, 5675 link_status); 5676 5677 if (err) 5678 return err; 5679 5680 if (link_status[DP_LANE_ALIGN_STATUS_UPDATED - DP_LANE0_1_STATUS] & 5681 DP_DOWNSTREAM_PORT_STATUS_CHANGED) 5682 WRITE_ONCE(intel_dp->downstream_port_changed, true); 5683 5684 return 0; 5685 } 5686 5687 static bool 5688 intel_dp_needs_link_retrain(struct intel_dp *intel_dp) 5689 { 5690 u8 link_status[DP_LINK_STATUS_SIZE]; 5691 5692 if (!intel_dp->link.active) 5693 return false; 5694 5695 /* 5696 * While PSR source HW is enabled, it will control main-link sending 5697 * frames, enabling and disabling it so trying to do a retrain will fail 5698 * as the link would or not be on or it could mix training patterns 5699 * and frame data at the same time causing retrain to fail. 5700 * Also when exiting PSR, HW will retrain the link anyways fixing 5701 * any link status error. 5702 */ 5703 if (intel_psr_enabled(intel_dp)) 5704 return false; 5705 5706 if (intel_dp->link.force_retrain) 5707 return true; 5708 5709 if (intel_dp_read_link_status(intel_dp, link_status) < 0) 5710 return false; 5711 5712 /* 5713 * Validate the cached values of intel_dp->link_rate and 5714 * intel_dp->lane_count before attempting to retrain. 5715 * 5716 * FIXME would be nice to user the crtc state here, but since 5717 * we need to call this from the short HPD handler that seems 5718 * a bit hard. 5719 */ 5720 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate, 5721 intel_dp->lane_count)) 5722 return false; 5723 5724 if (intel_dp->link.retrain_disabled) 5725 return false; 5726 5727 if (intel_dp->link.seq_train_failures) 5728 return true; 5729 5730 /* Retrain if link not ok */ 5731 return !intel_dp_link_ok(intel_dp, link_status) && 5732 !intel_psr_link_ok(intel_dp); 5733 } 5734 5735 bool intel_dp_has_connector(struct intel_dp *intel_dp, 5736 const struct drm_connector_state *conn_state) 5737 { 5738 struct intel_display *display = to_intel_display(intel_dp); 5739 struct intel_encoder *encoder; 5740 enum pipe pipe; 5741 5742 if (!conn_state->best_encoder) 5743 return false; 5744 5745 /* SST */ 5746 encoder = &dp_to_dig_port(intel_dp)->base; 5747 if (conn_state->best_encoder == &encoder->base) 5748 return true; 5749 5750 /* MST */ 5751 for_each_pipe(display, pipe) { 5752 encoder = &intel_dp->mst.stream_encoders[pipe]->base; 5753 if (conn_state->best_encoder == &encoder->base) 5754 return true; 5755 } 5756 5757 return false; 5758 } 5759 5760 static void wait_for_connector_hw_done(const struct drm_connector_state *conn_state) 5761 { 5762 struct intel_connector *connector = to_intel_connector(conn_state->connector); 5763 struct intel_display *display = to_intel_display(connector); 5764 5765 drm_modeset_lock_assert_held(&display->drm->mode_config.connection_mutex); 5766 5767 if (!conn_state->commit) 5768 return; 5769 5770 drm_WARN_ON(display->drm, 5771 !wait_for_completion_timeout(&conn_state->commit->hw_done, 5772 msecs_to_jiffies(5000))); 5773 } 5774 5775 int intel_dp_get_active_pipes(struct intel_dp *intel_dp, 5776 struct drm_modeset_acquire_ctx *ctx, 5777 u8 *pipe_mask) 5778 { 5779 struct intel_display *display = to_intel_display(intel_dp); 5780 struct drm_connector_list_iter conn_iter; 5781 struct intel_connector *connector; 5782 int ret = 0; 5783 5784 *pipe_mask = 0; 5785 5786 drm_connector_list_iter_begin(display->drm, &conn_iter); 5787 for_each_intel_connector_iter(connector, &conn_iter) { 5788 struct drm_connector_state *conn_state = 5789 connector->base.state; 5790 struct intel_crtc_state *crtc_state; 5791 struct intel_crtc *crtc; 5792 5793 if (!intel_dp_has_connector(intel_dp, conn_state)) 5794 continue; 5795 5796 crtc = to_intel_crtc(conn_state->crtc); 5797 if (!crtc) 5798 continue; 5799 5800 ret = drm_modeset_lock(&crtc->base.mutex, ctx); 5801 if (ret) 5802 break; 5803 5804 crtc_state = to_intel_crtc_state(crtc->base.state); 5805 5806 drm_WARN_ON(display->drm, 5807 !intel_crtc_has_dp_encoder(crtc_state)); 5808 5809 if (!crtc_state->hw.active) 5810 continue; 5811 5812 wait_for_connector_hw_done(conn_state); 5813 5814 *pipe_mask |= BIT(crtc->pipe); 5815 } 5816 drm_connector_list_iter_end(&conn_iter); 5817 5818 return ret; 5819 } 5820 5821 void intel_dp_flush_connector_commits(struct intel_connector *connector) 5822 { 5823 wait_for_connector_hw_done(connector->base.state); 5824 } 5825 5826 static bool intel_dp_is_connected(struct intel_dp *intel_dp) 5827 { 5828 struct intel_connector *connector = intel_dp->attached_connector; 5829 5830 return connector->base.status == connector_status_connected || 5831 intel_dp->is_mst; 5832 } 5833 5834 static int intel_dp_retrain_link(struct intel_encoder *encoder, 5835 struct drm_modeset_acquire_ctx *ctx) 5836 { 5837 struct intel_display *display = to_intel_display(encoder); 5838 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 5839 u8 pipe_mask; 5840 int ret; 5841 5842 if (!intel_dp_is_connected(intel_dp)) 5843 return 0; 5844 5845 ret = drm_modeset_lock(&display->drm->mode_config.connection_mutex, 5846 ctx); 5847 if (ret) 5848 return ret; 5849 5850 if (!intel_dp_needs_link_retrain(intel_dp)) 5851 return 0; 5852 5853 ret = intel_dp_get_active_pipes(intel_dp, ctx, &pipe_mask); 5854 if (ret) 5855 return ret; 5856 5857 if (pipe_mask == 0) 5858 return 0; 5859 5860 if (!intel_dp_needs_link_retrain(intel_dp)) 5861 return 0; 5862 5863 drm_dbg_kms(display->drm, 5864 "[ENCODER:%d:%s] retraining link (forced %s)\n", 5865 encoder->base.base.id, encoder->base.name, 5866 str_yes_no(intel_dp->link.force_retrain)); 5867 5868 ret = intel_modeset_commit_pipes(display, pipe_mask, ctx); 5869 if (ret == -EDEADLK) 5870 return ret; 5871 5872 intel_dp->link.force_retrain = false; 5873 5874 if (ret) 5875 drm_dbg_kms(display->drm, 5876 "[ENCODER:%d:%s] link retraining failed: %pe\n", 5877 encoder->base.base.id, encoder->base.name, 5878 ERR_PTR(ret)); 5879 5880 return ret; 5881 } 5882 5883 void intel_dp_link_check(struct intel_encoder *encoder) 5884 { 5885 struct drm_modeset_acquire_ctx ctx; 5886 int ret; 5887 5888 intel_modeset_lock_ctx_retry(&ctx, NULL, 0, ret) 5889 ret = intel_dp_retrain_link(encoder, &ctx); 5890 } 5891 5892 void intel_dp_check_link_state(struct intel_dp *intel_dp) 5893 { 5894 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 5895 struct intel_encoder *encoder = &dig_port->base; 5896 5897 if (!intel_dp_is_connected(intel_dp)) 5898 return; 5899 5900 if (!intel_dp_needs_link_retrain(intel_dp)) 5901 return; 5902 5903 intel_encoder_link_check_queue_work(encoder, 0); 5904 } 5905 5906 static void intel_dp_handle_device_service_irq(struct intel_dp *intel_dp, u8 irq_mask) 5907 { 5908 struct intel_display *display = to_intel_display(intel_dp); 5909 5910 drm_WARN_ON(display->drm, irq_mask & ~INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST); 5911 5912 if (irq_mask & DP_AUTOMATED_TEST_REQUEST) 5913 intel_dp_test_request(intel_dp); 5914 5915 if (irq_mask & DP_CP_IRQ) 5916 intel_hdcp_handle_cp_irq(intel_dp->attached_connector); 5917 5918 if (irq_mask & DP_SINK_SPECIFIC_IRQ) 5919 drm_dbg_kms(display->drm, "Sink specific irq unhandled\n"); 5920 } 5921 5922 5923 /* 5924 * Return %true if a full connector reprobe is required after handling a link 5925 * service IRQ event. 5926 */ 5927 static bool intel_dp_handle_link_service_irq(struct intel_dp *intel_dp, u8 irq_mask) 5928 { 5929 struct intel_display *display = to_intel_display(intel_dp); 5930 struct intel_connector *connector = intel_dp->attached_connector; 5931 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 5932 bool reprobe_needed = false; 5933 5934 drm_WARN_ON(display->drm, irq_mask & ~(INTEL_DP_LINK_SERVICE_IRQ_MASK_SST | 5935 INTEL_DP_LINK_SERVICE_IRQ_MASK_MST)); 5936 5937 if (irq_mask & RX_CAP_CHANGED) 5938 reprobe_needed = true; 5939 5940 if (irq_mask & LINK_STATUS_CHANGED) 5941 intel_dp_check_link_state(intel_dp); 5942 5943 if (irq_mask & HDMI_LINK_STATUS_CHANGED) 5944 intel_dp_handle_hdmi_link_status_change(intel_dp); 5945 5946 if (irq_mask & CONNECTED_OFF_ENTRY_REQUESTED) 5947 drm_dbg_kms(display->drm, 5948 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Allowing connected off request\n", 5949 connector->base.base.id, connector->base.name, 5950 encoder->base.base.id, encoder->base.name); 5951 5952 if ((irq_mask & DP_TUNNELING_IRQ) && 5953 drm_dp_tunnel_handle_irq(display->dp_tunnel_mgr, 5954 &intel_dp->aux)) 5955 reprobe_needed = true; 5956 5957 return reprobe_needed; 5958 } 5959 5960 /* 5961 * According to DP spec 5962 * 5.1.2: 5963 * 1. Read DPCD 5964 * 2. Configure link according to Receiver Capabilities 5965 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 5966 * 4. Check link status on receipt of hot-plug interrupt 5967 * 5968 * intel_dp_short_pulse - handles short pulse interrupts 5969 * when full detection is not required. 5970 * Returns %true if short pulse is handled and full detection 5971 * is NOT required and %false otherwise. 5972 */ 5973 static bool 5974 intel_dp_short_pulse(struct intel_dp *intel_dp) 5975 { 5976 bool reprobe_needed = false; 5977 u8 esi[4] = {}; 5978 5979 intel_dp_test_reset(intel_dp); 5980 5981 if (!intel_dp_get_and_ack_sink_irq_esi_sst(intel_dp, esi)) 5982 return false; 5983 5984 /* 5985 * If the current value of sink count doesn't match with 5986 * the value that was stored earlier we need to do full 5987 * detection. 5988 */ 5989 if (intel_dp_has_sink_count(intel_dp) && 5990 DP_GET_SINK_COUNT(esi[0]) != intel_dp->sink_count) 5991 /* No need to proceed if we are going to do full detect */ 5992 return false; 5993 5994 intel_dp_handle_device_service_irq(intel_dp, esi[1]); 5995 5996 /* 5997 * Force checking the link status for DPCD_REV < 1.2 5998 * TODO: let the link status check depend on LINK_STATUS_CHANGED 5999 * or intel_dp->link.force_retrain for DPCD_REV >= 1.2 6000 */ 6001 esi[3] |= LINK_STATUS_CHANGED; 6002 if (intel_dp_handle_link_service_irq(intel_dp, esi[3])) 6003 reprobe_needed = true; 6004 6005 /* Handle CEC interrupts, if any */ 6006 drm_dp_cec_irq(&intel_dp->aux); 6007 6008 if (READ_ONCE(intel_dp->downstream_port_changed)) { 6009 WRITE_ONCE(intel_dp->downstream_port_changed, false); 6010 reprobe_needed = true; 6011 } 6012 6013 intel_psr_short_pulse(intel_dp); 6014 6015 if (intel_alpm_get_error(intel_dp)) { 6016 intel_alpm_disable(intel_dp); 6017 intel_dp->alpm.sink_alpm_error = true; 6018 } 6019 6020 if (intel_dp_test_short_pulse(intel_dp)) 6021 reprobe_needed = true; 6022 6023 return !reprobe_needed; 6024 } 6025 6026 /* XXX this is probably wrong for multiple downstream ports */ 6027 static enum drm_connector_status 6028 intel_dp_detect_dpcd(struct intel_dp *intel_dp) 6029 { 6030 struct intel_display *display = to_intel_display(intel_dp); 6031 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 6032 u8 *dpcd = intel_dp->dpcd; 6033 u8 type; 6034 6035 if (drm_WARN_ON(display->drm, intel_dp_is_edp(intel_dp))) 6036 return connector_status_connected; 6037 6038 WRITE_ONCE(intel_dp->downstream_port_changed, false); 6039 6040 intel_lspcon_resume(dig_port); 6041 6042 if (!intel_dp_get_dpcd(intel_dp)) 6043 return connector_status_disconnected; 6044 6045 intel_dp->mst_detect = intel_dp_mst_detect(intel_dp); 6046 6047 /* if there's no downstream port, we're done */ 6048 if (!drm_dp_is_branch(dpcd)) 6049 return connector_status_connected; 6050 6051 /* If we're HPD-aware, SINK_COUNT changes dynamically */ 6052 if (intel_dp_has_sink_count(intel_dp) && 6053 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { 6054 return intel_dp->sink_count ? 6055 connector_status_connected : connector_status_disconnected; 6056 } 6057 6058 if (intel_dp->mst_detect == DRM_DP_MST) 6059 return connector_status_connected; 6060 6061 /* If no HPD, poke DDC gently */ 6062 if (drm_probe_ddc(&intel_dp->aux.ddc)) 6063 return connector_status_connected; 6064 6065 /* Well we tried, say unknown for unreliable port types */ 6066 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { 6067 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; 6068 if (type == DP_DS_PORT_TYPE_VGA || 6069 type == DP_DS_PORT_TYPE_NON_EDID) 6070 return connector_status_unknown; 6071 } else { 6072 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & 6073 DP_DWN_STRM_PORT_TYPE_MASK; 6074 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || 6075 type == DP_DWN_STRM_PORT_TYPE_OTHER) 6076 return connector_status_unknown; 6077 } 6078 6079 /* Anything else is out of spec, warn and ignore */ 6080 drm_dbg_kms(display->drm, "Broken DP branch device, ignoring\n"); 6081 return connector_status_disconnected; 6082 } 6083 6084 static enum drm_connector_status 6085 edp_detect(struct intel_dp *intel_dp) 6086 { 6087 return connector_status_connected; 6088 } 6089 6090 void intel_digital_port_lock(struct intel_encoder *encoder) 6091 { 6092 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6093 6094 if (dig_port->lock) 6095 dig_port->lock(dig_port); 6096 } 6097 6098 void intel_digital_port_unlock(struct intel_encoder *encoder) 6099 { 6100 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6101 6102 if (dig_port->unlock) 6103 dig_port->unlock(dig_port); 6104 } 6105 6106 /* 6107 * intel_digital_port_connected_locked - is the specified port connected? 6108 * @encoder: intel_encoder 6109 * 6110 * In cases where there's a connector physically connected but it can't be used 6111 * by our hardware we also return false, since the rest of the driver should 6112 * pretty much treat the port as disconnected. This is relevant for type-C 6113 * (starting on ICL) where there's ownership involved. 6114 * 6115 * The caller must hold the lock acquired by calling intel_digital_port_lock() 6116 * when calling this function. 6117 * 6118 * Return %true if port is connected, %false otherwise. 6119 */ 6120 bool intel_digital_port_connected_locked(struct intel_encoder *encoder) 6121 { 6122 struct intel_display *display = to_intel_display(encoder); 6123 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6124 bool is_glitch_free = intel_tc_port_handles_hpd_glitches(dig_port); 6125 bool is_connected = false; 6126 6127 with_intel_display_power(display, POWER_DOMAIN_DISPLAY_CORE) { 6128 poll_timeout_us(is_connected = dig_port->connected(encoder), 6129 is_connected || is_glitch_free, 6130 30, 4000, false); 6131 } 6132 6133 return is_connected; 6134 } 6135 6136 bool intel_digital_port_connected(struct intel_encoder *encoder) 6137 { 6138 bool ret; 6139 6140 intel_digital_port_lock(encoder); 6141 ret = intel_digital_port_connected_locked(encoder); 6142 intel_digital_port_unlock(encoder); 6143 6144 return ret; 6145 } 6146 6147 static const struct drm_edid * 6148 intel_dp_get_edid(struct intel_dp *intel_dp) 6149 { 6150 struct intel_connector *connector = intel_dp->attached_connector; 6151 const struct drm_edid *fixed_edid = connector->panel.fixed_edid; 6152 6153 /* Use panel fixed edid if we have one */ 6154 if (fixed_edid) { 6155 /* invalid edid */ 6156 if (IS_ERR(fixed_edid)) 6157 return NULL; 6158 6159 return drm_edid_dup(fixed_edid); 6160 } 6161 6162 return drm_edid_read_ddc(&connector->base, &intel_dp->aux.ddc); 6163 } 6164 6165 static void 6166 intel_dp_update_dfp(struct intel_dp *intel_dp, 6167 const struct drm_edid *drm_edid) 6168 { 6169 struct intel_display *display = to_intel_display(intel_dp); 6170 struct intel_connector *connector = intel_dp->attached_connector; 6171 6172 intel_dp->dfp.max_bpc = 6173 drm_dp_downstream_max_bpc(intel_dp->dpcd, 6174 intel_dp->downstream_ports, drm_edid); 6175 6176 intel_dp->dfp.max_dotclock = 6177 drm_dp_downstream_max_dotclock(intel_dp->dpcd, 6178 intel_dp->downstream_ports); 6179 6180 intel_dp->dfp.min_tmds_clock = 6181 drm_dp_downstream_min_tmds_clock(intel_dp->dpcd, 6182 intel_dp->downstream_ports, 6183 drm_edid); 6184 intel_dp->dfp.max_tmds_clock = 6185 drm_dp_downstream_max_tmds_clock(intel_dp->dpcd, 6186 intel_dp->downstream_ports, 6187 drm_edid); 6188 6189 intel_dp->dfp.pcon_max_frl_bw = 6190 drm_dp_get_pcon_max_frl_bw(intel_dp->dpcd, 6191 intel_dp->downstream_ports); 6192 6193 drm_dbg_kms(display->drm, 6194 "[CONNECTOR:%d:%s] DFP max bpc %d, max dotclock %d, TMDS clock %d-%d, PCON Max FRL BW %dGbps\n", 6195 connector->base.base.id, connector->base.name, 6196 intel_dp->dfp.max_bpc, 6197 intel_dp->dfp.max_dotclock, 6198 intel_dp->dfp.min_tmds_clock, 6199 intel_dp->dfp.max_tmds_clock, 6200 intel_dp->dfp.pcon_max_frl_bw); 6201 6202 intel_dp_get_pcon_dsc_cap(intel_dp); 6203 } 6204 6205 static bool 6206 intel_dp_can_ycbcr420(struct intel_dp *intel_dp) 6207 { 6208 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420) && 6209 (!drm_dp_is_branch(intel_dp->dpcd) || intel_dp->dfp.ycbcr420_passthrough)) 6210 return true; 6211 6212 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_RGB) && 6213 dfp_can_convert_from_rgb(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420)) 6214 return true; 6215 6216 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR444) && 6217 dfp_can_convert_from_ycbcr444(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420)) 6218 return true; 6219 6220 return false; 6221 } 6222 6223 static void 6224 intel_dp_update_420(struct intel_dp *intel_dp) 6225 { 6226 struct intel_display *display = to_intel_display(intel_dp); 6227 struct intel_connector *connector = intel_dp->attached_connector; 6228 6229 intel_dp->dfp.ycbcr420_passthrough = 6230 drm_dp_downstream_420_passthrough(intel_dp->dpcd, 6231 intel_dp->downstream_ports); 6232 /* on-board LSPCON always assumed to support 4:4:4->4:2:0 conversion */ 6233 intel_dp->dfp.ycbcr_444_to_420 = 6234 intel_lspcon_active(dp_to_dig_port(intel_dp)) || 6235 drm_dp_downstream_444_to_420_conversion(intel_dp->dpcd, 6236 intel_dp->downstream_ports); 6237 intel_dp->dfp.rgb_to_ycbcr = 6238 drm_dp_downstream_rgb_to_ycbcr_conversion(intel_dp->dpcd, 6239 intel_dp->downstream_ports, 6240 DP_DS_HDMI_BT709_RGB_YCBCR_CONV); 6241 6242 connector->base.ycbcr_420_allowed = intel_dp_can_ycbcr420(intel_dp); 6243 6244 drm_dbg_kms(display->drm, 6245 "[CONNECTOR:%d:%s] RGB->YcbCr conversion? %s, YCbCr 4:2:0 allowed? %s, YCbCr 4:4:4->4:2:0 conversion? %s\n", 6246 connector->base.base.id, connector->base.name, 6247 str_yes_no(intel_dp->dfp.rgb_to_ycbcr), 6248 str_yes_no(connector->base.ycbcr_420_allowed), 6249 str_yes_no(intel_dp->dfp.ycbcr_444_to_420)); 6250 } 6251 6252 static void 6253 intel_dp_set_edid(struct intel_dp *intel_dp) 6254 { 6255 struct intel_display *display = to_intel_display(intel_dp); 6256 struct intel_connector *connector = intel_dp->attached_connector; 6257 const struct drm_edid *drm_edid; 6258 bool vrr_capable; 6259 6260 intel_dp_unset_edid(intel_dp); 6261 drm_edid = intel_dp_get_edid(intel_dp); 6262 connector->detect_edid = drm_edid; 6263 6264 /* Below we depend on display info having been updated */ 6265 drm_edid_connector_update(&connector->base, drm_edid); 6266 6267 vrr_capable = intel_vrr_is_capable(connector); 6268 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s] VRR capable: %s\n", 6269 connector->base.base.id, connector->base.name, str_yes_no(vrr_capable)); 6270 drm_connector_set_vrr_capable_property(&connector->base, vrr_capable); 6271 6272 intel_dp_update_dfp(intel_dp, drm_edid); 6273 intel_dp_update_420(intel_dp); 6274 6275 drm_dp_cec_attach(&intel_dp->aux, 6276 connector->base.display_info.source_physical_address); 6277 } 6278 6279 static void 6280 intel_dp_unset_edid(struct intel_dp *intel_dp) 6281 { 6282 struct intel_connector *connector = intel_dp->attached_connector; 6283 6284 drm_dp_cec_unset_edid(&intel_dp->aux); 6285 drm_edid_free(connector->detect_edid); 6286 connector->detect_edid = NULL; 6287 6288 intel_dp->dfp.max_bpc = 0; 6289 intel_dp->dfp.max_dotclock = 0; 6290 intel_dp->dfp.min_tmds_clock = 0; 6291 intel_dp->dfp.max_tmds_clock = 0; 6292 6293 intel_dp->dfp.pcon_max_frl_bw = 0; 6294 6295 intel_dp->dfp.ycbcr_444_to_420 = false; 6296 connector->base.ycbcr_420_allowed = false; 6297 6298 drm_connector_set_vrr_capable_property(&connector->base, 6299 false); 6300 } 6301 6302 static void 6303 intel_dp_detect_sdp_caps(struct intel_dp *intel_dp) 6304 { 6305 struct intel_display *display = to_intel_display(intel_dp); 6306 6307 intel_dp->as_sdp_supported = HAS_AS_SDP(display) && 6308 drm_dp_as_sdp_supported(&intel_dp->aux, intel_dp->dpcd); 6309 } 6310 6311 static bool intel_dp_needs_dpcd_probe(struct intel_dp *intel_dp, bool force_on_external) 6312 { 6313 struct intel_connector *connector = intel_dp->attached_connector; 6314 6315 if (intel_dp_is_edp(intel_dp)) 6316 return false; 6317 6318 if (force_on_external) 6319 return true; 6320 6321 if (intel_dp->is_mst) 6322 return false; 6323 6324 return drm_edid_has_quirk(&connector->base, DRM_EDID_QUIRK_DP_DPCD_PROBE); 6325 } 6326 6327 void intel_dp_dpcd_set_probe(struct intel_dp *intel_dp, bool force_on_external) 6328 { 6329 drm_dp_dpcd_set_probe(&intel_dp->aux, 6330 intel_dp_needs_dpcd_probe(intel_dp, force_on_external)); 6331 } 6332 6333 static int 6334 intel_dp_detect(struct drm_connector *_connector, 6335 struct drm_modeset_acquire_ctx *ctx, 6336 bool force) 6337 { 6338 struct intel_display *display = to_intel_display(_connector->dev); 6339 struct intel_connector *connector = to_intel_connector(_connector); 6340 struct intel_dp *intel_dp = intel_attached_dp(connector); 6341 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 6342 struct intel_encoder *encoder = &dig_port->base; 6343 enum drm_connector_status status; 6344 int ret; 6345 6346 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s]\n", 6347 connector->base.base.id, connector->base.name); 6348 drm_WARN_ON(display->drm, 6349 !drm_modeset_is_locked(&display->drm->mode_config.connection_mutex)); 6350 6351 if (!intel_display_device_enabled(display)) 6352 return connector_status_disconnected; 6353 6354 if (!intel_display_driver_check_access(display)) 6355 return connector->base.status; 6356 6357 intel_dp_flush_connector_commits(connector); 6358 6359 intel_pps_vdd_on(intel_dp); 6360 6361 /* Can't disconnect eDP */ 6362 if (intel_dp_is_edp(intel_dp)) 6363 status = edp_detect(intel_dp); 6364 else if (intel_digital_port_connected(encoder)) 6365 status = intel_dp_detect_dpcd(intel_dp); 6366 else 6367 status = connector_status_disconnected; 6368 6369 if (status != connector_status_disconnected && 6370 !intel_dp_mst_verify_dpcd_state(intel_dp)) 6371 /* 6372 * This requires retrying detection for instance to re-enable 6373 * the MST mode that got reset via a long HPD pulse. The retry 6374 * will happen either via the hotplug handler's retry logic, 6375 * ensured by setting the connector here to SST/disconnected, 6376 * or via a userspace connector probing in response to the 6377 * hotplug uevent sent when removing the MST connectors. 6378 */ 6379 status = connector_status_disconnected; 6380 6381 if (status == connector_status_disconnected) { 6382 intel_dp_test_reset(intel_dp); 6383 /* 6384 * FIXME: Resetting these caps here cause 6385 * state computation fail if the connector need to be 6386 * modeset after sink disconnect. Move resetting them 6387 * to where new sink is connected. 6388 */ 6389 memset(connector->dp.dsc_dpcd, 0, sizeof(connector->dp.dsc_dpcd)); 6390 memset(connector->dp.panel_replay_caps.dpcd, 0, 6391 sizeof(connector->dp.panel_replay_caps.dpcd)); 6392 intel_dp->psr.sink_panel_replay_support = false; 6393 connector->dp.panel_replay_caps.support = false; 6394 connector->dp.panel_replay_caps.su_support = false; 6395 connector->dp.panel_replay_caps.dsc_support = 6396 INTEL_DP_PANEL_REPLAY_DSC_NOT_SUPPORTED; 6397 6398 intel_dp_mst_disconnect(intel_dp); 6399 6400 intel_dp_tunnel_disconnect(intel_dp); 6401 6402 goto out_unset_edid; 6403 } 6404 6405 intel_dp_init_source_oui(intel_dp); 6406 6407 ret = intel_dp_tunnel_detect(intel_dp, ctx); 6408 if (ret == -EDEADLK) { 6409 status = ret; 6410 6411 goto out_vdd_off; 6412 } 6413 6414 if (ret == 1) 6415 connector->base.epoch_counter++; 6416 6417 if (!intel_dp_is_edp(intel_dp)) 6418 intel_psr_init_dpcd(intel_dp, connector); 6419 6420 intel_dp_detect_dsc_caps(intel_dp, connector); 6421 6422 intel_dp_detect_sdp_caps(intel_dp); 6423 6424 if (intel_dp->reset_link_params) { 6425 intel_dp_reset_link_params(intel_dp); 6426 intel_dp->reset_link_params = false; 6427 } 6428 6429 intel_dp_mst_configure(intel_dp); 6430 6431 intel_dp_print_rates(intel_dp); 6432 6433 if (intel_dp->is_mst) { 6434 /* 6435 * If we are in MST mode then this connector 6436 * won't appear connected or have anything 6437 * with EDID on it 6438 */ 6439 status = connector_status_disconnected; 6440 goto out_unset_edid; 6441 } 6442 6443 /* 6444 * Some external monitors do not signal loss of link synchronization 6445 * with an IRQ_HPD, so force a link status check. 6446 * 6447 * TODO: this probably became redundant, so remove it: the link state 6448 * is rechecked/recovered now after modesets, where the loss of 6449 * synchronization tends to occur. 6450 */ 6451 if (!intel_dp_is_edp(intel_dp)) 6452 intel_dp_check_link_state(intel_dp); 6453 6454 /* 6455 * Clearing NACK and defer counts to get their exact values 6456 * while reading EDID which are required by Compliance tests 6457 * 4.2.2.4 and 4.2.2.5 6458 */ 6459 intel_dp->aux.i2c_nack_count = 0; 6460 intel_dp->aux.i2c_defer_count = 0; 6461 6462 intel_dp_set_edid(intel_dp); 6463 if (intel_dp_is_edp(intel_dp) || connector->detect_edid) 6464 status = connector_status_connected; 6465 6466 out_unset_edid: 6467 if (status != connector_status_connected && !intel_dp->is_mst) 6468 intel_dp_unset_edid(intel_dp); 6469 6470 intel_dp_dpcd_set_probe(intel_dp, false); 6471 6472 if (!intel_dp_is_edp(intel_dp)) 6473 drm_dp_set_subconnector_property(&connector->base, 6474 status, 6475 intel_dp->dpcd, 6476 intel_dp->downstream_ports); 6477 out_vdd_off: 6478 intel_pps_vdd_off(intel_dp); 6479 6480 return status; 6481 } 6482 6483 static void 6484 intel_dp_force(struct drm_connector *_connector) 6485 { 6486 struct intel_connector *connector = to_intel_connector(_connector); 6487 struct intel_display *display = to_intel_display(connector); 6488 struct intel_dp *intel_dp = intel_attached_dp(connector); 6489 6490 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s]\n", 6491 connector->base.base.id, connector->base.name); 6492 6493 if (!intel_display_driver_check_access(display)) 6494 return; 6495 6496 intel_dp_unset_edid(intel_dp); 6497 6498 if (connector->base.status != connector_status_connected) 6499 return; 6500 6501 intel_dp_set_edid(intel_dp); 6502 6503 intel_dp_dpcd_set_probe(intel_dp, false); 6504 } 6505 6506 static int intel_dp_get_modes(struct drm_connector *_connector) 6507 { 6508 struct intel_display *display = to_intel_display(_connector->dev); 6509 struct intel_connector *connector = to_intel_connector(_connector); 6510 struct intel_dp *intel_dp = intel_attached_dp(connector); 6511 int num_modes; 6512 6513 /* drm_edid_connector_update() done in ->detect() or ->force() */ 6514 num_modes = drm_edid_connector_add_modes(&connector->base); 6515 6516 /* Also add fixed mode, which may or may not be present in EDID */ 6517 if (intel_dp_is_edp(intel_dp)) 6518 num_modes += intel_panel_get_modes(connector); 6519 6520 if (num_modes) 6521 return num_modes; 6522 6523 if (!connector->detect_edid) { 6524 struct drm_display_mode *mode; 6525 6526 mode = drm_dp_downstream_mode(display->drm, 6527 intel_dp->dpcd, 6528 intel_dp->downstream_ports); 6529 if (mode) { 6530 drm_mode_probed_add(&connector->base, mode); 6531 num_modes++; 6532 } 6533 } 6534 6535 return num_modes; 6536 } 6537 6538 static int 6539 intel_dp_connector_register(struct drm_connector *_connector) 6540 { 6541 struct intel_connector *connector = to_intel_connector(_connector); 6542 struct intel_display *display = to_intel_display(connector); 6543 struct intel_dp *intel_dp = intel_attached_dp(connector); 6544 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 6545 int ret; 6546 6547 ret = intel_connector_register(&connector->base); 6548 if (ret) 6549 return ret; 6550 6551 drm_dbg_kms(display->drm, "registering %s bus for %s\n", 6552 intel_dp->aux.name, connector->base.kdev->kobj.name); 6553 6554 intel_dp->aux.dev = connector->base.kdev; 6555 ret = drm_dp_aux_register(&intel_dp->aux); 6556 if (!ret) 6557 drm_dp_cec_register_connector(&intel_dp->aux, &connector->base); 6558 6559 if (!intel_bios_encoder_is_lspcon(dig_port->base.devdata)) 6560 return ret; 6561 6562 /* 6563 * ToDo: Clean this up to handle lspcon init and resume more 6564 * efficiently and streamlined. 6565 */ 6566 if (intel_lspcon_init(dig_port)) { 6567 if (intel_lspcon_detect_hdr_capability(dig_port)) 6568 drm_connector_attach_hdr_output_metadata_property(&connector->base); 6569 } 6570 6571 return ret; 6572 } 6573 6574 static void 6575 intel_dp_connector_unregister(struct drm_connector *_connector) 6576 { 6577 struct intel_connector *connector = to_intel_connector(_connector); 6578 struct intel_dp *intel_dp = intel_attached_dp(connector); 6579 6580 drm_dp_cec_unregister_connector(&intel_dp->aux); 6581 drm_dp_aux_unregister(&intel_dp->aux); 6582 intel_connector_unregister(&connector->base); 6583 } 6584 6585 void intel_dp_connector_sync_state(struct intel_connector *connector, 6586 const struct intel_crtc_state *crtc_state) 6587 { 6588 struct intel_display *display = to_intel_display(connector); 6589 6590 if (crtc_state && crtc_state->dsc.compression_enable) { 6591 drm_WARN_ON(display->drm, 6592 !connector->dp.dsc_decompression_aux); 6593 connector->dp.dsc_decompression_enabled = true; 6594 } else { 6595 connector->dp.dsc_decompression_enabled = false; 6596 } 6597 } 6598 6599 void intel_dp_encoder_flush_work(struct drm_encoder *_encoder) 6600 { 6601 struct intel_encoder *encoder = to_intel_encoder(_encoder); 6602 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6603 struct intel_dp *intel_dp = &dig_port->dp; 6604 6605 intel_encoder_link_check_flush_work(encoder); 6606 6607 intel_dp_mst_encoder_cleanup(dig_port); 6608 6609 intel_dp_tunnel_destroy(intel_dp); 6610 6611 intel_pps_vdd_off_sync(intel_dp); 6612 6613 /* 6614 * Ensure power off delay is respected on module remove, so that we can 6615 * reduce delays at driver probe. See pps_init_timestamps(). 6616 */ 6617 intel_pps_wait_power_cycle(intel_dp); 6618 6619 intel_dp_aux_fini(intel_dp); 6620 } 6621 6622 void intel_dp_encoder_suspend(struct intel_encoder *encoder) 6623 { 6624 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 6625 6626 intel_pps_vdd_off_sync(intel_dp); 6627 6628 intel_dp_tunnel_suspend(intel_dp); 6629 } 6630 6631 void intel_dp_encoder_shutdown(struct intel_encoder *encoder) 6632 { 6633 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 6634 6635 intel_pps_wait_power_cycle(intel_dp); 6636 } 6637 6638 static int intel_modeset_tile_group(struct intel_atomic_state *state, 6639 int tile_group_id) 6640 { 6641 struct intel_display *display = to_intel_display(state); 6642 struct drm_connector_list_iter conn_iter; 6643 struct intel_connector *connector; 6644 int ret = 0; 6645 6646 drm_connector_list_iter_begin(display->drm, &conn_iter); 6647 for_each_intel_connector_iter(connector, &conn_iter) { 6648 struct drm_connector_state *conn_state; 6649 struct intel_crtc_state *crtc_state; 6650 struct intel_crtc *crtc; 6651 6652 if (!connector->base.has_tile || 6653 connector->base.tile_group->id != tile_group_id) 6654 continue; 6655 6656 conn_state = drm_atomic_get_connector_state(&state->base, 6657 &connector->base); 6658 if (IS_ERR(conn_state)) { 6659 ret = PTR_ERR(conn_state); 6660 break; 6661 } 6662 6663 crtc = to_intel_crtc(conn_state->crtc); 6664 6665 if (!crtc) 6666 continue; 6667 6668 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 6669 crtc_state->uapi.mode_changed = true; 6670 6671 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 6672 if (ret) 6673 break; 6674 } 6675 drm_connector_list_iter_end(&conn_iter); 6676 6677 return ret; 6678 } 6679 6680 static int intel_modeset_affected_transcoders(struct intel_atomic_state *state, u8 transcoders) 6681 { 6682 struct intel_display *display = to_intel_display(state); 6683 struct intel_crtc *crtc; 6684 6685 if (transcoders == 0) 6686 return 0; 6687 6688 for_each_intel_crtc(display->drm, crtc) { 6689 struct intel_crtc_state *crtc_state; 6690 int ret; 6691 6692 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6693 if (IS_ERR(crtc_state)) 6694 return PTR_ERR(crtc_state); 6695 6696 if (!crtc_state->hw.enable) 6697 continue; 6698 6699 if (!(transcoders & BIT(crtc_state->cpu_transcoder))) 6700 continue; 6701 6702 crtc_state->uapi.mode_changed = true; 6703 6704 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base); 6705 if (ret) 6706 return ret; 6707 6708 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 6709 if (ret) 6710 return ret; 6711 6712 transcoders &= ~BIT(crtc_state->cpu_transcoder); 6713 } 6714 6715 drm_WARN_ON(display->drm, transcoders != 0); 6716 6717 return 0; 6718 } 6719 6720 static int intel_modeset_synced_crtcs(struct intel_atomic_state *state, 6721 struct drm_connector *_connector) 6722 { 6723 struct intel_connector *connector = to_intel_connector(_connector); 6724 const struct drm_connector_state *old_conn_state = 6725 drm_atomic_get_old_connector_state(&state->base, &connector->base); 6726 const struct intel_crtc_state *old_crtc_state; 6727 struct intel_crtc *crtc; 6728 u8 transcoders; 6729 6730 crtc = to_intel_crtc(old_conn_state->crtc); 6731 if (!crtc) 6732 return 0; 6733 6734 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc); 6735 6736 if (!old_crtc_state->hw.active) 6737 return 0; 6738 6739 transcoders = old_crtc_state->sync_mode_slaves_mask; 6740 if (old_crtc_state->master_transcoder != INVALID_TRANSCODER) 6741 transcoders |= BIT(old_crtc_state->master_transcoder); 6742 6743 return intel_modeset_affected_transcoders(state, 6744 transcoders); 6745 } 6746 6747 static int intel_dp_connector_atomic_check(struct drm_connector *_connector, 6748 struct drm_atomic_state *_state) 6749 { 6750 struct intel_connector *connector = to_intel_connector(_connector); 6751 struct intel_display *display = to_intel_display(connector); 6752 struct intel_atomic_state *state = to_intel_atomic_state(_state); 6753 struct drm_connector_state *conn_state = 6754 drm_atomic_get_new_connector_state(_state, &connector->base); 6755 struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 6756 int ret; 6757 6758 ret = intel_digital_connector_atomic_check(&connector->base, &state->base); 6759 if (ret) 6760 return ret; 6761 6762 if (intel_dp_mst_source_support(intel_dp)) { 6763 ret = drm_dp_mst_root_conn_atomic_check(conn_state, &intel_dp->mst.mgr); 6764 if (ret) 6765 return ret; 6766 } 6767 6768 if (!intel_connector_needs_modeset(state, &connector->base)) 6769 return 0; 6770 6771 ret = intel_dp_tunnel_atomic_check_state(state, 6772 intel_dp, 6773 connector); 6774 if (ret) 6775 return ret; 6776 6777 /* 6778 * We don't enable port sync on BDW due to missing w/as and 6779 * due to not having adjusted the modeset sequence appropriately. 6780 */ 6781 if (DISPLAY_VER(display) < 9) 6782 return 0; 6783 6784 if (connector->base.has_tile) { 6785 ret = intel_modeset_tile_group(state, connector->base.tile_group->id); 6786 if (ret) 6787 return ret; 6788 } 6789 6790 return intel_modeset_synced_crtcs(state, &connector->base); 6791 } 6792 6793 static void intel_dp_oob_hotplug_event(struct drm_connector *_connector, 6794 enum drm_connector_status hpd_state) 6795 { 6796 struct intel_connector *connector = to_intel_connector(_connector); 6797 struct intel_display *display = to_intel_display(connector); 6798 struct intel_encoder *encoder = intel_attached_encoder(connector); 6799 bool hpd_high = hpd_state == connector_status_connected; 6800 unsigned int hpd_pin = encoder->hpd_pin; 6801 bool need_work = false; 6802 6803 spin_lock_irq(&display->irq.lock); 6804 if (hpd_high != test_bit(hpd_pin, &display->hotplug.oob_hotplug_last_state)) { 6805 display->hotplug.event_bits |= BIT(hpd_pin); 6806 6807 __assign_bit(hpd_pin, 6808 &display->hotplug.oob_hotplug_last_state, 6809 hpd_high); 6810 need_work = true; 6811 } 6812 spin_unlock_irq(&display->irq.lock); 6813 6814 if (need_work) 6815 intel_hpd_schedule_detection(display); 6816 } 6817 6818 static const struct drm_connector_funcs intel_dp_connector_funcs = { 6819 .force = intel_dp_force, 6820 .fill_modes = drm_helper_probe_single_connector_modes, 6821 .atomic_get_property = intel_digital_connector_atomic_get_property, 6822 .atomic_set_property = intel_digital_connector_atomic_set_property, 6823 .late_register = intel_dp_connector_register, 6824 .early_unregister = intel_dp_connector_unregister, 6825 .destroy = intel_connector_destroy, 6826 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 6827 .atomic_duplicate_state = intel_digital_connector_duplicate_state, 6828 .oob_hotplug_event = intel_dp_oob_hotplug_event, 6829 }; 6830 6831 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { 6832 .detect_ctx = intel_dp_detect, 6833 .get_modes = intel_dp_get_modes, 6834 .mode_valid = intel_dp_mode_valid, 6835 .atomic_check = intel_dp_connector_atomic_check, 6836 }; 6837 6838 enum irqreturn 6839 intel_dp_hpd_pulse(struct intel_digital_port *dig_port, bool long_hpd) 6840 { 6841 struct intel_display *display = to_intel_display(dig_port); 6842 struct intel_dp *intel_dp = &dig_port->dp; 6843 u8 dpcd[DP_RECEIVER_CAP_SIZE]; 6844 6845 if (dig_port->base.type == INTEL_OUTPUT_EDP && 6846 (long_hpd || 6847 intel_display_rpm_suspended(display) || 6848 !intel_pps_have_panel_power_or_vdd(intel_dp))) { 6849 /* 6850 * vdd off can generate a long/short pulse on eDP which 6851 * would require vdd on to handle it, and thus we 6852 * would end up in an endless cycle of 6853 * "vdd off -> long/short hpd -> vdd on -> detect -> vdd off -> ..." 6854 */ 6855 drm_dbg_kms(display->drm, 6856 "ignoring %s hpd on eDP [ENCODER:%d:%s]\n", 6857 long_hpd ? "long" : "short", 6858 dig_port->base.base.base.id, 6859 dig_port->base.base.name); 6860 return IRQ_HANDLED; 6861 } 6862 6863 drm_dbg_kms(display->drm, "got hpd irq on [ENCODER:%d:%s] - %s\n", 6864 dig_port->base.base.base.id, 6865 dig_port->base.base.name, 6866 long_hpd ? "long" : "short"); 6867 6868 /* 6869 * TBT DP tunnels require the GFX driver to read out the DPRX caps in 6870 * response to long HPD pulses. The DP hotplug handler does that, 6871 * however the hotplug handler may be blocked by another 6872 * connector's/encoder's hotplug handler. Since the TBT CM may not 6873 * complete the DP tunnel BW request for the latter connector/encoder 6874 * waiting for this encoder's DPRX read, perform a dummy read here. 6875 */ 6876 if (long_hpd) { 6877 intel_dp_dpcd_set_probe(intel_dp, true); 6878 6879 intel_dp_read_dprx_caps(intel_dp, dpcd); 6880 6881 intel_dp->reset_link_params = true; 6882 intel_dp_invalidate_source_oui(intel_dp); 6883 6884 return IRQ_NONE; 6885 } 6886 6887 if (intel_dp->is_mst) { 6888 if (!intel_dp_check_mst_status(intel_dp)) 6889 return IRQ_NONE; 6890 } else if (!intel_dp_short_pulse(intel_dp)) { 6891 return IRQ_NONE; 6892 } 6893 6894 return IRQ_HANDLED; 6895 } 6896 6897 static bool _intel_dp_is_port_edp(struct intel_display *display, 6898 const struct intel_bios_encoder_data *devdata, 6899 enum port port) 6900 { 6901 /* 6902 * eDP not supported on g4x. so bail out early just 6903 * for a bit extra safety in case the VBT is bonkers. 6904 */ 6905 if (DISPLAY_VER(display) < 5) 6906 return false; 6907 6908 if (DISPLAY_VER(display) < 9 && port == PORT_A) 6909 return true; 6910 6911 return devdata && intel_bios_encoder_supports_edp(devdata); 6912 } 6913 6914 bool intel_dp_is_port_edp(struct intel_display *display, enum port port) 6915 { 6916 const struct intel_bios_encoder_data *devdata = 6917 intel_bios_encoder_data_lookup(display, port); 6918 6919 return _intel_dp_is_port_edp(display, devdata, port); 6920 } 6921 6922 bool 6923 intel_dp_has_gamut_metadata_dip(struct intel_encoder *encoder) 6924 { 6925 struct intel_display *display = to_intel_display(encoder); 6926 enum port port = encoder->port; 6927 6928 if (intel_bios_encoder_is_lspcon(encoder->devdata)) 6929 return false; 6930 6931 if (DISPLAY_VER(display) >= 11) 6932 return true; 6933 6934 if (port == PORT_A) 6935 return false; 6936 6937 if (display->platform.haswell || display->platform.broadwell || 6938 DISPLAY_VER(display) >= 9) 6939 return true; 6940 6941 return false; 6942 } 6943 6944 static void 6945 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *_connector) 6946 { 6947 struct intel_connector *connector = to_intel_connector(_connector); 6948 struct intel_display *display = to_intel_display(intel_dp); 6949 enum port port = dp_to_dig_port(intel_dp)->base.port; 6950 6951 if (!intel_dp_is_edp(intel_dp)) 6952 drm_connector_attach_dp_subconnector_property(&connector->base); 6953 6954 if (!display->platform.g4x && port != PORT_A) 6955 intel_attach_force_audio_property(&connector->base); 6956 6957 intel_attach_broadcast_rgb_property(&connector->base); 6958 if (HAS_GMCH(display)) 6959 drm_connector_attach_max_bpc_property(&connector->base, 6, 10); 6960 else if (DISPLAY_VER(display) >= 5) 6961 drm_connector_attach_max_bpc_property(&connector->base, 6, 12); 6962 6963 /* Register HDMI colorspace for case of lspcon */ 6964 if (intel_bios_encoder_is_lspcon(dp_to_dig_port(intel_dp)->base.devdata)) { 6965 drm_connector_attach_content_type_property(&connector->base); 6966 intel_attach_hdmi_colorspace_property(&connector->base); 6967 } else { 6968 intel_attach_dp_colorspace_property(&connector->base); 6969 } 6970 6971 if (intel_dp_has_gamut_metadata_dip(&dp_to_dig_port(intel_dp)->base)) 6972 drm_connector_attach_hdr_output_metadata_property(&connector->base); 6973 6974 if (HAS_VRR(display)) 6975 drm_connector_attach_vrr_capable_property(&connector->base); 6976 } 6977 6978 static void 6979 intel_edp_add_properties(struct intel_dp *intel_dp) 6980 { 6981 struct intel_display *display = to_intel_display(intel_dp); 6982 struct intel_connector *connector = intel_dp->attached_connector; 6983 const struct drm_display_mode *fixed_mode = 6984 intel_panel_preferred_fixed_mode(connector); 6985 6986 intel_attach_scaling_mode_property(&connector->base); 6987 6988 drm_connector_set_panel_orientation_with_quirk(&connector->base, 6989 display->vbt.orientation, 6990 fixed_mode->hdisplay, 6991 fixed_mode->vdisplay); 6992 } 6993 6994 static void intel_edp_backlight_setup(struct intel_dp *intel_dp, 6995 struct intel_connector *connector) 6996 { 6997 struct intel_display *display = to_intel_display(intel_dp); 6998 enum pipe pipe = INVALID_PIPE; 6999 7000 if (display->platform.valleyview || display->platform.cherryview) 7001 pipe = vlv_pps_backlight_initial_pipe(intel_dp); 7002 7003 intel_backlight_setup(connector, pipe); 7004 } 7005 7006 static bool intel_edp_init_connector(struct intel_dp *intel_dp, 7007 struct intel_connector *connector) 7008 { 7009 struct intel_display *display = to_intel_display(intel_dp); 7010 struct drm_display_mode *fixed_mode; 7011 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 7012 bool has_dpcd; 7013 const struct drm_edid *drm_edid; 7014 7015 if (!intel_dp_is_edp(intel_dp)) 7016 return true; 7017 7018 /* 7019 * On IBX/CPT we may get here with LVDS already registered. Since the 7020 * driver uses the only internal power sequencer available for both 7021 * eDP and LVDS bail out early in this case to prevent interfering 7022 * with an already powered-on LVDS power sequencer. 7023 */ 7024 if (intel_get_lvds_encoder(display)) { 7025 drm_WARN_ON(display->drm, 7026 !(HAS_PCH_IBX(display) || HAS_PCH_CPT(display))); 7027 drm_info(display->drm, 7028 "LVDS was detected, not registering eDP\n"); 7029 7030 return false; 7031 } 7032 7033 intel_bios_init_panel_early(display, &connector->panel, 7034 encoder->devdata); 7035 7036 if (!intel_pps_init(intel_dp)) { 7037 drm_info(display->drm, 7038 "[ENCODER:%d:%s] unusable PPS, disabling eDP\n", 7039 encoder->base.base.id, encoder->base.name); 7040 /* 7041 * The BIOS may have still enabled VDD on the PPS even 7042 * though it's unusable. Make sure we turn it back off 7043 * and to release the power domain references/etc. 7044 */ 7045 goto out_vdd_off; 7046 } 7047 7048 /* 7049 * Enable HPD sense for live status check. 7050 * intel_hpd_irq_setup() will turn it off again 7051 * if it's no longer needed later. 7052 * 7053 * The DPCD probe below will make sure VDD is on. 7054 */ 7055 intel_hpd_enable_detection(encoder); 7056 7057 intel_alpm_init(intel_dp); 7058 7059 /* Cache DPCD and EDID for edp. */ 7060 has_dpcd = intel_edp_init_dpcd(intel_dp, connector); 7061 7062 if (!has_dpcd) { 7063 /* if this fails, presume the device is a ghost */ 7064 drm_info(display->drm, 7065 "[ENCODER:%d:%s] failed to retrieve link info, disabling eDP\n", 7066 encoder->base.base.id, encoder->base.name); 7067 goto out_vdd_off; 7068 } 7069 7070 /* 7071 * VBT and straps are liars. Also check HPD as that seems 7072 * to be the most reliable piece of information available. 7073 * 7074 * ... expect on devices that forgot to hook HPD up for eDP 7075 * (eg. Acer Chromebook C710), so we'll check it only if multiple 7076 * ports are attempting to use the same AUX CH, according to VBT. 7077 */ 7078 if (intel_bios_dp_has_shared_aux_ch(encoder->devdata)) { 7079 /* 7080 * If this fails, presume the DPCD answer came 7081 * from some other port using the same AUX CH. 7082 * 7083 * FIXME maybe cleaner to check this before the 7084 * DPCD read? Would need sort out the VDD handling... 7085 */ 7086 if (!intel_digital_port_connected(encoder)) { 7087 drm_info(display->drm, 7088 "[ENCODER:%d:%s] HPD is down, disabling eDP\n", 7089 encoder->base.base.id, encoder->base.name); 7090 goto out_vdd_off; 7091 } 7092 7093 /* 7094 * Unfortunately even the HPD based detection fails on 7095 * eg. Asus B360M-A (CFL+CNP), so as a last resort fall 7096 * back to checking for a VGA branch device. Only do this 7097 * on known affected platforms to minimize false positives. 7098 */ 7099 if (DISPLAY_VER(display) == 9 && drm_dp_is_branch(intel_dp->dpcd) && 7100 (intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_TYPE_MASK) == 7101 DP_DWN_STRM_PORT_TYPE_ANALOG) { 7102 drm_info(display->drm, 7103 "[ENCODER:%d:%s] VGA converter detected, disabling eDP\n", 7104 encoder->base.base.id, encoder->base.name); 7105 goto out_vdd_off; 7106 } 7107 } 7108 7109 mutex_lock(&display->drm->mode_config.mutex); 7110 drm_edid = drm_edid_read_ddc(&connector->base, connector->base.ddc); 7111 if (!drm_edid) { 7112 /* Fallback to EDID from ACPI OpRegion, if any */ 7113 drm_edid = intel_opregion_get_edid(connector); 7114 if (drm_edid) 7115 drm_dbg_kms(display->drm, 7116 "[CONNECTOR:%d:%s] Using OpRegion EDID\n", 7117 connector->base.base.id, connector->base.name); 7118 } 7119 if (drm_edid) { 7120 if (drm_edid_connector_update(&connector->base, drm_edid) || 7121 !drm_edid_connector_add_modes(&connector->base)) { 7122 drm_edid_connector_update(&connector->base, NULL); 7123 drm_edid_free(drm_edid); 7124 drm_edid = ERR_PTR(-EINVAL); 7125 } 7126 } else { 7127 drm_edid = ERR_PTR(-ENOENT); 7128 } 7129 7130 intel_bios_init_panel_late(display, &connector->panel, encoder->devdata, 7131 IS_ERR(drm_edid) ? NULL : drm_edid); 7132 7133 intel_panel_add_edid_fixed_modes(connector, true); 7134 7135 /* MSO requires information from the EDID */ 7136 intel_edp_mso_init(intel_dp); 7137 7138 /* multiply the mode clock and horizontal timings for MSO */ 7139 list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) 7140 intel_edp_mso_mode_fixup(connector, fixed_mode); 7141 7142 /* fallback to VBT if available for eDP */ 7143 if (!intel_panel_preferred_fixed_mode(connector)) 7144 intel_panel_add_vbt_lfp_fixed_mode(connector); 7145 7146 mutex_unlock(&display->drm->mode_config.mutex); 7147 7148 if (!intel_panel_preferred_fixed_mode(connector)) { 7149 drm_info(display->drm, 7150 "[ENCODER:%d:%s] failed to find fixed mode for the panel, disabling eDP\n", 7151 encoder->base.base.id, encoder->base.name); 7152 goto out_vdd_off; 7153 } 7154 7155 intel_panel_init(connector, drm_edid); 7156 7157 intel_edp_backlight_setup(intel_dp, connector); 7158 7159 intel_edp_add_properties(intel_dp); 7160 7161 intel_pps_init_late(intel_dp); 7162 7163 return true; 7164 7165 out_vdd_off: 7166 intel_pps_vdd_off_sync(intel_dp); 7167 intel_bios_fini_panel(&connector->panel); 7168 7169 return false; 7170 } 7171 7172 bool 7173 intel_dp_init_connector(struct intel_digital_port *dig_port, 7174 struct intel_connector *connector) 7175 { 7176 struct intel_display *display = to_intel_display(dig_port); 7177 struct intel_dp *intel_dp = &dig_port->dp; 7178 struct intel_encoder *encoder = &dig_port->base; 7179 struct drm_device *dev = encoder->base.dev; 7180 enum port port = encoder->port; 7181 int type; 7182 7183 if (drm_WARN(dev, dig_port->max_lanes < 1, 7184 "Not enough lanes (%d) for DP on [ENCODER:%d:%s]\n", 7185 dig_port->max_lanes, encoder->base.base.id, 7186 encoder->base.name)) 7187 return false; 7188 7189 intel_dp->reset_link_params = true; 7190 7191 /* Preserve the current hw state. */ 7192 intel_dp->DP = intel_de_read(display, intel_dp->output_reg); 7193 intel_dp->attached_connector = connector; 7194 7195 if (_intel_dp_is_port_edp(display, encoder->devdata, port)) { 7196 /* 7197 * Currently we don't support eDP on TypeC ports for DISPLAY_VER < 30, 7198 * although in theory it could work on TypeC legacy ports. 7199 */ 7200 drm_WARN_ON(dev, intel_encoder_is_tc(encoder) && 7201 DISPLAY_VER(display) < 30); 7202 type = DRM_MODE_CONNECTOR_eDP; 7203 encoder->type = INTEL_OUTPUT_EDP; 7204 7205 /* eDP only on port B and/or C on vlv/chv */ 7206 if (drm_WARN_ON(dev, (display->platform.valleyview || 7207 display->platform.cherryview) && 7208 port != PORT_B && port != PORT_C)) 7209 return false; 7210 } else { 7211 type = DRM_MODE_CONNECTOR_DisplayPort; 7212 } 7213 7214 intel_dp_set_default_sink_rates(intel_dp); 7215 intel_dp_set_default_max_sink_lane_count(intel_dp); 7216 7217 if (display->platform.valleyview || display->platform.cherryview) 7218 vlv_pps_pipe_init(intel_dp); 7219 7220 intel_dp_aux_init(intel_dp); 7221 connector->dp.dsc_decompression_aux = &intel_dp->aux; 7222 7223 drm_dbg_kms(display->drm, 7224 "Adding %s connector on [ENCODER:%d:%s]\n", 7225 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", 7226 encoder->base.base.id, encoder->base.name); 7227 7228 drm_connector_init_with_ddc(dev, &connector->base, &intel_dp_connector_funcs, 7229 type, &intel_dp->aux.ddc); 7230 drm_connector_helper_add(&connector->base, &intel_dp_connector_helper_funcs); 7231 7232 if (!HAS_GMCH(display) && DISPLAY_VER(display) < 12) 7233 connector->base.interlace_allowed = true; 7234 7235 if (type != DRM_MODE_CONNECTOR_eDP) 7236 connector->polled = DRM_CONNECTOR_POLL_HPD; 7237 connector->base.polled = connector->polled; 7238 7239 intel_connector_attach_encoder(connector, encoder); 7240 7241 if (HAS_DDI(display)) 7242 connector->get_hw_state = intel_ddi_connector_get_hw_state; 7243 else 7244 connector->get_hw_state = intel_connector_get_hw_state; 7245 connector->sync_state = intel_dp_connector_sync_state; 7246 7247 if (!intel_edp_init_connector(intel_dp, connector)) { 7248 intel_dp_aux_fini(intel_dp); 7249 goto fail; 7250 } 7251 7252 intel_dp_set_source_rates(intel_dp); 7253 intel_dp_set_common_rates(intel_dp); 7254 intel_dp_reset_link_params(intel_dp); 7255 7256 /* init MST on ports that can support it */ 7257 intel_dp_mst_encoder_init(dig_port, connector->base.base.id); 7258 7259 intel_dp_add_properties(intel_dp, &connector->base); 7260 7261 if (is_hdcp_supported(display, port) && !intel_dp_is_edp(intel_dp)) { 7262 int ret = intel_dp_hdcp_init(dig_port, connector); 7263 if (ret) 7264 drm_dbg_kms(display->drm, 7265 "HDCP init failed, skipping.\n"); 7266 } 7267 7268 intel_dp->frl.is_trained = false; 7269 intel_dp->frl.trained_rate_gbps = 0; 7270 7271 intel_psr_init(intel_dp); 7272 7273 return true; 7274 7275 fail: 7276 intel_display_power_flush_work(display); 7277 drm_connector_cleanup(&connector->base); 7278 7279 return false; 7280 } 7281 7282 void intel_dp_mst_suspend(struct intel_display *display) 7283 { 7284 struct intel_encoder *encoder; 7285 7286 if (!HAS_DISPLAY(display)) 7287 return; 7288 7289 for_each_intel_encoder(display->drm, encoder) { 7290 struct intel_dp *intel_dp; 7291 7292 if (encoder->type != INTEL_OUTPUT_DDI) 7293 continue; 7294 7295 intel_dp = enc_to_intel_dp(encoder); 7296 7297 if (!intel_dp_mst_source_support(intel_dp)) 7298 continue; 7299 7300 if (intel_dp->is_mst) 7301 drm_dp_mst_topology_mgr_suspend(&intel_dp->mst.mgr); 7302 } 7303 } 7304 7305 void intel_dp_mst_resume(struct intel_display *display) 7306 { 7307 struct intel_encoder *encoder; 7308 7309 if (!HAS_DISPLAY(display)) 7310 return; 7311 7312 for_each_intel_encoder(display->drm, encoder) { 7313 struct intel_dp *intel_dp; 7314 int ret; 7315 7316 if (encoder->type != INTEL_OUTPUT_DDI) 7317 continue; 7318 7319 intel_dp = enc_to_intel_dp(encoder); 7320 7321 if (!intel_dp_mst_source_support(intel_dp)) 7322 continue; 7323 7324 ret = drm_dp_mst_topology_mgr_resume(&intel_dp->mst.mgr, true); 7325 if (ret) { 7326 intel_dp->is_mst = false; 7327 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, false); 7328 } 7329 } 7330 } 7331 7332 static 7333 int intel_dp_sdp_compute_config_late(struct intel_crtc_state *crtc_state) 7334 { 7335 struct intel_display *display = to_intel_display(crtc_state); 7336 int guardband = intel_crtc_vblank_length(crtc_state); 7337 int min_sdp_guardband = intel_dp_sdp_min_guardband(crtc_state, false); 7338 7339 if (guardband < min_sdp_guardband) { 7340 drm_dbg_kms(display->drm, "guardband %d < min sdp guardband %d\n", 7341 guardband, min_sdp_guardband); 7342 return -EINVAL; 7343 } 7344 7345 return 0; 7346 } 7347 7348 int intel_dp_compute_config_late(struct intel_encoder *encoder, 7349 struct intel_crtc_state *crtc_state, 7350 struct drm_connector_state *conn_state) 7351 { 7352 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 7353 int ret; 7354 7355 intel_psr_compute_config_late(intel_dp, crtc_state); 7356 7357 ret = intel_dp_sdp_compute_config_late(crtc_state); 7358 if (ret) 7359 return ret; 7360 7361 intel_alpm_lobf_compute_config_late(intel_dp, crtc_state); 7362 7363 return 0; 7364 } 7365 7366 static 7367 int intel_dp_get_lines_for_sdp(const struct intel_crtc_state *crtc_state, u32 type) 7368 { 7369 switch (type) { 7370 case DP_SDP_VSC_EXT_VESA: 7371 case DP_SDP_VSC_EXT_CEA: 7372 return 10; 7373 case HDMI_PACKET_TYPE_GAMUT_METADATA: 7374 return 8; 7375 case DP_SDP_PPS: 7376 return 7; 7377 case DP_SDP_ADAPTIVE_SYNC: 7378 return crtc_state->vrr.vsync_start + 1; 7379 default: 7380 break; 7381 } 7382 7383 return 0; 7384 } 7385 7386 int intel_dp_sdp_min_guardband(const struct intel_crtc_state *crtc_state, 7387 bool assume_all_enabled) 7388 { 7389 struct intel_display *display = to_intel_display(crtc_state); 7390 int sdp_guardband = 0; 7391 7392 if (assume_all_enabled || 7393 crtc_state->infoframes.enable & 7394 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA)) 7395 sdp_guardband = max(sdp_guardband, 7396 intel_dp_get_lines_for_sdp(crtc_state, 7397 HDMI_PACKET_TYPE_GAMUT_METADATA)); 7398 7399 if (assume_all_enabled || 7400 crtc_state->dsc.compression_enable) 7401 sdp_guardband = max(sdp_guardband, 7402 intel_dp_get_lines_for_sdp(crtc_state, DP_SDP_PPS)); 7403 7404 if ((assume_all_enabled && HAS_AS_SDP(display)) || 7405 crtc_state->infoframes.enable & intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC)) 7406 sdp_guardband = max(sdp_guardband, 7407 intel_dp_get_lines_for_sdp(crtc_state, DP_SDP_ADAPTIVE_SYNC)); 7408 7409 return sdp_guardband; 7410 } 7411 7412 bool intel_dp_joiner_candidate_valid(struct intel_connector *connector, 7413 int hdisplay, 7414 int num_joined_pipes) 7415 { 7416 struct intel_display *display = to_intel_display(connector); 7417 struct intel_dp *intel_dp = intel_attached_dp(connector); 7418 7419 if (!intel_dp_can_join(intel_dp, num_joined_pipes)) 7420 return false; 7421 7422 if (hdisplay > num_joined_pipes * intel_dp_max_hdisplay_per_pipe(display)) 7423 return false; 7424 7425 if (connector->force_joined_pipes && connector->force_joined_pipes != num_joined_pipes) 7426 return false; 7427 7428 return true; 7429 } 7430