bpf: Prevent memory disambiguation attack
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / intel_dp.c
blob79521da5d11ddbffa3c5f402ff74595ed103f225
1 /*
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
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
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>
35 #include <drm/drmP.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>
42 #include "i915_drv.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)
53 struct dp_link_dpll {
54 int clock;
55 struct dpll dpll;
58 static const struct dp_link_dpll gen4_dpll[] = {
59 { 162000,
60 { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
61 { 270000,
62 { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
65 static const struct dp_link_dpll pch_dpll[] = {
66 { 162000,
67 { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
68 { 270000,
69 { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
72 static const struct dp_link_dpll vlv_dpll[] = {
73 { 162000,
74 { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
75 { 270000,
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,
103 648000, 810000 };
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,
139 enum pipe pipe);
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)
145 int i, max_rate;
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)
151 break;
152 intel_dp->sink_rates[i] = default_rates[i];
155 intel_dp->num_sink_rates = i;
158 /* Theoretical max between source and sink */
159 static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
161 return intel_dp->common_rates[intel_dp->num_common_rates - 1];
164 /* Theoretical max between source and sink */
165 static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
167 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
168 int source_max = intel_dig_port->max_lanes;
169 int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
171 return min(source_max, sink_max);
174 int intel_dp_max_lane_count(struct intel_dp *intel_dp)
176 return intel_dp->max_link_lane_count;
180 intel_dp_link_required(int pixel_clock, int bpp)
182 /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
183 return DIV_ROUND_UP(pixel_clock * bpp, 8);
187 intel_dp_max_data_rate(int max_link_clock, int max_lanes)
189 /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
190 * link rate that is generally expressed in Gbps. Since, 8 bits of data
191 * is transmitted every LS_Clk per lane, there is no need to account for
192 * the channel encoding that is done in the PHY layer here.
195 return max_link_clock * max_lanes;
198 static int
199 intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
201 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
202 struct intel_encoder *encoder = &intel_dig_port->base;
203 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
204 int max_dotclk = dev_priv->max_dotclk_freq;
205 int ds_max_dotclk;
207 int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
209 if (type != DP_DS_PORT_TYPE_VGA)
210 return max_dotclk;
212 ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
213 intel_dp->downstream_ports);
215 if (ds_max_dotclk != 0)
216 max_dotclk = min(max_dotclk, ds_max_dotclk);
218 return max_dotclk;
221 static void
222 intel_dp_set_source_rates(struct intel_dp *intel_dp)
224 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
225 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
226 enum port port = dig_port->base.port;
227 const int *source_rates;
228 int size;
229 u32 voltage;
231 /* This should only be done once */
232 WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
234 if (IS_GEN9_LP(dev_priv)) {
235 source_rates = bxt_rates;
236 size = ARRAY_SIZE(bxt_rates);
237 } else if (IS_CANNONLAKE(dev_priv)) {
238 source_rates = cnl_rates;
239 size = ARRAY_SIZE(cnl_rates);
240 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
241 if (port == PORT_A || port == PORT_D ||
242 voltage == VOLTAGE_INFO_0_85V)
243 size -= 2;
244 } else if (IS_GEN9_BC(dev_priv)) {
245 source_rates = skl_rates;
246 size = ARRAY_SIZE(skl_rates);
247 } else if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
248 IS_BROADWELL(dev_priv)) {
249 source_rates = default_rates;
250 size = ARRAY_SIZE(default_rates);
251 } else {
252 source_rates = default_rates;
253 size = ARRAY_SIZE(default_rates) - 1;
256 intel_dp->source_rates = source_rates;
257 intel_dp->num_source_rates = size;
260 static int intersect_rates(const int *source_rates, int source_len,
261 const int *sink_rates, int sink_len,
262 int *common_rates)
264 int i = 0, j = 0, k = 0;
266 while (i < source_len && j < sink_len) {
267 if (source_rates[i] == sink_rates[j]) {
268 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
269 return k;
270 common_rates[k] = source_rates[i];
271 ++k;
272 ++i;
273 ++j;
274 } else if (source_rates[i] < sink_rates[j]) {
275 ++i;
276 } else {
277 ++j;
280 return k;
283 /* return index of rate in rates array, or -1 if not found */
284 static int intel_dp_rate_index(const int *rates, int len, int rate)
286 int i;
288 for (i = 0; i < len; i++)
289 if (rate == rates[i])
290 return i;
292 return -1;
295 static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
297 WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
299 intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
300 intel_dp->num_source_rates,
301 intel_dp->sink_rates,
302 intel_dp->num_sink_rates,
303 intel_dp->common_rates);
305 /* Paranoia, there should always be something in common. */
306 if (WARN_ON(intel_dp->num_common_rates == 0)) {
307 intel_dp->common_rates[0] = default_rates[0];
308 intel_dp->num_common_rates = 1;
312 /* get length of common rates potentially limited by max_rate */
313 static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
314 int max_rate)
316 const int *common_rates = intel_dp->common_rates;
317 int i, common_len = intel_dp->num_common_rates;
319 /* Limit results by potentially reduced max rate */
320 for (i = 0; i < common_len; i++) {
321 if (common_rates[common_len - i - 1] <= max_rate)
322 return common_len - i;
325 return 0;
328 static bool intel_dp_link_params_valid(struct intel_dp *intel_dp, int link_rate,
329 uint8_t lane_count)
332 * FIXME: we need to synchronize the current link parameters with
333 * hardware readout. Currently fast link training doesn't work on
334 * boot-up.
336 if (link_rate == 0 ||
337 link_rate > intel_dp->max_link_rate)
338 return false;
340 if (lane_count == 0 ||
341 lane_count > intel_dp_max_lane_count(intel_dp))
342 return false;
344 return true;
347 int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
348 int link_rate, uint8_t lane_count)
350 int index;
352 index = intel_dp_rate_index(intel_dp->common_rates,
353 intel_dp->num_common_rates,
354 link_rate);
355 if (index > 0) {
356 intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
357 intel_dp->max_link_lane_count = lane_count;
358 } else if (lane_count > 1) {
359 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
360 intel_dp->max_link_lane_count = lane_count >> 1;
361 } else {
362 DRM_ERROR("Link Training Unsuccessful\n");
363 return -1;
366 return 0;
369 static enum drm_mode_status
370 intel_dp_mode_valid(struct drm_connector *connector,
371 struct drm_display_mode *mode)
373 struct intel_dp *intel_dp = intel_attached_dp(connector);
374 struct intel_connector *intel_connector = to_intel_connector(connector);
375 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
376 int target_clock = mode->clock;
377 int max_rate, mode_rate, max_lanes, max_link_clock;
378 int max_dotclk;
380 max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
382 if (intel_dp_is_edp(intel_dp) && fixed_mode) {
383 if (mode->hdisplay > fixed_mode->hdisplay)
384 return MODE_PANEL;
386 if (mode->vdisplay > fixed_mode->vdisplay)
387 return MODE_PANEL;
389 target_clock = fixed_mode->clock;
392 max_link_clock = intel_dp_max_link_rate(intel_dp);
393 max_lanes = intel_dp_max_lane_count(intel_dp);
395 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
396 mode_rate = intel_dp_link_required(target_clock, 18);
398 if (mode_rate > max_rate || target_clock > max_dotclk)
399 return MODE_CLOCK_HIGH;
401 if (mode->clock < 10000)
402 return MODE_CLOCK_LOW;
404 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
405 return MODE_H_ILLEGAL;
407 return MODE_OK;
410 uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
412 int i;
413 uint32_t v = 0;
415 if (src_bytes > 4)
416 src_bytes = 4;
417 for (i = 0; i < src_bytes; i++)
418 v |= ((uint32_t) src[i]) << ((3-i) * 8);
419 return v;
422 static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
424 int i;
425 if (dst_bytes > 4)
426 dst_bytes = 4;
427 for (i = 0; i < dst_bytes; i++)
428 dst[i] = src >> ((3-i) * 8);
431 static void
432 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp);
433 static void
434 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
435 bool force_disable_vdd);
436 static void
437 intel_dp_pps_init(struct intel_dp *intel_dp);
439 static void pps_lock(struct intel_dp *intel_dp)
441 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
444 * See intel_power_sequencer_reset() why we need
445 * a power domain reference here.
447 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
449 mutex_lock(&dev_priv->pps_mutex);
452 static void pps_unlock(struct intel_dp *intel_dp)
454 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
456 mutex_unlock(&dev_priv->pps_mutex);
458 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
461 static void
462 vlv_power_sequencer_kick(struct intel_dp *intel_dp)
464 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
465 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
466 enum pipe pipe = intel_dp->pps_pipe;
467 bool pll_enabled, release_cl_override = false;
468 enum dpio_phy phy = DPIO_PHY(pipe);
469 enum dpio_channel ch = vlv_pipe_to_channel(pipe);
470 uint32_t DP;
472 if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
473 "skipping pipe %c power seqeuncer kick due to port %c being active\n",
474 pipe_name(pipe), port_name(intel_dig_port->base.port)))
475 return;
477 DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
478 pipe_name(pipe), port_name(intel_dig_port->base.port));
480 /* Preserve the BIOS-computed detected bit. This is
481 * supposed to be read-only.
483 DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
484 DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
485 DP |= DP_PORT_WIDTH(1);
486 DP |= DP_LINK_TRAIN_PAT_1;
488 if (IS_CHERRYVIEW(dev_priv))
489 DP |= DP_PIPE_SELECT_CHV(pipe);
490 else if (pipe == PIPE_B)
491 DP |= DP_PIPEB_SELECT;
493 pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
496 * The DPLL for the pipe must be enabled for this to work.
497 * So enable temporarily it if it's not already enabled.
499 if (!pll_enabled) {
500 release_cl_override = IS_CHERRYVIEW(dev_priv) &&
501 !chv_phy_powergate_ch(dev_priv, phy, ch, true);
503 if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
504 &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
505 DRM_ERROR("Failed to force on pll for pipe %c!\n",
506 pipe_name(pipe));
507 return;
512 * Similar magic as in intel_dp_enable_port().
513 * We _must_ do this port enable + disable trick
514 * to make this power seqeuencer lock onto the port.
515 * Otherwise even VDD force bit won't work.
517 I915_WRITE(intel_dp->output_reg, DP);
518 POSTING_READ(intel_dp->output_reg);
520 I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
521 POSTING_READ(intel_dp->output_reg);
523 I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
524 POSTING_READ(intel_dp->output_reg);
526 if (!pll_enabled) {
527 vlv_force_pll_off(dev_priv, pipe);
529 if (release_cl_override)
530 chv_phy_powergate_ch(dev_priv, phy, ch, false);
534 static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
536 struct intel_encoder *encoder;
537 unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
540 * We don't have power sequencer currently.
541 * Pick one that's not used by other ports.
543 for_each_intel_encoder(&dev_priv->drm, encoder) {
544 struct intel_dp *intel_dp;
546 if (encoder->type != INTEL_OUTPUT_DP &&
547 encoder->type != INTEL_OUTPUT_EDP)
548 continue;
550 intel_dp = enc_to_intel_dp(&encoder->base);
552 if (encoder->type == INTEL_OUTPUT_EDP) {
553 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
554 intel_dp->active_pipe != intel_dp->pps_pipe);
556 if (intel_dp->pps_pipe != INVALID_PIPE)
557 pipes &= ~(1 << intel_dp->pps_pipe);
558 } else {
559 WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
561 if (intel_dp->active_pipe != INVALID_PIPE)
562 pipes &= ~(1 << intel_dp->active_pipe);
566 if (pipes == 0)
567 return INVALID_PIPE;
569 return ffs(pipes) - 1;
572 static enum pipe
573 vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
575 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
576 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
577 enum pipe pipe;
579 lockdep_assert_held(&dev_priv->pps_mutex);
581 /* We should never land here with regular DP ports */
582 WARN_ON(!intel_dp_is_edp(intel_dp));
584 WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
585 intel_dp->active_pipe != intel_dp->pps_pipe);
587 if (intel_dp->pps_pipe != INVALID_PIPE)
588 return intel_dp->pps_pipe;
590 pipe = vlv_find_free_pps(dev_priv);
593 * Didn't find one. This should not happen since there
594 * are two power sequencers and up to two eDP ports.
596 if (WARN_ON(pipe == INVALID_PIPE))
597 pipe = PIPE_A;
599 vlv_steal_power_sequencer(dev_priv, pipe);
600 intel_dp->pps_pipe = pipe;
602 DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
603 pipe_name(intel_dp->pps_pipe),
604 port_name(intel_dig_port->base.port));
606 /* init power sequencer on this pipe and port */
607 intel_dp_init_panel_power_sequencer(intel_dp);
608 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
611 * Even vdd force doesn't work until we've made
612 * the power sequencer lock in on the port.
614 vlv_power_sequencer_kick(intel_dp);
616 return intel_dp->pps_pipe;
619 static int
620 bxt_power_sequencer_idx(struct intel_dp *intel_dp)
622 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
623 int backlight_controller = dev_priv->vbt.backlight.controller;
625 lockdep_assert_held(&dev_priv->pps_mutex);
627 /* We should never land here with regular DP ports */
628 WARN_ON(!intel_dp_is_edp(intel_dp));
630 if (!intel_dp->pps_reset)
631 return backlight_controller;
633 intel_dp->pps_reset = false;
636 * Only the HW needs to be reprogrammed, the SW state is fixed and
637 * has been setup during connector init.
639 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
641 return backlight_controller;
644 typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
645 enum pipe pipe);
647 static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
648 enum pipe pipe)
650 return I915_READ(PP_STATUS(pipe)) & PP_ON;
653 static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
654 enum pipe pipe)
656 return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
659 static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
660 enum pipe pipe)
662 return true;
665 static enum pipe
666 vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
667 enum port port,
668 vlv_pipe_check pipe_check)
670 enum pipe pipe;
672 for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
673 u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
674 PANEL_PORT_SELECT_MASK;
676 if (port_sel != PANEL_PORT_SELECT_VLV(port))
677 continue;
679 if (!pipe_check(dev_priv, pipe))
680 continue;
682 return pipe;
685 return INVALID_PIPE;
688 static void
689 vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
691 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
692 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
693 enum port port = intel_dig_port->base.port;
695 lockdep_assert_held(&dev_priv->pps_mutex);
697 /* try to find a pipe with this port selected */
698 /* first pick one where the panel is on */
699 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
700 vlv_pipe_has_pp_on);
701 /* didn't find one? pick one where vdd is on */
702 if (intel_dp->pps_pipe == INVALID_PIPE)
703 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
704 vlv_pipe_has_vdd_on);
705 /* didn't find one? pick one with just the correct port */
706 if (intel_dp->pps_pipe == INVALID_PIPE)
707 intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
708 vlv_pipe_any);
710 /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
711 if (intel_dp->pps_pipe == INVALID_PIPE) {
712 DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
713 port_name(port));
714 return;
717 DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
718 port_name(port), pipe_name(intel_dp->pps_pipe));
720 intel_dp_init_panel_power_sequencer(intel_dp);
721 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
724 void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
726 struct intel_encoder *encoder;
728 if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
729 !IS_GEN9_LP(dev_priv)))
730 return;
733 * We can't grab pps_mutex here due to deadlock with power_domain
734 * mutex when power_domain functions are called while holding pps_mutex.
735 * That also means that in order to use pps_pipe the code needs to
736 * hold both a power domain reference and pps_mutex, and the power domain
737 * reference get/put must be done while _not_ holding pps_mutex.
738 * pps_{lock,unlock}() do these steps in the correct order, so one
739 * should use them always.
742 for_each_intel_encoder(&dev_priv->drm, encoder) {
743 struct intel_dp *intel_dp;
745 if (encoder->type != INTEL_OUTPUT_DP &&
746 encoder->type != INTEL_OUTPUT_EDP &&
747 encoder->type != INTEL_OUTPUT_DDI)
748 continue;
750 intel_dp = enc_to_intel_dp(&encoder->base);
752 /* Skip pure DVI/HDMI DDI encoders */
753 if (!i915_mmio_reg_valid(intel_dp->output_reg))
754 continue;
756 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
758 if (encoder->type != INTEL_OUTPUT_EDP)
759 continue;
761 if (IS_GEN9_LP(dev_priv))
762 intel_dp->pps_reset = true;
763 else
764 intel_dp->pps_pipe = INVALID_PIPE;
768 struct pps_registers {
769 i915_reg_t pp_ctrl;
770 i915_reg_t pp_stat;
771 i915_reg_t pp_on;
772 i915_reg_t pp_off;
773 i915_reg_t pp_div;
776 static void intel_pps_get_registers(struct intel_dp *intel_dp,
777 struct pps_registers *regs)
779 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
780 int pps_idx = 0;
782 memset(regs, 0, sizeof(*regs));
784 if (IS_GEN9_LP(dev_priv))
785 pps_idx = bxt_power_sequencer_idx(intel_dp);
786 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
787 pps_idx = vlv_power_sequencer_pipe(intel_dp);
789 regs->pp_ctrl = PP_CONTROL(pps_idx);
790 regs->pp_stat = PP_STATUS(pps_idx);
791 regs->pp_on = PP_ON_DELAYS(pps_idx);
792 regs->pp_off = PP_OFF_DELAYS(pps_idx);
793 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv))
794 regs->pp_div = PP_DIVISOR(pps_idx);
797 static i915_reg_t
798 _pp_ctrl_reg(struct intel_dp *intel_dp)
800 struct pps_registers regs;
802 intel_pps_get_registers(intel_dp, &regs);
804 return regs.pp_ctrl;
807 static i915_reg_t
808 _pp_stat_reg(struct intel_dp *intel_dp)
810 struct pps_registers regs;
812 intel_pps_get_registers(intel_dp, &regs);
814 return regs.pp_stat;
817 /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
818 This function only applicable when panel PM state is not to be tracked */
819 static int edp_notify_handler(struct notifier_block *this, unsigned long code,
820 void *unused)
822 struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
823 edp_notifier);
824 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
826 if (!intel_dp_is_edp(intel_dp) || code != SYS_RESTART)
827 return 0;
829 pps_lock(intel_dp);
831 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
832 enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
833 i915_reg_t pp_ctrl_reg, pp_div_reg;
834 u32 pp_div;
836 pp_ctrl_reg = PP_CONTROL(pipe);
837 pp_div_reg = PP_DIVISOR(pipe);
838 pp_div = I915_READ(pp_div_reg);
839 pp_div &= PP_REFERENCE_DIVIDER_MASK;
841 /* 0x1F write to PP_DIV_REG sets max cycle delay */
842 I915_WRITE(pp_div_reg, pp_div | 0x1F);
843 I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
844 msleep(intel_dp->panel_power_cycle_delay);
847 pps_unlock(intel_dp);
849 return 0;
852 static bool edp_have_panel_power(struct intel_dp *intel_dp)
854 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
856 lockdep_assert_held(&dev_priv->pps_mutex);
858 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
859 intel_dp->pps_pipe == INVALID_PIPE)
860 return false;
862 return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
865 static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
867 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
869 lockdep_assert_held(&dev_priv->pps_mutex);
871 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
872 intel_dp->pps_pipe == INVALID_PIPE)
873 return false;
875 return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
878 static void
879 intel_dp_check_edp(struct intel_dp *intel_dp)
881 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
883 if (!intel_dp_is_edp(intel_dp))
884 return;
886 if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
887 WARN(1, "eDP powered off while attempting aux channel communication.\n");
888 DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
889 I915_READ(_pp_stat_reg(intel_dp)),
890 I915_READ(_pp_ctrl_reg(intel_dp)));
894 static uint32_t
895 intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
897 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
898 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
899 uint32_t status;
900 bool done;
902 #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
903 if (has_aux_irq)
904 done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
905 msecs_to_jiffies_timeout(10));
906 else
907 done = wait_for(C, 10) == 0;
908 if (!done)
909 DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
910 has_aux_irq);
911 #undef C
913 return status;
916 static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
918 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
919 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
921 if (index)
922 return 0;
925 * The clock divider is based off the hrawclk, and would like to run at
926 * 2MHz. So, take the hrawclk value and divide by 2000 and use that
928 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
931 static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
933 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
934 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
936 if (index)
937 return 0;
940 * The clock divider is based off the cdclk or PCH rawclk, and would
941 * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
942 * divide by 2000 and use that
944 if (intel_dig_port->base.port == PORT_A)
945 return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
946 else
947 return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
950 static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
952 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
953 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
955 if (intel_dig_port->base.port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
956 /* Workaround for non-ULT HSW */
957 switch (index) {
958 case 0: return 63;
959 case 1: return 72;
960 default: return 0;
964 return ilk_get_aux_clock_divider(intel_dp, index);
967 static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
970 * SKL doesn't need us to program the AUX clock divider (Hardware will
971 * derive the clock from CDCLK automatically). We still implement the
972 * get_aux_clock_divider vfunc to plug-in into the existing code.
974 return index ? 0 : 1;
977 static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
978 bool has_aux_irq,
979 int send_bytes,
980 uint32_t aux_clock_divider)
982 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
983 struct drm_i915_private *dev_priv =
984 to_i915(intel_dig_port->base.base.dev);
985 uint32_t precharge, timeout;
987 if (IS_GEN6(dev_priv))
988 precharge = 3;
989 else
990 precharge = 5;
992 if (IS_BROADWELL(dev_priv))
993 timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
994 else
995 timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
997 return DP_AUX_CH_CTL_SEND_BUSY |
998 DP_AUX_CH_CTL_DONE |
999 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1000 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1001 timeout |
1002 DP_AUX_CH_CTL_RECEIVE_ERROR |
1003 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1004 (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
1005 (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
1008 static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
1009 bool has_aux_irq,
1010 int send_bytes,
1011 uint32_t unused)
1013 return DP_AUX_CH_CTL_SEND_BUSY |
1014 DP_AUX_CH_CTL_DONE |
1015 (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
1016 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1017 DP_AUX_CH_CTL_TIME_OUT_MAX |
1018 DP_AUX_CH_CTL_RECEIVE_ERROR |
1019 (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
1020 DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
1021 DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
1024 static int
1025 intel_dp_aux_ch(struct intel_dp *intel_dp,
1026 const uint8_t *send, int send_bytes,
1027 uint8_t *recv, int recv_size)
1029 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1030 struct drm_i915_private *dev_priv =
1031 to_i915(intel_dig_port->base.base.dev);
1032 i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
1033 uint32_t aux_clock_divider;
1034 int i, ret, recv_bytes;
1035 uint32_t status;
1036 int try, clock = 0;
1037 bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
1038 bool vdd;
1040 pps_lock(intel_dp);
1043 * We will be called with VDD already enabled for dpcd/edid/oui reads.
1044 * In such cases we want to leave VDD enabled and it's up to upper layers
1045 * to turn it off. But for eg. i2c-dev access we need to turn it on/off
1046 * ourselves.
1048 vdd = edp_panel_vdd_on(intel_dp);
1050 /* dp aux is extremely sensitive to irq latency, hence request the
1051 * lowest possible wakeup latency and so prevent the cpu from going into
1052 * deep sleep states.
1054 pm_qos_update_request(&dev_priv->pm_qos, 0);
1056 intel_dp_check_edp(intel_dp);
1058 /* Try to wait for any previous AUX channel activity */
1059 for (try = 0; try < 3; try++) {
1060 status = I915_READ_NOTRACE(ch_ctl);
1061 if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
1062 break;
1063 msleep(1);
1066 if (try == 3) {
1067 static u32 last_status = -1;
1068 const u32 status = I915_READ(ch_ctl);
1070 if (status != last_status) {
1071 WARN(1, "dp_aux_ch not started status 0x%08x\n",
1072 status);
1073 last_status = status;
1076 ret = -EBUSY;
1077 goto out;
1080 /* Only 5 data registers! */
1081 if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
1082 ret = -E2BIG;
1083 goto out;
1086 while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
1087 u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
1088 has_aux_irq,
1089 send_bytes,
1090 aux_clock_divider);
1092 /* Must try at least 3 times according to DP spec */
1093 for (try = 0; try < 5; try++) {
1094 /* Load the send data into the aux channel data registers */
1095 for (i = 0; i < send_bytes; i += 4)
1096 I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
1097 intel_dp_pack_aux(send + i,
1098 send_bytes - i));
1100 /* Send the command and wait for it to complete */
1101 I915_WRITE(ch_ctl, send_ctl);
1103 status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
1105 /* Clear done status and any errors */
1106 I915_WRITE(ch_ctl,
1107 status |
1108 DP_AUX_CH_CTL_DONE |
1109 DP_AUX_CH_CTL_TIME_OUT_ERROR |
1110 DP_AUX_CH_CTL_RECEIVE_ERROR);
1112 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
1113 continue;
1115 /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
1116 * 400us delay required for errors and timeouts
1117 * Timeout errors from the HW already meet this
1118 * requirement so skip to next iteration
1120 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1121 usleep_range(400, 500);
1122 continue;
1124 if (status & DP_AUX_CH_CTL_DONE)
1125 goto done;
1129 if ((status & DP_AUX_CH_CTL_DONE) == 0) {
1130 DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
1131 ret = -EBUSY;
1132 goto out;
1135 done:
1136 /* Check for timeout or receive error.
1137 * Timeouts occur when the sink is not connected
1139 if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
1140 DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
1141 ret = -EIO;
1142 goto out;
1145 /* Timeouts occur when the device isn't connected, so they're
1146 * "normal" -- don't fill the kernel log with these */
1147 if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
1148 DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
1149 ret = -ETIMEDOUT;
1150 goto out;
1153 /* Unload any bytes sent back from the other side */
1154 recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
1155 DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
1158 * By BSpec: "Message sizes of 0 or >20 are not allowed."
1159 * We have no idea of what happened so we return -EBUSY so
1160 * drm layer takes care for the necessary retries.
1162 if (recv_bytes == 0 || recv_bytes > 20) {
1163 DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
1164 recv_bytes);
1166 * FIXME: This patch was created on top of a series that
1167 * organize the retries at drm level. There EBUSY should
1168 * also take care for 1ms wait before retrying.
1169 * That aux retries re-org is still needed and after that is
1170 * merged we remove this sleep from here.
1172 usleep_range(1000, 1500);
1173 ret = -EBUSY;
1174 goto out;
1177 if (recv_bytes > recv_size)
1178 recv_bytes = recv_size;
1180 for (i = 0; i < recv_bytes; i += 4)
1181 intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
1182 recv + i, recv_bytes - i);
1184 ret = recv_bytes;
1185 out:
1186 pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
1188 if (vdd)
1189 edp_panel_vdd_off(intel_dp, false);
1191 pps_unlock(intel_dp);
1193 return ret;
1196 #define BARE_ADDRESS_SIZE 3
1197 #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
1198 static ssize_t
1199 intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1201 struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
1202 uint8_t txbuf[20], rxbuf[20];
1203 size_t txsize, rxsize;
1204 int ret;
1206 txbuf[0] = (msg->request << 4) |
1207 ((msg->address >> 16) & 0xf);
1208 txbuf[1] = (msg->address >> 8) & 0xff;
1209 txbuf[2] = msg->address & 0xff;
1210 txbuf[3] = msg->size - 1;
1212 switch (msg->request & ~DP_AUX_I2C_MOT) {
1213 case DP_AUX_NATIVE_WRITE:
1214 case DP_AUX_I2C_WRITE:
1215 case DP_AUX_I2C_WRITE_STATUS_UPDATE:
1216 txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
1217 rxsize = 2; /* 0 or 1 data bytes */
1219 if (WARN_ON(txsize > 20))
1220 return -E2BIG;
1222 WARN_ON(!msg->buffer != !msg->size);
1224 if (msg->buffer)
1225 memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
1227 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1228 if (ret > 0) {
1229 msg->reply = rxbuf[0] >> 4;
1231 if (ret > 1) {
1232 /* Number of bytes written in a short write. */
1233 ret = clamp_t(int, rxbuf[1], 0, msg->size);
1234 } else {
1235 /* Return payload size. */
1236 ret = msg->size;
1239 break;
1241 case DP_AUX_NATIVE_READ:
1242 case DP_AUX_I2C_READ:
1243 txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
1244 rxsize = msg->size + 1;
1246 if (WARN_ON(rxsize > 20))
1247 return -E2BIG;
1249 ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
1250 if (ret > 0) {
1251 msg->reply = rxbuf[0] >> 4;
1253 * Assume happy day, and copy the data. The caller is
1254 * expected to check msg->reply before touching it.
1256 * Return payload size.
1258 ret--;
1259 memcpy(msg->buffer, rxbuf + 1, ret);
1261 break;
1263 default:
1264 ret = -EINVAL;
1265 break;
1268 return ret;
1271 static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1272 enum port port)
1274 const struct ddi_vbt_port_info *info =
1275 &dev_priv->vbt.ddi_port_info[port];
1276 enum port aux_port;
1278 if (!info->alternate_aux_channel) {
1279 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1280 port_name(port), port_name(port));
1281 return port;
1284 switch (info->alternate_aux_channel) {
1285 case DP_AUX_A:
1286 aux_port = PORT_A;
1287 break;
1288 case DP_AUX_B:
1289 aux_port = PORT_B;
1290 break;
1291 case DP_AUX_C:
1292 aux_port = PORT_C;
1293 break;
1294 case DP_AUX_D:
1295 aux_port = PORT_D;
1296 break;
1297 default:
1298 MISSING_CASE(info->alternate_aux_channel);
1299 aux_port = PORT_A;
1300 break;
1303 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1304 port_name(aux_port), port_name(port));
1306 return aux_port;
1309 static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1310 enum port port)
1312 switch (port) {
1313 case PORT_B:
1314 case PORT_C:
1315 case PORT_D:
1316 return DP_AUX_CH_CTL(port);
1317 default:
1318 MISSING_CASE(port);
1319 return DP_AUX_CH_CTL(PORT_B);
1323 static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
1324 enum port port, int index)
1326 switch (port) {
1327 case PORT_B:
1328 case PORT_C:
1329 case PORT_D:
1330 return DP_AUX_CH_DATA(port, index);
1331 default:
1332 MISSING_CASE(port);
1333 return DP_AUX_CH_DATA(PORT_B, index);
1337 static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
1338 enum port port)
1340 switch (port) {
1341 case PORT_A:
1342 return DP_AUX_CH_CTL(port);
1343 case PORT_B:
1344 case PORT_C:
1345 case PORT_D:
1346 return PCH_DP_AUX_CH_CTL(port);
1347 default:
1348 MISSING_CASE(port);
1349 return DP_AUX_CH_CTL(PORT_A);
1353 static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1354 enum port port, int index)
1356 switch (port) {
1357 case PORT_A:
1358 return DP_AUX_CH_DATA(port, index);
1359 case PORT_B:
1360 case PORT_C:
1361 case PORT_D:
1362 return PCH_DP_AUX_CH_DATA(port, index);
1363 default:
1364 MISSING_CASE(port);
1365 return DP_AUX_CH_DATA(PORT_A, index);
1369 static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1370 enum port port)
1372 switch (port) {
1373 case PORT_A:
1374 case PORT_B:
1375 case PORT_C:
1376 case PORT_D:
1377 return DP_AUX_CH_CTL(port);
1378 default:
1379 MISSING_CASE(port);
1380 return DP_AUX_CH_CTL(PORT_A);
1384 static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1385 enum port port, int index)
1387 switch (port) {
1388 case PORT_A:
1389 case PORT_B:
1390 case PORT_C:
1391 case PORT_D:
1392 return DP_AUX_CH_DATA(port, index);
1393 default:
1394 MISSING_CASE(port);
1395 return DP_AUX_CH_DATA(PORT_A, index);
1399 static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
1400 enum port port)
1402 if (INTEL_INFO(dev_priv)->gen >= 9)
1403 return skl_aux_ctl_reg(dev_priv, port);
1404 else if (HAS_PCH_SPLIT(dev_priv))
1405 return ilk_aux_ctl_reg(dev_priv, port);
1406 else
1407 return g4x_aux_ctl_reg(dev_priv, port);
1410 static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1411 enum port port, int index)
1413 if (INTEL_INFO(dev_priv)->gen >= 9)
1414 return skl_aux_data_reg(dev_priv, port, index);
1415 else if (HAS_PCH_SPLIT(dev_priv))
1416 return ilk_aux_data_reg(dev_priv, port, index);
1417 else
1418 return g4x_aux_data_reg(dev_priv, port, index);
1421 static void intel_aux_reg_init(struct intel_dp *intel_dp)
1423 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1424 enum port port = intel_aux_port(dev_priv,
1425 dp_to_dig_port(intel_dp)->base.port);
1426 int i;
1428 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
1429 for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
1430 intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
1433 static void
1434 intel_dp_aux_fini(struct intel_dp *intel_dp)
1436 kfree(intel_dp->aux.name);
1439 static void
1440 intel_dp_aux_init(struct intel_dp *intel_dp)
1442 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
1443 enum port port = intel_dig_port->base.port;
1445 intel_aux_reg_init(intel_dp);
1446 drm_dp_aux_init(&intel_dp->aux);
1448 /* Failure to allocate our preferred name is not critical */
1449 intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
1450 intel_dp->aux.transfer = intel_dp_aux_transfer;
1453 bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
1455 int max_rate = intel_dp->source_rates[intel_dp->num_source_rates - 1];
1457 return max_rate >= 540000;
1460 static void
1461 intel_dp_set_clock(struct intel_encoder *encoder,
1462 struct intel_crtc_state *pipe_config)
1464 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1465 const struct dp_link_dpll *divisor = NULL;
1466 int i, count = 0;
1468 if (IS_G4X(dev_priv)) {
1469 divisor = gen4_dpll;
1470 count = ARRAY_SIZE(gen4_dpll);
1471 } else if (HAS_PCH_SPLIT(dev_priv)) {
1472 divisor = pch_dpll;
1473 count = ARRAY_SIZE(pch_dpll);
1474 } else if (IS_CHERRYVIEW(dev_priv)) {
1475 divisor = chv_dpll;
1476 count = ARRAY_SIZE(chv_dpll);
1477 } else if (IS_VALLEYVIEW(dev_priv)) {
1478 divisor = vlv_dpll;
1479 count = ARRAY_SIZE(vlv_dpll);
1482 if (divisor && count) {
1483 for (i = 0; i < count; i++) {
1484 if (pipe_config->port_clock == divisor[i].clock) {
1485 pipe_config->dpll = divisor[i].dpll;
1486 pipe_config->clock_set = true;
1487 break;
1493 static void snprintf_int_array(char *str, size_t len,
1494 const int *array, int nelem)
1496 int i;
1498 str[0] = '\0';
1500 for (i = 0; i < nelem; i++) {
1501 int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
1502 if (r >= len)
1503 return;
1504 str += r;
1505 len -= r;
1509 static void intel_dp_print_rates(struct intel_dp *intel_dp)
1511 char str[128]; /* FIXME: too big for stack? */
1513 if ((drm_debug & DRM_UT_KMS) == 0)
1514 return;
1516 snprintf_int_array(str, sizeof(str),
1517 intel_dp->source_rates, intel_dp->num_source_rates);
1518 DRM_DEBUG_KMS("source rates: %s\n", str);
1520 snprintf_int_array(str, sizeof(str),
1521 intel_dp->sink_rates, intel_dp->num_sink_rates);
1522 DRM_DEBUG_KMS("sink rates: %s\n", str);
1524 snprintf_int_array(str, sizeof(str),
1525 intel_dp->common_rates, intel_dp->num_common_rates);
1526 DRM_DEBUG_KMS("common rates: %s\n", str);
1530 intel_dp_max_link_rate(struct intel_dp *intel_dp)
1532 int len;
1534 len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
1535 if (WARN_ON(len <= 0))
1536 return 162000;
1538 return intel_dp->common_rates[len - 1];
1541 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
1543 int i = intel_dp_rate_index(intel_dp->sink_rates,
1544 intel_dp->num_sink_rates, rate);
1546 if (WARN_ON(i < 0))
1547 i = 0;
1549 return i;
1552 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
1553 uint8_t *link_bw, uint8_t *rate_select)
1555 /* eDP 1.4 rate select method. */
1556 if (intel_dp->use_rate_select) {
1557 *link_bw = 0;
1558 *rate_select =
1559 intel_dp_rate_select(intel_dp, port_clock);
1560 } else {
1561 *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
1562 *rate_select = 0;
1566 static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
1567 struct intel_crtc_state *pipe_config)
1569 int bpp, bpc;
1571 bpp = pipe_config->pipe_bpp;
1572 bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
1574 if (bpc > 0)
1575 bpp = min(bpp, 3*bpc);
1577 /* For DP Compliance we override the computed bpp for the pipe */
1578 if (intel_dp->compliance.test_data.bpc != 0) {
1579 pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
1580 pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
1581 DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
1582 pipe_config->pipe_bpp);
1584 return bpp;
1587 static bool intel_edp_compare_alt_mode(struct drm_display_mode *m1,
1588 struct drm_display_mode *m2)
1590 bool bres = false;
1592 if (m1 && m2)
1593 bres = (m1->hdisplay == m2->hdisplay &&
1594 m1->hsync_start == m2->hsync_start &&
1595 m1->hsync_end == m2->hsync_end &&
1596 m1->htotal == m2->htotal &&
1597 m1->vdisplay == m2->vdisplay &&
1598 m1->vsync_start == m2->vsync_start &&
1599 m1->vsync_end == m2->vsync_end &&
1600 m1->vtotal == m2->vtotal);
1601 return bres;
1604 bool
1605 intel_dp_compute_config(struct intel_encoder *encoder,
1606 struct intel_crtc_state *pipe_config,
1607 struct drm_connector_state *conn_state)
1609 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1610 struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1611 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1612 enum port port = encoder->port;
1613 struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
1614 struct intel_connector *intel_connector = intel_dp->attached_connector;
1615 struct intel_digital_connector_state *intel_conn_state =
1616 to_intel_digital_connector_state(conn_state);
1617 int lane_count, clock;
1618 int min_lane_count = 1;
1619 int max_lane_count = intel_dp_max_lane_count(intel_dp);
1620 /* Conveniently, the link BW constants become indices with a shift...*/
1621 int min_clock = 0;
1622 int max_clock;
1623 int bpp, mode_rate;
1624 int link_avail, link_clock;
1625 int common_len;
1626 uint8_t link_bw, rate_select;
1627 bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc,
1628 DP_DPCD_QUIRK_LIMITED_M_N);
1630 common_len = intel_dp_common_len_rate_limit(intel_dp,
1631 intel_dp->max_link_rate);
1633 /* No common link rates between source and sink */
1634 WARN_ON(common_len <= 0);
1636 max_clock = common_len - 1;
1638 if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
1639 pipe_config->has_pch_encoder = true;
1641 pipe_config->has_drrs = false;
1642 if (IS_G4X(dev_priv) || port == PORT_A)
1643 pipe_config->has_audio = false;
1644 else if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
1645 pipe_config->has_audio = intel_dp->has_audio;
1646 else
1647 pipe_config->has_audio = intel_conn_state->force_audio == HDMI_AUDIO_ON;
1649 if (intel_dp_is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
1650 struct drm_display_mode *panel_mode =
1651 intel_connector->panel.alt_fixed_mode;
1652 struct drm_display_mode *req_mode = &pipe_config->base.mode;
1654 if (!intel_edp_compare_alt_mode(req_mode, panel_mode))
1655 panel_mode = intel_connector->panel.fixed_mode;
1657 drm_mode_debug_printmodeline(panel_mode);
1659 intel_fixed_panel_mode(panel_mode, adjusted_mode);
1661 if (INTEL_GEN(dev_priv) >= 9) {
1662 int ret;
1663 ret = skl_update_scaler_crtc(pipe_config);
1664 if (ret)
1665 return ret;
1668 if (HAS_GMCH_DISPLAY(dev_priv))
1669 intel_gmch_panel_fitting(intel_crtc, pipe_config,
1670 conn_state->scaling_mode);
1671 else
1672 intel_pch_panel_fitting(intel_crtc, pipe_config,
1673 conn_state->scaling_mode);
1676 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1677 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
1678 return false;
1680 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
1681 return false;
1683 /* Use values requested by Compliance Test Request */
1684 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
1685 int index;
1687 /* Validate the compliance test data since max values
1688 * might have changed due to link train fallback.
1690 if (intel_dp_link_params_valid(intel_dp, intel_dp->compliance.test_link_rate,
1691 intel_dp->compliance.test_lane_count)) {
1692 index = intel_dp_rate_index(intel_dp->common_rates,
1693 intel_dp->num_common_rates,
1694 intel_dp->compliance.test_link_rate);
1695 if (index >= 0)
1696 min_clock = max_clock = index;
1697 min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
1700 DRM_DEBUG_KMS("DP link computation with max lane count %i "
1701 "max bw %d pixel clock %iKHz\n",
1702 max_lane_count, intel_dp->common_rates[max_clock],
1703 adjusted_mode->crtc_clock);
1705 /* Walk through all bpp values. Luckily they're all nicely spaced with 2
1706 * bpc in between. */
1707 bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
1708 if (intel_dp_is_edp(intel_dp)) {
1710 /* Get bpp from vbt only for panels that dont have bpp in edid */
1711 if (intel_connector->base.display_info.bpc == 0 &&
1712 (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
1713 DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
1714 dev_priv->vbt.edp.bpp);
1715 bpp = dev_priv->vbt.edp.bpp;
1719 * Use the maximum clock and number of lanes the eDP panel
1720 * advertizes being capable of. The panels are generally
1721 * designed to support only a single clock and lane
1722 * configuration, and typically these values correspond to the
1723 * native resolution of the panel.
1725 min_lane_count = max_lane_count;
1726 min_clock = max_clock;
1729 for (; bpp >= 6*3; bpp -= 2*3) {
1730 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
1731 bpp);
1733 for (clock = min_clock; clock <= max_clock; clock++) {
1734 for (lane_count = min_lane_count;
1735 lane_count <= max_lane_count;
1736 lane_count <<= 1) {
1738 link_clock = intel_dp->common_rates[clock];
1739 link_avail = intel_dp_max_data_rate(link_clock,
1740 lane_count);
1742 if (mode_rate <= link_avail) {
1743 goto found;
1749 return false;
1751 found:
1752 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
1754 * See:
1755 * CEA-861-E - 5.1 Default Encoding Parameters
1756 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
1758 pipe_config->limited_color_range =
1759 bpp != 18 &&
1760 drm_default_rgb_quant_range(adjusted_mode) ==
1761 HDMI_QUANTIZATION_RANGE_LIMITED;
1762 } else {
1763 pipe_config->limited_color_range =
1764 intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
1767 pipe_config->lane_count = lane_count;
1769 pipe_config->pipe_bpp = bpp;
1770 pipe_config->port_clock = intel_dp->common_rates[clock];
1772 intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
1773 &link_bw, &rate_select);
1775 DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
1776 link_bw, rate_select, pipe_config->lane_count,
1777 pipe_config->port_clock, bpp);
1778 DRM_DEBUG_KMS("DP link bw required %i available %i\n",
1779 mode_rate, link_avail);
1781 intel_link_compute_m_n(bpp, lane_count,
1782 adjusted_mode->crtc_clock,
1783 pipe_config->port_clock,
1784 &pipe_config->dp_m_n,
1785 reduce_m_n);
1787 if (intel_connector->panel.downclock_mode != NULL &&
1788 dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
1789 pipe_config->has_drrs = true;
1790 intel_link_compute_m_n(bpp, lane_count,
1791 intel_connector->panel.downclock_mode->clock,
1792 pipe_config->port_clock,
1793 &pipe_config->dp_m2_n2,
1794 reduce_m_n);
1797 if (!HAS_DDI(dev_priv))
1798 intel_dp_set_clock(encoder, pipe_config);
1800 intel_psr_compute_config(intel_dp, pipe_config);
1802 return true;
1805 void intel_dp_set_link_params(struct intel_dp *intel_dp,
1806 int link_rate, uint8_t lane_count,
1807 bool link_mst)
1809 intel_dp->link_rate = link_rate;
1810 intel_dp->lane_count = lane_count;
1811 intel_dp->link_mst = link_mst;
1814 static void intel_dp_prepare(struct intel_encoder *encoder,
1815 const struct intel_crtc_state *pipe_config)
1817 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1818 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1819 enum port port = encoder->port;
1820 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
1821 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
1823 intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
1824 pipe_config->lane_count,
1825 intel_crtc_has_type(pipe_config,
1826 INTEL_OUTPUT_DP_MST));
1829 * There are four kinds of DP registers:
1831 * IBX PCH
1832 * SNB CPU
1833 * IVB CPU
1834 * CPT PCH
1836 * IBX PCH and CPU are the same for almost everything,
1837 * except that the CPU DP PLL is configured in this
1838 * register
1840 * CPT PCH is quite different, having many bits moved
1841 * to the TRANS_DP_CTL register instead. That
1842 * configuration happens (oddly) in ironlake_pch_enable
1845 /* Preserve the BIOS-computed detected bit. This is
1846 * supposed to be read-only.
1848 intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
1850 /* Handle DP bits in common between all three register formats */
1851 intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
1852 intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
1854 /* Split out the IBX/CPU vs CPT settings */
1856 if (IS_GEN7(dev_priv) && port == PORT_A) {
1857 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1858 intel_dp->DP |= DP_SYNC_HS_HIGH;
1859 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1860 intel_dp->DP |= DP_SYNC_VS_HIGH;
1861 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1863 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1864 intel_dp->DP |= DP_ENHANCED_FRAMING;
1866 intel_dp->DP |= crtc->pipe << 29;
1867 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
1868 u32 trans_dp;
1870 intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
1872 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
1873 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1874 trans_dp |= TRANS_DP_ENH_FRAMING;
1875 else
1876 trans_dp &= ~TRANS_DP_ENH_FRAMING;
1877 I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
1878 } else {
1879 if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
1880 intel_dp->DP |= DP_COLOR_RANGE_16_235;
1882 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
1883 intel_dp->DP |= DP_SYNC_HS_HIGH;
1884 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
1885 intel_dp->DP |= DP_SYNC_VS_HIGH;
1886 intel_dp->DP |= DP_LINK_TRAIN_OFF;
1888 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
1889 intel_dp->DP |= DP_ENHANCED_FRAMING;
1891 if (IS_CHERRYVIEW(dev_priv))
1892 intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
1893 else if (crtc->pipe == PIPE_B)
1894 intel_dp->DP |= DP_PIPEB_SELECT;
1898 #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
1899 #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
1901 #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
1902 #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
1904 #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
1905 #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
1907 static void intel_pps_verify_state(struct intel_dp *intel_dp);
1909 static void wait_panel_status(struct intel_dp *intel_dp,
1910 u32 mask,
1911 u32 value)
1913 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1914 i915_reg_t pp_stat_reg, pp_ctrl_reg;
1916 lockdep_assert_held(&dev_priv->pps_mutex);
1918 intel_pps_verify_state(intel_dp);
1920 pp_stat_reg = _pp_stat_reg(intel_dp);
1921 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1923 DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
1924 mask, value,
1925 I915_READ(pp_stat_reg),
1926 I915_READ(pp_ctrl_reg));
1928 if (intel_wait_for_register(dev_priv,
1929 pp_stat_reg, mask, value,
1930 5000))
1931 DRM_ERROR("Panel status timeout: status %08x control %08x\n",
1932 I915_READ(pp_stat_reg),
1933 I915_READ(pp_ctrl_reg));
1935 DRM_DEBUG_KMS("Wait complete\n");
1938 static void wait_panel_on(struct intel_dp *intel_dp)
1940 DRM_DEBUG_KMS("Wait for panel power on\n");
1941 wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
1944 static void wait_panel_off(struct intel_dp *intel_dp)
1946 DRM_DEBUG_KMS("Wait for panel power off time\n");
1947 wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
1950 static void wait_panel_power_cycle(struct intel_dp *intel_dp)
1952 ktime_t panel_power_on_time;
1953 s64 panel_power_off_duration;
1955 DRM_DEBUG_KMS("Wait for panel power cycle\n");
1957 /* take the difference of currrent time and panel power off time
1958 * and then make panel wait for t11_t12 if needed. */
1959 panel_power_on_time = ktime_get_boottime();
1960 panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
1962 /* When we disable the VDD override bit last we have to do the manual
1963 * wait. */
1964 if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
1965 wait_remaining_ms_from_jiffies(jiffies,
1966 intel_dp->panel_power_cycle_delay - panel_power_off_duration);
1968 wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
1971 static void wait_backlight_on(struct intel_dp *intel_dp)
1973 wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
1974 intel_dp->backlight_on_delay);
1977 static void edp_wait_backlight_off(struct intel_dp *intel_dp)
1979 wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
1980 intel_dp->backlight_off_delay);
1983 /* Read the current pp_control value, unlocking the register if it
1984 * is locked
1987 static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
1989 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1990 u32 control;
1992 lockdep_assert_held(&dev_priv->pps_mutex);
1994 control = I915_READ(_pp_ctrl_reg(intel_dp));
1995 if (WARN_ON(!HAS_DDI(dev_priv) &&
1996 (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
1997 control &= ~PANEL_UNLOCK_MASK;
1998 control |= PANEL_UNLOCK_REGS;
2000 return control;
2004 * Must be paired with edp_panel_vdd_off().
2005 * Must hold pps_mutex around the whole on/off sequence.
2006 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2008 static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
2010 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2011 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2012 u32 pp;
2013 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2014 bool need_to_disable = !intel_dp->want_panel_vdd;
2016 lockdep_assert_held(&dev_priv->pps_mutex);
2018 if (!intel_dp_is_edp(intel_dp))
2019 return false;
2021 cancel_delayed_work(&intel_dp->panel_vdd_work);
2022 intel_dp->want_panel_vdd = true;
2024 if (edp_have_panel_vdd(intel_dp))
2025 return need_to_disable;
2027 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
2029 DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
2030 port_name(intel_dig_port->base.port));
2032 if (!edp_have_panel_power(intel_dp))
2033 wait_panel_power_cycle(intel_dp);
2035 pp = ironlake_get_pp_control(intel_dp);
2036 pp |= EDP_FORCE_VDD;
2038 pp_stat_reg = _pp_stat_reg(intel_dp);
2039 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2041 I915_WRITE(pp_ctrl_reg, pp);
2042 POSTING_READ(pp_ctrl_reg);
2043 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2044 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2046 * If the panel wasn't on, delay before accessing aux channel
2048 if (!edp_have_panel_power(intel_dp)) {
2049 DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
2050 port_name(intel_dig_port->base.port));
2051 msleep(intel_dp->panel_power_up_delay);
2054 return need_to_disable;
2058 * Must be paired with intel_edp_panel_vdd_off() or
2059 * intel_edp_panel_off().
2060 * Nested calls to these functions are not allowed since
2061 * we drop the lock. Caller must use some higher level
2062 * locking to prevent nested calls from other threads.
2064 void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
2066 bool vdd;
2068 if (!intel_dp_is_edp(intel_dp))
2069 return;
2071 pps_lock(intel_dp);
2072 vdd = edp_panel_vdd_on(intel_dp);
2073 pps_unlock(intel_dp);
2075 I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
2076 port_name(dp_to_dig_port(intel_dp)->base.port));
2079 static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
2081 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2082 struct intel_digital_port *intel_dig_port =
2083 dp_to_dig_port(intel_dp);
2084 u32 pp;
2085 i915_reg_t pp_stat_reg, pp_ctrl_reg;
2087 lockdep_assert_held(&dev_priv->pps_mutex);
2089 WARN_ON(intel_dp->want_panel_vdd);
2091 if (!edp_have_panel_vdd(intel_dp))
2092 return;
2094 DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
2095 port_name(intel_dig_port->base.port));
2097 pp = ironlake_get_pp_control(intel_dp);
2098 pp &= ~EDP_FORCE_VDD;
2100 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2101 pp_stat_reg = _pp_stat_reg(intel_dp);
2103 I915_WRITE(pp_ctrl_reg, pp);
2104 POSTING_READ(pp_ctrl_reg);
2106 /* Make sure sequencer is idle before allowing subsequent activity */
2107 DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
2108 I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
2110 if ((pp & PANEL_POWER_ON) == 0)
2111 intel_dp->panel_power_off_time = ktime_get_boottime();
2113 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2116 static void edp_panel_vdd_work(struct work_struct *__work)
2118 struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
2119 struct intel_dp, panel_vdd_work);
2121 pps_lock(intel_dp);
2122 if (!intel_dp->want_panel_vdd)
2123 edp_panel_vdd_off_sync(intel_dp);
2124 pps_unlock(intel_dp);
2127 static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
2129 unsigned long delay;
2132 * Queue the timer to fire a long time from now (relative to the power
2133 * down delay) to keep the panel power up across a sequence of
2134 * operations.
2136 delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
2137 schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
2141 * Must be paired with edp_panel_vdd_on().
2142 * Must hold pps_mutex around the whole on/off sequence.
2143 * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
2145 static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
2147 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2149 lockdep_assert_held(&dev_priv->pps_mutex);
2151 if (!intel_dp_is_edp(intel_dp))
2152 return;
2154 I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
2155 port_name(dp_to_dig_port(intel_dp)->base.port));
2157 intel_dp->want_panel_vdd = false;
2159 if (sync)
2160 edp_panel_vdd_off_sync(intel_dp);
2161 else
2162 edp_panel_vdd_schedule_off(intel_dp);
2165 static void edp_panel_on(struct intel_dp *intel_dp)
2167 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2168 u32 pp;
2169 i915_reg_t pp_ctrl_reg;
2171 lockdep_assert_held(&dev_priv->pps_mutex);
2173 if (!intel_dp_is_edp(intel_dp))
2174 return;
2176 DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
2177 port_name(dp_to_dig_port(intel_dp)->base.port));
2179 if (WARN(edp_have_panel_power(intel_dp),
2180 "eDP port %c panel power already on\n",
2181 port_name(dp_to_dig_port(intel_dp)->base.port)))
2182 return;
2184 wait_panel_power_cycle(intel_dp);
2186 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2187 pp = ironlake_get_pp_control(intel_dp);
2188 if (IS_GEN5(dev_priv)) {
2189 /* ILK workaround: disable reset around power sequence */
2190 pp &= ~PANEL_POWER_RESET;
2191 I915_WRITE(pp_ctrl_reg, pp);
2192 POSTING_READ(pp_ctrl_reg);
2195 pp |= PANEL_POWER_ON;
2196 if (!IS_GEN5(dev_priv))
2197 pp |= PANEL_POWER_RESET;
2199 I915_WRITE(pp_ctrl_reg, pp);
2200 POSTING_READ(pp_ctrl_reg);
2202 wait_panel_on(intel_dp);
2203 intel_dp->last_power_on = jiffies;
2205 if (IS_GEN5(dev_priv)) {
2206 pp |= PANEL_POWER_RESET; /* restore panel reset bit */
2207 I915_WRITE(pp_ctrl_reg, pp);
2208 POSTING_READ(pp_ctrl_reg);
2212 void intel_edp_panel_on(struct intel_dp *intel_dp)
2214 if (!intel_dp_is_edp(intel_dp))
2215 return;
2217 pps_lock(intel_dp);
2218 edp_panel_on(intel_dp);
2219 pps_unlock(intel_dp);
2223 static void edp_panel_off(struct intel_dp *intel_dp)
2225 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2226 u32 pp;
2227 i915_reg_t pp_ctrl_reg;
2229 lockdep_assert_held(&dev_priv->pps_mutex);
2231 if (!intel_dp_is_edp(intel_dp))
2232 return;
2234 DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
2235 port_name(dp_to_dig_port(intel_dp)->base.port));
2237 WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
2238 port_name(dp_to_dig_port(intel_dp)->base.port));
2240 pp = ironlake_get_pp_control(intel_dp);
2241 /* We need to switch off panel power _and_ force vdd, for otherwise some
2242 * panels get very unhappy and cease to work. */
2243 pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
2244 EDP_BLC_ENABLE);
2246 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2248 intel_dp->want_panel_vdd = false;
2250 I915_WRITE(pp_ctrl_reg, pp);
2251 POSTING_READ(pp_ctrl_reg);
2253 wait_panel_off(intel_dp);
2254 intel_dp->panel_power_off_time = ktime_get_boottime();
2256 /* We got a reference when we enabled the VDD. */
2257 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
2260 void intel_edp_panel_off(struct intel_dp *intel_dp)
2262 if (!intel_dp_is_edp(intel_dp))
2263 return;
2265 pps_lock(intel_dp);
2266 edp_panel_off(intel_dp);
2267 pps_unlock(intel_dp);
2270 /* Enable backlight in the panel power control. */
2271 static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
2273 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2274 u32 pp;
2275 i915_reg_t pp_ctrl_reg;
2278 * If we enable the backlight right away following a panel power
2279 * on, we may see slight flicker as the panel syncs with the eDP
2280 * link. So delay a bit to make sure the image is solid before
2281 * allowing it to appear.
2283 wait_backlight_on(intel_dp);
2285 pps_lock(intel_dp);
2287 pp = ironlake_get_pp_control(intel_dp);
2288 pp |= EDP_BLC_ENABLE;
2290 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2292 I915_WRITE(pp_ctrl_reg, pp);
2293 POSTING_READ(pp_ctrl_reg);
2295 pps_unlock(intel_dp);
2298 /* Enable backlight PWM and backlight PP control. */
2299 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state,
2300 const struct drm_connector_state *conn_state)
2302 struct intel_dp *intel_dp = enc_to_intel_dp(conn_state->best_encoder);
2304 if (!intel_dp_is_edp(intel_dp))
2305 return;
2307 DRM_DEBUG_KMS("\n");
2309 intel_panel_enable_backlight(crtc_state, conn_state);
2310 _intel_edp_backlight_on(intel_dp);
2313 /* Disable backlight in the panel power control. */
2314 static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
2316 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2317 u32 pp;
2318 i915_reg_t pp_ctrl_reg;
2320 if (!intel_dp_is_edp(intel_dp))
2321 return;
2323 pps_lock(intel_dp);
2325 pp = ironlake_get_pp_control(intel_dp);
2326 pp &= ~EDP_BLC_ENABLE;
2328 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
2330 I915_WRITE(pp_ctrl_reg, pp);
2331 POSTING_READ(pp_ctrl_reg);
2333 pps_unlock(intel_dp);
2335 intel_dp->last_backlight_off = jiffies;
2336 edp_wait_backlight_off(intel_dp);
2339 /* Disable backlight PP control and backlight PWM. */
2340 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state)
2342 struct intel_dp *intel_dp = enc_to_intel_dp(old_conn_state->best_encoder);
2344 if (!intel_dp_is_edp(intel_dp))
2345 return;
2347 DRM_DEBUG_KMS("\n");
2349 _intel_edp_backlight_off(intel_dp);
2350 intel_panel_disable_backlight(old_conn_state);
2354 * Hook for controlling the panel power control backlight through the bl_power
2355 * sysfs attribute. Take care to handle multiple calls.
2357 static void intel_edp_backlight_power(struct intel_connector *connector,
2358 bool enable)
2360 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
2361 bool is_enabled;
2363 pps_lock(intel_dp);
2364 is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
2365 pps_unlock(intel_dp);
2367 if (is_enabled == enable)
2368 return;
2370 DRM_DEBUG_KMS("panel power control backlight %s\n",
2371 enable ? "enable" : "disable");
2373 if (enable)
2374 _intel_edp_backlight_on(intel_dp);
2375 else
2376 _intel_edp_backlight_off(intel_dp);
2379 static void assert_dp_port(struct intel_dp *intel_dp, bool state)
2381 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
2382 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
2383 bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
2385 I915_STATE_WARN(cur_state != state,
2386 "DP port %c state assertion failure (expected %s, current %s)\n",
2387 port_name(dig_port->base.port),
2388 onoff(state), onoff(cur_state));
2390 #define assert_dp_port_disabled(d) assert_dp_port((d), false)
2392 static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
2394 bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
2396 I915_STATE_WARN(cur_state != state,
2397 "eDP PLL state assertion failure (expected %s, current %s)\n",
2398 onoff(state), onoff(cur_state));
2400 #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
2401 #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
2403 static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
2404 const struct intel_crtc_state *pipe_config)
2406 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2407 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2409 assert_pipe_disabled(dev_priv, crtc->pipe);
2410 assert_dp_port_disabled(intel_dp);
2411 assert_edp_pll_disabled(dev_priv);
2413 DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
2414 pipe_config->port_clock);
2416 intel_dp->DP &= ~DP_PLL_FREQ_MASK;
2418 if (pipe_config->port_clock == 162000)
2419 intel_dp->DP |= DP_PLL_FREQ_162MHZ;
2420 else
2421 intel_dp->DP |= DP_PLL_FREQ_270MHZ;
2423 I915_WRITE(DP_A, intel_dp->DP);
2424 POSTING_READ(DP_A);
2425 udelay(500);
2428 * [DevILK] Work around required when enabling DP PLL
2429 * while a pipe is enabled going to FDI:
2430 * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
2431 * 2. Program DP PLL enable
2433 if (IS_GEN5(dev_priv))
2434 intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
2436 intel_dp->DP |= DP_PLL_ENABLE;
2438 I915_WRITE(DP_A, intel_dp->DP);
2439 POSTING_READ(DP_A);
2440 udelay(200);
2443 static void ironlake_edp_pll_off(struct intel_dp *intel_dp,
2444 const struct intel_crtc_state *old_crtc_state)
2446 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
2447 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2449 assert_pipe_disabled(dev_priv, crtc->pipe);
2450 assert_dp_port_disabled(intel_dp);
2451 assert_edp_pll_enabled(dev_priv);
2453 DRM_DEBUG_KMS("disabling eDP PLL\n");
2455 intel_dp->DP &= ~DP_PLL_ENABLE;
2457 I915_WRITE(DP_A, intel_dp->DP);
2458 POSTING_READ(DP_A);
2459 udelay(200);
2462 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp)
2465 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus
2466 * be capable of signalling downstream hpd with a long pulse.
2467 * Whether or not that means D3 is safe to use is not clear,
2468 * but let's assume so until proven otherwise.
2470 * FIXME should really check all downstream ports...
2472 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 &&
2473 intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT &&
2474 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD;
2477 /* If the sink supports it, try to set the power state appropriately */
2478 void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
2480 int ret, i;
2482 /* Should have a valid DPCD by this point */
2483 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
2484 return;
2486 if (mode != DRM_MODE_DPMS_ON) {
2487 if (downstream_hpd_needs_d0(intel_dp))
2488 return;
2490 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2491 DP_SET_POWER_D3);
2492 } else {
2493 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
2496 * When turning on, we need to retry for 1ms to give the sink
2497 * time to wake up.
2499 for (i = 0; i < 3; i++) {
2500 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
2501 DP_SET_POWER_D0);
2502 if (ret == 1)
2503 break;
2504 msleep(1);
2507 if (ret == 1 && lspcon->active)
2508 lspcon_wait_pcon_mode(lspcon);
2511 if (ret != 1)
2512 DRM_DEBUG_KMS("failed to %s sink power state\n",
2513 mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
2516 static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
2517 enum pipe *pipe)
2519 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2520 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2521 enum port port = encoder->port;
2522 u32 tmp;
2523 bool ret;
2525 if (!intel_display_power_get_if_enabled(dev_priv,
2526 encoder->power_domain))
2527 return false;
2529 ret = false;
2531 tmp = I915_READ(intel_dp->output_reg);
2533 if (!(tmp & DP_PORT_EN))
2534 goto out;
2536 if (IS_GEN7(dev_priv) && port == PORT_A) {
2537 *pipe = PORT_TO_PIPE_CPT(tmp);
2538 } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2539 enum pipe p;
2541 for_each_pipe(dev_priv, p) {
2542 u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
2543 if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
2544 *pipe = p;
2545 ret = true;
2547 goto out;
2551 DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
2552 i915_mmio_reg_offset(intel_dp->output_reg));
2553 } else if (IS_CHERRYVIEW(dev_priv)) {
2554 *pipe = DP_PORT_TO_PIPE_CHV(tmp);
2555 } else {
2556 *pipe = PORT_TO_PIPE(tmp);
2559 ret = true;
2561 out:
2562 intel_display_power_put(dev_priv, encoder->power_domain);
2564 return ret;
2567 static void intel_dp_get_config(struct intel_encoder *encoder,
2568 struct intel_crtc_state *pipe_config)
2570 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2571 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2572 u32 tmp, flags = 0;
2573 enum port port = encoder->port;
2574 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2576 if (encoder->type == INTEL_OUTPUT_EDP)
2577 pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP);
2578 else
2579 pipe_config->output_types |= BIT(INTEL_OUTPUT_DP);
2581 tmp = I915_READ(intel_dp->output_reg);
2583 pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
2585 if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
2586 u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
2588 if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
2589 flags |= DRM_MODE_FLAG_PHSYNC;
2590 else
2591 flags |= DRM_MODE_FLAG_NHSYNC;
2593 if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
2594 flags |= DRM_MODE_FLAG_PVSYNC;
2595 else
2596 flags |= DRM_MODE_FLAG_NVSYNC;
2597 } else {
2598 if (tmp & DP_SYNC_HS_HIGH)
2599 flags |= DRM_MODE_FLAG_PHSYNC;
2600 else
2601 flags |= DRM_MODE_FLAG_NHSYNC;
2603 if (tmp & DP_SYNC_VS_HIGH)
2604 flags |= DRM_MODE_FLAG_PVSYNC;
2605 else
2606 flags |= DRM_MODE_FLAG_NVSYNC;
2609 pipe_config->base.adjusted_mode.flags |= flags;
2611 if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
2612 pipe_config->limited_color_range = true;
2614 pipe_config->lane_count =
2615 ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
2617 intel_dp_get_m_n(crtc, pipe_config);
2619 if (port == PORT_A) {
2620 if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
2621 pipe_config->port_clock = 162000;
2622 else
2623 pipe_config->port_clock = 270000;
2626 pipe_config->base.adjusted_mode.crtc_clock =
2627 intel_dotclock_calculate(pipe_config->port_clock,
2628 &pipe_config->dp_m_n);
2630 if (intel_dp_is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
2631 pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
2633 * This is a big fat ugly hack.
2635 * Some machines in UEFI boot mode provide us a VBT that has 18
2636 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2637 * unknown we fail to light up. Yet the same BIOS boots up with
2638 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2639 * max, not what it tells us to use.
2641 * Note: This will still be broken if the eDP panel is not lit
2642 * up by the BIOS, and thus we can't get the mode at module
2643 * load.
2645 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2646 pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
2647 dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
2651 static void intel_disable_dp(struct intel_encoder *encoder,
2652 const struct intel_crtc_state *old_crtc_state,
2653 const struct drm_connector_state *old_conn_state)
2655 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2657 if (old_crtc_state->has_audio)
2658 intel_audio_codec_disable(encoder,
2659 old_crtc_state, old_conn_state);
2661 /* Make sure the panel is off before trying to change the mode. But also
2662 * ensure that we have vdd while we switch off the panel. */
2663 intel_edp_panel_vdd_on(intel_dp);
2664 intel_edp_backlight_off(old_conn_state);
2665 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
2666 intel_edp_panel_off(intel_dp);
2669 static void g4x_disable_dp(struct intel_encoder *encoder,
2670 const struct intel_crtc_state *old_crtc_state,
2671 const struct drm_connector_state *old_conn_state)
2673 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2675 /* disable the port before the pipe on g4x */
2676 intel_dp_link_down(encoder, old_crtc_state);
2679 static void ilk_disable_dp(struct intel_encoder *encoder,
2680 const struct intel_crtc_state *old_crtc_state,
2681 const struct drm_connector_state *old_conn_state)
2683 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2686 static void vlv_disable_dp(struct intel_encoder *encoder,
2687 const struct intel_crtc_state *old_crtc_state,
2688 const struct drm_connector_state *old_conn_state)
2690 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2692 intel_psr_disable(intel_dp, old_crtc_state);
2694 intel_disable_dp(encoder, old_crtc_state, old_conn_state);
2697 static void ilk_post_disable_dp(struct intel_encoder *encoder,
2698 const struct intel_crtc_state *old_crtc_state,
2699 const struct drm_connector_state *old_conn_state)
2701 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2702 enum port port = encoder->port;
2704 intel_dp_link_down(encoder, old_crtc_state);
2706 /* Only ilk+ has port A */
2707 if (port == PORT_A)
2708 ironlake_edp_pll_off(intel_dp, old_crtc_state);
2711 static void vlv_post_disable_dp(struct intel_encoder *encoder,
2712 const struct intel_crtc_state *old_crtc_state,
2713 const struct drm_connector_state *old_conn_state)
2715 intel_dp_link_down(encoder, old_crtc_state);
2718 static void chv_post_disable_dp(struct intel_encoder *encoder,
2719 const struct intel_crtc_state *old_crtc_state,
2720 const struct drm_connector_state *old_conn_state)
2722 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2724 intel_dp_link_down(encoder, old_crtc_state);
2726 mutex_lock(&dev_priv->sb_lock);
2728 /* Assert data lane reset */
2729 chv_data_lane_soft_reset(encoder, old_crtc_state, true);
2731 mutex_unlock(&dev_priv->sb_lock);
2734 static void
2735 _intel_dp_set_link_train(struct intel_dp *intel_dp,
2736 uint32_t *DP,
2737 uint8_t dp_train_pat)
2739 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2740 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2741 enum port port = intel_dig_port->base.port;
2743 if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
2744 DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
2745 dp_train_pat & DP_TRAINING_PATTERN_MASK);
2747 if (HAS_DDI(dev_priv)) {
2748 uint32_t temp = I915_READ(DP_TP_CTL(port));
2750 if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
2751 temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
2752 else
2753 temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
2755 temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
2756 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2757 case DP_TRAINING_PATTERN_DISABLE:
2758 temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
2760 break;
2761 case DP_TRAINING_PATTERN_1:
2762 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
2763 break;
2764 case DP_TRAINING_PATTERN_2:
2765 temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
2766 break;
2767 case DP_TRAINING_PATTERN_3:
2768 temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
2769 break;
2771 I915_WRITE(DP_TP_CTL(port), temp);
2773 } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
2774 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
2775 *DP &= ~DP_LINK_TRAIN_MASK_CPT;
2777 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2778 case DP_TRAINING_PATTERN_DISABLE:
2779 *DP |= DP_LINK_TRAIN_OFF_CPT;
2780 break;
2781 case DP_TRAINING_PATTERN_1:
2782 *DP |= DP_LINK_TRAIN_PAT_1_CPT;
2783 break;
2784 case DP_TRAINING_PATTERN_2:
2785 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2786 break;
2787 case DP_TRAINING_PATTERN_3:
2788 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2789 *DP |= DP_LINK_TRAIN_PAT_2_CPT;
2790 break;
2793 } else {
2794 if (IS_CHERRYVIEW(dev_priv))
2795 *DP &= ~DP_LINK_TRAIN_MASK_CHV;
2796 else
2797 *DP &= ~DP_LINK_TRAIN_MASK;
2799 switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
2800 case DP_TRAINING_PATTERN_DISABLE:
2801 *DP |= DP_LINK_TRAIN_OFF;
2802 break;
2803 case DP_TRAINING_PATTERN_1:
2804 *DP |= DP_LINK_TRAIN_PAT_1;
2805 break;
2806 case DP_TRAINING_PATTERN_2:
2807 *DP |= DP_LINK_TRAIN_PAT_2;
2808 break;
2809 case DP_TRAINING_PATTERN_3:
2810 if (IS_CHERRYVIEW(dev_priv)) {
2811 *DP |= DP_LINK_TRAIN_PAT_3_CHV;
2812 } else {
2813 DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
2814 *DP |= DP_LINK_TRAIN_PAT_2;
2816 break;
2821 static void intel_dp_enable_port(struct intel_dp *intel_dp,
2822 const struct intel_crtc_state *old_crtc_state)
2824 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
2826 /* enable with pattern 1 (as per spec) */
2828 intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
2831 * Magic for VLV/CHV. We _must_ first set up the register
2832 * without actually enabling the port, and then do another
2833 * write to enable the port. Otherwise link training will
2834 * fail when the power sequencer is freshly used for this port.
2836 intel_dp->DP |= DP_PORT_EN;
2837 if (old_crtc_state->has_audio)
2838 intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
2840 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
2841 POSTING_READ(intel_dp->output_reg);
2844 static void intel_enable_dp(struct intel_encoder *encoder,
2845 const struct intel_crtc_state *pipe_config,
2846 const struct drm_connector_state *conn_state)
2848 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2849 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2850 struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
2851 uint32_t dp_reg = I915_READ(intel_dp->output_reg);
2852 enum pipe pipe = crtc->pipe;
2854 if (WARN_ON(dp_reg & DP_PORT_EN))
2855 return;
2857 pps_lock(intel_dp);
2859 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2860 vlv_init_panel_power_sequencer(encoder, pipe_config);
2862 intel_dp_enable_port(intel_dp, pipe_config);
2864 edp_panel_vdd_on(intel_dp);
2865 edp_panel_on(intel_dp);
2866 edp_panel_vdd_off(intel_dp, true);
2868 pps_unlock(intel_dp);
2870 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
2871 unsigned int lane_mask = 0x0;
2873 if (IS_CHERRYVIEW(dev_priv))
2874 lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
2876 vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
2877 lane_mask);
2880 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
2881 intel_dp_start_link_train(intel_dp);
2882 intel_dp_stop_link_train(intel_dp);
2884 if (pipe_config->has_audio) {
2885 DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
2886 pipe_name(pipe));
2887 intel_audio_codec_enable(encoder, pipe_config, conn_state);
2891 static void g4x_enable_dp(struct intel_encoder *encoder,
2892 const struct intel_crtc_state *pipe_config,
2893 const struct drm_connector_state *conn_state)
2895 intel_enable_dp(encoder, pipe_config, conn_state);
2896 intel_edp_backlight_on(pipe_config, conn_state);
2899 static void vlv_enable_dp(struct intel_encoder *encoder,
2900 const struct intel_crtc_state *pipe_config,
2901 const struct drm_connector_state *conn_state)
2903 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2905 intel_edp_backlight_on(pipe_config, conn_state);
2906 intel_psr_enable(intel_dp, pipe_config);
2909 static void g4x_pre_enable_dp(struct intel_encoder *encoder,
2910 const struct intel_crtc_state *pipe_config,
2911 const struct drm_connector_state *conn_state)
2913 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2914 enum port port = encoder->port;
2916 intel_dp_prepare(encoder, pipe_config);
2918 /* Only ilk+ has port A */
2919 if (port == PORT_A)
2920 ironlake_edp_pll_on(intel_dp, pipe_config);
2923 static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
2925 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
2926 struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
2927 enum pipe pipe = intel_dp->pps_pipe;
2928 i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
2930 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2932 if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
2933 return;
2935 edp_panel_vdd_off_sync(intel_dp);
2938 * VLV seems to get confused when multiple power seqeuencers
2939 * have the same port selected (even if only one has power/vdd
2940 * enabled). The failure manifests as vlv_wait_port_ready() failing
2941 * CHV on the other hand doesn't seem to mind having the same port
2942 * selected in multiple power seqeuencers, but let's clear the
2943 * port select always when logically disconnecting a power sequencer
2944 * from a port.
2946 DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
2947 pipe_name(pipe), port_name(intel_dig_port->base.port));
2948 I915_WRITE(pp_on_reg, 0);
2949 POSTING_READ(pp_on_reg);
2951 intel_dp->pps_pipe = INVALID_PIPE;
2954 static void vlv_steal_power_sequencer(struct drm_i915_private *dev_priv,
2955 enum pipe pipe)
2957 struct intel_encoder *encoder;
2959 lockdep_assert_held(&dev_priv->pps_mutex);
2961 for_each_intel_encoder(&dev_priv->drm, encoder) {
2962 struct intel_dp *intel_dp;
2963 enum port port;
2965 if (encoder->type != INTEL_OUTPUT_DP &&
2966 encoder->type != INTEL_OUTPUT_EDP)
2967 continue;
2969 intel_dp = enc_to_intel_dp(&encoder->base);
2970 port = dp_to_dig_port(intel_dp)->base.port;
2972 WARN(intel_dp->active_pipe == pipe,
2973 "stealing pipe %c power sequencer from active (e)DP port %c\n",
2974 pipe_name(pipe), port_name(port));
2976 if (intel_dp->pps_pipe != pipe)
2977 continue;
2979 DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
2980 pipe_name(pipe), port_name(port));
2982 /* make sure vdd is off before we steal it */
2983 vlv_detach_power_sequencer(intel_dp);
2987 static void vlv_init_panel_power_sequencer(struct intel_encoder *encoder,
2988 const struct intel_crtc_state *crtc_state)
2990 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
2991 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
2992 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
2994 lockdep_assert_held(&dev_priv->pps_mutex);
2996 WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
2998 if (intel_dp->pps_pipe != INVALID_PIPE &&
2999 intel_dp->pps_pipe != crtc->pipe) {
3001 * If another power sequencer was being used on this
3002 * port previously make sure to turn off vdd there while
3003 * we still have control of it.
3005 vlv_detach_power_sequencer(intel_dp);
3009 * We may be stealing the power
3010 * sequencer from another port.
3012 vlv_steal_power_sequencer(dev_priv, crtc->pipe);
3014 intel_dp->active_pipe = crtc->pipe;
3016 if (!intel_dp_is_edp(intel_dp))
3017 return;
3019 /* now it's all ours */
3020 intel_dp->pps_pipe = crtc->pipe;
3022 DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
3023 pipe_name(intel_dp->pps_pipe), port_name(encoder->port));
3025 /* init power sequencer on this pipe and port */
3026 intel_dp_init_panel_power_sequencer(intel_dp);
3027 intel_dp_init_panel_power_sequencer_registers(intel_dp, true);
3030 static void vlv_pre_enable_dp(struct intel_encoder *encoder,
3031 const struct intel_crtc_state *pipe_config,
3032 const struct drm_connector_state *conn_state)
3034 vlv_phy_pre_encoder_enable(encoder, pipe_config);
3036 intel_enable_dp(encoder, pipe_config, conn_state);
3039 static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
3040 const struct intel_crtc_state *pipe_config,
3041 const struct drm_connector_state *conn_state)
3043 intel_dp_prepare(encoder, pipe_config);
3045 vlv_phy_pre_pll_enable(encoder, pipe_config);
3048 static void chv_pre_enable_dp(struct intel_encoder *encoder,
3049 const struct intel_crtc_state *pipe_config,
3050 const struct drm_connector_state *conn_state)
3052 chv_phy_pre_encoder_enable(encoder, pipe_config);
3054 intel_enable_dp(encoder, pipe_config, conn_state);
3056 /* Second common lane will stay alive on its own now */
3057 chv_phy_release_cl2_override(encoder);
3060 static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
3061 const struct intel_crtc_state *pipe_config,
3062 const struct drm_connector_state *conn_state)
3064 intel_dp_prepare(encoder, pipe_config);
3066 chv_phy_pre_pll_enable(encoder, pipe_config);
3069 static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
3070 const struct intel_crtc_state *old_crtc_state,
3071 const struct drm_connector_state *old_conn_state)
3073 chv_phy_post_pll_disable(encoder, old_crtc_state);
3077 * Fetch AUX CH registers 0x202 - 0x207 which contain
3078 * link status information
3080 bool
3081 intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
3083 return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
3084 DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
3087 static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
3089 uint8_t psr_caps = 0;
3091 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
3092 return false;
3093 return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
3096 static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
3098 uint8_t dprx = 0;
3100 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
3101 &dprx) != 1)
3102 return false;
3103 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
3106 static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
3108 uint8_t alpm_caps = 0;
3110 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
3111 &alpm_caps) != 1)
3112 return false;
3113 return alpm_caps & DP_ALPM_CAP;
3116 /* These are source-specific values. */
3117 uint8_t
3118 intel_dp_voltage_max(struct intel_dp *intel_dp)
3120 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3121 enum port port = dp_to_dig_port(intel_dp)->base.port;
3123 if (INTEL_GEN(dev_priv) >= 9) {
3124 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3125 return intel_ddi_dp_voltage_max(encoder);
3126 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
3127 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3128 else if (IS_GEN7(dev_priv) && port == PORT_A)
3129 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3130 else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
3131 return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
3132 else
3133 return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
3136 uint8_t
3137 intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
3139 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3140 enum port port = dp_to_dig_port(intel_dp)->base.port;
3142 if (INTEL_GEN(dev_priv) >= 9) {
3143 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3144 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3145 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3146 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3147 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3148 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3149 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3150 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3151 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3152 default:
3153 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3155 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3156 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3157 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3158 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3159 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3160 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3161 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3162 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3163 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3164 default:
3165 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3167 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3168 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3169 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3170 return DP_TRAIN_PRE_EMPH_LEVEL_3;
3171 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3172 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3173 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3174 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3175 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3176 default:
3177 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3179 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3180 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3181 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3182 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3183 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3184 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3185 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3186 default:
3187 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3189 } else {
3190 switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
3191 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3192 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3193 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3194 return DP_TRAIN_PRE_EMPH_LEVEL_2;
3195 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3196 return DP_TRAIN_PRE_EMPH_LEVEL_1;
3197 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3198 default:
3199 return DP_TRAIN_PRE_EMPH_LEVEL_0;
3204 static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
3206 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3207 unsigned long demph_reg_value, preemph_reg_value,
3208 uniqtranscale_reg_value;
3209 uint8_t train_set = intel_dp->train_set[0];
3211 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3212 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3213 preemph_reg_value = 0x0004000;
3214 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3215 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3216 demph_reg_value = 0x2B405555;
3217 uniqtranscale_reg_value = 0x552AB83A;
3218 break;
3219 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3220 demph_reg_value = 0x2B404040;
3221 uniqtranscale_reg_value = 0x5548B83A;
3222 break;
3223 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3224 demph_reg_value = 0x2B245555;
3225 uniqtranscale_reg_value = 0x5560B83A;
3226 break;
3227 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3228 demph_reg_value = 0x2B405555;
3229 uniqtranscale_reg_value = 0x5598DA3A;
3230 break;
3231 default:
3232 return 0;
3234 break;
3235 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3236 preemph_reg_value = 0x0002000;
3237 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3238 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3239 demph_reg_value = 0x2B404040;
3240 uniqtranscale_reg_value = 0x5552B83A;
3241 break;
3242 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3243 demph_reg_value = 0x2B404848;
3244 uniqtranscale_reg_value = 0x5580B83A;
3245 break;
3246 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3247 demph_reg_value = 0x2B404040;
3248 uniqtranscale_reg_value = 0x55ADDA3A;
3249 break;
3250 default:
3251 return 0;
3253 break;
3254 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3255 preemph_reg_value = 0x0000000;
3256 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3257 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3258 demph_reg_value = 0x2B305555;
3259 uniqtranscale_reg_value = 0x5570B83A;
3260 break;
3261 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3262 demph_reg_value = 0x2B2B4040;
3263 uniqtranscale_reg_value = 0x55ADDA3A;
3264 break;
3265 default:
3266 return 0;
3268 break;
3269 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3270 preemph_reg_value = 0x0006000;
3271 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3272 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3273 demph_reg_value = 0x1B405555;
3274 uniqtranscale_reg_value = 0x55ADDA3A;
3275 break;
3276 default:
3277 return 0;
3279 break;
3280 default:
3281 return 0;
3284 vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
3285 uniqtranscale_reg_value, 0);
3287 return 0;
3290 static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
3292 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
3293 u32 deemph_reg_value, margin_reg_value;
3294 bool uniq_trans_scale = false;
3295 uint8_t train_set = intel_dp->train_set[0];
3297 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3298 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3299 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3300 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3301 deemph_reg_value = 128;
3302 margin_reg_value = 52;
3303 break;
3304 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3305 deemph_reg_value = 128;
3306 margin_reg_value = 77;
3307 break;
3308 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3309 deemph_reg_value = 128;
3310 margin_reg_value = 102;
3311 break;
3312 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3313 deemph_reg_value = 128;
3314 margin_reg_value = 154;
3315 uniq_trans_scale = true;
3316 break;
3317 default:
3318 return 0;
3320 break;
3321 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3322 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3323 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3324 deemph_reg_value = 85;
3325 margin_reg_value = 78;
3326 break;
3327 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3328 deemph_reg_value = 85;
3329 margin_reg_value = 116;
3330 break;
3331 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3332 deemph_reg_value = 85;
3333 margin_reg_value = 154;
3334 break;
3335 default:
3336 return 0;
3338 break;
3339 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3340 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3341 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3342 deemph_reg_value = 64;
3343 margin_reg_value = 104;
3344 break;
3345 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3346 deemph_reg_value = 64;
3347 margin_reg_value = 154;
3348 break;
3349 default:
3350 return 0;
3352 break;
3353 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3354 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3355 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3356 deemph_reg_value = 43;
3357 margin_reg_value = 154;
3358 break;
3359 default:
3360 return 0;
3362 break;
3363 default:
3364 return 0;
3367 chv_set_phy_signal_level(encoder, deemph_reg_value,
3368 margin_reg_value, uniq_trans_scale);
3370 return 0;
3373 static uint32_t
3374 gen4_signal_levels(uint8_t train_set)
3376 uint32_t signal_levels = 0;
3378 switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
3379 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
3380 default:
3381 signal_levels |= DP_VOLTAGE_0_4;
3382 break;
3383 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
3384 signal_levels |= DP_VOLTAGE_0_6;
3385 break;
3386 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
3387 signal_levels |= DP_VOLTAGE_0_8;
3388 break;
3389 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
3390 signal_levels |= DP_VOLTAGE_1_2;
3391 break;
3393 switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
3394 case DP_TRAIN_PRE_EMPH_LEVEL_0:
3395 default:
3396 signal_levels |= DP_PRE_EMPHASIS_0;
3397 break;
3398 case DP_TRAIN_PRE_EMPH_LEVEL_1:
3399 signal_levels |= DP_PRE_EMPHASIS_3_5;
3400 break;
3401 case DP_TRAIN_PRE_EMPH_LEVEL_2:
3402 signal_levels |= DP_PRE_EMPHASIS_6;
3403 break;
3404 case DP_TRAIN_PRE_EMPH_LEVEL_3:
3405 signal_levels |= DP_PRE_EMPHASIS_9_5;
3406 break;
3408 return signal_levels;
3411 /* Gen6's DP voltage swing and pre-emphasis control */
3412 static uint32_t
3413 gen6_edp_signal_levels(uint8_t train_set)
3415 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3416 DP_TRAIN_PRE_EMPHASIS_MASK);
3417 switch (signal_levels) {
3418 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3419 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3420 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3421 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3422 return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
3423 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3424 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3425 return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
3426 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3427 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3428 return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
3429 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3430 case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3431 return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
3432 default:
3433 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3434 "0x%x\n", signal_levels);
3435 return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
3439 /* Gen7's DP voltage swing and pre-emphasis control */
3440 static uint32_t
3441 gen7_edp_signal_levels(uint8_t train_set)
3443 int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
3444 DP_TRAIN_PRE_EMPHASIS_MASK);
3445 switch (signal_levels) {
3446 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3447 return EDP_LINK_TRAIN_400MV_0DB_IVB;
3448 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3449 return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
3450 case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
3451 return EDP_LINK_TRAIN_400MV_6DB_IVB;
3453 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3454 return EDP_LINK_TRAIN_600MV_0DB_IVB;
3455 case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3456 return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
3458 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
3459 return EDP_LINK_TRAIN_800MV_0DB_IVB;
3460 case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
3461 return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
3463 default:
3464 DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
3465 "0x%x\n", signal_levels);
3466 return EDP_LINK_TRAIN_500MV_0DB_IVB;
3470 void
3471 intel_dp_set_signal_levels(struct intel_dp *intel_dp)
3473 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3474 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3475 enum port port = intel_dig_port->base.port;
3476 uint32_t signal_levels, mask = 0;
3477 uint8_t train_set = intel_dp->train_set[0];
3479 if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
3480 signal_levels = bxt_signal_levels(intel_dp);
3481 } else if (HAS_DDI(dev_priv)) {
3482 signal_levels = ddi_signal_levels(intel_dp);
3483 mask = DDI_BUF_EMP_MASK;
3484 } else if (IS_CHERRYVIEW(dev_priv)) {
3485 signal_levels = chv_signal_levels(intel_dp);
3486 } else if (IS_VALLEYVIEW(dev_priv)) {
3487 signal_levels = vlv_signal_levels(intel_dp);
3488 } else if (IS_GEN7(dev_priv) && port == PORT_A) {
3489 signal_levels = gen7_edp_signal_levels(train_set);
3490 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
3491 } else if (IS_GEN6(dev_priv) && port == PORT_A) {
3492 signal_levels = gen6_edp_signal_levels(train_set);
3493 mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
3494 } else {
3495 signal_levels = gen4_signal_levels(train_set);
3496 mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
3499 if (mask)
3500 DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
3502 DRM_DEBUG_KMS("Using vswing level %d\n",
3503 train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
3504 DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
3505 (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
3506 DP_TRAIN_PRE_EMPHASIS_SHIFT);
3508 intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
3510 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3511 POSTING_READ(intel_dp->output_reg);
3514 void
3515 intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
3516 uint8_t dp_train_pat)
3518 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3519 struct drm_i915_private *dev_priv =
3520 to_i915(intel_dig_port->base.base.dev);
3522 _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
3524 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
3525 POSTING_READ(intel_dp->output_reg);
3528 void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
3530 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
3531 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
3532 enum port port = intel_dig_port->base.port;
3533 uint32_t val;
3535 if (!HAS_DDI(dev_priv))
3536 return;
3538 val = I915_READ(DP_TP_CTL(port));
3539 val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
3540 val |= DP_TP_CTL_LINK_TRAIN_IDLE;
3541 I915_WRITE(DP_TP_CTL(port), val);
3544 * On PORT_A we can have only eDP in SST mode. There the only reason
3545 * we need to set idle transmission mode is to work around a HW issue
3546 * where we enable the pipe while not in idle link-training mode.
3547 * In this case there is requirement to wait for a minimum number of
3548 * idle patterns to be sent.
3550 if (port == PORT_A)
3551 return;
3553 if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
3554 DP_TP_STATUS_IDLE_DONE,
3555 DP_TP_STATUS_IDLE_DONE,
3557 DRM_ERROR("Timed out waiting for DP idle patterns\n");
3560 static void
3561 intel_dp_link_down(struct intel_encoder *encoder,
3562 const struct intel_crtc_state *old_crtc_state)
3564 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3565 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
3566 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
3567 enum port port = encoder->port;
3568 uint32_t DP = intel_dp->DP;
3570 if (WARN_ON(HAS_DDI(dev_priv)))
3571 return;
3573 if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
3574 return;
3576 DRM_DEBUG_KMS("\n");
3578 if ((IS_GEN7(dev_priv) && port == PORT_A) ||
3579 (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
3580 DP &= ~DP_LINK_TRAIN_MASK_CPT;
3581 DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
3582 } else {
3583 if (IS_CHERRYVIEW(dev_priv))
3584 DP &= ~DP_LINK_TRAIN_MASK_CHV;
3585 else
3586 DP &= ~DP_LINK_TRAIN_MASK;
3587 DP |= DP_LINK_TRAIN_PAT_IDLE;
3589 I915_WRITE(intel_dp->output_reg, DP);
3590 POSTING_READ(intel_dp->output_reg);
3592 DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
3593 I915_WRITE(intel_dp->output_reg, DP);
3594 POSTING_READ(intel_dp->output_reg);
3597 * HW workaround for IBX, we need to move the port
3598 * to transcoder A after disabling it to allow the
3599 * matching HDMI port to be enabled on transcoder A.
3601 if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
3603 * We get CPU/PCH FIFO underruns on the other pipe when
3604 * doing the workaround. Sweep them under the rug.
3606 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3607 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
3609 /* always enable with pattern 1 (as per spec) */
3610 DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
3611 DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
3612 I915_WRITE(intel_dp->output_reg, DP);
3613 POSTING_READ(intel_dp->output_reg);
3615 DP &= ~DP_PORT_EN;
3616 I915_WRITE(intel_dp->output_reg, DP);
3617 POSTING_READ(intel_dp->output_reg);
3619 intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
3620 intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3621 intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
3624 msleep(intel_dp->panel_power_down_delay);
3626 intel_dp->DP = DP;
3628 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3629 pps_lock(intel_dp);
3630 intel_dp->active_pipe = INVALID_PIPE;
3631 pps_unlock(intel_dp);
3635 bool
3636 intel_dp_read_dpcd(struct intel_dp *intel_dp)
3638 if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
3639 sizeof(intel_dp->dpcd)) < 0)
3640 return false; /* aux transfer failed */
3642 DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
3644 return intel_dp->dpcd[DP_DPCD_REV] != 0;
3647 static bool
3648 intel_edp_init_dpcd(struct intel_dp *intel_dp)
3650 struct drm_i915_private *dev_priv =
3651 to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
3653 /* this function is meant to be called only once */
3654 WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
3656 if (!intel_dp_read_dpcd(intel_dp))
3657 return false;
3659 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
3660 drm_dp_is_branch(intel_dp->dpcd));
3662 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
3663 dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
3664 DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
3666 /* Check if the panel supports PSR */
3667 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
3668 intel_dp->psr_dpcd,
3669 sizeof(intel_dp->psr_dpcd));
3670 if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
3671 dev_priv->psr.sink_support = true;
3672 DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
3675 if (INTEL_GEN(dev_priv) >= 9 &&
3676 (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
3677 uint8_t frame_sync_cap;
3679 dev_priv->psr.sink_support = true;
3680 if (drm_dp_dpcd_readb(&intel_dp->aux,
3681 DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
3682 &frame_sync_cap) != 1)
3683 frame_sync_cap = 0;
3684 dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
3685 /* PSR2 needs frame sync as well */
3686 dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
3687 DRM_DEBUG_KMS("PSR2 %s on sink",
3688 dev_priv->psr.psr2_support ? "supported" : "not supported");
3690 if (dev_priv->psr.psr2_support) {
3691 dev_priv->psr.y_cord_support =
3692 intel_dp_get_y_cord_status(intel_dp);
3693 dev_priv->psr.colorimetry_support =
3694 intel_dp_get_colorimetry_status(intel_dp);
3695 dev_priv->psr.alpm =
3696 intel_dp_get_alpm_status(intel_dp);
3702 * Read the eDP display control registers.
3704 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
3705 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
3706 * set, but require eDP 1.4+ detection (e.g. for supported link rates
3707 * method). The display control registers should read zero if they're
3708 * not supported anyway.
3710 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
3711 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3712 sizeof(intel_dp->edp_dpcd))
3713 DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3714 intel_dp->edp_dpcd);
3716 /* Read the eDP 1.4+ supported link rates. */
3717 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) {
3718 __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
3719 int i;
3721 drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
3722 sink_rates, sizeof(sink_rates));
3724 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
3725 int val = le16_to_cpu(sink_rates[i]);
3727 if (val == 0)
3728 break;
3730 /* Value read multiplied by 200kHz gives the per-lane
3731 * link rate in kHz. The source rates are, however,
3732 * stored in terms of LS_Clk kHz. The full conversion
3733 * back to symbols is
3734 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
3736 intel_dp->sink_rates[i] = (val * 200) / 10;
3738 intel_dp->num_sink_rates = i;
3742 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available,
3743 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise.
3745 if (intel_dp->num_sink_rates)
3746 intel_dp->use_rate_select = true;
3747 else
3748 intel_dp_set_sink_rates(intel_dp);
3750 intel_dp_set_common_rates(intel_dp);
3752 return true;
3756 static bool
3757 intel_dp_get_dpcd(struct intel_dp *intel_dp)
3759 u8 sink_count;
3761 if (!intel_dp_read_dpcd(intel_dp))
3762 return false;
3764 /* Don't clobber cached eDP rates. */
3765 if (!intel_dp_is_edp(intel_dp)) {
3766 intel_dp_set_sink_rates(intel_dp);
3767 intel_dp_set_common_rates(intel_dp);
3770 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
3771 return false;
3774 * Sink count can change between short pulse hpd hence
3775 * a member variable in intel_dp will track any changes
3776 * between short pulse interrupts.
3778 intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
3781 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
3782 * a dongle is present but no display. Unless we require to know
3783 * if a dongle is present or not, we don't need to update
3784 * downstream port information. So, an early return here saves
3785 * time from performing other operations which are not required.
3787 if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
3788 return false;
3790 if (!drm_dp_is_branch(intel_dp->dpcd))
3791 return true; /* native DP sink */
3793 if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
3794 return true; /* no per-port downstream info */
3796 if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
3797 intel_dp->downstream_ports,
3798 DP_MAX_DOWNSTREAM_PORTS) < 0)
3799 return false; /* downstream port status fetch failed */
3801 return true;
3804 static bool
3805 intel_dp_can_mst(struct intel_dp *intel_dp)
3807 u8 mstm_cap;
3809 if (!i915_modparams.enable_dp_mst)
3810 return false;
3812 if (!intel_dp->can_mst)
3813 return false;
3815 if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
3816 return false;
3818 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
3819 return false;
3821 return mstm_cap & DP_MST_CAP;
3824 static void
3825 intel_dp_configure_mst(struct intel_dp *intel_dp)
3827 if (!i915_modparams.enable_dp_mst)
3828 return;
3830 if (!intel_dp->can_mst)
3831 return;
3833 intel_dp->is_mst = intel_dp_can_mst(intel_dp);
3835 if (intel_dp->is_mst)
3836 DRM_DEBUG_KMS("Sink is MST capable\n");
3837 else
3838 DRM_DEBUG_KMS("Sink is not MST capable\n");
3840 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
3841 intel_dp->is_mst);
3844 static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp,
3845 struct intel_crtc_state *crtc_state, bool disable_wa)
3847 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3848 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3849 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3850 u8 buf;
3851 int ret = 0;
3852 int count = 0;
3853 int attempts = 10;
3855 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
3856 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3857 ret = -EIO;
3858 goto out;
3861 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3862 buf & ~DP_TEST_SINK_START) < 0) {
3863 DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
3864 ret = -EIO;
3865 goto out;
3868 do {
3869 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3871 if (drm_dp_dpcd_readb(&intel_dp->aux,
3872 DP_TEST_SINK_MISC, &buf) < 0) {
3873 ret = -EIO;
3874 goto out;
3876 count = buf & DP_TEST_COUNT_MASK;
3877 } while (--attempts && count);
3879 if (attempts == 0) {
3880 DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
3881 ret = -ETIMEDOUT;
3884 out:
3885 if (disable_wa)
3886 hsw_enable_ips(crtc_state);
3887 return ret;
3890 static int intel_dp_sink_crc_start(struct intel_dp *intel_dp,
3891 struct intel_crtc_state *crtc_state)
3893 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3894 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3895 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3896 u8 buf;
3897 int ret;
3899 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
3900 return -EIO;
3902 if (!(buf & DP_TEST_CRC_SUPPORTED))
3903 return -ENOTTY;
3905 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
3906 return -EIO;
3908 if (buf & DP_TEST_SINK_START) {
3909 ret = intel_dp_sink_crc_stop(intel_dp, crtc_state, false);
3910 if (ret)
3911 return ret;
3914 hsw_disable_ips(crtc_state);
3916 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
3917 buf | DP_TEST_SINK_START) < 0) {
3918 hsw_enable_ips(crtc_state);
3919 return -EIO;
3922 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3923 return 0;
3926 int intel_dp_sink_crc(struct intel_dp *intel_dp, struct intel_crtc_state *crtc_state, u8 *crc)
3928 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3929 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3930 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3931 u8 buf;
3932 int count, ret;
3933 int attempts = 6;
3935 ret = intel_dp_sink_crc_start(intel_dp, crtc_state);
3936 if (ret)
3937 return ret;
3939 do {
3940 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
3942 if (drm_dp_dpcd_readb(&intel_dp->aux,
3943 DP_TEST_SINK_MISC, &buf) < 0) {
3944 ret = -EIO;
3945 goto stop;
3947 count = buf & DP_TEST_COUNT_MASK;
3949 } while (--attempts && count == 0);
3951 if (attempts == 0) {
3952 DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
3953 ret = -ETIMEDOUT;
3954 goto stop;
3957 if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
3958 ret = -EIO;
3959 goto stop;
3962 stop:
3963 intel_dp_sink_crc_stop(intel_dp, crtc_state, true);
3964 return ret;
3967 static bool
3968 intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3970 return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
3971 sink_irq_vector) == 1;
3974 static bool
3975 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
3977 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI,
3978 sink_irq_vector, DP_DPRX_ESI_LEN) ==
3979 DP_DPRX_ESI_LEN;
3982 static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
3984 int status = 0;
3985 int test_link_rate;
3986 uint8_t test_lane_count, test_link_bw;
3987 /* (DP CTS 1.2)
3988 * 4.3.1.11
3990 /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
3991 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
3992 &test_lane_count);
3994 if (status <= 0) {
3995 DRM_DEBUG_KMS("Lane count read failed\n");
3996 return DP_TEST_NAK;
3998 test_lane_count &= DP_MAX_LANE_COUNT_MASK;
4000 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
4001 &test_link_bw);
4002 if (status <= 0) {
4003 DRM_DEBUG_KMS("Link Rate read failed\n");
4004 return DP_TEST_NAK;
4006 test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
4008 /* Validate the requested link rate and lane count */
4009 if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
4010 test_lane_count))
4011 return DP_TEST_NAK;
4013 intel_dp->compliance.test_lane_count = test_lane_count;
4014 intel_dp->compliance.test_link_rate = test_link_rate;
4016 return DP_TEST_ACK;
4019 static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
4021 uint8_t test_pattern;
4022 uint8_t test_misc;
4023 __be16 h_width, v_height;
4024 int status = 0;
4026 /* Read the TEST_PATTERN (DP CTS 3.1.5) */
4027 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
4028 &test_pattern);
4029 if (status <= 0) {
4030 DRM_DEBUG_KMS("Test pattern read failed\n");
4031 return DP_TEST_NAK;
4033 if (test_pattern != DP_COLOR_RAMP)
4034 return DP_TEST_NAK;
4036 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
4037 &h_width, 2);
4038 if (status <= 0) {
4039 DRM_DEBUG_KMS("H Width read failed\n");
4040 return DP_TEST_NAK;
4043 status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
4044 &v_height, 2);
4045 if (status <= 0) {
4046 DRM_DEBUG_KMS("V Height read failed\n");
4047 return DP_TEST_NAK;
4050 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
4051 &test_misc);
4052 if (status <= 0) {
4053 DRM_DEBUG_KMS("TEST MISC read failed\n");
4054 return DP_TEST_NAK;
4056 if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
4057 return DP_TEST_NAK;
4058 if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
4059 return DP_TEST_NAK;
4060 switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
4061 case DP_TEST_BIT_DEPTH_6:
4062 intel_dp->compliance.test_data.bpc = 6;
4063 break;
4064 case DP_TEST_BIT_DEPTH_8:
4065 intel_dp->compliance.test_data.bpc = 8;
4066 break;
4067 default:
4068 return DP_TEST_NAK;
4071 intel_dp->compliance.test_data.video_pattern = test_pattern;
4072 intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
4073 intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
4074 /* Set test active flag here so userspace doesn't interrupt things */
4075 intel_dp->compliance.test_active = 1;
4077 return DP_TEST_ACK;
4080 static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
4082 uint8_t test_result = DP_TEST_ACK;
4083 struct intel_connector *intel_connector = intel_dp->attached_connector;
4084 struct drm_connector *connector = &intel_connector->base;
4086 if (intel_connector->detect_edid == NULL ||
4087 connector->edid_corrupt ||
4088 intel_dp->aux.i2c_defer_count > 6) {
4089 /* Check EDID read for NACKs, DEFERs and corruption
4090 * (DP CTS 1.2 Core r1.1)
4091 * 4.2.2.4 : Failed EDID read, I2C_NAK
4092 * 4.2.2.5 : Failed EDID read, I2C_DEFER
4093 * 4.2.2.6 : EDID corruption detected
4094 * Use failsafe mode for all cases
4096 if (intel_dp->aux.i2c_nack_count > 0 ||
4097 intel_dp->aux.i2c_defer_count > 0)
4098 DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
4099 intel_dp->aux.i2c_nack_count,
4100 intel_dp->aux.i2c_defer_count);
4101 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
4102 } else {
4103 struct edid *block = intel_connector->detect_edid;
4105 /* We have to write the checksum
4106 * of the last block read
4108 block += intel_connector->detect_edid->extensions;
4110 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
4111 block->checksum) <= 0)
4112 DRM_DEBUG_KMS("Failed to write EDID checksum\n");
4114 test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
4115 intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
4118 /* Set test active flag here so userspace doesn't interrupt things */
4119 intel_dp->compliance.test_active = 1;
4121 return test_result;
4124 static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
4126 uint8_t test_result = DP_TEST_NAK;
4127 return test_result;
4130 static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
4132 uint8_t response = DP_TEST_NAK;
4133 uint8_t request = 0;
4134 int status;
4136 status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
4137 if (status <= 0) {
4138 DRM_DEBUG_KMS("Could not read test request from sink\n");
4139 goto update_status;
4142 switch (request) {
4143 case DP_TEST_LINK_TRAINING:
4144 DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
4145 response = intel_dp_autotest_link_training(intel_dp);
4146 break;
4147 case DP_TEST_LINK_VIDEO_PATTERN:
4148 DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
4149 response = intel_dp_autotest_video_pattern(intel_dp);
4150 break;
4151 case DP_TEST_LINK_EDID_READ:
4152 DRM_DEBUG_KMS("EDID test requested\n");
4153 response = intel_dp_autotest_edid(intel_dp);
4154 break;
4155 case DP_TEST_LINK_PHY_TEST_PATTERN:
4156 DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
4157 response = intel_dp_autotest_phy_pattern(intel_dp);
4158 break;
4159 default:
4160 DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
4161 break;
4164 if (response & DP_TEST_ACK)
4165 intel_dp->compliance.test_type = request;
4167 update_status:
4168 status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
4169 if (status <= 0)
4170 DRM_DEBUG_KMS("Could not write test response to sink\n");
4173 static int
4174 intel_dp_check_mst_status(struct intel_dp *intel_dp)
4176 bool bret;
4178 if (intel_dp->is_mst) {
4179 u8 esi[DP_DPRX_ESI_LEN] = { 0 };
4180 int ret = 0;
4181 int retry;
4182 bool handled;
4183 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4184 go_again:
4185 if (bret == true) {
4187 /* check link status - esi[10] = 0x200c */
4188 if (intel_dp->active_mst_links &&
4189 !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
4190 DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
4191 intel_dp_start_link_train(intel_dp);
4192 intel_dp_stop_link_train(intel_dp);
4195 DRM_DEBUG_KMS("got esi %3ph\n", esi);
4196 ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
4198 if (handled) {
4199 for (retry = 0; retry < 3; retry++) {
4200 int wret;
4201 wret = drm_dp_dpcd_write(&intel_dp->aux,
4202 DP_SINK_COUNT_ESI+1,
4203 &esi[1], 3);
4204 if (wret == 3) {
4205 break;
4209 bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
4210 if (bret == true) {
4211 DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
4212 goto go_again;
4214 } else
4215 ret = 0;
4217 return ret;
4218 } else {
4219 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4220 DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
4221 intel_dp->is_mst = false;
4222 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
4223 /* send a hotplug event */
4224 drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
4227 return -EINVAL;
4230 static void
4231 intel_dp_retrain_link(struct intel_dp *intel_dp)
4233 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
4234 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4235 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
4237 /* Suppress underruns caused by re-training */
4238 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
4239 if (crtc->config->has_pch_encoder)
4240 intel_set_pch_fifo_underrun_reporting(dev_priv,
4241 intel_crtc_pch_transcoder(crtc), false);
4243 intel_dp_start_link_train(intel_dp);
4244 intel_dp_stop_link_train(intel_dp);
4246 /* Keep underrun reporting disabled until things are stable */
4247 intel_wait_for_vblank(dev_priv, crtc->pipe);
4249 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
4250 if (crtc->config->has_pch_encoder)
4251 intel_set_pch_fifo_underrun_reporting(dev_priv,
4252 intel_crtc_pch_transcoder(crtc), true);
4255 static void
4256 intel_dp_check_link_status(struct intel_dp *intel_dp)
4258 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4259 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4260 struct drm_connector_state *conn_state =
4261 intel_dp->attached_connector->base.state;
4262 u8 link_status[DP_LINK_STATUS_SIZE];
4264 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4266 if (!intel_dp_get_link_status(intel_dp, link_status)) {
4267 DRM_ERROR("Failed to get link status\n");
4268 return;
4271 if (!conn_state->crtc)
4272 return;
4274 WARN_ON(!drm_modeset_is_locked(&conn_state->crtc->mutex));
4276 if (!conn_state->crtc->state->active)
4277 return;
4279 if (conn_state->commit &&
4280 !try_wait_for_completion(&conn_state->commit->hw_done))
4281 return;
4284 * Validate the cached values of intel_dp->link_rate and
4285 * intel_dp->lane_count before attempting to retrain.
4287 if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
4288 intel_dp->lane_count))
4289 return;
4291 /* Retrain if Channel EQ or CR not ok */
4292 if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
4293 DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
4294 intel_encoder->base.name);
4296 intel_dp_retrain_link(intel_dp);
4301 * According to DP spec
4302 * 5.1.2:
4303 * 1. Read DPCD
4304 * 2. Configure link according to Receiver Capabilities
4305 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
4306 * 4. Check link status on receipt of hot-plug interrupt
4308 * intel_dp_short_pulse - handles short pulse interrupts
4309 * when full detection is not required.
4310 * Returns %true if short pulse is handled and full detection
4311 * is NOT required and %false otherwise.
4313 static bool
4314 intel_dp_short_pulse(struct intel_dp *intel_dp)
4316 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4317 u8 sink_irq_vector = 0;
4318 u8 old_sink_count = intel_dp->sink_count;
4319 bool ret;
4322 * Clearing compliance test variables to allow capturing
4323 * of values for next automated test request.
4325 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4328 * Now read the DPCD to see if it's actually running
4329 * If the current value of sink count doesn't match with
4330 * the value that was stored earlier or dpcd read failed
4331 * we need to do full detection
4333 ret = intel_dp_get_dpcd(intel_dp);
4335 if ((old_sink_count != intel_dp->sink_count) || !ret) {
4336 /* No need to proceed if we are going to do full detect */
4337 return false;
4340 /* Try to read the source of the interrupt */
4341 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4342 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4343 sink_irq_vector != 0) {
4344 /* Clear interrupt source */
4345 drm_dp_dpcd_writeb(&intel_dp->aux,
4346 DP_DEVICE_SERVICE_IRQ_VECTOR,
4347 sink_irq_vector);
4349 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4350 intel_dp_handle_test_request(intel_dp);
4351 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4352 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4355 intel_dp_check_link_status(intel_dp);
4357 if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
4358 DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
4359 /* Send a Hotplug Uevent to userspace to start modeset */
4360 drm_kms_helper_hotplug_event(&dev_priv->drm);
4363 return true;
4366 /* XXX this is probably wrong for multiple downstream ports */
4367 static enum drm_connector_status
4368 intel_dp_detect_dpcd(struct intel_dp *intel_dp)
4370 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
4371 uint8_t *dpcd = intel_dp->dpcd;
4372 uint8_t type;
4374 if (lspcon->active)
4375 lspcon_resume(lspcon);
4377 if (!intel_dp_get_dpcd(intel_dp))
4378 return connector_status_disconnected;
4380 if (intel_dp_is_edp(intel_dp))
4381 return connector_status_connected;
4383 /* if there's no downstream port, we're done */
4384 if (!drm_dp_is_branch(dpcd))
4385 return connector_status_connected;
4387 /* If we're HPD-aware, SINK_COUNT changes dynamically */
4388 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4389 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
4391 return intel_dp->sink_count ?
4392 connector_status_connected : connector_status_disconnected;
4395 if (intel_dp_can_mst(intel_dp))
4396 return connector_status_connected;
4398 /* If no HPD, poke DDC gently */
4399 if (drm_probe_ddc(&intel_dp->aux.ddc))
4400 return connector_status_connected;
4402 /* Well we tried, say unknown for unreliable port types */
4403 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
4404 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
4405 if (type == DP_DS_PORT_TYPE_VGA ||
4406 type == DP_DS_PORT_TYPE_NON_EDID)
4407 return connector_status_unknown;
4408 } else {
4409 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
4410 DP_DWN_STRM_PORT_TYPE_MASK;
4411 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
4412 type == DP_DWN_STRM_PORT_TYPE_OTHER)
4413 return connector_status_unknown;
4416 /* Anything else is out of spec, warn and ignore */
4417 DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
4418 return connector_status_disconnected;
4421 static enum drm_connector_status
4422 edp_detect(struct intel_dp *intel_dp)
4424 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4425 enum drm_connector_status status;
4427 status = intel_panel_detect(dev_priv);
4428 if (status == connector_status_unknown)
4429 status = connector_status_connected;
4431 return status;
4434 static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
4435 struct intel_digital_port *port)
4437 u32 bit;
4439 switch (port->base.port) {
4440 case PORT_B:
4441 bit = SDE_PORTB_HOTPLUG;
4442 break;
4443 case PORT_C:
4444 bit = SDE_PORTC_HOTPLUG;
4445 break;
4446 case PORT_D:
4447 bit = SDE_PORTD_HOTPLUG;
4448 break;
4449 default:
4450 MISSING_CASE(port->base.port);
4451 return false;
4454 return I915_READ(SDEISR) & bit;
4457 static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
4458 struct intel_digital_port *port)
4460 u32 bit;
4462 switch (port->base.port) {
4463 case PORT_B:
4464 bit = SDE_PORTB_HOTPLUG_CPT;
4465 break;
4466 case PORT_C:
4467 bit = SDE_PORTC_HOTPLUG_CPT;
4468 break;
4469 case PORT_D:
4470 bit = SDE_PORTD_HOTPLUG_CPT;
4471 break;
4472 default:
4473 MISSING_CASE(port->base.port);
4474 return false;
4477 return I915_READ(SDEISR) & bit;
4480 static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
4481 struct intel_digital_port *port)
4483 u32 bit;
4485 switch (port->base.port) {
4486 case PORT_A:
4487 bit = SDE_PORTA_HOTPLUG_SPT;
4488 break;
4489 case PORT_E:
4490 bit = SDE_PORTE_HOTPLUG_SPT;
4491 break;
4492 default:
4493 return cpt_digital_port_connected(dev_priv, port);
4496 return I915_READ(SDEISR) & bit;
4499 static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
4500 struct intel_digital_port *port)
4502 u32 bit;
4504 switch (port->base.port) {
4505 case PORT_B:
4506 bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
4507 break;
4508 case PORT_C:
4509 bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
4510 break;
4511 case PORT_D:
4512 bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
4513 break;
4514 default:
4515 MISSING_CASE(port->base.port);
4516 return false;
4519 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4522 static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
4523 struct intel_digital_port *port)
4525 u32 bit;
4527 switch (port->base.port) {
4528 case PORT_B:
4529 bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
4530 break;
4531 case PORT_C:
4532 bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
4533 break;
4534 case PORT_D:
4535 bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
4536 break;
4537 default:
4538 MISSING_CASE(port->base.port);
4539 return false;
4542 return I915_READ(PORT_HOTPLUG_STAT) & bit;
4545 static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
4546 struct intel_digital_port *port)
4548 if (port->base.port == PORT_A)
4549 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4550 else
4551 return ibx_digital_port_connected(dev_priv, port);
4554 static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
4555 struct intel_digital_port *port)
4557 if (port->base.port == PORT_A)
4558 return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
4559 else
4560 return cpt_digital_port_connected(dev_priv, port);
4563 static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
4564 struct intel_digital_port *port)
4566 if (port->base.port == PORT_A)
4567 return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
4568 else
4569 return cpt_digital_port_connected(dev_priv, port);
4572 static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
4573 struct intel_digital_port *port)
4575 if (port->base.port == PORT_A)
4576 return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
4577 else
4578 return cpt_digital_port_connected(dev_priv, port);
4581 static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
4582 struct intel_digital_port *intel_dig_port)
4584 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4585 enum port port;
4586 u32 bit;
4588 port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
4589 switch (port) {
4590 case PORT_A:
4591 bit = BXT_DE_PORT_HP_DDIA;
4592 break;
4593 case PORT_B:
4594 bit = BXT_DE_PORT_HP_DDIB;
4595 break;
4596 case PORT_C:
4597 bit = BXT_DE_PORT_HP_DDIC;
4598 break;
4599 default:
4600 MISSING_CASE(port);
4601 return false;
4604 return I915_READ(GEN8_DE_PORT_ISR) & bit;
4608 * intel_digital_port_connected - is the specified port connected?
4609 * @dev_priv: i915 private structure
4610 * @port: the port to test
4612 * Return %true if @port is connected, %false otherwise.
4614 bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
4615 struct intel_digital_port *port)
4617 if (HAS_GMCH_DISPLAY(dev_priv)) {
4618 if (IS_GM45(dev_priv))
4619 return gm45_digital_port_connected(dev_priv, port);
4620 else
4621 return g4x_digital_port_connected(dev_priv, port);
4624 if (IS_GEN5(dev_priv))
4625 return ilk_digital_port_connected(dev_priv, port);
4626 else if (IS_GEN6(dev_priv))
4627 return snb_digital_port_connected(dev_priv, port);
4628 else if (IS_GEN7(dev_priv))
4629 return ivb_digital_port_connected(dev_priv, port);
4630 else if (IS_GEN8(dev_priv))
4631 return bdw_digital_port_connected(dev_priv, port);
4632 else if (IS_GEN9_LP(dev_priv))
4633 return bxt_digital_port_connected(dev_priv, port);
4634 else
4635 return spt_digital_port_connected(dev_priv, port);
4638 static struct edid *
4639 intel_dp_get_edid(struct intel_dp *intel_dp)
4641 struct intel_connector *intel_connector = intel_dp->attached_connector;
4643 /* use cached edid if we have one */
4644 if (intel_connector->edid) {
4645 /* invalid edid */
4646 if (IS_ERR(intel_connector->edid))
4647 return NULL;
4649 return drm_edid_duplicate(intel_connector->edid);
4650 } else
4651 return drm_get_edid(&intel_connector->base,
4652 &intel_dp->aux.ddc);
4655 static void
4656 intel_dp_set_edid(struct intel_dp *intel_dp)
4658 struct intel_connector *intel_connector = intel_dp->attached_connector;
4659 struct edid *edid;
4661 intel_dp_unset_edid(intel_dp);
4662 edid = intel_dp_get_edid(intel_dp);
4663 intel_connector->detect_edid = edid;
4665 intel_dp->has_audio = drm_detect_monitor_audio(edid);
4668 static void
4669 intel_dp_unset_edid(struct intel_dp *intel_dp)
4671 struct intel_connector *intel_connector = intel_dp->attached_connector;
4673 kfree(intel_connector->detect_edid);
4674 intel_connector->detect_edid = NULL;
4676 intel_dp->has_audio = false;
4679 static int
4680 intel_dp_long_pulse(struct intel_connector *connector)
4682 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
4683 struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
4684 enum drm_connector_status status;
4685 u8 sink_irq_vector = 0;
4687 WARN_ON(!drm_modeset_is_locked(&dev_priv->drm.mode_config.connection_mutex));
4689 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4691 /* Can't disconnect eDP, but you can close the lid... */
4692 if (intel_dp_is_edp(intel_dp))
4693 status = edp_detect(intel_dp);
4694 else if (intel_digital_port_connected(dev_priv,
4695 dp_to_dig_port(intel_dp)))
4696 status = intel_dp_detect_dpcd(intel_dp);
4697 else
4698 status = connector_status_disconnected;
4700 if (status == connector_status_disconnected) {
4701 memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
4703 if (intel_dp->is_mst) {
4704 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
4705 intel_dp->is_mst,
4706 intel_dp->mst_mgr.mst_state);
4707 intel_dp->is_mst = false;
4708 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
4709 intel_dp->is_mst);
4712 goto out;
4715 if (intel_dp->reset_link_params) {
4716 /* Initial max link lane count */
4717 intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
4719 /* Initial max link rate */
4720 intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
4722 intel_dp->reset_link_params = false;
4725 intel_dp_print_rates(intel_dp);
4727 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
4728 drm_dp_is_branch(intel_dp->dpcd));
4730 intel_dp_configure_mst(intel_dp);
4732 if (intel_dp->is_mst) {
4734 * If we are in MST mode then this connector
4735 * won't appear connected or have anything
4736 * with EDID on it
4738 status = connector_status_disconnected;
4739 goto out;
4740 } else {
4742 * If display is now connected check links status,
4743 * there has been known issues of link loss triggerring
4744 * long pulse.
4746 * Some sinks (eg. ASUS PB287Q) seem to perform some
4747 * weird HPD ping pong during modesets. So we can apparently
4748 * end up with HPD going low during a modeset, and then
4749 * going back up soon after. And once that happens we must
4750 * retrain the link to get a picture. That's in case no
4751 * userspace component reacted to intermittent HPD dip.
4753 intel_dp_check_link_status(intel_dp);
4757 * Clearing NACK and defer counts to get their exact values
4758 * while reading EDID which are required by Compliance tests
4759 * 4.2.2.4 and 4.2.2.5
4761 intel_dp->aux.i2c_nack_count = 0;
4762 intel_dp->aux.i2c_defer_count = 0;
4764 intel_dp_set_edid(intel_dp);
4765 if (intel_dp_is_edp(intel_dp) || connector->detect_edid)
4766 status = connector_status_connected;
4767 intel_dp->detect_done = true;
4769 /* Try to read the source of the interrupt */
4770 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
4771 intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
4772 sink_irq_vector != 0) {
4773 /* Clear interrupt source */
4774 drm_dp_dpcd_writeb(&intel_dp->aux,
4775 DP_DEVICE_SERVICE_IRQ_VECTOR,
4776 sink_irq_vector);
4778 if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
4779 intel_dp_handle_test_request(intel_dp);
4780 if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
4781 DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
4784 out:
4785 if (status != connector_status_connected && !intel_dp->is_mst)
4786 intel_dp_unset_edid(intel_dp);
4788 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4789 return status;
4792 static int
4793 intel_dp_detect(struct drm_connector *connector,
4794 struct drm_modeset_acquire_ctx *ctx,
4795 bool force)
4797 struct intel_dp *intel_dp = intel_attached_dp(connector);
4798 int status = connector->status;
4800 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4801 connector->base.id, connector->name);
4803 /* If full detect is not performed yet, do a full detect */
4804 if (!intel_dp->detect_done) {
4805 struct drm_crtc *crtc;
4806 int ret;
4808 crtc = connector->state->crtc;
4809 if (crtc) {
4810 ret = drm_modeset_lock(&crtc->mutex, ctx);
4811 if (ret)
4812 return ret;
4815 status = intel_dp_long_pulse(intel_dp->attached_connector);
4818 intel_dp->detect_done = false;
4820 return status;
4823 static void
4824 intel_dp_force(struct drm_connector *connector)
4826 struct intel_dp *intel_dp = intel_attached_dp(connector);
4827 struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
4828 struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
4830 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4831 connector->base.id, connector->name);
4832 intel_dp_unset_edid(intel_dp);
4834 if (connector->status != connector_status_connected)
4835 return;
4837 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4839 intel_dp_set_edid(intel_dp);
4841 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
4844 static int intel_dp_get_modes(struct drm_connector *connector)
4846 struct intel_connector *intel_connector = to_intel_connector(connector);
4847 struct edid *edid;
4849 edid = intel_connector->detect_edid;
4850 if (edid) {
4851 int ret = intel_connector_update_modes(connector, edid);
4852 if (ret)
4853 return ret;
4856 /* if eDP has no EDID, fall back to fixed mode */
4857 if (intel_dp_is_edp(intel_attached_dp(connector)) &&
4858 intel_connector->panel.fixed_mode) {
4859 struct drm_display_mode *mode;
4861 mode = drm_mode_duplicate(connector->dev,
4862 intel_connector->panel.fixed_mode);
4863 if (mode) {
4864 drm_mode_probed_add(connector, mode);
4865 return 1;
4869 return 0;
4872 static int
4873 intel_dp_connector_register(struct drm_connector *connector)
4875 struct intel_dp *intel_dp = intel_attached_dp(connector);
4876 int ret;
4878 ret = intel_connector_register(connector);
4879 if (ret)
4880 return ret;
4882 i915_debugfs_connector_add(connector);
4884 DRM_DEBUG_KMS("registering %s bus for %s\n",
4885 intel_dp->aux.name, connector->kdev->kobj.name);
4887 intel_dp->aux.dev = connector->kdev;
4888 return drm_dp_aux_register(&intel_dp->aux);
4891 static void
4892 intel_dp_connector_unregister(struct drm_connector *connector)
4894 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4895 intel_connector_unregister(connector);
4898 static void
4899 intel_dp_connector_destroy(struct drm_connector *connector)
4901 struct intel_connector *intel_connector = to_intel_connector(connector);
4903 kfree(intel_connector->detect_edid);
4905 if (!IS_ERR_OR_NULL(intel_connector->edid))
4906 kfree(intel_connector->edid);
4909 * Can't call intel_dp_is_edp() since the encoder may have been
4910 * destroyed already.
4912 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4913 intel_panel_fini(&intel_connector->panel);
4915 drm_connector_cleanup(connector);
4916 kfree(connector);
4919 void intel_dp_encoder_destroy(struct drm_encoder *encoder)
4921 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
4922 struct intel_dp *intel_dp = &intel_dig_port->dp;
4924 intel_dp_mst_encoder_cleanup(intel_dig_port);
4925 if (intel_dp_is_edp(intel_dp)) {
4926 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4928 * vdd might still be enabled do to the delayed vdd off.
4929 * Make sure vdd is actually turned off here.
4931 pps_lock(intel_dp);
4932 edp_panel_vdd_off_sync(intel_dp);
4933 pps_unlock(intel_dp);
4935 if (intel_dp->edp_notifier.notifier_call) {
4936 unregister_reboot_notifier(&intel_dp->edp_notifier);
4937 intel_dp->edp_notifier.notifier_call = NULL;
4941 intel_dp_aux_fini(intel_dp);
4943 drm_encoder_cleanup(encoder);
4944 kfree(intel_dig_port);
4947 void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
4949 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
4951 if (!intel_dp_is_edp(intel_dp))
4952 return;
4955 * vdd might still be enabled do to the delayed vdd off.
4956 * Make sure vdd is actually turned off here.
4958 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4959 pps_lock(intel_dp);
4960 edp_panel_vdd_off_sync(intel_dp);
4961 pps_unlock(intel_dp);
4964 static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
4966 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4968 lockdep_assert_held(&dev_priv->pps_mutex);
4970 if (!edp_have_panel_vdd(intel_dp))
4971 return;
4974 * The VDD bit needs a power domain reference, so if the bit is
4975 * already enabled when we boot or resume, grab this reference and
4976 * schedule a vdd off, so we don't hold on to the reference
4977 * indefinitely.
4979 DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
4980 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
4982 edp_panel_vdd_schedule_off(intel_dp);
4985 static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
4987 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
4989 if ((intel_dp->DP & DP_PORT_EN) == 0)
4990 return INVALID_PIPE;
4992 if (IS_CHERRYVIEW(dev_priv))
4993 return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
4994 else
4995 return PORT_TO_PIPE(intel_dp->DP);
4998 void intel_dp_encoder_reset(struct drm_encoder *encoder)
5000 struct drm_i915_private *dev_priv = to_i915(encoder->dev);
5001 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
5002 struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
5004 if (!HAS_DDI(dev_priv))
5005 intel_dp->DP = I915_READ(intel_dp->output_reg);
5007 if (lspcon->active)
5008 lspcon_resume(lspcon);
5010 intel_dp->reset_link_params = true;
5012 pps_lock(intel_dp);
5014 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5015 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
5017 if (intel_dp_is_edp(intel_dp)) {
5018 /* Reinit the power sequencer, in case BIOS did something with it. */
5019 intel_dp_pps_init(intel_dp);
5020 intel_edp_panel_vdd_sanitize(intel_dp);
5023 pps_unlock(intel_dp);
5026 static const struct drm_connector_funcs intel_dp_connector_funcs = {
5027 .force = intel_dp_force,
5028 .fill_modes = drm_helper_probe_single_connector_modes,
5029 .atomic_get_property = intel_digital_connector_atomic_get_property,
5030 .atomic_set_property = intel_digital_connector_atomic_set_property,
5031 .late_register = intel_dp_connector_register,
5032 .early_unregister = intel_dp_connector_unregister,
5033 .destroy = intel_dp_connector_destroy,
5034 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
5035 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
5038 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
5039 .detect_ctx = intel_dp_detect,
5040 .get_modes = intel_dp_get_modes,
5041 .mode_valid = intel_dp_mode_valid,
5042 .atomic_check = intel_digital_connector_atomic_check,
5045 static const struct drm_encoder_funcs intel_dp_enc_funcs = {
5046 .reset = intel_dp_encoder_reset,
5047 .destroy = intel_dp_encoder_destroy,
5050 enum irqreturn
5051 intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
5053 struct intel_dp *intel_dp = &intel_dig_port->dp;
5054 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5055 enum irqreturn ret = IRQ_NONE;
5057 if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
5059 * vdd off can generate a long pulse on eDP which
5060 * would require vdd on to handle it, and thus we
5061 * would end up in an endless cycle of
5062 * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
5064 DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
5065 port_name(intel_dig_port->base.port));
5066 return IRQ_HANDLED;
5069 DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
5070 port_name(intel_dig_port->base.port),
5071 long_hpd ? "long" : "short");
5073 if (long_hpd) {
5074 intel_dp->reset_link_params = true;
5075 intel_dp->detect_done = false;
5076 return IRQ_NONE;
5079 intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
5081 if (intel_dp->is_mst) {
5082 if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
5084 * If we were in MST mode, and device is not
5085 * there, get out of MST mode
5087 DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
5088 intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
5089 intel_dp->is_mst = false;
5090 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
5091 intel_dp->is_mst);
5092 intel_dp->detect_done = false;
5093 goto put_power;
5097 if (!intel_dp->is_mst) {
5098 struct drm_modeset_acquire_ctx ctx;
5099 struct drm_connector *connector = &intel_dp->attached_connector->base;
5100 struct drm_crtc *crtc;
5101 int iret;
5102 bool handled = false;
5104 drm_modeset_acquire_init(&ctx, 0);
5105 retry:
5106 iret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, &ctx);
5107 if (iret)
5108 goto err;
5110 crtc = connector->state->crtc;
5111 if (crtc) {
5112 iret = drm_modeset_lock(&crtc->mutex, &ctx);
5113 if (iret)
5114 goto err;
5117 handled = intel_dp_short_pulse(intel_dp);
5119 err:
5120 if (iret == -EDEADLK) {
5121 drm_modeset_backoff(&ctx);
5122 goto retry;
5125 drm_modeset_drop_locks(&ctx);
5126 drm_modeset_acquire_fini(&ctx);
5127 WARN(iret, "Acquiring modeset locks failed with %i\n", iret);
5129 if (!handled) {
5130 intel_dp->detect_done = false;
5131 goto put_power;
5135 ret = IRQ_HANDLED;
5137 put_power:
5138 intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
5140 return ret;
5143 /* check the VBT to see whether the eDP is on another port */
5144 bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
5147 * eDP not supported on g4x. so bail out early just
5148 * for a bit extra safety in case the VBT is bonkers.
5150 if (INTEL_GEN(dev_priv) < 5)
5151 return false;
5153 if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
5154 return true;
5156 return intel_bios_is_port_edp(dev_priv, port);
5159 static void
5160 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
5162 struct drm_i915_private *dev_priv = to_i915(connector->dev);
5163 enum port port = dp_to_dig_port(intel_dp)->base.port;
5165 if (!IS_G4X(dev_priv) && port != PORT_A)
5166 intel_attach_force_audio_property(connector);
5168 intel_attach_broadcast_rgb_property(connector);
5170 if (intel_dp_is_edp(intel_dp)) {
5171 u32 allowed_scalers;
5173 allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
5174 if (!HAS_GMCH_DISPLAY(dev_priv))
5175 allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
5177 drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
5179 connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
5184 static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
5186 intel_dp->panel_power_off_time = ktime_get_boottime();
5187 intel_dp->last_power_on = jiffies;
5188 intel_dp->last_backlight_off = jiffies;
5191 static void
5192 intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
5194 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5195 u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
5196 struct pps_registers regs;
5198 intel_pps_get_registers(intel_dp, &regs);
5200 /* Workaround: Need to write PP_CONTROL with the unlock key as
5201 * the very first thing. */
5202 pp_ctl = ironlake_get_pp_control(intel_dp);
5204 pp_on = I915_READ(regs.pp_on);
5205 pp_off = I915_READ(regs.pp_off);
5206 if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
5207 I915_WRITE(regs.pp_ctrl, pp_ctl);
5208 pp_div = I915_READ(regs.pp_div);
5211 /* Pull timing values out of registers */
5212 seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
5213 PANEL_POWER_UP_DELAY_SHIFT;
5215 seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
5216 PANEL_LIGHT_ON_DELAY_SHIFT;
5218 seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
5219 PANEL_LIGHT_OFF_DELAY_SHIFT;
5221 seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
5222 PANEL_POWER_DOWN_DELAY_SHIFT;
5224 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
5225 seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
5226 BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
5227 } else {
5228 seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
5229 PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
5233 static void
5234 intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
5236 DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
5237 state_name,
5238 seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
5241 static void
5242 intel_pps_verify_state(struct intel_dp *intel_dp)
5244 struct edp_power_seq hw;
5245 struct edp_power_seq *sw = &intel_dp->pps_delays;
5247 intel_pps_readout_hw_state(intel_dp, &hw);
5249 if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
5250 hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
5251 DRM_ERROR("PPS state mismatch\n");
5252 intel_pps_dump_state("sw", sw);
5253 intel_pps_dump_state("hw", &hw);
5257 static void
5258 intel_dp_init_panel_power_sequencer(struct intel_dp *intel_dp)
5260 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5261 struct edp_power_seq cur, vbt, spec,
5262 *final = &intel_dp->pps_delays;
5264 lockdep_assert_held(&dev_priv->pps_mutex);
5266 /* already initialized? */
5267 if (final->t11_t12 != 0)
5268 return;
5270 intel_pps_readout_hw_state(intel_dp, &cur);
5272 intel_pps_dump_state("cur", &cur);
5274 vbt = dev_priv->vbt.edp.pps;
5275 /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
5276 * of 500ms appears to be too short. Ocassionally the panel
5277 * just fails to power back on. Increasing the delay to 800ms
5278 * seems sufficient to avoid this problem.
5280 if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
5281 vbt.t11_t12 = max_t(u16, vbt.t11_t12, 1300 * 10);
5282 DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
5283 vbt.t11_t12);
5285 /* T11_T12 delay is special and actually in units of 100ms, but zero
5286 * based in the hw (so we need to add 100 ms). But the sw vbt
5287 * table multiplies it with 1000 to make it in units of 100usec,
5288 * too. */
5289 vbt.t11_t12 += 100 * 10;
5291 /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
5292 * our hw here, which are all in 100usec. */
5293 spec.t1_t3 = 210 * 10;
5294 spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
5295 spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
5296 spec.t10 = 500 * 10;
5297 /* This one is special and actually in units of 100ms, but zero
5298 * based in the hw (so we need to add 100 ms). But the sw vbt
5299 * table multiplies it with 1000 to make it in units of 100usec,
5300 * too. */
5301 spec.t11_t12 = (510 + 100) * 10;
5303 intel_pps_dump_state("vbt", &vbt);
5305 /* Use the max of the register settings and vbt. If both are
5306 * unset, fall back to the spec limits. */
5307 #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
5308 spec.field : \
5309 max(cur.field, vbt.field))
5310 assign_final(t1_t3);
5311 assign_final(t8);
5312 assign_final(t9);
5313 assign_final(t10);
5314 assign_final(t11_t12);
5315 #undef assign_final
5317 #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
5318 intel_dp->panel_power_up_delay = get_delay(t1_t3);
5319 intel_dp->backlight_on_delay = get_delay(t8);
5320 intel_dp->backlight_off_delay = get_delay(t9);
5321 intel_dp->panel_power_down_delay = get_delay(t10);
5322 intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
5323 #undef get_delay
5325 DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
5326 intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
5327 intel_dp->panel_power_cycle_delay);
5329 DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
5330 intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
5333 * We override the HW backlight delays to 1 because we do manual waits
5334 * on them. For T8, even BSpec recommends doing it. For T9, if we
5335 * don't do this, we'll end up waiting for the backlight off delay
5336 * twice: once when we do the manual sleep, and once when we disable
5337 * the panel and wait for the PP_STATUS bit to become zero.
5339 final->t8 = 1;
5340 final->t9 = 1;
5343 * HW has only a 100msec granularity for t11_t12 so round it up
5344 * accordingly.
5346 final->t11_t12 = roundup(final->t11_t12, 100 * 10);
5349 static void
5350 intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
5351 bool force_disable_vdd)
5353 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5354 u32 pp_on, pp_off, pp_div, port_sel = 0;
5355 int div = dev_priv->rawclk_freq / 1000;
5356 struct pps_registers regs;
5357 enum port port = dp_to_dig_port(intel_dp)->base.port;
5358 const struct edp_power_seq *seq = &intel_dp->pps_delays;
5360 lockdep_assert_held(&dev_priv->pps_mutex);
5362 intel_pps_get_registers(intel_dp, &regs);
5365 * On some VLV machines the BIOS can leave the VDD
5366 * enabled even on power seqeuencers which aren't
5367 * hooked up to any port. This would mess up the
5368 * power domain tracking the first time we pick
5369 * one of these power sequencers for use since
5370 * edp_panel_vdd_on() would notice that the VDD was
5371 * already on and therefore wouldn't grab the power
5372 * domain reference. Disable VDD first to avoid this.
5373 * This also avoids spuriously turning the VDD on as
5374 * soon as the new power seqeuencer gets initialized.
5376 if (force_disable_vdd) {
5377 u32 pp = ironlake_get_pp_control(intel_dp);
5379 WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
5381 if (pp & EDP_FORCE_VDD)
5382 DRM_DEBUG_KMS("VDD already on, disabling first\n");
5384 pp &= ~EDP_FORCE_VDD;
5386 I915_WRITE(regs.pp_ctrl, pp);
5389 pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
5390 (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
5391 pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
5392 (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
5393 /* Compute the divisor for the pp clock, simply match the Bspec
5394 * formula. */
5395 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
5396 pp_div = I915_READ(regs.pp_ctrl);
5397 pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
5398 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5399 << BXT_POWER_CYCLE_DELAY_SHIFT);
5400 } else {
5401 pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
5402 pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
5403 << PANEL_POWER_CYCLE_DELAY_SHIFT);
5406 /* Haswell doesn't have any port selection bits for the panel
5407 * power sequencer any more. */
5408 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5409 port_sel = PANEL_PORT_SELECT_VLV(port);
5410 } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
5411 if (port == PORT_A)
5412 port_sel = PANEL_PORT_SELECT_DPA;
5413 else
5414 port_sel = PANEL_PORT_SELECT_DPD;
5417 pp_on |= port_sel;
5419 I915_WRITE(regs.pp_on, pp_on);
5420 I915_WRITE(regs.pp_off, pp_off);
5421 if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
5422 I915_WRITE(regs.pp_ctrl, pp_div);
5423 else
5424 I915_WRITE(regs.pp_div, pp_div);
5426 DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
5427 I915_READ(regs.pp_on),
5428 I915_READ(regs.pp_off),
5429 (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
5430 (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
5431 I915_READ(regs.pp_div));
5434 static void intel_dp_pps_init(struct intel_dp *intel_dp)
5436 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5438 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5439 vlv_initial_power_sequencer_setup(intel_dp);
5440 } else {
5441 intel_dp_init_panel_power_sequencer(intel_dp);
5442 intel_dp_init_panel_power_sequencer_registers(intel_dp, false);
5447 * intel_dp_set_drrs_state - program registers for RR switch to take effect
5448 * @dev_priv: i915 device
5449 * @crtc_state: a pointer to the active intel_crtc_state
5450 * @refresh_rate: RR to be programmed
5452 * This function gets called when refresh rate (RR) has to be changed from
5453 * one frequency to another. Switches can be between high and low RR
5454 * supported by the panel or to any other RR based on media playback (in
5455 * this case, RR value needs to be passed from user space).
5457 * The caller of this function needs to take a lock on dev_priv->drrs.
5459 static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
5460 const struct intel_crtc_state *crtc_state,
5461 int refresh_rate)
5463 struct intel_encoder *encoder;
5464 struct intel_digital_port *dig_port = NULL;
5465 struct intel_dp *intel_dp = dev_priv->drrs.dp;
5466 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
5467 enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
5469 if (refresh_rate <= 0) {
5470 DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
5471 return;
5474 if (intel_dp == NULL) {
5475 DRM_DEBUG_KMS("DRRS not supported.\n");
5476 return;
5479 dig_port = dp_to_dig_port(intel_dp);
5480 encoder = &dig_port->base;
5482 if (!intel_crtc) {
5483 DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
5484 return;
5487 if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
5488 DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
5489 return;
5492 if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
5493 refresh_rate)
5494 index = DRRS_LOW_RR;
5496 if (index == dev_priv->drrs.refresh_rate_type) {
5497 DRM_DEBUG_KMS(
5498 "DRRS requested for previously set RR...ignoring\n");
5499 return;
5502 if (!crtc_state->base.active) {
5503 DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
5504 return;
5507 if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
5508 switch (index) {
5509 case DRRS_HIGH_RR:
5510 intel_dp_set_m_n(intel_crtc, M1_N1);
5511 break;
5512 case DRRS_LOW_RR:
5513 intel_dp_set_m_n(intel_crtc, M2_N2);
5514 break;
5515 case DRRS_MAX_RR:
5516 default:
5517 DRM_ERROR("Unsupported refreshrate type\n");
5519 } else if (INTEL_GEN(dev_priv) > 6) {
5520 i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
5521 u32 val;
5523 val = I915_READ(reg);
5524 if (index > DRRS_HIGH_RR) {
5525 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5526 val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5527 else
5528 val |= PIPECONF_EDP_RR_MODE_SWITCH;
5529 } else {
5530 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5531 val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
5532 else
5533 val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
5535 I915_WRITE(reg, val);
5538 dev_priv->drrs.refresh_rate_type = index;
5540 DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
5544 * intel_edp_drrs_enable - init drrs struct if supported
5545 * @intel_dp: DP struct
5546 * @crtc_state: A pointer to the active crtc state.
5548 * Initializes frontbuffer_bits and drrs.dp
5550 void intel_edp_drrs_enable(struct intel_dp *intel_dp,
5551 const struct intel_crtc_state *crtc_state)
5553 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5555 if (!crtc_state->has_drrs) {
5556 DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
5557 return;
5560 if (dev_priv->psr.enabled) {
5561 DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
5562 return;
5565 mutex_lock(&dev_priv->drrs.mutex);
5566 if (WARN_ON(dev_priv->drrs.dp)) {
5567 DRM_ERROR("DRRS already enabled\n");
5568 goto unlock;
5571 dev_priv->drrs.busy_frontbuffer_bits = 0;
5573 dev_priv->drrs.dp = intel_dp;
5575 unlock:
5576 mutex_unlock(&dev_priv->drrs.mutex);
5580 * intel_edp_drrs_disable - Disable DRRS
5581 * @intel_dp: DP struct
5582 * @old_crtc_state: Pointer to old crtc_state.
5585 void intel_edp_drrs_disable(struct intel_dp *intel_dp,
5586 const struct intel_crtc_state *old_crtc_state)
5588 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
5590 if (!old_crtc_state->has_drrs)
5591 return;
5593 mutex_lock(&dev_priv->drrs.mutex);
5594 if (!dev_priv->drrs.dp) {
5595 mutex_unlock(&dev_priv->drrs.mutex);
5596 return;
5599 if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5600 intel_dp_set_drrs_state(dev_priv, old_crtc_state,
5601 intel_dp->attached_connector->panel.fixed_mode->vrefresh);
5603 dev_priv->drrs.dp = NULL;
5604 mutex_unlock(&dev_priv->drrs.mutex);
5606 cancel_delayed_work_sync(&dev_priv->drrs.work);
5609 static void intel_edp_drrs_downclock_work(struct work_struct *work)
5611 struct drm_i915_private *dev_priv =
5612 container_of(work, typeof(*dev_priv), drrs.work.work);
5613 struct intel_dp *intel_dp;
5615 mutex_lock(&dev_priv->drrs.mutex);
5617 intel_dp = dev_priv->drrs.dp;
5619 if (!intel_dp)
5620 goto unlock;
5623 * The delayed work can race with an invalidate hence we need to
5624 * recheck.
5627 if (dev_priv->drrs.busy_frontbuffer_bits)
5628 goto unlock;
5630 if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
5631 struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
5633 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5634 intel_dp->attached_connector->panel.downclock_mode->vrefresh);
5637 unlock:
5638 mutex_unlock(&dev_priv->drrs.mutex);
5642 * intel_edp_drrs_invalidate - Disable Idleness DRRS
5643 * @dev_priv: i915 device
5644 * @frontbuffer_bits: frontbuffer plane tracking bits
5646 * This function gets called everytime rendering on the given planes start.
5647 * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
5649 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5651 void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
5652 unsigned int frontbuffer_bits)
5654 struct drm_crtc *crtc;
5655 enum pipe pipe;
5657 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5658 return;
5660 cancel_delayed_work(&dev_priv->drrs.work);
5662 mutex_lock(&dev_priv->drrs.mutex);
5663 if (!dev_priv->drrs.dp) {
5664 mutex_unlock(&dev_priv->drrs.mutex);
5665 return;
5668 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5669 pipe = to_intel_crtc(crtc)->pipe;
5671 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5672 dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
5674 /* invalidate means busy screen hence upclock */
5675 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5676 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5677 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
5679 mutex_unlock(&dev_priv->drrs.mutex);
5683 * intel_edp_drrs_flush - Restart Idleness DRRS
5684 * @dev_priv: i915 device
5685 * @frontbuffer_bits: frontbuffer plane tracking bits
5687 * This function gets called every time rendering on the given planes has
5688 * completed or flip on a crtc is completed. So DRRS should be upclocked
5689 * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
5690 * if no other planes are dirty.
5692 * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
5694 void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
5695 unsigned int frontbuffer_bits)
5697 struct drm_crtc *crtc;
5698 enum pipe pipe;
5700 if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
5701 return;
5703 cancel_delayed_work(&dev_priv->drrs.work);
5705 mutex_lock(&dev_priv->drrs.mutex);
5706 if (!dev_priv->drrs.dp) {
5707 mutex_unlock(&dev_priv->drrs.mutex);
5708 return;
5711 crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
5712 pipe = to_intel_crtc(crtc)->pipe;
5714 frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
5715 dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
5717 /* flush means busy screen hence upclock */
5718 if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
5719 intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
5720 dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
5723 * flush also means no more activity hence schedule downclock, if all
5724 * other fbs are quiescent too
5726 if (!dev_priv->drrs.busy_frontbuffer_bits)
5727 schedule_delayed_work(&dev_priv->drrs.work,
5728 msecs_to_jiffies(1000));
5729 mutex_unlock(&dev_priv->drrs.mutex);
5733 * DOC: Display Refresh Rate Switching (DRRS)
5735 * Display Refresh Rate Switching (DRRS) is a power conservation feature
5736 * which enables swtching between low and high refresh rates,
5737 * dynamically, based on the usage scenario. This feature is applicable
5738 * for internal panels.
5740 * Indication that the panel supports DRRS is given by the panel EDID, which
5741 * would list multiple refresh rates for one resolution.
5743 * DRRS is of 2 types - static and seamless.
5744 * Static DRRS involves changing refresh rate (RR) by doing a full modeset
5745 * (may appear as a blink on screen) and is used in dock-undock scenario.
5746 * Seamless DRRS involves changing RR without any visual effect to the user
5747 * and can be used during normal system usage. This is done by programming
5748 * certain registers.
5750 * Support for static/seamless DRRS may be indicated in the VBT based on
5751 * inputs from the panel spec.
5753 * DRRS saves power by switching to low RR based on usage scenarios.
5755 * The implementation is based on frontbuffer tracking implementation. When
5756 * there is a disturbance on the screen triggered by user activity or a periodic
5757 * system activity, DRRS is disabled (RR is changed to high RR). When there is
5758 * no movement on screen, after a timeout of 1 second, a switch to low RR is
5759 * made.
5761 * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
5762 * and intel_edp_drrs_flush() are called.
5764 * DRRS can be further extended to support other internal panels and also
5765 * the scenario of video playback wherein RR is set based on the rate
5766 * requested by userspace.
5770 * intel_dp_drrs_init - Init basic DRRS work and mutex.
5771 * @connector: eDP connector
5772 * @fixed_mode: preferred mode of panel
5774 * This function is called only once at driver load to initialize basic
5775 * DRRS stuff.
5777 * Returns:
5778 * Downclock mode if panel supports it, else return NULL.
5779 * DRRS support is determined by the presence of downclock mode (apart
5780 * from VBT setting).
5782 static struct drm_display_mode *
5783 intel_dp_drrs_init(struct intel_connector *connector,
5784 struct drm_display_mode *fixed_mode)
5786 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
5787 struct drm_display_mode *downclock_mode = NULL;
5789 INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
5790 mutex_init(&dev_priv->drrs.mutex);
5792 if (INTEL_GEN(dev_priv) <= 6) {
5793 DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
5794 return NULL;
5797 if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
5798 DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
5799 return NULL;
5802 downclock_mode = intel_find_panel_downclock(dev_priv, fixed_mode,
5803 &connector->base);
5805 if (!downclock_mode) {
5806 DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
5807 return NULL;
5810 dev_priv->drrs.type = dev_priv->vbt.drrs_type;
5812 dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
5813 DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
5814 return downclock_mode;
5817 static bool intel_edp_init_connector(struct intel_dp *intel_dp,
5818 struct intel_connector *intel_connector)
5820 struct drm_device *dev = intel_dp_to_dev(intel_dp);
5821 struct drm_i915_private *dev_priv = to_i915(dev);
5822 struct drm_connector *connector = &intel_connector->base;
5823 struct drm_display_mode *fixed_mode = NULL;
5824 struct drm_display_mode *alt_fixed_mode = NULL;
5825 struct drm_display_mode *downclock_mode = NULL;
5826 bool has_dpcd;
5827 struct drm_display_mode *scan;
5828 struct edid *edid;
5829 enum pipe pipe = INVALID_PIPE;
5831 if (!intel_dp_is_edp(intel_dp))
5832 return true;
5835 * On IBX/CPT we may get here with LVDS already registered. Since the
5836 * driver uses the only internal power sequencer available for both
5837 * eDP and LVDS bail out early in this case to prevent interfering
5838 * with an already powered-on LVDS power sequencer.
5840 if (intel_get_lvds_encoder(&dev_priv->drm)) {
5841 WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
5842 DRM_INFO("LVDS was detected, not registering eDP\n");
5844 return false;
5847 pps_lock(intel_dp);
5849 intel_dp_init_panel_power_timestamps(intel_dp);
5850 intel_dp_pps_init(intel_dp);
5851 intel_edp_panel_vdd_sanitize(intel_dp);
5853 pps_unlock(intel_dp);
5855 /* Cache DPCD and EDID for edp. */
5856 has_dpcd = intel_edp_init_dpcd(intel_dp);
5858 if (!has_dpcd) {
5859 /* if this fails, presume the device is a ghost */
5860 DRM_INFO("failed to retrieve link info, disabling eDP\n");
5861 goto out_vdd_off;
5864 mutex_lock(&dev->mode_config.mutex);
5865 edid = drm_get_edid(connector, &intel_dp->aux.ddc);
5866 if (edid) {
5867 if (drm_add_edid_modes(connector, edid)) {
5868 drm_mode_connector_update_edid_property(connector,
5869 edid);
5870 } else {
5871 kfree(edid);
5872 edid = ERR_PTR(-EINVAL);
5874 } else {
5875 edid = ERR_PTR(-ENOENT);
5877 intel_connector->edid = edid;
5879 /* prefer fixed mode from EDID if available, save an alt mode also */
5880 list_for_each_entry(scan, &connector->probed_modes, head) {
5881 if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
5882 fixed_mode = drm_mode_duplicate(dev, scan);
5883 downclock_mode = intel_dp_drrs_init(
5884 intel_connector, fixed_mode);
5885 } else if (!alt_fixed_mode) {
5886 alt_fixed_mode = drm_mode_duplicate(dev, scan);
5890 /* fallback to VBT if available for eDP */
5891 if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
5892 fixed_mode = drm_mode_duplicate(dev,
5893 dev_priv->vbt.lfp_lvds_vbt_mode);
5894 if (fixed_mode) {
5895 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
5896 connector->display_info.width_mm = fixed_mode->width_mm;
5897 connector->display_info.height_mm = fixed_mode->height_mm;
5900 mutex_unlock(&dev->mode_config.mutex);
5902 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
5903 intel_dp->edp_notifier.notifier_call = edp_notify_handler;
5904 register_reboot_notifier(&intel_dp->edp_notifier);
5907 * Figure out the current pipe for the initial backlight setup.
5908 * If the current pipe isn't valid, try the PPS pipe, and if that
5909 * fails just assume pipe A.
5911 pipe = vlv_active_pipe(intel_dp);
5913 if (pipe != PIPE_A && pipe != PIPE_B)
5914 pipe = intel_dp->pps_pipe;
5916 if (pipe != PIPE_A && pipe != PIPE_B)
5917 pipe = PIPE_A;
5919 DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
5920 pipe_name(pipe));
5923 intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
5924 downclock_mode);
5925 intel_connector->panel.backlight.power = intel_edp_backlight_power;
5926 intel_panel_setup_backlight(connector, pipe);
5928 return true;
5930 out_vdd_off:
5931 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
5933 * vdd might still be enabled do to the delayed vdd off.
5934 * Make sure vdd is actually turned off here.
5936 pps_lock(intel_dp);
5937 edp_panel_vdd_off_sync(intel_dp);
5938 pps_unlock(intel_dp);
5940 return false;
5943 /* Set up the hotplug pin and aux power domain. */
5944 static void
5945 intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
5947 struct intel_encoder *encoder = &intel_dig_port->base;
5948 struct intel_dp *intel_dp = &intel_dig_port->dp;
5950 encoder->hpd_pin = intel_hpd_pin(encoder->port);
5952 switch (encoder->port) {
5953 case PORT_A:
5954 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
5955 break;
5956 case PORT_B:
5957 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
5958 break;
5959 case PORT_C:
5960 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
5961 break;
5962 case PORT_D:
5963 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
5964 break;
5965 case PORT_E:
5966 /* FIXME: Check VBT for actual wiring of PORT E */
5967 intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
5968 break;
5969 default:
5970 MISSING_CASE(encoder->port);
5974 static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
5976 struct intel_connector *intel_connector;
5977 struct drm_connector *connector;
5979 intel_connector = container_of(work, typeof(*intel_connector),
5980 modeset_retry_work);
5981 connector = &intel_connector->base;
5982 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
5983 connector->name);
5985 /* Grab the locks before changing connector property*/
5986 mutex_lock(&connector->dev->mode_config.mutex);
5987 /* Set connector link status to BAD and send a Uevent to notify
5988 * userspace to do a modeset.
5990 drm_mode_connector_set_link_status_property(connector,
5991 DRM_MODE_LINK_STATUS_BAD);
5992 mutex_unlock(&connector->dev->mode_config.mutex);
5993 /* Send Hotplug uevent so userspace can reprobe */
5994 drm_kms_helper_hotplug_event(connector->dev);
5997 bool
5998 intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5999 struct intel_connector *intel_connector)
6001 struct drm_connector *connector = &intel_connector->base;
6002 struct intel_dp *intel_dp = &intel_dig_port->dp;
6003 struct intel_encoder *intel_encoder = &intel_dig_port->base;
6004 struct drm_device *dev = intel_encoder->base.dev;
6005 struct drm_i915_private *dev_priv = to_i915(dev);
6006 enum port port = intel_encoder->port;
6007 int type;
6009 /* Initialize the work for modeset in case of link train failure */
6010 INIT_WORK(&intel_connector->modeset_retry_work,
6011 intel_dp_modeset_retry_work_fn);
6013 if (WARN(intel_dig_port->max_lanes < 1,
6014 "Not enough lanes (%d) for DP on port %c\n",
6015 intel_dig_port->max_lanes, port_name(port)))
6016 return false;
6018 intel_dp_set_source_rates(intel_dp);
6020 intel_dp->reset_link_params = true;
6021 intel_dp->pps_pipe = INVALID_PIPE;
6022 intel_dp->active_pipe = INVALID_PIPE;
6024 /* intel_dp vfuncs */
6025 if (INTEL_GEN(dev_priv) >= 9)
6026 intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
6027 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
6028 intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
6029 else if (HAS_PCH_SPLIT(dev_priv))
6030 intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
6031 else
6032 intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
6034 if (INTEL_GEN(dev_priv) >= 9)
6035 intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
6036 else
6037 intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
6039 if (HAS_DDI(dev_priv))
6040 intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
6042 /* Preserve the current hw state. */
6043 intel_dp->DP = I915_READ(intel_dp->output_reg);
6044 intel_dp->attached_connector = intel_connector;
6046 if (intel_dp_is_port_edp(dev_priv, port))
6047 type = DRM_MODE_CONNECTOR_eDP;
6048 else
6049 type = DRM_MODE_CONNECTOR_DisplayPort;
6051 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6052 intel_dp->active_pipe = vlv_active_pipe(intel_dp);
6055 * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
6056 * for DP the encoder type can be set by the caller to
6057 * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
6059 if (type == DRM_MODE_CONNECTOR_eDP)
6060 intel_encoder->type = INTEL_OUTPUT_EDP;
6062 /* eDP only on port B and/or C on vlv/chv */
6063 if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
6064 intel_dp_is_edp(intel_dp) &&
6065 port != PORT_B && port != PORT_C))
6066 return false;
6068 DRM_DEBUG_KMS("Adding %s connector on port %c\n",
6069 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
6070 port_name(port));
6072 drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
6073 drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
6075 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
6076 connector->interlace_allowed = true;
6077 connector->doublescan_allowed = 0;
6079 intel_dp_init_connector_port_info(intel_dig_port);
6081 intel_dp_aux_init(intel_dp);
6083 INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
6084 edp_panel_vdd_work);
6086 intel_connector_attach_encoder(intel_connector, intel_encoder);
6088 if (HAS_DDI(dev_priv))
6089 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
6090 else
6091 intel_connector->get_hw_state = intel_connector_get_hw_state;
6093 /* init MST on ports that can support it */
6094 if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
6095 (port == PORT_B || port == PORT_C || port == PORT_D))
6096 intel_dp_mst_encoder_init(intel_dig_port,
6097 intel_connector->base.base.id);
6099 if (!intel_edp_init_connector(intel_dp, intel_connector)) {
6100 intel_dp_aux_fini(intel_dp);
6101 intel_dp_mst_encoder_cleanup(intel_dig_port);
6102 goto fail;
6105 intel_dp_add_properties(intel_dp, connector);
6107 /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
6108 * 0xd. Failure to do so will result in spurious interrupts being
6109 * generated on the port when a cable is not attached.
6111 if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
6112 u32 temp = I915_READ(PEG_BAND_GAP_DATA);
6113 I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
6116 return true;
6118 fail:
6119 drm_connector_cleanup(connector);
6121 return false;
6124 bool intel_dp_init(struct drm_i915_private *dev_priv,
6125 i915_reg_t output_reg,
6126 enum port port)
6128 struct intel_digital_port *intel_dig_port;
6129 struct intel_encoder *intel_encoder;
6130 struct drm_encoder *encoder;
6131 struct intel_connector *intel_connector;
6133 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
6134 if (!intel_dig_port)
6135 return false;
6137 intel_connector = intel_connector_alloc();
6138 if (!intel_connector)
6139 goto err_connector_alloc;
6141 intel_encoder = &intel_dig_port->base;
6142 encoder = &intel_encoder->base;
6144 if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
6145 &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
6146 "DP %c", port_name(port)))
6147 goto err_encoder_init;
6149 intel_encoder->compute_config = intel_dp_compute_config;
6150 intel_encoder->get_hw_state = intel_dp_get_hw_state;
6151 intel_encoder->get_config = intel_dp_get_config;
6152 intel_encoder->suspend = intel_dp_encoder_suspend;
6153 if (IS_CHERRYVIEW(dev_priv)) {
6154 intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
6155 intel_encoder->pre_enable = chv_pre_enable_dp;
6156 intel_encoder->enable = vlv_enable_dp;
6157 intel_encoder->disable = vlv_disable_dp;
6158 intel_encoder->post_disable = chv_post_disable_dp;
6159 intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
6160 } else if (IS_VALLEYVIEW(dev_priv)) {
6161 intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
6162 intel_encoder->pre_enable = vlv_pre_enable_dp;
6163 intel_encoder->enable = vlv_enable_dp;
6164 intel_encoder->disable = vlv_disable_dp;
6165 intel_encoder->post_disable = vlv_post_disable_dp;
6166 } else if (INTEL_GEN(dev_priv) >= 5) {
6167 intel_encoder->pre_enable = g4x_pre_enable_dp;
6168 intel_encoder->enable = g4x_enable_dp;
6169 intel_encoder->disable = ilk_disable_dp;
6170 intel_encoder->post_disable = ilk_post_disable_dp;
6171 } else {
6172 intel_encoder->pre_enable = g4x_pre_enable_dp;
6173 intel_encoder->enable = g4x_enable_dp;
6174 intel_encoder->disable = g4x_disable_dp;
6177 intel_dig_port->dp.output_reg = output_reg;
6178 intel_dig_port->max_lanes = 4;
6180 intel_encoder->type = INTEL_OUTPUT_DP;
6181 intel_encoder->power_domain = intel_port_to_power_domain(port);
6182 if (IS_CHERRYVIEW(dev_priv)) {
6183 if (port == PORT_D)
6184 intel_encoder->crtc_mask = 1 << 2;
6185 else
6186 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
6187 } else {
6188 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
6190 intel_encoder->cloneable = 0;
6191 intel_encoder->port = port;
6193 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
6194 dev_priv->hotplug.irq_port[port] = intel_dig_port;
6196 if (port != PORT_A)
6197 intel_infoframe_init(intel_dig_port);
6199 if (!intel_dp_init_connector(intel_dig_port, intel_connector))
6200 goto err_init_connector;
6202 return true;
6204 err_init_connector:
6205 drm_encoder_cleanup(encoder);
6206 err_encoder_init:
6207 kfree(intel_connector);
6208 err_connector_alloc:
6209 kfree(intel_dig_port);
6210 return false;
6213 void intel_dp_mst_suspend(struct drm_device *dev)
6215 struct drm_i915_private *dev_priv = to_i915(dev);
6216 int i;
6218 /* disable MST */
6219 for (i = 0; i < I915_MAX_PORTS; i++) {
6220 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6222 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6223 continue;
6225 if (intel_dig_port->dp.is_mst)
6226 drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
6230 void intel_dp_mst_resume(struct drm_device *dev)
6232 struct drm_i915_private *dev_priv = to_i915(dev);
6233 int i;
6235 for (i = 0; i < I915_MAX_PORTS; i++) {
6236 struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
6237 int ret;
6239 if (!intel_dig_port || !intel_dig_port->dp.can_mst)
6240 continue;
6242 ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
6243 if (ret)
6244 intel_dp_check_mst_status(&intel_dig_port->dp);