2 * Copyright © 2008 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Keith Packard <keithp@keithp.com>
28 #include <linux/i2c.h>
29 #include <linux/slab.h>
30 #include <linux/export.h>
31 #include <linux/types.h>
32 #include <linux/notifier.h>
33 #include <linux/reboot.h>
34 #include <asm/byteorder.h>
36 #include <drm/drm_atomic_helper.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_crtc_helper.h>
39 #include <drm/drm_edid.h>
40 #include "intel_drv.h"
41 #include <drm/i915_drm.h>
44 #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
45 #define DP_DPRX_ESI_LEN 14
47 /* Compliance test status bits */
48 #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
49 #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
50 #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
51 #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
58 static const struct dp_link_dpll gen4_dpll[] = {
60 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
62 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
65 static const struct dp_link_dpll pch_dpll[] = {
67 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
69 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
72 static const struct dp_link_dpll vlv_dpll[] = {
74 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
76 { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
80 * CHV supports eDP 1.4 that have more link rates.
81 * Below only provides the fixed rate but exclude variable rate.
83 static const struct dp_link_dpll chv_dpll[] = {
85 * CHV requires to program fractional division for m2.
86 * m2 is stored in fixed point format using formula below
87 * (m2_int << 22) | m2_fraction
89 { 162000, /* m2_int = 32, m2_fraction = 1677722 */
90 { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
91 { 270000, /* m2_int = 27, m2_fraction = 0 */
92 { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
93 { 540000, /* m2_int = 27, m2_fraction = 0 */
94 { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
97 static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
98 324000, 432000, 540000 };
99 static const int skl_rates[] = { 162000, 216000, 270000,
100 324000, 432000, 540000 };
101 static const int cnl_rates[] = { 162000, 216000, 270000,
102 324000, 432000, 540000,
104 static const int default_rates[] = { 162000, 270000, 540000 };
107 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH)
108 * @intel_dp: DP struct
110 * If a CPU or PCH DP output is attached to an eDP panel, this function
111 * will return true, and false otherwise.
113 bool intel_dp_is_edp(struct intel_dp *intel_dp)
115 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
117 return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
120 static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
122 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
124 return intel_dig_port->base.base.dev;
127 static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
129 return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
132 static void intel_dp_link_down(struct intel_encoder *encoder,
133 const struct intel_crtc_state *old_crtc_state);
134 static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
135 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
136 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
137 const struct intel_crtc_state *crtc_state);
138 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
140 static void intel_dp_unset_edid(struct intel_dp *intel_dp);
142 /* update sink rates from dpcd */
143 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
147 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]);
149 for (i = 0; i < ARRAY_SIZE(default_rates); i++) {
150 if (default_rates[i] > max_rate)
152 intel_dp->sink_rates[i] = default_rates[i];
155 intel_dp->num_sink_rates = i;
158 /* Get length of rates array potentially limited by max_rate. */
159 static int intel_dp_rate_limit_len(const int *rates, int len, int max_rate)
163 /* Limit results by potentially reduced max rate */
164 for (i = 0; i < len; i++) {
165 if (rates[len - i - 1] <= max_rate)
172 /* Get length of common rates array potentially limited by max_rate. */
173 static int intel_dp_common_len_rate_limit(const struct intel_dp *intel_dp,
176 return intel_dp_rate_limit_len(intel_dp->common_rates,
177 intel_dp->num_common_rates, max_rate);
180 /* Theoretical max between source and sink */
181 static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
183 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
186 /* Theoretical max between source and sink */
187 static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
189 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
190 int source_max = intel_dig_port->max_lanes;
191 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
193 return min(source_max, sink_max);
196 int intel_dp_max_lane_count(struct intel_dp *intel_dp)
198 return intel_dp->max_link_lane_count;
202 intel_dp_link_required(int pixel_clock, int bpp)
204 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
205 return DIV_ROUND_UP(pixel_clock * bpp, 8);
209 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
211 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
212 * link rate that is generally expressed in Gbps. Since, 8 bits of data
213 * is transmitted every LS_Clk per lane, there is no need to account for
214 * the channel encoding that is done in the PHY layer here.
217 return max_link_clock * max_lanes;
221 intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
223 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
224 struct intel_encoder *encoder = &intel_dig_port->base;
225 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
226 int max_dotclk = dev_priv->max_dotclk_freq;
229 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
231 if (type != DP_DS_PORT_TYPE_VGA)
234 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
235 intel_dp->downstream_ports);
237 if (ds_max_dotclk != 0)
238 max_dotclk = min(max_dotclk, ds_max_dotclk);
243 static int cnl_adjusted_max_rate(struct intel_dp *intel_dp, int size)
245 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
246 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
247 enum port port = dig_port->base.port;
249 u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
251 /* Low voltage SKUs are limited to max of 5.4G */
252 if (voltage == VOLTAGE_INFO_0_85V)
255 /* For this SKU 8.1G is supported in all ports */
256 if (IS_CNL_WITH_PORT_F(dev_priv))
259 /* For other SKUs, max rate on ports A and B is 5.4G */
260 if (port == PORT_A || port == PORT_D)
267 intel_dp_set_source_rates(struct intel_dp *intel_dp)
269 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
270 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
271 const int *source_rates;
274 /* This should only be done once */
275 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
277 if (IS_GEN9_LP(dev_priv)) {
278 source_rates = bxt_rates;
279 size = ARRAY_SIZE(bxt_rates);
280 } else if (IS_CANNONLAKE(dev_priv)) {
281 source_rates = cnl_rates;
282 size = cnl_adjusted_max_rate(intel_dp, ARRAY_SIZE(cnl_rates));
283 } else if (IS_GEN9_BC(dev_priv)) {
284 source_rates = skl_rates;
285 size = ARRAY_SIZE(skl_rates);
286 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
287 IS_BROADWELL(dev_priv)) {
288 source_rates = default_rates;
289 size = ARRAY_SIZE(default_rates);
291 source_rates = default_rates;
292 size = ARRAY_SIZE(default_rates) - 1;
295 intel_dp->source_rates = source_rates;
296 intel_dp->num_source_rates = size;
299 static int intersect_rates(const int *source_rates, int source_len,
300 const int *sink_rates, int sink_len,
303 int i = 0, j = 0, k = 0;
305 while (i < source_len && j < sink_len) {
306 if (source_rates[i] == sink_rates[j]) {
307 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
309 common_rates[k] = source_rates[i];
313 } else if (source_rates[i] < sink_rates[j]) {
322 /* return index of rate in rates array, or -1 if not found */
323 static int intel_dp_rate_index(const int *rates, int len, int rate)
327 for (i = 0; i < len; i++)
328 if (rate == rates[i])
334 static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
336 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
338 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
339 intel_dp->num_source_rates,
340 intel_dp->sink_rates,
341 intel_dp->num_sink_rates,
342 intel_dp->common_rates);
344 /* Paranoia, there should always be something in common. */
345 if (WARN_ON(intel_dp->num_common_rates == 0)) {
346 intel_dp->common_rates[0] = default_rates[0];
347 intel_dp->num_common_rates = 1;
351 static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
355 * FIXME: we need to synchronize the current link parameters with
356 * hardware readout. Currently fast link training doesn't work on
359 if (link_rate == 0 ||
360 link_rate > intel_dp->max_link_rate)
363 if (lane_count == 0 ||
364 lane_count > intel_dp_max_lane_count(intel_dp))
370 int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
371 int link_rate, uint8_t lane_count)
375 index = intel_dp_rate_index(intel_dp->common_rates,
376 intel_dp->num_common_rates,
379 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
380 intel_dp->max_link_lane_count = lane_count;
381 } else if (lane_count > 1) {
382 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
383 intel_dp->max_link_lane_count = lane_count >> 1;
385 DRM_ERROR("Link Training Unsuccessful\n");
392 static enum drm_mode_status
393 intel_dp_mode_valid(struct drm_connector *connector,
394 struct drm_display_mode *mode)
396 struct intel_dp *intel_dp = intel_attached_dp(connector);
397 struct intel_connector *intel_connector = to_intel_connector(connector);
398 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
399 int target_clock = mode->clock;
400 int max_rate, mode_rate, max_lanes, max_link_clock;
403 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
405 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
406 if (mode->hdisplay > fixed_mode->hdisplay)
409 if (mode->vdisplay > fixed_mode->vdisplay)
412 target_clock = fixed_mode->clock;
415 max_link_clock = intel_dp_max_link_rate(intel_dp);
416 max_lanes = intel_dp_max_lane_count(intel_dp);
418 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
419 mode_rate = intel_dp_link_required(target_clock, 18);
421 if (mode_rate > max_rate || target_clock > max_dotclk)
422 return MODE_CLOCK_HIGH;
424 if (mode->clock < 10000)
425 return MODE_CLOCK_LOW;
427 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
428 return MODE_H_ILLEGAL;
433 uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
440 for (i = 0; i < src_bytes; i++)
441 v |= ((uint32_t) src[i]) << ((3-i) * 8);
445 static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
450 for (i = 0; i < dst_bytes; i++)
451 dst[i] = src >> ((3-i) * 8);
455 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
457 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
458 bool force_disable_vdd);
460 intel_dp_pps_init(struct intel_dp *intel_dp);
462 static void pps_lock(struct intel_dp *intel_dp)
464 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
467 * See intel_power_sequencer_reset() why we need
468 * a power domain reference here.
470 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
472 mutex_lock(&dev_priv->pps_mutex);
475 static void pps_unlock(struct intel_dp *intel_dp)
477 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
479 mutex_unlock(&dev_priv->pps_mutex);
481 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
485 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
487 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
488 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
489 enum pipe pipe = intel_dp->pps_pipe;
490 bool pll_enabled, release_cl_override = false;
491 enum dpio_phy phy = DPIO_PHY(pipe);
492 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
495 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
496 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
497 pipe_name(pipe), port_name(intel_dig_port->base.port)))
500 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
501 pipe_name(pipe), port_name(intel_dig_port->base.port));
503 /* Preserve the BIOS-computed detected bit. This is
504 * supposed to be read-only.
506 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
507 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
508 DP |= DP_PORT_WIDTH(1);
509 DP |= DP_LINK_TRAIN_PAT_1;
511 if (IS_CHERRYVIEW(dev_priv))
512 DP |= DP_PIPE_SELECT_CHV(pipe);
513 else if (pipe == PIPE_B)
514 DP |= DP_PIPEB_SELECT;
516 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
519 * The DPLL for the pipe must be enabled for this to work.
520 * So enable temporarily it if it's not already enabled.
523 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
524 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
526 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
527 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
528 DRM_ERROR("Failed to force on pll for pipe %c!\n",
535 * Similar magic as in intel_dp_enable_port().
536 * We _must_ do this port enable + disable trick
537 * to make this power seqeuencer lock onto the port.
538 * Otherwise even VDD force bit won't work.
540 I915_WRITE(intel_dp->output_reg, DP);
541 POSTING_READ(intel_dp->output_reg);
543 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
544 POSTING_READ(intel_dp->output_reg);
546 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
547 POSTING_READ(intel_dp->output_reg);
550 vlv_force_pll_off(dev_priv, pipe);
552 if (release_cl_override)
553 chv_phy_powergate_ch(dev_priv, phy, ch, false);
557 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
559 struct intel_encoder *encoder;
560 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
563 * We don't have power sequencer currently.
564 * Pick one that's not used by other ports.
566 for_each_intel_encoder(&dev_priv->drm, encoder) {
567 struct intel_dp *intel_dp;
569 if (encoder->type != INTEL_OUTPUT_DP &&
570 encoder->type != INTEL_OUTPUT_EDP)
573 intel_dp = enc_to_intel_dp(&encoder->base);
575 if (encoder->type == INTEL_OUTPUT_EDP) {
576 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
577 intel_dp->active_pipe != intel_dp->pps_pipe);
579 if (intel_dp->pps_pipe != INVALID_PIPE)
580 pipes &= ~(1 << intel_dp->pps_pipe);
582 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
584 if (intel_dp->active_pipe != INVALID_PIPE)
585 pipes &= ~(1 << intel_dp->active_pipe);
592 return ffs(pipes) - 1;
596 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
598 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
599 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
602 lockdep_assert_held(&dev_priv->pps_mutex);
604 /* We should never land here with regular DP ports */
605 WARN_ON(!intel_dp_is_edp(intel_dp));
607 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
608 intel_dp->active_pipe != intel_dp->pps_pipe);
610 if (intel_dp->pps_pipe != INVALID_PIPE)
611 return intel_dp->pps_pipe;
613 pipe = vlv_find_free_pps(dev_priv);
616 * Didn't find one. This should not happen since there
617 * are two power sequencers and up to two eDP ports.
619 if (WARN_ON(pipe == INVALID_PIPE))
622 vlv_steal_power_sequencer(dev_priv, pipe);
623 intel_dp->pps_pipe = pipe;
625 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
626 pipe_name(intel_dp->pps_pipe),
627 port_name(intel_dig_port->base.port));
629 /* init power sequencer on this pipe and port */
630 intel_dp_init_panel_power_sequencer(intel_dp);
631 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
634 * Even vdd force doesn't work until we've made
635 * the power sequencer lock in on the port.
637 vlv_power_sequencer_kick(intel_dp);
639 return intel_dp->pps_pipe;
643 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
645 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
647 lockdep_assert_held(&dev_priv->pps_mutex);
649 /* We should never land here with regular DP ports */
650 WARN_ON(!intel_dp_is_edp(intel_dp));
653 * TODO: BXT has 2 PPS instances. The correct port->PPS instance
654 * mapping needs to be retrieved from VBT, for now just hard-code to
655 * use instance #0 always.
657 if (!intel_dp->pps_reset)
660 intel_dp->pps_reset = false;
663 * Only the HW needs to be reprogrammed, the SW state is fixed and
664 * has been setup during connector init.
666 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
671 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
674 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
677 return I915_READ(PP_STATUS(pipe)) & PP_ON;
680 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
683 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
686 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
693 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
695 vlv_pipe_check pipe_check)
699 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
700 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
701 PANEL_PORT_SELECT_MASK;
703 if (port_sel != PANEL_PORT_SELECT_VLV(port))
706 if (!pipe_check(dev_priv, pipe))
716 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
718 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
719 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
720 enum port port = intel_dig_port->base.port;
722 lockdep_assert_held(&dev_priv->pps_mutex);
724 /* try to find a pipe with this port selected */
725 /* first pick one where the panel is on */
726 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
728 /* didn't find one? pick one where vdd is on */
729 if (intel_dp->pps_pipe == INVALID_PIPE)
730 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
731 vlv_pipe_has_vdd_on);
732 /* didn't find one? pick one with just the correct port */
733 if (intel_dp->pps_pipe == INVALID_PIPE)
734 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
737 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
738 if (intel_dp->pps_pipe == INVALID_PIPE) {
739 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
744 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
745 port_name(port), pipe_name(intel_dp->pps_pipe));
747 intel_dp_init_panel_power_sequencer(intel_dp);
748 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
751 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
753 struct intel_encoder *encoder;
755 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
756 !IS_GEN9_LP(dev_priv)))
760 * We can't grab pps_mutex here due to deadlock with power_domain
761 * mutex when power_domain functions are called while holding pps_mutex.
762 * That also means that in order to use pps_pipe the code needs to
763 * hold both a power domain reference and pps_mutex, and the power domain
764 * reference get/put must be done while _not_ holding pps_mutex.
765 * pps_{lock,unlock}() do these steps in the correct order, so one
766 * should use them always.
769 for_each_intel_encoder(&dev_priv->drm, encoder) {
770 struct intel_dp *intel_dp;
772 if (encoder->type != INTEL_OUTPUT_DP &&
773 encoder->type != INTEL_OUTPUT_EDP &&
774 encoder->type != INTEL_OUTPUT_DDI)
777 intel_dp = enc_to_intel_dp(&encoder->base);
779 /* Skip pure DVI/HDMI DDI encoders */
780 if (!i915_mmio_reg_valid(intel_dp->output_reg))
783 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
785 if (encoder->type != INTEL_OUTPUT_EDP)
788 if (IS_GEN9_LP(dev_priv))
789 intel_dp->pps_reset = true;
791 intel_dp->pps_pipe = INVALID_PIPE;
795 struct pps_registers {
803 static void intel_pps_get_registers(struct intel_dp *intel_dp,
804 struct pps_registers *regs)
806 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
809 memset(regs, 0, sizeof(*regs));
811 if (IS_GEN9_LP(dev_priv))
812 pps_idx = bxt_power_sequencer_idx(intel_dp);
813 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
814 pps_idx = vlv_power_sequencer_pipe(intel_dp);
816 regs->pp_ctrl = PP_CONTROL(pps_idx);
817 regs->pp_stat = PP_STATUS(pps_idx);
818 regs->pp_on = PP_ON_DELAYS(pps_idx);
819 regs->pp_off = PP_OFF_DELAYS(pps_idx);
820 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
821 !HAS_PCH_ICP(dev_priv))
822 regs->pp_div = PP_DIVISOR(pps_idx);
826 _pp_ctrl_reg(struct intel_dp *intel_dp)
828 struct pps_registers regs;
830 intel_pps_get_registers(intel_dp, ®s);
836 _pp_stat_reg(struct intel_dp *intel_dp)
838 struct pps_registers regs;
840 intel_pps_get_registers(intel_dp, ®s);
845 /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
846 This function only applicable when panel PM state is not to be tracked */
847 static int edp_notify_handler(struct notifier_block *this, unsigned long code,
850 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
852 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
854 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
859 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
860 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
861 i915_reg_t pp_ctrl_reg, pp_div_reg;
864 pp_ctrl_reg = PP_CONTROL(pipe);
865 pp_div_reg = PP_DIVISOR(pipe);
866 pp_div = I915_READ(pp_div_reg);
867 pp_div &= PP_REFERENCE_DIVIDER_MASK;
869 /* 0x1F write to PP_DIV_REG sets max cycle delay */
870 I915_WRITE(pp_div_reg, pp_div | 0x1F);
871 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
872 msleep(intel_dp->panel_power_cycle_delay);
875 pps_unlock(intel_dp);
880 static bool edp_have_panel_power(struct intel_dp *intel_dp)
882 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
884 lockdep_assert_held(&dev_priv->pps_mutex);
886 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
887 intel_dp->pps_pipe == INVALID_PIPE)
890 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
893 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
895 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
897 lockdep_assert_held(&dev_priv->pps_mutex);
899 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
900 intel_dp->pps_pipe == INVALID_PIPE)
903 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
907 intel_dp_check_edp(struct intel_dp *intel_dp)
909 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
911 if (!intel_dp_is_edp(intel_dp))
914 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
915 WARN(1, "eDP powered off while attempting aux channel communication.\n");
916 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
917 I915_READ(_pp_stat_reg(intel_dp)),
918 I915_READ(_pp_ctrl_reg(intel_dp)));
923 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
925 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
926 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
930 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
932 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
933 msecs_to_jiffies_timeout(10));
935 done = wait_for(C, 10) == 0;
937 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
944 static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
946 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
947 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
953 * The clock divider is based off the hrawclk, and would like to run at
954 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
956 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
959 static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
961 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
962 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
968 * The clock divider is based off the cdclk or PCH rawclk, and would
969 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
970 * divide by 2000 and use that
972 if (intel_dig_port->base.port == PORT_A)
973 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
975 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
978 static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
980 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
981 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
983 if (intel_dig_port->base.port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
984 /* Workaround for non-ULT HSW */
992 return ilk_get_aux_clock_divider(intel_dp, index);
995 static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
998 * SKL doesn't need us to program the AUX clock divider (Hardware will
999 * derive the clock from CDCLK automatically). We still implement the
1000 * get_aux_clock_divider vfunc to plug-in into the existing code.
1002 return index ? 0 : 1;
1005 static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
1008 uint32_t aux_clock_divider)
1010 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1011 struct drm_i915_private *dev_priv =
1012 to_i915(intel_dig_port->base.base.dev);
1013 uint32_t precharge, timeout;
1015 if (IS_GEN6(dev_priv))
1020 if (IS_BROADWELL(dev_priv))
1021 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
1023 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
1025 return DP_AUX_CH_CTL_SEND_BUSY |
1026 DP_AUX_CH_CTL_DONE |
1027 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1028 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1030 DP_AUX_CH_CTL_RECEIVE_ERROR |
1031 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1032 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1033 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
1036 static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1041 return DP_AUX_CH_CTL_SEND_BUSY |
1042 DP_AUX_CH_CTL_DONE |
1043 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1044 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1045 DP_AUX_CH_CTL_TIME_OUT_MAX |
1046 DP_AUX_CH_CTL_RECEIVE_ERROR |
1047 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1048 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
1049 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1053 intel_dp_aux_ch(struct intel_dp *intel_dp,
1054 const uint8_t *send, int send_bytes,
1055 uint8_t *recv, int recv_size)
1057 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1058 struct drm_i915_private *dev_priv =
1059 to_i915(intel_dig_port->base.base.dev);
1060 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
1061 uint32_t aux_clock_divider;
1062 int i, ret, recv_bytes;
1065 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
1071 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1072 * In such cases we want to leave VDD enabled and it's up to upper layers
1073 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1076 vdd = edp_panel_vdd_on(intel_dp);
1078 /* dp aux is extremely sensitive to irq latency, hence request the
1079 * lowest possible wakeup latency and so prevent the cpu from going into
1080 * deep sleep states.
1082 pm_qos_update_request(&dev_priv->pm_qos, 0);
1084 intel_dp_check_edp(intel_dp);
1086 /* Try to wait for any previous AUX channel activity */
1087 for (try = 0; try < 3; try++) {
1088 status = I915_READ_NOTRACE(ch_ctl);
1089 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1095 static u32 last_status = -1;
1096 const u32 status = I915_READ(ch_ctl);
1098 if (status != last_status) {
1099 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1101 last_status = status;
1108 /* Only 5 data registers! */
1109 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1114 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
1115 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1120 /* Must try at least 3 times according to DP spec */
1121 for (try = 0; try < 5; try++) {
1122 /* Load the send data into the aux channel data registers */
1123 for (i = 0; i < send_bytes; i += 4)
1124 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
1125 intel_dp_pack_aux(send + i,
1128 /* Send the command and wait for it to complete */
1129 I915_WRITE(ch_ctl, send_ctl);
1131 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
1133 /* Clear done status and any errors */
1136 DP_AUX_CH_CTL_DONE |
1137 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1138 DP_AUX_CH_CTL_RECEIVE_ERROR);
1140 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1143 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1144 * 400us delay required for errors and timeouts
1145 * Timeout errors from the HW already meet this
1146 * requirement so skip to next iteration
1148 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1149 usleep_range(400, 500);
1152 if (status & DP_AUX_CH_CTL_DONE)
1157 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
1158 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
1164 /* Check for timeout or receive error.
1165 * Timeouts occur when the sink is not connected
1167 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1168 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
1173 /* Timeouts occur when the device isn't connected, so they're
1174 * "normal" -- don't fill the kernel log with these */
1175 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
1176 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
1181 /* Unload any bytes sent back from the other side */
1182 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1183 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
1186 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1187 * We have no idea of what happened so we return -EBUSY so
1188 * drm layer takes care for the necessary retries.
1190 if (recv_bytes == 0 || recv_bytes > 20) {
1191 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1194 * FIXME: This patch was created on top of a series that
1195 * organize the retries at drm level. There EBUSY should
1196 * also take care for 1ms wait before retrying.
1197 * That aux retries re-org is still needed and after that is
1198 * merged we remove this sleep from here.
1200 usleep_range(1000, 1500);
1205 if (recv_bytes > recv_size)
1206 recv_bytes = recv_size;
1208 for (i = 0; i < recv_bytes; i += 4)
1209 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
1210 recv + i, recv_bytes - i);
1214 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1217 edp_panel_vdd_off(intel_dp, false);
1219 pps_unlock(intel_dp);
1224 #define BARE_ADDRESS_SIZE 3
1225 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
1227 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1229 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1230 uint8_t txbuf[20], rxbuf[20];
1231 size_t txsize, rxsize;
1234 txbuf[0] = (msg->request << 4) |
1235 ((msg->address >> 16) & 0xf);
1236 txbuf[1] = (msg->address >> 8) & 0xff;
1237 txbuf[2] = msg->address & 0xff;
1238 txbuf[3] = msg->size - 1;
1240 switch (msg->request & ~DP_AUX_I2C_MOT) {
1241 case DP_AUX_NATIVE_WRITE:
1242 case DP_AUX_I2C_WRITE:
1243 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1244 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
1245 rxsize = 2; /* 0 or 1 data bytes */
1247 if (WARN_ON(txsize > 20))
1250 WARN_ON(!msg->buffer != !msg->size);
1253 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1255 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1257 msg->reply = rxbuf[0] >> 4;
1260 /* Number of bytes written in a short write. */
1261 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1263 /* Return payload size. */
1269 case DP_AUX_NATIVE_READ:
1270 case DP_AUX_I2C_READ:
1271 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
1272 rxsize = msg->size + 1;
1274 if (WARN_ON(rxsize > 20))
1277 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1279 msg->reply = rxbuf[0] >> 4;
1281 * Assume happy day, and copy the data. The caller is
1282 * expected to check msg->reply before touching it.
1284 * Return payload size.
1287 memcpy(msg->buffer, rxbuf + 1, ret);
1299 static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1302 const struct ddi_vbt_port_info *info =
1303 &dev_priv->vbt.ddi_port_info[port];
1306 if (!info->alternate_aux_channel) {
1307 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1308 port_name(port), port_name(port));
1312 switch (info->alternate_aux_channel) {
1329 MISSING_CASE(info->alternate_aux_channel);
1334 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1335 port_name(aux_port), port_name(port));
1340 static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1347 return DP_AUX_CH_CTL(port);
1350 return DP_AUX_CH_CTL(PORT_B);
1354 static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1355 enum port port, int index)
1361 return DP_AUX_CH_DATA(port, index);
1364 return DP_AUX_CH_DATA(PORT_B, index);
1368 static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1373 return DP_AUX_CH_CTL(port);
1377 return PCH_DP_AUX_CH_CTL(port);
1380 return DP_AUX_CH_CTL(PORT_A);
1384 static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1385 enum port port, int index)
1389 return DP_AUX_CH_DATA(port, index);
1393 return PCH_DP_AUX_CH_DATA(port, index);
1396 return DP_AUX_CH_DATA(PORT_A, index);
1400 static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1409 return DP_AUX_CH_CTL(port);
1412 return DP_AUX_CH_CTL(PORT_A);
1416 static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1417 enum port port, int index)
1425 return DP_AUX_CH_DATA(port, index);
1428 return DP_AUX_CH_DATA(PORT_A, index);
1432 static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1435 if (INTEL_INFO(dev_priv)->gen >= 9)
1436 return skl_aux_ctl_reg(dev_priv, port);
1437 else if (HAS_PCH_SPLIT(dev_priv))
1438 return ilk_aux_ctl_reg(dev_priv, port);
1440 return g4x_aux_ctl_reg(dev_priv, port);
1443 static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1444 enum port port, int index)
1446 if (INTEL_INFO(dev_priv)->gen >= 9)
1447 return skl_aux_data_reg(dev_priv, port, index);
1448 else if (HAS_PCH_SPLIT(dev_priv))
1449 return ilk_aux_data_reg(dev_priv, port, index);
1451 return g4x_aux_data_reg(dev_priv, port, index);
1454 static void intel_aux_reg_init(struct intel_dp *intel_dp)
1456 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1457 enum port port = intel_aux_port(dev_priv,
1458 dp_to_dig_port(intel_dp)->base.port);
1461 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1462 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1463 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1467 intel_dp_aux_fini(struct intel_dp *intel_dp)
1469 kfree(intel_dp->aux.name);
1473 intel_dp_aux_init(struct intel_dp *intel_dp)
1475 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1476 enum port port = intel_dig_port->base.port;
1478 intel_aux_reg_init(intel_dp);
1479 drm_dp_aux_init(&intel_dp->aux);
1481 /* Failure to allocate our preferred name is not critical */
1482 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
1483 intel_dp->aux.transfer = intel_dp_aux_transfer;
1486 bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
1488 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1490 return max_rate >= 540000;
1494 intel_dp_set_clock(struct intel_encoder *encoder,
1495 struct intel_crtc_state *pipe_config)
1497 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1498 const struct dp_link_dpll *divisor = NULL;
1501 if (IS_G4X(dev_priv)) {
1502 divisor = gen4_dpll;
1503 count = ARRAY_SIZE(gen4_dpll);
1504 } else if (HAS_PCH_SPLIT(dev_priv)) {
1506 count = ARRAY_SIZE(pch_dpll);
1507 } else if (IS_CHERRYVIEW(dev_priv)) {
1509 count = ARRAY_SIZE(chv_dpll);
1510 } else if (IS_VALLEYVIEW(dev_priv)) {
1512 count = ARRAY_SIZE(vlv_dpll);
1515 if (divisor && count) {
1516 for (i = 0; i < count; i++) {
1517 if (pipe_config->port_clock == divisor[i].clock) {
1518 pipe_config->dpll = divisor[i].dpll;
1519 pipe_config->clock_set = true;
1526 static void snprintf_int_array(char *str, size_t len,
1527 const int *array, int nelem)
1533 for (i = 0; i < nelem; i++) {
1534 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
1542 static void intel_dp_print_rates(struct intel_dp *intel_dp)
1544 char str[128]; /* FIXME: too big for stack? */
1546 if ((drm_debug & DRM_UT_KMS) == 0)
1549 snprintf_int_array(str, sizeof(str),
1550 intel_dp->source_rates, intel_dp->num_source_rates);
1551 DRM_DEBUG_KMS("source rates: %s\n", str);
1553 snprintf_int_array(str, sizeof(str),
1554 intel_dp->sink_rates, intel_dp->num_sink_rates);
1555 DRM_DEBUG_KMS("sink rates: %s\n", str);
1557 snprintf_int_array(str, sizeof(str),
1558 intel_dp->common_rates, intel_dp->num_common_rates);
1559 DRM_DEBUG_KMS("common rates: %s\n", str);
1563 intel_dp_max_link_rate(struct intel_dp *intel_dp)
1567 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
1568 if (WARN_ON(len <= 0))
1571 return intel_dp->common_rates[len - 1];
1574 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1576 int i = intel_dp_rate_index(intel_dp->sink_rates,
1577 intel_dp->num_sink_rates, rate);
1585 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1586 uint8_t *link_bw, uint8_t *rate_select)
1588 /* eDP 1.4 rate select method. */
1589 if (intel_dp->use_rate_select) {
1592 intel_dp_rate_select(intel_dp, port_clock);
1594 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1599 static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1600 struct intel_crtc_state *pipe_config)
1604 bpp = pipe_config->pipe_bpp;
1605 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1608 bpp = min(bpp, 3*bpc);
1610 /* For DP Compliance we override the computed bpp for the pipe */
1611 if (intel_dp->compliance.test_data.bpc != 0) {
1612 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1613 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1614 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1615 pipe_config->pipe_bpp);
1620 static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1621 struct drm_display_mode *m2)
1626 bres = (m1->hdisplay == m2->hdisplay &&
1627 m1->hsync_start == m2->hsync_start &&
1628 m1->hsync_end == m2->hsync_end &&
1629 m1->htotal == m2->htotal &&
1630 m1->vdisplay == m2->vdisplay &&
1631 m1->vsync_start == m2->vsync_start &&
1632 m1->vsync_end == m2->vsync_end &&
1633 m1->vtotal == m2->vtotal);
1638 intel_dp_compute_config(struct intel_encoder *encoder,
1639 struct intel_crtc_state *pipe_config,
1640 struct drm_connector_state *conn_state)
1642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1643 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1644 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1645 enum port port = encoder->port;
1646 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
1647 struct intel_connector *intel_connector = intel_dp->attached_connector;
1648 struct intel_digital_connector_state *intel_conn_state =
1649 to_intel_digital_connector_state(conn_state);
1650 int lane_count, clock;
1651 int min_lane_count = 1;
1652 int max_lane_count = intel_dp_max_lane_count(intel_dp);
1653 /* Conveniently, the link BW constants become indices with a shift...*/
1657 int link_avail, link_clock;
1659 uint8_t link_bw, rate_select;
1660 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1661 DP_DPCD_QUIRK_LIMITED_M_N);
1663 common_len = intel_dp_common_len_rate_limit(intel_dp,
1664 intel_dp->max_link_rate);
1666 /* No common link rates between source and sink */
1667 WARN_ON(common_len <= 0);
1669 max_clock = common_len - 1;
1671 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
1672 pipe_config->has_pch_encoder = true;
1674 pipe_config->has_drrs = false;
1675 if (IS_G4X(dev_priv) || port == PORT_A)
1676 pipe_config->has_audio = false;
1677 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1678 pipe_config->has_audio = intel_dp->has_audio;
1680 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
1682 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1683 struct drm_display_mode *panel_mode =
1684 intel_connector->panel.alt_fixed_mode;
1685 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1687 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1688 panel_mode = intel_connector->panel.fixed_mode;
1690 drm_mode_debug_printmodeline(panel_mode);
1692 intel_fixed_panel_mode(panel_mode, adjusted_mode);
1694 if (INTEL_GEN(dev_priv) >= 9) {
1696 ret = skl_update_scaler_crtc(pipe_config);
1701 if (HAS_GMCH_DISPLAY(dev_priv))
1702 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1703 conn_state->scaling_mode);
1705 intel_pch_panel_fitting(intel_crtc, pipe_config,
1706 conn_state->scaling_mode);
1709 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1710 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
1713 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
1716 /* Use values requested by Compliance Test Request */
1717 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1720 /* Validate the compliance test data since max values
1721 * might have changed due to link train fallback.
1723 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1724 intel_dp->compliance.test_lane_count)) {
1725 index = intel_dp_rate_index(intel_dp->common_rates,
1726 intel_dp->num_common_rates,
1727 intel_dp->compliance.test_link_rate);
1729 min_clock = max_clock = index;
1730 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1733 DRM_DEBUG_KMS("DP link computation with max lane count %i "
1734 "max bw %d pixel clock %iKHz\n",
1735 max_lane_count, intel_dp->common_rates[max_clock],
1736 adjusted_mode->crtc_clock);
1738 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1739 * bpc in between. */
1740 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
1741 if (intel_dp_is_edp(intel_dp)) {
1743 /* Get bpp from vbt only for panels that dont have bpp in edid */
1744 if (intel_connector->base.display_info.bpc == 0 &&
1745 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
1746 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1747 dev_priv->vbt.edp.bpp);
1748 bpp = dev_priv->vbt.edp.bpp;
1752 * Use the maximum clock and number of lanes the eDP panel
1753 * advertizes being capable of. The panels are generally
1754 * designed to support only a single clock and lane
1755 * configuration, and typically these values correspond to the
1756 * native resolution of the panel.
1758 min_lane_count = max_lane_count;
1759 min_clock = max_clock;
1762 for (; bpp >= 6*3; bpp -= 2*3) {
1763 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1766 for (clock = min_clock; clock <= max_clock; clock++) {
1767 for (lane_count = min_lane_count;
1768 lane_count <= max_lane_count;
1771 link_clock = intel_dp->common_rates[clock];
1772 link_avail = intel_dp_max_data_rate(link_clock,
1775 if (mode_rate <= link_avail) {
1785 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1788 * CEA-861-E - 5.1 Default Encoding Parameters
1789 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1791 pipe_config->limited_color_range =
1793 drm_default_rgb_quant_range(adjusted_mode) ==
1794 HDMI_QUANTIZATION_RANGE_LIMITED;
1796 pipe_config->limited_color_range =
1797 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
1800 pipe_config->lane_count = lane_count;
1802 pipe_config->pipe_bpp = bpp;
1803 pipe_config->port_clock = intel_dp->common_rates[clock];
1805 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1806 &link_bw, &rate_select);
1808 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1809 link_bw, rate_select, pipe_config->lane_count,
1810 pipe_config->port_clock, bpp);
1811 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1812 mode_rate, link_avail);
1814 intel_link_compute_m_n(bpp, lane_count,
1815 adjusted_mode->crtc_clock,
1816 pipe_config->port_clock,
1817 &pipe_config->dp_m_n,
1820 if (intel_connector->panel.downclock_mode != NULL &&
1821 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
1822 pipe_config->has_drrs = true;
1823 intel_link_compute_m_n(bpp, lane_count,
1824 intel_connector->panel.downclock_mode->clock,
1825 pipe_config->port_clock,
1826 &pipe_config->dp_m2_n2,
1831 * DPLL0 VCO may need to be adjusted to get the correct
1832 * clock for eDP. This will affect cdclk as well.
1834 if (intel_dp_is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
1837 switch (pipe_config->port_clock / 2) {
1847 to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
1850 if (!HAS_DDI(dev_priv))
1851 intel_dp_set_clock(encoder, pipe_config);
1853 intel_psr_compute_config(intel_dp, pipe_config);
1858 void intel_dp_set_link_params(struct intel_dp *intel_dp,
1859 int link_rate, uint8_t lane_count,
1862 intel_dp->link_rate = link_rate;
1863 intel_dp->lane_count = lane_count;
1864 intel_dp->link_mst = link_mst;
1867 static void intel_dp_prepare(struct intel_encoder *encoder,
1868 const struct intel_crtc_state *pipe_config)
1870 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1871 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1872 enum port port = encoder->port;
1873 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1874 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1876 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1877 pipe_config->lane_count,
1878 intel_crtc_has_type(pipe_config,
1879 INTEL_OUTPUT_DP_MST));
1882 * There are four kinds of DP registers:
1889 * IBX PCH and CPU are the same for almost everything,
1890 * except that the CPU DP PLL is configured in this
1893 * CPT PCH is quite different, having many bits moved
1894 * to the TRANS_DP_CTL register instead. That
1895 * configuration happens (oddly) in ironlake_pch_enable
1898 /* Preserve the BIOS-computed detected bit. This is
1899 * supposed to be read-only.
1901 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
1903 /* Handle DP bits in common between all three register formats */
1904 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
1905 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
1907 /* Split out the IBX/CPU vs CPT settings */
1909 if (IS_GEN7(dev_priv) && port == PORT_A) {
1910 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1911 intel_dp->DP |= DP_SYNC_HS_HIGH;
1912 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1913 intel_dp->DP |= DP_SYNC_VS_HIGH;
1914 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1916 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1917 intel_dp->DP |= DP_ENHANCED_FRAMING;
1919 intel_dp->DP |= crtc->pipe << 29;
1920 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
1923 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1925 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1926 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1927 trans_dp |= TRANS_DP_ENH_FRAMING;
1929 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1930 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
1932 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
1933 intel_dp->DP |= DP_COLOR_RANGE_16_235;
1935 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1936 intel_dp->DP |= DP_SYNC_HS_HIGH;
1937 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1938 intel_dp->DP |= DP_SYNC_VS_HIGH;
1939 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1941 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1942 intel_dp->DP |= DP_ENHANCED_FRAMING;
1944 if (IS_CHERRYVIEW(dev_priv))
1945 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
1946 else if (crtc->pipe == PIPE_B)
1947 intel_dp->DP |= DP_PIPEB_SELECT;
1951 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1952 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
1954 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1955 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
1957 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1958 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
1960 static void intel_pps_verify_state(struct intel_dp *intel_dp);
1962 static void wait_panel_status(struct intel_dp *intel_dp,
1966 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1967 i915_reg_t pp_stat_reg, pp_ctrl_reg;
1969 lockdep_assert_held(&dev_priv->pps_mutex);
1971 intel_pps_verify_state(intel_dp);
1973 pp_stat_reg = _pp_stat_reg(intel_dp);
1974 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1976 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
1978 I915_READ(pp_stat_reg),
1979 I915_READ(pp_ctrl_reg));
1981 if (intel_wait_for_register(dev_priv,
1982 pp_stat_reg, mask, value,
1984 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
1985 I915_READ(pp_stat_reg),
1986 I915_READ(pp_ctrl_reg));
1988 DRM_DEBUG_KMS("Wait complete\n");
1991 static void wait_panel_on(struct intel_dp *intel_dp)
1993 DRM_DEBUG_KMS("Wait for panel power on\n");
1994 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1997 static void wait_panel_off(struct intel_dp *intel_dp)
1999 DRM_DEBUG_KMS("Wait for panel power off time\n");
2000 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
2003 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
2005 ktime_t panel_power_on_time;
2006 s64 panel_power_off_duration;
2008 DRM_DEBUG_KMS("Wait for panel power cycle\n");
2010 /* take the difference of currrent time and panel power off time
2011 * and then make panel wait for t11_t12 if needed. */
2012 panel_power_on_time = ktime_get_boottime();
2013 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
2015 /* When we disable the VDD override bit last we have to do the manual
2017 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
2018 wait_remaining_ms_from_jiffies(jiffies,
2019 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
2021 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
2024 static void wait_backlight_on(struct intel_dp *intel_dp)
2026 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
2027 intel_dp->backlight_on_delay);
2030 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
2032 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
2033 intel_dp->backlight_off_delay);
2036 /* Read the current pp_control value, unlocking the register if it
2040 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
2042 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2045 lockdep_assert_held(&dev_priv->pps_mutex);
2047 control = I915_READ(_pp_ctrl_reg(intel_dp));
2048 if (WARN_ON(!HAS_DDI(dev_priv) &&
2049 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
2050 control &= ~PANEL_UNLOCK_MASK;
2051 control |= PANEL_UNLOCK_REGS;
2057 * Must be paired with edp_panel_vdd_off().
2058 * Must hold pps_mutex around the whole on/off sequence.
2059 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2061 static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
2063 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2064 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2066 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2067 bool need_to_disable = !intel_dp->want_panel_vdd;
2069 lockdep_assert_held(&dev_priv->pps_mutex);
2071 if (!intel_dp_is_edp(intel_dp))
2074 cancel_delayed_work(&intel_dp->panel_vdd_work);
2075 intel_dp->want_panel_vdd = true;
2077 if (edp_have_panel_vdd(intel_dp))
2078 return need_to_disable;
2080 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
2082 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2083 port_name(intel_dig_port->base.port));
2085 if (!edp_have_panel_power(intel_dp))
2086 wait_panel_power_cycle(intel_dp);
2088 pp = ironlake_get_pp_control(intel_dp);
2089 pp |= EDP_FORCE_VDD;
2091 pp_stat_reg = _pp_stat_reg(intel_dp);
2092 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2094 I915_WRITE(pp_ctrl_reg, pp);
2095 POSTING_READ(pp_ctrl_reg);
2096 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2097 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2099 * If the panel wasn't on, delay before accessing aux channel
2101 if (!edp_have_panel_power(intel_dp)) {
2102 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2103 port_name(intel_dig_port->base.port));
2104 msleep(intel_dp->panel_power_up_delay);
2107 return need_to_disable;
2111 * Must be paired with intel_edp_panel_vdd_off() or
2112 * intel_edp_panel_off().
2113 * Nested calls to these functions are not allowed since
2114 * we drop the lock. Caller must use some higher level
2115 * locking to prevent nested calls from other threads.
2117 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
2121 if (!intel_dp_is_edp(intel_dp))
2125 vdd = edp_panel_vdd_on(intel_dp);
2126 pps_unlock(intel_dp);
2128 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
2129 port_name(dp_to_dig_port(intel_dp)->base.port));
2132 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
2134 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2135 struct intel_digital_port *intel_dig_port =
2136 dp_to_dig_port(intel_dp);
2138 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2140 lockdep_assert_held(&dev_priv->pps_mutex);
2142 WARN_ON(intel_dp->want_panel_vdd);
2144 if (!edp_have_panel_vdd(intel_dp))
2147 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2148 port_name(intel_dig_port->base.port));
2150 pp = ironlake_get_pp_control(intel_dp);
2151 pp &= ~EDP_FORCE_VDD;
2153 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2154 pp_stat_reg = _pp_stat_reg(intel_dp);
2156 I915_WRITE(pp_ctrl_reg, pp);
2157 POSTING_READ(pp_ctrl_reg);
2159 /* Make sure sequencer is idle before allowing subsequent activity */
2160 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2161 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2163 if ((pp & PANEL_POWER_ON) == 0)
2164 intel_dp->panel_power_off_time = ktime_get_boottime();
2166 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2169 static void edp_panel_vdd_work(struct work_struct *__work)
2171 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2172 struct intel_dp, panel_vdd_work);
2175 if (!intel_dp->want_panel_vdd)
2176 edp_panel_vdd_off_sync(intel_dp);
2177 pps_unlock(intel_dp);
2180 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2182 unsigned long delay;
2185 * Queue the timer to fire a long time from now (relative to the power
2186 * down delay) to keep the panel power up across a sequence of
2189 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2190 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2194 * Must be paired with edp_panel_vdd_on().
2195 * Must hold pps_mutex around the whole on/off sequence.
2196 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2198 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
2200 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2202 lockdep_assert_held(&dev_priv->pps_mutex);
2204 if (!intel_dp_is_edp(intel_dp))
2207 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
2208 port_name(dp_to_dig_port(intel_dp)->base.port));
2210 intel_dp->want_panel_vdd = false;
2213 edp_panel_vdd_off_sync(intel_dp);
2215 edp_panel_vdd_schedule_off(intel_dp);
2218 static void edp_panel_on(struct intel_dp *intel_dp)
2220 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2222 i915_reg_t pp_ctrl_reg;
2224 lockdep_assert_held(&dev_priv->pps_mutex);
2226 if (!intel_dp_is_edp(intel_dp))
2229 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2230 port_name(dp_to_dig_port(intel_dp)->base.port));
2232 if (WARN(edp_have_panel_power(intel_dp),
2233 "eDP port %c panel power already on\n",
2234 port_name(dp_to_dig_port(intel_dp)->base.port)))
2237 wait_panel_power_cycle(intel_dp);
2239 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2240 pp = ironlake_get_pp_control(intel_dp);
2241 if (IS_GEN5(dev_priv)) {
2242 /* ILK workaround: disable reset around power sequence */
2243 pp &= ~PANEL_POWER_RESET;
2244 I915_WRITE(pp_ctrl_reg, pp);
2245 POSTING_READ(pp_ctrl_reg);
2248 pp |= PANEL_POWER_ON;
2249 if (!IS_GEN5(dev_priv))
2250 pp |= PANEL_POWER_RESET;
2252 I915_WRITE(pp_ctrl_reg, pp);
2253 POSTING_READ(pp_ctrl_reg);
2255 wait_panel_on(intel_dp);
2256 intel_dp->last_power_on = jiffies;
2258 if (IS_GEN5(dev_priv)) {
2259 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
2260 I915_WRITE(pp_ctrl_reg, pp);
2261 POSTING_READ(pp_ctrl_reg);
2265 void intel_edp_panel_on(struct intel_dp *intel_dp)
2267 if (!intel_dp_is_edp(intel_dp))
2271 edp_panel_on(intel_dp);
2272 pps_unlock(intel_dp);
2276 static void edp_panel_off(struct intel_dp *intel_dp)
2278 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2280 i915_reg_t pp_ctrl_reg;
2282 lockdep_assert_held(&dev_priv->pps_mutex);
2284 if (!intel_dp_is_edp(intel_dp))
2287 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2288 port_name(dp_to_dig_port(intel_dp)->base.port));
2290 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2291 port_name(dp_to_dig_port(intel_dp)->base.port));
2293 pp = ironlake_get_pp_control(intel_dp);
2294 /* We need to switch off panel power _and_ force vdd, for otherwise some
2295 * panels get very unhappy and cease to work. */
2296 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2299 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2301 intel_dp->want_panel_vdd = false;
2303 I915_WRITE(pp_ctrl_reg, pp);
2304 POSTING_READ(pp_ctrl_reg);
2306 wait_panel_off(intel_dp);
2307 intel_dp->panel_power_off_time = ktime_get_boottime();
2309 /* We got a reference when we enabled the VDD. */
2310 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2313 void intel_edp_panel_off(struct intel_dp *intel_dp)
2315 if (!intel_dp_is_edp(intel_dp))
2319 edp_panel_off(intel_dp);
2320 pps_unlock(intel_dp);
2323 /* Enable backlight in the panel power control. */
2324 static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
2326 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2328 i915_reg_t pp_ctrl_reg;
2331 * If we enable the backlight right away following a panel power
2332 * on, we may see slight flicker as the panel syncs with the eDP
2333 * link. So delay a bit to make sure the image is solid before
2334 * allowing it to appear.
2336 wait_backlight_on(intel_dp);
2340 pp = ironlake_get_pp_control(intel_dp);
2341 pp |= EDP_BLC_ENABLE;
2343 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2345 I915_WRITE(pp_ctrl_reg, pp);
2346 POSTING_READ(pp_ctrl_reg);
2348 pps_unlock(intel_dp);
2351 /* Enable backlight PWM and backlight PP control. */
2352 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2353 const struct drm_connector_state *conn_state)
2355 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2357 if (!intel_dp_is_edp(intel_dp))
2360 DRM_DEBUG_KMS("\n");
2362 intel_panel_enable_backlight(crtc_state, conn_state);
2363 _intel_edp_backlight_on(intel_dp);
2366 /* Disable backlight in the panel power control. */
2367 static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
2369 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2371 i915_reg_t pp_ctrl_reg;
2373 if (!intel_dp_is_edp(intel_dp))
2378 pp = ironlake_get_pp_control(intel_dp);
2379 pp &= ~EDP_BLC_ENABLE;
2381 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2383 I915_WRITE(pp_ctrl_reg, pp);
2384 POSTING_READ(pp_ctrl_reg);
2386 pps_unlock(intel_dp);
2388 intel_dp->last_backlight_off = jiffies;
2389 edp_wait_backlight_off(intel_dp);
2392 /* Disable backlight PP control and backlight PWM. */
2393 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
2395 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2397 if (!intel_dp_is_edp(intel_dp))
2400 DRM_DEBUG_KMS("\n");
2402 _intel_edp_backlight_off(intel_dp);
2403 intel_panel_disable_backlight(old_conn_state);
2407 * Hook for controlling the panel power control backlight through the bl_power
2408 * sysfs attribute. Take care to handle multiple calls.
2410 static void intel_edp_backlight_power(struct intel_connector *connector,
2413 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
2417 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
2418 pps_unlock(intel_dp);
2420 if (is_enabled == enable)
2423 DRM_DEBUG_KMS("panel power control backlight %s\n",
2424 enable ? "enable" : "disable");
2427 _intel_edp_backlight_on(intel_dp);
2429 _intel_edp_backlight_off(intel_dp);
2432 static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2434 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2435 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2436 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2438 I915_STATE_WARN(cur_state != state,
2439 "DP port %c state assertion failure (expected %s, current %s)\n",
2440 port_name(dig_port->base.port),
2441 onoff(state), onoff(cur_state));
2443 #define assert_dp_port_disabled(d) assert_dp_port((d), false)
2445 static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2447 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2449 I915_STATE_WARN(cur_state != state,
2450 "eDP PLL state assertion failure (expected %s, current %s)\n",
2451 onoff(state), onoff(cur_state));
2453 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2454 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2456 static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2457 const struct intel_crtc_state *pipe_config)
2459 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2462 assert_pipe_disabled(dev_priv, crtc->pipe);
2463 assert_dp_port_disabled(intel_dp);
2464 assert_edp_pll_disabled(dev_priv);
2466 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2467 pipe_config->port_clock);
2469 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2471 if (pipe_config->port_clock == 162000)
2472 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2474 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2476 I915_WRITE(DP_A, intel_dp->DP);
2481 * [DevILK] Work around required when enabling DP PLL
2482 * while a pipe is enabled going to FDI:
2483 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2484 * 2. Program DP PLL enable
2486 if (IS_GEN5(dev_priv))
2487 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
2489 intel_dp->DP |= DP_PLL_ENABLE;
2491 I915_WRITE(DP_A, intel_dp->DP);
2496 static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2497 const struct intel_crtc_state *old_crtc_state)
2499 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
2500 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2502 assert_pipe_disabled(dev_priv, crtc->pipe);
2503 assert_dp_port_disabled(intel_dp);
2504 assert_edp_pll_enabled(dev_priv);
2506 DRM_DEBUG_KMS("disabling eDP PLL\n");
2508 intel_dp->DP &= ~DP_PLL_ENABLE;
2510 I915_WRITE(DP_A, intel_dp->DP);
2515 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2518 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2519 * be capable of signalling downstream hpd with a long pulse.
2520 * Whether or not that means D3 is safe to use is not clear,
2521 * but let's assume so until proven otherwise.
2523 * FIXME should really check all downstream ports...
2525 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2526 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2527 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2530 /* If the sink supports it, try to set the power state appropriately */
2531 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
2535 /* Should have a valid DPCD by this point */
2536 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2539 if (mode != DRM_MODE_DPMS_ON) {
2540 if (downstream_hpd_needs_d0(intel_dp))
2543 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2546 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2549 * When turning on, we need to retry for 1ms to give the sink
2552 for (i = 0; i < 3; i++) {
2553 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2560 if (ret == 1 && lspcon->active)
2561 lspcon_wait_pcon_mode(lspcon);
2565 DRM_DEBUG_KMS("failed to %s sink power state\n",
2566 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
2569 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2572 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2573 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2574 enum port port = encoder->port;
2578 if (!intel_display_power_get_if_enabled(dev_priv,
2579 encoder->power_domain))
2584 tmp = I915_READ(intel_dp->output_reg);
2586 if (!(tmp & DP_PORT_EN))
2589 if (IS_GEN7(dev_priv) && port == PORT_A) {
2590 *pipe = PORT_TO_PIPE_CPT(tmp);
2591 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2594 for_each_pipe(dev_priv, p) {
2595 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2596 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2604 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
2605 i915_mmio_reg_offset(intel_dp->output_reg));
2606 } else if (IS_CHERRYVIEW(dev_priv)) {
2607 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2609 *pipe = PORT_TO_PIPE(tmp);
2615 intel_display_power_put(dev_priv, encoder->power_domain);
2620 static void intel_dp_get_config(struct intel_encoder *encoder,
2621 struct intel_crtc_state *pipe_config)
2623 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2624 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2626 enum port port = encoder->port;
2627 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2629 if (encoder->type == INTEL_OUTPUT_EDP)
2630 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2632 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2634 tmp = I915_READ(intel_dp->output_reg);
2636 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
2638 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2639 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2641 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2642 flags |= DRM_MODE_FLAG_PHSYNC;
2644 flags |= DRM_MODE_FLAG_NHSYNC;
2646 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2647 flags |= DRM_MODE_FLAG_PVSYNC;
2649 flags |= DRM_MODE_FLAG_NVSYNC;
2651 if (tmp & DP_SYNC_HS_HIGH)
2652 flags |= DRM_MODE_FLAG_PHSYNC;
2654 flags |= DRM_MODE_FLAG_NHSYNC;
2656 if (tmp & DP_SYNC_VS_HIGH)
2657 flags |= DRM_MODE_FLAG_PVSYNC;
2659 flags |= DRM_MODE_FLAG_NVSYNC;
2662 pipe_config->base.adjusted_mode.flags |= flags;
2664 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
2665 pipe_config->limited_color_range = true;
2667 pipe_config->lane_count =
2668 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2670 intel_dp_get_m_n(crtc, pipe_config);
2672 if (port == PORT_A) {
2673 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
2674 pipe_config->port_clock = 162000;
2676 pipe_config->port_clock = 270000;
2679 pipe_config->base.adjusted_mode.crtc_clock =
2680 intel_dotclock_calculate(pipe_config->port_clock,
2681 &pipe_config->dp_m_n);
2683 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2684 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
2686 * This is a big fat ugly hack.
2688 * Some machines in UEFI boot mode provide us a VBT that has 18
2689 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2690 * unknown we fail to light up. Yet the same BIOS boots up with
2691 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2692 * max, not what it tells us to use.
2694 * Note: This will still be broken if the eDP panel is not lit
2695 * up by the BIOS, and thus we can't get the mode at module
2698 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2699 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2700 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
2704 static void intel_disable_dp(struct intel_encoder *encoder,
2705 const struct intel_crtc_state *old_crtc_state,
2706 const struct drm_connector_state *old_conn_state)
2708 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2710 if (old_crtc_state->has_audio)
2711 intel_audio_codec_disable(encoder,
2712 old_crtc_state, old_conn_state);
2714 /* Make sure the panel is off before trying to change the mode. But also
2715 * ensure that we have vdd while we switch off the panel. */
2716 intel_edp_panel_vdd_on(intel_dp);
2717 intel_edp_backlight_off(old_conn_state);
2718 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2719 intel_edp_panel_off(intel_dp);
2722 static void g4x_disable_dp(struct intel_encoder *encoder,
2723 const struct intel_crtc_state *old_crtc_state,
2724 const struct drm_connector_state *old_conn_state)
2726 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2728 /* disable the port before the pipe on g4x */
2729 intel_dp_link_down(encoder, old_crtc_state);
2732 static void ilk_disable_dp(struct intel_encoder *encoder,
2733 const struct intel_crtc_state *old_crtc_state,
2734 const struct drm_connector_state *old_conn_state)
2736 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2739 static void vlv_disable_dp(struct intel_encoder *encoder,
2740 const struct intel_crtc_state *old_crtc_state,
2741 const struct drm_connector_state *old_conn_state)
2743 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2745 intel_psr_disable(intel_dp, old_crtc_state);
2747 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2750 static void ilk_post_disable_dp(struct intel_encoder *encoder,
2751 const struct intel_crtc_state *old_crtc_state,
2752 const struct drm_connector_state *old_conn_state)
2754 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2755 enum port port = encoder->port;
2757 intel_dp_link_down(encoder, old_crtc_state);
2759 /* Only ilk+ has port A */
2761 ironlake_edp_pll_off(intel_dp, old_crtc_state);
2764 static void vlv_post_disable_dp(struct intel_encoder *encoder,
2765 const struct intel_crtc_state *old_crtc_state,
2766 const struct drm_connector_state *old_conn_state)
2768 intel_dp_link_down(encoder, old_crtc_state);
2771 static void chv_post_disable_dp(struct intel_encoder *encoder,
2772 const struct intel_crtc_state *old_crtc_state,
2773 const struct drm_connector_state *old_conn_state)
2775 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2777 intel_dp_link_down(encoder, old_crtc_state);
2779 mutex_lock(&dev_priv->sb_lock);
2781 /* Assert data lane reset */
2782 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
2784 mutex_unlock(&dev_priv->sb_lock);
2788 _intel_dp_set_link_train(struct intel_dp *intel_dp,
2790 uint8_t dp_train_pat)
2792 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2793 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2794 enum port port = intel_dig_port->base.port;
2796 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2797 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2798 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2800 if (HAS_DDI(dev_priv)) {
2801 uint32_t temp = I915_READ(DP_TP_CTL(port));
2803 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2804 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2806 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2808 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2809 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2810 case DP_TRAINING_PATTERN_DISABLE:
2811 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2814 case DP_TRAINING_PATTERN_1:
2815 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2817 case DP_TRAINING_PATTERN_2:
2818 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2820 case DP_TRAINING_PATTERN_3:
2821 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2824 I915_WRITE(DP_TP_CTL(port), temp);
2826 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
2827 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
2828 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2830 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2831 case DP_TRAINING_PATTERN_DISABLE:
2832 *DP |= DP_LINK_TRAIN_OFF_CPT;
2834 case DP_TRAINING_PATTERN_1:
2835 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2837 case DP_TRAINING_PATTERN_2:
2838 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2840 case DP_TRAINING_PATTERN_3:
2841 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2842 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2847 if (IS_CHERRYVIEW(dev_priv))
2848 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2850 *DP &= ~DP_LINK_TRAIN_MASK;
2852 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2853 case DP_TRAINING_PATTERN_DISABLE:
2854 *DP |= DP_LINK_TRAIN_OFF;
2856 case DP_TRAINING_PATTERN_1:
2857 *DP |= DP_LINK_TRAIN_PAT_1;
2859 case DP_TRAINING_PATTERN_2:
2860 *DP |= DP_LINK_TRAIN_PAT_2;
2862 case DP_TRAINING_PATTERN_3:
2863 if (IS_CHERRYVIEW(dev_priv)) {
2864 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2866 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2867 *DP |= DP_LINK_TRAIN_PAT_2;
2874 static void intel_dp_enable_port(struct intel_dp *intel_dp,
2875 const struct intel_crtc_state *old_crtc_state)
2877 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2879 /* enable with pattern 1 (as per spec) */
2881 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
2884 * Magic for VLV/CHV. We _must_ first set up the register
2885 * without actually enabling the port, and then do another
2886 * write to enable the port. Otherwise link training will
2887 * fail when the power sequencer is freshly used for this port.
2889 intel_dp->DP |= DP_PORT_EN;
2890 if (old_crtc_state->has_audio)
2891 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
2893 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2894 POSTING_READ(intel_dp->output_reg);
2897 static void intel_enable_dp(struct intel_encoder *encoder,
2898 const struct intel_crtc_state *pipe_config,
2899 const struct drm_connector_state *conn_state)
2901 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2902 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2903 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2904 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
2905 enum pipe pipe = crtc->pipe;
2907 if (WARN_ON(dp_reg & DP_PORT_EN))
2912 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2913 vlv_init_panel_power_sequencer(encoder, pipe_config);
2915 intel_dp_enable_port(intel_dp, pipe_config);
2917 edp_panel_vdd_on(intel_dp);
2918 edp_panel_on(intel_dp);
2919 edp_panel_vdd_off(intel_dp, true);
2921 pps_unlock(intel_dp);
2923 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
2924 unsigned int lane_mask = 0x0;
2926 if (IS_CHERRYVIEW(dev_priv))
2927 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
2929 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2933 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2934 intel_dp_start_link_train(intel_dp);
2935 intel_dp_stop_link_train(intel_dp);
2937 if (pipe_config->has_audio) {
2938 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
2940 intel_audio_codec_enable(encoder, pipe_config, conn_state);
2944 static void g4x_enable_dp(struct intel_encoder *encoder,
2945 const struct intel_crtc_state *pipe_config,
2946 const struct drm_connector_state *conn_state)
2948 intel_enable_dp(encoder, pipe_config, conn_state);
2949 intel_edp_backlight_on(pipe_config, conn_state);
2952 static void vlv_enable_dp(struct intel_encoder *encoder,
2953 const struct intel_crtc_state *pipe_config,
2954 const struct drm_connector_state *conn_state)
2956 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2958 intel_edp_backlight_on(pipe_config, conn_state);
2959 intel_psr_enable(intel_dp, pipe_config);
2962 static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2963 const struct intel_crtc_state *pipe_config,
2964 const struct drm_connector_state *conn_state)
2966 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2967 enum port port = encoder->port;
2969 intel_dp_prepare(encoder, pipe_config);
2971 /* Only ilk+ has port A */
2973 ironlake_edp_pll_on(intel_dp, pipe_config);
2976 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2978 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2979 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
2980 enum pipe pipe = intel_dp->pps_pipe;
2981 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
2983 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2985 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2988 edp_panel_vdd_off_sync(intel_dp);
2991 * VLV seems to get confused when multiple power seqeuencers
2992 * have the same port selected (even if only one has power/vdd
2993 * enabled). The failure manifests as vlv_wait_port_ready() failing
2994 * CHV on the other hand doesn't seem to mind having the same port
2995 * selected in multiple power seqeuencers, but let's clear the
2996 * port select always when logically disconnecting a power sequencer
2999 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
3000 pipe_name(pipe), port_name(intel_dig_port->base.port));
3001 I915_WRITE(pp_on_reg, 0);
3002 POSTING_READ(pp_on_reg);
3004 intel_dp->pps_pipe = INVALID_PIPE;
3007 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
3010 struct intel_encoder *encoder;
3012 lockdep_assert_held(&dev_priv->pps_mutex);
3014 for_each_intel_encoder(&dev_priv->drm, encoder) {
3015 struct intel_dp *intel_dp;
3018 if (encoder->type != INTEL_OUTPUT_DP &&
3019 encoder->type != INTEL_OUTPUT_EDP)
3022 intel_dp = enc_to_intel_dp(&encoder->base);
3023 port = dp_to_dig_port(intel_dp)->base.port;
3025 WARN(intel_dp->active_pipe == pipe,
3026 "stealing pipe %c power sequencer from active (e)DP port %c\n",
3027 pipe_name(pipe), port_name(port));
3029 if (intel_dp->pps_pipe != pipe)
3032 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
3033 pipe_name(pipe), port_name(port));
3035 /* make sure vdd is off before we steal it */
3036 vlv_detach_power_sequencer(intel_dp);
3040 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
3041 const struct intel_crtc_state *crtc_state)
3043 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3044 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3045 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3047 lockdep_assert_held(&dev_priv->pps_mutex);
3049 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
3051 if (intel_dp->pps_pipe != INVALID_PIPE &&
3052 intel_dp->pps_pipe != crtc->pipe) {
3054 * If another power sequencer was being used on this
3055 * port previously make sure to turn off vdd there while
3056 * we still have control of it.
3058 vlv_detach_power_sequencer(intel_dp);
3062 * We may be stealing the power
3063 * sequencer from another port.
3065 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
3067 intel_dp->active_pipe = crtc->pipe;
3069 if (!intel_dp_is_edp(intel_dp))
3072 /* now it's all ours */
3073 intel_dp->pps_pipe = crtc->pipe;
3075 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3076 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
3078 /* init power sequencer on this pipe and port */
3079 intel_dp_init_panel_power_sequencer(intel_dp);
3080 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
3083 static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3084 const struct intel_crtc_state *pipe_config,
3085 const struct drm_connector_state *conn_state)
3087 vlv_phy_pre_encoder_enable(encoder, pipe_config);
3089 intel_enable_dp(encoder, pipe_config, conn_state);
3092 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3093 const struct intel_crtc_state *pipe_config,
3094 const struct drm_connector_state *conn_state)
3096 intel_dp_prepare(encoder, pipe_config);
3098 vlv_phy_pre_pll_enable(encoder, pipe_config);
3101 static void chv_pre_enable_dp(struct intel_encoder *encoder,
3102 const struct intel_crtc_state *pipe_config,
3103 const struct drm_connector_state *conn_state)
3105 chv_phy_pre_encoder_enable(encoder, pipe_config);
3107 intel_enable_dp(encoder, pipe_config, conn_state);
3109 /* Second common lane will stay alive on its own now */
3110 chv_phy_release_cl2_override(encoder);
3113 static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3114 const struct intel_crtc_state *pipe_config,
3115 const struct drm_connector_state *conn_state)
3117 intel_dp_prepare(encoder, pipe_config);
3119 chv_phy_pre_pll_enable(encoder, pipe_config);
3122 static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3123 const struct intel_crtc_state *old_crtc_state,
3124 const struct drm_connector_state *old_conn_state)
3126 chv_phy_post_pll_disable(encoder, old_crtc_state);
3130 * Fetch AUX CH registers 0x202 - 0x207 which contain
3131 * link status information
3134 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
3136 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3137 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3140 static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3142 uint8_t psr_caps = 0;
3144 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3146 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3149 static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3153 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3156 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3159 static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
3161 uint8_t alpm_caps = 0;
3163 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3166 return alpm_caps & DP_ALPM_CAP;
3169 /* These are source-specific values. */
3171 intel_dp_voltage_max(struct intel_dp *intel_dp)
3173 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3174 enum port port = dp_to_dig_port(intel_dp)->base.port;
3176 if (INTEL_GEN(dev_priv) >= 9) {
3177 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3178 return intel_ddi_dp_voltage_max(encoder);
3179 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3180 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3181 else if (IS_GEN7(dev_priv) && port == PORT_A)
3182 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3183 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3184 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3186 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3190 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3192 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3193 enum port port = dp_to_dig_port(intel_dp)->base.port;
3195 if (INTEL_GEN(dev_priv) >= 9) {
3196 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3198 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3199 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3200 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3201 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3202 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3203 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3204 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3206 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3208 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3209 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3210 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3211 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3212 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3213 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3214 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3215 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3216 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3218 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3220 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3221 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3222 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3223 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3224 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3225 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3226 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3227 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3228 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3230 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3232 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3233 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3234 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3235 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3236 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3237 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3238 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3240 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3243 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3244 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3245 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3247 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3248 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3249 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3250 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3252 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3257 static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
3259 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3260 unsigned long demph_reg_value, preemph_reg_value,
3261 uniqtranscale_reg_value;
3262 uint8_t train_set = intel_dp->train_set[0];
3264 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3265 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3266 preemph_reg_value = 0x0004000;
3267 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3268 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3269 demph_reg_value = 0x2B405555;
3270 uniqtranscale_reg_value = 0x552AB83A;
3272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3273 demph_reg_value = 0x2B404040;
3274 uniqtranscale_reg_value = 0x5548B83A;
3276 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3277 demph_reg_value = 0x2B245555;
3278 uniqtranscale_reg_value = 0x5560B83A;
3280 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3281 demph_reg_value = 0x2B405555;
3282 uniqtranscale_reg_value = 0x5598DA3A;
3288 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3289 preemph_reg_value = 0x0002000;
3290 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3291 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3292 demph_reg_value = 0x2B404040;
3293 uniqtranscale_reg_value = 0x5552B83A;
3295 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3296 demph_reg_value = 0x2B404848;
3297 uniqtranscale_reg_value = 0x5580B83A;
3299 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3300 demph_reg_value = 0x2B404040;
3301 uniqtranscale_reg_value = 0x55ADDA3A;
3307 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3308 preemph_reg_value = 0x0000000;
3309 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3310 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3311 demph_reg_value = 0x2B305555;
3312 uniqtranscale_reg_value = 0x5570B83A;
3314 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3315 demph_reg_value = 0x2B2B4040;
3316 uniqtranscale_reg_value = 0x55ADDA3A;
3322 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3323 preemph_reg_value = 0x0006000;
3324 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3325 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3326 demph_reg_value = 0x1B405555;
3327 uniqtranscale_reg_value = 0x55ADDA3A;
3337 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3338 uniqtranscale_reg_value, 0);
3343 static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
3345 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3346 u32 deemph_reg_value, margin_reg_value;
3347 bool uniq_trans_scale = false;
3348 uint8_t train_set = intel_dp->train_set[0];
3350 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3351 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3352 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3353 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3354 deemph_reg_value = 128;
3355 margin_reg_value = 52;
3357 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3358 deemph_reg_value = 128;
3359 margin_reg_value = 77;
3361 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3362 deemph_reg_value = 128;
3363 margin_reg_value = 102;
3365 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3366 deemph_reg_value = 128;
3367 margin_reg_value = 154;
3368 uniq_trans_scale = true;
3374 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3375 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3376 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3377 deemph_reg_value = 85;
3378 margin_reg_value = 78;
3380 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3381 deemph_reg_value = 85;
3382 margin_reg_value = 116;
3384 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3385 deemph_reg_value = 85;
3386 margin_reg_value = 154;
3392 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3393 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3394 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3395 deemph_reg_value = 64;
3396 margin_reg_value = 104;
3398 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3399 deemph_reg_value = 64;
3400 margin_reg_value = 154;
3406 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3407 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3408 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3409 deemph_reg_value = 43;
3410 margin_reg_value = 154;
3420 chv_set_phy_signal_level(encoder, deemph_reg_value,
3421 margin_reg_value, uniq_trans_scale);
3427 gen4_signal_levels(uint8_t train_set)
3429 uint32_t signal_levels = 0;
3431 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3432 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3434 signal_levels |= DP_VOLTAGE_0_4;
3436 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3437 signal_levels |= DP_VOLTAGE_0_6;
3439 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3440 signal_levels |= DP_VOLTAGE_0_8;
3442 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3443 signal_levels |= DP_VOLTAGE_1_2;
3446 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3447 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3449 signal_levels |= DP_PRE_EMPHASIS_0;
3451 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3452 signal_levels |= DP_PRE_EMPHASIS_3_5;
3454 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3455 signal_levels |= DP_PRE_EMPHASIS_6;
3457 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3458 signal_levels |= DP_PRE_EMPHASIS_9_5;
3461 return signal_levels;
3464 /* Gen6's DP voltage swing and pre-emphasis control */
3466 gen6_edp_signal_levels(uint8_t train_set)
3468 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3469 DP_TRAIN_PRE_EMPHASIS_MASK);
3470 switch (signal_levels) {
3471 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3472 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3473 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3474 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3475 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
3476 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3477 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3478 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
3479 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3480 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3481 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
3482 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3483 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3484 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
3486 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3487 "0x%x\n", signal_levels);
3488 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3492 /* Gen7's DP voltage swing and pre-emphasis control */
3494 gen7_edp_signal_levels(uint8_t train_set)
3496 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3497 DP_TRAIN_PRE_EMPHASIS_MASK);
3498 switch (signal_levels) {
3499 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3500 return EDP_LINK_TRAIN_400MV_0DB_IVB;
3501 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3502 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
3503 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3504 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3506 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3507 return EDP_LINK_TRAIN_600MV_0DB_IVB;
3508 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3509 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3511 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3512 return EDP_LINK_TRAIN_800MV_0DB_IVB;
3513 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3514 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3517 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3518 "0x%x\n", signal_levels);
3519 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3524 intel_dp_set_signal_levels(struct intel_dp *intel_dp)
3526 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3527 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3528 enum port port = intel_dig_port->base.port;
3529 uint32_t signal_levels, mask = 0;
3530 uint8_t train_set = intel_dp->train_set[0];
3532 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3533 signal_levels = bxt_signal_levels(intel_dp);
3534 } else if (HAS_DDI(dev_priv)) {
3535 signal_levels = ddi_signal_levels(intel_dp);
3536 mask = DDI_BUF_EMP_MASK;
3537 } else if (IS_CHERRYVIEW(dev_priv)) {
3538 signal_levels = chv_signal_levels(intel_dp);
3539 } else if (IS_VALLEYVIEW(dev_priv)) {
3540 signal_levels = vlv_signal_levels(intel_dp);
3541 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3542 signal_levels = gen7_edp_signal_levels(train_set);
3543 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3544 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
3545 signal_levels = gen6_edp_signal_levels(train_set);
3546 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3548 signal_levels = gen4_signal_levels(train_set);
3549 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3553 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3555 DRM_DEBUG_KMS("Using vswing level %d\n",
3556 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3557 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3558 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3559 DP_TRAIN_PRE_EMPHASIS_SHIFT);
3561 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
3563 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3564 POSTING_READ(intel_dp->output_reg);
3568 intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3569 uint8_t dp_train_pat)
3571 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3572 struct drm_i915_private *dev_priv =
3573 to_i915(intel_dig_port->base.base.dev);
3575 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
3577 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3578 POSTING_READ(intel_dp->output_reg);
3581 void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
3583 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3584 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3585 enum port port = intel_dig_port->base.port;
3588 if (!HAS_DDI(dev_priv))
3591 val = I915_READ(DP_TP_CTL(port));
3592 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3593 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3594 I915_WRITE(DP_TP_CTL(port), val);
3597 * On PORT_A we can have only eDP in SST mode. There the only reason
3598 * we need to set idle transmission mode is to work around a HW issue
3599 * where we enable the pipe while not in idle link-training mode.
3600 * In this case there is requirement to wait for a minimum number of
3601 * idle patterns to be sent.
3606 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3607 DP_TP_STATUS_IDLE_DONE,
3608 DP_TP_STATUS_IDLE_DONE,
3610 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3614 intel_dp_link_down(struct intel_encoder *encoder,
3615 const struct intel_crtc_state *old_crtc_state)
3617 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3618 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3619 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3620 enum port port = encoder->port;
3621 uint32_t DP = intel_dp->DP;
3623 if (WARN_ON(HAS_DDI(dev_priv)))
3626 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3629 DRM_DEBUG_KMS("\n");
3631 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
3632 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3633 DP &= ~DP_LINK_TRAIN_MASK_CPT;
3634 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
3636 if (IS_CHERRYVIEW(dev_priv))
3637 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3639 DP &= ~DP_LINK_TRAIN_MASK;
3640 DP |= DP_LINK_TRAIN_PAT_IDLE;
3642 I915_WRITE(intel_dp->output_reg, DP);
3643 POSTING_READ(intel_dp->output_reg);
3645 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3646 I915_WRITE(intel_dp->output_reg, DP);
3647 POSTING_READ(intel_dp->output_reg);
3650 * HW workaround for IBX, we need to move the port
3651 * to transcoder A after disabling it to allow the
3652 * matching HDMI port to be enabled on transcoder A.
3654 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
3656 * We get CPU/PCH FIFO underruns on the other pipe when
3657 * doing the workaround. Sweep them under the rug.
3659 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3660 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3662 /* always enable with pattern 1 (as per spec) */
3663 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3664 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3665 I915_WRITE(intel_dp->output_reg, DP);
3666 POSTING_READ(intel_dp->output_reg);
3669 I915_WRITE(intel_dp->output_reg, DP);
3670 POSTING_READ(intel_dp->output_reg);
3672 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
3673 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3674 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3677 msleep(intel_dp->panel_power_down_delay);
3681 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3683 intel_dp->active_pipe = INVALID_PIPE;
3684 pps_unlock(intel_dp);
3689 intel_dp_read_dpcd(struct intel_dp *intel_dp)
3691 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3692 sizeof(intel_dp->dpcd)) < 0)
3693 return false; /* aux transfer failed */
3695 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
3697 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3701 intel_edp_init_dpcd(struct intel_dp *intel_dp)
3703 struct drm_i915_private *dev_priv =
3704 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3706 /* this function is meant to be called only once */
3707 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3709 if (!intel_dp_read_dpcd(intel_dp))
3712 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3713 drm_dp_is_branch(intel_dp->dpcd));
3715 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3716 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3717 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3719 /* Check if the panel supports PSR */
3720 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3722 sizeof(intel_dp->psr_dpcd));
3723 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3724 dev_priv->psr.sink_support = true;
3725 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3728 if (INTEL_GEN(dev_priv) >= 9 &&
3729 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3730 uint8_t frame_sync_cap;
3732 dev_priv->psr.sink_support = true;
3733 if (drm_dp_dpcd_readb(&intel_dp->aux,
3734 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3735 &frame_sync_cap) != 1)
3737 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3738 /* PSR2 needs frame sync as well */
3739 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3740 DRM_DEBUG_KMS("PSR2 %s on sink",
3741 dev_priv->psr.psr2_support ? "supported" : "not supported");
3743 if (dev_priv->psr.psr2_support) {
3744 dev_priv->psr.y_cord_support =
3745 intel_dp_get_y_cord_status(intel_dp);
3746 dev_priv->psr.colorimetry_support =
3747 intel_dp_get_colorimetry_status(intel_dp);
3748 dev_priv->psr.alpm =
3749 intel_dp_get_alpm_status(intel_dp);
3755 * Read the eDP display control registers.
3757 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3758 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3759 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3760 * method). The display control registers should read zero if they're
3761 * not supported anyway.
3763 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
3764 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3765 sizeof(intel_dp->edp_dpcd))
3766 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3767 intel_dp->edp_dpcd);
3769 /* Read the eDP 1.4+ supported link rates. */
3770 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
3771 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3774 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3775 sink_rates, sizeof(sink_rates));
3777 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3778 int val = le16_to_cpu(sink_rates[i]);
3783 /* Value read multiplied by 200kHz gives the per-lane
3784 * link rate in kHz. The source rates are, however,
3785 * stored in terms of LS_Clk kHz. The full conversion
3786 * back to symbols is
3787 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3789 intel_dp->sink_rates[i] = (val * 200) / 10;
3791 intel_dp->num_sink_rates = i;
3795 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3796 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3798 if (intel_dp->num_sink_rates)
3799 intel_dp->use_rate_select = true;
3801 intel_dp_set_sink_rates(intel_dp);
3803 intel_dp_set_common_rates(intel_dp);
3810 intel_dp_get_dpcd(struct intel_dp *intel_dp)
3814 if (!intel_dp_read_dpcd(intel_dp))
3817 /* Don't clobber cached eDP rates. */
3818 if (!intel_dp_is_edp(intel_dp)) {
3819 intel_dp_set_sink_rates(intel_dp);
3820 intel_dp_set_common_rates(intel_dp);
3823 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
3827 * Sink count can change between short pulse hpd hence
3828 * a member variable in intel_dp will track any changes
3829 * between short pulse interrupts.
3831 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
3834 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3835 * a dongle is present but no display. Unless we require to know
3836 * if a dongle is present or not, we don't need to update
3837 * downstream port information. So, an early return here saves
3838 * time from performing other operations which are not required.
3840 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
3843 if (!drm_dp_is_branch(intel_dp->dpcd))
3844 return true; /* native DP sink */
3846 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3847 return true; /* no per-port downstream info */
3849 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3850 intel_dp->downstream_ports,
3851 DP_MAX_DOWNSTREAM_PORTS) < 0)
3852 return false; /* downstream port status fetch failed */
3858 intel_dp_can_mst(struct intel_dp *intel_dp)
3862 if (!i915_modparams.enable_dp_mst)
3865 if (!intel_dp->can_mst)
3868 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3871 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
3874 return mstm_cap & DP_MST_CAP;
3878 intel_dp_configure_mst(struct intel_dp *intel_dp)
3880 if (!i915_modparams.enable_dp_mst)
3883 if (!intel_dp->can_mst)
3886 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3888 if (intel_dp->is_mst)
3889 DRM_DEBUG_KMS("Sink is MST capable\n");
3891 DRM_DEBUG_KMS("Sink is not MST capable\n");
3893 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3897 static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp,
3898 struct intel_crtc_state *crtc_state, bool disable_wa)
3900 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3901 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3902 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3908 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
3909 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3914 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3915 buf & ~DP_TEST_SINK_START) < 0) {
3916 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3922 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3924 if (drm_dp_dpcd_readb(&intel_dp->aux,
3925 DP_TEST_SINK_MISC, &buf) < 0) {
3929 count = buf & DP_TEST_COUNT_MASK;
3930 } while (--attempts && count);
3932 if (attempts == 0) {
3933 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
3939 hsw_enable_ips(crtc_state);
3943 static int intel_dp_sink_crc_start(struct intel_dp *intel_dp,
3944 struct intel_crtc_state *crtc_state)
3946 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3947 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3948 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3952 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3955 if (!(buf & DP_TEST_CRC_SUPPORTED))
3958 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3961 if (buf & DP_TEST_SINK_START) {
3962 ret = intel_dp_sink_crc_stop(intel_dp, crtc_state, false);
3967 hsw_disable_ips(crtc_state);
3969 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3970 buf | DP_TEST_SINK_START) < 0) {
3971 hsw_enable_ips(crtc_state);
3975 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3979 int intel_dp_sink_crc(struct intel_dp *intel_dp, struct intel_crtc_state *crtc_state, u8 *crc)
3981 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3982 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3983 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3988 ret = intel_dp_sink_crc_start(intel_dp, crtc_state);
3993 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3995 if (drm_dp_dpcd_readb(&intel_dp->aux,
3996 DP_TEST_SINK_MISC, &buf) < 0) {
4000 count = buf & DP_TEST_COUNT_MASK;
4002 } while (--attempts && count == 0);
4004 if (attempts == 0) {
4005 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
4010 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
4016 intel_dp_sink_crc_stop(intel_dp, crtc_state, true);
4021 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4023 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
4024 sink_irq_vector) == 1;
4028 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
4030 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
4031 sink_irq_vector, DP_DPRX_ESI_LEN) ==
4035 static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
4039 uint8_t test_lane_count, test_link_bw;
4043 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
4044 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
4048 DRM_DEBUG_KMS("Lane count read failed\n");
4051 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
4053 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4056 DRM_DEBUG_KMS("Link Rate read failed\n");
4059 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
4061 /* Validate the requested link rate and lane count */
4062 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4066 intel_dp->compliance.test_lane_count = test_lane_count;
4067 intel_dp->compliance.test_link_rate = test_link_rate;
4072 static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4074 uint8_t test_pattern;
4076 __be16 h_width, v_height;
4079 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4080 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4083 DRM_DEBUG_KMS("Test pattern read failed\n");
4086 if (test_pattern != DP_COLOR_RAMP)
4089 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4092 DRM_DEBUG_KMS("H Width read failed\n");
4096 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4099 DRM_DEBUG_KMS("V Height read failed\n");
4103 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4106 DRM_DEBUG_KMS("TEST MISC read failed\n");
4109 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4111 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4113 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4114 case DP_TEST_BIT_DEPTH_6:
4115 intel_dp->compliance.test_data.bpc = 6;
4117 case DP_TEST_BIT_DEPTH_8:
4118 intel_dp->compliance.test_data.bpc = 8;
4124 intel_dp->compliance.test_data.video_pattern = test_pattern;
4125 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4126 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4127 /* Set test active flag here so userspace doesn't interrupt things */
4128 intel_dp->compliance.test_active = 1;
4133 static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4135 uint8_t test_result = DP_TEST_ACK;
4136 struct intel_connector *intel_connector = intel_dp->attached_connector;
4137 struct drm_connector *connector = &intel_connector->base;
4139 if (intel_connector->detect_edid == NULL ||
4140 connector->edid_corrupt ||
4141 intel_dp->aux.i2c_defer_count > 6) {
4142 /* Check EDID read for NACKs, DEFERs and corruption
4143 * (DP CTS 1.2 Core r1.1)
4144 * 4.2.2.4 : Failed EDID read, I2C_NAK
4145 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4146 * 4.2.2.6 : EDID corruption detected
4147 * Use failsafe mode for all cases
4149 if (intel_dp->aux.i2c_nack_count > 0 ||
4150 intel_dp->aux.i2c_defer_count > 0)
4151 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4152 intel_dp->aux.i2c_nack_count,
4153 intel_dp->aux.i2c_defer_count);
4154 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
4156 struct edid *block = intel_connector->detect_edid;
4158 /* We have to write the checksum
4159 * of the last block read
4161 block += intel_connector->detect_edid->extensions;
4163 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4164 block->checksum) <= 0)
4165 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4167 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
4168 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
4171 /* Set test active flag here so userspace doesn't interrupt things */
4172 intel_dp->compliance.test_active = 1;
4177 static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4179 uint8_t test_result = DP_TEST_NAK;
4183 static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4185 uint8_t response = DP_TEST_NAK;
4186 uint8_t request = 0;
4189 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
4191 DRM_DEBUG_KMS("Could not read test request from sink\n");
4196 case DP_TEST_LINK_TRAINING:
4197 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
4198 response = intel_dp_autotest_link_training(intel_dp);
4200 case DP_TEST_LINK_VIDEO_PATTERN:
4201 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
4202 response = intel_dp_autotest_video_pattern(intel_dp);
4204 case DP_TEST_LINK_EDID_READ:
4205 DRM_DEBUG_KMS("EDID test requested\n");
4206 response = intel_dp_autotest_edid(intel_dp);
4208 case DP_TEST_LINK_PHY_TEST_PATTERN:
4209 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
4210 response = intel_dp_autotest_phy_pattern(intel_dp);
4213 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
4217 if (response & DP_TEST_ACK)
4218 intel_dp->compliance.test_type = request;
4221 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
4223 DRM_DEBUG_KMS("Could not write test response to sink\n");
4227 intel_dp_check_mst_status(struct intel_dp *intel_dp)
4231 if (intel_dp->is_mst) {
4232 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
4236 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4240 /* check link status - esi[10] = 0x200c */
4241 if (intel_dp->active_mst_links &&
4242 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4243 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4244 intel_dp_start_link_train(intel_dp);
4245 intel_dp_stop_link_train(intel_dp);
4248 DRM_DEBUG_KMS("got esi %3ph\n", esi);
4249 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4252 for (retry = 0; retry < 3; retry++) {
4254 wret = drm_dp_dpcd_write(&intel_dp->aux,
4255 DP_SINK_COUNT_ESI+1,
4262 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4264 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
4272 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4273 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4274 intel_dp->is_mst = false;
4275 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4276 /* send a hotplug event */
4277 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4284 intel_dp_retrain_link(struct intel_dp *intel_dp)
4286 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4287 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4288 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4290 /* Suppress underruns caused by re-training */
4291 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4292 if (crtc->config->has_pch_encoder)
4293 intel_set_pch_fifo_underrun_reporting(dev_priv,
4294 intel_crtc_pch_transcoder(crtc), false);
4296 intel_dp_start_link_train(intel_dp);
4297 intel_dp_stop_link_train(intel_dp);
4299 /* Keep underrun reporting disabled until things are stable */
4300 intel_wait_for_vblank(dev_priv, crtc->pipe);
4302 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4303 if (crtc->config->has_pch_encoder)
4304 intel_set_pch_fifo_underrun_reporting(dev_priv,
4305 intel_crtc_pch_transcoder(crtc), true);
4309 intel_dp_check_link_status(struct intel_dp *intel_dp)
4311 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4312 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4313 struct drm_connector_state *conn_state =
4314 intel_dp->attached_connector->base.state;
4315 u8 link_status[DP_LINK_STATUS_SIZE];
4317 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4319 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4320 DRM_ERROR("Failed to get link status\n");
4324 if (!conn_state->crtc)
4327 WARN_ON(!drm_modeset_is_locked(&conn_state->crtc->mutex));
4329 if (!conn_state->crtc->state->active)
4332 if (conn_state->commit &&
4333 !try_wait_for_completion(&conn_state->commit->hw_done))
4337 * Validate the cached values of intel_dp->link_rate and
4338 * intel_dp->lane_count before attempting to retrain.
4340 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4341 intel_dp->lane_count))
4344 /* Retrain if Channel EQ or CR not ok */
4345 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
4346 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4347 intel_encoder->base.name);
4349 intel_dp_retrain_link(intel_dp);
4354 * According to DP spec
4357 * 2. Configure link according to Receiver Capabilities
4358 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4359 * 4. Check link status on receipt of hot-plug interrupt
4361 * intel_dp_short_pulse - handles short pulse interrupts
4362 * when full detection is not required.
4363 * Returns %true if short pulse is handled and full detection
4364 * is NOT required and %false otherwise.
4367 intel_dp_short_pulse(struct intel_dp *intel_dp)
4369 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4370 u8 sink_irq_vector = 0;
4371 u8 old_sink_count = intel_dp->sink_count;
4375 * Clearing compliance test variables to allow capturing
4376 * of values for next automated test request.
4378 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4381 * Now read the DPCD to see if it's actually running
4382 * If the current value of sink count doesn't match with
4383 * the value that was stored earlier or dpcd read failed
4384 * we need to do full detection
4386 ret = intel_dp_get_dpcd(intel_dp);
4388 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4389 /* No need to proceed if we are going to do full detect */
4393 /* Try to read the source of the interrupt */
4394 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4395 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4396 sink_irq_vector != 0) {
4397 /* Clear interrupt source */
4398 drm_dp_dpcd_writeb(&intel_dp->aux,
4399 DP_DEVICE_SERVICE_IRQ_VECTOR,
4402 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4403 intel_dp_handle_test_request(intel_dp);
4404 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4405 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4408 intel_dp_check_link_status(intel_dp);
4410 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4411 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4412 /* Send a Hotplug Uevent to userspace to start modeset */
4413 drm_kms_helper_hotplug_event(&dev_priv->drm);
4419 /* XXX this is probably wrong for multiple downstream ports */
4420 static enum drm_connector_status
4421 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
4423 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
4424 uint8_t *dpcd = intel_dp->dpcd;
4428 lspcon_resume(lspcon);
4430 if (!intel_dp_get_dpcd(intel_dp))
4431 return connector_status_disconnected;
4433 if (intel_dp_is_edp(intel_dp))
4434 return connector_status_connected;
4436 /* if there's no downstream port, we're done */
4437 if (!drm_dp_is_branch(dpcd))
4438 return connector_status_connected;
4440 /* If we're HPD-aware, SINK_COUNT changes dynamically */
4441 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4442 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
4444 return intel_dp->sink_count ?
4445 connector_status_connected : connector_status_disconnected;
4448 if (intel_dp_can_mst(intel_dp))
4449 return connector_status_connected;
4451 /* If no HPD, poke DDC gently */
4452 if (drm_probe_ddc(&intel_dp->aux.ddc))
4453 return connector_status_connected;
4455 /* Well we tried, say unknown for unreliable port types */
4456 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4457 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4458 if (type == DP_DS_PORT_TYPE_VGA ||
4459 type == DP_DS_PORT_TYPE_NON_EDID)
4460 return connector_status_unknown;
4462 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4463 DP_DWN_STRM_PORT_TYPE_MASK;
4464 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4465 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4466 return connector_status_unknown;
4469 /* Anything else is out of spec, warn and ignore */
4470 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
4471 return connector_status_disconnected;
4474 static enum drm_connector_status
4475 edp_detect(struct intel_dp *intel_dp)
4477 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4478 enum drm_connector_status status;
4480 status = intel_panel_detect(dev_priv);
4481 if (status == connector_status_unknown)
4482 status = connector_status_connected;
4487 static bool ibx_digital_port_connected(struct intel_encoder *encoder)
4489 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4492 switch (encoder->hpd_pin) {
4494 bit = SDE_PORTB_HOTPLUG;
4497 bit = SDE_PORTC_HOTPLUG;
4500 bit = SDE_PORTD_HOTPLUG;
4503 MISSING_CASE(encoder->hpd_pin);
4507 return I915_READ(SDEISR) & bit;
4510 static bool cpt_digital_port_connected(struct intel_encoder *encoder)
4512 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4515 switch (encoder->hpd_pin) {
4517 bit = SDE_PORTB_HOTPLUG_CPT;
4520 bit = SDE_PORTC_HOTPLUG_CPT;
4523 bit = SDE_PORTD_HOTPLUG_CPT;
4526 MISSING_CASE(encoder->hpd_pin);
4530 return I915_READ(SDEISR) & bit;
4533 static bool spt_digital_port_connected(struct intel_encoder *encoder)
4535 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4538 switch (encoder->hpd_pin) {
4540 bit = SDE_PORTA_HOTPLUG_SPT;
4543 bit = SDE_PORTE_HOTPLUG_SPT;
4546 return cpt_digital_port_connected(encoder);
4549 return I915_READ(SDEISR) & bit;
4552 static bool g4x_digital_port_connected(struct intel_encoder *encoder)
4554 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4557 switch (encoder->hpd_pin) {
4559 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4562 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4565 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4568 MISSING_CASE(encoder->hpd_pin);
4572 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4575 static bool gm45_digital_port_connected(struct intel_encoder *encoder)
4577 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4580 switch (encoder->hpd_pin) {
4582 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
4585 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
4588 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
4591 MISSING_CASE(encoder->hpd_pin);
4595 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4598 static bool ilk_digital_port_connected(struct intel_encoder *encoder)
4600 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4602 if (encoder->hpd_pin == HPD_PORT_A)
4603 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4605 return ibx_digital_port_connected(encoder);
4608 static bool snb_digital_port_connected(struct intel_encoder *encoder)
4610 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4612 if (encoder->hpd_pin == HPD_PORT_A)
4613 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4615 return cpt_digital_port_connected(encoder);
4618 static bool ivb_digital_port_connected(struct intel_encoder *encoder)
4620 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4622 if (encoder->hpd_pin == HPD_PORT_A)
4623 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4625 return cpt_digital_port_connected(encoder);
4628 static bool bdw_digital_port_connected(struct intel_encoder *encoder)
4630 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4632 if (encoder->hpd_pin == HPD_PORT_A)
4633 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4635 return cpt_digital_port_connected(encoder);
4638 static bool bxt_digital_port_connected(struct intel_encoder *encoder)
4640 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4643 switch (encoder->hpd_pin) {
4645 bit = BXT_DE_PORT_HP_DDIA;
4648 bit = BXT_DE_PORT_HP_DDIB;
4651 bit = BXT_DE_PORT_HP_DDIC;
4654 MISSING_CASE(encoder->hpd_pin);
4658 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4662 * intel_digital_port_connected - is the specified port connected?
4663 * @encoder: intel_encoder
4665 * Return %true if port is connected, %false otherwise.
4667 bool intel_digital_port_connected(struct intel_encoder *encoder)
4669 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4671 if (HAS_GMCH_DISPLAY(dev_priv)) {
4672 if (IS_GM45(dev_priv))
4673 return gm45_digital_port_connected(encoder);
4675 return g4x_digital_port_connected(encoder);
4678 if (IS_GEN5(dev_priv))
4679 return ilk_digital_port_connected(encoder);
4680 else if (IS_GEN6(dev_priv))
4681 return snb_digital_port_connected(encoder);
4682 else if (IS_GEN7(dev_priv))
4683 return ivb_digital_port_connected(encoder);
4684 else if (IS_GEN8(dev_priv))
4685 return bdw_digital_port_connected(encoder);
4686 else if (IS_GEN9_LP(dev_priv))
4687 return bxt_digital_port_connected(encoder);
4689 return spt_digital_port_connected(encoder);
4692 static struct edid *
4693 intel_dp_get_edid(struct intel_dp *intel_dp)
4695 struct intel_connector *intel_connector = intel_dp->attached_connector;
4697 /* use cached edid if we have one */
4698 if (intel_connector->edid) {
4700 if (IS_ERR(intel_connector->edid))
4703 return drm_edid_duplicate(intel_connector->edid);
4705 return drm_get_edid(&intel_connector->base,
4706 &intel_dp->aux.ddc);
4710 intel_dp_set_edid(struct intel_dp *intel_dp)
4712 struct intel_connector *intel_connector = intel_dp->attached_connector;
4715 intel_dp_unset_edid(intel_dp);
4716 edid = intel_dp_get_edid(intel_dp);
4717 intel_connector->detect_edid = edid;
4719 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4723 intel_dp_unset_edid(struct intel_dp *intel_dp)
4725 struct intel_connector *intel_connector = intel_dp->attached_connector;
4727 kfree(intel_connector->detect_edid);
4728 intel_connector->detect_edid = NULL;
4730 intel_dp->has_audio = false;
4734 intel_dp_long_pulse(struct intel_connector *connector)
4736 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
4737 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
4738 enum drm_connector_status status;
4739 u8 sink_irq_vector = 0;
4741 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4743 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4745 /* Can't disconnect eDP, but you can close the lid... */
4746 if (intel_dp_is_edp(intel_dp))
4747 status = edp_detect(intel_dp);
4748 else if (intel_digital_port_connected(&dp_to_dig_port(intel_dp)->base))
4749 status = intel_dp_detect_dpcd(intel_dp);
4751 status = connector_status_disconnected;
4753 if (status == connector_status_disconnected) {
4754 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4756 if (intel_dp->is_mst) {
4757 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4759 intel_dp->mst_mgr.mst_state);
4760 intel_dp->is_mst = false;
4761 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4768 if (intel_dp->reset_link_params) {
4769 /* Initial max link lane count */
4770 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
4772 /* Initial max link rate */
4773 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
4775 intel_dp->reset_link_params = false;
4778 intel_dp_print_rates(intel_dp);
4780 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4781 drm_dp_is_branch(intel_dp->dpcd));
4783 intel_dp_configure_mst(intel_dp);
4785 if (intel_dp->is_mst) {
4787 * If we are in MST mode then this connector
4788 * won't appear connected or have anything
4791 status = connector_status_disconnected;
4795 * If display is now connected check links status,
4796 * there has been known issues of link loss triggerring
4799 * Some sinks (eg. ASUS PB287Q) seem to perform some
4800 * weird HPD ping pong during modesets. So we can apparently
4801 * end up with HPD going low during a modeset, and then
4802 * going back up soon after. And once that happens we must
4803 * retrain the link to get a picture. That's in case no
4804 * userspace component reacted to intermittent HPD dip.
4806 intel_dp_check_link_status(intel_dp);
4810 * Clearing NACK and defer counts to get their exact values
4811 * while reading EDID which are required by Compliance tests
4812 * 4.2.2.4 and 4.2.2.5
4814 intel_dp->aux.i2c_nack_count = 0;
4815 intel_dp->aux.i2c_defer_count = 0;
4817 intel_dp_set_edid(intel_dp);
4818 if (intel_dp_is_edp(intel_dp) || connector->detect_edid)
4819 status = connector_status_connected;
4820 intel_dp->detect_done = true;
4822 /* Try to read the source of the interrupt */
4823 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4824 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4825 sink_irq_vector != 0) {
4826 /* Clear interrupt source */
4827 drm_dp_dpcd_writeb(&intel_dp->aux,
4828 DP_DEVICE_SERVICE_IRQ_VECTOR,
4831 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4832 intel_dp_handle_test_request(intel_dp);
4833 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4834 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4838 if (status != connector_status_connected && !intel_dp->is_mst)
4839 intel_dp_unset_edid(intel_dp);
4841 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4846 intel_dp_detect(struct drm_connector *connector,
4847 struct drm_modeset_acquire_ctx *ctx,
4850 struct intel_dp *intel_dp = intel_attached_dp(connector);
4851 int status = connector->status;
4853 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4854 connector->base.id, connector->name);
4856 /* If full detect is not performed yet, do a full detect */
4857 if (!intel_dp->detect_done) {
4858 struct drm_crtc *crtc;
4861 crtc = connector->state->crtc;
4863 ret = drm_modeset_lock(&crtc->mutex, ctx);
4868 status = intel_dp_long_pulse(intel_dp->attached_connector);
4871 intel_dp->detect_done = false;
4877 intel_dp_force(struct drm_connector *connector)
4879 struct intel_dp *intel_dp = intel_attached_dp(connector);
4880 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4881 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
4883 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4884 connector->base.id, connector->name);
4885 intel_dp_unset_edid(intel_dp);
4887 if (connector->status != connector_status_connected)
4890 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4892 intel_dp_set_edid(intel_dp);
4894 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4897 static int intel_dp_get_modes(struct drm_connector *connector)
4899 struct intel_connector *intel_connector = to_intel_connector(connector);
4902 edid = intel_connector->detect_edid;
4904 int ret = intel_connector_update_modes(connector, edid);
4909 /* if eDP has no EDID, fall back to fixed mode */
4910 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
4911 intel_connector->panel.fixed_mode) {
4912 struct drm_display_mode *mode;
4914 mode = drm_mode_duplicate(connector->dev,
4915 intel_connector->panel.fixed_mode);
4917 drm_mode_probed_add(connector, mode);
4926 intel_dp_connector_register(struct drm_connector *connector)
4928 struct intel_dp *intel_dp = intel_attached_dp(connector);
4931 ret = intel_connector_register(connector);
4935 i915_debugfs_connector_add(connector);
4937 DRM_DEBUG_KMS("registering %s bus for %s\n",
4938 intel_dp->aux.name, connector->kdev->kobj.name);
4940 intel_dp->aux.dev = connector->kdev;
4941 return drm_dp_aux_register(&intel_dp->aux);
4945 intel_dp_connector_unregister(struct drm_connector *connector)
4947 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4948 intel_connector_unregister(connector);
4952 intel_dp_connector_destroy(struct drm_connector *connector)
4954 struct intel_connector *intel_connector = to_intel_connector(connector);
4956 kfree(intel_connector->detect_edid);
4958 if (!IS_ERR_OR_NULL(intel_connector->edid))
4959 kfree(intel_connector->edid);
4962 * Can't call intel_dp_is_edp() since the encoder may have been
4963 * destroyed already.
4965 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4966 intel_panel_fini(&intel_connector->panel);
4968 drm_connector_cleanup(connector);
4972 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
4974 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4975 struct intel_dp *intel_dp = &intel_dig_port->dp;
4977 intel_dp_mst_encoder_cleanup(intel_dig_port);
4978 if (intel_dp_is_edp(intel_dp)) {
4979 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4981 * vdd might still be enabled do to the delayed vdd off.
4982 * Make sure vdd is actually turned off here.
4985 edp_panel_vdd_off_sync(intel_dp);
4986 pps_unlock(intel_dp);
4988 if (intel_dp->edp_notifier.notifier_call) {
4989 unregister_reboot_notifier(&intel_dp->edp_notifier);
4990 intel_dp->edp_notifier.notifier_call = NULL;
4994 intel_dp_aux_fini(intel_dp);
4996 drm_encoder_cleanup(encoder);
4997 kfree(intel_dig_port);
5000 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
5002 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
5004 if (!intel_dp_is_edp(intel_dp))
5008 * vdd might still be enabled do to the delayed vdd off.
5009 * Make sure vdd is actually turned off here.
5011 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5013 edp_panel_vdd_off_sync(intel_dp);
5014 pps_unlock(intel_dp);
5017 static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
5019 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5021 lockdep_assert_held(&dev_priv->pps_mutex);
5023 if (!edp_have_panel_vdd(intel_dp))
5027 * The VDD bit needs a power domain reference, so if the bit is
5028 * already enabled when we boot or resume, grab this reference and
5029 * schedule a vdd off, so we don't hold on to the reference
5032 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
5033 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
5035 edp_panel_vdd_schedule_off(intel_dp);
5038 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
5040 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5042 if ((intel_dp->DP & DP_PORT_EN) == 0)
5043 return INVALID_PIPE;
5045 if (IS_CHERRYVIEW(dev_priv))
5046 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
5048 return PORT_TO_PIPE(intel_dp->DP);
5051 void intel_dp_encoder_reset(struct drm_encoder *encoder)
5053 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
5054 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5055 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
5057 if (!HAS_DDI(dev_priv))
5058 intel_dp->DP = I915_READ(intel_dp->output_reg);
5061 lspcon_resume(lspcon);
5063 intel_dp->reset_link_params = true;
5067 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5068 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5070 if (intel_dp_is_edp(intel_dp)) {
5071 /* Reinit the power sequencer, in case BIOS did something with it. */
5072 intel_dp_pps_init(intel_dp);
5073 intel_edp_panel_vdd_sanitize(intel_dp);
5076 pps_unlock(intel_dp);
5079 static const struct drm_connector_funcs intel_dp_connector_funcs = {
5080 .force = intel_dp_force,
5081 .fill_modes = drm_helper_probe_single_connector_modes,
5082 .atomic_get_property = intel_digital_connector_atomic_get_property,
5083 .atomic_set_property = intel_digital_connector_atomic_set_property,
5084 .late_register = intel_dp_connector_register,
5085 .early_unregister = intel_dp_connector_unregister,
5086 .destroy = intel_dp_connector_destroy,
5087 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
5088 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
5091 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5092 .detect_ctx = intel_dp_detect,
5093 .get_modes = intel_dp_get_modes,
5094 .mode_valid = intel_dp_mode_valid,
5095 .atomic_check = intel_digital_connector_atomic_check,
5098 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
5099 .reset = intel_dp_encoder_reset,
5100 .destroy = intel_dp_encoder_destroy,
5104 intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5106 struct intel_dp *intel_dp = &intel_dig_port->dp;
5107 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5108 enum irqreturn ret = IRQ_NONE;
5110 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5112 * vdd off can generate a long pulse on eDP which
5113 * would require vdd on to handle it, and thus we
5114 * would end up in an endless cycle of
5115 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5117 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5118 port_name(intel_dig_port->base.port));
5122 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5123 port_name(intel_dig_port->base.port),
5124 long_hpd ? "long" : "short");
5127 intel_dp->reset_link_params = true;
5128 intel_dp->detect_done = false;
5132 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
5134 if (intel_dp->is_mst) {
5135 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5137 * If we were in MST mode, and device is not
5138 * there, get out of MST mode
5140 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5141 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5142 intel_dp->is_mst = false;
5143 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5145 intel_dp->detect_done = false;
5150 if (!intel_dp->is_mst) {
5151 struct drm_modeset_acquire_ctx ctx;
5152 struct drm_connector *connector = &intel_dp->attached_connector->base;
5153 struct drm_crtc *crtc;
5155 bool handled = false;
5157 drm_modeset_acquire_init(&ctx, 0);
5159 iret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, &ctx);
5163 crtc = connector->state->crtc;
5165 iret = drm_modeset_lock(&crtc->mutex, &ctx);
5170 handled = intel_dp_short_pulse(intel_dp);
5173 if (iret == -EDEADLK) {
5174 drm_modeset_backoff(&ctx);
5178 drm_modeset_drop_locks(&ctx);
5179 drm_modeset_acquire_fini(&ctx);
5180 WARN(iret, "Acquiring modeset locks failed with %i\n", iret);
5183 intel_dp->detect_done = false;
5191 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
5196 /* check the VBT to see whether the eDP is on another port */
5197 bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
5200 * eDP not supported on g4x. so bail out early just
5201 * for a bit extra safety in case the VBT is bonkers.
5203 if (INTEL_GEN(dev_priv) < 5)
5206 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
5209 return intel_bios_is_port_edp(dev_priv, port);
5213 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5215 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5216 enum port port = dp_to_dig_port(intel_dp)->base.port;
5218 if (!IS_G4X(dev_priv) && port != PORT_A)
5219 intel_attach_force_audio_property(connector);
5221 intel_attach_broadcast_rgb_property(connector);
5223 if (intel_dp_is_edp(intel_dp)) {
5224 u32 allowed_scalers;
5226 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5227 if (!HAS_GMCH_DISPLAY(dev_priv))
5228 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5230 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5232 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
5237 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5239 intel_dp->panel_power_off_time = ktime_get_boottime();
5240 intel_dp->last_power_on = jiffies;
5241 intel_dp->last_backlight_off = jiffies;
5245 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
5247 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5248 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
5249 struct pps_registers regs;
5251 intel_pps_get_registers(intel_dp, ®s);
5253 /* Workaround: Need to write PP_CONTROL with the unlock key as
5254 * the very first thing. */
5255 pp_ctl = ironlake_get_pp_control(intel_dp);
5257 pp_on = I915_READ(regs.pp_on);
5258 pp_off = I915_READ(regs.pp_off);
5259 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv) &&
5260 !HAS_PCH_ICP(dev_priv)) {
5261 I915_WRITE(regs.pp_ctrl, pp_ctl);
5262 pp_div = I915_READ(regs.pp_div);
5265 /* Pull timing values out of registers */
5266 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5267 PANEL_POWER_UP_DELAY_SHIFT;
5269 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5270 PANEL_LIGHT_ON_DELAY_SHIFT;
5272 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5273 PANEL_LIGHT_OFF_DELAY_SHIFT;
5275 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5276 PANEL_POWER_DOWN_DELAY_SHIFT;
5278 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5279 HAS_PCH_ICP(dev_priv)) {
5280 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5281 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
5283 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
5284 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
5289 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5291 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5293 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5297 intel_pps_verify_state(struct intel_dp *intel_dp)
5299 struct edp_power_seq hw;
5300 struct edp_power_seq *sw = &intel_dp->pps_delays;
5302 intel_pps_readout_hw_state(intel_dp, &hw);
5304 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5305 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5306 DRM_ERROR("PPS state mismatch\n");
5307 intel_pps_dump_state("sw", sw);
5308 intel_pps_dump_state("hw", &hw);
5313 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
5315 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5316 struct edp_power_seq cur, vbt, spec,
5317 *final = &intel_dp->pps_delays;
5319 lockdep_assert_held(&dev_priv->pps_mutex);
5321 /* already initialized? */
5322 if (final->t11_t12 != 0)
5325 intel_pps_readout_hw_state(intel_dp, &cur);
5327 intel_pps_dump_state("cur", &cur);
5329 vbt = dev_priv->vbt.edp.pps;
5330 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5331 * of 500ms appears to be too short. Ocassionally the panel
5332 * just fails to power back on. Increasing the delay to 800ms
5333 * seems sufficient to avoid this problem.
5335 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
5336 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
5337 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5340 /* T11_T12 delay is special and actually in units of 100ms, but zero
5341 * based in the hw (so we need to add 100 ms). But the sw vbt
5342 * table multiplies it with 1000 to make it in units of 100usec,
5344 vbt.t11_t12 += 100 * 10;
5346 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5347 * our hw here, which are all in 100usec. */
5348 spec.t1_t3 = 210 * 10;
5349 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5350 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5351 spec.t10 = 500 * 10;
5352 /* This one is special and actually in units of 100ms, but zero
5353 * based in the hw (so we need to add 100 ms). But the sw vbt
5354 * table multiplies it with 1000 to make it in units of 100usec,
5356 spec.t11_t12 = (510 + 100) * 10;
5358 intel_pps_dump_state("vbt", &vbt);
5360 /* Use the max of the register settings and vbt. If both are
5361 * unset, fall back to the spec limits. */
5362 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
5364 max(cur.field, vbt.field))
5365 assign_final(t1_t3);
5369 assign_final(t11_t12);
5372 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
5373 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5374 intel_dp->backlight_on_delay = get_delay(t8);
5375 intel_dp->backlight_off_delay = get_delay(t9);
5376 intel_dp->panel_power_down_delay = get_delay(t10);
5377 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5380 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5381 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5382 intel_dp->panel_power_cycle_delay);
5384 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5385 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
5388 * We override the HW backlight delays to 1 because we do manual waits
5389 * on them. For T8, even BSpec recommends doing it. For T9, if we
5390 * don't do this, we'll end up waiting for the backlight off delay
5391 * twice: once when we do the manual sleep, and once when we disable
5392 * the panel and wait for the PP_STATUS bit to become zero.
5398 * HW has only a 100msec granularity for t11_t12 so round it up
5401 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
5405 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
5406 bool force_disable_vdd)
5408 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5409 u32 pp_on, pp_off, pp_div, port_sel = 0;
5410 int div = dev_priv->rawclk_freq / 1000;
5411 struct pps_registers regs;
5412 enum port port = dp_to_dig_port(intel_dp)->base.port;
5413 const struct edp_power_seq *seq = &intel_dp->pps_delays;
5415 lockdep_assert_held(&dev_priv->pps_mutex);
5417 intel_pps_get_registers(intel_dp, ®s);
5420 * On some VLV machines the BIOS can leave the VDD
5421 * enabled even on power seqeuencers which aren't
5422 * hooked up to any port. This would mess up the
5423 * power domain tracking the first time we pick
5424 * one of these power sequencers for use since
5425 * edp_panel_vdd_on() would notice that the VDD was
5426 * already on and therefore wouldn't grab the power
5427 * domain reference. Disable VDD first to avoid this.
5428 * This also avoids spuriously turning the VDD on as
5429 * soon as the new power seqeuencer gets initialized.
5431 if (force_disable_vdd) {
5432 u32 pp = ironlake_get_pp_control(intel_dp);
5434 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5436 if (pp & EDP_FORCE_VDD)
5437 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5439 pp &= ~EDP_FORCE_VDD;
5441 I915_WRITE(regs.pp_ctrl, pp);
5444 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
5445 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5446 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
5447 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
5448 /* Compute the divisor for the pp clock, simply match the Bspec
5450 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5451 HAS_PCH_ICP(dev_priv)) {
5452 pp_div = I915_READ(regs.pp_ctrl);
5453 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5454 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5455 << BXT_POWER_CYCLE_DELAY_SHIFT);
5457 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5458 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5459 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5462 /* Haswell doesn't have any port selection bits for the panel
5463 * power sequencer any more. */
5464 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5465 port_sel = PANEL_PORT_SELECT_VLV(port);
5466 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
5468 port_sel = PANEL_PORT_SELECT_DPA;
5470 port_sel = PANEL_PORT_SELECT_DPD;
5475 I915_WRITE(regs.pp_on, pp_on);
5476 I915_WRITE(regs.pp_off, pp_off);
5477 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5478 HAS_PCH_ICP(dev_priv))
5479 I915_WRITE(regs.pp_ctrl, pp_div);
5481 I915_WRITE(regs.pp_div, pp_div);
5483 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
5484 I915_READ(regs.pp_on),
5485 I915_READ(regs.pp_off),
5486 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv) ||
5487 HAS_PCH_ICP(dev_priv)) ?
5488 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5489 I915_READ(regs.pp_div));
5492 static void intel_dp_pps_init(struct intel_dp *intel_dp)
5494 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5496 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5497 vlv_initial_power_sequencer_setup(intel_dp);
5499 intel_dp_init_panel_power_sequencer(intel_dp);
5500 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
5505 * intel_dp_set_drrs_state - program registers for RR switch to take effect
5506 * @dev_priv: i915 device
5507 * @crtc_state: a pointer to the active intel_crtc_state
5508 * @refresh_rate: RR to be programmed
5510 * This function gets called when refresh rate (RR) has to be changed from
5511 * one frequency to another. Switches can be between high and low RR
5512 * supported by the panel or to any other RR based on media playback (in
5513 * this case, RR value needs to be passed from user space).
5515 * The caller of this function needs to take a lock on dev_priv->drrs.
5517 static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5518 const struct intel_crtc_state *crtc_state,
5521 struct intel_encoder *encoder;
5522 struct intel_digital_port *dig_port = NULL;
5523 struct intel_dp *intel_dp = dev_priv->drrs.dp;
5524 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
5525 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
5527 if (refresh_rate <= 0) {
5528 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5532 if (intel_dp == NULL) {
5533 DRM_DEBUG_KMS("DRRS not supported.\n");
5537 dig_port = dp_to_dig_port(intel_dp);
5538 encoder = &dig_port->base;
5541 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5545 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
5546 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5550 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5552 index = DRRS_LOW_RR;
5554 if (index == dev_priv->drrs.refresh_rate_type) {
5556 "DRRS requested for previously set RR...ignoring\n");
5560 if (!crtc_state->base.active) {
5561 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5565 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
5568 intel_dp_set_m_n(intel_crtc, M1_N1);
5571 intel_dp_set_m_n(intel_crtc, M2_N2);
5575 DRM_ERROR("Unsupported refreshrate type\n");
5577 } else if (INTEL_GEN(dev_priv) > 6) {
5578 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
5581 val = I915_READ(reg);
5582 if (index > DRRS_HIGH_RR) {
5583 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5584 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5586 val |= PIPECONF_EDP_RR_MODE_SWITCH;
5588 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5589 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5591 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
5593 I915_WRITE(reg, val);
5596 dev_priv->drrs.refresh_rate_type = index;
5598 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5602 * intel_edp_drrs_enable - init drrs struct if supported
5603 * @intel_dp: DP struct
5604 * @crtc_state: A pointer to the active crtc state.
5606 * Initializes frontbuffer_bits and drrs.dp
5608 void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5609 const struct intel_crtc_state *crtc_state)
5611 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5613 if (!crtc_state->has_drrs) {
5614 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5618 if (dev_priv->psr.enabled) {
5619 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5623 mutex_lock(&dev_priv->drrs.mutex);
5624 if (WARN_ON(dev_priv->drrs.dp)) {
5625 DRM_ERROR("DRRS already enabled\n");
5629 dev_priv->drrs.busy_frontbuffer_bits = 0;
5631 dev_priv->drrs.dp = intel_dp;
5634 mutex_unlock(&dev_priv->drrs.mutex);
5638 * intel_edp_drrs_disable - Disable DRRS
5639 * @intel_dp: DP struct
5640 * @old_crtc_state: Pointer to old crtc_state.
5643 void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5644 const struct intel_crtc_state *old_crtc_state)
5646 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5648 if (!old_crtc_state->has_drrs)
5651 mutex_lock(&dev_priv->drrs.mutex);
5652 if (!dev_priv->drrs.dp) {
5653 mutex_unlock(&dev_priv->drrs.mutex);
5657 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5658 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5659 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
5661 dev_priv->drrs.dp = NULL;
5662 mutex_unlock(&dev_priv->drrs.mutex);
5664 cancel_delayed_work_sync(&dev_priv->drrs.work);
5667 static void intel_edp_drrs_downclock_work(struct work_struct *work)
5669 struct drm_i915_private *dev_priv =
5670 container_of(work, typeof(*dev_priv), drrs.work.work);
5671 struct intel_dp *intel_dp;
5673 mutex_lock(&dev_priv->drrs.mutex);
5675 intel_dp = dev_priv->drrs.dp;
5681 * The delayed work can race with an invalidate hence we need to
5685 if (dev_priv->drrs.busy_frontbuffer_bits)
5688 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5689 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5691 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5692 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5696 mutex_unlock(&dev_priv->drrs.mutex);
5700 * intel_edp_drrs_invalidate - Disable Idleness DRRS
5701 * @dev_priv: i915 device
5702 * @frontbuffer_bits: frontbuffer plane tracking bits
5704 * This function gets called everytime rendering on the given planes start.
5705 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
5707 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5709 void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5710 unsigned int frontbuffer_bits)
5712 struct drm_crtc *crtc;
5715 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5718 cancel_delayed_work(&dev_priv->drrs.work);
5720 mutex_lock(&dev_priv->drrs.mutex);
5721 if (!dev_priv->drrs.dp) {
5722 mutex_unlock(&dev_priv->drrs.mutex);
5726 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5727 pipe = to_intel_crtc(crtc)->pipe;
5729 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5730 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5732 /* invalidate means busy screen hence upclock */
5733 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5734 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5735 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
5737 mutex_unlock(&dev_priv->drrs.mutex);
5741 * intel_edp_drrs_flush - Restart Idleness DRRS
5742 * @dev_priv: i915 device
5743 * @frontbuffer_bits: frontbuffer plane tracking bits
5745 * This function gets called every time rendering on the given planes has
5746 * completed or flip on a crtc is completed. So DRRS should be upclocked
5747 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5748 * if no other planes are dirty.
5750 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5752 void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5753 unsigned int frontbuffer_bits)
5755 struct drm_crtc *crtc;
5758 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5761 cancel_delayed_work(&dev_priv->drrs.work);
5763 mutex_lock(&dev_priv->drrs.mutex);
5764 if (!dev_priv->drrs.dp) {
5765 mutex_unlock(&dev_priv->drrs.mutex);
5769 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5770 pipe = to_intel_crtc(crtc)->pipe;
5772 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5773 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5775 /* flush means busy screen hence upclock */
5776 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5777 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5778 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
5781 * flush also means no more activity hence schedule downclock, if all
5782 * other fbs are quiescent too
5784 if (!dev_priv->drrs.busy_frontbuffer_bits)
5785 schedule_delayed_work(&dev_priv->drrs.work,
5786 msecs_to_jiffies(1000));
5787 mutex_unlock(&dev_priv->drrs.mutex);
5791 * DOC: Display Refresh Rate Switching (DRRS)
5793 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5794 * which enables swtching between low and high refresh rates,
5795 * dynamically, based on the usage scenario. This feature is applicable
5796 * for internal panels.
5798 * Indication that the panel supports DRRS is given by the panel EDID, which
5799 * would list multiple refresh rates for one resolution.
5801 * DRRS is of 2 types - static and seamless.
5802 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5803 * (may appear as a blink on screen) and is used in dock-undock scenario.
5804 * Seamless DRRS involves changing RR without any visual effect to the user
5805 * and can be used during normal system usage. This is done by programming
5806 * certain registers.
5808 * Support for static/seamless DRRS may be indicated in the VBT based on
5809 * inputs from the panel spec.
5811 * DRRS saves power by switching to low RR based on usage scenarios.
5813 * The implementation is based on frontbuffer tracking implementation. When
5814 * there is a disturbance on the screen triggered by user activity or a periodic
5815 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5816 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5819 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5820 * and intel_edp_drrs_flush() are called.
5822 * DRRS can be further extended to support other internal panels and also
5823 * the scenario of video playback wherein RR is set based on the rate
5824 * requested by userspace.
5828 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5829 * @connector: eDP connector
5830 * @fixed_mode: preferred mode of panel
5832 * This function is called only once at driver load to initialize basic
5836 * Downclock mode if panel supports it, else return NULL.
5837 * DRRS support is determined by the presence of downclock mode (apart
5838 * from VBT setting).
5840 static struct drm_display_mode *
5841 intel_dp_drrs_init(struct intel_connector *connector,
5842 struct drm_display_mode *fixed_mode)
5844 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
5845 struct drm_display_mode *downclock_mode = NULL;
5847 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5848 mutex_init(&dev_priv->drrs.mutex);
5850 if (INTEL_GEN(dev_priv) <= 6) {
5851 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5855 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
5856 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
5860 downclock_mode = intel_find_panel_downclock(dev_priv, fixed_mode,
5863 if (!downclock_mode) {
5864 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
5868 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
5870 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
5871 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
5872 return downclock_mode;
5875 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
5876 struct intel_connector *intel_connector)
5878 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5879 struct drm_i915_private *dev_priv = to_i915(dev);
5880 struct drm_connector *connector = &intel_connector->base;
5881 struct drm_display_mode *fixed_mode = NULL;
5882 struct drm_display_mode *alt_fixed_mode = NULL;
5883 struct drm_display_mode *downclock_mode = NULL;
5885 struct drm_display_mode *scan;
5887 enum pipe pipe = INVALID_PIPE;
5889 if (!intel_dp_is_edp(intel_dp))
5893 * On IBX/CPT we may get here with LVDS already registered. Since the
5894 * driver uses the only internal power sequencer available for both
5895 * eDP and LVDS bail out early in this case to prevent interfering
5896 * with an already powered-on LVDS power sequencer.
5898 if (intel_get_lvds_encoder(&dev_priv->drm)) {
5899 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5900 DRM_INFO("LVDS was detected, not registering eDP\n");
5907 intel_dp_init_panel_power_timestamps(intel_dp);
5908 intel_dp_pps_init(intel_dp);
5909 intel_edp_panel_vdd_sanitize(intel_dp);
5911 pps_unlock(intel_dp);
5913 /* Cache DPCD and EDID for edp. */
5914 has_dpcd = intel_edp_init_dpcd(intel_dp);
5917 /* if this fails, presume the device is a ghost */
5918 DRM_INFO("failed to retrieve link info, disabling eDP\n");
5922 mutex_lock(&dev->mode_config.mutex);
5923 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
5925 if (drm_add_edid_modes(connector, edid)) {
5926 drm_mode_connector_update_edid_property(connector,
5930 edid = ERR_PTR(-EINVAL);
5933 edid = ERR_PTR(-ENOENT);
5935 intel_connector->edid = edid;
5937 /* prefer fixed mode from EDID if available, save an alt mode also */
5938 list_for_each_entry(scan, &connector->probed_modes, head) {
5939 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5940 fixed_mode = drm_mode_duplicate(dev, scan);
5941 downclock_mode = intel_dp_drrs_init(
5942 intel_connector, fixed_mode);
5943 } else if (!alt_fixed_mode) {
5944 alt_fixed_mode = drm_mode_duplicate(dev, scan);
5948 /* fallback to VBT if available for eDP */
5949 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5950 fixed_mode = drm_mode_duplicate(dev,
5951 dev_priv->vbt.lfp_lvds_vbt_mode);
5953 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
5954 connector->display_info.width_mm = fixed_mode->width_mm;
5955 connector->display_info.height_mm = fixed_mode->height_mm;
5958 mutex_unlock(&dev->mode_config.mutex);
5960 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5961 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5962 register_reboot_notifier(&intel_dp->edp_notifier);
5965 * Figure out the current pipe for the initial backlight setup.
5966 * If the current pipe isn't valid, try the PPS pipe, and if that
5967 * fails just assume pipe A.
5969 pipe = vlv_active_pipe(intel_dp);
5971 if (pipe != PIPE_A && pipe != PIPE_B)
5972 pipe = intel_dp->pps_pipe;
5974 if (pipe != PIPE_A && pipe != PIPE_B)
5977 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5981 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5983 intel_connector->panel.backlight.power = intel_edp_backlight_power;
5984 intel_panel_setup_backlight(connector, pipe);
5989 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5991 * vdd might still be enabled do to the delayed vdd off.
5992 * Make sure vdd is actually turned off here.
5995 edp_panel_vdd_off_sync(intel_dp);
5996 pps_unlock(intel_dp);
6001 /* Set up the hotplug pin and aux power domain. */
6003 intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
6005 struct intel_encoder *encoder = &intel_dig_port->base;
6006 struct intel_dp *intel_dp = &intel_dig_port->dp;
6007 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6008 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
6010 encoder->hpd_pin = intel_hpd_pin_default(dev_priv, encoder->port);
6012 switch (encoder->port) {
6014 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
6017 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
6020 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
6023 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
6026 /* FIXME: Check VBT for actual wiring of PORT E */
6027 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
6030 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_F;
6033 MISSING_CASE(encoder->port);
6037 static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
6039 struct intel_connector *intel_connector;
6040 struct drm_connector *connector;
6042 intel_connector = container_of(work, typeof(*intel_connector),
6043 modeset_retry_work);
6044 connector = &intel_connector->base;
6045 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
6048 /* Grab the locks before changing connector property*/
6049 mutex_lock(&connector->dev->mode_config.mutex);
6050 /* Set connector link status to BAD and send a Uevent to notify
6051 * userspace to do a modeset.
6053 drm_mode_connector_set_link_status_property(connector,
6054 DRM_MODE_LINK_STATUS_BAD);
6055 mutex_unlock(&connector->dev->mode_config.mutex);
6056 /* Send Hotplug uevent so userspace can reprobe */
6057 drm_kms_helper_hotplug_event(connector->dev);
6061 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
6062 struct intel_connector *intel_connector)
6064 struct drm_connector *connector = &intel_connector->base;
6065 struct intel_dp *intel_dp = &intel_dig_port->dp;
6066 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6067 struct drm_device *dev = intel_encoder->base.dev;
6068 struct drm_i915_private *dev_priv = to_i915(dev);
6069 enum port port = intel_encoder->port;
6072 /* Initialize the work for modeset in case of link train failure */
6073 INIT_WORK(&intel_connector->modeset_retry_work,
6074 intel_dp_modeset_retry_work_fn);
6076 if (WARN(intel_dig_port->max_lanes < 1,
6077 "Not enough lanes (%d) for DP on port %c\n",
6078 intel_dig_port->max_lanes, port_name(port)))
6081 intel_dp_set_source_rates(intel_dp);
6083 intel_dp->reset_link_params = true;
6084 intel_dp->pps_pipe = INVALID_PIPE;
6085 intel_dp->active_pipe = INVALID_PIPE;
6087 /* intel_dp vfuncs */
6088 if (INTEL_GEN(dev_priv) >= 9)
6089 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
6090 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
6091 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
6092 else if (HAS_PCH_SPLIT(dev_priv))
6093 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6095 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
6097 if (INTEL_GEN(dev_priv) >= 9)
6098 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6100 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
6102 if (HAS_DDI(dev_priv))
6103 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6105 /* Preserve the current hw state. */
6106 intel_dp->DP = I915_READ(intel_dp->output_reg);
6107 intel_dp->attached_connector = intel_connector;
6109 if (intel_dp_is_port_edp(dev_priv, port))
6110 type = DRM_MODE_CONNECTOR_eDP;
6112 type = DRM_MODE_CONNECTOR_DisplayPort;
6114 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6115 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6118 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6119 * for DP the encoder type can be set by the caller to
6120 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6122 if (type == DRM_MODE_CONNECTOR_eDP)
6123 intel_encoder->type = INTEL_OUTPUT_EDP;
6125 /* eDP only on port B and/or C on vlv/chv */
6126 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
6127 intel_dp_is_edp(intel_dp) &&
6128 port != PORT_B && port != PORT_C))
6131 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6132 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6135 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
6136 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6138 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
6139 connector->interlace_allowed = true;
6140 connector->doublescan_allowed = 0;
6142 intel_dp_init_connector_port_info(intel_dig_port);
6144 intel_dp_aux_init(intel_dp);
6146 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
6147 edp_panel_vdd_work);
6149 intel_connector_attach_encoder(intel_connector, intel_encoder);
6151 if (HAS_DDI(dev_priv))
6152 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6154 intel_connector->get_hw_state = intel_connector_get_hw_state;
6156 /* init MST on ports that can support it */
6157 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
6158 (port == PORT_B || port == PORT_C ||
6159 port == PORT_D || port == PORT_F))
6160 intel_dp_mst_encoder_init(intel_dig_port,
6161 intel_connector->base.base.id);
6163 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
6164 intel_dp_aux_fini(intel_dp);
6165 intel_dp_mst_encoder_cleanup(intel_dig_port);
6169 intel_dp_add_properties(intel_dp, connector);
6171 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6172 * 0xd. Failure to do so will result in spurious interrupts being
6173 * generated on the port when a cable is not attached.
6175 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
6176 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6177 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6183 drm_connector_cleanup(connector);
6188 bool intel_dp_init(struct drm_i915_private *dev_priv,
6189 i915_reg_t output_reg,
6192 struct intel_digital_port *intel_dig_port;
6193 struct intel_encoder *intel_encoder;
6194 struct drm_encoder *encoder;
6195 struct intel_connector *intel_connector;
6197 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
6198 if (!intel_dig_port)
6201 intel_connector = intel_connector_alloc();
6202 if (!intel_connector)
6203 goto err_connector_alloc;
6205 intel_encoder = &intel_dig_port->base;
6206 encoder = &intel_encoder->base;
6208 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6209 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6210 "DP %c", port_name(port)))
6211 goto err_encoder_init;
6213 intel_encoder->compute_config = intel_dp_compute_config;
6214 intel_encoder->get_hw_state = intel_dp_get_hw_state;
6215 intel_encoder->get_config = intel_dp_get_config;
6216 intel_encoder->suspend = intel_dp_encoder_suspend;
6217 if (IS_CHERRYVIEW(dev_priv)) {
6218 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
6219 intel_encoder->pre_enable = chv_pre_enable_dp;
6220 intel_encoder->enable = vlv_enable_dp;
6221 intel_encoder->disable = vlv_disable_dp;
6222 intel_encoder->post_disable = chv_post_disable_dp;
6223 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
6224 } else if (IS_VALLEYVIEW(dev_priv)) {
6225 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
6226 intel_encoder->pre_enable = vlv_pre_enable_dp;
6227 intel_encoder->enable = vlv_enable_dp;
6228 intel_encoder->disable = vlv_disable_dp;
6229 intel_encoder->post_disable = vlv_post_disable_dp;
6230 } else if (INTEL_GEN(dev_priv) >= 5) {
6231 intel_encoder->pre_enable = g4x_pre_enable_dp;
6232 intel_encoder->enable = g4x_enable_dp;
6233 intel_encoder->disable = ilk_disable_dp;
6234 intel_encoder->post_disable = ilk_post_disable_dp;
6236 intel_encoder->pre_enable = g4x_pre_enable_dp;
6237 intel_encoder->enable = g4x_enable_dp;
6238 intel_encoder->disable = g4x_disable_dp;
6241 intel_dig_port->dp.output_reg = output_reg;
6242 intel_dig_port->max_lanes = 4;
6244 intel_encoder->type = INTEL_OUTPUT_DP;
6245 intel_encoder->power_domain = intel_port_to_power_domain(port);
6246 if (IS_CHERRYVIEW(dev_priv)) {
6248 intel_encoder->crtc_mask = 1 << 2;
6250 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6252 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6254 intel_encoder->cloneable = 0;
6255 intel_encoder->port = port;
6257 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
6258 dev_priv->hotplug.irq_port[port] = intel_dig_port;
6261 intel_infoframe_init(intel_dig_port);
6263 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6264 goto err_init_connector;
6269 drm_encoder_cleanup(encoder);
6271 kfree(intel_connector);
6272 err_connector_alloc:
6273 kfree(intel_dig_port);
6277 void intel_dp_mst_suspend(struct drm_device *dev)
6279 struct drm_i915_private *dev_priv = to_i915(dev);
6283 for (i = 0; i < I915_MAX_PORTS; i++) {
6284 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6286 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6289 if (intel_dig_port->dp.is_mst)
6290 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
6294 void intel_dp_mst_resume(struct drm_device *dev)
6296 struct drm_i915_private *dev_priv = to_i915(dev);
6299 for (i = 0; i < I915_MAX_PORTS; i++) {
6300 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6303 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6306 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6308 intel_dp_check_mst_status(&intel_dig_port->dp);