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