1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
10 #include "intel_display_power_well.h"
11 #include "intel_display_types.h"
13 #include "intel_dpio_phy.h"
14 #include "intel_dpll.h"
15 #include "intel_lvds.h"
16 #include "intel_lvds_regs.h"
17 #include "intel_pps.h"
18 #include "intel_pps_regs.h"
19 #include "intel_quirks.h"
21 static void vlv_steal_power_sequencer(struct intel_display *display,
24 static void pps_init_delays(struct intel_dp *intel_dp);
25 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd);
27 static const char *pps_name(struct intel_dp *intel_dp)
29 struct intel_display *display = to_intel_display(intel_dp);
30 struct drm_i915_private *i915 = to_i915(display->drm);
31 struct intel_pps *pps = &intel_dp->pps;
33 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) {
34 switch (pps->pps_pipe) {
37 * FIXME would be nice if we can guarantee
38 * to always have a valid PPS when calling this.
46 MISSING_CASE(pps->pps_pipe);
50 switch (pps->pps_idx) {
56 MISSING_CASE(pps->pps_idx);
61 return "PPS <invalid>";
64 intel_wakeref_t intel_pps_lock(struct intel_dp *intel_dp)
66 struct intel_display *display = to_intel_display(intel_dp);
67 struct drm_i915_private *dev_priv = to_i915(display->drm);
68 intel_wakeref_t wakeref;
71 * See intel_pps_reset_all() why we need a power domain reference here.
73 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DISPLAY_CORE);
74 mutex_lock(&display->pps.mutex);
79 intel_wakeref_t intel_pps_unlock(struct intel_dp *intel_dp,
80 intel_wakeref_t wakeref)
82 struct intel_display *display = to_intel_display(intel_dp);
83 struct drm_i915_private *dev_priv = to_i915(display->drm);
85 mutex_unlock(&display->pps.mutex);
86 intel_display_power_put(dev_priv, POWER_DOMAIN_DISPLAY_CORE, wakeref);
92 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
94 struct intel_display *display = to_intel_display(intel_dp);
95 struct drm_i915_private *dev_priv = to_i915(display->drm);
96 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
97 enum pipe pipe = intel_dp->pps.pps_pipe;
98 bool pll_enabled, release_cl_override = false;
99 enum dpio_phy phy = vlv_pipe_to_phy(pipe);
100 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
103 if (drm_WARN(display->drm,
104 intel_de_read(display, intel_dp->output_reg) & DP_PORT_EN,
105 "skipping %s kick due to [ENCODER:%d:%s] being active\n",
107 dig_port->base.base.base.id, dig_port->base.base.name))
110 drm_dbg_kms(display->drm,
111 "kicking %s for [ENCODER:%d:%s]\n",
113 dig_port->base.base.base.id, dig_port->base.base.name);
115 /* Preserve the BIOS-computed detected bit. This is
116 * supposed to be read-only.
118 DP = intel_de_read(display, intel_dp->output_reg) & DP_DETECTED;
119 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
120 DP |= DP_PORT_WIDTH(1);
121 DP |= DP_LINK_TRAIN_PAT_1;
123 if (IS_CHERRYVIEW(dev_priv))
124 DP |= DP_PIPE_SEL_CHV(pipe);
126 DP |= DP_PIPE_SEL(pipe);
128 pll_enabled = intel_de_read(display, DPLL(display, pipe)) & DPLL_VCO_ENABLE;
131 * The DPLL for the pipe must be enabled for this to work.
132 * So enable temporarily it if it's not already enabled.
135 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
136 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
138 if (vlv_force_pll_on(dev_priv, pipe, vlv_get_dpll(dev_priv))) {
139 drm_err(display->drm,
140 "Failed to force on PLL for pipe %c!\n",
147 * Similar magic as in intel_dp_enable_port().
148 * We _must_ do this port enable + disable trick
149 * to make this power sequencer lock onto the port.
150 * Otherwise even VDD force bit won't work.
152 intel_de_write(display, intel_dp->output_reg, DP);
153 intel_de_posting_read(display, intel_dp->output_reg);
155 intel_de_write(display, intel_dp->output_reg, DP | DP_PORT_EN);
156 intel_de_posting_read(display, intel_dp->output_reg);
158 intel_de_write(display, intel_dp->output_reg, DP & ~DP_PORT_EN);
159 intel_de_posting_read(display, intel_dp->output_reg);
162 vlv_force_pll_off(dev_priv, pipe);
164 if (release_cl_override)
165 chv_phy_powergate_ch(dev_priv, phy, ch, false);
169 static enum pipe vlv_find_free_pps(struct intel_display *display)
171 struct intel_encoder *encoder;
172 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
175 * We don't have power sequencer currently.
176 * Pick one that's not used by other ports.
178 for_each_intel_dp(display->drm, encoder) {
179 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
181 if (encoder->type == INTEL_OUTPUT_EDP) {
182 drm_WARN_ON(display->drm,
183 intel_dp->pps.active_pipe != INVALID_PIPE &&
184 intel_dp->pps.active_pipe !=
185 intel_dp->pps.pps_pipe);
187 if (intel_dp->pps.pps_pipe != INVALID_PIPE)
188 pipes &= ~(1 << intel_dp->pps.pps_pipe);
190 drm_WARN_ON(display->drm,
191 intel_dp->pps.pps_pipe != INVALID_PIPE);
193 if (intel_dp->pps.active_pipe != INVALID_PIPE)
194 pipes &= ~(1 << intel_dp->pps.active_pipe);
201 return ffs(pipes) - 1;
205 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
207 struct intel_display *display = to_intel_display(intel_dp);
208 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
211 lockdep_assert_held(&display->pps.mutex);
213 /* We should never land here with regular DP ports */
214 drm_WARN_ON(display->drm, !intel_dp_is_edp(intel_dp));
216 drm_WARN_ON(display->drm, intel_dp->pps.active_pipe != INVALID_PIPE &&
217 intel_dp->pps.active_pipe != intel_dp->pps.pps_pipe);
219 if (intel_dp->pps.pps_pipe != INVALID_PIPE)
220 return intel_dp->pps.pps_pipe;
222 pipe = vlv_find_free_pps(display);
225 * Didn't find one. This should not happen since there
226 * are two power sequencers and up to two eDP ports.
228 if (drm_WARN_ON(display->drm, pipe == INVALID_PIPE))
231 vlv_steal_power_sequencer(display, pipe);
232 intel_dp->pps.pps_pipe = pipe;
234 drm_dbg_kms(display->drm,
235 "picked %s for [ENCODER:%d:%s]\n",
237 dig_port->base.base.base.id, dig_port->base.base.name);
239 /* init power sequencer on this pipe and port */
240 pps_init_delays(intel_dp);
241 pps_init_registers(intel_dp, true);
244 * Even vdd force doesn't work until we've made
245 * the power sequencer lock in on the port.
247 vlv_power_sequencer_kick(intel_dp);
249 return intel_dp->pps.pps_pipe;
253 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
255 struct intel_display *display = to_intel_display(intel_dp);
256 int pps_idx = intel_dp->pps.pps_idx;
258 lockdep_assert_held(&display->pps.mutex);
260 /* We should never land here with regular DP ports */
261 drm_WARN_ON(display->drm, !intel_dp_is_edp(intel_dp));
263 if (!intel_dp->pps.pps_reset)
266 intel_dp->pps.pps_reset = false;
269 * Only the HW needs to be reprogrammed, the SW state is fixed and
270 * has been setup during connector init.
272 pps_init_registers(intel_dp, false);
277 typedef bool (*pps_check)(struct intel_display *display, int pps_idx);
279 static bool pps_has_pp_on(struct intel_display *display, int pps_idx)
281 return intel_de_read(display, PP_STATUS(display, pps_idx)) & PP_ON;
284 static bool pps_has_vdd_on(struct intel_display *display, int pps_idx)
286 return intel_de_read(display, PP_CONTROL(display, pps_idx)) & EDP_FORCE_VDD;
289 static bool pps_any(struct intel_display *display, int pps_idx)
295 vlv_initial_pps_pipe(struct intel_display *display,
296 enum port port, pps_check check)
300 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
301 u32 port_sel = intel_de_read(display,
302 PP_ON_DELAYS(display, pipe)) &
303 PANEL_PORT_SELECT_MASK;
305 if (port_sel != PANEL_PORT_SELECT_VLV(port))
308 if (!check(display, pipe))
318 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
320 struct intel_display *display = to_intel_display(intel_dp);
321 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
322 enum port port = dig_port->base.port;
324 lockdep_assert_held(&display->pps.mutex);
326 /* try to find a pipe with this port selected */
327 /* first pick one where the panel is on */
328 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(display, port,
330 /* didn't find one? pick one where vdd is on */
331 if (intel_dp->pps.pps_pipe == INVALID_PIPE)
332 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(display, port,
334 /* didn't find one? pick one with just the correct port */
335 if (intel_dp->pps.pps_pipe == INVALID_PIPE)
336 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(display, port,
339 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
340 if (intel_dp->pps.pps_pipe == INVALID_PIPE) {
341 drm_dbg_kms(display->drm,
342 "[ENCODER:%d:%s] no initial power sequencer\n",
343 dig_port->base.base.base.id, dig_port->base.base.name);
347 drm_dbg_kms(display->drm,
348 "[ENCODER:%d:%s] initial power sequencer: %s\n",
349 dig_port->base.base.base.id, dig_port->base.base.name,
353 static int intel_num_pps(struct intel_display *display)
355 struct drm_i915_private *i915 = to_i915(display->drm);
357 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
360 if (IS_GEMINILAKE(i915) || IS_BROXTON(i915))
363 if (INTEL_PCH_TYPE(i915) >= PCH_MTL)
366 if (INTEL_PCH_TYPE(i915) >= PCH_DG1)
369 if (INTEL_PCH_TYPE(i915) >= PCH_ICP)
375 static bool intel_pps_is_valid(struct intel_dp *intel_dp)
377 struct intel_display *display = to_intel_display(intel_dp);
378 struct drm_i915_private *i915 = to_i915(display->drm);
380 if (intel_dp->pps.pps_idx == 1 &&
381 INTEL_PCH_TYPE(i915) >= PCH_ICP &&
382 INTEL_PCH_TYPE(i915) <= PCH_ADP)
383 return intel_de_read(display, SOUTH_CHICKEN1) & ICP_SECOND_PPS_IO_SELECT;
389 bxt_initial_pps_idx(struct intel_display *display, pps_check check)
391 int pps_idx, pps_num = intel_num_pps(display);
393 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
394 if (check(display, pps_idx))
402 pps_initial_setup(struct intel_dp *intel_dp)
404 struct intel_display *display = to_intel_display(intel_dp);
405 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
406 struct intel_connector *connector = intel_dp->attached_connector;
407 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
409 lockdep_assert_held(&display->pps.mutex);
411 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) {
412 vlv_initial_power_sequencer_setup(intel_dp);
416 /* first ask the VBT */
417 if (intel_num_pps(display) > 1)
418 intel_dp->pps.pps_idx = connector->panel.vbt.backlight.controller;
420 intel_dp->pps.pps_idx = 0;
422 if (drm_WARN_ON(display->drm, intel_dp->pps.pps_idx >= intel_num_pps(display)))
423 intel_dp->pps.pps_idx = -1;
425 /* VBT wasn't parsed yet? pick one where the panel is on */
426 if (intel_dp->pps.pps_idx < 0)
427 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_has_pp_on);
428 /* didn't find one? pick one where vdd is on */
429 if (intel_dp->pps.pps_idx < 0)
430 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_has_vdd_on);
431 /* didn't find one? pick any */
432 if (intel_dp->pps.pps_idx < 0) {
433 intel_dp->pps.pps_idx = bxt_initial_pps_idx(display, pps_any);
435 drm_dbg_kms(display->drm,
436 "[ENCODER:%d:%s] no initial power sequencer, assuming %s\n",
437 encoder->base.base.id, encoder->base.name,
440 drm_dbg_kms(display->drm,
441 "[ENCODER:%d:%s] initial power sequencer: %s\n",
442 encoder->base.base.id, encoder->base.name,
446 return intel_pps_is_valid(intel_dp);
449 void intel_pps_reset_all(struct intel_display *display)
451 struct drm_i915_private *dev_priv = to_i915(display->drm);
452 struct intel_encoder *encoder;
454 if (drm_WARN_ON(display->drm, !IS_LP(dev_priv)))
457 if (!HAS_DISPLAY(display))
461 * We can't grab pps_mutex here due to deadlock with power_domain
462 * mutex when power_domain functions are called while holding pps_mutex.
463 * That also means that in order to use pps_pipe the code needs to
464 * hold both a power domain reference and pps_mutex, and the power domain
465 * reference get/put must be done while _not_ holding pps_mutex.
466 * pps_{lock,unlock}() do these steps in the correct order, so one
467 * should use them always.
470 for_each_intel_dp(display->drm, encoder) {
471 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
473 drm_WARN_ON(display->drm,
474 intel_dp->pps.active_pipe != INVALID_PIPE);
476 if (encoder->type != INTEL_OUTPUT_EDP)
479 if (DISPLAY_VER(display) >= 9)
480 intel_dp->pps.pps_reset = true;
482 intel_dp->pps.pps_pipe = INVALID_PIPE;
486 struct pps_registers {
494 static void intel_pps_get_registers(struct intel_dp *intel_dp,
495 struct pps_registers *regs)
497 struct intel_display *display = to_intel_display(intel_dp);
498 struct drm_i915_private *dev_priv = to_i915(display->drm);
501 memset(regs, 0, sizeof(*regs));
503 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
504 pps_idx = vlv_power_sequencer_pipe(intel_dp);
505 else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
506 pps_idx = bxt_power_sequencer_idx(intel_dp);
508 pps_idx = intel_dp->pps.pps_idx;
510 regs->pp_ctrl = PP_CONTROL(display, pps_idx);
511 regs->pp_stat = PP_STATUS(display, pps_idx);
512 regs->pp_on = PP_ON_DELAYS(display, pps_idx);
513 regs->pp_off = PP_OFF_DELAYS(display, pps_idx);
515 /* Cycle delay moved from PP_DIVISOR to PP_CONTROL */
516 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ||
517 INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
518 regs->pp_div = INVALID_MMIO_REG;
520 regs->pp_div = PP_DIVISOR(display, pps_idx);
524 _pp_ctrl_reg(struct intel_dp *intel_dp)
526 struct pps_registers regs;
528 intel_pps_get_registers(intel_dp, ®s);
534 _pp_stat_reg(struct intel_dp *intel_dp)
536 struct pps_registers regs;
538 intel_pps_get_registers(intel_dp, ®s);
543 static bool edp_have_panel_power(struct intel_dp *intel_dp)
545 struct intel_display *display = to_intel_display(intel_dp);
546 struct drm_i915_private *dev_priv = to_i915(display->drm);
548 lockdep_assert_held(&display->pps.mutex);
550 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
551 intel_dp->pps.pps_pipe == INVALID_PIPE)
554 return (intel_de_read(display, _pp_stat_reg(intel_dp)) & PP_ON) != 0;
557 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
559 struct intel_display *display = to_intel_display(intel_dp);
560 struct drm_i915_private *dev_priv = to_i915(display->drm);
562 lockdep_assert_held(&display->pps.mutex);
564 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
565 intel_dp->pps.pps_pipe == INVALID_PIPE)
568 return intel_de_read(display, _pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
571 void intel_pps_check_power_unlocked(struct intel_dp *intel_dp)
573 struct intel_display *display = to_intel_display(intel_dp);
574 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
576 if (!intel_dp_is_edp(intel_dp))
579 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
580 drm_WARN(display->drm, 1,
581 "[ENCODER:%d:%s] %s powered off while attempting AUX CH communication.\n",
582 dig_port->base.base.base.id, dig_port->base.base.name,
584 drm_dbg_kms(display->drm,
585 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
586 dig_port->base.base.base.id, dig_port->base.base.name,
588 intel_de_read(display, _pp_stat_reg(intel_dp)),
589 intel_de_read(display, _pp_ctrl_reg(intel_dp)));
593 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
594 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
596 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
597 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
599 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
600 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
602 static void intel_pps_verify_state(struct intel_dp *intel_dp);
604 static void wait_panel_status(struct intel_dp *intel_dp,
607 struct intel_display *display = to_intel_display(intel_dp);
608 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
609 i915_reg_t pp_stat_reg, pp_ctrl_reg;
611 lockdep_assert_held(&display->pps.mutex);
613 intel_pps_verify_state(intel_dp);
615 pp_stat_reg = _pp_stat_reg(intel_dp);
616 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
618 drm_dbg_kms(display->drm,
619 "[ENCODER:%d:%s] %s mask: 0x%08x value: 0x%08x PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
620 dig_port->base.base.base.id, dig_port->base.base.name,
623 intel_de_read(display, pp_stat_reg),
624 intel_de_read(display, pp_ctrl_reg));
626 if (intel_de_wait(display, pp_stat_reg, mask, value, 5000))
627 drm_err(display->drm,
628 "[ENCODER:%d:%s] %s panel status timeout: PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
629 dig_port->base.base.base.id, dig_port->base.base.name,
631 intel_de_read(display, pp_stat_reg),
632 intel_de_read(display, pp_ctrl_reg));
634 drm_dbg_kms(display->drm, "Wait complete\n");
637 static void wait_panel_on(struct intel_dp *intel_dp)
639 struct intel_display *display = to_intel_display(intel_dp);
640 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
642 drm_dbg_kms(display->drm,
643 "[ENCODER:%d:%s] %s wait for panel power on\n",
644 dig_port->base.base.base.id, dig_port->base.base.name,
646 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
649 static void wait_panel_off(struct intel_dp *intel_dp)
651 struct intel_display *display = to_intel_display(intel_dp);
652 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
654 drm_dbg_kms(display->drm,
655 "[ENCODER:%d:%s] %s wait for panel power off time\n",
656 dig_port->base.base.base.id, dig_port->base.base.name,
658 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
661 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
663 struct intel_display *display = to_intel_display(intel_dp);
664 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
665 ktime_t panel_power_on_time;
666 s64 panel_power_off_duration;
668 drm_dbg_kms(display->drm,
669 "[ENCODER:%d:%s] %s wait for panel power cycle\n",
670 dig_port->base.base.base.id, dig_port->base.base.name,
673 /* take the difference of current time and panel power off time
674 * and then make panel wait for t11_t12 if needed. */
675 panel_power_on_time = ktime_get_boottime();
676 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->pps.panel_power_off_time);
678 /* When we disable the VDD override bit last we have to do the manual
680 if (panel_power_off_duration < (s64)intel_dp->pps.panel_power_cycle_delay)
681 wait_remaining_ms_from_jiffies(jiffies,
682 intel_dp->pps.panel_power_cycle_delay - panel_power_off_duration);
684 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
687 void intel_pps_wait_power_cycle(struct intel_dp *intel_dp)
689 intel_wakeref_t wakeref;
691 if (!intel_dp_is_edp(intel_dp))
694 with_intel_pps_lock(intel_dp, wakeref)
695 wait_panel_power_cycle(intel_dp);
698 static void wait_backlight_on(struct intel_dp *intel_dp)
700 wait_remaining_ms_from_jiffies(intel_dp->pps.last_power_on,
701 intel_dp->pps.backlight_on_delay);
704 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
706 wait_remaining_ms_from_jiffies(intel_dp->pps.last_backlight_off,
707 intel_dp->pps.backlight_off_delay);
710 /* Read the current pp_control value, unlocking the register if it
714 static u32 ilk_get_pp_control(struct intel_dp *intel_dp)
716 struct intel_display *display = to_intel_display(intel_dp);
719 lockdep_assert_held(&display->pps.mutex);
721 control = intel_de_read(display, _pp_ctrl_reg(intel_dp));
722 if (drm_WARN_ON(display->drm, !HAS_DDI(display) &&
723 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
724 control &= ~PANEL_UNLOCK_MASK;
725 control |= PANEL_UNLOCK_REGS;
731 * Must be paired with intel_pps_vdd_off_unlocked().
732 * Must hold pps_mutex around the whole on/off sequence.
733 * Can be nested with intel_pps_vdd_{on,off}() calls.
735 bool intel_pps_vdd_on_unlocked(struct intel_dp *intel_dp)
737 struct intel_display *display = to_intel_display(intel_dp);
738 struct drm_i915_private *dev_priv = to_i915(display->drm);
739 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
741 i915_reg_t pp_stat_reg, pp_ctrl_reg;
742 bool need_to_disable = !intel_dp->pps.want_panel_vdd;
744 lockdep_assert_held(&display->pps.mutex);
746 if (!intel_dp_is_edp(intel_dp))
749 cancel_delayed_work(&intel_dp->pps.panel_vdd_work);
750 intel_dp->pps.want_panel_vdd = true;
752 if (edp_have_panel_vdd(intel_dp))
753 return need_to_disable;
755 drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref);
756 intel_dp->pps.vdd_wakeref = intel_display_power_get(dev_priv,
757 intel_aux_power_domain(dig_port));
759 pp_stat_reg = _pp_stat_reg(intel_dp);
760 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
762 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turning VDD on\n",
763 dig_port->base.base.base.id, dig_port->base.base.name,
766 if (!edp_have_panel_power(intel_dp))
767 wait_panel_power_cycle(intel_dp);
769 pp = ilk_get_pp_control(intel_dp);
772 intel_de_write(display, pp_ctrl_reg, pp);
773 intel_de_posting_read(display, pp_ctrl_reg);
774 drm_dbg_kms(display->drm,
775 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
776 dig_port->base.base.base.id, dig_port->base.base.name,
778 intel_de_read(display, pp_stat_reg),
779 intel_de_read(display, pp_ctrl_reg));
781 * If the panel wasn't on, delay before accessing aux channel
783 if (!edp_have_panel_power(intel_dp)) {
784 drm_dbg_kms(display->drm,
785 "[ENCODER:%d:%s] %s panel power wasn't enabled\n",
786 dig_port->base.base.base.id, dig_port->base.base.name,
788 msleep(intel_dp->pps.panel_power_up_delay);
791 return need_to_disable;
795 * Must be paired with intel_pps_off().
796 * Nested calls to these functions are not allowed since
797 * we drop the lock. Caller must use some higher level
798 * locking to prevent nested calls from other threads.
800 void intel_pps_vdd_on(struct intel_dp *intel_dp)
802 struct intel_display *display = to_intel_display(intel_dp);
803 struct drm_i915_private *i915 = to_i915(display->drm);
804 intel_wakeref_t wakeref;
807 if (!intel_dp_is_edp(intel_dp))
811 with_intel_pps_lock(intel_dp, wakeref)
812 vdd = intel_pps_vdd_on_unlocked(intel_dp);
813 I915_STATE_WARN(i915, !vdd, "[ENCODER:%d:%s] %s VDD already requested on\n",
814 dp_to_dig_port(intel_dp)->base.base.base.id,
815 dp_to_dig_port(intel_dp)->base.base.name,
819 static void intel_pps_vdd_off_sync_unlocked(struct intel_dp *intel_dp)
821 struct intel_display *display = to_intel_display(intel_dp);
822 struct drm_i915_private *dev_priv = to_i915(display->drm);
823 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
825 i915_reg_t pp_stat_reg, pp_ctrl_reg;
827 lockdep_assert_held(&display->pps.mutex);
829 drm_WARN_ON(display->drm, intel_dp->pps.want_panel_vdd);
831 if (!edp_have_panel_vdd(intel_dp))
834 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turning VDD off\n",
835 dig_port->base.base.base.id, dig_port->base.base.name,
838 pp = ilk_get_pp_control(intel_dp);
839 pp &= ~EDP_FORCE_VDD;
841 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
842 pp_stat_reg = _pp_stat_reg(intel_dp);
844 intel_de_write(display, pp_ctrl_reg, pp);
845 intel_de_posting_read(display, pp_ctrl_reg);
847 /* Make sure sequencer is idle before allowing subsequent activity */
848 drm_dbg_kms(display->drm,
849 "[ENCODER:%d:%s] %s PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
850 dig_port->base.base.base.id, dig_port->base.base.name,
852 intel_de_read(display, pp_stat_reg),
853 intel_de_read(display, pp_ctrl_reg));
855 if ((pp & PANEL_POWER_ON) == 0)
856 intel_dp->pps.panel_power_off_time = ktime_get_boottime();
858 intel_display_power_put(dev_priv,
859 intel_aux_power_domain(dig_port),
860 fetch_and_zero(&intel_dp->pps.vdd_wakeref));
863 void intel_pps_vdd_off_sync(struct intel_dp *intel_dp)
865 intel_wakeref_t wakeref;
867 if (!intel_dp_is_edp(intel_dp))
870 cancel_delayed_work_sync(&intel_dp->pps.panel_vdd_work);
872 * vdd might still be enabled due to the delayed vdd off.
873 * Make sure vdd is actually turned off here.
875 with_intel_pps_lock(intel_dp, wakeref)
876 intel_pps_vdd_off_sync_unlocked(intel_dp);
879 static void edp_panel_vdd_work(struct work_struct *__work)
881 struct intel_pps *pps = container_of(to_delayed_work(__work),
882 struct intel_pps, panel_vdd_work);
883 struct intel_dp *intel_dp = container_of(pps, struct intel_dp, pps);
884 intel_wakeref_t wakeref;
886 with_intel_pps_lock(intel_dp, wakeref) {
887 if (!intel_dp->pps.want_panel_vdd)
888 intel_pps_vdd_off_sync_unlocked(intel_dp);
892 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
894 struct intel_display *display = to_intel_display(intel_dp);
895 struct drm_i915_private *i915 = to_i915(display->drm);
899 * We may not yet know the real power sequencing delays,
900 * so keep VDD enabled until we're done with init.
902 if (intel_dp->pps.initializing)
906 * Queue the timer to fire a long time from now (relative to the power
907 * down delay) to keep the panel power up across a sequence of
910 delay = msecs_to_jiffies(intel_dp->pps.panel_power_cycle_delay * 5);
911 queue_delayed_work(i915->unordered_wq,
912 &intel_dp->pps.panel_vdd_work, delay);
916 * Must be paired with edp_panel_vdd_on().
917 * Must hold pps_mutex around the whole on/off sequence.
918 * Can be nested with intel_pps_vdd_{on,off}() calls.
920 void intel_pps_vdd_off_unlocked(struct intel_dp *intel_dp, bool sync)
922 struct intel_display *display = to_intel_display(intel_dp);
923 struct drm_i915_private *dev_priv = to_i915(display->drm);
925 lockdep_assert_held(&display->pps.mutex);
927 if (!intel_dp_is_edp(intel_dp))
930 I915_STATE_WARN(dev_priv, !intel_dp->pps.want_panel_vdd,
931 "[ENCODER:%d:%s] %s VDD not forced on",
932 dp_to_dig_port(intel_dp)->base.base.base.id,
933 dp_to_dig_port(intel_dp)->base.base.name,
936 intel_dp->pps.want_panel_vdd = false;
939 intel_pps_vdd_off_sync_unlocked(intel_dp);
941 edp_panel_vdd_schedule_off(intel_dp);
944 void intel_pps_on_unlocked(struct intel_dp *intel_dp)
946 struct intel_display *display = to_intel_display(intel_dp);
947 struct drm_i915_private *dev_priv = to_i915(display->drm);
949 i915_reg_t pp_ctrl_reg;
951 lockdep_assert_held(&display->pps.mutex);
953 if (!intel_dp_is_edp(intel_dp))
956 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turn panel power on\n",
957 dp_to_dig_port(intel_dp)->base.base.base.id,
958 dp_to_dig_port(intel_dp)->base.base.name,
961 if (drm_WARN(display->drm, edp_have_panel_power(intel_dp),
962 "[ENCODER:%d:%s] %s panel power already on\n",
963 dp_to_dig_port(intel_dp)->base.base.base.id,
964 dp_to_dig_port(intel_dp)->base.base.name,
968 wait_panel_power_cycle(intel_dp);
970 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
971 pp = ilk_get_pp_control(intel_dp);
972 if (IS_IRONLAKE(dev_priv)) {
973 /* ILK workaround: disable reset around power sequence */
974 pp &= ~PANEL_POWER_RESET;
975 intel_de_write(display, pp_ctrl_reg, pp);
976 intel_de_posting_read(display, pp_ctrl_reg);
981 * Disable DPLS gating around power sequence.
983 if (IS_DISPLAY_VER(display, 13, 14))
984 intel_de_rmw(display, SOUTH_DSPCLK_GATE_D,
985 0, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
987 pp |= PANEL_POWER_ON;
988 if (!IS_IRONLAKE(dev_priv))
989 pp |= PANEL_POWER_RESET;
991 intel_de_write(display, pp_ctrl_reg, pp);
992 intel_de_posting_read(display, pp_ctrl_reg);
994 wait_panel_on(intel_dp);
995 intel_dp->pps.last_power_on = jiffies;
997 if (IS_DISPLAY_VER(display, 13, 14))
998 intel_de_rmw(display, SOUTH_DSPCLK_GATE_D,
999 PCH_DPLSUNIT_CLOCK_GATE_DISABLE, 0);
1001 if (IS_IRONLAKE(dev_priv)) {
1002 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
1003 intel_de_write(display, pp_ctrl_reg, pp);
1004 intel_de_posting_read(display, pp_ctrl_reg);
1008 void intel_pps_on(struct intel_dp *intel_dp)
1010 intel_wakeref_t wakeref;
1012 if (!intel_dp_is_edp(intel_dp))
1015 with_intel_pps_lock(intel_dp, wakeref)
1016 intel_pps_on_unlocked(intel_dp);
1019 void intel_pps_off_unlocked(struct intel_dp *intel_dp)
1021 struct intel_display *display = to_intel_display(intel_dp);
1022 struct drm_i915_private *dev_priv = to_i915(display->drm);
1023 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1025 i915_reg_t pp_ctrl_reg;
1027 lockdep_assert_held(&display->pps.mutex);
1029 if (!intel_dp_is_edp(intel_dp))
1032 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] %s turn panel power off\n",
1033 dig_port->base.base.base.id, dig_port->base.base.name,
1034 pps_name(intel_dp));
1036 drm_WARN(display->drm, !intel_dp->pps.want_panel_vdd,
1037 "[ENCODER:%d:%s] %s need VDD to turn off panel\n",
1038 dig_port->base.base.base.id, dig_port->base.base.name,
1039 pps_name(intel_dp));
1041 pp = ilk_get_pp_control(intel_dp);
1042 /* We need to switch off panel power _and_ force vdd, for otherwise some
1043 * panels get very unhappy and cease to work. */
1044 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
1047 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1049 intel_dp->pps.want_panel_vdd = false;
1051 intel_de_write(display, pp_ctrl_reg, pp);
1052 intel_de_posting_read(display, pp_ctrl_reg);
1054 wait_panel_off(intel_dp);
1055 intel_dp->pps.panel_power_off_time = ktime_get_boottime();
1057 /* We got a reference when we enabled the VDD. */
1058 intel_display_power_put(dev_priv,
1059 intel_aux_power_domain(dig_port),
1060 fetch_and_zero(&intel_dp->pps.vdd_wakeref));
1063 void intel_pps_off(struct intel_dp *intel_dp)
1065 intel_wakeref_t wakeref;
1067 if (!intel_dp_is_edp(intel_dp))
1070 with_intel_pps_lock(intel_dp, wakeref)
1071 intel_pps_off_unlocked(intel_dp);
1074 /* Enable backlight in the panel power control. */
1075 void intel_pps_backlight_on(struct intel_dp *intel_dp)
1077 struct intel_display *display = to_intel_display(intel_dp);
1078 intel_wakeref_t wakeref;
1081 * If we enable the backlight right away following a panel power
1082 * on, we may see slight flicker as the panel syncs with the eDP
1083 * link. So delay a bit to make sure the image is solid before
1084 * allowing it to appear.
1086 wait_backlight_on(intel_dp);
1088 with_intel_pps_lock(intel_dp, wakeref) {
1089 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1092 pp = ilk_get_pp_control(intel_dp);
1093 pp |= EDP_BLC_ENABLE;
1095 intel_de_write(display, pp_ctrl_reg, pp);
1096 intel_de_posting_read(display, pp_ctrl_reg);
1100 /* Disable backlight in the panel power control. */
1101 void intel_pps_backlight_off(struct intel_dp *intel_dp)
1103 struct intel_display *display = to_intel_display(intel_dp);
1104 intel_wakeref_t wakeref;
1106 if (!intel_dp_is_edp(intel_dp))
1109 with_intel_pps_lock(intel_dp, wakeref) {
1110 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1113 pp = ilk_get_pp_control(intel_dp);
1114 pp &= ~EDP_BLC_ENABLE;
1116 intel_de_write(display, pp_ctrl_reg, pp);
1117 intel_de_posting_read(display, pp_ctrl_reg);
1120 intel_dp->pps.last_backlight_off = jiffies;
1121 edp_wait_backlight_off(intel_dp);
1125 * Hook for controlling the panel power control backlight through the bl_power
1126 * sysfs attribute. Take care to handle multiple calls.
1128 void intel_pps_backlight_power(struct intel_connector *connector, bool enable)
1130 struct intel_display *display = to_intel_display(connector);
1131 struct intel_dp *intel_dp = intel_attached_dp(connector);
1132 intel_wakeref_t wakeref;
1136 with_intel_pps_lock(intel_dp, wakeref)
1137 is_enabled = ilk_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
1138 if (is_enabled == enable)
1141 drm_dbg_kms(display->drm, "panel power control backlight %s\n",
1142 enable ? "enable" : "disable");
1145 intel_pps_backlight_on(intel_dp);
1147 intel_pps_backlight_off(intel_dp);
1150 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
1152 struct intel_display *display = to_intel_display(intel_dp);
1153 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1154 enum pipe pipe = intel_dp->pps.pps_pipe;
1155 i915_reg_t pp_on_reg = PP_ON_DELAYS(display, pipe);
1157 drm_WARN_ON(display->drm, intel_dp->pps.active_pipe != INVALID_PIPE);
1159 if (drm_WARN_ON(display->drm, pipe != PIPE_A && pipe != PIPE_B))
1162 intel_pps_vdd_off_sync_unlocked(intel_dp);
1165 * VLV seems to get confused when multiple power sequencers
1166 * have the same port selected (even if only one has power/vdd
1167 * enabled). The failure manifests as vlv_wait_port_ready() failing
1168 * CHV on the other hand doesn't seem to mind having the same port
1169 * selected in multiple power sequencers, but let's clear the
1170 * port select always when logically disconnecting a power sequencer
1173 drm_dbg_kms(display->drm,
1174 "detaching %s from [ENCODER:%d:%s]\n",
1176 dig_port->base.base.base.id, dig_port->base.base.name);
1177 intel_de_write(display, pp_on_reg, 0);
1178 intel_de_posting_read(display, pp_on_reg);
1180 intel_dp->pps.pps_pipe = INVALID_PIPE;
1183 static void vlv_steal_power_sequencer(struct intel_display *display,
1186 struct intel_encoder *encoder;
1188 lockdep_assert_held(&display->pps.mutex);
1190 for_each_intel_dp(display->drm, encoder) {
1191 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1193 drm_WARN(display->drm, intel_dp->pps.active_pipe == pipe,
1194 "stealing PPS %c from active [ENCODER:%d:%s]\n",
1195 pipe_name(pipe), encoder->base.base.id,
1196 encoder->base.name);
1198 if (intel_dp->pps.pps_pipe != pipe)
1201 drm_dbg_kms(display->drm,
1202 "stealing PPS %c from [ENCODER:%d:%s]\n",
1203 pipe_name(pipe), encoder->base.base.id,
1204 encoder->base.name);
1206 /* make sure vdd is off before we steal it */
1207 vlv_detach_power_sequencer(intel_dp);
1211 void vlv_pps_init(struct intel_encoder *encoder,
1212 const struct intel_crtc_state *crtc_state)
1214 struct intel_display *display = to_intel_display(encoder);
1215 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1216 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1218 lockdep_assert_held(&display->pps.mutex);
1220 drm_WARN_ON(display->drm, intel_dp->pps.active_pipe != INVALID_PIPE);
1222 if (intel_dp->pps.pps_pipe != INVALID_PIPE &&
1223 intel_dp->pps.pps_pipe != crtc->pipe) {
1225 * If another power sequencer was being used on this
1226 * port previously make sure to turn off vdd there while
1227 * we still have control of it.
1229 vlv_detach_power_sequencer(intel_dp);
1233 * We may be stealing the power
1234 * sequencer from another port.
1236 vlv_steal_power_sequencer(display, crtc->pipe);
1238 intel_dp->pps.active_pipe = crtc->pipe;
1240 if (!intel_dp_is_edp(intel_dp))
1243 /* now it's all ours */
1244 intel_dp->pps.pps_pipe = crtc->pipe;
1246 drm_dbg_kms(display->drm,
1247 "initializing %s for [ENCODER:%d:%s]\n",
1249 encoder->base.base.id, encoder->base.name);
1251 /* init power sequencer on this pipe and port */
1252 pps_init_delays(intel_dp);
1253 pps_init_registers(intel_dp, true);
1256 static void pps_vdd_init(struct intel_dp *intel_dp)
1258 struct intel_display *display = to_intel_display(intel_dp);
1259 struct drm_i915_private *dev_priv = to_i915(display->drm);
1260 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1262 lockdep_assert_held(&display->pps.mutex);
1264 if (!edp_have_panel_vdd(intel_dp))
1268 * The VDD bit needs a power domain reference, so if the bit is
1269 * already enabled when we boot or resume, grab this reference and
1270 * schedule a vdd off, so we don't hold on to the reference
1273 drm_dbg_kms(display->drm,
1274 "[ENCODER:%d:%s] %s VDD left on by BIOS, adjusting state tracking\n",
1275 dig_port->base.base.base.id, dig_port->base.base.name,
1276 pps_name(intel_dp));
1277 drm_WARN_ON(display->drm, intel_dp->pps.vdd_wakeref);
1278 intel_dp->pps.vdd_wakeref = intel_display_power_get(dev_priv,
1279 intel_aux_power_domain(dig_port));
1282 bool intel_pps_have_panel_power_or_vdd(struct intel_dp *intel_dp)
1284 intel_wakeref_t wakeref;
1285 bool have_power = false;
1287 with_intel_pps_lock(intel_dp, wakeref) {
1288 have_power = edp_have_panel_power(intel_dp) ||
1289 edp_have_panel_vdd(intel_dp);
1295 static void pps_init_timestamps(struct intel_dp *intel_dp)
1298 * Initialize panel power off time to 0, assuming panel power could have
1299 * been toggled between kernel boot and now only by a previously loaded
1300 * and removed i915, which has already ensured sufficient power off
1301 * delay at module remove.
1303 intel_dp->pps.panel_power_off_time = 0;
1304 intel_dp->pps.last_power_on = jiffies;
1305 intel_dp->pps.last_backlight_off = jiffies;
1309 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
1311 struct intel_display *display = to_intel_display(intel_dp);
1312 u32 pp_on, pp_off, pp_ctl;
1313 struct pps_registers regs;
1315 intel_pps_get_registers(intel_dp, ®s);
1317 pp_ctl = ilk_get_pp_control(intel_dp);
1319 /* Ensure PPS is unlocked */
1320 if (!HAS_DDI(display))
1321 intel_de_write(display, regs.pp_ctrl, pp_ctl);
1323 pp_on = intel_de_read(display, regs.pp_on);
1324 pp_off = intel_de_read(display, regs.pp_off);
1326 /* Pull timing values out of registers */
1327 seq->t1_t3 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on);
1328 seq->t8 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on);
1329 seq->t9 = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off);
1330 seq->t10 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off);
1332 if (i915_mmio_reg_valid(regs.pp_div)) {
1335 pp_div = intel_de_read(display, regs.pp_div);
1337 seq->t11_t12 = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div) * 1000;
1339 seq->t11_t12 = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl) * 1000;
1344 intel_pps_dump_state(struct intel_dp *intel_dp, const char *state_name,
1345 const struct edp_power_seq *seq)
1347 struct intel_display *display = to_intel_display(intel_dp);
1349 drm_dbg_kms(display->drm,
1350 "%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
1352 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
1356 intel_pps_verify_state(struct intel_dp *intel_dp)
1358 struct intel_display *display = to_intel_display(intel_dp);
1359 struct edp_power_seq hw;
1360 struct edp_power_seq *sw = &intel_dp->pps.pps_delays;
1362 intel_pps_readout_hw_state(intel_dp, &hw);
1364 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
1365 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
1366 drm_err(display->drm, "PPS state mismatch\n");
1367 intel_pps_dump_state(intel_dp, "sw", sw);
1368 intel_pps_dump_state(intel_dp, "hw", &hw);
1372 static bool pps_delays_valid(struct edp_power_seq *delays)
1374 return delays->t1_t3 || delays->t8 || delays->t9 ||
1375 delays->t10 || delays->t11_t12;
1378 static void pps_init_delays_bios(struct intel_dp *intel_dp,
1379 struct edp_power_seq *bios)
1381 struct intel_display *display = to_intel_display(intel_dp);
1383 lockdep_assert_held(&display->pps.mutex);
1385 if (!pps_delays_valid(&intel_dp->pps.bios_pps_delays))
1386 intel_pps_readout_hw_state(intel_dp, &intel_dp->pps.bios_pps_delays);
1388 *bios = intel_dp->pps.bios_pps_delays;
1390 intel_pps_dump_state(intel_dp, "bios", bios);
1393 static void pps_init_delays_vbt(struct intel_dp *intel_dp,
1394 struct edp_power_seq *vbt)
1396 struct intel_display *display = to_intel_display(intel_dp);
1397 struct intel_connector *connector = intel_dp->attached_connector;
1399 *vbt = connector->panel.vbt.edp.pps;
1401 if (!pps_delays_valid(vbt))
1404 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
1405 * of 500ms appears to be too short. Ocassionally the panel
1406 * just fails to power back on. Increasing the delay to 800ms
1407 * seems sufficient to avoid this problem.
1409 if (intel_has_quirk(display, QUIRK_INCREASE_T12_DELAY)) {
1410 vbt->t11_t12 = max_t(u16, vbt->t11_t12, 1300 * 10);
1411 drm_dbg_kms(display->drm,
1412 "Increasing T12 panel delay as per the quirk to %d\n",
1416 /* T11_T12 delay is special and actually in units of 100ms, but zero
1417 * based in the hw (so we need to add 100 ms). But the sw vbt
1418 * table multiplies it with 1000 to make it in units of 100usec,
1420 vbt->t11_t12 += 100 * 10;
1422 intel_pps_dump_state(intel_dp, "vbt", vbt);
1425 static void pps_init_delays_spec(struct intel_dp *intel_dp,
1426 struct edp_power_seq *spec)
1428 struct intel_display *display = to_intel_display(intel_dp);
1430 lockdep_assert_held(&display->pps.mutex);
1432 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
1433 * our hw here, which are all in 100usec. */
1434 spec->t1_t3 = 210 * 10;
1435 spec->t8 = 50 * 10; /* no limit for t8, use t7 instead */
1436 spec->t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
1437 spec->t10 = 500 * 10;
1438 /* This one is special and actually in units of 100ms, but zero
1439 * based in the hw (so we need to add 100 ms). But the sw vbt
1440 * table multiplies it with 1000 to make it in units of 100usec,
1442 spec->t11_t12 = (510 + 100) * 10;
1444 intel_pps_dump_state(intel_dp, "spec", spec);
1447 static void pps_init_delays(struct intel_dp *intel_dp)
1449 struct intel_display *display = to_intel_display(intel_dp);
1450 struct edp_power_seq cur, vbt, spec,
1451 *final = &intel_dp->pps.pps_delays;
1453 lockdep_assert_held(&display->pps.mutex);
1455 /* already initialized? */
1456 if (pps_delays_valid(final))
1459 pps_init_delays_bios(intel_dp, &cur);
1460 pps_init_delays_vbt(intel_dp, &vbt);
1461 pps_init_delays_spec(intel_dp, &spec);
1463 /* Use the max of the register settings and vbt. If both are
1464 * unset, fall back to the spec limits. */
1465 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
1467 max(cur.field, vbt.field))
1468 assign_final(t1_t3);
1472 assign_final(t11_t12);
1475 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
1476 intel_dp->pps.panel_power_up_delay = get_delay(t1_t3);
1477 intel_dp->pps.backlight_on_delay = get_delay(t8);
1478 intel_dp->pps.backlight_off_delay = get_delay(t9);
1479 intel_dp->pps.panel_power_down_delay = get_delay(t10);
1480 intel_dp->pps.panel_power_cycle_delay = get_delay(t11_t12);
1483 drm_dbg_kms(display->drm,
1484 "panel power up delay %d, power down delay %d, power cycle delay %d\n",
1485 intel_dp->pps.panel_power_up_delay,
1486 intel_dp->pps.panel_power_down_delay,
1487 intel_dp->pps.panel_power_cycle_delay);
1489 drm_dbg_kms(display->drm, "backlight on delay %d, off delay %d\n",
1490 intel_dp->pps.backlight_on_delay,
1491 intel_dp->pps.backlight_off_delay);
1494 * We override the HW backlight delays to 1 because we do manual waits
1495 * on them. For T8, even BSpec recommends doing it. For T9, if we
1496 * don't do this, we'll end up waiting for the backlight off delay
1497 * twice: once when we do the manual sleep, and once when we disable
1498 * the panel and wait for the PP_STATUS bit to become zero.
1504 * HW has only a 100msec granularity for t11_t12 so round it up
1507 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
1510 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd)
1512 struct intel_display *display = to_intel_display(intel_dp);
1513 struct drm_i915_private *dev_priv = to_i915(display->drm);
1514 u32 pp_on, pp_off, port_sel = 0;
1515 int div = DISPLAY_RUNTIME_INFO(display)->rawclk_freq / 1000;
1516 struct pps_registers regs;
1517 enum port port = dp_to_dig_port(intel_dp)->base.port;
1518 const struct edp_power_seq *seq = &intel_dp->pps.pps_delays;
1520 lockdep_assert_held(&display->pps.mutex);
1522 intel_pps_get_registers(intel_dp, ®s);
1525 * On some VLV machines the BIOS can leave the VDD
1526 * enabled even on power sequencers which aren't
1527 * hooked up to any port. This would mess up the
1528 * power domain tracking the first time we pick
1529 * one of these power sequencers for use since
1530 * intel_pps_vdd_on_unlocked() would notice that the VDD was
1531 * already on and therefore wouldn't grab the power
1532 * domain reference. Disable VDD first to avoid this.
1533 * This also avoids spuriously turning the VDD on as
1534 * soon as the new power sequencer gets initialized.
1536 if (force_disable_vdd) {
1537 u32 pp = ilk_get_pp_control(intel_dp);
1539 drm_WARN(display->drm, pp & PANEL_POWER_ON,
1540 "Panel power already on\n");
1542 if (pp & EDP_FORCE_VDD)
1543 drm_dbg_kms(display->drm,
1544 "VDD already on, disabling first\n");
1546 pp &= ~EDP_FORCE_VDD;
1548 intel_de_write(display, regs.pp_ctrl, pp);
1551 pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->t1_t3) |
1552 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->t8);
1553 pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->t9) |
1554 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->t10);
1556 /* Haswell doesn't have any port selection bits for the panel
1557 * power sequencer any more. */
1558 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1559 port_sel = PANEL_PORT_SELECT_VLV(port);
1560 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
1563 port_sel = PANEL_PORT_SELECT_DPA;
1566 port_sel = PANEL_PORT_SELECT_DPC;
1569 port_sel = PANEL_PORT_SELECT_DPD;
1579 intel_de_write(display, regs.pp_on, pp_on);
1580 intel_de_write(display, regs.pp_off, pp_off);
1583 * Compute the divisor for the pp clock, simply match the Bspec formula.
1585 if (i915_mmio_reg_valid(regs.pp_div))
1586 intel_de_write(display, regs.pp_div,
1587 REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, (100 * div) / 2 - 1) | REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000)));
1589 intel_de_rmw(display, regs.pp_ctrl, BXT_POWER_CYCLE_DELAY_MASK,
1590 REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK,
1591 DIV_ROUND_UP(seq->t11_t12, 1000)));
1593 drm_dbg_kms(display->drm,
1594 "panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
1595 intel_de_read(display, regs.pp_on),
1596 intel_de_read(display, regs.pp_off),
1597 i915_mmio_reg_valid(regs.pp_div) ?
1598 intel_de_read(display, regs.pp_div) :
1599 (intel_de_read(display, regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK));
1602 void intel_pps_encoder_reset(struct intel_dp *intel_dp)
1604 struct intel_display *display = to_intel_display(intel_dp);
1605 struct drm_i915_private *i915 = to_i915(display->drm);
1606 intel_wakeref_t wakeref;
1608 if (!intel_dp_is_edp(intel_dp))
1611 with_intel_pps_lock(intel_dp, wakeref) {
1613 * Reinit the power sequencer also on the resume path, in case
1614 * BIOS did something nasty with it.
1616 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
1617 vlv_initial_power_sequencer_setup(intel_dp);
1619 pps_init_delays(intel_dp);
1620 pps_init_registers(intel_dp, false);
1621 pps_vdd_init(intel_dp);
1623 if (edp_have_panel_vdd(intel_dp))
1624 edp_panel_vdd_schedule_off(intel_dp);
1628 bool intel_pps_init(struct intel_dp *intel_dp)
1630 intel_wakeref_t wakeref;
1633 intel_dp->pps.initializing = true;
1634 INIT_DELAYED_WORK(&intel_dp->pps.panel_vdd_work, edp_panel_vdd_work);
1636 pps_init_timestamps(intel_dp);
1638 with_intel_pps_lock(intel_dp, wakeref) {
1639 ret = pps_initial_setup(intel_dp);
1641 pps_init_delays(intel_dp);
1642 pps_init_registers(intel_dp, false);
1643 pps_vdd_init(intel_dp);
1649 static void pps_init_late(struct intel_dp *intel_dp)
1651 struct intel_display *display = to_intel_display(intel_dp);
1652 struct drm_i915_private *i915 = to_i915(display->drm);
1653 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
1654 struct intel_connector *connector = intel_dp->attached_connector;
1656 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
1659 if (intel_num_pps(display) < 2)
1662 drm_WARN(display->drm,
1663 connector->panel.vbt.backlight.controller >= 0 &&
1664 intel_dp->pps.pps_idx != connector->panel.vbt.backlight.controller,
1665 "[ENCODER:%d:%s] power sequencer mismatch: %d (initial) vs. %d (VBT)\n",
1666 encoder->base.base.id, encoder->base.name,
1667 intel_dp->pps.pps_idx, connector->panel.vbt.backlight.controller);
1669 if (connector->panel.vbt.backlight.controller >= 0)
1670 intel_dp->pps.pps_idx = connector->panel.vbt.backlight.controller;
1673 void intel_pps_init_late(struct intel_dp *intel_dp)
1675 intel_wakeref_t wakeref;
1677 with_intel_pps_lock(intel_dp, wakeref) {
1678 /* Reinit delays after per-panel info has been parsed from VBT */
1679 pps_init_late(intel_dp);
1681 memset(&intel_dp->pps.pps_delays, 0, sizeof(intel_dp->pps.pps_delays));
1682 pps_init_delays(intel_dp);
1683 pps_init_registers(intel_dp, false);
1685 intel_dp->pps.initializing = false;
1687 if (edp_have_panel_vdd(intel_dp))
1688 edp_panel_vdd_schedule_off(intel_dp);
1692 void intel_pps_unlock_regs_wa(struct intel_display *display)
1697 if (!HAS_DISPLAY(display) || HAS_DDI(display))
1700 * This w/a is needed at least on CPT/PPT, but to be sure apply it
1701 * everywhere where registers can be write protected.
1703 pps_num = intel_num_pps(display);
1705 for (pps_idx = 0; pps_idx < pps_num; pps_idx++)
1706 intel_de_rmw(display, PP_CONTROL(display, pps_idx),
1707 PANEL_UNLOCK_MASK, PANEL_UNLOCK_REGS);
1710 void intel_pps_setup(struct intel_display *display)
1712 struct drm_i915_private *i915 = to_i915(display->drm);
1714 if (HAS_PCH_SPLIT(i915) || IS_GEMINILAKE(i915) || IS_BROXTON(i915))
1715 display->pps.mmio_base = PCH_PPS_BASE;
1716 else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
1717 display->pps.mmio_base = VLV_PPS_BASE;
1719 display->pps.mmio_base = PPS_BASE;
1722 static int intel_pps_show(struct seq_file *m, void *data)
1724 struct intel_connector *connector = m->private;
1725 struct intel_dp *intel_dp = intel_attached_dp(connector);
1727 if (connector->base.status != connector_status_connected)
1730 seq_printf(m, "Panel power up delay: %d\n",
1731 intel_dp->pps.panel_power_up_delay);
1732 seq_printf(m, "Panel power down delay: %d\n",
1733 intel_dp->pps.panel_power_down_delay);
1734 seq_printf(m, "Backlight on delay: %d\n",
1735 intel_dp->pps.backlight_on_delay);
1736 seq_printf(m, "Backlight off delay: %d\n",
1737 intel_dp->pps.backlight_off_delay);
1741 DEFINE_SHOW_ATTRIBUTE(intel_pps);
1743 void intel_pps_connector_debugfs_add(struct intel_connector *connector)
1745 struct dentry *root = connector->base.debugfs_entry;
1746 int connector_type = connector->base.connector_type;
1748 if (connector_type == DRM_MODE_CONNECTOR_eDP)
1749 debugfs_create_file("i915_panel_timings", 0444, root,
1750 connector, &intel_pps_fops);
1753 void assert_pps_unlocked(struct intel_display *display, enum pipe pipe)
1755 struct drm_i915_private *dev_priv = to_i915(display->drm);
1758 enum pipe panel_pipe = INVALID_PIPE;
1761 if (drm_WARN_ON(display->drm, HAS_DDI(display)))
1764 if (HAS_PCH_SPLIT(dev_priv)) {
1767 pp_reg = PP_CONTROL(display, 0);
1768 port_sel = intel_de_read(display, PP_ON_DELAYS(display, 0)) &
1769 PANEL_PORT_SELECT_MASK;
1772 case PANEL_PORT_SELECT_LVDS:
1773 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
1775 case PANEL_PORT_SELECT_DPA:
1776 g4x_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1778 case PANEL_PORT_SELECT_DPC:
1779 g4x_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1781 case PANEL_PORT_SELECT_DPD:
1782 g4x_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1785 MISSING_CASE(port_sel);
1788 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1789 /* presumably write lock depends on pipe, not port select */
1790 pp_reg = PP_CONTROL(display, pipe);
1795 pp_reg = PP_CONTROL(display, 0);
1796 port_sel = intel_de_read(display, PP_ON_DELAYS(display, 0)) &
1797 PANEL_PORT_SELECT_MASK;
1799 drm_WARN_ON(display->drm,
1800 port_sel != PANEL_PORT_SELECT_LVDS);
1801 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
1804 val = intel_de_read(display, pp_reg);
1805 if (!(val & PANEL_POWER_ON) ||
1806 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
1809 I915_STATE_WARN(dev_priv, panel_pipe == pipe && locked,
1810 "panel assertion failure, pipe %c regs locked\n",