1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
8 #include "intel_display_types.h"
10 #include "intel_dpll.h"
11 #include "intel_pps.h"
13 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
16 static void pps_init_delays(struct intel_dp *intel_dp);
17 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd);
19 intel_wakeref_t intel_pps_lock(struct intel_dp *intel_dp)
21 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
22 intel_wakeref_t wakeref;
25 * See intel_pps_reset_all() why we need a power domain reference here.
27 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DISPLAY_CORE);
28 mutex_lock(&dev_priv->pps_mutex);
33 intel_wakeref_t intel_pps_unlock(struct intel_dp *intel_dp,
34 intel_wakeref_t wakeref)
36 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
38 mutex_unlock(&dev_priv->pps_mutex);
39 intel_display_power_put(dev_priv, POWER_DOMAIN_DISPLAY_CORE, wakeref);
45 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
47 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
48 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
49 enum pipe pipe = intel_dp->pps.pps_pipe;
50 bool pll_enabled, release_cl_override = false;
51 enum dpio_phy phy = DPIO_PHY(pipe);
52 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
55 if (drm_WARN(&dev_priv->drm,
56 intel_de_read(dev_priv, intel_dp->output_reg) & DP_PORT_EN,
57 "skipping pipe %c power sequencer kick due to [ENCODER:%d:%s] being active\n",
58 pipe_name(pipe), dig_port->base.base.base.id,
59 dig_port->base.base.name))
62 drm_dbg_kms(&dev_priv->drm,
63 "kicking pipe %c power sequencer for [ENCODER:%d:%s]\n",
64 pipe_name(pipe), dig_port->base.base.base.id,
65 dig_port->base.base.name);
67 /* Preserve the BIOS-computed detected bit. This is
68 * supposed to be read-only.
70 DP = intel_de_read(dev_priv, intel_dp->output_reg) & DP_DETECTED;
71 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
72 DP |= DP_PORT_WIDTH(1);
73 DP |= DP_LINK_TRAIN_PAT_1;
75 if (IS_CHERRYVIEW(dev_priv))
76 DP |= DP_PIPE_SEL_CHV(pipe);
78 DP |= DP_PIPE_SEL(pipe);
80 pll_enabled = intel_de_read(dev_priv, DPLL(pipe)) & DPLL_VCO_ENABLE;
83 * The DPLL for the pipe must be enabled for this to work.
84 * So enable temporarily it if it's not already enabled.
87 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
88 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
90 if (vlv_force_pll_on(dev_priv, pipe, vlv_get_dpll(dev_priv))) {
91 drm_err(&dev_priv->drm,
92 "Failed to force on pll for pipe %c!\n",
99 * Similar magic as in intel_dp_enable_port().
100 * We _must_ do this port enable + disable trick
101 * to make this power sequencer lock onto the port.
102 * Otherwise even VDD force bit won't work.
104 intel_de_write(dev_priv, intel_dp->output_reg, DP);
105 intel_de_posting_read(dev_priv, intel_dp->output_reg);
107 intel_de_write(dev_priv, intel_dp->output_reg, DP | DP_PORT_EN);
108 intel_de_posting_read(dev_priv, intel_dp->output_reg);
110 intel_de_write(dev_priv, intel_dp->output_reg, DP & ~DP_PORT_EN);
111 intel_de_posting_read(dev_priv, intel_dp->output_reg);
114 vlv_force_pll_off(dev_priv, pipe);
116 if (release_cl_override)
117 chv_phy_powergate_ch(dev_priv, phy, ch, false);
121 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
123 struct intel_encoder *encoder;
124 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
127 * We don't have power sequencer currently.
128 * Pick one that's not used by other ports.
130 for_each_intel_dp(&dev_priv->drm, encoder) {
131 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
133 if (encoder->type == INTEL_OUTPUT_EDP) {
134 drm_WARN_ON(&dev_priv->drm,
135 intel_dp->pps.active_pipe != INVALID_PIPE &&
136 intel_dp->pps.active_pipe !=
137 intel_dp->pps.pps_pipe);
139 if (intel_dp->pps.pps_pipe != INVALID_PIPE)
140 pipes &= ~(1 << intel_dp->pps.pps_pipe);
142 drm_WARN_ON(&dev_priv->drm,
143 intel_dp->pps.pps_pipe != INVALID_PIPE);
145 if (intel_dp->pps.active_pipe != INVALID_PIPE)
146 pipes &= ~(1 << intel_dp->pps.active_pipe);
153 return ffs(pipes) - 1;
157 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
159 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
160 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
163 lockdep_assert_held(&dev_priv->pps_mutex);
165 /* We should never land here with regular DP ports */
166 drm_WARN_ON(&dev_priv->drm, !intel_dp_is_edp(intel_dp));
168 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.active_pipe != INVALID_PIPE &&
169 intel_dp->pps.active_pipe != intel_dp->pps.pps_pipe);
171 if (intel_dp->pps.pps_pipe != INVALID_PIPE)
172 return intel_dp->pps.pps_pipe;
174 pipe = vlv_find_free_pps(dev_priv);
177 * Didn't find one. This should not happen since there
178 * are two power sequencers and up to two eDP ports.
180 if (drm_WARN_ON(&dev_priv->drm, pipe == INVALID_PIPE))
183 vlv_steal_power_sequencer(dev_priv, pipe);
184 intel_dp->pps.pps_pipe = pipe;
186 drm_dbg_kms(&dev_priv->drm,
187 "picked pipe %c power sequencer for [ENCODER:%d:%s]\n",
188 pipe_name(intel_dp->pps.pps_pipe),
189 dig_port->base.base.base.id,
190 dig_port->base.base.name);
192 /* init power sequencer on this pipe and port */
193 pps_init_delays(intel_dp);
194 pps_init_registers(intel_dp, true);
197 * Even vdd force doesn't work until we've made
198 * the power sequencer lock in on the port.
200 vlv_power_sequencer_kick(intel_dp);
202 return intel_dp->pps.pps_pipe;
206 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
208 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
209 int backlight_controller = dev_priv->vbt.backlight.controller;
211 lockdep_assert_held(&dev_priv->pps_mutex);
213 /* We should never land here with regular DP ports */
214 drm_WARN_ON(&dev_priv->drm, !intel_dp_is_edp(intel_dp));
216 if (!intel_dp->pps.pps_reset)
217 return backlight_controller;
219 intel_dp->pps.pps_reset = false;
222 * Only the HW needs to be reprogrammed, the SW state is fixed and
223 * has been setup during connector init.
225 pps_init_registers(intel_dp, false);
227 return backlight_controller;
230 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
233 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
236 return intel_de_read(dev_priv, PP_STATUS(pipe)) & PP_ON;
239 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
242 return intel_de_read(dev_priv, PP_CONTROL(pipe)) & EDP_FORCE_VDD;
245 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
252 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
254 vlv_pipe_check pipe_check)
258 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
259 u32 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(pipe)) &
260 PANEL_PORT_SELECT_MASK;
262 if (port_sel != PANEL_PORT_SELECT_VLV(port))
265 if (!pipe_check(dev_priv, pipe))
275 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
277 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
278 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
279 enum port port = dig_port->base.port;
281 lockdep_assert_held(&dev_priv->pps_mutex);
283 /* try to find a pipe with this port selected */
284 /* first pick one where the panel is on */
285 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
287 /* didn't find one? pick one where vdd is on */
288 if (intel_dp->pps.pps_pipe == INVALID_PIPE)
289 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
290 vlv_pipe_has_vdd_on);
291 /* didn't find one? pick one with just the correct port */
292 if (intel_dp->pps.pps_pipe == INVALID_PIPE)
293 intel_dp->pps.pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
296 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
297 if (intel_dp->pps.pps_pipe == INVALID_PIPE) {
298 drm_dbg_kms(&dev_priv->drm,
299 "no initial power sequencer for [ENCODER:%d:%s]\n",
300 dig_port->base.base.base.id,
301 dig_port->base.base.name);
305 drm_dbg_kms(&dev_priv->drm,
306 "initial power sequencer for [ENCODER:%d:%s]: pipe %c\n",
307 dig_port->base.base.base.id,
308 dig_port->base.base.name,
309 pipe_name(intel_dp->pps.pps_pipe));
312 void intel_pps_reset_all(struct drm_i915_private *dev_priv)
314 struct intel_encoder *encoder;
316 if (drm_WARN_ON(&dev_priv->drm, !IS_LP(dev_priv)))
320 * We can't grab pps_mutex here due to deadlock with power_domain
321 * mutex when power_domain functions are called while holding pps_mutex.
322 * That also means that in order to use pps_pipe the code needs to
323 * hold both a power domain reference and pps_mutex, and the power domain
324 * reference get/put must be done while _not_ holding pps_mutex.
325 * pps_{lock,unlock}() do these steps in the correct order, so one
326 * should use them always.
329 for_each_intel_dp(&dev_priv->drm, encoder) {
330 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
332 drm_WARN_ON(&dev_priv->drm,
333 intel_dp->pps.active_pipe != INVALID_PIPE);
335 if (encoder->type != INTEL_OUTPUT_EDP)
338 if (DISPLAY_VER(dev_priv) >= 9)
339 intel_dp->pps.pps_reset = true;
341 intel_dp->pps.pps_pipe = INVALID_PIPE;
345 struct pps_registers {
353 static void intel_pps_get_registers(struct intel_dp *intel_dp,
354 struct pps_registers *regs)
356 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
359 memset(regs, 0, sizeof(*regs));
361 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
362 pps_idx = bxt_power_sequencer_idx(intel_dp);
363 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
364 pps_idx = vlv_power_sequencer_pipe(intel_dp);
366 regs->pp_ctrl = PP_CONTROL(pps_idx);
367 regs->pp_stat = PP_STATUS(pps_idx);
368 regs->pp_on = PP_ON_DELAYS(pps_idx);
369 regs->pp_off = PP_OFF_DELAYS(pps_idx);
371 /* Cycle delay moved from PP_DIVISOR to PP_CONTROL */
372 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv) ||
373 INTEL_PCH_TYPE(dev_priv) >= PCH_CNP)
374 regs->pp_div = INVALID_MMIO_REG;
376 regs->pp_div = PP_DIVISOR(pps_idx);
380 _pp_ctrl_reg(struct intel_dp *intel_dp)
382 struct pps_registers regs;
384 intel_pps_get_registers(intel_dp, ®s);
390 _pp_stat_reg(struct intel_dp *intel_dp)
392 struct pps_registers regs;
394 intel_pps_get_registers(intel_dp, ®s);
399 static bool edp_have_panel_power(struct intel_dp *intel_dp)
401 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
403 lockdep_assert_held(&dev_priv->pps_mutex);
405 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
406 intel_dp->pps.pps_pipe == INVALID_PIPE)
409 return (intel_de_read(dev_priv, _pp_stat_reg(intel_dp)) & PP_ON) != 0;
412 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
414 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
416 lockdep_assert_held(&dev_priv->pps_mutex);
418 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
419 intel_dp->pps.pps_pipe == INVALID_PIPE)
422 return intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
425 void intel_pps_check_power_unlocked(struct intel_dp *intel_dp)
427 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
429 if (!intel_dp_is_edp(intel_dp))
432 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
433 drm_WARN(&dev_priv->drm, 1,
434 "eDP powered off while attempting aux channel communication.\n");
435 drm_dbg_kms(&dev_priv->drm, "Status 0x%08x Control 0x%08x\n",
436 intel_de_read(dev_priv, _pp_stat_reg(intel_dp)),
437 intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp)));
441 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
442 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
444 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
445 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
447 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
448 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
450 static void intel_pps_verify_state(struct intel_dp *intel_dp);
452 static void wait_panel_status(struct intel_dp *intel_dp,
456 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
457 i915_reg_t pp_stat_reg, pp_ctrl_reg;
459 lockdep_assert_held(&dev_priv->pps_mutex);
461 intel_pps_verify_state(intel_dp);
463 pp_stat_reg = _pp_stat_reg(intel_dp);
464 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
466 drm_dbg_kms(&dev_priv->drm,
467 "mask %08x value %08x status %08x control %08x\n",
469 intel_de_read(dev_priv, pp_stat_reg),
470 intel_de_read(dev_priv, pp_ctrl_reg));
472 if (intel_de_wait_for_register(dev_priv, pp_stat_reg,
474 drm_err(&dev_priv->drm,
475 "Panel status timeout: status %08x control %08x\n",
476 intel_de_read(dev_priv, pp_stat_reg),
477 intel_de_read(dev_priv, pp_ctrl_reg));
479 drm_dbg_kms(&dev_priv->drm, "Wait complete\n");
482 static void wait_panel_on(struct intel_dp *intel_dp)
484 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
486 drm_dbg_kms(&i915->drm, "Wait for panel power on\n");
487 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
490 static void wait_panel_off(struct intel_dp *intel_dp)
492 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
494 drm_dbg_kms(&i915->drm, "Wait for panel power off time\n");
495 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
498 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
500 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
501 ktime_t panel_power_on_time;
502 s64 panel_power_off_duration;
504 drm_dbg_kms(&i915->drm, "Wait for panel power cycle\n");
506 /* take the difference of currrent time and panel power off time
507 * and then make panel wait for t11_t12 if needed. */
508 panel_power_on_time = ktime_get_boottime();
509 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->pps.panel_power_off_time);
511 /* When we disable the VDD override bit last we have to do the manual
513 if (panel_power_off_duration < (s64)intel_dp->pps.panel_power_cycle_delay)
514 wait_remaining_ms_from_jiffies(jiffies,
515 intel_dp->pps.panel_power_cycle_delay - panel_power_off_duration);
517 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
520 void intel_pps_wait_power_cycle(struct intel_dp *intel_dp)
522 intel_wakeref_t wakeref;
524 if (!intel_dp_is_edp(intel_dp))
527 with_intel_pps_lock(intel_dp, wakeref)
528 wait_panel_power_cycle(intel_dp);
531 static void wait_backlight_on(struct intel_dp *intel_dp)
533 wait_remaining_ms_from_jiffies(intel_dp->pps.last_power_on,
534 intel_dp->pps.backlight_on_delay);
537 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
539 wait_remaining_ms_from_jiffies(intel_dp->pps.last_backlight_off,
540 intel_dp->pps.backlight_off_delay);
543 /* Read the current pp_control value, unlocking the register if it
547 static u32 ilk_get_pp_control(struct intel_dp *intel_dp)
549 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
552 lockdep_assert_held(&dev_priv->pps_mutex);
554 control = intel_de_read(dev_priv, _pp_ctrl_reg(intel_dp));
555 if (drm_WARN_ON(&dev_priv->drm, !HAS_DDI(dev_priv) &&
556 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
557 control &= ~PANEL_UNLOCK_MASK;
558 control |= PANEL_UNLOCK_REGS;
564 * Must be paired with intel_pps_vdd_off_unlocked().
565 * Must hold pps_mutex around the whole on/off sequence.
566 * Can be nested with intel_pps_vdd_{on,off}() calls.
568 bool intel_pps_vdd_on_unlocked(struct intel_dp *intel_dp)
570 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
571 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
573 i915_reg_t pp_stat_reg, pp_ctrl_reg;
574 bool need_to_disable = !intel_dp->pps.want_panel_vdd;
576 lockdep_assert_held(&dev_priv->pps_mutex);
578 if (!intel_dp_is_edp(intel_dp))
581 cancel_delayed_work(&intel_dp->pps.panel_vdd_work);
582 intel_dp->pps.want_panel_vdd = true;
584 if (edp_have_panel_vdd(intel_dp))
585 return need_to_disable;
587 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.vdd_wakeref);
588 intel_dp->pps.vdd_wakeref = intel_display_power_get(dev_priv,
589 intel_aux_power_domain(dig_port));
591 drm_dbg_kms(&dev_priv->drm, "Turning [ENCODER:%d:%s] VDD on\n",
592 dig_port->base.base.base.id,
593 dig_port->base.base.name);
595 if (!edp_have_panel_power(intel_dp))
596 wait_panel_power_cycle(intel_dp);
598 pp = ilk_get_pp_control(intel_dp);
601 pp_stat_reg = _pp_stat_reg(intel_dp);
602 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
604 intel_de_write(dev_priv, pp_ctrl_reg, pp);
605 intel_de_posting_read(dev_priv, pp_ctrl_reg);
606 drm_dbg_kms(&dev_priv->drm, "PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
607 intel_de_read(dev_priv, pp_stat_reg),
608 intel_de_read(dev_priv, pp_ctrl_reg));
610 * If the panel wasn't on, delay before accessing aux channel
612 if (!edp_have_panel_power(intel_dp)) {
613 drm_dbg_kms(&dev_priv->drm,
614 "[ENCODER:%d:%s] panel power wasn't enabled\n",
615 dig_port->base.base.base.id,
616 dig_port->base.base.name);
617 msleep(intel_dp->pps.panel_power_up_delay);
620 return need_to_disable;
624 * Must be paired with intel_pps_off().
625 * Nested calls to these functions are not allowed since
626 * we drop the lock. Caller must use some higher level
627 * locking to prevent nested calls from other threads.
629 void intel_pps_vdd_on(struct intel_dp *intel_dp)
631 intel_wakeref_t wakeref;
634 if (!intel_dp_is_edp(intel_dp))
638 with_intel_pps_lock(intel_dp, wakeref)
639 vdd = intel_pps_vdd_on_unlocked(intel_dp);
640 I915_STATE_WARN(!vdd, "[ENCODER:%d:%s] VDD already requested on\n",
641 dp_to_dig_port(intel_dp)->base.base.base.id,
642 dp_to_dig_port(intel_dp)->base.base.name);
645 static void intel_pps_vdd_off_sync_unlocked(struct intel_dp *intel_dp)
647 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
648 struct intel_digital_port *dig_port =
649 dp_to_dig_port(intel_dp);
651 i915_reg_t pp_stat_reg, pp_ctrl_reg;
653 lockdep_assert_held(&dev_priv->pps_mutex);
655 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.want_panel_vdd);
657 if (!edp_have_panel_vdd(intel_dp))
660 drm_dbg_kms(&dev_priv->drm, "Turning [ENCODER:%d:%s] VDD off\n",
661 dig_port->base.base.base.id,
662 dig_port->base.base.name);
664 pp = ilk_get_pp_control(intel_dp);
665 pp &= ~EDP_FORCE_VDD;
667 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
668 pp_stat_reg = _pp_stat_reg(intel_dp);
670 intel_de_write(dev_priv, pp_ctrl_reg, pp);
671 intel_de_posting_read(dev_priv, pp_ctrl_reg);
673 /* Make sure sequencer is idle before allowing subsequent activity */
674 drm_dbg_kms(&dev_priv->drm, "PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
675 intel_de_read(dev_priv, pp_stat_reg),
676 intel_de_read(dev_priv, pp_ctrl_reg));
678 if ((pp & PANEL_POWER_ON) == 0)
679 intel_dp->pps.panel_power_off_time = ktime_get_boottime();
681 intel_display_power_put(dev_priv,
682 intel_aux_power_domain(dig_port),
683 fetch_and_zero(&intel_dp->pps.vdd_wakeref));
686 void intel_pps_vdd_off_sync(struct intel_dp *intel_dp)
688 intel_wakeref_t wakeref;
690 if (!intel_dp_is_edp(intel_dp))
693 cancel_delayed_work_sync(&intel_dp->pps.panel_vdd_work);
695 * vdd might still be enabled due to the delayed vdd off.
696 * Make sure vdd is actually turned off here.
698 with_intel_pps_lock(intel_dp, wakeref)
699 intel_pps_vdd_off_sync_unlocked(intel_dp);
702 static void edp_panel_vdd_work(struct work_struct *__work)
704 struct intel_pps *pps = container_of(to_delayed_work(__work),
705 struct intel_pps, panel_vdd_work);
706 struct intel_dp *intel_dp = container_of(pps, struct intel_dp, pps);
707 intel_wakeref_t wakeref;
709 with_intel_pps_lock(intel_dp, wakeref) {
710 if (!intel_dp->pps.want_panel_vdd)
711 intel_pps_vdd_off_sync_unlocked(intel_dp);
715 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
720 * Queue the timer to fire a long time from now (relative to the power
721 * down delay) to keep the panel power up across a sequence of
724 delay = msecs_to_jiffies(intel_dp->pps.panel_power_cycle_delay * 5);
725 schedule_delayed_work(&intel_dp->pps.panel_vdd_work, delay);
729 * Must be paired with edp_panel_vdd_on().
730 * Must hold pps_mutex around the whole on/off sequence.
731 * Can be nested with intel_pps_vdd_{on,off}() calls.
733 void intel_pps_vdd_off_unlocked(struct intel_dp *intel_dp, bool sync)
735 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
737 lockdep_assert_held(&dev_priv->pps_mutex);
739 if (!intel_dp_is_edp(intel_dp))
742 I915_STATE_WARN(!intel_dp->pps.want_panel_vdd, "[ENCODER:%d:%s] VDD not forced on",
743 dp_to_dig_port(intel_dp)->base.base.base.id,
744 dp_to_dig_port(intel_dp)->base.base.name);
746 intel_dp->pps.want_panel_vdd = false;
749 intel_pps_vdd_off_sync_unlocked(intel_dp);
751 edp_panel_vdd_schedule_off(intel_dp);
754 void intel_pps_on_unlocked(struct intel_dp *intel_dp)
756 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
758 i915_reg_t pp_ctrl_reg;
760 lockdep_assert_held(&dev_priv->pps_mutex);
762 if (!intel_dp_is_edp(intel_dp))
765 drm_dbg_kms(&dev_priv->drm, "Turn [ENCODER:%d:%s] panel power on\n",
766 dp_to_dig_port(intel_dp)->base.base.base.id,
767 dp_to_dig_port(intel_dp)->base.base.name);
769 if (drm_WARN(&dev_priv->drm, edp_have_panel_power(intel_dp),
770 "[ENCODER:%d:%s] panel power already on\n",
771 dp_to_dig_port(intel_dp)->base.base.base.id,
772 dp_to_dig_port(intel_dp)->base.base.name))
775 wait_panel_power_cycle(intel_dp);
777 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
778 pp = ilk_get_pp_control(intel_dp);
779 if (IS_IRONLAKE(dev_priv)) {
780 /* ILK workaround: disable reset around power sequence */
781 pp &= ~PANEL_POWER_RESET;
782 intel_de_write(dev_priv, pp_ctrl_reg, pp);
783 intel_de_posting_read(dev_priv, pp_ctrl_reg);
786 pp |= PANEL_POWER_ON;
787 if (!IS_IRONLAKE(dev_priv))
788 pp |= PANEL_POWER_RESET;
790 intel_de_write(dev_priv, pp_ctrl_reg, pp);
791 intel_de_posting_read(dev_priv, pp_ctrl_reg);
793 wait_panel_on(intel_dp);
794 intel_dp->pps.last_power_on = jiffies;
796 if (IS_IRONLAKE(dev_priv)) {
797 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
798 intel_de_write(dev_priv, pp_ctrl_reg, pp);
799 intel_de_posting_read(dev_priv, pp_ctrl_reg);
803 void intel_pps_on(struct intel_dp *intel_dp)
805 intel_wakeref_t wakeref;
807 if (!intel_dp_is_edp(intel_dp))
810 with_intel_pps_lock(intel_dp, wakeref)
811 intel_pps_on_unlocked(intel_dp);
814 void intel_pps_off_unlocked(struct intel_dp *intel_dp)
816 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
817 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
819 i915_reg_t pp_ctrl_reg;
821 lockdep_assert_held(&dev_priv->pps_mutex);
823 if (!intel_dp_is_edp(intel_dp))
826 drm_dbg_kms(&dev_priv->drm, "Turn [ENCODER:%d:%s] panel power off\n",
827 dig_port->base.base.base.id, dig_port->base.base.name);
829 drm_WARN(&dev_priv->drm, !intel_dp->pps.want_panel_vdd,
830 "Need [ENCODER:%d:%s] VDD to turn off panel\n",
831 dig_port->base.base.base.id, dig_port->base.base.name);
833 pp = ilk_get_pp_control(intel_dp);
834 /* We need to switch off panel power _and_ force vdd, for otherwise some
835 * panels get very unhappy and cease to work. */
836 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
839 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
841 intel_dp->pps.want_panel_vdd = false;
843 intel_de_write(dev_priv, pp_ctrl_reg, pp);
844 intel_de_posting_read(dev_priv, pp_ctrl_reg);
846 wait_panel_off(intel_dp);
847 intel_dp->pps.panel_power_off_time = ktime_get_boottime();
849 /* We got a reference when we enabled the VDD. */
850 intel_display_power_put(dev_priv,
851 intel_aux_power_domain(dig_port),
852 fetch_and_zero(&intel_dp->pps.vdd_wakeref));
855 void intel_pps_off(struct intel_dp *intel_dp)
857 intel_wakeref_t wakeref;
859 if (!intel_dp_is_edp(intel_dp))
862 with_intel_pps_lock(intel_dp, wakeref)
863 intel_pps_off_unlocked(intel_dp);
866 /* Enable backlight in the panel power control. */
867 void intel_pps_backlight_on(struct intel_dp *intel_dp)
869 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
870 intel_wakeref_t wakeref;
873 * If we enable the backlight right away following a panel power
874 * on, we may see slight flicker as the panel syncs with the eDP
875 * link. So delay a bit to make sure the image is solid before
876 * allowing it to appear.
878 wait_backlight_on(intel_dp);
880 with_intel_pps_lock(intel_dp, wakeref) {
881 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
884 pp = ilk_get_pp_control(intel_dp);
885 pp |= EDP_BLC_ENABLE;
887 intel_de_write(dev_priv, pp_ctrl_reg, pp);
888 intel_de_posting_read(dev_priv, pp_ctrl_reg);
892 /* Disable backlight in the panel power control. */
893 void intel_pps_backlight_off(struct intel_dp *intel_dp)
895 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
896 intel_wakeref_t wakeref;
898 if (!intel_dp_is_edp(intel_dp))
901 with_intel_pps_lock(intel_dp, wakeref) {
902 i915_reg_t pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
905 pp = ilk_get_pp_control(intel_dp);
906 pp &= ~EDP_BLC_ENABLE;
908 intel_de_write(dev_priv, pp_ctrl_reg, pp);
909 intel_de_posting_read(dev_priv, pp_ctrl_reg);
912 intel_dp->pps.last_backlight_off = jiffies;
913 edp_wait_backlight_off(intel_dp);
917 * Hook for controlling the panel power control backlight through the bl_power
918 * sysfs attribute. Take care to handle multiple calls.
920 void intel_pps_backlight_power(struct intel_connector *connector, bool enable)
922 struct drm_i915_private *i915 = to_i915(connector->base.dev);
923 struct intel_dp *intel_dp = intel_attached_dp(connector);
924 intel_wakeref_t wakeref;
928 with_intel_pps_lock(intel_dp, wakeref)
929 is_enabled = ilk_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
930 if (is_enabled == enable)
933 drm_dbg_kms(&i915->drm, "panel power control backlight %s\n",
934 enable ? "enable" : "disable");
937 intel_pps_backlight_on(intel_dp);
939 intel_pps_backlight_off(intel_dp);
942 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
944 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
945 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
946 enum pipe pipe = intel_dp->pps.pps_pipe;
947 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
949 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.active_pipe != INVALID_PIPE);
951 if (drm_WARN_ON(&dev_priv->drm, pipe != PIPE_A && pipe != PIPE_B))
954 intel_pps_vdd_off_sync_unlocked(intel_dp);
957 * VLV seems to get confused when multiple power sequencers
958 * have the same port selected (even if only one has power/vdd
959 * enabled). The failure manifests as vlv_wait_port_ready() failing
960 * CHV on the other hand doesn't seem to mind having the same port
961 * selected in multiple power sequencers, but let's clear the
962 * port select always when logically disconnecting a power sequencer
965 drm_dbg_kms(&dev_priv->drm,
966 "detaching pipe %c power sequencer from [ENCODER:%d:%s]\n",
967 pipe_name(pipe), dig_port->base.base.base.id,
968 dig_port->base.base.name);
969 intel_de_write(dev_priv, pp_on_reg, 0);
970 intel_de_posting_read(dev_priv, pp_on_reg);
972 intel_dp->pps.pps_pipe = INVALID_PIPE;
975 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
978 struct intel_encoder *encoder;
980 lockdep_assert_held(&dev_priv->pps_mutex);
982 for_each_intel_dp(&dev_priv->drm, encoder) {
983 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
985 drm_WARN(&dev_priv->drm, intel_dp->pps.active_pipe == pipe,
986 "stealing pipe %c power sequencer from active [ENCODER:%d:%s]\n",
987 pipe_name(pipe), encoder->base.base.id,
990 if (intel_dp->pps.pps_pipe != pipe)
993 drm_dbg_kms(&dev_priv->drm,
994 "stealing pipe %c power sequencer from [ENCODER:%d:%s]\n",
995 pipe_name(pipe), encoder->base.base.id,
998 /* make sure vdd is off before we steal it */
999 vlv_detach_power_sequencer(intel_dp);
1003 void vlv_pps_init(struct intel_encoder *encoder,
1004 const struct intel_crtc_state *crtc_state)
1006 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1007 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1008 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1010 lockdep_assert_held(&dev_priv->pps_mutex);
1012 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.active_pipe != INVALID_PIPE);
1014 if (intel_dp->pps.pps_pipe != INVALID_PIPE &&
1015 intel_dp->pps.pps_pipe != crtc->pipe) {
1017 * If another power sequencer was being used on this
1018 * port previously make sure to turn off vdd there while
1019 * we still have control of it.
1021 vlv_detach_power_sequencer(intel_dp);
1025 * We may be stealing the power
1026 * sequencer from another port.
1028 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
1030 intel_dp->pps.active_pipe = crtc->pipe;
1032 if (!intel_dp_is_edp(intel_dp))
1035 /* now it's all ours */
1036 intel_dp->pps.pps_pipe = crtc->pipe;
1038 drm_dbg_kms(&dev_priv->drm,
1039 "initializing pipe %c power sequencer for [ENCODER:%d:%s]\n",
1040 pipe_name(intel_dp->pps.pps_pipe), encoder->base.base.id,
1041 encoder->base.name);
1043 /* init power sequencer on this pipe and port */
1044 pps_init_delays(intel_dp);
1045 pps_init_registers(intel_dp, true);
1048 static void intel_pps_vdd_sanitize(struct intel_dp *intel_dp)
1050 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1051 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1053 lockdep_assert_held(&dev_priv->pps_mutex);
1055 if (!edp_have_panel_vdd(intel_dp))
1059 * The VDD bit needs a power domain reference, so if the bit is
1060 * already enabled when we boot or resume, grab this reference and
1061 * schedule a vdd off, so we don't hold on to the reference
1064 drm_dbg_kms(&dev_priv->drm,
1065 "VDD left on by BIOS, adjusting state tracking\n");
1066 drm_WARN_ON(&dev_priv->drm, intel_dp->pps.vdd_wakeref);
1067 intel_dp->pps.vdd_wakeref = intel_display_power_get(dev_priv,
1068 intel_aux_power_domain(dig_port));
1070 edp_panel_vdd_schedule_off(intel_dp);
1073 bool intel_pps_have_power(struct intel_dp *intel_dp)
1075 intel_wakeref_t wakeref;
1076 bool have_power = false;
1078 with_intel_pps_lock(intel_dp, wakeref) {
1079 have_power = edp_have_panel_power(intel_dp) &&
1080 edp_have_panel_vdd(intel_dp);
1086 static void pps_init_timestamps(struct intel_dp *intel_dp)
1088 intel_dp->pps.panel_power_off_time = ktime_get_boottime();
1089 intel_dp->pps.last_power_on = jiffies;
1090 intel_dp->pps.last_backlight_off = jiffies;
1094 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
1096 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1097 u32 pp_on, pp_off, pp_ctl;
1098 struct pps_registers regs;
1100 intel_pps_get_registers(intel_dp, ®s);
1102 pp_ctl = ilk_get_pp_control(intel_dp);
1104 /* Ensure PPS is unlocked */
1105 if (!HAS_DDI(dev_priv))
1106 intel_de_write(dev_priv, regs.pp_ctrl, pp_ctl);
1108 pp_on = intel_de_read(dev_priv, regs.pp_on);
1109 pp_off = intel_de_read(dev_priv, regs.pp_off);
1111 /* Pull timing values out of registers */
1112 seq->t1_t3 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on);
1113 seq->t8 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on);
1114 seq->t9 = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off);
1115 seq->t10 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off);
1117 if (i915_mmio_reg_valid(regs.pp_div)) {
1120 pp_div = intel_de_read(dev_priv, regs.pp_div);
1122 seq->t11_t12 = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div) * 1000;
1124 seq->t11_t12 = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl) * 1000;
1129 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
1131 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
1133 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
1137 intel_pps_verify_state(struct intel_dp *intel_dp)
1139 struct edp_power_seq hw;
1140 struct edp_power_seq *sw = &intel_dp->pps.pps_delays;
1142 intel_pps_readout_hw_state(intel_dp, &hw);
1144 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
1145 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
1146 DRM_ERROR("PPS state mismatch\n");
1147 intel_pps_dump_state("sw", sw);
1148 intel_pps_dump_state("hw", &hw);
1152 static void pps_init_delays(struct intel_dp *intel_dp)
1154 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1155 struct edp_power_seq cur, vbt, spec,
1156 *final = &intel_dp->pps.pps_delays;
1158 lockdep_assert_held(&dev_priv->pps_mutex);
1160 /* already initialized? */
1161 if (final->t11_t12 != 0)
1164 intel_pps_readout_hw_state(intel_dp, &cur);
1166 intel_pps_dump_state("cur", &cur);
1168 vbt = dev_priv->vbt.edp.pps;
1169 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
1170 * of 500ms appears to be too short. Ocassionally the panel
1171 * just fails to power back on. Increasing the delay to 800ms
1172 * seems sufficient to avoid this problem.
1174 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
1175 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
1176 drm_dbg_kms(&dev_priv->drm,
1177 "Increasing T12 panel delay as per the quirk to %d\n",
1180 /* T11_T12 delay is special and actually in units of 100ms, but zero
1181 * based in the hw (so we need to add 100 ms). But the sw vbt
1182 * table multiplies it with 1000 to make it in units of 100usec,
1184 vbt.t11_t12 += 100 * 10;
1186 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
1187 * our hw here, which are all in 100usec. */
1188 spec.t1_t3 = 210 * 10;
1189 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
1190 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
1191 spec.t10 = 500 * 10;
1192 /* This one is special and actually in units of 100ms, but zero
1193 * based in the hw (so we need to add 100 ms). But the sw vbt
1194 * table multiplies it with 1000 to make it in units of 100usec,
1196 spec.t11_t12 = (510 + 100) * 10;
1198 intel_pps_dump_state("vbt", &vbt);
1200 /* Use the max of the register settings and vbt. If both are
1201 * unset, fall back to the spec limits. */
1202 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
1204 max(cur.field, vbt.field))
1205 assign_final(t1_t3);
1209 assign_final(t11_t12);
1212 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
1213 intel_dp->pps.panel_power_up_delay = get_delay(t1_t3);
1214 intel_dp->pps.backlight_on_delay = get_delay(t8);
1215 intel_dp->pps.backlight_off_delay = get_delay(t9);
1216 intel_dp->pps.panel_power_down_delay = get_delay(t10);
1217 intel_dp->pps.panel_power_cycle_delay = get_delay(t11_t12);
1220 drm_dbg_kms(&dev_priv->drm,
1221 "panel power up delay %d, power down delay %d, power cycle delay %d\n",
1222 intel_dp->pps.panel_power_up_delay,
1223 intel_dp->pps.panel_power_down_delay,
1224 intel_dp->pps.panel_power_cycle_delay);
1226 drm_dbg_kms(&dev_priv->drm, "backlight on delay %d, off delay %d\n",
1227 intel_dp->pps.backlight_on_delay,
1228 intel_dp->pps.backlight_off_delay);
1231 * We override the HW backlight delays to 1 because we do manual waits
1232 * on them. For T8, even BSpec recommends doing it. For T9, if we
1233 * don't do this, we'll end up waiting for the backlight off delay
1234 * twice: once when we do the manual sleep, and once when we disable
1235 * the panel and wait for the PP_STATUS bit to become zero.
1241 * HW has only a 100msec granularity for t11_t12 so round it up
1244 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
1247 static void pps_init_registers(struct intel_dp *intel_dp, bool force_disable_vdd)
1249 struct drm_i915_private *dev_priv = dp_to_i915(intel_dp);
1250 u32 pp_on, pp_off, port_sel = 0;
1251 int div = RUNTIME_INFO(dev_priv)->rawclk_freq / 1000;
1252 struct pps_registers regs;
1253 enum port port = dp_to_dig_port(intel_dp)->base.port;
1254 const struct edp_power_seq *seq = &intel_dp->pps.pps_delays;
1256 lockdep_assert_held(&dev_priv->pps_mutex);
1258 intel_pps_get_registers(intel_dp, ®s);
1261 * On some VLV machines the BIOS can leave the VDD
1262 * enabled even on power sequencers which aren't
1263 * hooked up to any port. This would mess up the
1264 * power domain tracking the first time we pick
1265 * one of these power sequencers for use since
1266 * intel_pps_vdd_on_unlocked() would notice that the VDD was
1267 * already on and therefore wouldn't grab the power
1268 * domain reference. Disable VDD first to avoid this.
1269 * This also avoids spuriously turning the VDD on as
1270 * soon as the new power sequencer gets initialized.
1272 if (force_disable_vdd) {
1273 u32 pp = ilk_get_pp_control(intel_dp);
1275 drm_WARN(&dev_priv->drm, pp & PANEL_POWER_ON,
1276 "Panel power already on\n");
1278 if (pp & EDP_FORCE_VDD)
1279 drm_dbg_kms(&dev_priv->drm,
1280 "VDD already on, disabling first\n");
1282 pp &= ~EDP_FORCE_VDD;
1284 intel_de_write(dev_priv, regs.pp_ctrl, pp);
1287 pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->t1_t3) |
1288 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->t8);
1289 pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->t9) |
1290 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->t10);
1292 /* Haswell doesn't have any port selection bits for the panel
1293 * power sequencer any more. */
1294 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1295 port_sel = PANEL_PORT_SELECT_VLV(port);
1296 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
1299 port_sel = PANEL_PORT_SELECT_DPA;
1302 port_sel = PANEL_PORT_SELECT_DPC;
1305 port_sel = PANEL_PORT_SELECT_DPD;
1315 intel_de_write(dev_priv, regs.pp_on, pp_on);
1316 intel_de_write(dev_priv, regs.pp_off, pp_off);
1319 * Compute the divisor for the pp clock, simply match the Bspec formula.
1321 if (i915_mmio_reg_valid(regs.pp_div)) {
1322 intel_de_write(dev_priv, regs.pp_div,
1323 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)));
1327 pp_ctl = intel_de_read(dev_priv, regs.pp_ctrl);
1328 pp_ctl &= ~BXT_POWER_CYCLE_DELAY_MASK;
1329 pp_ctl |= REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000));
1330 intel_de_write(dev_priv, regs.pp_ctrl, pp_ctl);
1333 drm_dbg_kms(&dev_priv->drm,
1334 "panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
1335 intel_de_read(dev_priv, regs.pp_on),
1336 intel_de_read(dev_priv, regs.pp_off),
1337 i915_mmio_reg_valid(regs.pp_div) ?
1338 intel_de_read(dev_priv, regs.pp_div) :
1339 (intel_de_read(dev_priv, regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK));
1342 void intel_pps_encoder_reset(struct intel_dp *intel_dp)
1344 struct drm_i915_private *i915 = dp_to_i915(intel_dp);
1345 intel_wakeref_t wakeref;
1347 if (!intel_dp_is_edp(intel_dp))
1350 with_intel_pps_lock(intel_dp, wakeref) {
1352 * Reinit the power sequencer also on the resume path, in case
1353 * BIOS did something nasty with it.
1355 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
1356 vlv_initial_power_sequencer_setup(intel_dp);
1358 pps_init_delays(intel_dp);
1359 pps_init_registers(intel_dp, false);
1361 intel_pps_vdd_sanitize(intel_dp);
1365 void intel_pps_init(struct intel_dp *intel_dp)
1367 INIT_DELAYED_WORK(&intel_dp->pps.panel_vdd_work, edp_panel_vdd_work);
1369 pps_init_timestamps(intel_dp);
1371 intel_pps_encoder_reset(intel_dp);
1374 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
1379 if (HAS_DDI(dev_priv))
1382 * This w/a is needed at least on CPT/PPT, but to be sure apply it
1383 * everywhere where registers can be write protected.
1385 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1390 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
1391 u32 val = intel_de_read(dev_priv, PP_CONTROL(pps_idx));
1393 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
1394 intel_de_write(dev_priv, PP_CONTROL(pps_idx), val);
1398 void intel_pps_setup(struct drm_i915_private *i915)
1400 if (HAS_PCH_SPLIT(i915) || IS_GEMINILAKE(i915) || IS_BROXTON(i915))
1401 i915->pps_mmio_base = PCH_PPS_BASE;
1402 else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
1403 i915->pps_mmio_base = VLV_PPS_BASE;
1405 i915->pps_mmio_base = PPS_BASE;