1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2020 Intel Corporation 4 */ 5 6 #include <linux/debugfs.h> 7 #include <linux/iopoll.h> 8 9 #include <drm/drm_print.h> 10 11 #include "g4x_dp.h" 12 #include "intel_de.h" 13 #include "intel_display_jiffies.h" 14 #include "intel_display_power_well.h" 15 #include "intel_display_regs.h" 16 #include "intel_display_types.h" 17 #include "intel_display_utils.h" 18 #include "intel_dp.h" 19 #include "intel_dpio_phy.h" 20 #include "intel_dpll.h" 21 #include "intel_lvds.h" 22 #include "intel_lvds_regs.h" 23 #include "intel_pps.h" 24 #include "intel_pps_regs.h" 25 #include "intel_quirks.h" 26 #include "intel_tc.h" 27 28 static void vlv_steal_power_sequencer(struct intel_display *display, 29 enum pipe pipe); 30 31 static void pps_init_delays(struct intel_dp *intel_dp); 32 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd); 33 34 static const char *pps_name(struct intel_dp *intel_dp) 35 { 36 struct intel_display *display = to_intel_display(intel_dp); 37 struct intel_pps *pps = &intel_dp->pps; 38 39 if (display->platform.valleyview || display->platform.cherryview) { 40 switch (pps->vlv_pps_pipe) { 41 case INVALID_PIPE: 42 /* 43 * FIXME would be nice if we can guarantee 44 * to always have a valid PPS when calling this. 45 */ 46 return "PPS <none>"; 47 case PIPE_A: 48 return "PPS A"; 49 case PIPE_B: 50 return "PPS B"; 51 default: 52 MISSING_CASE(pps->vlv_pps_pipe); 53 break; 54 } 55 } else { 56 switch (pps->pps_idx) { 57 case 0: 58 return "PPS 0"; 59 case 1: 60 return "PPS 1"; 61 default: 62 MISSING_CASE(pps->pps_idx); 63 break; 64 } 65 } 66 67 return "PPS <invalid>"; 68 } 69 70 struct ref_tracker *intel_pps_lock(struct intel_dp *intel_dp) 71 { 72 struct intel_display *display = to_intel_display(intel_dp); 73 struct ref_tracker *wakeref; 74 75 /* 76 * See vlv_pps_reset_all() why we need a power domain reference here. 77 */ 78 wakeref = intel_display_power_get(display, POWER_DOMAIN_DISPLAY_CORE); 79 mutex_lock(&display->pps.mutex); 80 81 return wakeref; 82 } 83 84 struct ref_tracker *intel_pps_unlock(struct intel_dp *intel_dp, struct ref_tracker *wakeref) 85 { 86 struct intel_display *display = to_intel_display(intel_dp); 87 88 mutex_unlock(&display->pps.mutex); 89 intel_display_power_put(display, POWER_DOMAIN_DISPLAY_CORE, wakeref); 90 91 return NULL; 92 } 93 94 static void 95 vlv_power_sequencer_kick(struct intel_dp *intel_dp) 96 { 97 struct intel_display *display = to_intel_display(intel_dp); 98 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 99 enum pipe pipe = intel_dp->pps.vlv_pps_pipe; 100 bool pll_enabled, release_cl_override = false; 101 enum dpio_phy phy = vlv_pipe_to_phy(pipe); 102 enum dpio_channel ch = vlv_pipe_to_channel(pipe); 103 u32 DP; 104 105 if (drm_WARN(display->drm, 106 intel_de_read(display, intel_dp->output_reg) & DP_PORT_EN, 107 "skipping %s kick due to [ENCODER:%d:%s] being active\n", 108 pps_name(intel_dp), 109 dig_port->base.base.base.id, dig_port->base.base.name)) 110 return; 111 112 drm_dbg_kms(display->drm, 113 "kicking %s for [ENCODER:%d:%s]\n", 114 pps_name(intel_dp), 115 dig_port->base.base.base.id, dig_port->base.base.name); 116 117 /* Preserve the BIOS-computed detected bit. This is 118 * supposed to be read-only. 119 */ 120 DP = intel_de_read(display, intel_dp->output_reg) & DP_DETECTED; 121 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0; 122 DP |= DP_PORT_WIDTH(1); 123 DP |= DP_LINK_TRAIN_PAT_1; 124 125 if (display->platform.cherryview) 126 DP |= DP_PIPE_SEL_CHV(pipe); 127 else 128 DP |= DP_PIPE_SEL(pipe); 129 130 pll_enabled = intel_de_read(display, DPLL(display, pipe)) & DPLL_VCO_ENABLE; 131 132 /* 133 * The DPLL for the pipe must be enabled for this to work. 134 * So enable temporarily it if it's not already enabled. 135 */ 136 if (!pll_enabled) { 137 release_cl_override = display->platform.cherryview && 138 !chv_phy_powergate_ch(display, phy, ch, true); 139 140 if (vlv_force_pll_on(display, pipe, vlv_get_dpll(display))) { 141 drm_err(display->drm, 142 "Failed to force on PLL for pipe %c!\n", 143 pipe_name(pipe)); 144 return; 145 } 146 } 147 148 /* 149 * Similar magic as in intel_dp_enable_port(). 150 * We _must_ do this port enable + disable trick 151 * to make this power sequencer lock onto the port. 152 * Otherwise even VDD force bit won't work. 153 */ 154 intel_de_write(display, intel_dp->output_reg, DP); 155 intel_de_posting_read(display, intel_dp->output_reg); 156 157 intel_de_write(display, intel_dp->output_reg, DP | DP_PORT_EN); 158 intel_de_posting_read(display, intel_dp->output_reg); 159 160 intel_de_write(display, intel_dp->output_reg, DP & ~DP_PORT_EN); 161 intel_de_posting_read(display, intel_dp->output_reg); 162 163 if (!pll_enabled) { 164 vlv_force_pll_off(display, pipe); 165 166 if (release_cl_override) 167 chv_phy_powergate_ch(display, phy, ch, false); 168 } 169 } 170 171 static enum pipe vlv_find_free_pps(struct intel_display *display) 172 { 173 struct intel_encoder *encoder; 174 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B); 175 176 /* 177 * We don't have power sequencer currently. 178 * Pick one that's not used by other ports. 179 */ 180 for_each_intel_dp(display->drm, encoder) { 181 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 182 183 if (encoder->type == INTEL_OUTPUT_EDP) { 184 drm_WARN_ON(display->drm, 185 intel_dp->pps.vlv_active_pipe != INVALID_PIPE && 186 intel_dp->pps.vlv_active_pipe != 187 intel_dp->pps.vlv_pps_pipe); 188 189 if (intel_dp->pps.vlv_pps_pipe != INVALID_PIPE) 190 pipes &= ~(1 << intel_dp->pps.vlv_pps_pipe); 191 } else { 192 drm_WARN_ON(display->drm, 193 intel_dp->pps.vlv_pps_pipe != INVALID_PIPE); 194 195 if (intel_dp->pps.vlv_active_pipe != INVALID_PIPE) 196 pipes &= ~(1 << intel_dp->pps.vlv_active_pipe); 197 } 198 } 199 200 if (pipes == 0) 201 return INVALID_PIPE; 202 203 return ffs(pipes) - 1; 204 } 205 206 static enum pipe 207 vlv_power_sequencer_pipe(struct intel_dp *intel_dp) 208 { 209 struct intel_display *display = to_intel_display(intel_dp); 210 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 211 enum pipe pipe; 212 213 lockdep_assert_held(&display->pps.mutex); 214 215 /* We should never land here with regular DP ports */ 216 drm_WARN_ON(display->drm, !intel_dp_is_edp(intel_dp)); 217 218 drm_WARN_ON(display->drm, intel_dp->pps.vlv_active_pipe != INVALID_PIPE && 219 intel_dp->pps.vlv_active_pipe != intel_dp->pps.vlv_pps_pipe); 220 221 if (intel_dp->pps.vlv_pps_pipe != INVALID_PIPE) 222 return intel_dp->pps.vlv_pps_pipe; 223 224 pipe = vlv_find_free_pps(display); 225 226 /* 227 * Didn't find one. This should not happen since there 228 * are two power sequencers and up to two eDP ports. 229 */ 230 if (drm_WARN_ON(display->drm, pipe == INVALID_PIPE)) 231 pipe = PIPE_A; 232 233 vlv_steal_power_sequencer(display, pipe); 234 intel_dp->pps.vlv_pps_pipe = pipe; 235 236 drm_dbg_kms(display->drm, 237 "picked %s for [ENCODER:%d:%s]\n", 238 pps_name(intel_dp), 239 dig_port->base.base.base.id, dig_port->base.base.name); 240 241 /* init power sequencer on this pipe and port */ 242 pps_init_delays(intel_dp); 243 pps_init_registers(intel_dp, true); 244 245 /* 246 * Even vdd force doesn't work until we've made 247 * the power sequencer lock in on the port. 248 */ 249 vlv_power_sequencer_kick(intel_dp); 250 251 return intel_dp->pps.vlv_pps_pipe; 252 } 253 254 static int 255 bxt_power_sequencer_idx(struct intel_dp *intel_dp) 256 { 257 struct intel_display *display = to_intel_display(intel_dp); 258 int pps_idx = intel_dp->pps.pps_idx; 259 260 lockdep_assert_held(&display->pps.mutex); 261 262 /* We should never land here with regular DP ports */ 263 drm_WARN_ON(display->drm, !intel_dp_is_edp(intel_dp)); 264 265 if (!intel_dp->pps.bxt_pps_reset) 266 return pps_idx; 267 268 intel_dp->pps.bxt_pps_reset = false; 269 270 /* 271 * Only the HW needs to be reprogrammed, the SW state is fixed and 272 * has been setup during connector init. 273 */ 274 pps_init_registers(intel_dp, false); 275 276 return pps_idx; 277 } 278 279 typedef bool (*pps_check)(struct intel_display *display, int pps_idx); 280 281 static bool pps_has_pp_on(struct intel_display *display, int pps_idx) 282 { 283 return intel_de_read(display, PP_STATUS(display, pps_idx)) & PP_ON; 284 } 285 286 static bool pps_has_vdd_on(struct intel_display *display, int pps_idx) 287 { 288 return intel_de_read(display, PP_CONTROL(display, pps_idx)) & EDP_FORCE_VDD; 289 } 290 291 static bool pps_any(struct intel_display *display, int pps_idx) 292 { 293 return true; 294 } 295 296 static enum pipe 297 vlv_initial_pps_pipe(struct intel_display *display, 298 enum port port, pps_check check) 299 { 300 enum pipe pipe; 301 302 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) { 303 u32 port_sel = intel_de_read(display, 304 PP_ON_DELAYS(display, pipe)) & 305 PANEL_PORT_SELECT_MASK; 306 307 if (port_sel != PANEL_PORT_SELECT_VLV(port)) 308 continue; 309 310 if (!check(display, pipe)) 311 continue; 312 313 return pipe; 314 } 315 316 return INVALID_PIPE; 317 } 318 319 static void 320 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp) 321 { 322 struct intel_display *display = to_intel_display(intel_dp); 323 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 324 enum port port = dig_port->base.port; 325 326 lockdep_assert_held(&display->pps.mutex); 327 328 /* try to find a pipe with this port selected */ 329 /* first pick one where the panel is on */ 330 intel_dp->pps.vlv_pps_pipe = vlv_initial_pps_pipe(display, port, 331 pps_has_pp_on); 332 /* didn't find one? pick one where vdd is on */ 333 if (intel_dp->pps.vlv_pps_pipe == INVALID_PIPE) 334 intel_dp->pps.vlv_pps_pipe = vlv_initial_pps_pipe(display, port, 335 pps_has_vdd_on); 336 /* didn't find one? pick one with just the correct port */ 337 if (intel_dp->pps.vlv_pps_pipe == INVALID_PIPE) 338 intel_dp->pps.vlv_pps_pipe = vlv_initial_pps_pipe(display, port, 339 pps_any); 340 341 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */ 342 if (intel_dp->pps.vlv_pps_pipe == INVALID_PIPE) { 343 drm_dbg_kms(display->drm, 344 "[ENCODER:%d:%s] no initial power sequencer\n", 345 dig_port->base.base.base.id, dig_port->base.base.name); 346 return; 347 } 348 349 drm_dbg_kms(display->drm, 350 "[ENCODER:%d:%s] initial power sequencer: %s\n", 351 dig_port->base.base.base.id, dig_port->base.base.name, 352 pps_name(intel_dp)); 353 } 354 355 static int intel_num_pps(struct intel_display *display) 356 { 357 if (display->platform.valleyview || display->platform.cherryview) 358 return 2; 359 360 if (display->platform.geminilake || display->platform.broxton) 361 return 2; 362 363 if (INTEL_PCH_TYPE(display) >= PCH_MTL) 364 return 2; 365 366 if (INTEL_PCH_TYPE(display) >= PCH_DG1) 367 return 1; 368 369 if (INTEL_PCH_TYPE(display) >= PCH_ICP) 370 return 2; 371 372 return 1; 373 } 374 375 static bool intel_pps_is_valid(struct intel_dp *intel_dp) 376 { 377 struct intel_display *display = to_intel_display(intel_dp); 378 379 if (intel_dp->pps.pps_idx == 1 && 380 INTEL_PCH_TYPE(display) >= PCH_ICP && 381 INTEL_PCH_TYPE(display) <= PCH_ADP) 382 return intel_de_read(display, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT; 383 384 return true; 385 } 386 387 static int 388 bxt_initial_pps_idx(struct intel_display *display, pps_check check) 389 { 390 int pps_idx, pps_num = intel_num_pps(display); 391 392 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { 393 if (check(display, pps_idx)) 394 return pps_idx; 395 } 396 397 return -1; 398 } 399 400 static bool 401 pps_initial_setup(struct intel_dp *intel_dp) 402 { 403 struct intel_display *display = to_intel_display(intel_dp); 404 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 405 struct intel_connector *connector = intel_dp->attached_connector; 406 407 lockdep_assert_held(&display->pps.mutex); 408 409 if (display->platform.valleyview || display->platform.cherryview) { 410 vlv_initial_power_sequencer_setup(intel_dp); 411 return true; 412 } 413 414 /* first ask the VBT */ 415 if (intel_num_pps(display) > 1) 416 intel_dp->pps.pps_idx = connector->panel.vbt.backlight.controller; 417 else 418 intel_dp->pps.pps_idx = 0; 419 420 if (drm_WARN_ON(display->drm, intel_dp->pps.pps_idx >= intel_num_pps(display))) 421 intel_dp->pps.pps_idx = -1; 422 423 /* VBT wasn't parsed yet? pick one where the panel is on */ 424 if (intel_dp->pps.pps_idx < 0) 425 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_has_pp_on); 426 /* didn't find one? pick one where vdd is on */ 427 if (intel_dp->pps.pps_idx < 0) 428 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_has_vdd_on); 429 /* didn't find one? pick any */ 430 if (intel_dp->pps.pps_idx < 0) { 431 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_any); 432 433 drm_dbg_kms(display->drm, 434 "[ENCODER:%d:%s] no initial power sequencer, assuming %s\n", 435 encoder->base.base.id, encoder->base.name, 436 pps_name(intel_dp)); 437 } else { 438 drm_dbg_kms(display->drm, 439 "[ENCODER:%d:%s] initial power sequencer: %s\n", 440 encoder->base.base.id, encoder->base.name, 441 pps_name(intel_dp)); 442 } 443 444 return intel_pps_is_valid(intel_dp); 445 } 446 447 void vlv_pps_reset_all(struct intel_display *display) 448 { 449 struct intel_encoder *encoder; 450 451 if (!HAS_DISPLAY(display)) 452 return; 453 454 /* 455 * We can't grab pps_mutex here due to deadlock with power_domain 456 * mutex when power_domain functions are called while holding pps_mutex. 457 * That also means that in order to use vlv_pps_pipe the code needs to 458 * hold both a power domain reference and pps_mutex, and the power domain 459 * reference get/put must be done while _not_ holding pps_mutex. 460 * pps_{lock,unlock}() do these steps in the correct order, so one 461 * should use them always. 462 */ 463 464 for_each_intel_dp(display->drm, encoder) { 465 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 466 467 drm_WARN_ON(display->drm, intel_dp->pps.vlv_active_pipe != INVALID_PIPE); 468 469 if (encoder->type == INTEL_OUTPUT_EDP) 470 intel_dp->pps.vlv_pps_pipe = INVALID_PIPE; 471 } 472 } 473 474 void bxt_pps_reset_all(struct intel_display *display) 475 { 476 struct intel_encoder *encoder; 477 478 if (!HAS_DISPLAY(display)) 479 return; 480 481 /* See vlv_pps_reset_all() for why we can't grab pps_mutex here. */ 482 483 for_each_intel_dp(display->drm, encoder) { 484 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 485 486 if (encoder->type == INTEL_OUTPUT_EDP) 487 intel_dp->pps.bxt_pps_reset = true; 488 } 489 } 490 491 struct pps_registers { 492 intel_reg_t pp_ctrl; 493 intel_reg_t pp_stat; 494 intel_reg_t pp_on; 495 intel_reg_t pp_off; 496 intel_reg_t pp_div; 497 }; 498 499 static void intel_pps_get_registers(struct intel_dp *intel_dp, 500 struct pps_registers *regs) 501 { 502 struct intel_display *display = to_intel_display(intel_dp); 503 int pps_idx; 504 505 memset(regs, 0, sizeof(*regs)); 506 507 if (display->platform.valleyview || display->platform.cherryview) 508 pps_idx = vlv_power_sequencer_pipe(intel_dp); 509 else if (display->platform.geminilake || display->platform.broxton) 510 pps_idx = bxt_power_sequencer_idx(intel_dp); 511 else 512 pps_idx = intel_dp->pps.pps_idx; 513 514 regs->pp_ctrl = PP_CONTROL(display, pps_idx); 515 regs->pp_stat = PP_STATUS(display, pps_idx); 516 regs->pp_on = PP_ON_DELAYS(display, pps_idx); 517 regs->pp_off = PP_OFF_DELAYS(display, pps_idx); 518 519 /* Cycle delay moved from PP_DIVISOR to PP_CONTROL */ 520 if (display->platform.geminilake || display->platform.broxton || 521 INTEL_PCH_TYPE(display) >= PCH_CNP) 522 regs->pp_div = INVALID_MMIO_REG; 523 else 524 regs->pp_div = PP_DIVISOR(display, pps_idx); 525 } 526 527 static intel_reg_t 528 _pp_ctrl_reg(struct intel_dp *intel_dp) 529 { 530 struct pps_registers regs; 531 532 intel_pps_get_registers(intel_dp, ®s); 533 534 return regs.pp_ctrl; 535 } 536 537 static intel_reg_t 538 _pp_stat_reg(struct intel_dp *intel_dp) 539 { 540 struct pps_registers regs; 541 542 intel_pps_get_registers(intel_dp, ®s); 543 544 return regs.pp_stat; 545 } 546 547 static bool edp_have_panel_power(struct intel_dp *intel_dp) 548 { 549 struct intel_display *display = to_intel_display(intel_dp); 550 551 lockdep_assert_held(&display->pps.mutex); 552 553 if ((display->platform.valleyview || display->platform.cherryview) && 554 intel_dp->pps.vlv_pps_pipe == INVALID_PIPE) 555 return false; 556 557 return (intel_de_read(display, _pp_stat_reg(intel_dp)) & PP_ON) != 0; 558 } 559 560 static bool edp_have_panel_vdd(struct intel_dp *intel_dp) 561 { 562 struct intel_display *display = to_intel_display(intel_dp); 563 564 lockdep_assert_held(&display->pps.mutex); 565 566 if ((display->platform.valleyview || display->platform.cherryview) && 567 intel_dp->pps.vlv_pps_pipe == INVALID_PIPE) 568 return false; 569 570 return intel_de_read(display, _pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD; 571 } 572 573 void intel_pps_check_power_unlocked(struct intel_dp *intel_dp) 574 { 575 struct intel_display *display = to_intel_display(intel_dp); 576 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 577 578 if (!intel_dp_is_edp(intel_dp)) 579 return; 580 581 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) { 582 drm_WARN(display->drm, 1, 583 "[ENCODER:%d:%s] %s powered off while attempting AUX CH communication.\n", 584 dig_port->base.base.base.id, dig_port->base.base.name, 585 pps_name(intel_dp)); 586 drm_dbg_kms(display->drm, 587 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", 588 dig_port->base.base.base.id, dig_port->base.base.name, 589 pps_name(intel_dp), 590 intel_de_read(display, _pp_stat_reg(intel_dp)), 591 intel_de_read(display, _pp_ctrl_reg(intel_dp))); 592 } 593 } 594 595 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK) 596 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE) 597 598 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0) 599 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0) 600 601 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK) 602 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE) 603 604 static void intel_pps_verify_state(struct intel_dp *intel_dp); 605 606 static void wait_panel_status(struct intel_dp *intel_dp, 607 u32 mask, u32 value) 608 { 609 struct intel_display *display = to_intel_display(intel_dp); 610 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 611 intel_reg_t pp_stat_reg, pp_ctrl_reg; 612 int ret; 613 u32 val; 614 615 lockdep_assert_held(&display->pps.mutex); 616 617 intel_pps_verify_state(intel_dp); 618 619 pp_stat_reg = _pp_stat_reg(intel_dp); 620 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 621 622 drm_dbg_kms(display->drm, 623 "[ENCODER:%d:%s] %s mask: 0x%08x value: 0x%08x PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", 624 dig_port->base.base.base.id, dig_port->base.base.name, 625 pps_name(intel_dp), 626 mask, value, 627 intel_de_read(display, pp_stat_reg), 628 intel_de_read(display, pp_ctrl_reg)); 629 630 ret = poll_timeout_us(val = intel_de_read(display, pp_stat_reg), 631 (val & mask) == value, 632 10 * 1000, 5000 * 1000, true); 633 if (ret) { 634 drm_err(display->drm, 635 "[ENCODER:%d:%s] %s panel status timeout: PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", 636 dig_port->base.base.base.id, dig_port->base.base.name, 637 pps_name(intel_dp), 638 intel_de_read(display, pp_stat_reg), 639 intel_de_read(display, pp_ctrl_reg)); 640 return; 641 } 642 643 drm_dbg_kms(display->drm, "Wait complete\n"); 644 } 645 646 static void wait_panel_on(struct intel_dp *intel_dp) 647 { 648 struct intel_display *display = to_intel_display(intel_dp); 649 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 650 651 drm_dbg_kms(display->drm, 652 "[ENCODER:%d:%s] %s wait for panel power on\n", 653 dig_port->base.base.base.id, dig_port->base.base.name, 654 pps_name(intel_dp)); 655 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE); 656 } 657 658 static void wait_panel_off(struct intel_dp *intel_dp) 659 { 660 struct intel_display *display = to_intel_display(intel_dp); 661 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 662 663 drm_dbg_kms(display->drm, 664 "[ENCODER:%d:%s] %s wait for panel power off time\n", 665 dig_port->base.base.base.id, dig_port->base.base.name, 666 pps_name(intel_dp)); 667 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE); 668 } 669 670 static void wait_panel_power_cycle(struct intel_dp *intel_dp) 671 { 672 struct intel_display *display = to_intel_display(intel_dp); 673 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 674 ktime_t panel_power_on_time; 675 s64 panel_power_off_duration, remaining; 676 677 /* take the difference of current time and panel power off time 678 * and then make panel wait for power_cycle if needed. */ 679 panel_power_on_time = ktime_get_boottime(); 680 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->pps.panel_power_off_time); 681 682 remaining = max(0, intel_dp->pps.panel_power_cycle_delay - panel_power_off_duration); 683 684 drm_dbg_kms(display->drm, 685 "[ENCODER:%d:%s] %s wait for panel power cycle (%lld ms remaining)\n", 686 dig_port->base.base.base.id, dig_port->base.base.name, 687 pps_name(intel_dp), remaining); 688 689 /* When we disable the VDD override bit last we have to do the manual 690 * wait. */ 691 if (remaining) 692 wait_remaining_ms_from_jiffies(jiffies, remaining); 693 694 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE); 695 } 696 697 void intel_pps_wait_power_cycle(struct intel_dp *intel_dp) 698 { 699 if (!intel_dp_is_edp(intel_dp)) 700 return; 701 702 with_intel_pps_lock(intel_dp) 703 wait_panel_power_cycle(intel_dp); 704 } 705 706 static void wait_backlight_on(struct intel_dp *intel_dp) 707 { 708 wait_remaining_ms_from_jiffies(intel_dp->pps.last_power_on, 709 intel_dp->pps.backlight_on_delay); 710 } 711 712 static void edp_wait_backlight_off(struct intel_dp *intel_dp) 713 { 714 wait_remaining_ms_from_jiffies(intel_dp->pps.last_backlight_off, 715 intel_dp->pps.backlight_off_delay); 716 } 717 718 /* Read the current pp_control value, unlocking the register if it 719 * is locked 720 */ 721 722 static u32 ilk_get_pp_control(struct intel_dp *intel_dp) 723 { 724 struct intel_display *display = to_intel_display(intel_dp); 725 u32 control; 726 727 lockdep_assert_held(&display->pps.mutex); 728 729 control = intel_de_read(display, _pp_ctrl_reg(intel_dp)); 730 if (drm_WARN_ON(display->drm, !HAS_DDI(display) && 731 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) { 732 control &= ~PANEL_UNLOCK_MASK; 733 control |= PANEL_UNLOCK_REGS; 734 } 735 return control; 736 } 737 738 /* 739 * Must be paired with intel_pps_vdd_off_unlocked(). 740 * Must hold pps_mutex around the whole on/off sequence. 741 * Can be nested with intel_pps_vdd_{on,off}() calls. 742 */ 743 bool intel_pps_vdd_on_unlocked(struct intel_dp *intel_dp) 744 { 745 struct intel_display *display = to_intel_display(intel_dp); 746 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 747 u32 pp; 748 intel_reg_t pp_stat_reg, pp_ctrl_reg; 749 bool need_to_disable = !intel_dp->pps.want_panel_vdd; 750 751 if (!intel_dp_is_edp(intel_dp)) 752 return false; 753 754 lockdep_assert_held(&display->pps.mutex); 755 756 cancel_delayed_work(&intel_dp->pps.panel_vdd_work); 757 intel_dp->pps.want_panel_vdd = true; 758 759 if (edp_have_panel_vdd(intel_dp)) 760 return need_to_disable; 761 762 if (intel_encoder_is_tc(&dig_port->base)) 763 intel_tc_port_get_link(dig_port, 1); 764 765 drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref); 766 intel_dp->pps.vdd_wakeref = intel_display_power_get(display, 767 intel_aux_power_domain(dig_port)); 768 769 pp_stat_reg = _pp_stat_reg(intel_dp); 770 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 771 772 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turning VDD on\n", 773 dig_port->base.base.base.id, dig_port->base.base.name, 774 pps_name(intel_dp)); 775 776 if (!edp_have_panel_power(intel_dp)) 777 wait_panel_power_cycle(intel_dp); 778 779 pp = ilk_get_pp_control(intel_dp); 780 pp |= EDP_FORCE_VDD; 781 782 intel_de_write(display, pp_ctrl_reg, pp); 783 intel_de_posting_read(display, pp_ctrl_reg); 784 drm_dbg_kms(display->drm, 785 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", 786 dig_port->base.base.base.id, dig_port->base.base.name, 787 pps_name(intel_dp), 788 intel_de_read(display, pp_stat_reg), 789 intel_de_read(display, pp_ctrl_reg)); 790 /* 791 * If the panel wasn't on, delay before accessing aux channel 792 */ 793 if (!edp_have_panel_power(intel_dp)) { 794 drm_dbg_kms(display->drm, 795 "[ENCODER:%d:%s] %s panel power wasn't enabled\n", 796 dig_port->base.base.base.id, dig_port->base.base.name, 797 pps_name(intel_dp)); 798 msleep(intel_dp->pps.panel_power_up_delay); 799 } 800 801 return need_to_disable; 802 } 803 804 /* 805 * Must be paired with intel_pps_vdd_off() or - to disable 806 * both VDD and panel power - intel_pps_off(). 807 * Nested calls to these functions are not allowed since 808 * we drop the lock. Caller must use some higher level 809 * locking to prevent nested calls from other threads. 810 */ 811 void intel_pps_vdd_on(struct intel_dp *intel_dp) 812 { 813 struct intel_display *display = to_intel_display(intel_dp); 814 bool vdd; 815 816 if (!intel_dp_is_edp(intel_dp)) 817 return; 818 819 vdd = false; 820 with_intel_pps_lock(intel_dp) 821 vdd = intel_pps_vdd_on_unlocked(intel_dp); 822 INTEL_DISPLAY_STATE_WARN(display, !vdd, "[ENCODER:%d:%s] %s VDD already requested on\n", 823 dp_to_dig_port(intel_dp)->base.base.base.id, 824 dp_to_dig_port(intel_dp)->base.base.name, 825 pps_name(intel_dp)); 826 } 827 828 static void intel_pps_vdd_off_sync_unlocked(struct intel_dp *intel_dp) 829 { 830 struct intel_display *display = to_intel_display(intel_dp); 831 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 832 u32 pp; 833 intel_reg_t pp_stat_reg, pp_ctrl_reg; 834 835 lockdep_assert_held(&display->pps.mutex); 836 837 drm_WARN_ON(display->drm, intel_dp->pps.want_panel_vdd); 838 839 if (!edp_have_panel_vdd(intel_dp)) 840 return; 841 842 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turning VDD off\n", 843 dig_port->base.base.base.id, dig_port->base.base.name, 844 pps_name(intel_dp)); 845 846 pp = ilk_get_pp_control(intel_dp); 847 pp &= ~EDP_FORCE_VDD; 848 849 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 850 pp_stat_reg = _pp_stat_reg(intel_dp); 851 852 intel_de_write(display, pp_ctrl_reg, pp); 853 intel_de_posting_read(display, pp_ctrl_reg); 854 855 /* Make sure sequencer is idle before allowing subsequent activity */ 856 drm_dbg_kms(display->drm, 857 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n", 858 dig_port->base.base.base.id, dig_port->base.base.name, 859 pps_name(intel_dp), 860 intel_de_read(display, pp_stat_reg), 861 intel_de_read(display, pp_ctrl_reg)); 862 863 if ((pp & PANEL_POWER_ON) == 0) { 864 intel_dp->pps.panel_power_off_time = ktime_get_boottime(); 865 intel_dp_invalidate_source_oui(intel_dp); 866 } 867 868 intel_display_power_put(display, 869 intel_aux_power_domain(dig_port), 870 fetch_and_zero(&intel_dp->pps.vdd_wakeref)); 871 872 if (intel_encoder_is_tc(&dig_port->base)) 873 intel_tc_port_put_link(dig_port); 874 } 875 876 void intel_pps_vdd_off_sync(struct intel_dp *intel_dp) 877 { 878 if (!intel_dp_is_edp(intel_dp)) 879 return; 880 881 cancel_delayed_work_sync(&intel_dp->pps.panel_vdd_work); 882 /* 883 * vdd might still be enabled due to the delayed vdd off. 884 * Make sure vdd is actually turned off here. 885 */ 886 with_intel_pps_lock(intel_dp) 887 intel_pps_vdd_off_sync_unlocked(intel_dp); 888 } 889 890 static void edp_panel_vdd_work(struct work_struct *__work) 891 { 892 struct intel_pps *pps = container_of(to_delayed_work(__work), 893 struct intel_pps, panel_vdd_work); 894 struct intel_dp *intel_dp = container_of(pps, struct intel_dp, pps); 895 896 with_intel_pps_lock(intel_dp) { 897 if (!intel_dp->pps.want_panel_vdd) 898 intel_pps_vdd_off_sync_unlocked(intel_dp); 899 } 900 } 901 902 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp) 903 { 904 struct intel_display *display = to_intel_display(intel_dp); 905 unsigned long delay; 906 907 /* 908 * We may not yet know the real power sequencing delays, 909 * so keep VDD enabled until we're done with init. 910 */ 911 if (intel_dp->pps.initializing) 912 return; 913 914 /* 915 * Queue the timer to fire a long time from now (relative to the power 916 * down delay) to keep the panel power up across a sequence of 917 * operations. 918 */ 919 delay = msecs_to_jiffies(intel_dp->pps.panel_power_cycle_delay * 5); 920 queue_delayed_work(display->wq.unordered, 921 &intel_dp->pps.panel_vdd_work, delay); 922 } 923 924 /* 925 * Must be paired with edp_panel_vdd_on(). 926 * Must hold pps_mutex around the whole on/off sequence. 927 * Can be nested with intel_pps_vdd_{on,off}() calls. 928 */ 929 void intel_pps_vdd_off_unlocked(struct intel_dp *intel_dp, bool sync) 930 { 931 struct intel_display *display = to_intel_display(intel_dp); 932 933 if (!intel_dp_is_edp(intel_dp)) 934 return; 935 936 lockdep_assert_held(&display->pps.mutex); 937 938 INTEL_DISPLAY_STATE_WARN(display, !intel_dp->pps.want_panel_vdd, 939 "[ENCODER:%d:%s] %s VDD not forced on", 940 dp_to_dig_port(intel_dp)->base.base.base.id, 941 dp_to_dig_port(intel_dp)->base.base.name, 942 pps_name(intel_dp)); 943 944 intel_dp->pps.want_panel_vdd = false; 945 946 if (sync) 947 intel_pps_vdd_off_sync_unlocked(intel_dp); 948 else 949 edp_panel_vdd_schedule_off(intel_dp); 950 } 951 952 void intel_pps_vdd_off(struct intel_dp *intel_dp) 953 { 954 if (!intel_dp_is_edp(intel_dp)) 955 return; 956 957 with_intel_pps_lock(intel_dp) 958 intel_pps_vdd_off_unlocked(intel_dp, false); 959 } 960 961 void intel_pps_on_unlocked(struct intel_dp *intel_dp) 962 { 963 struct intel_display *display = to_intel_display(intel_dp); 964 u32 pp; 965 intel_reg_t pp_ctrl_reg; 966 967 lockdep_assert_held(&display->pps.mutex); 968 969 if (!intel_dp_is_edp(intel_dp)) 970 return; 971 972 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turn panel power on\n", 973 dp_to_dig_port(intel_dp)->base.base.base.id, 974 dp_to_dig_port(intel_dp)->base.base.name, 975 pps_name(intel_dp)); 976 977 if (drm_WARN(display->drm, edp_have_panel_power(intel_dp), 978 "[ENCODER:%d:%s] %s panel power already on\n", 979 dp_to_dig_port(intel_dp)->base.base.base.id, 980 dp_to_dig_port(intel_dp)->base.base.name, 981 pps_name(intel_dp))) 982 return; 983 984 wait_panel_power_cycle(intel_dp); 985 986 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 987 pp = ilk_get_pp_control(intel_dp); 988 if (display->platform.ironlake) { 989 /* ILK workaround: disable reset around power sequence */ 990 pp &= ~PANEL_POWER_RESET; 991 intel_de_write(display, pp_ctrl_reg, pp); 992 intel_de_posting_read(display, pp_ctrl_reg); 993 } 994 995 /* 996 * WA: 22019252566 997 * Disable DPLS gating around power sequence. 998 */ 999 if (IS_DISPLAY_VER(display, 13, 14)) 1000 intel_de_rmw(display, SOUTH_DSPCLK_GATE_D, 1001 0, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); 1002 1003 pp |= PANEL_POWER_ON; 1004 if (!display->platform.ironlake) 1005 pp |= PANEL_POWER_RESET; 1006 1007 intel_de_write(display, pp_ctrl_reg, pp); 1008 intel_de_posting_read(display, pp_ctrl_reg); 1009 1010 wait_panel_on(intel_dp); 1011 intel_dp->pps.last_power_on = jiffies; 1012 1013 if (IS_DISPLAY_VER(display, 13, 14)) 1014 intel_de_rmw(display, SOUTH_DSPCLK_GATE_D, 1015 PCH_DPLSUNIT_CLOCK_GATE_DISABLE, 0); 1016 1017 if (display->platform.ironlake) { 1018 pp |= PANEL_POWER_RESET; /* restore panel reset bit */ 1019 intel_de_write(display, pp_ctrl_reg, pp); 1020 intel_de_posting_read(display, pp_ctrl_reg); 1021 } 1022 } 1023 1024 void intel_pps_on(struct intel_dp *intel_dp) 1025 { 1026 if (!intel_dp_is_edp(intel_dp)) 1027 return; 1028 1029 with_intel_pps_lock(intel_dp) 1030 intel_pps_on_unlocked(intel_dp); 1031 } 1032 1033 void intel_pps_off_unlocked(struct intel_dp *intel_dp) 1034 { 1035 struct intel_display *display = to_intel_display(intel_dp); 1036 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 1037 u32 pp; 1038 intel_reg_t pp_ctrl_reg; 1039 1040 lockdep_assert_held(&display->pps.mutex); 1041 1042 if (!intel_dp_is_edp(intel_dp)) 1043 return; 1044 1045 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turn panel power off\n", 1046 dig_port->base.base.base.id, dig_port->base.base.name, 1047 pps_name(intel_dp)); 1048 1049 drm_WARN(display->drm, !intel_dp->pps.want_panel_vdd, 1050 "[ENCODER:%d:%s] %s need VDD to turn off panel\n", 1051 dig_port->base.base.base.id, dig_port->base.base.name, 1052 pps_name(intel_dp)); 1053 1054 pp = ilk_get_pp_control(intel_dp); 1055 /* We need to switch off panel power _and_ force vdd, for otherwise some 1056 * panels get very unhappy and cease to work. */ 1057 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD | 1058 EDP_BLC_ENABLE); 1059 1060 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 1061 1062 intel_dp->pps.want_panel_vdd = false; 1063 1064 intel_de_write(display, pp_ctrl_reg, pp); 1065 intel_de_posting_read(display, pp_ctrl_reg); 1066 1067 wait_panel_off(intel_dp); 1068 intel_dp->pps.panel_power_off_time = ktime_get_boottime(); 1069 1070 intel_dp_invalidate_source_oui(intel_dp); 1071 1072 /* We got a reference when we enabled the VDD. */ 1073 intel_display_power_put(display, 1074 intel_aux_power_domain(dig_port), 1075 fetch_and_zero(&intel_dp->pps.vdd_wakeref)); 1076 1077 if (intel_encoder_is_tc(&dig_port->base)) 1078 intel_tc_port_put_link(dig_port); 1079 } 1080 1081 void intel_pps_off(struct intel_dp *intel_dp) 1082 { 1083 if (!intel_dp_is_edp(intel_dp)) 1084 return; 1085 1086 with_intel_pps_lock(intel_dp) 1087 intel_pps_off_unlocked(intel_dp); 1088 } 1089 1090 /* Enable backlight in the panel power control. */ 1091 void intel_pps_backlight_on(struct intel_dp *intel_dp) 1092 { 1093 struct intel_display *display = to_intel_display(intel_dp); 1094 1095 /* 1096 * If we enable the backlight right away following a panel power 1097 * on, we may see slight flicker as the panel syncs with the eDP 1098 * link. So delay a bit to make sure the image is solid before 1099 * allowing it to appear. 1100 */ 1101 wait_backlight_on(intel_dp); 1102 1103 with_intel_pps_lock(intel_dp) { 1104 intel_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 1105 u32 pp; 1106 1107 pp = ilk_get_pp_control(intel_dp); 1108 pp |= EDP_BLC_ENABLE; 1109 1110 intel_de_write(display, pp_ctrl_reg, pp); 1111 intel_de_posting_read(display, pp_ctrl_reg); 1112 } 1113 } 1114 1115 /* Disable backlight in the panel power control. */ 1116 void intel_pps_backlight_off(struct intel_dp *intel_dp) 1117 { 1118 struct intel_display *display = to_intel_display(intel_dp); 1119 1120 if (!intel_dp_is_edp(intel_dp)) 1121 return; 1122 1123 with_intel_pps_lock(intel_dp) { 1124 intel_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 1125 u32 pp; 1126 1127 pp = ilk_get_pp_control(intel_dp); 1128 pp &= ~EDP_BLC_ENABLE; 1129 1130 intel_de_write(display, pp_ctrl_reg, pp); 1131 intel_de_posting_read(display, pp_ctrl_reg); 1132 } 1133 1134 intel_dp->pps.last_backlight_off = jiffies; 1135 edp_wait_backlight_off(intel_dp); 1136 } 1137 1138 /* 1139 * Hook for controlling the panel power control backlight through the bl_power 1140 * sysfs attribute. Take care to handle multiple calls. 1141 */ 1142 void intel_pps_backlight_power(struct intel_connector *connector, bool enable) 1143 { 1144 struct intel_display *display = to_intel_display(connector); 1145 struct intel_dp *intel_dp = intel_attached_dp(connector); 1146 bool is_enabled; 1147 1148 is_enabled = false; 1149 with_intel_pps_lock(intel_dp) 1150 is_enabled = ilk_get_pp_control(intel_dp) & EDP_BLC_ENABLE; 1151 if (is_enabled == enable) 1152 return; 1153 1154 drm_dbg_kms(display->drm, "panel power control backlight %s\n", 1155 str_enable_disable(enable)); 1156 1157 if (enable) 1158 intel_pps_backlight_on(intel_dp); 1159 else 1160 intel_pps_backlight_off(intel_dp); 1161 } 1162 1163 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp) 1164 { 1165 struct intel_display *display = to_intel_display(intel_dp); 1166 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 1167 enum pipe pipe = intel_dp->pps.vlv_pps_pipe; 1168 intel_reg_t pp_on_reg = PP_ON_DELAYS(display, pipe); 1169 1170 drm_WARN_ON(display->drm, intel_dp->pps.vlv_active_pipe != INVALID_PIPE); 1171 1172 if (drm_WARN_ON(display->drm, pipe != PIPE_A && pipe != PIPE_B)) 1173 return; 1174 1175 intel_pps_vdd_off_sync_unlocked(intel_dp); 1176 1177 /* 1178 * VLV seems to get confused when multiple power sequencers 1179 * have the same port selected (even if only one has power/vdd 1180 * enabled). The failure manifests as vlv_wait_port_ready() failing 1181 * CHV on the other hand doesn't seem to mind having the same port 1182 * selected in multiple power sequencers, but let's clear the 1183 * port select always when logically disconnecting a power sequencer 1184 * from a port. 1185 */ 1186 drm_dbg_kms(display->drm, 1187 "detaching %s from [ENCODER:%d:%s]\n", 1188 pps_name(intel_dp), 1189 dig_port->base.base.base.id, dig_port->base.base.name); 1190 intel_de_write(display, pp_on_reg, 0); 1191 intel_de_posting_read(display, pp_on_reg); 1192 1193 intel_dp->pps.vlv_pps_pipe = INVALID_PIPE; 1194 } 1195 1196 static void vlv_steal_power_sequencer(struct intel_display *display, 1197 enum pipe pipe) 1198 { 1199 struct intel_encoder *encoder; 1200 1201 lockdep_assert_held(&display->pps.mutex); 1202 1203 for_each_intel_dp(display->drm, encoder) { 1204 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1205 1206 drm_WARN(display->drm, intel_dp->pps.vlv_active_pipe == pipe, 1207 "stealing PPS %c from active [ENCODER:%d:%s]\n", 1208 pipe_name(pipe), encoder->base.base.id, 1209 encoder->base.name); 1210 1211 if (intel_dp->pps.vlv_pps_pipe != pipe) 1212 continue; 1213 1214 drm_dbg_kms(display->drm, 1215 "stealing PPS %c from [ENCODER:%d:%s]\n", 1216 pipe_name(pipe), encoder->base.base.id, 1217 encoder->base.name); 1218 1219 /* make sure vdd is off before we steal it */ 1220 vlv_detach_power_sequencer(intel_dp); 1221 } 1222 } 1223 1224 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp) 1225 { 1226 struct intel_display *display = to_intel_display(intel_dp); 1227 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 1228 enum pipe pipe; 1229 1230 if (g4x_dp_port_enabled(display, intel_dp->output_reg, 1231 encoder->port, &pipe)) 1232 return pipe; 1233 1234 return INVALID_PIPE; 1235 } 1236 1237 /* Call on all DP, not just eDP */ 1238 void vlv_pps_pipe_init(struct intel_dp *intel_dp) 1239 { 1240 intel_dp->pps.vlv_pps_pipe = INVALID_PIPE; 1241 intel_dp->pps.vlv_active_pipe = vlv_active_pipe(intel_dp); 1242 } 1243 1244 /* Call on all DP, not just eDP */ 1245 void vlv_pps_pipe_reset(struct intel_dp *intel_dp) 1246 { 1247 with_intel_pps_lock(intel_dp) 1248 intel_dp->pps.vlv_active_pipe = vlv_active_pipe(intel_dp); 1249 } 1250 1251 enum pipe vlv_pps_backlight_initial_pipe(struct intel_dp *intel_dp) 1252 { 1253 enum pipe pipe; 1254 1255 /* 1256 * Figure out the current pipe for the initial backlight setup. If the 1257 * current pipe isn't valid, try the PPS pipe, and if that fails just 1258 * assume pipe A. 1259 */ 1260 pipe = vlv_active_pipe(intel_dp); 1261 1262 if (pipe != PIPE_A && pipe != PIPE_B) 1263 pipe = intel_dp->pps.vlv_pps_pipe; 1264 1265 if (pipe != PIPE_A && pipe != PIPE_B) 1266 pipe = PIPE_A; 1267 1268 return pipe; 1269 } 1270 1271 /* Call on all DP, not just eDP */ 1272 void vlv_pps_port_enable_unlocked(struct intel_encoder *encoder, 1273 const struct intel_crtc_state *crtc_state) 1274 { 1275 struct intel_display *display = to_intel_display(encoder); 1276 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1277 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1278 1279 lockdep_assert_held(&display->pps.mutex); 1280 1281 drm_WARN_ON(display->drm, intel_dp->pps.vlv_active_pipe != INVALID_PIPE); 1282 1283 if (intel_dp->pps.vlv_pps_pipe != INVALID_PIPE && 1284 intel_dp->pps.vlv_pps_pipe != crtc->pipe) { 1285 /* 1286 * If another power sequencer was being used on this 1287 * port previously make sure to turn off vdd there while 1288 * we still have control of it. 1289 */ 1290 vlv_detach_power_sequencer(intel_dp); 1291 } 1292 1293 /* 1294 * We may be stealing the power 1295 * sequencer from another port. 1296 */ 1297 vlv_steal_power_sequencer(display, crtc->pipe); 1298 1299 intel_dp->pps.vlv_active_pipe = crtc->pipe; 1300 1301 if (!intel_dp_is_edp(intel_dp)) 1302 return; 1303 1304 /* now it's all ours */ 1305 intel_dp->pps.vlv_pps_pipe = crtc->pipe; 1306 1307 drm_dbg_kms(display->drm, 1308 "initializing %s for [ENCODER:%d:%s]\n", 1309 pps_name(intel_dp), 1310 encoder->base.base.id, encoder->base.name); 1311 1312 /* init power sequencer on this pipe and port */ 1313 pps_init_delays(intel_dp); 1314 pps_init_registers(intel_dp, true); 1315 } 1316 1317 /* Call on all DP, not just eDP */ 1318 void vlv_pps_port_disable(struct intel_encoder *encoder, 1319 const struct intel_crtc_state *crtc_state) 1320 { 1321 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1322 1323 with_intel_pps_lock(intel_dp) 1324 intel_dp->pps.vlv_active_pipe = INVALID_PIPE; 1325 } 1326 1327 static void pps_vdd_init(struct intel_dp *intel_dp) 1328 { 1329 struct intel_display *display = to_intel_display(intel_dp); 1330 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 1331 1332 lockdep_assert_held(&display->pps.mutex); 1333 1334 if (!edp_have_panel_vdd(intel_dp)) 1335 return; 1336 1337 /* 1338 * The VDD bit needs a power domain reference, so if the bit is 1339 * already enabled when we boot or resume, grab this reference and 1340 * schedule a vdd off, so we don't hold on to the reference 1341 * indefinitely. 1342 */ 1343 drm_dbg_kms(display->drm, 1344 "[ENCODER:%d:%s] %s VDD left on by BIOS, adjusting state tracking\n", 1345 dig_port->base.base.base.id, dig_port->base.base.name, 1346 pps_name(intel_dp)); 1347 1348 if (intel_encoder_is_tc(&dig_port->base)) 1349 intel_tc_port_get_link(dig_port, 1); 1350 1351 drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref); 1352 intel_dp->pps.vdd_wakeref = intel_display_power_get(display, 1353 intel_aux_power_domain(dig_port)); 1354 } 1355 1356 bool intel_pps_have_panel_power_or_vdd(struct intel_dp *intel_dp) 1357 { 1358 bool have_power = false; 1359 1360 with_intel_pps_lock(intel_dp) { 1361 have_power = edp_have_panel_power(intel_dp) || 1362 edp_have_panel_vdd(intel_dp); 1363 } 1364 1365 return have_power; 1366 } 1367 1368 static void pps_init_timestamps(struct intel_dp *intel_dp) 1369 { 1370 /* 1371 * Initialize panel power off time to 0, assuming panel power could have 1372 * been toggled between kernel boot and now only by a previously loaded 1373 * and removed i915, which has already ensured sufficient power off 1374 * delay at module remove. 1375 */ 1376 intel_dp->pps.panel_power_off_time = 0; 1377 intel_dp->pps.last_power_on = jiffies; 1378 intel_dp->pps.last_backlight_off = jiffies; 1379 } 1380 1381 static void 1382 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct intel_pps_delays *seq) 1383 { 1384 struct intel_display *display = to_intel_display(intel_dp); 1385 u32 pp_on, pp_off, pp_ctl, power_cycle_delay; 1386 struct pps_registers regs; 1387 1388 intel_pps_get_registers(intel_dp, ®s); 1389 1390 pp_ctl = ilk_get_pp_control(intel_dp); 1391 1392 /* Ensure PPS is unlocked */ 1393 if (!HAS_DDI(display)) 1394 intel_de_write(display, regs.pp_ctrl, pp_ctl); 1395 1396 pp_on = intel_de_read(display, regs.pp_on); 1397 pp_off = intel_de_read(display, regs.pp_off); 1398 1399 /* Pull timing values out of registers */ 1400 seq->power_up = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on); 1401 seq->backlight_on = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on); 1402 seq->backlight_off = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off); 1403 seq->power_down = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off); 1404 1405 if (intel_reg_valid(regs.pp_div)) { 1406 u32 pp_div; 1407 1408 pp_div = intel_de_read(display, regs.pp_div); 1409 1410 power_cycle_delay = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div); 1411 } else { 1412 power_cycle_delay = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl); 1413 } 1414 1415 /* hardware wants <delay>+1 in 100ms units */ 1416 seq->power_cycle = power_cycle_delay ? (power_cycle_delay - 1) * 1000 : 0; 1417 } 1418 1419 static void 1420 intel_pps_dump_state(struct intel_dp *intel_dp, const char *state_name, 1421 const struct intel_pps_delays *seq) 1422 { 1423 struct intel_display *display = to_intel_display(intel_dp); 1424 1425 drm_dbg_kms(display->drm, 1426 "%s power_up %d backlight_on %d backlight_off %d power_down %d power_cycle %d\n", 1427 state_name, seq->power_up, seq->backlight_on, 1428 seq->backlight_off, seq->power_down, seq->power_cycle); 1429 } 1430 1431 static void 1432 intel_pps_verify_state(struct intel_dp *intel_dp) 1433 { 1434 struct intel_display *display = to_intel_display(intel_dp); 1435 struct intel_pps_delays hw; 1436 struct intel_pps_delays *sw = &intel_dp->pps.pps_delays; 1437 1438 intel_pps_readout_hw_state(intel_dp, &hw); 1439 1440 if (hw.power_up != sw->power_up || 1441 hw.backlight_on != sw->backlight_on || 1442 hw.backlight_off != sw->backlight_off || 1443 hw.power_down != sw->power_down || 1444 hw.power_cycle != sw->power_cycle) { 1445 drm_err(display->drm, "PPS state mismatch\n"); 1446 intel_pps_dump_state(intel_dp, "sw", sw); 1447 intel_pps_dump_state(intel_dp, "hw", &hw); 1448 } 1449 } 1450 1451 static bool pps_delays_valid(struct intel_pps_delays *delays) 1452 { 1453 return delays->power_up || delays->backlight_on || delays->backlight_off || 1454 delays->power_down || delays->power_cycle; 1455 } 1456 1457 static int msecs_to_pps_units(int msecs) 1458 { 1459 /* PPS uses 100us units */ 1460 return msecs * 10; 1461 } 1462 1463 static int pps_units_to_msecs(int val) 1464 { 1465 /* PPS uses 100us units */ 1466 return DIV_ROUND_UP(val, 10); 1467 } 1468 1469 static void pps_init_delays_bios(struct intel_dp *intel_dp, 1470 struct intel_pps_delays *bios) 1471 { 1472 struct intel_display *display = to_intel_display(intel_dp); 1473 1474 lockdep_assert_held(&display->pps.mutex); 1475 1476 if (!pps_delays_valid(&intel_dp->pps.bios_pps_delays)) 1477 intel_pps_readout_hw_state(intel_dp, &intel_dp->pps.bios_pps_delays); 1478 1479 *bios = intel_dp->pps.bios_pps_delays; 1480 1481 intel_pps_dump_state(intel_dp, "bios", bios); 1482 } 1483 1484 static void pps_init_delays_vbt(struct intel_dp *intel_dp, 1485 struct intel_pps_delays *vbt) 1486 { 1487 struct intel_display *display = to_intel_display(intel_dp); 1488 struct intel_connector *connector = intel_dp->attached_connector; 1489 1490 *vbt = connector->panel.vbt.edp.pps; 1491 1492 if (!pps_delays_valid(vbt)) 1493 return; 1494 1495 /* 1496 * On Toshiba Satellite P50-C-18C system the VBT T12 delay 1497 * of 500ms appears to be too short. Occasionally the panel 1498 * just fails to power back on. Increasing the delay to 800ms 1499 * seems sufficient to avoid this problem. 1500 */ 1501 if (intel_has_quirk(display, QUIRK_INCREASE_T12_DELAY)) { 1502 vbt->power_cycle = max_t(u16, vbt->power_cycle, msecs_to_pps_units(1300)); 1503 drm_dbg_kms(display->drm, 1504 "Increasing T12 panel delay as per the quirk to %d\n", 1505 vbt->power_cycle); 1506 } 1507 1508 intel_pps_dump_state(intel_dp, "vbt", vbt); 1509 } 1510 1511 static void pps_init_delays_spec(struct intel_dp *intel_dp, 1512 struct intel_pps_delays *spec) 1513 { 1514 struct intel_display *display = to_intel_display(intel_dp); 1515 1516 lockdep_assert_held(&display->pps.mutex); 1517 1518 /* Upper limits from eDP 1.3 spec */ 1519 spec->power_up = msecs_to_pps_units(10 + 200); /* T1+T3 */ 1520 spec->backlight_on = msecs_to_pps_units(50); /* no limit for T8, use T7 instead */ 1521 spec->backlight_off = msecs_to_pps_units(50); /* no limit for T9, make it symmetric with T8 */ 1522 spec->power_down = msecs_to_pps_units(500); /* T10 */ 1523 spec->power_cycle = msecs_to_pps_units(10 + 500); /* T11+T12 */ 1524 1525 intel_pps_dump_state(intel_dp, "spec", spec); 1526 } 1527 1528 static void pps_init_delays(struct intel_dp *intel_dp) 1529 { 1530 struct intel_display *display = to_intel_display(intel_dp); 1531 struct intel_pps_delays cur, vbt, spec, 1532 *final = &intel_dp->pps.pps_delays; 1533 1534 lockdep_assert_held(&display->pps.mutex); 1535 1536 /* already initialized? */ 1537 if (pps_delays_valid(final)) 1538 return; 1539 1540 pps_init_delays_bios(intel_dp, &cur); 1541 pps_init_delays_vbt(intel_dp, &vbt); 1542 pps_init_delays_spec(intel_dp, &spec); 1543 1544 /* Use the max of the register settings and vbt. If both are 1545 * unset, fall back to the spec limits. */ 1546 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \ 1547 spec.field : \ 1548 max(cur.field, vbt.field)) 1549 assign_final(power_up); 1550 assign_final(backlight_on); 1551 assign_final(backlight_off); 1552 assign_final(power_down); 1553 assign_final(power_cycle); 1554 #undef assign_final 1555 1556 intel_dp->pps.panel_power_up_delay = pps_units_to_msecs(final->power_up); 1557 intel_dp->pps.backlight_on_delay = pps_units_to_msecs(final->backlight_on); 1558 intel_dp->pps.backlight_off_delay = pps_units_to_msecs(final->backlight_off); 1559 intel_dp->pps.panel_power_down_delay = pps_units_to_msecs(final->power_down); 1560 intel_dp->pps.panel_power_cycle_delay = pps_units_to_msecs(final->power_cycle); 1561 1562 drm_dbg_kms(display->drm, 1563 "panel power up delay %d, power down delay %d, power cycle delay %d\n", 1564 intel_dp->pps.panel_power_up_delay, 1565 intel_dp->pps.panel_power_down_delay, 1566 intel_dp->pps.panel_power_cycle_delay); 1567 1568 drm_dbg_kms(display->drm, "backlight on delay %d, off delay %d\n", 1569 intel_dp->pps.backlight_on_delay, 1570 intel_dp->pps.backlight_off_delay); 1571 1572 /* 1573 * We override the HW backlight delays to 1 because we do manual waits 1574 * on them. For backlight_on, even BSpec recommends doing it. For 1575 * backlight_off, if we don't do this, we'll end up waiting for the 1576 * backlight off delay twice: once when we do the manual sleep, and 1577 * once when we disable the panel and wait for the PP_STATUS bit to 1578 * become zero. 1579 */ 1580 final->backlight_on = 1; 1581 final->backlight_off = 1; 1582 1583 /* 1584 * HW has only a 100msec granularity for power_cycle so round it up 1585 * accordingly. 1586 */ 1587 final->power_cycle = roundup(final->power_cycle, msecs_to_pps_units(100)); 1588 } 1589 1590 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd) 1591 { 1592 struct intel_display *display = to_intel_display(intel_dp); 1593 u32 pp_on, pp_off, port_sel = 0; 1594 int div = DISPLAY_RUNTIME_INFO(display)->rawclk_freq / 1000; 1595 struct pps_registers regs; 1596 enum port port = dp_to_dig_port(intel_dp)->base.port; 1597 const struct intel_pps_delays *seq = &intel_dp->pps.pps_delays; 1598 1599 lockdep_assert_held(&display->pps.mutex); 1600 1601 intel_pps_get_registers(intel_dp, ®s); 1602 1603 /* 1604 * On some VLV machines the BIOS can leave the VDD 1605 * enabled even on power sequencers which aren't 1606 * hooked up to any port. This would mess up the 1607 * power domain tracking the first time we pick 1608 * one of these power sequencers for use since 1609 * intel_pps_vdd_on_unlocked() would notice that the VDD was 1610 * already on and therefore wouldn't grab the power 1611 * domain reference. Disable VDD first to avoid this. 1612 * This also avoids spuriously turning the VDD on as 1613 * soon as the new power sequencer gets initialized. 1614 */ 1615 if (force_disable_vdd) { 1616 u32 pp = ilk_get_pp_control(intel_dp); 1617 1618 drm_WARN(display->drm, pp & PANEL_POWER_ON, 1619 "Panel power already on\n"); 1620 1621 if (pp & EDP_FORCE_VDD) 1622 drm_dbg_kms(display->drm, 1623 "VDD already on, disabling first\n"); 1624 1625 pp &= ~EDP_FORCE_VDD; 1626 1627 intel_de_write(display, regs.pp_ctrl, pp); 1628 } 1629 1630 pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->power_up) | 1631 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->backlight_on); 1632 pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->backlight_off) | 1633 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->power_down); 1634 1635 /* Haswell doesn't have any port selection bits for the panel 1636 * power sequencer any more. */ 1637 if (display->platform.valleyview || display->platform.cherryview) { 1638 port_sel = PANEL_PORT_SELECT_VLV(port); 1639 } else if (HAS_PCH_IBX(display) || HAS_PCH_CPT(display)) { 1640 switch (port) { 1641 case PORT_A: 1642 port_sel = PANEL_PORT_SELECT_DPA; 1643 break; 1644 case PORT_C: 1645 port_sel = PANEL_PORT_SELECT_DPC; 1646 break; 1647 case PORT_D: 1648 port_sel = PANEL_PORT_SELECT_DPD; 1649 break; 1650 default: 1651 MISSING_CASE(port); 1652 break; 1653 } 1654 } 1655 1656 pp_on |= port_sel; 1657 1658 intel_de_write(display, regs.pp_on, pp_on); 1659 intel_de_write(display, regs.pp_off, pp_off); 1660 1661 /* 1662 * Compute the divisor for the pp clock, simply match the Bspec formula. 1663 */ 1664 if (intel_reg_valid(regs.pp_div)) 1665 intel_de_write(display, regs.pp_div, 1666 REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, 1667 (100 * div) / 2 - 1) | 1668 REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, 1669 DIV_ROUND_UP(seq->power_cycle, 1000) + 1)); 1670 else 1671 intel_de_rmw(display, regs.pp_ctrl, BXT_POWER_CYCLE_DELAY_MASK, 1672 REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK, 1673 DIV_ROUND_UP(seq->power_cycle, 1000) + 1)); 1674 1675 drm_dbg_kms(display->drm, 1676 "panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n", 1677 intel_de_read(display, regs.pp_on), 1678 intel_de_read(display, regs.pp_off), 1679 intel_reg_valid(regs.pp_div) ? 1680 intel_de_read(display, regs.pp_div) : 1681 (intel_de_read(display, regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK)); 1682 } 1683 1684 void intel_pps_encoder_reset(struct intel_dp *intel_dp) 1685 { 1686 struct intel_display *display = to_intel_display(intel_dp); 1687 1688 if (!intel_dp_is_edp(intel_dp)) 1689 return; 1690 1691 with_intel_pps_lock(intel_dp) { 1692 /* 1693 * Reinit the power sequencer also on the resume path, in case 1694 * BIOS did something nasty with it. 1695 */ 1696 if (display->platform.valleyview || display->platform.cherryview) 1697 vlv_initial_power_sequencer_setup(intel_dp); 1698 1699 pps_init_delays(intel_dp); 1700 pps_init_registers(intel_dp, false); 1701 pps_vdd_init(intel_dp); 1702 1703 if (edp_have_panel_vdd(intel_dp)) 1704 edp_panel_vdd_schedule_off(intel_dp); 1705 } 1706 } 1707 1708 bool intel_pps_init(struct intel_dp *intel_dp) 1709 { 1710 bool ret; 1711 1712 intel_dp->pps.initializing = true; 1713 INIT_DELAYED_WORK(&intel_dp->pps.panel_vdd_work, edp_panel_vdd_work); 1714 1715 pps_init_timestamps(intel_dp); 1716 1717 with_intel_pps_lock(intel_dp) { 1718 ret = pps_initial_setup(intel_dp); 1719 1720 pps_init_delays(intel_dp); 1721 pps_init_registers(intel_dp, false); 1722 pps_vdd_init(intel_dp); 1723 } 1724 1725 return ret; 1726 } 1727 1728 static void pps_init_late(struct intel_dp *intel_dp) 1729 { 1730 struct intel_display *display = to_intel_display(intel_dp); 1731 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 1732 struct intel_connector *connector = intel_dp->attached_connector; 1733 1734 if (display->platform.valleyview || display->platform.cherryview) 1735 return; 1736 1737 if (intel_num_pps(display) < 2) 1738 return; 1739 1740 drm_WARN(display->drm, 1741 connector->panel.vbt.backlight.controller >= 0 && 1742 intel_dp->pps.pps_idx != connector->panel.vbt.backlight.controller, 1743 "[ENCODER:%d:%s] power sequencer mismatch: %d (initial) vs. %d (VBT)\n", 1744 encoder->base.base.id, encoder->base.name, 1745 intel_dp->pps.pps_idx, connector->panel.vbt.backlight.controller); 1746 1747 if (connector->panel.vbt.backlight.controller >= 0) 1748 intel_dp->pps.pps_idx = connector->panel.vbt.backlight.controller; 1749 } 1750 1751 void intel_pps_init_late(struct intel_dp *intel_dp) 1752 { 1753 with_intel_pps_lock(intel_dp) { 1754 /* Reinit delays after per-panel info has been parsed from VBT */ 1755 pps_init_late(intel_dp); 1756 1757 memset(&intel_dp->pps.pps_delays, 0, sizeof(intel_dp->pps.pps_delays)); 1758 pps_init_delays(intel_dp); 1759 pps_init_registers(intel_dp, false); 1760 1761 intel_dp->pps.initializing = false; 1762 1763 if (edp_have_panel_vdd(intel_dp)) 1764 edp_panel_vdd_schedule_off(intel_dp); 1765 } 1766 } 1767 1768 void intel_pps_unlock_regs_wa(struct intel_display *display) 1769 { 1770 int pps_num; 1771 int pps_idx; 1772 1773 if (!HAS_DISPLAY(display) || HAS_DDI(display)) 1774 return; 1775 /* 1776 * This w/a is needed at least on CPT/PPT, but to be sure apply it 1777 * everywhere where registers can be write protected. 1778 */ 1779 pps_num = intel_num_pps(display); 1780 1781 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) 1782 intel_de_rmw(display, PP_CONTROL(display, pps_idx), 1783 PANEL_UNLOCK_MASK, PANEL_UNLOCK_REGS); 1784 } 1785 1786 void intel_pps_setup(struct intel_display *display) 1787 { 1788 if (HAS_PCH_SPLIT(display) || display->platform.geminilake || display->platform.broxton) 1789 display->pps.mmio_base = PCH_PPS_BASE; 1790 else if (display->platform.valleyview || display->platform.cherryview) 1791 display->pps.mmio_base = VLV_PPS_BASE; 1792 else 1793 display->pps.mmio_base = PPS_BASE; 1794 } 1795 1796 static int intel_pps_show(struct seq_file *m, void *data) 1797 { 1798 struct intel_connector *connector = m->private; 1799 struct intel_dp *intel_dp = intel_attached_dp(connector); 1800 1801 if (connector->base.status != connector_status_connected) 1802 return -ENODEV; 1803 1804 seq_printf(m, "Panel power up delay: %d\n", 1805 intel_dp->pps.panel_power_up_delay); 1806 seq_printf(m, "Panel power down delay: %d\n", 1807 intel_dp->pps.panel_power_down_delay); 1808 seq_printf(m, "Panel power cycle delay: %d\n", 1809 intel_dp->pps.panel_power_cycle_delay); 1810 seq_printf(m, "Backlight on delay: %d\n", 1811 intel_dp->pps.backlight_on_delay); 1812 seq_printf(m, "Backlight off delay: %d\n", 1813 intel_dp->pps.backlight_off_delay); 1814 1815 return 0; 1816 } 1817 DEFINE_SHOW_ATTRIBUTE(intel_pps); 1818 1819 void intel_pps_connector_debugfs_add(struct intel_connector *connector) 1820 { 1821 struct dentry *root = connector->base.debugfs_entry; 1822 int connector_type = connector->base.connector_type; 1823 1824 if (connector_type == DRM_MODE_CONNECTOR_eDP) 1825 debugfs_create_file("i915_panel_timings", 0444, root, 1826 connector, &intel_pps_fops); 1827 } 1828 1829 void assert_pps_unlocked(struct intel_display *display, enum pipe pipe) 1830 { 1831 intel_reg_t pp_reg; 1832 u32 val; 1833 enum pipe panel_pipe = INVALID_PIPE; 1834 bool locked = true; 1835 1836 if (drm_WARN_ON(display->drm, HAS_DDI(display))) 1837 return; 1838 1839 if (HAS_PCH_SPLIT(display)) { 1840 u32 port_sel; 1841 1842 pp_reg = PP_CONTROL(display, 0); 1843 port_sel = intel_de_read(display, PP_ON_DELAYS(display, 0)) & 1844 PANEL_PORT_SELECT_MASK; 1845 1846 switch (port_sel) { 1847 case PANEL_PORT_SELECT_LVDS: 1848 intel_lvds_port_enabled(display, PCH_LVDS, &panel_pipe); 1849 break; 1850 case PANEL_PORT_SELECT_DPA: 1851 g4x_dp_port_enabled(display, DP_A, PORT_A, &panel_pipe); 1852 break; 1853 case PANEL_PORT_SELECT_DPC: 1854 g4x_dp_port_enabled(display, PCH_DP_C, PORT_C, &panel_pipe); 1855 break; 1856 case PANEL_PORT_SELECT_DPD: 1857 g4x_dp_port_enabled(display, PCH_DP_D, PORT_D, &panel_pipe); 1858 break; 1859 default: 1860 MISSING_CASE(port_sel); 1861 break; 1862 } 1863 } else if (display->platform.valleyview || display->platform.cherryview) { 1864 /* presumably write lock depends on pipe, not port select */ 1865 pp_reg = PP_CONTROL(display, pipe); 1866 panel_pipe = pipe; 1867 } else { 1868 u32 port_sel; 1869 1870 pp_reg = PP_CONTROL(display, 0); 1871 port_sel = intel_de_read(display, PP_ON_DELAYS(display, 0)) & 1872 PANEL_PORT_SELECT_MASK; 1873 1874 drm_WARN_ON(display->drm, 1875 port_sel != PANEL_PORT_SELECT_LVDS); 1876 intel_lvds_port_enabled(display, LVDS, &panel_pipe); 1877 } 1878 1879 val = intel_de_read(display, pp_reg); 1880 if (!(val & PANEL_POWER_ON) || 1881 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) 1882 locked = false; 1883 1884 INTEL_DISPLAY_STATE_WARN(display, panel_pipe == pipe && locked, 1885 "panel assertion failure, pipe %c regs locked\n", 1886 pipe_name(pipe)); 1887 } 1888